summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/configuration.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/configuration.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/configuration.cpp459
1 files changed, 0 insertions, 459 deletions
diff --git a/pwmanager/pwmanager/configuration.cpp b/pwmanager/pwmanager/configuration.cpp
deleted file mode 100644
index 8d67977..0000000
--- a/pwmanager/pwmanager/configuration.cpp
+++ b/dev/null
@@ -1,459 +0,0 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "configuration.h"
21#if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
22
23#include <kconfigdialog.h>
24#include <kfiledialog.h>
25#include <klocale.h>
26#include <kfontrequester.h>
27
28#include <qcheckbox.h>
29#include <qcombobox.h>
30#include <qlabel.h>
31#include <qlineedit.h>
32#include <qpushbutton.h>
33#include <qgroupbox.h>
34#include <qfileinfo.h>
35#include <qfontdialog.h>
36#include <qspinbox.h>
37#include <qvalidator.h>
38#include <qsqlpropertymap.h>
39#include <qlayout.h>
40
41#include <stdlib.h>
42#include <stdio.h>
43
44 #define INITIAL_CONFWND_SIZE(QSize(600, 450))
45
46
47/*********************************************************
48 ** class Configuration **
49 *********************************************************/
50
51Configuration * Configuration::_obj (0);
52
53Configuration::Configuration()
54{
55 skel = new KConfigSkeleton;
56 initSkel();
57 readConfig();
58}
59
60Configuration::~Configuration()
61{
62 writeConfig();
63 delete_ifnot_null(skel);
64}
65
66void Configuration::initSkel()
67{
68 skel->setCurrentGroup("GLOBAL");
69 skel->addItemString("autoStart", cGlobAutoStart);
70 skel->addItemString("browserCommand", cGlobBrowserCommand, CONF_DEFAULT_BROWSERCOMMAND);
71 skel->addItemString("xtermCommand", cGlobXtermCommand, CONF_DEFAULT_XTERMCOMMAND);
72 skel->addItemFont("entryFont", cGlobEntryFont);
73 skel->addItemInt("pwTimeout", cGlobPwTimeout, CONF_DEFAULT_PWTIMEOUT);
74 skel->addItemInt("lockTimeout", cGlobLockTimeout, CONF_DEFAULT_LOCKTIMEOUT);
75 skel->addItemInt("compression", cGlobCompression, CONF_DEFAULT_COMPRESSION);
76 skel->addItemInt("filePermissions", cGlobFilePermissions, CONF_DEFAULT_FILEPERMISSIONS);
77 skel->addItemInt("minimizeLock", cGlobMinimizeLock, CONF_DEFAULT_MINIMIZELOCK);
78 skel->addItemBool("unlockOnOpen", cGlobUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN);
79 skel->addItemBool("tray", cGlobTray, CONF_DEFAULT_TRAY);
80 skel->addItemBool("makeFileBackup", cGlobMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP);
81 skel->addItemBool("autostartDeeplocked", cGlobAutostartDeepLocked, CONF_DEFAULT_AUTOSTART_DEEPL);
82 skel->addItemBool("autoDeepLock", cGlobAutoDeepLock, CONF_DEFAULT_AUTODEEPLOCK);
83 skel->addItemBool("kwalletEmu", cGlobKwalletEmu, CONF_DEFAULT_KWALLETEMU);
84 skel->addItemBool("newEntrLockStat", cGlobNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT);
85
86 skel->setCurrentGroup("WND");
87 skel->addItemSize("MainWndSize", cWndMainWndSize);
88 skel->addItemInt("MainViewStyle", cWndMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE);
89 skel->addItemBool("autoMinimizeOnStart", cWndAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE);
90 skel->addItemBool("close", cWndClose, CONF_DEFAULT_WNDCLOSE);
91}
92
93bool Configuration::showConfWnd(QWidget *parent)
94{
95 bool ret = true;
96 KConfigDialog *confDlg;
97 confDlg = new KConfigDialog(parent, i18n("Main configuration").latin1(), skel,
98 KDialogBase::IconList,
99 KConfigDialog::Default | KConfigDialog::Ok |
100 KConfigDialog::Cancel | KConfigDialog::Help,
101 KConfigDialog::Ok, true);
102 ConfPageGlobal *confPageGlobal = new ConfPageGlobal;
103 ConfPageLookNFeel *confPageLookNFeel = new ConfPageLookNFeel;
104 ConfPageFile *confPageFile = new ConfPageFile;
105 ConfPageTimeouts *confPageTimeouts = new ConfPageTimeouts;
106 ConfPageExtApps *confPageExtApps = new ConfPageExtApps;
107 ConfPageAutostart *confPageAutostart = new ConfPageAutostart;
108 confDlg->addPage(confPageGlobal, i18n("General"), "pwmanager");
109 confDlg->addPage(confPageLookNFeel, i18n("Look & Feel"), "fonts");
110 confDlg->addPage(confPageFile, i18n("Files"), "filesave");
111 confDlg->addPage(confPageTimeouts, i18n("Timeouts"), "clock");
112 confDlg->addPage(confPageExtApps, i18n("External Applications"), "gear");
113 confDlg->addPage(confPageAutostart, i18n("Autostart"), "fileopen");
114 confDlg->resize(INITIAL_CONFWND_SIZE);
115 if (confDlg->exec() == 0)
116 ret = false;
117 delete confPageGlobal;
118 delete confPageLookNFeel;
119 delete confPageFile;
120 delete confPageTimeouts;
121 delete confPageExtApps;
122 delete confPageAutostart;
123 return ret;
124}
125
126
127/*********************************************************
128 ** class OctLineEdit **
129 *********************************************************/
130
131OctLineEdit::OctLineEdit(QWidget *parent, const char *name)
132 : QLineEdit(parent, name)
133{
134}
135
136OctLineEdit::~OctLineEdit()
137{
138}
139
140void OctLineEdit::setText(const QString &t)
141{
142 bool ok;
143 int tmp = t.toInt(&ok, 10);
144 if (!ok)
145 return;
146 QString ret;
147 ret.setNum(tmp, 8);
148 QLineEdit::setText(ret);
149}
150
151QString OctLineEdit::text() const
152{
153 bool ok;
154 QString ret;
155 QString t(QLineEdit::text());
156 int tmp = t.toInt(&ok, 8);
157 if (!ok)
158 return ret;
159 ret.setNum(tmp, 10);
160 return ret;
161}
162
163void OctLineEdit::keyPressEvent(QKeyEvent *e)
164{
165 int key = e->key();
166 switch (key) {
167 case Qt::Key_0:
168 case Qt::Key_1:
169 case Qt::Key_2:
170 case Qt::Key_3:
171 case Qt::Key_4:
172 case Qt::Key_5:
173 case Qt::Key_6:
174 case Qt::Key_7:
175 case Qt::Key_Escape:
176 case Qt::Key_Backtab:
177 case Qt::Key_Backspace:
178 case Qt::Key_Return:
179 case Qt::Key_Enter:
180 case Qt::Key_Insert:
181 case Qt::Key_Delete:
182 case Qt::Key_Home:
183 case Qt::Key_End:
184 case Qt::Key_Left:
185 case Qt::Key_Up:
186 case Qt::Key_Right:
187 case Qt::Key_Down:
188 e->accept();
189 QLineEdit::keyPressEvent(e);
190 break;
191 default:
192 e->ignore();
193 }
194}
195
196
197/*********************************************************
198 ** class ConfPageGlobal **
199 *********************************************************/
200
201ConfPageGlobal::ConfPageGlobal(QWidget *parent, const char *name, WFlags f)
202 : QWidget(parent, name, f)
203{
204 QCheckBox *kcfg_tray;
205 QCheckBox *kcfg_autoMinimizeOnStart;
206 QCheckBox *kcfg_unlockOnOpen;
207 QCheckBox *kcfg_newEntrLockStat;
208 QCheckBox *kcfg_close;
209 QComboBox *kcfg_minimizeLock;
210 QLabel *kcfg_minimizeLock_label;
211
212 QBoxLayout *l = new QVBoxLayout(this);
213 l->setSpacing(4);
214 kcfg_tray = new QCheckBox(i18n("Show icon in system-tray"), this, "kcfg_tray");
215 l->addWidget(kcfg_tray);
216 kcfg_autoMinimizeOnStart = new QCheckBox(i18n("auto-minimize to tray on startup"),
217 this, "kcfg_autoMinimizeOnStart");
218 l->addWidget(kcfg_autoMinimizeOnStart);
219 kcfg_unlockOnOpen = new QCheckBox(i18n("Open document with passwords unlocked"),
220 this, "kcfg_unlockOnOpen");
221 l->addWidget(kcfg_unlockOnOpen);
222#ifdef CONFIG_KWALLETIF
223 QCheckBox *kcfg_kwalletEmu;
224 kcfg_kwalletEmu = new QCheckBox(i18n("KWallet emulation"),
225 this, "kcfg_kwalletEmu");
226 l->addWidget(kcfg_kwalletEmu);
227#endif // CONFIG_KWALLETIF
228 kcfg_newEntrLockStat = new QCheckBox(i18n("Automatically lock new entries"),
229 this, "kcfg_newEntrLockStat");
230 l->addWidget(kcfg_newEntrLockStat);
231 kcfg_close = new QCheckBox(i18n("Do not minimize windows into tray. (Close the window)"),
232 this, "kcfg_close");
233 l->addWidget(kcfg_close);
234 l->addSpacing(4);
235 QBoxLayout *hl = new QHBoxLayout(this);
236 hl->setSpacing(10);
237 kcfg_minimizeLock_label = new QLabel(i18n("auto-lock on minimize:"), this);
238 hl->addWidget(kcfg_minimizeLock_label);
239 kcfg_minimizeLock = new QComboBox(this, "kcfg_minimizeLock");
240 hl->addStretch();
241 hl->addWidget(kcfg_minimizeLock);
242 kcfg_minimizeLock->insertItem(i18n("don't lock"));
243 kcfg_minimizeLock->insertItem(i18n("normal lock"));
244 kcfg_minimizeLock->insertItem(i18n("deep-lock"));
245 l->addLayout(hl);
246 l->addStretch();
247}
248
249
250/*********************************************************
251 ** class ConfPageLookNFeel **
252 *********************************************************/
253
254ConfPageLookNFeel::ConfPageLookNFeel(QWidget *parent, const char *name, WFlags f)
255 : QWidget(parent, name, f)
256{
257 QComboBox *kcfg_MainViewStyle;
258 QLabel *kcfg_MainViewStyle_label;
259 KFontRequester *kcfg_entryFont;
260 QGroupBox *kcfg_entryFont_box;
261
262 QBoxLayout *l = new QVBoxLayout(this);
263 l->setSpacing(10);
264 // font
265 kcfg_entryFont_box = new QGroupBox(i18n("Font for the password entries:"), this);
266 l->addWidget(kcfg_entryFont_box);
267 kcfg_entryFont_box->setColumns(1);
268 kcfg_entryFont = new KFontRequester(kcfg_entryFont_box, "kcfg_entryFont", false);
269 // wnd style
270 QBoxLayout *hl = new QHBoxLayout(this);
271 hl->setSpacing(10);
272 kcfg_MainViewStyle_label = new QLabel(i18n("Window-style:"), this);
273 hl->addWidget(kcfg_MainViewStyle_label);
274 kcfg_MainViewStyle = new QComboBox(this, "kcfg_MainViewStyle");
275 hl->addStretch();
276 hl->addWidget(kcfg_MainViewStyle);
277 kcfg_MainViewStyle->insertItem(i18n("Category on top"));
278 kcfg_MainViewStyle->insertItem(i18n("Category-list left"));
279 l->addLayout(hl);
280 l->addStretch();
281}
282
283
284/*********************************************************
285 ** class ConfPageFile **
286 *********************************************************/
287
288ConfPageFile::ConfPageFile(QWidget *parent, const char *name, WFlags f)
289 : QWidget(parent, name, f)
290{
291 QComboBox *kcfg_compression;
292 QLabel *kcfg_compression_label;
293 OctLineEdit *kcfg_filePermissions;
294 QLabel *kcfg_filePermissions_label;
295 QCheckBox *kcfg_makeFileBackup;
296
297 QBoxLayout *l = new QVBoxLayout(this);
298 l->setSpacing(10);
299 // compression
300 QBoxLayout *hl = new QHBoxLayout(this);
301 hl->setSpacing(10);
302 kcfg_compression_label = new QLabel(i18n("*.pwm file compression:"), this);
303 hl->addWidget(kcfg_compression_label);
304 kcfg_compression = new QComboBox(this, "kcfg_compression");
305 hl->addStretch();
306 hl->addWidget(kcfg_compression);
307 kcfg_compression->insertItem(i18n("none"));
308 kcfg_compression->insertItem(i18n("gzip"));
309 kcfg_compression->insertItem(i18n("bzip2"));
310 l->addLayout(hl);
311 // permissions
312 hl = new QHBoxLayout(this);
313 hl->setSpacing(10);
314 kcfg_filePermissions_label = new QLabel(i18n("permissions:"), this);
315 hl->addWidget(kcfg_filePermissions_label);
316 kcfg_filePermissions = new OctLineEdit(this, "kcfg_filePermissions");
317 hl->addStretch();
318 hl->addWidget(kcfg_filePermissions);
319 kcfg_filePermissions->setMaxLength(3);
320 l->addLayout(hl);
321 // backup
322 kcfg_makeFileBackup = new QCheckBox(i18n("Make file backup before saving"),
323 this, "kcfg_makeFileBackup");
324 l->addWidget(kcfg_makeFileBackup);
325 l->addStretch();
326}
327
328
329/*********************************************************
330 ** class ConfPageTimeouts **
331 *********************************************************/
332
333ConfPageTimeouts::ConfPageTimeouts(QWidget *parent, const char *name, WFlags f)
334 : QWidget(parent, name, f)
335{
336 QSpinBox *kcfg_pwTimeout;
337 QLabel *kcfg_pwTimeout_label;
338 QSpinBox *kcfg_lockTimeout;
339 QLabel *kcfg_lockTimeout_label;
340 QCheckBox *kcfg_autoDeepLock;
341
342 QBoxLayout *l = new QVBoxLayout(this);
343 l->setSpacing(10);
344 // pw timeout
345 QBoxLayout *hl = new QHBoxLayout(this);
346 hl->setSpacing(10);
347 kcfg_pwTimeout_label = new QLabel(i18n("Password timeout (timeout to hold "
348 "password in memory, so you don't have "
349 "to re-enter it, if you already have "
350 "entered it) [set to 0 to disable]:"),
351 this);
352 hl->addWidget(kcfg_pwTimeout_label);
353 kcfg_pwTimeout_label->setAlignment(QLabel::WordBreak);
354 kcfg_pwTimeout = new QSpinBox(this, "kcfg_pwTimeout");
355 hl->addStretch();
356 hl->addWidget(kcfg_pwTimeout);
357 l->addLayout(hl);
358 // lock timeout
359 hl = new QHBoxLayout(this);
360 hl->setSpacing(10);
361 kcfg_lockTimeout_label = new QLabel(i18n("Auto-lock timeout (auto lock document "
362 "after this amount of seconds) "
363 "[set to 0 to disable]:"),
364 this);
365 hl->addWidget(kcfg_lockTimeout_label);
366 kcfg_lockTimeout_label->setAlignment(QLabel::WordBreak);
367 kcfg_lockTimeout = new QSpinBox(this, "kcfg_lockTimeout");
368 hl->addStretch();
369 hl->addWidget(kcfg_lockTimeout);
370 l->addLayout(hl);
371 // auto deep lock checkbox
372 kcfg_autoDeepLock = new QCheckBox(i18n("deep-lock on autolock"),
373 this, "kcfg_autoDeepLock");
374 l->addWidget(kcfg_autoDeepLock);
375 l->addStretch();
376}
377
378
379/*********************************************************
380 ** class ConfPageExtApps **
381 *********************************************************/
382
383ConfPageExtApps::ConfPageExtApps(QWidget *parent, const char *name, WFlags f)
384 : QWidget(parent, name, f)
385{
386 QLineEdit *kcfg_browserCommand;
387 QLabel *kcfg_browserCommand_label;
388 QLineEdit *kcfg_xtermCommand;
389 QLabel *kcfg_xtermCommand_label;
390
391 QBoxLayout *l = new QVBoxLayout(this);
392 l->setSpacing(4);
393 // browser command
394 QBoxLayout *hl = new QHBoxLayout(this);
395 hl->setSpacing(10);
396 kcfg_browserCommand_label = new QLabel(i18n("Favourite browser:"), this);
397 hl->addWidget(kcfg_browserCommand_label);
398 kcfg_browserCommand = new QLineEdit(this, "kcfg_browserCommand");
399 hl->addStretch();
400 hl->addWidget(kcfg_browserCommand);
401 l->addLayout(hl);
402 // xterm command
403 hl = new QHBoxLayout(this);
404 hl->setSpacing(10);
405 kcfg_xtermCommand_label = new QLabel(i18n("Favourite X-terminal:"), this);
406 hl->addWidget(kcfg_xtermCommand_label);
407 kcfg_xtermCommand = new QLineEdit(this, "kcfg_xtermCommand");
408 hl->addStretch();
409 hl->addWidget(kcfg_xtermCommand);
410 l->addLayout(hl);
411 l->addStretch();
412}
413
414
415/*********************************************************
416 ** class ConfPageAutostart **
417 *********************************************************/
418
419ConfPageAutostart::ConfPageAutostart(QWidget *parent, const char *name, WFlags f)
420 : QWidget(parent, name, f)
421{
422 QGroupBox *kcfg_autoStart_box;
423 QPushButton *kcfg_autoStart_button;
424 QCheckBox *kcfg_autostartDeeplocked;
425
426 QBoxLayout *l = new QVBoxLayout(this);
427 l->setSpacing(4);
428 // autostart
429 kcfg_autoStart_box = new QGroupBox(i18n("Open this file automatically on startup:"),
430 this);
431 l->addWidget(kcfg_autoStart_box);
432 kcfg_autoStart_box->setColumns(2);
433 kcfg_autoStart = new QLineEdit(kcfg_autoStart_box, "kcfg_autoStart");
434 kcfg_autoStart_button = new QPushButton("...", kcfg_autoStart_box);
435 kcfg_autostartDeeplocked = new QCheckBox(i18n("open deeplocked"),
436 kcfg_autoStart_box, "kcfg_autostartDeeplocked");
437 l->addStretch();
438 // connections
439 connect(kcfg_autoStart_button, SIGNAL(clicked()),
440 this, SLOT(browseButton_slot()));
441}
442
443void ConfPageAutostart::browseButton_slot()
444{
445 QString path(KFileDialog::getOpenFileName(QString::null,
446 i18n("*.pwm|PwM Password file\n"
447 "*|All files"), this));
448 if (path == QString::null)
449 return;
450 kcfg_autoStart->setText(path);
451}
452
453
454#include "configuration.moc"
455
456#else // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
457 /* XXX: This is the code for KDE-3.1 compatibility. */
458# include "configuration_31compat.cpp"
459#endif // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)