author | ulf69 <ulf69> | 2004-10-20 18:38:39 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-20 18:38:39 (UTC) |
commit | 8e00329a4a5f0b66d26d20f067ab6aefca17f17a (patch) (unidiff) | |
tree | 9fa40d29baece91dc854b7e124c3bbc2962a0729 | |
parent | 13243e1fb1855d306d45a84365f55e20efeff69d (diff) | |
download | kdepimpi-8e00329a4a5f0b66d26d20f067ab6aefca17f17a.zip kdepimpi-8e00329a4a5f0b66d26d20f067ab6aefca17f17a.tar.gz kdepimpi-8e00329a4a5f0b66d26d20f067ab6aefca17f17a.tar.bz2 |
removed dead code
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 30 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 25 |
2 files changed, 27 insertions, 28 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index c511661..66d26d6 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,1373 +1,1373 @@ | |||
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 | #ifndef PWM_EMBEDDED | 27 | #ifndef PWM_EMBEDDED |
28 | #include <kmenubar.h> | 28 | #include <kmenubar.h> |
29 | #include <kstatusbar.h> | 29 | #include <kstatusbar.h> |
30 | #include <dcopclient.h> | 30 | #include <dcopclient.h> |
31 | #include "configwndimpl.h" | 31 | #include "configwndimpl.h" |
32 | #include "configuration.h" | 32 | #include "configuration.h" |
33 | #else | 33 | #else |
34 | #include <qmenubar.h> | 34 | #include <qmenubar.h> |
35 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | #include <pwmprefs.h> | 36 | #include <pwmprefs.h> |
37 | #include <kpimglobalprefs.h> | 37 | #include <kpimglobalprefs.h> |
38 | #include <kcmconfigs/kcmpwmconfig.h> | 38 | #include <kcmconfigs/kcmpwmconfig.h> |
39 | #include <kcmconfigs/kcmkdepimconfig.h> | 39 | #include <kcmconfigs/kcmkdepimconfig.h> |
40 | #include <kcmultidialog.h> | 40 | #include <kcmultidialog.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #include <qpixmap.h> | 43 | #include <qpixmap.h> |
44 | #include <qcheckbox.h> | 44 | #include <qcheckbox.h> |
45 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
48 | #include <qclipboard.h> | 48 | #include <qclipboard.h> |
49 | 49 | ||
50 | 50 | ||
51 | #include <stdio.h> | 51 | #include <stdio.h> |
52 | 52 | ||
53 | #include "pwm.h" | 53 | #include "pwm.h" |
54 | #include "pwminit.h" | 54 | #include "pwminit.h" |
55 | #include "pwmprint.h" | 55 | #include "pwmprint.h" |
56 | #include "addentrywndimpl.h" | 56 | #include "addentrywndimpl.h" |
57 | #include "globalstuff.h" | 57 | #include "globalstuff.h" |
58 | #include "findwndimpl.h" | 58 | #include "findwndimpl.h" |
59 | 59 | ||
60 | #ifdef CONFIG_KWALLETIF | 60 | #ifdef CONFIG_KWALLETIF |
61 | # include "kwalletif.h" | 61 | # include "kwalletif.h" |
62 | # include "kwalletemu.h" | 62 | # include "kwalletemu.h" |
63 | #endif | 63 | #endif |
64 | #ifdef CONFIG_KEYCARD | 64 | #ifdef CONFIG_KEYCARD |
65 | # include "pwmkeycard.h" | 65 | # include "pwmkeycard.h" |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | 68 | ||
69 | #define DEFAULT_SIZE (QSize(700, 400)) | 69 | #define DEFAULT_SIZE (QSize(700, 400)) |
70 | 70 | ||
71 | // Button IDs for "file" popup menu | 71 | // Button IDs for "file" popup menu |
72 | enum { | 72 | enum { |
73 | BUTTON_POPUP_FILE_NEW = 0, | 73 | BUTTON_POPUP_FILE_NEW = 0, |
74 | BUTTON_POPUP_FILE_OPEN, | 74 | BUTTON_POPUP_FILE_OPEN, |
75 | BUTTON_POPUP_FILE_CLOSE, | 75 | BUTTON_POPUP_FILE_CLOSE, |
76 | BUTTON_POPUP_FILE_SAVE, | 76 | BUTTON_POPUP_FILE_SAVE, |
77 | BUTTON_POPUP_FILE_SAVEAS, | 77 | BUTTON_POPUP_FILE_SAVEAS, |
78 | BUTTON_POPUP_FILE_EXPORT, | 78 | BUTTON_POPUP_FILE_EXPORT, |
79 | BUTTON_POPUP_FILE_IMPORT, | 79 | BUTTON_POPUP_FILE_IMPORT, |
80 | BUTTON_POPUP_FILE_PRINT, | 80 | BUTTON_POPUP_FILE_PRINT, |
81 | BUTTON_POPUP_FILE_QUIT | 81 | BUTTON_POPUP_FILE_QUIT |
82 | }; | 82 | }; |
83 | // Button IDs for "manage" popup menu | 83 | // Button IDs for "manage" popup menu |
84 | enum { | 84 | enum { |
85 | BUTTON_POPUP_MANAGE_ADD = 0, | 85 | BUTTON_POPUP_MANAGE_ADD = 0, |
86 | BUTTON_POPUP_MANAGE_EDIT, | 86 | BUTTON_POPUP_MANAGE_EDIT, |
87 | BUTTON_POPUP_MANAGE_DEL, | 87 | BUTTON_POPUP_MANAGE_DEL, |
88 | BUTTON_POPUP_MANAGE_CHANGEMP | 88 | BUTTON_POPUP_MANAGE_CHANGEMP |
89 | }; | 89 | }; |
90 | // Button IDs for chipcard popup menu | 90 | // Button IDs for chipcard popup menu |
91 | enum { | 91 | enum { |
92 | #ifdef CONFIG_KEYCARD | 92 | #ifdef CONFIG_KEYCARD |
93 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, | 93 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, |
94 | BUTTON_POPUP_CHIPCARD_DEL, | 94 | BUTTON_POPUP_CHIPCARD_DEL, |
95 | BUTTON_POPUP_CHIPCARD_READID, | 95 | BUTTON_POPUP_CHIPCARD_READID, |
96 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, | 96 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, |
97 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP | 97 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP |
98 | #else // CONFIG_KEYCARD | 98 | #else // CONFIG_KEYCARD |
99 | BUTTON_POPUP_CHIPCARD_NO = 0 | 99 | BUTTON_POPUP_CHIPCARD_NO = 0 |
100 | #endif // CONFIG_KEYCARD | 100 | #endif // CONFIG_KEYCARD |
101 | }; | 101 | }; |
102 | // Button IDs for "view" popup menu | 102 | // Button IDs for "view" popup menu |
103 | enum { | 103 | enum { |
104 | BUTTON_POPUP_VIEW_FIND = 0, | 104 | BUTTON_POPUP_VIEW_FIND = 0, |
105 | BUTTON_POPUP_VIEW_LOCK, | 105 | BUTTON_POPUP_VIEW_LOCK, |
106 | BUTTON_POPUP_VIEW_DEEPLOCK, | 106 | BUTTON_POPUP_VIEW_DEEPLOCK, |
107 | BUTTON_POPUP_VIEW_UNLOCK | 107 | BUTTON_POPUP_VIEW_UNLOCK |
108 | }; | 108 | }; |
109 | // Button IDs for "options" popup menu | 109 | // Button IDs for "options" popup menu |
110 | enum { | 110 | enum { |
111 | BUTTON_POPUP_OPTIONS_CONFIG = 0 | 111 | BUTTON_POPUP_OPTIONS_CONFIG = 0 |
112 | }; | 112 | }; |
113 | // Button IDs for "export" popup menu (in "file" popup menu) | 113 | // Button IDs for "export" popup menu (in "file" popup menu) |
114 | enum { | 114 | enum { |
115 | BUTTON_POPUP_EXPORT_TEXT = 0, | 115 | BUTTON_POPUP_EXPORT_TEXT = 0, |
116 | BUTTON_POPUP_EXPORT_GPASMAN | 116 | BUTTON_POPUP_EXPORT_GPASMAN |
117 | #ifdef CONFIG_KWALLETIF | 117 | #ifdef CONFIG_KWALLETIF |
118 | ,BUTTON_POPUP_EXPORT_KWALLET | 118 | ,BUTTON_POPUP_EXPORT_KWALLET |
119 | #endif | 119 | #endif |
120 | }; | 120 | }; |
121 | // Button IDs for "import" popup menu (in "file" popup menu) | 121 | // Button IDs for "import" popup menu (in "file" popup menu) |
122 | enum { | 122 | enum { |
123 | BUTTON_POPUP_IMPORT_TEXT = 0, | 123 | BUTTON_POPUP_IMPORT_TEXT = 0, |
124 | BUTTON_POPUP_IMPORT_GPASMAN | 124 | BUTTON_POPUP_IMPORT_GPASMAN |
125 | #ifdef CONFIG_KWALLETIF | 125 | #ifdef CONFIG_KWALLETIF |
126 | ,BUTTON_POPUP_IMPORT_KWALLET | 126 | ,BUTTON_POPUP_IMPORT_KWALLET |
127 | #endif | 127 | #endif |
128 | }; | 128 | }; |
129 | 129 | ||
130 | #ifdef PWM_EMBEDDED | 130 | #ifdef PWM_EMBEDDED |
131 | // Button IDs for "help" popup menu | 131 | // Button IDs for "help" popup menu |
132 | enum { | 132 | enum { |
133 | BUTTON_POPUP_HELP_LICENSE = 0, | 133 | BUTTON_POPUP_HELP_LICENSE = 0, |
134 | BUTTON_POPUP_HELP_FAQ, | 134 | BUTTON_POPUP_HELP_FAQ, |
135 | BUTTON_POPUP_HELP_ABOUT, | 135 | BUTTON_POPUP_HELP_ABOUT, |
136 | BUTTON_POPUP_HELP_SYNC, | 136 | BUTTON_POPUP_HELP_SYNC, |
137 | BUTTON_POPUP_HELP_WHATSNEW | 137 | BUTTON_POPUP_HELP_WHATSNEW |
138 | }; | 138 | }; |
139 | #endif | 139 | #endif |
140 | 140 | ||
141 | // Button IDs for toolbar | 141 | // Button IDs for toolbar |
142 | enum { | 142 | enum { |
143 | BUTTON_TOOL_NEW = 0, | 143 | BUTTON_TOOL_NEW = 0, |
144 | BUTTON_TOOL_OPEN, | 144 | BUTTON_TOOL_OPEN, |
145 | BUTTON_TOOL_SAVE, | 145 | BUTTON_TOOL_SAVE, |
146 | BUTTON_TOOL_SAVEAS, | 146 | BUTTON_TOOL_SAVEAS, |
147 | BUTTON_TOOL_PRINT, | 147 | BUTTON_TOOL_PRINT, |
148 | BUTTON_TOOL_ADD, | 148 | BUTTON_TOOL_ADD, |
149 | BUTTON_TOOL_EDIT, | 149 | BUTTON_TOOL_EDIT, |
150 | BUTTON_TOOL_DEL, | 150 | BUTTON_TOOL_DEL, |
151 | BUTTON_TOOL_FIND, | 151 | BUTTON_TOOL_FIND, |
152 | BUTTON_TOOL_LOCK, | 152 | BUTTON_TOOL_LOCK, |
153 | BUTTON_TOOL_DEEPLOCK, | 153 | BUTTON_TOOL_DEEPLOCK, |
154 | BUTTON_TOOL_UNLOCK | 154 | BUTTON_TOOL_UNLOCK |
155 | }; | 155 | }; |
156 | 156 | ||
157 | 157 | ||
158 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 158 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
159 | bool virginity, | 159 | bool virginity, |
160 | QWidget *parent, const char *name) | 160 | QWidget *parent, const char *name) |
161 | : KMainWindow(parent, "HALLO") | 161 | : KMainWindow(parent, "HALLO") |
162 | , forceQuit (false) | 162 | , forceQuit (false) |
163 | , forceMinimizeToTray (false) | 163 | , forceMinimizeToTray (false) |
164 | { | 164 | { |
165 | init = _init; | 165 | init = _init; |
166 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 166 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
167 | this, SLOT(docClosed(PwMDoc *))); | 167 | this, SLOT(docClosed(PwMDoc *))); |
168 | initMenubar(); | 168 | initMenubar(); |
169 | initToolbar(); | 169 | initToolbar(); |
170 | initMetrics(); | 170 | initMetrics(); |
171 | setVirgin(virginity); | 171 | setVirgin(virginity); |
172 | setFocusPolicy(QWidget::WheelFocus); | 172 | setFocusPolicy(QWidget::WheelFocus); |
173 | #ifndef PWM_EMBEDDED | 173 | #ifndef PWM_EMBEDDED |
174 | statusBar()->show(); | 174 | statusBar()->show(); |
175 | #endif | 175 | #endif |
176 | view = makeNewListView(doc); | 176 | view = makeNewListView(doc); |
177 | setCentralWidget(view); | 177 | setCentralWidget(view); |
178 | updateCaption(); | 178 | updateCaption(); |
179 | showStatMsg(i18n("Ready.")); | 179 | showStatMsg(i18n("Ready.")); |
180 | } | 180 | } |
181 | 181 | ||
182 | PwM::~PwM() | 182 | PwM::~PwM() |
183 | { | 183 | { |
184 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 184 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
185 | this, SLOT(docClosed(PwMDoc *))); | 185 | this, SLOT(docClosed(PwMDoc *))); |
186 | conf()->confWndMainWndSize(size()); | 186 | conf()->confWndMainWndSize(size()); |
187 | emit closed(this); | 187 | emit closed(this); |
188 | delete view; | 188 | delete view; |
189 | } | 189 | } |
190 | 190 | ||
191 | void PwM::initMenubar() | 191 | void PwM::initMenubar() |
192 | { | 192 | { |
193 | KIconLoader* picons; | 193 | KIconLoader* picons; |
194 | #ifndef PWM_EMBEDDED | 194 | #ifndef PWM_EMBEDDED |
195 | KIconLoader icons; | 195 | KIconLoader icons; |
196 | picons = &icons; | 196 | picons = &icons; |
197 | #else | 197 | #else |
198 | picons = KGlobal::iconLoader(); | 198 | picons = KGlobal::iconLoader(); |
199 | 199 | ||
200 | 200 | ||
201 | syncPopup = new KPopupMenu(this); | 201 | syncPopup = new KPopupMenu(this); |
202 | 202 | ||
203 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); | 203 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); |
204 | syncManager->setBlockSave(false); | 204 | syncManager->setBlockSave(false); |
205 | 205 | ||
206 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 206 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
207 | syncManager->fillSyncMenu(); | 207 | syncManager->fillSyncMenu(); |
208 | 208 | ||
209 | #endif | 209 | #endif |
210 | filePopup = new KPopupMenu(this); | 210 | filePopup = new KPopupMenu(this); |
211 | importPopup = new KPopupMenu(filePopup); | 211 | importPopup = new KPopupMenu(filePopup); |
212 | exportPopup = new KPopupMenu(filePopup); | 212 | exportPopup = new KPopupMenu(filePopup); |
213 | managePopup = new KPopupMenu(this); | 213 | managePopup = new KPopupMenu(this); |
214 | #ifdef CONFIG_KEYCARD | 214 | #ifdef CONFIG_KEYCARD |
215 | chipcardPopup = new KPopupMenu(this); | 215 | chipcardPopup = new KPopupMenu(this); |
216 | #endif // CONFIG_KEYCARD | 216 | #endif // CONFIG_KEYCARD |
217 | viewPopup = new KPopupMenu(this); | 217 | viewPopup = new KPopupMenu(this); |
218 | optionsPopup = new KPopupMenu(this); | 218 | optionsPopup = new KPopupMenu(this); |
219 | 219 | ||
220 | // "file" popup menu | 220 | // "file" popup menu |
221 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 221 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
222 | i18n("&New"), this, | 222 | i18n("&New"), this, |
223 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 223 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
224 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 224 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
225 | i18n("&Open"), this, | 225 | i18n("&Open"), this, |
226 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 226 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
227 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 227 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
228 | i18n("&Close"), this, | 228 | i18n("&Close"), this, |
229 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 229 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
230 | filePopup->insertSeparator(); | 230 | filePopup->insertSeparator(); |
231 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 231 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
232 | i18n("&Save"), this, | 232 | i18n("&Save"), this, |
233 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 233 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
234 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 234 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
235 | i18n("Save &as..."), | 235 | i18n("Save &as..."), |
236 | this, SLOT(saveAs_slot()), 0, | 236 | this, SLOT(saveAs_slot()), 0, |
237 | BUTTON_POPUP_FILE_SAVEAS); | 237 | BUTTON_POPUP_FILE_SAVEAS); |
238 | filePopup->insertSeparator(); | 238 | filePopup->insertSeparator(); |
239 | // "file/export" popup menu | 239 | // "file/export" popup menu |
240 | exportPopup->insertItem(i18n("&Text-file..."), this, | 240 | exportPopup->insertItem(i18n("&Text-file..."), this, |
241 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 241 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
242 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 242 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
243 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 243 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
244 | #ifdef CONFIG_KWALLETIF | 244 | #ifdef CONFIG_KWALLETIF |
245 | exportPopup->insertItem(i18n("&KWallet..."), this, | 245 | exportPopup->insertItem(i18n("&KWallet..."), this, |
246 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 246 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
247 | #endif | 247 | #endif |
248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
249 | i18n("E&xport"), exportPopup, | 249 | i18n("E&xport"), exportPopup, |
250 | BUTTON_POPUP_FILE_EXPORT); | 250 | BUTTON_POPUP_FILE_EXPORT); |
251 | // "file/import" popup menu | 251 | // "file/import" popup menu |
252 | importPopup->insertItem(i18n("&Text-file..."), this, | 252 | importPopup->insertItem(i18n("&Text-file..."), this, |
253 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 253 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
254 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 254 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
255 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 255 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
256 | #ifdef CONFIG_KWALLETIF | 256 | #ifdef CONFIG_KWALLETIF |
257 | importPopup->insertItem(i18n("&KWallet..."), this, | 257 | importPopup->insertItem(i18n("&KWallet..."), this, |
258 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 258 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
259 | #endif | 259 | #endif |
260 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 260 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
261 | i18n("I&mport"), importPopup, | 261 | i18n("I&mport"), importPopup, |
262 | BUTTON_POPUP_FILE_IMPORT); | 262 | BUTTON_POPUP_FILE_IMPORT); |
263 | filePopup->insertSeparator(); | 263 | filePopup->insertSeparator(); |
264 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 264 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
265 | i18n("&Print..."), this, | 265 | i18n("&Print..."), this, |
266 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 266 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
267 | filePopup->insertSeparator(); | 267 | filePopup->insertSeparator(); |
268 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 268 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
269 | i18n("&Quit"), this, | 269 | i18n("&Quit"), this, |
270 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 270 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
271 | menuBar()->insertItem(i18n("&File"), filePopup); | 271 | menuBar()->insertItem(i18n("&File"), filePopup); |
272 | // "manage" popup menu | 272 | // "manage" popup menu |
273 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 273 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
274 | i18n("&Add password"), this, | 274 | i18n("&Add password"), this, |
275 | SLOT(addPwd_slot()), 0, | 275 | SLOT(addPwd_slot()), 0, |
276 | BUTTON_POPUP_MANAGE_ADD); | 276 | BUTTON_POPUP_MANAGE_ADD); |
277 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 277 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
278 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 278 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
279 | BUTTON_POPUP_MANAGE_EDIT); | 279 | BUTTON_POPUP_MANAGE_EDIT); |
280 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 280 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
281 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 281 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
282 | 0, BUTTON_POPUP_MANAGE_DEL); | 282 | 0, BUTTON_POPUP_MANAGE_DEL); |
283 | managePopup->insertSeparator(); | 283 | managePopup->insertSeparator(); |
284 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 284 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
285 | i18n("Change &Master Password"), this, | 285 | i18n("Change &Master Password"), this, |
286 | SLOT(changeMasterPwd_slot()), 0, | 286 | SLOT(changeMasterPwd_slot()), 0, |
287 | BUTTON_POPUP_MANAGE_CHANGEMP); | 287 | BUTTON_POPUP_MANAGE_CHANGEMP); |
288 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 288 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
289 | // "chipcard" popup menu | 289 | // "chipcard" popup menu |
290 | #ifdef CONFIG_KEYCARD | 290 | #ifdef CONFIG_KEYCARD |
291 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 291 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
292 | i18n("&Generate new key-card"), this, | 292 | i18n("&Generate new key-card"), this, |
293 | SLOT(genNewCard_slot()), 0, | 293 | SLOT(genNewCard_slot()), 0, |
294 | BUTTON_POPUP_CHIPCARD_GENNEW); | 294 | BUTTON_POPUP_CHIPCARD_GENNEW); |
295 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 295 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
296 | i18n("&Erase key-card"), this, | 296 | i18n("&Erase key-card"), this, |
297 | SLOT(eraseCard_slot()), 0, | 297 | SLOT(eraseCard_slot()), 0, |
298 | BUTTON_POPUP_CHIPCARD_DEL); | 298 | BUTTON_POPUP_CHIPCARD_DEL); |
299 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 299 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
300 | i18n("Read card-&ID"), this, | 300 | i18n("Read card-&ID"), this, |
301 | SLOT(readCardId_slot()), 0, | 301 | SLOT(readCardId_slot()), 0, |
302 | BUTTON_POPUP_CHIPCARD_READID); | 302 | BUTTON_POPUP_CHIPCARD_READID); |
303 | chipcardPopup->insertSeparator(); | 303 | chipcardPopup->insertSeparator(); |
304 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 304 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
305 | i18n("&Make card backup-image"), this, | 305 | i18n("&Make card backup-image"), this, |
306 | SLOT(makeCardBackup_slot()), 0, | 306 | SLOT(makeCardBackup_slot()), 0, |
307 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 307 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
308 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 308 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
309 | i18n("&Replay card backup-image"), this, | 309 | i18n("&Replay card backup-image"), this, |
310 | SLOT(replayCardBackup_slot()), 0, | 310 | SLOT(replayCardBackup_slot()), 0, |
311 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 311 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
312 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 312 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
313 | #endif // CONFIG_KEYCARD | 313 | #endif // CONFIG_KEYCARD |
314 | // "view" popup menu | 314 | // "view" popup menu |
315 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 315 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
316 | i18n("&Find"), this, | 316 | i18n("&Find"), this, |
317 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 317 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
318 | viewPopup->insertSeparator(); | 318 | viewPopup->insertSeparator(); |
319 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 319 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
320 | i18n("&Lock all entries"), this, | 320 | i18n("&Lock all entries"), this, |
321 | SLOT(lockWnd_slot()), 0, | 321 | SLOT(lockWnd_slot()), 0, |
322 | BUTTON_POPUP_VIEW_LOCK); | 322 | BUTTON_POPUP_VIEW_LOCK); |
323 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 323 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
324 | i18n("&Deep-lock all entries"), this, | 324 | i18n("&Deep-lock all entries"), this, |
325 | SLOT(deepLockWnd_slot()), 0, | 325 | SLOT(deepLockWnd_slot()), 0, |
326 | BUTTON_POPUP_VIEW_DEEPLOCK); | 326 | BUTTON_POPUP_VIEW_DEEPLOCK); |
327 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 327 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
328 | i18n("&Unlock all entries"), this, | 328 | i18n("&Unlock all entries"), this, |
329 | SLOT(unlockWnd_slot()), 0, | 329 | SLOT(unlockWnd_slot()), 0, |
330 | BUTTON_POPUP_VIEW_UNLOCK); | 330 | BUTTON_POPUP_VIEW_UNLOCK); |
331 | menuBar()->insertItem(i18n("&View"), viewPopup); | 331 | menuBar()->insertItem(i18n("&View"), viewPopup); |
332 | // "options" popup menu | 332 | // "options" popup menu |
333 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 333 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
334 | i18n("&Configure..."), this, | 334 | i18n("&Configure..."), this, |
335 | SLOT(config_slot()), | 335 | SLOT(config_slot()), |
336 | BUTTON_POPUP_OPTIONS_CONFIG); | 336 | BUTTON_POPUP_OPTIONS_CONFIG); |
337 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 337 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
338 | // "help" popup menu | 338 | // "help" popup menu |
339 | #ifndef PWM_EMBEDDED | 339 | #ifndef PWM_EMBEDDED |
340 | helpPopup = helpMenu(QString::null, false); | 340 | helpPopup = helpMenu(QString::null, false); |
341 | #else | 341 | #else |
342 | menuBar()->insertItem(i18n("&Sync"), syncPopup); | 342 | menuBar()->insertItem(i18n("&Sync"), syncPopup); |
343 | 343 | ||
344 | 344 | ||
345 | 345 | ||
346 | 346 | ||
347 | 347 | ||
348 | helpPopup = new KPopupMenu(this); | 348 | helpPopup = new KPopupMenu(this); |
349 | 349 | ||
350 | 350 | ||
351 | helpPopup->insertItem(i18n("&License"), this, | 351 | helpPopup->insertItem(i18n("&License"), this, |
352 | SLOT(showLicense_slot()), 0, | 352 | SLOT(showLicense_slot()), 0, |
353 | BUTTON_POPUP_HELP_LICENSE); | 353 | BUTTON_POPUP_HELP_LICENSE); |
354 | 354 | ||
355 | helpPopup->insertItem(i18n("&Faq"), this, | 355 | helpPopup->insertItem(i18n("&Faq"), this, |
356 | SLOT(faq_slot()), 0, | 356 | SLOT(faq_slot()), 0, |
357 | BUTTON_POPUP_HELP_FAQ); | 357 | BUTTON_POPUP_HELP_FAQ); |
358 | 358 | ||
359 | helpPopup->insertItem(i18n("&About PwManager"), this, | 359 | helpPopup->insertItem(i18n("&About PwManager"), this, |
360 | SLOT(createAboutData_slot()), 0, | 360 | SLOT(createAboutData_slot()), 0, |
361 | BUTTON_POPUP_HELP_ABOUT); | 361 | BUTTON_POPUP_HELP_ABOUT); |
362 | 362 | ||
363 | helpPopup->insertItem(i18n("&Sync HowTo"), this, | 363 | helpPopup->insertItem(i18n("&Sync HowTo"), this, |
364 | SLOT(syncHowTo_slot()), 0, | 364 | SLOT(syncHowTo_slot()), 0, |
365 | BUTTON_POPUP_HELP_SYNC); | 365 | BUTTON_POPUP_HELP_SYNC); |
366 | 366 | ||
367 | helpPopup->insertItem(i18n("&What's New"), this, | 367 | helpPopup->insertItem(i18n("&What's New"), this, |
368 | SLOT(whatsnew_slot()), 0, | 368 | SLOT(whatsnew_slot()), 0, |
369 | BUTTON_POPUP_HELP_WHATSNEW); | 369 | BUTTON_POPUP_HELP_WHATSNEW); |
370 | 370 | ||
371 | #endif | 371 | #endif |
372 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 372 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
373 | 373 | ||
374 | } | 374 | } |
375 | 375 | ||
376 | void PwM::initToolbar() | 376 | void PwM::initToolbar() |
377 | { | 377 | { |
378 | KIconLoader* picons; | 378 | KIconLoader* picons; |
379 | #ifndef PWM_EMBEDDED | 379 | #ifndef PWM_EMBEDDED |
380 | KIconLoader icons; | 380 | KIconLoader icons; |
381 | picons = &icons; | 381 | picons = &icons; |
382 | #else | 382 | #else |
383 | picons = KGlobal::iconLoader(); | 383 | picons = KGlobal::iconLoader(); |
384 | #endif | 384 | #endif |
385 | 385 | ||
386 | #ifdef PWM_EMBEDDED | 386 | #ifdef PWM_EMBEDDED |
387 | if ( QApplication::desktop()->width() > 320 ) | 387 | if ( QApplication::desktop()->width() > 320 ) |
388 | #endif | 388 | #endif |
389 | { | 389 | { |
390 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 390 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
391 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 391 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
392 | SLOT(new_slot()), true, i18n("New")); | 392 | SLOT(new_slot()), true, i18n("New")); |
393 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 393 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
394 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 394 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
395 | SLOT(open_slot()), true, i18n("Open")); | 395 | SLOT(open_slot()), true, i18n("Open")); |
396 | toolBar()->insertSeparator(); | 396 | toolBar()->insertSeparator(); |
397 | } | 397 | } |
398 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), | 398 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), |
399 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, | 399 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, |
400 | SLOT(save_slot()), true, i18n("Save")); | 400 | SLOT(save_slot()), true, i18n("Save")); |
401 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), | 401 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), |
402 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, | 402 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, |
403 | SLOT(saveAs_slot()), true, i18n("Save as")); | 403 | SLOT(saveAs_slot()), true, i18n("Save as")); |
404 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), | 404 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), |
405 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, | 405 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, |
406 | SLOT(print_slot()), true, i18n("Print...")); | 406 | SLOT(print_slot()), true, i18n("Print...")); |
407 | toolBar()->insertSeparator(); | 407 | toolBar()->insertSeparator(); |
408 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), | 408 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), |
409 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, | 409 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, |
410 | SLOT(addPwd_slot()), true, | 410 | SLOT(addPwd_slot()), true, |
411 | i18n("Add password")); | 411 | i18n("Add password")); |
412 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), | 412 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), |
413 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, | 413 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, |
414 | SLOT(editPwd_slot()), true, | 414 | SLOT(editPwd_slot()), true, |
415 | i18n("Edit password")); | 415 | i18n("Edit password")); |
416 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), | 416 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), |
417 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, | 417 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, |
418 | SLOT(deletePwd_slot()), true, | 418 | SLOT(deletePwd_slot()), true, |
419 | i18n("Delete password")); | 419 | i18n("Delete password")); |
420 | toolBar()->insertSeparator(); | 420 | toolBar()->insertSeparator(); |
421 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), | 421 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), |
422 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, | 422 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, |
423 | SLOT(find_slot()), true, i18n("Find entry")); | 423 | SLOT(find_slot()), true, i18n("Find entry")); |
424 | toolBar()->insertSeparator(); | 424 | toolBar()->insertSeparator(); |
425 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), | 425 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), |
426 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, | 426 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, |
427 | SLOT(lockWnd_slot()), true, | 427 | SLOT(lockWnd_slot()), true, |
428 | i18n("Lock all entries")); | 428 | i18n("Lock all entries")); |
429 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), | 429 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), |
430 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, | 430 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, |
431 | SLOT(deepLockWnd_slot()), true, | 431 | SLOT(deepLockWnd_slot()), true, |
432 | i18n("Deep-Lock all entries")); | 432 | i18n("Deep-Lock all entries")); |
433 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), | 433 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), |
434 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, | 434 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, |
435 | SLOT(unlockWnd_slot()), true, | 435 | SLOT(unlockWnd_slot()), true, |
436 | i18n("Unlock all entries")); | 436 | i18n("Unlock all entries")); |
437 | } | 437 | } |
438 | 438 | ||
439 | void PwM::initMetrics() | 439 | void PwM::initMetrics() |
440 | { | 440 | { |
441 | QSize s = conf()->confWndMainWndSize(); | 441 | QSize s = conf()->confWndMainWndSize(); |
442 | if (s.isValid()) | 442 | if (s.isValid()) |
443 | resize(s); | 443 | resize(s); |
444 | else | 444 | else |
445 | resize(DEFAULT_SIZE); | 445 | resize(DEFAULT_SIZE); |
446 | } | 446 | } |
447 | 447 | ||
448 | void PwM::updateCaption() | 448 | void PwM::updateCaption() |
449 | { | 449 | { |
450 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); | 450 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); |
451 | } | 451 | } |
452 | 452 | ||
453 | void PwM::hideEvent(QHideEvent *) | 453 | void PwM::hideEvent(QHideEvent *) |
454 | { | 454 | { |
455 | if (isMinimized()) { | 455 | if (isMinimized()) { |
456 | if (init->tray()) { | 456 | if (init->tray()) { |
457 | forceMinimizeToTray = true; | 457 | forceMinimizeToTray = true; |
458 | close(); | 458 | close(); |
459 | } | 459 | } |
460 | int mmlock = conf()->confGlobMinimizeLock(); | 460 | int mmlock = conf()->confGlobMinimizeLock(); |
461 | switch (mmlock) { | 461 | switch (mmlock) { |
462 | case 0: // don't lock anything | 462 | case 0: // don't lock anything |
463 | break; | 463 | break; |
464 | case 1: {// normal lock | 464 | case 1: {// normal lock |
465 | curDoc()->lockAll(true); | 465 | curDoc()->lockAll(true); |
466 | break; | 466 | break; |
467 | } case 2: {// deep-lock | 467 | } case 2: {// deep-lock |
468 | curDoc()->deepLock(); | 468 | curDoc()->deepLock(); |
469 | break; | 469 | break; |
470 | } default: | 470 | } default: |
471 | WARN(); | 471 | WARN(); |
472 | } | 472 | } |
473 | } | 473 | } |
474 | } | 474 | } |
475 | 475 | ||
476 | void PwM::setVirgin(bool v) | 476 | void PwM::setVirgin(bool v) |
477 | { | 477 | { |
478 | if (virgin == v) | 478 | if (virgin == v) |
479 | return; | 479 | return; |
480 | virgin = v; | 480 | virgin = v; |
481 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); | 481 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); |
482 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); | 482 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); |
483 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); | 483 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); |
484 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); | 484 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); |
485 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); | 485 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); |
486 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); | 486 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); |
487 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); | 487 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); |
488 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); | 488 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); |
489 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); | 489 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); |
490 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); | 490 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); |
491 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); | 491 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); |
492 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); | 492 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); |
493 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); | 493 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); |
494 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); | 494 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); |
495 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); | 495 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); |
496 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); | 496 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); |
497 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); | 497 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); |
498 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); | 498 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); |
499 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); | 499 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); |
500 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); | 500 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); |
501 | } | 501 | } |
502 | 502 | ||
503 | void PwM::new_slot() | 503 | void PwM::new_slot() |
504 | { | 504 | { |
505 | init->createMainWnd(); | 505 | init->createMainWnd(); |
506 | } | 506 | } |
507 | 507 | ||
508 | //US ENH | 508 | //US ENH |
509 | void PwM::open_slot() | 509 | void PwM::open_slot() |
510 | { | 510 | { |
511 | open_slot(""); | 511 | open_slot(""); |
512 | } | 512 | } |
513 | 513 | ||
514 | void PwM::open_slot(QString fn) | 514 | void PwM::open_slot(QString fn) |
515 | { | 515 | { |
516 | openDoc(fn); | 516 | openDoc(fn); |
517 | } | 517 | } |
518 | 518 | ||
519 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) | 519 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) |
520 | { | 520 | { |
521 | if (!isVirgin()) { | 521 | if (!isVirgin()) { |
522 | // open the document in a new window. | 522 | // open the document in a new window. |
523 | PwM *newInstance = init->createMainWnd(); | 523 | PwM *newInstance = init->createMainWnd(); |
524 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); | 524 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); |
525 | if (!newDoc) { | 525 | if (!newDoc) { |
526 | newInstance->setForceQuit(true); | 526 | newInstance->setForceQuit(true); |
527 | delete_and_null(newInstance); | 527 | delete_and_null(newInstance); |
528 | } | 528 | } |
529 | return newDoc; | 529 | return newDoc; |
530 | } | 530 | } |
531 | 531 | ||
532 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) | 532 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) |
533 | return 0; | 533 | return 0; |
534 | showStatMsg(i18n("Successfully opened file.")); | 534 | showStatMsg(i18n("Successfully opened file.")); |
535 | updateCaption(); | 535 | updateCaption(); |
536 | setVirgin(false); | 536 | setVirgin(false); |
537 | return curDoc(); | 537 | return curDoc(); |
538 | } | 538 | } |
539 | 539 | ||
540 | PwMView * PwM::makeNewListView(PwMDoc *doc) | 540 | PwMView * PwM::makeNewListView(PwMDoc *doc) |
541 | { | 541 | { |
542 | PwMView *ret = new PwMView(this, this, doc); | 542 | PwMView *ret = new PwMView(this, this, doc); |
543 | ret->setFont(conf()->confGlobEntryFont()); | 543 | ret->setFont(conf()->confGlobEntryFont()); |
544 | ret->show(); | 544 | ret->show(); |
545 | return ret; | 545 | return ret; |
546 | } | 546 | } |
547 | 547 | ||
548 | void PwM::close_slot() | 548 | void PwM::close_slot() |
549 | { | 549 | { |
550 | close(); | 550 | close(); |
551 | } | 551 | } |
552 | 552 | ||
553 | void PwM::quitButton_slot() | 553 | void PwM::quitButton_slot() |
554 | { | 554 | { |
555 | init->shutdownApp(0); | 555 | init->shutdownApp(0); |
556 | } | 556 | } |
557 | 557 | ||
558 | void PwM::save_slot() | 558 | void PwM::save_slot() |
559 | { | 559 | { |
560 | save(); | 560 | save(); |
561 | } | 561 | } |
562 | 562 | ||
563 | bool PwM::save() | 563 | bool PwM::save() |
564 | { | 564 | { |
565 | if (!curDoc()->saveDocUi(curDoc())) | 565 | if (!curDoc()->saveDocUi(curDoc())) |
566 | return false; | 566 | return false; |
567 | showStatMsg(i18n("Successfully saved data.")); | 567 | showStatMsg(i18n("Successfully saved data.")); |
568 | updateCaption(); | 568 | updateCaption(); |
569 | return true; | 569 | return true; |
570 | } | 570 | } |
571 | 571 | ||
572 | void PwM::saveAs_slot() | 572 | void PwM::saveAs_slot() |
573 | { | 573 | { |
574 | saveAs(); | 574 | saveAs(); |
575 | } | 575 | } |
576 | 576 | ||
577 | bool PwM::saveAs() | 577 | bool PwM::saveAs() |
578 | { | 578 | { |
579 | if (!curDoc()->saveAsDocUi(curDoc())) | 579 | if (!curDoc()->saveAsDocUi(curDoc())) |
580 | return false; | 580 | return false; |
581 | showStatMsg(i18n("Successfully saved data.")); | 581 | showStatMsg(i18n("Successfully saved data.")); |
582 | updateCaption(); | 582 | updateCaption(); |
583 | return true; | 583 | return true; |
584 | } | 584 | } |
585 | 585 | ||
586 | //US ENH : changed code to run with older MOC | 586 | //US ENH : changed code to run with older MOC |
587 | void PwM::addPwd_slot() | 587 | void PwM::addPwd_slot() |
588 | { | 588 | { |
589 | addPwd_slot1(0, 0); | 589 | addPwd_slot1(0, 0); |
590 | } | 590 | } |
591 | 591 | ||
592 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) | 592 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) |
593 | { | 593 | { |
594 | PwMDoc *doc; | 594 | PwMDoc *doc; |
595 | if (_doc) { | 595 | if (_doc) { |
596 | doc = _doc; | 596 | doc = _doc; |
597 | } else { | 597 | } else { |
598 | doc = curDoc(); | 598 | doc = curDoc(); |
599 | } | 599 | } |
600 | PWM_ASSERT(doc); | 600 | PWM_ASSERT(doc); |
601 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 601 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
602 | #ifndef PWM_EMBEDDED | 602 | #ifndef PWM_EMBEDDED |
603 | AddEntryWndImpl w; | 603 | AddEntryWndImpl w; |
604 | #else | 604 | #else |
605 | AddEntryWndImpl w(this, "addentrywndimpl"); | 605 | AddEntryWndImpl w(this, "addentrywndimpl"); |
606 | #endif | 606 | #endif |
607 | 607 | ||
608 | vector<string> catList; | 608 | vector<string> catList; |
609 | doc->getCategoryList(&catList); | 609 | doc->getCategoryList(&catList); |
610 | unsigned i, size = catList.size(); | 610 | unsigned i, size = catList.size(); |
611 | for (i = 0; i < size; ++i) { | 611 | for (i = 0; i < size; ++i) { |
612 | w.addCategory(catList[i].c_str()); | 612 | w.addCategory(catList[i].c_str()); |
613 | } | 613 | } |
614 | w.setCurrCategory(view->getCurrentCategory()); | 614 | w.setCurrCategory(view->getCurrentCategory()); |
615 | if (pw) | 615 | if (pw) |
616 | w.pwLineEdit->setText(*pw); | 616 | w.pwLineEdit->setText(*pw); |
617 | 617 | ||
618 | tryAgain: | 618 | tryAgain: |
619 | if (w.exec() == 1) | 619 | if (w.exec() == 1) |
620 | { | 620 | { |
621 | PwMDataItem d; | 621 | PwMDataItem d; |
622 | 622 | ||
623 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 623 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
624 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | 624 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. |
625 | // another option would be to create a constructor for PwMDataItem | 625 | // another option would be to create a constructor for PwMDataItem |
626 | d.clear(true); | 626 | d.clear(true); |
627 | 627 | ||
628 | d.desc = w.getDescription().latin1(); | 628 | d.desc = w.getDescription().latin1(); |
629 | d.name = w.getUsername().latin1(); | 629 | d.name = w.getUsername().latin1(); |
630 | d.pw = w.getPassword().latin1(); | 630 | d.pw = w.getPassword().latin1(); |
631 | d.comment = w.getComment().latin1(); | 631 | d.comment = w.getComment().latin1(); |
632 | d.url = w.getUrl().latin1(); | 632 | d.url = w.getUrl().latin1(); |
633 | d.launcher = w.getLauncher().latin1(); | 633 | d.launcher = w.getLauncher().latin1(); |
634 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 634 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
635 | if (ret == e_entryExists) { | 635 | if (ret == e_entryExists) { |
636 | KMessageBox::error(this, | 636 | KMessageBox::error(this, |
637 | i18n | 637 | i18n |
638 | ("An entry with this \"Description\",\n" | 638 | ("An entry with this \"Description\",\n" |
639 | "does already exist.\n" | 639 | "does already exist.\n" |
640 | "Please select another description."), | 640 | "Please select another description."), |
641 | i18n("entry already exists.")); | 641 | i18n("entry already exists.")); |
642 | goto tryAgain; | 642 | goto tryAgain; |
643 | } else if (ret == e_maxAllowedEntr) { | 643 | } else if (ret == e_maxAllowedEntr) { |
644 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" | 644 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" |
645 | "has been reached.\nYou can't add more entries."), | 645 | "has been reached.\nYou can't add more entries."), |
646 | i18n("maximum number of entries")); | 646 | i18n("maximum number of entries")); |
647 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 647 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
648 | return; | 648 | return; |
649 | } | 649 | } |
650 | } | 650 | } |
651 | setVirgin(false); | 651 | setVirgin(false); |
652 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 652 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
653 | } | 653 | } |
654 | 654 | ||
655 | //US ENH : changed code to run with older MOC | 655 | //US ENH : changed code to run with older MOC |
656 | void PwM::editPwd_slot() | 656 | void PwM::editPwd_slot() |
657 | { | 657 | { |
658 | editPwd_slot3(0,0,0); | 658 | editPwd_slot3(0,0,0); |
659 | } | 659 | } |
660 | 660 | ||
661 | void PwM::editPwd_slot1(const QString *category) | 661 | void PwM::editPwd_slot1(const QString *category) |
662 | { | 662 | { |
663 | editPwd_slot3(category, 0, 0); | 663 | editPwd_slot3(category, 0, 0); |
664 | } | 664 | } |
665 | 665 | ||
666 | void PwM::editPwd_slot3(const QString *category, const int *index, | 666 | void PwM::editPwd_slot3(const QString *category, const int *index, |
667 | PwMDoc *_doc) | 667 | PwMDoc *_doc) |
668 | { | 668 | { |
669 | PwMDoc *doc; | 669 | PwMDoc *doc; |
670 | if (_doc) { | 670 | if (_doc) { |
671 | doc = _doc; | 671 | doc = _doc; |
672 | } else { | 672 | } else { |
673 | doc = curDoc(); | 673 | doc = curDoc(); |
674 | } | 674 | } |
675 | PWM_ASSERT(doc); | 675 | PWM_ASSERT(doc); |
676 | if (doc->isDocEmpty()) | 676 | if (doc->isDocEmpty()) |
677 | return; | 677 | return; |
678 | if (doc->isDeepLocked()) | 678 | if (doc->isDeepLocked()) |
679 | return; | 679 | return; |
680 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 680 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
681 | unsigned int curEntryIndex; | 681 | unsigned int curEntryIndex; |
682 | if (index) { | 682 | if (index) { |
683 | curEntryIndex = *index; | 683 | curEntryIndex = *index; |
684 | } else { | 684 | } else { |
685 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 685 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
686 | printDebug("couldn't get index. Maybe we have a binary entry here."); | 686 | printDebug("couldn't get index. Maybe we have a binary entry here."); |
687 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 687 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
688 | return; | 688 | return; |
689 | } | 689 | } |
690 | } | 690 | } |
691 | QString curCategory; | 691 | QString curCategory; |
692 | if (category) { | 692 | if (category) { |
693 | curCategory = *category; | 693 | curCategory = *category; |
694 | } else { | 694 | } else { |
695 | curCategory = view->getCurrentCategory(); | 695 | curCategory = view->getCurrentCategory(); |
696 | } | 696 | } |
697 | PwMDataItem currItem; | 697 | PwMDataItem currItem; |
698 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { | 698 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { |
699 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 699 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
700 | return; | 700 | return; |
701 | } | 701 | } |
702 | BUG_ON(currItem.binary); | 702 | BUG_ON(currItem.binary); |
703 | 703 | ||
704 | AddEntryWndImpl w; | 704 | AddEntryWndImpl w; |
705 | vector<string> catList; | 705 | vector<string> catList; |
706 | doc->getCategoryList(&catList); | 706 | doc->getCategoryList(&catList); |
707 | unsigned i, size = catList.size(); | 707 | unsigned i, size = catList.size(); |
708 | for (i = 0; i < size; ++i) { | 708 | for (i = 0; i < size; ++i) { |
709 | w.addCategory(catList[i].c_str()); | 709 | w.addCategory(catList[i].c_str()); |
710 | } | 710 | } |
711 | w.setCurrCategory(curCategory); | 711 | w.setCurrCategory(curCategory); |
712 | w.setDescription(currItem.desc.c_str()); | 712 | w.setDescription(currItem.desc.c_str()); |
713 | w.setUsername(currItem.name.c_str()); | 713 | w.setUsername(currItem.name.c_str()); |
714 | w.setPassword(currItem.pw.c_str()); | 714 | w.setPassword(currItem.pw.c_str()); |
715 | w.setUrl(currItem.url.c_str()); | 715 | w.setUrl(currItem.url.c_str()); |
716 | w.setLauncher(currItem.launcher.c_str()); | 716 | w.setLauncher(currItem.launcher.c_str()); |
717 | w.setComment(currItem.comment.c_str()); | 717 | w.setComment(currItem.comment.c_str()); |
718 | if (w.exec() == 1) { | 718 | if (w.exec() == 1) { |
719 | currItem.desc = w.getDescription().latin1(); | 719 | currItem.desc = w.getDescription().latin1(); |
720 | currItem.name = w.getUsername().latin1(); | 720 | currItem.name = w.getUsername().latin1(); |
721 | currItem.pw = w.getPassword().latin1(); | 721 | currItem.pw = w.getPassword().latin1(); |
722 | currItem.comment = w.getComment().latin1(); | 722 | currItem.comment = w.getComment().latin1(); |
723 | currItem.url = w.getUrl().latin1(); | 723 | currItem.url = w.getUrl().latin1(); |
724 | currItem.launcher = w.getLauncher().latin1(); | 724 | currItem.launcher = w.getLauncher().latin1(); |
725 | if (!doc->editEntry(curCategory, w.getCategory(), | 725 | if (!doc->editEntry(curCategory, w.getCategory(), |
726 | curEntryIndex, &currItem)) { | 726 | curEntryIndex, &currItem)) { |
727 | KMessageBox::error(this, | 727 | KMessageBox::error(this, |
728 | i18n("Couldn't edit the entry.\n" | 728 | i18n("Couldn't edit the entry.\n" |
729 | "Maybe you changed the category and " | 729 | "Maybe you changed the category and\n" |
730 | "this entry is already present in the new " | 730 | "this entry is already present\nin the new " |
731 | "category?"), | 731 | "category?"), |
732 | i18n("couldn't edit entry.")); | 732 | i18n("couldn't edit entry.")); |
733 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 733 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
734 | return; | 734 | return; |
735 | } | 735 | } |
736 | } | 736 | } |
737 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 737 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
738 | } | 738 | } |
739 | 739 | ||
740 | void PwM::deletePwd_slot() | 740 | void PwM::deletePwd_slot() |
741 | { | 741 | { |
742 | PWM_ASSERT(curDoc()); | 742 | PWM_ASSERT(curDoc()); |
743 | if (curDoc()->isDocEmpty()) | 743 | if (curDoc()->isDocEmpty()) |
744 | return; | 744 | return; |
745 | if (curDoc()->isDeepLocked()) | 745 | if (curDoc()->isDeepLocked()) |
746 | return; | 746 | return; |
747 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 747 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
748 | unsigned int curEntryIndex = 0; | 748 | unsigned int curEntryIndex = 0; |
749 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 749 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
750 | printDebug("couldn't get index"); | 750 | printDebug("couldn't get index"); |
751 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 751 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
752 | return; | 752 | return; |
753 | } | 753 | } |
754 | 754 | ||
755 | PwMDataItem currItem; | 755 | PwMDataItem currItem; |
756 | QString curCategory = view->getCurrentCategory(); | 756 | QString curCategory = view->getCurrentCategory(); |
757 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { | 757 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { |
758 | printDebug("couldn't get entry"); | 758 | printDebug("couldn't get entry"); |
759 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 759 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
760 | return; | 760 | return; |
761 | } | 761 | } |
762 | if (KMessageBox:: | 762 | if (KMessageBox:: |
763 | questionYesNo(this, | 763 | questionYesNo(this, |
764 | i18n | 764 | i18n |
765 | ("Do you really want to delete\nthe selected entry") + | 765 | ("Do you really want to delete\nthe selected entry") + |
766 | " \n\"" + QString(currItem.desc.c_str()) | 766 | " \n\"" + QString(currItem.desc.c_str()) |
767 | + "\" ?", i18n("delete?")) | 767 | + "\" ?", i18n("delete?")) |
768 | == KMessageBox::Yes) { | 768 | == KMessageBox::Yes) { |
769 | 769 | ||
770 | curDoc()->delEntry(curCategory, curEntryIndex); | 770 | curDoc()->delEntry(curCategory, curEntryIndex); |
771 | } | 771 | } |
772 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 772 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
773 | } | 773 | } |
774 | 774 | ||
775 | void PwM::changeMasterPwd_slot() | 775 | void PwM::changeMasterPwd_slot() |
776 | { | 776 | { |
777 | PWM_ASSERT(curDoc()); | 777 | PWM_ASSERT(curDoc()); |
778 | curDoc()->changeCurrentPw(); | 778 | curDoc()->changeCurrentPw(); |
779 | } | 779 | } |
780 | 780 | ||
781 | void PwM::lockWnd_slot() | 781 | void PwM::lockWnd_slot() |
782 | { | 782 | { |
783 | PWM_ASSERT(curDoc()); | 783 | PWM_ASSERT(curDoc()); |
784 | curDoc()->lockAll(true); | 784 | curDoc()->lockAll(true); |
785 | } | 785 | } |
786 | 786 | ||
787 | void PwM::deepLockWnd_slot() | 787 | void PwM::deepLockWnd_slot() |
788 | { | 788 | { |
789 | PWM_ASSERT(curDoc()); | 789 | PWM_ASSERT(curDoc()); |
790 | curDoc()->deepLock(); | 790 | curDoc()->deepLock(); |
791 | } | 791 | } |
792 | 792 | ||
793 | void PwM::unlockWnd_slot() | 793 | void PwM::unlockWnd_slot() |
794 | { | 794 | { |
795 | PWM_ASSERT(curDoc()); | 795 | PWM_ASSERT(curDoc()); |
796 | curDoc()->lockAll(false); | 796 | curDoc()->lockAll(false); |
797 | } | 797 | } |
798 | 798 | ||
799 | void PwM::config_slot() | 799 | void PwM::config_slot() |
800 | { | 800 | { |
801 | int oldStyle = conf()->confWndMainViewStyle(); | 801 | int oldStyle = conf()->confWndMainViewStyle(); |
802 | #ifdef PWM_EMBEDDED | 802 | #ifdef PWM_EMBEDDED |
803 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); | 803 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); |
804 | 804 | ||
805 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); | 805 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); |
806 | ConfigureDialog->addModule(pwmcfg ); | 806 | ConfigureDialog->addModule(pwmcfg ); |
807 | 807 | ||
808 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 808 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
809 | ConfigureDialog->addModule(kdelibcfg ); | 809 | ConfigureDialog->addModule(kdelibcfg ); |
810 | 810 | ||
811 | #ifndef DESKTOP_VERSION | 811 | #ifndef DESKTOP_VERSION |
812 | ConfigureDialog->showMaximized(); | 812 | ConfigureDialog->showMaximized(); |
813 | #endif | 813 | #endif |
814 | if ( ConfigureDialog->exec() ) | 814 | if ( ConfigureDialog->exec() ) |
815 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 815 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
816 | delete ConfigureDialog; | 816 | delete ConfigureDialog; |
817 | 817 | ||
818 | #else //PWM_EMBEDDED | 818 | #else //PWM_EMBEDDED |
819 | // display the configuration window (modal mode) | 819 | // display the configuration window (modal mode) |
820 | if (!conf()->showConfWnd(this)) | 820 | if (!conf()->showConfWnd(this)) |
821 | return; | 821 | return; |
822 | #endif | 822 | #endif |
823 | 823 | ||
824 | int newStyle = conf()->confWndMainViewStyle(); | 824 | int newStyle = conf()->confWndMainViewStyle(); |
825 | // reinitialize tray | 825 | // reinitialize tray |
826 | init->initTray(); | 826 | init->initTray(); |
827 | // reinitialize KWallet emulation | 827 | // reinitialize KWallet emulation |
828 | init->initKWalletEmu(); | 828 | init->initKWalletEmu(); |
829 | 829 | ||
830 | PwMDocList *_dl = PwMDoc::getOpenDocList(); | 830 | PwMDocList *_dl = PwMDoc::getOpenDocList(); |
831 | const vector<PwMDocList::listItem> *dl = _dl->getList(); | 831 | const vector<PwMDocList::listItem> *dl = _dl->getList(); |
832 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), | 832 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), |
833 | end = dl->end(); | 833 | end = dl->end(); |
834 | PwMDoc *doc; | 834 | PwMDoc *doc; |
835 | while (i != end) { | 835 | while (i != end) { |
836 | doc = (*i).doc; | 836 | doc = (*i).doc; |
837 | // unlock-without-mpw timeout | 837 | // unlock-without-mpw timeout |
838 | doc->timer()->start(DocTimer::id_mpwTimer); | 838 | doc->timer()->start(DocTimer::id_mpwTimer); |
839 | // auto-lock timeout | 839 | // auto-lock timeout |
840 | doc->timer()->start(DocTimer::id_autoLockTimer); | 840 | doc->timer()->start(DocTimer::id_autoLockTimer); |
841 | ++i; | 841 | ++i; |
842 | } | 842 | } |
843 | 843 | ||
844 | const QValueList<PwM *> *ml = init->mainWndList(); | 844 | const QValueList<PwM *> *ml = init->mainWndList(); |
845 | #ifndef PWM_EMBEDDED | 845 | #ifndef PWM_EMBEDDED |
846 | QValueList<PwM *>::const_iterator i2 = ml->begin(), | 846 | QValueList<PwM *>::const_iterator i2 = ml->begin(), |
847 | end2 = ml->end(); | 847 | end2 = ml->end(); |
848 | #else | 848 | #else |
849 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), | 849 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), |
850 | end2 = ml->end(); | 850 | end2 = ml->end(); |
851 | #endif | 851 | #endif |
852 | PwM *pwm; | 852 | PwM *pwm; |
853 | while (i2 != end2) { | 853 | while (i2 != end2) { |
854 | pwm = *i2; | 854 | pwm = *i2; |
855 | // reinitialize the window style. | 855 | // reinitialize the window style. |
856 | if (oldStyle != newStyle) | 856 | if (oldStyle != newStyle) |
857 | pwm->curView()->initStyle(newStyle); | 857 | pwm->curView()->initStyle(newStyle); |
858 | // set the new font | 858 | // set the new font |
859 | pwm->curView()->setFont(conf()->confGlobEntryFont()); | 859 | pwm->curView()->setFont(conf()->confGlobEntryFont()); |
860 | ++i2; | 860 | ++i2; |
861 | } | 861 | } |
862 | } | 862 | } |
863 | 863 | ||
864 | void PwM::activateMpButton(bool activate) | 864 | void PwM::activateMpButton(bool activate) |
865 | { | 865 | { |
866 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); | 866 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); |
867 | } | 867 | } |
868 | 868 | ||
869 | void PwM::closeEvent(QCloseEvent *e) | 869 | void PwM::closeEvent(QCloseEvent *e) |
870 | { | 870 | { |
871 | e->accept(); | 871 | e->accept(); |
872 | } | 872 | } |
873 | 873 | ||
874 | void PwM::docClosed(PwMDoc *doc) | 874 | void PwM::docClosed(PwMDoc *doc) |
875 | { | 875 | { |
876 | PARAM_UNUSED(doc); | 876 | PARAM_UNUSED(doc); |
877 | PWM_ASSERT(doc == curDoc()); | 877 | PWM_ASSERT(doc == curDoc()); |
878 | close(); | 878 | close(); |
879 | } | 879 | } |
880 | 880 | ||
881 | void PwM::find_slot() | 881 | void PwM::find_slot() |
882 | { | 882 | { |
883 | PWM_ASSERT(curDoc()); | 883 | PWM_ASSERT(curDoc()); |
884 | if (curDoc()->isDocEmpty()) | 884 | if (curDoc()->isDocEmpty()) |
885 | return; | 885 | return; |
886 | if (curDoc()->isDeepLocked()) | 886 | if (curDoc()->isDeepLocked()) |
887 | return; | 887 | return; |
888 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 888 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
889 | FindWndImpl findWnd(view); | 889 | FindWndImpl findWnd(view); |
890 | findWnd.exec(); | 890 | findWnd.exec(); |
891 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 891 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
892 | } | 892 | } |
893 | 893 | ||
894 | void PwM::exportToText() | 894 | void PwM::exportToText() |
895 | { | 895 | { |
896 | PWM_ASSERT(curDoc()); | 896 | PWM_ASSERT(curDoc()); |
897 | if (curDoc()->isDocEmpty()) { | 897 | if (curDoc()->isDocEmpty()) { |
898 | KMessageBox::information(this, | 898 | KMessageBox::information(this, |
899 | i18n | 899 | i18n |
900 | ("Sorry, there's nothing to export.\n" | 900 | ("Sorry, there's nothing to export.\n" |
901 | "Please first add some passwords."), | 901 | "Please first add some passwords."), |
902 | i18n("nothing to do")); | 902 | i18n("nothing to do")); |
903 | return; | 903 | return; |
904 | } | 904 | } |
905 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 905 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
906 | QString fn(KFileDialog::getSaveFileName(QString::null, | 906 | QString fn(KFileDialog::getSaveFileName(QString::null, |
907 | i18n("*|plain-text file"), | 907 | i18n("*|plain-text file"), |
908 | this)); | 908 | this)); |
909 | if (fn == "") { | 909 | if (fn == "") { |
910 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 910 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
911 | return; | 911 | return; |
912 | } | 912 | } |
913 | 913 | ||
914 | PwMerror ret = curDoc()->exportToText(&fn); | 914 | PwMerror ret = curDoc()->exportToText(&fn); |
915 | if (ret != e_success) { | 915 | if (ret != e_success) { |
916 | KMessageBox::error(this, | 916 | KMessageBox::error(this, |
917 | i18n("Error: Couldn't write to file.\n" | 917 | i18n("Error: Couldn't write to file.\n" |
918 | "Please check if you have permission to write " | 918 | "Please check if you have permission to write\n" |
919 | "to the file in that directory."), | 919 | "to the file in that directory."), |
920 | i18n("error while writing")); | 920 | i18n("error while writing")); |
921 | } else | 921 | } else |
922 | showStatMsg(i18n("Successfully exported data.")); | 922 | showStatMsg(i18n("Successfully exported data.")); |
923 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 923 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
924 | } | 924 | } |
925 | 925 | ||
926 | bool PwM::importFromText() | 926 | bool PwM::importFromText() |
927 | { | 927 | { |
928 | if (!isVirgin()) { | 928 | if (!isVirgin()) { |
929 | if (KMessageBox::questionYesNo(this, | 929 | if (KMessageBox::questionYesNo(this, |
930 | i18n("Do you want to import the data " | 930 | i18n("Do you want to import the data\n" |
931 | "into the current document? (If you " | 931 | "into the current document? (If you\n" |
932 | "select \"no\", a new document will be " | 932 | "select \"no\", a new document will be\n" |
933 | "opened.)"), | 933 | "opened.)"), |
934 | i18n("import into this document?")) | 934 | i18n("import into this document?")) |
935 | == KMessageBox::No) { | 935 | == KMessageBox::No) { |
936 | // import the data to a new window. | 936 | // import the data to a new window. |
937 | PwM *newInstance = init->createMainWnd(); | 937 | PwM *newInstance = init->createMainWnd(); |
938 | bool ok = newInstance->importFromText(); | 938 | bool ok = newInstance->importFromText(); |
939 | if (!ok) { | 939 | if (!ok) { |
940 | newInstance->setForceQuit(true); | 940 | newInstance->setForceQuit(true); |
941 | delete_and_null(newInstance); | 941 | delete_and_null(newInstance); |
942 | } | 942 | } |
943 | return ok; | 943 | return ok; |
944 | } | 944 | } |
945 | } | 945 | } |
946 | 946 | ||
947 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 947 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
948 | PwMerror ret; | 948 | PwMerror ret; |
949 | QString path(KFileDialog::getOpenFileName(QString::null, | 949 | QString path(KFileDialog::getOpenFileName(QString::null, |
950 | i18n("*|PWM-exported text file"), | 950 | i18n("*|PWM-exported text file"), |
951 | this)); | 951 | this)); |
952 | if (path == "") | 952 | if (path == "") |
953 | goto cancelImport; | 953 | goto cancelImport; |
954 | 954 | ||
955 | ret = curDoc()->importFromText(&path, 0); | 955 | ret = curDoc()->importFromText(&path, 0); |
956 | if (ret == e_fileFormat) { | 956 | if (ret == e_fileFormat) { |
957 | KMessageBox::error(this, | 957 | KMessageBox::error(this, |
958 | i18n("Could not read file-format.\n" | 958 | i18n("Could not read file-format.\n" |
959 | "This seems to be _not_ a valid file " | 959 | "This seems to be _not_ a valid file\n" |
960 | "exported by PwM."), | 960 | "exported by PwM."), |
961 | i18n("invalid file-format")); | 961 | i18n("invalid file-format")); |
962 | goto cancelImport; | 962 | goto cancelImport; |
963 | } else if (ret == e_invalidArg) { | 963 | } else if (ret == e_invalidArg) { |
964 | BUG(); | 964 | BUG(); |
965 | goto cancelImport; | 965 | goto cancelImport; |
966 | } else if (ret != e_success) { | 966 | } else if (ret != e_success) { |
967 | KMessageBox::error(this, | 967 | KMessageBox::error(this, |
968 | i18n("Could not import file!\n" | 968 | i18n("Could not import file!\n" |
969 | "Do you have permission to read this file? " | 969 | "Do you have permission to read this file?\n" |
970 | "Do you have enough free memory?"), | 970 | "Do you have enough free memory?"), |
971 | i18n("import failed")); | 971 | i18n("import failed")); |
972 | goto cancelImport; | 972 | goto cancelImport; |
973 | } | 973 | } |
974 | setVirgin(false); | 974 | setVirgin(false); |
975 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 975 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
976 | return true; | 976 | return true; |
977 | 977 | ||
978 | cancelImport: | 978 | cancelImport: |
979 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 979 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
980 | return false; | 980 | return false; |
981 | } | 981 | } |
982 | 982 | ||
983 | void PwM::exportToGpasman() | 983 | void PwM::exportToGpasman() |
984 | { | 984 | { |
985 | PWM_ASSERT(curDoc()); | 985 | PWM_ASSERT(curDoc()); |
986 | if (curDoc()->isDocEmpty()) { | 986 | if (curDoc()->isDocEmpty()) { |
987 | KMessageBox::information(this, | 987 | KMessageBox::information(this, |
988 | i18n | 988 | i18n |
989 | ("Sorry, there's nothing to export.\n" | 989 | ("Sorry, there's nothing to export.\n" |
990 | "Please first add some passwords."), | 990 | "Please first add some passwords."), |
991 | i18n("nothing to do")); | 991 | i18n("nothing to do")); |
992 | return; | 992 | return; |
993 | } | 993 | } |
994 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 994 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
995 | QString fn(KFileDialog::getSaveFileName(QString::null, | 995 | QString fn(KFileDialog::getSaveFileName(QString::null, |
996 | i18n("*|Gpasman or Kpasman file"), | 996 | i18n("*|Gpasman or Kpasman file"), |
997 | this)); | 997 | this)); |
998 | if (fn == "") { | 998 | if (fn == "") { |
999 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 999 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1000 | return; | 1000 | return; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 1003 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
1004 | if (ret != e_success) { | 1004 | if (ret != e_success) { |
1005 | if (ret == e_noPw) { | 1005 | if (ret == e_noPw) { |
1006 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1006 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1007 | return; | 1007 | return; |
1008 | } | 1008 | } |
1009 | KMessageBox::error(this, | 1009 | KMessageBox::error(this, |
1010 | i18n("Error: Couldn't write to file.\n" | 1010 | i18n("Error: Couldn't write to file.\n" |
1011 | "Please check if you have permission to write " | 1011 | "Please check if you have permission to write " |
1012 | "to the file in that directory."), | 1012 | "to the file in that directory."), |
1013 | i18n("error while writing")); | 1013 | i18n("error while writing")); |
1014 | } else | 1014 | } else |
1015 | showStatMsg(i18n("Successfully exported data.")); | 1015 | showStatMsg(i18n("Successfully exported data.")); |
1016 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1016 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | void PwM::exportToKWallet() | 1019 | void PwM::exportToKWallet() |
1020 | { | 1020 | { |
1021 | #ifdef CONFIG_KWALLETIF | 1021 | #ifdef CONFIG_KWALLETIF |
1022 | if (!checkAndAskForKWalletEmu()) | 1022 | if (!checkAndAskForKWalletEmu()) |
1023 | return; | 1023 | return; |
1024 | PWM_ASSERT(curDoc()); | 1024 | PWM_ASSERT(curDoc()); |
1025 | if (curDoc()->isDocEmpty()) { | 1025 | if (curDoc()->isDocEmpty()) { |
1026 | KMessageBox::information(this, | 1026 | KMessageBox::information(this, |
1027 | i18n | 1027 | i18n |
1028 | ("Sorry, there's nothing to export.\n" | 1028 | ("Sorry, there's nothing to export.\n" |
1029 | "Please first add some passwords."), | 1029 | "Please first add some passwords."), |
1030 | i18n("nothing to do")); | 1030 | i18n("nothing to do")); |
1031 | init->initKWalletEmu(); | 1031 | init->initKWalletEmu(); |
1032 | return; | 1032 | return; |
1033 | } | 1033 | } |
1034 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1034 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1035 | KWalletIf walletIf(this); | 1035 | KWalletIf walletIf(this); |
1036 | if (walletIf.kwalletExport(curDoc())) { | 1036 | if (walletIf.kwalletExport(curDoc())) { |
1037 | KMessageBox::information(this, | 1037 | KMessageBox::information(this, |
1038 | i18n("Successfully exported the data of the current " | 1038 | i18n("Successfully exported the data of the current " |
1039 | "document to KWallet."), | 1039 | "document to KWallet."), |
1040 | i18n("Successfully exported data.")); | 1040 | i18n("Successfully exported data.")); |
1041 | showStatMsg(i18n("Successfully exported data.")); | 1041 | showStatMsg(i18n("Successfully exported data.")); |
1042 | } | 1042 | } |
1043 | init->initKWalletEmu(); | 1043 | init->initKWalletEmu(); |
1044 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1044 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1045 | #endif // CONFIG_KWALLETIF | 1045 | #endif // CONFIG_KWALLETIF |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | bool PwM::importFromGpasman() | 1048 | bool PwM::importFromGpasman() |
1049 | { | 1049 | { |
1050 | if (!isVirgin()) { | 1050 | if (!isVirgin()) { |
1051 | if (KMessageBox::questionYesNo(this, | 1051 | if (KMessageBox::questionYesNo(this, |
1052 | i18n("Do you want to import the data " | 1052 | i18n("Do you want to import the data\n" |
1053 | "into the current document? (If you " | 1053 | "into the current document? (If you\n" |
1054 | "select \"no\", a new document will be " | 1054 | "select \"no\", a new document will be\n" |
1055 | "opened.)"), | 1055 | "opened.)"), |
1056 | i18n("import into this document?")) | 1056 | i18n("import into this document?")) |
1057 | == KMessageBox::No) { | 1057 | == KMessageBox::No) { |
1058 | // import the data to a new window. | 1058 | // import the data to a new window. |
1059 | PwM *newInstance = init->createMainWnd(); | 1059 | PwM *newInstance = init->createMainWnd(); |
1060 | bool ok = newInstance->importFromGpasman(); | 1060 | bool ok = newInstance->importFromGpasman(); |
1061 | if (!ok) { | 1061 | if (!ok) { |
1062 | newInstance->setForceQuit(true); | 1062 | newInstance->setForceQuit(true); |
1063 | delete_and_null(newInstance); | 1063 | delete_and_null(newInstance); |
1064 | } | 1064 | } |
1065 | return ok; | 1065 | return ok; |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1069 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1070 | PwMerror ret; | 1070 | PwMerror ret; |
1071 | QString path(KFileDialog::getOpenFileName(QString::null, | 1071 | QString path(KFileDialog::getOpenFileName(QString::null, |
1072 | i18n("*|Gpasman or Kpasman file"), this)); | 1072 | i18n("*|Gpasman or Kpasman file"), this)); |
1073 | if (path == "") | 1073 | if (path == "") |
1074 | goto cancelImport; | 1074 | goto cancelImport; |
1075 | ret = curDoc()->importFromGpasman(&path); | 1075 | ret = curDoc()->importFromGpasman(&path); |
1076 | if (ret == e_wrongPw) { | 1076 | if (ret == e_wrongPw) { |
1077 | if (KMessageBox::questionYesNo(this, | 1077 | if (KMessageBox::questionYesNo(this, |
1078 | i18n | 1078 | i18n |
1079 | ("This is probably the wrong master-password" | 1079 | ("This is probably the wrong master-password\n" |
1080 | "you have typed in.\n" | 1080 | "you have typed in.\n" |
1081 | "There is no real way to determine the " | 1081 | "There is no real way to determine the\n" |
1082 | "correctness of the password in the Gpasman " | 1082 | "correctness of the password in the Gpasman\n" |
1083 | "file-format. But I think this " | 1083 | "file-format. But I think this\n" |
1084 | "password ist wrong.\n" | 1084 | "password ist wrong.\n" |
1085 | "Do you want to continue nevertheless?"), | 1085 | "Do you want to continue nevertheless?"), |
1086 | i18n("password error")) | 1086 | i18n("password error")) |
1087 | == KMessageBox::No) { | 1087 | == KMessageBox::No) { |
1088 | goto cancelImport; | 1088 | goto cancelImport; |
1089 | } | 1089 | } |
1090 | } else if (ret != e_success) { | 1090 | } else if (ret != e_success) { |
1091 | KMessageBox::error(this, | 1091 | KMessageBox::error(this, |
1092 | i18n("Could not import file!\n" | 1092 | i18n("Could not import file!\n" |
1093 | "Do you have permission to read this file?"), | 1093 | "Do you have permission to read this file?"), |
1094 | i18n("import failed")); | 1094 | i18n("import failed")); |
1095 | goto cancelImport; | 1095 | goto cancelImport; |
1096 | } | 1096 | } |
1097 | setVirgin(false); | 1097 | setVirgin(false); |
1098 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1098 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1099 | return true; | 1099 | return true; |
1100 | 1100 | ||
1101 | cancelImport: | 1101 | cancelImport: |
1102 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1102 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1103 | return false; | 1103 | return false; |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | #ifdef CONFIG_KWALLETIF | 1106 | #ifdef CONFIG_KWALLETIF |
1107 | bool PwM::checkAndAskForKWalletEmu() | 1107 | bool PwM::checkAndAskForKWalletEmu() |
1108 | { | 1108 | { |
1109 | if (init->kwalletEmu()) { | 1109 | if (init->kwalletEmu()) { |
1110 | /* KWallet emulation is enabled. We can't import/export | 1110 | /* KWallet emulation is enabled. We can't import/export |
1111 | * data from/to it, while emulation is active. | 1111 | * data from/to it, while emulation is active. |
1112 | */ | 1112 | */ |
1113 | if (KMessageBox::questionYesNo(this, | 1113 | if (KMessageBox::questionYesNo(this, |
1114 | i18n("KWallet emulation is enabled.\n" | 1114 | i18n("KWallet emulation is enabled.\n" |
1115 | "You can't import or export data from/to " | 1115 | "You can't import or export data from/to " |
1116 | "the original KWallet, while the emulation " | 1116 | "the original KWallet, while the emulation " |
1117 | "is active.\n" | 1117 | "is active.\n" |
1118 | "Do you want to tempoarly disable the KWallet emulation?"), | 1118 | "Do you want to tempoarly disable the KWallet emulation?"), |
1119 | i18n("Tempoarly disable KWallet emulation?")) | 1119 | i18n("Tempoarly disable KWallet emulation?")) |
1120 | == KMessageBox::Yes) { | 1120 | == KMessageBox::Yes) { |
1121 | init->initKWalletEmu(true); | 1121 | init->initKWalletEmu(true); |
1122 | PWM_ASSERT(!init->kwalletEmu()); | 1122 | PWM_ASSERT(!init->kwalletEmu()); |
1123 | return true; | 1123 | return true; |
1124 | } | 1124 | } |
1125 | return false; | 1125 | return false; |
1126 | } | 1126 | } |
1127 | return true; | 1127 | return true; |
1128 | } | 1128 | } |
1129 | #endif // CONFIG_KWALLETIF | 1129 | #endif // CONFIG_KWALLETIF |
1130 | 1130 | ||
1131 | bool PwM::importKWallet() | 1131 | bool PwM::importKWallet() |
1132 | { | 1132 | { |
1133 | #ifdef CONFIG_KWALLETIF | 1133 | #ifdef CONFIG_KWALLETIF |
1134 | if (!checkAndAskForKWalletEmu()) | 1134 | if (!checkAndAskForKWalletEmu()) |
1135 | return false; | 1135 | return false; |
1136 | KWalletIf walletIf(this); | 1136 | KWalletIf walletIf(this); |
1137 | if (!isVirgin()) { | 1137 | if (!isVirgin()) { |
1138 | if (KMessageBox::questionYesNo(this, | 1138 | if (KMessageBox::questionYesNo(this, |
1139 | i18n("Do you want to import the data " | 1139 | i18n("Do you want to import the data " |
1140 | "into the current document? (If you " | 1140 | "into the current document? (If you " |
1141 | "select \"no\", a new document will be " | 1141 | "select \"no\", a new document will be " |
1142 | "opened.)"), | 1142 | "opened.)"), |
1143 | i18n("import into this document?")) | 1143 | i18n("import into this document?")) |
1144 | == KMessageBox::No) { | 1144 | == KMessageBox::No) { |
1145 | // import the data to a new window. | 1145 | // import the data to a new window. |
1146 | PwM *newInstance = init->createMainWnd(); | 1146 | PwM *newInstance = init->createMainWnd(); |
1147 | bool ok = newInstance->importKWallet(); | 1147 | bool ok = newInstance->importKWallet(); |
1148 | if (!ok) { | 1148 | if (!ok) { |
1149 | newInstance->setForceQuit(true); | 1149 | newInstance->setForceQuit(true); |
1150 | delete_and_null(newInstance); | 1150 | delete_and_null(newInstance); |
1151 | goto exit_fail; | 1151 | goto exit_fail; |
1152 | } else { | 1152 | } else { |
1153 | goto exit_ok; | 1153 | goto exit_ok; |
1154 | } | 1154 | } |
1155 | } | 1155 | } |
1156 | } | 1156 | } |
1157 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1157 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1158 | if (!walletIf.kwalletImport(curDoc())) { | 1158 | if (!walletIf.kwalletImport(curDoc())) { |
1159 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1159 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1160 | showStatMsg(i18n("KWallet import failed")); | 1160 | showStatMsg(i18n("KWallet import failed")); |
1161 | goto exit_fail; | 1161 | goto exit_fail; |
1162 | } | 1162 | } |
1163 | KMessageBox::information(this, | 1163 | KMessageBox::information(this, |
1164 | i18n("Successfully imported the KWallet data " | 1164 | i18n("Successfully imported the KWallet data " |
1165 | "into the current document."), | 1165 | "into the current document."), |
1166 | i18n("successfully imported")); | 1166 | i18n("successfully imported")); |
1167 | showStatMsg(i18n("successfully imported")); | 1167 | showStatMsg(i18n("successfully imported")); |
1168 | setVirgin(false); | 1168 | setVirgin(false); |
1169 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1169 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1170 | 1170 | ||
1171 | exit_ok: | 1171 | exit_ok: |
1172 | init->initKWalletEmu(); | 1172 | init->initKWalletEmu(); |
1173 | return true; | 1173 | return true; |
1174 | 1174 | ||
1175 | exit_fail: | 1175 | exit_fail: |
1176 | init->initKWalletEmu(); | 1176 | init->initKWalletEmu(); |
1177 | #endif // CONFIG_KWALLETIF | 1177 | #endif // CONFIG_KWALLETIF |
1178 | return false; | 1178 | return false; |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | void PwM::print_slot() | 1181 | void PwM::print_slot() |
1182 | { | 1182 | { |
1183 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1183 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1184 | #ifndef PWM_EMBEDDED | 1184 | #ifndef PWM_EMBEDDED |
1185 | PwMPrint p(curDoc(), this); | 1185 | PwMPrint p(curDoc(), this); |
1186 | p.printNow(); | 1186 | p.printNow(); |
1187 | #else | 1187 | #else |
1188 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1188 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1189 | #endif | 1189 | #endif |
1190 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1190 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | void PwM::genNewCard_slot() | 1193 | void PwM::genNewCard_slot() |
1194 | { | 1194 | { |
1195 | #ifdef CONFIG_KEYCARD | 1195 | #ifdef CONFIG_KEYCARD |
1196 | init->keycard()->genNewCard(); | 1196 | init->keycard()->genNewCard(); |
1197 | #endif | 1197 | #endif |
1198 | } | 1198 | } |
1199 | 1199 | ||
1200 | void PwM::eraseCard_slot() | 1200 | void PwM::eraseCard_slot() |
1201 | { | 1201 | { |
1202 | #ifdef CONFIG_KEYCARD | 1202 | #ifdef CONFIG_KEYCARD |
1203 | init->keycard()->eraseCard(); | 1203 | init->keycard()->eraseCard(); |
1204 | #endif | 1204 | #endif |
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | void PwM::readCardId_slot() | 1207 | void PwM::readCardId_slot() |
1208 | { | 1208 | { |
1209 | #ifdef CONFIG_KEYCARD | 1209 | #ifdef CONFIG_KEYCARD |
1210 | init->keycard()->displayKey(); | 1210 | init->keycard()->displayKey(); |
1211 | #endif | 1211 | #endif |
1212 | } | 1212 | } |
1213 | 1213 | ||
1214 | void PwM::makeCardBackup_slot() | 1214 | void PwM::makeCardBackup_slot() |
1215 | { | 1215 | { |
1216 | #ifdef CONFIG_KEYCARD | 1216 | #ifdef CONFIG_KEYCARD |
1217 | init->keycard()->makeBackupImage(); | 1217 | init->keycard()->makeBackupImage(); |
1218 | #endif | 1218 | #endif |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | void PwM::replayCardBackup_slot() | 1221 | void PwM::replayCardBackup_slot() |
1222 | { | 1222 | { |
1223 | #ifdef CONFIG_KEYCARD | 1223 | #ifdef CONFIG_KEYCARD |
1224 | init->keycard()->replayBackupImage(); | 1224 | init->keycard()->replayBackupImage(); |
1225 | #endif | 1225 | #endif |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | void PwM::execLauncher_slot() | 1228 | void PwM::execLauncher_slot() |
1229 | { | 1229 | { |
1230 | PWM_ASSERT(curDoc()); | 1230 | PWM_ASSERT(curDoc()); |
1231 | if (curDoc()->isDeepLocked()) | 1231 | if (curDoc()->isDeepLocked()) |
1232 | return; | 1232 | return; |
1233 | unsigned int curEntryIndex; | 1233 | unsigned int curEntryIndex; |
1234 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1234 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1235 | return; | 1235 | return; |
1236 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1236 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1237 | curEntryIndex); | 1237 | curEntryIndex); |
1238 | if (ret) | 1238 | if (ret) |
1239 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1239 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1240 | else | 1240 | else |
1241 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1241 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | void PwM::goToURL_slot() | 1244 | void PwM::goToURL_slot() |
1245 | { | 1245 | { |
1246 | PWM_ASSERT(curDoc()); | 1246 | PWM_ASSERT(curDoc()); |
1247 | if (curDoc()->isDeepLocked()) | 1247 | if (curDoc()->isDeepLocked()) |
1248 | return; | 1248 | return; |
1249 | unsigned int curEntryIndex; | 1249 | unsigned int curEntryIndex; |
1250 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1250 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1251 | return; | 1251 | return; |
1252 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1252 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1253 | curEntryIndex); | 1253 | curEntryIndex); |
1254 | if (ret) | 1254 | if (ret) |
1255 | showStatMsg(i18n("started browser with current URL.")); | 1255 | showStatMsg(i18n("started browser with current URL.")); |
1256 | else | 1256 | else |
1257 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1257 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | void PwM::copyToClipboard(const QString &s) | 1260 | void PwM::copyToClipboard(const QString &s) |
1261 | { | 1261 | { |
1262 | QClipboard *cb = QApplication::clipboard(); | 1262 | QClipboard *cb = QApplication::clipboard(); |
1263 | #ifndef PWM_EMBEDDED | 1263 | #ifndef PWM_EMBEDDED |
1264 | if (cb->supportsSelection()) | 1264 | if (cb->supportsSelection()) |
1265 | cb->setText(s, QClipboard::Selection); | 1265 | cb->setText(s, QClipboard::Selection); |
1266 | cb->setText(s, QClipboard::Clipboard); | 1266 | cb->setText(s, QClipboard::Clipboard); |
1267 | #else | 1267 | #else |
1268 | cb->setText(s); | 1268 | cb->setText(s); |
1269 | 1269 | ||
1270 | #endif | 1270 | #endif |
1271 | 1271 | ||
1272 | } | 1272 | } |
1273 | 1273 | ||
1274 | void PwM::showStatMsg(const QString &msg) | 1274 | void PwM::showStatMsg(const QString &msg) |
1275 | { | 1275 | { |
1276 | #ifndef PWM_EMBEDDED | 1276 | #ifndef PWM_EMBEDDED |
1277 | KStatusBar *statBar = statusBar(); | 1277 | KStatusBar *statBar = statusBar(); |
1278 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1278 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1279 | #else | 1279 | #else |
1280 | qDebug("Statusbar : %s",msg.latin1()); | 1280 | qDebug("Statusbar : %s",msg.latin1()); |
1281 | #endif | 1281 | #endif |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | void PwM::focusInEvent(QFocusEvent *e) | 1284 | void PwM::focusInEvent(QFocusEvent *e) |
1285 | { | 1285 | { |
1286 | if (e->gotFocus()) { | 1286 | if (e->gotFocus()) { |
1287 | emit gotFocus(this); | 1287 | emit gotFocus(this); |
1288 | } else if (e->lostFocus()) { | 1288 | } else if (e->lostFocus()) { |
1289 | emit lostFocus(this); | 1289 | emit lostFocus(this); |
1290 | } | 1290 | } |
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | 1293 | ||
1294 | #ifdef PWM_EMBEDDED | 1294 | #ifdef PWM_EMBEDDED |
1295 | 1295 | ||
1296 | void PwM::whatsnew_slot() | 1296 | void PwM::whatsnew_slot() |
1297 | { | 1297 | { |
1298 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 1298 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | void PwM::showLicense_slot() | 1301 | void PwM::showLicense_slot() |
1302 | { | 1302 | { |
1303 | KApplication::showLicence(); | 1303 | KApplication::showLicence(); |
1304 | } | 1304 | } |
1305 | 1305 | ||
1306 | void PwM::faq_slot() | 1306 | void PwM::faq_slot() |
1307 | { | 1307 | { |
1308 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1308 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1309 | } | 1309 | } |
1310 | 1310 | ||
1311 | void PwM::syncHowTo_slot() | 1311 | void PwM::syncHowTo_slot() |
1312 | { | 1312 | { |
1313 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 1313 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
1314 | } | 1314 | } |
1315 | 1315 | ||
1316 | 1316 | ||
1317 | void PwM::createAboutData_slot() | 1317 | void PwM::createAboutData_slot() |
1318 | { | 1318 | { |
1319 | QString version; | 1319 | QString version; |
1320 | #include <../version> | 1320 | #include <../version> |
1321 | QMessageBox::about( this, "About PwManager/Pi", | 1321 | QMessageBox::about( this, "About PwManager/Pi", |
1322 | "PwManager/Platform-independent\n" | 1322 | "PwManager/Platform-independent\n" |
1323 | "(PWM/Pi) " +version + " - " + | 1323 | "(PWM/Pi) " +version + " - " + |
1324 | #ifdef DESKTOP_VERSION | 1324 | #ifdef DESKTOP_VERSION |
1325 | "Desktop Edition\n" | 1325 | "Desktop Edition\n" |
1326 | #else | 1326 | #else |
1327 | "PDA-Edition\n" | 1327 | "PDA-Edition\n" |
1328 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1328 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1329 | #endif | 1329 | #endif |
1330 | 1330 | ||
1331 | "(c) 2004 Ulf Schenk\n" | 1331 | "(c) 2004 Ulf Schenk\n" |
1332 | "(c) 2004 Lutz Rogowski\n" | 1332 | "(c) 2004 Lutz Rogowski\n" |
1333 | "(c) 1997-2004, The KDE PIM Team\n" | 1333 | "(c) 1997-2004, The KDE PIM Team\n" |
1334 | 1334 | ||
1335 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1335 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1336 | "Matt Scifo - mscifo@o1.com\n" | 1336 | "Matt Scifo - mscifo@o1.com\n" |
1337 | "Elias Probst - elias.probst@gmx.de\n" | 1337 | "Elias Probst - elias.probst@gmx.de\n" |
1338 | "George Staikos - staikos@kde.org\n" | 1338 | "George Staikos - staikos@kde.org\n" |
1339 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1339 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1340 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1340 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1341 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1341 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1342 | "Troy Engel - tengel@sonic.net\n" | 1342 | "Troy Engel - tengel@sonic.net\n" |
1343 | "Wickey - wickey@gmx.at\n" | 1343 | "Wickey - wickey@gmx.at\n" |
1344 | "Ian MacGregor - original documentation author.\n" | 1344 | "Ian MacGregor - original documentation author.\n" |
1345 | ); | 1345 | ); |
1346 | } | 1346 | } |
1347 | 1347 | ||
1348 | 1348 | ||
1349 | //this are the overwritten callbackmethods from the syncinterface | 1349 | //this are the overwritten callbackmethods from the syncinterface |
1350 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1350 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1351 | { | 1351 | { |
1352 | PWM_ASSERT(curDoc()); | 1352 | PWM_ASSERT(curDoc()); |
1353 | 1353 | ||
1354 | bool ret = curDoc()->sync(manager, filename, mode); | 1354 | bool ret = curDoc()->sync(manager, filename, mode); |
1355 | 1355 | ||
1356 | qDebug("PwM::sync save now: ret=%i", ret); | 1356 | qDebug("PwM::sync save now: ret=%i", ret); |
1357 | 1357 | ||
1358 | if (ret == true) { | 1358 | if (ret == true) { |
1359 | //US BUG: what can we call here to update the view of the current doc? | 1359 | //US BUG: what can we call here to update the view of the current doc? |
1360 | //mViewManager->refreshView(); | 1360 | //mViewManager->refreshView(); |
1361 | 1361 | ||
1362 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | 1362 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. |
1363 | save(); | 1363 | save(); |
1364 | } | 1364 | } |
1365 | 1365 | ||
1366 | return ret; | 1366 | return ret; |
1367 | } | 1367 | } |
1368 | #endif | 1368 | #endif |
1369 | 1369 | ||
1370 | 1370 | ||
1371 | #ifndef PWM_EMBEDDED | 1371 | #ifndef PWM_EMBEDDED |
1372 | #include "pwm.moc" | 1372 | #include "pwm.moc" |
1373 | #endif | 1373 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 8869f3a..86b6273 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -499,1561 +499,1567 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) | |||
499 | goto out_moveback; | 499 | goto out_moveback; |
500 | } else if (e != e_success) { | 500 | } else if (e != e_success) { |
501 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 501 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
502 | f.close(); | 502 | f.close(); |
503 | ret = e_enc; | 503 | ret = e_enc; |
504 | goto out_moveback; | 504 | goto out_moveback; |
505 | } | 505 | } |
506 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 506 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
507 | f.close(); | 507 | f.close(); |
508 | if (chmod(filename.latin1(), | 508 | if (chmod(filename.latin1(), |
509 | conf()->confGlobFilePermissions())) { | 509 | conf()->confGlobFilePermissions())) { |
510 | printWarn(string("chmod failed: ") + strerror(errno)); | 510 | printWarn(string("chmod failed: ") + strerror(errno)); |
511 | } | 511 | } |
512 | openDocList.edit(this, getTitle().latin1()); | 512 | openDocList.edit(this, getTitle().latin1()); |
513 | if (wasDeepLocked) { | 513 | if (wasDeepLocked) { |
514 | /* Do _not_ save the data with the deepLock() | 514 | /* Do _not_ save the data with the deepLock() |
515 | * call, because this will recurse | 515 | * call, because this will recurse |
516 | * into saveDoc() | 516 | * into saveDoc() |
517 | */ | 517 | */ |
518 | deepLock(true, false); | 518 | deepLock(true, false); |
519 | /* We don't check return value here, because | 519 | /* We don't check return value here, because |
520 | * it won't fail. See NOTE in deepLock() | 520 | * it won't fail. See NOTE in deepLock() |
521 | */ | 521 | */ |
522 | } | 522 | } |
523 | if (tmpFileMoved != QString::null) { | 523 | if (tmpFileMoved != QString::null) { |
524 | // now remove the moved file. | 524 | // now remove the moved file. |
525 | if (!QFile::remove(tmpFileMoved)) { | 525 | if (!QFile::remove(tmpFileMoved)) { |
526 | printWarn(string("removing file ") | 526 | printWarn(string("removing file ") |
527 | + tmpFileMoved.latin1() | 527 | + tmpFileMoved.latin1() |
528 | + " failed!"); | 528 | + " failed!"); |
529 | } | 529 | } |
530 | } | 530 | } |
531 | ret = e_success; | 531 | ret = e_success; |
532 | printDebug(string("writing file { name: ") | 532 | printDebug(string("writing file { name: ") |
533 | + filename.latin1() + " compress: " | 533 | + filename.latin1() + " compress: " |
534 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 534 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
535 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 535 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
536 | + tostr(static_cast<int>(hashAlgo)) | 536 | + tostr(static_cast<int>(hashAlgo)) |
537 | + " }"); | 537 | + " }"); |
538 | goto out; | 538 | goto out; |
539 | out_moveback: | 539 | out_moveback: |
540 | if (tmpFileMoved != QString::null) { | 540 | if (tmpFileMoved != QString::null) { |
541 | if (copyFile(tmpFileMoved, filename)) { | 541 | if (copyFile(tmpFileMoved, filename)) { |
542 | if (!QFile::remove(tmpFileMoved)) { | 542 | if (!QFile::remove(tmpFileMoved)) { |
543 | printWarn(string("removing tmp file ") | 543 | printWarn(string("removing tmp file ") |
544 | + filename.latin1() | 544 | + filename.latin1() |
545 | + " failed!"); | 545 | + " failed!"); |
546 | } | 546 | } |
547 | } else { | 547 | } else { |
548 | printWarn(string("couldn't copy file ") | 548 | printWarn(string("couldn't copy file ") |
549 | + tmpFileMoved.latin1() | 549 | + tmpFileMoved.latin1() |
550 | + " back to " | 550 | + " back to " |
551 | + filename.latin1()); | 551 | + filename.latin1()); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | out: | 554 | out: |
555 | return ret; | 555 | return ret; |
556 | } | 556 | } |
557 | 557 | ||
558 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 558 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
559 | { | 559 | { |
560 | PWM_ASSERT(file); | 560 | PWM_ASSERT(file); |
561 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 561 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
562 | string decrypted, dataHash; | 562 | string decrypted, dataHash; |
563 | PwMerror ret; | 563 | PwMerror ret; |
564 | char cryptAlgo, dataHashType, compress; | 564 | char cryptAlgo, dataHashType, compress; |
565 | unsigned int headerLen; | 565 | unsigned int headerLen; |
566 | 566 | ||
567 | if (*file == "") | 567 | if (*file == "") |
568 | return e_readFile; | 568 | return e_readFile; |
569 | filename = *file; | 569 | filename = *file; |
570 | /* check if this file is already open. | 570 | /* check if this file is already open. |
571 | * This does not catch symlinks! | 571 | * This does not catch symlinks! |
572 | */ | 572 | */ |
573 | if (!isDeepLocked()) { | 573 | if (!isDeepLocked()) { |
574 | if (getOpenDocList()->find(filename.latin1())) | 574 | if (getOpenDocList()->find(filename.latin1())) |
575 | return e_alreadyOpen; | 575 | return e_alreadyOpen; |
576 | } | 576 | } |
577 | QFile f(filename); | 577 | QFile f(filename); |
578 | 578 | ||
579 | if (openLocked == 2) { | 579 | if (openLocked == 2) { |
580 | // open deep-locked | 580 | // open deep-locked |
581 | if (!QFile::exists(filename)) | 581 | if (!QFile::exists(filename)) |
582 | return e_openFile; | 582 | return e_openFile; |
583 | if (deepLock(true, false) != e_success) | 583 | if (deepLock(true, false) != e_success) |
584 | return e_openFile; | 584 | return e_openFile; |
585 | goto out_success; | 585 | goto out_success; |
586 | } | 586 | } |
587 | 587 | ||
588 | if (!f.open(IO_ReadOnly)) | 588 | if (!f.open(IO_ReadOnly)) |
589 | return e_openFile; | 589 | return e_openFile; |
590 | 590 | ||
591 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 591 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
592 | &dataHashType, &dataHash, &f); | 592 | &dataHashType, &dataHash, &f); |
593 | if (ret != e_success) { | 593 | if (ret != e_success) { |
594 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 594 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
595 | f.close(); | 595 | f.close(); |
596 | if (ret == e_wrongPw) { | 596 | if (ret == e_wrongPw) { |
597 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 597 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
598 | return ret; | 598 | return ret; |
599 | } else if (ret == e_noPw || | 599 | } else if (ret == e_noPw || |
600 | ret == e_fileVer || | 600 | ret == e_fileVer || |
601 | ret == e_fileFormat || | 601 | ret == e_fileFormat || |
602 | ret == e_hashNotImpl) { | 602 | ret == e_hashNotImpl) { |
603 | return ret; | 603 | return ret; |
604 | } else | 604 | } else |
605 | return e_readFile; | 605 | return e_readFile; |
606 | } | 606 | } |
607 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 607 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
608 | if (ret == e_cryptNotImpl) { | 608 | if (ret == e_cryptNotImpl) { |
609 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 609 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
610 | f.close(); | 610 | f.close(); |
611 | return e_cryptNotImpl; | 611 | return e_cryptNotImpl; |
612 | } else if (ret != e_success) { | 612 | } else if (ret != e_success) { |
613 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 613 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
614 | f.close(); | 614 | f.close(); |
615 | return e_readFile; | 615 | return e_readFile; |
616 | } | 616 | } |
617 | if (!decompressDta(&decrypted, compress)) { | 617 | if (!decompressDta(&decrypted, compress)) { |
618 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 618 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
619 | f.close(); | 619 | f.close(); |
620 | return e_fileCorrupt; | 620 | return e_fileCorrupt; |
621 | } | 621 | } |
622 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 622 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
623 | if (ret == e_hashNotImpl) { | 623 | if (ret == e_hashNotImpl) { |
624 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 624 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
625 | f.close(); | 625 | f.close(); |
626 | return e_hashNotImpl; | 626 | return e_hashNotImpl; |
627 | } else if (ret != e_success) { | 627 | } else if (ret != e_success) { |
628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 628 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
629 | f.close(); | 629 | f.close(); |
630 | return e_fileCorrupt; | 630 | return e_fileCorrupt; |
631 | } | 631 | } |
632 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 632 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
633 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 633 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
634 | f.close(); | 634 | f.close(); |
635 | return e_readFile; | 635 | return e_readFile; |
636 | } | 636 | } |
637 | f.close(); | 637 | f.close(); |
638 | timer()->start(DocTimer::id_mpwTimer); | 638 | timer()->start(DocTimer::id_mpwTimer); |
639 | timer()->start(DocTimer::id_autoLockTimer); | 639 | timer()->start(DocTimer::id_autoLockTimer); |
640 | out_success: | 640 | out_success: |
641 | openDocList.edit(this, getTitle().latin1()); | 641 | openDocList.edit(this, getTitle().latin1()); |
642 | emit docOpened(this); | 642 | emit docOpened(this); |
643 | return e_success; | 643 | return e_success; |
644 | } | 644 | } |
645 | 645 | ||
646 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 646 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
647 | QString *pw, QFile *f) | 647 | QString *pw, QFile *f) |
648 | { | 648 | { |
649 | PWM_ASSERT(pw); | 649 | PWM_ASSERT(pw); |
650 | PWM_ASSERT(f); | 650 | PWM_ASSERT(f); |
651 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else | 651 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
652 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | 652 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion |
653 | //USPWM_ASSERT(listView); | 653 | //USPWM_ASSERT(listView); |
654 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 654 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
655 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 655 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
656 | return e_writeFile; | 656 | return e_writeFile; |
657 | } | 657 | } |
658 | if (f->putch(PWM_FILE_VER) == -1 || | 658 | if (f->putch(PWM_FILE_VER) == -1 || |
659 | f->putch(keyHash) == -1 || | 659 | f->putch(keyHash) == -1 || |
660 | f->putch(dataHash) == -1 || | 660 | f->putch(dataHash) == -1 || |
661 | f->putch(crypt) == -1 || | 661 | f->putch(crypt) == -1 || |
662 | f->putch(compress) == -1 || | 662 | f->putch(compress) == -1 || |
663 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 663 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
664 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 664 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
665 | return e_writeFile; | 665 | return e_writeFile; |
666 | } | 666 | } |
667 | 667 | ||
668 | // write bytes of NUL-data. These bytes are reserved for future-use. | 668 | // write bytes of NUL-data. These bytes are reserved for future-use. |
669 | const int bufSize = 64; | 669 | const int bufSize = 64; |
670 | char tmp_buf[bufSize]; | 670 | char tmp_buf[bufSize]; |
671 | memset(tmp_buf, 0x00, bufSize); | 671 | memset(tmp_buf, 0x00, bufSize); |
672 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 672 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
673 | return e_writeFile; | 673 | return e_writeFile; |
674 | 674 | ||
675 | switch (keyHash) { | 675 | switch (keyHash) { |
676 | case PWM_HASH_SHA1: { | 676 | case PWM_HASH_SHA1: { |
677 | const int hashlen = SHA1_HASH_LEN_BYTE; | 677 | const int hashlen = SHA1_HASH_LEN_BYTE; |
678 | Sha1 hash; | 678 | Sha1 hash; |
679 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 679 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
680 | string ret = hash.sha1_read(); | 680 | string ret = hash.sha1_read(); |
681 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 681 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
682 | return e_writeFile; | 682 | return e_writeFile; |
683 | break; | 683 | break; |
684 | } | 684 | } |
685 | case PWM_HASH_SHA256: | 685 | case PWM_HASH_SHA256: |
686 | /*... fall through */ | 686 | /*... fall through */ |
687 | case PWM_HASH_SHA384: | 687 | case PWM_HASH_SHA384: |
688 | case PWM_HASH_SHA512: | 688 | case PWM_HASH_SHA512: |
689 | case PWM_HASH_MD5: | 689 | case PWM_HASH_MD5: |
690 | case PWM_HASH_RMD160: | 690 | case PWM_HASH_RMD160: |
691 | case PWM_HASH_TIGER: | 691 | case PWM_HASH_TIGER: |
692 | { | 692 | { |
693 | if (!LibGCryptIf::available()) | 693 | if (!LibGCryptIf::available()) |
694 | return e_hashNotImpl; | 694 | return e_hashNotImpl; |
695 | LibGCryptIf gc; | 695 | LibGCryptIf gc; |
696 | PwMerror err; | 696 | PwMerror err; |
697 | unsigned char *buf; | 697 | unsigned char *buf; |
698 | size_t hashLen; | 698 | size_t hashLen; |
699 | err = gc.hash(&buf, | 699 | err = gc.hash(&buf, |
700 | &hashLen, | 700 | &hashLen, |
701 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 701 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
702 | pw->length(), | 702 | pw->length(), |
703 | keyHash); | 703 | keyHash); |
704 | if (err != e_success) | 704 | if (err != e_success) |
705 | return e_hashNotImpl; | 705 | return e_hashNotImpl; |
706 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 706 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
707 | != static_cast<Q_LONG>(hashLen)) { | 707 | != static_cast<Q_LONG>(hashLen)) { |
708 | delete [] buf; | 708 | delete [] buf; |
709 | return e_hashNotImpl; | 709 | return e_hashNotImpl; |
710 | } | 710 | } |
711 | delete [] buf; | 711 | delete [] buf; |
712 | break; | 712 | break; |
713 | } | 713 | } |
714 | default: { | 714 | default: { |
715 | return e_hashNotImpl; | 715 | return e_hashNotImpl; |
716 | } } | 716 | } } |
717 | return e_success; | 717 | return e_success; |
718 | } | 718 | } |
719 | 719 | ||
720 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 720 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
721 | unsigned int *headerLength, char *dataHashType, | 721 | unsigned int *headerLength, char *dataHashType, |
722 | string *dataHash, QFile *f) | 722 | string *dataHash, QFile *f) |
723 | { | 723 | { |
724 | PWM_ASSERT(cryptAlgo); | 724 | PWM_ASSERT(cryptAlgo); |
725 | PWM_ASSERT(pw); | 725 | PWM_ASSERT(pw); |
726 | PWM_ASSERT(headerLength); | 726 | PWM_ASSERT(headerLength); |
727 | PWM_ASSERT(dataHashType); | 727 | PWM_ASSERT(dataHashType); |
728 | PWM_ASSERT(dataHash); | 728 | PWM_ASSERT(dataHash); |
729 | PWM_ASSERT(f); | 729 | PWM_ASSERT(f); |
730 | int tmpRet; | 730 | int tmpRet; |
731 | // check "magic" header | 731 | // check "magic" header |
732 | const char magicHdr[] = FILE_ID_HEADER; | 732 | const char magicHdr[] = FILE_ID_HEADER; |
733 | const int hdrLen = array_size(magicHdr) - 1; | 733 | const int hdrLen = array_size(magicHdr) - 1; |
734 | char tmp[hdrLen]; | 734 | char tmp[hdrLen]; |
735 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 735 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
736 | return e_readFile; | 736 | return e_readFile; |
737 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 737 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
738 | return e_fileFormat; | 738 | return e_fileFormat; |
739 | // read and check file ver | 739 | // read and check file ver |
740 | int fileV = f->getch(); | 740 | int fileV = f->getch(); |
741 | if (fileV == -1) | 741 | if (fileV == -1) |
742 | return e_fileFormat; | 742 | return e_fileFormat; |
743 | if (fileV != PWM_FILE_VER) | 743 | if (fileV != PWM_FILE_VER) |
744 | return e_fileVer; | 744 | return e_fileVer; |
745 | // read hash hash type | 745 | // read hash hash type |
746 | int keyHash = f->getch(); | 746 | int keyHash = f->getch(); |
747 | if (keyHash == -1) | 747 | if (keyHash == -1) |
748 | return e_fileFormat; | 748 | return e_fileFormat; |
749 | // read data hash type | 749 | // read data hash type |
750 | tmpRet = f->getch(); | 750 | tmpRet = f->getch(); |
751 | if (tmpRet == -1) | 751 | if (tmpRet == -1) |
752 | return e_fileFormat; | 752 | return e_fileFormat; |
753 | *dataHashType = tmpRet; | 753 | *dataHashType = tmpRet; |
754 | // read crypt algo | 754 | // read crypt algo |
755 | tmpRet = f->getch(); | 755 | tmpRet = f->getch(); |
756 | if (tmpRet == -1) | 756 | if (tmpRet == -1) |
757 | return e_fileFormat; | 757 | return e_fileFormat; |
758 | *cryptAlgo = tmpRet; | 758 | *cryptAlgo = tmpRet; |
759 | // get compression-algo | 759 | // get compression-algo |
760 | tmpRet = f->getch(); | 760 | tmpRet = f->getch(); |
761 | if (tmpRet == -1) | 761 | if (tmpRet == -1) |
762 | return e_fileFormat; | 762 | return e_fileFormat; |
763 | *compress = tmpRet; | 763 | *compress = tmpRet; |
764 | // get the MPW-flag | 764 | // get the MPW-flag |
765 | int mpw_flag = f->getch(); | 765 | int mpw_flag = f->getch(); |
766 | if (mpw_flag == -1) | 766 | if (mpw_flag == -1) |
767 | return e_fileFormat; | 767 | return e_fileFormat; |
768 | if (mpw_flag == 0x01) | 768 | if (mpw_flag == 0x01) |
769 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 769 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
770 | else | 770 | else |
771 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 771 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
772 | // skip the "RESERVED"-bytes | 772 | // skip the "RESERVED"-bytes |
773 | if (!(f->at(f->at() + 64))) | 773 | if (!(f->at(f->at() + 64))) |
774 | return e_fileFormat; | 774 | return e_fileFormat; |
775 | 775 | ||
776 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 776 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
777 | if (*pw == "") { | 777 | if (*pw == "") { |
778 | /* the user didn't give a master-password | 778 | /* the user didn't give a master-password |
779 | * or didn't insert a chipcard | 779 | * or didn't insert a chipcard |
780 | */ | 780 | */ |
781 | return e_noPw; | 781 | return e_noPw; |
782 | } | 782 | } |
783 | // verify key-hash | 783 | // verify key-hash |
784 | switch (keyHash) { | 784 | switch (keyHash) { |
785 | case PWM_HASH_SHA1: { | 785 | case PWM_HASH_SHA1: { |
786 | // read hash from header | 786 | // read hash from header |
787 | const int hashLen = SHA1_HASH_LEN_BYTE; | 787 | const int hashLen = SHA1_HASH_LEN_BYTE; |
788 | string readHash; | 788 | string readHash; |
789 | int i; | 789 | int i; |
790 | for (i = 0; i < hashLen; ++i) | 790 | for (i = 0; i < hashLen; ++i) |
791 | readHash.push_back(f->getch()); | 791 | readHash.push_back(f->getch()); |
792 | Sha1 hash; | 792 | Sha1 hash; |
793 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 793 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
794 | string ret = hash.sha1_read(); | 794 | string ret = hash.sha1_read(); |
795 | if (ret != readHash) | 795 | if (ret != readHash) |
796 | return e_wrongPw;// hash doesn't match (wrong key) | 796 | return e_wrongPw;// hash doesn't match (wrong key) |
797 | break; | 797 | break; |
798 | } | 798 | } |
799 | case PWM_HASH_SHA256: | 799 | case PWM_HASH_SHA256: |
800 | /*... fall through */ | 800 | /*... fall through */ |
801 | case PWM_HASH_SHA384: | 801 | case PWM_HASH_SHA384: |
802 | case PWM_HASH_SHA512: | 802 | case PWM_HASH_SHA512: |
803 | case PWM_HASH_MD5: | 803 | case PWM_HASH_MD5: |
804 | case PWM_HASH_RMD160: | 804 | case PWM_HASH_RMD160: |
805 | case PWM_HASH_TIGER: { | 805 | case PWM_HASH_TIGER: { |
806 | if (!LibGCryptIf::available()) | 806 | if (!LibGCryptIf::available()) |
807 | return e_hashNotImpl; | 807 | return e_hashNotImpl; |
808 | LibGCryptIf gc; | 808 | LibGCryptIf gc; |
809 | PwMerror err; | 809 | PwMerror err; |
810 | unsigned char *buf; | 810 | unsigned char *buf; |
811 | size_t hashLen; | 811 | size_t hashLen; |
812 | err = gc.hash(&buf, | 812 | err = gc.hash(&buf, |
813 | &hashLen, | 813 | &hashLen, |
814 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 814 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
815 | pw->length(), | 815 | pw->length(), |
816 | keyHash); | 816 | keyHash); |
817 | if (err != e_success) | 817 | if (err != e_success) |
818 | return e_hashNotImpl; | 818 | return e_hashNotImpl; |
819 | string calcHash(reinterpret_cast<const char *>(buf), | 819 | string calcHash(reinterpret_cast<const char *>(buf), |
820 | static_cast<string::size_type>(hashLen)); | 820 | static_cast<string::size_type>(hashLen)); |
821 | delete [] buf; | 821 | delete [] buf; |
822 | // read hash from header | 822 | // read hash from header |
823 | string readHash; | 823 | string readHash; |
824 | size_t i; | 824 | size_t i; |
825 | for (i = 0; i < hashLen; ++i) | 825 | for (i = 0; i < hashLen; ++i) |
826 | readHash.push_back(f->getch()); | 826 | readHash.push_back(f->getch()); |
827 | if (calcHash != readHash) | 827 | if (calcHash != readHash) |
828 | return e_wrongPw;// hash doesn't match (wrong key) | 828 | return e_wrongPw;// hash doesn't match (wrong key) |
829 | break; | 829 | break; |
830 | } | 830 | } |
831 | default: { | 831 | default: { |
832 | return e_hashNotImpl; | 832 | return e_hashNotImpl; |
833 | } } | 833 | } } |
834 | // read the data-hash from the file | 834 | // read the data-hash from the file |
835 | unsigned int hashLen, i; | 835 | unsigned int hashLen, i; |
836 | switch (*dataHashType) { | 836 | switch (*dataHashType) { |
837 | case PWM_HASH_SHA1: | 837 | case PWM_HASH_SHA1: |
838 | hashLen = SHA1_HASH_LEN_BYTE; | 838 | hashLen = SHA1_HASH_LEN_BYTE; |
839 | break; | 839 | break; |
840 | case PWM_HASH_SHA256: | 840 | case PWM_HASH_SHA256: |
841 | /*... fall through */ | 841 | /*... fall through */ |
842 | case PWM_HASH_SHA384: | 842 | case PWM_HASH_SHA384: |
843 | case PWM_HASH_SHA512: | 843 | case PWM_HASH_SHA512: |
844 | case PWM_HASH_MD5: | 844 | case PWM_HASH_MD5: |
845 | case PWM_HASH_RMD160: | 845 | case PWM_HASH_RMD160: |
846 | case PWM_HASH_TIGER: { | 846 | case PWM_HASH_TIGER: { |
847 | if (!LibGCryptIf::available()) | 847 | if (!LibGCryptIf::available()) |
848 | return e_hashNotImpl; | 848 | return e_hashNotImpl; |
849 | LibGCryptIf gc; | 849 | LibGCryptIf gc; |
850 | hashLen = gc.hashLength(*dataHashType); | 850 | hashLen = gc.hashLength(*dataHashType); |
851 | if (hashLen == 0) | 851 | if (hashLen == 0) |
852 | return e_hashNotImpl; | 852 | return e_hashNotImpl; |
853 | break; | 853 | break; |
854 | } | 854 | } |
855 | default: | 855 | default: |
856 | return e_hashNotImpl; | 856 | return e_hashNotImpl; |
857 | } | 857 | } |
858 | *dataHash = ""; | 858 | *dataHash = ""; |
859 | for (i = 0; i < hashLen; ++i) { | 859 | for (i = 0; i < hashLen; ++i) { |
860 | tmpRet = f->getch(); | 860 | tmpRet = f->getch(); |
861 | if (tmpRet == -1) | 861 | if (tmpRet == -1) |
862 | return e_fileFormat; | 862 | return e_fileFormat; |
863 | dataHash->push_back(static_cast<char>(tmpRet)); | 863 | dataHash->push_back(static_cast<char>(tmpRet)); |
864 | } | 864 | } |
865 | *headerLength = f->at(); | 865 | *headerLength = f->at(); |
866 | #ifndef PWM_EMBEDDED | 866 | #ifndef PWM_EMBEDDED |
867 | printDebug(string("opening file { compress: ") | 867 | printDebug(string("opening file { compress: ") |
868 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 868 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
869 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 869 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
870 | + tostr(static_cast<int>(keyHash)) | 870 | + tostr(static_cast<int>(keyHash)) |
871 | + " }"); | 871 | + " }"); |
872 | #else | 872 | #else |
873 | printDebug(string("opening file { compress: ") | 873 | printDebug(string("opening file { compress: ") |
874 | + tostr((int)(*compress)) + " cryptAlgo: " | 874 | + tostr((int)(*compress)) + " cryptAlgo: " |
875 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 875 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
876 | + tostr((int)(keyHash)) | 876 | + tostr((int)(keyHash)) |
877 | + " }"); | 877 | + " }"); |
878 | #endif | 878 | #endif |
879 | 879 | ||
880 | return e_success; | 880 | return e_success; |
881 | } | 881 | } |
882 | 882 | ||
883 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 883 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
884 | { | 884 | { |
885 | PWM_ASSERT(d); | 885 | PWM_ASSERT(d); |
886 | PWM_ASSERT(f); | 886 | PWM_ASSERT(f); |
887 | 887 | ||
888 | switch (dataHash) { | 888 | switch (dataHash) { |
889 | case PWM_HASH_SHA1: { | 889 | case PWM_HASH_SHA1: { |
890 | const int hashLen = SHA1_HASH_LEN_BYTE; | 890 | const int hashLen = SHA1_HASH_LEN_BYTE; |
891 | Sha1 h; | 891 | Sha1 h; |
892 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 892 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
893 | string hRet = h.sha1_read(); | 893 | string hRet = h.sha1_read(); |
894 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 894 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
895 | return e_writeFile; | 895 | return e_writeFile; |
896 | break; | 896 | break; |
897 | } | 897 | } |
898 | case PWM_HASH_SHA256: | 898 | case PWM_HASH_SHA256: |
899 | /*... fall through */ | 899 | /*... fall through */ |
900 | case PWM_HASH_SHA384: | 900 | case PWM_HASH_SHA384: |
901 | case PWM_HASH_SHA512: | 901 | case PWM_HASH_SHA512: |
902 | case PWM_HASH_MD5: | 902 | case PWM_HASH_MD5: |
903 | case PWM_HASH_RMD160: | 903 | case PWM_HASH_RMD160: |
904 | case PWM_HASH_TIGER: { | 904 | case PWM_HASH_TIGER: { |
905 | if (!LibGCryptIf::available()) | 905 | if (!LibGCryptIf::available()) |
906 | return e_hashNotImpl; | 906 | return e_hashNotImpl; |
907 | LibGCryptIf gc; | 907 | LibGCryptIf gc; |
908 | PwMerror err; | 908 | PwMerror err; |
909 | unsigned char *buf; | 909 | unsigned char *buf; |
910 | size_t hashLen; | 910 | size_t hashLen; |
911 | err = gc.hash(&buf, | 911 | err = gc.hash(&buf, |
912 | &hashLen, | 912 | &hashLen, |
913 | reinterpret_cast<const unsigned char *>(d->c_str()), | 913 | reinterpret_cast<const unsigned char *>(d->c_str()), |
914 | d->size(), | 914 | d->size(), |
915 | dataHash); | 915 | dataHash); |
916 | if (err != e_success) | 916 | if (err != e_success) |
917 | return e_hashNotImpl; | 917 | return e_hashNotImpl; |
918 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 918 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
919 | != static_cast<Q_LONG>(hashLen)) { | 919 | != static_cast<Q_LONG>(hashLen)) { |
920 | delete [] buf; | 920 | delete [] buf; |
921 | return e_hashNotImpl; | 921 | return e_hashNotImpl; |
922 | } | 922 | } |
923 | delete [] buf; | 923 | delete [] buf; |
924 | break; | 924 | break; |
925 | } | 925 | } |
926 | default: { | 926 | default: { |
927 | return e_hashNotImpl; | 927 | return e_hashNotImpl; |
928 | } } | 928 | } } |
929 | 929 | ||
930 | return e_success; | 930 | return e_success; |
931 | } | 931 | } |
932 | 932 | ||
933 | bool PwMDoc::backupFile(const QString &filePath) | 933 | bool PwMDoc::backupFile(const QString &filePath) |
934 | { | 934 | { |
935 | QFileInfo fi(filePath); | 935 | QFileInfo fi(filePath); |
936 | if (!fi.exists()) | 936 | if (!fi.exists()) |
937 | return true; // Yes, true is correct. | 937 | return true; // Yes, true is correct. |
938 | QString pathOnly(fi.dirPath(true)); | 938 | QString pathOnly(fi.dirPath(true)); |
939 | QString nameOnly(fi.fileName()); | 939 | QString nameOnly(fi.fileName()); |
940 | QString backupPath = pathOnly | 940 | QString backupPath = pathOnly |
941 | + "/~" | 941 | + "/~" |
942 | + nameOnly | 942 | + nameOnly |
943 | + ".backup"; | 943 | + ".backup"; |
944 | return copyFile(filePath, backupPath); | 944 | return copyFile(filePath, backupPath); |
945 | } | 945 | } |
946 | 946 | ||
947 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 947 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
948 | { | 948 | { |
949 | QFileInfo fi(src); | 949 | QFileInfo fi(src); |
950 | if (!fi.exists()) | 950 | if (!fi.exists()) |
951 | return false; | 951 | return false; |
952 | if (QFile::exists(dst)) { | 952 | if (QFile::exists(dst)) { |
953 | if (!QFile::remove(dst)) | 953 | if (!QFile::remove(dst)) |
954 | return false; | 954 | return false; |
955 | } | 955 | } |
956 | QFile srcFd(src); | 956 | QFile srcFd(src); |
957 | if (!srcFd.open(IO_ReadOnly)) | 957 | if (!srcFd.open(IO_ReadOnly)) |
958 | return false; | 958 | return false; |
959 | QFile dstFd(dst); | 959 | QFile dstFd(dst); |
960 | if (!dstFd.open(IO_ReadWrite)) { | 960 | if (!dstFd.open(IO_ReadWrite)) { |
961 | srcFd.close(); | 961 | srcFd.close(); |
962 | return false; | 962 | return false; |
963 | } | 963 | } |
964 | const int tmpBuf_size = 512; | 964 | const int tmpBuf_size = 512; |
965 | char tmpBuf[tmpBuf_size]; | 965 | char tmpBuf[tmpBuf_size]; |
966 | Q_LONG bytesRead, bytesWritten; | 966 | Q_LONG bytesRead, bytesWritten; |
967 | 967 | ||
968 | while (!srcFd.atEnd()) { | 968 | while (!srcFd.atEnd()) { |
969 | bytesRead = srcFd.readBlock(tmpBuf, | 969 | bytesRead = srcFd.readBlock(tmpBuf, |
970 | static_cast<Q_ULONG>(tmpBuf_size)); | 970 | static_cast<Q_ULONG>(tmpBuf_size)); |
971 | if (bytesRead == -1) { | 971 | if (bytesRead == -1) { |
972 | srcFd.close(); | 972 | srcFd.close(); |
973 | dstFd.close(); | 973 | dstFd.close(); |
974 | return false; | 974 | return false; |
975 | } | 975 | } |
976 | bytesWritten = dstFd.writeBlock(tmpBuf, | 976 | bytesWritten = dstFd.writeBlock(tmpBuf, |
977 | static_cast<Q_ULONG>(bytesRead)); | 977 | static_cast<Q_ULONG>(bytesRead)); |
978 | if (bytesWritten != bytesRead) { | 978 | if (bytesWritten != bytesRead) { |
979 | srcFd.close(); | 979 | srcFd.close(); |
980 | dstFd.close(); | 980 | dstFd.close(); |
981 | return false; | 981 | return false; |
982 | } | 982 | } |
983 | } | 983 | } |
984 | srcFd.close(); | 984 | srcFd.close(); |
985 | dstFd.close(); | 985 | dstFd.close(); |
986 | return true; | 986 | return true; |
987 | } | 987 | } |
988 | 988 | ||
989 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 989 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
990 | bool dontFlagDirty, bool updateMeta) | 990 | bool dontFlagDirty, bool updateMeta) |
991 | { | 991 | { |
992 | PWM_ASSERT(d); | 992 | PWM_ASSERT(d); |
993 | unsigned int cat = 0; | 993 | unsigned int cat = 0; |
994 | 994 | ||
995 | if (isDeepLocked()) { | 995 | if (isDeepLocked()) { |
996 | PwMerror ret; | 996 | PwMerror ret; |
997 | ret = deepLock(false); | 997 | ret = deepLock(false); |
998 | if (ret != e_success) | 998 | if (ret != e_success) |
999 | return e_lock; | 999 | return e_lock; |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | addCategory(category, &cat); | 1002 | addCategory(category, &cat); |
1003 | 1003 | ||
1004 | if (numEntries(category) >= maxEntries) | 1004 | if (numEntries(category) >= maxEntries) |
1005 | return e_maxAllowedEntr; | 1005 | return e_maxAllowedEntr; |
1006 | 1006 | ||
1007 | vector<unsigned int> foundPositions; | 1007 | vector<unsigned int> foundPositions; |
1008 | /* historically this was: | 1008 | /* historically this was: |
1009 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 1009 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
1010 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 1010 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
1011 | * But for now we only search in desc. | 1011 | * But for now we only search in desc. |
1012 | * That's a tweak to be KWallet compatible. But it should not add | 1012 | * That's a tweak to be KWallet compatible. But it should not add |
1013 | * usability-drop onto PwManager, does it? | 1013 | * usability-drop onto PwManager, does it? |
1014 | * (And yes, "int" was a bug. Correct is "unsigned int") | 1014 | * (And yes, "int" was a bug. Correct is "unsigned int") |
1015 | */ | 1015 | */ |
1016 | const unsigned int searchIn = SEARCH_IN_DESC; | 1016 | const unsigned int searchIn = SEARCH_IN_DESC; |
1017 | findEntry(cat, *d, searchIn, &foundPositions, true); | 1017 | findEntry(cat, *d, searchIn, &foundPositions, true); |
1018 | if (foundPositions.size()) { | 1018 | if (foundPositions.size()) { |
1019 | // DOH! We found this entry. | 1019 | // DOH! We found this entry. |
1020 | return e_entryExists; | 1020 | return e_entryExists; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | d->listViewPos = -1; | 1023 | d->listViewPos = -1; |
1024 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1024 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1025 | if (updateMeta) { | 1025 | if (updateMeta) { |
1026 | d->meta.create = QDateTime::currentDateTime(); | 1026 | d->meta.create = QDateTime::currentDateTime(); |
1027 | d->meta.update = d->meta.create; | 1027 | d->meta.update = d->meta.create; |
1028 | } | 1028 | } |
1029 | dti.dta[cat].d.push_back(*d); | 1029 | dti.dta[cat].d.push_back(*d); |
1030 | 1030 | ||
1031 | delAllEmptyCat(true); | 1031 | delAllEmptyCat(true); |
1032 | 1032 | ||
1033 | if (!dontFlagDirty) | 1033 | if (!dontFlagDirty) |
1034 | flagDirty(); | 1034 | flagDirty(); |
1035 | return e_success; | 1035 | return e_success; |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1038 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1039 | bool checkIfExist) | 1039 | bool checkIfExist) |
1040 | { | 1040 | { |
1041 | if (isDeepLocked()) { | 1041 | if (isDeepLocked()) { |
1042 | PwMerror ret; | 1042 | PwMerror ret; |
1043 | ret = deepLock(false); | 1043 | ret = deepLock(false); |
1044 | if (ret != e_success) | 1044 | if (ret != e_success) |
1045 | return e_lock; | 1045 | return e_lock; |
1046 | } | 1046 | } |
1047 | if (checkIfExist) { | 1047 | if (checkIfExist) { |
1048 | if (findCategory(category, categoryIndex)) | 1048 | if (findCategory(category, categoryIndex)) |
1049 | return e_categoryExists; | 1049 | return e_categoryExists; |
1050 | } | 1050 | } |
1051 | PwMCategoryItem item; | 1051 | PwMCategoryItem item; |
1052 | item.name = category.latin1(); | 1052 | item.name = category.latin1(); |
1053 | dti.dta.push_back(item); | 1053 | dti.dta.push_back(item); |
1054 | if (categoryIndex) | 1054 | if (categoryIndex) |
1055 | *categoryIndex = dti.dta.size() - 1; | 1055 | *categoryIndex = dti.dta.size() - 1; |
1056 | return e_success; | 1056 | return e_success; |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1059 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1060 | { | 1060 | { |
1061 | unsigned int cat = 0; | 1061 | unsigned int cat = 0; |
1062 | 1062 | ||
1063 | if (!findCategory(category, &cat)) { | 1063 | if (!findCategory(category, &cat)) { |
1064 | BUG(); | 1064 | BUG(); |
1065 | return false; | 1065 | return false; |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | return delEntry(cat, index, dontFlagDirty); | 1068 | return delEntry(cat, index, dontFlagDirty); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1071 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1072 | { | 1072 | { |
1073 | if (isDeepLocked()) | 1073 | if (isDeepLocked()) |
1074 | return false; | 1074 | return false; |
1075 | if (index > dti.dta[category].d.size() - 1) | 1075 | if (index > dti.dta[category].d.size() - 1) |
1076 | return false; | 1076 | return false; |
1077 | getDataChangedLock(); | 1077 | getDataChangedLock(); |
1078 | if (!lockAt(category, index, false)) { | 1078 | if (!lockAt(category, index, false)) { |
1079 | putDataChangedLock(); | 1079 | putDataChangedLock(); |
1080 | return false; | 1080 | return false; |
1081 | } | 1081 | } |
1082 | putDataChangedLock(); | 1082 | putDataChangedLock(); |
1083 | int lvPos = dti.dta[category].d[index].listViewPos; | 1083 | int lvPos = dti.dta[category].d[index].listViewPos; |
1084 | 1084 | ||
1085 | // delete entry | 1085 | // delete entry |
1086 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); | 1086 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1087 | 1087 | ||
1088 | unsigned int i, entries = numEntries(category); | 1088 | unsigned int i, entries = numEntries(category); |
1089 | if (!entries) { | 1089 | if (!entries) { |
1090 | // no more entries in this category, so | 1090 | // no more entries in this category, so |
1091 | // we can delete it, too. | 1091 | // we can delete it, too. |
1092 | BUG_ON(!delCategory(category)); | 1092 | BUG_ON(!delCategory(category)); |
1093 | // delCategory() flags it dirty, so we need not to do so. | 1093 | // delCategory() flags it dirty, so we need not to do so. |
1094 | return true; | 1094 | return true; |
1095 | } | 1095 | } |
1096 | for (i = 0; i < entries; ++i) { | 1096 | for (i = 0; i < entries; ++i) { |
1097 | // decrement all listViewPositions that are greater than the deleted. | 1097 | // decrement all listViewPositions that are greater than the deleted. |
1098 | if (dti.dta[category].d[i].listViewPos > lvPos) | 1098 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1099 | --dti.dta[category].d[i].listViewPos; | 1099 | --dti.dta[category].d[i].listViewPos; |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | if (!dontFlagDirty) | 1102 | if (!dontFlagDirty) |
1103 | flagDirty(); | 1103 | flagDirty(); |
1104 | return true; | 1104 | return true; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1107 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1108 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1108 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1109 | { | 1109 | { |
1110 | PWM_ASSERT(d); | 1110 | PWM_ASSERT(d); |
1111 | unsigned int oldCat = 0; | 1111 | unsigned int oldCat = 0; |
1112 | 1112 | ||
1113 | if (!findCategory(oldCategory, &oldCat)) { | 1113 | if (!findCategory(oldCategory, &oldCat)) { |
1114 | BUG(); | 1114 | BUG(); |
1115 | return false; | 1115 | return false; |
1116 | } | 1116 | } |
1117 | 1117 | ||
1118 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1118 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1121 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1122 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1122 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1123 | { | 1123 | { |
1124 | if (isDeepLocked()) | 1124 | if (isDeepLocked()) |
1125 | return false; | 1125 | return false; |
1126 | if (updateMeta) { | 1126 | if (updateMeta) { |
1127 | d->meta.update = QDateTime::currentDateTime(); | 1127 | d->meta.update = QDateTime::currentDateTime(); |
1128 | if (d->meta.create.isNull()) { | 1128 | if (d->meta.create.isNull()) { |
1129 | d->meta.create = d->meta.update; | 1129 | d->meta.create = d->meta.update; |
1130 | } | 1130 | } |
1131 | } | 1131 | } |
1132 | if (dti.dta[oldCategory].name != newCategory.latin1()) { | 1132 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1133 | // the user changed the category. | 1133 | // the user changed the category. |
1134 | PwMerror ret; | 1134 | PwMerror ret; |
1135 | d->rev = 0; | 1135 | d->rev = 0; |
1136 | ret = addEntry(newCategory, d, true, false); | 1136 | ret = addEntry(newCategory, d, true, false); |
1137 | if (ret != e_success) | 1137 | if (ret != e_success) |
1138 | return false; | 1138 | return false; |
1139 | if (!delEntry(oldCategory, index, true)) | 1139 | if (!delEntry(oldCategory, index, true)) |
1140 | return false; | 1140 | return false; |
1141 | } else { | 1141 | } else { |
1142 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1142 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1143 | dti.dta[oldCategory].d[index] = *d; | 1143 | dti.dta[oldCategory].d[index] = *d; |
1144 | } | 1144 | } |
1145 | flagDirty(); | 1145 | flagDirty(); |
1146 | return true; | 1146 | return true; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | unsigned int PwMDoc::numEntries(const QString &category) | 1149 | unsigned int PwMDoc::numEntries(const QString &category) |
1150 | { | 1150 | { |
1151 | unsigned int cat = 0; | 1151 | unsigned int cat = 0; |
1152 | 1152 | ||
1153 | if (!findCategory(category, &cat)) { | 1153 | if (!findCategory(category, &cat)) { |
1154 | BUG(); | 1154 | BUG(); |
1155 | return 0; | 1155 | return 0; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | return numEntries(cat); | 1158 | return numEntries(cat); |
1159 | } | 1159 | } |
1160 | 1160 | ||
1161 | bool PwMDoc::serializeDta(string *d) | 1161 | bool PwMDoc::serializeDta(string *d) |
1162 | { | 1162 | { |
1163 | PWM_ASSERT(d); | 1163 | PWM_ASSERT(d); |
1164 | Serializer ser; | 1164 | Serializer ser; |
1165 | if (!ser.serialize(dti)) | 1165 | if (!ser.serialize(dti)) |
1166 | return false; | 1166 | return false; |
1167 | d->assign(ser.getXml()); | 1167 | d->assign(ser.getXml()); |
1168 | if (!d->size()) | 1168 | if (!d->size()) |
1169 | return false; | 1169 | return false; |
1170 | return true; | 1170 | return true; |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1173 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1174 | { | 1174 | { |
1175 | PWM_ASSERT(d); | 1175 | PWM_ASSERT(d); |
1176 | #ifndef PWM_EMBEDDED | 1176 | #ifndef PWM_EMBEDDED |
1177 | try { | 1177 | try { |
1178 | 1178 | ||
1179 | Serializer ser(d->c_str()); | 1179 | Serializer ser(d->c_str()); |
1180 | ser.setDefaultLockStat(entriesLocked); | 1180 | ser.setDefaultLockStat(entriesLocked); |
1181 | if (!ser.deSerialize(&dti)) | 1181 | if (!ser.deSerialize(&dti)) |
1182 | return false; | 1182 | return false; |
1183 | } catch (PwMException) { | 1183 | } catch (PwMException) { |
1184 | return false; | 1184 | return false; |
1185 | } | 1185 | } |
1186 | #else | 1186 | #else |
1187 | Serializer ser(d->c_str()); | 1187 | Serializer ser(d->c_str()); |
1188 | ser.setDefaultLockStat(entriesLocked); | 1188 | ser.setDefaultLockStat(entriesLocked); |
1189 | if (!ser.deSerialize(&dti)) | 1189 | if (!ser.deSerialize(&dti)) |
1190 | return false; | 1190 | return false; |
1191 | #endif | 1191 | #endif |
1192 | 1192 | ||
1193 | emitDataChanged(this); | 1193 | emitDataChanged(this); |
1194 | return true; | 1194 | return true; |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1197 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1198 | PwMDataItem * d, bool unlockIfLocked) | 1198 | PwMDataItem * d, bool unlockIfLocked) |
1199 | { | 1199 | { |
1200 | PWM_ASSERT(d); | 1200 | PWM_ASSERT(d); |
1201 | unsigned int cat = 0; | 1201 | unsigned int cat = 0; |
1202 | 1202 | ||
1203 | if (!findCategory(category, &cat)) { | 1203 | if (!findCategory(category, &cat)) { |
1204 | BUG(); | 1204 | BUG(); |
1205 | return false; | 1205 | return false; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | return getEntry(cat, index, d, unlockIfLocked); | 1208 | return getEntry(cat, index, d, unlockIfLocked); |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1211 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1212 | PwMDataItem *d, bool unlockIfLocked) | 1212 | PwMDataItem *d, bool unlockIfLocked) |
1213 | { | 1213 | { |
1214 | if (index > dti.dta[category].d.size() - 1) | 1214 | if (index > dti.dta[category].d.size() - 1) |
1215 | return false; | 1215 | return false; |
1216 | 1216 | ||
1217 | bool locked = isLocked(category, index); | 1217 | bool locked = isLocked(category, index); |
1218 | if (locked) { | 1218 | if (locked) { |
1219 | /* this entry is locked. We don't return a password, | 1219 | /* this entry is locked. We don't return a password, |
1220 | * until it's unlocked by the user by inserting | 1220 | * until it's unlocked by the user by inserting |
1221 | * chipcard or entering the mpw | 1221 | * chipcard or entering the mpw |
1222 | */ | 1222 | */ |
1223 | if (unlockIfLocked) { | 1223 | if (unlockIfLocked) { |
1224 | if (!lockAt(category, index, false)) { | 1224 | if (!lockAt(category, index, false)) { |
1225 | return false; | 1225 | return false; |
1226 | } | 1226 | } |
1227 | locked = false; | 1227 | locked = false; |
1228 | } | 1228 | } |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | *d = dti.dta[category].d[index]; | 1231 | *d = dti.dta[category].d[index]; |
1232 | if (locked) | 1232 | if (locked) |
1233 | d->pw = LOCKED_STRING.latin1(); | 1233 | d->pw = LOCKED_STRING.latin1(); |
1234 | 1234 | ||
1235 | return true; | 1235 | return true; |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1238 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1239 | string *foundComment) | 1239 | string *foundComment) |
1240 | { | 1240 | { |
1241 | PWM_ASSERT(foundComment); | 1241 | PWM_ASSERT(foundComment); |
1242 | unsigned int cat = 0; | 1242 | unsigned int cat = 0; |
1243 | 1243 | ||
1244 | if (!findCategory(category, &cat)) | 1244 | if (!findCategory(category, &cat)) |
1245 | return e_invalidArg; | 1245 | return e_invalidArg; |
1246 | 1246 | ||
1247 | unsigned int i, entries = numEntries(cat); | 1247 | unsigned int i, entries = numEntries(cat); |
1248 | for (i = 0; i < entries; ++i) { | 1248 | for (i = 0; i < entries; ++i) { |
1249 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | 1249 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1250 | *foundComment = dti.dta[cat].d[i].comment; | 1250 | *foundComment = dti.dta[cat].d[i].comment; |
1251 | if (dti.dta[cat].d[i].binary) | 1251 | if (dti.dta[cat].d[i].binary) |
1252 | return e_binEntry; | 1252 | return e_binEntry; |
1253 | return e_normalEntry; | 1253 | return e_normalEntry; |
1254 | } | 1254 | } |
1255 | } | 1255 | } |
1256 | BUG(); | 1256 | BUG(); |
1257 | return e_generic; | 1257 | return e_generic; |
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | bool PwMDoc::compressDta(string *d, char algo) | 1260 | bool PwMDoc::compressDta(string *d, char algo) |
1261 | { | 1261 | { |
1262 | PWM_ASSERT(d); | 1262 | PWM_ASSERT(d); |
1263 | switch (algo) { | 1263 | switch (algo) { |
1264 | case PWM_COMPRESS_GZIP: { | 1264 | case PWM_COMPRESS_GZIP: { |
1265 | CompressGzip comp; | 1265 | CompressGzip comp; |
1266 | return comp.compress(d); | 1266 | return comp.compress(d); |
1267 | /*US } case PWM_COMPRESS_BZIP2: { | 1267 | } |
1268 | #ifndef PWM_EMBEDDED | ||
1269 | case PWM_COMPRESS_BZIP2: { | ||
1268 | CompressBzip2 comp; | 1270 | CompressBzip2 comp; |
1269 | return comp.compress(d); | 1271 | return comp.compress(d); |
1270 | */ | 1272 | } |
1271 | } case PWM_COMPRESS_NONE: { | 1273 | #endif |
1274 | case PWM_COMPRESS_NONE: { | ||
1272 | return true; | 1275 | return true; |
1273 | } default: { | 1276 | } default: { |
1274 | BUG(); | 1277 | BUG(); |
1275 | } | 1278 | } |
1276 | } | 1279 | } |
1277 | return false; | 1280 | return false; |
1278 | } | 1281 | } |
1279 | 1282 | ||
1280 | bool PwMDoc::decompressDta(string *d, char algo) | 1283 | bool PwMDoc::decompressDta(string *d, char algo) |
1281 | { | 1284 | { |
1282 | PWM_ASSERT(d); | 1285 | PWM_ASSERT(d); |
1283 | switch (algo) { | 1286 | switch (algo) { |
1284 | case PWM_COMPRESS_GZIP: { | 1287 | case PWM_COMPRESS_GZIP: { |
1285 | CompressGzip comp; | 1288 | CompressGzip comp; |
1286 | return comp.decompress(d); | 1289 | return comp.decompress(d); |
1287 | /*US } case PWM_COMPRESS_BZIP2: { | 1290 | } |
1291 | #ifndef PWM_EMBEDDED | ||
1292 | case PWM_COMPRESS_BZIP2: { | ||
1288 | CompressBzip2 comp; | 1293 | CompressBzip2 comp; |
1289 | return comp.decompress(d); | 1294 | return comp.decompress(d); |
1290 | */ | 1295 | } |
1291 | } case PWM_COMPRESS_NONE: { | 1296 | #endif |
1297 | case PWM_COMPRESS_NONE: { | ||
1292 | return true; | 1298 | return true; |
1293 | } | 1299 | } |
1294 | } | 1300 | } |
1295 | return false; | 1301 | return false; |
1296 | } | 1302 | } |
1297 | 1303 | ||
1298 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1304 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1299 | { | 1305 | { |
1300 | PWM_ASSERT(d); | 1306 | PWM_ASSERT(d); |
1301 | PWM_ASSERT(pw); | 1307 | PWM_ASSERT(pw); |
1302 | PWM_ASSERT(f); | 1308 | PWM_ASSERT(f); |
1303 | 1309 | ||
1304 | size_t encSize; | 1310 | size_t encSize; |
1305 | byte *encrypted = 0; | 1311 | byte *encrypted = 0; |
1306 | 1312 | ||
1307 | switch (algo) { | 1313 | switch (algo) { |
1308 | case PWM_CRYPT_BLOWFISH: { | 1314 | case PWM_CRYPT_BLOWFISH: { |
1309 | Blowfish::padNull(d); | 1315 | Blowfish::padNull(d); |
1310 | encSize = d->length(); | 1316 | encSize = d->length(); |
1311 | encrypted = new byte[encSize]; | 1317 | encrypted = new byte[encSize]; |
1312 | Blowfish bf; | 1318 | Blowfish bf; |
1313 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1319 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1314 | delete [] encrypted; | 1320 | delete [] encrypted; |
1315 | return e_weakPw; | 1321 | return e_weakPw; |
1316 | } | 1322 | } |
1317 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1323 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1318 | break; | 1324 | break; |
1319 | } | 1325 | } |
1320 | case PWM_CRYPT_AES128: | 1326 | case PWM_CRYPT_AES128: |
1321 | /*... fall through */ | 1327 | /*... fall through */ |
1322 | case PWM_CRYPT_AES192: | 1328 | case PWM_CRYPT_AES192: |
1323 | case PWM_CRYPT_AES256: | 1329 | case PWM_CRYPT_AES256: |
1324 | case PWM_CRYPT_3DES: | 1330 | case PWM_CRYPT_3DES: |
1325 | case PWM_CRYPT_TWOFISH: | 1331 | case PWM_CRYPT_TWOFISH: |
1326 | case PWM_CRYPT_TWOFISH128: { | 1332 | case PWM_CRYPT_TWOFISH128: { |
1327 | if (!LibGCryptIf::available()) | 1333 | if (!LibGCryptIf::available()) |
1328 | return e_cryptNotImpl; | 1334 | return e_cryptNotImpl; |
1329 | LibGCryptIf gc; | 1335 | LibGCryptIf gc; |
1330 | PwMerror err; | 1336 | PwMerror err; |
1331 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1337 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1332 | memcpy(plain, d->c_str(), d->length()); | 1338 | memcpy(plain, d->c_str(), d->length()); |
1333 | err = gc.encrypt(&encrypted, | 1339 | err = gc.encrypt(&encrypted, |
1334 | &encSize, | 1340 | &encSize, |
1335 | plain, | 1341 | plain, |
1336 | d->length(), | 1342 | d->length(), |
1337 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1343 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1338 | pw->length(), | 1344 | pw->length(), |
1339 | algo); | 1345 | algo); |
1340 | delete [] plain; | 1346 | delete [] plain; |
1341 | if (err != e_success) | 1347 | if (err != e_success) |
1342 | return e_cryptNotImpl; | 1348 | return e_cryptNotImpl; |
1343 | break; | 1349 | break; |
1344 | } | 1350 | } |
1345 | default: { | 1351 | default: { |
1346 | delete_ifnot_null_array(encrypted); | 1352 | delete_ifnot_null_array(encrypted); |
1347 | return e_cryptNotImpl; | 1353 | return e_cryptNotImpl; |
1348 | } } | 1354 | } } |
1349 | 1355 | ||
1350 | // write encrypted data to file | 1356 | // write encrypted data to file |
1351 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1357 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1352 | static_cast<Q_ULONG>(encSize)) | 1358 | static_cast<Q_ULONG>(encSize)) |
1353 | != static_cast<Q_LONG>(encSize)) { | 1359 | != static_cast<Q_LONG>(encSize)) { |
1354 | delete_ifnot_null_array(encrypted); | 1360 | delete_ifnot_null_array(encrypted); |
1355 | return e_writeFile; | 1361 | return e_writeFile; |
1356 | } | 1362 | } |
1357 | delete_ifnot_null_array(encrypted); | 1363 | delete_ifnot_null_array(encrypted); |
1358 | return e_success; | 1364 | return e_success; |
1359 | } | 1365 | } |
1360 | 1366 | ||
1361 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1367 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1362 | char algo, QFile *f) | 1368 | char algo, QFile *f) |
1363 | { | 1369 | { |
1364 | PWM_ASSERT(d); | 1370 | PWM_ASSERT(d); |
1365 | PWM_ASSERT(pw); | 1371 | PWM_ASSERT(pw); |
1366 | PWM_ASSERT(f); | 1372 | PWM_ASSERT(f); |
1367 | 1373 | ||
1368 | unsigned int cryptLen = f->size() - pos; | 1374 | unsigned int cryptLen = f->size() - pos; |
1369 | byte *encrypted = new byte[cryptLen]; | 1375 | byte *encrypted = new byte[cryptLen]; |
1370 | byte *decrypted = new byte[cryptLen]; | 1376 | byte *decrypted = new byte[cryptLen]; |
1371 | 1377 | ||
1372 | f->at(pos); | 1378 | f->at(pos); |
1373 | #ifndef PWM_EMBEDDED | 1379 | #ifndef PWM_EMBEDDED |
1374 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1380 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1375 | static_cast<Q_ULONG>(cryptLen)) | 1381 | static_cast<Q_ULONG>(cryptLen)) |
1376 | != static_cast<Q_LONG>(cryptLen)) { | 1382 | != static_cast<Q_LONG>(cryptLen)) { |
1377 | delete [] encrypted; | 1383 | delete [] encrypted; |
1378 | delete [] decrypted; | 1384 | delete [] decrypted; |
1379 | return e_readFile; | 1385 | return e_readFile; |
1380 | } | 1386 | } |
1381 | #else | 1387 | #else |
1382 | if (f->readBlock((char *)(encrypted), | 1388 | if (f->readBlock((char *)(encrypted), |
1383 | (unsigned long)(cryptLen)) | 1389 | (unsigned long)(cryptLen)) |
1384 | != (long)(cryptLen)) { | 1390 | != (long)(cryptLen)) { |
1385 | delete [] encrypted; | 1391 | delete [] encrypted; |
1386 | delete [] decrypted; | 1392 | delete [] decrypted; |
1387 | return e_readFile; | 1393 | return e_readFile; |
1388 | } | 1394 | } |
1389 | #endif | 1395 | #endif |
1390 | switch (algo) { | 1396 | switch (algo) { |
1391 | case PWM_CRYPT_BLOWFISH: { | 1397 | case PWM_CRYPT_BLOWFISH: { |
1392 | Blowfish bf; | 1398 | Blowfish bf; |
1393 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1399 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1394 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1400 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1395 | break; | 1401 | break; |
1396 | } | 1402 | } |
1397 | case PWM_CRYPT_AES128: | 1403 | case PWM_CRYPT_AES128: |
1398 | /*... fall through */ | 1404 | /*... fall through */ |
1399 | case PWM_CRYPT_AES192: | 1405 | case PWM_CRYPT_AES192: |
1400 | case PWM_CRYPT_AES256: | 1406 | case PWM_CRYPT_AES256: |
1401 | case PWM_CRYPT_3DES: | 1407 | case PWM_CRYPT_3DES: |
1402 | case PWM_CRYPT_TWOFISH: | 1408 | case PWM_CRYPT_TWOFISH: |
1403 | case PWM_CRYPT_TWOFISH128: { | 1409 | case PWM_CRYPT_TWOFISH128: { |
1404 | if (!LibGCryptIf::available()) | 1410 | if (!LibGCryptIf::available()) |
1405 | return e_cryptNotImpl; | 1411 | return e_cryptNotImpl; |
1406 | LibGCryptIf gc; | 1412 | LibGCryptIf gc; |
1407 | PwMerror err; | 1413 | PwMerror err; |
1408 | err = gc.decrypt(&decrypted, | 1414 | err = gc.decrypt(&decrypted, |
1409 | &cryptLen, | 1415 | &cryptLen, |
1410 | encrypted, | 1416 | encrypted, |
1411 | cryptLen, | 1417 | cryptLen, |
1412 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1418 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1413 | pw->length(), | 1419 | pw->length(), |
1414 | algo); | 1420 | algo); |
1415 | if (err != e_success) { | 1421 | if (err != e_success) { |
1416 | delete [] encrypted; | 1422 | delete [] encrypted; |
1417 | delete [] decrypted; | 1423 | delete [] decrypted; |
1418 | return e_cryptNotImpl; | 1424 | return e_cryptNotImpl; |
1419 | } | 1425 | } |
1420 | break; | 1426 | break; |
1421 | } | 1427 | } |
1422 | default: { | 1428 | default: { |
1423 | delete [] encrypted; | 1429 | delete [] encrypted; |
1424 | delete [] decrypted; | 1430 | delete [] decrypted; |
1425 | return e_cryptNotImpl; | 1431 | return e_cryptNotImpl; |
1426 | } } | 1432 | } } |
1427 | delete [] encrypted; | 1433 | delete [] encrypted; |
1428 | #ifndef PWM_EMBEDDED | 1434 | #ifndef PWM_EMBEDDED |
1429 | d->assign(reinterpret_cast<const char *>(decrypted), | 1435 | d->assign(reinterpret_cast<const char *>(decrypted), |
1430 | static_cast<string::size_type>(cryptLen)); | 1436 | static_cast<string::size_type>(cryptLen)); |
1431 | #else | 1437 | #else |
1432 | d->assign((const char *)(decrypted), | 1438 | d->assign((const char *)(decrypted), |
1433 | (string::size_type)(cryptLen)); | 1439 | (string::size_type)(cryptLen)); |
1434 | #endif | 1440 | #endif |
1435 | delete [] decrypted; | 1441 | delete [] decrypted; |
1436 | if (algo == PWM_CRYPT_BLOWFISH) { | 1442 | if (algo == PWM_CRYPT_BLOWFISH) { |
1437 | if (!Blowfish::unpadNull(d)) { | 1443 | if (!Blowfish::unpadNull(d)) { |
1438 | BUG(); | 1444 | BUG(); |
1439 | return e_readFile; | 1445 | return e_readFile; |
1440 | } | 1446 | } |
1441 | } | 1447 | } |
1442 | return e_success; | 1448 | return e_success; |
1443 | } | 1449 | } |
1444 | 1450 | ||
1445 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1451 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1446 | const string *dataStream) | 1452 | const string *dataStream) |
1447 | { | 1453 | { |
1448 | PWM_ASSERT(dataHash); | 1454 | PWM_ASSERT(dataHash); |
1449 | PWM_ASSERT(dataStream); | 1455 | PWM_ASSERT(dataStream); |
1450 | switch(dataHashType) { | 1456 | switch(dataHashType) { |
1451 | case PWM_HASH_SHA1: { | 1457 | case PWM_HASH_SHA1: { |
1452 | Sha1 hash; | 1458 | Sha1 hash; |
1453 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1459 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1454 | string ret = hash.sha1_read(); | 1460 | string ret = hash.sha1_read(); |
1455 | if (ret != *dataHash) | 1461 | if (ret != *dataHash) |
1456 | return e_fileCorrupt; | 1462 | return e_fileCorrupt; |
1457 | break; | 1463 | break; |
1458 | } | 1464 | } |
1459 | case PWM_HASH_SHA256: | 1465 | case PWM_HASH_SHA256: |
1460 | /*... fall through */ | 1466 | /*... fall through */ |
1461 | case PWM_HASH_SHA384: | 1467 | case PWM_HASH_SHA384: |
1462 | case PWM_HASH_SHA512: | 1468 | case PWM_HASH_SHA512: |
1463 | case PWM_HASH_MD5: | 1469 | case PWM_HASH_MD5: |
1464 | case PWM_HASH_RMD160: | 1470 | case PWM_HASH_RMD160: |
1465 | case PWM_HASH_TIGER: { | 1471 | case PWM_HASH_TIGER: { |
1466 | if (!LibGCryptIf::available()) | 1472 | if (!LibGCryptIf::available()) |
1467 | return e_hashNotImpl; | 1473 | return e_hashNotImpl; |
1468 | LibGCryptIf gc; | 1474 | LibGCryptIf gc; |
1469 | PwMerror err; | 1475 | PwMerror err; |
1470 | unsigned char *buf; | 1476 | unsigned char *buf; |
1471 | size_t hashLen; | 1477 | size_t hashLen; |
1472 | err = gc.hash(&buf, | 1478 | err = gc.hash(&buf, |
1473 | &hashLen, | 1479 | &hashLen, |
1474 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1480 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1475 | dataStream->length(), | 1481 | dataStream->length(), |
1476 | dataHashType); | 1482 | dataHashType); |
1477 | if (err != e_success) | 1483 | if (err != e_success) |
1478 | return e_hashNotImpl; | 1484 | return e_hashNotImpl; |
1479 | string calcHash(reinterpret_cast<const char *>(buf), | 1485 | string calcHash(reinterpret_cast<const char *>(buf), |
1480 | static_cast<string::size_type>(hashLen)); | 1486 | static_cast<string::size_type>(hashLen)); |
1481 | delete [] buf; | 1487 | delete [] buf; |
1482 | if (calcHash != *dataHash) | 1488 | if (calcHash != *dataHash) |
1483 | return e_fileCorrupt; | 1489 | return e_fileCorrupt; |
1484 | break; | 1490 | break; |
1485 | } | 1491 | } |
1486 | default: | 1492 | default: |
1487 | return e_hashNotImpl; | 1493 | return e_hashNotImpl; |
1488 | } | 1494 | } |
1489 | return e_success; | 1495 | return e_success; |
1490 | } | 1496 | } |
1491 | 1497 | ||
1492 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1498 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1493 | bool lock) | 1499 | bool lock) |
1494 | { | 1500 | { |
1495 | if (index >= numEntries(category)) { | 1501 | if (index >= numEntries(category)) { |
1496 | BUG(); | 1502 | BUG(); |
1497 | return false; | 1503 | return false; |
1498 | } | 1504 | } |
1499 | if (lock == dti.dta[category].d[index].lockStat) | 1505 | if (lock == dti.dta[category].d[index].lockStat) |
1500 | return true; | 1506 | return true; |
1501 | 1507 | ||
1502 | if (!lock && currentPw != "") { | 1508 | if (!lock && currentPw != "") { |
1503 | // "unlocking" and "password is already set" | 1509 | // "unlocking" and "password is already set" |
1504 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1510 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1505 | // unlocking without pw not allowed | 1511 | // unlocking without pw not allowed |
1506 | QString pw; | 1512 | QString pw; |
1507 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1513 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1508 | if (pw != "") { | 1514 | if (pw != "") { |
1509 | if (pw != currentPw) { | 1515 | if (pw != currentPw) { |
1510 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1516 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1511 | return false; | 1517 | return false; |
1512 | } else { | 1518 | } else { |
1513 | timer()->start(DocTimer::id_mpwTimer); | 1519 | timer()->start(DocTimer::id_mpwTimer); |
1514 | } | 1520 | } |
1515 | } else { | 1521 | } else { |
1516 | return false; | 1522 | return false; |
1517 | } | 1523 | } |
1518 | } else { | 1524 | } else { |
1519 | timer()->start(DocTimer::id_mpwTimer); | 1525 | timer()->start(DocTimer::id_mpwTimer); |
1520 | } | 1526 | } |
1521 | } | 1527 | } |
1522 | 1528 | ||
1523 | dti.dta[category].d[index].lockStat = lock; | 1529 | dti.dta[category].d[index].lockStat = lock; |
1524 | dti.dta[category].d[index].rev++; // increment revision counter. | 1530 | dti.dta[category].d[index].rev++; // increment revision counter. |
1525 | 1531 | ||
1526 | emitDataChanged(this); | 1532 | emitDataChanged(this); |
1527 | if (!lock) | 1533 | if (!lock) |
1528 | timer()->start(DocTimer::id_autoLockTimer); | 1534 | timer()->start(DocTimer::id_autoLockTimer); |
1529 | 1535 | ||
1530 | return true; | 1536 | return true; |
1531 | 1537 | ||
1532 | } | 1538 | } |
1533 | 1539 | ||
1534 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1540 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1535 | bool lock) | 1541 | bool lock) |
1536 | { | 1542 | { |
1537 | unsigned int cat = 0; | 1543 | unsigned int cat = 0; |
1538 | 1544 | ||
1539 | if (!findCategory(category, &cat)) { | 1545 | if (!findCategory(category, &cat)) { |
1540 | BUG(); | 1546 | BUG(); |
1541 | return false; | 1547 | return false; |
1542 | } | 1548 | } |
1543 | 1549 | ||
1544 | return lockAt(cat, index, lock); | 1550 | return lockAt(cat, index, lock); |
1545 | } | 1551 | } |
1546 | 1552 | ||
1547 | bool PwMDoc::lockAll(bool lock) | 1553 | bool PwMDoc::lockAll(bool lock) |
1548 | { | 1554 | { |
1549 | if (!lock && isDeepLocked()) { | 1555 | if (!lock && isDeepLocked()) { |
1550 | PwMerror ret; | 1556 | PwMerror ret; |
1551 | ret = deepLock(false); | 1557 | ret = deepLock(false); |
1552 | if (ret != e_success) | 1558 | if (ret != e_success) |
1553 | return false; | 1559 | return false; |
1554 | return true; | 1560 | return true; |
1555 | } | 1561 | } |
1556 | if (isDocEmpty()) { | 1562 | if (isDocEmpty()) { |
1557 | return true; | 1563 | return true; |
1558 | } | 1564 | } |
1559 | if (!lock && currentPw != "") { | 1565 | if (!lock && currentPw != "") { |
1560 | // unlocking and password is already set | 1566 | // unlocking and password is already set |
1561 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1567 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1562 | // unlocking without pw not allowed | 1568 | // unlocking without pw not allowed |
1563 | QString pw; | 1569 | QString pw; |
1564 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1570 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1565 | if (pw != "") { | 1571 | if (pw != "") { |
1566 | if (pw != currentPw) { | 1572 | if (pw != currentPw) { |
1567 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1573 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1568 | return false; | 1574 | return false; |
1569 | } else { | 1575 | } else { |
1570 | timer()->start(DocTimer::id_mpwTimer); | 1576 | timer()->start(DocTimer::id_mpwTimer); |
1571 | } | 1577 | } |
1572 | } else { | 1578 | } else { |
1573 | return false; | 1579 | return false; |
1574 | } | 1580 | } |
1575 | } else { | 1581 | } else { |
1576 | timer()->start(DocTimer::id_mpwTimer); | 1582 | timer()->start(DocTimer::id_mpwTimer); |
1577 | } | 1583 | } |
1578 | } | 1584 | } |
1579 | 1585 | ||
1580 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1586 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1581 | catEnd = dti.dta.end(), | 1587 | catEnd = dti.dta.end(), |
1582 | catI = catBegin; | 1588 | catI = catBegin; |
1583 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1589 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1584 | while (catI != catEnd) { | 1590 | while (catI != catEnd) { |
1585 | entrBegin = catI->d.begin(); | 1591 | entrBegin = catI->d.begin(); |
1586 | entrEnd = catI->d.end(); | 1592 | entrEnd = catI->d.end(); |
1587 | entrI = entrBegin; | 1593 | entrI = entrBegin; |
1588 | while (entrI != entrEnd) { | 1594 | while (entrI != entrEnd) { |
1589 | entrI->lockStat = lock; | 1595 | entrI->lockStat = lock; |
1590 | entrI->rev++; // increment revision counter. | 1596 | entrI->rev++; // increment revision counter. |
1591 | ++entrI; | 1597 | ++entrI; |
1592 | } | 1598 | } |
1593 | ++catI; | 1599 | ++catI; |
1594 | } | 1600 | } |
1595 | 1601 | ||
1596 | emitDataChanged(this); | 1602 | emitDataChanged(this); |
1597 | if (lock) | 1603 | if (lock) |
1598 | timer()->stop(DocTimer::id_autoLockTimer); | 1604 | timer()->stop(DocTimer::id_autoLockTimer); |
1599 | else | 1605 | else |
1600 | timer()->start(DocTimer::id_autoLockTimer); | 1606 | timer()->start(DocTimer::id_autoLockTimer); |
1601 | 1607 | ||
1602 | return true; | 1608 | return true; |
1603 | } | 1609 | } |
1604 | 1610 | ||
1605 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1611 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1606 | { | 1612 | { |
1607 | unsigned int cat = 0; | 1613 | unsigned int cat = 0; |
1608 | 1614 | ||
1609 | if (!findCategory(category, &cat)) { | 1615 | if (!findCategory(category, &cat)) { |
1610 | BUG(); | 1616 | BUG(); |
1611 | return false; | 1617 | return false; |
1612 | } | 1618 | } |
1613 | 1619 | ||
1614 | return isLocked(cat, index); | 1620 | return isLocked(cat, index); |
1615 | } | 1621 | } |
1616 | 1622 | ||
1617 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1623 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1618 | { | 1624 | { |
1619 | static vector< vector<bool> > *oldLockStates = 0; | 1625 | static vector< vector<bool> > *oldLockStates = 0; |
1620 | static bool wasDeepLocked; | 1626 | static bool wasDeepLocked; |
1621 | 1627 | ||
1622 | if (revert) {// revert the unlocking | 1628 | if (revert) {// revert the unlocking |
1623 | if (oldLockStates) { | 1629 | if (oldLockStates) { |
1624 | /* we actually _have_ unlocked something, because | 1630 | /* we actually _have_ unlocked something, because |
1625 | * we have allocated space for the oldLockStates. | 1631 | * we have allocated space for the oldLockStates. |
1626 | * So, go on and revert them! | 1632 | * So, go on and revert them! |
1627 | */ | 1633 | */ |
1628 | if (wasDeepLocked) { | 1634 | if (wasDeepLocked) { |
1629 | PwMerror ret = deepLock(true); | 1635 | PwMerror ret = deepLock(true); |
1630 | if (ret == e_success) { | 1636 | if (ret == e_success) { |
1631 | /* deep-lock succeed. We are save. | 1637 | /* deep-lock succeed. We are save. |
1632 | * (but if it failed, just go on | 1638 | * (but if it failed, just go on |
1633 | * lock them normally) | 1639 | * lock them normally) |
1634 | */ | 1640 | */ |
1635 | delete_and_null(oldLockStates); | 1641 | delete_and_null(oldLockStates); |
1636 | timer()->start(DocTimer::id_autoLockTimer); | 1642 | timer()->start(DocTimer::id_autoLockTimer); |
1637 | printDebug("tempoary unlocking of dta " | 1643 | printDebug("tempoary unlocking of dta " |
1638 | "reverted by deep-locking."); | 1644 | "reverted by deep-locking."); |
1639 | return true; | 1645 | return true; |
1640 | } | 1646 | } |
1641 | printDebug("deep-lock failed while reverting! " | 1647 | printDebug("deep-lock failed while reverting! " |
1642 | "Falling back to normal-lock."); | 1648 | "Falling back to normal-lock."); |
1643 | } | 1649 | } |
1644 | if (unlikely(!wasDeepLocked && | 1650 | if (unlikely(!wasDeepLocked && |
1645 | numCategories() != oldLockStates->size())) { | 1651 | numCategories() != oldLockStates->size())) { |
1646 | /* DOH! We have modified "dta" while | 1652 | /* DOH! We have modified "dta" while |
1647 | * it was unlocked tempoary. DON'T DO THIS! | 1653 | * it was unlocked tempoary. DON'T DO THIS! |
1648 | */ | 1654 | */ |
1649 | BUG(); | 1655 | BUG(); |
1650 | delete_and_null(oldLockStates); | 1656 | delete_and_null(oldLockStates); |
1651 | timer()->start(DocTimer::id_autoLockTimer); | 1657 | timer()->start(DocTimer::id_autoLockTimer); |
1652 | return false; | 1658 | return false; |
1653 | } | 1659 | } |
1654 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1660 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1655 | catEnd = dti.dta.end(), | 1661 | catEnd = dti.dta.end(), |
1656 | catI = catBegin; | 1662 | catI = catBegin; |
1657 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1663 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1658 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1664 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1659 | vector<bool>::iterator oldEntrStatBegin, | 1665 | vector<bool>::iterator oldEntrStatBegin, |
1660 | oldEntrStatEnd, | 1666 | oldEntrStatEnd, |
1661 | oldEntrStatI; | 1667 | oldEntrStatI; |
1662 | while (catI != catEnd) { | 1668 | while (catI != catEnd) { |
1663 | entrBegin = catI->d.begin(); | 1669 | entrBegin = catI->d.begin(); |
1664 | entrEnd = catI->d.end(); | 1670 | entrEnd = catI->d.end(); |
1665 | entrI = entrBegin; | 1671 | entrI = entrBegin; |
1666 | if (likely(!wasDeepLocked)) { | 1672 | if (likely(!wasDeepLocked)) { |
1667 | oldEntrStatBegin = oldCatStatI->begin(); | 1673 | oldEntrStatBegin = oldCatStatI->begin(); |
1668 | oldEntrStatEnd = oldCatStatI->end(); | 1674 | oldEntrStatEnd = oldCatStatI->end(); |
1669 | oldEntrStatI = oldEntrStatBegin; | 1675 | oldEntrStatI = oldEntrStatBegin; |
1670 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1676 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1671 | /* DOH! We have modified "dta" while | 1677 | /* DOH! We have modified "dta" while |
1672 | * it was unlocked tempoary. DON'T DO THIS! | 1678 | * it was unlocked tempoary. DON'T DO THIS! |
1673 | */ | 1679 | */ |
1674 | BUG(); | 1680 | BUG(); |
1675 | delete_and_null(oldLockStates); | 1681 | delete_and_null(oldLockStates); |
1676 | timer()->start(DocTimer::id_autoLockTimer); | 1682 | timer()->start(DocTimer::id_autoLockTimer); |
1677 | return false; | 1683 | return false; |
1678 | } | 1684 | } |
1679 | } | 1685 | } |
1680 | while (entrI != entrEnd) { | 1686 | while (entrI != entrEnd) { |
1681 | if (wasDeepLocked) { | 1687 | if (wasDeepLocked) { |
1682 | /* this is an error-fallback if | 1688 | /* this is an error-fallback if |
1683 | * deeplock didn't succeed | 1689 | * deeplock didn't succeed |
1684 | */ | 1690 | */ |
1685 | entrI->lockStat = true; | 1691 | entrI->lockStat = true; |
1686 | } else { | 1692 | } else { |
1687 | entrI->lockStat = *oldEntrStatI; | 1693 | entrI->lockStat = *oldEntrStatI; |
1688 | } | 1694 | } |
1689 | ++entrI; | 1695 | ++entrI; |
1690 | if (likely(!wasDeepLocked)) | 1696 | if (likely(!wasDeepLocked)) |
1691 | ++oldEntrStatI; | 1697 | ++oldEntrStatI; |
1692 | } | 1698 | } |
1693 | ++catI; | 1699 | ++catI; |
1694 | if (likely(!wasDeepLocked)) | 1700 | if (likely(!wasDeepLocked)) |
1695 | ++oldCatStatI; | 1701 | ++oldCatStatI; |
1696 | } | 1702 | } |
1697 | delete_and_null(oldLockStates); | 1703 | delete_and_null(oldLockStates); |
1698 | if (unlikely(wasDeepLocked)) { | 1704 | if (unlikely(wasDeepLocked)) { |
1699 | /* error fallback... */ | 1705 | /* error fallback... */ |
1700 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1706 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1701 | emitDataChanged(this); | 1707 | emitDataChanged(this); |
1702 | printDebug("WARNING: unlockAll_tempoary(true) " | 1708 | printDebug("WARNING: unlockAll_tempoary(true) " |
1703 | "deeplock fallback!"); | 1709 | "deeplock fallback!"); |
1704 | } | 1710 | } |
1705 | printDebug("tempoary unlocking of dta reverted."); | 1711 | printDebug("tempoary unlocking of dta reverted."); |
1706 | } else { | 1712 | } else { |
1707 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1713 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1708 | } | 1714 | } |
1709 | timer()->start(DocTimer::id_autoLockTimer); | 1715 | timer()->start(DocTimer::id_autoLockTimer); |
1710 | } else {// unlock all data tempoary | 1716 | } else {// unlock all data tempoary |
1711 | if (unlikely(oldLockStates != 0)) { | 1717 | if (unlikely(oldLockStates != 0)) { |
1712 | /* DOH! We have already unlocked the data tempoarly. | 1718 | /* DOH! We have already unlocked the data tempoarly. |
1713 | * No need to do it twice. ;) | 1719 | * No need to do it twice. ;) |
1714 | */ | 1720 | */ |
1715 | BUG(); | 1721 | BUG(); |
1716 | return false; | 1722 | return false; |
1717 | } | 1723 | } |
1718 | wasDeepLocked = false; | 1724 | wasDeepLocked = false; |
1719 | bool mustUnlock = false; | 1725 | bool mustUnlock = false; |
1720 | if (isDeepLocked()) { | 1726 | if (isDeepLocked()) { |
1721 | PwMerror ret; | 1727 | PwMerror ret; |
1722 | while (1) { | 1728 | while (1) { |
1723 | ret = deepLock(false); | 1729 | ret = deepLock(false); |
1724 | if (ret == e_success) { | 1730 | if (ret == e_success) { |
1725 | break; | 1731 | break; |
1726 | } else if (ret == e_wrongPw) { | 1732 | } else if (ret == e_wrongPw) { |
1727 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1733 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1728 | } else { | 1734 | } else { |
1729 | printDebug("deep-unlocking failed while " | 1735 | printDebug("deep-unlocking failed while " |
1730 | "tempoary unlocking!"); | 1736 | "tempoary unlocking!"); |
1731 | return false; | 1737 | return false; |
1732 | } | 1738 | } |
1733 | } | 1739 | } |
1734 | wasDeepLocked = true; | 1740 | wasDeepLocked = true; |
1735 | mustUnlock = true; | 1741 | mustUnlock = true; |
1736 | } else { | 1742 | } else { |
1737 | // first check if it's needed to unlock some entries | 1743 | // first check if it's needed to unlock some entries |
1738 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1744 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1739 | catEnd = dti.dta.end(), | 1745 | catEnd = dti.dta.end(), |
1740 | catI = catBegin; | 1746 | catI = catBegin; |
1741 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1747 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1742 | while (catI != catEnd) { | 1748 | while (catI != catEnd) { |
1743 | entrBegin = catI->d.begin(); | 1749 | entrBegin = catI->d.begin(); |
1744 | entrEnd = catI->d.end(); | 1750 | entrEnd = catI->d.end(); |
1745 | entrI = entrBegin; | 1751 | entrI = entrBegin; |
1746 | while (entrI != entrEnd) { | 1752 | while (entrI != entrEnd) { |
1747 | if (entrI->lockStat == true) { | 1753 | if (entrI->lockStat == true) { |
1748 | mustUnlock = true; | 1754 | mustUnlock = true; |
1749 | break; | 1755 | break; |
1750 | } | 1756 | } |
1751 | ++entrI; | 1757 | ++entrI; |
1752 | } | 1758 | } |
1753 | if (mustUnlock) | 1759 | if (mustUnlock) |
1754 | break; | 1760 | break; |
1755 | ++catI; | 1761 | ++catI; |
1756 | } | 1762 | } |
1757 | } | 1763 | } |
1758 | if (!mustUnlock) { | 1764 | if (!mustUnlock) { |
1759 | // nothing to do. | 1765 | // nothing to do. |
1760 | timer()->stop(DocTimer::id_autoLockTimer); | 1766 | timer()->stop(DocTimer::id_autoLockTimer); |
1761 | printDebug("unlockAll_tempoary(): nothing to do."); | 1767 | printDebug("unlockAll_tempoary(): nothing to do."); |
1762 | return true; | 1768 | return true; |
1763 | } else if (!wasDeepLocked) { | 1769 | } else if (!wasDeepLocked) { |
1764 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1770 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1765 | currentPw != "") { | 1771 | currentPw != "") { |
1766 | /* we can't unlock without mpw, so | 1772 | /* we can't unlock without mpw, so |
1767 | * we need to ask for it. | 1773 | * we need to ask for it. |
1768 | */ | 1774 | */ |
1769 | QString pw; | 1775 | QString pw; |
1770 | while (1) { | 1776 | while (1) { |
1771 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1777 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1772 | if (pw == "") { | 1778 | if (pw == "") { |
1773 | return false; | 1779 | return false; |
1774 | } else if (pw == currentPw) { | 1780 | } else if (pw == currentPw) { |
1775 | break; | 1781 | break; |
1776 | } | 1782 | } |
1777 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1783 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1778 | } | 1784 | } |
1779 | } | 1785 | } |
1780 | } | 1786 | } |
1781 | timer()->stop(DocTimer::id_autoLockTimer); | 1787 | timer()->stop(DocTimer::id_autoLockTimer); |
1782 | oldLockStates = new vector< vector<bool> >; | 1788 | oldLockStates = new vector< vector<bool> >; |
1783 | vector<bool> tmp_vec; | 1789 | vector<bool> tmp_vec; |
1784 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1790 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1785 | catEnd = dti.dta.end(), | 1791 | catEnd = dti.dta.end(), |
1786 | catI = catBegin; | 1792 | catI = catBegin; |
1787 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1793 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1788 | while (catI != catEnd) { | 1794 | while (catI != catEnd) { |
1789 | entrBegin = catI->d.begin(); | 1795 | entrBegin = catI->d.begin(); |
1790 | entrEnd = catI->d.end(); | 1796 | entrEnd = catI->d.end(); |
1791 | entrI = entrBegin; | 1797 | entrI = entrBegin; |
1792 | while (entrI != entrEnd) { | 1798 | while (entrI != entrEnd) { |
1793 | if (!wasDeepLocked) { | 1799 | if (!wasDeepLocked) { |
1794 | tmp_vec.push_back(entrI->lockStat); | 1800 | tmp_vec.push_back(entrI->lockStat); |
1795 | } | 1801 | } |
1796 | entrI->lockStat = false; | 1802 | entrI->lockStat = false; |
1797 | ++entrI; | 1803 | ++entrI; |
1798 | } | 1804 | } |
1799 | if (!wasDeepLocked) { | 1805 | if (!wasDeepLocked) { |
1800 | oldLockStates->push_back(tmp_vec); | 1806 | oldLockStates->push_back(tmp_vec); |
1801 | tmp_vec.clear(); | 1807 | tmp_vec.clear(); |
1802 | } | 1808 | } |
1803 | ++catI; | 1809 | ++catI; |
1804 | } | 1810 | } |
1805 | printDebug("tempoary unlocked dta."); | 1811 | printDebug("tempoary unlocked dta."); |
1806 | } | 1812 | } |
1807 | 1813 | ||
1808 | return true; | 1814 | return true; |
1809 | } | 1815 | } |
1810 | 1816 | ||
1811 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1817 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1812 | { | 1818 | { |
1813 | PwMerror ret; | 1819 | PwMerror ret; |
1814 | /* NOTE: saveDoc() depends on this function to return | 1820 | /* NOTE: saveDoc() depends on this function to return |
1815 | * e_success if saveToFile == false | 1821 | * e_success if saveToFile == false |
1816 | */ | 1822 | */ |
1817 | 1823 | ||
1818 | if (lock) { | 1824 | if (lock) { |
1819 | if (isDeepLocked()) | 1825 | if (isDeepLocked()) |
1820 | return e_lock; | 1826 | return e_lock; |
1821 | if (saveToFile) { | 1827 | if (saveToFile) { |
1822 | if (isDocEmpty()) | 1828 | if (isDocEmpty()) |
1823 | return e_docIsEmpty; | 1829 | return e_docIsEmpty; |
1824 | ret = saveDoc(conf()->confGlobCompression()); | 1830 | ret = saveDoc(conf()->confGlobCompression()); |
1825 | if (ret == e_filename) { | 1831 | if (ret == e_filename) { |
1826 | /* the doc wasn't saved to a file | 1832 | /* the doc wasn't saved to a file |
1827 | * by the user, yet. | 1833 | * by the user, yet. |
1828 | */ | 1834 | */ |
1829 | cantDeeplock_notSavedMsgBox(); | 1835 | cantDeeplock_notSavedMsgBox(); |
1830 | return e_docNotSaved; | 1836 | return e_docNotSaved; |
1831 | } else if (ret != e_success) { | 1837 | } else if (ret != e_success) { |
1832 | return e_lock; | 1838 | return e_lock; |
1833 | } | 1839 | } |
1834 | } | 1840 | } |
1835 | timer()->stop(DocTimer::id_autoLockTimer); | 1841 | timer()->stop(DocTimer::id_autoLockTimer); |
1836 | clearDoc(); | 1842 | clearDoc(); |
1837 | PwMDataItem d; | 1843 | PwMDataItem d; |
1838 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1844 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1839 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1845 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1840 | d.listViewPos = 0; | 1846 | d.listViewPos = 0; |
1841 | addEntry(DEFAULT_CATEGORY, &d, true); | 1847 | addEntry(DEFAULT_CATEGORY, &d, true); |
1842 | lockAt(DEFAULT_CATEGORY, 0, true); | 1848 | lockAt(DEFAULT_CATEGORY, 0, true); |
1843 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1849 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1844 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1850 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1845 | } else { | 1851 | } else { |
1846 | if (!isDeepLocked()) | 1852 | if (!isDeepLocked()) |
1847 | return e_lock; | 1853 | return e_lock; |
1848 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1854 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1849 | ? 0 : 1); | 1855 | ? 0 : 1); |
1850 | if (ret == e_wrongPw) { | 1856 | if (ret == e_wrongPw) { |
1851 | return e_wrongPw; | 1857 | return e_wrongPw; |
1852 | } else if (ret != e_success) { | 1858 | } else if (ret != e_success) { |
1853 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1859 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1854 | + tostr(static_cast<int>(ret))); | 1860 | + tostr(static_cast<int>(ret))); |
1855 | return e_lock; | 1861 | return e_lock; |
1856 | } | 1862 | } |
1857 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1863 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1858 | timer()->start(DocTimer::id_autoLockTimer); | 1864 | timer()->start(DocTimer::id_autoLockTimer); |
1859 | } | 1865 | } |
1860 | 1866 | ||
1861 | emitDataChanged(this); | 1867 | emitDataChanged(this); |
1862 | return e_success; | 1868 | return e_success; |
1863 | } | 1869 | } |
1864 | 1870 | ||
1865 | void PwMDoc::_deepUnlock() | 1871 | void PwMDoc::_deepUnlock() |
1866 | { | 1872 | { |
1867 | deepLock(false); | 1873 | deepLock(false); |
1868 | } | 1874 | } |
1869 | 1875 | ||
1870 | void PwMDoc::clearDoc() | 1876 | void PwMDoc::clearDoc() |
1871 | { | 1877 | { |
1872 | dti.clear(); | 1878 | dti.clear(); |
1873 | PwMCategoryItem d; | 1879 | PwMCategoryItem d; |
1874 | d.name = DEFAULT_CATEGORY.latin1(); | 1880 | d.name = DEFAULT_CATEGORY.latin1(); |
1875 | dti.dta.push_back(d); | 1881 | dti.dta.push_back(d); |
1876 | currentPw = ""; | 1882 | currentPw = ""; |
1877 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1883 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1878 | } | 1884 | } |
1879 | 1885 | ||
1880 | void PwMDoc::changeCurrentPw() | 1886 | void PwMDoc::changeCurrentPw() |
1881 | { | 1887 | { |
1882 | if (currentPw == "") | 1888 | if (currentPw == "") |
1883 | return; // doc hasn't been saved. No mpw available. | 1889 | return; // doc hasn't been saved. No mpw available. |
1884 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1890 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1885 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1891 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1886 | if (pw == "") | 1892 | if (pw == "") |
1887 | return; | 1893 | return; |
1888 | if (useChipcard) | 1894 | if (useChipcard) |
1889 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1895 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1890 | else | 1896 | else |
1891 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1897 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1892 | setCurrentPw(pw); | 1898 | setCurrentPw(pw); |
1893 | } | 1899 | } |
1894 | 1900 | ||
1895 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1901 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1896 | int pos) | 1902 | int pos) |
1897 | { | 1903 | { |
1898 | unsigned int cat = 0; | 1904 | unsigned int cat = 0; |
1899 | 1905 | ||
1900 | if (!findCategory(category, &cat)) { | 1906 | if (!findCategory(category, &cat)) { |
1901 | BUG(); | 1907 | BUG(); |
1902 | return; | 1908 | return; |
1903 | } | 1909 | } |
1904 | setListViewPos(cat, index, pos); | 1910 | setListViewPos(cat, index, pos); |
1905 | } | 1911 | } |
1906 | 1912 | ||
1907 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1913 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1908 | int pos) | 1914 | int pos) |
1909 | { | 1915 | { |
1910 | dti.dta[category].d[index].listViewPos = pos; | 1916 | dti.dta[category].d[index].listViewPos = pos; |
1911 | 1917 | ||
1912 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1918 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1913 | * get's called when it shouldn't. It's because PwMView assumes | 1919 | * get's called when it shouldn't. It's because PwMView assumes |
1914 | * the user resorted the UI on behalf of signal layoutChanged(). | 1920 | * the user resorted the UI on behalf of signal layoutChanged(). |
1915 | * This is somewhat broken and incorrect, but I've no other | 1921 | * This is somewhat broken and incorrect, but I've no other |
1916 | * solution for now. | 1922 | * solution for now. |
1917 | */ | 1923 | */ |
1918 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1924 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1919 | } | 1925 | } |
1920 | 1926 | ||
1921 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1927 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1922 | { | 1928 | { |
1923 | unsigned int cat = 0; | 1929 | unsigned int cat = 0; |
1924 | 1930 | ||
1925 | if (!findCategory(category, &cat)) { | 1931 | if (!findCategory(category, &cat)) { |
1926 | BUG(); | 1932 | BUG(); |
1927 | return -1; | 1933 | return -1; |
1928 | } | 1934 | } |
1929 | 1935 | ||
1930 | return dti.dta[cat].d[index].listViewPos; | 1936 | return dti.dta[cat].d[index].listViewPos; |
1931 | } | 1937 | } |
1932 | 1938 | ||
1933 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1939 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1934 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1940 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1935 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1941 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1936 | { | 1942 | { |
1937 | PWM_ASSERT(foundPositions); | 1943 | PWM_ASSERT(foundPositions); |
1938 | PWM_ASSERT(searchIn); | 1944 | PWM_ASSERT(searchIn); |
1939 | foundPositions->clear(); | 1945 | foundPositions->clear(); |
1940 | 1946 | ||
1941 | unsigned int i, entries = numEntries(category); | 1947 | unsigned int i, entries = numEntries(category); |
1942 | for (i = 0; i < entries; ++i) { | 1948 | for (i = 0; i < entries; ++i) { |
1943 | if (searchIn & SEARCH_IN_DESC) { | 1949 | if (searchIn & SEARCH_IN_DESC) { |
1944 | if (!compareString(find.desc, dti.dta[category].d[i].desc, | 1950 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1945 | caseSensitive, exactWordMatch)) { | 1951 | caseSensitive, exactWordMatch)) { |
1946 | continue; | 1952 | continue; |
1947 | } | 1953 | } |
1948 | } | 1954 | } |
1949 | if (searchIn & SEARCH_IN_NAME) { | 1955 | if (searchIn & SEARCH_IN_NAME) { |
1950 | if (!compareString(find.name, dti.dta[category].d[i].name, | 1956 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1951 | caseSensitive, exactWordMatch)) { | 1957 | caseSensitive, exactWordMatch)) { |
1952 | continue; | 1958 | continue; |
1953 | } | 1959 | } |
1954 | } | 1960 | } |
1955 | if (searchIn & SEARCH_IN_PW) { | 1961 | if (searchIn & SEARCH_IN_PW) { |
1956 | bool wasLocked = isLocked(category, i); | 1962 | bool wasLocked = isLocked(category, i); |
1957 | getDataChangedLock(); | 1963 | getDataChangedLock(); |
1958 | lockAt(category, i, false); | 1964 | lockAt(category, i, false); |
1959 | if (!compareString(find.pw, dti.dta[category].d[i].pw, | 1965 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1960 | caseSensitive, exactWordMatch)) { | 1966 | caseSensitive, exactWordMatch)) { |
1961 | lockAt(category, i, wasLocked); | 1967 | lockAt(category, i, wasLocked); |
1962 | putDataChangedLock(); | 1968 | putDataChangedLock(); |
1963 | continue; | 1969 | continue; |
1964 | } | 1970 | } |
1965 | lockAt(category, i, wasLocked); | 1971 | lockAt(category, i, wasLocked); |
1966 | putDataChangedLock(); | 1972 | putDataChangedLock(); |
1967 | } | 1973 | } |
1968 | if (searchIn & SEARCH_IN_COMMENT) { | 1974 | if (searchIn & SEARCH_IN_COMMENT) { |
1969 | if (!compareString(find.comment, dti.dta[category].d[i].comment, | 1975 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1970 | caseSensitive, exactWordMatch)) { | 1976 | caseSensitive, exactWordMatch)) { |
1971 | continue; | 1977 | continue; |
1972 | } | 1978 | } |
1973 | } | 1979 | } |
1974 | if (searchIn & SEARCH_IN_URL) { | 1980 | if (searchIn & SEARCH_IN_URL) { |
1975 | if (!compareString(find.url, dti.dta[category].d[i].url, | 1981 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1976 | caseSensitive, exactWordMatch)) { | 1982 | caseSensitive, exactWordMatch)) { |
1977 | continue; | 1983 | continue; |
1978 | } | 1984 | } |
1979 | } | 1985 | } |
1980 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1986 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1981 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, | 1987 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1982 | caseSensitive, exactWordMatch)) { | 1988 | caseSensitive, exactWordMatch)) { |
1983 | continue; | 1989 | continue; |
1984 | } | 1990 | } |
1985 | } | 1991 | } |
1986 | 1992 | ||
1987 | // all selected "searchIn" matched. | 1993 | // all selected "searchIn" matched. |
1988 | foundPositions->push_back(i); | 1994 | foundPositions->push_back(i); |
1989 | if (breakAfterFound) | 1995 | if (breakAfterFound) |
1990 | break; | 1996 | break; |
1991 | } | 1997 | } |
1992 | 1998 | ||
1993 | if (sortByLvp && foundPositions->size() > 1) { | 1999 | if (sortByLvp && foundPositions->size() > 1) { |
1994 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 2000 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
1995 | unsigned int /* lvp-pos */> > tmp_vec; | 2001 | unsigned int /* lvp-pos */> > tmp_vec; |
1996 | 2002 | ||
1997 | unsigned int i, items = foundPositions->size(); | 2003 | unsigned int i, items = foundPositions->size(); |
1998 | pair<unsigned int, unsigned int> tmp_pair; | 2004 | pair<unsigned int, unsigned int> tmp_pair; |
1999 | for (i = 0; i < items; ++i) { | 2005 | for (i = 0; i < items; ++i) { |
2000 | tmp_pair.first = (*foundPositions)[i]; | 2006 | tmp_pair.first = (*foundPositions)[i]; |
2001 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; | 2007 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
2002 | tmp_vec.push_back(tmp_pair); | 2008 | tmp_vec.push_back(tmp_pair); |
2003 | } | 2009 | } |
2004 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 2010 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
2005 | foundPositions->clear(); | 2011 | foundPositions->clear(); |
2006 | for (i = 0; i < items; ++i) { | 2012 | for (i = 0; i < items; ++i) { |
2007 | foundPositions->push_back(tmp_vec[i].first); | 2013 | foundPositions->push_back(tmp_vec[i].first); |
2008 | } | 2014 | } |
2009 | } | 2015 | } |
2010 | } | 2016 | } |
2011 | 2017 | ||
2012 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2018 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2013 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2019 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2014 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2020 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2015 | { | 2021 | { |
2016 | PWM_ASSERT(foundPositions); | 2022 | PWM_ASSERT(foundPositions); |
2017 | unsigned int cat = 0; | 2023 | unsigned int cat = 0; |
2018 | 2024 | ||
2019 | if (!findCategory(category, &cat)) { | 2025 | if (!findCategory(category, &cat)) { |
2020 | foundPositions->clear(); | 2026 | foundPositions->clear(); |
2021 | return; | 2027 | return; |
2022 | } | 2028 | } |
2023 | 2029 | ||
2024 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2030 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2025 | caseSensitive, exactWordMatch, sortByLvp); | 2031 | caseSensitive, exactWordMatch, sortByLvp); |
2026 | } | 2032 | } |
2027 | 2033 | ||
2028 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2034 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2029 | bool exactWordMatch) | 2035 | bool exactWordMatch) |
2030 | { | 2036 | { |
2031 | QString _s1(s1.c_str()); | 2037 | QString _s1(s1.c_str()); |
2032 | QString _s2(s2.c_str()); | 2038 | QString _s2(s2.c_str()); |
2033 | if (!caseSensitive) { | 2039 | if (!caseSensitive) { |
2034 | _s1 = _s1.lower(); | 2040 | _s1 = _s1.lower(); |
2035 | _s2 = _s2.lower(); | 2041 | _s2 = _s2.lower(); |
2036 | } | 2042 | } |
2037 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2043 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2038 | return true; | 2044 | return true; |
2039 | return false; | 2045 | return false; |
2040 | } | 2046 | } |
2041 | 2047 | ||
2042 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2048 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2043 | { | 2049 | { |
2044 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2050 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2045 | end = dti.dta.end(); | 2051 | end = dti.dta.end(); |
2046 | while (i != end) { | 2052 | while (i != end) { |
2047 | if ((*i).name == name.latin1()) { | 2053 | if ((*i).name == name.latin1()) { |
2048 | if (index) { | 2054 | if (index) { |
2049 | *index = i - dti.dta.begin(); | 2055 | *index = i - dti.dta.begin(); |
2050 | } | 2056 | } |
2051 | return true; | 2057 | return true; |
2052 | } | 2058 | } |
2053 | ++i; | 2059 | ++i; |
2054 | } | 2060 | } |
2055 | return false; | 2061 | return false; |
2056 | } | 2062 | } |
2057 | 2063 | ||
2058 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2064 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2059 | { | 2065 | { |
@@ -2358,1134 +2364,1127 @@ PwMerror PwMDoc::exportToText(const QString *file) | |||
2358 | for (i = 0; i < numCat; ++i) { | 2364 | for (i = 0; i < numCat; ++i) { |
2359 | numEnt = numEntries(i); | 2365 | numEnt = numEntries(i); |
2360 | 2366 | ||
2361 | exp = "\n== Category: "; | 2367 | exp = "\n== Category: "; |
2362 | exp += dti.dta[i].name; | 2368 | exp += dti.dta[i].name; |
2363 | exp += " ==\n"; | 2369 | exp += " ==\n"; |
2364 | #ifndef PWM_EMBEDDED | 2370 | #ifndef PWM_EMBEDDED |
2365 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2371 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2366 | unlockAll_tempoary(true); | 2372 | unlockAll_tempoary(true); |
2367 | f.close(); | 2373 | f.close(); |
2368 | return e_writeFile; | 2374 | return e_writeFile; |
2369 | } | 2375 | } |
2370 | #else | 2376 | #else |
2371 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2377 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2372 | unlockAll_tempoary(true); | 2378 | unlockAll_tempoary(true); |
2373 | f.close(); | 2379 | f.close(); |
2374 | return e_writeFile; | 2380 | return e_writeFile; |
2375 | } | 2381 | } |
2376 | #endif | 2382 | #endif |
2377 | for (j = 0; j < numEnt; ++j) { | 2383 | for (j = 0; j < numEnt; ++j) { |
2378 | exp = "\n-- "; | 2384 | exp = "\n-- "; |
2379 | exp += dti.dta[i].d[j].desc; | 2385 | exp += dti.dta[i].d[j].desc; |
2380 | exp += " --\n"; | 2386 | exp += " --\n"; |
2381 | 2387 | ||
2382 | exp += i18n("Username: ").latin1(); | 2388 | exp += i18n("Username: ").latin1(); |
2383 | exp += dti.dta[i].d[j].name; | 2389 | exp += dti.dta[i].d[j].name; |
2384 | exp += "\n"; | 2390 | exp += "\n"; |
2385 | 2391 | ||
2386 | exp += i18n("Password: ").latin1(); | 2392 | exp += i18n("Password: ").latin1(); |
2387 | exp += dti.dta[i].d[j].pw; | 2393 | exp += dti.dta[i].d[j].pw; |
2388 | exp += "\n"; | 2394 | exp += "\n"; |
2389 | 2395 | ||
2390 | exp += i18n("Comment: ").latin1(); | 2396 | exp += i18n("Comment: ").latin1(); |
2391 | exp += dti.dta[i].d[j].comment; | 2397 | exp += dti.dta[i].d[j].comment; |
2392 | exp += "\n"; | 2398 | exp += "\n"; |
2393 | 2399 | ||
2394 | exp += i18n("URL: ").latin1(); | 2400 | exp += i18n("URL: ").latin1(); |
2395 | exp += dti.dta[i].d[j].url; | 2401 | exp += dti.dta[i].d[j].url; |
2396 | exp += "\n"; | 2402 | exp += "\n"; |
2397 | 2403 | ||
2398 | exp += i18n("Launcher: ").latin1(); | 2404 | exp += i18n("Launcher: ").latin1(); |
2399 | exp += dti.dta[i].d[j].launcher; | 2405 | exp += dti.dta[i].d[j].launcher; |
2400 | exp += "\n"; | 2406 | exp += "\n"; |
2401 | 2407 | ||
2402 | #ifndef PWM_EMBEDDED | 2408 | #ifndef PWM_EMBEDDED |
2403 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2409 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2404 | unlockAll_tempoary(true); | 2410 | unlockAll_tempoary(true); |
2405 | f.close(); | 2411 | f.close(); |
2406 | return e_writeFile; | 2412 | return e_writeFile; |
2407 | } | 2413 | } |
2408 | #else | 2414 | #else |
2409 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2415 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2410 | unlockAll_tempoary(true); | 2416 | unlockAll_tempoary(true); |
2411 | f.close(); | 2417 | f.close(); |
2412 | return e_writeFile; | 2418 | return e_writeFile; |
2413 | } | 2419 | } |
2414 | #endif | 2420 | #endif |
2415 | } | 2421 | } |
2416 | } | 2422 | } |
2417 | unlockAll_tempoary(true); | 2423 | unlockAll_tempoary(true); |
2418 | f.close(); | 2424 | f.close(); |
2419 | 2425 | ||
2420 | return e_success; | 2426 | return e_success; |
2421 | } | 2427 | } |
2422 | 2428 | ||
2423 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2429 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2424 | { | 2430 | { |
2425 | PWM_ASSERT(file); | 2431 | PWM_ASSERT(file); |
2426 | if (format == 0) | 2432 | if (format == 0) |
2427 | return importText_PwM(file); | 2433 | return importText_PwM(file); |
2428 | else if (format == -1) { | 2434 | else if (format == -1) { |
2429 | // probe for all formats | 2435 | // probe for all formats |
2430 | if (importText_PwM(file) == e_success) | 2436 | if (importText_PwM(file) == e_success) |
2431 | return e_success; | 2437 | return e_success; |
2432 | dti.clear(); | 2438 | dti.clear(); |
2433 | emitDataChanged(this); | 2439 | emitDataChanged(this); |
2434 | // add next format here... | 2440 | // add next format here... |
2435 | return e_fileFormat; | 2441 | return e_fileFormat; |
2436 | } | 2442 | } |
2437 | return e_invalidArg; | 2443 | return e_invalidArg; |
2438 | } | 2444 | } |
2439 | 2445 | ||
2440 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2446 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2441 | { | 2447 | { |
2442 | #ifndef PWM_EMBEDDED | 2448 | #ifndef PWM_EMBEDDED |
2443 | PWM_ASSERT(file); | 2449 | PWM_ASSERT(file); |
2444 | FILE *f; | 2450 | FILE *f; |
2445 | int tmp; | 2451 | int tmp; |
2446 | ssize_t ret; | 2452 | ssize_t ret; |
2447 | string curCat; | 2453 | string curCat; |
2448 | unsigned int entriesRead = 0; | 2454 | unsigned int entriesRead = 0; |
2449 | PwMDataItem currItem; | 2455 | PwMDataItem currItem; |
2450 | f = fopen(file->latin1(), "r"); | 2456 | f = fopen(file->latin1(), "r"); |
2451 | if (!f) | 2457 | if (!f) |
2452 | return e_openFile; | 2458 | return e_openFile; |
2453 | size_t ch_tmp_size = 1024; | 2459 | size_t ch_tmp_size = 1024; |
2454 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2460 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2455 | if (!ch_tmp) { | 2461 | if (!ch_tmp) { |
2456 | fclose(f); | 2462 | fclose(f); |
2457 | return e_outOfMem; | 2463 | return e_outOfMem; |
2458 | } | 2464 | } |
2459 | 2465 | ||
2460 | // - check header | 2466 | // - check header |
2461 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2467 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2462 | goto formatError; | 2468 | goto formatError; |
2463 | // check version-string and return version in "ch_tmp". | 2469 | // check version-string and return version in "ch_tmp". |
2464 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2470 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2465 | // header not recognized as PwM generated header | 2471 | // header not recognized as PwM generated header |
2466 | goto formatError; | 2472 | goto formatError; |
2467 | } | 2473 | } |
2468 | // set filepointer behind version-string-line previously checked | 2474 | // set filepointer behind version-string-line previously checked |
2469 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2475 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2470 | goto formatError; | 2476 | goto formatError; |
2471 | // skip next line containing the build-date | 2477 | // skip next line containing the build-date |
2472 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2478 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2473 | goto formatError; | 2479 | goto formatError; |
2474 | // read header termination line | 2480 | // read header termination line |
2475 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2481 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2476 | goto formatError; | 2482 | goto formatError; |
2477 | if (strcmp(ch_tmp, "==============================\n")) | 2483 | if (strcmp(ch_tmp, "==============================\n")) |
2478 | goto formatError; | 2484 | goto formatError; |
2479 | 2485 | ||
2480 | // - read entries | 2486 | // - read entries |
2481 | do { | 2487 | do { |
2482 | // find beginning of next category | 2488 | // find beginning of next category |
2483 | do { | 2489 | do { |
2484 | tmp = fgetc(f); | 2490 | tmp = fgetc(f); |
2485 | } while (tmp == '\n' && tmp != EOF); | 2491 | } while (tmp == '\n' && tmp != EOF); |
2486 | if (tmp == EOF) | 2492 | if (tmp == EOF) |
2487 | break; | 2493 | break; |
2488 | 2494 | ||
2489 | // decrement filepos by one | 2495 | // decrement filepos by one |
2490 | fseek(f, -1, SEEK_CUR); | 2496 | fseek(f, -1, SEEK_CUR); |
2491 | // read cat-name | 2497 | // read cat-name |
2492 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2498 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2493 | goto formatError; | 2499 | goto formatError; |
2494 | // check cat-name format | 2500 | // check cat-name format |
2495 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2501 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2496 | goto formatError; | 2502 | goto formatError; |
2497 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2503 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2498 | goto formatError; | 2504 | goto formatError; |
2499 | // copy cat-name | 2505 | // copy cat-name |
2500 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2506 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2501 | 2507 | ||
2502 | do { | 2508 | do { |
2503 | // find beginning of next entry | 2509 | // find beginning of next entry |
2504 | do { | 2510 | do { |
2505 | tmp = fgetc(f); | 2511 | tmp = fgetc(f); |
2506 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2512 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2507 | if (tmp == EOF) | 2513 | if (tmp == EOF) |
2508 | break; | 2514 | break; |
2509 | if (tmp == '=') { | 2515 | if (tmp == '=') { |
2510 | fseek(f, -1, SEEK_CUR); | 2516 | fseek(f, -1, SEEK_CUR); |
2511 | break; | 2517 | break; |
2512 | } | 2518 | } |
2513 | // decrement filepos by one | 2519 | // decrement filepos by one |
2514 | fseek(f, -1, SEEK_CUR); | 2520 | fseek(f, -1, SEEK_CUR); |
2515 | // read desc-line | 2521 | // read desc-line |
2516 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2522 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2517 | goto formatError; | 2523 | goto formatError; |
2518 | // check desc-line format | 2524 | // check desc-line format |
2519 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2525 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2520 | goto formatError; | 2526 | goto formatError; |
2521 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2527 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2522 | goto formatError; | 2528 | goto formatError; |
2523 | // add desc-line | 2529 | // add desc-line |
2524 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2530 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2525 | 2531 | ||
2526 | // read username-line | 2532 | // read username-line |
2527 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2528 | goto formatError; | 2534 | goto formatError; |
2529 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2530 | goto formatError; | 2536 | goto formatError; |
2531 | 2537 | ||
2532 | // read pw-line | 2538 | // read pw-line |
2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2534 | goto formatError; | 2540 | goto formatError; |
2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2536 | goto formatError; | 2542 | goto formatError; |
2537 | 2543 | ||
2538 | // read comment-line | 2544 | // read comment-line |
2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2540 | goto formatError; | 2546 | goto formatError; |
2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2542 | goto formatError; | 2548 | goto formatError; |
2543 | 2549 | ||
2544 | // read URL-line | 2550 | // read URL-line |
2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2551 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2546 | goto formatError; | 2552 | goto formatError; |
2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2553 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2548 | goto formatError; | 2554 | goto formatError; |
2549 | 2555 | ||
2550 | // read launcher-line | 2556 | // read launcher-line |
2551 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2557 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2552 | goto formatError; | 2558 | goto formatError; |
2553 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2559 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2554 | goto formatError; | 2560 | goto formatError; |
2555 | 2561 | ||
2556 | currItem.lockStat = true; | 2562 | currItem.lockStat = true; |
2557 | currItem.listViewPos = -1; | 2563 | currItem.listViewPos = -1; |
2558 | addEntry(curCat.c_str(), &currItem, true); | 2564 | addEntry(curCat.c_str(), &currItem, true); |
2559 | ++entriesRead; | 2565 | ++entriesRead; |
2560 | } while (1); | 2566 | } while (1); |
2561 | } while (1); | 2567 | } while (1); |
2562 | if (!entriesRead) | 2568 | if (!entriesRead) |
2563 | goto formatError; | 2569 | goto formatError; |
2564 | 2570 | ||
2565 | free(ch_tmp); | 2571 | free(ch_tmp); |
2566 | fclose(f); | 2572 | fclose(f); |
2567 | flagDirty(); | 2573 | flagDirty(); |
2568 | return e_success; | 2574 | return e_success; |
2569 | 2575 | ||
2570 | formatError: | 2576 | formatError: |
2571 | free(ch_tmp); | 2577 | free(ch_tmp); |
2572 | fclose(f); | 2578 | fclose(f); |
2573 | return e_fileFormat; | 2579 | return e_fileFormat; |
2574 | #else | 2580 | #else |
2575 | PWM_ASSERT(file); | 2581 | PWM_ASSERT(file); |
2576 | QFile f(file->latin1()); | 2582 | QFile f(file->latin1()); |
2577 | int tmp; | 2583 | int tmp; |
2578 | ssize_t ret; | 2584 | ssize_t ret; |
2579 | string curCat; | 2585 | string curCat; |
2580 | unsigned int entriesRead = 0; | 2586 | unsigned int entriesRead = 0; |
2581 | PwMDataItem currItem; | 2587 | PwMDataItem currItem; |
2582 | bool res = f.open(IO_ReadOnly); | 2588 | bool res = f.open(IO_ReadOnly); |
2583 | if (res == false) | 2589 | if (res == false) |
2584 | return e_openFile; | 2590 | return e_openFile; |
2585 | 2591 | ||
2586 | unsigned int ch_tmp_size = 1024; | 2592 | unsigned int ch_tmp_size = 1024; |
2587 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2593 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2588 | if (!ch_tmp) { | 2594 | if (!ch_tmp) { |
2589 | f.close(); | 2595 | f.close(); |
2590 | return e_outOfMem; | 2596 | return e_outOfMem; |
2591 | } | 2597 | } |
2592 | 2598 | ||
2593 | // - check header | 2599 | // - check header |
2594 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. | 2600 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. |
2595 | goto formatError; | 2601 | goto formatError; |
2596 | 2602 | ||
2597 | //US read fileversion first, then check if ok. | 2603 | //US read fileversion first, then check if ok. |
2598 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2604 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2599 | goto formatError; | 2605 | goto formatError; |
2600 | 2606 | ||
2601 | // check version-string and return version in "ch_tmp". | 2607 | // check version-string and return version in "ch_tmp". |
2602 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2608 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2603 | //US // header not recognized as PwM generated header | 2609 | //US // header not recognized as PwM generated header |
2604 | //US goto formatError; | 2610 | //US goto formatError; |
2605 | //US} | 2611 | //US} |
2606 | //US set filepointer behind version-string-line previously checked | 2612 | //US set filepointer behind version-string-line previously checked |
2607 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2613 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2608 | //US goto formatError; | 2614 | //US goto formatError; |
2609 | // skip next line containing the build-date | 2615 | // skip next line containing the build-date |
2610 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2616 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2611 | goto formatError; | 2617 | goto formatError; |
2612 | // read header termination line | 2618 | // read header termination line |
2613 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2619 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2614 | goto formatError; | 2620 | goto formatError; |
2615 | if (strcmp(ch_tmp, "==============================\n")) | 2621 | if (strcmp(ch_tmp, "==============================\n")) |
2616 | goto formatError; | 2622 | goto formatError; |
2617 | 2623 | ||
2618 | // - read entries | 2624 | // - read entries |
2619 | do { | 2625 | do { |
2620 | // find beginning of next category | 2626 | // find beginning of next category |
2621 | do { | 2627 | do { |
2622 | tmp = f.getch(); | 2628 | tmp = f.getch(); |
2623 | } while (tmp == '\n' && tmp != EOF); | 2629 | } while (tmp == '\n' && tmp != EOF); |
2624 | if (tmp == EOF) | 2630 | if (tmp == EOF) |
2625 | break; | 2631 | break; |
2626 | 2632 | ||
2627 | // decrement filepos by one | 2633 | // decrement filepos by one |
2628 | f.at(f.at()-1); | 2634 | f.at(f.at()-1); |
2629 | // read cat-name | 2635 | // read cat-name |
2630 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2636 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2631 | goto formatError; | 2637 | goto formatError; |
2632 | // check cat-name format | 2638 | // check cat-name format |
2633 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2639 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2634 | goto formatError; | 2640 | goto formatError; |
2635 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2641 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2636 | goto formatError; | 2642 | goto formatError; |
2637 | // copy cat-name | 2643 | // copy cat-name |
2638 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2644 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2639 | 2645 | ||
2640 | do { | 2646 | do { |
2641 | // find beginning of next entry | 2647 | // find beginning of next entry |
2642 | do { | 2648 | do { |
2643 | tmp = f.getch(); | 2649 | tmp = f.getch(); |
2644 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2650 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2645 | if (tmp == EOF) | 2651 | if (tmp == EOF) |
2646 | break; | 2652 | break; |
2647 | if (tmp == '=') { | 2653 | if (tmp == '=') { |
2648 | f.at(f.at()-1); | 2654 | f.at(f.at()-1); |
2649 | break; | 2655 | break; |
2650 | } | 2656 | } |
2651 | // decrement filepos by one | 2657 | // decrement filepos by one |
2652 | f.at(f.at()-1); | 2658 | f.at(f.at()-1); |
2653 | // read desc-line | 2659 | // read desc-line |
2654 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2660 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2655 | goto formatError; | 2661 | goto formatError; |
2656 | // check desc-line format | 2662 | // check desc-line format |
2657 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2663 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2658 | goto formatError; | 2664 | goto formatError; |
2659 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2665 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2660 | goto formatError; | 2666 | goto formatError; |
2661 | // add desc-line | 2667 | // add desc-line |
2662 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2668 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2663 | 2669 | ||
2664 | // read username-line | 2670 | // read username-line |
2665 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2671 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2666 | goto formatError; | 2672 | goto formatError; |
2667 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2673 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2668 | goto formatError; | 2674 | goto formatError; |
2669 | 2675 | ||
2670 | // read pw-line | 2676 | // read pw-line |
2671 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2677 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2672 | goto formatError; | 2678 | goto formatError; |
2673 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2679 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2674 | goto formatError; | 2680 | goto formatError; |
2675 | 2681 | ||
2676 | // read comment-line | 2682 | // read comment-line |
2677 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2683 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2678 | goto formatError; | 2684 | goto formatError; |
2679 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2685 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2680 | goto formatError; | 2686 | goto formatError; |
2681 | 2687 | ||
2682 | // read URL-line | 2688 | // read URL-line |
2683 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2689 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2684 | goto formatError; | 2690 | goto formatError; |
2685 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2691 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2686 | goto formatError; | 2692 | goto formatError; |
2687 | 2693 | ||
2688 | // read launcher-line | 2694 | // read launcher-line |
2689 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2695 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2690 | goto formatError; | 2696 | goto formatError; |
2691 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2697 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2692 | goto formatError; | 2698 | goto formatError; |
2693 | 2699 | ||
2694 | currItem.lockStat = true; | 2700 | currItem.lockStat = true; |
2695 | currItem.listViewPos = -1; | 2701 | currItem.listViewPos = -1; |
2696 | addEntry(curCat.c_str(), &currItem, true); | 2702 | addEntry(curCat.c_str(), &currItem, true); |
2697 | ++entriesRead; | 2703 | ++entriesRead; |
2698 | } while (1); | 2704 | } while (1); |
2699 | } while (1); | 2705 | } while (1); |
2700 | if (!entriesRead) | 2706 | if (!entriesRead) |
2701 | goto formatError; | 2707 | goto formatError; |
2702 | 2708 | ||
2703 | free(ch_tmp); | 2709 | free(ch_tmp); |
2704 | f.close(); | 2710 | f.close(); |
2705 | flagDirty(); | 2711 | flagDirty(); |
2706 | return e_success; | 2712 | return e_success; |
2707 | 2713 | ||
2708 | formatError: | 2714 | formatError: |
2709 | free(ch_tmp); | 2715 | free(ch_tmp); |
2710 | f.close(); | 2716 | f.close(); |
2711 | return e_fileFormat; | 2717 | return e_fileFormat; |
2712 | 2718 | ||
2713 | #endif | 2719 | #endif |
2714 | 2720 | ||
2715 | } | 2721 | } |
2716 | 2722 | ||
2717 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2723 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2718 | { | 2724 | { |
2719 | PWM_ASSERT(in && out); | 2725 | PWM_ASSERT(in && out); |
2720 | ssize_t i = 0, len = in_size - 1; | 2726 | ssize_t i = 0, len = in_size - 1; |
2721 | while (i < len) { | 2727 | while (i < len) { |
2722 | if (in[i] == ':') | 2728 | if (in[i] == ':') |
2723 | break; | 2729 | break; |
2724 | ++i; | 2730 | ++i; |
2725 | } | 2731 | } |
2726 | i += 2; | 2732 | i += 2; |
2727 | *out = ""; | 2733 | *out = ""; |
2728 | out->append(in + i, in_size - i - 1); | 2734 | out->append(in + i, in_size - i - 1); |
2729 | return true; | 2735 | return true; |
2730 | } | 2736 | } |
2731 | 2737 | ||
2732 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2738 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2733 | { | 2739 | { |
2734 | PWM_ASSERT(file); | 2740 | PWM_ASSERT(file); |
2735 | GpasmanFile gp; | 2741 | GpasmanFile gp; |
2736 | int ret; | 2742 | int ret; |
2737 | 2743 | ||
2738 | if (!unlockAll_tempoary()) | 2744 | if (!unlockAll_tempoary()) |
2739 | return e_lock; | 2745 | return e_lock; |
2740 | 2746 | ||
2741 | QString gpmPassword; | 2747 | QString gpmPassword; |
2742 | while (1) { | 2748 | while (1) { |
2743 | gpmPassword = requestNewMpw(0); | 2749 | gpmPassword = requestNewMpw(0); |
2744 | if (gpmPassword == "") { | 2750 | if (gpmPassword == "") { |
2745 | unlockAll_tempoary(true); | 2751 | unlockAll_tempoary(true); |
2746 | return e_noPw; | 2752 | return e_noPw; |
2747 | } | 2753 | } |
2748 | if (gpmPassword.length() < 4) { | 2754 | if (gpmPassword.length() < 4) { |
2749 | gpmPwLenErrMsgBox(); | 2755 | gpmPwLenErrMsgBox(); |
2750 | } else { | 2756 | } else { |
2751 | break; | 2757 | break; |
2752 | } | 2758 | } |
2753 | } | 2759 | } |
2754 | 2760 | ||
2755 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2761 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2756 | if (ret != 1) { | 2762 | if (ret != 1) { |
2757 | unlockAll_tempoary(true); | 2763 | unlockAll_tempoary(true); |
2758 | return e_accessFile; | 2764 | return e_accessFile; |
2759 | } | 2765 | } |
2760 | 2766 | ||
2761 | char *entry[4]; | 2767 | char *entry[4]; |
2762 | unsigned int numCat = numCategories(), i; | 2768 | unsigned int numCat = numCategories(), i; |
2763 | unsigned int numEntr, j; | 2769 | unsigned int numEntr, j; |
2764 | int descLen, nameLen, pwLen, commentLen; | 2770 | int descLen, nameLen, pwLen, commentLen; |
2765 | for (i = 0; i < numCat; ++i) { | 2771 | for (i = 0; i < numCat; ++i) { |
2766 | numEntr = numEntries(i); | 2772 | numEntr = numEntries(i); |
2767 | for (j = 0; j < numEntr; ++j) { | 2773 | for (j = 0; j < numEntr; ++j) { |
2768 | descLen = dti.dta[i].d[j].desc.length(); | 2774 | descLen = dti.dta[i].d[j].desc.length(); |
2769 | nameLen = dti.dta[i].d[j].name.length(); | 2775 | nameLen = dti.dta[i].d[j].name.length(); |
2770 | pwLen = dti.dta[i].d[j].pw.length(); | 2776 | pwLen = dti.dta[i].d[j].pw.length(); |
2771 | commentLen = dti.dta[i].d[j].comment.length(); | 2777 | commentLen = dti.dta[i].d[j].comment.length(); |
2772 | entry[0] = new char[descLen + 1]; | 2778 | entry[0] = new char[descLen + 1]; |
2773 | entry[1] = new char[nameLen + 1]; | 2779 | entry[1] = new char[nameLen + 1]; |
2774 | entry[2] = new char[pwLen + 1]; | 2780 | entry[2] = new char[pwLen + 1]; |
2775 | entry[3] = new char[commentLen + 1]; | 2781 | entry[3] = new char[commentLen + 1]; |
2776 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); | 2782 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2777 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); | 2783 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2778 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); | 2784 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2779 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); | 2785 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2780 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2786 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2781 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2787 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2782 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2788 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2783 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2789 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2784 | 2790 | ||
2785 | ret = gp.save_entry(entry); | 2791 | ret = gp.save_entry(entry); |
2786 | if (ret == -1){ | 2792 | if (ret == -1){ |
2787 | delete [] entry[0]; | 2793 | delete [] entry[0]; |
2788 | delete [] entry[1]; | 2794 | delete [] entry[1]; |
2789 | delete [] entry[2]; | 2795 | delete [] entry[2]; |
2790 | delete [] entry[3]; | 2796 | delete [] entry[3]; |
2791 | gp.save_finalize(); | 2797 | gp.save_finalize(); |
2792 | unlockAll_tempoary(true); | 2798 | unlockAll_tempoary(true); |
2793 | return e_writeFile; | 2799 | return e_writeFile; |
2794 | } | 2800 | } |
2795 | 2801 | ||
2796 | delete [] entry[0]; | 2802 | delete [] entry[0]; |
2797 | delete [] entry[1]; | 2803 | delete [] entry[1]; |
2798 | delete [] entry[2]; | 2804 | delete [] entry[2]; |
2799 | delete [] entry[3]; | 2805 | delete [] entry[3]; |
2800 | } | 2806 | } |
2801 | } | 2807 | } |
2802 | unlockAll_tempoary(true); | 2808 | unlockAll_tempoary(true); |
2803 | if (gp.save_finalize() == -1) | 2809 | if (gp.save_finalize() == -1) |
2804 | return e_writeFile; | 2810 | return e_writeFile; |
2805 | 2811 | ||
2806 | return e_success; | 2812 | return e_success; |
2807 | } | 2813 | } |
2808 | 2814 | ||
2809 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2815 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2810 | { | 2816 | { |
2811 | PWM_ASSERT(file); | 2817 | PWM_ASSERT(file); |
2812 | QString pw = requestMpw(false); | 2818 | QString pw = requestMpw(false); |
2813 | if (pw == "") | 2819 | if (pw == "") |
2814 | return e_noPw; | 2820 | return e_noPw; |
2815 | GpasmanFile gp; | 2821 | GpasmanFile gp; |
2816 | int ret, i; | 2822 | int ret, i; |
2817 | PwMerror ret2; | 2823 | PwMerror ret2; |
2818 | char *entry[4]; | 2824 | char *entry[4]; |
2819 | PwMDataItem tmpData; | 2825 | PwMDataItem tmpData; |
2820 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2826 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2821 | if (ret != 1) | 2827 | if (ret != 1) |
2822 | return e_accessFile; | 2828 | return e_accessFile; |
2823 | 2829 | ||
2824 | do { | 2830 | do { |
2825 | ret = gp.load_entry(entry); | 2831 | ret = gp.load_entry(entry); |
2826 | if(ret != 1) | 2832 | if(ret != 1) |
2827 | break; | 2833 | break; |
2828 | tmpData.desc = entry[0]; | 2834 | tmpData.desc = entry[0]; |
2829 | tmpData.name = entry[1]; | 2835 | tmpData.name = entry[1]; |
2830 | tmpData.pw = entry[2]; | 2836 | tmpData.pw = entry[2]; |
2831 | tmpData.comment = entry[3]; | 2837 | tmpData.comment = entry[3]; |
2832 | tmpData.lockStat = true; | 2838 | tmpData.lockStat = true; |
2833 | tmpData.listViewPos = -1; | 2839 | tmpData.listViewPos = -1; |
2834 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2840 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2835 | for (i = 0; i < 4; ++i) | 2841 | for (i = 0; i < 4; ++i) |
2836 | free(entry[i]); | 2842 | free(entry[i]); |
2837 | if (ret2 == e_maxAllowedEntr) { | 2843 | if (ret2 == e_maxAllowedEntr) { |
2838 | gp.load_finalize(); | 2844 | gp.load_finalize(); |
2839 | return e_maxAllowedEntr; | 2845 | return e_maxAllowedEntr; |
2840 | } | 2846 | } |
2841 | } while (1); | 2847 | } while (1); |
2842 | gp.load_finalize(); | 2848 | gp.load_finalize(); |
2843 | if (isDocEmpty()) | 2849 | if (isDocEmpty()) |
2844 | return e_wrongPw; // we assume this. | 2850 | return e_wrongPw; // we assume this. |
2845 | 2851 | ||
2846 | flagDirty(); | 2852 | flagDirty(); |
2847 | return e_success; | 2853 | return e_success; |
2848 | } | 2854 | } |
2849 | 2855 | ||
2850 | 2856 | ||
2851 | //US: we use the stl sort algorythm to sort all elements in the order | 2857 | //US: we use the stl sort algorythm to sort all elements in the order |
2852 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 | 2858 | //of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 |
2853 | struct PwMDataItemListViewPosSort | 2859 | struct PwMDataItemListViewPosSort |
2854 | { | 2860 | { |
2855 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) | 2861 | bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) |
2856 | { | 2862 | { |
2857 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); | 2863 | //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); |
2858 | if ((rpEnd)->listViewPos < 0) | 2864 | if ((rpEnd)->listViewPos < 0) |
2859 | return false; | 2865 | return false; |
2860 | else | 2866 | else |
2861 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; | 2867 | return (rpStart)->listViewPos < (rpEnd)->listViewPos; |
2862 | } | 2868 | } |
2863 | }; | 2869 | }; |
2864 | 2870 | ||
2865 | void PwMDoc::ensureLvp() | 2871 | void PwMDoc::ensureLvp() |
2866 | { | 2872 | { |
2867 | if (isDocEmpty()) | 2873 | if (isDocEmpty()) |
2868 | return; | 2874 | return; |
2869 | 2875 | ||
2870 | //US ENH BUG: when using syncronizing, this way of sorting | 2876 | //US ENH BUG: when using syncronizing, this way of sorting |
2871 | //is not sufficient, because there might be empty spaces | 2877 | //is not sufficient, because there might be empty spaces |
2872 | // at the beginning. But the old algorythm only can add elements | 2878 | // at the beginning. But the old algorythm only can add elements |
2873 | //to the end.The result are crashes because of list overflows | 2879 | //to the end.The result are crashes because of list overflows |
2874 | //we need something to fill all gaps. | 2880 | //we need something to fill all gaps. |
2875 | vector<PwMDataItem*> sorted; | 2881 | vector<PwMDataItem*> sorted; |
2876 | vector< PwMDataItem*>::iterator sortedBegin, | 2882 | vector< PwMDataItem*>::iterator sortedBegin, |
2877 | sortedEnd, | 2883 | sortedEnd, |
2878 | sortedI; | 2884 | sortedI; |
2879 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2885 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2880 | catEnd = dti.dta.end(), | 2886 | catEnd = dti.dta.end(), |
2881 | catI = catBegin; | 2887 | catI = catBegin; |
2882 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2888 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2883 | int lvpTop, tmpLvp; | 2889 | int lvpTop, tmpLvp; |
2884 | 2890 | ||
2885 | //qDebug("collect:"); | 2891 | //qDebug("collect:"); |
2886 | 2892 | ||
2887 | while (catI != catEnd) { | 2893 | while (catI != catEnd) { |
2888 | lvpTop = -1; | 2894 | lvpTop = -1; |
2889 | sorted.clear(); | 2895 | sorted.clear(); |
2890 | 2896 | ||
2891 | entrBegin = catI->d.begin(); | 2897 | entrBegin = catI->d.begin(); |
2892 | entrEnd = catI->d.end(); | 2898 | entrEnd = catI->d.end(); |
2893 | entrI = entrBegin; | 2899 | entrI = entrBegin; |
2894 | 2900 | ||
2895 | //US: we use the stl sort algorythm to sort all elements in the order | 2901 | //US: we use the stl sort algorythm to sort all elements in the order |
2896 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 | 2902 | //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 |
2897 | while (entrI != entrEnd) { | 2903 | while (entrI != entrEnd) { |
2898 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2904 | //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2899 | sorted.push_back((PwMDataItem*)&(*entrI)); | 2905 | sorted.push_back((PwMDataItem*)&(*entrI)); |
2900 | ++entrI; | 2906 | ++entrI; |
2901 | } | 2907 | } |
2902 | 2908 | ||
2903 | sortedBegin = sorted.begin(); | 2909 | sortedBegin = sorted.begin(); |
2904 | sortedEnd = sorted.end(); | 2910 | sortedEnd = sorted.end(); |
2905 | 2911 | ||
2906 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); | 2912 | sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); |
2907 | 2913 | ||
2908 | // qDebug("resort:"); | 2914 | // qDebug("resort:"); |
2909 | //now we have all sorted in a collection | 2915 | //now we have all sorted in a collection |
2910 | //Now start with the sorted and reset listviewpos. | 2916 | //Now start with the sorted and reset listviewpos. |
2911 | sortedBegin = sorted.begin(); | 2917 | sortedBegin = sorted.begin(); |
2912 | sortedEnd = sorted.end(); | 2918 | sortedEnd = sorted.end(); |
2913 | sortedI = sortedBegin; | 2919 | sortedI = sortedBegin; |
2914 | 2920 | ||
2915 | while (sortedI != sortedEnd) { | 2921 | while (sortedI != sortedEnd) { |
2916 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); | 2922 | // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); |
2917 | (*sortedI)->listViewPos = ++lvpTop; | 2923 | (*sortedI)->listViewPos = ++lvpTop; |
2918 | ++sortedI; | 2924 | ++sortedI; |
2919 | } | 2925 | } |
2920 | 2926 | ||
2921 | /*/debug | 2927 | /*/debug |
2922 | entrBegin = catI->d.begin(); | 2928 | entrBegin = catI->d.begin(); |
2923 | entrEnd = catI->d.end(); | 2929 | entrEnd = catI->d.end(); |
2924 | entrI = entrBegin; | 2930 | entrI = entrBegin; |
2925 | 2931 | ||
2926 | while (entrI != entrEnd) { | 2932 | while (entrI != entrEnd) { |
2927 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); | 2933 | qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); |
2928 | ++entrI; | 2934 | ++entrI; |
2929 | } | 2935 | } |
2930 | */ | 2936 | */ |
2931 | 2937 | ||
2932 | ++catI; | 2938 | ++catI; |
2933 | } | 2939 | } |
2934 | } | 2940 | } |
2935 | 2941 | ||
2936 | QString PwMDoc::getTitle() | 2942 | QString PwMDoc::getTitle() |
2937 | { | 2943 | { |
2938 | /* NOTE: We have to ensure, that the returned title | 2944 | /* NOTE: We have to ensure, that the returned title |
2939 | * is unique and not reused somewhere else while | 2945 | * is unique and not reused somewhere else while |
2940 | * this document is valid (open). | 2946 | * this document is valid (open). |
2941 | */ | 2947 | */ |
2942 | QString title(getFilename()); | 2948 | QString title(getFilename()); |
2943 | 2949 | ||
2944 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | 2950 | //US ENH: The whole filename on PDAs is too long. So use only the last characters |
2945 | if (QApplication::desktop()->width() < 640) | 2951 | if (QApplication::desktop()->width() < 640) |
2946 | { | 2952 | { |
2947 | if (title.length() > 30) | 2953 | if (title.length() > 30) |
2948 | title = "..." + title.right(30); | 2954 | title = "..." + title.right(30); |
2949 | 2955 | ||
2950 | } | 2956 | } |
2951 | 2957 | ||
2952 | 2958 | ||
2953 | if (title.isEmpty()) { | 2959 | if (title.isEmpty()) { |
2954 | if (unnamedNum == 0) { | 2960 | if (unnamedNum == 0) { |
2955 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2961 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2956 | PWM_ASSERT(unnamedNum != 0); | 2962 | PWM_ASSERT(unnamedNum != 0); |
2957 | } | 2963 | } |
2958 | title = DEFAULT_TITLE; | 2964 | title = DEFAULT_TITLE; |
2959 | title += " "; | 2965 | title += " "; |
2960 | title += tostr(unnamedNum).c_str(); | 2966 | title += tostr(unnamedNum).c_str(); |
2961 | } | 2967 | } |
2962 | return title; | 2968 | return title; |
2963 | } | 2969 | } |
2964 | 2970 | ||
2965 | bool PwMDoc::tryDelete() | 2971 | bool PwMDoc::tryDelete() |
2966 | { | 2972 | { |
2967 | if (deleted) | 2973 | if (deleted) |
2968 | return true; | 2974 | return true; |
2969 | int ret; | 2975 | int ret; |
2970 | if (isDirty()) { | 2976 | if (isDirty()) { |
2971 | ret = dirtyAskSave(getTitle()); | 2977 | ret = dirtyAskSave(getTitle()); |
2972 | if (ret == 0) { // save to disk | 2978 | if (ret == 0) { // save to disk |
2973 | if (!saveDocUi(this)) | 2979 | if (!saveDocUi(this)) |
2974 | goto out_ignore; | 2980 | goto out_ignore; |
2975 | } else if (ret == 1) { // don't save and delete | 2981 | } else if (ret == 1) { // don't save and delete |
2976 | goto out_accept; | 2982 | goto out_accept; |
2977 | } else { // cancel operation | 2983 | } else { // cancel operation |
2978 | goto out_ignore; | 2984 | goto out_ignore; |
2979 | } | 2985 | } |
2980 | } | 2986 | } |
2981 | out_accept: | 2987 | out_accept: |
2982 | deleted = true; | 2988 | deleted = true; |
2983 | delete this; | 2989 | delete this; |
2984 | return true; | 2990 | return true; |
2985 | out_ignore: | 2991 | out_ignore: |
2986 | return false; | 2992 | return false; |
2987 | } | 2993 | } |
2988 | 2994 | ||
2989 | 2995 | ||
2990 | 2996 | ||
2991 | #ifdef PWM_EMBEDDED | 2997 | #ifdef PWM_EMBEDDED |
2992 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2998 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2993 | //US it could have been defined as static, but I did not want to. | 2999 | //US it could have been defined as static, but I did not want to. |
2994 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 3000 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2995 | { | 3001 | { |
2996 | int addedPasswordsLocal = 0; | 3002 | int addedPasswordsLocal = 0; |
2997 | int addedPasswordsRemote = 0; | 3003 | int addedPasswordsRemote = 0; |
2998 | int deletedPasswordsRemote = 0; | 3004 | int deletedPasswordsRemote = 0; |
2999 | int deletedPasswordsLocal = 0; | 3005 | int deletedPasswordsLocal = 0; |
3000 | int changedLocal = 0; | 3006 | int changedLocal = 0; |
3001 | int changedRemote = 0; | 3007 | int changedRemote = 0; |
3002 | 3008 | ||
3003 | PwMSyncItem* syncItemLocal; | 3009 | PwMSyncItem* syncItemLocal; |
3004 | PwMSyncItem* syncItemRemote; | 3010 | PwMSyncItem* syncItemRemote; |
3005 | 3011 | ||
3006 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 3012 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
3007 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3013 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3008 | 3014 | ||
3009 | bool fullDateRange = false; | 3015 | bool fullDateRange = false; |
3010 | int take; | 3016 | int take; |
3011 | // local->resetTempSyncStat(); | 3017 | // local->resetTempSyncStat(); |
3012 | QDateTime mLastSync = QDateTime::currentDateTime(); | 3018 | QDateTime mLastSync = QDateTime::currentDateTime(); |
3013 | QDateTime modifiedSync = mLastSync; | 3019 | QDateTime modifiedSync = mLastSync; |
3014 | 3020 | ||
3015 | unsigned int index; | 3021 | unsigned int index; |
3016 | //Step 1. Find syncinfo in Local file and create if not existent. | 3022 | //Step 1. Find syncinfo in Local file and create if not existent. |
3017 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3023 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3018 | if (found == false) | 3024 | if (found == false) |
3019 | { | 3025 | { |
3020 | PwMSyncItem newSyncItemLocal; | 3026 | PwMSyncItem newSyncItemLocal; |
3021 | newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); | 3027 | newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); |
3022 | newSyncItemLocal.lastSyncDate = mLastSync; | 3028 | newSyncItemLocal.lastSyncDate = mLastSync; |
3023 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 3029 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
3024 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 3030 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
3025 | if (found == false) { | 3031 | if (found == false) { |
3026 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 3032 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
3027 | return e_syncError; | 3033 | return e_syncError; |
3028 | } | 3034 | } |
3029 | } | 3035 | } |
3030 | 3036 | ||
3031 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 3037 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
3032 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 3038 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); |
3033 | 3039 | ||
3034 | //Step 2. Find syncinfo in remote file and create if not existent. | 3040 | //Step 2. Find syncinfo in remote file and create if not existent. |
3035 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3041 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3036 | if (found == false) | 3042 | if (found == false) |
3037 | { | 3043 | { |
3038 | qDebug("FULLDATE 1"); | 3044 | qDebug("FULLDATE 1"); |
3039 | fullDateRange = true; | 3045 | fullDateRange = true; |
3040 | PwMSyncItem newSyncItemRemote; | 3046 | PwMSyncItem newSyncItemRemote; |
3041 | newSyncItemRemote.syncName = mCurrentSyncName.latin1(); | 3047 | newSyncItemRemote.syncName = mCurrentSyncName.latin1(); |
3042 | newSyncItemRemote.lastSyncDate = mLastSync; | 3048 | newSyncItemRemote.lastSyncDate = mLastSync; |
3043 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 3049 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
3044 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 3050 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
3045 | if (found == false) { | 3051 | if (found == false) { |
3046 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 3052 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
3047 | return e_syncError; | 3053 | return e_syncError; |
3048 | } | 3054 | } |
3049 | } | 3055 | } |
3050 | 3056 | ||
3051 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 3057 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
3052 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | 3058 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); |
3053 | //and remove the found entry here. We will reenter it later again. | 3059 | //and remove the found entry here. We will reenter it later again. |
3054 | //US syncRemote->delSyncDataEntry(index, true); | 3060 | //US syncRemote->delSyncDataEntry(index, true); |
3055 | 3061 | ||
3056 | 3062 | ||
3057 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 3063 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
3058 | qDebug("FULLDATE 2"); | 3064 | qDebug("FULLDATE 2"); |
3059 | fullDateRange = true; | 3065 | fullDateRange = true; |
3060 | } | 3066 | } |
3061 | 3067 | ||
3062 | if ( ! fullDateRange ) { | 3068 | if ( ! fullDateRange ) { |
3063 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 3069 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
3064 | 3070 | ||
3065 | fullDateRange = true; | 3071 | fullDateRange = true; |
3066 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3072 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
3067 | } | 3073 | } |
3068 | } | 3074 | } |
3069 | // fullDateRange = true; // debug only! | 3075 | // fullDateRange = true; // debug only! |
3070 | if ( fullDateRange ) | 3076 | if ( fullDateRange ) |
3071 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3077 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
3072 | else | 3078 | else |
3073 | mLastSync = syncItemLocal->lastSyncDate; | 3079 | mLastSync = syncItemLocal->lastSyncDate; |
3074 | 3080 | ||
3075 | 3081 | ||
3076 | qDebug("*************************** "); | 3082 | qDebug("*************************** "); |
3077 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); | 3083 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
3078 | QStringList er = syncRemote->getIDEntryList(); | 3084 | QStringList er = syncRemote->getIDEntryList(); |
3079 | PwMDataItem* inRemote ;//= er.first(); | 3085 | PwMDataItem* inRemote ;//= er.first(); |
3080 | PwMDataItem* inLocal; | 3086 | PwMDataItem* inLocal; |
3081 | unsigned int catLocal, indexLocal; | 3087 | unsigned int catLocal, indexLocal; |
3082 | unsigned int catRemote, indexRemote; | 3088 | unsigned int catRemote, indexRemote; |
3083 | 3089 | ||
3084 | QString uid; | 3090 | QString uid; |
3085 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 3091 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
3086 | 3092 | ||
3087 | int modulo = (er.count()/10)+1; | 3093 | int modulo = (er.count()/10)+1; |
3088 | unsigned int incCounter = 0; | 3094 | unsigned int incCounter = 0; |
3089 | while ( incCounter < er.count()) { | 3095 | while ( incCounter < er.count()) { |
3090 | if (manager->isProgressBarCanceled()) | 3096 | if (manager->isProgressBarCanceled()) |
3091 | return e_syncError; | 3097 | return e_syncError; |
3092 | if ( incCounter % modulo == 0 ) | 3098 | if ( incCounter % modulo == 0 ) |
3093 | manager->showProgressBar(incCounter); | 3099 | manager->showProgressBar(incCounter); |
3094 | 3100 | ||
3095 | uid = er[ incCounter ]; | 3101 | uid = er[ incCounter ]; |
3096 | qDebug("sync uid %s from remote file", uid.latin1()); | 3102 | qDebug("sync uid %s from remote file", uid.latin1()); |
3097 | 3103 | ||
3098 | qApp->processEvents(); | 3104 | qApp->processEvents(); |
3099 | 3105 | ||
3100 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3106 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3101 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3107 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3102 | PWM_ASSERT(inRemote); | 3108 | PWM_ASSERT(inRemote); |
3103 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3109 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3104 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3110 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3105 | qDebug("take %d %s ", take, inLocal->desc.c_str()); | 3111 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3106 | if ( take == 3 ) | 3112 | if ( take == 3 ) |
3107 | return e_syncError; | 3113 | return e_syncError; |
3108 | if ( take == 1 ) {// take local | 3114 | if ( take == 1 ) {// take local |
3109 | int oldlistpos = inRemote->listViewPos; | 3115 | int oldlistpos = inRemote->listViewPos; |
3110 | (*inRemote) = (*inLocal); | 3116 | (*inRemote) = (*inLocal); |
3111 | inRemote->listViewPos = oldlistpos; | 3117 | inRemote->listViewPos = oldlistpos; |
3112 | ++changedRemote; | 3118 | ++changedRemote; |
3113 | } else { // take == 2 take remote | 3119 | } else { // take == 2 take remote |
3114 | int oldlistpos = inLocal->listViewPos; | 3120 | int oldlistpos = inLocal->listViewPos; |
3115 | (*inLocal) = (*inRemote); | 3121 | (*inLocal) = (*inRemote); |
3116 | inLocal->listViewPos = oldlistpos; | 3122 | inLocal->listViewPos = oldlistpos; |
3117 | ++changedLocal; | 3123 | ++changedLocal; |
3118 | } | 3124 | } |
3119 | } | 3125 | } |
3120 | } else { // no conflict | 3126 | } else { // no conflict |
3121 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 3127 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
3122 | inRemote->meta.update = modifiedSync; | 3128 | inRemote->meta.update = modifiedSync; |
3123 | 3129 | ||
3124 | //first check if we have a matching category in the local file | 3130 | //first check if we have a matching category in the local file |
3125 | const string* remotecat = syncRemote->getCategory(catRemote); | 3131 | const string* remotecat = syncRemote->getCategory(catRemote); |
3126 | //US syncRemote->insertAddressee( inRemote, false ); | ||
3127 | //US syncLocal->insertAddressee( inRemote, false ); | ||
3128 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 3132 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
3129 | 3133 | ||
3130 | ++addedPasswordsLocal; | 3134 | ++addedPasswordsLocal; |
3131 | } else { | 3135 | } else { |
3132 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 3136 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
3133 | syncRemote->delEntry(catRemote, indexRemote, true); | 3137 | syncRemote->delEntry(catRemote, indexRemote, true); |
3134 | //USsyncRemote->removeAddressee( inRemote ); | ||
3135 | ++deletedPasswordsRemote; | 3138 | ++deletedPasswordsRemote; |
3136 | } | 3139 | } |
3137 | } | 3140 | } |
3138 | 3141 | ||
3139 | ++incCounter; | 3142 | ++incCounter; |
3140 | } | 3143 | } |
3141 | 3144 | ||
3142 | 3145 | ||
3143 | er.clear(); | 3146 | er.clear(); |
3144 | QStringList el = syncLocal->getIDEntryList(); | 3147 | QStringList el = syncLocal->getIDEntryList(); |
3145 | modulo = (el.count()/10)+1; | 3148 | modulo = (el.count()/10)+1; |
3146 | 3149 | ||
3147 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 3150 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
3148 | incCounter = 0; | 3151 | incCounter = 0; |
3149 | while ( incCounter < el.count()) { | 3152 | while ( incCounter < el.count()) { |
3150 | qApp->processEvents(); | 3153 | qApp->processEvents(); |
3151 | if (manager->isProgressBarCanceled()) | 3154 | if (manager->isProgressBarCanceled()) |
3152 | return e_syncError; | 3155 | return e_syncError; |
3153 | if ( incCounter % modulo == 0 ) | 3156 | if ( incCounter % modulo == 0 ) |
3154 | manager->showProgressBar(incCounter); | 3157 | manager->showProgressBar(incCounter); |
3155 | uid = el[ incCounter ]; | 3158 | uid = el[ incCounter ]; |
3156 | qDebug("sync uid %s from local file", uid.latin1()); | 3159 | qDebug("sync uid %s from local file", uid.latin1()); |
3157 | 3160 | ||
3158 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3161 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3159 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3162 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3160 | PWM_ASSERT(inLocal); | 3163 | PWM_ASSERT(inLocal); |
3161 | 3164 | ||
3162 | if ( inRemote == 0 ) { | 3165 | if ( inRemote == 0 ) { |
3163 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 3166 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
3164 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3167 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3165 | syncLocal->delEntry(catLocal, indexLocal, true); | 3168 | syncLocal->delEntry(catLocal, indexLocal, true); |
3166 | //USsyncLocal->removeAddressee( inLocal ); | ||
3167 | ++deletedPasswordsLocal; | 3169 | ++deletedPasswordsLocal; |
3168 | } else { | 3170 | } else { |
3169 | if ( ! manager->mWriteBackExistingOnly ) { | 3171 | if ( ! manager->mWriteBackExistingOnly ) { |
3170 | ++addedPasswordsRemote; | 3172 | ++addedPasswordsRemote; |
3171 | inLocal->meta.update = modifiedSync; | 3173 | inLocal->meta.update = modifiedSync; |
3172 | 3174 | ||
3173 | //first check if we have a matching category in the remote file | 3175 | //first check if we have a matching category in the remote file |
3174 | const string* localcat = syncLocal->getCategory(catLocal); | 3176 | const string* localcat = syncLocal->getCategory(catLocal); |
3175 | 3177 | ||
3176 | //USsyncLocal->insertAddressee( inLocal, false ); | ||
3177 | PwMDataItem newEntry; | 3178 | PwMDataItem newEntry; |
3178 | newEntry = *inLocal; | 3179 | newEntry = *inLocal; |
3179 | inRemote = &newEntry; | 3180 | inRemote = &newEntry; |
3180 | 3181 | ||
3181 | //USsyncRemote->insertAddressee( inRemote, false ); | 3182 | //USsyncRemote->insertAddressee( inRemote, false ); |
3182 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 3183 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
3183 | 3184 | ||
3184 | } | 3185 | } |
3185 | } | 3186 | } |
3186 | 3187 | ||
3187 | } | 3188 | } |
3188 | ++incCounter; | 3189 | ++incCounter; |
3189 | } | 3190 | } |
3190 | el.clear(); | 3191 | el.clear(); |
3191 | manager->hideProgressBar(); | 3192 | manager->hideProgressBar(); |
3192 | 3193 | ||
3193 | // Now write the info back into the sync data space of the files | 3194 | // Now write the info back into the sync data space of the files |
3194 | 3195 | ||
3195 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 3196 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
3196 | // get rid of micro seconds | 3197 | // get rid of micro seconds |
3197 | QTime t = mLastSync.time(); | 3198 | QTime t = mLastSync.time(); |
3198 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3199 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3199 | 3200 | ||
3200 | 3201 | ||
3201 | syncItemLocal->lastSyncDate = mLastSync; | 3202 | syncItemLocal->lastSyncDate = mLastSync; |
3202 | syncItemRemote->lastSyncDate = mLastSync; | 3203 | syncItemRemote->lastSyncDate = mLastSync; |
3203 | 3204 | ||
3204 | QString mes; | 3205 | QString mes; |
3205 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | 3206 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); |
3206 | if ( manager->mShowSyncSummary ) { | 3207 | if ( manager->mShowSyncSummary ) { |
3207 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3208 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3208 | } | 3209 | } |
3209 | qDebug( mes ); | 3210 | qDebug( mes ); |
3210 | return e_success; | 3211 | return e_success; |
3211 | } | 3212 | } |
3212 | 3213 | ||
3213 | 3214 | ||
3214 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3215 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3215 | { | 3216 | { |
3216 | // 0 equal | 3217 | // 0 equal |
3217 | // 1 take local | 3218 | // 1 take local |
3218 | // 2 take remote | 3219 | // 2 take remote |
3219 | // 3 cancel | 3220 | // 3 cancel |
3220 | QDateTime localMod = local->meta.update; | 3221 | QDateTime localMod = local->meta.update; |
3221 | QDateTime remoteMod = remote->meta.update; | 3222 | QDateTime remoteMod = remote->meta.update; |
3222 | 3223 | ||
3223 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
3224 | |||
3225 | if ( localMod == remoteMod ) | 3224 | if ( localMod == remoteMod ) |
3226 | return 0; | 3225 | return 0; |
3227 | 3226 | ||
3228 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3227 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3229 | 3228 | ||
3230 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3229 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3231 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3230 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3232 | //full = true; //debug only | 3231 | //full = true; //debug only |
3233 | if ( full ) { | 3232 | if ( full ) { |
3234 | bool equ = ( (*local) == (*remote) ); | 3233 | bool equ = ( (*local) == (*remote) ); |
3235 | if ( equ ) { | 3234 | if ( equ ) { |
3236 | //qDebug("equal "); | 3235 | //qDebug("equal "); |
3237 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3236 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3238 | return 0; | 3237 | return 0; |
3239 | 3238 | ||
3240 | }//else //debug only | 3239 | }//else //debug only |
3241 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); | 3240 | //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3242 | } | 3241 | } |
3243 | 3242 | ||
3244 | int result; | 3243 | int result; |
3245 | bool localIsNew; | 3244 | bool localIsNew; |
3246 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 3245 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
3247 | 3246 | ||
3248 | if ( full && mode < SYNC_PREF_NEWEST ) | 3247 | if ( full && mode < SYNC_PREF_NEWEST ) |
3249 | mode = SYNC_PREF_ASK; | 3248 | mode = SYNC_PREF_ASK; |
3250 | 3249 | ||
3251 | switch( mode ) { | 3250 | switch( mode ) { |
3252 | case SYNC_PREF_LOCAL: | 3251 | case SYNC_PREF_LOCAL: |
3253 | if ( lastSync > remoteMod ) | 3252 | if ( lastSync > remoteMod ) |
3254 | return 1; | 3253 | return 1; |
3255 | if ( lastSync > localMod ) | 3254 | if ( lastSync > localMod ) |
3256 | return 2; | 3255 | return 2; |
3257 | return 1; | 3256 | return 1; |
3258 | break; | 3257 | break; |
3259 | case SYNC_PREF_REMOTE: | 3258 | case SYNC_PREF_REMOTE: |
3260 | if ( lastSync > remoteMod ) | 3259 | if ( lastSync > remoteMod ) |
3261 | return 1; | 3260 | return 1; |
3262 | if ( lastSync > localMod ) | 3261 | if ( lastSync > localMod ) |
3263 | return 2; | 3262 | return 2; |
3264 | return 2; | 3263 | return 2; |
3265 | break; | 3264 | break; |
3266 | case SYNC_PREF_NEWEST: | 3265 | case SYNC_PREF_NEWEST: |
3267 | if ( localMod > remoteMod ) | 3266 | if ( localMod > remoteMod ) |
3268 | return 1; | 3267 | return 1; |
3269 | else | 3268 | else |
3270 | return 2; | 3269 | return 2; |
3271 | break; | 3270 | break; |
3272 | case SYNC_PREF_ASK: | 3271 | case SYNC_PREF_ASK: |
3273 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3272 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3274 | if ( lastSync > remoteMod ) | 3273 | if ( lastSync > remoteMod ) |
3275 | return 1; | 3274 | return 1; |
3276 | if ( lastSync > localMod ) | 3275 | if ( lastSync > localMod ) |
3277 | return 2; | 3276 | return 2; |
3278 | localIsNew = localMod >= remoteMod; | 3277 | localIsNew = localMod >= remoteMod; |
3279 | //qDebug("conflict! ************************************** "); | 3278 | //qDebug("conflict! ************************************** "); |
3280 | { | 3279 | { |
3281 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3280 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3282 | result = acd.executeD(localIsNew); | 3281 | result = acd.executeD(localIsNew); |
3283 | return result; | 3282 | return result; |
3284 | } | 3283 | } |
3285 | break; | 3284 | break; |
3286 | case SYNC_PREF_FORCE_LOCAL: | 3285 | case SYNC_PREF_FORCE_LOCAL: |
3287 | return 1; | 3286 | return 1; |
3288 | break; | 3287 | break; |
3289 | case SYNC_PREF_FORCE_REMOTE: | 3288 | case SYNC_PREF_FORCE_REMOTE: |
3290 | return 2; | 3289 | return 2; |
3291 | break; | 3290 | break; |
3292 | 3291 | ||
3293 | default: | 3292 | default: |
3294 | // SYNC_PREF_TAKE_BOTH not implemented | 3293 | // SYNC_PREF_TAKE_BOTH not implemented |
3295 | break; | 3294 | break; |
3296 | } | 3295 | } |
3297 | return 0; | 3296 | return 0; |
3298 | } | 3297 | } |
3299 | 3298 | ||
3300 | 3299 | ||
3301 | 3300 | ||
3302 | 3301 | ||
3303 | //this are the overwritten callbackmethods from the syncinterface | 3302 | //this are the overwritten callbackmethods from the syncinterface |
3304 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3303 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3305 | { | 3304 | { |
3306 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3305 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3307 | 3306 | ||
3308 | //1) unlock local file first if necessary (ask for password) | 3307 | //1) unlock local file first if necessary (ask for password) |
3309 | if (this->isDeepLocked()) { | 3308 | if (this->isDeepLocked()) { |
3310 | PwMerror ret = this->deepLock(false); | 3309 | PwMerror ret = this->deepLock(false); |
3311 | if (ret != e_success) | 3310 | if (ret != e_success) |
3312 | return false; | 3311 | return false; |
3313 | } | 3312 | } |
3314 | 3313 | ||
3315 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). | 3314 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). |
3316 | PwMDoc syncTarget(this, "synctarget"); | 3315 | PwMDoc syncTarget(this, "synctarget"); |
3317 | PwMDoc* pSyncTarget = &syncTarget; | 3316 | PwMDoc* pSyncTarget = &syncTarget; |
3318 | 3317 | ||
3319 | 3318 | ||
3320 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3319 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3321 | 3320 | ||
3322 | if (err == e_alreadyOpen) { | 3321 | if (err == e_alreadyOpen) { |
3323 | PwMDocList::listItem li; | 3322 | PwMDocList::listItem li; |
3324 | if (getOpenDocList()->find(filename.latin1(), &li)) | 3323 | if (getOpenDocList()->find(filename.latin1(), &li)) |
3325 | pSyncTarget = li.doc; | 3324 | pSyncTarget = li.doc; |
3326 | else { | 3325 | else { |
3327 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3326 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3328 | return false; | 3327 | return false; |
3329 | } | 3328 | } |
3330 | } | 3329 | } |
3331 | else if (err != e_success) { | 3330 | else if (err != e_success) { |
3332 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3331 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3333 | return false; | 3332 | return false; |
3334 | } | 3333 | } |
3335 | 3334 | ||
3336 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3335 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3337 | 3336 | ||
3338 | 3337 | ||
3339 | //3) unlock remote file first if necessary (ask for password) | 3338 | //3) unlock remote file first if necessary (ask for password) |
3340 | if (pSyncTarget->isDeepLocked()) { | 3339 | if (pSyncTarget->isDeepLocked()) { |
3341 | PwMerror ret = pSyncTarget->deepLock(false); | 3340 | PwMerror ret = pSyncTarget->deepLock(false); |
3342 | if (ret != e_success) | 3341 | if (ret != e_success) |
3343 | return false; | 3342 | return false; |
3344 | } | 3343 | } |
3345 | 3344 | ||
3346 | 3345 | ||
3347 | err = syncronize(manager, this, pSyncTarget, mode ); | 3346 | err = syncronize(manager, this, pSyncTarget, mode ); |
3348 | 3347 | ||
3349 | if (err == e_success) { | 3348 | if (err == e_success) { |
3350 | if ( manager->mWriteBackFile ){ | 3349 | if ( manager->mWriteBackFile ){ |
3351 | qDebug("Saving remote PWManager file"); | 3350 | qDebug("Saving remote PWManager file"); |
3352 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); | 3351 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3353 | if (err != e_success) { | 3352 | if (err != e_success) { |
3354 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); | 3353 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); |
3355 | return false; | 3354 | return false; |
3356 | } | 3355 | } |
3357 | } | 3356 | } |
3358 | 3357 | ||
3359 | flagDirty(); | 3358 | flagDirty(); |
3360 | return true; | 3359 | return true; |
3361 | } | 3360 | } |
3362 | else { | 3361 | else { |
3363 | return false; | 3362 | return false; |
3364 | } | 3363 | } |
3365 | } | 3364 | } |
3366 | 3365 | ||
3367 | #endif | 3366 | #endif |
3368 | 3367 | ||
3369 | 3368 | ||
3370 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3369 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3371 | { | 3370 | { |
3372 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3371 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3373 | end = dti.syncDta.end(); | 3372 | end = dti.syncDta.end(); |
3374 | 3373 | ||
3375 | while (i != end) { | 3374 | while (i != end) { |
3376 | if ((*i).syncName == syncname.latin1()) { | 3375 | if ((*i).syncName == syncname.latin1()) { |
3377 | if (index) { | 3376 | if (index) { |
3378 | *index = i - dti.syncDta.begin(); | 3377 | *index = i - dti.syncDta.begin(); |
3379 | } | 3378 | } |
3380 | return true; | 3379 | return true; |
3381 | } | 3380 | } |
3382 | ++i; | 3381 | ++i; |
3383 | } | 3382 | } |
3384 | return false; | 3383 | return false; |
3385 | }; | 3384 | }; |
3386 | 3385 | ||
3387 | /** add new syncdataentry */ | 3386 | /** add new syncdataentry */ |
3388 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3387 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3389 | { | 3388 | { |
3390 | PWM_ASSERT(d); | 3389 | PWM_ASSERT(d); |
3391 | 3390 | ||
3392 | if (isDeepLocked()) { | 3391 | if (isDeepLocked()) { |
3393 | PwMerror ret; | 3392 | PwMerror ret; |
3394 | ret = deepLock(false); | 3393 | ret = deepLock(false); |
3395 | if (ret != e_success) | 3394 | if (ret != e_success) |
3396 | return e_lock; | 3395 | return e_lock; |
3397 | } | 3396 | } |
3398 | unsigned int index; | 3397 | unsigned int index; |
3399 | 3398 | ||
3400 | const QString tmp = d->syncName.c_str(); | 3399 | const QString tmp = d->syncName.c_str(); |
3401 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3400 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3402 | 3401 | ||
3403 | if (exists == true) { | 3402 | if (exists == true) { |
3404 | // DOH! We found this entry. | 3403 | // DOH! We found this entry. |
3405 | return e_entryExists; | 3404 | return e_entryExists; |
3406 | } | 3405 | } |
3407 | 3406 | ||
3408 | dti.syncDta.push_back(*d); | 3407 | dti.syncDta.push_back(*d); |
3409 | 3408 | ||
3410 | if (!dontFlagDirty) | 3409 | if (!dontFlagDirty) |
3411 | flagDirty(); | 3410 | flagDirty(); |
3412 | return e_success; | 3411 | return e_success; |
3413 | } | 3412 | } |
3414 | 3413 | ||
3415 | 3414 | ||
3416 | 3415 | ||
3417 | /** delete syncdata entry */ | 3416 | /** delete syncdata entry */ |
3418 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3417 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3419 | { | 3418 | { |
3420 | if (isDeepLocked()) | 3419 | if (isDeepLocked()) |
3421 | return false; | 3420 | return false; |
3422 | if (index > dti.syncDta.size() - 1) | 3421 | if (index > dti.syncDta.size() - 1) |
3423 | return false; | 3422 | return false; |
3424 | 3423 | ||
3425 | // delete entry | 3424 | // delete entry |
3426 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3425 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3427 | 3426 | ||
3428 | if (!dontFlagDirty) | 3427 | if (!dontFlagDirty) |
3429 | flagDirty(); | 3428 | flagDirty(); |
3430 | return true; | 3429 | return true; |
3431 | } | 3430 | } |
3432 | 3431 | ||
3433 | 3432 | ||
3434 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3433 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3435 | { | 3434 | { |
3436 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3435 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3437 | catend = dti.dta.end(); | 3436 | catend = dti.dta.end(); |
3438 | 3437 | ||
3439 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3438 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3440 | 3439 | ||
3441 | while (catcounter != catend) { | 3440 | while (catcounter != catend) { |
3442 | entrBegin = catcounter->d.begin(); | 3441 | entrBegin = catcounter->d.begin(); |
3443 | entrEnd = catcounter->d.end(); | 3442 | entrEnd = catcounter->d.end(); |
3444 | entrI = entrBegin; | 3443 | entrI = entrBegin; |
3445 | while (entrI != entrEnd) { | 3444 | while (entrI != entrEnd) { |
3446 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3445 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3447 | if (category) | 3446 | if (category) |
3448 | *category = catcounter - dti.dta.begin(); | 3447 | *category = catcounter - dti.dta.begin(); |
3449 | if (index) | 3448 | if (index) |
3450 | *index = entrI - entrBegin; | 3449 | *index = entrI - entrBegin; |
3451 | 3450 | ||
3452 | return &(*entrI); | 3451 | return &(*entrI); |
3453 | } | 3452 | } |
3454 | ++entrI; | 3453 | ++entrI; |
3455 | } | 3454 | } |
3456 | ++catcounter; | 3455 | ++catcounter; |
3457 | } | 3456 | } |
3458 | 3457 | ||
3459 | return 0; | 3458 | return 0; |
3460 | } | 3459 | } |
3461 | 3460 | ||
3462 | QStringList PwMDoc::getIDEntryList() | 3461 | QStringList PwMDoc::getIDEntryList() |
3463 | { | 3462 | { |
3464 | QStringList results; | 3463 | QStringList results; |
3465 | 3464 | ||
3466 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3465 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3467 | catend = dti.dta.end(); | 3466 | catend = dti.dta.end(); |
3468 | 3467 | ||
3469 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3468 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3470 | 3469 | ||
3471 | while (catcounter != catend) { | 3470 | while (catcounter != catend) { |
3472 | entrBegin = catcounter->d.begin(); | 3471 | entrBegin = catcounter->d.begin(); |
3473 | entrEnd = catcounter->d.end(); | 3472 | entrEnd = catcounter->d.end(); |
3474 | entrI = entrBegin; | 3473 | entrI = entrBegin; |
3475 | while (entrI != entrEnd) { | 3474 | while (entrI != entrEnd) { |
3476 | results.append( (*entrI).meta.uniqueid.c_str() ); | 3475 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3477 | ++entrI; | 3476 | ++entrI; |
3478 | } | 3477 | } |
3479 | ++catcounter; | 3478 | ++catcounter; |
3480 | } | 3479 | } |
3481 | 3480 | ||
3482 | return results; | 3481 | return results; |
3483 | } | 3482 | } |
3484 | 3483 | ||
3485 | 3484 | ||
3486 | 3485 | ||
3487 | 3486 | ||
3488 | 3487 | ||
3489 | #ifndef PWM_EMBEDDED | 3488 | #ifndef PWM_EMBEDDED |
3490 | #include "pwmdoc.moc" | 3489 | #include "pwmdoc.moc" |
3491 | #endif | 3490 | #endif |