summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--bin/kdepim/pwmanager/pwmanagerFAQ.txt38
-rw-r--r--pwmanager/pwmanager/pwm.cpp57
-rw-r--r--pwmanager/pwmanager/pwm.h8
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp85
-rw-r--r--pwmanager/pwmanager/pwmdoc.h39
-rw-r--r--pwmanager/pwmanager/pwmview.cpp92
-rw-r--r--pwmanager/pwmanager/pwmview.h25
-rw-r--r--pwmanager/pwmanager/serializer.cpp126
8 files changed, 321 insertions, 149 deletions
diff --git a/bin/kdepim/pwmanager/pwmanagerFAQ.txt b/bin/kdepim/pwmanager/pwmanagerFAQ.txt
index 7bfe368..a28f07b 100644
--- a/bin/kdepim/pwmanager/pwmanagerFAQ.txt
+++ b/bin/kdepim/pwmanager/pwmanagerFAQ.txt
@@ -1,41 +1,71 @@
1Q: 1Q:
2What is PWM/Pi 2What is PWM/Pi?
3Q: 3Q:
4For which platform is PWM/Pi available? 4For which platform is PWM/Pi available?
5Q: 5Q:
6Can I exchange the password files from PWM/Pi and PwManager 6Can I exchange the password files from PWM/Pi and PwManager?
7Q:
8Does Export/Import keep sync information in place?
9Q:
10Can PWM/Pi sync categories?
11Q:
12Which crypto, hash and compress algorithm is applied to the remote file
13while syncing?
14
7 15
8************************************************************************* 16*************************************************************************
9Q: 17Q:
10What is PWM/Pi 18What is PWM/Pi
11A: 19A:
12PWM/Pi is the platform-independend version of PwManager 1.0.1, written by 20PWM/Pi is the platform-independend version of PwManager 1.0.1, written by
13Michael Buesch and the PwManager Team (http://passwordmanager.sourceforge.net) 21Michael Buesch and the PwManager Team (http://passwordmanager.sourceforge.net)
14************************************************************************* 22*************************************************************************
15Q: 23Q:
16For which platform is PWM/Pi available? 24For which platform is PWM/Pi available?
17A: 25A:
18PWM/Pi is the platform-independend version of PWManager and it 26PWM/Pi is the platform-independend version of PWManager and it
19includes a replacement for the KDE libraries called microkde. 27includes a replacement for the KDE libraries called microkde.
20It can be compiled to any platform, where Qt is available. 28It can be compiled to any platform, where Qt is available.
21The source code compiles without modifications on Windows, 29The source code compiles without modifications on Windows,
22Linux Desktop and Sharp Zaurus PDA. Precompiled versions are available 30Linux Desktop and Sharp Zaurus PDA. Precompiled versions are available
23on www.pi-sync.net for Windows and Sharp Zaurus PDA. 31on www.pi-sync.net for Windows and Sharp Zaurus PDA.
24Latest versions and the source code cvs can be found at: 32Latest versions and the source code cvs can be found at:
25http://sourceforge.net/projects/kdepimpi/ 33http://sourceforge.net/projects/kdepimpi/
26************************************************************************* 34*************************************************************************
27Q: 35Q:
28Can I exchange the password files from PWM/Pi and PwManager 36Can I exchange the password files from PWM/Pi and PwManager
29A: 37A:
30The password files of PWM/Pi can not be exchanged with all versions up 38The password files of PWM/Pi can not be exchanged with all versions up
31to 1.0.1 of PwManager. 39to 1.0.1 of PwManager.
32However, Michael will integrate our changes into a PwManager release 40However, Michael will integrate our changes into a PwManager release
331.1, and the password files of that release will then be interchangable 411.1, and the password files of that release will then be interchangable
34with PWM/Pi 42with PWM/Pi
35 43*************************************************************************
36 44Q:
45Does Export/Import keep sync information in place
46A:
47Exporting data from PwManager removes all sync related information
48(Meta information) from the data. Because of that, a subsequent import
49results in "new" entries that will be handled as new entries when
50syncing them with an existing password file.
51*************************************************************************
52Q:
53Can PWM/Pi sync categories?
54A:
55No. PWM/Pi does not sync categories. It syncs all pw entries of the file
56without checking for the entries categories.
57A sync operation does not move modified entries from one category to another.
58Only if the sync operation has to create a new pw entry, it checks for the
59existance of the category and creates it if not existent.
60*************************************************************************
61Q:
62Which crypto, hash and compress algorithm is applied to the remote file
63while syncing?
64A: The sync operation applies the local crypt, hash and compress algorithm
65to both, the local and remote copy of the passwordfile and with thus
66overwrites the settings of the remote PwManager application.
37 67
38 68
39 69
40 70
41 71
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index 014e809..57b4432 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -87,121 +87,122 @@ enum {
87 BUTTON_POPUP_MANAGE_DEL, 87 BUTTON_POPUP_MANAGE_DEL,
88 BUTTON_POPUP_MANAGE_CHANGEMP 88 BUTTON_POPUP_MANAGE_CHANGEMP
89}; 89};
90// Button IDs for chipcard popup menu 90// Button IDs for chipcard popup menu
91enum { 91enum {
92#ifdef CONFIG_KEYCARD 92#ifdef CONFIG_KEYCARD
93 BUTTON_POPUP_CHIPCARD_GENNEW = 0, 93 BUTTON_POPUP_CHIPCARD_GENNEW = 0,
94 BUTTON_POPUP_CHIPCARD_DEL, 94 BUTTON_POPUP_CHIPCARD_DEL,
95 BUTTON_POPUP_CHIPCARD_READID, 95 BUTTON_POPUP_CHIPCARD_READID,
96 BUTTON_POPUP_CHIPCARD_SAVEBACKUP, 96 BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
97 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP 97 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
98#else // CONFIG_KEYCARD 98#else // CONFIG_KEYCARD
99 BUTTON_POPUP_CHIPCARD_NO = 0 99 BUTTON_POPUP_CHIPCARD_NO = 0
100#endif // CONFIG_KEYCARD 100#endif // CONFIG_KEYCARD
101}; 101};
102// Button IDs for "view" popup menu 102// Button IDs for "view" popup menu
103enum { 103enum {
104 BUTTON_POPUP_VIEW_FIND = 0, 104 BUTTON_POPUP_VIEW_FIND = 0,
105 BUTTON_POPUP_VIEW_LOCK, 105 BUTTON_POPUP_VIEW_LOCK,
106 BUTTON_POPUP_VIEW_DEEPLOCK, 106 BUTTON_POPUP_VIEW_DEEPLOCK,
107 BUTTON_POPUP_VIEW_UNLOCK 107 BUTTON_POPUP_VIEW_UNLOCK
108}; 108};
109// Button IDs for "options" popup menu 109// Button IDs for "options" popup menu
110enum { 110enum {
111 BUTTON_POPUP_OPTIONS_CONFIG = 0 111 BUTTON_POPUP_OPTIONS_CONFIG = 0
112}; 112};
113// Button IDs for "export" popup menu (in "file" popup menu) 113// Button IDs for "export" popup menu (in "file" popup menu)
114enum { 114enum {
115 BUTTON_POPUP_EXPORT_TEXT = 0, 115 BUTTON_POPUP_EXPORT_TEXT = 0,
116 BUTTON_POPUP_EXPORT_GPASMAN 116 BUTTON_POPUP_EXPORT_GPASMAN
117#ifdef CONFIG_KWALLETIF 117#ifdef CONFIG_KWALLETIF
118 ,BUTTON_POPUP_EXPORT_KWALLET 118 ,BUTTON_POPUP_EXPORT_KWALLET
119#endif 119#endif
120}; 120};
121// Button IDs for "import" popup menu (in "file" popup menu) 121// Button IDs for "import" popup menu (in "file" popup menu)
122enum { 122enum {
123 BUTTON_POPUP_IMPORT_TEXT = 0, 123 BUTTON_POPUP_IMPORT_TEXT = 0,
124 BUTTON_POPUP_IMPORT_GPASMAN 124 BUTTON_POPUP_IMPORT_GPASMAN
125#ifdef CONFIG_KWALLETIF 125#ifdef CONFIG_KWALLETIF
126 ,BUTTON_POPUP_IMPORT_KWALLET 126 ,BUTTON_POPUP_IMPORT_KWALLET
127#endif 127#endif
128}; 128};
129 129
130#ifdef PWM_EMBEDDED 130#ifdef PWM_EMBEDDED
131// Button IDs for "help" popup menu 131// Button IDs for "help" popup menu
132enum { 132enum {
133 BUTTON_POPUP_HELP_LICENSE = 0, 133 BUTTON_POPUP_HELP_LICENSE = 0,
134 BUTTON_POPUP_HELP_FAQ, 134 BUTTON_POPUP_HELP_FAQ,
135 BUTTON_POPUP_HELP_ABOUT 135 BUTTON_POPUP_HELP_ABOUT,
136 BUTTON_POPUP_HELP_SYNC
136}; 137};
137#endif 138#endif
138 139
139// Button IDs for toolbar 140// Button IDs for toolbar
140enum { 141enum {
141 BUTTON_TOOL_NEW = 0, 142 BUTTON_TOOL_NEW = 0,
142 BUTTON_TOOL_OPEN, 143 BUTTON_TOOL_OPEN,
143 BUTTON_TOOL_SAVE, 144 BUTTON_TOOL_SAVE,
144 BUTTON_TOOL_SAVEAS, 145 BUTTON_TOOL_SAVEAS,
145 BUTTON_TOOL_PRINT, 146 BUTTON_TOOL_PRINT,
146 BUTTON_TOOL_ADD, 147 BUTTON_TOOL_ADD,
147 BUTTON_TOOL_EDIT, 148 BUTTON_TOOL_EDIT,
148 BUTTON_TOOL_DEL, 149 BUTTON_TOOL_DEL,
149 BUTTON_TOOL_FIND, 150 BUTTON_TOOL_FIND,
150 BUTTON_TOOL_LOCK, 151 BUTTON_TOOL_LOCK,
151 BUTTON_TOOL_DEEPLOCK, 152 BUTTON_TOOL_DEEPLOCK,
152 BUTTON_TOOL_UNLOCK 153 BUTTON_TOOL_UNLOCK
153}; 154};
154 155
155 156
156PwM::PwM(PwMInit *_init, PwMDoc *doc, 157PwM::PwM(PwMInit *_init, PwMDoc *doc,
157 bool virginity, 158 bool virginity,
158 QWidget *parent, const char *name) 159 QWidget *parent, const char *name)
159 : KMainWindow(parent, name) 160 : KMainWindow(parent, "HALLO")
160 , forceQuit (false) 161 , forceQuit (false)
161 , forceMinimizeToTray (false) 162 , forceMinimizeToTray (false)
162{ 163{
163 init = _init; 164 init = _init;
164 connect(doc, SIGNAL(docClosed(PwMDoc *)), 165 connect(doc, SIGNAL(docClosed(PwMDoc *)),
165 this, SLOT(docClosed(PwMDoc *))); 166 this, SLOT(docClosed(PwMDoc *)));
166 initMenubar(); 167 initMenubar();
167 initToolbar(); 168 initToolbar();
168 initMetrics(); 169 initMetrics();
169 setVirgin(virginity); 170 setVirgin(virginity);
170 setFocusPolicy(QWidget::WheelFocus); 171 setFocusPolicy(QWidget::WheelFocus);
171#ifndef PWM_EMBEDDED 172#ifndef PWM_EMBEDDED
172 statusBar()->show(); 173 statusBar()->show();
173#endif 174#endif
174 view = makeNewListView(doc); 175 view = makeNewListView(doc);
175 setCentralWidget(view); 176 setCentralWidget(view);
176 updateCaption(); 177 updateCaption();
177 showStatMsg(i18n("Ready.")); 178 showStatMsg(i18n("Ready."));
178} 179}
179 180
180PwM::~PwM() 181PwM::~PwM()
181{ 182{
182 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), 183 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
183 this, SLOT(docClosed(PwMDoc *))); 184 this, SLOT(docClosed(PwMDoc *)));
184 conf()->confWndMainWndSize(size()); 185 conf()->confWndMainWndSize(size());
185 emit closed(this); 186 emit closed(this);
186 delete view; 187 delete view;
187} 188}
188 189
189void PwM::initMenubar() 190void PwM::initMenubar()
190{ 191{
191 KIconLoader* picons; 192 KIconLoader* picons;
192#ifndef PWM_EMBEDDED 193#ifndef PWM_EMBEDDED
193 KIconLoader icons; 194 KIconLoader icons;
194 picons = &icons; 195 picons = &icons;
195#else 196#else
196 picons = KGlobal::iconLoader(); 197 picons = KGlobal::iconLoader();
197 198
198 199
199 syncPopup = new KPopupMenu(this); 200 syncPopup = new KPopupMenu(this);
200 201
201 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); 202 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup);
202 syncManager->setBlockSave(false); 203 syncManager->setBlockSave(false);
203 204
204 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 205 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
205 syncManager->fillSyncMenu(); 206 syncManager->fillSyncMenu();
206 207
207#endif 208#endif
@@ -313,96 +314,100 @@ void PwM::initMenubar()
313 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), 314 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)),
314 i18n("&Find"), this, 315 i18n("&Find"), this,
315 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); 316 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
316 viewPopup->insertSeparator(); 317 viewPopup->insertSeparator();
317 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), 318 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)),
318 i18n("&Lock all entries"), this, 319 i18n("&Lock all entries"), this,
319 SLOT(lockWnd_slot()), 0, 320 SLOT(lockWnd_slot()), 0,
320 BUTTON_POPUP_VIEW_LOCK); 321 BUTTON_POPUP_VIEW_LOCK);
321 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), 322 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)),
322 i18n("&Deep-lock all entries"), this, 323 i18n("&Deep-lock all entries"), this,
323 SLOT(deepLockWnd_slot()), 0, 324 SLOT(deepLockWnd_slot()), 0,
324 BUTTON_POPUP_VIEW_DEEPLOCK); 325 BUTTON_POPUP_VIEW_DEEPLOCK);
325 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), 326 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)),
326 i18n("&Unlock all entries"), this, 327 i18n("&Unlock all entries"), this,
327 SLOT(unlockWnd_slot()), 0, 328 SLOT(unlockWnd_slot()), 0,
328 BUTTON_POPUP_VIEW_UNLOCK); 329 BUTTON_POPUP_VIEW_UNLOCK);
329 menuBar()->insertItem(i18n("&View"), viewPopup); 330 menuBar()->insertItem(i18n("&View"), viewPopup);
330// "options" popup menu 331// "options" popup menu
331 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), 332 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
332 i18n("&Configure..."), this, 333 i18n("&Configure..."), this,
333 SLOT(config_slot()), 334 SLOT(config_slot()),
334 BUTTON_POPUP_OPTIONS_CONFIG); 335 BUTTON_POPUP_OPTIONS_CONFIG);
335 menuBar()->insertItem(i18n("&Options"), optionsPopup); 336 menuBar()->insertItem(i18n("&Options"), optionsPopup);
336// "help" popup menu 337// "help" popup menu
337#ifndef PWM_EMBEDDED 338#ifndef PWM_EMBEDDED
338 helpPopup = helpMenu(QString::null, false); 339 helpPopup = helpMenu(QString::null, false);
339#else 340#else
340 menuBar()->insertItem(i18n("&Sync"), syncPopup); 341 menuBar()->insertItem(i18n("&Sync"), syncPopup);
341 342
342 343
343 344
344 345
345 346
346 helpPopup = new KPopupMenu(this); 347 helpPopup = new KPopupMenu(this);
347 348
348 349
349 helpPopup->insertItem(i18n("&License"), this, 350 helpPopup->insertItem(i18n("&License"), this,
350 SLOT(showLicense_slot()), 0, 351 SLOT(showLicense_slot()), 0,
351 BUTTON_POPUP_HELP_LICENSE); 352 BUTTON_POPUP_HELP_LICENSE);
352 353
353 helpPopup->insertItem(i18n("&Faq"), this, 354 helpPopup->insertItem(i18n("&Faq"), this,
354 SLOT(faq_slot()), 0, 355 SLOT(faq_slot()), 0,
355 BUTTON_POPUP_HELP_FAQ); 356 BUTTON_POPUP_HELP_FAQ);
356 357
357 helpPopup->insertItem(i18n("&About PwManager"), this, 358 helpPopup->insertItem(i18n("&About PwManager"), this,
358 SLOT(createAboutData_slot()), 0, 359 SLOT(createAboutData_slot()), 0,
359 BUTTON_POPUP_HELP_ABOUT); 360 BUTTON_POPUP_HELP_ABOUT);
360 361
362 helpPopup->insertItem(i18n("&Sync HowTo"), this,
363 SLOT(syncHowTo_slot()), 0,
364 BUTTON_POPUP_HELP_SYNC);
365
361#endif 366#endif
362 menuBar()->insertItem(i18n("&Help"), helpPopup); 367 menuBar()->insertItem(i18n("&Help"), helpPopup);
363 368
364} 369}
365 370
366void PwM::initToolbar() 371void PwM::initToolbar()
367{ 372{
368 KIconLoader* picons; 373 KIconLoader* picons;
369#ifndef PWM_EMBEDDED 374#ifndef PWM_EMBEDDED
370 KIconLoader icons; 375 KIconLoader icons;
371 picons = &icons; 376 picons = &icons;
372#else 377#else
373 picons = KGlobal::iconLoader(); 378 picons = KGlobal::iconLoader();
374#endif 379#endif
375 380
376#ifdef PWM_EMBEDDED 381#ifdef PWM_EMBEDDED
377 if ( QApplication::desktop()->width() > 320 ) 382 if ( QApplication::desktop()->width() > 320 )
378#endif 383#endif
379 { 384 {
380 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), 385 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar),
381 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, 386 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
382 SLOT(new_slot()), true, i18n("New")); 387 SLOT(new_slot()), true, i18n("New"));
383 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), 388 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar),
384 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, 389 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
385 SLOT(open_slot()), true, i18n("Open")); 390 SLOT(open_slot()), true, i18n("Open"));
386 toolBar()->insertSeparator(); 391 toolBar()->insertSeparator();
387 } 392 }
388 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), 393 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar),
389 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, 394 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
390 SLOT(save_slot()), true, i18n("Save")); 395 SLOT(save_slot()), true, i18n("Save"));
391 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), 396 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar),
392 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, 397 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
393 SLOT(saveAs_slot()), true, i18n("Save as")); 398 SLOT(saveAs_slot()), true, i18n("Save as"));
394 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), 399 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar),
395 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, 400 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
396 SLOT(print_slot()), true, i18n("Print...")); 401 SLOT(print_slot()), true, i18n("Print..."));
397 toolBar()->insertSeparator(); 402 toolBar()->insertSeparator();
398 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), 403 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar),
399 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, 404 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
400 SLOT(addPwd_slot()), true, 405 SLOT(addPwd_slot()), true,
401 i18n("Add password")); 406 i18n("Add password"));
402 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), 407 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar),
403 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, 408 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
404 SLOT(editPwd_slot()), true, 409 SLOT(editPwd_slot()), true,
405 i18n("Edit password")); 410 i18n("Edit password"));
406 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), 411 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar),
407 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, 412 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this,
408 SLOT(deletePwd_slot()), true, 413 SLOT(deletePwd_slot()), true,
@@ -564,114 +569,120 @@ void PwM::saveAs_slot()
564 saveAs(); 569 saveAs();
565} 570}
566 571
567bool PwM::saveAs() 572bool PwM::saveAs()
568{ 573{
569 if (!curDoc()->saveAsDocUi(curDoc())) 574 if (!curDoc()->saveAsDocUi(curDoc()))
570 return false; 575 return false;
571 showStatMsg(i18n("Successfully saved data.")); 576 showStatMsg(i18n("Successfully saved data."));
572 updateCaption(); 577 updateCaption();
573 return true; 578 return true;
574} 579}
575 580
576//US ENH : changed code to run with older MOC 581//US ENH : changed code to run with older MOC
577void PwM::addPwd_slot() 582void PwM::addPwd_slot()
578{ 583{
579 addPwd_slot(0, 0); 584 addPwd_slot(0, 0);
580} 585}
581 586
582void PwM::addPwd_slot(QString *pw, PwMDoc *_doc) 587void PwM::addPwd_slot(QString *pw, PwMDoc *_doc)
583{ 588{
584 PwMDoc *doc; 589 PwMDoc *doc;
585 if (_doc) { 590 if (_doc) {
586 doc = _doc; 591 doc = _doc;
587 } else { 592 } else {
588 doc = curDoc(); 593 doc = curDoc();
589 } 594 }
590 PWM_ASSERT(doc); 595 PWM_ASSERT(doc);
591 doc->timer()->getLock(DocTimer::id_autoLockTimer); 596 doc->timer()->getLock(DocTimer::id_autoLockTimer);
592#ifndef PWM_EMBEDDED 597#ifndef PWM_EMBEDDED
593 AddEntryWndImpl w; 598 AddEntryWndImpl w;
594#else 599#else
595 AddEntryWndImpl w(this, "addentrywndimpl"); 600 AddEntryWndImpl w(this, "addentrywndimpl");
596#endif 601#endif
597 602
598 vector<string> catList; 603 vector<string> catList;
599 doc->getCategoryList(&catList); 604 doc->getCategoryList(&catList);
600 unsigned i, size = catList.size(); 605 unsigned i, size = catList.size();
601 for (i = 0; i < size; ++i) { 606 for (i = 0; i < size; ++i) {
602 w.addCategory(catList[i].c_str()); 607 w.addCategory(catList[i].c_str());
603 } 608 }
604 w.setCurrCategory(view->getCurrentCategory()); 609 w.setCurrCategory(view->getCurrentCategory());
605 if (pw) 610 if (pw)
606 w.pwLineEdit->setText(*pw); 611 w.pwLineEdit->setText(*pw);
607 612
608 tryAgain: 613 tryAgain:
609 if (w.exec() == 1) 614 if (w.exec() == 1)
610 { 615 {
611 PwMDataItem d; 616 PwMDataItem d;
617
618 //US BUG: to initialize all values of curEntr with meaningfulldata,
619 // we call clear on it. Reason: Metadata will be uninitialized otherwise.
620 // another option would be to create a constructor for PwMDataItem
621 d.clear(true);
622
612 d.desc = w.getDescription().latin1(); 623 d.desc = w.getDescription().latin1();
613 d.name = w.getUsername().latin1(); 624 d.name = w.getUsername().latin1();
614 d.pw = w.getPassword().latin1(); 625 d.pw = w.getPassword().latin1();
615 d.comment = w.getComment().latin1(); 626 d.comment = w.getComment().latin1();
616 d.url = w.getUrl().latin1(); 627 d.url = w.getUrl().latin1();
617 d.launcher = w.getLauncher().latin1(); 628 d.launcher = w.getLauncher().latin1();
618 PwMerror ret = doc->addEntry(w.getCategory(), &d); 629 PwMerror ret = doc->addEntry(w.getCategory(), &d);
619 if (ret == e_entryExists) { 630 if (ret == e_entryExists) {
620 KMessageBox::error(this, 631 KMessageBox::error(this,
621 i18n 632 i18n
622 ("An entry with this \"Description\", " 633 ("An entry with this \"Description\",\n"
623 "does already exist.\n" 634 "does already exist.\n"
624 "Please select another description."), 635 "Please select another description."),
625 i18n("entry already exists.")); 636 i18n("entry already exists."));
626 goto tryAgain; 637 goto tryAgain;
627 } else if (ret == e_maxAllowedEntr) { 638 } else if (ret == e_maxAllowedEntr) {
628 KMessageBox::error(this, i18n("The maximum possible number of entries " 639 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
629 "has been reached. You can't add more entries."), 640 "has been reached.\nYou can't add more entries."),
630 i18n("maximum number of entries")); 641 i18n("maximum number of entries"));
631 doc->timer()->putLock(DocTimer::id_autoLockTimer); 642 doc->timer()->putLock(DocTimer::id_autoLockTimer);
632 return; 643 return;
633 } 644 }
634 } 645 }
635 setVirgin(false); 646 setVirgin(false);
636 doc->timer()->putLock(DocTimer::id_autoLockTimer); 647 doc->timer()->putLock(DocTimer::id_autoLockTimer);
637} 648}
638 649
639//US ENH : changed code to run with older MOC 650//US ENH : changed code to run with older MOC
640void PwM::editPwd_slot() 651void PwM::editPwd_slot()
641{ 652{
642 editPwd_slot(0,0,0); 653 editPwd_slot(0,0,0);
643} 654}
644 655
645void PwM::editPwd_slot(const QString *category) 656void PwM::editPwd_slot(const QString *category)
646{ 657{
647 editPwd_slot(category, 0, 0); 658 editPwd_slot(category, 0, 0);
648} 659}
649 660
650void PwM::editPwd_slot(const QString *category, const int *index, 661void PwM::editPwd_slot(const QString *category, const int *index,
651 PwMDoc *_doc) 662 PwMDoc *_doc)
652{ 663{
653 PwMDoc *doc; 664 PwMDoc *doc;
654 if (_doc) { 665 if (_doc) {
655 doc = _doc; 666 doc = _doc;
656 } else { 667 } else {
657 doc = curDoc(); 668 doc = curDoc();
658 } 669 }
659 PWM_ASSERT(doc); 670 PWM_ASSERT(doc);
660 if (doc->isDocEmpty()) 671 if (doc->isDocEmpty())
661 return; 672 return;
662 if (doc->isDeepLocked()) 673 if (doc->isDeepLocked())
663 return; 674 return;
664 doc->timer()->getLock(DocTimer::id_autoLockTimer); 675 doc->timer()->getLock(DocTimer::id_autoLockTimer);
665 unsigned int curEntryIndex; 676 unsigned int curEntryIndex;
666 if (index) { 677 if (index) {
667 curEntryIndex = *index; 678 curEntryIndex = *index;
668 } else { 679 } else {
669 if (!(view->getCurEntryIndex(&curEntryIndex))) { 680 if (!(view->getCurEntryIndex(&curEntryIndex))) {
670 printDebug("couldn't get index. Maybe we have a binary entry here."); 681 printDebug("couldn't get index. Maybe we have a binary entry here.");
671 doc->timer()->putLock(DocTimer::id_autoLockTimer); 682 doc->timer()->putLock(DocTimer::id_autoLockTimer);
672 return; 683 return;
673 } 684 }
674 } 685 }
675 QString curCategory; 686 QString curCategory;
676 if (category) { 687 if (category) {
677 curCategory = *category; 688 curCategory = *category;
@@ -1242,124 +1253,112 @@ void PwM::goToURL_slot()
1242} 1253}
1243 1254
1244void PwM::copyToClipboard(const QString &s) 1255void PwM::copyToClipboard(const QString &s)
1245{ 1256{
1246 QClipboard *cb = QApplication::clipboard(); 1257 QClipboard *cb = QApplication::clipboard();
1247#ifndef PWM_EMBEDDED 1258#ifndef PWM_EMBEDDED
1248 if (cb->supportsSelection()) 1259 if (cb->supportsSelection())
1249 cb->setText(s, QClipboard::Selection); 1260 cb->setText(s, QClipboard::Selection);
1250 cb->setText(s, QClipboard::Clipboard); 1261 cb->setText(s, QClipboard::Clipboard);
1251#else 1262#else
1252 cb->setText(s); 1263 cb->setText(s);
1253 1264
1254#endif 1265#endif
1255 1266
1256} 1267}
1257 1268
1258void PwM::showStatMsg(const QString &msg) 1269void PwM::showStatMsg(const QString &msg)
1259{ 1270{
1260#ifndef PWM_EMBEDDED 1271#ifndef PWM_EMBEDDED
1261 KStatusBar *statBar = statusBar(); 1272 KStatusBar *statBar = statusBar();
1262 statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); 1273 statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
1263#else 1274#else
1264 qDebug("Statusbar : %s",msg.latin1()); 1275 qDebug("Statusbar : %s",msg.latin1());
1265#endif 1276#endif
1266} 1277}
1267 1278
1268void PwM::focusInEvent(QFocusEvent *e) 1279void PwM::focusInEvent(QFocusEvent *e)
1269{ 1280{
1270 if (e->gotFocus()) { 1281 if (e->gotFocus()) {
1271 emit gotFocus(this); 1282 emit gotFocus(this);
1272 } else if (e->lostFocus()) { 1283 } else if (e->lostFocus()) {
1273 emit lostFocus(this); 1284 emit lostFocus(this);
1274 } 1285 }
1275} 1286}
1276 1287
1277 1288
1278#ifdef PWM_EMBEDDED 1289#ifdef PWM_EMBEDDED
1279 1290
1280void PwM::showLicense_slot() 1291void PwM::showLicense_slot()
1281{ 1292{
1282 KApplication::showLicence(); 1293 KApplication::showLicence();
1283} 1294}
1284 1295
1285void PwM::faq_slot() 1296void PwM::faq_slot()
1286{ 1297{
1287 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); 1298 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
1288} 1299}
1289 1300
1301void PwM::syncHowTo_slot()
1302{
1303 qDebug("PwM::syncHowTo_slot");
1304 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
1305}
1306
1307
1290void PwM::createAboutData_slot() 1308void PwM::createAboutData_slot()
1291{ 1309{
1292 QString version; 1310 QString version;
1293#include <../version> 1311#include <../version>
1294 QMessageBox::about( this, "About PwManager/Pi", 1312 QMessageBox::about( this, "About PwManager/Pi",
1295 "PwManager/Platform-independent\n" 1313 "PwManager/Platform-independent\n"
1296 "(PWM/Pi) " +version + " - " + 1314 "(PWM/Pi) " +version + " - " +
1297#ifdef DESKTOP_VERSION 1315#ifdef DESKTOP_VERSION
1298 "Desktop Edition\n" 1316 "Desktop Edition\n"
1299#else 1317#else
1300 "PDA-Edition\n" 1318 "PDA-Edition\n"
1301 "for: Zaurus 5500 / 7x0 / 8x0\n" 1319 "for: Zaurus 5500 / 7x0 / 8x0\n"
1302#endif 1320#endif
1303 1321
1304 "(c) 2004 Ulf Schenk\n" 1322 "(c) 2004 Ulf Schenk\n"
1305 "(c) 2004 Lutz Rogowski\n" 1323 "(c) 2004 Lutz Rogowski\n"
1306 "(c) 1997-2004, The KDE PIM Team\n" 1324 "(c) 1997-2004, The KDE PIM Team\n"
1307 1325
1308 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" 1326 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
1309 "Matt Scifo - mscifo@o1.com\n" 1327 "Matt Scifo - mscifo@o1.com\n"
1310 "Elias Probst - elias.probst@gmx.de\n" 1328 "Elias Probst - elias.probst@gmx.de\n"
1311 "George Staikos - staikos@kde.org\n" 1329 "George Staikos - staikos@kde.org\n"
1312 "Matthew Palmer - mjp16@uow.edu.au\n" 1330 "Matthew Palmer - mjp16@uow.edu.au\n"
1313 "Olivier Sessink - gpasman@nl.linux.org\n" 1331 "Olivier Sessink - gpasman@nl.linux.org\n"
1314 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" 1332 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
1315 "Troy Engel - tengel@sonic.net\n" 1333 "Troy Engel - tengel@sonic.net\n"
1316 "Wickey - wickey@gmx.at\n" 1334 "Wickey - wickey@gmx.at\n"
1317 "Ian MacGregor - original documentation author.\n" 1335 "Ian MacGregor - original documentation author.\n"
1318 ); 1336 );
1319} 1337}
1320 1338
1321 1339
1322//this are the overwritten callbackmethods from the syncinterface 1340//this are the overwritten callbackmethods from the syncinterface
1323bool PwM::sync(KSyncManager* manager, QString filename, int mode) 1341bool PwM::sync(KSyncManager* manager, QString filename, int mode)
1324{ 1342{
1325 PWM_ASSERT(curDoc()); 1343 PWM_ASSERT(curDoc());
1326 1344
1327 bool ret = curDoc()->sync(manager, filename, mode); 1345 bool ret = curDoc()->sync(manager, filename, mode);
1328 1346
1347 qDebug("PwM::sync save now: ret=%i", ret);
1348
1329 if (ret == true) { 1349 if (ret == true) {
1330 //US BUG: what can we call here to update the view of the current doc? 1350 //US BUG: what can we call here to update the view of the current doc?
1331 //mViewManager->refreshView(); 1351 //mViewManager->refreshView();
1352
1353 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull.
1354 save();
1332 } 1355 }
1333 1356
1334 return ret; 1357 return ret;
1335} 1358}
1336
1337//called by the syncmanager to indicate that the work has to be marked as dirty.
1338void PwM::sync_setModified()
1339{
1340 PWM_ASSERT(curDoc());
1341 curDoc()->sync_setModified();
1342}
1343
1344//called by the syncmanager to ask if the dirty flag is set.
1345bool PwM::sync_isModified()
1346{
1347 PWM_ASSERT(curDoc());
1348 return curDoc()->sync_isModified();
1349}
1350
1351//called by the syncmanager to indicate that the work has to be saved.
1352void PwM::sync_save()
1353{
1354 PWM_ASSERT(curDoc());
1355 return curDoc()->sync_save();
1356}
1357
1358
1359
1360#endif 1359#endif
1361 1360
1362 1361
1363#ifndef PWM_EMBEDDED 1362#ifndef PWM_EMBEDDED
1364#include "pwm.moc" 1363#include "pwm.moc"
1365#endif 1364#endif
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index 7c6bf0d..6ed9d34 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -132,166 +132,160 @@ public slots:
132 bool importKWallet(); 132 bool importKWallet();
133 /** file/print triggered */ 133 /** file/print triggered */
134 void print_slot(); 134 void print_slot();
135 /** manage/add triggered */ 135 /** manage/add triggered */
136 //US ENH : changed code to run with older MOC 136 //US ENH : changed code to run with older MOC
137 void addPwd_slot(); 137 void addPwd_slot();
138 void addPwd_slot(QString *pw, PwMDoc *_doc); 138 void addPwd_slot(QString *pw, PwMDoc *_doc);
139 /** manage/edit triggered */ 139 /** manage/edit triggered */
140 //US ENH : changed code to run with older MOC 140 //US ENH : changed code to run with older MOC
141 void editPwd_slot(); 141 void editPwd_slot();
142 void editPwd_slot(const QString *category); 142 void editPwd_slot(const QString *category);
143 void editPwd_slot(const QString *category = 0, const int *index = 0, 143 void editPwd_slot(const QString *category = 0, const int *index = 0,
144 PwMDoc *_doc = 0); 144 PwMDoc *_doc = 0);
145 /** manage/delete triggered */ 145 /** manage/delete triggered */
146 void deletePwd_slot(); 146 void deletePwd_slot();
147 /** execute the "Launcher" entry */ 147 /** execute the "Launcher" entry */
148 void execLauncher_slot(); 148 void execLauncher_slot();
149 /** open browser with URL entry */ 149 /** open browser with URL entry */
150 void goToURL_slot(); 150 void goToURL_slot();
151 /** manage/changeMasterPwd triggered */ 151 /** manage/changeMasterPwd triggered */
152 void changeMasterPwd_slot(); 152 void changeMasterPwd_slot();
153 /** lock current document */ 153 /** lock current document */
154 void lockWnd_slot(); 154 void lockWnd_slot();
155 /** deeplock current document */ 155 /** deeplock current document */
156 void deepLockWnd_slot(); 156 void deepLockWnd_slot();
157 /** window/unlock triggered */ 157 /** window/unlock triggered */
158 void unlockWnd_slot(); 158 void unlockWnd_slot();
159 /** find item */ 159 /** find item */
160 void find_slot(); 160 void find_slot();
161 /** configure clicked */ 161 /** configure clicked */
162 void config_slot(); 162 void config_slot();
163 /** (de)activate the "change master pw" button in the menu-bar */ 163 /** (de)activate the "change master pw" button in the menu-bar */
164 void activateMpButton(bool activate = true); 164 void activateMpButton(bool activate = true);
165 /** generate a new chipcard */ 165 /** generate a new chipcard */
166 void genNewCard_slot(); 166 void genNewCard_slot();
167 /** completely erase the current card */ 167 /** completely erase the current card */
168 void eraseCard_slot(); 168 void eraseCard_slot();
169 /** returns the ID number of the current card */ 169 /** returns the ID number of the current card */
170 void readCardId_slot(); 170 void readCardId_slot();
171 /** make backup image of the current card */ 171 /** make backup image of the current card */
172 void makeCardBackup_slot(); 172 void makeCardBackup_slot();
173 /** write backup image to current card */ 173 /** write backup image to current card */
174 void replayCardBackup_slot(); 174 void replayCardBackup_slot();
175 175
176#ifdef PWM_EMBEDDED 176#ifdef PWM_EMBEDDED
177 void showLicense_slot(); 177 void showLicense_slot();
178 void faq_slot(); 178 void faq_slot();
179 void createAboutData_slot(); 179 void createAboutData_slot();
180 void syncHowTo_slot();
180#endif 181#endif
181 182
182protected: 183protected:
183 /** is this window virgin? */ 184 /** is this window virgin? */
184 bool isVirgin() 185 bool isVirgin()
185 { return virgin; } 186 { return virgin; }
186 /** add/remove virginity */ 187 /** add/remove virginity */
187 void setVirgin(bool v); 188 void setVirgin(bool v);
188 /** initialize the menubar */ 189 /** initialize the menubar */
189 void initMenubar(); 190 void initMenubar();
190 /** initialize the toolbar */ 191 /** initialize the toolbar */
191 void initToolbar(); 192 void initToolbar();
192 /** initialize the window-metrics */ 193 /** initialize the window-metrics */
193 void initMetrics(); 194 void initMetrics();
194 /** close-event */ 195 /** close-event */
195 void closeEvent(QCloseEvent *e); 196 void closeEvent(QCloseEvent *e);
196 /** creates a new PwM-ListView and returns it */ 197 /** creates a new PwM-ListView and returns it */
197 PwMView * makeNewListView(PwMDoc *doc); 198 PwMView * makeNewListView(PwMDoc *doc);
198 /** Window hide-event */ 199 /** Window hide-event */
199 void hideEvent(QHideEvent *); 200 void hideEvent(QHideEvent *);
200 /** is this window minimized? */ 201 /** is this window minimized? */
201 bool isMinimized() 202 bool isMinimized()
202 { 203 {
203#ifndef PWM_EMBEDDED 204#ifndef PWM_EMBEDDED
204 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) 205 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
205 return KWin::windowInfo(winId()).isMinimized(); 206 return KWin::windowInfo(winId()).isMinimized();
206 #else // KDE_VERSION 207 #else // KDE_VERSION
207 return KWin::info(winId()).isIconified(); 208 return KWin::info(winId()).isIconified();
208 #endif // KDE_VERSION 209 #endif // KDE_VERSION
209#else 210#else
210 return false; 211 return false;
211#endif 212#endif
212 } 213 }
213 /** window got the focus */ 214 /** window got the focus */
214 void focusInEvent(QFocusEvent *e); 215 void focusInEvent(QFocusEvent *e);
215 /** update the caption string */ 216 /** update the caption string */
216 void updateCaption(); 217 void updateCaption();
217#ifdef CONFIG_KWALLETIF 218#ifdef CONFIG_KWALLETIF
218 /** check if kwalletemu is enabled and ask the user what to do */ 219 /** check if kwalletemu is enabled and ask the user what to do */
219 bool checkAndAskForKWalletEmu(); 220 bool checkAndAskForKWalletEmu();
220#endif // CONFIG_KWALLETIF 221#endif // CONFIG_KWALLETIF
221 222
222protected slots: 223protected slots:
223 /** doc got closed */ 224 /** doc got closed */
224 void docClosed(PwMDoc *doc); 225 void docClosed(PwMDoc *doc);
225 226
226signals: 227signals:
227 /** window got closed (by user or someone else) */ 228 /** window got closed (by user or someone else) */
228 void closed(PwM *wnd); 229 void closed(PwM *wnd);
229 /** window got the focus (was brought to foreground) */ 230 /** window got the focus (was brought to foreground) */
230 void gotFocus(PwM *wnd); 231 void gotFocus(PwM *wnd);
231 /** window lost the focus */ 232 /** window lost the focus */
232 void lostFocus(PwM *wnd); 233 void lostFocus(PwM *wnd);
233 234
234protected: 235protected:
235 /** pointer to the view active in this KMainWindow */ 236 /** pointer to the view active in this KMainWindow */
236 PwMView *view; 237 PwMView *view;
237 /** pointer to the init class */ 238 /** pointer to the init class */
238 PwMInit *init; 239 PwMInit *init;
239 /** has this window already lost its virginity? 240 /** has this window already lost its virginity?
240 * Means is there an open working document 241 * Means is there an open working document
241 */ 242 */
242 bool virgin; 243 bool virgin;
243 /** "file" popup-menu */ 244 /** "file" popup-menu */
244 KPopupMenu *filePopup; 245 KPopupMenu *filePopup;
245 246
246 /** "manage" popup-menu */ 247 /** "manage" popup-menu */
247 KPopupMenu *managePopup; 248 KPopupMenu *managePopup;
248#ifdef CONFIG_KEYCARD 249#ifdef CONFIG_KEYCARD
249 /** "chipcard" popup-menu */ 250 /** "chipcard" popup-menu */
250 KPopupMenu *chipcardPopup; 251 KPopupMenu *chipcardPopup;
251#endif // CONFIG_KEYCARD 252#endif // CONFIG_KEYCARD
252 /** "view" popup-menu */ 253 /** "view" popup-menu */
253 KPopupMenu *viewPopup; 254 KPopupMenu *viewPopup;
254 /** "options" popup-menu */ 255 /** "options" popup-menu */
255 KPopupMenu *optionsPopup; 256 KPopupMenu *optionsPopup;
256 /** "help" popup-menu */ 257 /** "help" popup-menu */
257 KPopupMenu *helpPopup; 258 KPopupMenu *helpPopup;
258 /** "export" popup-menu */ 259 /** "export" popup-menu */
259 KPopupMenu *exportPopup; 260 KPopupMenu *exportPopup;
260 /** "import" popup-menu */ 261 /** "import" popup-menu */
261 KPopupMenu *importPopup; 262 KPopupMenu *importPopup;
262 /** force quit this window? */ 263 /** force quit this window? */
263 bool forceQuit; 264 bool forceQuit;
264 /** force minimize this window to the tray */ 265 /** force minimize this window to the tray */
265 bool forceMinimizeToTray; 266 bool forceMinimizeToTray;
266 267
267 268
268 269
269 270
270 private: 271 private:
271#ifdef PWM_EMBEDDED 272#ifdef PWM_EMBEDDED
272 //this are the overwritten callbackmethods from the syncinterface 273 //this are the overwritten callbackmethods from the syncinterface
273 virtual bool sync(KSyncManager* manager, QString filename, int mode); 274 virtual bool sync(KSyncManager* manager, QString filename, int mode);
274 275
275 //called by the syncmanager to indicate that the work has to marked as dirty.
276 virtual void sync_setModified();
277 //called by the syncmanager to ask if the dirty flag is set.
278 virtual bool sync_isModified();
279 //called by the syncmanager to indicate that the work has to be saved.
280 virtual void sync_save();
281
282 // LR ******************************* 276 // LR *******************************
283 // sync stuff! 277 // sync stuff!
284 QPopupMenu *syncPopup; 278 QPopupMenu *syncPopup;
285 KSyncManager* syncManager; 279 KSyncManager* syncManager;
286#endif 280#endif
287 281
288 282
289 283
290 284
291 285
292 286
293 287
294 288
295}; 289};
296 290
297#endif 291#endif
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 0ac5517..2a7b11d 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -442,97 +442,98 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
442 goto out_moveback; 442 goto out_moveback;
443 } else if (e != e_success) { 443 } else if (e != e_success) {
444 printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); 444 printDebug("PwMDoc::saveDoc(): writeDataHash() failed");
445 f.close(); 445 f.close();
446 ret = e_writeHeader; 446 ret = e_writeHeader;
447 goto out_moveback; 447 goto out_moveback;
448 } 448 }
449 if (!compressDta(&serialized, compress)) { 449 if (!compressDta(&serialized, compress)) {
450 printDebug("PwMDoc::saveDoc(): compressDta() failed"); 450 printDebug("PwMDoc::saveDoc(): compressDta() failed");
451 f.close(); 451 f.close();
452 ret = e_enc; 452 ret = e_enc;
453 goto out_moveback; 453 goto out_moveback;
454 } 454 }
455 e = encrypt(&serialized, &currentPw, &f, cryptAlgo); 455 e = encrypt(&serialized, &currentPw, &f, cryptAlgo);
456 if (e == e_weakPw) { 456 if (e == e_weakPw) {
457 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); 457 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw");
458 f.close(); 458 f.close();
459 ret = e_weakPw; 459 ret = e_weakPw;
460 goto out_moveback; 460 goto out_moveback;
461 } else if (e == e_cryptNotImpl) { 461 } else if (e == e_cryptNotImpl) {
462 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); 462 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl");
463 f.close(); 463 f.close();
464 ret = e_cryptNotImpl; 464 ret = e_cryptNotImpl;
465 goto out_moveback; 465 goto out_moveback;
466 } else if (e != e_success) { 466 } else if (e != e_success) {
467 printDebug("PwMDoc::saveDoc(): encrypt() failed"); 467 printDebug("PwMDoc::saveDoc(): encrypt() failed");
468 f.close(); 468 f.close();
469 ret = e_enc; 469 ret = e_enc;
470 goto out_moveback; 470 goto out_moveback;
471 } 471 }
472 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 472 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
473 f.close(); 473 f.close();
474 if (chmod(filename.latin1(), 474 if (chmod(filename.latin1(),
475 conf()->confGlobFilePermissions())) { 475 conf()->confGlobFilePermissions())) {
476 printWarn(string("chmod failed: ") + strerror(errno)); 476 printWarn(string("chmod failed: ") + strerror(errno));
477 } 477 }
478 openDocList.edit(this, getTitle().latin1()); 478 openDocList.edit(this, getTitle().latin1());
479 if (wasDeepLocked) 479 if (wasDeepLocked)
480 deepLock(true); 480 deepLock(true);
481 if (tmpFileMoved != QString::null) { 481 if (tmpFileMoved != QString::null) {
482 // now remove the moved file. 482 // now remove the moved file.
483 if (!QFile::remove(tmpFileMoved)) { 483 if (!QFile::remove(tmpFileMoved)) {
484 printWarn(string("removing file ") 484 printWarn(string("removing file ")
485 + tmpFileMoved.latin1() 485 + tmpFileMoved.latin1()
486 + " failed!"); 486 + " failed!");
487 } 487 }
488 } 488 }
489 ret = e_success; 489 ret = e_success;
490 printDebug(string("writing file { compress: ") 490 printDebug(string("writing file { name: ")
491 + filename.latin1() + " compress: "
491 + tostr(static_cast<int>(compress)) + " cryptAlgo: " 492 + tostr(static_cast<int>(compress)) + " cryptAlgo: "
492 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " 493 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: "
493 + tostr(static_cast<int>(hashAlgo)) 494 + tostr(static_cast<int>(hashAlgo))
494 + " }"); 495 + " }");
495 goto out; 496 goto out;
496out_moveback: 497out_moveback:
497 if (tmpFileMoved != QString::null) { 498 if (tmpFileMoved != QString::null) {
498 if (copyFile(tmpFileMoved, filename)) { 499 if (copyFile(tmpFileMoved, filename)) {
499 if (!QFile::remove(tmpFileMoved)) { 500 if (!QFile::remove(tmpFileMoved)) {
500 printWarn(string("removing tmp file ") 501 printWarn(string("removing tmp file ")
501 + filename.latin1() 502 + filename.latin1()
502 + " failed!"); 503 + " failed!");
503 } 504 }
504 } else { 505 } else {
505 printWarn(string("couldn't copy file ") 506 printWarn(string("couldn't copy file ")
506 + tmpFileMoved.latin1() 507 + tmpFileMoved.latin1()
507 + " back to " 508 + " back to "
508 + filename.latin1()); 509 + filename.latin1());
509 } 510 }
510 } 511 }
511out: 512out:
512 return ret; 513 return ret;
513} 514}
514 515
515PwMerror PwMDoc::openDoc(const QString *file, int openLocked) 516PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
516{ 517{
517 PWM_ASSERT(file); 518 PWM_ASSERT(file);
518 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); 519 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2);
519 string decrypted, dataHash; 520 string decrypted, dataHash;
520 PwMerror ret; 521 PwMerror ret;
521 char cryptAlgo, dataHashType, compress; 522 char cryptAlgo, dataHashType, compress;
522 unsigned int headerLen; 523 unsigned int headerLen;
523 524
524 if (*file == "") 525 if (*file == "")
525 return e_readFile; 526 return e_readFile;
526 filename = *file; 527 filename = *file;
527 /* check if this file is already open. 528 /* check if this file is already open.
528 * This does not catch symlinks! 529 * This does not catch symlinks!
529 */ 530 */
530 if (!isDeepLocked()) { 531 if (!isDeepLocked()) {
531 if (getOpenDocList()->find(filename.latin1())) 532 if (getOpenDocList()->find(filename.latin1()))
532 return e_alreadyOpen; 533 return e_alreadyOpen;
533 } 534 }
534 QFile f(filename); 535 QFile f(filename);
535 536
536 if (openLocked == 2) { 537 if (openLocked == 2) {
537 // open deep-locked 538 // open deep-locked
538 if (!QFile::exists(filename)) 539 if (!QFile::exists(filename))
@@ -560,97 +561,99 @@ PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
560 return ret; 561 return ret;
561 } else 562 } else
562 return e_readFile; 563 return e_readFile;
563 } 564 }
564 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f); 565 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f);
565 if (ret == e_cryptNotImpl) { 566 if (ret == e_cryptNotImpl) {
566 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); 567 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl");
567 f.close(); 568 f.close();
568 return e_cryptNotImpl; 569 return e_cryptNotImpl;
569 } else if (ret != e_success) { 570 } else if (ret != e_success) {
570 printDebug("PwMDoc::openDoc(): decrypt() failed"); 571 printDebug("PwMDoc::openDoc(): decrypt() failed");
571 f.close(); 572 f.close();
572 return e_readFile; 573 return e_readFile;
573 } 574 }
574 if (!decompressDta(&decrypted, compress)) { 575 if (!decompressDta(&decrypted, compress)) {
575 printDebug("PwMDoc::openDoc(): decompressDta() failed"); 576 printDebug("PwMDoc::openDoc(): decompressDta() failed");
576 f.close(); 577 f.close();
577 return e_fileCorrupt; 578 return e_fileCorrupt;
578 } 579 }
579 ret = checkDataHash(dataHashType, &dataHash, &decrypted); 580 ret = checkDataHash(dataHashType, &dataHash, &decrypted);
580 if (ret == e_hashNotImpl) { 581 if (ret == e_hashNotImpl) {
581 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); 582 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl");
582 f.close(); 583 f.close();
583 return e_hashNotImpl; 584 return e_hashNotImpl;
584 } else if (ret != e_success) { 585 } else if (ret != e_success) {
585 printDebug("PwMDoc::openDoc(): checkDataHash() failed"); 586 printDebug("PwMDoc::openDoc(): checkDataHash() failed");
586 f.close(); 587 f.close();
587 return e_fileCorrupt; 588 return e_fileCorrupt;
588 } 589 }
589 if (!deSerializeDta(&decrypted, openLocked == 1)) { 590 if (!deSerializeDta(&decrypted, openLocked == 1)) {
590 printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); 591 printDebug("PwMDoc::openDoc(): deSerializeDta() failed");
591 f.close(); 592 f.close();
592 return e_readFile; 593 return e_readFile;
593 } 594 }
594 f.close(); 595 f.close();
595 timer()->start(DocTimer::id_mpwTimer); 596 timer()->start(DocTimer::id_mpwTimer);
596 timer()->start(DocTimer::id_autoLockTimer); 597 timer()->start(DocTimer::id_autoLockTimer);
597out_success: 598out_success:
598 openDocList.edit(this, getTitle().latin1()); 599 openDocList.edit(this, getTitle().latin1());
599 emit docOpened(this); 600 emit docOpened(this);
600 return e_success; 601 return e_success;
601} 602}
602 603
603PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 604PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
604 QString *pw, QFile *f) 605 QString *pw, QFile *f)
605{ 606{
606 PWM_ASSERT(pw); 607 PWM_ASSERT(pw);
607 PWM_ASSERT(f); 608 PWM_ASSERT(f);
608 PWM_ASSERT(listView); 609 //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else
610 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion
611 //USPWM_ASSERT(listView);
609 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != 612 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
610 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { 613 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
611 return e_writeFile; 614 return e_writeFile;
612 } 615 }
613 if (f->putch(PWM_FILE_VER) == -1 || 616 if (f->putch(PWM_FILE_VER) == -1 ||
614 f->putch(keyHash) == -1 || 617 f->putch(keyHash) == -1 ||
615 f->putch(dataHash) == -1 || 618 f->putch(dataHash) == -1 ||
616 f->putch(crypt) == -1 || 619 f->putch(crypt) == -1 ||
617 f->putch(compress) == -1 || 620 f->putch(compress) == -1 ||
618 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? 621 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
619 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { 622 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) {
620 return e_writeFile; 623 return e_writeFile;
621 } 624 }
622 625
623 // write bytes of NUL-data. These bytes are reserved for future-use. 626 // write bytes of NUL-data. These bytes are reserved for future-use.
624 const int bufSize = 64; 627 const int bufSize = 64;
625 char tmp_buf[bufSize]; 628 char tmp_buf[bufSize];
626 memset(tmp_buf, 0x00, bufSize); 629 memset(tmp_buf, 0x00, bufSize);
627 if (f->writeBlock(tmp_buf, bufSize) != bufSize) 630 if (f->writeBlock(tmp_buf, bufSize) != bufSize)
628 return e_writeFile; 631 return e_writeFile;
629 632
630 switch (keyHash) { 633 switch (keyHash) {
631 case PWM_HASH_SHA1: { 634 case PWM_HASH_SHA1: {
632 const int hashlen = SHA1_HASH_LEN_BYTE; 635 const int hashlen = SHA1_HASH_LEN_BYTE;
633 Sha1 hash; 636 Sha1 hash;
634 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 637 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
635 string ret = hash.sha1_read(); 638 string ret = hash.sha1_read();
636 if (f->writeBlock(ret.c_str(), hashlen) != hashlen) 639 if (f->writeBlock(ret.c_str(), hashlen) != hashlen)
637 return e_writeFile; 640 return e_writeFile;
638 break; 641 break;
639 } 642 }
640 case PWM_HASH_SHA256: 643 case PWM_HASH_SHA256:
641 /*... fall through */ 644 /*... fall through */
642 case PWM_HASH_SHA384: 645 case PWM_HASH_SHA384:
643 case PWM_HASH_SHA512: 646 case PWM_HASH_SHA512:
644 case PWM_HASH_MD5: 647 case PWM_HASH_MD5:
645 case PWM_HASH_RMD160: 648 case PWM_HASH_RMD160:
646 case PWM_HASH_TIGER: 649 case PWM_HASH_TIGER:
647 { 650 {
648 if (!LibGCryptIf::available()) 651 if (!LibGCryptIf::available())
649 return e_hashNotImpl; 652 return e_hashNotImpl;
650 LibGCryptIf gc; 653 LibGCryptIf gc;
651 PwMerror err; 654 PwMerror err;
652 unsigned char *buf; 655 unsigned char *buf;
653 size_t hashLen; 656 size_t hashLen;
654 err = gc.hash(&buf, 657 err = gc.hash(&buf,
655 &hashLen, 658 &hashLen,
656 reinterpret_cast<const unsigned char *>(pw->latin1()), 659 reinterpret_cast<const unsigned char *>(pw->latin1()),
@@ -2759,576 +2762,594 @@ PwMerror PwMDoc::exportToGpasman(const QString *file)
2759} 2762}
2760 2763
2761PwMerror PwMDoc::importFromGpasman(const QString *file) 2764PwMerror PwMDoc::importFromGpasman(const QString *file)
2762{ 2765{
2763 PWM_ASSERT(file); 2766 PWM_ASSERT(file);
2764 QString pw = requestMpw(false); 2767 QString pw = requestMpw(false);
2765 if (pw == "") 2768 if (pw == "")
2766 return e_noPw; 2769 return e_noPw;
2767 GpasmanFile gp; 2770 GpasmanFile gp;
2768 int ret, i; 2771 int ret, i;
2769 PwMerror ret2; 2772 PwMerror ret2;
2770 char *entry[4]; 2773 char *entry[4];
2771 PwMDataItem tmpData; 2774 PwMDataItem tmpData;
2772 ret = gp.load_init(file->latin1(), pw.latin1()); 2775 ret = gp.load_init(file->latin1(), pw.latin1());
2773 if (ret != 1) 2776 if (ret != 1)
2774 return e_accessFile; 2777 return e_accessFile;
2775 2778
2776 do { 2779 do {
2777 ret = gp.load_entry(entry); 2780 ret = gp.load_entry(entry);
2778 if(ret != 1) 2781 if(ret != 1)
2779 break; 2782 break;
2780 tmpData.desc = entry[0]; 2783 tmpData.desc = entry[0];
2781 tmpData.name = entry[1]; 2784 tmpData.name = entry[1];
2782 tmpData.pw = entry[2]; 2785 tmpData.pw = entry[2];
2783 tmpData.comment = entry[3]; 2786 tmpData.comment = entry[3];
2784 tmpData.lockStat = true; 2787 tmpData.lockStat = true;
2785 tmpData.listViewPos = -1; 2788 tmpData.listViewPos = -1;
2786 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2789 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2787 for (i = 0; i < 4; ++i) 2790 for (i = 0; i < 4; ++i)
2788 free(entry[i]); 2791 free(entry[i]);
2789 if (ret2 == e_maxAllowedEntr) { 2792 if (ret2 == e_maxAllowedEntr) {
2790 gp.load_finalize(); 2793 gp.load_finalize();
2791 return e_maxAllowedEntr; 2794 return e_maxAllowedEntr;
2792 } 2795 }
2793 } while (1); 2796 } while (1);
2794 gp.load_finalize(); 2797 gp.load_finalize();
2795 if (isDocEmpty()) 2798 if (isDocEmpty())
2796 return e_wrongPw; // we assume this. 2799 return e_wrongPw; // we assume this.
2797 2800
2798 flagDirty(); 2801 flagDirty();
2799 return e_success; 2802 return e_success;
2800} 2803}
2801 2804
2802void PwMDoc::ensureLvp() 2805void PwMDoc::ensureLvp()
2803{ 2806{
2804 if (isDocEmpty()) 2807 if (isDocEmpty())
2805 return; 2808 return;
2806 2809
2810 //US ENH BUG: when using syncronizing, this way of sorting
2811 //is not sufficient, because there might be empty spaces
2812 // at the beginning. But this algorythm only can add elements
2813 //to the end.The result are crashes because of listoverflows
2814 //we need something to fill all gaps.
2807 vector< vector<PwMDataItem>::iterator > undefined; 2815 vector< vector<PwMDataItem>::iterator > undefined;
2816 vector< vector<PwMDataItem>::iterator > sorted;
2808 vector< vector<PwMDataItem>::iterator >::iterator undefBegin, 2817 vector< vector<PwMDataItem>::iterator >::iterator undefBegin,
2809 undefEnd, 2818 undefEnd,
2810 undefI; 2819 undefI;
2820 vector< vector<PwMDataItem>::iterator >::iterator sortedBegin,
2821 sortedEnd,
2822 sortedI;
2811 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2823 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2812 catEnd = dti.dta.end(), 2824 catEnd = dti.dta.end(),
2813 catI = catBegin; 2825 catI = catBegin;
2814 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2826 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2815 int lvpTop, tmpLvp; 2827 int lvpTop, tmpLvp;
2816 2828
2817 while (catI != catEnd) { 2829 while (catI != catEnd) {
2818 lvpTop = -1; 2830 lvpTop = -1;
2819 undefined.clear(); 2831 undefined.clear();
2820 2832
2821 entrBegin = catI->d.begin(); 2833 entrBegin = catI->d.begin();
2822 entrEnd = catI->d.end(); 2834 entrEnd = catI->d.end();
2823 entrI = entrBegin; 2835 entrI = entrBegin;
2824 2836
2825 while (entrI != entrEnd) { 2837 while (entrI != entrEnd) {
2826 tmpLvp = entrI->listViewPos; 2838 tmpLvp = entrI->listViewPos;
2827 if (tmpLvp == -1) 2839 if (tmpLvp == -1)
2828 undefined.push_back(entrI); 2840 undefined.push_back(entrI);
2829 else if (tmpLvp > lvpTop) 2841 else
2830 lvpTop = tmpLvp; 2842 sorted[tmpLvp] = entrI;
2843 //US else if (tmpLvp > lvpTop)
2844 //US lvpTop = tmpLvp;
2831 ++entrI; 2845 ++entrI;
2832 } 2846 }
2847
2848 //now we have all undefied in the collection. Now insert the existing
2849 sortedBegin = sorted.begin();
2850 sortedEnd = sorted.end();
2851 sortedI = sortedBegin;
2852
2853 while (sortedI != sortedEnd) {
2854 tmpLvp = (*sortedI)->listViewPos;
2855 undefined[tmpLvp] = *sortedI;
2856 ++sortedI;
2857 }
2858
2833 undefBegin = undefined.begin(); 2859 undefBegin = undefined.begin();
2834 undefEnd = undefined.end(); 2860 undefEnd = undefined.end();
2835 undefI = undefBegin; 2861 undefI = undefBegin;
2836 while (undefI != undefEnd) { 2862 while (undefI != undefEnd) {
2837 (*undefI)->listViewPos = ++lvpTop; 2863 (*undefI)->listViewPos = ++lvpTop;
2838 ++undefI; 2864 ++undefI;
2839 } 2865 }
2840 ++catI; 2866 ++catI;
2841 } 2867 }
2842} 2868}
2843 2869
2844QString PwMDoc::getTitle() 2870QString PwMDoc::getTitle()
2845{ 2871{
2846 /* NOTE: We have to ensure, that the returned title 2872 /* NOTE: We have to ensure, that the returned title
2847 * is unique and not reused somewhere else while 2873 * is unique and not reused somewhere else while
2848 * this document is valid (open). 2874 * this document is valid (open).
2849 */ 2875 */
2850 QString title(getFilename()); 2876 QString title(getFilename());
2877
2878 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2879 if (QApplication::desktop()->width() < 640)
2880 {
2881 if (title.length() > 30)
2882 title = "..." + title.right(30);
2883
2884 }
2885
2886
2851 if (title.isEmpty()) { 2887 if (title.isEmpty()) {
2852 if (unnamedNum == 0) { 2888 if (unnamedNum == 0) {
2853 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2889 unnamedNum = PwMDocList::getNewUnnamedNumber();
2854 PWM_ASSERT(unnamedNum != 0); 2890 PWM_ASSERT(unnamedNum != 0);
2855 } 2891 }
2856 title = DEFAULT_TITLE; 2892 title = DEFAULT_TITLE;
2857 title += " "; 2893 title += " ";
2858 title += tostr(unnamedNum).c_str(); 2894 title += tostr(unnamedNum).c_str();
2859 } 2895 }
2860 return title; 2896 return title;
2861} 2897}
2862 2898
2863bool PwMDoc::tryDelete() 2899bool PwMDoc::tryDelete()
2864{ 2900{
2865 if (deleted) 2901 if (deleted)
2866 return true; 2902 return true;
2867 int ret; 2903 int ret;
2868 if (isDirty()) { 2904 if (isDirty()) {
2869 ret = dirtyAskSave(getTitle()); 2905 ret = dirtyAskSave(getTitle());
2870 if (ret == 0) { // save to disk 2906 if (ret == 0) { // save to disk
2871 if (!saveDocUi(this)) 2907 if (!saveDocUi(this))
2872 goto out_ignore; 2908 goto out_ignore;
2873 } else if (ret == 1) { // don't save and delete 2909 } else if (ret == 1) { // don't save and delete
2874 goto out_accept; 2910 goto out_accept;
2875 } else { // cancel operation 2911 } else { // cancel operation
2876 goto out_ignore; 2912 goto out_ignore;
2877 } 2913 }
2878 } 2914 }
2879out_accept: 2915out_accept:
2880 deleted = true; 2916 deleted = true;
2881 delete this; 2917 delete this;
2882 return true; 2918 return true;
2883out_ignore: 2919out_ignore:
2884 return false; 2920 return false;
2885} 2921}
2886 2922
2887 2923
2888 2924
2889#ifdef PWM_EMBEDDED 2925#ifdef PWM_EMBEDDED
2890//US ENH: this is the magic function that syncronizes the this doc with the remote doc 2926//US ENH: this is the magic function that syncronizes the this doc with the remote doc
2891//US it could have been defined as static, but I did not want to. 2927//US it could have been defined as static, but I did not want to.
2892PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 2928PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
2893{ 2929{
2894 int addedPasswordsLocal = 0; 2930 int addedPasswordsLocal = 0;
2895 int addedPasswordsRemote = 0; 2931 int addedPasswordsRemote = 0;
2896 int deletedPasswordsRemote = 0; 2932 int deletedPasswordsRemote = 0;
2897 int deletedPasswordsLocal = 0; 2933 int deletedPasswordsLocal = 0;
2898 int changedLocal = 0; 2934 int changedLocal = 0;
2899 int changedRemote = 0; 2935 int changedRemote = 0;
2900 2936
2901 PwMSyncItem* syncItemLocal; 2937 PwMSyncItem* syncItemLocal;
2902 PwMSyncItem* syncItemRemote; 2938 PwMSyncItem* syncItemRemote;
2903 2939
2904 QString mCurrentSyncName = manager->getCurrentSyncName(); 2940 QString mCurrentSyncName = manager->getCurrentSyncName();
2905 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2941 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2906 2942
2907 bool fullDateRange = false; 2943 bool fullDateRange = false;
2908 int take; 2944 int take;
2909 // local->resetTempSyncStat(); 2945 // local->resetTempSyncStat();
2910 QDateTime mLastSync = QDateTime::currentDateTime(); 2946 QDateTime mLastSync = QDateTime::currentDateTime();
2911 QDateTime modifiedSync = mLastSync; 2947 QDateTime modifiedSync = mLastSync;
2912 2948
2913 unsigned int index; 2949 unsigned int index;
2914 //Step 1. Find syncinfo in Local file and create if not existent. 2950 //Step 1. Find syncinfo in Local file and create if not existent.
2915 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2951 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2916 if (found == false) 2952 if (found == false)
2917 { 2953 {
2918 PwMSyncItem newSyncItemLocal; 2954 PwMSyncItem newSyncItemLocal;
2919 newSyncItemLocal.syncName = mCurrentSyncDevice; 2955 newSyncItemLocal.syncName = mCurrentSyncDevice;
2920 newSyncItemLocal.lastSyncDate = mLastSync; 2956 newSyncItemLocal.lastSyncDate = mLastSync;
2921 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 2957 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
2922 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2958 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2923 if (found == false) { 2959 if (found == false) {
2924 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 2960 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
2925 return e_syncError; 2961 return e_syncError;
2926 } 2962 }
2927 } 2963 }
2928 2964
2929 syncItemLocal = syncLocal->getSyncDataEntry(index); 2965 syncItemLocal = syncLocal->getSyncDataEntry(index);
2930 qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); 2966 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
2931 2967
2932 //Step 2. Find syncinfo in remote file and create if not existent. 2968 //Step 2. Find syncinfo in remote file and create if not existent.
2933 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2969 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2934 if (found == false) 2970 if (found == false)
2935 { 2971 {
2936 qDebug("FULLDATE 1"); 2972 qDebug("FULLDATE 1");
2937 fullDateRange = true; 2973 fullDateRange = true;
2938 PwMSyncItem newSyncItemRemote; 2974 PwMSyncItem newSyncItemRemote;
2939 newSyncItemRemote.syncName = mCurrentSyncName; 2975 newSyncItemRemote.syncName = mCurrentSyncName;
2940 newSyncItemRemote.lastSyncDate = mLastSync; 2976 newSyncItemRemote.lastSyncDate = mLastSync;
2941 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 2977 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
2942 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2978 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2943 if (found == false) { 2979 if (found == false) {
2944 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 2980 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
2945 return e_syncError; 2981 return e_syncError;
2946 } 2982 }
2947 } 2983 }
2948 2984
2949 syncItemRemote = syncRemote->getSyncDataEntry(index); 2985 syncItemRemote = syncRemote->getSyncDataEntry(index);
2986 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
2950 //and remove the found entry here. We will reenter it later again. 2987 //and remove the found entry here. We will reenter it later again.
2951 //US syncRemote->delSyncDataEntry(index, true); 2988 //US syncRemote->delSyncDataEntry(index, true);
2952 2989
2953 2990
2954 if ( syncItemLocal->lastSyncDate == mLastSync ) { 2991 if ( syncItemLocal->lastSyncDate == mLastSync ) {
2955 qDebug("FULLDATE 2"); 2992 qDebug("FULLDATE 2");
2956 fullDateRange = true; 2993 fullDateRange = true;
2957 } 2994 }
2958 2995
2959 if ( ! fullDateRange ) { 2996 if ( ! fullDateRange ) {
2960 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 2997 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
2961 2998
2962 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2999 // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() );
2963 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 3000 // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2964 fullDateRange = true; 3001 fullDateRange = true;
2965 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3002 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
2966 } 3003 }
2967 } 3004 }
2968 // fullDateRange = true; // debug only! 3005 // fullDateRange = true; // debug only!
2969 if ( fullDateRange ) 3006 if ( fullDateRange )
2970 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3007 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
2971 else 3008 else
2972 mLastSync = syncItemLocal->lastSyncDate; 3009 mLastSync = syncItemLocal->lastSyncDate;
2973 3010
2974 3011
2975 qDebug("*************************** "); 3012 qDebug("*************************** ");
2976 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 3013 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
2977 QStringList er = syncRemote->getIDEntryList(); 3014 QStringList er = syncRemote->getIDEntryList();
2978 PwMDataItem* inRemote ;//= er.first(); 3015 PwMDataItem* inRemote ;//= er.first();
2979 PwMDataItem* inLocal; 3016 PwMDataItem* inLocal;
2980 unsigned int catLocal, indexLocal; 3017 unsigned int catLocal, indexLocal;
2981 unsigned int catRemote, indexRemote; 3018 unsigned int catRemote, indexRemote;
2982 3019
2983 QString uid; 3020 QString uid;
2984 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3021 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2985 3022
2986 int modulo = (er.count()/10)+1; 3023 int modulo = (er.count()/10)+1;
2987 unsigned int incCounter = 0; 3024 unsigned int incCounter = 0;
2988 while ( incCounter < er.count()) { 3025 while ( incCounter < er.count()) {
2989 if (manager->isProgressBarCanceled()) 3026 if (manager->isProgressBarCanceled())
2990 return e_syncError; 3027 return e_syncError;
2991 if ( incCounter % modulo == 0 ) 3028 if ( incCounter % modulo == 0 )
2992 manager->showProgressBar(incCounter); 3029 manager->showProgressBar(incCounter);
2993 3030
2994 uid = er[ incCounter ]; 3031 uid = er[ incCounter ];
2995 qDebug("sync uid %s from remote file", uid.latin1()); 3032 qDebug("sync uid %s from remote file", uid.latin1());
2996 3033
2997 qApp->processEvents(); 3034 qApp->processEvents();
2998 3035
2999 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3036 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3000 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3037 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3001 PWM_ASSERT(inRemote); 3038 PWM_ASSERT(inRemote);
3002 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3039 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3003 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3040 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3004 //qDebug("take %d %s ", take, inL.summary().latin1()); 3041 qDebug("take %d %s ", take, inLocal->desc.c_str());
3005 if ( take == 3 ) 3042 if ( take == 3 )
3006 return e_syncError; 3043 return e_syncError;
3007 if ( take == 1 ) {// take local 3044 if ( take == 1 ) {// take local
3008 //US syncRemote->removeAddressee( inRemote ); 3045 //US syncRemote->removeAddressee( inRemote );
3009 (*inRemote) = (*inLocal); 3046 (*inRemote) = (*inLocal);
3010 //US syncRemote->insertAddressee( inRemote , false); 3047 //US syncRemote->insertAddressee( inRemote , false);
3011 ++changedRemote; 3048 ++changedRemote;
3012 } else { // take == 2 take remote 3049 } else { // take == 2 take remote
3013 //US syncLocal->removeAddressee( inLocal ); 3050 //US syncLocal->removeAddressee( inLocal );
3014 (*inLocal) = (*inRemote); 3051 (*inLocal) = (*inRemote);
3015 //US syncLocal->insertAddressee( inLocal , false ); 3052 //US syncLocal->insertAddressee( inLocal , false );
3016 ++changedLocal; 3053 ++changedLocal;
3017 } 3054 }
3018 } 3055 }
3019 } else { // no conflict 3056 } else { // no conflict
3020 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3057 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3021 inRemote->meta.update = modifiedSync; 3058 inRemote->meta.update = modifiedSync;
3022 3059
3023 //first check if we have a matching category in the local file 3060 //first check if we have a matching category in the local file
3024 const string* remotecat = syncRemote->getCategory(catRemote); 3061 const string* remotecat = syncRemote->getCategory(catRemote);
3025 //US syncRemote->insertAddressee( inRemote, false ); 3062 //US syncRemote->insertAddressee( inRemote, false );
3026 //US syncLocal->insertAddressee( inRemote, false ); 3063 //US syncLocal->insertAddressee( inRemote, false );
3027 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3064 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3028 3065
3029 ++addedPasswordsLocal; 3066 ++addedPasswordsLocal;
3030 } else { 3067 } else {
3031 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3068 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3032 syncRemote->delEntry(catRemote, indexRemote, true); 3069 syncRemote->delEntry(catRemote, indexRemote, true);
3033 //USsyncRemote->removeAddressee( inRemote ); 3070 //USsyncRemote->removeAddressee( inRemote );
3034 ++deletedPasswordsRemote; 3071 ++deletedPasswordsRemote;
3035 } 3072 }
3036 } 3073 }
3037 3074
3038 ++incCounter; 3075 ++incCounter;
3039 } 3076 }
3040 3077
3041 3078
3042 er.clear(); 3079 er.clear();
3043 QStringList el = syncLocal->getIDEntryList(); 3080 QStringList el = syncLocal->getIDEntryList();
3044 modulo = (el.count()/10)+1; 3081 modulo = (el.count()/10)+1;
3045 3082
3046 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3083 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3047 incCounter = 0; 3084 incCounter = 0;
3048 while ( incCounter < el.count()) { 3085 while ( incCounter < el.count()) {
3049 qApp->processEvents(); 3086 qApp->processEvents();
3050 if (manager->isProgressBarCanceled()) 3087 if (manager->isProgressBarCanceled())
3051 return e_syncError; 3088 return e_syncError;
3052 if ( incCounter % modulo == 0 ) 3089 if ( incCounter % modulo == 0 )
3053 manager->showProgressBar(incCounter); 3090 manager->showProgressBar(incCounter);
3054 uid = el[ incCounter ]; 3091 uid = el[ incCounter ];
3092 qDebug("sync uid %s from local file", uid.latin1());
3055 3093
3056 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3094 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3057 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3095 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3058 PWM_ASSERT(inLocal); 3096 PWM_ASSERT(inLocal);
3059 3097
3060 if ( inRemote == 0 ) { 3098 if ( inRemote == 0 ) {
3061 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3099 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3062 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3100 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3063 syncLocal->delEntry(catLocal, indexLocal, true); 3101 syncLocal->delEntry(catLocal, indexLocal, true);
3064 //USsyncLocal->removeAddressee( inLocal ); 3102 //USsyncLocal->removeAddressee( inLocal );
3065 ++deletedPasswordsLocal; 3103 ++deletedPasswordsLocal;
3066 } else { 3104 } else {
3067 if ( ! manager->mWriteBackExistingOnly ) { 3105 if ( ! manager->mWriteBackExistingOnly ) {
3068 ++addedPasswordsRemote; 3106 ++addedPasswordsRemote;
3069 inLocal->meta.update = modifiedSync; 3107 inLocal->meta.update = modifiedSync;
3070 3108
3071 //first check if we have a matching category in the remote file 3109 //first check if we have a matching category in the remote file
3072 const string* localcat = syncLocal->getCategory(catLocal); 3110 const string* localcat = syncLocal->getCategory(catLocal);
3073 3111
3074 //USsyncLocal->insertAddressee( inLocal, false ); 3112 //USsyncLocal->insertAddressee( inLocal, false );
3075 PwMDataItem newEntry; 3113 PwMDataItem newEntry;
3076 newEntry = *inLocal; 3114 newEntry = *inLocal;
3077 inRemote = &newEntry; 3115 inRemote = &newEntry;
3078 3116
3079 //USsyncRemote->insertAddressee( inRemote, false ); 3117 //USsyncRemote->insertAddressee( inRemote, false );
3080 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3118 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3081 3119
3082 } 3120 }
3083 } 3121 }
3084 3122
3085 } 3123 }
3086 ++incCounter; 3124 ++incCounter;
3087 } 3125 }
3088 el.clear(); 3126 el.clear();
3089 manager->hideProgressBar(); 3127 manager->hideProgressBar();
3090 3128
3091 // Now write the info back into the sync data space of the files 3129 // Now write the info back into the sync data space of the files
3092 3130
3093 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3131 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3094 // get rid of micro seconds 3132 // get rid of micro seconds
3095 QTime t = mLastSync.time(); 3133 QTime t = mLastSync.time();
3096 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3134 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3097 3135
3098 3136
3099 syncItemLocal->lastSyncDate = mLastSync; 3137 syncItemLocal->lastSyncDate = mLastSync;
3100 syncItemRemote->lastSyncDate = mLastSync; 3138 syncItemRemote->lastSyncDate = mLastSync;
3101 3139
3102 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 3140 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
3103 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 3141 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
3104 3142
3105 //US syncRemote->addSyncDataEntry( syncItemRemote, false ); 3143 //US syncRemote->addSyncDataEntry( syncItemRemote, false );
3106 //US syncLocal->addSyncDataEntry( syncItemLocal, false ); 3144 //US syncLocal->addSyncDataEntry( syncItemLocal, false );
3107 QString mes; 3145 QString mes;
3108 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); 3146 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
3109 if ( manager->mShowSyncSummary ) { 3147 if ( manager->mShowSyncSummary ) {
3110 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3148 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3111 } 3149 }
3112 qDebug( mes ); 3150 qDebug( mes );
3113 return e_success; 3151 return e_success;
3114} 3152}
3115 3153
3116 3154
3117int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3155int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3118{ 3156{
3119 // 0 equal 3157 // 0 equal
3120 // 1 take local 3158 // 1 take local
3121 // 2 take remote 3159 // 2 take remote
3122 // 3 cancel 3160 // 3 cancel
3123 QDateTime localMod = local->meta.update; 3161 QDateTime localMod = local->meta.update;
3124 QDateTime remoteMod = remote->meta.update; 3162 QDateTime remoteMod = remote->meta.update;
3125 3163
3126 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3164 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3127 3165
3128 if ( localMod == remoteMod ) 3166 if ( localMod == remoteMod )
3129 return 0; 3167 return 0;
3130 3168
3131 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3169 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3132 3170
3133 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3171 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3134 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3172 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3135 //full = true; //debug only 3173 full = true; //debug only
3136 if ( full ) { 3174 if ( full ) {
3137 bool equ = true;//US ( (*local) == (*remote) ); 3175 bool equ = ( (*local) == (*remote) );
3138 if ( equ ) { 3176 if ( equ ) {
3139 //qDebug("equal "); 3177 qDebug("equal ");
3140 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3178 if ( mode < SYNC_PREF_FORCE_LOCAL )
3141 return 0; 3179 return 0;
3142 3180
3143 }//else //debug only 3181 }else //debug only
3144 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 3182 qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3145 } 3183 }
3146 3184
3147 int result; 3185 int result;
3148 bool localIsNew; 3186 bool localIsNew;
3149 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 3187 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
3150 3188
3151 if ( full && mode < SYNC_PREF_NEWEST ) 3189 if ( full && mode < SYNC_PREF_NEWEST )
3152 mode = SYNC_PREF_ASK; 3190 mode = SYNC_PREF_ASK;
3153 3191
3154 switch( mode ) { 3192 switch( mode ) {
3155 case SYNC_PREF_LOCAL: 3193 case SYNC_PREF_LOCAL:
3156 if ( lastSync > remoteMod ) 3194 if ( lastSync > remoteMod )
3157 return 1; 3195 return 1;
3158 if ( lastSync > localMod ) 3196 if ( lastSync > localMod )
3159 return 2; 3197 return 2;
3160 return 1; 3198 return 1;
3161 break; 3199 break;
3162 case SYNC_PREF_REMOTE: 3200 case SYNC_PREF_REMOTE:
3163 if ( lastSync > remoteMod ) 3201 if ( lastSync > remoteMod )
3164 return 1; 3202 return 1;
3165 if ( lastSync > localMod ) 3203 if ( lastSync > localMod )
3166 return 2; 3204 return 2;
3167 return 2; 3205 return 2;
3168 break; 3206 break;
3169 case SYNC_PREF_NEWEST: 3207 case SYNC_PREF_NEWEST:
3170 if ( localMod > remoteMod ) 3208 if ( localMod > remoteMod )
3171 return 1; 3209 return 1;
3172 else 3210 else
3173 return 2; 3211 return 2;
3174 break; 3212 break;
3175 case SYNC_PREF_ASK: 3213 case SYNC_PREF_ASK:
3176 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3214 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3177 if ( lastSync > remoteMod ) 3215 if ( lastSync > remoteMod )
3178 return 1; 3216 return 1;
3179 if ( lastSync > localMod ) 3217 if ( lastSync > localMod )
3180 return 2; 3218 return 2;
3181 localIsNew = localMod >= remoteMod; 3219 localIsNew = localMod >= remoteMod;
3182 //qDebug("conflict! ************************************** "); 3220 //qDebug("conflict! ************************************** ");
3183 { 3221 {
3184 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3222 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3185 result = acd.executeD(localIsNew); 3223 result = acd.executeD(localIsNew);
3186 return result; 3224 return result;
3187 } 3225 }
3188 break; 3226 break;
3189 case SYNC_PREF_FORCE_LOCAL: 3227 case SYNC_PREF_FORCE_LOCAL:
3190 return 1; 3228 return 1;
3191 break; 3229 break;
3192 case SYNC_PREF_FORCE_REMOTE: 3230 case SYNC_PREF_FORCE_REMOTE:
3193 return 2; 3231 return 2;
3194 break; 3232 break;
3195 3233
3196 default: 3234 default:
3197 // SYNC_PREF_TAKE_BOTH not implemented 3235 // SYNC_PREF_TAKE_BOTH not implemented
3198 break; 3236 break;
3199 } 3237 }
3200 return 0; 3238 return 0;
3201} 3239}
3202 3240
3203 3241
3204 3242
3205 3243
3206//this are the overwritten callbackmethods from the syncinterface 3244//this are the overwritten callbackmethods from the syncinterface
3207bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3245bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3208{ 3246{
3209 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3247 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3210 3248
3211 //1) unlock local file first if necessary (ask for password) 3249 //1) unlock local file first if necessary (ask for password)
3212 if (this->isDeepLocked()) { 3250 if (this->isDeepLocked()) {
3213 PwMerror ret = this->deepLock(false); 3251 PwMerror ret = this->deepLock(false);
3214 if (ret != e_success) 3252 if (ret != e_success)
3215 return false; 3253 return false;
3216 } 3254 }
3217 3255
3218 //2) construct and open a new doc on the stack(automatic cleanup) for remote file. 3256 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3219 PwMDoc syncTarget(this, "synctarget"); 3257 PwMDoc syncTarget(this, "synctarget");
3220 PwMDoc* pSyncTarget = &syncTarget; 3258 PwMDoc* pSyncTarget = &syncTarget;
3221 3259
3222 3260
3223 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3261 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3224 3262
3225 if (err == e_alreadyOpen) { 3263 if (err == e_alreadyOpen) {
3226 PwMDocList::listItem li; 3264 PwMDocList::listItem li;
3227 if (getOpenDocList()->find(filename.latin1(), &li)) 3265 if (getOpenDocList()->find(filename.latin1(), &li))
3228 pSyncTarget = li.doc; 3266 pSyncTarget = li.doc;
3229 else { 3267 else {
3230 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3268 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3231 return false; 3269 return false;
3232 } 3270 }
3233 } 3271 }
3234 else if (err != e_success) { 3272 else if (err != e_success) {
3235 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3273 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3236 return false; 3274 return false;
3237 } 3275 }
3238 3276
3239 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3277 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3240 3278
3241 3279
3242 //3) unlock remote file first if necessary (ask for password) 3280 //3) unlock remote file first if necessary (ask for password)
3243 if (pSyncTarget->isDeepLocked()) { 3281 if (pSyncTarget->isDeepLocked()) {
3244 PwMerror ret = pSyncTarget->deepLock(false); 3282 PwMerror ret = pSyncTarget->deepLock(false);
3245 if (ret != e_success) 3283 if (ret != e_success)
3246 return false; 3284 return false;
3247 } 3285 }
3248 3286
3249 3287
3250 err = syncronize(manager, this, pSyncTarget, mode ); 3288 err = syncronize(manager, this, pSyncTarget, mode );
3251 3289
3252 if (err == e_success) { 3290 if (err == e_success) {
3253 if ( manager->mWriteBackFile ){ 3291 if ( manager->mWriteBackFile ){
3254 qDebug("Saving remote PWManager file"); 3292 qDebug("Saving remote PWManager file");
3255 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3293 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3256 if (err != e_success) { 3294 if (err != e_success) {
3257 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3295 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3258 return false; 3296 return false;
3259 } 3297 }
3260 } 3298 }
3261 3299
3262 flagDirty(); 3300 flagDirty();
3263 return true; 3301 return true;
3264 } 3302 }
3265 else { 3303 else {
3266 return false; 3304 return false;
3267 } 3305 }
3268} 3306}
3269 3307
3270//called by the syncmanager to indicate that the work has to marked as dirty.
3271void PwMDoc::sync_setModified()
3272{
3273 flagDirty();
3274}
3275
3276//called by the syncmanager to ask if the dirty flag is set.
3277bool PwMDoc::sync_isModified()
3278{
3279 return isDirty();
3280}
3281
3282//called by the syncmanager to indicate that the work has to be saved.
3283void PwMDoc::sync_save()
3284{
3285 saveDoc(conf()->confGlobCompression());
3286}
3287#endif 3308#endif
3288 3309
3289 3310
3290bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3311bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3291{ 3312{
3292 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3313 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3293 end = dti.syncDta.end(); 3314 end = dti.syncDta.end();
3294 3315
3295 while (i != end) { 3316 while (i != end) {
3296 if ((*i).syncName == syncname.latin1()) { 3317 if ((*i).syncName == syncname.latin1()) {
3297 if (index) { 3318 if (index) {
3298 *index = i - dti.syncDta.begin(); 3319 *index = i - dti.syncDta.begin();
3299 } 3320 }
3300 return true; 3321 return true;
3301 } 3322 }
3302 ++i; 3323 ++i;
3303 } 3324 }
3304 return false; 3325 return false;
3305}; 3326};
3306 3327
3307/** add new syncdataentry */ 3328/** add new syncdataentry */
3308PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3329PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3309{ 3330{
3310 PWM_ASSERT(d); 3331 PWM_ASSERT(d);
3311 3332
3312 if (isDeepLocked()) { 3333 if (isDeepLocked()) {
3313 PwMerror ret; 3334 PwMerror ret;
3314 ret = deepLock(false); 3335 ret = deepLock(false);
3315 if (ret != e_success) 3336 if (ret != e_success)
3316 return e_lock; 3337 return e_lock;
3317 } 3338 }
3318 unsigned int index; 3339 unsigned int index;
3319 3340
3320 const QString tmp = d->syncName.c_str(); 3341 const QString tmp = d->syncName.c_str();
3321 bool exists = findSyncData(d->syncName.c_str(), &index); 3342 bool exists = findSyncData(d->syncName.c_str(), &index);
3322 3343
3323 if (exists == true) { 3344 if (exists == true) {
3324 // DOH! We found this entry. 3345 // DOH! We found this entry.
3325 return e_entryExists; 3346 return e_entryExists;
3326 } 3347 }
3327 3348
3328 dti.syncDta.push_back(*d); 3349 dti.syncDta.push_back(*d);
3329 3350
3330 if (!dontFlagDirty) 3351 if (!dontFlagDirty)
3331 flagDirty(); 3352 flagDirty();
3332 return e_success; 3353 return e_success;
3333} 3354}
3334 3355
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 2e9547e..6a1dd30 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -85,195 +85,201 @@ using std::pair;
85 #define DOC_STAT_DEEPLOCKED (1) 85 #define DOC_STAT_DEEPLOCKED (1)
86/** encrypted document on disk is dirty. data has to go to disk. */ 86/** encrypted document on disk is dirty. data has to go to disk. */
87 #define DOC_STAT_DISK_DIRTY (1 << 1) 87 #define DOC_STAT_DISK_DIRTY (1 << 1)
88/** we are using a chipcard to encrypt the data */ 88/** we are using a chipcard to encrypt the data */
89 #define DOC_STAT_USE_CHIPCARD (1 << 2) 89 #define DOC_STAT_USE_CHIPCARD (1 << 2)
90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 90/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 91 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
92 92
93class PwMDoc; 93class PwMDoc;
94class PwMView; 94class PwMView;
95class QFile; 95class QFile;
96 96
97/* meta data for a PwMDataItem */ 97/* meta data for a PwMDataItem */
98struct PwMMetaData 98struct PwMMetaData
99{ 99{
100 PwMMetaData() 100 PwMMetaData()
101 : updateInt (0) 101 : updateInt (0)
102 { } 102 { }
103 /** creation date of the PwMDataItem to which 103 /** creation date of the PwMDataItem to which
104 * this meta data belongs. 104 * this meta data belongs.
105 */ 105 */
106 QDateTimecreate; 106 QDateTimecreate;
107 /** becomes valid on this date */ 107 /** becomes valid on this date */
108 QDateTimevalid; 108 QDateTimevalid;
109 /** expire date */ 109 /** expire date */
110 QDateTimeexpire; 110 QDateTimeexpire;
111 /** update date (last updated at this date) */ 111 /** update date (last updated at this date) */
112 QDateTimeupdate; 112 QDateTimeupdate;
113 /** update interval (in minutes). Time since the 113 /** update interval (in minutes). Time since the
114 * last update to remind the user to update the item. 114 * last update to remind the user to update the item.
115 * 0 disables. 115 * 0 disables.
116 */ 116 */
117 unsigned long updateInt; 117 unsigned long updateInt;
118 118
119 //US ENH: enhancements of the filestructure 119 //US ENH: enhancements of the filestructure
120 /* each entry gets a unique id assigned */ 120 /* each entry gets a unique id assigned */
121 string uniqueid; 121 string uniqueid;
122 122
123 123
124 void clear() 124 void clear()
125 { 125 {
126 create = QDateTime(); 126 create = QDateTime();
127 expire = QDateTime(); 127 expire = QDateTime();
128 update = QDateTime(); 128 update = QDateTime();
129 updateInt = 0; 129 updateInt = 0;
130 uniqueid = KApplication::randomString(8); 130 uniqueid = KApplication::randomString(8);
131 } 131 }
132 132
133 PwMMetaData& operator = (const PwMMetaData& x)
134 {
135 create = x.create;
136 expire = x.expire;
137 update = x.update;
138 updateInt = x.updateInt;
139 uniqueid = x.uniqueid;
140 return *this;
141 }
142
143 inline bool isValid() const 133 inline bool isValid() const
144 { 134 {
145 if (valid.isNull()) 135 if (valid.isNull())
146 return true; 136 return true;
147 return (valid < QDateTime::currentDateTime()); 137 return (valid < QDateTime::currentDateTime());
148 } 138 }
149 inline bool isExpired() const 139 inline bool isExpired() const
150 { 140 {
151 if (expire.isNull()) 141 if (expire.isNull())
152 return false; 142 return false;
153 return (expire < QDateTime::currentDateTime()); 143 return (expire < QDateTime::currentDateTime());
154 } 144 }
155 inline bool isUpdateIntOver() const 145 inline bool isUpdateIntOver() const
156 { 146 {
157 if (updateInt == 0 || 147 if (updateInt == 0 ||
158 update.isNull()) 148 update.isNull())
159 return false; 149 return false;
160 QDateTime d(update); 150 QDateTime d(update);
161 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 151 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
162 } 152 }
163}; 153};
164 154
165struct PwMDataItem 155struct PwMDataItem
166{ 156{
167 PwMDataItem() 157 PwMDataItem()
168 : lockStat (true) 158 : lockStat (true)
169 , listViewPos (-1) 159 , listViewPos (-1)
170 , binary (false) 160 , binary (false)
171 , rev (0) 161 , rev (0)
172 { } 162 { }
173 163
174 /** password description */ 164 /** password description */
175 stringdesc; 165 stringdesc;
176 /** user-name */ 166 /** user-name */
177 stringname; 167 stringname;
178 /** the password itself */ 168 /** the password itself */
179 stringpw; 169 stringpw;
180 /** some comment */ 170 /** some comment */
181 stringcomment; 171 stringcomment;
182 /** an URL string */ 172 /** an URL string */
183 stringurl; 173 stringurl;
184 /** launcher. Can be executed as a system() command */ 174 /** launcher. Can be executed as a system() command */
185 stringlauncher; 175 stringlauncher;
186 /** locking status. If locked (true), pw is not emitted through getEntry() */ 176 /** locking status. If locked (true), pw is not emitted through getEntry() */
187 boollockStat; 177 boollockStat;
188 /** position of this item in main "list-view" 178 /** position of this item in main "list-view"
189 * If -1, the position is not yet specified and should be appended to the list 179 * If -1, the position is not yet specified and should be appended to the list
190 */ 180 */
191 intlistViewPos; 181 intlistViewPos;
192 /** does this entry contain binary data? */ 182 /** does this entry contain binary data? */
193 bool binary; 183 bool binary;
194 /** meta data for this data item. */ 184 /** meta data for this data item. */
195 PwMMetaData meta; 185 PwMMetaData meta;
196 /** data revision counter. This counter can be used 186 /** data revision counter. This counter can be used
197 * to easily, efficiently determine if this data item 187 * to easily, efficiently determine if this data item
198 * has changed since some time. 188 * has changed since some time.
199 * This counter is incremented on every update. 189 * This counter is incremented on every update.
200 */ 190 */
201 unsigned int rev; 191 unsigned int rev;
202 192
203 void clear(bool clearMeta = true) 193 void clear(bool clearMeta = true)
204 { 194 {
205 /* NOTE: Don't use .clear() here to be 195 /* NOTE: Don't use .clear() here to be
206 * backward compatible with gcc-2 (Debian Woody) 196 * backward compatible with gcc-2 (Debian Woody)
207 */ 197 */
208 desc = ""; 198 desc = "";
209 name = ""; 199 name = "";
210 pw = ""; 200 pw = "";
211 comment = ""; 201 comment = "";
212 url = ""; 202 url = "";
213 launcher = ""; 203 launcher = "";
214 lockStat = true; 204 lockStat = true;
215 listViewPos = -1; 205 listViewPos = -1;
216 binary = false; 206 binary = false;
217 if (clearMeta) 207 if (clearMeta)
218 meta.clear(); 208 meta.clear();
219 } 209 }
220 210 //US ENH: we need this operator to compare two items if we have no unique ids
211 //available. Generaly this happens before the first sync
212 bool PwMDataItem::operator==( const PwMDataItem &a ) const
213 {
214 qDebug("oper==%s", a.desc.c_str());
215 if ( desc != a.desc ) return false;
216 if ( name != a.name ) return false;
217 if ( pw != a.pw ) return false;
218 if ( comment != a.comment ) return false;
219 if ( url != a.url ) return false;
220 if ( launcher != a.launcher ) return false;
221 //all other field will not be checked.
222 return true;
223 }
224
225 //US ENH:this operator is used to copy an elements data during syncronization
226 //Attention: listViewPos will not be copied. So the position will stay the same.
221 PwMDataItem& operator = (const PwMDataItem& x) 227 PwMDataItem& operator = (const PwMDataItem& x)
222 { 228 {
223 qDebug("oper=%s", x.desc.c_str()); 229 // qDebug("oper=%s", x.desc.c_str());
224 desc = x.desc; 230 desc = x.desc;
225 name = x.name; 231 name = x.name;
226 pw = x.pw; 232 pw = x.pw;
227 comment = x.comment; 233 comment = x.comment;
228 url = x.url; 234 url = x.url;
229 launcher = x.launcher; 235 launcher = x.launcher;
230 lockStat = x.lockStat; 236 lockStat = x.lockStat;
231 listViewPos = x.listViewPos; 237 //Do not copy listViewPos!!! listViewPos = x.listViewPos;
232 binary = x.binary; 238 binary = x.binary;
233 meta = x.meta; 239 meta = x.meta;
234 rev = x.rev; 240 rev = x.rev;
235 return *this; 241 return *this;
236 } 242 }
237 243
238}; 244};
239 245
240struct PwMCategoryItem 246struct PwMCategoryItem
241{ 247{
242 /** all PwMDataItems (all passwords) within this category */ 248 /** all PwMDataItems (all passwords) within this category */
243 vector<PwMDataItem>d; 249 vector<PwMDataItem>d;
244 /** category name/description */ 250 /** category name/description */
245 string name; 251 string name;
246 252
247 void clear() 253 void clear()
248 { 254 {
249 d.clear(); 255 d.clear();
250 name = ""; 256 name = "";
251 } 257 }
252}; 258};
253 259
254struct PwMSyncItem 260struct PwMSyncItem
255{ 261{
256 string syncName; 262 string syncName;
257 QDateTime lastSyncDate; 263 QDateTime lastSyncDate;
258 264
259 void clear() 265 void clear()
260 { 266 {
261 lastSyncDate = QDateTime(); 267 lastSyncDate = QDateTime();
262 syncName = ""; 268 syncName = "";
263 } 269 }
264}; 270};
265 271
266struct PwMItem 272struct PwMItem
267{ 273{
268 vector<PwMCategoryItem> dta; 274 vector<PwMCategoryItem> dta;
269 vector<PwMSyncItem> syncDta; 275 vector<PwMSyncItem> syncDta;
270 276
271 void clear() 277 void clear()
272 { 278 {
273 dta.clear(); 279 dta.clear();
274 syncDta.clear(); 280 syncDta.clear();
275 } 281 }
276}; 282};
277 283
278 284
279/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 285/** "Function Object" for sort()ing PwMDataItem::listViewPos */
@@ -729,78 +735,71 @@ protected:
729 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 735 * If this is not a valid PwM-exported file, it returns e_fileFormat */
730 PwMerror importText_PwM(const QString *file); 736 PwMerror importText_PwM(const QString *file);
731 /** PwM-text-import helper function to extract the name/pw/comment out 737 /** PwM-text-import helper function to extract the name/pw/comment out
732 * of one entry-line */ 738 * of one entry-line */
733 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 739 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
734 /** compare two strings */ 740 /** compare two strings */
735 bool compareString(const string &s1, const string &s2, bool caseSensitive, 741 bool compareString(const string &s1, const string &s2, bool caseSensitive,
736 bool exactWordMatch); 742 bool exactWordMatch);
737 /** clears all document-data */ 743 /** clears all document-data */
738 void clearDoc(); 744 void clearDoc();
739 /** delete all empty categories */ 745 /** delete all empty categories */
740 void delAllEmptyCat(bool dontFlagDirty); 746 void delAllEmptyCat(bool dontFlagDirty);
741 /** set a document status flag */ 747 /** set a document status flag */
742 void setDocStatFlag(unsigned int statFlag) 748 void setDocStatFlag(unsigned int statFlag)
743 { curDocStat |= statFlag; } 749 { curDocStat |= statFlag; }
744 /** unset a document status flag */ 750 /** unset a document status flag */
745 void unsetDocStatFlag(unsigned int statFlag) 751 void unsetDocStatFlag(unsigned int statFlag)
746 { curDocStat &= ~statFlag; } 752 { curDocStat &= ~statFlag; }
747 /** get a document status flag */ 753 /** get a document status flag */
748 bool getDocStatFlag(unsigned int statFlag) const 754 bool getDocStatFlag(unsigned int statFlag) const
749 { return (curDocStat & statFlag); } 755 { return (curDocStat & statFlag); }
750 /** set the "currentPassword" */ 756 /** set the "currentPassword" */
751 void setCurrentPw(const QString &pw) 757 void setCurrentPw(const QString &pw)
752 { 758 {
753 currentPw = pw; 759 currentPw = pw;
754 setDocStatFlag(DOC_STAT_DISK_DIRTY); 760 setDocStatFlag(DOC_STAT_DISK_DIRTY);
755 } 761 }
756 /** make a backup-copy of the given file */ 762 /** make a backup-copy of the given file */
757 bool backupFile(const QString &filePath); 763 bool backupFile(const QString &filePath);
758 /** copy a file from src to dst */ 764 /** copy a file from src to dst */
759 bool copyFile(const QString &src, const QString &dst); 765 bool copyFile(const QString &src, const QString &dst);
760 766
761 767
762 public: 768 public:
763#ifdef PWM_EMBEDDED 769#ifdef PWM_EMBEDDED
764 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 770 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
765 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 771 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
766 772
767 //takePwMDataItem returns the following values 773 //takePwMDataItem returns the following values
768 // 0 equal 774 // 0 equal
769 // 1 take local 775 // 1 take local
770 // 2 take remote 776 // 2 take remote
771 // 3 cancel 777 // 3 cancel
772 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 778 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
773 779
774 //the following methods are the overwritten callbackmethods from the syncinterface 780 //the following methods are the overwritten callbackmethods from the syncinterface
775 virtual bool sync(KSyncManager* manager, QString filename, int mode); 781 virtual bool sync(KSyncManager* manager, QString filename, int mode);
776 782
777 //called by the syncmanager to indicate that the work has to be marked as dirty.
778 virtual void sync_setModified();
779 //called by the syncmanager to ask if the dirty flag is set.
780 virtual bool sync_isModified();
781 //called by the syncmanager to indicate that the work has to be saved.
782 virtual void sync_save();
783
784#endif 783#endif
785 private: 784 private:
786 //US ENH: helpermethods to access the sync data for a certain syncname. 785 //US ENH: helpermethods to access the sync data for a certain syncname.
787 // It returns the syncdatas index 786 // It returns the syncdatas index
788 bool findSyncData(const QString &syncname, unsigned int *index); 787 bool findSyncData(const QString &syncname, unsigned int *index);
789 788
790 /** add new syncdataentry */ 789 /** add new syncdataentry */
791 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 790 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
792 791
793 /** returns a pointer to the syncdata */ 792 /** returns a pointer to the syncdata */
794 PwMSyncItem* getSyncDataEntry(unsigned int index) 793 PwMSyncItem* getSyncDataEntry(unsigned int index)
795 { return &(dti.syncDta[index]); } 794 { return &(dti.syncDta[index]); }
796 795
797 /** delete entry */ 796 /** delete entry */
798 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 797 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
799 798
800 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 799 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
801 800
802 QStringList getIDEntryList(); 801 QStringList getIDEntryList();
803 802
804}; 803};
805 804
806#endif 805#endif
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp
index e23ce25..e53124f 100644
--- a/pwmanager/pwmanager/pwmview.cpp
+++ b/pwmanager/pwmanager/pwmview.cpp
@@ -411,114 +411,194 @@ void PwMView::copyNameToClip()
411void PwMView::copyDescToClip() 411void PwMView::copyDescToClip()
412{ 412{
413 if (doc->isDeepLocked()) 413 if (doc->isDeepLocked())
414 return; 414 return;
415 unsigned int curIndex = 0; 415 unsigned int curIndex = 0;
416 if (!getCurEntryIndex(&curIndex)) 416 if (!getCurEntryIndex(&curIndex))
417 return; 417 return;
418 PwMDataItem d; 418 PwMDataItem d;
419 document()->getEntry(getCurrentCategory(), curIndex, &d); 419 document()->getEntry(getCurrentCategory(), curIndex, &d);
420 PwM::copyToClipboard(d.desc.c_str()); 420 PwM::copyToClipboard(d.desc.c_str());
421} 421}
422 422
423void PwMView::copyUrlToClip() 423void PwMView::copyUrlToClip()
424{ 424{
425 if (doc->isDeepLocked()) 425 if (doc->isDeepLocked())
426 return; 426 return;
427 unsigned int curIndex = 0; 427 unsigned int curIndex = 0;
428 if (!getCurEntryIndex(&curIndex)) 428 if (!getCurEntryIndex(&curIndex))
429 return; 429 return;
430 PwMDataItem d; 430 PwMDataItem d;
431 document()->getEntry(getCurrentCategory(), curIndex, &d); 431 document()->getEntry(getCurrentCategory(), curIndex, &d);
432 PwM::copyToClipboard(d.url.c_str()); 432 PwM::copyToClipboard(d.url.c_str());
433} 433}
434 434
435void PwMView::copyLauncherToClip() 435void PwMView::copyLauncherToClip()
436{ 436{
437 if (doc->isDeepLocked()) 437 if (doc->isDeepLocked())
438 return; 438 return;
439 unsigned int curIndex = 0; 439 unsigned int curIndex = 0;
440 if (!getCurEntryIndex(&curIndex)) 440 if (!getCurEntryIndex(&curIndex))
441 return; 441 return;
442 PwMDataItem d; 442 PwMDataItem d;
443 document()->getEntry(getCurrentCategory(), curIndex, &d); 443 document()->getEntry(getCurrentCategory(), curIndex, &d);
444 PwM::copyToClipboard(d.launcher.c_str()); 444 PwM::copyToClipboard(d.launcher.c_str());
445} 445}
446 446
447void PwMView::copyCommentToClip() 447void PwMView::copyCommentToClip()
448{ 448{
449 if (doc->isDeepLocked()) 449 if (doc->isDeepLocked())
450 return; 450 return;
451 unsigned int curIndex = 0; 451 unsigned int curIndex = 0;
452 if (!getCurEntryIndex(&curIndex)) 452 if (!getCurEntryIndex(&curIndex))
453 return; 453 return;
454 PwMDataItem d; 454 PwMDataItem d;
455 document()->getEntry(getCurrentCategory(), curIndex, &d); 455 document()->getEntry(getCurrentCategory(), curIndex, &d);
456 PwM::copyToClipboard(d.comment.c_str()); 456 PwM::copyToClipboard(d.comment.c_str());
457} 457}
458 458
459/************************************************************************
460 *
461 *
462 *
463 ************************************************************************/
464
465
466PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name )
467 : QTextBrowser( parent, name )
468
469
470{
471//US setWrapPolicy( QTextEdit::AtWordBoundary );
472 setLinkUnderline( false );
473 // setVScrollBarMode( QScrollView::AlwaysOff );
474 //setHScrollBarMode( QScrollView::AlwaysOff );
475
476//US QStyleSheet *sheet = styleSheet();
477//US QStyleSheetItem *link = sheet->item( "a" );
478//US link->setColor( KGlobalSettings::linkColor() );
479
480}
481
482void PwMDataItemView::setPwMDataItem( const PwMDataItem& a )
483
484{
485 mItem = a;
486 // clear view
487 setText( QString::null );
488
489
490 QString dynamicPart;
491 QString format = "<tr><td align=\"right\"><b>%1</b></td>"
492 "<td align=\"left\">%2</td></tr>";
493
494 dynamicPart += format
495 .arg( i18n("Description") )
496 .arg( mItem.desc.c_str() );
459 497
498 dynamicPart += format
499 .arg( i18n("Name") )
500 .arg( mItem.name.c_str() );
501
502 dynamicPart += format
503 .arg( i18n("Password") )
504 .arg( mItem.pw.c_str() );
505
506 QString comment(mItem.pw.c_str());
507 dynamicPart += format
508 .arg( i18n("Comment") )
509 .arg( comment.replace( QRegExp("\n"), "<br>" ) );
510
511 dynamicPart += format
512 .arg( i18n("URL") )
513 .arg( mItem.url.c_str() );
514
515 dynamicPart += format
516 .arg( i18n("Launcher") )
517 .arg( mItem.launcher.c_str() );
518
519 QString mText = "<table><td colspan=\"2\">&nbsp;</td>";
520
521 mText += dynamicPart;
522 mText += "</table>";
523
524 // at last display it...
525 setText( mText );
526
527}
528
529PwMDataItem PwMDataItemView::pwmdataitem() const
530{
531 return mItem;
532}
533
534/************************************************************************
535 *
536 *
537 *
538 ************************************************************************/
460 539
461 540
462PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, 541PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name )
463 true ,i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) 542 : KDialogBase(parent, name, true ,
543 i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false)
464{ 544{
465 findButton( Close )->setText( i18n("Cancel Sync")); 545 findButton( Close )->setText( i18n("Cancel Sync"));
466 findButton( Ok )->setText( i18n("Remote")); 546 findButton( Ok )->setText( i18n("Remote"));
467 findButton( User1 )->setText( i18n("Local")); 547 findButton( User1 )->setText( i18n("Local"));
468 QWidget* topframe = new QWidget( this ); 548 QWidget* topframe = new QWidget( this );
469 setMainWidget( topframe ); 549 setMainWidget( topframe );
470 QBoxLayout* bl; 550 QBoxLayout* bl;
471 if ( QApplication::desktop()->width() < 640 ) { 551 if ( QApplication::desktop()->width() < 640 ) {
472 bl = new QVBoxLayout( topframe ); 552 bl = new QVBoxLayout( topframe );
473 } else { 553 } else {
474 bl = new QHBoxLayout( topframe ); 554 bl = new QHBoxLayout( topframe );
475 } 555 }
476 QVBox* subframe = new QVBox( topframe ); 556 QVBox* subframe = new QVBox( topframe );
477 bl->addWidget(subframe ); 557 bl->addWidget(subframe );
478 QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); 558 QLabel* lab = new QLabel( i18n("Local Entry"), subframe );
479 if ( takeloc ) 559 if ( takeloc )
480 lab->setBackgroundColor(Qt::green.light() ); 560 lab->setBackgroundColor(Qt::green.light() );
481 // AddresseeView * av = new AddresseeView( subframe ); 561 PwMDataItemView * av = new PwMDataItemView( subframe );
482 // av->setAddressee( loc ); 562 av->setPwMDataItem( loc );
483 subframe = new QVBox( topframe ); 563 subframe = new QVBox( topframe );
484 bl->addWidget(subframe ); 564 bl->addWidget(subframe );
485 lab = new QLabel( i18n("Remote Entry"), subframe ); 565 lab = new QLabel( i18n("Remote Entry"), subframe );
486 if ( !takeloc ) 566 if ( !takeloc )
487 lab->setBackgroundColor(Qt::green.light() ); 567 lab->setBackgroundColor(Qt::green.light() );
488 // av = new AddresseeView( subframe ); 568 av = new PwMDataItemView( subframe );
489 // av->setAddressee( rem ); 569 av->setPwMDataItem( rem );
490 QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); 570 QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote()));
491 QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); 571 QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local()));
492#ifndef DESKTOP_VERSION 572#ifndef DESKTOP_VERSION
493 showMaximized(); 573 showMaximized();
494#else 574#else
495 resize ( 640, 400 ); 575 resize ( 640, 400 );
496#endif 576#endif
497} 577}
498 578
499int PwMDataItemChooser::executeD( bool local ) 579int PwMDataItemChooser::executeD( bool local )
500{ 580{
501 mSyncResult = 3; 581 mSyncResult = 3;
502 if ( local ) 582 if ( local )
503 findButton( User1 )->setFocus(); 583 findButton( User1 )->setFocus();
504 else 584 else
505 findButton( Ok )->setFocus(); 585 findButton( Ok )->setFocus();
506 exec(); 586 exec();
507 return mSyncResult; 587 return mSyncResult;
508} 588}
509void PwMDataItemChooser::slot_remote() 589void PwMDataItemChooser::slot_remote()
510{ 590{
511 mSyncResult = 2; 591 mSyncResult = 2;
512 accept(); 592 accept();
513} 593}
514void PwMDataItemChooser::slot_local() 594void PwMDataItemChooser::slot_local()
515{ 595{
516 mSyncResult = 1; 596 mSyncResult = 1;
517 accept(); 597 accept();
518} 598}
519 599
520 600
521 601
522#ifndef PWM_EMBEDDED 602#ifndef PWM_EMBEDDED
523#include "pwmview.moc" 603#include "pwmview.moc"
524#endif 604#endif
diff --git a/pwmanager/pwmanager/pwmview.h b/pwmanager/pwmanager/pwmview.h
index 75cce51..e42b17a 100644
--- a/pwmanager/pwmanager/pwmview.h
+++ b/pwmanager/pwmanager/pwmview.h
@@ -1,91 +1,92 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef PWMVIEW_H 20#ifndef PWMVIEW_H
21#define PWMVIEW_H 21#define PWMVIEW_H
22 22
23//US ENH: wouldn't it be a good idea if we could use this consts everywhere else. 23//US ENH: wouldn't it be a good idea if we could use this consts everywhere else.
24//US ENH: for examle in listviewpwm.cpp 24//US ENH: for examle in listviewpwm.cpp
25//US ENH: Because of that I transfer them into the headerfile. 25//US ENH: Because of that I transfer them into the headerfile.
26 #define COLUMN_DESC 0 26 #define COLUMN_DESC 0
27 #define COLUMN_NAME 1 27 #define COLUMN_NAME 1
28 #define COLUMN_PW 2 28 #define COLUMN_PW 2
29 #define COLUMN_URL 3 29 #define COLUMN_URL 3
30 #define COLUMN_LAUNCHER 4 30 #define COLUMN_LAUNCHER 4
31 31
32 32
33#include "listviewpwm.h" 33#include "listviewpwm.h"
34#include "pwmdoc.h" 34#include "pwmdoc.h"
35#include "pwmviewstyle.h" 35#include "pwmviewstyle.h"
36 36
37#include <kconfig.h> 37#include <kconfig.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kdialogbase.h> 39#include <kdialogbase.h>
40 40
41#include <qevent.h> 41#include <qevent.h>
42#include <qfont.h> 42#include <qfont.h>
43#include <qobject.h> 43#include <qobject.h>
44#include <qtextbrowser.h>
44 45
45#include <vector> 46#include <vector>
46#include <string> 47#include <string>
47 48
48using std::string; 49using std::string;
49using std::vector; 50using std::vector;
50 51
51class PwM; 52class PwM;
52class ConfFile; 53class ConfFile;
53class PwMStatusBar; 54class PwMStatusBar;
54 55
55 56
56/** View class for PwM */ 57/** View class for PwM */
57class PwMView : public PwMViewStyle 58class PwMView : public PwMViewStyle
58{ 59{
59 Q_OBJECT 60 Q_OBJECT
60 friend class PwMViewStyle; 61 friend class PwMViewStyle;
61public: 62public:
62 /** construtor */ 63 /** construtor */
63 PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc, 64 PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc,
64 const char *name = 0); 65 const char *name = 0);
65 /** destructor */ 66 /** destructor */
66 ~PwMView(); 67 ~PwMView();
67 68
68 /** returns pointer to the document */ 69 /** returns pointer to the document */
69 PwMDoc* document() 70 PwMDoc* document()
70 { return doc; } 71 { return doc; }
71 /** returns the index of the currently selected entry. 72 /** returns the index of the currently selected entry.
72 * (index as represented in PwMDoc !) 73 * (index as represented in PwMDoc !)
73 */ 74 */
74 bool getCurEntryIndex(unsigned int *index); 75 bool getCurEntryIndex(unsigned int *index);
75 /** returns the position of the given item in the document 76 /** returns the position of the given item in the document
76 * Note: This func only serches in the current category. 77 * Note: This func only serches in the current category.
77 */ 78 */
78 bool getDocEntryIndex(unsigned int *index, 79 bool getDocEntryIndex(unsigned int *index,
79 const QListViewItem *item); 80 const QListViewItem *item);
80 81
81public slots: 82public slots:
82 /** update the view (call if dirty) */ 83 /** update the view (call if dirty) */
83 void updateView() 84 void updateView()
84 { 85 {
85 updateCategories(); 86 updateCategories();
86 shiftToView(); 87 shiftToView();
87 } 88 }
88 /** (re)sort all items and (re)shift them to listView. */ 89 /** (re)sort all items and (re)shift them to listView. */
89 void shiftToView(); 90 void shiftToView();
90 /** handle clicking on an item */ 91 /** handle clicking on an item */
91 void handleToggle(QListViewItem *item); 92 void handleToggle(QListViewItem *item);
@@ -104,69 +105,93 @@ protected:
104 105
105protected: 106protected:
106 /** update the categories from document */ 107 /** update the categories from document */
107 void updateCategories(); 108 void updateCategories();
108 /** widget resize event */ 109 /** widget resize event */
109 void resizeEvent(QResizeEvent *); 110 void resizeEvent(QResizeEvent *);
110 /** initialize context-menu */ 111 /** initialize context-menu */
111 void initCtxMenu(); 112 void initCtxMenu();
112 /** tempoarly disable auto-sorting and user-sorting */ 113 /** tempoarly disable auto-sorting and user-sorting */
113 void tmpDisableSort() 114 void tmpDisableSort()
114 { lv->setSorting(-1); } 115 { lv->setSorting(-1); }
115 /** re-enable tempoarly disabled sorting */ 116 /** re-enable tempoarly disabled sorting */
116 void tmpReEnableSort() 117 void tmpReEnableSort()
117 { 118 {
118 lv->setSorting(lv->columns() + 1, 119 lv->setSorting(lv->columns() + 1,
119 true/*lv->sortOrder() == Qt::Ascending*/); 120 true/*lv->sortOrder() == Qt::Ascending*/);
120 } 121 }
121 /** The user pressed and released a key. */ 122 /** The user pressed and released a key. */
122 void keyReleaseEvent(QKeyEvent *e); 123 void keyReleaseEvent(QKeyEvent *e);
123 124
124protected slots: 125protected slots:
125 /** changes the comment text-edit, because a new item has been selected */ 126 /** changes the comment text-edit, because a new item has been selected */
126 void refreshCommentTextEdit(QListViewItem *curItem); 127 void refreshCommentTextEdit(QListViewItem *curItem);
127 /** copy pw to clipboard */ 128 /** copy pw to clipboard */
128 void copyPwToClip(); 129 void copyPwToClip();
129 /** copy name to clipboard */ 130 /** copy name to clipboard */
130 void copyNameToClip(); 131 void copyNameToClip();
131 /** copy desc to clipboard */ 132 /** copy desc to clipboard */
132 void copyDescToClip(); 133 void copyDescToClip();
133 /** copy url to clipboard */ 134 /** copy url to clipboard */
134 void copyUrlToClip(); 135 void copyUrlToClip();
135 /** copy launcher to clipboard */ 136 /** copy launcher to clipboard */
136 void copyLauncherToClip(); 137 void copyLauncherToClip();
137 /** copy comment to clipboard */ 138 /** copy comment to clipboard */
138 void copyCommentToClip(); 139 void copyCommentToClip();
139 /** reorganize the "listViewPos" positions in the document 140 /** reorganize the "listViewPos" positions in the document
140 * (for the current category only!) 141 * (for the current category only!)
141 */ 142 */
142 void reorgLp(); 143 void reorgLp();
143 144
144private: 145private:
145 /** document */ 146 /** document */
146 PwMDoc *doc; 147 PwMDoc *doc;
147 /** pointer to the main class "PwM" */ 148 /** pointer to the main class "PwM" */
148 PwM *mainClass; 149 PwM *mainClass;
149}; 150};
150 151
151 152
153//US ENH basic widget to view an password entry. We need it for the sync stuff.
154//But might be oif interest for other functionalities as well.
155class PwMDataItemView : public QTextBrowser
156{
157 public:
158 PwMDataItemView( QWidget *parent = 0, const char *name = 0 );
159
160 /**
161 Sets the PwMDataItem object. It is displayed immediately.
162
163 @param a The PwMDataItem object.
164 */
165 void setPwMDataItem( const PwMDataItem& a );
166
167 /**
168 Returns the current PwMDataItem object.
169 */
170 PwMDataItem pwmdataitem() const;
171
172 private:
173 PwMDataItem mItem;
174};
175
176
152//US ENH we need this chooser when syncing results in a conflict 177//US ENH we need this chooser when syncing results in a conflict
153class PwMDataItemChooser : public KDialogBase 178class PwMDataItemChooser : public KDialogBase
154{ 179{
155 Q_OBJECT 180 Q_OBJECT
156 181
157 public: 182 public:
158 PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); 183 PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 );
159 184
160 int executeD( bool local ); 185 int executeD( bool local );
161 186
162 private: 187 private:
163 int mSyncResult; 188 int mSyncResult;
164 189
165 private slots: 190 private slots:
166 void slot_remote(); 191 void slot_remote();
167 void slot_local(); 192 void slot_local();
168 193
169}; 194};
170 195
171 196
172#endif 197#endif
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index 203f82c..5c6568f 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -1,78 +1,78 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13/*************************************************************************** 13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk 14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager 15 * This file is originaly based on version 2.0 of pwmanager
16 * and was modified to run on embedded devices that run microkde 16 * and was modified to run on embedded devices that run microkde
17 * 17 *
18 * $Id$ 18 * $Id$
19 **************************************************************************/ 19 **************************************************************************/
20 20
21#include "serializer.h" 21#include "serializer.h"
22#include "pwmexception.h" 22#include "pwmexception.h"
23 23
24#ifdef PWM_EMBEDDED 24#ifdef PWM_EMBEDDED
25#include <kglobal.h> 25#include <kglobal.h>
26#include <klocale.h> 26#include <klocale.h>
27#endif 27#endif
28 28
29/* enable/disable serializer debugging (0/1) */ 29/* enable/disable serializer debugging (0/1) */
30 #define SERIALIZER_DEBUG0 30 #define SERIALIZER_DEBUG1
31/* use the old xml tags for writing (0/1) */ 31/* use the old xml tags for writing (0/1) */
32 #define USE_OLD_TAGS 0 32 #define USE_OLD_TAGS 0
33/* write a CDATA section (0/1) */ 33/* write a CDATA section (0/1) */
34 #define WRITE_CDATA_SEC 0 34 #define WRITE_CDATA_SEC 0
35 35
36 36
37 #define META_CREATE_DATE"c" 37 #define META_CREATE_DATE"c"
38 #define META_VALID_DATE "v" 38 #define META_VALID_DATE "v"
39 #define META_EXPIRE_DATE"e" 39 #define META_EXPIRE_DATE"e"
40 #define META_UPDATE_DATE"u" 40 #define META_UPDATE_DATE"u"
41 #define META_UPDATE_INT "i" 41 #define META_UPDATE_INT "i"
42//US ENH : uniqueid 42//US ENH : uniqueid
43#define META_UNIQUEID "n" 43#define META_UNIQUEID "n"
44#define SYNC_ROOT "s" 44#define SYNC_ROOT "s"
45#define SYNC_TARGET_PREFIX "t" 45#define SYNC_TARGET_PREFIX "t"
46#define SYNC_TARGET_NAME "n" 46#define SYNC_TARGET_NAME "n"
47 47
48 48
49/* This is compatibility stuff. 49/* This is compatibility stuff.
50 * The names of the entries have changed and here are the 50 * The names of the entries have changed and here are the
51 * new and old ones 51 * new and old ones
52 */ 52 */
53 #define ROOT_MAGIC_OLD "PwM-xml-dat" 53 #define ROOT_MAGIC_OLD "PwM-xml-dat"
54 #define VER_STR_OLD "ver" 54 #define VER_STR_OLD "ver"
55 #define COMPAT_VER_OLD "0x02" 55 #define COMPAT_VER_OLD "0x02"
56 #define CAT_ROOT_OLD "categories" 56 #define CAT_ROOT_OLD "categories"
57 #define CAT_PREFIX_OLD "cat_" 57 #define CAT_PREFIX_OLD "cat_"
58 #define CAT_NAME_OLD "name" 58 #define CAT_NAME_OLD "name"
59 #define ENTRY_PREFIX_OLD"entry_" 59 #define ENTRY_PREFIX_OLD"entry_"
60 #define ENTRY_DESC_OLD "desc" 60 #define ENTRY_DESC_OLD "desc"
61 #define ENTRY_NAME_OLD "name" 61 #define ENTRY_NAME_OLD "name"
62 #define ENTRY_PW_OLD "pw" 62 #define ENTRY_PW_OLD "pw"
63 #define ENTRY_COMMENT_OLD"comment" 63 #define ENTRY_COMMENT_OLD"comment"
64 #define ENTRY_URL_OLD "url" 64 #define ENTRY_URL_OLD "url"
65 #define ENTRY_LAUNCHER_OLD"launcher" 65 #define ENTRY_LAUNCHER_OLD"launcher"
66 #define ENTRY_LVP_OLD "listViewPos" 66 #define ENTRY_LVP_OLD "listViewPos"
67 #define ENTRY_BIN_OLD "b" 67 #define ENTRY_BIN_OLD "b"
68 #define ENTRY_META_OLD "m" 68 #define ENTRY_META_OLD "m"
69 69
70 #define ROOT_MAGIC_NEW "P" 70 #define ROOT_MAGIC_NEW "P"
71 #define VER_STR_NEW "v" 71 #define VER_STR_NEW "v"
72 #define COMPAT_VER_NEW "2" 72 #define COMPAT_VER_NEW "2"
73 #define CAT_ROOT_NEW "c" 73 #define CAT_ROOT_NEW "c"
74 #define CAT_PREFIX_NEW "c" 74 #define CAT_PREFIX_NEW "c"
75 #define CAT_NAME_NEW "n" 75 #define CAT_NAME_NEW "n"
76 #define ENTRY_PREFIX_NEW"e" 76 #define ENTRY_PREFIX_NEW"e"
77 #define ENTRY_DESC_NEW "d" 77 #define ENTRY_DESC_NEW "d"
78 #define ENTRY_NAME_NEW "n" 78 #define ENTRY_NAME_NEW "n"
@@ -259,96 +259,100 @@ bool Serializer::deSerialize(PwMItem *dta)
259 return true; 259 return true;
260} 260}
261 261
262bool Serializer::readCategories(const QDomNode &n, 262bool Serializer::readCategories(const QDomNode &n,
263 vector<PwMCategoryItem> *dta) 263 vector<PwMCategoryItem> *dta)
264{ 264{
265 QDomNodeList nl(n.childNodes()); 265 QDomNodeList nl(n.childNodes());
266 QDomNode cur; 266 QDomNode cur;
267 QString name; 267 QString name;
268 unsigned int numCat = nl.count(), i; 268 unsigned int numCat = nl.count(), i;
269 PwMCategoryItem curCat; 269 PwMCategoryItem curCat;
270 vector<PwMDataItem> curEntr; 270 vector<PwMDataItem> curEntr;
271 271
272 if (!numCat) { 272 if (!numCat) {
273 printDebug("Serializer::readCategories(): empty"); 273 printDebug("Serializer::readCategories(): empty");
274 return false; 274 return false;
275 } 275 }
276 for (i = 0; i < numCat; ++i) { 276 for (i = 0; i < numCat; ++i) {
277 cur = nl.item(i); 277 cur = nl.item(i);
278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW || 278 if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
279 cur.nodeName().left(4) == CAT_PREFIX_OLD) { 279 cur.nodeName().left(4) == CAT_PREFIX_OLD) {
280 name = cur.toElement().attribute(CAT_NAME_NEW); 280 name = cur.toElement().attribute(CAT_NAME_NEW);
281 if (name == QString::null) 281 if (name == QString::null)
282 name = cur.toElement().attribute(CAT_NAME_OLD); 282 name = cur.toElement().attribute(CAT_NAME_OLD);
283 PWM_ASSERT(name != QString::null); 283 PWM_ASSERT(name != QString::null);
284 PWM_ASSERT(name != ""); 284 PWM_ASSERT(name != "");
285 curCat.clear(); 285 curCat.clear();
286 curCat.name = name.latin1(); 286 curCat.name = name.latin1();
287 if (!readEntries(cur, &curEntr)) { 287 if (!readEntries(cur, &curEntr)) {
288 dta->clear(); 288 dta->clear();
289 return false; 289 return false;
290 } 290 }
291 curCat.d = curEntr; 291 curCat.d = curEntr;
292 dta->push_back(curCat); 292 dta->push_back(curCat);
293 } else { 293 } else {
294 printDebug("Serializer::readCategories(): uh? not a category?"); 294 printDebug("Serializer::readCategories(): uh? not a category?");
295 } 295 }
296 } 296 }
297 return true; 297 return true;
298} 298}
299 299
300bool Serializer::readEntries(const QDomNode &n, 300bool Serializer::readEntries(const QDomNode &n,
301 vector<PwMDataItem> *dta) 301 vector<PwMDataItem> *dta)
302{ 302{
303 QDomNodeList nl(n.childNodes()); 303 QDomNodeList nl(n.childNodes());
304 QDomNode cur; 304 QDomNode cur;
305 unsigned int numEntr = nl.count(), i; 305 unsigned int numEntr = nl.count(), i;
306 PwMDataItem curEntr; 306 PwMDataItem curEntr;
307 //US BUG: to initialize all values of curEntr with meaningfulldata,
308 // we call clear on it. Reason: Information in the file we will read might be incomplete.
309 // e.g. the metadata is missing.
310 curEntr.clear(true);
307 311
308 dta->clear(); 312 dta->clear();
309 for (i = 0; i < numEntr; ++i) { 313 for (i = 0; i < numEntr; ++i) {
310 cur = nl.item(i); 314 cur = nl.item(i);
311 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || 315 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
312 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { 316 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
313 if (!extractEntry(cur, &curEntr)) { 317 if (!extractEntry(cur, &curEntr)) {
314 return false; 318 return false;
315 } 319 }
316 dta->push_back(curEntr); 320 dta->push_back(curEntr);
317 } else { 321 } else {
318 printDebug("Serializer::readEntries(): hm? not an entry?"); 322 printDebug("Serializer::readEntries(): hm? not an entry?");
319 } 323 }
320 } 324 }
321 return true; 325 return true;
322} 326}
323 327
324bool Serializer::extractEntry(const QDomNode &n, 328bool Serializer::extractEntry(const QDomNode &n,
325 PwMDataItem *dta) 329 PwMDataItem *dta)
326{ 330{
327 QDomNodeList nl(n.childNodes()); 331 QDomNodeList nl(n.childNodes());
328 QDomNode cur, cdata; 332 QDomNode cur, cdata;
329 unsigned int cnt = nl.count(), i; 333 unsigned int cnt = nl.count(), i;
330 QString name, text; 334 QString name, text;
331 335
332 if (!cnt) { 336 if (!cnt) {
333 printDebug("Serializer::extractEntry(): empty"); 337 printDebug("Serializer::extractEntry(): empty");
334 return false; 338 return false;
335 } 339 }
336 dta->clear(); 340 dta->clear();
337 for (i = 0; i < cnt; ++i) { 341 for (i = 0; i < cnt; ++i) {
338 cur = nl.item(i); 342 cur = nl.item(i);
339 name = cur.nodeName(); 343 name = cur.nodeName();
340 cdata = cur.firstChild(); 344 cdata = cur.firstChild();
341 if (unlikely(cdata.isCDATASection())) { 345 if (unlikely(cdata.isCDATASection())) {
342 text = cdata.toCDATASection().data(); 346 text = cdata.toCDATASection().data();
343 } else if (likely(cur.isElement())) { 347 } else if (likely(cur.isElement())) {
344 text = cur.toElement().text(); 348 text = cur.toElement().text();
345 } else { 349 } else {
346 printDebug("Serializer::extractEntry(): neither CDATA nor element."); 350 printDebug("Serializer::extractEntry(): neither CDATA nor element.");
347 return false; 351 return false;
348 } 352 }
349 if (text == " ") 353 if (text == " ")
350 text = ""; // for backward compatibility. 354 text = ""; // for backward compatibility.
351 if (name == ENTRY_DESC_NEW || 355 if (name == ENTRY_DESC_NEW ||
352 name == ENTRY_DESC_OLD) { 356 name == ENTRY_DESC_OLD) {
353 dta->desc = unescapeEntryData(text).latin1(); 357 dta->desc = unescapeEntryData(text).latin1();
354 } else if (name == ENTRY_NAME_NEW || 358 } else if (name == ENTRY_NAME_NEW ||
@@ -356,140 +360,141 @@ bool Serializer::extractEntry(const QDomNode &n,
356 dta->name = unescapeEntryData(text).latin1(); 360 dta->name = unescapeEntryData(text).latin1();
357 } else if (name == ENTRY_PW_NEW || 361 } else if (name == ENTRY_PW_NEW ||
358 name == ENTRY_PW_OLD) { 362 name == ENTRY_PW_OLD) {
359 dta->pw = unescapeEntryData(text).latin1(); 363 dta->pw = unescapeEntryData(text).latin1();
360 } else if (name == ENTRY_COMMENT_NEW || 364 } else if (name == ENTRY_COMMENT_NEW ||
361 name == ENTRY_COMMENT_OLD) { 365 name == ENTRY_COMMENT_OLD) {
362 dta->comment = unescapeEntryData(text).latin1(); 366 dta->comment = unescapeEntryData(text).latin1();
363 } else if (name == ENTRY_URL_NEW || 367 } else if (name == ENTRY_URL_NEW ||
364 name == ENTRY_URL_OLD) { 368 name == ENTRY_URL_OLD) {
365 dta->url = unescapeEntryData(text).latin1(); 369 dta->url = unescapeEntryData(text).latin1();
366 } else if (name == ENTRY_LAUNCHER_NEW || 370 } else if (name == ENTRY_LAUNCHER_NEW ||
367 name == ENTRY_LAUNCHER_OLD) { 371 name == ENTRY_LAUNCHER_OLD) {
368 dta->launcher = unescapeEntryData(text).latin1(); 372 dta->launcher = unescapeEntryData(text).latin1();
369 } else if (name == ENTRY_LVP_NEW || 373 } else if (name == ENTRY_LVP_NEW ||
370 name == ENTRY_LVP_OLD) { 374 name == ENTRY_LVP_OLD) {
371 dta->listViewPos = strtol(text.latin1(), 0, 10); 375 dta->listViewPos = strtol(text.latin1(), 0, 10);
372 } else if (name == ENTRY_BIN_NEW) { 376 } else if (name == ENTRY_BIN_NEW) {
373 // ENTRY_BIN_NEW == ENTRY_BIN_OLD 377 // ENTRY_BIN_NEW == ENTRY_BIN_OLD
374 if (text == "0") { 378 if (text == "0") {
375 dta->binary = false; 379 dta->binary = false;
376 } else { 380 } else {
377 dta->binary = true; 381 dta->binary = true;
378 } 382 }
379 } else if (name == ENTRY_META_NEW) { 383 } else if (name == ENTRY_META_NEW) {
380 // ENTRY_META_NEW == ENTRY_META_OLD 384 // ENTRY_META_NEW == ENTRY_META_OLD
381 if (!extractMeta(cur, &dta->meta)) 385 if (!extractMeta(cur, &dta->meta))
382 return false; 386 return false;
383 } else { 387 } else {
384 printDebug(string("Serializer::extractEntry(): invalid: ") 388 printDebug(string("Serializer::extractEntry(): invalid: ")
385 + name.latin1()); 389 + name.latin1());
386 } 390 }
387 } 391 }
388 dta->lockStat = defaultLockStat; 392 dta->lockStat = defaultLockStat;
389 return true; 393 return true;
390} 394}
391 395
392bool Serializer::extractMeta(const QDomNode &n, 396bool Serializer::extractMeta(const QDomNode &n,
393 PwMMetaData *dta) 397 PwMMetaData *dta)
394{ 398{
395 QDomNode cur(n.firstChild()); 399 QDomNode cur(n.firstChild());
396 QString name, val; 400 QString name, val;
397 while (!cur.isNull()) { 401 while (!cur.isNull()) {
398 name = cur.nodeName(); 402 name = cur.nodeName();
399 val = cur.toElement().text(); 403 val = cur.toElement().text();
400 if (val == "") { 404 if (val == "") {
401 cur = cur.nextSibling(); 405 cur = cur.nextSibling();
402 continue; 406 continue;
403 } 407 }
408
409 //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers.
410 //because of that it is possible that here some values are not set, which means they are null.
411 //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates.
412
413 QDateTime dtval; //dtval should be invalid by definition.
414
415 if ((name == META_CREATE_DATE) ||
416 (name == META_VALID_DATE) ||
417 (name == META_EXPIRE_DATE) ||
418 (name == META_UPDATE_DATE))
419 {
420 //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length());
421
404#ifndef PWM_EMBEDDED 422#ifndef PWM_EMBEDDED
405 if (name == META_CREATE_DATE) { 423 dtval = QDateTime::fromString(val, Qt::ISODate);
406 dta->create = QDateTime::fromString(val, Qt::ISODate);
407 } else if (name == META_VALID_DATE) {
408 dta->valid = QDateTime::fromString(val, Qt::ISODate);
409 } else if (name == META_EXPIRE_DATE) {
410 dta->expire = QDateTime::fromString(val, Qt::ISODate);
411 } else if (name == META_UPDATE_DATE) {
412 dta->update = QDateTime::fromString(val, Qt::ISODate);
413 } else if (name == META_UPDATE_INT) {
414 dta->updateInt = strtoul(val.latin1(), 0, 10);
415 } else if (name == META_UNIQUEID) {
416 dta->uniqueid = unescapeEntryData(val).latin1();
417 } else {
418 printDebug(string("extractMeta(): invalid: ")
419 + name.latin1());
420 }
421#else 424#else
425 bool ok;
426 dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
427
428 if (ok == false)
429 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
430#endif
422 431
432 //if the parsed data is wrong, dtval should be invalid at this time.
423 433
424 bool ok = true; 434 }
425 435
426 if (name == META_CREATE_DATE) { 436 if (name == META_CREATE_DATE) {
427 dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 437 dta->create = dtval;
428 } else if (name == META_VALID_DATE) { 438 } else if (name == META_VALID_DATE) {
429 dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 439 dta->valid = dtval;
430 } else if (name == META_EXPIRE_DATE) { 440 } else if (name == META_EXPIRE_DATE) {
431 dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 441 dta->expire = dtval;
432 } else if (name == META_UPDATE_DATE) { 442 } else if (name == META_UPDATE_DATE) {
433 dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 443 dta->update = dtval;
434 } else if (name == META_UPDATE_INT) { 444 } else if (name == META_UPDATE_INT) {
435 dta->updateInt = strtoul(val.latin1(), 0, 10); 445 dta->updateInt = strtoul(val.latin1(), 0, 10);
436 } else if (name == META_UNIQUEID) { 446 } else if (name == META_UNIQUEID) {
437 dta->uniqueid = unescapeEntryData(val).latin1(); 447 dta->uniqueid = unescapeEntryData(val).latin1();
438 } else { 448 } else {
439 printDebug(string("extractMeta(): invalid: ") 449 printDebug(string("extractMeta(): invalid: ")
440 + name.latin1()); 450 + name.latin1());
441 } 451 }
442 452
443 if (ok == false)
444 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
445
446
447#endif
448 cur = cur.nextSibling(); 453 cur = cur.nextSibling();
449 } 454 }
450 return true; 455 return true;
451} 456}
452 457
453bool Serializer::checkValid() 458bool Serializer::checkValid()
454{ 459{
455 PWM_ASSERT(domDoc); 460 PWM_ASSERT(domDoc);
456 QDomElement root(domDoc->documentElement()); 461 QDomElement root(domDoc->documentElement());
457 if (root.nodeName() != ROOT_MAGIC_NEW && 462 if (root.nodeName() != ROOT_MAGIC_NEW &&
458 root.nodeName() != ROOT_MAGIC_OLD) { 463 root.nodeName() != ROOT_MAGIC_OLD) {
459 printDebug("Serializer: wrong magic"); 464 printDebug("Serializer: wrong magic");
460 return false; 465 return false;
461 } 466 }
462 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && 467 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW &&
463 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { 468 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) {
464 printDebug("Serializer: wrong version"); 469 printDebug("Serializer: wrong version");
465 return false; 470 return false;
466 } 471 }
467 return true; 472 return true;
468} 473}
469 474
470QDomElement Serializer::genNewRoot() 475QDomElement Serializer::genNewRoot()
471{ 476{
472 PWM_ASSERT(domDoc); 477 PWM_ASSERT(domDoc);
473 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); 478 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR));
474 root.setAttribute(VER_STR_WR, COMPAT_VER_WR); 479 root.setAttribute(VER_STR_WR, COMPAT_VER_WR);
475 domDoc->appendChild(root); 480 domDoc->appendChild(root);
476 return root; 481 return root;
477} 482}
478 483
479bool Serializer::addCategories(QDomElement *e, 484bool Serializer::addCategories(QDomElement *e,
480 const vector<PwMCategoryItem> &dta) 485 const vector<PwMCategoryItem> &dta)
481{ 486{
482 unsigned int numCat = dta.size(), i; 487 unsigned int numCat = dta.size(), i;
483 QString curId, curName; 488 QString curId, curName;
484 QDomElement curCat; 489 QDomElement curCat;
485 490
486 for (i = 0; i < numCat; ++i) { 491 for (i = 0; i < numCat; ++i) {
487 curId = CAT_PREFIX_WR; 492 curId = CAT_PREFIX_WR;
488 curId += tostr(i).c_str(); 493 curId += tostr(i).c_str();
489 curName = dta[i].name.c_str(); 494 curName = dta[i].name.c_str();
490 curCat = domDoc->createElement(curId); 495 curCat = domDoc->createElement(curId);
491 curCat.setAttribute(CAT_NAME_WR, curName); 496 curCat.setAttribute(CAT_NAME_WR, curName);
492 if (!addEntries(&curCat, dta[i].d)) { 497 if (!addEntries(&curCat, dta[i].d)) {
493 return false; 498 return false;
494 } 499 }
495 e->appendChild(curCat); 500 e->appendChild(curCat);
@@ -559,198 +564,217 @@ bool Serializer::writeEntry(QDomElement *e,
559 tag = domDoc->createElement(ENTRY_PW_WR); 564 tag = domDoc->createElement(ENTRY_PW_WR);
560 curText = new_text(escapeEntryData(dta.pw.c_str())); 565 curText = new_text(escapeEntryData(dta.pw.c_str()));
561 tag.appendChild(curText); 566 tag.appendChild(curText);
562 e->appendChild(tag); 567 e->appendChild(tag);
563 568
564 tag = domDoc->createElement(ENTRY_COMMENT_WR); 569 tag = domDoc->createElement(ENTRY_COMMENT_WR);
565 curText = new_text(escapeEntryData(dta.comment.c_str())); 570 curText = new_text(escapeEntryData(dta.comment.c_str()));
566 tag.appendChild(curText); 571 tag.appendChild(curText);
567 e->appendChild(tag); 572 e->appendChild(tag);
568 573
569 tag = domDoc->createElement(ENTRY_URL_WR); 574 tag = domDoc->createElement(ENTRY_URL_WR);
570 curText = new_text(escapeEntryData(dta.url.c_str())); 575 curText = new_text(escapeEntryData(dta.url.c_str()));
571 tag.appendChild(curText); 576 tag.appendChild(curText);
572 e->appendChild(tag); 577 e->appendChild(tag);
573 578
574 tag = domDoc->createElement(ENTRY_LAUNCHER_WR); 579 tag = domDoc->createElement(ENTRY_LAUNCHER_WR);
575 curText = new_text(escapeEntryData(dta.launcher.c_str())); 580 curText = new_text(escapeEntryData(dta.launcher.c_str()));
576 tag.appendChild(curText); 581 tag.appendChild(curText);
577 e->appendChild(tag); 582 e->appendChild(tag);
578 583
579 tag = domDoc->createElement(ENTRY_LVP_WR); 584 tag = domDoc->createElement(ENTRY_LVP_WR);
580 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); 585 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str());
581 tag.appendChild(plainText); 586 tag.appendChild(plainText);
582 e->appendChild(tag); 587 e->appendChild(tag);
583 588
584 tag = domDoc->createElement(ENTRY_BIN_WR); 589 tag = domDoc->createElement(ENTRY_BIN_WR);
585 if (dta.binary) 590 if (dta.binary)
586 plainText = domDoc->createTextNode("1"); 591 plainText = domDoc->createTextNode("1");
587 else 592 else
588 plainText = domDoc->createTextNode("0"); 593 plainText = domDoc->createTextNode("0");
589 tag.appendChild(plainText); 594 tag.appendChild(plainText);
590 e->appendChild(tag); 595 e->appendChild(tag);
591 596
592 tag = domDoc->createElement(ENTRY_META_WR); 597 tag = domDoc->createElement(ENTRY_META_WR);
593 if (!writeMeta(&tag, dta.meta)) 598 if (!writeMeta(&tag, dta.meta))
594 return false; 599 return false;
595 e->appendChild(tag); 600 e->appendChild(tag);
596 601
597#undef new_text 602#undef new_text
598 return true; 603 return true;
599} 604}
600 605
601bool Serializer::writeMeta(QDomElement *e, 606bool Serializer::writeMeta(QDomElement *e,
602 const PwMMetaData &dta) 607 const PwMMetaData &dta)
603{ 608{
604 QDomText text; 609 QDomText text;
605 QDomElement tag; 610 QDomElement tag;
606 611
607 tag = domDoc->createElement(META_CREATE_DATE); 612 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
613 //So do not transform an empty value at all.
614 if (dta.create.isValid())
615 {
616 tag = domDoc->createElement(META_CREATE_DATE);
608#ifndef PWM_EMBEDDED 617#ifndef PWM_EMBEDDED
609 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); 618 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
610#else 619#else
611 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); 620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
612#endif 621#endif
613 tag.appendChild(text); 622 tag.appendChild(text);
614 e->appendChild(tag); 623 e->appendChild(tag);
624 }
615 625
616 tag = domDoc->createElement(META_VALID_DATE); 626 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
627 //So do not transform an empty value at all.
628 if (dta.valid.isValid())
629 {
630 tag = domDoc->createElement(META_VALID_DATE);
617#ifndef PWM_EMBEDDED 631#ifndef PWM_EMBEDDED
618 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); 632 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
619#else 633#else
620 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); 634 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
621#endif 635#endif
622 tag.appendChild(text); 636 tag.appendChild(text);
623 e->appendChild(tag); 637 e->appendChild(tag);
638 }
624 639
625 tag = domDoc->createElement(META_EXPIRE_DATE); 640 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
641 //So do not transform an empty value at all.
642 if (dta.expire.isValid())
643 {
644 tag = domDoc->createElement(META_EXPIRE_DATE);
626#ifndef PWM_EMBEDDED 645#ifndef PWM_EMBEDDED
627 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); 646 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
628#else 647#else
629 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); 648 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
630#endif 649#endif
631 tag.appendChild(text); 650 tag.appendChild(text);
632 e->appendChild(tag); 651 e->appendChild(tag);
652 }
633 653
634 tag = domDoc->createElement(META_UPDATE_DATE); 654 //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers.
655 //So do not transform an empty value at all.
656 if (dta.update.isValid())
657 {
658 tag = domDoc->createElement(META_UPDATE_DATE);
635#ifndef PWM_EMBEDDED 659#ifndef PWM_EMBEDDED
636 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); 660 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
637#else 661#else
638 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); 662 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
639#endif 663#endif
640 tag.appendChild(text); 664 tag.appendChild(text);
641 e->appendChild(tag); 665 e->appendChild(tag);
666 }
642 667
643 tag = domDoc->createElement(META_UPDATE_INT); 668 tag = domDoc->createElement(META_UPDATE_INT);
644 text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); 669 text = domDoc->createTextNode(tostr(dta.updateInt).c_str());
645 tag.appendChild(text); 670 tag.appendChild(text);
646 e->appendChild(tag); 671 e->appendChild(tag);
647 672
648 tag = domDoc->createElement(META_UNIQUEID); 673 tag = domDoc->createElement(META_UNIQUEID);
649 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); 674 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str()));
650 tag.appendChild(text); 675 tag.appendChild(text);
651 e->appendChild(tag); 676 e->appendChild(tag);
652 677
653#undef new_text 678#undef new_text
654 return true; 679 return true;
655} 680}
656 681
657QString Serializer::escapeEntryData(QString dta) 682QString Serializer::escapeEntryData(QString dta)
658{ 683{
659#ifndef PWM_EMBEDDED 684#ifndef PWM_EMBEDDED
660 dta.replace('\n', "$>--endl--<$"); 685 dta.replace('\n', "$>--endl--<$");
661 dta.replace("]]>", "||>"); 686 dta.replace("]]>", "||>");
662#else 687#else
663 dta.replace(QRegExp("\n"), "$>--endl--<$"); 688 dta.replace(QRegExp("\n"), "$>--endl--<$");
664 dta.replace(QRegExp("]]>"), "||>"); 689 dta.replace(QRegExp("]]>"), "||>");
665#endif 690#endif
666 return dta; 691 return dta;
667} 692}
668 693
669QString Serializer::unescapeEntryData(QString dta) 694QString Serializer::unescapeEntryData(QString dta)
670{ 695{
671#ifndef PWM_EMBEDDED 696#ifndef PWM_EMBEDDED
672 dta.replace("$>--endl--<$", "\n"); 697 dta.replace("$>--endl--<$", "\n");
673 dta.replace("||>", "]]>"); 698 dta.replace("||>", "]]>");
674#else 699#else
675 dta.replace(QRegExp("$>--endl--<$"), "\n"); 700 dta.replace(QRegExp("\\$>--endl--<\\$"), "\n");
676 dta.replace(QRegExp("||>"), "]]>"); 701 dta.replace(QRegExp("||>"), "]]>");
677#endif 702#endif
678 return dta; 703 return dta;
679} 704}
680 705
681 706
682//US ENH: the following methods are getting used to write/read sync entries 707//US ENH: the following methods are getting used to write/read sync entries
683/** read the syncentries in the node "n" */ 708/** read the syncentries in the node "n" */
684bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) 709bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta)
685{ 710{
686 QDomNodeList nl(n.childNodes()); 711 QDomNodeList nl(n.childNodes());
687 QDomNode cur; 712 QDomNode cur;
688 713
689 QString devicename, val; 714 QString devicename, val;
690 unsigned int numSync = nl.count(), i; 715 unsigned int numSync = nl.count(), i;
691 PwMSyncItem curSync; 716 PwMSyncItem curSync;
692 bool ok = true; 717 bool ok = true;
693 718
694 if (!numSync) { 719 if (!numSync) {
695 //no sync entries is a possible result 720 //no sync entries is a possible result
696 printDebug("Serializer::readSyncData(): empty"); 721 printDebug("Serializer::readSyncData(): empty");
697 return true; 722 return true;
698 } 723 }
699 for (i = 0; i < numSync; ++i) { 724 for (i = 0; i < numSync; ++i) {
700 cur = nl.item(i); 725 cur = nl.item(i);
701 if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { 726 if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) {
702 devicename = cur.toElement().attribute(SYNC_TARGET_NAME); 727 devicename = cur.toElement().attribute(SYNC_TARGET_NAME);
703 val = cur.toElement().text(); 728 val = cur.toElement().text();
704 729
705 if ((val == "") || (devicename == QString::null)) { 730 if ((val == "") || (devicename == QString::null)) {
706 printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); 731 printDebug("Serializer::readSyncData(): empty synctarget name or syncdate");
707 continue; 732 continue;
708 } 733 }
709 734
710 curSync.syncName = devicename; 735 curSync.syncName = devicename;
711#ifndef PWM_EMBEDDED 736#ifndef PWM_EMBEDDED
712 curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); 737 curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate);
713#else 738#else
714 curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); 739 curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
715 if (ok == false) 740 if (ok == false)
716 qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); 741 qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1());
717 742
718#endif 743#endif
719 dta->push_back(curSync); 744 dta->push_back(curSync);
720 } 745 }
721 } 746 }
722 return true; 747 return true;
723 748
724} 749}
725 750
726 751
727 752
728bool Serializer::addSyncData(QDomElement *e, 753bool Serializer::addSyncData(QDomElement *e,
729 const vector<PwMSyncItem> &dta) 754 const vector<PwMSyncItem> &dta)
730{ 755{
731 unsigned int numSync = dta.size(), i; 756 unsigned int numSync = dta.size(), i;
732 QString curId, curDeviceName; 757 QString curId, curDeviceName;
733 QDomElement curSync, curSyncDate; 758 QDomElement curSync;
734 QDomText text; 759 QDomText text;
735 760
736 for (i = 0; i < numSync; ++i) { 761 for (i = 0; i < numSync; ++i) {
737 curId = SYNC_TARGET_PREFIX; 762 curId = SYNC_TARGET_PREFIX;
738 curId += tostr(i).c_str(); 763 curId += tostr(i).c_str();
739 curDeviceName = dta[i].syncName.c_str(); 764 curDeviceName = dta[i].syncName.c_str();
740 curSync = domDoc->createElement(curId); 765 curSync = domDoc->createElement(curId);
741 curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); 766 curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName);
742 767
743#ifndef PWM_EMBEDDED 768#ifndef PWM_EMBEDDED
744 text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); 769 text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate));
745#else 770#else
746 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); 771 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate));
747#endif 772#endif
748 curSyncDate.appendChild(text); 773 curSync.appendChild(text);
749 curSync.appendChild(curSyncDate);
750 774
751 e->appendChild(curSync); 775 e->appendChild(curSync);
752 776
753 } 777 }
754 return true; 778 return true;
755} 779}
756 780