author | zautrix <zautrix> | 2005-03-03 13:42:15 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-03 13:42:15 (UTC) |
commit | 91feaad38e5f81063fa496a4e2988aa791267fd1 (patch) (unidiff) | |
tree | fc408221a6b1a664f3574657a336526726aa9ccc | |
parent | 806a806422872b6f31183267c6b084d425458902 (diff) | |
download | kdepimpi-91feaad38e5f81063fa496a4e2988aa791267fd1.zip kdepimpi-91feaad38e5f81063fa496a4e2988aa791267fd1.tar.gz kdepimpi-91feaad38e5f81063fa496a4e2988aa791267fd1.tar.bz2 |
more pw fixes
-rw-r--r-- | pwmanager/pwmanager/commentbox.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/commentbox.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/listviewpwm.cpp | 8 | ||||
-rw-r--r-- | pwmanager/pwmanager/listviewpwm.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 58 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_0.cpp | 20 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_0.h | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_1.cpp | 19 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_1.h | 2 |
12 files changed, 121 insertions, 11 deletions
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp index 51f88b2..5416856 100644 --- a/pwmanager/pwmanager/commentbox.cpp +++ b/pwmanager/pwmanager/commentbox.cpp | |||
@@ -1,283 +1,283 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "commentbox.h" | 20 | #include "commentbox.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "htmlgen.h" | 22 | #include "htmlgen.h" |
23 | 23 | ||
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | 25 | ||
26 | #ifndef PWM_EMBEDDED | 26 | #ifndef PWM_EMBEDDED |
27 | #include <khtml_part.h> | 27 | #include <khtml_part.h> |
28 | #include <khtmlview.h> | 28 | #include <khtmlview.h> |
29 | #include <qtextedit.h> | 29 | #include <qtextedit.h> |
30 | #else | 30 | #else |
31 | #include <qmultilineedit.h> | 31 | #include <qmultilineedit.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | #ifndef PWM_EMBEDDED | 36 | #ifndef PWM_EMBEDDED |
37 | CommentBox::CommentBox(QWidget *_parentWidget) | 37 | CommentBox::CommentBox(QWidget *_parentWidget) |
38 | { | 38 | { |
39 | PWM_ASSERT(_parentWidget); | 39 | PWM_ASSERT(_parentWidget); |
40 | parentWidget = _parentWidget; | 40 | parentWidget = _parentWidget; |
41 | textDta = 0; | 41 | textDta = 0; |
42 | htmlDta = 0; | 42 | htmlDta = 0; |
43 | mode = mode_notSet; | 43 | mode = mode_notSet; |
44 | setFont( prefs->mViewFont ); | 44 | setFont( prefs->mViewFont ); |
45 | } | 45 | } |
46 | 46 | ||
47 | CommentBox::~CommentBox() | 47 | CommentBox::~CommentBox() |
48 | { | 48 | { |
49 | clearText(); | 49 | clearText(); |
50 | clearHtml(); | 50 | clearHtml(); |
51 | } | 51 | } |
52 | 52 | ||
53 | void CommentBox::clear() | 53 | void CommentBox::clear() |
54 | { | 54 | { |
55 | clearText(); | 55 | clearText(); |
56 | clearHtml(); | 56 | clearHtml(); |
57 | mode = mode_notSet; | 57 | mode = mode_notSet; |
58 | this->hide(); | 58 | this->hide(); |
59 | } | 59 | } |
60 | 60 | ||
61 | void CommentBox::clearText() | 61 | void CommentBox::clearText() |
62 | { | 62 | { |
63 | delete_ifnot_null(textDta); | 63 | delete_ifnot_null(textDta); |
64 | } | 64 | } |
65 | 65 | ||
66 | void CommentBox::clearHtml() | 66 | void CommentBox::clearHtml() |
67 | { | 67 | { |
68 | delete_ifnot_null(htmlDta); | 68 | delete_ifnot_null(htmlDta); |
69 | } | 69 | } |
70 | 70 | ||
71 | void CommentBox::setText(const QString &text) | 71 | void CommentBox::setText(const QString &text) |
72 | { | 72 | { |
73 | switchTo(mode_text); | 73 | switchTo(mode_text); |
74 | PWM_ASSERT(textDta); | 74 | PWM_ASSERT(textDta); |
75 | textDta->setText( text); | 75 | textDta->setText( text); |
76 | if (!textDta->isVisible()) | 76 | if (!textDta->isVisible()) |
77 | textDta->show(); | 77 | textDta->show(); |
78 | } | 78 | } |
79 | 79 | ||
80 | bool CommentBox::getText(QString *text) | 80 | bool CommentBox::getText(QString *text) |
81 | { | 81 | { |
82 | if (mode != mode_text) | 82 | if (mode != mode_text) |
83 | return false; | 83 | return false; |
84 | PWM_ASSERT(text); | 84 | PWM_ASSERT(text); |
85 | if (!textDta) { | 85 | if (!textDta) { |
86 | *text = ""; | 86 | *text = ""; |
87 | return true; | 87 | return true; |
88 | } | 88 | } |
89 | *text = textDta->text(); | 89 | *text = textDta->text(); |
90 | return true; | 90 | return true; |
91 | } | 91 | } |
92 | 92 | ||
93 | void CommentBox::setHtml(QString code) | 93 | void CommentBox::setHtml(QString code) |
94 | { | 94 | { |
95 | switchTo(mode_html); | 95 | switchTo(mode_html); |
96 | PWM_ASSERT(htmlDta); | 96 | PWM_ASSERT(htmlDta); |
97 | if (!HtmlGen::replaceSSDummy(&code)) | 97 | if (!HtmlGen::replaceSSDummy(&code)) |
98 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); | 98 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); |
99 | htmlDta->begin(); | 99 | htmlDta->begin(); |
100 | htmlDta->write(code); | 100 | htmlDta->write(code); |
101 | htmlDta->end(); | 101 | htmlDta->end(); |
102 | htmlDta->show(); | 102 | htmlDta->show(); |
103 | } | 103 | } |
104 | 104 | ||
105 | void CommentBox::setContent(const QString &dta) | 105 | void CommentBox::setContent(const QString &dta) |
106 | { | 106 | { |
107 | // if there's no data, hide the comment-box | 107 | // if there's no data, hide the comment-box |
108 | if (dta.isEmpty()) { | 108 | if (dta.isEmpty()) { |
109 | clear(); | 109 | clear(); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | if (HtmlGen::isHtml(dta)) { | 112 | if (HtmlGen::isHtml(dta)) { |
113 | setHtml(dta); | 113 | setHtml(dta); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | // we assume it's plain text | 116 | // we assume it's plain text |
117 | setText(dta); | 117 | setText(dta); |
118 | } | 118 | } |
119 | 119 | ||
120 | void CommentBox::switchTo(commentBoxMode newMode) | 120 | void CommentBox::switchTo(commentBoxMode newMode) |
121 | { | 121 | { |
122 | if (newMode == mode) | 122 | if (newMode == mode) |
123 | return; | 123 | return; |
124 | 124 | ||
125 | // cleanup old mode | 125 | // cleanup old mode |
126 | switch (mode) { | 126 | switch (mode) { |
127 | case mode_text: | 127 | case mode_text: |
128 | clearText(); | 128 | clearText(); |
129 | break; | 129 | break; |
130 | case mode_html: | 130 | case mode_html: |
131 | clearHtml(); | 131 | clearHtml(); |
132 | break; | 132 | break; |
133 | default: | 133 | default: |
134 | break; | 134 | break; |
135 | } | 135 | } |
136 | 136 | ||
137 | // setup new mode | 137 | // setup new mode |
138 | switch (newMode) { | 138 | switch (newMode) { |
139 | case mode_text: | 139 | case mode_text: |
140 | textDta = new QTextEdit(parentWidget); | 140 | textDta = new QTextEdit(parentWidget); |
141 | textDta->setTextFormat(Qt::PlainText); | 141 | textDta->setTextFormat(Qt::PlainText); |
142 | textDta->setReadOnly(true); | 142 | textDta->setReadOnly(true); |
143 | textDta->show(); | 143 | textDta->show(); |
144 | break; | 144 | break; |
145 | case mode_html: | 145 | case mode_html: |
146 | htmlDta = new KHTMLPart(parentWidget, 0, | 146 | htmlDta = new KHTMLPart(parentWidget, 0, |
147 | parentWidget); | 147 | parentWidget); |
148 | htmlDta->show(); | 148 | htmlDta->show(); |
149 | break; | 149 | break; |
150 | default: | 150 | default: |
151 | BUG(); | 151 | BUG(); |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | 154 | ||
155 | mode = newMode; | 155 | mode = newMode; |
156 | } | 156 | } |
157 | 157 | ||
158 | void CommentBox::show() | 158 | void CommentBox::show() |
159 | { | 159 | { |
160 | switch (mode) { | 160 | switch (mode) { |
161 | case mode_text: | 161 | case mode_text: |
162 | PWM_ASSERT(textDta); | 162 | PWM_ASSERT(textDta); |
163 | textDta->show(); | 163 | textDta->show(); |
164 | break; | 164 | break; |
165 | case mode_html: | 165 | case mode_html: |
166 | PWM_ASSERT(htmlDta); | 166 | PWM_ASSERT(htmlDta); |
167 | htmlDta->show(); | 167 | htmlDta->show(); |
168 | break; | 168 | break; |
169 | default: | 169 | default: |
170 | break; | 170 | break; |
171 | } | 171 | } |
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | void CommentBox::hide() | 175 | void CommentBox::hide() |
176 | { | 176 | { |
177 | switch (mode) { | 177 | switch (mode) { |
178 | case mode_text: | 178 | case mode_text: |
179 | PWM_ASSERT(textDta); | 179 | PWM_ASSERT(textDta); |
180 | textDta->hide(); | 180 | textDta->hide(); |
181 | break; | 181 | break; |
182 | case mode_html: | 182 | case mode_html: |
183 | PWM_ASSERT(htmlDta); | 183 | PWM_ASSERT(htmlDta); |
184 | htmlDta->hide(); | 184 | htmlDta->hide(); |
185 | break; | 185 | break; |
186 | default: | 186 | default: |
187 | break; | 187 | break; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | void CommentBox::resize(const QSize &size) | 191 | void CommentBox::resize(const QSize &size) |
192 | { | 192 | { |
193 | switch (mode) { | 193 | switch (mode) { |
194 | case mode_text: | 194 | case mode_text: |
195 | PWM_ASSERT(textDta); | 195 | PWM_ASSERT(textDta); |
196 | textDta->resize(size); | 196 | textDta->resize(size); |
197 | break; | 197 | break; |
198 | case mode_html: | 198 | case mode_html: |
199 | PWM_ASSERT(htmlDta); | 199 | PWM_ASSERT(htmlDta); |
200 | htmlDta->view()->resize(size); | 200 | htmlDta->view()->resize(size); |
201 | break; | 201 | break; |
202 | default: | 202 | default: |
203 | break; | 203 | break; |
204 | } | 204 | } |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | QSize CommentBox::size() | 208 | QSize CommentBox::size() |
209 | { | 209 | { |
210 | switch (mode) { | 210 | switch (mode) { |
211 | case mode_text: | 211 | case mode_text: |
212 | PWM_ASSERT(textDta); | 212 | PWM_ASSERT(textDta); |
213 | return textDta->size(); | 213 | return textDta->size(); |
214 | break; | 214 | break; |
215 | case mode_html: | 215 | case mode_html: |
216 | PWM_ASSERT(htmlDta); | 216 | PWM_ASSERT(htmlDta); |
217 | return htmlDta->view()->size(); | 217 | return htmlDta->view()->size(); |
218 | break; | 218 | break; |
219 | default: | 219 | default: |
220 | break; | 220 | break; |
221 | } | 221 | } |
222 | 222 | ||
223 | return QSize(); | 223 | return QSize(); |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
227 | //////////////////////////////////////////////////////////////////////// | 227 | //////////////////////////////////////////////////////////////////////// |
228 | 228 | ||
229 | #else | 229 | #else |
230 | 230 | ||
231 | CommentBox::CommentBox(QWidget *_parentWidget) | 231 | CommentBox::CommentBox(QWidget *_parentWidget) |
232 | : QMultiLineEdit(_parentWidget) | 232 | : QTextBrowser(_parentWidget) |
233 | 233 | ||
234 | { | 234 | { |
235 | this->setReadOnly(true); | 235 | //this->setReadOnly(true); |
236 | setFocusPolicy( QWidget::ClickFocus ); | 236 | setFocusPolicy( QWidget::ClickFocus ); |
237 | } | 237 | } |
238 | 238 | ||
239 | CommentBox::~CommentBox() | 239 | CommentBox::~CommentBox() |
240 | { | 240 | { |
241 | } | 241 | } |
242 | 242 | ||
243 | void CommentBox::clear() | 243 | void CommentBox::clear() |
244 | { | 244 | { |
245 | this->hide(); | 245 | this->hide(); |
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
249 | void CommentBox::setText(const QString &text) | 249 | void CommentBox::setText(const QString &text) |
250 | { | 250 | { |
251 | QMultiLineEdit::setText( text); | 251 | QTextBrowser::setText( text); |
252 | if (!this->isVisible()) | 252 | if (!isVisible()) |
253 | this->show(); | 253 | show(); |
254 | } | 254 | } |
255 | 255 | ||
256 | bool CommentBox::getText(QString *text) | 256 | bool CommentBox::getText(QString *text) |
257 | { | 257 | { |
258 | *text = this->text(); | 258 | *text = this->text(); |
259 | return true; | 259 | return true; |
260 | } | 260 | } |
261 | 261 | ||
262 | void CommentBox::setContent(const QString &dta) | 262 | void CommentBox::setContent(const QString &dta) |
263 | { | 263 | { |
264 | // if there's no data, hide the comment-box | 264 | // if there's no data, hide the comment-box |
265 | if (dta.isEmpty()) { | 265 | if (dta.isEmpty()) { |
266 | clear(); | 266 | clear(); |
267 | return; | 267 | return; |
268 | } | 268 | } |
269 | 269 | ||
270 | // we assume it's plain text | 270 | // we assume it's plain text |
271 | setText(dta); | 271 | setText(dta); |
272 | } | 272 | } |
273 | 273 | ||
274 | #endif | 274 | #endif |
275 | 275 | ||
276 | 276 | ||
277 | 277 | ||
278 | 278 | ||
279 | 279 | ||
280 | 280 | ||
281 | 281 | ||
282 | 282 | ||
283 | 283 | ||
diff --git a/pwmanager/pwmanager/commentbox.h b/pwmanager/pwmanager/commentbox.h index 352867c..3103353 100644 --- a/pwmanager/pwmanager/commentbox.h +++ b/pwmanager/pwmanager/commentbox.h | |||
@@ -1,124 +1,124 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef COMMENTBOX_H | 20 | #ifndef COMMENTBOX_H |
21 | #define COMMENTBOX_H | 21 | #define COMMENTBOX_H |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qsize.h> | 24 | #include <qsize.h> |
25 | class QWidget; | 25 | class QWidget; |
26 | class QTextEdit; | 26 | class QTextEdit; |
27 | class KHTMLPart; | 27 | class KHTMLPart; |
28 | 28 | ||
29 | #ifndef PWM_EMBEDDED | 29 | #ifndef PWM_EMBEDDED |
30 | 30 | ||
31 | class CommentBox | 31 | class CommentBox |
32 | { | 32 | { |
33 | protected: | 33 | protected: |
34 | enum commentBoxMode | 34 | enum commentBoxMode |
35 | { | 35 | { |
36 | mode_notSet = 0, | 36 | mode_notSet = 0, |
37 | mode_text, | 37 | mode_text, |
38 | mode_html | 38 | mode_html |
39 | }; | 39 | }; |
40 | 40 | ||
41 | public: | 41 | public: |
42 | CommentBox(QWidget *_parentWidget); | 42 | CommentBox(QWidget *_parentWidget); |
43 | ~CommentBox(); | 43 | ~CommentBox(); |
44 | 44 | ||
45 | /** clear all data in the comment box */ | 45 | /** clear all data in the comment box */ |
46 | void clear(); | 46 | void clear(); |
47 | /** show the comment box */ | 47 | /** show the comment box */ |
48 | void show(); | 48 | void show(); |
49 | /** hide the comment box */ | 49 | /** hide the comment box */ |
50 | void hide(); | 50 | void hide(); |
51 | /** resize the comment box */ | 51 | /** resize the comment box */ |
52 | void resize(const QSize &size); | 52 | void resize(const QSize &size); |
53 | void resize(int w, int h) | 53 | void resize(int w, int h) |
54 | { resize(QSize(w, h)); } | 54 | { resize(QSize(w, h)); } |
55 | /** get the size of the comment box */ | 55 | /** get the size of the comment box */ |
56 | QSize size(); | 56 | QSize size(); |
57 | /** if neccessary switch to text-mode and | 57 | /** if neccessary switch to text-mode and |
58 | * insert this text into the comment box | 58 | * insert this text into the comment box |
59 | */ | 59 | */ |
60 | void setText(const QString &text); | 60 | void setText(const QString &text); |
61 | /** get the text of the comment box. | 61 | /** get the text of the comment box. |
62 | * If it's not in text-mode it returns false | 62 | * If it's not in text-mode it returns false |
63 | */ | 63 | */ |
64 | bool getText(QString *text); | 64 | bool getText(QString *text); |
65 | /** if neccessary switch to HTML-mode and | 65 | /** if neccessary switch to HTML-mode and |
66 | * insert this html code into the comment box | 66 | * insert this html code into the comment box |
67 | */ | 67 | */ |
68 | void setHtml(QString code); | 68 | void setHtml(QString code); |
69 | /** checks "dta" for its type, sets the correct | 69 | /** checks "dta" for its type, sets the correct |
70 | * mode and writes "dta" to the comment box | 70 | * mode and writes "dta" to the comment box |
71 | */ | 71 | */ |
72 | void setContent(const QString &dta); | 72 | void setContent(const QString &dta); |
73 | 73 | ||
74 | protected: | 74 | protected: |
75 | /** switch the current mode */ | 75 | /** switch the current mode */ |
76 | void switchTo(commentBoxMode newMode); | 76 | void switchTo(commentBoxMode newMode); |
77 | /** clear all text data */ | 77 | /** clear all text data */ |
78 | void clearText(); | 78 | void clearText(); |
79 | /** clear all HTML data */ | 79 | /** clear all HTML data */ |
80 | void clearHtml(); | 80 | void clearHtml(); |
81 | 81 | ||
82 | protected: | 82 | protected: |
83 | /** parent widget for this comment box */ | 83 | /** parent widget for this comment box */ |
84 | QWidget *parentWidget; | 84 | QWidget *parentWidget; |
85 | /** current comment box usage type */ | 85 | /** current comment box usage type */ |
86 | commentBoxMode mode; | 86 | commentBoxMode mode; |
87 | /** if the comment box is a normal textbox, data is stored here */ | 87 | /** if the comment box is a normal textbox, data is stored here */ |
88 | QTextEdit *textDta; | 88 | QTextEdit *textDta; |
89 | /** if the comment box is a HTML box, data is stored here */ | 89 | /** if the comment box is a HTML box, data is stored here */ |
90 | KHTMLPart *htmlDta; | 90 | KHTMLPart *htmlDta; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | #else | 93 | #else |
94 | #include <qmultilineedit.h> | 94 | #include <qtextbrowser.h> |
95 | /** Implementation of the advanced HTML comment box */ | 95 | /** Implementation of the advanced HTML comment box */ |
96 | //US ENH: CommentBox must be derived from QWidget, to allow the splitter to set a initial size | 96 | //US ENH: CommentBox must be derived from QWidget, to allow the splitter to set a initial size |
97 | // without conflicting with the two display modes | 97 | // without conflicting with the two display modes |
98 | 98 | ||
99 | class CommentBox : public QMultiLineEdit | 99 | class CommentBox : public QTextBrowser |
100 | { | 100 | { |
101 | public: | 101 | public: |
102 | CommentBox(QWidget *_parentWidget); | 102 | CommentBox(QWidget *_parentWidget); |
103 | ~CommentBox(); | 103 | ~CommentBox(); |
104 | 104 | ||
105 | /** clear all data in the comment box */ | 105 | /** clear all data in the comment box */ |
106 | void clear(); | 106 | void clear(); |
107 | /** if neccessary switch to text-mode and | 107 | /** if neccessary switch to text-mode and |
108 | * insert this text into the comment box | 108 | * insert this text into the comment box |
109 | */ | 109 | */ |
110 | void setText(const QString &text); | 110 | void setText(const QString &text); |
111 | /** get the text of the comment box. | 111 | /** get the text of the comment box. |
112 | * If it's not in text-mode it returns false | 112 | * If it's not in text-mode it returns false |
113 | */ | 113 | */ |
114 | bool getText(QString *text); | 114 | bool getText(QString *text); |
115 | /** if neccessary switch to HTML-mode and | 115 | /** if neccessary switch to HTML-mode and |
116 | * insert this html code into the comment box | 116 | * insert this html code into the comment box |
117 | */ | 117 | */ |
118 | void setContent(const QString &dta); | 118 | void setContent(const QString &dta); |
119 | 119 | ||
120 | }; | 120 | }; |
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | 123 | ||
124 | #endif | 124 | #endif |
diff --git a/pwmanager/pwmanager/listviewpwm.cpp b/pwmanager/pwmanager/listviewpwm.cpp index 85e788c..8d46fff 100644 --- a/pwmanager/pwmanager/listviewpwm.cpp +++ b/pwmanager/pwmanager/listviewpwm.cpp | |||
@@ -1,113 +1,121 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "listviewpwm.h" | 20 | #include "listviewpwm.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "pwmview.h" | 22 | #include "pwmview.h" |
23 | 23 | ||
24 | #include <qpainter.h> | 24 | #include <qpainter.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | 26 | ||
27 | #include <kiconloader.h> | 27 | #include <kiconloader.h> |
28 | 28 | ||
29 | #ifdef PWM_EMBEDDED | 29 | #ifdef PWM_EMBEDDED |
30 | #include <kglobal.h> | 30 | #include <kglobal.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | ListViewPwM::ListViewPwM(QWidget *parent, const char *name) | 33 | ListViewPwM::ListViewPwM(QWidget *parent, const char *name) |
34 | : KListView(parent, name) | 34 | : KListView(parent, name) |
35 | { | 35 | { |
36 | //setResizeMode(QListView::AllColumns); | 36 | //setResizeMode(QListView::AllColumns); |
37 | setAllColumnsShowFocus (true ); | 37 | setAllColumnsShowFocus (true ); |
38 | } | 38 | } |
39 | 39 | ||
40 | bool ListViewPwM::event(QEvent *e) | 40 | bool ListViewPwM::event(QEvent *e) |
41 | { | 41 | { |
42 | if (e->type() == QEvent::LayoutHint) | 42 | if (e->type() == QEvent::LayoutHint) |
43 | emit layoutChanged(); | 43 | emit layoutChanged(); |
44 | if (e->type() == QEvent::KeyPress) { | ||
45 | QKeyEvent* ke = (QKeyEvent*) e; | ||
46 | if ( ke->key() == Qt::Key_Space) { | ||
47 | emit toggleOverview(); | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | } | ||
44 | return KListView::event(e); | 52 | return KListView::event(e); |
45 | } | 53 | } |
46 | 54 | ||
47 | 55 | ||
48 | QPixmap * ListViewItemPwM::onPix = 0; | 56 | QPixmap * ListViewItemPwM::onPix = 0; |
49 | QPixmap * ListViewItemPwM::offPix = 0; | 57 | QPixmap * ListViewItemPwM::offPix = 0; |
50 | 58 | ||
51 | ListViewItemPwM::ListViewItemPwM(QListView *parent) | 59 | ListViewItemPwM::ListViewItemPwM(QListView *parent) |
52 | : QCheckListItem(parent, "", QCheckListItem::CheckBox) | 60 | : QCheckListItem(parent, "", QCheckListItem::CheckBox) |
53 | { | 61 | { |
54 | if (!onPix) { | 62 | if (!onPix) { |
55 | PWM_ASSERT(!offPix); | 63 | PWM_ASSERT(!offPix); |
56 | KIconLoader* picons; | 64 | KIconLoader* picons; |
57 | #ifndef PWM_EMBEDDED | 65 | #ifndef PWM_EMBEDDED |
58 | KIconLoader il; | 66 | KIconLoader il; |
59 | picons = &il; | 67 | picons = &il; |
60 | #else | 68 | #else |
61 | picons = KGlobal::iconLoader(); | 69 | picons = KGlobal::iconLoader(); |
62 | #endif | 70 | #endif |
63 | 71 | ||
64 | KIconLoader il; | 72 | KIconLoader il; |
65 | #ifndef PWM_EMBEDDED | 73 | #ifndef PWM_EMBEDDED |
66 | static QPixmap onP(picons->loadIcon("button_ok", KIcon::Small)); | 74 | static QPixmap onP(picons->loadIcon("button_ok", KIcon::Small)); |
67 | #else | 75 | #else |
68 | static QPixmap onP(picons->loadIcon("decrypted", KIcon::Small)); | 76 | static QPixmap onP(picons->loadIcon("decrypted", KIcon::Small)); |
69 | #endif | 77 | #endif |
70 | onPix = &onP; | 78 | onPix = &onP; |
71 | static QPixmap offP(picons->loadIcon("encrypted", KIcon::Small)); | 79 | static QPixmap offP(picons->loadIcon("encrypted", KIcon::Small)); |
72 | offPix = &offP; | 80 | offPix = &offP; |
73 | } | 81 | } |
74 | } | 82 | } |
75 | 83 | ||
76 | void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg, | 84 | void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg, |
77 | int column, int width, int align) | 85 | int column, int width, int align) |
78 | { | 86 | { |
79 | // qDebug("ListViewItemPwM::paintCell column=%i", column); | 87 | // qDebug("ListViewItemPwM::paintCell column=%i", column); |
80 | if (!p) | 88 | if (!p) |
81 | return; | 89 | return; |
82 | //US BUG: | 90 | //US BUG: |
83 | if (column != COLUMN_DESC) { | 91 | if (column != COLUMN_DESC) { |
84 | QCheckListItem::paintCell(p, cg, column, width, align); | 92 | QCheckListItem::paintCell(p, cg, column, width, align); |
85 | return; | 93 | return; |
86 | } | 94 | } |
87 | QPixmap *curPix = isOn() ? onPix : offPix; | 95 | QPixmap *curPix = isOn() ? onPix : offPix; |
88 | int pixSpace = curPix->width(); | 96 | int pixSpace = curPix->width(); |
89 | pixSpace += 4; | 97 | pixSpace += 4; |
90 | #ifndef PWM_EMBEDDED | 98 | #ifndef PWM_EMBEDDED |
91 | QRect window(p->viewport()); | 99 | QRect window(p->viewport()); |
92 | // clear the rectangle (we have to clear it first. see QT doc) | 100 | // clear the rectangle (we have to clear it first. see QT doc) |
93 | p->eraseRect(0, 0, pixSpace, window.height()); | 101 | p->eraseRect(0, 0, pixSpace, window.height()); |
94 | // now draw the pixmap | 102 | // now draw the pixmap |
95 | int y = (height() - curPix->height()) / 2; | 103 | int y = (height() - curPix->height()) / 2; |
96 | p->drawPixmap(1, y, *curPix); | 104 | p->drawPixmap(1, y, *curPix); |
97 | window.moveLeft(pixSpace); | 105 | window.moveLeft(pixSpace); |
98 | p->setViewport(window); | 106 | p->setViewport(window); |
99 | #else | 107 | #else |
100 | p->eraseRect(0, 0, pixSpace, height()); | 108 | p->eraseRect(0, 0, pixSpace, height()); |
101 | // now draw the pixmap | 109 | // now draw the pixmap |
102 | int y = (height() - curPix->height()) / 2; | 110 | int y = (height() - curPix->height()) / 2; |
103 | p->drawPixmap(1, y, *curPix); | 111 | p->drawPixmap(1, y, *curPix); |
104 | p->translate( pixSpace, 0 ); | 112 | p->translate( pixSpace, 0 ); |
105 | 113 | ||
106 | #endif | 114 | #endif |
107 | QListViewItem::paintCell(p, cg, column, width - pixSpace, align); | 115 | QListViewItem::paintCell(p, cg, column, width - pixSpace, align); |
108 | 116 | ||
109 | } | 117 | } |
110 | 118 | ||
111 | #ifndef PWM_EMBEDDED | 119 | #ifndef PWM_EMBEDDED |
112 | #include "listviewpwm.moc" | 120 | #include "listviewpwm.moc" |
113 | #endif | 121 | #endif |
diff --git a/pwmanager/pwmanager/listviewpwm.h b/pwmanager/pwmanager/listviewpwm.h index e6471c6..840ee73 100644 --- a/pwmanager/pwmanager/listviewpwm.h +++ b/pwmanager/pwmanager/listviewpwm.h | |||
@@ -1,57 +1,58 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef __LISTVIEW_H | 20 | #ifndef __LISTVIEW_H |
21 | #define __LISTVIEW_H | 21 | #define __LISTVIEW_H |
22 | 22 | ||
23 | #include <klistview.h> | 23 | #include <klistview.h> |
24 | 24 | ||
25 | /** PwManager implementation of the list view. | 25 | /** PwManager implementation of the list view. |
26 | * Derived from KListView. | 26 | * Derived from KListView. |
27 | */ | 27 | */ |
28 | class ListViewPwM : public KListView | 28 | class ListViewPwM : public KListView |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | public: | 31 | public: |
32 | ListViewPwM(QWidget *parent = 0, const char *name = 0); | 32 | ListViewPwM(QWidget *parent = 0, const char *name = 0); |
33 | 33 | ||
34 | signals: | 34 | signals: |
35 | void layoutChanged(); | 35 | void layoutChanged(); |
36 | void toggleOverview(); | ||
36 | 37 | ||
37 | protected: | 38 | protected: |
38 | virtual bool event(QEvent *e); | 39 | virtual bool event(QEvent *e); |
39 | }; | 40 | }; |
40 | 41 | ||
41 | class ListViewItemPwM : public QCheckListItem | 42 | class ListViewItemPwM : public QCheckListItem |
42 | { | 43 | { |
43 | public: | 44 | public: |
44 | ListViewItemPwM(QListView *parent); | 45 | ListViewItemPwM(QListView *parent); |
45 | 46 | ||
46 | protected: | 47 | protected: |
47 | void paintCell(QPainter *p, const QColorGroup &cg, | 48 | void paintCell(QPainter *p, const QColorGroup &cg, |
48 | int column, int width, int align); | 49 | int column, int width, int align); |
49 | 50 | ||
50 | protected: | 51 | protected: |
51 | /** pixmap to display for an item with state "on" */ | 52 | /** pixmap to display for an item with state "on" */ |
52 | static QPixmap *onPix; | 53 | static QPixmap *onPix; |
53 | /** pixmap to display for an item with state "off" */ | 54 | /** pixmap to display for an item with state "off" */ |
54 | static QPixmap *offPix; | 55 | static QPixmap *offPix; |
55 | }; | 56 | }; |
56 | 57 | ||
57 | #endif | 58 | #endif |
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index aed8ec0..9187380 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,1564 +1,1564 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include <klocale.h> | 20 | #include <klocale.h> |
21 | #include <klistview.h> | 21 | #include <klistview.h> |
22 | #include <ktoolbar.h> | 22 | #include <ktoolbar.h> |
23 | #include <kfiledialog.h> | 23 | #include <kfiledialog.h> |
24 | #include <kiconloader.h> | 24 | #include <kiconloader.h> |
25 | #include <kmessagebox.h> | 25 | #include <kmessagebox.h> |
26 | 26 | ||
27 | #include <qstatusbar.h> | 27 | #include <qstatusbar.h> |
28 | 28 | ||
29 | #ifndef PWM_EMBEDDED | 29 | #ifndef PWM_EMBEDDED |
30 | #include <kmenubar.h> | 30 | #include <kmenubar.h> |
31 | #include <kstatusbar.h> | 31 | #include <kstatusbar.h> |
32 | #include <dcopclient.h> | 32 | #include <dcopclient.h> |
33 | #include "configwndimpl.h" | 33 | #include "configwndimpl.h" |
34 | #include "configuration.h" | 34 | #include "configuration.h" |
35 | #else | 35 | #else |
36 | #include <qmenubar.h> | 36 | #include <qmenubar.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <pwmprefs.h> | 38 | #include <pwmprefs.h> |
39 | #include <kpimglobalprefs.h> | 39 | #include <kpimglobalprefs.h> |
40 | #include <kcmconfigs/kcmpwmconfig.h> | 40 | #include <kcmconfigs/kcmpwmconfig.h> |
41 | #include <kcmconfigs/kcmkdepimconfig.h> | 41 | #include <kcmconfigs/kcmkdepimconfig.h> |
42 | #include <kcmultidialog.h> | 42 | #include <kcmultidialog.h> |
43 | #include "editcategory.h" | 43 | #include "editcategory.h" |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | #ifndef DESKTOP_VERSION | 47 | #ifndef DESKTOP_VERSION |
48 | #include <qpe/global.h> | 48 | #include <qpe/global.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #include <qpixmap.h> | 51 | #include <qpixmap.h> |
52 | #include <qcheckbox.h> | 52 | #include <qcheckbox.h> |
53 | #include <qspinbox.h> | 53 | #include <qspinbox.h> |
54 | #include <qlineedit.h> | 54 | #include <qlineedit.h> |
55 | #include <qfileinfo.h> | 55 | #include <qfileinfo.h> |
56 | #include <qclipboard.h> | 56 | #include <qclipboard.h> |
57 | 57 | ||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | 60 | ||
61 | #include "pwm.h" | 61 | #include "pwm.h" |
62 | #include "pwminit.h" | 62 | #include "pwminit.h" |
63 | #include "pwmprint.h" | 63 | #include "pwmprint.h" |
64 | #include "addentrywndimpl.h" | 64 | #include "addentrywndimpl.h" |
65 | #include "globalstuff.h" | 65 | #include "globalstuff.h" |
66 | #include "findwndimpl.h" | 66 | #include "findwndimpl.h" |
67 | #include "csv.h" | 67 | #include "csv.h" |
68 | 68 | ||
69 | #ifdef CONFIG_KWALLETIF | 69 | #ifdef CONFIG_KWALLETIF |
70 | # include "kwalletif.h" | 70 | # include "kwalletif.h" |
71 | # include "kwalletemu.h" | 71 | # include "kwalletemu.h" |
72 | #endif | 72 | #endif |
73 | #ifdef CONFIG_KEYCARD | 73 | #ifdef CONFIG_KEYCARD |
74 | # include "pwmkeycard.h" | 74 | # include "pwmkeycard.h" |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | 77 | ||
78 | #define DEFAULT_SIZE (QSize(700, 400)) | 78 | #define DEFAULT_SIZE (QSize(700, 400)) |
79 | 79 | ||
80 | // Button IDs for "file" popup menu | 80 | // Button IDs for "file" popup menu |
81 | enum { | 81 | enum { |
82 | BUTTON_POPUP_FILE_NEW = 0, | 82 | BUTTON_POPUP_FILE_NEW = 0, |
83 | BUTTON_POPUP_FILE_OPEN, | 83 | BUTTON_POPUP_FILE_OPEN, |
84 | BUTTON_POPUP_FILE_CLOSE, | 84 | BUTTON_POPUP_FILE_CLOSE, |
85 | BUTTON_POPUP_FILE_SAVE, | 85 | BUTTON_POPUP_FILE_SAVE, |
86 | BUTTON_POPUP_FILE_SAVEAS, | 86 | BUTTON_POPUP_FILE_SAVEAS, |
87 | BUTTON_POPUP_FILE_EXPORT, | 87 | BUTTON_POPUP_FILE_EXPORT, |
88 | BUTTON_POPUP_FILE_IMPORT, | 88 | BUTTON_POPUP_FILE_IMPORT, |
89 | BUTTON_POPUP_FILE_PRINT, | 89 | BUTTON_POPUP_FILE_PRINT, |
90 | BUTTON_POPUP_FILE_QUIT | 90 | BUTTON_POPUP_FILE_QUIT |
91 | }; | 91 | }; |
92 | // Button IDs for "manage" popup menu | 92 | // Button IDs for "manage" popup menu |
93 | enum { | 93 | enum { |
94 | BUTTON_POPUP_MANAGE_ADD = 0, | 94 | BUTTON_POPUP_MANAGE_ADD = 0, |
95 | BUTTON_POPUP_MANAGE_EDIT, | 95 | BUTTON_POPUP_MANAGE_EDIT, |
96 | BUTTON_POPUP_MANAGE_DEL, | 96 | BUTTON_POPUP_MANAGE_DEL, |
97 | BUTTON_POPUP_MANAGE_CHANGEMP | 97 | BUTTON_POPUP_MANAGE_CHANGEMP |
98 | }; | 98 | }; |
99 | // Button IDs for chipcard popup menu | 99 | // Button IDs for chipcard popup menu |
100 | enum { | 100 | enum { |
101 | #ifdef CONFIG_KEYCARD | 101 | #ifdef CONFIG_KEYCARD |
102 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, | 102 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, |
103 | BUTTON_POPUP_CHIPCARD_DEL, | 103 | BUTTON_POPUP_CHIPCARD_DEL, |
104 | BUTTON_POPUP_CHIPCARD_READID, | 104 | BUTTON_POPUP_CHIPCARD_READID, |
105 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, | 105 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, |
106 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP | 106 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP |
107 | #else // CONFIG_KEYCARD | 107 | #else // CONFIG_KEYCARD |
108 | BUTTON_POPUP_CHIPCARD_NO = 0 | 108 | BUTTON_POPUP_CHIPCARD_NO = 0 |
109 | #endif // CONFIG_KEYCARD | 109 | #endif // CONFIG_KEYCARD |
110 | }; | 110 | }; |
111 | // Button IDs for "view" popup menu | 111 | // Button IDs for "view" popup menu |
112 | enum { | 112 | enum { |
113 | BUTTON_POPUP_VIEW_FIND = 0, | 113 | BUTTON_POPUP_VIEW_FIND = 0, |
114 | BUTTON_POPUP_VIEW_LOCK, | 114 | BUTTON_POPUP_VIEW_LOCK, |
115 | BUTTON_POPUP_VIEW_DEEPLOCK, | 115 | BUTTON_POPUP_VIEW_DEEPLOCK, |
116 | BUTTON_POPUP_VIEW_UNLOCK | 116 | BUTTON_POPUP_VIEW_UNLOCK |
117 | }; | 117 | }; |
118 | // Button IDs for "options" popup menu | 118 | // Button IDs for "options" popup menu |
119 | enum { | 119 | enum { |
120 | BUTTON_POPUP_OPTIONS_CONFIG = 0 | 120 | BUTTON_POPUP_OPTIONS_CONFIG = 0 |
121 | #ifdef PWM_EMBEDDED | 121 | #ifdef PWM_EMBEDDED |
122 | ,BUTTON_POPUP_OPTIONS_CATEGORY | 122 | ,BUTTON_POPUP_OPTIONS_CATEGORY |
123 | #endif | 123 | #endif |
124 | }; | 124 | }; |
125 | // Button IDs for "export" popup menu (in "file" popup menu) | 125 | // Button IDs for "export" popup menu (in "file" popup menu) |
126 | enum { | 126 | enum { |
127 | BUTTON_POPUP_EXPORT_TEXT = 0, | 127 | BUTTON_POPUP_EXPORT_TEXT = 0, |
128 | BUTTON_POPUP_EXPORT_GPASMAN, | 128 | BUTTON_POPUP_EXPORT_GPASMAN, |
129 | BUTTON_POPUP_EXPORT_CSV | 129 | BUTTON_POPUP_EXPORT_CSV |
130 | #ifdef CONFIG_KWALLETIF | 130 | #ifdef CONFIG_KWALLETIF |
131 | ,BUTTON_POPUP_EXPORT_KWALLET | 131 | ,BUTTON_POPUP_EXPORT_KWALLET |
132 | #endif | 132 | #endif |
133 | }; | 133 | }; |
134 | // Button IDs for "import" popup menu (in "file" popup menu) | 134 | // Button IDs for "import" popup menu (in "file" popup menu) |
135 | enum { | 135 | enum { |
136 | BUTTON_POPUP_IMPORT_TEXT = 0, | 136 | BUTTON_POPUP_IMPORT_TEXT = 0, |
137 | BUTTON_POPUP_IMPORT_GPASMAN, | 137 | BUTTON_POPUP_IMPORT_GPASMAN, |
138 | BUTTON_POPUP_IMPORT_CSV | 138 | BUTTON_POPUP_IMPORT_CSV |
139 | #ifdef CONFIG_KWALLETIF | 139 | #ifdef CONFIG_KWALLETIF |
140 | ,BUTTON_POPUP_IMPORT_KWALLET | 140 | ,BUTTON_POPUP_IMPORT_KWALLET |
141 | #endif | 141 | #endif |
142 | }; | 142 | }; |
143 | 143 | ||
144 | #ifdef PWM_EMBEDDED | 144 | #ifdef PWM_EMBEDDED |
145 | // Button IDs for "help" popup menu | 145 | // Button IDs for "help" popup menu |
146 | enum { | 146 | enum { |
147 | BUTTON_POPUP_HELP_LICENSE = 0, | 147 | BUTTON_POPUP_HELP_LICENSE = 0, |
148 | BUTTON_POPUP_HELP_FAQ, | 148 | BUTTON_POPUP_HELP_FAQ, |
149 | BUTTON_POPUP_HELP_ABOUT, | 149 | BUTTON_POPUP_HELP_ABOUT, |
150 | BUTTON_POPUP_HELP_SYNC, | 150 | BUTTON_POPUP_HELP_SYNC, |
151 | BUTTON_POPUP_HELP_WHATSNEW | 151 | BUTTON_POPUP_HELP_WHATSNEW |
152 | }; | 152 | }; |
153 | #endif | 153 | #endif |
154 | 154 | ||
155 | // Button IDs for toolbar | 155 | // Button IDs for toolbar |
156 | enum { | 156 | enum { |
157 | BUTTON_TOOL_NEW = 0, | 157 | BUTTON_TOOL_NEW = 0, |
158 | BUTTON_TOOL_OPEN, | 158 | BUTTON_TOOL_OPEN, |
159 | BUTTON_TOOL_SAVE, | 159 | BUTTON_TOOL_SAVE, |
160 | BUTTON_TOOL_SAVEAS, | 160 | BUTTON_TOOL_SAVEAS, |
161 | BUTTON_TOOL_PRINT, | 161 | BUTTON_TOOL_PRINT, |
162 | BUTTON_TOOL_ADD, | 162 | BUTTON_TOOL_ADD, |
163 | BUTTON_TOOL_EDIT, | 163 | BUTTON_TOOL_EDIT, |
164 | BUTTON_TOOL_DEL, | 164 | BUTTON_TOOL_DEL, |
165 | BUTTON_TOOL_FIND, | 165 | BUTTON_TOOL_FIND, |
166 | BUTTON_TOOL_LOCK, | 166 | BUTTON_TOOL_LOCK, |
167 | BUTTON_TOOL_DEEPLOCK, | 167 | BUTTON_TOOL_DEEPLOCK, |
168 | BUTTON_TOOL_UNLOCK | 168 | BUTTON_TOOL_UNLOCK |
169 | }; | 169 | }; |
170 | 170 | ||
171 | 171 | ||
172 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 172 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
173 | bool virginity, | 173 | bool virginity, |
174 | QWidget *parent, const char *name) | 174 | QWidget *parent, const char *name) |
175 | : KMainWindow(parent, "HALLO") | 175 | : KMainWindow(parent, "HALLO") |
176 | , forceQuit (false) | 176 | , forceQuit (false) |
177 | , forceMinimizeToTray (false) | 177 | , forceMinimizeToTray (false) |
178 | { | 178 | { |
179 | syncManager = 0; | 179 | syncManager = 0; |
180 | virgin = !virginity; | 180 | virgin = !virginity; |
181 | init = _init; | 181 | init = _init; |
182 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 182 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
183 | this, SLOT(docClosed(PwMDoc *))); | 183 | this, SLOT(docClosed(PwMDoc *))); |
184 | initMenubar(); | 184 | initMenubar(); |
185 | initToolbar(); | 185 | initToolbar(); |
186 | initMetrics(); | 186 | initMetrics(); |
187 | setVirgin(virginity); | 187 | setVirgin(virginity); |
188 | setFocusPolicy(QWidget::WheelFocus); | 188 | setFocusPolicy(QWidget::WheelFocus); |
189 | #ifndef PWM_EMBEDDED | 189 | #ifndef PWM_EMBEDDED |
190 | statusBar()->show(); | 190 | statusBar()->show(); |
191 | #endif | 191 | #endif |
192 | view = makeNewListView(doc); | 192 | view = makeNewListView(doc); |
193 | setCentralWidget(view); | 193 | setCentralWidget(view); |
194 | updateCaption(); | 194 | updateCaption(); |
195 | showStatMsg(i18n("Ready.")); | 195 | showStatMsg(i18n("Ready.")); |
196 | } | 196 | } |
197 | 197 | ||
198 | PwM::~PwM() | 198 | PwM::~PwM() |
199 | { | 199 | { |
200 | //qDebug("PwM::~PwM() %x", this); | 200 | //qDebug("PwM::~PwM() %x", this); |
201 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 201 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
202 | this, SLOT(docClosed(PwMDoc *))); | 202 | this, SLOT(docClosed(PwMDoc *))); |
203 | conf()->confWndMainWndSize(size()); | 203 | conf()->confWndMainWndSize(size()); |
204 | //LR closing of windows changed | 204 | //LR closing of windows changed |
205 | //needed for fastload option on PDA | 205 | //needed for fastload option on PDA |
206 | //emit closed(this); | 206 | //emit closed(this); |
207 | //qDebug("PwM::~PwM() emited closed(this)"); | 207 | //qDebug("PwM::~PwM() emited closed(this)"); |
208 | delete view; | 208 | delete view; |
209 | delete syncManager; | 209 | delete syncManager; |
210 | } | 210 | } |
211 | 211 | ||
212 | void PwM::initMenubar() | 212 | void PwM::initMenubar() |
213 | { | 213 | { |
214 | KIconLoader* picons; | 214 | KIconLoader* picons; |
215 | #ifndef PWM_EMBEDDED | 215 | #ifndef PWM_EMBEDDED |
216 | KIconLoader icons; | 216 | KIconLoader icons; |
217 | picons = &icons; | 217 | picons = &icons; |
218 | #else | 218 | #else |
219 | picons = KGlobal::iconLoader(); | 219 | picons = KGlobal::iconLoader(); |
220 | 220 | ||
221 | 221 | ||
222 | syncPopup = new KPopupMenu(this); | 222 | syncPopup = new KPopupMenu(this); |
223 | 223 | ||
224 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); | 224 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); |
225 | syncManager->setBlockSave(false); | 225 | syncManager->setBlockSave(false); |
226 | 226 | ||
227 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 227 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
228 | syncManager->fillSyncMenu(); | 228 | syncManager->fillSyncMenu(); |
229 | 229 | ||
230 | #endif | 230 | #endif |
231 | filePopup = new KPopupMenu(this); | 231 | filePopup = new KPopupMenu(this); |
232 | importPopup = new KPopupMenu(filePopup); | 232 | importPopup = new KPopupMenu(filePopup); |
233 | exportPopup = new KPopupMenu(filePopup); | 233 | exportPopup = new KPopupMenu(filePopup); |
234 | managePopup = new KPopupMenu(this); | 234 | managePopup = new KPopupMenu(this); |
235 | #ifdef CONFIG_KEYCARD | 235 | #ifdef CONFIG_KEYCARD |
236 | chipcardPopup = new KPopupMenu(this); | 236 | chipcardPopup = new KPopupMenu(this); |
237 | #endif // CONFIG_KEYCARD | 237 | #endif // CONFIG_KEYCARD |
238 | viewPopup = new KPopupMenu(this); | 238 | viewPopup = new KPopupMenu(this); |
239 | optionsPopup = new KPopupMenu(this); | 239 | optionsPopup = new KPopupMenu(this); |
240 | 240 | ||
241 | // "file" popup menu | 241 | // "file" popup menu |
242 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 242 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
243 | i18n("&New"), this, | 243 | i18n("&New"), this, |
244 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 244 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
245 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 245 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
246 | i18n("&Open"), this, | 246 | i18n("&Open"), this, |
247 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 247 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
249 | i18n("&Close"), this, | 249 | i18n("&Close"), this, |
250 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 250 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
251 | filePopup->insertSeparator(); | 251 | filePopup->insertSeparator(); |
252 | filePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 252 | filePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
253 | i18n("&Add password"), this, | 253 | i18n("&Add password"), this, |
254 | SLOT(addPwd_slot()), 0, | 254 | SLOT(addPwd_slot()), 0, |
255 | BUTTON_POPUP_MANAGE_ADD); | 255 | BUTTON_POPUP_MANAGE_ADD); |
256 | filePopup->insertSeparator(); | 256 | filePopup->insertSeparator(); |
257 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 257 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
258 | i18n("&Save"), this, | 258 | i18n("&Save"), this, |
259 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 259 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
260 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 260 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
261 | i18n("Save &as..."), | 261 | i18n("Save &as..."), |
262 | this, SLOT(saveAs_slot()), 0, | 262 | this, SLOT(saveAs_slot()), 0, |
263 | BUTTON_POPUP_FILE_SAVEAS); | 263 | BUTTON_POPUP_FILE_SAVEAS); |
264 | filePopup->insertSeparator(); | 264 | filePopup->insertSeparator(); |
265 | // "file/export" popup menu | 265 | // "file/export" popup menu |
266 | exportPopup->insertItem(i18n("&Text-file..."), this, | 266 | exportPopup->insertItem(i18n("&Text-file..."), this, |
267 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 267 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
268 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 268 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
269 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 269 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
270 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 270 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
271 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); | 271 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); |
272 | #ifdef CONFIG_KWALLETIF | 272 | #ifdef CONFIG_KWALLETIF |
273 | exportPopup->insertItem(i18n("&KWallet..."), this, | 273 | exportPopup->insertItem(i18n("&KWallet..."), this, |
274 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 274 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
275 | #endif | 275 | #endif |
276 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 276 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
277 | i18n("E&xport"), exportPopup, | 277 | i18n("E&xport"), exportPopup, |
278 | BUTTON_POPUP_FILE_EXPORT); | 278 | BUTTON_POPUP_FILE_EXPORT); |
279 | // "file/import" popup menu | 279 | // "file/import" popup menu |
280 | importPopup->insertItem(i18n("&Text-file..."), this, | 280 | importPopup->insertItem(i18n("&Text-file..."), this, |
281 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 281 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
282 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 282 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
283 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 283 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
284 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 284 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
285 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); | 285 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); |
286 | #ifdef CONFIG_KWALLETIF | 286 | #ifdef CONFIG_KWALLETIF |
287 | importPopup->insertItem(i18n("&KWallet..."), this, | 287 | importPopup->insertItem(i18n("&KWallet..."), this, |
288 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 288 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
289 | #endif | 289 | #endif |
290 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 290 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
291 | i18n("I&mport"), importPopup, | 291 | i18n("I&mport"), importPopup, |
292 | BUTTON_POPUP_FILE_IMPORT); | 292 | BUTTON_POPUP_FILE_IMPORT); |
293 | filePopup->insertSeparator(); | 293 | filePopup->insertSeparator(); |
294 | #if 0 | 294 | #if 0 |
295 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 295 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
296 | i18n("&Print..."), this, | 296 | i18n("&Print..."), this, |
297 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 297 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
298 | filePopup->insertSeparator(); | 298 | filePopup->insertSeparator(); |
299 | #endif | 299 | #endif |
300 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 300 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
301 | i18n("&Quit"), this, | 301 | i18n("&Quit"), this, |
302 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 302 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
303 | menuBar()->insertItem(i18n("&File"), filePopup); | 303 | menuBar()->insertItem(i18n("&File"), filePopup); |
304 | // "manage" popup menu | 304 | // "manage" popup menu |
305 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 305 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
306 | i18n("&Add password"), this, | 306 | i18n("&Add password"), this, |
307 | SLOT(addPwd_slot()), 0, | 307 | SLOT(addPwd_slot()), 0, |
308 | BUTTON_POPUP_MANAGE_ADD); | 308 | BUTTON_POPUP_MANAGE_ADD); |
309 | managePopup->insertSeparator(); | 309 | managePopup->insertSeparator(); |
310 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 310 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
311 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 311 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
312 | BUTTON_POPUP_MANAGE_EDIT); | 312 | BUTTON_POPUP_MANAGE_EDIT); |
313 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 313 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
314 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 314 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
315 | 0, BUTTON_POPUP_MANAGE_DEL); | 315 | 0, BUTTON_POPUP_MANAGE_DEL); |
316 | managePopup->insertSeparator(); | 316 | managePopup->insertSeparator(); |
317 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 317 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
318 | i18n("Change &Master Password"), this, | 318 | i18n("Change &Master Password"), this, |
319 | SLOT(changeMasterPwd_slot()), 0, | 319 | SLOT(changeMasterPwd_slot()), 0, |
320 | BUTTON_POPUP_MANAGE_CHANGEMP); | 320 | BUTTON_POPUP_MANAGE_CHANGEMP); |
321 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 321 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
322 | // "chipcard" popup menu | 322 | // "chipcard" popup menu |
323 | #ifdef CONFIG_KEYCARD | 323 | #ifdef CONFIG_KEYCARD |
324 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 324 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
325 | i18n("&Generate new key-card"), this, | 325 | i18n("&Generate new key-card"), this, |
326 | SLOT(genNewCard_slot()), 0, | 326 | SLOT(genNewCard_slot()), 0, |
327 | BUTTON_POPUP_CHIPCARD_GENNEW); | 327 | BUTTON_POPUP_CHIPCARD_GENNEW); |
328 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 328 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
329 | i18n("&Erase key-card"), this, | 329 | i18n("&Erase key-card"), this, |
330 | SLOT(eraseCard_slot()), 0, | 330 | SLOT(eraseCard_slot()), 0, |
331 | BUTTON_POPUP_CHIPCARD_DEL); | 331 | BUTTON_POPUP_CHIPCARD_DEL); |
332 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 332 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
333 | i18n("Read card-&ID"), this, | 333 | i18n("Read card-&ID"), this, |
334 | SLOT(readCardId_slot()), 0, | 334 | SLOT(readCardId_slot()), 0, |
335 | BUTTON_POPUP_CHIPCARD_READID); | 335 | BUTTON_POPUP_CHIPCARD_READID); |
336 | chipcardPopup->insertSeparator(); | 336 | chipcardPopup->insertSeparator(); |
337 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 337 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
338 | i18n("&Make card backup-image"), this, | 338 | i18n("&Make card backup-image"), this, |
339 | SLOT(makeCardBackup_slot()), 0, | 339 | SLOT(makeCardBackup_slot()), 0, |
340 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 340 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
341 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 341 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
342 | i18n("&Replay card backup-image"), this, | 342 | i18n("&Replay card backup-image"), this, |
343 | SLOT(replayCardBackup_slot()), 0, | 343 | SLOT(replayCardBackup_slot()), 0, |
344 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 344 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
345 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 345 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
346 | #endif // CONFIG_KEYCARD | 346 | #endif // CONFIG_KEYCARD |
347 | // "view" popup menu | 347 | // "view" popup menu |
348 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 348 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
349 | i18n("&Find"), this, | 349 | i18n("&Find"), this, |
350 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 350 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
351 | viewPopup->insertSeparator(); | 351 | viewPopup->insertSeparator(); |
352 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 352 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
353 | i18n("&Lock all entries"), this, | 353 | i18n("&Lock all entries"), this, |
354 | SLOT(lockWnd_slot()), 0, | 354 | SLOT(lockWnd_slot()), 0, |
355 | BUTTON_POPUP_VIEW_LOCK); | 355 | BUTTON_POPUP_VIEW_LOCK); |
356 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 356 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
357 | i18n("&Deep-lock all entries"), this, | 357 | i18n("&Deep-lock all entries"), this, |
358 | SLOT(deepLockWnd_slot()), 0, | 358 | SLOT(deepLockWnd_slot()), 0, |
359 | BUTTON_POPUP_VIEW_DEEPLOCK); | 359 | BUTTON_POPUP_VIEW_DEEPLOCK); |
360 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 360 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
361 | i18n("&Unlock all entries"), this, | 361 | i18n("&Unlock all entries"), this, |
362 | SLOT(unlockWnd_slot()), 0, | 362 | SLOT(unlockWnd_slot()), 0, |
363 | BUTTON_POPUP_VIEW_UNLOCK); | 363 | BUTTON_POPUP_VIEW_UNLOCK); |
364 | menuBar()->insertItem(i18n("&View"), viewPopup); | 364 | menuBar()->insertItem(i18n("&View"), viewPopup); |
365 | // "options" popup menu | 365 | // "options" popup menu |
366 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 366 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
367 | i18n("&Configure..."), this, | 367 | i18n("&Configure..."), this, |
368 | SLOT(config_slot()),0, | 368 | SLOT(config_slot()),0, |
369 | BUTTON_POPUP_OPTIONS_CONFIG); | 369 | BUTTON_POPUP_OPTIONS_CONFIG); |
370 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 370 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
371 | // "help" popup menu | 371 | // "help" popup menu |
372 | #ifndef PWM_EMBEDDED | 372 | #ifndef PWM_EMBEDDED |
373 | helpPopup = helpMenu(QString::null, false); | 373 | helpPopup = helpMenu(QString::null, false); |
374 | #else | 374 | #else |
375 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 375 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
376 | i18n("C&ategories..."), this, | 376 | i18n("C&ategories..."), this, |
377 | SLOT(category_slot()),0, | 377 | SLOT(category_slot()),0, |
378 | BUTTON_POPUP_OPTIONS_CATEGORY); | 378 | BUTTON_POPUP_OPTIONS_CATEGORY); |
379 | 379 | ||
380 | 380 | ||
381 | menuBar()->insertItem(i18n("&Sync"), syncPopup); | 381 | menuBar()->insertItem(i18n("&Sync"), syncPopup); |
382 | 382 | ||
383 | 383 | ||
384 | 384 | ||
385 | 385 | ||
386 | 386 | ||
387 | helpPopup = new KPopupMenu(this); | 387 | helpPopup = new KPopupMenu(this); |
388 | 388 | ||
389 | 389 | ||
390 | helpPopup->insertItem(i18n("&License"), this, | 390 | helpPopup->insertItem(i18n("&License"), this, |
391 | SLOT(showLicense_slot()), 0, | 391 | SLOT(showLicense_slot()), 0, |
392 | BUTTON_POPUP_HELP_LICENSE); | 392 | BUTTON_POPUP_HELP_LICENSE); |
393 | 393 | ||
394 | helpPopup->insertItem(i18n("&Faq"), this, | 394 | helpPopup->insertItem(i18n("&Faq"), this, |
395 | SLOT(faq_slot()), 0, | 395 | SLOT(faq_slot()), 0, |
396 | BUTTON_POPUP_HELP_FAQ); | 396 | BUTTON_POPUP_HELP_FAQ); |
397 | 397 | ||
398 | helpPopup->insertItem(i18n("&About PwManager"), this, | 398 | helpPopup->insertItem(i18n("&About PwManager"), this, |
399 | SLOT(createAboutData_slot()), 0, | 399 | SLOT(createAboutData_slot()), 0, |
400 | BUTTON_POPUP_HELP_ABOUT); | 400 | BUTTON_POPUP_HELP_ABOUT); |
401 | 401 | ||
402 | helpPopup->insertItem(i18n("&Sync HowTo"), this, | 402 | helpPopup->insertItem(i18n("&Sync HowTo"), this, |
403 | SLOT(syncHowTo_slot()), 0, | 403 | SLOT(syncHowTo_slot()), 0, |
404 | BUTTON_POPUP_HELP_SYNC); | 404 | BUTTON_POPUP_HELP_SYNC); |
405 | 405 | ||
406 | helpPopup->insertItem(i18n("&What's New"), this, | 406 | helpPopup->insertItem(i18n("&What's New"), this, |
407 | SLOT(whatsnew_slot()), 0, | 407 | SLOT(whatsnew_slot()), 0, |
408 | BUTTON_POPUP_HELP_WHATSNEW); | 408 | BUTTON_POPUP_HELP_WHATSNEW); |
409 | 409 | ||
410 | #endif | 410 | #endif |
411 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 411 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
412 | 412 | ||
413 | } | 413 | } |
414 | 414 | ||
415 | void PwM::initToolbar() | 415 | void PwM::initToolbar() |
416 | { | 416 | { |
417 | KIconLoader* picons; | 417 | KIconLoader* picons; |
418 | #ifndef PWM_EMBEDDED | 418 | #ifndef PWM_EMBEDDED |
419 | KIconLoader icons; | 419 | KIconLoader icons; |
420 | picons = &icons; | 420 | picons = &icons; |
421 | #else | 421 | #else |
422 | picons = KGlobal::iconLoader(); | 422 | picons = KGlobal::iconLoader(); |
423 | #endif | 423 | #endif |
424 | 424 | ||
425 | #if 0 | 425 | #if 0 |
426 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 426 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
427 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 427 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
428 | SLOT(new_slot()), true, i18n("New")); | 428 | SLOT(new_slot()), true, i18n("New")); |
429 | #endif | 429 | #endif |
430 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 430 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
431 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 431 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
432 | SLOT(open_slot()), true, i18n("Open")); | 432 | SLOT(open_slot()), true, i18n("Open")); |
433 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), | 433 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), |
434 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, | 434 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, |
435 | SLOT(addPwd_slot()), true, | 435 | SLOT(addPwd_slot()), true, |
436 | i18n("Add password")); | 436 | i18n("Add password")); |
437 | toolBar()->insertSeparator(); | 437 | toolBar()->insertSeparator(); |
438 | 438 | ||
439 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), | 439 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), |
440 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, | 440 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, |
441 | SLOT(find_slot()), true, i18n("Find entry")); | 441 | SLOT(find_slot()), true, i18n("Find entry")); |
442 | toolBar()->insertSeparator(); | 442 | toolBar()->insertSeparator(); |
443 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), | 443 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), |
444 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, | 444 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, |
445 | SLOT(save_slot()), true, i18n("Save")); | 445 | SLOT(save_slot()), true, i18n("Save")); |
446 | #if 0 | 446 | #if 0 |
447 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), | 447 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), |
448 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, | 448 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, |
449 | SLOT(saveAs_slot()), true, i18n("Save as")); | 449 | SLOT(saveAs_slot()), true, i18n("Save as")); |
450 | #endif | 450 | #endif |
451 | 451 | ||
452 | 452 | ||
453 | #if 0 | 453 | #if 0 |
454 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), | 454 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), |
455 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, | 455 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, |
456 | SLOT(print_slot()), true, i18n("Print...")); | 456 | SLOT(print_slot()), true, i18n("Print...")); |
457 | #endif | 457 | #endif |
458 | toolBar()->insertSeparator(); | 458 | toolBar()->insertSeparator(); |
459 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), | 459 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), |
460 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, | 460 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, |
461 | SLOT(editPwd_slot()), true, | 461 | SLOT(editPwd_slot()), true, |
462 | i18n("Edit password")); | 462 | i18n("Edit password")); |
463 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), | 463 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), |
464 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, | 464 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, |
465 | SLOT(deletePwd_slot()), true, | 465 | SLOT(deletePwd_slot()), true, |
466 | i18n("Delete password")); | 466 | i18n("Delete password")); |
467 | toolBar()->insertSeparator(); | 467 | toolBar()->insertSeparator(); |
468 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), | 468 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), |
469 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, | 469 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, |
470 | SLOT(lockWnd_slot()), true, | 470 | SLOT(lockWnd_slot()), true, |
471 | i18n("Lock all entries")); | 471 | i18n("Lock all entries")); |
472 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), | 472 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), |
473 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, | 473 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, |
474 | SLOT(deepLockWnd_slot()), true, | 474 | SLOT(deepLockWnd_slot()), true, |
475 | i18n("Deep-Lock all entries")); | 475 | i18n("Deep-Lock all entries")); |
476 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), | 476 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), |
477 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, | 477 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, |
478 | SLOT(unlockWnd_slot()), true, | 478 | SLOT(unlockWnd_slot()), true, |
479 | i18n("Unlock all entries")); | 479 | i18n("Unlock all entries")); |
480 | } | 480 | } |
481 | 481 | ||
482 | void PwM::initMetrics() | 482 | void PwM::initMetrics() |
483 | { | 483 | { |
484 | QSize s = conf()->confWndMainWndSize(); | 484 | QSize s = conf()->confWndMainWndSize(); |
485 | if (s.isValid()) | 485 | if (s.isValid()) |
486 | resize(s); | 486 | resize(s); |
487 | else | 487 | else |
488 | resize(DEFAULT_SIZE); | 488 | resize(DEFAULT_SIZE); |
489 | } | 489 | } |
490 | 490 | ||
491 | void PwM::updateCaption() | 491 | void PwM::updateCaption() |
492 | { | 492 | { |
493 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); | 493 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); |
494 | } | 494 | } |
495 | 495 | ||
496 | void PwM::hideEvent(QHideEvent *) | 496 | void PwM::hideEvent(QHideEvent *) |
497 | { | 497 | { |
498 | if (isMinimized()) { | 498 | if (isMinimized()) { |
499 | if (init->tray()) { | 499 | if (init->tray()) { |
500 | forceMinimizeToTray = true; | 500 | forceMinimizeToTray = true; |
501 | close(); | 501 | close(); |
502 | } | 502 | } |
503 | int mmlock = conf()->confGlobMinimizeLock(); | 503 | int mmlock = conf()->confGlobMinimizeLock(); |
504 | switch (mmlock) { | 504 | switch (mmlock) { |
505 | case 0: // don't lock anything | 505 | case 0: // don't lock anything |
506 | break; | 506 | break; |
507 | case 1: {// normal lock | 507 | case 1: {// normal lock |
508 | curDoc()->lockAll(true); | 508 | curDoc()->lockAll(true); |
509 | break; | 509 | break; |
510 | } case 2: {// deep-lock | 510 | } case 2: {// deep-lock |
511 | curDoc()->deepLock(); | 511 | curDoc()->deepLock(); |
512 | break; | 512 | break; |
513 | } default: | 513 | } default: |
514 | WARN(); | 514 | WARN(); |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | void PwM::setVirgin(bool v) | 519 | void PwM::setVirgin(bool v) |
520 | { | 520 | { |
521 | if (virgin == v) | 521 | if (virgin == v) |
522 | return; | 522 | return; |
523 | virgin = v; | 523 | virgin = v; |
524 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); | 524 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); |
525 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); | 525 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); |
526 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); | 526 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); |
527 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); | 527 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); |
528 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); | 528 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); |
529 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); | 529 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); |
530 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); | 530 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); |
531 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); | 531 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); |
532 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); | 532 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); |
533 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); | 533 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); |
534 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); | 534 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); |
535 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); | 535 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); |
536 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); | 536 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); |
537 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); | 537 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); |
538 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); | 538 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); |
539 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); | 539 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); |
540 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); | 540 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); |
541 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); | 541 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); |
542 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); | 542 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); |
543 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); | 543 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); |
544 | } | 544 | } |
545 | 545 | ||
546 | void PwM::new_slot() | 546 | void PwM::new_slot() |
547 | { | 547 | { |
548 | init->createMainWnd(); | 548 | init->createMainWnd(); |
549 | } | 549 | } |
550 | 550 | ||
551 | //US ENH | 551 | //US ENH |
552 | void PwM::open_slot() | 552 | void PwM::open_slot() |
553 | { | 553 | { |
554 | open_slot(""); | 554 | open_slot(""); |
555 | } | 555 | } |
556 | 556 | ||
557 | void PwM::open_slot(QString fn) | 557 | void PwM::open_slot(QString fn) |
558 | { | 558 | { |
559 | openDoc(fn); | 559 | openDoc(fn); |
560 | } | 560 | } |
561 | 561 | ||
562 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) | 562 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) |
563 | { | 563 | { |
564 | if (!isVirgin()) { | 564 | if (!isVirgin()) { |
565 | // open the document in a new window. | 565 | // open the document in a new window. |
566 | PwM *newInstance = init->createMainWnd(); | 566 | PwM *newInstance = init->createMainWnd(); |
567 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); | 567 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); |
568 | if (!newDoc) { | 568 | if (!newDoc) { |
569 | newInstance->setForceQuit(true); | 569 | newInstance->setForceQuit(true); |
570 | delete_and_null(newInstance); | 570 | delete_and_null(newInstance); |
571 | } | 571 | } |
572 | return newDoc; | 572 | return newDoc; |
573 | } | 573 | } |
574 | 574 | ||
575 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) | 575 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) |
576 | return 0; | 576 | return 0; |
577 | showStatMsg(i18n("Successfully opened file.")); | 577 | showStatMsg(i18n("Successfully opened file.")); |
578 | updateCaption(); | 578 | updateCaption(); |
579 | setVirgin(false); | 579 | setVirgin(false); |
580 | return curDoc(); | 580 | return curDoc(); |
581 | } | 581 | } |
582 | 582 | ||
583 | PwMView * PwM::makeNewListView(PwMDoc *doc) | 583 | PwMView * PwM::makeNewListView(PwMDoc *doc) |
584 | { | 584 | { |
585 | PwMView *ret = new PwMView(this, this, doc); | 585 | PwMView *ret = new PwMView(this, this, doc); |
586 | ret->setFont(conf()->confGlobEntryFont()); | 586 | ret->setFont(conf()->confGlobEntryFont()); |
587 | ret->show(); | 587 | ret->show(); |
588 | return ret; | 588 | return ret; |
589 | } | 589 | } |
590 | 590 | ||
591 | void PwM::close_slot() | 591 | void PwM::close_slot() |
592 | { | 592 | { |
593 | close(); | 593 | close(); |
594 | } | 594 | } |
595 | 595 | ||
596 | void PwM::quitButton_slot() | 596 | void PwM::quitButton_slot() |
597 | { | 597 | { |
598 | init->shutdownApp(0); | 598 | init->shutdownApp(0); |
599 | } | 599 | } |
600 | 600 | ||
601 | void PwM::save_slot() | 601 | void PwM::save_slot() |
602 | { | 602 | { |
603 | save(); | 603 | save(); |
604 | } | 604 | } |
605 | 605 | ||
606 | bool PwM::save() | 606 | bool PwM::save() |
607 | { | 607 | { |
608 | if (!curDoc()->saveDocUi(curDoc())) | 608 | if (!curDoc()->saveDocUi(curDoc())) |
609 | return false; | 609 | return false; |
610 | showStatMsg(i18n("Successfully saved data.")); | 610 | showStatMsg(i18n("Successfully saved data.")); |
611 | updateCaption(); | 611 | updateCaption(); |
612 | return true; | 612 | return true; |
613 | } | 613 | } |
614 | 614 | ||
615 | void PwM::saveAs_slot() | 615 | void PwM::saveAs_slot() |
616 | { | 616 | { |
617 | saveAs(); | 617 | saveAs(); |
618 | } | 618 | } |
619 | 619 | ||
620 | bool PwM::saveAs() | 620 | bool PwM::saveAs() |
621 | { | 621 | { |
622 | if (!curDoc()->saveAsDocUi(curDoc())) | 622 | if (!curDoc()->saveAsDocUi(curDoc())) |
623 | return false; | 623 | return false; |
624 | showStatMsg(i18n("Successfully saved data.")); | 624 | showStatMsg(i18n("Successfully saved data.")); |
625 | updateCaption(); | 625 | updateCaption(); |
626 | return true; | 626 | return true; |
627 | } | 627 | } |
628 | 628 | ||
629 | //US ENH : changed code to run with older MOC | 629 | //US ENH : changed code to run with older MOC |
630 | void PwM::addPwd_slot() | 630 | void PwM::addPwd_slot() |
631 | { | 631 | { |
632 | addPwd_slot1(0, 0); | 632 | addPwd_slot1(0, 0); |
633 | } | 633 | } |
634 | 634 | ||
635 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) | 635 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) |
636 | { | 636 | { |
637 | PwMDoc *doc; | 637 | PwMDoc *doc; |
638 | if (_doc) { | 638 | if (_doc) { |
639 | doc = _doc; | 639 | doc = _doc; |
640 | } else { | 640 | } else { |
641 | doc = curDoc(); | 641 | doc = curDoc(); |
642 | } | 642 | } |
643 | PWM_ASSERT(doc); | 643 | PWM_ASSERT(doc); |
644 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 644 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
645 | #ifndef PWM_EMBEDDED | 645 | #ifndef PWM_EMBEDDED |
646 | AddEntryWndImpl w; | 646 | AddEntryWndImpl w; |
647 | #else | 647 | #else |
648 | AddEntryWndImpl w(doc, this, "addentrywndimpl"); | 648 | AddEntryWndImpl w(doc, this, "addentrywndimpl"); |
649 | #endif | 649 | #endif |
650 | w.setCaption( i18n ("Add new password") ); | 650 | w.setCaption( i18n ("Add new password") ); |
651 | vector<string> catList; | 651 | vector<string> catList; |
652 | doc->getCategoryList(&catList); | 652 | doc->getCategoryList(&catList); |
653 | unsigned i, size = catList.size(); | 653 | unsigned i, size = catList.size(); |
654 | for (i = 0; i < size; ++i) { | 654 | for (i = 0; i < size; ++i) { |
655 | w.addCategory(catList[i].c_str()); | 655 | w.addCategory(catList[i].c_str()); |
656 | } | 656 | } |
657 | w.setCurrCategory(view->getCurrentCategory()); | 657 | w.setCurrCategory(view->getCurrentCategory()); |
658 | if (pw) | 658 | if (pw) |
659 | w.pwLineEdit->setText(*pw); | 659 | w.pwLineEdit->setText(*pw); |
660 | 660 | ||
661 | tryAgain: | 661 | tryAgain: |
662 | w.descLineEdit->setFocus(); | 662 | w.descLineEdit->setFocus(); |
663 | if (w.exec() == 1) | 663 | if (w.exec() == 1) |
664 | { | 664 | { |
665 | PwMDataItem d; | 665 | PwMDataItem d; |
666 | 666 | ||
667 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 667 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
668 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | 668 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. |
669 | // another option would be to create a constructor for PwMDataItem | 669 | // another option would be to create a constructor for PwMDataItem |
670 | d.clear(true); | 670 | d.clear(true); |
671 | 671 | ||
672 | d.desc = w.getDescription().latin1(); | 672 | d.desc = w.getDescription().latin1(); |
673 | d.name = w.getUsername().latin1(); | 673 | d.name = w.getUsername().latin1(); |
674 | d.pw = w.getPassword().latin1(); | 674 | d.pw = w.getPassword().latin1(); |
675 | d.comment = w.getComment().latin1(); | 675 | d.comment = w.getComment().latin1(); |
676 | d.url = w.getUrl().latin1(); | 676 | d.url = w.getUrl().latin1(); |
677 | d.launcher = w.getLauncher().latin1(); | 677 | d.launcher = w.getLauncher().latin1(); |
678 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 678 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
679 | if (ret == e_entryExists) { | 679 | if (ret == e_entryExists) { |
680 | KMessageBox::error(this, | 680 | KMessageBox::error(this, |
681 | i18n | 681 | i18n |
682 | ("An entry with this \"Description\",\n" | 682 | ("An entry with this \"Description\",\n" |
683 | "does already exist.\n" | 683 | "does already exist.\n" |
684 | "Please select another description."), | 684 | "Please select another description."), |
685 | i18n("entry already exists.")); | 685 | i18n("entry already exists.")); |
686 | goto tryAgain; | 686 | goto tryAgain; |
687 | } else if (ret == e_maxAllowedEntr) { | 687 | } else if (ret == e_maxAllowedEntr) { |
688 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" | 688 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" |
689 | "has been reached.\nYou can't add more entries."), | 689 | "has been reached.\nYou can't add more entries."), |
690 | i18n("maximum number of entries")); | 690 | i18n("maximum number of entries")); |
691 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 691 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
692 | return; | 692 | return; |
693 | } | 693 | } |
694 | } | 694 | } |
695 | setVirgin(false); | 695 | setVirgin(false); |
696 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 696 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
697 | } | 697 | } |
698 | 698 | ||
699 | //US ENH : changed code to run with older MOC | 699 | //US ENH : changed code to run with older MOC |
700 | void PwM::editPwd_slot() | 700 | void PwM::editPwd_slot() |
701 | { | 701 | { |
702 | editPwd_slot3(0,0,0); | 702 | editPwd_slot3(0,0,0); |
703 | } | 703 | } |
704 | 704 | ||
705 | void PwM::editPwd_slot1(const QString *category) | 705 | void PwM::editPwd_slot1(const QString *category) |
706 | { | 706 | { |
707 | editPwd_slot3(category, 0, 0); | 707 | editPwd_slot3(category, 0, 0); |
708 | } | 708 | } |
709 | 709 | ||
710 | void PwM::editPwd_slot3(const QString *category, const int *index, | 710 | void PwM::editPwd_slot3(const QString *category, const int *index, |
711 | PwMDoc *_doc) | 711 | PwMDoc *_doc) |
712 | { | 712 | { |
713 | PwMDoc *doc; | 713 | PwMDoc *doc; |
714 | if (_doc) { | 714 | if (_doc) { |
715 | doc = _doc; | 715 | doc = _doc; |
716 | } else { | 716 | } else { |
717 | doc = curDoc(); | 717 | doc = curDoc(); |
718 | } | 718 | } |
719 | PWM_ASSERT(doc); | 719 | PWM_ASSERT(doc); |
720 | if (doc->isDocEmpty()) | 720 | if (doc->isDocEmpty()) |
721 | return; | 721 | return; |
722 | if (doc->isDeepLocked()) | 722 | if (doc->isDeepLocked()) |
723 | return; | 723 | return; |
724 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 724 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
725 | unsigned int curEntryIndex; | 725 | unsigned int curEntryIndex; |
726 | if (index) { | 726 | if (index) { |
727 | curEntryIndex = *index; | 727 | curEntryIndex = *index; |
728 | } else { | 728 | } else { |
729 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 729 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
730 | qDebug("couldn't get index. Maybe we have a binary entry here. "); | ||
730 | printDebug("couldn't get index. Maybe we have a binary entry here."); | 731 | printDebug("couldn't get index. Maybe we have a binary entry here."); |
731 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 732 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
732 | return; | 733 | return; |
733 | } | 734 | } |
734 | } | 735 | } |
735 | QString curCategory; | 736 | QString curCategory; |
736 | if (category) { | 737 | if (category) { |
737 | curCategory = *category; | 738 | curCategory = *category; |
738 | } else { | 739 | } else { |
739 | curCategory = view->getCurrentCategory(); | 740 | curCategory = view->getCurrentCategory(); |
740 | } | 741 | } |
741 | PwMDataItem currItem; | 742 | PwMDataItem currItem; |
742 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { | 743 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { |
743 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 744 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
744 | return; | 745 | return; |
745 | } | 746 | } |
746 | BUG_ON(currItem.binary); | 747 | BUG_ON(currItem.binary); |
747 | |||
748 | AddEntryWndImpl w(doc); | 748 | AddEntryWndImpl w(doc); |
749 | w.setCaption( i18n ("Edit password") ); | 749 | w.setCaption( i18n ("Edit password") ); |
750 | vector<string> catList; | 750 | vector<string> catList; |
751 | doc->getCategoryList(&catList); | 751 | doc->getCategoryList(&catList); |
752 | unsigned i, size = catList.size(); | 752 | unsigned i, size = catList.size(); |
753 | for (i = 0; i < size; ++i) { | 753 | for (i = 0; i < size; ++i) { |
754 | w.addCategory(catList[i].c_str()); | 754 | w.addCategory(catList[i].c_str()); |
755 | } | 755 | } |
756 | w.setCurrCategory(curCategory); | 756 | w.setCurrCategory(curCategory); |
757 | w.setDescription(currItem.desc.c_str()); | 757 | w.setDescription(currItem.desc.c_str()); |
758 | w.setUsername(currItem.name.c_str()); | 758 | w.setUsername(currItem.name.c_str()); |
759 | w.setPassword(currItem.pw.c_str()); | 759 | w.setPassword(currItem.pw.c_str()); |
760 | w.setUrl(currItem.url.c_str()); | 760 | w.setUrl(currItem.url.c_str()); |
761 | w.setLauncher(currItem.launcher.c_str()); | 761 | w.setLauncher(currItem.launcher.c_str()); |
762 | w.setComment(currItem.comment.c_str()); | 762 | w.setComment(currItem.comment.c_str()); |
763 | w.descLineEdit->setFocus(); | 763 | w.descLineEdit->setFocus(); |
764 | if (w.exec() == 1) { | 764 | if (w.exec() == 1) { |
765 | currItem.desc = w.getDescription().latin1(); | 765 | currItem.desc = w.getDescription().latin1(); |
766 | currItem.name = w.getUsername().latin1(); | 766 | currItem.name = w.getUsername().latin1(); |
767 | currItem.pw = w.getPassword().latin1(); | 767 | currItem.pw = w.getPassword().latin1(); |
768 | currItem.comment = w.getComment().latin1(); | 768 | currItem.comment = w.getComment().latin1(); |
769 | currItem.url = w.getUrl().latin1(); | 769 | currItem.url = w.getUrl().latin1(); |
770 | currItem.launcher = w.getLauncher().latin1(); | 770 | currItem.launcher = w.getLauncher().latin1(); |
771 | if (!doc->editEntry(curCategory, w.getCategory(), | 771 | if (!doc->editEntry(curCategory, w.getCategory(), |
772 | curEntryIndex, &currItem)) { | 772 | curEntryIndex, &currItem)) { |
773 | KMessageBox::error(this, | 773 | KMessageBox::error(this, |
774 | i18n("Couldn't edit the entry.\n" | 774 | i18n("Couldn't edit the entry.\n" |
775 | "Maybe you changed the category and\n" | 775 | "Maybe you changed the category and\n" |
776 | "this entry is already present\nin the new " | 776 | "this entry is already present\nin the new " |
777 | "category?"), | 777 | "category?"), |
778 | i18n("couldn't edit entry.")); | 778 | i18n("couldn't edit entry.")); |
779 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 779 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
780 | return; | 780 | return; |
781 | } | 781 | } |
782 | } | 782 | } |
783 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 783 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
784 | } | 784 | } |
785 | 785 | ||
786 | void PwM::deletePwd_slot() | 786 | void PwM::deletePwd_slot() |
787 | { | 787 | { |
788 | PWM_ASSERT(curDoc()); | 788 | PWM_ASSERT(curDoc()); |
789 | if (curDoc()->isDocEmpty()) | 789 | if (curDoc()->isDocEmpty()) |
790 | return; | 790 | return; |
791 | if (curDoc()->isDeepLocked()) | 791 | if (curDoc()->isDeepLocked()) |
792 | return; | 792 | return; |
793 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 793 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
794 | unsigned int curEntryIndex = 0; | 794 | unsigned int curEntryIndex = 0; |
795 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 795 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
796 | printDebug("couldn't get index"); | 796 | printDebug("couldn't get index"); |
797 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 797 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
798 | return; | 798 | return; |
799 | } | 799 | } |
800 | 800 | ||
801 | PwMDataItem currItem; | 801 | PwMDataItem currItem; |
802 | QString curCategory = view->getCurrentCategory(); | 802 | QString curCategory = view->getCurrentCategory(); |
803 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { | 803 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { |
804 | printDebug("couldn't get entry"); | 804 | printDebug("couldn't get entry"); |
805 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 805 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
806 | return; | 806 | return; |
807 | } | 807 | } |
808 | if (KMessageBox:: | 808 | if (KMessageBox:: |
809 | questionYesNo(this, | 809 | questionYesNo(this, |
810 | i18n | 810 | i18n |
811 | ("Do you really want to delete\nthe selected entry") + | 811 | ("Do you really want to delete\nthe selected entry") + |
812 | " \n\"" + QString(currItem.desc.c_str()) | 812 | " \n\"" + QString(currItem.desc.c_str()) |
813 | + "\" ?", i18n("delete?")) | 813 | + "\" ?", i18n("delete?")) |
814 | == KMessageBox::Yes) { | 814 | == KMessageBox::Yes) { |
815 | 815 | ||
816 | curDoc()->delEntry(curCategory, curEntryIndex); | 816 | curDoc()->delEntry(curCategory, curEntryIndex); |
817 | } | 817 | } |
818 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 818 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
819 | } | 819 | } |
820 | 820 | ||
821 | void PwM::changeMasterPwd_slot() | 821 | void PwM::changeMasterPwd_slot() |
822 | { | 822 | { |
823 | PWM_ASSERT(curDoc()); | 823 | PWM_ASSERT(curDoc()); |
824 | curDoc()->changeCurrentPw(); | 824 | curDoc()->changeCurrentPw(); |
825 | } | 825 | } |
826 | 826 | ||
827 | void PwM::lockWnd_slot() | 827 | void PwM::lockWnd_slot() |
828 | { | 828 | { |
829 | PWM_ASSERT(curDoc()); | 829 | PWM_ASSERT(curDoc()); |
830 | curDoc()->lockAll(true); | 830 | curDoc()->lockAll(true); |
831 | } | 831 | } |
832 | 832 | ||
833 | void PwM::deepLockWnd_slot() | 833 | void PwM::deepLockWnd_slot() |
834 | { | 834 | { |
835 | PWM_ASSERT(curDoc()); | 835 | PWM_ASSERT(curDoc()); |
836 | curDoc()->deepLock(); | 836 | curDoc()->deepLock(); |
837 | } | 837 | } |
838 | 838 | ||
839 | void PwM::unlockWnd_slot() | 839 | void PwM::unlockWnd_slot() |
840 | { | 840 | { |
841 | PWM_ASSERT(curDoc()); | 841 | PWM_ASSERT(curDoc()); |
842 | curDoc()->lockAll(false); | 842 | curDoc()->lockAll(false); |
843 | } | 843 | } |
844 | 844 | ||
845 | void PwM::config_slot() | 845 | void PwM::config_slot() |
846 | { | 846 | { |
847 | int oldStyle = conf()->confWndMainViewStyle(); | 847 | int oldStyle = conf()->confWndMainViewStyle(); |
848 | #ifdef PWM_EMBEDDED | 848 | #ifdef PWM_EMBEDDED |
849 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); | 849 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); |
850 | 850 | ||
851 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); | 851 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); |
852 | ConfigureDialog->addModule(pwmcfg ); | 852 | ConfigureDialog->addModule(pwmcfg ); |
853 | 853 | ||
854 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 854 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
855 | ConfigureDialog->addModule(kdelibcfg ); | 855 | ConfigureDialog->addModule(kdelibcfg ); |
856 | 856 | ||
857 | #ifndef DESKTOP_VERSION | 857 | #ifndef DESKTOP_VERSION |
858 | ConfigureDialog->showMaximized(); | 858 | ConfigureDialog->showMaximized(); |
859 | #endif | 859 | #endif |
860 | if ( ConfigureDialog->exec() ) | 860 | if ( ConfigureDialog->exec() ) |
861 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 861 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
862 | delete ConfigureDialog; | 862 | delete ConfigureDialog; |
863 | 863 | ||
864 | #else //PWM_EMBEDDED | 864 | #else //PWM_EMBEDDED |
865 | // display the configuration window (modal mode) | 865 | // display the configuration window (modal mode) |
866 | if (!conf()->showConfWnd(this)) | 866 | if (!conf()->showConfWnd(this)) |
867 | return; | 867 | return; |
868 | #endif | 868 | #endif |
869 | 869 | ||
870 | int newStyle = conf()->confWndMainViewStyle(); | 870 | int newStyle = conf()->confWndMainViewStyle(); |
871 | // reinitialize tray | 871 | // reinitialize tray |
872 | init->initTray(); | 872 | init->initTray(); |
873 | // reinitialize KWallet emulation | 873 | // reinitialize KWallet emulation |
874 | init->initKWalletEmu(); | 874 | init->initKWalletEmu(); |
875 | 875 | ||
876 | PwMDocList *_dl = PwMDoc::getOpenDocList(); | 876 | PwMDocList *_dl = PwMDoc::getOpenDocList(); |
877 | const vector<PwMDocList::listItem> *dl = _dl->getList(); | 877 | const vector<PwMDocList::listItem> *dl = _dl->getList(); |
878 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), | 878 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), |
879 | end = dl->end(); | 879 | end = dl->end(); |
880 | PwMDoc *doc; | 880 | PwMDoc *doc; |
881 | while (i != end) { | 881 | while (i != end) { |
882 | doc = (*i).doc; | 882 | doc = (*i).doc; |
883 | // unlock-without-mpw timeout | 883 | // unlock-without-mpw timeout |
884 | doc->timer()->start(DocTimer::id_mpwTimer); | 884 | doc->timer()->start(DocTimer::id_mpwTimer); |
885 | // auto-lock timeout | 885 | // auto-lock timeout |
886 | doc->timer()->start(DocTimer::id_autoLockTimer); | 886 | doc->timer()->start(DocTimer::id_autoLockTimer); |
887 | ++i; | 887 | ++i; |
888 | } | 888 | } |
889 | 889 | ||
890 | const QValueList<PwM *> *ml = init->mainWndList(); | 890 | const QValueList<PwM *> *ml = init->mainWndList(); |
891 | #ifndef PWM_EMBEDDED | 891 | #ifndef PWM_EMBEDDED |
892 | QValueList<PwM *>::const_iterator i2 = ml->begin(), | 892 | QValueList<PwM *>::const_iterator i2 = ml->begin(), |
893 | end2 = ml->end(); | 893 | end2 = ml->end(); |
894 | #else | 894 | #else |
895 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), | 895 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), |
896 | end2 = ml->end(); | 896 | end2 = ml->end(); |
897 | #endif | 897 | #endif |
898 | PwM *pwm; | 898 | PwM *pwm; |
899 | while (i2 != end2) { | 899 | while (i2 != end2) { |
900 | pwm = *i2; | 900 | pwm = *i2; |
901 | // reinitialize the window style. | 901 | // reinitialize the window style. |
902 | if (oldStyle != newStyle) | 902 | if (oldStyle != newStyle) |
903 | pwm->curView()->initStyle(newStyle); | 903 | pwm->curView()->initStyle(newStyle); |
904 | // set the new font | 904 | // set the new font |
905 | pwm->curView()->setFont(conf()->confGlobEntryFont()); | 905 | pwm->curView()->setFont(conf()->confGlobEntryFont()); |
906 | ++i2; | 906 | ++i2; |
907 | } | 907 | } |
908 | } | 908 | } |
909 | 909 | ||
910 | void PwM::activateMpButton(bool activate) | 910 | void PwM::activateMpButton(bool activate) |
911 | { | 911 | { |
912 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); | 912 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); |
913 | } | 913 | } |
914 | 914 | ||
915 | void PwM::closeEvent(QCloseEvent *e) | 915 | void PwM::closeEvent(QCloseEvent *e) |
916 | { | 916 | { |
917 | //qDebug("PwM::closeEvent "); | 917 | //qDebug("PwM::closeEvent "); |
918 | emit closed( this ); | 918 | emit closed( this ); |
919 | return; | 919 | return; |
920 | e->accept(); | 920 | e->accept(); |
921 | } | 921 | } |
922 | 922 | ||
923 | void PwM::docClosed(PwMDoc *doc) | 923 | void PwM::docClosed(PwMDoc *doc) |
924 | { | 924 | { |
925 | //qDebug("PwM::docClosed "); | 925 | //qDebug("PwM::docClosed "); |
926 | PARAM_UNUSED(doc); | 926 | PARAM_UNUSED(doc); |
927 | PWM_ASSERT(doc == curDoc()); | 927 | PWM_ASSERT(doc == curDoc()); |
928 | close(); | 928 | close(); |
929 | } | 929 | } |
930 | 930 | ||
931 | void PwM::find_slot() | 931 | void PwM::find_slot() |
932 | { | 932 | { |
933 | PWM_ASSERT(curDoc()); | 933 | PWM_ASSERT(curDoc()); |
934 | if (curDoc()->isDocEmpty()) | 934 | if (curDoc()->isDocEmpty()) |
935 | return; | 935 | return; |
936 | if (curDoc()->isDeepLocked()) | 936 | if (curDoc()->isDeepLocked()) |
937 | return; | 937 | return; |
938 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 938 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
939 | FindWndImpl findWnd(view); | 939 | FindWndImpl findWnd(view); |
940 | findWnd.exec(); | 940 | findWnd.exec(); |
941 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 941 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
942 | } | 942 | } |
943 | 943 | ||
944 | void PwM::exportToText() | 944 | void PwM::exportToText() |
945 | { | 945 | { |
946 | PWM_ASSERT(curDoc()); | 946 | PWM_ASSERT(curDoc()); |
947 | if (curDoc()->isDocEmpty()) { | 947 | if (curDoc()->isDocEmpty()) { |
948 | KMessageBox::information(this, | 948 | KMessageBox::information(this, |
949 | i18n | 949 | i18n |
950 | ("Sorry, there's nothing to export.\n" | 950 | ("Sorry, there's nothing to export.\n" |
951 | "Please first add some passwords."), | 951 | "Please first add some passwords."), |
952 | i18n("nothing to do")); | 952 | i18n("nothing to do")); |
953 | return; | 953 | return; |
954 | } | 954 | } |
955 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 955 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
956 | QString fn(KFileDialog::getSaveFileName(QString::null, | 956 | QString fn(KFileDialog::getSaveFileName(QString::null, |
957 | i18n("*|plain-text file"), | 957 | i18n("*|plain-text file"), |
958 | this)); | 958 | this)); |
959 | if (fn == "") { | 959 | if (fn == "") { |
960 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 960 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
961 | return; | 961 | return; |
962 | } | 962 | } |
963 | 963 | ||
964 | PwMerror ret = curDoc()->exportToText(&fn); | 964 | PwMerror ret = curDoc()->exportToText(&fn); |
965 | if (ret != e_success) { | 965 | if (ret != e_success) { |
966 | KMessageBox::error(this, | 966 | KMessageBox::error(this, |
967 | i18n("Error: Couldn't write to file.\n" | 967 | i18n("Error: Couldn't write to file.\n" |
968 | "Please check if you have permission to write\n" | 968 | "Please check if you have permission to write\n" |
969 | "to the file in that directory."), | 969 | "to the file in that directory."), |
970 | i18n("error while writing")); | 970 | i18n("error while writing")); |
971 | } else | 971 | } else |
972 | showStatMsg(i18n("Successfully exported data.")); | 972 | showStatMsg(i18n("Successfully exported data.")); |
973 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 973 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
974 | } | 974 | } |
975 | 975 | ||
976 | bool PwM::importFromText() | 976 | bool PwM::importFromText() |
977 | { | 977 | { |
978 | if (!isVirgin()) { | 978 | if (!isVirgin()) { |
979 | if (KMessageBox::questionYesNo(this, | 979 | if (KMessageBox::questionYesNo(this, |
980 | i18n("Do you want to import the data\n" | 980 | i18n("Do you want to import the data\n" |
981 | "into the current document? (If you\n" | 981 | "into the current document? (If you\n" |
982 | "select \"no\", a new document will be\n" | 982 | "select \"no\", a new document will be\n" |
983 | "opened.)"), | 983 | "opened.)"), |
984 | i18n("import into this document?")) | 984 | i18n("import into this document?")) |
985 | == KMessageBox::No) { | 985 | == KMessageBox::No) { |
986 | // import the data to a new window. | 986 | // import the data to a new window. |
987 | PwM *newInstance = init->createMainWnd(); | 987 | PwM *newInstance = init->createMainWnd(); |
988 | bool ok = newInstance->importFromText(); | 988 | bool ok = newInstance->importFromText(); |
989 | if (!ok) { | 989 | if (!ok) { |
990 | newInstance->setForceQuit(true); | 990 | newInstance->setForceQuit(true); |
991 | delete_and_null(newInstance); | 991 | delete_and_null(newInstance); |
992 | } | 992 | } |
993 | return ok; | 993 | return ok; |
994 | } | 994 | } |
995 | } | 995 | } |
996 | 996 | ||
997 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 997 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
998 | PwMerror ret; | 998 | PwMerror ret; |
999 | QString path(KFileDialog::getOpenFileName(QString::null, | 999 | QString path(KFileDialog::getOpenFileName(QString::null, |
1000 | i18n("*|PWM-exported text file"), | 1000 | i18n("*|PWM-exported text file"), |
1001 | this)); | 1001 | this)); |
1002 | if (path == "") | 1002 | if (path == "") |
1003 | goto cancelImport; | 1003 | goto cancelImport; |
1004 | 1004 | ||
1005 | ret = curDoc()->importFromText(&path, 0); | 1005 | ret = curDoc()->importFromText(&path, 0); |
1006 | if (ret == e_fileFormat) { | 1006 | if (ret == e_fileFormat) { |
1007 | KMessageBox::error(this, | 1007 | KMessageBox::error(this, |
1008 | i18n("Could not read file-format.\n" | 1008 | i18n("Could not read file-format.\n" |
1009 | "This seems to be _not_ a valid file\n" | 1009 | "This seems to be _not_ a valid file\n" |
1010 | "exported by PwM."), | 1010 | "exported by PwM."), |
1011 | i18n("invalid file-format")); | 1011 | i18n("invalid file-format")); |
1012 | goto cancelImport; | 1012 | goto cancelImport; |
1013 | } else if (ret == e_invalidArg) { | 1013 | } else if (ret == e_invalidArg) { |
1014 | BUG(); | 1014 | BUG(); |
1015 | goto cancelImport; | 1015 | goto cancelImport; |
1016 | } else if (ret != e_success) { | 1016 | } else if (ret != e_success) { |
1017 | KMessageBox::error(this, | 1017 | KMessageBox::error(this, |
1018 | i18n("Could not import file!\n" | 1018 | i18n("Could not import file!\n" |
1019 | "Do you have permission to read this file?\n" | 1019 | "Do you have permission to read this file?\n" |
1020 | "Do you have enough free memory?"), | 1020 | "Do you have enough free memory?"), |
1021 | i18n("import failed")); | 1021 | i18n("import failed")); |
1022 | goto cancelImport; | 1022 | goto cancelImport; |
1023 | } | 1023 | } |
1024 | setVirgin(false); | 1024 | setVirgin(false); |
1025 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1025 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1026 | return true; | 1026 | return true; |
1027 | 1027 | ||
1028 | cancelImport: | 1028 | cancelImport: |
1029 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1029 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1030 | return false; | 1030 | return false; |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | void PwM::exportToGpasman() | 1033 | void PwM::exportToGpasman() |
1034 | { | 1034 | { |
1035 | PWM_ASSERT(curDoc()); | 1035 | PWM_ASSERT(curDoc()); |
1036 | if (curDoc()->isDocEmpty()) { | 1036 | if (curDoc()->isDocEmpty()) { |
1037 | KMessageBox::information(this, | 1037 | KMessageBox::information(this, |
1038 | i18n | 1038 | i18n |
1039 | ("Sorry, there's nothing to export.\n" | 1039 | ("Sorry, there's nothing to export.\n" |
1040 | "Please first add some passwords."), | 1040 | "Please first add some passwords."), |
1041 | i18n("nothing to do")); | 1041 | i18n("nothing to do")); |
1042 | return; | 1042 | return; |
1043 | } | 1043 | } |
1044 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1044 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1045 | QString fn(KFileDialog::getSaveFileName(QString::null, | 1045 | QString fn(KFileDialog::getSaveFileName(QString::null, |
1046 | i18n("*|Gpasman or Kpasman file"), | 1046 | i18n("*|Gpasman or Kpasman file"), |
1047 | this)); | 1047 | this)); |
1048 | if (fn == "") { | 1048 | if (fn == "") { |
1049 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1049 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1050 | return; | 1050 | return; |
1051 | } | 1051 | } |
1052 | 1052 | ||
1053 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 1053 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
1054 | if (ret != e_success) { | 1054 | if (ret != e_success) { |
1055 | if (ret == e_noPw) { | 1055 | if (ret == e_noPw) { |
1056 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1056 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1057 | return; | 1057 | return; |
1058 | } | 1058 | } |
1059 | KMessageBox::error(this, | 1059 | KMessageBox::error(this, |
1060 | i18n("Error: Couldn't write to file.\n" | 1060 | i18n("Error: Couldn't write to file.\n" |
1061 | "Please check if you have permission to write " | 1061 | "Please check if you have permission to write " |
1062 | "to the file in that directory."), | 1062 | "to the file in that directory."), |
1063 | i18n("error while writing")); | 1063 | i18n("error while writing")); |
1064 | } else | 1064 | } else |
1065 | showStatMsg(i18n("Successfully exported data.")); | 1065 | showStatMsg(i18n("Successfully exported data.")); |
1066 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1066 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | 1069 | ||
1070 | 1070 | ||
1071 | void PwM::exportToCsv() | 1071 | void PwM::exportToCsv() |
1072 | { | 1072 | { |
1073 | PWM_ASSERT(curDoc()); | 1073 | PWM_ASSERT(curDoc()); |
1074 | if (curDoc()->isDocEmpty()) { | 1074 | if (curDoc()->isDocEmpty()) { |
1075 | KMessageBox::information(this, | 1075 | KMessageBox::information(this, |
1076 | i18n | 1076 | i18n |
1077 | ("Sorry, there is nothing to export;\n" | 1077 | ("Sorry, there is nothing to export;\n" |
1078 | "please add some passwords first."), | 1078 | "please add some passwords first."), |
1079 | i18n("Nothing to Do")); | 1079 | i18n("Nothing to Do")); |
1080 | return; | 1080 | return; |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1083 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1084 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); | 1084 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); |
1085 | if (fn.isEmpty()) { | 1085 | if (fn.isEmpty()) { |
1086 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1086 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1087 | return; | 1087 | return; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | Csv csv(this); | 1090 | Csv csv(this); |
1091 | if (!csv.exportData(fn, curDoc())) { | 1091 | if (!csv.exportData(fn, curDoc())) { |
1092 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1092 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1093 | showStatMsg(i18n("CSV file export failed.")); | 1093 | showStatMsg(i18n("CSV file export failed.")); |
1094 | return; | 1094 | return; |
1095 | } | 1095 | } |
1096 | showStatMsg(i18n("Successfully exported data.")); | 1096 | showStatMsg(i18n("Successfully exported data.")); |
1097 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1097 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | bool PwM::importCsv() | 1100 | bool PwM::importCsv() |
1101 | { | 1101 | { |
1102 | Csv csv(this); | 1102 | Csv csv(this); |
1103 | if (!isVirgin()) { | 1103 | if (!isVirgin()) { |
1104 | if (KMessageBox::questionYesNo(this, | 1104 | if (KMessageBox::questionYesNo(this, |
1105 | i18n("Do you want to import the data\n" | 1105 | i18n("Do you want to import the data\n" |
1106 | "into the current document? (If you\n" | 1106 | "into the current document? (If you\n" |
1107 | "select \"no\", a new document will be\n" | 1107 | "select \"no\", a new document will be\n" |
1108 | "opened.)"), | 1108 | "opened.)"), |
1109 | i18n("Import into This Document?")) | 1109 | i18n("Import into This Document?")) |
1110 | == KMessageBox::No) { | 1110 | == KMessageBox::No) { |
1111 | // import the data to a new window. | 1111 | // import the data to a new window. |
1112 | PwM *newInstance = init->createMainWnd(); | 1112 | PwM *newInstance = init->createMainWnd(); |
1113 | bool ok = newInstance->importCsv(); | 1113 | bool ok = newInstance->importCsv(); |
1114 | if (!ok) { | 1114 | if (!ok) { |
1115 | newInstance->setForceQuit(true); | 1115 | newInstance->setForceQuit(true); |
1116 | delete_and_null(newInstance); | 1116 | delete_and_null(newInstance); |
1117 | } | 1117 | } |
1118 | return ok; | 1118 | return ok; |
1119 | } | 1119 | } |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); | 1122 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); |
1123 | if (filename.isEmpty()) | 1123 | if (filename.isEmpty()) |
1124 | return false; | 1124 | return false; |
1125 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1125 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1126 | if (!csv.importData(filename, curDoc())) { | 1126 | if (!csv.importData(filename, curDoc())) { |
1127 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1127 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1128 | showStatMsg(i18n("CSV file import failed.")); | 1128 | showStatMsg(i18n("CSV file import failed.")); |
1129 | return false; | 1129 | return false; |
1130 | } | 1130 | } |
1131 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1131 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1132 | KMessageBox::information(this, | 1132 | KMessageBox::information(this, |
1133 | i18n("Successfully imported the CSV data\n" | 1133 | i18n("Successfully imported the CSV data\n" |
1134 | "into the current document."), i18n("Successfully Imported")); | 1134 | "into the current document."), i18n("Successfully Imported")); |
1135 | showStatMsg(i18n("Successfully imported")); | 1135 | showStatMsg(i18n("Successfully imported")); |
1136 | setVirgin(false); | 1136 | setVirgin(false); |
1137 | return true; | 1137 | return true; |
1138 | } | 1138 | } |
1139 | 1139 | ||
1140 | 1140 | ||
1141 | void PwM::exportToKWallet() | 1141 | void PwM::exportToKWallet() |
1142 | { | 1142 | { |
1143 | #ifdef CONFIG_KWALLETIF | 1143 | #ifdef CONFIG_KWALLETIF |
1144 | if (!checkAndAskForKWalletEmu()) | 1144 | if (!checkAndAskForKWalletEmu()) |
1145 | return; | 1145 | return; |
1146 | PWM_ASSERT(curDoc()); | 1146 | PWM_ASSERT(curDoc()); |
1147 | if (curDoc()->isDocEmpty()) { | 1147 | if (curDoc()->isDocEmpty()) { |
1148 | KMessageBox::information(this, | 1148 | KMessageBox::information(this, |
1149 | i18n | 1149 | i18n |
1150 | ("Sorry, there's nothing to export.\n" | 1150 | ("Sorry, there's nothing to export.\n" |
1151 | "Please first add some passwords."), | 1151 | "Please first add some passwords."), |
1152 | i18n("nothing to do")); | 1152 | i18n("nothing to do")); |
1153 | init->initKWalletEmu(); | 1153 | init->initKWalletEmu(); |
1154 | return; | 1154 | return; |
1155 | } | 1155 | } |
1156 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1156 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1157 | KWalletIf walletIf(this); | 1157 | KWalletIf walletIf(this); |
1158 | if (walletIf.kwalletExport(curDoc())) { | 1158 | if (walletIf.kwalletExport(curDoc())) { |
1159 | KMessageBox::information(this, | 1159 | KMessageBox::information(this, |
1160 | i18n("Successfully exported the data of the current " | 1160 | i18n("Successfully exported the data of the current " |
1161 | "document to KWallet."), | 1161 | "document to KWallet."), |
1162 | i18n("Successfully exported data.")); | 1162 | i18n("Successfully exported data.")); |
1163 | showStatMsg(i18n("Successfully exported data.")); | 1163 | showStatMsg(i18n("Successfully exported data.")); |
1164 | } | 1164 | } |
1165 | init->initKWalletEmu(); | 1165 | init->initKWalletEmu(); |
1166 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1166 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1167 | #endif // CONFIG_KWALLETIF | 1167 | #endif // CONFIG_KWALLETIF |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | bool PwM::importFromGpasman() | 1170 | bool PwM::importFromGpasman() |
1171 | { | 1171 | { |
1172 | if (!isVirgin()) { | 1172 | if (!isVirgin()) { |
1173 | if (KMessageBox::questionYesNo(this, | 1173 | if (KMessageBox::questionYesNo(this, |
1174 | i18n("Do you want to import the data\n" | 1174 | i18n("Do you want to import the data\n" |
1175 | "into the current document? (If you\n" | 1175 | "into the current document? (If you\n" |
1176 | "select \"no\", a new document will be\n" | 1176 | "select \"no\", a new document will be\n" |
1177 | "opened.)"), | 1177 | "opened.)"), |
1178 | i18n("import into this document?")) | 1178 | i18n("import into this document?")) |
1179 | == KMessageBox::No) { | 1179 | == KMessageBox::No) { |
1180 | // import the data to a new window. | 1180 | // import the data to a new window. |
1181 | PwM *newInstance = init->createMainWnd(); | 1181 | PwM *newInstance = init->createMainWnd(); |
1182 | bool ok = newInstance->importFromGpasman(); | 1182 | bool ok = newInstance->importFromGpasman(); |
1183 | if (!ok) { | 1183 | if (!ok) { |
1184 | newInstance->setForceQuit(true); | 1184 | newInstance->setForceQuit(true); |
1185 | delete_and_null(newInstance); | 1185 | delete_and_null(newInstance); |
1186 | } | 1186 | } |
1187 | return ok; | 1187 | return ok; |
1188 | } | 1188 | } |
1189 | } | 1189 | } |
1190 | 1190 | ||
1191 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1191 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1192 | PwMerror ret; | 1192 | PwMerror ret; |
1193 | QString path(KFileDialog::getOpenFileName(QString::null, | 1193 | QString path(KFileDialog::getOpenFileName(QString::null, |
1194 | i18n("*|Gpasman or Kpasman file"), this)); | 1194 | i18n("*|Gpasman or Kpasman file"), this)); |
1195 | if (path == "") | 1195 | if (path == "") |
1196 | goto cancelImport; | 1196 | goto cancelImport; |
1197 | ret = curDoc()->importFromGpasman(&path); | 1197 | ret = curDoc()->importFromGpasman(&path); |
1198 | if (ret == e_wrongPw) { | 1198 | if (ret == e_wrongPw) { |
1199 | if (KMessageBox::questionYesNo(this, | 1199 | if (KMessageBox::questionYesNo(this, |
1200 | i18n | 1200 | i18n |
1201 | ("This is probably the wrong master-password\n" | 1201 | ("This is probably the wrong master-password\n" |
1202 | "you have typed in.\n" | 1202 | "you have typed in.\n" |
1203 | "There is no real way to determine the\n" | 1203 | "There is no real way to determine the\n" |
1204 | "correctness of the password in the Gpasman\n" | 1204 | "correctness of the password in the Gpasman\n" |
1205 | "file-format. But I think this\n" | 1205 | "file-format. But I think this\n" |
1206 | "password ist wrong.\n" | 1206 | "password ist wrong.\n" |
1207 | "Do you want to continue nevertheless?"), | 1207 | "Do you want to continue nevertheless?"), |
1208 | i18n("password error")) | 1208 | i18n("password error")) |
1209 | == KMessageBox::No) { | 1209 | == KMessageBox::No) { |
1210 | goto cancelImport; | 1210 | goto cancelImport; |
1211 | } | 1211 | } |
1212 | } else if (ret != e_success) { | 1212 | } else if (ret != e_success) { |
1213 | KMessageBox::error(this, | 1213 | KMessageBox::error(this, |
1214 | i18n("Could not import file!\n" | 1214 | i18n("Could not import file!\n" |
1215 | "Do you have permission to read this file?"), | 1215 | "Do you have permission to read this file?"), |
1216 | i18n("import failed")); | 1216 | i18n("import failed")); |
1217 | goto cancelImport; | 1217 | goto cancelImport; |
1218 | } | 1218 | } |
1219 | setVirgin(false); | 1219 | setVirgin(false); |
1220 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1220 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1221 | return true; | 1221 | return true; |
1222 | 1222 | ||
1223 | cancelImport: | 1223 | cancelImport: |
1224 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1224 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1225 | return false; | 1225 | return false; |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | #ifdef CONFIG_KWALLETIF | 1228 | #ifdef CONFIG_KWALLETIF |
1229 | bool PwM::checkAndAskForKWalletEmu() | 1229 | bool PwM::checkAndAskForKWalletEmu() |
1230 | { | 1230 | { |
1231 | if (init->kwalletEmu()) { | 1231 | if (init->kwalletEmu()) { |
1232 | /* KWallet emulation is enabled. We can't import/export | 1232 | /* KWallet emulation is enabled. We can't import/export |
1233 | * data from/to it, while emulation is active. | 1233 | * data from/to it, while emulation is active. |
1234 | */ | 1234 | */ |
1235 | if (KMessageBox::questionYesNo(this, | 1235 | if (KMessageBox::questionYesNo(this, |
1236 | i18n("KWallet emulation is enabled.\n" | 1236 | i18n("KWallet emulation is enabled.\n" |
1237 | "You can't import or export data from/to " | 1237 | "You can't import or export data from/to " |
1238 | "the original KWallet, while the emulation " | 1238 | "the original KWallet, while the emulation " |
1239 | "is active.\n" | 1239 | "is active.\n" |
1240 | "Do you want to tempoarly disable the KWallet emulation?"), | 1240 | "Do you want to tempoarly disable the KWallet emulation?"), |
1241 | i18n("Tempoarly disable KWallet emulation?")) | 1241 | i18n("Tempoarly disable KWallet emulation?")) |
1242 | == KMessageBox::Yes) { | 1242 | == KMessageBox::Yes) { |
1243 | init->initKWalletEmu(true); | 1243 | init->initKWalletEmu(true); |
1244 | PWM_ASSERT(!init->kwalletEmu()); | 1244 | PWM_ASSERT(!init->kwalletEmu()); |
1245 | return true; | 1245 | return true; |
1246 | } | 1246 | } |
1247 | return false; | 1247 | return false; |
1248 | } | 1248 | } |
1249 | return true; | 1249 | return true; |
1250 | } | 1250 | } |
1251 | #endif // CONFIG_KWALLETIF | 1251 | #endif // CONFIG_KWALLETIF |
1252 | 1252 | ||
1253 | bool PwM::importKWallet() | 1253 | bool PwM::importKWallet() |
1254 | { | 1254 | { |
1255 | #ifdef CONFIG_KWALLETIF | 1255 | #ifdef CONFIG_KWALLETIF |
1256 | if (!checkAndAskForKWalletEmu()) | 1256 | if (!checkAndAskForKWalletEmu()) |
1257 | return false; | 1257 | return false; |
1258 | KWalletIf walletIf(this); | 1258 | KWalletIf walletIf(this); |
1259 | if (!isVirgin()) { | 1259 | if (!isVirgin()) { |
1260 | if (KMessageBox::questionYesNo(this, | 1260 | if (KMessageBox::questionYesNo(this, |
1261 | i18n("Do you want to import the data " | 1261 | i18n("Do you want to import the data " |
1262 | "into the current document? (If you " | 1262 | "into the current document? (If you " |
1263 | "select \"no\", a new document will be " | 1263 | "select \"no\", a new document will be " |
1264 | "opened.)"), | 1264 | "opened.)"), |
1265 | i18n("import into this document?")) | 1265 | i18n("import into this document?")) |
1266 | == KMessageBox::No) { | 1266 | == KMessageBox::No) { |
1267 | // import the data to a new window. | 1267 | // import the data to a new window. |
1268 | PwM *newInstance = init->createMainWnd(); | 1268 | PwM *newInstance = init->createMainWnd(); |
1269 | bool ok = newInstance->importKWallet(); | 1269 | bool ok = newInstance->importKWallet(); |
1270 | if (!ok) { | 1270 | if (!ok) { |
1271 | newInstance->setForceQuit(true); | 1271 | newInstance->setForceQuit(true); |
1272 | delete_and_null(newInstance); | 1272 | delete_and_null(newInstance); |
1273 | goto exit_fail; | 1273 | goto exit_fail; |
1274 | } else { | 1274 | } else { |
1275 | goto exit_ok; | 1275 | goto exit_ok; |
1276 | } | 1276 | } |
1277 | } | 1277 | } |
1278 | } | 1278 | } |
1279 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1279 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1280 | if (!walletIf.kwalletImport(curDoc())) { | 1280 | if (!walletIf.kwalletImport(curDoc())) { |
1281 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1281 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1282 | showStatMsg(i18n("KWallet import failed")); | 1282 | showStatMsg(i18n("KWallet import failed")); |
1283 | goto exit_fail; | 1283 | goto exit_fail; |
1284 | } | 1284 | } |
1285 | KMessageBox::information(this, | 1285 | KMessageBox::information(this, |
1286 | i18n("Successfully imported the KWallet data " | 1286 | i18n("Successfully imported the KWallet data " |
1287 | "into the current document."), | 1287 | "into the current document."), |
1288 | i18n("successfully imported")); | 1288 | i18n("successfully imported")); |
1289 | showStatMsg(i18n("successfully imported")); | 1289 | showStatMsg(i18n("successfully imported")); |
1290 | setVirgin(false); | 1290 | setVirgin(false); |
1291 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1291 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1292 | 1292 | ||
1293 | exit_ok: | 1293 | exit_ok: |
1294 | init->initKWalletEmu(); | 1294 | init->initKWalletEmu(); |
1295 | return true; | 1295 | return true; |
1296 | 1296 | ||
1297 | exit_fail: | 1297 | exit_fail: |
1298 | init->initKWalletEmu(); | 1298 | init->initKWalletEmu(); |
1299 | #endif // CONFIG_KWALLETIF | 1299 | #endif // CONFIG_KWALLETIF |
1300 | return false; | 1300 | return false; |
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | void PwM::print_slot() | 1303 | void PwM::print_slot() |
1304 | { | 1304 | { |
1305 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1305 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1306 | #ifndef PWM_EMBEDDED | 1306 | #ifndef PWM_EMBEDDED |
1307 | PwMPrint p(curDoc(), this); | 1307 | PwMPrint p(curDoc(), this); |
1308 | p.printNow(); | 1308 | p.printNow(); |
1309 | #else | 1309 | #else |
1310 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1310 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1311 | #endif | 1311 | #endif |
1312 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1312 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1313 | } | 1313 | } |
1314 | 1314 | ||
1315 | void PwM::genNewCard_slot() | 1315 | void PwM::genNewCard_slot() |
1316 | { | 1316 | { |
1317 | #ifdef CONFIG_KEYCARD | 1317 | #ifdef CONFIG_KEYCARD |
1318 | init->keycard()->genNewCard(); | 1318 | init->keycard()->genNewCard(); |
1319 | #endif | 1319 | #endif |
1320 | } | 1320 | } |
1321 | 1321 | ||
1322 | void PwM::eraseCard_slot() | 1322 | void PwM::eraseCard_slot() |
1323 | { | 1323 | { |
1324 | #ifdef CONFIG_KEYCARD | 1324 | #ifdef CONFIG_KEYCARD |
1325 | init->keycard()->eraseCard(); | 1325 | init->keycard()->eraseCard(); |
1326 | #endif | 1326 | #endif |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | void PwM::readCardId_slot() | 1329 | void PwM::readCardId_slot() |
1330 | { | 1330 | { |
1331 | #ifdef CONFIG_KEYCARD | 1331 | #ifdef CONFIG_KEYCARD |
1332 | init->keycard()->displayKey(); | 1332 | init->keycard()->displayKey(); |
1333 | #endif | 1333 | #endif |
1334 | } | 1334 | } |
1335 | 1335 | ||
1336 | void PwM::makeCardBackup_slot() | 1336 | void PwM::makeCardBackup_slot() |
1337 | { | 1337 | { |
1338 | #ifdef CONFIG_KEYCARD | 1338 | #ifdef CONFIG_KEYCARD |
1339 | init->keycard()->makeBackupImage(); | 1339 | init->keycard()->makeBackupImage(); |
1340 | #endif | 1340 | #endif |
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | void PwM::replayCardBackup_slot() | 1343 | void PwM::replayCardBackup_slot() |
1344 | { | 1344 | { |
1345 | #ifdef CONFIG_KEYCARD | 1345 | #ifdef CONFIG_KEYCARD |
1346 | init->keycard()->replayBackupImage(); | 1346 | init->keycard()->replayBackupImage(); |
1347 | #endif | 1347 | #endif |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void PwM::execLauncher_slot() | 1350 | void PwM::execLauncher_slot() |
1351 | { | 1351 | { |
1352 | PWM_ASSERT(curDoc()); | 1352 | PWM_ASSERT(curDoc()); |
1353 | if (curDoc()->isDeepLocked()) | 1353 | if (curDoc()->isDeepLocked()) |
1354 | return; | 1354 | return; |
1355 | unsigned int curEntryIndex; | 1355 | unsigned int curEntryIndex; |
1356 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1356 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1357 | return; | 1357 | return; |
1358 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1358 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1359 | curEntryIndex); | 1359 | curEntryIndex); |
1360 | if (ret) | 1360 | if (ret) |
1361 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1361 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1362 | else | 1362 | else |
1363 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1363 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | void PwM::goToURL_slot() | 1366 | void PwM::goToURL_slot() |
1367 | { | 1367 | { |
1368 | PWM_ASSERT(curDoc()); | 1368 | PWM_ASSERT(curDoc()); |
1369 | if (curDoc()->isDeepLocked()) | 1369 | if (curDoc()->isDeepLocked()) |
1370 | return; | 1370 | return; |
1371 | unsigned int curEntryIndex; | 1371 | unsigned int curEntryIndex; |
1372 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1372 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1373 | return; | 1373 | return; |
1374 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1374 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1375 | curEntryIndex); | 1375 | curEntryIndex); |
1376 | if (ret) | 1376 | if (ret) |
1377 | showStatMsg(i18n("started browser with current URL.")); | 1377 | showStatMsg(i18n("started browser with current URL.")); |
1378 | else | 1378 | else |
1379 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1379 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1380 | } | 1380 | } |
1381 | 1381 | ||
1382 | void PwM::copyToClipboard(const QString &s) | 1382 | void PwM::copyToClipboard(const QString &s) |
1383 | { | 1383 | { |
1384 | QClipboard *cb = QApplication::clipboard(); | 1384 | QClipboard *cb = QApplication::clipboard(); |
1385 | #ifndef PWM_EMBEDDED | 1385 | #ifndef PWM_EMBEDDED |
1386 | if (cb->supportsSelection()) | 1386 | if (cb->supportsSelection()) |
1387 | cb->setText(s, QClipboard::Selection); | 1387 | cb->setText(s, QClipboard::Selection); |
1388 | cb->setText(s, QClipboard::Clipboard); | 1388 | cb->setText(s, QClipboard::Clipboard); |
1389 | #else | 1389 | #else |
1390 | cb->setText(s); | 1390 | cb->setText(s); |
1391 | 1391 | ||
1392 | #endif | 1392 | #endif |
1393 | 1393 | ||
1394 | } | 1394 | } |
1395 | 1395 | ||
1396 | 1396 | ||
1397 | void PwM::showStatMsg(const QString &msg) | 1397 | void PwM::showStatMsg(const QString &msg) |
1398 | { | 1398 | { |
1399 | #ifdef DESKTOP_VERSION | 1399 | #ifdef DESKTOP_VERSION |
1400 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1400 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1401 | #else | 1401 | #else |
1402 | //qDebug("Statusbar : %s",msg.latin1()); | 1402 | //qDebug("Statusbar : %s",msg.latin1()); |
1403 | Global::statusMessage(msg); | 1403 | Global::statusMessage(msg); |
1404 | #endif | 1404 | #endif |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | void PwM::focusInEvent(QFocusEvent *e) | 1407 | void PwM::focusInEvent(QFocusEvent *e) |
1408 | { | 1408 | { |
1409 | if (e->gotFocus()) { | 1409 | if (e->gotFocus()) { |
1410 | emit gotFocus(this); | 1410 | emit gotFocus(this); |
1411 | } else if (e->lostFocus()) { | 1411 | } else if (e->lostFocus()) { |
1412 | emit lostFocus(this); | 1412 | emit lostFocus(this); |
1413 | } | 1413 | } |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | 1416 | ||
1417 | #ifdef PWM_EMBEDDED | 1417 | #ifdef PWM_EMBEDDED |
1418 | 1418 | ||
1419 | void PwM::category_slot() | 1419 | void PwM::category_slot() |
1420 | { | 1420 | { |
1421 | PwMDoc *doc = curDoc(); | 1421 | PwMDoc *doc = curDoc(); |
1422 | PWM_ASSERT(doc); | 1422 | PWM_ASSERT(doc); |
1423 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 1423 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
1424 | 1424 | ||
1425 | editCategoryWnd w(doc, this, "editcategory"); | 1425 | editCategoryWnd w(doc, this, "editcategory"); |
1426 | /* | 1426 | /* |
1427 | vector<string> catList; | 1427 | vector<string> catList; |
1428 | doc->getCategoryList(&catList); | 1428 | doc->getCategoryList(&catList); |
1429 | unsigned i, size = catList.size(); | 1429 | unsigned i, size = catList.size(); |
1430 | for (i = 0; i < size; ++i) { | 1430 | for (i = 0; i < size; ++i) { |
1431 | w.addCategory(catList[i].c_str()); | 1431 | w.addCategory(catList[i].c_str()); |
1432 | } | 1432 | } |
1433 | w.setCurrCategory(view->getCurrentCategory()); | 1433 | w.setCurrCategory(view->getCurrentCategory()); |
1434 | if (pw) | 1434 | if (pw) |
1435 | w.pwLineEdit->setText(*pw); | 1435 | w.pwLineEdit->setText(*pw); |
1436 | */ | 1436 | */ |
1437 | w.setCurrCategory(view->getCurrentCategory()); | 1437 | w.setCurrCategory(view->getCurrentCategory()); |
1438 | 1438 | ||
1439 | tryAgain: | 1439 | tryAgain: |
1440 | if (w.exec() == 1) | 1440 | if (w.exec() == 1) |
1441 | { | 1441 | { |
1442 | PwMDataItem d; | 1442 | PwMDataItem d; |
1443 | 1443 | ||
1444 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 1444 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
1445 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | 1445 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. |
1446 | // another option would be to create a constructor for PwMDataItem | 1446 | // another option would be to create a constructor for PwMDataItem |
1447 | d.clear(true); | 1447 | d.clear(true); |
1448 | /* | 1448 | /* |
1449 | d.desc = w.getDescription().latin1(); | 1449 | d.desc = w.getDescription().latin1(); |
1450 | d.name = w.getUsername().latin1(); | 1450 | d.name = w.getUsername().latin1(); |
1451 | d.pw = w.getPassword().latin1(); | 1451 | d.pw = w.getPassword().latin1(); |
1452 | d.comment = w.getComment().latin1(); | 1452 | d.comment = w.getComment().latin1(); |
1453 | d.url = w.getUrl().latin1(); | 1453 | d.url = w.getUrl().latin1(); |
1454 | d.launcher = w.getLauncher().latin1(); | 1454 | d.launcher = w.getLauncher().latin1(); |
1455 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 1455 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
1456 | if (ret == e_entryExists) { | 1456 | if (ret == e_entryExists) { |
1457 | KMessageBox::error(this, | 1457 | KMessageBox::error(this, |
1458 | i18n | 1458 | i18n |
1459 | ("An entry with this \"Description\",\n" | 1459 | ("An entry with this \"Description\",\n" |
1460 | "does already exist.\n" | 1460 | "does already exist.\n" |
1461 | "Please select another description."), | 1461 | "Please select another description."), |
1462 | i18n("entry already exists.")); | 1462 | i18n("entry already exists.")); |
1463 | goto tryAgain; | 1463 | goto tryAgain; |
1464 | } else if (ret == e_maxAllowedEntr) { | 1464 | } else if (ret == e_maxAllowedEntr) { |
1465 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" | 1465 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" |
1466 | "has been reached.\nYou can't add more entries."), | 1466 | "has been reached.\nYou can't add more entries."), |
1467 | i18n("maximum number of entries")); | 1467 | i18n("maximum number of entries")); |
1468 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 1468 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
1469 | return; | 1469 | return; |
1470 | } | 1470 | } |
1471 | */ | 1471 | */ |
1472 | } | 1472 | } |
1473 | setVirgin(false); | 1473 | setVirgin(false); |
1474 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 1474 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
1475 | } | 1475 | } |
1476 | 1476 | ||
1477 | 1477 | ||
1478 | void PwM::whatsnew_slot() | 1478 | void PwM::whatsnew_slot() |
1479 | { | 1479 | { |
1480 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 1480 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
1481 | } | 1481 | } |
1482 | 1482 | ||
1483 | void PwM::showLicense_slot() | 1483 | void PwM::showLicense_slot() |
1484 | { | 1484 | { |
1485 | KApplication::showLicence(); | 1485 | KApplication::showLicence(); |
1486 | } | 1486 | } |
1487 | 1487 | ||
1488 | void PwM::faq_slot() | 1488 | void PwM::faq_slot() |
1489 | { | 1489 | { |
1490 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1490 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1491 | } | 1491 | } |
1492 | 1492 | ||
1493 | void PwM::syncHowTo_slot() | 1493 | void PwM::syncHowTo_slot() |
1494 | { | 1494 | { |
1495 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 1495 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
1496 | } | 1496 | } |
1497 | 1497 | ||
1498 | 1498 | ||
1499 | void PwM::createAboutData_slot() | 1499 | void PwM::createAboutData_slot() |
1500 | { | 1500 | { |
1501 | QString version; | 1501 | QString version; |
1502 | #include <../version> | 1502 | #include <../version> |
1503 | ; | 1503 | ; |
1504 | QMessageBox::about( this, "About PwManager/Pi", | 1504 | QMessageBox::about( this, "About PwManager/Pi", |
1505 | "PwManager/Platform-independent\n" | 1505 | "PwManager/Platform-independent\n" |
1506 | "(PWM/Pi) " +version + " - " + | 1506 | "(PWM/Pi) " +version + " - " + |
1507 | #ifdef DESKTOP_VERSION | 1507 | #ifdef DESKTOP_VERSION |
1508 | "Desktop Edition\n" | 1508 | "Desktop Edition\n" |
1509 | #else | 1509 | #else |
1510 | "PDA-Edition\n" | 1510 | "PDA-Edition\n" |
1511 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1511 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1512 | #endif | 1512 | #endif |
1513 | 1513 | ||
1514 | "(c) 2004 Ulf Schenk\n" | 1514 | "(c) 2004 Ulf Schenk\n" |
1515 | "(c) 2004 Lutz Rogowski\n" | 1515 | "(c) 2004 Lutz Rogowski\n" |
1516 | "(c) 1997-2004, The KDE PIM Team\n" | 1516 | "(c) 1997-2004, The KDE PIM Team\n" |
1517 | 1517 | ||
1518 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1518 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1519 | "Matt Scifo - mscifo@o1.com\n" | 1519 | "Matt Scifo - mscifo@o1.com\n" |
1520 | "Elias Probst - elias.probst@gmx.de\n" | 1520 | "Elias Probst - elias.probst@gmx.de\n" |
1521 | "George Staikos - staikos@kde.org\n" | 1521 | "George Staikos - staikos@kde.org\n" |
1522 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1522 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1523 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1523 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1524 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1524 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1525 | "Troy Engel - tengel@sonic.net\n" | 1525 | "Troy Engel - tengel@sonic.net\n" |
1526 | "Wickey - wickey@gmx.at\n" | 1526 | "Wickey - wickey@gmx.at\n" |
1527 | "Ian MacGregor - original documentation author.\n" | 1527 | "Ian MacGregor - original documentation author.\n" |
1528 | ); | 1528 | ); |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | 1531 | ||
1532 | //this are the overwritten callbackmethods from the syncinterface | 1532 | //this are the overwritten callbackmethods from the syncinterface |
1533 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1533 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1534 | { | 1534 | { |
1535 | PWM_ASSERT(curDoc()); | 1535 | PWM_ASSERT(curDoc()); |
1536 | 1536 | ||
1537 | bool ret = curDoc()->sync(manager, filename, mode); | 1537 | bool ret = curDoc()->sync(manager, filename, mode); |
1538 | 1538 | ||
1539 | qDebug("PwM::sync save now: ret=%i", ret); | 1539 | qDebug("PwM::sync save now: ret=%i", ret); |
1540 | 1540 | ||
1541 | if (ret == true) { | 1541 | if (ret == true) { |
1542 | //US BUG: what can we call here to update the view of the current doc? | 1542 | //US BUG: what can we call here to update the view of the current doc? |
1543 | //mViewManager->refreshView(); | 1543 | //mViewManager->refreshView(); |
1544 | 1544 | ||
1545 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | 1545 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. |
1546 | save(); | 1546 | save(); |
1547 | } | 1547 | } |
1548 | 1548 | ||
1549 | return ret; | 1549 | return ret; |
1550 | } | 1550 | } |
1551 | 1551 | ||
1552 | void PwM::removeSyncInfo( QString syncProfile) | 1552 | void PwM::removeSyncInfo( QString syncProfile) |
1553 | { | 1553 | { |
1554 | qDebug("PWM:removeSyncInfo for profile %s ", syncProfile.latin1()); | 1554 | qDebug("PWM:removeSyncInfo for profile %s ", syncProfile.latin1()); |
1555 | curDoc()->removeSyncInfo( syncProfile ); | 1555 | curDoc()->removeSyncInfo( syncProfile ); |
1556 | //US curDoc()->removeSyncInfo sets the dirtyFlag. | 1556 | //US curDoc()->removeSyncInfo sets the dirtyFlag. |
1557 | } | 1557 | } |
1558 | 1558 | ||
1559 | #endif | 1559 | #endif |
1560 | 1560 | ||
1561 | 1561 | ||
1562 | #ifndef PWM_EMBEDDED | 1562 | #ifndef PWM_EMBEDDED |
1563 | #include "pwm.moc" | 1563 | #include "pwm.moc" |
1564 | #endif | 1564 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 1f15ffd..6fbe110 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,2802 +1,2858 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.1 of pwmanager | 14 | * This file is originaly based on version 1.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmdoc.h" | 20 | #include "pwmdoc.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "blowfish.h" | 22 | #include "blowfish.h" |
23 | #include "sha1.h" | 23 | #include "sha1.h" |
24 | #include "globalstuff.h" | 24 | #include "globalstuff.h" |
25 | #include "gpasmanfile.h" | 25 | #include "gpasmanfile.h" |
26 | #include "serializer.h" | 26 | #include "serializer.h" |
27 | #include "compressgzip.h" | 27 | #include "compressgzip.h" |
28 | //US#include "compressbzip2.h" | 28 | //US#include "compressbzip2.h" |
29 | #include "randomizer.h" | 29 | #include "randomizer.h" |
30 | #include "pwminit.h" | 30 | #include "pwminit.h" |
31 | #include "libgcryptif.h" | 31 | #include "libgcryptif.h" |
32 | #ifdef PWM_EMBEDDED | 32 | #ifdef PWM_EMBEDDED |
33 | #include "pwmprefs.h" | 33 | #include "pwmprefs.h" |
34 | #include "kglobal.h" | 34 | #include "kglobal.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | 40 | ||
41 | #ifdef CONFIG_KWALLETIF | 41 | #ifdef CONFIG_KWALLETIF |
42 | # include "kwalletemu.h" | 42 | # include "kwalletemu.h" |
43 | #endif // CONFIG_KWALLETIF | 43 | #endif // CONFIG_KWALLETIF |
44 | 44 | ||
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | #include <qsize.h> | 46 | #include <qsize.h> |
47 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | 49 | ||
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | //US#include <iostream> | 54 | //US#include <iostream> |
55 | #include <algorithm> | 55 | #include <algorithm> |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | 57 | #include <sys/stat.h> |
58 | #ifndef _WIN32_ | 58 | #ifndef _WIN32_ |
59 | #include <unistd.h> | 59 | #include <unistd.h> |
60 | #include <stdint.h> | 60 | #include <stdint.h> |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #ifdef PWM_EMBEDDED | 63 | #ifdef PWM_EMBEDDED |
64 | #ifndef Q_LONG | 64 | #ifndef Q_LONG |
65 | #define Q_LONG long | 65 | #define Q_LONG long |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | #ifndef Q_ULONG | 68 | #ifndef Q_ULONG |
69 | #define Q_ULONG unsigned long | 69 | #define Q_ULONG unsigned long |
70 | #endif | 70 | #endif |
71 | #endif //PWM_EMBEDDED | 71 | #endif //PWM_EMBEDDED |
72 | 72 | ||
73 | 73 | ||
74 | //TODO: reset to its normal value. | 74 | //TODO: reset to its normal value. |
75 | //LR set to 5 min | 75 | //LR set to 5 min |
76 | #define META_CHECK_TIMER_INTERVAL300 /* 10 300*/ /* sek */ | 76 | #define META_CHECK_TIMER_INTERVAL300 /* 10 300*/ /* sek */ |
77 | 77 | ||
78 | using namespace std; | 78 | using namespace std; |
79 | 79 | ||
80 | 80 | ||
81 | void PwMDocList::add(PwMDoc *doc, const string &id) | 81 | void PwMDocList::add(PwMDoc *doc, const string &id) |
82 | { | 82 | { |
83 | #ifdef PWM_DEBUG | 83 | #ifdef PWM_DEBUG |
84 | // check for existance of object in debug mode only. | 84 | // check for existance of object in debug mode only. |
85 | vector<listItem>::iterator begin = docList.begin(), | 85 | vector<listItem>::iterator begin = docList.begin(), |
86 | end = docList.end(), | 86 | end = docList.end(), |
87 | i = begin; | 87 | i = begin; |
88 | while (i != end) { | 88 | while (i != end) { |
89 | if (i->doc == doc) { | 89 | if (i->doc == doc) { |
90 | BUG(); | 90 | BUG(); |
91 | return; | 91 | return; |
92 | } | 92 | } |
93 | ++i; | 93 | ++i; |
94 | } | 94 | } |
95 | #endif | 95 | #endif |
96 | listItem newItem; | 96 | listItem newItem; |
97 | newItem.doc = doc; | 97 | newItem.doc = doc; |
98 | newItem.docId = id; | 98 | newItem.docId = id; |
99 | docList.push_back(newItem); | 99 | docList.push_back(newItem); |
100 | } | 100 | } |
101 | 101 | ||
102 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 102 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
103 | { | 103 | { |
104 | vector<listItem>::iterator begin = docList.begin(), | 104 | vector<listItem>::iterator begin = docList.begin(), |
105 | end = docList.end(), | 105 | end = docList.end(), |
106 | i = begin; | 106 | i = begin; |
107 | while (i != end) { | 107 | while (i != end) { |
108 | if (i->doc == doc) { | 108 | if (i->doc == doc) { |
109 | i->docId = newId; | 109 | i->docId = newId; |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | ++i; | 112 | ++i; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | void PwMDocList::del(PwMDoc *doc) | 116 | void PwMDocList::del(PwMDoc *doc) |
117 | { | 117 | { |
118 | vector<listItem>::iterator begin = docList.begin(), | 118 | vector<listItem>::iterator begin = docList.begin(), |
119 | end = docList.end(), | 119 | end = docList.end(), |
120 | i = begin; | 120 | i = begin; |
121 | while (i != end) { | 121 | while (i != end) { |
122 | if (i->doc == doc) { | 122 | if (i->doc == doc) { |
123 | docList.erase(i); | 123 | docList.erase(i); |
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | ++i; | 126 | ++i; |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | bool PwMDocList::find(const string &id, listItem *ret) | 130 | bool PwMDocList::find(const string &id, listItem *ret) |
131 | { | 131 | { |
132 | vector<listItem>::iterator begin = docList.begin(), | 132 | vector<listItem>::iterator begin = docList.begin(), |
133 | end = docList.end(), | 133 | end = docList.end(), |
134 | i = begin; | 134 | i = begin; |
135 | while (i != end) { | 135 | while (i != end) { |
136 | if (i->docId == id) { | 136 | if (i->docId == id) { |
137 | if (ret) | 137 | if (ret) |
138 | *ret = *i; | 138 | *ret = *i; |
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | ++i; | 141 | ++i; |
142 | } | 142 | } |
143 | return false; | 143 | return false; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | DocTimer::DocTimer(PwMDoc *_doc) | 148 | DocTimer::DocTimer(PwMDoc *_doc) |
149 | : doc (_doc) | 149 | : doc (_doc) |
150 | , mpwLock (0) | 150 | , mpwLock (0) |
151 | , autoLockLock (0) | 151 | , autoLockLock (0) |
152 | , metaCheckLock (0) | 152 | , metaCheckLock (0) |
153 | { | 153 | { |
154 | mpwTimer = new QTimer; | 154 | mpwTimer = new QTimer; |
155 | autoLockTimer = new QTimer; | 155 | autoLockTimer = new QTimer; |
156 | metaCheckTimer = new QTimer; | 156 | metaCheckTimer = new QTimer; |
157 | connect(mpwTimer, SIGNAL(timeout()), | 157 | connect(mpwTimer, SIGNAL(timeout()), |
158 | this, SLOT(mpwTimeout())); | 158 | this, SLOT(mpwTimeout())); |
159 | connect(autoLockTimer, SIGNAL(timeout()), | 159 | connect(autoLockTimer, SIGNAL(timeout()), |
160 | this, SLOT(autoLockTimeout())); | 160 | this, SLOT(autoLockTimeout())); |
161 | connect(metaCheckTimer, SIGNAL(timeout()), | 161 | connect(metaCheckTimer, SIGNAL(timeout()), |
162 | this, SLOT(metaCheckTimeout())); | 162 | this, SLOT(metaCheckTimeout())); |
163 | } | 163 | } |
164 | 164 | ||
165 | DocTimer::~DocTimer() | 165 | DocTimer::~DocTimer() |
166 | { | 166 | { |
167 | delete mpwTimer; | 167 | delete mpwTimer; |
168 | delete autoLockTimer; | 168 | delete autoLockTimer; |
169 | delete metaCheckTimer; | 169 | delete metaCheckTimer; |
170 | } | 170 | } |
171 | 171 | ||
172 | void DocTimer::start(TimerIDs timer) | 172 | void DocTimer::start(TimerIDs timer) |
173 | { | 173 | { |
174 | switch (timer) { | 174 | switch (timer) { |
175 | case id_mpwTimer: | 175 | case id_mpwTimer: |
176 | if (mpwTimer->isActive()) | 176 | if (mpwTimer->isActive()) |
177 | mpwTimer->stop(); | 177 | mpwTimer->stop(); |
178 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 178 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
179 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 179 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
180 | break; | 180 | break; |
181 | case id_autoLockTimer: | 181 | case id_autoLockTimer: |
182 | if (autoLockTimer->isActive()) | 182 | if (autoLockTimer->isActive()) |
183 | autoLockTimer->stop(); | 183 | autoLockTimer->stop(); |
184 | if (conf()->confGlobLockTimeout() > 0) | 184 | if (conf()->confGlobLockTimeout() > 0) |
185 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 185 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
186 | break; | 186 | break; |
187 | case id_metaCheckTimer: | 187 | case id_metaCheckTimer: |
188 | if (metaCheckTimer->isActive()) | 188 | if (metaCheckTimer->isActive()) |
189 | metaCheckTimer->stop(); | 189 | metaCheckTimer->stop(); |
190 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 190 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
191 | break; | 191 | break; |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | void DocTimer::stop(TimerIDs timer) | 195 | void DocTimer::stop(TimerIDs timer) |
196 | { | 196 | { |
197 | switch (timer) { | 197 | switch (timer) { |
198 | case id_mpwTimer: | 198 | case id_mpwTimer: |
199 | mpwTimer->stop(); | 199 | mpwTimer->stop(); |
200 | break; | 200 | break; |
201 | case id_autoLockTimer: | 201 | case id_autoLockTimer: |
202 | autoLockTimer->stop(); | 202 | autoLockTimer->stop(); |
203 | break; | 203 | break; |
204 | case id_metaCheckTimer: | 204 | case id_metaCheckTimer: |
205 | metaCheckTimer->stop(); | 205 | metaCheckTimer->stop(); |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | void DocTimer::getLock(TimerIDs timer) | 210 | void DocTimer::getLock(TimerIDs timer) |
211 | { | 211 | { |
212 | switch (timer) { | 212 | switch (timer) { |
213 | case id_mpwTimer: | 213 | case id_mpwTimer: |
214 | ++mpwLock; | 214 | ++mpwLock; |
215 | break; | 215 | break; |
216 | case id_autoLockTimer: | 216 | case id_autoLockTimer: |
217 | ++autoLockLock; | 217 | ++autoLockLock; |
218 | break; | 218 | break; |
219 | case id_metaCheckTimer: | 219 | case id_metaCheckTimer: |
220 | ++metaCheckLock; | 220 | ++metaCheckLock; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | void DocTimer::putLock(TimerIDs timer) | 225 | void DocTimer::putLock(TimerIDs timer) |
226 | { | 226 | { |
227 | switch (timer) { | 227 | switch (timer) { |
228 | case id_mpwTimer: | 228 | case id_mpwTimer: |
229 | if (mpwLock) | 229 | if (mpwLock) |
230 | --mpwLock; | 230 | --mpwLock; |
231 | break; | 231 | break; |
232 | case id_autoLockTimer: | 232 | case id_autoLockTimer: |
233 | if (autoLockLock) | 233 | if (autoLockLock) |
234 | --autoLockLock; | 234 | --autoLockLock; |
235 | break; | 235 | break; |
236 | case id_metaCheckTimer: | 236 | case id_metaCheckTimer: |
237 | if (metaCheckLock) | 237 | if (metaCheckLock) |
238 | --metaCheckLock; | 238 | --metaCheckLock; |
239 | break; | 239 | break; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | void DocTimer::mpwTimeout() | 243 | void DocTimer::mpwTimeout() |
244 | { | 244 | { |
245 | if (mpwLock) { | 245 | if (mpwLock) { |
246 | mpwTimer->start(1000, true); | 246 | mpwTimer->start(1000, true); |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 249 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
250 | } | 250 | } |
251 | 251 | ||
252 | void DocTimer::autoLockTimeout() | 252 | void DocTimer::autoLockTimeout() |
253 | { | 253 | { |
254 | if (autoLockLock) { | 254 | if (autoLockLock) { |
255 | autoLockTimer->start(1000, true); | 255 | autoLockTimer->start(1000, true); |
256 | return; | 256 | return; |
257 | } | 257 | } |
258 | if (conf()->confGlobAutoDeepLock() && | 258 | if (conf()->confGlobAutoDeepLock() && |
259 | doc->filename != QString::null && | 259 | doc->filename != QString::null && |
260 | doc->filename != "") { | 260 | doc->filename != "") { |
261 | doc->deepLock(true); | 261 | doc->deepLock(true); |
262 | } else { | 262 | } else { |
263 | doc->lockAll(true); | 263 | doc->lockAll(true); |
264 | } | 264 | } |
265 | } | 265 | } |
266 | 266 | ||
267 | void DocTimer::metaCheckTimeout() | 267 | void DocTimer::metaCheckTimeout() |
268 | { | 268 | { |
269 | if (metaCheckLock) { | 269 | if (metaCheckLock) { |
270 | // check again in one second. | 270 | // check again in one second. |
271 | metaCheckTimer->start(1000, true); | 271 | metaCheckTimer->start(1000, true); |
272 | return; | 272 | return; |
273 | } | 273 | } |
274 | if (doc->isDeepLocked()) { | 274 | if (doc->isDeepLocked()) { |
275 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 275 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
276 | return; | 276 | return; |
277 | } | 277 | } |
278 | if (doc->isDocEmpty()) { | 278 | if (doc->isDocEmpty()) { |
279 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 279 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
280 | return; | 280 | return; |
281 | } | 281 | } |
282 | #ifdef CONFIG_KWALLETIF | 282 | #ifdef CONFIG_KWALLETIF |
283 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 283 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
284 | if (kwlEmu) | 284 | if (kwlEmu) |
285 | kwlEmu->suspendDocSignals(); | 285 | kwlEmu->suspendDocSignals(); |
286 | #endif // CONFIG_KWALLETIF | 286 | #endif // CONFIG_KWALLETIF |
287 | /* We simply trigger all views to update their | 287 | /* We simply trigger all views to update their |
288 | * displayed values. This way they have a chance | 288 | * displayed values. This way they have a chance |
289 | * to get notified when some meta changes over time. | 289 | * to get notified when some meta changes over time. |
290 | * (for example an entry expired). | 290 | * (for example an entry expired). |
291 | * The _view_ is responsive for not updating its | 291 | * The _view_ is responsive for not updating its |
292 | * contents if nothing really changed! | 292 | * contents if nothing really changed! |
293 | */ | 293 | */ |
294 | emit doc->dataChanged(doc); | 294 | emit doc->dataChanged(doc); |
295 | #ifdef CONFIG_KWALLETIF | 295 | #ifdef CONFIG_KWALLETIF |
296 | if (kwlEmu) | 296 | if (kwlEmu) |
297 | kwlEmu->resumeDocSignals(); | 297 | kwlEmu->resumeDocSignals(); |
298 | #endif // CONFIG_KWALLETIF | 298 | #endif // CONFIG_KWALLETIF |
299 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 299 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | 303 | ||
304 | PwMDocList PwMDoc::openDocList; | 304 | PwMDocList PwMDoc::openDocList; |
305 | unsigned int PwMDocList::unnamedDocCnt = 1; | 305 | unsigned int PwMDocList::unnamedDocCnt = 1; |
306 | 306 | ||
307 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 307 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
308 | : PwMDocUi(parent, name) | 308 | : PwMDocUi(parent, name) |
309 | , dataChangedLock (0) | 309 | , dataChangedLock (0) |
310 | { | 310 | { |
311 | deleted = false; | 311 | deleted = false; |
312 | unnamedNum = 0; | 312 | unnamedNum = 0; |
313 | getOpenDocList()->add(this, getTitle().latin1()); | 313 | getOpenDocList()->add(this, getTitle().latin1()); |
314 | curDocStat = 0; | 314 | curDocStat = 0; |
315 | setMaxNumEntries(); | 315 | setMaxNumEntries(); |
316 | _timer = new DocTimer(this); | 316 | _timer = new DocTimer(this); |
317 | timer()->start(DocTimer::id_mpwTimer); | 317 | timer()->start(DocTimer::id_mpwTimer); |
318 | timer()->start(DocTimer::id_autoLockTimer); | 318 | timer()->start(DocTimer::id_autoLockTimer); |
319 | timer()->start(DocTimer::id_metaCheckTimer); | 319 | timer()->start(DocTimer::id_metaCheckTimer); |
320 | addCategory(DEFAULT_CATEGORY, 0, false); | 320 | addCategory(DEFAULT_CATEGORY, 0, false); |
321 | listView = 0; | 321 | listView = 0; |
322 | emit docCreated(this); | 322 | emit docCreated(this); |
323 | } | 323 | } |
324 | 324 | ||
325 | PwMDoc::~PwMDoc() | 325 | PwMDoc::~PwMDoc() |
326 | { | 326 | { |
327 | emit docClosed(this); | 327 | emit docClosed(this); |
328 | getOpenDocList()->del(this); | 328 | getOpenDocList()->del(this); |
329 | delete _timer; | 329 | delete _timer; |
330 | } | 330 | } |
331 | 331 | ||
332 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 332 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
333 | { | 333 | { |
334 | PwMerror ret, e; | 334 | PwMerror ret, e; |
335 | string serialized; | 335 | string serialized; |
336 | QFile f; | 336 | QFile f; |
337 | QString tmpFileMoved(QString::null); | 337 | QString tmpFileMoved(QString::null); |
338 | bool wasDeepLocked; | 338 | bool wasDeepLocked; |
339 | QString savedFilename(filename); | 339 | QString savedFilename(filename); |
340 | 340 | ||
341 | if (!file) { | 341 | if (!file) { |
342 | if (filename == "") | 342 | if (filename == "") |
343 | return e_filename; | 343 | return e_filename; |
344 | if (isDeepLocked()) { | 344 | if (isDeepLocked()) { |
345 | /* We don't need to save any data. | 345 | /* We don't need to save any data. |
346 | * It's already all on disk, because | 346 | * It's already all on disk, because |
347 | * we are deeplocked. | 347 | * we are deeplocked. |
348 | */ | 348 | */ |
349 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 349 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
350 | ret = e_success; | 350 | ret = e_success; |
351 | return ret; | 351 | return ret; |
352 | } | 352 | } |
353 | } else { | 353 | } else { |
354 | if (*file == "" && filename == "") | 354 | if (*file == "" && filename == "") |
355 | return e_filename; | 355 | return e_filename; |
356 | if (*file != "") | 356 | if (*file != "") |
357 | filename = *file; | 357 | filename = *file; |
358 | } | 358 | } |
359 | 359 | ||
360 | wasDeepLocked = isDeepLocked(); | 360 | wasDeepLocked = isDeepLocked(); |
361 | if (wasDeepLocked) { | 361 | if (wasDeepLocked) { |
362 | /* We are deeplocked. That means all data is already | 362 | /* We are deeplocked. That means all data is already |
363 | * on disk. BUT we need to do saving procedure, | 363 | * on disk. BUT we need to do saving procedure, |
364 | * because *file != savedFilename. | 364 | * because *file != savedFilename. |
365 | * Additionally we need to tempoarly restore | 365 | * Additionally we need to tempoarly restore |
366 | * the old "filename", because deepLock() references it. | 366 | * the old "filename", because deepLock() references it. |
367 | */ | 367 | */ |
368 | QString newFilename(filename); | 368 | QString newFilename(filename); |
369 | filename = savedFilename; | 369 | filename = savedFilename; |
370 | getDataChangedLock(); | 370 | getDataChangedLock(); |
371 | e = deepLock(false); | 371 | e = deepLock(false); |
372 | putDataChangedLock(); | 372 | putDataChangedLock(); |
373 | filename = newFilename; | 373 | filename = newFilename; |
374 | switch (e) { | 374 | switch (e) { |
375 | case e_success: | 375 | case e_success: |
376 | break; | 376 | break; |
377 | case e_wrongPw: | 377 | case e_wrongPw: |
378 | case e_noPw: | 378 | case e_noPw: |
379 | emitDataChanged(this); | 379 | emitDataChanged(this); |
380 | return e; | 380 | return e; |
381 | default: | 381 | default: |
382 | emitDataChanged(this); | 382 | emitDataChanged(this); |
383 | return e_openFile; | 383 | return e_openFile; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | 386 | ||
387 | if (!isPwAvailable()) { | 387 | if (!isPwAvailable()) { |
388 | /* password is not available. This means, the | 388 | /* password is not available. This means, the |
389 | * document wasn't saved, yet. | 389 | * document wasn't saved, yet. |
390 | */ | 390 | */ |
391 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 391 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
392 | QString pw(requestNewMpw(&useChipcard)); | 392 | QString pw(requestNewMpw(&useChipcard)); |
393 | if (pw != "") { | 393 | if (pw != "") { |
394 | currentPw = pw; | 394 | currentPw = pw; |
395 | } else { | 395 | } else { |
396 | return e_noPw; | 396 | return e_noPw; |
397 | } | 397 | } |
398 | if (useChipcard) { | 398 | if (useChipcard) { |
399 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 399 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
400 | } else { | 400 | } else { |
401 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 401 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 405 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
406 | int _hashAlgo = conf()->confGlobHashAlgo(); | 406 | int _hashAlgo = conf()->confGlobHashAlgo(); |
407 | 407 | ||
408 | // sanity check for the selected algorithms | 408 | // sanity check for the selected algorithms |
409 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 409 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
410 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 410 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
411 | printWarn("Invalid Crypto-Algorithm selected! " | 411 | printWarn("Invalid Crypto-Algorithm selected! " |
412 | "Config-file seems to be corrupt. " | 412 | "Config-file seems to be corrupt. " |
413 | "Falling back to Blowfish."); | 413 | "Falling back to Blowfish."); |
414 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 414 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
415 | } | 415 | } |
416 | if (_hashAlgo < PWM_HASH_SHA1 || | 416 | if (_hashAlgo < PWM_HASH_SHA1 || |
417 | _hashAlgo > PWM_HASH_TIGER) { | 417 | _hashAlgo > PWM_HASH_TIGER) { |
418 | printWarn("Invalid Hash-Algorithm selected! " | 418 | printWarn("Invalid Hash-Algorithm selected! " |
419 | "Config-file seems to be corrupt. " | 419 | "Config-file seems to be corrupt. " |
420 | "Falling back to SHA1."); | 420 | "Falling back to SHA1."); |
421 | _hashAlgo = PWM_HASH_SHA1; | 421 | _hashAlgo = PWM_HASH_SHA1; |
422 | } | 422 | } |
423 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 423 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
424 | char hashAlgo = static_cast<char>(_hashAlgo); | 424 | char hashAlgo = static_cast<char>(_hashAlgo); |
425 | 425 | ||
426 | if (conf()->confGlobMakeFileBackup()) { | 426 | if (conf()->confGlobMakeFileBackup()) { |
427 | if (!backupFile(filename)) | 427 | if (!backupFile(filename)) |
428 | return e_fileBackup; | 428 | return e_fileBackup; |
429 | } | 429 | } |
430 | if (QFile::exists(filename)) { | 430 | if (QFile::exists(filename)) { |
431 | /* Move the existing file to some tmp file. | 431 | /* Move the existing file to some tmp file. |
432 | * When saving file succeeds, delete tmp file. Otherwise | 432 | * When saving file succeeds, delete tmp file. Otherwise |
433 | * move tmp file back. See below. | 433 | * move tmp file back. See below. |
434 | */ | 434 | */ |
435 | Randomizer *rnd = Randomizer::obj(); | 435 | Randomizer *rnd = Randomizer::obj(); |
436 | char rnd_buf[5]; | 436 | char rnd_buf[5]; |
437 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 437 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
438 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 438 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
439 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 439 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
440 | if (!copyFile(filename, tmpFileMoved)) | 440 | if (!copyFile(filename, tmpFileMoved)) |
441 | return e_openFile; | 441 | return e_openFile; |
442 | if (!QFile::remove(filename)) { | 442 | if (!QFile::remove(filename)) { |
443 | printWarn(string("removing orig file ") | 443 | printWarn(string("removing orig file ") |
444 | + filename.latin1() | 444 | + filename.latin1() |
445 | + " failed!"); | 445 | + " failed!"); |
446 | } | 446 | } |
447 | } | 447 | } |
448 | f.setName(filename); | 448 | f.setName(filename); |
449 | if (!f.open(IO_ReadWrite)) { | 449 | if (!f.open(IO_ReadWrite)) { |
450 | ret = e_openFile; | 450 | ret = e_openFile; |
451 | goto out_moveback; | 451 | goto out_moveback; |
452 | } | 452 | } |
453 | e = writeFileHeader(hashAlgo, hashAlgo, | 453 | e = writeFileHeader(hashAlgo, hashAlgo, |
454 | cryptAlgo, compress, | 454 | cryptAlgo, compress, |
455 | ¤tPw, &f); | 455 | ¤tPw, &f); |
456 | if (e == e_hashNotImpl) { | 456 | if (e == e_hashNotImpl) { |
457 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 457 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
458 | f.close(); | 458 | f.close(); |
459 | ret = e_hashNotImpl; | 459 | ret = e_hashNotImpl; |
460 | goto out_moveback; | 460 | goto out_moveback; |
461 | } else if (e != e_success) { | 461 | } else if (e != e_success) { |
462 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 462 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
463 | f.close(); | 463 | f.close(); |
464 | ret = e_writeHeader; | 464 | ret = e_writeHeader; |
465 | goto out_moveback; | 465 | goto out_moveback; |
466 | } | 466 | } |
467 | if (!serializeDta(&serialized)) { | 467 | if (!serializeDta(&serialized)) { |
468 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 468 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
469 | f.close(); | 469 | f.close(); |
470 | ret = e_serializeDta; | 470 | ret = e_serializeDta; |
471 | goto out_moveback; | 471 | goto out_moveback; |
472 | } | 472 | } |
473 | e = writeDataHash(hashAlgo, &serialized, &f); | 473 | e = writeDataHash(hashAlgo, &serialized, &f); |
474 | if (e == e_hashNotImpl) { | 474 | if (e == e_hashNotImpl) { |
475 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 475 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
476 | f.close(); | 476 | f.close(); |
477 | ret = e_hashNotImpl; | 477 | ret = e_hashNotImpl; |
478 | goto out_moveback; | 478 | goto out_moveback; |
479 | } else if (e != e_success) { | 479 | } else if (e != e_success) { |
480 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 480 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
481 | f.close(); | 481 | f.close(); |
482 | ret = e_writeHeader; | 482 | ret = e_writeHeader; |
483 | goto out_moveback; | 483 | goto out_moveback; |
484 | } | 484 | } |
485 | if (!compressDta(&serialized, compress)) { | 485 | if (!compressDta(&serialized, compress)) { |
486 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 486 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
487 | f.close(); | 487 | f.close(); |
488 | ret = e_enc; | 488 | ret = e_enc; |
489 | goto out_moveback; | 489 | goto out_moveback; |
490 | } | 490 | } |
491 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo, hashAlgo); | 491 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo, hashAlgo); |
492 | if (e == e_weakPw) { | 492 | if (e == e_weakPw) { |
493 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 493 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
494 | f.close(); | 494 | f.close(); |
495 | ret = e_weakPw; | 495 | ret = e_weakPw; |
496 | goto out_moveback; | 496 | goto out_moveback; |
497 | } else if (e == e_cryptNotImpl) { | 497 | } else if (e == e_cryptNotImpl) { |
498 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 498 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
499 | f.close(); | 499 | f.close(); |
500 | ret = e_cryptNotImpl; | 500 | ret = e_cryptNotImpl; |
501 | goto out_moveback; | 501 | goto out_moveback; |
502 | } else if (e != e_success) { | 502 | } else if (e != e_success) { |
503 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 503 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
504 | f.close(); | 504 | f.close(); |
505 | ret = e_enc; | 505 | ret = e_enc; |
506 | goto out_moveback; | 506 | goto out_moveback; |
507 | } | 507 | } |
508 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 508 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
509 | f.close(); | 509 | f.close(); |
510 | #ifndef _WIN32_ | 510 | #ifndef _WIN32_ |
511 | if (chmod(filename.latin1(), | 511 | if (chmod(filename.latin1(), |
512 | conf()->confGlobFilePermissions())) { | 512 | conf()->confGlobFilePermissions())) { |
513 | printWarn(string("chmod failed: ") + strerror(errno)); | 513 | printWarn(string("chmod failed: ") + strerror(errno)); |
514 | } | 514 | } |
515 | #endif | 515 | #endif |
516 | openDocList.edit(this, getTitle().latin1()); | 516 | openDocList.edit(this, getTitle().latin1()); |
517 | if (wasDeepLocked) { | 517 | if (wasDeepLocked) { |
518 | /* Do _not_ save the data with the deepLock() | 518 | /* Do _not_ save the data with the deepLock() |
519 | * call, because this will recurse | 519 | * call, because this will recurse |
520 | * into saveDoc() | 520 | * into saveDoc() |
521 | */ | 521 | */ |
522 | deepLock(true, false); | 522 | deepLock(true, false); |
523 | /* We don't check return value here, because | 523 | /* We don't check return value here, because |
524 | * it won't fail. See NOTE in deepLock() | 524 | * it won't fail. See NOTE in deepLock() |
525 | */ | 525 | */ |
526 | } | 526 | } |
527 | if (tmpFileMoved != QString::null) { | 527 | if (tmpFileMoved != QString::null) { |
528 | // now remove the moved file. | 528 | // now remove the moved file. |
529 | if (!QFile::remove(tmpFileMoved)) { | 529 | if (!QFile::remove(tmpFileMoved)) { |
530 | printWarn(string("removing file ") | 530 | printWarn(string("removing file ") |
531 | + tmpFileMoved.latin1() | 531 | + tmpFileMoved.latin1() |
532 | + " failed!"); | 532 | + " failed!"); |
533 | } | 533 | } |
534 | } | 534 | } |
535 | ret = e_success; | 535 | ret = e_success; |
536 | printDebug(string("writing file { name: ") | 536 | printDebug(string("writing file { name: ") |
537 | + filename.latin1() + " compress: " | 537 | + filename.latin1() + " compress: " |
538 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 538 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
539 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 539 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
540 | + tostr(static_cast<int>(hashAlgo)) | 540 | + tostr(static_cast<int>(hashAlgo)) |
541 | + " }"); | 541 | + " }"); |
542 | goto out; | 542 | goto out; |
543 | out_moveback: | 543 | out_moveback: |
544 | if (tmpFileMoved != QString::null) { | 544 | if (tmpFileMoved != QString::null) { |
545 | if (copyFile(tmpFileMoved, filename)) { | 545 | if (copyFile(tmpFileMoved, filename)) { |
546 | if (!QFile::remove(tmpFileMoved)) { | 546 | if (!QFile::remove(tmpFileMoved)) { |
547 | printWarn(string("removing tmp file ") | 547 | printWarn(string("removing tmp file ") |
548 | + filename.latin1() | 548 | + filename.latin1() |
549 | + " failed!"); | 549 | + " failed!"); |
550 | } | 550 | } |
551 | } else { | 551 | } else { |
552 | printWarn(string("couldn't copy file ") | 552 | printWarn(string("couldn't copy file ") |
553 | + tmpFileMoved.latin1() | 553 | + tmpFileMoved.latin1() |
554 | + " back to " | 554 | + " back to " |
555 | + filename.latin1()); | 555 | + filename.latin1()); |
556 | } | 556 | } |
557 | } | 557 | } |
558 | out: | 558 | out: |
559 | return ret; | 559 | return ret; |
560 | } | 560 | } |
561 | 561 | ||
562 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 562 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
563 | { | 563 | { |
564 | PWM_ASSERT(file); | 564 | PWM_ASSERT(file); |
565 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 565 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
566 | string decrypted, dataHash; | 566 | string decrypted, dataHash; |
567 | PwMerror ret; | 567 | PwMerror ret; |
568 | char cryptAlgo, dataHashType, compress; | 568 | char cryptAlgo, dataHashType, compress; |
569 | unsigned int headerLen; | 569 | unsigned int headerLen; |
570 | 570 | ||
571 | if (*file == "") | 571 | if (*file == "") |
572 | return e_readFile; | 572 | return e_readFile; |
573 | filename = *file; | 573 | filename = *file; |
574 | /* check if this file is already open. | 574 | /* check if this file is already open. |
575 | * This does not catch symlinks! | 575 | * This does not catch symlinks! |
576 | */ | 576 | */ |
577 | if (!isDeepLocked()) { | 577 | if (!isDeepLocked()) { |
578 | if (getOpenDocList()->find(filename.latin1())) | 578 | if (getOpenDocList()->find(filename.latin1())) |
579 | return e_alreadyOpen; | 579 | return e_alreadyOpen; |
580 | } | 580 | } |
581 | QFile f(filename); | 581 | QFile f(filename); |
582 | 582 | ||
583 | if (openLocked == 2) { | 583 | if (openLocked == 2) { |
584 | // open deep-locked | 584 | // open deep-locked |
585 | if (!QFile::exists(filename)) | 585 | if (!QFile::exists(filename)) |
586 | return e_openFile; | 586 | return e_openFile; |
587 | if (deepLock(true, false) != e_success) | 587 | if (deepLock(true, false) != e_success) |
588 | return e_openFile; | 588 | return e_openFile; |
589 | goto out_success; | 589 | goto out_success; |
590 | } | 590 | } |
591 | 591 | ||
592 | if (!f.open(IO_ReadOnly)) | 592 | if (!f.open(IO_ReadOnly)) |
593 | return e_openFile; | 593 | return e_openFile; |
594 | 594 | ||
595 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 595 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
596 | &dataHashType, &dataHash, &f); | 596 | &dataHashType, &dataHash, &f); |
597 | if (ret != e_success) { | 597 | if (ret != e_success) { |
598 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 598 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
599 | f.close(); | 599 | f.close(); |
600 | if (ret == e_wrongPw) { | 600 | if (ret == e_wrongPw) { |
601 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 601 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
602 | return ret; | 602 | return ret; |
603 | } else if (ret == e_noPw || | 603 | } else if (ret == e_noPw || |
604 | ret == e_fileVer || | 604 | ret == e_fileVer || |
605 | ret == e_fileFormat || | 605 | ret == e_fileFormat || |
606 | ret == e_hashNotImpl) { | 606 | ret == e_hashNotImpl) { |
607 | return ret; | 607 | return ret; |
608 | } else | 608 | } else |
609 | return e_readFile; | 609 | return e_readFile; |
610 | } | 610 | } |
611 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, dataHashType, &f); | 611 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, dataHashType, &f); |
612 | if (ret == e_cryptNotImpl) { | 612 | if (ret == e_cryptNotImpl) { |
613 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 613 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
614 | f.close(); | 614 | f.close(); |
615 | return e_cryptNotImpl; | 615 | return e_cryptNotImpl; |
616 | } else if (ret != e_success) { | 616 | } else if (ret != e_success) { |
617 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 617 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
618 | f.close(); | 618 | f.close(); |
619 | return e_readFile; | 619 | return e_readFile; |
620 | } | 620 | } |
621 | if (!decompressDta(&decrypted, compress)) { | 621 | if (!decompressDta(&decrypted, compress)) { |
622 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 622 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
623 | f.close(); | 623 | f.close(); |
624 | return e_fileCorrupt; | 624 | return e_fileCorrupt; |
625 | } | 625 | } |
626 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 626 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
627 | if (ret == e_hashNotImpl) { | 627 | if (ret == e_hashNotImpl) { |
628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
629 | f.close(); | 629 | f.close(); |
630 | return e_hashNotImpl; | 630 | return e_hashNotImpl; |
631 | } else if (ret != e_success) { | 631 | } else if (ret != e_success) { |
632 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 632 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
633 | f.close(); | 633 | f.close(); |
634 | return e_fileCorrupt; | 634 | return e_fileCorrupt; |
635 | } | 635 | } |
636 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 636 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
637 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 637 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
638 | f.close(); | 638 | f.close(); |
639 | return e_readFile; | 639 | return e_readFile; |
640 | } | 640 | } |
641 | f.close(); | 641 | f.close(); |
642 | timer()->start(DocTimer::id_mpwTimer); | 642 | timer()->start(DocTimer::id_mpwTimer); |
643 | timer()->start(DocTimer::id_autoLockTimer); | 643 | timer()->start(DocTimer::id_autoLockTimer); |
644 | out_success: | 644 | out_success: |
645 | openDocList.edit(this, getTitle().latin1()); | 645 | openDocList.edit(this, getTitle().latin1()); |
646 | emit docOpened(this); | 646 | emit docOpened(this); |
647 | return e_success; | 647 | return e_success; |
648 | } | 648 | } |
649 | 649 | ||
650 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 650 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
651 | QString *pw, QFile *f) | 651 | QString *pw, QFile *f) |
652 | { | 652 | { |
653 | PWM_ASSERT(pw); | 653 | PWM_ASSERT(pw); |
654 | PWM_ASSERT(f); | 654 | PWM_ASSERT(f); |
655 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else | 655 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
656 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | 656 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion |
657 | //USPWM_ASSERT(listView); | 657 | //USPWM_ASSERT(listView); |
658 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 658 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
659 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 659 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
660 | return e_writeFile; | 660 | return e_writeFile; |
661 | } | 661 | } |
662 | if (f->putch(PWM_FILE_VER) == -1 || | 662 | if (f->putch(PWM_FILE_VER) == -1 || |
663 | f->putch(keyHash) == -1 || | 663 | f->putch(keyHash) == -1 || |
664 | f->putch(dataHash) == -1 || | 664 | f->putch(dataHash) == -1 || |
665 | f->putch(crypt) == -1 || | 665 | f->putch(crypt) == -1 || |
666 | f->putch(compress) == -1 || | 666 | f->putch(compress) == -1 || |
667 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 667 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
668 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 668 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
669 | return e_writeFile; | 669 | return e_writeFile; |
670 | } | 670 | } |
671 | 671 | ||
672 | // write bytes of NUL-data. These bytes are reserved for future-use. | 672 | // write bytes of NUL-data. These bytes are reserved for future-use. |
673 | const int bufSize = 64; | 673 | const int bufSize = 64; |
674 | char tmp_buf[bufSize]; | 674 | char tmp_buf[bufSize]; |
675 | memset(tmp_buf, 0x00, bufSize); | 675 | memset(tmp_buf, 0x00, bufSize); |
676 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 676 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
677 | return e_writeFile; | 677 | return e_writeFile; |
678 | 678 | ||
679 | switch (keyHash) { | 679 | switch (keyHash) { |
680 | case PWM_HASH_SHA1: { | 680 | case PWM_HASH_SHA1: { |
681 | const int hashlen = SHA1_HASH_LEN_BYTE; | 681 | const int hashlen = SHA1_HASH_LEN_BYTE; |
682 | Sha1 hash; | 682 | Sha1 hash; |
683 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 683 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
684 | string ret = hash.sha1_read(); | 684 | string ret = hash.sha1_read(); |
685 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 685 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
686 | return e_writeFile; | 686 | return e_writeFile; |
687 | break; | 687 | break; |
688 | } | 688 | } |
689 | case PWM_HASH_SHA256: | 689 | case PWM_HASH_SHA256: |
690 | /*... fall through */ | 690 | /*... fall through */ |
691 | case PWM_HASH_SHA384: | 691 | case PWM_HASH_SHA384: |
692 | case PWM_HASH_SHA512: | 692 | case PWM_HASH_SHA512: |
693 | case PWM_HASH_MD5: | 693 | case PWM_HASH_MD5: |
694 | case PWM_HASH_RMD160: | 694 | case PWM_HASH_RMD160: |
695 | case PWM_HASH_TIGER: | 695 | case PWM_HASH_TIGER: |
696 | { | 696 | { |
697 | if (!LibGCryptIf::available()) | 697 | if (!LibGCryptIf::available()) |
698 | return e_hashNotImpl; | 698 | return e_hashNotImpl; |
699 | LibGCryptIf gc; | 699 | LibGCryptIf gc; |
700 | PwMerror err; | 700 | PwMerror err; |
701 | unsigned char *buf; | 701 | unsigned char *buf; |
702 | size_t hashLen; | 702 | size_t hashLen; |
703 | err = gc.hash(&buf, | 703 | err = gc.hash(&buf, |
704 | &hashLen, | 704 | &hashLen, |
705 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 705 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
706 | pw->length(), | 706 | pw->length(), |
707 | keyHash); | 707 | keyHash); |
708 | if (err != e_success) | 708 | if (err != e_success) |
709 | return e_hashNotImpl; | 709 | return e_hashNotImpl; |
710 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 710 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
711 | != static_cast<Q_LONG>(hashLen)) { | 711 | != static_cast<Q_LONG>(hashLen)) { |
712 | delete [] buf; | 712 | delete [] buf; |
713 | return e_hashNotImpl; | 713 | return e_hashNotImpl; |
714 | } | 714 | } |
715 | delete [] buf; | 715 | delete [] buf; |
716 | break; | 716 | break; |
717 | } | 717 | } |
718 | default: { | 718 | default: { |
719 | return e_hashNotImpl; | 719 | return e_hashNotImpl; |
720 | } } | 720 | } } |
721 | return e_success; | 721 | return e_success; |
722 | } | 722 | } |
723 | 723 | ||
724 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 724 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
725 | unsigned int *headerLength, char *dataHashType, | 725 | unsigned int *headerLength, char *dataHashType, |
726 | string *dataHash, QFile *f) | 726 | string *dataHash, QFile *f) |
727 | { | 727 | { |
728 | PWM_ASSERT(cryptAlgo); | 728 | PWM_ASSERT(cryptAlgo); |
729 | PWM_ASSERT(pw); | 729 | PWM_ASSERT(pw); |
730 | PWM_ASSERT(headerLength); | 730 | PWM_ASSERT(headerLength); |
731 | PWM_ASSERT(dataHashType); | 731 | PWM_ASSERT(dataHashType); |
732 | PWM_ASSERT(dataHash); | 732 | PWM_ASSERT(dataHash); |
733 | PWM_ASSERT(f); | 733 | PWM_ASSERT(f); |
734 | int tmpRet; | 734 | int tmpRet; |
735 | // check "magic" header | 735 | // check "magic" header |
736 | const char magicHdr[] = FILE_ID_HEADER; | 736 | const char magicHdr[] = FILE_ID_HEADER; |
737 | const int hdrLen = array_size(magicHdr) - 1; | 737 | const int hdrLen = array_size(magicHdr) - 1; |
738 | char tmp[hdrLen]; | 738 | char tmp[hdrLen]; |
739 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 739 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
740 | return e_readFile; | 740 | return e_readFile; |
741 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 741 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
742 | return e_fileFormat; | 742 | return e_fileFormat; |
743 | // read and check file ver | 743 | // read and check file ver |
744 | int fileV = f->getch(); | 744 | int fileV = f->getch(); |
745 | if (fileV == -1) | 745 | if (fileV == -1) |
746 | return e_fileFormat; | 746 | return e_fileFormat; |
747 | if (fileV != PWM_FILE_VER) | 747 | if (fileV != PWM_FILE_VER) |
748 | return e_fileVer; | 748 | return e_fileVer; |
749 | // read hash hash type | 749 | // read hash hash type |
750 | int keyHash = f->getch(); | 750 | int keyHash = f->getch(); |
751 | if (keyHash == -1) | 751 | if (keyHash == -1) |
752 | return e_fileFormat; | 752 | return e_fileFormat; |
753 | // read data hash type | 753 | // read data hash type |
754 | tmpRet = f->getch(); | 754 | tmpRet = f->getch(); |
755 | if (tmpRet == -1) | 755 | if (tmpRet == -1) |
756 | return e_fileFormat; | 756 | return e_fileFormat; |
757 | *dataHashType = tmpRet; | 757 | *dataHashType = tmpRet; |
758 | // read crypt algo | 758 | // read crypt algo |
759 | tmpRet = f->getch(); | 759 | tmpRet = f->getch(); |
760 | if (tmpRet == -1) | 760 | if (tmpRet == -1) |
761 | return e_fileFormat; | 761 | return e_fileFormat; |
762 | *cryptAlgo = tmpRet; | 762 | *cryptAlgo = tmpRet; |
763 | // get compression-algo | 763 | // get compression-algo |
764 | tmpRet = f->getch(); | 764 | tmpRet = f->getch(); |
765 | if (tmpRet == -1) | 765 | if (tmpRet == -1) |
766 | return e_fileFormat; | 766 | return e_fileFormat; |
767 | *compress = tmpRet; | 767 | *compress = tmpRet; |
768 | // get the MPW-flag | 768 | // get the MPW-flag |
769 | int mpw_flag = f->getch(); | 769 | int mpw_flag = f->getch(); |
770 | if (mpw_flag == -1) | 770 | if (mpw_flag == -1) |
771 | return e_fileFormat; | 771 | return e_fileFormat; |
772 | if (mpw_flag == 0x01) | 772 | if (mpw_flag == 0x01) |
773 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 773 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
774 | else | 774 | else |
775 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 775 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
776 | // skip the "RESERVED"-bytes | 776 | // skip the "RESERVED"-bytes |
777 | if (!(f->at(f->at() + 64))) | 777 | if (!(f->at(f->at() + 64))) |
778 | return e_fileFormat; | 778 | return e_fileFormat; |
779 | 779 | ||
780 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 780 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
781 | if (*pw == "") { | 781 | if (*pw == "") { |
782 | /* the user didn't give a master-password | 782 | /* the user didn't give a master-password |
783 | * or didn't insert a chipcard | 783 | * or didn't insert a chipcard |
784 | */ | 784 | */ |
785 | return e_noPw; | 785 | return e_noPw; |
786 | } | 786 | } |
787 | // verify key-hash | 787 | // verify key-hash |
788 | switch (keyHash) { | 788 | switch (keyHash) { |
789 | case PWM_HASH_SHA1: { | 789 | case PWM_HASH_SHA1: { |
790 | // read hash from header | 790 | // read hash from header |
791 | const int hashLen = SHA1_HASH_LEN_BYTE; | 791 | const int hashLen = SHA1_HASH_LEN_BYTE; |
792 | string readHash; | 792 | string readHash; |
793 | int i; | 793 | int i; |
794 | for (i = 0; i < hashLen; ++i) | 794 | for (i = 0; i < hashLen; ++i) |
795 | readHash.push_back(f->getch()); | 795 | readHash.push_back(f->getch()); |
796 | Sha1 hash; | 796 | Sha1 hash; |
797 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 797 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
798 | string ret = hash.sha1_read(); | 798 | string ret = hash.sha1_read(); |
799 | if (ret != readHash) | 799 | if (ret != readHash) |
800 | return e_wrongPw;// hash doesn't match (wrong key) | 800 | return e_wrongPw;// hash doesn't match (wrong key) |
801 | break; | 801 | break; |
802 | } | 802 | } |
803 | case PWM_HASH_SHA256: | 803 | case PWM_HASH_SHA256: |
804 | /*... fall through */ | 804 | /*... fall through */ |
805 | case PWM_HASH_SHA384: | 805 | case PWM_HASH_SHA384: |
806 | case PWM_HASH_SHA512: | 806 | case PWM_HASH_SHA512: |
807 | case PWM_HASH_MD5: | 807 | case PWM_HASH_MD5: |
808 | case PWM_HASH_RMD160: | 808 | case PWM_HASH_RMD160: |
809 | case PWM_HASH_TIGER: { | 809 | case PWM_HASH_TIGER: { |
810 | if (!LibGCryptIf::available()) | 810 | if (!LibGCryptIf::available()) |
811 | return e_hashNotImpl; | 811 | return e_hashNotImpl; |
812 | LibGCryptIf gc; | 812 | LibGCryptIf gc; |
813 | PwMerror err; | 813 | PwMerror err; |
814 | unsigned char *buf; | 814 | unsigned char *buf; |
815 | size_t hashLen; | 815 | size_t hashLen; |
816 | err = gc.hash(&buf, | 816 | err = gc.hash(&buf, |
817 | &hashLen, | 817 | &hashLen, |
818 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 818 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
819 | pw->length(), | 819 | pw->length(), |
820 | keyHash); | 820 | keyHash); |
821 | if (err != e_success) | 821 | if (err != e_success) |
822 | return e_hashNotImpl; | 822 | return e_hashNotImpl; |
823 | string calcHash(reinterpret_cast<const char *>(buf), | 823 | string calcHash(reinterpret_cast<const char *>(buf), |
824 | static_cast<string::size_type>(hashLen)); | 824 | static_cast<string::size_type>(hashLen)); |
825 | delete [] buf; | 825 | delete [] buf; |
826 | // read hash from header | 826 | // read hash from header |
827 | string readHash; | 827 | string readHash; |
828 | size_t i; | 828 | size_t i; |
829 | for (i = 0; i < hashLen; ++i) | 829 | for (i = 0; i < hashLen; ++i) |
830 | readHash.push_back(f->getch()); | 830 | readHash.push_back(f->getch()); |
831 | if (calcHash != readHash) | 831 | if (calcHash != readHash) |
832 | return e_wrongPw;// hash doesn't match (wrong key) | 832 | return e_wrongPw;// hash doesn't match (wrong key) |
833 | break; | 833 | break; |
834 | } | 834 | } |
835 | default: { | 835 | default: { |
836 | return e_hashNotImpl; | 836 | return e_hashNotImpl; |
837 | } } | 837 | } } |
838 | // read the data-hash from the file | 838 | // read the data-hash from the file |
839 | unsigned int hashLen, i; | 839 | unsigned int hashLen, i; |
840 | switch (*dataHashType) { | 840 | switch (*dataHashType) { |
841 | case PWM_HASH_SHA1: | 841 | case PWM_HASH_SHA1: |
842 | hashLen = SHA1_HASH_LEN_BYTE; | 842 | hashLen = SHA1_HASH_LEN_BYTE; |
843 | break; | 843 | break; |
844 | case PWM_HASH_SHA256: | 844 | case PWM_HASH_SHA256: |
845 | /*... fall through */ | 845 | /*... fall through */ |
846 | case PWM_HASH_SHA384: | 846 | case PWM_HASH_SHA384: |
847 | case PWM_HASH_SHA512: | 847 | case PWM_HASH_SHA512: |
848 | case PWM_HASH_MD5: | 848 | case PWM_HASH_MD5: |
849 | case PWM_HASH_RMD160: | 849 | case PWM_HASH_RMD160: |
850 | case PWM_HASH_TIGER: { | 850 | case PWM_HASH_TIGER: { |
851 | if (!LibGCryptIf::available()) | 851 | if (!LibGCryptIf::available()) |
852 | return e_hashNotImpl; | 852 | return e_hashNotImpl; |
853 | LibGCryptIf gc; | 853 | LibGCryptIf gc; |
854 | hashLen = gc.hashLength(*dataHashType); | 854 | hashLen = gc.hashLength(*dataHashType); |
855 | if (hashLen == 0) | 855 | if (hashLen == 0) |
856 | return e_hashNotImpl; | 856 | return e_hashNotImpl; |
857 | break; | 857 | break; |
858 | } | 858 | } |
859 | default: | 859 | default: |
860 | return e_hashNotImpl; | 860 | return e_hashNotImpl; |
861 | } | 861 | } |
862 | *dataHash = ""; | 862 | *dataHash = ""; |
863 | for (i = 0; i < hashLen; ++i) { | 863 | for (i = 0; i < hashLen; ++i) { |
864 | tmpRet = f->getch(); | 864 | tmpRet = f->getch(); |
865 | if (tmpRet == -1) | 865 | if (tmpRet == -1) |
866 | return e_fileFormat; | 866 | return e_fileFormat; |
867 | dataHash->push_back(static_cast<char>(tmpRet)); | 867 | dataHash->push_back(static_cast<char>(tmpRet)); |
868 | } | 868 | } |
869 | *headerLength = f->at(); | 869 | *headerLength = f->at(); |
870 | #ifndef PWM_EMBEDDED | 870 | #ifndef PWM_EMBEDDED |
871 | printDebug(string("opening file { compress: ") | 871 | printDebug(string("opening file { compress: ") |
872 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 872 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
873 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 873 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
874 | + tostr(static_cast<int>(keyHash)) | 874 | + tostr(static_cast<int>(keyHash)) |
875 | + " }"); | 875 | + " }"); |
876 | #else | 876 | #else |
877 | printDebug(string("opening file { compress: ") | 877 | printDebug(string("opening file { compress: ") |
878 | + tostr((int)(*compress)) + " cryptAlgo: " | 878 | + tostr((int)(*compress)) + " cryptAlgo: " |
879 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 879 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
880 | + tostr((int)(keyHash)) | 880 | + tostr((int)(keyHash)) |
881 | + " }"); | 881 | + " }"); |
882 | #endif | 882 | #endif |
883 | 883 | ||
884 | return e_success; | 884 | return e_success; |
885 | } | 885 | } |
886 | 886 | ||
887 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 887 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
888 | { | 888 | { |
889 | PWM_ASSERT(d); | 889 | PWM_ASSERT(d); |
890 | PWM_ASSERT(f); | 890 | PWM_ASSERT(f); |
891 | 891 | ||
892 | switch (dataHash) { | 892 | switch (dataHash) { |
893 | case PWM_HASH_SHA1: { | 893 | case PWM_HASH_SHA1: { |
894 | const int hashLen = SHA1_HASH_LEN_BYTE; | 894 | const int hashLen = SHA1_HASH_LEN_BYTE; |
895 | Sha1 h; | 895 | Sha1 h; |
896 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 896 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
897 | string hRet = h.sha1_read(); | 897 | string hRet = h.sha1_read(); |
898 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 898 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
899 | return e_writeFile; | 899 | return e_writeFile; |
900 | break; | 900 | break; |
901 | } | 901 | } |
902 | case PWM_HASH_SHA256: | 902 | case PWM_HASH_SHA256: |
903 | /*... fall through */ | 903 | /*... fall through */ |
904 | case PWM_HASH_SHA384: | 904 | case PWM_HASH_SHA384: |
905 | case PWM_HASH_SHA512: | 905 | case PWM_HASH_SHA512: |
906 | case PWM_HASH_MD5: | 906 | case PWM_HASH_MD5: |
907 | case PWM_HASH_RMD160: | 907 | case PWM_HASH_RMD160: |
908 | case PWM_HASH_TIGER: { | 908 | case PWM_HASH_TIGER: { |
909 | if (!LibGCryptIf::available()) | 909 | if (!LibGCryptIf::available()) |
910 | return e_hashNotImpl; | 910 | return e_hashNotImpl; |
911 | LibGCryptIf gc; | 911 | LibGCryptIf gc; |
912 | PwMerror err; | 912 | PwMerror err; |
913 | unsigned char *buf; | 913 | unsigned char *buf; |
914 | size_t hashLen; | 914 | size_t hashLen; |
915 | err = gc.hash(&buf, | 915 | err = gc.hash(&buf, |
916 | &hashLen, | 916 | &hashLen, |
917 | reinterpret_cast<const unsigned char *>(d->c_str()), | 917 | reinterpret_cast<const unsigned char *>(d->c_str()), |
918 | d->size(), | 918 | d->size(), |
919 | dataHash); | 919 | dataHash); |
920 | if (err != e_success) | 920 | if (err != e_success) |
921 | return e_hashNotImpl; | 921 | return e_hashNotImpl; |
922 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 922 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
923 | != static_cast<Q_LONG>(hashLen)) { | 923 | != static_cast<Q_LONG>(hashLen)) { |
924 | delete [] buf; | 924 | delete [] buf; |
925 | return e_hashNotImpl; | 925 | return e_hashNotImpl; |
926 | } | 926 | } |
927 | delete [] buf; | 927 | delete [] buf; |
928 | break; | 928 | break; |
929 | } | 929 | } |
930 | default: { | 930 | default: { |
931 | return e_hashNotImpl; | 931 | return e_hashNotImpl; |
932 | } } | 932 | } } |
933 | 933 | ||
934 | return e_success; | 934 | return e_success; |
935 | } | 935 | } |
936 | 936 | ||
937 | bool PwMDoc::backupFile(const QString &filePath) | 937 | bool PwMDoc::backupFile(const QString &filePath) |
938 | { | 938 | { |
939 | QFileInfo fi(filePath); | 939 | QFileInfo fi(filePath); |
940 | if (!fi.exists()) | 940 | if (!fi.exists()) |
941 | return true; // Yes, true is correct. | 941 | return true; // Yes, true is correct. |
942 | QString pathOnly(fi.dirPath(true)); | 942 | QString pathOnly(fi.dirPath(true)); |
943 | QString nameOnly(fi.fileName()); | 943 | QString nameOnly(fi.fileName()); |
944 | QString backupPath = pathOnly | 944 | QString backupPath = pathOnly |
945 | + "/~" | 945 | + "/~" |
946 | + nameOnly | 946 | + nameOnly |
947 | + ".backup"; | 947 | + ".backup"; |
948 | return copyFile(filePath, backupPath); | 948 | return copyFile(filePath, backupPath); |
949 | } | 949 | } |
950 | 950 | ||
951 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 951 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
952 | { | 952 | { |
953 | QFileInfo fi(src); | 953 | QFileInfo fi(src); |
954 | if (!fi.exists()) | 954 | if (!fi.exists()) |
955 | return false; | 955 | return false; |
956 | if (QFile::exists(dst)) { | 956 | if (QFile::exists(dst)) { |
957 | if (!QFile::remove(dst)) | 957 | if (!QFile::remove(dst)) |
958 | return false; | 958 | return false; |
959 | } | 959 | } |
960 | QFile srcFd(src); | 960 | QFile srcFd(src); |
961 | if (!srcFd.open(IO_ReadOnly)) | 961 | if (!srcFd.open(IO_ReadOnly)) |
962 | return false; | 962 | return false; |
963 | QFile dstFd(dst); | 963 | QFile dstFd(dst); |
964 | if (!dstFd.open(IO_ReadWrite)) { | 964 | if (!dstFd.open(IO_ReadWrite)) { |
965 | srcFd.close(); | 965 | srcFd.close(); |
966 | return false; | 966 | return false; |
967 | } | 967 | } |
968 | const int tmpBuf_size = 512; | 968 | const int tmpBuf_size = 512; |
969 | char tmpBuf[tmpBuf_size]; | 969 | char tmpBuf[tmpBuf_size]; |
970 | Q_LONG bytesRead, bytesWritten; | 970 | Q_LONG bytesRead, bytesWritten; |
971 | 971 | ||
972 | while (!srcFd.atEnd()) { | 972 | while (!srcFd.atEnd()) { |
973 | bytesRead = srcFd.readBlock(tmpBuf, | 973 | bytesRead = srcFd.readBlock(tmpBuf, |
974 | static_cast<Q_ULONG>(tmpBuf_size)); | 974 | static_cast<Q_ULONG>(tmpBuf_size)); |
975 | if (bytesRead == -1) { | 975 | if (bytesRead == -1) { |
976 | srcFd.close(); | 976 | srcFd.close(); |
977 | dstFd.close(); | 977 | dstFd.close(); |
978 | return false; | 978 | return false; |
979 | } | 979 | } |
980 | bytesWritten = dstFd.writeBlock(tmpBuf, | 980 | bytesWritten = dstFd.writeBlock(tmpBuf, |
981 | static_cast<Q_ULONG>(bytesRead)); | 981 | static_cast<Q_ULONG>(bytesRead)); |
982 | if (bytesWritten != bytesRead) { | 982 | if (bytesWritten != bytesRead) { |
983 | srcFd.close(); | 983 | srcFd.close(); |
984 | dstFd.close(); | 984 | dstFd.close(); |
985 | return false; | 985 | return false; |
986 | } | 986 | } |
987 | } | 987 | } |
988 | srcFd.close(); | 988 | srcFd.close(); |
989 | dstFd.close(); | 989 | dstFd.close(); |
990 | return true; | 990 | return true; |
991 | } | 991 | } |
992 | 992 | ||
993 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 993 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
994 | bool dontFlagDirty, bool updateMeta) | 994 | bool dontFlagDirty, bool updateMeta) |
995 | { | 995 | { |
996 | PWM_ASSERT(d); | 996 | PWM_ASSERT(d); |
997 | unsigned int cat = 0; | 997 | unsigned int cat = 0; |
998 | 998 | ||
999 | if (isDeepLocked()) { | 999 | if (isDeepLocked()) { |
1000 | PwMerror ret; | 1000 | PwMerror ret; |
1001 | ret = deepLock(false); | 1001 | ret = deepLock(false); |
1002 | if (ret != e_success) | 1002 | if (ret != e_success) |
1003 | return e_lock; | 1003 | return e_lock; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | addCategory(category, &cat); | 1006 | addCategory(category, &cat); |
1007 | 1007 | ||
1008 | if (numEntries(category) >= maxEntries) | 1008 | if (numEntries(category) >= maxEntries) |
1009 | return e_maxAllowedEntr; | 1009 | return e_maxAllowedEntr; |
1010 | 1010 | ||
1011 | vector<unsigned int> foundPositions; | 1011 | vector<unsigned int> foundPositions; |
1012 | /* historically this was: | 1012 | /* historically this was: |
1013 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 1013 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
1014 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 1014 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
1015 | * But for now we only search in desc. | 1015 | * But for now we only search in desc. |
1016 | * That's a tweak to be KWallet compatible. But it should not add | 1016 | * That's a tweak to be KWallet compatible. But it should not add |
1017 | * usability-drop onto PwManager, does it? | 1017 | * usability-drop onto PwManager, does it? |
1018 | * (And yes, "int" was a bug. Correct is "unsigned int") | 1018 | * (And yes, "int" was a bug. Correct is "unsigned int") |
1019 | */ | 1019 | */ |
1020 | const unsigned int searchIn = SEARCH_IN_DESC; | 1020 | const unsigned int searchIn = SEARCH_IN_DESC; |
1021 | findEntry(cat, *d, searchIn, &foundPositions, true); | 1021 | findEntry(cat, *d, searchIn, &foundPositions, true); |
1022 | if (foundPositions.size()) { | 1022 | if (foundPositions.size()) { |
1023 | // DOH! We found this entry. | 1023 | // DOH! We found this entry. |
1024 | return e_entryExists; | 1024 | return e_entryExists; |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | d->listViewPos = -1; | 1027 | d->listViewPos = -1; |
1028 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1028 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1029 | if (updateMeta) { | 1029 | if (updateMeta) { |
1030 | d->meta.create = QDateTime::currentDateTime(); | 1030 | d->meta.create = QDateTime::currentDateTime(); |
1031 | d->meta.update = d->meta.create; | 1031 | d->meta.update = d->meta.create; |
1032 | } | 1032 | } |
1033 | dti.dta[cat].d.push_back(*d); | 1033 | dti.dta[cat].d.push_back(*d); |
1034 | 1034 | ||
1035 | delAllEmptyCat(true); | 1035 | delAllEmptyCat(true); |
1036 | 1036 | ||
1037 | if (!dontFlagDirty) | 1037 | if (!dontFlagDirty) |
1038 | flagDirty(); | 1038 | flagDirty(); |
1039 | return e_success; | 1039 | return e_success; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1042 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1043 | bool checkIfExist) | 1043 | bool checkIfExist) |
1044 | { | 1044 | { |
1045 | if (isDeepLocked()) { | 1045 | if (isDeepLocked()) { |
1046 | PwMerror ret; | 1046 | PwMerror ret; |
1047 | ret = deepLock(false); | 1047 | ret = deepLock(false); |
1048 | if (ret != e_success) | 1048 | if (ret != e_success) |
1049 | return e_lock; | 1049 | return e_lock; |
1050 | } | 1050 | } |
1051 | if (checkIfExist) { | 1051 | if (checkIfExist) { |
1052 | if (findCategory(category, categoryIndex)) | 1052 | if (findCategory(category, categoryIndex)) |
1053 | return e_categoryExists; | 1053 | return e_categoryExists; |
1054 | } | 1054 | } |
1055 | PwMCategoryItem item; | 1055 | PwMCategoryItem item; |
1056 | //US ENH: clear item to initialize with default values, or create a constructor | 1056 | //US ENH: clear item to initialize with default values, or create a constructor |
1057 | item.clear(); | 1057 | item.clear(); |
1058 | 1058 | ||
1059 | item.name = category.latin1(); | 1059 | item.name = category.latin1(); |
1060 | dti.dta.push_back(item); | 1060 | dti.dta.push_back(item); |
1061 | if (categoryIndex) | 1061 | if (categoryIndex) |
1062 | *categoryIndex = dti.dta.size() - 1; | 1062 | *categoryIndex = dti.dta.size() - 1; |
1063 | return e_success; | 1063 | return e_success; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1066 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1067 | { | 1067 | { |
1068 | unsigned int cat = 0; | 1068 | unsigned int cat = 0; |
1069 | 1069 | ||
1070 | if (!findCategory(category, &cat)) { | 1070 | if (!findCategory(category, &cat)) { |
1071 | BUG(); | 1071 | BUG(); |
1072 | return false; | 1072 | return false; |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | return delEntry(cat, index, dontFlagDirty); | 1075 | return delEntry(cat, index, dontFlagDirty); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1078 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1079 | { | 1079 | { |
1080 | if (isDeepLocked()) | 1080 | if (isDeepLocked()) |
1081 | return false; | 1081 | return false; |
1082 | if (index > dti.dta[category].d.size() - 1) | 1082 | if (index > dti.dta[category].d.size() - 1) |
1083 | return false; | 1083 | return false; |
1084 | getDataChangedLock(); | 1084 | getDataChangedLock(); |
1085 | if (!lockAt(category, index, false)) { | 1085 | if (!lockAt(category, index, false)) { |
1086 | putDataChangedLock(); | 1086 | putDataChangedLock(); |
1087 | return false; | 1087 | return false; |
1088 | } | 1088 | } |
1089 | putDataChangedLock(); | 1089 | putDataChangedLock(); |
1090 | int lvPos = dti.dta[category].d[index].listViewPos; | 1090 | int lvPos = dti.dta[category].d[index].listViewPos; |
1091 | 1091 | ||
1092 | // delete entry | 1092 | // delete entry |
1093 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); | 1093 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1094 | 1094 | ||
1095 | unsigned int i, entries = numEntries(category); | 1095 | unsigned int i, entries = numEntries(category); |
1096 | if (!entries) { | 1096 | if (!entries) { |
1097 | // no more entries in this category, so | 1097 | // no more entries in this category, so |
1098 | // we can delete it, too. | 1098 | // we can delete it, too. |
1099 | BUG_ON(!delCategory(category)); | 1099 | BUG_ON(!delCategory(category)); |
1100 | // delCategory() flags it dirty, so we need not to do so. | 1100 | // delCategory() flags it dirty, so we need not to do so. |
1101 | return true; | 1101 | return true; |
1102 | } | 1102 | } |
1103 | for (i = 0; i < entries; ++i) { | 1103 | for (i = 0; i < entries; ++i) { |
1104 | // decrement all listViewPositions that are greater than the deleted. | 1104 | // decrement all listViewPositions that are greater than the deleted. |
1105 | if (dti.dta[category].d[i].listViewPos > lvPos) | 1105 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1106 | --dti.dta[category].d[i].listViewPos; | 1106 | --dti.dta[category].d[i].listViewPos; |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | if (!dontFlagDirty) | 1109 | if (!dontFlagDirty) |
1110 | flagDirty(); | 1110 | flagDirty(); |
1111 | return true; | 1111 | return true; |
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1114 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1115 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1115 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1116 | { | 1116 | { |
1117 | PWM_ASSERT(d); | 1117 | PWM_ASSERT(d); |
1118 | unsigned int oldCat = 0; | 1118 | unsigned int oldCat = 0; |
1119 | 1119 | ||
1120 | if (!findCategory(oldCategory, &oldCat)) { | 1120 | if (!findCategory(oldCategory, &oldCat)) { |
1121 | BUG(); | 1121 | BUG(); |
1122 | return false; | 1122 | return false; |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1125 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1128 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1129 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1129 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1130 | { | 1130 | { |
1131 | if (isDeepLocked()) | 1131 | if (isDeepLocked()) |
1132 | return false; | 1132 | return false; |
1133 | if (updateMeta) { | 1133 | if (updateMeta) { |
1134 | d->meta.update = QDateTime::currentDateTime(); | 1134 | d->meta.update = QDateTime::currentDateTime(); |
1135 | if (d->meta.create.isNull()) { | 1135 | if (d->meta.create.isNull()) { |
1136 | d->meta.create = d->meta.update; | 1136 | d->meta.create = d->meta.update; |
1137 | } | 1137 | } |
1138 | } | 1138 | } |
1139 | if (dti.dta[oldCategory].name != newCategory.latin1()) { | 1139 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1140 | // the user changed the category. | 1140 | // the user changed the category. |
1141 | PwMerror ret; | 1141 | PwMerror ret; |
1142 | d->rev = 0; | 1142 | d->rev = 0; |
1143 | ret = addEntry(newCategory, d, true, false); | 1143 | ret = addEntry(newCategory, d, true, false); |
1144 | if (ret != e_success) | 1144 | if (ret != e_success) |
1145 | return false; | 1145 | return false; |
1146 | if (!delEntry(oldCategory, index, true)) | 1146 | if (!delEntry(oldCategory, index, true)) |
1147 | return false; | 1147 | return false; |
1148 | } else { | 1148 | } else { |
1149 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1149 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1150 | dti.dta[oldCategory].d[index] = *d; | 1150 | dti.dta[oldCategory].d[index] = *d; |
1151 | } | 1151 | } |
1152 | flagDirty(); | 1152 | flagDirty(); |
1153 | return true; | 1153 | return true; |
1154 | } | 1154 | } |
1155 | 1155 | ||
1156 | unsigned int PwMDoc::numEntries(const QString &category) | 1156 | unsigned int PwMDoc::numEntries(const QString &category) |
1157 | { | 1157 | { |
1158 | unsigned int cat = 0; | 1158 | unsigned int cat = 0; |
1159 | 1159 | ||
1160 | if (!findCategory(category, &cat)) { | 1160 | if (!findCategory(category, &cat)) { |
1161 | BUG(); | 1161 | BUG(); |
1162 | return 0; | 1162 | return 0; |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | return numEntries(cat); | 1165 | return numEntries(cat); |
1166 | } | 1166 | } |
1167 | 1167 | ||
1168 | bool PwMDoc::serializeDta(string *d) | 1168 | bool PwMDoc::serializeDta(string *d) |
1169 | { | 1169 | { |
1170 | PWM_ASSERT(d); | 1170 | PWM_ASSERT(d); |
1171 | Serializer ser; | 1171 | Serializer ser; |
1172 | if (!ser.serialize(dti)) | 1172 | if (!ser.serialize(dti)) |
1173 | return false; | 1173 | return false; |
1174 | d->assign(ser.getXml()); | 1174 | d->assign(ser.getXml()); |
1175 | if (!d->size()) | 1175 | if (!d->size()) |
1176 | return false; | 1176 | return false; |
1177 | return true; | 1177 | return true; |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1180 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1181 | { | 1181 | { |
1182 | PWM_ASSERT(d); | 1182 | PWM_ASSERT(d); |
1183 | #ifndef PWM_EMBEDDED | 1183 | #ifndef PWM_EMBEDDED |
1184 | try { | 1184 | try { |
1185 | 1185 | ||
1186 | Serializer ser(d->c_str()); | 1186 | Serializer ser(d->c_str()); |
1187 | ser.setDefaultLockStat(entriesLocked); | 1187 | ser.setDefaultLockStat(entriesLocked); |
1188 | if (!ser.deSerialize(&dti)) | 1188 | if (!ser.deSerialize(&dti)) |
1189 | return false; | 1189 | return false; |
1190 | } catch (PwMException) { | 1190 | } catch (PwMException) { |
1191 | return false; | 1191 | return false; |
1192 | } | 1192 | } |
1193 | #else | 1193 | #else |
1194 | Serializer ser(d->c_str()); | 1194 | Serializer ser(d->c_str()); |
1195 | ser.setDefaultLockStat(entriesLocked); | 1195 | ser.setDefaultLockStat(entriesLocked); |
1196 | if (!ser.deSerialize(&dti)) | 1196 | if (!ser.deSerialize(&dti)) |
1197 | return false; | 1197 | return false; |
1198 | #endif | 1198 | #endif |
1199 | 1199 | ||
1200 | emitDataChanged(this); | 1200 | emitDataChanged(this); |
1201 | return true; | 1201 | return true; |
1202 | } | 1202 | } |
1203 | 1203 | ||
1204 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1204 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1205 | PwMDataItem * d, bool unlockIfLocked) | 1205 | PwMDataItem * d, bool unlockIfLocked) |
1206 | { | 1206 | { |
1207 | PWM_ASSERT(d); | 1207 | PWM_ASSERT(d); |
1208 | unsigned int cat = 0; | 1208 | unsigned int cat = 0; |
1209 | 1209 | ||
1210 | if (!findCategory(category, &cat)) { | 1210 | if (!findCategory(category, &cat)) { |
1211 | BUG(); | 1211 | BUG(); |
1212 | return false; | 1212 | return false; |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | return getEntry(cat, index, d, unlockIfLocked); | 1215 | return getEntry(cat, index, d, unlockIfLocked); |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1218 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1219 | PwMDataItem *d, bool unlockIfLocked) | 1219 | PwMDataItem *d, bool unlockIfLocked) |
1220 | { | 1220 | { |
1221 | if (index > dti.dta[category].d.size() - 1) | 1221 | if (index > dti.dta[category].d.size() - 1) |
1222 | return false; | 1222 | return false; |
1223 | 1223 | ||
1224 | bool locked = isLocked(category, index); | 1224 | bool locked = isLocked(category, index); |
1225 | if (locked) { | 1225 | if (locked) { |
1226 | /* this entry is locked. We don't return a password, | 1226 | /* this entry is locked. We don't return a password, |
1227 | * until it's unlocked by the user by inserting | 1227 | * until it's unlocked by the user by inserting |
1228 | * chipcard or entering the mpw | 1228 | * chipcard or entering the mpw |
1229 | */ | 1229 | */ |
1230 | if (unlockIfLocked) { | 1230 | if (unlockIfLocked) { |
1231 | if (!lockAt(category, index, false)) { | 1231 | if (!lockAt(category, index, false)) { |
1232 | return false; | 1232 | return false; |
1233 | } | 1233 | } |
1234 | locked = false; | 1234 | locked = false; |
1235 | } | 1235 | } |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | *d = dti.dta[category].d[index]; | 1238 | *d = dti.dta[category].d[index]; |
1239 | if (locked) | 1239 | if (locked) |
1240 | d->pw = LOCKED_STRING.latin1(); | 1240 | d->pw = LOCKED_STRING.latin1(); |
1241 | 1241 | ||
1242 | return true; | 1242 | return true; |
1243 | } | 1243 | } |
1244 | |||
1245 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1244 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1246 | string *foundComment) | 1245 | string *foundComment) |
1247 | { | 1246 | { |
1248 | PWM_ASSERT(foundComment); | 1247 | PWM_ASSERT(foundComment); |
1249 | unsigned int cat = 0; | 1248 | unsigned int cat = 0; |
1250 | 1249 | ||
1251 | if (!findCategory(category, &cat)) | 1250 | if (!findCategory(category, &cat)) |
1252 | return e_invalidArg; | 1251 | return e_invalidArg; |
1253 | 1252 | ||
1254 | unsigned int i, entries = numEntries(cat); | 1253 | unsigned int i, entries = numEntries(cat); |
1255 | for (i = 0; i < entries; ++i) { | 1254 | for (i = 0; i < entries; ++i) { |
1256 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | 1255 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1257 | *foundComment = dti.dta[cat].d[i].comment; | 1256 | *foundComment = dti.dta[cat].d[i].comment; |
1258 | if (dti.dta[cat].d[i].binary) | 1257 | if (dti.dta[cat].d[i].binary) |
1259 | return e_binEntry; | 1258 | return e_binEntry; |
1260 | return e_normalEntry; | 1259 | return e_normalEntry; |
1261 | } | 1260 | } |
1262 | } | 1261 | } |
1263 | BUG(); | 1262 | BUG(); |
1264 | return e_generic; | 1263 | return e_generic; |
1265 | } | 1264 | } |
1266 | 1265 | ||
1266 | PwMerror PwMDoc::getCommentByLvp_long(const QString &category, int listViewPos, | ||
1267 | string *foundComment) | ||
1268 | { | ||
1269 | PWM_ASSERT(foundComment); | ||
1270 | unsigned int cat = 0; | ||
1271 | |||
1272 | if (!findCategory(category, &cat)) | ||
1273 | return e_invalidArg; | ||
1274 | |||
1275 | unsigned int i, entries = numEntries(cat); | ||
1276 | for (i = 0; i < entries; ++i) { | ||
1277 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | ||
1278 | if (dti.dta[cat].d[i].binary) | ||
1279 | return e_binEntry; | ||
1280 | PwMCategoryItem* catItem = getCategoryEntry(cat); | ||
1281 | QString retval; | ||
1282 | QString tempval = QString (dti.dta[cat].d[i].desc.c_str()); | ||
1283 | if ( !tempval.isEmpty() ) { | ||
1284 | retval += "<b>" +QString ( catItem->desc_text.c_str() )+ ":</b> "+ tempval+"<br>" ; | ||
1285 | } | ||
1286 | tempval = QString (dti.dta[cat].d[i].name.c_str()); | ||
1287 | if ( !tempval.isEmpty() ) { | ||
1288 | retval += "<b>" +QString ( catItem->name_text.c_str() ) + ":</b> "+ tempval+"<br>" ; | ||
1289 | } | ||
1290 | tempval = QString (dti.dta[cat].d[i].pw.c_str()); | ||
1291 | if ( !tempval.isEmpty() ) { | ||
1292 | if ( dti.dta[cat].d[i].lockStat ) | ||
1293 | retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + i18n("<LOCKED>") +"<br>" ; | ||
1294 | else | ||
1295 | retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + tempval+"<br>" ; | ||
1296 | } | ||
1297 | tempval = QString (dti.dta[cat].d[i].url.c_str()); | ||
1298 | if ( !tempval.isEmpty() ) { | ||
1299 | retval += "<b>" +i18n("URL:")+ "</b> " + tempval+"<br>" ; | ||
1300 | } | ||
1301 | tempval = QString (dti.dta[cat].d[i].launcher.c_str()); | ||
1302 | if ( !tempval.isEmpty() ) { | ||
1303 | retval += "<b>" +i18n("Launcher:")+ "</b> " + tempval+"<br>" ; | ||
1304 | } | ||
1305 | tempval = QString (dti.dta[cat].d[i].comment.c_str()); | ||
1306 | if ( !tempval.isEmpty() ) { | ||
1307 | tempval.replace(QRegExp ( "\n" ), "<br>" ); | ||
1308 | retval += "<b>" +i18n("Comment:")+ "</b><br>" + tempval+"<br>" ; | ||
1309 | } | ||
1310 | |||
1311 | string ret ( retval.latin1() ); | ||
1312 | |||
1313 | |||
1314 | // *foundComment = dti.dta[cat].d[i].comment; | ||
1315 | *foundComment = ret; | ||
1316 | return e_normalEntry; | ||
1317 | } | ||
1318 | } | ||
1319 | BUG(); | ||
1320 | return e_generic; | ||
1321 | } | ||
1322 | |||
1267 | bool PwMDoc::compressDta(string *d, char algo) | 1323 | bool PwMDoc::compressDta(string *d, char algo) |
1268 | { | 1324 | { |
1269 | PWM_ASSERT(d); | 1325 | PWM_ASSERT(d); |
1270 | switch (algo) { | 1326 | switch (algo) { |
1271 | case PWM_COMPRESS_GZIP: { | 1327 | case PWM_COMPRESS_GZIP: { |
1272 | CompressGzip comp; | 1328 | CompressGzip comp; |
1273 | return comp.compress(d); | 1329 | return comp.compress(d); |
1274 | } | 1330 | } |
1275 | #ifndef PWM_EMBEDDED | 1331 | #ifndef PWM_EMBEDDED |
1276 | case PWM_COMPRESS_BZIP2: { | 1332 | case PWM_COMPRESS_BZIP2: { |
1277 | CompressBzip2 comp; | 1333 | CompressBzip2 comp; |
1278 | return comp.compress(d); | 1334 | return comp.compress(d); |
1279 | } | 1335 | } |
1280 | #endif | 1336 | #endif |
1281 | case PWM_COMPRESS_NONE: { | 1337 | case PWM_COMPRESS_NONE: { |
1282 | return true; | 1338 | return true; |
1283 | } default: { | 1339 | } default: { |
1284 | BUG(); | 1340 | BUG(); |
1285 | } | 1341 | } |
1286 | } | 1342 | } |
1287 | return false; | 1343 | return false; |
1288 | } | 1344 | } |
1289 | 1345 | ||
1290 | bool PwMDoc::decompressDta(string *d, char algo) | 1346 | bool PwMDoc::decompressDta(string *d, char algo) |
1291 | { | 1347 | { |
1292 | PWM_ASSERT(d); | 1348 | PWM_ASSERT(d); |
1293 | switch (algo) { | 1349 | switch (algo) { |
1294 | case PWM_COMPRESS_GZIP: { | 1350 | case PWM_COMPRESS_GZIP: { |
1295 | CompressGzip comp; | 1351 | CompressGzip comp; |
1296 | return comp.decompress(d); | 1352 | return comp.decompress(d); |
1297 | } | 1353 | } |
1298 | #ifndef PWM_EMBEDDED | 1354 | #ifndef PWM_EMBEDDED |
1299 | case PWM_COMPRESS_BZIP2: { | 1355 | case PWM_COMPRESS_BZIP2: { |
1300 | CompressBzip2 comp; | 1356 | CompressBzip2 comp; |
1301 | return comp.decompress(d); | 1357 | return comp.decompress(d); |
1302 | } | 1358 | } |
1303 | #endif | 1359 | #endif |
1304 | case PWM_COMPRESS_NONE: { | 1360 | case PWM_COMPRESS_NONE: { |
1305 | return true; | 1361 | return true; |
1306 | } | 1362 | } |
1307 | } | 1363 | } |
1308 | return false; | 1364 | return false; |
1309 | } | 1365 | } |
1310 | 1366 | ||
1311 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo, | 1367 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo, |
1312 | char hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase | 1368 | char hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase |
1313 | ) | 1369 | ) |
1314 | { | 1370 | { |
1315 | PWM_ASSERT(d); | 1371 | PWM_ASSERT(d); |
1316 | PWM_ASSERT(pw); | 1372 | PWM_ASSERT(pw); |
1317 | PWM_ASSERT(f); | 1373 | PWM_ASSERT(f); |
1318 | 1374 | ||
1319 | size_t encSize; | 1375 | size_t encSize; |
1320 | byte *encrypted = 0; | 1376 | byte *encrypted = 0; |
1321 | 1377 | ||
1322 | switch (algo) { | 1378 | switch (algo) { |
1323 | case PWM_CRYPT_BLOWFISH: { | 1379 | case PWM_CRYPT_BLOWFISH: { |
1324 | Blowfish::padNull(d); | 1380 | Blowfish::padNull(d); |
1325 | encSize = d->length(); | 1381 | encSize = d->length(); |
1326 | encrypted = new byte[encSize]; | 1382 | encrypted = new byte[encSize]; |
1327 | Blowfish bf; | 1383 | Blowfish bf; |
1328 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1384 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1329 | delete [] encrypted; | 1385 | delete [] encrypted; |
1330 | return e_weakPw; | 1386 | return e_weakPw; |
1331 | } | 1387 | } |
1332 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1388 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1333 | break; | 1389 | break; |
1334 | } | 1390 | } |
1335 | case PWM_CRYPT_AES128: | 1391 | case PWM_CRYPT_AES128: |
1336 | /*... fall through */ | 1392 | /*... fall through */ |
1337 | case PWM_CRYPT_AES192: | 1393 | case PWM_CRYPT_AES192: |
1338 | case PWM_CRYPT_AES256: | 1394 | case PWM_CRYPT_AES256: |
1339 | case PWM_CRYPT_3DES: | 1395 | case PWM_CRYPT_3DES: |
1340 | case PWM_CRYPT_TWOFISH: | 1396 | case PWM_CRYPT_TWOFISH: |
1341 | case PWM_CRYPT_TWOFISH128: { | 1397 | case PWM_CRYPT_TWOFISH128: { |
1342 | if (!LibGCryptIf::available()) | 1398 | if (!LibGCryptIf::available()) |
1343 | return e_cryptNotImpl; | 1399 | return e_cryptNotImpl; |
1344 | LibGCryptIf gc; | 1400 | LibGCryptIf gc; |
1345 | PwMerror err; | 1401 | PwMerror err; |
1346 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1402 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1347 | memcpy(plain, d->c_str(), d->length()); | 1403 | memcpy(plain, d->c_str(), d->length()); |
1348 | err = gc.encrypt(&encrypted, | 1404 | err = gc.encrypt(&encrypted, |
1349 | &encSize, | 1405 | &encSize, |
1350 | plain, | 1406 | plain, |
1351 | d->length(), | 1407 | d->length(), |
1352 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1408 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1353 | pw->length(), | 1409 | pw->length(), |
1354 | algo, | 1410 | algo, |
1355 | hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase | 1411 | hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase |
1356 | ); | 1412 | ); |
1357 | delete [] plain; | 1413 | delete [] plain; |
1358 | if (err != e_success) | 1414 | if (err != e_success) |
1359 | return e_cryptNotImpl; | 1415 | return e_cryptNotImpl; |
1360 | break; | 1416 | break; |
1361 | } | 1417 | } |
1362 | default: { | 1418 | default: { |
1363 | delete_ifnot_null_array(encrypted); | 1419 | delete_ifnot_null_array(encrypted); |
1364 | return e_cryptNotImpl; | 1420 | return e_cryptNotImpl; |
1365 | } } | 1421 | } } |
1366 | 1422 | ||
1367 | // write encrypted data to file | 1423 | // write encrypted data to file |
1368 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1424 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1369 | static_cast<Q_ULONG>(encSize)) | 1425 | static_cast<Q_ULONG>(encSize)) |
1370 | != static_cast<Q_LONG>(encSize)) { | 1426 | != static_cast<Q_LONG>(encSize)) { |
1371 | delete_ifnot_null_array(encrypted); | 1427 | delete_ifnot_null_array(encrypted); |
1372 | return e_writeFile; | 1428 | return e_writeFile; |
1373 | } | 1429 | } |
1374 | delete_ifnot_null_array(encrypted); | 1430 | delete_ifnot_null_array(encrypted); |
1375 | return e_success; | 1431 | return e_success; |
1376 | } | 1432 | } |
1377 | 1433 | ||
1378 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1434 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1379 | char algo, | 1435 | char algo, |
1380 | char hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase | 1436 | char hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase |
1381 | QFile *f) | 1437 | QFile *f) |
1382 | { | 1438 | { |
1383 | PWM_ASSERT(d); | 1439 | PWM_ASSERT(d); |
1384 | PWM_ASSERT(pw); | 1440 | PWM_ASSERT(pw); |
1385 | PWM_ASSERT(f); | 1441 | PWM_ASSERT(f); |
1386 | 1442 | ||
1387 | unsigned int cryptLen = f->size() - pos; | 1443 | unsigned int cryptLen = f->size() - pos; |
1388 | byte *encrypted = new byte[cryptLen]; | 1444 | byte *encrypted = new byte[cryptLen]; |
1389 | byte *decrypted = new byte[cryptLen]; | 1445 | byte *decrypted = new byte[cryptLen]; |
1390 | 1446 | ||
1391 | f->at(pos); | 1447 | f->at(pos); |
1392 | #ifndef PWM_EMBEDDED | 1448 | #ifndef PWM_EMBEDDED |
1393 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1449 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1394 | static_cast<Q_ULONG>(cryptLen)) | 1450 | static_cast<Q_ULONG>(cryptLen)) |
1395 | != static_cast<Q_LONG>(cryptLen)) { | 1451 | != static_cast<Q_LONG>(cryptLen)) { |
1396 | delete [] encrypted; | 1452 | delete [] encrypted; |
1397 | delete [] decrypted; | 1453 | delete [] decrypted; |
1398 | return e_readFile; | 1454 | return e_readFile; |
1399 | } | 1455 | } |
1400 | #else | 1456 | #else |
1401 | if (f->readBlock((char *)(encrypted), | 1457 | if (f->readBlock((char *)(encrypted), |
1402 | (unsigned long)(cryptLen)) | 1458 | (unsigned long)(cryptLen)) |
1403 | != (long)(cryptLen)) { | 1459 | != (long)(cryptLen)) { |
1404 | delete [] encrypted; | 1460 | delete [] encrypted; |
1405 | delete [] decrypted; | 1461 | delete [] decrypted; |
1406 | return e_readFile; | 1462 | return e_readFile; |
1407 | } | 1463 | } |
1408 | #endif | 1464 | #endif |
1409 | switch (algo) { | 1465 | switch (algo) { |
1410 | case PWM_CRYPT_BLOWFISH: { | 1466 | case PWM_CRYPT_BLOWFISH: { |
1411 | Blowfish bf; | 1467 | Blowfish bf; |
1412 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1468 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1413 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1469 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1414 | break; | 1470 | break; |
1415 | } | 1471 | } |
1416 | case PWM_CRYPT_AES128: | 1472 | case PWM_CRYPT_AES128: |
1417 | /*... fall through */ | 1473 | /*... fall through */ |
1418 | case PWM_CRYPT_AES192: | 1474 | case PWM_CRYPT_AES192: |
1419 | case PWM_CRYPT_AES256: | 1475 | case PWM_CRYPT_AES256: |
1420 | case PWM_CRYPT_3DES: | 1476 | case PWM_CRYPT_3DES: |
1421 | case PWM_CRYPT_TWOFISH: | 1477 | case PWM_CRYPT_TWOFISH: |
1422 | case PWM_CRYPT_TWOFISH128: { | 1478 | case PWM_CRYPT_TWOFISH128: { |
1423 | if (!LibGCryptIf::available()) | 1479 | if (!LibGCryptIf::available()) |
1424 | return e_cryptNotImpl; | 1480 | return e_cryptNotImpl; |
1425 | LibGCryptIf gc; | 1481 | LibGCryptIf gc; |
1426 | PwMerror err; | 1482 | PwMerror err; |
1427 | err = gc.decrypt(&decrypted, | 1483 | err = gc.decrypt(&decrypted, |
1428 | &cryptLen, | 1484 | &cryptLen, |
1429 | encrypted, | 1485 | encrypted, |
1430 | cryptLen, | 1486 | cryptLen, |
1431 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1487 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1432 | pw->length(), | 1488 | pw->length(), |
1433 | algo, | 1489 | algo, |
1434 | hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase | 1490 | hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase |
1435 | ); | 1491 | ); |
1436 | if (err != e_success) { | 1492 | if (err != e_success) { |
1437 | delete [] encrypted; | 1493 | delete [] encrypted; |
1438 | delete [] decrypted; | 1494 | delete [] decrypted; |
1439 | return e_cryptNotImpl; | 1495 | return e_cryptNotImpl; |
1440 | } | 1496 | } |
1441 | break; | 1497 | break; |
1442 | } | 1498 | } |
1443 | default: { | 1499 | default: { |
1444 | delete [] encrypted; | 1500 | delete [] encrypted; |
1445 | delete [] decrypted; | 1501 | delete [] decrypted; |
1446 | return e_cryptNotImpl; | 1502 | return e_cryptNotImpl; |
1447 | } } | 1503 | } } |
1448 | delete [] encrypted; | 1504 | delete [] encrypted; |
1449 | #ifndef PWM_EMBEDDED | 1505 | #ifndef PWM_EMBEDDED |
1450 | d->assign(reinterpret_cast<const char *>(decrypted), | 1506 | d->assign(reinterpret_cast<const char *>(decrypted), |
1451 | static_cast<string::size_type>(cryptLen)); | 1507 | static_cast<string::size_type>(cryptLen)); |
1452 | #else | 1508 | #else |
1453 | d->assign((const char *)(decrypted), | 1509 | d->assign((const char *)(decrypted), |
1454 | (string::size_type)(cryptLen)); | 1510 | (string::size_type)(cryptLen)); |
1455 | #endif | 1511 | #endif |
1456 | delete [] decrypted; | 1512 | delete [] decrypted; |
1457 | if (algo == PWM_CRYPT_BLOWFISH) { | 1513 | if (algo == PWM_CRYPT_BLOWFISH) { |
1458 | if (!Blowfish::unpadNull(d)) { | 1514 | if (!Blowfish::unpadNull(d)) { |
1459 | BUG(); | 1515 | BUG(); |
1460 | return e_readFile; | 1516 | return e_readFile; |
1461 | } | 1517 | } |
1462 | } | 1518 | } |
1463 | return e_success; | 1519 | return e_success; |
1464 | } | 1520 | } |
1465 | 1521 | ||
1466 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1522 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1467 | const string *dataStream) | 1523 | const string *dataStream) |
1468 | { | 1524 | { |
1469 | PWM_ASSERT(dataHash); | 1525 | PWM_ASSERT(dataHash); |
1470 | PWM_ASSERT(dataStream); | 1526 | PWM_ASSERT(dataStream); |
1471 | switch(dataHashType) { | 1527 | switch(dataHashType) { |
1472 | case PWM_HASH_SHA1: { | 1528 | case PWM_HASH_SHA1: { |
1473 | Sha1 hash; | 1529 | Sha1 hash; |
1474 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1530 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1475 | string ret = hash.sha1_read(); | 1531 | string ret = hash.sha1_read(); |
1476 | if (ret != *dataHash) | 1532 | if (ret != *dataHash) |
1477 | return e_fileCorrupt; | 1533 | return e_fileCorrupt; |
1478 | break; | 1534 | break; |
1479 | } | 1535 | } |
1480 | case PWM_HASH_SHA256: | 1536 | case PWM_HASH_SHA256: |
1481 | /*... fall through */ | 1537 | /*... fall through */ |
1482 | case PWM_HASH_SHA384: | 1538 | case PWM_HASH_SHA384: |
1483 | case PWM_HASH_SHA512: | 1539 | case PWM_HASH_SHA512: |
1484 | case PWM_HASH_MD5: | 1540 | case PWM_HASH_MD5: |
1485 | case PWM_HASH_RMD160: | 1541 | case PWM_HASH_RMD160: |
1486 | case PWM_HASH_TIGER: { | 1542 | case PWM_HASH_TIGER: { |
1487 | if (!LibGCryptIf::available()) | 1543 | if (!LibGCryptIf::available()) |
1488 | return e_hashNotImpl; | 1544 | return e_hashNotImpl; |
1489 | LibGCryptIf gc; | 1545 | LibGCryptIf gc; |
1490 | PwMerror err; | 1546 | PwMerror err; |
1491 | unsigned char *buf; | 1547 | unsigned char *buf; |
1492 | size_t hashLen; | 1548 | size_t hashLen; |
1493 | err = gc.hash(&buf, | 1549 | err = gc.hash(&buf, |
1494 | &hashLen, | 1550 | &hashLen, |
1495 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1551 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1496 | dataStream->length(), | 1552 | dataStream->length(), |
1497 | dataHashType); | 1553 | dataHashType); |
1498 | if (err != e_success) | 1554 | if (err != e_success) |
1499 | return e_hashNotImpl; | 1555 | return e_hashNotImpl; |
1500 | string calcHash(reinterpret_cast<const char *>(buf), | 1556 | string calcHash(reinterpret_cast<const char *>(buf), |
1501 | static_cast<string::size_type>(hashLen)); | 1557 | static_cast<string::size_type>(hashLen)); |
1502 | delete [] buf; | 1558 | delete [] buf; |
1503 | if (calcHash != *dataHash) | 1559 | if (calcHash != *dataHash) |
1504 | return e_fileCorrupt; | 1560 | return e_fileCorrupt; |
1505 | break; | 1561 | break; |
1506 | } | 1562 | } |
1507 | default: | 1563 | default: |
1508 | return e_hashNotImpl; | 1564 | return e_hashNotImpl; |
1509 | } | 1565 | } |
1510 | return e_success; | 1566 | return e_success; |
1511 | } | 1567 | } |
1512 | 1568 | ||
1513 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1569 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1514 | bool lock) | 1570 | bool lock) |
1515 | { | 1571 | { |
1516 | if (index >= numEntries(category)) { | 1572 | if (index >= numEntries(category)) { |
1517 | BUG(); | 1573 | BUG(); |
1518 | return false; | 1574 | return false; |
1519 | } | 1575 | } |
1520 | if (lock == dti.dta[category].d[index].lockStat) | 1576 | if (lock == dti.dta[category].d[index].lockStat) |
1521 | return true; | 1577 | return true; |
1522 | 1578 | ||
1523 | if (!lock && currentPw != "") { | 1579 | if (!lock && currentPw != "") { |
1524 | // "unlocking" and "password is already set" | 1580 | // "unlocking" and "password is already set" |
1525 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1581 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1526 | // unlocking without pw not allowed | 1582 | // unlocking without pw not allowed |
1527 | QString pw; | 1583 | QString pw; |
1528 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1584 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1529 | if (pw != "") { | 1585 | if (pw != "") { |
1530 | if (pw != currentPw) { | 1586 | if (pw != currentPw) { |
1531 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1587 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1532 | return false; | 1588 | return false; |
1533 | } else { | 1589 | } else { |
1534 | timer()->start(DocTimer::id_mpwTimer); | 1590 | timer()->start(DocTimer::id_mpwTimer); |
1535 | } | 1591 | } |
1536 | } else { | 1592 | } else { |
1537 | return false; | 1593 | return false; |
1538 | } | 1594 | } |
1539 | } else { | 1595 | } else { |
1540 | timer()->start(DocTimer::id_mpwTimer); | 1596 | timer()->start(DocTimer::id_mpwTimer); |
1541 | } | 1597 | } |
1542 | } | 1598 | } |
1543 | 1599 | ||
1544 | dti.dta[category].d[index].lockStat = lock; | 1600 | dti.dta[category].d[index].lockStat = lock; |
1545 | dti.dta[category].d[index].rev++; // increment revision counter. | 1601 | dti.dta[category].d[index].rev++; // increment revision counter. |
1546 | 1602 | ||
1547 | emitDataChanged(this); | 1603 | emitDataChanged(this); |
1548 | if (!lock) | 1604 | if (!lock) |
1549 | timer()->start(DocTimer::id_autoLockTimer); | 1605 | timer()->start(DocTimer::id_autoLockTimer); |
1550 | 1606 | ||
1551 | return true; | 1607 | return true; |
1552 | 1608 | ||
1553 | } | 1609 | } |
1554 | 1610 | ||
1555 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1611 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1556 | bool lock) | 1612 | bool lock) |
1557 | { | 1613 | { |
1558 | unsigned int cat = 0; | 1614 | unsigned int cat = 0; |
1559 | 1615 | ||
1560 | if (!findCategory(category, &cat)) { | 1616 | if (!findCategory(category, &cat)) { |
1561 | BUG(); | 1617 | BUG(); |
1562 | return false; | 1618 | return false; |
1563 | } | 1619 | } |
1564 | 1620 | ||
1565 | return lockAt(cat, index, lock); | 1621 | return lockAt(cat, index, lock); |
1566 | } | 1622 | } |
1567 | 1623 | ||
1568 | bool PwMDoc::lockAll(bool lock) | 1624 | bool PwMDoc::lockAll(bool lock) |
1569 | { | 1625 | { |
1570 | if (!lock && isDeepLocked()) { | 1626 | if (!lock && isDeepLocked()) { |
1571 | PwMerror ret; | 1627 | PwMerror ret; |
1572 | ret = deepLock(false); | 1628 | ret = deepLock(false); |
1573 | if (ret != e_success) | 1629 | if (ret != e_success) |
1574 | return false; | 1630 | return false; |
1575 | return true; | 1631 | return true; |
1576 | } | 1632 | } |
1577 | if (isDocEmpty()) { | 1633 | if (isDocEmpty()) { |
1578 | return true; | 1634 | return true; |
1579 | } | 1635 | } |
1580 | if (!lock && currentPw != "") { | 1636 | if (!lock && currentPw != "") { |
1581 | // unlocking and password is already set | 1637 | // unlocking and password is already set |
1582 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1638 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1583 | // unlocking without pw not allowed | 1639 | // unlocking without pw not allowed |
1584 | QString pw; | 1640 | QString pw; |
1585 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1641 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1586 | if (pw != "") { | 1642 | if (pw != "") { |
1587 | if (pw != currentPw) { | 1643 | if (pw != currentPw) { |
1588 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1644 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1589 | return false; | 1645 | return false; |
1590 | } else { | 1646 | } else { |
1591 | timer()->start(DocTimer::id_mpwTimer); | 1647 | timer()->start(DocTimer::id_mpwTimer); |
1592 | } | 1648 | } |
1593 | } else { | 1649 | } else { |
1594 | return false; | 1650 | return false; |
1595 | } | 1651 | } |
1596 | } else { | 1652 | } else { |
1597 | timer()->start(DocTimer::id_mpwTimer); | 1653 | timer()->start(DocTimer::id_mpwTimer); |
1598 | } | 1654 | } |
1599 | } | 1655 | } |
1600 | 1656 | ||
1601 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1657 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1602 | catEnd = dti.dta.end(), | 1658 | catEnd = dti.dta.end(), |
1603 | catI = catBegin; | 1659 | catI = catBegin; |
1604 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1660 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1605 | while (catI != catEnd) { | 1661 | while (catI != catEnd) { |
1606 | entrBegin = catI->d.begin(); | 1662 | entrBegin = catI->d.begin(); |
1607 | entrEnd = catI->d.end(); | 1663 | entrEnd = catI->d.end(); |
1608 | entrI = entrBegin; | 1664 | entrI = entrBegin; |
1609 | while (entrI != entrEnd) { | 1665 | while (entrI != entrEnd) { |
1610 | entrI->lockStat = lock; | 1666 | entrI->lockStat = lock; |
1611 | entrI->rev++; // increment revision counter. | 1667 | entrI->rev++; // increment revision counter. |
1612 | ++entrI; | 1668 | ++entrI; |
1613 | } | 1669 | } |
1614 | ++catI; | 1670 | ++catI; |
1615 | } | 1671 | } |
1616 | 1672 | ||
1617 | emitDataChanged(this); | 1673 | emitDataChanged(this); |
1618 | if (lock) | 1674 | if (lock) |
1619 | timer()->stop(DocTimer::id_autoLockTimer); | 1675 | timer()->stop(DocTimer::id_autoLockTimer); |
1620 | else | 1676 | else |
1621 | timer()->start(DocTimer::id_autoLockTimer); | 1677 | timer()->start(DocTimer::id_autoLockTimer); |
1622 | 1678 | ||
1623 | return true; | 1679 | return true; |
1624 | } | 1680 | } |
1625 | 1681 | ||
1626 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1682 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1627 | { | 1683 | { |
1628 | unsigned int cat = 0; | 1684 | unsigned int cat = 0; |
1629 | 1685 | ||
1630 | if (!findCategory(category, &cat)) { | 1686 | if (!findCategory(category, &cat)) { |
1631 | BUG(); | 1687 | BUG(); |
1632 | return false; | 1688 | return false; |
1633 | } | 1689 | } |
1634 | 1690 | ||
1635 | return isLocked(cat, index); | 1691 | return isLocked(cat, index); |
1636 | } | 1692 | } |
1637 | 1693 | ||
1638 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1694 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1639 | { | 1695 | { |
1640 | static vector< vector<bool> > *oldLockStates = 0; | 1696 | static vector< vector<bool> > *oldLockStates = 0; |
1641 | static bool wasDeepLocked; | 1697 | static bool wasDeepLocked; |
1642 | 1698 | ||
1643 | if (revert) {// revert the unlocking | 1699 | if (revert) {// revert the unlocking |
1644 | if (oldLockStates) { | 1700 | if (oldLockStates) { |
1645 | /* we actually _have_ unlocked something, because | 1701 | /* we actually _have_ unlocked something, because |
1646 | * we have allocated space for the oldLockStates. | 1702 | * we have allocated space for the oldLockStates. |
1647 | * So, go on and revert them! | 1703 | * So, go on and revert them! |
1648 | */ | 1704 | */ |
1649 | if (wasDeepLocked) { | 1705 | if (wasDeepLocked) { |
1650 | PwMerror ret = deepLock(true); | 1706 | PwMerror ret = deepLock(true); |
1651 | if (ret == e_success) { | 1707 | if (ret == e_success) { |
1652 | /* deep-lock succeed. We are save. | 1708 | /* deep-lock succeed. We are save. |
1653 | * (but if it failed, just go on | 1709 | * (but if it failed, just go on |
1654 | * lock them normally) | 1710 | * lock them normally) |
1655 | */ | 1711 | */ |
1656 | delete_and_null(oldLockStates); | 1712 | delete_and_null(oldLockStates); |
1657 | timer()->start(DocTimer::id_autoLockTimer); | 1713 | timer()->start(DocTimer::id_autoLockTimer); |
1658 | printDebug("tempoary unlocking of dta " | 1714 | printDebug("tempoary unlocking of dta " |
1659 | "reverted by deep-locking."); | 1715 | "reverted by deep-locking."); |
1660 | return true; | 1716 | return true; |
1661 | } | 1717 | } |
1662 | printDebug("deep-lock failed while reverting! " | 1718 | printDebug("deep-lock failed while reverting! " |
1663 | "Falling back to normal-lock."); | 1719 | "Falling back to normal-lock."); |
1664 | } | 1720 | } |
1665 | if (unlikely(!wasDeepLocked && | 1721 | if (unlikely(!wasDeepLocked && |
1666 | numCategories() != oldLockStates->size())) { | 1722 | numCategories() != oldLockStates->size())) { |
1667 | /* DOH! We have modified "dta" while | 1723 | /* DOH! We have modified "dta" while |
1668 | * it was unlocked tempoary. DON'T DO THIS! | 1724 | * it was unlocked tempoary. DON'T DO THIS! |
1669 | */ | 1725 | */ |
1670 | BUG(); | 1726 | BUG(); |
1671 | delete_and_null(oldLockStates); | 1727 | delete_and_null(oldLockStates); |
1672 | timer()->start(DocTimer::id_autoLockTimer); | 1728 | timer()->start(DocTimer::id_autoLockTimer); |
1673 | return false; | 1729 | return false; |
1674 | } | 1730 | } |
1675 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1731 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1676 | catEnd = dti.dta.end(), | 1732 | catEnd = dti.dta.end(), |
1677 | catI = catBegin; | 1733 | catI = catBegin; |
1678 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1734 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1679 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1735 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1680 | vector<bool>::iterator oldEntrStatBegin, | 1736 | vector<bool>::iterator oldEntrStatBegin, |
1681 | oldEntrStatEnd, | 1737 | oldEntrStatEnd, |
1682 | oldEntrStatI; | 1738 | oldEntrStatI; |
1683 | while (catI != catEnd) { | 1739 | while (catI != catEnd) { |
1684 | entrBegin = catI->d.begin(); | 1740 | entrBegin = catI->d.begin(); |
1685 | entrEnd = catI->d.end(); | 1741 | entrEnd = catI->d.end(); |
1686 | entrI = entrBegin; | 1742 | entrI = entrBegin; |
1687 | if (likely(!wasDeepLocked)) { | 1743 | if (likely(!wasDeepLocked)) { |
1688 | oldEntrStatBegin = oldCatStatI->begin(); | 1744 | oldEntrStatBegin = oldCatStatI->begin(); |
1689 | oldEntrStatEnd = oldCatStatI->end(); | 1745 | oldEntrStatEnd = oldCatStatI->end(); |
1690 | oldEntrStatI = oldEntrStatBegin; | 1746 | oldEntrStatI = oldEntrStatBegin; |
1691 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1747 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1692 | /* DOH! We have modified "dta" while | 1748 | /* DOH! We have modified "dta" while |
1693 | * it was unlocked tempoary. DON'T DO THIS! | 1749 | * it was unlocked tempoary. DON'T DO THIS! |
1694 | */ | 1750 | */ |
1695 | BUG(); | 1751 | BUG(); |
1696 | delete_and_null(oldLockStates); | 1752 | delete_and_null(oldLockStates); |
1697 | timer()->start(DocTimer::id_autoLockTimer); | 1753 | timer()->start(DocTimer::id_autoLockTimer); |
1698 | return false; | 1754 | return false; |
1699 | } | 1755 | } |
1700 | } | 1756 | } |
1701 | while (entrI != entrEnd) { | 1757 | while (entrI != entrEnd) { |
1702 | if (wasDeepLocked) { | 1758 | if (wasDeepLocked) { |
1703 | /* this is an error-fallback if | 1759 | /* this is an error-fallback if |
1704 | * deeplock didn't succeed | 1760 | * deeplock didn't succeed |
1705 | */ | 1761 | */ |
1706 | entrI->lockStat = true; | 1762 | entrI->lockStat = true; |
1707 | } else { | 1763 | } else { |
1708 | entrI->lockStat = *oldEntrStatI; | 1764 | entrI->lockStat = *oldEntrStatI; |
1709 | } | 1765 | } |
1710 | ++entrI; | 1766 | ++entrI; |
1711 | if (likely(!wasDeepLocked)) | 1767 | if (likely(!wasDeepLocked)) |
1712 | ++oldEntrStatI; | 1768 | ++oldEntrStatI; |
1713 | } | 1769 | } |
1714 | ++catI; | 1770 | ++catI; |
1715 | if (likely(!wasDeepLocked)) | 1771 | if (likely(!wasDeepLocked)) |
1716 | ++oldCatStatI; | 1772 | ++oldCatStatI; |
1717 | } | 1773 | } |
1718 | delete_and_null(oldLockStates); | 1774 | delete_and_null(oldLockStates); |
1719 | if (unlikely(wasDeepLocked)) { | 1775 | if (unlikely(wasDeepLocked)) { |
1720 | /* error fallback... */ | 1776 | /* error fallback... */ |
1721 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1777 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1722 | emitDataChanged(this); | 1778 | emitDataChanged(this); |
1723 | printDebug("WARNING: unlockAll_tempoary(true) " | 1779 | printDebug("WARNING: unlockAll_tempoary(true) " |
1724 | "deeplock fallback!"); | 1780 | "deeplock fallback!"); |
1725 | } | 1781 | } |
1726 | printDebug("tempoary unlocking of dta reverted."); | 1782 | printDebug("tempoary unlocking of dta reverted."); |
1727 | } else { | 1783 | } else { |
1728 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1784 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1729 | } | 1785 | } |
1730 | timer()->start(DocTimer::id_autoLockTimer); | 1786 | timer()->start(DocTimer::id_autoLockTimer); |
1731 | } else {// unlock all data tempoary | 1787 | } else {// unlock all data tempoary |
1732 | if (unlikely(oldLockStates != 0)) { | 1788 | if (unlikely(oldLockStates != 0)) { |
1733 | /* DOH! We have already unlocked the data tempoarly. | 1789 | /* DOH! We have already unlocked the data tempoarly. |
1734 | * No need to do it twice. ;) | 1790 | * No need to do it twice. ;) |
1735 | */ | 1791 | */ |
1736 | BUG(); | 1792 | BUG(); |
1737 | return false; | 1793 | return false; |
1738 | } | 1794 | } |
1739 | wasDeepLocked = false; | 1795 | wasDeepLocked = false; |
1740 | bool mustUnlock = false; | 1796 | bool mustUnlock = false; |
1741 | if (isDeepLocked()) { | 1797 | if (isDeepLocked()) { |
1742 | PwMerror ret; | 1798 | PwMerror ret; |
1743 | while (1) { | 1799 | while (1) { |
1744 | ret = deepLock(false); | 1800 | ret = deepLock(false); |
1745 | if (ret == e_success) { | 1801 | if (ret == e_success) { |
1746 | break; | 1802 | break; |
1747 | } else if (ret == e_wrongPw) { | 1803 | } else if (ret == e_wrongPw) { |
1748 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1804 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1749 | } else { | 1805 | } else { |
1750 | printDebug("deep-unlocking failed while " | 1806 | printDebug("deep-unlocking failed while " |
1751 | "tempoary unlocking!"); | 1807 | "tempoary unlocking!"); |
1752 | return false; | 1808 | return false; |
1753 | } | 1809 | } |
1754 | } | 1810 | } |
1755 | wasDeepLocked = true; | 1811 | wasDeepLocked = true; |
1756 | mustUnlock = true; | 1812 | mustUnlock = true; |
1757 | } else { | 1813 | } else { |
1758 | // first check if it's needed to unlock some entries | 1814 | // first check if it's needed to unlock some entries |
1759 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1815 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1760 | catEnd = dti.dta.end(), | 1816 | catEnd = dti.dta.end(), |
1761 | catI = catBegin; | 1817 | catI = catBegin; |
1762 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1818 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1763 | while (catI != catEnd) { | 1819 | while (catI != catEnd) { |
1764 | entrBegin = catI->d.begin(); | 1820 | entrBegin = catI->d.begin(); |
1765 | entrEnd = catI->d.end(); | 1821 | entrEnd = catI->d.end(); |
1766 | entrI = entrBegin; | 1822 | entrI = entrBegin; |
1767 | while (entrI != entrEnd) { | 1823 | while (entrI != entrEnd) { |
1768 | if (entrI->lockStat == true) { | 1824 | if (entrI->lockStat == true) { |
1769 | mustUnlock = true; | 1825 | mustUnlock = true; |
1770 | break; | 1826 | break; |
1771 | } | 1827 | } |
1772 | ++entrI; | 1828 | ++entrI; |
1773 | } | 1829 | } |
1774 | if (mustUnlock) | 1830 | if (mustUnlock) |
1775 | break; | 1831 | break; |
1776 | ++catI; | 1832 | ++catI; |
1777 | } | 1833 | } |
1778 | } | 1834 | } |
1779 | if (!mustUnlock) { | 1835 | if (!mustUnlock) { |
1780 | // nothing to do. | 1836 | // nothing to do. |
1781 | timer()->stop(DocTimer::id_autoLockTimer); | 1837 | timer()->stop(DocTimer::id_autoLockTimer); |
1782 | printDebug("unlockAll_tempoary(): nothing to do."); | 1838 | printDebug("unlockAll_tempoary(): nothing to do."); |
1783 | return true; | 1839 | return true; |
1784 | } else if (!wasDeepLocked) { | 1840 | } else if (!wasDeepLocked) { |
1785 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1841 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1786 | currentPw != "") { | 1842 | currentPw != "") { |
1787 | /* we can't unlock without mpw, so | 1843 | /* we can't unlock without mpw, so |
1788 | * we need to ask for it. | 1844 | * we need to ask for it. |
1789 | */ | 1845 | */ |
1790 | QString pw; | 1846 | QString pw; |
1791 | while (1) { | 1847 | while (1) { |
1792 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1848 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1793 | if (pw == "") { | 1849 | if (pw == "") { |
1794 | return false; | 1850 | return false; |
1795 | } else if (pw == currentPw) { | 1851 | } else if (pw == currentPw) { |
1796 | break; | 1852 | break; |
1797 | } | 1853 | } |
1798 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1854 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1799 | } | 1855 | } |
1800 | } | 1856 | } |
1801 | } | 1857 | } |
1802 | timer()->stop(DocTimer::id_autoLockTimer); | 1858 | timer()->stop(DocTimer::id_autoLockTimer); |
1803 | oldLockStates = new vector< vector<bool> >; | 1859 | oldLockStates = new vector< vector<bool> >; |
1804 | vector<bool> tmp_vec; | 1860 | vector<bool> tmp_vec; |
1805 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1861 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1806 | catEnd = dti.dta.end(), | 1862 | catEnd = dti.dta.end(), |
1807 | catI = catBegin; | 1863 | catI = catBegin; |
1808 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1864 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1809 | while (catI != catEnd) { | 1865 | while (catI != catEnd) { |
1810 | entrBegin = catI->d.begin(); | 1866 | entrBegin = catI->d.begin(); |
1811 | entrEnd = catI->d.end(); | 1867 | entrEnd = catI->d.end(); |
1812 | entrI = entrBegin; | 1868 | entrI = entrBegin; |
1813 | while (entrI != entrEnd) { | 1869 | while (entrI != entrEnd) { |
1814 | if (!wasDeepLocked) { | 1870 | if (!wasDeepLocked) { |
1815 | tmp_vec.push_back(entrI->lockStat); | 1871 | tmp_vec.push_back(entrI->lockStat); |
1816 | } | 1872 | } |
1817 | entrI->lockStat = false; | 1873 | entrI->lockStat = false; |
1818 | ++entrI; | 1874 | ++entrI; |
1819 | } | 1875 | } |
1820 | if (!wasDeepLocked) { | 1876 | if (!wasDeepLocked) { |
1821 | oldLockStates->push_back(tmp_vec); | 1877 | oldLockStates->push_back(tmp_vec); |
1822 | tmp_vec.clear(); | 1878 | tmp_vec.clear(); |
1823 | } | 1879 | } |
1824 | ++catI; | 1880 | ++catI; |
1825 | } | 1881 | } |
1826 | printDebug("tempoary unlocked dta."); | 1882 | printDebug("tempoary unlocked dta."); |
1827 | } | 1883 | } |
1828 | 1884 | ||
1829 | return true; | 1885 | return true; |
1830 | } | 1886 | } |
1831 | 1887 | ||
1832 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1888 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1833 | { | 1889 | { |
1834 | PwMerror ret; | 1890 | PwMerror ret; |
1835 | /* NOTE: saveDoc() depends on this function to return | 1891 | /* NOTE: saveDoc() depends on this function to return |
1836 | * e_success if saveToFile == false | 1892 | * e_success if saveToFile == false |
1837 | */ | 1893 | */ |
1838 | 1894 | ||
1839 | if (lock) { | 1895 | if (lock) { |
1840 | if (isDeepLocked()) | 1896 | if (isDeepLocked()) |
1841 | return e_lock; | 1897 | return e_lock; |
1842 | if (saveToFile) { | 1898 | if (saveToFile) { |
1843 | if (isDocEmpty()) | 1899 | if (isDocEmpty()) |
1844 | return e_docIsEmpty; | 1900 | return e_docIsEmpty; |
1845 | ret = saveDoc(conf()->confGlobCompression()); | 1901 | ret = saveDoc(conf()->confGlobCompression()); |
1846 | if (ret == e_filename) { | 1902 | if (ret == e_filename) { |
1847 | /* the doc wasn't saved to a file | 1903 | /* the doc wasn't saved to a file |
1848 | * by the user, yet. | 1904 | * by the user, yet. |
1849 | */ | 1905 | */ |
1850 | cantDeeplock_notSavedMsgBox(); | 1906 | cantDeeplock_notSavedMsgBox(); |
1851 | return e_docNotSaved; | 1907 | return e_docNotSaved; |
1852 | } else if (ret != e_success) { | 1908 | } else if (ret != e_success) { |
1853 | return e_lock; | 1909 | return e_lock; |
1854 | } | 1910 | } |
1855 | } | 1911 | } |
1856 | timer()->stop(DocTimer::id_autoLockTimer); | 1912 | timer()->stop(DocTimer::id_autoLockTimer); |
1857 | clearDoc(); | 1913 | clearDoc(); |
1858 | PwMDataItem d; | 1914 | PwMDataItem d; |
1859 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1915 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1860 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1916 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1861 | d.listViewPos = 0; | 1917 | d.listViewPos = 0; |
1862 | addEntry(DEFAULT_CATEGORY, &d, true); | 1918 | addEntry(DEFAULT_CATEGORY, &d, true); |
1863 | lockAt(DEFAULT_CATEGORY, 0, true); | 1919 | lockAt(DEFAULT_CATEGORY, 0, true); |
1864 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1920 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1865 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1921 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1866 | } else { | 1922 | } else { |
1867 | if (!isDeepLocked()) | 1923 | if (!isDeepLocked()) |
1868 | return e_lock; | 1924 | return e_lock; |
1869 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1925 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1870 | ? 0 : 1); | 1926 | ? 0 : 1); |
1871 | if (ret == e_wrongPw) { | 1927 | if (ret == e_wrongPw) { |
1872 | return e_wrongPw; | 1928 | return e_wrongPw; |
1873 | } else if (ret != e_success) { | 1929 | } else if (ret != e_success) { |
1874 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1930 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1875 | + tostr(static_cast<int>(ret))); | 1931 | + tostr(static_cast<int>(ret))); |
1876 | return e_lock; | 1932 | return e_lock; |
1877 | } | 1933 | } |
1878 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1934 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1879 | timer()->start(DocTimer::id_autoLockTimer); | 1935 | timer()->start(DocTimer::id_autoLockTimer); |
1880 | } | 1936 | } |
1881 | 1937 | ||
1882 | emitDataChanged(this); | 1938 | emitDataChanged(this); |
1883 | return e_success; | 1939 | return e_success; |
1884 | } | 1940 | } |
1885 | 1941 | ||
1886 | void PwMDoc::_deepUnlock() | 1942 | void PwMDoc::_deepUnlock() |
1887 | { | 1943 | { |
1888 | deepLock(false); | 1944 | deepLock(false); |
1889 | } | 1945 | } |
1890 | 1946 | ||
1891 | void PwMDoc::clearDoc() | 1947 | void PwMDoc::clearDoc() |
1892 | { | 1948 | { |
1893 | dti.clear(); | 1949 | dti.clear(); |
1894 | PwMCategoryItem d; | 1950 | PwMCategoryItem d; |
1895 | //US ENH: to initialize all members with meaningfull data. | 1951 | //US ENH: to initialize all members with meaningfull data. |
1896 | d.clear(); | 1952 | d.clear(); |
1897 | d.name = DEFAULT_CATEGORY.latin1(); | 1953 | d.name = DEFAULT_CATEGORY.latin1(); |
1898 | dti.dta.push_back(d); | 1954 | dti.dta.push_back(d); |
1899 | currentPw = ""; | 1955 | currentPw = ""; |
1900 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1956 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1901 | } | 1957 | } |
1902 | 1958 | ||
1903 | void PwMDoc::changeCurrentPw() | 1959 | void PwMDoc::changeCurrentPw() |
1904 | { | 1960 | { |
1905 | if (currentPw == "") | 1961 | if (currentPw == "") |
1906 | return; // doc hasn't been saved. No mpw available. | 1962 | return; // doc hasn't been saved. No mpw available. |
1907 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1963 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1908 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1964 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1909 | if (pw == "") | 1965 | if (pw == "") |
1910 | return; | 1966 | return; |
1911 | if (useChipcard) | 1967 | if (useChipcard) |
1912 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1968 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1913 | else | 1969 | else |
1914 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1970 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1915 | setCurrentPw(pw); | 1971 | setCurrentPw(pw); |
1916 | } | 1972 | } |
1917 | 1973 | ||
1918 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1974 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1919 | int pos) | 1975 | int pos) |
1920 | { | 1976 | { |
1921 | unsigned int cat = 0; | 1977 | unsigned int cat = 0; |
1922 | 1978 | ||
1923 | if (!findCategory(category, &cat)) { | 1979 | if (!findCategory(category, &cat)) { |
1924 | BUG(); | 1980 | BUG(); |
1925 | return; | 1981 | return; |
1926 | } | 1982 | } |
1927 | setListViewPos(cat, index, pos); | 1983 | setListViewPos(cat, index, pos); |
1928 | } | 1984 | } |
1929 | 1985 | ||
1930 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1986 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1931 | int pos) | 1987 | int pos) |
1932 | { | 1988 | { |
1933 | dti.dta[category].d[index].listViewPos = pos; | 1989 | dti.dta[category].d[index].listViewPos = pos; |
1934 | 1990 | ||
1935 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1991 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1936 | * get's called when it shouldn't. It's because PwMView assumes | 1992 | * get's called when it shouldn't. It's because PwMView assumes |
1937 | * the user resorted the UI on behalf of signal layoutChanged(). | 1993 | * the user resorted the UI on behalf of signal layoutChanged(). |
1938 | * This is somewhat broken and incorrect, but I've no other | 1994 | * This is somewhat broken and incorrect, but I've no other |
1939 | * solution for now. | 1995 | * solution for now. |
1940 | */ | 1996 | */ |
1941 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1997 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1942 | } | 1998 | } |
1943 | 1999 | ||
1944 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 2000 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1945 | { | 2001 | { |
1946 | unsigned int cat = 0; | 2002 | unsigned int cat = 0; |
1947 | 2003 | ||
1948 | if (!findCategory(category, &cat)) { | 2004 | if (!findCategory(category, &cat)) { |
1949 | BUG(); | 2005 | BUG(); |
1950 | return -1; | 2006 | return -1; |
1951 | } | 2007 | } |
1952 | 2008 | ||
1953 | return dti.dta[cat].d[index].listViewPos; | 2009 | return dti.dta[cat].d[index].listViewPos; |
1954 | } | 2010 | } |
1955 | 2011 | ||
1956 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 2012 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1957 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2013 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1958 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2014 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1959 | { | 2015 | { |
1960 | PWM_ASSERT(foundPositions); | 2016 | PWM_ASSERT(foundPositions); |
1961 | PWM_ASSERT(searchIn); | 2017 | PWM_ASSERT(searchIn); |
1962 | foundPositions->clear(); | 2018 | foundPositions->clear(); |
1963 | 2019 | ||
1964 | unsigned int i, entries = numEntries(category); | 2020 | unsigned int i, entries = numEntries(category); |
1965 | for (i = 0; i < entries; ++i) { | 2021 | for (i = 0; i < entries; ++i) { |
1966 | if (searchIn & SEARCH_IN_DESC) { | 2022 | if (searchIn & SEARCH_IN_DESC) { |
1967 | if (!compareString(find.desc, dti.dta[category].d[i].desc, | 2023 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1968 | caseSensitive, exactWordMatch)) { | 2024 | caseSensitive, exactWordMatch)) { |
1969 | continue; | 2025 | continue; |
1970 | } | 2026 | } |
1971 | } | 2027 | } |
1972 | if (searchIn & SEARCH_IN_NAME) { | 2028 | if (searchIn & SEARCH_IN_NAME) { |
1973 | if (!compareString(find.name, dti.dta[category].d[i].name, | 2029 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1974 | caseSensitive, exactWordMatch)) { | 2030 | caseSensitive, exactWordMatch)) { |
1975 | continue; | 2031 | continue; |
1976 | } | 2032 | } |
1977 | } | 2033 | } |
1978 | if (searchIn & SEARCH_IN_PW) { | 2034 | if (searchIn & SEARCH_IN_PW) { |
1979 | bool wasLocked = isLocked(category, i); | 2035 | bool wasLocked = isLocked(category, i); |
1980 | getDataChangedLock(); | 2036 | getDataChangedLock(); |
1981 | lockAt(category, i, false); | 2037 | lockAt(category, i, false); |
1982 | if (!compareString(find.pw, dti.dta[category].d[i].pw, | 2038 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1983 | caseSensitive, exactWordMatch)) { | 2039 | caseSensitive, exactWordMatch)) { |
1984 | lockAt(category, i, wasLocked); | 2040 | lockAt(category, i, wasLocked); |
1985 | putDataChangedLock(); | 2041 | putDataChangedLock(); |
1986 | continue; | 2042 | continue; |
1987 | } | 2043 | } |
1988 | lockAt(category, i, wasLocked); | 2044 | lockAt(category, i, wasLocked); |
1989 | putDataChangedLock(); | 2045 | putDataChangedLock(); |
1990 | } | 2046 | } |
1991 | if (searchIn & SEARCH_IN_COMMENT) { | 2047 | if (searchIn & SEARCH_IN_COMMENT) { |
1992 | if (!compareString(find.comment, dti.dta[category].d[i].comment, | 2048 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1993 | caseSensitive, exactWordMatch)) { | 2049 | caseSensitive, exactWordMatch)) { |
1994 | continue; | 2050 | continue; |
1995 | } | 2051 | } |
1996 | } | 2052 | } |
1997 | if (searchIn & SEARCH_IN_URL) { | 2053 | if (searchIn & SEARCH_IN_URL) { |
1998 | if (!compareString(find.url, dti.dta[category].d[i].url, | 2054 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1999 | caseSensitive, exactWordMatch)) { | 2055 | caseSensitive, exactWordMatch)) { |
2000 | continue; | 2056 | continue; |
2001 | } | 2057 | } |
2002 | } | 2058 | } |
2003 | if (searchIn & SEARCH_IN_LAUNCHER) { | 2059 | if (searchIn & SEARCH_IN_LAUNCHER) { |
2004 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, | 2060 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
2005 | caseSensitive, exactWordMatch)) { | 2061 | caseSensitive, exactWordMatch)) { |
2006 | continue; | 2062 | continue; |
2007 | } | 2063 | } |
2008 | } | 2064 | } |
2009 | 2065 | ||
2010 | // all selected "searchIn" matched. | 2066 | // all selected "searchIn" matched. |
2011 | foundPositions->push_back(i); | 2067 | foundPositions->push_back(i); |
2012 | if (breakAfterFound) | 2068 | if (breakAfterFound) |
2013 | break; | 2069 | break; |
2014 | } | 2070 | } |
2015 | 2071 | ||
2016 | if (sortByLvp && foundPositions->size() > 1) { | 2072 | if (sortByLvp && foundPositions->size() > 1) { |
2017 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 2073 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
2018 | unsigned int /* lvp-pos */> > tmp_vec; | 2074 | unsigned int /* lvp-pos */> > tmp_vec; |
2019 | 2075 | ||
2020 | unsigned int i, items = foundPositions->size(); | 2076 | unsigned int i, items = foundPositions->size(); |
2021 | pair<unsigned int, unsigned int> tmp_pair; | 2077 | pair<unsigned int, unsigned int> tmp_pair; |
2022 | for (i = 0; i < items; ++i) { | 2078 | for (i = 0; i < items; ++i) { |
2023 | tmp_pair.first = (*foundPositions)[i]; | 2079 | tmp_pair.first = (*foundPositions)[i]; |
2024 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; | 2080 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
2025 | tmp_vec.push_back(tmp_pair); | 2081 | tmp_vec.push_back(tmp_pair); |
2026 | } | 2082 | } |
2027 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 2083 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
2028 | foundPositions->clear(); | 2084 | foundPositions->clear(); |
2029 | for (i = 0; i < items; ++i) { | 2085 | for (i = 0; i < items; ++i) { |
2030 | foundPositions->push_back(tmp_vec[i].first); | 2086 | foundPositions->push_back(tmp_vec[i].first); |
2031 | } | 2087 | } |
2032 | } | 2088 | } |
2033 | } | 2089 | } |
2034 | 2090 | ||
2035 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2091 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2036 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2092 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2037 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2093 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2038 | { | 2094 | { |
2039 | PWM_ASSERT(foundPositions); | 2095 | PWM_ASSERT(foundPositions); |
2040 | unsigned int cat = 0; | 2096 | unsigned int cat = 0; |
2041 | 2097 | ||
2042 | if (!findCategory(category, &cat)) { | 2098 | if (!findCategory(category, &cat)) { |
2043 | foundPositions->clear(); | 2099 | foundPositions->clear(); |
2044 | return; | 2100 | return; |
2045 | } | 2101 | } |
2046 | 2102 | ||
2047 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2103 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2048 | caseSensitive, exactWordMatch, sortByLvp); | 2104 | caseSensitive, exactWordMatch, sortByLvp); |
2049 | } | 2105 | } |
2050 | 2106 | ||
2051 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2107 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2052 | bool exactWordMatch) | 2108 | bool exactWordMatch) |
2053 | { | 2109 | { |
2054 | QString _s1(s1.c_str()); | 2110 | QString _s1(s1.c_str()); |
2055 | QString _s2(s2.c_str()); | 2111 | QString _s2(s2.c_str()); |
2056 | if (!caseSensitive) { | 2112 | if (!caseSensitive) { |
2057 | _s1 = _s1.lower(); | 2113 | _s1 = _s1.lower(); |
2058 | _s2 = _s2.lower(); | 2114 | _s2 = _s2.lower(); |
2059 | } | 2115 | } |
2060 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2116 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2061 | return true; | 2117 | return true; |
2062 | return false; | 2118 | return false; |
2063 | } | 2119 | } |
2064 | 2120 | ||
2065 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2121 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2066 | { | 2122 | { |
2067 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2123 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2068 | end = dti.dta.end(); | 2124 | end = dti.dta.end(); |
2069 | while (i != end) { | 2125 | while (i != end) { |
2070 | if ((*i).name == name.latin1()) { | 2126 | if ((*i).name == name.latin1()) { |
2071 | if (index) { | 2127 | if (index) { |
2072 | *index = i - dti.dta.begin(); | 2128 | *index = i - dti.dta.begin(); |
2073 | } | 2129 | } |
2074 | return true; | 2130 | return true; |
2075 | } | 2131 | } |
2076 | ++i; | 2132 | ++i; |
2077 | } | 2133 | } |
2078 | return false; | 2134 | return false; |
2079 | } | 2135 | } |
2080 | 2136 | ||
2081 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2137 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2082 | { | 2138 | { |
2083 | unsigned int cat = 0; | 2139 | unsigned int cat = 0; |
2084 | 2140 | ||
2085 | if (!findCategory(category, &cat)) | 2141 | if (!findCategory(category, &cat)) |
2086 | return false; | 2142 | return false; |
2087 | 2143 | ||
2088 | return renameCategory(cat, newName); | 2144 | return renameCategory(cat, newName); |
2089 | } | 2145 | } |
2090 | 2146 | ||
2091 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2147 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2092 | bool dontFlagDirty) | 2148 | bool dontFlagDirty) |
2093 | { | 2149 | { |
2094 | if (category > numCategories() - 1) | 2150 | if (category > numCategories() - 1) |
2095 | return false; | 2151 | return false; |
2096 | 2152 | ||
2097 | dti.dta[category].name = newName.latin1(); | 2153 | dti.dta[category].name = newName.latin1(); |
2098 | if (!dontFlagDirty) | 2154 | if (!dontFlagDirty) |
2099 | flagDirty(); | 2155 | flagDirty(); |
2100 | 2156 | ||
2101 | return true; | 2157 | return true; |
2102 | } | 2158 | } |
2103 | 2159 | ||
2104 | bool PwMDoc::delCategory(const QString &category) | 2160 | bool PwMDoc::delCategory(const QString &category) |
2105 | { | 2161 | { |
2106 | unsigned int cat = 0; | 2162 | unsigned int cat = 0; |
2107 | 2163 | ||
2108 | if (!findCategory(category, &cat)) | 2164 | if (!findCategory(category, &cat)) |
2109 | return false; | 2165 | return false; |
2110 | 2166 | ||
2111 | return delCategory(cat); | 2167 | return delCategory(cat); |
2112 | } | 2168 | } |
2113 | 2169 | ||
2114 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2170 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2115 | { | 2171 | { |
2116 | if (category > numCategories() - 1) | 2172 | if (category > numCategories() - 1) |
2117 | return false; | 2173 | return false; |
2118 | 2174 | ||
2119 | // We don't delete it, if it is the last existing | 2175 | // We don't delete it, if it is the last existing |
2120 | // category! Instead we rename it to "Default". | 2176 | // category! Instead we rename it to "Default". |
2121 | if (numCategories() > 1) { | 2177 | if (numCategories() > 1) { |
2122 | dti.dta.erase(dti.dta.begin() + category); | 2178 | dti.dta.erase(dti.dta.begin() + category); |
2123 | } else { | 2179 | } else { |
2124 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2180 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2125 | return true; | 2181 | return true; |
2126 | } | 2182 | } |
2127 | if (!dontFlagDirty) | 2183 | if (!dontFlagDirty) |
2128 | flagDirty(); | 2184 | flagDirty(); |
2129 | 2185 | ||
2130 | return true; | 2186 | return true; |
2131 | } | 2187 | } |
2132 | 2188 | ||
2133 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2189 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2134 | { | 2190 | { |
2135 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), | 2191 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2136 | end = dti.dta.end(), | 2192 | end = dti.dta.end(), |
2137 | i = begin; | 2193 | i = begin; |
2138 | while (i != end) { | 2194 | while (i != end) { |
2139 | if (i->d.empty()) { | 2195 | if (i->d.empty()) { |
2140 | delCategory(begin - i, dontFlagDirty); | 2196 | delCategory(begin - i, dontFlagDirty); |
2141 | } | 2197 | } |
2142 | ++i; | 2198 | ++i; |
2143 | } | 2199 | } |
2144 | } | 2200 | } |
2145 | 2201 | ||
2146 | void PwMDoc::getCategoryList(vector<string> *list) | 2202 | void PwMDoc::getCategoryList(vector<string> *list) |
2147 | { | 2203 | { |
2148 | PWM_ASSERT(list); | 2204 | PWM_ASSERT(list); |
2149 | list->clear(); | 2205 | list->clear(); |
2150 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2206 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2151 | end = dti.dta.end(); | 2207 | end = dti.dta.end(); |
2152 | while (i != end) { | 2208 | while (i != end) { |
2153 | list->push_back(i->name); | 2209 | list->push_back(i->name); |
2154 | ++i; | 2210 | ++i; |
2155 | } | 2211 | } |
2156 | } | 2212 | } |
2157 | 2213 | ||
2158 | void PwMDoc::getCategoryList(QStringList *list) | 2214 | void PwMDoc::getCategoryList(QStringList *list) |
2159 | { | 2215 | { |
2160 | PWM_ASSERT(list); | 2216 | PWM_ASSERT(list); |
2161 | list->clear(); | 2217 | list->clear(); |
2162 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2218 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2163 | end = dti.dta.end(); | 2219 | end = dti.dta.end(); |
2164 | while (i != end) { | 2220 | while (i != end) { |
2165 | #ifndef PWM_EMBEDDED | 2221 | #ifndef PWM_EMBEDDED |
2166 | list->push_back(i->name.c_str()); | 2222 | list->push_back(i->name.c_str()); |
2167 | #else | 2223 | #else |
2168 | list->append(i->name.c_str()); | 2224 | list->append(i->name.c_str()); |
2169 | #endif | 2225 | #endif |
2170 | ++i; | 2226 | ++i; |
2171 | } | 2227 | } |
2172 | } | 2228 | } |
2173 | 2229 | ||
2174 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2230 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2175 | { | 2231 | { |
2176 | PWM_ASSERT(list); | 2232 | PWM_ASSERT(list); |
2177 | unsigned int cat = 0; | 2233 | unsigned int cat = 0; |
2178 | if (!findCategory(category, &cat)) { | 2234 | if (!findCategory(category, &cat)) { |
2179 | list->clear(); | 2235 | list->clear(); |
2180 | return; | 2236 | return; |
2181 | } | 2237 | } |
2182 | getEntryList(cat, list); | 2238 | getEntryList(cat, list); |
2183 | } | 2239 | } |
2184 | 2240 | ||
2185 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2241 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2186 | { | 2242 | { |
2187 | PWM_ASSERT(list); | 2243 | PWM_ASSERT(list); |
2188 | unsigned int cat = 0; | 2244 | unsigned int cat = 0; |
2189 | if (!findCategory(category, &cat)) { | 2245 | if (!findCategory(category, &cat)) { |
2190 | list->clear(); | 2246 | list->clear(); |
2191 | return; | 2247 | return; |
2192 | } | 2248 | } |
2193 | getEntryList(cat, list); | 2249 | getEntryList(cat, list); |
2194 | } | 2250 | } |
2195 | 2251 | ||
2196 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2252 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2197 | { | 2253 | { |
2198 | PWM_ASSERT(list); | 2254 | PWM_ASSERT(list); |
2199 | list->clear(); | 2255 | list->clear(); |
2200 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2256 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2201 | end = dti.dta[category].d.end(), | 2257 | end = dti.dta[category].d.end(), |
2202 | i = begin; | 2258 | i = begin; |
2203 | while (i != end) { | 2259 | while (i != end) { |
2204 | list->push_back(i->desc); | 2260 | list->push_back(i->desc); |
2205 | ++i; | 2261 | ++i; |
2206 | } | 2262 | } |
2207 | } | 2263 | } |
2208 | 2264 | ||
2209 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2265 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2210 | { | 2266 | { |
2211 | PWM_ASSERT(list); | 2267 | PWM_ASSERT(list); |
2212 | list->clear(); | 2268 | list->clear(); |
2213 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2269 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2214 | end = dti.dta[category].d.end(), | 2270 | end = dti.dta[category].d.end(), |
2215 | i = begin; | 2271 | i = begin; |
2216 | while (i != end) { | 2272 | while (i != end) { |
2217 | #ifndef PWM_EMBEDDED | 2273 | #ifndef PWM_EMBEDDED |
2218 | list->push_back(i->desc.c_str()); | 2274 | list->push_back(i->desc.c_str()); |
2219 | #else | 2275 | #else |
2220 | list->append(i->desc.c_str()); | 2276 | list->append(i->desc.c_str()); |
2221 | #endif | 2277 | #endif |
2222 | ++i; | 2278 | ++i; |
2223 | } | 2279 | } |
2224 | } | 2280 | } |
2225 | 2281 | ||
2226 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2282 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2227 | { | 2283 | { |
2228 | unsigned int cat = 0; | 2284 | unsigned int cat = 0; |
2229 | 2285 | ||
2230 | if (!findCategory(category, &cat)) | 2286 | if (!findCategory(category, &cat)) |
2231 | return false; | 2287 | return false; |
2232 | 2288 | ||
2233 | return execLauncher(cat, entryIndex); | 2289 | return execLauncher(cat, entryIndex); |
2234 | } | 2290 | } |
2235 | 2291 | ||
2236 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2292 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2237 | { | 2293 | { |
2238 | #ifndef _WIN32_ | 2294 | #ifndef _WIN32_ |
2239 | if (geteuid() == 0) { | 2295 | if (geteuid() == 0) { |
2240 | rootAlertMsgBox(); | 2296 | rootAlertMsgBox(); |
2241 | return false; | 2297 | return false; |
2242 | } | 2298 | } |
2243 | #endif | 2299 | #endif |
2244 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2300 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2245 | bool wasLocked = isLocked(category, entryIndex); | 2301 | bool wasLocked = isLocked(category, entryIndex); |
2246 | 2302 | ||
2247 | if (command.find("$p") != -1) { | 2303 | if (command.find("$p") != -1) { |
2248 | /* the user requested the password to be included | 2304 | /* the user requested the password to be included |
2249 | * into the command. We have to ask for the password, | 2305 | * into the command. We have to ask for the password, |
2250 | * if it's locked. We do that by unlocking the entry | 2306 | * if it's locked. We do that by unlocking the entry |
2251 | */ | 2307 | */ |
2252 | if (!lockAt(category, entryIndex, false)) | 2308 | if (!lockAt(category, entryIndex, false)) |
2253 | return false; | 2309 | return false; |
2254 | } | 2310 | } |
2255 | #ifndef PWM_EMBEDDED | 2311 | #ifndef PWM_EMBEDDED |
2256 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2312 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2257 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2313 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2258 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2314 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2259 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2315 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2260 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2316 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2261 | #else | 2317 | #else |
2262 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2318 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2263 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2319 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2264 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2320 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2265 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2321 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2266 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2322 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2267 | #endif | 2323 | #endif |
2268 | command.append(" &"); | 2324 | command.append(" &"); |
2269 | 2325 | ||
2270 | QString customXterm(conf()->confGlobXtermCommand()); | 2326 | QString customXterm(conf()->confGlobXtermCommand()); |
2271 | if (!customXterm.isEmpty()) | 2327 | if (!customXterm.isEmpty()) |
2272 | command = customXterm + " " + command; | 2328 | command = customXterm + " " + command; |
2273 | 2329 | ||
2274 | system(command.latin1()); | 2330 | system(command.latin1()); |
2275 | 2331 | ||
2276 | lockAt(category, entryIndex, wasLocked); | 2332 | lockAt(category, entryIndex, wasLocked); |
2277 | return true; | 2333 | return true; |
2278 | } | 2334 | } |
2279 | 2335 | ||
2280 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2336 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2281 | { | 2337 | { |
2282 | unsigned int cat = 0; | 2338 | unsigned int cat = 0; |
2283 | 2339 | ||
2284 | if (!findCategory(category, &cat)) | 2340 | if (!findCategory(category, &cat)) |
2285 | return false; | 2341 | return false; |
2286 | 2342 | ||
2287 | return goToURL(cat, entryIndex); | 2343 | return goToURL(cat, entryIndex); |
2288 | } | 2344 | } |
2289 | 2345 | ||
2290 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2346 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2291 | { | 2347 | { |
2292 | #ifndef _WIN32_ | 2348 | #ifndef _WIN32_ |
2293 | if (geteuid() == 0) { | 2349 | if (geteuid() == 0) { |
2294 | rootAlertMsgBox(); | 2350 | rootAlertMsgBox(); |
2295 | return false; | 2351 | return false; |
2296 | } | 2352 | } |
2297 | #endif | 2353 | #endif |
2298 | QString url(dti.dta[category].d[entryIndex].url.c_str()); | 2354 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2299 | if (url.isEmpty()) | 2355 | if (url.isEmpty()) |
2300 | return false; | 2356 | return false; |
2301 | 2357 | ||
2302 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2358 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2303 | if (!customBrowser.isEmpty()) { | 2359 | if (!customBrowser.isEmpty()) { |
2304 | browserProc.clearArguments(); | 2360 | browserProc.clearArguments(); |
2305 | browserProc << customBrowser << url; | 2361 | browserProc << customBrowser << url; |
2306 | if (browserProc.start(KProcess::DontCare)) | 2362 | if (browserProc.start(KProcess::DontCare)) |
2307 | return true; | 2363 | return true; |
2308 | } | 2364 | } |
2309 | 2365 | ||
2310 | browserProc.clearArguments(); | 2366 | browserProc.clearArguments(); |
2311 | browserProc << "konqueror" << url; | 2367 | browserProc << "konqueror" << url; |
2312 | if (browserProc.start(KProcess::DontCare)) | 2368 | if (browserProc.start(KProcess::DontCare)) |
2313 | return true; | 2369 | return true; |
2314 | 2370 | ||
2315 | browserProc.clearArguments(); | 2371 | browserProc.clearArguments(); |
2316 | browserProc << "mozilla" << url; | 2372 | browserProc << "mozilla" << url; |
2317 | if (browserProc.start(KProcess::DontCare)) | 2373 | if (browserProc.start(KProcess::DontCare)) |
2318 | return true; | 2374 | return true; |
2319 | 2375 | ||
2320 | browserProc.clearArguments(); | 2376 | browserProc.clearArguments(); |
2321 | browserProc << "opera" << url; | 2377 | browserProc << "opera" << url; |
2322 | if (browserProc.start(KProcess::DontCare)) | 2378 | if (browserProc.start(KProcess::DontCare)) |
2323 | return true; | 2379 | return true; |
2324 | return false; | 2380 | return false; |
2325 | } | 2381 | } |
2326 | 2382 | ||
2327 | PwMerror PwMDoc::exportToText(const QString *file) | 2383 | PwMerror PwMDoc::exportToText(const QString *file) |
2328 | { | 2384 | { |
2329 | PWM_ASSERT(file); | 2385 | PWM_ASSERT(file); |
2330 | if (QFile::exists(*file)) { | 2386 | if (QFile::exists(*file)) { |
2331 | if (!QFile::remove(*file)) | 2387 | if (!QFile::remove(*file)) |
2332 | return e_accessFile; | 2388 | return e_accessFile; |
2333 | } | 2389 | } |
2334 | QFile f(*file); | 2390 | QFile f(*file); |
2335 | if (!f.open(IO_ReadWrite)) | 2391 | if (!f.open(IO_ReadWrite)) |
2336 | return e_openFile; | 2392 | return e_openFile; |
2337 | 2393 | ||
2338 | if (!unlockAll_tempoary()) { | 2394 | if (!unlockAll_tempoary()) { |
2339 | f.close(); | 2395 | f.close(); |
2340 | return e_lock; | 2396 | return e_lock; |
2341 | } | 2397 | } |
2342 | 2398 | ||
2343 | // write header | 2399 | // write header |
2344 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2400 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2345 | header += PACKAGE_VER; | 2401 | header += PACKAGE_VER; |
2346 | header += i18n("\non ").latin1(); | 2402 | header += i18n("\non ").latin1(); |
2347 | QDate currDate = QDate::currentDate(); | 2403 | QDate currDate = QDate::currentDate(); |
2348 | QTime currTime = QTime::currentTime(); | 2404 | QTime currTime = QTime::currentTime(); |
2349 | 2405 | ||
2350 | #ifndef PWM_EMBEDDED | 2406 | #ifndef PWM_EMBEDDED |
2351 | header += currDate.toString("ddd MMMM d ").latin1(); | 2407 | header += currDate.toString("ddd MMMM d ").latin1(); |
2352 | header += currTime.toString("hh:mm:ss ").latin1(); | 2408 | header += currTime.toString("hh:mm:ss ").latin1(); |
2353 | #else | 2409 | #else |
2354 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2410 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2355 | bool ampm = KGlobal::locale()->use12Clock(); | 2411 | bool ampm = KGlobal::locale()->use12Clock(); |
2356 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2412 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2357 | KGlobal::locale()->setHore24Format(true); | 2413 | KGlobal::locale()->setHore24Format(true); |
2358 | 2414 | ||
2359 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); | 2415 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); |
2360 | header += KGlobal::locale()->formatTime(currTime, true).latin1(); | 2416 | header += KGlobal::locale()->formatTime(currTime, true).latin1(); |
2361 | KGlobal::locale()->setDateFormatShort(dfs); | 2417 | KGlobal::locale()->setDateFormatShort(dfs); |
2362 | KGlobal::locale()->setHore24Format(!ampm); | 2418 | KGlobal::locale()->setHore24Format(!ampm); |
2363 | 2419 | ||
2364 | #endif | 2420 | #endif |
2365 | header += tostr(currDate.year()); | 2421 | header += tostr(currDate.year()); |
2366 | header += "\n==============================\n\n"; | 2422 | header += "\n==============================\n\n"; |
2367 | 2423 | ||
2368 | 2424 | ||
2369 | #ifndef PWM_EMBEDDED | 2425 | #ifndef PWM_EMBEDDED |
2370 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2426 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2371 | unlockAll_tempoary(true); | 2427 | unlockAll_tempoary(true); |
2372 | f.close(); | 2428 | f.close(); |
2373 | return e_writeFile; | 2429 | return e_writeFile; |
2374 | } | 2430 | } |
2375 | #else | 2431 | #else |
2376 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2432 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2377 | unlockAll_tempoary(true); | 2433 | unlockAll_tempoary(true); |
2378 | f.close(); | 2434 | f.close(); |
2379 | return e_writeFile; | 2435 | return e_writeFile; |
2380 | } | 2436 | } |
2381 | #endif | 2437 | #endif |
2382 | unsigned int i, numCat = numCategories(); | 2438 | unsigned int i, numCat = numCategories(); |
2383 | unsigned int j, numEnt; | 2439 | unsigned int j, numEnt; |
2384 | string exp; | 2440 | string exp; |
2385 | for (i = 0; i < numCat; ++i) { | 2441 | for (i = 0; i < numCat; ++i) { |
2386 | numEnt = numEntries(i); | 2442 | numEnt = numEntries(i); |
2387 | 2443 | ||
2388 | exp = "\n== Category: "; | 2444 | exp = "\n== Category: "; |
2389 | exp += dti.dta[i].name; | 2445 | exp += dti.dta[i].name; |
2390 | exp += " ==\n"; | 2446 | exp += " ==\n"; |
2391 | #ifndef PWM_EMBEDDED | 2447 | #ifndef PWM_EMBEDDED |
2392 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2448 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2393 | unlockAll_tempoary(true); | 2449 | unlockAll_tempoary(true); |
2394 | f.close(); | 2450 | f.close(); |
2395 | return e_writeFile; | 2451 | return e_writeFile; |
2396 | } | 2452 | } |
2397 | #else | 2453 | #else |
2398 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2454 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2399 | unlockAll_tempoary(true); | 2455 | unlockAll_tempoary(true); |
2400 | f.close(); | 2456 | f.close(); |
2401 | return e_writeFile; | 2457 | return e_writeFile; |
2402 | } | 2458 | } |
2403 | #endif | 2459 | #endif |
2404 | for (j = 0; j < numEnt; ++j) { | 2460 | for (j = 0; j < numEnt; ++j) { |
2405 | exp = "\n-- "; | 2461 | exp = "\n-- "; |
2406 | exp += dti.dta[i].d[j].desc; | 2462 | exp += dti.dta[i].d[j].desc; |
2407 | exp += " --\n"; | 2463 | exp += " --\n"; |
2408 | 2464 | ||
2409 | exp += i18n("Username: ").latin1(); | 2465 | exp += i18n("Username: ").latin1(); |
2410 | exp += dti.dta[i].d[j].name; | 2466 | exp += dti.dta[i].d[j].name; |
2411 | exp += "\n"; | 2467 | exp += "\n"; |
2412 | 2468 | ||
2413 | exp += i18n("Password: ").latin1(); | 2469 | exp += i18n("Password: ").latin1(); |
2414 | exp += dti.dta[i].d[j].pw; | 2470 | exp += dti.dta[i].d[j].pw; |
2415 | exp += "\n"; | 2471 | exp += "\n"; |
2416 | 2472 | ||
2417 | exp += i18n("Comment: ").latin1(); | 2473 | exp += i18n("Comment: ").latin1(); |
2418 | exp += dti.dta[i].d[j].comment; | 2474 | exp += dti.dta[i].d[j].comment; |
2419 | exp += "\n"; | 2475 | exp += "\n"; |
2420 | 2476 | ||
2421 | exp += i18n("URL: ").latin1(); | 2477 | exp += i18n("URL: ").latin1(); |
2422 | exp += dti.dta[i].d[j].url; | 2478 | exp += dti.dta[i].d[j].url; |
2423 | exp += "\n"; | 2479 | exp += "\n"; |
2424 | 2480 | ||
2425 | exp += i18n("Launcher: ").latin1(); | 2481 | exp += i18n("Launcher: ").latin1(); |
2426 | exp += dti.dta[i].d[j].launcher; | 2482 | exp += dti.dta[i].d[j].launcher; |
2427 | exp += "\n"; | 2483 | exp += "\n"; |
2428 | 2484 | ||
2429 | #ifndef PWM_EMBEDDED | 2485 | #ifndef PWM_EMBEDDED |
2430 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2486 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2431 | unlockAll_tempoary(true); | 2487 | unlockAll_tempoary(true); |
2432 | f.close(); | 2488 | f.close(); |
2433 | return e_writeFile; | 2489 | return e_writeFile; |
2434 | } | 2490 | } |
2435 | #else | 2491 | #else |
2436 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2492 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2437 | unlockAll_tempoary(true); | 2493 | unlockAll_tempoary(true); |
2438 | f.close(); | 2494 | f.close(); |
2439 | return e_writeFile; | 2495 | return e_writeFile; |
2440 | } | 2496 | } |
2441 | #endif | 2497 | #endif |
2442 | } | 2498 | } |
2443 | } | 2499 | } |
2444 | unlockAll_tempoary(true); | 2500 | unlockAll_tempoary(true); |
2445 | f.close(); | 2501 | f.close(); |
2446 | 2502 | ||
2447 | return e_success; | 2503 | return e_success; |
2448 | } | 2504 | } |
2449 | 2505 | ||
2450 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2506 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2451 | { | 2507 | { |
2452 | PWM_ASSERT(file); | 2508 | PWM_ASSERT(file); |
2453 | if (format == 0) | 2509 | if (format == 0) |
2454 | return importText_PwM(file); | 2510 | return importText_PwM(file); |
2455 | else if (format == -1) { | 2511 | else if (format == -1) { |
2456 | // probe for all formats | 2512 | // probe for all formats |
2457 | if (importText_PwM(file) == e_success) | 2513 | if (importText_PwM(file) == e_success) |
2458 | return e_success; | 2514 | return e_success; |
2459 | dti.clear(); | 2515 | dti.clear(); |
2460 | emitDataChanged(this); | 2516 | emitDataChanged(this); |
2461 | // add next format here... | 2517 | // add next format here... |
2462 | return e_fileFormat; | 2518 | return e_fileFormat; |
2463 | } | 2519 | } |
2464 | return e_invalidArg; | 2520 | return e_invalidArg; |
2465 | } | 2521 | } |
2466 | 2522 | ||
2467 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2523 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2468 | { | 2524 | { |
2469 | #ifndef PWM_EMBEDDED | 2525 | #ifndef PWM_EMBEDDED |
2470 | PWM_ASSERT(file); | 2526 | PWM_ASSERT(file); |
2471 | FILE *f; | 2527 | FILE *f; |
2472 | int tmp; | 2528 | int tmp; |
2473 | ssize_t ret; | 2529 | ssize_t ret; |
2474 | string curCat; | 2530 | string curCat; |
2475 | unsigned int entriesRead = 0; | 2531 | unsigned int entriesRead = 0; |
2476 | PwMDataItem currItem; | 2532 | PwMDataItem currItem; |
2477 | f = fopen(file->latin1(), "r"); | 2533 | f = fopen(file->latin1(), "r"); |
2478 | if (!f) | 2534 | if (!f) |
2479 | return e_openFile; | 2535 | return e_openFile; |
2480 | size_t ch_tmp_size = 1024; | 2536 | size_t ch_tmp_size = 1024; |
2481 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2537 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2482 | if (!ch_tmp) { | 2538 | if (!ch_tmp) { |
2483 | fclose(f); | 2539 | fclose(f); |
2484 | return e_outOfMem; | 2540 | return e_outOfMem; |
2485 | } | 2541 | } |
2486 | 2542 | ||
2487 | // - check header | 2543 | // - check header |
2488 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2544 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2489 | goto formatError; | 2545 | goto formatError; |
2490 | // check version-string and return version in "ch_tmp". | 2546 | // check version-string and return version in "ch_tmp". |
2491 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2547 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2492 | // header not recognized as PwM generated header | 2548 | // header not recognized as PwM generated header |
2493 | goto formatError; | 2549 | goto formatError; |
2494 | } | 2550 | } |
2495 | // set filepointer behind version-string-line previously checked | 2551 | // set filepointer behind version-string-line previously checked |
2496 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2552 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2497 | goto formatError; | 2553 | goto formatError; |
2498 | // skip next line containing the build-date | 2554 | // skip next line containing the build-date |
2499 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2555 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2500 | goto formatError; | 2556 | goto formatError; |
2501 | // read header termination line | 2557 | // read header termination line |
2502 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2558 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2503 | goto formatError; | 2559 | goto formatError; |
2504 | if (strcmp(ch_tmp, "==============================\n")) | 2560 | if (strcmp(ch_tmp, "==============================\n")) |
2505 | goto formatError; | 2561 | goto formatError; |
2506 | 2562 | ||
2507 | // - read entries | 2563 | // - read entries |
2508 | do { | 2564 | do { |
2509 | // find beginning of next category | 2565 | // find beginning of next category |
2510 | do { | 2566 | do { |
2511 | tmp = fgetc(f); | 2567 | tmp = fgetc(f); |
2512 | } while (tmp == '\n' && tmp != EOF); | 2568 | } while (tmp == '\n' && tmp != EOF); |
2513 | if (tmp == EOF) | 2569 | if (tmp == EOF) |
2514 | break; | 2570 | break; |
2515 | 2571 | ||
2516 | // decrement filepos by one | 2572 | // decrement filepos by one |
2517 | fseek(f, -1, SEEK_CUR); | 2573 | fseek(f, -1, SEEK_CUR); |
2518 | // read cat-name | 2574 | // read cat-name |
2519 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2575 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2520 | goto formatError; | 2576 | goto formatError; |
2521 | // check cat-name format | 2577 | // check cat-name format |
2522 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2578 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2523 | goto formatError; | 2579 | goto formatError; |
2524 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2580 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2525 | goto formatError; | 2581 | goto formatError; |
2526 | // copy cat-name | 2582 | // copy cat-name |
2527 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2583 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2528 | 2584 | ||
2529 | do { | 2585 | do { |
2530 | // find beginning of next entry | 2586 | // find beginning of next entry |
2531 | do { | 2587 | do { |
2532 | tmp = fgetc(f); | 2588 | tmp = fgetc(f); |
2533 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2589 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2534 | if (tmp == EOF) | 2590 | if (tmp == EOF) |
2535 | break; | 2591 | break; |
2536 | if (tmp == '=') { | 2592 | if (tmp == '=') { |
2537 | fseek(f, -1, SEEK_CUR); | 2593 | fseek(f, -1, SEEK_CUR); |
2538 | break; | 2594 | break; |
2539 | } | 2595 | } |
2540 | // decrement filepos by one | 2596 | // decrement filepos by one |
2541 | fseek(f, -1, SEEK_CUR); | 2597 | fseek(f, -1, SEEK_CUR); |
2542 | // read desc-line | 2598 | // read desc-line |
2543 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2599 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2544 | goto formatError; | 2600 | goto formatError; |
2545 | // check desc-line format | 2601 | // check desc-line format |
2546 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2602 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2547 | goto formatError; | 2603 | goto formatError; |
2548 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2604 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2549 | goto formatError; | 2605 | goto formatError; |
2550 | // add desc-line | 2606 | // add desc-line |
2551 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2607 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2552 | 2608 | ||
2553 | // read username-line | 2609 | // read username-line |
2554 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2610 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2555 | goto formatError; | 2611 | goto formatError; |
2556 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2612 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2557 | goto formatError; | 2613 | goto formatError; |
2558 | 2614 | ||
2559 | // read pw-line | 2615 | // read pw-line |
2560 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2616 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2561 | goto formatError; | 2617 | goto formatError; |
2562 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2618 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2563 | goto formatError; | 2619 | goto formatError; |
2564 | 2620 | ||
2565 | // read comment-line | 2621 | // read comment-line |
2566 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2622 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2567 | goto formatError; | 2623 | goto formatError; |
2568 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2624 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2569 | goto formatError; | 2625 | goto formatError; |
2570 | 2626 | ||
2571 | // read URL-line | 2627 | // read URL-line |
2572 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2628 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2573 | goto formatError; | 2629 | goto formatError; |
2574 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2630 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2575 | goto formatError; | 2631 | goto formatError; |
2576 | 2632 | ||
2577 | // read launcher-line | 2633 | // read launcher-line |
2578 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2634 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2579 | goto formatError; | 2635 | goto formatError; |
2580 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2636 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2581 | goto formatError; | 2637 | goto formatError; |
2582 | 2638 | ||
2583 | currItem.lockStat = true; | 2639 | currItem.lockStat = true; |
2584 | currItem.listViewPos = -1; | 2640 | currItem.listViewPos = -1; |
2585 | addEntry(curCat.c_str(), &currItem, true); | 2641 | addEntry(curCat.c_str(), &currItem, true); |
2586 | ++entriesRead; | 2642 | ++entriesRead; |
2587 | } while (1); | 2643 | } while (1); |
2588 | } while (1); | 2644 | } while (1); |
2589 | if (!entriesRead) | 2645 | if (!entriesRead) |
2590 | goto formatError; | 2646 | goto formatError; |
2591 | 2647 | ||
2592 | free(ch_tmp); | 2648 | free(ch_tmp); |
2593 | fclose(f); | 2649 | fclose(f); |
2594 | flagDirty(); | 2650 | flagDirty(); |
2595 | return e_success; | 2651 | return e_success; |
2596 | 2652 | ||
2597 | formatError: | 2653 | formatError: |
2598 | free(ch_tmp); | 2654 | free(ch_tmp); |
2599 | fclose(f); | 2655 | fclose(f); |
2600 | return e_fileFormat; | 2656 | return e_fileFormat; |
2601 | #else | 2657 | #else |
2602 | PWM_ASSERT(file); | 2658 | PWM_ASSERT(file); |
2603 | QFile f(file->latin1()); | 2659 | QFile f(file->latin1()); |
2604 | int tmp; | 2660 | int tmp; |
2605 | ssize_t ret; | 2661 | ssize_t ret; |
2606 | string curCat; | 2662 | string curCat; |
2607 | unsigned int entriesRead = 0; | 2663 | unsigned int entriesRead = 0; |
2608 | PwMDataItem currItem; | 2664 | PwMDataItem currItem; |
2609 | bool res = f.open(IO_ReadOnly); | 2665 | bool res = f.open(IO_ReadOnly); |
2610 | if (res == false) | 2666 | if (res == false) |
2611 | return e_openFile; | 2667 | return e_openFile; |
2612 | 2668 | ||
2613 | unsigned int ch_tmp_size = 1024; | 2669 | unsigned int ch_tmp_size = 1024; |
2614 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2670 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2615 | if (!ch_tmp) { | 2671 | if (!ch_tmp) { |
2616 | f.close(); | 2672 | f.close(); |
2617 | return e_outOfMem; | 2673 | return e_outOfMem; |
2618 | } | 2674 | } |
2619 | 2675 | ||
2620 | // - check header | 2676 | // - check header |
2621 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. | 2677 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. |
2622 | goto formatError; | 2678 | goto formatError; |
2623 | 2679 | ||
2624 | //US read fileversion first, then check if ok. | 2680 | //US read fileversion first, then check if ok. |
2625 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2681 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2626 | goto formatError; | 2682 | goto formatError; |
2627 | 2683 | ||
2628 | // check version-string and return version in "ch_tmp". | 2684 | // check version-string and return version in "ch_tmp". |
2629 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2685 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2630 | //US // header not recognized as PwM generated header | 2686 | //US // header not recognized as PwM generated header |
2631 | //US goto formatError; | 2687 | //US goto formatError; |
2632 | //US} | 2688 | //US} |
2633 | //US set filepointer behind version-string-line previously checked | 2689 | //US set filepointer behind version-string-line previously checked |
2634 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2690 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2635 | //US goto formatError; | 2691 | //US goto formatError; |
2636 | // skip next line containing the build-date | 2692 | // skip next line containing the build-date |
2637 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2693 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2638 | goto formatError; | 2694 | goto formatError; |
2639 | // read header termination line | 2695 | // read header termination line |
2640 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2696 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2641 | goto formatError; | 2697 | goto formatError; |
2642 | if (strcmp(ch_tmp, "==============================\n")) | 2698 | if (strcmp(ch_tmp, "==============================\n")) |
2643 | goto formatError; | 2699 | goto formatError; |
2644 | 2700 | ||
2645 | // - read entries | 2701 | // - read entries |
2646 | do { | 2702 | do { |
2647 | // find beginning of next category | 2703 | // find beginning of next category |
2648 | do { | 2704 | do { |
2649 | tmp = f.getch(); | 2705 | tmp = f.getch(); |
2650 | } while (tmp == '\n' && tmp != EOF); | 2706 | } while (tmp == '\n' && tmp != EOF); |
2651 | if (tmp == EOF) | 2707 | if (tmp == EOF) |
2652 | break; | 2708 | break; |
2653 | 2709 | ||
2654 | // decrement filepos by one | 2710 | // decrement filepos by one |
2655 | f.at(f.at()-1); | 2711 | f.at(f.at()-1); |
2656 | // read cat-name | 2712 | // read cat-name |
2657 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2713 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2658 | goto formatError; | 2714 | goto formatError; |
2659 | // check cat-name format | 2715 | // check cat-name format |
2660 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2716 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2661 | goto formatError; | 2717 | goto formatError; |
2662 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2718 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2663 | goto formatError; | 2719 | goto formatError; |
2664 | // copy cat-name | 2720 | // copy cat-name |
2665 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2721 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2666 | 2722 | ||
2667 | do { | 2723 | do { |
2668 | // find beginning of next entry | 2724 | // find beginning of next entry |
2669 | do { | 2725 | do { |
2670 | tmp = f.getch(); | 2726 | tmp = f.getch(); |
2671 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2727 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2672 | if (tmp == EOF) | 2728 | if (tmp == EOF) |
2673 | break; | 2729 | break; |
2674 | if (tmp == '=') { | 2730 | if (tmp == '=') { |
2675 | f.at(f.at()-1); | 2731 | f.at(f.at()-1); |
2676 | break; | 2732 | break; |
2677 | } | 2733 | } |
2678 | // decrement filepos by one | 2734 | // decrement filepos by one |
2679 | f.at(f.at()-1); | 2735 | f.at(f.at()-1); |
2680 | // read desc-line | 2736 | // read desc-line |
2681 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2737 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2682 | goto formatError; | 2738 | goto formatError; |
2683 | // check desc-line format | 2739 | // check desc-line format |
2684 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2740 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2685 | goto formatError; | 2741 | goto formatError; |
2686 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2742 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2687 | goto formatError; | 2743 | goto formatError; |
2688 | // add desc-line | 2744 | // add desc-line |
2689 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2745 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2690 | 2746 | ||
2691 | // read username-line | 2747 | // read username-line |
2692 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2748 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2693 | goto formatError; | 2749 | goto formatError; |
2694 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2750 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2695 | goto formatError; | 2751 | goto formatError; |
2696 | 2752 | ||
2697 | // read pw-line | 2753 | // read pw-line |
2698 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2754 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2699 | goto formatError; | 2755 | goto formatError; |
2700 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2756 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2701 | goto formatError; | 2757 | goto formatError; |
2702 | 2758 | ||
2703 | // read comment-line | 2759 | // read comment-line |
2704 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2760 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2705 | goto formatError; | 2761 | goto formatError; |
2706 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2762 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2707 | goto formatError; | 2763 | goto formatError; |
2708 | 2764 | ||
2709 | // read URL-line | 2765 | // read URL-line |
2710 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2766 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2711 | goto formatError; | 2767 | goto formatError; |
2712 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2768 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2713 | goto formatError; | 2769 | goto formatError; |
2714 | 2770 | ||
2715 | // read launcher-line | 2771 | // read launcher-line |
2716 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2772 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2717 | goto formatError; | 2773 | goto formatError; |
2718 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2774 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2719 | goto formatError; | 2775 | goto formatError; |
2720 | 2776 | ||
2721 | currItem.lockStat = true; | 2777 | currItem.lockStat = true; |
2722 | currItem.listViewPos = -1; | 2778 | currItem.listViewPos = -1; |
2723 | addEntry(curCat.c_str(), &currItem, true); | 2779 | addEntry(curCat.c_str(), &currItem, true); |
2724 | ++entriesRead; | 2780 | ++entriesRead; |
2725 | } while (1); | 2781 | } while (1); |
2726 | } while (1); | 2782 | } while (1); |
2727 | if (!entriesRead) | 2783 | if (!entriesRead) |
2728 | goto formatError; | 2784 | goto formatError; |
2729 | 2785 | ||
2730 | free(ch_tmp); | 2786 | free(ch_tmp); |
2731 | f.close(); | 2787 | f.close(); |
2732 | flagDirty(); | 2788 | flagDirty(); |
2733 | return e_success; | 2789 | return e_success; |
2734 | 2790 | ||
2735 | formatError: | 2791 | formatError: |
2736 | free(ch_tmp); | 2792 | free(ch_tmp); |
2737 | f.close(); | 2793 | f.close(); |
2738 | return e_fileFormat; | 2794 | return e_fileFormat; |
2739 | 2795 | ||
2740 | #endif | 2796 | #endif |
2741 | 2797 | ||
2742 | } | 2798 | } |
2743 | 2799 | ||
2744 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2800 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2745 | { | 2801 | { |
2746 | PWM_ASSERT(in && out); | 2802 | PWM_ASSERT(in && out); |
2747 | ssize_t i = 0, len = in_size - 1; | 2803 | ssize_t i = 0, len = in_size - 1; |
2748 | while (i < len) { | 2804 | while (i < len) { |
2749 | if (in[i] == ':') | 2805 | if (in[i] == ':') |
2750 | break; | 2806 | break; |
2751 | ++i; | 2807 | ++i; |
2752 | } | 2808 | } |
2753 | i += 2; | 2809 | i += 2; |
2754 | *out = ""; | 2810 | *out = ""; |
2755 | out->append(in + i, in_size - i - 1); | 2811 | out->append(in + i, in_size - i - 1); |
2756 | return true; | 2812 | return true; |
2757 | } | 2813 | } |
2758 | 2814 | ||
2759 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2815 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2760 | { | 2816 | { |
2761 | PWM_ASSERT(file); | 2817 | PWM_ASSERT(file); |
2762 | GpasmanFile gp; | 2818 | GpasmanFile gp; |
2763 | int ret; | 2819 | int ret; |
2764 | 2820 | ||
2765 | if (!unlockAll_tempoary()) | 2821 | if (!unlockAll_tempoary()) |
2766 | return e_lock; | 2822 | return e_lock; |
2767 | 2823 | ||
2768 | QString gpmPassword; | 2824 | QString gpmPassword; |
2769 | while (1) { | 2825 | while (1) { |
2770 | gpmPassword = requestNewMpw(0); | 2826 | gpmPassword = requestNewMpw(0); |
2771 | if (gpmPassword == "") { | 2827 | if (gpmPassword == "") { |
2772 | unlockAll_tempoary(true); | 2828 | unlockAll_tempoary(true); |
2773 | return e_noPw; | 2829 | return e_noPw; |
2774 | } | 2830 | } |
2775 | if (gpmPassword.length() < 4) { | 2831 | if (gpmPassword.length() < 4) { |
2776 | gpmPwLenErrMsgBox(); | 2832 | gpmPwLenErrMsgBox(); |
2777 | } else { | 2833 | } else { |
2778 | break; | 2834 | break; |
2779 | } | 2835 | } |
2780 | } | 2836 | } |
2781 | 2837 | ||
2782 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2838 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2783 | if (ret != 1) { | 2839 | if (ret != 1) { |
2784 | unlockAll_tempoary(true); | 2840 | unlockAll_tempoary(true); |
2785 | return e_accessFile; | 2841 | return e_accessFile; |
2786 | } | 2842 | } |
2787 | 2843 | ||
2788 | char *entry[4]; | 2844 | char *entry[4]; |
2789 | unsigned int numCat = numCategories(), i; | 2845 | unsigned int numCat = numCategories(), i; |
2790 | unsigned int numEntr, j; | 2846 | unsigned int numEntr, j; |
2791 | int descLen, nameLen, pwLen, commentLen; | 2847 | int descLen, nameLen, pwLen, commentLen; |
2792 | for (i = 0; i < numCat; ++i) { | 2848 | for (i = 0; i < numCat; ++i) { |
2793 | numEntr = numEntries(i); | 2849 | numEntr = numEntries(i); |
2794 | for (j = 0; j < numEntr; ++j) { | 2850 | for (j = 0; j < numEntr; ++j) { |
2795 | descLen = dti.dta[i].d[j].desc.length(); | 2851 | descLen = dti.dta[i].d[j].desc.length(); |
2796 | nameLen = dti.dta[i].d[j].name.length(); | 2852 | nameLen = dti.dta[i].d[j].name.length(); |
2797 | pwLen = dti.dta[i].d[j].pw.length(); | 2853 | pwLen = dti.dta[i].d[j].pw.length(); |
2798 | commentLen = dti.dta[i].d[j].comment.length(); | 2854 | commentLen = dti.dta[i].d[j].comment.length(); |
2799 | entry[0] = new char[descLen + 1]; | 2855 | entry[0] = new char[descLen + 1]; |
2800 | entry[1] = new char[nameLen + 1]; | 2856 | entry[1] = new char[nameLen + 1]; |
2801 | entry[2] = new char[pwLen + 1]; | 2857 | entry[2] = new char[pwLen + 1]; |
2802 | entry[3] = new char[commentLen + 1]; | 2858 | entry[3] = new char[commentLen + 1]; |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 9fcdda7..45dd729 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -1,831 +1,833 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.1 of pwmanager | 14 | * This file is originaly based on version 1.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef __PWMDOC_H | 20 | #ifndef __PWMDOC_H |
21 | #define __PWMDOC_H | 21 | #define __PWMDOC_H |
22 | #ifdef _WIN32_ | 22 | #ifdef _WIN32_ |
23 | #define ssize_t unsigned int | 23 | #define ssize_t unsigned int |
24 | #endif | 24 | #endif |
25 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 25 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
26 | 26 | ||
27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
34 | 34 | ||
35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
42 | 42 | ||
43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
46 | 46 | ||
47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
49 | 49 | ||
50 | 50 | ||
51 | #include "pwmexception.h" | 51 | #include "pwmexception.h" |
52 | #include "pwmdocui.h" | 52 | #include "pwmdocui.h" |
53 | 53 | ||
54 | #include <qobject.h> | 54 | #include <qobject.h> |
55 | #include <qtimer.h> | 55 | #include <qtimer.h> |
56 | #include <qdatetime.h> | 56 | #include <qdatetime.h> |
57 | 57 | ||
58 | #include <kprocess.h> | 58 | #include <kprocess.h> |
59 | 59 | ||
60 | #ifndef PWM_EMBEDDED | 60 | #ifndef PWM_EMBEDDED |
61 | #include "configuration.h" | 61 | #include "configuration.h" |
62 | #else | 62 | #else |
63 | #include <kapplication.h> | 63 | #include <kapplication.h> |
64 | #include <ksyncmanager.h> | 64 | #include <ksyncmanager.h> |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #include <string> | 67 | #include <string> |
68 | #include <vector> | 68 | #include <vector> |
69 | #include <utility> | 69 | #include <utility> |
70 | 70 | ||
71 | using std::vector; | 71 | using std::vector; |
72 | using std::string; | 72 | using std::string; |
73 | using std::pair; | 73 | using std::pair; |
74 | 74 | ||
75 | /* used in findEntry() function */ | 75 | /* used in findEntry() function */ |
76 | #define SEARCH_IN_DESC (1) | 76 | #define SEARCH_IN_DESC (1) |
77 | #define SEARCH_IN_NAME (1 << 1) | 77 | #define SEARCH_IN_NAME (1 << 1) |
78 | #define SEARCH_IN_PW (1 << 2) | 78 | #define SEARCH_IN_PW (1 << 2) |
79 | #define SEARCH_IN_COMMENT(1 << 3) | 79 | #define SEARCH_IN_COMMENT(1 << 3) |
80 | #define SEARCH_IN_URL (1 << 4) | 80 | #define SEARCH_IN_URL (1 << 4) |
81 | #define SEARCH_IN_LAUNCHER(1 << 5) | 81 | #define SEARCH_IN_LAUNCHER(1 << 5) |
82 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 82 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
83 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 83 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
84 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 84 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
85 | 85 | ||
86 | /** document deeplocked. Data is out for lunch to disk */ | 86 | /** document deeplocked. Data is out for lunch to disk */ |
87 | #define DOC_STAT_DEEPLOCKED (1) | 87 | #define DOC_STAT_DEEPLOCKED (1) |
88 | /** encrypted document on disk is dirty. data has to go to disk. */ | 88 | /** encrypted document on disk is dirty. data has to go to disk. */ |
89 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 89 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
90 | /** we are using a chipcard to encrypt the data */ | 90 | /** we are using a chipcard to encrypt the data */ |
91 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 91 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
92 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 92 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
93 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 93 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
94 | 94 | ||
95 | class PwMDoc; | 95 | class PwMDoc; |
96 | class PwMView; | 96 | class PwMView; |
97 | class QFile; | 97 | class QFile; |
98 | 98 | ||
99 | /* meta data for a PwMDataItem */ | 99 | /* meta data for a PwMDataItem */ |
100 | struct PwMMetaData | 100 | struct PwMMetaData |
101 | { | 101 | { |
102 | PwMMetaData() | 102 | PwMMetaData() |
103 | : updateInt (0) | 103 | : updateInt (0) |
104 | { } | 104 | { } |
105 | /** creation date of the PwMDataItem to which | 105 | /** creation date of the PwMDataItem to which |
106 | * this meta data belongs. | 106 | * this meta data belongs. |
107 | */ | 107 | */ |
108 | QDateTimecreate; | 108 | QDateTimecreate; |
109 | /** becomes valid on this date */ | 109 | /** becomes valid on this date */ |
110 | QDateTimevalid; | 110 | QDateTimevalid; |
111 | /** expire date */ | 111 | /** expire date */ |
112 | QDateTimeexpire; | 112 | QDateTimeexpire; |
113 | /** update date (last updated at this date) */ | 113 | /** update date (last updated at this date) */ |
114 | QDateTimeupdate; | 114 | QDateTimeupdate; |
115 | /** update interval (in minutes). Time since the | 115 | /** update interval (in minutes). Time since the |
116 | * last update to remind the user to update the item. | 116 | * last update to remind the user to update the item. |
117 | * 0 disables. | 117 | * 0 disables. |
118 | */ | 118 | */ |
119 | unsigned long updateInt; | 119 | unsigned long updateInt; |
120 | 120 | ||
121 | //US ENH: enhancements of the filestructure | 121 | //US ENH: enhancements of the filestructure |
122 | /* each entry gets a unique id assigned */ | 122 | /* each entry gets a unique id assigned */ |
123 | string uniqueid; | 123 | string uniqueid; |
124 | 124 | ||
125 | 125 | ||
126 | void clear() | 126 | void clear() |
127 | { | 127 | { |
128 | create = QDateTime(); | 128 | create = QDateTime(); |
129 | expire = QDateTime(); | 129 | expire = QDateTime(); |
130 | update = QDateTime(); | 130 | update = QDateTime(); |
131 | updateInt = 0; | 131 | updateInt = 0; |
132 | uniqueid = KApplication::randomString(8).latin1(); | 132 | uniqueid = KApplication::randomString(8).latin1(); |
133 | } | 133 | } |
134 | 134 | ||
135 | inline bool isValid() const | 135 | inline bool isValid() const |
136 | { | 136 | { |
137 | if (valid.isNull()) | 137 | if (valid.isNull()) |
138 | return true; | 138 | return true; |
139 | return (valid < QDateTime::currentDateTime()); | 139 | return (valid < QDateTime::currentDateTime()); |
140 | } | 140 | } |
141 | inline bool isExpired() const | 141 | inline bool isExpired() const |
142 | { | 142 | { |
143 | if (expire.isNull()) | 143 | if (expire.isNull()) |
144 | return false; | 144 | return false; |
145 | return (expire < QDateTime::currentDateTime()); | 145 | return (expire < QDateTime::currentDateTime()); |
146 | } | 146 | } |
147 | inline bool isUpdateIntOver() const | 147 | inline bool isUpdateIntOver() const |
148 | { | 148 | { |
149 | if (updateInt == 0 || | 149 | if (updateInt == 0 || |
150 | update.isNull()) | 150 | update.isNull()) |
151 | return false; | 151 | return false; |
152 | QDateTime d(update); | 152 | QDateTime d(update); |
153 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 153 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
154 | } | 154 | } |
155 | }; | 155 | }; |
156 | 156 | ||
157 | struct PwMDataItem | 157 | struct PwMDataItem |
158 | { | 158 | { |
159 | PwMDataItem() | 159 | PwMDataItem() |
160 | : lockStat (true) | 160 | : lockStat (true) |
161 | , listViewPos (-1) | 161 | , listViewPos (-1) |
162 | , binary (false) | 162 | , binary (false) |
163 | , rev (0) | 163 | , rev (0) |
164 | { } | 164 | { } |
165 | 165 | ||
166 | /** password description */ | 166 | /** password description */ |
167 | stringdesc; | 167 | stringdesc; |
168 | /** user-name */ | 168 | /** user-name */ |
169 | stringname; | 169 | stringname; |
170 | /** the password itself */ | 170 | /** the password itself */ |
171 | stringpw; | 171 | stringpw; |
172 | /** some comment */ | 172 | /** some comment */ |
173 | stringcomment; | 173 | stringcomment; |
174 | /** an URL string */ | 174 | /** an URL string */ |
175 | stringurl; | 175 | stringurl; |
176 | /** launcher. Can be executed as a system() command */ | 176 | /** launcher. Can be executed as a system() command */ |
177 | stringlauncher; | 177 | stringlauncher; |
178 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 178 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
179 | boollockStat; | 179 | boollockStat; |
180 | /** position of this item in main "list-view" | 180 | /** position of this item in main "list-view" |
181 | * If -1, the position is not yet specified and should be appended to the list | 181 | * If -1, the position is not yet specified and should be appended to the list |
182 | */ | 182 | */ |
183 | intlistViewPos; | 183 | intlistViewPos; |
184 | /** does this entry contain binary data? */ | 184 | /** does this entry contain binary data? */ |
185 | bool binary; | 185 | bool binary; |
186 | /** meta data for this data item. */ | 186 | /** meta data for this data item. */ |
187 | PwMMetaData meta; | 187 | PwMMetaData meta; |
188 | /** data revision counter. This counter can be used | 188 | /** data revision counter. This counter can be used |
189 | * to easily, efficiently determine if this data item | 189 | * to easily, efficiently determine if this data item |
190 | * has changed since some time. | 190 | * has changed since some time. |
191 | * This counter is incremented on every update. | 191 | * This counter is incremented on every update. |
192 | */ | 192 | */ |
193 | unsigned int rev; | 193 | unsigned int rev; |
194 | 194 | ||
195 | void clear(bool clearMeta = true) | 195 | void clear(bool clearMeta = true) |
196 | { | 196 | { |
197 | /* NOTE: Don't use .clear() here to be | 197 | /* NOTE: Don't use .clear() here to be |
198 | * backward compatible with gcc-2 (Debian Woody) | 198 | * backward compatible with gcc-2 (Debian Woody) |
199 | */ | 199 | */ |
200 | desc = ""; | 200 | desc = ""; |
201 | name = ""; | 201 | name = ""; |
202 | pw = ""; | 202 | pw = ""; |
203 | comment = ""; | 203 | comment = ""; |
204 | url = ""; | 204 | url = ""; |
205 | launcher = ""; | 205 | launcher = ""; |
206 | lockStat = true; | 206 | lockStat = true; |
207 | listViewPos = -1; | 207 | listViewPos = -1; |
208 | binary = false; | 208 | binary = false; |
209 | if (clearMeta) | 209 | if (clearMeta) |
210 | meta.clear(); | 210 | meta.clear(); |
211 | } | 211 | } |
212 | //US ENH: we need this operator to compare two items if we have no unique ids | 212 | //US ENH: we need this operator to compare two items if we have no unique ids |
213 | //available. Generaly this happens before the first sync | 213 | //available. Generaly this happens before the first sync |
214 | 214 | ||
215 | bool PwMDataItem::operator==( const PwMDataItem &a ) const | 215 | bool PwMDataItem::operator==( const PwMDataItem &a ) const |
216 | { | 216 | { |
217 | //qDebug("oper==%s", a.desc.c_str()); | 217 | //qDebug("oper==%s", a.desc.c_str()); |
218 | if ( desc != a.desc ) return false; | 218 | if ( desc != a.desc ) return false; |
219 | if ( name != a.name ) return false; | 219 | if ( name != a.name ) return false; |
220 | if ( pw != a.pw ) return false; | 220 | if ( pw != a.pw ) return false; |
221 | if ( comment != a.comment ) return false; | 221 | if ( comment != a.comment ) return false; |
222 | if ( url != a.url ) return false; | 222 | if ( url != a.url ) return false; |
223 | if ( launcher != a.launcher ) return false; | 223 | if ( launcher != a.launcher ) return false; |
224 | //all other field will not be checked. | 224 | //all other field will not be checked. |
225 | return true; | 225 | return true; |
226 | } | 226 | } |
227 | 227 | ||
228 | //US ENH: this sync method actually copies all values from the parameter like the =operator | 228 | //US ENH: this sync method actually copies all values from the parameter like the =operator |
229 | //does with two exceptions: listViewPos will not be changed, and the launcher only if required. | 229 | //does with two exceptions: listViewPos will not be changed, and the launcher only if required. |
230 | bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) | 230 | bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) |
231 | { | 231 | { |
232 | desc = a.desc; | 232 | desc = a.desc; |
233 | name = a.name; | 233 | name = a.name; |
234 | pw = a.pw; | 234 | pw = a.pw; |
235 | comment = a.comment; | 235 | comment = a.comment; |
236 | url = a.url; | 236 | url = a.url; |
237 | if (syncLauncher == true) | 237 | if (syncLauncher == true) |
238 | launcher = a.launcher; | 238 | launcher = a.launcher; |
239 | meta = a.meta; | 239 | meta = a.meta; |
240 | binary = a.binary; | 240 | binary = a.binary; |
241 | lockStat = a.lockStat; | 241 | lockStat = a.lockStat; |
242 | rev = a.rev; | 242 | rev = a.rev; |
243 | 243 | ||
244 | return true; | 244 | return true; |
245 | } | 245 | } |
246 | 246 | ||
247 | }; | 247 | }; |
248 | 248 | ||
249 | struct PwMCategoryItem | 249 | struct PwMCategoryItem |
250 | { | 250 | { |
251 | /** all PwMDataItems (all passwords) within this category */ | 251 | /** all PwMDataItems (all passwords) within this category */ |
252 | vector<PwMDataItem>d; | 252 | vector<PwMDataItem>d; |
253 | /** category name/description */ | 253 | /** category name/description */ |
254 | string name; | 254 | string name; |
255 | 255 | ||
256 | //US ENH: enhancements of the filestructure | 256 | //US ENH: enhancements of the filestructure |
257 | /* each category stores the text for description,name and password */ | 257 | /* each category stores the text for description,name and password */ |
258 | string desc_text; | 258 | string desc_text; |
259 | string name_text; | 259 | string name_text; |
260 | string pw_text; | 260 | string pw_text; |
261 | 261 | ||
262 | void clear() | 262 | void clear() |
263 | { | 263 | { |
264 | d.clear(); | 264 | d.clear(); |
265 | name = ""; | 265 | name = ""; |
266 | desc_text = "Description"; | 266 | desc_text = "Description"; |
267 | name_text = "Username"; | 267 | name_text = "Username"; |
268 | pw_text = "Password"; | 268 | pw_text = "Password"; |
269 | } | 269 | } |
270 | }; | 270 | }; |
271 | 271 | ||
272 | struct PwMSyncItem | 272 | struct PwMSyncItem |
273 | { | 273 | { |
274 | string syncName; | 274 | string syncName; |
275 | QDateTime lastSyncDate; | 275 | QDateTime lastSyncDate; |
276 | 276 | ||
277 | void clear() | 277 | void clear() |
278 | { | 278 | { |
279 | lastSyncDate = QDateTime(); | 279 | lastSyncDate = QDateTime(); |
280 | syncName = ""; | 280 | syncName = ""; |
281 | } | 281 | } |
282 | }; | 282 | }; |
283 | 283 | ||
284 | struct PwMItem | 284 | struct PwMItem |
285 | { | 285 | { |
286 | vector<PwMCategoryItem> dta; | 286 | vector<PwMCategoryItem> dta; |
287 | vector<PwMSyncItem> syncDta; | 287 | vector<PwMSyncItem> syncDta; |
288 | 288 | ||
289 | void clear() | 289 | void clear() |
290 | { | 290 | { |
291 | dta.clear(); | 291 | dta.clear(); |
292 | syncDta.clear(); | 292 | syncDta.clear(); |
293 | } | 293 | } |
294 | }; | 294 | }; |
295 | 295 | ||
296 | 296 | ||
297 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 297 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
298 | class dta_lvp_greater | 298 | class dta_lvp_greater |
299 | { | 299 | { |
300 | public: | 300 | public: |
301 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 301 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
302 | const pair<unsigned int, unsigned int> &d2) | 302 | const pair<unsigned int, unsigned int> &d2) |
303 | { | 303 | { |
304 | return d1.second > d2.second; | 304 | return d1.second > d2.second; |
305 | } | 305 | } |
306 | }; | 306 | }; |
307 | 307 | ||
308 | /** list of PwMDoc documents and it's IDs */ | 308 | /** list of PwMDoc documents and it's IDs */ |
309 | class PwMDocList | 309 | class PwMDocList |
310 | { | 310 | { |
311 | public: | 311 | public: |
312 | struct listItem | 312 | struct listItem |
313 | { | 313 | { |
314 | /** document filename (known as ID, here) */ | 314 | /** document filename (known as ID, here) */ |
315 | string docId; | 315 | string docId; |
316 | /** pointer to the document class */ | 316 | /** pointer to the document class */ |
317 | PwMDoc *doc; | 317 | PwMDoc *doc; |
318 | }; | 318 | }; |
319 | 319 | ||
320 | PwMDocList() {} | 320 | PwMDocList() {} |
321 | 321 | ||
322 | /** add a new item to the list */ | 322 | /** add a new item to the list */ |
323 | void add(PwMDoc *doc, const string &id); | 323 | void add(PwMDoc *doc, const string &id); |
324 | /** changes the contents of an existing item */ | 324 | /** changes the contents of an existing item */ |
325 | void edit(PwMDoc *doc, const string &newId); | 325 | void edit(PwMDoc *doc, const string &newId); |
326 | /** remove the given item */ | 326 | /** remove the given item */ |
327 | void del(PwMDoc *doc); | 327 | void del(PwMDoc *doc); |
328 | /** get the item at index */ | 328 | /** get the item at index */ |
329 | listItem getAt(int index) | 329 | listItem getAt(int index) |
330 | { return docList[index]; } | 330 | { return docList[index]; } |
331 | /** find an entry with this id */ | 331 | /** find an entry with this id */ |
332 | bool find(const string &id, listItem *ret = 0); | 332 | bool find(const string &id, listItem *ret = 0); |
333 | /** returns a copy of the list */ | 333 | /** returns a copy of the list */ |
334 | const vector<listItem>* getList() const | 334 | const vector<listItem>* getList() const |
335 | { return &docList; } | 335 | { return &docList; } |
336 | 336 | ||
337 | 337 | ||
338 | /** returns a new unique number to extend the name of | 338 | /** returns a new unique number to extend the name of |
339 | * an unnamed document. | 339 | * an unnamed document. |
340 | */ | 340 | */ |
341 | static unsigned int getNewUnnamedNumber() | 341 | static unsigned int getNewUnnamedNumber() |
342 | { return unnamedDocCnt++; } | 342 | { return unnamedDocCnt++; } |
343 | 343 | ||
344 | protected: | 344 | protected: |
345 | /* Hm, I think we shouldn't really use a "list" here, should we? | 345 | /* Hm, I think we shouldn't really use a "list" here, should we? |
346 | * So I decided to actually use a vector. | 346 | * So I decided to actually use a vector. |
347 | */ | 347 | */ |
348 | vector<listItem> docList; | 348 | vector<listItem> docList; |
349 | /** This value is used to get a new number for yet unnamed | 349 | /** This value is used to get a new number for yet unnamed |
350 | * documents. It is incremented on every request. So it's | 350 | * documents. It is incremented on every request. So it's |
351 | * theoretically possible to overflow it, but... :) | 351 | * theoretically possible to overflow it, but... :) |
352 | */ | 352 | */ |
353 | static unsigned int unnamedDocCnt; | 353 | static unsigned int unnamedDocCnt; |
354 | }; | 354 | }; |
355 | 355 | ||
356 | /** implements timers for the document */ | 356 | /** implements timers for the document */ |
357 | class DocTimer : public QObject | 357 | class DocTimer : public QObject |
358 | { | 358 | { |
359 | Q_OBJECT | 359 | Q_OBJECT |
360 | public: | 360 | public: |
361 | enum TimerIDs | 361 | enum TimerIDs |
362 | { | 362 | { |
363 | id_mpwTimer, | 363 | id_mpwTimer, |
364 | id_autoLockTimer, | 364 | id_autoLockTimer, |
365 | id_metaCheckTimer | 365 | id_metaCheckTimer |
366 | }; | 366 | }; |
367 | 367 | ||
368 | public: | 368 | public: |
369 | DocTimer(PwMDoc *_doc); | 369 | DocTimer(PwMDoc *_doc); |
370 | ~DocTimer(); | 370 | ~DocTimer(); |
371 | 371 | ||
372 | /** start the timer */ | 372 | /** start the timer */ |
373 | void start(TimerIDs timer); | 373 | void start(TimerIDs timer); |
374 | /** stop the timer */ | 374 | /** stop the timer */ |
375 | void stop(TimerIDs timer); | 375 | void stop(TimerIDs timer); |
376 | /** get the lock for a timer. | 376 | /** get the lock for a timer. |
377 | * This lock is a recursive lock. When a lock is | 377 | * This lock is a recursive lock. When a lock is |
378 | * held, the timer will be stopped and timeout is | 378 | * held, the timer will be stopped and timeout is |
379 | * guaranteed to not happen | 379 | * guaranteed to not happen |
380 | */ | 380 | */ |
381 | void getLock(TimerIDs timer); | 381 | void getLock(TimerIDs timer); |
382 | /** put a recursive timer lock */ | 382 | /** put a recursive timer lock */ |
383 | void putLock(TimerIDs timer); | 383 | void putLock(TimerIDs timer); |
384 | 384 | ||
385 | protected slots: | 385 | protected slots: |
386 | /** timeout slot for the mpw timer */ | 386 | /** timeout slot for the mpw timer */ |
387 | void mpwTimeout(); | 387 | void mpwTimeout(); |
388 | /** timeout slot for the autoLock timer */ | 388 | /** timeout slot for the autoLock timer */ |
389 | void autoLockTimeout(); | 389 | void autoLockTimeout(); |
390 | /** timeout slot for the metaCheck timer */ | 390 | /** timeout slot for the metaCheck timer */ |
391 | void metaCheckTimeout(); | 391 | void metaCheckTimeout(); |
392 | 392 | ||
393 | protected: | 393 | protected: |
394 | /** pointer to the document associated with this timer. */ | 394 | /** pointer to the document associated with this timer. */ |
395 | PwMDoc *doc; | 395 | PwMDoc *doc; |
396 | /** timer object for mpw timer */ | 396 | /** timer object for mpw timer */ |
397 | QTimer *mpwTimer; | 397 | QTimer *mpwTimer; |
398 | /** timer object for the autoLock timer */ | 398 | /** timer object for the autoLock timer */ |
399 | QTimer *autoLockTimer; | 399 | QTimer *autoLockTimer; |
400 | /** timer object for the metaCheck timer */ | 400 | /** timer object for the metaCheck timer */ |
401 | QTimer *metaCheckTimer; | 401 | QTimer *metaCheckTimer; |
402 | /** lock counter for the mpw timer */ | 402 | /** lock counter for the mpw timer */ |
403 | unsigned int mpwLock; | 403 | unsigned int mpwLock; |
404 | /** lock counter for the autoLock timer */ | 404 | /** lock counter for the autoLock timer */ |
405 | unsigned int autoLockLock; | 405 | unsigned int autoLockLock; |
406 | /** lock counter for the metaCheck timer */ | 406 | /** lock counter for the metaCheck timer */ |
407 | unsigned int metaCheckLock; | 407 | unsigned int metaCheckLock; |
408 | }; | 408 | }; |
409 | 409 | ||
410 | /** Document class for PwM */ | 410 | /** Document class for PwM */ |
411 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. | 411 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. |
412 | // But PwMDoc is handling the sync by itself. | 412 | // But PwMDoc is handling the sync by itself. |
413 | class PwMDoc : public PwMDocUi, public KSyncInterface | 413 | class PwMDoc : public PwMDocUi, public KSyncInterface |
414 | 414 | ||
415 | { | 415 | { |
416 | Q_OBJECT | 416 | Q_OBJECT |
417 | friend class DocTimer; | 417 | friend class DocTimer; |
418 | 418 | ||
419 | public: | 419 | public: |
420 | /** construtor */ | 420 | /** construtor */ |
421 | PwMDoc(QObject* parent = 0, const char *name = 0); | 421 | PwMDoc(QObject* parent = 0, const char *name = 0); |
422 | /** destructor */ | 422 | /** destructor */ |
423 | ~PwMDoc(); | 423 | ~PwMDoc(); |
424 | 424 | ||
425 | /** returns a pointer to a list of all open documents */ | 425 | /** returns a pointer to a list of all open documents */ |
426 | static PwMDocList* getOpenDocList() | 426 | static PwMDocList* getOpenDocList() |
427 | { return &openDocList; } | 427 | { return &openDocList; } |
428 | 428 | ||
429 | /** flag document dirty. dta changed */ | 429 | /** flag document dirty. dta changed */ |
430 | void flagDirty() | 430 | void flagDirty() |
431 | { | 431 | { |
432 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 432 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
433 | emitDataChanged(this); | 433 | emitDataChanged(this); |
434 | } | 434 | } |
435 | /** modified? */ | 435 | /** modified? */ |
436 | bool isDirty() | 436 | bool isDirty() |
437 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 437 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
438 | /** save document to disk */ | 438 | /** save document to disk */ |
439 | PwMerror saveDoc(char compress, const QString *file = 0); | 439 | PwMerror saveDoc(char compress, const QString *file = 0); |
440 | /** read document from file. | 440 | /** read document from file. |
441 | * "openLocked is must be set to either of these values: | 441 | * "openLocked is must be set to either of these values: |
442 | * 0 == open with all entries unlocked | 442 | * 0 == open with all entries unlocked |
443 | * 1 == open with all entries locked | 443 | * 1 == open with all entries locked |
444 | * 2 == open deep-locked | 444 | * 2 == open deep-locked |
445 | */ | 445 | */ |
446 | PwMerror openDoc(const QString *file, int openLocked); | 446 | PwMerror openDoc(const QString *file, int openLocked); |
447 | /** export document to ascii-textfile */ | 447 | /** export document to ascii-textfile */ |
448 | PwMerror exportToText(const QString *file); | 448 | PwMerror exportToText(const QString *file); |
449 | /** export document to gpasman / kpasman file */ | 449 | /** export document to gpasman / kpasman file */ |
450 | PwMerror exportToGpasman(const QString *file); | 450 | PwMerror exportToGpasman(const QString *file); |
451 | /** import document from ascii-textfile */ | 451 | /** import document from ascii-textfile */ |
452 | PwMerror importFromText(const QString *file, int format = -1); | 452 | PwMerror importFromText(const QString *file, int format = -1); |
453 | /** import document from gpasman / kpasman file */ | 453 | /** import document from gpasman / kpasman file */ |
454 | PwMerror importFromGpasman(const QString *file); | 454 | PwMerror importFromGpasman(const QString *file); |
455 | /** add new entry */ | 455 | /** add new entry */ |
456 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 456 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
457 | bool dontFlagDirty = false, bool updateMeta = true); | 457 | bool dontFlagDirty = false, bool updateMeta = true); |
458 | /** add new category. This function doesn't flag the document dirty! */ | 458 | /** add new category. This function doesn't flag the document dirty! */ |
459 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 459 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
460 | bool checkIfExist = true); | 460 | bool checkIfExist = true); |
461 | /** rename an existing category */ | 461 | /** rename an existing category */ |
462 | bool renameCategory(const QString &category, const QString &newName); | 462 | bool renameCategory(const QString &category, const QString &newName); |
463 | /** rename an existing category */ | 463 | /** rename an existing category */ |
464 | bool renameCategory(unsigned int category, const QString &newName, | 464 | bool renameCategory(unsigned int category, const QString &newName, |
465 | bool dontFlagDirty = false); | 465 | bool dontFlagDirty = false); |
466 | /** delete an existing category */ | 466 | /** delete an existing category */ |
467 | bool delCategory(const QString &category); | 467 | bool delCategory(const QString &category); |
468 | /** delete an existing category */ | 468 | /** delete an existing category */ |
469 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 469 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
470 | /** returns a list of all category-names */ | 470 | /** returns a list of all category-names */ |
471 | void getCategoryList(vector<string> *list); | 471 | void getCategoryList(vector<string> *list); |
472 | /** returns a list of all category-names */ | 472 | /** returns a list of all category-names */ |
473 | void getCategoryList(QStringList *list); | 473 | void getCategoryList(QStringList *list); |
474 | /** returns a list of all entry-descs in the given category */ | 474 | /** returns a list of all entry-descs in the given category */ |
475 | void getEntryList(const QString &category, QStringList *list); | 475 | void getEntryList(const QString &category, QStringList *list); |
476 | /** returns a list of all entry-descs in the given category */ | 476 | /** returns a list of all entry-descs in the given category */ |
477 | void getEntryList(const QString &category, vector<string> *list); | 477 | void getEntryList(const QString &category, vector<string> *list); |
478 | /** returns a list of all entry-descs in the given category */ | 478 | /** returns a list of all entry-descs in the given category */ |
479 | void getEntryList(unsigned int category, vector<string> *list); | 479 | void getEntryList(unsigned int category, vector<string> *list); |
480 | /** returns a list of all entry-descs in the given category */ | 480 | /** returns a list of all entry-descs in the given category */ |
481 | void getEntryList(unsigned int category, QStringList *list); | 481 | void getEntryList(unsigned int category, QStringList *list); |
482 | /** delete entry */ | 482 | /** delete entry */ |
483 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 483 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
484 | /** delete entry */ | 484 | /** delete entry */ |
485 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 485 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
486 | /** edit entry */ | 486 | /** edit entry */ |
487 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 487 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
488 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 488 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
489 | /** edit entry */ | 489 | /** edit entry */ |
490 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 490 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
491 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 491 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
492 | /** finds the category with the "name" and return it's index */ | 492 | /** finds the category with the "name" and return it's index */ |
493 | bool findCategory(const QString &name, unsigned int *index); | 493 | bool findCategory(const QString &name, unsigned int *index); |
494 | /** search for an entry "find" and check while searching only for | 494 | /** search for an entry "find" and check while searching only for |
495 | * the data-fields specified by "searchIn". To set the "searchIn" | 495 | * the data-fields specified by "searchIn". To set the "searchIn" |
496 | * value, we may use one or more of the SEARCH_IN_* defines at | 496 | * value, we may use one or more of the SEARCH_IN_* defines at |
497 | * the top of this header-file. It returns the positions of all | 497 | * the top of this header-file. It returns the positions of all |
498 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 498 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
499 | * the function terminates after the first occurence of the entry | 499 | * the function terminates after the first occurence of the entry |
500 | * and doesn't go on searching. So foundPositions->size() is never | 500 | * and doesn't go on searching. So foundPositions->size() is never |
501 | * > 1 if breakAfterFound is true. | 501 | * > 1 if breakAfterFound is true. |
502 | */ | 502 | */ |
503 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 503 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
504 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 504 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
505 | bool caseSensitive = true, bool exactWordMatch = true, | 505 | bool caseSensitive = true, bool exactWordMatch = true, |
506 | bool sortByLvp = false); | 506 | bool sortByLvp = false); |
507 | /** see the above funtion. This function allows to set the category by name. */ | 507 | /** see the above funtion. This function allows to set the category by name. */ |
508 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 508 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
509 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 509 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
510 | bool caseSensitive = true, bool exactWordMatch = true, | 510 | bool caseSensitive = true, bool exactWordMatch = true, |
511 | bool sortByLvp = false); | 511 | bool sortByLvp = false); |
512 | /** returns number of entries */ | 512 | /** returns number of entries */ |
513 | unsigned int numEntries(const QString &category); | 513 | unsigned int numEntries(const QString &category); |
514 | unsigned int numEntries(unsigned int category) | 514 | unsigned int numEntries(unsigned int category) |
515 | { return dti.dta[category].d.size(); } | 515 | { return dti.dta[category].d.size(); } |
516 | /** returns number of categories */ | 516 | /** returns number of categories */ |
517 | unsigned int numCategories() | 517 | unsigned int numCategories() |
518 | { return dti.dta.size(); } | 518 | { return dti.dta.size(); } |
519 | /** returns the name of the category at "index" */ | 519 | /** returns the name of the category at "index" */ |
520 | const string* getCategory(unsigned int index) | 520 | const string* getCategory(unsigned int index) |
521 | { return (&(dti.dta[index].name)); } | 521 | { return (&(dti.dta[index].name)); } |
522 | 522 | ||
523 | /** returns the data of item at "index". | 523 | /** returns the data of item at "index". |
524 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 524 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
525 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 525 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
526 | * the pw. | 526 | * the pw. |
527 | */ | 527 | */ |
528 | bool getEntry(const QString &category, unsigned int index, | 528 | bool getEntry(const QString &category, unsigned int index, |
529 | PwMDataItem *d, bool unlockIfLocked = false); | 529 | PwMDataItem *d, bool unlockIfLocked = false); |
530 | bool getEntry(unsigned int category, unsigned int index, | 530 | bool getEntry(unsigned int category, unsigned int index, |
531 | PwMDataItem *d, bool unlockIfLocked = false); | 531 | PwMDataItem *d, bool unlockIfLocked = false); |
532 | /** returns the comment-string by looking at the category | 532 | /** returns the comment-string by looking at the category |
533 | * and the listViewPos | 533 | * and the listViewPos |
534 | */ | 534 | */ |
535 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 535 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
536 | string *foundComment); | 536 | string *foundComment); |
537 | PwMerror getCommentByLvp_long(const QString &category, int listViewPos, | ||
538 | string *foundComment); | ||
537 | /** checks if a password is already available. (currentPw) */ | 539 | /** checks if a password is already available. (currentPw) */ |
538 | bool isPwAvailable() | 540 | bool isPwAvailable() |
539 | { return (currentPw != ""); } | 541 | { return (currentPw != ""); } |
540 | /** un/lock entry at "index". If needed, ask for password. */ | 542 | /** un/lock entry at "index". If needed, ask for password. */ |
541 | bool lockAt(const QString &category, unsigned int index, | 543 | bool lockAt(const QString &category, unsigned int index, |
542 | bool lock = true); | 544 | bool lock = true); |
543 | bool lockAt(unsigned int category, unsigned int index, | 545 | bool lockAt(unsigned int category, unsigned int index, |
544 | bool lock = true); | 546 | bool lock = true); |
545 | /** returns the lock-status at "index" */ | 547 | /** returns the lock-status at "index" */ |
546 | bool isLocked(const QString &category, unsigned int index); | 548 | bool isLocked(const QString &category, unsigned int index); |
547 | bool isLocked(unsigned int category, unsigned int index) | 549 | bool isLocked(unsigned int category, unsigned int index) |
548 | { return dti.dta[category].d[index].lockStat; } | 550 | { return dti.dta[category].d[index].lockStat; } |
549 | /** returns the deeplock status */ | 551 | /** returns the deeplock status */ |
550 | bool isDeepLocked() | 552 | bool isDeepLocked() |
551 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 553 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
552 | /** (un)lock all entries */ | 554 | /** (un)lock all entries */ |
553 | bool lockAll(bool lock); | 555 | bool lockAll(bool lock); |
554 | /** unlocks all entries tempoarly. | 556 | /** unlocks all entries tempoarly. |
555 | * 1st NOTE: Be very careful with this function! :) | 557 | * 1st NOTE: Be very careful with this function! :) |
556 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 558 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
557 | * please DON'T forget to call unlockAll_Tempoary(true); | 559 | * please DON'T forget to call unlockAll_Tempoary(true); |
558 | * _before_ the user (or someone else) is able to change | 560 | * _before_ the user (or someone else) is able to change |
559 | * the document! | 561 | * the document! |
560 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 562 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
561 | * unlocked! This will cause corruption. | 563 | * unlocked! This will cause corruption. |
562 | */ | 564 | */ |
563 | bool unlockAll_tempoary(bool revert = false); | 565 | bool unlockAll_tempoary(bool revert = false); |
564 | /** deep-(un)locks the document. | 566 | /** deep-(un)locks the document. |
565 | * deep-locking writes all data to the file, deletes all data | 567 | * deep-locking writes all data to the file, deletes all data |
566 | * in memory, but doesn't close the document. | 568 | * in memory, but doesn't close the document. |
567 | * deep-locking is only available, if the user previously saved | 569 | * deep-locking is only available, if the user previously saved |
568 | * the doc to a file (with a password). | 570 | * the doc to a file (with a password). |
569 | * If "saveToFile" is false, it does NOT write the data to the file! | 571 | * If "saveToFile" is false, it does NOT write the data to the file! |
570 | */ | 572 | */ |
571 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 573 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
572 | /** is unlockable without pw? */ | 574 | /** is unlockable without pw? */ |
573 | bool unlockWoPw() | 575 | bool unlockWoPw() |
574 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 576 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
575 | /** get the "currentPassword" */ | 577 | /** get the "currentPassword" */ |
576 | const QString& getCurrentPw() | 578 | const QString& getCurrentPw() |
577 | { return currentPw; } | 579 | { return currentPw; } |
578 | /** open a window and request the user to change the mpw */ | 580 | /** open a window and request the user to change the mpw */ |
579 | void changeCurrentPw(); | 581 | void changeCurrentPw(); |
580 | /** set the "listViewPos" variable of "dta" */ | 582 | /** set the "listViewPos" variable of "dta" */ |
581 | void setListViewPos(const QString &category, unsigned int index, | 583 | void setListViewPos(const QString &category, unsigned int index, |
582 | int pos); | 584 | int pos); |
583 | /** set the "listViewPos" variable of "dta" */ | 585 | /** set the "listViewPos" variable of "dta" */ |
584 | void setListViewPos(unsigned int category, unsigned int index, | 586 | void setListViewPos(unsigned int category, unsigned int index, |
585 | int pos); | 587 | int pos); |
586 | /** get the "listViewPos" variable of "dta" */ | 588 | /** get the "listViewPos" variable of "dta" */ |
587 | int getListViewPos(const QString &category, unsigned int index); | 589 | int getListViewPos(const QString &category, unsigned int index); |
588 | /** set the maximum number of entries allowed */ | 590 | /** set the maximum number of entries allowed */ |
589 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 591 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
590 | { maxEntries = num; } | 592 | { maxEntries = num; } |
591 | /** get the maximum number of entries allowed */ | 593 | /** get the maximum number of entries allowed */ |
592 | unsigned int getMaxNumEntries() | 594 | unsigned int getMaxNumEntries() |
593 | { return maxEntries; } | 595 | { return maxEntries; } |
594 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 596 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
595 | * If there are some undefined entries, add them to the end of | 597 | * If there are some undefined entries, add them to the end of |
596 | * the listViewPos(itions). */ | 598 | * the listViewPos(itions). */ |
597 | void ensureLvp(); | 599 | void ensureLvp(); |
598 | /** execute the "launcher" of this entry */ | 600 | /** execute the "launcher" of this entry */ |
599 | bool execLauncher(const QString &category, unsigned int entryIndex); | 601 | bool execLauncher(const QString &category, unsigned int entryIndex); |
600 | /** see above */ | 602 | /** see above */ |
601 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 603 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
602 | /** open a browser with the URL-section of the given entry */ | 604 | /** open a browser with the URL-section of the given entry */ |
603 | bool goToURL(const QString &category, unsigned int entryIndex); | 605 | bool goToURL(const QString &category, unsigned int entryIndex); |
604 | /** see above */ | 606 | /** see above */ |
605 | bool goToURL(unsigned int category, unsigned int entryIndex); | 607 | bool goToURL(unsigned int category, unsigned int entryIndex); |
606 | /** returns true if there is no entry present in the document. | 608 | /** returns true if there is no entry present in the document. |
607 | * Note: The "default" Category is present everytime, so | 609 | * Note: The "default" Category is present everytime, so |
608 | * it's checked for it's entries. | 610 | * it's checked for it's entries. |
609 | */ | 611 | */ |
610 | bool isDocEmpty() | 612 | bool isDocEmpty() |
611 | { | 613 | { |
612 | if (numCategories() > 1) | 614 | if (numCategories() > 1) |
613 | return false; | 615 | return false; |
614 | if (numEntries(0)) | 616 | if (numEntries(0)) |
615 | return false; | 617 | return false; |
616 | return true; | 618 | return true; |
617 | } | 619 | } |
618 | /** returns the filename of this doc */ | 620 | /** returns the filename of this doc */ |
619 | const QString& getFilename() | 621 | const QString& getFilename() |
620 | { return filename; } | 622 | { return filename; } |
621 | /** returns the title of the doc */ | 623 | /** returns the title of the doc */ |
622 | QString getTitle(); | 624 | QString getTitle(); |
623 | /** sets the list-view-pointer hold in the doc */ | 625 | /** sets the list-view-pointer hold in the doc */ |
624 | void setListViewPointer(PwMView *_listView) | 626 | void setListViewPointer(PwMView *_listView) |
625 | { listView = _listView; } | 627 | { listView = _listView; } |
626 | /** returns the list-view-pointer */ | 628 | /** returns the list-view-pointer */ |
627 | PwMView * getListViewPointer() | 629 | PwMView * getListViewPointer() |
628 | { return listView; } | 630 | { return listView; } |
629 | /** try to delete the doc. The user may be asked to save | 631 | /** try to delete the doc. The user may be asked to save |
630 | * the data. The user may cancel the whole operation. | 632 | * the data. The user may cancel the whole operation. |
631 | * false is returned, then. | 633 | * false is returned, then. |
632 | */ | 634 | */ |
633 | bool tryDelete(); | 635 | bool tryDelete(); |
634 | /** is the doc deleted? (with tryDelete() ) */ | 636 | /** is the doc deleted? (with tryDelete() ) */ |
635 | bool isDeleted() | 637 | bool isDeleted() |
636 | { return deleted; } | 638 | { return deleted; } |
637 | /** returns the document timer object */ | 639 | /** returns the document timer object */ |
638 | DocTimer * timer() | 640 | DocTimer * timer() |
639 | { return _timer; } | 641 | { return _timer; } |
640 | /** get a lock on the dataChanged signal. | 642 | /** get a lock on the dataChanged signal. |
641 | * If someone is holding a lock, the signal is not emitted. | 643 | * If someone is holding a lock, the signal is not emitted. |
642 | */ | 644 | */ |
643 | void getDataChangedLock() | 645 | void getDataChangedLock() |
644 | { ++dataChangedLock; } | 646 | { ++dataChangedLock; } |
645 | /** put the dataChanged lock */ | 647 | /** put the dataChanged lock */ |
646 | void putDataChangedLock() | 648 | void putDataChangedLock() |
647 | { --dataChangedLock; } | 649 | { --dataChangedLock; } |
648 | /** returns the revision count of the item at cat/index */ | 650 | /** returns the revision count of the item at cat/index */ |
649 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 651 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
650 | { return dti.dta[category].d[index].rev; } | 652 | { return dti.dta[category].d[index].rev; } |
651 | /** returns a const pointer to the entries meta */ | 653 | /** returns a const pointer to the entries meta */ |
652 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 654 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
653 | { return &(dti.dta[category].d[index].meta); } | 655 | { return &(dti.dta[category].d[index].meta); } |
654 | /** is the entry at "category" "index" a binary entry? */ | 656 | /** is the entry at "category" "index" a binary entry? */ |
655 | bool isBinEntry(unsigned int category, unsigned int index) | 657 | bool isBinEntry(unsigned int category, unsigned int index) |
656 | { return dti.dta[category].d[index].binary; } | 658 | { return dti.dta[category].d[index].binary; } |
657 | 659 | ||
658 | public slots: | 660 | public slots: |
659 | /** wrapper for PwMTray */ | 661 | /** wrapper for PwMTray */ |
660 | void _deepUnlock(); | 662 | void _deepUnlock(); |
661 | 663 | ||
662 | signals: | 664 | signals: |
663 | /** the data of the document has changed and must be updated | 665 | /** the data of the document has changed and must be updated |
664 | * in all views. | 666 | * in all views. |
665 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 667 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
666 | */ | 668 | */ |
667 | void dataChanged(PwMDoc *document); | 669 | void dataChanged(PwMDoc *document); |
668 | /** the document class is going to close. This signal may be | 670 | /** the document class is going to close. This signal may be |
669 | * used to nofify all views, that the user closed the document, | 671 | * used to nofify all views, that the user closed the document, |
670 | * so the views can go down, too. | 672 | * so the views can go down, too. |
671 | */ | 673 | */ |
672 | void docClosed(PwMDoc *document); | 674 | void docClosed(PwMDoc *document); |
673 | /** somebody just opened the document */ | 675 | /** somebody just opened the document */ |
674 | void docOpened(PwMDoc *document); | 676 | void docOpened(PwMDoc *document); |
675 | /** this document object just got created */ | 677 | /** this document object just got created */ |
676 | void docCreated(PwMDoc *document); | 678 | void docCreated(PwMDoc *document); |
677 | 679 | ||
678 | public: | 680 | public: |
679 | /** emit the dataChanged signal after checking for a lock */ | 681 | /** emit the dataChanged signal after checking for a lock */ |
680 | void emitDataChanged(PwMDoc *document) | 682 | void emitDataChanged(PwMDoc *document) |
681 | { | 683 | { |
682 | if (!dataChangedLock) | 684 | if (!dataChangedLock) |
683 | emit dataChanged(document); | 685 | emit dataChanged(document); |
684 | } | 686 | } |
685 | 687 | ||
686 | protected: | 688 | protected: |
687 | /** current file for this doc */ | 689 | /** current file for this doc */ |
688 | QString filename; | 690 | QString filename; |
689 | //US ENH: we need a place where we keep the syncentries. So I invented | 691 | //US ENH: we need a place where we keep the syncentries. So I invented |
690 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | 692 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem |
691 | /** holds all data */ | 693 | /** holds all data */ |
692 | PwMItem dti; | 694 | PwMItem dti; |
693 | /** maximum number of entries */ | 695 | /** maximum number of entries */ |
694 | unsigned int maxEntries; | 696 | unsigned int maxEntries; |
695 | /** currently used password to encrypt data */ | 697 | /** currently used password to encrypt data */ |
696 | QString currentPw; | 698 | QString currentPw; |
697 | /** current global document status flags */ | 699 | /** current global document status flags */ |
698 | unsigned int curDocStat; | 700 | unsigned int curDocStat; |
699 | /** browser process for goToURL() */ | 701 | /** browser process for goToURL() */ |
700 | KProcess browserProc; | 702 | KProcess browserProc; |
701 | /** pointer to the list-view, using this document. | 703 | /** pointer to the list-view, using this document. |
702 | * As there can only be one list-view per doc, we | 704 | * As there can only be one list-view per doc, we |
703 | * don't need a list here. | 705 | * don't need a list here. |
704 | */ | 706 | */ |
705 | PwMView *listView; | 707 | PwMView *listView; |
706 | /** unnamedNum is used to store the "unnamed counter" | 708 | /** unnamedNum is used to store the "unnamed counter" |
707 | * for this document, while it's unnamed. If it's 0, | 709 | * for this document, while it's unnamed. If it's 0, |
708 | * we have to get a new unique one. | 710 | * we have to get a new unique one. |
709 | */ | 711 | */ |
710 | unsigned int unnamedNum; | 712 | unsigned int unnamedNum; |
711 | /** is this doc going to be deleted (executing in destructor context) */ | 713 | /** is this doc going to be deleted (executing in destructor context) */ |
712 | bool deleted; | 714 | bool deleted; |
713 | /** document timer */ | 715 | /** document timer */ |
714 | DocTimer *_timer; | 716 | DocTimer *_timer; |
715 | /** lock counter for the "dataChanged" signal */ | 717 | /** lock counter for the "dataChanged" signal */ |
716 | unsigned int dataChangedLock; | 718 | unsigned int dataChangedLock; |
717 | 719 | ||
718 | /** list of all open documents */ | 720 | /** list of all open documents */ |
719 | static PwMDocList openDocList; | 721 | static PwMDocList openDocList; |
720 | 722 | ||
721 | protected: | 723 | protected: |
722 | /** serialize "dta" and return it in "d". */ | 724 | /** serialize "dta" and return it in "d". */ |
723 | bool serializeDta(string *d); | 725 | bool serializeDta(string *d); |
724 | /** de-serialize "d" and overwrite "dta" */ | 726 | /** de-serialize "d" and overwrite "dta" */ |
725 | bool deSerializeDta(const string *d, bool entriesLocked); | 727 | bool deSerializeDta(const string *d, bool entriesLocked); |
726 | /** write header to file */ | 728 | /** write header to file */ |
727 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 729 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
728 | QString *pw, QFile *f); | 730 | QString *pw, QFile *f); |
729 | /** write data-hash to file */ | 731 | /** write data-hash to file */ |
730 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 732 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
731 | /** check header. Read header info and verify key-hash and filever. | 733 | /** check header. Read header info and verify key-hash and filever. |
732 | * returns length of header in "headerLength" */ | 734 | * returns length of header in "headerLength" */ |
733 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 735 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
734 | unsigned int *headerLength, char *dataHashType, | 736 | unsigned int *headerLength, char *dataHashType, |
735 | string *dataHash, QFile *f); | 737 | string *dataHash, QFile *f); |
736 | /** check the data-hash */ | 738 | /** check the data-hash */ |
737 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 739 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
738 | /** encrypt data "d" and write to "filename" */ | 740 | /** encrypt data "d" and write to "filename" */ |
739 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo, | 741 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo, |
740 | char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase | 742 | char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase |
741 | ); | 743 | ); |
742 | /** read data from file beginning at "pos", decrypt and return it */ | 744 | /** read data from file beginning at "pos", decrypt and return it */ |
743 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, | 745 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, |
744 | char _hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase | 746 | char _hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase |
745 | QFile *f); | 747 | QFile *f); |
746 | /** compress the data */ | 748 | /** compress the data */ |
747 | bool compressDta(string *d, char algo); | 749 | bool compressDta(string *d, char algo); |
748 | /** uncompress the data */ | 750 | /** uncompress the data */ |
749 | bool decompressDta(string *d, char algo); | 751 | bool decompressDta(string *d, char algo); |
750 | /** internal import function for a text-file generated by PwM. | 752 | /** internal import function for a text-file generated by PwM. |
751 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 753 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
752 | PwMerror importText_PwM(const QString *file); | 754 | PwMerror importText_PwM(const QString *file); |
753 | /** PwM-text-import helper function to extract the name/pw/comment out | 755 | /** PwM-text-import helper function to extract the name/pw/comment out |
754 | * of one entry-line */ | 756 | * of one entry-line */ |
755 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 757 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
756 | /** compare two strings */ | 758 | /** compare two strings */ |
757 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 759 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
758 | bool exactWordMatch); | 760 | bool exactWordMatch); |
759 | /** clears all document-data */ | 761 | /** clears all document-data */ |
760 | void clearDoc(); | 762 | void clearDoc(); |
761 | /** delete all empty categories */ | 763 | /** delete all empty categories */ |
762 | void delAllEmptyCat(bool dontFlagDirty); | 764 | void delAllEmptyCat(bool dontFlagDirty); |
763 | /** set a document status flag */ | 765 | /** set a document status flag */ |
764 | void setDocStatFlag(unsigned int statFlag) | 766 | void setDocStatFlag(unsigned int statFlag) |
765 | { curDocStat |= statFlag; } | 767 | { curDocStat |= statFlag; } |
766 | /** unset a document status flag */ | 768 | /** unset a document status flag */ |
767 | void unsetDocStatFlag(unsigned int statFlag) | 769 | void unsetDocStatFlag(unsigned int statFlag) |
768 | { curDocStat &= ~statFlag; } | 770 | { curDocStat &= ~statFlag; } |
769 | /** get a document status flag */ | 771 | /** get a document status flag */ |
770 | bool getDocStatFlag(unsigned int statFlag) const | 772 | bool getDocStatFlag(unsigned int statFlag) const |
771 | { return (curDocStat & statFlag); } | 773 | { return (curDocStat & statFlag); } |
772 | /** set the "currentPassword" */ | 774 | /** set the "currentPassword" */ |
773 | void setCurrentPw(const QString &pw) | 775 | void setCurrentPw(const QString &pw) |
774 | { | 776 | { |
775 | currentPw = pw; | 777 | currentPw = pw; |
776 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 778 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
777 | } | 779 | } |
778 | /** make a backup-copy of the given file */ | 780 | /** make a backup-copy of the given file */ |
779 | bool backupFile(const QString &filePath); | 781 | bool backupFile(const QString &filePath); |
780 | /** copy a file from src to dst */ | 782 | /** copy a file from src to dst */ |
781 | bool copyFile(const QString &src, const QString &dst); | 783 | bool copyFile(const QString &src, const QString &dst); |
782 | 784 | ||
783 | 785 | ||
784 | public: | 786 | public: |
785 | #ifdef PWM_EMBEDDED | 787 | #ifdef PWM_EMBEDDED |
786 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 788 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
787 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 789 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
788 | 790 | ||
789 | //takePwMDataItem returns the following values | 791 | //takePwMDataItem returns the following values |
790 | // 0 equal | 792 | // 0 equal |
791 | // 1 take local | 793 | // 1 take local |
792 | // 2 take remote | 794 | // 2 take remote |
793 | // 3 cancel | 795 | // 3 cancel |
794 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | 796 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); |
795 | 797 | ||
796 | //the following methods are the overwritten callbackmethods from the syncinterface | 798 | //the following methods are the overwritten callbackmethods from the syncinterface |
797 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 799 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
798 | virtual void removeSyncInfo( QString syncProfile); | 800 | virtual void removeSyncInfo( QString syncProfile); |
799 | 801 | ||
800 | #endif | 802 | #endif |
801 | //US ENH: helpermethods to return a whole category entry | 803 | //US ENH: helpermethods to return a whole category entry |
802 | /** returns a pointer to the categoryitem */ | 804 | /** returns a pointer to the categoryitem */ |
803 | PwMCategoryItem* getCategoryEntry(unsigned int index) | 805 | PwMCategoryItem* getCategoryEntry(unsigned int index) |
804 | { return &(dti.dta[index]); } | 806 | { return &(dti.dta[index]); } |
805 | 807 | ||
806 | private: | 808 | private: |
807 | //US ENH: helpermethods to access the sync data for a certain syncname. | 809 | //US ENH: helpermethods to access the sync data for a certain syncname. |
808 | // It returns the syncdatas index | 810 | // It returns the syncdatas index |
809 | bool findSyncData(const QString &syncname, unsigned int *index); | 811 | bool findSyncData(const QString &syncname, unsigned int *index); |
810 | 812 | ||
811 | /** add new syncdataentry */ | 813 | /** add new syncdataentry */ |
812 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 814 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
813 | 815 | ||
814 | /** returns a pointer to the syncdata */ | 816 | /** returns a pointer to the syncdata */ |
815 | PwMSyncItem* getSyncDataEntry(unsigned int index) | 817 | PwMSyncItem* getSyncDataEntry(unsigned int index) |
816 | { return &(dti.syncDta[index]); } | 818 | { return &(dti.syncDta[index]); } |
817 | 819 | ||
818 | /** delete entry */ | 820 | /** delete entry */ |
819 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 821 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
820 | 822 | ||
821 | /** returns number of categories */ | 823 | /** returns number of categories */ |
822 | unsigned int numSyncDataEntries() | 824 | unsigned int numSyncDataEntries() |
823 | { return dti.syncDta.size(); } | 825 | { return dti.syncDta.size(); } |
824 | 826 | ||
825 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 827 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
826 | 828 | ||
827 | QStringList getIDEntryList(); | 829 | QStringList getIDEntryList(); |
828 | 830 | ||
829 | }; | 831 | }; |
830 | 832 | ||
831 | #endif | 833 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index 7f7dd6f..0092692 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,621 +1,621 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmview.h" | 20 | #include "pwmview.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "globalstuff.h" | 22 | #include "globalstuff.h" |
23 | #include "pwm.h" | 23 | #include "pwm.h" |
24 | #include "rencatwnd.h" | 24 | #include "rencatwnd.h" |
25 | #ifndef PWM_EMBEDDED | 25 | #ifndef PWM_EMBEDDED |
26 | #include "configuration.h" | 26 | #include "configuration.h" |
27 | #else | 27 | #else |
28 | #include "pwmprefs.h" | 28 | #include "pwmprefs.h" |
29 | #endif | 29 | #endif |
30 | #include "commentbox.h" | 30 | #include "commentbox.h" |
31 | 31 | ||
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qpoint.h> | 36 | #include <qpoint.h> |
37 | #include <qapplication.h> | 37 | #include <qapplication.h> |
38 | #include <qlayout.h> | 38 | #include <qlayout.h> |
39 | 39 | ||
40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
41 | //US ENH: for examle in listviewpwm.cpp | 41 | //US ENH: for examle in listviewpwm.cpp |
42 | //US ENH: Because of that I transfer them into the headerfile. | 42 | //US ENH: Because of that I transfer them into the headerfile. |
43 | /* | 43 | /* |
44 | #define COLUMN_DESC 0 | 44 | #define COLUMN_DESC 0 |
45 | #define COLUMN_NAME 1 | 45 | #define COLUMN_NAME 1 |
46 | #define COLUMN_PW 2 | 46 | #define COLUMN_PW 2 |
47 | #define COLUMN_URL 3 | 47 | #define COLUMN_URL 3 |
48 | #define COLUMN_LAUNCHER 4 | 48 | #define COLUMN_LAUNCHER 4 |
49 | */ | 49 | */ |
50 | 50 | ||
51 | PwMView::PwMView(PwM *_mainClass, | 51 | PwMView::PwMView(PwM *_mainClass, |
52 | QWidget *parent, PwMDoc *_doc, | 52 | QWidget *parent, PwMDoc *_doc, |
53 | const char *name) | 53 | const char *name) |
54 | : PwMViewStyle(parent, name) | 54 | : PwMViewStyle(parent, name) |
55 | { | 55 | { |
56 | PWM_ASSERT(_mainClass); | 56 | PWM_ASSERT(_mainClass); |
57 | PWM_ASSERT(parent); | 57 | PWM_ASSERT(parent); |
58 | PWM_ASSERT(_doc); | 58 | PWM_ASSERT(_doc); |
59 | setView(this); | 59 | setView(this); |
60 | doc = _doc; | 60 | doc = _doc; |
61 | doc->setListViewPointer(this); | 61 | doc->setListViewPointer(this); |
62 | mainClass = _mainClass; | 62 | mainClass = _mainClass; |
63 | resize(_mainClass->size()); | 63 | resize(_mainClass->size()); |
64 | initStyle(conf()->confWndMainViewStyle()); | 64 | initStyle(conf()->confWndMainViewStyle()); |
65 | initCtxMenu(); | 65 | initCtxMenu(); |
66 | doc->setCurrentView(this); | 66 | doc->setCurrentView(this); |
67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); | 67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); |
68 | connect(this, SIGNAL(editPW()), mainClass, SLOT(editPwd_slot())); | 68 | connect(this, SIGNAL(editPW()), mainClass, SLOT(editPwd_slot())); |
69 | } | 69 | } |
70 | 70 | ||
71 | PwMView::~PwMView() | 71 | PwMView::~PwMView() |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | void PwMView::initCtxMenu() | 75 | void PwMView::initCtxMenu() |
76 | { | 76 | { |
77 | ctxMenu = new QPopupMenu(this); | 77 | ctxMenu = new QPopupMenu(this); |
78 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); | 78 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); |
79 | ctxMenu->insertSeparator(); | 79 | ctxMenu->insertSeparator(); |
80 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); | 80 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); |
81 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); | 81 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); |
82 | ctxMenu->insertSeparator(); | 82 | ctxMenu->insertSeparator(); |
83 | ctxMenu->insertItem(i18n("copy password to clipboard"), | 83 | ctxMenu->insertItem(i18n("copy password to clipboard"), |
84 | this, SLOT(copyPwToClip())); | 84 | this, SLOT(copyPwToClip())); |
85 | ctxMenu->insertItem(i18n("copy username to clipboard"), | 85 | ctxMenu->insertItem(i18n("copy username to clipboard"), |
86 | this, SLOT(copyNameToClip())); | 86 | this, SLOT(copyNameToClip())); |
87 | ctxMenu->insertItem(i18n("copy description to clipboard"), | 87 | ctxMenu->insertItem(i18n("copy description to clipboard"), |
88 | this, SLOT(copyDescToClip())); | 88 | this, SLOT(copyDescToClip())); |
89 | ctxMenu->insertItem(i18n("copy url to clipboard"), | 89 | ctxMenu->insertItem(i18n("copy url to clipboard"), |
90 | this, SLOT(copyUrlToClip())); | 90 | this, SLOT(copyUrlToClip())); |
91 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), | 91 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), |
92 | this, SLOT(copyLauncherToClip())); | 92 | this, SLOT(copyLauncherToClip())); |
93 | ctxMenu->insertItem(i18n("copy comment to clipboard"), | 93 | ctxMenu->insertItem(i18n("copy comment to clipboard"), |
94 | this, SLOT(copyCommentToClip())); | 94 | this, SLOT(copyCommentToClip())); |
95 | ctxMenu->insertSeparator(); | 95 | ctxMenu->insertSeparator(); |
96 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, | 96 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, |
97 | SLOT(execLauncher_slot())); | 97 | SLOT(execLauncher_slot())); |
98 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, | 98 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, |
99 | SLOT(goToURL_slot())); | 99 | SLOT(goToURL_slot())); |
100 | } | 100 | } |
101 | 101 | ||
102 | void PwMView::resizeEvent(QResizeEvent *) | 102 | void PwMView::resizeEvent(QResizeEvent *) |
103 | { | 103 | { |
104 | resizeView(size()); | 104 | resizeView(size()); |
105 | } | 105 | } |
106 | 106 | ||
107 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) | 107 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) |
108 | { | 108 | { |
109 | PWM_ASSERT(commentBox); | 109 | PWM_ASSERT(commentBox); |
110 | if (!curItem) | 110 | if (!curItem) |
111 | return; | 111 | return; |
112 | string comment; | 112 | string comment; |
113 | PwMerror ret; | 113 | PwMerror ret; |
114 | ret = document()->getCommentByLvp(getCurrentCategory(), | 114 | ret = document()->getCommentByLvp_long(getCurrentCategory(), |
115 | lv->childCount() - lv->itemIndex(curItem) - 1, | 115 | lv->childCount() - lv->itemIndex(curItem) - 1, |
116 | &comment); | 116 | &comment); |
117 | if (ret == e_binEntry) { | 117 | if (ret == e_binEntry) { |
118 | commentBox->setContent(i18n("This is a binary entry.\n" | 118 | commentBox->setContent(i18n("This is a binary entry.\n" |
119 | "It is not a normal password-entry, as it contains " | 119 | "It is not a normal password-entry, as it contains " |
120 | "binary data, which PwManager can't display here.")); | 120 | "binary data, which PwManager can't display here.")); |
121 | } else if (ret == e_normalEntry) { | 121 | } else if (ret == e_normalEntry) { |
122 | commentBox->setContent(comment.c_str()); | 122 | commentBox->setContent(comment.c_str()); |
123 | } else { | 123 | } else { |
124 | BUG(); | 124 | BUG(); |
125 | return; | 125 | return; |
126 | } | 126 | } |
127 | lv->ensureItemVisible(curItem); | 127 | lv->ensureItemVisible(curItem); |
128 | } | 128 | } |
129 | 129 | ||
130 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) | 130 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) |
131 | { | 131 | { |
132 | refreshCommentTextEdit(lv->currentItem()); | 132 | refreshCommentTextEdit(lv->currentItem()); |
133 | } | 133 | } |
134 | 134 | ||
135 | bool PwMView::getCurEntryIndex(unsigned int *index) | 135 | bool PwMView::getCurEntryIndex(unsigned int *index) |
136 | { | 136 | { |
137 | QListViewItem *current = lv->currentItem(); | 137 | QListViewItem *current = lv->currentItem(); |
138 | if (!current) | 138 | if (!current) |
139 | return false; | 139 | return false; |
140 | return getDocEntryIndex(index, current); | 140 | return getDocEntryIndex(index, current); |
141 | } | 141 | } |
142 | 142 | ||
143 | bool PwMView::getDocEntryIndex(unsigned int *index, | 143 | bool PwMView::getDocEntryIndex(unsigned int *index, |
144 | const QListViewItem *item) | 144 | const QListViewItem *item) |
145 | { | 145 | { |
146 | vector<unsigned int> foundPositions; | 146 | vector<unsigned int> foundPositions; |
147 | PwMDataItem curItem; | 147 | PwMDataItem curItem; |
148 | curItem.desc = item->text(COLUMN_DESC).latin1(); | 148 | curItem.desc = item->text(COLUMN_DESC).latin1(); |
149 | curItem.name = item->text(COLUMN_NAME).latin1(); | 149 | curItem.name = item->text(COLUMN_NAME).latin1(); |
150 | document()->getCommentByLvp(getCurrentCategory(), | 150 | document()->getCommentByLvp(getCurrentCategory(), |
151 | lv->childCount() - lv->itemIndex(item) - 1, | 151 | lv->childCount() - lv->itemIndex(item) - 1, |
152 | &curItem.comment); | 152 | &curItem.comment); |
153 | curItem.url = item->text(COLUMN_URL).latin1(); | 153 | curItem.url = item->text(COLUMN_URL).latin1(); |
154 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); | 154 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); |
155 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | | 155 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | |
156 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | | 156 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | |
157 | SEARCH_IN_LAUNCHER, | 157 | SEARCH_IN_LAUNCHER, |
158 | &foundPositions, true); | 158 | &foundPositions, true); |
159 | if (foundPositions.size()) { | 159 | if (foundPositions.size()) { |
160 | *index = foundPositions[0]; | 160 | *index = foundPositions[0]; |
161 | return true; | 161 | return true; |
162 | } | 162 | } |
163 | 163 | ||
164 | return false; | 164 | return false; |
165 | } | 165 | } |
166 | 166 | ||
167 | void PwMView::handleToggle(QListViewItem *item) | 167 | void PwMView::handleToggle(QListViewItem *item) |
168 | { | 168 | { |
169 | PWM_ASSERT(doc); | 169 | PWM_ASSERT(doc); |
170 | if (!item) | 170 | if (!item) |
171 | return; | 171 | return; |
172 | QCheckListItem *clItem = (QCheckListItem *)item; | 172 | QCheckListItem *clItem = (QCheckListItem *)item; |
173 | QString curCat(getCurrentCategory()); | 173 | QString curCat(getCurrentCategory()); |
174 | 174 | ||
175 | // find document position of this entry. | 175 | // find document position of this entry. |
176 | unsigned int curEntryDocIndex; | 176 | unsigned int curEntryDocIndex; |
177 | if (!getDocEntryIndex(&curEntryDocIndex, item)) | 177 | if (!getDocEntryIndex(&curEntryDocIndex, item)) |
178 | return; | 178 | return; |
179 | 179 | ||
180 | // hack to refresh the comment, if only one item is present | 180 | // hack to refresh the comment, if only one item is present |
181 | if (lv->childCount() == 1) | 181 | if (lv->childCount() == 1) |
182 | refreshCommentTextEdit(lv->currentItem()); | 182 | refreshCommentTextEdit(lv->currentItem()); |
183 | 183 | ||
184 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) | 184 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) |
185 | return; // this is just a click somewhere on the entry | 185 | return; // this is just a click somewhere on the entry |
186 | if (doc->isDeepLocked()) { | 186 | if (doc->isDeepLocked()) { |
187 | PwMerror ret; | 187 | PwMerror ret; |
188 | ret = doc->deepLock(false); | 188 | ret = doc->deepLock(false); |
189 | if (ret != e_success) | 189 | if (ret != e_success) |
190 | clItem->setOn(false); | 190 | clItem->setOn(false); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); | 193 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); |
194 | } | 194 | } |
195 | 195 | ||
196 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) | 196 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) |
197 | { | 197 | { |
198 | if (!item) | 198 | if (!item) |
199 | return; | 199 | return; |
200 | ctxMenu->move(point); | 200 | ctxMenu->move(point); |
201 | /* don't use ctxMenu->exec() here, as it generates race conditions | 201 | /* don't use ctxMenu->exec() here, as it generates race conditions |
202 | * with the card interface code. Believe it or not. :) | 202 | * with the card interface code. Believe it or not. :) |
203 | */ | 203 | */ |
204 | ctxMenu->show(); | 204 | ctxMenu->show(); |
205 | } | 205 | } |
206 | 206 | ||
207 | void PwMView::updateCategories() | 207 | void PwMView::updateCategories() |
208 | { | 208 | { |
209 | //qDebug("PwMView::updateCategories() "); | 209 | //qDebug("PwMView::updateCategories() "); |
210 | QString oldSel(getCurrentCategory()); | 210 | QString oldSel(getCurrentCategory()); |
211 | delAllCategories(); | 211 | delAllCategories(); |
212 | QStringList catList; | 212 | QStringList catList; |
213 | document()->getCategoryList(&catList); | 213 | document()->getCategoryList(&catList); |
214 | catList.sort(); | 214 | catList.sort(); |
215 | #ifndef PWM_EMBEDDED | 215 | #ifndef PWM_EMBEDDED |
216 | QStringList::iterator i = catList.begin(), | 216 | QStringList::iterator i = catList.begin(), |
217 | end = catList.end(); | 217 | end = catList.end(); |
218 | #else | 218 | #else |
219 | QStringList::Iterator i = catList.begin(), | 219 | QStringList::Iterator i = catList.begin(), |
220 | end = catList.end(); | 220 | end = catList.end(); |
221 | #endif | 221 | #endif |
222 | while (i != end) { | 222 | while (i != end) { |
223 | addCategory(*i); | 223 | addCategory(*i); |
224 | ++i; | 224 | ++i; |
225 | } | 225 | } |
226 | selectCategory(oldSel); | 226 | selectCategory(oldSel); |
227 | } | 227 | } |
228 | 228 | ||
229 | void PwMView::shiftToView() | 229 | void PwMView::shiftToView() |
230 | { | 230 | { |
231 | int cX = lv->contentsX(); | 231 | int cX = lv->contentsX(); |
232 | int cY = lv->contentsY(); | 232 | int cY = lv->contentsY(); |
233 | commentBox->clear(); | 233 | commentBox->clear(); |
234 | 234 | ||
235 | unsigned int catDocIndex; | 235 | unsigned int catDocIndex; |
236 | if (unlikely( | 236 | if (unlikely( |
237 | !(document()->findCategory(getCurrentCategory(), | 237 | !(document()->findCategory(getCurrentCategory(), |
238 | &catDocIndex)))) { | 238 | &catDocIndex)))) { |
239 | BUG(); | 239 | BUG(); |
240 | } | 240 | } |
241 | 241 | ||
242 | // ensure all listViewPos are set | 242 | // ensure all listViewPos are set |
243 | doc->ensureLvp(); | 243 | doc->ensureLvp(); |
244 | 244 | ||
245 | // clear all tmp-data vectors | 245 | // clear all tmp-data vectors |
246 | unsigned int i, entries = doc->numEntries(catDocIndex); | 246 | unsigned int i, entries = doc->numEntries(catDocIndex); |
247 | if (entries) { | 247 | if (entries) { |
248 | mainClass->setVirgin(false); | 248 | mainClass->setVirgin(false); |
249 | } | 249 | } |
250 | vector<PwMDataItem> tmpSorted; | 250 | vector<PwMDataItem> tmpSorted; |
251 | PwMDataItem currItem; | 251 | PwMDataItem currItem; |
252 | currItem.clear(); | 252 | currItem.clear(); |
253 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); | 253 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); |
254 | 254 | ||
255 | // Sort items and store them in tempoary tmpSorted. | 255 | // Sort items and store them in tempoary tmpSorted. |
256 | for (i = 0; i < entries; ++i) { | 256 | for (i = 0; i < entries; ++i) { |
257 | doc->getEntry(catDocIndex, i, &currItem); | 257 | doc->getEntry(catDocIndex, i, &currItem); |
258 | //qDebug("PwMView::shiftToView: %s, %i", currItem.desc.c_str(), currItem.listViewPos); | 258 | //qDebug("PwMView::shiftToView: %s, %i", currItem.desc.c_str(), currItem.listViewPos); |
259 | tmpSorted[currItem.listViewPos] = currItem; | 259 | tmpSorted[currItem.listViewPos] = currItem; |
260 | } | 260 | } |
261 | 261 | ||
262 | // shift tempoary data to ListView. | 262 | // shift tempoary data to ListView. |
263 | tmpDisableSort(); | 263 | tmpDisableSort(); |
264 | lv->clear(); | 264 | lv->clear(); |
265 | 265 | ||
266 | //US ENH: adjust the headers of the table according the category texts | 266 | //US ENH: adjust the headers of the table according the category texts |
267 | { | 267 | { |
268 | PwMCategoryItem* catItem = doc->getCategoryEntry(catDocIndex); | 268 | PwMCategoryItem* catItem = doc->getCategoryEntry(catDocIndex); |
269 | // qDebug("PwMView::ShiftToView CAT: %i, %s", catDocIndex, catItem->name.c_str()); | 269 | // qDebug("PwMView::ShiftToView CAT: %i, %s", catDocIndex, catItem->name.c_str()); |
270 | lv->setColumnText(COLUMN_DESC, catItem->desc_text.c_str()); | 270 | lv->setColumnText(COLUMN_DESC, catItem->desc_text.c_str()); |
271 | lv->setColumnText(COLUMN_NAME, catItem->name_text.c_str()); | 271 | lv->setColumnText(COLUMN_NAME, catItem->name_text.c_str()); |
272 | lv->setColumnText(COLUMN_PW, catItem->pw_text.c_str()); | 272 | lv->setColumnText(COLUMN_PW, catItem->pw_text.c_str()); |
273 | } | 273 | } |
274 | 274 | ||
275 | QCheckListItem *newItem; | 275 | QCheckListItem *newItem; |
276 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), | 276 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), |
277 | end = tmpSorted.end(); | 277 | end = tmpSorted.end(); |
278 | while (it != end) { | 278 | while (it != end) { |
279 | newItem = new ListViewItemPwM(lv); | 279 | newItem = new ListViewItemPwM(lv); |
280 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 280 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
281 | if ((*it).binary) { | 281 | if ((*it).binary) { |
282 | newItem->setText(COLUMN_NAME, ""); | 282 | newItem->setText(COLUMN_NAME, ""); |
283 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 283 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
284 | newItem->setText(COLUMN_URL, ""); | 284 | newItem->setText(COLUMN_URL, ""); |
285 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 285 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
286 | } else { | 286 | } else { |
287 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 287 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
288 | if ((*it).lockStat) { | 288 | if ((*it).lockStat) { |
289 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 289 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
290 | + " " | 290 | + " " |
291 | + i18n("To unlock click the icon on the left.")); | 291 | + i18n("To unlock click the icon on the left.")); |
292 | } else { | 292 | } else { |
293 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 293 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
294 | } | 294 | } |
295 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 295 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
296 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 296 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
297 | } | 297 | } |
298 | newItem->setOn(!((*it).lockStat)); | 298 | newItem->setOn(!((*it).lockStat)); |
299 | lv->insertItem(newItem); | 299 | lv->insertItem(newItem); |
300 | ++it; | 300 | ++it; |
301 | } | 301 | } |
302 | tmpReEnableSort(); | 302 | tmpReEnableSort(); |
303 | 303 | ||
304 | if (cY || cX) | 304 | if (cY || cX) |
305 | lv->setContentsPos(cX, cY); | 305 | lv->setContentsPos(cX, cY); |
306 | } | 306 | } |
307 | 307 | ||
308 | void PwMView::reorgLp() | 308 | void PwMView::reorgLp() |
309 | { | 309 | { |
310 | if (!lv->childCount()) | 310 | if (!lv->childCount()) |
311 | return; | 311 | return; |
312 | PWM_ASSERT(doc); | 312 | PWM_ASSERT(doc); |
313 | PWM_ASSERT(!doc->isDocEmpty()); | 313 | PWM_ASSERT(!doc->isDocEmpty()); |
314 | QListViewItem *currItem; | 314 | QListViewItem *currItem; |
315 | vector<unsigned int> foundPos; | 315 | vector<unsigned int> foundPos; |
316 | /* This searchIn _should_ be: | 316 | /* This searchIn _should_ be: |
317 | *const unsigned int searchIn = SEARCH_IN_DESC; | 317 | *const unsigned int searchIn = SEARCH_IN_DESC; |
318 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 318 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
319 | * So we need to search again, if we don't find the entry. (see below) | 319 | * So we need to search again, if we don't find the entry. (see below) |
320 | */ | 320 | */ |
321 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 321 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
322 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 322 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
323 | QString curCat(getCurrentCategory()); | 323 | QString curCat(getCurrentCategory()); |
324 | PwMDataItem findThis; | 324 | PwMDataItem findThis; |
325 | unsigned int i, cnt = lv->childCount(); | 325 | unsigned int i, cnt = lv->childCount(); |
326 | for (i = 0; i < cnt; ++i) { | 326 | for (i = 0; i < cnt; ++i) { |
327 | currItem = lv->itemAtIndex(i); | 327 | currItem = lv->itemAtIndex(i); |
328 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 328 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
329 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 329 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
330 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 330 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
331 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 331 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
332 | doc->findEntry(curCat, findThis, searchIn, | 332 | doc->findEntry(curCat, findThis, searchIn, |
333 | &foundPos, true); | 333 | &foundPos, true); |
334 | if (!foundPos.size()) { | 334 | if (!foundPos.size()) { |
335 | /* Did not find the entry. We seem to have a binary | 335 | /* Did not find the entry. We seem to have a binary |
336 | * entry here (pray for it!). So search again with | 336 | * entry here (pray for it!). So search again with |
337 | * the "correct" searchIn flags. | 337 | * the "correct" searchIn flags. |
338 | */ | 338 | */ |
339 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 339 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
340 | doc->findEntry(curCat, findThis, searchIn2, | 340 | doc->findEntry(curCat, findThis, searchIn2, |
341 | &foundPos, true); | 341 | &foundPos, true); |
342 | if (unlikely(!foundPos.size())) { | 342 | if (unlikely(!foundPos.size())) { |
343 | BUG(); | 343 | BUG(); |
344 | continue; | 344 | continue; |
345 | } | 345 | } |
346 | /* We assert that it's a binary entry, now. | 346 | /* We assert that it's a binary entry, now. |
347 | * No chance to efficiently verify it here. | 347 | * No chance to efficiently verify it here. |
348 | */ | 348 | */ |
349 | } | 349 | } |
350 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 350 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
351 | } | 351 | } |
352 | } | 352 | } |
353 | 353 | ||
354 | void PwMView::selAt(int index) | 354 | void PwMView::selAt(int index) |
355 | { | 355 | { |
356 | QListViewItem *item = lv->itemAtIndex(index); | 356 | QListViewItem *item = lv->itemAtIndex(index); |
357 | if (!item) | 357 | if (!item) |
358 | return; | 358 | return; |
359 | lv->setCurrentItem(item); | 359 | lv->setCurrentItem(item); |
360 | lv->ensureItemVisible(item); | 360 | lv->ensureItemVisible(item); |
361 | } | 361 | } |
362 | 362 | ||
363 | void PwMView::renCatButton_slot() | 363 | void PwMView::renCatButton_slot() |
364 | { | 364 | { |
365 | if (doc->isDeepLocked()) | 365 | if (doc->isDeepLocked()) |
366 | return; | 366 | return; |
367 | RenCatWnd wnd(this); | 367 | RenCatWnd wnd(this); |
368 | if (wnd.exec() == 1) { | 368 | if (wnd.exec() == 1) { |
369 | QString newName(wnd.getNewName()); | 369 | QString newName(wnd.getNewName()); |
370 | if (newName == "") | 370 | if (newName == "") |
371 | return; | 371 | return; |
372 | document()->renameCategory(getCurrentCategory(), | 372 | document()->renameCategory(getCurrentCategory(), |
373 | newName); | 373 | newName); |
374 | } | 374 | } |
375 | } | 375 | } |
376 | 376 | ||
377 | void PwMView::delCatButton_slot() | 377 | void PwMView::delCatButton_slot() |
378 | { | 378 | { |
379 | if (doc->isDeepLocked()) | 379 | if (doc->isDeepLocked()) |
380 | return; | 380 | return; |
381 | if (numCategories() <= 1) { | 381 | if (numCategories() <= 1) { |
382 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 382 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
383 | return; | 383 | return; |
384 | } | 384 | } |
385 | if (KMessageBox::questionYesNo(this, | 385 | if (KMessageBox::questionYesNo(this, |
386 | i18n("Do you really want to\n" | 386 | i18n("Do you really want to\n" |
387 | "delete the selected\n" | 387 | "delete the selected\n" |
388 | "category? All password-\n" | 388 | "category? All password-\n" |
389 | "entries will be lost in\n" | 389 | "entries will be lost in\n" |
390 | "this category!\n"), | 390 | "this category!\n"), |
391 | i18n("Delete category?")) | 391 | i18n("Delete category?")) |
392 | == KMessageBox::No) { | 392 | == KMessageBox::No) { |
393 | return; | 393 | return; |
394 | } | 394 | } |
395 | document()->delCategory(getCurrentCategory()); | 395 | document()->delCategory(getCurrentCategory()); |
396 | } | 396 | } |
397 | 397 | ||
398 | void PwMView::copyPwToClip() | 398 | void PwMView::copyPwToClip() |
399 | { | 399 | { |
400 | if (doc->isDeepLocked()) | 400 | if (doc->isDeepLocked()) |
401 | return; | 401 | return; |
402 | unsigned int curIndex = 0; | 402 | unsigned int curIndex = 0; |
403 | if (!getCurEntryIndex(&curIndex)) | 403 | if (!getCurEntryIndex(&curIndex)) |
404 | return; | 404 | return; |
405 | PwMDataItem d; | 405 | PwMDataItem d; |
406 | document()->getDataChangedLock(); | 406 | document()->getDataChangedLock(); |
407 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 407 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
408 | document()->putDataChangedLock(); | 408 | document()->putDataChangedLock(); |
409 | PwM::copyToClipboard(d.pw.c_str()); | 409 | PwM::copyToClipboard(d.pw.c_str()); |
410 | } | 410 | } |
411 | 411 | ||
412 | void PwMView::copyNameToClip() | 412 | void PwMView::copyNameToClip() |
413 | { | 413 | { |
414 | if (doc->isDeepLocked()) | 414 | if (doc->isDeepLocked()) |
415 | return; | 415 | return; |
416 | unsigned int curIndex = 0; | 416 | unsigned int curIndex = 0; |
417 | if (!getCurEntryIndex(&curIndex)) | 417 | if (!getCurEntryIndex(&curIndex)) |
418 | return; | 418 | return; |
419 | PwMDataItem d; | 419 | PwMDataItem d; |
420 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 420 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
421 | PwM::copyToClipboard(d.name.c_str()); | 421 | PwM::copyToClipboard(d.name.c_str()); |
422 | } | 422 | } |
423 | 423 | ||
424 | void PwMView::copyDescToClip() | 424 | void PwMView::copyDescToClip() |
425 | { | 425 | { |
426 | if (doc->isDeepLocked()) | 426 | if (doc->isDeepLocked()) |
427 | return; | 427 | return; |
428 | unsigned int curIndex = 0; | 428 | unsigned int curIndex = 0; |
429 | if (!getCurEntryIndex(&curIndex)) | 429 | if (!getCurEntryIndex(&curIndex)) |
430 | return; | 430 | return; |
431 | PwMDataItem d; | 431 | PwMDataItem d; |
432 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 432 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
433 | PwM::copyToClipboard(d.desc.c_str()); | 433 | PwM::copyToClipboard(d.desc.c_str()); |
434 | } | 434 | } |
435 | 435 | ||
436 | void PwMView::copyUrlToClip() | 436 | void PwMView::copyUrlToClip() |
437 | { | 437 | { |
438 | if (doc->isDeepLocked()) | 438 | if (doc->isDeepLocked()) |
439 | return; | 439 | return; |
440 | unsigned int curIndex = 0; | 440 | unsigned int curIndex = 0; |
441 | if (!getCurEntryIndex(&curIndex)) | 441 | if (!getCurEntryIndex(&curIndex)) |
442 | return; | 442 | return; |
443 | PwMDataItem d; | 443 | PwMDataItem d; |
444 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 444 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
445 | PwM::copyToClipboard(d.url.c_str()); | 445 | PwM::copyToClipboard(d.url.c_str()); |
446 | } | 446 | } |
447 | 447 | ||
448 | void PwMView::copyLauncherToClip() | 448 | void PwMView::copyLauncherToClip() |
449 | { | 449 | { |
450 | if (doc->isDeepLocked()) | 450 | if (doc->isDeepLocked()) |
451 | return; | 451 | return; |
452 | unsigned int curIndex = 0; | 452 | unsigned int curIndex = 0; |
453 | if (!getCurEntryIndex(&curIndex)) | 453 | if (!getCurEntryIndex(&curIndex)) |
454 | return; | 454 | return; |
455 | PwMDataItem d; | 455 | PwMDataItem d; |
456 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 456 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
457 | PwM::copyToClipboard(d.launcher.c_str()); | 457 | PwM::copyToClipboard(d.launcher.c_str()); |
458 | } | 458 | } |
459 | 459 | ||
460 | void PwMView::copyCommentToClip() | 460 | void PwMView::copyCommentToClip() |
461 | { | 461 | { |
462 | if (doc->isDeepLocked()) | 462 | if (doc->isDeepLocked()) |
463 | return; | 463 | return; |
464 | unsigned int curIndex = 0; | 464 | unsigned int curIndex = 0; |
465 | if (!getCurEntryIndex(&curIndex)) | 465 | if (!getCurEntryIndex(&curIndex)) |
466 | return; | 466 | return; |
467 | PwMDataItem d; | 467 | PwMDataItem d; |
468 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 468 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
469 | PwM::copyToClipboard(d.comment.c_str()); | 469 | PwM::copyToClipboard(d.comment.c_str()); |
470 | } | 470 | } |
471 | 471 | ||
472 | /************************************************************************ | 472 | /************************************************************************ |
473 | * | 473 | * |
474 | * | 474 | * |
475 | * | 475 | * |
476 | ************************************************************************/ | 476 | ************************************************************************/ |
477 | 477 | ||
478 | 478 | ||
479 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) | 479 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) |
480 | : QTextBrowser( parent, name ) | 480 | : QTextBrowser( parent, name ) |
481 | 481 | ||
482 | 482 | ||
483 | { | 483 | { |
484 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); | 484 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); |
485 | setLinkUnderline( false ); | 485 | setLinkUnderline( false ); |
486 | // setVScrollBarMode( QScrollView::AlwaysOff ); | 486 | // setVScrollBarMode( QScrollView::AlwaysOff ); |
487 | //setHScrollBarMode( QScrollView::AlwaysOff ); | 487 | //setHScrollBarMode( QScrollView::AlwaysOff ); |
488 | 488 | ||
489 | //US QStyleSheet *sheet = styleSheet(); | 489 | //US QStyleSheet *sheet = styleSheet(); |
490 | //US QStyleSheetItem *link = sheet->item( "a" ); | 490 | //US QStyleSheetItem *link = sheet->item( "a" ); |
491 | //US link->setColor( KGlobalSettings::linkColor() ); | 491 | //US link->setColor( KGlobalSettings::linkColor() ); |
492 | 492 | ||
493 | } | 493 | } |
494 | 494 | ||
495 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) | 495 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) |
496 | 496 | ||
497 | { | 497 | { |
498 | mItem = a; | 498 | mItem = a; |
499 | // clear view | 499 | // clear view |
500 | setText( QString::null ); | 500 | setText( QString::null ); |
501 | 501 | ||
502 | 502 | ||
503 | QString dynamicPart; | 503 | QString dynamicPart; |
504 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" | 504 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" |
505 | "<td align=\"left\">%2</td></tr>"; | 505 | "<td align=\"left\">%2</td></tr>"; |
506 | 506 | ||
507 | dynamicPart += format | 507 | dynamicPart += format |
508 | .arg( i18n("LastUpdate") ) | 508 | .arg( i18n("LastUpdate") ) |
509 | .arg( mItem.meta.update.toString().latin1() ); | 509 | .arg( mItem.meta.update.toString().latin1() ); |
510 | 510 | ||
511 | dynamicPart += format | 511 | dynamicPart += format |
512 | .arg( i18n("Description") ) | 512 | .arg( i18n("Description") ) |
513 | .arg( mItem.desc.c_str() ); | 513 | .arg( mItem.desc.c_str() ); |
514 | 514 | ||
515 | dynamicPart += format | 515 | dynamicPart += format |
516 | .arg( i18n("Name") ) | 516 | .arg( i18n("Name") ) |
517 | .arg( mItem.name.c_str() ); | 517 | .arg( mItem.name.c_str() ); |
518 | 518 | ||
519 | dynamicPart += format | 519 | dynamicPart += format |
520 | .arg( i18n("Password") ) | 520 | .arg( i18n("Password") ) |
521 | .arg( mItem.pw.c_str() ); | 521 | .arg( mItem.pw.c_str() ); |
522 | 522 | ||
523 | QString comment(mItem.pw.c_str()); | 523 | QString comment(mItem.pw.c_str()); |
524 | dynamicPart += format | 524 | dynamicPart += format |
525 | .arg( i18n("Comment") ) | 525 | .arg( i18n("Comment") ) |
526 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); | 526 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); |
527 | 527 | ||
528 | dynamicPart += format | 528 | dynamicPart += format |
529 | .arg( i18n("URL") ) | 529 | .arg( i18n("URL") ) |
530 | .arg( mItem.url.c_str() ); | 530 | .arg( mItem.url.c_str() ); |
531 | 531 | ||
532 | dynamicPart += format | 532 | dynamicPart += format |
533 | .arg( i18n("Launcher") ) | 533 | .arg( i18n("Launcher") ) |
534 | .arg( mItem.launcher.c_str() ); | 534 | .arg( mItem.launcher.c_str() ); |
535 | 535 | ||
536 | QString mText = "<table><td colspan=\"2\"> </td>"; | 536 | QString mText = "<table><td colspan=\"2\"> </td>"; |
537 | 537 | ||
538 | mText += dynamicPart; | 538 | mText += dynamicPart; |
539 | mText += "</table>"; | 539 | mText += "</table>"; |
540 | 540 | ||
541 | // at last display it... | 541 | // at last display it... |
542 | setText( mText ); | 542 | setText( mText ); |
543 | 543 | ||
544 | } | 544 | } |
545 | 545 | ||
546 | PwMDataItem PwMDataItemView::pwmdataitem() const | 546 | PwMDataItem PwMDataItemView::pwmdataitem() const |
547 | { | 547 | { |
548 | return mItem; | 548 | return mItem; |
549 | } | 549 | } |
550 | 550 | ||
551 | /************************************************************************ | 551 | /************************************************************************ |
552 | * | 552 | * |
553 | * | 553 | * |
554 | * | 554 | * |
555 | ************************************************************************/ | 555 | ************************************************************************/ |
556 | 556 | ||
557 | 557 | ||
558 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) | 558 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) |
559 | : KDialogBase(parent, name, true , | 559 | : KDialogBase(parent, name, true , |
560 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | 560 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) |
561 | { | 561 | { |
562 | findButton( Close )->setText( i18n("Cancel Sync")); | 562 | findButton( Close )->setText( i18n("Cancel Sync")); |
563 | findButton( Ok )->setText( i18n("Remote")); | 563 | findButton( Ok )->setText( i18n("Remote")); |
564 | findButton( User1 )->setText( i18n("Local")); | 564 | findButton( User1 )->setText( i18n("Local")); |
565 | QWidget* topframe = new QWidget( this ); | 565 | QWidget* topframe = new QWidget( this ); |
566 | setMainWidget( topframe ); | 566 | setMainWidget( topframe ); |
567 | QBoxLayout* bl; | 567 | QBoxLayout* bl; |
568 | if ( QApplication::desktop()->width() < 640 ) { | 568 | if ( QApplication::desktop()->width() < 640 ) { |
569 | bl = new QVBoxLayout( topframe ); | 569 | bl = new QVBoxLayout( topframe ); |
570 | } else { | 570 | } else { |
571 | bl = new QHBoxLayout( topframe ); | 571 | bl = new QHBoxLayout( topframe ); |
572 | } | 572 | } |
573 | QVBox* subframe = new QVBox( topframe ); | 573 | QVBox* subframe = new QVBox( topframe ); |
574 | bl->addWidget(subframe ); | 574 | bl->addWidget(subframe ); |
575 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | 575 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); |
576 | if ( takeloc ) | 576 | if ( takeloc ) |
577 | lab->setBackgroundColor(Qt::green.light() ); | 577 | lab->setBackgroundColor(Qt::green.light() ); |
578 | PwMDataItemView * av = new PwMDataItemView( subframe ); | 578 | PwMDataItemView * av = new PwMDataItemView( subframe ); |
579 | av->setPwMDataItem( loc ); | 579 | av->setPwMDataItem( loc ); |
580 | subframe = new QVBox( topframe ); | 580 | subframe = new QVBox( topframe ); |
581 | bl->addWidget(subframe ); | 581 | bl->addWidget(subframe ); |
582 | lab = new QLabel( i18n("Remote Entry"), subframe ); | 582 | lab = new QLabel( i18n("Remote Entry"), subframe ); |
583 | if ( !takeloc ) | 583 | if ( !takeloc ) |
584 | lab->setBackgroundColor(Qt::green.light() ); | 584 | lab->setBackgroundColor(Qt::green.light() ); |
585 | av = new PwMDataItemView( subframe ); | 585 | av = new PwMDataItemView( subframe ); |
586 | av->setPwMDataItem( rem ); | 586 | av->setPwMDataItem( rem ); |
587 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | 587 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); |
588 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | 588 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); |
589 | #ifndef DESKTOP_VERSION | 589 | #ifndef DESKTOP_VERSION |
590 | showMaximized(); | 590 | showMaximized(); |
591 | #else | 591 | #else |
592 | resize ( 640, 400 ); | 592 | resize ( 640, 400 ); |
593 | #endif | 593 | #endif |
594 | } | 594 | } |
595 | 595 | ||
596 | int PwMDataItemChooser::executeD( bool local ) | 596 | int PwMDataItemChooser::executeD( bool local ) |
597 | { | 597 | { |
598 | mSyncResult = 3; | 598 | mSyncResult = 3; |
599 | if ( local ) | 599 | if ( local ) |
600 | findButton( User1 )->setFocus(); | 600 | findButton( User1 )->setFocus(); |
601 | else | 601 | else |
602 | findButton( Ok )->setFocus(); | 602 | findButton( Ok )->setFocus(); |
603 | exec(); | 603 | exec(); |
604 | return mSyncResult; | 604 | return mSyncResult; |
605 | } | 605 | } |
606 | void PwMDataItemChooser::slot_remote() | 606 | void PwMDataItemChooser::slot_remote() |
607 | { | 607 | { |
608 | mSyncResult = 2; | 608 | mSyncResult = 2; |
609 | accept(); | 609 | accept(); |
610 | } | 610 | } |
611 | void PwMDataItemChooser::slot_local() | 611 | void PwMDataItemChooser::slot_local() |
612 | { | 612 | { |
613 | mSyncResult = 1; | 613 | mSyncResult = 1; |
614 | accept(); | 614 | accept(); |
615 | } | 615 | } |
616 | 616 | ||
617 | 617 | ||
618 | 618 | ||
619 | #ifndef PWM_EMBEDDED | 619 | #ifndef PWM_EMBEDDED |
620 | #include "pwmview.moc" | 620 | #include "pwmview.moc" |
621 | #endif | 621 | #endif |
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.cpp b/pwmanager/pwmanager/pwmviewstyle_0.cpp index 1fc8a34..d82eb15 100644 --- a/pwmanager/pwmanager/pwmviewstyle_0.cpp +++ b/pwmanager/pwmanager/pwmviewstyle_0.cpp | |||
@@ -1,112 +1,132 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmviewstyle_0.h" | 20 | #include "pwmviewstyle_0.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "listviewpwm.h" | 22 | #include "listviewpwm.h" |
23 | #include "commentbox.h" | 23 | #include "commentbox.h" |
24 | 24 | ||
25 | #include <klocale.h> | 25 | #include <klocale.h> |
26 | #include "pwmprefs.h" | 26 | #include "pwmprefs.h" |
27 | 27 | ||
28 | PwMViewStyle_0::PwMViewStyle_0(PwMView *view) | 28 | PwMViewStyle_0::PwMViewStyle_0(PwMView *view) |
29 | : QObject() | 29 | : QObject() |
30 | { | 30 | { |
31 | vbox1 = new QVBox(view); | 31 | vbox1 = new QVBox(view); |
32 | vbox1->setSpacing(3); | 32 | vbox1->setSpacing(3); |
33 | hbox1 = new QHBox(vbox1); | 33 | hbox1 = new QHBox(vbox1); |
34 | hbox1->setSpacing(3); | 34 | hbox1->setSpacing(3); |
35 | categoriesTitle = new QLabel(hbox1); | 35 | categoriesTitle = new QLabel(hbox1); |
36 | categoriesTitle->setText(i18n("Categories:")); | 36 | categoriesTitle->setText(i18n("Categories:")); |
37 | categoriesCombo = new QComboBox(hbox1); | 37 | categoriesCombo = new QComboBox(hbox1); |
38 | renCatButton = new QPushButton(i18n("&Rename"), hbox1); | 38 | renCatButton = new QPushButton(i18n("&Rename"), hbox1); |
39 | delCatButton = new QPushButton(i18n("&Delete"), hbox1); | 39 | delCatButton = new QPushButton(i18n("&Delete"), hbox1); |
40 | #ifndef PWM_EMBEDDED | 40 | #ifndef PWM_EMBEDDED |
41 | splitter1 = new QSplitter(vbox1); | 41 | splitter1 = new QSplitter(vbox1); |
42 | splitter1->setOrientation(Qt::Vertical); | 42 | splitter1->setOrientation(Qt::Vertical); |
43 | #else | 43 | #else |
44 | splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1); | 44 | splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1); |
45 | splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 45 | splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
46 | 46 | ||
47 | //US topLayout->addWidget(mMiniSplitter ); | 47 | //US topLayout->addWidget(mMiniSplitter ); |
48 | #endif | 48 | #endif |
49 | lv = new ListViewPwM(splitter1); | 49 | lv = new ListViewPwM(splitter1); |
50 | commentBox = new CommentBox(splitter1); | 50 | commentBox = new CommentBox(splitter1); |
51 | // set sizes and styles | 51 | // set sizes and styles |
52 | commentBox->resize(commentBox->size().width(), 60); | 52 | commentBox->resize(commentBox->size().width(), 60); |
53 | categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight); | 53 | categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight); |
54 | // connections | 54 | // connections |
55 | connect(categoriesCombo, SIGNAL(activated(int)), | 55 | connect(categoriesCombo, SIGNAL(activated(int)), |
56 | view, SLOT(shiftToView())); | 56 | view, SLOT(shiftToView())); |
57 | connect(renCatButton, SIGNAL(clicked()), | 57 | connect(renCatButton, SIGNAL(clicked()), |
58 | view, SLOT(renCatButton_slot())); | 58 | view, SLOT(renCatButton_slot())); |
59 | connect(delCatButton, SIGNAL(clicked()), | 59 | connect(delCatButton, SIGNAL(clicked()), |
60 | view, SLOT(delCatButton_slot())); | 60 | view, SLOT(delCatButton_slot())); |
61 | connect(lv, SIGNAL(toggleOverview()), | ||
62 | this, SLOT(toggleSplitter())); | ||
61 | } | 63 | } |
62 | 64 | ||
63 | PwMViewStyle_0::~PwMViewStyle_0() | 65 | PwMViewStyle_0::~PwMViewStyle_0() |
64 | { | 66 | { |
65 | delete vbox1; | 67 | delete vbox1; |
66 | } | 68 | } |
69 | void PwMViewStyle_0::toggleSplitter() | ||
70 | { | ||
71 | |||
72 | QValueList<int> si = splitter1->sizes(); | ||
73 | splitter1->toggle(); | ||
74 | QValueList<int> si2 = splitter1->sizes(); | ||
75 | //qDebug("PwMViewStyle_0::toggleSplitter() %d %d %d %d", si[0],si[1],si2[0],si2[1] ); | ||
76 | if ( si[0] == si2[0] && si[1] == si2[1] && si2[1] == 1 ) { | ||
77 | int diff = si[0]/2; | ||
78 | if ( diff > 200 ) | ||
79 | diff = 200; | ||
80 | si[0] -= diff; | ||
81 | si[1] += diff; | ||
82 | splitter1->toggle(); | ||
83 | splitter1->setSizes( si ); | ||
84 | } | ||
85 | |||
86 | } | ||
67 | 87 | ||
68 | void PwMViewStyle_0::delCategory(const QString &cat) | 88 | void PwMViewStyle_0::delCategory(const QString &cat) |
69 | { | 89 | { |
70 | PWM_ASSERT(categoriesCombo); | 90 | PWM_ASSERT(categoriesCombo); |
71 | int i, count = categoriesCombo->count(); | 91 | int i, count = categoriesCombo->count(); |
72 | for (i = 0; i < count; ++i) { | 92 | for (i = 0; i < count; ++i) { |
73 | if (categoriesCombo->text(i) == cat) { | 93 | if (categoriesCombo->text(i) == cat) { |
74 | categoriesCombo->removeItem(i); | 94 | categoriesCombo->removeItem(i); |
75 | return; | 95 | return; |
76 | } | 96 | } |
77 | } | 97 | } |
78 | BUG(); | 98 | BUG(); |
79 | } | 99 | } |
80 | 100 | ||
81 | void PwMViewStyle_0::selectCategory(const QString &cat) | 101 | void PwMViewStyle_0::selectCategory(const QString &cat) |
82 | { | 102 | { |
83 | PWM_ASSERT(categoriesCombo); | 103 | PWM_ASSERT(categoriesCombo); |
84 | int i, count = categoriesCombo->count(); | 104 | int i, count = categoriesCombo->count(); |
85 | for (i = 0; i < count; ++i) { | 105 | for (i = 0; i < count; ++i) { |
86 | if (categoriesCombo->text(i) == cat) { | 106 | if (categoriesCombo->text(i) == cat) { |
87 | categoriesCombo->setCurrentItem(i); | 107 | categoriesCombo->setCurrentItem(i); |
88 | return; | 108 | return; |
89 | } | 109 | } |
90 | } | 110 | } |
91 | // fall back to 0 | 111 | // fall back to 0 |
92 | categoriesCombo->setCurrentItem(0); | 112 | categoriesCombo->setCurrentItem(0); |
93 | } | 113 | } |
94 | 114 | ||
95 | 115 | ||
96 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 116 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
97 | void PwMViewStyle_0::restoreSettings(PWMPrefs* prefs) | 117 | void PwMViewStyle_0::restoreSettings(PWMPrefs* prefs) |
98 | { | 118 | { |
99 | //load and store the size of the listviewcolumns | 119 | //load and store the size of the listviewcolumns |
100 | lv->restoreLayout(prefs->getConfig(), "listview"); | 120 | lv->restoreLayout(prefs->getConfig(), "listview"); |
101 | splitter1->setSizes( prefs->mCommentSplitter ); | 121 | splitter1->setSizes( prefs->mCommentSplitter ); |
102 | commentBox->setFont( prefs->mViewFont ); | 122 | commentBox->setFont( prefs->mViewFont ); |
103 | } | 123 | } |
104 | 124 | ||
105 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 125 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
106 | void PwMViewStyle_0::saveSettings(PWMPrefs* prefs) | 126 | void PwMViewStyle_0::saveSettings(PWMPrefs* prefs) |
107 | { | 127 | { |
108 | //store the size of the listviewcolumns | 128 | //store the size of the listviewcolumns |
109 | lv->saveLayout(prefs->getConfig(), "listview"); | 129 | lv->saveLayout(prefs->getConfig(), "listview"); |
110 | prefs->mCommentSplitter = splitter1->sizes(); | 130 | prefs->mCommentSplitter = splitter1->sizes(); |
111 | 131 | ||
112 | } | 132 | } |
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.h b/pwmanager/pwmanager/pwmviewstyle_0.h index bd93c06..6d3c1d1 100644 --- a/pwmanager/pwmanager/pwmviewstyle_0.h +++ b/pwmanager/pwmanager/pwmviewstyle_0.h | |||
@@ -1,105 +1,107 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef PWMVIEWSTYLE_0_H | 20 | #ifndef PWMVIEWSTYLE_0_H |
21 | #define PWMVIEWSTYLE_0_H | 21 | #define PWMVIEWSTYLE_0_H |
22 | 22 | ||
23 | #include <qhbox.h> | 23 | #include <qhbox.h> |
24 | #include <qvbox.h> | 24 | #include <qvbox.h> |
25 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
26 | #ifndef PWM_EMBEDDED | 26 | #ifndef PWM_EMBEDDED |
27 | #include <qtextedit.h> | 27 | #include <qtextedit.h> |
28 | #include <qsplitter.h> | 28 | #include <qsplitter.h> |
29 | #else | 29 | #else |
30 | #include <qmultilineedit.h> | 30 | #include <qmultilineedit.h> |
31 | #include <KDGanttMinimizeSplitter.h> | 31 | #include <KDGanttMinimizeSplitter.h> |
32 | #endif | 32 | #endif |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | 35 | ||
36 | class PwMView; | 36 | class PwMView; |
37 | class ListViewPwM; | 37 | class ListViewPwM; |
38 | class CommentBox; | 38 | class CommentBox; |
39 | class PWMPrefs; | 39 | class PWMPrefs; |
40 | 40 | ||
41 | class PwMViewStyle_0 : public QObject | 41 | class PwMViewStyle_0 : public QObject |
42 | { | 42 | { |
43 | Q_OBJECT | ||
43 | public: | 44 | public: |
44 | PwMViewStyle_0(PwMView *view); | 45 | PwMViewStyle_0(PwMView *view); |
45 | ~PwMViewStyle_0(); | 46 | ~PwMViewStyle_0(); |
46 | 47 | ||
47 | ListViewPwM * getLv() | 48 | ListViewPwM * getLv() |
48 | { return lv; } | 49 | { return lv; } |
49 | CommentBox * getCommentBox() | 50 | CommentBox * getCommentBox() |
50 | { return commentBox; } | 51 | { return commentBox; } |
51 | 52 | ||
52 | /** returns the currently selected category */ | 53 | /** returns the currently selected category */ |
53 | QString getCurrentCategory() | 54 | QString getCurrentCategory() |
54 | { return categoriesCombo->currentText(); } | 55 | { return categoriesCombo->currentText(); } |
55 | /** add Category to the view */ | 56 | /** add Category to the view */ |
56 | void addCategory(const QString &cat) | 57 | void addCategory(const QString &cat) |
57 | { categoriesCombo->insertItem(cat); } | 58 | { categoriesCombo->insertItem(cat); } |
58 | /** delete Category from view */ | 59 | /** delete Category from view */ |
59 | void delCategory(const QString &cat); | 60 | void delCategory(const QString &cat); |
60 | /** delete all categories from view */ | 61 | /** delete all categories from view */ |
61 | void delAllCategories() | 62 | void delAllCategories() |
62 | { categoriesCombo->clear(); } | 63 | { categoriesCombo->clear(); } |
63 | /** select the specified category */ | 64 | /** select the specified category */ |
64 | void selectCategory(const QString &cat); | 65 | void selectCategory(const QString &cat); |
65 | /** returns the number of categories in this view. | 66 | /** returns the number of categories in this view. |
66 | * This value dosn't say anything about the number of | 67 | * This value dosn't say anything about the number of |
67 | * categories in the document. | 68 | * categories in the document. |
68 | */ | 69 | */ |
69 | int numCategories() | 70 | int numCategories() |
70 | { return categoriesCombo->count(); } | 71 | { return categoriesCombo->count(); } |
71 | /** resize the view */ | 72 | /** resize the view */ |
72 | void resize(const QSize &size) | 73 | void resize(const QSize &size) |
73 | { vbox1->resize(size); } | 74 | { vbox1->resize(size); } |
74 | 75 | ||
75 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 76 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
76 | void restoreSettings(PWMPrefs* prefs); | 77 | void restoreSettings(PWMPrefs* prefs); |
77 | void saveSettings(PWMPrefs* prefs); | 78 | void saveSettings(PWMPrefs* prefs); |
78 | 79 | ||
79 | 80 | public slots: | |
81 | void toggleSplitter(); | ||
80 | protected: | 82 | protected: |
81 | /** main list view */ | 83 | /** main list view */ |
82 | ListViewPwM *lv; | 84 | ListViewPwM *lv; |
83 | /** categories combo-box */ | 85 | /** categories combo-box */ |
84 | QComboBox *categoriesCombo; | 86 | QComboBox *categoriesCombo; |
85 | /** title string for the categories combo or list box */ | 87 | /** title string for the categories combo or list box */ |
86 | QLabel *categoriesTitle; | 88 | QLabel *categoriesTitle; |
87 | /** hbox1 for widget style */ | 89 | /** hbox1 for widget style */ |
88 | QHBox *hbox1; | 90 | QHBox *hbox1; |
89 | /** vbox1 for widget style */ | 91 | /** vbox1 for widget style */ |
90 | QVBox *vbox1; | 92 | QVBox *vbox1; |
91 | /** splitter for commentTextEdit */ | 93 | /** splitter for commentTextEdit */ |
92 | #ifndef PWM_EMBEDDED | 94 | #ifndef PWM_EMBEDDED |
93 | QSplitter *splitter1; | 95 | QSplitter *splitter1; |
94 | #else | 96 | #else |
95 | KDGanttMinimizeSplitter * splitter1; | 97 | KDGanttMinimizeSplitter * splitter1; |
96 | #endif | 98 | #endif |
97 | /** push button to change the category name */ | 99 | /** push button to change the category name */ |
98 | QPushButton *renCatButton; | 100 | QPushButton *renCatButton; |
99 | /** push button to delete the category */ | 101 | /** push button to delete the category */ |
100 | QPushButton *delCatButton; | 102 | QPushButton *delCatButton; |
101 | /** comment box */ | 103 | /** comment box */ |
102 | CommentBox *commentBox; | 104 | CommentBox *commentBox; |
103 | }; | 105 | }; |
104 | 106 | ||
105 | #endif | 107 | #endif |
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.cpp b/pwmanager/pwmanager/pwmviewstyle_1.cpp index 4a7ffd7..7294f34 100644 --- a/pwmanager/pwmanager/pwmviewstyle_1.cpp +++ b/pwmanager/pwmanager/pwmviewstyle_1.cpp | |||
@@ -1,173 +1,192 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmviewstyle_1.h" | 20 | #include "pwmviewstyle_1.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "listviewpwm.h" | 22 | #include "listviewpwm.h" |
23 | #include "commentbox.h" | 23 | #include "commentbox.h" |
24 | 24 | ||
25 | #include <klocale.h> | 25 | #include <klocale.h> |
26 | #include "pwmprefs.h" | 26 | #include "pwmprefs.h" |
27 | 27 | ||
28 | #ifndef DESKTOP_VERSION | 28 | #ifndef DESKTOP_VERSION |
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #else | 30 | #else |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | #endif | 32 | #endif |
33 | #define INITIAL_CATEGORIES_WIDTH100 | 33 | #define INITIAL_CATEGORIES_WIDTH100 |
34 | 34 | ||
35 | PwMViewStyle_1::PwMViewStyle_1(PwMView *view) | 35 | PwMViewStyle_1::PwMViewStyle_1(PwMView *view) |
36 | : QObject() | 36 | : QObject() |
37 | { | 37 | { |
38 | #ifndef PWM_EMBEDDED | 38 | #ifndef PWM_EMBEDDED |
39 | splitter = new QSplitter(view); | 39 | splitter = new QSplitter(view); |
40 | #else | 40 | #else |
41 | if ( QApplication::desktop()->width() > 240 ) { | 41 | if ( QApplication::desktop()->width() > 240 ) { |
42 | splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); | 42 | splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); |
43 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left ); | 43 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Left ); |
44 | // topLayout = new QHBoxLayout( this ); | 44 | // topLayout = new QHBoxLayout( this ); |
45 | // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 45 | // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
46 | // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 46 | // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
47 | } else { | 47 | } else { |
48 | splitter = new KDGanttMinimizeSplitter( Qt::Vertical, view); | 48 | splitter = new KDGanttMinimizeSplitter( Qt::Vertical, view); |
49 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); | 49 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); |
50 | // topLayout = new QHBoxLayout( this ); | 50 | // topLayout = new QHBoxLayout( this ); |
51 | // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 51 | // mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
52 | // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 52 | // mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
53 | } | 53 | } |
54 | //US topLayout->addWidget(mMiniSplitter ); | 54 | //US topLayout->addWidget(mMiniSplitter ); |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | vbox1 = new QVBox(splitter); | 57 | vbox1 = new QVBox(splitter); |
58 | categoriesTitle = new QLabel(vbox1); | 58 | categoriesTitle = new QLabel(vbox1); |
59 | categoriesList = new QListBox(vbox1); | 59 | categoriesList = new QListBox(vbox1); |
60 | #ifndef PWM_EMBEDDED | 60 | #ifndef PWM_EMBEDDED |
61 | splitter2 = new QSplitter(splitter); | 61 | splitter2 = new QSplitter(splitter); |
62 | splitter2->setOrientation(Qt::Vertical); | 62 | splitter2->setOrientation(Qt::Vertical); |
63 | #else | 63 | #else |
64 | splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); | 64 | splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); |
65 | splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 65 | splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
66 | 66 | ||
67 | //US topLayout->addWidget(mMiniSplitter ); | 67 | //US topLayout->addWidget(mMiniSplitter ); |
68 | #endif | 68 | #endif |
69 | lv = new ListViewPwM(splitter2); | 69 | lv = new ListViewPwM(splitter2); |
70 | commentBox = new CommentBox(splitter2); | 70 | commentBox = new CommentBox(splitter2); |
71 | // set sizes and styles | 71 | // set sizes and styles |
72 | //UScommentBox->resize(commentBox->size().width(), 60); | 72 | //UScommentBox->resize(commentBox->size().width(), 60); |
73 | QValueList<int> sizes; | 73 | QValueList<int> sizes; |
74 | #ifndef PWM_EMBEDDED | 74 | #ifndef PWM_EMBEDDED |
75 | sizes.push_back(INITIAL_CATEGORIES_WIDTH); | 75 | sizes.push_back(INITIAL_CATEGORIES_WIDTH); |
76 | sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); | 76 | sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); |
77 | #else | 77 | #else |
78 | sizes.append(INITIAL_CATEGORIES_WIDTH); | 78 | sizes.append(INITIAL_CATEGORIES_WIDTH); |
79 | sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); | 79 | sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); |
80 | #endif | 80 | #endif |
81 | //USsplitter->setSizes(sizes); | 81 | //USsplitter->setSizes(sizes); |
82 | categoriesTitle->setAlignment(Qt::AlignHCenter); | 82 | categoriesTitle->setAlignment(Qt::AlignHCenter); |
83 | #ifndef PWM_EMBEDDED | 83 | #ifndef PWM_EMBEDDED |
84 | categoriesTitle->setFrameShape(QFrame::MenuBarPanel); | 84 | categoriesTitle->setFrameShape(QFrame::MenuBarPanel); |
85 | #else | 85 | #else |
86 | categoriesTitle->setFrameShape(QFrame::StyledPanel); | 86 | categoriesTitle->setFrameShape(QFrame::StyledPanel); |
87 | #endif | 87 | #endif |
88 | categoriesTitle->setText(i18n("Categories:")); | 88 | categoriesTitle->setText(i18n("Categories:")); |
89 | catCtxMenu = new QPopupMenu(view); | 89 | catCtxMenu = new QPopupMenu(view); |
90 | catCtxMenu->insertItem(i18n("&Rename"), | 90 | catCtxMenu->insertItem(i18n("&Rename"), |
91 | view, SLOT(renCatButton_slot())); | 91 | view, SLOT(renCatButton_slot())); |
92 | catCtxMenu->insertItem(i18n("&Delete"), | 92 | catCtxMenu->insertItem(i18n("&Delete"), |
93 | view, SLOT(delCatButton_slot())); | 93 | view, SLOT(delCatButton_slot())); |
94 | 94 | ||
95 | #ifndef DESKTOP_VERSION | 95 | #ifndef DESKTOP_VERSION |
96 | QPEApplication::setStylusOperation( categoriesList->viewport(), QPEApplication::RightOnHold ); | 96 | QPEApplication::setStylusOperation( categoriesList->viewport(), QPEApplication::RightOnHold ); |
97 | #endif | 97 | #endif |
98 | 98 | ||
99 | // connections | 99 | // connections |
100 | connect(categoriesList, SIGNAL(highlighted(int)), | 100 | connect(categoriesList, SIGNAL(highlighted(int)), |
101 | view, SLOT(shiftToView())); | 101 | view, SLOT(shiftToView())); |
102 | connect(categoriesList, | 102 | connect(categoriesList, |
103 | SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), | 103 | SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), |
104 | this, | 104 | this, |
105 | SLOT(catRightClick(QListBoxItem *, const QPoint &))); | 105 | SLOT(catRightClick(QListBoxItem *, const QPoint &))); |
106 | |||
107 | connect(lv, SIGNAL(toggleOverview()), | ||
108 | this, SLOT(toggleSplitter())); | ||
106 | } | 109 | } |
107 | 110 | ||
108 | PwMViewStyle_1::~PwMViewStyle_1() | 111 | PwMViewStyle_1::~PwMViewStyle_1() |
109 | { | 112 | { |
110 | delete catCtxMenu; | 113 | delete catCtxMenu; |
111 | delete splitter; | 114 | delete splitter; |
112 | } | 115 | } |
116 | void PwMViewStyle_1::toggleSplitter() | ||
117 | { | ||
118 | QValueList<int> si = splitter2->sizes(); | ||
119 | splitter2->toggle(); | ||
120 | QValueList<int> si2 = splitter2->sizes(); | ||
121 | //qDebug("PwMViewStyle_1::toggleSplitter() %d %d %d %d", si[0],si[1],si2[0],si2[1] ); | ||
122 | if ( si[0] == si2[0] && si[1] == si2[1] && si2[1] == 1 ) { | ||
123 | int diff = si[0]/2; | ||
124 | if ( diff > 200 ) | ||
125 | diff = 200; | ||
126 | si[0] -= diff; | ||
127 | si[1] += diff; | ||
128 | splitter2->toggle(); | ||
129 | splitter2->setSizes( si ); | ||
130 | } | ||
131 | } | ||
113 | 132 | ||
114 | void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) | 133 | void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) |
115 | { | 134 | { |
116 | if (!item) | 135 | if (!item) |
117 | return; | 136 | return; |
118 | catCtxMenu->move(point); | 137 | catCtxMenu->move(point); |
119 | catCtxMenu->show(); | 138 | catCtxMenu->show(); |
120 | } | 139 | } |
121 | 140 | ||
122 | void PwMViewStyle_1::delCategory(const QString &cat) | 141 | void PwMViewStyle_1::delCategory(const QString &cat) |
123 | { | 142 | { |
124 | PWM_ASSERT(categoriesList); | 143 | PWM_ASSERT(categoriesList); |
125 | int i, count = categoriesList->count(); | 144 | int i, count = categoriesList->count(); |
126 | for (i = 0; i < count; ++i) { | 145 | for (i = 0; i < count; ++i) { |
127 | if (categoriesList->text(i) == cat) { | 146 | if (categoriesList->text(i) == cat) { |
128 | categoriesList->removeItem(i); | 147 | categoriesList->removeItem(i); |
129 | return; | 148 | return; |
130 | } | 149 | } |
131 | } | 150 | } |
132 | BUG(); | 151 | BUG(); |
133 | } | 152 | } |
134 | 153 | ||
135 | void PwMViewStyle_1::selectCategory(const QString &cat) | 154 | void PwMViewStyle_1::selectCategory(const QString &cat) |
136 | { | 155 | { |
137 | PWM_ASSERT(categoriesList); | 156 | PWM_ASSERT(categoriesList); |
138 | int i, count = categoriesList->count(); | 157 | int i, count = categoriesList->count(); |
139 | for (i = 0; i < count; ++i) { | 158 | for (i = 0; i < count; ++i) { |
140 | if (categoriesList->text(i) == cat) { | 159 | if (categoriesList->text(i) == cat) { |
141 | categoriesList->setCurrentItem(i); | 160 | categoriesList->setCurrentItem(i); |
142 | return; | 161 | return; |
143 | } | 162 | } |
144 | } | 163 | } |
145 | // fall back to 0 | 164 | // fall back to 0 |
146 | categoriesList->setCurrentItem(0); | 165 | categoriesList->setCurrentItem(0); |
147 | } | 166 | } |
148 | 167 | ||
149 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 168 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
150 | void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs) | 169 | void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs) |
151 | { | 170 | { |
152 | //load and store the size of the listviewcolumns | 171 | //load and store the size of the listviewcolumns |
153 | lv->restoreLayout(prefs->getConfig(), "listview"); | 172 | lv->restoreLayout(prefs->getConfig(), "listview"); |
154 | splitter->setSizes( prefs->mCategorySplitter ); | 173 | splitter->setSizes( prefs->mCategorySplitter ); |
155 | splitter2->setSizes( prefs->mCommentSplitter ); | 174 | splitter2->setSizes( prefs->mCommentSplitter ); |
156 | commentBox->setFont( prefs->mViewFont ); | 175 | commentBox->setFont( prefs->mViewFont ); |
157 | 176 | ||
158 | } | 177 | } |
159 | 178 | ||
160 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 179 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
161 | void PwMViewStyle_1::saveSettings(PWMPrefs* prefs) | 180 | void PwMViewStyle_1::saveSettings(PWMPrefs* prefs) |
162 | { | 181 | { |
163 | //store the size of the listviewcolumns | 182 | //store the size of the listviewcolumns |
164 | lv->saveLayout(prefs->getConfig(), "listview"); | 183 | lv->saveLayout(prefs->getConfig(), "listview"); |
165 | prefs->mCategorySplitter = splitter->sizes(); | 184 | prefs->mCategorySplitter = splitter->sizes(); |
166 | prefs->mCommentSplitter = splitter2->sizes(); | 185 | prefs->mCommentSplitter = splitter2->sizes(); |
167 | 186 | ||
168 | } | 187 | } |
169 | 188 | ||
170 | 189 | ||
171 | #ifndef PWM_EMBEDDED | 190 | #ifndef PWM_EMBEDDED |
172 | #include "pwmviewstyle_1.moc" | 191 | #include "pwmviewstyle_1.moc" |
173 | #endif | 192 | #endif |
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.h b/pwmanager/pwmanager/pwmviewstyle_1.h index a7f100c..4f7a256 100644 --- a/pwmanager/pwmanager/pwmviewstyle_1.h +++ b/pwmanager/pwmanager/pwmviewstyle_1.h | |||
@@ -1,112 +1,114 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 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 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef PWMVIEWSTYLE_1_H | 20 | #ifndef PWMVIEWSTYLE_1_H |
21 | #define PWMVIEWSTYLE_1_H | 21 | #define PWMVIEWSTYLE_1_H |
22 | 22 | ||
23 | #include <qvbox.h> | 23 | #include <qvbox.h> |
24 | 24 | ||
25 | #ifndef PWM_EMBEDDED | 25 | #ifndef PWM_EMBEDDED |
26 | #include <qtextedit.h> | 26 | #include <qtextedit.h> |
27 | #include <qsplitter.h> | 27 | #include <qsplitter.h> |
28 | #else | 28 | #else |
29 | #include <qmultilineedit.h> | 29 | #include <qmultilineedit.h> |
30 | #include <KDGanttMinimizeSplitter.h> | 30 | #include <KDGanttMinimizeSplitter.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qlistbox.h> | 34 | #include <qlistbox.h> |
35 | #include <qpopupmenu.h> | 35 | #include <qpopupmenu.h> |
36 | 36 | ||
37 | class PwMView; | 37 | class PwMView; |
38 | class ListViewPwM; | 38 | class ListViewPwM; |
39 | class CommentBox; | 39 | class CommentBox; |
40 | class PWMPrefs; | 40 | class PWMPrefs; |
41 | 41 | ||
42 | class PwMViewStyle_1 : public QObject | 42 | class PwMViewStyle_1 : public QObject |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | public: | 45 | public: |
46 | PwMViewStyle_1(PwMView *view); | 46 | PwMViewStyle_1(PwMView *view); |
47 | ~PwMViewStyle_1(); | 47 | ~PwMViewStyle_1(); |
48 | 48 | ||
49 | ListViewPwM * getLv() | 49 | ListViewPwM * getLv() |
50 | { return lv; } | 50 | { return lv; } |
51 | CommentBox * getCommentBox() | 51 | CommentBox * getCommentBox() |
52 | { return commentBox; } | 52 | { return commentBox; } |
53 | 53 | ||
54 | /** returns the currently selected category */ | 54 | /** returns the currently selected category */ |
55 | QString getCurrentCategory() | 55 | QString getCurrentCategory() |
56 | { return categoriesList->currentText(); } | 56 | { return categoriesList->currentText(); } |
57 | /** add Category to the view */ | 57 | /** add Category to the view */ |
58 | void addCategory(const QString &cat) | 58 | void addCategory(const QString &cat) |
59 | { categoriesList->insertItem(cat); } | 59 | { categoriesList->insertItem(cat); } |
60 | /** delete Category from view */ | 60 | /** delete Category from view */ |
61 | void delCategory(const QString &cat); | 61 | void delCategory(const QString &cat); |
62 | /** delete all categories from view */ | 62 | /** delete all categories from view */ |
63 | void delAllCategories() | 63 | void delAllCategories() |
64 | { categoriesList->clear(); } | 64 | { categoriesList->clear(); } |
65 | /** select the specified category */ | 65 | /** select the specified category */ |
66 | void selectCategory(const QString &cat); | 66 | void selectCategory(const QString &cat); |
67 | /** returns the number of categories in this view. | 67 | /** returns the number of categories in this view. |
68 | * This value dosn't say anything about the number of | 68 | * This value dosn't say anything about the number of |
69 | * categories in the document. | 69 | * categories in the document. |
70 | */ | 70 | */ |
71 | int numCategories() | 71 | int numCategories() |
72 | { return categoriesList->count(); } | 72 | { return categoriesList->count(); } |
73 | /** resize the view */ | 73 | /** resize the view */ |
74 | void resize(const QSize &size) | 74 | void resize(const QSize &size) |
75 | { splitter->resize(size); } | 75 | { splitter->resize(size); } |
76 | 76 | ||
77 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 77 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
78 | void restoreSettings(PWMPrefs* prefs); | 78 | void restoreSettings(PWMPrefs* prefs); |
79 | void saveSettings(PWMPrefs* prefs); | 79 | void saveSettings(PWMPrefs* prefs); |
80 | 80 | ||
81 | public slots: | ||
82 | void toggleSplitter(); | ||
81 | protected slots: | 83 | protected slots: |
82 | /** user clicked right button in category list */ | 84 | /** user clicked right button in category list */ |
83 | void catRightClick(QListBoxItem *item, const QPoint &point); | 85 | void catRightClick(QListBoxItem *item, const QPoint &point); |
84 | 86 | ||
85 | protected: | 87 | protected: |
86 | /** main list view */ | 88 | /** main list view */ |
87 | ListViewPwM *lv; | 89 | ListViewPwM *lv; |
88 | #ifndef PWM_EMBEDDED | 90 | #ifndef PWM_EMBEDDED |
89 | /** main splitter widget */ | 91 | /** main splitter widget */ |
90 | QSplitter *splitter; | 92 | QSplitter *splitter; |
91 | /** commentTextEdit splitter */ | 93 | /** commentTextEdit splitter */ |
92 | QSplitter *splitter2; | 94 | QSplitter *splitter2; |
93 | #else | 95 | #else |
94 | /** main splitter widget */ | 96 | /** main splitter widget */ |
95 | KDGanttMinimizeSplitter *splitter; | 97 | KDGanttMinimizeSplitter *splitter; |
96 | /** commentTextEdit splitter */ | 98 | /** commentTextEdit splitter */ |
97 | KDGanttMinimizeSplitter *splitter2; | 99 | KDGanttMinimizeSplitter *splitter2; |
98 | #endif | 100 | #endif |
99 | 101 | ||
100 | /** categories list-box */ | 102 | /** categories list-box */ |
101 | QListBox *categoriesList; | 103 | QListBox *categoriesList; |
102 | /** title string for the categories combo or list box */ | 104 | /** title string for the categories combo or list box */ |
103 | QLabel *categoriesTitle; | 105 | QLabel *categoriesTitle; |
104 | /** hbox1 for widget style */ | 106 | /** hbox1 for widget style */ |
105 | QVBox *vbox1; | 107 | QVBox *vbox1; |
106 | /** text-edit to display the comment */ | 108 | /** text-edit to display the comment */ |
107 | CommentBox *commentBox; | 109 | CommentBox *commentBox; |
108 | /** category list context menu */ | 110 | /** category list context menu */ |
109 | QPopupMenu *catCtxMenu; | 111 | QPopupMenu *catCtxMenu; |
110 | }; | 112 | }; |
111 | 113 | ||
112 | #endif | 114 | #endif |