summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-11-28 05:53:55 (UTC)
committer zautrix <zautrix>2005-11-28 05:53:55 (UTC)
commit29c3ed5181b8a33aac73eec90956819b71641048 (patch) (unidiff)
tree8733a18a337b28545ccda5e178cab1b1977314d5
parentc09ac6c4c77ee1ed50cd9d86a6798eebdede3991 (diff)
downloadkdepimpi-29c3ed5181b8a33aac73eec90956819b71641048.zip
kdepimpi-29c3ed5181b8a33aac73eec90956819b71641048.tar.gz
kdepimpi-29c3ed5181b8a33aac73eec90956819b71641048.tar.bz2
sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwm.cpp4
-rw-r--r--pwmanager/pwmanager/pwm.h2
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp2
-rw-r--r--pwmanager/pwmanager/pwmdoc.h2
4 files changed, 5 insertions, 5 deletions
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
index e12dc49..8373850 100644
--- a/pwmanager/pwmanager/pwm.cpp
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -1,1599 +1,1599 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include <klocale.h> 20#include <klocale.h>
21#include <klistview.h> 21#include <klistview.h>
22#include <ktoolbar.h> 22#include <ktoolbar.h>
23#include <kfiledialog.h> 23#include <kfiledialog.h>
24#include <kiconloader.h> 24#include <kiconloader.h>
25#include <kmessagebox.h> 25#include <kmessagebox.h>
26 26
27#include <qstatusbar.h> 27#include <qstatusbar.h>
28 28
29#ifndef PWM_EMBEDDED 29#ifndef PWM_EMBEDDED
30#include <kmenubar.h> 30#include <kmenubar.h>
31#include <kstatusbar.h> 31#include <kstatusbar.h>
32#include <dcopclient.h> 32#include <dcopclient.h>
33#include "configwndimpl.h" 33#include "configwndimpl.h"
34#include "configuration.h" 34#include "configuration.h"
35#else 35#else
36#include <qmenubar.h> 36#include <qmenubar.h>
37#include <qmessagebox.h> 37#include <qmessagebox.h>
38#include <pwmprefs.h> 38#include <pwmprefs.h>
39#include <kpimglobalprefs.h> 39#include <kpimglobalprefs.h>
40#include <kprefsdialog.h> 40#include <kprefsdialog.h>
41#include <kcmconfigs/kcmpwmconfig.h> 41#include <kcmconfigs/kcmpwmconfig.h>
42#include <kcmconfigs/kcmkdepimconfig.h> 42#include <kcmconfigs/kcmkdepimconfig.h>
43#include <kcmultidialog.h> 43#include <kcmultidialog.h>
44#include "editcategory.h" 44#include "editcategory.h"
45#endif 45#endif
46 46
47 47
48#ifndef DESKTOP_VERSION 48#ifndef DESKTOP_VERSION
49#include <qpe/global.h> 49#include <qpe/global.h>
50#endif 50#endif
51 51
52#include <qpixmap.h> 52#include <qpixmap.h>
53#include <qcheckbox.h> 53#include <qcheckbox.h>
54#include <qspinbox.h> 54#include <qspinbox.h>
55#include <qlineedit.h> 55#include <qlineedit.h>
56#include <qfileinfo.h> 56#include <qfileinfo.h>
57#include <qclipboard.h> 57#include <qclipboard.h>
58 58
59 59
60#include <stdio.h> 60#include <stdio.h>
61 61
62#include "pwm.h" 62#include "pwm.h"
63#include "pwminit.h" 63#include "pwminit.h"
64#include "pwmprint.h" 64#include "pwmprint.h"
65#include "addentrywndimpl.h" 65#include "addentrywndimpl.h"
66#include "globalstuff.h" 66#include "globalstuff.h"
67#include "findwndimpl.h" 67#include "findwndimpl.h"
68#include "csv.h" 68#include "csv.h"
69 69
70#ifdef CONFIG_KWALLETIF 70#ifdef CONFIG_KWALLETIF
71# include "kwalletif.h" 71# include "kwalletif.h"
72# include "kwalletemu.h" 72# include "kwalletemu.h"
73#endif 73#endif
74#ifdef CONFIG_KEYCARD 74#ifdef CONFIG_KEYCARD
75# include "pwmkeycard.h" 75# include "pwmkeycard.h"
76#endif 76#endif
77 77
78 #define DEFAULT_SIZE (QSize(700, 400)) 78 #define DEFAULT_SIZE (QSize(700, 400))
79 79
80// Button IDs for "file" popup menu 80// Button IDs for "file" popup menu
81enum { 81enum {
82 BUTTON_POPUP_FILE_NEW = 0, 82 BUTTON_POPUP_FILE_NEW = 0,
83 BUTTON_POPUP_FILE_OPEN, 83 BUTTON_POPUP_FILE_OPEN,
84 BUTTON_POPUP_FILE_CLOSE, 84 BUTTON_POPUP_FILE_CLOSE,
85 BUTTON_POPUP_FILE_SAVE, 85 BUTTON_POPUP_FILE_SAVE,
86 BUTTON_POPUP_FILE_SAVEAS, 86 BUTTON_POPUP_FILE_SAVEAS,
87 BUTTON_POPUP_FILE_EXPORT, 87 BUTTON_POPUP_FILE_EXPORT,
88 BUTTON_POPUP_FILE_IMPORT, 88 BUTTON_POPUP_FILE_IMPORT,
89 BUTTON_POPUP_FILE_PRINT, 89 BUTTON_POPUP_FILE_PRINT,
90 BUTTON_POPUP_FILE_QUIT 90 BUTTON_POPUP_FILE_QUIT
91}; 91};
92// Button IDs for "manage" popup menu 92// Button IDs for "manage" popup menu
93enum { 93enum {
94 BUTTON_POPUP_MANAGE_ADD = 0, 94 BUTTON_POPUP_MANAGE_ADD = 0,
95 BUTTON_POPUP_MANAGE_EDIT, 95 BUTTON_POPUP_MANAGE_EDIT,
96 BUTTON_POPUP_MANAGE_DEL, 96 BUTTON_POPUP_MANAGE_DEL,
97 BUTTON_POPUP_MANAGE_CHANGEMP 97 BUTTON_POPUP_MANAGE_CHANGEMP
98}; 98};
99// Button IDs for chipcard popup menu 99// Button IDs for chipcard popup menu
100enum { 100enum {
101#ifdef CONFIG_KEYCARD 101#ifdef CONFIG_KEYCARD
102 BUTTON_POPUP_CHIPCARD_GENNEW = 0, 102 BUTTON_POPUP_CHIPCARD_GENNEW = 0,
103 BUTTON_POPUP_CHIPCARD_DEL, 103 BUTTON_POPUP_CHIPCARD_DEL,
104 BUTTON_POPUP_CHIPCARD_READID, 104 BUTTON_POPUP_CHIPCARD_READID,
105 BUTTON_POPUP_CHIPCARD_SAVEBACKUP, 105 BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
106 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP 106 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
107#else // CONFIG_KEYCARD 107#else // CONFIG_KEYCARD
108 BUTTON_POPUP_CHIPCARD_NO = 0 108 BUTTON_POPUP_CHIPCARD_NO = 0
109#endif // CONFIG_KEYCARD 109#endif // CONFIG_KEYCARD
110}; 110};
111// Button IDs for "view" popup menu 111// Button IDs for "view" popup menu
112enum { 112enum {
113 BUTTON_POPUP_VIEW_FIND = 0, 113 BUTTON_POPUP_VIEW_FIND = 0,
114 BUTTON_POPUP_VIEW_LOCK, 114 BUTTON_POPUP_VIEW_LOCK,
115 BUTTON_POPUP_VIEW_DEEPLOCK, 115 BUTTON_POPUP_VIEW_DEEPLOCK,
116 BUTTON_POPUP_VIEW_UNLOCK 116 BUTTON_POPUP_VIEW_UNLOCK
117}; 117};
118// Button IDs for "options" popup menu 118// Button IDs for "options" popup menu
119enum { 119enum {
120 BUTTON_POPUP_OPTIONS_CONFIG = 0, 120 BUTTON_POPUP_OPTIONS_CONFIG = 0,
121 BUTTON_POPUP_OPTIONS_GLOBAL_CONFIG 121 BUTTON_POPUP_OPTIONS_GLOBAL_CONFIG
122#ifdef PWM_EMBEDDED 122#ifdef PWM_EMBEDDED
123 ,BUTTON_POPUP_OPTIONS_CATEGORY 123 ,BUTTON_POPUP_OPTIONS_CATEGORY
124#endif 124#endif
125}; 125};
126// Button IDs for "export" popup menu (in "file" popup menu) 126// Button IDs for "export" popup menu (in "file" popup menu)
127enum { 127enum {
128 BUTTON_POPUP_EXPORT_TEXT = 0, 128 BUTTON_POPUP_EXPORT_TEXT = 0,
129 BUTTON_POPUP_EXPORT_GPASMAN, 129 BUTTON_POPUP_EXPORT_GPASMAN,
130 BUTTON_POPUP_EXPORT_CSV 130 BUTTON_POPUP_EXPORT_CSV
131#ifdef CONFIG_KWALLETIF 131#ifdef CONFIG_KWALLETIF
132 ,BUTTON_POPUP_EXPORT_KWALLET 132 ,BUTTON_POPUP_EXPORT_KWALLET
133#endif 133#endif
134}; 134};
135// Button IDs for "import" popup menu (in "file" popup menu) 135// Button IDs for "import" popup menu (in "file" popup menu)
136enum { 136enum {
137 BUTTON_POPUP_IMPORT_TEXT = 0, 137 BUTTON_POPUP_IMPORT_TEXT = 0,
138 BUTTON_POPUP_IMPORT_GPASMAN, 138 BUTTON_POPUP_IMPORT_GPASMAN,
139 BUTTON_POPUP_IMPORT_CSV 139 BUTTON_POPUP_IMPORT_CSV
140#ifdef CONFIG_KWALLETIF 140#ifdef CONFIG_KWALLETIF
141 ,BUTTON_POPUP_IMPORT_KWALLET 141 ,BUTTON_POPUP_IMPORT_KWALLET
142#endif 142#endif
143}; 143};
144 144
145#ifdef PWM_EMBEDDED 145#ifdef PWM_EMBEDDED
146// Button IDs for "help" popup menu 146// Button IDs for "help" popup menu
147enum { 147enum {
148 BUTTON_POPUP_HELP_LICENSE = 0, 148 BUTTON_POPUP_HELP_LICENSE = 0,
149 BUTTON_POPUP_HELP_FAQ, 149 BUTTON_POPUP_HELP_FAQ,
150 BUTTON_POPUP_HELP_ABOUT, 150 BUTTON_POPUP_HELP_ABOUT,
151 BUTTON_POPUP_HELP_SYNC, 151 BUTTON_POPUP_HELP_SYNC,
152 BUTTON_POPUP_HELP_WHATSNEW 152 BUTTON_POPUP_HELP_WHATSNEW
153}; 153};
154#endif 154#endif
155 155
156// Button IDs for toolbar 156// Button IDs for toolbar
157enum { 157enum {
158 BUTTON_TOOL_NEW = 0, 158 BUTTON_TOOL_NEW = 0,
159 BUTTON_TOOL_OPEN, 159 BUTTON_TOOL_OPEN,
160 BUTTON_TOOL_SAVE, 160 BUTTON_TOOL_SAVE,
161 BUTTON_TOOL_SAVEAS, 161 BUTTON_TOOL_SAVEAS,
162 BUTTON_TOOL_PRINT, 162 BUTTON_TOOL_PRINT,
163 BUTTON_TOOL_ADD, 163 BUTTON_TOOL_ADD,
164 BUTTON_TOOL_EDIT, 164 BUTTON_TOOL_EDIT,
165 BUTTON_TOOL_DEL, 165 BUTTON_TOOL_DEL,
166 BUTTON_TOOL_FIND, 166 BUTTON_TOOL_FIND,
167 BUTTON_TOOL_LOCK, 167 BUTTON_TOOL_LOCK,
168 BUTTON_TOOL_DEEPLOCK, 168 BUTTON_TOOL_DEEPLOCK,
169 BUTTON_TOOL_UNLOCK 169 BUTTON_TOOL_UNLOCK
170}; 170};
171 171
172 172
173PwM::PwM(PwMInit *_init, PwMDoc *doc, 173PwM::PwM(PwMInit *_init, PwMDoc *doc,
174 bool virginity, 174 bool virginity,
175 QWidget *parent, const char *name) 175 QWidget *parent, const char *name)
176 : KMainWindow(parent, "HALLO") 176 : KMainWindow(parent, "HALLO")
177 , forceQuit (false) 177 , forceQuit (false)
178 , forceMinimizeToTray (false) 178 , forceMinimizeToTray (false)
179{ 179{
180 syncManager = 0; 180 syncManager = 0;
181 virgin = !virginity; 181 virgin = !virginity;
182 init = _init; 182 init = _init;
183 connect(doc, SIGNAL(docClosed(PwMDoc *)), 183 connect(doc, SIGNAL(docClosed(PwMDoc *)),
184 this, SLOT(docClosed(PwMDoc *))); 184 this, SLOT(docClosed(PwMDoc *)));
185 initMenubar(); 185 initMenubar();
186 initToolbar(); 186 initToolbar();
187 initMetrics(); 187 initMetrics();
188 setVirgin(virginity); 188 setVirgin(virginity);
189 setFocusPolicy(QWidget::WheelFocus); 189 setFocusPolicy(QWidget::WheelFocus);
190#ifndef PWM_EMBEDDED 190#ifndef PWM_EMBEDDED
191 statusBar()->show(); 191 statusBar()->show();
192#endif 192#endif
193 view = makeNewListView(doc); 193 view = makeNewListView(doc);
194 setCentralWidget(view); 194 setCentralWidget(view);
195 updateCaption(); 195 updateCaption();
196 showStatMsg(i18n("Ready.")); 196 showStatMsg(i18n("Ready."));
197} 197}
198 198
199PwM::~PwM() 199PwM::~PwM()
200{ 200{
201 //qDebug("PwM::~PwM() %x", this); 201 //qDebug("PwM::~PwM() %x", this);
202 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), 202 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
203 this, SLOT(docClosed(PwMDoc *))); 203 this, SLOT(docClosed(PwMDoc *)));
204 conf()->confWndMainWndSize(size()); 204 conf()->confWndMainWndSize(size());
205 //LR closing of windows changed 205 //LR closing of windows changed
206 //needed for fastload option on PDA 206 //needed for fastload option on PDA
207 //emit closed(this); 207 //emit closed(this);
208 //qDebug("PwM::~PwM() emited closed(this)"); 208 //qDebug("PwM::~PwM() emited closed(this)");
209 delete view; 209 delete view;
210 delete syncManager; 210 delete syncManager;
211} 211}
212 212
213void PwM::initMenubar() 213void PwM::initMenubar()
214{ 214{
215 KIconLoader* picons; 215 KIconLoader* picons;
216#ifndef PWM_EMBEDDED 216#ifndef PWM_EMBEDDED
217 KIconLoader icons; 217 KIconLoader icons;
218 picons = &icons; 218 picons = &icons;
219#else 219#else
220 picons = KGlobal::iconLoader(); 220 picons = KGlobal::iconLoader();
221 221
222 222
223 syncPopup = new KPopupMenu(this); 223 syncPopup = new KPopupMenu(this);
224 224
225 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); 225 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup);
226 syncManager->setBlockSave(false); 226 syncManager->setBlockSave(false);
227 227
228 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 228 connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
229 syncManager->fillSyncMenu(); 229 syncManager->fillSyncMenu();
230 230
231#endif 231#endif
232 filePopup = new KPopupMenu(this); 232 filePopup = new KPopupMenu(this);
233 importPopup = new KPopupMenu(filePopup); 233 importPopup = new KPopupMenu(filePopup);
234 exportPopup = new KPopupMenu(filePopup); 234 exportPopup = new KPopupMenu(filePopup);
235 managePopup = new KPopupMenu(this); 235 managePopup = new KPopupMenu(this);
236#ifdef CONFIG_KEYCARD 236#ifdef CONFIG_KEYCARD
237 chipcardPopup = new KPopupMenu(this); 237 chipcardPopup = new KPopupMenu(this);
238#endif // CONFIG_KEYCARD 238#endif // CONFIG_KEYCARD
239 viewPopup = new KPopupMenu(this); 239 viewPopup = new KPopupMenu(this);
240 optionsPopup = new KPopupMenu(this); 240 optionsPopup = new KPopupMenu(this);
241 241
242// "file" popup menu 242// "file" popup menu
243 filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), 243 filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
244 i18n("&New"), this, 244 i18n("&New"), this,
245 SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); 245 SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW);
246 filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), 246 filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)),
247 i18n("&Open"), this, 247 i18n("&Open"), this,
248 SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); 248 SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN);
249 filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), 249 filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)),
250 i18n("&Close"), this, 250 i18n("&Close"), this,
251 SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); 251 SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE);
252 filePopup->insertSeparator(); 252 filePopup->insertSeparator();
253 filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), 253 filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)),
254 i18n("&Save"), this, 254 i18n("&Save"), this,
255 SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); 255 SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE);
256 filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), 256 filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)),
257 i18n("Save &as..."), 257 i18n("Save &as..."),
258 this, SLOT(saveAs_slot()), 0, 258 this, SLOT(saveAs_slot()), 0,
259 BUTTON_POPUP_FILE_SAVEAS); 259 BUTTON_POPUP_FILE_SAVEAS);
260 filePopup->insertSeparator(); 260 filePopup->insertSeparator();
261 // "file/export" popup menu 261 // "file/export" popup menu
262 exportPopup->insertItem(i18n("&Text-file..."), this, 262 exportPopup->insertItem(i18n("&Text-file..."), this,
263 SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); 263 SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
264 exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, 264 exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
265 SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); 265 SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
266 exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, 266 exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
267 SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); 267 SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV);
268#ifdef CONFIG_KWALLETIF 268#ifdef CONFIG_KWALLETIF
269 exportPopup->insertItem(i18n("&KWallet..."), this, 269 exportPopup->insertItem(i18n("&KWallet..."), this,
270 SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); 270 SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
271#endif 271#endif
272 filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), 272 filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)),
273 i18n("E&xport"), exportPopup, 273 i18n("E&xport"), exportPopup,
274 BUTTON_POPUP_FILE_EXPORT); 274 BUTTON_POPUP_FILE_EXPORT);
275 // "file/import" popup menu 275 // "file/import" popup menu
276 importPopup->insertItem(i18n("&Text-file..."), this, 276 importPopup->insertItem(i18n("&Text-file..."), this,
277 SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); 277 SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
278 importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, 278 importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
279 SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); 279 SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
280 importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, 280 importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this,
281 SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); 281 SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV);
282#ifdef CONFIG_KWALLETIF 282#ifdef CONFIG_KWALLETIF
283 importPopup->insertItem(i18n("&KWallet..."), this, 283 importPopup->insertItem(i18n("&KWallet..."), this,
284 SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); 284 SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
285#endif 285#endif
286 filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), 286 filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)),
287 i18n("I&mport"), importPopup, 287 i18n("I&mport"), importPopup,
288 BUTTON_POPUP_FILE_IMPORT); 288 BUTTON_POPUP_FILE_IMPORT);
289 filePopup->insertSeparator(); 289 filePopup->insertSeparator();
290#if 0 290#if 0
291 filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), 291 filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)),
292 i18n("&Print..."), this, 292 i18n("&Print..."), this,
293 SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); 293 SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT);
294 filePopup->insertSeparator(); 294 filePopup->insertSeparator();
295#endif 295#endif
296 filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), 296 filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)),
297 i18n("&Quit"), this, 297 i18n("&Quit"), this,
298 SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); 298 SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT);
299 menuBar()->insertItem(i18n("&File"), filePopup); 299 menuBar()->insertItem(i18n("&File"), filePopup);
300// "manage" popup menu 300// "manage" popup menu
301 managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), 301 managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)),
302 i18n("&Add password"), this, 302 i18n("&Add password"), this,
303 SLOT(addPwd_slot()), 0, 303 SLOT(addPwd_slot()), 0,
304 BUTTON_POPUP_MANAGE_ADD); 304 BUTTON_POPUP_MANAGE_ADD);
305 managePopup->insertSeparator(); 305 managePopup->insertSeparator();
306 managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), 306 managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)),
307 i18n("&Edit"), this, SLOT(editPwd_slot()), 0, 307 i18n("&Edit"), this, SLOT(editPwd_slot()), 0,
308 BUTTON_POPUP_MANAGE_EDIT); 308 BUTTON_POPUP_MANAGE_EDIT);
309 managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), 309 managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
310 i18n("&Delete"), this, SLOT(deletePwd_slot()), 310 i18n("&Delete"), this, SLOT(deletePwd_slot()),
311 0, BUTTON_POPUP_MANAGE_DEL); 311 0, BUTTON_POPUP_MANAGE_DEL);
312 managePopup->insertSeparator(); 312 managePopup->insertSeparator();
313 managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), 313 managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)),
314 i18n("Change &Master Password"), this, 314 i18n("Change &Master Password"), this,
315 SLOT(changeMasterPwd_slot()), 0, 315 SLOT(changeMasterPwd_slot()), 0,
316 BUTTON_POPUP_MANAGE_CHANGEMP); 316 BUTTON_POPUP_MANAGE_CHANGEMP);
317 menuBar()->insertItem(i18n("&Manage"), managePopup); 317 menuBar()->insertItem(i18n("&Manage"), managePopup);
318// "chipcard" popup menu 318// "chipcard" popup menu
319#ifdef CONFIG_KEYCARD 319#ifdef CONFIG_KEYCARD
320 chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), 320 chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)),
321 i18n("&Generate new key-card"), this, 321 i18n("&Generate new key-card"), this,
322 SLOT(genNewCard_slot()), 0, 322 SLOT(genNewCard_slot()), 0,
323 BUTTON_POPUP_CHIPCARD_GENNEW); 323 BUTTON_POPUP_CHIPCARD_GENNEW);
324 chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), 324 chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)),
325 i18n("&Erase key-card"), this, 325 i18n("&Erase key-card"), this,
326 SLOT(eraseCard_slot()), 0, 326 SLOT(eraseCard_slot()), 0,
327 BUTTON_POPUP_CHIPCARD_DEL); 327 BUTTON_POPUP_CHIPCARD_DEL);
328 chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), 328 chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)),
329 i18n("Read card-&ID"), this, 329 i18n("Read card-&ID"), this,
330 SLOT(readCardId_slot()), 0, 330 SLOT(readCardId_slot()), 0,
331 BUTTON_POPUP_CHIPCARD_READID); 331 BUTTON_POPUP_CHIPCARD_READID);
332 chipcardPopup->insertSeparator(); 332 chipcardPopup->insertSeparator();
333 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), 333 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)),
334 i18n("&Make card backup-image"), this, 334 i18n("&Make card backup-image"), this,
335 SLOT(makeCardBackup_slot()), 0, 335 SLOT(makeCardBackup_slot()), 0,
336 BUTTON_POPUP_CHIPCARD_SAVEBACKUP); 336 BUTTON_POPUP_CHIPCARD_SAVEBACKUP);
337 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), 337 chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)),
338 i18n("&Replay card backup-image"), this, 338 i18n("&Replay card backup-image"), this,
339 SLOT(replayCardBackup_slot()), 0, 339 SLOT(replayCardBackup_slot()), 0,
340 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); 340 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP);
341 menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); 341 menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup);
342#endif // CONFIG_KEYCARD 342#endif // CONFIG_KEYCARD
343// "view" popup menu 343// "view" popup menu
344 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), 344 viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)),
345 i18n("&Find"), this, 345 i18n("&Find"), this,
346 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); 346 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
347 viewPopup->insertSeparator(); 347 viewPopup->insertSeparator();
348 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), 348 viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)),
349 i18n("&Lock all entries"), this, 349 i18n("&Lock all entries"), this,
350 SLOT(lockWnd_slot()), 0, 350 SLOT(lockWnd_slot()), 0,
351 BUTTON_POPUP_VIEW_LOCK); 351 BUTTON_POPUP_VIEW_LOCK);
352 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), 352 viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)),
353 i18n("&Deep-lock all entries"), this, 353 i18n("&Deep-lock all entries"), this,
354 SLOT(deepLockWnd_slot()), 0, 354 SLOT(deepLockWnd_slot()), 0,
355 BUTTON_POPUP_VIEW_DEEPLOCK); 355 BUTTON_POPUP_VIEW_DEEPLOCK);
356 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), 356 viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)),
357 i18n("&Unlock all entries"), this, 357 i18n("&Unlock all entries"), this,
358 SLOT(unlockWnd_slot()), 0, 358 SLOT(unlockWnd_slot()), 0,
359 BUTTON_POPUP_VIEW_UNLOCK); 359 BUTTON_POPUP_VIEW_UNLOCK);
360 menuBar()->insertItem(i18n("&View"), viewPopup); 360 menuBar()->insertItem(i18n("&View"), viewPopup);
361// "options" popup menu 361// "options" popup menu
362 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), 362 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
363 i18n("&Configure PwM/Pi..."), this, 363 i18n("&Configure PwM/Pi..."), this,
364 SLOT(config_slot()),0, 364 SLOT(config_slot()),0,
365 BUTTON_POPUP_OPTIONS_CONFIG); 365 BUTTON_POPUP_OPTIONS_CONFIG);
366 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), 366 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
367 i18n("Global Settings..."), this, 367 i18n("Global Settings..."), this,
368 SLOT(config_global_slot()),0, 368 SLOT(config_global_slot()),0,
369 BUTTON_POPUP_OPTIONS_GLOBAL_CONFIG); 369 BUTTON_POPUP_OPTIONS_GLOBAL_CONFIG);
370 if ( QApplication::desktop()->width() <= 240 ) { 370 if ( QApplication::desktop()->width() <= 240 ) {
371 managePopup->insertSeparator(); 371 managePopup->insertSeparator();
372 managePopup->insertItem(i18n("&Options"), optionsPopup); 372 managePopup->insertItem(i18n("&Options"), optionsPopup);
373 } else 373 } else
374 menuBar()->insertItem(i18n("&Options"), optionsPopup); 374 menuBar()->insertItem(i18n("&Options"), optionsPopup);
375// "help" popup menu 375// "help" popup menu
376#ifndef PWM_EMBEDDED 376#ifndef PWM_EMBEDDED
377 helpPopup = helpMenu(QString::null, false); 377 helpPopup = helpMenu(QString::null, false);
378#else 378#else
379 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), 379 optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)),
380 i18n("C&ategories..."), this, 380 i18n("C&ategories..."), this,
381 SLOT(category_slot()),0, 381 SLOT(category_slot()),0,
382 BUTTON_POPUP_OPTIONS_CATEGORY); 382 BUTTON_POPUP_OPTIONS_CATEGORY);
383 383
384 384
385 menuBar()->insertItem(i18n("&Sync"), syncPopup); 385 menuBar()->insertItem(i18n("&Sync"), syncPopup);
386 386
387 387
388 388
389 389
390 390
391 helpPopup = new KPopupMenu(this); 391 helpPopup = new KPopupMenu(this);
392 392
393 393
394 helpPopup->insertItem(i18n("&License"), this, 394 helpPopup->insertItem(i18n("&License"), this,
395 SLOT(showLicense_slot()), 0, 395 SLOT(showLicense_slot()), 0,
396 BUTTON_POPUP_HELP_LICENSE); 396 BUTTON_POPUP_HELP_LICENSE);
397 397
398 helpPopup->insertItem(i18n("&Faq"), this, 398 helpPopup->insertItem(i18n("&Faq"), this,
399 SLOT(faq_slot()), 0, 399 SLOT(faq_slot()), 0,
400 BUTTON_POPUP_HELP_FAQ); 400 BUTTON_POPUP_HELP_FAQ);
401 401
402 helpPopup->insertItem(i18n("&About PwManager"), this, 402 helpPopup->insertItem(i18n("&About PwManager"), this,
403 SLOT(createAboutData_slot()), 0, 403 SLOT(createAboutData_slot()), 0,
404 BUTTON_POPUP_HELP_ABOUT); 404 BUTTON_POPUP_HELP_ABOUT);
405 405
406 helpPopup->insertItem(i18n("&Sync HowTo"), this, 406 helpPopup->insertItem(i18n("&Sync HowTo"), this,
407 SLOT(syncHowTo_slot()), 0, 407 SLOT(syncHowTo_slot()), 0,
408 BUTTON_POPUP_HELP_SYNC); 408 BUTTON_POPUP_HELP_SYNC);
409 409
410 helpPopup->insertItem(i18n("&What's New"), this, 410 helpPopup->insertItem(i18n("&What's New"), this,
411 SLOT(whatsnew_slot()), 0, 411 SLOT(whatsnew_slot()), 0,
412 BUTTON_POPUP_HELP_WHATSNEW); 412 BUTTON_POPUP_HELP_WHATSNEW);
413 413
414#endif 414#endif
415 menuBar()->insertItem(i18n("&Help"), helpPopup); 415 menuBar()->insertItem(i18n("&Help"), helpPopup);
416 416
417} 417}
418 418
419void PwM::initToolbar() 419void PwM::initToolbar()
420{ 420{
421 KIconLoader* picons; 421 KIconLoader* picons;
422#ifndef PWM_EMBEDDED 422#ifndef PWM_EMBEDDED
423 KIconLoader icons; 423 KIconLoader icons;
424 picons = &icons; 424 picons = &icons;
425#else 425#else
426 picons = KGlobal::iconLoader(); 426 picons = KGlobal::iconLoader();
427#endif 427#endif
428 428
429#if 0 429#if 0
430 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), 430 toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar),
431 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, 431 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
432 SLOT(new_slot()), true, i18n("New")); 432 SLOT(new_slot()), true, i18n("New"));
433#endif 433#endif
434 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), 434 toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar),
435 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, 435 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
436 SLOT(open_slot()), true, i18n("Open")); 436 SLOT(open_slot()), true, i18n("Open"));
437 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), 437 toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar),
438 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, 438 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
439 SLOT(addPwd_slot()), true, 439 SLOT(addPwd_slot()), true,
440 i18n("Add password")); 440 i18n("Add password"));
441 toolBar()->insertSeparator(); 441 toolBar()->insertSeparator();
442 442
443 toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), 443 toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar),
444 BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, 444 BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this,
445 SLOT(find_slot()), true, i18n("Find entry")); 445 SLOT(find_slot()), true, i18n("Find entry"));
446 toolBar()->insertSeparator(); 446 toolBar()->insertSeparator();
447 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), 447 toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar),
448 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, 448 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
449 SLOT(save_slot()), true, i18n("Save")); 449 SLOT(save_slot()), true, i18n("Save"));
450#if 0 450#if 0
451 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), 451 toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar),
452 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, 452 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
453 SLOT(saveAs_slot()), true, i18n("Save as")); 453 SLOT(saveAs_slot()), true, i18n("Save as"));
454#endif 454#endif
455 455
456 456
457#if 0 457#if 0
458 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), 458 toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar),
459 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, 459 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
460 SLOT(print_slot()), true, i18n("Print...")); 460 SLOT(print_slot()), true, i18n("Print..."));
461#endif 461#endif
462 toolBar()->insertSeparator(); 462 toolBar()->insertSeparator();
463 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), 463 toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar),
464 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, 464 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
465 SLOT(editPwd_slot()), true, 465 SLOT(editPwd_slot()), true,
466 i18n("Edit password")); 466 i18n("Edit password"));
467 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), 467 toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar),
468 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, 468 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this,
469 SLOT(deletePwd_slot()), true, 469 SLOT(deletePwd_slot()), true,
470 i18n("Delete password")); 470 i18n("Delete password"));
471 toolBar()->insertSeparator(); 471 toolBar()->insertSeparator();
472 toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), 472 toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar),
473 BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, 473 BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this,
474 SLOT(lockWnd_slot()), true, 474 SLOT(lockWnd_slot()), true,
475 i18n("Lock all entries")); 475 i18n("Lock all entries"));
476 toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), 476 toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar),
477 BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, 477 BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this,
478 SLOT(deepLockWnd_slot()), true, 478 SLOT(deepLockWnd_slot()), true,
479 i18n("Deep-Lock all entries")); 479 i18n("Deep-Lock all entries"));
480 toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), 480 toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar),
481 BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, 481 BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this,
482 SLOT(unlockWnd_slot()), true, 482 SLOT(unlockWnd_slot()), true,
483 i18n("Unlock all entries")); 483 i18n("Unlock all entries"));
484} 484}
485 485
486void PwM::initMetrics() 486void PwM::initMetrics()
487{ 487{
488 QSize s = conf()->confWndMainWndSize(); 488 QSize s = conf()->confWndMainWndSize();
489 if (s.isValid()) 489 if (s.isValid())
490 resize(s); 490 resize(s);
491 else 491 else
492 resize(DEFAULT_SIZE); 492 resize(DEFAULT_SIZE);
493} 493}
494 494
495void PwM::updateCaption() 495void PwM::updateCaption()
496{ 496{
497 QString s = curDoc()->getTitle(); 497 QString s = curDoc()->getTitle();
498 int maxlen = 50; 498 int maxlen = 50;
499 if ( QApplication::desktop()->width() < 640 ) { 499 if ( QApplication::desktop()->width() < 640 ) {
500 if ( QApplication::desktop()->width() < 320 ) 500 if ( QApplication::desktop()->width() < 320 )
501 maxlen = 22; 501 maxlen = 22;
502 else 502 else
503 maxlen = 35; 503 maxlen = 35;
504 } 504 }
505 if ( s.length() > maxlen ) { 505 if ( s.length() > maxlen ) {
506 s = "..."+s.right(maxlen -3); 506 s = "..."+s.right(maxlen -3);
507 } 507 }
508 setPlainCaption( s ); 508 setPlainCaption( s );
509} 509}
510 510
511void PwM::hideEvent(QHideEvent *) 511void PwM::hideEvent(QHideEvent *)
512{ 512{
513 if (isMinimized()) { 513 if (isMinimized()) {
514 if (init->tray()) { 514 if (init->tray()) {
515 forceMinimizeToTray = true; 515 forceMinimizeToTray = true;
516 close(); 516 close();
517 } 517 }
518 int mmlock = conf()->confGlobMinimizeLock(); 518 int mmlock = conf()->confGlobMinimizeLock();
519 switch (mmlock) { 519 switch (mmlock) {
520 case 0: // don't lock anything 520 case 0: // don't lock anything
521 break; 521 break;
522 case 1: {// normal lock 522 case 1: {// normal lock
523 curDoc()->lockAll(true); 523 curDoc()->lockAll(true);
524 break; 524 break;
525 } case 2: {// deep-lock 525 } case 2: {// deep-lock
526 curDoc()->deepLock(); 526 curDoc()->deepLock();
527 break; 527 break;
528 } default: 528 } default:
529 WARN(); 529 WARN();
530 } 530 }
531 } 531 }
532} 532}
533 533
534void PwM::setVirgin(bool v) 534void PwM::setVirgin(bool v)
535{ 535{
536 if (virgin == v) 536 if (virgin == v)
537 return; 537 return;
538 virgin = v; 538 virgin = v;
539 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); 539 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v);
540 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); 540 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v);
541 filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); 541 filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v);
542 filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); 542 filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v);
543 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); 543 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v);
544 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); 544 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v);
545 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); 545 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v);
546 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); 546 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v);
547 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); 547 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v);
548 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); 548 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v);
549 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); 549 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v);
550 toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); 550 toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v);
551 toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); 551 toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v);
552 toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); 552 toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v);
553 toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); 553 toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v);
554 toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); 554 toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v);
555 toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); 555 toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v);
556 toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); 556 toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v);
557 toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); 557 toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v);
558 toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); 558 toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v);
559} 559}
560 560
561void PwM::new_slot() 561void PwM::new_slot()
562{ 562{
563 init->createMainWnd(); 563 init->createMainWnd();
564} 564}
565 565
566//US ENH 566//US ENH
567void PwM::open_slot() 567void PwM::open_slot()
568{ 568{
569 open_slot(""); 569 open_slot("");
570} 570}
571 571
572void PwM::open_slot(QString fn) 572void PwM::open_slot(QString fn)
573{ 573{
574 openDoc(fn); 574 openDoc(fn);
575} 575}
576 576
577PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) 577PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked)
578{ 578{
579 if (!isVirgin()) { 579 if (!isVirgin()) {
580 // open the document in a new window. 580 // open the document in a new window.
581 PwM *newInstance = init->createMainWnd(); 581 PwM *newInstance = init->createMainWnd();
582 PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); 582 PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked);
583 if (!newDoc) { 583 if (!newDoc) {
584 newInstance->setForceQuit(true); 584 newInstance->setForceQuit(true);
585 delete_and_null(newInstance); 585 delete_and_null(newInstance);
586 } 586 }
587 return newDoc; 587 return newDoc;
588 } 588 }
589 589
590 if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) 590 if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked))
591 return 0; 591 return 0;
592 showStatMsg(i18n("Successfully opened file.")); 592 showStatMsg(i18n("Successfully opened file."));
593 updateCaption(); 593 updateCaption();
594 setVirgin(false); 594 setVirgin(false);
595 return curDoc(); 595 return curDoc();
596} 596}
597 597
598PwMView * PwM::makeNewListView(PwMDoc *doc) 598PwMView * PwM::makeNewListView(PwMDoc *doc)
599{ 599{
600 PwMView *ret = new PwMView(this, this, doc); 600 PwMView *ret = new PwMView(this, this, doc);
601 ret->setFont(conf()->confGlobEntryFont()); 601 ret->setFont(conf()->confGlobEntryFont());
602 ret->show(); 602 ret->show();
603 return ret; 603 return ret;
604} 604}
605 605
606void PwM::close_slot() 606void PwM::close_slot()
607{ 607{
608 close(); 608 close();
609} 609}
610 610
611void PwM::quitButton_slot() 611void PwM::quitButton_slot()
612{ 612{
613 init->shutdownApp(0); 613 init->shutdownApp(0);
614} 614}
615 615
616void PwM::save_slot() 616void PwM::save_slot()
617{ 617{
618 save(); 618 save();
619} 619}
620 620
621bool PwM::save() 621bool PwM::save()
622{ 622{
623 if (!curDoc()->saveDocUi(curDoc())) 623 if (!curDoc()->saveDocUi(curDoc()))
624 return false; 624 return false;
625 showStatMsg(i18n("Successfully saved data.")); 625 showStatMsg(i18n("Successfully saved data."));
626 updateCaption(); 626 updateCaption();
627 return true; 627 return true;
628} 628}
629 629
630void PwM::saveAs_slot() 630void PwM::saveAs_slot()
631{ 631{
632 saveAs(); 632 saveAs();
633} 633}
634 634
635bool PwM::saveAs() 635bool PwM::saveAs()
636{ 636{
637 if (!curDoc()->saveAsDocUi(curDoc())) 637 if (!curDoc()->saveAsDocUi(curDoc()))
638 return false; 638 return false;
639 showStatMsg(i18n("Successfully saved data.")); 639 showStatMsg(i18n("Successfully saved data."));
640 updateCaption(); 640 updateCaption();
641 return true; 641 return true;
642} 642}
643 643
644//US ENH : changed code to run with older MOC 644//US ENH : changed code to run with older MOC
645void PwM::addPwd_slot() 645void PwM::addPwd_slot()
646{ 646{
647 addPwd_slot1(0, 0); 647 addPwd_slot1(0, 0);
648} 648}
649 649
650void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) 650void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc)
651{ 651{
652 PwMDoc *doc; 652 PwMDoc *doc;
653 if (_doc) { 653 if (_doc) {
654 doc = _doc; 654 doc = _doc;
655 } else { 655 } else {
656 doc = curDoc(); 656 doc = curDoc();
657 } 657 }
658 PWM_ASSERT(doc); 658 PWM_ASSERT(doc);
659 doc->timer()->getLock(DocTimer::id_autoLockTimer); 659 doc->timer()->getLock(DocTimer::id_autoLockTimer);
660#ifndef PWM_EMBEDDED 660#ifndef PWM_EMBEDDED
661 AddEntryWndImpl w; 661 AddEntryWndImpl w;
662#else 662#else
663 AddEntryWndImpl w(doc, this, "addentrywndimpl"); 663 AddEntryWndImpl w(doc, this, "addentrywndimpl");
664#endif 664#endif
665 w.setCaption( i18n ("Add new password") ); 665 w.setCaption( i18n ("Add new password") );
666 vector<string> catList; 666 vector<string> catList;
667 doc->getCategoryList(&catList); 667 doc->getCategoryList(&catList);
668 unsigned i, size = catList.size(); 668 unsigned i, size = catList.size();
669 for (i = 0; i < size; ++i) { 669 for (i = 0; i < size; ++i) {
670 w.addCategory(catList[i].c_str()); 670 w.addCategory(catList[i].c_str());
671 } 671 }
672 w.setCurrCategory(view->getCurrentCategory()); 672 w.setCurrCategory(view->getCurrentCategory());
673 if (pw) 673 if (pw)
674 w.pwLineEdit->setText(*pw); 674 w.pwLineEdit->setText(*pw);
675 675
676 tryAgain: 676 tryAgain:
677 w.descLineEdit->setFocus(); 677 w.descLineEdit->setFocus();
678 if (w.exec() == 1) 678 if (w.exec() == 1)
679 { 679 {
680 PwMDataItem d; 680 PwMDataItem d;
681 681
682 //US BUG: to initialize all values of curEntr with meaningfulldata, 682 //US BUG: to initialize all values of curEntr with meaningfulldata,
683 // we call clear on it. Reason: Metadata will be uninitialized otherwise. 683 // we call clear on it. Reason: Metadata will be uninitialized otherwise.
684 // another option would be to create a constructor for PwMDataItem 684 // another option would be to create a constructor for PwMDataItem
685 d.clear(true); 685 d.clear(true);
686 686
687 d.desc = w.getDescription().latin1(); 687 d.desc = w.getDescription().latin1();
688 d.name = w.getUsername().latin1(); 688 d.name = w.getUsername().latin1();
689 d.pw = w.getPassword().latin1(); 689 d.pw = w.getPassword().latin1();
690 d.comment = w.getComment().latin1(); 690 d.comment = w.getComment().latin1();
691 d.url = w.getUrl().latin1(); 691 d.url = w.getUrl().latin1();
692 d.launcher = w.getLauncher().latin1(); 692 d.launcher = w.getLauncher().latin1();
693 PwMerror ret = doc->addEntry(w.getCategory(), &d); 693 PwMerror ret = doc->addEntry(w.getCategory(), &d);
694 if (ret == e_entryExists) { 694 if (ret == e_entryExists) {
695 KMessageBox::error(this, 695 KMessageBox::error(this,
696 i18n 696 i18n
697 ("An entry with this \"Description\",\n" 697 ("An entry with this \"Description\",\n"
698 "does already exist.\n" 698 "does already exist.\n"
699 "Please select another description."), 699 "Please select another description."),
700 i18n("entry already exists.")); 700 i18n("entry already exists."));
701 goto tryAgain; 701 goto tryAgain;
702 } else if (ret == e_maxAllowedEntr) { 702 } else if (ret == e_maxAllowedEntr) {
703 KMessageBox::error(this, i18n("The maximum possible number of\nentries" 703 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
704 "has been reached.\nYou can't add more entries."), 704 "has been reached.\nYou can't add more entries."),
705 i18n("maximum number of entries")); 705 i18n("maximum number of entries"));
706 doc->timer()->putLock(DocTimer::id_autoLockTimer); 706 doc->timer()->putLock(DocTimer::id_autoLockTimer);
707 return; 707 return;
708 } 708 }
709 } 709 }
710 setVirgin(false); 710 setVirgin(false);
711 doc->timer()->putLock(DocTimer::id_autoLockTimer); 711 doc->timer()->putLock(DocTimer::id_autoLockTimer);
712} 712}
713 713
714//US ENH : changed code to run with older MOC 714//US ENH : changed code to run with older MOC
715void PwM::editPwd_slot() 715void PwM::editPwd_slot()
716{ 716{
717 editPwd_slot3(0,0,0); 717 editPwd_slot3(0,0,0);
718} 718}
719 719
720void PwM::editPwd_slot1(const QString *category) 720void PwM::editPwd_slot1(const QString *category)
721{ 721{
722 editPwd_slot3(category, 0, 0); 722 editPwd_slot3(category, 0, 0);
723} 723}
724 724
725void PwM::editPwd_slot3(const QString *category, const int *index, 725void PwM::editPwd_slot3(const QString *category, const int *index,
726 PwMDoc *_doc) 726 PwMDoc *_doc)
727{ 727{
728 PwMDoc *doc; 728 PwMDoc *doc;
729 if (_doc) { 729 if (_doc) {
730 doc = _doc; 730 doc = _doc;
731 } else { 731 } else {
732 doc = curDoc(); 732 doc = curDoc();
733 } 733 }
734 PWM_ASSERT(doc); 734 PWM_ASSERT(doc);
735 if (doc->isDocEmpty()) 735 if (doc->isDocEmpty())
736 return; 736 return;
737 if (doc->isDeepLocked()) 737 if (doc->isDeepLocked())
738 return; 738 return;
739 doc->timer()->getLock(DocTimer::id_autoLockTimer); 739 doc->timer()->getLock(DocTimer::id_autoLockTimer);
740 unsigned int curEntryIndex; 740 unsigned int curEntryIndex;
741 if (index) { 741 if (index) {
742 curEntryIndex = *index; 742 curEntryIndex = *index;
743 } else { 743 } else {
744 if (!(view->getCurEntryIndex(&curEntryIndex))) { 744 if (!(view->getCurEntryIndex(&curEntryIndex))) {
745 qDebug("couldn't get index. Maybe we have a binary entry here. "); 745 qDebug("couldn't get index. Maybe we have a binary entry here. ");
746 printDebug("couldn't get index. Maybe we have a binary entry here."); 746 printDebug("couldn't get index. Maybe we have a binary entry here.");
747 doc->timer()->putLock(DocTimer::id_autoLockTimer); 747 doc->timer()->putLock(DocTimer::id_autoLockTimer);
748 return; 748 return;
749 } 749 }
750 } 750 }
751 QString curCategory; 751 QString curCategory;
752 if (category) { 752 if (category) {
753 curCategory = *category; 753 curCategory = *category;
754 } else { 754 } else {
755 curCategory = view->getCurrentCategory(); 755 curCategory = view->getCurrentCategory();
756 } 756 }
757 PwMDataItem currItem; 757 PwMDataItem currItem;
758 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { 758 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
759 doc->timer()->putLock(DocTimer::id_autoLockTimer); 759 doc->timer()->putLock(DocTimer::id_autoLockTimer);
760 return; 760 return;
761 } 761 }
762 BUG_ON(currItem.binary); 762 BUG_ON(currItem.binary);
763 AddEntryWndImpl w(doc); 763 AddEntryWndImpl w(doc);
764 w.setCaption( i18n ("Edit password") ); 764 w.setCaption( i18n ("Edit password") );
765 vector<string> catList; 765 vector<string> catList;
766 doc->getCategoryList(&catList); 766 doc->getCategoryList(&catList);
767 unsigned i, size = catList.size(); 767 unsigned i, size = catList.size();
768 for (i = 0; i < size; ++i) { 768 for (i = 0; i < size; ++i) {
769 w.addCategory(catList[i].c_str()); 769 w.addCategory(catList[i].c_str());
770 } 770 }
771 w.setCurrCategory(curCategory); 771 w.setCurrCategory(curCategory);
772 w.setDescription(currItem.desc.c_str()); 772 w.setDescription(currItem.desc.c_str());
773 w.setUsername(currItem.name.c_str()); 773 w.setUsername(currItem.name.c_str());
774 w.setPassword(currItem.pw.c_str()); 774 w.setPassword(currItem.pw.c_str());
775 w.setUrl(currItem.url.c_str()); 775 w.setUrl(currItem.url.c_str());
776 w.setLauncher(currItem.launcher.c_str()); 776 w.setLauncher(currItem.launcher.c_str());
777 w.setComment(currItem.comment.c_str()); 777 w.setComment(currItem.comment.c_str());
778 w.descLineEdit->setFocus(); 778 w.descLineEdit->setFocus();
779 if (w.exec() == 1) { 779 if (w.exec() == 1) {
780 currItem.desc = w.getDescription().latin1(); 780 currItem.desc = w.getDescription().latin1();
781 currItem.name = w.getUsername().latin1(); 781 currItem.name = w.getUsername().latin1();
782 currItem.pw = w.getPassword().latin1(); 782 currItem.pw = w.getPassword().latin1();
783 currItem.comment = w.getComment().latin1(); 783 currItem.comment = w.getComment().latin1();
784 currItem.url = w.getUrl().latin1(); 784 currItem.url = w.getUrl().latin1();
785 currItem.launcher = w.getLauncher().latin1(); 785 currItem.launcher = w.getLauncher().latin1();
786 if (!doc->editEntry(curCategory, w.getCategory(), 786 if (!doc->editEntry(curCategory, w.getCategory(),
787 curEntryIndex, &currItem)) { 787 curEntryIndex, &currItem)) {
788 KMessageBox::error(this, 788 KMessageBox::error(this,
789 i18n("Couldn't edit the entry.\n" 789 i18n("Couldn't edit the entry.\n"
790 "Maybe you changed the category and\n" 790 "Maybe you changed the category and\n"
791 "this entry is already present\nin the new " 791 "this entry is already present\nin the new "
792 "category?"), 792 "category?"),
793 i18n("couldn't edit entry.")); 793 i18n("couldn't edit entry."));
794 doc->timer()->putLock(DocTimer::id_autoLockTimer); 794 doc->timer()->putLock(DocTimer::id_autoLockTimer);
795 return; 795 return;
796 } 796 }
797 } 797 }
798 doc->timer()->putLock(DocTimer::id_autoLockTimer); 798 doc->timer()->putLock(DocTimer::id_autoLockTimer);
799} 799}
800 800
801void PwM::deletePwd_slot() 801void PwM::deletePwd_slot()
802{ 802{
803 PWM_ASSERT(curDoc()); 803 PWM_ASSERT(curDoc());
804 if (curDoc()->isDocEmpty()) 804 if (curDoc()->isDocEmpty())
805 return; 805 return;
806 if (curDoc()->isDeepLocked()) 806 if (curDoc()->isDeepLocked())
807 return; 807 return;
808 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 808 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
809 unsigned int curEntryIndex = 0; 809 unsigned int curEntryIndex = 0;
810 if (!(view->getCurEntryIndex(&curEntryIndex))) { 810 if (!(view->getCurEntryIndex(&curEntryIndex))) {
811 printDebug("couldn't get index"); 811 printDebug("couldn't get index");
812 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 812 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
813 return; 813 return;
814 } 814 }
815 815
816 PwMDataItem currItem; 816 PwMDataItem currItem;
817 QString curCategory = view->getCurrentCategory(); 817 QString curCategory = view->getCurrentCategory();
818 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { 818 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
819 printDebug("couldn't get entry"); 819 printDebug("couldn't get entry");
820 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 820 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
821 return; 821 return;
822 } 822 }
823 if (KMessageBox:: 823 if (KMessageBox::
824 questionYesNo(this, 824 questionYesNo(this,
825 i18n 825 i18n
826 ("Do you really want to delete\nthe selected entry") + 826 ("Do you really want to delete\nthe selected entry") +
827 " \n\"" + QString(currItem.desc.c_str()) 827 " \n\"" + QString(currItem.desc.c_str())
828 + "\" ?", i18n("delete?")) 828 + "\" ?", i18n("delete?"))
829 == KMessageBox::Yes) { 829 == KMessageBox::Yes) {
830 830
831 curDoc()->delEntry(curCategory, curEntryIndex); 831 curDoc()->delEntry(curCategory, curEntryIndex);
832 } 832 }
833 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 833 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
834} 834}
835 835
836void PwM::changeMasterPwd_slot() 836void PwM::changeMasterPwd_slot()
837{ 837{
838 PWM_ASSERT(curDoc()); 838 PWM_ASSERT(curDoc());
839 curDoc()->changeCurrentPw(); 839 curDoc()->changeCurrentPw();
840} 840}
841 841
842void PwM::lockWnd_slot() 842void PwM::lockWnd_slot()
843{ 843{
844 PWM_ASSERT(curDoc()); 844 PWM_ASSERT(curDoc());
845 curDoc()->lockAll(true); 845 curDoc()->lockAll(true);
846} 846}
847 847
848void PwM::deepLockWnd_slot() 848void PwM::deepLockWnd_slot()
849{ 849{
850 PWM_ASSERT(curDoc()); 850 PWM_ASSERT(curDoc());
851 curDoc()->deepLock(); 851 curDoc()->deepLock();
852} 852}
853 853
854void PwM::unlockWnd_slot() 854void PwM::unlockWnd_slot()
855{ 855{
856 PWM_ASSERT(curDoc()); 856 PWM_ASSERT(curDoc());
857 curDoc()->lockAll(false); 857 curDoc()->lockAll(false);
858} 858}
859void PwM::config_global_slot() 859void PwM::config_global_slot()
860{ 860{
861 KPimPrefsGlobalDialog gc ( this ); 861 KPimPrefsGlobalDialog gc ( this );
862 gc.exec(); 862 gc.exec();
863} 863}
864void PwM::config_slot() 864void PwM::config_slot()
865{ 865{
866 int oldStyle = conf()->confWndMainViewStyle(); 866 int oldStyle = conf()->confWndMainViewStyle();
867 867
868#if 0 868#if 0
869 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); 869 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true );
870 870
871 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); 871 KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" );
872 ConfigureDialog->addModule(pwmcfg ); 872 ConfigureDialog->addModule(pwmcfg );
873 873
874 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 874 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
875 ConfigureDialog->addModule(kdelibcfg ); 875 ConfigureDialog->addModule(kdelibcfg );
876#endif 876#endif
877 877
878 878
879 879
880 KDialogBase * ConfigureDialog = new KDialogBase ( KDialogBase::Plain , i18n("Configure KA/Pi"), KDialogBase::Default |KDialogBase::Cancel | KDialogBase::Apply | KDialogBase::Ok, KDialogBase::Ok,0, "name", true, true); 880 KDialogBase * ConfigureDialog = new KDialogBase ( KDialogBase::Plain , i18n("Configure KA/Pi"), KDialogBase::Default |KDialogBase::Cancel | KDialogBase::Apply | KDialogBase::Ok, KDialogBase::Ok,0, "name", true, true);
881 881
882 KCMPwmConfig* kabcfg = new KCMPwmConfig( ConfigureDialog , "KCMpwmConfig" ); 882 KCMPwmConfig* kabcfg = new KCMPwmConfig( ConfigureDialog , "KCMpwmConfig" );
883 ConfigureDialog->setMainWidget( kabcfg ); 883 ConfigureDialog->setMainWidget( kabcfg );
884 connect( ConfigureDialog, SIGNAL( applyClicked() ), 884 connect( ConfigureDialog, SIGNAL( applyClicked() ),
885 kabcfg, SLOT( save() ) ); 885 kabcfg, SLOT( save() ) );
886 connect( ConfigureDialog, SIGNAL( acceptClicked() ), 886 connect( ConfigureDialog, SIGNAL( acceptClicked() ),
887 kabcfg, SLOT( save() ) ); 887 kabcfg, SLOT( save() ) );
888 connect( ConfigureDialog, SIGNAL( defaultClicked() ), 888 connect( ConfigureDialog, SIGNAL( defaultClicked() ),
889 kabcfg, SLOT( defaults() ) ); 889 kabcfg, SLOT( defaults() ) );
890 //saveSettings(); 890 //saveSettings();
891 kabcfg->load(); 891 kabcfg->load();
892#ifndef DESKTOP_VERSION 892#ifndef DESKTOP_VERSION
893 if ( QApplication::desktop()->height() <= 480 ) 893 if ( QApplication::desktop()->height() <= 480 )
894 ;// ConfigureDialog->hideButtons(); 894 ;// ConfigureDialog->hideButtons();
895 ConfigureDialog->showMaximized(); 895 ConfigureDialog->showMaximized();
896#endif 896#endif
897 897
898 898
899 if ( ConfigureDialog->exec() ) 899 if ( ConfigureDialog->exec() )
900 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 900 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
901 delete ConfigureDialog; 901 delete ConfigureDialog;
902 902
903 903
904 904
905 int newStyle = conf()->confWndMainViewStyle(); 905 int newStyle = conf()->confWndMainViewStyle();
906 // reinitialize tray 906 // reinitialize tray
907 init->initTray(); 907 init->initTray();
908 // reinitialize KWallet emulation 908 // reinitialize KWallet emulation
909 init->initKWalletEmu(); 909 init->initKWalletEmu();
910 910
911 PwMDocList *_dl = PwMDoc::getOpenDocList(); 911 PwMDocList *_dl = PwMDoc::getOpenDocList();
912 const vector<PwMDocList::listItem> *dl = _dl->getList(); 912 const vector<PwMDocList::listItem> *dl = _dl->getList();
913 vector<PwMDocList::listItem>::const_iterator i = dl->begin(), 913 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
914 end = dl->end(); 914 end = dl->end();
915 PwMDoc *doc; 915 PwMDoc *doc;
916 while (i != end) { 916 while (i != end) {
917 doc = (*i).doc; 917 doc = (*i).doc;
918 // unlock-without-mpw timeout 918 // unlock-without-mpw timeout
919 doc->timer()->start(DocTimer::id_mpwTimer); 919 doc->timer()->start(DocTimer::id_mpwTimer);
920 // auto-lock timeout 920 // auto-lock timeout
921 doc->timer()->start(DocTimer::id_autoLockTimer); 921 doc->timer()->start(DocTimer::id_autoLockTimer);
922 ++i; 922 ++i;
923 } 923 }
924 924
925 const QValueList<PwM *> *ml = init->mainWndList(); 925 const QValueList<PwM *> *ml = init->mainWndList();
926#ifndef PWM_EMBEDDED 926#ifndef PWM_EMBEDDED
927 QValueList<PwM *>::const_iterator i2 = ml->begin(), 927 QValueList<PwM *>::const_iterator i2 = ml->begin(),
928 end2 = ml->end(); 928 end2 = ml->end();
929#else 929#else
930 QValueList<PwM *>::ConstIterator i2 = ml->begin(), 930 QValueList<PwM *>::ConstIterator i2 = ml->begin(),
931 end2 = ml->end(); 931 end2 = ml->end();
932#endif 932#endif
933 PwM *pwm; 933 PwM *pwm;
934 while (i2 != end2) { 934 while (i2 != end2) {
935 pwm = *i2; 935 pwm = *i2;
936 // reinitialize the window style. 936 // reinitialize the window style.
937 if (oldStyle != newStyle) 937 if (oldStyle != newStyle)
938 pwm->curView()->initStyle(newStyle); 938 pwm->curView()->initStyle(newStyle);
939 // set the new font 939 // set the new font
940 pwm->curView()->setFont(conf()->confGlobEntryFont()); 940 pwm->curView()->setFont(conf()->confGlobEntryFont());
941 ++i2; 941 ++i2;
942 } 942 }
943} 943}
944 944
945void PwM::activateMpButton(bool activate) 945void PwM::activateMpButton(bool activate)
946{ 946{
947 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); 947 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
948} 948}
949 949
950void PwM::closeEvent(QCloseEvent *e) 950void PwM::closeEvent(QCloseEvent *e)
951{ 951{
952 //qDebug("PwM::closeEvent "); 952 //qDebug("PwM::closeEvent ");
953 emit closed( this ); 953 emit closed( this );
954 return; 954 return;
955 e->accept(); 955 e->accept();
956} 956}
957 957
958void PwM::docClosed(PwMDoc *doc) 958void PwM::docClosed(PwMDoc *doc)
959{ 959{
960 //qDebug("PwM::docClosed "); 960 //qDebug("PwM::docClosed ");
961 PARAM_UNUSED(doc); 961 PARAM_UNUSED(doc);
962 PWM_ASSERT(doc == curDoc()); 962 PWM_ASSERT(doc == curDoc());
963 close(); 963 close();
964} 964}
965 965
966void PwM::find_slot() 966void PwM::find_slot()
967{ 967{
968 PWM_ASSERT(curDoc()); 968 PWM_ASSERT(curDoc());
969 if (curDoc()->isDocEmpty()) 969 if (curDoc()->isDocEmpty())
970 return; 970 return;
971 if (curDoc()->isDeepLocked()) 971 if (curDoc()->isDeepLocked())
972 return; 972 return;
973 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 973 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
974 FindWndImpl findWnd(view); 974 FindWndImpl findWnd(view);
975 findWnd.exec(); 975 findWnd.exec();
976 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 976 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
977} 977}
978 978
979void PwM::exportToText() 979void PwM::exportToText()
980{ 980{
981 PWM_ASSERT(curDoc()); 981 PWM_ASSERT(curDoc());
982 if (curDoc()->isDocEmpty()) { 982 if (curDoc()->isDocEmpty()) {
983 KMessageBox::information(this, 983 KMessageBox::information(this,
984 i18n 984 i18n
985 ("Sorry, there's nothing to export.\n" 985 ("Sorry, there's nothing to export.\n"
986 "Please first add some passwords."), 986 "Please first add some passwords."),
987 i18n("nothing to do")); 987 i18n("nothing to do"));
988 return; 988 return;
989 } 989 }
990 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 990 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
991 QString fn(KFileDialog::getSaveFileName(QString::null, 991 QString fn(KFileDialog::getSaveFileName(QString::null,
992 i18n("*|plain-text file"), 992 i18n("*|plain-text file"),
993 this)); 993 this));
994 if (fn == "") { 994 if (fn == "") {
995 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 995 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
996 return; 996 return;
997 } 997 }
998 998
999 PwMerror ret = curDoc()->exportToText(&fn); 999 PwMerror ret = curDoc()->exportToText(&fn);
1000 if (ret != e_success) { 1000 if (ret != e_success) {
1001 KMessageBox::error(this, 1001 KMessageBox::error(this,
1002 i18n("Error: Couldn't write to file.\n" 1002 i18n("Error: Couldn't write to file.\n"
1003 "Please check if you have permission to write\n" 1003 "Please check if you have permission to write\n"
1004 "to the file in that directory."), 1004 "to the file in that directory."),
1005 i18n("error while writing")); 1005 i18n("error while writing"));
1006 } else 1006 } else
1007 showStatMsg(i18n("Successfully exported data.")); 1007 showStatMsg(i18n("Successfully exported data."));
1008 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1008 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1009} 1009}
1010 1010
1011bool PwM::importFromText() 1011bool PwM::importFromText()
1012{ 1012{
1013 if (!isVirgin()) { 1013 if (!isVirgin()) {
1014 if (KMessageBox::questionYesNo(this, 1014 if (KMessageBox::questionYesNo(this,
1015 i18n("Do you want to import the data\n" 1015 i18n("Do you want to import the data\n"
1016 "into the current document? (If you\n" 1016 "into the current document? (If you\n"
1017 "select \"no\", a new document will be\n" 1017 "select \"no\", a new document will be\n"
1018 "opened.)"), 1018 "opened.)"),
1019 i18n("import into this document?")) 1019 i18n("import into this document?"))
1020 == KMessageBox::No) { 1020 == KMessageBox::No) {
1021 // import the data to a new window. 1021 // import the data to a new window.
1022 PwM *newInstance = init->createMainWnd(); 1022 PwM *newInstance = init->createMainWnd();
1023 bool ok = newInstance->importFromText(); 1023 bool ok = newInstance->importFromText();
1024 if (!ok) { 1024 if (!ok) {
1025 newInstance->setForceQuit(true); 1025 newInstance->setForceQuit(true);
1026 delete_and_null(newInstance); 1026 delete_and_null(newInstance);
1027 } 1027 }
1028 return ok; 1028 return ok;
1029 } 1029 }
1030 } 1030 }
1031 1031
1032 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1032 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1033 PwMerror ret; 1033 PwMerror ret;
1034 QString path(KFileDialog::getOpenFileName(QString::null, 1034 QString path(KFileDialog::getOpenFileName(QString::null,
1035 i18n("*|PWM-exported text file"), 1035 i18n("*|PWM-exported text file"),
1036 this)); 1036 this));
1037 if (path == "") 1037 if (path == "")
1038 goto cancelImport; 1038 goto cancelImport;
1039 1039
1040 ret = curDoc()->importFromText(&path, 0); 1040 ret = curDoc()->importFromText(&path, 0);
1041 if (ret == e_fileFormat) { 1041 if (ret == e_fileFormat) {
1042 KMessageBox::error(this, 1042 KMessageBox::error(this,
1043 i18n("Could not read file-format.\n" 1043 i18n("Could not read file-format.\n"
1044 "This seems to be _not_ a valid file\n" 1044 "This seems to be _not_ a valid file\n"
1045 "exported by PwM."), 1045 "exported by PwM."),
1046 i18n("invalid file-format")); 1046 i18n("invalid file-format"));
1047 goto cancelImport; 1047 goto cancelImport;
1048 } else if (ret == e_invalidArg) { 1048 } else if (ret == e_invalidArg) {
1049 BUG(); 1049 BUG();
1050 goto cancelImport; 1050 goto cancelImport;
1051 } else if (ret != e_success) { 1051 } else if (ret != e_success) {
1052 KMessageBox::error(this, 1052 KMessageBox::error(this,
1053 i18n("Could not import file!\n" 1053 i18n("Could not import file!\n"
1054 "Do you have permission to read this file?\n" 1054 "Do you have permission to read this file?\n"
1055 "Do you have enough free memory?"), 1055 "Do you have enough free memory?"),
1056 i18n("import failed")); 1056 i18n("import failed"));
1057 goto cancelImport; 1057 goto cancelImport;
1058 } 1058 }
1059 setVirgin(false); 1059 setVirgin(false);
1060 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1060 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1061 return true; 1061 return true;
1062 1062
1063cancelImport: 1063cancelImport:
1064 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1064 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1065 return false; 1065 return false;
1066} 1066}
1067 1067
1068void PwM::exportToGpasman() 1068void PwM::exportToGpasman()
1069{ 1069{
1070 PWM_ASSERT(curDoc()); 1070 PWM_ASSERT(curDoc());
1071 if (curDoc()->isDocEmpty()) { 1071 if (curDoc()->isDocEmpty()) {
1072 KMessageBox::information(this, 1072 KMessageBox::information(this,
1073 i18n 1073 i18n
1074 ("Sorry, there's nothing to export.\n" 1074 ("Sorry, there's nothing to export.\n"
1075 "Please first add some passwords."), 1075 "Please first add some passwords."),
1076 i18n("nothing to do")); 1076 i18n("nothing to do"));
1077 return; 1077 return;
1078 } 1078 }
1079 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1079 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1080 QString fn(KFileDialog::getSaveFileName(QString::null, 1080 QString fn(KFileDialog::getSaveFileName(QString::null,
1081 i18n("*|Gpasman or Kpasman file"), 1081 i18n("*|Gpasman or Kpasman file"),
1082 this)); 1082 this));
1083 if (fn == "") { 1083 if (fn == "") {
1084 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1084 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1085 return; 1085 return;
1086 } 1086 }
1087 1087
1088 PwMerror ret = curDoc()->exportToGpasman(&fn); 1088 PwMerror ret = curDoc()->exportToGpasman(&fn);
1089 if (ret != e_success) { 1089 if (ret != e_success) {
1090 if (ret == e_noPw) { 1090 if (ret == e_noPw) {
1091 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1091 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1092 return; 1092 return;
1093 } 1093 }
1094 KMessageBox::error(this, 1094 KMessageBox::error(this,
1095 i18n("Error: Couldn't write to file.\n" 1095 i18n("Error: Couldn't write to file.\n"
1096 "Please check if you have permission to write " 1096 "Please check if you have permission to write "
1097 "to the file in that directory."), 1097 "to the file in that directory."),
1098 i18n("error while writing")); 1098 i18n("error while writing"));
1099 } else 1099 } else
1100 showStatMsg(i18n("Successfully exported data.")); 1100 showStatMsg(i18n("Successfully exported data."));
1101 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1101 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1102} 1102}
1103 1103
1104 1104
1105 1105
1106void PwM::exportToCsv() 1106void PwM::exportToCsv()
1107{ 1107{
1108 PWM_ASSERT(curDoc()); 1108 PWM_ASSERT(curDoc());
1109 if (curDoc()->isDocEmpty()) { 1109 if (curDoc()->isDocEmpty()) {
1110 KMessageBox::information(this, 1110 KMessageBox::information(this,
1111 i18n 1111 i18n
1112 ("Sorry, there is nothing to export;\n" 1112 ("Sorry, there is nothing to export;\n"
1113 "please add some passwords first."), 1113 "please add some passwords first."),
1114 i18n("Nothing to Do")); 1114 i18n("Nothing to Do"));
1115 return; 1115 return;
1116 } 1116 }
1117 1117
1118 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1118 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1119 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); 1119 QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this));
1120 if (fn.isEmpty()) { 1120 if (fn.isEmpty()) {
1121 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1121 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1122 return; 1122 return;
1123 } 1123 }
1124 1124
1125 Csv csv(this); 1125 Csv csv(this);
1126 if (!csv.exportData(fn, curDoc())) { 1126 if (!csv.exportData(fn, curDoc())) {
1127 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1127 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1128 showStatMsg(i18n("CSV file export failed.")); 1128 showStatMsg(i18n("CSV file export failed."));
1129 return; 1129 return;
1130 } 1130 }
1131 showStatMsg(i18n("Successfully exported data.")); 1131 showStatMsg(i18n("Successfully exported data."));
1132 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1132 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1133} 1133}
1134 1134
1135bool PwM::importCsv() 1135bool PwM::importCsv()
1136{ 1136{
1137 Csv csv(this); 1137 Csv csv(this);
1138 if (!isVirgin()) { 1138 if (!isVirgin()) {
1139 if (KMessageBox::questionYesNo(this, 1139 if (KMessageBox::questionYesNo(this,
1140 i18n("Do you want to import the data\n" 1140 i18n("Do you want to import the data\n"
1141 "into the current document? (If you\n" 1141 "into the current document? (If you\n"
1142 "select \"no\", a new document will be\n" 1142 "select \"no\", a new document will be\n"
1143 "opened.)"), 1143 "opened.)"),
1144 i18n("Import into This Document?")) 1144 i18n("Import into This Document?"))
1145 == KMessageBox::No) { 1145 == KMessageBox::No) {
1146 // import the data to a new window. 1146 // import the data to a new window.
1147 PwM *newInstance = init->createMainWnd(); 1147 PwM *newInstance = init->createMainWnd();
1148 bool ok = newInstance->importCsv(); 1148 bool ok = newInstance->importCsv();
1149 if (!ok) { 1149 if (!ok) {
1150 newInstance->setForceQuit(true); 1150 newInstance->setForceQuit(true);
1151 delete_and_null(newInstance); 1151 delete_and_null(newInstance);
1152 } 1152 }
1153 return ok; 1153 return ok;
1154 } 1154 }
1155 } 1155 }
1156 1156
1157 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); 1157 QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this);
1158 if (filename.isEmpty()) 1158 if (filename.isEmpty())
1159 return false; 1159 return false;
1160 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1160 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1161 if (!csv.importData(filename, curDoc())) { 1161 if (!csv.importData(filename, curDoc())) {
1162 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1162 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1163 showStatMsg(i18n("CSV file import failed.")); 1163 showStatMsg(i18n("CSV file import failed."));
1164 return false; 1164 return false;
1165 } 1165 }
1166 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1166 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1167 KMessageBox::information(this, 1167 KMessageBox::information(this,
1168 i18n("Successfully imported the CSV data\n" 1168 i18n("Successfully imported the CSV data\n"
1169 "into the current document."), i18n("Successfully Imported")); 1169 "into the current document."), i18n("Successfully Imported"));
1170 showStatMsg(i18n("Successfully imported")); 1170 showStatMsg(i18n("Successfully imported"));
1171 setVirgin(false); 1171 setVirgin(false);
1172 return true; 1172 return true;
1173} 1173}
1174 1174
1175 1175
1176void PwM::exportToKWallet() 1176void PwM::exportToKWallet()
1177{ 1177{
1178#ifdef CONFIG_KWALLETIF 1178#ifdef CONFIG_KWALLETIF
1179 if (!checkAndAskForKWalletEmu()) 1179 if (!checkAndAskForKWalletEmu())
1180 return; 1180 return;
1181 PWM_ASSERT(curDoc()); 1181 PWM_ASSERT(curDoc());
1182 if (curDoc()->isDocEmpty()) { 1182 if (curDoc()->isDocEmpty()) {
1183 KMessageBox::information(this, 1183 KMessageBox::information(this,
1184 i18n 1184 i18n
1185 ("Sorry, there's nothing to export.\n" 1185 ("Sorry, there's nothing to export.\n"
1186 "Please first add some passwords."), 1186 "Please first add some passwords."),
1187 i18n("nothing to do")); 1187 i18n("nothing to do"));
1188 init->initKWalletEmu(); 1188 init->initKWalletEmu();
1189 return; 1189 return;
1190 } 1190 }
1191 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1191 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1192 KWalletIf walletIf(this); 1192 KWalletIf walletIf(this);
1193 if (walletIf.kwalletExport(curDoc())) { 1193 if (walletIf.kwalletExport(curDoc())) {
1194 KMessageBox::information(this, 1194 KMessageBox::information(this,
1195 i18n("Successfully exported the data of the current " 1195 i18n("Successfully exported the data of the current "
1196 "document to KWallet."), 1196 "document to KWallet."),
1197 i18n("Successfully exported data.")); 1197 i18n("Successfully exported data."));
1198 showStatMsg(i18n("Successfully exported data.")); 1198 showStatMsg(i18n("Successfully exported data."));
1199 } 1199 }
1200 init->initKWalletEmu(); 1200 init->initKWalletEmu();
1201 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1201 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1202#endif // CONFIG_KWALLETIF 1202#endif // CONFIG_KWALLETIF
1203} 1203}
1204 1204
1205bool PwM::importFromGpasman() 1205bool PwM::importFromGpasman()
1206{ 1206{
1207 if (!isVirgin()) { 1207 if (!isVirgin()) {
1208 if (KMessageBox::questionYesNo(this, 1208 if (KMessageBox::questionYesNo(this,
1209 i18n("Do you want to import the data\n" 1209 i18n("Do you want to import the data\n"
1210 "into the current document? (If you\n" 1210 "into the current document? (If you\n"
1211 "select \"no\", a new document will be\n" 1211 "select \"no\", a new document will be\n"
1212 "opened.)"), 1212 "opened.)"),
1213 i18n("import into this document?")) 1213 i18n("import into this document?"))
1214 == KMessageBox::No) { 1214 == KMessageBox::No) {
1215 // import the data to a new window. 1215 // import the data to a new window.
1216 PwM *newInstance = init->createMainWnd(); 1216 PwM *newInstance = init->createMainWnd();
1217 bool ok = newInstance->importFromGpasman(); 1217 bool ok = newInstance->importFromGpasman();
1218 if (!ok) { 1218 if (!ok) {
1219 newInstance->setForceQuit(true); 1219 newInstance->setForceQuit(true);
1220 delete_and_null(newInstance); 1220 delete_and_null(newInstance);
1221 } 1221 }
1222 return ok; 1222 return ok;
1223 } 1223 }
1224 } 1224 }
1225 1225
1226 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1226 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1227 PwMerror ret; 1227 PwMerror ret;
1228 QString path(KFileDialog::getOpenFileName(QString::null, 1228 QString path(KFileDialog::getOpenFileName(QString::null,
1229 i18n("*|Gpasman or Kpasman file"), this)); 1229 i18n("*|Gpasman or Kpasman file"), this));
1230 if (path == "") 1230 if (path == "")
1231 goto cancelImport; 1231 goto cancelImport;
1232 ret = curDoc()->importFromGpasman(&path); 1232 ret = curDoc()->importFromGpasman(&path);
1233 if (ret == e_wrongPw) { 1233 if (ret == e_wrongPw) {
1234 if (KMessageBox::questionYesNo(this, 1234 if (KMessageBox::questionYesNo(this,
1235 i18n 1235 i18n
1236 ("This is probably the wrong master-password\n" 1236 ("This is probably the wrong master-password\n"
1237 "you have typed in.\n" 1237 "you have typed in.\n"
1238 "There is no real way to determine the\n" 1238 "There is no real way to determine the\n"
1239 "correctness of the password in the Gpasman\n" 1239 "correctness of the password in the Gpasman\n"
1240 "file-format. But I think this\n" 1240 "file-format. But I think this\n"
1241 "password ist wrong.\n" 1241 "password ist wrong.\n"
1242 "Do you want to continue nevertheless?"), 1242 "Do you want to continue nevertheless?"),
1243 i18n("password error")) 1243 i18n("password error"))
1244 == KMessageBox::No) { 1244 == KMessageBox::No) {
1245 goto cancelImport; 1245 goto cancelImport;
1246 } 1246 }
1247 } else if (ret != e_success) { 1247 } else if (ret != e_success) {
1248 KMessageBox::error(this, 1248 KMessageBox::error(this,
1249 i18n("Could not import file!\n" 1249 i18n("Could not import file!\n"
1250 "Do you have permission to read this file?"), 1250 "Do you have permission to read this file?"),
1251 i18n("import failed")); 1251 i18n("import failed"));
1252 goto cancelImport; 1252 goto cancelImport;
1253 } 1253 }
1254 setVirgin(false); 1254 setVirgin(false);
1255 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1255 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1256 return true; 1256 return true;
1257 1257
1258cancelImport: 1258cancelImport:
1259 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1259 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1260 return false; 1260 return false;
1261} 1261}
1262 1262
1263#ifdef CONFIG_KWALLETIF 1263#ifdef CONFIG_KWALLETIF
1264bool PwM::checkAndAskForKWalletEmu() 1264bool PwM::checkAndAskForKWalletEmu()
1265{ 1265{
1266 if (init->kwalletEmu()) { 1266 if (init->kwalletEmu()) {
1267 /* KWallet emulation is enabled. We can't import/export 1267 /* KWallet emulation is enabled. We can't import/export
1268 * data from/to it, while emulation is active. 1268 * data from/to it, while emulation is active.
1269 */ 1269 */
1270 if (KMessageBox::questionYesNo(this, 1270 if (KMessageBox::questionYesNo(this,
1271 i18n("KWallet emulation is enabled.\n" 1271 i18n("KWallet emulation is enabled.\n"
1272 "You can't import or export data from/to " 1272 "You can't import or export data from/to "
1273 "the original KWallet, while the emulation " 1273 "the original KWallet, while the emulation "
1274 "is active.\n" 1274 "is active.\n"
1275 "Do you want to tempoarly disable the KWallet emulation?"), 1275 "Do you want to tempoarly disable the KWallet emulation?"),
1276 i18n("Tempoarly disable KWallet emulation?")) 1276 i18n("Tempoarly disable KWallet emulation?"))
1277 == KMessageBox::Yes) { 1277 == KMessageBox::Yes) {
1278 init->initKWalletEmu(true); 1278 init->initKWalletEmu(true);
1279 PWM_ASSERT(!init->kwalletEmu()); 1279 PWM_ASSERT(!init->kwalletEmu());
1280 return true; 1280 return true;
1281 } 1281 }
1282 return false; 1282 return false;
1283 } 1283 }
1284 return true; 1284 return true;
1285} 1285}
1286#endif // CONFIG_KWALLETIF 1286#endif // CONFIG_KWALLETIF
1287 1287
1288bool PwM::importKWallet() 1288bool PwM::importKWallet()
1289{ 1289{
1290#ifdef CONFIG_KWALLETIF 1290#ifdef CONFIG_KWALLETIF
1291 if (!checkAndAskForKWalletEmu()) 1291 if (!checkAndAskForKWalletEmu())
1292 return false; 1292 return false;
1293 KWalletIf walletIf(this); 1293 KWalletIf walletIf(this);
1294 if (!isVirgin()) { 1294 if (!isVirgin()) {
1295 if (KMessageBox::questionYesNo(this, 1295 if (KMessageBox::questionYesNo(this,
1296 i18n("Do you want to import the data " 1296 i18n("Do you want to import the data "
1297 "into the current document? (If you " 1297 "into the current document? (If you "
1298 "select \"no\", a new document will be " 1298 "select \"no\", a new document will be "
1299 "opened.)"), 1299 "opened.)"),
1300 i18n("import into this document?")) 1300 i18n("import into this document?"))
1301 == KMessageBox::No) { 1301 == KMessageBox::No) {
1302 // import the data to a new window. 1302 // import the data to a new window.
1303 PwM *newInstance = init->createMainWnd(); 1303 PwM *newInstance = init->createMainWnd();
1304 bool ok = newInstance->importKWallet(); 1304 bool ok = newInstance->importKWallet();
1305 if (!ok) { 1305 if (!ok) {
1306 newInstance->setForceQuit(true); 1306 newInstance->setForceQuit(true);
1307 delete_and_null(newInstance); 1307 delete_and_null(newInstance);
1308 goto exit_fail; 1308 goto exit_fail;
1309 } else { 1309 } else {
1310 goto exit_ok; 1310 goto exit_ok;
1311 } 1311 }
1312 } 1312 }
1313 } 1313 }
1314 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1314 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1315 if (!walletIf.kwalletImport(curDoc())) { 1315 if (!walletIf.kwalletImport(curDoc())) {
1316 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1316 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1317 showStatMsg(i18n("KWallet import failed")); 1317 showStatMsg(i18n("KWallet import failed"));
1318 goto exit_fail; 1318 goto exit_fail;
1319 } 1319 }
1320 KMessageBox::information(this, 1320 KMessageBox::information(this,
1321 i18n("Successfully imported the KWallet data " 1321 i18n("Successfully imported the KWallet data "
1322 "into the current document."), 1322 "into the current document."),
1323 i18n("successfully imported")); 1323 i18n("successfully imported"));
1324 showStatMsg(i18n("successfully imported")); 1324 showStatMsg(i18n("successfully imported"));
1325 setVirgin(false); 1325 setVirgin(false);
1326 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1326 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1327 1327
1328exit_ok: 1328exit_ok:
1329 init->initKWalletEmu(); 1329 init->initKWalletEmu();
1330 return true; 1330 return true;
1331 1331
1332exit_fail: 1332exit_fail:
1333 init->initKWalletEmu(); 1333 init->initKWalletEmu();
1334#endif // CONFIG_KWALLETIF 1334#endif // CONFIG_KWALLETIF
1335 return false; 1335 return false;
1336} 1336}
1337 1337
1338void PwM::print_slot() 1338void PwM::print_slot()
1339{ 1339{
1340 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); 1340 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1341#ifndef PWM_EMBEDDED 1341#ifndef PWM_EMBEDDED
1342 PwMPrint p(curDoc(), this); 1342 PwMPrint p(curDoc(), this);
1343 p.printNow(); 1343 p.printNow();
1344#else 1344#else
1345 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); 1345 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
1346#endif 1346#endif
1347 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); 1347 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1348} 1348}
1349 1349
1350void PwM::genNewCard_slot() 1350void PwM::genNewCard_slot()
1351{ 1351{
1352#ifdef CONFIG_KEYCARD 1352#ifdef CONFIG_KEYCARD
1353 init->keycard()->genNewCard(); 1353 init->keycard()->genNewCard();
1354#endif 1354#endif
1355} 1355}
1356 1356
1357void PwM::eraseCard_slot() 1357void PwM::eraseCard_slot()
1358{ 1358{
1359#ifdef CONFIG_KEYCARD 1359#ifdef CONFIG_KEYCARD
1360 init->keycard()->eraseCard(); 1360 init->keycard()->eraseCard();
1361#endif 1361#endif
1362} 1362}
1363 1363
1364void PwM::readCardId_slot() 1364void PwM::readCardId_slot()
1365{ 1365{
1366#ifdef CONFIG_KEYCARD 1366#ifdef CONFIG_KEYCARD
1367 init->keycard()->displayKey(); 1367 init->keycard()->displayKey();
1368#endif 1368#endif
1369} 1369}
1370 1370
1371void PwM::makeCardBackup_slot() 1371void PwM::makeCardBackup_slot()
1372{ 1372{
1373#ifdef CONFIG_KEYCARD 1373#ifdef CONFIG_KEYCARD
1374 init->keycard()->makeBackupImage(); 1374 init->keycard()->makeBackupImage();
1375#endif 1375#endif
1376} 1376}
1377 1377
1378void PwM::replayCardBackup_slot() 1378void PwM::replayCardBackup_slot()
1379{ 1379{
1380#ifdef CONFIG_KEYCARD 1380#ifdef CONFIG_KEYCARD
1381 init->keycard()->replayBackupImage(); 1381 init->keycard()->replayBackupImage();
1382#endif 1382#endif
1383} 1383}
1384 1384
1385void PwM::execLauncher_slot() 1385void PwM::execLauncher_slot()
1386{ 1386{
1387 PWM_ASSERT(curDoc()); 1387 PWM_ASSERT(curDoc());
1388 if (curDoc()->isDeepLocked()) 1388 if (curDoc()->isDeepLocked())
1389 return; 1389 return;
1390 unsigned int curEntryIndex; 1390 unsigned int curEntryIndex;
1391 if (!view->getCurEntryIndex(&curEntryIndex)) 1391 if (!view->getCurEntryIndex(&curEntryIndex))
1392 return; 1392 return;
1393 bool ret = curDoc()->execLauncher(view->getCurrentCategory(), 1393 bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
1394 curEntryIndex); 1394 curEntryIndex);
1395 if (ret) 1395 if (ret)
1396 showStatMsg(i18n("Executed the \"Launcher\".")); 1396 showStatMsg(i18n("Executed the \"Launcher\"."));
1397 else 1397 else
1398 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); 1398 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
1399} 1399}
1400 1400
1401void PwM::goToURL_slot() 1401void PwM::goToURL_slot()
1402{ 1402{
1403 PWM_ASSERT(curDoc()); 1403 PWM_ASSERT(curDoc());
1404 if (curDoc()->isDeepLocked()) 1404 if (curDoc()->isDeepLocked())
1405 return; 1405 return;
1406 unsigned int curEntryIndex; 1406 unsigned int curEntryIndex;
1407 if (!view->getCurEntryIndex(&curEntryIndex)) 1407 if (!view->getCurEntryIndex(&curEntryIndex))
1408 return; 1408 return;
1409 bool ret = curDoc()->goToURL(view->getCurrentCategory(), 1409 bool ret = curDoc()->goToURL(view->getCurrentCategory(),
1410 curEntryIndex); 1410 curEntryIndex);
1411 if (ret) 1411 if (ret)
1412 showStatMsg(i18n("started browser with current URL.")); 1412 showStatMsg(i18n("started browser with current URL."));
1413 else 1413 else
1414 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); 1414 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
1415} 1415}
1416 1416
1417void PwM::copyToClipboard(const QString &s) 1417void PwM::copyToClipboard(const QString &s)
1418{ 1418{
1419 QClipboard *cb = QApplication::clipboard(); 1419 QClipboard *cb = QApplication::clipboard();
1420#ifndef PWM_EMBEDDED 1420#ifndef PWM_EMBEDDED
1421 if (cb->supportsSelection()) 1421 if (cb->supportsSelection())
1422 cb->setText(s, QClipboard::Selection); 1422 cb->setText(s, QClipboard::Selection);
1423 cb->setText(s, QClipboard::Clipboard); 1423 cb->setText(s, QClipboard::Clipboard);
1424#else 1424#else
1425 cb->setText(s); 1425 cb->setText(s);
1426 1426
1427#endif 1427#endif
1428 1428
1429} 1429}
1430 1430
1431 1431
1432void PwM::showStatMsg(const QString &msg) 1432void PwM::showStatMsg(const QString &msg)
1433{ 1433{
1434#ifdef DESKTOP_VERSION 1434#ifdef DESKTOP_VERSION
1435 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); 1435 statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
1436#else 1436#else
1437 //qDebug("Statusbar : %s",msg.latin1()); 1437 //qDebug("Statusbar : %s",msg.latin1());
1438 Global::statusMessage(msg); 1438 Global::statusMessage(msg);
1439#endif 1439#endif
1440} 1440}
1441 1441
1442void PwM::focusInEvent(QFocusEvent *e) 1442void PwM::focusInEvent(QFocusEvent *e)
1443{ 1443{
1444 if (e->gotFocus()) { 1444 if (e->gotFocus()) {
1445 emit gotFocus(this); 1445 emit gotFocus(this);
1446 } else if (e->lostFocus()) { 1446 } else if (e->lostFocus()) {
1447 emit lostFocus(this); 1447 emit lostFocus(this);
1448 } 1448 }
1449} 1449}
1450 1450
1451 1451
1452#ifdef PWM_EMBEDDED 1452#ifdef PWM_EMBEDDED
1453 1453
1454void PwM::category_slot() 1454void PwM::category_slot()
1455{ 1455{
1456 PwMDoc *doc = curDoc(); 1456 PwMDoc *doc = curDoc();
1457 PWM_ASSERT(doc); 1457 PWM_ASSERT(doc);
1458 doc->timer()->getLock(DocTimer::id_autoLockTimer); 1458 doc->timer()->getLock(DocTimer::id_autoLockTimer);
1459 1459
1460 editCategoryWnd w(doc, this, "editcategory"); 1460 editCategoryWnd w(doc, this, "editcategory");
1461/* 1461/*
1462 vector<string> catList; 1462 vector<string> catList;
1463 doc->getCategoryList(&catList); 1463 doc->getCategoryList(&catList);
1464 unsigned i, size = catList.size(); 1464 unsigned i, size = catList.size();
1465 for (i = 0; i < size; ++i) { 1465 for (i = 0; i < size; ++i) {
1466 w.addCategory(catList[i].c_str()); 1466 w.addCategory(catList[i].c_str());
1467 } 1467 }
1468 w.setCurrCategory(view->getCurrentCategory()); 1468 w.setCurrCategory(view->getCurrentCategory());
1469 if (pw) 1469 if (pw)
1470 w.pwLineEdit->setText(*pw); 1470 w.pwLineEdit->setText(*pw);
1471*/ 1471*/
1472 w.setCurrCategory(view->getCurrentCategory()); 1472 w.setCurrCategory(view->getCurrentCategory());
1473 1473
1474 tryAgain: 1474 tryAgain:
1475 if (w.exec() == 1) 1475 if (w.exec() == 1)
1476 { 1476 {
1477 PwMDataItem d; 1477 PwMDataItem d;
1478 1478
1479 //US BUG: to initialize all values of curEntr with meaningfulldata, 1479 //US BUG: to initialize all values of curEntr with meaningfulldata,
1480 // we call clear on it. Reason: Metadata will be uninitialized otherwise. 1480 // we call clear on it. Reason: Metadata will be uninitialized otherwise.
1481 // another option would be to create a constructor for PwMDataItem 1481 // another option would be to create a constructor for PwMDataItem
1482 d.clear(true); 1482 d.clear(true);
1483 /* 1483 /*
1484 d.desc = w.getDescription().latin1(); 1484 d.desc = w.getDescription().latin1();
1485 d.name = w.getUsername().latin1(); 1485 d.name = w.getUsername().latin1();
1486 d.pw = w.getPassword().latin1(); 1486 d.pw = w.getPassword().latin1();
1487 d.comment = w.getComment().latin1(); 1487 d.comment = w.getComment().latin1();
1488 d.url = w.getUrl().latin1(); 1488 d.url = w.getUrl().latin1();
1489 d.launcher = w.getLauncher().latin1(); 1489 d.launcher = w.getLauncher().latin1();
1490 PwMerror ret = doc->addEntry(w.getCategory(), &d); 1490 PwMerror ret = doc->addEntry(w.getCategory(), &d);
1491 if (ret == e_entryExists) { 1491 if (ret == e_entryExists) {
1492 KMessageBox::error(this, 1492 KMessageBox::error(this,
1493 i18n 1493 i18n
1494 ("An entry with this \"Description\",\n" 1494 ("An entry with this \"Description\",\n"
1495 "does already exist.\n" 1495 "does already exist.\n"
1496 "Please select another description."), 1496 "Please select another description."),
1497 i18n("entry already exists.")); 1497 i18n("entry already exists."));
1498 goto tryAgain; 1498 goto tryAgain;
1499 } else if (ret == e_maxAllowedEntr) { 1499 } else if (ret == e_maxAllowedEntr) {
1500 KMessageBox::error(this, i18n("The maximum possible number of\nentries" 1500 KMessageBox::error(this, i18n("The maximum possible number of\nentries"
1501 "has been reached.\nYou can't add more entries."), 1501 "has been reached.\nYou can't add more entries."),
1502 i18n("maximum number of entries")); 1502 i18n("maximum number of entries"));
1503 doc->timer()->putLock(DocTimer::id_autoLockTimer); 1503 doc->timer()->putLock(DocTimer::id_autoLockTimer);
1504 return; 1504 return;
1505 } 1505 }
1506 */ 1506 */
1507 } 1507 }
1508 setVirgin(false); 1508 setVirgin(false);
1509 doc->timer()->putLock(DocTimer::id_autoLockTimer); 1509 doc->timer()->putLock(DocTimer::id_autoLockTimer);
1510} 1510}
1511 1511
1512 1512
1513void PwM::whatsnew_slot() 1513void PwM::whatsnew_slot()
1514{ 1514{
1515 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 1515 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
1516} 1516}
1517 1517
1518void PwM::showLicense_slot() 1518void PwM::showLicense_slot()
1519{ 1519{
1520 KApplication::showLicence(); 1520 KApplication::showLicence();
1521} 1521}
1522 1522
1523void PwM::faq_slot() 1523void PwM::faq_slot()
1524{ 1524{
1525 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); 1525 KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" );
1526} 1526}
1527 1527
1528void PwM::syncHowTo_slot() 1528void PwM::syncHowTo_slot()
1529{ 1529{
1530 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 1530 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
1531} 1531}
1532 1532
1533 1533
1534void PwM::createAboutData_slot() 1534void PwM::createAboutData_slot()
1535{ 1535{
1536 QString version; 1536 QString version;
1537#include <../version> 1537#include <../version>
1538; 1538;
1539 QMessageBox::about( this, "About PwManager/Pi", 1539 QMessageBox::about( this, "About PwManager/Pi",
1540 "PwManager/Platform-independent\n" 1540 "PwManager/Platform-independent\n"
1541 "(PWM/Pi) " +version + " - " + 1541 "(PWM/Pi) " +version + " - " +
1542#ifdef DESKTOP_VERSION 1542#ifdef DESKTOP_VERSION
1543 "Desktop Edition\n" 1543 "Desktop Edition\n"
1544#else 1544#else
1545 "PDA-Edition\n" 1545 "PDA-Edition\n"
1546 "for: Zaurus 5500 / 7x0 / 8x0\n" 1546 "for: Zaurus 5500 / 7x0 / 8x0\n"
1547#endif 1547#endif
1548 1548
1549 "(c) 2004 Ulf Schenk\n" 1549 "(c) 2004 Ulf Schenk\n"
1550 "(c) 2004 Lutz Rogowski\n" 1550 "(c) 2004 Lutz Rogowski\n"
1551 "(c) 1997-2004, The KDE PIM Team\n" 1551 "(c) 1997-2004, The KDE PIM Team\n"
1552 1552
1553 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" 1553 "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n"
1554 "Matt Scifo - mscifo@o1.com\n" 1554 "Matt Scifo - mscifo@o1.com\n"
1555 "Elias Probst - elias.probst@gmx.de\n" 1555 "Elias Probst - elias.probst@gmx.de\n"
1556 "George Staikos - staikos@kde.org\n" 1556 "George Staikos - staikos@kde.org\n"
1557 "Matthew Palmer - mjp16@uow.edu.au\n" 1557 "Matthew Palmer - mjp16@uow.edu.au\n"
1558 "Olivier Sessink - gpasman@nl.linux.org\n" 1558 "Olivier Sessink - gpasman@nl.linux.org\n"
1559 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" 1559 "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n"
1560 "Troy Engel - tengel@sonic.net\n" 1560 "Troy Engel - tengel@sonic.net\n"
1561 "Wickey - wickey@gmx.at\n" 1561 "Wickey - wickey@gmx.at\n"
1562 "Ian MacGregor - original documentation author.\n" 1562 "Ian MacGregor - original documentation author.\n"
1563 ); 1563 );
1564} 1564}
1565 1565
1566 1566
1567//this are the overwritten callbackmethods from the syncinterface 1567//this are the overwritten callbackmethods from the syncinterface
1568bool PwM::sync(KSyncManager* manager, QString filename, int mode) 1568bool PwM::sync(KSyncManager* manager, QString filename, int mode,QString resource)
1569{ 1569{
1570 PWM_ASSERT(curDoc()); 1570 PWM_ASSERT(curDoc());
1571 1571
1572 bool ret = curDoc()->sync(manager, filename, mode); 1572 bool ret = curDoc()->sync(manager, filename, mode,resource);
1573 1573
1574 qDebug("PwM::sync save now: ret=%i", ret); 1574 qDebug("PwM::sync save now: ret=%i", ret);
1575 1575
1576 if (ret == true) { 1576 if (ret == true) {
1577 //US BUG: what can we call here to update the view of the current doc? 1577 //US BUG: what can we call here to update the view of the current doc?
1578 //mViewManager->refreshView(); 1578 //mViewManager->refreshView();
1579 1579
1580 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. 1580 //US curDoc()->sync sets the dirtyFlag in case the sync was successfull.
1581 save(); 1581 save();
1582 } 1582 }
1583 1583
1584 return ret; 1584 return ret;
1585} 1585}
1586 1586
1587void PwM::removeSyncInfo( QString syncProfile) 1587void PwM::removeSyncInfo( QString syncProfile)
1588{ 1588{
1589 qDebug("PWM:removeSyncInfo for profile %s ", syncProfile.latin1()); 1589 qDebug("PWM:removeSyncInfo for profile %s ", syncProfile.latin1());
1590 curDoc()->removeSyncInfo( syncProfile ); 1590 curDoc()->removeSyncInfo( syncProfile );
1591 //US curDoc()->removeSyncInfo sets the dirtyFlag. 1591 //US curDoc()->removeSyncInfo sets the dirtyFlag.
1592} 1592}
1593 1593
1594#endif 1594#endif
1595 1595
1596 1596
1597#ifndef PWM_EMBEDDED 1597#ifndef PWM_EMBEDDED
1598#include "pwm.moc" 1598#include "pwm.moc"
1599#endif 1599#endif
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
index 2d1b854..c4bbb4e 100644
--- a/pwmanager/pwmanager/pwm.h
+++ b/pwmanager/pwmanager/pwm.h
@@ -1,300 +1,300 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWM_H 20#ifndef __PWM_H
21#define __PWM_H 21#define __PWM_H
22 22
23 23
24#include <kpopupmenu.h> 24#include <kpopupmenu.h>
25#include <klistview.h> 25#include <klistview.h>
26#include <kmainwindow.h> 26#include <kmainwindow.h>
27 27
28#ifndef PWM_EMBEDDED 28#ifndef PWM_EMBEDDED
29#include <kwin.h> 29#include <kwin.h>
30#include <kapp.h> 30#include <kapp.h>
31#include <kdeversion.h> 31#include <kdeversion.h>
32#else 32#else
33#include <ksyncmanager.h> 33#include <ksyncmanager.h>
34#endif 34#endif
35 35
36#include <kaction.h> 36#include <kaction.h>
37 37
38#include <qglobal.h> 38#include <qglobal.h>
39 39
40#include "pwmview.h" 40#include "pwmview.h"
41#include "pwmexception.h" 41#include "pwmexception.h"
42 42
43 43
44/** timeout for displaying a message on the status-bar (in seconds) */ 44/** timeout for displaying a message on the status-bar (in seconds) */
45 #define STATUSBAR_MSG_TIMEOUT5 45 #define STATUSBAR_MSG_TIMEOUT5
46 46
47 47
48class PwMInit; 48class PwMInit;
49class KSyncManager; 49class KSyncManager;
50 50
51/** PwM is the base class of the project */ 51/** PwM is the base class of the project */
52#ifndef PWM_EMBEDDED 52#ifndef PWM_EMBEDDED
53//MOC_SKIP_BEGIN 53//MOC_SKIP_BEGIN
54class PwM : public KMainWindow 54class PwM : public KMainWindow
55//MOC_SKIP_END 55//MOC_SKIP_END
56#else 56#else
57class PwM : public KMainWindow, public KSyncInterface 57class PwM : public KMainWindow, public KSyncInterface
58#endif 58#endif
59{ 59{
60 Q_OBJECT 60 Q_OBJECT
61public: 61public:
62 friend class PwMView; 62 friend class PwMView;
63 /** construtor */ 63 /** construtor */
64 PwM(PwMInit *_init, PwMDoc *doc, 64 PwM(PwMInit *_init, PwMDoc *doc,
65 bool virginity = true, 65 bool virginity = true,
66 QWidget* parent = 0, const char *name = 0); 66 QWidget* parent = 0, const char *name = 0);
67 /** destructor */ 67 /** destructor */
68 ~PwM(); 68 ~PwM();
69 69
70 /** copy some text to the global clipboard */ 70 /** copy some text to the global clipboard */
71 static void copyToClipboard(const QString &s); 71 static void copyToClipboard(const QString &s);
72 72
73 /** returns pointer to the view */ 73 /** returns pointer to the view */
74 PwMView * curView() 74 PwMView * curView()
75 { return view; } 75 { return view; }
76 /** returns pointer to the currently using document. */ 76 /** returns pointer to the currently using document. */
77 PwMDoc * curDoc() 77 PwMDoc * curDoc()
78 { return curView()->document(); } 78 { return curView()->document(); }
79 /** open a new doc with the given filename */ 79 /** open a new doc with the given filename */
80 PwMDoc * openDoc(QString filename, bool openDeepLocked = false); 80 PwMDoc * openDoc(QString filename, bool openDeepLocked = false);
81 /** show a message on the global status bar. 81 /** show a message on the global status bar.
82 * The message times out after some seconds. 82 * The message times out after some seconds.
83 */ 83 */
84 void showStatMsg(const QString &msg); 84 void showStatMsg(const QString &msg);
85 /** ask the user where to save the doc (if it has not been saved, yet) 85 /** ask the user where to save the doc (if it has not been saved, yet)
86 * and write the data to disk. 86 * and write the data to disk.
87 */ 87 */
88 bool save(); 88 bool save();
89 /** ask the user where to save the doc 89 /** ask the user where to save the doc
90 * and write the data to disk. 90 * and write the data to disk.
91 */ 91 */
92 bool saveAs(); 92 bool saveAs();
93 /** force quit. Quit this window, always! Don't minimize it */ 93 /** force quit. Quit this window, always! Don't minimize it */
94 bool isForceQuit() 94 bool isForceQuit()
95 { return forceQuit; } 95 { return forceQuit; }
96 /** set forceQuit */ 96 /** set forceQuit */
97 void setForceQuit(bool force) 97 void setForceQuit(bool force)
98 { forceQuit = force; } 98 { forceQuit = force; }
99 /** force minimize this window */ 99 /** force minimize this window */
100 bool isForceMinimizeToTray() 100 bool isForceMinimizeToTray()
101 { return forceMinimizeToTray; } 101 { return forceMinimizeToTray; }
102 /** set forceMinimizeToTray */ 102 /** set forceMinimizeToTray */
103 void setForceMinimizeToTray(bool force) 103 void setForceMinimizeToTray(bool force)
104 { forceMinimizeToTray = force; } 104 { forceMinimizeToTray = force; }
105 105
106public slots: 106public slots:
107 /** file/new triggered */ 107 /** file/new triggered */
108 void new_slot(); 108 void new_slot();
109 /** file/open triggered */ 109 /** file/open triggered */
110//US ENH 110//US ENH
111 void open_slot(); 111 void open_slot();
112 void open_slot(QString fn); 112 void open_slot(QString fn);
113 /** file/close triggered */ 113 /** file/close triggered */
114 void close_slot(); 114 void close_slot();
115 /** file/quit triggered */ 115 /** file/quit triggered */
116 void quitButton_slot(); 116 void quitButton_slot();
117 /** file/save triggered */ 117 /** file/save triggered */
118 void save_slot(); 118 void save_slot();
119 /** file/saveAs triggered */ 119 /** file/saveAs triggered */
120 void saveAs_slot(); 120 void saveAs_slot();
121 /** file/export/text triggered */ 121 /** file/export/text triggered */
122 void exportToText(); 122 void exportToText();
123 /** file/export/gpasman triggered */ 123 /** file/export/gpasman triggered */
124 void exportToGpasman(); 124 void exportToGpasman();
125 /** file/export/kwallet triggered */ 125 /** file/export/kwallet triggered */
126 void exportToKWallet(); 126 void exportToKWallet();
127 /** file/export/csv triggered */ 127 /** file/export/csv triggered */
128 void exportToCsv(); 128 void exportToCsv();
129 /** file/import/text triggered */ 129 /** file/import/text triggered */
130 bool importFromText(); 130 bool importFromText();
131 /** file/import/gpasman triggered */ 131 /** file/import/gpasman triggered */
132 bool importFromGpasman(); 132 bool importFromGpasman();
133 /** file/import/kwallet triggered */ 133 /** file/import/kwallet triggered */
134 bool importKWallet(); 134 bool importKWallet();
135 /** file/import/csv triggered */ 135 /** file/import/csv triggered */
136 bool importCsv(); 136 bool importCsv();
137 /** file/print triggered */ 137 /** file/print triggered */
138 void print_slot(); 138 void print_slot();
139 /** manage/add triggered */ 139 /** manage/add triggered */
140 //US ENH : changed code to run with older MOC 140 //US ENH : changed code to run with older MOC
141 141
142 void addPwd_slot(); 142 void addPwd_slot();
143 void addPwd_slot1(QString *pw, PwMDoc *_doc); 143 void addPwd_slot1(QString *pw, PwMDoc *_doc);
144 /** manage/edit triggered */ 144 /** manage/edit triggered */
145 //US ENH : changed code to run with older MOC 145 //US ENH : changed code to run with older MOC
146 void editPwd_slot(); 146 void editPwd_slot();
147 void editPwd_slot1(const QString *category); 147 void editPwd_slot1(const QString *category);
148 void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc ); 148 void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc );
149 149
150 /** manage/delete triggered */ 150 /** manage/delete triggered */
151 void deletePwd_slot(); 151 void deletePwd_slot();
152 /** execute the "Launcher" entry */ 152 /** execute the "Launcher" entry */
153 void execLauncher_slot(); 153 void execLauncher_slot();
154 /** open browser with URL entry */ 154 /** open browser with URL entry */
155 void goToURL_slot(); 155 void goToURL_slot();
156 /** manage/changeMasterPwd triggered */ 156 /** manage/changeMasterPwd triggered */
157 void changeMasterPwd_slot(); 157 void changeMasterPwd_slot();
158 /** lock current document */ 158 /** lock current document */
159 void lockWnd_slot(); 159 void lockWnd_slot();
160 /** deeplock current document */ 160 /** deeplock current document */
161 void deepLockWnd_slot(); 161 void deepLockWnd_slot();
162 /** window/unlock triggered */ 162 /** window/unlock triggered */
163 void unlockWnd_slot(); 163 void unlockWnd_slot();
164 /** find item */ 164 /** find item */
165 void find_slot(); 165 void find_slot();
166 /** configure clicked */ 166 /** configure clicked */
167 void config_slot(); 167 void config_slot();
168 void config_global_slot(); 168 void config_global_slot();
169 /** (de)activate the "change master pw" button in the menu-bar */ 169 /** (de)activate the "change master pw" button in the menu-bar */
170 void activateMpButton(bool activate = true); 170 void activateMpButton(bool activate = true);
171 /** generate a new chipcard */ 171 /** generate a new chipcard */
172 void genNewCard_slot(); 172 void genNewCard_slot();
173 /** completely erase the current card */ 173 /** completely erase the current card */
174 void eraseCard_slot(); 174 void eraseCard_slot();
175 /** returns the ID number of the current card */ 175 /** returns the ID number of the current card */
176 void readCardId_slot(); 176 void readCardId_slot();
177 /** make backup image of the current card */ 177 /** make backup image of the current card */
178 void makeCardBackup_slot(); 178 void makeCardBackup_slot();
179 /** write backup image to current card */ 179 /** write backup image to current card */
180 void replayCardBackup_slot(); 180 void replayCardBackup_slot();
181 181
182#ifdef PWM_EMBEDDED 182#ifdef PWM_EMBEDDED
183 void category_slot(); 183 void category_slot();
184 void whatsnew_slot(); 184 void whatsnew_slot();
185 void showLicense_slot(); 185 void showLicense_slot();
186 void faq_slot(); 186 void faq_slot();
187 void createAboutData_slot(); 187 void createAboutData_slot();
188 void syncHowTo_slot(); 188 void syncHowTo_slot();
189#endif 189#endif
190 190
191protected: 191protected:
192 /** is this window virgin? */ 192 /** is this window virgin? */
193 bool isVirgin() 193 bool isVirgin()
194 { return virgin; } 194 { return virgin; }
195 /** add/remove virginity */ 195 /** add/remove virginity */
196 void setVirgin(bool v); 196 void setVirgin(bool v);
197 /** initialize the menubar */ 197 /** initialize the menubar */
198 void initMenubar(); 198 void initMenubar();
199 /** initialize the toolbar */ 199 /** initialize the toolbar */
200 void initToolbar(); 200 void initToolbar();
201 /** initialize the window-metrics */ 201 /** initialize the window-metrics */
202 void initMetrics(); 202 void initMetrics();
203 /** close-event */ 203 /** close-event */
204 void closeEvent(QCloseEvent *e); 204 void closeEvent(QCloseEvent *e);
205 /** creates a new PwM-ListView and returns it */ 205 /** creates a new PwM-ListView and returns it */
206 PwMView * makeNewListView(PwMDoc *doc); 206 PwMView * makeNewListView(PwMDoc *doc);
207 /** Window hide-event */ 207 /** Window hide-event */
208 void hideEvent(QHideEvent *); 208 void hideEvent(QHideEvent *);
209 /** is this window minimized? */ 209 /** is this window minimized? */
210 bool isMinimized() 210 bool isMinimized()
211 { 211 {
212#ifndef PWM_EMBEDDED 212#ifndef PWM_EMBEDDED
213 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) 213 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
214 return KWin::windowInfo(winId()).isMinimized(); 214 return KWin::windowInfo(winId()).isMinimized();
215 #else // KDE_VERSION 215 #else // KDE_VERSION
216 return KWin::info(winId()).isIconified(); 216 return KWin::info(winId()).isIconified();
217 #endif // KDE_VERSION 217 #endif // KDE_VERSION
218#else 218#else
219 return false; 219 return false;
220#endif 220#endif
221 } 221 }
222 /** window got the focus */ 222 /** window got the focus */
223 void focusInEvent(QFocusEvent *e); 223 void focusInEvent(QFocusEvent *e);
224 /** update the caption string */ 224 /** update the caption string */
225 void updateCaption(); 225 void updateCaption();
226#ifdef CONFIG_KWALLETIF 226#ifdef CONFIG_KWALLETIF
227 /** check if kwalletemu is enabled and ask the user what to do */ 227 /** check if kwalletemu is enabled and ask the user what to do */
228 bool checkAndAskForKWalletEmu(); 228 bool checkAndAskForKWalletEmu();
229#endif // CONFIG_KWALLETIF 229#endif // CONFIG_KWALLETIF
230 230
231protected slots: 231protected slots:
232 /** doc got closed */ 232 /** doc got closed */
233 void docClosed(PwMDoc *doc); 233 void docClosed(PwMDoc *doc);
234 234
235signals: 235signals:
236 /** window got closed (by user or someone else) */ 236 /** window got closed (by user or someone else) */
237 void closed(PwM *wnd); 237 void closed(PwM *wnd);
238 /** window got the focus (was brought to foreground) */ 238 /** window got the focus (was brought to foreground) */
239 void gotFocus(PwM *wnd); 239 void gotFocus(PwM *wnd);
240 /** window lost the focus */ 240 /** window lost the focus */
241 void lostFocus(PwM *wnd); 241 void lostFocus(PwM *wnd);
242 242
243protected: 243protected:
244 /** pointer to the view active in this KMainWindow */ 244 /** pointer to the view active in this KMainWindow */
245 PwMView *view; 245 PwMView *view;
246 /** pointer to the init class */ 246 /** pointer to the init class */
247 PwMInit *init; 247 PwMInit *init;
248 /** has this window already lost its virginity? 248 /** has this window already lost its virginity?
249 * Means is there an open working document 249 * Means is there an open working document
250 */ 250 */
251 bool virgin; 251 bool virgin;
252 /** "file" popup-menu */ 252 /** "file" popup-menu */
253 KPopupMenu *filePopup; 253 KPopupMenu *filePopup;
254 254
255 /** "manage" popup-menu */ 255 /** "manage" popup-menu */
256 KPopupMenu *managePopup; 256 KPopupMenu *managePopup;
257#ifdef CONFIG_KEYCARD 257#ifdef CONFIG_KEYCARD
258 /** "chipcard" popup-menu */ 258 /** "chipcard" popup-menu */
259 KPopupMenu *chipcardPopup; 259 KPopupMenu *chipcardPopup;
260#endif // CONFIG_KEYCARD 260#endif // CONFIG_KEYCARD
261 /** "view" popup-menu */ 261 /** "view" popup-menu */
262 KPopupMenu *viewPopup; 262 KPopupMenu *viewPopup;
263 /** "options" popup-menu */ 263 /** "options" popup-menu */
264 KPopupMenu *optionsPopup; 264 KPopupMenu *optionsPopup;
265 /** "help" popup-menu */ 265 /** "help" popup-menu */
266 KPopupMenu *helpPopup; 266 KPopupMenu *helpPopup;
267 /** "export" popup-menu */ 267 /** "export" popup-menu */
268 KPopupMenu *exportPopup; 268 KPopupMenu *exportPopup;
269 /** "import" popup-menu */ 269 /** "import" popup-menu */
270 KPopupMenu *importPopup; 270 KPopupMenu *importPopup;
271 /** force quit this window? */ 271 /** force quit this window? */
272 bool forceQuit; 272 bool forceQuit;
273 /** force minimize this window to the tray */ 273 /** force minimize this window to the tray */
274 bool forceMinimizeToTray; 274 bool forceMinimizeToTray;
275 275
276 276
277 277
278 278
279 private: 279 private:
280#ifdef PWM_EMBEDDED 280#ifdef PWM_EMBEDDED
281 //this are the overwritten callbackmethods from the syncinterface 281 //this are the overwritten callbackmethods from the syncinterface
282 virtual bool sync(KSyncManager* manager, QString filename, int mode); 282 virtual bool sync(KSyncManager* manager, QString filename, int mode,QString resource);
283 virtual void removeSyncInfo( QString syncProfile); 283 virtual void removeSyncInfo( QString syncProfile);
284 284
285 // LR ******************************* 285 // LR *******************************
286 // sync stuff! 286 // sync stuff!
287 QPopupMenu *syncPopup; 287 QPopupMenu *syncPopup;
288 KSyncManager* syncManager; 288 KSyncManager* syncManager;
289#endif 289#endif
290 290
291 291
292 292
293 293
294 294
295 295
296 296
297 297
298}; 298};
299 299
300#endif 300#endif
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 1f3c58b..b58d7e2 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1,3634 +1,3634 @@
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.1 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmdoc.h" 20#include "pwmdoc.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "blowfish.h" 22#include "blowfish.h"
23#include "sha1.h" 23#include "sha1.h"
24#include "globalstuff.h" 24#include "globalstuff.h"
25#include "gpasmanfile.h" 25#include "gpasmanfile.h"
26#include "serializer.h" 26#include "serializer.h"
27#include "compressgzip.h" 27#include "compressgzip.h"
28//US#include "compressbzip2.h" 28//US#include "compressbzip2.h"
29#include "randomizer.h" 29#include "randomizer.h"
30#include "pwminit.h" 30#include "pwminit.h"
31#include "libgcryptif.h" 31#include "libgcryptif.h"
32#ifdef PWM_EMBEDDED 32#ifdef PWM_EMBEDDED
33#include "pwmprefs.h" 33#include "pwmprefs.h"
34#include "kglobal.h" 34#include "kglobal.h"
35#endif 35#endif
36 36
37#include <kmessagebox.h> 37#include <kmessagebox.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kglobalsettings.h> 39#include <kglobalsettings.h>
40#include <libkcal/syncdefines.h> 40#include <libkcal/syncdefines.h>
41 41
42 42
43#ifdef CONFIG_KWALLETIF 43#ifdef CONFIG_KWALLETIF
44# include "kwalletemu.h" 44# include "kwalletemu.h"
45#endif // CONFIG_KWALLETIF 45#endif // CONFIG_KWALLETIF
46 46
47#include <qdatetime.h> 47#include <qdatetime.h>
48#include <qsize.h> 48#include <qsize.h>
49#include <qfileinfo.h> 49#include <qfileinfo.h>
50#include <qfile.h> 50#include <qfile.h>
51 51
52#include <stdio.h> 52#include <stdio.h>
53#include <stdlib.h> 53#include <stdlib.h>
54#include <errno.h> 54#include <errno.h>
55#include <string.h> 55#include <string.h>
56//US#include <iostream> 56//US#include <iostream>
57#include <algorithm> 57#include <algorithm>
58#include <sys/types.h> 58#include <sys/types.h>
59#include <sys/stat.h> 59#include <sys/stat.h>
60#ifndef _WIN32_ 60#ifndef _WIN32_
61#include <unistd.h> 61#include <unistd.h>
62#include <stdint.h> 62#include <stdint.h>
63#endif 63#endif
64 64
65#ifdef PWM_EMBEDDED 65#ifdef PWM_EMBEDDED
66#ifndef Q_LONG 66#ifndef Q_LONG
67#define Q_LONG long 67#define Q_LONG long
68#endif 68#endif
69 69
70#ifndef Q_ULONG 70#ifndef Q_ULONG
71#define Q_ULONG unsigned long 71#define Q_ULONG unsigned long
72#endif 72#endif
73#endif //PWM_EMBEDDED 73#endif //PWM_EMBEDDED
74 74
75 75
76//TODO: reset to its normal value. 76//TODO: reset to its normal value.
77//LR set to 5 min 77//LR set to 5 min
78 #define META_CHECK_TIMER_INTERVAL300 /* 10 300*/ /* sek */ 78 #define META_CHECK_TIMER_INTERVAL300 /* 10 300*/ /* sek */
79 79
80using namespace std; 80using namespace std;
81 81
82 82
83void PwMDocList::add(PwMDoc *doc, const string &id) 83void PwMDocList::add(PwMDoc *doc, const string &id)
84{ 84{
85#ifdef PWM_DEBUG 85#ifdef PWM_DEBUG
86 // check for existance of object in debug mode only. 86 // check for existance of object in debug mode only.
87 vector<listItem>::iterator begin = docList.begin(), 87 vector<listItem>::iterator begin = docList.begin(),
88 end = docList.end(), 88 end = docList.end(),
89 i = begin; 89 i = begin;
90 while (i != end) { 90 while (i != end) {
91 if (i->doc == doc) { 91 if (i->doc == doc) {
92 BUG(); 92 BUG();
93 return; 93 return;
94 } 94 }
95 ++i; 95 ++i;
96 } 96 }
97#endif 97#endif
98 listItem newItem; 98 listItem newItem;
99 newItem.doc = doc; 99 newItem.doc = doc;
100 newItem.docId = id; 100 newItem.docId = id;
101 docList.push_back(newItem); 101 docList.push_back(newItem);
102} 102}
103 103
104void PwMDocList::edit(PwMDoc *doc, const string &newId) 104void PwMDocList::edit(PwMDoc *doc, const string &newId)
105{ 105{
106 vector<listItem>::iterator begin = docList.begin(), 106 vector<listItem>::iterator begin = docList.begin(),
107 end = docList.end(), 107 end = docList.end(),
108 i = begin; 108 i = begin;
109 while (i != end) { 109 while (i != end) {
110 if (i->doc == doc) { 110 if (i->doc == doc) {
111 i->docId = newId; 111 i->docId = newId;
112 return; 112 return;
113 } 113 }
114 ++i; 114 ++i;
115 } 115 }
116} 116}
117 117
118void PwMDocList::del(PwMDoc *doc) 118void PwMDocList::del(PwMDoc *doc)
119{ 119{
120 vector<listItem>::iterator begin = docList.begin(), 120 vector<listItem>::iterator begin = docList.begin(),
121 end = docList.end(), 121 end = docList.end(),
122 i = begin; 122 i = begin;
123 while (i != end) { 123 while (i != end) {
124 if (i->doc == doc) { 124 if (i->doc == doc) {
125 docList.erase(i); 125 docList.erase(i);
126 return; 126 return;
127 } 127 }
128 ++i; 128 ++i;
129 } 129 }
130} 130}
131 131
132bool PwMDocList::find(const string &id, listItem *ret) 132bool PwMDocList::find(const string &id, listItem *ret)
133{ 133{
134 vector<listItem>::iterator begin = docList.begin(), 134 vector<listItem>::iterator begin = docList.begin(),
135 end = docList.end(), 135 end = docList.end(),
136 i = begin; 136 i = begin;
137 while (i != end) { 137 while (i != end) {
138 if (i->docId == id) { 138 if (i->docId == id) {
139 if (ret) 139 if (ret)
140 *ret = *i; 140 *ret = *i;
141 return true; 141 return true;
142 } 142 }
143 ++i; 143 ++i;
144 } 144 }
145 return false; 145 return false;
146} 146}
147 147
148 148
149 149
150DocTimer::DocTimer(PwMDoc *_doc) 150DocTimer::DocTimer(PwMDoc *_doc)
151 : doc (_doc) 151 : doc (_doc)
152 , mpwLock (0) 152 , mpwLock (0)
153 , autoLockLock (0) 153 , autoLockLock (0)
154 , metaCheckLock (0) 154 , metaCheckLock (0)
155{ 155{
156 mpwTimer = new QTimer; 156 mpwTimer = new QTimer;
157 autoLockTimer = new QTimer; 157 autoLockTimer = new QTimer;
158 metaCheckTimer = new QTimer; 158 metaCheckTimer = new QTimer;
159 connect(mpwTimer, SIGNAL(timeout()), 159 connect(mpwTimer, SIGNAL(timeout()),
160 this, SLOT(mpwTimeout())); 160 this, SLOT(mpwTimeout()));
161 connect(autoLockTimer, SIGNAL(timeout()), 161 connect(autoLockTimer, SIGNAL(timeout()),
162 this, SLOT(autoLockTimeout())); 162 this, SLOT(autoLockTimeout()));
163 connect(metaCheckTimer, SIGNAL(timeout()), 163 connect(metaCheckTimer, SIGNAL(timeout()),
164 this, SLOT(metaCheckTimeout())); 164 this, SLOT(metaCheckTimeout()));
165} 165}
166 166
167DocTimer::~DocTimer() 167DocTimer::~DocTimer()
168{ 168{
169 delete mpwTimer; 169 delete mpwTimer;
170 delete autoLockTimer; 170 delete autoLockTimer;
171 delete metaCheckTimer; 171 delete metaCheckTimer;
172} 172}
173 173
174void DocTimer::start(TimerIDs timer) 174void DocTimer::start(TimerIDs timer)
175{ 175{
176 switch (timer) { 176 switch (timer) {
177 case id_mpwTimer: 177 case id_mpwTimer:
178 if (mpwTimer->isActive()) 178 if (mpwTimer->isActive())
179 mpwTimer->stop(); 179 mpwTimer->stop();
180 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 180 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
181 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); 181 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
182 break; 182 break;
183 case id_autoLockTimer: 183 case id_autoLockTimer:
184 if (autoLockTimer->isActive()) 184 if (autoLockTimer->isActive())
185 autoLockTimer->stop(); 185 autoLockTimer->stop();
186 if (conf()->confGlobLockTimeout() > 0) 186 if (conf()->confGlobLockTimeout() > 0)
187 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); 187 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
188 break; 188 break;
189 case id_metaCheckTimer: 189 case id_metaCheckTimer:
190 if (metaCheckTimer->isActive()) 190 if (metaCheckTimer->isActive())
191 metaCheckTimer->stop(); 191 metaCheckTimer->stop();
192 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 192 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
193 break; 193 break;
194 } 194 }
195} 195}
196 196
197void DocTimer::stop(TimerIDs timer) 197void DocTimer::stop(TimerIDs timer)
198{ 198{
199 switch (timer) { 199 switch (timer) {
200 case id_mpwTimer: 200 case id_mpwTimer:
201 mpwTimer->stop(); 201 mpwTimer->stop();
202 break; 202 break;
203 case id_autoLockTimer: 203 case id_autoLockTimer:
204 autoLockTimer->stop(); 204 autoLockTimer->stop();
205 break; 205 break;
206 case id_metaCheckTimer: 206 case id_metaCheckTimer:
207 metaCheckTimer->stop(); 207 metaCheckTimer->stop();
208 break; 208 break;
209 } 209 }
210} 210}
211 211
212void DocTimer::getLock(TimerIDs timer) 212void DocTimer::getLock(TimerIDs timer)
213{ 213{
214 switch (timer) { 214 switch (timer) {
215 case id_mpwTimer: 215 case id_mpwTimer:
216 ++mpwLock; 216 ++mpwLock;
217 break; 217 break;
218 case id_autoLockTimer: 218 case id_autoLockTimer:
219 ++autoLockLock; 219 ++autoLockLock;
220 break; 220 break;
221 case id_metaCheckTimer: 221 case id_metaCheckTimer:
222 ++metaCheckLock; 222 ++metaCheckLock;
223 break; 223 break;
224 } 224 }
225} 225}
226 226
227void DocTimer::putLock(TimerIDs timer) 227void DocTimer::putLock(TimerIDs timer)
228{ 228{
229 switch (timer) { 229 switch (timer) {
230 case id_mpwTimer: 230 case id_mpwTimer:
231 if (mpwLock) 231 if (mpwLock)
232 --mpwLock; 232 --mpwLock;
233 break; 233 break;
234 case id_autoLockTimer: 234 case id_autoLockTimer:
235 if (autoLockLock) 235 if (autoLockLock)
236 --autoLockLock; 236 --autoLockLock;
237 break; 237 break;
238 case id_metaCheckTimer: 238 case id_metaCheckTimer:
239 if (metaCheckLock) 239 if (metaCheckLock)
240 --metaCheckLock; 240 --metaCheckLock;
241 break; 241 break;
242 } 242 }
243} 243}
244 244
245void DocTimer::mpwTimeout() 245void DocTimer::mpwTimeout()
246{ 246{
247 if (mpwLock) { 247 if (mpwLock) {
248 mpwTimer->start(1000, true); 248 mpwTimer->start(1000, true);
249 return; 249 return;
250 } 250 }
251 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 251 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
252} 252}
253 253
254void DocTimer::autoLockTimeout() 254void DocTimer::autoLockTimeout()
255{ 255{
256 if (autoLockLock) { 256 if (autoLockLock) {
257 autoLockTimer->start(1000, true); 257 autoLockTimer->start(1000, true);
258 return; 258 return;
259 } 259 }
260 if (conf()->confGlobAutoDeepLock() && 260 if (conf()->confGlobAutoDeepLock() &&
261 doc->filename != QString::null && 261 doc->filename != QString::null &&
262 doc->filename != "") { 262 doc->filename != "") {
263 doc->deepLock(true); 263 doc->deepLock(true);
264 } else { 264 } else {
265 doc->lockAll(true); 265 doc->lockAll(true);
266 } 266 }
267} 267}
268 268
269void DocTimer::metaCheckTimeout() 269void DocTimer::metaCheckTimeout()
270{ 270{
271 if (metaCheckLock) { 271 if (metaCheckLock) {
272 // check again in one second. 272 // check again in one second.
273 metaCheckTimer->start(1000, true); 273 metaCheckTimer->start(1000, true);
274 return; 274 return;
275 } 275 }
276 if (doc->isDeepLocked()) { 276 if (doc->isDeepLocked()) {
277 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 277 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
278 return; 278 return;
279 } 279 }
280 if (doc->isDocEmpty()) { 280 if (doc->isDocEmpty()) {
281 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 281 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
282 return; 282 return;
283 } 283 }
284#ifdef CONFIG_KWALLETIF 284#ifdef CONFIG_KWALLETIF
285 KWalletEmu *kwlEmu = doc->init->kwalletEmu(); 285 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
286 if (kwlEmu) 286 if (kwlEmu)
287 kwlEmu->suspendDocSignals(); 287 kwlEmu->suspendDocSignals();
288#endif // CONFIG_KWALLETIF 288#endif // CONFIG_KWALLETIF
289 /* We simply trigger all views to update their 289 /* We simply trigger all views to update their
290 * displayed values. This way they have a chance 290 * displayed values. This way they have a chance
291 * to get notified when some meta changes over time. 291 * to get notified when some meta changes over time.
292 * (for example an entry expired). 292 * (for example an entry expired).
293 * The _view_ is responsive for not updating its 293 * The _view_ is responsive for not updating its
294 * contents if nothing really changed! 294 * contents if nothing really changed!
295 */ 295 */
296 emit doc->dataChanged(doc); 296 emit doc->dataChanged(doc);
297#ifdef CONFIG_KWALLETIF 297#ifdef CONFIG_KWALLETIF
298 if (kwlEmu) 298 if (kwlEmu)
299 kwlEmu->resumeDocSignals(); 299 kwlEmu->resumeDocSignals();
300#endif // CONFIG_KWALLETIF 300#endif // CONFIG_KWALLETIF
301 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 301 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
302} 302}
303 303
304 304
305 305
306PwMDocList PwMDoc::openDocList; 306PwMDocList PwMDoc::openDocList;
307unsigned int PwMDocList::unnamedDocCnt = 1; 307unsigned int PwMDocList::unnamedDocCnt = 1;
308 308
309PwMDoc::PwMDoc(QObject *parent, const char *name) 309PwMDoc::PwMDoc(QObject *parent, const char *name)
310 : PwMDocUi(parent, name) 310 : PwMDocUi(parent, name)
311 , dataChangedLock (0) 311 , dataChangedLock (0)
312{ 312{
313 deleted = false; 313 deleted = false;
314 unnamedNum = 0; 314 unnamedNum = 0;
315 getOpenDocList()->add(this, getTitle().latin1()); 315 getOpenDocList()->add(this, getTitle().latin1());
316 curDocStat = 0; 316 curDocStat = 0;
317 setMaxNumEntries(); 317 setMaxNumEntries();
318 _timer = new DocTimer(this); 318 _timer = new DocTimer(this);
319 timer()->start(DocTimer::id_mpwTimer); 319 timer()->start(DocTimer::id_mpwTimer);
320 timer()->start(DocTimer::id_autoLockTimer); 320 timer()->start(DocTimer::id_autoLockTimer);
321 timer()->start(DocTimer::id_metaCheckTimer); 321 timer()->start(DocTimer::id_metaCheckTimer);
322 addCategory(DEFAULT_CATEGORY, 0, false); 322 addCategory(DEFAULT_CATEGORY, 0, false);
323 listView = 0; 323 listView = 0;
324 emit docCreated(this); 324 emit docCreated(this);
325} 325}
326 326
327PwMDoc::~PwMDoc() 327PwMDoc::~PwMDoc()
328{ 328{
329 emit docClosed(this); 329 emit docClosed(this);
330 getOpenDocList()->del(this); 330 getOpenDocList()->del(this);
331 delete _timer; 331 delete _timer;
332} 332}
333 333
334PwMerror PwMDoc::saveDoc(char compress, const QString *file) 334PwMerror PwMDoc::saveDoc(char compress, const QString *file)
335{ 335{
336 PwMerror ret, e; 336 PwMerror ret, e;
337 string serialized; 337 string serialized;
338 QFile f; 338 QFile f;
339 QString tmpFileMoved(QString::null); 339 QString tmpFileMoved(QString::null);
340 bool wasDeepLocked; 340 bool wasDeepLocked;
341 QString savedFilename(filename); 341 QString savedFilename(filename);
342 342
343 if (!file) { 343 if (!file) {
344 if (filename == "") 344 if (filename == "")
345 return e_filename; 345 return e_filename;
346 if (isDeepLocked()) { 346 if (isDeepLocked()) {
347 /* We don't need to save any data. 347 /* We don't need to save any data.
348 * It's already all on disk, because 348 * It's already all on disk, because
349 * we are deeplocked. 349 * we are deeplocked.
350 */ 350 */
351 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 351 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
352 ret = e_success; 352 ret = e_success;
353 return ret; 353 return ret;
354 } 354 }
355 } else { 355 } else {
356 if (*file == "" && filename == "") 356 if (*file == "" && filename == "")
357 return e_filename; 357 return e_filename;
358 if (*file != "") 358 if (*file != "")
359 filename = *file; 359 filename = *file;
360 } 360 }
361 361
362 wasDeepLocked = isDeepLocked(); 362 wasDeepLocked = isDeepLocked();
363 if (wasDeepLocked) { 363 if (wasDeepLocked) {
364 /* We are deeplocked. That means all data is already 364 /* We are deeplocked. That means all data is already
365 * on disk. BUT we need to do saving procedure, 365 * on disk. BUT we need to do saving procedure,
366 * because *file != savedFilename. 366 * because *file != savedFilename.
367 * Additionally we need to tempoarly restore 367 * Additionally we need to tempoarly restore
368 * the old "filename", because deepLock() references it. 368 * the old "filename", because deepLock() references it.
369 */ 369 */
370 QString newFilename(filename); 370 QString newFilename(filename);
371 filename = savedFilename; 371 filename = savedFilename;
372 getDataChangedLock(); 372 getDataChangedLock();
373 e = deepLock(false); 373 e = deepLock(false);
374 putDataChangedLock(); 374 putDataChangedLock();
375 filename = newFilename; 375 filename = newFilename;
376 switch (e) { 376 switch (e) {
377 case e_success: 377 case e_success:
378 break; 378 break;
379 case e_wrongPw: 379 case e_wrongPw:
380 case e_noPw: 380 case e_noPw:
381 emitDataChanged(this); 381 emitDataChanged(this);
382 return e; 382 return e;
383 default: 383 default:
384 emitDataChanged(this); 384 emitDataChanged(this);
385 return e_openFile; 385 return e_openFile;
386 } 386 }
387 } 387 }
388 388
389 if (!isPwAvailable()) { 389 if (!isPwAvailable()) {
390 /* password is not available. This means, the 390 /* password is not available. This means, the
391 * document wasn't saved, yet. 391 * document wasn't saved, yet.
392 */ 392 */
393 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 393 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
394 QString pw(requestNewMpw(&useChipcard)); 394 QString pw(requestNewMpw(&useChipcard));
395 if (pw != "") { 395 if (pw != "") {
396 currentPw = pw; 396 currentPw = pw;
397 } else { 397 } else {
398 return e_noPw; 398 return e_noPw;
399 } 399 }
400 if (useChipcard) { 400 if (useChipcard) {
401 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 401 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
402 } else { 402 } else {
403 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 403 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
404 } 404 }
405 } 405 }
406 406
407 int _cryptAlgo = conf()->confGlobCryptAlgo(); 407 int _cryptAlgo = conf()->confGlobCryptAlgo();
408 int _hashAlgo = conf()->confGlobHashAlgo(); 408 int _hashAlgo = conf()->confGlobHashAlgo();
409 409
410 // sanity check for the selected algorithms 410 // sanity check for the selected algorithms
411 if (_cryptAlgo < PWM_CRYPT_BLOWFISH || 411 if (_cryptAlgo < PWM_CRYPT_BLOWFISH ||
412 _cryptAlgo > PWM_CRYPT_TWOFISH128) { 412 _cryptAlgo > PWM_CRYPT_TWOFISH128) {
413 printWarn("Invalid Crypto-Algorithm selected! " 413 printWarn("Invalid Crypto-Algorithm selected! "
414 "Config-file seems to be corrupt. " 414 "Config-file seems to be corrupt. "
415 "Falling back to Blowfish."); 415 "Falling back to Blowfish.");
416 _cryptAlgo = PWM_CRYPT_BLOWFISH; 416 _cryptAlgo = PWM_CRYPT_BLOWFISH;
417 } 417 }
418 if (_hashAlgo < PWM_HASH_SHA1 || 418 if (_hashAlgo < PWM_HASH_SHA1 ||
419 _hashAlgo > PWM_HASH_TIGER) { 419 _hashAlgo > PWM_HASH_TIGER) {
420 printWarn("Invalid Hash-Algorithm selected! " 420 printWarn("Invalid Hash-Algorithm selected! "
421 "Config-file seems to be corrupt. " 421 "Config-file seems to be corrupt. "
422 "Falling back to SHA1."); 422 "Falling back to SHA1.");
423 _hashAlgo = PWM_HASH_SHA1; 423 _hashAlgo = PWM_HASH_SHA1;
424 } 424 }
425 char cryptAlgo = static_cast<char>(_cryptAlgo); 425 char cryptAlgo = static_cast<char>(_cryptAlgo);
426 char hashAlgo = static_cast<char>(_hashAlgo); 426 char hashAlgo = static_cast<char>(_hashAlgo);
427 427
428 if (conf()->confGlobMakeFileBackup()) { 428 if (conf()->confGlobMakeFileBackup()) {
429 if (!backupFile(filename)) 429 if (!backupFile(filename))
430 return e_fileBackup; 430 return e_fileBackup;
431 } 431 }
432 int mLastBackupDate = 0; 432 int mLastBackupDate = 0;
433 KConfig configGlobal (locateLocal("config","pwmanagerbuprc")); 433 KConfig configGlobal (locateLocal("config","pwmanagerbuprc"));
434 QFileInfo fileInfo ( filename ); 434 QFileInfo fileInfo ( filename );
435 mLastBackupDate = configGlobal.readNumEntry( "LastBackupDate-"+ fileInfo.fileName (), 0 ); 435 mLastBackupDate = configGlobal.readNumEntry( "LastBackupDate-"+ fileInfo.fileName (), 0 );
436 KConfig config (locateLocal("config","microkdeglobalrc")); 436 KConfig config (locateLocal("config","microkdeglobalrc"));
437 config.setGroup( "BackupSettings" ); 437 config.setGroup( "BackupSettings" );
438 bool b_enabled = config.readBoolEntry( "BackupEnabled" ); 438 bool b_enabled = config.readBoolEntry( "BackupEnabled" );
439 if ( b_enabled && QFile::exists(filename)) { 439 if ( b_enabled && QFile::exists(filename)) {
440 int num = config.readNumEntry( "BackupNumbers" ); 440 int num = config.readNumEntry( "BackupNumbers" );
441 int d_count = config.readNumEntry( "BackupDayCount" ); 441 int d_count = config.readNumEntry( "BackupDayCount" );
442 bool stdDir = config.readBoolEntry( "BackupUseDefaultDir" ); 442 bool stdDir = config.readBoolEntry( "BackupUseDefaultDir" );
443 QString bupDir = config.readEntry( "BackupDatadir" ); 443 QString bupDir = config.readEntry( "BackupDatadir" );
444 QDate reference ( 2000,1,1 ); 444 QDate reference ( 2000,1,1 );
445 int daysTo = reference.daysTo ( QDate::currentDate() ); 445 int daysTo = reference.daysTo ( QDate::currentDate() );
446 bool saveDate = false; 446 bool saveDate = false;
447 if ( daysTo - d_count >= mLastBackupDate ) { 447 if ( daysTo - d_count >= mLastBackupDate ) {
448 qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate ); 448 qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate );
449 if ( stdDir ) 449 if ( stdDir )
450 bupDir = KGlobalSettings::backupDataDir(); 450 bupDir = KGlobalSettings::backupDataDir();
451 int retval = KApplication::createBackup( filename, bupDir, num ); 451 int retval = KApplication::createBackup( filename, bupDir, num );
452 if ( retval == 0 ) { 452 if ( retval == 0 ) {
453 qDebug("KO: Backup cancelled. Will try again tomorrow "); 453 qDebug("KO: Backup cancelled. Will try again tomorrow ");
454 // retval == 0 : backup skipped for today, try again tomorrow 454 // retval == 0 : backup skipped for today, try again tomorrow
455 mLastBackupDate = daysTo - d_count+1; 455 mLastBackupDate = daysTo - d_count+1;
456 saveDate = true; 456 saveDate = true;
457 } else if ( retval == 1 ){ 457 } else if ( retval == 1 ){
458 qDebug("KO: Backup created."); 458 qDebug("KO: Backup created.");
459 // backup ok 459 // backup ok
460 mLastBackupDate = daysTo; 460 mLastBackupDate = daysTo;
461 saveDate = true; 461 saveDate = true;
462 } else if ( retval == 2 ){ 462 } else if ( retval == 2 ){
463 qDebug("KO: Backup globally cancelled."); 463 qDebug("KO: Backup globally cancelled.");
464 // backup globally cancelled 464 // backup globally cancelled
465 b_enabled = false; 465 b_enabled = false;
466 } 466 }
467 if ( !b_enabled ) { 467 if ( !b_enabled ) {
468 config.writeEntry( "mBackupEnabled", false ); 468 config.writeEntry( "mBackupEnabled", false );
469 } 469 }
470 if ( saveDate ) { 470 if ( saveDate ) {
471 configGlobal.writeEntry( "LastBackupDate-"+ fileInfo.fileName (), mLastBackupDate ); 471 configGlobal.writeEntry( "LastBackupDate-"+ fileInfo.fileName (), mLastBackupDate );
472 } 472 }
473 } 473 }
474 } 474 }
475 if (QFile::exists(filename)) { 475 if (QFile::exists(filename)) {
476 /* Move the existing file to some tmp file. 476 /* Move the existing file to some tmp file.
477 * When saving file succeeds, delete tmp file. Otherwise 477 * When saving file succeeds, delete tmp file. Otherwise
478 * move tmp file back. See below. 478 * move tmp file back. See below.
479 */ 479 */
480 Randomizer *rnd = Randomizer::obj(); 480 Randomizer *rnd = Randomizer::obj();
481 char rnd_buf[5]; 481 char rnd_buf[5];
482 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, 482 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF,
483 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); 483 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF);
484 tmpFileMoved = filename + "." + rnd_buf + ".mv"; 484 tmpFileMoved = filename + "." + rnd_buf + ".mv";
485 if (!copyFile(filename, tmpFileMoved)) 485 if (!copyFile(filename, tmpFileMoved))
486 return e_openFile; 486 return e_openFile;
487 if (!QFile::remove(filename)) { 487 if (!QFile::remove(filename)) {
488 printWarn(string("removing orig file ") 488 printWarn(string("removing orig file ")
489 + filename.latin1() 489 + filename.latin1()
490 + " failed!"); 490 + " failed!");
491 } 491 }
492 } 492 }
493 f.setName(filename); 493 f.setName(filename);
494 if (!f.open(IO_ReadWrite)) { 494 if (!f.open(IO_ReadWrite)) {
495 ret = e_openFile; 495 ret = e_openFile;
496 goto out_moveback; 496 goto out_moveback;
497 } 497 }
498 e = writeFileHeader(hashAlgo, hashAlgo, 498 e = writeFileHeader(hashAlgo, hashAlgo,
499 cryptAlgo, compress, 499 cryptAlgo, compress,
500 &currentPw, &f); 500 &currentPw, &f);
501 if (e == e_hashNotImpl) { 501 if (e == e_hashNotImpl) {
502 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); 502 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl");
503 f.close(); 503 f.close();
504 ret = e_hashNotImpl; 504 ret = e_hashNotImpl;
505 goto out_moveback; 505 goto out_moveback;
506 } else if (e != e_success) { 506 } else if (e != e_success) {
507 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); 507 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed");
508 f.close(); 508 f.close();
509 ret = e_writeHeader; 509 ret = e_writeHeader;
510 goto out_moveback; 510 goto out_moveback;
511 } 511 }
512 if (!serializeDta(&serialized)) { 512 if (!serializeDta(&serialized)) {
513 printDebug("PwMDoc::saveDoc(): serializeDta() failed"); 513 printDebug("PwMDoc::saveDoc(): serializeDta() failed");
514 f.close(); 514 f.close();
515 ret = e_serializeDta; 515 ret = e_serializeDta;
516 goto out_moveback; 516 goto out_moveback;
517 } 517 }
518 e = writeDataHash(hashAlgo, &serialized, &f); 518 e = writeDataHash(hashAlgo, &serialized, &f);
519 if (e == e_hashNotImpl) { 519 if (e == e_hashNotImpl) {
520 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); 520 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl");
521 f.close(); 521 f.close();
522 ret = e_hashNotImpl; 522 ret = e_hashNotImpl;
523 goto out_moveback; 523 goto out_moveback;
524 } else if (e != e_success) { 524 } else if (e != e_success) {
525 printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); 525 printDebug("PwMDoc::saveDoc(): writeDataHash() failed");
526 f.close(); 526 f.close();
527 ret = e_writeHeader; 527 ret = e_writeHeader;
528 goto out_moveback; 528 goto out_moveback;
529 } 529 }
530 if (!compressDta(&serialized, compress)) { 530 if (!compressDta(&serialized, compress)) {
531 printDebug("PwMDoc::saveDoc(): compressDta() failed"); 531 printDebug("PwMDoc::saveDoc(): compressDta() failed");
532 f.close(); 532 f.close();
533 ret = e_enc; 533 ret = e_enc;
534 goto out_moveback; 534 goto out_moveback;
535 } 535 }
536 e = encrypt(&serialized, &currentPw, &f, cryptAlgo, hashAlgo); 536 e = encrypt(&serialized, &currentPw, &f, cryptAlgo, hashAlgo);
537 if (e == e_weakPw) { 537 if (e == e_weakPw) {
538 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); 538 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw");
539 f.close(); 539 f.close();
540 ret = e_weakPw; 540 ret = e_weakPw;
541 goto out_moveback; 541 goto out_moveback;
542 } else if (e == e_cryptNotImpl) { 542 } else if (e == e_cryptNotImpl) {
543 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); 543 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl");
544 f.close(); 544 f.close();
545 ret = e_cryptNotImpl; 545 ret = e_cryptNotImpl;
546 goto out_moveback; 546 goto out_moveback;
547 } else if (e != e_success) { 547 } else if (e != e_success) {
548 printDebug("PwMDoc::saveDoc(): encrypt() failed"); 548 printDebug("PwMDoc::saveDoc(): encrypt() failed");
549 f.close(); 549 f.close();
550 ret = e_enc; 550 ret = e_enc;
551 goto out_moveback; 551 goto out_moveback;
552 } 552 }
553 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 553 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
554 f.close(); 554 f.close();
555#ifndef _WIN32_ 555#ifndef _WIN32_
556 if (chmod(filename.latin1(), 556 if (chmod(filename.latin1(),
557 conf()->confGlobFilePermissions())) { 557 conf()->confGlobFilePermissions())) {
558 printWarn(string("chmod failed: ") + strerror(errno)); 558 printWarn(string("chmod failed: ") + strerror(errno));
559 } 559 }
560#endif 560#endif
561 openDocList.edit(this, getTitle().latin1()); 561 openDocList.edit(this, getTitle().latin1());
562 if (wasDeepLocked) { 562 if (wasDeepLocked) {
563 /* Do _not_ save the data with the deepLock() 563 /* Do _not_ save the data with the deepLock()
564 * call, because this will recurse 564 * call, because this will recurse
565 * into saveDoc() 565 * into saveDoc()
566 */ 566 */
567 deepLock(true, false); 567 deepLock(true, false);
568 /* We don't check return value here, because 568 /* We don't check return value here, because
569 * it won't fail. See NOTE in deepLock() 569 * it won't fail. See NOTE in deepLock()
570 */ 570 */
571 } 571 }
572 if (tmpFileMoved != QString::null) { 572 if (tmpFileMoved != QString::null) {
573 // now remove the moved file. 573 // now remove the moved file.
574 if (!QFile::remove(tmpFileMoved)) { 574 if (!QFile::remove(tmpFileMoved)) {
575 printWarn(string("removing file ") 575 printWarn(string("removing file ")
576 + tmpFileMoved.latin1() 576 + tmpFileMoved.latin1()
577 + " failed!"); 577 + " failed!");
578 } 578 }
579 } 579 }
580 ret = e_success; 580 ret = e_success;
581 printDebug(string("writing file { name: ") 581 printDebug(string("writing file { name: ")
582 + filename.latin1() + " compress: " 582 + filename.latin1() + " compress: "
583 + tostr(static_cast<int>(compress)) + " cryptAlgo: " 583 + tostr(static_cast<int>(compress)) + " cryptAlgo: "
584 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " 584 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: "
585 + tostr(static_cast<int>(hashAlgo)) 585 + tostr(static_cast<int>(hashAlgo))
586 + " }"); 586 + " }");
587 goto out; 587 goto out;
588out_moveback: 588out_moveback:
589 if (tmpFileMoved != QString::null) { 589 if (tmpFileMoved != QString::null) {
590 if (copyFile(tmpFileMoved, filename)) { 590 if (copyFile(tmpFileMoved, filename)) {
591 if (!QFile::remove(tmpFileMoved)) { 591 if (!QFile::remove(tmpFileMoved)) {
592 printWarn(string("removing tmp file ") 592 printWarn(string("removing tmp file ")
593 + filename.latin1() 593 + filename.latin1()
594 + " failed!"); 594 + " failed!");
595 } 595 }
596 } else { 596 } else {
597 printWarn(string("couldn't copy file ") 597 printWarn(string("couldn't copy file ")
598 + tmpFileMoved.latin1() 598 + tmpFileMoved.latin1()
599 + " back to " 599 + " back to "
600 + filename.latin1()); 600 + filename.latin1());
601 } 601 }
602 } 602 }
603out: 603out:
604 return ret; 604 return ret;
605} 605}
606 606
607PwMerror PwMDoc::openDoc(const QString *file, int openLocked) 607PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
608{ 608{
609 PWM_ASSERT(file); 609 PWM_ASSERT(file);
610 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); 610 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2);
611 string decrypted, dataHash; 611 string decrypted, dataHash;
612 PwMerror ret; 612 PwMerror ret;
613 char cryptAlgo, dataHashType, compress; 613 char cryptAlgo, dataHashType, compress;
614 unsigned int headerLen; 614 unsigned int headerLen;
615 615
616 if (*file == "") 616 if (*file == "")
617 return e_readFile; 617 return e_readFile;
618 filename = *file; 618 filename = *file;
619 /* check if this file is already open. 619 /* check if this file is already open.
620 * This does not catch symlinks! 620 * This does not catch symlinks!
621 */ 621 */
622 if (!isDeepLocked()) { 622 if (!isDeepLocked()) {
623 if (getOpenDocList()->find(filename.latin1())) 623 if (getOpenDocList()->find(filename.latin1()))
624 return e_alreadyOpen; 624 return e_alreadyOpen;
625 } 625 }
626 QFile f(filename); 626 QFile f(filename);
627 627
628 if (openLocked == 2) { 628 if (openLocked == 2) {
629 // open deep-locked 629 // open deep-locked
630 if (!QFile::exists(filename)) 630 if (!QFile::exists(filename))
631 return e_openFile; 631 return e_openFile;
632 if (deepLock(true, false) != e_success) 632 if (deepLock(true, false) != e_success)
633 return e_openFile; 633 return e_openFile;
634 goto out_success; 634 goto out_success;
635 } 635 }
636 636
637 if (!f.open(IO_ReadOnly)) 637 if (!f.open(IO_ReadOnly))
638 return e_openFile; 638 return e_openFile;
639 639
640 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen, 640 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen,
641 &dataHashType, &dataHash, &f); 641 &dataHashType, &dataHash, &f);
642 if (ret != e_success) { 642 if (ret != e_success) {
643 printDebug("PwMDoc::openDoc(): checkHeader() failed"); 643 printDebug("PwMDoc::openDoc(): checkHeader() failed");
644 f.close(); 644 f.close();
645 if (ret == e_wrongPw) { 645 if (ret == e_wrongPw) {
646 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 646 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
647 return ret; 647 return ret;
648 } else if (ret == e_noPw || 648 } else if (ret == e_noPw ||
649 ret == e_fileVer || 649 ret == e_fileVer ||
650 ret == e_fileFormat || 650 ret == e_fileFormat ||
651 ret == e_hashNotImpl) { 651 ret == e_hashNotImpl) {
652 return ret; 652 return ret;
653 } else 653 } else
654 return e_readFile; 654 return e_readFile;
655 } 655 }
656 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, dataHashType, &f); 656 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, dataHashType, &f);
657 if (ret == e_cryptNotImpl) { 657 if (ret == e_cryptNotImpl) {
658 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); 658 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl");
659 f.close(); 659 f.close();
660 return e_cryptNotImpl; 660 return e_cryptNotImpl;
661 } else if (ret != e_success) { 661 } else if (ret != e_success) {
662 printDebug("PwMDoc::openDoc(): decrypt() failed"); 662 printDebug("PwMDoc::openDoc(): decrypt() failed");
663 f.close(); 663 f.close();
664 return e_readFile; 664 return e_readFile;
665 } 665 }
666 if (!decompressDta(&decrypted, compress)) { 666 if (!decompressDta(&decrypted, compress)) {
667 printDebug("PwMDoc::openDoc(): decompressDta() failed"); 667 printDebug("PwMDoc::openDoc(): decompressDta() failed");
668 f.close(); 668 f.close();
669 return e_fileCorrupt; 669 return e_fileCorrupt;
670 } 670 }
671 ret = checkDataHash(dataHashType, &dataHash, &decrypted); 671 ret = checkDataHash(dataHashType, &dataHash, &decrypted);
672 if (ret == e_hashNotImpl) { 672 if (ret == e_hashNotImpl) {
673 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); 673 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl");
674 f.close(); 674 f.close();
675 return e_hashNotImpl; 675 return e_hashNotImpl;
676 } else if (ret != e_success) { 676 } else if (ret != e_success) {
677 printDebug("PwMDoc::openDoc(): checkDataHash() failed"); 677 printDebug("PwMDoc::openDoc(): checkDataHash() failed");
678 f.close(); 678 f.close();
679 return e_fileCorrupt; 679 return e_fileCorrupt;
680 } 680 }
681 if (!deSerializeDta(&decrypted, openLocked == 1)) { 681 if (!deSerializeDta(&decrypted, openLocked == 1)) {
682 printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); 682 printDebug("PwMDoc::openDoc(): deSerializeDta() failed");
683 f.close(); 683 f.close();
684 return e_readFile; 684 return e_readFile;
685 } 685 }
686 f.close(); 686 f.close();
687 timer()->start(DocTimer::id_mpwTimer); 687 timer()->start(DocTimer::id_mpwTimer);
688 timer()->start(DocTimer::id_autoLockTimer); 688 timer()->start(DocTimer::id_autoLockTimer);
689out_success: 689out_success:
690 openDocList.edit(this, getTitle().latin1()); 690 openDocList.edit(this, getTitle().latin1());
691 emit docOpened(this); 691 emit docOpened(this);
692 return e_success; 692 return e_success;
693} 693}
694 694
695PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 695PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
696 QString *pw, QFile *f) 696 QString *pw, QFile *f)
697{ 697{
698 PWM_ASSERT(pw); 698 PWM_ASSERT(pw);
699 PWM_ASSERT(f); 699 PWM_ASSERT(f);
700 //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else 700 //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else
701 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion 701 //Wenn I sync, I open a doc without a view => listView is 0 => Assertion
702 //USPWM_ASSERT(listView); 702 //USPWM_ASSERT(listView);
703 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != 703 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
704 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { 704 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
705 return e_writeFile; 705 return e_writeFile;
706 } 706 }
707 if (f->putch(PWM_FILE_VER) == -1 || 707 if (f->putch(PWM_FILE_VER) == -1 ||
708 f->putch(keyHash) == -1 || 708 f->putch(keyHash) == -1 ||
709 f->putch(dataHash) == -1 || 709 f->putch(dataHash) == -1 ||
710 f->putch(crypt) == -1 || 710 f->putch(crypt) == -1 ||
711 f->putch(compress) == -1 || 711 f->putch(compress) == -1 ||
712 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? 712 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
713 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { 713 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) {
714 return e_writeFile; 714 return e_writeFile;
715 } 715 }
716 716
717 // write bytes of NUL-data. These bytes are reserved for future-use. 717 // write bytes of NUL-data. These bytes are reserved for future-use.
718 const int bufSize = 64; 718 const int bufSize = 64;
719 char tmp_buf[bufSize]; 719 char tmp_buf[bufSize];
720 memset(tmp_buf, 0x00, bufSize); 720 memset(tmp_buf, 0x00, bufSize);
721 if (f->writeBlock(tmp_buf, bufSize) != bufSize) 721 if (f->writeBlock(tmp_buf, bufSize) != bufSize)
722 return e_writeFile; 722 return e_writeFile;
723 723
724 switch (keyHash) { 724 switch (keyHash) {
725 case PWM_HASH_SHA1: { 725 case PWM_HASH_SHA1: {
726 const int hashlen = SHA1_HASH_LEN_BYTE; 726 const int hashlen = SHA1_HASH_LEN_BYTE;
727 Sha1 hash; 727 Sha1 hash;
728 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 728 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
729 string ret = hash.sha1_read(); 729 string ret = hash.sha1_read();
730 if (f->writeBlock(ret.c_str(), hashlen) != hashlen) 730 if (f->writeBlock(ret.c_str(), hashlen) != hashlen)
731 return e_writeFile; 731 return e_writeFile;
732 break; 732 break;
733 } 733 }
734 case PWM_HASH_SHA256: 734 case PWM_HASH_SHA256:
735 /*... fall through */ 735 /*... fall through */
736 case PWM_HASH_SHA384: 736 case PWM_HASH_SHA384:
737 case PWM_HASH_SHA512: 737 case PWM_HASH_SHA512:
738 case PWM_HASH_MD5: 738 case PWM_HASH_MD5:
739 case PWM_HASH_RMD160: 739 case PWM_HASH_RMD160:
740 case PWM_HASH_TIGER: 740 case PWM_HASH_TIGER:
741 { 741 {
742 if (!LibGCryptIf::available()) 742 if (!LibGCryptIf::available())
743 return e_hashNotImpl; 743 return e_hashNotImpl;
744 LibGCryptIf gc; 744 LibGCryptIf gc;
745 PwMerror err; 745 PwMerror err;
746 unsigned char *buf; 746 unsigned char *buf;
747 size_t hashLen; 747 size_t hashLen;
748 err = gc.hash(&buf, 748 err = gc.hash(&buf,
749 &hashLen, 749 &hashLen,
750 reinterpret_cast<const unsigned char *>(pw->latin1()), 750 reinterpret_cast<const unsigned char *>(pw->latin1()),
751 pw->length(), 751 pw->length(),
752 keyHash); 752 keyHash);
753 if (err != e_success) 753 if (err != e_success)
754 return e_hashNotImpl; 754 return e_hashNotImpl;
755 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 755 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
756 != static_cast<Q_LONG>(hashLen)) { 756 != static_cast<Q_LONG>(hashLen)) {
757 delete [] buf; 757 delete [] buf;
758 return e_hashNotImpl; 758 return e_hashNotImpl;
759 } 759 }
760 delete [] buf; 760 delete [] buf;
761 break; 761 break;
762 } 762 }
763 default: { 763 default: {
764 return e_hashNotImpl; 764 return e_hashNotImpl;
765 } } 765 } }
766 return e_success; 766 return e_success;
767} 767}
768 768
769PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, 769PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
770 unsigned int *headerLength, char *dataHashType, 770 unsigned int *headerLength, char *dataHashType,
771 string *dataHash, QFile *f) 771 string *dataHash, QFile *f)
772{ 772{
773 PWM_ASSERT(cryptAlgo); 773 PWM_ASSERT(cryptAlgo);
774 PWM_ASSERT(pw); 774 PWM_ASSERT(pw);
775 PWM_ASSERT(headerLength); 775 PWM_ASSERT(headerLength);
776 PWM_ASSERT(dataHashType); 776 PWM_ASSERT(dataHashType);
777 PWM_ASSERT(dataHash); 777 PWM_ASSERT(dataHash);
778 PWM_ASSERT(f); 778 PWM_ASSERT(f);
779 int tmpRet; 779 int tmpRet;
780 // check "magic" header 780 // check "magic" header
781 const char magicHdr[] = FILE_ID_HEADER; 781 const char magicHdr[] = FILE_ID_HEADER;
782 const int hdrLen = array_size(magicHdr) - 1; 782 const int hdrLen = array_size(magicHdr) - 1;
783 char tmp[hdrLen]; 783 char tmp[hdrLen];
784 if (f->readBlock(tmp, hdrLen) != hdrLen) 784 if (f->readBlock(tmp, hdrLen) != hdrLen)
785 return e_readFile; 785 return e_readFile;
786 if (memcmp(tmp, magicHdr, hdrLen) != 0) 786 if (memcmp(tmp, magicHdr, hdrLen) != 0)
787 return e_fileFormat; 787 return e_fileFormat;
788 // read and check file ver 788 // read and check file ver
789 int fileV = f->getch(); 789 int fileV = f->getch();
790 if (fileV == -1) 790 if (fileV == -1)
791 return e_fileFormat; 791 return e_fileFormat;
792 if (fileV != PWM_FILE_VER) 792 if (fileV != PWM_FILE_VER)
793 return e_fileVer; 793 return e_fileVer;
794 // read hash hash type 794 // read hash hash type
795 int keyHash = f->getch(); 795 int keyHash = f->getch();
796 if (keyHash == -1) 796 if (keyHash == -1)
797 return e_fileFormat; 797 return e_fileFormat;
798 // read data hash type 798 // read data hash type
799 tmpRet = f->getch(); 799 tmpRet = f->getch();
800 if (tmpRet == -1) 800 if (tmpRet == -1)
801 return e_fileFormat; 801 return e_fileFormat;
802 *dataHashType = tmpRet; 802 *dataHashType = tmpRet;
803 // read crypt algo 803 // read crypt algo
804 tmpRet = f->getch(); 804 tmpRet = f->getch();
805 if (tmpRet == -1) 805 if (tmpRet == -1)
806 return e_fileFormat; 806 return e_fileFormat;
807 *cryptAlgo = tmpRet; 807 *cryptAlgo = tmpRet;
808 // get compression-algo 808 // get compression-algo
809 tmpRet = f->getch(); 809 tmpRet = f->getch();
810 if (tmpRet == -1) 810 if (tmpRet == -1)
811 return e_fileFormat; 811 return e_fileFormat;
812 *compress = tmpRet; 812 *compress = tmpRet;
813 // get the MPW-flag 813 // get the MPW-flag
814 int mpw_flag = f->getch(); 814 int mpw_flag = f->getch();
815 if (mpw_flag == -1) 815 if (mpw_flag == -1)
816 return e_fileFormat; 816 return e_fileFormat;
817 if (mpw_flag == 0x01) 817 if (mpw_flag == 0x01)
818 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 818 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
819 else 819 else
820 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 820 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
821 // skip the "RESERVED"-bytes 821 // skip the "RESERVED"-bytes
822 if (!(f->at(f->at() + 64))) 822 if (!(f->at(f->at() + 64)))
823 return e_fileFormat; 823 return e_fileFormat;
824 824
825 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 825 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
826 if (*pw == "") { 826 if (*pw == "") {
827 /* the user didn't give a master-password 827 /* the user didn't give a master-password
828 * or didn't insert a chipcard 828 * or didn't insert a chipcard
829 */ 829 */
830 return e_noPw; 830 return e_noPw;
831 } 831 }
832 // verify key-hash 832 // verify key-hash
833 switch (keyHash) { 833 switch (keyHash) {
834 case PWM_HASH_SHA1: { 834 case PWM_HASH_SHA1: {
835 // read hash from header 835 // read hash from header
836 const int hashLen = SHA1_HASH_LEN_BYTE; 836 const int hashLen = SHA1_HASH_LEN_BYTE;
837 string readHash; 837 string readHash;
838 int i; 838 int i;
839 for (i = 0; i < hashLen; ++i) 839 for (i = 0; i < hashLen; ++i)
840 readHash.push_back(f->getch()); 840 readHash.push_back(f->getch());
841 Sha1 hash; 841 Sha1 hash;
842 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); 842 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
843 string ret = hash.sha1_read(); 843 string ret = hash.sha1_read();
844 if (ret != readHash) 844 if (ret != readHash)
845 return e_wrongPw;// hash doesn't match (wrong key) 845 return e_wrongPw;// hash doesn't match (wrong key)
846 break; 846 break;
847 } 847 }
848 case PWM_HASH_SHA256: 848 case PWM_HASH_SHA256:
849 /*... fall through */ 849 /*... fall through */
850 case PWM_HASH_SHA384: 850 case PWM_HASH_SHA384:
851 case PWM_HASH_SHA512: 851 case PWM_HASH_SHA512:
852 case PWM_HASH_MD5: 852 case PWM_HASH_MD5:
853 case PWM_HASH_RMD160: 853 case PWM_HASH_RMD160:
854 case PWM_HASH_TIGER: { 854 case PWM_HASH_TIGER: {
855 if (!LibGCryptIf::available()) 855 if (!LibGCryptIf::available())
856 return e_hashNotImpl; 856 return e_hashNotImpl;
857 LibGCryptIf gc; 857 LibGCryptIf gc;
858 PwMerror err; 858 PwMerror err;
859 unsigned char *buf; 859 unsigned char *buf;
860 size_t hashLen; 860 size_t hashLen;
861 err = gc.hash(&buf, 861 err = gc.hash(&buf,
862 &hashLen, 862 &hashLen,
863 reinterpret_cast<const unsigned char *>(pw->latin1()), 863 reinterpret_cast<const unsigned char *>(pw->latin1()),
864 pw->length(), 864 pw->length(),
865 keyHash); 865 keyHash);
866 if (err != e_success) 866 if (err != e_success)
867 return e_hashNotImpl; 867 return e_hashNotImpl;
868 string calcHash(reinterpret_cast<const char *>(buf), 868 string calcHash(reinterpret_cast<const char *>(buf),
869 static_cast<string::size_type>(hashLen)); 869 static_cast<string::size_type>(hashLen));
870 delete [] buf; 870 delete [] buf;
871 // read hash from header 871 // read hash from header
872 string readHash; 872 string readHash;
873 size_t i; 873 size_t i;
874 for (i = 0; i < hashLen; ++i) 874 for (i = 0; i < hashLen; ++i)
875 readHash.push_back(f->getch()); 875 readHash.push_back(f->getch());
876 if (calcHash != readHash) 876 if (calcHash != readHash)
877 return e_wrongPw;// hash doesn't match (wrong key) 877 return e_wrongPw;// hash doesn't match (wrong key)
878 break; 878 break;
879 } 879 }
880 default: { 880 default: {
881 return e_hashNotImpl; 881 return e_hashNotImpl;
882 } } 882 } }
883 // read the data-hash from the file 883 // read the data-hash from the file
884 unsigned int hashLen, i; 884 unsigned int hashLen, i;
885 switch (*dataHashType) { 885 switch (*dataHashType) {
886 case PWM_HASH_SHA1: 886 case PWM_HASH_SHA1:
887 hashLen = SHA1_HASH_LEN_BYTE; 887 hashLen = SHA1_HASH_LEN_BYTE;
888 break; 888 break;
889 case PWM_HASH_SHA256: 889 case PWM_HASH_SHA256:
890 /*... fall through */ 890 /*... fall through */
891 case PWM_HASH_SHA384: 891 case PWM_HASH_SHA384:
892 case PWM_HASH_SHA512: 892 case PWM_HASH_SHA512:
893 case PWM_HASH_MD5: 893 case PWM_HASH_MD5:
894 case PWM_HASH_RMD160: 894 case PWM_HASH_RMD160:
895 case PWM_HASH_TIGER: { 895 case PWM_HASH_TIGER: {
896 if (!LibGCryptIf::available()) 896 if (!LibGCryptIf::available())
897 return e_hashNotImpl; 897 return e_hashNotImpl;
898 LibGCryptIf gc; 898 LibGCryptIf gc;
899 hashLen = gc.hashLength(*dataHashType); 899 hashLen = gc.hashLength(*dataHashType);
900 if (hashLen == 0) 900 if (hashLen == 0)
901 return e_hashNotImpl; 901 return e_hashNotImpl;
902 break; 902 break;
903 } 903 }
904 default: 904 default:
905 return e_hashNotImpl; 905 return e_hashNotImpl;
906 } 906 }
907 *dataHash = ""; 907 *dataHash = "";
908 for (i = 0; i < hashLen; ++i) { 908 for (i = 0; i < hashLen; ++i) {
909 tmpRet = f->getch(); 909 tmpRet = f->getch();
910 if (tmpRet == -1) 910 if (tmpRet == -1)
911 return e_fileFormat; 911 return e_fileFormat;
912 dataHash->push_back(static_cast<char>(tmpRet)); 912 dataHash->push_back(static_cast<char>(tmpRet));
913 } 913 }
914 *headerLength = f->at(); 914 *headerLength = f->at();
915#ifndef PWM_EMBEDDED 915#ifndef PWM_EMBEDDED
916 printDebug(string("opening file { compress: ") 916 printDebug(string("opening file { compress: ")
917 + tostr(static_cast<int>(*compress)) + " cryptAlgo: " 917 + tostr(static_cast<int>(*compress)) + " cryptAlgo: "
918 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " 918 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: "
919 + tostr(static_cast<int>(keyHash)) 919 + tostr(static_cast<int>(keyHash))
920 + " }"); 920 + " }");
921#else 921#else
922 printDebug(string("opening file { compress: ") 922 printDebug(string("opening file { compress: ")
923 + tostr((int)(*compress)) + " cryptAlgo: " 923 + tostr((int)(*compress)) + " cryptAlgo: "
924 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " 924 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: "
925 + tostr((int)(keyHash)) 925 + tostr((int)(keyHash))
926 + " }"); 926 + " }");
927#endif 927#endif
928 928
929 return e_success; 929 return e_success;
930} 930}
931 931
932PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) 932PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
933{ 933{
934 PWM_ASSERT(d); 934 PWM_ASSERT(d);
935 PWM_ASSERT(f); 935 PWM_ASSERT(f);
936 936
937 switch (dataHash) { 937 switch (dataHash) {
938 case PWM_HASH_SHA1: { 938 case PWM_HASH_SHA1: {
939 const int hashLen = SHA1_HASH_LEN_BYTE; 939 const int hashLen = SHA1_HASH_LEN_BYTE;
940 Sha1 h; 940 Sha1 h;
941 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); 941 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size());
942 string hRet = h.sha1_read(); 942 string hRet = h.sha1_read();
943 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) 943 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen)
944 return e_writeFile; 944 return e_writeFile;
945 break; 945 break;
946 } 946 }
947 case PWM_HASH_SHA256: 947 case PWM_HASH_SHA256:
948 /*... fall through */ 948 /*... fall through */
949 case PWM_HASH_SHA384: 949 case PWM_HASH_SHA384:
950 case PWM_HASH_SHA512: 950 case PWM_HASH_SHA512:
951 case PWM_HASH_MD5: 951 case PWM_HASH_MD5:
952 case PWM_HASH_RMD160: 952 case PWM_HASH_RMD160:
953 case PWM_HASH_TIGER: { 953 case PWM_HASH_TIGER: {
954 if (!LibGCryptIf::available()) 954 if (!LibGCryptIf::available())
955 return e_hashNotImpl; 955 return e_hashNotImpl;
956 LibGCryptIf gc; 956 LibGCryptIf gc;
957 PwMerror err; 957 PwMerror err;
958 unsigned char *buf; 958 unsigned char *buf;
959 size_t hashLen; 959 size_t hashLen;
960 err = gc.hash(&buf, 960 err = gc.hash(&buf,
961 &hashLen, 961 &hashLen,
962 reinterpret_cast<const unsigned char *>(d->c_str()), 962 reinterpret_cast<const unsigned char *>(d->c_str()),
963 d->size(), 963 d->size(),
964 dataHash); 964 dataHash);
965 if (err != e_success) 965 if (err != e_success)
966 return e_hashNotImpl; 966 return e_hashNotImpl;
967 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) 967 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
968 != static_cast<Q_LONG>(hashLen)) { 968 != static_cast<Q_LONG>(hashLen)) {
969 delete [] buf; 969 delete [] buf;
970 return e_hashNotImpl; 970 return e_hashNotImpl;
971 } 971 }
972 delete [] buf; 972 delete [] buf;
973 break; 973 break;
974 } 974 }
975 default: { 975 default: {
976 return e_hashNotImpl; 976 return e_hashNotImpl;
977 } } 977 } }
978 978
979 return e_success; 979 return e_success;
980} 980}
981 981
982bool PwMDoc::backupFile(const QString &filePath) 982bool PwMDoc::backupFile(const QString &filePath)
983{ 983{
984 QFileInfo fi(filePath); 984 QFileInfo fi(filePath);
985 if (!fi.exists()) 985 if (!fi.exists())
986 return true; // Yes, true is correct. 986 return true; // Yes, true is correct.
987 QString pathOnly(fi.dirPath(true)); 987 QString pathOnly(fi.dirPath(true));
988 QString nameOnly(fi.fileName()); 988 QString nameOnly(fi.fileName());
989 QString backupPath = pathOnly 989 QString backupPath = pathOnly
990 + "/~" 990 + "/~"
991 + nameOnly 991 + nameOnly
992 + ".backup"; 992 + ".backup";
993 return copyFile(filePath, backupPath); 993 return copyFile(filePath, backupPath);
994} 994}
995 995
996bool PwMDoc::copyFile(const QString &src, const QString &dst) 996bool PwMDoc::copyFile(const QString &src, const QString &dst)
997{ 997{
998 QFileInfo fi(src); 998 QFileInfo fi(src);
999 if (!fi.exists()) 999 if (!fi.exists())
1000 return false; 1000 return false;
1001 if (QFile::exists(dst)) { 1001 if (QFile::exists(dst)) {
1002 if (!QFile::remove(dst)) 1002 if (!QFile::remove(dst))
1003 return false; 1003 return false;
1004 } 1004 }
1005 QFile srcFd(src); 1005 QFile srcFd(src);
1006 if (!srcFd.open(IO_ReadOnly)) 1006 if (!srcFd.open(IO_ReadOnly))
1007 return false; 1007 return false;
1008 QFile dstFd(dst); 1008 QFile dstFd(dst);
1009 if (!dstFd.open(IO_ReadWrite)) { 1009 if (!dstFd.open(IO_ReadWrite)) {
1010 srcFd.close(); 1010 srcFd.close();
1011 return false; 1011 return false;
1012 } 1012 }
1013 const int tmpBuf_size = 512; 1013 const int tmpBuf_size = 512;
1014 char tmpBuf[tmpBuf_size]; 1014 char tmpBuf[tmpBuf_size];
1015 Q_LONG bytesRead, bytesWritten; 1015 Q_LONG bytesRead, bytesWritten;
1016 1016
1017 while (!srcFd.atEnd()) { 1017 while (!srcFd.atEnd()) {
1018 bytesRead = srcFd.readBlock(tmpBuf, 1018 bytesRead = srcFd.readBlock(tmpBuf,
1019 static_cast<Q_ULONG>(tmpBuf_size)); 1019 static_cast<Q_ULONG>(tmpBuf_size));
1020 if (bytesRead == -1) { 1020 if (bytesRead == -1) {
1021 srcFd.close(); 1021 srcFd.close();
1022 dstFd.close(); 1022 dstFd.close();
1023 return false; 1023 return false;
1024 } 1024 }
1025 bytesWritten = dstFd.writeBlock(tmpBuf, 1025 bytesWritten = dstFd.writeBlock(tmpBuf,
1026 static_cast<Q_ULONG>(bytesRead)); 1026 static_cast<Q_ULONG>(bytesRead));
1027 if (bytesWritten != bytesRead) { 1027 if (bytesWritten != bytesRead) {
1028 srcFd.close(); 1028 srcFd.close();
1029 dstFd.close(); 1029 dstFd.close();
1030 return false; 1030 return false;
1031 } 1031 }
1032 } 1032 }
1033 srcFd.close(); 1033 srcFd.close();
1034 dstFd.close(); 1034 dstFd.close();
1035 return true; 1035 return true;
1036} 1036}
1037 1037
1038PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, 1038PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
1039 bool dontFlagDirty, bool updateMeta) 1039 bool dontFlagDirty, bool updateMeta)
1040{ 1040{
1041 PWM_ASSERT(d); 1041 PWM_ASSERT(d);
1042 unsigned int cat = 0; 1042 unsigned int cat = 0;
1043 1043
1044 if (isDeepLocked()) { 1044 if (isDeepLocked()) {
1045 PwMerror ret; 1045 PwMerror ret;
1046 ret = deepLock(false); 1046 ret = deepLock(false);
1047 if (ret != e_success) 1047 if (ret != e_success)
1048 return e_lock; 1048 return e_lock;
1049 } 1049 }
1050 1050
1051 addCategory(category, &cat); 1051 addCategory(category, &cat);
1052 1052
1053 if (numEntries(category) >= maxEntries) 1053 if (numEntries(category) >= maxEntries)
1054 return e_maxAllowedEntr; 1054 return e_maxAllowedEntr;
1055 1055
1056 vector<unsigned int> foundPositions; 1056 vector<unsigned int> foundPositions;
1057 /* historically this was: 1057 /* historically this was:
1058 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | 1058 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
1059 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; 1059 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
1060 * But for now we only search in desc. 1060 * But for now we only search in desc.
1061 * That's a tweak to be KWallet compatible. But it should not add 1061 * That's a tweak to be KWallet compatible. But it should not add
1062 * usability-drop onto PwManager, does it? 1062 * usability-drop onto PwManager, does it?
1063 * (And yes, "int" was a bug. Correct is "unsigned int") 1063 * (And yes, "int" was a bug. Correct is "unsigned int")
1064 */ 1064 */
1065 const unsigned int searchIn = SEARCH_IN_DESC; 1065 const unsigned int searchIn = SEARCH_IN_DESC;
1066 findEntry(cat, *d, searchIn, &foundPositions, true); 1066 findEntry(cat, *d, searchIn, &foundPositions, true);
1067 if (foundPositions.size()) { 1067 if (foundPositions.size()) {
1068 // DOH! We found this entry. 1068 // DOH! We found this entry.
1069 return e_entryExists; 1069 return e_entryExists;
1070 } 1070 }
1071 1071
1072 d->listViewPos = -1; 1072 d->listViewPos = -1;
1073 d->lockStat = conf()->confGlobNewEntrLockStat(); 1073 d->lockStat = conf()->confGlobNewEntrLockStat();
1074 if (updateMeta) { 1074 if (updateMeta) {
1075 d->meta.create = QDateTime::currentDateTime(); 1075 d->meta.create = QDateTime::currentDateTime();
1076 d->meta.update = d->meta.create; 1076 d->meta.update = d->meta.create;
1077 } 1077 }
1078 dti.dta[cat].d.push_back(*d); 1078 dti.dta[cat].d.push_back(*d);
1079 1079
1080 delAllEmptyCat(true); 1080 delAllEmptyCat(true);
1081 1081
1082 if (!dontFlagDirty) 1082 if (!dontFlagDirty)
1083 flagDirty(); 1083 flagDirty();
1084 return e_success; 1084 return e_success;
1085} 1085}
1086 1086
1087PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, 1087PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
1088 bool checkIfExist) 1088 bool checkIfExist)
1089{ 1089{
1090 if (isDeepLocked()) { 1090 if (isDeepLocked()) {
1091 PwMerror ret; 1091 PwMerror ret;
1092 ret = deepLock(false); 1092 ret = deepLock(false);
1093 if (ret != e_success) 1093 if (ret != e_success)
1094 return e_lock; 1094 return e_lock;
1095 } 1095 }
1096 if (checkIfExist) { 1096 if (checkIfExist) {
1097 if (findCategory(category, categoryIndex)) 1097 if (findCategory(category, categoryIndex))
1098 return e_categoryExists; 1098 return e_categoryExists;
1099 } 1099 }
1100 PwMCategoryItem item; 1100 PwMCategoryItem item;
1101 //US ENH: clear item to initialize with default values, or create a constructor 1101 //US ENH: clear item to initialize with default values, or create a constructor
1102 item.clear(); 1102 item.clear();
1103 1103
1104 item.name = category.latin1(); 1104 item.name = category.latin1();
1105 dti.dta.push_back(item); 1105 dti.dta.push_back(item);
1106 if (categoryIndex) 1106 if (categoryIndex)
1107 *categoryIndex = dti.dta.size() - 1; 1107 *categoryIndex = dti.dta.size() - 1;
1108 return e_success; 1108 return e_success;
1109} 1109}
1110 1110
1111bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) 1111bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1112{ 1112{
1113 unsigned int cat = 0; 1113 unsigned int cat = 0;
1114 1114
1115 if (!findCategory(category, &cat)) { 1115 if (!findCategory(category, &cat)) {
1116 BUG(); 1116 BUG();
1117 return false; 1117 return false;
1118 } 1118 }
1119 1119
1120 return delEntry(cat, index, dontFlagDirty); 1120 return delEntry(cat, index, dontFlagDirty);
1121} 1121}
1122 1122
1123bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) 1123bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1124{ 1124{
1125 if (isDeepLocked()) 1125 if (isDeepLocked())
1126 return false; 1126 return false;
1127 if (index > dti.dta[category].d.size() - 1) 1127 if (index > dti.dta[category].d.size() - 1)
1128 return false; 1128 return false;
1129 getDataChangedLock(); 1129 getDataChangedLock();
1130 if (!lockAt(category, index, false)) { 1130 if (!lockAt(category, index, false)) {
1131 putDataChangedLock(); 1131 putDataChangedLock();
1132 return false; 1132 return false;
1133 } 1133 }
1134 putDataChangedLock(); 1134 putDataChangedLock();
1135 int lvPos = dti.dta[category].d[index].listViewPos; 1135 int lvPos = dti.dta[category].d[index].listViewPos;
1136 1136
1137 // delete entry 1137 // delete entry
1138 dti.dta[category].d.erase(dti.dta[category].d.begin() + index); 1138 dti.dta[category].d.erase(dti.dta[category].d.begin() + index);
1139 1139
1140 unsigned int i, entries = numEntries(category); 1140 unsigned int i, entries = numEntries(category);
1141 if (!entries) { 1141 if (!entries) {
1142 // no more entries in this category, so 1142 // no more entries in this category, so
1143 // we can delete it, too. 1143 // we can delete it, too.
1144 BUG_ON(!delCategory(category)); 1144 BUG_ON(!delCategory(category));
1145 // delCategory() flags it dirty, so we need not to do so. 1145 // delCategory() flags it dirty, so we need not to do so.
1146 return true; 1146 return true;
1147 } 1147 }
1148 for (i = 0; i < entries; ++i) { 1148 for (i = 0; i < entries; ++i) {
1149 // decrement all listViewPositions that are greater than the deleted. 1149 // decrement all listViewPositions that are greater than the deleted.
1150 if (dti.dta[category].d[i].listViewPos > lvPos) 1150 if (dti.dta[category].d[i].listViewPos > lvPos)
1151 --dti.dta[category].d[i].listViewPos; 1151 --dti.dta[category].d[i].listViewPos;
1152 } 1152 }
1153 1153
1154 if (!dontFlagDirty) 1154 if (!dontFlagDirty)
1155 flagDirty(); 1155 flagDirty();
1156 return true; 1156 return true;
1157} 1157}
1158 1158
1159bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, 1159bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1160 unsigned int index, PwMDataItem *d, bool updateMeta) 1160 unsigned int index, PwMDataItem *d, bool updateMeta)
1161{ 1161{
1162 PWM_ASSERT(d); 1162 PWM_ASSERT(d);
1163 unsigned int oldCat = 0; 1163 unsigned int oldCat = 0;
1164 1164
1165 if (!findCategory(oldCategory, &oldCat)) { 1165 if (!findCategory(oldCategory, &oldCat)) {
1166 BUG(); 1166 BUG();
1167 return false; 1167 return false;
1168 } 1168 }
1169 1169
1170 return editEntry(oldCat, newCategory, index, d, updateMeta); 1170 return editEntry(oldCat, newCategory, index, d, updateMeta);
1171} 1171}
1172 1172
1173bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, 1173bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1174 unsigned int index, PwMDataItem *d, bool updateMeta) 1174 unsigned int index, PwMDataItem *d, bool updateMeta)
1175{ 1175{
1176 if (isDeepLocked()) 1176 if (isDeepLocked())
1177 return false; 1177 return false;
1178 if (updateMeta) { 1178 if (updateMeta) {
1179 d->meta.update = QDateTime::currentDateTime(); 1179 d->meta.update = QDateTime::currentDateTime();
1180 if (d->meta.create.isNull()) { 1180 if (d->meta.create.isNull()) {
1181 d->meta.create = d->meta.update; 1181 d->meta.create = d->meta.update;
1182 } 1182 }
1183 } 1183 }
1184 if (dti.dta[oldCategory].name != newCategory.latin1()) { 1184 if (dti.dta[oldCategory].name != newCategory.latin1()) {
1185 // the user changed the category. 1185 // the user changed the category.
1186 PwMerror ret; 1186 PwMerror ret;
1187 d->rev = 0; 1187 d->rev = 0;
1188 ret = addEntry(newCategory, d, true, false); 1188 ret = addEntry(newCategory, d, true, false);
1189 if (ret != e_success) 1189 if (ret != e_success)
1190 return false; 1190 return false;
1191 if (!delEntry(oldCategory, index, true)) 1191 if (!delEntry(oldCategory, index, true))
1192 return false; 1192 return false;
1193 } else { 1193 } else {
1194 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. 1194 d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter.
1195 dti.dta[oldCategory].d[index] = *d; 1195 dti.dta[oldCategory].d[index] = *d;
1196 } 1196 }
1197 flagDirty(); 1197 flagDirty();
1198 return true; 1198 return true;
1199} 1199}
1200 1200
1201unsigned int PwMDoc::numEntries(const QString &category) 1201unsigned int PwMDoc::numEntries(const QString &category)
1202{ 1202{
1203 unsigned int cat = 0; 1203 unsigned int cat = 0;
1204 1204
1205 if (!findCategory(category, &cat)) { 1205 if (!findCategory(category, &cat)) {
1206 BUG(); 1206 BUG();
1207 return 0; 1207 return 0;
1208 } 1208 }
1209 1209
1210 return numEntries(cat); 1210 return numEntries(cat);
1211} 1211}
1212 1212
1213bool PwMDoc::serializeDta(string *d) 1213bool PwMDoc::serializeDta(string *d)
1214{ 1214{
1215 PWM_ASSERT(d); 1215 PWM_ASSERT(d);
1216 Serializer ser; 1216 Serializer ser;
1217 if (!ser.serialize(dti)) 1217 if (!ser.serialize(dti))
1218 return false; 1218 return false;
1219 d->assign(ser.getXml()); 1219 d->assign(ser.getXml());
1220 if (!d->size()) 1220 if (!d->size())
1221 return false; 1221 return false;
1222 return true; 1222 return true;
1223} 1223}
1224 1224
1225bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1225bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1226{ 1226{
1227 PWM_ASSERT(d); 1227 PWM_ASSERT(d);
1228#ifndef PWM_EMBEDDED 1228#ifndef PWM_EMBEDDED
1229 try { 1229 try {
1230 1230
1231 Serializer ser(d->c_str()); 1231 Serializer ser(d->c_str());
1232 ser.setDefaultLockStat(entriesLocked); 1232 ser.setDefaultLockStat(entriesLocked);
1233 if (!ser.deSerialize(&dti)) 1233 if (!ser.deSerialize(&dti))
1234 return false; 1234 return false;
1235 } catch (PwMException) { 1235 } catch (PwMException) {
1236 return false; 1236 return false;
1237 } 1237 }
1238#else 1238#else
1239 Serializer ser(d->c_str()); 1239 Serializer ser(d->c_str());
1240 ser.setDefaultLockStat(entriesLocked); 1240 ser.setDefaultLockStat(entriesLocked);
1241 if (!ser.deSerialize(&dti)) 1241 if (!ser.deSerialize(&dti))
1242 return false; 1242 return false;
1243#endif 1243#endif
1244 1244
1245 emitDataChanged(this); 1245 emitDataChanged(this);
1246 return true; 1246 return true;
1247} 1247}
1248 1248
1249bool PwMDoc::getEntry(const QString &category, unsigned int index, 1249bool PwMDoc::getEntry(const QString &category, unsigned int index,
1250 PwMDataItem * d, bool unlockIfLocked) 1250 PwMDataItem * d, bool unlockIfLocked)
1251{ 1251{
1252 PWM_ASSERT(d); 1252 PWM_ASSERT(d);
1253 unsigned int cat = 0; 1253 unsigned int cat = 0;
1254 1254
1255 if (!findCategory(category, &cat)) { 1255 if (!findCategory(category, &cat)) {
1256 BUG(); 1256 BUG();
1257 return false; 1257 return false;
1258 } 1258 }
1259 1259
1260 return getEntry(cat, index, d, unlockIfLocked); 1260 return getEntry(cat, index, d, unlockIfLocked);
1261} 1261}
1262 1262
1263bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1263bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1264 PwMDataItem *d, bool unlockIfLocked) 1264 PwMDataItem *d, bool unlockIfLocked)
1265{ 1265{
1266 if (index > dti.dta[category].d.size() - 1) 1266 if (index > dti.dta[category].d.size() - 1)
1267 return false; 1267 return false;
1268 1268
1269 bool locked = isLocked(category, index); 1269 bool locked = isLocked(category, index);
1270 if (locked) { 1270 if (locked) {
1271 /* this entry is locked. We don't return a password, 1271 /* this entry is locked. We don't return a password,
1272 * until it's unlocked by the user by inserting 1272 * until it's unlocked by the user by inserting
1273 * chipcard or entering the mpw 1273 * chipcard or entering the mpw
1274 */ 1274 */
1275 if (unlockIfLocked) { 1275 if (unlockIfLocked) {
1276 if (!lockAt(category, index, false)) { 1276 if (!lockAt(category, index, false)) {
1277 return false; 1277 return false;
1278 } 1278 }
1279 locked = false; 1279 locked = false;
1280 } 1280 }
1281 } 1281 }
1282 1282
1283 *d = dti.dta[category].d[index]; 1283 *d = dti.dta[category].d[index];
1284 if (locked) 1284 if (locked)
1285 d->pw = LOCKED_STRING.latin1(); 1285 d->pw = LOCKED_STRING.latin1();
1286 1286
1287 return true; 1287 return true;
1288} 1288}
1289PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1289PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1290 string *foundComment) 1290 string *foundComment)
1291{ 1291{
1292 PWM_ASSERT(foundComment); 1292 PWM_ASSERT(foundComment);
1293 unsigned int cat = 0; 1293 unsigned int cat = 0;
1294 1294
1295 if (!findCategory(category, &cat)) 1295 if (!findCategory(category, &cat))
1296 return e_invalidArg; 1296 return e_invalidArg;
1297 1297
1298 unsigned int i, entries = numEntries(cat); 1298 unsigned int i, entries = numEntries(cat);
1299 for (i = 0; i < entries; ++i) { 1299 for (i = 0; i < entries; ++i) {
1300 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1300 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1301 *foundComment = dti.dta[cat].d[i].comment; 1301 *foundComment = dti.dta[cat].d[i].comment;
1302 if (dti.dta[cat].d[i].binary) 1302 if (dti.dta[cat].d[i].binary)
1303 return e_binEntry; 1303 return e_binEntry;
1304 return e_normalEntry; 1304 return e_normalEntry;
1305 } 1305 }
1306 } 1306 }
1307 BUG(); 1307 BUG();
1308 return e_generic; 1308 return e_generic;
1309} 1309}
1310 1310
1311PwMerror PwMDoc::getCommentByLvp_long(const QString &category, int listViewPos, 1311PwMerror PwMDoc::getCommentByLvp_long(const QString &category, int listViewPos,
1312 string *foundComment) 1312 string *foundComment)
1313{ 1313{
1314 PWM_ASSERT(foundComment); 1314 PWM_ASSERT(foundComment);
1315 unsigned int cat = 0; 1315 unsigned int cat = 0;
1316 1316
1317 if (!findCategory(category, &cat)) 1317 if (!findCategory(category, &cat))
1318 return e_invalidArg; 1318 return e_invalidArg;
1319 1319
1320 unsigned int i, entries = numEntries(cat); 1320 unsigned int i, entries = numEntries(cat);
1321 for (i = 0; i < entries; ++i) { 1321 for (i = 0; i < entries; ++i) {
1322 if (dti.dta[cat].d[i].listViewPos == listViewPos) { 1322 if (dti.dta[cat].d[i].listViewPos == listViewPos) {
1323 if (dti.dta[cat].d[i].binary) 1323 if (dti.dta[cat].d[i].binary)
1324 return e_binEntry; 1324 return e_binEntry;
1325 PwMCategoryItem* catItem = getCategoryEntry(cat); 1325 PwMCategoryItem* catItem = getCategoryEntry(cat);
1326 QString retval; 1326 QString retval;
1327 QString tempval = QString (dti.dta[cat].d[i].desc.c_str()); 1327 QString tempval = QString (dti.dta[cat].d[i].desc.c_str());
1328 if ( !tempval.isEmpty() ) { 1328 if ( !tempval.isEmpty() ) {
1329 retval += "<b>" +QString ( catItem->desc_text.c_str() )+ ":</b> "+ tempval+"<br>" ; 1329 retval += "<b>" +QString ( catItem->desc_text.c_str() )+ ":</b> "+ tempval+"<br>" ;
1330 } 1330 }
1331 tempval = QString (dti.dta[cat].d[i].name.c_str()); 1331 tempval = QString (dti.dta[cat].d[i].name.c_str());
1332 if ( !tempval.isEmpty() ) { 1332 if ( !tempval.isEmpty() ) {
1333 retval += "<b>" +QString ( catItem->name_text.c_str() ) + ":</b> "+ tempval+"<br>" ; 1333 retval += "<b>" +QString ( catItem->name_text.c_str() ) + ":</b> "+ tempval+"<br>" ;
1334 } 1334 }
1335 tempval = QString (dti.dta[cat].d[i].pw.c_str()); 1335 tempval = QString (dti.dta[cat].d[i].pw.c_str());
1336 if ( !tempval.isEmpty() ) { 1336 if ( !tempval.isEmpty() ) {
1337 if ( dti.dta[cat].d[i].lockStat ) 1337 if ( dti.dta[cat].d[i].lockStat )
1338 retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ": " + i18n("LOCKED") +"</b><br>" ; 1338 retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ": " + i18n("LOCKED") +"</b><br>" ;
1339 else 1339 else
1340 retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + tempval+"<br>" ; 1340 retval += "<b>" +QString ( catItem->pw_text.c_str() )+ ":</b> " + tempval+"<br>" ;
1341 } 1341 }
1342 tempval = QString (dti.dta[cat].d[i].url.c_str()); 1342 tempval = QString (dti.dta[cat].d[i].url.c_str());
1343 if ( !tempval.isEmpty() ) { 1343 if ( !tempval.isEmpty() ) {
1344 retval += "<b>" +i18n("URL:")+ "</b> " + tempval+"<br>" ; 1344 retval += "<b>" +i18n("URL:")+ "</b> " + tempval+"<br>" ;
1345 } 1345 }
1346 tempval = QString (dti.dta[cat].d[i].launcher.c_str()); 1346 tempval = QString (dti.dta[cat].d[i].launcher.c_str());
1347 if ( !tempval.isEmpty() ) { 1347 if ( !tempval.isEmpty() ) {
1348 retval += "<b>" +i18n("Launcher:")+ "</b> " + tempval+"<br>" ; 1348 retval += "<b>" +i18n("Launcher:")+ "</b> " + tempval+"<br>" ;
1349 } 1349 }
1350 tempval = QString (dti.dta[cat].d[i].comment.c_str()); 1350 tempval = QString (dti.dta[cat].d[i].comment.c_str());
1351 if ( !tempval.isEmpty() ) { 1351 if ( !tempval.isEmpty() ) {
1352 tempval.replace(QRegExp ( "\n" ), "<br>" ); 1352 tempval.replace(QRegExp ( "\n" ), "<br>" );
1353 retval += "<b>" +i18n("Comment:")+ "</b><br>" + tempval+"<br>" ; 1353 retval += "<b>" +i18n("Comment:")+ "</b><br>" + tempval+"<br>" ;
1354 } 1354 }
1355 1355
1356 string ret ( retval.latin1() ); 1356 string ret ( retval.latin1() );
1357 1357
1358 1358
1359 // *foundComment = dti.dta[cat].d[i].comment; 1359 // *foundComment = dti.dta[cat].d[i].comment;
1360 *foundComment = ret; 1360 *foundComment = ret;
1361 return e_normalEntry; 1361 return e_normalEntry;
1362 } 1362 }
1363 } 1363 }
1364 BUG(); 1364 BUG();
1365 return e_generic; 1365 return e_generic;
1366} 1366}
1367 1367
1368bool PwMDoc::compressDta(string *d, char algo) 1368bool PwMDoc::compressDta(string *d, char algo)
1369{ 1369{
1370 PWM_ASSERT(d); 1370 PWM_ASSERT(d);
1371 switch (algo) { 1371 switch (algo) {
1372 case PWM_COMPRESS_GZIP: { 1372 case PWM_COMPRESS_GZIP: {
1373 CompressGzip comp; 1373 CompressGzip comp;
1374 return comp.compress(d); 1374 return comp.compress(d);
1375 } 1375 }
1376#ifndef PWM_EMBEDDED 1376#ifndef PWM_EMBEDDED
1377 case PWM_COMPRESS_BZIP2: { 1377 case PWM_COMPRESS_BZIP2: {
1378 CompressBzip2 comp; 1378 CompressBzip2 comp;
1379 return comp.compress(d); 1379 return comp.compress(d);
1380 } 1380 }
1381#endif 1381#endif
1382 case PWM_COMPRESS_NONE: { 1382 case PWM_COMPRESS_NONE: {
1383 return true; 1383 return true;
1384 } default: { 1384 } default: {
1385 BUG(); 1385 BUG();
1386 } 1386 }
1387 } 1387 }
1388 return false; 1388 return false;
1389} 1389}
1390 1390
1391bool PwMDoc::decompressDta(string *d, char algo) 1391bool PwMDoc::decompressDta(string *d, char algo)
1392{ 1392{
1393 PWM_ASSERT(d); 1393 PWM_ASSERT(d);
1394 switch (algo) { 1394 switch (algo) {
1395 case PWM_COMPRESS_GZIP: { 1395 case PWM_COMPRESS_GZIP: {
1396 CompressGzip comp; 1396 CompressGzip comp;
1397 return comp.decompress(d); 1397 return comp.decompress(d);
1398 } 1398 }
1399#ifndef PWM_EMBEDDED 1399#ifndef PWM_EMBEDDED
1400 case PWM_COMPRESS_BZIP2: { 1400 case PWM_COMPRESS_BZIP2: {
1401 CompressBzip2 comp; 1401 CompressBzip2 comp;
1402 return comp.decompress(d); 1402 return comp.decompress(d);
1403 } 1403 }
1404#endif 1404#endif
1405 case PWM_COMPRESS_NONE: { 1405 case PWM_COMPRESS_NONE: {
1406 return true; 1406 return true;
1407 } 1407 }
1408 } 1408 }
1409 return false; 1409 return false;
1410} 1410}
1411 1411
1412PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo, 1412PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo,
1413 char hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 1413 char hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
1414) 1414)
1415{ 1415{
1416 PWM_ASSERT(d); 1416 PWM_ASSERT(d);
1417 PWM_ASSERT(pw); 1417 PWM_ASSERT(pw);
1418 PWM_ASSERT(f); 1418 PWM_ASSERT(f);
1419 1419
1420 size_t encSize; 1420 size_t encSize;
1421 byte *encrypted = 0; 1421 byte *encrypted = 0;
1422 1422
1423 switch (algo) { 1423 switch (algo) {
1424 case PWM_CRYPT_BLOWFISH: { 1424 case PWM_CRYPT_BLOWFISH: {
1425 Blowfish::padNull(d); 1425 Blowfish::padNull(d);
1426 encSize = d->length(); 1426 encSize = d->length();
1427 encrypted = new byte[encSize]; 1427 encrypted = new byte[encSize];
1428 Blowfish bf; 1428 Blowfish bf;
1429 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { 1429 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1430 delete [] encrypted; 1430 delete [] encrypted;
1431 return e_weakPw; 1431 return e_weakPw;
1432 } 1432 }
1433 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); 1433 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1434 break; 1434 break;
1435 } 1435 }
1436 case PWM_CRYPT_AES128: 1436 case PWM_CRYPT_AES128:
1437 /*... fall through */ 1437 /*... fall through */
1438 case PWM_CRYPT_AES192: 1438 case PWM_CRYPT_AES192:
1439 case PWM_CRYPT_AES256: 1439 case PWM_CRYPT_AES256:
1440 case PWM_CRYPT_3DES: 1440 case PWM_CRYPT_3DES:
1441 case PWM_CRYPT_TWOFISH: 1441 case PWM_CRYPT_TWOFISH:
1442 case PWM_CRYPT_TWOFISH128: { 1442 case PWM_CRYPT_TWOFISH128: {
1443 if (!LibGCryptIf::available()) 1443 if (!LibGCryptIf::available())
1444 return e_cryptNotImpl; 1444 return e_cryptNotImpl;
1445 LibGCryptIf gc; 1445 LibGCryptIf gc;
1446 PwMerror err; 1446 PwMerror err;
1447 unsigned char *plain = new unsigned char[d->length() + 1024]; 1447 unsigned char *plain = new unsigned char[d->length() + 1024];
1448 memcpy(plain, d->c_str(), d->length()); 1448 memcpy(plain, d->c_str(), d->length());
1449 err = gc.encrypt(&encrypted, 1449 err = gc.encrypt(&encrypted,
1450 &encSize, 1450 &encSize,
1451 plain, 1451 plain,
1452 d->length(), 1452 d->length(),
1453 reinterpret_cast<const unsigned char *>(pw->latin1()), 1453 reinterpret_cast<const unsigned char *>(pw->latin1()),
1454 pw->length(), 1454 pw->length(),
1455 algo, 1455 algo,
1456 hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 1456 hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
1457 ); 1457 );
1458 delete [] plain; 1458 delete [] plain;
1459 if (err != e_success) 1459 if (err != e_success)
1460 return e_cryptNotImpl; 1460 return e_cryptNotImpl;
1461 break; 1461 break;
1462 } 1462 }
1463 default: { 1463 default: {
1464 delete_ifnot_null_array(encrypted); 1464 delete_ifnot_null_array(encrypted);
1465 return e_cryptNotImpl; 1465 return e_cryptNotImpl;
1466 } } 1466 } }
1467 1467
1468 // write encrypted data to file 1468 // write encrypted data to file
1469 if (f->writeBlock(reinterpret_cast<const char *>(encrypted), 1469 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1470 static_cast<Q_ULONG>(encSize)) 1470 static_cast<Q_ULONG>(encSize))
1471 != static_cast<Q_LONG>(encSize)) { 1471 != static_cast<Q_LONG>(encSize)) {
1472 delete_ifnot_null_array(encrypted); 1472 delete_ifnot_null_array(encrypted);
1473 return e_writeFile; 1473 return e_writeFile;
1474 } 1474 }
1475 delete_ifnot_null_array(encrypted); 1475 delete_ifnot_null_array(encrypted);
1476 return e_success; 1476 return e_success;
1477} 1477}
1478 1478
1479PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, 1479PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1480 char algo, 1480 char algo,
1481 char hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase 1481 char hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase
1482 QFile *f) 1482 QFile *f)
1483{ 1483{
1484 PWM_ASSERT(d); 1484 PWM_ASSERT(d);
1485 PWM_ASSERT(pw); 1485 PWM_ASSERT(pw);
1486 PWM_ASSERT(f); 1486 PWM_ASSERT(f);
1487 1487
1488 unsigned int cryptLen = f->size() - pos; 1488 unsigned int cryptLen = f->size() - pos;
1489 byte *encrypted = new byte[cryptLen]; 1489 byte *encrypted = new byte[cryptLen];
1490 byte *decrypted = new byte[cryptLen]; 1490 byte *decrypted = new byte[cryptLen];
1491 1491
1492 f->at(pos); 1492 f->at(pos);
1493#ifndef PWM_EMBEDDED 1493#ifndef PWM_EMBEDDED
1494 if (f->readBlock(reinterpret_cast<char *>(encrypted), 1494 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1495 static_cast<Q_ULONG>(cryptLen)) 1495 static_cast<Q_ULONG>(cryptLen))
1496 != static_cast<Q_LONG>(cryptLen)) { 1496 != static_cast<Q_LONG>(cryptLen)) {
1497 delete [] encrypted; 1497 delete [] encrypted;
1498 delete [] decrypted; 1498 delete [] decrypted;
1499 return e_readFile; 1499 return e_readFile;
1500 } 1500 }
1501#else 1501#else
1502 if (f->readBlock((char *)(encrypted), 1502 if (f->readBlock((char *)(encrypted),
1503 (unsigned long)(cryptLen)) 1503 (unsigned long)(cryptLen))
1504 != (long)(cryptLen)) { 1504 != (long)(cryptLen)) {
1505 delete [] encrypted; 1505 delete [] encrypted;
1506 delete [] decrypted; 1506 delete [] decrypted;
1507 return e_readFile; 1507 return e_readFile;
1508 } 1508 }
1509#endif 1509#endif
1510 switch (algo) { 1510 switch (algo) {
1511 case PWM_CRYPT_BLOWFISH: { 1511 case PWM_CRYPT_BLOWFISH: {
1512 Blowfish bf; 1512 Blowfish bf;
1513 bf.bf_setkey((byte *) pw->latin1(), pw->length()); 1513 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1514 bf.bf_decrypt(decrypted, encrypted, cryptLen); 1514 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1515 break; 1515 break;
1516 } 1516 }
1517 case PWM_CRYPT_AES128: 1517 case PWM_CRYPT_AES128:
1518 /*... fall through */ 1518 /*... fall through */
1519 case PWM_CRYPT_AES192: 1519 case PWM_CRYPT_AES192:
1520 case PWM_CRYPT_AES256: 1520 case PWM_CRYPT_AES256:
1521 case PWM_CRYPT_3DES: 1521 case PWM_CRYPT_3DES:
1522 case PWM_CRYPT_TWOFISH: 1522 case PWM_CRYPT_TWOFISH:
1523 case PWM_CRYPT_TWOFISH128: { 1523 case PWM_CRYPT_TWOFISH128: {
1524 if (!LibGCryptIf::available()) 1524 if (!LibGCryptIf::available())
1525 return e_cryptNotImpl; 1525 return e_cryptNotImpl;
1526 LibGCryptIf gc; 1526 LibGCryptIf gc;
1527 PwMerror err; 1527 PwMerror err;
1528 err = gc.decrypt(&decrypted, 1528 err = gc.decrypt(&decrypted,
1529 &cryptLen, 1529 &cryptLen,
1530 encrypted, 1530 encrypted,
1531 cryptLen, 1531 cryptLen,
1532 reinterpret_cast<const unsigned char *>(pw->latin1()), 1532 reinterpret_cast<const unsigned char *>(pw->latin1()),
1533 pw->length(), 1533 pw->length(),
1534 algo, 1534 algo,
1535 hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 1535 hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
1536); 1536);
1537 if (err != e_success) { 1537 if (err != e_success) {
1538 delete [] encrypted; 1538 delete [] encrypted;
1539 delete [] decrypted; 1539 delete [] decrypted;
1540 return e_cryptNotImpl; 1540 return e_cryptNotImpl;
1541 } 1541 }
1542 break; 1542 break;
1543 } 1543 }
1544 default: { 1544 default: {
1545 delete [] encrypted; 1545 delete [] encrypted;
1546 delete [] decrypted; 1546 delete [] decrypted;
1547 return e_cryptNotImpl; 1547 return e_cryptNotImpl;
1548 } } 1548 } }
1549 delete [] encrypted; 1549 delete [] encrypted;
1550#ifndef PWM_EMBEDDED 1550#ifndef PWM_EMBEDDED
1551 d->assign(reinterpret_cast<const char *>(decrypted), 1551 d->assign(reinterpret_cast<const char *>(decrypted),
1552 static_cast<string::size_type>(cryptLen)); 1552 static_cast<string::size_type>(cryptLen));
1553#else 1553#else
1554 d->assign((const char *)(decrypted), 1554 d->assign((const char *)(decrypted),
1555 (string::size_type)(cryptLen)); 1555 (string::size_type)(cryptLen));
1556#endif 1556#endif
1557 delete [] decrypted; 1557 delete [] decrypted;
1558 if (algo == PWM_CRYPT_BLOWFISH) { 1558 if (algo == PWM_CRYPT_BLOWFISH) {
1559 if (!Blowfish::unpadNull(d)) { 1559 if (!Blowfish::unpadNull(d)) {
1560 BUG(); 1560 BUG();
1561 return e_readFile; 1561 return e_readFile;
1562 } 1562 }
1563 } 1563 }
1564 return e_success; 1564 return e_success;
1565} 1565}
1566 1566
1567PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, 1567PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1568 const string *dataStream) 1568 const string *dataStream)
1569{ 1569{
1570 PWM_ASSERT(dataHash); 1570 PWM_ASSERT(dataHash);
1571 PWM_ASSERT(dataStream); 1571 PWM_ASSERT(dataStream);
1572 switch(dataHashType) { 1572 switch(dataHashType) {
1573 case PWM_HASH_SHA1: { 1573 case PWM_HASH_SHA1: {
1574 Sha1 hash; 1574 Sha1 hash;
1575 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); 1575 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length());
1576 string ret = hash.sha1_read(); 1576 string ret = hash.sha1_read();
1577 if (ret != *dataHash) 1577 if (ret != *dataHash)
1578 return e_fileCorrupt; 1578 return e_fileCorrupt;
1579 break; 1579 break;
1580 } 1580 }
1581 case PWM_HASH_SHA256: 1581 case PWM_HASH_SHA256:
1582 /*... fall through */ 1582 /*... fall through */
1583 case PWM_HASH_SHA384: 1583 case PWM_HASH_SHA384:
1584 case PWM_HASH_SHA512: 1584 case PWM_HASH_SHA512:
1585 case PWM_HASH_MD5: 1585 case PWM_HASH_MD5:
1586 case PWM_HASH_RMD160: 1586 case PWM_HASH_RMD160:
1587 case PWM_HASH_TIGER: { 1587 case PWM_HASH_TIGER: {
1588 if (!LibGCryptIf::available()) 1588 if (!LibGCryptIf::available())
1589 return e_hashNotImpl; 1589 return e_hashNotImpl;
1590 LibGCryptIf gc; 1590 LibGCryptIf gc;
1591 PwMerror err; 1591 PwMerror err;
1592 unsigned char *buf; 1592 unsigned char *buf;
1593 size_t hashLen; 1593 size_t hashLen;
1594 err = gc.hash(&buf, 1594 err = gc.hash(&buf,
1595 &hashLen, 1595 &hashLen,
1596 reinterpret_cast<const unsigned char *>(dataStream->c_str()), 1596 reinterpret_cast<const unsigned char *>(dataStream->c_str()),
1597 dataStream->length(), 1597 dataStream->length(),
1598 dataHashType); 1598 dataHashType);
1599 if (err != e_success) 1599 if (err != e_success)
1600 return e_hashNotImpl; 1600 return e_hashNotImpl;
1601 string calcHash(reinterpret_cast<const char *>(buf), 1601 string calcHash(reinterpret_cast<const char *>(buf),
1602 static_cast<string::size_type>(hashLen)); 1602 static_cast<string::size_type>(hashLen));
1603 delete [] buf; 1603 delete [] buf;
1604 if (calcHash != *dataHash) 1604 if (calcHash != *dataHash)
1605 return e_fileCorrupt; 1605 return e_fileCorrupt;
1606 break; 1606 break;
1607 } 1607 }
1608 default: 1608 default:
1609 return e_hashNotImpl; 1609 return e_hashNotImpl;
1610 } 1610 }
1611 return e_success; 1611 return e_success;
1612} 1612}
1613 1613
1614bool PwMDoc::lockAt(unsigned int category, unsigned int index, 1614bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1615 bool lock) 1615 bool lock)
1616{ 1616{
1617 if (index >= numEntries(category)) { 1617 if (index >= numEntries(category)) {
1618 BUG(); 1618 BUG();
1619 return false; 1619 return false;
1620 } 1620 }
1621 if (lock == dti.dta[category].d[index].lockStat) 1621 if (lock == dti.dta[category].d[index].lockStat)
1622 return true; 1622 return true;
1623 1623
1624 if (!lock && currentPw != "") { 1624 if (!lock && currentPw != "") {
1625 // "unlocking" and "password is already set" 1625 // "unlocking" and "password is already set"
1626 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1626 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1627 // unlocking without pw not allowed 1627 // unlocking without pw not allowed
1628 QString pw; 1628 QString pw;
1629 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1629 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1630 if (pw != "") { 1630 if (pw != "") {
1631 if (pw != currentPw) { 1631 if (pw != currentPw) {
1632 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1632 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1633 return false; 1633 return false;
1634 } else { 1634 } else {
1635 timer()->start(DocTimer::id_mpwTimer); 1635 timer()->start(DocTimer::id_mpwTimer);
1636 } 1636 }
1637 } else { 1637 } else {
1638 return false; 1638 return false;
1639 } 1639 }
1640 } else { 1640 } else {
1641 timer()->start(DocTimer::id_mpwTimer); 1641 timer()->start(DocTimer::id_mpwTimer);
1642 } 1642 }
1643 } 1643 }
1644 1644
1645 dti.dta[category].d[index].lockStat = lock; 1645 dti.dta[category].d[index].lockStat = lock;
1646 dti.dta[category].d[index].rev++; // increment revision counter. 1646 dti.dta[category].d[index].rev++; // increment revision counter.
1647 1647
1648 emitDataChanged(this); 1648 emitDataChanged(this);
1649 if (!lock) 1649 if (!lock)
1650 timer()->start(DocTimer::id_autoLockTimer); 1650 timer()->start(DocTimer::id_autoLockTimer);
1651 1651
1652 return true; 1652 return true;
1653 1653
1654} 1654}
1655 1655
1656bool PwMDoc::lockAt(const QString &category,unsigned int index, 1656bool PwMDoc::lockAt(const QString &category,unsigned int index,
1657 bool lock) 1657 bool lock)
1658{ 1658{
1659 unsigned int cat = 0; 1659 unsigned int cat = 0;
1660 1660
1661 if (!findCategory(category, &cat)) { 1661 if (!findCategory(category, &cat)) {
1662 BUG(); 1662 BUG();
1663 return false; 1663 return false;
1664 } 1664 }
1665 1665
1666 return lockAt(cat, index, lock); 1666 return lockAt(cat, index, lock);
1667} 1667}
1668 1668
1669bool PwMDoc::lockAll(bool lock) 1669bool PwMDoc::lockAll(bool lock)
1670{ 1670{
1671 if (!lock && isDeepLocked()) { 1671 if (!lock && isDeepLocked()) {
1672 PwMerror ret; 1672 PwMerror ret;
1673 ret = deepLock(false); 1673 ret = deepLock(false);
1674 if (ret != e_success) 1674 if (ret != e_success)
1675 return false; 1675 return false;
1676 return true; 1676 return true;
1677 } 1677 }
1678 if (isDocEmpty()) { 1678 if (isDocEmpty()) {
1679 return true; 1679 return true;
1680 } 1680 }
1681 if (!lock && currentPw != "") { 1681 if (!lock && currentPw != "") {
1682 // unlocking and password is already set 1682 // unlocking and password is already set
1683 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { 1683 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1684 // unlocking without pw not allowed 1684 // unlocking without pw not allowed
1685 QString pw; 1685 QString pw;
1686 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1686 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1687 if (pw != "") { 1687 if (pw != "") {
1688 if (pw != currentPw) { 1688 if (pw != currentPw) {
1689 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1689 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1690 return false; 1690 return false;
1691 } else { 1691 } else {
1692 timer()->start(DocTimer::id_mpwTimer); 1692 timer()->start(DocTimer::id_mpwTimer);
1693 } 1693 }
1694 } else { 1694 } else {
1695 return false; 1695 return false;
1696 } 1696 }
1697 } else { 1697 } else {
1698 timer()->start(DocTimer::id_mpwTimer); 1698 timer()->start(DocTimer::id_mpwTimer);
1699 } 1699 }
1700 } 1700 }
1701 1701
1702 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1702 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1703 catEnd = dti.dta.end(), 1703 catEnd = dti.dta.end(),
1704 catI = catBegin; 1704 catI = catBegin;
1705 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1705 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1706 while (catI != catEnd) { 1706 while (catI != catEnd) {
1707 entrBegin = catI->d.begin(); 1707 entrBegin = catI->d.begin();
1708 entrEnd = catI->d.end(); 1708 entrEnd = catI->d.end();
1709 entrI = entrBegin; 1709 entrI = entrBegin;
1710 while (entrI != entrEnd) { 1710 while (entrI != entrEnd) {
1711 entrI->lockStat = lock; 1711 entrI->lockStat = lock;
1712 entrI->rev++; // increment revision counter. 1712 entrI->rev++; // increment revision counter.
1713 ++entrI; 1713 ++entrI;
1714 } 1714 }
1715 ++catI; 1715 ++catI;
1716 } 1716 }
1717 1717
1718 emitDataChanged(this); 1718 emitDataChanged(this);
1719 if (lock) 1719 if (lock)
1720 timer()->stop(DocTimer::id_autoLockTimer); 1720 timer()->stop(DocTimer::id_autoLockTimer);
1721 else 1721 else
1722 timer()->start(DocTimer::id_autoLockTimer); 1722 timer()->start(DocTimer::id_autoLockTimer);
1723 1723
1724 return true; 1724 return true;
1725} 1725}
1726 1726
1727bool PwMDoc::isLocked(const QString &category, unsigned int index) 1727bool PwMDoc::isLocked(const QString &category, unsigned int index)
1728{ 1728{
1729 unsigned int cat = 0; 1729 unsigned int cat = 0;
1730 1730
1731 if (!findCategory(category, &cat)) { 1731 if (!findCategory(category, &cat)) {
1732 BUG(); 1732 BUG();
1733 return false; 1733 return false;
1734 } 1734 }
1735 1735
1736 return isLocked(cat, index); 1736 return isLocked(cat, index);
1737} 1737}
1738 1738
1739bool PwMDoc::unlockAll_tempoary(bool revert) 1739bool PwMDoc::unlockAll_tempoary(bool revert)
1740{ 1740{
1741 static vector< vector<bool> > *oldLockStates = 0; 1741 static vector< vector<bool> > *oldLockStates = 0;
1742 static bool wasDeepLocked; 1742 static bool wasDeepLocked;
1743 1743
1744 if (revert) {// revert the unlocking 1744 if (revert) {// revert the unlocking
1745 if (oldLockStates) { 1745 if (oldLockStates) {
1746 /* we actually _have_ unlocked something, because 1746 /* we actually _have_ unlocked something, because
1747 * we have allocated space for the oldLockStates. 1747 * we have allocated space for the oldLockStates.
1748 * So, go on and revert them! 1748 * So, go on and revert them!
1749 */ 1749 */
1750 if (wasDeepLocked) { 1750 if (wasDeepLocked) {
1751 PwMerror ret = deepLock(true); 1751 PwMerror ret = deepLock(true);
1752 if (ret == e_success) { 1752 if (ret == e_success) {
1753 /* deep-lock succeed. We are save. 1753 /* deep-lock succeed. We are save.
1754 * (but if it failed, just go on 1754 * (but if it failed, just go on
1755 * lock them normally) 1755 * lock them normally)
1756 */ 1756 */
1757 delete_and_null(oldLockStates); 1757 delete_and_null(oldLockStates);
1758 timer()->start(DocTimer::id_autoLockTimer); 1758 timer()->start(DocTimer::id_autoLockTimer);
1759 printDebug("tempoary unlocking of dta " 1759 printDebug("tempoary unlocking of dta "
1760 "reverted by deep-locking."); 1760 "reverted by deep-locking.");
1761 return true; 1761 return true;
1762 } 1762 }
1763 printDebug("deep-lock failed while reverting! " 1763 printDebug("deep-lock failed while reverting! "
1764 "Falling back to normal-lock."); 1764 "Falling back to normal-lock.");
1765 } 1765 }
1766 if (unlikely(!wasDeepLocked && 1766 if (unlikely(!wasDeepLocked &&
1767 numCategories() != oldLockStates->size())) { 1767 numCategories() != oldLockStates->size())) {
1768 /* DOH! We have modified "dta" while 1768 /* DOH! We have modified "dta" while
1769 * it was unlocked tempoary. DON'T DO THIS! 1769 * it was unlocked tempoary. DON'T DO THIS!
1770 */ 1770 */
1771 BUG(); 1771 BUG();
1772 delete_and_null(oldLockStates); 1772 delete_and_null(oldLockStates);
1773 timer()->start(DocTimer::id_autoLockTimer); 1773 timer()->start(DocTimer::id_autoLockTimer);
1774 return false; 1774 return false;
1775 } 1775 }
1776 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1776 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1777 catEnd = dti.dta.end(), 1777 catEnd = dti.dta.end(),
1778 catI = catBegin; 1778 catI = catBegin;
1779 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1779 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1780 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); 1780 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin();
1781 vector<bool>::iterator oldEntrStatBegin, 1781 vector<bool>::iterator oldEntrStatBegin,
1782 oldEntrStatEnd, 1782 oldEntrStatEnd,
1783 oldEntrStatI; 1783 oldEntrStatI;
1784 while (catI != catEnd) { 1784 while (catI != catEnd) {
1785 entrBegin = catI->d.begin(); 1785 entrBegin = catI->d.begin();
1786 entrEnd = catI->d.end(); 1786 entrEnd = catI->d.end();
1787 entrI = entrBegin; 1787 entrI = entrBegin;
1788 if (likely(!wasDeepLocked)) { 1788 if (likely(!wasDeepLocked)) {
1789 oldEntrStatBegin = oldCatStatI->begin(); 1789 oldEntrStatBegin = oldCatStatI->begin();
1790 oldEntrStatEnd = oldCatStatI->end(); 1790 oldEntrStatEnd = oldCatStatI->end();
1791 oldEntrStatI = oldEntrStatBegin; 1791 oldEntrStatI = oldEntrStatBegin;
1792 if (unlikely(catI->d.size() != oldCatStatI->size())) { 1792 if (unlikely(catI->d.size() != oldCatStatI->size())) {
1793 /* DOH! We have modified "dta" while 1793 /* DOH! We have modified "dta" while
1794 * it was unlocked tempoary. DON'T DO THIS! 1794 * it was unlocked tempoary. DON'T DO THIS!
1795 */ 1795 */
1796 BUG(); 1796 BUG();
1797 delete_and_null(oldLockStates); 1797 delete_and_null(oldLockStates);
1798 timer()->start(DocTimer::id_autoLockTimer); 1798 timer()->start(DocTimer::id_autoLockTimer);
1799 return false; 1799 return false;
1800 } 1800 }
1801 } 1801 }
1802 while (entrI != entrEnd) { 1802 while (entrI != entrEnd) {
1803 if (wasDeepLocked) { 1803 if (wasDeepLocked) {
1804 /* this is an error-fallback if 1804 /* this is an error-fallback if
1805 * deeplock didn't succeed 1805 * deeplock didn't succeed
1806 */ 1806 */
1807 entrI->lockStat = true; 1807 entrI->lockStat = true;
1808 } else { 1808 } else {
1809 entrI->lockStat = *oldEntrStatI; 1809 entrI->lockStat = *oldEntrStatI;
1810 } 1810 }
1811 ++entrI; 1811 ++entrI;
1812 if (likely(!wasDeepLocked)) 1812 if (likely(!wasDeepLocked))
1813 ++oldEntrStatI; 1813 ++oldEntrStatI;
1814 } 1814 }
1815 ++catI; 1815 ++catI;
1816 if (likely(!wasDeepLocked)) 1816 if (likely(!wasDeepLocked))
1817 ++oldCatStatI; 1817 ++oldCatStatI;
1818 } 1818 }
1819 delete_and_null(oldLockStates); 1819 delete_and_null(oldLockStates);
1820 if (unlikely(wasDeepLocked)) { 1820 if (unlikely(wasDeepLocked)) {
1821 /* error fallback... */ 1821 /* error fallback... */
1822 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1822 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1823 emitDataChanged(this); 1823 emitDataChanged(this);
1824 printDebug("WARNING: unlockAll_tempoary(true) " 1824 printDebug("WARNING: unlockAll_tempoary(true) "
1825 "deeplock fallback!"); 1825 "deeplock fallback!");
1826 } 1826 }
1827 printDebug("tempoary unlocking of dta reverted."); 1827 printDebug("tempoary unlocking of dta reverted.");
1828 } else { 1828 } else {
1829 printDebug("unlockAll_tempoary(true): nothing to do."); 1829 printDebug("unlockAll_tempoary(true): nothing to do.");
1830 } 1830 }
1831 timer()->start(DocTimer::id_autoLockTimer); 1831 timer()->start(DocTimer::id_autoLockTimer);
1832 } else {// unlock all data tempoary 1832 } else {// unlock all data tempoary
1833 if (unlikely(oldLockStates != 0)) { 1833 if (unlikely(oldLockStates != 0)) {
1834 /* DOH! We have already unlocked the data tempoarly. 1834 /* DOH! We have already unlocked the data tempoarly.
1835 * No need to do it twice. ;) 1835 * No need to do it twice. ;)
1836 */ 1836 */
1837 BUG(); 1837 BUG();
1838 return false; 1838 return false;
1839 } 1839 }
1840 wasDeepLocked = false; 1840 wasDeepLocked = false;
1841 bool mustUnlock = false; 1841 bool mustUnlock = false;
1842 if (isDeepLocked()) { 1842 if (isDeepLocked()) {
1843 PwMerror ret; 1843 PwMerror ret;
1844 while (1) { 1844 while (1) {
1845 ret = deepLock(false); 1845 ret = deepLock(false);
1846 if (ret == e_success) { 1846 if (ret == e_success) {
1847 break; 1847 break;
1848 } else if (ret == e_wrongPw) { 1848 } else if (ret == e_wrongPw) {
1849 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1849 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1850 } else { 1850 } else {
1851 printDebug("deep-unlocking failed while " 1851 printDebug("deep-unlocking failed while "
1852 "tempoary unlocking!"); 1852 "tempoary unlocking!");
1853 return false; 1853 return false;
1854 } 1854 }
1855 } 1855 }
1856 wasDeepLocked = true; 1856 wasDeepLocked = true;
1857 mustUnlock = true; 1857 mustUnlock = true;
1858 } else { 1858 } else {
1859 // first check if it's needed to unlock some entries 1859 // first check if it's needed to unlock some entries
1860 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1860 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1861 catEnd = dti.dta.end(), 1861 catEnd = dti.dta.end(),
1862 catI = catBegin; 1862 catI = catBegin;
1863 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1863 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1864 while (catI != catEnd) { 1864 while (catI != catEnd) {
1865 entrBegin = catI->d.begin(); 1865 entrBegin = catI->d.begin();
1866 entrEnd = catI->d.end(); 1866 entrEnd = catI->d.end();
1867 entrI = entrBegin; 1867 entrI = entrBegin;
1868 while (entrI != entrEnd) { 1868 while (entrI != entrEnd) {
1869 if (entrI->lockStat == true) { 1869 if (entrI->lockStat == true) {
1870 mustUnlock = true; 1870 mustUnlock = true;
1871 break; 1871 break;
1872 } 1872 }
1873 ++entrI; 1873 ++entrI;
1874 } 1874 }
1875 if (mustUnlock) 1875 if (mustUnlock)
1876 break; 1876 break;
1877 ++catI; 1877 ++catI;
1878 } 1878 }
1879 } 1879 }
1880 if (!mustUnlock) { 1880 if (!mustUnlock) {
1881 // nothing to do. 1881 // nothing to do.
1882 timer()->stop(DocTimer::id_autoLockTimer); 1882 timer()->stop(DocTimer::id_autoLockTimer);
1883 printDebug("unlockAll_tempoary(): nothing to do."); 1883 printDebug("unlockAll_tempoary(): nothing to do.");
1884 return true; 1884 return true;
1885 } else if (!wasDeepLocked) { 1885 } else if (!wasDeepLocked) {
1886 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && 1886 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) &&
1887 currentPw != "") { 1887 currentPw != "") {
1888 /* we can't unlock without mpw, so 1888 /* we can't unlock without mpw, so
1889 * we need to ask for it. 1889 * we need to ask for it.
1890 */ 1890 */
1891 QString pw; 1891 QString pw;
1892 while (1) { 1892 while (1) {
1893 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1893 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1894 if (pw == "") { 1894 if (pw == "") {
1895 return false; 1895 return false;
1896 } else if (pw == currentPw) { 1896 } else if (pw == currentPw) {
1897 break; 1897 break;
1898 } 1898 }
1899 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); 1899 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1900 } 1900 }
1901 } 1901 }
1902 } 1902 }
1903 timer()->stop(DocTimer::id_autoLockTimer); 1903 timer()->stop(DocTimer::id_autoLockTimer);
1904 oldLockStates = new vector< vector<bool> >; 1904 oldLockStates = new vector< vector<bool> >;
1905 vector<bool> tmp_vec; 1905 vector<bool> tmp_vec;
1906 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 1906 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
1907 catEnd = dti.dta.end(), 1907 catEnd = dti.dta.end(),
1908 catI = catBegin; 1908 catI = catBegin;
1909 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 1909 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1910 while (catI != catEnd) { 1910 while (catI != catEnd) {
1911 entrBegin = catI->d.begin(); 1911 entrBegin = catI->d.begin();
1912 entrEnd = catI->d.end(); 1912 entrEnd = catI->d.end();
1913 entrI = entrBegin; 1913 entrI = entrBegin;
1914 while (entrI != entrEnd) { 1914 while (entrI != entrEnd) {
1915 if (!wasDeepLocked) { 1915 if (!wasDeepLocked) {
1916 tmp_vec.push_back(entrI->lockStat); 1916 tmp_vec.push_back(entrI->lockStat);
1917 } 1917 }
1918 entrI->lockStat = false; 1918 entrI->lockStat = false;
1919 ++entrI; 1919 ++entrI;
1920 } 1920 }
1921 if (!wasDeepLocked) { 1921 if (!wasDeepLocked) {
1922 oldLockStates->push_back(tmp_vec); 1922 oldLockStates->push_back(tmp_vec);
1923 tmp_vec.clear(); 1923 tmp_vec.clear();
1924 } 1924 }
1925 ++catI; 1925 ++catI;
1926 } 1926 }
1927 printDebug("tempoary unlocked dta."); 1927 printDebug("tempoary unlocked dta.");
1928 } 1928 }
1929 1929
1930 return true; 1930 return true;
1931} 1931}
1932 1932
1933PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) 1933PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1934{ 1934{
1935 PwMerror ret; 1935 PwMerror ret;
1936 /* NOTE: saveDoc() depends on this function to return 1936 /* NOTE: saveDoc() depends on this function to return
1937 * e_success if saveToFile == false 1937 * e_success if saveToFile == false
1938 */ 1938 */
1939 1939
1940 if (lock) { 1940 if (lock) {
1941 if (isDeepLocked()) 1941 if (isDeepLocked())
1942 return e_lock; 1942 return e_lock;
1943 if (saveToFile) { 1943 if (saveToFile) {
1944 if (isDocEmpty()) 1944 if (isDocEmpty())
1945 return e_docIsEmpty; 1945 return e_docIsEmpty;
1946 ret = saveDoc(conf()->confGlobCompression()); 1946 ret = saveDoc(conf()->confGlobCompression());
1947 if (ret == e_filename) { 1947 if (ret == e_filename) {
1948 /* the doc wasn't saved to a file 1948 /* the doc wasn't saved to a file
1949 * by the user, yet. 1949 * by the user, yet.
1950 */ 1950 */
1951 cantDeeplock_notSavedMsgBox(); 1951 cantDeeplock_notSavedMsgBox();
1952 return e_docNotSaved; 1952 return e_docNotSaved;
1953 } else if (ret != e_success) { 1953 } else if (ret != e_success) {
1954 return e_lock; 1954 return e_lock;
1955 } 1955 }
1956 } 1956 }
1957 timer()->stop(DocTimer::id_autoLockTimer); 1957 timer()->stop(DocTimer::id_autoLockTimer);
1958 clearDoc(); 1958 clearDoc();
1959 PwMDataItem d; 1959 PwMDataItem d;
1960 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); 1960 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1();
1961 d.comment = IS_DEEPLOCKED_MSG.latin1(); 1961 d.comment = IS_DEEPLOCKED_MSG.latin1();
1962 d.listViewPos = 0; 1962 d.listViewPos = 0;
1963 addEntry(DEFAULT_CATEGORY, &d, true); 1963 addEntry(DEFAULT_CATEGORY, &d, true);
1964 lockAt(DEFAULT_CATEGORY, 0, true); 1964 lockAt(DEFAULT_CATEGORY, 0, true);
1965 unsetDocStatFlag(DOC_STAT_DISK_DIRTY); 1965 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
1966 setDocStatFlag(DOC_STAT_DEEPLOCKED); 1966 setDocStatFlag(DOC_STAT_DEEPLOCKED);
1967 } else { 1967 } else {
1968 if (!isDeepLocked()) 1968 if (!isDeepLocked())
1969 return e_lock; 1969 return e_lock;
1970 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) 1970 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen())
1971 ? 0 : 1); 1971 ? 0 : 1);
1972 if (ret == e_wrongPw) { 1972 if (ret == e_wrongPw) {
1973 return e_wrongPw; 1973 return e_wrongPw;
1974 } else if (ret != e_success) { 1974 } else if (ret != e_success) {
1975 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") 1975 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ")
1976 + tostr(static_cast<int>(ret))); 1976 + tostr(static_cast<int>(ret)));
1977 return e_lock; 1977 return e_lock;
1978 } 1978 }
1979 unsetDocStatFlag(DOC_STAT_DEEPLOCKED); 1979 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1980 timer()->start(DocTimer::id_autoLockTimer); 1980 timer()->start(DocTimer::id_autoLockTimer);
1981 } 1981 }
1982 1982
1983 emitDataChanged(this); 1983 emitDataChanged(this);
1984 return e_success; 1984 return e_success;
1985} 1985}
1986 1986
1987void PwMDoc::_deepUnlock() 1987void PwMDoc::_deepUnlock()
1988{ 1988{
1989 deepLock(false); 1989 deepLock(false);
1990} 1990}
1991 1991
1992void PwMDoc::clearDoc() 1992void PwMDoc::clearDoc()
1993{ 1993{
1994 dti.clear(); 1994 dti.clear();
1995 PwMCategoryItem d; 1995 PwMCategoryItem d;
1996 //US ENH: to initialize all members with meaningfull data. 1996 //US ENH: to initialize all members with meaningfull data.
1997 d.clear(); 1997 d.clear();
1998 d.name = DEFAULT_CATEGORY.latin1(); 1998 d.name = DEFAULT_CATEGORY.latin1();
1999 dti.dta.push_back(d); 1999 dti.dta.push_back(d);
2000 currentPw = ""; 2000 currentPw = "";
2001 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 2001 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
2002} 2002}
2003 2003
2004void PwMDoc::changeCurrentPw() 2004void PwMDoc::changeCurrentPw()
2005{ 2005{
2006 if (currentPw == "") 2006 if (currentPw == "")
2007 return; // doc hasn't been saved. No mpw available. 2007 return; // doc hasn't been saved. No mpw available.
2008 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); 2008 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
2009 QString pw = requestMpwChange(&currentPw, &useChipcard); 2009 QString pw = requestMpwChange(&currentPw, &useChipcard);
2010 if (pw == "") 2010 if (pw == "")
2011 return; 2011 return;
2012 if (useChipcard) 2012 if (useChipcard)
2013 setDocStatFlag(DOC_STAT_USE_CHIPCARD); 2013 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
2014 else 2014 else
2015 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); 2015 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
2016 setCurrentPw(pw); 2016 setCurrentPw(pw);
2017} 2017}
2018 2018
2019void PwMDoc::setListViewPos(const QString &category, unsigned int index, 2019void PwMDoc::setListViewPos(const QString &category, unsigned int index,
2020 int pos) 2020 int pos)
2021{ 2021{
2022 unsigned int cat = 0; 2022 unsigned int cat = 0;
2023 2023
2024 if (!findCategory(category, &cat)) { 2024 if (!findCategory(category, &cat)) {
2025 BUG(); 2025 BUG();
2026 return; 2026 return;
2027 } 2027 }
2028 setListViewPos(cat, index, pos); 2028 setListViewPos(cat, index, pos);
2029} 2029}
2030 2030
2031void PwMDoc::setListViewPos(unsigned int category, unsigned int index, 2031void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
2032 int pos) 2032 int pos)
2033{ 2033{
2034 dti.dta[category].d[index].listViewPos = pos; 2034 dti.dta[category].d[index].listViewPos = pos;
2035 2035
2036/* FIXME workaround: don't flag dirty, because this function sometimes 2036/* FIXME workaround: don't flag dirty, because this function sometimes
2037 * get's called when it shouldn't. It's because PwMView assumes 2037 * get's called when it shouldn't. It's because PwMView assumes
2038 * the user resorted the UI on behalf of signal layoutChanged(). 2038 * the user resorted the UI on behalf of signal layoutChanged().
2039 * This is somewhat broken and incorrect, but I've no other 2039 * This is somewhat broken and incorrect, but I've no other
2040 * solution for now. 2040 * solution for now.
2041 */ 2041 */
2042 //setDocStatFlag(DOC_STAT_DISK_DIRTY); 2042 //setDocStatFlag(DOC_STAT_DISK_DIRTY);
2043} 2043}
2044 2044
2045int PwMDoc::getListViewPos(const QString &category, unsigned int index) 2045int PwMDoc::getListViewPos(const QString &category, unsigned int index)
2046{ 2046{
2047 unsigned int cat = 0; 2047 unsigned int cat = 0;
2048 2048
2049 if (!findCategory(category, &cat)) { 2049 if (!findCategory(category, &cat)) {
2050 BUG(); 2050 BUG();
2051 return -1; 2051 return -1;
2052 } 2052 }
2053 2053
2054 return dti.dta[cat].d[index].listViewPos; 2054 return dti.dta[cat].d[index].listViewPos;
2055} 2055}
2056 2056
2057void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 2057void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
2058 vector<unsigned int> *foundPositions, bool breakAfterFound, 2058 vector<unsigned int> *foundPositions, bool breakAfterFound,
2059 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 2059 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
2060{ 2060{
2061 PWM_ASSERT(foundPositions); 2061 PWM_ASSERT(foundPositions);
2062 PWM_ASSERT(searchIn); 2062 PWM_ASSERT(searchIn);
2063 foundPositions->clear(); 2063 foundPositions->clear();
2064 2064
2065 unsigned int i, entries = numEntries(category); 2065 unsigned int i, entries = numEntries(category);
2066 for (i = 0; i < entries; ++i) { 2066 for (i = 0; i < entries; ++i) {
2067 if (searchIn & SEARCH_IN_DESC) { 2067 if (searchIn & SEARCH_IN_DESC) {
2068 if (!compareString(find.desc, dti.dta[category].d[i].desc, 2068 if (!compareString(find.desc, dti.dta[category].d[i].desc,
2069 caseSensitive, exactWordMatch)) { 2069 caseSensitive, exactWordMatch)) {
2070 continue; 2070 continue;
2071 } 2071 }
2072 } 2072 }
2073 if (searchIn & SEARCH_IN_NAME) { 2073 if (searchIn & SEARCH_IN_NAME) {
2074 if (!compareString(find.name, dti.dta[category].d[i].name, 2074 if (!compareString(find.name, dti.dta[category].d[i].name,
2075 caseSensitive, exactWordMatch)) { 2075 caseSensitive, exactWordMatch)) {
2076 continue; 2076 continue;
2077 } 2077 }
2078 } 2078 }
2079 if (searchIn & SEARCH_IN_PW) { 2079 if (searchIn & SEARCH_IN_PW) {
2080 bool wasLocked = isLocked(category, i); 2080 bool wasLocked = isLocked(category, i);
2081 getDataChangedLock(); 2081 getDataChangedLock();
2082 lockAt(category, i, false); 2082 lockAt(category, i, false);
2083 if (!compareString(find.pw, dti.dta[category].d[i].pw, 2083 if (!compareString(find.pw, dti.dta[category].d[i].pw,
2084 caseSensitive, exactWordMatch)) { 2084 caseSensitive, exactWordMatch)) {
2085 lockAt(category, i, wasLocked); 2085 lockAt(category, i, wasLocked);
2086 putDataChangedLock(); 2086 putDataChangedLock();
2087 continue; 2087 continue;
2088 } 2088 }
2089 lockAt(category, i, wasLocked); 2089 lockAt(category, i, wasLocked);
2090 putDataChangedLock(); 2090 putDataChangedLock();
2091 } 2091 }
2092 if (searchIn & SEARCH_IN_COMMENT) { 2092 if (searchIn & SEARCH_IN_COMMENT) {
2093 if (!compareString(find.comment, dti.dta[category].d[i].comment, 2093 if (!compareString(find.comment, dti.dta[category].d[i].comment,
2094 caseSensitive, exactWordMatch)) { 2094 caseSensitive, exactWordMatch)) {
2095 continue; 2095 continue;
2096 } 2096 }
2097 } 2097 }
2098 if (searchIn & SEARCH_IN_URL) { 2098 if (searchIn & SEARCH_IN_URL) {
2099 if (!compareString(find.url, dti.dta[category].d[i].url, 2099 if (!compareString(find.url, dti.dta[category].d[i].url,
2100 caseSensitive, exactWordMatch)) { 2100 caseSensitive, exactWordMatch)) {
2101 continue; 2101 continue;
2102 } 2102 }
2103 } 2103 }
2104 if (searchIn & SEARCH_IN_LAUNCHER) { 2104 if (searchIn & SEARCH_IN_LAUNCHER) {
2105 if (!compareString(find.launcher, dti.dta[category].d[i].launcher, 2105 if (!compareString(find.launcher, dti.dta[category].d[i].launcher,
2106 caseSensitive, exactWordMatch)) { 2106 caseSensitive, exactWordMatch)) {
2107 continue; 2107 continue;
2108 } 2108 }
2109 } 2109 }
2110 2110
2111 // all selected "searchIn" matched. 2111 // all selected "searchIn" matched.
2112 foundPositions->push_back(i); 2112 foundPositions->push_back(i);
2113 if (breakAfterFound) 2113 if (breakAfterFound)
2114 break; 2114 break;
2115 } 2115 }
2116 2116
2117 if (sortByLvp && foundPositions->size() > 1) { 2117 if (sortByLvp && foundPositions->size() > 1) {
2118 vector< pair<unsigned int /* foundPosition (real doc pos) */, 2118 vector< pair<unsigned int /* foundPosition (real doc pos) */,
2119 unsigned int /* lvp-pos */> > tmp_vec; 2119 unsigned int /* lvp-pos */> > tmp_vec;
2120 2120
2121 unsigned int i, items = foundPositions->size(); 2121 unsigned int i, items = foundPositions->size();
2122 pair<unsigned int, unsigned int> tmp_pair; 2122 pair<unsigned int, unsigned int> tmp_pair;
2123 for (i = 0; i < items; ++i) { 2123 for (i = 0; i < items; ++i) {
2124 tmp_pair.first = (*foundPositions)[i]; 2124 tmp_pair.first = (*foundPositions)[i];
2125 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; 2125 tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos;
2126 tmp_vec.push_back(tmp_pair); 2126 tmp_vec.push_back(tmp_pair);
2127 } 2127 }
2128 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); 2128 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater());
2129 foundPositions->clear(); 2129 foundPositions->clear();
2130 for (i = 0; i < items; ++i) { 2130 for (i = 0; i < items; ++i) {
2131 foundPositions->push_back(tmp_vec[i].first); 2131 foundPositions->push_back(tmp_vec[i].first);
2132 } 2132 }
2133 } 2133 }
2134} 2134}
2135 2135
2136void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 2136void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
2137 vector<unsigned int> *foundPositions, bool breakAfterFound, 2137 vector<unsigned int> *foundPositions, bool breakAfterFound,
2138 bool caseSensitive, bool exactWordMatch, bool sortByLvp) 2138 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
2139{ 2139{
2140 PWM_ASSERT(foundPositions); 2140 PWM_ASSERT(foundPositions);
2141 unsigned int cat = 0; 2141 unsigned int cat = 0;
2142 2142
2143 if (!findCategory(category, &cat)) { 2143 if (!findCategory(category, &cat)) {
2144 foundPositions->clear(); 2144 foundPositions->clear();
2145 return; 2145 return;
2146 } 2146 }
2147 2147
2148 findEntry(cat, find, searchIn, foundPositions, breakAfterFound, 2148 findEntry(cat, find, searchIn, foundPositions, breakAfterFound,
2149 caseSensitive, exactWordMatch, sortByLvp); 2149 caseSensitive, exactWordMatch, sortByLvp);
2150} 2150}
2151 2151
2152bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, 2152bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive,
2153 bool exactWordMatch) 2153 bool exactWordMatch)
2154{ 2154{
2155 QString _s1(s1.c_str()); 2155 QString _s1(s1.c_str());
2156 QString _s2(s2.c_str()); 2156 QString _s2(s2.c_str());
2157 if (!caseSensitive) { 2157 if (!caseSensitive) {
2158 _s1 = _s1.lower(); 2158 _s1 = _s1.lower();
2159 _s2 = _s2.lower(); 2159 _s2 = _s2.lower();
2160 } 2160 }
2161 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) 2161 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1))
2162 return true; 2162 return true;
2163 return false; 2163 return false;
2164} 2164}
2165 2165
2166bool PwMDoc::findCategory(const QString &name, unsigned int *index) 2166bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2167{ 2167{
2168 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2168 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2169 end = dti.dta.end(); 2169 end = dti.dta.end();
2170 while (i != end) { 2170 while (i != end) {
2171 if ((*i).name == name.latin1()) { 2171 if ((*i).name == name.latin1()) {
2172 if (index) { 2172 if (index) {
2173 *index = i - dti.dta.begin(); 2173 *index = i - dti.dta.begin();
2174 } 2174 }
2175 return true; 2175 return true;
2176 } 2176 }
2177 ++i; 2177 ++i;
2178 } 2178 }
2179 return false; 2179 return false;
2180} 2180}
2181 2181
2182bool PwMDoc::renameCategory(const QString &category, const QString &newName) 2182bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2183{ 2183{
2184 unsigned int cat = 0; 2184 unsigned int cat = 0;
2185 2185
2186 if (!findCategory(category, &cat)) 2186 if (!findCategory(category, &cat))
2187 return false; 2187 return false;
2188 2188
2189 return renameCategory(cat, newName); 2189 return renameCategory(cat, newName);
2190} 2190}
2191 2191
2192bool PwMDoc::renameCategory(unsigned int category, const QString &newName, 2192bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2193 bool dontFlagDirty) 2193 bool dontFlagDirty)
2194{ 2194{
2195 if (category > numCategories() - 1) 2195 if (category > numCategories() - 1)
2196 return false; 2196 return false;
2197 2197
2198 dti.dta[category].name = newName.latin1(); 2198 dti.dta[category].name = newName.latin1();
2199 if (!dontFlagDirty) 2199 if (!dontFlagDirty)
2200 flagDirty(); 2200 flagDirty();
2201 2201
2202 return true; 2202 return true;
2203} 2203}
2204 2204
2205bool PwMDoc::delCategory(const QString &category) 2205bool PwMDoc::delCategory(const QString &category)
2206{ 2206{
2207 unsigned int cat = 0; 2207 unsigned int cat = 0;
2208 2208
2209 if (!findCategory(category, &cat)) 2209 if (!findCategory(category, &cat))
2210 return false; 2210 return false;
2211 2211
2212 return delCategory(cat); 2212 return delCategory(cat);
2213} 2213}
2214 2214
2215bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) 2215bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2216{ 2216{
2217 if (category > numCategories() - 1) 2217 if (category > numCategories() - 1)
2218 return false; 2218 return false;
2219 2219
2220 // We don't delete it, if it is the last existing 2220 // We don't delete it, if it is the last existing
2221 // category! Instead we rename it to "Default". 2221 // category! Instead we rename it to "Default".
2222 if (numCategories() > 1) { 2222 if (numCategories() > 1) {
2223 dti.dta.erase(dti.dta.begin() + category); 2223 dti.dta.erase(dti.dta.begin() + category);
2224 } else { 2224 } else {
2225 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); 2225 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2226 return true; 2226 return true;
2227 } 2227 }
2228 if (!dontFlagDirty) 2228 if (!dontFlagDirty)
2229 flagDirty(); 2229 flagDirty();
2230 2230
2231 return true; 2231 return true;
2232} 2232}
2233 2233
2234void PwMDoc::delAllEmptyCat(bool dontFlagDirty) 2234void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2235{ 2235{
2236 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), 2236 vector<PwMCategoryItem>::iterator begin = dti.dta.begin(),
2237 end = dti.dta.end(), 2237 end = dti.dta.end(),
2238 i = begin; 2238 i = begin;
2239 while (i != end) { 2239 while (i != end) {
2240 if (i->d.empty()) { 2240 if (i->d.empty()) {
2241 delCategory(begin - i, dontFlagDirty); 2241 delCategory(begin - i, dontFlagDirty);
2242 } 2242 }
2243 ++i; 2243 ++i;
2244 } 2244 }
2245} 2245}
2246 2246
2247void PwMDoc::getCategoryList(vector<string> *list) 2247void PwMDoc::getCategoryList(vector<string> *list)
2248{ 2248{
2249 PWM_ASSERT(list); 2249 PWM_ASSERT(list);
2250 list->clear(); 2250 list->clear();
2251 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2251 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2252 end = dti.dta.end(); 2252 end = dti.dta.end();
2253 while (i != end) { 2253 while (i != end) {
2254 list->push_back(i->name); 2254 list->push_back(i->name);
2255 ++i; 2255 ++i;
2256 } 2256 }
2257} 2257}
2258 2258
2259void PwMDoc::getCategoryList(QStringList *list) 2259void PwMDoc::getCategoryList(QStringList *list)
2260{ 2260{
2261 PWM_ASSERT(list); 2261 PWM_ASSERT(list);
2262 list->clear(); 2262 list->clear();
2263 vector<PwMCategoryItem>::iterator i = dti.dta.begin(), 2263 vector<PwMCategoryItem>::iterator i = dti.dta.begin(),
2264 end = dti.dta.end(); 2264 end = dti.dta.end();
2265 while (i != end) { 2265 while (i != end) {
2266#ifndef PWM_EMBEDDED 2266#ifndef PWM_EMBEDDED
2267 list->push_back(i->name.c_str()); 2267 list->push_back(i->name.c_str());
2268#else 2268#else
2269 list->append(i->name.c_str()); 2269 list->append(i->name.c_str());
2270#endif 2270#endif
2271 ++i; 2271 ++i;
2272 } 2272 }
2273} 2273}
2274 2274
2275void PwMDoc::getEntryList(const QString &category, QStringList *list) 2275void PwMDoc::getEntryList(const QString &category, QStringList *list)
2276{ 2276{
2277 PWM_ASSERT(list); 2277 PWM_ASSERT(list);
2278 unsigned int cat = 0; 2278 unsigned int cat = 0;
2279 if (!findCategory(category, &cat)) { 2279 if (!findCategory(category, &cat)) {
2280 list->clear(); 2280 list->clear();
2281 return; 2281 return;
2282 } 2282 }
2283 getEntryList(cat, list); 2283 getEntryList(cat, list);
2284} 2284}
2285 2285
2286void PwMDoc::getEntryList(const QString &category, vector<string> *list) 2286void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2287{ 2287{
2288 PWM_ASSERT(list); 2288 PWM_ASSERT(list);
2289 unsigned int cat = 0; 2289 unsigned int cat = 0;
2290 if (!findCategory(category, &cat)) { 2290 if (!findCategory(category, &cat)) {
2291 list->clear(); 2291 list->clear();
2292 return; 2292 return;
2293 } 2293 }
2294 getEntryList(cat, list); 2294 getEntryList(cat, list);
2295} 2295}
2296 2296
2297void PwMDoc::getEntryList(unsigned int category, vector<string> *list) 2297void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2298{ 2298{
2299 PWM_ASSERT(list); 2299 PWM_ASSERT(list);
2300 list->clear(); 2300 list->clear();
2301 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2301 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2302 end = dti.dta[category].d.end(), 2302 end = dti.dta[category].d.end(),
2303 i = begin; 2303 i = begin;
2304 while (i != end) { 2304 while (i != end) {
2305 list->push_back(i->desc); 2305 list->push_back(i->desc);
2306 ++i; 2306 ++i;
2307 } 2307 }
2308} 2308}
2309 2309
2310void PwMDoc::getEntryList(unsigned int category, QStringList *list) 2310void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2311{ 2311{
2312 PWM_ASSERT(list); 2312 PWM_ASSERT(list);
2313 list->clear(); 2313 list->clear();
2314 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), 2314 vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(),
2315 end = dti.dta[category].d.end(), 2315 end = dti.dta[category].d.end(),
2316 i = begin; 2316 i = begin;
2317 while (i != end) { 2317 while (i != end) {
2318#ifndef PWM_EMBEDDED 2318#ifndef PWM_EMBEDDED
2319 list->push_back(i->desc.c_str()); 2319 list->push_back(i->desc.c_str());
2320#else 2320#else
2321 list->append(i->desc.c_str()); 2321 list->append(i->desc.c_str());
2322#endif 2322#endif
2323 ++i; 2323 ++i;
2324 } 2324 }
2325} 2325}
2326 2326
2327bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) 2327bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2328{ 2328{
2329 unsigned int cat = 0; 2329 unsigned int cat = 0;
2330 2330
2331 if (!findCategory(category, &cat)) 2331 if (!findCategory(category, &cat))
2332 return false; 2332 return false;
2333 2333
2334 return execLauncher(cat, entryIndex); 2334 return execLauncher(cat, entryIndex);
2335} 2335}
2336 2336
2337bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) 2337bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2338{ 2338{
2339#ifndef _WIN32_ 2339#ifndef _WIN32_
2340 if (geteuid() == 0) { 2340 if (geteuid() == 0) {
2341 rootAlertMsgBox(); 2341 rootAlertMsgBox();
2342 return false; 2342 return false;
2343 } 2343 }
2344#endif 2344#endif
2345 QString command(dti.dta[category].d[entryIndex].launcher.c_str()); 2345 QString command(dti.dta[category].d[entryIndex].launcher.c_str());
2346 bool wasLocked = isLocked(category, entryIndex); 2346 bool wasLocked = isLocked(category, entryIndex);
2347 2347
2348 if (command.find("$p") != -1) { 2348 if (command.find("$p") != -1) {
2349 /* the user requested the password to be included 2349 /* the user requested the password to be included
2350 * into the command. We have to ask for the password, 2350 * into the command. We have to ask for the password,
2351 * if it's locked. We do that by unlocking the entry 2351 * if it's locked. We do that by unlocking the entry
2352 */ 2352 */
2353 if (!lockAt(category, entryIndex, false)) 2353 if (!lockAt(category, entryIndex, false))
2354 return false; 2354 return false;
2355 } 2355 }
2356#ifndef PWM_EMBEDDED 2356#ifndef PWM_EMBEDDED
2357 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); 2357 command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str());
2358 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); 2358 command.replace("$n", dti.dta[category].d[entryIndex].name.c_str());
2359 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); 2359 command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str());
2360 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); 2360 command.replace("$u", dti.dta[category].d[entryIndex].url.c_str());
2361 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); 2361 command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str());
2362#else 2362#else
2363 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); 2363 command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str());
2364 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); 2364 command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str());
2365 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); 2365 command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str());
2366 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); 2366 command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str());
2367 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); 2367 command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str());
2368#endif 2368#endif
2369 command.append(" &"); 2369 command.append(" &");
2370 2370
2371 QString customXterm(conf()->confGlobXtermCommand()); 2371 QString customXterm(conf()->confGlobXtermCommand());
2372 if (!customXterm.isEmpty()) 2372 if (!customXterm.isEmpty())
2373 command = customXterm + " " + command; 2373 command = customXterm + " " + command;
2374 2374
2375 system(command.latin1()); 2375 system(command.latin1());
2376 2376
2377 lockAt(category, entryIndex, wasLocked); 2377 lockAt(category, entryIndex, wasLocked);
2378 return true; 2378 return true;
2379} 2379}
2380 2380
2381bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) 2381bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2382{ 2382{
2383 unsigned int cat = 0; 2383 unsigned int cat = 0;
2384 2384
2385 if (!findCategory(category, &cat)) 2385 if (!findCategory(category, &cat))
2386 return false; 2386 return false;
2387 2387
2388 return goToURL(cat, entryIndex); 2388 return goToURL(cat, entryIndex);
2389} 2389}
2390 2390
2391bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) 2391bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2392{ 2392{
2393#ifndef _WIN32_ 2393#ifndef _WIN32_
2394 if (geteuid() == 0) { 2394 if (geteuid() == 0) {
2395 rootAlertMsgBox(); 2395 rootAlertMsgBox();
2396 return false; 2396 return false;
2397 } 2397 }
2398#endif 2398#endif
2399 QString url(dti.dta[category].d[entryIndex].url.c_str()); 2399 QString url(dti.dta[category].d[entryIndex].url.c_str());
2400 if (url.isEmpty()) 2400 if (url.isEmpty())
2401 return false; 2401 return false;
2402 2402
2403 QString customBrowser(conf()->confGlobBrowserCommand()); 2403 QString customBrowser(conf()->confGlobBrowserCommand());
2404 if (!customBrowser.isEmpty()) { 2404 if (!customBrowser.isEmpty()) {
2405 browserProc.clearArguments(); 2405 browserProc.clearArguments();
2406 browserProc << customBrowser << url; 2406 browserProc << customBrowser << url;
2407 if (browserProc.start(KProcess::DontCare)) 2407 if (browserProc.start(KProcess::DontCare))
2408 return true; 2408 return true;
2409 } 2409 }
2410 2410
2411 browserProc.clearArguments(); 2411 browserProc.clearArguments();
2412 browserProc << "konqueror" << url; 2412 browserProc << "konqueror" << url;
2413 if (browserProc.start(KProcess::DontCare)) 2413 if (browserProc.start(KProcess::DontCare))
2414 return true; 2414 return true;
2415 2415
2416 browserProc.clearArguments(); 2416 browserProc.clearArguments();
2417 browserProc << "mozilla" << url; 2417 browserProc << "mozilla" << url;
2418 if (browserProc.start(KProcess::DontCare)) 2418 if (browserProc.start(KProcess::DontCare))
2419 return true; 2419 return true;
2420 2420
2421 browserProc.clearArguments(); 2421 browserProc.clearArguments();
2422 browserProc << "opera" << url; 2422 browserProc << "opera" << url;
2423 if (browserProc.start(KProcess::DontCare)) 2423 if (browserProc.start(KProcess::DontCare))
2424 return true; 2424 return true;
2425 return false; 2425 return false;
2426} 2426}
2427 2427
2428PwMerror PwMDoc::exportToText(const QString *file) 2428PwMerror PwMDoc::exportToText(const QString *file)
2429{ 2429{
2430 PWM_ASSERT(file); 2430 PWM_ASSERT(file);
2431 if (QFile::exists(*file)) { 2431 if (QFile::exists(*file)) {
2432 if (!QFile::remove(*file)) 2432 if (!QFile::remove(*file))
2433 return e_accessFile; 2433 return e_accessFile;
2434 } 2434 }
2435 QFile f(*file); 2435 QFile f(*file);
2436 if (!f.open(IO_ReadWrite)) 2436 if (!f.open(IO_ReadWrite))
2437 return e_openFile; 2437 return e_openFile;
2438 2438
2439 if (!unlockAll_tempoary()) { 2439 if (!unlockAll_tempoary()) {
2440 f.close(); 2440 f.close();
2441 return e_lock; 2441 return e_lock;
2442 } 2442 }
2443 2443
2444 // write header 2444 // write header
2445 string header = i18n("Password table generated by\nPwM v").latin1(); 2445 string header = i18n("Password table generated by\nPwM v").latin1();
2446 header += PACKAGE_VER; 2446 header += PACKAGE_VER;
2447 header += i18n("\non ").latin1(); 2447 header += i18n("\non ").latin1();
2448 QDate currDate = QDate::currentDate(); 2448 QDate currDate = QDate::currentDate();
2449 QTime currTime = QTime::currentTime(); 2449 QTime currTime = QTime::currentTime();
2450 2450
2451#ifndef PWM_EMBEDDED 2451#ifndef PWM_EMBEDDED
2452 header += currDate.toString("ddd MMMM d ").latin1(); 2452 header += currDate.toString("ddd MMMM d ").latin1();
2453 header += currTime.toString("hh:mm:ss ").latin1(); 2453 header += currTime.toString("hh:mm:ss ").latin1();
2454#else 2454#else
2455 QString dfs = KGlobal::locale()->dateFormatShort(); 2455 QString dfs = KGlobal::locale()->dateFormatShort();
2456 bool ampm = KGlobal::locale()->use12Clock(); 2456 bool ampm = KGlobal::locale()->use12Clock();
2457 KGlobal::locale()->setDateFormatShort("%A %B %d"); 2457 KGlobal::locale()->setDateFormatShort("%A %B %d");
2458 KGlobal::locale()->setHore24Format(true); 2458 KGlobal::locale()->setHore24Format(true);
2459 2459
2460 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1(); 2460 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined).latin1();
2461 header += KGlobal::locale()->formatTime(currTime, true).latin1(); 2461 header += KGlobal::locale()->formatTime(currTime, true).latin1();
2462 KGlobal::locale()->setDateFormatShort(dfs); 2462 KGlobal::locale()->setDateFormatShort(dfs);
2463 KGlobal::locale()->setHore24Format(!ampm); 2463 KGlobal::locale()->setHore24Format(!ampm);
2464 2464
2465#endif 2465#endif
2466 header += tostr(currDate.year()); 2466 header += tostr(currDate.year());
2467 header += "\n==============================\n\n"; 2467 header += "\n==============================\n\n";
2468 2468
2469 2469
2470#ifndef PWM_EMBEDDED 2470#ifndef PWM_EMBEDDED
2471 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { 2471 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2472 unlockAll_tempoary(true); 2472 unlockAll_tempoary(true);
2473 f.close(); 2473 f.close();
2474 return e_writeFile; 2474 return e_writeFile;
2475 } 2475 }
2476#else 2476#else
2477 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { 2477 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2478 unlockAll_tempoary(true); 2478 unlockAll_tempoary(true);
2479 f.close(); 2479 f.close();
2480 return e_writeFile; 2480 return e_writeFile;
2481 } 2481 }
2482#endif 2482#endif
2483 unsigned int i, numCat = numCategories(); 2483 unsigned int i, numCat = numCategories();
2484 unsigned int j, numEnt; 2484 unsigned int j, numEnt;
2485 string exp; 2485 string exp;
2486 for (i = 0; i < numCat; ++i) { 2486 for (i = 0; i < numCat; ++i) {
2487 numEnt = numEntries(i); 2487 numEnt = numEntries(i);
2488 2488
2489 exp = "\n== Category: "; 2489 exp = "\n== Category: ";
2490 exp += dti.dta[i].name; 2490 exp += dti.dta[i].name;
2491 exp += " ==\n"; 2491 exp += " ==\n";
2492#ifndef PWM_EMBEDDED 2492#ifndef PWM_EMBEDDED
2493 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2493 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2494 unlockAll_tempoary(true); 2494 unlockAll_tempoary(true);
2495 f.close(); 2495 f.close();
2496 return e_writeFile; 2496 return e_writeFile;
2497 } 2497 }
2498#else 2498#else
2499 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2499 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2500 unlockAll_tempoary(true); 2500 unlockAll_tempoary(true);
2501 f.close(); 2501 f.close();
2502 return e_writeFile; 2502 return e_writeFile;
2503 } 2503 }
2504#endif 2504#endif
2505 for (j = 0; j < numEnt; ++j) { 2505 for (j = 0; j < numEnt; ++j) {
2506 exp = "\n-- "; 2506 exp = "\n-- ";
2507 exp += dti.dta[i].d[j].desc; 2507 exp += dti.dta[i].d[j].desc;
2508 exp += " --\n"; 2508 exp += " --\n";
2509 2509
2510 exp += i18n("Username: ").latin1(); 2510 exp += i18n("Username: ").latin1();
2511 exp += dti.dta[i].d[j].name; 2511 exp += dti.dta[i].d[j].name;
2512 exp += "\n"; 2512 exp += "\n";
2513 2513
2514 exp += i18n("Password: ").latin1(); 2514 exp += i18n("Password: ").latin1();
2515 exp += dti.dta[i].d[j].pw; 2515 exp += dti.dta[i].d[j].pw;
2516 exp += "\n"; 2516 exp += "\n";
2517 2517
2518 exp += i18n("Comment: ").latin1(); 2518 exp += i18n("Comment: ").latin1();
2519 exp += dti.dta[i].d[j].comment; 2519 exp += dti.dta[i].d[j].comment;
2520 exp += "\n"; 2520 exp += "\n";
2521 2521
2522 exp += i18n("URL: ").latin1(); 2522 exp += i18n("URL: ").latin1();
2523 exp += dti.dta[i].d[j].url; 2523 exp += dti.dta[i].d[j].url;
2524 exp += "\n"; 2524 exp += "\n";
2525 2525
2526 exp += i18n("Launcher: ").latin1(); 2526 exp += i18n("Launcher: ").latin1();
2527 exp += dti.dta[i].d[j].launcher; 2527 exp += dti.dta[i].d[j].launcher;
2528 exp += "\n"; 2528 exp += "\n";
2529 2529
2530#ifndef PWM_EMBEDDED 2530#ifndef PWM_EMBEDDED
2531 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { 2531 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2532 unlockAll_tempoary(true); 2532 unlockAll_tempoary(true);
2533 f.close(); 2533 f.close();
2534 return e_writeFile; 2534 return e_writeFile;
2535 } 2535 }
2536#else 2536#else
2537 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { 2537 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2538 unlockAll_tempoary(true); 2538 unlockAll_tempoary(true);
2539 f.close(); 2539 f.close();
2540 return e_writeFile; 2540 return e_writeFile;
2541 } 2541 }
2542#endif 2542#endif
2543 } 2543 }
2544 } 2544 }
2545 unlockAll_tempoary(true); 2545 unlockAll_tempoary(true);
2546 f.close(); 2546 f.close();
2547 2547
2548 return e_success; 2548 return e_success;
2549} 2549}
2550 2550
2551PwMerror PwMDoc::importFromText(const QString *file, int format) 2551PwMerror PwMDoc::importFromText(const QString *file, int format)
2552{ 2552{
2553 PWM_ASSERT(file); 2553 PWM_ASSERT(file);
2554 if (format == 0) 2554 if (format == 0)
2555 return importText_PwM(file); 2555 return importText_PwM(file);
2556 else if (format == -1) { 2556 else if (format == -1) {
2557 // probe for all formats 2557 // probe for all formats
2558 if (importText_PwM(file) == e_success) 2558 if (importText_PwM(file) == e_success)
2559 return e_success; 2559 return e_success;
2560 dti.clear(); 2560 dti.clear();
2561 emitDataChanged(this); 2561 emitDataChanged(this);
2562 // add next format here... 2562 // add next format here...
2563 return e_fileFormat; 2563 return e_fileFormat;
2564 } 2564 }
2565 return e_invalidArg; 2565 return e_invalidArg;
2566} 2566}
2567 2567
2568PwMerror PwMDoc::importText_PwM(const QString *file) 2568PwMerror PwMDoc::importText_PwM(const QString *file)
2569{ 2569{
2570#ifndef PWM_EMBEDDED 2570#ifndef PWM_EMBEDDED
2571 PWM_ASSERT(file); 2571 PWM_ASSERT(file);
2572 FILE *f; 2572 FILE *f;
2573 int tmp; 2573 int tmp;
2574 ssize_t ret; 2574 ssize_t ret;
2575 string curCat; 2575 string curCat;
2576 unsigned int entriesRead = 0; 2576 unsigned int entriesRead = 0;
2577 PwMDataItem currItem; 2577 PwMDataItem currItem;
2578 f = fopen(file->latin1(), "r"); 2578 f = fopen(file->latin1(), "r");
2579 if (!f) 2579 if (!f)
2580 return e_openFile; 2580 return e_openFile;
2581 size_t ch_tmp_size = 1024; 2581 size_t ch_tmp_size = 1024;
2582 char *ch_tmp = (char*)malloc(ch_tmp_size); 2582 char *ch_tmp = (char*)malloc(ch_tmp_size);
2583 if (!ch_tmp) { 2583 if (!ch_tmp) {
2584 fclose(f); 2584 fclose(f);
2585 return e_outOfMem; 2585 return e_outOfMem;
2586 } 2586 }
2587 2587
2588 // - check header 2588 // - check header
2589 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. 2589 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2590 goto formatError; 2590 goto formatError;
2591 // check version-string and return version in "ch_tmp". 2591 // check version-string and return version in "ch_tmp".
2592 if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2592 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2593 // header not recognized as PwM generated header 2593 // header not recognized as PwM generated header
2594 goto formatError; 2594 goto formatError;
2595 } 2595 }
2596 // set filepointer behind version-string-line previously checked 2596 // set filepointer behind version-string-line previously checked
2597 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2597 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2598 goto formatError; 2598 goto formatError;
2599 // skip next line containing the build-date 2599 // skip next line containing the build-date
2600 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2600 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2601 goto formatError; 2601 goto formatError;
2602 // read header termination line 2602 // read header termination line
2603 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2603 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2604 goto formatError; 2604 goto formatError;
2605 if (strcmp(ch_tmp, "==============================\n")) 2605 if (strcmp(ch_tmp, "==============================\n"))
2606 goto formatError; 2606 goto formatError;
2607 2607
2608 // - read entries 2608 // - read entries
2609 do { 2609 do {
2610 // find beginning of next category 2610 // find beginning of next category
2611 do { 2611 do {
2612 tmp = fgetc(f); 2612 tmp = fgetc(f);
2613 } while (tmp == '\n' && tmp != EOF); 2613 } while (tmp == '\n' && tmp != EOF);
2614 if (tmp == EOF) 2614 if (tmp == EOF)
2615 break; 2615 break;
2616 2616
2617 // decrement filepos by one 2617 // decrement filepos by one
2618 fseek(f, -1, SEEK_CUR); 2618 fseek(f, -1, SEEK_CUR);
2619 // read cat-name 2619 // read cat-name
2620 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2620 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2621 goto formatError; 2621 goto formatError;
2622 // check cat-name format 2622 // check cat-name format
2623 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2623 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2624 goto formatError; 2624 goto formatError;
2625 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2625 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2626 goto formatError; 2626 goto formatError;
2627 // copy cat-name 2627 // copy cat-name
2628 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2628 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2629 2629
2630 do { 2630 do {
2631 // find beginning of next entry 2631 // find beginning of next entry
2632 do { 2632 do {
2633 tmp = fgetc(f); 2633 tmp = fgetc(f);
2634 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2634 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2635 if (tmp == EOF) 2635 if (tmp == EOF)
2636 break; 2636 break;
2637 if (tmp == '=') { 2637 if (tmp == '=') {
2638 fseek(f, -1, SEEK_CUR); 2638 fseek(f, -1, SEEK_CUR);
2639 break; 2639 break;
2640 } 2640 }
2641 // decrement filepos by one 2641 // decrement filepos by one
2642 fseek(f, -1, SEEK_CUR); 2642 fseek(f, -1, SEEK_CUR);
2643 // read desc-line 2643 // read desc-line
2644 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) 2644 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2645 goto formatError; 2645 goto formatError;
2646 // check desc-line format 2646 // check desc-line format
2647 if (memcmp(ch_tmp, "-- ", 3) != 0) 2647 if (memcmp(ch_tmp, "-- ", 3) != 0)
2648 goto formatError; 2648 goto formatError;
2649 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2649 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2650 goto formatError; 2650 goto formatError;
2651 // add desc-line 2651 // add desc-line
2652 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2652 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2653 2653
2654 // read username-line 2654 // read username-line
2655 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2655 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2656 goto formatError; 2656 goto formatError;
2657 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2657 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2658 goto formatError; 2658 goto formatError;
2659 2659
2660 // read pw-line 2660 // read pw-line
2661 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2661 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2662 goto formatError; 2662 goto formatError;
2663 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2663 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2664 goto formatError; 2664 goto formatError;
2665 2665
2666 // read comment-line 2666 // read comment-line
2667 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2667 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2668 goto formatError; 2668 goto formatError;
2669 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2669 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2670 goto formatError; 2670 goto formatError;
2671 2671
2672 // read URL-line 2672 // read URL-line
2673 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2673 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2674 goto formatError; 2674 goto formatError;
2675 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2675 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2676 goto formatError; 2676 goto formatError;
2677 2677
2678 // read launcher-line 2678 // read launcher-line
2679 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) 2679 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2680 goto formatError; 2680 goto formatError;
2681 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2681 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2682 goto formatError; 2682 goto formatError;
2683 2683
2684 currItem.lockStat = true; 2684 currItem.lockStat = true;
2685 currItem.listViewPos = -1; 2685 currItem.listViewPos = -1;
2686 addEntry(curCat.c_str(), &currItem, true); 2686 addEntry(curCat.c_str(), &currItem, true);
2687 ++entriesRead; 2687 ++entriesRead;
2688 } while (1); 2688 } while (1);
2689 } while (1); 2689 } while (1);
2690 if (!entriesRead) 2690 if (!entriesRead)
2691 goto formatError; 2691 goto formatError;
2692 2692
2693 free(ch_tmp); 2693 free(ch_tmp);
2694 fclose(f); 2694 fclose(f);
2695 flagDirty(); 2695 flagDirty();
2696 return e_success; 2696 return e_success;
2697 2697
2698 formatError: 2698 formatError:
2699 free(ch_tmp); 2699 free(ch_tmp);
2700 fclose(f); 2700 fclose(f);
2701 return e_fileFormat; 2701 return e_fileFormat;
2702#else 2702#else
2703 PWM_ASSERT(file); 2703 PWM_ASSERT(file);
2704 QFile f(file->latin1()); 2704 QFile f(file->latin1());
2705 int tmp; 2705 int tmp;
2706 ssize_t ret; 2706 ssize_t ret;
2707 string curCat; 2707 string curCat;
2708 unsigned int entriesRead = 0; 2708 unsigned int entriesRead = 0;
2709 PwMDataItem currItem; 2709 PwMDataItem currItem;
2710 bool res = f.open(IO_ReadOnly); 2710 bool res = f.open(IO_ReadOnly);
2711 if (res == false) 2711 if (res == false)
2712 return e_openFile; 2712 return e_openFile;
2713 2713
2714 unsigned int ch_tmp_size = 1024; 2714 unsigned int ch_tmp_size = 1024;
2715 char *ch_tmp = (char*)malloc(ch_tmp_size); 2715 char *ch_tmp = (char*)malloc(ch_tmp_size);
2716 if (!ch_tmp) { 2716 if (!ch_tmp) {
2717 f.close(); 2717 f.close();
2718 return e_outOfMem; 2718 return e_outOfMem;
2719 } 2719 }
2720 2720
2721 // - check header 2721 // - check header
2722 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line. 2722 if (f.readLine(ch_tmp, ch_tmp_size) == -1) // skip first line.
2723 goto formatError; 2723 goto formatError;
2724 2724
2725 //US read fileversion first, then check if ok. 2725 //US read fileversion first, then check if ok.
2726 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2726 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2727 goto formatError; 2727 goto formatError;
2728 2728
2729 // check version-string and return version in "ch_tmp". 2729 // check version-string and return version in "ch_tmp".
2730 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) { 2730 //US if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2731 //US // header not recognized as PwM generated header 2731 //US // header not recognized as PwM generated header
2732 //US goto formatError; 2732 //US goto formatError;
2733 //US} 2733 //US}
2734 //US set filepointer behind version-string-line previously checked 2734 //US set filepointer behind version-string-line previously checked
2735 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2735 //US if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2736 //US goto formatError; 2736 //US goto formatError;
2737 // skip next line containing the build-date 2737 // skip next line containing the build-date
2738 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2738 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2739 goto formatError; 2739 goto formatError;
2740 // read header termination line 2740 // read header termination line
2741 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2741 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2742 goto formatError; 2742 goto formatError;
2743 if (strcmp(ch_tmp, "==============================\n")) 2743 if (strcmp(ch_tmp, "==============================\n"))
2744 goto formatError; 2744 goto formatError;
2745 2745
2746 // - read entries 2746 // - read entries
2747 do { 2747 do {
2748 // find beginning of next category 2748 // find beginning of next category
2749 do { 2749 do {
2750 tmp = f.getch(); 2750 tmp = f.getch();
2751 } while (tmp == '\n' && tmp != EOF); 2751 } while (tmp == '\n' && tmp != EOF);
2752 if (tmp == EOF) 2752 if (tmp == EOF)
2753 break; 2753 break;
2754 2754
2755 // decrement filepos by one 2755 // decrement filepos by one
2756 f.at(f.at()-1); 2756 f.at(f.at()-1);
2757 // read cat-name 2757 // read cat-name
2758 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2758 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2759 goto formatError; 2759 goto formatError;
2760 // check cat-name format 2760 // check cat-name format
2761 if (memcmp(ch_tmp, "== Category: ", 13) != 0) 2761 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2762 goto formatError; 2762 goto formatError;
2763 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) 2763 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2764 goto formatError; 2764 goto formatError;
2765 // copy cat-name 2765 // copy cat-name
2766 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); 2766 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2767 2767
2768 do { 2768 do {
2769 // find beginning of next entry 2769 // find beginning of next entry
2770 do { 2770 do {
2771 tmp = f.getch(); 2771 tmp = f.getch();
2772 } while (tmp == '\n' && tmp != EOF && tmp != '='); 2772 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2773 if (tmp == EOF) 2773 if (tmp == EOF)
2774 break; 2774 break;
2775 if (tmp == '=') { 2775 if (tmp == '=') {
2776 f.at(f.at()-1); 2776 f.at(f.at()-1);
2777 break; 2777 break;
2778 } 2778 }
2779 // decrement filepos by one 2779 // decrement filepos by one
2780 f.at(f.at()-1); 2780 f.at(f.at()-1);
2781 // read desc-line 2781 // read desc-line
2782 if (f.readLine(ch_tmp, ch_tmp_size) == -1) 2782 if (f.readLine(ch_tmp, ch_tmp_size) == -1)
2783 goto formatError; 2783 goto formatError;
2784 // check desc-line format 2784 // check desc-line format
2785 if (memcmp(ch_tmp, "-- ", 3) != 0) 2785 if (memcmp(ch_tmp, "-- ", 3) != 0)
2786 goto formatError; 2786 goto formatError;
2787 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) 2787 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2788 goto formatError; 2788 goto formatError;
2789 // add desc-line 2789 // add desc-line
2790 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); 2790 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2791 2791
2792 // read username-line 2792 // read username-line
2793 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2793 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2794 goto formatError; 2794 goto formatError;
2795 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) 2795 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2796 goto formatError; 2796 goto formatError;
2797 2797
2798 // read pw-line 2798 // read pw-line
2799 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2799 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2800 goto formatError; 2800 goto formatError;
2801 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) 2801 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2802 goto formatError; 2802 goto formatError;
2803 2803
2804 // read comment-line 2804 // read comment-line
2805 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2805 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2806 goto formatError; 2806 goto formatError;
2807 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) 2807 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2808 goto formatError; 2808 goto formatError;
2809 2809
2810 // read URL-line 2810 // read URL-line
2811 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2811 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2812 goto formatError; 2812 goto formatError;
2813 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) 2813 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2814 goto formatError; 2814 goto formatError;
2815 2815
2816 // read launcher-line 2816 // read launcher-line
2817 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1) 2817 if ((ret = f.readLine(ch_tmp, ch_tmp_size)) == -1)
2818 goto formatError; 2818 goto formatError;
2819 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) 2819 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2820 goto formatError; 2820 goto formatError;
2821 2821
2822 currItem.lockStat = true; 2822 currItem.lockStat = true;
2823 currItem.listViewPos = -1; 2823 currItem.listViewPos = -1;
2824 addEntry(curCat.c_str(), &currItem, true); 2824 addEntry(curCat.c_str(), &currItem, true);
2825 ++entriesRead; 2825 ++entriesRead;
2826 } while (1); 2826 } while (1);
2827 } while (1); 2827 } while (1);
2828 if (!entriesRead) 2828 if (!entriesRead)
2829 goto formatError; 2829 goto formatError;
2830 2830
2831 free(ch_tmp); 2831 free(ch_tmp);
2832 f.close(); 2832 f.close();
2833 flagDirty(); 2833 flagDirty();
2834 return e_success; 2834 return e_success;
2835 2835
2836 formatError: 2836 formatError:
2837 free(ch_tmp); 2837 free(ch_tmp);
2838 f.close(); 2838 f.close();
2839 return e_fileFormat; 2839 return e_fileFormat;
2840 2840
2841#endif 2841#endif
2842 2842
2843} 2843}
2844 2844
2845bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) 2845bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2846{ 2846{
2847 PWM_ASSERT(in && out); 2847 PWM_ASSERT(in && out);
2848 ssize_t i = 0, len = in_size - 1; 2848 ssize_t i = 0, len = in_size - 1;
2849 while (i < len) { 2849 while (i < len) {
2850 if (in[i] == ':') 2850 if (in[i] == ':')
2851 break; 2851 break;
2852 ++i; 2852 ++i;
2853 } 2853 }
2854 i += 2; 2854 i += 2;
2855 *out = ""; 2855 *out = "";
2856 out->append(in + i, in_size - i - 1); 2856 out->append(in + i, in_size - i - 1);
2857 return true; 2857 return true;
2858} 2858}
2859 2859
2860PwMerror PwMDoc::exportToGpasman(const QString *file) 2860PwMerror PwMDoc::exportToGpasman(const QString *file)
2861{ 2861{
2862 PWM_ASSERT(file); 2862 PWM_ASSERT(file);
2863 GpasmanFile gp; 2863 GpasmanFile gp;
2864 int ret; 2864 int ret;
2865 2865
2866 if (!unlockAll_tempoary()) 2866 if (!unlockAll_tempoary())
2867 return e_lock; 2867 return e_lock;
2868 2868
2869 QString gpmPassword; 2869 QString gpmPassword;
2870 while (1) { 2870 while (1) {
2871 gpmPassword = requestNewMpw(0); 2871 gpmPassword = requestNewMpw(0);
2872 if (gpmPassword == "") { 2872 if (gpmPassword == "") {
2873 unlockAll_tempoary(true); 2873 unlockAll_tempoary(true);
2874 return e_noPw; 2874 return e_noPw;
2875 } 2875 }
2876 if (gpmPassword.length() < 4) { 2876 if (gpmPassword.length() < 4) {
2877 gpmPwLenErrMsgBox(); 2877 gpmPwLenErrMsgBox();
2878 } else { 2878 } else {
2879 break; 2879 break;
2880 } 2880 }
2881 } 2881 }
2882 2882
2883 ret = gp.save_init(file->latin1(), gpmPassword.latin1()); 2883 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2884 if (ret != 1) { 2884 if (ret != 1) {
2885 unlockAll_tempoary(true); 2885 unlockAll_tempoary(true);
2886 return e_accessFile; 2886 return e_accessFile;
2887 } 2887 }
2888 2888
2889 char *entry[4]; 2889 char *entry[4];
2890 unsigned int numCat = numCategories(), i; 2890 unsigned int numCat = numCategories(), i;
2891 unsigned int numEntr, j; 2891 unsigned int numEntr, j;
2892 int descLen, nameLen, pwLen, commentLen; 2892 int descLen, nameLen, pwLen, commentLen;
2893 for (i = 0; i < numCat; ++i) { 2893 for (i = 0; i < numCat; ++i) {
2894 numEntr = numEntries(i); 2894 numEntr = numEntries(i);
2895 for (j = 0; j < numEntr; ++j) { 2895 for (j = 0; j < numEntr; ++j) {
2896 descLen = dti.dta[i].d[j].desc.length(); 2896 descLen = dti.dta[i].d[j].desc.length();
2897 nameLen = dti.dta[i].d[j].name.length(); 2897 nameLen = dti.dta[i].d[j].name.length();
2898 pwLen = dti.dta[i].d[j].pw.length(); 2898 pwLen = dti.dta[i].d[j].pw.length();
2899 commentLen = dti.dta[i].d[j].comment.length(); 2899 commentLen = dti.dta[i].d[j].comment.length();
2900 entry[0] = new char[descLen + 1]; 2900 entry[0] = new char[descLen + 1];
2901 entry[1] = new char[nameLen + 1]; 2901 entry[1] = new char[nameLen + 1];
2902 entry[2] = new char[pwLen + 1]; 2902 entry[2] = new char[pwLen + 1];
2903 entry[3] = new char[commentLen + 1]; 2903 entry[3] = new char[commentLen + 1];
2904 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); 2904 strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str());
2905 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); 2905 strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str());
2906 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); 2906 strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str());
2907 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); 2907 strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str());
2908 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; 2908 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2909 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; 2909 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2910 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; 2910 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2911 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; 2911 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2912 2912
2913 ret = gp.save_entry(entry); 2913 ret = gp.save_entry(entry);
2914 if (ret == -1){ 2914 if (ret == -1){
2915 delete [] entry[0]; 2915 delete [] entry[0];
2916 delete [] entry[1]; 2916 delete [] entry[1];
2917 delete [] entry[2]; 2917 delete [] entry[2];
2918 delete [] entry[3]; 2918 delete [] entry[3];
2919 gp.save_finalize(); 2919 gp.save_finalize();
2920 unlockAll_tempoary(true); 2920 unlockAll_tempoary(true);
2921 return e_writeFile; 2921 return e_writeFile;
2922 } 2922 }
2923 2923
2924 delete [] entry[0]; 2924 delete [] entry[0];
2925 delete [] entry[1]; 2925 delete [] entry[1];
2926 delete [] entry[2]; 2926 delete [] entry[2];
2927 delete [] entry[3]; 2927 delete [] entry[3];
2928 } 2928 }
2929 } 2929 }
2930 unlockAll_tempoary(true); 2930 unlockAll_tempoary(true);
2931 if (gp.save_finalize() == -1) 2931 if (gp.save_finalize() == -1)
2932 return e_writeFile; 2932 return e_writeFile;
2933 2933
2934 return e_success; 2934 return e_success;
2935} 2935}
2936 2936
2937PwMerror PwMDoc::importFromGpasman(const QString *file) 2937PwMerror PwMDoc::importFromGpasman(const QString *file)
2938{ 2938{
2939 PWM_ASSERT(file); 2939 PWM_ASSERT(file);
2940 QString pw = requestMpw(false); 2940 QString pw = requestMpw(false);
2941 if (pw == "") 2941 if (pw == "")
2942 return e_noPw; 2942 return e_noPw;
2943 GpasmanFile gp; 2943 GpasmanFile gp;
2944 int ret, i; 2944 int ret, i;
2945 PwMerror ret2; 2945 PwMerror ret2;
2946 char *entry[4]; 2946 char *entry[4];
2947 PwMDataItem tmpData; 2947 PwMDataItem tmpData;
2948 ret = gp.load_init(file->latin1(), pw.latin1()); 2948 ret = gp.load_init(file->latin1(), pw.latin1());
2949 if (ret != 1) 2949 if (ret != 1)
2950 return e_accessFile; 2950 return e_accessFile;
2951 2951
2952 do { 2952 do {
2953 ret = gp.load_entry(entry); 2953 ret = gp.load_entry(entry);
2954 if(ret != 1) 2954 if(ret != 1)
2955 break; 2955 break;
2956 tmpData.desc = entry[0]; 2956 tmpData.desc = entry[0];
2957 tmpData.name = entry[1]; 2957 tmpData.name = entry[1];
2958 tmpData.pw = entry[2]; 2958 tmpData.pw = entry[2];
2959 tmpData.comment = entry[3]; 2959 tmpData.comment = entry[3];
2960 tmpData.lockStat = true; 2960 tmpData.lockStat = true;
2961 tmpData.listViewPos = -1; 2961 tmpData.listViewPos = -1;
2962 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2962 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2963 for (i = 0; i < 4; ++i) 2963 for (i = 0; i < 4; ++i)
2964 free(entry[i]); 2964 free(entry[i]);
2965 if (ret2 == e_maxAllowedEntr) { 2965 if (ret2 == e_maxAllowedEntr) {
2966 gp.load_finalize(); 2966 gp.load_finalize();
2967 return e_maxAllowedEntr; 2967 return e_maxAllowedEntr;
2968 } 2968 }
2969 } while (1); 2969 } while (1);
2970 gp.load_finalize(); 2970 gp.load_finalize();
2971 if (isDocEmpty()) 2971 if (isDocEmpty())
2972 return e_wrongPw; // we assume this. 2972 return e_wrongPw; // we assume this.
2973 2973
2974 flagDirty(); 2974 flagDirty();
2975 return e_success; 2975 return e_success;
2976} 2976}
2977 2977
2978 2978
2979//US: we use the stl sort algorythm to sort all elements in the order 2979//US: we use the stl sort algorythm to sort all elements in the order
2980//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2980//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2981struct PwMDataItemListViewPosSort 2981struct PwMDataItemListViewPosSort
2982{ 2982{
2983 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2983 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2984 { 2984 {
2985 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2985 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2986 if ((rpEnd)->listViewPos < 0) 2986 if ((rpEnd)->listViewPos < 0)
2987 return false; 2987 return false;
2988 else 2988 else
2989 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2989 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2990 } 2990 }
2991}; 2991};
2992 2992
2993void PwMDoc::ensureLvp() 2993void PwMDoc::ensureLvp()
2994{ 2994{
2995 if (isDocEmpty()) 2995 if (isDocEmpty())
2996 return; 2996 return;
2997 2997
2998 //US ENH BUG: when using syncronizing, this way of sorting 2998 //US ENH BUG: when using syncronizing, this way of sorting
2999 //is not sufficient, because there might be empty spaces 2999 //is not sufficient, because there might be empty spaces
3000 // at the beginning. But the old algorythm only can add elements 3000 // at the beginning. But the old algorythm only can add elements
3001 //to the end.The result are crashes because of list overflows 3001 //to the end.The result are crashes because of list overflows
3002 //we need something to fill all gaps. 3002 //we need something to fill all gaps.
3003 vector<PwMDataItem*> sorted; 3003 vector<PwMDataItem*> sorted;
3004 vector< PwMDataItem*>::iterator sortedBegin, 3004 vector< PwMDataItem*>::iterator sortedBegin,
3005 sortedEnd, 3005 sortedEnd,
3006 sortedI; 3006 sortedI;
3007 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 3007 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
3008 catEnd = dti.dta.end(), 3008 catEnd = dti.dta.end(),
3009 catI = catBegin; 3009 catI = catBegin;
3010 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3010 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3011 int lvpTop, tmpLvp; 3011 int lvpTop, tmpLvp;
3012 3012
3013 //qDebug("collect:"); 3013 //qDebug("collect:");
3014 3014
3015 while (catI != catEnd) { 3015 while (catI != catEnd) {
3016 lvpTop = -1; 3016 lvpTop = -1;
3017 sorted.clear(); 3017 sorted.clear();
3018 3018
3019 entrBegin = catI->d.begin(); 3019 entrBegin = catI->d.begin();
3020 entrEnd = catI->d.end(); 3020 entrEnd = catI->d.end();
3021 entrI = entrBegin; 3021 entrI = entrBegin;
3022 3022
3023 //US: we use the stl sort algorythm to sort all elements in the order 3023 //US: we use the stl sort algorythm to sort all elements in the order
3024 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 3024 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
3025 while (entrI != entrEnd) { 3025 while (entrI != entrEnd) {
3026 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 3026 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
3027 sorted.push_back((PwMDataItem*)&(*entrI)); 3027 sorted.push_back((PwMDataItem*)&(*entrI));
3028 ++entrI; 3028 ++entrI;
3029 } 3029 }
3030 3030
3031 sortedBegin = sorted.begin(); 3031 sortedBegin = sorted.begin();
3032 sortedEnd = sorted.end(); 3032 sortedEnd = sorted.end();
3033 3033
3034 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 3034 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
3035 3035
3036 // qDebug("resort:"); 3036 // qDebug("resort:");
3037 //now we have all sorted in a collection 3037 //now we have all sorted in a collection
3038 //Now start with the sorted and reset listviewpos. 3038 //Now start with the sorted and reset listviewpos.
3039 sortedBegin = sorted.begin(); 3039 sortedBegin = sorted.begin();
3040 sortedEnd = sorted.end(); 3040 sortedEnd = sorted.end();
3041 sortedI = sortedBegin; 3041 sortedI = sortedBegin;
3042 3042
3043 while (sortedI != sortedEnd) { 3043 while (sortedI != sortedEnd) {
3044 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 3044 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
3045 (*sortedI)->listViewPos = ++lvpTop; 3045 (*sortedI)->listViewPos = ++lvpTop;
3046 ++sortedI; 3046 ++sortedI;
3047 } 3047 }
3048 3048
3049 /*/debug 3049 /*/debug
3050 entrBegin = catI->d.begin(); 3050 entrBegin = catI->d.begin();
3051 entrEnd = catI->d.end(); 3051 entrEnd = catI->d.end();
3052 entrI = entrBegin; 3052 entrI = entrBegin;
3053 3053
3054 while (entrI != entrEnd) { 3054 while (entrI != entrEnd) {
3055 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 3055 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
3056 ++entrI; 3056 ++entrI;
3057 } 3057 }
3058 */ 3058 */
3059 3059
3060 ++catI; 3060 ++catI;
3061 } 3061 }
3062} 3062}
3063 3063
3064QString PwMDoc::getTitle() 3064QString PwMDoc::getTitle()
3065{ 3065{
3066 /* NOTE: We have to ensure, that the returned title 3066 /* NOTE: We have to ensure, that the returned title
3067 * is unique and not reused somewhere else while 3067 * is unique and not reused somewhere else while
3068 * this document is valid (open). 3068 * this document is valid (open).
3069 */ 3069 */
3070 QString title(getFilename()); 3070 QString title(getFilename());
3071 3071
3072 //US ENH: The whole filename on PDAs is too long. So use only the last characters 3072 //US ENH: The whole filename on PDAs is too long. So use only the last characters
3073 if (QApplication::desktop()->width() < 640) 3073 if (QApplication::desktop()->width() < 640)
3074 { 3074 {
3075 if (title.length() > 30) 3075 if (title.length() > 30)
3076 title = "..." + title.right(30); 3076 title = "..." + title.right(30);
3077 3077
3078 } 3078 }
3079 3079
3080 3080
3081 if (title.isEmpty()) { 3081 if (title.isEmpty()) {
3082 if (unnamedNum == 0) { 3082 if (unnamedNum == 0) {
3083 unnamedNum = PwMDocList::getNewUnnamedNumber(); 3083 unnamedNum = PwMDocList::getNewUnnamedNumber();
3084 PWM_ASSERT(unnamedNum != 0); 3084 PWM_ASSERT(unnamedNum != 0);
3085 } 3085 }
3086 title = DEFAULT_TITLE; 3086 title = DEFAULT_TITLE;
3087 title += " "; 3087 title += " ";
3088 title += tostr(unnamedNum).c_str(); 3088 title += tostr(unnamedNum).c_str();
3089 } 3089 }
3090 return title; 3090 return title;
3091} 3091}
3092 3092
3093bool PwMDoc::tryDelete() 3093bool PwMDoc::tryDelete()
3094{ 3094{
3095 3095
3096 if (deleted) 3096 if (deleted)
3097 return true; 3097 return true;
3098 int ret; 3098 int ret;
3099 if (isDirty()) { 3099 if (isDirty()) {
3100 ret = dirtyAskSave(getTitle()); 3100 ret = dirtyAskSave(getTitle());
3101 if (ret == 0) { // save to disk 3101 if (ret == 0) { // save to disk
3102 if (!saveDocUi(this)) 3102 if (!saveDocUi(this))
3103 goto out_ignore; 3103 goto out_ignore;
3104 } else if (ret == 1) { // don't save and delete 3104 } else if (ret == 1) { // don't save and delete
3105 goto out_accept; 3105 goto out_accept;
3106 } else { // cancel operation 3106 } else { // cancel operation
3107 goto out_ignore; 3107 goto out_ignore;
3108 } 3108 }
3109 } 3109 }
3110out_accept: 3110out_accept:
3111 deleted = true; 3111 deleted = true;
3112 delete this; 3112 delete this;
3113 return true; 3113 return true;
3114out_ignore: 3114out_ignore:
3115 return false; 3115 return false;
3116} 3116}
3117 3117
3118 3118
3119 3119
3120#ifdef PWM_EMBEDDED 3120#ifdef PWM_EMBEDDED
3121//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3121//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3122//US it could have been defined as static, but I did not want to. 3122//US it could have been defined as static, but I did not want to.
3123PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3123PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3124{ 3124{
3125 int addedPasswordsLocal = 0; 3125 int addedPasswordsLocal = 0;
3126 int addedPasswordsRemote = 0; 3126 int addedPasswordsRemote = 0;
3127 int deletedPasswordsRemote = 0; 3127 int deletedPasswordsRemote = 0;
3128 int deletedPasswordsLocal = 0; 3128 int deletedPasswordsLocal = 0;
3129 int changedLocal = 0; 3129 int changedLocal = 0;
3130 int changedRemote = 0; 3130 int changedRemote = 0;
3131 3131
3132 PwMSyncItem* syncItemLocal; 3132 PwMSyncItem* syncItemLocal;
3133 PwMSyncItem* syncItemRemote; 3133 PwMSyncItem* syncItemRemote;
3134 3134
3135 QString mCurrentSyncName = manager->getCurrentSyncName(); 3135 QString mCurrentSyncName = manager->getCurrentSyncName();
3136 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3136 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3137 3137
3138 bool mSyncLauncher = true; 3138 bool mSyncLauncher = true;
3139 3139
3140 bool fullDateRange = false; 3140 bool fullDateRange = false;
3141 int take; 3141 int take;
3142 // local->resetTempSyncStat(); 3142 // local->resetTempSyncStat();
3143 QDateTime mLastSync = QDateTime::currentDateTime(); 3143 QDateTime mLastSync = QDateTime::currentDateTime();
3144 QDateTime modifiedSync = mLastSync; 3144 QDateTime modifiedSync = mLastSync;
3145 3145
3146 unsigned int index; 3146 unsigned int index;
3147 //Step 1. Find syncinfo in Local file and create if not existent. 3147 //Step 1. Find syncinfo in Local file and create if not existent.
3148 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3148 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3149 if (found == false) 3149 if (found == false)
3150 { 3150 {
3151 PwMSyncItem newSyncItemLocal; 3151 PwMSyncItem newSyncItemLocal;
3152 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3152 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3153 newSyncItemLocal.lastSyncDate = mLastSync; 3153 newSyncItemLocal.lastSyncDate = mLastSync;
3154 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3154 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3155 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3155 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3156 if (found == false) { 3156 if (found == false) {
3157 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3157 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3158 return e_syncError; 3158 return e_syncError;
3159 } 3159 }
3160 } 3160 }
3161 3161
3162 syncItemLocal = syncLocal->getSyncDataEntry(index); 3162 syncItemLocal = syncLocal->getSyncDataEntry(index);
3163 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3163 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3164 3164
3165 //Step 2. Find syncinfo in remote file and create if not existent. 3165 //Step 2. Find syncinfo in remote file and create if not existent.
3166 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3166 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3167 if (found == false) 3167 if (found == false)
3168 { 3168 {
3169 qDebug("FULLDATE 1"); 3169 qDebug("FULLDATE 1");
3170 fullDateRange = true; 3170 fullDateRange = true;
3171 PwMSyncItem newSyncItemRemote; 3171 PwMSyncItem newSyncItemRemote;
3172 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3172 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3173 newSyncItemRemote.lastSyncDate = mLastSync; 3173 newSyncItemRemote.lastSyncDate = mLastSync;
3174 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3174 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3175 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3175 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3176 if (found == false) { 3176 if (found == false) {
3177 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3177 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3178 return e_syncError; 3178 return e_syncError;
3179 } 3179 }
3180 } 3180 }
3181 3181
3182 syncItemRemote = syncRemote->getSyncDataEntry(index); 3182 syncItemRemote = syncRemote->getSyncDataEntry(index);
3183 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3183 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3184 //and remove the found entry here. We will reenter it later again. 3184 //and remove the found entry here. We will reenter it later again.
3185 //US syncRemote->delSyncDataEntry(index, true); 3185 //US syncRemote->delSyncDataEntry(index, true);
3186 3186
3187 3187
3188 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3188 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3189 qDebug("FULLDATE 2"); 3189 qDebug("FULLDATE 2");
3190 fullDateRange = true; 3190 fullDateRange = true;
3191 } 3191 }
3192 3192
3193 if ( ! fullDateRange ) { 3193 if ( ! fullDateRange ) {
3194 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3194 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3195 3195
3196 fullDateRange = true; 3196 fullDateRange = true;
3197 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3197 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3198 } 3198 }
3199 } 3199 }
3200 // fullDateRange = true; // debug only! 3200 // fullDateRange = true; // debug only!
3201 if ( fullDateRange ) 3201 if ( fullDateRange )
3202 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3202 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3203 else 3203 else
3204 mLastSync = syncItemLocal->lastSyncDate; 3204 mLastSync = syncItemLocal->lastSyncDate;
3205 3205
3206 3206
3207 qDebug("*************************** "); 3207 qDebug("*************************** ");
3208 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3208 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3209 QStringList er = syncRemote->getIDEntryList(); 3209 QStringList er = syncRemote->getIDEntryList();
3210 PwMDataItem* inRemote ;//= er.first(); 3210 PwMDataItem* inRemote ;//= er.first();
3211 PwMDataItem* inLocal; 3211 PwMDataItem* inLocal;
3212 unsigned int catLocal, indexLocal; 3212 unsigned int catLocal, indexLocal;
3213 unsigned int catRemote, indexRemote; 3213 unsigned int catRemote, indexRemote;
3214 3214
3215 QString uid; 3215 QString uid;
3216 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3216 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3217 3217
3218 int modulo = (er.count()/10)+1; 3218 int modulo = (er.count()/10)+1;
3219 unsigned int incCounter = 0; 3219 unsigned int incCounter = 0;
3220 while ( incCounter < er.count()) { 3220 while ( incCounter < er.count()) {
3221 if (manager->isProgressBarCanceled()) 3221 if (manager->isProgressBarCanceled())
3222 return e_syncError; 3222 return e_syncError;
3223 if ( incCounter % modulo == 0 ) 3223 if ( incCounter % modulo == 0 )
3224 manager->showProgressBar(incCounter); 3224 manager->showProgressBar(incCounter);
3225 3225
3226 uid = er[ incCounter ]; 3226 uid = er[ incCounter ];
3227 qDebug("sync uid %s from remote file", uid.latin1()); 3227 qDebug("sync uid %s from remote file", uid.latin1());
3228 3228
3229 qApp->processEvents(); 3229 qApp->processEvents();
3230 3230
3231 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3231 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3232 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3232 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3233 PWM_ASSERT(inRemote); 3233 PWM_ASSERT(inRemote);
3234 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3234 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3235 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3235 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3236 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3236 qDebug("take %d %s ", take, inLocal->desc.c_str());
3237 if ( take == 3 ) 3237 if ( take == 3 )
3238 return e_syncError; 3238 return e_syncError;
3239 if ( take == 1 ) {// take local 3239 if ( take == 1 ) {// take local
3240 inRemote->syncItem(*inLocal, mSyncLauncher); 3240 inRemote->syncItem(*inLocal, mSyncLauncher);
3241 ++changedRemote; 3241 ++changedRemote;
3242 } else { // take == 2 take remote 3242 } else { // take == 2 take remote
3243 inLocal->syncItem(*inRemote, mSyncLauncher); 3243 inLocal->syncItem(*inRemote, mSyncLauncher);
3244 ++changedLocal; 3244 ++changedLocal;
3245 } 3245 }
3246 } 3246 }
3247 } else { // no conflict 3247 } else { // no conflict
3248 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3248 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3249 inRemote->meta.update = modifiedSync; 3249 inRemote->meta.update = modifiedSync;
3250 3250
3251 //first check if we have a matching category in the local file 3251 //first check if we have a matching category in the local file
3252 const string* remotecat = syncRemote->getCategory(catRemote); 3252 const string* remotecat = syncRemote->getCategory(catRemote);
3253 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3253 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3254 3254
3255 ++addedPasswordsLocal; 3255 ++addedPasswordsLocal;
3256 } else { 3256 } else {
3257 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3257 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3258 syncRemote->delEntry(catRemote, indexRemote, true); 3258 syncRemote->delEntry(catRemote, indexRemote, true);
3259 ++deletedPasswordsRemote; 3259 ++deletedPasswordsRemote;
3260 } 3260 }
3261 } 3261 }
3262 3262
3263 ++incCounter; 3263 ++incCounter;
3264 } 3264 }
3265 3265
3266 3266
3267 er.clear(); 3267 er.clear();
3268 QStringList el = syncLocal->getIDEntryList(); 3268 QStringList el = syncLocal->getIDEntryList();
3269 modulo = (el.count()/10)+1; 3269 modulo = (el.count()/10)+1;
3270 3270
3271 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3271 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3272 incCounter = 0; 3272 incCounter = 0;
3273 while ( incCounter < el.count()) { 3273 while ( incCounter < el.count()) {
3274 qApp->processEvents(); 3274 qApp->processEvents();
3275 if (manager->isProgressBarCanceled()) 3275 if (manager->isProgressBarCanceled())
3276 return e_syncError; 3276 return e_syncError;
3277 if ( incCounter % modulo == 0 ) 3277 if ( incCounter % modulo == 0 )
3278 manager->showProgressBar(incCounter); 3278 manager->showProgressBar(incCounter);
3279 uid = el[ incCounter ]; 3279 uid = el[ incCounter ];
3280 qDebug("sync uid %s from local file", uid.latin1()); 3280 qDebug("sync uid %s from local file", uid.latin1());
3281 3281
3282 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3282 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3283 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3283 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3284 PWM_ASSERT(inLocal); 3284 PWM_ASSERT(inLocal);
3285 3285
3286 if ( inRemote == 0 ) { 3286 if ( inRemote == 0 ) {
3287 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3287 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3288 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3288 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3289 syncLocal->delEntry(catLocal, indexLocal, true); 3289 syncLocal->delEntry(catLocal, indexLocal, true);
3290 ++deletedPasswordsLocal; 3290 ++deletedPasswordsLocal;
3291 } else { 3291 } else {
3292 if ( ! manager->mWriteBackExistingOnly ) { 3292 if ( ! manager->mWriteBackExistingOnly ) {
3293 ++addedPasswordsRemote; 3293 ++addedPasswordsRemote;
3294 inLocal->meta.update = modifiedSync; 3294 inLocal->meta.update = modifiedSync;
3295 3295
3296 //first check if we have a matching category in the remote file 3296 //first check if we have a matching category in the remote file
3297 const string* localcat = syncLocal->getCategory(catLocal); 3297 const string* localcat = syncLocal->getCategory(catLocal);
3298 3298
3299 PwMDataItem newEntry; 3299 PwMDataItem newEntry;
3300 newEntry = *inLocal; 3300 newEntry = *inLocal;
3301 inRemote = &newEntry; 3301 inRemote = &newEntry;
3302 3302
3303 //USsyncRemote->insertAddressee( inRemote, false ); 3303 //USsyncRemote->insertAddressee( inRemote, false );
3304 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3304 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3305 3305
3306 } 3306 }
3307 } 3307 }
3308 3308
3309 } 3309 }
3310 ++incCounter; 3310 ++incCounter;
3311 } 3311 }
3312 el.clear(); 3312 el.clear();
3313 manager->hideProgressBar(); 3313 manager->hideProgressBar();
3314 3314
3315 // Now write the info back into the sync data space of the files 3315 // Now write the info back into the sync data space of the files
3316 3316
3317 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3317 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3318 // get rid of micro seconds 3318 // get rid of micro seconds
3319 QTime t = mLastSync.time(); 3319 QTime t = mLastSync.time();
3320 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3320 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3321 3321
3322 3322
3323 syncItemLocal->lastSyncDate = mLastSync; 3323 syncItemLocal->lastSyncDate = mLastSync;
3324 syncItemRemote->lastSyncDate = mLastSync; 3324 syncItemRemote->lastSyncDate = mLastSync;
3325 3325
3326 QString mes; 3326 QString mes;
3327 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 ); 3327 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 );
3328 if ( manager->mShowSyncSummary ) { 3328 if ( manager->mShowSyncSummary ) {
3329 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3329 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3330 } 3330 }
3331 qDebug( mes ); 3331 qDebug( mes );
3332 return e_success; 3332 return e_success;
3333} 3333}
3334 3334
3335 3335
3336int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3336int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3337{ 3337{
3338 // 0 equal 3338 // 0 equal
3339 // 1 take local 3339 // 1 take local
3340 // 2 take remote 3340 // 2 take remote
3341 // 3 cancel 3341 // 3 cancel
3342 QDateTime localMod = local->meta.update; 3342 QDateTime localMod = local->meta.update;
3343 QDateTime remoteMod = remote->meta.update; 3343 QDateTime remoteMod = remote->meta.update;
3344 3344
3345 if ( localMod == remoteMod ) 3345 if ( localMod == remoteMod )
3346 return 0; 3346 return 0;
3347 3347
3348 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3348 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3349 3349
3350 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3350 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3351 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3351 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3352 //full = true; //debug only 3352 //full = true; //debug only
3353 if ( full ) { 3353 if ( full ) {
3354 bool equ = ( (*local) == (*remote) ); 3354 bool equ = ( (*local) == (*remote) );
3355 if ( equ ) { 3355 if ( equ ) {
3356 //qDebug("equal "); 3356 //qDebug("equal ");
3357 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3357 if ( mode < SYNC_PREF_FORCE_LOCAL )
3358 return 0; 3358 return 0;
3359 3359
3360 }//else //debug only 3360 }//else //debug only
3361 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3361 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3362 } 3362 }
3363 3363
3364 int result; 3364 int result;
3365 bool localIsNew; 3365 bool localIsNew;
3366 //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() ); 3366 //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() );
3367 3367
3368 if ( full && mode < SYNC_PREF_NEWEST ) 3368 if ( full && mode < SYNC_PREF_NEWEST )
3369 mode = SYNC_PREF_ASK; 3369 mode = SYNC_PREF_ASK;
3370 3370
3371 switch( mode ) { 3371 switch( mode ) {
3372 case SYNC_PREF_LOCAL: 3372 case SYNC_PREF_LOCAL:
3373 if ( lastSync > remoteMod ) 3373 if ( lastSync > remoteMod )
3374 return 1; 3374 return 1;
3375 if ( lastSync > localMod ) 3375 if ( lastSync > localMod )
3376 return 2; 3376 return 2;
3377 return 1; 3377 return 1;
3378 break; 3378 break;
3379 case SYNC_PREF_REMOTE: 3379 case SYNC_PREF_REMOTE:
3380 if ( lastSync > remoteMod ) 3380 if ( lastSync > remoteMod )
3381 return 1; 3381 return 1;
3382 if ( lastSync > localMod ) 3382 if ( lastSync > localMod )
3383 return 2; 3383 return 2;
3384 return 2; 3384 return 2;
3385 break; 3385 break;
3386 case SYNC_PREF_NEWEST: 3386 case SYNC_PREF_NEWEST:
3387 if ( localMod > remoteMod ) 3387 if ( localMod > remoteMod )
3388 return 1; 3388 return 1;
3389 else 3389 else
3390 return 2; 3390 return 2;
3391 break; 3391 break;
3392 case SYNC_PREF_ASK: 3392 case SYNC_PREF_ASK:
3393 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3393 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3394 if ( lastSync > remoteMod ) 3394 if ( lastSync > remoteMod )
3395 return 1; 3395 return 1;
3396 if ( lastSync > localMod ) 3396 if ( lastSync > localMod )
3397 return 2; 3397 return 2;
3398 localIsNew = localMod >= remoteMod; 3398 localIsNew = localMod >= remoteMod;
3399 //qDebug("conflict! ************************************** "); 3399 //qDebug("conflict! ************************************** ");
3400 { 3400 {
3401 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3401 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3402 result = acd.executeD(localIsNew); 3402 result = acd.executeD(localIsNew);
3403 return result; 3403 return result;
3404 } 3404 }
3405 break; 3405 break;
3406 case SYNC_PREF_FORCE_LOCAL: 3406 case SYNC_PREF_FORCE_LOCAL:
3407 return 1; 3407 return 1;
3408 break; 3408 break;
3409 case SYNC_PREF_FORCE_REMOTE: 3409 case SYNC_PREF_FORCE_REMOTE:
3410 return 2; 3410 return 2;
3411 break; 3411 break;
3412 3412
3413 default: 3413 default:
3414 // SYNC_PREF_TAKE_BOTH not implemented 3414 // SYNC_PREF_TAKE_BOTH not implemented
3415 break; 3415 break;
3416 } 3416 }
3417 return 0; 3417 return 0;
3418} 3418}
3419 3419
3420void PwMDoc::removeSyncInfo( QString syncProfile) 3420void PwMDoc::removeSyncInfo( QString syncProfile)
3421{ 3421{
3422 bool res, found; 3422 bool res, found;
3423 unsigned int count, i; 3423 unsigned int count, i;
3424 if ( syncProfile.isEmpty() ) { 3424 if ( syncProfile.isEmpty() ) {
3425 count = numSyncDataEntries(); 3425 count = numSyncDataEntries();
3426 for (i = count; count > 0; count-- ) { 3426 for (i = count; count > 0; count-- ) {
3427 res = delSyncDataEntry(i-1, false); 3427 res = delSyncDataEntry(i-1, false);
3428 if (res == false) { 3428 if (res == false) {
3429 qDebug("PwMDoc::removeSyncInfo: could not remove syncprofile"); 3429 qDebug("PwMDoc::removeSyncInfo: could not remove syncprofile");
3430 } 3430 }
3431 } 3431 }
3432 } else { 3432 } else {
3433 found = findSyncData(syncProfile, &count); 3433 found = findSyncData(syncProfile, &count);
3434 if (found == true) 3434 if (found == true)
3435 { 3435 {
3436 res = delSyncDataEntry(count, false); 3436 res = delSyncDataEntry(count, false);
3437 if (res == false) { 3437 if (res == false) {
3438 qDebug("PwMDoc::removeSyncInfo: could not remove %s", syncProfile.latin1()); 3438 qDebug("PwMDoc::removeSyncInfo: could not remove %s", syncProfile.latin1());
3439 3439
3440 } 3440 }
3441 } 3441 }
3442 } 3442 }
3443} 3443}
3444 3444
3445 3445
3446//this are the overwritten callbackmethods from the syncinterface 3446//this are the overwritten callbackmethods from the syncinterface
3447bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3447bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode, QString resource)
3448{ 3448{
3449 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3449 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3450 3450
3451 //1) unlock local file first if necessary (ask for password) 3451 //1) unlock local file first if necessary (ask for password)
3452 if (this->isDeepLocked()) { 3452 if (this->isDeepLocked()) {
3453 PwMerror ret = this->deepLock(false); 3453 PwMerror ret = this->deepLock(false);
3454 if (ret != e_success) 3454 if (ret != e_success)
3455 return false; 3455 return false;
3456 } 3456 }
3457 3457
3458 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3458 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3459 PwMDoc syncTarget(this, "synctarget"); 3459 PwMDoc syncTarget(this, "synctarget");
3460 PwMDoc* pSyncTarget = &syncTarget; 3460 PwMDoc* pSyncTarget = &syncTarget;
3461 3461
3462 3462
3463 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3463 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3464 3464
3465 if (err == e_alreadyOpen) { 3465 if (err == e_alreadyOpen) {
3466 PwMDocList::listItem li; 3466 PwMDocList::listItem li;
3467 if (getOpenDocList()->find(filename.latin1(), &li)) 3467 if (getOpenDocList()->find(filename.latin1(), &li))
3468 pSyncTarget = li.doc; 3468 pSyncTarget = li.doc;
3469 else { 3469 else {
3470 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3470 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3471 return false; 3471 return false;
3472 } 3472 }
3473 } 3473 }
3474 else if (err != e_success) { 3474 else if (err != e_success) {
3475 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3475 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3476 return false; 3476 return false;
3477 } 3477 }
3478 3478
3479 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3479 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3480 3480
3481 3481
3482 //3) unlock remote file first if necessary (ask for password) 3482 //3) unlock remote file first if necessary (ask for password)
3483 if (pSyncTarget->isDeepLocked()) { 3483 if (pSyncTarget->isDeepLocked()) {
3484 PwMerror ret = pSyncTarget->deepLock(false); 3484 PwMerror ret = pSyncTarget->deepLock(false);
3485 if (ret != e_success) 3485 if (ret != e_success)
3486 return false; 3486 return false;
3487 } 3487 }
3488 3488
3489 3489
3490 err = syncronize(manager, this, pSyncTarget, mode ); 3490 err = syncronize(manager, this, pSyncTarget, mode );
3491 3491
3492 if (err == e_success) { 3492 if (err == e_success) {
3493 if ( manager->mWriteBackFile ){ 3493 if ( manager->mWriteBackFile ){
3494 qDebug("Saving remote PWManager file"); 3494 qDebug("Saving remote PWManager file");
3495 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3495 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3496 if (err != e_success) { 3496 if (err != e_success) {
3497 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3497 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3498 return false; 3498 return false;
3499 } 3499 }
3500 } 3500 }
3501 3501
3502 flagDirty(); 3502 flagDirty();
3503 return true; 3503 return true;
3504 } 3504 }
3505 else { 3505 else {
3506 return false; 3506 return false;
3507 } 3507 }
3508} 3508}
3509 3509
3510#endif 3510#endif
3511 3511
3512 3512
3513bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3513bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3514{ 3514{
3515 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3515 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3516 end = dti.syncDta.end(); 3516 end = dti.syncDta.end();
3517 3517
3518 while (i != end) { 3518 while (i != end) {
3519 if ((*i).syncName == syncname.latin1()) { 3519 if ((*i).syncName == syncname.latin1()) {
3520 if (index) { 3520 if (index) {
3521 *index = i - dti.syncDta.begin(); 3521 *index = i - dti.syncDta.begin();
3522 } 3522 }
3523 return true; 3523 return true;
3524 } 3524 }
3525 ++i; 3525 ++i;
3526 } 3526 }
3527 return false; 3527 return false;
3528}; 3528};
3529 3529
3530/** add new syncdataentry */ 3530/** add new syncdataentry */
3531PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3531PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3532{ 3532{
3533 PWM_ASSERT(d); 3533 PWM_ASSERT(d);
3534 3534
3535 if (isDeepLocked()) { 3535 if (isDeepLocked()) {
3536 PwMerror ret; 3536 PwMerror ret;
3537 ret = deepLock(false); 3537 ret = deepLock(false);
3538 if (ret != e_success) 3538 if (ret != e_success)
3539 return e_lock; 3539 return e_lock;
3540 } 3540 }
3541 unsigned int index; 3541 unsigned int index;
3542 3542
3543 const QString tmp = d->syncName.c_str(); 3543 const QString tmp = d->syncName.c_str();
3544 bool exists = findSyncData(d->syncName.c_str(), &index); 3544 bool exists = findSyncData(d->syncName.c_str(), &index);
3545 3545
3546 if (exists == true) { 3546 if (exists == true) {
3547 // DOH! We found this entry. 3547 // DOH! We found this entry.
3548 return e_entryExists; 3548 return e_entryExists;
3549 } 3549 }
3550 3550
3551 dti.syncDta.push_back(*d); 3551 dti.syncDta.push_back(*d);
3552 3552
3553 if (!dontFlagDirty) 3553 if (!dontFlagDirty)
3554 flagDirty(); 3554 flagDirty();
3555 return e_success; 3555 return e_success;
3556} 3556}
3557 3557
3558 3558
3559 3559
3560/** delete syncdata entry */ 3560/** delete syncdata entry */
3561bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3561bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3562{ 3562{
3563 if (isDeepLocked()) 3563 if (isDeepLocked())
3564 return false; 3564 return false;
3565 if (index > dti.syncDta.size() - 1) 3565 if (index > dti.syncDta.size() - 1)
3566 return false; 3566 return false;
3567 3567
3568 // delete entry 3568 // delete entry
3569 dti.syncDta.erase(dti.syncDta.begin() + index); 3569 dti.syncDta.erase(dti.syncDta.begin() + index);
3570 3570
3571 if (!dontFlagDirty) 3571 if (!dontFlagDirty)
3572 flagDirty(); 3572 flagDirty();
3573 return true; 3573 return true;
3574} 3574}
3575 3575
3576 3576
3577PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3577PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3578{ 3578{
3579 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3579 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3580 catend = dti.dta.end(); 3580 catend = dti.dta.end();
3581 3581
3582 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3582 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3583 3583
3584 while (catcounter != catend) { 3584 while (catcounter != catend) {
3585 entrBegin = catcounter->d.begin(); 3585 entrBegin = catcounter->d.begin();
3586 entrEnd = catcounter->d.end(); 3586 entrEnd = catcounter->d.end();
3587 entrI = entrBegin; 3587 entrI = entrBegin;
3588 while (entrI != entrEnd) { 3588 while (entrI != entrEnd) {
3589 if ((*entrI).meta.uniqueid == uid.latin1()) { 3589 if ((*entrI).meta.uniqueid == uid.latin1()) {
3590 if (category) 3590 if (category)
3591 *category = catcounter - dti.dta.begin(); 3591 *category = catcounter - dti.dta.begin();
3592 if (index) 3592 if (index)
3593 *index = entrI - entrBegin; 3593 *index = entrI - entrBegin;
3594 3594
3595 return &(*entrI); 3595 return &(*entrI);
3596 } 3596 }
3597 ++entrI; 3597 ++entrI;
3598 } 3598 }
3599 ++catcounter; 3599 ++catcounter;
3600 } 3600 }
3601 3601
3602 return 0; 3602 return 0;
3603} 3603}
3604 3604
3605QStringList PwMDoc::getIDEntryList() 3605QStringList PwMDoc::getIDEntryList()
3606{ 3606{
3607 QStringList results; 3607 QStringList results;
3608 3608
3609 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3609 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3610 catend = dti.dta.end(); 3610 catend = dti.dta.end();
3611 3611
3612 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3612 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3613 3613
3614 while (catcounter != catend) { 3614 while (catcounter != catend) {
3615 entrBegin = catcounter->d.begin(); 3615 entrBegin = catcounter->d.begin();
3616 entrEnd = catcounter->d.end(); 3616 entrEnd = catcounter->d.end();
3617 entrI = entrBegin; 3617 entrI = entrBegin;
3618 while (entrI != entrEnd) { 3618 while (entrI != entrEnd) {
3619 results.append( (*entrI).meta.uniqueid.c_str() ); 3619 results.append( (*entrI).meta.uniqueid.c_str() );
3620 ++entrI; 3620 ++entrI;
3621 } 3621 }
3622 ++catcounter; 3622 ++catcounter;
3623 } 3623 }
3624 3624
3625 return results; 3625 return results;
3626} 3626}
3627 3627
3628 3628
3629 3629
3630 3630
3631 3631
3632#ifndef PWM_EMBEDDED 3632#ifndef PWM_EMBEDDED
3633#include "pwmdoc.moc" 3633#include "pwmdoc.moc"
3634#endif 3634#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 45dd729..144831f 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -1,833 +1,833 @@
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.1 of pwmanager 14 * This file is originaly based on version 1.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 __PWMDOC_H 20#ifndef __PWMDOC_H
21#define __PWMDOC_H 21#define __PWMDOC_H
22#ifdef _WIN32_ 22#ifdef _WIN32_
23#define ssize_t unsigned int 23#define ssize_t unsigned int
24#endif 24#endif
25 #define PWM_FILE_VER (static_cast<char>(0x05)) 25 #define PWM_FILE_VER (static_cast<char>(0x05))
26 26
27 #define PWM_HASH_SHA1 (static_cast<char>(0x01)) 27 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
28 #define PWM_HASH_SHA256 (static_cast<char>(0x02)) 28 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
29 #define PWM_HASH_SHA384 (static_cast<char>(0x03)) 29 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
30 #define PWM_HASH_SHA512 (static_cast<char>(0x04)) 30 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
31 #define PWM_HASH_MD5 (static_cast<char>(0x05)) 31 #define PWM_HASH_MD5 (static_cast<char>(0x05))
32 #define PWM_HASH_RMD160 (static_cast<char>(0x06)) 32 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
33 #define PWM_HASH_TIGER (static_cast<char>(0x07)) 33 #define PWM_HASH_TIGER (static_cast<char>(0x07))
34 34
35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
36 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 36 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
37 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 37 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
38 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 38 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
39 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 39 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
42 42
43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
46 46
47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
49 49
50 50
51#include "pwmexception.h" 51#include "pwmexception.h"
52#include "pwmdocui.h" 52#include "pwmdocui.h"
53 53
54#include <qobject.h> 54#include <qobject.h>
55#include <qtimer.h> 55#include <qtimer.h>
56#include <qdatetime.h> 56#include <qdatetime.h>
57 57
58#include <kprocess.h> 58#include <kprocess.h>
59 59
60#ifndef PWM_EMBEDDED 60#ifndef PWM_EMBEDDED
61#include "configuration.h" 61#include "configuration.h"
62#else 62#else
63#include <kapplication.h> 63#include <kapplication.h>
64#include <ksyncmanager.h> 64#include <ksyncmanager.h>
65#endif 65#endif
66 66
67#include <string> 67#include <string>
68#include <vector> 68#include <vector>
69#include <utility> 69#include <utility>
70 70
71using std::vector; 71using std::vector;
72using std::string; 72using std::string;
73using std::pair; 73using std::pair;
74 74
75/* used in findEntry() function */ 75/* used in findEntry() function */
76 #define SEARCH_IN_DESC (1) 76 #define SEARCH_IN_DESC (1)
77 #define SEARCH_IN_NAME (1 << 1) 77 #define SEARCH_IN_NAME (1 << 1)
78 #define SEARCH_IN_PW (1 << 2) 78 #define SEARCH_IN_PW (1 << 2)
79 #define SEARCH_IN_COMMENT(1 << 3) 79 #define SEARCH_IN_COMMENT(1 << 3)
80 #define SEARCH_IN_URL (1 << 4) 80 #define SEARCH_IN_URL (1 << 4)
81 #define SEARCH_IN_LAUNCHER(1 << 5) 81 #define SEARCH_IN_LAUNCHER(1 << 5)
82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
85 85
86/** document deeplocked. Data is out for lunch to disk */ 86/** document deeplocked. Data is out for lunch to disk */
87 #define DOC_STAT_DEEPLOCKED (1) 87 #define DOC_STAT_DEEPLOCKED (1)
88/** encrypted document on disk is dirty. data has to go to disk. */ 88/** encrypted document on disk is dirty. data has to go to disk. */
89 #define DOC_STAT_DISK_DIRTY (1 << 1) 89 #define DOC_STAT_DISK_DIRTY (1 << 1)
90/** we are using a chipcard to encrypt the data */ 90/** we are using a chipcard to encrypt the data */
91 #define DOC_STAT_USE_CHIPCARD (1 << 2) 91 #define DOC_STAT_USE_CHIPCARD (1 << 2)
92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
94 94
95class PwMDoc; 95class PwMDoc;
96class PwMView; 96class PwMView;
97class QFile; 97class QFile;
98 98
99/* meta data for a PwMDataItem */ 99/* meta data for a PwMDataItem */
100struct PwMMetaData 100struct PwMMetaData
101{ 101{
102 PwMMetaData() 102 PwMMetaData()
103 : updateInt (0) 103 : updateInt (0)
104 { } 104 { }
105 /** creation date of the PwMDataItem to which 105 /** creation date of the PwMDataItem to which
106 * this meta data belongs. 106 * this meta data belongs.
107 */ 107 */
108 QDateTimecreate; 108 QDateTimecreate;
109 /** becomes valid on this date */ 109 /** becomes valid on this date */
110 QDateTimevalid; 110 QDateTimevalid;
111 /** expire date */ 111 /** expire date */
112 QDateTimeexpire; 112 QDateTimeexpire;
113 /** update date (last updated at this date) */ 113 /** update date (last updated at this date) */
114 QDateTimeupdate; 114 QDateTimeupdate;
115 /** update interval (in minutes). Time since the 115 /** update interval (in minutes). Time since the
116 * last update to remind the user to update the item. 116 * last update to remind the user to update the item.
117 * 0 disables. 117 * 0 disables.
118 */ 118 */
119 unsigned long updateInt; 119 unsigned long updateInt;
120 120
121 //US ENH: enhancements of the filestructure 121 //US ENH: enhancements of the filestructure
122 /* each entry gets a unique id assigned */ 122 /* each entry gets a unique id assigned */
123 string uniqueid; 123 string uniqueid;
124 124
125 125
126 void clear() 126 void clear()
127 { 127 {
128 create = QDateTime(); 128 create = QDateTime();
129 expire = QDateTime(); 129 expire = QDateTime();
130 update = QDateTime(); 130 update = QDateTime();
131 updateInt = 0; 131 updateInt = 0;
132 uniqueid = KApplication::randomString(8).latin1(); 132 uniqueid = KApplication::randomString(8).latin1();
133 } 133 }
134 134
135 inline bool isValid() const 135 inline bool isValid() const
136 { 136 {
137 if (valid.isNull()) 137 if (valid.isNull())
138 return true; 138 return true;
139 return (valid < QDateTime::currentDateTime()); 139 return (valid < QDateTime::currentDateTime());
140 } 140 }
141 inline bool isExpired() const 141 inline bool isExpired() const
142 { 142 {
143 if (expire.isNull()) 143 if (expire.isNull())
144 return false; 144 return false;
145 return (expire < QDateTime::currentDateTime()); 145 return (expire < QDateTime::currentDateTime());
146 } 146 }
147 inline bool isUpdateIntOver() const 147 inline bool isUpdateIntOver() const
148 { 148 {
149 if (updateInt == 0 || 149 if (updateInt == 0 ||
150 update.isNull()) 150 update.isNull())
151 return false; 151 return false;
152 QDateTime d(update); 152 QDateTime d(update);
153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
154 } 154 }
155}; 155};
156 156
157struct PwMDataItem 157struct PwMDataItem
158{ 158{
159 PwMDataItem() 159 PwMDataItem()
160 : lockStat (true) 160 : lockStat (true)
161 , listViewPos (-1) 161 , listViewPos (-1)
162 , binary (false) 162 , binary (false)
163 , rev (0) 163 , rev (0)
164 { } 164 { }
165 165
166 /** password description */ 166 /** password description */
167 stringdesc; 167 stringdesc;
168 /** user-name */ 168 /** user-name */
169 stringname; 169 stringname;
170 /** the password itself */ 170 /** the password itself */
171 stringpw; 171 stringpw;
172 /** some comment */ 172 /** some comment */
173 stringcomment; 173 stringcomment;
174 /** an URL string */ 174 /** an URL string */
175 stringurl; 175 stringurl;
176 /** launcher. Can be executed as a system() command */ 176 /** launcher. Can be executed as a system() command */
177 stringlauncher; 177 stringlauncher;
178 /** locking status. If locked (true), pw is not emitted through getEntry() */ 178 /** locking status. If locked (true), pw is not emitted through getEntry() */
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227 227
228 //US ENH: this sync method actually copies all values from the parameter like the =operator 228 //US ENH: this sync method actually copies all values from the parameter like the =operator
229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required. 229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required.
230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) 230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true )
231 { 231 {
232 desc = a.desc; 232 desc = a.desc;
233 name = a.name; 233 name = a.name;
234 pw = a.pw; 234 pw = a.pw;
235 comment = a.comment; 235 comment = a.comment;
236 url = a.url; 236 url = a.url;
237 if (syncLauncher == true) 237 if (syncLauncher == true)
238 launcher = a.launcher; 238 launcher = a.launcher;
239 meta = a.meta; 239 meta = a.meta;
240 binary = a.binary; 240 binary = a.binary;
241 lockStat = a.lockStat; 241 lockStat = a.lockStat;
242 rev = a.rev; 242 rev = a.rev;
243 243
244 return true; 244 return true;
245 } 245 }
246 246
247}; 247};
248 248
249struct PwMCategoryItem 249struct PwMCategoryItem
250{ 250{
251 /** all PwMDataItems (all passwords) within this category */ 251 /** all PwMDataItems (all passwords) within this category */
252 vector<PwMDataItem>d; 252 vector<PwMDataItem>d;
253 /** category name/description */ 253 /** category name/description */
254 string name; 254 string name;
255 255
256 //US ENH: enhancements of the filestructure 256 //US ENH: enhancements of the filestructure
257 /* each category stores the text for description,name and password */ 257 /* each category stores the text for description,name and password */
258 string desc_text; 258 string desc_text;
259 string name_text; 259 string name_text;
260 string pw_text; 260 string pw_text;
261 261
262 void clear() 262 void clear()
263 { 263 {
264 d.clear(); 264 d.clear();
265 name = ""; 265 name = "";
266 desc_text = "Description"; 266 desc_text = "Description";
267 name_text = "Username"; 267 name_text = "Username";
268 pw_text = "Password"; 268 pw_text = "Password";
269 } 269 }
270}; 270};
271 271
272struct PwMSyncItem 272struct PwMSyncItem
273{ 273{
274 string syncName; 274 string syncName;
275 QDateTime lastSyncDate; 275 QDateTime lastSyncDate;
276 276
277 void clear() 277 void clear()
278 { 278 {
279 lastSyncDate = QDateTime(); 279 lastSyncDate = QDateTime();
280 syncName = ""; 280 syncName = "";
281 } 281 }
282}; 282};
283 283
284struct PwMItem 284struct PwMItem
285{ 285{
286 vector<PwMCategoryItem> dta; 286 vector<PwMCategoryItem> dta;
287 vector<PwMSyncItem> syncDta; 287 vector<PwMSyncItem> syncDta;
288 288
289 void clear() 289 void clear()
290 { 290 {
291 dta.clear(); 291 dta.clear();
292 syncDta.clear(); 292 syncDta.clear();
293 } 293 }
294}; 294};
295 295
296 296
297/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 297/** "Function Object" for sort()ing PwMDataItem::listViewPos */
298class dta_lvp_greater 298class dta_lvp_greater
299{ 299{
300public: 300public:
301 bool operator() (const pair<unsigned int, unsigned int> &d1, 301 bool operator() (const pair<unsigned int, unsigned int> &d1,
302 const pair<unsigned int, unsigned int> &d2) 302 const pair<unsigned int, unsigned int> &d2)
303 { 303 {
304 return d1.second > d2.second; 304 return d1.second > d2.second;
305 } 305 }
306}; 306};
307 307
308/** list of PwMDoc documents and it's IDs */ 308/** list of PwMDoc documents and it's IDs */
309class PwMDocList 309class PwMDocList
310{ 310{
311public: 311public:
312 struct listItem 312 struct listItem
313 { 313 {
314 /** document filename (known as ID, here) */ 314 /** document filename (known as ID, here) */
315 string docId; 315 string docId;
316 /** pointer to the document class */ 316 /** pointer to the document class */
317 PwMDoc *doc; 317 PwMDoc *doc;
318 }; 318 };
319 319
320 PwMDocList() {} 320 PwMDocList() {}
321 321
322 /** add a new item to the list */ 322 /** add a new item to the list */
323 void add(PwMDoc *doc, const string &id); 323 void add(PwMDoc *doc, const string &id);
324 /** changes the contents of an existing item */ 324 /** changes the contents of an existing item */
325 void edit(PwMDoc *doc, const string &newId); 325 void edit(PwMDoc *doc, const string &newId);
326 /** remove the given item */ 326 /** remove the given item */
327 void del(PwMDoc *doc); 327 void del(PwMDoc *doc);
328 /** get the item at index */ 328 /** get the item at index */
329 listItem getAt(int index) 329 listItem getAt(int index)
330 { return docList[index]; } 330 { return docList[index]; }
331 /** find an entry with this id */ 331 /** find an entry with this id */
332 bool find(const string &id, listItem *ret = 0); 332 bool find(const string &id, listItem *ret = 0);
333 /** returns a copy of the list */ 333 /** returns a copy of the list */
334 const vector<listItem>* getList() const 334 const vector<listItem>* getList() const
335 { return &docList; } 335 { return &docList; }
336 336
337 337
338 /** returns a new unique number to extend the name of 338 /** returns a new unique number to extend the name of
339 * an unnamed document. 339 * an unnamed document.
340 */ 340 */
341 static unsigned int getNewUnnamedNumber() 341 static unsigned int getNewUnnamedNumber()
342 { return unnamedDocCnt++; } 342 { return unnamedDocCnt++; }
343 343
344protected: 344protected:
345 /* Hm, I think we shouldn't really use a "list" here, should we? 345 /* Hm, I think we shouldn't really use a "list" here, should we?
346 * So I decided to actually use a vector. 346 * So I decided to actually use a vector.
347 */ 347 */
348 vector<listItem> docList; 348 vector<listItem> docList;
349 /** This value is used to get a new number for yet unnamed 349 /** This value is used to get a new number for yet unnamed
350 * documents. It is incremented on every request. So it's 350 * documents. It is incremented on every request. So it's
351 * theoretically possible to overflow it, but... :) 351 * theoretically possible to overflow it, but... :)
352 */ 352 */
353 static unsigned int unnamedDocCnt; 353 static unsigned int unnamedDocCnt;
354}; 354};
355 355
356/** implements timers for the document */ 356/** implements timers for the document */
357class DocTimer : public QObject 357class DocTimer : public QObject
358{ 358{
359 Q_OBJECT 359 Q_OBJECT
360public: 360public:
361 enum TimerIDs 361 enum TimerIDs
362 { 362 {
363 id_mpwTimer, 363 id_mpwTimer,
364 id_autoLockTimer, 364 id_autoLockTimer,
365 id_metaCheckTimer 365 id_metaCheckTimer
366 }; 366 };
367 367
368public: 368public:
369 DocTimer(PwMDoc *_doc); 369 DocTimer(PwMDoc *_doc);
370 ~DocTimer(); 370 ~DocTimer();
371 371
372 /** start the timer */ 372 /** start the timer */
373 void start(TimerIDs timer); 373 void start(TimerIDs timer);
374 /** stop the timer */ 374 /** stop the timer */
375 void stop(TimerIDs timer); 375 void stop(TimerIDs timer);
376 /** get the lock for a timer. 376 /** get the lock for a timer.
377 * This lock is a recursive lock. When a lock is 377 * This lock is a recursive lock. When a lock is
378 * held, the timer will be stopped and timeout is 378 * held, the timer will be stopped and timeout is
379 * guaranteed to not happen 379 * guaranteed to not happen
380 */ 380 */
381 void getLock(TimerIDs timer); 381 void getLock(TimerIDs timer);
382 /** put a recursive timer lock */ 382 /** put a recursive timer lock */
383 void putLock(TimerIDs timer); 383 void putLock(TimerIDs timer);
384 384
385protected slots: 385protected slots:
386 /** timeout slot for the mpw timer */ 386 /** timeout slot for the mpw timer */
387 void mpwTimeout(); 387 void mpwTimeout();
388 /** timeout slot for the autoLock timer */ 388 /** timeout slot for the autoLock timer */
389 void autoLockTimeout(); 389 void autoLockTimeout();
390 /** timeout slot for the metaCheck timer */ 390 /** timeout slot for the metaCheck timer */
391 void metaCheckTimeout(); 391 void metaCheckTimeout();
392 392
393protected: 393protected:
394 /** pointer to the document associated with this timer. */ 394 /** pointer to the document associated with this timer. */
395 PwMDoc *doc; 395 PwMDoc *doc;
396 /** timer object for mpw timer */ 396 /** timer object for mpw timer */
397 QTimer *mpwTimer; 397 QTimer *mpwTimer;
398 /** timer object for the autoLock timer */ 398 /** timer object for the autoLock timer */
399 QTimer *autoLockTimer; 399 QTimer *autoLockTimer;
400 /** timer object for the metaCheck timer */ 400 /** timer object for the metaCheck timer */
401 QTimer *metaCheckTimer; 401 QTimer *metaCheckTimer;
402 /** lock counter for the mpw timer */ 402 /** lock counter for the mpw timer */
403 unsigned int mpwLock; 403 unsigned int mpwLock;
404 /** lock counter for the autoLock timer */ 404 /** lock counter for the autoLock timer */
405 unsigned int autoLockLock; 405 unsigned int autoLockLock;
406 /** lock counter for the metaCheck timer */ 406 /** lock counter for the metaCheck timer */
407 unsigned int metaCheckLock; 407 unsigned int metaCheckLock;
408}; 408};
409 409
410/** Document class for PwM */ 410/** Document class for PwM */
411//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 411//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
412// But PwMDoc is handling the sync by itself. 412// But PwMDoc is handling the sync by itself.
413class PwMDoc : public PwMDocUi, public KSyncInterface 413class PwMDoc : public PwMDocUi, public KSyncInterface
414 414
415{ 415{
416 Q_OBJECT 416 Q_OBJECT
417 friend class DocTimer; 417 friend class DocTimer;
418 418
419public: 419public:
420 /** construtor */ 420 /** construtor */
421 PwMDoc(QObject* parent = 0, const char *name = 0); 421 PwMDoc(QObject* parent = 0, const char *name = 0);
422 /** destructor */ 422 /** destructor */
423 ~PwMDoc(); 423 ~PwMDoc();
424 424
425 /** returns a pointer to a list of all open documents */ 425 /** returns a pointer to a list of all open documents */
426 static PwMDocList* getOpenDocList() 426 static PwMDocList* getOpenDocList()
427 { return &openDocList; } 427 { return &openDocList; }
428 428
429 /** flag document dirty. dta changed */ 429 /** flag document dirty. dta changed */
430 void flagDirty() 430 void flagDirty()
431 { 431 {
432 setDocStatFlag(DOC_STAT_DISK_DIRTY); 432 setDocStatFlag(DOC_STAT_DISK_DIRTY);
433 emitDataChanged(this); 433 emitDataChanged(this);
434 } 434 }
435 /** modified? */ 435 /** modified? */
436 bool isDirty() 436 bool isDirty()
437 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 437 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
438 /** save document to disk */ 438 /** save document to disk */
439 PwMerror saveDoc(char compress, const QString *file = 0); 439 PwMerror saveDoc(char compress, const QString *file = 0);
440 /** read document from file. 440 /** read document from file.
441 * "openLocked is must be set to either of these values: 441 * "openLocked is must be set to either of these values:
442 * 0 == open with all entries unlocked 442 * 0 == open with all entries unlocked
443 * 1 == open with all entries locked 443 * 1 == open with all entries locked
444 * 2 == open deep-locked 444 * 2 == open deep-locked
445 */ 445 */
446 PwMerror openDoc(const QString *file, int openLocked); 446 PwMerror openDoc(const QString *file, int openLocked);
447 /** export document to ascii-textfile */ 447 /** export document to ascii-textfile */
448 PwMerror exportToText(const QString *file); 448 PwMerror exportToText(const QString *file);
449 /** export document to gpasman / kpasman file */ 449 /** export document to gpasman / kpasman file */
450 PwMerror exportToGpasman(const QString *file); 450 PwMerror exportToGpasman(const QString *file);
451 /** import document from ascii-textfile */ 451 /** import document from ascii-textfile */
452 PwMerror importFromText(const QString *file, int format = -1); 452 PwMerror importFromText(const QString *file, int format = -1);
453 /** import document from gpasman / kpasman file */ 453 /** import document from gpasman / kpasman file */
454 PwMerror importFromGpasman(const QString *file); 454 PwMerror importFromGpasman(const QString *file);
455 /** add new entry */ 455 /** add new entry */
456 PwMerror addEntry(const QString &category, PwMDataItem *d, 456 PwMerror addEntry(const QString &category, PwMDataItem *d,
457 bool dontFlagDirty = false, bool updateMeta = true); 457 bool dontFlagDirty = false, bool updateMeta = true);
458 /** add new category. This function doesn't flag the document dirty! */ 458 /** add new category. This function doesn't flag the document dirty! */
459 PwMerror addCategory(const QString &category, unsigned int *categoryIndex, 459 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
460 bool checkIfExist = true); 460 bool checkIfExist = true);
461 /** rename an existing category */ 461 /** rename an existing category */
462 bool renameCategory(const QString &category, const QString &newName); 462 bool renameCategory(const QString &category, const QString &newName);
463 /** rename an existing category */ 463 /** rename an existing category */
464 bool renameCategory(unsigned int category, const QString &newName, 464 bool renameCategory(unsigned int category, const QString &newName,
465 bool dontFlagDirty = false); 465 bool dontFlagDirty = false);
466 /** delete an existing category */ 466 /** delete an existing category */
467 bool delCategory(const QString &category); 467 bool delCategory(const QString &category);
468 /** delete an existing category */ 468 /** delete an existing category */
469 bool delCategory(unsigned int category, bool dontFlagDirty = false); 469 bool delCategory(unsigned int category, bool dontFlagDirty = false);
470 /** returns a list of all category-names */ 470 /** returns a list of all category-names */
471 void getCategoryList(vector<string> *list); 471 void getCategoryList(vector<string> *list);
472 /** returns a list of all category-names */ 472 /** returns a list of all category-names */
473 void getCategoryList(QStringList *list); 473 void getCategoryList(QStringList *list);
474 /** returns a list of all entry-descs in the given category */ 474 /** returns a list of all entry-descs in the given category */
475 void getEntryList(const QString &category, QStringList *list); 475 void getEntryList(const QString &category, QStringList *list);
476 /** returns a list of all entry-descs in the given category */ 476 /** returns a list of all entry-descs in the given category */
477 void getEntryList(const QString &category, vector<string> *list); 477 void getEntryList(const QString &category, vector<string> *list);
478 /** returns a list of all entry-descs in the given category */ 478 /** returns a list of all entry-descs in the given category */
479 void getEntryList(unsigned int category, vector<string> *list); 479 void getEntryList(unsigned int category, vector<string> *list);
480 /** returns a list of all entry-descs in the given category */ 480 /** returns a list of all entry-descs in the given category */
481 void getEntryList(unsigned int category, QStringList *list); 481 void getEntryList(unsigned int category, QStringList *list);
482 /** delete entry */ 482 /** delete entry */
483 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); 483 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
484 /** delete entry */ 484 /** delete entry */
485 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); 485 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
486 /** edit entry */ 486 /** edit entry */
487 bool editEntry(const QString &oldCategory, const QString &newCategory, 487 bool editEntry(const QString &oldCategory, const QString &newCategory,
488 unsigned int index, PwMDataItem *d, bool updateMeta = true); 488 unsigned int index, PwMDataItem *d, bool updateMeta = true);
489 /** edit entry */ 489 /** edit entry */
490 bool editEntry(unsigned int oldCategory, const QString &newCategory, 490 bool editEntry(unsigned int oldCategory, const QString &newCategory,
491 unsigned int index, PwMDataItem *d, bool updateMeta = true); 491 unsigned int index, PwMDataItem *d, bool updateMeta = true);
492 /** finds the category with the "name" and return it's index */ 492 /** finds the category with the "name" and return it's index */
493 bool findCategory(const QString &name, unsigned int *index); 493 bool findCategory(const QString &name, unsigned int *index);
494 /** search for an entry "find" and check while searching only for 494 /** search for an entry "find" and check while searching only for
495 * the data-fields specified by "searchIn". To set the "searchIn" 495 * the data-fields specified by "searchIn". To set the "searchIn"
496 * value, we may use one or more of the SEARCH_IN_* defines at 496 * value, we may use one or more of the SEARCH_IN_* defines at
497 * the top of this header-file. It returns the positions of all 497 * the top of this header-file. It returns the positions of all
498 * matched entries in "foundPositions". If "breakAfterFound" is true, 498 * matched entries in "foundPositions". If "breakAfterFound" is true,
499 * the function terminates after the first occurence of the entry 499 * the function terminates after the first occurence of the entry
500 * and doesn't go on searching. So foundPositions->size() is never 500 * and doesn't go on searching. So foundPositions->size() is never
501 * > 1 if breakAfterFound is true. 501 * > 1 if breakAfterFound is true.
502 */ 502 */
503 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, 503 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
504 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 504 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
505 bool caseSensitive = true, bool exactWordMatch = true, 505 bool caseSensitive = true, bool exactWordMatch = true,
506 bool sortByLvp = false); 506 bool sortByLvp = false);
507 /** see the above funtion. This function allows to set the category by name. */ 507 /** see the above funtion. This function allows to set the category by name. */
508 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, 508 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
509 vector<unsigned int> *foundPositions, bool breakAfterFound = false, 509 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
510 bool caseSensitive = true, bool exactWordMatch = true, 510 bool caseSensitive = true, bool exactWordMatch = true,
511 bool sortByLvp = false); 511 bool sortByLvp = false);
512 /** returns number of entries */ 512 /** returns number of entries */
513 unsigned int numEntries(const QString &category); 513 unsigned int numEntries(const QString &category);
514 unsigned int numEntries(unsigned int category) 514 unsigned int numEntries(unsigned int category)
515 { return dti.dta[category].d.size(); } 515 { return dti.dta[category].d.size(); }
516 /** returns number of categories */ 516 /** returns number of categories */
517 unsigned int numCategories() 517 unsigned int numCategories()
518 { return dti.dta.size(); } 518 { return dti.dta.size(); }
519 /** returns the name of the category at "index" */ 519 /** returns the name of the category at "index" */
520 const string* getCategory(unsigned int index) 520 const string* getCategory(unsigned int index)
521 { return (&(dti.dta[index].name)); } 521 { return (&(dti.dta[index].name)); }
522 522
523 /** returns the data of item at "index". 523 /** returns the data of item at "index".
524 * It unlocks the entry if it's locked and unlockIfLocked is true. 524 * It unlocks the entry if it's locked and unlockIfLocked is true.
525 * If the entry is locked, but unlockIfLocked is false, it'll not return 525 * If the entry is locked, but unlockIfLocked is false, it'll not return
526 * the pw. 526 * the pw.
527 */ 527 */
528 bool getEntry(const QString &category, unsigned int index, 528 bool getEntry(const QString &category, unsigned int index,
529 PwMDataItem *d, bool unlockIfLocked = false); 529 PwMDataItem *d, bool unlockIfLocked = false);
530 bool getEntry(unsigned int category, unsigned int index, 530 bool getEntry(unsigned int category, unsigned int index,
531 PwMDataItem *d, bool unlockIfLocked = false); 531 PwMDataItem *d, bool unlockIfLocked = false);
532 /** returns the comment-string by looking at the category 532 /** returns the comment-string by looking at the category
533 * and the listViewPos 533 * and the listViewPos
534 */ 534 */
535 PwMerror getCommentByLvp(const QString &category, int listViewPos, 535 PwMerror getCommentByLvp(const QString &category, int listViewPos,
536 string *foundComment); 536 string *foundComment);
537 PwMerror getCommentByLvp_long(const QString &category, int listViewPos, 537 PwMerror getCommentByLvp_long(const QString &category, int listViewPos,
538 string *foundComment); 538 string *foundComment);
539 /** checks if a password is already available. (currentPw) */ 539 /** checks if a password is already available. (currentPw) */
540 bool isPwAvailable() 540 bool isPwAvailable()
541 { return (currentPw != ""); } 541 { return (currentPw != ""); }
542 /** un/lock entry at "index". If needed, ask for password. */ 542 /** un/lock entry at "index". If needed, ask for password. */
543 bool lockAt(const QString &category, unsigned int index, 543 bool lockAt(const QString &category, unsigned int index,
544 bool lock = true); 544 bool lock = true);
545 bool lockAt(unsigned int category, unsigned int index, 545 bool lockAt(unsigned int category, unsigned int index,
546 bool lock = true); 546 bool lock = true);
547 /** returns the lock-status at "index" */ 547 /** returns the lock-status at "index" */
548 bool isLocked(const QString &category, unsigned int index); 548 bool isLocked(const QString &category, unsigned int index);
549 bool isLocked(unsigned int category, unsigned int index) 549 bool isLocked(unsigned int category, unsigned int index)
550 { return dti.dta[category].d[index].lockStat; } 550 { return dti.dta[category].d[index].lockStat; }
551 /** returns the deeplock status */ 551 /** returns the deeplock status */
552 bool isDeepLocked() 552 bool isDeepLocked()
553 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } 553 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
554 /** (un)lock all entries */ 554 /** (un)lock all entries */
555 bool lockAll(bool lock); 555 bool lockAll(bool lock);
556 /** unlocks all entries tempoarly. 556 /** unlocks all entries tempoarly.
557 * 1st NOTE: Be very careful with this function! :) 557 * 1st NOTE: Be very careful with this function! :)
558 * 2nd NOTE: After you have called unlockAll_Tempoary(); , 558 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
559 * please DON'T forget to call unlockAll_Tempoary(true); 559 * please DON'T forget to call unlockAll_Tempoary(true);
560 * _before_ the user (or someone else) is able to change 560 * _before_ the user (or someone else) is able to change
561 * the document! 561 * the document!
562 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary 562 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
563 * unlocked! This will cause corruption. 563 * unlocked! This will cause corruption.
564 */ 564 */
565 bool unlockAll_tempoary(bool revert = false); 565 bool unlockAll_tempoary(bool revert = false);
566 /** deep-(un)locks the document. 566 /** deep-(un)locks the document.
567 * deep-locking writes all data to the file, deletes all data 567 * deep-locking writes all data to the file, deletes all data
568 * in memory, but doesn't close the document. 568 * in memory, but doesn't close the document.
569 * deep-locking is only available, if the user previously saved 569 * deep-locking is only available, if the user previously saved
570 * the doc to a file (with a password). 570 * the doc to a file (with a password).
571 * If "saveToFile" is false, it does NOT write the data to the file! 571 * If "saveToFile" is false, it does NOT write the data to the file!
572 */ 572 */
573 PwMerror deepLock(bool lock = true, bool saveToFile = true); 573 PwMerror deepLock(bool lock = true, bool saveToFile = true);
574 /** is unlockable without pw? */ 574 /** is unlockable without pw? */
575 bool unlockWoPw() 575 bool unlockWoPw()
576 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } 576 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
577 /** get the "currentPassword" */ 577 /** get the "currentPassword" */
578 const QString& getCurrentPw() 578 const QString& getCurrentPw()
579 { return currentPw; } 579 { return currentPw; }
580 /** open a window and request the user to change the mpw */ 580 /** open a window and request the user to change the mpw */
581 void changeCurrentPw(); 581 void changeCurrentPw();
582 /** set the "listViewPos" variable of "dta" */ 582 /** set the "listViewPos" variable of "dta" */
583 void setListViewPos(const QString &category, unsigned int index, 583 void setListViewPos(const QString &category, unsigned int index,
584 int pos); 584 int pos);
585 /** set the "listViewPos" variable of "dta" */ 585 /** set the "listViewPos" variable of "dta" */
586 void setListViewPos(unsigned int category, unsigned int index, 586 void setListViewPos(unsigned int category, unsigned int index,
587 int pos); 587 int pos);
588 /** get the "listViewPos" variable of "dta" */ 588 /** get the "listViewPos" variable of "dta" */
589 int getListViewPos(const QString &category, unsigned int index); 589 int getListViewPos(const QString &category, unsigned int index);
590 /** set the maximum number of entries allowed */ 590 /** set the maximum number of entries allowed */
591 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) 591 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
592 { maxEntries = num; } 592 { maxEntries = num; }
593 /** get the maximum number of entries allowed */ 593 /** get the maximum number of entries allowed */
594 unsigned int getMaxNumEntries() 594 unsigned int getMaxNumEntries()
595 { return maxEntries; } 595 { return maxEntries; }
596 /** ensure all listViewPos of all dta items are set. (are ! -1). 596 /** ensure all listViewPos of all dta items are set. (are ! -1).
597 * If there are some undefined entries, add them to the end of 597 * If there are some undefined entries, add them to the end of
598 * the listViewPos(itions). */ 598 * the listViewPos(itions). */
599 void ensureLvp(); 599 void ensureLvp();
600 /** execute the "launcher" of this entry */ 600 /** execute the "launcher" of this entry */
601 bool execLauncher(const QString &category, unsigned int entryIndex); 601 bool execLauncher(const QString &category, unsigned int entryIndex);
602 /** see above */ 602 /** see above */
603 bool execLauncher(unsigned int category, unsigned int entryIndex); 603 bool execLauncher(unsigned int category, unsigned int entryIndex);
604 /** open a browser with the URL-section of the given entry */ 604 /** open a browser with the URL-section of the given entry */
605 bool goToURL(const QString &category, unsigned int entryIndex); 605 bool goToURL(const QString &category, unsigned int entryIndex);
606 /** see above */ 606 /** see above */
607 bool goToURL(unsigned int category, unsigned int entryIndex); 607 bool goToURL(unsigned int category, unsigned int entryIndex);
608 /** returns true if there is no entry present in the document. 608 /** returns true if there is no entry present in the document.
609 * Note: The "default" Category is present everytime, so 609 * Note: The "default" Category is present everytime, so
610 * it's checked for it's entries. 610 * it's checked for it's entries.
611 */ 611 */
612 bool isDocEmpty() 612 bool isDocEmpty()
613 { 613 {
614 if (numCategories() > 1) 614 if (numCategories() > 1)
615 return false; 615 return false;
616 if (numEntries(0)) 616 if (numEntries(0))
617 return false; 617 return false;
618 return true; 618 return true;
619 } 619 }
620 /** returns the filename of this doc */ 620 /** returns the filename of this doc */
621 const QString& getFilename() 621 const QString& getFilename()
622 { return filename; } 622 { return filename; }
623 /** returns the title of the doc */ 623 /** returns the title of the doc */
624 QString getTitle(); 624 QString getTitle();
625 /** sets the list-view-pointer hold in the doc */ 625 /** sets the list-view-pointer hold in the doc */
626 void setListViewPointer(PwMView *_listView) 626 void setListViewPointer(PwMView *_listView)
627 { listView = _listView; } 627 { listView = _listView; }
628 /** returns the list-view-pointer */ 628 /** returns the list-view-pointer */
629 PwMView * getListViewPointer() 629 PwMView * getListViewPointer()
630 { return listView; } 630 { return listView; }
631 /** try to delete the doc. The user may be asked to save 631 /** try to delete the doc. The user may be asked to save
632 * the data. The user may cancel the whole operation. 632 * the data. The user may cancel the whole operation.
633 * false is returned, then. 633 * false is returned, then.
634 */ 634 */
635 bool tryDelete(); 635 bool tryDelete();
636 /** is the doc deleted? (with tryDelete() ) */ 636 /** is the doc deleted? (with tryDelete() ) */
637 bool isDeleted() 637 bool isDeleted()
638 { return deleted; } 638 { return deleted; }
639 /** returns the document timer object */ 639 /** returns the document timer object */
640 DocTimer * timer() 640 DocTimer * timer()
641 { return _timer; } 641 { return _timer; }
642 /** get a lock on the dataChanged signal. 642 /** get a lock on the dataChanged signal.
643 * If someone is holding a lock, the signal is not emitted. 643 * If someone is holding a lock, the signal is not emitted.
644 */ 644 */
645 void getDataChangedLock() 645 void getDataChangedLock()
646 { ++dataChangedLock; } 646 { ++dataChangedLock; }
647 /** put the dataChanged lock */ 647 /** put the dataChanged lock */
648 void putDataChangedLock() 648 void putDataChangedLock()
649 { --dataChangedLock; } 649 { --dataChangedLock; }
650 /** returns the revision count of the item at cat/index */ 650 /** returns the revision count of the item at cat/index */
651 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 651 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
652 { return dti.dta[category].d[index].rev; } 652 { return dti.dta[category].d[index].rev; }
653 /** returns a const pointer to the entries meta */ 653 /** returns a const pointer to the entries meta */
654 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 654 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
655 { return &(dti.dta[category].d[index].meta); } 655 { return &(dti.dta[category].d[index].meta); }
656 /** is the entry at "category" "index" a binary entry? */ 656 /** is the entry at "category" "index" a binary entry? */
657 bool isBinEntry(unsigned int category, unsigned int index) 657 bool isBinEntry(unsigned int category, unsigned int index)
658 { return dti.dta[category].d[index].binary; } 658 { return dti.dta[category].d[index].binary; }
659 659
660public slots: 660public slots:
661 /** wrapper for PwMTray */ 661 /** wrapper for PwMTray */
662 void _deepUnlock(); 662 void _deepUnlock();
663 663
664signals: 664signals:
665 /** the data of the document has changed and must be updated 665 /** the data of the document has changed and must be updated
666 * in all views. 666 * in all views.
667 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 667 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
668 */ 668 */
669 void dataChanged(PwMDoc *document); 669 void dataChanged(PwMDoc *document);
670 /** the document class is going to close. This signal may be 670 /** the document class is going to close. This signal may be
671 * used to nofify all views, that the user closed the document, 671 * used to nofify all views, that the user closed the document,
672 * so the views can go down, too. 672 * so the views can go down, too.
673 */ 673 */
674 void docClosed(PwMDoc *document); 674 void docClosed(PwMDoc *document);
675 /** somebody just opened the document */ 675 /** somebody just opened the document */
676 void docOpened(PwMDoc *document); 676 void docOpened(PwMDoc *document);
677 /** this document object just got created */ 677 /** this document object just got created */
678 void docCreated(PwMDoc *document); 678 void docCreated(PwMDoc *document);
679 679
680public: 680public:
681 /** emit the dataChanged signal after checking for a lock */ 681 /** emit the dataChanged signal after checking for a lock */
682 void emitDataChanged(PwMDoc *document) 682 void emitDataChanged(PwMDoc *document)
683 { 683 {
684 if (!dataChangedLock) 684 if (!dataChangedLock)
685 emit dataChanged(document); 685 emit dataChanged(document);
686 } 686 }
687 687
688protected: 688protected:
689 /** current file for this doc */ 689 /** current file for this doc */
690 QString filename; 690 QString filename;
691//US ENH: we need a place where we keep the syncentries. So I invented 691//US ENH: we need a place where we keep the syncentries. So I invented
692// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem 692// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
693 /** holds all data */ 693 /** holds all data */
694 PwMItem dti; 694 PwMItem dti;
695 /** maximum number of entries */ 695 /** maximum number of entries */
696 unsigned int maxEntries; 696 unsigned int maxEntries;
697 /** currently used password to encrypt data */ 697 /** currently used password to encrypt data */
698 QString currentPw; 698 QString currentPw;
699 /** current global document status flags */ 699 /** current global document status flags */
700 unsigned int curDocStat; 700 unsigned int curDocStat;
701 /** browser process for goToURL() */ 701 /** browser process for goToURL() */
702 KProcess browserProc; 702 KProcess browserProc;
703 /** pointer to the list-view, using this document. 703 /** pointer to the list-view, using this document.
704 * As there can only be one list-view per doc, we 704 * As there can only be one list-view per doc, we
705 * don't need a list here. 705 * don't need a list here.
706 */ 706 */
707 PwMView *listView; 707 PwMView *listView;
708 /** unnamedNum is used to store the "unnamed counter" 708 /** unnamedNum is used to store the "unnamed counter"
709 * for this document, while it's unnamed. If it's 0, 709 * for this document, while it's unnamed. If it's 0,
710 * we have to get a new unique one. 710 * we have to get a new unique one.
711 */ 711 */
712 unsigned int unnamedNum; 712 unsigned int unnamedNum;
713 /** is this doc going to be deleted (executing in destructor context) */ 713 /** is this doc going to be deleted (executing in destructor context) */
714 bool deleted; 714 bool deleted;
715 /** document timer */ 715 /** document timer */
716 DocTimer *_timer; 716 DocTimer *_timer;
717 /** lock counter for the "dataChanged" signal */ 717 /** lock counter for the "dataChanged" signal */
718 unsigned int dataChangedLock; 718 unsigned int dataChangedLock;
719 719
720 /** list of all open documents */ 720 /** list of all open documents */
721 static PwMDocList openDocList; 721 static PwMDocList openDocList;
722 722
723protected: 723protected:
724 /** serialize "dta" and return it in "d". */ 724 /** serialize "dta" and return it in "d". */
725 bool serializeDta(string *d); 725 bool serializeDta(string *d);
726 /** de-serialize "d" and overwrite "dta" */ 726 /** de-serialize "d" and overwrite "dta" */
727 bool deSerializeDta(const string *d, bool entriesLocked); 727 bool deSerializeDta(const string *d, bool entriesLocked);
728 /** write header to file */ 728 /** write header to file */
729 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 729 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
730 QString *pw, QFile *f); 730 QString *pw, QFile *f);
731 /** write data-hash to file */ 731 /** write data-hash to file */
732 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 732 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
733 /** check header. Read header info and verify key-hash and filever. 733 /** check header. Read header info and verify key-hash and filever.
734 * returns length of header in "headerLength" */ 734 * returns length of header in "headerLength" */
735 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 735 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
736 unsigned int *headerLength, char *dataHashType, 736 unsigned int *headerLength, char *dataHashType,
737 string *dataHash, QFile *f); 737 string *dataHash, QFile *f);
738 /** check the data-hash */ 738 /** check the data-hash */
739 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 739 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
740 /** encrypt data "d" and write to "filename" */ 740 /** encrypt data "d" and write to "filename" */
741 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo, 741 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo,
742 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 742 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
743); 743);
744 /** read data from file beginning at "pos", decrypt and return it */ 744 /** read data from file beginning at "pos", decrypt and return it */
745 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, 745 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo,
746 char _hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase 746 char _hashalgo, //US BUG: pass _hashalgo because we need it in hashPassphrase
747QFile *f); 747QFile *f);
748 /** compress the data */ 748 /** compress the data */
749 bool compressDta(string *d, char algo); 749 bool compressDta(string *d, char algo);
750 /** uncompress the data */ 750 /** uncompress the data */
751 bool decompressDta(string *d, char algo); 751 bool decompressDta(string *d, char algo);
752 /** internal import function for a text-file generated by PwM. 752 /** internal import function for a text-file generated by PwM.
753 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 753 * If this is not a valid PwM-exported file, it returns e_fileFormat */
754 PwMerror importText_PwM(const QString *file); 754 PwMerror importText_PwM(const QString *file);
755 /** PwM-text-import helper function to extract the name/pw/comment out 755 /** PwM-text-import helper function to extract the name/pw/comment out
756 * of one entry-line */ 756 * of one entry-line */
757 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 757 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
758 /** compare two strings */ 758 /** compare two strings */
759 bool compareString(const string &s1, const string &s2, bool caseSensitive, 759 bool compareString(const string &s1, const string &s2, bool caseSensitive,
760 bool exactWordMatch); 760 bool exactWordMatch);
761 /** clears all document-data */ 761 /** clears all document-data */
762 void clearDoc(); 762 void clearDoc();
763 /** delete all empty categories */ 763 /** delete all empty categories */
764 void delAllEmptyCat(bool dontFlagDirty); 764 void delAllEmptyCat(bool dontFlagDirty);
765 /** set a document status flag */ 765 /** set a document status flag */
766 void setDocStatFlag(unsigned int statFlag) 766 void setDocStatFlag(unsigned int statFlag)
767 { curDocStat |= statFlag; } 767 { curDocStat |= statFlag; }
768 /** unset a document status flag */ 768 /** unset a document status flag */
769 void unsetDocStatFlag(unsigned int statFlag) 769 void unsetDocStatFlag(unsigned int statFlag)
770 { curDocStat &= ~statFlag; } 770 { curDocStat &= ~statFlag; }
771 /** get a document status flag */ 771 /** get a document status flag */
772 bool getDocStatFlag(unsigned int statFlag) const 772 bool getDocStatFlag(unsigned int statFlag) const
773 { return (curDocStat & statFlag); } 773 { return (curDocStat & statFlag); }
774 /** set the "currentPassword" */ 774 /** set the "currentPassword" */
775 void setCurrentPw(const QString &pw) 775 void setCurrentPw(const QString &pw)
776 { 776 {
777 currentPw = pw; 777 currentPw = pw;
778 setDocStatFlag(DOC_STAT_DISK_DIRTY); 778 setDocStatFlag(DOC_STAT_DISK_DIRTY);
779 } 779 }
780 /** make a backup-copy of the given file */ 780 /** make a backup-copy of the given file */
781 bool backupFile(const QString &filePath); 781 bool backupFile(const QString &filePath);
782 /** copy a file from src to dst */ 782 /** copy a file from src to dst */
783 bool copyFile(const QString &src, const QString &dst); 783 bool copyFile(const QString &src, const QString &dst);
784 784
785 785
786 public: 786 public:
787#ifdef PWM_EMBEDDED 787#ifdef PWM_EMBEDDED
788 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 788 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
789 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 789 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
790 790
791 //takePwMDataItem returns the following values 791 //takePwMDataItem returns the following values
792 // 0 equal 792 // 0 equal
793 // 1 take local 793 // 1 take local
794 // 2 take remote 794 // 2 take remote
795 // 3 cancel 795 // 3 cancel
796 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 796 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
797 797
798 //the following methods are the overwritten callbackmethods from the syncinterface 798 //the following methods are the overwritten callbackmethods from the syncinterface
799 virtual bool sync(KSyncManager* manager, QString filename, int mode); 799 virtual bool sync(KSyncManager* manager, QString filename, int mode, QString resource);
800 virtual void removeSyncInfo( QString syncProfile); 800 virtual void removeSyncInfo( QString syncProfile);
801 801
802#endif 802#endif
803 //US ENH: helpermethods to return a whole category entry 803 //US ENH: helpermethods to return a whole category entry
804 /** returns a pointer to the categoryitem */ 804 /** returns a pointer to the categoryitem */
805 PwMCategoryItem* getCategoryEntry(unsigned int index) 805 PwMCategoryItem* getCategoryEntry(unsigned int index)
806 { return &(dti.dta[index]); } 806 { return &(dti.dta[index]); }
807 807
808 private: 808 private:
809 //US ENH: helpermethods to access the sync data for a certain syncname. 809 //US ENH: helpermethods to access the sync data for a certain syncname.
810 // It returns the syncdatas index 810 // It returns the syncdatas index
811 bool findSyncData(const QString &syncname, unsigned int *index); 811 bool findSyncData(const QString &syncname, unsigned int *index);
812 812
813 /** add new syncdataentry */ 813 /** add new syncdataentry */
814 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 814 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
815 815
816 /** returns a pointer to the syncdata */ 816 /** returns a pointer to the syncdata */
817 PwMSyncItem* getSyncDataEntry(unsigned int index) 817 PwMSyncItem* getSyncDataEntry(unsigned int index)
818 { return &(dti.syncDta[index]); } 818 { return &(dti.syncDta[index]); }
819 819
820 /** delete entry */ 820 /** delete entry */
821 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 821 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
822 822
823 /** returns number of categories */ 823 /** returns number of categories */
824 unsigned int numSyncDataEntries() 824 unsigned int numSyncDataEntries()
825 { return dti.syncDta.size(); } 825 { return dti.syncDta.size(); }
826 826
827 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 827 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
828 828
829 QStringList getIDEntryList(); 829 QStringList getIDEntryList();
830 830
831}; 831};
832 832
833#endif 833#endif