karm Library API Documentation

preferences.cpp

00001 #undef Unsorted // for --enable-final
00002 #include <qcheckbox.h>
00003 #include <qlabel.h>
00004 #include <qstring.h>
00005 #include <qspinbox.h>
00006 #include <qlayout.h>
00007 
00008 #include <kapplication.h>       // kapp
00009 #include <kconfig.h>
00010 #include <kdebug.h>
00011 #include <kemailsettings.h>
00012 #include <kiconloader.h>
00013 #include <klineedit.h>          // lineEdit()
00014 #include <klocale.h>            // i18n
00015 #include <kstandarddirs.h>
00016 #include <kurlrequester.h>
00017 
00018 #include "preferences.h"
00019 
00020 Preferences *Preferences::_instance = 0;
00021 
00022 Preferences::Preferences()
00023   : KDialogBase( IconList, i18n("Preferences"), Ok|Cancel, Ok )
00024 {
00025 
00026   setIconListAllVisible( true );
00027 
00028   makeBehaviorPage();
00029   makeDisplayPage();
00030   makeStoragePage();
00031 
00032   load();
00033 }
00034 
00035 Preferences *Preferences::instance()
00036 {
00037   if (_instance == 0) {
00038     _instance = new Preferences();
00039   }
00040   return _instance;
00041 }
00042 
00043 void Preferences::makeBehaviorPage()
00044 {
00045   QPixmap icon = KGlobal::iconLoader()->loadIcon(
00046       QString::fromLatin1("kcmsystem"), KIcon::Toolbar,
00047       KIcon::SizeMedium);
00048   QFrame* behaviorPage = addPage( i18n("Behavior"), i18n("Behavior Settings"),
00049       icon );
00050 
00051   QVBoxLayout* topLevel = new QVBoxLayout( behaviorPage, 0, spacingHint() );
00052   QGridLayout* layout = new QGridLayout( topLevel, 2, 2 );
00053   layout->setColStretch( 1, 1 );
00054 
00055   _doIdleDetectionW = new QCheckBox( i18n("Detect desktop as idle after"),
00056       behaviorPage, "_doIdleDetectionW");
00057   _idleDetectValueW = new QSpinBox(1,60*24, 1, behaviorPage,
00058       "_idleDetectValueW");
00059   _idleDetectValueW->setSuffix(i18n(" minutes"));
00060   _promptDeleteW = new QCheckBox( i18n( "Prompt before deleting tasks" ),
00061       behaviorPage, "_promptDeleteW" );
00062 
00063   layout->addWidget(_doIdleDetectionW, 0, 0 );
00064   layout->addWidget(_idleDetectValueW, 0, 1 );
00065   layout->addWidget(_promptDeleteW, 1, 0 );
00066 
00067   connect( _doIdleDetectionW, SIGNAL( clicked() ), this,
00068       SLOT( idleDetectCheckBoxChanged() ));
00069 }
00070 
00071 void Preferences::makeDisplayPage()
00072 {
00073   QPixmap icon = KGlobal::iconLoader()->loadIcon(
00074       QString::fromLatin1("viewmag"), KIcon::Toolbar, KIcon::SizeMedium );
00075   QFrame* displayPage = addPage( i18n("Display"), i18n("Display Settings"),
00076       icon );
00077 
00078   QVBoxLayout* topLevel = new QVBoxLayout( displayPage, 0, spacingHint() );
00079   QGridLayout* layout = new QGridLayout( topLevel, 5, 2 );
00080   layout->setColStretch( 1, 1 );
00081 
00082   QLabel* _displayColumnsLabelW = new QLabel( i18n("Columns displayed:"),
00083       displayPage );
00084   _displaySessionW = new QCheckBox ( i18n("Session time"),
00085       displayPage, "_displaySessionW");
00086   _displayTimeW = new QCheckBox ( i18n("Cumulative task time"),
00087       displayPage, "_displayTimeW");
00088   _displayTotalSessionW = new QCheckBox( i18n("Total session time"),
00089       displayPage, "_displayTotalSessionW");
00090   _displayTotalTimeW = new QCheckBox ( i18n("Total task time"),
00091       displayPage, "_displayTotalTimeW");
00092 
00093   layout->addMultiCellWidget( _displayColumnsLabelW, 0, 0, 0, 1 );
00094   layout->addWidget(_displaySessionW, 1, 1 );
00095   layout->addWidget(_displayTimeW, 2, 1 );
00096   layout->addWidget(_displayTotalSessionW, 3, 1 );
00097   layout->addWidget(_displayTotalTimeW, 4, 1 );
00098 }
00099 
00100 void Preferences::makeStoragePage()
00101 {
00102   QPixmap icon = KGlobal::iconLoader()->loadIcon(QString::fromLatin1("kfm"),
00103       KIcon::Toolbar, KIcon::SizeMedium );
00104   QFrame* storagePage = addPage( i18n("Storage"), i18n("Storage Settings"),
00105       icon );
00106 
00107   QVBoxLayout* topLevel = new QVBoxLayout( storagePage, 0, spacingHint() );
00108   QGridLayout* layout = new QGridLayout( topLevel, 4, 2 );
00109   layout->setColStretch( 1, 1 );
00110 
00111   // autosave
00112   _doAutoSaveW = new QCheckBox( i18n("Save tasks every"),
00113       storagePage, "_doAutoSaveW" );
00114   _autoSaveValueW = new QSpinBox(1, 60*24, 1, storagePage, "_autoSaveValueW");
00115   _autoSaveValueW->setSuffix(i18n(" minutes"));
00116 
00117   // iCalendar
00118   QLabel* _iCalFileLabel = new QLabel( i18n("iCalendar file:"), storagePage);
00119   _iCalFileW = new KURLRequester(storagePage, "_iCalFileW");
00120   _iCalFileW->setFilter(QString::fromLatin1("*.ics"));
00121 
00122   // add widgets to layout
00123   layout->addWidget(_doAutoSaveW, 0, 0);
00124   layout->addWidget(_autoSaveValueW, 0, 1);
00125   layout->addWidget(_iCalFileLabel, 1, 0 );
00126   layout->addWidget(_iCalFileW, 1, 1 );
00127 
00128   // checkboxes disable file selection controls
00129   connect( _doAutoSaveW, SIGNAL( clicked() ), this,
00130       SLOT( autoSaveCheckBoxChanged() ));
00131 }
00132 
00133 void Preferences::disableIdleDetection()
00134 {
00135   _doIdleDetectionW->setEnabled(false);
00136 }
00137 
00138 
00139 //---------------------------------------------------------------------------
00140 //                            SLOTS
00141 //---------------------------------------------------------------------------
00142 
00143 void Preferences::showDialog()
00144 {
00145 
00146   // set all widgets
00147   _iCalFileW->lineEdit()->setText(_iCalFileV);
00148 
00149   _doIdleDetectionW->setChecked(_doIdleDetectionV);
00150   _idleDetectValueW->setValue(_idleDetectValueV);
00151 
00152   _doAutoSaveW->setChecked(_doAutoSaveV);
00153   _autoSaveValueW->setValue(_autoSaveValueV);
00154 
00155   _promptDeleteW->setChecked(_promptDeleteV);
00156 
00157   _displaySessionW->setChecked(_displayColumnV[0]);
00158   _displayTimeW->setChecked(_displayColumnV[1]);
00159   _displayTotalSessionW->setChecked(_displayColumnV[2]);
00160   _displayTotalTimeW->setChecked(_displayColumnV[3]);
00161 
00162   // adapt visibility of preference items according
00163   // to settings
00164   idleDetectCheckBoxChanged();
00165   autoSaveCheckBoxChanged();
00166 
00167   show();
00168 }
00169 
00170 void Preferences::slotOk()
00171 {
00172 
00173   // storage
00174   _iCalFileV = _iCalFileW->lineEdit()->text();
00175 
00176   _doIdleDetectionV = _doIdleDetectionW->isChecked();
00177   _idleDetectValueV = _idleDetectValueW->value();
00178 
00179   _doAutoSaveV = _doAutoSaveW->isChecked();
00180   _autoSaveValueV = _autoSaveValueW->value();
00181 
00182   // behavior
00183   _promptDeleteV = _promptDeleteW->isChecked();
00184 
00185   // display
00186   _displayColumnV[0] = _displaySessionW->isChecked();
00187   _displayColumnV[1] = _displayTimeW->isChecked();
00188   _displayColumnV[2] = _displayTotalSessionW->isChecked();
00189   _displayColumnV[3] = _displayTotalTimeW->isChecked();
00190 
00191   emitSignals();
00192   save();
00193   KDialogBase::slotOk();
00194 }
00195 
00196 void Preferences::slotCancel()
00197 {
00198   KDialogBase::slotCancel();
00199 }
00200 
00201 void Preferences::idleDetectCheckBoxChanged()
00202 {
00203   _idleDetectValueW->setEnabled(_doIdleDetectionW->isChecked());
00204 }
00205 
00206 void Preferences::autoSaveCheckBoxChanged()
00207 {
00208   _autoSaveValueW->setEnabled(_doAutoSaveW->isChecked());
00209 }
00210 
00211 void Preferences::emitSignals()
00212 {
00213   emit iCalFile( _iCalFileV );
00214   emit detectIdleness( _doIdleDetectionV );
00215   emit idlenessTimeout( _idleDetectValueV );
00216   emit autoSave( _doAutoSaveV );
00217   emit autoSavePeriod( _autoSaveValueV );
00218   emit setupChanged();
00219 }
00220 
00221 QString Preferences::iCalFile() const
00222 {
00223   return _iCalFileV;
00224 }
00225 
00226 QString Preferences::activeCalendarFile() const
00227 {
00228   return _iCalFileV;
00229 }
00230 
00231 bool Preferences::detectIdleness() const
00232 {
00233   return _doIdleDetectionV;
00234 }
00235 
00236 int Preferences::idlenessTimeout() const
00237 {
00238   return _idleDetectValueV;
00239 }
00240 
00241 bool Preferences::autoSave() const
00242 {
00243   return _doAutoSaveV;
00244 }
00245 
00246 int Preferences::autoSavePeriod() const
00247 {
00248   return _autoSaveValueV;
00249 }
00250 
00251 bool Preferences::promptDelete() const
00252 {
00253     return _promptDeleteV;
00254 }
00255 
00256 bool Preferences::displayColumn(int n) const  { return _displayColumnV[n]; }
00257 
00258 
00259 QString Preferences::userRealName() const
00260 {
00261     return _userRealName;
00262 }
00263 
00264 //---------------------------------------------------------------------------
00265 //                                  Load and Save
00266 //---------------------------------------------------------------------------
00267 void Preferences::load()
00268 {
00269   KConfig &config = *kapp->config();
00270 
00271   config.setGroup( QString::fromLatin1("Idle detection") );
00272   _doIdleDetectionV = config.readBoolEntry( QString::fromLatin1("enabled"),
00273      true );
00274   _idleDetectValueV = config.readNumEntry(QString::fromLatin1("period"), 15);
00275 
00276   config.setGroup( QString::fromLatin1("Saving") );
00277   _iCalFileV = config.readPathEntry( QString::fromLatin1("ical file"),
00278       locateLocal( "appdata", QString::fromLatin1( "karm.ics")));
00279   _doAutoSaveV = config.readBoolEntry( QString::fromLatin1("auto save"),
00280       true);
00281   _autoSaveValueV = config.readNumEntry(
00282       QString::fromLatin1("auto save period"), 5);
00283   _promptDeleteV = config.readBoolEntry( QString::fromLatin1("prompt delete"),
00284       true);
00285 
00286   _displayColumnV[0] = config.readBoolEntry(
00287       QString::fromLatin1("display session time"), true);
00288   _displayColumnV[1] = config.readBoolEntry(
00289       QString::fromLatin1("display time"), true);
00290   _displayColumnV[2] = config.readBoolEntry(
00291       QString::fromLatin1("display total session time"), true);
00292   _displayColumnV[3] = config.readBoolEntry(
00293       QString::fromLatin1("display total time"), true);
00294 
00295   KEMailSettings settings;
00296   _userRealName = settings.getSetting( KEMailSettings::RealName );
00297 }
00298 
00299 void Preferences::save()
00300 {
00301   KConfig &config = *KGlobal::config();
00302 
00303   config.setGroup( QString::fromLatin1("Idle detection"));
00304   config.writeEntry( QString::fromLatin1("enabled"), _doIdleDetectionV);
00305   config.writeEntry( QString::fromLatin1("period"), _idleDetectValueV);
00306 
00307   config.setGroup( QString::fromLatin1("Saving"));
00308   config.writePathEntry( QString::fromLatin1("ical file"), _iCalFileV);
00309   config.writeEntry( QString::fromLatin1("auto save"), _doAutoSaveV);
00310   config.writeEntry( QString::fromLatin1("auto save period"), _autoSaveValueV);
00311   config.writeEntry( QString::fromLatin1("prompt delete"), _promptDeleteV);
00312 
00313   config.writeEntry( QString::fromLatin1("display session time"),
00314       _displayColumnV[0]);
00315   config.writeEntry( QString::fromLatin1("display time"),
00316       _displayColumnV[1]);
00317   config.writeEntry( QString::fromLatin1("display total session time"),
00318       _displayColumnV[2]);
00319   config.writeEntry( QString::fromLatin1("display total time"),
00320       _displayColumnV[3]);
00321 
00322   config.sync();
00323 
00324 }
00325 
00326 #include "preferences.moc"
KDE Logo
This file is part of the documentation for karm Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:53 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003