author | zautrix <zautrix> | 2004-10-23 09:04:58 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-23 09:04:58 (UTC) |
commit | ba2583db0431059cd7368be23c9653e81af16d29 (patch) (unidiff) | |
tree | 75d4a662731651d391a5e5bb60e89d1245781593 | |
parent | eb0bc46bfbba45a84c7353f1c9c4dba27273f021 (diff) | |
download | kdepimpi-ba2583db0431059cd7368be23c9653e81af16d29.zip kdepimpi-ba2583db0431059cd7368be23c9653e81af16d29.tar.gz kdepimpi-ba2583db0431059cd7368be23c9653e81af16d29.tar.bz2 |
fixed desktop descape bug. added statusbar to embedded and desktop
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 8 |
3 files changed, 18 insertions, 10 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index 9798e8e..b7b5307 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,410 +1,412 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include <klocale.h> | 20 | #include <klocale.h> |
21 | #include <klistview.h> | 21 | #include <klistview.h> |
22 | #include <ktoolbar.h> | 22 | #include <ktoolbar.h> |
23 | #include <kfiledialog.h> | 23 | #include <kfiledialog.h> |
24 | #include <kiconloader.h> | 24 | #include <kiconloader.h> |
25 | #include <kmessagebox.h> | 25 | #include <kmessagebox.h> |
26 | 26 | ||
27 | #include <qstatusbar.h> | ||
28 | |||
27 | #ifndef PWM_EMBEDDED | 29 | #ifndef PWM_EMBEDDED |
28 | #include <kmenubar.h> | 30 | #include <kmenubar.h> |
29 | #include <kstatusbar.h> | 31 | #include <kstatusbar.h> |
30 | #include <dcopclient.h> | 32 | #include <dcopclient.h> |
31 | #include "configwndimpl.h" | 33 | #include "configwndimpl.h" |
32 | #include "configuration.h" | 34 | #include "configuration.h" |
33 | #else | 35 | #else |
34 | #include <qmenubar.h> | 36 | #include <qmenubar.h> |
35 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
36 | #include <pwmprefs.h> | 38 | #include <pwmprefs.h> |
37 | #include <kpimglobalprefs.h> | 39 | #include <kpimglobalprefs.h> |
38 | #include <kcmconfigs/kcmpwmconfig.h> | 40 | #include <kcmconfigs/kcmpwmconfig.h> |
39 | #include <kcmconfigs/kcmkdepimconfig.h> | 41 | #include <kcmconfigs/kcmkdepimconfig.h> |
40 | #include <kcmultidialog.h> | 42 | #include <kcmultidialog.h> |
41 | #endif | 43 | #endif |
42 | 44 | ||
43 | 45 | ||
44 | #ifndef DESKTOP_VERSION | 46 | #ifndef DESKTOP_VERSION |
45 | #include <qpe/global.h> | 47 | #include <qpe/global.h> |
46 | #endif | 48 | #endif |
47 | 49 | ||
48 | #include <qpixmap.h> | 50 | #include <qpixmap.h> |
49 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
50 | #include <qspinbox.h> | 52 | #include <qspinbox.h> |
51 | #include <qlineedit.h> | 53 | #include <qlineedit.h> |
52 | #include <qfileinfo.h> | 54 | #include <qfileinfo.h> |
53 | #include <qclipboard.h> | 55 | #include <qclipboard.h> |
54 | 56 | ||
55 | 57 | ||
56 | #include <stdio.h> | 58 | #include <stdio.h> |
57 | 59 | ||
58 | #include "pwm.h" | 60 | #include "pwm.h" |
59 | #include "pwminit.h" | 61 | #include "pwminit.h" |
60 | #include "pwmprint.h" | 62 | #include "pwmprint.h" |
61 | #include "addentrywndimpl.h" | 63 | #include "addentrywndimpl.h" |
62 | #include "globalstuff.h" | 64 | #include "globalstuff.h" |
63 | #include "findwndimpl.h" | 65 | #include "findwndimpl.h" |
64 | #include "csv.h" | 66 | #include "csv.h" |
65 | 67 | ||
66 | #ifdef CONFIG_KWALLETIF | 68 | #ifdef CONFIG_KWALLETIF |
67 | # include "kwalletif.h" | 69 | # include "kwalletif.h" |
68 | # include "kwalletemu.h" | 70 | # include "kwalletemu.h" |
69 | #endif | 71 | #endif |
70 | #ifdef CONFIG_KEYCARD | 72 | #ifdef CONFIG_KEYCARD |
71 | # include "pwmkeycard.h" | 73 | # include "pwmkeycard.h" |
72 | #endif | 74 | #endif |
73 | 75 | ||
74 | 76 | ||
75 | #define DEFAULT_SIZE (QSize(700, 400)) | 77 | #define DEFAULT_SIZE (QSize(700, 400)) |
76 | 78 | ||
77 | // Button IDs for "file" popup menu | 79 | // Button IDs for "file" popup menu |
78 | enum { | 80 | enum { |
79 | BUTTON_POPUP_FILE_NEW = 0, | 81 | BUTTON_POPUP_FILE_NEW = 0, |
80 | BUTTON_POPUP_FILE_OPEN, | 82 | BUTTON_POPUP_FILE_OPEN, |
81 | BUTTON_POPUP_FILE_CLOSE, | 83 | BUTTON_POPUP_FILE_CLOSE, |
82 | BUTTON_POPUP_FILE_SAVE, | 84 | BUTTON_POPUP_FILE_SAVE, |
83 | BUTTON_POPUP_FILE_SAVEAS, | 85 | BUTTON_POPUP_FILE_SAVEAS, |
84 | BUTTON_POPUP_FILE_EXPORT, | 86 | BUTTON_POPUP_FILE_EXPORT, |
85 | BUTTON_POPUP_FILE_IMPORT, | 87 | BUTTON_POPUP_FILE_IMPORT, |
86 | BUTTON_POPUP_FILE_PRINT, | 88 | BUTTON_POPUP_FILE_PRINT, |
87 | BUTTON_POPUP_FILE_QUIT | 89 | BUTTON_POPUP_FILE_QUIT |
88 | }; | 90 | }; |
89 | // Button IDs for "manage" popup menu | 91 | // Button IDs for "manage" popup menu |
90 | enum { | 92 | enum { |
91 | BUTTON_POPUP_MANAGE_ADD = 0, | 93 | BUTTON_POPUP_MANAGE_ADD = 0, |
92 | BUTTON_POPUP_MANAGE_EDIT, | 94 | BUTTON_POPUP_MANAGE_EDIT, |
93 | BUTTON_POPUP_MANAGE_DEL, | 95 | BUTTON_POPUP_MANAGE_DEL, |
94 | BUTTON_POPUP_MANAGE_CHANGEMP | 96 | BUTTON_POPUP_MANAGE_CHANGEMP |
95 | }; | 97 | }; |
96 | // Button IDs for chipcard popup menu | 98 | // Button IDs for chipcard popup menu |
97 | enum { | 99 | enum { |
98 | #ifdef CONFIG_KEYCARD | 100 | #ifdef CONFIG_KEYCARD |
99 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, | 101 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, |
100 | BUTTON_POPUP_CHIPCARD_DEL, | 102 | BUTTON_POPUP_CHIPCARD_DEL, |
101 | BUTTON_POPUP_CHIPCARD_READID, | 103 | BUTTON_POPUP_CHIPCARD_READID, |
102 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, | 104 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, |
103 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP | 105 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP |
104 | #else // CONFIG_KEYCARD | 106 | #else // CONFIG_KEYCARD |
105 | BUTTON_POPUP_CHIPCARD_NO = 0 | 107 | BUTTON_POPUP_CHIPCARD_NO = 0 |
106 | #endif // CONFIG_KEYCARD | 108 | #endif // CONFIG_KEYCARD |
107 | }; | 109 | }; |
108 | // Button IDs for "view" popup menu | 110 | // Button IDs for "view" popup menu |
109 | enum { | 111 | enum { |
110 | BUTTON_POPUP_VIEW_FIND = 0, | 112 | BUTTON_POPUP_VIEW_FIND = 0, |
111 | BUTTON_POPUP_VIEW_LOCK, | 113 | BUTTON_POPUP_VIEW_LOCK, |
112 | BUTTON_POPUP_VIEW_DEEPLOCK, | 114 | BUTTON_POPUP_VIEW_DEEPLOCK, |
113 | BUTTON_POPUP_VIEW_UNLOCK | 115 | BUTTON_POPUP_VIEW_UNLOCK |
114 | }; | 116 | }; |
115 | // Button IDs for "options" popup menu | 117 | // Button IDs for "options" popup menu |
116 | enum { | 118 | enum { |
117 | BUTTON_POPUP_OPTIONS_CONFIG = 0 | 119 | BUTTON_POPUP_OPTIONS_CONFIG = 0 |
118 | }; | 120 | }; |
119 | // Button IDs for "export" popup menu (in "file" popup menu) | 121 | // Button IDs for "export" popup menu (in "file" popup menu) |
120 | enum { | 122 | enum { |
121 | BUTTON_POPUP_EXPORT_TEXT = 0, | 123 | BUTTON_POPUP_EXPORT_TEXT = 0, |
122 | BUTTON_POPUP_EXPORT_GPASMAN, | 124 | BUTTON_POPUP_EXPORT_GPASMAN, |
123 | BUTTON_POPUP_EXPORT_CSV | 125 | BUTTON_POPUP_EXPORT_CSV |
124 | #ifdef CONFIG_KWALLETIF | 126 | #ifdef CONFIG_KWALLETIF |
125 | ,BUTTON_POPUP_EXPORT_KWALLET | 127 | ,BUTTON_POPUP_EXPORT_KWALLET |
126 | #endif | 128 | #endif |
127 | }; | 129 | }; |
128 | // Button IDs for "import" popup menu (in "file" popup menu) | 130 | // Button IDs for "import" popup menu (in "file" popup menu) |
129 | enum { | 131 | enum { |
130 | BUTTON_POPUP_IMPORT_TEXT = 0, | 132 | BUTTON_POPUP_IMPORT_TEXT = 0, |
131 | BUTTON_POPUP_IMPORT_GPASMAN, | 133 | BUTTON_POPUP_IMPORT_GPASMAN, |
132 | BUTTON_POPUP_IMPORT_CSV | 134 | BUTTON_POPUP_IMPORT_CSV |
133 | #ifdef CONFIG_KWALLETIF | 135 | #ifdef CONFIG_KWALLETIF |
134 | ,BUTTON_POPUP_IMPORT_KWALLET | 136 | ,BUTTON_POPUP_IMPORT_KWALLET |
135 | #endif | 137 | #endif |
136 | }; | 138 | }; |
137 | 139 | ||
138 | #ifdef PWM_EMBEDDED | 140 | #ifdef PWM_EMBEDDED |
139 | // Button IDs for "help" popup menu | 141 | // Button IDs for "help" popup menu |
140 | enum { | 142 | enum { |
141 | BUTTON_POPUP_HELP_LICENSE = 0, | 143 | BUTTON_POPUP_HELP_LICENSE = 0, |
142 | BUTTON_POPUP_HELP_FAQ, | 144 | BUTTON_POPUP_HELP_FAQ, |
143 | BUTTON_POPUP_HELP_ABOUT, | 145 | BUTTON_POPUP_HELP_ABOUT, |
144 | BUTTON_POPUP_HELP_SYNC, | 146 | BUTTON_POPUP_HELP_SYNC, |
145 | BUTTON_POPUP_HELP_WHATSNEW | 147 | BUTTON_POPUP_HELP_WHATSNEW |
146 | }; | 148 | }; |
147 | #endif | 149 | #endif |
148 | 150 | ||
149 | // Button IDs for toolbar | 151 | // Button IDs for toolbar |
150 | enum { | 152 | enum { |
151 | BUTTON_TOOL_NEW = 0, | 153 | BUTTON_TOOL_NEW = 0, |
152 | BUTTON_TOOL_OPEN, | 154 | BUTTON_TOOL_OPEN, |
153 | BUTTON_TOOL_SAVE, | 155 | BUTTON_TOOL_SAVE, |
154 | BUTTON_TOOL_SAVEAS, | 156 | BUTTON_TOOL_SAVEAS, |
155 | BUTTON_TOOL_PRINT, | 157 | BUTTON_TOOL_PRINT, |
156 | BUTTON_TOOL_ADD, | 158 | BUTTON_TOOL_ADD, |
157 | BUTTON_TOOL_EDIT, | 159 | BUTTON_TOOL_EDIT, |
158 | BUTTON_TOOL_DEL, | 160 | BUTTON_TOOL_DEL, |
159 | BUTTON_TOOL_FIND, | 161 | BUTTON_TOOL_FIND, |
160 | BUTTON_TOOL_LOCK, | 162 | BUTTON_TOOL_LOCK, |
161 | BUTTON_TOOL_DEEPLOCK, | 163 | BUTTON_TOOL_DEEPLOCK, |
162 | BUTTON_TOOL_UNLOCK | 164 | BUTTON_TOOL_UNLOCK |
163 | }; | 165 | }; |
164 | 166 | ||
165 | 167 | ||
166 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 168 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
167 | bool virginity, | 169 | bool virginity, |
168 | QWidget *parent, const char *name) | 170 | QWidget *parent, const char *name) |
169 | : KMainWindow(parent, "HALLO") | 171 | : KMainWindow(parent, "HALLO") |
170 | , forceQuit (false) | 172 | , forceQuit (false) |
171 | , forceMinimizeToTray (false) | 173 | , forceMinimizeToTray (false) |
172 | { | 174 | { |
173 | virgin = !virginity; | 175 | virgin = !virginity; |
174 | init = _init; | 176 | init = _init; |
175 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 177 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
176 | this, SLOT(docClosed(PwMDoc *))); | 178 | this, SLOT(docClosed(PwMDoc *))); |
177 | initMenubar(); | 179 | initMenubar(); |
178 | initToolbar(); | 180 | initToolbar(); |
179 | initMetrics(); | 181 | initMetrics(); |
180 | setVirgin(virginity); | 182 | setVirgin(virginity); |
181 | setFocusPolicy(QWidget::WheelFocus); | 183 | setFocusPolicy(QWidget::WheelFocus); |
182 | #ifndef PWM_EMBEDDED | 184 | #ifndef PWM_EMBEDDED |
183 | statusBar()->show(); | 185 | statusBar()->show(); |
184 | #endif | 186 | #endif |
185 | view = makeNewListView(doc); | 187 | view = makeNewListView(doc); |
186 | setCentralWidget(view); | 188 | setCentralWidget(view); |
187 | updateCaption(); | 189 | updateCaption(); |
188 | showStatMsg(i18n("Ready.")); | 190 | showStatMsg(i18n("Ready.")); |
189 | } | 191 | } |
190 | 192 | ||
191 | PwM::~PwM() | 193 | PwM::~PwM() |
192 | { | 194 | { |
193 | //qDebug("PwM::~PwM()"); | 195 | //qDebug("PwM::~PwM()"); |
194 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 196 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
195 | this, SLOT(docClosed(PwMDoc *))); | 197 | this, SLOT(docClosed(PwMDoc *))); |
196 | conf()->confWndMainWndSize(size()); | 198 | conf()->confWndMainWndSize(size()); |
197 | emit closed(this); | 199 | emit closed(this); |
198 | //qDebug("PwM::~PwM() emited closed(this)"); | 200 | //qDebug("PwM::~PwM() emited closed(this)"); |
199 | delete view; | 201 | delete view; |
200 | } | 202 | } |
201 | 203 | ||
202 | void PwM::initMenubar() | 204 | void PwM::initMenubar() |
203 | { | 205 | { |
204 | KIconLoader* picons; | 206 | KIconLoader* picons; |
205 | #ifndef PWM_EMBEDDED | 207 | #ifndef PWM_EMBEDDED |
206 | KIconLoader icons; | 208 | KIconLoader icons; |
207 | picons = &icons; | 209 | picons = &icons; |
208 | #else | 210 | #else |
209 | picons = KGlobal::iconLoader(); | 211 | picons = KGlobal::iconLoader(); |
210 | 212 | ||
211 | 213 | ||
212 | syncPopup = new KPopupMenu(this); | 214 | syncPopup = new KPopupMenu(this); |
213 | 215 | ||
214 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); | 216 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); |
215 | syncManager->setBlockSave(false); | 217 | syncManager->setBlockSave(false); |
216 | 218 | ||
217 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 219 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
218 | syncManager->fillSyncMenu(); | 220 | syncManager->fillSyncMenu(); |
219 | 221 | ||
220 | #endif | 222 | #endif |
221 | filePopup = new KPopupMenu(this); | 223 | filePopup = new KPopupMenu(this); |
222 | importPopup = new KPopupMenu(filePopup); | 224 | importPopup = new KPopupMenu(filePopup); |
223 | exportPopup = new KPopupMenu(filePopup); | 225 | exportPopup = new KPopupMenu(filePopup); |
224 | managePopup = new KPopupMenu(this); | 226 | managePopup = new KPopupMenu(this); |
225 | #ifdef CONFIG_KEYCARD | 227 | #ifdef CONFIG_KEYCARD |
226 | chipcardPopup = new KPopupMenu(this); | 228 | chipcardPopup = new KPopupMenu(this); |
227 | #endif // CONFIG_KEYCARD | 229 | #endif // CONFIG_KEYCARD |
228 | viewPopup = new KPopupMenu(this); | 230 | viewPopup = new KPopupMenu(this); |
229 | optionsPopup = new KPopupMenu(this); | 231 | optionsPopup = new KPopupMenu(this); |
230 | 232 | ||
231 | // "file" popup menu | 233 | // "file" popup menu |
232 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 234 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
233 | i18n("&New"), this, | 235 | i18n("&New"), this, |
234 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 236 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
235 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 237 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
236 | i18n("&Open"), this, | 238 | i18n("&Open"), this, |
237 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 239 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
238 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 240 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
239 | i18n("&Close"), this, | 241 | i18n("&Close"), this, |
240 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 242 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
241 | filePopup->insertSeparator(); | 243 | filePopup->insertSeparator(); |
242 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 244 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
243 | i18n("&Save"), this, | 245 | i18n("&Save"), this, |
244 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 246 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
245 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 247 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
246 | i18n("Save &as..."), | 248 | i18n("Save &as..."), |
247 | this, SLOT(saveAs_slot()), 0, | 249 | this, SLOT(saveAs_slot()), 0, |
248 | BUTTON_POPUP_FILE_SAVEAS); | 250 | BUTTON_POPUP_FILE_SAVEAS); |
249 | filePopup->insertSeparator(); | 251 | filePopup->insertSeparator(); |
250 | // "file/export" popup menu | 252 | // "file/export" popup menu |
251 | exportPopup->insertItem(i18n("&Text-file..."), this, | 253 | exportPopup->insertItem(i18n("&Text-file..."), this, |
252 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 254 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
253 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 255 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
254 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 256 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
255 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 257 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
256 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); | 258 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); |
257 | #ifdef CONFIG_KWALLETIF | 259 | #ifdef CONFIG_KWALLETIF |
258 | exportPopup->insertItem(i18n("&KWallet..."), this, | 260 | exportPopup->insertItem(i18n("&KWallet..."), this, |
259 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 261 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
260 | #endif | 262 | #endif |
261 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 263 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
262 | i18n("E&xport"), exportPopup, | 264 | i18n("E&xport"), exportPopup, |
263 | BUTTON_POPUP_FILE_EXPORT); | 265 | BUTTON_POPUP_FILE_EXPORT); |
264 | // "file/import" popup menu | 266 | // "file/import" popup menu |
265 | importPopup->insertItem(i18n("&Text-file..."), this, | 267 | importPopup->insertItem(i18n("&Text-file..."), this, |
266 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 268 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
267 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 269 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
268 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 270 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
269 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 271 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
270 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); | 272 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); |
271 | #ifdef CONFIG_KWALLETIF | 273 | #ifdef CONFIG_KWALLETIF |
272 | importPopup->insertItem(i18n("&KWallet..."), this, | 274 | importPopup->insertItem(i18n("&KWallet..."), this, |
273 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 275 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
274 | #endif | 276 | #endif |
275 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 277 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
276 | i18n("I&mport"), importPopup, | 278 | i18n("I&mport"), importPopup, |
277 | BUTTON_POPUP_FILE_IMPORT); | 279 | BUTTON_POPUP_FILE_IMPORT); |
278 | filePopup->insertSeparator(); | 280 | filePopup->insertSeparator(); |
279 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 281 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
280 | i18n("&Print..."), this, | 282 | i18n("&Print..."), this, |
281 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 283 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
282 | filePopup->insertSeparator(); | 284 | filePopup->insertSeparator(); |
283 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 285 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
284 | i18n("&Quit"), this, | 286 | i18n("&Quit"), this, |
285 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 287 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
286 | menuBar()->insertItem(i18n("&File"), filePopup); | 288 | menuBar()->insertItem(i18n("&File"), filePopup); |
287 | // "manage" popup menu | 289 | // "manage" popup menu |
288 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 290 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
289 | i18n("&Add password"), this, | 291 | i18n("&Add password"), this, |
290 | SLOT(addPwd_slot()), 0, | 292 | SLOT(addPwd_slot()), 0, |
291 | BUTTON_POPUP_MANAGE_ADD); | 293 | BUTTON_POPUP_MANAGE_ADD); |
292 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 294 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
293 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 295 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
294 | BUTTON_POPUP_MANAGE_EDIT); | 296 | BUTTON_POPUP_MANAGE_EDIT); |
295 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 297 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
296 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 298 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
297 | 0, BUTTON_POPUP_MANAGE_DEL); | 299 | 0, BUTTON_POPUP_MANAGE_DEL); |
298 | managePopup->insertSeparator(); | 300 | managePopup->insertSeparator(); |
299 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 301 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
300 | i18n("Change &Master Password"), this, | 302 | i18n("Change &Master Password"), this, |
301 | SLOT(changeMasterPwd_slot()), 0, | 303 | SLOT(changeMasterPwd_slot()), 0, |
302 | BUTTON_POPUP_MANAGE_CHANGEMP); | 304 | BUTTON_POPUP_MANAGE_CHANGEMP); |
303 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 305 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
304 | // "chipcard" popup menu | 306 | // "chipcard" popup menu |
305 | #ifdef CONFIG_KEYCARD | 307 | #ifdef CONFIG_KEYCARD |
306 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 308 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
307 | i18n("&Generate new key-card"), this, | 309 | i18n("&Generate new key-card"), this, |
308 | SLOT(genNewCard_slot()), 0, | 310 | SLOT(genNewCard_slot()), 0, |
309 | BUTTON_POPUP_CHIPCARD_GENNEW); | 311 | BUTTON_POPUP_CHIPCARD_GENNEW); |
310 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 312 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
311 | i18n("&Erase key-card"), this, | 313 | i18n("&Erase key-card"), this, |
312 | SLOT(eraseCard_slot()), 0, | 314 | SLOT(eraseCard_slot()), 0, |
313 | BUTTON_POPUP_CHIPCARD_DEL); | 315 | BUTTON_POPUP_CHIPCARD_DEL); |
314 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 316 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
315 | i18n("Read card-&ID"), this, | 317 | i18n("Read card-&ID"), this, |
316 | SLOT(readCardId_slot()), 0, | 318 | SLOT(readCardId_slot()), 0, |
317 | BUTTON_POPUP_CHIPCARD_READID); | 319 | BUTTON_POPUP_CHIPCARD_READID); |
318 | chipcardPopup->insertSeparator(); | 320 | chipcardPopup->insertSeparator(); |
319 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 321 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
320 | i18n("&Make card backup-image"), this, | 322 | i18n("&Make card backup-image"), this, |
321 | SLOT(makeCardBackup_slot()), 0, | 323 | SLOT(makeCardBackup_slot()), 0, |
322 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 324 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
323 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 325 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
324 | i18n("&Replay card backup-image"), this, | 326 | i18n("&Replay card backup-image"), this, |
325 | SLOT(replayCardBackup_slot()), 0, | 327 | SLOT(replayCardBackup_slot()), 0, |
326 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 328 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
327 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 329 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
328 | #endif // CONFIG_KEYCARD | 330 | #endif // CONFIG_KEYCARD |
329 | // "view" popup menu | 331 | // "view" popup menu |
330 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 332 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
331 | i18n("&Find"), this, | 333 | i18n("&Find"), this, |
332 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 334 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
333 | viewPopup->insertSeparator(); | 335 | viewPopup->insertSeparator(); |
334 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 336 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
335 | i18n("&Lock all entries"), this, | 337 | i18n("&Lock all entries"), this, |
336 | SLOT(lockWnd_slot()), 0, | 338 | SLOT(lockWnd_slot()), 0, |
337 | BUTTON_POPUP_VIEW_LOCK); | 339 | BUTTON_POPUP_VIEW_LOCK); |
338 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 340 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
339 | i18n("&Deep-lock all entries"), this, | 341 | i18n("&Deep-lock all entries"), this, |
340 | SLOT(deepLockWnd_slot()), 0, | 342 | SLOT(deepLockWnd_slot()), 0, |
341 | BUTTON_POPUP_VIEW_DEEPLOCK); | 343 | BUTTON_POPUP_VIEW_DEEPLOCK); |
342 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 344 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
343 | i18n("&Unlock all entries"), this, | 345 | i18n("&Unlock all entries"), this, |
344 | SLOT(unlockWnd_slot()), 0, | 346 | SLOT(unlockWnd_slot()), 0, |
345 | BUTTON_POPUP_VIEW_UNLOCK); | 347 | BUTTON_POPUP_VIEW_UNLOCK); |
346 | menuBar()->insertItem(i18n("&View"), viewPopup); | 348 | menuBar()->insertItem(i18n("&View"), viewPopup); |
347 | // "options" popup menu | 349 | // "options" popup menu |
348 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 350 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
349 | i18n("&Configure..."), this, | 351 | i18n("&Configure..."), this, |
350 | SLOT(config_slot()), | 352 | SLOT(config_slot()), |
351 | BUTTON_POPUP_OPTIONS_CONFIG); | 353 | BUTTON_POPUP_OPTIONS_CONFIG); |
352 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 354 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
353 | // "help" popup menu | 355 | // "help" popup menu |
354 | #ifndef PWM_EMBEDDED | 356 | #ifndef PWM_EMBEDDED |
355 | helpPopup = helpMenu(QString::null, false); | 357 | helpPopup = helpMenu(QString::null, false); |
356 | #else | 358 | #else |
357 | menuBar()->insertItem(i18n("&Sync"), syncPopup); | 359 | menuBar()->insertItem(i18n("&Sync"), syncPopup); |
358 | 360 | ||
359 | 361 | ||
360 | 362 | ||
361 | 363 | ||
362 | 364 | ||
363 | helpPopup = new KPopupMenu(this); | 365 | helpPopup = new KPopupMenu(this); |
364 | 366 | ||
365 | 367 | ||
366 | helpPopup->insertItem(i18n("&License"), this, | 368 | helpPopup->insertItem(i18n("&License"), this, |
367 | SLOT(showLicense_slot()), 0, | 369 | SLOT(showLicense_slot()), 0, |
368 | BUTTON_POPUP_HELP_LICENSE); | 370 | BUTTON_POPUP_HELP_LICENSE); |
369 | 371 | ||
370 | helpPopup->insertItem(i18n("&Faq"), this, | 372 | helpPopup->insertItem(i18n("&Faq"), this, |
371 | SLOT(faq_slot()), 0, | 373 | SLOT(faq_slot()), 0, |
372 | BUTTON_POPUP_HELP_FAQ); | 374 | BUTTON_POPUP_HELP_FAQ); |
373 | 375 | ||
374 | helpPopup->insertItem(i18n("&About PwManager"), this, | 376 | helpPopup->insertItem(i18n("&About PwManager"), this, |
375 | SLOT(createAboutData_slot()), 0, | 377 | SLOT(createAboutData_slot()), 0, |
376 | BUTTON_POPUP_HELP_ABOUT); | 378 | BUTTON_POPUP_HELP_ABOUT); |
377 | 379 | ||
378 | helpPopup->insertItem(i18n("&Sync HowTo"), this, | 380 | helpPopup->insertItem(i18n("&Sync HowTo"), this, |
379 | SLOT(syncHowTo_slot()), 0, | 381 | SLOT(syncHowTo_slot()), 0, |
380 | BUTTON_POPUP_HELP_SYNC); | 382 | BUTTON_POPUP_HELP_SYNC); |
381 | 383 | ||
382 | helpPopup->insertItem(i18n("&What's New"), this, | 384 | helpPopup->insertItem(i18n("&What's New"), this, |
383 | SLOT(whatsnew_slot()), 0, | 385 | SLOT(whatsnew_slot()), 0, |
384 | BUTTON_POPUP_HELP_WHATSNEW); | 386 | BUTTON_POPUP_HELP_WHATSNEW); |
385 | 387 | ||
386 | #endif | 388 | #endif |
387 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 389 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
388 | 390 | ||
389 | } | 391 | } |
390 | 392 | ||
391 | void PwM::initToolbar() | 393 | void PwM::initToolbar() |
392 | { | 394 | { |
393 | KIconLoader* picons; | 395 | KIconLoader* picons; |
394 | #ifndef PWM_EMBEDDED | 396 | #ifndef PWM_EMBEDDED |
395 | KIconLoader icons; | 397 | KIconLoader icons; |
396 | picons = &icons; | 398 | picons = &icons; |
397 | #else | 399 | #else |
398 | picons = KGlobal::iconLoader(); | 400 | picons = KGlobal::iconLoader(); |
399 | #endif | 401 | #endif |
400 | 402 | ||
401 | #ifdef PWM_EMBEDDED | 403 | #ifdef PWM_EMBEDDED |
402 | if ( QApplication::desktop()->width() > 320 ) | 404 | if ( QApplication::desktop()->width() > 320 ) |
403 | #endif | 405 | #endif |
404 | { | 406 | { |
405 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 407 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
406 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 408 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
407 | SLOT(new_slot()), true, i18n("New")); | 409 | SLOT(new_slot()), true, i18n("New")); |
408 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 410 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
409 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 411 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
410 | SLOT(open_slot()), true, i18n("Open")); | 412 | SLOT(open_slot()), true, i18n("Open")); |
@@ -977,487 +979,485 @@ bool PwM::importFromText() | |||
977 | goto cancelImport; | 979 | goto cancelImport; |
978 | } else if (ret == e_invalidArg) { | 980 | } else if (ret == e_invalidArg) { |
979 | BUG(); | 981 | BUG(); |
980 | goto cancelImport; | 982 | goto cancelImport; |
981 | } else if (ret != e_success) { | 983 | } else if (ret != e_success) { |
982 | KMessageBox::error(this, | 984 | KMessageBox::error(this, |
983 | i18n("Could not import file!\n" | 985 | i18n("Could not import file!\n" |
984 | "Do you have permission to read this file?\n" | 986 | "Do you have permission to read this file?\n" |
985 | "Do you have enough free memory?"), | 987 | "Do you have enough free memory?"), |
986 | i18n("import failed")); | 988 | i18n("import failed")); |
987 | goto cancelImport; | 989 | goto cancelImport; |
988 | } | 990 | } |
989 | setVirgin(false); | 991 | setVirgin(false); |
990 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 992 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
991 | return true; | 993 | return true; |
992 | 994 | ||
993 | cancelImport: | 995 | cancelImport: |
994 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 996 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
995 | return false; | 997 | return false; |
996 | } | 998 | } |
997 | 999 | ||
998 | void PwM::exportToGpasman() | 1000 | void PwM::exportToGpasman() |
999 | { | 1001 | { |
1000 | PWM_ASSERT(curDoc()); | 1002 | PWM_ASSERT(curDoc()); |
1001 | if (curDoc()->isDocEmpty()) { | 1003 | if (curDoc()->isDocEmpty()) { |
1002 | KMessageBox::information(this, | 1004 | KMessageBox::information(this, |
1003 | i18n | 1005 | i18n |
1004 | ("Sorry, there's nothing to export.\n" | 1006 | ("Sorry, there's nothing to export.\n" |
1005 | "Please first add some passwords."), | 1007 | "Please first add some passwords."), |
1006 | i18n("nothing to do")); | 1008 | i18n("nothing to do")); |
1007 | return; | 1009 | return; |
1008 | } | 1010 | } |
1009 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1011 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1010 | QString fn(KFileDialog::getSaveFileName(QString::null, | 1012 | QString fn(KFileDialog::getSaveFileName(QString::null, |
1011 | i18n("*|Gpasman or Kpasman file"), | 1013 | i18n("*|Gpasman or Kpasman file"), |
1012 | this)); | 1014 | this)); |
1013 | if (fn == "") { | 1015 | if (fn == "") { |
1014 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1016 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1015 | return; | 1017 | return; |
1016 | } | 1018 | } |
1017 | 1019 | ||
1018 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 1020 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
1019 | if (ret != e_success) { | 1021 | if (ret != e_success) { |
1020 | if (ret == e_noPw) { | 1022 | if (ret == e_noPw) { |
1021 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1023 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1022 | return; | 1024 | return; |
1023 | } | 1025 | } |
1024 | KMessageBox::error(this, | 1026 | KMessageBox::error(this, |
1025 | i18n("Error: Couldn't write to file.\n" | 1027 | i18n("Error: Couldn't write to file.\n" |
1026 | "Please check if you have permission to write " | 1028 | "Please check if you have permission to write " |
1027 | "to the file in that directory."), | 1029 | "to the file in that directory."), |
1028 | i18n("error while writing")); | 1030 | i18n("error while writing")); |
1029 | } else | 1031 | } else |
1030 | showStatMsg(i18n("Successfully exported data.")); | 1032 | showStatMsg(i18n("Successfully exported data.")); |
1031 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1033 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1032 | } | 1034 | } |
1033 | 1035 | ||
1034 | 1036 | ||
1035 | 1037 | ||
1036 | void PwM::exportToCsv() | 1038 | void PwM::exportToCsv() |
1037 | { | 1039 | { |
1038 | PWM_ASSERT(curDoc()); | 1040 | PWM_ASSERT(curDoc()); |
1039 | if (curDoc()->isDocEmpty()) { | 1041 | if (curDoc()->isDocEmpty()) { |
1040 | KMessageBox::information(this, | 1042 | KMessageBox::information(this, |
1041 | i18n | 1043 | i18n |
1042 | ("Sorry, there is nothing to export;\n" | 1044 | ("Sorry, there is nothing to export;\n" |
1043 | "please add some passwords first."), | 1045 | "please add some passwords first."), |
1044 | i18n("Nothing to Do")); | 1046 | i18n("Nothing to Do")); |
1045 | return; | 1047 | return; |
1046 | } | 1048 | } |
1047 | 1049 | ||
1048 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1050 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1049 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); | 1051 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); |
1050 | if (fn.isEmpty()) { | 1052 | if (fn.isEmpty()) { |
1051 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1053 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1052 | return; | 1054 | return; |
1053 | } | 1055 | } |
1054 | 1056 | ||
1055 | Csv csv(this); | 1057 | Csv csv(this); |
1056 | if (!csv.exportData(fn, curDoc())) { | 1058 | if (!csv.exportData(fn, curDoc())) { |
1057 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1059 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1058 | showStatMsg(i18n("CSV file export failed.")); | 1060 | showStatMsg(i18n("CSV file export failed.")); |
1059 | return; | 1061 | return; |
1060 | } | 1062 | } |
1061 | showStatMsg(i18n("Successfully exported data.")); | 1063 | showStatMsg(i18n("Successfully exported data.")); |
1062 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1064 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1063 | } | 1065 | } |
1064 | 1066 | ||
1065 | bool PwM::importCsv() | 1067 | bool PwM::importCsv() |
1066 | { | 1068 | { |
1067 | Csv csv(this); | 1069 | Csv csv(this); |
1068 | if (!isVirgin()) { | 1070 | if (!isVirgin()) { |
1069 | if (KMessageBox::questionYesNo(this, | 1071 | if (KMessageBox::questionYesNo(this, |
1070 | i18n("Do you want to import the data\n" | 1072 | i18n("Do you want to import the data\n" |
1071 | "into the current document? (If you\n" | 1073 | "into the current document? (If you\n" |
1072 | "select \"no\", a new document will be\n" | 1074 | "select \"no\", a new document will be\n" |
1073 | "opened.)"), | 1075 | "opened.)"), |
1074 | i18n("Import into This Document?")) | 1076 | i18n("Import into This Document?")) |
1075 | == KMessageBox::No) { | 1077 | == KMessageBox::No) { |
1076 | // import the data to a new window. | 1078 | // import the data to a new window. |
1077 | PwM *newInstance = init->createMainWnd(); | 1079 | PwM *newInstance = init->createMainWnd(); |
1078 | bool ok = newInstance->importCsv(); | 1080 | bool ok = newInstance->importCsv(); |
1079 | if (!ok) { | 1081 | if (!ok) { |
1080 | newInstance->setForceQuit(true); | 1082 | newInstance->setForceQuit(true); |
1081 | delete_and_null(newInstance); | 1083 | delete_and_null(newInstance); |
1082 | } | 1084 | } |
1083 | return ok; | 1085 | return ok; |
1084 | } | 1086 | } |
1085 | } | 1087 | } |
1086 | 1088 | ||
1087 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); | 1089 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); |
1088 | if (filename.isEmpty()) | 1090 | if (filename.isEmpty()) |
1089 | return false; | 1091 | return false; |
1090 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1092 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1091 | if (!csv.importData(filename, curDoc())) { | 1093 | if (!csv.importData(filename, curDoc())) { |
1092 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1094 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1093 | showStatMsg(i18n("CSV file import failed.")); | 1095 | showStatMsg(i18n("CSV file import failed.")); |
1094 | return false; | 1096 | return false; |
1095 | } | 1097 | } |
1096 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1098 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1097 | KMessageBox::information(this, | 1099 | KMessageBox::information(this, |
1098 | i18n("Successfully imported the CSV data\n" | 1100 | i18n("Successfully imported the CSV data\n" |
1099 | "into the current document."), i18n("Successfully Imported")); | 1101 | "into the current document."), i18n("Successfully Imported")); |
1100 | showStatMsg(i18n("Successfully imported")); | 1102 | showStatMsg(i18n("Successfully imported")); |
1101 | setVirgin(false); | 1103 | setVirgin(false); |
1102 | return true; | 1104 | return true; |
1103 | } | 1105 | } |
1104 | 1106 | ||
1105 | 1107 | ||
1106 | void PwM::exportToKWallet() | 1108 | void PwM::exportToKWallet() |
1107 | { | 1109 | { |
1108 | #ifdef CONFIG_KWALLETIF | 1110 | #ifdef CONFIG_KWALLETIF |
1109 | if (!checkAndAskForKWalletEmu()) | 1111 | if (!checkAndAskForKWalletEmu()) |
1110 | return; | 1112 | return; |
1111 | PWM_ASSERT(curDoc()); | 1113 | PWM_ASSERT(curDoc()); |
1112 | if (curDoc()->isDocEmpty()) { | 1114 | if (curDoc()->isDocEmpty()) { |
1113 | KMessageBox::information(this, | 1115 | KMessageBox::information(this, |
1114 | i18n | 1116 | i18n |
1115 | ("Sorry, there's nothing to export.\n" | 1117 | ("Sorry, there's nothing to export.\n" |
1116 | "Please first add some passwords."), | 1118 | "Please first add some passwords."), |
1117 | i18n("nothing to do")); | 1119 | i18n("nothing to do")); |
1118 | init->initKWalletEmu(); | 1120 | init->initKWalletEmu(); |
1119 | return; | 1121 | return; |
1120 | } | 1122 | } |
1121 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1123 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1122 | KWalletIf walletIf(this); | 1124 | KWalletIf walletIf(this); |
1123 | if (walletIf.kwalletExport(curDoc())) { | 1125 | if (walletIf.kwalletExport(curDoc())) { |
1124 | KMessageBox::information(this, | 1126 | KMessageBox::information(this, |
1125 | i18n("Successfully exported the data of the current " | 1127 | i18n("Successfully exported the data of the current " |
1126 | "document to KWallet."), | 1128 | "document to KWallet."), |
1127 | i18n("Successfully exported data.")); | 1129 | i18n("Successfully exported data.")); |
1128 | showStatMsg(i18n("Successfully exported data.")); | 1130 | showStatMsg(i18n("Successfully exported data.")); |
1129 | } | 1131 | } |
1130 | init->initKWalletEmu(); | 1132 | init->initKWalletEmu(); |
1131 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1133 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1132 | #endif // CONFIG_KWALLETIF | 1134 | #endif // CONFIG_KWALLETIF |
1133 | } | 1135 | } |
1134 | 1136 | ||
1135 | bool PwM::importFromGpasman() | 1137 | bool PwM::importFromGpasman() |
1136 | { | 1138 | { |
1137 | if (!isVirgin()) { | 1139 | if (!isVirgin()) { |
1138 | if (KMessageBox::questionYesNo(this, | 1140 | if (KMessageBox::questionYesNo(this, |
1139 | i18n("Do you want to import the data\n" | 1141 | i18n("Do you want to import the data\n" |
1140 | "into the current document? (If you\n" | 1142 | "into the current document? (If you\n" |
1141 | "select \"no\", a new document will be\n" | 1143 | "select \"no\", a new document will be\n" |
1142 | "opened.)"), | 1144 | "opened.)"), |
1143 | i18n("import into this document?")) | 1145 | i18n("import into this document?")) |
1144 | == KMessageBox::No) { | 1146 | == KMessageBox::No) { |
1145 | // import the data to a new window. | 1147 | // import the data to a new window. |
1146 | PwM *newInstance = init->createMainWnd(); | 1148 | PwM *newInstance = init->createMainWnd(); |
1147 | bool ok = newInstance->importFromGpasman(); | 1149 | bool ok = newInstance->importFromGpasman(); |
1148 | if (!ok) { | 1150 | if (!ok) { |
1149 | newInstance->setForceQuit(true); | 1151 | newInstance->setForceQuit(true); |
1150 | delete_and_null(newInstance); | 1152 | delete_and_null(newInstance); |
1151 | } | 1153 | } |
1152 | return ok; | 1154 | return ok; |
1153 | } | 1155 | } |
1154 | } | 1156 | } |
1155 | 1157 | ||
1156 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1158 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1157 | PwMerror ret; | 1159 | PwMerror ret; |
1158 | QString path(KFileDialog::getOpenFileName(QString::null, | 1160 | QString path(KFileDialog::getOpenFileName(QString::null, |
1159 | i18n("*|Gpasman or Kpasman file"), this)); | 1161 | i18n("*|Gpasman or Kpasman file"), this)); |
1160 | if (path == "") | 1162 | if (path == "") |
1161 | goto cancelImport; | 1163 | goto cancelImport; |
1162 | ret = curDoc()->importFromGpasman(&path); | 1164 | ret = curDoc()->importFromGpasman(&path); |
1163 | if (ret == e_wrongPw) { | 1165 | if (ret == e_wrongPw) { |
1164 | if (KMessageBox::questionYesNo(this, | 1166 | if (KMessageBox::questionYesNo(this, |
1165 | i18n | 1167 | i18n |
1166 | ("This is probably the wrong master-password\n" | 1168 | ("This is probably the wrong master-password\n" |
1167 | "you have typed in.\n" | 1169 | "you have typed in.\n" |
1168 | "There is no real way to determine the\n" | 1170 | "There is no real way to determine the\n" |
1169 | "correctness of the password in the Gpasman\n" | 1171 | "correctness of the password in the Gpasman\n" |
1170 | "file-format. But I think this\n" | 1172 | "file-format. But I think this\n" |
1171 | "password ist wrong.\n" | 1173 | "password ist wrong.\n" |
1172 | "Do you want to continue nevertheless?"), | 1174 | "Do you want to continue nevertheless?"), |
1173 | i18n("password error")) | 1175 | i18n("password error")) |
1174 | == KMessageBox::No) { | 1176 | == KMessageBox::No) { |
1175 | goto cancelImport; | 1177 | goto cancelImport; |
1176 | } | 1178 | } |
1177 | } else if (ret != e_success) { | 1179 | } else if (ret != e_success) { |
1178 | KMessageBox::error(this, | 1180 | KMessageBox::error(this, |
1179 | i18n("Could not import file!\n" | 1181 | i18n("Could not import file!\n" |
1180 | "Do you have permission to read this file?"), | 1182 | "Do you have permission to read this file?"), |
1181 | i18n("import failed")); | 1183 | i18n("import failed")); |
1182 | goto cancelImport; | 1184 | goto cancelImport; |
1183 | } | 1185 | } |
1184 | setVirgin(false); | 1186 | setVirgin(false); |
1185 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1187 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1186 | return true; | 1188 | return true; |
1187 | 1189 | ||
1188 | cancelImport: | 1190 | cancelImport: |
1189 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1191 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1190 | return false; | 1192 | return false; |
1191 | } | 1193 | } |
1192 | 1194 | ||
1193 | #ifdef CONFIG_KWALLETIF | 1195 | #ifdef CONFIG_KWALLETIF |
1194 | bool PwM::checkAndAskForKWalletEmu() | 1196 | bool PwM::checkAndAskForKWalletEmu() |
1195 | { | 1197 | { |
1196 | if (init->kwalletEmu()) { | 1198 | if (init->kwalletEmu()) { |
1197 | /* KWallet emulation is enabled. We can't import/export | 1199 | /* KWallet emulation is enabled. We can't import/export |
1198 | * data from/to it, while emulation is active. | 1200 | * data from/to it, while emulation is active. |
1199 | */ | 1201 | */ |
1200 | if (KMessageBox::questionYesNo(this, | 1202 | if (KMessageBox::questionYesNo(this, |
1201 | i18n("KWallet emulation is enabled.\n" | 1203 | i18n("KWallet emulation is enabled.\n" |
1202 | "You can't import or export data from/to " | 1204 | "You can't import or export data from/to " |
1203 | "the original KWallet, while the emulation " | 1205 | "the original KWallet, while the emulation " |
1204 | "is active.\n" | 1206 | "is active.\n" |
1205 | "Do you want to tempoarly disable the KWallet emulation?"), | 1207 | "Do you want to tempoarly disable the KWallet emulation?"), |
1206 | i18n("Tempoarly disable KWallet emulation?")) | 1208 | i18n("Tempoarly disable KWallet emulation?")) |
1207 | == KMessageBox::Yes) { | 1209 | == KMessageBox::Yes) { |
1208 | init->initKWalletEmu(true); | 1210 | init->initKWalletEmu(true); |
1209 | PWM_ASSERT(!init->kwalletEmu()); | 1211 | PWM_ASSERT(!init->kwalletEmu()); |
1210 | return true; | 1212 | return true; |
1211 | } | 1213 | } |
1212 | return false; | 1214 | return false; |
1213 | } | 1215 | } |
1214 | return true; | 1216 | return true; |
1215 | } | 1217 | } |
1216 | #endif // CONFIG_KWALLETIF | 1218 | #endif // CONFIG_KWALLETIF |
1217 | 1219 | ||
1218 | bool PwM::importKWallet() | 1220 | bool PwM::importKWallet() |
1219 | { | 1221 | { |
1220 | #ifdef CONFIG_KWALLETIF | 1222 | #ifdef CONFIG_KWALLETIF |
1221 | if (!checkAndAskForKWalletEmu()) | 1223 | if (!checkAndAskForKWalletEmu()) |
1222 | return false; | 1224 | return false; |
1223 | KWalletIf walletIf(this); | 1225 | KWalletIf walletIf(this); |
1224 | if (!isVirgin()) { | 1226 | if (!isVirgin()) { |
1225 | if (KMessageBox::questionYesNo(this, | 1227 | if (KMessageBox::questionYesNo(this, |
1226 | i18n("Do you want to import the data " | 1228 | i18n("Do you want to import the data " |
1227 | "into the current document? (If you " | 1229 | "into the current document? (If you " |
1228 | "select \"no\", a new document will be " | 1230 | "select \"no\", a new document will be " |
1229 | "opened.)"), | 1231 | "opened.)"), |
1230 | i18n("import into this document?")) | 1232 | i18n("import into this document?")) |
1231 | == KMessageBox::No) { | 1233 | == KMessageBox::No) { |
1232 | // import the data to a new window. | 1234 | // import the data to a new window. |
1233 | PwM *newInstance = init->createMainWnd(); | 1235 | PwM *newInstance = init->createMainWnd(); |
1234 | bool ok = newInstance->importKWallet(); | 1236 | bool ok = newInstance->importKWallet(); |
1235 | if (!ok) { | 1237 | if (!ok) { |
1236 | newInstance->setForceQuit(true); | 1238 | newInstance->setForceQuit(true); |
1237 | delete_and_null(newInstance); | 1239 | delete_and_null(newInstance); |
1238 | goto exit_fail; | 1240 | goto exit_fail; |
1239 | } else { | 1241 | } else { |
1240 | goto exit_ok; | 1242 | goto exit_ok; |
1241 | } | 1243 | } |
1242 | } | 1244 | } |
1243 | } | 1245 | } |
1244 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1246 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1245 | if (!walletIf.kwalletImport(curDoc())) { | 1247 | if (!walletIf.kwalletImport(curDoc())) { |
1246 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1248 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1247 | showStatMsg(i18n("KWallet import failed")); | 1249 | showStatMsg(i18n("KWallet import failed")); |
1248 | goto exit_fail; | 1250 | goto exit_fail; |
1249 | } | 1251 | } |
1250 | KMessageBox::information(this, | 1252 | KMessageBox::information(this, |
1251 | i18n("Successfully imported the KWallet data " | 1253 | i18n("Successfully imported the KWallet data " |
1252 | "into the current document."), | 1254 | "into the current document."), |
1253 | i18n("successfully imported")); | 1255 | i18n("successfully imported")); |
1254 | showStatMsg(i18n("successfully imported")); | 1256 | showStatMsg(i18n("successfully imported")); |
1255 | setVirgin(false); | 1257 | setVirgin(false); |
1256 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1258 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1257 | 1259 | ||
1258 | exit_ok: | 1260 | exit_ok: |
1259 | init->initKWalletEmu(); | 1261 | init->initKWalletEmu(); |
1260 | return true; | 1262 | return true; |
1261 | 1263 | ||
1262 | exit_fail: | 1264 | exit_fail: |
1263 | init->initKWalletEmu(); | 1265 | init->initKWalletEmu(); |
1264 | #endif // CONFIG_KWALLETIF | 1266 | #endif // CONFIG_KWALLETIF |
1265 | return false; | 1267 | return false; |
1266 | } | 1268 | } |
1267 | 1269 | ||
1268 | void PwM::print_slot() | 1270 | void PwM::print_slot() |
1269 | { | 1271 | { |
1270 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1272 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1271 | #ifndef PWM_EMBEDDED | 1273 | #ifndef PWM_EMBEDDED |
1272 | PwMPrint p(curDoc(), this); | 1274 | PwMPrint p(curDoc(), this); |
1273 | p.printNow(); | 1275 | p.printNow(); |
1274 | #else | 1276 | #else |
1275 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1277 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1276 | #endif | 1278 | #endif |
1277 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1279 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1278 | } | 1280 | } |
1279 | 1281 | ||
1280 | void PwM::genNewCard_slot() | 1282 | void PwM::genNewCard_slot() |
1281 | { | 1283 | { |
1282 | #ifdef CONFIG_KEYCARD | 1284 | #ifdef CONFIG_KEYCARD |
1283 | init->keycard()->genNewCard(); | 1285 | init->keycard()->genNewCard(); |
1284 | #endif | 1286 | #endif |
1285 | } | 1287 | } |
1286 | 1288 | ||
1287 | void PwM::eraseCard_slot() | 1289 | void PwM::eraseCard_slot() |
1288 | { | 1290 | { |
1289 | #ifdef CONFIG_KEYCARD | 1291 | #ifdef CONFIG_KEYCARD |
1290 | init->keycard()->eraseCard(); | 1292 | init->keycard()->eraseCard(); |
1291 | #endif | 1293 | #endif |
1292 | } | 1294 | } |
1293 | 1295 | ||
1294 | void PwM::readCardId_slot() | 1296 | void PwM::readCardId_slot() |
1295 | { | 1297 | { |
1296 | #ifdef CONFIG_KEYCARD | 1298 | #ifdef CONFIG_KEYCARD |
1297 | init->keycard()->displayKey(); | 1299 | init->keycard()->displayKey(); |
1298 | #endif | 1300 | #endif |
1299 | } | 1301 | } |
1300 | 1302 | ||
1301 | void PwM::makeCardBackup_slot() | 1303 | void PwM::makeCardBackup_slot() |
1302 | { | 1304 | { |
1303 | #ifdef CONFIG_KEYCARD | 1305 | #ifdef CONFIG_KEYCARD |
1304 | init->keycard()->makeBackupImage(); | 1306 | init->keycard()->makeBackupImage(); |
1305 | #endif | 1307 | #endif |
1306 | } | 1308 | } |
1307 | 1309 | ||
1308 | void PwM::replayCardBackup_slot() | 1310 | void PwM::replayCardBackup_slot() |
1309 | { | 1311 | { |
1310 | #ifdef CONFIG_KEYCARD | 1312 | #ifdef CONFIG_KEYCARD |
1311 | init->keycard()->replayBackupImage(); | 1313 | init->keycard()->replayBackupImage(); |
1312 | #endif | 1314 | #endif |
1313 | } | 1315 | } |
1314 | 1316 | ||
1315 | void PwM::execLauncher_slot() | 1317 | void PwM::execLauncher_slot() |
1316 | { | 1318 | { |
1317 | PWM_ASSERT(curDoc()); | 1319 | PWM_ASSERT(curDoc()); |
1318 | if (curDoc()->isDeepLocked()) | 1320 | if (curDoc()->isDeepLocked()) |
1319 | return; | 1321 | return; |
1320 | unsigned int curEntryIndex; | 1322 | unsigned int curEntryIndex; |
1321 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1323 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1322 | return; | 1324 | return; |
1323 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1325 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1324 | curEntryIndex); | 1326 | curEntryIndex); |
1325 | if (ret) | 1327 | if (ret) |
1326 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1328 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1327 | else | 1329 | else |
1328 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1330 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1329 | } | 1331 | } |
1330 | 1332 | ||
1331 | void PwM::goToURL_slot() | 1333 | void PwM::goToURL_slot() |
1332 | { | 1334 | { |
1333 | PWM_ASSERT(curDoc()); | 1335 | PWM_ASSERT(curDoc()); |
1334 | if (curDoc()->isDeepLocked()) | 1336 | if (curDoc()->isDeepLocked()) |
1335 | return; | 1337 | return; |
1336 | unsigned int curEntryIndex; | 1338 | unsigned int curEntryIndex; |
1337 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1339 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1338 | return; | 1340 | return; |
1339 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1341 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1340 | curEntryIndex); | 1342 | curEntryIndex); |
1341 | if (ret) | 1343 | if (ret) |
1342 | showStatMsg(i18n("started browser with current URL.")); | 1344 | showStatMsg(i18n("started browser with current URL.")); |
1343 | else | 1345 | else |
1344 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1346 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1345 | } | 1347 | } |
1346 | 1348 | ||
1347 | void PwM::copyToClipboard(const QString &s) | 1349 | void PwM::copyToClipboard(const QString &s) |
1348 | { | 1350 | { |
1349 | QClipboard *cb = QApplication::clipboard(); | 1351 | QClipboard *cb = QApplication::clipboard(); |
1350 | #ifndef PWM_EMBEDDED | 1352 | #ifndef PWM_EMBEDDED |
1351 | if (cb->supportsSelection()) | 1353 | if (cb->supportsSelection()) |
1352 | cb->setText(s, QClipboard::Selection); | 1354 | cb->setText(s, QClipboard::Selection); |
1353 | cb->setText(s, QClipboard::Clipboard); | 1355 | cb->setText(s, QClipboard::Clipboard); |
1354 | #else | 1356 | #else |
1355 | cb->setText(s); | 1357 | cb->setText(s); |
1356 | 1358 | ||
1357 | #endif | 1359 | #endif |
1358 | 1360 | ||
1359 | } | 1361 | } |
1360 | 1362 | ||
1363 | |||
1361 | void PwM::showStatMsg(const QString &msg) | 1364 | void PwM::showStatMsg(const QString &msg) |
1362 | { | 1365 | { |
1363 | #ifndef PWM_EMBEDDED | 1366 | #ifdef DESKTOP_VERSION |
1364 | KStatusBar *statBar = statusBar(); | 1367 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1365 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | ||
1366 | #else | 1368 | #else |
1367 | qDebug("Statusbar : %s",msg.latin1()); | 1369 | qDebug("Statusbar : %s",msg.latin1()); |
1368 | #ifndef DESKTOP_VERSION | ||
1369 | Global::statusMessage(msg); | 1370 | Global::statusMessage(msg); |
1370 | #endif | 1371 | #endif |
1371 | #endif | ||
1372 | } | 1372 | } |
1373 | 1373 | ||
1374 | void PwM::focusInEvent(QFocusEvent *e) | 1374 | void PwM::focusInEvent(QFocusEvent *e) |
1375 | { | 1375 | { |
1376 | if (e->gotFocus()) { | 1376 | if (e->gotFocus()) { |
1377 | emit gotFocus(this); | 1377 | emit gotFocus(this); |
1378 | } else if (e->lostFocus()) { | 1378 | } else if (e->lostFocus()) { |
1379 | emit lostFocus(this); | 1379 | emit lostFocus(this); |
1380 | } | 1380 | } |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | 1383 | ||
1384 | #ifdef PWM_EMBEDDED | 1384 | #ifdef PWM_EMBEDDED |
1385 | 1385 | ||
1386 | void PwM::whatsnew_slot() | 1386 | void PwM::whatsnew_slot() |
1387 | { | 1387 | { |
1388 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 1388 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
1389 | } | 1389 | } |
1390 | 1390 | ||
1391 | void PwM::showLicense_slot() | 1391 | void PwM::showLicense_slot() |
1392 | { | 1392 | { |
1393 | KApplication::showLicence(); | 1393 | KApplication::showLicence(); |
1394 | } | 1394 | } |
1395 | 1395 | ||
1396 | void PwM::faq_slot() | 1396 | void PwM::faq_slot() |
1397 | { | 1397 | { |
1398 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1398 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1399 | } | 1399 | } |
1400 | 1400 | ||
1401 | void PwM::syncHowTo_slot() | 1401 | void PwM::syncHowTo_slot() |
1402 | { | 1402 | { |
1403 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 1403 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
1404 | } | 1404 | } |
1405 | 1405 | ||
1406 | 1406 | ||
1407 | void PwM::createAboutData_slot() | 1407 | void PwM::createAboutData_slot() |
1408 | { | 1408 | { |
1409 | QString version; | 1409 | QString version; |
1410 | #include <../version> | 1410 | #include <../version> |
1411 | QMessageBox::about( this, "About PwManager/Pi", | 1411 | QMessageBox::about( this, "About PwManager/Pi", |
1412 | "PwManager/Platform-independent\n" | 1412 | "PwManager/Platform-independent\n" |
1413 | "(PWM/Pi) " +version + " - " + | 1413 | "(PWM/Pi) " +version + " - " + |
1414 | #ifdef DESKTOP_VERSION | 1414 | #ifdef DESKTOP_VERSION |
1415 | "Desktop Edition\n" | 1415 | "Desktop Edition\n" |
1416 | #else | 1416 | #else |
1417 | "PDA-Edition\n" | 1417 | "PDA-Edition\n" |
1418 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1418 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1419 | #endif | 1419 | #endif |
1420 | 1420 | ||
1421 | "(c) 2004 Ulf Schenk\n" | 1421 | "(c) 2004 Ulf Schenk\n" |
1422 | "(c) 2004 Lutz Rogowski\n" | 1422 | "(c) 2004 Lutz Rogowski\n" |
1423 | "(c) 1997-2004, The KDE PIM Team\n" | 1423 | "(c) 1997-2004, The KDE PIM Team\n" |
1424 | 1424 | ||
1425 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1425 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1426 | "Matt Scifo - mscifo@o1.com\n" | 1426 | "Matt Scifo - mscifo@o1.com\n" |
1427 | "Elias Probst - elias.probst@gmx.de\n" | 1427 | "Elias Probst - elias.probst@gmx.de\n" |
1428 | "George Staikos - staikos@kde.org\n" | 1428 | "George Staikos - staikos@kde.org\n" |
1429 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1429 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1430 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1430 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1431 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1431 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1432 | "Troy Engel - tengel@sonic.net\n" | 1432 | "Troy Engel - tengel@sonic.net\n" |
1433 | "Wickey - wickey@gmx.at\n" | 1433 | "Wickey - wickey@gmx.at\n" |
1434 | "Ian MacGregor - original documentation author.\n" | 1434 | "Ian MacGregor - original documentation author.\n" |
1435 | ); | 1435 | ); |
1436 | } | 1436 | } |
1437 | 1437 | ||
1438 | 1438 | ||
1439 | //this are the overwritten callbackmethods from the syncinterface | 1439 | //this are the overwritten callbackmethods from the syncinterface |
1440 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1440 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1441 | { | 1441 | { |
1442 | PWM_ASSERT(curDoc()); | 1442 | PWM_ASSERT(curDoc()); |
1443 | 1443 | ||
1444 | bool ret = curDoc()->sync(manager, filename, mode); | 1444 | bool ret = curDoc()->sync(manager, filename, mode); |
1445 | 1445 | ||
1446 | qDebug("PwM::sync save now: ret=%i", ret); | 1446 | qDebug("PwM::sync save now: ret=%i", ret); |
1447 | 1447 | ||
1448 | if (ret == true) { | 1448 | if (ret == true) { |
1449 | //US BUG: what can we call here to update the view of the current doc? | 1449 | //US BUG: what can we call here to update the view of the current doc? |
1450 | //mViewManager->refreshView(); | 1450 | //mViewManager->refreshView(); |
1451 | 1451 | ||
1452 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | 1452 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. |
1453 | save(); | 1453 | save(); |
1454 | } | 1454 | } |
1455 | 1455 | ||
1456 | return ret; | 1456 | return ret; |
1457 | } | 1457 | } |
1458 | #endif | 1458 | #endif |
1459 | 1459 | ||
1460 | 1460 | ||
1461 | #ifndef PWM_EMBEDDED | 1461 | #ifndef PWM_EMBEDDED |
1462 | #include "pwm.moc" | 1462 | #include "pwm.moc" |
1463 | #endif | 1463 | #endif |
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp index 6ddb6f5..71b4a8d 100644 --- a/pwmanager/pwmanager/pwmdocui.cpp +++ b/pwmanager/pwmanager/pwmdocui.cpp | |||
@@ -1,467 +1,467 @@ | |||
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 "pwmdocui.h" | 20 | #include "pwmdocui.h" |
21 | #include "setmasterpwwndimpl.h" | 21 | #include "setmasterpwwndimpl.h" |
22 | #include "getmasterpwwndimpl.h" | 22 | #include "getmasterpwwndimpl.h" |
23 | #include "pwmexception.h" | 23 | #include "pwmexception.h" |
24 | #include "getkeycardwnd.h" | 24 | #include "getkeycardwnd.h" |
25 | #include "pwm.h" | 25 | #include "pwm.h" |
26 | #include "globalstuff.h" | 26 | #include "globalstuff.h" |
27 | #include "spinforsignal.h" | 27 | #include "spinforsignal.h" |
28 | 28 | ||
29 | #include <qlineedit.h> | 29 | #include <qlineedit.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | 31 | ||
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <kfiledialog.h> | 33 | #include <kfiledialog.h> |
34 | 34 | ||
35 | #ifndef PWM_EMBEDDED | 35 | #ifndef PWM_EMBEDDED |
36 | #include <kwin.h> | 36 | #include <kwin.h> |
37 | #else | 37 | #else |
38 | #include <qdir.h> | 38 | #include <qdir.h> |
39 | #include "pwmprefs.h" | 39 | #include "pwmprefs.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | 42 | ||
43 | #ifdef CONFIG_KEYCARD | 43 | #ifdef CONFIG_KEYCARD |
44 | # include "pwmkeycard.h" | 44 | # include "pwmkeycard.h" |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | 47 | ||
48 | PwMDocUi::PwMDocUi(QObject *parent, const char *name) | 48 | PwMDocUi::PwMDocUi(QObject *parent, const char *name) |
49 | : QObject(parent, name) | 49 | : QObject(parent, name) |
50 | { | 50 | { |
51 | currentView = 0; | 51 | currentView = 0; |
52 | keyCard = 0; | 52 | keyCard = 0; |
53 | } | 53 | } |
54 | 54 | ||
55 | PwMDocUi::~PwMDocUi() | 55 | PwMDocUi::~PwMDocUi() |
56 | { | 56 | { |
57 | } | 57 | } |
58 | 58 | ||
59 | QString PwMDocUi::requestMpw(bool chipcard) | 59 | QString PwMDocUi::requestMpw(bool chipcard) |
60 | { | 60 | { |
61 | QString pw; | 61 | QString pw; |
62 | 62 | ||
63 | if (chipcard) { | 63 | if (chipcard) { |
64 | #ifdef CONFIG_KEYCARD | 64 | #ifdef CONFIG_KEYCARD |
65 | PWM_ASSERT(keyCard); | 65 | PWM_ASSERT(keyCard); |
66 | uint32_t id; | 66 | uint32_t id; |
67 | string ret; | 67 | string ret; |
68 | SpinForSignal *spinner = keyCard->getSpinner(); | 68 | SpinForSignal *spinner = keyCard->getSpinner(); |
69 | connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), | 69 | connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), |
70 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); | 70 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); |
71 | keyCard->getKey(); | 71 | keyCard->getKey(); |
72 | spinner->spin(&id, &ret); | 72 | spinner->spin(&id, &ret); |
73 | disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), | 73 | disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), |
74 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); | 74 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); |
75 | if (ret == "") | 75 | if (ret == "") |
76 | return ""; | 76 | return ""; |
77 | pw = ret.c_str(); | 77 | pw = ret.c_str(); |
78 | #else // CONFIG_KEYCARD | 78 | #else // CONFIG_KEYCARD |
79 | no_keycard_support_msg_box(currentView); | 79 | no_keycard_support_msg_box(currentView); |
80 | #endif // CONFIG_KEYCARD | 80 | #endif // CONFIG_KEYCARD |
81 | } else { | 81 | } else { |
82 | #ifndef PWM_EMBEDDED | 82 | #ifndef PWM_EMBEDDED |
83 | GetMasterPwWndImpl pwWnd; | 83 | GetMasterPwWndImpl pwWnd; |
84 | KWin::setState(pwWnd.winId(), NET::StaysOnTop); | 84 | KWin::setState(pwWnd.winId(), NET::StaysOnTop); |
85 | #else | 85 | #else |
86 | GetMasterPwWndImpl pwWnd; | 86 | GetMasterPwWndImpl pwWnd; |
87 | #endif | 87 | #endif |
88 | if (pwWnd.exec() != 1) | 88 | if (pwWnd.exec() != 1) |
89 | return ""; | 89 | return ""; |
90 | pw = pwWnd.pwLineEdit->text(); | 90 | pw = pwWnd.pwLineEdit->text(); |
91 | } | 91 | } |
92 | 92 | ||
93 | return pw; | 93 | return pw; |
94 | } | 94 | } |
95 | 95 | ||
96 | QString PwMDocUi::requestNewMpw(bool *chipcard) | 96 | QString PwMDocUi::requestNewMpw(bool *chipcard) |
97 | { | 97 | { |
98 | QString pw; | 98 | QString pw; |
99 | SetMasterPwWndImpl pwWnd(currentView); | 99 | SetMasterPwWndImpl pwWnd(currentView); |
100 | pwWnd.setPwMKeyCard(keyCard); | 100 | pwWnd.setPwMKeyCard(keyCard); |
101 | if (!chipcard) { | 101 | if (!chipcard) { |
102 | #ifndef PWM_EMBEDDED | 102 | #ifndef PWM_EMBEDDED |
103 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); | 103 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); |
104 | #else | 104 | #else |
105 | pwWnd.mainTab->removePage(pwWnd.tab_2); | 105 | pwWnd.mainTab->removePage(pwWnd.tab_2); |
106 | #endif | 106 | #endif |
107 | } | 107 | } |
108 | 108 | ||
109 | if (pwWnd.exec() != 1) | 109 | if (pwWnd.exec() != 1) |
110 | return ""; | 110 | return ""; |
111 | pw = pwWnd.getPw(chipcard).c_str(); | 111 | pw = pwWnd.getPw(chipcard).c_str(); |
112 | 112 | ||
113 | return pw; | 113 | return pw; |
114 | } | 114 | } |
115 | 115 | ||
116 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) | 116 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) |
117 | { | 117 | { |
118 | QString pw(requestMpw(*chipcard)); | 118 | QString pw(requestMpw(*chipcard)); |
119 | if (pw == "") | 119 | if (pw == "") |
120 | return ""; | 120 | return ""; |
121 | if (pw != *currentPw) { | 121 | if (pw != *currentPw) { |
122 | wrongMpwMsgBox(*chipcard); | 122 | wrongMpwMsgBox(*chipcard); |
123 | return ""; | 123 | return ""; |
124 | } | 124 | } |
125 | 125 | ||
126 | pw = requestNewMpw(chipcard); | 126 | pw = requestNewMpw(chipcard); |
127 | if (pw == "") | 127 | if (pw == "") |
128 | return ""; | 128 | return ""; |
129 | return pw; | 129 | return pw; |
130 | } | 130 | } |
131 | 131 | ||
132 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 132 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
133 | { | 133 | { |
134 | QString msg; | 134 | QString msg; |
135 | if (prefix != "") { | 135 | if (prefix != "") { |
136 | msg += prefix; | 136 | msg += prefix; |
137 | msg += "\n"; | 137 | msg += "\n"; |
138 | } | 138 | } |
139 | 139 | ||
140 | if (chipcard) { | 140 | if (chipcard) { |
141 | msg += i18n("Wrong key-card!\n" | 141 | msg += i18n("Wrong key-card!\n" |
142 | "Please try again with the\n" | 142 | "Please try again with the\n" |
143 | "correct key-card."); | 143 | "correct key-card."); |
144 | } else { | 144 | } else { |
145 | msg += i18n("Wrong master-password!\n" | 145 | msg += i18n("Wrong master-password!\n" |
146 | "Please try again."); | 146 | "Please try again."); |
147 | } | 147 | } |
148 | 148 | ||
149 | if (postfix != "") { | 149 | if (postfix != "") { |
150 | msg += "\n"; | 150 | msg += "\n"; |
151 | msg += postfix; | 151 | msg += postfix; |
152 | } | 152 | } |
153 | KMessageBox::error(currentView, msg, | 153 | KMessageBox::error(currentView, msg, |
154 | (chipcard) ? (i18n("wrong chipcard")) | 154 | (chipcard) ? (i18n("wrong chipcard")) |
155 | : (i18n("password error"))); | 155 | : (i18n("password error"))); |
156 | } | 156 | } |
157 | 157 | ||
158 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 158 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
159 | { | 159 | { |
160 | QString msg; | 160 | QString msg; |
161 | if (prefix != "") { | 161 | if (prefix != "") { |
162 | msg += prefix; | 162 | msg += prefix; |
163 | msg += "\n"; | 163 | msg += "\n"; |
164 | } | 164 | } |
165 | 165 | ||
166 | if (chipcard) { | 166 | if (chipcard) { |
167 | msg += i18n("No key-card found!\n" | 167 | msg += i18n("No key-card found!\n" |
168 | "Please insert the\n" | 168 | "Please insert the\n" |
169 | "correct key-card."); | 169 | "correct key-card."); |
170 | } else { | 170 | } else { |
171 | msg += i18n("No master-password given!"); | 171 | msg += i18n("No master-password given!"); |
172 | } | 172 | } |
173 | 173 | ||
174 | if (postfix != "") { | 174 | if (postfix != "") { |
175 | msg += "\n"; | 175 | msg += "\n"; |
176 | msg += postfix; | 176 | msg += postfix; |
177 | } | 177 | } |
178 | KMessageBox::error(currentView, msg, | 178 | KMessageBox::error(currentView, msg, |
179 | (chipcard) ? (i18n("no chipcard")) | 179 | (chipcard) ? (i18n("no chipcard")) |
180 | : (i18n("password error"))); | 180 | : (i18n("password error"))); |
181 | } | 181 | } |
182 | 182 | ||
183 | void PwMDocUi::rootAlertMsgBox() | 183 | void PwMDocUi::rootAlertMsgBox() |
184 | { | 184 | { |
185 | KMessageBox::error(currentView, | 185 | KMessageBox::error(currentView, |
186 | i18n("This feature is not available,n" | 186 | i18n("This feature is not available,n" |
187 | "if you execute PwM with \"root\" \n" | 187 | "if you execute PwM with \"root\" \n" |
188 | "UID 0 privileges, for security reasons!"), | 188 | "UID 0 privileges, for security reasons!"), |
189 | i18n("not allowed as root!")); | 189 | i18n("not allowed as root!")); |
190 | } | 190 | } |
191 | 191 | ||
192 | void PwMDocUi::cantDeeplock_notSavedMsgBox() | 192 | void PwMDocUi::cantDeeplock_notSavedMsgBox() |
193 | { | 193 | { |
194 | KMessageBox::error(currentView, | 194 | KMessageBox::error(currentView, |
195 | i18n("Can't deep-lock, because the document\n" | 195 | i18n("Can't deep-lock, because the document\n" |
196 | "hasn't been saved, yet. Please save\n" | 196 | "hasn't been saved, yet. Please save\n" |
197 | "to a file and try again."), | 197 | "to a file and try again."), |
198 | i18n("not saved, yet")); | 198 | i18n("not saved, yet")); |
199 | } | 199 | } |
200 | 200 | ||
201 | void PwMDocUi::gpmPwLenErrMsgBox() | 201 | void PwMDocUi::gpmPwLenErrMsgBox() |
202 | { | 202 | { |
203 | KMessageBox::error(currentView, | 203 | KMessageBox::error(currentView, |
204 | i18n("GPasman does not support passwords\n" | 204 | i18n("GPasman does not support passwords\n" |
205 | "shorter than 4 characters! Please try\n" | 205 | "shorter than 4 characters! Please try\n" |
206 | "again with a longer password."), | 206 | "again with a longer password."), |
207 | i18n("password too short")); | 207 | i18n("password too short")); |
208 | } | 208 | } |
209 | 209 | ||
210 | int PwMDocUi::dirtyAskSave(const QString &docTitle) | 210 | int PwMDocUi::dirtyAskSave(const QString &docTitle) |
211 | { | 211 | { |
212 | int ret; | 212 | int ret; |
213 | #ifndef PWM_EMBEDDED | 213 | #ifndef PWM_EMBEDDED |
214 | ret = KMessageBox::questionYesNoCancel(currentView, | 214 | ret = KMessageBox::questionYesNoCancel(currentView, |
215 | i18n("The list \"") + | 215 | i18n("The list \"") + |
216 | docTitle + | 216 | docTitle + |
217 | i18n | 217 | i18n |
218 | ("\" has been modified.\n" | 218 | ("\" has been modified.\n" |
219 | "Do you want to save it?"), | 219 | "Do you want to save it?"), |
220 | i18n("save?")); | 220 | i18n("save?")); |
221 | if (ret == KMessageBox::Yes) { | 221 | if (ret == KMessageBox::Yes) { |
222 | return 0; | 222 | return 0; |
223 | } else if (ret == KMessageBox::No) { | 223 | } else if (ret == KMessageBox::No) { |
224 | return 1; | 224 | return 1; |
225 | } | 225 | } |
226 | #else | 226 | #else |
227 | ret = KMessageBox::warningYesNoCancel(currentView, | 227 | ret = KMessageBox::warningYesNoCancel(currentView, |
228 | i18n("The list \"") + | 228 | i18n("The list \"") + |
229 | docTitle + | 229 | docTitle + |
230 | i18n | 230 | i18n |
231 | ("\"\nhas been modified.\n" | 231 | ("\"\nhas been modified.\n" |
232 | "Do you want to save it?"), | 232 | "Do you want to save it?"), |
233 | i18n("save?")); | 233 | i18n("save?")); |
234 | if (ret == KMessageBox::Yes) { | 234 | if (ret == KMessageBox::Yes) { |
235 | return 0; | 235 | return 0; |
236 | } else if (ret == KMessageBox::No) { | 236 | } else if (ret == KMessageBox::No) { |
237 | return 1; | 237 | return 1; |
238 | } | 238 | } |
239 | 239 | ||
240 | #endif | 240 | #endif |
241 | 241 | ||
242 | // cancel | 242 | // cancel |
243 | return -1; | 243 | return -1; |
244 | } | 244 | } |
245 | 245 | ||
246 | bool PwMDocUi::saveDocUi(PwMDoc *doc) | 246 | bool PwMDocUi::saveDocUi(PwMDoc *doc) |
247 | { | 247 | { |
248 | PWM_ASSERT(doc); | 248 | PWM_ASSERT(doc); |
249 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 249 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
250 | if (doc->isDocEmpty()) { | 250 | if (doc->isDocEmpty()) { |
251 | KMessageBox::information(currentView, | 251 | KMessageBox::information(currentView, |
252 | i18n | 252 | i18n |
253 | ("Sorry, there's nothing to save.\n" | 253 | ("Sorry, there's nothing to save.\n" |
254 | "Please first add some passwords."), | 254 | "Please first add some passwords."), |
255 | i18n("nothing to do")); | 255 | i18n("nothing to do")); |
256 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 256 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
257 | return true; | 257 | return true; |
258 | } | 258 | } |
259 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); | 259 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); |
260 | if (ret == e_filename) { | 260 | if (ret == e_filename) { |
261 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 261 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
262 | return saveAsDocUi(doc); | 262 | return saveAsDocUi(doc); |
263 | } else if (ret == e_weakPw) { | 263 | } else if (ret == e_weakPw) { |
264 | KMessageBox::error(currentView, | 264 | KMessageBox::error(currentView, |
265 | i18n("Error: This is a weak password.\n" | 265 | i18n("Error: This is a weak password.\n" |
266 | "Please select another password."), | 266 | "Please select another password."), |
267 | i18n("weak password")); | 267 | i18n("weak password")); |
268 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 268 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
269 | return false; | 269 | return false; |
270 | } else if (ret == e_fileBackup) { | 270 | } else if (ret == e_fileBackup) { |
271 | KMessageBox::error(currentView, | 271 | KMessageBox::error(currentView, |
272 | i18n("Error: Couldn't make backup-file!"), | 272 | i18n("Error: Couldn't make backup-file!"), |
273 | i18n("backup failed")); | 273 | i18n("backup failed")); |
274 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 274 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
275 | return false; | 275 | return false; |
276 | } else if (ret == e_noPw || | 276 | } else if (ret == e_noPw || |
277 | ret == e_wrongPw || | 277 | ret == e_wrongPw || |
278 | ret == e_openFile) { | 278 | ret == e_openFile) { |
279 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 279 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
280 | return false; | 280 | return false; |
281 | } else if (ret != e_success) { | 281 | } else if (ret != e_success) { |
282 | KMessageBox::error(currentView, | 282 | KMessageBox::error(currentView, |
283 | i18n("Error: Couldn't write to file.\n" | 283 | i18n("Error: Couldn't write to file.\n" |
284 | "Please check if you have permission to\n" | 284 | "Please check if you have permission to\n" |
285 | "write to the file in that directory."), | 285 | "write to the file in that directory."), |
286 | i18n("error while writing")); | 286 | i18n("error while writing")); |
287 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 287 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
288 | return false; | 288 | return false; |
289 | } | 289 | } |
290 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 290 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
291 | return true; | 291 | return true; |
292 | } | 292 | } |
293 | 293 | ||
294 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) | 294 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) |
295 | { | 295 | { |
296 | PWM_ASSERT(doc); | 296 | PWM_ASSERT(doc); |
297 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 297 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
298 | if (doc->isDocEmpty()) { | 298 | if (doc->isDocEmpty()) { |
299 | KMessageBox::information(currentView, | 299 | KMessageBox::information(currentView, |
300 | i18n | 300 | i18n |
301 | ("Sorry, there's nothing to save.\n" | 301 | ("Sorry, there's nothing to save.\n" |
302 | "Please first add some passwords."), | 302 | "Please first add some passwords."), |
303 | i18n("nothing to do")); | 303 | i18n("nothing to do")); |
304 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 304 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
305 | return true; | 305 | return true; |
306 | } | 306 | } |
307 | #ifndef PWM_EMBEDDED | 307 | #ifndef PWM_EMBEDDED |
308 | QString fn(KFileDialog::getSaveFileName(QString::null, | 308 | QString fn(KFileDialog::getSaveFileName(QString::null, |
309 | i18n("*.pwm|PwManager Password file"), | 309 | i18n("*.pwm|PwManager Password file"), |
310 | currentView)); | 310 | currentView)); |
311 | #else | 311 | #else |
312 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); | 312 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); |
313 | fn = KFileDialog::getSaveFileName(fn, | 313 | fn = KFileDialog::getSaveFileName(fn, |
314 | i18n("password filename(*.pwm)"), | 314 | i18n("password filename(*.pwm)"), |
315 | currentView); | 315 | currentView); |
316 | 316 | ||
317 | #endif | 317 | #endif |
318 | if (fn == "") { | 318 | if (fn == "") { |
319 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 319 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
320 | return false; | 320 | return false; |
321 | } | 321 | } |
322 | if (fn.right(4) != ".pwm") | 322 | if (fn.right(4) != ".pwm") |
323 | fn += ".pwm"; | 323 | fn += ".pwm"; |
324 | 324 | ||
325 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); | 325 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); |
326 | if (ret == e_noPw || | 326 | if (ret == e_noPw || |
327 | ret == e_wrongPw || | 327 | ret == e_wrongPw || |
328 | ret == e_openFile) { | 328 | ret == e_openFile) { |
329 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 329 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
330 | return false; | 330 | return false; |
331 | } else if (ret != e_success) { | 331 | } else if (ret != e_success) { |
332 | KMessageBox::error(currentView, | 332 | KMessageBox::error(currentView, |
333 | i18n("Error: Couldn't write to file.\n" | 333 | i18n("Error: Couldn't write to file.\n" |
334 | "Please check if you have permission to\n" | 334 | "Please check if you have permission to\n" |
335 | "write to the file in that directory."), | 335 | "write to the file in that directory."), |
336 | i18n("error while writing")); | 336 | i18n("error while writing")); |
337 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 337 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
338 | return false; | 338 | return false; |
339 | } | 339 | } |
340 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 340 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
341 | return true; | 341 | return true; |
342 | } | 342 | } |
343 | 343 | ||
344 | bool PwMDocUi::openDocUi(PwMDoc *doc, | 344 | bool PwMDocUi::openDocUi(PwMDoc *doc, |
345 | QString filename, | 345 | QString filename, |
346 | bool openDeepLocked) | 346 | bool openDeepLocked) |
347 | { | 347 | { |
348 | if (filename.isEmpty()) | 348 | if (filename.isEmpty()) |
349 | { | 349 | { |
350 | #ifndef PWM_EMBEDDED | 350 | #ifndef PWM_EMBEDDED |
351 | filename = KFileDialog::getOpenFileName(QString::null, | 351 | filename = KFileDialog::getOpenFileName(QString::null, |
352 | i18n("*.pwm|PwManager Password file\n" | 352 | i18n("*.pwm|PwManager Password file\n" |
353 | "*|All files"), getCurrentView()); | 353 | "*|All files"), getCurrentView()); |
354 | #else | 354 | #else |
355 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); | 355 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); |
356 | filename = KFileDialog::getOpenFileName(filename, | 356 | filename = KFileDialog::getOpenFileName(filename, |
357 | i18n("password filename(*.pwm)"), getCurrentView()); | 357 | i18n("password filename(*.pwm)"), getCurrentView()); |
358 | #endif | 358 | #endif |
359 | } | 359 | } |
360 | if (filename.isEmpty()) | 360 | if (filename.isEmpty()) |
361 | goto cancelOpen; | 361 | goto cancelOpen; |
362 | PwMerror ret; | 362 | PwMerror ret; |
363 | while (true) { | 363 | while (true) { |
364 | int lockStat = -1; | 364 | int lockStat = -1; |
365 | if (openDeepLocked) { | 365 | if (openDeepLocked) { |
366 | lockStat = 2; | 366 | lockStat = 2; |
367 | } else { | 367 | } else { |
368 | if (conf()->confGlobUnlockOnOpen()) { | 368 | if (conf()->confGlobUnlockOnOpen()) { |
369 | lockStat = 0; | 369 | lockStat = 0; |
370 | } else { | 370 | } else { |
371 | lockStat = 1; | 371 | lockStat = 1; |
372 | } | 372 | } |
373 | } | 373 | } |
374 | ret = doc->openDoc(&filename, lockStat); | 374 | ret = doc->openDoc(&filename, lockStat); |
375 | //qDebug("pwmdocui::OpenDocui %i", ret); | 375 | //qDebug("pwmdocui::OpenDocui %i", ret); |
376 | if (ret != e_success) { | 376 | if (ret != e_success) { |
377 | if (ret == e_readFile || ret == e_openFile) { | 377 | if (ret == e_readFile || ret == e_openFile) { |
378 | KMessageBox::error(getCurrentView(), | 378 | KMessageBox::error(getCurrentView(), |
379 | i18n("Could not read file!") | 379 | i18n("Could not read file!") |
380 | + "\n" | 380 | + "\n" |
381 | + filename, | 381 | + filename, |
382 | i18n("file error")); | 382 | i18n("File error")); |
383 | goto cancelOpen; | 383 | goto cancelOpen; |
384 | } | 384 | } |
385 | if (ret == e_alreadyOpen) { | 385 | if (ret == e_alreadyOpen) { |
386 | KMessageBox::error(getCurrentView(), | 386 | KMessageBox::error(getCurrentView(), |
387 | i18n("This file is already open."), | 387 | i18n("This file is already open."), |
388 | i18n("already open")); | 388 | i18n("Already open")); |
389 | goto cancelOpen; | 389 | goto cancelOpen; |
390 | } | 390 | } |
391 | if (ret == e_fileVer) { | 391 | if (ret == e_fileVer) { |
392 | KMessageBox::error(getCurrentView(), | 392 | KMessageBox::error(getCurrentView(), |
393 | i18n | 393 | i18n |
394 | ("File-version is not supported!\n" | 394 | ("File-version is not supported!\n" |
395 | "Did you create this file with an\nolder or newer version of PwM?"), | 395 | "Did you create this file with an\nolder or newer version of PwM?"), |
396 | i18n | 396 | i18n |
397 | ("incompatible version")); | 397 | ("Incompatible version")); |
398 | goto cancelOpen; | 398 | goto cancelOpen; |
399 | } | 399 | } |
400 | if (ret == e_wrongPw) { | 400 | if (ret == e_wrongPw) { |
401 | continue; | 401 | continue; |
402 | } | 402 | } |
403 | if (ret == e_noPw) { | 403 | if (ret == e_noPw) { |
404 | goto cancelOpen; | 404 | goto cancelOpen; |
405 | } | 405 | } |
406 | if (ret == e_fileFormat) { | 406 | if (ret == e_fileFormat) { |
407 | KMessageBox::error(getCurrentView(), | 407 | KMessageBox::error(getCurrentView(), |
408 | i18n | 408 | i18n |
409 | ("Sorry, this file has not been recognized\n" | 409 | ("Sorry, this file has not been recognized\n" |
410 | "as a PwM Password file.\n" | 410 | "as a PwM Password file.\n" |
411 | "Probably you have selected the wrong file."), | 411 | "Probably you have selected the wrong file."), |
412 | i18n | 412 | i18n |
413 | ("no PwM password-file")); | 413 | ("No PwM password-file")); |
414 | goto cancelOpen; | 414 | goto cancelOpen; |
415 | } | 415 | } |
416 | if (ret == e_fileCorrupt) { | 416 | if (ret == e_fileCorrupt) { |
417 | KMessageBox::error(getCurrentView(), | 417 | KMessageBox::error(getCurrentView(), |
418 | i18n | 418 | i18n |
419 | ("File corrupt!\n" | 419 | ("File corrupt!\n" |
420 | "Maybe the media, you stored this file on,\n" | 420 | "Maybe the media, you stored this file on,\n" |
421 | "had bad sectors?"), | 421 | "had bad sectors?"), |
422 | i18n | 422 | i18n |
423 | ("checksum error")); | 423 | ("Checksum error")); |
424 | goto cancelOpen; | 424 | goto cancelOpen; |
425 | } | 425 | } |
426 | } | 426 | } |
427 | break; | 427 | break; |
428 | } | 428 | } |
429 | return true; | 429 | return true; |
430 | 430 | ||
431 | cancelOpen: | 431 | cancelOpen: |
432 | return false; | 432 | return false; |
433 | } | 433 | } |
434 | 434 | ||
435 | QString PwMDocUi::string_defaultCategory() | 435 | QString PwMDocUi::string_defaultCategory() |
436 | { | 436 | { |
437 | return i18n("Default"); | 437 | return i18n("Default"); |
438 | } | 438 | } |
439 | 439 | ||
440 | QString PwMDocUi::string_locked() | 440 | QString PwMDocUi::string_locked() |
441 | { | 441 | { |
442 | return i18n("<LOCKED>"); | 442 | return i18n("<LOCKED>"); |
443 | } | 443 | } |
444 | 444 | ||
445 | QString PwMDocUi::string_deepLockedShort() | 445 | QString PwMDocUi::string_deepLockedShort() |
446 | { | 446 | { |
447 | return i18n("DEEP-LOCKED"); | 447 | return i18n("DEEP-LOCKED"); |
448 | } | 448 | } |
449 | 449 | ||
450 | QString PwMDocUi::string_deepLockedLong() | 450 | QString PwMDocUi::string_deepLockedLong() |
451 | { | 451 | { |
452 | return i18n("This file is DEEP-LOCKED!\n" | 452 | return i18n("This file is DEEP-LOCKED!\n" |
453 | "That means all data has been encrypted\n" | 453 | "That means all data has been encrypted\n" |
454 | "and written out to the file. If you want\n" | 454 | "and written out to the file. If you want\n" |
455 | "to see the entries, please UNLOCK the file.\n" | 455 | "to see the entries, please UNLOCK the file.\n" |
456 | "While unlocking, you will be prompted for the\n" | 456 | "While unlocking, you will be prompted for the\n" |
457 | "master-password or the key-card."); | 457 | "master-password or the key-card."); |
458 | } | 458 | } |
459 | 459 | ||
460 | QString PwMDocUi::string_defaultTitle() | 460 | QString PwMDocUi::string_defaultTitle() |
461 | { | 461 | { |
462 | return i18n("Untitled"); | 462 | return i18n("Untitled"); |
463 | } | 463 | } |
464 | 464 | ||
465 | #ifndef PWM_EMBEDDED | 465 | #ifndef PWM_EMBEDDED |
466 | #include "pwmdocui.moc" | 466 | #include "pwmdocui.moc" |
467 | #endif | 467 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index ed0f754..5753c1d 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,784 +1,792 @@ | |||
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 1.1 of pwmanager | 15 | * This file is originaly based on version 1.1 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_DEBUG0 |
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 | //abort(); | ||
169 | //qDebug("parse %s ", buffer.data()); | ||
168 | PWM_ASSERT(domDoc); | 170 | PWM_ASSERT(domDoc); |
169 | #ifndef PWM_EMBEDDED | 171 | #ifndef PWM_EMBEDDED |
170 | if (!domDoc->setContent(buffer, true)) | 172 | if (!domDoc->setContent(buffer, true)) |
171 | return false; | 173 | return false; |
172 | #else | 174 | #else |
173 | #ifdef DESKTOP_VERSION | 175 | #ifdef DESKTOP_VERSION |
174 | if (!domDoc->setContent(buffer, true)) | 176 | if (!domDoc->setContent(buffer, true)) |
175 | #else | 177 | #else |
176 | if (!domDoc->setContent(buffer)) | 178 | if (!domDoc->setContent(buffer)) |
177 | #endif | 179 | #endif |
178 | return false; | 180 | return false; |
179 | #endif | 181 | #endif |
180 | if (!checkValid()) | 182 | if (!checkValid()) |
181 | return false; | 183 | return false; |
182 | return true; | 184 | return true; |
183 | } | 185 | } |
184 | 186 | ||
185 | QCString Serializer::getXml() | 187 | QCString Serializer::getXml() |
186 | { | 188 | { |
187 | PWM_ASSERT(domDoc); | 189 | PWM_ASSERT(domDoc); |
188 | 190 | ||
189 | #ifndef PWM_EMBEDDED | 191 | #ifndef PWM_EMBEDDED |
190 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 192 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
191 | QCString tmp(domDoc->toCString(8)); | 193 | QCString tmp(domDoc->toCString(8)); |
192 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 194 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
193 | cout << tmp << endl; | 195 | cout << tmp << endl; |
194 | printDebug("<END Serializer::getXml() dump>"); | 196 | printDebug("<END Serializer::getXml() dump>"); |
195 | #endif // DEBUG | 197 | #endif // DEBUG |
196 | 198 | ||
197 | QCString ret(domDoc->toCString(0)); | 199 | QCString ret(domDoc->toCString(0)); |
198 | ret.replace('\n', ""); | 200 | ret.replace('\n', ""); |
199 | return ret; | 201 | return ret; |
200 | #else | 202 | #else |
201 | 203 | ||
202 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 204 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
203 | QCString tmp(" " + domDoc->toCString()); | 205 | QCString tmp(" " + domDoc->toCString()); |
204 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 206 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
205 | qDebug(tmp); | 207 | qDebug(tmp); |
206 | cout << tmp << endl; | 208 | cout << tmp << endl; |
207 | printDebug("<END Serializer::getXml() dump>"); | 209 | printDebug("<END Serializer::getXml() dump>"); |
208 | #endif // DEBUG | 210 | #endif // DEBUG |
209 | 211 | ||
210 | QCString ret(domDoc->toCString()); | 212 | QCString ret(domDoc->toCString()); |
211 | ret.replace(QRegExp("\n"), ""); | 213 | ret.replace(QRegExp("\n"), ""); |
212 | return ret; | 214 | return ret; |
213 | 215 | ||
214 | #endif | 216 | #endif |
215 | } | 217 | } |
216 | 218 | ||
217 | bool Serializer::serialize(PwMItem &dta) | 219 | bool Serializer::serialize(PwMItem &dta) |
218 | { | 220 | { |
219 | PWM_ASSERT(domDoc); | 221 | PWM_ASSERT(domDoc); |
220 | QDomElement root(genNewRoot()); | 222 | QDomElement root(genNewRoot()); |
221 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 223 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
222 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); | 224 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); |
223 | if (!addSyncData(&syncNode, dta.syncDta)) | 225 | if (!addSyncData(&syncNode, dta.syncDta)) |
224 | return false; | 226 | return false; |
225 | root.appendChild(syncNode); | 227 | root.appendChild(syncNode); |
226 | if (!addCategories(&catNode, dta.dta)) | 228 | if (!addCategories(&catNode, dta.dta)) |
227 | return false; | 229 | return false; |
228 | root.appendChild(catNode); | 230 | root.appendChild(catNode); |
229 | return true; | 231 | return true; |
230 | } | 232 | } |
231 | 233 | ||
232 | bool Serializer::deSerialize(PwMItem *dta) | 234 | bool Serializer::deSerialize(PwMItem *dta) |
233 | { | 235 | { |
234 | PWM_ASSERT(domDoc); | 236 | PWM_ASSERT(domDoc); |
235 | PWM_ASSERT(dta); | 237 | PWM_ASSERT(dta); |
236 | QDomElement root(domDoc->documentElement()); | 238 | QDomElement root(domDoc->documentElement()); |
237 | QDomNode n; | 239 | QDomNode n; |
238 | 240 | ||
239 | dta->clear(); | 241 | dta->clear(); |
240 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 242 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
241 | // find <categories> ... </categories> | 243 | // find <categories> ... </categories> |
242 | // <c> ... </c> | 244 | // <c> ... </c> |
243 | if (n.nodeName() == CAT_ROOT_NEW || | 245 | if (n.nodeName() == CAT_ROOT_NEW || |
244 | n.nodeName() == CAT_ROOT_OLD) { | 246 | n.nodeName() == CAT_ROOT_OLD) { |
245 | if (!readCategories(n, &(dta->dta))) { | 247 | if (!readCategories(n, &(dta->dta))) { |
246 | return false; | 248 | return false; |
247 | } | 249 | } |
248 | continue; | 250 | continue; |
249 | } | 251 | } |
250 | else if (n.nodeName() == SYNC_ROOT) { | 252 | else if (n.nodeName() == SYNC_ROOT) { |
251 | if (!readSyncData(n, &(dta->syncDta))) { | 253 | if (!readSyncData(n, &(dta->syncDta))) { |
252 | return false; | 254 | return false; |
253 | } | 255 | } |
254 | continue; | 256 | continue; |
255 | } | 257 | } |
256 | 258 | ||
257 | /* NOTE: We can stop processing here, as we | 259 | /* NOTE: We can stop processing here, as we |
258 | * don't have more nodes in root, yet. | 260 | * don't have more nodes in root, yet. |
259 | */ | 261 | */ |
260 | return false; | 262 | return false; |
261 | 263 | ||
262 | } | 264 | } |
263 | return true; | 265 | return true; |
264 | } | 266 | } |
265 | 267 | ||
266 | bool Serializer::readCategories(const QDomNode &n, | 268 | bool Serializer::readCategories(const QDomNode &n, |
267 | vector<PwMCategoryItem> *dta) | 269 | vector<PwMCategoryItem> *dta) |
268 | { | 270 | { |
269 | QDomNodeList nl(n.childNodes()); | 271 | QDomNodeList nl(n.childNodes()); |
270 | QDomNode cur; | 272 | QDomNode cur; |
271 | QString name; | 273 | QString name; |
272 | unsigned int numCat = nl.count(), i; | 274 | unsigned int numCat = nl.count(), i; |
273 | PwMCategoryItem curCat; | 275 | PwMCategoryItem curCat; |
274 | vector<PwMDataItem> curEntr; | 276 | vector<PwMDataItem> curEntr; |
275 | 277 | ||
276 | if (!numCat) { | 278 | if (!numCat) { |
277 | printDebug("Serializer::readCategories(): empty"); | 279 | printDebug("Serializer::readCategories(): empty"); |
278 | return false; | 280 | return false; |
279 | } | 281 | } |
280 | for (i = 0; i < numCat; ++i) { | 282 | for (i = 0; i < numCat; ++i) { |
281 | cur = nl.item(i); | 283 | cur = nl.item(i); |
282 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 284 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
283 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 285 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
284 | name = cur.toElement().attribute(CAT_NAME_NEW); | 286 | name = cur.toElement().attribute(CAT_NAME_NEW); |
285 | if (name == QString::null) | 287 | if (name == QString::null) |
286 | name = cur.toElement().attribute(CAT_NAME_OLD); | 288 | name = cur.toElement().attribute(CAT_NAME_OLD); |
287 | PWM_ASSERT(name != QString::null); | 289 | PWM_ASSERT(name != QString::null); |
288 | PWM_ASSERT(name != ""); | 290 | PWM_ASSERT(name != ""); |
289 | curCat.clear(); | 291 | curCat.clear(); |
290 | curCat.name = name.latin1(); | 292 | curCat.name = name.latin1(); |
291 | if (!readEntries(cur, &curEntr)) { | 293 | if (!readEntries(cur, &curEntr)) { |
292 | dta->clear(); | 294 | dta->clear(); |
293 | return false; | 295 | return false; |
294 | } | 296 | } |
295 | curCat.d = curEntr; | 297 | curCat.d = curEntr; |
296 | dta->push_back(curCat); | 298 | dta->push_back(curCat); |
297 | } else { | 299 | } else { |
298 | printDebug("Serializer::readCategories(): uh? not a category?"); | 300 | printDebug("Serializer::readCategories(): uh? not a category?"); |
299 | } | 301 | } |
300 | } | 302 | } |
301 | return true; | 303 | return true; |
302 | } | 304 | } |
303 | 305 | ||
304 | bool Serializer::readEntries(const QDomNode &n, | 306 | bool Serializer::readEntries(const QDomNode &n, |
305 | vector<PwMDataItem> *dta) | 307 | vector<PwMDataItem> *dta) |
306 | { | 308 | { |
307 | QDomNodeList nl(n.childNodes()); | 309 | QDomNodeList nl(n.childNodes()); |
308 | QDomNode cur; | 310 | QDomNode cur; |
309 | unsigned int numEntr = nl.count(), i; | 311 | unsigned int numEntr = nl.count(), i; |
310 | PwMDataItem curEntr; | 312 | PwMDataItem curEntr; |
311 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 313 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
312 | // we call clear on it. Reason: Information in the file we will read might be incomplete. | 314 | // we call clear on it. Reason: Information in the file we will read might be incomplete. |
313 | // e.g. the metadata is missing. | 315 | // e.g. the metadata is missing. |
314 | curEntr.clear(true); | 316 | curEntr.clear(true); |
315 | 317 | ||
316 | dta->clear(); | 318 | dta->clear(); |
317 | for (i = 0; i < numEntr; ++i) { | 319 | for (i = 0; i < numEntr; ++i) { |
318 | cur = nl.item(i); | 320 | cur = nl.item(i); |
319 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 321 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
320 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 322 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
321 | if (!extractEntry(cur, &curEntr)) { | 323 | if (!extractEntry(cur, &curEntr)) { |
322 | return false; | 324 | return false; |
323 | } | 325 | } |
324 | dta->push_back(curEntr); | 326 | dta->push_back(curEntr); |
325 | } else { | 327 | } else { |
326 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 328 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
327 | } | 329 | } |
328 | } | 330 | } |
329 | return true; | 331 | return true; |
330 | } | 332 | } |
331 | 333 | ||
332 | bool Serializer::extractEntry(const QDomNode &n, | 334 | bool Serializer::extractEntry(const QDomNode &n, |
333 | PwMDataItem *dta) | 335 | PwMDataItem *dta) |
334 | { | 336 | { |
335 | QDomNodeList nl(n.childNodes()); | 337 | QDomNodeList nl(n.childNodes()); |
336 | QDomNode cur, cdata; | 338 | QDomNode cur, cdata; |
337 | unsigned int cnt = nl.count(), i; | 339 | unsigned int cnt = nl.count(), i; |
338 | QString name, text; | 340 | QString name, text; |
339 | 341 | ||
340 | if (!cnt) { | 342 | if (!cnt) { |
341 | printDebug("Serializer::extractEntry(): empty"); | 343 | printDebug("Serializer::extractEntry(): empty"); |
342 | return false; | 344 | return false; |
343 | } | 345 | } |
344 | dta->clear(); | 346 | dta->clear(); |
345 | for (i = 0; i < cnt; ++i) { | 347 | for (i = 0; i < cnt; ++i) { |
346 | cur = nl.item(i); | 348 | cur = nl.item(i); |
347 | name = cur.nodeName(); | 349 | name = cur.nodeName(); |
348 | cdata = cur.firstChild(); | 350 | cdata = cur.firstChild(); |
349 | if (unlikely(cdata.isCDATASection())) { | 351 | if (unlikely(cdata.isCDATASection())) { |
350 | text = cdata.toCDATASection().data(); | 352 | text = cdata.toCDATASection().data(); |
351 | } else if (likely(cur.isElement())) { | 353 | } else if (likely(cur.isElement())) { |
352 | text = cur.toElement().text(); | 354 | text = cur.toElement().text(); |
353 | } else { | 355 | } else { |
354 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 356 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
355 | return false; | 357 | return false; |
356 | } | 358 | } |
357 | if (text == " ") | 359 | if (text == " ") |
358 | text = ""; // for backward compatibility. | 360 | text = ""; // for backward compatibility. |
361 | //qDebug("entry %s ",unescapeEntryData(text).latin1()); | ||
359 | if (name == ENTRY_DESC_NEW || | 362 | if (name == ENTRY_DESC_NEW || |
360 | name == ENTRY_DESC_OLD) { | 363 | name == ENTRY_DESC_OLD) { |
361 | dta->desc = unescapeEntryData(text).latin1(); | 364 | dta->desc = unescapeEntryData(text).latin1(); |
362 | } else if (name == ENTRY_NAME_NEW || | 365 | } else if (name == ENTRY_NAME_NEW || |
363 | name == ENTRY_NAME_OLD) { | 366 | name == ENTRY_NAME_OLD) { |
364 | dta->name = unescapeEntryData(text).latin1(); | 367 | dta->name = unescapeEntryData(text).latin1(); |
365 | } else if (name == ENTRY_PW_NEW || | 368 | } else if (name == ENTRY_PW_NEW || |
366 | name == ENTRY_PW_OLD) { | 369 | name == ENTRY_PW_OLD) { |
367 | dta->pw = unescapeEntryData(text).latin1(); | 370 | dta->pw = unescapeEntryData(text).latin1(); |
368 | } else if (name == ENTRY_COMMENT_NEW || | 371 | } else if (name == ENTRY_COMMENT_NEW || |
369 | name == ENTRY_COMMENT_OLD) { | 372 | name == ENTRY_COMMENT_OLD) { |
370 | dta->comment = unescapeEntryData(text).latin1(); | 373 | dta->comment = unescapeEntryData(text).latin1(); |
371 | } else if (name == ENTRY_URL_NEW || | 374 | } else if (name == ENTRY_URL_NEW || |
372 | name == ENTRY_URL_OLD) { | 375 | name == ENTRY_URL_OLD) { |
373 | dta->url = unescapeEntryData(text).latin1(); | 376 | dta->url = unescapeEntryData(text).latin1(); |
374 | } else if (name == ENTRY_LAUNCHER_NEW || | 377 | } else if (name == ENTRY_LAUNCHER_NEW || |
375 | name == ENTRY_LAUNCHER_OLD) { | 378 | name == ENTRY_LAUNCHER_OLD) { |
376 | dta->launcher = unescapeEntryData(text).latin1(); | 379 | dta->launcher = unescapeEntryData(text).latin1(); |
377 | } else if (name == ENTRY_LVP_NEW || | 380 | } else if (name == ENTRY_LVP_NEW || |
378 | name == ENTRY_LVP_OLD) { | 381 | name == ENTRY_LVP_OLD) { |
379 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 382 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
380 | } else if (name == ENTRY_BIN_NEW) { | 383 | } else if (name == ENTRY_BIN_NEW) { |
381 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 384 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
382 | if (text == "0") { | 385 | if (text == "0") { |
383 | dta->binary = false; | 386 | dta->binary = false; |
384 | } else { | 387 | } else { |
385 | dta->binary = true; | 388 | dta->binary = true; |
386 | } | 389 | } |
387 | } else if (name == ENTRY_META_NEW) { | 390 | } else if (name == ENTRY_META_NEW) { |
388 | // ENTRY_META_NEW == ENTRY_META_OLD | 391 | // ENTRY_META_NEW == ENTRY_META_OLD |
389 | if (!extractMeta(cur, &dta->meta)) | 392 | if (!extractMeta(cur, &dta->meta)) |
390 | return false; | 393 | return false; |
391 | } else { | 394 | } else { |
392 | printDebug(string("Serializer::extractEntry(): invalid: ") | 395 | printDebug(string("Serializer::extractEntry(): invalid: ") |
393 | + name.latin1()); | 396 | + name.latin1()); |
394 | } | 397 | } |
395 | } | 398 | } |
396 | dta->lockStat = defaultLockStat; | 399 | dta->lockStat = defaultLockStat; |
397 | return true; | 400 | return true; |
398 | } | 401 | } |
399 | 402 | ||
400 | bool Serializer::extractMeta(const QDomNode &n, | 403 | bool Serializer::extractMeta(const QDomNode &n, |
401 | PwMMetaData *dta) | 404 | PwMMetaData *dta) |
402 | { | 405 | { |
403 | QDomNode cur(n.firstChild()); | 406 | QDomNode cur(n.firstChild()); |
404 | QString name, val; | 407 | QString name, val; |
405 | while (!cur.isNull()) { | 408 | while (!cur.isNull()) { |
406 | name = cur.nodeName(); | 409 | name = cur.nodeName(); |
407 | val = cur.toElement().text(); | 410 | val = cur.toElement().text(); |
408 | if (val == "") { | 411 | if (val == "") { |
409 | cur = cur.nextSibling(); | 412 | cur = cur.nextSibling(); |
410 | continue; | 413 | continue; |
411 | } | 414 | } |
412 | 415 | ||
413 | //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. | 416 | //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. |
414 | //because of that it is possible that here some values are not set, which means they are null. | 417 | //because of that it is possible that here some values are not set, which means they are null. |
415 | //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates. | 418 | //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates. |
416 | 419 | ||
417 | QDateTime dtval; //dtval should be invalid by definition. | 420 | QDateTime dtval; //dtval should be invalid by definition. |
418 | 421 | ||
419 | if ((name == META_CREATE_DATE) || | 422 | if ((name == META_CREATE_DATE) || |
420 | (name == META_VALID_DATE) || | 423 | (name == META_VALID_DATE) || |
421 | (name == META_EXPIRE_DATE) || | 424 | (name == META_EXPIRE_DATE) || |
422 | (name == META_UPDATE_DATE)) | 425 | (name == META_UPDATE_DATE)) |
423 | { | 426 | { |
424 | //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); | 427 | //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); |
425 | 428 | ||
426 | #ifndef PWM_EMBEDDED | 429 | #ifndef PWM_EMBEDDED |
427 | dtval = QDateTime::fromString(val, Qt::ISODate); | 430 | dtval = QDateTime::fromString(val, Qt::ISODate); |
428 | #else | 431 | #else |
429 | bool ok; | 432 | bool ok; |
430 | dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 433 | dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
431 | 434 | ||
432 | if (ok == false) | 435 | if (ok == false) |
433 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 436 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
434 | #endif | 437 | #endif |
435 | 438 | ||
436 | //if the parsed data is wrong, dtval should be invalid at this time. | 439 | //if the parsed data is wrong, dtval should be invalid at this time. |
437 | 440 | ||
438 | } | 441 | } |
439 | 442 | ||
440 | if (name == META_CREATE_DATE) { | 443 | if (name == META_CREATE_DATE) { |
441 | dta->create = dtval; | 444 | dta->create = dtval; |
442 | } else if (name == META_VALID_DATE) { | 445 | } else if (name == META_VALID_DATE) { |
443 | dta->valid = dtval; | 446 | dta->valid = dtval; |
444 | } else if (name == META_EXPIRE_DATE) { | 447 | } else if (name == META_EXPIRE_DATE) { |
445 | dta->expire = dtval; | 448 | dta->expire = dtval; |
446 | } else if (name == META_UPDATE_DATE) { | 449 | } else if (name == META_UPDATE_DATE) { |
447 | dta->update = dtval; | 450 | dta->update = dtval; |
448 | } else if (name == META_UPDATE_INT) { | 451 | } else if (name == META_UPDATE_INT) { |
449 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 452 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
450 | } else if (name == META_UNIQUEID) { | 453 | } else if (name == META_UNIQUEID) { |
451 | dta->uniqueid = unescapeEntryData(val).latin1(); | 454 | dta->uniqueid = unescapeEntryData(val).latin1(); |
452 | } else { | 455 | } else { |
453 | printDebug(string("extractMeta(): invalid: ") | 456 | printDebug(string("extractMeta(): invalid: ") |
454 | + name.latin1()); | 457 | + name.latin1()); |
455 | } | 458 | } |
456 | 459 | ||
457 | cur = cur.nextSibling(); | 460 | cur = cur.nextSibling(); |
458 | } | 461 | } |
459 | return true; | 462 | return true; |
460 | } | 463 | } |
461 | 464 | ||
462 | bool Serializer::checkValid() | 465 | bool Serializer::checkValid() |
463 | { | 466 | { |
464 | PWM_ASSERT(domDoc); | 467 | PWM_ASSERT(domDoc); |
465 | QDomElement root(domDoc->documentElement()); | 468 | QDomElement root(domDoc->documentElement()); |
466 | if (root.nodeName() != ROOT_MAGIC_NEW && | 469 | if (root.nodeName() != ROOT_MAGIC_NEW && |
467 | root.nodeName() != ROOT_MAGIC_OLD) { | 470 | root.nodeName() != ROOT_MAGIC_OLD) { |
468 | printDebug("Serializer: wrong magic"); | 471 | printDebug("Serializer: wrong magic"); |
469 | return false; | 472 | return false; |
470 | } | 473 | } |
471 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 474 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
472 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 475 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
473 | printDebug("Serializer: wrong version"); | 476 | printDebug("Serializer: wrong version"); |
474 | return false; | 477 | return false; |
475 | } | 478 | } |
476 | return true; | 479 | return true; |
477 | } | 480 | } |
478 | 481 | ||
479 | QDomElement Serializer::genNewRoot() | 482 | QDomElement Serializer::genNewRoot() |
480 | { | 483 | { |
481 | PWM_ASSERT(domDoc); | 484 | PWM_ASSERT(domDoc); |
482 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 485 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
483 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 486 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
484 | domDoc->appendChild(root); | 487 | domDoc->appendChild(root); |
485 | return root; | 488 | return root; |
486 | } | 489 | } |
487 | 490 | ||
488 | bool Serializer::addCategories(QDomElement *e, | 491 | bool Serializer::addCategories(QDomElement *e, |
489 | const vector<PwMCategoryItem> &dta) | 492 | const vector<PwMCategoryItem> &dta) |
490 | { | 493 | { |
491 | unsigned int numCat = dta.size(), i; | 494 | unsigned int numCat = dta.size(), i; |
492 | QString curId, curName; | 495 | QString curId, curName; |
493 | QDomElement curCat; | 496 | QDomElement curCat; |
494 | 497 | ||
495 | for (i = 0; i < numCat; ++i) { | 498 | for (i = 0; i < numCat; ++i) { |
496 | curId = CAT_PREFIX_WR; | 499 | curId = CAT_PREFIX_WR; |
497 | curId += tostr(i).c_str(); | 500 | curId += tostr(i).c_str(); |
498 | curName = dta[i].name.c_str(); | 501 | curName = dta[i].name.c_str(); |
499 | curCat = domDoc->createElement(curId); | 502 | curCat = domDoc->createElement(curId); |
500 | curCat.setAttribute(CAT_NAME_WR, curName); | 503 | curCat.setAttribute(CAT_NAME_WR, curName); |
501 | if (!addEntries(&curCat, dta[i].d)) { | 504 | if (!addEntries(&curCat, dta[i].d)) { |
502 | return false; | 505 | return false; |
503 | } | 506 | } |
504 | e->appendChild(curCat); | 507 | e->appendChild(curCat); |
505 | } | 508 | } |
506 | return true; | 509 | return true; |
507 | } | 510 | } |
508 | 511 | ||
509 | bool Serializer::addEntries(QDomElement *e, | 512 | bool Serializer::addEntries(QDomElement *e, |
510 | const vector<PwMDataItem> &dta) | 513 | const vector<PwMDataItem> &dta) |
511 | { | 514 | { |
512 | unsigned int numEntr = dta.size(), i; | 515 | unsigned int numEntr = dta.size(), i; |
513 | QString curId; | 516 | QString curId; |
514 | QDomElement curEntr; | 517 | QDomElement curEntr; |
515 | 518 | ||
516 | for (i = 0; i < numEntr; ++i) { | 519 | for (i = 0; i < numEntr; ++i) { |
517 | curId = ENTRY_PREFIX_WR; | 520 | curId = ENTRY_PREFIX_WR; |
518 | curId += tostr(i).c_str(); | 521 | curId += tostr(i).c_str(); |
519 | curEntr = domDoc->createElement(curId); | 522 | curEntr = domDoc->createElement(curId); |
520 | if (!writeEntry(&curEntr, dta[i])) { | 523 | if (!writeEntry(&curEntr, dta[i])) { |
521 | return false; | 524 | return false; |
522 | } | 525 | } |
523 | e->appendChild(curEntr); | 526 | e->appendChild(curEntr); |
524 | } | 527 | } |
525 | return true; | 528 | return true; |
526 | } | 529 | } |
527 | 530 | ||
528 | bool Serializer::writeEntry(QDomElement *e, | 531 | bool Serializer::writeEntry(QDomElement *e, |
529 | const PwMDataItem &_dta) | 532 | const PwMDataItem &_dta) |
530 | { | 533 | { |
531 | #if WRITE_CDATA_SEC != 0 | 534 | #if WRITE_CDATA_SEC != 0 |
532 | # define new_text(x)domDoc->createCDATASection(x) | 535 | # define new_text(x)domDoc->createCDATASection(x) |
533 | QDomCDATASection curText; | 536 | QDomCDATASection curText; |
534 | #else | 537 | #else |
535 | # define new_text(x)domDoc->createTextNode(x) | 538 | # define new_text(x)domDoc->createTextNode(x) |
536 | QDomText curText; | 539 | QDomText curText; |
537 | #endif | 540 | #endif |
538 | 541 | ||
539 | QDomText plainText; | 542 | QDomText plainText; |
540 | QDomElement tag; | 543 | QDomElement tag; |
541 | 544 | ||
542 | // begin -- This is for compatibility with the old serializer | 545 | // begin -- This is for compatibility with the old serializer |
543 | PwMDataItem dta = _dta; | 546 | PwMDataItem dta = _dta; |
544 | if (!dta.desc.size()) | 547 | if (!dta.desc.size()) |
545 | dta.desc = " "; | 548 | dta.desc = " "; |
546 | if (!dta.name.size()) | 549 | if (!dta.name.size()) |
547 | dta.name = " "; | 550 | dta.name = " "; |
548 | if (!dta.pw.size()) | 551 | if (!dta.pw.size()) |
549 | dta.pw = " "; | 552 | dta.pw = " "; |
550 | if (!dta.comment.size()) | 553 | if (!dta.comment.size()) |
551 | dta.comment = " "; | 554 | dta.comment = " "; |
552 | if (!dta.url.size()) | 555 | if (!dta.url.size()) |
553 | dta.url = " "; | 556 | dta.url = " "; |
554 | if (!dta.launcher.size()) | 557 | if (!dta.launcher.size()) |
555 | dta.launcher = " "; | 558 | dta.launcher = " "; |
556 | // end -- This is for compatibility with the old serializer | 559 | // end -- This is for compatibility with the old serializer |
557 | 560 | ||
558 | tag = domDoc->createElement(ENTRY_DESC_WR); | 561 | tag = domDoc->createElement(ENTRY_DESC_WR); |
559 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 562 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
560 | tag.appendChild(curText); | 563 | tag.appendChild(curText); |
561 | e->appendChild(tag); | 564 | e->appendChild(tag); |
562 | 565 | ||
563 | tag = domDoc->createElement(ENTRY_NAME_WR); | 566 | tag = domDoc->createElement(ENTRY_NAME_WR); |
564 | curText = new_text(escapeEntryData(dta.name.c_str())); | 567 | curText = new_text(escapeEntryData(dta.name.c_str())); |
565 | tag.appendChild(curText); | 568 | tag.appendChild(curText); |
566 | e->appendChild(tag); | 569 | e->appendChild(tag); |
567 | 570 | ||
568 | tag = domDoc->createElement(ENTRY_PW_WR); | 571 | tag = domDoc->createElement(ENTRY_PW_WR); |
569 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 572 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
570 | tag.appendChild(curText); | 573 | tag.appendChild(curText); |
571 | e->appendChild(tag); | 574 | e->appendChild(tag); |
572 | 575 | ||
573 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 576 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
574 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 577 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
575 | tag.appendChild(curText); | 578 | tag.appendChild(curText); |
576 | e->appendChild(tag); | 579 | e->appendChild(tag); |
577 | 580 | ||
578 | tag = domDoc->createElement(ENTRY_URL_WR); | 581 | tag = domDoc->createElement(ENTRY_URL_WR); |
579 | curText = new_text(escapeEntryData(dta.url.c_str())); | 582 | curText = new_text(escapeEntryData(dta.url.c_str())); |
580 | tag.appendChild(curText); | 583 | tag.appendChild(curText); |
581 | e->appendChild(tag); | 584 | e->appendChild(tag); |
582 | 585 | ||
583 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 586 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
584 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 587 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
585 | tag.appendChild(curText); | 588 | tag.appendChild(curText); |
586 | e->appendChild(tag); | 589 | e->appendChild(tag); |
587 | 590 | ||
588 | tag = domDoc->createElement(ENTRY_LVP_WR); | 591 | tag = domDoc->createElement(ENTRY_LVP_WR); |
589 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 592 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
590 | tag.appendChild(plainText); | 593 | tag.appendChild(plainText); |
591 | e->appendChild(tag); | 594 | e->appendChild(tag); |
592 | 595 | ||
593 | tag = domDoc->createElement(ENTRY_BIN_WR); | 596 | tag = domDoc->createElement(ENTRY_BIN_WR); |
594 | if (dta.binary) | 597 | if (dta.binary) |
595 | plainText = domDoc->createTextNode("1"); | 598 | plainText = domDoc->createTextNode("1"); |
596 | else | 599 | else |
597 | plainText = domDoc->createTextNode("0"); | 600 | plainText = domDoc->createTextNode("0"); |
598 | tag.appendChild(plainText); | 601 | tag.appendChild(plainText); |
599 | e->appendChild(tag); | 602 | e->appendChild(tag); |
600 | 603 | ||
601 | tag = domDoc->createElement(ENTRY_META_WR); | 604 | tag = domDoc->createElement(ENTRY_META_WR); |
602 | if (!writeMeta(&tag, dta.meta)) | 605 | if (!writeMeta(&tag, dta.meta)) |
603 | return false; | 606 | return false; |
604 | e->appendChild(tag); | 607 | e->appendChild(tag); |
605 | 608 | ||
606 | #undef new_text | 609 | #undef new_text |
607 | return true; | 610 | return true; |
608 | } | 611 | } |
609 | 612 | ||
610 | bool Serializer::writeMeta(QDomElement *e, | 613 | bool Serializer::writeMeta(QDomElement *e, |
611 | const PwMMetaData &dta) | 614 | const PwMMetaData &dta) |
612 | { | 615 | { |
613 | QDomText text; | 616 | QDomText text; |
614 | QDomElement tag; | 617 | QDomElement tag; |
615 | 618 | ||
616 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 619 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
617 | //So do not transform an empty value at all. | 620 | //So do not transform an empty value at all. |
618 | if (dta.create.isValid()) | 621 | if (dta.create.isValid()) |
619 | { | 622 | { |
620 | tag = domDoc->createElement(META_CREATE_DATE); | 623 | tag = domDoc->createElement(META_CREATE_DATE); |
621 | #ifndef PWM_EMBEDDED | 624 | #ifndef PWM_EMBEDDED |
622 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 625 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
623 | #else | 626 | #else |
624 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 627 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
625 | #endif | 628 | #endif |
626 | tag.appendChild(text); | 629 | tag.appendChild(text); |
627 | e->appendChild(tag); | 630 | e->appendChild(tag); |
628 | } | 631 | } |
629 | 632 | ||
630 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 633 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
631 | //So do not transform an empty value at all. | 634 | //So do not transform an empty value at all. |
632 | if (dta.valid.isValid()) | 635 | if (dta.valid.isValid()) |
633 | { | 636 | { |
634 | tag = domDoc->createElement(META_VALID_DATE); | 637 | tag = domDoc->createElement(META_VALID_DATE); |
635 | #ifndef PWM_EMBEDDED | 638 | #ifndef PWM_EMBEDDED |
636 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 639 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
637 | #else | 640 | #else |
638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 641 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
639 | #endif | 642 | #endif |
640 | tag.appendChild(text); | 643 | tag.appendChild(text); |
641 | e->appendChild(tag); | 644 | e->appendChild(tag); |
642 | } | 645 | } |
643 | 646 | ||
644 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 647 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
645 | //So do not transform an empty value at all. | 648 | //So do not transform an empty value at all. |
646 | if (dta.expire.isValid()) | 649 | if (dta.expire.isValid()) |
647 | { | 650 | { |
648 | tag = domDoc->createElement(META_EXPIRE_DATE); | 651 | tag = domDoc->createElement(META_EXPIRE_DATE); |
649 | #ifndef PWM_EMBEDDED | 652 | #ifndef PWM_EMBEDDED |
650 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 653 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
651 | #else | 654 | #else |
652 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 655 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
653 | #endif | 656 | #endif |
654 | tag.appendChild(text); | 657 | tag.appendChild(text); |
655 | e->appendChild(tag); | 658 | e->appendChild(tag); |
656 | } | 659 | } |
657 | 660 | ||
658 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 661 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
659 | //So do not transform an empty value at all. | 662 | //So do not transform an empty value at all. |
660 | if (dta.update.isValid()) | 663 | if (dta.update.isValid()) |
661 | { | 664 | { |
662 | tag = domDoc->createElement(META_UPDATE_DATE); | 665 | tag = domDoc->createElement(META_UPDATE_DATE); |
663 | #ifndef PWM_EMBEDDED | 666 | #ifndef PWM_EMBEDDED |
664 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 667 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
665 | #else | 668 | #else |
666 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 669 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
667 | #endif | 670 | #endif |
668 | tag.appendChild(text); | 671 | tag.appendChild(text); |
669 | e->appendChild(tag); | 672 | e->appendChild(tag); |
670 | } | 673 | } |
671 | 674 | ||
672 | tag = domDoc->createElement(META_UPDATE_INT); | 675 | tag = domDoc->createElement(META_UPDATE_INT); |
673 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 676 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
674 | tag.appendChild(text); | 677 | tag.appendChild(text); |
675 | e->appendChild(tag); | 678 | e->appendChild(tag); |
676 | 679 | ||
677 | tag = domDoc->createElement(META_UNIQUEID); | 680 | tag = domDoc->createElement(META_UNIQUEID); |
678 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); | 681 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); |
679 | tag.appendChild(text); | 682 | tag.appendChild(text); |
680 | e->appendChild(tag); | 683 | e->appendChild(tag); |
681 | 684 | ||
682 | #undef new_text | 685 | #undef new_text |
683 | return true; | 686 | return true; |
684 | } | 687 | } |
685 | 688 | ||
686 | QString Serializer::escapeEntryData(QString dta) | 689 | QString Serializer::escapeEntryData(QString dta) |
687 | { | 690 | { |
688 | #ifndef PWM_EMBEDDED | 691 | #ifndef PWM_EMBEDDED |
689 | dta.replace('\n', "$>--endl--<$"); | 692 | dta.replace('\n', "$>--endl--<$"); |
690 | dta.replace("]]>", "||>"); | 693 | dta.replace("]]>", "||>"); |
691 | #else | 694 | #else |
692 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 695 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
693 | dta.replace(QRegExp("]]>"), "||>"); | 696 | dta.replace(QRegExp("]]>"), "||>"); |
694 | #endif | 697 | #endif |
695 | return dta; | 698 | return dta; |
696 | } | 699 | } |
697 | 700 | ||
698 | QString Serializer::unescapeEntryData(QString dta) | 701 | QString Serializer::unescapeEntryData(QString dta) |
699 | { | 702 | { |
700 | #ifndef PWM_EMBEDDED | 703 | #ifndef PWM_EMBEDDED |
701 | dta.replace("$>--endl--<$", "\n"); | 704 | dta.replace("$>--endl--<$", "\n"); |
702 | dta.replace("||>", "]]>"); | 705 | dta.replace("||>", "]]>"); |
703 | #else | 706 | #else |
707 | #ifdef DESKTOP_VERSION | ||
708 | dta.replace("$>--endl--<$", "\n"); | ||
709 | dta.replace("||>", "]]>"); | ||
710 | #else | ||
704 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); | 711 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); |
705 | dta.replace(QRegExp("||>"), "]]>"); | 712 | dta.replace(QRegExp("||>"), "]]>"); |
706 | #endif | 713 | #endif |
714 | #endif | ||
707 | return dta; | 715 | return dta; |
708 | } | 716 | } |
709 | 717 | ||
710 | 718 | ||
711 | //US ENH: the following methods are getting used to write/read sync entries | 719 | //US ENH: the following methods are getting used to write/read sync entries |
712 | /** read the syncentries in the node "n" */ | 720 | /** read the syncentries in the node "n" */ |
713 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) | 721 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) |
714 | { | 722 | { |
715 | QDomNodeList nl(n.childNodes()); | 723 | QDomNodeList nl(n.childNodes()); |
716 | QDomNode cur; | 724 | QDomNode cur; |
717 | 725 | ||
718 | QString devicename, val; | 726 | QString devicename, val; |
719 | unsigned int numSync = nl.count(), i; | 727 | unsigned int numSync = nl.count(), i; |
720 | PwMSyncItem curSync; | 728 | PwMSyncItem curSync; |
721 | bool ok = true; | 729 | bool ok = true; |
722 | 730 | ||
723 | if (!numSync) { | 731 | if (!numSync) { |
724 | //no sync entries is a possible result | 732 | //no sync entries is a possible result |
725 | printDebug("Serializer::readSyncData(): empty"); | 733 | printDebug("Serializer::readSyncData(): empty"); |
726 | return true; | 734 | return true; |
727 | } | 735 | } |
728 | for (i = 0; i < numSync; ++i) { | 736 | for (i = 0; i < numSync; ++i) { |
729 | cur = nl.item(i); | 737 | cur = nl.item(i); |
730 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { | 738 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { |
731 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); | 739 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); |
732 | val = cur.toElement().text(); | 740 | val = cur.toElement().text(); |
733 | 741 | ||
734 | if ((val == "") || (devicename == QString::null)) { | 742 | if ((val == "") || (devicename == QString::null)) { |
735 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); | 743 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); |
736 | continue; | 744 | continue; |
737 | } | 745 | } |
738 | 746 | ||
739 | curSync.syncName = devicename.latin1(); | 747 | curSync.syncName = devicename.latin1(); |
740 | #ifndef PWM_EMBEDDED | 748 | #ifndef PWM_EMBEDDED |
741 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); | 749 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); |
742 | #else | 750 | #else |
743 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 751 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
744 | if (ok == false) | 752 | if (ok == false) |
745 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); | 753 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); |
746 | 754 | ||
747 | #endif | 755 | #endif |
748 | dta->push_back(curSync); | 756 | dta->push_back(curSync); |
749 | } | 757 | } |
750 | } | 758 | } |
751 | return true; | 759 | return true; |
752 | 760 | ||
753 | } | 761 | } |
754 | 762 | ||
755 | 763 | ||
756 | 764 | ||
757 | bool Serializer::addSyncData(QDomElement *e, | 765 | bool Serializer::addSyncData(QDomElement *e, |
758 | const vector<PwMSyncItem> &dta) | 766 | const vector<PwMSyncItem> &dta) |
759 | { | 767 | { |
760 | unsigned int numSync = dta.size(), i; | 768 | unsigned int numSync = dta.size(), i; |
761 | QString curId, curDeviceName; | 769 | QString curId, curDeviceName; |
762 | QDomElement curSync; | 770 | QDomElement curSync; |
763 | QDomText text; | 771 | QDomText text; |
764 | 772 | ||
765 | for (i = 0; i < numSync; ++i) { | 773 | for (i = 0; i < numSync; ++i) { |
766 | curId = SYNC_TARGET_PREFIX; | 774 | curId = SYNC_TARGET_PREFIX; |
767 | curId += tostr(i).c_str(); | 775 | curId += tostr(i).c_str(); |
768 | curDeviceName = dta[i].syncName.c_str(); | 776 | curDeviceName = dta[i].syncName.c_str(); |
769 | curSync = domDoc->createElement(curId); | 777 | curSync = domDoc->createElement(curId); |
770 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); | 778 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); |
771 | 779 | ||
772 | #ifndef PWM_EMBEDDED | 780 | #ifndef PWM_EMBEDDED |
773 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); | 781 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); |
774 | #else | 782 | #else |
775 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); | 783 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); |
776 | #endif | 784 | #endif |
777 | curSync.appendChild(text); | 785 | curSync.appendChild(text); |
778 | 786 | ||
779 | e->appendChild(curSync); | 787 | e->appendChild(curSync); |
780 | 788 | ||
781 | } | 789 | } |
782 | return true; | 790 | return true; |
783 | } | 791 | } |
784 | 792 | ||