00001 #undef Unsorted // for --enable-final
00002 #include <tqcheckbox.h>
00003 #include <tqlabel.h>
00004 #include <tqstring.h>
00005 #include <tqspinbox.h>
00006 #include <tqlayout.h>
00007
00008 #include <tdeapplication.h>
00009 #include <tdeconfig.h>
00010 #include <kdebug.h>
00011 #include <tdeemailsettings.h>
00012 #include <kiconloader.h>
00013 #include <klineedit.h>
00014 #include <tdelocale.h>
00015 #include <kstandarddirs.h>
00016 #include <kurlrequester.h>
00017
00018 #include "preferences.h"
00019
00020 Preferences *Preferences::_instance = 0;
00021
00022 Preferences::Preferences( const TQString& icsFile )
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 if ( ! icsFile.isEmpty() ) _iCalFileV = icsFile;
00036
00037 }
00038
00039 Preferences *Preferences::instance( const TQString &icsfile )
00040 {
00041 if (_instance == 0) {
00042 _instance = new Preferences( icsfile );
00043 }
00044 return _instance;
00045 }
00046
00047 void Preferences::makeBehaviorPage()
00048 {
00049 TQPixmap icon = SmallIcon( "preferences-system", TDEIcon::SizeMedium);
00050 TQFrame* behaviorPage = addPage( i18n("Behavior"), i18n("Behavior Settings"),
00051 icon );
00052
00053 TQVBoxLayout* topLevel = new TQVBoxLayout( behaviorPage, 0, spacingHint() );
00054 TQGridLayout* layout = new TQGridLayout( topLevel, 2, 2 );
00055 layout->setColStretch( 1, 1 );
00056
00057 _doIdleDetectionW = new TQCheckBox
00058 ( i18n("Detect desktop as idle after"), behaviorPage, "_doIdleDetectionW");
00059 _idleDetectValueW = new TQSpinBox
00060 (1,60*24, 1, behaviorPage, "_idleDetectValueW");
00061 _idleDetectValueW->setSuffix(i18n(" min"));
00062 _promptDeleteW = new TQCheckBox
00063 ( i18n( "Prompt before deleting tasks" ), behaviorPage, "_promptDeleteW" );
00064
00065 layout->addWidget(_doIdleDetectionW, 0, 0 );
00066 layout->addWidget(_idleDetectValueW, 0, 1 );
00067 layout->addWidget(_promptDeleteW, 1, 0 );
00068
00069 topLevel->addStretch();
00070
00071 connect( _doIdleDetectionW, TQT_SIGNAL( clicked() ), this,
00072 TQT_SLOT( idleDetectCheckBoxChanged() ));
00073 }
00074
00075 void Preferences::makeDisplayPage()
00076 {
00077 TQPixmap icon = SmallIcon( "viewmag", TDEIcon::SizeMedium );
00078 TQFrame* displayPage = addPage( i18n("Display"), i18n("Display Settings"),
00079 icon );
00080
00081 TQVBoxLayout* topLevel = new TQVBoxLayout( displayPage, 0, spacingHint() );
00082 TQGridLayout* layout = new TQGridLayout( topLevel, 5, 2 );
00083 layout->setColStretch( 1, 1 );
00084
00085 TQLabel* _displayColumnsLabelW = new TQLabel( i18n("Columns displayed:"),
00086 displayPage );
00087 _displaySessionW = new TQCheckBox ( i18n("Session time"),
00088 displayPage, "_displaySessionW");
00089 _displayTimeW = new TQCheckBox ( i18n("Cumulative task time"),
00090 displayPage, "_displayTimeW");
00091 _displayTotalSessionW = new TQCheckBox( i18n("Total session time"),
00092 displayPage, "_displayTotalSessionW");
00093 _displayTotalTimeW = new TQCheckBox ( i18n("Total task time"),
00094 displayPage, "_displayTotalTimeW");
00095
00096 layout->addMultiCellWidget( _displayColumnsLabelW, 0, 0, 0, 1 );
00097 layout->addWidget(_displaySessionW, 1, 1 );
00098 layout->addWidget(_displayTimeW, 2, 1 );
00099 layout->addWidget(_displayTotalSessionW, 3, 1 );
00100 layout->addWidget(_displayTotalTimeW, 4, 1 );
00101
00102 topLevel->addStretch();
00103 }
00104
00105 void Preferences::makeStoragePage()
00106 {
00107 TQPixmap icon = SmallIcon( "kfm", TDEIcon::SizeMedium );
00108 TQFrame* storagePage = addPage( i18n("Storage"), i18n("Storage Settings"),
00109 icon );
00110
00111 TQVBoxLayout* topLevel = new TQVBoxLayout( storagePage, 0, spacingHint() );
00112 TQGridLayout* layout = new TQGridLayout( topLevel, 4, 2 );
00113 layout->setColStretch( 1, 1 );
00114
00115
00116 _doAutoSaveW = new TQCheckBox
00117 ( i18n("Save tasks every"), storagePage, "_doAutoSaveW" );
00118 _autoSaveValueW = new TQSpinBox(1, 60*24, 1, storagePage, "_autoSaveValueW");
00119 _autoSaveValueW->setSuffix(i18n(" min"));
00120
00121
00122 TQLabel* _iCalFileLabel = new TQLabel( i18n("iCalendar file:"), storagePage);
00123 _iCalFileW = new KURLRequester(storagePage, "_iCalFileW");
00124 _iCalFileW->setFilter(TQString::fromLatin1("*.ics"));
00125 _iCalFileW->setMode(KFile::File);
00126
00127
00128 _loggingW = new TQCheckBox
00129 ( i18n("Log history"), storagePage, "_loggingW" );
00130
00131
00132 layout->addWidget(_doAutoSaveW, 0, 0);
00133 layout->addWidget(_autoSaveValueW, 0, 1);
00134 layout->addWidget(_iCalFileLabel, 1, 0 );
00135 layout->addWidget(_iCalFileW, 1, 1 );
00136 layout->addWidget(_loggingW, 2, 0 );
00137
00138 topLevel->addStretch();
00139
00140
00141 connect( _doAutoSaveW, TQT_SIGNAL( clicked() ),
00142 this, TQT_SLOT( autoSaveCheckBoxChanged() ));
00143 }
00144
00145 void Preferences::disableIdleDetection()
00146 {
00147 _doIdleDetectionW->setEnabled(false);
00148 _idleDetectValueW->setEnabled(false);
00149 }
00150
00151
00152
00153
00154
00155
00156 void Preferences::showDialog()
00157 {
00158
00159
00160 _iCalFileW->lineEdit()->setText(_iCalFileV);
00161
00162 _doIdleDetectionW->setChecked(_doIdleDetectionV);
00163 _idleDetectValueW->setValue(_idleDetectValueV);
00164
00165 _doAutoSaveW->setChecked(_doAutoSaveV);
00166 _autoSaveValueW->setValue(_autoSaveValueV);
00167 _loggingW->setChecked(_loggingV);
00168
00169 _promptDeleteW->setChecked(_promptDeleteV);
00170
00171 _displaySessionW->setChecked(_displayColumnV[0]);
00172 _displayTimeW->setChecked(_displayColumnV[1]);
00173 _displayTotalSessionW->setChecked(_displayColumnV[2]);
00174 _displayTotalTimeW->setChecked(_displayColumnV[3]);
00175
00176
00177
00178 idleDetectCheckBoxChanged();
00179 autoSaveCheckBoxChanged();
00180
00181 show();
00182 }
00183
00184 void Preferences::slotOk()
00185 {
00186 kdDebug(5970) << "Entering Preferences::slotOk" << endl;
00187
00188 _iCalFileV = _iCalFileW->lineEdit()->text();
00189
00190 _doIdleDetectionV = _doIdleDetectionW->isChecked();
00191 _idleDetectValueV = _idleDetectValueW->value();
00192
00193 _doAutoSaveV = _doAutoSaveW->isChecked();
00194 _autoSaveValueV = _autoSaveValueW->value();
00195 _loggingV = _loggingW->isChecked();
00196
00197
00198 _promptDeleteV = _promptDeleteW->isChecked();
00199
00200
00201 _displayColumnV[0] = _displaySessionW->isChecked();
00202 _displayColumnV[1] = _displayTimeW->isChecked();
00203 _displayColumnV[2] = _displayTotalSessionW->isChecked();
00204 _displayColumnV[3] = _displayTotalTimeW->isChecked();
00205
00206 emitSignals();
00207 save();
00208 KDialogBase::slotOk();
00209 }
00210
00211 void Preferences::slotCancel()
00212 {
00213 kdDebug(5970) << "Entering Preferences::slotCancel" << endl;
00214 KDialogBase::slotCancel();
00215 }
00216
00217 void Preferences::idleDetectCheckBoxChanged()
00218 {
00219 _idleDetectValueW->setEnabled(_doIdleDetectionW->isChecked());
00220 }
00221
00222 void Preferences::autoSaveCheckBoxChanged()
00223 {
00224 _autoSaveValueW->setEnabled(_doAutoSaveW->isChecked());
00225 }
00226
00227 void Preferences::emitSignals()
00228 {
00229 kdDebug(5970) << "Entering Preferences::emitSignals" << endl;
00230 emit iCalFile( _iCalFileV );
00231 emit detectIdleness( _doIdleDetectionV );
00232 emit idlenessTimeout( _idleDetectValueV );
00233 emit autoSave( _doAutoSaveV );
00234 emit autoSavePeriod( _autoSaveValueV );
00235 emit setupChanged();
00236 }
00237
00238 TQString Preferences::iCalFile() const { return _iCalFileV; }
00239 TQString Preferences::activeCalendarFile() const { return _iCalFileV; }
00240 bool Preferences::detectIdleness() const { return _doIdleDetectionV; }
00241 int Preferences::idlenessTimeout() const { return _idleDetectValueV; }
00242 bool Preferences::autoSave() const { return _doAutoSaveV; }
00243 int Preferences::autoSavePeriod() const { return _autoSaveValueV; }
00244 bool Preferences::logging() const { return _loggingV; }
00245 bool Preferences::promptDelete() const { return _promptDeleteV; }
00246 TQString Preferences::setPromptDelete(bool prompt) { _promptDeleteV=prompt; return ""; }
00247 bool Preferences::displayColumn(int n) const { return _displayColumnV[n]; }
00248 TQString Preferences::userRealName() const { return _userRealName; }
00249
00250
00251
00252
00253 void Preferences::load()
00254 {
00255 TDEConfig &config = *kapp->config();
00256
00257 config.setGroup( TQString::fromLatin1("Idle detection") );
00258 _doIdleDetectionV = config.readBoolEntry( TQString::fromLatin1("enabled"),
00259 true );
00260 _idleDetectValueV = config.readNumEntry(TQString::fromLatin1("period"), 15);
00261
00262 config.setGroup( TQString::fromLatin1("Saving") );
00263 _iCalFileV = config.readPathEntry
00264 ( TQString::fromLatin1("ical file"),
00265 locateLocal( "appdata", TQString::fromLatin1( "karm.ics")));
00266 _doAutoSaveV = config.readBoolEntry
00267 ( TQString::fromLatin1("auto save"), true);
00268 _autoSaveValueV = config.readNumEntry
00269 ( TQString::fromLatin1("auto save period"), 5);
00270 _promptDeleteV = config.readBoolEntry
00271 ( TQString::fromLatin1("prompt delete"), true);
00272 _loggingV = config.readBoolEntry
00273 ( TQString::fromLatin1("logging"), true);
00274
00275 _displayColumnV[0] = config.readBoolEntry
00276 ( TQString::fromLatin1("display session time"), true);
00277 _displayColumnV[1] = config.readBoolEntry
00278 ( TQString::fromLatin1("display time"), true);
00279 _displayColumnV[2] = config.readBoolEntry
00280 ( TQString::fromLatin1("display total session time"), true);
00281 _displayColumnV[3] = config.readBoolEntry
00282 ( TQString::fromLatin1("display total time"), true);
00283
00284 KEMailSettings settings;
00285 _userRealName = settings.getSetting( KEMailSettings::RealName );
00286 }
00287
00288 void Preferences::save()
00289 {
00290 TDEConfig &config = *TDEGlobal::config();
00291
00292 config.setGroup( TQString::fromLatin1("Idle detection"));
00293 config.writeEntry( TQString::fromLatin1("enabled"), _doIdleDetectionV);
00294 config.writeEntry( TQString::fromLatin1("period"), _idleDetectValueV);
00295
00296 config.setGroup( TQString::fromLatin1("Saving"));
00297 config.writePathEntry( TQString::fromLatin1("ical file"), _iCalFileV);
00298 config.writeEntry( TQString::fromLatin1("auto save"), _doAutoSaveV);
00299 config.writeEntry( TQString::fromLatin1("logging"), _loggingV);
00300 config.writeEntry( TQString::fromLatin1("auto save period"), _autoSaveValueV);
00301 config.writeEntry( TQString::fromLatin1("prompt delete"), _promptDeleteV);
00302
00303 config.writeEntry( TQString::fromLatin1("display session time"),
00304 _displayColumnV[0]);
00305 config.writeEntry( TQString::fromLatin1("display time"),
00306 _displayColumnV[1]);
00307 config.writeEntry( TQString::fromLatin1("display total session time"),
00308 _displayColumnV[2]);
00309 config.writeEntry( TQString::fromLatin1("display total time"),
00310 _displayColumnV[3]);
00311
00312 config.sync();
00313 }
00314
00315
00316 bool Preferences::readBoolEntry( const TQString& key )
00317 {
00318 TDEConfig &config = *TDEGlobal::config();
00319 return config.readBoolEntry ( key, true );
00320 }
00321
00322 void Preferences::writeEntry( const TQString &key, bool value)
00323 {
00324 TDEConfig &config = *TDEGlobal::config();
00325 config.writeEntry( key, value );
00326 config.sync();
00327 }
00328
00329 void Preferences::deleteEntry( const TQString &key )
00330 {
00331 TDEConfig &config = *TDEGlobal::config();
00332 config.deleteEntry( key );
00333 config.sync();
00334 }
00335
00336 #include "preferences.moc"