-rw-r--r-- | bin/kdepim/pwmanager/pwmanagerFAQ.txt | 38 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 57 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.h | 8 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 85 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 39 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 92 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.h | 25 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 126 |
8 files changed, 321 insertions, 149 deletions
diff --git a/bin/kdepim/pwmanager/pwmanagerFAQ.txt b/bin/kdepim/pwmanager/pwmanagerFAQ.txt index 7bfe368..a28f07b 100644 --- a/bin/kdepim/pwmanager/pwmanagerFAQ.txt +++ b/bin/kdepim/pwmanager/pwmanagerFAQ.txt | |||
@@ -1,41 +1,71 @@ | |||
1 | Q: | 1 | Q: |
2 | What is PWM/Pi | 2 | What is PWM/Pi? |
3 | Q: | 3 | Q: |
4 | For which platform is PWM/Pi available? | 4 | For which platform is PWM/Pi available? |
5 | Q: | 5 | Q: |
6 | Can I exchange the password files from PWM/Pi and PwManager | 6 | Can I exchange the password files from PWM/Pi and PwManager? |
7 | Q: | ||
8 | Does Export/Import keep sync information in place? | ||
9 | Q: | ||
10 | Can PWM/Pi sync categories? | ||
11 | Q: | ||
12 | Which crypto, hash and compress algorithm is applied to the remote file | ||
13 | while syncing? | ||
14 | |||
7 | 15 | ||
8 | ************************************************************************* | 16 | ************************************************************************* |
9 | Q: | 17 | Q: |
10 | What is PWM/Pi | 18 | What is PWM/Pi |
11 | A: | 19 | A: |
12 | PWM/Pi is the platform-independend version of PwManager 1.0.1, written by | 20 | PWM/Pi is the platform-independend version of PwManager 1.0.1, written by |
13 | Michael Buesch and the PwManager Team (http://passwordmanager.sourceforge.net) | 21 | Michael Buesch and the PwManager Team (http://passwordmanager.sourceforge.net) |
14 | ************************************************************************* | 22 | ************************************************************************* |
15 | Q: | 23 | Q: |
16 | For which platform is PWM/Pi available? | 24 | For which platform is PWM/Pi available? |
17 | A: | 25 | A: |
18 | PWM/Pi is the platform-independend version of PWManager and it | 26 | PWM/Pi is the platform-independend version of PWManager and it |
19 | includes a replacement for the KDE libraries called microkde. | 27 | includes a replacement for the KDE libraries called microkde. |
20 | It can be compiled to any platform, where Qt is available. | 28 | It can be compiled to any platform, where Qt is available. |
21 | The source code compiles without modifications on Windows, | 29 | The source code compiles without modifications on Windows, |
22 | Linux Desktop and Sharp Zaurus PDA. Precompiled versions are available | 30 | Linux Desktop and Sharp Zaurus PDA. Precompiled versions are available |
23 | on www.pi-sync.net for Windows and Sharp Zaurus PDA. | 31 | on www.pi-sync.net for Windows and Sharp Zaurus PDA. |
24 | Latest versions and the source code cvs can be found at: | 32 | Latest versions and the source code cvs can be found at: |
25 | http://sourceforge.net/projects/kdepimpi/ | 33 | http://sourceforge.net/projects/kdepimpi/ |
26 | ************************************************************************* | 34 | ************************************************************************* |
27 | Q: | 35 | Q: |
28 | Can I exchange the password files from PWM/Pi and PwManager | 36 | Can I exchange the password files from PWM/Pi and PwManager |
29 | A: | 37 | A: |
30 | The password files of PWM/Pi can not be exchanged with all versions up | 38 | The password files of PWM/Pi can not be exchanged with all versions up |
31 | to 1.0.1 of PwManager. | 39 | to 1.0.1 of PwManager. |
32 | However, Michael will integrate our changes into a PwManager release | 40 | However, Michael will integrate our changes into a PwManager release |
33 | 1.1, and the password files of that release will then be interchangable | 41 | 1.1, and the password files of that release will then be interchangable |
34 | with PWM/Pi | 42 | with PWM/Pi |
35 | 43 | ************************************************************************* | |
36 | 44 | Q: | |
45 | Does Export/Import keep sync information in place | ||
46 | A: | ||
47 | Exporting data from PwManager removes all sync related information | ||
48 | (Meta information) from the data. Because of that, a subsequent import | ||
49 | results in "new" entries that will be handled as new entries when | ||
50 | syncing them with an existing password file. | ||
51 | ************************************************************************* | ||
52 | Q: | ||
53 | Can PWM/Pi sync categories? | ||
54 | A: | ||
55 | No. PWM/Pi does not sync categories. It syncs all pw entries of the file | ||
56 | without checking for the entries categories. | ||
57 | A sync operation does not move modified entries from one category to another. | ||
58 | Only if the sync operation has to create a new pw entry, it checks for the | ||
59 | existance of the category and creates it if not existent. | ||
60 | ************************************************************************* | ||
61 | Q: | ||
62 | Which crypto, hash and compress algorithm is applied to the remote file | ||
63 | while syncing? | ||
64 | A: The sync operation applies the local crypt, hash and compress algorithm | ||
65 | to both, the local and remote copy of the passwordfile and with thus | ||
66 | overwrites the settings of the remote PwManager application. | ||
37 | 67 | ||
38 | 68 | ||
39 | 69 | ||
40 | 70 | ||
41 | 71 | ||
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index 014e809..57b4432 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,1365 +1,1364 @@ | |||
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 | }; | 137 | }; |
137 | #endif | 138 | #endif |
138 | 139 | ||
139 | // Button IDs for toolbar | 140 | // Button IDs for toolbar |
140 | enum { | 141 | enum { |
141 | BUTTON_TOOL_NEW = 0, | 142 | BUTTON_TOOL_NEW = 0, |
142 | BUTTON_TOOL_OPEN, | 143 | BUTTON_TOOL_OPEN, |
143 | BUTTON_TOOL_SAVE, | 144 | BUTTON_TOOL_SAVE, |
144 | BUTTON_TOOL_SAVEAS, | 145 | BUTTON_TOOL_SAVEAS, |
145 | BUTTON_TOOL_PRINT, | 146 | BUTTON_TOOL_PRINT, |
146 | BUTTON_TOOL_ADD, | 147 | BUTTON_TOOL_ADD, |
147 | BUTTON_TOOL_EDIT, | 148 | BUTTON_TOOL_EDIT, |
148 | BUTTON_TOOL_DEL, | 149 | BUTTON_TOOL_DEL, |
149 | BUTTON_TOOL_FIND, | 150 | BUTTON_TOOL_FIND, |
150 | BUTTON_TOOL_LOCK, | 151 | BUTTON_TOOL_LOCK, |
151 | BUTTON_TOOL_DEEPLOCK, | 152 | BUTTON_TOOL_DEEPLOCK, |
152 | BUTTON_TOOL_UNLOCK | 153 | BUTTON_TOOL_UNLOCK |
153 | }; | 154 | }; |
154 | 155 | ||
155 | 156 | ||
156 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 157 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
157 | bool virginity, | 158 | bool virginity, |
158 | QWidget *parent, const char *name) | 159 | QWidget *parent, const char *name) |
159 | : KMainWindow(parent, name) | 160 | : KMainWindow(parent, "HALLO") |
160 | , forceQuit (false) | 161 | , forceQuit (false) |
161 | , forceMinimizeToTray (false) | 162 | , forceMinimizeToTray (false) |
162 | { | 163 | { |
163 | init = _init; | 164 | init = _init; |
164 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 165 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
165 | this, SLOT(docClosed(PwMDoc *))); | 166 | this, SLOT(docClosed(PwMDoc *))); |
166 | initMenubar(); | 167 | initMenubar(); |
167 | initToolbar(); | 168 | initToolbar(); |
168 | initMetrics(); | 169 | initMetrics(); |
169 | setVirgin(virginity); | 170 | setVirgin(virginity); |
170 | setFocusPolicy(QWidget::WheelFocus); | 171 | setFocusPolicy(QWidget::WheelFocus); |
171 | #ifndef PWM_EMBEDDED | 172 | #ifndef PWM_EMBEDDED |
172 | statusBar()->show(); | 173 | statusBar()->show(); |
173 | #endif | 174 | #endif |
174 | view = makeNewListView(doc); | 175 | view = makeNewListView(doc); |
175 | setCentralWidget(view); | 176 | setCentralWidget(view); |
176 | updateCaption(); | 177 | updateCaption(); |
177 | showStatMsg(i18n("Ready.")); | 178 | showStatMsg(i18n("Ready.")); |
178 | } | 179 | } |
179 | 180 | ||
180 | PwM::~PwM() | 181 | PwM::~PwM() |
181 | { | 182 | { |
182 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 183 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
183 | this, SLOT(docClosed(PwMDoc *))); | 184 | this, SLOT(docClosed(PwMDoc *))); |
184 | conf()->confWndMainWndSize(size()); | 185 | conf()->confWndMainWndSize(size()); |
185 | emit closed(this); | 186 | emit closed(this); |
186 | delete view; | 187 | delete view; |
187 | } | 188 | } |
188 | 189 | ||
189 | void PwM::initMenubar() | 190 | void PwM::initMenubar() |
190 | { | 191 | { |
191 | KIconLoader* picons; | 192 | KIconLoader* picons; |
192 | #ifndef PWM_EMBEDDED | 193 | #ifndef PWM_EMBEDDED |
193 | KIconLoader icons; | 194 | KIconLoader icons; |
194 | picons = &icons; | 195 | picons = &icons; |
195 | #else | 196 | #else |
196 | picons = KGlobal::iconLoader(); | 197 | picons = KGlobal::iconLoader(); |
197 | 198 | ||
198 | 199 | ||
199 | syncPopup = new KPopupMenu(this); | 200 | syncPopup = new KPopupMenu(this); |
200 | 201 | ||
201 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); | 202 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); |
202 | syncManager->setBlockSave(false); | 203 | syncManager->setBlockSave(false); |
203 | 204 | ||
204 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 205 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
205 | syncManager->fillSyncMenu(); | 206 | syncManager->fillSyncMenu(); |
206 | 207 | ||
207 | #endif | 208 | #endif |
208 | filePopup = new KPopupMenu(this); | 209 | filePopup = new KPopupMenu(this); |
209 | importPopup = new KPopupMenu(filePopup); | 210 | importPopup = new KPopupMenu(filePopup); |
210 | exportPopup = new KPopupMenu(filePopup); | 211 | exportPopup = new KPopupMenu(filePopup); |
211 | managePopup = new KPopupMenu(this); | 212 | managePopup = new KPopupMenu(this); |
212 | #ifdef CONFIG_KEYCARD | 213 | #ifdef CONFIG_KEYCARD |
213 | chipcardPopup = new KPopupMenu(this); | 214 | chipcardPopup = new KPopupMenu(this); |
214 | #endif // CONFIG_KEYCARD | 215 | #endif // CONFIG_KEYCARD |
215 | viewPopup = new KPopupMenu(this); | 216 | viewPopup = new KPopupMenu(this); |
216 | optionsPopup = new KPopupMenu(this); | 217 | optionsPopup = new KPopupMenu(this); |
217 | 218 | ||
218 | // "file" popup menu | 219 | // "file" popup menu |
219 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 220 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
220 | i18n("&New"), this, | 221 | i18n("&New"), this, |
221 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 222 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
222 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 223 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
223 | i18n("&Open"), this, | 224 | i18n("&Open"), this, |
224 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 225 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
225 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 226 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
226 | i18n("&Close"), this, | 227 | i18n("&Close"), this, |
227 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 228 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
228 | filePopup->insertSeparator(); | 229 | filePopup->insertSeparator(); |
229 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 230 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
230 | i18n("&Save"), this, | 231 | i18n("&Save"), this, |
231 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 232 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
232 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 233 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
233 | i18n("Save &as..."), | 234 | i18n("Save &as..."), |
234 | this, SLOT(saveAs_slot()), 0, | 235 | this, SLOT(saveAs_slot()), 0, |
235 | BUTTON_POPUP_FILE_SAVEAS); | 236 | BUTTON_POPUP_FILE_SAVEAS); |
236 | filePopup->insertSeparator(); | 237 | filePopup->insertSeparator(); |
237 | // "file/export" popup menu | 238 | // "file/export" popup menu |
238 | exportPopup->insertItem(i18n("&Text-file..."), this, | 239 | exportPopup->insertItem(i18n("&Text-file..."), this, |
239 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 240 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
240 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 241 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
241 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 242 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
242 | #ifdef CONFIG_KWALLETIF | 243 | #ifdef CONFIG_KWALLETIF |
243 | exportPopup->insertItem(i18n("&KWallet..."), this, | 244 | exportPopup->insertItem(i18n("&KWallet..."), this, |
244 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 245 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
245 | #endif | 246 | #endif |
246 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 247 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
247 | i18n("E&xport"), exportPopup, | 248 | i18n("E&xport"), exportPopup, |
248 | BUTTON_POPUP_FILE_EXPORT); | 249 | BUTTON_POPUP_FILE_EXPORT); |
249 | // "file/import" popup menu | 250 | // "file/import" popup menu |
250 | importPopup->insertItem(i18n("&Text-file..."), this, | 251 | importPopup->insertItem(i18n("&Text-file..."), this, |
251 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 252 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
252 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 253 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
253 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 254 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
254 | #ifdef CONFIG_KWALLETIF | 255 | #ifdef CONFIG_KWALLETIF |
255 | importPopup->insertItem(i18n("&KWallet..."), this, | 256 | importPopup->insertItem(i18n("&KWallet..."), this, |
256 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 257 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
257 | #endif | 258 | #endif |
258 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 259 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
259 | i18n("I&mport"), importPopup, | 260 | i18n("I&mport"), importPopup, |
260 | BUTTON_POPUP_FILE_IMPORT); | 261 | BUTTON_POPUP_FILE_IMPORT); |
261 | filePopup->insertSeparator(); | 262 | filePopup->insertSeparator(); |
262 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 263 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
263 | i18n("&Print..."), this, | 264 | i18n("&Print..."), this, |
264 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 265 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
265 | filePopup->insertSeparator(); | 266 | filePopup->insertSeparator(); |
266 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 267 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
267 | i18n("&Quit"), this, | 268 | i18n("&Quit"), this, |
268 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 269 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
269 | menuBar()->insertItem(i18n("&File"), filePopup); | 270 | menuBar()->insertItem(i18n("&File"), filePopup); |
270 | // "manage" popup menu | 271 | // "manage" popup menu |
271 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 272 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
272 | i18n("&Add password"), this, | 273 | i18n("&Add password"), this, |
273 | SLOT(addPwd_slot()), 0, | 274 | SLOT(addPwd_slot()), 0, |
274 | BUTTON_POPUP_MANAGE_ADD); | 275 | BUTTON_POPUP_MANAGE_ADD); |
275 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 276 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
276 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 277 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
277 | BUTTON_POPUP_MANAGE_EDIT); | 278 | BUTTON_POPUP_MANAGE_EDIT); |
278 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 279 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
279 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 280 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
280 | 0, BUTTON_POPUP_MANAGE_DEL); | 281 | 0, BUTTON_POPUP_MANAGE_DEL); |
281 | managePopup->insertSeparator(); | 282 | managePopup->insertSeparator(); |
282 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 283 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
283 | i18n("Change &Master Password"), this, | 284 | i18n("Change &Master Password"), this, |
284 | SLOT(changeMasterPwd_slot()), 0, | 285 | SLOT(changeMasterPwd_slot()), 0, |
285 | BUTTON_POPUP_MANAGE_CHANGEMP); | 286 | BUTTON_POPUP_MANAGE_CHANGEMP); |
286 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 287 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
287 | // "chipcard" popup menu | 288 | // "chipcard" popup menu |
288 | #ifdef CONFIG_KEYCARD | 289 | #ifdef CONFIG_KEYCARD |
289 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 290 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
290 | i18n("&Generate new key-card"), this, | 291 | i18n("&Generate new key-card"), this, |
291 | SLOT(genNewCard_slot()), 0, | 292 | SLOT(genNewCard_slot()), 0, |
292 | BUTTON_POPUP_CHIPCARD_GENNEW); | 293 | BUTTON_POPUP_CHIPCARD_GENNEW); |
293 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 294 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
294 | i18n("&Erase key-card"), this, | 295 | i18n("&Erase key-card"), this, |
295 | SLOT(eraseCard_slot()), 0, | 296 | SLOT(eraseCard_slot()), 0, |
296 | BUTTON_POPUP_CHIPCARD_DEL); | 297 | BUTTON_POPUP_CHIPCARD_DEL); |
297 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 298 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
298 | i18n("Read card-&ID"), this, | 299 | i18n("Read card-&ID"), this, |
299 | SLOT(readCardId_slot()), 0, | 300 | SLOT(readCardId_slot()), 0, |
300 | BUTTON_POPUP_CHIPCARD_READID); | 301 | BUTTON_POPUP_CHIPCARD_READID); |
301 | chipcardPopup->insertSeparator(); | 302 | chipcardPopup->insertSeparator(); |
302 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 303 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
303 | i18n("&Make card backup-image"), this, | 304 | i18n("&Make card backup-image"), this, |
304 | SLOT(makeCardBackup_slot()), 0, | 305 | SLOT(makeCardBackup_slot()), 0, |
305 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 306 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
306 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 307 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
307 | i18n("&Replay card backup-image"), this, | 308 | i18n("&Replay card backup-image"), this, |
308 | SLOT(replayCardBackup_slot()), 0, | 309 | SLOT(replayCardBackup_slot()), 0, |
309 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 310 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
310 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 311 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
311 | #endif // CONFIG_KEYCARD | 312 | #endif // CONFIG_KEYCARD |
312 | // "view" popup menu | 313 | // "view" popup menu |
313 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 314 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
314 | i18n("&Find"), this, | 315 | i18n("&Find"), this, |
315 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 316 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
316 | viewPopup->insertSeparator(); | 317 | viewPopup->insertSeparator(); |
317 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 318 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
318 | i18n("&Lock all entries"), this, | 319 | i18n("&Lock all entries"), this, |
319 | SLOT(lockWnd_slot()), 0, | 320 | SLOT(lockWnd_slot()), 0, |
320 | BUTTON_POPUP_VIEW_LOCK); | 321 | BUTTON_POPUP_VIEW_LOCK); |
321 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 322 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
322 | i18n("&Deep-lock all entries"), this, | 323 | i18n("&Deep-lock all entries"), this, |
323 | SLOT(deepLockWnd_slot()), 0, | 324 | SLOT(deepLockWnd_slot()), 0, |
324 | BUTTON_POPUP_VIEW_DEEPLOCK); | 325 | BUTTON_POPUP_VIEW_DEEPLOCK); |
325 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 326 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
326 | i18n("&Unlock all entries"), this, | 327 | i18n("&Unlock all entries"), this, |
327 | SLOT(unlockWnd_slot()), 0, | 328 | SLOT(unlockWnd_slot()), 0, |
328 | BUTTON_POPUP_VIEW_UNLOCK); | 329 | BUTTON_POPUP_VIEW_UNLOCK); |
329 | menuBar()->insertItem(i18n("&View"), viewPopup); | 330 | menuBar()->insertItem(i18n("&View"), viewPopup); |
330 | // "options" popup menu | 331 | // "options" popup menu |
331 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 332 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
332 | i18n("&Configure..."), this, | 333 | i18n("&Configure..."), this, |
333 | SLOT(config_slot()), | 334 | SLOT(config_slot()), |
334 | BUTTON_POPUP_OPTIONS_CONFIG); | 335 | BUTTON_POPUP_OPTIONS_CONFIG); |
335 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 336 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
336 | // "help" popup menu | 337 | // "help" popup menu |
337 | #ifndef PWM_EMBEDDED | 338 | #ifndef PWM_EMBEDDED |
338 | helpPopup = helpMenu(QString::null, false); | 339 | helpPopup = helpMenu(QString::null, false); |
339 | #else | 340 | #else |
340 | menuBar()->insertItem(i18n("&Sync"), syncPopup); | 341 | menuBar()->insertItem(i18n("&Sync"), syncPopup); |
341 | 342 | ||
342 | 343 | ||
343 | 344 | ||
344 | 345 | ||
345 | 346 | ||
346 | helpPopup = new KPopupMenu(this); | 347 | helpPopup = new KPopupMenu(this); |
347 | 348 | ||
348 | 349 | ||
349 | helpPopup->insertItem(i18n("&License"), this, | 350 | helpPopup->insertItem(i18n("&License"), this, |
350 | SLOT(showLicense_slot()), 0, | 351 | SLOT(showLicense_slot()), 0, |
351 | BUTTON_POPUP_HELP_LICENSE); | 352 | BUTTON_POPUP_HELP_LICENSE); |
352 | 353 | ||
353 | helpPopup->insertItem(i18n("&Faq"), this, | 354 | helpPopup->insertItem(i18n("&Faq"), this, |
354 | SLOT(faq_slot()), 0, | 355 | SLOT(faq_slot()), 0, |
355 | BUTTON_POPUP_HELP_FAQ); | 356 | BUTTON_POPUP_HELP_FAQ); |
356 | 357 | ||
357 | helpPopup->insertItem(i18n("&About PwManager"), this, | 358 | helpPopup->insertItem(i18n("&About PwManager"), this, |
358 | SLOT(createAboutData_slot()), 0, | 359 | SLOT(createAboutData_slot()), 0, |
359 | BUTTON_POPUP_HELP_ABOUT); | 360 | BUTTON_POPUP_HELP_ABOUT); |
360 | 361 | ||
362 | helpPopup->insertItem(i18n("&Sync HowTo"), this, | ||
363 | SLOT(syncHowTo_slot()), 0, | ||
364 | BUTTON_POPUP_HELP_SYNC); | ||
365 | |||
361 | #endif | 366 | #endif |
362 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 367 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
363 | 368 | ||
364 | } | 369 | } |
365 | 370 | ||
366 | void PwM::initToolbar() | 371 | void PwM::initToolbar() |
367 | { | 372 | { |
368 | KIconLoader* picons; | 373 | KIconLoader* picons; |
369 | #ifndef PWM_EMBEDDED | 374 | #ifndef PWM_EMBEDDED |
370 | KIconLoader icons; | 375 | KIconLoader icons; |
371 | picons = &icons; | 376 | picons = &icons; |
372 | #else | 377 | #else |
373 | picons = KGlobal::iconLoader(); | 378 | picons = KGlobal::iconLoader(); |
374 | #endif | 379 | #endif |
375 | 380 | ||
376 | #ifdef PWM_EMBEDDED | 381 | #ifdef PWM_EMBEDDED |
377 | if ( QApplication::desktop()->width() > 320 ) | 382 | if ( QApplication::desktop()->width() > 320 ) |
378 | #endif | 383 | #endif |
379 | { | 384 | { |
380 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 385 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
381 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 386 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
382 | SLOT(new_slot()), true, i18n("New")); | 387 | SLOT(new_slot()), true, i18n("New")); |
383 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 388 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
384 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 389 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
385 | SLOT(open_slot()), true, i18n("Open")); | 390 | SLOT(open_slot()), true, i18n("Open")); |
386 | toolBar()->insertSeparator(); | 391 | toolBar()->insertSeparator(); |
387 | } | 392 | } |
388 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), | 393 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), |
389 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, | 394 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, |
390 | SLOT(save_slot()), true, i18n("Save")); | 395 | SLOT(save_slot()), true, i18n("Save")); |
391 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), | 396 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), |
392 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, | 397 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, |
393 | SLOT(saveAs_slot()), true, i18n("Save as")); | 398 | SLOT(saveAs_slot()), true, i18n("Save as")); |
394 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), | 399 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), |
395 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, | 400 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, |
396 | SLOT(print_slot()), true, i18n("Print...")); | 401 | SLOT(print_slot()), true, i18n("Print...")); |
397 | toolBar()->insertSeparator(); | 402 | toolBar()->insertSeparator(); |
398 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), | 403 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), |
399 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, | 404 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, |
400 | SLOT(addPwd_slot()), true, | 405 | SLOT(addPwd_slot()), true, |
401 | i18n("Add password")); | 406 | i18n("Add password")); |
402 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), | 407 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), |
403 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, | 408 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, |
404 | SLOT(editPwd_slot()), true, | 409 | SLOT(editPwd_slot()), true, |
405 | i18n("Edit password")); | 410 | i18n("Edit password")); |
406 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), | 411 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), |
407 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, | 412 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, |
408 | SLOT(deletePwd_slot()), true, | 413 | SLOT(deletePwd_slot()), true, |
409 | i18n("Delete password")); | 414 | i18n("Delete password")); |
410 | toolBar()->insertSeparator(); | 415 | toolBar()->insertSeparator(); |
411 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), | 416 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), |
412 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, | 417 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, |
413 | SLOT(find_slot()), true, i18n("Find entry")); | 418 | SLOT(find_slot()), true, i18n("Find entry")); |
414 | toolBar()->insertSeparator(); | 419 | toolBar()->insertSeparator(); |
415 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), | 420 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), |
416 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, | 421 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, |
417 | SLOT(lockWnd_slot()), true, | 422 | SLOT(lockWnd_slot()), true, |
418 | i18n("Lock all entries")); | 423 | i18n("Lock all entries")); |
419 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), | 424 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), |
420 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, | 425 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, |
421 | SLOT(deepLockWnd_slot()), true, | 426 | SLOT(deepLockWnd_slot()), true, |
422 | i18n("Deep-Lock all entries")); | 427 | i18n("Deep-Lock all entries")); |
423 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), | 428 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), |
424 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, | 429 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, |
425 | SLOT(unlockWnd_slot()), true, | 430 | SLOT(unlockWnd_slot()), true, |
426 | i18n("Unlock all entries")); | 431 | i18n("Unlock all entries")); |
427 | } | 432 | } |
428 | 433 | ||
429 | void PwM::initMetrics() | 434 | void PwM::initMetrics() |
430 | { | 435 | { |
431 | QSize s = conf()->confWndMainWndSize(); | 436 | QSize s = conf()->confWndMainWndSize(); |
432 | if (s.isValid()) | 437 | if (s.isValid()) |
433 | resize(s); | 438 | resize(s); |
434 | else | 439 | else |
435 | resize(DEFAULT_SIZE); | 440 | resize(DEFAULT_SIZE); |
436 | } | 441 | } |
437 | 442 | ||
438 | void PwM::updateCaption() | 443 | void PwM::updateCaption() |
439 | { | 444 | { |
440 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); | 445 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); |
441 | } | 446 | } |
442 | 447 | ||
443 | void PwM::hideEvent(QHideEvent *) | 448 | void PwM::hideEvent(QHideEvent *) |
444 | { | 449 | { |
445 | if (isMinimized()) { | 450 | if (isMinimized()) { |
446 | if (init->tray()) { | 451 | if (init->tray()) { |
447 | forceMinimizeToTray = true; | 452 | forceMinimizeToTray = true; |
448 | close(); | 453 | close(); |
449 | } | 454 | } |
450 | int mmlock = conf()->confGlobMinimizeLock(); | 455 | int mmlock = conf()->confGlobMinimizeLock(); |
451 | switch (mmlock) { | 456 | switch (mmlock) { |
452 | case 0: // don't lock anything | 457 | case 0: // don't lock anything |
453 | break; | 458 | break; |
454 | case 1: {// normal lock | 459 | case 1: {// normal lock |
455 | curDoc()->lockAll(true); | 460 | curDoc()->lockAll(true); |
456 | break; | 461 | break; |
457 | } case 2: {// deep-lock | 462 | } case 2: {// deep-lock |
458 | curDoc()->deepLock(); | 463 | curDoc()->deepLock(); |
459 | break; | 464 | break; |
460 | } default: | 465 | } default: |
461 | WARN(); | 466 | WARN(); |
462 | } | 467 | } |
463 | } | 468 | } |
464 | } | 469 | } |
465 | 470 | ||
466 | void PwM::setVirgin(bool v) | 471 | void PwM::setVirgin(bool v) |
467 | { | 472 | { |
468 | if (virgin == v) | 473 | if (virgin == v) |
469 | return; | 474 | return; |
470 | virgin = v; | 475 | virgin = v; |
471 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); | 476 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); |
472 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); | 477 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); |
473 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); | 478 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); |
474 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); | 479 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); |
475 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); | 480 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); |
476 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); | 481 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); |
477 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); | 482 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); |
478 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); | 483 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); |
479 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); | 484 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); |
480 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); | 485 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); |
481 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); | 486 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); |
482 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); | 487 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); |
483 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); | 488 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); |
484 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); | 489 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); |
485 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); | 490 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); |
486 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); | 491 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); |
487 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); | 492 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); |
488 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); | 493 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); |
489 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); | 494 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); |
490 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); | 495 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); |
491 | } | 496 | } |
492 | 497 | ||
493 | void PwM::new_slot() | 498 | void PwM::new_slot() |
494 | { | 499 | { |
495 | init->createMainWnd(); | 500 | init->createMainWnd(); |
496 | } | 501 | } |
497 | 502 | ||
498 | //US ENH | 503 | //US ENH |
499 | void PwM::open_slot() | 504 | void PwM::open_slot() |
500 | { | 505 | { |
501 | open_slot(""); | 506 | open_slot(""); |
502 | } | 507 | } |
503 | 508 | ||
504 | void PwM::open_slot(QString fn) | 509 | void PwM::open_slot(QString fn) |
505 | { | 510 | { |
506 | openDoc(fn); | 511 | openDoc(fn); |
507 | } | 512 | } |
508 | 513 | ||
509 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) | 514 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) |
510 | { | 515 | { |
511 | if (!isVirgin()) { | 516 | if (!isVirgin()) { |
512 | // open the document in a new window. | 517 | // open the document in a new window. |
513 | PwM *newInstance = init->createMainWnd(); | 518 | PwM *newInstance = init->createMainWnd(); |
514 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); | 519 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); |
515 | if (!newDoc) { | 520 | if (!newDoc) { |
516 | newInstance->setForceQuit(true); | 521 | newInstance->setForceQuit(true); |
517 | delete_and_null(newInstance); | 522 | delete_and_null(newInstance); |
518 | } | 523 | } |
519 | return newDoc; | 524 | return newDoc; |
520 | } | 525 | } |
521 | 526 | ||
522 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) | 527 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) |
523 | return 0; | 528 | return 0; |
524 | showStatMsg(i18n("Successfully opened file.")); | 529 | showStatMsg(i18n("Successfully opened file.")); |
525 | updateCaption(); | 530 | updateCaption(); |
526 | setVirgin(false); | 531 | setVirgin(false); |
527 | return curDoc(); | 532 | return curDoc(); |
528 | } | 533 | } |
529 | 534 | ||
530 | PwMView * PwM::makeNewListView(PwMDoc *doc) | 535 | PwMView * PwM::makeNewListView(PwMDoc *doc) |
531 | { | 536 | { |
532 | PwMView *ret = new PwMView(this, this, doc); | 537 | PwMView *ret = new PwMView(this, this, doc); |
533 | ret->setFont(conf()->confGlobEntryFont()); | 538 | ret->setFont(conf()->confGlobEntryFont()); |
534 | ret->show(); | 539 | ret->show(); |
535 | return ret; | 540 | return ret; |
536 | } | 541 | } |
537 | 542 | ||
538 | void PwM::close_slot() | 543 | void PwM::close_slot() |
539 | { | 544 | { |
540 | close(); | 545 | close(); |
541 | } | 546 | } |
542 | 547 | ||
543 | void PwM::quitButton_slot() | 548 | void PwM::quitButton_slot() |
544 | { | 549 | { |
545 | init->shutdownApp(0); | 550 | init->shutdownApp(0); |
546 | } | 551 | } |
547 | 552 | ||
548 | void PwM::save_slot() | 553 | void PwM::save_slot() |
549 | { | 554 | { |
550 | save(); | 555 | save(); |
551 | } | 556 | } |
552 | 557 | ||
553 | bool PwM::save() | 558 | bool PwM::save() |
554 | { | 559 | { |
555 | if (!curDoc()->saveDocUi(curDoc())) | 560 | if (!curDoc()->saveDocUi(curDoc())) |
556 | return false; | 561 | return false; |
557 | showStatMsg(i18n("Successfully saved data.")); | 562 | showStatMsg(i18n("Successfully saved data.")); |
558 | updateCaption(); | 563 | updateCaption(); |
559 | return true; | 564 | return true; |
560 | } | 565 | } |
561 | 566 | ||
562 | void PwM::saveAs_slot() | 567 | void PwM::saveAs_slot() |
563 | { | 568 | { |
564 | saveAs(); | 569 | saveAs(); |
565 | } | 570 | } |
566 | 571 | ||
567 | bool PwM::saveAs() | 572 | bool PwM::saveAs() |
568 | { | 573 | { |
569 | if (!curDoc()->saveAsDocUi(curDoc())) | 574 | if (!curDoc()->saveAsDocUi(curDoc())) |
570 | return false; | 575 | return false; |
571 | showStatMsg(i18n("Successfully saved data.")); | 576 | showStatMsg(i18n("Successfully saved data.")); |
572 | updateCaption(); | 577 | updateCaption(); |
573 | return true; | 578 | return true; |
574 | } | 579 | } |
575 | 580 | ||
576 | //US ENH : changed code to run with older MOC | 581 | //US ENH : changed code to run with older MOC |
577 | void PwM::addPwd_slot() | 582 | void PwM::addPwd_slot() |
578 | { | 583 | { |
579 | addPwd_slot(0, 0); | 584 | addPwd_slot(0, 0); |
580 | } | 585 | } |
581 | 586 | ||
582 | void PwM::addPwd_slot(QString *pw, PwMDoc *_doc) | 587 | void PwM::addPwd_slot(QString *pw, PwMDoc *_doc) |
583 | { | 588 | { |
584 | PwMDoc *doc; | 589 | PwMDoc *doc; |
585 | if (_doc) { | 590 | if (_doc) { |
586 | doc = _doc; | 591 | doc = _doc; |
587 | } else { | 592 | } else { |
588 | doc = curDoc(); | 593 | doc = curDoc(); |
589 | } | 594 | } |
590 | PWM_ASSERT(doc); | 595 | PWM_ASSERT(doc); |
591 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 596 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
592 | #ifndef PWM_EMBEDDED | 597 | #ifndef PWM_EMBEDDED |
593 | AddEntryWndImpl w; | 598 | AddEntryWndImpl w; |
594 | #else | 599 | #else |
595 | AddEntryWndImpl w(this, "addentrywndimpl"); | 600 | AddEntryWndImpl w(this, "addentrywndimpl"); |
596 | #endif | 601 | #endif |
597 | 602 | ||
598 | vector<string> catList; | 603 | vector<string> catList; |
599 | doc->getCategoryList(&catList); | 604 | doc->getCategoryList(&catList); |
600 | unsigned i, size = catList.size(); | 605 | unsigned i, size = catList.size(); |
601 | for (i = 0; i < size; ++i) { | 606 | for (i = 0; i < size; ++i) { |
602 | w.addCategory(catList[i].c_str()); | 607 | w.addCategory(catList[i].c_str()); |
603 | } | 608 | } |
604 | w.setCurrCategory(view->getCurrentCategory()); | 609 | w.setCurrCategory(view->getCurrentCategory()); |
605 | if (pw) | 610 | if (pw) |
606 | w.pwLineEdit->setText(*pw); | 611 | w.pwLineEdit->setText(*pw); |
607 | 612 | ||
608 | tryAgain: | 613 | tryAgain: |
609 | if (w.exec() == 1) | 614 | if (w.exec() == 1) |
610 | { | 615 | { |
611 | PwMDataItem d; | 616 | PwMDataItem d; |
617 | |||
618 | //US BUG: to initialize all values of curEntr with meaningfulldata, | ||
619 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | ||
620 | // another option would be to create a constructor for PwMDataItem | ||
621 | d.clear(true); | ||
622 | |||
612 | d.desc = w.getDescription().latin1(); | 623 | d.desc = w.getDescription().latin1(); |
613 | d.name = w.getUsername().latin1(); | 624 | d.name = w.getUsername().latin1(); |
614 | d.pw = w.getPassword().latin1(); | 625 | d.pw = w.getPassword().latin1(); |
615 | d.comment = w.getComment().latin1(); | 626 | d.comment = w.getComment().latin1(); |
616 | d.url = w.getUrl().latin1(); | 627 | d.url = w.getUrl().latin1(); |
617 | d.launcher = w.getLauncher().latin1(); | 628 | d.launcher = w.getLauncher().latin1(); |
618 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 629 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
619 | if (ret == e_entryExists) { | 630 | if (ret == e_entryExists) { |
620 | KMessageBox::error(this, | 631 | KMessageBox::error(this, |
621 | i18n | 632 | i18n |
622 | ("An entry with this \"Description\", " | 633 | ("An entry with this \"Description\",\n" |
623 | "does already exist.\n" | 634 | "does already exist.\n" |
624 | "Please select another description."), | 635 | "Please select another description."), |
625 | i18n("entry already exists.")); | 636 | i18n("entry already exists.")); |
626 | goto tryAgain; | 637 | goto tryAgain; |
627 | } else if (ret == e_maxAllowedEntr) { | 638 | } else if (ret == e_maxAllowedEntr) { |
628 | KMessageBox::error(this, i18n("The maximum possible number of entries " | 639 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" |
629 | "has been reached. You can't add more entries."), | 640 | "has been reached.\nYou can't add more entries."), |
630 | i18n("maximum number of entries")); | 641 | i18n("maximum number of entries")); |
631 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 642 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
632 | return; | 643 | return; |
633 | } | 644 | } |
634 | } | 645 | } |
635 | setVirgin(false); | 646 | setVirgin(false); |
636 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 647 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
637 | } | 648 | } |
638 | 649 | ||
639 | //US ENH : changed code to run with older MOC | 650 | //US ENH : changed code to run with older MOC |
640 | void PwM::editPwd_slot() | 651 | void PwM::editPwd_slot() |
641 | { | 652 | { |
642 | editPwd_slot(0,0,0); | 653 | editPwd_slot(0,0,0); |
643 | } | 654 | } |
644 | 655 | ||
645 | void PwM::editPwd_slot(const QString *category) | 656 | void PwM::editPwd_slot(const QString *category) |
646 | { | 657 | { |
647 | editPwd_slot(category, 0, 0); | 658 | editPwd_slot(category, 0, 0); |
648 | } | 659 | } |
649 | 660 | ||
650 | void PwM::editPwd_slot(const QString *category, const int *index, | 661 | void PwM::editPwd_slot(const QString *category, const int *index, |
651 | PwMDoc *_doc) | 662 | PwMDoc *_doc) |
652 | { | 663 | { |
653 | PwMDoc *doc; | 664 | PwMDoc *doc; |
654 | if (_doc) { | 665 | if (_doc) { |
655 | doc = _doc; | 666 | doc = _doc; |
656 | } else { | 667 | } else { |
657 | doc = curDoc(); | 668 | doc = curDoc(); |
658 | } | 669 | } |
659 | PWM_ASSERT(doc); | 670 | PWM_ASSERT(doc); |
660 | if (doc->isDocEmpty()) | 671 | if (doc->isDocEmpty()) |
661 | return; | 672 | return; |
662 | if (doc->isDeepLocked()) | 673 | if (doc->isDeepLocked()) |
663 | return; | 674 | return; |
664 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 675 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
665 | unsigned int curEntryIndex; | 676 | unsigned int curEntryIndex; |
666 | if (index) { | 677 | if (index) { |
667 | curEntryIndex = *index; | 678 | curEntryIndex = *index; |
668 | } else { | 679 | } else { |
669 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 680 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
670 | printDebug("couldn't get index. Maybe we have a binary entry here."); | 681 | printDebug("couldn't get index. Maybe we have a binary entry here."); |
671 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 682 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
672 | return; | 683 | return; |
673 | } | 684 | } |
674 | } | 685 | } |
675 | QString curCategory; | 686 | QString curCategory; |
676 | if (category) { | 687 | if (category) { |
677 | curCategory = *category; | 688 | curCategory = *category; |
678 | } else { | 689 | } else { |
679 | curCategory = view->getCurrentCategory(); | 690 | curCategory = view->getCurrentCategory(); |
680 | } | 691 | } |
681 | PwMDataItem currItem; | 692 | PwMDataItem currItem; |
682 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { | 693 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { |
683 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 694 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
684 | return; | 695 | return; |
685 | } | 696 | } |
686 | BUG_ON(currItem.binary); | 697 | BUG_ON(currItem.binary); |
687 | 698 | ||
688 | AddEntryWndImpl w; | 699 | AddEntryWndImpl w; |
689 | vector<string> catList; | 700 | vector<string> catList; |
690 | doc->getCategoryList(&catList); | 701 | doc->getCategoryList(&catList); |
691 | unsigned i, size = catList.size(); | 702 | unsigned i, size = catList.size(); |
692 | for (i = 0; i < size; ++i) { | 703 | for (i = 0; i < size; ++i) { |
693 | w.addCategory(catList[i].c_str()); | 704 | w.addCategory(catList[i].c_str()); |
694 | } | 705 | } |
695 | w.setCurrCategory(curCategory); | 706 | w.setCurrCategory(curCategory); |
696 | w.setDescription(currItem.desc.c_str()); | 707 | w.setDescription(currItem.desc.c_str()); |
697 | w.setUsername(currItem.name.c_str()); | 708 | w.setUsername(currItem.name.c_str()); |
698 | w.setPassword(currItem.pw.c_str()); | 709 | w.setPassword(currItem.pw.c_str()); |
699 | w.setUrl(currItem.url.c_str()); | 710 | w.setUrl(currItem.url.c_str()); |
700 | w.setLauncher(currItem.launcher.c_str()); | 711 | w.setLauncher(currItem.launcher.c_str()); |
701 | w.setComment(currItem.comment.c_str()); | 712 | w.setComment(currItem.comment.c_str()); |
702 | if (w.exec() == 1) { | 713 | if (w.exec() == 1) { |
703 | currItem.desc = w.getDescription().latin1(); | 714 | currItem.desc = w.getDescription().latin1(); |
704 | currItem.name = w.getUsername().latin1(); | 715 | currItem.name = w.getUsername().latin1(); |
705 | currItem.pw = w.getPassword().latin1(); | 716 | currItem.pw = w.getPassword().latin1(); |
706 | currItem.comment = w.getComment().latin1(); | 717 | currItem.comment = w.getComment().latin1(); |
707 | currItem.url = w.getUrl().latin1(); | 718 | currItem.url = w.getUrl().latin1(); |
708 | currItem.launcher = w.getLauncher().latin1(); | 719 | currItem.launcher = w.getLauncher().latin1(); |
709 | if (!doc->editEntry(curCategory, w.getCategory(), | 720 | if (!doc->editEntry(curCategory, w.getCategory(), |
710 | curEntryIndex, &currItem)) { | 721 | curEntryIndex, &currItem)) { |
711 | KMessageBox::error(this, | 722 | KMessageBox::error(this, |
712 | i18n("Couldn't edit the entry.\n" | 723 | i18n("Couldn't edit the entry.\n" |
713 | "Maybe you changed the category and " | 724 | "Maybe you changed the category and " |
714 | "this entry is already present in the new " | 725 | "this entry is already present in the new " |
715 | "category?"), | 726 | "category?"), |
716 | i18n("couldn't edit entry.")); | 727 | i18n("couldn't edit entry.")); |
717 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 728 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
718 | return; | 729 | return; |
719 | } | 730 | } |
720 | } | 731 | } |
721 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 732 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
722 | } | 733 | } |
723 | 734 | ||
724 | void PwM::deletePwd_slot() | 735 | void PwM::deletePwd_slot() |
725 | { | 736 | { |
726 | PWM_ASSERT(curDoc()); | 737 | PWM_ASSERT(curDoc()); |
727 | if (curDoc()->isDocEmpty()) | 738 | if (curDoc()->isDocEmpty()) |
728 | return; | 739 | return; |
729 | if (curDoc()->isDeepLocked()) | 740 | if (curDoc()->isDeepLocked()) |
730 | return; | 741 | return; |
731 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 742 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
732 | unsigned int curEntryIndex = 0; | 743 | unsigned int curEntryIndex = 0; |
733 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 744 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
734 | printDebug("couldn't get index"); | 745 | printDebug("couldn't get index"); |
735 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 746 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
736 | return; | 747 | return; |
737 | } | 748 | } |
738 | 749 | ||
739 | PwMDataItem currItem; | 750 | PwMDataItem currItem; |
740 | QString curCategory = view->getCurrentCategory(); | 751 | QString curCategory = view->getCurrentCategory(); |
741 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { | 752 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { |
742 | printDebug("couldn't get entry"); | 753 | printDebug("couldn't get entry"); |
743 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 754 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
744 | return; | 755 | return; |
745 | } | 756 | } |
746 | if (KMessageBox:: | 757 | if (KMessageBox:: |
747 | questionYesNo(this, | 758 | questionYesNo(this, |
748 | i18n | 759 | i18n |
749 | ("Do you really want to delete\nthe selected entry") + | 760 | ("Do you really want to delete\nthe selected entry") + |
750 | " \n\"" + QString(currItem.desc.c_str()) | 761 | " \n\"" + QString(currItem.desc.c_str()) |
751 | + "\" ?", i18n("delete?")) | 762 | + "\" ?", i18n("delete?")) |
752 | == KMessageBox::Yes) { | 763 | == KMessageBox::Yes) { |
753 | 764 | ||
754 | curDoc()->delEntry(curCategory, curEntryIndex); | 765 | curDoc()->delEntry(curCategory, curEntryIndex); |
755 | } | 766 | } |
756 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 767 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
757 | } | 768 | } |
758 | 769 | ||
759 | void PwM::changeMasterPwd_slot() | 770 | void PwM::changeMasterPwd_slot() |
760 | { | 771 | { |
761 | PWM_ASSERT(curDoc()); | 772 | PWM_ASSERT(curDoc()); |
762 | curDoc()->changeCurrentPw(); | 773 | curDoc()->changeCurrentPw(); |
763 | } | 774 | } |
764 | 775 | ||
765 | void PwM::lockWnd_slot() | 776 | void PwM::lockWnd_slot() |
766 | { | 777 | { |
767 | PWM_ASSERT(curDoc()); | 778 | PWM_ASSERT(curDoc()); |
768 | curDoc()->lockAll(true); | 779 | curDoc()->lockAll(true); |
769 | } | 780 | } |
770 | 781 | ||
771 | void PwM::deepLockWnd_slot() | 782 | void PwM::deepLockWnd_slot() |
772 | { | 783 | { |
773 | PWM_ASSERT(curDoc()); | 784 | PWM_ASSERT(curDoc()); |
774 | curDoc()->deepLock(); | 785 | curDoc()->deepLock(); |
775 | } | 786 | } |
776 | 787 | ||
777 | void PwM::unlockWnd_slot() | 788 | void PwM::unlockWnd_slot() |
778 | { | 789 | { |
779 | PWM_ASSERT(curDoc()); | 790 | PWM_ASSERT(curDoc()); |
780 | curDoc()->lockAll(false); | 791 | curDoc()->lockAll(false); |
781 | } | 792 | } |
782 | 793 | ||
783 | void PwM::config_slot() | 794 | void PwM::config_slot() |
784 | { | 795 | { |
785 | int oldStyle = conf()->confWndMainViewStyle(); | 796 | int oldStyle = conf()->confWndMainViewStyle(); |
786 | #ifdef PWM_EMBEDDED | 797 | #ifdef PWM_EMBEDDED |
787 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); | 798 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); |
788 | 799 | ||
789 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); | 800 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); |
790 | ConfigureDialog->addModule(pwmcfg ); | 801 | ConfigureDialog->addModule(pwmcfg ); |
791 | 802 | ||
792 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | 803 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); |
793 | ConfigureDialog->addModule(kdelibcfg ); | 804 | ConfigureDialog->addModule(kdelibcfg ); |
794 | 805 | ||
795 | #ifndef DESKTOP_VERSION | 806 | #ifndef DESKTOP_VERSION |
796 | ConfigureDialog->showMaximized(); | 807 | ConfigureDialog->showMaximized(); |
797 | #endif | 808 | #endif |
798 | if ( ConfigureDialog->exec() ) | 809 | if ( ConfigureDialog->exec() ) |
799 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | 810 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); |
800 | delete ConfigureDialog; | 811 | delete ConfigureDialog; |
801 | 812 | ||
802 | #else //PWM_EMBEDDED | 813 | #else //PWM_EMBEDDED |
803 | // display the configuration window (modal mode) | 814 | // display the configuration window (modal mode) |
804 | if (!conf()->showConfWnd(this)) | 815 | if (!conf()->showConfWnd(this)) |
805 | return; | 816 | return; |
806 | #endif | 817 | #endif |
807 | 818 | ||
808 | int newStyle = conf()->confWndMainViewStyle(); | 819 | int newStyle = conf()->confWndMainViewStyle(); |
809 | // reinitialize tray | 820 | // reinitialize tray |
810 | init->initTray(); | 821 | init->initTray(); |
811 | // reinitialize KWallet emulation | 822 | // reinitialize KWallet emulation |
812 | init->initKWalletEmu(); | 823 | init->initKWalletEmu(); |
813 | 824 | ||
814 | PwMDocList *_dl = PwMDoc::getOpenDocList(); | 825 | PwMDocList *_dl = PwMDoc::getOpenDocList(); |
815 | const vector<PwMDocList::listItem> *dl = _dl->getList(); | 826 | const vector<PwMDocList::listItem> *dl = _dl->getList(); |
816 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), | 827 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), |
817 | end = dl->end(); | 828 | end = dl->end(); |
818 | PwMDoc *doc; | 829 | PwMDoc *doc; |
819 | while (i != end) { | 830 | while (i != end) { |
820 | doc = (*i).doc; | 831 | doc = (*i).doc; |
821 | // unlock-without-mpw timeout | 832 | // unlock-without-mpw timeout |
822 | doc->timer()->start(DocTimer::id_mpwTimer); | 833 | doc->timer()->start(DocTimer::id_mpwTimer); |
823 | // auto-lock timeout | 834 | // auto-lock timeout |
824 | doc->timer()->start(DocTimer::id_autoLockTimer); | 835 | doc->timer()->start(DocTimer::id_autoLockTimer); |
825 | ++i; | 836 | ++i; |
826 | } | 837 | } |
827 | 838 | ||
828 | const QValueList<PwM *> *ml = init->mainWndList(); | 839 | const QValueList<PwM *> *ml = init->mainWndList(); |
829 | #ifndef PWM_EMBEDDED | 840 | #ifndef PWM_EMBEDDED |
830 | QValueList<PwM *>::const_iterator i2 = ml->begin(), | 841 | QValueList<PwM *>::const_iterator i2 = ml->begin(), |
831 | end2 = ml->end(); | 842 | end2 = ml->end(); |
832 | #else | 843 | #else |
833 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), | 844 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), |
834 | end2 = ml->end(); | 845 | end2 = ml->end(); |
835 | #endif | 846 | #endif |
836 | PwM *pwm; | 847 | PwM *pwm; |
837 | while (i2 != end2) { | 848 | while (i2 != end2) { |
838 | pwm = *i2; | 849 | pwm = *i2; |
839 | // reinitialize the window style. | 850 | // reinitialize the window style. |
840 | if (oldStyle != newStyle) | 851 | if (oldStyle != newStyle) |
841 | pwm->curView()->initStyle(newStyle); | 852 | pwm->curView()->initStyle(newStyle); |
842 | // set the new font | 853 | // set the new font |
843 | pwm->curView()->setFont(conf()->confGlobEntryFont()); | 854 | pwm->curView()->setFont(conf()->confGlobEntryFont()); |
844 | ++i2; | 855 | ++i2; |
845 | } | 856 | } |
846 | } | 857 | } |
847 | 858 | ||
848 | void PwM::activateMpButton(bool activate) | 859 | void PwM::activateMpButton(bool activate) |
849 | { | 860 | { |
850 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); | 861 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); |
851 | } | 862 | } |
852 | 863 | ||
853 | void PwM::closeEvent(QCloseEvent *e) | 864 | void PwM::closeEvent(QCloseEvent *e) |
854 | { | 865 | { |
855 | e->accept(); | 866 | e->accept(); |
856 | } | 867 | } |
857 | 868 | ||
858 | void PwM::docClosed(PwMDoc *doc) | 869 | void PwM::docClosed(PwMDoc *doc) |
859 | { | 870 | { |
860 | PARAM_UNUSED(doc); | 871 | PARAM_UNUSED(doc); |
861 | PWM_ASSERT(doc == curDoc()); | 872 | PWM_ASSERT(doc == curDoc()); |
862 | close(); | 873 | close(); |
863 | } | 874 | } |
864 | 875 | ||
865 | void PwM::find_slot() | 876 | void PwM::find_slot() |
866 | { | 877 | { |
867 | PWM_ASSERT(curDoc()); | 878 | PWM_ASSERT(curDoc()); |
868 | if (curDoc()->isDocEmpty()) | 879 | if (curDoc()->isDocEmpty()) |
869 | return; | 880 | return; |
870 | if (curDoc()->isDeepLocked()) | 881 | if (curDoc()->isDeepLocked()) |
871 | return; | 882 | return; |
872 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 883 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
873 | FindWndImpl findWnd(view); | 884 | FindWndImpl findWnd(view); |
874 | findWnd.exec(); | 885 | findWnd.exec(); |
875 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 886 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
876 | } | 887 | } |
877 | 888 | ||
878 | void PwM::exportToText() | 889 | void PwM::exportToText() |
879 | { | 890 | { |
880 | PWM_ASSERT(curDoc()); | 891 | PWM_ASSERT(curDoc()); |
881 | if (curDoc()->isDocEmpty()) { | 892 | if (curDoc()->isDocEmpty()) { |
882 | KMessageBox::information(this, | 893 | KMessageBox::information(this, |
883 | i18n | 894 | i18n |
884 | ("Sorry, there's nothing to export.\n" | 895 | ("Sorry, there's nothing to export.\n" |
885 | "Please first add some passwords."), | 896 | "Please first add some passwords."), |
886 | i18n("nothing to do")); | 897 | i18n("nothing to do")); |
887 | return; | 898 | return; |
888 | } | 899 | } |
889 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 900 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
890 | QString fn(KFileDialog::getSaveFileName(QString::null, | 901 | QString fn(KFileDialog::getSaveFileName(QString::null, |
891 | i18n("*|plain-text file"), | 902 | i18n("*|plain-text file"), |
892 | this)); | 903 | this)); |
893 | if (fn == "") { | 904 | if (fn == "") { |
894 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 905 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
895 | return; | 906 | return; |
896 | } | 907 | } |
897 | 908 | ||
898 | PwMerror ret = curDoc()->exportToText(&fn); | 909 | PwMerror ret = curDoc()->exportToText(&fn); |
899 | if (ret != e_success) { | 910 | if (ret != e_success) { |
900 | KMessageBox::error(this, | 911 | KMessageBox::error(this, |
901 | i18n("Error: Couldn't write to file.\n" | 912 | i18n("Error: Couldn't write to file.\n" |
902 | "Please check if you have permission to write " | 913 | "Please check if you have permission to write " |
903 | "to the file in that directory."), | 914 | "to the file in that directory."), |
904 | i18n("error while writing")); | 915 | i18n("error while writing")); |
905 | } else | 916 | } else |
906 | showStatMsg(i18n("Successfully exported data.")); | 917 | showStatMsg(i18n("Successfully exported data.")); |
907 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 918 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
908 | } | 919 | } |
909 | 920 | ||
910 | bool PwM::importFromText() | 921 | bool PwM::importFromText() |
911 | { | 922 | { |
912 | if (!isVirgin()) { | 923 | if (!isVirgin()) { |
913 | if (KMessageBox::questionYesNo(this, | 924 | if (KMessageBox::questionYesNo(this, |
914 | i18n("Do you want to import the data " | 925 | i18n("Do you want to import the data " |
915 | "into the current document? (If you " | 926 | "into the current document? (If you " |
916 | "select \"no\", a new document will be " | 927 | "select \"no\", a new document will be " |
917 | "opened.)"), | 928 | "opened.)"), |
918 | i18n("import into this document?")) | 929 | i18n("import into this document?")) |
919 | == KMessageBox::No) { | 930 | == KMessageBox::No) { |
920 | // import the data to a new window. | 931 | // import the data to a new window. |
921 | PwM *newInstance = init->createMainWnd(); | 932 | PwM *newInstance = init->createMainWnd(); |
922 | bool ok = newInstance->importFromText(); | 933 | bool ok = newInstance->importFromText(); |
923 | if (!ok) { | 934 | if (!ok) { |
924 | newInstance->setForceQuit(true); | 935 | newInstance->setForceQuit(true); |
925 | delete_and_null(newInstance); | 936 | delete_and_null(newInstance); |
926 | } | 937 | } |
927 | return ok; | 938 | return ok; |
928 | } | 939 | } |
929 | } | 940 | } |
930 | 941 | ||
931 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 942 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
932 | PwMerror ret; | 943 | PwMerror ret; |
933 | QString path(KFileDialog::getOpenFileName(QString::null, | 944 | QString path(KFileDialog::getOpenFileName(QString::null, |
934 | i18n("*|PWM-exported text file"), | 945 | i18n("*|PWM-exported text file"), |
935 | this)); | 946 | this)); |
936 | if (path == "") | 947 | if (path == "") |
937 | goto cancelImport; | 948 | goto cancelImport; |
938 | 949 | ||
939 | ret = curDoc()->importFromText(&path, 0); | 950 | ret = curDoc()->importFromText(&path, 0); |
940 | if (ret == e_fileFormat) { | 951 | if (ret == e_fileFormat) { |
941 | KMessageBox::error(this, | 952 | KMessageBox::error(this, |
942 | i18n("Could not read file-format.\n" | 953 | i18n("Could not read file-format.\n" |
943 | "This seems to be _not_ a valid file " | 954 | "This seems to be _not_ a valid file " |
944 | "exported by PwM."), | 955 | "exported by PwM."), |
945 | i18n("invalid file-format")); | 956 | i18n("invalid file-format")); |
946 | goto cancelImport; | 957 | goto cancelImport; |
947 | } else if (ret == e_invalidArg) { | 958 | } else if (ret == e_invalidArg) { |
948 | BUG(); | 959 | BUG(); |
949 | goto cancelImport; | 960 | goto cancelImport; |
950 | } else if (ret != e_success) { | 961 | } else if (ret != e_success) { |
951 | KMessageBox::error(this, | 962 | KMessageBox::error(this, |
952 | i18n("Could not import file!\n" | 963 | i18n("Could not import file!\n" |
953 | "Do you have permission to read this file? " | 964 | "Do you have permission to read this file? " |
954 | "Do you have enough free memory?"), | 965 | "Do you have enough free memory?"), |
955 | i18n("import failed")); | 966 | i18n("import failed")); |
956 | goto cancelImport; | 967 | goto cancelImport; |
957 | } | 968 | } |
958 | setVirgin(false); | 969 | setVirgin(false); |
959 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 970 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
960 | return true; | 971 | return true; |
961 | 972 | ||
962 | cancelImport: | 973 | cancelImport: |
963 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 974 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
964 | return false; | 975 | return false; |
965 | } | 976 | } |
966 | 977 | ||
967 | void PwM::exportToGpasman() | 978 | void PwM::exportToGpasman() |
968 | { | 979 | { |
969 | PWM_ASSERT(curDoc()); | 980 | PWM_ASSERT(curDoc()); |
970 | if (curDoc()->isDocEmpty()) { | 981 | if (curDoc()->isDocEmpty()) { |
971 | KMessageBox::information(this, | 982 | KMessageBox::information(this, |
972 | i18n | 983 | i18n |
973 | ("Sorry, there's nothing to export.\n" | 984 | ("Sorry, there's nothing to export.\n" |
974 | "Please first add some passwords."), | 985 | "Please first add some passwords."), |
975 | i18n("nothing to do")); | 986 | i18n("nothing to do")); |
976 | return; | 987 | return; |
977 | } | 988 | } |
978 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 989 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
979 | QString fn(KFileDialog::getSaveFileName(QString::null, | 990 | QString fn(KFileDialog::getSaveFileName(QString::null, |
980 | i18n("*|Gpasman or Kpasman file"), | 991 | i18n("*|Gpasman or Kpasman file"), |
981 | this)); | 992 | this)); |
982 | if (fn == "") { | 993 | if (fn == "") { |
983 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 994 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
984 | return; | 995 | return; |
985 | } | 996 | } |
986 | 997 | ||
987 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 998 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
988 | if (ret != e_success) { | 999 | if (ret != e_success) { |
989 | if (ret == e_noPw) { | 1000 | if (ret == e_noPw) { |
990 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1001 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
991 | return; | 1002 | return; |
992 | } | 1003 | } |
993 | KMessageBox::error(this, | 1004 | KMessageBox::error(this, |
994 | i18n("Error: Couldn't write to file.\n" | 1005 | i18n("Error: Couldn't write to file.\n" |
995 | "Please check if you have permission to write " | 1006 | "Please check if you have permission to write " |
996 | "to the file in that directory."), | 1007 | "to the file in that directory."), |
997 | i18n("error while writing")); | 1008 | i18n("error while writing")); |
998 | } else | 1009 | } else |
999 | showStatMsg(i18n("Successfully exported data.")); | 1010 | showStatMsg(i18n("Successfully exported data.")); |
1000 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1011 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1001 | } | 1012 | } |
1002 | 1013 | ||
1003 | void PwM::exportToKWallet() | 1014 | void PwM::exportToKWallet() |
1004 | { | 1015 | { |
1005 | #ifdef CONFIG_KWALLETIF | 1016 | #ifdef CONFIG_KWALLETIF |
1006 | if (!checkAndAskForKWalletEmu()) | 1017 | if (!checkAndAskForKWalletEmu()) |
1007 | return; | 1018 | return; |
1008 | PWM_ASSERT(curDoc()); | 1019 | PWM_ASSERT(curDoc()); |
1009 | if (curDoc()->isDocEmpty()) { | 1020 | if (curDoc()->isDocEmpty()) { |
1010 | KMessageBox::information(this, | 1021 | KMessageBox::information(this, |
1011 | i18n | 1022 | i18n |
1012 | ("Sorry, there's nothing to export.\n" | 1023 | ("Sorry, there's nothing to export.\n" |
1013 | "Please first add some passwords."), | 1024 | "Please first add some passwords."), |
1014 | i18n("nothing to do")); | 1025 | i18n("nothing to do")); |
1015 | init->initKWalletEmu(); | 1026 | init->initKWalletEmu(); |
1016 | return; | 1027 | return; |
1017 | } | 1028 | } |
1018 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1029 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1019 | KWalletIf walletIf(this); | 1030 | KWalletIf walletIf(this); |
1020 | if (walletIf.kwalletExport(curDoc())) { | 1031 | if (walletIf.kwalletExport(curDoc())) { |
1021 | KMessageBox::information(this, | 1032 | KMessageBox::information(this, |
1022 | i18n("Successfully exported the data of the current " | 1033 | i18n("Successfully exported the data of the current " |
1023 | "document to KWallet."), | 1034 | "document to KWallet."), |
1024 | i18n("Successfully exported data.")); | 1035 | i18n("Successfully exported data.")); |
1025 | showStatMsg(i18n("Successfully exported data.")); | 1036 | showStatMsg(i18n("Successfully exported data.")); |
1026 | } | 1037 | } |
1027 | init->initKWalletEmu(); | 1038 | init->initKWalletEmu(); |
1028 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1039 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1029 | #endif // CONFIG_KWALLETIF | 1040 | #endif // CONFIG_KWALLETIF |
1030 | } | 1041 | } |
1031 | 1042 | ||
1032 | bool PwM::importFromGpasman() | 1043 | bool PwM::importFromGpasman() |
1033 | { | 1044 | { |
1034 | if (!isVirgin()) { | 1045 | if (!isVirgin()) { |
1035 | if (KMessageBox::questionYesNo(this, | 1046 | if (KMessageBox::questionYesNo(this, |
1036 | i18n("Do you want to import the data " | 1047 | i18n("Do you want to import the data " |
1037 | "into the current document? (If you " | 1048 | "into the current document? (If you " |
1038 | "select \"no\", a new document will be " | 1049 | "select \"no\", a new document will be " |
1039 | "opened.)"), | 1050 | "opened.)"), |
1040 | i18n("import into this document?")) | 1051 | i18n("import into this document?")) |
1041 | == KMessageBox::No) { | 1052 | == KMessageBox::No) { |
1042 | // import the data to a new window. | 1053 | // import the data to a new window. |
1043 | PwM *newInstance = init->createMainWnd(); | 1054 | PwM *newInstance = init->createMainWnd(); |
1044 | bool ok = newInstance->importFromGpasman(); | 1055 | bool ok = newInstance->importFromGpasman(); |
1045 | if (!ok) { | 1056 | if (!ok) { |
1046 | newInstance->setForceQuit(true); | 1057 | newInstance->setForceQuit(true); |
1047 | delete_and_null(newInstance); | 1058 | delete_and_null(newInstance); |
1048 | } | 1059 | } |
1049 | return ok; | 1060 | return ok; |
1050 | } | 1061 | } |
1051 | } | 1062 | } |
1052 | 1063 | ||
1053 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1064 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1054 | PwMerror ret; | 1065 | PwMerror ret; |
1055 | QString path(KFileDialog::getOpenFileName(QString::null, | 1066 | QString path(KFileDialog::getOpenFileName(QString::null, |
1056 | i18n("*|Gpasman or Kpasman file"), this)); | 1067 | i18n("*|Gpasman or Kpasman file"), this)); |
1057 | if (path == "") | 1068 | if (path == "") |
1058 | goto cancelImport; | 1069 | goto cancelImport; |
1059 | ret = curDoc()->importFromGpasman(&path); | 1070 | ret = curDoc()->importFromGpasman(&path); |
1060 | if (ret == e_wrongPw) { | 1071 | if (ret == e_wrongPw) { |
1061 | if (KMessageBox::questionYesNo(this, | 1072 | if (KMessageBox::questionYesNo(this, |
1062 | i18n | 1073 | i18n |
1063 | ("This is probably the wrong master-password" | 1074 | ("This is probably the wrong master-password" |
1064 | "you have typed in.\n" | 1075 | "you have typed in.\n" |
1065 | "There is no real way to determine the " | 1076 | "There is no real way to determine the " |
1066 | "correctness of the password in the Gpasman " | 1077 | "correctness of the password in the Gpasman " |
1067 | "file-format. But I think this " | 1078 | "file-format. But I think this " |
1068 | "password ist wrong.\n" | 1079 | "password ist wrong.\n" |
1069 | "Do you want to continue nevertheless?"), | 1080 | "Do you want to continue nevertheless?"), |
1070 | i18n("password error")) | 1081 | i18n("password error")) |
1071 | == KMessageBox::No) { | 1082 | == KMessageBox::No) { |
1072 | goto cancelImport; | 1083 | goto cancelImport; |
1073 | } | 1084 | } |
1074 | } else if (ret != e_success) { | 1085 | } else if (ret != e_success) { |
1075 | KMessageBox::error(this, | 1086 | KMessageBox::error(this, |
1076 | i18n("Could not import file!\n" | 1087 | i18n("Could not import file!\n" |
1077 | "Do you have permission to read this file?"), | 1088 | "Do you have permission to read this file?"), |
1078 | i18n("import failed")); | 1089 | i18n("import failed")); |
1079 | goto cancelImport; | 1090 | goto cancelImport; |
1080 | } | 1091 | } |
1081 | setVirgin(false); | 1092 | setVirgin(false); |
1082 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1093 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1083 | return true; | 1094 | return true; |
1084 | 1095 | ||
1085 | cancelImport: | 1096 | cancelImport: |
1086 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1097 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1087 | return false; | 1098 | return false; |
1088 | } | 1099 | } |
1089 | 1100 | ||
1090 | #ifdef CONFIG_KWALLETIF | 1101 | #ifdef CONFIG_KWALLETIF |
1091 | bool PwM::checkAndAskForKWalletEmu() | 1102 | bool PwM::checkAndAskForKWalletEmu() |
1092 | { | 1103 | { |
1093 | if (init->kwalletEmu()) { | 1104 | if (init->kwalletEmu()) { |
1094 | /* KWallet emulation is enabled. We can't import/export | 1105 | /* KWallet emulation is enabled. We can't import/export |
1095 | * data from/to it, while emulation is active. | 1106 | * data from/to it, while emulation is active. |
1096 | */ | 1107 | */ |
1097 | if (KMessageBox::questionYesNo(this, | 1108 | if (KMessageBox::questionYesNo(this, |
1098 | i18n("KWallet emulation is enabled.\n" | 1109 | i18n("KWallet emulation is enabled.\n" |
1099 | "You can't import or export data from/to " | 1110 | "You can't import or export data from/to " |
1100 | "the original KWallet, while the emulation " | 1111 | "the original KWallet, while the emulation " |
1101 | "is active.\n" | 1112 | "is active.\n" |
1102 | "Do you want to tempoarly disable the KWallet emulation?"), | 1113 | "Do you want to tempoarly disable the KWallet emulation?"), |
1103 | i18n("Tempoarly disable KWallet emulation?")) | 1114 | i18n("Tempoarly disable KWallet emulation?")) |
1104 | == KMessageBox::Yes) { | 1115 | == KMessageBox::Yes) { |
1105 | init->initKWalletEmu(true); | 1116 | init->initKWalletEmu(true); |
1106 | PWM_ASSERT(!init->kwalletEmu()); | 1117 | PWM_ASSERT(!init->kwalletEmu()); |
1107 | return true; | 1118 | return true; |
1108 | } | 1119 | } |
1109 | return false; | 1120 | return false; |
1110 | } | 1121 | } |
1111 | return true; | 1122 | return true; |
1112 | } | 1123 | } |
1113 | #endif // CONFIG_KWALLETIF | 1124 | #endif // CONFIG_KWALLETIF |
1114 | 1125 | ||
1115 | bool PwM::importKWallet() | 1126 | bool PwM::importKWallet() |
1116 | { | 1127 | { |
1117 | #ifdef CONFIG_KWALLETIF | 1128 | #ifdef CONFIG_KWALLETIF |
1118 | if (!checkAndAskForKWalletEmu()) | 1129 | if (!checkAndAskForKWalletEmu()) |
1119 | return false; | 1130 | return false; |
1120 | KWalletIf walletIf(this); | 1131 | KWalletIf walletIf(this); |
1121 | if (!isVirgin()) { | 1132 | if (!isVirgin()) { |
1122 | if (KMessageBox::questionYesNo(this, | 1133 | if (KMessageBox::questionYesNo(this, |
1123 | i18n("Do you want to import the data " | 1134 | i18n("Do you want to import the data " |
1124 | "into the current document? (If you " | 1135 | "into the current document? (If you " |
1125 | "select \"no\", a new document will be " | 1136 | "select \"no\", a new document will be " |
1126 | "opened.)"), | 1137 | "opened.)"), |
1127 | i18n("import into this document?")) | 1138 | i18n("import into this document?")) |
1128 | == KMessageBox::No) { | 1139 | == KMessageBox::No) { |
1129 | // import the data to a new window. | 1140 | // import the data to a new window. |
1130 | PwM *newInstance = init->createMainWnd(); | 1141 | PwM *newInstance = init->createMainWnd(); |
1131 | bool ok = newInstance->importKWallet(); | 1142 | bool ok = newInstance->importKWallet(); |
1132 | if (!ok) { | 1143 | if (!ok) { |
1133 | newInstance->setForceQuit(true); | 1144 | newInstance->setForceQuit(true); |
1134 | delete_and_null(newInstance); | 1145 | delete_and_null(newInstance); |
1135 | goto exit_fail; | 1146 | goto exit_fail; |
1136 | } else { | 1147 | } else { |
1137 | goto exit_ok; | 1148 | goto exit_ok; |
1138 | } | 1149 | } |
1139 | } | 1150 | } |
1140 | } | 1151 | } |
1141 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1152 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1142 | if (!walletIf.kwalletImport(curDoc())) { | 1153 | if (!walletIf.kwalletImport(curDoc())) { |
1143 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1154 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1144 | showStatMsg(i18n("KWallet import failed")); | 1155 | showStatMsg(i18n("KWallet import failed")); |
1145 | goto exit_fail; | 1156 | goto exit_fail; |
1146 | } | 1157 | } |
1147 | KMessageBox::information(this, | 1158 | KMessageBox::information(this, |
1148 | i18n("Successfully imported the KWallet data " | 1159 | i18n("Successfully imported the KWallet data " |
1149 | "into the current document."), | 1160 | "into the current document."), |
1150 | i18n("successfully imported")); | 1161 | i18n("successfully imported")); |
1151 | showStatMsg(i18n("successfully imported")); | 1162 | showStatMsg(i18n("successfully imported")); |
1152 | setVirgin(false); | 1163 | setVirgin(false); |
1153 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1164 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1154 | 1165 | ||
1155 | exit_ok: | 1166 | exit_ok: |
1156 | init->initKWalletEmu(); | 1167 | init->initKWalletEmu(); |
1157 | return true; | 1168 | return true; |
1158 | 1169 | ||
1159 | exit_fail: | 1170 | exit_fail: |
1160 | init->initKWalletEmu(); | 1171 | init->initKWalletEmu(); |
1161 | #endif // CONFIG_KWALLETIF | 1172 | #endif // CONFIG_KWALLETIF |
1162 | return false; | 1173 | return false; |
1163 | } | 1174 | } |
1164 | 1175 | ||
1165 | void PwM::print_slot() | 1176 | void PwM::print_slot() |
1166 | { | 1177 | { |
1167 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1178 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1168 | #ifndef PWM_EMBEDDED | 1179 | #ifndef PWM_EMBEDDED |
1169 | PwMPrint p(curDoc(), this); | 1180 | PwMPrint p(curDoc(), this); |
1170 | p.printNow(); | 1181 | p.printNow(); |
1171 | #else | 1182 | #else |
1172 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1183 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1173 | #endif | 1184 | #endif |
1174 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1185 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1175 | } | 1186 | } |
1176 | 1187 | ||
1177 | void PwM::genNewCard_slot() | 1188 | void PwM::genNewCard_slot() |
1178 | { | 1189 | { |
1179 | #ifdef CONFIG_KEYCARD | 1190 | #ifdef CONFIG_KEYCARD |
1180 | init->keycard()->genNewCard(); | 1191 | init->keycard()->genNewCard(); |
1181 | #endif | 1192 | #endif |
1182 | } | 1193 | } |
1183 | 1194 | ||
1184 | void PwM::eraseCard_slot() | 1195 | void PwM::eraseCard_slot() |
1185 | { | 1196 | { |
1186 | #ifdef CONFIG_KEYCARD | 1197 | #ifdef CONFIG_KEYCARD |
1187 | init->keycard()->eraseCard(); | 1198 | init->keycard()->eraseCard(); |
1188 | #endif | 1199 | #endif |
1189 | } | 1200 | } |
1190 | 1201 | ||
1191 | void PwM::readCardId_slot() | 1202 | void PwM::readCardId_slot() |
1192 | { | 1203 | { |
1193 | #ifdef CONFIG_KEYCARD | 1204 | #ifdef CONFIG_KEYCARD |
1194 | init->keycard()->displayKey(); | 1205 | init->keycard()->displayKey(); |
1195 | #endif | 1206 | #endif |
1196 | } | 1207 | } |
1197 | 1208 | ||
1198 | void PwM::makeCardBackup_slot() | 1209 | void PwM::makeCardBackup_slot() |
1199 | { | 1210 | { |
1200 | #ifdef CONFIG_KEYCARD | 1211 | #ifdef CONFIG_KEYCARD |
1201 | init->keycard()->makeBackupImage(); | 1212 | init->keycard()->makeBackupImage(); |
1202 | #endif | 1213 | #endif |
1203 | } | 1214 | } |
1204 | 1215 | ||
1205 | void PwM::replayCardBackup_slot() | 1216 | void PwM::replayCardBackup_slot() |
1206 | { | 1217 | { |
1207 | #ifdef CONFIG_KEYCARD | 1218 | #ifdef CONFIG_KEYCARD |
1208 | init->keycard()->replayBackupImage(); | 1219 | init->keycard()->replayBackupImage(); |
1209 | #endif | 1220 | #endif |
1210 | } | 1221 | } |
1211 | 1222 | ||
1212 | void PwM::execLauncher_slot() | 1223 | void PwM::execLauncher_slot() |
1213 | { | 1224 | { |
1214 | PWM_ASSERT(curDoc()); | 1225 | PWM_ASSERT(curDoc()); |
1215 | if (curDoc()->isDeepLocked()) | 1226 | if (curDoc()->isDeepLocked()) |
1216 | return; | 1227 | return; |
1217 | unsigned int curEntryIndex; | 1228 | unsigned int curEntryIndex; |
1218 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1229 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1219 | return; | 1230 | return; |
1220 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1231 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1221 | curEntryIndex); | 1232 | curEntryIndex); |
1222 | if (ret) | 1233 | if (ret) |
1223 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1234 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1224 | else | 1235 | else |
1225 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1236 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1226 | } | 1237 | } |
1227 | 1238 | ||
1228 | void PwM::goToURL_slot() | 1239 | void PwM::goToURL_slot() |
1229 | { | 1240 | { |
1230 | PWM_ASSERT(curDoc()); | 1241 | PWM_ASSERT(curDoc()); |
1231 | if (curDoc()->isDeepLocked()) | 1242 | if (curDoc()->isDeepLocked()) |
1232 | return; | 1243 | return; |
1233 | unsigned int curEntryIndex; | 1244 | unsigned int curEntryIndex; |
1234 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1245 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1235 | return; | 1246 | return; |
1236 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1247 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1237 | curEntryIndex); | 1248 | curEntryIndex); |
1238 | if (ret) | 1249 | if (ret) |
1239 | showStatMsg(i18n("started browser with current URL.")); | 1250 | showStatMsg(i18n("started browser with current URL.")); |
1240 | else | 1251 | else |
1241 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1252 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1242 | } | 1253 | } |
1243 | 1254 | ||
1244 | void PwM::copyToClipboard(const QString &s) | 1255 | void PwM::copyToClipboard(const QString &s) |
1245 | { | 1256 | { |
1246 | QClipboard *cb = QApplication::clipboard(); | 1257 | QClipboard *cb = QApplication::clipboard(); |
1247 | #ifndef PWM_EMBEDDED | 1258 | #ifndef PWM_EMBEDDED |
1248 | if (cb->supportsSelection()) | 1259 | if (cb->supportsSelection()) |
1249 | cb->setText(s, QClipboard::Selection); | 1260 | cb->setText(s, QClipboard::Selection); |
1250 | cb->setText(s, QClipboard::Clipboard); | 1261 | cb->setText(s, QClipboard::Clipboard); |
1251 | #else | 1262 | #else |
1252 | cb->setText(s); | 1263 | cb->setText(s); |
1253 | 1264 | ||
1254 | #endif | 1265 | #endif |
1255 | 1266 | ||
1256 | } | 1267 | } |
1257 | 1268 | ||
1258 | void PwM::showStatMsg(const QString &msg) | 1269 | void PwM::showStatMsg(const QString &msg) |
1259 | { | 1270 | { |
1260 | #ifndef PWM_EMBEDDED | 1271 | #ifndef PWM_EMBEDDED |
1261 | KStatusBar *statBar = statusBar(); | 1272 | KStatusBar *statBar = statusBar(); |
1262 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1273 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1263 | #else | 1274 | #else |
1264 | qDebug("Statusbar : %s",msg.latin1()); | 1275 | qDebug("Statusbar : %s",msg.latin1()); |
1265 | #endif | 1276 | #endif |
1266 | } | 1277 | } |
1267 | 1278 | ||
1268 | void PwM::focusInEvent(QFocusEvent *e) | 1279 | void PwM::focusInEvent(QFocusEvent *e) |
1269 | { | 1280 | { |
1270 | if (e->gotFocus()) { | 1281 | if (e->gotFocus()) { |
1271 | emit gotFocus(this); | 1282 | emit gotFocus(this); |
1272 | } else if (e->lostFocus()) { | 1283 | } else if (e->lostFocus()) { |
1273 | emit lostFocus(this); | 1284 | emit lostFocus(this); |
1274 | } | 1285 | } |
1275 | } | 1286 | } |
1276 | 1287 | ||
1277 | 1288 | ||
1278 | #ifdef PWM_EMBEDDED | 1289 | #ifdef PWM_EMBEDDED |
1279 | 1290 | ||
1280 | void PwM::showLicense_slot() | 1291 | void PwM::showLicense_slot() |
1281 | { | 1292 | { |
1282 | KApplication::showLicence(); | 1293 | KApplication::showLicence(); |
1283 | } | 1294 | } |
1284 | 1295 | ||
1285 | void PwM::faq_slot() | 1296 | void PwM::faq_slot() |
1286 | { | 1297 | { |
1287 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1298 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1288 | } | 1299 | } |
1289 | 1300 | ||
1301 | void PwM::syncHowTo_slot() | ||
1302 | { | ||
1303 | qDebug("PwM::syncHowTo_slot"); | ||
1304 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | ||
1305 | } | ||
1306 | |||
1307 | |||
1290 | void PwM::createAboutData_slot() | 1308 | void PwM::createAboutData_slot() |
1291 | { | 1309 | { |
1292 | QString version; | 1310 | QString version; |
1293 | #include <../version> | 1311 | #include <../version> |
1294 | QMessageBox::about( this, "About PwManager/Pi", | 1312 | QMessageBox::about( this, "About PwManager/Pi", |
1295 | "PwManager/Platform-independent\n" | 1313 | "PwManager/Platform-independent\n" |
1296 | "(PWM/Pi) " +version + " - " + | 1314 | "(PWM/Pi) " +version + " - " + |
1297 | #ifdef DESKTOP_VERSION | 1315 | #ifdef DESKTOP_VERSION |
1298 | "Desktop Edition\n" | 1316 | "Desktop Edition\n" |
1299 | #else | 1317 | #else |
1300 | "PDA-Edition\n" | 1318 | "PDA-Edition\n" |
1301 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1319 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1302 | #endif | 1320 | #endif |
1303 | 1321 | ||
1304 | "(c) 2004 Ulf Schenk\n" | 1322 | "(c) 2004 Ulf Schenk\n" |
1305 | "(c) 2004 Lutz Rogowski\n" | 1323 | "(c) 2004 Lutz Rogowski\n" |
1306 | "(c) 1997-2004, The KDE PIM Team\n" | 1324 | "(c) 1997-2004, The KDE PIM Team\n" |
1307 | 1325 | ||
1308 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1326 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1309 | "Matt Scifo - mscifo@o1.com\n" | 1327 | "Matt Scifo - mscifo@o1.com\n" |
1310 | "Elias Probst - elias.probst@gmx.de\n" | 1328 | "Elias Probst - elias.probst@gmx.de\n" |
1311 | "George Staikos - staikos@kde.org\n" | 1329 | "George Staikos - staikos@kde.org\n" |
1312 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1330 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1313 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1331 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1314 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1332 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1315 | "Troy Engel - tengel@sonic.net\n" | 1333 | "Troy Engel - tengel@sonic.net\n" |
1316 | "Wickey - wickey@gmx.at\n" | 1334 | "Wickey - wickey@gmx.at\n" |
1317 | "Ian MacGregor - original documentation author.\n" | 1335 | "Ian MacGregor - original documentation author.\n" |
1318 | ); | 1336 | ); |
1319 | } | 1337 | } |
1320 | 1338 | ||
1321 | 1339 | ||
1322 | //this are the overwritten callbackmethods from the syncinterface | 1340 | //this are the overwritten callbackmethods from the syncinterface |
1323 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1341 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1324 | { | 1342 | { |
1325 | PWM_ASSERT(curDoc()); | 1343 | PWM_ASSERT(curDoc()); |
1326 | 1344 | ||
1327 | bool ret = curDoc()->sync(manager, filename, mode); | 1345 | bool ret = curDoc()->sync(manager, filename, mode); |
1328 | 1346 | ||
1347 | qDebug("PwM::sync save now: ret=%i", ret); | ||
1348 | |||
1329 | if (ret == true) { | 1349 | if (ret == true) { |
1330 | //US BUG: what can we call here to update the view of the current doc? | 1350 | //US BUG: what can we call here to update the view of the current doc? |
1331 | //mViewManager->refreshView(); | 1351 | //mViewManager->refreshView(); |
1352 | |||
1353 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | ||
1354 | save(); | ||
1332 | } | 1355 | } |
1333 | 1356 | ||
1334 | return ret; | 1357 | return ret; |
1335 | } | 1358 | } |
1336 | |||
1337 | //called by the syncmanager to indicate that the work has to be marked as dirty. | ||
1338 | void PwM::sync_setModified() | ||
1339 | { | ||
1340 | PWM_ASSERT(curDoc()); | ||
1341 | curDoc()->sync_setModified(); | ||
1342 | } | ||
1343 | |||
1344 | //called by the syncmanager to ask if the dirty flag is set. | ||
1345 | bool PwM::sync_isModified() | ||
1346 | { | ||
1347 | PWM_ASSERT(curDoc()); | ||
1348 | return curDoc()->sync_isModified(); | ||
1349 | } | ||
1350 | |||
1351 | //called by the syncmanager to indicate that the work has to be saved. | ||
1352 | void PwM::sync_save() | ||
1353 | { | ||
1354 | PWM_ASSERT(curDoc()); | ||
1355 | return curDoc()->sync_save(); | ||
1356 | } | ||
1357 | |||
1358 | |||
1359 | |||
1360 | #endif | 1359 | #endif |
1361 | 1360 | ||
1362 | 1361 | ||
1363 | #ifndef PWM_EMBEDDED | 1362 | #ifndef PWM_EMBEDDED |
1364 | #include "pwm.moc" | 1363 | #include "pwm.moc" |
1365 | #endif | 1364 | #endif |
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h index 7c6bf0d..6ed9d34 100644 --- a/pwmanager/pwmanager/pwm.h +++ b/pwmanager/pwmanager/pwm.h | |||
@@ -1,297 +1,291 @@ | |||
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 | #ifndef __PWM_H | 20 | #ifndef __PWM_H |
21 | #define __PWM_H | 21 | #define __PWM_H |
22 | 22 | ||
23 | 23 | ||
24 | #include <kpopupmenu.h> | 24 | #include <kpopupmenu.h> |
25 | #include <klistview.h> | 25 | #include <klistview.h> |
26 | #include <kmainwindow.h> | 26 | #include <kmainwindow.h> |
27 | 27 | ||
28 | #ifndef PWM_EMBEDDED | 28 | #ifndef PWM_EMBEDDED |
29 | #include <kwin.h> | 29 | #include <kwin.h> |
30 | #include <kapp.h> | 30 | #include <kapp.h> |
31 | #include <kdeversion.h> | 31 | #include <kdeversion.h> |
32 | #else | 32 | #else |
33 | #include <ksyncmanager.h> | 33 | #include <ksyncmanager.h> |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #include <kaction.h> | 36 | #include <kaction.h> |
37 | 37 | ||
38 | #include <qglobal.h> | 38 | #include <qglobal.h> |
39 | 39 | ||
40 | #include "pwmview.h" | 40 | #include "pwmview.h" |
41 | #include "pwmexception.h" | 41 | #include "pwmexception.h" |
42 | 42 | ||
43 | 43 | ||
44 | /** timeout for displaying a message on the status-bar (in seconds) */ | 44 | /** timeout for displaying a message on the status-bar (in seconds) */ |
45 | #define STATUSBAR_MSG_TIMEOUT5 | 45 | #define STATUSBAR_MSG_TIMEOUT5 |
46 | 46 | ||
47 | 47 | ||
48 | class PwMInit; | 48 | class PwMInit; |
49 | class KSyncManager; | 49 | class KSyncManager; |
50 | 50 | ||
51 | /** PwM is the base class of the project */ | 51 | /** PwM is the base class of the project */ |
52 | #ifndef PWM_EMBEDDED | 52 | #ifndef PWM_EMBEDDED |
53 | //MOC_SKIP_BEGIN | 53 | //MOC_SKIP_BEGIN |
54 | class PwM : public KMainWindow | 54 | class PwM : public KMainWindow |
55 | //MOC_SKIP_END | 55 | //MOC_SKIP_END |
56 | #else | 56 | #else |
57 | class PwM : public KMainWindow, public KSyncInterface | 57 | class PwM : public KMainWindow, public KSyncInterface |
58 | #endif | 58 | #endif |
59 | { | 59 | { |
60 | Q_OBJECT | 60 | Q_OBJECT |
61 | public: | 61 | public: |
62 | friend class PwMView; | 62 | friend class PwMView; |
63 | /** construtor */ | 63 | /** construtor */ |
64 | PwM(PwMInit *_init, PwMDoc *doc, | 64 | PwM(PwMInit *_init, PwMDoc *doc, |
65 | bool virginity = true, | 65 | bool virginity = true, |
66 | QWidget* parent = 0, const char *name = 0); | 66 | QWidget* parent = 0, const char *name = 0); |
67 | /** destructor */ | 67 | /** destructor */ |
68 | ~PwM(); | 68 | ~PwM(); |
69 | 69 | ||
70 | /** copy some text to the global clipboard */ | 70 | /** copy some text to the global clipboard */ |
71 | static void copyToClipboard(const QString &s); | 71 | static void copyToClipboard(const QString &s); |
72 | 72 | ||
73 | /** returns pointer to the view */ | 73 | /** returns pointer to the view */ |
74 | PwMView * curView() | 74 | PwMView * curView() |
75 | { return view; } | 75 | { return view; } |
76 | /** returns pointer to the currently using document. */ | 76 | /** returns pointer to the currently using document. */ |
77 | PwMDoc * curDoc() | 77 | PwMDoc * curDoc() |
78 | { return curView()->document(); } | 78 | { return curView()->document(); } |
79 | /** open a new doc with the given filename */ | 79 | /** open a new doc with the given filename */ |
80 | PwMDoc * openDoc(QString filename, bool openDeepLocked = false); | 80 | PwMDoc * openDoc(QString filename, bool openDeepLocked = false); |
81 | /** show a message on the global status bar. | 81 | /** show a message on the global status bar. |
82 | * The message times out after some seconds. | 82 | * The message times out after some seconds. |
83 | */ | 83 | */ |
84 | void showStatMsg(const QString &msg); | 84 | void showStatMsg(const QString &msg); |
85 | /** ask the user where to save the doc (if it has not been saved, yet) | 85 | /** ask the user where to save the doc (if it has not been saved, yet) |
86 | * and write the data to disk. | 86 | * and write the data to disk. |
87 | */ | 87 | */ |
88 | bool save(); | 88 | bool save(); |
89 | /** ask the user where to save the doc | 89 | /** ask the user where to save the doc |
90 | * and write the data to disk. | 90 | * and write the data to disk. |
91 | */ | 91 | */ |
92 | bool saveAs(); | 92 | bool saveAs(); |
93 | /** force quit. Quit this window, always! Don't minimize it */ | 93 | /** force quit. Quit this window, always! Don't minimize it */ |
94 | bool isForceQuit() | 94 | bool isForceQuit() |
95 | { return forceQuit; } | 95 | { return forceQuit; } |
96 | /** set forceQuit */ | 96 | /** set forceQuit */ |
97 | void setForceQuit(bool force) | 97 | void setForceQuit(bool force) |
98 | { forceQuit = force; } | 98 | { forceQuit = force; } |
99 | /** force minimize this window */ | 99 | /** force minimize this window */ |
100 | bool isForceMinimizeToTray() | 100 | bool isForceMinimizeToTray() |
101 | { return forceMinimizeToTray; } | 101 | { return forceMinimizeToTray; } |
102 | /** set forceMinimizeToTray */ | 102 | /** set forceMinimizeToTray */ |
103 | void setForceMinimizeToTray(bool force) | 103 | void setForceMinimizeToTray(bool force) |
104 | { forceMinimizeToTray = force; } | 104 | { forceMinimizeToTray = force; } |
105 | 105 | ||
106 | public slots: | 106 | public slots: |
107 | /** file/new triggered */ | 107 | /** file/new triggered */ |
108 | void new_slot(); | 108 | void new_slot(); |
109 | /** file/open triggered */ | 109 | /** file/open triggered */ |
110 | //US ENH | 110 | //US ENH |
111 | void open_slot(); | 111 | void open_slot(); |
112 | void open_slot(QString fn); | 112 | void open_slot(QString fn); |
113 | /** file/close triggered */ | 113 | /** file/close triggered */ |
114 | void close_slot(); | 114 | void close_slot(); |
115 | /** file/quit triggered */ | 115 | /** file/quit triggered */ |
116 | void quitButton_slot(); | 116 | void quitButton_slot(); |
117 | /** file/save triggered */ | 117 | /** file/save triggered */ |
118 | void save_slot(); | 118 | void save_slot(); |
119 | /** file/saveAs triggered */ | 119 | /** file/saveAs triggered */ |
120 | void saveAs_slot(); | 120 | void saveAs_slot(); |
121 | /** file/export/text triggered */ | 121 | /** file/export/text triggered */ |
122 | void exportToText(); | 122 | void exportToText(); |
123 | /** file/export/gpasman triggered */ | 123 | /** file/export/gpasman triggered */ |
124 | void exportToGpasman(); | 124 | void exportToGpasman(); |
125 | /** file/export/kwallet triggered */ | 125 | /** file/export/kwallet triggered */ |
126 | void exportToKWallet(); | 126 | void exportToKWallet(); |
127 | /** file/import/text triggered */ | 127 | /** file/import/text triggered */ |
128 | bool importFromText(); | 128 | bool importFromText(); |
129 | /** file/import/gpasman triggered */ | 129 | /** file/import/gpasman triggered */ |
130 | bool importFromGpasman(); | 130 | bool importFromGpasman(); |
131 | /** file/import/kwallet triggered */ | 131 | /** file/import/kwallet triggered */ |
132 | bool importKWallet(); | 132 | bool importKWallet(); |
133 | /** file/print triggered */ | 133 | /** file/print triggered */ |
134 | void print_slot(); | 134 | void print_slot(); |
135 | /** manage/add triggered */ | 135 | /** manage/add triggered */ |
136 | //US ENH : changed code to run with older MOC | 136 | //US ENH : changed code to run with older MOC |
137 | void addPwd_slot(); | 137 | void addPwd_slot(); |
138 | void addPwd_slot(QString *pw, PwMDoc *_doc); | 138 | void addPwd_slot(QString *pw, PwMDoc *_doc); |
139 | /** manage/edit triggered */ | 139 | /** manage/edit triggered */ |
140 | //US ENH : changed code to run with older MOC | 140 | //US ENH : changed code to run with older MOC |
141 | void editPwd_slot(); | 141 | void editPwd_slot(); |
142 | void editPwd_slot(const QString *category); | 142 | void editPwd_slot(const QString *category); |
143 | void editPwd_slot(const QString *category = 0, const int *index = 0, | 143 | void editPwd_slot(const QString *category = 0, const int *index = 0, |
144 | PwMDoc *_doc = 0); | 144 | PwMDoc *_doc = 0); |
145 | /** manage/delete triggered */ | 145 | /** manage/delete triggered */ |
146 | void deletePwd_slot(); | 146 | void deletePwd_slot(); |
147 | /** execute the "Launcher" entry */ | 147 | /** execute the "Launcher" entry */ |
148 | void execLauncher_slot(); | 148 | void execLauncher_slot(); |
149 | /** open browser with URL entry */ | 149 | /** open browser with URL entry */ |
150 | void goToURL_slot(); | 150 | void goToURL_slot(); |
151 | /** manage/changeMasterPwd triggered */ | 151 | /** manage/changeMasterPwd triggered */ |
152 | void changeMasterPwd_slot(); | 152 | void changeMasterPwd_slot(); |
153 | /** lock current document */ | 153 | /** lock current document */ |
154 | void lockWnd_slot(); | 154 | void lockWnd_slot(); |
155 | /** deeplock current document */ | 155 | /** deeplock current document */ |
156 | void deepLockWnd_slot(); | 156 | void deepLockWnd_slot(); |
157 | /** window/unlock triggered */ | 157 | /** window/unlock triggered */ |
158 | void unlockWnd_slot(); | 158 | void unlockWnd_slot(); |
159 | /** find item */ | 159 | /** find item */ |
160 | void find_slot(); | 160 | void find_slot(); |
161 | /** configure clicked */ | 161 | /** configure clicked */ |
162 | void config_slot(); | 162 | void config_slot(); |
163 | /** (de)activate the "change master pw" button in the menu-bar */ | 163 | /** (de)activate the "change master pw" button in the menu-bar */ |
164 | void activateMpButton(bool activate = true); | 164 | void activateMpButton(bool activate = true); |
165 | /** generate a new chipcard */ | 165 | /** generate a new chipcard */ |
166 | void genNewCard_slot(); | 166 | void genNewCard_slot(); |
167 | /** completely erase the current card */ | 167 | /** completely erase the current card */ |
168 | void eraseCard_slot(); | 168 | void eraseCard_slot(); |
169 | /** returns the ID number of the current card */ | 169 | /** returns the ID number of the current card */ |
170 | void readCardId_slot(); | 170 | void readCardId_slot(); |
171 | /** make backup image of the current card */ | 171 | /** make backup image of the current card */ |
172 | void makeCardBackup_slot(); | 172 | void makeCardBackup_slot(); |
173 | /** write backup image to current card */ | 173 | /** write backup image to current card */ |
174 | void replayCardBackup_slot(); | 174 | void replayCardBackup_slot(); |
175 | 175 | ||
176 | #ifdef PWM_EMBEDDED | 176 | #ifdef PWM_EMBEDDED |
177 | void showLicense_slot(); | 177 | void showLicense_slot(); |
178 | void faq_slot(); | 178 | void faq_slot(); |
179 | void createAboutData_slot(); | 179 | void createAboutData_slot(); |
180 | void syncHowTo_slot(); | ||
180 | #endif | 181 | #endif |
181 | 182 | ||
182 | protected: | 183 | protected: |
183 | /** is this window virgin? */ | 184 | /** is this window virgin? */ |
184 | bool isVirgin() | 185 | bool isVirgin() |
185 | { return virgin; } | 186 | { return virgin; } |
186 | /** add/remove virginity */ | 187 | /** add/remove virginity */ |
187 | void setVirgin(bool v); | 188 | void setVirgin(bool v); |
188 | /** initialize the menubar */ | 189 | /** initialize the menubar */ |
189 | void initMenubar(); | 190 | void initMenubar(); |
190 | /** initialize the toolbar */ | 191 | /** initialize the toolbar */ |
191 | void initToolbar(); | 192 | void initToolbar(); |
192 | /** initialize the window-metrics */ | 193 | /** initialize the window-metrics */ |
193 | void initMetrics(); | 194 | void initMetrics(); |
194 | /** close-event */ | 195 | /** close-event */ |
195 | void closeEvent(QCloseEvent *e); | 196 | void closeEvent(QCloseEvent *e); |
196 | /** creates a new PwM-ListView and returns it */ | 197 | /** creates a new PwM-ListView and returns it */ |
197 | PwMView * makeNewListView(PwMDoc *doc); | 198 | PwMView * makeNewListView(PwMDoc *doc); |
198 | /** Window hide-event */ | 199 | /** Window hide-event */ |
199 | void hideEvent(QHideEvent *); | 200 | void hideEvent(QHideEvent *); |
200 | /** is this window minimized? */ | 201 | /** is this window minimized? */ |
201 | bool isMinimized() | 202 | bool isMinimized() |
202 | { | 203 | { |
203 | #ifndef PWM_EMBEDDED | 204 | #ifndef PWM_EMBEDDED |
204 | #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) | 205 | #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) |
205 | return KWin::windowInfo(winId()).isMinimized(); | 206 | return KWin::windowInfo(winId()).isMinimized(); |
206 | #else // KDE_VERSION | 207 | #else // KDE_VERSION |
207 | return KWin::info(winId()).isIconified(); | 208 | return KWin::info(winId()).isIconified(); |
208 | #endif // KDE_VERSION | 209 | #endif // KDE_VERSION |
209 | #else | 210 | #else |
210 | return false; | 211 | return false; |
211 | #endif | 212 | #endif |
212 | } | 213 | } |
213 | /** window got the focus */ | 214 | /** window got the focus */ |
214 | void focusInEvent(QFocusEvent *e); | 215 | void focusInEvent(QFocusEvent *e); |
215 | /** update the caption string */ | 216 | /** update the caption string */ |
216 | void updateCaption(); | 217 | void updateCaption(); |
217 | #ifdef CONFIG_KWALLETIF | 218 | #ifdef CONFIG_KWALLETIF |
218 | /** check if kwalletemu is enabled and ask the user what to do */ | 219 | /** check if kwalletemu is enabled and ask the user what to do */ |
219 | bool checkAndAskForKWalletEmu(); | 220 | bool checkAndAskForKWalletEmu(); |
220 | #endif // CONFIG_KWALLETIF | 221 | #endif // CONFIG_KWALLETIF |
221 | 222 | ||
222 | protected slots: | 223 | protected slots: |
223 | /** doc got closed */ | 224 | /** doc got closed */ |
224 | void docClosed(PwMDoc *doc); | 225 | void docClosed(PwMDoc *doc); |
225 | 226 | ||
226 | signals: | 227 | signals: |
227 | /** window got closed (by user or someone else) */ | 228 | /** window got closed (by user or someone else) */ |
228 | void closed(PwM *wnd); | 229 | void closed(PwM *wnd); |
229 | /** window got the focus (was brought to foreground) */ | 230 | /** window got the focus (was brought to foreground) */ |
230 | void gotFocus(PwM *wnd); | 231 | void gotFocus(PwM *wnd); |
231 | /** window lost the focus */ | 232 | /** window lost the focus */ |
232 | void lostFocus(PwM *wnd); | 233 | void lostFocus(PwM *wnd); |
233 | 234 | ||
234 | protected: | 235 | protected: |
235 | /** pointer to the view active in this KMainWindow */ | 236 | /** pointer to the view active in this KMainWindow */ |
236 | PwMView *view; | 237 | PwMView *view; |
237 | /** pointer to the init class */ | 238 | /** pointer to the init class */ |
238 | PwMInit *init; | 239 | PwMInit *init; |
239 | /** has this window already lost its virginity? | 240 | /** has this window already lost its virginity? |
240 | * Means is there an open working document | 241 | * Means is there an open working document |
241 | */ | 242 | */ |
242 | bool virgin; | 243 | bool virgin; |
243 | /** "file" popup-menu */ | 244 | /** "file" popup-menu */ |
244 | KPopupMenu *filePopup; | 245 | KPopupMenu *filePopup; |
245 | 246 | ||
246 | /** "manage" popup-menu */ | 247 | /** "manage" popup-menu */ |
247 | KPopupMenu *managePopup; | 248 | KPopupMenu *managePopup; |
248 | #ifdef CONFIG_KEYCARD | 249 | #ifdef CONFIG_KEYCARD |
249 | /** "chipcard" popup-menu */ | 250 | /** "chipcard" popup-menu */ |
250 | KPopupMenu *chipcardPopup; | 251 | KPopupMenu *chipcardPopup; |
251 | #endif // CONFIG_KEYCARD | 252 | #endif // CONFIG_KEYCARD |
252 | /** "view" popup-menu */ | 253 | /** "view" popup-menu */ |
253 | KPopupMenu *viewPopup; | 254 | KPopupMenu *viewPopup; |
254 | /** "options" popup-menu */ | 255 | /** "options" popup-menu */ |
255 | KPopupMenu *optionsPopup; | 256 | KPopupMenu *optionsPopup; |
256 | /** "help" popup-menu */ | 257 | /** "help" popup-menu */ |
257 | KPopupMenu *helpPopup; | 258 | KPopupMenu *helpPopup; |
258 | /** "export" popup-menu */ | 259 | /** "export" popup-menu */ |
259 | KPopupMenu *exportPopup; | 260 | KPopupMenu *exportPopup; |
260 | /** "import" popup-menu */ | 261 | /** "import" popup-menu */ |
261 | KPopupMenu *importPopup; | 262 | KPopupMenu *importPopup; |
262 | /** force quit this window? */ | 263 | /** force quit this window? */ |
263 | bool forceQuit; | 264 | bool forceQuit; |
264 | /** force minimize this window to the tray */ | 265 | /** force minimize this window to the tray */ |
265 | bool forceMinimizeToTray; | 266 | bool forceMinimizeToTray; |
266 | 267 | ||
267 | 268 | ||
268 | 269 | ||
269 | 270 | ||
270 | private: | 271 | private: |
271 | #ifdef PWM_EMBEDDED | 272 | #ifdef PWM_EMBEDDED |
272 | //this are the overwritten callbackmethods from the syncinterface | 273 | //this are the overwritten callbackmethods from the syncinterface |
273 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 274 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
274 | 275 | ||
275 | //called by the syncmanager to indicate that the work has to marked as dirty. | ||
276 | virtual void sync_setModified(); | ||
277 | //called by the syncmanager to ask if the dirty flag is set. | ||
278 | virtual bool sync_isModified(); | ||
279 | //called by the syncmanager to indicate that the work has to be saved. | ||
280 | virtual void sync_save(); | ||
281 | |||
282 | // LR ******************************* | 276 | // LR ******************************* |
283 | // sync stuff! | 277 | // sync stuff! |
284 | QPopupMenu *syncPopup; | 278 | QPopupMenu *syncPopup; |
285 | KSyncManager* syncManager; | 279 | KSyncManager* syncManager; |
286 | #endif | 280 | #endif |
287 | 281 | ||
288 | 282 | ||
289 | 283 | ||
290 | 284 | ||
291 | 285 | ||
292 | 286 | ||
293 | 287 | ||
294 | 288 | ||
295 | }; | 289 | }; |
296 | 290 | ||
297 | #endif | 291 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 0ac5517..2a7b11d 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,3411 +1,3432 @@ | |||
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 2.0 of pwmanager | 14 | * This file is originaly based on version 2.0 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmdoc.h" | 20 | #include "pwmdoc.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "blowfish.h" | 22 | #include "blowfish.h" |
23 | #include "sha1.h" | 23 | #include "sha1.h" |
24 | #include "globalstuff.h" | 24 | #include "globalstuff.h" |
25 | #include "gpasmanfile.h" | 25 | #include "gpasmanfile.h" |
26 | #include "serializer.h" | 26 | #include "serializer.h" |
27 | #include "compressgzip.h" | 27 | #include "compressgzip.h" |
28 | //US#include "compressbzip2.h" | 28 | //US#include "compressbzip2.h" |
29 | #include "randomizer.h" | 29 | #include "randomizer.h" |
30 | #include "pwminit.h" | 30 | #include "pwminit.h" |
31 | #include "libgcryptif.h" | 31 | #include "libgcryptif.h" |
32 | #ifdef PWM_EMBEDDED | 32 | #ifdef PWM_EMBEDDED |
33 | #include "pwmprefs.h" | 33 | #include "pwmprefs.h" |
34 | #include "kglobal.h" | 34 | #include "kglobal.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <kmessagebox.h> | 37 | #include <kmessagebox.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | 40 | ||
41 | #ifdef CONFIG_KWALLETIF | 41 | #ifdef CONFIG_KWALLETIF |
42 | # include "kwalletemu.h" | 42 | # include "kwalletemu.h" |
43 | #endif // CONFIG_KWALLETIF | 43 | #endif // CONFIG_KWALLETIF |
44 | 44 | ||
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | #include <qsize.h> | 46 | #include <qsize.h> |
47 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | 49 | ||
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | #include <string.h> | 53 | #include <string.h> |
54 | //US#include <iostream> | 54 | //US#include <iostream> |
55 | #include <algorithm> | 55 | #include <algorithm> |
56 | #include <sys/types.h> | 56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | 57 | #include <sys/stat.h> |
58 | #include <unistd.h> | 58 | #include <unistd.h> |
59 | #include <stdint.h> | 59 | #include <stdint.h> |
60 | 60 | ||
61 | 61 | ||
62 | #ifdef PWM_EMBEDDED | 62 | #ifdef PWM_EMBEDDED |
63 | #ifndef Q_LONG | 63 | #ifndef Q_LONG |
64 | #define Q_LONG long | 64 | #define Q_LONG long |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #ifndef Q_ULONG | 67 | #ifndef Q_ULONG |
68 | #define Q_ULONG unsigned long | 68 | #define Q_ULONG unsigned long |
69 | #endif | 69 | #endif |
70 | #endif //PWM_EMBEDDED | 70 | #endif //PWM_EMBEDDED |
71 | 71 | ||
72 | 72 | ||
73 | //TODO: reset to its normal value. | 73 | //TODO: reset to its normal value. |
74 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 74 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
75 | 75 | ||
76 | using namespace std; | 76 | using namespace std; |
77 | 77 | ||
78 | 78 | ||
79 | void PwMDocList::add(PwMDoc *doc, const string &id) | 79 | void PwMDocList::add(PwMDoc *doc, const string &id) |
80 | { | 80 | { |
81 | #ifdef PWM_DEBUG | 81 | #ifdef PWM_DEBUG |
82 | // check for existance of object in debug mode only. | 82 | // check for existance of object in debug mode only. |
83 | vector<listItem>::iterator begin = docList.begin(), | 83 | vector<listItem>::iterator begin = docList.begin(), |
84 | end = docList.end(), | 84 | end = docList.end(), |
85 | i = begin; | 85 | i = begin; |
86 | while (i != end) { | 86 | while (i != end) { |
87 | if (i->doc == doc) { | 87 | if (i->doc == doc) { |
88 | BUG(); | 88 | BUG(); |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | ++i; | 91 | ++i; |
92 | } | 92 | } |
93 | #endif | 93 | #endif |
94 | listItem newItem; | 94 | listItem newItem; |
95 | newItem.doc = doc; | 95 | newItem.doc = doc; |
96 | newItem.docId = id; | 96 | newItem.docId = id; |
97 | docList.push_back(newItem); | 97 | docList.push_back(newItem); |
98 | } | 98 | } |
99 | 99 | ||
100 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 100 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
101 | { | 101 | { |
102 | vector<listItem>::iterator begin = docList.begin(), | 102 | vector<listItem>::iterator begin = docList.begin(), |
103 | end = docList.end(), | 103 | end = docList.end(), |
104 | i = begin; | 104 | i = begin; |
105 | while (i != end) { | 105 | while (i != end) { |
106 | if (i->doc == doc) { | 106 | if (i->doc == doc) { |
107 | i->docId = newId; | 107 | i->docId = newId; |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | ++i; | 110 | ++i; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | void PwMDocList::del(PwMDoc *doc) | 114 | void PwMDocList::del(PwMDoc *doc) |
115 | { | 115 | { |
116 | vector<listItem>::iterator begin = docList.begin(), | 116 | vector<listItem>::iterator begin = docList.begin(), |
117 | end = docList.end(), | 117 | end = docList.end(), |
118 | i = begin; | 118 | i = begin; |
119 | while (i != end) { | 119 | while (i != end) { |
120 | if (i->doc == doc) { | 120 | if (i->doc == doc) { |
121 | docList.erase(i); | 121 | docList.erase(i); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | ++i; | 124 | ++i; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | bool PwMDocList::find(const string &id, listItem *ret) | 128 | bool PwMDocList::find(const string &id, listItem *ret) |
129 | { | 129 | { |
130 | vector<listItem>::iterator begin = docList.begin(), | 130 | vector<listItem>::iterator begin = docList.begin(), |
131 | end = docList.end(), | 131 | end = docList.end(), |
132 | i = begin; | 132 | i = begin; |
133 | while (i != end) { | 133 | while (i != end) { |
134 | if (i->docId == id) { | 134 | if (i->docId == id) { |
135 | if (ret) | 135 | if (ret) |
136 | *ret = *i; | 136 | *ret = *i; |
137 | return true; | 137 | return true; |
138 | } | 138 | } |
139 | ++i; | 139 | ++i; |
140 | } | 140 | } |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | DocTimer::DocTimer(PwMDoc *_doc) | 146 | DocTimer::DocTimer(PwMDoc *_doc) |
147 | : doc (_doc) | 147 | : doc (_doc) |
148 | , mpwLock (0) | 148 | , mpwLock (0) |
149 | , autoLockLock (0) | 149 | , autoLockLock (0) |
150 | , metaCheckLock (0) | 150 | , metaCheckLock (0) |
151 | { | 151 | { |
152 | mpwTimer = new QTimer; | 152 | mpwTimer = new QTimer; |
153 | autoLockTimer = new QTimer; | 153 | autoLockTimer = new QTimer; |
154 | metaCheckTimer = new QTimer; | 154 | metaCheckTimer = new QTimer; |
155 | connect(mpwTimer, SIGNAL(timeout()), | 155 | connect(mpwTimer, SIGNAL(timeout()), |
156 | this, SLOT(mpwTimeout())); | 156 | this, SLOT(mpwTimeout())); |
157 | connect(autoLockTimer, SIGNAL(timeout()), | 157 | connect(autoLockTimer, SIGNAL(timeout()), |
158 | this, SLOT(autoLockTimeout())); | 158 | this, SLOT(autoLockTimeout())); |
159 | connect(metaCheckTimer, SIGNAL(timeout()), | 159 | connect(metaCheckTimer, SIGNAL(timeout()), |
160 | this, SLOT(metaCheckTimeout())); | 160 | this, SLOT(metaCheckTimeout())); |
161 | } | 161 | } |
162 | 162 | ||
163 | DocTimer::~DocTimer() | 163 | DocTimer::~DocTimer() |
164 | { | 164 | { |
165 | delete mpwTimer; | 165 | delete mpwTimer; |
166 | delete autoLockTimer; | 166 | delete autoLockTimer; |
167 | delete metaCheckTimer; | 167 | delete metaCheckTimer; |
168 | } | 168 | } |
169 | 169 | ||
170 | void DocTimer::start(TimerIDs timer) | 170 | void DocTimer::start(TimerIDs timer) |
171 | { | 171 | { |
172 | switch (timer) { | 172 | switch (timer) { |
173 | case id_mpwTimer: | 173 | case id_mpwTimer: |
174 | if (mpwTimer->isActive()) | 174 | if (mpwTimer->isActive()) |
175 | mpwTimer->stop(); | 175 | mpwTimer->stop(); |
176 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 176 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
177 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 177 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
178 | break; | 178 | break; |
179 | case id_autoLockTimer: | 179 | case id_autoLockTimer: |
180 | if (autoLockTimer->isActive()) | 180 | if (autoLockTimer->isActive()) |
181 | autoLockTimer->stop(); | 181 | autoLockTimer->stop(); |
182 | if (conf()->confGlobLockTimeout() > 0) | 182 | if (conf()->confGlobLockTimeout() > 0) |
183 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 183 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
184 | break; | 184 | break; |
185 | case id_metaCheckTimer: | 185 | case id_metaCheckTimer: |
186 | if (metaCheckTimer->isActive()) | 186 | if (metaCheckTimer->isActive()) |
187 | metaCheckTimer->stop(); | 187 | metaCheckTimer->stop(); |
188 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 188 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
189 | break; | 189 | break; |
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
193 | void DocTimer::stop(TimerIDs timer) | 193 | void DocTimer::stop(TimerIDs timer) |
194 | { | 194 | { |
195 | switch (timer) { | 195 | switch (timer) { |
196 | case id_mpwTimer: | 196 | case id_mpwTimer: |
197 | mpwTimer->stop(); | 197 | mpwTimer->stop(); |
198 | break; | 198 | break; |
199 | case id_autoLockTimer: | 199 | case id_autoLockTimer: |
200 | autoLockTimer->stop(); | 200 | autoLockTimer->stop(); |
201 | break; | 201 | break; |
202 | case id_metaCheckTimer: | 202 | case id_metaCheckTimer: |
203 | metaCheckTimer->stop(); | 203 | metaCheckTimer->stop(); |
204 | break; | 204 | break; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | void DocTimer::getLock(TimerIDs timer) | 208 | void DocTimer::getLock(TimerIDs timer) |
209 | { | 209 | { |
210 | switch (timer) { | 210 | switch (timer) { |
211 | case id_mpwTimer: | 211 | case id_mpwTimer: |
212 | ++mpwLock; | 212 | ++mpwLock; |
213 | break; | 213 | break; |
214 | case id_autoLockTimer: | 214 | case id_autoLockTimer: |
215 | ++autoLockLock; | 215 | ++autoLockLock; |
216 | break; | 216 | break; |
217 | case id_metaCheckTimer: | 217 | case id_metaCheckTimer: |
218 | ++metaCheckLock; | 218 | ++metaCheckLock; |
219 | break; | 219 | break; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | void DocTimer::putLock(TimerIDs timer) | 223 | void DocTimer::putLock(TimerIDs timer) |
224 | { | 224 | { |
225 | switch (timer) { | 225 | switch (timer) { |
226 | case id_mpwTimer: | 226 | case id_mpwTimer: |
227 | if (mpwLock) | 227 | if (mpwLock) |
228 | --mpwLock; | 228 | --mpwLock; |
229 | break; | 229 | break; |
230 | case id_autoLockTimer: | 230 | case id_autoLockTimer: |
231 | if (autoLockLock) | 231 | if (autoLockLock) |
232 | --autoLockLock; | 232 | --autoLockLock; |
233 | break; | 233 | break; |
234 | case id_metaCheckTimer: | 234 | case id_metaCheckTimer: |
235 | if (metaCheckLock) | 235 | if (metaCheckLock) |
236 | --metaCheckLock; | 236 | --metaCheckLock; |
237 | break; | 237 | break; |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | void DocTimer::mpwTimeout() | 241 | void DocTimer::mpwTimeout() |
242 | { | 242 | { |
243 | if (mpwLock) { | 243 | if (mpwLock) { |
244 | mpwTimer->start(1000, true); | 244 | mpwTimer->start(1000, true); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 247 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
248 | } | 248 | } |
249 | 249 | ||
250 | void DocTimer::autoLockTimeout() | 250 | void DocTimer::autoLockTimeout() |
251 | { | 251 | { |
252 | if (autoLockLock) { | 252 | if (autoLockLock) { |
253 | autoLockTimer->start(1000, true); | 253 | autoLockTimer->start(1000, true); |
254 | return; | 254 | return; |
255 | } | 255 | } |
256 | if (conf()->confGlobAutoDeepLock() && | 256 | if (conf()->confGlobAutoDeepLock() && |
257 | doc->filename != QString::null && | 257 | doc->filename != QString::null && |
258 | doc->filename != "") { | 258 | doc->filename != "") { |
259 | doc->deepLock(true); | 259 | doc->deepLock(true); |
260 | } else { | 260 | } else { |
261 | doc->lockAll(true); | 261 | doc->lockAll(true); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | void DocTimer::metaCheckTimeout() | 265 | void DocTimer::metaCheckTimeout() |
266 | { | 266 | { |
267 | if (metaCheckLock) { | 267 | if (metaCheckLock) { |
268 | // check again in one second. | 268 | // check again in one second. |
269 | metaCheckTimer->start(1000, true); | 269 | metaCheckTimer->start(1000, true); |
270 | return; | 270 | return; |
271 | } | 271 | } |
272 | if (doc->isDeepLocked()) { | 272 | if (doc->isDeepLocked()) { |
273 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 273 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | if (doc->isDocEmpty()) { | 276 | if (doc->isDocEmpty()) { |
277 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 277 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
278 | return; | 278 | return; |
279 | } | 279 | } |
280 | #ifdef CONFIG_KWALLETIF | 280 | #ifdef CONFIG_KWALLETIF |
281 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 281 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
282 | if (kwlEmu) | 282 | if (kwlEmu) |
283 | kwlEmu->suspendDocSignals(); | 283 | kwlEmu->suspendDocSignals(); |
284 | #endif // CONFIG_KWALLETIF | 284 | #endif // CONFIG_KWALLETIF |
285 | /* We simply trigger all views to update their | 285 | /* We simply trigger all views to update their |
286 | * displayed values. This way they have a chance | 286 | * displayed values. This way they have a chance |
287 | * to get notified when some meta changes over time. | 287 | * to get notified when some meta changes over time. |
288 | * (for example an entry expired). | 288 | * (for example an entry expired). |
289 | * The _view_ is responsive for not updating its | 289 | * The _view_ is responsive for not updating its |
290 | * contents if nothing really changed! | 290 | * contents if nothing really changed! |
291 | */ | 291 | */ |
292 | emit doc->dataChanged(doc); | 292 | emit doc->dataChanged(doc); |
293 | #ifdef CONFIG_KWALLETIF | 293 | #ifdef CONFIG_KWALLETIF |
294 | if (kwlEmu) | 294 | if (kwlEmu) |
295 | kwlEmu->resumeDocSignals(); | 295 | kwlEmu->resumeDocSignals(); |
296 | #endif // CONFIG_KWALLETIF | 296 | #endif // CONFIG_KWALLETIF |
297 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 297 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | 301 | ||
302 | PwMDocList PwMDoc::openDocList; | 302 | PwMDocList PwMDoc::openDocList; |
303 | unsigned int PwMDocList::unnamedDocCnt = 1; | 303 | unsigned int PwMDocList::unnamedDocCnt = 1; |
304 | 304 | ||
305 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 305 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
306 | : PwMDocUi(parent, name) | 306 | : PwMDocUi(parent, name) |
307 | , dataChangedLock (0) | 307 | , dataChangedLock (0) |
308 | { | 308 | { |
309 | deleted = false; | 309 | deleted = false; |
310 | unnamedNum = 0; | 310 | unnamedNum = 0; |
311 | getOpenDocList()->add(this, getTitle().latin1()); | 311 | getOpenDocList()->add(this, getTitle().latin1()); |
312 | curDocStat = 0; | 312 | curDocStat = 0; |
313 | setMaxNumEntries(); | 313 | setMaxNumEntries(); |
314 | _timer = new DocTimer(this); | 314 | _timer = new DocTimer(this); |
315 | timer()->start(DocTimer::id_mpwTimer); | 315 | timer()->start(DocTimer::id_mpwTimer); |
316 | timer()->start(DocTimer::id_autoLockTimer); | 316 | timer()->start(DocTimer::id_autoLockTimer); |
317 | timer()->start(DocTimer::id_metaCheckTimer); | 317 | timer()->start(DocTimer::id_metaCheckTimer); |
318 | addCategory(DEFAULT_CATEGORY, 0, false); | 318 | addCategory(DEFAULT_CATEGORY, 0, false); |
319 | listView = 0; | 319 | listView = 0; |
320 | emit docCreated(this); | 320 | emit docCreated(this); |
321 | } | 321 | } |
322 | 322 | ||
323 | PwMDoc::~PwMDoc() | 323 | PwMDoc::~PwMDoc() |
324 | { | 324 | { |
325 | emit docClosed(this); | 325 | emit docClosed(this); |
326 | getOpenDocList()->del(this); | 326 | getOpenDocList()->del(this); |
327 | delete _timer; | 327 | delete _timer; |
328 | } | 328 | } |
329 | 329 | ||
330 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 330 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
331 | { | 331 | { |
332 | PwMerror ret, e; | 332 | PwMerror ret, e; |
333 | if (!file) { | 333 | if (!file) { |
334 | if (filename == "") | 334 | if (filename == "") |
335 | return e_filename; | 335 | return e_filename; |
336 | } else { | 336 | } else { |
337 | if (*file == "" && filename == "") | 337 | if (*file == "" && filename == "") |
338 | return e_filename; | 338 | return e_filename; |
339 | if (*file != "") | 339 | if (*file != "") |
340 | filename = *file; | 340 | filename = *file; |
341 | } | 341 | } |
342 | 342 | ||
343 | bool wasDeepLocked = isDeepLocked(); | 343 | bool wasDeepLocked = isDeepLocked(); |
344 | if (wasDeepLocked) { | 344 | if (wasDeepLocked) { |
345 | if (deepLock(false) != e_success) | 345 | if (deepLock(false) != e_success) |
346 | return e_noPw; | 346 | return e_noPw; |
347 | } | 347 | } |
348 | 348 | ||
349 | if (!isPwAvailable()) { | 349 | if (!isPwAvailable()) { |
350 | /* password is not available. This means, the | 350 | /* password is not available. This means, the |
351 | * document wasn't saved, yet. | 351 | * document wasn't saved, yet. |
352 | */ | 352 | */ |
353 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 353 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
354 | QString pw(requestNewMpw(&useChipcard)); | 354 | QString pw(requestNewMpw(&useChipcard)); |
355 | if (pw != "") { | 355 | if (pw != "") { |
356 | currentPw = pw; | 356 | currentPw = pw; |
357 | } else { | 357 | } else { |
358 | return e_noPw; | 358 | return e_noPw; |
359 | } | 359 | } |
360 | if (useChipcard) { | 360 | if (useChipcard) { |
361 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 361 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
362 | } else { | 362 | } else { |
363 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 363 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
364 | } | 364 | } |
365 | } | 365 | } |
366 | 366 | ||
367 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 367 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
368 | int _hashAlgo = conf()->confGlobHashAlgo(); | 368 | int _hashAlgo = conf()->confGlobHashAlgo(); |
369 | 369 | ||
370 | // sanity check for the selected algorithms | 370 | // sanity check for the selected algorithms |
371 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 371 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
372 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 372 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
373 | printWarn("Invalid Crypto-Algorithm selected! " | 373 | printWarn("Invalid Crypto-Algorithm selected! " |
374 | "Config-file seems to be corrupt. " | 374 | "Config-file seems to be corrupt. " |
375 | "Falling back to Blowfish."); | 375 | "Falling back to Blowfish."); |
376 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 376 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
377 | } | 377 | } |
378 | if (_hashAlgo < PWM_HASH_SHA1 || | 378 | if (_hashAlgo < PWM_HASH_SHA1 || |
379 | _hashAlgo > PWM_HASH_TIGER) { | 379 | _hashAlgo > PWM_HASH_TIGER) { |
380 | printWarn("Invalid Hash-Algorithm selected! " | 380 | printWarn("Invalid Hash-Algorithm selected! " |
381 | "Config-file seems to be corrupt. " | 381 | "Config-file seems to be corrupt. " |
382 | "Falling back to SHA1."); | 382 | "Falling back to SHA1."); |
383 | _hashAlgo = PWM_HASH_SHA1; | 383 | _hashAlgo = PWM_HASH_SHA1; |
384 | } | 384 | } |
385 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 385 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
386 | char hashAlgo = static_cast<char>(_hashAlgo); | 386 | char hashAlgo = static_cast<char>(_hashAlgo); |
387 | 387 | ||
388 | if (conf()->confGlobMakeFileBackup()) { | 388 | if (conf()->confGlobMakeFileBackup()) { |
389 | if (!backupFile(filename)) | 389 | if (!backupFile(filename)) |
390 | return e_fileBackup; | 390 | return e_fileBackup; |
391 | } | 391 | } |
392 | QString tmpFileMoved(QString::null); | 392 | QString tmpFileMoved(QString::null); |
393 | if (QFile::exists(filename)) { | 393 | if (QFile::exists(filename)) { |
394 | /* Move the existing file to some tmp file. | 394 | /* Move the existing file to some tmp file. |
395 | * When saving file succeeds, delete tmp file. Otherwise | 395 | * When saving file succeeds, delete tmp file. Otherwise |
396 | * move tmp file back. See below. | 396 | * move tmp file back. See below. |
397 | */ | 397 | */ |
398 | Randomizer *rnd = Randomizer::obj(); | 398 | Randomizer *rnd = Randomizer::obj(); |
399 | char rnd_buf[5]; | 399 | char rnd_buf[5]; |
400 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 400 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
401 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 401 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
402 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 402 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
403 | if (!copyFile(filename, tmpFileMoved)) | 403 | if (!copyFile(filename, tmpFileMoved)) |
404 | return e_openFile; | 404 | return e_openFile; |
405 | if (!QFile::remove(filename)) { | 405 | if (!QFile::remove(filename)) { |
406 | printWarn(string("removing orig file ") | 406 | printWarn(string("removing orig file ") |
407 | + filename.latin1() | 407 | + filename.latin1() |
408 | + " failed!"); | 408 | + " failed!"); |
409 | } | 409 | } |
410 | } | 410 | } |
411 | QFile f(filename); | 411 | QFile f(filename); |
412 | string serialized; | 412 | string serialized; |
413 | if (!f.open(IO_ReadWrite)) { | 413 | if (!f.open(IO_ReadWrite)) { |
414 | ret = e_openFile; | 414 | ret = e_openFile; |
415 | goto out_moveback; | 415 | goto out_moveback; |
416 | } | 416 | } |
417 | e = writeFileHeader(hashAlgo, hashAlgo, | 417 | e = writeFileHeader(hashAlgo, hashAlgo, |
418 | cryptAlgo, compress, | 418 | cryptAlgo, compress, |
419 | ¤tPw, &f); | 419 | ¤tPw, &f); |
420 | if (e == e_hashNotImpl) { | 420 | if (e == e_hashNotImpl) { |
421 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 421 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
422 | f.close(); | 422 | f.close(); |
423 | ret = e_hashNotImpl; | 423 | ret = e_hashNotImpl; |
424 | goto out_moveback; | 424 | goto out_moveback; |
425 | } else if (e != e_success) { | 425 | } else if (e != e_success) { |
426 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 426 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
427 | f.close(); | 427 | f.close(); |
428 | ret = e_writeHeader; | 428 | ret = e_writeHeader; |
429 | goto out_moveback; | 429 | goto out_moveback; |
430 | } | 430 | } |
431 | if (!serializeDta(&serialized)) { | 431 | if (!serializeDta(&serialized)) { |
432 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 432 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
433 | f.close(); | 433 | f.close(); |
434 | ret = e_serializeDta; | 434 | ret = e_serializeDta; |
435 | goto out_moveback; | 435 | goto out_moveback; |
436 | } | 436 | } |
437 | e = writeDataHash(hashAlgo, &serialized, &f); | 437 | e = writeDataHash(hashAlgo, &serialized, &f); |
438 | if (e == e_hashNotImpl) { | 438 | if (e == e_hashNotImpl) { |
439 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 439 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
440 | f.close(); | 440 | f.close(); |
441 | ret = e_hashNotImpl; | 441 | ret = e_hashNotImpl; |
442 | goto out_moveback; | 442 | goto out_moveback; |
443 | } else if (e != e_success) { | 443 | } else if (e != e_success) { |
444 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 444 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
445 | f.close(); | 445 | f.close(); |
446 | ret = e_writeHeader; | 446 | ret = e_writeHeader; |
447 | goto out_moveback; | 447 | goto out_moveback; |
448 | } | 448 | } |
449 | if (!compressDta(&serialized, compress)) { | 449 | if (!compressDta(&serialized, compress)) { |
450 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 450 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
451 | f.close(); | 451 | f.close(); |
452 | ret = e_enc; | 452 | ret = e_enc; |
453 | goto out_moveback; | 453 | goto out_moveback; |
454 | } | 454 | } |
455 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); | 455 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); |
456 | if (e == e_weakPw) { | 456 | if (e == e_weakPw) { |
457 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 457 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
458 | f.close(); | 458 | f.close(); |
459 | ret = e_weakPw; | 459 | ret = e_weakPw; |
460 | goto out_moveback; | 460 | goto out_moveback; |
461 | } else if (e == e_cryptNotImpl) { | 461 | } else if (e == e_cryptNotImpl) { |
462 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 462 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
463 | f.close(); | 463 | f.close(); |
464 | ret = e_cryptNotImpl; | 464 | ret = e_cryptNotImpl; |
465 | goto out_moveback; | 465 | goto out_moveback; |
466 | } else if (e != e_success) { | 466 | } else if (e != e_success) { |
467 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 467 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
468 | f.close(); | 468 | f.close(); |
469 | ret = e_enc; | 469 | ret = e_enc; |
470 | goto out_moveback; | 470 | goto out_moveback; |
471 | } | 471 | } |
472 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 472 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
473 | f.close(); | 473 | f.close(); |
474 | if (chmod(filename.latin1(), | 474 | if (chmod(filename.latin1(), |
475 | conf()->confGlobFilePermissions())) { | 475 | conf()->confGlobFilePermissions())) { |
476 | printWarn(string("chmod failed: ") + strerror(errno)); | 476 | printWarn(string("chmod failed: ") + strerror(errno)); |
477 | } | 477 | } |
478 | openDocList.edit(this, getTitle().latin1()); | 478 | openDocList.edit(this, getTitle().latin1()); |
479 | if (wasDeepLocked) | 479 | if (wasDeepLocked) |
480 | deepLock(true); | 480 | deepLock(true); |
481 | if (tmpFileMoved != QString::null) { | 481 | if (tmpFileMoved != QString::null) { |
482 | // now remove the moved file. | 482 | // now remove the moved file. |
483 | if (!QFile::remove(tmpFileMoved)) { | 483 | if (!QFile::remove(tmpFileMoved)) { |
484 | printWarn(string("removing file ") | 484 | printWarn(string("removing file ") |
485 | + tmpFileMoved.latin1() | 485 | + tmpFileMoved.latin1() |
486 | + " failed!"); | 486 | + " failed!"); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | ret = e_success; | 489 | ret = e_success; |
490 | printDebug(string("writing file { compress: ") | 490 | printDebug(string("writing file { name: ") |
491 | + filename.latin1() + " compress: " | ||
491 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 492 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
492 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 493 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
493 | + tostr(static_cast<int>(hashAlgo)) | 494 | + tostr(static_cast<int>(hashAlgo)) |
494 | + " }"); | 495 | + " }"); |
495 | goto out; | 496 | goto out; |
496 | out_moveback: | 497 | out_moveback: |
497 | if (tmpFileMoved != QString::null) { | 498 | if (tmpFileMoved != QString::null) { |
498 | if (copyFile(tmpFileMoved, filename)) { | 499 | if (copyFile(tmpFileMoved, filename)) { |
499 | if (!QFile::remove(tmpFileMoved)) { | 500 | if (!QFile::remove(tmpFileMoved)) { |
500 | printWarn(string("removing tmp file ") | 501 | printWarn(string("removing tmp file ") |
501 | + filename.latin1() | 502 | + filename.latin1() |
502 | + " failed!"); | 503 | + " failed!"); |
503 | } | 504 | } |
504 | } else { | 505 | } else { |
505 | printWarn(string("couldn't copy file ") | 506 | printWarn(string("couldn't copy file ") |
506 | + tmpFileMoved.latin1() | 507 | + tmpFileMoved.latin1() |
507 | + " back to " | 508 | + " back to " |
508 | + filename.latin1()); | 509 | + filename.latin1()); |
509 | } | 510 | } |
510 | } | 511 | } |
511 | out: | 512 | out: |
512 | return ret; | 513 | return ret; |
513 | } | 514 | } |
514 | 515 | ||
515 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 516 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
516 | { | 517 | { |
517 | PWM_ASSERT(file); | 518 | PWM_ASSERT(file); |
518 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 519 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
519 | string decrypted, dataHash; | 520 | string decrypted, dataHash; |
520 | PwMerror ret; | 521 | PwMerror ret; |
521 | char cryptAlgo, dataHashType, compress; | 522 | char cryptAlgo, dataHashType, compress; |
522 | unsigned int headerLen; | 523 | unsigned int headerLen; |
523 | 524 | ||
524 | if (*file == "") | 525 | if (*file == "") |
525 | return e_readFile; | 526 | return e_readFile; |
526 | filename = *file; | 527 | filename = *file; |
527 | /* check if this file is already open. | 528 | /* check if this file is already open. |
528 | * This does not catch symlinks! | 529 | * This does not catch symlinks! |
529 | */ | 530 | */ |
530 | if (!isDeepLocked()) { | 531 | if (!isDeepLocked()) { |
531 | if (getOpenDocList()->find(filename.latin1())) | 532 | if (getOpenDocList()->find(filename.latin1())) |
532 | return e_alreadyOpen; | 533 | return e_alreadyOpen; |
533 | } | 534 | } |
534 | QFile f(filename); | 535 | QFile f(filename); |
535 | 536 | ||
536 | if (openLocked == 2) { | 537 | if (openLocked == 2) { |
537 | // open deep-locked | 538 | // open deep-locked |
538 | if (!QFile::exists(filename)) | 539 | if (!QFile::exists(filename)) |
539 | return e_openFile; | 540 | return e_openFile; |
540 | if (deepLock(true, false) != e_success) | 541 | if (deepLock(true, false) != e_success) |
541 | return e_openFile; | 542 | return e_openFile; |
542 | goto out_success; | 543 | goto out_success; |
543 | } | 544 | } |
544 | 545 | ||
545 | if (!f.open(IO_ReadOnly)) | 546 | if (!f.open(IO_ReadOnly)) |
546 | return e_openFile; | 547 | return e_openFile; |
547 | 548 | ||
548 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 549 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
549 | &dataHashType, &dataHash, &f); | 550 | &dataHashType, &dataHash, &f); |
550 | if (ret != e_success) { | 551 | if (ret != e_success) { |
551 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 552 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
552 | f.close(); | 553 | f.close(); |
553 | if (ret == e_wrongPw) { | 554 | if (ret == e_wrongPw) { |
554 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 555 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
555 | return ret; | 556 | return ret; |
556 | } else if (ret == e_noPw || | 557 | } else if (ret == e_noPw || |
557 | ret == e_fileVer || | 558 | ret == e_fileVer || |
558 | ret == e_fileFormat || | 559 | ret == e_fileFormat || |
559 | ret == e_hashNotImpl) { | 560 | ret == e_hashNotImpl) { |
560 | return ret; | 561 | return ret; |
561 | } else | 562 | } else |
562 | return e_readFile; | 563 | return e_readFile; |
563 | } | 564 | } |
564 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 565 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
565 | if (ret == e_cryptNotImpl) { | 566 | if (ret == e_cryptNotImpl) { |
566 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 567 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
567 | f.close(); | 568 | f.close(); |
568 | return e_cryptNotImpl; | 569 | return e_cryptNotImpl; |
569 | } else if (ret != e_success) { | 570 | } else if (ret != e_success) { |
570 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 571 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
571 | f.close(); | 572 | f.close(); |
572 | return e_readFile; | 573 | return e_readFile; |
573 | } | 574 | } |
574 | if (!decompressDta(&decrypted, compress)) { | 575 | if (!decompressDta(&decrypted, compress)) { |
575 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 576 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
576 | f.close(); | 577 | f.close(); |
577 | return e_fileCorrupt; | 578 | return e_fileCorrupt; |
578 | } | 579 | } |
579 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 580 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
580 | if (ret == e_hashNotImpl) { | 581 | if (ret == e_hashNotImpl) { |
581 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 582 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
582 | f.close(); | 583 | f.close(); |
583 | return e_hashNotImpl; | 584 | return e_hashNotImpl; |
584 | } else if (ret != e_success) { | 585 | } else if (ret != e_success) { |
585 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 586 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
586 | f.close(); | 587 | f.close(); |
587 | return e_fileCorrupt; | 588 | return e_fileCorrupt; |
588 | } | 589 | } |
589 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 590 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
590 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 591 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
591 | f.close(); | 592 | f.close(); |
592 | return e_readFile; | 593 | return e_readFile; |
593 | } | 594 | } |
594 | f.close(); | 595 | f.close(); |
595 | timer()->start(DocTimer::id_mpwTimer); | 596 | timer()->start(DocTimer::id_mpwTimer); |
596 | timer()->start(DocTimer::id_autoLockTimer); | 597 | timer()->start(DocTimer::id_autoLockTimer); |
597 | out_success: | 598 | out_success: |
598 | openDocList.edit(this, getTitle().latin1()); | 599 | openDocList.edit(this, getTitle().latin1()); |
599 | emit docOpened(this); | 600 | emit docOpened(this); |
600 | return e_success; | 601 | return e_success; |
601 | } | 602 | } |
602 | 603 | ||
603 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 604 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
604 | QString *pw, QFile *f) | 605 | QString *pw, QFile *f) |
605 | { | 606 | { |
606 | PWM_ASSERT(pw); | 607 | PWM_ASSERT(pw); |
607 | PWM_ASSERT(f); | 608 | PWM_ASSERT(f); |
608 | PWM_ASSERT(listView); | 609 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
610 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | ||
611 | //USPWM_ASSERT(listView); | ||
609 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 612 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
610 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 613 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
611 | return e_writeFile; | 614 | return e_writeFile; |
612 | } | 615 | } |
613 | if (f->putch(PWM_FILE_VER) == -1 || | 616 | if (f->putch(PWM_FILE_VER) == -1 || |
614 | f->putch(keyHash) == -1 || | 617 | f->putch(keyHash) == -1 || |
615 | f->putch(dataHash) == -1 || | 618 | f->putch(dataHash) == -1 || |
616 | f->putch(crypt) == -1 || | 619 | f->putch(crypt) == -1 || |
617 | f->putch(compress) == -1 || | 620 | f->putch(compress) == -1 || |
618 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 621 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
619 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 622 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
620 | return e_writeFile; | 623 | return e_writeFile; |
621 | } | 624 | } |
622 | 625 | ||
623 | // write bytes of NUL-data. These bytes are reserved for future-use. | 626 | // write bytes of NUL-data. These bytes are reserved for future-use. |
624 | const int bufSize = 64; | 627 | const int bufSize = 64; |
625 | char tmp_buf[bufSize]; | 628 | char tmp_buf[bufSize]; |
626 | memset(tmp_buf, 0x00, bufSize); | 629 | memset(tmp_buf, 0x00, bufSize); |
627 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 630 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
628 | return e_writeFile; | 631 | return e_writeFile; |
629 | 632 | ||
630 | switch (keyHash) { | 633 | switch (keyHash) { |
631 | case PWM_HASH_SHA1: { | 634 | case PWM_HASH_SHA1: { |
632 | const int hashlen = SHA1_HASH_LEN_BYTE; | 635 | const int hashlen = SHA1_HASH_LEN_BYTE; |
633 | Sha1 hash; | 636 | Sha1 hash; |
634 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 637 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
635 | string ret = hash.sha1_read(); | 638 | string ret = hash.sha1_read(); |
636 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 639 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
637 | return e_writeFile; | 640 | return e_writeFile; |
638 | break; | 641 | break; |
639 | } | 642 | } |
640 | case PWM_HASH_SHA256: | 643 | case PWM_HASH_SHA256: |
641 | /*... fall through */ | 644 | /*... fall through */ |
642 | case PWM_HASH_SHA384: | 645 | case PWM_HASH_SHA384: |
643 | case PWM_HASH_SHA512: | 646 | case PWM_HASH_SHA512: |
644 | case PWM_HASH_MD5: | 647 | case PWM_HASH_MD5: |
645 | case PWM_HASH_RMD160: | 648 | case PWM_HASH_RMD160: |
646 | case PWM_HASH_TIGER: | 649 | case PWM_HASH_TIGER: |
647 | { | 650 | { |
648 | if (!LibGCryptIf::available()) | 651 | if (!LibGCryptIf::available()) |
649 | return e_hashNotImpl; | 652 | return e_hashNotImpl; |
650 | LibGCryptIf gc; | 653 | LibGCryptIf gc; |
651 | PwMerror err; | 654 | PwMerror err; |
652 | unsigned char *buf; | 655 | unsigned char *buf; |
653 | size_t hashLen; | 656 | size_t hashLen; |
654 | err = gc.hash(&buf, | 657 | err = gc.hash(&buf, |
655 | &hashLen, | 658 | &hashLen, |
656 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 659 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
657 | pw->length(), | 660 | pw->length(), |
658 | keyHash); | 661 | keyHash); |
659 | if (err != e_success) | 662 | if (err != e_success) |
660 | return e_hashNotImpl; | 663 | return e_hashNotImpl; |
661 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 664 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
662 | != static_cast<Q_LONG>(hashLen)) { | 665 | != static_cast<Q_LONG>(hashLen)) { |
663 | delete [] buf; | 666 | delete [] buf; |
664 | return e_hashNotImpl; | 667 | return e_hashNotImpl; |
665 | } | 668 | } |
666 | delete [] buf; | 669 | delete [] buf; |
667 | break; | 670 | break; |
668 | } | 671 | } |
669 | default: { | 672 | default: { |
670 | return e_hashNotImpl; | 673 | return e_hashNotImpl; |
671 | } } | 674 | } } |
672 | return e_success; | 675 | return e_success; |
673 | } | 676 | } |
674 | 677 | ||
675 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 678 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
676 | unsigned int *headerLength, char *dataHashType, | 679 | unsigned int *headerLength, char *dataHashType, |
677 | string *dataHash, QFile *f) | 680 | string *dataHash, QFile *f) |
678 | { | 681 | { |
679 | PWM_ASSERT(cryptAlgo); | 682 | PWM_ASSERT(cryptAlgo); |
680 | PWM_ASSERT(pw); | 683 | PWM_ASSERT(pw); |
681 | PWM_ASSERT(headerLength); | 684 | PWM_ASSERT(headerLength); |
682 | PWM_ASSERT(dataHashType); | 685 | PWM_ASSERT(dataHashType); |
683 | PWM_ASSERT(dataHash); | 686 | PWM_ASSERT(dataHash); |
684 | PWM_ASSERT(f); | 687 | PWM_ASSERT(f); |
685 | int tmpRet; | 688 | int tmpRet; |
686 | // check "magic" header | 689 | // check "magic" header |
687 | const char magicHdr[] = FILE_ID_HEADER; | 690 | const char magicHdr[] = FILE_ID_HEADER; |
688 | const int hdrLen = array_size(magicHdr) - 1; | 691 | const int hdrLen = array_size(magicHdr) - 1; |
689 | char tmp[hdrLen]; | 692 | char tmp[hdrLen]; |
690 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 693 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
691 | return e_readFile; | 694 | return e_readFile; |
692 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 695 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
693 | return e_fileFormat; | 696 | return e_fileFormat; |
694 | // read and check file ver | 697 | // read and check file ver |
695 | int fileV = f->getch(); | 698 | int fileV = f->getch(); |
696 | if (fileV == -1) | 699 | if (fileV == -1) |
697 | return e_fileFormat; | 700 | return e_fileFormat; |
698 | if (fileV != PWM_FILE_VER) | 701 | if (fileV != PWM_FILE_VER) |
699 | return e_fileVer; | 702 | return e_fileVer; |
700 | // read hash hash type | 703 | // read hash hash type |
701 | int keyHash = f->getch(); | 704 | int keyHash = f->getch(); |
702 | if (keyHash == -1) | 705 | if (keyHash == -1) |
703 | return e_fileFormat; | 706 | return e_fileFormat; |
704 | // read data hash type | 707 | // read data hash type |
705 | tmpRet = f->getch(); | 708 | tmpRet = f->getch(); |
706 | if (tmpRet == -1) | 709 | if (tmpRet == -1) |
707 | return e_fileFormat; | 710 | return e_fileFormat; |
708 | *dataHashType = tmpRet; | 711 | *dataHashType = tmpRet; |
709 | // read crypt algo | 712 | // read crypt algo |
710 | tmpRet = f->getch(); | 713 | tmpRet = f->getch(); |
711 | if (tmpRet == -1) | 714 | if (tmpRet == -1) |
712 | return e_fileFormat; | 715 | return e_fileFormat; |
713 | *cryptAlgo = tmpRet; | 716 | *cryptAlgo = tmpRet; |
714 | // get compression-algo | 717 | // get compression-algo |
715 | tmpRet = f->getch(); | 718 | tmpRet = f->getch(); |
716 | if (tmpRet == -1) | 719 | if (tmpRet == -1) |
717 | return e_fileFormat; | 720 | return e_fileFormat; |
718 | *compress = tmpRet; | 721 | *compress = tmpRet; |
719 | // get the MPW-flag | 722 | // get the MPW-flag |
720 | int mpw_flag = f->getch(); | 723 | int mpw_flag = f->getch(); |
721 | if (mpw_flag == -1) | 724 | if (mpw_flag == -1) |
722 | return e_fileFormat; | 725 | return e_fileFormat; |
723 | if (mpw_flag == 0x01) | 726 | if (mpw_flag == 0x01) |
724 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 727 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
725 | else | 728 | else |
726 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 729 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
727 | // skip the "RESERVED"-bytes | 730 | // skip the "RESERVED"-bytes |
728 | if (!(f->at(f->at() + 64))) | 731 | if (!(f->at(f->at() + 64))) |
729 | return e_fileFormat; | 732 | return e_fileFormat; |
730 | 733 | ||
731 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 734 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
732 | if (*pw == "") { | 735 | if (*pw == "") { |
733 | /* the user didn't give a master-password | 736 | /* the user didn't give a master-password |
734 | * or didn't insert a chipcard | 737 | * or didn't insert a chipcard |
735 | */ | 738 | */ |
736 | return e_noPw; | 739 | return e_noPw; |
737 | } | 740 | } |
738 | // verify key-hash | 741 | // verify key-hash |
739 | switch (keyHash) { | 742 | switch (keyHash) { |
740 | case PWM_HASH_SHA1: { | 743 | case PWM_HASH_SHA1: { |
741 | // read hash from header | 744 | // read hash from header |
742 | const int hashLen = SHA1_HASH_LEN_BYTE; | 745 | const int hashLen = SHA1_HASH_LEN_BYTE; |
743 | string readHash; | 746 | string readHash; |
744 | int i; | 747 | int i; |
745 | for (i = 0; i < hashLen; ++i) | 748 | for (i = 0; i < hashLen; ++i) |
746 | readHash.push_back(f->getch()); | 749 | readHash.push_back(f->getch()); |
747 | Sha1 hash; | 750 | Sha1 hash; |
748 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 751 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
749 | string ret = hash.sha1_read(); | 752 | string ret = hash.sha1_read(); |
750 | if (ret != readHash) | 753 | if (ret != readHash) |
751 | return e_wrongPw;// hash doesn't match (wrong key) | 754 | return e_wrongPw;// hash doesn't match (wrong key) |
752 | break; | 755 | break; |
753 | } | 756 | } |
754 | case PWM_HASH_SHA256: | 757 | case PWM_HASH_SHA256: |
755 | /*... fall through */ | 758 | /*... fall through */ |
756 | case PWM_HASH_SHA384: | 759 | case PWM_HASH_SHA384: |
757 | case PWM_HASH_SHA512: | 760 | case PWM_HASH_SHA512: |
758 | case PWM_HASH_MD5: | 761 | case PWM_HASH_MD5: |
759 | case PWM_HASH_RMD160: | 762 | case PWM_HASH_RMD160: |
760 | case PWM_HASH_TIGER: { | 763 | case PWM_HASH_TIGER: { |
761 | if (!LibGCryptIf::available()) | 764 | if (!LibGCryptIf::available()) |
762 | return e_hashNotImpl; | 765 | return e_hashNotImpl; |
763 | LibGCryptIf gc; | 766 | LibGCryptIf gc; |
764 | PwMerror err; | 767 | PwMerror err; |
765 | unsigned char *buf; | 768 | unsigned char *buf; |
766 | size_t hashLen; | 769 | size_t hashLen; |
767 | err = gc.hash(&buf, | 770 | err = gc.hash(&buf, |
768 | &hashLen, | 771 | &hashLen, |
769 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 772 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
770 | pw->length(), | 773 | pw->length(), |
771 | keyHash); | 774 | keyHash); |
772 | if (err != e_success) | 775 | if (err != e_success) |
773 | return e_hashNotImpl; | 776 | return e_hashNotImpl; |
774 | string calcHash(reinterpret_cast<const char *>(buf), | 777 | string calcHash(reinterpret_cast<const char *>(buf), |
775 | static_cast<string::size_type>(hashLen)); | 778 | static_cast<string::size_type>(hashLen)); |
776 | delete [] buf; | 779 | delete [] buf; |
777 | // read hash from header | 780 | // read hash from header |
778 | string readHash; | 781 | string readHash; |
779 | size_t i; | 782 | size_t i; |
780 | for (i = 0; i < hashLen; ++i) | 783 | for (i = 0; i < hashLen; ++i) |
781 | readHash.push_back(f->getch()); | 784 | readHash.push_back(f->getch()); |
782 | if (calcHash != readHash) | 785 | if (calcHash != readHash) |
783 | return e_wrongPw;// hash doesn't match (wrong key) | 786 | return e_wrongPw;// hash doesn't match (wrong key) |
784 | break; | 787 | break; |
785 | } | 788 | } |
786 | default: { | 789 | default: { |
787 | return e_hashNotImpl; | 790 | return e_hashNotImpl; |
788 | } } | 791 | } } |
789 | // read the data-hash from the file | 792 | // read the data-hash from the file |
790 | unsigned int hashLen, i; | 793 | unsigned int hashLen, i; |
791 | switch (*dataHashType) { | 794 | switch (*dataHashType) { |
792 | case PWM_HASH_SHA1: | 795 | case PWM_HASH_SHA1: |
793 | hashLen = SHA1_HASH_LEN_BYTE; | 796 | hashLen = SHA1_HASH_LEN_BYTE; |
794 | break; | 797 | break; |
795 | case PWM_HASH_SHA256: | 798 | case PWM_HASH_SHA256: |
796 | /*... fall through */ | 799 | /*... fall through */ |
797 | case PWM_HASH_SHA384: | 800 | case PWM_HASH_SHA384: |
798 | case PWM_HASH_SHA512: | 801 | case PWM_HASH_SHA512: |
799 | case PWM_HASH_MD5: | 802 | case PWM_HASH_MD5: |
800 | case PWM_HASH_RMD160: | 803 | case PWM_HASH_RMD160: |
801 | case PWM_HASH_TIGER: { | 804 | case PWM_HASH_TIGER: { |
802 | if (!LibGCryptIf::available()) | 805 | if (!LibGCryptIf::available()) |
803 | return e_hashNotImpl; | 806 | return e_hashNotImpl; |
804 | LibGCryptIf gc; | 807 | LibGCryptIf gc; |
805 | hashLen = gc.hashLength(*dataHashType); | 808 | hashLen = gc.hashLength(*dataHashType); |
806 | if (hashLen == 0) | 809 | if (hashLen == 0) |
807 | return e_hashNotImpl; | 810 | return e_hashNotImpl; |
808 | break; | 811 | break; |
809 | } | 812 | } |
810 | default: | 813 | default: |
811 | return e_hashNotImpl; | 814 | return e_hashNotImpl; |
812 | } | 815 | } |
813 | *dataHash = ""; | 816 | *dataHash = ""; |
814 | for (i = 0; i < hashLen; ++i) { | 817 | for (i = 0; i < hashLen; ++i) { |
815 | tmpRet = f->getch(); | 818 | tmpRet = f->getch(); |
816 | if (tmpRet == -1) | 819 | if (tmpRet == -1) |
817 | return e_fileFormat; | 820 | return e_fileFormat; |
818 | dataHash->push_back(static_cast<char>(tmpRet)); | 821 | dataHash->push_back(static_cast<char>(tmpRet)); |
819 | } | 822 | } |
820 | *headerLength = f->at(); | 823 | *headerLength = f->at(); |
821 | #ifndef PWM_EMBEDDED | 824 | #ifndef PWM_EMBEDDED |
822 | printDebug(string("opening file { compress: ") | 825 | printDebug(string("opening file { compress: ") |
823 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 826 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
824 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 827 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
825 | + tostr(static_cast<int>(keyHash)) | 828 | + tostr(static_cast<int>(keyHash)) |
826 | + " }"); | 829 | + " }"); |
827 | #else | 830 | #else |
828 | printDebug(string("opening file { compress: ") | 831 | printDebug(string("opening file { compress: ") |
829 | + tostr((int)(*compress)) + " cryptAlgo: " | 832 | + tostr((int)(*compress)) + " cryptAlgo: " |
830 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 833 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
831 | + tostr((int)(keyHash)) | 834 | + tostr((int)(keyHash)) |
832 | + " }"); | 835 | + " }"); |
833 | #endif | 836 | #endif |
834 | 837 | ||
835 | return e_success; | 838 | return e_success; |
836 | } | 839 | } |
837 | 840 | ||
838 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 841 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
839 | { | 842 | { |
840 | PWM_ASSERT(d); | 843 | PWM_ASSERT(d); |
841 | PWM_ASSERT(f); | 844 | PWM_ASSERT(f); |
842 | 845 | ||
843 | switch (dataHash) { | 846 | switch (dataHash) { |
844 | case PWM_HASH_SHA1: { | 847 | case PWM_HASH_SHA1: { |
845 | const int hashLen = SHA1_HASH_LEN_BYTE; | 848 | const int hashLen = SHA1_HASH_LEN_BYTE; |
846 | Sha1 h; | 849 | Sha1 h; |
847 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 850 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
848 | string hRet = h.sha1_read(); | 851 | string hRet = h.sha1_read(); |
849 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 852 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
850 | return e_writeFile; | 853 | return e_writeFile; |
851 | break; | 854 | break; |
852 | } | 855 | } |
853 | case PWM_HASH_SHA256: | 856 | case PWM_HASH_SHA256: |
854 | /*... fall through */ | 857 | /*... fall through */ |
855 | case PWM_HASH_SHA384: | 858 | case PWM_HASH_SHA384: |
856 | case PWM_HASH_SHA512: | 859 | case PWM_HASH_SHA512: |
857 | case PWM_HASH_MD5: | 860 | case PWM_HASH_MD5: |
858 | case PWM_HASH_RMD160: | 861 | case PWM_HASH_RMD160: |
859 | case PWM_HASH_TIGER: { | 862 | case PWM_HASH_TIGER: { |
860 | if (!LibGCryptIf::available()) | 863 | if (!LibGCryptIf::available()) |
861 | return e_hashNotImpl; | 864 | return e_hashNotImpl; |
862 | LibGCryptIf gc; | 865 | LibGCryptIf gc; |
863 | PwMerror err; | 866 | PwMerror err; |
864 | unsigned char *buf; | 867 | unsigned char *buf; |
865 | size_t hashLen; | 868 | size_t hashLen; |
866 | err = gc.hash(&buf, | 869 | err = gc.hash(&buf, |
867 | &hashLen, | 870 | &hashLen, |
868 | reinterpret_cast<const unsigned char *>(d->c_str()), | 871 | reinterpret_cast<const unsigned char *>(d->c_str()), |
869 | d->size(), | 872 | d->size(), |
870 | dataHash); | 873 | dataHash); |
871 | if (err != e_success) | 874 | if (err != e_success) |
872 | return e_hashNotImpl; | 875 | return e_hashNotImpl; |
873 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 876 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
874 | != static_cast<Q_LONG>(hashLen)) { | 877 | != static_cast<Q_LONG>(hashLen)) { |
875 | delete [] buf; | 878 | delete [] buf; |
876 | return e_hashNotImpl; | 879 | return e_hashNotImpl; |
877 | } | 880 | } |
878 | delete [] buf; | 881 | delete [] buf; |
879 | break; | 882 | break; |
880 | } | 883 | } |
881 | default: { | 884 | default: { |
882 | return e_hashNotImpl; | 885 | return e_hashNotImpl; |
883 | } } | 886 | } } |
884 | 887 | ||
885 | return e_success; | 888 | return e_success; |
886 | } | 889 | } |
887 | 890 | ||
888 | bool PwMDoc::backupFile(const QString &filePath) | 891 | bool PwMDoc::backupFile(const QString &filePath) |
889 | { | 892 | { |
890 | QFileInfo fi(filePath); | 893 | QFileInfo fi(filePath); |
891 | if (!fi.exists()) | 894 | if (!fi.exists()) |
892 | return true; // Yes, true is correct. | 895 | return true; // Yes, true is correct. |
893 | QString pathOnly(fi.dirPath(true)); | 896 | QString pathOnly(fi.dirPath(true)); |
894 | QString nameOnly(fi.fileName()); | 897 | QString nameOnly(fi.fileName()); |
895 | QString backupPath = pathOnly | 898 | QString backupPath = pathOnly |
896 | + "/~" | 899 | + "/~" |
897 | + nameOnly | 900 | + nameOnly |
898 | + ".backup"; | 901 | + ".backup"; |
899 | return copyFile(filePath, backupPath); | 902 | return copyFile(filePath, backupPath); |
900 | } | 903 | } |
901 | 904 | ||
902 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 905 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
903 | { | 906 | { |
904 | QFileInfo fi(src); | 907 | QFileInfo fi(src); |
905 | if (!fi.exists()) | 908 | if (!fi.exists()) |
906 | return false; | 909 | return false; |
907 | if (QFile::exists(dst)) { | 910 | if (QFile::exists(dst)) { |
908 | if (!QFile::remove(dst)) | 911 | if (!QFile::remove(dst)) |
909 | return false; | 912 | return false; |
910 | } | 913 | } |
911 | QFile srcFd(src); | 914 | QFile srcFd(src); |
912 | if (!srcFd.open(IO_ReadOnly)) | 915 | if (!srcFd.open(IO_ReadOnly)) |
913 | return false; | 916 | return false; |
914 | QFile dstFd(dst); | 917 | QFile dstFd(dst); |
915 | if (!dstFd.open(IO_ReadWrite)) { | 918 | if (!dstFd.open(IO_ReadWrite)) { |
916 | srcFd.close(); | 919 | srcFd.close(); |
917 | return false; | 920 | return false; |
918 | } | 921 | } |
919 | const int tmpBuf_size = 512; | 922 | const int tmpBuf_size = 512; |
920 | char tmpBuf[tmpBuf_size]; | 923 | char tmpBuf[tmpBuf_size]; |
921 | Q_LONG bytesRead, bytesWritten; | 924 | Q_LONG bytesRead, bytesWritten; |
922 | 925 | ||
923 | while (!srcFd.atEnd()) { | 926 | while (!srcFd.atEnd()) { |
924 | bytesRead = srcFd.readBlock(tmpBuf, | 927 | bytesRead = srcFd.readBlock(tmpBuf, |
925 | static_cast<Q_ULONG>(tmpBuf_size)); | 928 | static_cast<Q_ULONG>(tmpBuf_size)); |
926 | if (bytesRead == -1) { | 929 | if (bytesRead == -1) { |
927 | srcFd.close(); | 930 | srcFd.close(); |
928 | dstFd.close(); | 931 | dstFd.close(); |
929 | return false; | 932 | return false; |
930 | } | 933 | } |
931 | bytesWritten = dstFd.writeBlock(tmpBuf, | 934 | bytesWritten = dstFd.writeBlock(tmpBuf, |
932 | static_cast<Q_ULONG>(bytesRead)); | 935 | static_cast<Q_ULONG>(bytesRead)); |
933 | if (bytesWritten != bytesRead) { | 936 | if (bytesWritten != bytesRead) { |
934 | srcFd.close(); | 937 | srcFd.close(); |
935 | dstFd.close(); | 938 | dstFd.close(); |
936 | return false; | 939 | return false; |
937 | } | 940 | } |
938 | } | 941 | } |
939 | srcFd.close(); | 942 | srcFd.close(); |
940 | dstFd.close(); | 943 | dstFd.close(); |
941 | return true; | 944 | return true; |
942 | } | 945 | } |
943 | 946 | ||
944 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 947 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
945 | bool dontFlagDirty, bool updateMeta) | 948 | bool dontFlagDirty, bool updateMeta) |
946 | { | 949 | { |
947 | PWM_ASSERT(d); | 950 | PWM_ASSERT(d); |
948 | unsigned int cat = 0; | 951 | unsigned int cat = 0; |
949 | 952 | ||
950 | if (isDeepLocked()) { | 953 | if (isDeepLocked()) { |
951 | PwMerror ret; | 954 | PwMerror ret; |
952 | ret = deepLock(false); | 955 | ret = deepLock(false); |
953 | if (ret != e_success) | 956 | if (ret != e_success) |
954 | return e_lock; | 957 | return e_lock; |
955 | } | 958 | } |
956 | 959 | ||
957 | addCategory(category, &cat); | 960 | addCategory(category, &cat); |
958 | 961 | ||
959 | if (numEntries(category) >= maxEntries) | 962 | if (numEntries(category) >= maxEntries) |
960 | return e_maxAllowedEntr; | 963 | return e_maxAllowedEntr; |
961 | 964 | ||
962 | vector<unsigned int> foundPositions; | 965 | vector<unsigned int> foundPositions; |
963 | /* historically this was: | 966 | /* historically this was: |
964 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 967 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
965 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 968 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
966 | * But for now we only search in desc. | 969 | * But for now we only search in desc. |
967 | * That's a tweak to be KWallet compatible. But it should not add | 970 | * That's a tweak to be KWallet compatible. But it should not add |
968 | * usability-drop onto PwManager, does it? | 971 | * usability-drop onto PwManager, does it? |
969 | * (And yes, "int" was a bug. Correct is "unsigned int") | 972 | * (And yes, "int" was a bug. Correct is "unsigned int") |
970 | */ | 973 | */ |
971 | const unsigned int searchIn = SEARCH_IN_DESC; | 974 | const unsigned int searchIn = SEARCH_IN_DESC; |
972 | findEntry(cat, *d, searchIn, &foundPositions, true); | 975 | findEntry(cat, *d, searchIn, &foundPositions, true); |
973 | if (foundPositions.size()) { | 976 | if (foundPositions.size()) { |
974 | // DOH! We found this entry. | 977 | // DOH! We found this entry. |
975 | return e_entryExists; | 978 | return e_entryExists; |
976 | } | 979 | } |
977 | 980 | ||
978 | d->listViewPos = -1; | 981 | d->listViewPos = -1; |
979 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 982 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
980 | if (updateMeta) { | 983 | if (updateMeta) { |
981 | d->meta.create = QDateTime::currentDateTime(); | 984 | d->meta.create = QDateTime::currentDateTime(); |
982 | d->meta.update = d->meta.create; | 985 | d->meta.update = d->meta.create; |
983 | } | 986 | } |
984 | dti.dta[cat].d.push_back(*d); | 987 | dti.dta[cat].d.push_back(*d); |
985 | 988 | ||
986 | delAllEmptyCat(true); | 989 | delAllEmptyCat(true); |
987 | 990 | ||
988 | if (!dontFlagDirty) | 991 | if (!dontFlagDirty) |
989 | flagDirty(); | 992 | flagDirty(); |
990 | return e_success; | 993 | return e_success; |
991 | } | 994 | } |
992 | 995 | ||
993 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 996 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
994 | bool checkIfExist) | 997 | bool checkIfExist) |
995 | { | 998 | { |
996 | if (isDeepLocked()) { | 999 | if (isDeepLocked()) { |
997 | PwMerror ret; | 1000 | PwMerror ret; |
998 | ret = deepLock(false); | 1001 | ret = deepLock(false); |
999 | if (ret != e_success) | 1002 | if (ret != e_success) |
1000 | return e_lock; | 1003 | return e_lock; |
1001 | } | 1004 | } |
1002 | if (checkIfExist) { | 1005 | if (checkIfExist) { |
1003 | if (findCategory(category, categoryIndex)) | 1006 | if (findCategory(category, categoryIndex)) |
1004 | return e_categoryExists; | 1007 | return e_categoryExists; |
1005 | } | 1008 | } |
1006 | PwMCategoryItem item; | 1009 | PwMCategoryItem item; |
1007 | item.name = category.latin1(); | 1010 | item.name = category.latin1(); |
1008 | dti.dta.push_back(item); | 1011 | dti.dta.push_back(item); |
1009 | if (categoryIndex) | 1012 | if (categoryIndex) |
1010 | *categoryIndex = dti.dta.size() - 1; | 1013 | *categoryIndex = dti.dta.size() - 1; |
1011 | return e_success; | 1014 | return e_success; |
1012 | } | 1015 | } |
1013 | 1016 | ||
1014 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1017 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1015 | { | 1018 | { |
1016 | unsigned int cat = 0; | 1019 | unsigned int cat = 0; |
1017 | 1020 | ||
1018 | if (!findCategory(category, &cat)) { | 1021 | if (!findCategory(category, &cat)) { |
1019 | BUG(); | 1022 | BUG(); |
1020 | return false; | 1023 | return false; |
1021 | } | 1024 | } |
1022 | 1025 | ||
1023 | return delEntry(cat, index, dontFlagDirty); | 1026 | return delEntry(cat, index, dontFlagDirty); |
1024 | } | 1027 | } |
1025 | 1028 | ||
1026 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1029 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1027 | { | 1030 | { |
1028 | if (isDeepLocked()) | 1031 | if (isDeepLocked()) |
1029 | return false; | 1032 | return false; |
1030 | if (index > dti.dta[category].d.size() - 1) | 1033 | if (index > dti.dta[category].d.size() - 1) |
1031 | return false; | 1034 | return false; |
1032 | getDataChangedLock(); | 1035 | getDataChangedLock(); |
1033 | if (!lockAt(category, index, false)) { | 1036 | if (!lockAt(category, index, false)) { |
1034 | putDataChangedLock(); | 1037 | putDataChangedLock(); |
1035 | return false; | 1038 | return false; |
1036 | } | 1039 | } |
1037 | putDataChangedLock(); | 1040 | putDataChangedLock(); |
1038 | int lvPos = dti.dta[category].d[index].listViewPos; | 1041 | int lvPos = dti.dta[category].d[index].listViewPos; |
1039 | 1042 | ||
1040 | // delete entry | 1043 | // delete entry |
1041 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); | 1044 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1042 | 1045 | ||
1043 | unsigned int i, entries = numEntries(category); | 1046 | unsigned int i, entries = numEntries(category); |
1044 | if (!entries) { | 1047 | if (!entries) { |
1045 | // no more entries in this category, so | 1048 | // no more entries in this category, so |
1046 | // we can delete it, too. | 1049 | // we can delete it, too. |
1047 | BUG_ON(!delCategory(category)); | 1050 | BUG_ON(!delCategory(category)); |
1048 | // delCategory() flags it dirty, so we need not to do so. | 1051 | // delCategory() flags it dirty, so we need not to do so. |
1049 | return true; | 1052 | return true; |
1050 | } | 1053 | } |
1051 | for (i = 0; i < entries; ++i) { | 1054 | for (i = 0; i < entries; ++i) { |
1052 | // decrement all listViewPositions that are greater than the deleted. | 1055 | // decrement all listViewPositions that are greater than the deleted. |
1053 | if (dti.dta[category].d[i].listViewPos > lvPos) | 1056 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1054 | --dti.dta[category].d[i].listViewPos; | 1057 | --dti.dta[category].d[i].listViewPos; |
1055 | } | 1058 | } |
1056 | 1059 | ||
1057 | if (!dontFlagDirty) | 1060 | if (!dontFlagDirty) |
1058 | flagDirty(); | 1061 | flagDirty(); |
1059 | return true; | 1062 | return true; |
1060 | } | 1063 | } |
1061 | 1064 | ||
1062 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1065 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1063 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1066 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1064 | { | 1067 | { |
1065 | PWM_ASSERT(d); | 1068 | PWM_ASSERT(d); |
1066 | unsigned int oldCat = 0; | 1069 | unsigned int oldCat = 0; |
1067 | 1070 | ||
1068 | if (!findCategory(oldCategory, &oldCat)) { | 1071 | if (!findCategory(oldCategory, &oldCat)) { |
1069 | BUG(); | 1072 | BUG(); |
1070 | return false; | 1073 | return false; |
1071 | } | 1074 | } |
1072 | 1075 | ||
1073 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1076 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1074 | } | 1077 | } |
1075 | 1078 | ||
1076 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1079 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1077 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1080 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1078 | { | 1081 | { |
1079 | if (isDeepLocked()) | 1082 | if (isDeepLocked()) |
1080 | return false; | 1083 | return false; |
1081 | if (updateMeta) { | 1084 | if (updateMeta) { |
1082 | d->meta.update = QDateTime::currentDateTime(); | 1085 | d->meta.update = QDateTime::currentDateTime(); |
1083 | if (d->meta.create.isNull()) { | 1086 | if (d->meta.create.isNull()) { |
1084 | d->meta.create = d->meta.update; | 1087 | d->meta.create = d->meta.update; |
1085 | } | 1088 | } |
1086 | } | 1089 | } |
1087 | if (dti.dta[oldCategory].name != newCategory.latin1()) { | 1090 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1088 | // the user changed the category. | 1091 | // the user changed the category. |
1089 | PwMerror ret; | 1092 | PwMerror ret; |
1090 | d->rev = 0; | 1093 | d->rev = 0; |
1091 | ret = addEntry(newCategory, d, true, false); | 1094 | ret = addEntry(newCategory, d, true, false); |
1092 | if (ret != e_success) | 1095 | if (ret != e_success) |
1093 | return false; | 1096 | return false; |
1094 | if (!delEntry(oldCategory, index, true)) | 1097 | if (!delEntry(oldCategory, index, true)) |
1095 | return false; | 1098 | return false; |
1096 | } else { | 1099 | } else { |
1097 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1100 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1098 | dti.dta[oldCategory].d[index] = *d; | 1101 | dti.dta[oldCategory].d[index] = *d; |
1099 | } | 1102 | } |
1100 | flagDirty(); | 1103 | flagDirty(); |
1101 | return true; | 1104 | return true; |
1102 | } | 1105 | } |
1103 | 1106 | ||
1104 | unsigned int PwMDoc::numEntries(const QString &category) | 1107 | unsigned int PwMDoc::numEntries(const QString &category) |
1105 | { | 1108 | { |
1106 | unsigned int cat = 0; | 1109 | unsigned int cat = 0; |
1107 | 1110 | ||
1108 | if (!findCategory(category, &cat)) { | 1111 | if (!findCategory(category, &cat)) { |
1109 | BUG(); | 1112 | BUG(); |
1110 | return 0; | 1113 | return 0; |
1111 | } | 1114 | } |
1112 | 1115 | ||
1113 | return numEntries(cat); | 1116 | return numEntries(cat); |
1114 | } | 1117 | } |
1115 | 1118 | ||
1116 | bool PwMDoc::serializeDta(string *d) | 1119 | bool PwMDoc::serializeDta(string *d) |
1117 | { | 1120 | { |
1118 | PWM_ASSERT(d); | 1121 | PWM_ASSERT(d); |
1119 | Serializer ser; | 1122 | Serializer ser; |
1120 | if (!ser.serialize(dti)) | 1123 | if (!ser.serialize(dti)) |
1121 | return false; | 1124 | return false; |
1122 | d->assign(ser.getXml()); | 1125 | d->assign(ser.getXml()); |
1123 | if (!d->size()) | 1126 | if (!d->size()) |
1124 | return false; | 1127 | return false; |
1125 | return true; | 1128 | return true; |
1126 | } | 1129 | } |
1127 | 1130 | ||
1128 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1131 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1129 | { | 1132 | { |
1130 | PWM_ASSERT(d); | 1133 | PWM_ASSERT(d); |
1131 | #ifndef PWM_EMBEDDED | 1134 | #ifndef PWM_EMBEDDED |
1132 | try { | 1135 | try { |
1133 | 1136 | ||
1134 | Serializer ser(d->c_str()); | 1137 | Serializer ser(d->c_str()); |
1135 | ser.setDefaultLockStat(entriesLocked); | 1138 | ser.setDefaultLockStat(entriesLocked); |
1136 | if (!ser.deSerialize(&dti)) | 1139 | if (!ser.deSerialize(&dti)) |
1137 | return false; | 1140 | return false; |
1138 | } catch (PwMException) { | 1141 | } catch (PwMException) { |
1139 | return false; | 1142 | return false; |
1140 | } | 1143 | } |
1141 | #else | 1144 | #else |
1142 | Serializer ser(d->c_str()); | 1145 | Serializer ser(d->c_str()); |
1143 | ser.setDefaultLockStat(entriesLocked); | 1146 | ser.setDefaultLockStat(entriesLocked); |
1144 | if (!ser.deSerialize(&dti)) | 1147 | if (!ser.deSerialize(&dti)) |
1145 | return false; | 1148 | return false; |
1146 | #endif | 1149 | #endif |
1147 | 1150 | ||
1148 | emitDataChanged(this); | 1151 | emitDataChanged(this); |
1149 | return true; | 1152 | return true; |
1150 | } | 1153 | } |
1151 | 1154 | ||
1152 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1155 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1153 | PwMDataItem * d, bool unlockIfLocked) | 1156 | PwMDataItem * d, bool unlockIfLocked) |
1154 | { | 1157 | { |
1155 | PWM_ASSERT(d); | 1158 | PWM_ASSERT(d); |
1156 | unsigned int cat = 0; | 1159 | unsigned int cat = 0; |
1157 | 1160 | ||
1158 | if (!findCategory(category, &cat)) { | 1161 | if (!findCategory(category, &cat)) { |
1159 | BUG(); | 1162 | BUG(); |
1160 | return false; | 1163 | return false; |
1161 | } | 1164 | } |
1162 | 1165 | ||
1163 | return getEntry(cat, index, d, unlockIfLocked); | 1166 | return getEntry(cat, index, d, unlockIfLocked); |
1164 | } | 1167 | } |
1165 | 1168 | ||
1166 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1169 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1167 | PwMDataItem *d, bool unlockIfLocked) | 1170 | PwMDataItem *d, bool unlockIfLocked) |
1168 | { | 1171 | { |
1169 | if (index > dti.dta[category].d.size() - 1) | 1172 | if (index > dti.dta[category].d.size() - 1) |
1170 | return false; | 1173 | return false; |
1171 | 1174 | ||
1172 | bool locked = isLocked(category, index); | 1175 | bool locked = isLocked(category, index); |
1173 | if (locked) { | 1176 | if (locked) { |
1174 | /* this entry is locked. We don't return a password, | 1177 | /* this entry is locked. We don't return a password, |
1175 | * until it's unlocked by the user by inserting | 1178 | * until it's unlocked by the user by inserting |
1176 | * chipcard or entering the mpw | 1179 | * chipcard or entering the mpw |
1177 | */ | 1180 | */ |
1178 | if (unlockIfLocked) { | 1181 | if (unlockIfLocked) { |
1179 | if (!lockAt(category, index, false)) { | 1182 | if (!lockAt(category, index, false)) { |
1180 | return false; | 1183 | return false; |
1181 | } | 1184 | } |
1182 | locked = false; | 1185 | locked = false; |
1183 | } | 1186 | } |
1184 | } | 1187 | } |
1185 | 1188 | ||
1186 | *d = dti.dta[category].d[index]; | 1189 | *d = dti.dta[category].d[index]; |
1187 | if (locked) | 1190 | if (locked) |
1188 | d->pw = LOCKED_STRING.latin1(); | 1191 | d->pw = LOCKED_STRING.latin1(); |
1189 | 1192 | ||
1190 | return true; | 1193 | return true; |
1191 | } | 1194 | } |
1192 | 1195 | ||
1193 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1196 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1194 | string *foundComment) | 1197 | string *foundComment) |
1195 | { | 1198 | { |
1196 | PWM_ASSERT(foundComment); | 1199 | PWM_ASSERT(foundComment); |
1197 | unsigned int cat = 0; | 1200 | unsigned int cat = 0; |
1198 | 1201 | ||
1199 | if (!findCategory(category, &cat)) | 1202 | if (!findCategory(category, &cat)) |
1200 | return e_invalidArg; | 1203 | return e_invalidArg; |
1201 | 1204 | ||
1202 | unsigned int i, entries = numEntries(cat); | 1205 | unsigned int i, entries = numEntries(cat); |
1203 | for (i = 0; i < entries; ++i) { | 1206 | for (i = 0; i < entries; ++i) { |
1204 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | 1207 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1205 | *foundComment = dti.dta[cat].d[i].comment; | 1208 | *foundComment = dti.dta[cat].d[i].comment; |
1206 | if (dti.dta[cat].d[i].binary) | 1209 | if (dti.dta[cat].d[i].binary) |
1207 | return e_binEntry; | 1210 | return e_binEntry; |
1208 | return e_normalEntry; | 1211 | return e_normalEntry; |
1209 | } | 1212 | } |
1210 | } | 1213 | } |
1211 | BUG(); | 1214 | BUG(); |
1212 | return e_generic; | 1215 | return e_generic; |
1213 | } | 1216 | } |
1214 | 1217 | ||
1215 | bool PwMDoc::compressDta(string *d, char algo) | 1218 | bool PwMDoc::compressDta(string *d, char algo) |
1216 | { | 1219 | { |
1217 | PWM_ASSERT(d); | 1220 | PWM_ASSERT(d); |
1218 | switch (algo) { | 1221 | switch (algo) { |
1219 | case PWM_COMPRESS_GZIP: { | 1222 | case PWM_COMPRESS_GZIP: { |
1220 | CompressGzip comp; | 1223 | CompressGzip comp; |
1221 | return comp.compress(d); | 1224 | return comp.compress(d); |
1222 | /*US } case PWM_COMPRESS_BZIP2: { | 1225 | /*US } case PWM_COMPRESS_BZIP2: { |
1223 | CompressBzip2 comp; | 1226 | CompressBzip2 comp; |
1224 | return comp.compress(d); | 1227 | return comp.compress(d); |
1225 | */ | 1228 | */ |
1226 | } case PWM_COMPRESS_NONE: { | 1229 | } case PWM_COMPRESS_NONE: { |
1227 | return true; | 1230 | return true; |
1228 | } default: { | 1231 | } default: { |
1229 | BUG(); | 1232 | BUG(); |
1230 | } | 1233 | } |
1231 | } | 1234 | } |
1232 | return false; | 1235 | return false; |
1233 | } | 1236 | } |
1234 | 1237 | ||
1235 | bool PwMDoc::decompressDta(string *d, char algo) | 1238 | bool PwMDoc::decompressDta(string *d, char algo) |
1236 | { | 1239 | { |
1237 | PWM_ASSERT(d); | 1240 | PWM_ASSERT(d); |
1238 | switch (algo) { | 1241 | switch (algo) { |
1239 | case PWM_COMPRESS_GZIP: { | 1242 | case PWM_COMPRESS_GZIP: { |
1240 | CompressGzip comp; | 1243 | CompressGzip comp; |
1241 | return comp.decompress(d); | 1244 | return comp.decompress(d); |
1242 | /*US } case PWM_COMPRESS_BZIP2: { | 1245 | /*US } case PWM_COMPRESS_BZIP2: { |
1243 | CompressBzip2 comp; | 1246 | CompressBzip2 comp; |
1244 | return comp.decompress(d); | 1247 | return comp.decompress(d); |
1245 | */ | 1248 | */ |
1246 | } case PWM_COMPRESS_NONE: { | 1249 | } case PWM_COMPRESS_NONE: { |
1247 | return true; | 1250 | return true; |
1248 | } | 1251 | } |
1249 | } | 1252 | } |
1250 | return false; | 1253 | return false; |
1251 | } | 1254 | } |
1252 | 1255 | ||
1253 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1256 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1254 | { | 1257 | { |
1255 | PWM_ASSERT(d); | 1258 | PWM_ASSERT(d); |
1256 | PWM_ASSERT(pw); | 1259 | PWM_ASSERT(pw); |
1257 | PWM_ASSERT(f); | 1260 | PWM_ASSERT(f); |
1258 | 1261 | ||
1259 | size_t encSize; | 1262 | size_t encSize; |
1260 | byte *encrypted = 0; | 1263 | byte *encrypted = 0; |
1261 | 1264 | ||
1262 | switch (algo) { | 1265 | switch (algo) { |
1263 | case PWM_CRYPT_BLOWFISH: { | 1266 | case PWM_CRYPT_BLOWFISH: { |
1264 | Blowfish::padNull(d); | 1267 | Blowfish::padNull(d); |
1265 | encSize = d->length(); | 1268 | encSize = d->length(); |
1266 | encrypted = new byte[encSize]; | 1269 | encrypted = new byte[encSize]; |
1267 | Blowfish bf; | 1270 | Blowfish bf; |
1268 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1271 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1269 | delete [] encrypted; | 1272 | delete [] encrypted; |
1270 | return e_weakPw; | 1273 | return e_weakPw; |
1271 | } | 1274 | } |
1272 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1275 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1273 | break; | 1276 | break; |
1274 | } | 1277 | } |
1275 | case PWM_CRYPT_AES128: | 1278 | case PWM_CRYPT_AES128: |
1276 | /*... fall through */ | 1279 | /*... fall through */ |
1277 | case PWM_CRYPT_AES192: | 1280 | case PWM_CRYPT_AES192: |
1278 | case PWM_CRYPT_AES256: | 1281 | case PWM_CRYPT_AES256: |
1279 | case PWM_CRYPT_3DES: | 1282 | case PWM_CRYPT_3DES: |
1280 | case PWM_CRYPT_TWOFISH: | 1283 | case PWM_CRYPT_TWOFISH: |
1281 | case PWM_CRYPT_TWOFISH128: { | 1284 | case PWM_CRYPT_TWOFISH128: { |
1282 | if (!LibGCryptIf::available()) | 1285 | if (!LibGCryptIf::available()) |
1283 | return e_cryptNotImpl; | 1286 | return e_cryptNotImpl; |
1284 | LibGCryptIf gc; | 1287 | LibGCryptIf gc; |
1285 | PwMerror err; | 1288 | PwMerror err; |
1286 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1289 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1287 | memcpy(plain, d->c_str(), d->length()); | 1290 | memcpy(plain, d->c_str(), d->length()); |
1288 | err = gc.encrypt(&encrypted, | 1291 | err = gc.encrypt(&encrypted, |
1289 | &encSize, | 1292 | &encSize, |
1290 | plain, | 1293 | plain, |
1291 | d->length(), | 1294 | d->length(), |
1292 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1295 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1293 | pw->length(), | 1296 | pw->length(), |
1294 | algo); | 1297 | algo); |
1295 | delete [] plain; | 1298 | delete [] plain; |
1296 | if (err != e_success) | 1299 | if (err != e_success) |
1297 | return e_cryptNotImpl; | 1300 | return e_cryptNotImpl; |
1298 | break; | 1301 | break; |
1299 | } | 1302 | } |
1300 | default: { | 1303 | default: { |
1301 | delete_ifnot_null_array(encrypted); | 1304 | delete_ifnot_null_array(encrypted); |
1302 | return e_cryptNotImpl; | 1305 | return e_cryptNotImpl; |
1303 | } } | 1306 | } } |
1304 | 1307 | ||
1305 | // write encrypted data to file | 1308 | // write encrypted data to file |
1306 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1309 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1307 | static_cast<Q_ULONG>(encSize)) | 1310 | static_cast<Q_ULONG>(encSize)) |
1308 | != static_cast<Q_LONG>(encSize)) { | 1311 | != static_cast<Q_LONG>(encSize)) { |
1309 | delete_ifnot_null_array(encrypted); | 1312 | delete_ifnot_null_array(encrypted); |
1310 | return e_writeFile; | 1313 | return e_writeFile; |
1311 | } | 1314 | } |
1312 | delete_ifnot_null_array(encrypted); | 1315 | delete_ifnot_null_array(encrypted); |
1313 | return e_success; | 1316 | return e_success; |
1314 | } | 1317 | } |
1315 | 1318 | ||
1316 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1319 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1317 | char algo, QFile *f) | 1320 | char algo, QFile *f) |
1318 | { | 1321 | { |
1319 | PWM_ASSERT(d); | 1322 | PWM_ASSERT(d); |
1320 | PWM_ASSERT(pw); | 1323 | PWM_ASSERT(pw); |
1321 | PWM_ASSERT(f); | 1324 | PWM_ASSERT(f); |
1322 | 1325 | ||
1323 | unsigned int cryptLen = f->size() - pos; | 1326 | unsigned int cryptLen = f->size() - pos; |
1324 | byte *encrypted = new byte[cryptLen]; | 1327 | byte *encrypted = new byte[cryptLen]; |
1325 | byte *decrypted = new byte[cryptLen]; | 1328 | byte *decrypted = new byte[cryptLen]; |
1326 | 1329 | ||
1327 | f->at(pos); | 1330 | f->at(pos); |
1328 | #ifndef PWM_EMBEDDED | 1331 | #ifndef PWM_EMBEDDED |
1329 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1332 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1330 | static_cast<Q_ULONG>(cryptLen)) | 1333 | static_cast<Q_ULONG>(cryptLen)) |
1331 | != static_cast<Q_LONG>(cryptLen)) { | 1334 | != static_cast<Q_LONG>(cryptLen)) { |
1332 | delete [] encrypted; | 1335 | delete [] encrypted; |
1333 | delete [] decrypted; | 1336 | delete [] decrypted; |
1334 | return e_readFile; | 1337 | return e_readFile; |
1335 | } | 1338 | } |
1336 | #else | 1339 | #else |
1337 | if (f->readBlock((char *)(encrypted), | 1340 | if (f->readBlock((char *)(encrypted), |
1338 | (unsigned long)(cryptLen)) | 1341 | (unsigned long)(cryptLen)) |
1339 | != (long)(cryptLen)) { | 1342 | != (long)(cryptLen)) { |
1340 | delete [] encrypted; | 1343 | delete [] encrypted; |
1341 | delete [] decrypted; | 1344 | delete [] decrypted; |
1342 | return e_readFile; | 1345 | return e_readFile; |
1343 | } | 1346 | } |
1344 | #endif | 1347 | #endif |
1345 | switch (algo) { | 1348 | switch (algo) { |
1346 | case PWM_CRYPT_BLOWFISH: { | 1349 | case PWM_CRYPT_BLOWFISH: { |
1347 | Blowfish bf; | 1350 | Blowfish bf; |
1348 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1351 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1349 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1352 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1350 | break; | 1353 | break; |
1351 | } | 1354 | } |
1352 | case PWM_CRYPT_AES128: | 1355 | case PWM_CRYPT_AES128: |
1353 | /*... fall through */ | 1356 | /*... fall through */ |
1354 | case PWM_CRYPT_AES192: | 1357 | case PWM_CRYPT_AES192: |
1355 | case PWM_CRYPT_AES256: | 1358 | case PWM_CRYPT_AES256: |
1356 | case PWM_CRYPT_3DES: | 1359 | case PWM_CRYPT_3DES: |
1357 | case PWM_CRYPT_TWOFISH: | 1360 | case PWM_CRYPT_TWOFISH: |
1358 | case PWM_CRYPT_TWOFISH128: { | 1361 | case PWM_CRYPT_TWOFISH128: { |
1359 | if (!LibGCryptIf::available()) | 1362 | if (!LibGCryptIf::available()) |
1360 | return e_cryptNotImpl; | 1363 | return e_cryptNotImpl; |
1361 | LibGCryptIf gc; | 1364 | LibGCryptIf gc; |
1362 | PwMerror err; | 1365 | PwMerror err; |
1363 | err = gc.decrypt(&decrypted, | 1366 | err = gc.decrypt(&decrypted, |
1364 | &cryptLen, | 1367 | &cryptLen, |
1365 | encrypted, | 1368 | encrypted, |
1366 | cryptLen, | 1369 | cryptLen, |
1367 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1370 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1368 | pw->length(), | 1371 | pw->length(), |
1369 | algo); | 1372 | algo); |
1370 | if (err != e_success) { | 1373 | if (err != e_success) { |
1371 | delete [] encrypted; | 1374 | delete [] encrypted; |
1372 | delete [] decrypted; | 1375 | delete [] decrypted; |
1373 | return e_cryptNotImpl; | 1376 | return e_cryptNotImpl; |
1374 | } | 1377 | } |
1375 | break; | 1378 | break; |
1376 | } | 1379 | } |
1377 | default: { | 1380 | default: { |
1378 | delete [] encrypted; | 1381 | delete [] encrypted; |
1379 | delete [] decrypted; | 1382 | delete [] decrypted; |
1380 | return e_cryptNotImpl; | 1383 | return e_cryptNotImpl; |
1381 | } } | 1384 | } } |
1382 | delete [] encrypted; | 1385 | delete [] encrypted; |
1383 | #ifndef PWM_EMBEDDED | 1386 | #ifndef PWM_EMBEDDED |
1384 | d->assign(reinterpret_cast<const char *>(decrypted), | 1387 | d->assign(reinterpret_cast<const char *>(decrypted), |
1385 | static_cast<string::size_type>(cryptLen)); | 1388 | static_cast<string::size_type>(cryptLen)); |
1386 | #else | 1389 | #else |
1387 | d->assign((const char *)(decrypted), | 1390 | d->assign((const char *)(decrypted), |
1388 | (string::size_type)(cryptLen)); | 1391 | (string::size_type)(cryptLen)); |
1389 | #endif | 1392 | #endif |
1390 | delete [] decrypted; | 1393 | delete [] decrypted; |
1391 | if (algo == PWM_CRYPT_BLOWFISH) { | 1394 | if (algo == PWM_CRYPT_BLOWFISH) { |
1392 | if (!Blowfish::unpadNull(d)) { | 1395 | if (!Blowfish::unpadNull(d)) { |
1393 | BUG(); | 1396 | BUG(); |
1394 | return e_readFile; | 1397 | return e_readFile; |
1395 | } | 1398 | } |
1396 | } | 1399 | } |
1397 | return e_success; | 1400 | return e_success; |
1398 | } | 1401 | } |
1399 | 1402 | ||
1400 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1403 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1401 | const string *dataStream) | 1404 | const string *dataStream) |
1402 | { | 1405 | { |
1403 | PWM_ASSERT(dataHash); | 1406 | PWM_ASSERT(dataHash); |
1404 | PWM_ASSERT(dataStream); | 1407 | PWM_ASSERT(dataStream); |
1405 | switch(dataHashType) { | 1408 | switch(dataHashType) { |
1406 | case PWM_HASH_SHA1: { | 1409 | case PWM_HASH_SHA1: { |
1407 | Sha1 hash; | 1410 | Sha1 hash; |
1408 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1411 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1409 | string ret = hash.sha1_read(); | 1412 | string ret = hash.sha1_read(); |
1410 | if (ret != *dataHash) | 1413 | if (ret != *dataHash) |
1411 | return e_fileCorrupt; | 1414 | return e_fileCorrupt; |
1412 | break; | 1415 | break; |
1413 | } | 1416 | } |
1414 | case PWM_HASH_SHA256: | 1417 | case PWM_HASH_SHA256: |
1415 | /*... fall through */ | 1418 | /*... fall through */ |
1416 | case PWM_HASH_SHA384: | 1419 | case PWM_HASH_SHA384: |
1417 | case PWM_HASH_SHA512: | 1420 | case PWM_HASH_SHA512: |
1418 | case PWM_HASH_MD5: | 1421 | case PWM_HASH_MD5: |
1419 | case PWM_HASH_RMD160: | 1422 | case PWM_HASH_RMD160: |
1420 | case PWM_HASH_TIGER: { | 1423 | case PWM_HASH_TIGER: { |
1421 | if (!LibGCryptIf::available()) | 1424 | if (!LibGCryptIf::available()) |
1422 | return e_hashNotImpl; | 1425 | return e_hashNotImpl; |
1423 | LibGCryptIf gc; | 1426 | LibGCryptIf gc; |
1424 | PwMerror err; | 1427 | PwMerror err; |
1425 | unsigned char *buf; | 1428 | unsigned char *buf; |
1426 | size_t hashLen; | 1429 | size_t hashLen; |
1427 | err = gc.hash(&buf, | 1430 | err = gc.hash(&buf, |
1428 | &hashLen, | 1431 | &hashLen, |
1429 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1432 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1430 | dataStream->length(), | 1433 | dataStream->length(), |
1431 | dataHashType); | 1434 | dataHashType); |
1432 | if (err != e_success) | 1435 | if (err != e_success) |
1433 | return e_hashNotImpl; | 1436 | return e_hashNotImpl; |
1434 | string calcHash(reinterpret_cast<const char *>(buf), | 1437 | string calcHash(reinterpret_cast<const char *>(buf), |
1435 | static_cast<string::size_type>(hashLen)); | 1438 | static_cast<string::size_type>(hashLen)); |
1436 | delete [] buf; | 1439 | delete [] buf; |
1437 | if (calcHash != *dataHash) | 1440 | if (calcHash != *dataHash) |
1438 | return e_fileCorrupt; | 1441 | return e_fileCorrupt; |
1439 | break; | 1442 | break; |
1440 | } | 1443 | } |
1441 | default: | 1444 | default: |
1442 | return e_hashNotImpl; | 1445 | return e_hashNotImpl; |
1443 | } | 1446 | } |
1444 | return e_success; | 1447 | return e_success; |
1445 | } | 1448 | } |
1446 | 1449 | ||
1447 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1450 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1448 | bool lock) | 1451 | bool lock) |
1449 | { | 1452 | { |
1450 | if (index >= numEntries(category)) { | 1453 | if (index >= numEntries(category)) { |
1451 | BUG(); | 1454 | BUG(); |
1452 | return false; | 1455 | return false; |
1453 | } | 1456 | } |
1454 | if (lock == dti.dta[category].d[index].lockStat) | 1457 | if (lock == dti.dta[category].d[index].lockStat) |
1455 | return true; | 1458 | return true; |
1456 | 1459 | ||
1457 | if (!lock && currentPw != "") { | 1460 | if (!lock && currentPw != "") { |
1458 | // "unlocking" and "password is already set" | 1461 | // "unlocking" and "password is already set" |
1459 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1462 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1460 | // unlocking without pw not allowed | 1463 | // unlocking without pw not allowed |
1461 | QString pw; | 1464 | QString pw; |
1462 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1465 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1463 | if (pw != "") { | 1466 | if (pw != "") { |
1464 | if (pw != currentPw) { | 1467 | if (pw != currentPw) { |
1465 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1468 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1466 | return false; | 1469 | return false; |
1467 | } else { | 1470 | } else { |
1468 | timer()->start(DocTimer::id_mpwTimer); | 1471 | timer()->start(DocTimer::id_mpwTimer); |
1469 | } | 1472 | } |
1470 | } else { | 1473 | } else { |
1471 | return false; | 1474 | return false; |
1472 | } | 1475 | } |
1473 | } else { | 1476 | } else { |
1474 | timer()->start(DocTimer::id_mpwTimer); | 1477 | timer()->start(DocTimer::id_mpwTimer); |
1475 | } | 1478 | } |
1476 | } | 1479 | } |
1477 | 1480 | ||
1478 | dti.dta[category].d[index].lockStat = lock; | 1481 | dti.dta[category].d[index].lockStat = lock; |
1479 | dti.dta[category].d[index].rev++; // increment revision counter. | 1482 | dti.dta[category].d[index].rev++; // increment revision counter. |
1480 | 1483 | ||
1481 | emitDataChanged(this); | 1484 | emitDataChanged(this); |
1482 | if (!lock) | 1485 | if (!lock) |
1483 | timer()->start(DocTimer::id_autoLockTimer); | 1486 | timer()->start(DocTimer::id_autoLockTimer); |
1484 | 1487 | ||
1485 | return true; | 1488 | return true; |
1486 | 1489 | ||
1487 | } | 1490 | } |
1488 | 1491 | ||
1489 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1492 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1490 | bool lock) | 1493 | bool lock) |
1491 | { | 1494 | { |
1492 | unsigned int cat = 0; | 1495 | unsigned int cat = 0; |
1493 | 1496 | ||
1494 | if (!findCategory(category, &cat)) { | 1497 | if (!findCategory(category, &cat)) { |
1495 | BUG(); | 1498 | BUG(); |
1496 | return false; | 1499 | return false; |
1497 | } | 1500 | } |
1498 | 1501 | ||
1499 | return lockAt(cat, index, lock); | 1502 | return lockAt(cat, index, lock); |
1500 | } | 1503 | } |
1501 | 1504 | ||
1502 | bool PwMDoc::lockAll(bool lock) | 1505 | bool PwMDoc::lockAll(bool lock) |
1503 | { | 1506 | { |
1504 | if (!lock && isDeepLocked()) { | 1507 | if (!lock && isDeepLocked()) { |
1505 | PwMerror ret; | 1508 | PwMerror ret; |
1506 | ret = deepLock(false); | 1509 | ret = deepLock(false); |
1507 | if (ret != e_success) | 1510 | if (ret != e_success) |
1508 | return false; | 1511 | return false; |
1509 | return true; | 1512 | return true; |
1510 | } | 1513 | } |
1511 | if (isDocEmpty()) { | 1514 | if (isDocEmpty()) { |
1512 | return true; | 1515 | return true; |
1513 | } | 1516 | } |
1514 | if (!lock && currentPw != "") { | 1517 | if (!lock && currentPw != "") { |
1515 | // unlocking and password is already set | 1518 | // unlocking and password is already set |
1516 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1519 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1517 | // unlocking without pw not allowed | 1520 | // unlocking without pw not allowed |
1518 | QString pw; | 1521 | QString pw; |
1519 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1522 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1520 | if (pw != "") { | 1523 | if (pw != "") { |
1521 | if (pw != currentPw) { | 1524 | if (pw != currentPw) { |
1522 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1525 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1523 | return false; | 1526 | return false; |
1524 | } else { | 1527 | } else { |
1525 | timer()->start(DocTimer::id_mpwTimer); | 1528 | timer()->start(DocTimer::id_mpwTimer); |
1526 | } | 1529 | } |
1527 | } else { | 1530 | } else { |
1528 | return false; | 1531 | return false; |
1529 | } | 1532 | } |
1530 | } else { | 1533 | } else { |
1531 | timer()->start(DocTimer::id_mpwTimer); | 1534 | timer()->start(DocTimer::id_mpwTimer); |
1532 | } | 1535 | } |
1533 | } | 1536 | } |
1534 | 1537 | ||
1535 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1538 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1536 | catEnd = dti.dta.end(), | 1539 | catEnd = dti.dta.end(), |
1537 | catI = catBegin; | 1540 | catI = catBegin; |
1538 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1541 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1539 | while (catI != catEnd) { | 1542 | while (catI != catEnd) { |
1540 | entrBegin = catI->d.begin(); | 1543 | entrBegin = catI->d.begin(); |
1541 | entrEnd = catI->d.end(); | 1544 | entrEnd = catI->d.end(); |
1542 | entrI = entrBegin; | 1545 | entrI = entrBegin; |
1543 | while (entrI != entrEnd) { | 1546 | while (entrI != entrEnd) { |
1544 | entrI->lockStat = lock; | 1547 | entrI->lockStat = lock; |
1545 | entrI->rev++; // increment revision counter. | 1548 | entrI->rev++; // increment revision counter. |
1546 | ++entrI; | 1549 | ++entrI; |
1547 | } | 1550 | } |
1548 | ++catI; | 1551 | ++catI; |
1549 | } | 1552 | } |
1550 | 1553 | ||
1551 | emitDataChanged(this); | 1554 | emitDataChanged(this); |
1552 | if (lock) | 1555 | if (lock) |
1553 | timer()->stop(DocTimer::id_autoLockTimer); | 1556 | timer()->stop(DocTimer::id_autoLockTimer); |
1554 | else | 1557 | else |
1555 | timer()->start(DocTimer::id_autoLockTimer); | 1558 | timer()->start(DocTimer::id_autoLockTimer); |
1556 | 1559 | ||
1557 | return true; | 1560 | return true; |
1558 | } | 1561 | } |
1559 | 1562 | ||
1560 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1563 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1561 | { | 1564 | { |
1562 | unsigned int cat = 0; | 1565 | unsigned int cat = 0; |
1563 | 1566 | ||
1564 | if (!findCategory(category, &cat)) { | 1567 | if (!findCategory(category, &cat)) { |
1565 | BUG(); | 1568 | BUG(); |
1566 | return false; | 1569 | return false; |
1567 | } | 1570 | } |
1568 | 1571 | ||
1569 | return isLocked(cat, index); | 1572 | return isLocked(cat, index); |
1570 | } | 1573 | } |
1571 | 1574 | ||
1572 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1575 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1573 | { | 1576 | { |
1574 | static vector< vector<bool> > *oldLockStates = 0; | 1577 | static vector< vector<bool> > *oldLockStates = 0; |
1575 | static bool wasDeepLocked; | 1578 | static bool wasDeepLocked; |
1576 | 1579 | ||
1577 | if (revert) {// revert the unlocking | 1580 | if (revert) {// revert the unlocking |
1578 | if (oldLockStates) { | 1581 | if (oldLockStates) { |
1579 | /* we actually _have_ unlocked something, because | 1582 | /* we actually _have_ unlocked something, because |
1580 | * we have allocated space for the oldLockStates. | 1583 | * we have allocated space for the oldLockStates. |
1581 | * So, go on and revert them! | 1584 | * So, go on and revert them! |
1582 | */ | 1585 | */ |
1583 | if (wasDeepLocked) { | 1586 | if (wasDeepLocked) { |
1584 | PwMerror ret = deepLock(true); | 1587 | PwMerror ret = deepLock(true); |
1585 | if (ret == e_success) { | 1588 | if (ret == e_success) { |
1586 | /* deep-lock succeed. We are save. | 1589 | /* deep-lock succeed. We are save. |
1587 | * (but if it failed, just go on | 1590 | * (but if it failed, just go on |
1588 | * lock them normally) | 1591 | * lock them normally) |
1589 | */ | 1592 | */ |
1590 | delete_and_null(oldLockStates); | 1593 | delete_and_null(oldLockStates); |
1591 | timer()->start(DocTimer::id_autoLockTimer); | 1594 | timer()->start(DocTimer::id_autoLockTimer); |
1592 | printDebug("tempoary unlocking of dta " | 1595 | printDebug("tempoary unlocking of dta " |
1593 | "reverted by deep-locking."); | 1596 | "reverted by deep-locking."); |
1594 | return true; | 1597 | return true; |
1595 | } | 1598 | } |
1596 | printDebug("deep-lock failed while reverting! " | 1599 | printDebug("deep-lock failed while reverting! " |
1597 | "Falling back to normal-lock."); | 1600 | "Falling back to normal-lock."); |
1598 | } | 1601 | } |
1599 | if (unlikely(!wasDeepLocked && | 1602 | if (unlikely(!wasDeepLocked && |
1600 | numCategories() != oldLockStates->size())) { | 1603 | numCategories() != oldLockStates->size())) { |
1601 | /* DOH! We have modified "dta" while | 1604 | /* DOH! We have modified "dta" while |
1602 | * it was unlocked tempoary. DON'T DO THIS! | 1605 | * it was unlocked tempoary. DON'T DO THIS! |
1603 | */ | 1606 | */ |
1604 | BUG(); | 1607 | BUG(); |
1605 | delete_and_null(oldLockStates); | 1608 | delete_and_null(oldLockStates); |
1606 | timer()->start(DocTimer::id_autoLockTimer); | 1609 | timer()->start(DocTimer::id_autoLockTimer); |
1607 | return false; | 1610 | return false; |
1608 | } | 1611 | } |
1609 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1612 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1610 | catEnd = dti.dta.end(), | 1613 | catEnd = dti.dta.end(), |
1611 | catI = catBegin; | 1614 | catI = catBegin; |
1612 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1615 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1613 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1616 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1614 | vector<bool>::iterator oldEntrStatBegin, | 1617 | vector<bool>::iterator oldEntrStatBegin, |
1615 | oldEntrStatEnd, | 1618 | oldEntrStatEnd, |
1616 | oldEntrStatI; | 1619 | oldEntrStatI; |
1617 | while (catI != catEnd) { | 1620 | while (catI != catEnd) { |
1618 | entrBegin = catI->d.begin(); | 1621 | entrBegin = catI->d.begin(); |
1619 | entrEnd = catI->d.end(); | 1622 | entrEnd = catI->d.end(); |
1620 | entrI = entrBegin; | 1623 | entrI = entrBegin; |
1621 | if (likely(!wasDeepLocked)) { | 1624 | if (likely(!wasDeepLocked)) { |
1622 | oldEntrStatBegin = oldCatStatI->begin(); | 1625 | oldEntrStatBegin = oldCatStatI->begin(); |
1623 | oldEntrStatEnd = oldCatStatI->end(); | 1626 | oldEntrStatEnd = oldCatStatI->end(); |
1624 | oldEntrStatI = oldEntrStatBegin; | 1627 | oldEntrStatI = oldEntrStatBegin; |
1625 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1628 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1626 | /* DOH! We have modified "dta" while | 1629 | /* DOH! We have modified "dta" while |
1627 | * it was unlocked tempoary. DON'T DO THIS! | 1630 | * it was unlocked tempoary. DON'T DO THIS! |
1628 | */ | 1631 | */ |
1629 | BUG(); | 1632 | BUG(); |
1630 | delete_and_null(oldLockStates); | 1633 | delete_and_null(oldLockStates); |
1631 | timer()->start(DocTimer::id_autoLockTimer); | 1634 | timer()->start(DocTimer::id_autoLockTimer); |
1632 | return false; | 1635 | return false; |
1633 | } | 1636 | } |
1634 | } | 1637 | } |
1635 | while (entrI != entrEnd) { | 1638 | while (entrI != entrEnd) { |
1636 | if (wasDeepLocked) { | 1639 | if (wasDeepLocked) { |
1637 | /* this is an error-fallback if | 1640 | /* this is an error-fallback if |
1638 | * deeplock didn't succeed | 1641 | * deeplock didn't succeed |
1639 | */ | 1642 | */ |
1640 | entrI->lockStat = true; | 1643 | entrI->lockStat = true; |
1641 | } else { | 1644 | } else { |
1642 | entrI->lockStat = *oldEntrStatI; | 1645 | entrI->lockStat = *oldEntrStatI; |
1643 | } | 1646 | } |
1644 | ++entrI; | 1647 | ++entrI; |
1645 | if (likely(!wasDeepLocked)) | 1648 | if (likely(!wasDeepLocked)) |
1646 | ++oldEntrStatI; | 1649 | ++oldEntrStatI; |
1647 | } | 1650 | } |
1648 | ++catI; | 1651 | ++catI; |
1649 | if (likely(!wasDeepLocked)) | 1652 | if (likely(!wasDeepLocked)) |
1650 | ++oldCatStatI; | 1653 | ++oldCatStatI; |
1651 | } | 1654 | } |
1652 | delete_and_null(oldLockStates); | 1655 | delete_and_null(oldLockStates); |
1653 | if (unlikely(wasDeepLocked)) { | 1656 | if (unlikely(wasDeepLocked)) { |
1654 | /* error fallback... */ | 1657 | /* error fallback... */ |
1655 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1658 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1656 | emitDataChanged(this); | 1659 | emitDataChanged(this); |
1657 | printDebug("WARNING: unlockAll_tempoary(true) " | 1660 | printDebug("WARNING: unlockAll_tempoary(true) " |
1658 | "deeplock fallback!"); | 1661 | "deeplock fallback!"); |
1659 | } | 1662 | } |
1660 | printDebug("tempoary unlocking of dta reverted."); | 1663 | printDebug("tempoary unlocking of dta reverted."); |
1661 | } else { | 1664 | } else { |
1662 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1665 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1663 | } | 1666 | } |
1664 | timer()->start(DocTimer::id_autoLockTimer); | 1667 | timer()->start(DocTimer::id_autoLockTimer); |
1665 | } else {// unlock all data tempoary | 1668 | } else {// unlock all data tempoary |
1666 | if (unlikely(oldLockStates != 0)) { | 1669 | if (unlikely(oldLockStates != 0)) { |
1667 | /* DOH! We have already unlocked the data tempoarly. | 1670 | /* DOH! We have already unlocked the data tempoarly. |
1668 | * No need to do it twice. ;) | 1671 | * No need to do it twice. ;) |
1669 | */ | 1672 | */ |
1670 | BUG(); | 1673 | BUG(); |
1671 | return false; | 1674 | return false; |
1672 | } | 1675 | } |
1673 | wasDeepLocked = false; | 1676 | wasDeepLocked = false; |
1674 | bool mustUnlock = false; | 1677 | bool mustUnlock = false; |
1675 | if (isDeepLocked()) { | 1678 | if (isDeepLocked()) { |
1676 | PwMerror ret; | 1679 | PwMerror ret; |
1677 | while (1) { | 1680 | while (1) { |
1678 | ret = deepLock(false); | 1681 | ret = deepLock(false); |
1679 | if (ret == e_success) { | 1682 | if (ret == e_success) { |
1680 | break; | 1683 | break; |
1681 | } else if (ret == e_wrongPw) { | 1684 | } else if (ret == e_wrongPw) { |
1682 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1685 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1683 | } else { | 1686 | } else { |
1684 | printDebug("deep-unlocking failed while " | 1687 | printDebug("deep-unlocking failed while " |
1685 | "tempoary unlocking!"); | 1688 | "tempoary unlocking!"); |
1686 | return false; | 1689 | return false; |
1687 | } | 1690 | } |
1688 | } | 1691 | } |
1689 | wasDeepLocked = true; | 1692 | wasDeepLocked = true; |
1690 | mustUnlock = true; | 1693 | mustUnlock = true; |
1691 | } else { | 1694 | } else { |
1692 | // first check if it's needed to unlock some entries | 1695 | // first check if it's needed to unlock some entries |
1693 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1696 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1694 | catEnd = dti.dta.end(), | 1697 | catEnd = dti.dta.end(), |
1695 | catI = catBegin; | 1698 | catI = catBegin; |
1696 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1699 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1697 | while (catI != catEnd) { | 1700 | while (catI != catEnd) { |
1698 | entrBegin = catI->d.begin(); | 1701 | entrBegin = catI->d.begin(); |
1699 | entrEnd = catI->d.end(); | 1702 | entrEnd = catI->d.end(); |
1700 | entrI = entrBegin; | 1703 | entrI = entrBegin; |
1701 | while (entrI != entrEnd) { | 1704 | while (entrI != entrEnd) { |
1702 | if (entrI->lockStat == true) { | 1705 | if (entrI->lockStat == true) { |
1703 | mustUnlock = true; | 1706 | mustUnlock = true; |
1704 | break; | 1707 | break; |
1705 | } | 1708 | } |
1706 | ++entrI; | 1709 | ++entrI; |
1707 | } | 1710 | } |
1708 | if (mustUnlock) | 1711 | if (mustUnlock) |
1709 | break; | 1712 | break; |
1710 | ++catI; | 1713 | ++catI; |
1711 | } | 1714 | } |
1712 | } | 1715 | } |
1713 | if (!mustUnlock) { | 1716 | if (!mustUnlock) { |
1714 | // nothing to do. | 1717 | // nothing to do. |
1715 | timer()->stop(DocTimer::id_autoLockTimer); | 1718 | timer()->stop(DocTimer::id_autoLockTimer); |
1716 | printDebug("unlockAll_tempoary(): nothing to do."); | 1719 | printDebug("unlockAll_tempoary(): nothing to do."); |
1717 | return true; | 1720 | return true; |
1718 | } else if (!wasDeepLocked) { | 1721 | } else if (!wasDeepLocked) { |
1719 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1722 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1720 | currentPw != "") { | 1723 | currentPw != "") { |
1721 | /* we can't unlock without mpw, so | 1724 | /* we can't unlock without mpw, so |
1722 | * we need to ask for it. | 1725 | * we need to ask for it. |
1723 | */ | 1726 | */ |
1724 | QString pw; | 1727 | QString pw; |
1725 | while (1) { | 1728 | while (1) { |
1726 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1729 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1727 | if (pw == "") { | 1730 | if (pw == "") { |
1728 | return false; | 1731 | return false; |
1729 | } else if (pw == currentPw) { | 1732 | } else if (pw == currentPw) { |
1730 | break; | 1733 | break; |
1731 | } | 1734 | } |
1732 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1735 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1733 | } | 1736 | } |
1734 | } | 1737 | } |
1735 | } | 1738 | } |
1736 | timer()->stop(DocTimer::id_autoLockTimer); | 1739 | timer()->stop(DocTimer::id_autoLockTimer); |
1737 | oldLockStates = new vector< vector<bool> >; | 1740 | oldLockStates = new vector< vector<bool> >; |
1738 | vector<bool> tmp_vec; | 1741 | vector<bool> tmp_vec; |
1739 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1742 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1740 | catEnd = dti.dta.end(), | 1743 | catEnd = dti.dta.end(), |
1741 | catI = catBegin; | 1744 | catI = catBegin; |
1742 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1745 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1743 | while (catI != catEnd) { | 1746 | while (catI != catEnd) { |
1744 | entrBegin = catI->d.begin(); | 1747 | entrBegin = catI->d.begin(); |
1745 | entrEnd = catI->d.end(); | 1748 | entrEnd = catI->d.end(); |
1746 | entrI = entrBegin; | 1749 | entrI = entrBegin; |
1747 | while (entrI != entrEnd) { | 1750 | while (entrI != entrEnd) { |
1748 | if (!wasDeepLocked) { | 1751 | if (!wasDeepLocked) { |
1749 | tmp_vec.push_back(entrI->lockStat); | 1752 | tmp_vec.push_back(entrI->lockStat); |
1750 | } | 1753 | } |
1751 | entrI->lockStat = false; | 1754 | entrI->lockStat = false; |
1752 | ++entrI; | 1755 | ++entrI; |
1753 | } | 1756 | } |
1754 | if (!wasDeepLocked) { | 1757 | if (!wasDeepLocked) { |
1755 | oldLockStates->push_back(tmp_vec); | 1758 | oldLockStates->push_back(tmp_vec); |
1756 | tmp_vec.clear(); | 1759 | tmp_vec.clear(); |
1757 | } | 1760 | } |
1758 | ++catI; | 1761 | ++catI; |
1759 | } | 1762 | } |
1760 | printDebug("tempoary unlocked dta."); | 1763 | printDebug("tempoary unlocked dta."); |
1761 | } | 1764 | } |
1762 | 1765 | ||
1763 | return true; | 1766 | return true; |
1764 | } | 1767 | } |
1765 | 1768 | ||
1766 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1769 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1767 | { | 1770 | { |
1768 | PwMerror ret; | 1771 | PwMerror ret; |
1769 | 1772 | ||
1770 | if (lock) { | 1773 | if (lock) { |
1771 | if (isDeepLocked()) | 1774 | if (isDeepLocked()) |
1772 | return e_lock; | 1775 | return e_lock; |
1773 | if (saveToFile) { | 1776 | if (saveToFile) { |
1774 | if (isDocEmpty()) | 1777 | if (isDocEmpty()) |
1775 | return e_docIsEmpty; | 1778 | return e_docIsEmpty; |
1776 | ret = saveDoc(conf()->confGlobCompression()); | 1779 | ret = saveDoc(conf()->confGlobCompression()); |
1777 | if (ret == e_filename) { | 1780 | if (ret == e_filename) { |
1778 | /* the doc wasn't saved to a file | 1781 | /* the doc wasn't saved to a file |
1779 | * by the user, yet. | 1782 | * by the user, yet. |
1780 | */ | 1783 | */ |
1781 | cantDeeplock_notSavedMsgBox(); | 1784 | cantDeeplock_notSavedMsgBox(); |
1782 | return e_docNotSaved; | 1785 | return e_docNotSaved; |
1783 | } else if (ret != e_success) { | 1786 | } else if (ret != e_success) { |
1784 | return e_lock; | 1787 | return e_lock; |
1785 | } | 1788 | } |
1786 | } | 1789 | } |
1787 | timer()->stop(DocTimer::id_autoLockTimer); | 1790 | timer()->stop(DocTimer::id_autoLockTimer); |
1788 | clearDoc(); | 1791 | clearDoc(); |
1789 | PwMDataItem d; | 1792 | PwMDataItem d; |
1790 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1793 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1791 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1794 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1792 | d.listViewPos = 0; | 1795 | d.listViewPos = 0; |
1793 | addEntry(DEFAULT_CATEGORY, &d, true); | 1796 | addEntry(DEFAULT_CATEGORY, &d, true); |
1794 | lockAt(DEFAULT_CATEGORY, 0, true); | 1797 | lockAt(DEFAULT_CATEGORY, 0, true); |
1795 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1798 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1796 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1799 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1797 | } else { | 1800 | } else { |
1798 | if (!isDeepLocked()) | 1801 | if (!isDeepLocked()) |
1799 | return e_lock; | 1802 | return e_lock; |
1800 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1803 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1801 | ? 0 : 1); | 1804 | ? 0 : 1); |
1802 | if (ret == e_wrongPw) { | 1805 | if (ret == e_wrongPw) { |
1803 | return e_wrongPw; | 1806 | return e_wrongPw; |
1804 | } else if (ret != e_success) { | 1807 | } else if (ret != e_success) { |
1805 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1808 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1806 | + tostr(static_cast<int>(ret))); | 1809 | + tostr(static_cast<int>(ret))); |
1807 | return e_lock; | 1810 | return e_lock; |
1808 | } | 1811 | } |
1809 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1812 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1810 | timer()->start(DocTimer::id_autoLockTimer); | 1813 | timer()->start(DocTimer::id_autoLockTimer); |
1811 | } | 1814 | } |
1812 | 1815 | ||
1813 | emitDataChanged(this); | 1816 | emitDataChanged(this); |
1814 | return e_success; | 1817 | return e_success; |
1815 | } | 1818 | } |
1816 | 1819 | ||
1817 | void PwMDoc::_deepUnlock() | 1820 | void PwMDoc::_deepUnlock() |
1818 | { | 1821 | { |
1819 | deepLock(false); | 1822 | deepLock(false); |
1820 | } | 1823 | } |
1821 | 1824 | ||
1822 | void PwMDoc::clearDoc() | 1825 | void PwMDoc::clearDoc() |
1823 | { | 1826 | { |
1824 | dti.clear(); | 1827 | dti.clear(); |
1825 | PwMCategoryItem d; | 1828 | PwMCategoryItem d; |
1826 | d.name = DEFAULT_CATEGORY.latin1(); | 1829 | d.name = DEFAULT_CATEGORY.latin1(); |
1827 | dti.dta.push_back(d); | 1830 | dti.dta.push_back(d); |
1828 | currentPw = ""; | 1831 | currentPw = ""; |
1829 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1832 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1830 | } | 1833 | } |
1831 | 1834 | ||
1832 | void PwMDoc::changeCurrentPw() | 1835 | void PwMDoc::changeCurrentPw() |
1833 | { | 1836 | { |
1834 | if (currentPw == "") | 1837 | if (currentPw == "") |
1835 | return; // doc hasn't been saved. No mpw available. | 1838 | return; // doc hasn't been saved. No mpw available. |
1836 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1839 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1837 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1840 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1838 | if (pw == "") | 1841 | if (pw == "") |
1839 | return; | 1842 | return; |
1840 | if (useChipcard) | 1843 | if (useChipcard) |
1841 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1844 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1842 | else | 1845 | else |
1843 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1846 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1844 | setCurrentPw(pw); | 1847 | setCurrentPw(pw); |
1845 | } | 1848 | } |
1846 | 1849 | ||
1847 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1850 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1848 | int pos) | 1851 | int pos) |
1849 | { | 1852 | { |
1850 | unsigned int cat = 0; | 1853 | unsigned int cat = 0; |
1851 | 1854 | ||
1852 | if (!findCategory(category, &cat)) { | 1855 | if (!findCategory(category, &cat)) { |
1853 | BUG(); | 1856 | BUG(); |
1854 | return; | 1857 | return; |
1855 | } | 1858 | } |
1856 | setListViewPos(cat, index, pos); | 1859 | setListViewPos(cat, index, pos); |
1857 | } | 1860 | } |
1858 | 1861 | ||
1859 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1862 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1860 | int pos) | 1863 | int pos) |
1861 | { | 1864 | { |
1862 | dti.dta[category].d[index].listViewPos = pos; | 1865 | dti.dta[category].d[index].listViewPos = pos; |
1863 | 1866 | ||
1864 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1867 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1865 | * get's called when it shouldn't. It's because PwMView assumes | 1868 | * get's called when it shouldn't. It's because PwMView assumes |
1866 | * the user resorted the UI on behalf of signal layoutChanged(). | 1869 | * the user resorted the UI on behalf of signal layoutChanged(). |
1867 | * This is somewhat broken and incorrect, but I've no other | 1870 | * This is somewhat broken and incorrect, but I've no other |
1868 | * solution for now. | 1871 | * solution for now. |
1869 | */ | 1872 | */ |
1870 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1873 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1871 | } | 1874 | } |
1872 | 1875 | ||
1873 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1876 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1874 | { | 1877 | { |
1875 | unsigned int cat = 0; | 1878 | unsigned int cat = 0; |
1876 | 1879 | ||
1877 | if (!findCategory(category, &cat)) { | 1880 | if (!findCategory(category, &cat)) { |
1878 | BUG(); | 1881 | BUG(); |
1879 | return -1; | 1882 | return -1; |
1880 | } | 1883 | } |
1881 | 1884 | ||
1882 | return dti.dta[cat].d[index].listViewPos; | 1885 | return dti.dta[cat].d[index].listViewPos; |
1883 | } | 1886 | } |
1884 | 1887 | ||
1885 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1888 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1886 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1889 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1887 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1890 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1888 | { | 1891 | { |
1889 | PWM_ASSERT(foundPositions); | 1892 | PWM_ASSERT(foundPositions); |
1890 | PWM_ASSERT(searchIn); | 1893 | PWM_ASSERT(searchIn); |
1891 | foundPositions->clear(); | 1894 | foundPositions->clear(); |
1892 | 1895 | ||
1893 | unsigned int i, entries = numEntries(category); | 1896 | unsigned int i, entries = numEntries(category); |
1894 | for (i = 0; i < entries; ++i) { | 1897 | for (i = 0; i < entries; ++i) { |
1895 | if (searchIn & SEARCH_IN_DESC) { | 1898 | if (searchIn & SEARCH_IN_DESC) { |
1896 | if (!compareString(find.desc, dti.dta[category].d[i].desc, | 1899 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1897 | caseSensitive, exactWordMatch)) { | 1900 | caseSensitive, exactWordMatch)) { |
1898 | continue; | 1901 | continue; |
1899 | } | 1902 | } |
1900 | } | 1903 | } |
1901 | if (searchIn & SEARCH_IN_NAME) { | 1904 | if (searchIn & SEARCH_IN_NAME) { |
1902 | if (!compareString(find.name, dti.dta[category].d[i].name, | 1905 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1903 | caseSensitive, exactWordMatch)) { | 1906 | caseSensitive, exactWordMatch)) { |
1904 | continue; | 1907 | continue; |
1905 | } | 1908 | } |
1906 | } | 1909 | } |
1907 | if (searchIn & SEARCH_IN_PW) { | 1910 | if (searchIn & SEARCH_IN_PW) { |
1908 | bool wasLocked = isLocked(category, i); | 1911 | bool wasLocked = isLocked(category, i); |
1909 | getDataChangedLock(); | 1912 | getDataChangedLock(); |
1910 | lockAt(category, i, false); | 1913 | lockAt(category, i, false); |
1911 | if (!compareString(find.pw, dti.dta[category].d[i].pw, | 1914 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1912 | caseSensitive, exactWordMatch)) { | 1915 | caseSensitive, exactWordMatch)) { |
1913 | lockAt(category, i, wasLocked); | 1916 | lockAt(category, i, wasLocked); |
1914 | putDataChangedLock(); | 1917 | putDataChangedLock(); |
1915 | continue; | 1918 | continue; |
1916 | } | 1919 | } |
1917 | lockAt(category, i, wasLocked); | 1920 | lockAt(category, i, wasLocked); |
1918 | putDataChangedLock(); | 1921 | putDataChangedLock(); |
1919 | } | 1922 | } |
1920 | if (searchIn & SEARCH_IN_COMMENT) { | 1923 | if (searchIn & SEARCH_IN_COMMENT) { |
1921 | if (!compareString(find.comment, dti.dta[category].d[i].comment, | 1924 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1922 | caseSensitive, exactWordMatch)) { | 1925 | caseSensitive, exactWordMatch)) { |
1923 | continue; | 1926 | continue; |
1924 | } | 1927 | } |
1925 | } | 1928 | } |
1926 | if (searchIn & SEARCH_IN_URL) { | 1929 | if (searchIn & SEARCH_IN_URL) { |
1927 | if (!compareString(find.url, dti.dta[category].d[i].url, | 1930 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1928 | caseSensitive, exactWordMatch)) { | 1931 | caseSensitive, exactWordMatch)) { |
1929 | continue; | 1932 | continue; |
1930 | } | 1933 | } |
1931 | } | 1934 | } |
1932 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1935 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1933 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, | 1936 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1934 | caseSensitive, exactWordMatch)) { | 1937 | caseSensitive, exactWordMatch)) { |
1935 | continue; | 1938 | continue; |
1936 | } | 1939 | } |
1937 | } | 1940 | } |
1938 | 1941 | ||
1939 | // all selected "searchIn" matched. | 1942 | // all selected "searchIn" matched. |
1940 | foundPositions->push_back(i); | 1943 | foundPositions->push_back(i); |
1941 | if (breakAfterFound) | 1944 | if (breakAfterFound) |
1942 | break; | 1945 | break; |
1943 | } | 1946 | } |
1944 | 1947 | ||
1945 | if (sortByLvp && foundPositions->size() > 1) { | 1948 | if (sortByLvp && foundPositions->size() > 1) { |
1946 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 1949 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
1947 | unsigned int /* lvp-pos */> > tmp_vec; | 1950 | unsigned int /* lvp-pos */> > tmp_vec; |
1948 | 1951 | ||
1949 | unsigned int i, items = foundPositions->size(); | 1952 | unsigned int i, items = foundPositions->size(); |
1950 | pair<unsigned int, unsigned int> tmp_pair; | 1953 | pair<unsigned int, unsigned int> tmp_pair; |
1951 | for (i = 0; i < items; ++i) { | 1954 | for (i = 0; i < items; ++i) { |
1952 | tmp_pair.first = (*foundPositions)[i]; | 1955 | tmp_pair.first = (*foundPositions)[i]; |
1953 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; | 1956 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
1954 | tmp_vec.push_back(tmp_pair); | 1957 | tmp_vec.push_back(tmp_pair); |
1955 | } | 1958 | } |
1956 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 1959 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
1957 | foundPositions->clear(); | 1960 | foundPositions->clear(); |
1958 | for (i = 0; i < items; ++i) { | 1961 | for (i = 0; i < items; ++i) { |
1959 | foundPositions->push_back(tmp_vec[i].first); | 1962 | foundPositions->push_back(tmp_vec[i].first); |
1960 | } | 1963 | } |
1961 | } | 1964 | } |
1962 | } | 1965 | } |
1963 | 1966 | ||
1964 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 1967 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
1965 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1968 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1966 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1969 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1967 | { | 1970 | { |
1968 | PWM_ASSERT(foundPositions); | 1971 | PWM_ASSERT(foundPositions); |
1969 | unsigned int cat = 0; | 1972 | unsigned int cat = 0; |
1970 | 1973 | ||
1971 | if (!findCategory(category, &cat)) { | 1974 | if (!findCategory(category, &cat)) { |
1972 | foundPositions->clear(); | 1975 | foundPositions->clear(); |
1973 | return; | 1976 | return; |
1974 | } | 1977 | } |
1975 | 1978 | ||
1976 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 1979 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
1977 | caseSensitive, exactWordMatch, sortByLvp); | 1980 | caseSensitive, exactWordMatch, sortByLvp); |
1978 | } | 1981 | } |
1979 | 1982 | ||
1980 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 1983 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
1981 | bool exactWordMatch) | 1984 | bool exactWordMatch) |
1982 | { | 1985 | { |
1983 | QString _s1(s1.c_str()); | 1986 | QString _s1(s1.c_str()); |
1984 | QString _s2(s2.c_str()); | 1987 | QString _s2(s2.c_str()); |
1985 | if (!caseSensitive) { | 1988 | if (!caseSensitive) { |
1986 | _s1 = _s1.lower(); | 1989 | _s1 = _s1.lower(); |
1987 | _s2 = _s2.lower(); | 1990 | _s2 = _s2.lower(); |
1988 | } | 1991 | } |
1989 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 1992 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
1990 | return true; | 1993 | return true; |
1991 | return false; | 1994 | return false; |
1992 | } | 1995 | } |
1993 | 1996 | ||
1994 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 1997 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
1995 | { | 1998 | { |
1996 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 1999 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
1997 | end = dti.dta.end(); | 2000 | end = dti.dta.end(); |
1998 | while (i != end) { | 2001 | while (i != end) { |
1999 | if ((*i).name == name.latin1()) { | 2002 | if ((*i).name == name.latin1()) { |
2000 | if (index) { | 2003 | if (index) { |
2001 | *index = i - dti.dta.begin(); | 2004 | *index = i - dti.dta.begin(); |
2002 | } | 2005 | } |
2003 | return true; | 2006 | return true; |
2004 | } | 2007 | } |
2005 | ++i; | 2008 | ++i; |
2006 | } | 2009 | } |
2007 | return false; | 2010 | return false; |
2008 | } | 2011 | } |
2009 | 2012 | ||
2010 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2013 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2011 | { | 2014 | { |
2012 | unsigned int cat = 0; | 2015 | unsigned int cat = 0; |
2013 | 2016 | ||
2014 | if (!findCategory(category, &cat)) | 2017 | if (!findCategory(category, &cat)) |
2015 | return false; | 2018 | return false; |
2016 | 2019 | ||
2017 | return renameCategory(cat, newName); | 2020 | return renameCategory(cat, newName); |
2018 | } | 2021 | } |
2019 | 2022 | ||
2020 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2023 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2021 | bool dontFlagDirty) | 2024 | bool dontFlagDirty) |
2022 | { | 2025 | { |
2023 | if (category > numCategories() - 1) | 2026 | if (category > numCategories() - 1) |
2024 | return false; | 2027 | return false; |
2025 | 2028 | ||
2026 | dti.dta[category].name = newName.latin1(); | 2029 | dti.dta[category].name = newName.latin1(); |
2027 | if (!dontFlagDirty) | 2030 | if (!dontFlagDirty) |
2028 | flagDirty(); | 2031 | flagDirty(); |
2029 | 2032 | ||
2030 | return true; | 2033 | return true; |
2031 | } | 2034 | } |
2032 | 2035 | ||
2033 | bool PwMDoc::delCategory(const QString &category) | 2036 | bool PwMDoc::delCategory(const QString &category) |
2034 | { | 2037 | { |
2035 | unsigned int cat = 0; | 2038 | unsigned int cat = 0; |
2036 | 2039 | ||
2037 | if (!findCategory(category, &cat)) | 2040 | if (!findCategory(category, &cat)) |
2038 | return false; | 2041 | return false; |
2039 | 2042 | ||
2040 | return delCategory(cat); | 2043 | return delCategory(cat); |
2041 | } | 2044 | } |
2042 | 2045 | ||
2043 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2046 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2044 | { | 2047 | { |
2045 | if (category > numCategories() - 1) | 2048 | if (category > numCategories() - 1) |
2046 | return false; | 2049 | return false; |
2047 | 2050 | ||
2048 | // We don't delete it, if it is the last existing | 2051 | // We don't delete it, if it is the last existing |
2049 | // category! Instead we rename it to "Default". | 2052 | // category! Instead we rename it to "Default". |
2050 | if (numCategories() > 1) { | 2053 | if (numCategories() > 1) { |
2051 | dti.dta.erase(dti.dta.begin() + category); | 2054 | dti.dta.erase(dti.dta.begin() + category); |
2052 | } else { | 2055 | } else { |
2053 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2056 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2054 | return true; | 2057 | return true; |
2055 | } | 2058 | } |
2056 | if (!dontFlagDirty) | 2059 | if (!dontFlagDirty) |
2057 | flagDirty(); | 2060 | flagDirty(); |
2058 | 2061 | ||
2059 | return true; | 2062 | return true; |
2060 | } | 2063 | } |
2061 | 2064 | ||
2062 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2065 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2063 | { | 2066 | { |
2064 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), | 2067 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2065 | end = dti.dta.end(), | 2068 | end = dti.dta.end(), |
2066 | i = begin; | 2069 | i = begin; |
2067 | while (i != end) { | 2070 | while (i != end) { |
2068 | if (i->d.empty()) { | 2071 | if (i->d.empty()) { |
2069 | delCategory(begin - i, dontFlagDirty); | 2072 | delCategory(begin - i, dontFlagDirty); |
2070 | } | 2073 | } |
2071 | ++i; | 2074 | ++i; |
2072 | } | 2075 | } |
2073 | } | 2076 | } |
2074 | 2077 | ||
2075 | void PwMDoc::getCategoryList(vector<string> *list) | 2078 | void PwMDoc::getCategoryList(vector<string> *list) |
2076 | { | 2079 | { |
2077 | PWM_ASSERT(list); | 2080 | PWM_ASSERT(list); |
2078 | list->clear(); | 2081 | list->clear(); |
2079 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2082 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2080 | end = dti.dta.end(); | 2083 | end = dti.dta.end(); |
2081 | while (i != end) { | 2084 | while (i != end) { |
2082 | list->push_back(i->name); | 2085 | list->push_back(i->name); |
2083 | ++i; | 2086 | ++i; |
2084 | } | 2087 | } |
2085 | } | 2088 | } |
2086 | 2089 | ||
2087 | void PwMDoc::getCategoryList(QStringList *list) | 2090 | void PwMDoc::getCategoryList(QStringList *list) |
2088 | { | 2091 | { |
2089 | PWM_ASSERT(list); | 2092 | PWM_ASSERT(list); |
2090 | list->clear(); | 2093 | list->clear(); |
2091 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2094 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2092 | end = dti.dta.end(); | 2095 | end = dti.dta.end(); |
2093 | while (i != end) { | 2096 | while (i != end) { |
2094 | #ifndef PWM_EMBEDDED | 2097 | #ifndef PWM_EMBEDDED |
2095 | list->push_back(i->name.c_str()); | 2098 | list->push_back(i->name.c_str()); |
2096 | #else | 2099 | #else |
2097 | list->append(i->name.c_str()); | 2100 | list->append(i->name.c_str()); |
2098 | #endif | 2101 | #endif |
2099 | ++i; | 2102 | ++i; |
2100 | } | 2103 | } |
2101 | } | 2104 | } |
2102 | 2105 | ||
2103 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2106 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2104 | { | 2107 | { |
2105 | PWM_ASSERT(list); | 2108 | PWM_ASSERT(list); |
2106 | unsigned int cat = 0; | 2109 | unsigned int cat = 0; |
2107 | if (!findCategory(category, &cat)) { | 2110 | if (!findCategory(category, &cat)) { |
2108 | list->clear(); | 2111 | list->clear(); |
2109 | return; | 2112 | return; |
2110 | } | 2113 | } |
2111 | getEntryList(cat, list); | 2114 | getEntryList(cat, list); |
2112 | } | 2115 | } |
2113 | 2116 | ||
2114 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2117 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2115 | { | 2118 | { |
2116 | PWM_ASSERT(list); | 2119 | PWM_ASSERT(list); |
2117 | unsigned int cat = 0; | 2120 | unsigned int cat = 0; |
2118 | if (!findCategory(category, &cat)) { | 2121 | if (!findCategory(category, &cat)) { |
2119 | list->clear(); | 2122 | list->clear(); |
2120 | return; | 2123 | return; |
2121 | } | 2124 | } |
2122 | getEntryList(cat, list); | 2125 | getEntryList(cat, list); |
2123 | } | 2126 | } |
2124 | 2127 | ||
2125 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2128 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2126 | { | 2129 | { |
2127 | PWM_ASSERT(list); | 2130 | PWM_ASSERT(list); |
2128 | list->clear(); | 2131 | list->clear(); |
2129 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2132 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2130 | end = dti.dta[category].d.end(), | 2133 | end = dti.dta[category].d.end(), |
2131 | i = begin; | 2134 | i = begin; |
2132 | while (i != end) { | 2135 | while (i != end) { |
2133 | list->push_back(i->desc); | 2136 | list->push_back(i->desc); |
2134 | ++i; | 2137 | ++i; |
2135 | } | 2138 | } |
2136 | } | 2139 | } |
2137 | 2140 | ||
2138 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2141 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2139 | { | 2142 | { |
2140 | PWM_ASSERT(list); | 2143 | PWM_ASSERT(list); |
2141 | list->clear(); | 2144 | list->clear(); |
2142 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2145 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2143 | end = dti.dta[category].d.end(), | 2146 | end = dti.dta[category].d.end(), |
2144 | i = begin; | 2147 | i = begin; |
2145 | while (i != end) { | 2148 | while (i != end) { |
2146 | #ifndef PWM_EMBEDDED | 2149 | #ifndef PWM_EMBEDDED |
2147 | list->push_back(i->desc.c_str()); | 2150 | list->push_back(i->desc.c_str()); |
2148 | #else | 2151 | #else |
2149 | list->append(i->desc.c_str()); | 2152 | list->append(i->desc.c_str()); |
2150 | #endif | 2153 | #endif |
2151 | ++i; | 2154 | ++i; |
2152 | } | 2155 | } |
2153 | } | 2156 | } |
2154 | 2157 | ||
2155 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2158 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2156 | { | 2159 | { |
2157 | unsigned int cat = 0; | 2160 | unsigned int cat = 0; |
2158 | 2161 | ||
2159 | if (!findCategory(category, &cat)) | 2162 | if (!findCategory(category, &cat)) |
2160 | return false; | 2163 | return false; |
2161 | 2164 | ||
2162 | return execLauncher(cat, entryIndex); | 2165 | return execLauncher(cat, entryIndex); |
2163 | } | 2166 | } |
2164 | 2167 | ||
2165 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2168 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2166 | { | 2169 | { |
2167 | if (geteuid() == 0) { | 2170 | if (geteuid() == 0) { |
2168 | rootAlertMsgBox(); | 2171 | rootAlertMsgBox(); |
2169 | return false; | 2172 | return false; |
2170 | } | 2173 | } |
2171 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2174 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2172 | bool wasLocked = isLocked(category, entryIndex); | 2175 | bool wasLocked = isLocked(category, entryIndex); |
2173 | 2176 | ||
2174 | if (command.find("$p") != -1) { | 2177 | if (command.find("$p") != -1) { |
2175 | /* the user requested the password to be included | 2178 | /* the user requested the password to be included |
2176 | * into the command. We have to ask for the password, | 2179 | * into the command. We have to ask for the password, |
2177 | * if it's locked. We do that by unlocking the entry | 2180 | * if it's locked. We do that by unlocking the entry |
2178 | */ | 2181 | */ |
2179 | if (!lockAt(category, entryIndex, false)) | 2182 | if (!lockAt(category, entryIndex, false)) |
2180 | return false; | 2183 | return false; |
2181 | } | 2184 | } |
2182 | #ifndef PWM_EMBEDDED | 2185 | #ifndef PWM_EMBEDDED |
2183 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2186 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2184 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2187 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2185 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2188 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2186 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2189 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2187 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2190 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2188 | #else | 2191 | #else |
2189 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2192 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2190 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2193 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2191 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2194 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2192 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2195 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2193 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2196 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2194 | #endif | 2197 | #endif |
2195 | command.append(" &"); | 2198 | command.append(" &"); |
2196 | 2199 | ||
2197 | QString customXterm(conf()->confGlobXtermCommand()); | 2200 | QString customXterm(conf()->confGlobXtermCommand()); |
2198 | if (!customXterm.isEmpty()) | 2201 | if (!customXterm.isEmpty()) |
2199 | command = customXterm + " " + command; | 2202 | command = customXterm + " " + command; |
2200 | 2203 | ||
2201 | system(command.latin1()); | 2204 | system(command.latin1()); |
2202 | 2205 | ||
2203 | lockAt(category, entryIndex, wasLocked); | 2206 | lockAt(category, entryIndex, wasLocked); |
2204 | return true; | 2207 | return true; |
2205 | } | 2208 | } |
2206 | 2209 | ||
2207 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2210 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2208 | { | 2211 | { |
2209 | unsigned int cat = 0; | 2212 | unsigned int cat = 0; |
2210 | 2213 | ||
2211 | if (!findCategory(category, &cat)) | 2214 | if (!findCategory(category, &cat)) |
2212 | return false; | 2215 | return false; |
2213 | 2216 | ||
2214 | return goToURL(cat, entryIndex); | 2217 | return goToURL(cat, entryIndex); |
2215 | } | 2218 | } |
2216 | 2219 | ||
2217 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2220 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2218 | { | 2221 | { |
2219 | if (geteuid() == 0) { | 2222 | if (geteuid() == 0) { |
2220 | rootAlertMsgBox(); | 2223 | rootAlertMsgBox(); |
2221 | return false; | 2224 | return false; |
2222 | } | 2225 | } |
2223 | QString url(dti.dta[category].d[entryIndex].url.c_str()); | 2226 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2224 | if (url.isEmpty()) | 2227 | if (url.isEmpty()) |
2225 | return false; | 2228 | return false; |
2226 | 2229 | ||
2227 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2230 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2228 | if (!customBrowser.isEmpty()) { | 2231 | if (!customBrowser.isEmpty()) { |
2229 | browserProc.clearArguments(); | 2232 | browserProc.clearArguments(); |
2230 | browserProc << customBrowser << url; | 2233 | browserProc << customBrowser << url; |
2231 | if (browserProc.start(KProcess::DontCare)) | 2234 | if (browserProc.start(KProcess::DontCare)) |
2232 | return true; | 2235 | return true; |
2233 | } | 2236 | } |
2234 | 2237 | ||
2235 | browserProc.clearArguments(); | 2238 | browserProc.clearArguments(); |
2236 | browserProc << "konqueror" << url; | 2239 | browserProc << "konqueror" << url; |
2237 | if (browserProc.start(KProcess::DontCare)) | 2240 | if (browserProc.start(KProcess::DontCare)) |
2238 | return true; | 2241 | return true; |
2239 | 2242 | ||
2240 | browserProc.clearArguments(); | 2243 | browserProc.clearArguments(); |
2241 | browserProc << "mozilla" << url; | 2244 | browserProc << "mozilla" << url; |
2242 | if (browserProc.start(KProcess::DontCare)) | 2245 | if (browserProc.start(KProcess::DontCare)) |
2243 | return true; | 2246 | return true; |
2244 | 2247 | ||
2245 | browserProc.clearArguments(); | 2248 | browserProc.clearArguments(); |
2246 | browserProc << "opera" << url; | 2249 | browserProc << "opera" << url; |
2247 | if (browserProc.start(KProcess::DontCare)) | 2250 | if (browserProc.start(KProcess::DontCare)) |
2248 | return true; | 2251 | return true; |
2249 | return false; | 2252 | return false; |
2250 | } | 2253 | } |
2251 | 2254 | ||
2252 | PwMerror PwMDoc::exportToText(const QString *file) | 2255 | PwMerror PwMDoc::exportToText(const QString *file) |
2253 | { | 2256 | { |
2254 | PWM_ASSERT(file); | 2257 | PWM_ASSERT(file); |
2255 | if (QFile::exists(*file)) { | 2258 | if (QFile::exists(*file)) { |
2256 | if (!QFile::remove(*file)) | 2259 | if (!QFile::remove(*file)) |
2257 | return e_accessFile; | 2260 | return e_accessFile; |
2258 | } | 2261 | } |
2259 | QFile f(*file); | 2262 | QFile f(*file); |
2260 | if (!f.open(IO_ReadWrite)) | 2263 | if (!f.open(IO_ReadWrite)) |
2261 | return e_openFile; | 2264 | return e_openFile; |
2262 | 2265 | ||
2263 | if (!unlockAll_tempoary()) { | 2266 | if (!unlockAll_tempoary()) { |
2264 | f.close(); | 2267 | f.close(); |
2265 | return e_lock; | 2268 | return e_lock; |
2266 | } | 2269 | } |
2267 | 2270 | ||
2268 | // write header | 2271 | // write header |
2269 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2272 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2270 | header += PACKAGE_VER; | 2273 | header += PACKAGE_VER; |
2271 | header += i18n("\non ").latin1(); | 2274 | header += i18n("\non ").latin1(); |
2272 | QDate currDate = QDate::currentDate(); | 2275 | QDate currDate = QDate::currentDate(); |
2273 | QTime currTime = QTime::currentTime(); | 2276 | QTime currTime = QTime::currentTime(); |
2274 | 2277 | ||
2275 | #ifndef PWM_EMBEDDED | 2278 | #ifndef PWM_EMBEDDED |
2276 | header += currDate.toString("ddd MMMM d ").latin1(); | 2279 | header += currDate.toString("ddd MMMM d ").latin1(); |
2277 | header += currTime.toString("hh:mm:ss ").latin1(); | 2280 | header += currTime.toString("hh:mm:ss ").latin1(); |
2278 | #else | 2281 | #else |
2279 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2282 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2280 | bool ampm = KGlobal::locale()->use12Clock(); | 2283 | bool ampm = KGlobal::locale()->use12Clock(); |
2281 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2284 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2282 | KGlobal::locale()->setHore24Format(true); | 2285 | KGlobal::locale()->setHore24Format(true); |
2283 | 2286 | ||
2284 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); | 2287 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); |
2285 | header += KGlobal::locale()->formatTime(currTime, true); | 2288 | header += KGlobal::locale()->formatTime(currTime, true); |
2286 | KGlobal::locale()->setDateFormatShort(dfs); | 2289 | KGlobal::locale()->setDateFormatShort(dfs); |
2287 | KGlobal::locale()->setHore24Format(!ampm); | 2290 | KGlobal::locale()->setHore24Format(!ampm); |
2288 | 2291 | ||
2289 | #endif | 2292 | #endif |
2290 | header += tostr(currDate.year()); | 2293 | header += tostr(currDate.year()); |
2291 | header += "\n==============================\n\n"; | 2294 | header += "\n==============================\n\n"; |
2292 | 2295 | ||
2293 | 2296 | ||
2294 | #ifndef PWM_EMBEDDED | 2297 | #ifndef PWM_EMBEDDED |
2295 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2298 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2296 | unlockAll_tempoary(true); | 2299 | unlockAll_tempoary(true); |
2297 | f.close(); | 2300 | f.close(); |
2298 | return e_writeFile; | 2301 | return e_writeFile; |
2299 | } | 2302 | } |
2300 | #else | 2303 | #else |
2301 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2304 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2302 | unlockAll_tempoary(true); | 2305 | unlockAll_tempoary(true); |
2303 | f.close(); | 2306 | f.close(); |
2304 | return e_writeFile; | 2307 | return e_writeFile; |
2305 | } | 2308 | } |
2306 | #endif | 2309 | #endif |
2307 | unsigned int i, numCat = numCategories(); | 2310 | unsigned int i, numCat = numCategories(); |
2308 | unsigned int j, numEnt; | 2311 | unsigned int j, numEnt; |
2309 | string exp; | 2312 | string exp; |
2310 | for (i = 0; i < numCat; ++i) { | 2313 | for (i = 0; i < numCat; ++i) { |
2311 | numEnt = numEntries(i); | 2314 | numEnt = numEntries(i); |
2312 | 2315 | ||
2313 | exp = "\n== Category: "; | 2316 | exp = "\n== Category: "; |
2314 | exp += dti.dta[i].name; | 2317 | exp += dti.dta[i].name; |
2315 | exp += " ==\n"; | 2318 | exp += " ==\n"; |
2316 | #ifndef PWM_EMBEDDED | 2319 | #ifndef PWM_EMBEDDED |
2317 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2320 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2318 | unlockAll_tempoary(true); | 2321 | unlockAll_tempoary(true); |
2319 | f.close(); | 2322 | f.close(); |
2320 | return e_writeFile; | 2323 | return e_writeFile; |
2321 | } | 2324 | } |
2322 | #else | 2325 | #else |
2323 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2326 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2324 | unlockAll_tempoary(true); | 2327 | unlockAll_tempoary(true); |
2325 | f.close(); | 2328 | f.close(); |
2326 | return e_writeFile; | 2329 | return e_writeFile; |
2327 | } | 2330 | } |
2328 | #endif | 2331 | #endif |
2329 | for (j = 0; j < numEnt; ++j) { | 2332 | for (j = 0; j < numEnt; ++j) { |
2330 | exp = "\n-- "; | 2333 | exp = "\n-- "; |
2331 | exp += dti.dta[i].d[j].desc; | 2334 | exp += dti.dta[i].d[j].desc; |
2332 | exp += " --\n"; | 2335 | exp += " --\n"; |
2333 | 2336 | ||
2334 | exp += i18n("Username: ").latin1(); | 2337 | exp += i18n("Username: ").latin1(); |
2335 | exp += dti.dta[i].d[j].name; | 2338 | exp += dti.dta[i].d[j].name; |
2336 | exp += "\n"; | 2339 | exp += "\n"; |
2337 | 2340 | ||
2338 | exp += i18n("Password: ").latin1(); | 2341 | exp += i18n("Password: ").latin1(); |
2339 | exp += dti.dta[i].d[j].pw; | 2342 | exp += dti.dta[i].d[j].pw; |
2340 | exp += "\n"; | 2343 | exp += "\n"; |
2341 | 2344 | ||
2342 | exp += i18n("Comment: ").latin1(); | 2345 | exp += i18n("Comment: ").latin1(); |
2343 | exp += dti.dta[i].d[j].comment; | 2346 | exp += dti.dta[i].d[j].comment; |
2344 | exp += "\n"; | 2347 | exp += "\n"; |
2345 | 2348 | ||
2346 | exp += i18n("URL: ").latin1(); | 2349 | exp += i18n("URL: ").latin1(); |
2347 | exp += dti.dta[i].d[j].url; | 2350 | exp += dti.dta[i].d[j].url; |
2348 | exp += "\n"; | 2351 | exp += "\n"; |
2349 | 2352 | ||
2350 | exp += i18n("Launcher: ").latin1(); | 2353 | exp += i18n("Launcher: ").latin1(); |
2351 | exp += dti.dta[i].d[j].launcher; | 2354 | exp += dti.dta[i].d[j].launcher; |
2352 | exp += "\n"; | 2355 | exp += "\n"; |
2353 | 2356 | ||
2354 | #ifndef PWM_EMBEDDED | 2357 | #ifndef PWM_EMBEDDED |
2355 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2358 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2356 | unlockAll_tempoary(true); | 2359 | unlockAll_tempoary(true); |
2357 | f.close(); | 2360 | f.close(); |
2358 | return e_writeFile; | 2361 | return e_writeFile; |
2359 | } | 2362 | } |
2360 | #else | 2363 | #else |
2361 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2364 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2362 | unlockAll_tempoary(true); | 2365 | unlockAll_tempoary(true); |
2363 | f.close(); | 2366 | f.close(); |
2364 | return e_writeFile; | 2367 | return e_writeFile; |
2365 | } | 2368 | } |
2366 | #endif | 2369 | #endif |
2367 | } | 2370 | } |
2368 | } | 2371 | } |
2369 | unlockAll_tempoary(true); | 2372 | unlockAll_tempoary(true); |
2370 | f.close(); | 2373 | f.close(); |
2371 | 2374 | ||
2372 | return e_success; | 2375 | return e_success; |
2373 | } | 2376 | } |
2374 | 2377 | ||
2375 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2378 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2376 | { | 2379 | { |
2377 | PWM_ASSERT(file); | 2380 | PWM_ASSERT(file); |
2378 | if (format == 0) | 2381 | if (format == 0) |
2379 | return importText_PwM(file); | 2382 | return importText_PwM(file); |
2380 | else if (format == -1) { | 2383 | else if (format == -1) { |
2381 | // probe for all formats | 2384 | // probe for all formats |
2382 | if (importText_PwM(file) == e_success) | 2385 | if (importText_PwM(file) == e_success) |
2383 | return e_success; | 2386 | return e_success; |
2384 | dti.clear(); | 2387 | dti.clear(); |
2385 | emitDataChanged(this); | 2388 | emitDataChanged(this); |
2386 | // add next format here... | 2389 | // add next format here... |
2387 | return e_fileFormat; | 2390 | return e_fileFormat; |
2388 | } | 2391 | } |
2389 | return e_invalidArg; | 2392 | return e_invalidArg; |
2390 | } | 2393 | } |
2391 | 2394 | ||
2392 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2395 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2393 | { | 2396 | { |
2394 | #ifndef PWM_EMBEDDED | 2397 | #ifndef PWM_EMBEDDED |
2395 | PWM_ASSERT(file); | 2398 | PWM_ASSERT(file); |
2396 | FILE *f; | 2399 | FILE *f; |
2397 | int tmp; | 2400 | int tmp; |
2398 | ssize_t ret; | 2401 | ssize_t ret; |
2399 | string curCat; | 2402 | string curCat; |
2400 | unsigned int entriesRead = 0; | 2403 | unsigned int entriesRead = 0; |
2401 | PwMDataItem currItem; | 2404 | PwMDataItem currItem; |
2402 | f = fopen(file->latin1(), "r"); | 2405 | f = fopen(file->latin1(), "r"); |
2403 | if (!f) | 2406 | if (!f) |
2404 | return e_openFile; | 2407 | return e_openFile; |
2405 | size_t ch_tmp_size = 1024; | 2408 | size_t ch_tmp_size = 1024; |
2406 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2409 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2407 | if (!ch_tmp) { | 2410 | if (!ch_tmp) { |
2408 | fclose(f); | 2411 | fclose(f); |
2409 | return e_outOfMem; | 2412 | return e_outOfMem; |
2410 | } | 2413 | } |
2411 | 2414 | ||
2412 | // - check header | 2415 | // - check header |
2413 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2416 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2414 | goto formatError; | 2417 | goto formatError; |
2415 | // check version-string and return version in "ch_tmp". | 2418 | // check version-string and return version in "ch_tmp". |
2416 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2419 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2417 | // header not recognized as PwM generated header | 2420 | // header not recognized as PwM generated header |
2418 | goto formatError; | 2421 | goto formatError; |
2419 | } | 2422 | } |
2420 | // set filepointer behind version-string-line previously checked | 2423 | // set filepointer behind version-string-line previously checked |
2421 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2424 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2422 | goto formatError; | 2425 | goto formatError; |
2423 | // skip next line containing the build-date | 2426 | // skip next line containing the build-date |
2424 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2427 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2425 | goto formatError; | 2428 | goto formatError; |
2426 | // read header termination line | 2429 | // read header termination line |
2427 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2430 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2428 | goto formatError; | 2431 | goto formatError; |
2429 | if (strcmp(ch_tmp, "==============================\n")) | 2432 | if (strcmp(ch_tmp, "==============================\n")) |
2430 | goto formatError; | 2433 | goto formatError; |
2431 | 2434 | ||
2432 | // - read entries | 2435 | // - read entries |
2433 | do { | 2436 | do { |
2434 | // find beginning of next category | 2437 | // find beginning of next category |
2435 | do { | 2438 | do { |
2436 | tmp = fgetc(f); | 2439 | tmp = fgetc(f); |
2437 | } while (tmp == '\n' && tmp != EOF); | 2440 | } while (tmp == '\n' && tmp != EOF); |
2438 | if (tmp == EOF) | 2441 | if (tmp == EOF) |
2439 | break; | 2442 | break; |
2440 | 2443 | ||
2441 | // decrement filepos by one | 2444 | // decrement filepos by one |
2442 | fseek(f, -1, SEEK_CUR); | 2445 | fseek(f, -1, SEEK_CUR); |
2443 | // read cat-name | 2446 | // read cat-name |
2444 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2447 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2445 | goto formatError; | 2448 | goto formatError; |
2446 | // check cat-name format | 2449 | // check cat-name format |
2447 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2450 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2448 | goto formatError; | 2451 | goto formatError; |
2449 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2452 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2450 | goto formatError; | 2453 | goto formatError; |
2451 | // copy cat-name | 2454 | // copy cat-name |
2452 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2455 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2453 | 2456 | ||
2454 | do { | 2457 | do { |
2455 | // find beginning of next entry | 2458 | // find beginning of next entry |
2456 | do { | 2459 | do { |
2457 | tmp = fgetc(f); | 2460 | tmp = fgetc(f); |
2458 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2461 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2459 | if (tmp == EOF) | 2462 | if (tmp == EOF) |
2460 | break; | 2463 | break; |
2461 | if (tmp == '=') { | 2464 | if (tmp == '=') { |
2462 | fseek(f, -1, SEEK_CUR); | 2465 | fseek(f, -1, SEEK_CUR); |
2463 | break; | 2466 | break; |
2464 | } | 2467 | } |
2465 | // decrement filepos by one | 2468 | // decrement filepos by one |
2466 | fseek(f, -1, SEEK_CUR); | 2469 | fseek(f, -1, SEEK_CUR); |
2467 | // read desc-line | 2470 | // read desc-line |
2468 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2471 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2469 | goto formatError; | 2472 | goto formatError; |
2470 | // check desc-line format | 2473 | // check desc-line format |
2471 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2474 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2472 | goto formatError; | 2475 | goto formatError; |
2473 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2476 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2474 | goto formatError; | 2477 | goto formatError; |
2475 | // add desc-line | 2478 | // add desc-line |
2476 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2479 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2477 | 2480 | ||
2478 | // read username-line | 2481 | // read username-line |
2479 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2482 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2480 | goto formatError; | 2483 | goto formatError; |
2481 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2484 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2482 | goto formatError; | 2485 | goto formatError; |
2483 | 2486 | ||
2484 | // read pw-line | 2487 | // read pw-line |
2485 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2488 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2486 | goto formatError; | 2489 | goto formatError; |
2487 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2490 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2488 | goto formatError; | 2491 | goto formatError; |
2489 | 2492 | ||
2490 | // read comment-line | 2493 | // read comment-line |
2491 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2494 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2492 | goto formatError; | 2495 | goto formatError; |
2493 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2496 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2494 | goto formatError; | 2497 | goto formatError; |
2495 | 2498 | ||
2496 | // read URL-line | 2499 | // read URL-line |
2497 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2500 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2498 | goto formatError; | 2501 | goto formatError; |
2499 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2502 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2500 | goto formatError; | 2503 | goto formatError; |
2501 | 2504 | ||
2502 | // read launcher-line | 2505 | // read launcher-line |
2503 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2506 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2504 | goto formatError; | 2507 | goto formatError; |
2505 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2508 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2506 | goto formatError; | 2509 | goto formatError; |
2507 | 2510 | ||
2508 | currItem.lockStat = true; | 2511 | currItem.lockStat = true; |
2509 | currItem.listViewPos = -1; | 2512 | currItem.listViewPos = -1; |
2510 | addEntry(curCat.c_str(), &currItem, true); | 2513 | addEntry(curCat.c_str(), &currItem, true); |
2511 | ++entriesRead; | 2514 | ++entriesRead; |
2512 | } while (1); | 2515 | } while (1); |
2513 | } while (1); | 2516 | } while (1); |
2514 | if (!entriesRead) | 2517 | if (!entriesRead) |
2515 | goto formatError; | 2518 | goto formatError; |
2516 | 2519 | ||
2517 | free(ch_tmp); | 2520 | free(ch_tmp); |
2518 | fclose(f); | 2521 | fclose(f); |
2519 | flagDirty(); | 2522 | flagDirty(); |
2520 | return e_success; | 2523 | return e_success; |
2521 | 2524 | ||
2522 | formatError: | 2525 | formatError: |
2523 | free(ch_tmp); | 2526 | free(ch_tmp); |
2524 | fclose(f); | 2527 | fclose(f); |
2525 | return e_fileFormat; | 2528 | return e_fileFormat; |
2526 | #else | 2529 | #else |
2527 | PWM_ASSERT(file); | 2530 | PWM_ASSERT(file); |
2528 | QFile f(file->latin1()); | 2531 | QFile f(file->latin1()); |
2529 | int tmp; | 2532 | int tmp; |
2530 | ssize_t ret; | 2533 | ssize_t ret; |
2531 | string curCat; | 2534 | string curCat; |
2532 | unsigned int entriesRead = 0; | 2535 | unsigned int entriesRead = 0; |
2533 | PwMDataItem currItem; | 2536 | PwMDataItem currItem; |
2534 | bool res = f.open(IO_ReadOnly); | 2537 | bool res = f.open(IO_ReadOnly); |
2535 | if (res == false) | 2538 | if (res == false) |
2536 | return e_openFile; | 2539 | return e_openFile; |
2537 | 2540 | ||
2538 | unsigned int ch_tmp_size = 1024; | 2541 | unsigned int ch_tmp_size = 1024; |
2539 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2542 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2540 | if (!ch_tmp) { | 2543 | if (!ch_tmp) { |
2541 | f.close(); | 2544 | f.close(); |
2542 | return e_outOfMem; | 2545 | return e_outOfMem; |
2543 | } | 2546 | } |
2544 | 2547 | ||
2545 | // - check header | 2548 | // - check header |
2546 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. | 2549 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. |
2547 | goto formatError; | 2550 | goto formatError; |
2548 | 2551 | ||
2549 | //US read fileversion first, then check if ok. | 2552 | //US read fileversion first, then check if ok. |
2550 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2553 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2551 | goto formatError; | 2554 | goto formatError; |
2552 | 2555 | ||
2553 | // check version-string and return version in "ch_tmp". | 2556 | // check version-string and return version in "ch_tmp". |
2554 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2557 | //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2555 | //US // header not recognized as PwM generated header | 2558 | //US // header not recognized as PwM generated header |
2556 | //US goto formatError; | 2559 | //US goto formatError; |
2557 | //US} | 2560 | //US} |
2558 | //US set filepointer behind version-string-line previously checked | 2561 | //US set filepointer behind version-string-line previously checked |
2559 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2562 | //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2560 | //US goto formatError; | 2563 | //US goto formatError; |
2561 | // skip next line containing the build-date | 2564 | // skip next line containing the build-date |
2562 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2565 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2563 | goto formatError; | 2566 | goto formatError; |
2564 | // read header termination line | 2567 | // read header termination line |
2565 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2568 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2566 | goto formatError; | 2569 | goto formatError; |
2567 | if (strcmp(ch_tmp, "==============================\n")) | 2570 | if (strcmp(ch_tmp, "==============================\n")) |
2568 | goto formatError; | 2571 | goto formatError; |
2569 | 2572 | ||
2570 | // - read entries | 2573 | // - read entries |
2571 | do { | 2574 | do { |
2572 | // find beginning of next category | 2575 | // find beginning of next category |
2573 | do { | 2576 | do { |
2574 | tmp = f.getch(); | 2577 | tmp = f.getch(); |
2575 | } while (tmp == '\n' && tmp != EOF); | 2578 | } while (tmp == '\n' && tmp != EOF); |
2576 | if (tmp == EOF) | 2579 | if (tmp == EOF) |
2577 | break; | 2580 | break; |
2578 | 2581 | ||
2579 | // decrement filepos by one | 2582 | // decrement filepos by one |
2580 | f.at(f.at()-1); | 2583 | f.at(f.at()-1); |
2581 | // read cat-name | 2584 | // read cat-name |
2582 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2585 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2583 | goto formatError; | 2586 | goto formatError; |
2584 | // check cat-name format | 2587 | // check cat-name format |
2585 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2588 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2586 | goto formatError; | 2589 | goto formatError; |
2587 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2590 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2588 | goto formatError; | 2591 | goto formatError; |
2589 | // copy cat-name | 2592 | // copy cat-name |
2590 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2593 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2591 | 2594 | ||
2592 | do { | 2595 | do { |
2593 | // find beginning of next entry | 2596 | // find beginning of next entry |
2594 | do { | 2597 | do { |
2595 | tmp = f.getch(); | 2598 | tmp = f.getch(); |
2596 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2599 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2597 | if (tmp == EOF) | 2600 | if (tmp == EOF) |
2598 | break; | 2601 | break; |
2599 | if (tmp == '=') { | 2602 | if (tmp == '=') { |
2600 | f.at(f.at()-1); | 2603 | f.at(f.at()-1); |
2601 | break; | 2604 | break; |
2602 | } | 2605 | } |
2603 | // decrement filepos by one | 2606 | // decrement filepos by one |
2604 | f.at(f.at()-1); | 2607 | f.at(f.at()-1); |
2605 | // read desc-line | 2608 | // read desc-line |
2606 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) | 2609 | if (f.readLine(ch_tmp, ch_tmp_size) == -1) |
2607 | goto formatError; | 2610 | goto formatError; |
2608 | // check desc-line format | 2611 | // check desc-line format |
2609 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2612 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2610 | goto formatError; | 2613 | goto formatError; |
2611 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2614 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2612 | goto formatError; | 2615 | goto formatError; |
2613 | // add desc-line | 2616 | // add desc-line |
2614 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2617 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2615 | 2618 | ||
2616 | // read username-line | 2619 | // read username-line |
2617 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2620 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2618 | goto formatError; | 2621 | goto formatError; |
2619 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2622 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2620 | goto formatError; | 2623 | goto formatError; |
2621 | 2624 | ||
2622 | // read pw-line | 2625 | // read pw-line |
2623 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2626 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2624 | goto formatError; | 2627 | goto formatError; |
2625 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2628 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2626 | goto formatError; | 2629 | goto formatError; |
2627 | 2630 | ||
2628 | // read comment-line | 2631 | // read comment-line |
2629 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2632 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2630 | goto formatError; | 2633 | goto formatError; |
2631 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2634 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2632 | goto formatError; | 2635 | goto formatError; |
2633 | 2636 | ||
2634 | // read URL-line | 2637 | // read URL-line |
2635 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2638 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2636 | goto formatError; | 2639 | goto formatError; |
2637 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2640 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2638 | goto formatError; | 2641 | goto formatError; |
2639 | 2642 | ||
2640 | // read launcher-line | 2643 | // read launcher-line |
2641 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) | 2644 | if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) |
2642 | goto formatError; | 2645 | goto formatError; |
2643 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2646 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2644 | goto formatError; | 2647 | goto formatError; |
2645 | 2648 | ||
2646 | currItem.lockStat = true; | 2649 | currItem.lockStat = true; |
2647 | currItem.listViewPos = -1; | 2650 | currItem.listViewPos = -1; |
2648 | addEntry(curCat.c_str(), &currItem, true); | 2651 | addEntry(curCat.c_str(), &currItem, true); |
2649 | ++entriesRead; | 2652 | ++entriesRead; |
2650 | } while (1); | 2653 | } while (1); |
2651 | } while (1); | 2654 | } while (1); |
2652 | if (!entriesRead) | 2655 | if (!entriesRead) |
2653 | goto formatError; | 2656 | goto formatError; |
2654 | 2657 | ||
2655 | free(ch_tmp); | 2658 | free(ch_tmp); |
2656 | f.close(); | 2659 | f.close(); |
2657 | flagDirty(); | 2660 | flagDirty(); |
2658 | return e_success; | 2661 | return e_success; |
2659 | 2662 | ||
2660 | formatError: | 2663 | formatError: |
2661 | free(ch_tmp); | 2664 | free(ch_tmp); |
2662 | f.close(); | 2665 | f.close(); |
2663 | return e_fileFormat; | 2666 | return e_fileFormat; |
2664 | 2667 | ||
2665 | #endif | 2668 | #endif |
2666 | 2669 | ||
2667 | } | 2670 | } |
2668 | 2671 | ||
2669 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2672 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2670 | { | 2673 | { |
2671 | PWM_ASSERT(in && out); | 2674 | PWM_ASSERT(in && out); |
2672 | ssize_t i = 0, len = in_size - 1; | 2675 | ssize_t i = 0, len = in_size - 1; |
2673 | while (i < len) { | 2676 | while (i < len) { |
2674 | if (in[i] == ':') | 2677 | if (in[i] == ':') |
2675 | break; | 2678 | break; |
2676 | ++i; | 2679 | ++i; |
2677 | } | 2680 | } |
2678 | i += 2; | 2681 | i += 2; |
2679 | *out = ""; | 2682 | *out = ""; |
2680 | out->append(in + i, in_size - i - 1); | 2683 | out->append(in + i, in_size - i - 1); |
2681 | return true; | 2684 | return true; |
2682 | } | 2685 | } |
2683 | 2686 | ||
2684 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2687 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2685 | { | 2688 | { |
2686 | PWM_ASSERT(file); | 2689 | PWM_ASSERT(file); |
2687 | GpasmanFile gp; | 2690 | GpasmanFile gp; |
2688 | int ret; | 2691 | int ret; |
2689 | 2692 | ||
2690 | if (!unlockAll_tempoary()) | 2693 | if (!unlockAll_tempoary()) |
2691 | return e_lock; | 2694 | return e_lock; |
2692 | 2695 | ||
2693 | QString gpmPassword; | 2696 | QString gpmPassword; |
2694 | while (1) { | 2697 | while (1) { |
2695 | gpmPassword = requestNewMpw(0); | 2698 | gpmPassword = requestNewMpw(0); |
2696 | if (gpmPassword == "") { | 2699 | if (gpmPassword == "") { |
2697 | unlockAll_tempoary(true); | 2700 | unlockAll_tempoary(true); |
2698 | return e_noPw; | 2701 | return e_noPw; |
2699 | } | 2702 | } |
2700 | if (gpmPassword.length() < 4) { | 2703 | if (gpmPassword.length() < 4) { |
2701 | gpmPwLenErrMsgBox(); | 2704 | gpmPwLenErrMsgBox(); |
2702 | } else { | 2705 | } else { |
2703 | break; | 2706 | break; |
2704 | } | 2707 | } |
2705 | } | 2708 | } |
2706 | 2709 | ||
2707 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2710 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2708 | if (ret != 1) { | 2711 | if (ret != 1) { |
2709 | unlockAll_tempoary(true); | 2712 | unlockAll_tempoary(true); |
2710 | return e_accessFile; | 2713 | return e_accessFile; |
2711 | } | 2714 | } |
2712 | 2715 | ||
2713 | char *entry[4]; | 2716 | char *entry[4]; |
2714 | unsigned int numCat = numCategories(), i; | 2717 | unsigned int numCat = numCategories(), i; |
2715 | unsigned int numEntr, j; | 2718 | unsigned int numEntr, j; |
2716 | int descLen, nameLen, pwLen, commentLen; | 2719 | int descLen, nameLen, pwLen, commentLen; |
2717 | for (i = 0; i < numCat; ++i) { | 2720 | for (i = 0; i < numCat; ++i) { |
2718 | numEntr = numEntries(i); | 2721 | numEntr = numEntries(i); |
2719 | for (j = 0; j < numEntr; ++j) { | 2722 | for (j = 0; j < numEntr; ++j) { |
2720 | descLen = dti.dta[i].d[j].desc.length(); | 2723 | descLen = dti.dta[i].d[j].desc.length(); |
2721 | nameLen = dti.dta[i].d[j].name.length(); | 2724 | nameLen = dti.dta[i].d[j].name.length(); |
2722 | pwLen = dti.dta[i].d[j].pw.length(); | 2725 | pwLen = dti.dta[i].d[j].pw.length(); |
2723 | commentLen = dti.dta[i].d[j].comment.length(); | 2726 | commentLen = dti.dta[i].d[j].comment.length(); |
2724 | entry[0] = new char[descLen + 1]; | 2727 | entry[0] = new char[descLen + 1]; |
2725 | entry[1] = new char[nameLen + 1]; | 2728 | entry[1] = new char[nameLen + 1]; |
2726 | entry[2] = new char[pwLen + 1]; | 2729 | entry[2] = new char[pwLen + 1]; |
2727 | entry[3] = new char[commentLen + 1]; | 2730 | entry[3] = new char[commentLen + 1]; |
2728 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); | 2731 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2729 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); | 2732 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2730 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); | 2733 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2731 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); | 2734 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2732 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2735 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2733 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2736 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2734 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2737 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2735 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2738 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2736 | 2739 | ||
2737 | ret = gp.save_entry(entry); | 2740 | ret = gp.save_entry(entry); |
2738 | if (ret == -1){ | 2741 | if (ret == -1){ |
2739 | delete [] entry[0]; | 2742 | delete [] entry[0]; |
2740 | delete [] entry[1]; | 2743 | delete [] entry[1]; |
2741 | delete [] entry[2]; | 2744 | delete [] entry[2]; |
2742 | delete [] entry[3]; | 2745 | delete [] entry[3]; |
2743 | gp.save_finalize(); | 2746 | gp.save_finalize(); |
2744 | unlockAll_tempoary(true); | 2747 | unlockAll_tempoary(true); |
2745 | return e_writeFile; | 2748 | return e_writeFile; |
2746 | } | 2749 | } |
2747 | 2750 | ||
2748 | delete [] entry[0]; | 2751 | delete [] entry[0]; |
2749 | delete [] entry[1]; | 2752 | delete [] entry[1]; |
2750 | delete [] entry[2]; | 2753 | delete [] entry[2]; |
2751 | delete [] entry[3]; | 2754 | delete [] entry[3]; |
2752 | } | 2755 | } |
2753 | } | 2756 | } |
2754 | unlockAll_tempoary(true); | 2757 | unlockAll_tempoary(true); |
2755 | if (gp.save_finalize() == -1) | 2758 | if (gp.save_finalize() == -1) |
2756 | return e_writeFile; | 2759 | return e_writeFile; |
2757 | 2760 | ||
2758 | return e_success; | 2761 | return e_success; |
2759 | } | 2762 | } |
2760 | 2763 | ||
2761 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2764 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2762 | { | 2765 | { |
2763 | PWM_ASSERT(file); | 2766 | PWM_ASSERT(file); |
2764 | QString pw = requestMpw(false); | 2767 | QString pw = requestMpw(false); |
2765 | if (pw == "") | 2768 | if (pw == "") |
2766 | return e_noPw; | 2769 | return e_noPw; |
2767 | GpasmanFile gp; | 2770 | GpasmanFile gp; |
2768 | int ret, i; | 2771 | int ret, i; |
2769 | PwMerror ret2; | 2772 | PwMerror ret2; |
2770 | char *entry[4]; | 2773 | char *entry[4]; |
2771 | PwMDataItem tmpData; | 2774 | PwMDataItem tmpData; |
2772 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2775 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2773 | if (ret != 1) | 2776 | if (ret != 1) |
2774 | return e_accessFile; | 2777 | return e_accessFile; |
2775 | 2778 | ||
2776 | do { | 2779 | do { |
2777 | ret = gp.load_entry(entry); | 2780 | ret = gp.load_entry(entry); |
2778 | if(ret != 1) | 2781 | if(ret != 1) |
2779 | break; | 2782 | break; |
2780 | tmpData.desc = entry[0]; | 2783 | tmpData.desc = entry[0]; |
2781 | tmpData.name = entry[1]; | 2784 | tmpData.name = entry[1]; |
2782 | tmpData.pw = entry[2]; | 2785 | tmpData.pw = entry[2]; |
2783 | tmpData.comment = entry[3]; | 2786 | tmpData.comment = entry[3]; |
2784 | tmpData.lockStat = true; | 2787 | tmpData.lockStat = true; |
2785 | tmpData.listViewPos = -1; | 2788 | tmpData.listViewPos = -1; |
2786 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2789 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2787 | for (i = 0; i < 4; ++i) | 2790 | for (i = 0; i < 4; ++i) |
2788 | free(entry[i]); | 2791 | free(entry[i]); |
2789 | if (ret2 == e_maxAllowedEntr) { | 2792 | if (ret2 == e_maxAllowedEntr) { |
2790 | gp.load_finalize(); | 2793 | gp.load_finalize(); |
2791 | return e_maxAllowedEntr; | 2794 | return e_maxAllowedEntr; |
2792 | } | 2795 | } |
2793 | } while (1); | 2796 | } while (1); |
2794 | gp.load_finalize(); | 2797 | gp.load_finalize(); |
2795 | if (isDocEmpty()) | 2798 | if (isDocEmpty()) |
2796 | return e_wrongPw; // we assume this. | 2799 | return e_wrongPw; // we assume this. |
2797 | 2800 | ||
2798 | flagDirty(); | 2801 | flagDirty(); |
2799 | return e_success; | 2802 | return e_success; |
2800 | } | 2803 | } |
2801 | 2804 | ||
2802 | void PwMDoc::ensureLvp() | 2805 | void PwMDoc::ensureLvp() |
2803 | { | 2806 | { |
2804 | if (isDocEmpty()) | 2807 | if (isDocEmpty()) |
2805 | return; | 2808 | return; |
2806 | 2809 | ||
2810 | //US ENH BUG: when using syncronizing, this way of sorting | ||
2811 | //is not sufficient, because there might be empty spaces | ||
2812 | // at the beginning. But this algorythm only can add elements | ||
2813 | //to the end.The result are crashes because of listoverflows | ||
2814 | //we need something to fill all gaps. | ||
2807 | vector< vector<PwMDataItem>::iterator > undefined; | 2815 | vector< vector<PwMDataItem>::iterator > undefined; |
2816 | vector< vector<PwMDataItem>::iterator > sorted; | ||
2808 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2817 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, |
2809 | undefEnd, | 2818 | undefEnd, |
2810 | undefI; | 2819 | undefI; |
2820 | vector< vector<PwMDataItem>::iterator >::iterator sortedBegin, | ||
2821 | sortedEnd, | ||
2822 | sortedI; | ||
2811 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2823 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2812 | catEnd = dti.dta.end(), | 2824 | catEnd = dti.dta.end(), |
2813 | catI = catBegin; | 2825 | catI = catBegin; |
2814 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2826 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2815 | int lvpTop, tmpLvp; | 2827 | int lvpTop, tmpLvp; |
2816 | 2828 | ||
2817 | while (catI != catEnd) { | 2829 | while (catI != catEnd) { |
2818 | lvpTop = -1; | 2830 | lvpTop = -1; |
2819 | undefined.clear(); | 2831 | undefined.clear(); |
2820 | 2832 | ||
2821 | entrBegin = catI->d.begin(); | 2833 | entrBegin = catI->d.begin(); |
2822 | entrEnd = catI->d.end(); | 2834 | entrEnd = catI->d.end(); |
2823 | entrI = entrBegin; | 2835 | entrI = entrBegin; |
2824 | 2836 | ||
2825 | while (entrI != entrEnd) { | 2837 | while (entrI != entrEnd) { |
2826 | tmpLvp = entrI->listViewPos; | 2838 | tmpLvp = entrI->listViewPos; |
2827 | if (tmpLvp == -1) | 2839 | if (tmpLvp == -1) |
2828 | undefined.push_back(entrI); | 2840 | undefined.push_back(entrI); |
2829 | else if (tmpLvp > lvpTop) | 2841 | else |
2830 | lvpTop = tmpLvp; | 2842 | sorted[tmpLvp] = entrI; |
2843 | //US else if (tmpLvp > lvpTop) | ||
2844 | //US lvpTop = tmpLvp; | ||
2831 | ++entrI; | 2845 | ++entrI; |
2832 | } | 2846 | } |
2847 | |||
2848 | //now we have all undefied in the collection. Now insert the existing | ||
2849 | sortedBegin = sorted.begin(); | ||
2850 | sortedEnd = sorted.end(); | ||
2851 | sortedI = sortedBegin; | ||
2852 | |||
2853 | while (sortedI != sortedEnd) { | ||
2854 | tmpLvp = (*sortedI)->listViewPos; | ||
2855 | undefined[tmpLvp] = *sortedI; | ||
2856 | ++sortedI; | ||
2857 | } | ||
2858 | |||
2833 | undefBegin = undefined.begin(); | 2859 | undefBegin = undefined.begin(); |
2834 | undefEnd = undefined.end(); | 2860 | undefEnd = undefined.end(); |
2835 | undefI = undefBegin; | 2861 | undefI = undefBegin; |
2836 | while (undefI != undefEnd) { | 2862 | while (undefI != undefEnd) { |
2837 | (*undefI)->listViewPos = ++lvpTop; | 2863 | (*undefI)->listViewPos = ++lvpTop; |
2838 | ++undefI; | 2864 | ++undefI; |
2839 | } | 2865 | } |
2840 | ++catI; | 2866 | ++catI; |
2841 | } | 2867 | } |
2842 | } | 2868 | } |
2843 | 2869 | ||
2844 | QString PwMDoc::getTitle() | 2870 | QString PwMDoc::getTitle() |
2845 | { | 2871 | { |
2846 | /* NOTE: We have to ensure, that the returned title | 2872 | /* NOTE: We have to ensure, that the returned title |
2847 | * is unique and not reused somewhere else while | 2873 | * is unique and not reused somewhere else while |
2848 | * this document is valid (open). | 2874 | * this document is valid (open). |
2849 | */ | 2875 | */ |
2850 | QString title(getFilename()); | 2876 | QString title(getFilename()); |
2877 | |||
2878 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | ||
2879 | if (QApplication::desktop()->width() < 640) | ||
2880 | { | ||
2881 | if (title.length() > 30) | ||
2882 | title = "..." + title.right(30); | ||
2883 | |||
2884 | } | ||
2885 | |||
2886 | |||
2851 | if (title.isEmpty()) { | 2887 | if (title.isEmpty()) { |
2852 | if (unnamedNum == 0) { | 2888 | if (unnamedNum == 0) { |
2853 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2889 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2854 | PWM_ASSERT(unnamedNum != 0); | 2890 | PWM_ASSERT(unnamedNum != 0); |
2855 | } | 2891 | } |
2856 | title = DEFAULT_TITLE; | 2892 | title = DEFAULT_TITLE; |
2857 | title += " "; | 2893 | title += " "; |
2858 | title += tostr(unnamedNum).c_str(); | 2894 | title += tostr(unnamedNum).c_str(); |
2859 | } | 2895 | } |
2860 | return title; | 2896 | return title; |
2861 | } | 2897 | } |
2862 | 2898 | ||
2863 | bool PwMDoc::tryDelete() | 2899 | bool PwMDoc::tryDelete() |
2864 | { | 2900 | { |
2865 | if (deleted) | 2901 | if (deleted) |
2866 | return true; | 2902 | return true; |
2867 | int ret; | 2903 | int ret; |
2868 | if (isDirty()) { | 2904 | if (isDirty()) { |
2869 | ret = dirtyAskSave(getTitle()); | 2905 | ret = dirtyAskSave(getTitle()); |
2870 | if (ret == 0) { // save to disk | 2906 | if (ret == 0) { // save to disk |
2871 | if (!saveDocUi(this)) | 2907 | if (!saveDocUi(this)) |
2872 | goto out_ignore; | 2908 | goto out_ignore; |
2873 | } else if (ret == 1) { // don't save and delete | 2909 | } else if (ret == 1) { // don't save and delete |
2874 | goto out_accept; | 2910 | goto out_accept; |
2875 | } else { // cancel operation | 2911 | } else { // cancel operation |
2876 | goto out_ignore; | 2912 | goto out_ignore; |
2877 | } | 2913 | } |
2878 | } | 2914 | } |
2879 | out_accept: | 2915 | out_accept: |
2880 | deleted = true; | 2916 | deleted = true; |
2881 | delete this; | 2917 | delete this; |
2882 | return true; | 2918 | return true; |
2883 | out_ignore: | 2919 | out_ignore: |
2884 | return false; | 2920 | return false; |
2885 | } | 2921 | } |
2886 | 2922 | ||
2887 | 2923 | ||
2888 | 2924 | ||
2889 | #ifdef PWM_EMBEDDED | 2925 | #ifdef PWM_EMBEDDED |
2890 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2926 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2891 | //US it could have been defined as static, but I did not want to. | 2927 | //US it could have been defined as static, but I did not want to. |
2892 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2928 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2893 | { | 2929 | { |
2894 | int addedPasswordsLocal = 0; | 2930 | int addedPasswordsLocal = 0; |
2895 | int addedPasswordsRemote = 0; | 2931 | int addedPasswordsRemote = 0; |
2896 | int deletedPasswordsRemote = 0; | 2932 | int deletedPasswordsRemote = 0; |
2897 | int deletedPasswordsLocal = 0; | 2933 | int deletedPasswordsLocal = 0; |
2898 | int changedLocal = 0; | 2934 | int changedLocal = 0; |
2899 | int changedRemote = 0; | 2935 | int changedRemote = 0; |
2900 | 2936 | ||
2901 | PwMSyncItem* syncItemLocal; | 2937 | PwMSyncItem* syncItemLocal; |
2902 | PwMSyncItem* syncItemRemote; | 2938 | PwMSyncItem* syncItemRemote; |
2903 | 2939 | ||
2904 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2940 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2905 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2941 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2906 | 2942 | ||
2907 | bool fullDateRange = false; | 2943 | bool fullDateRange = false; |
2908 | int take; | 2944 | int take; |
2909 | // local->resetTempSyncStat(); | 2945 | // local->resetTempSyncStat(); |
2910 | QDateTime mLastSync = QDateTime::currentDateTime(); | 2946 | QDateTime mLastSync = QDateTime::currentDateTime(); |
2911 | QDateTime modifiedSync = mLastSync; | 2947 | QDateTime modifiedSync = mLastSync; |
2912 | 2948 | ||
2913 | unsigned int index; | 2949 | unsigned int index; |
2914 | //Step 1. Find syncinfo in Local file and create if not existent. | 2950 | //Step 1. Find syncinfo in Local file and create if not existent. |
2915 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2951 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2916 | if (found == false) | 2952 | if (found == false) |
2917 | { | 2953 | { |
2918 | PwMSyncItem newSyncItemLocal; | 2954 | PwMSyncItem newSyncItemLocal; |
2919 | newSyncItemLocal.syncName = mCurrentSyncDevice; | 2955 | newSyncItemLocal.syncName = mCurrentSyncDevice; |
2920 | newSyncItemLocal.lastSyncDate = mLastSync; | 2956 | newSyncItemLocal.lastSyncDate = mLastSync; |
2921 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 2957 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
2922 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2958 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2923 | if (found == false) { | 2959 | if (found == false) { |
2924 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 2960 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
2925 | return e_syncError; | 2961 | return e_syncError; |
2926 | } | 2962 | } |
2927 | } | 2963 | } |
2928 | 2964 | ||
2929 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 2965 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
2930 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 2966 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); |
2931 | 2967 | ||
2932 | //Step 2. Find syncinfo in remote file and create if not existent. | 2968 | //Step 2. Find syncinfo in remote file and create if not existent. |
2933 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2969 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2934 | if (found == false) | 2970 | if (found == false) |
2935 | { | 2971 | { |
2936 | qDebug("FULLDATE 1"); | 2972 | qDebug("FULLDATE 1"); |
2937 | fullDateRange = true; | 2973 | fullDateRange = true; |
2938 | PwMSyncItem newSyncItemRemote; | 2974 | PwMSyncItem newSyncItemRemote; |
2939 | newSyncItemRemote.syncName = mCurrentSyncName; | 2975 | newSyncItemRemote.syncName = mCurrentSyncName; |
2940 | newSyncItemRemote.lastSyncDate = mLastSync; | 2976 | newSyncItemRemote.lastSyncDate = mLastSync; |
2941 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 2977 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
2942 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2978 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2943 | if (found == false) { | 2979 | if (found == false) { |
2944 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 2980 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
2945 | return e_syncError; | 2981 | return e_syncError; |
2946 | } | 2982 | } |
2947 | } | 2983 | } |
2948 | 2984 | ||
2949 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 2985 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
2986 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | ||
2950 | //and remove the found entry here. We will reenter it later again. | 2987 | //and remove the found entry here. We will reenter it later again. |
2951 | //US syncRemote->delSyncDataEntry(index, true); | 2988 | //US syncRemote->delSyncDataEntry(index, true); |
2952 | 2989 | ||
2953 | 2990 | ||
2954 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 2991 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
2955 | qDebug("FULLDATE 2"); | 2992 | qDebug("FULLDATE 2"); |
2956 | fullDateRange = true; | 2993 | fullDateRange = true; |
2957 | } | 2994 | } |
2958 | 2995 | ||
2959 | if ( ! fullDateRange ) { | 2996 | if ( ! fullDateRange ) { |
2960 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 2997 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
2961 | 2998 | ||
2962 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2999 | // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() ); |
2963 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 3000 | // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2964 | fullDateRange = true; | 3001 | fullDateRange = true; |
2965 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3002 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
2966 | } | 3003 | } |
2967 | } | 3004 | } |
2968 | // fullDateRange = true; // debug only! | 3005 | // fullDateRange = true; // debug only! |
2969 | if ( fullDateRange ) | 3006 | if ( fullDateRange ) |
2970 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3007 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
2971 | else | 3008 | else |
2972 | mLastSync = syncItemLocal->lastSyncDate; | 3009 | mLastSync = syncItemLocal->lastSyncDate; |
2973 | 3010 | ||
2974 | 3011 | ||
2975 | qDebug("*************************** "); | 3012 | qDebug("*************************** "); |
2976 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 3013 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
2977 | QStringList er = syncRemote->getIDEntryList(); | 3014 | QStringList er = syncRemote->getIDEntryList(); |
2978 | PwMDataItem* inRemote ;//= er.first(); | 3015 | PwMDataItem* inRemote ;//= er.first(); |
2979 | PwMDataItem* inLocal; | 3016 | PwMDataItem* inLocal; |
2980 | unsigned int catLocal, indexLocal; | 3017 | unsigned int catLocal, indexLocal; |
2981 | unsigned int catRemote, indexRemote; | 3018 | unsigned int catRemote, indexRemote; |
2982 | 3019 | ||
2983 | QString uid; | 3020 | QString uid; |
2984 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 3021 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2985 | 3022 | ||
2986 | int modulo = (er.count()/10)+1; | 3023 | int modulo = (er.count()/10)+1; |
2987 | unsigned int incCounter = 0; | 3024 | unsigned int incCounter = 0; |
2988 | while ( incCounter < er.count()) { | 3025 | while ( incCounter < er.count()) { |
2989 | if (manager->isProgressBarCanceled()) | 3026 | if (manager->isProgressBarCanceled()) |
2990 | return e_syncError; | 3027 | return e_syncError; |
2991 | if ( incCounter % modulo == 0 ) | 3028 | if ( incCounter % modulo == 0 ) |
2992 | manager->showProgressBar(incCounter); | 3029 | manager->showProgressBar(incCounter); |
2993 | 3030 | ||
2994 | uid = er[ incCounter ]; | 3031 | uid = er[ incCounter ]; |
2995 | qDebug("sync uid %s from remote file", uid.latin1()); | 3032 | qDebug("sync uid %s from remote file", uid.latin1()); |
2996 | 3033 | ||
2997 | qApp->processEvents(); | 3034 | qApp->processEvents(); |
2998 | 3035 | ||
2999 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3036 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3000 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3037 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3001 | PWM_ASSERT(inRemote); | 3038 | PWM_ASSERT(inRemote); |
3002 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3039 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3003 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3040 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3004 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 3041 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3005 | if ( take == 3 ) | 3042 | if ( take == 3 ) |
3006 | return e_syncError; | 3043 | return e_syncError; |
3007 | if ( take == 1 ) {// take local | 3044 | if ( take == 1 ) {// take local |
3008 | //US syncRemote->removeAddressee( inRemote ); | 3045 | //US syncRemote->removeAddressee( inRemote ); |
3009 | (*inRemote) = (*inLocal); | 3046 | (*inRemote) = (*inLocal); |
3010 | //US syncRemote->insertAddressee( inRemote , false); | 3047 | //US syncRemote->insertAddressee( inRemote , false); |
3011 | ++changedRemote; | 3048 | ++changedRemote; |
3012 | } else { // take == 2 take remote | 3049 | } else { // take == 2 take remote |
3013 | //US syncLocal->removeAddressee( inLocal ); | 3050 | //US syncLocal->removeAddressee( inLocal ); |
3014 | (*inLocal) = (*inRemote); | 3051 | (*inLocal) = (*inRemote); |
3015 | //US syncLocal->insertAddressee( inLocal , false ); | 3052 | //US syncLocal->insertAddressee( inLocal , false ); |
3016 | ++changedLocal; | 3053 | ++changedLocal; |
3017 | } | 3054 | } |
3018 | } | 3055 | } |
3019 | } else { // no conflict | 3056 | } else { // no conflict |
3020 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 3057 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
3021 | inRemote->meta.update = modifiedSync; | 3058 | inRemote->meta.update = modifiedSync; |
3022 | 3059 | ||
3023 | //first check if we have a matching category in the local file | 3060 | //first check if we have a matching category in the local file |
3024 | const string* remotecat = syncRemote->getCategory(catRemote); | 3061 | const string* remotecat = syncRemote->getCategory(catRemote); |
3025 | //US syncRemote->insertAddressee( inRemote, false ); | 3062 | //US syncRemote->insertAddressee( inRemote, false ); |
3026 | //US syncLocal->insertAddressee( inRemote, false ); | 3063 | //US syncLocal->insertAddressee( inRemote, false ); |
3027 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); | 3064 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
3028 | 3065 | ||
3029 | ++addedPasswordsLocal; | 3066 | ++addedPasswordsLocal; |
3030 | } else { | 3067 | } else { |
3031 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 3068 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
3032 | syncRemote->delEntry(catRemote, indexRemote, true); | 3069 | syncRemote->delEntry(catRemote, indexRemote, true); |
3033 | //USsyncRemote->removeAddressee( inRemote ); | 3070 | //USsyncRemote->removeAddressee( inRemote ); |
3034 | ++deletedPasswordsRemote; | 3071 | ++deletedPasswordsRemote; |
3035 | } | 3072 | } |
3036 | } | 3073 | } |
3037 | 3074 | ||
3038 | ++incCounter; | 3075 | ++incCounter; |
3039 | } | 3076 | } |
3040 | 3077 | ||
3041 | 3078 | ||
3042 | er.clear(); | 3079 | er.clear(); |
3043 | QStringList el = syncLocal->getIDEntryList(); | 3080 | QStringList el = syncLocal->getIDEntryList(); |
3044 | modulo = (el.count()/10)+1; | 3081 | modulo = (el.count()/10)+1; |
3045 | 3082 | ||
3046 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 3083 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
3047 | incCounter = 0; | 3084 | incCounter = 0; |
3048 | while ( incCounter < el.count()) { | 3085 | while ( incCounter < el.count()) { |
3049 | qApp->processEvents(); | 3086 | qApp->processEvents(); |
3050 | if (manager->isProgressBarCanceled()) | 3087 | if (manager->isProgressBarCanceled()) |
3051 | return e_syncError; | 3088 | return e_syncError; |
3052 | if ( incCounter % modulo == 0 ) | 3089 | if ( incCounter % modulo == 0 ) |
3053 | manager->showProgressBar(incCounter); | 3090 | manager->showProgressBar(incCounter); |
3054 | uid = el[ incCounter ]; | 3091 | uid = el[ incCounter ]; |
3092 | qDebug("sync uid %s from local file", uid.latin1()); | ||
3055 | 3093 | ||
3056 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3094 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3057 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3095 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3058 | PWM_ASSERT(inLocal); | 3096 | PWM_ASSERT(inLocal); |
3059 | 3097 | ||
3060 | if ( inRemote == 0 ) { | 3098 | if ( inRemote == 0 ) { |
3061 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 3099 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
3062 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 3100 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
3063 | syncLocal->delEntry(catLocal, indexLocal, true); | 3101 | syncLocal->delEntry(catLocal, indexLocal, true); |
3064 | //USsyncLocal->removeAddressee( inLocal ); | 3102 | //USsyncLocal->removeAddressee( inLocal ); |
3065 | ++deletedPasswordsLocal; | 3103 | ++deletedPasswordsLocal; |
3066 | } else { | 3104 | } else { |
3067 | if ( ! manager->mWriteBackExistingOnly ) { | 3105 | if ( ! manager->mWriteBackExistingOnly ) { |
3068 | ++addedPasswordsRemote; | 3106 | ++addedPasswordsRemote; |
3069 | inLocal->meta.update = modifiedSync; | 3107 | inLocal->meta.update = modifiedSync; |
3070 | 3108 | ||
3071 | //first check if we have a matching category in the remote file | 3109 | //first check if we have a matching category in the remote file |
3072 | const string* localcat = syncLocal->getCategory(catLocal); | 3110 | const string* localcat = syncLocal->getCategory(catLocal); |
3073 | 3111 | ||
3074 | //USsyncLocal->insertAddressee( inLocal, false ); | 3112 | //USsyncLocal->insertAddressee( inLocal, false ); |
3075 | PwMDataItem newEntry; | 3113 | PwMDataItem newEntry; |
3076 | newEntry = *inLocal; | 3114 | newEntry = *inLocal; |
3077 | inRemote = &newEntry; | 3115 | inRemote = &newEntry; |
3078 | 3116 | ||
3079 | //USsyncRemote->insertAddressee( inRemote, false ); | 3117 | //USsyncRemote->insertAddressee( inRemote, false ); |
3080 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); | 3118 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
3081 | 3119 | ||
3082 | } | 3120 | } |
3083 | } | 3121 | } |
3084 | 3122 | ||
3085 | } | 3123 | } |
3086 | ++incCounter; | 3124 | ++incCounter; |
3087 | } | 3125 | } |
3088 | el.clear(); | 3126 | el.clear(); |
3089 | manager->hideProgressBar(); | 3127 | manager->hideProgressBar(); |
3090 | 3128 | ||
3091 | // Now write the info back into the sync data space of the files | 3129 | // Now write the info back into the sync data space of the files |
3092 | 3130 | ||
3093 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 3131 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
3094 | // get rid of micro seconds | 3132 | // get rid of micro seconds |
3095 | QTime t = mLastSync.time(); | 3133 | QTime t = mLastSync.time(); |
3096 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 3134 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
3097 | 3135 | ||
3098 | 3136 | ||
3099 | syncItemLocal->lastSyncDate = mLastSync; | 3137 | syncItemLocal->lastSyncDate = mLastSync; |
3100 | syncItemRemote->lastSyncDate = mLastSync; | 3138 | syncItemRemote->lastSyncDate = mLastSync; |
3101 | 3139 | ||
3102 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 3140 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
3103 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 3141 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
3104 | 3142 | ||
3105 | //US syncRemote->addSyncDataEntry( syncItemRemote, false ); | 3143 | //US syncRemote->addSyncDataEntry( syncItemRemote, false ); |
3106 | //US syncLocal->addSyncDataEntry( syncItemLocal, false ); | 3144 | //US syncLocal->addSyncDataEntry( syncItemLocal, false ); |
3107 | QString mes; | 3145 | QString mes; |
3108 | 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 ); | 3146 | 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 ); |
3109 | if ( manager->mShowSyncSummary ) { | 3147 | if ( manager->mShowSyncSummary ) { |
3110 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3148 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3111 | } | 3149 | } |
3112 | qDebug( mes ); | 3150 | qDebug( mes ); |
3113 | return e_success; | 3151 | return e_success; |
3114 | } | 3152 | } |
3115 | 3153 | ||
3116 | 3154 | ||
3117 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3155 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3118 | { | 3156 | { |
3119 | // 0 equal | 3157 | // 0 equal |
3120 | // 1 take local | 3158 | // 1 take local |
3121 | // 2 take remote | 3159 | // 2 take remote |
3122 | // 3 cancel | 3160 | // 3 cancel |
3123 | QDateTime localMod = local->meta.update; | 3161 | QDateTime localMod = local->meta.update; |
3124 | QDateTime remoteMod = remote->meta.update; | 3162 | QDateTime remoteMod = remote->meta.update; |
3125 | 3163 | ||
3126 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 3164 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
3127 | 3165 | ||
3128 | if ( localMod == remoteMod ) | 3166 | if ( localMod == remoteMod ) |
3129 | return 0; | 3167 | return 0; |
3130 | 3168 | ||
3131 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3169 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3132 | 3170 | ||
3133 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3171 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3134 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3172 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3135 | //full = true; //debug only | 3173 | full = true; //debug only |
3136 | if ( full ) { | 3174 | if ( full ) { |
3137 | bool equ = true;//US ( (*local) == (*remote) ); | 3175 | bool equ = ( (*local) == (*remote) ); |
3138 | if ( equ ) { | 3176 | if ( equ ) { |
3139 | //qDebug("equal "); | 3177 | qDebug("equal "); |
3140 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3178 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3141 | return 0; | 3179 | return 0; |
3142 | 3180 | ||
3143 | }//else //debug only | 3181 | }else //debug only |
3144 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 3182 | qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3145 | } | 3183 | } |
3146 | 3184 | ||
3147 | int result; | 3185 | int result; |
3148 | bool localIsNew; | 3186 | bool localIsNew; |
3149 | //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() ); | 3187 | //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() ); |
3150 | 3188 | ||
3151 | if ( full && mode < SYNC_PREF_NEWEST ) | 3189 | if ( full && mode < SYNC_PREF_NEWEST ) |
3152 | mode = SYNC_PREF_ASK; | 3190 | mode = SYNC_PREF_ASK; |
3153 | 3191 | ||
3154 | switch( mode ) { | 3192 | switch( mode ) { |
3155 | case SYNC_PREF_LOCAL: | 3193 | case SYNC_PREF_LOCAL: |
3156 | if ( lastSync > remoteMod ) | 3194 | if ( lastSync > remoteMod ) |
3157 | return 1; | 3195 | return 1; |
3158 | if ( lastSync > localMod ) | 3196 | if ( lastSync > localMod ) |
3159 | return 2; | 3197 | return 2; |
3160 | return 1; | 3198 | return 1; |
3161 | break; | 3199 | break; |
3162 | case SYNC_PREF_REMOTE: | 3200 | case SYNC_PREF_REMOTE: |
3163 | if ( lastSync > remoteMod ) | 3201 | if ( lastSync > remoteMod ) |
3164 | return 1; | 3202 | return 1; |
3165 | if ( lastSync > localMod ) | 3203 | if ( lastSync > localMod ) |
3166 | return 2; | 3204 | return 2; |
3167 | return 2; | 3205 | return 2; |
3168 | break; | 3206 | break; |
3169 | case SYNC_PREF_NEWEST: | 3207 | case SYNC_PREF_NEWEST: |
3170 | if ( localMod > remoteMod ) | 3208 | if ( localMod > remoteMod ) |
3171 | return 1; | 3209 | return 1; |
3172 | else | 3210 | else |
3173 | return 2; | 3211 | return 2; |
3174 | break; | 3212 | break; |
3175 | case SYNC_PREF_ASK: | 3213 | case SYNC_PREF_ASK: |
3176 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 3214 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
3177 | if ( lastSync > remoteMod ) | 3215 | if ( lastSync > remoteMod ) |
3178 | return 1; | 3216 | return 1; |
3179 | if ( lastSync > localMod ) | 3217 | if ( lastSync > localMod ) |
3180 | return 2; | 3218 | return 2; |
3181 | localIsNew = localMod >= remoteMod; | 3219 | localIsNew = localMod >= remoteMod; |
3182 | //qDebug("conflict! ************************************** "); | 3220 | //qDebug("conflict! ************************************** "); |
3183 | { | 3221 | { |
3184 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | 3222 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); |
3185 | result = acd.executeD(localIsNew); | 3223 | result = acd.executeD(localIsNew); |
3186 | return result; | 3224 | return result; |
3187 | } | 3225 | } |
3188 | break; | 3226 | break; |
3189 | case SYNC_PREF_FORCE_LOCAL: | 3227 | case SYNC_PREF_FORCE_LOCAL: |
3190 | return 1; | 3228 | return 1; |
3191 | break; | 3229 | break; |
3192 | case SYNC_PREF_FORCE_REMOTE: | 3230 | case SYNC_PREF_FORCE_REMOTE: |
3193 | return 2; | 3231 | return 2; |
3194 | break; | 3232 | break; |
3195 | 3233 | ||
3196 | default: | 3234 | default: |
3197 | // SYNC_PREF_TAKE_BOTH not implemented | 3235 | // SYNC_PREF_TAKE_BOTH not implemented |
3198 | break; | 3236 | break; |
3199 | } | 3237 | } |
3200 | return 0; | 3238 | return 0; |
3201 | } | 3239 | } |
3202 | 3240 | ||
3203 | 3241 | ||
3204 | 3242 | ||
3205 | 3243 | ||
3206 | //this are the overwritten callbackmethods from the syncinterface | 3244 | //this are the overwritten callbackmethods from the syncinterface |
3207 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3245 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
3208 | { | 3246 | { |
3209 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3247 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
3210 | 3248 | ||
3211 | //1) unlock local file first if necessary (ask for password) | 3249 | //1) unlock local file first if necessary (ask for password) |
3212 | if (this->isDeepLocked()) { | 3250 | if (this->isDeepLocked()) { |
3213 | PwMerror ret = this->deepLock(false); | 3251 | PwMerror ret = this->deepLock(false); |
3214 | if (ret != e_success) | 3252 | if (ret != e_success) |
3215 | return false; | 3253 | return false; |
3216 | } | 3254 | } |
3217 | 3255 | ||
3218 | //2) construct and open a new doc on the stack(automatic cleanup) for remote file. | 3256 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). |
3219 | PwMDoc syncTarget(this, "synctarget"); | 3257 | PwMDoc syncTarget(this, "synctarget"); |
3220 | PwMDoc* pSyncTarget = &syncTarget; | 3258 | PwMDoc* pSyncTarget = &syncTarget; |
3221 | 3259 | ||
3222 | 3260 | ||
3223 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3261 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3224 | 3262 | ||
3225 | if (err == e_alreadyOpen) { | 3263 | if (err == e_alreadyOpen) { |
3226 | PwMDocList::listItem li; | 3264 | PwMDocList::listItem li; |
3227 | if (getOpenDocList()->find(filename.latin1(), &li)) | 3265 | if (getOpenDocList()->find(filename.latin1(), &li)) |
3228 | pSyncTarget = li.doc; | 3266 | pSyncTarget = li.doc; |
3229 | else { | 3267 | else { |
3230 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3268 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3231 | return false; | 3269 | return false; |
3232 | } | 3270 | } |
3233 | } | 3271 | } |
3234 | else if (err != e_success) { | 3272 | else if (err != e_success) { |
3235 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); | 3273 | qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); |
3236 | return false; | 3274 | return false; |
3237 | } | 3275 | } |
3238 | 3276 | ||
3239 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3277 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
3240 | 3278 | ||
3241 | 3279 | ||
3242 | //3) unlock remote file first if necessary (ask for password) | 3280 | //3) unlock remote file first if necessary (ask for password) |
3243 | if (pSyncTarget->isDeepLocked()) { | 3281 | if (pSyncTarget->isDeepLocked()) { |
3244 | PwMerror ret = pSyncTarget->deepLock(false); | 3282 | PwMerror ret = pSyncTarget->deepLock(false); |
3245 | if (ret != e_success) | 3283 | if (ret != e_success) |
3246 | return false; | 3284 | return false; |
3247 | } | 3285 | } |
3248 | 3286 | ||
3249 | 3287 | ||
3250 | err = syncronize(manager, this, pSyncTarget, mode ); | 3288 | err = syncronize(manager, this, pSyncTarget, mode ); |
3251 | 3289 | ||
3252 | if (err == e_success) { | 3290 | if (err == e_success) { |
3253 | if ( manager->mWriteBackFile ){ | 3291 | if ( manager->mWriteBackFile ){ |
3254 | qDebug("Saving remote PWManager file"); | 3292 | qDebug("Saving remote PWManager file"); |
3255 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); | 3293 | err = pSyncTarget->saveDoc(conf()->confGlobCompression()); |
3256 | if (err != e_success) { | 3294 | if (err != e_success) { |
3257 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); | 3295 | qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); |
3258 | return false; | 3296 | return false; |
3259 | } | 3297 | } |
3260 | } | 3298 | } |
3261 | 3299 | ||
3262 | flagDirty(); | 3300 | flagDirty(); |
3263 | return true; | 3301 | return true; |
3264 | } | 3302 | } |
3265 | else { | 3303 | else { |
3266 | return false; | 3304 | return false; |
3267 | } | 3305 | } |
3268 | } | 3306 | } |
3269 | 3307 | ||
3270 | //called by the syncmanager to indicate that the work has to marked as dirty. | ||
3271 | void PwMDoc::sync_setModified() | ||
3272 | { | ||
3273 | flagDirty(); | ||
3274 | } | ||
3275 | |||
3276 | //called by the syncmanager to ask if the dirty flag is set. | ||
3277 | bool PwMDoc::sync_isModified() | ||
3278 | { | ||
3279 | return isDirty(); | ||
3280 | } | ||
3281 | |||
3282 | //called by the syncmanager to indicate that the work has to be saved. | ||
3283 | void PwMDoc::sync_save() | ||
3284 | { | ||
3285 | saveDoc(conf()->confGlobCompression()); | ||
3286 | } | ||
3287 | #endif | 3308 | #endif |
3288 | 3309 | ||
3289 | 3310 | ||
3290 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3311 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3291 | { | 3312 | { |
3292 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3313 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |
3293 | end = dti.syncDta.end(); | 3314 | end = dti.syncDta.end(); |
3294 | 3315 | ||
3295 | while (i != end) { | 3316 | while (i != end) { |
3296 | if ((*i).syncName == syncname.latin1()) { | 3317 | if ((*i).syncName == syncname.latin1()) { |
3297 | if (index) { | 3318 | if (index) { |
3298 | *index = i - dti.syncDta.begin(); | 3319 | *index = i - dti.syncDta.begin(); |
3299 | } | 3320 | } |
3300 | return true; | 3321 | return true; |
3301 | } | 3322 | } |
3302 | ++i; | 3323 | ++i; |
3303 | } | 3324 | } |
3304 | return false; | 3325 | return false; |
3305 | }; | 3326 | }; |
3306 | 3327 | ||
3307 | /** add new syncdataentry */ | 3328 | /** add new syncdataentry */ |
3308 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | 3329 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) |
3309 | { | 3330 | { |
3310 | PWM_ASSERT(d); | 3331 | PWM_ASSERT(d); |
3311 | 3332 | ||
3312 | if (isDeepLocked()) { | 3333 | if (isDeepLocked()) { |
3313 | PwMerror ret; | 3334 | PwMerror ret; |
3314 | ret = deepLock(false); | 3335 | ret = deepLock(false); |
3315 | if (ret != e_success) | 3336 | if (ret != e_success) |
3316 | return e_lock; | 3337 | return e_lock; |
3317 | } | 3338 | } |
3318 | unsigned int index; | 3339 | unsigned int index; |
3319 | 3340 | ||
3320 | const QString tmp = d->syncName.c_str(); | 3341 | const QString tmp = d->syncName.c_str(); |
3321 | bool exists = findSyncData(d->syncName.c_str(), &index); | 3342 | bool exists = findSyncData(d->syncName.c_str(), &index); |
3322 | 3343 | ||
3323 | if (exists == true) { | 3344 | if (exists == true) { |
3324 | // DOH! We found this entry. | 3345 | // DOH! We found this entry. |
3325 | return e_entryExists; | 3346 | return e_entryExists; |
3326 | } | 3347 | } |
3327 | 3348 | ||
3328 | dti.syncDta.push_back(*d); | 3349 | dti.syncDta.push_back(*d); |
3329 | 3350 | ||
3330 | if (!dontFlagDirty) | 3351 | if (!dontFlagDirty) |
3331 | flagDirty(); | 3352 | flagDirty(); |
3332 | return e_success; | 3353 | return e_success; |
3333 | } | 3354 | } |
3334 | 3355 | ||
3335 | 3356 | ||
3336 | 3357 | ||
3337 | /** delete syncdata entry */ | 3358 | /** delete syncdata entry */ |
3338 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | 3359 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) |
3339 | { | 3360 | { |
3340 | if (isDeepLocked()) | 3361 | if (isDeepLocked()) |
3341 | return false; | 3362 | return false; |
3342 | if (index > dti.syncDta.size() - 1) | 3363 | if (index > dti.syncDta.size() - 1) |
3343 | return false; | 3364 | return false; |
3344 | 3365 | ||
3345 | // delete entry | 3366 | // delete entry |
3346 | dti.syncDta.erase(dti.syncDta.begin() + index); | 3367 | dti.syncDta.erase(dti.syncDta.begin() + index); |
3347 | 3368 | ||
3348 | if (!dontFlagDirty) | 3369 | if (!dontFlagDirty) |
3349 | flagDirty(); | 3370 | flagDirty(); |
3350 | return true; | 3371 | return true; |
3351 | } | 3372 | } |
3352 | 3373 | ||
3353 | 3374 | ||
3354 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | 3375 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) |
3355 | { | 3376 | { |
3356 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3377 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3357 | catend = dti.dta.end(); | 3378 | catend = dti.dta.end(); |
3358 | 3379 | ||
3359 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3380 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3360 | 3381 | ||
3361 | while (catcounter != catend) { | 3382 | while (catcounter != catend) { |
3362 | entrBegin = catcounter->d.begin(); | 3383 | entrBegin = catcounter->d.begin(); |
3363 | entrEnd = catcounter->d.end(); | 3384 | entrEnd = catcounter->d.end(); |
3364 | entrI = entrBegin; | 3385 | entrI = entrBegin; |
3365 | while (entrI != entrEnd) { | 3386 | while (entrI != entrEnd) { |
3366 | if ((*entrI).meta.uniqueid == uid.latin1()) { | 3387 | if ((*entrI).meta.uniqueid == uid.latin1()) { |
3367 | if (category) | 3388 | if (category) |
3368 | *category = catcounter - dti.dta.begin(); | 3389 | *category = catcounter - dti.dta.begin(); |
3369 | if (index) | 3390 | if (index) |
3370 | *index = entrI - entrBegin; | 3391 | *index = entrI - entrBegin; |
3371 | 3392 | ||
3372 | return &(*entrI); | 3393 | return &(*entrI); |
3373 | } | 3394 | } |
3374 | ++entrI; | 3395 | ++entrI; |
3375 | } | 3396 | } |
3376 | ++catcounter; | 3397 | ++catcounter; |
3377 | } | 3398 | } |
3378 | 3399 | ||
3379 | return 0; | 3400 | return 0; |
3380 | } | 3401 | } |
3381 | 3402 | ||
3382 | QStringList PwMDoc::getIDEntryList() | 3403 | QStringList PwMDoc::getIDEntryList() |
3383 | { | 3404 | { |
3384 | QStringList results; | 3405 | QStringList results; |
3385 | 3406 | ||
3386 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3407 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3387 | catend = dti.dta.end(); | 3408 | catend = dti.dta.end(); |
3388 | 3409 | ||
3389 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3410 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3390 | 3411 | ||
3391 | while (catcounter != catend) { | 3412 | while (catcounter != catend) { |
3392 | entrBegin = catcounter->d.begin(); | 3413 | entrBegin = catcounter->d.begin(); |
3393 | entrEnd = catcounter->d.end(); | 3414 | entrEnd = catcounter->d.end(); |
3394 | entrI = entrBegin; | 3415 | entrI = entrBegin; |
3395 | while (entrI != entrEnd) { | 3416 | while (entrI != entrEnd) { |
3396 | results.append( (*entrI).meta.uniqueid.c_str() ); | 3417 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3397 | ++entrI; | 3418 | ++entrI; |
3398 | } | 3419 | } |
3399 | ++catcounter; | 3420 | ++catcounter; |
3400 | } | 3421 | } |
3401 | 3422 | ||
3402 | return results; | 3423 | return results; |
3403 | } | 3424 | } |
3404 | 3425 | ||
3405 | 3426 | ||
3406 | 3427 | ||
3407 | 3428 | ||
3408 | 3429 | ||
3409 | #ifndef PWM_EMBEDDED | 3430 | #ifndef PWM_EMBEDDED |
3410 | #include "pwmdoc.moc" | 3431 | #include "pwmdoc.moc" |
3411 | #endif | 3432 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 2e9547e..6a1dd30 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -1,806 +1,805 @@ | |||
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 2.0 of pwmanager | 14 | * This file is originaly based on version 2.0 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef __PWMDOC_H | 20 | #ifndef __PWMDOC_H |
21 | #define __PWMDOC_H | 21 | #define __PWMDOC_H |
22 | 22 | ||
23 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 23 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
24 | 24 | ||
25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
32 | 32 | ||
33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
40 | 40 | ||
41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
44 | 44 | ||
45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
47 | 47 | ||
48 | 48 | ||
49 | #include "pwmexception.h" | 49 | #include "pwmexception.h" |
50 | #include "pwmdocui.h" | 50 | #include "pwmdocui.h" |
51 | 51 | ||
52 | #include <qobject.h> | 52 | #include <qobject.h> |
53 | #include <qtimer.h> | 53 | #include <qtimer.h> |
54 | #include <qdatetime.h> | 54 | #include <qdatetime.h> |
55 | 55 | ||
56 | #include <kprocess.h> | 56 | #include <kprocess.h> |
57 | 57 | ||
58 | #ifndef PWM_EMBEDDED | 58 | #ifndef PWM_EMBEDDED |
59 | #include "configuration.h" | 59 | #include "configuration.h" |
60 | #else | 60 | #else |
61 | #include <kapplication.h> | 61 | #include <kapplication.h> |
62 | #include <ksyncmanager.h> | 62 | #include <ksyncmanager.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #include <string> | 65 | #include <string> |
66 | #include <vector> | 66 | #include <vector> |
67 | #include <utility> | 67 | #include <utility> |
68 | 68 | ||
69 | using std::vector; | 69 | using std::vector; |
70 | using std::string; | 70 | using std::string; |
71 | using std::pair; | 71 | using std::pair; |
72 | 72 | ||
73 | /* used in findEntry() function */ | 73 | /* used in findEntry() function */ |
74 | #define SEARCH_IN_DESC (1) | 74 | #define SEARCH_IN_DESC (1) |
75 | #define SEARCH_IN_NAME (1 << 1) | 75 | #define SEARCH_IN_NAME (1 << 1) |
76 | #define SEARCH_IN_PW (1 << 2) | 76 | #define SEARCH_IN_PW (1 << 2) |
77 | #define SEARCH_IN_COMMENT(1 << 3) | 77 | #define SEARCH_IN_COMMENT(1 << 3) |
78 | #define SEARCH_IN_URL (1 << 4) | 78 | #define SEARCH_IN_URL (1 << 4) |
79 | #define SEARCH_IN_LAUNCHER(1 << 5) | 79 | #define SEARCH_IN_LAUNCHER(1 << 5) |
80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
83 | 83 | ||
84 | /** document deeplocked. Data is out for lunch to disk */ | 84 | /** document deeplocked. Data is out for lunch to disk */ |
85 | #define DOC_STAT_DEEPLOCKED (1) | 85 | #define DOC_STAT_DEEPLOCKED (1) |
86 | /** encrypted document on disk is dirty. data has to go to disk. */ | 86 | /** encrypted document on disk is dirty. data has to go to disk. */ |
87 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 87 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
88 | /** we are using a chipcard to encrypt the data */ | 88 | /** we are using a chipcard to encrypt the data */ |
89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
92 | 92 | ||
93 | class PwMDoc; | 93 | class PwMDoc; |
94 | class PwMView; | 94 | class PwMView; |
95 | class QFile; | 95 | class QFile; |
96 | 96 | ||
97 | /* meta data for a PwMDataItem */ | 97 | /* meta data for a PwMDataItem */ |
98 | struct PwMMetaData | 98 | struct PwMMetaData |
99 | { | 99 | { |
100 | PwMMetaData() | 100 | PwMMetaData() |
101 | : updateInt (0) | 101 | : updateInt (0) |
102 | { } | 102 | { } |
103 | /** creation date of the PwMDataItem to which | 103 | /** creation date of the PwMDataItem to which |
104 | * this meta data belongs. | 104 | * this meta data belongs. |
105 | */ | 105 | */ |
106 | QDateTimecreate; | 106 | QDateTimecreate; |
107 | /** becomes valid on this date */ | 107 | /** becomes valid on this date */ |
108 | QDateTimevalid; | 108 | QDateTimevalid; |
109 | /** expire date */ | 109 | /** expire date */ |
110 | QDateTimeexpire; | 110 | QDateTimeexpire; |
111 | /** update date (last updated at this date) */ | 111 | /** update date (last updated at this date) */ |
112 | QDateTimeupdate; | 112 | QDateTimeupdate; |
113 | /** update interval (in minutes). Time since the | 113 | /** update interval (in minutes). Time since the |
114 | * last update to remind the user to update the item. | 114 | * last update to remind the user to update the item. |
115 | * 0 disables. | 115 | * 0 disables. |
116 | */ | 116 | */ |
117 | unsigned long updateInt; | 117 | unsigned long updateInt; |
118 | 118 | ||
119 | //US ENH: enhancements of the filestructure | 119 | //US ENH: enhancements of the filestructure |
120 | /* each entry gets a unique id assigned */ | 120 | /* each entry gets a unique id assigned */ |
121 | string uniqueid; | 121 | string uniqueid; |
122 | 122 | ||
123 | 123 | ||
124 | void clear() | 124 | void clear() |
125 | { | 125 | { |
126 | create = QDateTime(); | 126 | create = QDateTime(); |
127 | expire = QDateTime(); | 127 | expire = QDateTime(); |
128 | update = QDateTime(); | 128 | update = QDateTime(); |
129 | updateInt = 0; | 129 | updateInt = 0; |
130 | uniqueid = KApplication::randomString(8); | 130 | uniqueid = KApplication::randomString(8); |
131 | } | 131 | } |
132 | 132 | ||
133 | PwMMetaData& operator = (const PwMMetaData& x) | ||
134 | { | ||
135 | create = x.create; | ||
136 | expire = x.expire; | ||
137 | update = x.update; | ||
138 | updateInt = x.updateInt; | ||
139 | uniqueid = x.uniqueid; | ||
140 | return *this; | ||
141 | } | ||
142 | |||
143 | inline bool isValid() const | 133 | inline bool isValid() const |
144 | { | 134 | { |
145 | if (valid.isNull()) | 135 | if (valid.isNull()) |
146 | return true; | 136 | return true; |
147 | return (valid < QDateTime::currentDateTime()); | 137 | return (valid < QDateTime::currentDateTime()); |
148 | } | 138 | } |
149 | inline bool isExpired() const | 139 | inline bool isExpired() const |
150 | { | 140 | { |
151 | if (expire.isNull()) | 141 | if (expire.isNull()) |
152 | return false; | 142 | return false; |
153 | return (expire < QDateTime::currentDateTime()); | 143 | return (expire < QDateTime::currentDateTime()); |
154 | } | 144 | } |
155 | inline bool isUpdateIntOver() const | 145 | inline bool isUpdateIntOver() const |
156 | { | 146 | { |
157 | if (updateInt == 0 || | 147 | if (updateInt == 0 || |
158 | update.isNull()) | 148 | update.isNull()) |
159 | return false; | 149 | return false; |
160 | QDateTime d(update); | 150 | QDateTime d(update); |
161 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 151 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
162 | } | 152 | } |
163 | }; | 153 | }; |
164 | 154 | ||
165 | struct PwMDataItem | 155 | struct PwMDataItem |
166 | { | 156 | { |
167 | PwMDataItem() | 157 | PwMDataItem() |
168 | : lockStat (true) | 158 | : lockStat (true) |
169 | , listViewPos (-1) | 159 | , listViewPos (-1) |
170 | , binary (false) | 160 | , binary (false) |
171 | , rev (0) | 161 | , rev (0) |
172 | { } | 162 | { } |
173 | 163 | ||
174 | /** password description */ | 164 | /** password description */ |
175 | stringdesc; | 165 | stringdesc; |
176 | /** user-name */ | 166 | /** user-name */ |
177 | stringname; | 167 | stringname; |
178 | /** the password itself */ | 168 | /** the password itself */ |
179 | stringpw; | 169 | stringpw; |
180 | /** some comment */ | 170 | /** some comment */ |
181 | stringcomment; | 171 | stringcomment; |
182 | /** an URL string */ | 172 | /** an URL string */ |
183 | stringurl; | 173 | stringurl; |
184 | /** launcher. Can be executed as a system() command */ | 174 | /** launcher. Can be executed as a system() command */ |
185 | stringlauncher; | 175 | stringlauncher; |
186 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 176 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
187 | boollockStat; | 177 | boollockStat; |
188 | /** position of this item in main "list-view" | 178 | /** position of this item in main "list-view" |
189 | * If -1, the position is not yet specified and should be appended to the list | 179 | * If -1, the position is not yet specified and should be appended to the list |
190 | */ | 180 | */ |
191 | intlistViewPos; | 181 | intlistViewPos; |
192 | /** does this entry contain binary data? */ | 182 | /** does this entry contain binary data? */ |
193 | bool binary; | 183 | bool binary; |
194 | /** meta data for this data item. */ | 184 | /** meta data for this data item. */ |
195 | PwMMetaData meta; | 185 | PwMMetaData meta; |
196 | /** data revision counter. This counter can be used | 186 | /** data revision counter. This counter can be used |
197 | * to easily, efficiently determine if this data item | 187 | * to easily, efficiently determine if this data item |
198 | * has changed since some time. | 188 | * has changed since some time. |
199 | * This counter is incremented on every update. | 189 | * This counter is incremented on every update. |
200 | */ | 190 | */ |
201 | unsigned int rev; | 191 | unsigned int rev; |
202 | 192 | ||
203 | void clear(bool clearMeta = true) | 193 | void clear(bool clearMeta = true) |
204 | { | 194 | { |
205 | /* NOTE: Don't use .clear() here to be | 195 | /* NOTE: Don't use .clear() here to be |
206 | * backward compatible with gcc-2 (Debian Woody) | 196 | * backward compatible with gcc-2 (Debian Woody) |
207 | */ | 197 | */ |
208 | desc = ""; | 198 | desc = ""; |
209 | name = ""; | 199 | name = ""; |
210 | pw = ""; | 200 | pw = ""; |
211 | comment = ""; | 201 | comment = ""; |
212 | url = ""; | 202 | url = ""; |
213 | launcher = ""; | 203 | launcher = ""; |
214 | lockStat = true; | 204 | lockStat = true; |
215 | listViewPos = -1; | 205 | listViewPos = -1; |
216 | binary = false; | 206 | binary = false; |
217 | if (clearMeta) | 207 | if (clearMeta) |
218 | meta.clear(); | 208 | meta.clear(); |
219 | } | 209 | } |
220 | 210 | //US ENH: we need this operator to compare two items if we have no unique ids | |
211 | //available. Generaly this happens before the first sync | ||
212 | bool PwMDataItem::operator==( const PwMDataItem &a ) const | ||
213 | { | ||
214 | qDebug("oper==%s", a.desc.c_str()); | ||
215 | if ( desc != a.desc ) return false; | ||
216 | if ( name != a.name ) return false; | ||
217 | if ( pw != a.pw ) return false; | ||
218 | if ( comment != a.comment ) return false; | ||
219 | if ( url != a.url ) return false; | ||
220 | if ( launcher != a.launcher ) return false; | ||
221 | //all other field will not be checked. | ||
222 | return true; | ||
223 | } | ||
224 | |||
225 | //US ENH:this operator is used to copy an elements data during syncronization | ||
226 | //Attention: listViewPos will not be copied. So the position will stay the same. | ||
221 | PwMDataItem& operator = (const PwMDataItem& x) | 227 | PwMDataItem& operator = (const PwMDataItem& x) |
222 | { | 228 | { |
223 | qDebug("oper=%s", x.desc.c_str()); | 229 | // qDebug("oper=%s", x.desc.c_str()); |
224 | desc = x.desc; | 230 | desc = x.desc; |
225 | name = x.name; | 231 | name = x.name; |
226 | pw = x.pw; | 232 | pw = x.pw; |
227 | comment = x.comment; | 233 | comment = x.comment; |
228 | url = x.url; | 234 | url = x.url; |
229 | launcher = x.launcher; | 235 | launcher = x.launcher; |
230 | lockStat = x.lockStat; | 236 | lockStat = x.lockStat; |
231 | listViewPos = x.listViewPos; | 237 | //Do not copy listViewPos!!! listViewPos = x.listViewPos; |
232 | binary = x.binary; | 238 | binary = x.binary; |
233 | meta = x.meta; | 239 | meta = x.meta; |
234 | rev = x.rev; | 240 | rev = x.rev; |
235 | return *this; | 241 | return *this; |
236 | } | 242 | } |
237 | 243 | ||
238 | }; | 244 | }; |
239 | 245 | ||
240 | struct PwMCategoryItem | 246 | struct PwMCategoryItem |
241 | { | 247 | { |
242 | /** all PwMDataItems (all passwords) within this category */ | 248 | /** all PwMDataItems (all passwords) within this category */ |
243 | vector<PwMDataItem>d; | 249 | vector<PwMDataItem>d; |
244 | /** category name/description */ | 250 | /** category name/description */ |
245 | string name; | 251 | string name; |
246 | 252 | ||
247 | void clear() | 253 | void clear() |
248 | { | 254 | { |
249 | d.clear(); | 255 | d.clear(); |
250 | name = ""; | 256 | name = ""; |
251 | } | 257 | } |
252 | }; | 258 | }; |
253 | 259 | ||
254 | struct PwMSyncItem | 260 | struct PwMSyncItem |
255 | { | 261 | { |
256 | string syncName; | 262 | string syncName; |
257 | QDateTime lastSyncDate; | 263 | QDateTime lastSyncDate; |
258 | 264 | ||
259 | void clear() | 265 | void clear() |
260 | { | 266 | { |
261 | lastSyncDate = QDateTime(); | 267 | lastSyncDate = QDateTime(); |
262 | syncName = ""; | 268 | syncName = ""; |
263 | } | 269 | } |
264 | }; | 270 | }; |
265 | 271 | ||
266 | struct PwMItem | 272 | struct PwMItem |
267 | { | 273 | { |
268 | vector<PwMCategoryItem> dta; | 274 | vector<PwMCategoryItem> dta; |
269 | vector<PwMSyncItem> syncDta; | 275 | vector<PwMSyncItem> syncDta; |
270 | 276 | ||
271 | void clear() | 277 | void clear() |
272 | { | 278 | { |
273 | dta.clear(); | 279 | dta.clear(); |
274 | syncDta.clear(); | 280 | syncDta.clear(); |
275 | } | 281 | } |
276 | }; | 282 | }; |
277 | 283 | ||
278 | 284 | ||
279 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 285 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
280 | class dta_lvp_greater | 286 | class dta_lvp_greater |
281 | { | 287 | { |
282 | public: | 288 | public: |
283 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 289 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
284 | const pair<unsigned int, unsigned int> &d2) | 290 | const pair<unsigned int, unsigned int> &d2) |
285 | { | 291 | { |
286 | return d1.second > d2.second; | 292 | return d1.second > d2.second; |
287 | } | 293 | } |
288 | }; | 294 | }; |
289 | 295 | ||
290 | /** list of PwMDoc documents and it's IDs */ | 296 | /** list of PwMDoc documents and it's IDs */ |
291 | class PwMDocList | 297 | class PwMDocList |
292 | { | 298 | { |
293 | public: | 299 | public: |
294 | struct listItem | 300 | struct listItem |
295 | { | 301 | { |
296 | /** document filename (known as ID, here) */ | 302 | /** document filename (known as ID, here) */ |
297 | string docId; | 303 | string docId; |
298 | /** pointer to the document class */ | 304 | /** pointer to the document class */ |
299 | PwMDoc *doc; | 305 | PwMDoc *doc; |
300 | }; | 306 | }; |
301 | 307 | ||
302 | PwMDocList() {} | 308 | PwMDocList() {} |
303 | 309 | ||
304 | /** add a new item to the list */ | 310 | /** add a new item to the list */ |
305 | void add(PwMDoc *doc, const string &id); | 311 | void add(PwMDoc *doc, const string &id); |
306 | /** changes the contents of an existing item */ | 312 | /** changes the contents of an existing item */ |
307 | void edit(PwMDoc *doc, const string &newId); | 313 | void edit(PwMDoc *doc, const string &newId); |
308 | /** remove the given item */ | 314 | /** remove the given item */ |
309 | void del(PwMDoc *doc); | 315 | void del(PwMDoc *doc); |
310 | /** get the item at index */ | 316 | /** get the item at index */ |
311 | listItem getAt(int index) | 317 | listItem getAt(int index) |
312 | { return docList[index]; } | 318 | { return docList[index]; } |
313 | /** find an entry with this id */ | 319 | /** find an entry with this id */ |
314 | bool find(const string &id, listItem *ret = 0); | 320 | bool find(const string &id, listItem *ret = 0); |
315 | /** returns a copy of the list */ | 321 | /** returns a copy of the list */ |
316 | const vector<listItem>* getList() const | 322 | const vector<listItem>* getList() const |
317 | { return &docList; } | 323 | { return &docList; } |
318 | 324 | ||
319 | 325 | ||
320 | /** returns a new unique number to extend the name of | 326 | /** returns a new unique number to extend the name of |
321 | * an unnamed document. | 327 | * an unnamed document. |
322 | */ | 328 | */ |
323 | static unsigned int getNewUnnamedNumber() | 329 | static unsigned int getNewUnnamedNumber() |
324 | { return unnamedDocCnt++; } | 330 | { return unnamedDocCnt++; } |
325 | 331 | ||
326 | protected: | 332 | protected: |
327 | /* Hm, I think we shouldn't really use a "list" here, should we? | 333 | /* Hm, I think we shouldn't really use a "list" here, should we? |
328 | * So I decided to actually use a vector. | 334 | * So I decided to actually use a vector. |
329 | */ | 335 | */ |
330 | vector<listItem> docList; | 336 | vector<listItem> docList; |
331 | /** This value is used to get a new number for yet unnamed | 337 | /** This value is used to get a new number for yet unnamed |
332 | * documents. It is incremented on every request. So it's | 338 | * documents. It is incremented on every request. So it's |
333 | * theoretically possible to overflow it, but... :) | 339 | * theoretically possible to overflow it, but... :) |
334 | */ | 340 | */ |
335 | static unsigned int unnamedDocCnt; | 341 | static unsigned int unnamedDocCnt; |
336 | }; | 342 | }; |
337 | 343 | ||
338 | /** implements timers for the document */ | 344 | /** implements timers for the document */ |
339 | class DocTimer : public QObject | 345 | class DocTimer : public QObject |
340 | { | 346 | { |
341 | Q_OBJECT | 347 | Q_OBJECT |
342 | public: | 348 | public: |
343 | enum TimerIDs | 349 | enum TimerIDs |
344 | { | 350 | { |
345 | id_mpwTimer, | 351 | id_mpwTimer, |
346 | id_autoLockTimer, | 352 | id_autoLockTimer, |
347 | id_metaCheckTimer | 353 | id_metaCheckTimer |
348 | }; | 354 | }; |
349 | 355 | ||
350 | public: | 356 | public: |
351 | DocTimer(PwMDoc *_doc); | 357 | DocTimer(PwMDoc *_doc); |
352 | ~DocTimer(); | 358 | ~DocTimer(); |
353 | 359 | ||
354 | /** start the timer */ | 360 | /** start the timer */ |
355 | void start(TimerIDs timer); | 361 | void start(TimerIDs timer); |
356 | /** stop the timer */ | 362 | /** stop the timer */ |
357 | void stop(TimerIDs timer); | 363 | void stop(TimerIDs timer); |
358 | /** get the lock for a timer. | 364 | /** get the lock for a timer. |
359 | * This lock is a recursive lock. When a lock is | 365 | * This lock is a recursive lock. When a lock is |
360 | * held, the timer will be stopped and timeout is | 366 | * held, the timer will be stopped and timeout is |
361 | * guaranteed to not happen | 367 | * guaranteed to not happen |
362 | */ | 368 | */ |
363 | void getLock(TimerIDs timer); | 369 | void getLock(TimerIDs timer); |
364 | /** put a recursive timer lock */ | 370 | /** put a recursive timer lock */ |
365 | void putLock(TimerIDs timer); | 371 | void putLock(TimerIDs timer); |
366 | 372 | ||
367 | protected slots: | 373 | protected slots: |
368 | /** timeout slot for the mpw timer */ | 374 | /** timeout slot for the mpw timer */ |
369 | void mpwTimeout(); | 375 | void mpwTimeout(); |
370 | /** timeout slot for the autoLock timer */ | 376 | /** timeout slot for the autoLock timer */ |
371 | void autoLockTimeout(); | 377 | void autoLockTimeout(); |
372 | /** timeout slot for the metaCheck timer */ | 378 | /** timeout slot for the metaCheck timer */ |
373 | void metaCheckTimeout(); | 379 | void metaCheckTimeout(); |
374 | 380 | ||
375 | protected: | 381 | protected: |
376 | /** pointer to the document associated with this timer. */ | 382 | /** pointer to the document associated with this timer. */ |
377 | PwMDoc *doc; | 383 | PwMDoc *doc; |
378 | /** timer object for mpw timer */ | 384 | /** timer object for mpw timer */ |
379 | QTimer *mpwTimer; | 385 | QTimer *mpwTimer; |
380 | /** timer object for the autoLock timer */ | 386 | /** timer object for the autoLock timer */ |
381 | QTimer *autoLockTimer; | 387 | QTimer *autoLockTimer; |
382 | /** timer object for the metaCheck timer */ | 388 | /** timer object for the metaCheck timer */ |
383 | QTimer *metaCheckTimer; | 389 | QTimer *metaCheckTimer; |
384 | /** lock counter for the mpw timer */ | 390 | /** lock counter for the mpw timer */ |
385 | unsigned int mpwLock; | 391 | unsigned int mpwLock; |
386 | /** lock counter for the autoLock timer */ | 392 | /** lock counter for the autoLock timer */ |
387 | unsigned int autoLockLock; | 393 | unsigned int autoLockLock; |
388 | /** lock counter for the metaCheck timer */ | 394 | /** lock counter for the metaCheck timer */ |
389 | unsigned int metaCheckLock; | 395 | unsigned int metaCheckLock; |
390 | }; | 396 | }; |
391 | 397 | ||
392 | /** Document class for PwM */ | 398 | /** Document class for PwM */ |
393 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. | 399 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. |
394 | // But PwMDoc is handling the sync by itself. | 400 | // But PwMDoc is handling the sync by itself. |
395 | class PwMDoc : public PwMDocUi, public KSyncInterface | 401 | class PwMDoc : public PwMDocUi, public KSyncInterface |
396 | 402 | ||
397 | { | 403 | { |
398 | Q_OBJECT | 404 | Q_OBJECT |
399 | friend class DocTimer; | 405 | friend class DocTimer; |
400 | 406 | ||
401 | public: | 407 | public: |
402 | /** construtor */ | 408 | /** construtor */ |
403 | PwMDoc(QObject* parent = 0, const char *name = 0); | 409 | PwMDoc(QObject* parent = 0, const char *name = 0); |
404 | /** destructor */ | 410 | /** destructor */ |
405 | ~PwMDoc(); | 411 | ~PwMDoc(); |
406 | 412 | ||
407 | /** returns a pointer to a list of all open documents */ | 413 | /** returns a pointer to a list of all open documents */ |
408 | static PwMDocList* getOpenDocList() | 414 | static PwMDocList* getOpenDocList() |
409 | { return &openDocList; } | 415 | { return &openDocList; } |
410 | 416 | ||
411 | /** flag document dirty. dta changed */ | 417 | /** flag document dirty. dta changed */ |
412 | void flagDirty() | 418 | void flagDirty() |
413 | { | 419 | { |
414 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 420 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
415 | emitDataChanged(this); | 421 | emitDataChanged(this); |
416 | } | 422 | } |
417 | /** modified? */ | 423 | /** modified? */ |
418 | bool isDirty() | 424 | bool isDirty() |
419 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 425 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
420 | /** save document to disk */ | 426 | /** save document to disk */ |
421 | PwMerror saveDoc(char compress, const QString *file = 0); | 427 | PwMerror saveDoc(char compress, const QString *file = 0); |
422 | /** read document from file. | 428 | /** read document from file. |
423 | * "openLocked is must be set to either of these values: | 429 | * "openLocked is must be set to either of these values: |
424 | * 0 == open with all entries unlocked | 430 | * 0 == open with all entries unlocked |
425 | * 1 == open with all entries locked | 431 | * 1 == open with all entries locked |
426 | * 2 == open deep-locked | 432 | * 2 == open deep-locked |
427 | */ | 433 | */ |
428 | PwMerror openDoc(const QString *file, int openLocked); | 434 | PwMerror openDoc(const QString *file, int openLocked); |
429 | /** export document to ascii-textfile */ | 435 | /** export document to ascii-textfile */ |
430 | PwMerror exportToText(const QString *file); | 436 | PwMerror exportToText(const QString *file); |
431 | /** export document to gpasman / kpasman file */ | 437 | /** export document to gpasman / kpasman file */ |
432 | PwMerror exportToGpasman(const QString *file); | 438 | PwMerror exportToGpasman(const QString *file); |
433 | /** import document from ascii-textfile */ | 439 | /** import document from ascii-textfile */ |
434 | PwMerror importFromText(const QString *file, int format = -1); | 440 | PwMerror importFromText(const QString *file, int format = -1); |
435 | /** import document from gpasman / kpasman file */ | 441 | /** import document from gpasman / kpasman file */ |
436 | PwMerror importFromGpasman(const QString *file); | 442 | PwMerror importFromGpasman(const QString *file); |
437 | /** add new entry */ | 443 | /** add new entry */ |
438 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 444 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
439 | bool dontFlagDirty = false, bool updateMeta = true); | 445 | bool dontFlagDirty = false, bool updateMeta = true); |
440 | /** add new category. This function doesn't flag the document dirty! */ | 446 | /** add new category. This function doesn't flag the document dirty! */ |
441 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 447 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
442 | bool checkIfExist = true); | 448 | bool checkIfExist = true); |
443 | /** rename an existing category */ | 449 | /** rename an existing category */ |
444 | bool renameCategory(const QString &category, const QString &newName); | 450 | bool renameCategory(const QString &category, const QString &newName); |
445 | /** rename an existing category */ | 451 | /** rename an existing category */ |
446 | bool renameCategory(unsigned int category, const QString &newName, | 452 | bool renameCategory(unsigned int category, const QString &newName, |
447 | bool dontFlagDirty = false); | 453 | bool dontFlagDirty = false); |
448 | /** delete an existing category */ | 454 | /** delete an existing category */ |
449 | bool delCategory(const QString &category); | 455 | bool delCategory(const QString &category); |
450 | /** delete an existing category */ | 456 | /** delete an existing category */ |
451 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 457 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
452 | /** returns a list of all category-names */ | 458 | /** returns a list of all category-names */ |
453 | void getCategoryList(vector<string> *list); | 459 | void getCategoryList(vector<string> *list); |
454 | /** returns a list of all category-names */ | 460 | /** returns a list of all category-names */ |
455 | void getCategoryList(QStringList *list); | 461 | void getCategoryList(QStringList *list); |
456 | /** returns a list of all entry-descs in the given category */ | 462 | /** returns a list of all entry-descs in the given category */ |
457 | void getEntryList(const QString &category, QStringList *list); | 463 | void getEntryList(const QString &category, QStringList *list); |
458 | /** returns a list of all entry-descs in the given category */ | 464 | /** returns a list of all entry-descs in the given category */ |
459 | void getEntryList(const QString &category, vector<string> *list); | 465 | void getEntryList(const QString &category, vector<string> *list); |
460 | /** returns a list of all entry-descs in the given category */ | 466 | /** returns a list of all entry-descs in the given category */ |
461 | void getEntryList(unsigned int category, vector<string> *list); | 467 | void getEntryList(unsigned int category, vector<string> *list); |
462 | /** returns a list of all entry-descs in the given category */ | 468 | /** returns a list of all entry-descs in the given category */ |
463 | void getEntryList(unsigned int category, QStringList *list); | 469 | void getEntryList(unsigned int category, QStringList *list); |
464 | /** delete entry */ | 470 | /** delete entry */ |
465 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 471 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
466 | /** delete entry */ | 472 | /** delete entry */ |
467 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 473 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
468 | /** edit entry */ | 474 | /** edit entry */ |
469 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 475 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
470 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 476 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
471 | /** edit entry */ | 477 | /** edit entry */ |
472 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 478 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
473 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 479 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
474 | /** finds the category with the "name" and return it's index */ | 480 | /** finds the category with the "name" and return it's index */ |
475 | bool findCategory(const QString &name, unsigned int *index); | 481 | bool findCategory(const QString &name, unsigned int *index); |
476 | /** search for an entry "find" and check while searching only for | 482 | /** search for an entry "find" and check while searching only for |
477 | * the data-fields specified by "searchIn". To set the "searchIn" | 483 | * the data-fields specified by "searchIn". To set the "searchIn" |
478 | * value, we may use one or more of the SEARCH_IN_* defines at | 484 | * value, we may use one or more of the SEARCH_IN_* defines at |
479 | * the top of this header-file. It returns the positions of all | 485 | * the top of this header-file. It returns the positions of all |
480 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 486 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
481 | * the function terminates after the first occurence of the entry | 487 | * the function terminates after the first occurence of the entry |
482 | * and doesn't go on searching. So foundPositions->size() is never | 488 | * and doesn't go on searching. So foundPositions->size() is never |
483 | * > 1 if breakAfterFound is true. | 489 | * > 1 if breakAfterFound is true. |
484 | */ | 490 | */ |
485 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 491 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
486 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 492 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
487 | bool caseSensitive = true, bool exactWordMatch = true, | 493 | bool caseSensitive = true, bool exactWordMatch = true, |
488 | bool sortByLvp = false); | 494 | bool sortByLvp = false); |
489 | /** see the above funtion. This function allows to set the category by name. */ | 495 | /** see the above funtion. This function allows to set the category by name. */ |
490 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 496 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
491 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 497 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
492 | bool caseSensitive = true, bool exactWordMatch = true, | 498 | bool caseSensitive = true, bool exactWordMatch = true, |
493 | bool sortByLvp = false); | 499 | bool sortByLvp = false); |
494 | /** returns number of entries */ | 500 | /** returns number of entries */ |
495 | unsigned int numEntries(const QString &category); | 501 | unsigned int numEntries(const QString &category); |
496 | unsigned int numEntries(unsigned int category) | 502 | unsigned int numEntries(unsigned int category) |
497 | { return dti.dta[category].d.size(); } | 503 | { return dti.dta[category].d.size(); } |
498 | /** returns number of categories */ | 504 | /** returns number of categories */ |
499 | unsigned int numCategories() | 505 | unsigned int numCategories() |
500 | { return dti.dta.size(); } | 506 | { return dti.dta.size(); } |
501 | /** returns the name of the category at "index" */ | 507 | /** returns the name of the category at "index" */ |
502 | const string* getCategory(unsigned int index) | 508 | const string* getCategory(unsigned int index) |
503 | { return (&(dti.dta[index].name)); } | 509 | { return (&(dti.dta[index].name)); } |
504 | 510 | ||
505 | /** returns the data of item at "index". | 511 | /** returns the data of item at "index". |
506 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 512 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
507 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 513 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
508 | * the pw. | 514 | * the pw. |
509 | */ | 515 | */ |
510 | bool getEntry(const QString &category, unsigned int index, | 516 | bool getEntry(const QString &category, unsigned int index, |
511 | PwMDataItem *d, bool unlockIfLocked = false); | 517 | PwMDataItem *d, bool unlockIfLocked = false); |
512 | bool getEntry(unsigned int category, unsigned int index, | 518 | bool getEntry(unsigned int category, unsigned int index, |
513 | PwMDataItem *d, bool unlockIfLocked = false); | 519 | PwMDataItem *d, bool unlockIfLocked = false); |
514 | /** returns the comment-string by looking at the category | 520 | /** returns the comment-string by looking at the category |
515 | * and the listViewPos | 521 | * and the listViewPos |
516 | */ | 522 | */ |
517 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 523 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
518 | string *foundComment); | 524 | string *foundComment); |
519 | /** checks if a password is already available. (currentPw) */ | 525 | /** checks if a password is already available. (currentPw) */ |
520 | bool isPwAvailable() | 526 | bool isPwAvailable() |
521 | { return (currentPw != ""); } | 527 | { return (currentPw != ""); } |
522 | /** un/lock entry at "index". If needed, ask for password. */ | 528 | /** un/lock entry at "index". If needed, ask for password. */ |
523 | bool lockAt(const QString &category, unsigned int index, | 529 | bool lockAt(const QString &category, unsigned int index, |
524 | bool lock = true); | 530 | bool lock = true); |
525 | bool lockAt(unsigned int category, unsigned int index, | 531 | bool lockAt(unsigned int category, unsigned int index, |
526 | bool lock = true); | 532 | bool lock = true); |
527 | /** returns the lock-status at "index" */ | 533 | /** returns the lock-status at "index" */ |
528 | bool isLocked(const QString &category, unsigned int index); | 534 | bool isLocked(const QString &category, unsigned int index); |
529 | bool isLocked(unsigned int category, unsigned int index) | 535 | bool isLocked(unsigned int category, unsigned int index) |
530 | { return dti.dta[category].d[index].lockStat; } | 536 | { return dti.dta[category].d[index].lockStat; } |
531 | /** returns the deeplock status */ | 537 | /** returns the deeplock status */ |
532 | bool isDeepLocked() | 538 | bool isDeepLocked() |
533 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 539 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
534 | /** (un)lock all entries */ | 540 | /** (un)lock all entries */ |
535 | bool lockAll(bool lock); | 541 | bool lockAll(bool lock); |
536 | /** unlocks all entries tempoarly. | 542 | /** unlocks all entries tempoarly. |
537 | * 1st NOTE: Be very careful with this function! :) | 543 | * 1st NOTE: Be very careful with this function! :) |
538 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 544 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
539 | * please DON'T forget to call unlockAll_Tempoary(true); | 545 | * please DON'T forget to call unlockAll_Tempoary(true); |
540 | * _before_ the user (or someone else) is able to change | 546 | * _before_ the user (or someone else) is able to change |
541 | * the document! | 547 | * the document! |
542 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 548 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
543 | * unlocked! This will cause corruption. | 549 | * unlocked! This will cause corruption. |
544 | */ | 550 | */ |
545 | bool unlockAll_tempoary(bool revert = false); | 551 | bool unlockAll_tempoary(bool revert = false); |
546 | /** deep-(un)locks the document. | 552 | /** deep-(un)locks the document. |
547 | * deep-locking writes all data to the file, deletes all data | 553 | * deep-locking writes all data to the file, deletes all data |
548 | * in memory, but doesn't close the document. | 554 | * in memory, but doesn't close the document. |
549 | * deep-locking is only available, if the user previously saved | 555 | * deep-locking is only available, if the user previously saved |
550 | * the doc to a file (with a password). | 556 | * the doc to a file (with a password). |
551 | * If "saveToFile" is false, it does NOT write the data to the file! | 557 | * If "saveToFile" is false, it does NOT write the data to the file! |
552 | */ | 558 | */ |
553 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 559 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
554 | /** is unlockable without pw? */ | 560 | /** is unlockable without pw? */ |
555 | bool unlockWoPw() | 561 | bool unlockWoPw() |
556 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 562 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
557 | /** get the "currentPassword" */ | 563 | /** get the "currentPassword" */ |
558 | const QString& getCurrentPw() | 564 | const QString& getCurrentPw() |
559 | { return currentPw; } | 565 | { return currentPw; } |
560 | /** open a window and request the user to change the mpw */ | 566 | /** open a window and request the user to change the mpw */ |
561 | void changeCurrentPw(); | 567 | void changeCurrentPw(); |
562 | /** set the "listViewPos" variable of "dta" */ | 568 | /** set the "listViewPos" variable of "dta" */ |
563 | void setListViewPos(const QString &category, unsigned int index, | 569 | void setListViewPos(const QString &category, unsigned int index, |
564 | int pos); | 570 | int pos); |
565 | /** set the "listViewPos" variable of "dta" */ | 571 | /** set the "listViewPos" variable of "dta" */ |
566 | void setListViewPos(unsigned int category, unsigned int index, | 572 | void setListViewPos(unsigned int category, unsigned int index, |
567 | int pos); | 573 | int pos); |
568 | /** get the "listViewPos" variable of "dta" */ | 574 | /** get the "listViewPos" variable of "dta" */ |
569 | int getListViewPos(const QString &category, unsigned int index); | 575 | int getListViewPos(const QString &category, unsigned int index); |
570 | /** set the maximum number of entries allowed */ | 576 | /** set the maximum number of entries allowed */ |
571 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 577 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
572 | { maxEntries = num; } | 578 | { maxEntries = num; } |
573 | /** get the maximum number of entries allowed */ | 579 | /** get the maximum number of entries allowed */ |
574 | unsigned int getMaxNumEntries() | 580 | unsigned int getMaxNumEntries() |
575 | { return maxEntries; } | 581 | { return maxEntries; } |
576 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 582 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
577 | * If there are some undefined entries, add them to the end of | 583 | * If there are some undefined entries, add them to the end of |
578 | * the listViewPos(itions). */ | 584 | * the listViewPos(itions). */ |
579 | void ensureLvp(); | 585 | void ensureLvp(); |
580 | /** execute the "launcher" of this entry */ | 586 | /** execute the "launcher" of this entry */ |
581 | bool execLauncher(const QString &category, unsigned int entryIndex); | 587 | bool execLauncher(const QString &category, unsigned int entryIndex); |
582 | /** see above */ | 588 | /** see above */ |
583 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 589 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
584 | /** open a browser with the URL-section of the given entry */ | 590 | /** open a browser with the URL-section of the given entry */ |
585 | bool goToURL(const QString &category, unsigned int entryIndex); | 591 | bool goToURL(const QString &category, unsigned int entryIndex); |
586 | /** see above */ | 592 | /** see above */ |
587 | bool goToURL(unsigned int category, unsigned int entryIndex); | 593 | bool goToURL(unsigned int category, unsigned int entryIndex); |
588 | /** returns true if there is no entry present in the document. | 594 | /** returns true if there is no entry present in the document. |
589 | * Note: The "default" Category is present everytime, so | 595 | * Note: The "default" Category is present everytime, so |
590 | * it's checked for it's entries. | 596 | * it's checked for it's entries. |
591 | */ | 597 | */ |
592 | bool isDocEmpty() | 598 | bool isDocEmpty() |
593 | { | 599 | { |
594 | if (numCategories() > 1) | 600 | if (numCategories() > 1) |
595 | return false; | 601 | return false; |
596 | if (numEntries(0)) | 602 | if (numEntries(0)) |
597 | return false; | 603 | return false; |
598 | return true; | 604 | return true; |
599 | } | 605 | } |
600 | /** returns the filename of this doc */ | 606 | /** returns the filename of this doc */ |
601 | const QString& getFilename() | 607 | const QString& getFilename() |
602 | { return filename; } | 608 | { return filename; } |
603 | /** returns the title of the doc */ | 609 | /** returns the title of the doc */ |
604 | QString getTitle(); | 610 | QString getTitle(); |
605 | /** sets the list-view-pointer hold in the doc */ | 611 | /** sets the list-view-pointer hold in the doc */ |
606 | void setListViewPointer(PwMView *_listView) | 612 | void setListViewPointer(PwMView *_listView) |
607 | { listView = _listView; } | 613 | { listView = _listView; } |
608 | /** returns the list-view-pointer */ | 614 | /** returns the list-view-pointer */ |
609 | PwMView * getListViewPointer() | 615 | PwMView * getListViewPointer() |
610 | { return listView; } | 616 | { return listView; } |
611 | /** try to delete the doc. The user may be asked to save | 617 | /** try to delete the doc. The user may be asked to save |
612 | * the data. The user may cancel the whole operation. | 618 | * the data. The user may cancel the whole operation. |
613 | * false is returned, then. | 619 | * false is returned, then. |
614 | */ | 620 | */ |
615 | bool tryDelete(); | 621 | bool tryDelete(); |
616 | /** is the doc deleted? (with tryDelete() ) */ | 622 | /** is the doc deleted? (with tryDelete() ) */ |
617 | bool isDeleted() | 623 | bool isDeleted() |
618 | { return deleted; } | 624 | { return deleted; } |
619 | /** returns the document timer object */ | 625 | /** returns the document timer object */ |
620 | DocTimer * timer() | 626 | DocTimer * timer() |
621 | { return _timer; } | 627 | { return _timer; } |
622 | /** get a lock on the dataChanged signal. | 628 | /** get a lock on the dataChanged signal. |
623 | * If someone is holding a lock, the signal is not emitted. | 629 | * If someone is holding a lock, the signal is not emitted. |
624 | */ | 630 | */ |
625 | void getDataChangedLock() | 631 | void getDataChangedLock() |
626 | { ++dataChangedLock; } | 632 | { ++dataChangedLock; } |
627 | /** put the dataChanged lock */ | 633 | /** put the dataChanged lock */ |
628 | void putDataChangedLock() | 634 | void putDataChangedLock() |
629 | { --dataChangedLock; } | 635 | { --dataChangedLock; } |
630 | /** returns the revision count of the item at cat/index */ | 636 | /** returns the revision count of the item at cat/index */ |
631 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 637 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
632 | { return dti.dta[category].d[index].rev; } | 638 | { return dti.dta[category].d[index].rev; } |
633 | /** returns a const pointer to the entries meta */ | 639 | /** returns a const pointer to the entries meta */ |
634 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 640 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
635 | { return &(dti.dta[category].d[index].meta); } | 641 | { return &(dti.dta[category].d[index].meta); } |
636 | /** is the entry at "category" "index" a binary entry? */ | 642 | /** is the entry at "category" "index" a binary entry? */ |
637 | bool isBinEntry(unsigned int category, unsigned int index) | 643 | bool isBinEntry(unsigned int category, unsigned int index) |
638 | { return dti.dta[category].d[index].binary; } | 644 | { return dti.dta[category].d[index].binary; } |
639 | 645 | ||
640 | public slots: | 646 | public slots: |
641 | /** wrapper for PwMTray */ | 647 | /** wrapper for PwMTray */ |
642 | void _deepUnlock(); | 648 | void _deepUnlock(); |
643 | 649 | ||
644 | signals: | 650 | signals: |
645 | /** the data of the document has changed and must be updated | 651 | /** the data of the document has changed and must be updated |
646 | * in all views. | 652 | * in all views. |
647 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 653 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
648 | */ | 654 | */ |
649 | void dataChanged(PwMDoc *document); | 655 | void dataChanged(PwMDoc *document); |
650 | /** the document class is going to close. This signal may be | 656 | /** the document class is going to close. This signal may be |
651 | * used to nofify all views, that the user closed the document, | 657 | * used to nofify all views, that the user closed the document, |
652 | * so the views can go down, too. | 658 | * so the views can go down, too. |
653 | */ | 659 | */ |
654 | void docClosed(PwMDoc *document); | 660 | void docClosed(PwMDoc *document); |
655 | /** somebody just opened the document */ | 661 | /** somebody just opened the document */ |
656 | void docOpened(PwMDoc *document); | 662 | void docOpened(PwMDoc *document); |
657 | /** this document object just got created */ | 663 | /** this document object just got created */ |
658 | void docCreated(PwMDoc *document); | 664 | void docCreated(PwMDoc *document); |
659 | 665 | ||
660 | public: | 666 | public: |
661 | /** emit the dataChanged signal after checking for a lock */ | 667 | /** emit the dataChanged signal after checking for a lock */ |
662 | void emitDataChanged(PwMDoc *document) | 668 | void emitDataChanged(PwMDoc *document) |
663 | { | 669 | { |
664 | if (!dataChangedLock) | 670 | if (!dataChangedLock) |
665 | emit dataChanged(document); | 671 | emit dataChanged(document); |
666 | } | 672 | } |
667 | 673 | ||
668 | protected: | 674 | protected: |
669 | /** current file for this doc */ | 675 | /** current file for this doc */ |
670 | QString filename; | 676 | QString filename; |
671 | //US ENH: we need a place where we keep the syncentries. So I invented | 677 | //US ENH: we need a place where we keep the syncentries. So I invented |
672 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | 678 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem |
673 | /** holds all data */ | 679 | /** holds all data */ |
674 | PwMItem dti; | 680 | PwMItem dti; |
675 | /** maximum number of entries */ | 681 | /** maximum number of entries */ |
676 | unsigned int maxEntries; | 682 | unsigned int maxEntries; |
677 | /** currently used password to encrypt data */ | 683 | /** currently used password to encrypt data */ |
678 | QString currentPw; | 684 | QString currentPw; |
679 | /** current global document status flags */ | 685 | /** current global document status flags */ |
680 | unsigned int curDocStat; | 686 | unsigned int curDocStat; |
681 | /** browser process for goToURL() */ | 687 | /** browser process for goToURL() */ |
682 | KProcess browserProc; | 688 | KProcess browserProc; |
683 | /** pointer to the list-view, using this document. | 689 | /** pointer to the list-view, using this document. |
684 | * As there can only be one list-view per doc, we | 690 | * As there can only be one list-view per doc, we |
685 | * don't need a list here. | 691 | * don't need a list here. |
686 | */ | 692 | */ |
687 | PwMView *listView; | 693 | PwMView *listView; |
688 | /** unnamedNum is used to store the "unnamed counter" | 694 | /** unnamedNum is used to store the "unnamed counter" |
689 | * for this document, while it's unnamed. If it's 0, | 695 | * for this document, while it's unnamed. If it's 0, |
690 | * we have to get a new unique one. | 696 | * we have to get a new unique one. |
691 | */ | 697 | */ |
692 | unsigned int unnamedNum; | 698 | unsigned int unnamedNum; |
693 | /** is this doc going to be deleted (executing in destructor context) */ | 699 | /** is this doc going to be deleted (executing in destructor context) */ |
694 | bool deleted; | 700 | bool deleted; |
695 | /** document timer */ | 701 | /** document timer */ |
696 | DocTimer *_timer; | 702 | DocTimer *_timer; |
697 | /** lock counter for the "dataChanged" signal */ | 703 | /** lock counter for the "dataChanged" signal */ |
698 | unsigned int dataChangedLock; | 704 | unsigned int dataChangedLock; |
699 | 705 | ||
700 | /** list of all open documents */ | 706 | /** list of all open documents */ |
701 | static PwMDocList openDocList; | 707 | static PwMDocList openDocList; |
702 | 708 | ||
703 | protected: | 709 | protected: |
704 | /** serialize "dta" and return it in "d". */ | 710 | /** serialize "dta" and return it in "d". */ |
705 | bool serializeDta(string *d); | 711 | bool serializeDta(string *d); |
706 | /** de-serialize "d" and overwrite "dta" */ | 712 | /** de-serialize "d" and overwrite "dta" */ |
707 | bool deSerializeDta(const string *d, bool entriesLocked); | 713 | bool deSerializeDta(const string *d, bool entriesLocked); |
708 | /** write header to file */ | 714 | /** write header to file */ |
709 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 715 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
710 | QString *pw, QFile *f); | 716 | QString *pw, QFile *f); |
711 | /** write data-hash to file */ | 717 | /** write data-hash to file */ |
712 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 718 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
713 | /** check header. Read header info and verify key-hash and filever. | 719 | /** check header. Read header info and verify key-hash and filever. |
714 | * returns length of header in "headerLength" */ | 720 | * returns length of header in "headerLength" */ |
715 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 721 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
716 | unsigned int *headerLength, char *dataHashType, | 722 | unsigned int *headerLength, char *dataHashType, |
717 | string *dataHash, QFile *f); | 723 | string *dataHash, QFile *f); |
718 | /** check the data-hash */ | 724 | /** check the data-hash */ |
719 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 725 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
720 | /** encrypt data "d" and write to "filename" */ | 726 | /** encrypt data "d" and write to "filename" */ |
721 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 727 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
722 | /** read data from file beginning at "pos", decrypt and return it */ | 728 | /** read data from file beginning at "pos", decrypt and return it */ |
723 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); | 729 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); |
724 | /** compress the data */ | 730 | /** compress the data */ |
725 | bool compressDta(string *d, char algo); | 731 | bool compressDta(string *d, char algo); |
726 | /** uncompress the data */ | 732 | /** uncompress the data */ |
727 | bool decompressDta(string *d, char algo); | 733 | bool decompressDta(string *d, char algo); |
728 | /** internal import function for a text-file generated by PwM. | 734 | /** internal import function for a text-file generated by PwM. |
729 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 735 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
730 | PwMerror importText_PwM(const QString *file); | 736 | PwMerror importText_PwM(const QString *file); |
731 | /** PwM-text-import helper function to extract the name/pw/comment out | 737 | /** PwM-text-import helper function to extract the name/pw/comment out |
732 | * of one entry-line */ | 738 | * of one entry-line */ |
733 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 739 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
734 | /** compare two strings */ | 740 | /** compare two strings */ |
735 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 741 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
736 | bool exactWordMatch); | 742 | bool exactWordMatch); |
737 | /** clears all document-data */ | 743 | /** clears all document-data */ |
738 | void clearDoc(); | 744 | void clearDoc(); |
739 | /** delete all empty categories */ | 745 | /** delete all empty categories */ |
740 | void delAllEmptyCat(bool dontFlagDirty); | 746 | void delAllEmptyCat(bool dontFlagDirty); |
741 | /** set a document status flag */ | 747 | /** set a document status flag */ |
742 | void setDocStatFlag(unsigned int statFlag) | 748 | void setDocStatFlag(unsigned int statFlag) |
743 | { curDocStat |= statFlag; } | 749 | { curDocStat |= statFlag; } |
744 | /** unset a document status flag */ | 750 | /** unset a document status flag */ |
745 | void unsetDocStatFlag(unsigned int statFlag) | 751 | void unsetDocStatFlag(unsigned int statFlag) |
746 | { curDocStat &= ~statFlag; } | 752 | { curDocStat &= ~statFlag; } |
747 | /** get a document status flag */ | 753 | /** get a document status flag */ |
748 | bool getDocStatFlag(unsigned int statFlag) const | 754 | bool getDocStatFlag(unsigned int statFlag) const |
749 | { return (curDocStat & statFlag); } | 755 | { return (curDocStat & statFlag); } |
750 | /** set the "currentPassword" */ | 756 | /** set the "currentPassword" */ |
751 | void setCurrentPw(const QString &pw) | 757 | void setCurrentPw(const QString &pw) |
752 | { | 758 | { |
753 | currentPw = pw; | 759 | currentPw = pw; |
754 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 760 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
755 | } | 761 | } |
756 | /** make a backup-copy of the given file */ | 762 | /** make a backup-copy of the given file */ |
757 | bool backupFile(const QString &filePath); | 763 | bool backupFile(const QString &filePath); |
758 | /** copy a file from src to dst */ | 764 | /** copy a file from src to dst */ |
759 | bool copyFile(const QString &src, const QString &dst); | 765 | bool copyFile(const QString &src, const QString &dst); |
760 | 766 | ||
761 | 767 | ||
762 | public: | 768 | public: |
763 | #ifdef PWM_EMBEDDED | 769 | #ifdef PWM_EMBEDDED |
764 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 770 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
765 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 771 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
766 | 772 | ||
767 | //takePwMDataItem returns the following values | 773 | //takePwMDataItem returns the following values |
768 | // 0 equal | 774 | // 0 equal |
769 | // 1 take local | 775 | // 1 take local |
770 | // 2 take remote | 776 | // 2 take remote |
771 | // 3 cancel | 777 | // 3 cancel |
772 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | 778 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); |
773 | 779 | ||
774 | //the following methods are the overwritten callbackmethods from the syncinterface | 780 | //the following methods are the overwritten callbackmethods from the syncinterface |
775 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 781 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
776 | 782 | ||
777 | //called by the syncmanager to indicate that the work has to be marked as dirty. | ||
778 | virtual void sync_setModified(); | ||
779 | //called by the syncmanager to ask if the dirty flag is set. | ||
780 | virtual bool sync_isModified(); | ||
781 | //called by the syncmanager to indicate that the work has to be saved. | ||
782 | virtual void sync_save(); | ||
783 | |||
784 | #endif | 783 | #endif |
785 | private: | 784 | private: |
786 | //US ENH: helpermethods to access the sync data for a certain syncname. | 785 | //US ENH: helpermethods to access the sync data for a certain syncname. |
787 | // It returns the syncdatas index | 786 | // It returns the syncdatas index |
788 | bool findSyncData(const QString &syncname, unsigned int *index); | 787 | bool findSyncData(const QString &syncname, unsigned int *index); |
789 | 788 | ||
790 | /** add new syncdataentry */ | 789 | /** add new syncdataentry */ |
791 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 790 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
792 | 791 | ||
793 | /** returns a pointer to the syncdata */ | 792 | /** returns a pointer to the syncdata */ |
794 | PwMSyncItem* getSyncDataEntry(unsigned int index) | 793 | PwMSyncItem* getSyncDataEntry(unsigned int index) |
795 | { return &(dti.syncDta[index]); } | 794 | { return &(dti.syncDta[index]); } |
796 | 795 | ||
797 | /** delete entry */ | 796 | /** delete entry */ |
798 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 797 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
799 | 798 | ||
800 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 799 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
801 | 800 | ||
802 | QStringList getIDEntryList(); | 801 | QStringList getIDEntryList(); |
803 | 802 | ||
804 | }; | 803 | }; |
805 | 804 | ||
806 | #endif | 805 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index e23ce25..e53124f 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,524 +1,604 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmview.h" | 20 | #include "pwmview.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "globalstuff.h" | 22 | #include "globalstuff.h" |
23 | #include "pwm.h" | 23 | #include "pwm.h" |
24 | #include "rencatwnd.h" | 24 | #include "rencatwnd.h" |
25 | #ifndef PWM_EMBEDDED | 25 | #ifndef PWM_EMBEDDED |
26 | #include "configuration.h" | 26 | #include "configuration.h" |
27 | #else | 27 | #else |
28 | #include "pwmprefs.h" | 28 | #include "pwmprefs.h" |
29 | #endif | 29 | #endif |
30 | #include "commentbox.h" | 30 | #include "commentbox.h" |
31 | 31 | ||
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qpoint.h> | 36 | #include <qpoint.h> |
37 | #include <qapplication.h> | 37 | #include <qapplication.h> |
38 | #include <qlayout.h> | 38 | #include <qlayout.h> |
39 | 39 | ||
40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
41 | //US ENH: for examle in listviewpwm.cpp | 41 | //US ENH: for examle in listviewpwm.cpp |
42 | //US ENH: Because of that I transfer them into the headerfile. | 42 | //US ENH: Because of that I transfer them into the headerfile. |
43 | /* | 43 | /* |
44 | #define COLUMN_DESC 0 | 44 | #define COLUMN_DESC 0 |
45 | #define COLUMN_NAME 1 | 45 | #define COLUMN_NAME 1 |
46 | #define COLUMN_PW 2 | 46 | #define COLUMN_PW 2 |
47 | #define COLUMN_URL 3 | 47 | #define COLUMN_URL 3 |
48 | #define COLUMN_LAUNCHER 4 | 48 | #define COLUMN_LAUNCHER 4 |
49 | */ | 49 | */ |
50 | 50 | ||
51 | PwMView::PwMView(PwM *_mainClass, | 51 | PwMView::PwMView(PwM *_mainClass, |
52 | QWidget *parent, PwMDoc *_doc, | 52 | QWidget *parent, PwMDoc *_doc, |
53 | const char *name) | 53 | const char *name) |
54 | : PwMViewStyle(parent, name) | 54 | : PwMViewStyle(parent, name) |
55 | { | 55 | { |
56 | PWM_ASSERT(_mainClass); | 56 | PWM_ASSERT(_mainClass); |
57 | PWM_ASSERT(parent); | 57 | PWM_ASSERT(parent); |
58 | PWM_ASSERT(_doc); | 58 | PWM_ASSERT(_doc); |
59 | setView(this); | 59 | setView(this); |
60 | doc = _doc; | 60 | doc = _doc; |
61 | doc->setListViewPointer(this); | 61 | doc->setListViewPointer(this); |
62 | mainClass = _mainClass; | 62 | mainClass = _mainClass; |
63 | resize(_mainClass->size()); | 63 | resize(_mainClass->size()); |
64 | initStyle(conf()->confWndMainViewStyle()); | 64 | initStyle(conf()->confWndMainViewStyle()); |
65 | initCtxMenu(); | 65 | initCtxMenu(); |
66 | doc->setCurrentView(this); | 66 | doc->setCurrentView(this); |
67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); | 67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); |
68 | } | 68 | } |
69 | 69 | ||
70 | PwMView::~PwMView() | 70 | PwMView::~PwMView() |
71 | { | 71 | { |
72 | } | 72 | } |
73 | 73 | ||
74 | void PwMView::initCtxMenu() | 74 | void PwMView::initCtxMenu() |
75 | { | 75 | { |
76 | ctxMenu = new QPopupMenu(this); | 76 | ctxMenu = new QPopupMenu(this); |
77 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); | 77 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); |
78 | ctxMenu->insertSeparator(); | 78 | ctxMenu->insertSeparator(); |
79 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); | 79 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); |
80 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); | 80 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); |
81 | ctxMenu->insertSeparator(); | 81 | ctxMenu->insertSeparator(); |
82 | ctxMenu->insertItem(i18n("copy password to clipboard"), | 82 | ctxMenu->insertItem(i18n("copy password to clipboard"), |
83 | this, SLOT(copyPwToClip())); | 83 | this, SLOT(copyPwToClip())); |
84 | ctxMenu->insertItem(i18n("copy username to clipboard"), | 84 | ctxMenu->insertItem(i18n("copy username to clipboard"), |
85 | this, SLOT(copyNameToClip())); | 85 | this, SLOT(copyNameToClip())); |
86 | ctxMenu->insertItem(i18n("copy description to clipboard"), | 86 | ctxMenu->insertItem(i18n("copy description to clipboard"), |
87 | this, SLOT(copyDescToClip())); | 87 | this, SLOT(copyDescToClip())); |
88 | ctxMenu->insertItem(i18n("copy url to clipboard"), | 88 | ctxMenu->insertItem(i18n("copy url to clipboard"), |
89 | this, SLOT(copyUrlToClip())); | 89 | this, SLOT(copyUrlToClip())); |
90 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), | 90 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), |
91 | this, SLOT(copyLauncherToClip())); | 91 | this, SLOT(copyLauncherToClip())); |
92 | ctxMenu->insertItem(i18n("copy comment to clipboard"), | 92 | ctxMenu->insertItem(i18n("copy comment to clipboard"), |
93 | this, SLOT(copyCommentToClip())); | 93 | this, SLOT(copyCommentToClip())); |
94 | ctxMenu->insertSeparator(); | 94 | ctxMenu->insertSeparator(); |
95 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, | 95 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, |
96 | SLOT(execLauncher_slot())); | 96 | SLOT(execLauncher_slot())); |
97 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, | 97 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, |
98 | SLOT(goToURL_slot())); | 98 | SLOT(goToURL_slot())); |
99 | } | 99 | } |
100 | 100 | ||
101 | void PwMView::resizeEvent(QResizeEvent *) | 101 | void PwMView::resizeEvent(QResizeEvent *) |
102 | { | 102 | { |
103 | resizeView(size()); | 103 | resizeView(size()); |
104 | } | 104 | } |
105 | 105 | ||
106 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) | 106 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) |
107 | { | 107 | { |
108 | PWM_ASSERT(commentBox); | 108 | PWM_ASSERT(commentBox); |
109 | if (!curItem) | 109 | if (!curItem) |
110 | return; | 110 | return; |
111 | string comment; | 111 | string comment; |
112 | PwMerror ret; | 112 | PwMerror ret; |
113 | ret = document()->getCommentByLvp(getCurrentCategory(), | 113 | ret = document()->getCommentByLvp(getCurrentCategory(), |
114 | lv->childCount() - lv->itemIndex(curItem) - 1, | 114 | lv->childCount() - lv->itemIndex(curItem) - 1, |
115 | &comment); | 115 | &comment); |
116 | if (ret == e_binEntry) { | 116 | if (ret == e_binEntry) { |
117 | commentBox->setContent(i18n("This is a binary entry.\n" | 117 | commentBox->setContent(i18n("This is a binary entry.\n" |
118 | "It is not a normal password-entry, as it contains " | 118 | "It is not a normal password-entry, as it contains " |
119 | "binary data, which PwManager can't display here.")); | 119 | "binary data, which PwManager can't display here.")); |
120 | } else if (ret == e_normalEntry) { | 120 | } else if (ret == e_normalEntry) { |
121 | commentBox->setContent(comment.c_str()); | 121 | commentBox->setContent(comment.c_str()); |
122 | } else { | 122 | } else { |
123 | BUG(); | 123 | BUG(); |
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | lv->ensureItemVisible(curItem); | 126 | lv->ensureItemVisible(curItem); |
127 | } | 127 | } |
128 | 128 | ||
129 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) | 129 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) |
130 | { | 130 | { |
131 | refreshCommentTextEdit(lv->currentItem()); | 131 | refreshCommentTextEdit(lv->currentItem()); |
132 | } | 132 | } |
133 | 133 | ||
134 | bool PwMView::getCurEntryIndex(unsigned int *index) | 134 | bool PwMView::getCurEntryIndex(unsigned int *index) |
135 | { | 135 | { |
136 | QListViewItem *current = lv->currentItem(); | 136 | QListViewItem *current = lv->currentItem(); |
137 | if (!current) | 137 | if (!current) |
138 | return false; | 138 | return false; |
139 | return getDocEntryIndex(index, current); | 139 | return getDocEntryIndex(index, current); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool PwMView::getDocEntryIndex(unsigned int *index, | 142 | bool PwMView::getDocEntryIndex(unsigned int *index, |
143 | const QListViewItem *item) | 143 | const QListViewItem *item) |
144 | { | 144 | { |
145 | vector<unsigned int> foundPositions; | 145 | vector<unsigned int> foundPositions; |
146 | PwMDataItem curItem; | 146 | PwMDataItem curItem; |
147 | curItem.desc = item->text(COLUMN_DESC).latin1(); | 147 | curItem.desc = item->text(COLUMN_DESC).latin1(); |
148 | curItem.name = item->text(COLUMN_NAME).latin1(); | 148 | curItem.name = item->text(COLUMN_NAME).latin1(); |
149 | document()->getCommentByLvp(getCurrentCategory(), | 149 | document()->getCommentByLvp(getCurrentCategory(), |
150 | lv->childCount() - lv->itemIndex(item) - 1, | 150 | lv->childCount() - lv->itemIndex(item) - 1, |
151 | &curItem.comment); | 151 | &curItem.comment); |
152 | curItem.url = item->text(COLUMN_URL).latin1(); | 152 | curItem.url = item->text(COLUMN_URL).latin1(); |
153 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); | 153 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); |
154 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | | 154 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | |
155 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | | 155 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | |
156 | SEARCH_IN_LAUNCHER, | 156 | SEARCH_IN_LAUNCHER, |
157 | &foundPositions, true); | 157 | &foundPositions, true); |
158 | if (foundPositions.size()) { | 158 | if (foundPositions.size()) { |
159 | *index = foundPositions[0]; | 159 | *index = foundPositions[0]; |
160 | return true; | 160 | return true; |
161 | } | 161 | } |
162 | 162 | ||
163 | return false; | 163 | return false; |
164 | } | 164 | } |
165 | 165 | ||
166 | void PwMView::handleToggle(QListViewItem *item) | 166 | void PwMView::handleToggle(QListViewItem *item) |
167 | { | 167 | { |
168 | PWM_ASSERT(doc); | 168 | PWM_ASSERT(doc); |
169 | if (!item) | 169 | if (!item) |
170 | return; | 170 | return; |
171 | QCheckListItem *clItem = (QCheckListItem *)item; | 171 | QCheckListItem *clItem = (QCheckListItem *)item; |
172 | QString curCat(getCurrentCategory()); | 172 | QString curCat(getCurrentCategory()); |
173 | 173 | ||
174 | // find document position of this entry. | 174 | // find document position of this entry. |
175 | unsigned int curEntryDocIndex; | 175 | unsigned int curEntryDocIndex; |
176 | if (!getDocEntryIndex(&curEntryDocIndex, item)) | 176 | if (!getDocEntryIndex(&curEntryDocIndex, item)) |
177 | return; | 177 | return; |
178 | 178 | ||
179 | // hack to refresh the comment, if only one item is present | 179 | // hack to refresh the comment, if only one item is present |
180 | if (lv->childCount() == 1) | 180 | if (lv->childCount() == 1) |
181 | refreshCommentTextEdit(lv->currentItem()); | 181 | refreshCommentTextEdit(lv->currentItem()); |
182 | 182 | ||
183 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) | 183 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) |
184 | return; // this is just a click somewhere on the entry | 184 | return; // this is just a click somewhere on the entry |
185 | if (doc->isDeepLocked()) { | 185 | if (doc->isDeepLocked()) { |
186 | PwMerror ret; | 186 | PwMerror ret; |
187 | ret = doc->deepLock(false); | 187 | ret = doc->deepLock(false); |
188 | if (ret != e_success) | 188 | if (ret != e_success) |
189 | clItem->setOn(false); | 189 | clItem->setOn(false); |
190 | return; | 190 | return; |
191 | } | 191 | } |
192 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); | 192 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); |
193 | } | 193 | } |
194 | 194 | ||
195 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) | 195 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) |
196 | { | 196 | { |
197 | if (!item) | 197 | if (!item) |
198 | return; | 198 | return; |
199 | ctxMenu->move(point); | 199 | ctxMenu->move(point); |
200 | /* don't use ctxMenu->exec() here, as it generates race conditions | 200 | /* don't use ctxMenu->exec() here, as it generates race conditions |
201 | * with the card interface code. Believe it or not. :) | 201 | * with the card interface code. Believe it or not. :) |
202 | */ | 202 | */ |
203 | ctxMenu->show(); | 203 | ctxMenu->show(); |
204 | } | 204 | } |
205 | 205 | ||
206 | void PwMView::updateCategories() | 206 | void PwMView::updateCategories() |
207 | { | 207 | { |
208 | QString oldSel(getCurrentCategory()); | 208 | QString oldSel(getCurrentCategory()); |
209 | delAllCategories(); | 209 | delAllCategories(); |
210 | QStringList catList; | 210 | QStringList catList; |
211 | document()->getCategoryList(&catList); | 211 | document()->getCategoryList(&catList); |
212 | catList.sort(); | 212 | catList.sort(); |
213 | #ifndef PWM_EMBEDDED | 213 | #ifndef PWM_EMBEDDED |
214 | QStringList::iterator i = catList.begin(), | 214 | QStringList::iterator i = catList.begin(), |
215 | end = catList.end(); | 215 | end = catList.end(); |
216 | #else | 216 | #else |
217 | QStringList::Iterator i = catList.begin(), | 217 | QStringList::Iterator i = catList.begin(), |
218 | end = catList.end(); | 218 | end = catList.end(); |
219 | #endif | 219 | #endif |
220 | while (i != end) { | 220 | while (i != end) { |
221 | addCategory(*i); | 221 | addCategory(*i); |
222 | ++i; | 222 | ++i; |
223 | } | 223 | } |
224 | selectCategory(oldSel); | 224 | selectCategory(oldSel); |
225 | } | 225 | } |
226 | 226 | ||
227 | void PwMView::shiftToView() | 227 | void PwMView::shiftToView() |
228 | { | 228 | { |
229 | int cX = lv->contentsX(); | 229 | int cX = lv->contentsX(); |
230 | int cY = lv->contentsY(); | 230 | int cY = lv->contentsY(); |
231 | commentBox->clear(); | 231 | commentBox->clear(); |
232 | 232 | ||
233 | unsigned int catDocIndex; | 233 | unsigned int catDocIndex; |
234 | if (unlikely( | 234 | if (unlikely( |
235 | !(document()->findCategory(getCurrentCategory(), | 235 | !(document()->findCategory(getCurrentCategory(), |
236 | &catDocIndex)))) { | 236 | &catDocIndex)))) { |
237 | BUG(); | 237 | BUG(); |
238 | } | 238 | } |
239 | 239 | ||
240 | // ensure all listViewPos are set | 240 | // ensure all listViewPos are set |
241 | doc->ensureLvp(); | 241 | doc->ensureLvp(); |
242 | 242 | ||
243 | // clear all tmp-data vectors | 243 | // clear all tmp-data vectors |
244 | unsigned int i, entries = doc->numEntries(catDocIndex); | 244 | unsigned int i, entries = doc->numEntries(catDocIndex); |
245 | if (entries) { | 245 | if (entries) { |
246 | mainClass->setVirgin(false); | 246 | mainClass->setVirgin(false); |
247 | } | 247 | } |
248 | vector<PwMDataItem> tmpSorted; | 248 | vector<PwMDataItem> tmpSorted; |
249 | PwMDataItem currItem; | 249 | PwMDataItem currItem; |
250 | currItem.clear(); | 250 | currItem.clear(); |
251 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); | 251 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); |
252 | 252 | ||
253 | // Sort items and store them in tempoary tmpSorted. | 253 | // Sort items and store them in tempoary tmpSorted. |
254 | for (i = 0; i < entries; ++i) { | 254 | for (i = 0; i < entries; ++i) { |
255 | doc->getEntry(catDocIndex, i, &currItem); | 255 | doc->getEntry(catDocIndex, i, &currItem); |
256 | tmpSorted[currItem.listViewPos] = currItem; | 256 | tmpSorted[currItem.listViewPos] = currItem; |
257 | } | 257 | } |
258 | 258 | ||
259 | // shift tempoary data to ListView. | 259 | // shift tempoary data to ListView. |
260 | tmpDisableSort(); | 260 | tmpDisableSort(); |
261 | lv->clear(); | 261 | lv->clear(); |
262 | QCheckListItem *newItem; | 262 | QCheckListItem *newItem; |
263 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), | 263 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), |
264 | end = tmpSorted.end(); | 264 | end = tmpSorted.end(); |
265 | while (it != end) { | 265 | while (it != end) { |
266 | newItem = new ListViewItemPwM(lv); | 266 | newItem = new ListViewItemPwM(lv); |
267 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 267 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
268 | if ((*it).binary) { | 268 | if ((*it).binary) { |
269 | newItem->setText(COLUMN_NAME, ""); | 269 | newItem->setText(COLUMN_NAME, ""); |
270 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 270 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
271 | newItem->setText(COLUMN_URL, ""); | 271 | newItem->setText(COLUMN_URL, ""); |
272 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 272 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
273 | } else { | 273 | } else { |
274 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 274 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
275 | if ((*it).lockStat) { | 275 | if ((*it).lockStat) { |
276 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 276 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
277 | + " " | 277 | + " " |
278 | + i18n("To unlock click the icon on the left.")); | 278 | + i18n("To unlock click the icon on the left.")); |
279 | } else { | 279 | } else { |
280 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 280 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
281 | } | 281 | } |
282 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 282 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
283 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 283 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
284 | } | 284 | } |
285 | newItem->setOn(!((*it).lockStat)); | 285 | newItem->setOn(!((*it).lockStat)); |
286 | lv->insertItem(newItem); | 286 | lv->insertItem(newItem); |
287 | ++it; | 287 | ++it; |
288 | } | 288 | } |
289 | tmpReEnableSort(); | 289 | tmpReEnableSort(); |
290 | 290 | ||
291 | if (cY || cX) | 291 | if (cY || cX) |
292 | lv->setContentsPos(cX, cY); | 292 | lv->setContentsPos(cX, cY); |
293 | } | 293 | } |
294 | 294 | ||
295 | void PwMView::reorgLp() | 295 | void PwMView::reorgLp() |
296 | { | 296 | { |
297 | if (!lv->childCount()) | 297 | if (!lv->childCount()) |
298 | return; | 298 | return; |
299 | PWM_ASSERT(doc); | 299 | PWM_ASSERT(doc); |
300 | PWM_ASSERT(!doc->isDocEmpty()); | 300 | PWM_ASSERT(!doc->isDocEmpty()); |
301 | QListViewItem *currItem; | 301 | QListViewItem *currItem; |
302 | vector<unsigned int> foundPos; | 302 | vector<unsigned int> foundPos; |
303 | /* This searchIn _should_ be: | 303 | /* This searchIn _should_ be: |
304 | *const unsigned int searchIn = SEARCH_IN_DESC; | 304 | *const unsigned int searchIn = SEARCH_IN_DESC; |
305 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 305 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
306 | * So we need to search again, if we don't find the entry. (see below) | 306 | * So we need to search again, if we don't find the entry. (see below) |
307 | */ | 307 | */ |
308 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 308 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
309 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 309 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
310 | QString curCat(getCurrentCategory()); | 310 | QString curCat(getCurrentCategory()); |
311 | PwMDataItem findThis; | 311 | PwMDataItem findThis; |
312 | unsigned int i, cnt = lv->childCount(); | 312 | unsigned int i, cnt = lv->childCount(); |
313 | for (i = 0; i < cnt; ++i) { | 313 | for (i = 0; i < cnt; ++i) { |
314 | currItem = lv->itemAtIndex(i); | 314 | currItem = lv->itemAtIndex(i); |
315 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 315 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
316 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 316 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
317 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 317 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
318 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 318 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
319 | doc->findEntry(curCat, findThis, searchIn, | 319 | doc->findEntry(curCat, findThis, searchIn, |
320 | &foundPos, true); | 320 | &foundPos, true); |
321 | if (!foundPos.size()) { | 321 | if (!foundPos.size()) { |
322 | /* Did not find the entry. We seem to have a binary | 322 | /* Did not find the entry. We seem to have a binary |
323 | * entry here (pray for it!). So search again with | 323 | * entry here (pray for it!). So search again with |
324 | * the "correct" searchIn flags. | 324 | * the "correct" searchIn flags. |
325 | */ | 325 | */ |
326 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 326 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
327 | doc->findEntry(curCat, findThis, searchIn2, | 327 | doc->findEntry(curCat, findThis, searchIn2, |
328 | &foundPos, true); | 328 | &foundPos, true); |
329 | if (unlikely(!foundPos.size())) { | 329 | if (unlikely(!foundPos.size())) { |
330 | BUG(); | 330 | BUG(); |
331 | continue; | 331 | continue; |
332 | } | 332 | } |
333 | /* We assert that it's a binary entry, now. | 333 | /* We assert that it's a binary entry, now. |
334 | * No chance to efficiently verify it here. | 334 | * No chance to efficiently verify it here. |
335 | */ | 335 | */ |
336 | } | 336 | } |
337 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 337 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | void PwMView::selAt(int index) | 341 | void PwMView::selAt(int index) |
342 | { | 342 | { |
343 | QListViewItem *item = lv->itemAtIndex(index); | 343 | QListViewItem *item = lv->itemAtIndex(index); |
344 | if (!item) | 344 | if (!item) |
345 | return; | 345 | return; |
346 | lv->setCurrentItem(item); | 346 | lv->setCurrentItem(item); |
347 | lv->ensureItemVisible(item); | 347 | lv->ensureItemVisible(item); |
348 | } | 348 | } |
349 | 349 | ||
350 | void PwMView::renCatButton_slot() | 350 | void PwMView::renCatButton_slot() |
351 | { | 351 | { |
352 | if (doc->isDeepLocked()) | 352 | if (doc->isDeepLocked()) |
353 | return; | 353 | return; |
354 | RenCatWnd wnd(this); | 354 | RenCatWnd wnd(this); |
355 | if (wnd.exec() == 1) { | 355 | if (wnd.exec() == 1) { |
356 | QString newName(wnd.getNewName()); | 356 | QString newName(wnd.getNewName()); |
357 | if (newName == "") | 357 | if (newName == "") |
358 | return; | 358 | return; |
359 | document()->renameCategory(getCurrentCategory(), | 359 | document()->renameCategory(getCurrentCategory(), |
360 | newName); | 360 | newName); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | void PwMView::delCatButton_slot() | 364 | void PwMView::delCatButton_slot() |
365 | { | 365 | { |
366 | if (doc->isDeepLocked()) | 366 | if (doc->isDeepLocked()) |
367 | return; | 367 | return; |
368 | if (numCategories() <= 1) { | 368 | if (numCategories() <= 1) { |
369 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 369 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
370 | return; | 370 | return; |
371 | } | 371 | } |
372 | if (KMessageBox::questionYesNo(this, | 372 | if (KMessageBox::questionYesNo(this, |
373 | i18n("Do you really want to\n" | 373 | i18n("Do you really want to\n" |
374 | "delete the selected\n" | 374 | "delete the selected\n" |
375 | "category? All password-\n" | 375 | "category? All password-\n" |
376 | "entries will be lost in\n" | 376 | "entries will be lost in\n" |
377 | "this category!\n"), | 377 | "this category!\n"), |
378 | i18n("Delete category?")) | 378 | i18n("Delete category?")) |
379 | == KMessageBox::No) { | 379 | == KMessageBox::No) { |
380 | return; | 380 | return; |
381 | } | 381 | } |
382 | document()->delCategory(getCurrentCategory()); | 382 | document()->delCategory(getCurrentCategory()); |
383 | } | 383 | } |
384 | 384 | ||
385 | void PwMView::copyPwToClip() | 385 | void PwMView::copyPwToClip() |
386 | { | 386 | { |
387 | if (doc->isDeepLocked()) | 387 | if (doc->isDeepLocked()) |
388 | return; | 388 | return; |
389 | unsigned int curIndex = 0; | 389 | unsigned int curIndex = 0; |
390 | if (!getCurEntryIndex(&curIndex)) | 390 | if (!getCurEntryIndex(&curIndex)) |
391 | return; | 391 | return; |
392 | PwMDataItem d; | 392 | PwMDataItem d; |
393 | document()->getDataChangedLock(); | 393 | document()->getDataChangedLock(); |
394 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 394 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
395 | document()->putDataChangedLock(); | 395 | document()->putDataChangedLock(); |
396 | PwM::copyToClipboard(d.pw.c_str()); | 396 | PwM::copyToClipboard(d.pw.c_str()); |
397 | } | 397 | } |
398 | 398 | ||
399 | void PwMView::copyNameToClip() | 399 | void PwMView::copyNameToClip() |
400 | { | 400 | { |
401 | if (doc->isDeepLocked()) | 401 | if (doc->isDeepLocked()) |
402 | return; | 402 | return; |
403 | unsigned int curIndex = 0; | 403 | unsigned int curIndex = 0; |
404 | if (!getCurEntryIndex(&curIndex)) | 404 | if (!getCurEntryIndex(&curIndex)) |
405 | return; | 405 | return; |
406 | PwMDataItem d; | 406 | PwMDataItem d; |
407 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 407 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
408 | PwM::copyToClipboard(d.name.c_str()); | 408 | PwM::copyToClipboard(d.name.c_str()); |
409 | } | 409 | } |
410 | 410 | ||
411 | void PwMView::copyDescToClip() | 411 | void PwMView::copyDescToClip() |
412 | { | 412 | { |
413 | if (doc->isDeepLocked()) | 413 | if (doc->isDeepLocked()) |
414 | return; | 414 | return; |
415 | unsigned int curIndex = 0; | 415 | unsigned int curIndex = 0; |
416 | if (!getCurEntryIndex(&curIndex)) | 416 | if (!getCurEntryIndex(&curIndex)) |
417 | return; | 417 | return; |
418 | PwMDataItem d; | 418 | PwMDataItem d; |
419 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 419 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
420 | PwM::copyToClipboard(d.desc.c_str()); | 420 | PwM::copyToClipboard(d.desc.c_str()); |
421 | } | 421 | } |
422 | 422 | ||
423 | void PwMView::copyUrlToClip() | 423 | void PwMView::copyUrlToClip() |
424 | { | 424 | { |
425 | if (doc->isDeepLocked()) | 425 | if (doc->isDeepLocked()) |
426 | return; | 426 | return; |
427 | unsigned int curIndex = 0; | 427 | unsigned int curIndex = 0; |
428 | if (!getCurEntryIndex(&curIndex)) | 428 | if (!getCurEntryIndex(&curIndex)) |
429 | return; | 429 | return; |
430 | PwMDataItem d; | 430 | PwMDataItem d; |
431 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 431 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
432 | PwM::copyToClipboard(d.url.c_str()); | 432 | PwM::copyToClipboard(d.url.c_str()); |
433 | } | 433 | } |
434 | 434 | ||
435 | void PwMView::copyLauncherToClip() | 435 | void PwMView::copyLauncherToClip() |
436 | { | 436 | { |
437 | if (doc->isDeepLocked()) | 437 | if (doc->isDeepLocked()) |
438 | return; | 438 | return; |
439 | unsigned int curIndex = 0; | 439 | unsigned int curIndex = 0; |
440 | if (!getCurEntryIndex(&curIndex)) | 440 | if (!getCurEntryIndex(&curIndex)) |
441 | return; | 441 | return; |
442 | PwMDataItem d; | 442 | PwMDataItem d; |
443 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 443 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
444 | PwM::copyToClipboard(d.launcher.c_str()); | 444 | PwM::copyToClipboard(d.launcher.c_str()); |
445 | } | 445 | } |
446 | 446 | ||
447 | void PwMView::copyCommentToClip() | 447 | void PwMView::copyCommentToClip() |
448 | { | 448 | { |
449 | if (doc->isDeepLocked()) | 449 | if (doc->isDeepLocked()) |
450 | return; | 450 | return; |
451 | unsigned int curIndex = 0; | 451 | unsigned int curIndex = 0; |
452 | if (!getCurEntryIndex(&curIndex)) | 452 | if (!getCurEntryIndex(&curIndex)) |
453 | return; | 453 | return; |
454 | PwMDataItem d; | 454 | PwMDataItem d; |
455 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 455 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
456 | PwM::copyToClipboard(d.comment.c_str()); | 456 | PwM::copyToClipboard(d.comment.c_str()); |
457 | } | 457 | } |
458 | 458 | ||
459 | /************************************************************************ | ||
460 | * | ||
461 | * | ||
462 | * | ||
463 | ************************************************************************/ | ||
464 | |||
465 | |||
466 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) | ||
467 | : QTextBrowser( parent, name ) | ||
468 | |||
469 | |||
470 | { | ||
471 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); | ||
472 | setLinkUnderline( false ); | ||
473 | // setVScrollBarMode( QScrollView::AlwaysOff ); | ||
474 | //setHScrollBarMode( QScrollView::AlwaysOff ); | ||
475 | |||
476 | //US QStyleSheet *sheet = styleSheet(); | ||
477 | //US QStyleSheetItem *link = sheet->item( "a" ); | ||
478 | //US link->setColor( KGlobalSettings::linkColor() ); | ||
479 | |||
480 | } | ||
481 | |||
482 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) | ||
483 | |||
484 | { | ||
485 | mItem = a; | ||
486 | // clear view | ||
487 | setText( QString::null ); | ||
488 | |||
489 | |||
490 | QString dynamicPart; | ||
491 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" | ||
492 | "<td align=\"left\">%2</td></tr>"; | ||
493 | |||
494 | dynamicPart += format | ||
495 | .arg( i18n("Description") ) | ||
496 | .arg( mItem.desc.c_str() ); | ||
459 | 497 | ||
498 | dynamicPart += format | ||
499 | .arg( i18n("Name") ) | ||
500 | .arg( mItem.name.c_str() ); | ||
501 | |||
502 | dynamicPart += format | ||
503 | .arg( i18n("Password") ) | ||
504 | .arg( mItem.pw.c_str() ); | ||
505 | |||
506 | QString comment(mItem.pw.c_str()); | ||
507 | dynamicPart += format | ||
508 | .arg( i18n("Comment") ) | ||
509 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); | ||
510 | |||
511 | dynamicPart += format | ||
512 | .arg( i18n("URL") ) | ||
513 | .arg( mItem.url.c_str() ); | ||
514 | |||
515 | dynamicPart += format | ||
516 | .arg( i18n("Launcher") ) | ||
517 | .arg( mItem.launcher.c_str() ); | ||
518 | |||
519 | QString mText = "<table><td colspan=\"2\"> </td>"; | ||
520 | |||
521 | mText += dynamicPart; | ||
522 | mText += "</table>"; | ||
523 | |||
524 | // at last display it... | ||
525 | setText( mText ); | ||
526 | |||
527 | } | ||
528 | |||
529 | PwMDataItem PwMDataItemView::pwmdataitem() const | ||
530 | { | ||
531 | return mItem; | ||
532 | } | ||
533 | |||
534 | /************************************************************************ | ||
535 | * | ||
536 | * | ||
537 | * | ||
538 | ************************************************************************/ | ||
460 | 539 | ||
461 | 540 | ||
462 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, | 541 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) |
463 | true ,i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | 542 | : KDialogBase(parent, name, true , |
543 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | ||
464 | { | 544 | { |
465 | findButton( Close )->setText( i18n("Cancel Sync")); | 545 | findButton( Close )->setText( i18n("Cancel Sync")); |
466 | findButton( Ok )->setText( i18n("Remote")); | 546 | findButton( Ok )->setText( i18n("Remote")); |
467 | findButton( User1 )->setText( i18n("Local")); | 547 | findButton( User1 )->setText( i18n("Local")); |
468 | QWidget* topframe = new QWidget( this ); | 548 | QWidget* topframe = new QWidget( this ); |
469 | setMainWidget( topframe ); | 549 | setMainWidget( topframe ); |
470 | QBoxLayout* bl; | 550 | QBoxLayout* bl; |
471 | if ( QApplication::desktop()->width() < 640 ) { | 551 | if ( QApplication::desktop()->width() < 640 ) { |
472 | bl = new QVBoxLayout( topframe ); | 552 | bl = new QVBoxLayout( topframe ); |
473 | } else { | 553 | } else { |
474 | bl = new QHBoxLayout( topframe ); | 554 | bl = new QHBoxLayout( topframe ); |
475 | } | 555 | } |
476 | QVBox* subframe = new QVBox( topframe ); | 556 | QVBox* subframe = new QVBox( topframe ); |
477 | bl->addWidget(subframe ); | 557 | bl->addWidget(subframe ); |
478 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | 558 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); |
479 | if ( takeloc ) | 559 | if ( takeloc ) |
480 | lab->setBackgroundColor(Qt::green.light() ); | 560 | lab->setBackgroundColor(Qt::green.light() ); |
481 | // AddresseeView * av = new AddresseeView( subframe ); | 561 | PwMDataItemView * av = new PwMDataItemView( subframe ); |
482 | // av->setAddressee( loc ); | 562 | av->setPwMDataItem( loc ); |
483 | subframe = new QVBox( topframe ); | 563 | subframe = new QVBox( topframe ); |
484 | bl->addWidget(subframe ); | 564 | bl->addWidget(subframe ); |
485 | lab = new QLabel( i18n("Remote Entry"), subframe ); | 565 | lab = new QLabel( i18n("Remote Entry"), subframe ); |
486 | if ( !takeloc ) | 566 | if ( !takeloc ) |
487 | lab->setBackgroundColor(Qt::green.light() ); | 567 | lab->setBackgroundColor(Qt::green.light() ); |
488 | // av = new AddresseeView( subframe ); | 568 | av = new PwMDataItemView( subframe ); |
489 | // av->setAddressee( rem ); | 569 | av->setPwMDataItem( rem ); |
490 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | 570 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); |
491 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | 571 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); |
492 | #ifndef DESKTOP_VERSION | 572 | #ifndef DESKTOP_VERSION |
493 | showMaximized(); | 573 | showMaximized(); |
494 | #else | 574 | #else |
495 | resize ( 640, 400 ); | 575 | resize ( 640, 400 ); |
496 | #endif | 576 | #endif |
497 | } | 577 | } |
498 | 578 | ||
499 | int PwMDataItemChooser::executeD( bool local ) | 579 | int PwMDataItemChooser::executeD( bool local ) |
500 | { | 580 | { |
501 | mSyncResult = 3; | 581 | mSyncResult = 3; |
502 | if ( local ) | 582 | if ( local ) |
503 | findButton( User1 )->setFocus(); | 583 | findButton( User1 )->setFocus(); |
504 | else | 584 | else |
505 | findButton( Ok )->setFocus(); | 585 | findButton( Ok )->setFocus(); |
506 | exec(); | 586 | exec(); |
507 | return mSyncResult; | 587 | return mSyncResult; |
508 | } | 588 | } |
509 | void PwMDataItemChooser::slot_remote() | 589 | void PwMDataItemChooser::slot_remote() |
510 | { | 590 | { |
511 | mSyncResult = 2; | 591 | mSyncResult = 2; |
512 | accept(); | 592 | accept(); |
513 | } | 593 | } |
514 | void PwMDataItemChooser::slot_local() | 594 | void PwMDataItemChooser::slot_local() |
515 | { | 595 | { |
516 | mSyncResult = 1; | 596 | mSyncResult = 1; |
517 | accept(); | 597 | accept(); |
518 | } | 598 | } |
519 | 599 | ||
520 | 600 | ||
521 | 601 | ||
522 | #ifndef PWM_EMBEDDED | 602 | #ifndef PWM_EMBEDDED |
523 | #include "pwmview.moc" | 603 | #include "pwmview.moc" |
524 | #endif | 604 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.h b/pwmanager/pwmanager/pwmview.h index 75cce51..e42b17a 100644 --- a/pwmanager/pwmanager/pwmview.h +++ b/pwmanager/pwmanager/pwmview.h | |||
@@ -1,172 +1,197 @@ | |||
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 | #ifndef PWMVIEW_H | 20 | #ifndef PWMVIEW_H |
21 | #define PWMVIEW_H | 21 | #define PWMVIEW_H |
22 | 22 | ||
23 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 23 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
24 | //US ENH: for examle in listviewpwm.cpp | 24 | //US ENH: for examle in listviewpwm.cpp |
25 | //US ENH: Because of that I transfer them into the headerfile. | 25 | //US ENH: Because of that I transfer them into the headerfile. |
26 | #define COLUMN_DESC 0 | 26 | #define COLUMN_DESC 0 |
27 | #define COLUMN_NAME 1 | 27 | #define COLUMN_NAME 1 |
28 | #define COLUMN_PW 2 | 28 | #define COLUMN_PW 2 |
29 | #define COLUMN_URL 3 | 29 | #define COLUMN_URL 3 |
30 | #define COLUMN_LAUNCHER 4 | 30 | #define COLUMN_LAUNCHER 4 |
31 | 31 | ||
32 | 32 | ||
33 | #include "listviewpwm.h" | 33 | #include "listviewpwm.h" |
34 | #include "pwmdoc.h" | 34 | #include "pwmdoc.h" |
35 | #include "pwmviewstyle.h" | 35 | #include "pwmviewstyle.h" |
36 | 36 | ||
37 | #include <kconfig.h> | 37 | #include <kconfig.h> |
38 | #include <klocale.h> | 38 | #include <klocale.h> |
39 | #include <kdialogbase.h> | 39 | #include <kdialogbase.h> |
40 | 40 | ||
41 | #include <qevent.h> | 41 | #include <qevent.h> |
42 | #include <qfont.h> | 42 | #include <qfont.h> |
43 | #include <qobject.h> | 43 | #include <qobject.h> |
44 | #include <qtextbrowser.h> | ||
44 | 45 | ||
45 | #include <vector> | 46 | #include <vector> |
46 | #include <string> | 47 | #include <string> |
47 | 48 | ||
48 | using std::string; | 49 | using std::string; |
49 | using std::vector; | 50 | using std::vector; |
50 | 51 | ||
51 | class PwM; | 52 | class PwM; |
52 | class ConfFile; | 53 | class ConfFile; |
53 | class PwMStatusBar; | 54 | class PwMStatusBar; |
54 | 55 | ||
55 | 56 | ||
56 | /** View class for PwM */ | 57 | /** View class for PwM */ |
57 | class PwMView : public PwMViewStyle | 58 | class PwMView : public PwMViewStyle |
58 | { | 59 | { |
59 | Q_OBJECT | 60 | Q_OBJECT |
60 | friend class PwMViewStyle; | 61 | friend class PwMViewStyle; |
61 | public: | 62 | public: |
62 | /** construtor */ | 63 | /** construtor */ |
63 | PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc, | 64 | PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc, |
64 | const char *name = 0); | 65 | const char *name = 0); |
65 | /** destructor */ | 66 | /** destructor */ |
66 | ~PwMView(); | 67 | ~PwMView(); |
67 | 68 | ||
68 | /** returns pointer to the document */ | 69 | /** returns pointer to the document */ |
69 | PwMDoc* document() | 70 | PwMDoc* document() |
70 | { return doc; } | 71 | { return doc; } |
71 | /** returns the index of the currently selected entry. | 72 | /** returns the index of the currently selected entry. |
72 | * (index as represented in PwMDoc !) | 73 | * (index as represented in PwMDoc !) |
73 | */ | 74 | */ |
74 | bool getCurEntryIndex(unsigned int *index); | 75 | bool getCurEntryIndex(unsigned int *index); |
75 | /** returns the position of the given item in the document | 76 | /** returns the position of the given item in the document |
76 | * Note: This func only serches in the current category. | 77 | * Note: This func only serches in the current category. |
77 | */ | 78 | */ |
78 | bool getDocEntryIndex(unsigned int *index, | 79 | bool getDocEntryIndex(unsigned int *index, |
79 | const QListViewItem *item); | 80 | const QListViewItem *item); |
80 | 81 | ||
81 | public slots: | 82 | public slots: |
82 | /** update the view (call if dirty) */ | 83 | /** update the view (call if dirty) */ |
83 | void updateView() | 84 | void updateView() |
84 | { | 85 | { |
85 | updateCategories(); | 86 | updateCategories(); |
86 | shiftToView(); | 87 | shiftToView(); |
87 | } | 88 | } |
88 | /** (re)sort all items and (re)shift them to listView. */ | 89 | /** (re)sort all items and (re)shift them to listView. */ |
89 | void shiftToView(); | 90 | void shiftToView(); |
90 | /** handle clicking on an item */ | 91 | /** handle clicking on an item */ |
91 | void handleToggle(QListViewItem *item); | 92 | void handleToggle(QListViewItem *item); |
92 | /** handle right-clicking on an item */ | 93 | /** handle right-clicking on an item */ |
93 | void handleRightClick(QListViewItem *item, const QPoint &point, int); | 94 | void handleRightClick(QListViewItem *item, const QPoint &point, int); |
94 | /** selects the item at "index" */ | 95 | /** selects the item at "index" */ |
95 | void selAt(int index); | 96 | void selAt(int index); |
96 | /** rename category button pressed */ | 97 | /** rename category button pressed */ |
97 | void renCatButton_slot(); | 98 | void renCatButton_slot(); |
98 | /** delete category button pressed */ | 99 | /** delete category button pressed */ |
99 | void delCatButton_slot(); | 100 | void delCatButton_slot(); |
100 | 101 | ||
101 | protected: | 102 | protected: |
102 | /** right-click context-menu */ | 103 | /** right-click context-menu */ |
103 | QPopupMenu *ctxMenu; | 104 | QPopupMenu *ctxMenu; |
104 | 105 | ||
105 | protected: | 106 | protected: |
106 | /** update the categories from document */ | 107 | /** update the categories from document */ |
107 | void updateCategories(); | 108 | void updateCategories(); |
108 | /** widget resize event */ | 109 | /** widget resize event */ |
109 | void resizeEvent(QResizeEvent *); | 110 | void resizeEvent(QResizeEvent *); |
110 | /** initialize context-menu */ | 111 | /** initialize context-menu */ |
111 | void initCtxMenu(); | 112 | void initCtxMenu(); |
112 | /** tempoarly disable auto-sorting and user-sorting */ | 113 | /** tempoarly disable auto-sorting and user-sorting */ |
113 | void tmpDisableSort() | 114 | void tmpDisableSort() |
114 | { lv->setSorting(-1); } | 115 | { lv->setSorting(-1); } |
115 | /** re-enable tempoarly disabled sorting */ | 116 | /** re-enable tempoarly disabled sorting */ |
116 | void tmpReEnableSort() | 117 | void tmpReEnableSort() |
117 | { | 118 | { |
118 | lv->setSorting(lv->columns() + 1, | 119 | lv->setSorting(lv->columns() + 1, |
119 | true/*lv->sortOrder() == Qt::Ascending*/); | 120 | true/*lv->sortOrder() == Qt::Ascending*/); |
120 | } | 121 | } |
121 | /** The user pressed and released a key. */ | 122 | /** The user pressed and released a key. */ |
122 | void keyReleaseEvent(QKeyEvent *e); | 123 | void keyReleaseEvent(QKeyEvent *e); |
123 | 124 | ||
124 | protected slots: | 125 | protected slots: |
125 | /** changes the comment text-edit, because a new item has been selected */ | 126 | /** changes the comment text-edit, because a new item has been selected */ |
126 | void refreshCommentTextEdit(QListViewItem *curItem); | 127 | void refreshCommentTextEdit(QListViewItem *curItem); |
127 | /** copy pw to clipboard */ | 128 | /** copy pw to clipboard */ |
128 | void copyPwToClip(); | 129 | void copyPwToClip(); |
129 | /** copy name to clipboard */ | 130 | /** copy name to clipboard */ |
130 | void copyNameToClip(); | 131 | void copyNameToClip(); |
131 | /** copy desc to clipboard */ | 132 | /** copy desc to clipboard */ |
132 | void copyDescToClip(); | 133 | void copyDescToClip(); |
133 | /** copy url to clipboard */ | 134 | /** copy url to clipboard */ |
134 | void copyUrlToClip(); | 135 | void copyUrlToClip(); |
135 | /** copy launcher to clipboard */ | 136 | /** copy launcher to clipboard */ |
136 | void copyLauncherToClip(); | 137 | void copyLauncherToClip(); |
137 | /** copy comment to clipboard */ | 138 | /** copy comment to clipboard */ |
138 | void copyCommentToClip(); | 139 | void copyCommentToClip(); |
139 | /** reorganize the "listViewPos" positions in the document | 140 | /** reorganize the "listViewPos" positions in the document |
140 | * (for the current category only!) | 141 | * (for the current category only!) |
141 | */ | 142 | */ |
142 | void reorgLp(); | 143 | void reorgLp(); |
143 | 144 | ||
144 | private: | 145 | private: |
145 | /** document */ | 146 | /** document */ |
146 | PwMDoc *doc; | 147 | PwMDoc *doc; |
147 | /** pointer to the main class "PwM" */ | 148 | /** pointer to the main class "PwM" */ |
148 | PwM *mainClass; | 149 | PwM *mainClass; |
149 | }; | 150 | }; |
150 | 151 | ||
151 | 152 | ||
153 | //US ENH basic widget to view an password entry. We need it for the sync stuff. | ||
154 | //But might be oif interest for other functionalities as well. | ||
155 | class PwMDataItemView : public QTextBrowser | ||
156 | { | ||
157 | public: | ||
158 | PwMDataItemView( QWidget *parent = 0, const char *name = 0 ); | ||
159 | |||
160 | /** | ||
161 | Sets the PwMDataItem object. It is displayed immediately. | ||
162 | |||
163 | @param a The PwMDataItem object. | ||
164 | */ | ||
165 | void setPwMDataItem( const PwMDataItem& a ); | ||
166 | |||
167 | /** | ||
168 | Returns the current PwMDataItem object. | ||
169 | */ | ||
170 | PwMDataItem pwmdataitem() const; | ||
171 | |||
172 | private: | ||
173 | PwMDataItem mItem; | ||
174 | }; | ||
175 | |||
176 | |||
152 | //US ENH we need this chooser when syncing results in a conflict | 177 | //US ENH we need this chooser when syncing results in a conflict |
153 | class PwMDataItemChooser : public KDialogBase | 178 | class PwMDataItemChooser : public KDialogBase |
154 | { | 179 | { |
155 | Q_OBJECT | 180 | Q_OBJECT |
156 | 181 | ||
157 | public: | 182 | public: |
158 | PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); | 183 | PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); |
159 | 184 | ||
160 | int executeD( bool local ); | 185 | int executeD( bool local ); |
161 | 186 | ||
162 | private: | 187 | private: |
163 | int mSyncResult; | 188 | int mSyncResult; |
164 | 189 | ||
165 | private slots: | 190 | private slots: |
166 | void slot_remote(); | 191 | void slot_remote(); |
167 | void slot_local(); | 192 | void slot_local(); |
168 | 193 | ||
169 | }; | 194 | }; |
170 | 195 | ||
171 | 196 | ||
172 | #endif | 197 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index 203f82c..5c6568f 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,756 +1,780 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "serializer.h" | 21 | #include "serializer.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | 23 | ||
24 | #ifdef PWM_EMBEDDED | 24 | #ifdef PWM_EMBEDDED |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | /* enable/disable serializer debugging (0/1) */ | 29 | /* enable/disable serializer debugging (0/1) */ |
30 | #define SERIALIZER_DEBUG0 | 30 | #define SERIALIZER_DEBUG1 |
31 | /* use the old xml tags for writing (0/1) */ | 31 | /* use the old xml tags for writing (0/1) */ |
32 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
33 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
34 | #define WRITE_CDATA_SEC 0 | 34 | #define WRITE_CDATA_SEC 0 |
35 | 35 | ||
36 | 36 | ||
37 | #define META_CREATE_DATE"c" | 37 | #define META_CREATE_DATE"c" |
38 | #define META_VALID_DATE "v" | 38 | #define META_VALID_DATE "v" |
39 | #define META_EXPIRE_DATE"e" | 39 | #define META_EXPIRE_DATE"e" |
40 | #define META_UPDATE_DATE"u" | 40 | #define META_UPDATE_DATE"u" |
41 | #define META_UPDATE_INT "i" | 41 | #define META_UPDATE_INT "i" |
42 | //US ENH : uniqueid | 42 | //US ENH : uniqueid |
43 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
44 | #define SYNC_ROOT "s" | 44 | #define SYNC_ROOT "s" |
45 | #define SYNC_TARGET_PREFIX "t" | 45 | #define SYNC_TARGET_PREFIX "t" |
46 | #define SYNC_TARGET_NAME "n" | 46 | #define SYNC_TARGET_NAME "n" |
47 | 47 | ||
48 | 48 | ||
49 | /* This is compatibility stuff. | 49 | /* This is compatibility stuff. |
50 | * The names of the entries have changed and here are the | 50 | * The names of the entries have changed and here are the |
51 | * new and old ones | 51 | * new and old ones |
52 | */ | 52 | */ |
53 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 53 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
54 | #define VER_STR_OLD "ver" | 54 | #define VER_STR_OLD "ver" |
55 | #define COMPAT_VER_OLD "0x02" | 55 | #define COMPAT_VER_OLD "0x02" |
56 | #define CAT_ROOT_OLD "categories" | 56 | #define CAT_ROOT_OLD "categories" |
57 | #define CAT_PREFIX_OLD "cat_" | 57 | #define CAT_PREFIX_OLD "cat_" |
58 | #define CAT_NAME_OLD "name" | 58 | #define CAT_NAME_OLD "name" |
59 | #define ENTRY_PREFIX_OLD"entry_" | 59 | #define ENTRY_PREFIX_OLD"entry_" |
60 | #define ENTRY_DESC_OLD "desc" | 60 | #define ENTRY_DESC_OLD "desc" |
61 | #define ENTRY_NAME_OLD "name" | 61 | #define ENTRY_NAME_OLD "name" |
62 | #define ENTRY_PW_OLD "pw" | 62 | #define ENTRY_PW_OLD "pw" |
63 | #define ENTRY_COMMENT_OLD"comment" | 63 | #define ENTRY_COMMENT_OLD"comment" |
64 | #define ENTRY_URL_OLD "url" | 64 | #define ENTRY_URL_OLD "url" |
65 | #define ENTRY_LAUNCHER_OLD"launcher" | 65 | #define ENTRY_LAUNCHER_OLD"launcher" |
66 | #define ENTRY_LVP_OLD "listViewPos" | 66 | #define ENTRY_LVP_OLD "listViewPos" |
67 | #define ENTRY_BIN_OLD "b" | 67 | #define ENTRY_BIN_OLD "b" |
68 | #define ENTRY_META_OLD "m" | 68 | #define ENTRY_META_OLD "m" |
69 | 69 | ||
70 | #define ROOT_MAGIC_NEW "P" | 70 | #define ROOT_MAGIC_NEW "P" |
71 | #define VER_STR_NEW "v" | 71 | #define VER_STR_NEW "v" |
72 | #define COMPAT_VER_NEW "2" | 72 | #define COMPAT_VER_NEW "2" |
73 | #define CAT_ROOT_NEW "c" | 73 | #define CAT_ROOT_NEW "c" |
74 | #define CAT_PREFIX_NEW "c" | 74 | #define CAT_PREFIX_NEW "c" |
75 | #define CAT_NAME_NEW "n" | 75 | #define CAT_NAME_NEW "n" |
76 | #define ENTRY_PREFIX_NEW"e" | 76 | #define ENTRY_PREFIX_NEW"e" |
77 | #define ENTRY_DESC_NEW "d" | 77 | #define ENTRY_DESC_NEW "d" |
78 | #define ENTRY_NAME_NEW "n" | 78 | #define ENTRY_NAME_NEW "n" |
79 | #define ENTRY_PW_NEW "p" | 79 | #define ENTRY_PW_NEW "p" |
80 | #define ENTRY_COMMENT_NEW"c" | 80 | #define ENTRY_COMMENT_NEW"c" |
81 | #define ENTRY_URL_NEW "u" | 81 | #define ENTRY_URL_NEW "u" |
82 | #define ENTRY_LAUNCHER_NEW"l" | 82 | #define ENTRY_LAUNCHER_NEW"l" |
83 | #define ENTRY_LVP_NEW "v" | 83 | #define ENTRY_LVP_NEW "v" |
84 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 84 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
85 | #define ENTRY_META_NEW ENTRY_META_OLD | 85 | #define ENTRY_META_NEW ENTRY_META_OLD |
86 | 86 | ||
87 | #if USE_OLD_TAGS != 0 | 87 | #if USE_OLD_TAGS != 0 |
88 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 88 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
89 | # define VER_STR_WR VER_STR_OLD | 89 | # define VER_STR_WR VER_STR_OLD |
90 | # define COMPAT_VER_WR COMPAT_VER_OLD | 90 | # define COMPAT_VER_WR COMPAT_VER_OLD |
91 | # define CAT_ROOT_WR CAT_ROOT_OLD | 91 | # define CAT_ROOT_WR CAT_ROOT_OLD |
92 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 92 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
93 | # define CAT_NAME_WR CAT_NAME_OLD | 93 | # define CAT_NAME_WR CAT_NAME_OLD |
94 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 94 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
95 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 95 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
96 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 96 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
97 | # define ENTRY_PW_WR ENTRY_PW_OLD | 97 | # define ENTRY_PW_WR ENTRY_PW_OLD |
98 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 98 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
99 | # define ENTRY_URL_WR ENTRY_URL_OLD | 99 | # define ENTRY_URL_WR ENTRY_URL_OLD |
100 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 100 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
101 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 101 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
102 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 102 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
103 | # define ENTRY_META_WR ENTRY_META_OLD | 103 | # define ENTRY_META_WR ENTRY_META_OLD |
104 | #else | 104 | #else |
105 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 105 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
106 | # define VER_STR_WR VER_STR_NEW | 106 | # define VER_STR_WR VER_STR_NEW |
107 | # define COMPAT_VER_WR COMPAT_VER_NEW | 107 | # define COMPAT_VER_WR COMPAT_VER_NEW |
108 | # define CAT_ROOT_WR CAT_ROOT_NEW | 108 | # define CAT_ROOT_WR CAT_ROOT_NEW |
109 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 109 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
110 | # define CAT_NAME_WR CAT_NAME_NEW | 110 | # define CAT_NAME_WR CAT_NAME_NEW |
111 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 111 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
112 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 112 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
113 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 113 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
114 | # define ENTRY_PW_WR ENTRY_PW_NEW | 114 | # define ENTRY_PW_WR ENTRY_PW_NEW |
115 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 115 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
116 | # define ENTRY_URL_WR ENTRY_URL_NEW | 116 | # define ENTRY_URL_WR ENTRY_URL_NEW |
117 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 117 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
118 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 118 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
119 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 119 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
120 | # define ENTRY_META_WR ENTRY_META_NEW | 120 | # define ENTRY_META_WR ENTRY_META_NEW |
121 | #endif | 121 | #endif |
122 | 122 | ||
123 | 123 | ||
124 | Serializer::Serializer() | 124 | Serializer::Serializer() |
125 | { | 125 | { |
126 | defaultLockStat = true; | 126 | defaultLockStat = true; |
127 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 127 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
128 | #ifndef PWM_EMBEDDED | 128 | #ifndef PWM_EMBEDDED |
129 | domDoc = new QDomDocument; | 129 | domDoc = new QDomDocument; |
130 | #else | 130 | #else |
131 | domDoc = new QDomDocument("mydoc"); | 131 | domDoc = new QDomDocument("mydoc"); |
132 | #endif | 132 | #endif |
133 | } | 133 | } |
134 | 134 | ||
135 | Serializer::Serializer(const QCString &buffer) | 135 | Serializer::Serializer(const QCString &buffer) |
136 | { | 136 | { |
137 | defaultLockStat = true; | 137 | defaultLockStat = true; |
138 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 138 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
139 | #ifndef PWM_EMBEDDED | 139 | #ifndef PWM_EMBEDDED |
140 | domDoc = new QDomDocument; | 140 | domDoc = new QDomDocument; |
141 | #else | 141 | #else |
142 | domDoc = new QDomDocument("mydoc"); | 142 | domDoc = new QDomDocument("mydoc"); |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | if (!parseXml(buffer)) { | 145 | if (!parseXml(buffer)) { |
146 | delete domDoc; | 146 | delete domDoc; |
147 | #ifndef PWM_EMBEDDED | 147 | #ifndef PWM_EMBEDDED |
148 | throw PwMException(PwMException::EX_PARSE); | 148 | throw PwMException(PwMException::EX_PARSE); |
149 | #else | 149 | #else |
150 | qDebug("Serializer::Serializer : Parse Exception "); | 150 | qDebug("Serializer::Serializer : Parse Exception "); |
151 | #endif | 151 | #endif |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | Serializer::~Serializer() | 155 | Serializer::~Serializer() |
156 | { | 156 | { |
157 | delete_ifnot_null(domDoc); | 157 | delete_ifnot_null(domDoc); |
158 | } | 158 | } |
159 | 159 | ||
160 | void Serializer::clear() | 160 | void Serializer::clear() |
161 | { | 161 | { |
162 | delete_ifnot_null(domDoc); | 162 | delete_ifnot_null(domDoc); |
163 | domDoc = new QDomDocument; | 163 | domDoc = new QDomDocument; |
164 | } | 164 | } |
165 | 165 | ||
166 | bool Serializer::parseXml(const QCString &buffer) | 166 | bool Serializer::parseXml(const QCString &buffer) |
167 | { | 167 | { |
168 | PWM_ASSERT(domDoc); | 168 | PWM_ASSERT(domDoc); |
169 | #ifndef PWM_EMBEDDED | 169 | #ifndef PWM_EMBEDDED |
170 | if (!domDoc->setContent(buffer, true)) | 170 | if (!domDoc->setContent(buffer, true)) |
171 | return false; | 171 | return false; |
172 | #else | 172 | #else |
173 | if (!domDoc->setContent(buffer)) | 173 | if (!domDoc->setContent(buffer)) |
174 | return false; | 174 | return false; |
175 | #endif | 175 | #endif |
176 | if (!checkValid()) | 176 | if (!checkValid()) |
177 | return false; | 177 | return false; |
178 | return true; | 178 | return true; |
179 | } | 179 | } |
180 | 180 | ||
181 | QCString Serializer::getXml() | 181 | QCString Serializer::getXml() |
182 | { | 182 | { |
183 | PWM_ASSERT(domDoc); | 183 | PWM_ASSERT(domDoc); |
184 | 184 | ||
185 | #ifndef PWM_EMBEDDED | 185 | #ifndef PWM_EMBEDDED |
186 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 186 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
187 | QCString tmp(domDoc->toCString(8)); | 187 | QCString tmp(domDoc->toCString(8)); |
188 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 188 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
189 | cout << tmp << endl; | 189 | cout << tmp << endl; |
190 | printDebug("<END Serializer::getXml() dump>"); | 190 | printDebug("<END Serializer::getXml() dump>"); |
191 | #endif // DEBUG | 191 | #endif // DEBUG |
192 | 192 | ||
193 | QCString ret(domDoc->toCString(0)); | 193 | QCString ret(domDoc->toCString(0)); |
194 | ret.replace('\n', ""); | 194 | ret.replace('\n', ""); |
195 | return ret; | 195 | return ret; |
196 | #else | 196 | #else |
197 | 197 | ||
198 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 198 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
199 | QCString tmp(" " + domDoc->toCString()); | 199 | QCString tmp(" " + domDoc->toCString()); |
200 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 200 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
201 | qDebug(tmp); | 201 | qDebug(tmp); |
202 | cout << tmp << endl; | 202 | cout << tmp << endl; |
203 | printDebug("<END Serializer::getXml() dump>"); | 203 | printDebug("<END Serializer::getXml() dump>"); |
204 | #endif // DEBUG | 204 | #endif // DEBUG |
205 | 205 | ||
206 | QCString ret(domDoc->toCString()); | 206 | QCString ret(domDoc->toCString()); |
207 | ret.replace(QRegExp("\n"), ""); | 207 | ret.replace(QRegExp("\n"), ""); |
208 | return ret; | 208 | return ret; |
209 | 209 | ||
210 | #endif | 210 | #endif |
211 | } | 211 | } |
212 | 212 | ||
213 | bool Serializer::serialize(PwMItem &dta) | 213 | bool Serializer::serialize(PwMItem &dta) |
214 | { | 214 | { |
215 | PWM_ASSERT(domDoc); | 215 | PWM_ASSERT(domDoc); |
216 | QDomElement root(genNewRoot()); | 216 | QDomElement root(genNewRoot()); |
217 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 217 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
218 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); | 218 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); |
219 | if (!addSyncData(&syncNode, dta.syncDta)) | 219 | if (!addSyncData(&syncNode, dta.syncDta)) |
220 | return false; | 220 | return false; |
221 | root.appendChild(syncNode); | 221 | root.appendChild(syncNode); |
222 | if (!addCategories(&catNode, dta.dta)) | 222 | if (!addCategories(&catNode, dta.dta)) |
223 | return false; | 223 | return false; |
224 | root.appendChild(catNode); | 224 | root.appendChild(catNode); |
225 | return true; | 225 | return true; |
226 | } | 226 | } |
227 | 227 | ||
228 | bool Serializer::deSerialize(PwMItem *dta) | 228 | bool Serializer::deSerialize(PwMItem *dta) |
229 | { | 229 | { |
230 | PWM_ASSERT(domDoc); | 230 | PWM_ASSERT(domDoc); |
231 | PWM_ASSERT(dta); | 231 | PWM_ASSERT(dta); |
232 | QDomElement root(domDoc->documentElement()); | 232 | QDomElement root(domDoc->documentElement()); |
233 | QDomNode n; | 233 | QDomNode n; |
234 | 234 | ||
235 | dta->clear(); | 235 | dta->clear(); |
236 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 236 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
237 | // find <categories> ... </categories> | 237 | // find <categories> ... </categories> |
238 | // <c> ... </c> | 238 | // <c> ... </c> |
239 | if (n.nodeName() == CAT_ROOT_NEW || | 239 | if (n.nodeName() == CAT_ROOT_NEW || |
240 | n.nodeName() == CAT_ROOT_OLD) { | 240 | n.nodeName() == CAT_ROOT_OLD) { |
241 | if (!readCategories(n, &(dta->dta))) { | 241 | if (!readCategories(n, &(dta->dta))) { |
242 | return false; | 242 | return false; |
243 | } | 243 | } |
244 | continue; | 244 | continue; |
245 | } | 245 | } |
246 | else if (n.nodeName() == SYNC_ROOT) { | 246 | else if (n.nodeName() == SYNC_ROOT) { |
247 | if (!readSyncData(n, &(dta->syncDta))) { | 247 | if (!readSyncData(n, &(dta->syncDta))) { |
248 | return false; | 248 | return false; |
249 | } | 249 | } |
250 | continue; | 250 | continue; |
251 | } | 251 | } |
252 | 252 | ||
253 | /* NOTE: We can stop processing here, as we | 253 | /* NOTE: We can stop processing here, as we |
254 | * don't have more nodes in root, yet. | 254 | * don't have more nodes in root, yet. |
255 | */ | 255 | */ |
256 | return false; | 256 | return false; |
257 | 257 | ||
258 | } | 258 | } |
259 | return true; | 259 | return true; |
260 | } | 260 | } |
261 | 261 | ||
262 | bool Serializer::readCategories(const QDomNode &n, | 262 | bool Serializer::readCategories(const QDomNode &n, |
263 | vector<PwMCategoryItem> *dta) | 263 | vector<PwMCategoryItem> *dta) |
264 | { | 264 | { |
265 | QDomNodeList nl(n.childNodes()); | 265 | QDomNodeList nl(n.childNodes()); |
266 | QDomNode cur; | 266 | QDomNode cur; |
267 | QString name; | 267 | QString name; |
268 | unsigned int numCat = nl.count(), i; | 268 | unsigned int numCat = nl.count(), i; |
269 | PwMCategoryItem curCat; | 269 | PwMCategoryItem curCat; |
270 | vector<PwMDataItem> curEntr; | 270 | vector<PwMDataItem> curEntr; |
271 | 271 | ||
272 | if (!numCat) { | 272 | if (!numCat) { |
273 | printDebug("Serializer::readCategories(): empty"); | 273 | printDebug("Serializer::readCategories(): empty"); |
274 | return false; | 274 | return false; |
275 | } | 275 | } |
276 | for (i = 0; i < numCat; ++i) { | 276 | for (i = 0; i < numCat; ++i) { |
277 | cur = nl.item(i); | 277 | cur = nl.item(i); |
278 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 278 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
279 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 279 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
280 | name = cur.toElement().attribute(CAT_NAME_NEW); | 280 | name = cur.toElement().attribute(CAT_NAME_NEW); |
281 | if (name == QString::null) | 281 | if (name == QString::null) |
282 | name = cur.toElement().attribute(CAT_NAME_OLD); | 282 | name = cur.toElement().attribute(CAT_NAME_OLD); |
283 | PWM_ASSERT(name != QString::null); | 283 | PWM_ASSERT(name != QString::null); |
284 | PWM_ASSERT(name != ""); | 284 | PWM_ASSERT(name != ""); |
285 | curCat.clear(); | 285 | curCat.clear(); |
286 | curCat.name = name.latin1(); | 286 | curCat.name = name.latin1(); |
287 | if (!readEntries(cur, &curEntr)) { | 287 | if (!readEntries(cur, &curEntr)) { |
288 | dta->clear(); | 288 | dta->clear(); |
289 | return false; | 289 | return false; |
290 | } | 290 | } |
291 | curCat.d = curEntr; | 291 | curCat.d = curEntr; |
292 | dta->push_back(curCat); | 292 | dta->push_back(curCat); |
293 | } else { | 293 | } else { |
294 | printDebug("Serializer::readCategories(): uh? not a category?"); | 294 | printDebug("Serializer::readCategories(): uh? not a category?"); |
295 | } | 295 | } |
296 | } | 296 | } |
297 | return true; | 297 | return true; |
298 | } | 298 | } |
299 | 299 | ||
300 | bool Serializer::readEntries(const QDomNode &n, | 300 | bool Serializer::readEntries(const QDomNode &n, |
301 | vector<PwMDataItem> *dta) | 301 | vector<PwMDataItem> *dta) |
302 | { | 302 | { |
303 | QDomNodeList nl(n.childNodes()); | 303 | QDomNodeList nl(n.childNodes()); |
304 | QDomNode cur; | 304 | QDomNode cur; |
305 | unsigned int numEntr = nl.count(), i; | 305 | unsigned int numEntr = nl.count(), i; |
306 | PwMDataItem curEntr; | 306 | PwMDataItem curEntr; |
307 | //US BUG: to initialize all values of curEntr with meaningfulldata, | ||
308 | // we call clear on it. Reason: Information in the file we will read might be incomplete. | ||
309 | // e.g. the metadata is missing. | ||
310 | curEntr.clear(true); | ||
307 | 311 | ||
308 | dta->clear(); | 312 | dta->clear(); |
309 | for (i = 0; i < numEntr; ++i) { | 313 | for (i = 0; i < numEntr; ++i) { |
310 | cur = nl.item(i); | 314 | cur = nl.item(i); |
311 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 315 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
312 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 316 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
313 | if (!extractEntry(cur, &curEntr)) { | 317 | if (!extractEntry(cur, &curEntr)) { |
314 | return false; | 318 | return false; |
315 | } | 319 | } |
316 | dta->push_back(curEntr); | 320 | dta->push_back(curEntr); |
317 | } else { | 321 | } else { |
318 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 322 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
319 | } | 323 | } |
320 | } | 324 | } |
321 | return true; | 325 | return true; |
322 | } | 326 | } |
323 | 327 | ||
324 | bool Serializer::extractEntry(const QDomNode &n, | 328 | bool Serializer::extractEntry(const QDomNode &n, |
325 | PwMDataItem *dta) | 329 | PwMDataItem *dta) |
326 | { | 330 | { |
327 | QDomNodeList nl(n.childNodes()); | 331 | QDomNodeList nl(n.childNodes()); |
328 | QDomNode cur, cdata; | 332 | QDomNode cur, cdata; |
329 | unsigned int cnt = nl.count(), i; | 333 | unsigned int cnt = nl.count(), i; |
330 | QString name, text; | 334 | QString name, text; |
331 | 335 | ||
332 | if (!cnt) { | 336 | if (!cnt) { |
333 | printDebug("Serializer::extractEntry(): empty"); | 337 | printDebug("Serializer::extractEntry(): empty"); |
334 | return false; | 338 | return false; |
335 | } | 339 | } |
336 | dta->clear(); | 340 | dta->clear(); |
337 | for (i = 0; i < cnt; ++i) { | 341 | for (i = 0; i < cnt; ++i) { |
338 | cur = nl.item(i); | 342 | cur = nl.item(i); |
339 | name = cur.nodeName(); | 343 | name = cur.nodeName(); |
340 | cdata = cur.firstChild(); | 344 | cdata = cur.firstChild(); |
341 | if (unlikely(cdata.isCDATASection())) { | 345 | if (unlikely(cdata.isCDATASection())) { |
342 | text = cdata.toCDATASection().data(); | 346 | text = cdata.toCDATASection().data(); |
343 | } else if (likely(cur.isElement())) { | 347 | } else if (likely(cur.isElement())) { |
344 | text = cur.toElement().text(); | 348 | text = cur.toElement().text(); |
345 | } else { | 349 | } else { |
346 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 350 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
347 | return false; | 351 | return false; |
348 | } | 352 | } |
349 | if (text == " ") | 353 | if (text == " ") |
350 | text = ""; // for backward compatibility. | 354 | text = ""; // for backward compatibility. |
351 | if (name == ENTRY_DESC_NEW || | 355 | if (name == ENTRY_DESC_NEW || |
352 | name == ENTRY_DESC_OLD) { | 356 | name == ENTRY_DESC_OLD) { |
353 | dta->desc = unescapeEntryData(text).latin1(); | 357 | dta->desc = unescapeEntryData(text).latin1(); |
354 | } else if (name == ENTRY_NAME_NEW || | 358 | } else if (name == ENTRY_NAME_NEW || |
355 | name == ENTRY_NAME_OLD) { | 359 | name == ENTRY_NAME_OLD) { |
356 | dta->name = unescapeEntryData(text).latin1(); | 360 | dta->name = unescapeEntryData(text).latin1(); |
357 | } else if (name == ENTRY_PW_NEW || | 361 | } else if (name == ENTRY_PW_NEW || |
358 | name == ENTRY_PW_OLD) { | 362 | name == ENTRY_PW_OLD) { |
359 | dta->pw = unescapeEntryData(text).latin1(); | 363 | dta->pw = unescapeEntryData(text).latin1(); |
360 | } else if (name == ENTRY_COMMENT_NEW || | 364 | } else if (name == ENTRY_COMMENT_NEW || |
361 | name == ENTRY_COMMENT_OLD) { | 365 | name == ENTRY_COMMENT_OLD) { |
362 | dta->comment = unescapeEntryData(text).latin1(); | 366 | dta->comment = unescapeEntryData(text).latin1(); |
363 | } else if (name == ENTRY_URL_NEW || | 367 | } else if (name == ENTRY_URL_NEW || |
364 | name == ENTRY_URL_OLD) { | 368 | name == ENTRY_URL_OLD) { |
365 | dta->url = unescapeEntryData(text).latin1(); | 369 | dta->url = unescapeEntryData(text).latin1(); |
366 | } else if (name == ENTRY_LAUNCHER_NEW || | 370 | } else if (name == ENTRY_LAUNCHER_NEW || |
367 | name == ENTRY_LAUNCHER_OLD) { | 371 | name == ENTRY_LAUNCHER_OLD) { |
368 | dta->launcher = unescapeEntryData(text).latin1(); | 372 | dta->launcher = unescapeEntryData(text).latin1(); |
369 | } else if (name == ENTRY_LVP_NEW || | 373 | } else if (name == ENTRY_LVP_NEW || |
370 | name == ENTRY_LVP_OLD) { | 374 | name == ENTRY_LVP_OLD) { |
371 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 375 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
372 | } else if (name == ENTRY_BIN_NEW) { | 376 | } else if (name == ENTRY_BIN_NEW) { |
373 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 377 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
374 | if (text == "0") { | 378 | if (text == "0") { |
375 | dta->binary = false; | 379 | dta->binary = false; |
376 | } else { | 380 | } else { |
377 | dta->binary = true; | 381 | dta->binary = true; |
378 | } | 382 | } |
379 | } else if (name == ENTRY_META_NEW) { | 383 | } else if (name == ENTRY_META_NEW) { |
380 | // ENTRY_META_NEW == ENTRY_META_OLD | 384 | // ENTRY_META_NEW == ENTRY_META_OLD |
381 | if (!extractMeta(cur, &dta->meta)) | 385 | if (!extractMeta(cur, &dta->meta)) |
382 | return false; | 386 | return false; |
383 | } else { | 387 | } else { |
384 | printDebug(string("Serializer::extractEntry(): invalid: ") | 388 | printDebug(string("Serializer::extractEntry(): invalid: ") |
385 | + name.latin1()); | 389 | + name.latin1()); |
386 | } | 390 | } |
387 | } | 391 | } |
388 | dta->lockStat = defaultLockStat; | 392 | dta->lockStat = defaultLockStat; |
389 | return true; | 393 | return true; |
390 | } | 394 | } |
391 | 395 | ||
392 | bool Serializer::extractMeta(const QDomNode &n, | 396 | bool Serializer::extractMeta(const QDomNode &n, |
393 | PwMMetaData *dta) | 397 | PwMMetaData *dta) |
394 | { | 398 | { |
395 | QDomNode cur(n.firstChild()); | 399 | QDomNode cur(n.firstChild()); |
396 | QString name, val; | 400 | QString name, val; |
397 | while (!cur.isNull()) { | 401 | while (!cur.isNull()) { |
398 | name = cur.nodeName(); | 402 | name = cur.nodeName(); |
399 | val = cur.toElement().text(); | 403 | val = cur.toElement().text(); |
400 | if (val == "") { | 404 | if (val == "") { |
401 | cur = cur.nextSibling(); | 405 | cur = cur.nextSibling(); |
402 | continue; | 406 | continue; |
403 | } | 407 | } |
408 | |||
409 | //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. | ||
410 | //because of that it is possible that here some values are not set, which means they are null. | ||
411 | //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates. | ||
412 | |||
413 | QDateTime dtval; //dtval should be invalid by definition. | ||
414 | |||
415 | if ((name == META_CREATE_DATE) || | ||
416 | (name == META_VALID_DATE) || | ||
417 | (name == META_EXPIRE_DATE) || | ||
418 | (name == META_UPDATE_DATE)) | ||
419 | { | ||
420 | //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); | ||
421 | |||
404 | #ifndef PWM_EMBEDDED | 422 | #ifndef PWM_EMBEDDED |
405 | if (name == META_CREATE_DATE) { | 423 | dtval = QDateTime::fromString(val, Qt::ISODate); |
406 | dta->create = QDateTime::fromString(val, Qt::ISODate); | ||
407 | } else if (name == META_VALID_DATE) { | ||
408 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | ||
409 | } else if (name == META_EXPIRE_DATE) { | ||
410 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | ||
411 | } else if (name == META_UPDATE_DATE) { | ||
412 | dta->update = QDateTime::fromString(val, Qt::ISODate); | ||
413 | } else if (name == META_UPDATE_INT) { | ||
414 | dta->updateInt = strtoul(val.latin1(), 0, 10); | ||
415 | } else if (name == META_UNIQUEID) { | ||
416 | dta->uniqueid = unescapeEntryData(val).latin1(); | ||
417 | } else { | ||
418 | printDebug(string("extractMeta(): invalid: ") | ||
419 | + name.latin1()); | ||
420 | } | ||
421 | #else | 424 | #else |
425 | bool ok; | ||
426 | dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | ||
427 | |||
428 | if (ok == false) | ||
429 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | ||
430 | #endif | ||
422 | 431 | ||
432 | //if the parsed data is wrong, dtval should be invalid at this time. | ||
423 | 433 | ||
424 | bool ok = true; | 434 | } |
425 | 435 | ||
426 | if (name == META_CREATE_DATE) { | 436 | if (name == META_CREATE_DATE) { |
427 | dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 437 | dta->create = dtval; |
428 | } else if (name == META_VALID_DATE) { | 438 | } else if (name == META_VALID_DATE) { |
429 | dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 439 | dta->valid = dtval; |
430 | } else if (name == META_EXPIRE_DATE) { | 440 | } else if (name == META_EXPIRE_DATE) { |
431 | dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 441 | dta->expire = dtval; |
432 | } else if (name == META_UPDATE_DATE) { | 442 | } else if (name == META_UPDATE_DATE) { |
433 | dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 443 | dta->update = dtval; |
434 | } else if (name == META_UPDATE_INT) { | 444 | } else if (name == META_UPDATE_INT) { |
435 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 445 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
436 | } else if (name == META_UNIQUEID) { | 446 | } else if (name == META_UNIQUEID) { |
437 | dta->uniqueid = unescapeEntryData(val).latin1(); | 447 | dta->uniqueid = unescapeEntryData(val).latin1(); |
438 | } else { | 448 | } else { |
439 | printDebug(string("extractMeta(): invalid: ") | 449 | printDebug(string("extractMeta(): invalid: ") |
440 | + name.latin1()); | 450 | + name.latin1()); |
441 | } | 451 | } |
442 | 452 | ||
443 | if (ok == false) | ||
444 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | ||
445 | |||
446 | |||
447 | #endif | ||
448 | cur = cur.nextSibling(); | 453 | cur = cur.nextSibling(); |
449 | } | 454 | } |
450 | return true; | 455 | return true; |
451 | } | 456 | } |
452 | 457 | ||
453 | bool Serializer::checkValid() | 458 | bool Serializer::checkValid() |
454 | { | 459 | { |
455 | PWM_ASSERT(domDoc); | 460 | PWM_ASSERT(domDoc); |
456 | QDomElement root(domDoc->documentElement()); | 461 | QDomElement root(domDoc->documentElement()); |
457 | if (root.nodeName() != ROOT_MAGIC_NEW && | 462 | if (root.nodeName() != ROOT_MAGIC_NEW && |
458 | root.nodeName() != ROOT_MAGIC_OLD) { | 463 | root.nodeName() != ROOT_MAGIC_OLD) { |
459 | printDebug("Serializer: wrong magic"); | 464 | printDebug("Serializer: wrong magic"); |
460 | return false; | 465 | return false; |
461 | } | 466 | } |
462 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 467 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
463 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 468 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
464 | printDebug("Serializer: wrong version"); | 469 | printDebug("Serializer: wrong version"); |
465 | return false; | 470 | return false; |
466 | } | 471 | } |
467 | return true; | 472 | return true; |
468 | } | 473 | } |
469 | 474 | ||
470 | QDomElement Serializer::genNewRoot() | 475 | QDomElement Serializer::genNewRoot() |
471 | { | 476 | { |
472 | PWM_ASSERT(domDoc); | 477 | PWM_ASSERT(domDoc); |
473 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 478 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
474 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 479 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
475 | domDoc->appendChild(root); | 480 | domDoc->appendChild(root); |
476 | return root; | 481 | return root; |
477 | } | 482 | } |
478 | 483 | ||
479 | bool Serializer::addCategories(QDomElement *e, | 484 | bool Serializer::addCategories(QDomElement *e, |
480 | const vector<PwMCategoryItem> &dta) | 485 | const vector<PwMCategoryItem> &dta) |
481 | { | 486 | { |
482 | unsigned int numCat = dta.size(), i; | 487 | unsigned int numCat = dta.size(), i; |
483 | QString curId, curName; | 488 | QString curId, curName; |
484 | QDomElement curCat; | 489 | QDomElement curCat; |
485 | 490 | ||
486 | for (i = 0; i < numCat; ++i) { | 491 | for (i = 0; i < numCat; ++i) { |
487 | curId = CAT_PREFIX_WR; | 492 | curId = CAT_PREFIX_WR; |
488 | curId += tostr(i).c_str(); | 493 | curId += tostr(i).c_str(); |
489 | curName = dta[i].name.c_str(); | 494 | curName = dta[i].name.c_str(); |
490 | curCat = domDoc->createElement(curId); | 495 | curCat = domDoc->createElement(curId); |
491 | curCat.setAttribute(CAT_NAME_WR, curName); | 496 | curCat.setAttribute(CAT_NAME_WR, curName); |
492 | if (!addEntries(&curCat, dta[i].d)) { | 497 | if (!addEntries(&curCat, dta[i].d)) { |
493 | return false; | 498 | return false; |
494 | } | 499 | } |
495 | e->appendChild(curCat); | 500 | e->appendChild(curCat); |
496 | } | 501 | } |
497 | return true; | 502 | return true; |
498 | } | 503 | } |
499 | 504 | ||
500 | bool Serializer::addEntries(QDomElement *e, | 505 | bool Serializer::addEntries(QDomElement *e, |
501 | const vector<PwMDataItem> &dta) | 506 | const vector<PwMDataItem> &dta) |
502 | { | 507 | { |
503 | unsigned int numEntr = dta.size(), i; | 508 | unsigned int numEntr = dta.size(), i; |
504 | QString curId; | 509 | QString curId; |
505 | QDomElement curEntr; | 510 | QDomElement curEntr; |
506 | 511 | ||
507 | for (i = 0; i < numEntr; ++i) { | 512 | for (i = 0; i < numEntr; ++i) { |
508 | curId = ENTRY_PREFIX_WR; | 513 | curId = ENTRY_PREFIX_WR; |
509 | curId += tostr(i).c_str(); | 514 | curId += tostr(i).c_str(); |
510 | curEntr = domDoc->createElement(curId); | 515 | curEntr = domDoc->createElement(curId); |
511 | if (!writeEntry(&curEntr, dta[i])) { | 516 | if (!writeEntry(&curEntr, dta[i])) { |
512 | return false; | 517 | return false; |
513 | } | 518 | } |
514 | e->appendChild(curEntr); | 519 | e->appendChild(curEntr); |
515 | } | 520 | } |
516 | return true; | 521 | return true; |
517 | } | 522 | } |
518 | 523 | ||
519 | bool Serializer::writeEntry(QDomElement *e, | 524 | bool Serializer::writeEntry(QDomElement *e, |
520 | const PwMDataItem &_dta) | 525 | const PwMDataItem &_dta) |
521 | { | 526 | { |
522 | #if WRITE_CDATA_SEC != 0 | 527 | #if WRITE_CDATA_SEC != 0 |
523 | # define new_text(x)domDoc->createCDATASection(x) | 528 | # define new_text(x)domDoc->createCDATASection(x) |
524 | QDomCDATASection curText; | 529 | QDomCDATASection curText; |
525 | #else | 530 | #else |
526 | # define new_text(x)domDoc->createTextNode(x) | 531 | # define new_text(x)domDoc->createTextNode(x) |
527 | QDomText curText; | 532 | QDomText curText; |
528 | #endif | 533 | #endif |
529 | 534 | ||
530 | QDomText plainText; | 535 | QDomText plainText; |
531 | QDomElement tag; | 536 | QDomElement tag; |
532 | 537 | ||
533 | // begin -- This is for compatibility with the old serializer | 538 | // begin -- This is for compatibility with the old serializer |
534 | PwMDataItem dta = _dta; | 539 | PwMDataItem dta = _dta; |
535 | if (!dta.desc.size()) | 540 | if (!dta.desc.size()) |
536 | dta.desc = " "; | 541 | dta.desc = " "; |
537 | if (!dta.name.size()) | 542 | if (!dta.name.size()) |
538 | dta.name = " "; | 543 | dta.name = " "; |
539 | if (!dta.pw.size()) | 544 | if (!dta.pw.size()) |
540 | dta.pw = " "; | 545 | dta.pw = " "; |
541 | if (!dta.comment.size()) | 546 | if (!dta.comment.size()) |
542 | dta.comment = " "; | 547 | dta.comment = " "; |
543 | if (!dta.url.size()) | 548 | if (!dta.url.size()) |
544 | dta.url = " "; | 549 | dta.url = " "; |
545 | if (!dta.launcher.size()) | 550 | if (!dta.launcher.size()) |
546 | dta.launcher = " "; | 551 | dta.launcher = " "; |
547 | // end -- This is for compatibility with the old serializer | 552 | // end -- This is for compatibility with the old serializer |
548 | 553 | ||
549 | tag = domDoc->createElement(ENTRY_DESC_WR); | 554 | tag = domDoc->createElement(ENTRY_DESC_WR); |
550 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 555 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
551 | tag.appendChild(curText); | 556 | tag.appendChild(curText); |
552 | e->appendChild(tag); | 557 | e->appendChild(tag); |
553 | 558 | ||
554 | tag = domDoc->createElement(ENTRY_NAME_WR); | 559 | tag = domDoc->createElement(ENTRY_NAME_WR); |
555 | curText = new_text(escapeEntryData(dta.name.c_str())); | 560 | curText = new_text(escapeEntryData(dta.name.c_str())); |
556 | tag.appendChild(curText); | 561 | tag.appendChild(curText); |
557 | e->appendChild(tag); | 562 | e->appendChild(tag); |
558 | 563 | ||
559 | tag = domDoc->createElement(ENTRY_PW_WR); | 564 | tag = domDoc->createElement(ENTRY_PW_WR); |
560 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 565 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
561 | tag.appendChild(curText); | 566 | tag.appendChild(curText); |
562 | e->appendChild(tag); | 567 | e->appendChild(tag); |
563 | 568 | ||
564 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 569 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
565 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 570 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
566 | tag.appendChild(curText); | 571 | tag.appendChild(curText); |
567 | e->appendChild(tag); | 572 | e->appendChild(tag); |
568 | 573 | ||
569 | tag = domDoc->createElement(ENTRY_URL_WR); | 574 | tag = domDoc->createElement(ENTRY_URL_WR); |
570 | curText = new_text(escapeEntryData(dta.url.c_str())); | 575 | curText = new_text(escapeEntryData(dta.url.c_str())); |
571 | tag.appendChild(curText); | 576 | tag.appendChild(curText); |
572 | e->appendChild(tag); | 577 | e->appendChild(tag); |
573 | 578 | ||
574 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 579 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
575 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 580 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
576 | tag.appendChild(curText); | 581 | tag.appendChild(curText); |
577 | e->appendChild(tag); | 582 | e->appendChild(tag); |
578 | 583 | ||
579 | tag = domDoc->createElement(ENTRY_LVP_WR); | 584 | tag = domDoc->createElement(ENTRY_LVP_WR); |
580 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 585 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
581 | tag.appendChild(plainText); | 586 | tag.appendChild(plainText); |
582 | e->appendChild(tag); | 587 | e->appendChild(tag); |
583 | 588 | ||
584 | tag = domDoc->createElement(ENTRY_BIN_WR); | 589 | tag = domDoc->createElement(ENTRY_BIN_WR); |
585 | if (dta.binary) | 590 | if (dta.binary) |
586 | plainText = domDoc->createTextNode("1"); | 591 | plainText = domDoc->createTextNode("1"); |
587 | else | 592 | else |
588 | plainText = domDoc->createTextNode("0"); | 593 | plainText = domDoc->createTextNode("0"); |
589 | tag.appendChild(plainText); | 594 | tag.appendChild(plainText); |
590 | e->appendChild(tag); | 595 | e->appendChild(tag); |
591 | 596 | ||
592 | tag = domDoc->createElement(ENTRY_META_WR); | 597 | tag = domDoc->createElement(ENTRY_META_WR); |
593 | if (!writeMeta(&tag, dta.meta)) | 598 | if (!writeMeta(&tag, dta.meta)) |
594 | return false; | 599 | return false; |
595 | e->appendChild(tag); | 600 | e->appendChild(tag); |
596 | 601 | ||
597 | #undef new_text | 602 | #undef new_text |
598 | return true; | 603 | return true; |
599 | } | 604 | } |
600 | 605 | ||
601 | bool Serializer::writeMeta(QDomElement *e, | 606 | bool Serializer::writeMeta(QDomElement *e, |
602 | const PwMMetaData &dta) | 607 | const PwMMetaData &dta) |
603 | { | 608 | { |
604 | QDomText text; | 609 | QDomText text; |
605 | QDomElement tag; | 610 | QDomElement tag; |
606 | 611 | ||
607 | tag = domDoc->createElement(META_CREATE_DATE); | 612 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
613 | //So do not transform an empty value at all. | ||
614 | if (dta.create.isValid()) | ||
615 | { | ||
616 | tag = domDoc->createElement(META_CREATE_DATE); | ||
608 | #ifndef PWM_EMBEDDED | 617 | #ifndef PWM_EMBEDDED |
609 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 618 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
610 | #else | 619 | #else |
611 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 620 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
612 | #endif | 621 | #endif |
613 | tag.appendChild(text); | 622 | tag.appendChild(text); |
614 | e->appendChild(tag); | 623 | e->appendChild(tag); |
624 | } | ||
615 | 625 | ||
616 | tag = domDoc->createElement(META_VALID_DATE); | 626 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
627 | //So do not transform an empty value at all. | ||
628 | if (dta.valid.isValid()) | ||
629 | { | ||
630 | tag = domDoc->createElement(META_VALID_DATE); | ||
617 | #ifndef PWM_EMBEDDED | 631 | #ifndef PWM_EMBEDDED |
618 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 632 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
619 | #else | 633 | #else |
620 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 634 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
621 | #endif | 635 | #endif |
622 | tag.appendChild(text); | 636 | tag.appendChild(text); |
623 | e->appendChild(tag); | 637 | e->appendChild(tag); |
638 | } | ||
624 | 639 | ||
625 | tag = domDoc->createElement(META_EXPIRE_DATE); | 640 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
641 | //So do not transform an empty value at all. | ||
642 | if (dta.expire.isValid()) | ||
643 | { | ||
644 | tag = domDoc->createElement(META_EXPIRE_DATE); | ||
626 | #ifndef PWM_EMBEDDED | 645 | #ifndef PWM_EMBEDDED |
627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 646 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
628 | #else | 647 | #else |
629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 648 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
630 | #endif | 649 | #endif |
631 | tag.appendChild(text); | 650 | tag.appendChild(text); |
632 | e->appendChild(tag); | 651 | e->appendChild(tag); |
652 | } | ||
633 | 653 | ||
634 | tag = domDoc->createElement(META_UPDATE_DATE); | 654 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
655 | //So do not transform an empty value at all. | ||
656 | if (dta.update.isValid()) | ||
657 | { | ||
658 | tag = domDoc->createElement(META_UPDATE_DATE); | ||
635 | #ifndef PWM_EMBEDDED | 659 | #ifndef PWM_EMBEDDED |
636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 660 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
637 | #else | 661 | #else |
638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 662 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
639 | #endif | 663 | #endif |
640 | tag.appendChild(text); | 664 | tag.appendChild(text); |
641 | e->appendChild(tag); | 665 | e->appendChild(tag); |
666 | } | ||
642 | 667 | ||
643 | tag = domDoc->createElement(META_UPDATE_INT); | 668 | tag = domDoc->createElement(META_UPDATE_INT); |
644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 669 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
645 | tag.appendChild(text); | 670 | tag.appendChild(text); |
646 | e->appendChild(tag); | 671 | e->appendChild(tag); |
647 | 672 | ||
648 | tag = domDoc->createElement(META_UNIQUEID); | 673 | tag = domDoc->createElement(META_UNIQUEID); |
649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); | 674 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); |
650 | tag.appendChild(text); | 675 | tag.appendChild(text); |
651 | e->appendChild(tag); | 676 | e->appendChild(tag); |
652 | 677 | ||
653 | #undef new_text | 678 | #undef new_text |
654 | return true; | 679 | return true; |
655 | } | 680 | } |
656 | 681 | ||
657 | QString Serializer::escapeEntryData(QString dta) | 682 | QString Serializer::escapeEntryData(QString dta) |
658 | { | 683 | { |
659 | #ifndef PWM_EMBEDDED | 684 | #ifndef PWM_EMBEDDED |
660 | dta.replace('\n', "$>--endl--<$"); | 685 | dta.replace('\n', "$>--endl--<$"); |
661 | dta.replace("]]>", "||>"); | 686 | dta.replace("]]>", "||>"); |
662 | #else | 687 | #else |
663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 688 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
664 | dta.replace(QRegExp("]]>"), "||>"); | 689 | dta.replace(QRegExp("]]>"), "||>"); |
665 | #endif | 690 | #endif |
666 | return dta; | 691 | return dta; |
667 | } | 692 | } |
668 | 693 | ||
669 | QString Serializer::unescapeEntryData(QString dta) | 694 | QString Serializer::unescapeEntryData(QString dta) |
670 | { | 695 | { |
671 | #ifndef PWM_EMBEDDED | 696 | #ifndef PWM_EMBEDDED |
672 | dta.replace("$>--endl--<$", "\n"); | 697 | dta.replace("$>--endl--<$", "\n"); |
673 | dta.replace("||>", "]]>"); | 698 | dta.replace("||>", "]]>"); |
674 | #else | 699 | #else |
675 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 700 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); |
676 | dta.replace(QRegExp("||>"), "]]>"); | 701 | dta.replace(QRegExp("||>"), "]]>"); |
677 | #endif | 702 | #endif |
678 | return dta; | 703 | return dta; |
679 | } | 704 | } |
680 | 705 | ||
681 | 706 | ||
682 | //US ENH: the following methods are getting used to write/read sync entries | 707 | //US ENH: the following methods are getting used to write/read sync entries |
683 | /** read the syncentries in the node "n" */ | 708 | /** read the syncentries in the node "n" */ |
684 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) | 709 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) |
685 | { | 710 | { |
686 | QDomNodeList nl(n.childNodes()); | 711 | QDomNodeList nl(n.childNodes()); |
687 | QDomNode cur; | 712 | QDomNode cur; |
688 | 713 | ||
689 | QString devicename, val; | 714 | QString devicename, val; |
690 | unsigned int numSync = nl.count(), i; | 715 | unsigned int numSync = nl.count(), i; |
691 | PwMSyncItem curSync; | 716 | PwMSyncItem curSync; |
692 | bool ok = true; | 717 | bool ok = true; |
693 | 718 | ||
694 | if (!numSync) { | 719 | if (!numSync) { |
695 | //no sync entries is a possible result | 720 | //no sync entries is a possible result |
696 | printDebug("Serializer::readSyncData(): empty"); | 721 | printDebug("Serializer::readSyncData(): empty"); |
697 | return true; | 722 | return true; |
698 | } | 723 | } |
699 | for (i = 0; i < numSync; ++i) { | 724 | for (i = 0; i < numSync; ++i) { |
700 | cur = nl.item(i); | 725 | cur = nl.item(i); |
701 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { | 726 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { |
702 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); | 727 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); |
703 | val = cur.toElement().text(); | 728 | val = cur.toElement().text(); |
704 | 729 | ||
705 | if ((val == "") || (devicename == QString::null)) { | 730 | if ((val == "") || (devicename == QString::null)) { |
706 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); | 731 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); |
707 | continue; | 732 | continue; |
708 | } | 733 | } |
709 | 734 | ||
710 | curSync.syncName = devicename; | 735 | curSync.syncName = devicename; |
711 | #ifndef PWM_EMBEDDED | 736 | #ifndef PWM_EMBEDDED |
712 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); | 737 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); |
713 | #else | 738 | #else |
714 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 739 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
715 | if (ok == false) | 740 | if (ok == false) |
716 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); | 741 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); |
717 | 742 | ||
718 | #endif | 743 | #endif |
719 | dta->push_back(curSync); | 744 | dta->push_back(curSync); |
720 | } | 745 | } |
721 | } | 746 | } |
722 | return true; | 747 | return true; |
723 | 748 | ||
724 | } | 749 | } |
725 | 750 | ||
726 | 751 | ||
727 | 752 | ||
728 | bool Serializer::addSyncData(QDomElement *e, | 753 | bool Serializer::addSyncData(QDomElement *e, |
729 | const vector<PwMSyncItem> &dta) | 754 | const vector<PwMSyncItem> &dta) |
730 | { | 755 | { |
731 | unsigned int numSync = dta.size(), i; | 756 | unsigned int numSync = dta.size(), i; |
732 | QString curId, curDeviceName; | 757 | QString curId, curDeviceName; |
733 | QDomElement curSync, curSyncDate; | 758 | QDomElement curSync; |
734 | QDomText text; | 759 | QDomText text; |
735 | 760 | ||
736 | for (i = 0; i < numSync; ++i) { | 761 | for (i = 0; i < numSync; ++i) { |
737 | curId = SYNC_TARGET_PREFIX; | 762 | curId = SYNC_TARGET_PREFIX; |
738 | curId += tostr(i).c_str(); | 763 | curId += tostr(i).c_str(); |
739 | curDeviceName = dta[i].syncName.c_str(); | 764 | curDeviceName = dta[i].syncName.c_str(); |
740 | curSync = domDoc->createElement(curId); | 765 | curSync = domDoc->createElement(curId); |
741 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); | 766 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); |
742 | 767 | ||
743 | #ifndef PWM_EMBEDDED | 768 | #ifndef PWM_EMBEDDED |
744 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); | 769 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); |
745 | #else | 770 | #else |
746 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); | 771 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); |
747 | #endif | 772 | #endif |
748 | curSyncDate.appendChild(text); | 773 | curSync.appendChild(text); |
749 | curSync.appendChild(curSyncDate); | ||
750 | 774 | ||
751 | e->appendChild(curSync); | 775 | e->appendChild(curSync); |
752 | 776 | ||
753 | } | 777 | } |
754 | return true; | 778 | return true; |
755 | } | 779 | } |
756 | 780 | ||