author | ulf69 <ulf69> | 2004-09-24 22:21:25 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-24 22:21:25 (UTC) |
commit | e695903cc49b33e63505b651b13d830e318fc29a (patch) (unidiff) | |
tree | fd210e2defbdcb3f3d9d739d0b00e6853705af29 | |
parent | a884dac6f756b3702a10ae97aa8782e4d2a84b20 (diff) | |
download | kdepimpi-e695903cc49b33e63505b651b13d830e318fc29a.zip kdepimpi-e695903cc49b33e63505b651b13d830e318fc29a.tar.gz kdepimpi-e695903cc49b33e63505b651b13d830e318fc29a.tar.bz2 |
fixed bug with QDomDocument handling, plus some GUI enhancements
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 8 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmexception.cpp | 7 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 12 |
3 files changed, 23 insertions, 4 deletions
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp index e42dd9d..5e675fc 100644 --- a/pwmanager/pwmanager/pwmdocui.cpp +++ b/pwmanager/pwmanager/pwmdocui.cpp | |||
@@ -59,399 +59,399 @@ PwMDocUi::~PwMDocUi() | |||
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, " | 186 | i18n("This feature is not available, " |
187 | "if you execute PwM with \"root\" " | 187 | "if you execute PwM with \"root\" " |
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 " | 195 | i18n("Can't deep-lock, because the document " |
196 | "hasn't been saved, yet. Please save " | 196 | "hasn't been saved, yet. Please save " |
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 " | 204 | i18n("GPasman does not support passwords " |
205 | "shorter than 4 characters! Please try " | 205 | "shorter than 4 characters! Please try " |
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 | ("\" has been modified.\n" | 231 | ("\" has 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_success) { | 276 | } else if (ret != e_success) { |
277 | KMessageBox::error(currentView, | 277 | KMessageBox::error(currentView, |
278 | i18n("Error: Couldn't write to file.\n" | 278 | i18n("Error: Couldn't write to file.\n" |
279 | "Please check if you have permission to " | 279 | "Please check if you have permission to " |
280 | "write to the file in that directory."), | 280 | "write to the file in that directory."), |
281 | i18n("error while writing")); | 281 | i18n("error while writing")); |
282 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 282 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
283 | return false; | 283 | return false; |
284 | } | 284 | } |
285 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 285 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
286 | return true; | 286 | return true; |
287 | } | 287 | } |
288 | 288 | ||
289 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) | 289 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) |
290 | { | 290 | { |
291 | PWM_ASSERT(doc); | 291 | PWM_ASSERT(doc); |
292 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 292 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
293 | if (doc->isDocEmpty()) { | 293 | if (doc->isDocEmpty()) { |
294 | KMessageBox::information(currentView, | 294 | KMessageBox::information(currentView, |
295 | i18n | 295 | i18n |
296 | ("Sorry, there's nothing to save.\n" | 296 | ("Sorry, there's nothing to save.\n" |
297 | "Please first add some passwords."), | 297 | "Please first add some passwords."), |
298 | i18n("nothing to do")); | 298 | i18n("nothing to do")); |
299 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 299 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
300 | return true; | 300 | return true; |
301 | } | 301 | } |
302 | #ifndef PWM_EMBEDDED | 302 | #ifndef PWM_EMBEDDED |
303 | QString fn(KFileDialog::getSaveFileName(QString::null, | 303 | QString fn(KFileDialog::getSaveFileName(QString::null, |
304 | i18n("*.pwm|PwManager Password file"), | 304 | i18n("*.pwm|PwManager Password file"), |
305 | currentView)); | 305 | currentView)); |
306 | #else | 306 | #else |
307 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); | 307 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); |
308 | fn = KFileDialog::getSaveFileName(fn, | 308 | fn = KFileDialog::getSaveFileName(fn, |
309 | i18n("password filename(*.pwm)"), | 309 | i18n("password filename(*.pwm)"), |
310 | currentView); | 310 | currentView); |
311 | 311 | ||
312 | #endif | 312 | #endif |
313 | if (fn == "") { | 313 | if (fn == "") { |
314 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 314 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
315 | return false; | 315 | return false; |
316 | } | 316 | } |
317 | if (fn.right(4) != ".pwm") | 317 | if (fn.right(4) != ".pwm") |
318 | fn += ".pwm"; | 318 | fn += ".pwm"; |
319 | 319 | ||
320 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); | 320 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); |
321 | if (ret != e_success) { | 321 | if (ret != e_success) { |
322 | KMessageBox::error(currentView, | 322 | KMessageBox::error(currentView, |
323 | i18n("Error: Couldn't write to file.\n" | 323 | i18n("Error: Couldn't write to file.\n" |
324 | "Please check if you have permission to " | 324 | "Please check if you have permission to " |
325 | "write to the file in that directory."), | 325 | "write to the file in that directory."), |
326 | i18n("error while writing")); | 326 | i18n("error while writing")); |
327 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 327 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
328 | return false; | 328 | return false; |
329 | } | 329 | } |
330 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 330 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
331 | return true; | 331 | return true; |
332 | } | 332 | } |
333 | 333 | ||
334 | bool PwMDocUi::openDocUi(PwMDoc *doc, | 334 | bool PwMDocUi::openDocUi(PwMDoc *doc, |
335 | QString filename, | 335 | QString filename, |
336 | bool openDeepLocked) | 336 | bool openDeepLocked) |
337 | { | 337 | { |
338 | if (filename.isEmpty()) | 338 | if (filename.isEmpty()) |
339 | { | 339 | { |
340 | #ifndef PWM_EMBEDDED | 340 | #ifndef PWM_EMBEDDED |
341 | filename = KFileDialog::getOpenFileName(QString::null, | 341 | filename = KFileDialog::getOpenFileName(QString::null, |
342 | i18n("*.pwm|PwManager Password file\n" | 342 | i18n("*.pwm|PwManager Password file\n" |
343 | "*|All files"), getCurrentView()); | 343 | "*|All files"), getCurrentView()); |
344 | #else | 344 | #else |
345 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); | 345 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); |
346 | filename = KFileDialog::getOpenFileName(filename, | 346 | filename = KFileDialog::getOpenFileName(filename, |
347 | i18n("password filename(*.pwm)"), getCurrentView()); | 347 | i18n("password filename(*.pwm)"), getCurrentView()); |
348 | #endif | 348 | #endif |
349 | } | 349 | } |
350 | if (filename.isEmpty()) | 350 | if (filename.isEmpty()) |
351 | goto cancelOpen; | 351 | goto cancelOpen; |
352 | PwMerror ret; | 352 | PwMerror ret; |
353 | while (true) { | 353 | while (true) { |
354 | int lockStat = -1; | 354 | int lockStat = -1; |
355 | if (openDeepLocked) { | 355 | if (openDeepLocked) { |
356 | lockStat = 2; | 356 | lockStat = 2; |
357 | } else { | 357 | } else { |
358 | if (conf()->confGlobUnlockOnOpen()) { | 358 | if (conf()->confGlobUnlockOnOpen()) { |
359 | lockStat = 0; | 359 | lockStat = 0; |
360 | } else { | 360 | } else { |
361 | lockStat = 1; | 361 | lockStat = 1; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | ret = doc->openDoc(&filename, lockStat); | 364 | ret = doc->openDoc(&filename, lockStat); |
365 | qDebug("pwmdocui::OpenDocui %i", ret); | 365 | qDebug("pwmdocui::OpenDocui %i", ret); |
366 | if (ret != e_success) { | 366 | if (ret != e_success) { |
367 | if (ret == e_readFile || ret == e_openFile) { | 367 | if (ret == e_readFile || ret == e_openFile) { |
368 | KMessageBox::error(getCurrentView(), | 368 | KMessageBox::error(getCurrentView(), |
369 | i18n("Could not read file!") | 369 | i18n("Could not read file!") |
370 | + "\n" | 370 | + "\n" |
371 | + filename, | 371 | + filename, |
372 | i18n("file error")); | 372 | i18n("file error")); |
373 | goto cancelOpen; | 373 | goto cancelOpen; |
374 | } | 374 | } |
375 | if (ret == e_alreadyOpen) { | 375 | if (ret == e_alreadyOpen) { |
376 | KMessageBox::error(getCurrentView(), | 376 | KMessageBox::error(getCurrentView(), |
377 | i18n("This file is already open."), | 377 | i18n("This file is already open."), |
378 | i18n("already open")); | 378 | i18n("already open")); |
379 | goto cancelOpen; | 379 | goto cancelOpen; |
380 | } | 380 | } |
381 | if (ret == e_fileVer) { | 381 | if (ret == e_fileVer) { |
382 | KMessageBox::error(getCurrentView(), | 382 | KMessageBox::error(getCurrentView(), |
383 | i18n | 383 | i18n |
384 | ("File-version is not supported!\n" | 384 | ("File-version is not supported!\n" |
385 | "Did you create this file with an older or newer version of PwM?"), | 385 | "Did you create this file with an older or newer version of PwM?"), |
386 | i18n | 386 | i18n |
387 | ("incompatible version")); | 387 | ("incompatible version")); |
388 | goto cancelOpen; | 388 | goto cancelOpen; |
389 | } | 389 | } |
390 | if (ret == e_wrongPw) { | 390 | if (ret == e_wrongPw) { |
391 | continue; | 391 | continue; |
392 | } | 392 | } |
393 | if (ret == e_noPw) { | 393 | if (ret == e_noPw) { |
394 | goto cancelOpen; | 394 | goto cancelOpen; |
395 | } | 395 | } |
396 | if (ret == e_fileFormat) { | 396 | if (ret == e_fileFormat) { |
397 | KMessageBox::error(getCurrentView(), | 397 | KMessageBox::error(getCurrentView(), |
398 | i18n | 398 | i18n |
399 | ("Sorry, this file has not been recognized " | 399 | ("Sorry, this file has not been recognized " |
400 | "as a PwM Password file.\n" | 400 | "as a PwM Password file.\n" |
401 | "Probably you have selected the wrong file."), | 401 | "Probably you have selected the wrong file."), |
402 | i18n | 402 | i18n |
403 | ("no PwM password-file")); | 403 | ("no PwM password-file")); |
404 | goto cancelOpen; | 404 | goto cancelOpen; |
405 | } | 405 | } |
406 | if (ret == e_fileCorrupt) { | 406 | if (ret == e_fileCorrupt) { |
407 | KMessageBox::error(getCurrentView(), | 407 | KMessageBox::error(getCurrentView(), |
408 | i18n | 408 | i18n |
409 | ("File corrupt!\n" | 409 | ("File corrupt!\n" |
410 | "Maybe the media, you stored this file on, " | 410 | "Maybe the media, you stored this file on, " |
411 | "had bad sectors?"), | 411 | "had bad sectors?"), |
412 | i18n | 412 | i18n |
413 | ("checksum error")); | 413 | ("checksum error")); |
414 | goto cancelOpen; | 414 | goto cancelOpen; |
415 | } | 415 | } |
416 | } | 416 | } |
417 | break; | 417 | break; |
418 | } | 418 | } |
419 | return true; | 419 | return true; |
420 | 420 | ||
421 | cancelOpen: | 421 | cancelOpen: |
422 | return false; | 422 | return false; |
423 | } | 423 | } |
424 | 424 | ||
425 | QString PwMDocUi::string_defaultCategory() | 425 | QString PwMDocUi::string_defaultCategory() |
426 | { | 426 | { |
427 | return i18n("Default"); | 427 | return i18n("Default"); |
428 | } | 428 | } |
429 | 429 | ||
430 | QString PwMDocUi::string_locked() | 430 | QString PwMDocUi::string_locked() |
431 | { | 431 | { |
432 | return i18n("<LOCKED>"); | 432 | return i18n("<LOCKED>"); |
433 | } | 433 | } |
434 | 434 | ||
435 | QString PwMDocUi::string_deepLockedShort() | 435 | QString PwMDocUi::string_deepLockedShort() |
436 | { | 436 | { |
437 | return i18n("DEEP-LOCKED"); | 437 | return i18n("DEEP-LOCKED"); |
438 | } | 438 | } |
439 | 439 | ||
440 | QString PwMDocUi::string_deepLockedLong() | 440 | QString PwMDocUi::string_deepLockedLong() |
441 | { | 441 | { |
442 | return i18n("This file is DEEP-LOCKED!\n" | 442 | return i18n("This file is DEEP-LOCKED!\n" |
443 | "That means all data has been encrypted " | 443 | "That means all data has been encrypted\n" |
444 | "and written out to the file. If you want " | 444 | "and written out to the file. If you want\n" |
445 | "to see the entries, please UNLOCK the file. " | 445 | "to see the entries, please UNLOCK the file.\n" |
446 | "While unlocking, you will be prompted for the " | 446 | "While unlocking, you will be prompted for the\n" |
447 | "master-password or the key-card."); | 447 | "master-password or the key-card."); |
448 | } | 448 | } |
449 | 449 | ||
450 | QString PwMDocUi::string_defaultTitle() | 450 | QString PwMDocUi::string_defaultTitle() |
451 | { | 451 | { |
452 | return i18n("Untitled"); | 452 | return i18n("Untitled"); |
453 | } | 453 | } |
454 | 454 | ||
455 | #ifndef PWM_EMBEDDED | 455 | #ifndef PWM_EMBEDDED |
456 | #include "pwmdocui.moc" | 456 | #include "pwmdocui.moc" |
457 | #endif | 457 | #endif |
diff --git a/pwmanager/pwmanager/pwmexception.cpp b/pwmanager/pwmanager/pwmexception.cpp index 4c00b04..c0dbb39 100644 --- a/pwmanager/pwmanager/pwmexception.cpp +++ b/pwmanager/pwmanager/pwmexception.cpp | |||
@@ -1,58 +1,65 @@ | |||
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 | 20 | ||
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | 22 | ||
23 | #include <kmessagebox.h> | 23 | #include <kmessagebox.h> |
24 | 24 | ||
25 | 25 | ||
26 | void pwmFatal(const char *id, | 26 | void pwmFatal(const char *id, |
27 | const char *file, | 27 | const char *file, |
28 | int line) | 28 | int line) |
29 | { | 29 | { |
30 | cerr << PROG_NAME " " << id << " at " | 30 | cerr << PROG_NAME " " << id << " at " |
31 | << file << ":" << line | 31 | << file << ":" << line |
32 | << endl; | 32 | << endl; |
33 | } | 33 | } |
34 | 34 | ||
35 | void __printError(const string &msg) | 35 | void __printError(const string &msg) |
36 | { | 36 | { |
37 | QString __msg(PROG_NAME " generated a fatal fault:\n"); | 37 | QString __msg(PROG_NAME " generated a fatal fault:\n"); |
38 | __msg += msg.c_str(); | 38 | __msg += msg.c_str(); |
39 | cerr << "\n\n" << __msg.latin1() << endl; | 39 | cerr << "\n\n" << __msg.latin1() << endl; |
40 | KMessageBox::error(0, __msg, PROG_NAME " fatal ERROR!"); | 40 | KMessageBox::error(0, __msg, PROG_NAME " fatal ERROR!"); |
41 | } | 41 | } |
42 | 42 | ||
43 | void __printInfo(const string &msg) | 43 | void __printInfo(const string &msg) |
44 | { | 44 | { |
45 | cout << PROG_NAME " INFO: " << msg << endl; | 45 | cout << PROG_NAME " INFO: " << msg << endl; |
46 | #ifdef PWM_DEBUG | ||
47 | qDebug("%s INFO: %s", PROG_NAME, msg.c_str()) ; | ||
48 | #endif | ||
46 | } | 49 | } |
47 | 50 | ||
48 | void __printWarn(const string &msg) | 51 | void __printWarn(const string &msg) |
49 | { | 52 | { |
50 | cerr << PROG_NAME " WARNING: " << msg << endl; | 53 | cerr << PROG_NAME " WARNING: " << msg << endl; |
54 | #ifdef PWM_DEBUG | ||
55 | qDebug("%s WARNING: %s", PROG_NAME, msg.c_str()) ; | ||
56 | #endif | ||
51 | } | 57 | } |
52 | 58 | ||
53 | #ifdef PWM_DEBUG | 59 | #ifdef PWM_DEBUG |
54 | void __printDebug(const string &msg) | 60 | void __printDebug(const string &msg) |
55 | { | 61 | { |
56 | cout << PROG_NAME " DEBUG: " << msg << endl; | 62 | cout << PROG_NAME " DEBUG: " << msg << endl; |
63 | qDebug("%s DEBUG: %s", PROG_NAME, msg.c_str()) ; | ||
57 | } | 64 | } |
58 | #endif // PWM_DEBUG | 65 | #endif // PWM_DEBUG |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index 2810b48..fcdcec3 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,569 +1,581 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "serializer.h" | 21 | #include "serializer.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | 23 | ||
24 | #ifdef PWM_EMBEDDED | 24 | #ifdef PWM_EMBEDDED |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | /* enable/disable serializer debugging (0/1) */ | 29 | /* enable/disable serializer debugging (0/1) */ |
30 | #define SERIALIZER_DEBUG1 | 30 | #define SERIALIZER_DEBUG1 |
31 | /* use the old xml tags for writing (0/1) */ | 31 | /* use the old xml tags for writing (0/1) */ |
32 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
33 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
34 | #define WRITE_CDATA_SEC 0 | 34 | #define WRITE_CDATA_SEC 0 |
35 | 35 | ||
36 | 36 | ||
37 | #define META_CREATE_DATE"c" | 37 | #define META_CREATE_DATE"c" |
38 | #define META_VALID_DATE "v" | 38 | #define META_VALID_DATE "v" |
39 | #define META_EXPIRE_DATE"e" | 39 | #define META_EXPIRE_DATE"e" |
40 | #define META_UPDATE_DATE"u" | 40 | #define META_UPDATE_DATE"u" |
41 | #define META_UPDATE_INT "i" | 41 | #define META_UPDATE_INT "i" |
42 | //US ENH : uniqueid | 42 | //US ENH : uniqueid |
43 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
44 | 44 | ||
45 | /* This is compatibility stuff. | 45 | /* This is compatibility stuff. |
46 | * The names of the entries have changed and here are the | 46 | * The names of the entries have changed and here are the |
47 | * new and old ones | 47 | * new and old ones |
48 | */ | 48 | */ |
49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
50 | #define VER_STR_OLD "ver" | 50 | #define VER_STR_OLD "ver" |
51 | #define COMPAT_VER_OLD "0x02" | 51 | #define COMPAT_VER_OLD "0x02" |
52 | #define CAT_ROOT_OLD "categories" | 52 | #define CAT_ROOT_OLD "categories" |
53 | #define CAT_PREFIX_OLD "cat_" | 53 | #define CAT_PREFIX_OLD "cat_" |
54 | #define CAT_NAME_OLD "name" | 54 | #define CAT_NAME_OLD "name" |
55 | #define ENTRY_PREFIX_OLD"entry_" | 55 | #define ENTRY_PREFIX_OLD"entry_" |
56 | #define ENTRY_DESC_OLD "desc" | 56 | #define ENTRY_DESC_OLD "desc" |
57 | #define ENTRY_NAME_OLD "name" | 57 | #define ENTRY_NAME_OLD "name" |
58 | #define ENTRY_PW_OLD "pw" | 58 | #define ENTRY_PW_OLD "pw" |
59 | #define ENTRY_COMMENT_OLD"comment" | 59 | #define ENTRY_COMMENT_OLD"comment" |
60 | #define ENTRY_URL_OLD "url" | 60 | #define ENTRY_URL_OLD "url" |
61 | #define ENTRY_LAUNCHER_OLD"launcher" | 61 | #define ENTRY_LAUNCHER_OLD"launcher" |
62 | #define ENTRY_LVP_OLD "listViewPos" | 62 | #define ENTRY_LVP_OLD "listViewPos" |
63 | #define ENTRY_BIN_OLD "b" | 63 | #define ENTRY_BIN_OLD "b" |
64 | #define ENTRY_META_OLD "m" | 64 | #define ENTRY_META_OLD "m" |
65 | 65 | ||
66 | #define ROOT_MAGIC_NEW "P" | 66 | #define ROOT_MAGIC_NEW "P" |
67 | #define VER_STR_NEW "v" | 67 | #define VER_STR_NEW "v" |
68 | #define COMPAT_VER_NEW "2" | 68 | #define COMPAT_VER_NEW "2" |
69 | #define CAT_ROOT_NEW "c" | 69 | #define CAT_ROOT_NEW "c" |
70 | #define CAT_PREFIX_NEW "c" | 70 | #define CAT_PREFIX_NEW "c" |
71 | #define CAT_NAME_NEW "n" | 71 | #define CAT_NAME_NEW "n" |
72 | #define ENTRY_PREFIX_NEW"e" | 72 | #define ENTRY_PREFIX_NEW"e" |
73 | #define ENTRY_DESC_NEW "d" | 73 | #define ENTRY_DESC_NEW "d" |
74 | #define ENTRY_NAME_NEW "n" | 74 | #define ENTRY_NAME_NEW "n" |
75 | #define ENTRY_PW_NEW "p" | 75 | #define ENTRY_PW_NEW "p" |
76 | #define ENTRY_COMMENT_NEW"c" | 76 | #define ENTRY_COMMENT_NEW"c" |
77 | #define ENTRY_URL_NEW "u" | 77 | #define ENTRY_URL_NEW "u" |
78 | #define ENTRY_LAUNCHER_NEW"l" | 78 | #define ENTRY_LAUNCHER_NEW"l" |
79 | #define ENTRY_LVP_NEW "v" | 79 | #define ENTRY_LVP_NEW "v" |
80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
81 | #define ENTRY_META_NEW ENTRY_META_OLD | 81 | #define ENTRY_META_NEW ENTRY_META_OLD |
82 | 82 | ||
83 | #if USE_OLD_TAGS != 0 | 83 | #if USE_OLD_TAGS != 0 |
84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
85 | # define VER_STR_WR VER_STR_OLD | 85 | # define VER_STR_WR VER_STR_OLD |
86 | # define COMPAT_VER_WR COMPAT_VER_OLD | 86 | # define COMPAT_VER_WR COMPAT_VER_OLD |
87 | # define CAT_ROOT_WR CAT_ROOT_OLD | 87 | # define CAT_ROOT_WR CAT_ROOT_OLD |
88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
89 | # define CAT_NAME_WR CAT_NAME_OLD | 89 | # define CAT_NAME_WR CAT_NAME_OLD |
90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
93 | # define ENTRY_PW_WR ENTRY_PW_OLD | 93 | # define ENTRY_PW_WR ENTRY_PW_OLD |
94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
95 | # define ENTRY_URL_WR ENTRY_URL_OLD | 95 | # define ENTRY_URL_WR ENTRY_URL_OLD |
96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
99 | # define ENTRY_META_WR ENTRY_META_OLD | 99 | # define ENTRY_META_WR ENTRY_META_OLD |
100 | #else | 100 | #else |
101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
102 | # define VER_STR_WR VER_STR_NEW | 102 | # define VER_STR_WR VER_STR_NEW |
103 | # define COMPAT_VER_WR COMPAT_VER_NEW | 103 | # define COMPAT_VER_WR COMPAT_VER_NEW |
104 | # define CAT_ROOT_WR CAT_ROOT_NEW | 104 | # define CAT_ROOT_WR CAT_ROOT_NEW |
105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
106 | # define CAT_NAME_WR CAT_NAME_NEW | 106 | # define CAT_NAME_WR CAT_NAME_NEW |
107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
110 | # define ENTRY_PW_WR ENTRY_PW_NEW | 110 | # define ENTRY_PW_WR ENTRY_PW_NEW |
111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
112 | # define ENTRY_URL_WR ENTRY_URL_NEW | 112 | # define ENTRY_URL_WR ENTRY_URL_NEW |
113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
116 | # define ENTRY_META_WR ENTRY_META_NEW | 116 | # define ENTRY_META_WR ENTRY_META_NEW |
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | 119 | ||
120 | Serializer::Serializer() | 120 | Serializer::Serializer() |
121 | { | 121 | { |
122 | defaultLockStat = true; | 122 | defaultLockStat = true; |
123 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | ||
124 | #ifndef PWM_EMBEDDED | ||
123 | domDoc = new QDomDocument; | 125 | domDoc = new QDomDocument; |
126 | #else | ||
127 | domDoc = new QDomDocument("mydoc"); | ||
128 | #endif | ||
124 | } | 129 | } |
125 | 130 | ||
126 | Serializer::Serializer(const QCString &buffer) | 131 | Serializer::Serializer(const QCString &buffer) |
127 | { | 132 | { |
128 | defaultLockStat = true; | 133 | defaultLockStat = true; |
134 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | ||
135 | #ifndef PWM_EMBEDDED | ||
129 | domDoc = new QDomDocument; | 136 | domDoc = new QDomDocument; |
137 | #else | ||
138 | domDoc = new QDomDocument("mydoc"); | ||
139 | #endif | ||
140 | |||
130 | if (!parseXml(buffer)) { | 141 | if (!parseXml(buffer)) { |
131 | delete domDoc; | 142 | delete domDoc; |
132 | #ifndef PWM_EMBEDDED | 143 | #ifndef PWM_EMBEDDED |
133 | throw PwMException(PwMException::EX_PARSE); | 144 | throw PwMException(PwMException::EX_PARSE); |
134 | #else | 145 | #else |
135 | qDebug("Serializer::Serializer : Parse Exception "); | 146 | qDebug("Serializer::Serializer : Parse Exception "); |
136 | #endif | 147 | #endif |
137 | } | 148 | } |
138 | } | 149 | } |
139 | 150 | ||
140 | Serializer::~Serializer() | 151 | Serializer::~Serializer() |
141 | { | 152 | { |
142 | delete_ifnot_null(domDoc); | 153 | delete_ifnot_null(domDoc); |
143 | } | 154 | } |
144 | 155 | ||
145 | void Serializer::clear() | 156 | void Serializer::clear() |
146 | { | 157 | { |
147 | delete_ifnot_null(domDoc); | 158 | delete_ifnot_null(domDoc); |
148 | domDoc = new QDomDocument; | 159 | domDoc = new QDomDocument; |
149 | } | 160 | } |
150 | 161 | ||
151 | bool Serializer::parseXml(const QCString &buffer) | 162 | bool Serializer::parseXml(const QCString &buffer) |
152 | { | 163 | { |
153 | PWM_ASSERT(domDoc); | 164 | PWM_ASSERT(domDoc); |
154 | #ifndef PWM_EMBEDDED | 165 | #ifndef PWM_EMBEDDED |
155 | if (!domDoc->setContent(buffer, true)) | 166 | if (!domDoc->setContent(buffer, true)) |
156 | return false; | 167 | return false; |
157 | #else | 168 | #else |
158 | if (!domDoc->setContent(buffer)) | 169 | if (!domDoc->setContent(buffer)) |
159 | return false; | 170 | return false; |
160 | #endif | 171 | #endif |
161 | if (!checkValid()) | 172 | if (!checkValid()) |
162 | return false; | 173 | return false; |
163 | return true; | 174 | return true; |
164 | } | 175 | } |
165 | 176 | ||
166 | QCString Serializer::getXml() | 177 | QCString Serializer::getXml() |
167 | { | 178 | { |
168 | PWM_ASSERT(domDoc); | 179 | PWM_ASSERT(domDoc); |
169 | 180 | ||
170 | #ifndef PWM_EMBEDDED | 181 | #ifndef PWM_EMBEDDED |
171 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 182 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
172 | QCString tmp(domDoc->toCString(8)); | 183 | QCString tmp(domDoc->toCString(8)); |
173 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 184 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
174 | cout << tmp << endl; | 185 | cout << tmp << endl; |
175 | printDebug("<END Serializer::getXml() dump>"); | 186 | printDebug("<END Serializer::getXml() dump>"); |
176 | #endif // DEBUG | 187 | #endif // DEBUG |
177 | 188 | ||
178 | QCString ret(domDoc->toCString(0)); | 189 | QCString ret(domDoc->toCString(0)); |
179 | ret.replace('\n', ""); | 190 | ret.replace('\n', ""); |
180 | return ret; | 191 | return ret; |
181 | #else | 192 | #else |
182 | 193 | ||
183 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 194 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
184 | QCString tmp(" " + domDoc->toCString()); | 195 | QCString tmp(" " + domDoc->toCString()); |
185 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 196 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
197 | qDebug(tmp); | ||
186 | cout << tmp << endl; | 198 | cout << tmp << endl; |
187 | printDebug("<END Serializer::getXml() dump>"); | 199 | printDebug("<END Serializer::getXml() dump>"); |
188 | #endif // DEBUG | 200 | #endif // DEBUG |
189 | 201 | ||
190 | QCString ret(domDoc->toCString()); | 202 | QCString ret(domDoc->toCString()); |
191 | ret.replace(QRegExp("\n"), ""); | 203 | ret.replace(QRegExp("\n"), ""); |
192 | return ret; | 204 | return ret; |
193 | 205 | ||
194 | #endif | 206 | #endif |
195 | } | 207 | } |
196 | 208 | ||
197 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) | 209 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) |
198 | { | 210 | { |
199 | PWM_ASSERT(domDoc); | 211 | PWM_ASSERT(domDoc); |
200 | QDomElement root(genNewRoot()); | 212 | QDomElement root(genNewRoot()); |
201 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 213 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
202 | root.appendChild(catNode); | 214 | root.appendChild(catNode); |
203 | if (!addCategories(&catNode, dta)) | 215 | if (!addCategories(&catNode, dta)) |
204 | return false; | 216 | return false; |
205 | return true; | 217 | return true; |
206 | } | 218 | } |
207 | 219 | ||
208 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | 220 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) |
209 | { | 221 | { |
210 | PWM_ASSERT(domDoc); | 222 | PWM_ASSERT(domDoc); |
211 | PWM_ASSERT(dta); | 223 | PWM_ASSERT(dta); |
212 | QDomElement root(domDoc->documentElement()); | 224 | QDomElement root(domDoc->documentElement()); |
213 | QDomNode n; | 225 | QDomNode n; |
214 | 226 | ||
215 | dta->clear(); | 227 | dta->clear(); |
216 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 228 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
217 | // find <categories> ... </categories> | 229 | // find <categories> ... </categories> |
218 | // <c> ... </c> | 230 | // <c> ... </c> |
219 | if (n.nodeName() == CAT_ROOT_NEW || | 231 | if (n.nodeName() == CAT_ROOT_NEW || |
220 | n.nodeName() == CAT_ROOT_OLD) { | 232 | n.nodeName() == CAT_ROOT_OLD) { |
221 | if (!readCategories(n, dta)) { | 233 | if (!readCategories(n, dta)) { |
222 | return false; | 234 | return false; |
223 | } | 235 | } |
224 | 236 | ||
225 | /* NOTE: We can stop processing here, as we | 237 | /* NOTE: We can stop processing here, as we |
226 | * don't have more nodes in root, yet. | 238 | * don't have more nodes in root, yet. |
227 | */ | 239 | */ |
228 | return true; | 240 | return true; |
229 | } | 241 | } |
230 | } | 242 | } |
231 | return false; | 243 | return false; |
232 | } | 244 | } |
233 | 245 | ||
234 | bool Serializer::readCategories(const QDomNode &n, | 246 | bool Serializer::readCategories(const QDomNode &n, |
235 | vector<PwMCategoryItem> *dta) | 247 | vector<PwMCategoryItem> *dta) |
236 | { | 248 | { |
237 | QDomNodeList nl(n.childNodes()); | 249 | QDomNodeList nl(n.childNodes()); |
238 | QDomNode cur; | 250 | QDomNode cur; |
239 | QString name; | 251 | QString name; |
240 | unsigned int numCat = nl.count(), i; | 252 | unsigned int numCat = nl.count(), i; |
241 | PwMCategoryItem curCat; | 253 | PwMCategoryItem curCat; |
242 | vector<PwMDataItem> curEntr; | 254 | vector<PwMDataItem> curEntr; |
243 | 255 | ||
244 | if (!numCat) { | 256 | if (!numCat) { |
245 | printDebug("Serializer::readCategories(): empty"); | 257 | printDebug("Serializer::readCategories(): empty"); |
246 | return false; | 258 | return false; |
247 | } | 259 | } |
248 | for (i = 0; i < numCat; ++i) { | 260 | for (i = 0; i < numCat; ++i) { |
249 | cur = nl.item(i); | 261 | cur = nl.item(i); |
250 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 262 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
251 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 263 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
252 | name = cur.toElement().attribute(CAT_NAME_NEW); | 264 | name = cur.toElement().attribute(CAT_NAME_NEW); |
253 | if (name == QString::null) | 265 | if (name == QString::null) |
254 | name = cur.toElement().attribute(CAT_NAME_OLD); | 266 | name = cur.toElement().attribute(CAT_NAME_OLD); |
255 | PWM_ASSERT(name != QString::null); | 267 | PWM_ASSERT(name != QString::null); |
256 | PWM_ASSERT(name != ""); | 268 | PWM_ASSERT(name != ""); |
257 | curCat.clear(); | 269 | curCat.clear(); |
258 | curCat.name = name.latin1(); | 270 | curCat.name = name.latin1(); |
259 | if (!readEntries(cur, &curEntr)) { | 271 | if (!readEntries(cur, &curEntr)) { |
260 | dta->clear(); | 272 | dta->clear(); |
261 | return false; | 273 | return false; |
262 | } | 274 | } |
263 | curCat.d = curEntr; | 275 | curCat.d = curEntr; |
264 | dta->push_back(curCat); | 276 | dta->push_back(curCat); |
265 | } else { | 277 | } else { |
266 | printDebug("Serializer::readCategories(): uh? not a category?"); | 278 | printDebug("Serializer::readCategories(): uh? not a category?"); |
267 | } | 279 | } |
268 | } | 280 | } |
269 | return true; | 281 | return true; |
270 | } | 282 | } |
271 | 283 | ||
272 | bool Serializer::readEntries(const QDomNode &n, | 284 | bool Serializer::readEntries(const QDomNode &n, |
273 | vector<PwMDataItem> *dta) | 285 | vector<PwMDataItem> *dta) |
274 | { | 286 | { |
275 | QDomNodeList nl(n.childNodes()); | 287 | QDomNodeList nl(n.childNodes()); |
276 | QDomNode cur; | 288 | QDomNode cur; |
277 | unsigned int numEntr = nl.count(), i; | 289 | unsigned int numEntr = nl.count(), i; |
278 | PwMDataItem curEntr; | 290 | PwMDataItem curEntr; |
279 | 291 | ||
280 | dta->clear(); | 292 | dta->clear(); |
281 | for (i = 0; i < numEntr; ++i) { | 293 | for (i = 0; i < numEntr; ++i) { |
282 | cur = nl.item(i); | 294 | cur = nl.item(i); |
283 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 295 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
284 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 296 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
285 | if (!extractEntry(cur, &curEntr)) { | 297 | if (!extractEntry(cur, &curEntr)) { |
286 | return false; | 298 | return false; |
287 | } | 299 | } |
288 | dta->push_back(curEntr); | 300 | dta->push_back(curEntr); |
289 | } else { | 301 | } else { |
290 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 302 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
291 | } | 303 | } |
292 | } | 304 | } |
293 | return true; | 305 | return true; |
294 | } | 306 | } |
295 | 307 | ||
296 | bool Serializer::extractEntry(const QDomNode &n, | 308 | bool Serializer::extractEntry(const QDomNode &n, |
297 | PwMDataItem *dta) | 309 | PwMDataItem *dta) |
298 | { | 310 | { |
299 | QDomNodeList nl(n.childNodes()); | 311 | QDomNodeList nl(n.childNodes()); |
300 | QDomNode cur, cdata; | 312 | QDomNode cur, cdata; |
301 | unsigned int cnt = nl.count(), i; | 313 | unsigned int cnt = nl.count(), i; |
302 | QString name, text; | 314 | QString name, text; |
303 | 315 | ||
304 | if (!cnt) { | 316 | if (!cnt) { |
305 | printDebug("Serializer::extractEntry(): empty"); | 317 | printDebug("Serializer::extractEntry(): empty"); |
306 | return false; | 318 | return false; |
307 | } | 319 | } |
308 | dta->clear(); | 320 | dta->clear(); |
309 | for (i = 0; i < cnt; ++i) { | 321 | for (i = 0; i < cnt; ++i) { |
310 | cur = nl.item(i); | 322 | cur = nl.item(i); |
311 | name = cur.nodeName(); | 323 | name = cur.nodeName(); |
312 | cdata = cur.firstChild(); | 324 | cdata = cur.firstChild(); |
313 | if (unlikely(cdata.isCDATASection())) { | 325 | if (unlikely(cdata.isCDATASection())) { |
314 | text = cdata.toCDATASection().data(); | 326 | text = cdata.toCDATASection().data(); |
315 | } else if (likely(cur.isElement())) { | 327 | } else if (likely(cur.isElement())) { |
316 | text = cur.toElement().text(); | 328 | text = cur.toElement().text(); |
317 | } else { | 329 | } else { |
318 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
319 | return false; | 331 | return false; |
320 | } | 332 | } |
321 | if (text == " ") | 333 | if (text == " ") |
322 | text = ""; // for backward compatibility. | 334 | text = ""; // for backward compatibility. |
323 | if (name == ENTRY_DESC_NEW || | 335 | if (name == ENTRY_DESC_NEW || |
324 | name == ENTRY_DESC_OLD) { | 336 | name == ENTRY_DESC_OLD) { |
325 | dta->desc = unescapeEntryData(text).latin1(); | 337 | dta->desc = unescapeEntryData(text).latin1(); |
326 | } else if (name == ENTRY_NAME_NEW || | 338 | } else if (name == ENTRY_NAME_NEW || |
327 | name == ENTRY_NAME_OLD) { | 339 | name == ENTRY_NAME_OLD) { |
328 | dta->name = unescapeEntryData(text).latin1(); | 340 | dta->name = unescapeEntryData(text).latin1(); |
329 | } else if (name == ENTRY_PW_NEW || | 341 | } else if (name == ENTRY_PW_NEW || |
330 | name == ENTRY_PW_OLD) { | 342 | name == ENTRY_PW_OLD) { |
331 | dta->pw = unescapeEntryData(text).latin1(); | 343 | dta->pw = unescapeEntryData(text).latin1(); |
332 | } else if (name == ENTRY_COMMENT_NEW || | 344 | } else if (name == ENTRY_COMMENT_NEW || |
333 | name == ENTRY_COMMENT_OLD) { | 345 | name == ENTRY_COMMENT_OLD) { |
334 | dta->comment = unescapeEntryData(text).latin1(); | 346 | dta->comment = unescapeEntryData(text).latin1(); |
335 | } else if (name == ENTRY_URL_NEW || | 347 | } else if (name == ENTRY_URL_NEW || |
336 | name == ENTRY_URL_OLD) { | 348 | name == ENTRY_URL_OLD) { |
337 | dta->url = unescapeEntryData(text).latin1(); | 349 | dta->url = unescapeEntryData(text).latin1(); |
338 | } else if (name == ENTRY_LAUNCHER_NEW || | 350 | } else if (name == ENTRY_LAUNCHER_NEW || |
339 | name == ENTRY_LAUNCHER_OLD) { | 351 | name == ENTRY_LAUNCHER_OLD) { |
340 | dta->launcher = unescapeEntryData(text).latin1(); | 352 | dta->launcher = unescapeEntryData(text).latin1(); |
341 | } else if (name == ENTRY_LVP_NEW || | 353 | } else if (name == ENTRY_LVP_NEW || |
342 | name == ENTRY_LVP_OLD) { | 354 | name == ENTRY_LVP_OLD) { |
343 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 355 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
344 | } else if (name == ENTRY_BIN_NEW) { | 356 | } else if (name == ENTRY_BIN_NEW) { |
345 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
346 | if (text == "0") { | 358 | if (text == "0") { |
347 | dta->binary = false; | 359 | dta->binary = false; |
348 | } else { | 360 | } else { |
349 | dta->binary = true; | 361 | dta->binary = true; |
350 | } | 362 | } |
351 | } else if (name == ENTRY_META_NEW) { | 363 | } else if (name == ENTRY_META_NEW) { |
352 | // ENTRY_META_NEW == ENTRY_META_OLD | 364 | // ENTRY_META_NEW == ENTRY_META_OLD |
353 | if (!extractMeta(cur, &dta->meta)) | 365 | if (!extractMeta(cur, &dta->meta)) |
354 | return false; | 366 | return false; |
355 | } else { | 367 | } else { |
356 | printDebug(string("Serializer::extractEntry(): invalid: ") | 368 | printDebug(string("Serializer::extractEntry(): invalid: ") |
357 | + name.latin1()); | 369 | + name.latin1()); |
358 | } | 370 | } |
359 | } | 371 | } |
360 | dta->lockStat = defaultLockStat; | 372 | dta->lockStat = defaultLockStat; |
361 | return true; | 373 | return true; |
362 | } | 374 | } |
363 | 375 | ||
364 | bool Serializer::extractMeta(const QDomNode &n, | 376 | bool Serializer::extractMeta(const QDomNode &n, |
365 | PwMMetaData *dta) | 377 | PwMMetaData *dta) |
366 | { | 378 | { |
367 | QDomNode cur(n.firstChild()); | 379 | QDomNode cur(n.firstChild()); |
368 | QString name, val; | 380 | QString name, val; |
369 | while (!cur.isNull()) { | 381 | while (!cur.isNull()) { |
370 | name = cur.nodeName(); | 382 | name = cur.nodeName(); |
371 | val = cur.toElement().text(); | 383 | val = cur.toElement().text(); |
372 | if (val == "") { | 384 | if (val == "") { |
373 | cur = cur.nextSibling(); | 385 | cur = cur.nextSibling(); |
374 | continue; | 386 | continue; |
375 | } | 387 | } |
376 | #ifndef PWM_EMBEDDED | 388 | #ifndef PWM_EMBEDDED |
377 | if (name == META_CREATE_DATE) { | 389 | if (name == META_CREATE_DATE) { |
378 | dta->create = QDateTime::fromString(val, Qt::ISODate); | 390 | dta->create = QDateTime::fromString(val, Qt::ISODate); |
379 | } else if (name == META_VALID_DATE) { | 391 | } else if (name == META_VALID_DATE) { |
380 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | 392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); |
381 | } else if (name == META_EXPIRE_DATE) { | 393 | } else if (name == META_EXPIRE_DATE) { |
382 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | 394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); |
383 | } else if (name == META_UPDATE_DATE) { | 395 | } else if (name == META_UPDATE_DATE) { |
384 | dta->update = QDateTime::fromString(val, Qt::ISODate); | 396 | dta->update = QDateTime::fromString(val, Qt::ISODate); |
385 | } else if (name == META_UPDATE_INT) { | 397 | } else if (name == META_UPDATE_INT) { |
386 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 398 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
387 | } else if (name == META_UNIQUEID) { | 399 | } else if (name == META_UNIQUEID) { |
388 | dta->uniqueid = unescapeEntryData(val).latin1(); | 400 | dta->uniqueid = unescapeEntryData(val).latin1(); |
389 | } else { | 401 | } else { |
390 | printDebug(string("extractMeta(): invalid: ") | 402 | printDebug(string("extractMeta(): invalid: ") |
391 | + name.latin1()); | 403 | + name.latin1()); |
392 | } | 404 | } |
393 | #else | 405 | #else |
394 | 406 | ||
395 | QDateTime m_dt; | 407 | QDateTime m_dt; |
396 | 408 | ||
397 | if ((name == META_CREATE_DATE) || | 409 | if ((name == META_CREATE_DATE) || |
398 | (name == META_VALID_DATE) || | 410 | (name == META_VALID_DATE) || |
399 | (name == META_EXPIRE_DATE) || | 411 | (name == META_EXPIRE_DATE) || |
400 | (name == META_UPDATE_DATE)) | 412 | (name == META_UPDATE_DATE)) |
401 | { | 413 | { |
402 | int pos = val.find("T"); | 414 | int pos = val.find("T"); |
403 | QString date = val.left(pos); | 415 | QString date = val.left(pos); |
404 | QString time = val.mid(pos+1); | 416 | QString time = val.mid(pos+1); |
405 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); | 417 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); |
406 | bool ok1, ok2; | 418 | bool ok1, ok2; |
407 | 419 | ||
408 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); | 420 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); |
409 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); | 421 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); |
410 | if ((ok1 == false) || (ok2 == false)) | 422 | if ((ok1 == false) || (ok2 == false)) |
411 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 423 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
412 | m_dt.setDate(m_date); | 424 | m_dt.setDate(m_date); |
413 | m_dt.setTime(m_time); | 425 | m_dt.setTime(m_time); |
414 | } | 426 | } |
415 | 427 | ||
416 | 428 | ||
417 | if (name == META_CREATE_DATE) { | 429 | if (name == META_CREATE_DATE) { |
418 | dta->create = m_dt; | 430 | dta->create = m_dt; |
419 | } else if (name == META_VALID_DATE) { | 431 | } else if (name == META_VALID_DATE) { |
420 | dta->valid = m_dt; | 432 | dta->valid = m_dt; |
421 | } else if (name == META_EXPIRE_DATE) { | 433 | } else if (name == META_EXPIRE_DATE) { |
422 | dta->expire = m_dt; | 434 | dta->expire = m_dt; |
423 | } else if (name == META_UPDATE_DATE) { | 435 | } else if (name == META_UPDATE_DATE) { |
424 | dta->update = m_dt; | 436 | dta->update = m_dt; |
425 | } else if (name == META_UPDATE_INT) { | 437 | } else if (name == META_UPDATE_INT) { |
426 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 438 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
427 | } else if (name == META_UNIQUEID) { | 439 | } else if (name == META_UNIQUEID) { |
428 | dta->uniqueid = unescapeEntryData(val).latin1(); | 440 | dta->uniqueid = unescapeEntryData(val).latin1(); |
429 | } else { | 441 | } else { |
430 | printDebug(string("extractMeta(): invalid: ") | 442 | printDebug(string("extractMeta(): invalid: ") |
431 | + name.latin1()); | 443 | + name.latin1()); |
432 | } | 444 | } |
433 | #endif | 445 | #endif |
434 | cur = cur.nextSibling(); | 446 | cur = cur.nextSibling(); |
435 | } | 447 | } |
436 | return true; | 448 | return true; |
437 | } | 449 | } |
438 | 450 | ||
439 | bool Serializer::checkValid() | 451 | bool Serializer::checkValid() |
440 | { | 452 | { |
441 | PWM_ASSERT(domDoc); | 453 | PWM_ASSERT(domDoc); |
442 | QDomElement root(domDoc->documentElement()); | 454 | QDomElement root(domDoc->documentElement()); |
443 | if (root.nodeName() != ROOT_MAGIC_NEW && | 455 | if (root.nodeName() != ROOT_MAGIC_NEW && |
444 | root.nodeName() != ROOT_MAGIC_OLD) { | 456 | root.nodeName() != ROOT_MAGIC_OLD) { |
445 | printDebug("Serializer: wrong magic"); | 457 | printDebug("Serializer: wrong magic"); |
446 | return false; | 458 | return false; |
447 | } | 459 | } |
448 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 460 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
449 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 461 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
450 | printDebug("Serializer: wrong version"); | 462 | printDebug("Serializer: wrong version"); |
451 | return false; | 463 | return false; |
452 | } | 464 | } |
453 | return true; | 465 | return true; |
454 | } | 466 | } |
455 | 467 | ||
456 | QDomElement Serializer::genNewRoot() | 468 | QDomElement Serializer::genNewRoot() |
457 | { | 469 | { |
458 | PWM_ASSERT(domDoc); | 470 | PWM_ASSERT(domDoc); |
459 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 471 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
460 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 472 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
461 | domDoc->appendChild(root); | 473 | domDoc->appendChild(root); |
462 | return root; | 474 | return root; |
463 | } | 475 | } |
464 | 476 | ||
465 | bool Serializer::addCategories(QDomElement *e, | 477 | bool Serializer::addCategories(QDomElement *e, |
466 | const vector<PwMCategoryItem> &dta) | 478 | const vector<PwMCategoryItem> &dta) |
467 | { | 479 | { |
468 | unsigned int numCat = dta.size(), i; | 480 | unsigned int numCat = dta.size(), i; |
469 | QString curId, curName; | 481 | QString curId, curName; |
470 | QDomElement curCat; | 482 | QDomElement curCat; |
471 | 483 | ||
472 | for (i = 0; i < numCat; ++i) { | 484 | for (i = 0; i < numCat; ++i) { |
473 | curId = CAT_PREFIX_WR; | 485 | curId = CAT_PREFIX_WR; |
474 | curId += tostr(i).c_str(); | 486 | curId += tostr(i).c_str(); |
475 | curName = dta[i].name.c_str(); | 487 | curName = dta[i].name.c_str(); |
476 | curCat = domDoc->createElement(curId); | 488 | curCat = domDoc->createElement(curId); |
477 | curCat.setAttribute(CAT_NAME_WR, curName); | 489 | curCat.setAttribute(CAT_NAME_WR, curName); |
478 | if (!addEntries(&curCat, dta[i].d)) { | 490 | if (!addEntries(&curCat, dta[i].d)) { |
479 | return false; | 491 | return false; |
480 | } | 492 | } |
481 | e->appendChild(curCat); | 493 | e->appendChild(curCat); |
482 | } | 494 | } |
483 | return true; | 495 | return true; |
484 | } | 496 | } |
485 | 497 | ||
486 | bool Serializer::addEntries(QDomElement *e, | 498 | bool Serializer::addEntries(QDomElement *e, |
487 | const vector<PwMDataItem> &dta) | 499 | const vector<PwMDataItem> &dta) |
488 | { | 500 | { |
489 | unsigned int numEntr = dta.size(), i; | 501 | unsigned int numEntr = dta.size(), i; |
490 | QString curId; | 502 | QString curId; |
491 | QDomElement curEntr; | 503 | QDomElement curEntr; |
492 | 504 | ||
493 | for (i = 0; i < numEntr; ++i) { | 505 | for (i = 0; i < numEntr; ++i) { |
494 | curId = ENTRY_PREFIX_WR; | 506 | curId = ENTRY_PREFIX_WR; |
495 | curId += tostr(i).c_str(); | 507 | curId += tostr(i).c_str(); |
496 | curEntr = domDoc->createElement(curId); | 508 | curEntr = domDoc->createElement(curId); |
497 | if (!writeEntry(&curEntr, dta[i])) { | 509 | if (!writeEntry(&curEntr, dta[i])) { |
498 | return false; | 510 | return false; |
499 | } | 511 | } |
500 | e->appendChild(curEntr); | 512 | e->appendChild(curEntr); |
501 | } | 513 | } |
502 | return true; | 514 | return true; |
503 | } | 515 | } |
504 | 516 | ||
505 | bool Serializer::writeEntry(QDomElement *e, | 517 | bool Serializer::writeEntry(QDomElement *e, |
506 | const PwMDataItem &_dta) | 518 | const PwMDataItem &_dta) |
507 | { | 519 | { |
508 | #if WRITE_CDATA_SEC != 0 | 520 | #if WRITE_CDATA_SEC != 0 |
509 | # define new_text(x)domDoc->createCDATASection(x) | 521 | # define new_text(x)domDoc->createCDATASection(x) |
510 | QDomCDATASection curText; | 522 | QDomCDATASection curText; |
511 | #else | 523 | #else |
512 | # define new_text(x)domDoc->createTextNode(x) | 524 | # define new_text(x)domDoc->createTextNode(x) |
513 | QDomText curText; | 525 | QDomText curText; |
514 | #endif | 526 | #endif |
515 | 527 | ||
516 | QDomText plainText; | 528 | QDomText plainText; |
517 | QDomElement tag; | 529 | QDomElement tag; |
518 | 530 | ||
519 | // begin -- This is for compatibility with the old serializer | 531 | // begin -- This is for compatibility with the old serializer |
520 | PwMDataItem dta = _dta; | 532 | PwMDataItem dta = _dta; |
521 | if (!dta.desc.size()) | 533 | if (!dta.desc.size()) |
522 | dta.desc = " "; | 534 | dta.desc = " "; |
523 | if (!dta.name.size()) | 535 | if (!dta.name.size()) |
524 | dta.name = " "; | 536 | dta.name = " "; |
525 | if (!dta.pw.size()) | 537 | if (!dta.pw.size()) |
526 | dta.pw = " "; | 538 | dta.pw = " "; |
527 | if (!dta.comment.size()) | 539 | if (!dta.comment.size()) |
528 | dta.comment = " "; | 540 | dta.comment = " "; |
529 | if (!dta.url.size()) | 541 | if (!dta.url.size()) |
530 | dta.url = " "; | 542 | dta.url = " "; |
531 | if (!dta.launcher.size()) | 543 | if (!dta.launcher.size()) |
532 | dta.launcher = " "; | 544 | dta.launcher = " "; |
533 | // end -- This is for compatibility with the old serializer | 545 | // end -- This is for compatibility with the old serializer |
534 | 546 | ||
535 | tag = domDoc->createElement(ENTRY_DESC_WR); | 547 | tag = domDoc->createElement(ENTRY_DESC_WR); |
536 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 548 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
537 | tag.appendChild(curText); | 549 | tag.appendChild(curText); |
538 | e->appendChild(tag); | 550 | e->appendChild(tag); |
539 | 551 | ||
540 | tag = domDoc->createElement(ENTRY_NAME_WR); | 552 | tag = domDoc->createElement(ENTRY_NAME_WR); |
541 | curText = new_text(escapeEntryData(dta.name.c_str())); | 553 | curText = new_text(escapeEntryData(dta.name.c_str())); |
542 | tag.appendChild(curText); | 554 | tag.appendChild(curText); |
543 | e->appendChild(tag); | 555 | e->appendChild(tag); |
544 | 556 | ||
545 | tag = domDoc->createElement(ENTRY_PW_WR); | 557 | tag = domDoc->createElement(ENTRY_PW_WR); |
546 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 558 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
547 | tag.appendChild(curText); | 559 | tag.appendChild(curText); |
548 | e->appendChild(tag); | 560 | e->appendChild(tag); |
549 | 561 | ||
550 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 562 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
551 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 563 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
552 | tag.appendChild(curText); | 564 | tag.appendChild(curText); |
553 | e->appendChild(tag); | 565 | e->appendChild(tag); |
554 | 566 | ||
555 | tag = domDoc->createElement(ENTRY_URL_WR); | 567 | tag = domDoc->createElement(ENTRY_URL_WR); |
556 | curText = new_text(escapeEntryData(dta.url.c_str())); | 568 | curText = new_text(escapeEntryData(dta.url.c_str())); |
557 | tag.appendChild(curText); | 569 | tag.appendChild(curText); |
558 | e->appendChild(tag); | 570 | e->appendChild(tag); |
559 | 571 | ||
560 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 572 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
561 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 573 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
562 | tag.appendChild(curText); | 574 | tag.appendChild(curText); |
563 | e->appendChild(tag); | 575 | e->appendChild(tag); |
564 | 576 | ||
565 | tag = domDoc->createElement(ENTRY_LVP_WR); | 577 | tag = domDoc->createElement(ENTRY_LVP_WR); |
566 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 578 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
567 | tag.appendChild(plainText); | 579 | tag.appendChild(plainText); |
568 | e->appendChild(tag); | 580 | e->appendChild(tag); |
569 | 581 | ||