summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/configuration.cpp
blob: 8d679772770b23d542dac430776a0d6356649e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2004 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 2.0 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "configuration.h"
#if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)

#include <kconfigdialog.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kfontrequester.h>

#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qfileinfo.h>
#include <qfontdialog.h>
#include <qspinbox.h>
#include <qvalidator.h>
#include <qsqlpropertymap.h>
#include <qlayout.h>

#include <stdlib.h>
#include <stdio.h>

#define INITIAL_CONFWND_SIZE	(QSize(600, 450))


/*********************************************************
 **  class Configuration                                **
 *********************************************************/

Configuration * Configuration::_obj (0);

Configuration::Configuration()
{
	skel = new KConfigSkeleton;
	initSkel();
	readConfig();
}

Configuration::~Configuration()
{
	writeConfig();
	delete_ifnot_null(skel);
}

void Configuration::initSkel()
{
	skel->setCurrentGroup("GLOBAL");
	skel->addItemString("autoStart", cGlobAutoStart);
	skel->addItemString("browserCommand", cGlobBrowserCommand, CONF_DEFAULT_BROWSERCOMMAND);
	skel->addItemString("xtermCommand", cGlobXtermCommand, CONF_DEFAULT_XTERMCOMMAND);
	skel->addItemFont("entryFont", cGlobEntryFont);
	skel->addItemInt("pwTimeout", cGlobPwTimeout, CONF_DEFAULT_PWTIMEOUT);
	skel->addItemInt("lockTimeout", cGlobLockTimeout, CONF_DEFAULT_LOCKTIMEOUT);
	skel->addItemInt("compression", cGlobCompression, CONF_DEFAULT_COMPRESSION);
	skel->addItemInt("filePermissions", cGlobFilePermissions, CONF_DEFAULT_FILEPERMISSIONS);
	skel->addItemInt("minimizeLock", cGlobMinimizeLock, CONF_DEFAULT_MINIMIZELOCK);
	skel->addItemBool("unlockOnOpen", cGlobUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN);
	skel->addItemBool("tray", cGlobTray, CONF_DEFAULT_TRAY);
	skel->addItemBool("makeFileBackup", cGlobMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP);
	skel->addItemBool("autostartDeeplocked", cGlobAutostartDeepLocked, CONF_DEFAULT_AUTOSTART_DEEPL);
	skel->addItemBool("autoDeepLock", cGlobAutoDeepLock, CONF_DEFAULT_AUTODEEPLOCK);
	skel->addItemBool("kwalletEmu", cGlobKwalletEmu, CONF_DEFAULT_KWALLETEMU);
	skel->addItemBool("newEntrLockStat", cGlobNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT);

	skel->setCurrentGroup("WND");
	skel->addItemSize("MainWndSize", cWndMainWndSize);
	skel->addItemInt("MainViewStyle", cWndMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE);
	skel->addItemBool("autoMinimizeOnStart", cWndAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE);
	skel->addItemBool("close", cWndClose, CONF_DEFAULT_WNDCLOSE);
}

bool Configuration::showConfWnd(QWidget *parent)
{
	bool ret = true;
	KConfigDialog *confDlg;
	confDlg = new KConfigDialog(parent, i18n("Main configuration").latin1(), skel,
				    KDialogBase::IconList,
				    KConfigDialog::Default | KConfigDialog::Ok |
				    KConfigDialog::Cancel | KConfigDialog::Help,
				    KConfigDialog::Ok, true);
	ConfPageGlobal *confPageGlobal = new ConfPageGlobal;
	ConfPageLookNFeel *confPageLookNFeel = new ConfPageLookNFeel;
	ConfPageFile *confPageFile = new ConfPageFile;
	ConfPageTimeouts *confPageTimeouts = new ConfPageTimeouts;
	ConfPageExtApps *confPageExtApps = new ConfPageExtApps;
	ConfPageAutostart *confPageAutostart = new ConfPageAutostart;
	confDlg->addPage(confPageGlobal, i18n("General"), "pwmanager");
	confDlg->addPage(confPageLookNFeel, i18n("Look & Feel"), "fonts");
	confDlg->addPage(confPageFile, i18n("Files"), "filesave");
	confDlg->addPage(confPageTimeouts, i18n("Timeouts"), "clock");
	confDlg->addPage(confPageExtApps, i18n("External Applications"), "gear");
	confDlg->addPage(confPageAutostart, i18n("Autostart"), "fileopen");
	confDlg->resize(INITIAL_CONFWND_SIZE);
	if (confDlg->exec() == 0)
		ret = false;
	delete confPageGlobal;
	delete confPageLookNFeel;
	delete confPageFile;
	delete confPageTimeouts;
	delete confPageExtApps;
	delete confPageAutostart;
	return ret;
}


/*********************************************************
 **  class OctLineEdit                                  **
 *********************************************************/

OctLineEdit::OctLineEdit(QWidget *parent, const char *name)
 : QLineEdit(parent, name)
{
}

OctLineEdit::~OctLineEdit()
{
}

void OctLineEdit::setText(const QString &t)
{
	bool ok;
	int tmp = t.toInt(&ok, 10);
	if (!ok)
		return;
	QString ret;
	ret.setNum(tmp, 8);
	QLineEdit::setText(ret);
}

QString OctLineEdit::text() const
{
	bool ok;
	QString ret;
	QString t(QLineEdit::text());
	int tmp = t.toInt(&ok, 8);
	if (!ok)
		return ret;
	ret.setNum(tmp, 10);
	return ret;
}

void OctLineEdit::keyPressEvent(QKeyEvent *e)
{
	int key = e->key();
	switch (key) {
	case Qt::Key_0:
	case Qt::Key_1:
	case Qt::Key_2:
	case Qt::Key_3:
	case Qt::Key_4:
	case Qt::Key_5:
	case Qt::Key_6:
	case Qt::Key_7:
	case Qt::Key_Escape:
	case Qt::Key_Backtab:
	case Qt::Key_Backspace:
	case Qt::Key_Return:
	case Qt::Key_Enter:
	case Qt::Key_Insert:
	case Qt::Key_Delete:
	case Qt::Key_Home:
	case Qt::Key_End:
	case Qt::Key_Left:
	case Qt::Key_Up:
	case Qt::Key_Right:
	case Qt::Key_Down:
		e->accept();
		QLineEdit::keyPressEvent(e);
		break;
	default:
		e->ignore();
	}
}


/*********************************************************
 **  class ConfPageGlobal                               **
 *********************************************************/

ConfPageGlobal::ConfPageGlobal(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QCheckBox *kcfg_tray;
	QCheckBox *kcfg_autoMinimizeOnStart;
	QCheckBox *kcfg_unlockOnOpen;
	QCheckBox *kcfg_newEntrLockStat;
	QCheckBox *kcfg_close;
	QComboBox *kcfg_minimizeLock;
	QLabel *kcfg_minimizeLock_label;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(4);
	kcfg_tray = new QCheckBox(i18n("Show icon in system-tray"), this, "kcfg_tray");
	l->addWidget(kcfg_tray);
	kcfg_autoMinimizeOnStart = new QCheckBox(i18n("auto-minimize to tray on startup"),
						 this, "kcfg_autoMinimizeOnStart");
	l->addWidget(kcfg_autoMinimizeOnStart);
	kcfg_unlockOnOpen = new QCheckBox(i18n("Open document with passwords unlocked"),
					  this, "kcfg_unlockOnOpen");
	l->addWidget(kcfg_unlockOnOpen);
#ifdef CONFIG_KWALLETIF
	QCheckBox *kcfg_kwalletEmu;
	kcfg_kwalletEmu = new QCheckBox(i18n("KWallet emulation"),
					this, "kcfg_kwalletEmu");
	l->addWidget(kcfg_kwalletEmu);
#endif // CONFIG_KWALLETIF
	kcfg_newEntrLockStat = new QCheckBox(i18n("Automatically lock new entries"),
					     this, "kcfg_newEntrLockStat");
	l->addWidget(kcfg_newEntrLockStat);
	kcfg_close = new QCheckBox(i18n("Do not minimize windows into tray. (Close the window)"),
				   this, "kcfg_close");
	l->addWidget(kcfg_close);
	l->addSpacing(4);
	QBoxLayout *hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_minimizeLock_label = new QLabel(i18n("auto-lock on minimize:"), this);
	hl->addWidget(kcfg_minimizeLock_label);
	kcfg_minimizeLock = new QComboBox(this, "kcfg_minimizeLock");
	hl->addStretch();
	hl->addWidget(kcfg_minimizeLock);
	kcfg_minimizeLock->insertItem(i18n("don't lock"));
	kcfg_minimizeLock->insertItem(i18n("normal lock"));
	kcfg_minimizeLock->insertItem(i18n("deep-lock"));
	l->addLayout(hl);
	l->addStretch();
}


/*********************************************************
 **  class ConfPageLookNFeel                            **
 *********************************************************/

ConfPageLookNFeel::ConfPageLookNFeel(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QComboBox *kcfg_MainViewStyle;
	QLabel *kcfg_MainViewStyle_label;
	KFontRequester *kcfg_entryFont;
	QGroupBox *kcfg_entryFont_box;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(10);
	// font
	kcfg_entryFont_box = new QGroupBox(i18n("Font for the password entries:"), this);
	l->addWidget(kcfg_entryFont_box);
	kcfg_entryFont_box->setColumns(1);
	kcfg_entryFont = new KFontRequester(kcfg_entryFont_box, "kcfg_entryFont", false);
	// wnd style
	QBoxLayout *hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_MainViewStyle_label = new QLabel(i18n("Window-style:"), this);
	hl->addWidget(kcfg_MainViewStyle_label);
	kcfg_MainViewStyle = new QComboBox(this, "kcfg_MainViewStyle");
	hl->addStretch();
	hl->addWidget(kcfg_MainViewStyle);
	kcfg_MainViewStyle->insertItem(i18n("Category on top"));
	kcfg_MainViewStyle->insertItem(i18n("Category-list left"));
	l->addLayout(hl);
	l->addStretch();
}


/*********************************************************
 **  class ConfPageFile                                 **
 *********************************************************/

ConfPageFile::ConfPageFile(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QComboBox *kcfg_compression;
	QLabel *kcfg_compression_label;
	OctLineEdit *kcfg_filePermissions;
	QLabel *kcfg_filePermissions_label;
	QCheckBox *kcfg_makeFileBackup;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(10);
	// compression
	QBoxLayout *hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_compression_label = new QLabel(i18n("*.pwm file compression:"), this);
	hl->addWidget(kcfg_compression_label);
	kcfg_compression = new QComboBox(this, "kcfg_compression");
	hl->addStretch();
	hl->addWidget(kcfg_compression);
	kcfg_compression->insertItem(i18n("none"));
	kcfg_compression->insertItem(i18n("gzip"));
	kcfg_compression->insertItem(i18n("bzip2"));
	l->addLayout(hl);
	// permissions
	hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_filePermissions_label = new QLabel(i18n("permissions:"), this);
	hl->addWidget(kcfg_filePermissions_label);
	kcfg_filePermissions = new OctLineEdit(this, "kcfg_filePermissions");
	hl->addStretch();
	hl->addWidget(kcfg_filePermissions);
	kcfg_filePermissions->setMaxLength(3);
	l->addLayout(hl);
	// backup
	kcfg_makeFileBackup = new QCheckBox(i18n("Make file backup before saving"),
					    this, "kcfg_makeFileBackup");
	l->addWidget(kcfg_makeFileBackup);
	l->addStretch();
}


/*********************************************************
 **  class ConfPageTimeouts                             **
 *********************************************************/

ConfPageTimeouts::ConfPageTimeouts(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QSpinBox *kcfg_pwTimeout;
	QLabel *kcfg_pwTimeout_label;
	QSpinBox *kcfg_lockTimeout;
	QLabel *kcfg_lockTimeout_label;
	QCheckBox *kcfg_autoDeepLock;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(10);
	// pw timeout
	QBoxLayout *hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_pwTimeout_label = new QLabel(i18n("Password timeout (timeout to hold "
					       "password in memory, so you don't have "
					       "to re-enter it, if you already have "
					       "entered it) [set to 0 to disable]:"),
					  this);
	hl->addWidget(kcfg_pwTimeout_label);
	kcfg_pwTimeout_label->setAlignment(QLabel::WordBreak);
	kcfg_pwTimeout = new QSpinBox(this, "kcfg_pwTimeout");
	hl->addStretch();
	hl->addWidget(kcfg_pwTimeout);
	l->addLayout(hl);
	// lock timeout
	hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_lockTimeout_label = new QLabel(i18n("Auto-lock timeout (auto lock document "
						 "after this amount of seconds) "
						 "[set to 0 to disable]:"),
					    this);
	hl->addWidget(kcfg_lockTimeout_label);
	kcfg_lockTimeout_label->setAlignment(QLabel::WordBreak);
	kcfg_lockTimeout = new QSpinBox(this, "kcfg_lockTimeout");
	hl->addStretch();
	hl->addWidget(kcfg_lockTimeout);
	l->addLayout(hl);
	// auto deep lock checkbox
	kcfg_autoDeepLock = new QCheckBox(i18n("deep-lock on autolock"),
					  this, "kcfg_autoDeepLock");
	l->addWidget(kcfg_autoDeepLock);
	l->addStretch();
}


/*********************************************************
 **  class ConfPageExtApps                              **
 *********************************************************/

ConfPageExtApps::ConfPageExtApps(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QLineEdit *kcfg_browserCommand;
	QLabel *kcfg_browserCommand_label;
	QLineEdit *kcfg_xtermCommand;
	QLabel *kcfg_xtermCommand_label;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(4);
	// browser command
	QBoxLayout *hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_browserCommand_label = new QLabel(i18n("Favourite browser:"), this);
	hl->addWidget(kcfg_browserCommand_label);
	kcfg_browserCommand = new QLineEdit(this, "kcfg_browserCommand");
	hl->addStretch();
	hl->addWidget(kcfg_browserCommand);
	l->addLayout(hl);
	// xterm command
	hl = new QHBoxLayout(this);
	hl->setSpacing(10);
	kcfg_xtermCommand_label = new QLabel(i18n("Favourite X-terminal:"), this);
	hl->addWidget(kcfg_xtermCommand_label);
	kcfg_xtermCommand = new QLineEdit(this, "kcfg_xtermCommand");
	hl->addStretch();
	hl->addWidget(kcfg_xtermCommand);
	l->addLayout(hl);
	l->addStretch();
}


/*********************************************************
 **  class ConfPageAutostart                            **
 *********************************************************/

ConfPageAutostart::ConfPageAutostart(QWidget *parent, const char *name, WFlags f)
 : QWidget(parent, name, f)
{
	QGroupBox *kcfg_autoStart_box;
	QPushButton *kcfg_autoStart_button;
	QCheckBox *kcfg_autostartDeeplocked;

	QBoxLayout *l = new QVBoxLayout(this);
	l->setSpacing(4);
	// autostart
	kcfg_autoStart_box = new QGroupBox(i18n("Open this file automatically on startup:"),
					   this);
	l->addWidget(kcfg_autoStart_box);
	kcfg_autoStart_box->setColumns(2);
	kcfg_autoStart = new QLineEdit(kcfg_autoStart_box, "kcfg_autoStart");
	kcfg_autoStart_button = new QPushButton("...", kcfg_autoStart_box);
	kcfg_autostartDeeplocked = new QCheckBox(i18n("open deeplocked"),
						 kcfg_autoStart_box, "kcfg_autostartDeeplocked");
	l->addStretch();
	// connections
	connect(kcfg_autoStart_button, SIGNAL(clicked()),
		this, SLOT(browseButton_slot()));
}

void ConfPageAutostart::browseButton_slot()
{
	QString path(KFileDialog::getOpenFileName(QString::null,
						  i18n("*.pwm|PwM Password file\n"
						       "*|All files"), this));
	if (path == QString::null)
		return;
	kcfg_autoStart->setText(path);
}


#include "configuration.moc"

#else // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
  /* XXX: This is the code for KDE-3.1 compatibility. */
# include "configuration_31compat.cpp"
#endif // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)