summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index e86b3d2..9341425 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1,3681 +1,3685 @@
1/**************************************************************************** 1/****************************************************************************
2** 2**
3** Created: Sat Apr 6 17:57:45 2002 3** Created: Sat Apr 6 17:57:45 2002
4** 4**
5** Author: Carsten Schneider <CarstenSchneider@t-online.de> 5** Author: Carsten Schneider <CarstenSchneider@t-online.de>
6** 6**
7** $Id$ 7** $Id$
8** 8**
9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html 9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html
10** 10**
11** Compile Flags: 11** Compile Flags:
12** Zaurus arm : -DNO_OPIE 12** Zaurus arm : -DNO_OPIE
13** Zaurus Opie arm: none 13** Zaurus Opie arm: none
14** Linux Desktop : -DDESKTOP 14** Linux Desktop : -DDESKTOP
15** Windows Desktop: -DDESKTOP -DWIN32 15** Windows Desktop: -DDESKTOP -DWIN32
16** 16**
17****************************************************************************/ 17****************************************************************************/
18#include "zsafe.h" 18#include "zsafe.h"
19#include "newdialog.h" 19#include "newdialog.h"
20#include "searchdialog.h" 20#include "searchdialog.h"
21#include "categorydialog.h" 21#include "categorydialog.h"
22#include "passworddialog.h" 22#include "passworddialog.h"
23#include "infoform.h" 23#include "infoform.h"
24#include "zlistview.h" 24#include "zlistview.h"
25#include "shadedlistitem.h" 25#include "shadedlistitem.h"
26 26
27#ifndef DESKTOP 27#ifndef DESKTOP
28#ifndef NO_OPIE 28#ifndef NO_OPIE
29#include <opie/ofiledialog.h> 29#include <opie/ofiledialog.h>
30#else 30#else
31#include "scqtfileedit.h" 31#include "scqtfileedit.h"
32#endif 32#endif
33#endif 33#endif
34 34
35#include <qclipboard.h> 35#include <qclipboard.h>
36 36
37#include <stdio.h> 37#include <stdio.h>
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#ifndef WIN32 43#ifndef WIN32
44#include <unistd.h> 44#include <unistd.h>
45#endif 45#endif
46#include <string.h> 46#include <string.h>
47#include <errno.h> 47#include <errno.h>
48 48
49#include <qmenubar.h> 49#include <qmenubar.h>
50#include <qpopupmenu.h> 50#include <qpopupmenu.h>
51 51
52#ifdef DESKTOP 52#ifdef DESKTOP
53#include <qfiledialog.h> 53#include <qfiledialog.h>
54#ifndef WIN32 54#ifndef WIN32
55#include <qsettings.h> 55#include <qsettings.h>
56#else 56#else
57#include "qsettings.h" 57#include "qsettings.h"
58#endif 58#endif
59#include <qapplication.h> 59#include <qapplication.h>
60#else 60#else
61#include <qfile.h> 61#include <qfile.h>
62#include <qpe/fileselector.h> 62#include <qpe/fileselector.h>
63#include <qpe/global.h> 63#include <qpe/global.h>
64#include <qpe/qpeapplication.h> 64#include <qpe/qpeapplication.h>
65#include <qpe/resource.h> 65#include <qpe/resource.h>
66#include <qpe/config.h> 66#include <qpe/config.h>
67#endif 67#endif
68 68
69#include <qtimer.h> 69#include <qtimer.h>
70#include <qlayout.h> 70#include <qlayout.h>
71#include <qmessagebox.h> 71#include <qmessagebox.h>
72#include <qfile.h> 72#include <qfile.h>
73#include <qtextstream.h> 73#include <qtextstream.h>
74#include <qheader.h> 74#include <qheader.h>
75#include <qlistview.h> 75#include <qlistview.h>
76#include <qtoolbutton.h> 76#include <qtoolbutton.h>
77#include <qlayout.h> 77#include <qlayout.h>
78#include <qvariant.h> 78#include <qvariant.h>
79#include <qtooltip.h> 79#include <qtooltip.h>
80#include <qwhatsthis.h> 80#include <qwhatsthis.h>
81#include <qimage.h> 81#include <qimage.h>
82#include <qpixmap.h> 82#include <qpixmap.h>
83#include <qlineedit.h> 83#include <qlineedit.h>
84#include <qmultilineedit.h> 84#include <qmultilineedit.h>
85#include <qregexp.h> 85#include <qregexp.h>
86#include <qdir.h> 86#include <qdir.h>
87#include <qtextbrowser.h> 87#include <qtextbrowser.h>
88#include <qlabel.h> 88#include <qlabel.h>
89#include <qcombobox.h> 89#include <qcombobox.h>
90 90
91#include "krc2.h" 91#include "krc2.h"
92 92
93#include "wait.h" 93#include "wait.h"
94 94
95extern int DeskW, DeskH; 95extern int DeskW, DeskH;
96#ifdef DESKTOP 96#ifdef DESKTOP
97extern QApplication *appl; 97extern QApplication *appl;
98#else 98#else
99extern QPEApplication *appl; 99extern QPEApplication *appl;
100#endif 100#endif
101 101
102 102
103#ifdef DESKTOP 103#ifdef DESKTOP
104#ifndef WIN32 104#ifndef WIN32
105const QString APP_KEY="/.zsafe/"; 105const QString APP_KEY="/.zsafe/";
106#else 106#else
107const QString APP_KEY=""; 107const QString APP_KEY="";
108#endif 108#endif
109#else 109#else
110const QString APP_KEY=""; 110const QString APP_KEY="";
111#endif 111#endif
112 112
113// include xmp images 113// include xmp images
114#include "pics/zsafe/copy.xpm" 114#include "pics/zsafe/copy.xpm"
115#include "pics/zsafe/cut.xpm" 115#include "pics/zsafe/cut.xpm"
116#include "pics/zsafe/edit.xpm" 116#include "pics/zsafe/edit.xpm"
117#include "pics/zsafe/editdelete.xpm" 117#include "pics/zsafe/editdelete.xpm"
118#include "pics/zsafe/find.xpm" 118#include "pics/zsafe/find.xpm"
119#include "pics/zsafe/folder_open.xpm" 119#include "pics/zsafe/folder_open.xpm"
120#include "pics/zsafe/help_icon.xpm" 120#include "pics/zsafe/help_icon.xpm"
121#include "pics/zsafe/new.xpm" 121#include "pics/zsafe/new.xpm"
122#include "pics/zsafe/paste.xpm" 122#include "pics/zsafe/paste.xpm"
123#include "pics/zsafe/quit_icon.xpm" 123#include "pics/zsafe/quit_icon.xpm"
124#include "pics/zsafe/save.xpm" 124#include "pics/zsafe/save.xpm"
125#include "pics/zsafe/trash.xpm" 125#include "pics/zsafe/trash.xpm"
126#include "pics/zsafe/expand.xpm" 126#include "pics/zsafe/expand.xpm"
127#include "pics/zsafe/export.xpm" 127#include "pics/zsafe/export.xpm"
128#include "pics/zsafe/import.xpm" 128#include "pics/zsafe/import.xpm"
129#include "pics/zsafe/zsafe.xpm" 129#include "pics/zsafe/zsafe.xpm"
130 130
131static const char* const bank_cards_data[] = { 131static const char* const bank_cards_data[] = {
132"14 14 16 1", 132"14 14 16 1",
133". c None", 133". c None",
134"# c #000000", 134"# c #000000",
135"b c #0000de", 135"b c #0000de",
136"a c #0000e6", 136"a c #0000e6",
137"j c #41de83", 137"j c #41de83",
138"k c #4acecd", 138"k c #4acecd",
139"h c #4aced5", 139"h c #4aced5",
140"g c #5a40cd", 140"g c #5a40cd",
141"d c #5a44d5", 141"d c #5a44d5",
142"l c #9440d5", 142"l c #9440d5",
143"m c #b4ce4a", 143"m c #b4ce4a",
144"n c #cd4883", 144"n c #cd4883",
145"e c #d5ae10", 145"e c #d5ae10",
146"f c #de3ce6", 146"f c #de3ce6",
147"i c #e640e6", 147"i c #e640e6",
148"c c #ffffff", 148"c c #ffffff",
149"..............", 149"..............",
150".###########..", 150".###########..",
151".#ababababa#..", 151".#ababababa#..",
152".#babbbabbb#..", 152".#babbbabbb#..",
153".#ccccccccc#..", 153".#ccccccccc#..",
154".#cdcefcghc#..", 154".#cdcefcghc#..",
155".#ccccccccc#..", 155".#ccccccccc#..",
156".#cicjkclic#..", 156".#cicjkclic#..",
157".#ccccccccc#..", 157".#ccccccccc#..",
158".#cmchlcnec#..", 158".#cmchlcnec#..",
159".#ccccccccc#..", 159".#ccccccccc#..",
160".###########..", 160".###########..",
161"..............", 161"..............",
162".............."}; 162".............."};
163 163
164 164
165static const char* const passwords_data[] = { 165static const char* const passwords_data[] = {
166"16 16 20 1", 166"16 16 20 1",
167". c None", 167". c None",
168"# c #000000", 168"# c #000000",
169"r c #000083", 169"r c #000083",
170"p c #0000c5", 170"p c #0000c5",
171"q c #0000ff", 171"q c #0000ff",
172"n c #008100", 172"n c #008100",
173"l c #00c200", 173"l c #00c200",
174"m c #00ff00", 174"m c #00ff00",
175"j c #838100", 175"j c #838100",
176"a c #c55900", 176"a c #c55900",
177"h c #c5c200", 177"h c #c5c200",
178"o c #c5c2ff", 178"o c #c5c2ff",
179"k c #c5ffc5", 179"k c #c5ffc5",
180"f c #ff0000", 180"f c #ff0000",
181"d c #ff8100", 181"d c #ff8100",
182"b c #ffaa5a", 182"b c #ffaa5a",
183"e c #ffc2c5", 183"e c #ffc2c5",
184"c c #ffdeac", 184"c c #ffdeac",
185"i c #ffff00", 185"i c #ffff00",
186"g c #ffffc5", 186"g c #ffffc5",
187"............###.", 187"............###.",
188"...........#abb#", 188"...........#abb#",
189"..........#cbab#", 189"..........#cbab#",
190".........#cbdd#.", 190".........#cbdd#.",
191"######..#cbdd#..", 191"######..#cbdd#..",
192"#eeff#..#add#...", 192"#eeff#..#add#...",
193"#eeff#######....", 193"#eeff#######....",
194"#ccdbdd#........", 194"#ccdbdd#........",
195"#dddbdd###......", 195"#dddbdd###......",
196"#gghihhjj#......", 196"#gghihhjj#......",
197"#hhhihhjj###....", 197"#hhhihhjj###....",
198"#kklmllnnnn#....", 198"#kklmllnnnn#....",
199"#lllmllnnnn#....", 199"#lllmllnnnn#....",
200"#oopqpprprr#....", 200"#oopqpprprr#....",
201"#oopqpprprr#....", 201"#oopqpprprr#....",
202"############...."}; 202"############...."};
203 203
204static const char* const software_data[] = { 204static const char* const software_data[] = {
205"16 16 5 1", 205"16 16 5 1",
206". c None", 206". c None",
207"# c #000000", 207"# c #000000",
208"b c #838183", 208"b c #838183",
209"c c #c5ffff", 209"c c #c5ffff",
210"a c #ffffff", 210"a c #ffffff",
211"................", 211"................",
212".##############.", 212".##############.",
213"#aaaaaaaaaaaaaa#", 213"#aaaaaaaaaaaaaa#",
214"#abbbbbbbbbbbbb#", 214"#abbbbbbbbbbbbb#",
215"#ab##########ab#", 215"#ab##########ab#",
216"#ab#c########ab#", 216"#ab#c########ab#",
217"#ab#c#c######ab#", 217"#ab#c#c######ab#",
218"#ab##########ab#", 218"#ab##########ab#",
219"#ab##########ab#", 219"#ab##########ab#",
220"#ab##########ab#", 220"#ab##########ab#",
221"#ab##########ab#", 221"#ab##########ab#",
222"#ab##########ab#", 222"#ab##########ab#",
223"#aaaaaaaaaaaaab#", 223"#aaaaaaaaaaaaab#",
224"#bbbbbbbbbbbbbb#", 224"#bbbbbbbbbbbbbb#",
225".##############.", 225".##############.",
226"................"}; 226"................"};
227 227
228static const char* const general_data[] = { 228static const char* const general_data[] = {
229"14 14 98 2", 229"14 14 98 2",
230"Qt c None", 230"Qt c None",
231".k c #000000", 231".k c #000000",
232"#x c #080808", 232"#x c #080808",
233"#F c #101008", 233"#F c #101008",
234"#q c #101010", 234"#q c #101010",
235"#i c #101410", 235"#i c #101410",
236"## c #101810", 236"## c #101810",
237".m c #181818", 237".m c #181818",
238".3 c #181c18", 238".3 c #181c18",
239".I c #182018", 239".I c #182018",
240".T c #202420", 240".T c #202420",
241"#D c #202820", 241"#D c #202820",
242"#y c #292c29", 242"#y c #292c29",
243".c c #293029", 243".c c #293029",
244".d c #313031", 244".d c #313031",
245"#E c #313429", 245"#E c #313429",
246"#r c #313831", 246"#r c #313831",
247".j c #393c31", 247".j c #393c31",
248"#j c #394039", 248"#j c #394039",
249"#C c #414841", 249"#C c #414841",
250".w c #4a554a", 250".w c #4a554a",
251".a c #4a594a", 251".a c #4a594a",
252".# c #525052", 252".# c #525052",
253".l c #52594a", 253".l c #52594a",
254"#f c #525952", 254"#f c #525952",
255"#v c #525d52", 255"#v c #525d52",
256".O c #5a4c4a", 256".O c #5a4c4a",
257".9 c #5a595a", 257".9 c #5a595a",
258".A c #5a5d52", 258".A c #5a5d52",
259".B c #624c52", 259".B c #624c52",
260".0 c #625552", 260".0 c #625552",
261"#o c #626562", 261"#o c #626562",
262".R c #626962", 262".R c #626962",
263"#. c #626d5a", 263"#. c #626d5a",
264"#p c #626d62", 264"#p c #626d62",
265".2 c #627162", 265".2 c #627162",
266"#h c #6a6d62", 266"#h c #6a6d62",
267"#z c #6a7562", 267"#z c #6a7562",
268"#w c #6a756a", 268"#w c #6a756a",
269".C c #73656a", 269".C c #73656a",
270".P c #73696a", 270".P c #73696a",
271"#a c #737d6a", 271"#a c #737d6a",
272".U c #738573", 272".U c #738573",
273".E c #7b817b", 273".E c #7b817b",
274"#B c #7b857b", 274"#B c #7b857b",
275"#s c #7b897b", 275"#s c #7b897b",
276"#n c #7b917b", 276"#n c #7b917b",
277".b c #838d83", 277".b c #838d83",
278".7 c #839583", 278".7 c #839583",
279".n c #8b7d7b", 279".n c #8b7d7b",
280"#g c #8b8583", 280"#g c #8b8583",
281".g c #8b858b", 281".g c #8b858b",
282".r c #8b898b", 282".r c #8b898b",
283".s c #8b8d8b", 283".s c #8b8d8b",
284".i c #8b9183", 284".i c #8b9183",
285".8 c #8b918b", 285".8 c #8b918b",
286"#A c #8b9d8b", 286"#A c #8b9d8b",
287".S c #8ba183", 287".S c #8ba183",
288".Z c #94918b", 288".Z c #94918b",
289".N c #949994", 289".N c #949994",
290".F c #949d94", 290".F c #949d94",
291".x c #94a18b", 291".x c #94a18b",
292".v c #94a194", 292".v c #94a194",
293".Y c #94aa94", 293".Y c #94aa94",
294".h c #9c999c", 294".h c #9c999c",
295".Q c #9ca19c", 295".Q c #9ca19c",
296"#u c #9ca59c", 296"#u c #9ca59c",
297".H c #9caa9c", 297".H c #9caa9c",
298"#e c #9cb29c", 298"#e c #9cb29c",
299"#m c #a4b29c", 299"#m c #a4b29c",
300"#t c #a4b2a4", 300"#t c #a4b2a4",
301".M c #a4b69c", 301".M c #a4b69c",
302"#l c #a4b6a4", 302"#l c #a4b6a4",
303".z c #a4baa4", 303".z c #a4baa4",
304".f c #aca5ac", 304".f c #aca5ac",
305".q c #acaaac", 305".q c #acaaac",
306"#d c #acbeac", 306"#d c #acbeac",
307".6 c #acc2ac", 307".6 c #acc2ac",
308".o c #b4b2b4", 308".o c #b4b2b4",
309".t c #b4beb4", 309".t c #b4beb4",
310"#k c #b4c2ac", 310"#k c #b4c2ac",
311".5 c #b4cab4", 311".5 c #b4cab4",
312".D c #bdb6bd", 312".D c #bdb6bd",
313".G c #bdc6b4", 313".G c #bdc6b4",
314"#c c #bdceb4", 314"#c c #bdceb4",
315".X c #bdd2bd", 315".X c #bdd2bd",
316".4 c #bdd6bd", 316".4 c #bdd6bd",
317".1 c #c5bec5", 317".1 c #c5bec5",
318".e c #c5c2c5", 318".e c #c5c2c5",
319".u c #c5cac5", 319".u c #c5cac5",
320"#b c #c5d6c5", 320"#b c #c5d6c5",
321".J c #c5dec5", 321".J c #c5dec5",
322".p c #cdcacd", 322".p c #cdcacd",
323".W c #cddecd", 323".W c #cddecd",
324".L c #cde2cd", 324".L c #cde2cd",
325".K c #d5eacd", 325".K c #d5eacd",
326".V c #d5ead5", 326".V c #d5ead5",
327".y c #d5eed5", 327".y c #d5eed5",
328"QtQtQtQtQtQtQtQtQtQtQtQtQtQt", 328"QtQtQtQtQtQtQtQtQtQtQtQtQtQt",
329"QtQtQt.#.a.b.cQtQtQtQtQtQtQt", 329"QtQtQt.#.a.b.cQtQtQtQtQtQtQt",
330"QtQt.d.e.f.g.h.i.c.j.dQt.kQt", 330"QtQt.d.e.f.g.h.i.c.j.dQt.kQt",
331".a.l.m.n.o.p.q.r.s.t.u.v.wQt", 331".a.l.m.n.o.p.q.r.s.t.u.v.wQt",
332".x.y.z.A.B.C.D.p.q.E.F.G.H.I", 332".x.y.z.A.B.C.D.p.q.E.F.G.H.I",
333".I.J.K.L.M.N.O.P.o.p.Q.R.S.T", 333".I.J.K.L.M.N.O.P.o.p.Q.R.S.T",
334"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3", 334"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3",
335"Qt.3.X.W.4.X.5.6.7.8.9.s#.##", 335"Qt.3.X.W.4.X.5.6.7.8.9.s#.##",
336"QtQt#a.X#b#c.5.6#d#e#f#g#h#i", 336"QtQt#a.X#b#c.5.6#d#e#f#g#h#i",
337"QtQtQt#j.7#k.6#d#l#m#n#o#p#q", 337"QtQtQt#j.7#k.6#d#l#m#n#o#p#q",
338"QtQtQtQt.k#r#s#m#t.H#u#v#w#x", 338"QtQtQtQt.k#r#s#m#t.H#u#v#w#x",
339"QtQtQtQtQtQt.k#y#z.v#A#B#C#x", 339"QtQtQtQtQtQt.k#y#z.v#A#B#C#x",
340"QtQtQtQtQtQtQtQt.k#D.w#s#E.k", 340"QtQtQtQtQtQtQtQt.k#D.w#s#E.k",
341"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; 341"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"};
342 342
343// exit ZSafe and clear the clipboard for security reasons 343// exit ZSafe and clear the clipboard for security reasons
344 void ZSafe::exitZs (int ec) 344 void ZSafe::exitZs (int ec)
345 { 345 {
346 QClipboard *cb = QApplication::clipboard(); 346 QClipboard *cb = QApplication::clipboard();
347 cb->clear(); 347 cb->clear();
348 348
349 exit (ec); 349 exit (ec);
350 } 350 }
351 351
352 352
353// save the configuration into the file 353// save the configuration into the file
354 void ZSafe::saveConf () 354 void ZSafe::saveConf ()
355 { 355 {
356 if (conf) 356 if (conf)
357 { 357 {
358 delete conf; 358 delete conf;
359 359
360#ifdef DESKTOP 360#ifdef DESKTOP
361#ifndef WIN32 361#ifndef WIN32
362 conf = new QSettings (); 362 conf = new QSettings ();
363 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 363 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
364#else 364#else
365 conf = new QSettings (cfgFile); 365 conf = new QSettings (cfgFile);
366 conf->insertSearchPath (QSettings::Unix, cfgFile); 366 conf->insertSearchPath (QSettings::Unix, cfgFile);
367#endif 367#endif
368#else 368#else
369 conf = new Config (cfgFile, Config::File); 369 conf = new Config (cfgFile, Config::File);
370 conf->setGroup ("zsafe"); 370 conf->setGroup ("zsafe");
371#endif 371#endif
372 } 372 }
373 } 373 }
374 374
375 375
376/* 376/*
377 * Constructs a ZSafe which is a child of 'parent', with the 377 * Constructs a ZSafe which is a child of 'parent', with the
378 * name 'name' and widget flags set to 'f' 378 * name 'name' and widget flags set to 'f'
379 * 379 *
380 * The dialog will by default be modeless, unless you set 'modal' to 380 * The dialog will by default be modeless, unless you set 'modal' to
381 * TRUE to construct a modal dialog. 381 * TRUE to construct a modal dialog.
382 */ 382 */
383ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) 383ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
384 : QDialog( parent, name, modal, fl ) 384 : QDialog( parent, name, modal, fl )
385{ 385{
386 IsCut = false; 386 IsCut = false;
387 IsCopy = false; 387 IsCopy = false;
388 modified = false; 388 modified = false;
389 389
390 // set the config file 390 // set the config file
391 cfgFile=QDir::homeDirPath(); 391 cfgFile=QDir::homeDirPath();
392 cfgFile += "/.zsafe.cfg"; 392 cfgFile += "/.zsafe.cfg";
393 // set the icon path 393 // set the icon path
394 QString qpedir ((const char *)getenv("QPEDIR")); 394 QString qpedir ((const char *)getenv("QPEDIR"));
395#ifdef DESKTOP 395#ifdef DESKTOP
396 iconPath = QDir::homeDirPath() + "/pics/"; 396 iconPath = QDir::homeDirPath() + "/pics/";
397#else 397#else
398 if (qpedir.isEmpty()) 398 if (qpedir.isEmpty())
399 iconPath = "/home/QtPalmtop/pics/"; 399 iconPath = "/home/QtPalmtop/pics/";
400 else 400 else
401 iconPath = qpedir + "/pics/"; 401 iconPath = qpedir + "/pics/";
402#endif 402#endif
403 403
404 // create a zsafe configuration object 404 // create a zsafe configuration object
405#ifdef DESKTOP 405#ifdef DESKTOP
406#ifndef WIN32 406#ifndef WIN32
407 conf = new QSettings (); 407 conf = new QSettings ();
408 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 408 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
409#else 409#else
410 conf = new QSettings (cfgFile); 410 conf = new QSettings (cfgFile);
411 conf->insertSearchPath (QSettings::Unix, cfgFile); 411 conf->insertSearchPath (QSettings::Unix, cfgFile);
412#endif 412#endif
413#else 413#else
414 conf = new Config (cfgFile, Config::File); 414 conf = new Config (cfgFile, Config::File);
415 conf->setGroup ("zsafePrefs"); 415 conf->setGroup ("zsafePrefs");
416#endif 416#endif
417#ifdef DESKTOP 417#ifdef DESKTOP
418// #ifndef WIN32 418// #ifndef WIN32
419 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); 419 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false);
420// #endif 420// #endif
421#else 421#else
422 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); 422 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0);
423#endif 423#endif
424#ifndef DESKTOP 424#ifndef DESKTOP
425 conf->setGroup ("zsafe"); 425 conf->setGroup ("zsafe");
426#endif 426#endif
427 427
428 QPixmap copy_img((const char**) copy_xpm); 428 QPixmap copy_img((const char**) copy_xpm);
429 QPixmap cut_img((const char**) cut_xpm); 429 QPixmap cut_img((const char**) cut_xpm);
430 QPixmap edit_img((const char**) edit_xpm); 430 QPixmap edit_img((const char**) edit_xpm);
431 QPixmap editdelete_img((const char**) editdelete_xpm); 431 QPixmap editdelete_img((const char**) editdelete_xpm);
432 QPixmap find_img((const char**) find_xpm); 432 QPixmap find_img((const char**) find_xpm);
433 QPixmap folder_open_img((const char**) folder_open_xpm); 433 QPixmap folder_open_img((const char**) folder_open_xpm);
434 QPixmap help_icon_img((const char**) help_icon_xpm); 434 QPixmap help_icon_img((const char**) help_icon_xpm);
435 QPixmap new_img((const char**) new_xpm); 435 QPixmap new_img((const char**) new_xpm);
436 QPixmap paste_img((const char**) paste_xpm); 436 QPixmap paste_img((const char**) paste_xpm);
437 QPixmap quit_icon_img((const char**) quit_icon_xpm); 437 QPixmap quit_icon_img((const char**) quit_icon_xpm);
438 QPixmap save_img((const char**) save_xpm); 438 QPixmap save_img((const char**) save_xpm);
439 QPixmap trash_img((const char**) trash_xpm); 439 QPixmap trash_img((const char**) trash_xpm);
440 QPixmap expand_img((const char**) expand_xpm); 440 QPixmap expand_img((const char**) expand_xpm);
441 QPixmap export_img((const char**) export_xpm); 441 QPixmap export_img((const char**) export_xpm);
442 QPixmap import_img((const char**) import_xpm); 442 QPixmap import_img((const char**) import_xpm);
443 443
444 QPixmap bank_cards( ( const char** ) bank_cards_data ); 444 QPixmap bank_cards( ( const char** ) bank_cards_data );
445 QPixmap passwords( ( const char** ) passwords_data ); 445 QPixmap passwords( ( const char** ) passwords_data );
446 QPixmap software( ( const char** ) software_data ); 446 QPixmap software( ( const char** ) software_data );
447 QPixmap general( ( const char** ) general_data ); 447 QPixmap general( ( const char** ) general_data );
448 if ( !name ) 448 if ( !name )
449 setName( "ZSafe" ); 449 setName( "ZSafe" );
450 450
451#ifdef DESKTOP 451#ifdef DESKTOP
452#ifdef WIN32 452#ifdef WIN32
453 setGeometry(100, 150, DeskW, DeskH-30 ); 453 setGeometry(100, 150, DeskW, DeskH-30 );
454#else 454#else
455 resize( DeskW, DeskH-30 ); 455 resize( DeskW, DeskH-30 );
456#endif 456#endif
457 // setMinimumSize( QSize( DeskW, DeskH-30 ) ); 457 // setMinimumSize( QSize( DeskW, DeskH-30 ) );
458 // setMaximumSize( QSize( DeskW, DeskH-30 ) ); 458 // setMaximumSize( QSize( DeskW, DeskH-30 ) );
459#else 459#else
460 resize( DeskW, DeskH-30 ); 460 resize( DeskW, DeskH-30 );
461 // setMinimumSize( QSize( DeskW, DeskH-30 ) ); 461 // setMinimumSize( QSize( DeskW, DeskH-30 ) );
462 // setMaximumSize( QSize( 440, 290 ) ); 462 // setMaximumSize( QSize( 440, 290 ) );
463 // setMaximumSize( QSize( DeskW+400, DeskH+200 ) ); 463 // setMaximumSize( QSize( DeskW+400, DeskH+200 ) );
464#endif 464#endif
465 // setCaption( tr( "ZSafe" ) ); 465 // setCaption( tr( "ZSafe" ) );
466 466
467 filename = conf->readEntry(APP_KEY+"document"); 467 filename = conf->readEntry(APP_KEY+"document");
468 if (filename.isEmpty() || filename.isNull()) 468 if (filename.isEmpty() || filename.isNull())
469 { 469 {
470 470
471 // check if the directory application exists, if not 471 // check if the directory application exists, if not
472 // create it 472 // create it
473// #ifndef WIN32 473// #ifndef WIN32
474 // QString d1("Documents/application"); 474 // QString d1("Documents/application");
475// #else 475// #else
476 QString d1(QDir::homeDirPath() + "/Documents/application"); 476 QString d1(QDir::homeDirPath() + "/Documents/application");
477// #endif 477// #endif
478 QDir pd1(d1); 478 QDir pd1(d1);
479 if (!pd1.exists()) 479 if (!pd1.exists())
480 { 480 {
481 QDir pd1("Documents"); 481 QDir pd1("Documents");
482 if (!pd1.mkdir("application", FALSE)) 482 if (!pd1.mkdir("application", FALSE))
483 { 483 {
484 QMessageBox::critical( 0, tr("ZSafe"), 484 QMessageBox::critical( 0, tr("ZSafe"),
485 tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1)); 485 tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d1));
486 exitZs (1); 486 exitZs (1);
487 } 487 }
488 } 488 }
489// #ifndef WIN32 489// #ifndef WIN32
490 // QString d2("Documents/application/zsafe"); 490 // QString d2("Documents/application/zsafe");
491// #else 491// #else
492 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); 492 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
493// #endif 493// #endif
494 QDir pd2(d2); 494 QDir pd2(d2);
495 if (!pd2.exists()) 495 if (!pd2.exists())
496 { 496 {
497 QDir pd2("Documents/application"); 497 QDir pd2("Documents/application");
498 if (!pd2.mkdir("zsafe", FALSE)) 498 if (!pd2.mkdir("zsafe", FALSE))
499 { 499 {
500 QMessageBox::critical( 0, tr("ZSafe"), 500 QMessageBox::critical( 0, tr("ZSafe"),
501 tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2)); 501 tr("Can't create directory\n%1\n\nZSafe will now exit.").arg(d2));
502 exitZs (1); 502 exitZs (1);
503 } 503 }
504 } 504 }
505 505
506 506
507 // set the default filename 507 // set the default filename
508 filename=d2 + "/passwords.zsf"; 508 filename=d2 + "/passwords.zsf";
509 509
510 // save the current filename to the config file 510 // save the current filename to the config file
511 conf->writeEntry(APP_KEY+"document", filename); 511 conf->writeEntry(APP_KEY+"document", filename);
512 saveConf(); 512 saveConf();
513 } 513 }
514 514
515 //if (filename == "INVALIDPWD") 515 //if (filename == "INVALIDPWD")
516 //filename = ""; 516 //filename = "";
517 517
518 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 518 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
519#ifdef WIN32 519#ifdef WIN32
520 this->setCaption("Qt ZSafe: " + ti); 520 this->setCaption("Qt ZSafe: " + ti);
521#else 521#else
522 this->setCaption("ZSafe: " + ti); 522 this->setCaption("ZSafe: " + ti);
523#endif 523#endif
524 524
525 selectedItem = NULL; 525 selectedItem = NULL;
526 lastSearchedCategory = NULL; 526 lastSearchedCategory = NULL;
527 lastSearchedItem = NULL; 527 lastSearchedItem = NULL;
528 lastSearchedName = ""; 528 lastSearchedName = "";
529 lastSearchedUsername = ""; 529 lastSearchedUsername = "";
530 lastSearchedComment = ""; 530 lastSearchedComment = "";
531 531
532 infoForm = new InfoForm(); 532 infoForm = new InfoForm();
533 categoryDialog = NULL; 533 categoryDialog = NULL;
534 534
535 // add a menu bar 535 // add a menu bar
536 QMenuBar *menu = new QMenuBar( this ); 536 QMenuBar *menu = new QMenuBar( this );
537 537
538 // add file menu 538 // add file menu
539 // QPopupMenu *file = new QPopupMenu( this ); 539 // QPopupMenu *file = new QPopupMenu( this );
540 file = new QPopupMenu( this ); 540 file = new QPopupMenu( this );
541 541
542// #ifdef DESKTOP 542// #ifdef DESKTOP
543 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); 543 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) );
544 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); 544 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) );
545 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); 545 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) );
546 file->insertSeparator(); 546 file->insertSeparator();
547// #endif 547// #endif
548 548
549 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); 549 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) );
550 file->insertItem( save_img, tr("S&ave document with new Password"), this, 550 file->insertItem( save_img, tr("S&ave document with new Password"), this,
551 SLOT(saveDocumentWithPwd()) ); 551 SLOT(saveDocumentWithPwd()) );
552 file->insertSeparator(); 552 file->insertSeparator();
553 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); 553 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) );
554 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); 554 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) );
555 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); 555 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) );
556 file->insertSeparator(); 556 file->insertSeparator();
557 file->insertItem( expand_img, tr("&Open entries expanded"), this, 557 file->insertItem( expand_img, tr("&Open entries expanded"), this,
558 SLOT(setExpandFlag()), 0, 'o'); 558 SLOT(setExpandFlag()), 0, 'o');
559 file->setItemChecked('o', expandTree); 559 file->setItemChecked('o', expandTree);
560 file->insertSeparator(); 560 file->insertSeparator();
561 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); 561 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) );
562 menu->insertItem( tr("&File"), file ); 562 menu->insertItem( tr("&File"), file );
563 563
564 QPopupMenu *cat = new QPopupMenu( this ); 564 QPopupMenu *cat = new QPopupMenu( this );
565 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); 565 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) );
566 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); 566 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) );
567 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); 567 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) );
568 menu->insertItem( tr("&Category"), cat ); 568 menu->insertItem( tr("&Category"), cat );
569 569
570 QPopupMenu *it = new QPopupMenu( this ); 570 QPopupMenu *it = new QPopupMenu( this );
571 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); 571 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) );
572 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); 572 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) );
573 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); 573 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) );
574 it->insertSeparator(); 574 it->insertSeparator();
575 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); 575 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) );
576 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); 576 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) );
577 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); 577 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) );
578 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); 578 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) );
579 menu->insertItem( tr("&Entry"), it ); 579 menu->insertItem( tr("&Entry"), it );
580 580
581 QPopupMenu *help = new QPopupMenu( this ); 581 QPopupMenu *help = new QPopupMenu( this );
582 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); 582 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) );
583 menu->insertItem( tr("&Help"), help ); 583 menu->insertItem( tr("&Help"), help );
584 584
585 // toolbar icons 585 // toolbar icons
586 586
587 New = new QToolButton( menu, "New" ); 587 New = new QToolButton( menu, "New" );
588 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); 588 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) );
589 New->setMouseTracking( TRUE ); 589 New->setMouseTracking( TRUE );
590 New->setText( tr( "" ) ); 590 New->setText( tr( "" ) );
591 New->setPixmap( new_img ); 591 New->setPixmap( new_img );
592 QToolTip::add( New, tr( "New entry" ) ); 592 QToolTip::add( New, tr( "New entry" ) );
593 593
594 Edit = new QToolButton( menu, "Edit" ); 594 Edit = new QToolButton( menu, "Edit" );
595 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); 595 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) );
596 Edit->setText( tr( "" ) ); 596 Edit->setText( tr( "" ) );
597 Edit->setPixmap( edit_img ); 597 Edit->setPixmap( edit_img );
598 QToolTip::add( Edit, tr( "Edit category or entry" ) ); 598 QToolTip::add( Edit, tr( "Edit category or entry" ) );
599 599
600 Delete = new QToolButton( menu, "Delete" ); 600 Delete = new QToolButton( menu, "Delete" );
601 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 601 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
602 Delete->setText( tr( "" ) ); 602 Delete->setText( tr( "" ) );
603 Delete->setPixmap( trash_img ); 603 Delete->setPixmap( trash_img );
604 QToolTip::add( Delete, tr( "Delete category or entry" ) ); 604 QToolTip::add( Delete, tr( "Delete category or entry" ) );
605 605
606 Find = new QToolButton( menu, "Find" ); 606 Find = new QToolButton( menu, "Find" );
607 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); 607 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) );
608 Find->setText( tr( "" ) ); 608 Find->setText( tr( "" ) );
609 Find->setPixmap( find_img ); 609 Find->setPixmap( find_img );
610 QToolTip::add( Find, tr( "Find entry" ) ); 610 QToolTip::add( Find, tr( "Find entry" ) );
611 611
612/* 612/*
613 QBoxLayout * h = new QHBoxLayout( this ); 613 QBoxLayout * h = new QHBoxLayout( this );
614 h->addWidget (menu); 614 h->addWidget (menu);
615 h->addWidget (New); 615 h->addWidget (New);
616 h->addWidget (Edit); 616 h->addWidget (Edit);
617 h->addWidget (Delete); 617 h->addWidget (Delete);
618 h->addWidget (Find); 618 h->addWidget (Find);
619*/ 619*/
620 620
621 ListView = new ZListView( this, "ListView" ); 621 ListView = new ZListView( this, "ListView" );
622 ListView->addColumn( tr( "Name" ) ); 622 ListView->addColumn( tr( "Name" ) );
623 ListView->addColumn( tr( "Field 2" ) ); 623 ListView->addColumn( tr( "Field 2" ) );
624 ListView->addColumn( tr( "Field 3" ) ); 624 ListView->addColumn( tr( "Field 3" ) );
625 ListView->addColumn( tr( "Comment" ) ); 625 ListView->addColumn( tr( "Comment" ) );
626 ListView->addColumn( tr( "Field 4" ) ); 626 ListView->addColumn( tr( "Field 4" ) );
627 ListView->addColumn( tr( "Field 5" ) ); 627 ListView->addColumn( tr( "Field 5" ) );
628 ListView->setAllColumnsShowFocus(TRUE); 628 ListView->setAllColumnsShowFocus(TRUE);
629 629
630#ifdef DESKTOP 630#ifdef DESKTOP
631 ListView->setResizePolicy(QScrollView::AutoOneFit); 631 ListView->setResizePolicy(QScrollView::AutoOneFit);
632 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); 632 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) );
633#else 633#else
634 ListView->setResizePolicy(QScrollView::AutoOneFit); 634 ListView->setResizePolicy(QScrollView::AutoOneFit);
635 // ListView->setGeometry( QRect( 0, 22, 635 // ListView->setGeometry( QRect( 0, 22,
636 // this->width(), this->height() - 30 ) ); 636 // this->width(), this->height() - 30 ) );
637 // ListView->setMaximumSize( QSize( 440, 290 ) ); 637 // ListView->setMaximumSize( QSize( 440, 290 ) );
638#endif 638#endif
639 ListView->setVScrollBarMode( QListView::Auto ); 639 ListView->setVScrollBarMode( QListView::Auto );
640 640
641 QBoxLayout * l = new QVBoxLayout( this ); 641 QBoxLayout * l = new QVBoxLayout( this );
642 l->addWidget (menu); 642 l->addWidget (menu);
643 l->addWidget (ListView); 643 l->addWidget (ListView);
644 644
645#ifndef DESKTOP 645#ifndef DESKTOP
646 // start a timer (100 ms) to load the default document 646 // start a timer (100 ms) to load the default document
647 docuTimer.start( 100, true ); 647 docuTimer.start( 100, true );
648 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); 648 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) );
649 raiseFlag = true; 649 raiseFlag = true;
650 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); 650 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) );
651#else 651#else
652 // open the default document 652 // open the default document
653 openDocument(filename); 653 openDocument(filename);
654#endif 654#endif
655 655
656 // signals and slots connections for QTollButton 656 // signals and slots connections for QTollButton
657 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); 657 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) );
658 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); 658 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) );
659 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); 659 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) );
660 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); 660 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) );
661 // signals and slots connections for QListView 661 // signals and slots connections for QListView
662 connect( ListView, SIGNAL( selectionChanged( QListViewItem* ) ), 662 connect( ListView, SIGNAL( selectionChanged( QListViewItem* ) ),
663 this, SLOT( listViewSelected( QListViewItem* ) ) ); 663 this, SLOT( listViewSelected( QListViewItem* ) ) );
664 connect( ListView, SIGNAL( doubleClicked( QListViewItem* ) ), 664 connect( ListView, SIGNAL( doubleClicked( QListViewItem* ) ),
665 this, SLOT( showInfo( QListViewItem* ) ) ); 665 this, SLOT( showInfo( QListViewItem* ) ) );
666 connect( ListView, SIGNAL( returnPressed( QListViewItem* ) ), 666 connect( ListView, SIGNAL( returnPressed( QListViewItem* ) ),
667 this, SLOT( showInfo( QListViewItem* ) ) ); 667 this, SLOT( showInfo( QListViewItem* ) ) );
668 668
669} 669}
670 670
671const QColor *ZSafe::evenRowColor = &Qt::white; 671const QColor *ZSafe::evenRowColor = &Qt::white;
672// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 672// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
673const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 673const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
674 674
675/* 675/*
676 * Destroys the object and frees any allocated resources 676 * Destroys the object and frees any allocated resources
677 */ 677 */
678ZSafe::~ZSafe() 678ZSafe::~ZSafe()
679{ 679{
680 // no need to delete child widgets, Qt does it all for us 680 // no need to delete child widgets, Qt does it all for us
681 quitMe(); 681 quitMe();
682} 682}
683 683
684// load the default document 684// load the default document
685void ZSafe::slotLoadDocu() 685void ZSafe::slotLoadDocu()
686{ 686{
687 openDocument (filename); 687 openDocument (filename);
688} 688}
689 689
690void ZSafe::deletePwd() 690void ZSafe::deletePwd()
691{ 691{
692 692
693 if (!selectedItem) 693 if (!selectedItem)
694 return; 694 return;
695 if (!isCategory(selectedItem)) 695 if (!isCategory(selectedItem))
696 { 696 {
697 switch( QMessageBox::information( this, tr("ZSafe"), 697 switch( QMessageBox::information( this, tr("ZSafe"),
698 tr("Do you want to delete?"), 698 tr("Do you want to delete?"),
699 tr("&Delete"), tr("D&on't Delete"), 699 tr("&Delete"), tr("D&on't Delete"),
700 0 // Enter == button 0 700 0 // Enter == button 0
701 ) ) { // Escape == button 2 701 ) ) { // Escape == button 2
702 case 0: // Delete clicked, Alt-S or Enter pressed. 702 case 0: // Delete clicked, Alt-S or Enter pressed.
703 // Delete 703 // Delete
704 modified = true; 704 modified = true;
705 selectedItem->parent()->takeItem(selectedItem); 705 selectedItem->parent()->takeItem(selectedItem);
706 selectedItem = NULL; 706 selectedItem = NULL;
707 break; 707 break;
708 case 1: // Don't delete 708 case 1: // Don't delete
709 break; 709 break;
710 } 710 }
711 } 711 }
712 else 712 else
713 { 713 {
714 delCategory(); 714 delCategory();
715 } 715 }
716} 716}
717 717
718void ZSafe::editPwd() 718void ZSafe::editPwd()
719{ 719{
720 if (!selectedItem) 720 if (!selectedItem)
721 return; 721 return;
722 if (!isCategory(selectedItem)) 722 if (!isCategory(selectedItem))
723 { 723 {
724 // open the 'New Entry' dialog 724 // open the 'New Entry' dialog
725 NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE); 725 NewDialog *dialog = new NewDialog(this, tr("Edit Entry"), TRUE);
726#ifdef WIN32 726#ifdef WIN32
727 dialog->setCaption ("Qt " + tr("Edit Entry")); 727 dialog->setCaption ("Qt " + tr("Edit Entry"));
728 dialog->setGeometry(200, 250, 220, 310 ); 728 dialog->setGeometry(200, 250, 220, 310 );
729#endif 729#endif
730 730
731 // set the labels 731 // set the labels
732 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 732 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
733 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 733 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
734 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 734 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
735 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 735 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
736 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 736 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
737 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 737 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
738 738
739 // set the fields 739 // set the fields
740 dialog->NameField->setText(selectedItem->text (0)); 740 dialog->NameField->setText(selectedItem->text (0));
741 dialog->UsernameField->setText(selectedItem->text (1)); 741 dialog->UsernameField->setText(selectedItem->text (1));
742 dialog->PasswordField->setText(selectedItem->text (2)); 742 dialog->PasswordField->setText(selectedItem->text (2));
743 QString comment = selectedItem->text (3); 743 QString comment = selectedItem->text (3);
744 comment.replace (QRegExp("<br>"), "\n"); 744 comment.replace (QRegExp("<br>"), "\n");
745 dialog->Field5->setText(selectedItem->text (4)); 745 dialog->Field5->setText(selectedItem->text (4));
746 dialog->Field6->setText(selectedItem->text (5)); 746 dialog->Field6->setText(selectedItem->text (5));
747 dialog->CommentField->insertLine(comment); 747 dialog->CommentField->insertLine(comment);
748 dialog->CommentField->setCursorPosition(0,0); 748 dialog->CommentField->setCursorPosition(0,0);
749#ifdef DESKTOP 749#ifdef DESKTOP
750#ifndef WIN32 750#ifndef WIN32
751 dialog->show(); 751 dialog->show();
752#endif 752#endif
753#else 753#else
754 dialog->showMaximized(); 754 dialog->showMaximized();
755#endif 755#endif
756 DialogCode result = (DialogCode) dialog->exec(); 756 DialogCode result = (DialogCode) dialog->exec();
757 757
758#ifdef DESKTOP 758#ifdef DESKTOP
759 result = Accepted; 759 result = Accepted;
760#endif 760#endif
761 if (result == Accepted) 761 if (result == Accepted)
762 { 762 {
763 modified = true; 763 modified = true;
764 // edit the selected item 764 // edit the selected item
765 QString name = dialog->NameField->text(); 765 QString name = dialog->NameField->text();
766 selectedItem->setText (0, tr (name)); 766 selectedItem->setText (0, tr (name));
767 QString user = dialog->UsernameField->text(); 767 QString user = dialog->UsernameField->text();
768 selectedItem->setText (1, tr (user)); 768 selectedItem->setText (1, tr (user));
769 QString pwd = dialog->PasswordField->text(); 769 QString pwd = dialog->PasswordField->text();
770 selectedItem->setText (2, tr (pwd)); 770 selectedItem->setText (2, tr (pwd));
771 QString comment = dialog->CommentField->text(); 771 QString comment = dialog->CommentField->text();
772 comment.replace (QRegExp("\n"), "<br>"); 772 comment.replace (QRegExp("\n"), "<br>");
773 selectedItem->setText (3, tr (comment)); 773 selectedItem->setText (3, tr (comment));
774 QString f5 = dialog->Field5->text(); 774 QString f5 = dialog->Field5->text();
775 selectedItem->setText (4, tr (f5)); 775 selectedItem->setText (4, tr (f5));
776 QString f6 = dialog->Field6->text(); 776 QString f6 = dialog->Field6->text();
777 selectedItem->setText (5, tr (f6)); 777 selectedItem->setText (5, tr (f6));
778 } 778 }
779 779
780 delete dialog; 780 delete dialog;
781 } 781 }
782 else 782 else
783 { 783 {
784 editCategory(); 784 editCategory();
785 } 785 }
786} 786}
787 787
788void ZSafe::newPwd() 788void ZSafe::newPwd()
789{ 789{
790 if (!selectedItem) 790 if (!selectedItem)
791 return; 791 return;
792 792
793 if (!isCategory(selectedItem)) 793 if (!isCategory(selectedItem))
794 selectedItem = selectedItem->parent(); 794 selectedItem = selectedItem->parent();
795 795
796 if (isCategory(selectedItem)) 796 if (isCategory(selectedItem))
797 { 797 {
798 QString cat = selectedItem->text(0); 798 QString cat = selectedItem->text(0);
799 799
800 // open the 'New Entry' dialog 800 // open the 'New Entry' dialog
801 NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE); 801 NewDialog *dialog = new NewDialog(this, tr("New Entry"), TRUE);
802#ifdef WIN32 802#ifdef WIN32
803 dialog->setCaption ("Qt " + tr("New Entry")); 803 dialog->setCaption ("Qt " + tr("New Entry"));
804 dialog->setGeometry(200, 250, 220, 310 ); 804 dialog->setGeometry(200, 250, 220, 310 );
805#endif 805#endif
806 // set the labels 806 // set the labels
807 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 807 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
808 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 808 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
809 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 809 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
810 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 810 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
811 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 811 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
812 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 812 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
813retype: 813retype:
814#ifdef DESKTOP 814#ifdef DESKTOP
815#ifndef WIN32 815#ifndef WIN32
816 dialog->show(); 816 dialog->show();
817#endif 817#endif
818#else 818#else
819 dialog->showMaximized(); 819 dialog->showMaximized();
820#endif 820#endif
821 DialogCode result = (DialogCode) dialog->exec(); 821 DialogCode result = (DialogCode) dialog->exec();
822#ifdef DESKTOP 822#ifdef DESKTOP
823 result = Accepted; 823 result = Accepted;
824#endif 824#endif
825 825
826 if (result == Accepted) 826 if (result == Accepted)
827 { 827 {
828 828
829 QString name = dialog->NameField->text(); 829 QString name = dialog->NameField->text();
830 if (cat == name) 830 if (cat == name)
831 { 831 {
832 QMessageBox::critical( 0, tr("ZSafe"), 832 QMessageBox::critical( 0, tr("ZSafe"),
833 tr("Entry name must be different\nfrom the category name.") ); 833 tr("Entry name must be different\nfrom the category name.") );
834 goto retype; // it's not a good programming style :-) 834 goto retype; // it's not a good programming style :-)
835 } 835 }
836 836
837 modified = true; 837 modified = true;
838 // add the new item 838 // add the new item
839 QListViewItem *i = new ShadedListItem (0, selectedItem); 839 QListViewItem *i = new ShadedListItem (0, selectedItem);
840 i->setOpen (TRUE); 840 i->setOpen (TRUE);
841 841
842 i->setText (0, tr (name)); 842 i->setText (0, tr (name));
843 QString user = dialog->UsernameField->text(); 843 QString user = dialog->UsernameField->text();
844 i->setText (1, tr (user)); 844 i->setText (1, tr (user));
845 QString pwd = dialog->PasswordField->text(); 845 QString pwd = dialog->PasswordField->text();
846 i->setText (2, tr (pwd)); 846 i->setText (2, tr (pwd));
847 QString comment = dialog->CommentField->text(); 847 QString comment = dialog->CommentField->text();
848 comment.replace (QRegExp("\n"), "<br>"); 848 comment.replace (QRegExp("\n"), "<br>");
849 i->setText (3, tr (comment)); 849 i->setText (3, tr (comment));
850 QString f5 = dialog->Field5->text(); 850 QString f5 = dialog->Field5->text();
851 i->setText (4, tr (f5)); 851 i->setText (4, tr (f5));
852 QString f6 = dialog->Field6->text(); 852 QString f6 = dialog->Field6->text();
853 i->setText (5, tr (f6)); 853 i->setText (5, tr (f6));
854 } 854 }
855 855
856 delete dialog; 856 delete dialog;
857 } 857 }
858} 858}
859 859
860void ZSafe::findPwd() 860void ZSafe::findPwd()
861{ 861{
862 862
863 // open the 'Search' dialog 863 // open the 'Search' dialog
864 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 864 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
865#ifdef WIN32 865#ifdef WIN32
866 dialog->setCaption ("Qt " + tr("Search")); 866 dialog->setCaption ("Qt " + tr("Search"));
867#endif 867#endif
868 868
869#ifdef DESKTOP 869#ifdef DESKTOP
870#endif 870#endif
871 if (lastSearchedName) 871 if (lastSearchedName)
872 dialog->NameField->setText(lastSearchedName); 872 dialog->NameField->setText(lastSearchedName);
873 else 873 else
874 dialog->NameField->setText(""); 874 dialog->NameField->setText("");
875 if (lastSearchedUsername) 875 if (lastSearchedUsername)
876 dialog->UsernameField->setText(lastSearchedUsername); 876 dialog->UsernameField->setText(lastSearchedUsername);
877 else 877 else
878 dialog->UsernameField->setText(""); 878 dialog->UsernameField->setText("");
879 if (lastSearchedComment) 879 if (lastSearchedComment)
880 dialog->CommentField->setText(lastSearchedComment); 880 dialog->CommentField->setText(lastSearchedComment);
881 else 881 else
882 dialog->CommentField->setText(""); 882 dialog->CommentField->setText("");
883 DialogCode result = (DialogCode) dialog->exec(); 883 DialogCode result = (DialogCode) dialog->exec();
884#ifdef DESKTOP 884#ifdef DESKTOP
885 result = Accepted; 885 result = Accepted;
886#endif 886#endif
887 887
888 QString name; 888 QString name;
889 QString username; 889 QString username;
890 QString comment; 890 QString comment;
891 if (result == Accepted) 891 if (result == Accepted)
892 { 892 {
893 name = dialog->NameField->text(); 893 name = dialog->NameField->text();
894 username = dialog->UsernameField->text(); 894 username = dialog->UsernameField->text();
895 comment = dialog->CommentField->text(); 895 comment = dialog->CommentField->text();
896 qWarning (name); 896 qWarning (name);
897 } 897 }
898 else 898 else
899 { 899 {
900 delete dialog; 900 delete dialog;
901 return; 901 return;
902 } 902 }
903 903
904 if (!name.isEmpty() && name != lastSearchedName || 904 if (!name.isEmpty() && name != lastSearchedName ||
905 lastSearchedName.isEmpty() && !name.isEmpty()) 905 lastSearchedName.isEmpty() && !name.isEmpty())
906 { 906 {
907 // set search at the beginning if a new name is given 907 // set search at the beginning if a new name is given
908 lastSearchedCategory = NULL; 908 lastSearchedCategory = NULL;
909 lastSearchedItem = NULL; 909 lastSearchedItem = NULL;
910 } 910 }
911 lastSearchedName = name; 911 lastSearchedName = name;
912 if (!username.isEmpty() && username != lastSearchedUsername || 912 if (!username.isEmpty() && username != lastSearchedUsername ||
913 lastSearchedUsername.isEmpty() && !username.isEmpty()) 913 lastSearchedUsername.isEmpty() && !username.isEmpty())
914 { 914 {
915 // set search at the beginning if a new name is given 915 // set search at the beginning if a new name is given
916 lastSearchedCategory = NULL; 916 lastSearchedCategory = NULL;
917 lastSearchedItem = NULL; 917 lastSearchedItem = NULL;
918 } 918 }
919 lastSearchedUsername = username; 919 lastSearchedUsername = username;
920 if (!comment.isEmpty() && comment != lastSearchedComment || 920 if (!comment.isEmpty() && comment != lastSearchedComment ||
921 lastSearchedComment.isEmpty() && !comment.isEmpty()) 921 lastSearchedComment.isEmpty() && !comment.isEmpty())
922 { 922 {
923 // set search at the beginning if a new name is given 923 // set search at the beginning if a new name is given
924 lastSearchedCategory = NULL; 924 lastSearchedCategory = NULL;
925 lastSearchedItem = NULL; 925 lastSearchedItem = NULL;
926 } 926 }
927 lastSearchedComment = comment; 927 lastSearchedComment = comment;
928 928
929 ListView->clearSelection(); 929 ListView->clearSelection();
930 930
931 bool found=FALSE; 931 bool found=FALSE;
932 // step through all categories 932 // step through all categories
933 QListViewItem *i; 933 QListViewItem *i;
934 if (lastSearchedCategory) 934 if (lastSearchedCategory)
935 i = lastSearchedCategory; 935 i = lastSearchedCategory;
936 else 936 else
937 i = ListView->firstChild(); 937 i = ListView->firstChild();
938 for (; 938 for (;
939 i != NULL; 939 i != NULL;
940 i = i->nextSibling()) 940 i = i->nextSibling())
941 { 941 {
942 qWarning (i->text(0)); 942 qWarning (i->text(0));
943 i->setSelected(FALSE); 943 i->setSelected(FALSE);
944 944
945 // step through all subitems 945 // step through all subitems
946 QListViewItem *si; 946 QListViewItem *si;
947 if (lastSearchedItem) 947 if (lastSearchedItem)
948 si = lastSearchedItem; 948 si = lastSearchedItem;
949 else 949 else
950 si = i->firstChild(); 950 si = i->firstChild();
951 // for (si = i->firstChild(); 951 // for (si = i->firstChild();
952 for (; 952 for (;
953 si != NULL; 953 si != NULL;
954 si = si->nextSibling()) 954 si = si->nextSibling())
955 { 955 {
956 qWarning (si->text(0)); 956 qWarning (si->text(0));
957 if (si->isSelected()) 957 if (si->isSelected())
958 si->setSelected(FALSE); 958 si->setSelected(FALSE);
959 // ListView->repaintItem(si); 959 // ListView->repaintItem(si);
960 960
961 bool n=TRUE; 961 bool n=TRUE;
962 bool u=TRUE; 962 bool u=TRUE;
963 bool c=TRUE; 963 bool c=TRUE;
964 if (!name.isEmpty()) 964 if (!name.isEmpty())
965 n = (si->text(0)).contains (name, FALSE); 965 n = (si->text(0)).contains (name, FALSE);
966 if (!username.isEmpty()) 966 if (!username.isEmpty())
967 u = (si->text(1)).contains (username, FALSE); 967 u = (si->text(1)).contains (username, FALSE);
968 if (!comment.isEmpty()) 968 if (!comment.isEmpty())
969 c = (si->text(3)).contains (comment, FALSE); 969 c = (si->text(3)).contains (comment, FALSE);
970 970
971 if ((n && u && c ) && !found) 971 if ((n && u && c ) && !found)
972 { 972 {
973 qWarning ("Found"); 973 qWarning ("Found");
974 selectedItem = si; 974 selectedItem = si;
975 si->setSelected(TRUE); 975 si->setSelected(TRUE);
976 ListView->setCurrentItem(si); 976 ListView->setCurrentItem(si);
977 ListView->ensureItemVisible(si); 977 ListView->ensureItemVisible(si);
978 ListView->triggerUpdate(); 978 ListView->triggerUpdate();
979 979
980 lastSearchedCategory = i; 980 lastSearchedCategory = i;
981 // set to the next item 981 // set to the next item
982 lastSearchedItem = si->nextSibling(); 982 lastSearchedItem = si->nextSibling();
983 if (!lastSearchedItem) 983 if (!lastSearchedItem)
984 { 984 {
985 // no next item within category -> set next category 985 // no next item within category -> set next category
986 lastSearchedCategory = i->nextSibling(); 986 lastSearchedCategory = i->nextSibling();
987 if (!lastSearchedCategory) 987 if (!lastSearchedCategory)
988 lastSearchedItem = NULL; // END 988 lastSearchedItem = NULL; // END
989 } 989 }
990 990
991 found = TRUE; 991 found = TRUE;
992 delete dialog; 992 delete dialog;
993 update(); 993 update();
994 return; 994 return;
995 } 995 }
996 } 996 }
997 lastSearchedCategory = i->nextSibling(); 997 lastSearchedCategory = i->nextSibling();
998 lastSearchedItem = NULL; 998 lastSearchedItem = NULL;
999 } 999 }
1000 lastSearchedCategory = NULL; 1000 lastSearchedCategory = NULL;
1001 lastSearchedItem = NULL; 1001 lastSearchedItem = NULL;
1002 delete dialog; 1002 delete dialog;
1003 update(); 1003 update();
1004 QMessageBox::information( this, tr("ZSafe"), 1004 QMessageBox::information( this, tr("ZSafe"),
1005 tr("Entry not found"), tr("&OK"), 0); 1005 tr("Entry not found"), tr("&OK"), 0);
1006 1006
1007} 1007}
1008 1008
1009QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1009QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1010{ 1010{
1011 QString category; 1011 QString category;
1012 if (_item) 1012 if (_item)
1013 { 1013 {
1014 if (isCategory(_item)) 1014 if (isCategory(_item))
1015 { 1015 {
1016 category = _item->text(0); 1016 category = _item->text(0);
1017 } 1017 }
1018 else 1018 else
1019 { 1019 {
1020 QListViewItem *cat = _item->parent(); 1020 QListViewItem *cat = _item->parent();
1021 category = cat->text(0); 1021 category = cat->text(0);
1022 } 1022 }
1023 } 1023 }
1024 else 1024 else
1025 { 1025 {
1026 return def; 1026 return def;
1027 } 1027 }
1028 1028
1029 QString app_key = APP_KEY; 1029 QString app_key = APP_KEY;
1030#ifndef DESKTOP 1030#ifndef DESKTOP
1031#ifndef WIN32 1031#ifndef WIN32
1032 conf->setGroup ("fieldDefs"); 1032 conf->setGroup ("fieldDefs");
1033#endif 1033#endif
1034#else 1034#else
1035#ifndef WIN32 1035#ifndef WIN32
1036 app_key += "/fieldDefs/"; 1036 app_key += "/fieldDefs/";
1037#endif 1037#endif
1038#endif 1038#endif
1039// #ifndef WIN32 1039// #ifndef WIN32
1040 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1040 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1041// #else 1041// #else
1042// QString label(def); 1042// QString label(def);
1043// #endif 1043// #endif
1044 1044
1045#ifndef DESKTOP 1045#ifndef DESKTOP
1046 conf->setGroup ("zsafe"); 1046 conf->setGroup ("zsafe");
1047#endif 1047#endif
1048 return label; 1048 return label;
1049} 1049}
1050 1050
1051QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1051QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1052{ 1052{
1053 QString app_key = APP_KEY; 1053 QString app_key = APP_KEY;
1054#ifndef DESKTOP 1054#ifndef DESKTOP
1055 conf->setGroup ("fieldDefs"); 1055 conf->setGroup ("fieldDefs");
1056#else 1056#else
1057#ifndef WIN32 1057#ifndef WIN32
1058 app_key += "/fieldDefs/"; 1058 app_key += "/fieldDefs/";
1059#endif 1059#endif
1060#endif 1060#endif
1061// #ifndef WIN32 1061// #ifndef WIN32
1062 QString label = conf->readEntry(app_key+category+"-field"+field, 1062 QString label = conf->readEntry(app_key+category+"-field"+field,
1063 def); 1063 def);
1064// #else 1064// #else
1065 // QString label(def); 1065 // QString label(def);
1066// #endif 1066// #endif
1067#ifndef DESKTOP 1067#ifndef DESKTOP
1068 conf->setGroup ("zsafe"); 1068 conf->setGroup ("zsafe");
1069#endif 1069#endif
1070 return label; 1070 return label;
1071} 1071}
1072 1072
1073void ZSafe::showInfo( QListViewItem *_item) 1073void ZSafe::showInfo( QListViewItem *_item)
1074{ 1074{
1075 if (!_item) 1075 if (!_item)
1076 return; 1076 return;
1077 if (selectedItem != NULL) 1077 if (selectedItem != NULL)
1078 selectedItem->setSelected(FALSE); 1078 selectedItem->setSelected(FALSE);
1079 1079
1080 selectedItem = _item; 1080 selectedItem = _item;
1081 selectedItem->setSelected(TRUE); 1081 selectedItem->setSelected(TRUE);
1082 1082
1083 if (!isCategory(_item)) 1083 if (!isCategory(_item))
1084 { 1084 {
1085/* 1085/*
1086 QString label=selectedItem->text(0); 1086 QString label=selectedItem->text(0);
1087 label+="\n"; 1087 label+="\n";
1088 label+=selectedItem->text(1); 1088 label+=selectedItem->text(1);
1089 label+="\n"; 1089 label+="\n";
1090 label+=selectedItem->text(2); 1090 label+=selectedItem->text(2);
1091 label+="\n"; 1091 label+="\n";
1092 label+=selectedItem->text(3); 1092 label+=selectedItem->text(3);
1093*/ 1093*/
1094 1094
1095 QString text; 1095 QString text;
1096 QString entry; 1096 QString entry;
1097 1097
1098 text = "<html><body><div align=""center""><u><b>"; 1098 text = "<html><body><div align=""center""><u><b>";
1099 text += selectedItem->text(0); 1099 text += selectedItem->text(0);
1100 text += "</b></u><br></div><br>"; 1100 text += "</b></u><br></div><br>";
1101 1101
1102 entry = selectedItem->text(1); 1102 entry = selectedItem->text(1);
1103 if (!entry.isEmpty() && entry.compare(" ")) 1103 if (!entry.isEmpty() && entry.compare(" "))
1104 { 1104 {
1105 text += "<u><b>"; 1105 text += "<u><b>";
1106 text += getFieldLabel (selectedItem, "2", tr("Username")); 1106 text += getFieldLabel (selectedItem, "2", tr("Username"));
1107 text += ":<br></b></u><blockquote>"; 1107 text += ":<br></b></u><blockquote>";
1108 text += entry; 1108 text += entry;
1109 text += "</blockquote>"; 1109 text += "</blockquote>";
1110 // text += "<br>"; 1110 // text += "<br>";
1111 } 1111 }
1112 1112
1113 entry = selectedItem->text(2); 1113 entry = selectedItem->text(2);
1114 if (!entry.isEmpty() && entry.compare(" ")) 1114 if (!entry.isEmpty() && entry.compare(" "))
1115 { 1115 {
1116 text += "<u><b>"; 1116 text += "<u><b>";
1117 text += getFieldLabel (selectedItem, "3", tr("Password")); 1117 text += getFieldLabel (selectedItem, "3", tr("Password"));
1118 text += ":<br> </b></u><blockquote>"; 1118 text += ":<br> </b></u><blockquote>";
1119 text += entry; 1119 text += entry;
1120 text += "</blockquote>"; 1120 text += "</blockquote>";
1121 // text += "<br>"; 1121 // text += "<br>";
1122 } 1122 }
1123 1123
1124 entry = selectedItem->text(4); 1124 entry = selectedItem->text(4);
1125 if (!entry.isEmpty() && entry.compare(" ")) 1125 if (!entry.isEmpty() && entry.compare(" "))
1126 { 1126 {
1127 text += "<u><b>"; 1127 text += "<u><b>";
1128 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1128 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1129 text += ":<br> </b></u><blockquote>"; 1129 text += ":<br> </b></u><blockquote>";
1130 text += entry; 1130 text += entry;
1131 text += "</blockquote>"; 1131 text += "</blockquote>";
1132 // text += "<br>"; 1132 // text += "<br>";
1133 } 1133 }
1134 1134
1135 entry = selectedItem->text(5); 1135 entry = selectedItem->text(5);
1136 if (!entry.isEmpty() && entry.compare(" ")) 1136 if (!entry.isEmpty() && entry.compare(" "))
1137 { 1137 {
1138 text += "<u><b>"; 1138 text += "<u><b>";
1139 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1139 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1140 text += ":<br> </b></u><blockquote>"; 1140 text += ":<br> </b></u><blockquote>";
1141 text += entry; 1141 text += entry;
1142 text += "</blockquote>"; 1142 text += "</blockquote>";
1143 // text += "<br>"; 1143 // text += "<br>";
1144 } 1144 }
1145 1145
1146 entry = selectedItem->text(3); 1146 entry = selectedItem->text(3);
1147 if (!entry.isEmpty() && entry.compare(" ")) 1147 if (!entry.isEmpty() && entry.compare(" "))
1148 { 1148 {
1149 text += "<u><b>"; 1149 text += "<u><b>";
1150 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1150 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1151 text += ":<br> </b></u>"; 1151 text += ":<br> </b></u>";
1152 QString comment = selectedItem->text(3); 1152 QString comment = selectedItem->text(3);
1153 comment.replace (QRegExp("\n"), "<br>"); 1153 comment.replace (QRegExp("\n"), "<br>");
1154 text += comment; 1154 text += comment;
1155 // text += "<br>"; 1155 // text += "<br>";
1156 } 1156 }
1157 1157
1158 text += "</body></html>"; 1158 text += "</body></html>";
1159 1159
1160 infoForm->InfoText->setText(text); 1160 infoForm->InfoText->setText(text);
1161 infoForm->hide(); 1161 infoForm->hide();
1162#ifdef DESKTOP 1162#ifdef DESKTOP
1163 infoForm->show(); 1163 infoForm->show();
1164#else 1164#else
1165 infoForm->showMaximized(); 1165 infoForm->showMaximized();
1166#endif 1166#endif
1167 1167
1168 } 1168 }
1169} 1169}
1170 1170
1171void ZSafe::listViewSelected( QListViewItem *_item) 1171void ZSafe::listViewSelected( QListViewItem *_item)
1172{ 1172{
1173 if (!_item) 1173 if (!_item)
1174 return; 1174 return;
1175 if (selectedItem != NULL) 1175 if (selectedItem != NULL)
1176 selectedItem->setSelected(FALSE); 1176 selectedItem->setSelected(FALSE);
1177 1177
1178 selectedItem = _item; 1178 selectedItem = _item;
1179 1179
1180#ifndef DESKTOP 1180#ifndef DESKTOP
1181 // set the column text dependent on the selected item 1181 // set the column text dependent on the selected item
1182 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1182 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1183 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1183 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1184 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1184 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1185 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1185 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1186 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1186 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1187 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1187 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1188#endif 1188#endif
1189#ifdef WIN32 1189#ifdef WIN32
1190 // set the column text dependent on the selected item 1190 // set the column text dependent on the selected item
1191 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1191 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1192 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1192 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1193 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1193 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1194 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1194 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1195 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1195 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1196 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1196 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1197#endif 1197#endif
1198 1198
1199} 1199}
1200 1200
1201bool ZSafe::isCategory(QListViewItem *_item) 1201bool ZSafe::isCategory(QListViewItem *_item)
1202{ 1202{
1203 if (_item == NULL) 1203 if (_item == NULL)
1204 return FALSE; 1204 return FALSE;
1205 1205
1206 QString categoryName = _item->text (0); 1206 QString categoryName = _item->text (0);
1207 if (categories.find ((const char *)categoryName)) 1207 if (categories.find ((const char *)categoryName))
1208 return TRUE; 1208 return TRUE;
1209 else 1209 else
1210 return FALSE; 1210 return FALSE;
1211} 1211}
1212 1212
1213void ZSafe::removeAsciiFile() 1213void ZSafe::removeAsciiFile()
1214{ 1214{
1215 // QString fn = filename + ".txt"; 1215 // QString fn = filename + ".txt";
1216 // open the file dialog 1216 // open the file dialog
1217#ifndef DESKTOP 1217#ifndef DESKTOP
1218#ifndef NO_OPIE 1218#ifndef NO_OPIE
1219 QMap<QString, QStringList> mimeTypes; 1219 QMap<QString, QStringList> mimeTypes;
1220 mimeTypes.insert(tr("All"), QStringList() ); 1220 mimeTypes.insert(tr("All"), QStringList() );
1221 mimeTypes.insert(tr("Text"), "text/*" ); 1221 mimeTypes.insert(tr("Text"), "text/*" );
1222 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1222 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1223 QDir::homeDirPath() + "/Documents/application/zsafe", 1223 QDir::homeDirPath() + "/Documents/application/zsafe",
1224 QString::null, 1224 QString::null,
1225 mimeTypes, 1225 mimeTypes,
1226 this, 1226 this,
1227 tr ("Remove text file")); 1227 tr ("Remove text file"));
1228#else 1228#else
1229 QString fn = ScQtFileEdit::getOpenFileName(this, 1229 QString fn = ScQtFileEdit::getOpenFileName(this,
1230 tr ("Remove text file"), 1230 tr ("Remove text file"),
1231 QDir::homeDirPath() + "/Documents/application/zsafe", 1231 QDir::homeDirPath() + "/Documents/application/zsafe",
1232 "*.txt"); 1232 "*.txt");
1233#endif 1233#endif
1234#else 1234#else
1235 QString fn = QFileDialog::getOpenFileName( 1235 QString fn = QFileDialog::getOpenFileName(
1236 QDir::homeDirPath() + "/Documents/application/zsafe", 1236 QDir::homeDirPath() + "/Documents/application/zsafe",
1237 "ZSafe (*.txt)", 1237 "ZSafe (*.txt)",
1238 this, 1238 this,
1239 "ZSafe File Dialog" 1239 "ZSafe File Dialog"
1240 "Choose a text file" ); 1240 "Choose a text file" );
1241#endif 1241#endif
1242 1242
1243 if (fn && fn.length() > 0 ) 1243 if (fn && fn.length() > 0 )
1244 { 1244 {
1245 QFile f( fn ); 1245 QFile f( fn );
1246 if ( !f.remove() ) 1246 if ( !f.remove() )
1247 { 1247 {
1248 qWarning( QString("Could not remove file %1").arg(fn), 1248 qWarning( QString("Could not remove file %1").arg(fn),
1249 2000 ); 1249 2000 );
1250 QMessageBox::critical( 0, tr("ZSafe"), 1250 QMessageBox::critical( 0, tr("ZSafe"),
1251 tr("Could not remove text file.") ); 1251 tr("Could not remove text file.") );
1252 return; 1252 return;
1253 } 1253 }
1254 } 1254 }
1255} 1255}
1256 1256
1257void ZSafe::writeAllEntries() 1257void ZSafe::writeAllEntries()
1258{ 1258{
1259 if (filename.isEmpty()) 1259 if (filename.isEmpty())
1260 { 1260 {
1261 QMessageBox::critical( 0, tr("ZSafe"), 1261 QMessageBox::critical( 0, tr("ZSafe"),
1262 tr("No document defined.\nYou have to create a new document")); 1262 tr("No document defined.\nYou have to create a new document"));
1263 return; 1263 return;
1264 } 1264 }
1265 1265
1266 // open the file dialog 1266 // open the file dialog
1267#ifndef DESKTOP 1267#ifndef DESKTOP
1268#ifndef NO_OPIE 1268#ifndef NO_OPIE
1269 QMap<QString, QStringList> mimeTypes; 1269 QMap<QString, QStringList> mimeTypes;
1270 mimeTypes.insert(tr("All"), QStringList() ); 1270 mimeTypes.insert(tr("All"), QStringList() );
1271 mimeTypes.insert(tr("Text"), "text/*" ); 1271 mimeTypes.insert(tr("Text"), "text/*" );
1272 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 1272 QString fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
1273 QDir::homeDirPath() + "/Documents/application/zsafe", 1273 QDir::homeDirPath() + "/Documents/application/zsafe",
1274 QString::null, 1274 QString::null,
1275 mimeTypes, 1275 mimeTypes,
1276 this, 1276 this,
1277 tr ("Export text file")); 1277 tr ("Export text file"));
1278#else 1278#else
1279 QString fn = ScQtFileEdit::getSaveAsFileName(this, 1279 QString fn = ScQtFileEdit::getSaveAsFileName(this,
1280 tr ("Export text file"), 1280 tr ("Export text file"),
1281 QDir::homeDirPath() + "/Documents/application/zsafe", 1281 QDir::homeDirPath() + "/Documents/application/zsafe",
1282 "*.txt"); 1282 "*.txt");
1283#endif 1283#endif
1284#else 1284#else
1285 QString fn = QFileDialog::getSaveFileName( 1285 QString fn = QFileDialog::getSaveFileName(
1286 QDir::homeDirPath() + "/Documents/application/zsafe", 1286 QDir::homeDirPath() + "/Documents/application/zsafe",
1287 "ZSafe (*.txt)", 1287 "ZSafe (*.txt)",
1288 this, 1288 this,
1289 "ZSafe File Dialog" 1289 "ZSafe File Dialog"
1290 "Choose a text file" ); 1290 "Choose a text file" );
1291#endif 1291#endif
1292 1292
1293 // open the new document 1293 // open the new document
1294 if (fn && fn.length() > 0 ) 1294 if (fn && fn.length() > 0 )
1295 { 1295 {
1296 QFile f( fn ); 1296 QFile f( fn );
1297 if ( !f.open( IO_WriteOnly ) ) { 1297 if ( !f.open( IO_WriteOnly ) ) {
1298 qWarning( QString("Could not write to file %1").arg(fn), 1298 qWarning( QString("Could not write to file %1").arg(fn),
1299 2000 ); 1299 2000 );
1300 QMessageBox::critical( 0, "ZSafe", 1300 QMessageBox::critical( 0, "ZSafe",
1301 QString("Could not export to text file.") ); 1301 QString("Could not export to text file.") );
1302 return; 1302 return;
1303 } 1303 }
1304 QTextStream t( &f ); 1304 QTextStream t( &f );
1305 1305
1306 QListViewItem *i; 1306 QListViewItem *i;
1307 // step through all categories 1307 // step through all categories
1308 for (i = ListView->firstChild(); 1308 for (i = ListView->firstChild();
1309 i != NULL; 1309 i != NULL;
1310 i = i->nextSibling()) 1310 i = i->nextSibling())
1311 { 1311 {
1312 // step through all subitems 1312 // step through all subitems
1313 QListViewItem *si; 1313 QListViewItem *si;
1314 for (si = i->firstChild(); 1314 for (si = i->firstChild();
1315 si != NULL; 1315 si != NULL;
1316 si = si->nextSibling()) 1316 si = si->nextSibling())
1317 { 1317 {
1318 QString oneEntry; 1318 QString oneEntry;
1319 oneEntry += "\""; 1319 oneEntry += "\"";
1320 oneEntry += i->text(0); 1320 oneEntry += i->text(0);
1321 oneEntry += "\";"; 1321 oneEntry += "\";";
1322 oneEntry += "\""; 1322 oneEntry += "\"";
1323 oneEntry += si->text(0); 1323 oneEntry += si->text(0);
1324 oneEntry += "\";"; 1324 oneEntry += "\";";
1325 oneEntry += "\""; 1325 oneEntry += "\"";
1326 oneEntry += si->text(1); 1326 oneEntry += si->text(1);
1327 oneEntry += "\";"; 1327 oneEntry += "\";";
1328 oneEntry += "\""; 1328 oneEntry += "\"";
1329 oneEntry += si->text(2); 1329 oneEntry += si->text(2);
1330 oneEntry += "\";"; 1330 oneEntry += "\";";
1331 oneEntry += "\""; 1331 oneEntry += "\"";
1332 QString comment = si->text(3); 1332 QString comment = si->text(3);
1333 comment.replace (QRegExp("\n"), "<br>"); 1333 comment.replace (QRegExp("\n"), "<br>");
1334 oneEntry += comment; 1334 oneEntry += comment;
1335 oneEntry += "\";"; 1335 oneEntry += "\";";
1336 oneEntry += "\""; 1336 oneEntry += "\"";
1337 oneEntry += si->text(4); 1337 oneEntry += si->text(4);
1338 oneEntry += "\";"; 1338 oneEntry += "\";";
1339 oneEntry += "\""; 1339 oneEntry += "\"";
1340 oneEntry += si->text(5); 1340 oneEntry += si->text(5);
1341 oneEntry += "\""; 1341 oneEntry += "\"";
1342 // qWarning (oneEntry); 1342 // qWarning (oneEntry);
1343 t << oneEntry << endl; 1343 t << oneEntry << endl;
1344 1344
1345 // qWarning (si->text(0)); 1345 // qWarning (si->text(0));
1346 } 1346 }
1347 } 1347 }
1348 f.close(); 1348 f.close();
1349 } 1349 }
1350} 1350}
1351 1351
1352void ZSafe::readAllEntries() 1352void ZSafe::readAllEntries()
1353{ 1353{
1354 if (filename.isEmpty()) 1354 if (filename.isEmpty())
1355 { 1355 {
1356 QMessageBox::critical( 0, tr("ZSafe"), 1356 QMessageBox::critical( 0, tr("ZSafe"),
1357 tr("No document defined.\nYou have to create a new document")); 1357 tr("No document defined.\nYou have to create a new document"));
1358 return; 1358 return;
1359 } 1359 }
1360 1360
1361 // open the file dialog 1361 // open the file dialog
1362#ifndef DESKTOP 1362#ifndef DESKTOP
1363#ifndef NO_OPIE 1363#ifndef NO_OPIE
1364 QMap<QString, QStringList> mimeTypes; 1364 QMap<QString, QStringList> mimeTypes;
1365 mimeTypes.insert(tr("All"), QStringList() ); 1365 mimeTypes.insert(tr("All"), QStringList() );
1366 mimeTypes.insert(tr("Text"), "text/*" ); 1366 mimeTypes.insert(tr("Text"), "text/*" );
1367 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1367 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1368 QDir::homeDirPath() + "/Documents/application/zsafe", 1368 QDir::homeDirPath() + "/Documents/application/zsafe",
1369 QString::null, 1369 QString::null,
1370 mimeTypes, 1370 mimeTypes,
1371 this, 1371 this,
1372 tr ("Import text file")); 1372 tr ("Import text file"));
1373#else 1373#else
1374 QString fn = ScQtFileEdit::getOpenFileName(this, 1374 QString fn = ScQtFileEdit::getOpenFileName(this,
1375 tr ("Import text file"), 1375 tr ("Import text file"),
1376 QDir::homeDirPath() + "/Documents/application/zsafe", 1376 QDir::homeDirPath() + "/Documents/application/zsafe",
1377 "*.txt"); 1377 "*.txt");
1378#endif 1378#endif
1379#else 1379#else
1380 QString fn = QFileDialog::getOpenFileName( 1380 QString fn = QFileDialog::getOpenFileName(
1381 QDir::homeDirPath() + "/Documents/application/zsafe", 1381 QDir::homeDirPath() + "/Documents/application/zsafe",
1382 "ZSafe (*.txt)", 1382 "ZSafe (*.txt)",
1383 this, 1383 this,
1384 "ZSafe File Dialog" 1384 "ZSafe File Dialog"
1385 "Choose a text file" ); 1385 "Choose a text file" );
1386#endif 1386#endif
1387 1387
1388 if (fn && fn.length() > 0 ) 1388 if (fn && fn.length() > 0 )
1389 { 1389 {
1390 QFile f( fn ); 1390 QFile f( fn );
1391 if ( !f.open( IO_ReadOnly ) ) 1391 if ( !f.open( IO_ReadOnly ) )
1392 { 1392 {
1393 qWarning( QString("Could not read file %1").arg(fn), 1393 qWarning( QString("Could not read file %1").arg(fn),
1394 2000 ); 1394 2000 );
1395 QMessageBox::critical( 0, "ZSafe", 1395 QMessageBox::critical( 0, "ZSafe",
1396 QString("Could not import text file.") ); 1396 QString("Could not import text file.") );
1397 return; 1397 return;
1398 } 1398 }
1399 1399
1400 modified = true; 1400 modified = true;
1401 1401
1402 // clear the password list 1402 // clear the password list
1403 selectedItem = NULL; 1403 selectedItem = NULL;
1404 QListViewItem *i; 1404 QListViewItem *i;
1405 // step through all categories 1405 // step through all categories
1406 for (i = ListView->firstChild(); 1406 for (i = ListView->firstChild();
1407 i != NULL; 1407 i != NULL;
1408 i = i->nextSibling()) 1408 i = i->nextSibling())
1409 { 1409 {
1410 // step through all subitems 1410 // step through all subitems
1411 QListViewItem *si; 1411 QListViewItem *si;
1412 for (si = i->firstChild(); 1412 for (si = i->firstChild();
1413 si != NULL; ) 1413 si != NULL; )
1414 // si = si->nextSibling()) 1414 // si = si->nextSibling())
1415 { 1415 {
1416 QListViewItem *_si = si; 1416 QListViewItem *_si = si;
1417 si = si->nextSibling(); 1417 si = si->nextSibling();
1418 i->takeItem(_si); // remove from view list 1418 i->takeItem(_si); // remove from view list
1419 if (_si) delete _si; 1419 if (_si) delete _si;
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 qWarning ("ReadAllEntries(): "); 1423 qWarning ("ReadAllEntries(): ");
1424 1424
1425 QTextStream t(&f); 1425 QTextStream t(&f);
1426 while ( !t.eof() ) 1426 while ( !t.eof() )
1427 { 1427 {
1428 QString s = t.readLine(); 1428 QString s = t.readLine();
1429 s.replace (QRegExp("\";\""), "\"|\""); 1429 s.replace (QRegExp("\";\""), "\"|\"");
1430 // char buffer[1024]; 1430 // char buffer[1024];
1431#ifndef WIN32 1431#ifndef WIN32
1432 char buffer[s.length()+1]; 1432 char buffer[s.length()+1];
1433#else 1433#else
1434 char buffer[4048]; 1434 char buffer[4048];
1435#endif 1435#endif
1436 strcpy (buffer, s); 1436 strcpy (buffer, s);
1437 1437
1438 QString name; 1438 QString name;
1439 QString user; 1439 QString user;
1440 QString password; 1440 QString password;
1441 QString comment; 1441 QString comment;
1442 QString field5=""; 1442 QString field5="";
1443 QString field6=""; 1443 QString field6="";
1444 1444
1445 // separete the entries 1445 // separete the entries
1446 char *i = strtok (buffer, "|"); 1446 char *i = strtok (buffer, "|");
1447 QString category(&i[1]); 1447 QString category(&i[1]);
1448 category.truncate(category.length() -1); 1448 category.truncate(category.length() -1);
1449 1449
1450 int idx=0; 1450 int idx=0;
1451 while ((i = strtok (NULL, "|")) != NULL) 1451 while ((i = strtok (NULL, "|")) != NULL)
1452 { 1452 {
1453 switch (idx) 1453 switch (idx)
1454 { 1454 {
1455 case 0: 1455 case 0:
1456 name = &i[1]; 1456 name = &i[1];
1457 name.truncate(name.length() -1); 1457 name.truncate(name.length() -1);
1458 // name 1458 // name
1459 break; 1459 break;
1460 case 1: 1460 case 1:
1461 // user 1461 // user
1462 user = &i[1]; 1462 user = &i[1];
1463 user.truncate(user.length() -1); 1463 user.truncate(user.length() -1);
1464 break; 1464 break;
1465 case 2: 1465 case 2:
1466 // password 1466 // password
1467 password = &i[1]; 1467 password = &i[1];
1468 password.truncate(password.length() -1); 1468 password.truncate(password.length() -1);
1469 break; 1469 break;
1470 case 3: 1470 case 3:
1471 // comment 1471 // comment
1472 comment = &i[1]; 1472 comment = &i[1];
1473 comment.truncate(comment.length() -1); 1473 comment.truncate(comment.length() -1);
1474 break; 1474 break;
1475 case 4: 1475 case 4:
1476 // field5 1476 // field5
1477 field5 = &i[1]; 1477 field5 = &i[1];
1478 field5.truncate(field5.length() -1); 1478 field5.truncate(field5.length() -1);
1479 break; 1479 break;
1480 case 5: 1480 case 5:
1481 // field6 1481 // field6
1482 field6 = &i[1]; 1482 field6 = &i[1];
1483 field6.truncate(field6.length() -1); 1483 field6.truncate(field6.length() -1);
1484 break; 1484 break;
1485 } 1485 }
1486 idx++; 1486 idx++;
1487 } 1487 }
1488 1488
1489 Category *cat= categories.find (category); 1489 Category *cat= categories.find (category);
1490 if (cat) 1490 if (cat)
1491 { 1491 {
1492 // use the existend item 1492 // use the existend item
1493 QListViewItem *catItem = cat->getListItem(); 1493 QListViewItem *catItem = cat->getListItem();
1494 if (catItem) 1494 if (catItem)
1495 { 1495 {
1496 QListViewItem * item = new ShadedListItem( 0, catItem ); 1496 QListViewItem * item = new ShadedListItem( 0, catItem );
1497 item->setText( 0, tr( name ) ); 1497 item->setText( 0, tr( name ) );
1498 item->setText( 1, tr( user ) ); 1498 item->setText( 1, tr( user ) );
1499 item->setText( 2, tr( password ) ); 1499 item->setText( 2, tr( password ) );
1500 item->setText( 3, tr( comment ) ); 1500 item->setText( 3, tr( comment ) );
1501 item->setText( 4, tr( field5 ) ); 1501 item->setText( 4, tr( field5 ) );
1502 item->setText( 5, tr( field6 ) ); 1502 item->setText( 5, tr( field6 ) );
1503 catItem->setOpen( TRUE ); 1503 catItem->setOpen( TRUE );
1504 } 1504 }
1505 } 1505 }
1506 else 1506 else
1507 { 1507 {
1508 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1508 QListViewItem *catI = new ShadedListItem( 1, ListView );
1509 // create and insert a new item 1509 // create and insert a new item
1510 QListViewItem * item = new ShadedListItem( 0, catI ); 1510 QListViewItem * item = new ShadedListItem( 0, catI );
1511 item->setText( 0, tr( name ) ); 1511 item->setText( 0, tr( name ) );
1512 item->setText( 1, tr( user ) ); 1512 item->setText( 1, tr( user ) );
1513 item->setText( 2, tr( password ) ); 1513 item->setText( 2, tr( password ) );
1514 item->setText( 3, tr( comment ) ); 1514 item->setText( 3, tr( comment ) );
1515 item->setText( 4, tr( field5 ) ); 1515 item->setText( 4, tr( field5 ) );
1516 item->setText( 5, tr( field6 ) ); 1516 item->setText( 5, tr( field6 ) );
1517 catI->setOpen( TRUE ); 1517 catI->setOpen( TRUE );
1518 1518
1519 Category *c1 = new Category(); 1519 Category *c1 = new Category();
1520 c1->setCategoryName(category); 1520 c1->setCategoryName(category);
1521 1521
1522 QString icon; 1522 QString icon;
1523 QString fullIconPath; 1523 QString fullIconPath;
1524 QPixmap *pix; 1524 QPixmap *pix;
1525// #ifndef WIN32 1525// #ifndef WIN32
1526 icon = conf->readEntry(APP_KEY+category); 1526 icon = conf->readEntry(APP_KEY+category);
1527// #endif 1527// #endif
1528 bool isIconAv = false; 1528 bool isIconAv = false;
1529 if (!icon.isEmpty() && !icon.isNull()) 1529 if (!icon.isEmpty() && !icon.isNull())
1530 { 1530 {
1531 // build the full path 1531 // build the full path
1532 fullIconPath = iconPath + icon; 1532 fullIconPath = iconPath + icon;
1533 pix = new QPixmap (fullIconPath); 1533 pix = new QPixmap (fullIconPath);
1534 if (pix) 1534 if (pix)
1535 { 1535 {
1536 QImage img = pix->convertToImage(); 1536 QImage img = pix->convertToImage();
1537 pix->convertFromImage(img.smoothScale(14,14)); 1537 pix->convertFromImage(img.smoothScale(14,14));
1538 c1->setIconName (icon); 1538 c1->setIconName (icon);
1539 c1->setIcon (*pix); 1539 c1->setIcon (*pix);
1540 isIconAv = true; 1540 isIconAv = true;
1541 } 1541 }
1542 } 1542 }
1543 if (!isIconAv) 1543 if (!isIconAv)
1544 { 1544 {
1545 c1->setIcon (*getPredefinedIcon(category)); 1545 c1->setIcon (*getPredefinedIcon(category));
1546 } 1546 }
1547 c1->setListItem (catI); 1547 c1->setListItem (catI);
1548 c1->initListItem(); 1548 c1->initListItem();
1549 categories.insert (c1->getCategoryName(), c1); 1549 categories.insert (c1->getCategoryName(), c1);
1550 } 1550 }
1551 1551
1552 } 1552 }
1553 f.close(); 1553 f.close();
1554 1554
1555 } 1555 }
1556 else 1556 else
1557 { 1557 {
1558 } 1558 }
1559 1559
1560} 1560}
1561 1561
1562#ifdef UNUSED 1562#ifdef UNUSED
1563void ZSafe::writeAllEntries() 1563void ZSafe::writeAllEntries()
1564{ 1564{
1565 // open the file for writing 1565 // open the file for writing
1566 QString fn = filename + ".txt"; 1566 QString fn = filename + ".txt";
1567 QFile f( fn ); 1567 QFile f( fn );
1568 if ( !f.open( IO_WriteOnly ) ) { 1568 if ( !f.open( IO_WriteOnly ) ) {
1569 qWarning( QString("Could not write to file %1").arg(fn), 1569 qWarning( QString("Could not write to file %1").arg(fn),
1570 2000 ); 1570 2000 );
1571 QMessageBox::critical( 0, tr("ZSafe"), 1571 QMessageBox::critical( 0, tr("ZSafe"),
1572 tr("Could not export to text file.") ); 1572 tr("Could not export to text file.") );
1573 return; 1573 return;
1574 } 1574 }
1575 QTextStream t( &f ); 1575 QTextStream t( &f );
1576 1576
1577 QListViewItem *i; 1577 QListViewItem *i;
1578 // step through all categories 1578 // step through all categories
1579 for (i = ListView->firstChild(); 1579 for (i = ListView->firstChild();
1580 i != NULL; 1580 i != NULL;
1581 i = i->nextSibling()) 1581 i = i->nextSibling())
1582 { 1582 {
1583 // step through all subitems 1583 // step through all subitems
1584 QListViewItem *si; 1584 QListViewItem *si;
1585 for (si = i->firstChild(); 1585 for (si = i->firstChild();
1586 si != NULL; 1586 si != NULL;
1587 si = si->nextSibling()) 1587 si = si->nextSibling())
1588 { 1588 {
1589 QString oneEntry; 1589 QString oneEntry;
1590 oneEntry += "\""; 1590 oneEntry += "\"";
1591 oneEntry += i->text(0); 1591 oneEntry += i->text(0);
1592 oneEntry += "\";"; 1592 oneEntry += "\";";
1593 oneEntry += "\""; 1593 oneEntry += "\"";
1594 oneEntry += si->text(0); 1594 oneEntry += si->text(0);
1595 oneEntry += "\";"; 1595 oneEntry += "\";";
1596 oneEntry += "\""; 1596 oneEntry += "\"";
1597 oneEntry += si->text(1); 1597 oneEntry += si->text(1);
1598 oneEntry += "\";"; 1598 oneEntry += "\";";
1599 oneEntry += "\""; 1599 oneEntry += "\"";
1600 oneEntry += si->text(2); 1600 oneEntry += si->text(2);
1601 oneEntry += "\";"; 1601 oneEntry += "\";";
1602 oneEntry += "\""; 1602 oneEntry += "\"";
1603 // oneEntry += si->text(3); 1603 // oneEntry += si->text(3);
1604 QString comment = si->text(3); 1604 QString comment = si->text(3);
1605 comment.replace (QRegExp("\n"), "<br>"); 1605 comment.replace (QRegExp("\n"), "<br>");
1606 oneEntry += comment; 1606 oneEntry += comment;
1607 oneEntry += "\""; 1607 oneEntry += "\"";
1608 // qWarning (oneEntry); 1608 // qWarning (oneEntry);
1609 t << oneEntry << endl; 1609 t << oneEntry << endl;
1610 1610
1611 // qWarning (si->text(0)); 1611 // qWarning (si->text(0));
1612 } 1612 }
1613 } 1613 }
1614 f.close(); 1614 f.close();
1615} 1615}
1616 1616
1617void ZSafe::readAllEntries() 1617void ZSafe::readAllEntries()
1618{ 1618{
1619 QString fn = filename + ".txt"; 1619 QString fn = filename + ".txt";
1620 QFile f( fn ); 1620 QFile f( fn );
1621 if ( !f.open( IO_ReadOnly ) ) 1621 if ( !f.open( IO_ReadOnly ) )
1622 { 1622 {
1623 qWarning( QString("Could not read file %1").arg(fn), 1623 qWarning( QString("Could not read file %1").arg(fn),
1624 2000 ); 1624 2000 );
1625 QMessageBox::critical( 0, tr("ZSafe"), 1625 QMessageBox::critical( 0, tr("ZSafe"),
1626 tr("Could not import text file.") ); 1626 tr("Could not import text file.") );
1627 return; 1627 return;
1628 } 1628 }
1629 1629
1630 modified = true; 1630 modified = true;
1631 1631
1632 // clear the password list 1632 // clear the password list
1633 selectedItem = NULL; 1633 selectedItem = NULL;
1634 QListViewItem *i; 1634 QListViewItem *i;
1635 // step through all categories 1635 // step through all categories
1636 for (i = ListView->firstChild(); 1636 for (i = ListView->firstChild();
1637 i != NULL; 1637 i != NULL;
1638 i = i->nextSibling()) 1638 i = i->nextSibling())
1639 { 1639 {
1640 // step through all subitems 1640 // step through all subitems
1641 QListViewItem *si; 1641 QListViewItem *si;
1642 for (si = i->firstChild(); 1642 for (si = i->firstChild();
1643 si != NULL; ) 1643 si != NULL; )
1644 // si = si->nextSibling()) 1644 // si = si->nextSibling())
1645 { 1645 {
1646 QListViewItem *_si = si; 1646 QListViewItem *_si = si;
1647 si = si->nextSibling(); 1647 si = si->nextSibling();
1648 i->takeItem(_si); // remove from view list 1648 i->takeItem(_si); // remove from view list
1649 if (_si) delete _si; 1649 if (_si) delete _si;
1650 } 1650 }
1651 } 1651 }
1652 1652
1653 qWarning ("ReadAllEntries(): "); 1653 qWarning ("ReadAllEntries(): ");
1654 1654
1655 QTextStream t(&f); 1655 QTextStream t(&f);
1656 while ( !t.eof() ) 1656 while ( !t.eof() )
1657 { 1657 {
1658 QString s = t.readLine(); 1658 QString s = t.readLine();
1659 s.replace (QRegExp("\";\""), "\"|\""); 1659 s.replace (QRegExp("\";\""), "\"|\"");
1660 // char buffer[1024]; 1660 // char buffer[1024];
1661 int len=s.length()+1; 1661 int len=s.length()+1;
1662#ifdef WIN32 1662#ifdef WIN32
1663 char buffer[512]; 1663 char buffer[512];
1664#else 1664#else
1665 char buffer[len]; 1665 char buffer[len];
1666#endif 1666#endif
1667 strcpy (buffer, s); 1667 strcpy (buffer, s);
1668 1668
1669 QString name; 1669 QString name;
1670 QString user; 1670 QString user;
1671 QString password; 1671 QString password;
1672 QString comment; 1672 QString comment;
1673 1673
1674 // separete the entries 1674 // separete the entries
1675 char *i = strtok (buffer, "|"); 1675 char *i = strtok (buffer, "|");
1676 QString category(&i[1]); 1676 QString category(&i[1]);
1677 category.truncate(category.length() -1); 1677 category.truncate(category.length() -1);
1678 1678
1679 int idx=0; 1679 int idx=0;
1680 while (i = strtok (NULL, "|")) 1680 while (i = strtok (NULL, "|"))
1681 { 1681 {
1682 switch (idx) 1682 switch (idx)
1683 { 1683 {
1684 case 0: 1684 case 0:
1685 name = &i[1]; 1685 name = &i[1];
1686 name.truncate(name.length() -1); 1686 name.truncate(name.length() -1);
1687 // name 1687 // name
1688 break; 1688 break;
1689 case 1: 1689 case 1:
1690 // user 1690 // user
1691 user = &i[1]; 1691 user = &i[1];
1692 user.truncate(user.length() -1); 1692 user.truncate(user.length() -1);
1693 break; 1693 break;
1694 case 2: 1694 case 2:
1695 // password 1695 // password
1696 password = &i[1]; 1696 password = &i[1];
1697 password.truncate(password.length() -1); 1697 password.truncate(password.length() -1);
1698 break; 1698 break;
1699 case 3: 1699 case 3:
1700 // comment 1700 // comment
1701 comment = &i[1]; 1701 comment = &i[1];
1702 comment.truncate(comment.length() -1); 1702 comment.truncate(comment.length() -1);
1703 break; 1703 break;
1704 } 1704 }
1705 idx++; 1705 idx++;
1706 } 1706 }
1707 1707
1708 Category *cat= categories.find (category); 1708 Category *cat= categories.find (category);
1709 if (cat) 1709 if (cat)
1710 { 1710 {
1711 // use the existend item 1711 // use the existend item
1712 QListViewItem *catItem = cat->getListItem(); 1712 QListViewItem *catItem = cat->getListItem();
1713 if (catItem) 1713 if (catItem)
1714 { 1714 {
1715 QListViewItem * item = new ShadedListItem( 0, catItem ); 1715 QListViewItem * item = new ShadedListItem( 0, catItem );
1716 item->setText( 0, tr( name ) ); 1716 item->setText( 0, tr( name ) );
1717 item->setText( 1, tr( user ) ); 1717 item->setText( 1, tr( user ) );
1718 item->setText( 2, tr( password ) ); 1718 item->setText( 2, tr( password ) );
1719 item->setText( 3, tr( comment ) ); 1719 item->setText( 3, tr( comment ) );
1720 catItem->setOpen( TRUE ); 1720 catItem->setOpen( TRUE );
1721 } 1721 }
1722 } 1722 }
1723 else 1723 else
1724 { 1724 {
1725 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1725 QListViewItem *catI = new ShadedListItem( 1, ListView );
1726 // create and insert a new item 1726 // create and insert a new item
1727 QListViewItem * item = new ShadedListItem( 0, catI ); 1727 QListViewItem * item = new ShadedListItem( 0, catI );
1728 item->setText( 0, tr( name ) ); 1728 item->setText( 0, tr( name ) );
1729 item->setText( 1, tr( user ) ); 1729 item->setText( 1, tr( user ) );
1730 item->setText( 2, tr( password ) ); 1730 item->setText( 2, tr( password ) );
1731 item->setText( 3, tr( comment ) ); 1731 item->setText( 3, tr( comment ) );
1732 catI->setOpen( TRUE ); 1732 catI->setOpen( TRUE );
1733 1733
1734 Category *c1 = new Category(); 1734 Category *c1 = new Category();
1735 c1->setCategoryName(category); 1735 c1->setCategoryName(category);
1736 1736
1737 QString icon; 1737 QString icon;
1738 QString fullIconPath; 1738 QString fullIconPath;
1739 QPixmap *pix; 1739 QPixmap *pix;
1740// #ifndef WIN32 1740// #ifndef WIN32
1741 icon = conf->readEntry(APP_KEY+category); 1741 icon = conf->readEntry(APP_KEY+category);
1742// #endif 1742// #endif
1743 bool isIconAv = false; 1743 bool isIconAv = false;
1744 if (!icon.isEmpty() && !icon.isNull()) 1744 if (!icon.isEmpty() && !icon.isNull())
1745 { 1745 {
1746 // build the full path 1746 // build the full path
1747 fullIconPath = iconPath + icon; 1747 fullIconPath = iconPath + icon;
1748 pix = new QPixmap (fullIconPath); 1748 pix = new QPixmap (fullIconPath);
1749 if (pix) 1749 if (pix)
1750 { 1750 {
1751 QImage img = pix->convertToImage(); 1751 QImage img = pix->convertToImage();
1752 pix->convertFromImage(img.smoothScale(14,14)); 1752 pix->convertFromImage(img.smoothScale(14,14));
1753 c1->setIconName (icon); 1753 c1->setIconName (icon);
1754 c1->setIcon (*pix); 1754 c1->setIcon (*pix);
1755 isIconAv = true; 1755 isIconAv = true;
1756 } 1756 }
1757 } 1757 }
1758 if (!isIconAv) 1758 if (!isIconAv)
1759 { 1759 {
1760 c1->setIcon (*getPredefinedIcon(category)); 1760 c1->setIcon (*getPredefinedIcon(category));
1761 } 1761 }
1762 c1->setListItem (catI); 1762 c1->setListItem (catI);
1763 c1->initListItem(); 1763 c1->initListItem();
1764 categories.insert (c1->getCategoryName(), c1); 1764 categories.insert (c1->getCategoryName(), c1);
1765 } 1765 }
1766 1766
1767 } 1767 }
1768 f.close(); 1768 f.close();
1769 1769
1770} 1770}
1771#endif // UNUSED 1771#endif // UNUSED
1772 1772
1773void ZSafe::resume(int) 1773void ZSafe::resume(int)
1774{ 1774{
1775 qWarning ("Resume"); 1775 qWarning ("Resume");
1776 // hide the main window 1776 // hide the main window
1777 1777
1778 infoForm->hide(); 1778 infoForm->hide();
1779 // open zsafe again 1779 // open zsafe again
1780 m_password = ""; 1780 m_password = "";
1781 selectedItem = NULL; 1781 selectedItem = NULL;
1782 1782
1783 // clear the password list 1783 // clear the password list
1784 QListViewItem *i; 1784 QListViewItem *i;
1785 // step through all categories 1785 // step through all categories
1786 for (i = ListView->firstChild(); 1786 for (i = ListView->firstChild();
1787 i != NULL; 1787 i != NULL;
1788 i = i->nextSibling()) 1788 i = i->nextSibling())
1789 { 1789 {
1790 // step through all subitems 1790 // step through all subitems
1791 QListViewItem *si; 1791 QListViewItem *si;
1792 for (si = i->firstChild(); 1792 for (si = i->firstChild();
1793 si != NULL; ) 1793 si != NULL; )
1794 { 1794 {
1795 QListViewItem *_si = si; 1795 QListViewItem *_si = si;
1796 si = si->nextSibling(); 1796 si = si->nextSibling();
1797 i->takeItem(_si); // remove from view list 1797 i->takeItem(_si); // remove from view list
1798 if (_si) delete _si; 1798 if (_si) delete _si;
1799 } 1799 }
1800 } 1800 }
1801 1801
1802 // ask for password and read again 1802 // ask for password and read again
1803 openDocument(filename); 1803 openDocument(filename);
1804} 1804}
1805 1805
1806//--------------------------------------------- 1806//---------------------------------------------
1807 1807
1808 1808
1809bool ZSafe::openDocument(const char* _filename, const char* ) 1809bool ZSafe::openDocument(const char* _filename, const char* )
1810{ 1810{
1811 int retval; 1811 int retval;
1812 char* entry[FIELD_SIZE]; 1812 char* entry[FIELD_SIZE];
1813// #ifndef WIN32 1813// #ifndef WIN32
1814 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1814 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1815// #else 1815// #else
1816 // int validationFlag = 1; 1816 // int validationFlag = 1;
1817// #endif 1817// #endif
1818 1818
1819 int pwdOk = 0; 1819 int pwdOk = 0;
1820 int numberOfTries = 3; 1820 int numberOfTries = 3;
1821 for (int i=0; i < numberOfTries; i++) 1821 for (int i=0; i < numberOfTries; i++)
1822 { 1822 {
1823 QFile f(_filename); 1823 QFile f(_filename);
1824 if (f.exists()) 1824 if (f.exists())
1825 { 1825 {
1826 // ask with a dialog for the password 1826 // ask with a dialog for the password
1827 if (m_password.isEmpty()) 1827 if (m_password.isEmpty())
1828 getDocPassword(tr("Enter Password")); 1828 getDocPassword(tr("Enter Password"));
1829 if (m_password.isEmpty() && validationFlag == 0) 1829 if (m_password.isEmpty() && validationFlag == 0)
1830 { 1830 {
1831 qWarning ("Wrong password"); 1831 qWarning ("Wrong password");
1832 QMessageBox::critical( 0, tr("ZSafe"), 1832 QMessageBox::critical( 0, tr("ZSafe"),
1833 tr("Wrong password.\n\nZSafe will now exit.") ); 1833 tr("Wrong password.\n\nZSafe will now exit.") );
1834 exitZs (1); 1834 exitZs (1);
1835 } 1835 }
1836 1836
1837 retval = loadInit(_filename, m_password); 1837 retval = loadInit(_filename, m_password);
1838 if (retval != PWERR_GOOD) 1838 if (retval != PWERR_GOOD)
1839 { 1839 {
1840 qWarning ("Error loading Document"); 1840 qWarning ("Error loading Document");
1841 return false; 1841 return false;
1842 } 1842 }
1843 } 1843 }
1844 else 1844 else
1845 { 1845 {
1846#ifdef WIN32 1846#ifdef WIN32
1847 this->setCaption("Qt ZSafe"); 1847 this->setCaption("Qt ZSafe");
1848#else 1848#else
1849 this->setCaption("ZSafe"); 1849 this->setCaption("ZSafe");
1850#endif 1850#endif
1851 filename = ""; 1851 filename = "";
1852 return false; 1852 return false;
1853 } 1853 }
1854 1854
1855 1855
1856 // load the validation entry 1856 // load the validation entry
1857 if (validationFlag == 0) 1857 if (validationFlag == 0)
1858 { 1858 {
1859 pwdOk = 1; 1859 pwdOk = 1;
1860 break; 1860 break;
1861 } 1861 }
1862 1862
1863 retval = loadEntry(entry); 1863 retval = loadEntry(entry);
1864 if (retval == 1 && 1864 if (retval == 1 &&
1865 !strcmp (entry[0], "ZSAFECATEGORY") && 1865 !strcmp (entry[0], "ZSAFECATEGORY") &&
1866 !strcmp (entry[1], "name") && 1866 !strcmp (entry[1], "name") &&
1867 !strcmp (entry[2], "username") && 1867 !strcmp (entry[2], "username") &&
1868 !strcmp (entry[3], "password") && 1868 !strcmp (entry[3], "password") &&
1869 !strcmp (entry[4], "comment") ) 1869 !strcmp (entry[4], "comment") )
1870 { 1870 {
1871 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1871 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1872 pwdOk = 1; 1872 pwdOk = 1;
1873 break; 1873 break;
1874 } 1874 }
1875 else 1875 else
1876 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1876 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1877 fclose (fd); 1877 fclose (fd);
1878 m_password = ""; 1878 m_password = "";
1879 1879
1880 if (i < numberOfTries - 1) 1880 if (i < numberOfTries - 1)
1881 { 1881 {
1882 switch( QMessageBox::warning( this, tr("ZSafe"), 1882 switch( QMessageBox::warning( this, tr("ZSafe"),
1883 tr("Wrong password.\nEnter again?"), 1883 tr("Wrong password.\nEnter again?"),
1884 tr("&Yes"), tr("&No."), 1884 tr("&Yes"), tr("&No."),
1885 0 1885 0
1886 ) ) 1886 ) )
1887 { 1887 {
1888 case 1: // No 1888 case 1: // No
1889 exitZs (1); 1889 exitZs (1);
1890 break; 1890 break;
1891 case 0: // Yes 1891 case 0: // Yes
1892 continue; 1892 continue;
1893 } 1893 }
1894 } 1894 }
1895 } 1895 }
1896 if (pwdOk == 0) 1896 if (pwdOk == 0)
1897 { 1897 {
1898 // unset the document entry 1898 // unset the document entry
1899 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 1899 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
1900 if (conf) 1900 if (conf)
1901 delete conf; 1901 delete conf;
1902 1902
1903 exitZs (1); 1903 exitZs (1);
1904 } 1904 }
1905 1905
1906 1906
1907 retval = loadEntry(entry); 1907 retval = loadEntry(entry);
1908 1908
1909 int numberOfEntries=0; 1909 int numberOfEntries=0;
1910 while (retval == 1) { 1910 while (retval == 1) {
1911 1911
1912 QString category(entry[0]); 1912 QString category(entry[0]);
1913 QString name(entry[1]); 1913 QString name(entry[1]);
1914 QString user(entry[2]); 1914 QString user(entry[2]);
1915 QString password(entry[3]); 1915 QString password(entry[3]);
1916 QString comment(entry[4]); 1916 QString comment(entry[4]);
1917 QString field5(entry[5]); 1917 QString field5(entry[5]);
1918 QString field6(entry[6]); 1918 QString field6(entry[6]);
1919 // add the subitems to the categories 1919 // add the subitems to the categories
1920 1920
1921 Category *cat= categories.find (category); 1921 Category *cat= categories.find (category);
1922 if (cat) 1922 if (cat)
1923 { 1923 {
1924 // use the existend item 1924 // use the existend item
1925 QListViewItem *catItem = cat->getListItem(); 1925 QListViewItem *catItem = cat->getListItem();
1926 if (catItem) 1926 if (catItem)
1927 { 1927 {
1928 QListViewItem * item = new ShadedListItem( 0, catItem ); 1928 QListViewItem * item = new ShadedListItem( 0, catItem );
1929 item->setText( 0, tr( name ) ); 1929 item->setText( 0, tr( name ) );
1930 item->setText( 1, tr( user ) ); 1930 item->setText( 1, tr( user ) );
1931 item->setText( 2, tr( password ) ); 1931 item->setText( 2, tr( password ) );
1932 item->setText( 3, tr( comment ) ); 1932 item->setText( 3, tr( comment ) );
1933 item->setText( 4, tr( field5 ) ); 1933 item->setText( 4, tr( field5 ) );
1934 item->setText( 5, tr( field6 ) ); 1934 item->setText( 5, tr( field6 ) );
1935 if (expandTree) 1935 if (expandTree)
1936 catItem->setOpen( TRUE ); 1936 catItem->setOpen( TRUE );
1937 numberOfEntries++; 1937 numberOfEntries++;
1938 } 1938 }
1939 } 1939 }
1940 else 1940 else
1941 { 1941 {
1942 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1942 QListViewItem *catI = new ShadedListItem( 1, ListView );
1943 // create and insert a new item 1943 // create and insert a new item
1944 QListViewItem * item = new ShadedListItem( 0, catI ); 1944 QListViewItem * item = new ShadedListItem( 0, catI );
1945 item->setText( 0, tr( name ) ); 1945 item->setText( 0, tr( name ) );
1946 item->setText( 1, tr( user ) ); 1946 item->setText( 1, tr( user ) );
1947 item->setText( 2, tr( password ) ); 1947 item->setText( 2, tr( password ) );
1948 item->setText( 3, tr( comment ) ); 1948 item->setText( 3, tr( comment ) );
1949 item->setText( 4, tr( field5 ) ); 1949 item->setText( 4, tr( field5 ) );
1950 item->setText( 5, tr( field6 ) ); 1950 item->setText( 5, tr( field6 ) );
1951 if (expandTree) 1951 if (expandTree)
1952 catI->setOpen( TRUE ); 1952 catI->setOpen( TRUE );
1953 1953
1954 Category *c1 = new Category(); 1954 Category *c1 = new Category();
1955 c1->setCategoryName(category); 1955 c1->setCategoryName(category);
1956 1956
1957 QString icon; 1957 QString icon;
1958 QString fullIconPath; 1958 QString fullIconPath;
1959 QPixmap *pix; 1959 QPixmap *pix;
1960// #ifndef WIN32 1960// #ifndef WIN32
1961 icon = conf->readEntry(APP_KEY+category); 1961 icon = conf->readEntry(APP_KEY+category);
1962// #endif 1962// #endif
1963 bool isIconAv = false; 1963 bool isIconAv = false;
1964 if (!icon.isEmpty() && !icon.isNull()) 1964 if (!icon.isEmpty() && !icon.isNull())
1965 { 1965 {
1966 // build the full path 1966 // build the full path
1967 fullIconPath = iconPath + icon; 1967 fullIconPath = iconPath + icon;
1968 pix = new QPixmap (fullIconPath); 1968 pix = new QPixmap (fullIconPath);
1969 if (pix) 1969 if (pix)
1970 { 1970 {
1971 QImage img = pix->convertToImage(); 1971 QImage img = pix->convertToImage();
1972 pix->convertFromImage(img.smoothScale(14,14)); 1972 pix->convertFromImage(img.smoothScale(14,14));
1973 c1->setIconName (icon); 1973 c1->setIconName (icon);
1974 c1->setIcon (*pix); 1974 c1->setIcon (*pix);
1975 isIconAv = true; 1975 isIconAv = true;
1976 } 1976 }
1977 } 1977 }
1978 if (!isIconAv) 1978 if (!isIconAv)
1979 { 1979 {
1980 c1->setIcon (*getPredefinedIcon(category)); 1980 c1->setIcon (*getPredefinedIcon(category));
1981 } 1981 }
1982 1982
1983 c1->setListItem (catI); 1983 c1->setListItem (catI);
1984 c1->initListItem(); 1984 c1->initListItem();
1985 categories.insert (c1->getCategoryName(), c1); 1985 categories.insert (c1->getCategoryName(), c1);
1986 numberOfEntries++; 1986 numberOfEntries++;
1987 } 1987 }
1988 1988
1989 for (int count = 0; count < FIELD_SIZE; count++) { 1989 for (int count = 0; count < FIELD_SIZE; count++) {
1990 free(entry[count]); 1990 free(entry[count]);
1991 } 1991 }
1992 retval = loadEntry(entry); 1992 retval = loadEntry(entry);
1993 if (retval == 2) { 1993 if (retval == 2) {
1994 // m_parent->slotStatusHelpMsg("Last entry loaded"); 1994 // m_parent->slotStatusHelpMsg("Last entry loaded");
1995 } 1995 }
1996 } // end while 1996 } // end while
1997 1997
1998 if (numberOfEntries == 0) 1998 if (numberOfEntries == 0)
1999 { 1999 {
2000 2000
2001 switch( QMessageBox::warning( this, tr("ZSafe"), 2001 switch( QMessageBox::warning( this, tr("ZSafe"),
2002 tr("Empty document or\nwrong password.\nContinue?"), 2002 tr("Empty document or\nwrong password.\nContinue?"),
2003 tr("&No"), tr("&Yes."), 2003 tr("&No"), tr("&Yes."),
2004 0 2004 0
2005 ) ) { 2005 ) ) {
2006 case 0: // No 2006 case 0: // No
2007 retval = loadFinalize(); 2007 retval = loadFinalize();
2008 exitZs (1); 2008 exitZs (1);
2009 break; 2009 break;
2010 case 1: // Yes 2010 case 1: // Yes
2011 break; 2011 break;
2012 } 2012 }
2013 } 2013 }
2014 2014
2015 retval = loadFinalize(); 2015 retval = loadFinalize();
2016 2016
2017 return true; 2017 return true;
2018} 2018}
2019 2019
2020int ZSafe::loadInit(const char* _filename, const char *password) 2020int ZSafe::loadInit(const char* _filename, const char *password)
2021{ 2021{
2022 unsigned int j = 0; 2022 unsigned int j = 0;
2023 unsigned int keylength=0; 2023 unsigned int keylength=0;
2024 int count=0, count2=0, count3=0; 2024 int count=0, count2=0, count3=0;
2025 unsigned char charbuf[8]; 2025 unsigned char charbuf[8];
2026 unsigned short ciphertext[4]; 2026 unsigned short ciphertext[4];
2027 char key[128]; 2027 char key[128];
2028 Krc2* krc2 = new Krc2(); 2028 Krc2* krc2 = new Krc2();
2029 2029
2030 fd = fopen (_filename, "rb"); 2030 fd = fopen (_filename, "rb");
2031 2031
2032 QFileInfo f (_filename); 2032 QFileInfo f (_filename);
2033 load_buffer_length = f.size(); 2033 load_buffer_length = f.size();
2034 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2034 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2035 2035
2036 if (fd == NULL) 2036 if (fd == NULL)
2037 return PWERR_OPEN; 2037 return PWERR_OPEN;
2038 2038
2039 buffer = (char *)malloc(load_buffer_length); 2039 buffer = (char *)malloc(load_buffer_length);
2040 for (j = 0; password[j] != '\0'; j++) { 2040 for (j = 0; password[j] != '\0'; j++) {
2041 key[j] = password[j]; 2041 key[j] = password[j];
2042 } 2042 }
2043 keylength = j; 2043 keylength = j;
2044 krc2->rc2_expandkey (key, keylength, 128); 2044 krc2->rc2_expandkey (key, keylength, 128);
2045 2045
2046#ifndef WIN32 2046#ifndef WIN32
2047 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2047 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2048#else 2048#else
2049 printf ("LoadInit() read1"); 2049 printf ("LoadInit() read1");
2050 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2050 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2051#endif 2051#endif
2052 2052
2053 if (size < 8) 2053 if (size < 8)
2054 return PWERR_DATA; 2054 return PWERR_DATA;
2055 2055
2056 for (count = 0; count < 4; count++) { 2056 for (count = 0; count < 4; count++) {
2057 count2 = count << 1; 2057 count2 = count << 1;
2058 iv[count] = charbuf[count2] << 8; 2058 iv[count] = charbuf[count2] << 8;
2059 iv[count] += charbuf[count2 + 1]; 2059 iv[count] += charbuf[count2 + 1];
2060 } 2060 }
2061 2061
2062 size = 0; 2062 size = 0;
2063 bufferIndex = 0; 2063 bufferIndex = 0;
2064#ifndef WIN32 2064#ifndef WIN32
2065 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2065 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2066 while (count < 8) { 2066 while (count < 8) {
2067 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2067 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2068#else 2068#else
2069 printf ("LoadInit() read2"); 2069 printf ("LoadInit() read2");
2070 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2070 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2071 while (count < 8) { 2071 while (count < 8) {
2072 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2072 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2073#endif 2073#endif
2074 if (count2 == 0) { 2074 if (count2 == 0) {
2075 return PWERR_DATA; 2075 return PWERR_DATA;
2076 } 2076 }
2077 count += count2; 2077 count += count2;
2078 } /* while (count < 8) */ 2078 } /* while (count < 8) */
2079 2079
2080 size += 8; 2080 size += 8;
2081 for (count2 = 0; count2 < 8; count2 += 2) { 2081 for (count2 = 0; count2 < 8; count2 += 2) {
2082 count3 = count2 >> 1; 2082 count3 = count2 >> 1;
2083 ciphertext[count3] = charbuf[count2] << 8; 2083 ciphertext[count3] = charbuf[count2] << 8;
2084 ciphertext[count3] += charbuf[count2 + 1]; 2084 ciphertext[count3] += charbuf[count2 + 1];
2085 2085
2086 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2086 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2087 iv[count3] = plaintext[count3]; 2087 iv[count3] = plaintext[count3];
2088 } /* for (count2) */ 2088 } /* for (count2) */
2089 2089
2090 krc2->rc2_decrypt (plaintext); 2090 krc2->rc2_decrypt (plaintext);
2091 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2091 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2092 bufferIndex += 8; 2092 bufferIndex += 8;
2093 buffer[bufferIndex + 1] = '\0'; 2093 buffer[bufferIndex + 1] = '\0';
2094 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2094 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2095 size -= buffer[size - 1]; 2095 size -= buffer[size - 1];
2096 lastcount = 0; 2096 lastcount = 0;
2097 2097
2098 /* This will point to the starting index */ 2098 /* This will point to the starting index */
2099 bufferIndex = 0; 2099 bufferIndex = 0;
2100 return PWERR_GOOD; 2100 return PWERR_GOOD;
2101} 2101}
2102 2102
2103int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2103int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2104{ 2104{
2105 /* Strip off PKCS 5 padding 2105 /* Strip off PKCS 5 padding
2106 * Should check to make sure it's good here 2106 * Should check to make sure it's good here
2107 */ 2107 */
2108 int count, count1=0; 2108 int count, count1=0;
2109 2109
2110 for (count = lastcount; count < size; count++) { 2110 for (count = lastcount; count < size; count++) {
2111 if ((unsigned char) (buffer[count]) == 255) { 2111 if ((unsigned char) (buffer[count]) == 255) {
2112 if (buffer[bufferIndex] == '\0') { 2112 if (buffer[bufferIndex] == '\0') {
2113 bufferIndex++; 2113 bufferIndex++;
2114 } 2114 }
2115 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2115 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2116 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2116 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2117 entry[count1][count - bufferIndex] = '\0'; 2117 entry[count1][count - bufferIndex] = '\0';
2118 count++; 2118 count++;
2119 bufferIndex = count; 2119 bufferIndex = count;
2120 count1++; 2120 count1++;
2121 if (count1 == FIELD_SIZE) { 2121 if (count1 == FIELD_SIZE) {
2122 lastcount = count; 2122 lastcount = count;
2123 return 1; 2123 return 1;
2124 } 2124 }
2125 } /* if ((unsigned char) (buffer[count]) == 255) */ 2125 } /* if ((unsigned char) (buffer[count]) == 255) */
2126 } /* for (count = 0; count < size; count++) */ 2126 } /* for (count = 0; count < size; count++) */
2127 2127
2128 return 2; 2128 return 2;
2129} 2129}
2130 2130
2131int ZSafe::loadFinalize(void) 2131int ZSafe::loadFinalize(void)
2132{ 2132{
2133 fclose (fd); 2133 fclose (fd);
2134 if (buffer) free(buffer); 2134 if (buffer) free(buffer);
2135 return PWERR_GOOD; 2135 return PWERR_GOOD;
2136} 2136}
2137 2137
2138bool ZSafe::saveDocument(const char* _filename, 2138bool ZSafe::saveDocument(const char* _filename,
2139 bool withPwd, 2139 bool withPwd,
2140 const char* ) 2140 const char* )
2141{ 2141{
2142 if (filename.isEmpty()) 2142 if (filename.isEmpty())
2143 { 2143 {
2144 QMessageBox::critical( 0, tr("ZSafe"), 2144 QMessageBox::critical( 0, tr("ZSafe"),
2145 tr("No document defined.\nYou have to create a new document")); 2145 tr("No document defined.\nYou have to create a new document"));
2146 return false; 2146 return false;
2147 } 2147 }
2148 2148
2149 // if (m_password.isEmpty()) 2149 // if (m_password.isEmpty())
2150 // withPwd = true; // the document must be saved with a valid password 2150 // withPwd = true; // the document must be saved with a valid password
2151 if (withPwd) 2151 if (withPwd)
2152 { 2152 {
2153 bool pwdOk = FALSE; 2153 bool pwdOk = FALSE;
2154 while (!pwdOk) 2154 while (!pwdOk)
2155 { 2155 {
2156 getDocPassword(tr("Enter Password")); 2156 getDocPassword(tr("Enter Password"));
2157 if (m_password.isEmpty()) 2157 if (m_password.isEmpty())
2158 { 2158 {
2159 2159
2160 QMessageBox::critical( 0, tr("ZSafe"), 2160 QMessageBox::critical( 0, tr("ZSafe"),
2161 tr("Password is empty.\nPlease enter again.")); 2161 tr("Password is empty.\nPlease enter again."));
2162 continue; 2162 continue;
2163 } 2163 }
2164 2164
2165 QString firstPasswd = m_password; 2165 QString firstPasswd = m_password;
2166 2166
2167 getDocPassword(tr("Reenter Password")); 2167 getDocPassword(tr("Reenter Password"));
2168 if (m_password.isEmpty()) 2168 if (m_password.isEmpty())
2169 { 2169 {
2170 QMessageBox::critical( 0, tr("ZSafe"), 2170 QMessageBox::critical( 0, tr("ZSafe"),
2171 tr("Password is empty.\nPlease enter again.")); 2171 tr("Password is empty.\nPlease enter again."));
2172 continue; 2172 continue;
2173 } 2173 }
2174 if (firstPasswd != m_password) 2174 if (firstPasswd != m_password)
2175 { 2175 {
2176 2176
2177 QMessageBox::critical( 0, tr("ZSafe"), 2177 QMessageBox::critical( 0, tr("ZSafe"),
2178 tr("Passwords must be identical.\nPlease enter again.")); 2178 tr("Passwords must be identical.\nPlease enter again."));
2179 continue; 2179 continue;
2180 } 2180 }
2181 pwdOk = TRUE; 2181 pwdOk = TRUE;
2182 modified = false; 2182 modified = false;
2183 } 2183 }
2184 } 2184 }
2185 else if (modified) 2185 else if (modified)
2186 { 2186 {
2187 QString fns(_filename); 2187 QString fns(_filename);
2188 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2188 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2189 switch( QMessageBox::information( this, tr("ZSafe"), 2189 switch( QMessageBox::information( this, tr("ZSafe"),
2190 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2190 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2191 tr("&Save"), 2191 tr("&Save"),
2192 tr("&Don't Save"), 2192 tr("&Don't Save"),
2193 0 // Enter == button 0 2193 0 // Enter == button 0
2194 ) ) 2194 ) )
2195 { // Escape == button 2 2195 { // Escape == button 2
2196 case 0: // Save clicked, Alt-S or Enter pressed. 2196 case 0: // Save clicked, Alt-S or Enter pressed.
2197 modified = false; 2197 modified = false;
2198 break; 2198 break;
2199 case 1: // Don't Save clicked or Alt-D pressed 2199 case 1: // Don't Save clicked or Alt-D pressed
2200 modified = false; 2200 modified = false;
2201 return true; 2201 return true;
2202 } 2202 }
2203 } 2203 }
2204 modified = false; 2204 modified = false;
2205 2205
2206 if (m_password.isEmpty()) 2206 if (m_password.isEmpty())
2207 return false; 2207 return false;
2208 2208
2209 int retval = saveInit(_filename, m_password); 2209 int retval = saveInit(_filename, m_password);
2210 // int retval = saveInit(_filename, "test"); 2210 // int retval = saveInit(_filename, "test");
2211 if (retval != PWERR_GOOD) { 2211 if (retval != PWERR_GOOD) {
2212 return false; 2212 return false;
2213 } 2213 }
2214 2214
2215 char* entry[FIELD_SIZE]; 2215 char* entry[FIELD_SIZE];
2216 2216
2217 // save the validation entry 2217 // save the validation entry
2218 { 2218 {
2219 int i=0; 2219 int i=0;
2220 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2220 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2221 strcpy(entry[i++], "ZSAFECATEGORY"); 2221 strcpy(entry[i++], "ZSAFECATEGORY");
2222 entry[i] = (char*)malloc(strlen("name")+1); 2222 entry[i] = (char*)malloc(strlen("name")+1);
2223 strcpy(entry[i++], "name"); 2223 strcpy(entry[i++], "name");
2224 entry[i] = (char*)malloc(strlen("username")+1); 2224 entry[i] = (char*)malloc(strlen("username")+1);
2225 strcpy(entry[i++], "username"); 2225 strcpy(entry[i++], "username");
2226 entry[i] = (char*)malloc(strlen("password")+1); 2226 entry[i] = (char*)malloc(strlen("password")+1);
2227 strcpy(entry[i++], "password"); 2227 strcpy(entry[i++], "password");
2228 entry[i] = (char*)malloc(strlen("comment")+1); 2228 entry[i] = (char*)malloc(strlen("comment")+1);
2229 strcpy(entry[i++], "comment"); 2229 strcpy(entry[i++], "comment");
2230 2230
2231 entry[i] = (char*)malloc(strlen("field5")+1); 2231 entry[i] = (char*)malloc(strlen("field5")+1);
2232 strcpy(entry[i++], "field5"); 2232 strcpy(entry[i++], "field5");
2233 entry[i] = (char*)malloc(strlen("field6")+1); 2233 entry[i] = (char*)malloc(strlen("field6")+1);
2234 strcpy(entry[i++], "field6"); 2234 strcpy(entry[i++], "field6");
2235 2235
2236 retval = saveEntry(entry); 2236 retval = saveEntry(entry);
2237 for (int z=0; z<i; z++) free(entry[z]); 2237 for (int z=0; z<i; z++) free(entry[z]);
2238 if (retval == PWERR_DATA) { 2238 if (retval == PWERR_DATA) {
2239 qWarning("1: Error writing file, contents not saved"); 2239 qWarning("1: Error writing file, contents not saved");
2240 saveFinalize(); 2240 saveFinalize();
2241 return false; 2241 return false;
2242 } 2242 }
2243// #ifndef WIN32 2243// #ifndef WIN32
2244 conf->writeEntry(APP_KEY+"valzsafe", 1); 2244 conf->writeEntry(APP_KEY+"valzsafe", 1);
2245// #endif 2245// #endif
2246 saveConf(); 2246 saveConf();
2247 } 2247 }
2248 2248
2249 QListViewItem *i; 2249 QListViewItem *i;
2250 // step through all categories 2250 // step through all categories
2251 for (i = ListView->firstChild(); 2251 for (i = ListView->firstChild();
2252 i != NULL; 2252 i != NULL;
2253 i = i->nextSibling()) 2253 i = i->nextSibling())
2254 { 2254 {
2255 // step through all subitems 2255 // step through all subitems
2256 QListViewItem *si; 2256 QListViewItem *si;
2257 for (si = i->firstChild(); 2257 for (si = i->firstChild();
2258 si != NULL; 2258 si != NULL;
2259 si = si->nextSibling()) 2259 si = si->nextSibling())
2260 { 2260 {
2261 int j=0; 2261 int j=0;
2262 entry[j] = (char*)malloc(strlen(i->text(0))+1); 2262 entry[j] = (char*)malloc(strlen(i->text(0))+1);
2263 strcpy(entry[j++], i->text(0)); 2263 strcpy(entry[j++], i->text(0));
2264 entry[j] = (char*)malloc(strlen(si->text(0))+1); 2264 entry[j] = (char*)malloc(strlen(si->text(0))+1);
2265 strcpy(entry[j++], si->text(0)); 2265 strcpy(entry[j++], si->text(0));
2266 entry[j] = (char*)malloc(strlen(si->text(1))+1); 2266 entry[j] = (char*)malloc(strlen(si->text(1))+1);
2267 strcpy(entry[j++], si->text(1)); 2267 strcpy(entry[j++], si->text(1));
2268 entry[j] = (char*)malloc(strlen(si->text(2))+1); 2268 entry[j] = (char*)malloc(strlen(si->text(2))+1);
2269 strcpy(entry[j++], si->text(2)); 2269 strcpy(entry[j++], si->text(2));
2270 entry[j] = (char*)malloc(strlen(si->text(3))+1); 2270 entry[j] = (char*)malloc(strlen(si->text(3))+1);
2271 strcpy(entry[j++], si->text(3)); 2271 strcpy(entry[j++], si->text(3));
2272 2272
2273 entry[j] = (char*)malloc(strlen(si->text(4))+1); 2273 entry[j] = (char*)malloc(strlen(si->text(4))+1);
2274 strcpy(entry[j++], si->text(4)); 2274 strcpy(entry[j++], si->text(4));
2275 entry[j] = (char*)malloc(strlen(si->text(5))+1); 2275 entry[j] = (char*)malloc(strlen(si->text(5))+1);
2276 strcpy(entry[j++], si->text(5)); 2276 strcpy(entry[j++], si->text(5));
2277 2277
2278 retval = saveEntry(entry); 2278 retval = saveEntry(entry);
2279 for (int z=0; z<j; z++) 2279 for (int z=0; z<j; z++)
2280 { 2280 {
2281 free(entry[z]); 2281 free(entry[z]);
2282 } 2282 }
2283 if (retval == PWERR_DATA) { 2283 if (retval == PWERR_DATA) {
2284 qWarning("1: Error writing file, contents not saved"); 2284 qWarning("1: Error writing file, contents not saved");
2285 saveFinalize(); 2285 saveFinalize();
2286 return false; 2286 return false;
2287 } 2287 }
2288 2288
2289 } 2289 }
2290 } 2290 }
2291 2291
2292 if (saveFinalize() == PWERR_DATA) { 2292 if (saveFinalize() == PWERR_DATA) {
2293 qWarning("2: Error writing file, contents not saved"); 2293 qWarning("2: Error writing file, contents not saved");
2294 return false; 2294 return false;
2295 } else { 2295 } else {
2296#ifndef DESKTOP 2296#ifndef DESKTOP
2297 Global::statusMessage (tr("Password file saved.")); 2297 Global::statusMessage (tr("Password file saved."));
2298#endif 2298#endif
2299 modified = false; 2299 modified = false;
2300 return true; 2300 return true;
2301 } 2301 }
2302} 2302}
2303 2303
2304PasswordForm *newPwdDialog; 2304PasswordForm *newPwdDialog;
2305bool newPwdDialogResult = false; 2305bool newPwdDialogResult = false;
2306void ZSafe::setPasswordDialogDone() 2306void ZSafe::setPasswordDialogDone()
2307{ 2307{
2308 newPwdDialogResult = true; 2308 newPwdDialogResult = true;
2309 newPwdDialog->close(); 2309 newPwdDialog->close();
2310} 2310}
2311 2311
2312void ZSafe::getDocPassword(QString title) 2312void ZSafe::getDocPassword(QString title)
2313{ 2313{
2314qWarning ("getDocPassword"); 2314qWarning ("getDocPassword");
2315 // open the 'Password' dialog 2315 // open the 'Password' dialog
2316 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2316 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2317 newPwdDialog = dialog; 2317 newPwdDialog = dialog;
2318 newPwdDialogResult = false; 2318 newPwdDialogResult = false;
2319 2319
2320 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2320 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2321 this, SLOT( setPasswordDialogDone() ) ); 2321 this, SLOT( setPasswordDialogDone() ) );
2322 2322
2323 // CS: !!! 2323 // CS: !!!
2324 // int pos = filename.findRev ('/'); 2324 // int pos = filename.findRev ('/');
2325 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2325 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2326#ifdef WIN32 2326#ifdef WIN32
2327 dialog->setCaption("Qt " + ti); 2327 dialog->setCaption("Qt " + ti);
2328#else 2328#else
2329 dialog->setCaption(ti); 2329 dialog->setCaption(ti);
2330#endif 2330#endif
2331 // dialog->setCaption(title); 2331 // dialog->setCaption(title);
2332 2332
2333 dialog->PasswordField->setFocus(); 2333 dialog->PasswordField->setFocus();
2334 DialogCode result = (DialogCode) dialog->exec(); 2334 DialogCode result = (DialogCode) dialog->exec();
2335#ifdef DESKTOP 2335#ifdef DESKTOP
2336 result = Accepted; 2336 result = Accepted;
2337#endif 2337#endif
2338 2338
2339 QString password; 2339 QString password;
2340 if (result == Accepted || newPwdDialogResult) 2340 if (result == Accepted || newPwdDialogResult)
2341 { 2341 {
2342 m_password = dialog->PasswordField->text(); 2342 m_password = dialog->PasswordField->text();
2343 } 2343 }
2344 else 2344 else
2345 { 2345 {
2346 exitZs (1); 2346 exitZs (1);
2347 } 2347 }
2348} 2348}
2349 2349
2350int ZSafe::saveInit(const char *_filename, const char *password) 2350int ZSafe::saveInit(const char *_filename, const char *password)
2351{ 2351{
2352 char key[128]; 2352 char key[128];
2353 unsigned int j = 0; 2353 unsigned int j = 0;
2354 unsigned int keylength; 2354 unsigned int keylength;
2355 // int val; 2355 // int val;
2356 int count2; 2356 int count2;
2357 Krc2* krc2 = new Krc2(); 2357 Krc2* krc2 = new Krc2();
2358 2358
2359 /* first we should check the permissions of the filename */ 2359 /* first we should check the permissions of the filename */
2360/* 2360/*
2361 if (QFile::exists(_filename)) { 2361 if (QFile::exists(_filename)) {
2362 val = checkFile(_filename); 2362 val = checkFile(_filename);
2363 if (val != PWERR_GOOD) 2363 if (val != PWERR_GOOD)
2364 return val; 2364 return val;
2365 } else 2365 } else
2366 { 2366 {
2367 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2367 val = creat (_filename, (S_IRUSR | S_IWUSR));
2368 if (val == -1) 2368 if (val == -1)
2369 return PWERR_OPEN; 2369 return PWERR_OPEN;
2370 else 2370 else
2371 close(val); 2371 close(val);
2372 } 2372 }
2373*/ 2373*/
2374 QFileInfo f (_filename); 2374 QFileInfo f (_filename);
2375 save_buffer_length = f.size(); 2375 save_buffer_length = f.size();
2376 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2376 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2377 2377
2378 fd = fopen (_filename, "wb"); 2378 fd = fopen (_filename, "wb");
2379 if (fd == NULL) 2379 if (fd == NULL)
2380 return PWERR_OPEN; 2380 return PWERR_OPEN;
2381 2381
2382 buffer = (char*)malloc(save_buffer_length); 2382 buffer = (char*)malloc(save_buffer_length);
2383 2383
2384 /* make the key ready */ 2384 /* make the key ready */
2385 for (j = 0; password[j] != '\0'; j++) { 2385 for (j = 0; password[j] != '\0'; j++) {
2386 key[j] = password[j]; 2386 key[j] = password[j];
2387 } 2387 }
2388 keylength = j; 2388 keylength = j;
2389 krc2->rc2_expandkey (key, keylength, 128); 2389 krc2->rc2_expandkey (key, keylength, 128);
2390 2390
2391 /* First, we make the IV */ 2391 /* First, we make the IV */
2392 for (count2 = 0; count2 < 4; count2++) { 2392 for (count2 = 0; count2 < 4; count2++) {
2393 iv[count2] = rand (); 2393 iv[count2] = rand ();
2394 putc ((unsigned char) (iv[count2] >> 8), fd); 2394 putc ((unsigned char) (iv[count2] >> 8), fd);
2395 putc ((unsigned char) (iv[count2] & 0xff), fd); 2395 putc ((unsigned char) (iv[count2] & 0xff), fd);
2396 } 2396 }
2397 2397
2398 bufferIndex = 0; 2398 bufferIndex = 0;
2399 return PWERR_GOOD; 2399 return PWERR_GOOD;
2400} 2400}
2401 2401
2402 2402
2403int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2403int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2404{ 2404{
2405 char *text1; 2405 char *text1;
2406 int count2, count3; 2406 int count2, count3;
2407 unsigned short ciphertext[4]; 2407 unsigned short ciphertext[4];
2408 Krc2* krc2 = new Krc2(); 2408 Krc2* krc2 = new Krc2();
2409 2409
2410 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2410 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2411 2411
2412 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2412 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2413 text1 = entry[count2]; 2413 text1 = entry[count2];
2414 if (strlen (text1) == 0) { 2414 if (strlen (text1) == 0) {
2415 strncat(buffer, " ", strlen(" ")); 2415 strncat(buffer, " ", strlen(" "));
2416 } else { 2416 } else {
2417 strncat(buffer, text1, strlen(text1)); 2417 strncat(buffer, text1, strlen(text1));
2418 } 2418 }
2419 /* Use 255 as the marker. \n is too tough to test for */ 2419 /* Use 255 as the marker. \n is too tough to test for */
2420 buffer[strlen (buffer)] = 255; 2420 buffer[strlen (buffer)] = 255;
2421 } /*for (count2 = 0; count2 < 5; count2++)*/ 2421 } /*for (count2 = 0; count2 < 5; count2++)*/
2422 count2 = 0; 2422 count2 = 0;
2423 /* I'm using CBC mode and encrypting the data straight from top down. 2423 /* I'm using CBC mode and encrypting the data straight from top down.
2424 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2424 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2425 * PKCS 5 padding (explained at the code section 2425 * PKCS 5 padding (explained at the code section
2426 */ 2426 */
2427 while (count2 < (int)strlen (buffer)) { 2427 while (count2 < (int)strlen (buffer)) {
2428#ifndef WORDS_BIGENDIAN 2428#ifndef WORDS_BIGENDIAN
2429 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2429 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2430 plaintext[bufferIndex] += buffer[count2] & 0xff; 2430 plaintext[bufferIndex] += buffer[count2] & 0xff;
2431#endif 2431#endif
2432#ifdef WORDS_BIGENDIAN 2432#ifdef WORDS_BIGENDIAN
2433 plaintext[bufferIndex] = buffer[count2] << 8; 2433 plaintext[bufferIndex] = buffer[count2] << 8;
2434 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2434 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2435#endif 2435#endif
2436 bufferIndex++; 2436 bufferIndex++;
2437 if (bufferIndex == 4) { 2437 if (bufferIndex == 4) {
2438 krc2->rc2_encrypt (plaintext); 2438 krc2->rc2_encrypt (plaintext);
2439 2439
2440 for (count3 = 0; count3 < 4; count3++) { 2440 for (count3 = 0; count3 < 4; count3++) {
2441 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2441 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2442 2442
2443 /* Now store the ciphertext as the iv */ 2443 /* Now store the ciphertext as the iv */
2444 iv[count3] = plaintext[count3]; 2444 iv[count3] = plaintext[count3];
2445 2445
2446 /* reset the buffer index */ 2446 /* reset the buffer index */
2447 bufferIndex = 0; 2447 bufferIndex = 0;
2448 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2448 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2449 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2449 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2450 } /*for (count3 = 0; count3 < 5; count3++)*/ 2450 } /*for (count3 = 0; count3 < 5; count3++)*/
2451 } /*if (bufferIndex == 5)*/ 2451 } /*if (bufferIndex == 5)*/
2452 /* increment a short, not a byte */ 2452 /* increment a short, not a byte */
2453 count2 += 2; 2453 count2 += 2;
2454 } /*while (count2 < strlen (buffer))*/ 2454 } /*while (count2 < strlen (buffer))*/
2455 int ret = PWERR_GOOD; 2455 int ret = PWERR_GOOD;
2456 return ret; 2456 return ret;
2457} 2457}
2458 2458
2459int ZSafe::saveFinalize(void) 2459int ZSafe::saveFinalize(void)
2460{ 2460{
2461 int count1, retval = PWERR_GOOD; 2461 int count1, retval = PWERR_GOOD;
2462 unsigned short ciphertext[4]; 2462 unsigned short ciphertext[4];
2463 Krc2* krc2 = new Krc2(); 2463 Krc2* krc2 = new Krc2();
2464 2464
2465 /* Tack on the PKCS 5 padding 2465 /* Tack on the PKCS 5 padding
2466 * How it works is we fill up the last n bytes with the value n 2466 * How it works is we fill up the last n bytes with the value n
2467 * 2467 *
2468 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2468 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2469 * over, leaving us 3 short, so we fill it in with 3's. 2469 * over, leaving us 3 short, so we fill it in with 3's.
2470 * 2470 *
2471 * If we come out even, we fill it with 8 8s 2471 * If we come out even, we fill it with 8 8s
2472 * 2472 *
2473 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2473 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2474 * so, half everything 2474 * so, half everything
2475 */ 2475 */
2476 for (count1 = bufferIndex; count1 < 4; count1++) { 2476 for (count1 = bufferIndex; count1 < 4; count1++) {
2477 plaintext[count1] = (4 - bufferIndex); 2477 plaintext[count1] = (4 - bufferIndex);
2478 } 2478 }
2479 krc2->rc2_encrypt (plaintext); 2479 krc2->rc2_encrypt (plaintext);
2480 for (count1 = 0; count1 < 4; count1++) { 2480 for (count1 = 0; count1 < 4; count1++) {
2481 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2481 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2482 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2482 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2483 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2483 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2484 } 2484 }
2485 2485
2486 fclose (fd); 2486 fclose (fd);
2487 free(buffer); 2487 free(buffer);
2488 return retval; 2488 return retval;
2489} 2489}
2490 2490
2491void ZSafe::quitMe () 2491void ZSafe::quitMe ()
2492{ 2492{
2493 qWarning ("QUIT..."); 2493 qWarning ("QUIT...");
2494 2494
2495 if (modified) 2495 if (modified)
2496 { 2496 {
2497 switch( QMessageBox::information( this, tr("ZSafe"), 2497 switch( QMessageBox::information( this, tr("ZSafe"),
2498 tr("Do you want to save\nbefore exiting?"), 2498 tr("Do you want to save\nbefore exiting?"),
2499 tr("&Save"), 2499 tr("&Save"),
2500 tr("S&ave with\nnew\npassword"), 2500 tr("S&ave with\nnew\npassword"),
2501 tr("&Don't Save"), 2501 tr("&Don't Save"),
2502 0 // Enter == button 0 2502 0 // Enter == button 0
2503 ) ) 2503 ) )
2504 { // Escape == button 2 2504 { // Escape == button 2
2505 case 0: // Save clicked, Alt-S or Enter pressed. 2505 case 0: // Save clicked, Alt-S or Enter pressed.
2506 // save 2506 // save
2507 modified = false; 2507 modified = false;
2508 saveDocument(filename, FALSE); 2508 saveDocument(filename, FALSE);
2509 exitZs (1); 2509 exitZs (1);
2510 break; 2510 break;
2511 case 1: // 2511 case 1: //
2512 // Save with new password 2512 // Save with new password
2513 modified = false; 2513 modified = false;
2514 saveDocument(filename, TRUE); 2514 saveDocument(filename, TRUE);
2515 exitZs (1); 2515 exitZs (1);
2516 break; 2516 break;
2517 case 2: // Don't Save clicked or Alt-D pressed 2517 case 2: // Don't Save clicked or Alt-D pressed
2518 // don't save but exitZs 2518 // don't save but exitZs
2519 exitZs (1); 2519 exitZs (1);
2520 break; 2520 break;
2521 } 2521 }
2522 } 2522 }
2523 exitZs (1); 2523 exitZs (1);
2524 2524
2525} 2525}
2526 2526
2527void ZSafe::categoryFieldActivated( const QString& category) 2527void ZSafe::categoryFieldActivated( const QString& category)
2528{ 2528{
2529 if (categoryDialog) 2529 if (categoryDialog)
2530 setCategoryDialogFields(categoryDialog, category); 2530 setCategoryDialogFields(categoryDialog, category);
2531} 2531}
2532 2532
2533void ZSafe::addCategory() 2533void ZSafe::addCategory()
2534{ 2534{
2535 if (filename.isEmpty()) 2535 if (filename.isEmpty())
2536 { 2536 {
2537 QMessageBox::critical( 0, tr("ZSafe"), 2537 QMessageBox::critical( 0, tr("ZSafe"),
2538 tr("No document defined.\nYou have to create a new document")); 2538 tr("No document defined.\nYou have to create a new document"));
2539 return; 2539 return;
2540 } 2540 }
2541 else 2541 else
2542 { 2542 {
2543 // open the 'Category' dialog 2543 // open the 'Category' dialog
2544 bool initIcons = false; 2544 bool initIcons = false;
2545 // open the 'Category' dialog 2545 // open the 'Category' dialog
2546 CategoryDialog *dialog; 2546 CategoryDialog *dialog;
2547 if (categoryDialog) 2547 if (categoryDialog)
2548 { 2548 {
2549 dialog = categoryDialog; 2549 dialog = categoryDialog;
2550 } 2550 }
2551 else 2551 else
2552 { 2552 {
2553 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2553 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2554#ifdef WIN32 2554#ifdef WIN32
2555 categoryDialog->setCaption ("Qt " + tr("Category")); 2555 categoryDialog->setCaption ("Qt " + tr("Category"));
2556#endif 2556#endif
2557 dialog = categoryDialog; 2557 dialog = categoryDialog;
2558 connect( dialog->CategoryField, 2558 connect( dialog->CategoryField,
2559 SIGNAL( activated ( const QString &)), 2559 SIGNAL( activated ( const QString &)),
2560 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2560 this, SLOT( categoryFieldActivated( const QString & ) ) );
2561 initIcons = true; 2561 initIcons = true;
2562 } 2562 }
2563 2563
2564#ifdef DESKTOP 2564#ifdef DESKTOP
2565#ifndef WIN32 2565#ifndef WIN32
2566 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2566 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2567#else 2567#else
2568 // read all categories from the config file and store 2568 // read all categories from the config file and store
2569 // into a list 2569 // into a list
2570 QFile f (cfgFile); 2570 QFile f (cfgFile);
2571 QStringList list; 2571 QStringList list;
2572 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2572 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2573 QTextStream t( &f ); // use a text stream 2573 QTextStream t( &f ); // use a text stream
2574 QString s; 2574 QString s;
2575 int n = 1; 2575 int n = 1;
2576 while ( !t.eof() ) { // until end of file... 2576 while ( !t.eof() ) { // until end of file...
2577 s = t.readLine(); // line of text excluding '\n' 2577 s = t.readLine(); // line of text excluding '\n'
2578 list.append(s); 2578 list.append(s);
2579 } 2579 }
2580 f.close(); 2580 f.close();
2581 } 2581 }
2582#endif 2582#endif
2583#else 2583#else
2584 // read all categories from the config file and store 2584 // read all categories from the config file and store
2585 // into a list 2585 // into a list
2586 QFile f (cfgFile); 2586 QFile f (cfgFile);
2587 QStringList list; 2587 QStringList list;
2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2588 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2589 QTextStream t( &f ); // use a text stream 2589 QTextStream t( &f ); // use a text stream
2590 QString s; 2590 QString s;
2591 while ( !t.eof() ) { // until end of file... 2591 while ( !t.eof() ) { // until end of file...
2592 s = t.readLine(); // line of text excluding '\n' 2592 s = t.readLine(); // line of text excluding '\n'
2593 list.append(s); 2593 list.append(s);
2594 } 2594 }
2595 f.close(); 2595 f.close();
2596 } 2596 }
2597#endif 2597#endif
2598 QStringList::Iterator it = list.begin(); 2598 QStringList::Iterator it = list.begin();
2599 QString categ; 2599 QString categ;
2600 QString firstCategory; 2600 QString firstCategory;
2601 dialog->CategoryField->clear(); // remove all items 2601 dialog->CategoryField->clear(); // remove all items
2602 while( it != list.end() ) 2602 while( it != list.end() )
2603 { 2603 {
2604 QString *cat = new QString (*it); 2604 QString *cat = new QString (*it);
2605 if (cat->contains("-field1", FALSE)) 2605 if (cat->contains("-field1", FALSE))
2606 { 2606 {
2607#ifdef DESKTOP 2607#ifdef DESKTOP
2608#ifndef WIN32 2608#ifndef WIN32
2609 categ = cat->section ("-field1", 0, 0); 2609 categ = cat->section ("-field1", 0, 0);
2610#else 2610#else
2611 int pos = cat->find ("-field1"); 2611 int pos = cat->find ("-field1");
2612 categ = cat->left (pos); 2612 categ = cat->left (pos);
2613#endif 2613#endif
2614#else 2614#else
2615 int pos = cat->find ("-field1"); 2615 int pos = cat->find ("-field1");
2616 cat->truncate(pos); 2616 cat->truncate(pos);
2617 categ = *cat; 2617 categ = *cat;
2618#endif 2618#endif
2619 if (!categ.isEmpty()) 2619 if (!categ.isEmpty())
2620 { 2620 {
2621 dialog->CategoryField->insertItem (categ, -1); 2621 dialog->CategoryField->insertItem (categ, -1);
2622 if (firstCategory.isEmpty()) 2622 if (firstCategory.isEmpty())
2623 firstCategory = categ; 2623 firstCategory = categ;
2624 } 2624 }
2625 } 2625 }
2626 ++it; 2626 ++it;
2627 } 2627 }
2628 2628
2629 2629
2630 if (firstCategory.isEmpty()) 2630 if (firstCategory.isEmpty())
2631 setCategoryDialogFields(dialog); 2631 setCategoryDialogFields(dialog);
2632 else 2632 else
2633 setCategoryDialogFields(dialog, firstCategory); 2633 setCategoryDialogFields(dialog, firstCategory);
2634 2634
2635 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2635 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2636 2636
2637 if (initIcons) 2637 if (initIcons)
2638 { 2638 {
2639 Wait waitDialog(this, tr("Wait dialog")); 2639 Wait waitDialog(this, tr("Wait dialog"));
2640 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2640 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2641 waitDialog.show(); 2641 waitDialog.show();
2642 qApp->processEvents(); 2642 qApp->processEvents();
2643 2643
2644#ifdef DESKTOP 2644#ifdef DESKTOP
2645 QDir d(iconPath); 2645 QDir d(iconPath);
2646#else 2646#else
2647 QDir d(QPEApplication::qpeDir() + "/pics/"); 2647 QDir d(QPEApplication::qpeDir() + "/pics/");
2648#endif 2648#endif
2649 d.setFilter( QDir::Files); 2649 d.setFilter( QDir::Files);
2650 2650
2651 const QFileInfoList *list = d.entryInfoList(); 2651 const QFileInfoList *list = d.entryInfoList();
2652 QFileInfoListIterator it( *list ); // create list iterator 2652 QFileInfoListIterator it( *list ); // create list iterator
2653 QFileInfo *fi; // pointer for traversing 2653 QFileInfo *fi; // pointer for traversing
2654 2654
2655 dialog->IconField->insertItem("predefined"); 2655 dialog->IconField->insertItem("predefined");
2656 while ( (fi=it.current()) ) { // for each file... 2656 while ( (fi=it.current()) ) { // for each file...
2657 QString fileName = fi->fileName(); 2657 QString fileName = fi->fileName();
2658 if(fileName.right(4) == ".png"){ 2658 if(fileName.right(4) == ".png"){
2659 fileName = fileName.mid(0,fileName.length()-4); 2659 fileName = fileName.mid(0,fileName.length()-4);
2660#ifdef DESKTOP 2660#ifdef DESKTOP
2661 QPixmap imageOfFile; 2661 QPixmap imageOfFile;
2662 imageOfFile.load(iconPath + fi->fileName()); 2662 imageOfFile.load(iconPath + fi->fileName());
2663#else 2663#else
2664 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2664 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2665#endif 2665#endif
2666 QImage foo = imageOfFile.convertToImage(); 2666 QImage foo = imageOfFile.convertToImage();
2667 foo = foo.smoothScale(16,16); 2667 foo = foo.smoothScale(16,16);
2668 imageOfFile.convertFromImage(foo); 2668 imageOfFile.convertFromImage(foo);
2669 dialog->IconField->insertItem(imageOfFile,fileName); 2669 dialog->IconField->insertItem(imageOfFile,fileName);
2670 } 2670 }
2671 ++it; 2671 ++it;
2672 } 2672 }
2673 waitDialog.hide(); 2673 waitDialog.hide();
2674 } 2674 }
2675 2675
2676#ifndef WIN32 2676#ifndef WIN32
2677 dialog->show(); 2677 dialog->show();
2678#endif 2678#endif
2679#ifndef DESKTOP 2679#ifndef DESKTOP
2680 // dialog->move (20, 100); 2680 // dialog->move (20, 100);
2681#endif 2681#endif
2682 DialogCode result = (DialogCode) dialog->exec(); 2682 DialogCode result = (DialogCode) dialog->exec();
2683#ifdef DESKTOP 2683#ifdef DESKTOP
2684 result = Accepted; 2684 result = Accepted;
2685#endif 2685#endif
2686 2686
2687 QString category; 2687 QString category;
2688 QString icon; 2688 QString icon;
2689 QString fullIconPath; 2689 QString fullIconPath;
2690 QPixmap *pix; 2690 QPixmap *pix;
2691 if (result == Accepted) 2691 if (result == Accepted)
2692 { 2692 {
2693 modified = true; 2693 modified = true;
2694 category = dialog->CategoryField->currentText(); 2694 category = dialog->CategoryField->currentText();
2695 icon = dialog->IconField->currentText()+".png"; 2695 icon = dialog->IconField->currentText()+".png";
2696 2696
2697 qWarning (category); 2697 qWarning (category);
2698 2698
2699 QListViewItem *li = new ShadedListItem( 1, ListView ); 2699 QListViewItem *li = new ShadedListItem( 1, ListView );
2700 Category *c1 = new Category(); 2700 Category *c1 = new Category();
2701 c1->setCategoryName(category); 2701 c1->setCategoryName(category);
2702 2702
2703 // if (!icon.isEmpty() && !icon.isNull()) 2703 // if (!icon.isEmpty() && !icon.isNull())
2704 if (icon != "predefined.png") 2704 if (icon != "predefined.png")
2705 { 2705 {
2706 // build the full path 2706 // build the full path
2707 fullIconPath = iconPath + icon; 2707 fullIconPath = iconPath + icon;
2708 pix = new QPixmap (fullIconPath); 2708 pix = new QPixmap (fullIconPath);
2709 // pix->resize(14, 14); 2709 // pix->resize(14, 14);
2710 if (pix) 2710 if (pix)
2711 { 2711 {
2712 // save the full pixmap name into the config file 2712 // save the full pixmap name into the config file
2713// #ifndef WIN32 2713// #ifndef WIN32
2714 conf->writeEntry(APP_KEY+category, icon); 2714 conf->writeEntry(APP_KEY+category, icon);
2715// #endif 2715// #endif
2716 saveConf(); 2716 saveConf();
2717 QImage img = pix->convertToImage(); 2717 QImage img = pix->convertToImage();
2718 pix->convertFromImage(img.smoothScale(14,14)); 2718 pix->convertFromImage(img.smoothScale(14,14));
2719 c1->setIcon (*pix); 2719 c1->setIcon (*pix);
2720 c1->setIconName(icon); 2720 c1->setIconName(icon);
2721 } 2721 }
2722 else 2722 else
2723 { 2723 {
2724 QPixmap folder( ( const char** ) general_data ); 2724 QPixmap folder( ( const char** ) general_data );
2725 c1->setIcon (folder); 2725 c1->setIcon (folder);
2726 } 2726 }
2727 } 2727 }
2728 else 2728 else
2729 { 2729 {
2730 c1->setIcon (*getPredefinedIcon(category)); 2730 c1->setIcon (*getPredefinedIcon(category));
2731 } 2731 }
2732 2732
2733 c1->setListItem (li); 2733 c1->setListItem (li);
2734 c1->initListItem(); 2734 c1->initListItem();
2735 categories.insert (c1->getCategoryName(), c1); 2735 categories.insert (c1->getCategoryName(), c1);
2736 2736
2737 saveCategoryDialogFields(dialog); 2737 saveCategoryDialogFields(dialog);
2738 } 2738 }
2739 else 2739 else
2740 { 2740 {
2741 // delete dialog; 2741 // delete dialog;
2742 dialog->hide(); 2742 dialog->hide();
2743 return; 2743 return;
2744 } 2744 }
2745 2745
2746 } 2746 }
2747 2747
2748} 2748}
2749 2749
2750void ZSafe::delCategory() 2750void ZSafe::delCategory()
2751{ 2751{
2752 if (!selectedItem) 2752 if (!selectedItem)
2753 return; 2753 return;
2754 if (isCategory(selectedItem)) 2754 if (isCategory(selectedItem))
2755 { 2755 {
2756 switch( QMessageBox::information( this, tr("ZSafe"), 2756 switch( QMessageBox::information( this, tr("ZSafe"),
2757 tr("Do you want to delete?"), 2757 tr("Do you want to delete?"),
2758 tr("&Delete"), tr("D&on't Delete"), 2758 tr("&Delete"), tr("D&on't Delete"),
2759 0 // Enter == button 0 2759 0 // Enter == button 0
2760 ) ) { // Escape == button 2 2760 ) ) { // Escape == button 2
2761 case 0: // Delete clicked, Alt-S or Enter pressed. 2761 case 0: // Delete clicked, Alt-S or Enter pressed.
2762 // Delete from the category list 2762 // Delete from the category list
2763 modified = true; 2763 modified = true;
2764 categories.remove (selectedItem->text(0)); 2764 categories.remove (selectedItem->text(0));
2765// #ifndef WIN32 2765// #ifndef WIN32
2766 conf->removeEntry (selectedItem->text(0)); 2766 conf->removeEntry (selectedItem->text(0));
2767// #endif 2767// #endif
2768 saveConf(); 2768 saveConf();
2769 2769
2770 // Delete the selected item and all subitems 2770 // Delete the selected item and all subitems
2771 // step through all subitems 2771 // step through all subitems
2772 QListViewItem *si; 2772 QListViewItem *si;
2773 for (si = selectedItem->firstChild(); 2773 for (si = selectedItem->firstChild();
2774 si != NULL; ) 2774 si != NULL; )
2775 { 2775 {
2776 QListViewItem *_si = si; 2776 QListViewItem *_si = si;
2777 si = si->nextSibling(); 2777 si = si->nextSibling();
2778 selectedItem->takeItem(_si); // remove from view list 2778 selectedItem->takeItem(_si); // remove from view list
2779 if (_si) delete _si; 2779 if (_si) delete _si;
2780 } 2780 }
2781 ListView->takeItem(selectedItem); 2781 ListView->takeItem(selectedItem);
2782 delete selectedItem; 2782 delete selectedItem;
2783 2783
2784 selectedItem = NULL; 2784 selectedItem = NULL;
2785 break; 2785 break;
2786 case 1: // Don't delete 2786 case 1: // Don't delete
2787 break; 2787 break;
2788 } 2788 }
2789 2789
2790 } 2790 }
2791} 2791}
2792 2792
2793void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2793void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2794{ 2794{
2795 if (!dialog) 2795 if (!dialog)
2796 return; 2796 return;
2797 2797
2798 QString icon; 2798 QString icon;
2799 if (selectedItem) 2799 if (selectedItem)
2800 { 2800 {
2801 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2801 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2802 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2802 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2803 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2803 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2804 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2804 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2805 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2805 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2806 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2806 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2807 2807
2808 Category *cat= categories.find (selectedItem->text(0)); 2808 Category *cat= categories.find (selectedItem->text(0));
2809 if (cat) 2809 if (cat)
2810 { 2810 {
2811 icon = cat->getIconName(); 2811 icon = cat->getIconName();
2812 } 2812 }
2813 else
2814 icon = conf->readEntry(APP_KEY+selectedItem->text(0));
2813 } 2815 }
2814 else 2816 else
2815 { 2817 {
2816 dialog->Field1->setText(tr("Name")); 2818 dialog->Field1->setText(tr("Name"));
2817 dialog->Field2->setText(tr("Username")); 2819 dialog->Field2->setText(tr("Username"));
2818 dialog->Field3->setText(tr("Password")); 2820 dialog->Field3->setText(tr("Password"));
2819 dialog->Field4->setText(tr("Comment")); 2821 dialog->Field4->setText(tr("Comment"));
2820 dialog->Field5->setText(tr("Field 4")); 2822 dialog->Field5->setText(tr("Field 4"));
2821 dialog->Field6->setText(tr("Field 5")); 2823 dialog->Field6->setText(tr("Field 5"));
2822 } 2824 }
2823 2825
2824#ifdef DESKTOP 2826#ifdef DESKTOP
2825 QDir d(iconPath); 2827 QDir d(iconPath);
2826#else 2828#else
2827 QDir d(QPEApplication::qpeDir() + "/pics/"); 2829 QDir d(QPEApplication::qpeDir() + "/pics/");
2828#endif 2830#endif
2829 d.setFilter( QDir::Files); 2831 d.setFilter( QDir::Files);
2830 2832
2831 const QFileInfoList *list = d.entryInfoList(); 2833 const QFileInfoList *list = d.entryInfoList();
2832 int i=0; 2834 int i=0;
2833 QFileInfoListIterator it( *list ); // create list iterator 2835 QFileInfoListIterator it( *list ); // create list iterator
2834 QFileInfo *fi; // pointer for traversing 2836 QFileInfo *fi; // pointer for traversing
2835 if (icon.isEmpty() || icon.isNull()) 2837 if (icon.isEmpty() || icon.isNull())
2836 { 2838 {
2837 dialog->IconField->setCurrentItem(0); 2839 dialog->IconField->setCurrentItem(0);
2838 } 2840 }
2839 else 2841 else
2840 { 2842 {
2841 while ( (fi=it.current()) ) 2843 while ( (fi=it.current()) )
2842 { // for each file... 2844 { // for each file...
2843 QString fileName = fi->fileName(); 2845 QString fileName = fi->fileName();
2844 if(fileName.right(4) == ".png") 2846 if(fileName.right(4) == ".png")
2845 { 2847 {
2846 fileName = fileName.mid(0,fileName.length()-4); 2848 fileName = fileName.mid(0,fileName.length()-4);
2847 2849
2848 if(fileName+".png"==icon) 2850 if(fileName+".png"==icon)
2849 { 2851 {
2850 dialog->IconField->setCurrentItem(i+1); 2852 dialog->IconField->setCurrentItem(i+1);
2851 break; 2853 break;
2852 } 2854 }
2853 ++i; 2855 ++i;
2854 } 2856 }
2855 ++it; 2857 ++it;
2856 } 2858 }
2857 } 2859 }
2858} 2860}
2859 2861
2860void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2862void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2861{ 2863{
2862 if (!dialog) 2864 if (!dialog)
2863 return; 2865 return;
2864 2866
2865 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 2867 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
2866 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 2868 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
2867 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 2869 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
2868 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 2870 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
2869 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 2871 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
2870 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 2872 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
2871 2873
2872 QString icon; 2874 QString icon;
2873 Category *cat= categories.find (category); 2875 Category *cat= categories.find (category);
2874 if (cat) 2876 if (cat)
2875 { 2877 {
2876 icon = cat->getIconName(); 2878 icon = cat->getIconName();
2877 } 2879 }
2880 else
2881 icon = conf->readEntry(APP_KEY+category);
2878 2882
2879#ifdef DESKTOP 2883#ifdef DESKTOP
2880 QDir d(iconPath); 2884 QDir d(iconPath);
2881#else 2885#else
2882 QDir d(QPEApplication::qpeDir() + "/pics/"); 2886 QDir d(QPEApplication::qpeDir() + "/pics/");
2883#endif 2887#endif
2884 d.setFilter( QDir::Files); 2888 d.setFilter( QDir::Files);
2885 2889
2886 const QFileInfoList *list = d.entryInfoList(); 2890 const QFileInfoList *list = d.entryInfoList();
2887 int i=0; 2891 int i=0;
2888 QFileInfoListIterator it( *list ); // create list iterator 2892 QFileInfoListIterator it( *list ); // create list iterator
2889 QFileInfo *fi; // pointer for traversing 2893 QFileInfo *fi; // pointer for traversing
2890 if (icon.isEmpty() || icon.isNull()) 2894 if (icon.isEmpty() || icon.isNull())
2891 { 2895 {
2892 dialog->IconField->setCurrentItem(0); 2896 dialog->IconField->setCurrentItem(0);
2893 } 2897 }
2894 else 2898 else
2895 { 2899 {
2896 while ( (fi=it.current()) ) 2900 while ( (fi=it.current()) )
2897 { // for each file... 2901 { // for each file...
2898 QString fileName = fi->fileName(); 2902 QString fileName = fi->fileName();
2899 if(fileName.right(4) == ".png") 2903 if(fileName.right(4) == ".png")
2900 { 2904 {
2901 fileName = fileName.mid(0,fileName.length()-4); 2905 fileName = fileName.mid(0,fileName.length()-4);
2902 2906
2903 if(fileName+".png"==icon) 2907 if(fileName+".png"==icon)
2904 { 2908 {
2905 dialog->IconField->setCurrentItem(i+1); 2909 dialog->IconField->setCurrentItem(i+1);
2906 break; 2910 break;
2907 } 2911 }
2908 ++i; 2912 ++i;
2909 } 2913 }
2910 ++it; 2914 ++it;
2911 } 2915 }
2912 } 2916 }
2913} 2917}
2914 2918
2915void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 2919void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
2916{ 2920{
2917 QString app_key = APP_KEY; 2921 QString app_key = APP_KEY;
2918#ifndef DESKTOP 2922#ifndef DESKTOP
2919 conf->setGroup ("fieldDefs"); 2923 conf->setGroup ("fieldDefs");
2920#else 2924#else
2921#ifndef WIN32 2925#ifndef WIN32
2922 app_key += "/fieldDefs/"; 2926 app_key += "/fieldDefs/";
2923#endif 2927#endif
2924#endif 2928#endif
2925 QString category = dialog->CategoryField->currentText(); 2929 QString category = dialog->CategoryField->currentText();
2926// #ifndef WIN32 2930// #ifndef WIN32
2927 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 2931 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
2928 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 2932 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
2929 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 2933 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
2930 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 2934 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
2931 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 2935 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
2932 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 2936 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
2933// #endif 2937// #endif
2934 saveConf(); 2938 saveConf();
2935#ifndef DESKTOP 2939#ifndef DESKTOP
2936 conf->setGroup ("zsafe"); 2940 conf->setGroup ("zsafe");
2937#endif 2941#endif
2938} 2942}
2939 2943
2940void ZSafe::editCategory() 2944void ZSafe::editCategory()
2941{ 2945{
2942 if (!selectedItem) 2946 if (!selectedItem)
2943 return; 2947 return;
2944 if (isCategory(selectedItem)) 2948 if (isCategory(selectedItem))
2945 { 2949 {
2946 QString category = selectedItem->text(0); 2950 QString category = selectedItem->text(0);
2947 bool initIcons = false; 2951 bool initIcons = false;
2948 // open the 'Category' dialog 2952 // open the 'Category' dialog
2949 CategoryDialog *dialog; 2953 CategoryDialog *dialog;
2950 if (categoryDialog) 2954 if (categoryDialog)
2951 { 2955 {
2952 dialog = categoryDialog; 2956 dialog = categoryDialog;
2953 } 2957 }
2954 else 2958 else
2955 { 2959 {
2956 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2960 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2957#ifdef WIN32 2961#ifdef WIN32
2958 categoryDialog->setCaption ("Qt " + tr("Category")); 2962 categoryDialog->setCaption ("Qt " + tr("Category"));
2959#endif 2963#endif
2960 dialog = categoryDialog; 2964 dialog = categoryDialog;
2961 connect( dialog->CategoryField, 2965 connect( dialog->CategoryField,
2962 SIGNAL( activated ( const QString &)), 2966 SIGNAL( activated ( const QString &)),
2963 this, SLOT( categoryFieldActivated( const QString & ) ) ); 2967 this, SLOT( categoryFieldActivated( const QString & ) ) );
2964 initIcons = true; 2968 initIcons = true;
2965 } 2969 }
2966 setCategoryDialogFields(dialog); 2970 setCategoryDialogFields(dialog);
2967 2971
2968#ifdef DESKTOP 2972#ifdef DESKTOP
2969#ifndef WIN32 2973#ifndef WIN32
2970 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2974 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2971#else 2975#else
2972 // read all categories from the config file and store 2976 // read all categories from the config file and store
2973 // into a list 2977 // into a list
2974 QFile f (cfgFile); 2978 QFile f (cfgFile);
2975 QStringList list; 2979 QStringList list;
2976 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2980 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2977 QTextStream t( &f ); // use a text stream 2981 QTextStream t( &f ); // use a text stream
2978 QString s; 2982 QString s;
2979 int n = 1; 2983 int n = 1;
2980 while ( !t.eof() ) { // until end of file... 2984 while ( !t.eof() ) { // until end of file...
2981 s = t.readLine(); // line of text excluding '\n' 2985 s = t.readLine(); // line of text excluding '\n'
2982 list.append(s); 2986 list.append(s);
2983 } 2987 }
2984 f.close(); 2988 f.close();
2985 } 2989 }
2986#endif 2990#endif
2987#else 2991#else
2988 // read all categories from the config file and store 2992 // read all categories from the config file and store
2989 // into a list 2993 // into a list
2990 QFile f (cfgFile); 2994 QFile f (cfgFile);
2991 QStringList list; 2995 QStringList list;
2992 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2996 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2993 QTextStream t( &f ); // use a text stream 2997 QTextStream t( &f ); // use a text stream
2994 QString s; 2998 QString s;
2995 while ( !t.eof() ) { // until end of file... 2999 while ( !t.eof() ) { // until end of file...
2996 s = t.readLine(); // line of text excluding '\n' 3000 s = t.readLine(); // line of text excluding '\n'
2997 list.append(s); 3001 list.append(s);
2998 } 3002 }
2999 f.close(); 3003 f.close();
3000 } 3004 }
3001#endif 3005#endif
3002 QStringList::Iterator it = list.begin(); 3006 QStringList::Iterator it = list.begin();
3003 QString categ; 3007 QString categ;
3004 dialog->CategoryField->clear(); // remove all items 3008 dialog->CategoryField->clear(); // remove all items
3005 int i=0; 3009 int i=0;
3006 bool foundCategory = false; 3010 bool foundCategory = false;
3007 while( it != list.end() ) 3011 while( it != list.end() )
3008 { 3012 {
3009 QString *cat = new QString (*it); 3013 QString *cat = new QString (*it);
3010 if (cat->contains("-field1", FALSE)) 3014 if (cat->contains("-field1", FALSE))
3011 { 3015 {
3012#ifdef DESKTOP 3016#ifdef DESKTOP
3013#ifndef WIN32 3017#ifndef WIN32
3014 categ = cat->section ("-field1", 0, 0); 3018 categ = cat->section ("-field1", 0, 0);
3015#else 3019#else
3016 int pos = cat->find ("-field1"); 3020 int pos = cat->find ("-field1");
3017 categ = cat->left (pos); 3021 categ = cat->left (pos);
3018#endif 3022#endif
3019#else 3023#else
3020 int pos = cat->find ("-field1"); 3024 int pos = cat->find ("-field1");
3021 cat->truncate(pos); 3025 cat->truncate(pos);
3022 categ = *cat; 3026 categ = *cat;
3023#endif 3027#endif
3024 if (!categ.isEmpty()) 3028 if (!categ.isEmpty())
3025 { 3029 {
3026 dialog->CategoryField->insertItem (categ, i); 3030 dialog->CategoryField->insertItem (categ, i);
3027 if (category.compare(categ) == 0) 3031 if (category.compare(categ) == 0)
3028 { 3032 {
3029 dialog->CategoryField->setCurrentItem(i); 3033 dialog->CategoryField->setCurrentItem(i);
3030 foundCategory = true; 3034 foundCategory = true;
3031 } 3035 }
3032 i++; 3036 i++;
3033 } 3037 }
3034 } 3038 }
3035 ++it; 3039 ++it;
3036 } 3040 }
3037 if (!foundCategory) 3041 if (!foundCategory)
3038 { 3042 {
3039 dialog->CategoryField->insertItem (category, i); 3043 dialog->CategoryField->insertItem (category, i);
3040 dialog->CategoryField->setCurrentItem(i); 3044 dialog->CategoryField->setCurrentItem(i);
3041 } 3045 }
3042 3046
3043 QString icon; 3047 QString icon;
3044 Category *cat= categories.find (selectedItem->text(0)); 3048 Category *cat= categories.find (selectedItem->text(0));
3045 if (cat) 3049 if (cat)
3046 { 3050 {
3047 icon = cat->getIconName(); 3051 icon = cat->getIconName();
3048 } 3052 }
3049 3053
3050 if (initIcons) 3054 if (initIcons)
3051 { 3055 {
3052 3056
3053 Wait waitDialog(this, tr("Wait dialog")); 3057 Wait waitDialog(this, tr("Wait dialog"));
3054 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3058 waitDialog.waitLabel->setText(tr("Gathering icons..."));
3055 waitDialog.show(); 3059 waitDialog.show();
3056 qApp->processEvents(); 3060 qApp->processEvents();
3057 3061
3058#ifdef DESKTOP 3062#ifdef DESKTOP
3059 QDir d(iconPath); 3063 QDir d(iconPath);
3060#else 3064#else
3061 QDir d(QPEApplication::qpeDir() + "/pics/"); 3065 QDir d(QPEApplication::qpeDir() + "/pics/");
3062#endif 3066#endif
3063 d.setFilter( QDir::Files); 3067 d.setFilter( QDir::Files);
3064 3068
3065 const QFileInfoList *list = d.entryInfoList(); 3069 const QFileInfoList *list = d.entryInfoList();
3066 int i=0; 3070 int i=0;
3067 QFileInfoListIterator it( *list ); // create list iterator 3071 QFileInfoListIterator it( *list ); // create list iterator
3068 QFileInfo *fi; // pointer for traversing 3072 QFileInfo *fi; // pointer for traversing
3069 if (icon.isEmpty() || icon.isNull()) 3073 if (icon.isEmpty() || icon.isNull())
3070 { 3074 {
3071 dialog->IconField->setCurrentItem(0); 3075 dialog->IconField->setCurrentItem(0);
3072 } 3076 }
3073 3077
3074 dialog->IconField->insertItem("predefined"); 3078 dialog->IconField->insertItem("predefined");
3075 while ( (fi=it.current()) ) { // for each file... 3079 while ( (fi=it.current()) ) { // for each file...
3076 QString fileName = fi->fileName(); 3080 QString fileName = fi->fileName();
3077 if(fileName.right(4) == ".png") 3081 if(fileName.right(4) == ".png")
3078 { 3082 {
3079 fileName = fileName.mid(0,fileName.length()-4); 3083 fileName = fileName.mid(0,fileName.length()-4);
3080#ifdef DESKTOP 3084#ifdef DESKTOP
3081 QPixmap imageOfFile; 3085 QPixmap imageOfFile;
3082 imageOfFile.load(iconPath + fi->fileName()); 3086 imageOfFile.load(iconPath + fi->fileName());
3083#else 3087#else
3084 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3088 QPixmap imageOfFile(Resource::loadPixmap(fileName));
3085#endif 3089#endif
3086 QImage foo = imageOfFile.convertToImage(); 3090 QImage foo = imageOfFile.convertToImage();
3087 foo = foo.smoothScale(16,16); 3091 foo = foo.smoothScale(16,16);
3088 imageOfFile.convertFromImage(foo); 3092 imageOfFile.convertFromImage(foo);
3089 dialog->IconField->insertItem(imageOfFile,fileName); 3093 dialog->IconField->insertItem(imageOfFile,fileName);
3090 if(fileName+".png"==icon) 3094 if(fileName+".png"==icon)
3091 dialog->IconField->setCurrentItem(i+1); 3095 dialog->IconField->setCurrentItem(i+1);
3092 ++i; 3096 ++i;
3093 } 3097 }
3094 ++it; 3098 ++it;
3095 } 3099 }
3096 waitDialog.hide(); 3100 waitDialog.hide();
3097 } 3101 }
3098 else 3102 else
3099 { 3103 {
3100#ifdef DESKTOP 3104#ifdef DESKTOP
3101 // QDir d(QDir::homeDirPath() + "/pics/"); 3105 // QDir d(QDir::homeDirPath() + "/pics/");
3102 QDir d(iconPath); 3106 QDir d(iconPath);
3103#else 3107#else
3104 QDir d(QPEApplication::qpeDir() + "/pics/"); 3108 QDir d(QPEApplication::qpeDir() + "/pics/");
3105#endif 3109#endif
3106 d.setFilter( QDir::Files); 3110 d.setFilter( QDir::Files);
3107 3111
3108 const QFileInfoList *list = d.entryInfoList(); 3112 const QFileInfoList *list = d.entryInfoList();
3109 int i=0; 3113 int i=0;
3110 QFileInfoListIterator it( *list ); // create list iterator 3114 QFileInfoListIterator it( *list ); // create list iterator
3111 QFileInfo *fi; // pointer for traversing 3115 QFileInfo *fi; // pointer for traversing
3112 if (icon.isEmpty() || icon.isNull()) 3116 if (icon.isEmpty() || icon.isNull())
3113 { 3117 {
3114 dialog->IconField->setCurrentItem(0); 3118 dialog->IconField->setCurrentItem(0);
3115 } 3119 }
3116 else 3120 else
3117 { 3121 {
3118 3122
3119 while ( (fi=it.current()) ) 3123 while ( (fi=it.current()) )
3120 { // for each file... 3124 { // for each file...
3121 QString fileName = fi->fileName(); 3125 QString fileName = fi->fileName();
3122 if(fileName.right(4) == ".png") 3126 if(fileName.right(4) == ".png")
3123 { 3127 {
3124 fileName = fileName.mid(0,fileName.length()-4); 3128 fileName = fileName.mid(0,fileName.length()-4);
3125 3129
3126 3130
3127 if(fileName+".png"==icon) 3131 if(fileName+".png"==icon)
3128 { 3132 {
3129 dialog->IconField->setCurrentItem(i+1); 3133 dialog->IconField->setCurrentItem(i+1);
3130 break; 3134 break;
3131 } 3135 }
3132 ++i; 3136 ++i;
3133 } 3137 }
3134 ++it; 3138 ++it;
3135 } 3139 }
3136 } 3140 }
3137 } 3141 }
3138 3142
3139 // dialog->show(); 3143 // dialog->show();
3140#ifndef DESKTOP 3144#ifndef DESKTOP
3141 // dialog->move (20, 100); 3145 // dialog->move (20, 100);
3142#endif 3146#endif
3143 DialogCode result = (DialogCode) dialog->exec(); 3147 DialogCode result = (DialogCode) dialog->exec();
3144#ifdef DESKTOP 3148#ifdef DESKTOP
3145 result = Accepted; 3149 result = Accepted;
3146#endif 3150#endif
3147 3151
3148 QString fullIconPath; 3152 QString fullIconPath;
3149 QPixmap *pix; 3153 QPixmap *pix;
3150 if (result == Accepted) 3154 if (result == Accepted)
3151 { 3155 {
3152 modified = true; 3156 modified = true;
3153 if (category != dialog->CategoryField->currentText()) 3157 if (category != dialog->CategoryField->currentText())
3154 { 3158 {
3155 categories.remove (category); 3159 categories.remove (category);
3156// #ifndef WIN32 3160// #ifndef WIN32
3157 conf->removeEntry(category); 3161 conf->removeEntry(category);
3158// #endif 3162// #endif
3159 saveConf(); 3163 saveConf();
3160 } 3164 }
3161 3165
3162 category = dialog->CategoryField->currentText(); 3166 category = dialog->CategoryField->currentText();
3163 icon = dialog->IconField->currentText()+".png"; 3167 icon = dialog->IconField->currentText()+".png";
3164 3168
3165 if (cat) 3169 if (cat)
3166 { 3170 {
3167 qWarning("Category found"); 3171 qWarning("Category found");
3168 3172
3169 // if (!icon.isEmpty() && !icon.isNull()) 3173 // if (!icon.isEmpty() && !icon.isNull())
3170 if (icon != "predefined.png") 3174 if (icon != "predefined.png")
3171 { 3175 {
3172 // build the full path 3176 // build the full path
3173 fullIconPath = iconPath + icon; 3177 fullIconPath = iconPath + icon;
3174 pix = new QPixmap (fullIconPath); 3178 pix = new QPixmap (fullIconPath);
3175 if (pix) 3179 if (pix)
3176 { 3180 {
3177 // save the full pixmap name into the config file 3181 // save the full pixmap name into the config file
3178// #ifndef WIN32 3182// #ifndef WIN32
3179 conf->writeEntry(APP_KEY+category, icon); 3183 conf->writeEntry(APP_KEY+category, icon);
3180// #endif 3184// #endif
3181 saveConf(); 3185 saveConf();
3182 QImage img = pix->convertToImage(); 3186 QImage img = pix->convertToImage();
3183 pix->convertFromImage(img.smoothScale(14,14)); 3187 pix->convertFromImage(img.smoothScale(14,14));
3184 cat->setIconName (icon); 3188 cat->setIconName (icon);
3185 cat->setIcon (*pix); 3189 cat->setIcon (*pix);
3186 } 3190 }
3187 } 3191 }
3188 else 3192 else
3189 { 3193 {
3190// #ifndef WIN32 3194// #ifndef WIN32
3191 conf->removeEntry (category); 3195 conf->removeEntry (category);
3192// #endif 3196// #endif
3193 saveConf(); 3197 saveConf();
3194 cat->setIcon (*getPredefinedIcon(category)); 3198 cat->setIcon (*getPredefinedIcon(category));
3195 } 3199 }
3196 3200
3197 // change the category name of the selected category 3201 // change the category name of the selected category
3198 QListViewItem *catItem = cat->getListItem(); 3202 QListViewItem *catItem = cat->getListItem();
3199 if (catItem) 3203 if (catItem)
3200 { 3204 {
3201 qWarning (category); 3205 qWarning (category);
3202 catItem->setText( 0, tr( category ) ); 3206 catItem->setText( 0, tr( category ) );
3203 cat->setCategoryName (tr(category)); 3207 cat->setCategoryName (tr(category));
3204 cat->initListItem(); 3208 cat->initListItem();
3205 categories.insert (category, cat); 3209 categories.insert (category, cat);
3206 } 3210 }
3207 } 3211 }
3208 saveCategoryDialogFields(dialog); 3212 saveCategoryDialogFields(dialog);
3209 } 3213 }
3210 else 3214 else
3211 { 3215 {
3212 // delete dialog; 3216 // delete dialog;
3213 dialog->hide(); 3217 dialog->hide();
3214 return; 3218 return;
3215 } 3219 }
3216 3220
3217 } 3221 }
3218} 3222}
3219 3223
3220void ZSafe::cutItem() 3224void ZSafe::cutItem()
3221{ 3225{
3222 if (!selectedItem) 3226 if (!selectedItem)
3223 return; 3227 return;
3224 if (!isCategory(selectedItem)) 3228 if (!isCategory(selectedItem))
3225 { 3229 {
3226 IsCut = true; 3230 IsCut = true;
3227 copiedItem = selectedItem; 3231 copiedItem = selectedItem;
3228 } 3232 }
3229} 3233}
3230 3234
3231void ZSafe::copyItem() 3235void ZSafe::copyItem()
3232{ 3236{
3233 if (!selectedItem) 3237 if (!selectedItem)
3234 return; 3238 return;
3235 if (!isCategory(selectedItem)) 3239 if (!isCategory(selectedItem))
3236 { 3240 {
3237 IsCopy = true; 3241 IsCopy = true;
3238 copiedItem = selectedItem; 3242 copiedItem = selectedItem;
3239 } 3243 }
3240} 3244}
3241 3245
3242// paste item into category 3246// paste item into category
3243void ZSafe::pasteItem() 3247void ZSafe::pasteItem()
3244{ 3248{
3245 if (!selectedItem) 3249 if (!selectedItem)
3246 return; 3250 return;
3247 if (isCategory(selectedItem)) 3251 if (isCategory(selectedItem))
3248 { 3252 {
3249 modified = true; 3253 modified = true;
3250 if (IsCut) 3254 if (IsCut)
3251 { 3255 {
3252 if (copiedItem) 3256 if (copiedItem)
3253 { 3257 {
3254 // add the new item 3258 // add the new item
3255 QListViewItem *i = new ShadedListItem (0, selectedItem); 3259 QListViewItem *i = new ShadedListItem (0, selectedItem);
3256 // i->setOpen (TRUE); 3260 // i->setOpen (TRUE);
3257 i->setText (0, copiedItem->text(0)); 3261 i->setText (0, copiedItem->text(0));
3258 i->setText (1, copiedItem->text(1)); 3262 i->setText (1, copiedItem->text(1));
3259 i->setText (2, copiedItem->text(2)); 3263 i->setText (2, copiedItem->text(2));
3260 i->setText (3, copiedItem->text(3)); 3264 i->setText (3, copiedItem->text(3));
3261 i->setText (4, copiedItem->text(4)); 3265 i->setText (4, copiedItem->text(4));
3262 i->setText (5, copiedItem->text(5)); 3266 i->setText (5, copiedItem->text(5));
3263 selectedItem->setOpen( TRUE ); 3267 selectedItem->setOpen( TRUE );
3264 3268
3265 // remove the cutted item 3269 // remove the cutted item
3266 copiedItem->parent()->takeItem(copiedItem); 3270 copiedItem->parent()->takeItem(copiedItem);
3267 selectedItem = NULL; 3271 selectedItem = NULL;
3268 } 3272 }
3269 } 3273 }
3270 else if (IsCopy) 3274 else if (IsCopy)
3271 { 3275 {
3272 if (copiedItem) 3276 if (copiedItem)
3273 { 3277 {
3274 // add the new item 3278 // add the new item
3275 QListViewItem *i = new ShadedListItem (0, selectedItem); 3279 QListViewItem *i = new ShadedListItem (0, selectedItem);
3276 // i->setOpen (TRUE); 3280 // i->setOpen (TRUE);
3277 i->setText (0, copiedItem->text(0)); 3281 i->setText (0, copiedItem->text(0));
3278 i->setText (1, copiedItem->text(1)); 3282 i->setText (1, copiedItem->text(1));
3279 i->setText (2, copiedItem->text(2)); 3283 i->setText (2, copiedItem->text(2));
3280 i->setText (3, copiedItem->text(3)); 3284 i->setText (3, copiedItem->text(3));
3281 i->setText (4, copiedItem->text(4)); 3285 i->setText (4, copiedItem->text(4));
3282 i->setText (5, copiedItem->text(5)); 3286 i->setText (5, copiedItem->text(5));
3283 selectedItem->setOpen( TRUE ); 3287 selectedItem->setOpen( TRUE );
3284 } 3288 }
3285 } 3289 }
3286 } 3290 }
3287 IsCut = false; 3291 IsCut = false;
3288 IsCopy = false; 3292 IsCopy = false;
3289} 3293}
3290 3294
3291void ZSafe::newDocument() 3295void ZSafe::newDocument()
3292{ 3296{
3293 3297
3294 // open the file dialog 3298 // open the file dialog
3295#ifndef DESKTOP 3299#ifndef DESKTOP
3296#ifndef NO_OPIE 3300#ifndef NO_OPIE
3297 QMap<QString, QStringList> mimeTypes; 3301 QMap<QString, QStringList> mimeTypes;
3298 mimeTypes.insert(tr("All"), QStringList() ); 3302 mimeTypes.insert(tr("All"), QStringList() );
3299 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3303 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3300 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3304 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3301 QDir::homeDirPath() + "/Documents/application/zsafe", 3305 QDir::homeDirPath() + "/Documents/application/zsafe",
3302 QString::null, 3306 QString::null,
3303 mimeTypes, 3307 mimeTypes,
3304 this, 3308 this,
3305 tr ("Create new ZSafe document")); 3309 tr ("Create new ZSafe document"));
3306#else 3310#else
3307 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3311 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3308 tr ("Create new ZSafe document"), 3312 tr ("Create new ZSafe document"),
3309 QDir::homeDirPath() + "/Documents/application/zsafe", 3313 QDir::homeDirPath() + "/Documents/application/zsafe",
3310 "*.zsf"); 3314 "*.zsf");
3311#endif 3315#endif
3312#else 3316#else
3313 QString newFile = QFileDialog::getSaveFileName( 3317 QString newFile = QFileDialog::getSaveFileName(
3314 QDir::homeDirPath() + "/Documents/application/zsafe", 3318 QDir::homeDirPath() + "/Documents/application/zsafe",
3315 "ZSafe (*.zsf)", 3319 "ZSafe (*.zsf)",
3316 this, 3320 this,
3317 "ZSafe File Dialog" 3321 "ZSafe File Dialog"
3318 "Choose a ZSafe file" ); 3322 "Choose a ZSafe file" );
3319#endif 3323#endif
3320 3324
3321 // open the new document 3325 // open the new document
3322 if (newFile && newFile.length() > 0 ) 3326 if (newFile && newFile.length() > 0 )
3323 { 3327 {
3324 // save the previous opened document 3328 // save the previous opened document
3325 if (!filename.isEmpty()) 3329 if (!filename.isEmpty())
3326 saveDocument(filename, FALSE); 3330 saveDocument(filename, FALSE);
3327 3331
3328 modified = true; 3332 modified = true;
3329 3333
3330 // clear the password list 3334 // clear the password list
3331 QListViewItem *i; 3335 QListViewItem *i;
3332 QListViewItem *c = NULL; 3336 QListViewItem *c = NULL;
3333 // step through all categories 3337 // step through all categories
3334 for (i = ListView->firstChild(); 3338 for (i = ListView->firstChild();
3335 i != NULL; 3339 i != NULL;
3336 i = i->nextSibling()) 3340 i = i->nextSibling())
3337 { 3341 {
3338 if (c) delete c; // delete the previous category 3342 if (c) delete c; // delete the previous category
3339 3343
3340 c = i; 3344 c = i;
3341 // step through all subitems 3345 // step through all subitems
3342 QListViewItem *si; 3346 QListViewItem *si;
3343 for (si = i->firstChild(); 3347 for (si = i->firstChild();
3344 si != NULL; ) 3348 si != NULL; )
3345 { 3349 {
3346 QListViewItem *_si = si; 3350 QListViewItem *_si = si;
3347 si = si->nextSibling(); 3351 si = si->nextSibling();
3348 i->takeItem(_si); // remove from view list 3352 i->takeItem(_si); // remove from view list
3349 if (_si) delete _si; 3353 if (_si) delete _si;
3350 } 3354 }
3351 } 3355 }
3352 if (c) delete c; // delete the previous category 3356 if (c) delete c; // delete the previous category
3353 categories.clear(); 3357 categories.clear();
3354 3358
3355 // m_password = ""; 3359 // m_password = "";
3356 selectedItem = NULL; 3360 selectedItem = NULL;
3357 3361
3358 filename = newFile; 3362 filename = newFile;
3359 3363
3360 // save the current filename to the config file 3364 // save the current filename to the config file
3361 conf->writeEntry(APP_KEY+"document", filename); 3365 conf->writeEntry(APP_KEY+"document", filename);
3362 saveConf(); 3366 saveConf();
3363 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3367 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3364#ifdef WIN32 3368#ifdef WIN32
3365 this->setCaption("Qt ZSafe: " + ti); 3369 this->setCaption("Qt ZSafe: " + ti);
3366#else 3370#else
3367 this->setCaption("ZSafe: " + ti); 3371 this->setCaption("ZSafe: " + ti);
3368#endif 3372#endif
3369 3373
3370 // openDocument(filename); 3374 // openDocument(filename);
3371 3375
3372 QMessageBox::information( this, tr("ZSafe"), 3376 QMessageBox::information( this, tr("ZSafe"),
3373 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3377 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3374 3378
3375 saveDocumentWithPwd(); 3379 saveDocumentWithPwd();
3376 } 3380 }
3377} 3381}
3378 3382
3379void ZSafe::loadDocument() 3383void ZSafe::loadDocument()
3380{ 3384{
3381 3385
3382 // open the file dialog 3386 // open the file dialog
3383#ifndef DESKTOP 3387#ifndef DESKTOP
3384#ifndef NO_OPIE 3388#ifndef NO_OPIE
3385 QMap<QString, QStringList> mimeTypes; 3389 QMap<QString, QStringList> mimeTypes;
3386 mimeTypes.insert(tr("All"), QStringList() ); 3390 mimeTypes.insert(tr("All"), QStringList() );
3387 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3391 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3388 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 3392 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
3389 QDir::homeDirPath() + "/Documents/application/zsafe", 3393 QDir::homeDirPath() + "/Documents/application/zsafe",
3390 QString::null, 3394 QString::null,
3391 mimeTypes, 3395 mimeTypes,
3392 this, 3396 this,
3393 tr ("Open ZSafe document")); 3397 tr ("Open ZSafe document"));
3394#else 3398#else
3395 QString newFile = ScQtFileEdit::getOpenFileName(this, 3399 QString newFile = ScQtFileEdit::getOpenFileName(this,
3396 tr ("Open ZSafe document"), 3400 tr ("Open ZSafe document"),
3397 QDir::homeDirPath() + "/Documents/application/zsafe", 3401 QDir::homeDirPath() + "/Documents/application/zsafe",
3398 "*.zsf"); 3402 "*.zsf");
3399#endif 3403#endif
3400#else 3404#else
3401 QString newFile = QFileDialog::getOpenFileName( 3405 QString newFile = QFileDialog::getOpenFileName(
3402 QDir::homeDirPath() + "/Documents/application/zsafe", 3406 QDir::homeDirPath() + "/Documents/application/zsafe",
3403 "ZSafe (*.zsf)", 3407 "ZSafe (*.zsf)",
3404 this, 3408 this,
3405 "ZSafe File Dialog" 3409 "ZSafe File Dialog"
3406 "Choose a ZSafe file" ); 3410 "Choose a ZSafe file" );
3407#endif 3411#endif
3408 3412
3409 // open the new document 3413 // open the new document
3410 if (newFile && newFile.length() > 0 ) 3414 if (newFile && newFile.length() > 0 )
3411 { 3415 {
3412 // save the previous opened document 3416 // save the previous opened document
3413 if (!filename.isEmpty()) 3417 if (!filename.isEmpty())
3414 saveDocument(filename, FALSE); 3418 saveDocument(filename, FALSE);
3415 3419
3416 // clear the password list 3420 // clear the password list
3417 QListViewItem *i; 3421 QListViewItem *i;
3418 QListViewItem *c = NULL; 3422 QListViewItem *c = NULL;
3419 // step through all categories 3423 // step through all categories
3420 for (i = ListView->firstChild(); 3424 for (i = ListView->firstChild();
3421 i != NULL; 3425 i != NULL;
3422 i = i->nextSibling()) 3426 i = i->nextSibling())
3423 { 3427 {
3424 if (c) delete c; // delete the previous category 3428 if (c) delete c; // delete the previous category
3425 3429
3426 c = i; 3430 c = i;
3427 // step through all subitems 3431 // step through all subitems
3428 QListViewItem *si; 3432 QListViewItem *si;
3429 for (si = i->firstChild(); 3433 for (si = i->firstChild();
3430 si != NULL; ) 3434 si != NULL; )
3431 { 3435 {
3432 QListViewItem *_si = si; 3436 QListViewItem *_si = si;
3433 si = si->nextSibling(); 3437 si = si->nextSibling();
3434 i->takeItem(_si); // remove from view list 3438 i->takeItem(_si); // remove from view list
3435 if (_si) delete _si; 3439 if (_si) delete _si;
3436 } 3440 }
3437 } 3441 }
3438 if (c) delete c; // delete the previous category 3442 if (c) delete c; // delete the previous category
3439 categories.clear(); 3443 categories.clear();
3440 m_password = ""; 3444 m_password = "";
3441 selectedItem = NULL; 3445 selectedItem = NULL;
3442 filename = newFile; 3446 filename = newFile;
3443 3447
3444 // save the current filename to the config file 3448 // save the current filename to the config file
3445 conf->writeEntry(APP_KEY+"document", filename); 3449 conf->writeEntry(APP_KEY+"document", filename);
3446 saveConf(); 3450 saveConf();
3447 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3451 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3448#ifdef WIN32 3452#ifdef WIN32
3449 this->setCaption("Qt ZSafe: " + ti); 3453 this->setCaption("Qt ZSafe: " + ti);
3450#else 3454#else
3451 this->setCaption("ZSafe: " + ti); 3455 this->setCaption("ZSafe: " + ti);
3452#endif 3456#endif
3453 3457
3454 openDocument(filename); 3458 openDocument(filename);
3455 } 3459 }
3456} 3460}
3457 3461
3458void ZSafe::saveDocumentAs() 3462void ZSafe::saveDocumentAs()
3459{ 3463{
3460 3464
3461#ifndef DESKTOP 3465#ifndef DESKTOP
3462#ifndef NO_OPIE 3466#ifndef NO_OPIE
3463 QMap<QString, QStringList> mimeTypes; 3467 QMap<QString, QStringList> mimeTypes;
3464 mimeTypes.insert(tr("All"), QStringList() ); 3468 mimeTypes.insert(tr("All"), QStringList() );
3465 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3469 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3466 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3470 QString newFile = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3467 QDir::homeDirPath() + "/Documents/application/zsafe", 3471 QDir::homeDirPath() + "/Documents/application/zsafe",
3468 QString::null, 3472 QString::null,
3469 mimeTypes, 3473 mimeTypes,
3470 this, 3474 this,
3471 tr ("Save ZSafe document as..")); 3475 tr ("Save ZSafe document as.."));
3472#else 3476#else
3473 QString newFile = ScQtFileEdit::getSaveAsFileName(this, 3477 QString newFile = ScQtFileEdit::getSaveAsFileName(this,
3474 tr ("Save ZSafe document as.."), 3478 tr ("Save ZSafe document as.."),
3475 QDir::homeDirPath() + "/Documents/application/zsafe", 3479 QDir::homeDirPath() + "/Documents/application/zsafe",
3476 "*.zsf"); 3480 "*.zsf");
3477#endif 3481#endif
3478#else 3482#else
3479 // open the file dialog 3483 // open the file dialog
3480 QString newFile = QFileDialog::getSaveFileName( 3484 QString newFile = QFileDialog::getSaveFileName(
3481 QDir::homeDirPath() + "/Documents/application/zsafe", 3485 QDir::homeDirPath() + "/Documents/application/zsafe",
3482 "ZSafe (*.zsf)", 3486 "ZSafe (*.zsf)",
3483 this, 3487 this,
3484 "ZSafe File Dialog" 3488 "ZSafe File Dialog"
3485 "Choose a ZSafe file" ); 3489 "Choose a ZSafe file" );
3486#endif 3490#endif
3487 3491
3488 // open the new document 3492 // open the new document
3489 if (newFile && newFile.length() > 0 ) 3493 if (newFile && newFile.length() > 0 )
3490 { 3494 {
3491 // save the previous opened document 3495 // save the previous opened document
3492 if (!filename.isEmpty()) 3496 if (!filename.isEmpty())
3493 saveDocument(filename, FALSE); 3497 saveDocument(filename, FALSE);
3494 3498
3495 selectedItem = NULL; 3499 selectedItem = NULL;
3496 filename = newFile; 3500 filename = newFile;
3497 3501
3498 // save the current filename to the config file 3502 // save the current filename to the config file
3499 conf->writeEntry(APP_KEY+"document", filename); 3503 conf->writeEntry(APP_KEY+"document", filename);
3500 saveConf(); 3504 saveConf();
3501 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3505 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3502#ifdef WIN32 3506#ifdef WIN32
3503 this->setCaption("Qt ZSafe: " + ti); 3507 this->setCaption("Qt ZSafe: " + ti);
3504#else 3508#else
3505 this->setCaption("ZSafe: " + ti); 3509 this->setCaption("ZSafe: " + ti);
3506#endif 3510#endif
3507 3511
3508 QMessageBox::information( this, tr("ZSafe"), 3512 QMessageBox::information( this, tr("ZSafe"),
3509 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3513 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3510 3514
3511 saveDocumentWithPwd(); 3515 saveDocumentWithPwd();
3512 } 3516 }
3513} 3517}
3514 3518
3515void ZSafe::saveDocumentWithoutPwd() 3519void ZSafe::saveDocumentWithoutPwd()
3516{ 3520{
3517 saveDocument(filename, FALSE); 3521 saveDocument(filename, FALSE);
3518} 3522}
3519 3523
3520void ZSafe::saveDocumentWithPwd() 3524void ZSafe::saveDocumentWithPwd()
3521{ 3525{
3522 saveDocument(filename, TRUE); 3526 saveDocument(filename, TRUE);
3523} 3527}
3524 3528
3525void ZSafe::about() 3529void ZSafe::about()
3526{ 3530{
3527 QString info; 3531 QString info;
3528 info = "<html><body><div align=""center"">"; 3532 info = "<html><body><div align=""center"">";
3529 info += "<b>"; 3533 info += "<b>";
3530 info += tr("Zaurus Password Manager<br>"); 3534 info += tr("Zaurus Password Manager<br>");
3531 info += tr("ZSafe version 2.1.2<br>"); 3535 info += tr("ZSafe version 2.1.2<br>");
3532 info += "</b>"; 3536 info += "</b>";
3533 info += tr("by Carsten Schneider<br>"); 3537 info += tr("by Carsten Schneider<br>");
3534 info += "zcarsten@gmx.net<br>"; 3538 info += "zcarsten@gmx.net<br>";
3535 info += "http://z-soft.z-portal.info/zsafe"; 3539 info += "http://z-soft.z-portal.info/zsafe";
3536 info += "<br>"; 3540 info += "<br>";
3537 info += tr("Translations by Robert Ernst<br>"); 3541 info += tr("Translations by Robert Ernst<br>");
3538 info += "robert.ernst@linux-solutions.at<br>"; 3542 info += "robert.ernst@linux-solutions.at<br>";
3539 info += "<br></div>"; 3543 info += "<br></div>";
3540 info += "</body></html>"; 3544 info += "</body></html>";
3541 3545
3542 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); 3546 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0);
3543 3547
3544 QMessageBox mb( this, tr("ZSafe")); 3548 QMessageBox mb( this, tr("ZSafe"));
3545 mb.setText (info); 3549 mb.setText (info);
3546 mb.setButtonText (QMessageBox::Ok, tr ("&OK")); 3550 mb.setButtonText (QMessageBox::Ok, tr ("&OK"));
3547 QPixmap zsafe_img((const char**) zsafe_xpm); 3551 QPixmap zsafe_img((const char**) zsafe_xpm);
3548 mb.setIconPixmap (zsafe_img); 3552 mb.setIconPixmap (zsafe_img);
3549 mb.exec(); 3553 mb.exec();
3550} 3554}
3551 3555
3552void ZSafe::setExpandFlag() 3556void ZSafe::setExpandFlag()
3553{ 3557{
3554 expandTree = !expandTree; 3558 expandTree = !expandTree;
3555 file->setItemChecked('o', expandTree); 3559 file->setItemChecked('o', expandTree);
3556#ifndef DESKTOP 3560#ifndef DESKTOP
3557 conf->setGroup ("zsafePrefs"); 3561 conf->setGroup ("zsafePrefs");
3558#endif 3562#endif
3559// #ifndef WIN32 3563// #ifndef WIN32
3560 conf->writeEntry (APP_KEY+"expandTree", expandTree); 3564 conf->writeEntry (APP_KEY+"expandTree", expandTree);
3561// #endif 3565// #endif
3562 saveConf(); 3566 saveConf();
3563 3567
3564} 3568}
3565 3569
3566void ZSafe::paintEvent( QPaintEvent * ) 3570void ZSafe::paintEvent( QPaintEvent * )
3567{ 3571{
3568 if (raiseFlag) 3572 if (raiseFlag)
3569 { 3573 {
3570 raiseFlag = false; 3574 raiseFlag = false;
3571 raiseTimer.start (1, true); 3575 raiseTimer.start (1, true);
3572 if (infoForm->isVisible()) 3576 if (infoForm->isVisible())
3573 infoForm->raise(); 3577 infoForm->raise();
3574 } 3578 }
3575} 3579}
3576 3580
3577void ZSafe::resizeEvent ( QResizeEvent * ) 3581void ZSafe::resizeEvent ( QResizeEvent * )
3578{ 3582{
3579 // qWarning ("resizeEvent"); 3583 // qWarning ("resizeEvent");
3580#ifndef DESKTOP 3584#ifndef DESKTOP
3581 DeskW = appl->desktop()->width(); 3585 DeskW = appl->desktop()->width();
3582 DeskH = appl->desktop()->height(); 3586 DeskH = appl->desktop()->height();
3583#else 3587#else
3584 DeskW = this->width(); 3588 DeskW = this->width();
3585 DeskH = this->height(); 3589 DeskH = this->height();
3586#endif 3590#endif
3587 qWarning( QString("Width : %1").arg(DeskW), 2000 ); 3591 qWarning( QString("Width : %1").arg(DeskW), 2000 );
3588 qWarning( QString("Height: %1").arg(DeskH), 2000 ); 3592 qWarning( QString("Height: %1").arg(DeskH), 2000 );
3589 3593
3590 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); 3594 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
3591 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); 3595 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
3592 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 3596 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
3593 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); 3597 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
3594} 3598}
3595 3599
3596void ZSafe::slotRaiseTimer() 3600void ZSafe::slotRaiseTimer()
3597{ 3601{
3598 if (infoForm->isVisible()) 3602 if (infoForm->isVisible())
3599 infoForm->raise(); 3603 infoForm->raise();
3600 raiseFlag = true; 3604 raiseFlag = true;
3601} 3605}
3602 3606
3603QPixmap * ZSafe::getPredefinedIcon(QString category) 3607QPixmap * ZSafe::getPredefinedIcon(QString category)
3604{ 3608{
3605 QPixmap *pm; 3609 QPixmap *pm;
3606 if (category == "Bank cards") 3610 if (category == "Bank cards")
3607 pm = new QPixmap((const char**)bank_cards_data); 3611 pm = new QPixmap((const char**)bank_cards_data);
3608 else if (category == "Passwords") 3612 else if (category == "Passwords")
3609 pm = new QPixmap((const char**)passwords_data); 3613 pm = new QPixmap((const char**)passwords_data);
3610 else if (category == "Software") 3614 else if (category == "Software")
3611 pm = new QPixmap((const char**)software_data); 3615 pm = new QPixmap((const char**)software_data);
3612 else if (category == "General") 3616 else if (category == "General")
3613 pm = new QPixmap((const char**)general_data); 3617 pm = new QPixmap((const char**)general_data);
3614 else 3618 else
3615 pm = new QPixmap((const char**)general_data); 3619 pm = new QPixmap((const char**)general_data);
3616 return pm; 3620 return pm;
3617} 3621}
3618 3622
3619void ZSafe::setDocument(const QString& fileref) 3623void ZSafe::setDocument(const QString& fileref)
3620{ 3624{
3621#ifndef DESKTOP 3625#ifndef DESKTOP
3622 // stop the timer to prevent loading of the default document 3626 // stop the timer to prevent loading of the default document
3623 docuTimer.stop(); 3627 docuTimer.stop();
3624 3628
3625 DocLnk link(fileref); 3629 DocLnk link(fileref);
3626 if ( link.isValid() ) 3630 if ( link.isValid() )
3627 { 3631 {
3628 // if (filename != link.file()) 3632 // if (filename != link.file())
3629 // saveDocument(filename, FALSE); 3633 // saveDocument(filename, FALSE);
3630 filename = link.file(); 3634 filename = link.file();
3631 } 3635 }
3632 else 3636 else
3633 { 3637 {
3634 // if (filename != fileref) 3638 // if (filename != fileref)
3635 // saveDocument(filename, FALSE); 3639 // saveDocument(filename, FALSE);
3636 filename = fileref; 3640 filename = fileref;
3637 } 3641 }
3638 // save the current filename to the config file 3642 // save the current filename to the config file
3639 conf->writeEntry(APP_KEY+"document", filename); 3643 conf->writeEntry(APP_KEY+"document", filename);
3640 saveConf(); 3644 saveConf();
3641 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3645 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3642#ifdef WIN32 3646#ifdef WIN32
3643 this->setCaption("Qt ZSafe: " + ti); 3647 this->setCaption("Qt ZSafe: " + ti);
3644#else 3648#else
3645 this->setCaption("ZSafe: " + ti); 3649 this->setCaption("ZSafe: " + ti);
3646#endif 3650#endif
3647 3651
3648 // clear the password list 3652 // clear the password list
3649 QListViewItem *i; 3653 QListViewItem *i;
3650 QListViewItem *c = NULL; 3654 QListViewItem *c = NULL;
3651 // step through all categories 3655 // step through all categories
3652 for (i = ListView->firstChild(); 3656 for (i = ListView->firstChild();
3653 i != NULL; 3657 i != NULL;
3654 i = i->nextSibling()) 3658 i = i->nextSibling())
3655 { 3659 {
3656 if (c) delete c; // delete the previous category 3660 if (c) delete c; // delete the previous category
3657 3661
3658 c = i; 3662 c = i;
3659 // step through all subitems 3663 // step through all subitems
3660 QListViewItem *si; 3664 QListViewItem *si;
3661 for (si = i->firstChild(); 3665 for (si = i->firstChild();
3662 si != NULL; ) 3666 si != NULL; )
3663 { 3667 {
3664 QListViewItem *_si = si; 3668 QListViewItem *_si = si;
3665 si = si->nextSibling(); 3669 si = si->nextSibling();
3666 i->takeItem(_si); // remove from view list 3670 i->takeItem(_si); // remove from view list
3667 if (_si) delete _si; 3671 if (_si) delete _si;
3668 } 3672 }
3669 } 3673 }
3670 if (c) delete c; // delete the previous category 3674 if (c) delete c; // delete the previous category
3671 categories.clear(); 3675 categories.clear();
3672 3676
3673 m_password = ""; 3677 m_password = "";
3674 selectedItem = NULL; 3678 selectedItem = NULL;
3675 3679
3676 openDocument(filename); 3680 openDocument(filename);
3677#endif 3681#endif
3678} 3682}
3679 3683
3680 3684
3681 3685