summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/configwndimpl.cpp
blob: 5440498948ef1798c04143bca9f90340c23821c3 (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
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003 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 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "configwndimpl.h"
#include "pwm.h"
#include "configuration.h"

#include <qfileinfo.h>
#include <qlineedit.h>

#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <klocale.h>

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

#ifdef PWM_EMBEDDED
#include <kfontdialog.h>
#endif

ConfigWndImpl::ConfigWndImpl()
#ifdef PWM_EMBEDDED
    : configWnd(0, "ConfigWndImpl", TRUE)
#endif

{
}

ConfigWndImpl::~ConfigWndImpl()
{
}

void ConfigWndImpl::okButton_slot()
{
	done(0);
}

void ConfigWndImpl::cancelButton_slot()
{
	done(1);
}

void ConfigWndImpl::browseAutoStButton_slot()
{
#ifndef PWM_EMBEDDED
	QString path(KFileDialog::getOpenFileName(QString::null,
						  i18n("*.pwm|PwM Password file\n"
						       "*|All files"), this));
#else
	QString path = locateLocal( "data", KGlobal::getAppName() + "/*.pwm");
	path = KFileDialog::getOpenFileName(path,
						i18n("password filename(*.pwm)"), this);
#endif
	if (path != QString::null)
		autoStartLineEdit->setText(path);
}

void ConfigWndImpl::selEntrFontButton_slot()
{
	bool ok;
#ifndef PWM_EMBEDDED
	QFont fnt = QFontDialog::getFont(&ok, currentEntryFont, this);
#else
	QFont fnt = KFontDialog::getFont(currentEntryFont, ok);
#endif
	if (!ok)
		return;
	currEntrFont->setFont(fnt);
	currEntrFont->setText(fnt.family());
	currentEntryFont = fnt;
}

int ConfigWndImpl::getFilePermissions()
{
	char octalDigits[] = "01234567";
	bool isOctal;
	QString permString(permissionLineEdit->text());
	int i, j, length = permString.length();
	if (length != 3) {
		printWarn("Wrong permission string length! Please enter "
			  "the string like the following example: 600");
		return CONF_DEFAULT_FILEPERMISSIONS;
	}
	for (i = 0; i < length; ++i) {
		isOctal = false;
		for (j = 0; j < 8; ++j) {
			if (permString.at(i) == octalDigits[j]) {
				isOctal = true;
				break;
			}
		}
		if (!isOctal) {
			printWarn("CONFIG: File-permissions: This is "
				  "not an octal number ");
			return CONF_DEFAULT_FILEPERMISSIONS;
		}
	}

	int ret = strtol(permString.latin1(), 0, 8);
	if (ret == 0) {
		/* either an error occured, or the user did really type 000 */
		printWarn("CONFIG: File-permissions: Hm, either conversion error, "
			  "or you really typed 000. 8-)");
		return CONF_DEFAULT_FILEPERMISSIONS;
	}
	return ret;
}

void ConfigWndImpl::setFilePermissions(int perm)
{
	char tmpBuf[30];
	sprintf(tmpBuf, "%o", perm);
	permissionLineEdit->setText(tmpBuf);
}

#ifndef PWM_EMBEDDED
#include "configwndimpl.moc"
#endif