certmanager Library API Documentation

kwatchgnupgconfig.cpp

00001 /*
00002     kwatchgnupgconfig.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include "kwatchgnupgconfig.h"
00034 
00035 #include <klocale.h>
00036 #include <kurlrequester.h>
00037 #include <kconfig.h>
00038 #include <kapplication.h>
00039 
00040 #include <qframe.h>
00041 #include <qlayout.h>
00042 #include <qlabel.h>
00043 #include <qspinbox.h>
00044 #include <qcheckbox.h>
00045 #include <qcombobox.h>
00046 #include <qdir.h>
00047 #include <qvgroupbox.h>
00048 
00049 static const char* log_levels[] = { "none", "basic", "advanced", "expert", "guru" };
00050 
00051 static int log_level_to_int( const QString& loglevel )
00052 {
00053   if( loglevel == "none" ) {
00054     return 0;
00055   } else if( loglevel == "basic" ) {
00056     return 1;
00057   } else if( loglevel == "advanced" ) {
00058     return 2;
00059   } else if( loglevel == "expert" ) {
00060     return 3;
00061   } else if( loglevel == "guru" ) {
00062     return 4;
00063   } else {
00064     // default
00065     return 1;
00066   }
00067 }
00068 
00069 KWatchGnuPGConfig::KWatchGnuPGConfig( QWidget* parent, const char* name )
00070   : KDialogBase( Plain, i18n("Configure KWatchGnuPG"),
00071          Ok|Cancel, Ok, parent, name )
00072 {
00073   // tmp vars:
00074   QWidget * w;
00075   QGridLayout * glay;
00076   QGroupBox * group;
00077 
00078   QWidget * top = plainPage();
00079 
00080   QVBoxLayout * vlay = new QVBoxLayout( top, 0, spacingHint() );
00081 
00082   group = new QVGroupBox( i18n("WatchGnuPG"), top );
00083   group->layout()->setSpacing( spacingHint() );
00084 
00085   w = new QWidget( group );
00086 
00087   glay = new QGridLayout( w, 3, 2, 0, spacingHint() );
00088   glay->setColStretch( 1, 1 );
00089 
00090   int row = -1;
00091 
00092   ++row;
00093   mExeED = new KURLRequester( w );
00094   glay->addWidget( new QLabel( mExeED, i18n("&Executable:"), w ), row, 0 );
00095   glay->addWidget( mExeED, row, 1 );
00096   connect( mExeED, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()) );
00097 
00098   ++row;
00099   mSocketED = new KURLRequester( w );
00100   glay->addWidget( new QLabel( mSocketED, i18n("&Socket:"), w ), row, 0 );
00101   glay->addWidget( mSocketED, row, 1 );
00102   connect( mSocketED, SIGNAL(textChanged(const QString&)), SLOT(slotChanged()) );
00103 
00104   ++row;
00105   mLogLevelCB = new QComboBox( false, w );
00106   mLogLevelCB->insertItem( i18n("None") );
00107   mLogLevelCB->insertItem( i18n("Basic") );
00108   mLogLevelCB->insertItem( i18n("Advanced") );
00109   mLogLevelCB->insertItem( i18n("Expert") );
00110   mLogLevelCB->insertItem( i18n("Guru") );
00111   glay->addWidget( new QLabel( mLogLevelCB, i18n("Default &log level:"), w ), row, 0 );
00112   glay->addWidget( mLogLevelCB, row, 1 );
00113   connect( mLogLevelCB, SIGNAL(activated(int)), SLOT(slotChanged()) );
00114 
00115   vlay->addWidget( group );
00116 
00117   /******************* Log Window group *******************/
00118   group = new QVGroupBox( i18n("Log Window"), top );
00119   group->layout()->setSpacing( spacingHint() );
00120 
00121   w = new QWidget( group );
00122 
00123   glay = new QGridLayout( w, 2, 3, 0, spacingHint() );
00124   glay->setColStretch( 1, 1 );
00125 
00126   row = -1;
00127 
00128   ++row;
00129   mLoglenSB = new QSpinBox( 0, 1000000, 100, w );
00130   mLoglenSB->setSuffix( i18n("history size spinbox suffix"," lines") );
00131   mLoglenSB->setSpecialValueText( i18n("unlimited") );
00132   glay->addWidget( new QLabel( mLoglenSB, i18n("&History size:"), w ), row, 0 );
00133   glay->addWidget( mLoglenSB, row, 1 );
00134   QPushButton * button = new QPushButton( i18n("Set &Unlimited"), w );
00135   glay->addWidget( button, row, 2 );
00136 
00137   connect( mLoglenSB, SIGNAL(valueChanged(int)), SLOT(slotChanged()) );
00138   connect( button, SIGNAL(clicked()), SLOT(slotSetHistorySizeUnlimited()) );
00139 
00140   ++row;
00141   mWordWrapCB = new QCheckBox( i18n("Enable &word wrapping"), w );
00142   mWordWrapCB->hide(); // QTextEdit doesn't support word wrapping in LogText mode
00143   glay->addMultiCellWidget( mWordWrapCB, row, row, 0, 2 );
00144 
00145   connect( mWordWrapCB, SIGNAL(clicked()), SLOT(slotChanged()) );
00146 
00147   vlay->addWidget( group );
00148   vlay->addStretch( 1 );
00149 
00150   connect( this, SIGNAL(applyClicked()), SLOT(slotSave()) );
00151   connect( this, SIGNAL(okClicked()), SLOT(slotSave()) );
00152 }
00153 
00154 void KWatchGnuPGConfig::slotSetHistorySizeUnlimited() {
00155   mLoglenSB->setValue( 0 );
00156 }
00157 
00158 void KWatchGnuPGConfig::loadConfig()
00159 {
00160   KConfig* config = kapp->config();
00161   config->setGroup("WatchGnuPG");
00162   mExeED->setURL( config->readEntry( "Executable", "watchgnupg" ) );
00163   mSocketED->setURL( config->readEntry( "Socket", QDir::home().canonicalPath()
00164                                         + "/.gnupg/log-socket") );
00165   mLogLevelCB->setCurrentItem( log_level_to_int( config->readEntry( "LogLevel", "basic" ) ) );
00166 
00167   config->setGroup("LogWindow");
00168   mLoglenSB->setValue( config->readNumEntry( "MaxLogLen", 10000 ) );
00169   mWordWrapCB->setChecked( config->readBoolEntry("WordWrap", false ) );
00170 
00171   config->setGroup( QString::null );
00172   enableButtonOK( false );
00173   enableButtonApply( false );
00174 }
00175 
00176 void KWatchGnuPGConfig::saveConfig()
00177 {
00178   KConfig* config = kapp->config();
00179   config->setGroup("WatchGnuPG");
00180   config->writeEntry( "Executable", mExeED->url() );
00181   config->writeEntry( "Socket", mSocketED->url() );
00182   config->writeEntry( "LogLevel", log_levels[mLogLevelCB->currentItem()] );
00183 
00184   config->setGroup("LogWindow");
00185   config->writeEntry( "MaxLogLen", mLoglenSB->value() );
00186   config->writeEntry( "WordWrap", mWordWrapCB->isChecked() );
00187 
00188   config->setGroup( QString::null );
00189   config->sync();
00190   enableButtonOK( false );
00191   enableButtonApply( false );
00192 }
00193 
00194 void KWatchGnuPGConfig::slotChanged()
00195 {
00196   enableButtonOK( true );
00197   enableButtonApply( true );
00198 }
00199 
00200 void KWatchGnuPGConfig::slotSave()
00201 {
00202   saveConfig();
00203   emit reconfigure();
00204 }
00205 
00206 #include "kwatchgnupgconfig.moc"
KDE Logo
This file is part of the documentation for certmanager Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 2 09:52:57 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003