summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/setmasterpwwndimpl.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/setmasterpwwndimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/setmasterpwwndimpl.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/setmasterpwwndimpl.cpp b/pwmanager/pwmanager/setmasterpwwndimpl.cpp
new file mode 100644
index 0000000..aac0408
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwndimpl.cpp
@@ -0,0 +1,152 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 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/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "setmasterpwwndimpl.h"
22#include "pwm.h"
23#include "globalstuff.h"
24
25#include <kmessagebox.h>
26
27#include <qlineedit.h>
28#include <qlabel.h>
29#include <qtabwidget.h>
30
31#include <stdio.h>
32
33#ifdef CONFIG_KEYCARD
34# include "pwmkeycard.h"
35#endif
36
37 #define STRING_CARD_NONE(SetMasterPwWndImpl::string_cardNone())
38
39
40SetMasterPwWndImpl::SetMasterPwWndImpl(QWidget * parent, const char *name)
41: setMasterPwWnd(parent, name)
42{
43#ifdef CONFIG_KEYCARD
44 curCardIdLabel->setText(STRING_CARD_NONE);
45#else // CONFIG_KEYCARD
46#ifndef PWM_EMBEDDED
47 mainTab->removePage(mainTab->page(1));
48#else
49 qDebug("SetMasterPwWndImpl::SetMasterPwWndImpl has to be fixed");
50#endif
51#endif // CONFIG_KEYCARD
52 keyCard = 0;
53}
54
55SetMasterPwWndImpl::~SetMasterPwWndImpl()
56{
57}
58
59void SetMasterPwWndImpl::okButton_slot()
60{
61 int index = mainTab->currentPageIndex();
62 if (index == 0) {
63 // normal password
64 if (pwEdit_1->text() != pwEdit_2->text()) {
65 KMessageBox::error(this,
66 i18n
67 ("The two passwords you have entered don't match.\n"
68 "Please try entering them again."),
69 i18n("Different passwords"));
70 return;
71 }
72 if (pwEdit_1->text() == "") {
73 KMessageBox::error(this,
74 i18n("No password entered. "
75 "Please type in a password, that "
76 "you want to use for the encryption."),
77 i18n("no password"));
78 return;
79 }
80 } else {
81 // key-card
82 if (curCardIdLabel->text() == STRING_CARD_NONE) {
83 KMessageBox::error(this,
84 i18n("You didn't select a card as "
85 "PwM-key-card."),
86 i18n("no card"));
87 return;
88 }
89 }
90 done(1);
91}
92
93void SetMasterPwWndImpl::cancelButton_slot()
94{
95 done(2);
96}
97
98void SetMasterPwWndImpl::genCardButton_slot()
99{
100#ifdef CONFIG_KEYCARD
101 PWM_ASSERT(keyCard);
102 keyCard->genNewCard();
103#endif // CONFIG_KEYCARD
104}
105
106void SetMasterPwWndImpl::selCardButton_slot()
107{
108#ifdef CONFIG_KEYCARD
109 PWM_ASSERT(keyCard);
110 connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
111 this, SLOT(keyAvailable_slot(uint32_t, const string &)));
112 keyCard->getKey();
113#endif // CONFIG_KEYCARD
114}
115
116void SetMasterPwWndImpl::keyAvailable_slot(uint32_t cardId,
117 const string &key)
118{
119 if (key == "")
120 return;
121 curCardKey = key;
122 char id_buf[(sizeof(cardId) * 2) + 2 /* "0x" */ + 1 /* NULL */];
123 memcpy(id_buf, "0x", 2);
124 sprintf(id_buf + 2, "%X", cardId);
125 curCardIdLabel->setText(id_buf);
126}
127
128string SetMasterPwWndImpl::getPw(bool *useCard)
129{
130 int index = mainTab->currentPageIndex();
131 if (index == 0) {
132 // normal password
133 if (useCard)
134 *useCard = false;
135 PWM_ASSERT(pwEdit_1->text() == pwEdit_2->text());
136 return pwEdit_1->text().latin1();
137 } else {
138#ifdef CONFIG_KEYCARD
139 // key-card
140 if (useCard)
141 *useCard = true;
142 PWM_ASSERT(curCardKey != "");
143 PWM_ASSERT(curCardIdLabel->text() != STRING_CARD_NONE);
144 return curCardKey;
145#endif // CONFIG_KEYCARD
146 }
147 return "";
148}
149
150#ifndef PWM_EMBEDDED
151#include "setmasterpwwndimpl.moc"
152#endif