/*************************************************************************** * Copyright (C) 2006 by Michael Kaufmann * * michael@enlighter.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "logwidget.h" #include "openvpnmanager.h" #include #include #include #include #include #include using namespace std; logWidget::logWidget( unsigned int maxLines, QWidget* parent, const char* name, WFlags fl ) : logWidgetBase( parent, name, fl ) { mMaxLines = maxLines; mAdvanced = false; } logWidget::~logWidget() {} void logWidget::reg( openVPNManager * manager ) { debug( "reg" ); QWidget * TabPage = new QWidget( loggingTabs, manager->id() ); KTextEdit * historyView = new KTextEdit( TabPage , "History" ); historyView->setTextFormat( Qt::LogText ); historyView->setMaxLogLines( mMaxLines ); historyView->append( i18n( "Logging max. %1 lines for %2" ).arg( mMaxLines ).arg( manager->id() ) ); QGridLayout * TabPageLayout = new QGridLayout( TabPage, 1, 1, 11, 6, "TabPageLayout" ); TabPageLayout->addWidget( historyView, 0, 0 ); if ( mAdvanced ) { KLineEdit * commandLine = new KLineEdit( TabPage ); connect( commandLine, SIGNAL( returnPressed( const QString& ) ), manager, SLOT( directCommand( const QString& ) ) ); connect( commandLine, SIGNAL( returnPressed( const QString& ) ), commandLine, SLOT( clear() ) ); mCommandList[ manager->id() ] = commandLine; TabPageLayout->addWidget( commandLine, 1, 0 ); } loggingTabs->addTab( TabPage, manager->id() ); mTabList[ manager->id() ] = TabPage; mHistoryList[ manager->id() ] = historyView; QObject::connect( manager, SIGNAL ( message( const QString &, const QString &, openVPNManager::requests ) ), this, SLOT ( message( const QString &, const QString &, openVPNManager::requests ) ) ); } void logWidget::dereg( openVPNManager * manager ) { QObject::disconnect( manager, 0, 0, 0 ); loggingTabs->removePage( mTabList[ manager->id() ] ); /* TODO: Do I need to delete them manually ? */ mTabList.remove( manager->id() ); mHistoryList.remove( manager->id() ); mCommandList.remove( manager->id() ); } void logWidget::message( const QString & id, const QString & message, openVPNManager::requests type ) { switch ( type ) { case openVPNManager::MISC: // mHistoryList[ id ] ->append( QString( "%1" ).arg( message ) ); // break; default: mHistoryList[ id ] ->append( message ); break; } } void logWidget::debug( const QString & method, const QString & message ) { #ifdef DEBUG QString myMethod ( method ); static unsigned int maxLen = 0; maxLen = QMAX( myMethod.length(), maxLen ); cout << "logWidget::" << myMethod.leftJustify( maxLen ) << " => " << message << endl; #endif } void logWidget::setAdvanced( bool advanced ) { /* TODO: If user changes this while kovpn is running then apply it in real time. */ mAdvanced = advanced; } #include "logwidget.moc"