summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 41c572a..1c15852 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1,2343 +1,2343 @@
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 -DNO_OPIE 14** Linux Desktop : -DDESKTOP -DNO_OPIE
15** Windows Desktop: -DDESKTOP -DNO_OPIE 15** Windows Desktop: -DDESKTOP -DNO_OPIE
16** use qmake 16** use qmake
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 <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33using namespace Opie::Core; 33using namespace Opie::Core;
34using namespace Opie::Ui; 34using namespace Opie::Ui;
35#else 35#else
36#include "scqtfileedit.h" 36#include "scqtfileedit.h"
37#endif 37#endif
38#endif 38#endif
39 39
40#include <qclipboard.h> 40#include <qclipboard.h>
41 41
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#ifndef Q_WS_WIN 46#ifndef Q_WS_WIN
47#include <unistd.h> 47#include <unistd.h>
48#endif 48#endif
49#include <string.h> 49#include <string.h>
50#include <errno.h> 50#include <errno.h>
51 51
52#include <qmenubar.h> 52#include <qmenubar.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54 54
55#ifdef DESKTOP 55#ifdef DESKTOP
56#include <qfiledialog.h> 56#include <qfiledialog.h>
57#include <qdragobject.h> 57#include <qdragobject.h>
58#ifndef Q_WS_WIN 58#ifndef Q_WS_WIN
59#include <qsettings.h> 59#include <qsettings.h>
60#else 60#else
61#include "qsettings.h" 61#include "qsettings.h"
62#endif 62#endif
63#include <qapplication.h> 63#include <qapplication.h>
64#else 64#else
65#include <qfile.h> 65#include <qfile.h>
66#include <qpe/fileselector.h> 66#include <qpe/fileselector.h>
67#include <qpe/global.h> 67#include <qpe/global.h>
68#include <qpe/qpeapplication.h> 68#include <qpe/qpeapplication.h>
69#include <qpe/resource.h> 69#include <qpe/resource.h>
70#include <qpe/config.h> 70#include <qpe/config.h>
71#endif 71#endif
72 72
73#include <qtimer.h> 73#include <qtimer.h>
74#include <qlayout.h> 74#include <qlayout.h>
75#include <qmessagebox.h> 75#include <qmessagebox.h>
76#include <qfile.h> 76#include <qfile.h>
77#include <qtextstream.h> 77#include <qtextstream.h>
78#include <qheader.h> 78#include <qheader.h>
79#include <qlistview.h> 79#include <qlistview.h>
80#include <qtoolbutton.h> 80#include <qtoolbutton.h>
81#include <qvariant.h> 81#include <qvariant.h>
82#include <qtooltip.h> 82#include <qtooltip.h>
83#include <qwhatsthis.h> 83#include <qwhatsthis.h>
84#include <qimage.h> 84#include <qimage.h>
85#include <qpixmap.h> 85#include <qpixmap.h>
86#include <qlineedit.h> 86#include <qlineedit.h>
87#include <qmultilineedit.h> 87#include <qmultilineedit.h>
88#include <qregexp.h> 88#include <qregexp.h>
89#include <qdir.h> 89#include <qdir.h>
90#include <qtextbrowser.h> 90#include <qtextbrowser.h>
91#include <qlabel.h> 91#include <qlabel.h>
92#include <qcombobox.h> 92#include <qcombobox.h>
93 93
94#include "krc2.h" 94#include "krc2.h"
95 95
96#include "wait.h" 96#include "wait.h"
97 97
98extern int DeskW, DeskH; 98extern int DeskW, DeskH;
99#ifdef DESKTOP 99#ifdef DESKTOP
100extern QApplication *appl; 100extern QApplication *appl;
101#else 101#else
102extern QPEApplication *appl; 102extern QPEApplication *appl;
103#endif 103#endif
104 104
105#ifdef JPATCH_HDE 105#ifdef JPATCH_HDE
106#define tr(arg) arg 106#define tr(arg) arg
107#endif 107#endif
108 108
109 109
110#ifdef DESKTOP 110#ifdef DESKTOP
111#ifndef Q_WS_WIN 111#ifndef Q_WS_WIN
112const QString APP_KEY="/.zsafe/"; 112const QString APP_KEY="/.zsafe/";
113#else 113#else
114const QString APP_KEY=""; 114const QString APP_KEY="";
115#endif 115#endif
116#else 116#else
117const QString APP_KEY=""; 117const QString APP_KEY="";
118#endif 118#endif
119 119
120// include xmp images 120// include xmp images
121#include "pics/zsafe/copy.xpm" 121#include "pics/zsafe/copy.xpm"
122#include "pics/zsafe/cut.xpm" 122#include "pics/zsafe/cut.xpm"
123#include "pics/zsafe/edit.xpm" 123#include "pics/zsafe/edit.xpm"
124#include "pics/zsafe/editdelete.xpm" 124#include "pics/zsafe/editdelete.xpm"
125#include "pics/zsafe/find.xpm" 125#include "pics/zsafe/find.xpm"
126#include "pics/zsafe/folder_open.xpm" 126#include "pics/zsafe/folder_open.xpm"
127#include "pics/zsafe/help_icon.xpm" 127#include "pics/zsafe/help_icon.xpm"
128#include "pics/zsafe/new.xpm" 128#include "pics/zsafe/new.xpm"
129#include "pics/zsafe/paste.xpm" 129#include "pics/zsafe/paste.xpm"
130#include "pics/zsafe/quit_icon.xpm" 130#include "pics/zsafe/quit_icon.xpm"
131#include "pics/zsafe/save.xpm" 131#include "pics/zsafe/save.xpm"
132#include "pics/zsafe/trash.xpm" 132#include "pics/zsafe/trash.xpm"
133#include "pics/zsafe/expand.xpm" 133#include "pics/zsafe/expand.xpm"
134#include "pics/zsafe/export.xpm" 134#include "pics/zsafe/export.xpm"
135#include "pics/zsafe/import.xpm" 135#include "pics/zsafe/import.xpm"
136#include "pics/zsafe/zsafe.xpm" 136#include "pics/zsafe/zsafe.xpm"
137 137
138static const char* const bank_cards_data[] = { 138static const char* const bank_cards_data[] = {
139"14 14 16 1", 139"14 14 16 1",
140". c None", 140". c None",
141"# c #000000", 141"# c #000000",
142"b c #0000de", 142"b c #0000de",
143"a c #0000e6", 143"a c #0000e6",
144"j c #41de83", 144"j c #41de83",
145"k c #4acecd", 145"k c #4acecd",
146"h c #4aced5", 146"h c #4aced5",
147"g c #5a40cd", 147"g c #5a40cd",
148"d c #5a44d5", 148"d c #5a44d5",
149"l c #9440d5", 149"l c #9440d5",
150"m c #b4ce4a", 150"m c #b4ce4a",
151"n c #cd4883", 151"n c #cd4883",
152"e c #d5ae10", 152"e c #d5ae10",
153"f c #de3ce6", 153"f c #de3ce6",
154"i c #e640e6", 154"i c #e640e6",
155"c c #ffffff", 155"c c #ffffff",
156"..............", 156"..............",
157".###########..", 157".###########..",
158".#ababababa#..", 158".#ababababa#..",
159".#babbbabbb#..", 159".#babbbabbb#..",
160".#ccccccccc#..", 160".#ccccccccc#..",
161".#cdcefcghc#..", 161".#cdcefcghc#..",
162".#ccccccccc#..", 162".#ccccccccc#..",
163".#cicjkclic#..", 163".#cicjkclic#..",
164".#ccccccccc#..", 164".#ccccccccc#..",
165".#cmchlcnec#..", 165".#cmchlcnec#..",
166".#ccccccccc#..", 166".#ccccccccc#..",
167".###########..", 167".###########..",
168"..............", 168"..............",
169".............."}; 169".............."};
170 170
171 171
172static const char* const passwords_data[] = { 172static const char* const passwords_data[] = {
173"16 16 20 1", 173"16 16 20 1",
174". c None", 174". c None",
175"# c #000000", 175"# c #000000",
176"r c #000083", 176"r c #000083",
177"p c #0000c5", 177"p c #0000c5",
178"q c #0000ff", 178"q c #0000ff",
179"n c #008100", 179"n c #008100",
180"l c #00c200", 180"l c #00c200",
181"m c #00ff00", 181"m c #00ff00",
182"j c #838100", 182"j c #838100",
183"a c #c55900", 183"a c #c55900",
184"h c #c5c200", 184"h c #c5c200",
185"o c #c5c2ff", 185"o c #c5c2ff",
186"k c #c5ffc5", 186"k c #c5ffc5",
187"f c #ff0000", 187"f c #ff0000",
188"d c #ff8100", 188"d c #ff8100",
189"b c #ffaa5a", 189"b c #ffaa5a",
190"e c #ffc2c5", 190"e c #ffc2c5",
191"c c #ffdeac", 191"c c #ffdeac",
192"i c #ffff00", 192"i c #ffff00",
193"g c #ffffc5", 193"g c #ffffc5",
194"............###.", 194"............###.",
195"...........#abb#", 195"...........#abb#",
196"..........#cbab#", 196"..........#cbab#",
197".........#cbdd#.", 197".........#cbdd#.",
198"######..#cbdd#..", 198"######..#cbdd#..",
199"#eeff#..#add#...", 199"#eeff#..#add#...",
200"#eeff#######....", 200"#eeff#######....",
201"#ccdbdd#........", 201"#ccdbdd#........",
202"#dddbdd###......", 202"#dddbdd###......",
203"#gghihhjj#......", 203"#gghihhjj#......",
204"#hhhihhjj###....", 204"#hhhihhjj###....",
205"#kklmllnnnn#....", 205"#kklmllnnnn#....",
206"#lllmllnnnn#....", 206"#lllmllnnnn#....",
207"#oopqpprprr#....", 207"#oopqpprprr#....",
208"#oopqpprprr#....", 208"#oopqpprprr#....",
209"############...."}; 209"############...."};
210 210
211static const char* const software_data[] = { 211static const char* const software_data[] = {
212"16 16 5 1", 212"16 16 5 1",
213". c None", 213". c None",
214"# c #000000", 214"# c #000000",
215"b c #838183", 215"b c #838183",
216"c c #c5ffff", 216"c c #c5ffff",
217"a c #ffffff", 217"a c #ffffff",
218"................", 218"................",
219".##############.", 219".##############.",
220"#aaaaaaaaaaaaaa#", 220"#aaaaaaaaaaaaaa#",
221"#abbbbbbbbbbbbb#", 221"#abbbbbbbbbbbbb#",
222"#ab##########ab#", 222"#ab##########ab#",
223"#ab#c########ab#", 223"#ab#c########ab#",
224"#ab#c#c######ab#", 224"#ab#c#c######ab#",
225"#ab##########ab#", 225"#ab##########ab#",
226"#ab##########ab#", 226"#ab##########ab#",
227"#ab##########ab#", 227"#ab##########ab#",
228"#ab##########ab#", 228"#ab##########ab#",
229"#ab##########ab#", 229"#ab##########ab#",
230"#aaaaaaaaaaaaab#", 230"#aaaaaaaaaaaaab#",
231"#bbbbbbbbbbbbbb#", 231"#bbbbbbbbbbbbbb#",
232".##############.", 232".##############.",
233"................"}; 233"................"};
234 234
235static const char* const general_data[] = { 235static const char* const general_data[] = {
236"14 14 98 2", 236"14 14 98 2",
237"Qt c None", 237"Qt c None",
238".k c #000000", 238".k c #000000",
239"#x c #080808", 239"#x c #080808",
240"#F c #101008", 240"#F c #101008",
241"#q c #101010", 241"#q c #101010",
242"#i c #101410", 242"#i c #101410",
243"## c #101810", 243"## c #101810",
244".m c #181818", 244".m c #181818",
245".3 c #181c18", 245".3 c #181c18",
246".I c #182018", 246".I c #182018",
247".T c #202420", 247".T c #202420",
248"#D c #202820", 248"#D c #202820",
249"#y c #292c29", 249"#y c #292c29",
250".c c #293029", 250".c c #293029",
251".d c #313031", 251".d c #313031",
252"#E c #313429", 252"#E c #313429",
253"#r c #313831", 253"#r c #313831",
254".j c #393c31", 254".j c #393c31",
255"#j c #394039", 255"#j c #394039",
256"#C c #414841", 256"#C c #414841",
257".w c #4a554a", 257".w c #4a554a",
258".a c #4a594a", 258".a c #4a594a",
259".# c #525052", 259".# c #525052",
260".l c #52594a", 260".l c #52594a",
261"#f c #525952", 261"#f c #525952",
262"#v c #525d52", 262"#v c #525d52",
263".O c #5a4c4a", 263".O c #5a4c4a",
264".9 c #5a595a", 264".9 c #5a595a",
265".A c #5a5d52", 265".A c #5a5d52",
266".B c #624c52", 266".B c #624c52",
267".0 c #625552", 267".0 c #625552",
268"#o c #626562", 268"#o c #626562",
269".R c #626962", 269".R c #626962",
270"#. c #626d5a", 270"#. c #626d5a",
271"#p c #626d62", 271"#p c #626d62",
272".2 c #627162", 272".2 c #627162",
273"#h c #6a6d62", 273"#h c #6a6d62",
274"#z c #6a7562", 274"#z c #6a7562",
275"#w c #6a756a", 275"#w c #6a756a",
276".C c #73656a", 276".C c #73656a",
277".P c #73696a", 277".P c #73696a",
278"#a c #737d6a", 278"#a c #737d6a",
279".U c #738573", 279".U c #738573",
280".E c #7b817b", 280".E c #7b817b",
281"#B c #7b857b", 281"#B c #7b857b",
282"#s c #7b897b", 282"#s c #7b897b",
283"#n c #7b917b", 283"#n c #7b917b",
284".b c #838d83", 284".b c #838d83",
285".7 c #839583", 285".7 c #839583",
286".n c #8b7d7b", 286".n c #8b7d7b",
287"#g c #8b8583", 287"#g c #8b8583",
288".g c #8b858b", 288".g c #8b858b",
289".r c #8b898b", 289".r c #8b898b",
290".s c #8b8d8b", 290".s c #8b8d8b",
291".i c #8b9183", 291".i c #8b9183",
292".8 c #8b918b", 292".8 c #8b918b",
293"#A c #8b9d8b", 293"#A c #8b9d8b",
294".S c #8ba183", 294".S c #8ba183",
295".Z c #94918b", 295".Z c #94918b",
296".N c #949994", 296".N c #949994",
297".F c #949d94", 297".F c #949d94",
298".x c #94a18b", 298".x c #94a18b",
299".v c #94a194", 299".v c #94a194",
300".Y c #94aa94", 300".Y c #94aa94",
301".h c #9c999c", 301".h c #9c999c",
302".Q c #9ca19c", 302".Q c #9ca19c",
303"#u c #9ca59c", 303"#u c #9ca59c",
304".H c #9caa9c", 304".H c #9caa9c",
305"#e c #9cb29c", 305"#e c #9cb29c",
306"#m c #a4b29c", 306"#m c #a4b29c",
307"#t c #a4b2a4", 307"#t c #a4b2a4",
308".M c #a4b69c", 308".M c #a4b69c",
309"#l c #a4b6a4", 309"#l c #a4b6a4",
310".z c #a4baa4", 310".z c #a4baa4",
311".f c #aca5ac", 311".f c #aca5ac",
312".q c #acaaac", 312".q c #acaaac",
313"#d c #acbeac", 313"#d c #acbeac",
314".6 c #acc2ac", 314".6 c #acc2ac",
315".o c #b4b2b4", 315".o c #b4b2b4",
316".t c #b4beb4", 316".t c #b4beb4",
317"#k c #b4c2ac", 317"#k c #b4c2ac",
318".5 c #b4cab4", 318".5 c #b4cab4",
319".D c #bdb6bd", 319".D c #bdb6bd",
320".G c #bdc6b4", 320".G c #bdc6b4",
321"#c c #bdceb4", 321"#c c #bdceb4",
322".X c #bdd2bd", 322".X c #bdd2bd",
323".4 c #bdd6bd", 323".4 c #bdd6bd",
324".1 c #c5bec5", 324".1 c #c5bec5",
325".e c #c5c2c5", 325".e c #c5c2c5",
326".u c #c5cac5", 326".u c #c5cac5",
327"#b c #c5d6c5", 327"#b c #c5d6c5",
328".J c #c5dec5", 328".J c #c5dec5",
329".p c #cdcacd", 329".p c #cdcacd",
330".W c #cddecd", 330".W c #cddecd",
331".L c #cde2cd", 331".L c #cde2cd",
332".K c #d5eacd", 332".K c #d5eacd",
333".V c #d5ead5", 333".V c #d5ead5",
334".y c #d5eed5", 334".y c #d5eed5",
335"QtQtQtQtQtQtQtQtQtQtQtQtQtQt", 335"QtQtQtQtQtQtQtQtQtQtQtQtQtQt",
336"QtQtQt.#.a.b.cQtQtQtQtQtQtQt", 336"QtQtQt.#.a.b.cQtQtQtQtQtQtQt",
337"QtQt.d.e.f.g.h.i.c.j.dQt.kQt", 337"QtQt.d.e.f.g.h.i.c.j.dQt.kQt",
338".a.l.m.n.o.p.q.r.s.t.u.v.wQt", 338".a.l.m.n.o.p.q.r.s.t.u.v.wQt",
339".x.y.z.A.B.C.D.p.q.E.F.G.H.I", 339".x.y.z.A.B.C.D.p.q.E.F.G.H.I",
340".I.J.K.L.M.N.O.P.o.p.Q.R.S.T", 340".I.J.K.L.M.N.O.P.o.p.Q.R.S.T",
341"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3", 341"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3",
342"Qt.3.X.W.4.X.5.6.7.8.9.s#.##", 342"Qt.3.X.W.4.X.5.6.7.8.9.s#.##",
343"QtQt#a.X#b#c.5.6#d#e#f#g#h#i", 343"QtQt#a.X#b#c.5.6#d#e#f#g#h#i",
344"QtQtQt#j.7#k.6#d#l#m#n#o#p#q", 344"QtQtQt#j.7#k.6#d#l#m#n#o#p#q",
345"QtQtQtQt.k#r#s#m#t.H#u#v#w#x", 345"QtQtQtQt.k#r#s#m#t.H#u#v#w#x",
346"QtQtQtQtQtQt.k#y#z.v#A#B#C#x", 346"QtQtQtQtQtQt.k#y#z.v#A#B#C#x",
347"QtQtQtQtQtQtQtQt.k#D.w#s#E.k", 347"QtQtQtQtQtQtQtQt.k#D.w#s#E.k",
348"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; 348"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"};
349 349
350// exit ZSafe and clear the clipboard for security reasons 350// exit ZSafe and clear the clipboard for security reasons
351 void ZSafe::exitZs (int ec) 351 void ZSafe::exitZs (int ec)
352 { 352 {
353 QClipboard *cb = QApplication::clipboard(); 353 QClipboard *cb = QApplication::clipboard();
354 cb->clear(); 354 cb->clear();
355 355
356 exit (ec); 356 exit (ec);
357 } 357 }
358 358
359 359
360// save the configuration into the file 360// save the configuration into the file
361 void ZSafe::saveConf () 361 void ZSafe::saveConf ()
362 { 362 {
363 if (conf) 363 if (conf)
364 { 364 {
365 delete conf; 365 delete conf;
366 366
367#ifdef DESKTOP 367#ifdef DESKTOP
368#ifndef Q_WS_WIN 368#ifndef Q_WS_WIN
369 conf = new QSettings(); 369 conf = new QSettings();
370 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 370 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
371#else 371#else
372 conf = new QSettings (cfgFile); 372 conf = new QSettings (cfgFile);
373 conf->insertSearchPath (QSettings::Unix, cfgFile); 373 conf->insertSearchPath (QSettings::Unix, cfgFile);
374#endif 374#endif
375#else 375#else
376 conf = new Config (cfgFile, Config::File); 376 conf = new Config (cfgFile, Config::File);
377 conf->setGroup ("zsafe"); 377 conf->setGroup ("zsafe");
378#endif 378#endif
379 } 379 }
380 } 380 }
381 381
382 382
383/* 383/*
384 * Constructs a ZSafe which is a child of 'parent', with the 384 * Constructs a ZSafe which is a child of 'parent', with the
385 * name 'name' and widget flags set to 'f' 385 * name 'name' and widget flags set to 'f'
386 * 386 *
387 * The dialog will by default be modeless, unless you set 'modal' to 387 * The dialog will by default be modeless, unless you set 'modal' to
388 * TRUE to construct a modal dialog. 388 * TRUE to construct a modal dialog.
389 */ 389 */
390ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) 390ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
391 : QDialog( parent, name, modal, fl ), 391 : QDialog( parent, name, modal, fl ),
392 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) 392 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l)
393{ 393{
394 IsCut = false; 394 IsCut = false;
395 IsCopy = false; 395 IsCopy = false;
396 modified = false; 396 modified = false;
397 showpwd = false; 397 showpwd = false;
398 398
399 // set the config file 399 // set the config file
400 cfgFile=QDir::homeDirPath(); 400 cfgFile=QDir::homeDirPath();
401 cfgFile += "/.zsafe.cfg"; 401 cfgFile += "/.zsafe.cfg";
402 // set the icon path 402 // set the icon path
403#ifdef NO_OPIE 403#ifdef NO_OPIE
404 QString qpedir ((const char *)getenv("QPEDIR")); 404 QString qpedir ((const char *)getenv("QPEDIR"));
405#else 405#else
406 QString qpedir ((const char *)getenv("OPIEDIR")); 406 QString qpedir ((const char *)getenv("OPIEDIR"));
407#endif 407#endif
408 408
409#ifdef DESKTOP 409#ifdef DESKTOP
410 iconPath = QDir::homeDirPath() + "/pics/"; 410 iconPath = QDir::homeDirPath() + "/pics/";
411#else 411#else
412 if (qpedir.isEmpty()) 412 if (qpedir.isEmpty())
413 iconPath = "/home/QtPalmtop/pics/"; 413 iconPath = "/home/QtPalmtop/pics/";
414 else 414 else
415 iconPath = qpedir + "/pics/"; 415 iconPath = qpedir + "/pics/";
416#endif 416#endif
417 417
418 // create a zsafe configuration object 418 // create a zsafe configuration object
419#ifdef DESKTOP 419#ifdef DESKTOP
420#ifndef Q_WS_WIN 420#ifndef Q_WS_WIN
421 conf = new QSettings (); 421 conf = new QSettings ();
422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
423#else 423#else
424 conf = new QSettings (cfgFile); 424 conf = new QSettings (cfgFile);
425 conf->insertSearchPath (QSettings::Unix, cfgFile); 425 conf->insertSearchPath (QSettings::Unix, cfgFile);
426#endif 426#endif
427#else 427#else
428 conf = new Config (cfgFile, Config::File); 428 conf = new Config (cfgFile, Config::File);
429 conf->setGroup ("zsafePrefs"); 429 conf->setGroup ("zsafePrefs");
430#endif 430#endif
431#ifdef DESKTOP 431#ifdef DESKTOP
432// #ifndef Q_WS_WIN 432// #ifndef Q_WS_WIN
433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); 433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false);
434// #endif 434// #endif
435#else 435#else
436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); 436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0);
437#endif 437#endif
438#ifndef DESKTOP 438#ifndef DESKTOP
439 conf->setGroup ("zsafe"); 439 conf->setGroup ("zsafe");
440#endif 440#endif
441 441
442 QPixmap copy_img((const char**) copy_xpm); 442 QPixmap copy_img((const char**) copy_xpm);
443 QPixmap cut_img((const char**) cut_xpm); 443 QPixmap cut_img((const char**) cut_xpm);
444 QPixmap edit_img((const char**) edit_xpm); 444 QPixmap edit_img((const char**) edit_xpm);
445 QPixmap editdelete_img((const char**) editdelete_xpm); 445 QPixmap editdelete_img((const char**) editdelete_xpm);
446 QPixmap find_img((const char**) find_xpm); 446 QPixmap find_img((const char**) find_xpm);
447 QPixmap folder_open_img((const char**) folder_open_xpm); 447 QPixmap folder_open_img((const char**) folder_open_xpm);
448 QPixmap help_icon_img((const char**) help_icon_xpm); 448 QPixmap help_icon_img((const char**) help_icon_xpm);
449 QPixmap new_img((const char**) new_xpm); 449 QPixmap new_img((const char**) new_xpm);
450 QPixmap paste_img((const char**) paste_xpm); 450 QPixmap paste_img((const char**) paste_xpm);
451 QPixmap quit_icon_img((const char**) quit_icon_xpm); 451 QPixmap quit_icon_img((const char**) quit_icon_xpm);
452 QPixmap save_img((const char**) save_xpm); 452 QPixmap save_img((const char**) save_xpm);
453 QPixmap trash_img((const char**) trash_xpm); 453 QPixmap trash_img((const char**) trash_xpm);
454 QPixmap expand_img((const char**) expand_xpm); 454 QPixmap expand_img((const char**) expand_xpm);
455 QPixmap export_img((const char**) export_xpm); 455 QPixmap export_img((const char**) export_xpm);
456 QPixmap import_img((const char**) import_xpm); 456 QPixmap import_img((const char**) import_xpm);
457 457
458 QPixmap bank_cards( ( const char** ) bank_cards_data ); 458 QPixmap bank_cards( ( const char** ) bank_cards_data );
459 QPixmap passwords( ( const char** ) passwords_data ); 459 QPixmap passwords( ( const char** ) passwords_data );
460 QPixmap software( ( const char** ) software_data ); 460 QPixmap software( ( const char** ) software_data );
461 QPixmap general( ( const char** ) general_data ); 461 QPixmap general( ( const char** ) general_data );
462 QPixmap image0( ( const char** ) zsafe_xpm ); 462 QPixmap image0( ( const char** ) zsafe_xpm );
463 if ( !name ) 463 if ( !name )
464 setName( "ZSafe" ); 464 setName( "ZSafe" );
465 465
466#ifdef DESKTOP 466#ifdef DESKTOP
467#ifdef Q_WS_WIN 467#ifdef Q_WS_WIN
468 setGeometry(100, 150, DeskW, DeskH-30 ); 468 setGeometry(100, 150, DeskW, DeskH-30 );
469#else 469#else
470 resize( DeskW, DeskH-30 ); 470 resize( DeskW, DeskH-30 );
471#endif 471#endif
472 472
473#else 473#else
474 474
475#ifdef JPATCH_HDE 475#ifdef JPATCH_HDE
476 int DeskS; 476 int DeskS;
477 if(DeskW > DeskH) 477 if(DeskW > DeskH)
478 { 478 {
479 DeskS = DeskW; 479 DeskS = DeskW;
480 } 480 }
481 else 481 else
482 { 482 {
483 DeskS = DeskH; 483 DeskS = DeskH;
484 } 484 }
485 resize( DeskW, DeskH ); 485 resize( DeskW, DeskH );
486 setMinimumSize( QSize( DeskS, DeskS ) ); 486 setMinimumSize( QSize( DeskS, DeskS ) );
487 setMaximumSize( QSize( DeskS, DeskS ) ); 487 setMaximumSize( QSize( DeskS, DeskS ) );
488#else 488#else
489 resize( DeskW, DeskH-30 ); 489 resize( DeskW, DeskH-30 );
490#endif 490#endif
491 491
492#endif 492#endif
493 setCaption( tr( "ZSafe" ) ); 493 setCaption( tr( "ZSafe" ) );
494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; 494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe";
495 QString filename = conf->readEntry(APP_KEY+"document"); 495 QString filename = conf->readEntry(APP_KEY+"document");
496 if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() ) 496 if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() )
497 { 497 {
498 // check if the directory application exists, if not 498 // check if the directory application exists, if not
499 // create it 499 // create it
500// #ifndef Q_WS_WIN 500// #ifndef Q_WS_WIN
501 // QString d1("Documents/application"); 501 // QString d1("Documents/application");
502// #else 502// #else
503 QString d1(QDir::homeDirPath() + "/Documents/application"); 503 QString d1(QDir::homeDirPath() + "/Documents/application");
504// #endif 504// #endif
505 QDir pd1(d1); 505 QDir pd1(d1);
506 if (!pd1.exists()) 506 if (!pd1.exists())
507 { 507 {
508 QDir pd2(QDir::homeDirPath() + "/Documents"); 508 QDir pd2(QDir::homeDirPath() + "/Documents");
509 if (!pd2.exists()) { 509 if (!pd2.exists()) {
510 QDir pd3(QDir::homeDirPath()); 510 QDir pd3(QDir::homeDirPath());
511 if (!pd3.mkdir("Documents", FALSE)) { 511 if (!pd3.mkdir("Documents", FALSE)) {
512 } 512 }
513 } 513 }
514 514
515 if (!pd2.mkdir("application", FALSE)) 515 if (!pd2.mkdir("application", FALSE))
516 { 516 {
517 QMessageBox::critical( 0, tr("ZSafe"), 517 QMessageBox::critical( 0, tr("ZSafe"),
518#ifdef JPATCH_HDE 518#ifdef JPATCH_HDE
519 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); 519 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>"));
520#else 520#else
521 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); 521 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1));
522#endif 522#endif
523 exitZs (1); 523 exitZs (1);
524 } 524 }
525 } 525 }
526// #ifndef Q_WS_WIN 526// #ifndef Q_WS_WIN
527 // QString d2("Documents/application/zsafe"); 527 // QString d2("Documents/application/zsafe");
528// #else 528// #else
529 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); 529 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
530// #endif 530// #endif
531 QDir pd2(d2); 531 QDir pd2(d2);
532 if (!pd2.exists()) 532 if (!pd2.exists())
533 { 533 {
534 if (!pd1.mkdir("zsafe", FALSE)) 534 if (!pd1.mkdir("zsafe", FALSE))
535 { 535 {
536 QMessageBox::critical( 0, tr("ZSafe"), 536 QMessageBox::critical( 0, tr("ZSafe"),
537#ifdef JPATCH_HDE 537#ifdef JPATCH_HDE
538 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); 538 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P"));
539#else 539#else
540 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); 540 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2));
541#endif 541#endif
542 exitZs (1); 542 exitZs (1);
543 } 543 }
544 } 544 }
545 545
546 filename = zsafeAppDirPath + "/passwords.zsf"; 546 filename = zsafeAppDirPath + "/passwords.zsf";
547 547
548 // save the current filename to the config file 548 // save the current filename to the config file
549 conf->writeEntry(APP_KEY+"document", filename); 549 conf->writeEntry(APP_KEY+"document", filename);
550 saveConf(); 550 saveConf();
551 } 551 }
552 //if (filename == "INVALIDPWD") 552 //if (filename == "INVALIDPWD")
553 //filename = ""; 553 //filename = "";
554 554
555 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 555 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
556#ifdef Q_WS_WIN 556#ifdef Q_WS_WIN
557 this->setCaption("Qt ZSafe: " + ti); 557 this->setCaption("Qt ZSafe: " + ti);
558#else 558#else
559 this->setCaption("ZSafe: " + ti); 559 this->setCaption("ZSafe: " + ti);
560#endif 560#endif
561 561
562 selectedItem = NULL; 562 selectedItem = NULL;
563 lastSearchedCategory = NULL; 563 lastSearchedCategory = NULL;
564 lastSearchedItem = NULL; 564 lastSearchedItem = NULL;
565 lastSearchedName = ""; 565 lastSearchedName = "";
566 lastSearchedUsername = ""; 566 lastSearchedUsername = "";
567 lastSearchedComment = ""; 567 lastSearchedComment = "";
568 568
569 infoForm = new InfoForm(this, "show_info", TRUE); 569 infoForm = new InfoForm(this, "show_info", TRUE);
570 categoryDialog = NULL; 570 categoryDialog = NULL;
571 infoForm->setIcon( image0); 571 infoForm->setIcon( image0);
572 572
573 // add a menu bar 573 // add a menu bar
574 QMenuBar *menu = new QMenuBar( this ); 574 QMenuBar *menu = new QMenuBar( this );
575 575
576 // add file menu 576 // add file menu
577 // QPopupMenu *file = new QPopupMenu( this ); 577 // QPopupMenu *file = new QPopupMenu( this );
578 file = new QPopupMenu( this ); 578 file = new QPopupMenu( this );
579 579
580// #ifdef DESKTOP 580// #ifdef DESKTOP
581 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); 581 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) );
582 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); 582 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) );
583 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); 583 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) );
584 file->insertSeparator(); 584 file->insertSeparator();
585// #endif 585// #endif
586 586
587 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); 587 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) );
588 file->insertItem( save_img, tr("S&ave document with new Password"), this, 588 file->insertItem( save_img, tr("S&ave document with new Password"), this,
589 SLOT(saveDocumentWithPwd()) ); 589 SLOT(saveDocumentWithPwd()) );
590 file->insertSeparator(); 590 file->insertSeparator();
591 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); 591 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) );
592 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); 592 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) );
593 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); 593 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) );
594 file->insertSeparator(); 594 file->insertSeparator();
595 file->insertItem( expand_img, tr("&Open entries expanded"), this, 595 file->insertItem( expand_img, tr("&Open entries expanded"), this,
596 SLOT(setExpandFlag()), 0, 'o'); 596 SLOT(setExpandFlag()), 0, 'o');
597 file->setItemChecked('o', expandTree); 597 file->setItemChecked('o', expandTree);
598 file->insertSeparator(); 598 file->insertSeparator();
599 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); 599 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) );
600 menu->insertItem( tr("&File"), file ); 600 menu->insertItem( tr("&File"), file );
601 601
602 QPopupMenu *cat = new QPopupMenu( this ); 602 QPopupMenu *cat = new QPopupMenu( this );
603 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); 603 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) );
604 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); 604 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) );
605 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); 605 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) );
606 menu->insertItem( tr("&Category"), cat ); 606 menu->insertItem( tr("&Category"), cat );
607 607
608 QPopupMenu *it = new QPopupMenu( this ); 608 QPopupMenu *it = new QPopupMenu( this );
609 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); 609 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) );
610 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); 610 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) );
611 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); 611 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) );
612 it->insertSeparator(); 612 it->insertSeparator();
613 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); 613 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) );
614 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); 614 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) );
615 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); 615 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) );
616 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); 616 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) );
617 menu->insertItem( tr("&Entry"), it ); 617 menu->insertItem( tr("&Entry"), it );
618 618
619 QPopupMenu *help = new QPopupMenu( this ); 619 QPopupMenu *help = new QPopupMenu( this );
620 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); 620 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) );
621 menu->insertItem( tr("&Help"), help ); 621 menu->insertItem( tr("&Help"), help );
622 622
623 // toolbar icons 623 // toolbar icons
624 624
625 New = new QToolButton( menu, "New" ); 625 New = new QToolButton( menu, "New" );
626 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); 626 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) );
627 New->setMouseTracking( TRUE ); 627 New->setMouseTracking( TRUE );
628 New->setText( "" ); 628 New->setText( "" );
629 New->setPixmap( new_img ); 629 New->setPixmap( new_img );
630 QToolTip::add( New, tr( "New entry" ) ); 630 QToolTip::add( New, tr( "New entry" ) );
631 631
632 Edit = new QToolButton( menu, "Edit" ); 632 Edit = new QToolButton( menu, "Edit" );
633 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); 633 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) );
634 Edit->setText( "" ); 634 Edit->setText( "" );
635 Edit->setPixmap( edit_img ); 635 Edit->setPixmap( edit_img );
636 QToolTip::add( Edit, tr( "Edit category or entry" ) ); 636 QToolTip::add( Edit, tr( "Edit category or entry" ) );
637 637
638 Delete = new QToolButton( menu, "Delete" ); 638 Delete = new QToolButton( menu, "Delete" );
639 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 639 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
640 Delete->setText( "" ); 640 Delete->setText( "" );
641 Delete->setPixmap( trash_img ); 641 Delete->setPixmap( trash_img );
642 QToolTip::add( Delete, tr( "Delete category or entry" ) ); 642 QToolTip::add( Delete, tr( "Delete category or entry" ) );
643 643
644 Find = new QToolButton( menu, "Find" ); 644 Find = new QToolButton( menu, "Find" );
645 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); 645 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) );
646 Find->setText( "" ); 646 Find->setText( "" );
647 Find->setPixmap( find_img ); 647 Find->setPixmap( find_img );
648 QToolTip::add( Find, tr( "Find entry" ) ); 648 QToolTip::add( Find, tr( "Find entry" ) );
649 649
650/* 650/*
651 QBoxLayout * h = new QHBoxLayout( this ); 651 QBoxLayout * h = new QHBoxLayout( this );
652 h->addWidget (menu); 652 h->addWidget (menu);
653 h->addWidget (New); 653 h->addWidget (New);
654 h->addWidget (Edit); 654 h->addWidget (Edit);
655 h->addWidget (Delete); 655 h->addWidget (Delete);
656 h->addWidget (Find); 656 h->addWidget (Find);
657*/ 657*/
658 658
659 ListView = new ZListView( this, "ListView" ); 659 ListView = new ZListView( this, "ListView" );
660 ListView->addColumn( tr( "Name" ) ); 660 ListView->addColumn( tr( "Name" ) );
661 ListView->addColumn( tr( "Field 2" ) ); 661 ListView->addColumn( tr( "Field 2" ) );
662 ListView->addColumn( tr( "Field 3" ) ); 662 ListView->addColumn( tr( "Field 3" ) );
663 ListView->addColumn( tr( "Comment" ) ); 663 ListView->addColumn( tr( "Comment" ) );
664 ListView->addColumn( tr( "Field 4" ) ); 664 ListView->addColumn( tr( "Field 4" ) );
665 ListView->addColumn( tr( "Field 5" ) ); 665 ListView->addColumn( tr( "Field 5" ) );
666 ListView->setAllColumnsShowFocus(TRUE); 666 ListView->setAllColumnsShowFocus(TRUE);
667 667
668#ifdef DESKTOP 668#ifdef DESKTOP
669 ListView->setResizePolicy(QScrollView::AutoOneFit); 669 ListView->setResizePolicy(QScrollView::AutoOneFit);
670 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); 670 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) );
671#else 671#else
672 ListView->setResizePolicy(QScrollView::AutoOneFit); 672 ListView->setResizePolicy(QScrollView::AutoOneFit);
673 // ListView->setGeometry( QRect( 0, 22, 673 // ListView->setGeometry( QRect( 0, 22,
674 // this->width(), this->height() - 30 ) ); 674 // this->width(), this->height() - 30 ) );
675 // ListView->setMaximumSize( QSize( 440, 290 ) ); 675 // ListView->setMaximumSize( QSize( 440, 290 ) );
676#endif 676#endif
677 ListView->setVScrollBarMode( QListView::Auto ); 677 ListView->setVScrollBarMode( QListView::Auto );
678 678
679 QBoxLayout * l = new QVBoxLayout( this ); 679 QBoxLayout * l = new QVBoxLayout( this );
680 l->addWidget (menu); 680 l->addWidget (menu);
681 l->addWidget (ListView); 681 l->addWidget (ListView);
682 682
683#ifndef DESKTOP 683#ifndef DESKTOP
684 // start a timer (100 ms) to load the default document 684 // start a timer (100 ms) to load the default document
685 docuTimer.start( 100, true ); 685 docuTimer.start( 100, true );
686 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); 686 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) );
687 raiseFlag = true; 687 raiseFlag = true;
688 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); 688 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) );
689#else 689#else
690 // open the default document 690 // open the default document
691 openDocument(filename); 691 openDocument(filename);
692#endif 692#endif
693 693
694 // signals and slots connections for QTollButton 694 // signals and slots connections for QTollButton
695 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); 695 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) );
696 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); 696 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) );
697 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); 697 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) );
698 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); 698 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) );
699 // signals and slots connections for QListView 699 // signals and slots connections for QListView
700 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), 700 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ),
701 this, SLOT( listViewSelected(QListViewItem*) ) ); 701 this, SLOT( listViewSelected(QListViewItem*) ) );
702 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), 702 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ),
703 this, SLOT( showInfo(QListViewItem*) ) ); 703 this, SLOT( showInfo(QListViewItem*) ) );
704 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), 704 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ),
705 this, SLOT( showInfo(QListViewItem*) ) ); 705 this, SLOT( showInfo(QListViewItem*) ) );
706 706
707 #ifndef DESKTOP 707 #ifndef DESKTOP
708 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); 708 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
709#endif 709#endif
710 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 710 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
711 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); 711 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
712 712
713 this->setIcon( image0); 713 this->setIcon( image0);
714} 714}
715 715
716const QColor *ZSafe::evenRowColor = &Qt::white; 716const QColor *ZSafe::evenRowColor = &Qt::white;
717// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 717// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
718const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 718const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
719 719
720/* 720/*
721 * Destroys the object and frees any allocated resources 721 * Destroys the object and frees any allocated resources
722 */ 722 */
723ZSafe::~ZSafe() 723ZSafe::~ZSafe()
724{ 724{
725 // no need to delete child widgets, Qt does it all for us 725 // no need to delete child widgets, Qt does it all for us
726 quitMe(); 726 quitMe();
727} 727}
728 728
729// load the default document 729// load the default document
730void ZSafe::slotLoadDocu() 730void ZSafe::slotLoadDocu()
731{ 731{
732 openDocument (filename); 732 openDocument (filename);
733} 733}
734 734
735void ZSafe::deletePwd() 735void ZSafe::deletePwd()
736{ 736{
737 737
738 if (!selectedItem) 738 if (!selectedItem)
739 return; 739 return;
740 if (!isCategory(selectedItem)) 740 if (!isCategory(selectedItem))
741 { 741 {
742 switch( QMessageBox::information( this, tr("ZSafe"), 742 switch( QMessageBox::information( this, tr("ZSafe"),
743 tr("Do you want to delete?"), 743 tr("Do you want to delete?"),
744 tr("&Delete"), tr("D&on't Delete"), 744 tr("&Delete"), tr("D&on't Delete"),
745 0 // Enter == button 0 745 0 // Enter == button 0
746 ) ) { // Escape == button 2 746 ) ) { // Escape == button 2
747 case 0: // Delete clicked, Alt-S or Enter pressed. 747 case 0: // Delete clicked, Alt-S or Enter pressed.
748 // Delete 748 // Delete
749 modified = true; 749 modified = true;
750 selectedItem->parent()->takeItem(selectedItem); 750 selectedItem->parent()->takeItem(selectedItem);
751 selectedItem = NULL; 751 selectedItem = NULL;
752 break; 752 break;
753 case 1: // Don't delete 753 case 1: // Don't delete
754 break; 754 break;
755 } 755 }
756 } 756 }
757 else 757 else
758 { 758 {
759 delCategory(); 759 delCategory();
760 } 760 }
761} 761}
762 762
763void ZSafe::editPwd() 763void ZSafe::editPwd()
764{ 764{
765 if (!selectedItem) 765 if (!selectedItem)
766 return; 766 return;
767 if (!isCategory(selectedItem)) 767 if (!isCategory(selectedItem))
768 { 768 {
769 // open the 'New Entry' dialog 769 // open the 'New Entry' dialog
770 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE); 770 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE);
771#ifdef Q_WS_WIN 771#ifdef Q_WS_WIN
772 dialog->setCaption ("Qt " + tr("Edit Entry")); 772 dialog->setCaption ("Qt " + tr("Edit Entry"));
773 dialog->setGeometry(200, 250, 220, 310 ); 773 dialog->setGeometry(200, 250, 220, 310 );
774#endif 774#endif
775 775
776 // set the labels 776 // set the labels
777 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 777 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
778 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 778 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
779 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 779 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
780 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 780 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
781 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 781 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
782 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 782 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
783 783
784 // set the fields 784 // set the fields
785 dialog->NameField->setText(selectedItem->text (0)); 785 dialog->NameField->setText(selectedItem->text (0));
786 dialog->UsernameField->setText(selectedItem->text (1)); 786 dialog->UsernameField->setText(selectedItem->text (1));
787 dialog->PasswordField->setText(selectedItem->text (2)); 787 dialog->PasswordField->setText(selectedItem->text (2));
788 QString comment = selectedItem->text (3); 788 QString comment = selectedItem->text (3);
789 comment.replace (QRegExp("<br>"), "\n"); 789 comment.replace (QRegExp("<br>"), "\n");
790 dialog->Field5->setText(selectedItem->text (4)); 790 dialog->Field5->setText(selectedItem->text (4));
791 dialog->Field6->setText(selectedItem->text (5)); 791 dialog->Field6->setText(selectedItem->text (5));
792 dialog->CommentField->insertLine(comment); 792 dialog->CommentField->insertLine(comment);
793 dialog->CommentField->setCursorPosition(0,0); 793 dialog->CommentField->setCursorPosition(0,0);
794 794
795#ifdef Q_WS_QWS 795#ifdef Q_WS_QWS
796 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 796 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
797#endif 797#endif
798 798
799#ifdef DESKTOP 799#ifdef DESKTOP
800#ifndef Q_QW_QWIN 800#ifndef Q_QW_QWIN
801 dialog->show(); 801 dialog->show();
802#endif 802#endif
803#else 803#else
804 dialog->showMaximized(); 804 dialog->showMaximized();
805#endif 805#endif
806 int result = dialog->exec();
807#ifdef DESKTOP 806#ifdef DESKTOP
807 int result = dialog->exec();
808// result = QDialog::Accepted; 808// result = QDialog::Accepted;
809#endif 809#endif
810 if (result == Accepted) 810 if (result == Accepted)
811 { 811 {
812 modified = true; 812 modified = true;
813 // edit the selected item 813 // edit the selected item
814 QString name = dialog->NameField->text(); 814 QString name = dialog->NameField->text();
815 selectedItem->setText (0, tr (name)); 815 selectedItem->setText (0, tr (name));
816 QString user = dialog->UsernameField->text(); 816 QString user = dialog->UsernameField->text();
817 selectedItem->setText (1, tr (user)); 817 selectedItem->setText (1, tr (user));
818 QString pwd = dialog->PasswordField->text(); 818 QString pwd = dialog->PasswordField->text();
819 selectedItem->setText (2, tr (pwd)); 819 selectedItem->setText (2, tr (pwd));
820 QString comment = dialog->CommentField->text(); 820 QString comment = dialog->CommentField->text();
821 comment.replace (QRegExp("\n"), "<br>"); 821 comment.replace (QRegExp("\n"), "<br>");
822 selectedItem->setText (3, tr (comment)); 822 selectedItem->setText (3, tr (comment));
823 QString f5 = dialog->Field5->text(); 823 QString f5 = dialog->Field5->text();
824 selectedItem->setText (4, tr (f5)); 824 selectedItem->setText (4, tr (f5));
825 QString f6 = dialog->Field6->text(); 825 QString f6 = dialog->Field6->text();
826 selectedItem->setText (5, tr (f6)); 826 selectedItem->setText (5, tr (f6));
827 } 827 }
828 828
829 delete dialog; 829 delete dialog;
830 } 830 }
831 else 831 else
832 { 832 {
833 editCategory(); 833 editCategory();
834 } 834 }
835} 835}
836 836
837void ZSafe::newPwd() 837void ZSafe::newPwd()
838{ 838{
839 if (!selectedItem) 839 if (!selectedItem)
840 return; 840 return;
841 841
842 if (!isCategory(selectedItem)) 842 if (!isCategory(selectedItem))
843 selectedItem = selectedItem->parent(); 843 selectedItem = selectedItem->parent();
844 844
845 if (isCategory(selectedItem)) 845 if (isCategory(selectedItem))
846 { 846 {
847 QString cat = selectedItem->text(0); 847 QString cat = selectedItem->text(0);
848 848
849 // open the 'New Entry' dialog 849 // open the 'New Entry' dialog
850 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE); 850 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE);
851#ifdef Q_WS_WIN 851#ifdef Q_WS_WIN
852 dialog->setCaption ("Qt " + tr("New Entry")); 852 dialog->setCaption ("Qt " + tr("New Entry"));
853 dialog->setGeometry(200, 250, 220, 310 ); 853 dialog->setGeometry(200, 250, 220, 310 );
854#endif 854#endif
855 // set the labels 855 // set the labels
856 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 856 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
857 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 857 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
858 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 858 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
859 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 859 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
860 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 860 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
861 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 861 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
862retype: 862retype:
863 863
864#ifdef Q_WS_QWS 864#ifdef Q_WS_QWS
865 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 865 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
866#endif 866#endif
867 867
868#ifdef DESKTOP 868#ifdef DESKTOP
869#ifndef Q_QW_QWIN 869#ifndef Q_QW_QWIN
870 dialog->show(); 870 dialog->show();
871#endif 871#endif
872#else 872#else
873 dialog->showMaximized(); 873 dialog->showMaximized();
874#endif 874#endif
875#ifdef DESKTOP 875#ifdef DESKTOP
876 int result = dialog->exec(); 876 int result = dialog->exec();
877// result = QDialog::Accepted; 877// result = QDialog::Accepted;
878#endif 878#endif
879 879
880 if (result == Accepted) 880 if (result == Accepted)
881 { 881 {
882 882
883 QString name = dialog->NameField->text(); 883 QString name = dialog->NameField->text();
884 if (cat == name) 884 if (cat == name)
885 { 885 {
886 QMessageBox::critical( 0, tr("ZSafe"), 886 QMessageBox::critical( 0, tr("ZSafe"),
887 tr("Entry name must be different\nfrom the category name.") ); 887 tr("Entry name must be different\nfrom the category name.") );
888 goto retype; // it's not a good programming style :-) 888 goto retype; // it's not a good programming style :-)
889 } 889 }
890 890
891 modified = true; 891 modified = true;
892 // add the new item 892 // add the new item
893 QListViewItem *i = new ShadedListItem (0, selectedItem); 893 QListViewItem *i = new ShadedListItem (0, selectedItem);
894 i->setOpen (TRUE); 894 i->setOpen (TRUE);
895 895
896 i->setText (0, tr (name)); 896 i->setText (0, tr (name));
897 QString user = dialog->UsernameField->text(); 897 QString user = dialog->UsernameField->text();
898 i->setText (1, tr (user)); 898 i->setText (1, tr (user));
899 QString pwd = dialog->PasswordField->text(); 899 QString pwd = dialog->PasswordField->text();
900 i->setText (2, tr (pwd)); 900 i->setText (2, tr (pwd));
901 QString comment = dialog->CommentField->text(); 901 QString comment = dialog->CommentField->text();
902 comment.replace (QRegExp("\n"), "<br>"); 902 comment.replace (QRegExp("\n"), "<br>");
903 i->setText (3, tr (comment)); 903 i->setText (3, tr (comment));
904 QString f5 = dialog->Field5->text(); 904 QString f5 = dialog->Field5->text();
905 i->setText (4, tr (f5)); 905 i->setText (4, tr (f5));
906 QString f6 = dialog->Field6->text(); 906 QString f6 = dialog->Field6->text();
907 i->setText (5, tr (f6)); 907 i->setText (5, tr (f6));
908 } 908 }
909 909
910 delete dialog; 910 delete dialog;
911 } 911 }
912} 912}
913 913
914void ZSafe::findPwd() 914void ZSafe::findPwd()
915{ 915{
916 916
917 // open the 'Search' dialog 917 // open the 'Search' dialog
918 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 918 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
919#ifdef Q_WS_WIN 919#ifdef Q_WS_WIN
920 dialog->setCaption ("Qt " + tr("Search")); 920 dialog->setCaption ("Qt " + tr("Search"));
921#endif 921#endif
922 922
923#ifdef DESKTOP 923#ifdef DESKTOP
924#endif 924#endif
925 if (lastSearchedName) 925 if (lastSearchedName)
926 dialog->NameField->setText(lastSearchedName); 926 dialog->NameField->setText(lastSearchedName);
927 else 927 else
928 dialog->NameField->setText(""); 928 dialog->NameField->setText("");
929 if (lastSearchedUsername) 929 if (lastSearchedUsername)
930 dialog->UsernameField->setText(lastSearchedUsername); 930 dialog->UsernameField->setText(lastSearchedUsername);
931 else 931 else
932 dialog->UsernameField->setText(""); 932 dialog->UsernameField->setText("");
933 if (lastSearchedComment) 933 if (lastSearchedComment)
934 dialog->CommentField->setText(lastSearchedComment); 934 dialog->CommentField->setText(lastSearchedComment);
935 else 935 else
936 dialog->CommentField->setText(""); 936 dialog->CommentField->setText("");
937 DialogCode result = (DialogCode) dialog->exec(); 937 DialogCode result = (DialogCode) dialog->exec();
938#ifdef DESKTOP 938#ifdef DESKTOP
939 result = Accepted; 939 result = Accepted;
940#endif 940#endif
941 941
942 QString name; 942 QString name;
943 QString username; 943 QString username;
944 QString comment; 944 QString comment;
945 if (result == Accepted) 945 if (result == Accepted)
946 { 946 {
947 name = dialog->NameField->text(); 947 name = dialog->NameField->text();
948 username = dialog->UsernameField->text(); 948 username = dialog->UsernameField->text();
949 comment = dialog->CommentField->text(); 949 comment = dialog->CommentField->text();
950#ifndef NO_OPIE 950#ifndef NO_OPIE
951 owarn << name << oendl; 951 owarn << name << oendl;
952#else 952#else
953 qWarning (name); 953 qWarning (name);
954#endif 954#endif
955 } 955 }
956 else 956 else
957 { 957 {
958 delete dialog; 958 delete dialog;
959 return; 959 return;
960 } 960 }
961 961
962 if (!name.isEmpty() && name != lastSearchedName || 962 if (!name.isEmpty() && name != lastSearchedName ||
963 lastSearchedName.isEmpty() && !name.isEmpty()) 963 lastSearchedName.isEmpty() && !name.isEmpty())
964 { 964 {
965 // set search at the beginning if a new name is given 965 // set search at the beginning if a new name is given
966 lastSearchedCategory = NULL; 966 lastSearchedCategory = NULL;
967 lastSearchedItem = NULL; 967 lastSearchedItem = NULL;
968 } 968 }
969 lastSearchedName = name; 969 lastSearchedName = name;
970 if (!username.isEmpty() && username != lastSearchedUsername || 970 if (!username.isEmpty() && username != lastSearchedUsername ||
971 lastSearchedUsername.isEmpty() && !username.isEmpty()) 971 lastSearchedUsername.isEmpty() && !username.isEmpty())
972 { 972 {
973 // set search at the beginning if a new name is given 973 // set search at the beginning if a new name is given
974 lastSearchedCategory = NULL; 974 lastSearchedCategory = NULL;
975 lastSearchedItem = NULL; 975 lastSearchedItem = NULL;
976 } 976 }
977 lastSearchedUsername = username; 977 lastSearchedUsername = username;
978 if (!comment.isEmpty() && comment != lastSearchedComment || 978 if (!comment.isEmpty() && comment != lastSearchedComment ||
979 lastSearchedComment.isEmpty() && !comment.isEmpty()) 979 lastSearchedComment.isEmpty() && !comment.isEmpty())
980 { 980 {
981 // set search at the beginning if a new name is given 981 // set search at the beginning if a new name is given
982 lastSearchedCategory = NULL; 982 lastSearchedCategory = NULL;
983 lastSearchedItem = NULL; 983 lastSearchedItem = NULL;
984 } 984 }
985 lastSearchedComment = comment; 985 lastSearchedComment = comment;
986 986
987 ListView->clearSelection(); 987 ListView->clearSelection();
988 988
989 bool found=FALSE; 989 bool found=FALSE;
990 // step through all categories 990 // step through all categories
991 QListViewItem *i; 991 QListViewItem *i;
992 if (lastSearchedCategory) 992 if (lastSearchedCategory)
993 i = lastSearchedCategory; 993 i = lastSearchedCategory;
994 else 994 else
995 i = ListView->firstChild(); 995 i = ListView->firstChild();
996 for (; 996 for (;
997 i != NULL; 997 i != NULL;
998 i = i->nextSibling()) 998 i = i->nextSibling())
999 { 999 {
1000#ifndef NO_OPIE 1000#ifndef NO_OPIE
1001 owarn << i->text(0) << oendl; 1001 owarn << i->text(0) << oendl;
1002#endif 1002#endif
1003 i->setSelected(FALSE); 1003 i->setSelected(FALSE);
1004 1004
1005 // step through all subitems 1005 // step through all subitems
1006 QListViewItem *si; 1006 QListViewItem *si;
1007 if (lastSearchedItem) 1007 if (lastSearchedItem)
1008 si = lastSearchedItem; 1008 si = lastSearchedItem;
1009 else 1009 else
1010 si = i->firstChild(); 1010 si = i->firstChild();
1011 // for (si = i->firstChild(); 1011 // for (si = i->firstChild();
1012 for (; 1012 for (;
1013 si != NULL; 1013 si != NULL;
1014 si = si->nextSibling()) 1014 si = si->nextSibling())
1015 { 1015 {
1016#ifndef NO_OPIE 1016#ifndef NO_OPIE
1017 owarn << si->text(0) << oendl; 1017 owarn << si->text(0) << oendl;
1018#else 1018#else
1019 qWarning (si->text(0)); 1019 qWarning (si->text(0));
1020#endif 1020#endif
1021 if (si->isSelected()) 1021 if (si->isSelected())
1022 si->setSelected(FALSE); 1022 si->setSelected(FALSE);
1023 // ListView->repaintItem(si); 1023 // ListView->repaintItem(si);
1024 1024
1025 bool n=TRUE; 1025 bool n=TRUE;
1026 bool u=TRUE; 1026 bool u=TRUE;
1027 bool c=TRUE; 1027 bool c=TRUE;
1028 if (!name.isEmpty()) 1028 if (!name.isEmpty())
1029 n = (si->text(0)).contains (name, FALSE); 1029 n = (si->text(0)).contains (name, FALSE);
1030 if (!username.isEmpty()) 1030 if (!username.isEmpty())
1031 u = (si->text(1)).contains (username, FALSE); 1031 u = (si->text(1)).contains (username, FALSE);
1032 if (!comment.isEmpty()) 1032 if (!comment.isEmpty())
1033 c = (si->text(3)).contains (comment, FALSE); 1033 c = (si->text(3)).contains (comment, FALSE);
1034 1034
1035 if ((n && u && c ) && !found) 1035 if ((n && u && c ) && !found)
1036 { 1036 {
1037#ifndef NO_OPIE 1037#ifndef NO_OPIE
1038 owarn << "Found" << oendl; 1038 owarn << "Found" << oendl;
1039#else 1039#else
1040 qWarning ("Found"); 1040 qWarning ("Found");
1041#endif 1041#endif
1042 selectedItem = si; 1042 selectedItem = si;
1043 si->setSelected(TRUE); 1043 si->setSelected(TRUE);
1044 ListView->setCurrentItem(si); 1044 ListView->setCurrentItem(si);
1045 ListView->ensureItemVisible(si); 1045 ListView->ensureItemVisible(si);
1046 ListView->triggerUpdate(); 1046 ListView->triggerUpdate();
1047 1047
1048 lastSearchedCategory = i; 1048 lastSearchedCategory = i;
1049 // set to the next item 1049 // set to the next item
1050 lastSearchedItem = si->nextSibling(); 1050 lastSearchedItem = si->nextSibling();
1051 if (!lastSearchedItem) 1051 if (!lastSearchedItem)
1052 { 1052 {
1053 // no next item within category -> set next category 1053 // no next item within category -> set next category
1054 lastSearchedCategory = i->nextSibling(); 1054 lastSearchedCategory = i->nextSibling();
1055 if (!lastSearchedCategory) 1055 if (!lastSearchedCategory)
1056 lastSearchedItem = NULL; // END 1056 lastSearchedItem = NULL; // END
1057 } 1057 }
1058 1058
1059 found = TRUE; 1059 found = TRUE;
1060 delete dialog; 1060 delete dialog;
1061 update(); 1061 update();
1062 return; 1062 return;
1063 } 1063 }
1064 } 1064 }
1065 lastSearchedCategory = i->nextSibling(); 1065 lastSearchedCategory = i->nextSibling();
1066 lastSearchedItem = NULL; 1066 lastSearchedItem = NULL;
1067 } 1067 }
1068 lastSearchedCategory = NULL; 1068 lastSearchedCategory = NULL;
1069 lastSearchedItem = NULL; 1069 lastSearchedItem = NULL;
1070 delete dialog; 1070 delete dialog;
1071 update(); 1071 update();
1072 QMessageBox::information( this, tr("ZSafe"), 1072 QMessageBox::information( this, tr("ZSafe"),
1073 tr("Entry not found"), tr("&OK"), 0); 1073 tr("Entry not found"), tr("&OK"), 0);
1074 1074
1075} 1075}
1076 1076
1077QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1077QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1078{ 1078{
1079 QString category; 1079 QString category;
1080 if (_item) 1080 if (_item)
1081 { 1081 {
1082 if (isCategory(_item)) 1082 if (isCategory(_item))
1083 { 1083 {
1084 category = _item->text(0); 1084 category = _item->text(0);
1085 } 1085 }
1086 else 1086 else
1087 { 1087 {
1088 QListViewItem *cat = _item->parent(); 1088 QListViewItem *cat = _item->parent();
1089 category = cat->text(0); 1089 category = cat->text(0);
1090 } 1090 }
1091 } 1091 }
1092 else 1092 else
1093 { 1093 {
1094 return def; 1094 return def;
1095 } 1095 }
1096 1096
1097 QString app_key = APP_KEY; 1097 QString app_key = APP_KEY;
1098#ifndef DESKTOP 1098#ifndef DESKTOP
1099#ifndef Q_WS_WIN 1099#ifndef Q_WS_WIN
1100 conf->setGroup ("fieldDefs"); 1100 conf->setGroup ("fieldDefs");
1101#endif 1101#endif
1102#else 1102#else
1103#ifndef Q_WS_WIN 1103#ifndef Q_WS_WIN
1104 app_key += "/fieldDefs/"; 1104 app_key += "/fieldDefs/";
1105#endif 1105#endif
1106#endif 1106#endif
1107// #ifndef Q_WS_WIN 1107// #ifndef Q_WS_WIN
1108 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1108 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1109// #else 1109// #else
1110// QString label(def); 1110// QString label(def);
1111// #endif 1111// #endif
1112 1112
1113#ifndef DESKTOP 1113#ifndef DESKTOP
1114 conf->setGroup ("zsafe"); 1114 conf->setGroup ("zsafe");
1115#endif 1115#endif
1116 return label; 1116 return label;
1117} 1117}
1118 1118
1119QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1119QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1120{ 1120{
1121 QString app_key = APP_KEY; 1121 QString app_key = APP_KEY;
1122#ifndef DESKTOP 1122#ifndef DESKTOP
1123 conf->setGroup ("fieldDefs"); 1123 conf->setGroup ("fieldDefs");
1124#else 1124#else
1125#ifndef Q_WS_WIN 1125#ifndef Q_WS_WIN
1126 app_key += "/fieldDefs/"; 1126 app_key += "/fieldDefs/";
1127#endif 1127#endif
1128#endif 1128#endif
1129// #ifndef Q_WS_WIN 1129// #ifndef Q_WS_WIN
1130 QString label = conf->readEntry(app_key+category+"-field"+field, 1130 QString label = conf->readEntry(app_key+category+"-field"+field,
1131 def); 1131 def);
1132// #else 1132// #else
1133 // QString label(def); 1133 // QString label(def);
1134// #endif 1134// #endif
1135#ifndef DESKTOP 1135#ifndef DESKTOP
1136 conf->setGroup ("zsafe"); 1136 conf->setGroup ("zsafe");
1137#endif 1137#endif
1138 return label; 1138 return label;
1139} 1139}
1140 1140
1141void ZSafe::showInfo( QListViewItem *_item) 1141void ZSafe::showInfo( QListViewItem *_item)
1142{ 1142{
1143 if (!_item) 1143 if (!_item)
1144 return; 1144 return;
1145 if (selectedItem != NULL) 1145 if (selectedItem != NULL)
1146 selectedItem->setSelected(FALSE); 1146 selectedItem->setSelected(FALSE);
1147 1147
1148 selectedItem = _item; 1148 selectedItem = _item;
1149 selectedItem->setSelected(TRUE); 1149 selectedItem->setSelected(TRUE);
1150 1150
1151 if (!isCategory(_item)) 1151 if (!isCategory(_item))
1152 { 1152 {
1153/* 1153/*
1154 QString label=selectedItem->text(0); 1154 QString label=selectedItem->text(0);
1155 label+="\n"; 1155 label+="\n";
1156 label+=selectedItem->text(1); 1156 label+=selectedItem->text(1);
1157 label+="\n"; 1157 label+="\n";
1158 label+=selectedItem->text(2); 1158 label+=selectedItem->text(2);
1159 label+="\n"; 1159 label+="\n";
1160 label+=selectedItem->text(3); 1160 label+=selectedItem->text(3);
1161*/ 1161*/
1162 1162
1163 QString text; 1163 QString text;
1164 QString entry; 1164 QString entry;
1165 1165
1166 text = "<html><body><div align=""center""><u><b>"; 1166 text = "<html><body><div align=""center""><u><b>";
1167 text += selectedItem->text(0); 1167 text += selectedItem->text(0);
1168 text += "</b></u><br></div><br>"; 1168 text += "</b></u><br></div><br>";
1169 1169
1170 entry = selectedItem->text(1); 1170 entry = selectedItem->text(1);
1171 if (!entry.isEmpty() && entry.compare(" ")) 1171 if (!entry.isEmpty() && entry.compare(" "))
1172 { 1172 {
1173 text += "<u><b>"; 1173 text += "<u><b>";
1174 text += getFieldLabel (selectedItem, "2", tr("Username")); 1174 text += getFieldLabel (selectedItem, "2", tr("Username"));
1175 text += ":<br></b></u><blockquote>"; 1175 text += ":<br></b></u><blockquote>";
1176 text += entry; 1176 text += entry;
1177 text += "</blockquote>"; 1177 text += "</blockquote>";
1178 // text += "<br>"; 1178 // text += "<br>";
1179 } 1179 }
1180 1180
1181 entry = selectedItem->text(2); 1181 entry = selectedItem->text(2);
1182 if (!entry.isEmpty() && entry.compare(" ")) 1182 if (!entry.isEmpty() && entry.compare(" "))
1183 { 1183 {
1184 text += "<u><b>"; 1184 text += "<u><b>";
1185 text += getFieldLabel (selectedItem, "3", tr("Password")); 1185 text += getFieldLabel (selectedItem, "3", tr("Password"));
1186 text += ":<br> </b></u><blockquote>"; 1186 text += ":<br> </b></u><blockquote>";
1187 text += entry; 1187 text += entry;
1188 text += "</blockquote>"; 1188 text += "</blockquote>";
1189 // text += "<br>"; 1189 // text += "<br>";
1190 } 1190 }
1191 1191
1192 entry = selectedItem->text(4); 1192 entry = selectedItem->text(4);
1193 if (!entry.isEmpty() && entry.compare(" ")) 1193 if (!entry.isEmpty() && entry.compare(" "))
1194 { 1194 {
1195 text += "<u><b>"; 1195 text += "<u><b>";
1196 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1196 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1197 text += ":<br> </b></u><blockquote>"; 1197 text += ":<br> </b></u><blockquote>";
1198 text += entry; 1198 text += entry;
1199 text += "</blockquote>"; 1199 text += "</blockquote>";
1200 // text += "<br>"; 1200 // text += "<br>";
1201 } 1201 }
1202 1202
1203 entry = selectedItem->text(5); 1203 entry = selectedItem->text(5);
1204 if (!entry.isEmpty() && entry.compare(" ")) 1204 if (!entry.isEmpty() && entry.compare(" "))
1205 { 1205 {
1206 text += "<u><b>"; 1206 text += "<u><b>";
1207 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1207 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1208 text += ":<br> </b></u><blockquote>"; 1208 text += ":<br> </b></u><blockquote>";
1209 text += entry; 1209 text += entry;
1210 text += "</blockquote>"; 1210 text += "</blockquote>";
1211 // text += "<br>"; 1211 // text += "<br>";
1212 } 1212 }
1213 1213
1214 entry = selectedItem->text(3); 1214 entry = selectedItem->text(3);
1215 if (!entry.isEmpty() && entry.compare(" ")) 1215 if (!entry.isEmpty() && entry.compare(" "))
1216 { 1216 {
1217 text += "<u><b>"; 1217 text += "<u><b>";
1218 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1218 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1219 text += ":<br> </b></u>"; 1219 text += ":<br> </b></u>";
1220 QString comment = selectedItem->text(3); 1220 QString comment = selectedItem->text(3);
1221 comment.replace (QRegExp("\n"), "<br>"); 1221 comment.replace (QRegExp("\n"), "<br>");
1222 text += comment; 1222 text += comment;
1223 // text += "<br>"; 1223 // text += "<br>";
1224 } 1224 }
1225 1225
1226 text += "</body></html>"; 1226 text += "</body></html>";
1227 1227
1228 infoForm->InfoText->setText(text); 1228 infoForm->InfoText->setText(text);
1229// infoForm->hide(); 1229// infoForm->hide();
1230#ifdef Q_WS_QWS 1230#ifdef Q_WS_QWS
1231 QPEApplication::showDialog( infoForm ); 1231 QPEApplication::showDialog( infoForm );
1232#endif 1232#endif
1233 1233
1234#ifdef DESKTOP 1234#ifdef DESKTOP
1235 infoForm->show(); 1235 infoForm->show();
1236 #endif 1236 #endif
1237 } 1237 }
1238} 1238}
1239 1239
1240void ZSafe::listViewSelected( QListViewItem *_item) 1240void ZSafe::listViewSelected( QListViewItem *_item)
1241{ 1241{
1242 if (!_item) 1242 if (!_item)
1243 return; 1243 return;
1244 if (selectedItem != NULL) 1244 if (selectedItem != NULL)
1245 selectedItem->setSelected(FALSE); 1245 selectedItem->setSelected(FALSE);
1246 1246
1247 selectedItem = _item; 1247 selectedItem = _item;
1248 1248
1249#ifndef DESKTOP 1249#ifndef DESKTOP
1250 // set the column text dependent on the selected item 1250 // set the column text dependent on the selected item
1251 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1251 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1252 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1252 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1253 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1253 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1254 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1254 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1255 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1255 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1256 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1256 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1257#endif 1257#endif
1258#ifdef Q_WS_WIN 1258#ifdef Q_WS_WIN
1259 // set the column text dependent on the selected item 1259 // set the column text dependent on the selected item
1260 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1260 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1261 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1261 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1262 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1262 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1263 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1263 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1264 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1264 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1265 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1265 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1266#endif 1266#endif
1267 1267
1268} 1268}
1269 1269
1270bool ZSafe::isCategory(QListViewItem *_item) 1270bool ZSafe::isCategory(QListViewItem *_item)
1271{ 1271{
1272 if (_item == NULL) 1272 if (_item == NULL)
1273 return FALSE; 1273 return FALSE;
1274 1274
1275 QString categoryName = _item->text (0); 1275 QString categoryName = _item->text (0);
1276 if (categories.find (categoryName)) 1276 if (categories.find (categoryName))
1277 return TRUE; 1277 return TRUE;
1278 else 1278 else
1279 return FALSE; 1279 return FALSE;
1280} 1280}
1281 1281
1282void ZSafe::removeAsciiFile() 1282void ZSafe::removeAsciiFile()
1283{ 1283{
1284 // QString fn = filename + ".txt"; 1284 // QString fn = filename + ".txt";
1285 // open the file dialog 1285 // open the file dialog
1286#ifndef DESKTOP 1286#ifndef DESKTOP
1287#ifndef NO_OPIE 1287#ifndef NO_OPIE
1288 QMap<QString, QStringList> mimeTypes; 1288 QMap<QString, QStringList> mimeTypes;
1289 mimeTypes.insert(tr("All"), QStringList() ); 1289 mimeTypes.insert(tr("All"), QStringList() );
1290 mimeTypes.insert(tr("Text"), "text/*" ); 1290 mimeTypes.insert(tr("Text"), "text/*" );
1291 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1291 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1292 QDir::homeDirPath() + "/Documents/application/zsafe", 1292 QDir::homeDirPath() + "/Documents/application/zsafe",
1293 QString::null, 1293 QString::null,
1294 mimeTypes, 1294 mimeTypes,
1295 this, 1295 this,
1296 tr ("Remove text file")); 1296 tr ("Remove text file"));
1297#else 1297#else
1298 QString fn = ScQtFileEdit::getOpenFileName(this, 1298 QString fn = ScQtFileEdit::getOpenFileName(this,
1299 tr ("Remove text file"), 1299 tr ("Remove text file"),
1300 QDir::homeDirPath() + "/Documents/application/zsafe", 1300 QDir::homeDirPath() + "/Documents/application/zsafe",
1301 "*.txt"); 1301 "*.txt");
1302#endif 1302#endif
1303#else 1303#else
1304 QString fn = QFileDialog::getOpenFileName( 1304 QString fn = QFileDialog::getOpenFileName(
1305 QDir::homeDirPath() + "/Documents/application/zsafe", 1305 QDir::homeDirPath() + "/Documents/application/zsafe",
1306 "ZSafe (*.txt)", 1306 "ZSafe (*.txt)",
1307 this, 1307 this,
1308 "ZSafe File Dialog" 1308 "ZSafe File Dialog"
1309 "Choose a text file" ); 1309 "Choose a text file" );
1310#endif 1310#endif
1311 1311
1312 if (fn && fn.length() > 0 ) 1312 if (fn && fn.length() > 0 )
1313 { 1313 {
1314 QFile f( fn ); 1314 QFile f( fn );
1315 if ( !f.remove() ) 1315 if ( !f.remove() )
1316 { 1316 {
1317#ifndef NO_OPIE 1317#ifndef NO_OPIE
1318 owarn << "Could not remove file " << fn << oendl; 1318 owarn << "Could not remove file " << fn << oendl;
1319#else 1319#else
1320 qWarning( QString("Could not remove file %1").arg(fn),2000 ); 1320 qWarning( QString("Could not remove file %1").arg(fn),2000 );
1321#endif 1321#endif
1322 QMessageBox::critical( 0, tr("ZSafe"), 1322 QMessageBox::critical( 0, tr("ZSafe"),
1323 tr("Could not remove text file.") ); 1323 tr("Could not remove text file.") );
1324 return; 1324 return;
1325 } 1325 }
1326 } 1326 }
1327} 1327}
1328 1328
1329void ZSafe::writeAllEntries() 1329void ZSafe::writeAllEntries()
1330{ 1330{
1331 if (filename.isEmpty()) 1331 if (filename.isEmpty())
1332 { 1332 {
1333 QMessageBox::critical( 0, tr("ZSafe"), 1333 QMessageBox::critical( 0, tr("ZSafe"),
1334 tr("No document defined.\nYou have to create a new document")); 1334 tr("No document defined.\nYou have to create a new document"));
1335 return; 1335 return;
1336 } 1336 }
1337 1337
1338 // open the file dialog 1338 // open the file dialog
1339 QString fn = zsaveDialog(); 1339 QString fn = zsaveDialog();
1340 // open the new document 1340 // open the new document
1341 if (fn && fn.length() > 0 ) 1341 if (fn && fn.length() > 0 )
1342 { 1342 {
1343 QFile f( fn ); 1343 QFile f( fn );
1344 if ( !f.open( IO_WriteOnly ) ) { 1344 if ( !f.open( IO_WriteOnly ) ) {
1345#ifndef NO_OPIE 1345#ifndef NO_OPIE
1346 owarn << "Could not write to file " << fn << oendl; 1346 owarn << "Could not write to file " << fn << oendl;
1347#else 1347#else
1348 qWarning( QString("Could not write to file %1").arg(fn),2000 ); 1348 qWarning( QString("Could not write to file %1").arg(fn),2000 );
1349#endif 1349#endif
1350 QMessageBox::critical( 0, "ZSafe", 1350 QMessageBox::critical( 0, "ZSafe",
1351 QString("Could not export to text file.") ); 1351 QString("Could not export to text file.") );
1352 return; 1352 return;
1353 } 1353 }
1354 QTextStream t( &f ); 1354 QTextStream t( &f );
1355 1355
1356 QListViewItem *i; 1356 QListViewItem *i;
1357 // step through all categories 1357 // step through all categories
1358 for (i = ListView->firstChild(); 1358 for (i = ListView->firstChild();
1359 i != NULL; 1359 i != NULL;
1360 i = i->nextSibling()) 1360 i = i->nextSibling())
1361 { 1361 {
1362 // step through all subitems 1362 // step through all subitems
1363 QListViewItem *si; 1363 QListViewItem *si;
1364 for (si = i->firstChild(); 1364 for (si = i->firstChild();
1365 si != NULL; 1365 si != NULL;
1366 si = si->nextSibling()) 1366 si = si->nextSibling())
1367 { 1367 {
1368 QString oneEntry; 1368 QString oneEntry;
1369 oneEntry += "\""; 1369 oneEntry += "\"";
1370 oneEntry += i->text(0); 1370 oneEntry += i->text(0);
1371 oneEntry += "\";"; 1371 oneEntry += "\";";
1372 oneEntry += "\""; 1372 oneEntry += "\"";
1373 oneEntry += si->text(0); 1373 oneEntry += si->text(0);
1374 oneEntry += "\";"; 1374 oneEntry += "\";";
1375 oneEntry += "\""; 1375 oneEntry += "\"";
1376 oneEntry += si->text(1); 1376 oneEntry += si->text(1);
1377 oneEntry += "\";"; 1377 oneEntry += "\";";
1378 oneEntry += "\""; 1378 oneEntry += "\"";
1379 oneEntry += si->text(2); 1379 oneEntry += si->text(2);
1380 oneEntry += "\";"; 1380 oneEntry += "\";";
1381 oneEntry += "\""; 1381 oneEntry += "\"";
1382 QString comment = si->text(3); 1382 QString comment = si->text(3);
1383 comment.replace (QRegExp("\n"), "<br>"); 1383 comment.replace (QRegExp("\n"), "<br>");
1384 oneEntry += comment; 1384 oneEntry += comment;
1385 oneEntry += "\";"; 1385 oneEntry += "\";";
1386 oneEntry += "\""; 1386 oneEntry += "\"";
1387 oneEntry += si->text(4); 1387 oneEntry += si->text(4);
1388 oneEntry += "\";"; 1388 oneEntry += "\";";
1389 oneEntry += "\""; 1389 oneEntry += "\"";
1390 oneEntry += si->text(5); 1390 oneEntry += si->text(5);
1391 oneEntry += "\""; 1391 oneEntry += "\"";
1392 // owarn << oneEntry << oendl; 1392 // owarn << oneEntry << oendl;
1393 t << oneEntry << endl; 1393 t << oneEntry << endl;
1394 1394
1395 // owarn << si->text(0) << oendl; 1395 // owarn << si->text(0) << oendl;
1396 } 1396 }
1397 } 1397 }
1398 f.close(); 1398 f.close();
1399 } 1399 }
1400} 1400}
1401 1401
1402void ZSafe::readAllEntries() 1402void ZSafe::readAllEntries()
1403{ 1403{
1404 if (filename.isEmpty()) 1404 if (filename.isEmpty())
1405 { 1405 {
1406 QMessageBox::critical( 0, tr("ZSafe"), 1406 QMessageBox::critical( 0, tr("ZSafe"),
1407 tr("No document defined.\nYou have to create a new document")); 1407 tr("No document defined.\nYou have to create a new document"));
1408 return; 1408 return;
1409 } 1409 }
1410 1410
1411 // open the file dialog 1411 // open the file dialog
1412#ifndef DESKTOP 1412#ifndef DESKTOP
1413#ifndef NO_OPIE 1413#ifndef NO_OPIE
1414 QMap<QString, QStringList> mimeTypes; 1414 QMap<QString, QStringList> mimeTypes;
1415 mimeTypes.insert(tr("All"), QStringList() ); 1415 mimeTypes.insert(tr("All"), QStringList() );
1416 mimeTypes.insert(tr("Text"), "text/*" ); 1416 mimeTypes.insert(tr("Text"), "text/*" );
1417 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1417 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1418 QDir::homeDirPath() + "/Documents/application/zsafe", 1418 QDir::homeDirPath() + "/Documents/application/zsafe",
1419 QString::null, 1419 QString::null,
1420 mimeTypes, 1420 mimeTypes,
1421 this, 1421 this,
1422 tr ("Import text file")); 1422 tr ("Import text file"));
1423#else 1423#else
1424 QString fn = ScQtFileEdit::getOpenFileName(this, 1424 QString fn = ScQtFileEdit::getOpenFileName(this,
1425 tr ("Import text file"), 1425 tr ("Import text file"),
1426 QDir::homeDirPath() + "/Documents/application/zsafe", 1426 QDir::homeDirPath() + "/Documents/application/zsafe",
1427 "*.txt"); 1427 "*.txt");
1428#endif 1428#endif
1429#else 1429#else
1430 QString fn = QFileDialog::getOpenFileName( 1430 QString fn = QFileDialog::getOpenFileName(
1431 QDir::homeDirPath() + "/Documents/application/zsafe", 1431 QDir::homeDirPath() + "/Documents/application/zsafe",
1432 "ZSafe (*.txt)", 1432 "ZSafe (*.txt)",
1433 this, 1433 this,
1434 "ZSafe File Dialog" 1434 "ZSafe File Dialog"
1435 "Choose a text file" ); 1435 "Choose a text file" );
1436#endif 1436#endif
1437 1437
1438 if (fn && fn.length() > 0 ) 1438 if (fn && fn.length() > 0 )
1439 { 1439 {
1440 QFile f( fn ); 1440 QFile f( fn );
1441 if ( !f.open( IO_ReadOnly ) ) 1441 if ( !f.open( IO_ReadOnly ) )
1442 { 1442 {
1443#ifndef NO_OPIE 1443#ifndef NO_OPIE
1444 owarn << "Could not read file " << fn << oendl; 1444 owarn << "Could not read file " << fn << oendl;
1445#else 1445#else
1446 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1446 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1447#endif 1447#endif
1448 QMessageBox::critical( 0, "ZSafe", 1448 QMessageBox::critical( 0, "ZSafe",
1449 QString("Could not import text file.") ); 1449 QString("Could not import text file.") );
1450 return; 1450 return;
1451 } 1451 }
1452 1452
1453 modified = true; 1453 modified = true;
1454 1454
1455 // clear the password list 1455 // clear the password list
1456 selectedItem = NULL; 1456 selectedItem = NULL;
1457 QListViewItem *i; 1457 QListViewItem *i;
1458 // step through all categories 1458 // step through all categories
1459 for (i = ListView->firstChild(); 1459 for (i = ListView->firstChild();
1460 i != NULL; 1460 i != NULL;
1461 i = i->nextSibling()) 1461 i = i->nextSibling())
1462 { 1462 {
1463 // step through all subitems 1463 // step through all subitems
1464 QListViewItem *si; 1464 QListViewItem *si;
1465 for (si = i->firstChild(); 1465 for (si = i->firstChild();
1466 si != NULL; ) 1466 si != NULL; )
1467 // si = si->nextSibling()) 1467 // si = si->nextSibling())
1468 { 1468 {
1469 QListViewItem *_si = si; 1469 QListViewItem *_si = si;
1470 si = si->nextSibling(); 1470 si = si->nextSibling();
1471 i->takeItem(_si); // remove from view list 1471 i->takeItem(_si); // remove from view list
1472 if (_si) delete _si; 1472 if (_si) delete _si;
1473 } 1473 }
1474 } 1474 }
1475 1475
1476#ifndef NO_OPIE 1476#ifndef NO_OPIE
1477 owarn << "ReadAllEntries(): " << oendl; 1477 owarn << "ReadAllEntries(): " << oendl;
1478#else 1478#else
1479 qWarning ("ReadAllEntries(): "); 1479 qWarning ("ReadAllEntries(): ");
1480#endif 1480#endif
1481 1481
1482 QTextStream t(&f); 1482 QTextStream t(&f);
1483 while ( !t.eof() ) 1483 while ( !t.eof() )
1484 { 1484 {
1485 QString s = t.readLine(); 1485 QString s = t.readLine();
1486 s.replace (QRegExp("\";\""), "\"|\""); 1486 s.replace (QRegExp("\";\""), "\"|\"");
1487 // char buffer[1024]; 1487 // char buffer[1024];
1488#ifndef Q_WS_WIN 1488#ifndef Q_WS_WIN
1489 char buffer[s.length()+1]; 1489 char buffer[s.length()+1];
1490#else 1490#else
1491 char buffer[4048]; 1491 char buffer[4048];
1492#endif 1492#endif
1493 1493
1494 1494
1495 /* modify QString -> QCString::utf8 */ 1495 /* modify QString -> QCString::utf8 */
1496 1496
1497 strcpy (buffer, s.utf8()); 1497 strcpy (buffer, s.utf8());
1498 1498
1499 QString name; 1499 QString name;
1500 QString user; 1500 QString user;
1501 QString password; 1501 QString password;
1502 QString comment; 1502 QString comment;
1503 QString field5=""; 1503 QString field5="";
1504 QString field6=""; 1504 QString field6="";
1505 1505
1506 // separete the entries 1506 // separete the entries
1507 char *i = strtok (buffer, "|"); 1507 char *i = strtok (buffer, "|");
1508 QString category(QString::fromUtf8(&i[1])); 1508 QString category(QString::fromUtf8(&i[1]));
1509 category.truncate(category.length() -1); 1509 category.truncate(category.length() -1);
1510 1510
1511 int idx=0; 1511 int idx=0;
1512 while ((i = strtok (NULL, "|")) != NULL) 1512 while ((i = strtok (NULL, "|")) != NULL)
1513 { 1513 {
1514 switch (idx) 1514 switch (idx)
1515 { 1515 {
1516 case 0: 1516 case 0:
1517 name = QString::fromUtf8(&i[1]); 1517 name = QString::fromUtf8(&i[1]);
1518 name.truncate(name.length() -1); 1518 name.truncate(name.length() -1);
1519 // name 1519 // name
1520 break; 1520 break;
1521 case 1: 1521 case 1:
1522 // user 1522 // user
1523 user = QString::fromUtf8(&i[1]); 1523 user = QString::fromUtf8(&i[1]);
1524 user.truncate(user.length() -1); 1524 user.truncate(user.length() -1);
1525 break; 1525 break;
1526 case 2: 1526 case 2:
1527 // password 1527 // password
1528 password = QString::fromUtf8(&i[1]); 1528 password = QString::fromUtf8(&i[1]);
1529 password.truncate(password.length() -1); 1529 password.truncate(password.length() -1);
1530 break; 1530 break;
1531 case 3: 1531 case 3:
1532 // comment 1532 // comment
1533 comment = QString::fromUtf8(&i[1]); 1533 comment = QString::fromUtf8(&i[1]);
1534 comment.truncate(comment.length() -1); 1534 comment.truncate(comment.length() -1);
1535 break; 1535 break;
1536 case 4: 1536 case 4:
1537 // field5 1537 // field5
1538 field5 = QString::fromUtf8(&i[1]); 1538 field5 = QString::fromUtf8(&i[1]);
1539 field5.truncate(field5.length() -1); 1539 field5.truncate(field5.length() -1);
1540 break; 1540 break;
1541 case 5: 1541 case 5:
1542 // field6 1542 // field6
1543 field6 = QString::fromUtf8(&i[1]); 1543 field6 = QString::fromUtf8(&i[1]);
1544 field6.truncate(field6.length() -1); 1544 field6.truncate(field6.length() -1);
1545 break; 1545 break;
1546 } 1546 }
1547 idx++; 1547 idx++;
1548 } 1548 }
1549 1549
1550 Category *cat= categories.find (category); 1550 Category *cat= categories.find (category);
1551 if (cat) 1551 if (cat)
1552 { 1552 {
1553 // use the existend item 1553 // use the existend item
1554 QListViewItem *catItem = cat->getListItem(); 1554 QListViewItem *catItem = cat->getListItem();
1555 if (catItem) 1555 if (catItem)
1556 { 1556 {
1557 QListViewItem * item = new ShadedListItem( 0, catItem ); 1557 QListViewItem * item = new ShadedListItem( 0, catItem );
1558 item->setText( 0, tr( name ) ); 1558 item->setText( 0, tr( name ) );
1559 item->setText( 1, tr( user ) ); 1559 item->setText( 1, tr( user ) );
1560 item->setText( 2, tr( password ) ); 1560 item->setText( 2, tr( password ) );
1561 item->setText( 3, tr( comment ) ); 1561 item->setText( 3, tr( comment ) );
1562 item->setText( 4, tr( field5 ) ); 1562 item->setText( 4, tr( field5 ) );
1563 item->setText( 5, tr( field6 ) ); 1563 item->setText( 5, tr( field6 ) );
1564 catItem->setOpen( TRUE ); 1564 catItem->setOpen( TRUE );
1565 } 1565 }
1566 } 1566 }
1567 else 1567 else
1568 { 1568 {
1569 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1569 QListViewItem *catI = new ShadedListItem( 1, ListView );
1570 // create and insert a new item 1570 // create and insert a new item
1571 QListViewItem * item = new ShadedListItem( 0, catI ); 1571 QListViewItem * item = new ShadedListItem( 0, catI );
1572 item->setText( 0, tr( name ) ); 1572 item->setText( 0, tr( name ) );
1573 item->setText( 1, tr( user ) ); 1573 item->setText( 1, tr( user ) );
1574 item->setText( 2, tr( password ) ); 1574 item->setText( 2, tr( password ) );
1575 item->setText( 3, tr( comment ) ); 1575 item->setText( 3, tr( comment ) );
1576 item->setText( 4, tr( field5 ) ); 1576 item->setText( 4, tr( field5 ) );
1577 item->setText( 5, tr( field6 ) ); 1577 item->setText( 5, tr( field6 ) );
1578 1578
1579 catI->setOpen( TRUE ); 1579 catI->setOpen( TRUE );
1580 1580
1581 Category *c1 = new Category(); 1581 Category *c1 = new Category();
1582 c1->setCategoryName(category); 1582 c1->setCategoryName(category);
1583 1583
1584 QString icon; 1584 QString icon;
1585 QString fullIconPath; 1585 QString fullIconPath;
1586 QPixmap *pix; 1586 QPixmap *pix;
1587// #ifndef Q_WS_WIN 1587// #ifndef Q_WS_WIN
1588 icon = conf->readEntry(APP_KEY+category); 1588 icon = conf->readEntry(APP_KEY+category);
1589// #endif 1589// #endif
1590 bool isIconAv = false; 1590 bool isIconAv = false;
1591 if (!icon.isEmpty() && !icon.isNull()) 1591 if (!icon.isEmpty() && !icon.isNull())
1592 { 1592 {
1593 // build the full path 1593 // build the full path
1594 fullIconPath = iconPath + icon; 1594 fullIconPath = iconPath + icon;
1595 pix = new QPixmap (fullIconPath); 1595 pix = new QPixmap (fullIconPath);
1596 if (!pix->isNull()) 1596 if (!pix->isNull())
1597 { 1597 {
1598 QImage img = pix->convertToImage(); 1598 QImage img = pix->convertToImage();
1599 pix->convertFromImage(img.smoothScale(14,14)); 1599 pix->convertFromImage(img.smoothScale(14,14));
1600 c1->setIconName (icon); 1600 c1->setIconName (icon);
1601 c1->setIcon (*pix); 1601 c1->setIcon (*pix);
1602 isIconAv = true; 1602 isIconAv = true;
1603 } 1603 }
1604 } 1604 }
1605 if (!isIconAv) 1605 if (!isIconAv)
1606 { 1606 {
1607 c1->setIcon (*getPredefinedIcon(category)); 1607 c1->setIcon (*getPredefinedIcon(category));
1608 } 1608 }
1609 c1->setListItem (catI); 1609 c1->setListItem (catI);
1610 c1->initListItem(); 1610 c1->initListItem();
1611 categories.insert (c1->getCategoryName(), c1); 1611 categories.insert (c1->getCategoryName(), c1);
1612 } 1612 }
1613 1613
1614 } 1614 }
1615 f.close(); 1615 f.close();
1616 1616
1617 } 1617 }
1618 else 1618 else
1619 { 1619 {
1620 } 1620 }
1621 1621
1622} 1622}
1623 1623
1624#ifdef UNUSED 1624#ifdef UNUSED
1625void ZSafe::writeAllEntries() 1625void ZSafe::writeAllEntries()
1626{ 1626{
1627 if (filename.isEmpty()) 1627 if (filename.isEmpty())
1628 { 1628 {
1629 QMessageBox::critical( 0, tr("ZSafe"), 1629 QMessageBox::critical( 0, tr("ZSafe"),
1630 tr("<P>No document defined. You have to create a new document</P>")); 1630 tr("<P>No document defined. You have to create a new document</P>"));
1631 return; 1631 return;
1632 } 1632 }
1633 1633
1634 // open the file for writing 1634 // open the file for writing
1635 QString fn = filename + ".txt"; 1635 QString fn = filename + ".txt";
1636 QFile f( fn ); 1636 QFile f( fn );
1637 if ( !f.open( IO_WriteOnly ) ) { 1637 if ( !f.open( IO_WriteOnly ) ) {
1638#ifndef NO_OPIE 1638#ifndef NO_OPIE
1639 owarn << "Could not write to file " << fn << oendl; 1639 owarn << "Could not write to file " << fn << oendl;
1640#else 1640#else
1641 qWarning( QString("Could not write to file %1").arg(fn), 2000 ); 1641 qWarning( QString("Could not write to file %1").arg(fn), 2000 );
1642#endif 1642#endif
1643 QMessageBox::critical( 0, tr("ZSafe"), 1643 QMessageBox::critical( 0, tr("ZSafe"),
1644 tr("Could not export to text file.") ); 1644 tr("Could not export to text file.") );
1645 return; 1645 return;
1646 } 1646 }
1647 QTextStream t( &f ); 1647 QTextStream t( &f );
1648 1648
1649 QListViewItem *i; 1649 QListViewItem *i;
1650 // step through all categories 1650 // step through all categories
1651 for (i = ListView->firstChild(); 1651 for (i = ListView->firstChild();
1652 i != NULL; 1652 i != NULL;
1653 i = i->nextSibling()) 1653 i = i->nextSibling())
1654 { 1654 {
1655 // step through all subitems 1655 // step through all subitems
1656 QListViewItem *si; 1656 QListViewItem *si;
1657 for (si = i->firstChild(); 1657 for (si = i->firstChild();
1658 si != NULL; 1658 si != NULL;
1659 si = si->nextSibling()) 1659 si = si->nextSibling())
1660 { 1660 {
1661 QString oneEntry; 1661 QString oneEntry;
1662 oneEntry += "\""; 1662 oneEntry += "\"";
1663 oneEntry += i->text(0); 1663 oneEntry += i->text(0);
1664 oneEntry += "\";"; 1664 oneEntry += "\";";
1665 oneEntry += "\""; 1665 oneEntry += "\"";
1666 oneEntry += si->text(0); 1666 oneEntry += si->text(0);
1667 oneEntry += "\";"; 1667 oneEntry += "\";";
1668 oneEntry += "\""; 1668 oneEntry += "\"";
1669 oneEntry += si->text(1); 1669 oneEntry += si->text(1);
1670 oneEntry += "\";"; 1670 oneEntry += "\";";
1671 oneEntry += "\""; 1671 oneEntry += "\"";
1672 oneEntry += si->text(2); 1672 oneEntry += si->text(2);
1673 oneEntry += "\";"; 1673 oneEntry += "\";";
1674 oneEntry += "\""; 1674 oneEntry += "\"";
1675 // oneEntry += si->text(3); 1675 // oneEntry += si->text(3);
1676 QString comment = si->text(3); 1676 QString comment = si->text(3);
1677 comment.replace (QRegExp("\n"), "<br>"); 1677 comment.replace (QRegExp("\n"), "<br>");
1678 oneEntry += comment; 1678 oneEntry += comment;
1679 oneEntry += "\""; 1679 oneEntry += "\"";
1680 // owarn << oneEntry << oendl; 1680 // owarn << oneEntry << oendl;
1681 t << oneEntry << endl; 1681 t << oneEntry << endl;
1682 1682
1683 // owarn << si->text(0) << oendl; 1683 // owarn << si->text(0) << oendl;
1684 } 1684 }
1685 } 1685 }
1686 f.close(); 1686 f.close();
1687} 1687}
1688 1688
1689void ZSafe::readAllEntries() 1689void ZSafe::readAllEntries()
1690{ 1690{
1691 QString fn = filename + ".txt"; 1691 QString fn = filename + ".txt";
1692 QFile f( fn ); 1692 QFile f( fn );
1693 if ( !f.open( IO_ReadOnly ) ) 1693 if ( !f.open( IO_ReadOnly ) )
1694 { 1694 {
1695#ifndef NO_OPIE 1695#ifndef NO_OPIE
1696 owarn << "Could not read file " << fn << oendl; 1696 owarn << "Could not read file " << fn << oendl;
1697#else 1697#else
1698 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1698 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1699#endif 1699#endif
1700 QMessageBox::critical( 0, tr("ZSafe"), 1700 QMessageBox::critical( 0, tr("ZSafe"),
1701 tr("Could not import text file.") ); 1701 tr("Could not import text file.") );
1702 return; 1702 return;
1703 } 1703 }
1704 1704
1705 modified = true; 1705 modified = true;
1706 1706
1707 // clear the password list 1707 // clear the password list
1708 selectedItem = NULL; 1708 selectedItem = NULL;
1709 QListViewItem *i; 1709 QListViewItem *i;
1710 // step through all categories 1710 // step through all categories
1711 for (i = ListView->firstChild(); 1711 for (i = ListView->firstChild();
1712 i != NULL; 1712 i != NULL;
1713 i = i->nextSibling()) 1713 i = i->nextSibling())
1714 { 1714 {
1715 // step through all subitems 1715 // step through all subitems
1716 QListViewItem *si; 1716 QListViewItem *si;
1717 for (si = i->firstChild(); 1717 for (si = i->firstChild();
1718 si != NULL; ) 1718 si != NULL; )
1719 // si = si->nextSibling()) 1719 // si = si->nextSibling())
1720 { 1720 {
1721 QListViewItem *_si = si; 1721 QListViewItem *_si = si;
1722 si = si->nextSibling(); 1722 si = si->nextSibling();
1723 i->takeItem(_si); // remove from view list 1723 i->takeItem(_si); // remove from view list
1724 if (_si) delete _si; 1724 if (_si) delete _si;
1725 } 1725 }
1726 } 1726 }
1727 1727
1728#ifndef NO_OPIE 1728#ifndef NO_OPIE
1729 owarn << "ReadAllEntries(): " << oendl; 1729 owarn << "ReadAllEntries(): " << oendl;
1730#else 1730#else
1731 qWarning ("ReadAllEntries(): "); 1731 qWarning ("ReadAllEntries(): ");
1732#endif 1732#endif
1733 QTextStream t(&f); 1733 QTextStream t(&f);
1734 while ( !t.eof() ) 1734 while ( !t.eof() )
1735 { 1735 {
1736 QString s = t.readLine(); 1736 QString s = t.readLine();
1737 s.replace (QRegExp("\";\""), "\"|\""); 1737 s.replace (QRegExp("\";\""), "\"|\"");
1738 // char buffer[1024]; 1738 // char buffer[1024];
1739 int len=s.length()+1; 1739 int len=s.length()+1;
1740#ifdef Q_WS_WIN 1740#ifdef Q_WS_WIN
1741 char buffer[512]; 1741 char buffer[512];
1742#else 1742#else
1743 char buffer[len]; 1743 char buffer[len];
1744#endif 1744#endif
1745 strcpy (buffer, s); 1745 strcpy (buffer, s);
1746 1746
1747 QString name; 1747 QString name;
1748 QString user; 1748 QString user;
1749 QString password; 1749 QString password;
1750 QString comment; 1750 QString comment;
1751 1751
1752 // separete the entries 1752 // separete the entries
1753 char *i = strtok (buffer, "|"); 1753 char *i = strtok (buffer, "|");
1754 QString category(&i[1]); 1754 QString category(&i[1]);
1755 category.truncate(category.length() -1); 1755 category.truncate(category.length() -1);
1756 1756
1757 int idx=0; 1757 int idx=0;
1758 while (i = strtok (NULL, "|")) 1758 while (i = strtok (NULL, "|"))
1759 { 1759 {
1760 switch (idx) 1760 switch (idx)
1761 { 1761 {
1762 case 0: 1762 case 0:
1763 name = &i[1]; 1763 name = &i[1];
1764 name.truncate(name.length() -1); 1764 name.truncate(name.length() -1);
1765 // name 1765 // name
1766 break; 1766 break;
1767 case 1: 1767 case 1:
1768 // user 1768 // user
1769 user = &i[1]; 1769 user = &i[1];
1770 user.truncate(user.length() -1); 1770 user.truncate(user.length() -1);
1771 break; 1771 break;
1772 case 2: 1772 case 2:
1773 // password 1773 // password
1774 password = &i[1]; 1774 password = &i[1];
1775 password.truncate(password.length() -1); 1775 password.truncate(password.length() -1);
1776 break; 1776 break;
1777 case 3: 1777 case 3:
1778 // comment 1778 // comment
1779 comment = &i[1]; 1779 comment = &i[1];
1780 comment.truncate(comment.length() -1); 1780 comment.truncate(comment.length() -1);
1781 break; 1781 break;
1782 } 1782 }
1783 idx++; 1783 idx++;
1784 } 1784 }
1785 1785
1786 Category *cat= categories.find (category); 1786 Category *cat= categories.find (category);
1787 if (cat) 1787 if (cat)
1788 { 1788 {
1789 // use the existend item 1789 // use the existend item
1790 QListViewItem *catItem = cat->getListItem(); 1790 QListViewItem *catItem = cat->getListItem();
1791 if (catItem) 1791 if (catItem)
1792 { 1792 {
1793 QListViewItem * item = new ShadedListItem( 0, catItem ); 1793 QListViewItem * item = new ShadedListItem( 0, catItem );
1794 item->setText( 0, tr( name ) ); 1794 item->setText( 0, tr( name ) );
1795 item->setText( 1, tr( user ) ); 1795 item->setText( 1, tr( user ) );
1796 item->setText( 2, tr( password ) ); 1796 item->setText( 2, tr( password ) );
1797 item->setText( 3, tr( comment ) ); 1797 item->setText( 3, tr( comment ) );
1798 1798
1799 catItem->setOpen( TRUE ); 1799 catItem->setOpen( TRUE );
1800 } 1800 }
1801 } 1801 }
1802 else 1802 else
1803 { 1803 {
1804 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1804 QListViewItem *catI = new ShadedListItem( 1, ListView );
1805 // create and insert a new item 1805 // create and insert a new item
1806 QListViewItem * item = new ShadedListItem( 0, catI ); 1806 QListViewItem * item = new ShadedListItem( 0, catI );
1807 item->setText( 0, tr( name ) ); 1807 item->setText( 0, tr( name ) );
1808 item->setText( 1, tr( user ) ); 1808 item->setText( 1, tr( user ) );
1809 item->setText( 2, tr( password ) ); 1809 item->setText( 2, tr( password ) );
1810 item->setText( 3, tr( comment ) ); 1810 item->setText( 3, tr( comment ) );
1811 1811
1812 catI->setOpen( TRUE ); 1812 catI->setOpen( TRUE );
1813 1813
1814 Category *c1 = new Category(); 1814 Category *c1 = new Category();
1815 c1->setCategoryName(category); 1815 c1->setCategoryName(category);
1816 1816
1817 QString icon; 1817 QString icon;
1818 QString fullIconPath; 1818 QString fullIconPath;
1819 QPixmap *pix; 1819 QPixmap *pix;
1820// #ifndef Q_WS_WIN 1820// #ifndef Q_WS_WIN
1821 icon = conf->readEntry(APP_KEY+category); 1821 icon = conf->readEntry(APP_KEY+category);
1822// #endif 1822// #endif
1823 bool isIconAv = false; 1823 bool isIconAv = false;
1824 if (!icon.isEmpty() && !icon.isNull()) 1824 if (!icon.isEmpty() && !icon.isNull())
1825 { 1825 {
1826 // build the full path 1826 // build the full path
1827 fullIconPath = iconPath + icon; 1827 fullIconPath = iconPath + icon;
1828 pix = new QPixmap (fullIconPath); 1828 pix = new QPixmap (fullIconPath);
1829 if (!pix->isNull()) 1829 if (!pix->isNull())
1830 { 1830 {
1831 QImage img = pix->convertToImage(); 1831 QImage img = pix->convertToImage();
1832 pix->convertFromImage(img.smoothScale(14,14)); 1832 pix->convertFromImage(img.smoothScale(14,14));
1833 c1->setIconName (icon); 1833 c1->setIconName (icon);
1834 c1->setIcon (*pix); 1834 c1->setIcon (*pix);
1835 isIconAv = true; 1835 isIconAv = true;
1836 } 1836 }
1837 } 1837 }
1838 if (!isIconAv) 1838 if (!isIconAv)
1839 { 1839 {
1840 c1->setIcon (*getPredefinedIcon(category)); 1840 c1->setIcon (*getPredefinedIcon(category));
1841 } 1841 }
1842 c1->setListItem (catI); 1842 c1->setListItem (catI);
1843 c1->initListItem(); 1843 c1->initListItem();
1844 categories.insert (c1->getCategoryName(), c1); 1844 categories.insert (c1->getCategoryName(), c1);
1845 } 1845 }
1846 1846
1847 } 1847 }
1848 f.close(); 1848 f.close();
1849 1849
1850} 1850}
1851#endif // UNUSED 1851#endif // UNUSED
1852 1852
1853void ZSafe::resume(int) 1853void ZSafe::resume(int)
1854{ 1854{
1855#ifndef NO_OPIE 1855#ifndef NO_OPIE
1856 owarn << "Resume" << oendl; 1856 owarn << "Resume" << oendl;
1857#endif 1857#endif
1858 // hide the main window 1858 // hide the main window
1859 1859
1860 if ( !showpwd ) 1860 if ( !showpwd )
1861 { 1861 {
1862 infoForm->hide(); 1862 infoForm->hide();
1863 // open zsafe again 1863 // open zsafe again
1864 m_password = ""; 1864 m_password = "";
1865 selectedItem = NULL; 1865 selectedItem = NULL;
1866 1866
1867 // clear the password list 1867 // clear the password list
1868 QListViewItem *i; 1868 QListViewItem *i;
1869 // step through all categories 1869 // step through all categories
1870 for (i = ListView->firstChild(); 1870 for (i = ListView->firstChild();
1871 i != NULL; 1871 i != NULL;
1872 i = i->nextSibling()) 1872 i = i->nextSibling())
1873 { 1873 {
1874 // step through all subitems 1874 // step through all subitems
1875 QListViewItem *si; 1875 QListViewItem *si;
1876 for (si = i->firstChild(); 1876 for (si = i->firstChild();
1877 si != NULL; ) 1877 si != NULL; )
1878 { 1878 {
1879 QListViewItem *_si = si; 1879 QListViewItem *_si = si;
1880 si = si->nextSibling(); 1880 si = si->nextSibling();
1881 i->takeItem(_si); // remove from view list 1881 i->takeItem(_si); // remove from view list
1882 if (_si) delete _si; 1882 if (_si) delete _si;
1883 } 1883 }
1884 } 1884 }
1885 1885
1886 // ask for password and read again 1886 // ask for password and read again
1887 openDocument(filename); 1887 openDocument(filename);
1888 } 1888 }
1889} 1889}
1890 1890
1891//--------------------------------------------- 1891//---------------------------------------------
1892 1892
1893 1893
1894bool ZSafe::openDocument(const char* _filename, const char* ) 1894bool ZSafe::openDocument(const char* _filename, const char* )
1895{ 1895{
1896 QString name= _filename; 1896 QString name= _filename;
1897 qWarning("openDocument "+name); 1897 qWarning("openDocument "+name);
1898 int retval; 1898 int retval;
1899 char* entry[FIELD_SIZE]; 1899 char* entry[FIELD_SIZE];
1900// #ifndef Q_WS_WIN 1900// #ifndef Q_WS_WIN
1901 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1901 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1902// #else 1902// #else
1903 // int validationFlag = 1; 1903 // int validationFlag = 1;
1904// #endif 1904// #endif
1905 1905
1906 int pwdOk = 0; 1906 int pwdOk = 0;
1907 int numberOfTries = 3; 1907 int numberOfTries = 3;
1908 for (int i=0; i < numberOfTries; i++) 1908 for (int i=0; i < numberOfTries; i++)
1909 { 1909 {
1910 QFile f(_filename); 1910 QFile f(_filename);
1911 if (f.exists()) 1911 if (f.exists())
1912 { 1912 {
1913 // ask with a dialog for the password 1913 // ask with a dialog for the password
1914 if (m_password.isEmpty()) 1914 if (m_password.isEmpty())
1915 getDocPassword(tr("Enter Password")); 1915 getDocPassword(tr("Enter Password"));
1916 if (m_password.isEmpty() && validationFlag == 0) 1916 if (m_password.isEmpty() && validationFlag == 0)
1917 { 1917 {
1918#ifndef NO_OPIE 1918#ifndef NO_OPIE
1919 owarn << "Wrong password" << oendl; 1919 owarn << "Wrong password" << oendl;
1920#else 1920#else
1921 qWarning ("Wrong password"); 1921 qWarning ("Wrong password");
1922#endif 1922#endif
1923 QMessageBox::critical( 0, tr("ZSafe"), 1923 QMessageBox::critical( 0, tr("ZSafe"),
1924 tr("Wrong password.\n\nZSafe will now exit.") ); 1924 tr("Wrong password.\n\nZSafe will now exit.") );
1925 exitZs (1); 1925 exitZs (1);
1926 } 1926 }
1927 1927
1928 retval = loadInit(_filename, m_password); 1928 retval = loadInit(_filename, m_password);
1929 if (retval != PWERR_GOOD) 1929 if (retval != PWERR_GOOD)
1930 { 1930 {
1931#ifndef NO_OPIE 1931#ifndef NO_OPIE
1932 owarn << "Error loading Document" << oendl; 1932 owarn << "Error loading Document" << oendl;
1933#else 1933#else
1934 qWarning ("Error loading Document"); 1934 qWarning ("Error loading Document");
1935#endif 1935#endif
1936 return false; 1936 return false;
1937 } 1937 }
1938 } 1938 }
1939 else 1939 else
1940 { 1940 {
1941#ifdef Q_WS_WIN 1941#ifdef Q_WS_WIN
1942 this->setCaption("Qt ZSafe"); 1942 this->setCaption("Qt ZSafe");
1943#else 1943#else
1944 this->setCaption("ZSafe"); 1944 this->setCaption("ZSafe");
1945#endif 1945#endif
1946 filename = ""; 1946 filename = "";
1947 switch( QMessageBox::warning( this, tr("ZSafe"), 1947 switch( QMessageBox::warning( this, tr("ZSafe"),
1948 tr("<P>You must create a new document first. Ok to create?</P>"), 1948 tr("<P>You must create a new document first. Ok to create?</P>"),
1949 tr("&Yes"), tr("&No."), 1949 tr("&Yes"), tr("&No."),
1950 0 1950 0
1951 ) ) 1951 ) )
1952 { 1952 {
1953 case 1: // No 1953 case 1: // No
1954 return false; 1954 return false;
1955 break; 1955 break;
1956 case 0: // Yes 1956 case 0: // Yes
1957 newDocument(); 1957 newDocument();
1958 return false; 1958 return false;
1959 break; 1959 break;
1960 } 1960 }
1961 1961
1962 } 1962 }
1963 1963
1964 1964
1965 // load the validation entry 1965 // load the validation entry
1966 if (validationFlag == 0) 1966 if (validationFlag == 0)
1967 { 1967 {
1968 pwdOk = 1; 1968 pwdOk = 1;
1969 break; 1969 break;
1970 } 1970 }
1971 1971
1972 retval = loadEntry(entry); 1972 retval = loadEntry(entry);
1973 if (retval == 1 && 1973 if (retval == 1 &&
1974 !strcmp (entry[0], "ZSAFECATEGORY") && 1974 !strcmp (entry[0], "ZSAFECATEGORY") &&
1975 !strcmp (entry[1], "name") && 1975 !strcmp (entry[1], "name") &&
1976 !strcmp (entry[2], "username") && 1976 !strcmp (entry[2], "username") &&
1977 !strcmp (entry[3], "password") && 1977 !strcmp (entry[3], "password") &&
1978 !strcmp (entry[4], "comment") ) 1978 !strcmp (entry[4], "comment") )
1979 { 1979 {
1980 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1980 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1981 pwdOk = 1; 1981 pwdOk = 1;
1982 break; 1982 break;
1983 } 1983 }
1984 else 1984 else
1985 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1985 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1986 fclose (fd); 1986 fclose (fd);
1987 m_password = ""; 1987 m_password = "";
1988 1988
1989 if (i < numberOfTries - 1) 1989 if (i < numberOfTries - 1)
1990 { 1990 {
1991 switch( QMessageBox::warning( this, tr("ZSafe"), 1991 switch( QMessageBox::warning( this, tr("ZSafe"),
1992 tr("Wrong password.\nEnter again?"), 1992 tr("Wrong password.\nEnter again?"),
1993 tr("&Yes"), tr("&No."), 1993 tr("&Yes"), tr("&No."),
1994 0 1994 0
1995 ) ) 1995 ) )
1996 { 1996 {
1997 case 1: // No 1997 case 1: // No
1998 exitZs (1); 1998 exitZs (1);
1999 break; 1999 break;
2000 case 0: // Yes 2000 case 0: // Yes
2001 continue; 2001 continue;
2002 } 2002 }
2003 } 2003 }
2004 } 2004 }
2005 if (pwdOk == 0) 2005 if (pwdOk == 0)
2006 { 2006 {
2007 // unset the document entry 2007 // unset the document entry
2008 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 2008 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
2009 if (conf) 2009 if (conf)
2010 delete conf; 2010 delete conf;
2011 2011
2012 exitZs (1); 2012 exitZs (1);
2013 } 2013 }
2014 2014
2015 2015
2016 retval = loadEntry(entry); 2016 retval = loadEntry(entry);
2017 2017
2018 int numberOfEntries=0; 2018 int numberOfEntries=0;
2019 while (retval == 1) { 2019 while (retval == 1) {
2020 2020
2021 QString category( QString::fromUtf8(entry[0]) ); 2021 QString category( QString::fromUtf8(entry[0]) );
2022 QString name( QString::fromUtf8(entry[1]) ); 2022 QString name( QString::fromUtf8(entry[1]) );
2023 QString user( QString::fromUtf8(entry[2]) ); 2023 QString user( QString::fromUtf8(entry[2]) );
2024 QString password( QString::fromUtf8(entry[3]) ); 2024 QString password( QString::fromUtf8(entry[3]) );
2025 QString comment( QString::fromUtf8(entry[4]) ); 2025 QString comment( QString::fromUtf8(entry[4]) );
2026 QString field5( QString::fromUtf8(entry[5]) ); 2026 QString field5( QString::fromUtf8(entry[5]) );
2027 QString field6( QString::fromUtf8(entry[6]) ); 2027 QString field6( QString::fromUtf8(entry[6]) );
2028 // add the subitems to the categories 2028 // add the subitems to the categories
2029 2029
2030 Category *cat= categories.find (category); 2030 Category *cat= categories.find (category);
2031 if (cat) 2031 if (cat)
2032 { 2032 {
2033 // use the existend item 2033 // use the existend item
2034 QListViewItem *catItem = cat->getListItem(); 2034 QListViewItem *catItem = cat->getListItem();
2035 if (catItem) 2035 if (catItem)
2036 { 2036 {
2037 QListViewItem * item = new ShadedListItem( 0, catItem ); 2037 QListViewItem * item = new ShadedListItem( 0, catItem );
2038 item->setText( 0, tr( name ) ); 2038 item->setText( 0, tr( name ) );
2039 item->setText( 1, tr( user ) ); 2039 item->setText( 1, tr( user ) );
2040 item->setText( 2, tr( password ) ); 2040 item->setText( 2, tr( password ) );
2041 item->setText( 3, tr( comment ) ); 2041 item->setText( 3, tr( comment ) );
2042 item->setText( 4, tr( field5 ) ); 2042 item->setText( 4, tr( field5 ) );
2043 item->setText( 5, tr( field6 ) ); 2043 item->setText( 5, tr( field6 ) );
2044 2044
2045 if (expandTree) 2045 if (expandTree)
2046 catItem->setOpen( TRUE ); 2046 catItem->setOpen( TRUE );
2047 numberOfEntries++; 2047 numberOfEntries++;
2048 } 2048 }
2049 } 2049 }
2050 else 2050 else
2051 { 2051 {
2052 QListViewItem *catI = new ShadedListItem( 1, ListView ); 2052 QListViewItem *catI = new ShadedListItem( 1, ListView );
2053 // create and insert a new item 2053 // create and insert a new item
2054 QListViewItem * item = new ShadedListItem( 0, catI ); 2054 QListViewItem * item = new ShadedListItem( 0, catI );
2055 2055
2056 item->setText( 0, tr( name ) ); 2056 item->setText( 0, tr( name ) );
2057 item->setText( 1, tr( user ) ); 2057 item->setText( 1, tr( user ) );
2058 item->setText( 2, tr( password ) ); 2058 item->setText( 2, tr( password ) );
2059 item->setText( 3, tr( comment ) ); 2059 item->setText( 3, tr( comment ) );
2060 item->setText( 4, tr( field5 ) ); 2060 item->setText( 4, tr( field5 ) );
2061 item->setText( 5, tr( field6 ) ); 2061 item->setText( 5, tr( field6 ) );
2062 2062
2063 if (expandTree) 2063 if (expandTree)
2064 catI->setOpen( TRUE ); 2064 catI->setOpen( TRUE );
2065 2065
2066 Category *c1 = new Category(); 2066 Category *c1 = new Category();
2067 c1->setCategoryName(category); 2067 c1->setCategoryName(category);
2068 2068
2069 QString icon; 2069 QString icon;
2070 QString fullIconPath; 2070 QString fullIconPath;
2071 QPixmap *pix; 2071 QPixmap *pix;
2072// #ifndef Q_WS_WIN 2072// #ifndef Q_WS_WIN
2073 icon = conf->readEntry(APP_KEY+category); 2073 icon = conf->readEntry(APP_KEY+category);
2074// #endif 2074// #endif
2075 bool isIconAv = false; 2075 bool isIconAv = false;
2076 if (!icon.isEmpty() && !icon.isNull()) 2076 if (!icon.isEmpty() && !icon.isNull())
2077 { 2077 {
2078 // build the full path 2078 // build the full path
2079 fullIconPath = iconPath + icon; 2079 fullIconPath = iconPath + icon;
2080 pix = new QPixmap (fullIconPath); 2080 pix = new QPixmap (fullIconPath);
2081 if (!pix->isNull()) 2081 if (!pix->isNull())
2082 { 2082 {
2083 QImage img = pix->convertToImage(); 2083 QImage img = pix->convertToImage();
2084 pix->convertFromImage(img.smoothScale(14,14)); 2084 pix->convertFromImage(img.smoothScale(14,14));
2085 c1->setIconName (icon); 2085 c1->setIconName (icon);
2086 c1->setIcon (*pix); 2086 c1->setIcon (*pix);
2087 isIconAv = true; 2087 isIconAv = true;
2088 } 2088 }
2089 } 2089 }
2090 if (!isIconAv) 2090 if (!isIconAv)
2091 { 2091 {
2092 c1->setIcon (*getPredefinedIcon(category)); 2092 c1->setIcon (*getPredefinedIcon(category));
2093 } 2093 }
2094 2094
2095 c1->setListItem (catI); 2095 c1->setListItem (catI);
2096 c1->initListItem(); 2096 c1->initListItem();
2097 categories.insert (c1->getCategoryName(), c1); 2097 categories.insert (c1->getCategoryName(), c1);
2098 numberOfEntries++; 2098 numberOfEntries++;
2099 } 2099 }
2100 2100
2101 for (int count = 0; count < FIELD_SIZE; count++) { 2101 for (int count = 0; count < FIELD_SIZE; count++) {
2102 free(entry[count]); 2102 free(entry[count]);
2103 } 2103 }
2104 retval = loadEntry(entry); 2104 retval = loadEntry(entry);
2105 if (retval == 2) { 2105 if (retval == 2) {
2106 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2106 // m_parent->slotStatusHelpMsg("Last entry loaded");
2107 } 2107 }
2108 } // end while 2108 } // end while
2109 2109
2110 if (numberOfEntries == 0) 2110 if (numberOfEntries == 0)
2111 { 2111 {
2112 2112
2113 switch( QMessageBox::warning( this, tr("ZSafe"), 2113 switch( QMessageBox::warning( this, tr("ZSafe"),
2114 tr("Empty document or\nwrong password.\nContinue?"), 2114 tr("Empty document or\nwrong password.\nContinue?"),
2115 tr("&No"), tr("&Yes."), 2115 tr("&No"), tr("&Yes."),
2116 0 2116 0
2117 ) ) { 2117 ) ) {
2118 case 0: // No 2118 case 0: // No
2119 retval = loadFinalize(); 2119 retval = loadFinalize();
2120 exitZs (1); 2120 exitZs (1);
2121 break; 2121 break;
2122 case 1: // Yes 2122 case 1: // Yes
2123 break; 2123 break;
2124 } 2124 }
2125 } 2125 }
2126 2126
2127 retval = loadFinalize(); 2127 retval = loadFinalize();
2128 2128
2129 return true; 2129 return true;
2130} 2130}
2131 2131
2132int ZSafe::loadInit(const char* _filename, const char *password) 2132int ZSafe::loadInit(const char* _filename, const char *password)
2133{ 2133{
2134 unsigned int j = 0; 2134 unsigned int j = 0;
2135 unsigned int keylength=0; 2135 unsigned int keylength=0;
2136 int count=0, count2=0, count3=0; 2136 int count=0, count2=0, count3=0;
2137 unsigned char charbuf[8]; 2137 unsigned char charbuf[8];
2138 unsigned short ciphertext[4]; 2138 unsigned short ciphertext[4];
2139 char key[128]; 2139 char key[128];
2140 Krc2* krc2 = new Krc2(); 2140 Krc2* krc2 = new Krc2();
2141 2141
2142 fd = fopen (_filename, "rb"); 2142 fd = fopen (_filename, "rb");
2143 2143
2144 QFileInfo f (_filename); 2144 QFileInfo f (_filename);
2145 load_buffer_length = f.size(); 2145 load_buffer_length = f.size();
2146 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2146 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2147 2147
2148 if (fd == NULL) 2148 if (fd == NULL)
2149 return PWERR_OPEN; 2149 return PWERR_OPEN;
2150 2150
2151 buffer = (char *)malloc(load_buffer_length); 2151 buffer = (char *)malloc(load_buffer_length);
2152 for (j = 0; password[j] != '\0'; j++) { 2152 for (j = 0; password[j] != '\0'; j++) {
2153 key[j] = password[j]; 2153 key[j] = password[j];
2154 } 2154 }
2155 keylength = j; 2155 keylength = j;
2156 krc2->rc2_expandkey (key, keylength, 128); 2156 krc2->rc2_expandkey (key, keylength, 128);
2157 2157
2158#ifndef Q_WS_WIN 2158#ifndef Q_WS_WIN
2159 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2159 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2160#else 2160#else
2161 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2161 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2162#endif 2162#endif
2163 2163
2164 if (size < 8) 2164 if (size < 8)
2165 return PWERR_DATA; 2165 return PWERR_DATA;
2166 2166
2167 for (count = 0; count < 4; count++) { 2167 for (count = 0; count < 4; count++) {
2168 count2 = count << 1; 2168 count2 = count << 1;
2169 iv[count] = charbuf[count2] << 8; 2169 iv[count] = charbuf[count2] << 8;
2170 iv[count] += charbuf[count2 + 1]; 2170 iv[count] += charbuf[count2 + 1];
2171 } 2171 }
2172 2172
2173 size = 0; 2173 size = 0;
2174 bufferIndex = 0; 2174 bufferIndex = 0;
2175#ifndef Q_WS_WIN 2175#ifndef Q_WS_WIN
2176 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2176 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2177 while (count < 8) { 2177 while (count < 8) {
2178 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2178 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2179#else 2179#else
2180 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2180 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2181 while (count < 8) { 2181 while (count < 8) {
2182 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2182 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2183#endif 2183#endif
2184 if (count2 == 0) { 2184 if (count2 == 0) {
2185 return PWERR_DATA; 2185 return PWERR_DATA;
2186 } 2186 }
2187 count += count2; 2187 count += count2;
2188 } /* while (count < 8) */ 2188 } /* while (count < 8) */
2189 2189
2190 size += 8; 2190 size += 8;
2191 for (count2 = 0; count2 < 8; count2 += 2) { 2191 for (count2 = 0; count2 < 8; count2 += 2) {
2192 count3 = count2 >> 1; 2192 count3 = count2 >> 1;
2193 ciphertext[count3] = charbuf[count2] << 8; 2193 ciphertext[count3] = charbuf[count2] << 8;
2194 ciphertext[count3] += charbuf[count2 + 1]; 2194 ciphertext[count3] += charbuf[count2 + 1];
2195 2195
2196 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2196 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2197 iv[count3] = plaintext[count3]; 2197 iv[count3] = plaintext[count3];
2198 } /* for (count2) */ 2198 } /* for (count2) */
2199 2199
2200 krc2->rc2_decrypt (plaintext); 2200 krc2->rc2_decrypt (plaintext);
2201 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2201 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2202 bufferIndex += 8; 2202 bufferIndex += 8;
2203 buffer[bufferIndex + 1] = '\0'; 2203 buffer[bufferIndex + 1] = '\0';
2204 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2204 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2205 size -= buffer[size - 1]; 2205 size -= buffer[size - 1];
2206 lastcount = 0; 2206 lastcount = 0;
2207 2207
2208 /* This will point to the starting index */ 2208 /* This will point to the starting index */
2209 bufferIndex = 0; 2209 bufferIndex = 0;
2210 return PWERR_GOOD; 2210 return PWERR_GOOD;
2211} 2211}
2212 2212
2213int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2213int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2214{ 2214{
2215 /* Strip off PKCS 5 padding 2215 /* Strip off PKCS 5 padding
2216 * Should check to make sure it's good here 2216 * Should check to make sure it's good here
2217 */ 2217 */
2218 int count, count1=0; 2218 int count, count1=0;
2219 2219
2220 for (count = lastcount; count < size; count++) { 2220 for (count = lastcount; count < size; count++) {
2221 if ((unsigned char) (buffer[count]) == 255) { 2221 if ((unsigned char) (buffer[count]) == 255) {
2222 if (buffer[bufferIndex] == '\0') { 2222 if (buffer[bufferIndex] == '\0') {
2223 bufferIndex++; 2223 bufferIndex++;
2224 } 2224 }
2225 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2225 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2226 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2226 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2227 entry[count1][count - bufferIndex] = '\0'; 2227 entry[count1][count - bufferIndex] = '\0';
2228 count++; 2228 count++;
2229 bufferIndex = count; 2229 bufferIndex = count;
2230 count1++; 2230 count1++;
2231 if (count1 == FIELD_SIZE) { 2231 if (count1 == FIELD_SIZE) {
2232 lastcount = count; 2232 lastcount = count;
2233 return 1; 2233 return 1;
2234 } 2234 }
2235 } /* if ((unsigned char) (buffer[count]) == 255) */ 2235 } /* if ((unsigned char) (buffer[count]) == 255) */
2236 } /* for (count = 0; count < size; count++) */ 2236 } /* for (count = 0; count < size; count++) */
2237 2237
2238 return 2; 2238 return 2;
2239} 2239}
2240 2240
2241int ZSafe::loadFinalize(void) 2241int ZSafe::loadFinalize(void)
2242{ 2242{
2243 fclose (fd); 2243 fclose (fd);
2244 if (buffer) free(buffer); 2244 if (buffer) free(buffer);
2245 return PWERR_GOOD; 2245 return PWERR_GOOD;
2246} 2246}
2247 2247
2248bool ZSafe::saveDocument(const char* _filename, 2248bool ZSafe::saveDocument(const char* _filename,
2249 bool withPwd, 2249 bool withPwd,
2250 const char* ) 2250 const char* )
2251{ 2251{
2252 if (filename.isEmpty()) 2252 if (filename.isEmpty())
2253 { 2253 {
2254 QMessageBox::critical( 0, tr("ZSafe"), 2254 QMessageBox::critical( 0, tr("ZSafe"),
2255 tr("No document defined.\nYou have to create a new document")); 2255 tr("No document defined.\nYou have to create a new document"));
2256 return false; 2256 return false;
2257 } 2257 }
2258 2258
2259 // if (m_password.isEmpty()) 2259 // if (m_password.isEmpty())
2260 // withPwd = true; // the document must be saved with a valid password 2260 // withPwd = true; // the document must be saved with a valid password
2261 if (withPwd) 2261 if (withPwd)
2262 { 2262 {
2263 bool pwdOk = FALSE; 2263 bool pwdOk = FALSE;
2264 while (!pwdOk) 2264 while (!pwdOk)
2265 { 2265 {
2266 getDocPassword(tr("Enter Password")); 2266 getDocPassword(tr("Enter Password"));
2267 if (m_password.isEmpty()) 2267 if (m_password.isEmpty())
2268 { 2268 {
2269 2269
2270 QMessageBox::critical( 0, tr("ZSafe"), 2270 QMessageBox::critical( 0, tr("ZSafe"),
2271 tr("Password is empty.\nPlease enter again.")); 2271 tr("Password is empty.\nPlease enter again."));
2272 continue; 2272 continue;
2273 } 2273 }
2274 2274
2275 QString firstPasswd = m_password; 2275 QString firstPasswd = m_password;
2276 2276
2277 getDocPassword(tr("Reenter Password")); 2277 getDocPassword(tr("Reenter Password"));
2278 if (m_password.isEmpty()) 2278 if (m_password.isEmpty())
2279 { 2279 {
2280 QMessageBox::critical( 0, tr("ZSafe"), 2280 QMessageBox::critical( 0, tr("ZSafe"),
2281 tr("Password is empty.\nPlease enter again.")); 2281 tr("Password is empty.\nPlease enter again."));
2282 continue; 2282 continue;
2283 } 2283 }
2284 if (firstPasswd != m_password) 2284 if (firstPasswd != m_password)
2285 { 2285 {
2286 2286
2287 QMessageBox::critical( 0, tr("ZSafe"), 2287 QMessageBox::critical( 0, tr("ZSafe"),
2288 tr("Passwords must be identical.\nPlease enter again.")); 2288 tr("Passwords must be identical.\nPlease enter again."));
2289 continue; 2289 continue;
2290 } 2290 }
2291 pwdOk = TRUE; 2291 pwdOk = TRUE;
2292 modified = false; 2292 modified = false;
2293 } 2293 }
2294 } 2294 }
2295 else if (modified) 2295 else if (modified)
2296 { 2296 {
2297 QString fns(_filename); 2297 QString fns(_filename);
2298 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2298 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2299 switch( QMessageBox::information( this, tr("ZSafe"), 2299 switch( QMessageBox::information( this, tr("ZSafe"),
2300 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2300 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2301 tr("&Save"), 2301 tr("&Save"),
2302 tr("&Don't Save"), 2302 tr("&Don't Save"),
2303 0 // Enter == button 0 2303 0 // Enter == button 0
2304 ) ) 2304 ) )
2305 { // Escape == button 2 2305 { // Escape == button 2
2306 case 0: // Save clicked, Alt-S or Enter pressed. 2306 case 0: // Save clicked, Alt-S or Enter pressed.
2307 modified = false; 2307 modified = false;
2308 break; 2308 break;
2309 case 1: // Don't Save clicked or Alt-D pressed 2309 case 1: // Don't Save clicked or Alt-D pressed
2310 modified = false; 2310 modified = false;
2311 return true; 2311 return true;
2312 } 2312 }
2313 } 2313 }
2314 modified = false; 2314 modified = false;
2315 2315
2316 if (m_password.isEmpty()) 2316 if (m_password.isEmpty())
2317 return false; 2317 return false;
2318 2318
2319 int retval = saveInit(_filename, m_password); 2319 int retval = saveInit(_filename, m_password);
2320 // int retval = saveInit(_filename, "test"); 2320 // int retval = saveInit(_filename, "test");
2321 if (retval != PWERR_GOOD) { 2321 if (retval != PWERR_GOOD) {
2322 return false; 2322 return false;
2323 } 2323 }
2324 2324
2325 char* entry[FIELD_SIZE]; 2325 char* entry[FIELD_SIZE];
2326 2326
2327 // save the validation entry 2327 // save the validation entry
2328 { 2328 {
2329 int i=0; 2329 int i=0;
2330 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2330 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2331 strcpy(entry[i++], "ZSAFECATEGORY"); 2331 strcpy(entry[i++], "ZSAFECATEGORY");
2332 entry[i] = (char*)malloc(strlen("name")+1); 2332 entry[i] = (char*)malloc(strlen("name")+1);
2333 strcpy(entry[i++], "name"); 2333 strcpy(entry[i++], "name");
2334 entry[i] = (char*)malloc(strlen("username")+1); 2334 entry[i] = (char*)malloc(strlen("username")+1);
2335 strcpy(entry[i++], "username"); 2335 strcpy(entry[i++], "username");
2336 entry[i] = (char*)malloc(strlen("password")+1); 2336 entry[i] = (char*)malloc(strlen("password")+1);
2337 strcpy(entry[i++], "password"); 2337 strcpy(entry[i++], "password");
2338 entry[i] = (char*)malloc(strlen("comment")+1); 2338 entry[i] = (char*)malloc(strlen("comment")+1);
2339 strcpy(entry[i++], "comment"); 2339 strcpy(entry[i++], "comment");
2340 2340
2341 entry[i] = (char*)malloc(strlen("field5")+1); 2341 entry[i] = (char*)malloc(strlen("field5")+1);
2342 strcpy(entry[i++], "field5"); 2342 strcpy(entry[i++], "field5");
2343 entry[i] = (char*)malloc(strlen("field6")+1); 2343 entry[i] = (char*)malloc(strlen("field6")+1);