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