2 #include <tqcheckbox.h>
8 #include <tdeapplication.h>
11 #include <tdeemailsettings.h>
12 #include <kiconloader.h>
13 #include <klineedit.h>
14 #include <tdelocale.h>
15 #include <kstandarddirs.h>
16 #include <kurlrequester.h>
18 #include "preferences.h"
22 Preferences::Preferences(
const TQString& icsFile )
23 : KDialogBase( IconList, i18n(
"Preferences"), Ok|Cancel, Ok )
26 setIconListAllVisible(
true );
35 if ( ! icsFile.isEmpty() ) _iCalFileV = icsFile;
39 Preferences *Preferences::instance(
const TQString &icsfile )
47 void Preferences::makeBehaviorPage()
49 TQPixmap icon = SmallIcon(
"preferences-system", TDEIcon::SizeMedium);
50 TQFrame* behaviorPage = addPage( i18n(
"Behavior"), i18n(
"Behavior Settings"),
53 TQVBoxLayout* topLevel =
new TQVBoxLayout( behaviorPage, 0, spacingHint() );
54 TQGridLayout* layout =
new TQGridLayout( topLevel, 2, 2 );
55 layout->setColStretch( 1, 1 );
57 _doIdleDetectionW =
new TQCheckBox
58 ( i18n(
"Detect desktop as idle after"), behaviorPage,
"_doIdleDetectionW");
59 _idleDetectValueW =
new TQSpinBox
60 (1,60*24, 1, behaviorPage,
"_idleDetectValueW");
61 _idleDetectValueW->setSuffix(i18n(
" min"));
62 _promptDeleteW =
new TQCheckBox
63 ( i18n(
"Prompt before deleting tasks" ), behaviorPage,
"_promptDeleteW" );
65 layout->addWidget(_doIdleDetectionW, 0, 0 );
66 layout->addWidget(_idleDetectValueW, 0, 1 );
67 layout->addWidget(_promptDeleteW, 1, 0 );
69 topLevel->addStretch();
71 connect( _doIdleDetectionW, TQ_SIGNAL( clicked() ),
this,
72 TQ_SLOT( idleDetectCheckBoxChanged() ));
75 void Preferences::makeDisplayPage()
77 TQPixmap icon = SmallIcon(
"viewmag", TDEIcon::SizeMedium );
78 TQFrame* displayPage = addPage( i18n(
"Display"), i18n(
"Display Settings"),
81 TQVBoxLayout* topLevel =
new TQVBoxLayout( displayPage, 0, spacingHint() );
82 TQGridLayout* layout =
new TQGridLayout( topLevel, 5, 2 );
83 layout->setColStretch( 1, 1 );
85 TQLabel* _displayColumnsLabelW =
new TQLabel( i18n(
"Columns displayed:"),
87 _displaySessionW =
new TQCheckBox ( i18n(
"Session time"),
88 displayPage,
"_displaySessionW");
89 _displayTimeW =
new TQCheckBox ( i18n(
"Cumulative task time"),
90 displayPage,
"_displayTimeW");
91 _displayTotalSessionW =
new TQCheckBox( i18n(
"Total session time"),
92 displayPage,
"_displayTotalSessionW");
93 _displayTotalTimeW =
new TQCheckBox ( i18n(
"Total task time"),
94 displayPage,
"_displayTotalTimeW");
96 layout->addMultiCellWidget( _displayColumnsLabelW, 0, 0, 0, 1 );
97 layout->addWidget(_displaySessionW, 1, 1 );
98 layout->addWidget(_displayTimeW, 2, 1 );
99 layout->addWidget(_displayTotalSessionW, 3, 1 );
100 layout->addWidget(_displayTotalTimeW, 4, 1 );
102 topLevel->addStretch();
105 void Preferences::makeStoragePage()
107 TQPixmap icon = SmallIcon(
"kfm", TDEIcon::SizeMedium );
108 TQFrame* storagePage = addPage( i18n(
"Storage"), i18n(
"Storage Settings"),
111 TQVBoxLayout* topLevel =
new TQVBoxLayout( storagePage, 0, spacingHint() );
112 TQGridLayout* layout =
new TQGridLayout( topLevel, 4, 2 );
113 layout->setColStretch( 1, 1 );
116 _doAutoSaveW =
new TQCheckBox
117 ( i18n(
"Save tasks every"), storagePage,
"_doAutoSaveW" );
118 _autoSaveValueW =
new TQSpinBox(1, 60*24, 1, storagePage,
"_autoSaveValueW");
119 _autoSaveValueW->setSuffix(i18n(
" min"));
122 TQLabel* _iCalFileLabel =
new TQLabel( i18n(
"iCalendar file:"), storagePage);
123 _iCalFileW =
new KURLRequester(storagePage,
"_iCalFileW");
124 _iCalFileW->setFilter(TQString::fromLatin1(
"*.ics"));
125 _iCalFileW->setMode(KFile::File);
128 _loggingW =
new TQCheckBox
129 ( i18n(
"Log history"), storagePage,
"_loggingW" );
132 layout->addWidget(_doAutoSaveW, 0, 0);
133 layout->addWidget(_autoSaveValueW, 0, 1);
134 layout->addWidget(_iCalFileLabel, 1, 0 );
135 layout->addWidget(_iCalFileW, 1, 1 );
136 layout->addWidget(_loggingW, 2, 0 );
138 topLevel->addStretch();
141 connect( _doAutoSaveW, TQ_SIGNAL( clicked() ),
142 this, TQ_SLOT( autoSaveCheckBoxChanged() ));
145 void Preferences::disableIdleDetection()
147 _doIdleDetectionW->setEnabled(
false);
148 _idleDetectValueW->setEnabled(
false);
156 void Preferences::showDialog()
160 _iCalFileW->lineEdit()->setText(_iCalFileV);
162 _doIdleDetectionW->setChecked(_doIdleDetectionV);
163 _idleDetectValueW->setValue(_idleDetectValueV);
165 _doAutoSaveW->setChecked(_doAutoSaveV);
166 _autoSaveValueW->setValue(_autoSaveValueV);
167 _loggingW->setChecked(_loggingV);
169 _promptDeleteW->setChecked(_promptDeleteV);
171 _displaySessionW->setChecked(_displayColumnV[0]);
172 _displayTimeW->setChecked(_displayColumnV[1]);
173 _displayTotalSessionW->setChecked(_displayColumnV[2]);
174 _displayTotalTimeW->setChecked(_displayColumnV[3]);
178 idleDetectCheckBoxChanged();
179 autoSaveCheckBoxChanged();
184 void Preferences::slotOk()
186 kdDebug(5970) <<
"Entering Preferences::slotOk" << endl;
188 _iCalFileV = _iCalFileW->lineEdit()->text();
190 _doIdleDetectionV = _doIdleDetectionW->isChecked();
191 _idleDetectValueV = _idleDetectValueW->value();
193 _doAutoSaveV = _doAutoSaveW->isChecked();
194 _autoSaveValueV = _autoSaveValueW->value();
195 _loggingV = _loggingW->isChecked();
198 _promptDeleteV = _promptDeleteW->isChecked();
201 _displayColumnV[0] = _displaySessionW->isChecked();
202 _displayColumnV[1] = _displayTimeW->isChecked();
203 _displayColumnV[2] = _displayTotalSessionW->isChecked();
204 _displayColumnV[3] = _displayTotalTimeW->isChecked();
208 KDialogBase::slotOk();
211 void Preferences::slotCancel()
213 kdDebug(5970) <<
"Entering Preferences::slotCancel" << endl;
214 KDialogBase::slotCancel();
217 void Preferences::idleDetectCheckBoxChanged()
219 _idleDetectValueW->setEnabled(_doIdleDetectionW->isChecked());
222 void Preferences::autoSaveCheckBoxChanged()
224 _autoSaveValueW->setEnabled(_doAutoSaveW->isChecked());
227 void Preferences::emitSignals()
229 kdDebug(5970) <<
"Entering Preferences::emitSignals" << endl;
230 emit iCalFile( _iCalFileV );
231 emit detectIdleness( _doIdleDetectionV );
232 emit idlenessTimeout( _idleDetectValueV );
233 emit autoSave( _doAutoSaveV );
234 emit autoSavePeriod( _autoSaveValueV );
238 TQString Preferences::iCalFile()
const {
return _iCalFileV; }
239 TQString Preferences::activeCalendarFile()
const {
return _iCalFileV; }
240 bool Preferences::detectIdleness()
const {
return _doIdleDetectionV; }
241 int Preferences::idlenessTimeout()
const {
return _idleDetectValueV; }
242 bool Preferences::autoSave()
const {
return _doAutoSaveV; }
243 int Preferences::autoSavePeriod()
const {
return _autoSaveValueV; }
244 bool Preferences::logging()
const {
return _loggingV; }
245 bool Preferences::promptDelete()
const {
return _promptDeleteV; }
246 TQString Preferences::setPromptDelete(
bool prompt) { _promptDeleteV=prompt;
return ""; }
247 bool Preferences::displayColumn(
int n)
const {
return _displayColumnV[n]; }
248 TQString Preferences::userRealName()
const {
return _userRealName; }
253 void Preferences::load()
255 TDEConfig &config = *kapp->config();
257 config.setGroup( TQString::fromLatin1(
"Idle detection") );
258 _doIdleDetectionV = config.readBoolEntry( TQString::fromLatin1(
"enabled"),
260 _idleDetectValueV = config.readNumEntry(TQString::fromLatin1(
"period"), 15);
262 config.setGroup( TQString::fromLatin1(
"Saving") );
263 _iCalFileV = config.readPathEntry
264 ( TQString::fromLatin1(
"ical file"),
265 locateLocal(
"appdata", TQString::fromLatin1(
"karm.ics")));
266 _doAutoSaveV = config.readBoolEntry
267 ( TQString::fromLatin1(
"auto save"),
true);
268 _autoSaveValueV = config.readNumEntry
269 ( TQString::fromLatin1(
"auto save period"), 5);
270 _promptDeleteV = config.readBoolEntry
271 ( TQString::fromLatin1(
"prompt delete"),
true);
272 _loggingV = config.readBoolEntry
273 ( TQString::fromLatin1(
"logging"),
true);
275 _displayColumnV[0] = config.readBoolEntry
276 ( TQString::fromLatin1(
"display session time"),
true);
277 _displayColumnV[1] = config.readBoolEntry
278 ( TQString::fromLatin1(
"display time"),
true);
279 _displayColumnV[2] = config.readBoolEntry
280 ( TQString::fromLatin1(
"display total session time"),
true);
281 _displayColumnV[3] = config.readBoolEntry
282 ( TQString::fromLatin1(
"display total time"),
true);
284 KEMailSettings settings;
285 _userRealName = settings.getSetting( KEMailSettings::RealName );
288 void Preferences::save()
290 TDEConfig &config = *TDEGlobal::config();
292 config.setGroup( TQString::fromLatin1(
"Idle detection"));
293 config.writeEntry( TQString::fromLatin1(
"enabled"), _doIdleDetectionV);
294 config.writeEntry( TQString::fromLatin1(
"period"), _idleDetectValueV);
296 config.setGroup( TQString::fromLatin1(
"Saving"));
297 config.writePathEntry( TQString::fromLatin1(
"ical file"), _iCalFileV);
298 config.writeEntry( TQString::fromLatin1(
"auto save"), _doAutoSaveV);
299 config.writeEntry( TQString::fromLatin1(
"logging"), _loggingV);
300 config.writeEntry( TQString::fromLatin1(
"auto save period"), _autoSaveValueV);
301 config.writeEntry( TQString::fromLatin1(
"prompt delete"), _promptDeleteV);
303 config.writeEntry( TQString::fromLatin1(
"display session time"),
305 config.writeEntry( TQString::fromLatin1(
"display time"),
307 config.writeEntry( TQString::fromLatin1(
"display total session time"),
309 config.writeEntry( TQString::fromLatin1(
"display total time"),
316 bool Preferences::readBoolEntry(
const TQString& key )
318 TDEConfig &config = *TDEGlobal::config();
319 return config.readBoolEntry ( key,
true );
322 void Preferences::writeEntry(
const TQString &key,
bool value)
324 TDEConfig &config = *TDEGlobal::config();
325 config.writeEntry( key, value );
329 void Preferences::deleteEntry(
const TQString &key )
331 TDEConfig &config = *TDEGlobal::config();
332 config.deleteEntry( key );
336 #include "preferences.moc"
Provide an interface to the configuration options for the program.