karm

preferences.cpp
1#undef Unsorted // for --enable-final
2#include <tqcheckbox.h>
3#include <tqlabel.h>
4#include <tqstring.h>
5#include <tqspinbox.h>
6#include <tqlayout.h>
7
8#include <tdeapplication.h> // tdeApp
9#include <tdeconfig.h>
10#include <kdebug.h>
11#include <tdeemailsettings.h>
12#include <kiconloader.h>
13#include <klineedit.h> // lineEdit()
14#include <tdelocale.h> // i18n
15#include <tdestandarddirs.h>
16#include <kurlrequester.h>
17
18#include "preferences.h"
19
20Preferences *Preferences::_instance = 0;
21
22Preferences::Preferences( const TQString& icsFile )
23 : KDialogBase( IconList, i18n("Preferences"), Ok|Cancel, Ok )
24{
25
26 setIconListAllVisible( true );
27
28 makeBehaviorPage();
29 makeDisplayPage();
30 makeStoragePage();
31
32 load();
33
34 // command-line option overrides what is stored in
35 if ( ! icsFile.isEmpty() ) _iCalFileV = icsFile;
36
37}
38
39Preferences *Preferences::instance( const TQString &icsfile )
40{
41 if (_instance == 0) {
42 _instance = new Preferences( icsfile );
43 }
44 return _instance;
45}
46
47void Preferences::makeBehaviorPage()
48{
49 TQPixmap icon = SmallIcon( "preferences-system", TDEIcon::SizeMedium);
50 TQFrame* behaviorPage = addPage( i18n("Behavior"), i18n("Behavior Settings"),
51 icon );
52
53 TQVBoxLayout* topLevel = new TQVBoxLayout( behaviorPage, 0, spacingHint() );
54 TQGridLayout* layout = new TQGridLayout( topLevel, 2, 2 );
55 layout->setColStretch( 1, 1 );
56
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" );
64
65 layout->addWidget(_doIdleDetectionW, 0, 0 );
66 layout->addWidget(_idleDetectValueW, 0, 1 );
67 layout->addWidget(_promptDeleteW, 1, 0 );
68
69 topLevel->addStretch();
70
71 connect( _doIdleDetectionW, TQ_SIGNAL( clicked() ), this,
72 TQ_SLOT( idleDetectCheckBoxChanged() ));
73}
74
75void Preferences::makeDisplayPage()
76{
77 TQPixmap icon = SmallIcon( "viewmag", TDEIcon::SizeMedium );
78 TQFrame* displayPage = addPage( i18n("Display"), i18n("Display Settings"),
79 icon );
80
81 TQVBoxLayout* topLevel = new TQVBoxLayout( displayPage, 0, spacingHint() );
82 TQGridLayout* layout = new TQGridLayout( topLevel, 5, 2 );
83 layout->setColStretch( 1, 1 );
84
85 TQLabel* _displayColumnsLabelW = new TQLabel( i18n("Columns displayed:"),
86 displayPage );
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");
95
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 );
101
102 topLevel->addStretch();
103}
104
105void Preferences::makeStoragePage()
106{
107 TQPixmap icon = SmallIcon( "kfm", TDEIcon::SizeMedium );
108 TQFrame* storagePage = addPage( i18n("Storage"), i18n("Storage Settings"),
109 icon );
110
111 TQVBoxLayout* topLevel = new TQVBoxLayout( storagePage, 0, spacingHint() );
112 TQGridLayout* layout = new TQGridLayout( topLevel, 4, 2 );
113 layout->setColStretch( 1, 1 );
114
115 // autosave
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"));
120
121 // iCalendar
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);
126
127 // Log time?
128 _loggingW = new TQCheckBox
129 ( i18n("Log history"), storagePage, "_loggingW" );
130
131 // add widgets to layout
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 );
137
138 topLevel->addStretch();
139
140 // checkboxes disable file selection controls
141 connect( _doAutoSaveW, TQ_SIGNAL( clicked() ),
142 this, TQ_SLOT( autoSaveCheckBoxChanged() ));
143}
144
145void Preferences::disableIdleDetection()
146{
147 _doIdleDetectionW->setEnabled(false);
148 _idleDetectValueW->setEnabled(false);
149}
150
151
152//---------------------------------------------------------------------------
153// SLOTS
154//---------------------------------------------------------------------------
155
156void Preferences::showDialog()
157{
158
159 // set all widgets
160 _iCalFileW->lineEdit()->setText(_iCalFileV);
161
162 _doIdleDetectionW->setChecked(_doIdleDetectionV);
163 _idleDetectValueW->setValue(_idleDetectValueV);
164
165 _doAutoSaveW->setChecked(_doAutoSaveV);
166 _autoSaveValueW->setValue(_autoSaveValueV);
167 _loggingW->setChecked(_loggingV);
168
169 _promptDeleteW->setChecked(_promptDeleteV);
170
171 _displaySessionW->setChecked(_displayColumnV[0]);
172 _displayTimeW->setChecked(_displayColumnV[1]);
173 _displayTotalSessionW->setChecked(_displayColumnV[2]);
174 _displayTotalTimeW->setChecked(_displayColumnV[3]);
175
176 // adapt visibility of preference items according
177 // to settings
178 idleDetectCheckBoxChanged();
179 autoSaveCheckBoxChanged();
180
181 show();
182}
183
184void Preferences::slotOk()
185{
186 kdDebug(5970) << "Entering Preferences::slotOk" << endl;
187 // storage
188 _iCalFileV = _iCalFileW->lineEdit()->text();
189
190 _doIdleDetectionV = _doIdleDetectionW->isChecked();
191 _idleDetectValueV = _idleDetectValueW->value();
192
193 _doAutoSaveV = _doAutoSaveW->isChecked();
194 _autoSaveValueV = _autoSaveValueW->value();
195 _loggingV = _loggingW->isChecked();
196
197 // behavior
198 _promptDeleteV = _promptDeleteW->isChecked();
199
200 // display
201 _displayColumnV[0] = _displaySessionW->isChecked();
202 _displayColumnV[1] = _displayTimeW->isChecked();
203 _displayColumnV[2] = _displayTotalSessionW->isChecked();
204 _displayColumnV[3] = _displayTotalTimeW->isChecked();
205
206 emitSignals();
207 save();
208 KDialogBase::slotOk();
209}
210
211void Preferences::slotCancel()
212{
213 kdDebug(5970) << "Entering Preferences::slotCancel" << endl;
214 KDialogBase::slotCancel();
215}
216
217void Preferences::idleDetectCheckBoxChanged()
218{
219 _idleDetectValueW->setEnabled(_doIdleDetectionW->isChecked());
220}
221
222void Preferences::autoSaveCheckBoxChanged()
223{
224 _autoSaveValueW->setEnabled(_doAutoSaveW->isChecked());
225}
226
227void Preferences::emitSignals()
228{
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 );
235 emit setupChanged();
236}
237
238TQString Preferences::iCalFile() const { return _iCalFileV; }
239TQString Preferences::activeCalendarFile() const { return _iCalFileV; }
240bool Preferences::detectIdleness() const { return _doIdleDetectionV; }
241int Preferences::idlenessTimeout() const { return _idleDetectValueV; }
242bool Preferences::autoSave() const { return _doAutoSaveV; }
243int Preferences::autoSavePeriod() const { return _autoSaveValueV; }
244bool Preferences::logging() const { return _loggingV; }
245bool Preferences::promptDelete() const { return _promptDeleteV; }
246TQString Preferences::setPromptDelete(bool prompt) { _promptDeleteV=prompt; return ""; }
247bool Preferences::displayColumn(int n) const { return _displayColumnV[n]; }
248TQString Preferences::userRealName() const { return _userRealName; }
249
250//---------------------------------------------------------------------------
251// Load and Save
252//---------------------------------------------------------------------------
253void Preferences::load()
254{
255 TDEConfig &config = *tdeApp->config();
256
257 config.setGroup( TQString::fromLatin1("Idle detection") );
258 _doIdleDetectionV = config.readBoolEntry( TQString::fromLatin1("enabled"),
259 true );
260 _idleDetectValueV = config.readNumEntry(TQString::fromLatin1("period"), 15);
261
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);
274
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);
283
284 KEMailSettings settings;
285 _userRealName = settings.getSetting( KEMailSettings::RealName );
286}
287
288void Preferences::save()
289{
290 TDEConfig &config = *TDEGlobal::config();
291
292 config.setGroup( TQString::fromLatin1("Idle detection"));
293 config.writeEntry( TQString::fromLatin1("enabled"), _doIdleDetectionV);
294 config.writeEntry( TQString::fromLatin1("period"), _idleDetectValueV);
295
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);
302
303 config.writeEntry( TQString::fromLatin1("display session time"),
304 _displayColumnV[0]);
305 config.writeEntry( TQString::fromLatin1("display time"),
306 _displayColumnV[1]);
307 config.writeEntry( TQString::fromLatin1("display total session time"),
308 _displayColumnV[2]);
309 config.writeEntry( TQString::fromLatin1("display total time"),
310 _displayColumnV[3]);
311
312 config.sync();
313}
314
315// HACK: this entire config dialog should be upgraded to TDEConfigXT
316bool Preferences::readBoolEntry( const TQString& key )
317{
318 TDEConfig &config = *TDEGlobal::config();
319 return config.readBoolEntry ( key, true );
320}
321
322void Preferences::writeEntry( const TQString &key, bool value)
323{
324 TDEConfig &config = *TDEGlobal::config();
325 config.writeEntry( key, value );
326 config.sync();
327}
328
329void Preferences::deleteEntry( const TQString &key )
330{
331 TDEConfig &config = *TDEGlobal::config();
332 config.deleteEntry( key );
333 config.sync();
334}
335
336#include "preferences.moc"
Provide an interface to the configuration options for the program.
Definition: preferences.h:17