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>
00009
#include <kconfig.h>
00010
#include <kdebug.h>
00011
#include <kemailsettings.h>
00012
#include <kiconloader.h>
00013
#include <klineedit.h>
00014
#include <klocale.h>
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
00056 ( i18n(
"Detect desktop as idle after"), behaviorPage,
"_doIdleDetectionW");
00057 _idleDetectValueW =
new QSpinBox
00058 (1,60*24, 1, behaviorPage,
"_idleDetectValueW");
00059 _idleDetectValueW->setSuffix(i18n(
" minutes"));
00060 _promptDeleteW =
new QCheckBox
00061 ( i18n(
"Prompt before deleting tasks" ), 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
00112 _doAutoSaveW =
new QCheckBox
00113 ( i18n(
"Save tasks every"), storagePage,
"_doAutoSaveW" );
00114 _autoSaveValueW =
new QSpinBox(1, 60*24, 1, storagePage,
"_autoSaveValueW");
00115 _autoSaveValueW->setSuffix(i18n(
" minutes"));
00116
00117
00118
QLabel* _iCalFileLabel =
new QLabel( i18n(
"iCalendar file:"), storagePage);
00119 _iCalFileW =
new KURLRequester(storagePage,
"_iCalFileW");
00120 _iCalFileW->setFilter(QString::fromLatin1(
"*.ics"));
00121
00122
00123 _loggingW =
new QCheckBox
00124 ( i18n(
"Log history"), storagePage,
"_loggingW" );
00125
00126
00127 layout->addWidget(_doAutoSaveW, 0, 0);
00128 layout->addWidget(_autoSaveValueW, 0, 1);
00129 layout->addWidget(_iCalFileLabel, 1, 0 );
00130 layout->addWidget(_iCalFileW, 1, 1 );
00131 layout->addWidget(_loggingW, 2, 0 );
00132
00133
00134 connect( _doAutoSaveW, SIGNAL( clicked() ),
00135
this, SLOT( autoSaveCheckBoxChanged() ));
00136 }
00137
00138
void Preferences::disableIdleDetection()
00139 {
00140 _doIdleDetectionW->setEnabled(
false);
00141 }
00142
00143
00144
00145
00146
00147
00148
void Preferences::showDialog()
00149 {
00150
00151
00152 _iCalFileW->lineEdit()->setText(_iCalFileV);
00153
00154 _doIdleDetectionW->setChecked(_doIdleDetectionV);
00155 _idleDetectValueW->setValue(_idleDetectValueV);
00156
00157 _doAutoSaveW->setChecked(_doAutoSaveV);
00158 _autoSaveValueW->setValue(_autoSaveValueV);
00159 _loggingW->setChecked(_loggingV);
00160
00161 _promptDeleteW->setChecked(_promptDeleteV);
00162
00163 _displaySessionW->setChecked(_displayColumnV[0]);
00164 _displayTimeW->setChecked(_displayColumnV[1]);
00165 _displayTotalSessionW->setChecked(_displayColumnV[2]);
00166 _displayTotalTimeW->setChecked(_displayColumnV[3]);
00167
00168
00169
00170 idleDetectCheckBoxChanged();
00171 autoSaveCheckBoxChanged();
00172
00173 show();
00174 }
00175
00176
void Preferences::slotOk()
00177 {
00178
00179
00180 _iCalFileV = _iCalFileW->lineEdit()->text();
00181
00182 _doIdleDetectionV = _doIdleDetectionW->isChecked();
00183 _idleDetectValueV = _idleDetectValueW->value();
00184
00185 _doAutoSaveV = _doAutoSaveW->isChecked();
00186 _autoSaveValueV = _autoSaveValueW->value();
00187 _loggingV = _loggingW->isChecked();
00188
00189
00190 _promptDeleteV = _promptDeleteW->isChecked();
00191
00192
00193 _displayColumnV[0] = _displaySessionW->isChecked();
00194 _displayColumnV[1] = _displayTimeW->isChecked();
00195 _displayColumnV[2] = _displayTotalSessionW->isChecked();
00196 _displayColumnV[3] = _displayTotalTimeW->isChecked();
00197
00198 emitSignals();
00199 save();
00200 KDialogBase::slotOk();
00201 }
00202
00203
void Preferences::slotCancel()
00204 {
00205 KDialogBase::slotCancel();
00206 }
00207
00208
void Preferences::idleDetectCheckBoxChanged()
00209 {
00210 _idleDetectValueW->setEnabled(_doIdleDetectionW->isChecked());
00211 }
00212
00213
void Preferences::autoSaveCheckBoxChanged()
00214 {
00215 _autoSaveValueW->setEnabled(_doAutoSaveW->isChecked());
00216 }
00217
00218
void Preferences::emitSignals()
00219 {
00220 emit iCalFile( _iCalFileV );
00221 emit detectIdleness( _doIdleDetectionV );
00222 emit idlenessTimeout( _idleDetectValueV );
00223 emit autoSave( _doAutoSaveV );
00224 emit autoSavePeriod( _autoSaveValueV );
00225 emit setupChanged();
00226 }
00227
00228
QString Preferences::iCalFile() const {
return _iCalFileV; }
00229
QString Preferences::activeCalendarFile()
const {
return _iCalFileV; }
00230
bool Preferences::detectIdleness() const {
return _doIdleDetectionV; }
00231
int Preferences::idlenessTimeout() const {
return _idleDetectValueV; }
00232
bool Preferences::autoSave() const {
return _doAutoSaveV; }
00233
int Preferences::autoSavePeriod() const {
return _autoSaveValueV; }
00234
bool Preferences::logging() const {
return _loggingV; }
00235
bool Preferences::promptDelete() const {
return _promptDeleteV; }
00236
bool Preferences::displayColumn(
int n)
const {
return _displayColumnV[n]; }
00237
QString Preferences::userRealName() const {
return _userRealName; }
00238
00239
00240
00241
00242
void Preferences::load()
00243 {
00244 KConfig &config = *kapp->config();
00245
00246 config.setGroup( QString::fromLatin1(
"Idle detection") );
00247 _doIdleDetectionV = config.readBoolEntry( QString::fromLatin1(
"enabled"),
00248
true );
00249 _idleDetectValueV = config.readNumEntry(QString::fromLatin1(
"period"), 15);
00250
00251 config.setGroup( QString::fromLatin1(
"Saving") );
00252 _iCalFileV = config.readPathEntry
00253 ( QString::fromLatin1(
"ical file"),
00254 locateLocal(
"appdata", QString::fromLatin1(
"karm.ics")));
00255 _doAutoSaveV = config.readBoolEntry
00256 ( QString::fromLatin1(
"auto save"),
true);
00257 _autoSaveValueV = config.readNumEntry
00258 ( QString::fromLatin1(
"auto save period"), 5);
00259 _promptDeleteV = config.readBoolEntry
00260 ( QString::fromLatin1(
"prompt delete"),
true);
00261 _loggingV = config.readBoolEntry
00262 ( QString::fromLatin1(
"logging"),
true);
00263
00264 _displayColumnV[0] = config.readBoolEntry
00265 ( QString::fromLatin1(
"display session time"),
true);
00266 _displayColumnV[1] = config.readBoolEntry
00267 ( QString::fromLatin1(
"display time"),
true);
00268 _displayColumnV[2] = config.readBoolEntry
00269 ( QString::fromLatin1(
"display total session time"),
true);
00270 _displayColumnV[3] = config.readBoolEntry
00271 ( QString::fromLatin1(
"display total time"),
true);
00272
00273 KEMailSettings settings;
00274 _userRealName = settings.getSetting( KEMailSettings::RealName );
00275 }
00276
00277
void Preferences::save()
00278 {
00279 KConfig &config = *KGlobal::config();
00280
00281 config.setGroup( QString::fromLatin1(
"Idle detection"));
00282 config.writeEntry( QString::fromLatin1(
"enabled"), _doIdleDetectionV);
00283 config.writeEntry( QString::fromLatin1(
"period"), _idleDetectValueV);
00284
00285 config.setGroup( QString::fromLatin1(
"Saving"));
00286 config.writePathEntry( QString::fromLatin1(
"ical file"), _iCalFileV);
00287 config.writeEntry( QString::fromLatin1(
"auto save"), _doAutoSaveV);
00288 config.writeEntry( QString::fromLatin1(
"logging"), _loggingV);
00289 config.writeEntry( QString::fromLatin1(
"auto save period"), _autoSaveValueV);
00290 config.writeEntry( QString::fromLatin1(
"prompt delete"), _promptDeleteV);
00291
00292 config.writeEntry( QString::fromLatin1(
"display session time"),
00293 _displayColumnV[0]);
00294 config.writeEntry( QString::fromLatin1(
"display time"),
00295 _displayColumnV[1]);
00296 config.writeEntry( QString::fromLatin1(
"display total session time"),
00297 _displayColumnV[2]);
00298 config.writeEntry( QString::fromLatin1(
"display total time"),
00299 _displayColumnV[3]);
00300
00301 config.sync();
00302 }
00303
00304
00305
bool Preferences::readBoolEntry(
const QString& key )
00306 {
00307 KConfig &config = *KGlobal::config();
00308
return config.readBoolEntry ( key,
true );
00309 }
00310
00311
void Preferences::writeEntry(
const QString &key,
bool value)
00312 {
00313 KConfig &config = *KGlobal::config();
00314 config.writeEntry( key, value );
00315 config.sync();
00316 }
00317
00318
void Preferences::deleteEntry(
const QString &key )
00319 {
00320 KConfig &config = *KGlobal::config();
00321 config.deleteEntry( key );
00322 config.sync();
00323 }
00324
00325
#include "preferences.moc"