summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-07-27 00:53:35 (UTC)
committer llornkcor <llornkcor>2004-07-27 00:53:35 (UTC)
commit2f332574ddbd31fe9709c1ec93049ecef9bd00a4 (patch) (unidiff)
treeb4d2fb110e398d6fa2491bd754a1d3f2e651fe97
parent8ff9840e3cbb28a1a644eb165465c60903e651a1 (diff)
downloadopie-2f332574ddbd31fe9709c1ec93049ecef9bd00a4.zip
opie-2f332574ddbd31fe9709c1ec93049ecef9bd00a4.tar.gz
opie-2f332574ddbd31fe9709c1ec93049ecef9bd00a4.tar.bz2
workaround weird windows listview bug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/zsafe/zsafe.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 2dd94aa..6aa6392 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1,3875 +1,3879 @@
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 ("zsafePrefs"); 377 conf->setGroup ("zsafePrefs");
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 filename = conf->readEntry(APP_KEY+"document"); 495 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#ifdef Q_WS_WIN
715 ListView->setSelected( ListView->firstChild() , true);
716 ListView->setSelected( ListView->firstChild() , false);
717#endif
714} 718}
715 719
716const QColor *ZSafe::evenRowColor = &Qt::white; 720const QColor *ZSafe::evenRowColor = &Qt::white;
717// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 721// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
718const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 722const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
719 723
720/* 724/*
721 * Destroys the object and frees any allocated resources 725 * Destroys the object and frees any allocated resources
722 */ 726 */
723ZSafe::~ZSafe() 727ZSafe::~ZSafe()
724{ 728{
725 // no need to delete child widgets, Qt does it all for us 729 // no need to delete child widgets, Qt does it all for us
726 quitMe(); 730 quitMe();
727} 731}
728 732
729// load the default document 733// load the default document
730void ZSafe::slotLoadDocu() 734void ZSafe::slotLoadDocu()
731{ 735{
732 openDocument (filename); 736 openDocument (filename);
733} 737}
734 738
735void ZSafe::deletePwd() 739void ZSafe::deletePwd()
736{ 740{
737 741
738 if (!selectedItem) 742 if (!selectedItem)
739 return; 743 return;
740 if (!isCategory(selectedItem)) 744 if (!isCategory(selectedItem))
741 { 745 {
742 switch( QMessageBox::information( this, tr("ZSafe"), 746 switch( QMessageBox::information( this, tr("ZSafe"),
743 tr("Do you want to delete?"), 747 tr("Do you want to delete?"),
744 tr("&Delete"), tr("D&on't Delete"), 748 tr("&Delete"), tr("D&on't Delete"),
745 0 // Enter == button 0 749 0 // Enter == button 0
746 ) ) { // Escape == button 2 750 ) ) { // Escape == button 2
747 case 0: // Delete clicked, Alt-S or Enter pressed. 751 case 0: // Delete clicked, Alt-S or Enter pressed.
748 // Delete 752 // Delete
749 modified = true; 753 modified = true;
750 selectedItem->parent()->takeItem(selectedItem); 754 selectedItem->parent()->takeItem(selectedItem);
751 selectedItem = NULL; 755 selectedItem = NULL;
752 break; 756 break;
753 case 1: // Don't delete 757 case 1: // Don't delete
754 break; 758 break;
755 } 759 }
756 } 760 }
757 else 761 else
758 { 762 {
759 delCategory(); 763 delCategory();
760 } 764 }
761} 765}
762 766
763void ZSafe::editPwd() 767void ZSafe::editPwd()
764{ 768{
765 if (!selectedItem) 769 if (!selectedItem)
766 return; 770 return;
767 if (!isCategory(selectedItem)) 771 if (!isCategory(selectedItem))
768 { 772 {
769 // open the 'New Entry' dialog 773 // open the 'New Entry' dialog
770 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE); 774 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE);
771#ifdef Q_WS_WIN 775#ifdef Q_WS_WIN
772 dialog->setCaption ("Qt " + tr("Edit Entry")); 776 dialog->setCaption ("Qt " + tr("Edit Entry"));
773 dialog->setGeometry(200, 250, 220, 310 ); 777 dialog->setGeometry(200, 250, 220, 310 );
774#endif 778#endif
775 779
776 // set the labels 780 // set the labels
777 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 781 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
778 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 782 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
779 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 783 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
780 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 784 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
781 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 785 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
782 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 786 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
783 787
784 // set the fields 788 // set the fields
785 dialog->NameField->setText(selectedItem->text (0)); 789 dialog->NameField->setText(selectedItem->text (0));
786 dialog->UsernameField->setText(selectedItem->text (1)); 790 dialog->UsernameField->setText(selectedItem->text (1));
787 dialog->PasswordField->setText(selectedItem->text (2)); 791 dialog->PasswordField->setText(selectedItem->text (2));
788 QString comment = selectedItem->text (3); 792 QString comment = selectedItem->text (3);
789 comment.replace (QRegExp("<br>"), "\n"); 793 comment.replace (QRegExp("<br>"), "\n");
790 dialog->Field5->setText(selectedItem->text (4)); 794 dialog->Field5->setText(selectedItem->text (4));
791 dialog->Field6->setText(selectedItem->text (5)); 795 dialog->Field6->setText(selectedItem->text (5));
792 dialog->CommentField->insertLine(comment); 796 dialog->CommentField->insertLine(comment);
793 dialog->CommentField->setCursorPosition(0,0); 797 dialog->CommentField->setCursorPosition(0,0);
794 798
795#ifdef Q_WS_QWS 799#ifdef Q_WS_QWS
796 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 800 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
797#endif 801#endif
798 802
799#ifdef DESKTOP 803#ifdef DESKTOP
800#ifndef Q_QW_QWIN 804#ifndef Q_QW_QWIN
801 dialog->show(); 805 dialog->show();
802#endif 806#endif
803#else 807#else
804 dialog->showMaximized(); 808 dialog->showMaximized();
805#endif 809#endif
806#ifdef DESKTOP 810#ifdef DESKTOP
807 int result = dialog->exec(); 811 int result = dialog->exec();
808 result = QDialog::Accepted; 812 result = QDialog::Accepted;
809#endif 813#endif
810 if (result == Accepted) 814 if (result == Accepted)
811 { 815 {
812 modified = true; 816 modified = true;
813 // edit the selected item 817 // edit the selected item
814 QString name = dialog->NameField->text(); 818 QString name = dialog->NameField->text();
815 selectedItem->setText (0, tr (name)); 819 selectedItem->setText (0, tr (name));
816 QString user = dialog->UsernameField->text(); 820 QString user = dialog->UsernameField->text();
817 selectedItem->setText (1, tr (user)); 821 selectedItem->setText (1, tr (user));
818 QString pwd = dialog->PasswordField->text(); 822 QString pwd = dialog->PasswordField->text();
819 selectedItem->setText (2, tr (pwd)); 823 selectedItem->setText (2, tr (pwd));
820 QString comment = dialog->CommentField->text(); 824 QString comment = dialog->CommentField->text();
821 comment.replace (QRegExp("\n"), "<br>"); 825 comment.replace (QRegExp("\n"), "<br>");
822 selectedItem->setText (3, tr (comment)); 826 selectedItem->setText (3, tr (comment));
823 QString f5 = dialog->Field5->text(); 827 QString f5 = dialog->Field5->text();
824 selectedItem->setText (4, tr (f5)); 828 selectedItem->setText (4, tr (f5));
825 QString f6 = dialog->Field6->text(); 829 QString f6 = dialog->Field6->text();
826 selectedItem->setText (5, tr (f6)); 830 selectedItem->setText (5, tr (f6));
827 } 831 }
828 832
829 delete dialog; 833 delete dialog;
830 } 834 }
831 else 835 else
832 { 836 {
833 editCategory(); 837 editCategory();
834 } 838 }
835} 839}
836 840
837void ZSafe::newPwd() 841void ZSafe::newPwd()
838{ 842{
839 if (!selectedItem) 843 if (!selectedItem)
840 return; 844 return;
841 qWarning("new item"); 845 qWarning("new item");
842 if (!isCategory(selectedItem)) 846 if (!isCategory(selectedItem))
843 selectedItem = selectedItem->parent(); 847 selectedItem = selectedItem->parent();
844 848
845 if (isCategory(selectedItem)) 849 if (isCategory(selectedItem))
846 { 850 {
847 QString cat = selectedItem->text(0); 851 QString cat = selectedItem->text(0);
848 qWarning(cat); 852 qWarning(cat);
849 // open the 'New Entry' dialog 853 // open the 'New Entry' dialog
850 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE); 854 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE);
851#ifdef Q_WS_WIN 855#ifdef Q_WS_WIN
852 dialog->setCaption ("Qt " + tr("New Entry")); 856 dialog->setCaption ("Qt " + tr("New Entry"));
853 dialog->setGeometry(200, 250, 220, 310 ); 857 dialog->setGeometry(200, 250, 220, 310 );
854#endif 858#endif
855 // set the labels 859 // set the labels
856 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 860 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
857 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 861 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
858 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 862 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
859 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 863 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
860 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 864 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
861 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 865 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
862retype: 866retype:
863 867
864#ifdef Q_WS_QWS 868#ifdef Q_WS_QWS
865 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 869 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
866#endif 870#endif
867 871
868#ifdef DESKTOP 872#ifdef DESKTOP
869#ifndef Q_QW_QWIN 873#ifndef Q_QW_QWIN
870 dialog->show(); 874 dialog->show();
871#endif 875#endif
872#else 876#else
873 dialog->showMaximized(); 877 dialog->showMaximized();
874#endif 878#endif
875#ifdef DESKTOP 879#ifdef DESKTOP
876 int result = dialog->exec(); 880 int result = dialog->exec();
877 result = QDialog::Accepted; 881 result = QDialog::Accepted;
878#endif 882#endif
879 883
880 if (result == Accepted) 884 if (result == Accepted)
881 { 885 {
882 886
883 QString name = dialog->NameField->text(); 887 QString name = dialog->NameField->text();
884 if (cat == name) 888 if (cat == name)
885 { 889 {
886 QMessageBox::critical( 0, tr("ZSafe"), 890 QMessageBox::critical( 0, tr("ZSafe"),
887 tr("Entry name must be different\nfrom the category name.") ); 891 tr("Entry name must be different\nfrom the category name.") );
888 goto retype; // it's not a good programming style :-) 892 goto retype; // it's not a good programming style :-)
889 } 893 }
890 894
891 modified = true; 895 modified = true;
892 // add the new item 896 // add the new item
893 QListViewItem *i = new ShadedListItem (0, selectedItem); 897 QListViewItem *i = new ShadedListItem (0, selectedItem);
894 i->setOpen (TRUE); 898 i->setOpen (TRUE);
895 899
896 i->setText (0, tr (name)); 900 i->setText (0, tr (name));
897 QString user = dialog->UsernameField->text(); 901 QString user = dialog->UsernameField->text();
898 i->setText (1, tr (user)); 902 i->setText (1, tr (user));
899 QString pwd = dialog->PasswordField->text(); 903 QString pwd = dialog->PasswordField->text();
900 i->setText (2, tr (pwd)); 904 i->setText (2, tr (pwd));
901 QString comment = dialog->CommentField->text(); 905 QString comment = dialog->CommentField->text();
902 comment.replace (QRegExp("\n"), "<br>"); 906 comment.replace (QRegExp("\n"), "<br>");
903 i->setText (3, tr (comment)); 907 i->setText (3, tr (comment));
904 QString f5 = dialog->Field5->text(); 908 QString f5 = dialog->Field5->text();
905 i->setText (4, tr (f5)); 909 i->setText (4, tr (f5));
906 QString f6 = dialog->Field6->text(); 910 QString f6 = dialog->Field6->text();
907 i->setText (5, tr (f6)); 911 i->setText (5, tr (f6));
908 } 912 }
909 913
910 delete dialog; 914 delete dialog;
911 } 915 }
912} 916}
913 917
914void ZSafe::findPwd() 918void ZSafe::findPwd()
915{ 919{
916 920
917 // open the 'Search' dialog 921 // open the 'Search' dialog
918 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 922 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
919#ifdef Q_WS_WIN 923#ifdef Q_WS_WIN
920 dialog->setCaption ("Qt " + tr("Search")); 924 dialog->setCaption ("Qt " + tr("Search"));
921#endif 925#endif
922 926
923#ifdef DESKTOP 927#ifdef DESKTOP
924#endif 928#endif
925 if (lastSearchedName) 929 if (lastSearchedName)
926 dialog->NameField->setText(lastSearchedName); 930 dialog->NameField->setText(lastSearchedName);
927 else 931 else
928 dialog->NameField->setText(""); 932 dialog->NameField->setText("");
929 if (lastSearchedUsername) 933 if (lastSearchedUsername)
930 dialog->UsernameField->setText(lastSearchedUsername); 934 dialog->UsernameField->setText(lastSearchedUsername);
931 else 935 else
932 dialog->UsernameField->setText(""); 936 dialog->UsernameField->setText("");
933 if (lastSearchedComment) 937 if (lastSearchedComment)
934 dialog->CommentField->setText(lastSearchedComment); 938 dialog->CommentField->setText(lastSearchedComment);
935 else 939 else
936 dialog->CommentField->setText(""); 940 dialog->CommentField->setText("");
937 DialogCode result = (DialogCode) dialog->exec(); 941 DialogCode result = (DialogCode) dialog->exec();
938#ifdef DESKTOP 942#ifdef DESKTOP
939 result = Accepted; 943 result = Accepted;
940#endif 944#endif
941 945
942 QString name; 946 QString name;
943 QString username; 947 QString username;
944 QString comment; 948 QString comment;
945 if (result == Accepted) 949 if (result == Accepted)
946 { 950 {
947 name = dialog->NameField->text(); 951 name = dialog->NameField->text();
948 username = dialog->UsernameField->text(); 952 username = dialog->UsernameField->text();
949 comment = dialog->CommentField->text(); 953 comment = dialog->CommentField->text();
950#ifndef NO_OPIE 954#ifndef NO_OPIE
951 owarn << name << oendl; 955 owarn << name << oendl;
952#else 956#else
953 qWarning (name); 957 qWarning (name);
954#endif 958#endif
955 } 959 }
956 else 960 else
957 { 961 {
958 delete dialog; 962 delete dialog;
959 return; 963 return;
960 } 964 }
961 965
962 if (!name.isEmpty() && name != lastSearchedName || 966 if (!name.isEmpty() && name != lastSearchedName ||
963 lastSearchedName.isEmpty() && !name.isEmpty()) 967 lastSearchedName.isEmpty() && !name.isEmpty())
964 { 968 {
965 // set search at the beginning if a new name is given 969 // set search at the beginning if a new name is given
966 lastSearchedCategory = NULL; 970 lastSearchedCategory = NULL;
967 lastSearchedItem = NULL; 971 lastSearchedItem = NULL;
968 } 972 }
969 lastSearchedName = name; 973 lastSearchedName = name;
970 if (!username.isEmpty() && username != lastSearchedUsername || 974 if (!username.isEmpty() && username != lastSearchedUsername ||
971 lastSearchedUsername.isEmpty() && !username.isEmpty()) 975 lastSearchedUsername.isEmpty() && !username.isEmpty())
972 { 976 {
973 // set search at the beginning if a new name is given 977 // set search at the beginning if a new name is given
974 lastSearchedCategory = NULL; 978 lastSearchedCategory = NULL;
975 lastSearchedItem = NULL; 979 lastSearchedItem = NULL;
976 } 980 }
977 lastSearchedUsername = username; 981 lastSearchedUsername = username;
978 if (!comment.isEmpty() && comment != lastSearchedComment || 982 if (!comment.isEmpty() && comment != lastSearchedComment ||
979 lastSearchedComment.isEmpty() && !comment.isEmpty()) 983 lastSearchedComment.isEmpty() && !comment.isEmpty())
980 { 984 {
981 // set search at the beginning if a new name is given 985 // set search at the beginning if a new name is given
982 lastSearchedCategory = NULL; 986 lastSearchedCategory = NULL;
983 lastSearchedItem = NULL; 987 lastSearchedItem = NULL;
984 } 988 }
985 lastSearchedComment = comment; 989 lastSearchedComment = comment;
986 990
987 ListView->clearSelection(); 991 ListView->clearSelection();
988 992
989 bool found=FALSE; 993 bool found=FALSE;
990 // step through all categories 994 // step through all categories
991 QListViewItem *i; 995 QListViewItem *i;
992 if (lastSearchedCategory) 996 if (lastSearchedCategory)
993 i = lastSearchedCategory; 997 i = lastSearchedCategory;
994 else 998 else
995 i = ListView->firstChild(); 999 i = ListView->firstChild();
996 for (; 1000 for (;
997 i != NULL; 1001 i != NULL;
998 i = i->nextSibling()) 1002 i = i->nextSibling())
999 { 1003 {
1000#ifndef NO_OPIE 1004#ifndef NO_OPIE
1001 owarn << i->text(0) << oendl; 1005 owarn << i->text(0) << oendl;
1002#endif 1006#endif
1003 i->setSelected(FALSE); 1007 i->setSelected(FALSE);
1004 1008
1005 // step through all subitems 1009 // step through all subitems
1006 QListViewItem *si; 1010 QListViewItem *si;
1007 if (lastSearchedItem) 1011 if (lastSearchedItem)
1008 si = lastSearchedItem; 1012 si = lastSearchedItem;
1009 else 1013 else
1010 si = i->firstChild(); 1014 si = i->firstChild();
1011 // for (si = i->firstChild(); 1015 // for (si = i->firstChild();
1012 for (; 1016 for (;
1013 si != NULL; 1017 si != NULL;
1014 si = si->nextSibling()) 1018 si = si->nextSibling())
1015 { 1019 {
1016#ifndef NO_OPIE 1020#ifndef NO_OPIE
1017 owarn << si->text(0) << oendl; 1021 owarn << si->text(0) << oendl;
1018#else 1022#else
1019 qWarning (si->text(0)); 1023 qWarning (si->text(0));
1020#endif 1024#endif
1021 if (si->isSelected()) 1025 if (si->isSelected())
1022 si->setSelected(FALSE); 1026 si->setSelected(FALSE);
1023 // ListView->repaintItem(si); 1027 // ListView->repaintItem(si);
1024 1028
1025 bool n=TRUE; 1029 bool n=TRUE;
1026 bool u=TRUE; 1030 bool u=TRUE;
1027 bool c=TRUE; 1031 bool c=TRUE;
1028 if (!name.isEmpty()) 1032 if (!name.isEmpty())
1029 n = (si->text(0)).contains (name, FALSE); 1033 n = (si->text(0)).contains (name, FALSE);
1030 if (!username.isEmpty()) 1034 if (!username.isEmpty())
1031 u = (si->text(1)).contains (username, FALSE); 1035 u = (si->text(1)).contains (username, FALSE);
1032 if (!comment.isEmpty()) 1036 if (!comment.isEmpty())
1033 c = (si->text(3)).contains (comment, FALSE); 1037 c = (si->text(3)).contains (comment, FALSE);
1034 1038
1035 if ((n && u && c ) && !found) 1039 if ((n && u && c ) && !found)
1036 { 1040 {
1037#ifndef NO_OPIE 1041#ifndef NO_OPIE
1038 owarn << "Found" << oendl; 1042 owarn << "Found" << oendl;
1039#else 1043#else
1040 qWarning ("Found"); 1044 qWarning ("Found");
1041#endif 1045#endif
1042 selectedItem = si; 1046 selectedItem = si;
1043 si->setSelected(TRUE); 1047 si->setSelected(TRUE);
1044 ListView->setCurrentItem(si); 1048 ListView->setCurrentItem(si);
1045 ListView->ensureItemVisible(si); 1049 ListView->ensureItemVisible(si);
1046 ListView->triggerUpdate(); 1050 ListView->triggerUpdate();
1047 1051
1048 lastSearchedCategory = i; 1052 lastSearchedCategory = i;
1049 // set to the next item 1053 // set to the next item
1050 lastSearchedItem = si->nextSibling(); 1054 lastSearchedItem = si->nextSibling();
1051 if (!lastSearchedItem) 1055 if (!lastSearchedItem)
1052 { 1056 {
1053 // no next item within category -> set next category 1057 // no next item within category -> set next category
1054 lastSearchedCategory = i->nextSibling(); 1058 lastSearchedCategory = i->nextSibling();
1055 if (!lastSearchedCategory) 1059 if (!lastSearchedCategory)
1056 lastSearchedItem = NULL; // END 1060 lastSearchedItem = NULL; // END
1057 } 1061 }
1058 1062
1059 found = TRUE; 1063 found = TRUE;
1060 delete dialog; 1064 delete dialog;
1061 update(); 1065 update();
1062 return; 1066 return;
1063 } 1067 }
1064 } 1068 }
1065 lastSearchedCategory = i->nextSibling(); 1069 lastSearchedCategory = i->nextSibling();
1066 lastSearchedItem = NULL; 1070 lastSearchedItem = NULL;
1067 } 1071 }
1068 lastSearchedCategory = NULL; 1072 lastSearchedCategory = NULL;
1069 lastSearchedItem = NULL; 1073 lastSearchedItem = NULL;
1070 delete dialog; 1074 delete dialog;
1071 update(); 1075 update();
1072 QMessageBox::information( this, tr("ZSafe"), 1076 QMessageBox::information( this, tr("ZSafe"),
1073 tr("Entry not found"), tr("&OK"), 0); 1077 tr("Entry not found"), tr("&OK"), 0);
1074 1078
1075} 1079}
1076 1080
1077QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1081QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1078{ 1082{
1079 QString category; 1083 QString category;
1080 if (_item) 1084 if (_item)
1081 { 1085 {
1082 if (isCategory(_item)) 1086 if (isCategory(_item))
1083 { 1087 {
1084 category = _item->text(0); 1088 category = _item->text(0);
1085 } 1089 }
1086 else 1090 else
1087 { 1091 {
1088 QListViewItem *cat = _item->parent(); 1092 QListViewItem *cat = _item->parent();
1089 category = cat->text(0); 1093 category = cat->text(0);
1090 } 1094 }
1091 } 1095 }
1092 else 1096 else
1093 { 1097 {
1094 return def; 1098 return def;
1095 } 1099 }
1096 1100
1097 QString app_key = APP_KEY; 1101 QString app_key = APP_KEY;
1098#ifndef DESKTOP 1102#ifndef DESKTOP
1099#ifndef Q_WS_WIN 1103#ifndef Q_WS_WIN
1100 conf->setGroup ("fieldDefs"); 1104 conf->setGroup ("fieldDefs");
1101#endif 1105#endif
1102#else 1106#else
1103#ifndef Q_WS_WIN 1107#ifndef Q_WS_WIN
1104 app_key += "/fieldDefs/"; 1108 app_key += "/fieldDefs/";
1105#endif 1109#endif
1106#endif 1110#endif
1107// #ifndef Q_WS_WIN 1111// #ifndef Q_WS_WIN
1108 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1112 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1109// #else 1113// #else
1110// QString label(def); 1114// QString label(def);
1111// #endif 1115// #endif
1112 1116
1113#ifndef DESKTOP 1117#ifndef DESKTOP
1114 conf->setGroup ("zsafe"); 1118 conf->setGroup ("zsafe");
1115#endif 1119#endif
1116 return label; 1120 return label;
1117} 1121}
1118 1122
1119QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1123QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1120{ 1124{
1121 QString app_key = APP_KEY; 1125 QString app_key = APP_KEY;
1122#ifndef DESKTOP 1126#ifndef DESKTOP
1123 conf->setGroup ("fieldDefs"); 1127 conf->setGroup ("fieldDefs");
1124#else 1128#else
1125#ifndef Q_WS_WIN 1129#ifndef Q_WS_WIN
1126 app_key += "/fieldDefs/"; 1130 app_key += "/fieldDefs/";
1127#endif 1131#endif
1128#endif 1132#endif
1129// #ifndef Q_WS_WIN 1133// #ifndef Q_WS_WIN
1130 QString label = conf->readEntry(app_key+category+"-field"+field, 1134 QString label = conf->readEntry(app_key+category+"-field"+field,
1131 def); 1135 def);
1132// #else 1136// #else
1133 // QString label(def); 1137 // QString label(def);
1134// #endif 1138// #endif
1135#ifndef DESKTOP 1139#ifndef DESKTOP
1136 conf->setGroup ("zsafe"); 1140 conf->setGroup ("zsafe");
1137#endif 1141#endif
1138 return label; 1142 return label;
1139} 1143}
1140 1144
1141void ZSafe::showInfo( QListViewItem *_item) 1145void ZSafe::showInfo( QListViewItem *_item)
1142{ 1146{
1143 if (!_item) 1147 if (!_item)
1144 return; 1148 return;
1145 if (selectedItem != NULL) 1149 if (selectedItem != NULL)
1146 selectedItem->setSelected(FALSE); 1150 selectedItem->setSelected(FALSE);
1147 1151
1148 selectedItem = _item; 1152 selectedItem = _item;
1149 selectedItem->setSelected(TRUE); 1153 selectedItem->setSelected(TRUE);
1150 1154
1151 if (!isCategory(_item)) 1155 if (!isCategory(_item))
1152 { 1156 {
1153/* 1157/*
1154 QString label=selectedItem->text(0); 1158 QString label=selectedItem->text(0);
1155 label+="\n"; 1159 label+="\n";
1156 label+=selectedItem->text(1); 1160 label+=selectedItem->text(1);
1157 label+="\n"; 1161 label+="\n";
1158 label+=selectedItem->text(2); 1162 label+=selectedItem->text(2);
1159 label+="\n"; 1163 label+="\n";
1160 label+=selectedItem->text(3); 1164 label+=selectedItem->text(3);
1161*/ 1165*/
1162 1166
1163 QString text; 1167 QString text;
1164 QString entry; 1168 QString entry;
1165 1169
1166 text = "<html><body><div align=""center""><u><b>"; 1170 text = "<html><body><div align=""center""><u><b>";
1167 text += selectedItem->text(0); 1171 text += selectedItem->text(0);
1168 text += "</b></u><br></div><br>"; 1172 text += "</b></u><br></div><br>";
1169 1173
1170 entry = selectedItem->text(1); 1174 entry = selectedItem->text(1);
1171 if (!entry.isEmpty() && entry.compare(" ")) 1175 if (!entry.isEmpty() && entry.compare(" "))
1172 { 1176 {
1173 text += "<u><b>"; 1177 text += "<u><b>";
1174 text += getFieldLabel (selectedItem, "2", tr("Username")); 1178 text += getFieldLabel (selectedItem, "2", tr("Username"));
1175 text += ":<br></b></u><blockquote>"; 1179 text += ":<br></b></u><blockquote>";
1176 text += entry; 1180 text += entry;
1177 text += "</blockquote>"; 1181 text += "</blockquote>";
1178 // text += "<br>"; 1182 // text += "<br>";
1179 } 1183 }
1180 1184
1181 entry = selectedItem->text(2); 1185 entry = selectedItem->text(2);
1182 if (!entry.isEmpty() && entry.compare(" ")) 1186 if (!entry.isEmpty() && entry.compare(" "))
1183 { 1187 {
1184 text += "<u><b>"; 1188 text += "<u><b>";
1185 text += getFieldLabel (selectedItem, "3", tr("Password")); 1189 text += getFieldLabel (selectedItem, "3", tr("Password"));
1186 text += ":<br> </b></u><blockquote>"; 1190 text += ":<br> </b></u><blockquote>";
1187 text += entry; 1191 text += entry;
1188 text += "</blockquote>"; 1192 text += "</blockquote>";
1189 // text += "<br>"; 1193 // text += "<br>";
1190 } 1194 }
1191 1195
1192 entry = selectedItem->text(4); 1196 entry = selectedItem->text(4);
1193 if (!entry.isEmpty() && entry.compare(" ")) 1197 if (!entry.isEmpty() && entry.compare(" "))
1194 { 1198 {
1195 text += "<u><b>"; 1199 text += "<u><b>";
1196 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1200 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1197 text += ":<br> </b></u><blockquote>"; 1201 text += ":<br> </b></u><blockquote>";
1198 text += entry; 1202 text += entry;
1199 text += "</blockquote>"; 1203 text += "</blockquote>";
1200 // text += "<br>"; 1204 // text += "<br>";
1201 } 1205 }
1202 1206
1203 entry = selectedItem->text(5); 1207 entry = selectedItem->text(5);
1204 if (!entry.isEmpty() && entry.compare(" ")) 1208 if (!entry.isEmpty() && entry.compare(" "))
1205 { 1209 {
1206 text += "<u><b>"; 1210 text += "<u><b>";
1207 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1211 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1208 text += ":<br> </b></u><blockquote>"; 1212 text += ":<br> </b></u><blockquote>";
1209 text += entry; 1213 text += entry;
1210 text += "</blockquote>"; 1214 text += "</blockquote>";
1211 // text += "<br>"; 1215 // text += "<br>";
1212 } 1216 }
1213 1217
1214 entry = selectedItem->text(3); 1218 entry = selectedItem->text(3);
1215 if (!entry.isEmpty() && entry.compare(" ")) 1219 if (!entry.isEmpty() && entry.compare(" "))
1216 { 1220 {
1217 text += "<u><b>"; 1221 text += "<u><b>";
1218 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1222 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1219 text += ":<br> </b></u>"; 1223 text += ":<br> </b></u>";
1220 QString comment = selectedItem->text(3); 1224 QString comment = selectedItem->text(3);
1221 comment.replace (QRegExp("\n"), "<br>"); 1225 comment.replace (QRegExp("\n"), "<br>");
1222 text += comment; 1226 text += comment;
1223 // text += "<br>"; 1227 // text += "<br>";
1224 } 1228 }
1225 1229
1226 text += "</body></html>"; 1230 text += "</body></html>";
1227 1231
1228 infoForm->InfoText->setText(text); 1232 infoForm->InfoText->setText(text);
1229// infoForm->hide(); 1233// infoForm->hide();
1230#ifdef Q_WS_QWS 1234#ifdef Q_WS_QWS
1231 QPEApplication::showDialog( infoForm ); 1235 QPEApplication::showDialog( infoForm );
1232#endif 1236#endif
1233 1237
1234#ifdef DESKTOP 1238#ifdef DESKTOP
1235 infoForm->show(); 1239 infoForm->show();
1236 #endif 1240 #endif
1237 } 1241 }
1238} 1242}
1239 1243
1240void ZSafe::listViewSelected( QListViewItem *_item) 1244void ZSafe::listViewSelected( QListViewItem *_item)
1241{ 1245{
1242 if (!_item) 1246 if (!_item)
1243 return; 1247 return;
1244 if (selectedItem != NULL) 1248 if (selectedItem != NULL)
1245 selectedItem->setSelected(FALSE); 1249 selectedItem->setSelected(FALSE);
1246 1250
1247 selectedItem = _item; 1251 selectedItem = _item;
1248 1252
1249#ifndef DESKTOP 1253#ifndef DESKTOP
1250 // set the column text dependent on the selected item 1254 // set the column text dependent on the selected item
1251 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1255 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1252 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1256 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1253 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1257 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1254 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1258 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1255 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1259 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1256 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1260 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1257#endif 1261#endif
1258#ifdef Q_WS_WIN 1262#ifdef Q_WS_WIN
1259 // set the column text dependent on the selected item 1263 // set the column text dependent on the selected item
1260 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1264 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1261 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1265 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1262 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1266 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1263 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1267 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1264 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1268 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1265 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1269 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1266#endif 1270#endif
1267 1271
1268} 1272}
1269 1273
1270bool ZSafe::isCategory(QListViewItem *_item) 1274bool ZSafe::isCategory(QListViewItem *_item)
1271{ 1275{
1272 if (_item == NULL) 1276 if (_item == NULL)
1273 return FALSE; 1277 return FALSE;
1274 1278
1275 QString categoryName = _item->text (0); 1279 QString categoryName = _item->text (0);
1276 if (categories.find (categoryName)) 1280 if (categories.find (categoryName))
1277 return TRUE; 1281 return TRUE;
1278 else 1282 else
1279 return FALSE; 1283 return FALSE;
1280} 1284}
1281 1285
1282void ZSafe::removeAsciiFile() 1286void ZSafe::removeAsciiFile()
1283{ 1287{
1284 // QString fn = filename + ".txt"; 1288 // QString fn = filename + ".txt";
1285 // open the file dialog 1289 // open the file dialog
1286#ifndef DESKTOP 1290#ifndef DESKTOP
1287#ifndef NO_OPIE 1291#ifndef NO_OPIE
1288 QMap<QString, QStringList> mimeTypes; 1292 QMap<QString, QStringList> mimeTypes;
1289 mimeTypes.insert(tr("All"), QStringList() ); 1293 mimeTypes.insert(tr("All"), QStringList() );
1290 mimeTypes.insert(tr("Text"), "text/*" ); 1294 mimeTypes.insert(tr("Text"), "text/*" );
1291 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1295 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1292 QDir::homeDirPath() + "/Documents/application/zsafe", 1296 QDir::homeDirPath() + "/Documents/application/zsafe",
1293 QString::null, 1297 QString::null,
1294 mimeTypes, 1298 mimeTypes,
1295 this, 1299 this,
1296 tr ("Remove text file")); 1300 tr ("Remove text file"));
1297#else 1301#else
1298 QString fn = ScQtFileEdit::getOpenFileName(this, 1302 QString fn = ScQtFileEdit::getOpenFileName(this,
1299 tr ("Remove text file"), 1303 tr ("Remove text file"),
1300 QDir::homeDirPath() + "/Documents/application/zsafe", 1304 QDir::homeDirPath() + "/Documents/application/zsafe",
1301 "*.txt"); 1305 "*.txt");
1302#endif 1306#endif
1303#else 1307#else
1304 QString fn = QFileDialog::getOpenFileName( 1308 QString fn = QFileDialog::getOpenFileName(
1305 QDir::homeDirPath() + "/Documents/application/zsafe", 1309 QDir::homeDirPath() + "/Documents/application/zsafe",
1306 "ZSafe (*.txt)", 1310 "ZSafe (*.txt)",
1307 this, 1311 this,
1308 "ZSafe File Dialog" 1312 "ZSafe File Dialog"
1309 "Choose a text file" ); 1313 "Choose a text file" );
1310#endif 1314#endif
1311 1315
1312 if (fn && fn.length() > 0 ) 1316 if (fn && fn.length() > 0 )
1313 { 1317 {
1314 QFile f( fn ); 1318 QFile f( fn );
1315 if ( !f.remove() ) 1319 if ( !f.remove() )
1316 { 1320 {
1317#ifndef NO_OPIE 1321#ifndef NO_OPIE
1318 owarn << "Could not remove file " << fn << oendl; 1322 owarn << "Could not remove file " << fn << oendl;
1319#else 1323#else
1320 qWarning( QString("Could not remove file %1").arg(fn),2000 ); 1324 qWarning( QString("Could not remove file %1").arg(fn),2000 );
1321#endif 1325#endif
1322 QMessageBox::critical( 0, tr("ZSafe"), 1326 QMessageBox::critical( 0, tr("ZSafe"),
1323 tr("Could not remove text file.") ); 1327 tr("Could not remove text file.") );
1324 return; 1328 return;
1325 } 1329 }
1326 } 1330 }
1327} 1331}
1328 1332
1329void ZSafe::writeAllEntries() 1333void ZSafe::writeAllEntries()
1330{ 1334{
1331 if (filename.isEmpty()) 1335 if (filename.isEmpty())
1332 { 1336 {
1333 QMessageBox::critical( 0, tr("ZSafe"), 1337 QMessageBox::critical( 0, tr("ZSafe"),
1334 tr("No document defined.\nYou have to create a new document")); 1338 tr("No document defined.\nYou have to create a new document"));
1335 return; 1339 return;
1336 } 1340 }
1337 1341
1338 // open the file dialog 1342 // open the file dialog
1339 QString fn = zsaveDialog(); 1343 QString fn = zsaveDialog();
1340 // open the new document 1344 // open the new document
1341 if (fn && fn.length() > 0 ) 1345 if (fn && fn.length() > 0 )
1342 { 1346 {
1343 QFile f( fn ); 1347 QFile f( fn );
1344 if ( !f.open( IO_WriteOnly ) ) { 1348 if ( !f.open( IO_WriteOnly ) ) {
1345#ifndef NO_OPIE 1349#ifndef NO_OPIE
1346 owarn << "Could not write to file " << fn << oendl; 1350 owarn << "Could not write to file " << fn << oendl;
1347#else 1351#else
1348 qWarning( QString("Could not write to file %1").arg(fn),2000 ); 1352 qWarning( QString("Could not write to file %1").arg(fn),2000 );
1349#endif 1353#endif
1350 QMessageBox::critical( 0, "ZSafe", 1354 QMessageBox::critical( 0, "ZSafe",
1351 QString("Could not export to text file.") ); 1355 QString("Could not export to text file.") );
1352 return; 1356 return;
1353 } 1357 }
1354 QTextStream t( &f ); 1358 QTextStream t( &f );
1355 1359
1356 QListViewItem *i; 1360 QListViewItem *i;
1357 // step through all categories 1361 // step through all categories
1358 for (i = ListView->firstChild(); 1362 for (i = ListView->firstChild();
1359 i != NULL; 1363 i != NULL;
1360 i = i->nextSibling()) 1364 i = i->nextSibling())
1361 { 1365 {
1362 // step through all subitems 1366 // step through all subitems
1363 QListViewItem *si; 1367 QListViewItem *si;
1364 for (si = i->firstChild(); 1368 for (si = i->firstChild();
1365 si != NULL; 1369 si != NULL;
1366 si = si->nextSibling()) 1370 si = si->nextSibling())
1367 { 1371 {
1368 QString oneEntry; 1372 QString oneEntry;
1369 oneEntry += "\""; 1373 oneEntry += "\"";
1370 oneEntry += i->text(0); 1374 oneEntry += i->text(0);
1371 oneEntry += "\";"; 1375 oneEntry += "\";";
1372 oneEntry += "\""; 1376 oneEntry += "\"";
1373 oneEntry += si->text(0); 1377 oneEntry += si->text(0);
1374 oneEntry += "\";"; 1378 oneEntry += "\";";
1375 oneEntry += "\""; 1379 oneEntry += "\"";
1376 oneEntry += si->text(1); 1380 oneEntry += si->text(1);
1377 oneEntry += "\";"; 1381 oneEntry += "\";";
1378 oneEntry += "\""; 1382 oneEntry += "\"";
1379 oneEntry += si->text(2); 1383 oneEntry += si->text(2);
1380 oneEntry += "\";"; 1384 oneEntry += "\";";
1381 oneEntry += "\""; 1385 oneEntry += "\"";
1382 QString comment = si->text(3); 1386 QString comment = si->text(3);
1383 comment.replace (QRegExp("\n"), "<br>"); 1387 comment.replace (QRegExp("\n"), "<br>");
1384 oneEntry += comment; 1388 oneEntry += comment;
1385 oneEntry += "\";"; 1389 oneEntry += "\";";
1386 oneEntry += "\""; 1390 oneEntry += "\"";
1387 oneEntry += si->text(4); 1391 oneEntry += si->text(4);
1388 oneEntry += "\";"; 1392 oneEntry += "\";";
1389 oneEntry += "\""; 1393 oneEntry += "\"";
1390 oneEntry += si->text(5); 1394 oneEntry += si->text(5);
1391 oneEntry += "\""; 1395 oneEntry += "\"";
1392 // owarn << oneEntry << oendl; 1396 // owarn << oneEntry << oendl;
1393 t << oneEntry << endl; 1397 t << oneEntry << endl;
1394 1398
1395 // owarn << si->text(0) << oendl; 1399 // owarn << si->text(0) << oendl;
1396 } 1400 }
1397 } 1401 }
1398 f.close(); 1402 f.close();
1399 } 1403 }
1400} 1404}
1401 1405
1402void ZSafe::readAllEntries() 1406void ZSafe::readAllEntries()
1403{ 1407{
1404 if (filename.isEmpty()) 1408 if (filename.isEmpty())
1405 { 1409 {
1406 QMessageBox::critical( 0, tr("ZSafe"), 1410 QMessageBox::critical( 0, tr("ZSafe"),
1407 tr("No document defined.\nYou have to create a new document")); 1411 tr("No document defined.\nYou have to create a new document"));
1408 return; 1412 return;
1409 } 1413 }
1410 1414
1411 // open the file dialog 1415 // open the file dialog
1412#ifndef DESKTOP 1416#ifndef DESKTOP
1413#ifndef NO_OPIE 1417#ifndef NO_OPIE
1414 QMap<QString, QStringList> mimeTypes; 1418 QMap<QString, QStringList> mimeTypes;
1415 mimeTypes.insert(tr("All"), QStringList() ); 1419 mimeTypes.insert(tr("All"), QStringList() );
1416 mimeTypes.insert(tr("Text"), "text/*" ); 1420 mimeTypes.insert(tr("Text"), "text/*" );
1417 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1421 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1418 QDir::homeDirPath() + "/Documents/application/zsafe", 1422 QDir::homeDirPath() + "/Documents/application/zsafe",
1419 QString::null, 1423 QString::null,
1420 mimeTypes, 1424 mimeTypes,
1421 this, 1425 this,
1422 tr ("Import text file")); 1426 tr ("Import text file"));
1423#else 1427#else
1424 QString fn = ScQtFileEdit::getOpenFileName(this, 1428 QString fn = ScQtFileEdit::getOpenFileName(this,
1425 tr ("Import text file"), 1429 tr ("Import text file"),
1426 QDir::homeDirPath() + "/Documents/application/zsafe", 1430 QDir::homeDirPath() + "/Documents/application/zsafe",
1427 "*.txt"); 1431 "*.txt");
1428#endif 1432#endif
1429#else 1433#else
1430 QString fn = QFileDialog::getOpenFileName( 1434 QString fn = QFileDialog::getOpenFileName(
1431 QDir::homeDirPath() + "/Documents/application/zsafe", 1435 QDir::homeDirPath() + "/Documents/application/zsafe",
1432 "ZSafe (*.txt)", 1436 "ZSafe (*.txt)",
1433 this, 1437 this,
1434 "ZSafe File Dialog" 1438 "ZSafe File Dialog"
1435 "Choose a text file" ); 1439 "Choose a text file" );
1436#endif 1440#endif
1437 1441
1438 if (fn && fn.length() > 0 ) 1442 if (fn && fn.length() > 0 )
1439 { 1443 {
1440 QFile f( fn ); 1444 QFile f( fn );
1441 if ( !f.open( IO_ReadOnly ) ) 1445 if ( !f.open( IO_ReadOnly ) )
1442 { 1446 {
1443#ifndef NO_OPIE 1447#ifndef NO_OPIE
1444 owarn << "Could not read file " << fn << oendl; 1448 owarn << "Could not read file " << fn << oendl;
1445#else 1449#else
1446 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1450 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1447#endif 1451#endif
1448 QMessageBox::critical( 0, "ZSafe", 1452 QMessageBox::critical( 0, "ZSafe",
1449 QString("Could not import text file.") ); 1453 QString("Could not import text file.") );
1450 return; 1454 return;
1451 } 1455 }
1452 1456
1453 modified = true; 1457 modified = true;
1454 1458
1455 // clear the password list 1459 // clear the password list
1456 selectedItem = NULL; 1460 selectedItem = NULL;
1457 QListViewItem *i; 1461 QListViewItem *i;
1458 // step through all categories 1462 // step through all categories
1459 for (i = ListView->firstChild(); 1463 for (i = ListView->firstChild();
1460 i != NULL; 1464 i != NULL;
1461 i = i->nextSibling()) 1465 i = i->nextSibling())
1462 { 1466 {
1463 // step through all subitems 1467 // step through all subitems
1464 QListViewItem *si; 1468 QListViewItem *si;
1465 for (si = i->firstChild(); 1469 for (si = i->firstChild();
1466 si != NULL; ) 1470 si != NULL; )
1467 // si = si->nextSibling()) 1471 // si = si->nextSibling())
1468 { 1472 {
1469 QListViewItem *_si = si; 1473 QListViewItem *_si = si;
1470 si = si->nextSibling(); 1474 si = si->nextSibling();
1471 i->takeItem(_si); // remove from view list 1475 i->takeItem(_si); // remove from view list
1472 if (_si) delete _si; 1476 if (_si) delete _si;
1473 } 1477 }
1474 } 1478 }
1475 1479
1476#ifndef NO_OPIE 1480#ifndef NO_OPIE
1477 owarn << "ReadAllEntries(): " << oendl; 1481 owarn << "ReadAllEntries(): " << oendl;
1478#else 1482#else
1479 qWarning ("ReadAllEntries(): "); 1483 qWarning ("ReadAllEntries(): ");
1480#endif 1484#endif
1481 1485
1482 QTextStream t(&f); 1486 QTextStream t(&f);
1483 while ( !t.eof() ) 1487 while ( !t.eof() )
1484 { 1488 {
1485 QString s = t.readLine(); 1489 QString s = t.readLine();
1486 s.replace (QRegExp("\";\""), "\"|\""); 1490 s.replace (QRegExp("\";\""), "\"|\"");
1487 // char buffer[1024]; 1491 // char buffer[1024];
1488#ifndef Q_WS_WIN 1492#ifndef Q_WS_WIN
1489 char buffer[s.length()+1]; 1493 char buffer[s.length()+1];
1490#else 1494#else
1491 char buffer[4048]; 1495 char buffer[4048];
1492#endif 1496#endif
1493 1497
1494 1498
1495 /* modify QString -> QCString::utf8 */ 1499 /* modify QString -> QCString::utf8 */
1496 1500
1497 strcpy (buffer, s.utf8()); 1501 strcpy (buffer, s.utf8());
1498 1502
1499 QString name; 1503 QString name;
1500 QString user; 1504 QString user;
1501 QString password; 1505 QString password;
1502 QString comment; 1506 QString comment;
1503 QString field5=""; 1507 QString field5="";
1504 QString field6=""; 1508 QString field6="";
1505 1509
1506 // separete the entries 1510 // separete the entries
1507 char *i = strtok (buffer, "|"); 1511 char *i = strtok (buffer, "|");
1508 QString category(QString::fromUtf8(&i[1])); 1512 QString category(QString::fromUtf8(&i[1]));
1509 category.truncate(category.length() -1); 1513 category.truncate(category.length() -1);
1510 1514
1511 int idx=0; 1515 int idx=0;
1512 while ((i = strtok (NULL, "|")) != NULL) 1516 while ((i = strtok (NULL, "|")) != NULL)
1513 { 1517 {
1514 switch (idx) 1518 switch (idx)
1515 { 1519 {
1516 case 0: 1520 case 0:
1517 name = QString::fromUtf8(&i[1]); 1521 name = QString::fromUtf8(&i[1]);
1518 name.truncate(name.length() -1); 1522 name.truncate(name.length() -1);
1519 // name 1523 // name
1520 break; 1524 break;
1521 case 1: 1525 case 1:
1522 // user 1526 // user
1523 user = QString::fromUtf8(&i[1]); 1527 user = QString::fromUtf8(&i[1]);
1524 user.truncate(user.length() -1); 1528 user.truncate(user.length() -1);
1525 break; 1529 break;
1526 case 2: 1530 case 2:
1527 // password 1531 // password
1528 password = QString::fromUtf8(&i[1]); 1532 password = QString::fromUtf8(&i[1]);
1529 password.truncate(password.length() -1); 1533 password.truncate(password.length() -1);
1530 break; 1534 break;
1531 case 3: 1535 case 3:
1532 // comment 1536 // comment
1533 comment = QString::fromUtf8(&i[1]); 1537 comment = QString::fromUtf8(&i[1]);
1534 comment.truncate(comment.length() -1); 1538 comment.truncate(comment.length() -1);
1535 break; 1539 break;
1536 case 4: 1540 case 4:
1537 // field5 1541 // field5
1538 field5 = QString::fromUtf8(&i[1]); 1542 field5 = QString::fromUtf8(&i[1]);
1539 field5.truncate(field5.length() -1); 1543 field5.truncate(field5.length() -1);
1540 break; 1544 break;
1541 case 5: 1545 case 5:
1542 // field6 1546 // field6
1543 field6 = QString::fromUtf8(&i[1]); 1547 field6 = QString::fromUtf8(&i[1]);
1544 field6.truncate(field6.length() -1); 1548 field6.truncate(field6.length() -1);
1545 break; 1549 break;
1546 } 1550 }
1547 idx++; 1551 idx++;
1548 } 1552 }
1549 1553
1550 Category *cat= categories.find (category); 1554 Category *cat= categories.find (category);
1551 if (cat) 1555 if (cat)
1552 { 1556 {
1553 // use the existend item 1557 // use the existend item
1554 QListViewItem *catItem = cat->getListItem(); 1558 QListViewItem *catItem = cat->getListItem();
1555 if (catItem) 1559 if (catItem)
1556 { 1560 {
1557 QListViewItem * item = new ShadedListItem( 0, catItem ); 1561 QListViewItem * item = new ShadedListItem( 0, catItem );
1558 item->setText( 0, tr( name ) ); 1562 item->setText( 0, tr( name ) );
1559 item->setText( 1, tr( user ) ); 1563 item->setText( 1, tr( user ) );
1560 item->setText( 2, tr( password ) ); 1564 item->setText( 2, tr( password ) );
1561 item->setText( 3, tr( comment ) ); 1565 item->setText( 3, tr( comment ) );
1562 item->setText( 4, tr( field5 ) ); 1566 item->setText( 4, tr( field5 ) );
1563 item->setText( 5, tr( field6 ) ); 1567 item->setText( 5, tr( field6 ) );
1564 catItem->setOpen( TRUE ); 1568 catItem->setOpen( TRUE );
1565 } 1569 }
1566 } 1570 }
1567 else 1571 else
1568 { 1572 {
1569 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1573 QListViewItem *catI = new ShadedListItem( 1, ListView );
1570 // create and insert a new item 1574 // create and insert a new item
1571 QListViewItem * item = new ShadedListItem( 0, catI ); 1575 QListViewItem * item = new ShadedListItem( 0, catI );
1572 item->setText( 0, tr( name ) ); 1576 item->setText( 0, tr( name ) );
1573 item->setText( 1, tr( user ) ); 1577 item->setText( 1, tr( user ) );
1574 item->setText( 2, tr( password ) ); 1578 item->setText( 2, tr( password ) );
1575 item->setText( 3, tr( comment ) ); 1579 item->setText( 3, tr( comment ) );
1576 item->setText( 4, tr( field5 ) ); 1580 item->setText( 4, tr( field5 ) );
1577 item->setText( 5, tr( field6 ) ); 1581 item->setText( 5, tr( field6 ) );
1578 1582
1579 catI->setOpen( TRUE ); 1583 catI->setOpen( TRUE );
1580 1584
1581 Category *c1 = new Category(); 1585 Category *c1 = new Category();
1582 c1->setCategoryName(category); 1586 c1->setCategoryName(category);
1583 1587
1584 QString icon; 1588 QString icon;
1585 QString fullIconPath; 1589 QString fullIconPath;
1586 QPixmap *pix; 1590 QPixmap *pix;
1587// #ifndef Q_WS_WIN 1591// #ifndef Q_WS_WIN
1588 icon = conf->readEntry(APP_KEY+category); 1592 icon = conf->readEntry(APP_KEY+category);
1589// #endif 1593// #endif
1590 bool isIconAv = false; 1594 bool isIconAv = false;
1591 if (!icon.isEmpty() && !icon.isNull()) 1595 if (!icon.isEmpty() && !icon.isNull())
1592 { 1596 {
1593 // build the full path 1597 // build the full path
1594 fullIconPath = iconPath + icon; 1598 fullIconPath = iconPath + icon;
1595 pix = new QPixmap (fullIconPath); 1599 pix = new QPixmap (fullIconPath);
1596 if (!pix->isNull()) 1600 if (!pix->isNull())
1597 { 1601 {
1598 QImage img = pix->convertToImage(); 1602 QImage img = pix->convertToImage();
1599 pix->convertFromImage(img.smoothScale(14,14)); 1603 pix->convertFromImage(img.smoothScale(14,14));
1600 c1->setIconName (icon); 1604 c1->setIconName (icon);
1601 c1->setIcon (*pix); 1605 c1->setIcon (*pix);
1602 isIconAv = true; 1606 isIconAv = true;
1603 } 1607 }
1604 } 1608 }
1605 if (!isIconAv) 1609 if (!isIconAv)
1606 { 1610 {
1607 c1->setIcon (*getPredefinedIcon(category)); 1611 c1->setIcon (*getPredefinedIcon(category));
1608 } 1612 }
1609 c1->setListItem (catI); 1613 c1->setListItem (catI);
1610 c1->initListItem(); 1614 c1->initListItem();
1611 categories.insert (c1->getCategoryName(), c1); 1615 categories.insert (c1->getCategoryName(), c1);
1612 } 1616 }
1613 1617
1614 } 1618 }
1615 f.close(); 1619 f.close();
1616 1620
1617 } 1621 }
1618 else 1622 else
1619 { 1623 {
1620 } 1624 }
1621 1625
1622} 1626}
1623 1627
1624#ifdef UNUSED 1628#ifdef UNUSED
1625void ZSafe::writeAllEntries() 1629void ZSafe::writeAllEntries()
1626{ 1630{
1627 if (filename.isEmpty()) 1631 if (filename.isEmpty())
1628 { 1632 {
1629 QMessageBox::critical( 0, tr("ZSafe"), 1633 QMessageBox::critical( 0, tr("ZSafe"),
1630 tr("<P>No document defined. You have to create a new document</P>")); 1634 tr("<P>No document defined. You have to create a new document</P>"));
1631 return; 1635 return;
1632 } 1636 }
1633 1637
1634 // open the file for writing 1638 // open the file for writing
1635 QString fn = filename + ".txt"; 1639 QString fn = filename + ".txt";
1636 QFile f( fn ); 1640 QFile f( fn );
1637 if ( !f.open( IO_WriteOnly ) ) { 1641 if ( !f.open( IO_WriteOnly ) ) {
1638#ifndef NO_OPIE 1642#ifndef NO_OPIE
1639 owarn << "Could not write to file " << fn << oendl; 1643 owarn << "Could not write to file " << fn << oendl;
1640#else 1644#else
1641 qWarning( QString("Could not write to file %1").arg(fn), 2000 ); 1645 qWarning( QString("Could not write to file %1").arg(fn), 2000 );
1642#endif 1646#endif
1643 QMessageBox::critical( 0, tr("ZSafe"), 1647 QMessageBox::critical( 0, tr("ZSafe"),
1644 tr("Could not export to text file.") ); 1648 tr("Could not export to text file.") );
1645 return; 1649 return;
1646 } 1650 }
1647 QTextStream t( &f ); 1651 QTextStream t( &f );
1648 1652
1649 QListViewItem *i; 1653 QListViewItem *i;
1650 // step through all categories 1654 // step through all categories
1651 for (i = ListView->firstChild(); 1655 for (i = ListView->firstChild();
1652 i != NULL; 1656 i != NULL;
1653 i = i->nextSibling()) 1657 i = i->nextSibling())
1654 { 1658 {
1655 // step through all subitems 1659 // step through all subitems
1656 QListViewItem *si; 1660 QListViewItem *si;
1657 for (si = i->firstChild(); 1661 for (si = i->firstChild();
1658 si != NULL; 1662 si != NULL;
1659 si = si->nextSibling()) 1663 si = si->nextSibling())
1660 { 1664 {
1661 QString oneEntry; 1665 QString oneEntry;
1662 oneEntry += "\""; 1666 oneEntry += "\"";
1663 oneEntry += i->text(0); 1667 oneEntry += i->text(0);
1664 oneEntry += "\";"; 1668 oneEntry += "\";";
1665 oneEntry += "\""; 1669 oneEntry += "\"";
1666 oneEntry += si->text(0); 1670 oneEntry += si->text(0);
1667 oneEntry += "\";"; 1671 oneEntry += "\";";
1668 oneEntry += "\""; 1672 oneEntry += "\"";
1669 oneEntry += si->text(1); 1673 oneEntry += si->text(1);
1670 oneEntry += "\";"; 1674 oneEntry += "\";";
1671 oneEntry += "\""; 1675 oneEntry += "\"";
1672 oneEntry += si->text(2); 1676 oneEntry += si->text(2);
1673 oneEntry += "\";"; 1677 oneEntry += "\";";
1674 oneEntry += "\""; 1678 oneEntry += "\"";
1675 // oneEntry += si->text(3); 1679 // oneEntry += si->text(3);
1676 QString comment = si->text(3); 1680 QString comment = si->text(3);
1677 comment.replace (QRegExp("\n"), "<br>"); 1681 comment.replace (QRegExp("\n"), "<br>");
1678 oneEntry += comment; 1682 oneEntry += comment;
1679 oneEntry += "\""; 1683 oneEntry += "\"";
1680 // owarn << oneEntry << oendl; 1684 // owarn << oneEntry << oendl;
1681 t << oneEntry << endl; 1685 t << oneEntry << endl;
1682 1686
1683 // owarn << si->text(0) << oendl; 1687 // owarn << si->text(0) << oendl;
1684 } 1688 }
1685 } 1689 }
1686 f.close(); 1690 f.close();
1687} 1691}
1688 1692
1689void ZSafe::readAllEntries() 1693void ZSafe::readAllEntries()
1690{ 1694{
1691 QString fn = filename + ".txt"; 1695 QString fn = filename + ".txt";
1692 QFile f( fn ); 1696 QFile f( fn );
1693 if ( !f.open( IO_ReadOnly ) ) 1697 if ( !f.open( IO_ReadOnly ) )
1694 { 1698 {
1695#ifndef NO_OPIE 1699#ifndef NO_OPIE
1696 owarn << "Could not read file " << fn << oendl; 1700 owarn << "Could not read file " << fn << oendl;
1697#else 1701#else
1698 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1702 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1699#endif 1703#endif
1700 QMessageBox::critical( 0, tr("ZSafe"), 1704 QMessageBox::critical( 0, tr("ZSafe"),
1701 tr("Could not import text file.") ); 1705 tr("Could not import text file.") );
1702 return; 1706 return;
1703 } 1707 }
1704 1708
1705 modified = true; 1709 modified = true;
1706 1710
1707 // clear the password list 1711 // clear the password list
1708 selectedItem = NULL; 1712 selectedItem = NULL;
1709 QListViewItem *i; 1713 QListViewItem *i;
1710 // step through all categories 1714 // step through all categories
1711 for (i = ListView->firstChild(); 1715 for (i = ListView->firstChild();
1712 i != NULL; 1716 i != NULL;
1713 i = i->nextSibling()) 1717 i = i->nextSibling())
1714 { 1718 {
1715 // step through all subitems 1719 // step through all subitems
1716 QListViewItem *si; 1720 QListViewItem *si;
1717 for (si = i->firstChild(); 1721 for (si = i->firstChild();
1718 si != NULL; ) 1722 si != NULL; )
1719 // si = si->nextSibling()) 1723 // si = si->nextSibling())
1720 { 1724 {
1721 QListViewItem *_si = si; 1725 QListViewItem *_si = si;
1722 si = si->nextSibling(); 1726 si = si->nextSibling();
1723 i->takeItem(_si); // remove from view list 1727 i->takeItem(_si); // remove from view list
1724 if (_si) delete _si; 1728 if (_si) delete _si;
1725 } 1729 }
1726 } 1730 }
1727 1731
1728#ifndef NO_OPIE 1732#ifndef NO_OPIE
1729 owarn << "ReadAllEntries(): " << oendl; 1733 owarn << "ReadAllEntries(): " << oendl;
1730#else 1734#else
1731 qWarning ("ReadAllEntries(): "); 1735 qWarning ("ReadAllEntries(): ");
1732#endif 1736#endif
1733 QTextStream t(&f); 1737 QTextStream t(&f);
1734 while ( !t.eof() ) 1738 while ( !t.eof() )
1735 { 1739 {
1736 QString s = t.readLine(); 1740 QString s = t.readLine();
1737 s.replace (QRegExp("\";\""), "\"|\""); 1741 s.replace (QRegExp("\";\""), "\"|\"");
1738 // char buffer[1024]; 1742 // char buffer[1024];
1739 int len=s.length()+1; 1743 int len=s.length()+1;
1740#ifdef Q_WS_WIN 1744#ifdef Q_WS_WIN
1741 char buffer[512]; 1745 char buffer[512];
1742#else 1746#else
1743 char buffer[len]; 1747 char buffer[len];
1744#endif 1748#endif
1745 strcpy (buffer, s); 1749 strcpy (buffer, s);
1746 1750
1747 QString name; 1751 QString name;
1748 QString user; 1752 QString user;
1749 QString password; 1753 QString password;
1750 QString comment; 1754 QString comment;
1751 1755
1752 // separete the entries 1756 // separete the entries
1753 char *i = strtok (buffer, "|"); 1757 char *i = strtok (buffer, "|");
1754 QString category(&i[1]); 1758 QString category(&i[1]);
1755 category.truncate(category.length() -1); 1759 category.truncate(category.length() -1);
1756 1760
1757 int idx=0; 1761 int idx=0;
1758 while (i = strtok (NULL, "|")) 1762 while (i = strtok (NULL, "|"))
1759 { 1763 {
1760 switch (idx) 1764 switch (idx)
1761 { 1765 {
1762 case 0: 1766 case 0:
1763 name = &i[1]; 1767 name = &i[1];
1764 name.truncate(name.length() -1); 1768 name.truncate(name.length() -1);
1765 // name 1769 // name
1766 break; 1770 break;
1767 case 1: 1771 case 1:
1768 // user 1772 // user
1769 user = &i[1]; 1773 user = &i[1];
1770 user.truncate(user.length() -1); 1774 user.truncate(user.length() -1);
1771 break; 1775 break;
1772 case 2: 1776 case 2:
1773 // password 1777 // password
1774 password = &i[1]; 1778 password = &i[1];
1775 password.truncate(password.length() -1); 1779 password.truncate(password.length() -1);
1776 break; 1780 break;
1777 case 3: 1781 case 3:
1778 // comment 1782 // comment
1779 comment = &i[1]; 1783 comment = &i[1];
1780 comment.truncate(comment.length() -1); 1784 comment.truncate(comment.length() -1);
1781 break; 1785 break;
1782 } 1786 }
1783 idx++; 1787 idx++;
1784 } 1788 }
1785 1789
1786 Category *cat= categories.find (category); 1790 Category *cat= categories.find (category);
1787 if (cat) 1791 if (cat)
1788 { 1792 {
1789 // use the existend item 1793 // use the existend item
1790 QListViewItem *catItem = cat->getListItem(); 1794 QListViewItem *catItem = cat->getListItem();
1791 if (catItem) 1795 if (catItem)
1792 { 1796 {
1793 QListViewItem * item = new ShadedListItem( 0, catItem ); 1797 QListViewItem * item = new ShadedListItem( 0, catItem );
1794 item->setText( 0, tr( name ) ); 1798 item->setText( 0, tr( name ) );
1795 item->setText( 1, tr( user ) ); 1799 item->setText( 1, tr( user ) );
1796 item->setText( 2, tr( password ) ); 1800 item->setText( 2, tr( password ) );
1797 item->setText( 3, tr( comment ) ); 1801 item->setText( 3, tr( comment ) );
1798 1802
1799 catItem->setOpen( TRUE ); 1803 catItem->setOpen( TRUE );
1800 } 1804 }
1801 } 1805 }
1802 else 1806 else
1803 { 1807 {
1804 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1808 QListViewItem *catI = new ShadedListItem( 1, ListView );
1805 // create and insert a new item 1809 // create and insert a new item
1806 QListViewItem * item = new ShadedListItem( 0, catI ); 1810 QListViewItem * item = new ShadedListItem( 0, catI );
1807 item->setText( 0, tr( name ) ); 1811 item->setText( 0, tr( name ) );
1808 item->setText( 1, tr( user ) ); 1812 item->setText( 1, tr( user ) );
1809 item->setText( 2, tr( password ) ); 1813 item->setText( 2, tr( password ) );
1810 item->setText( 3, tr( comment ) ); 1814 item->setText( 3, tr( comment ) );
1811 1815
1812 catI->setOpen( TRUE ); 1816 catI->setOpen( TRUE );
1813 1817
1814 Category *c1 = new Category(); 1818 Category *c1 = new Category();
1815 c1->setCategoryName(category); 1819 c1->setCategoryName(category);
1816 1820
1817 QString icon; 1821 QString icon;
1818 QString fullIconPath; 1822 QString fullIconPath;
1819 QPixmap *pix; 1823 QPixmap *pix;
1820// #ifndef Q_WS_WIN 1824// #ifndef Q_WS_WIN
1821 icon = conf->readEntry(APP_KEY+category); 1825 icon = conf->readEntry(APP_KEY+category);
1822// #endif 1826// #endif
1823 bool isIconAv = false; 1827 bool isIconAv = false;
1824 if (!icon.isEmpty() && !icon.isNull()) 1828 if (!icon.isEmpty() && !icon.isNull())
1825 { 1829 {
1826 // build the full path 1830 // build the full path
1827 fullIconPath = iconPath + icon; 1831 fullIconPath = iconPath + icon;
1828 pix = new QPixmap (fullIconPath); 1832 pix = new QPixmap (fullIconPath);
1829 if (!pix->isNull()) 1833 if (!pix->isNull())
1830 { 1834 {
1831 QImage img = pix->convertToImage(); 1835 QImage img = pix->convertToImage();
1832 pix->convertFromImage(img.smoothScale(14,14)); 1836 pix->convertFromImage(img.smoothScale(14,14));
1833 c1->setIconName (icon); 1837 c1->setIconName (icon);
1834 c1->setIcon (*pix); 1838 c1->setIcon (*pix);
1835 isIconAv = true; 1839 isIconAv = true;
1836 } 1840 }
1837 } 1841 }
1838 if (!isIconAv) 1842 if (!isIconAv)
1839 { 1843 {
1840 c1->setIcon (*getPredefinedIcon(category)); 1844 c1->setIcon (*getPredefinedIcon(category));
1841 } 1845 }
1842 c1->setListItem (catI); 1846 c1->setListItem (catI);
1843 c1->initListItem(); 1847 c1->initListItem();
1844 categories.insert (c1->getCategoryName(), c1); 1848 categories.insert (c1->getCategoryName(), c1);
1845 } 1849 }
1846 1850
1847 } 1851 }
1848 f.close(); 1852 f.close();
1849 1853
1850} 1854}
1851#endif // UNUSED 1855#endif // UNUSED
1852 1856
1853void ZSafe::resume(int) 1857void ZSafe::resume(int)
1854{ 1858{
1855#ifndef NO_OPIE 1859#ifndef NO_OPIE
1856 owarn << "Resume" << oendl; 1860 owarn << "Resume" << oendl;
1857#endif 1861#endif
1858 // hide the main window 1862 // hide the main window
1859 1863
1860 if ( !showpwd ) 1864 if ( !showpwd )
1861 { 1865 {
1862 infoForm->hide(); 1866 infoForm->hide();
1863 // open zsafe again 1867 // open zsafe again
1864 m_password = ""; 1868 m_password = "";
1865 selectedItem = NULL; 1869 selectedItem = NULL;
1866 1870
1867 // clear the password list 1871 // clear the password list
1868 QListViewItem *i; 1872 QListViewItem *i;
1869 // step through all categories 1873 // step through all categories
1870 for (i = ListView->firstChild(); 1874 for (i = ListView->firstChild();
1871 i != NULL; 1875 i != NULL;
1872 i = i->nextSibling()) 1876 i = i->nextSibling())
1873 { 1877 {
1874 // step through all subitems 1878 // step through all subitems
1875 QListViewItem *si; 1879 QListViewItem *si;
1876 for (si = i->firstChild(); 1880 for (si = i->firstChild();
1877 si != NULL; ) 1881 si != NULL; )
1878 { 1882 {
1879 QListViewItem *_si = si; 1883 QListViewItem *_si = si;
1880 si = si->nextSibling(); 1884 si = si->nextSibling();
1881 i->takeItem(_si); // remove from view list 1885 i->takeItem(_si); // remove from view list
1882 if (_si) delete _si; 1886 if (_si) delete _si;
1883 } 1887 }
1884 } 1888 }
1885 1889
1886 // ask for password and read again 1890 // ask for password and read again
1887 openDocument(filename); 1891 openDocument(filename);
1888 } 1892 }
1889} 1893}
1890 1894
1891//--------------------------------------------- 1895//---------------------------------------------
1892 1896
1893 1897
1894bool ZSafe::openDocument(const char* _filename, const char* ) 1898bool ZSafe::openDocument(const char* _filename, const char* )
1895{ 1899{
1896 QString name= _filename; 1900 QString name= _filename;
1897 qWarning("openDocument "+name); 1901 qWarning("openDocument "+name);
1898 int retval; 1902 int retval;
1899 char* entry[FIELD_SIZE]; 1903 char* entry[FIELD_SIZE];
1900// #ifndef Q_WS_WIN 1904// #ifndef Q_WS_WIN
1901 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1905 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1902// #else 1906// #else
1903 // int validationFlag = 1; 1907 // int validationFlag = 1;
1904// #endif 1908// #endif
1905 1909
1906 int pwdOk = 0; 1910 int pwdOk = 0;
1907 int numberOfTries = 3; 1911 int numberOfTries = 3;
1908 for (int i=0; i < numberOfTries; i++) 1912 for (int i=0; i < numberOfTries; i++)
1909 { 1913 {
1910 QFile f(_filename); 1914 QFile f(_filename);
1911 if (f.exists()) 1915 if (f.exists())
1912 { 1916 {
1913 // ask with a dialog for the password 1917 // ask with a dialog for the password
1914 if (m_password.isEmpty()) 1918 if (m_password.isEmpty())
1915 getDocPassword(tr("Enter Password")); 1919 getDocPassword(tr("Enter Password"));
1916 if (m_password.isEmpty() && validationFlag == 0) 1920 if (m_password.isEmpty() && validationFlag == 0)
1917 { 1921 {
1918#ifndef NO_OPIE 1922#ifndef NO_OPIE
1919 owarn << "Wrong password" << oendl; 1923 owarn << "Wrong password" << oendl;
1920#else 1924#else
1921 qWarning ("Wrong password"); 1925 qWarning ("Wrong password");
1922#endif 1926#endif
1923 QMessageBox::critical( 0, tr("ZSafe"), 1927 QMessageBox::critical( 0, tr("ZSafe"),
1924 tr("Wrong password.\n\nZSafe will now exit.") ); 1928 tr("Wrong password.\n\nZSafe will now exit.") );
1925 exitZs (1); 1929 exitZs (1);
1926 } 1930 }
1927 1931
1928 retval = loadInit(_filename, m_password); 1932 retval = loadInit(_filename, m_password);
1929 if (retval != PWERR_GOOD) 1933 if (retval != PWERR_GOOD)
1930 { 1934 {
1931#ifndef NO_OPIE 1935#ifndef NO_OPIE
1932 owarn << "Error loading Document" << oendl; 1936 owarn << "Error loading Document" << oendl;
1933#else 1937#else
1934 qWarning ("Error loading Document"); 1938 qWarning ("Error loading Document");
1935#endif 1939#endif
1936 return false; 1940 return false;
1937 } 1941 }
1938 } 1942 }
1939 else 1943 else
1940 { 1944 {
1941#ifdef Q_WS_WIN 1945#ifdef Q_WS_WIN
1942 this->setCaption("Qt ZSafe"); 1946 this->setCaption("Qt ZSafe");
1943#else 1947#else
1944 this->setCaption("ZSafe"); 1948 this->setCaption("ZSafe");
1945#endif 1949#endif
1946 filename = ""; 1950 filename = "";
1947 switch( QMessageBox::warning( this, tr("ZSafe"), 1951 switch( QMessageBox::warning( this, tr("ZSafe"),
1948 tr("<P>You must create a new document first. Ok to create?</P>"), 1952 tr("<P>You must create a new document first. Ok to create?</P>"),
1949 tr("&Yes"), tr("&No."), 1953 tr("&Yes"), tr("&No."),
1950 0 1954 0
1951 ) ) 1955 ) )
1952 { 1956 {
1953 case 1: // No 1957 case 1: // No
1954 return false; 1958 return false;
1955 break; 1959 break;
1956 case 0: // Yes 1960 case 0: // Yes
1957 newDocument(); 1961 newDocument();
1958 return false; 1962 return false;
1959 break; 1963 break;
1960 } 1964 }
1961 1965
1962 } 1966 }
1963 1967
1964 1968
1965 // load the validation entry 1969 // load the validation entry
1966 if (validationFlag == 0) 1970 if (validationFlag == 0)
1967 { 1971 {
1968 pwdOk = 1; 1972 pwdOk = 1;
1969 break; 1973 break;
1970 } 1974 }
1971 1975
1972 retval = loadEntry(entry); 1976 retval = loadEntry(entry);
1973 if (retval == 1 && 1977 if (retval == 1 &&
1974 !strcmp (entry[0], "ZSAFECATEGORY") && 1978 !strcmp (entry[0], "ZSAFECATEGORY") &&
1975 !strcmp (entry[1], "name") && 1979 !strcmp (entry[1], "name") &&
1976 !strcmp (entry[2], "username") && 1980 !strcmp (entry[2], "username") &&
1977 !strcmp (entry[3], "password") && 1981 !strcmp (entry[3], "password") &&
1978 !strcmp (entry[4], "comment") ) 1982 !strcmp (entry[4], "comment") )
1979 { 1983 {
1980 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1984 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1981 pwdOk = 1; 1985 pwdOk = 1;
1982 break; 1986 break;
1983 } 1987 }
1984 else 1988 else
1985 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1989 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1986 fclose (fd); 1990 fclose (fd);
1987 m_password = ""; 1991 m_password = "";
1988 1992
1989 if (i < numberOfTries - 1) 1993 if (i < numberOfTries - 1)
1990 { 1994 {
1991 switch( QMessageBox::warning( this, tr("ZSafe"), 1995 switch( QMessageBox::warning( this, tr("ZSafe"),
1992 tr("Wrong password.\nEnter again?"), 1996 tr("Wrong password.\nEnter again?"),
1993 tr("&Yes"), tr("&No."), 1997 tr("&Yes"), tr("&No."),
1994 0 1998 0
1995 ) ) 1999 ) )
1996 { 2000 {
1997 case 1: // No 2001 case 1: // No
1998 exitZs (1); 2002 exitZs (1);
1999 break; 2003 break;
2000 case 0: // Yes 2004 case 0: // Yes
2001 continue; 2005 continue;
2002 } 2006 }
2003 } 2007 }
2004 } 2008 }
2005 if (pwdOk == 0) 2009 if (pwdOk == 0)
2006 { 2010 {
2007 // unset the document entry 2011 // unset the document entry
2008 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 2012 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
2009 if (conf) 2013 if (conf)
2010 delete conf; 2014 delete conf;
2011 2015
2012 exitZs (1); 2016 exitZs (1);
2013 } 2017 }
2014 2018
2015 2019
2016 retval = loadEntry(entry); 2020 retval = loadEntry(entry);
2017 2021
2018 int numberOfEntries=0; 2022 int numberOfEntries=0;
2019 while (retval == 1) { 2023 while (retval == 1) {
2020 2024
2021 QString category( QString::fromUtf8(entry[0]) ); 2025 QString category( QString::fromUtf8(entry[0]) );
2022 QString name( QString::fromUtf8(entry[1]) ); 2026 QString name( QString::fromUtf8(entry[1]) );
2023 QString user( QString::fromUtf8(entry[2]) ); 2027 QString user( QString::fromUtf8(entry[2]) );
2024 QString password( QString::fromUtf8(entry[3]) ); 2028 QString password( QString::fromUtf8(entry[3]) );
2025 QString comment( QString::fromUtf8(entry[4]) ); 2029 QString comment( QString::fromUtf8(entry[4]) );
2026 QString field5( QString::fromUtf8(entry[5]) ); 2030 QString field5( QString::fromUtf8(entry[5]) );
2027 QString field6( QString::fromUtf8(entry[6]) ); 2031 QString field6( QString::fromUtf8(entry[6]) );
2028 // add the subitems to the categories 2032 // add the subitems to the categories
2029 2033
2030 Category *cat= categories.find (category); 2034 Category *cat= categories.find (category);
2031 if (cat) 2035 if (cat)
2032 { 2036 {
2033 // use the existend item 2037 // use the existend item
2034 QListViewItem *catItem = cat->getListItem(); 2038 QListViewItem *catItem = cat->getListItem();
2035 if (catItem) 2039 if (catItem)
2036 { 2040 {
2037 QListViewItem * item = new ShadedListItem( 0, catItem ); 2041 QListViewItem * item = new ShadedListItem( 0, catItem );
2038 item->setText( 0, tr( name ) ); 2042 item->setText( 0, tr( name ) );
2039 item->setText( 1, tr( user ) ); 2043 item->setText( 1, tr( user ) );
2040 item->setText( 2, tr( password ) ); 2044 item->setText( 2, tr( password ) );
2041 item->setText( 3, tr( comment ) ); 2045 item->setText( 3, tr( comment ) );
2042 item->setText( 4, tr( field5 ) ); 2046 item->setText( 4, tr( field5 ) );
2043 item->setText( 5, tr( field6 ) ); 2047 item->setText( 5, tr( field6 ) );
2044 2048
2045 if (expandTree) 2049 if (expandTree)
2046 catItem->setOpen( TRUE ); 2050 catItem->setOpen( TRUE );
2047 numberOfEntries++; 2051 numberOfEntries++;
2048 } 2052 }
2049 } 2053 }
2050 else 2054 else
2051 { 2055 {
2052 QListViewItem *catI = new ShadedListItem( 1, ListView ); 2056 QListViewItem *catI = new ShadedListItem( 1, ListView );
2053 // create and insert a new item 2057 // create and insert a new item
2054 QListViewItem * item = new ShadedListItem( 0, catI ); 2058 QListViewItem * item = new ShadedListItem( 0, catI );
2055 2059
2056 item->setText( 0, tr( name ) ); 2060 item->setText( 0, tr( name ) );
2057 item->setText( 1, tr( user ) ); 2061 item->setText( 1, tr( user ) );
2058 item->setText( 2, tr( password ) ); 2062 item->setText( 2, tr( password ) );
2059 item->setText( 3, tr( comment ) ); 2063 item->setText( 3, tr( comment ) );
2060 item->setText( 4, tr( field5 ) ); 2064 item->setText( 4, tr( field5 ) );
2061 item->setText( 5, tr( field6 ) ); 2065 item->setText( 5, tr( field6 ) );
2062 2066
2063 if (expandTree) 2067 if (expandTree)
2064 catI->setOpen( TRUE ); 2068 catI->setOpen( TRUE );
2065 2069
2066 Category *c1 = new Category(); 2070 Category *c1 = new Category();
2067 c1->setCategoryName(category); 2071 c1->setCategoryName(category);
2068 2072
2069 QString icon; 2073 QString icon;
2070 QString fullIconPath; 2074 QString fullIconPath;
2071 QPixmap *pix; 2075 QPixmap *pix;
2072// #ifndef Q_WS_WIN 2076// #ifndef Q_WS_WIN
2073 icon = conf->readEntry(APP_KEY+category); 2077 icon = conf->readEntry(APP_KEY+category);
2074// #endif 2078// #endif
2075 bool isIconAv = false; 2079 bool isIconAv = false;
2076 if (!icon.isEmpty() && !icon.isNull()) 2080 if (!icon.isEmpty() && !icon.isNull())
2077 { 2081 {
2078 // build the full path 2082 // build the full path
2079 fullIconPath = iconPath + icon; 2083 fullIconPath = iconPath + icon;
2080 pix = new QPixmap (fullIconPath); 2084 pix = new QPixmap (fullIconPath);
2081 if (!pix->isNull()) 2085 if (!pix->isNull())
2082 { 2086 {
2083 QImage img = pix->convertToImage(); 2087 QImage img = pix->convertToImage();
2084 pix->convertFromImage(img.smoothScale(14,14)); 2088 pix->convertFromImage(img.smoothScale(14,14));
2085 c1->setIconName (icon); 2089 c1->setIconName (icon);
2086 c1->setIcon (*pix); 2090 c1->setIcon (*pix);
2087 isIconAv = true; 2091 isIconAv = true;
2088 } 2092 }
2089 } 2093 }
2090 if (!isIconAv) 2094 if (!isIconAv)
2091 { 2095 {
2092 c1->setIcon (*getPredefinedIcon(category)); 2096 c1->setIcon (*getPredefinedIcon(category));
2093 } 2097 }
2094 2098
2095 c1->setListItem (catI); 2099 c1->setListItem (catI);
2096 c1->initListItem(); 2100 c1->initListItem();
2097 categories.insert (c1->getCategoryName(), c1); 2101 categories.insert (c1->getCategoryName(), c1);
2098 numberOfEntries++; 2102 numberOfEntries++;
2099 } 2103 }
2100 2104
2101 for (int count = 0; count < FIELD_SIZE; count++) { 2105 for (int count = 0; count < FIELD_SIZE; count++) {
2102 free(entry[count]); 2106 free(entry[count]);
2103 } 2107 }
2104 retval = loadEntry(entry); 2108 retval = loadEntry(entry);
2105 if (retval == 2) { 2109 if (retval == 2) {
2106 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2110 // m_parent->slotStatusHelpMsg("Last entry loaded");
2107 } 2111 }
2108 } // end while 2112 } // end while
2109 2113
2110 if (numberOfEntries == 0) 2114 if (numberOfEntries == 0)
2111 { 2115 {
2112 2116
2113 switch( QMessageBox::warning( this, tr("ZSafe"), 2117 switch( QMessageBox::warning( this, tr("ZSafe"),
2114 tr("Empty document or\nwrong password.\nContinue?"), 2118 tr("Empty document or\nwrong password.\nContinue?"),
2115 tr("&No"), tr("&Yes."), 2119 tr("&No"), tr("&Yes."),
2116 0 2120 0
2117 ) ) { 2121 ) ) {
2118 case 0: // No 2122 case 0: // No
2119 retval = loadFinalize(); 2123 retval = loadFinalize();
2120 exitZs (1); 2124 exitZs (1);
2121 break; 2125 break;
2122 case 1: // Yes 2126 case 1: // Yes
2123 break; 2127 break;
2124 } 2128 }
2125 } 2129 }
2126 2130
2127 retval = loadFinalize(); 2131 retval = loadFinalize();
2128 2132
2129 return true; 2133 return true;
2130} 2134}
2131 2135
2132int ZSafe::loadInit(const char* _filename, const char *password) 2136int ZSafe::loadInit(const char* _filename, const char *password)
2133{ 2137{
2134 unsigned int j = 0; 2138 unsigned int j = 0;
2135 unsigned int keylength=0; 2139 unsigned int keylength=0;
2136 int count=0, count2=0, count3=0; 2140 int count=0, count2=0, count3=0;
2137 unsigned char charbuf[8]; 2141 unsigned char charbuf[8];
2138 unsigned short ciphertext[4]; 2142 unsigned short ciphertext[4];
2139 char key[128]; 2143 char key[128];
2140 Krc2* krc2 = new Krc2(); 2144 Krc2* krc2 = new Krc2();
2141 2145
2142 fd = fopen (_filename, "rb"); 2146 fd = fopen (_filename, "rb");
2143 2147
2144 QFileInfo f (_filename); 2148 QFileInfo f (_filename);
2145 load_buffer_length = f.size(); 2149 load_buffer_length = f.size();
2146 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2150 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2147 2151
2148 if (fd == NULL) 2152 if (fd == NULL)
2149 return PWERR_OPEN; 2153 return PWERR_OPEN;
2150 2154
2151 buffer = (char *)malloc(load_buffer_length); 2155 buffer = (char *)malloc(load_buffer_length);
2152 for (j = 0; password[j] != '\0'; j++) { 2156 for (j = 0; password[j] != '\0'; j++) {
2153 key[j] = password[j]; 2157 key[j] = password[j];
2154 } 2158 }
2155 keylength = j; 2159 keylength = j;
2156 krc2->rc2_expandkey (key, keylength, 128); 2160 krc2->rc2_expandkey (key, keylength, 128);
2157 2161
2158#ifndef Q_WS_WIN 2162#ifndef Q_WS_WIN
2159 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2163 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2160#else 2164#else
2161 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2165 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2162#endif 2166#endif
2163 2167
2164 if (size < 8) 2168 if (size < 8)
2165 return PWERR_DATA; 2169 return PWERR_DATA;
2166 2170
2167 for (count = 0; count < 4; count++) { 2171 for (count = 0; count < 4; count++) {
2168 count2 = count << 1; 2172 count2 = count << 1;
2169 iv[count] = charbuf[count2] << 8; 2173 iv[count] = charbuf[count2] << 8;
2170 iv[count] += charbuf[count2 + 1]; 2174 iv[count] += charbuf[count2 + 1];
2171 } 2175 }
2172 2176
2173 size = 0; 2177 size = 0;
2174 bufferIndex = 0; 2178 bufferIndex = 0;
2175#ifndef Q_WS_WIN 2179#ifndef Q_WS_WIN
2176 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2180 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2177 while (count < 8) { 2181 while (count < 8) {
2178 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2182 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2179#else 2183#else
2180 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2184 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2181 while (count < 8) { 2185 while (count < 8) {
2182 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2186 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2183#endif 2187#endif
2184 if (count2 == 0) { 2188 if (count2 == 0) {
2185 return PWERR_DATA; 2189 return PWERR_DATA;
2186 } 2190 }
2187 count += count2; 2191 count += count2;
2188 } /* while (count < 8) */ 2192 } /* while (count < 8) */
2189 2193
2190 size += 8; 2194 size += 8;
2191 for (count2 = 0; count2 < 8; count2 += 2) { 2195 for (count2 = 0; count2 < 8; count2 += 2) {
2192 count3 = count2 >> 1; 2196 count3 = count2 >> 1;
2193 ciphertext[count3] = charbuf[count2] << 8; 2197 ciphertext[count3] = charbuf[count2] << 8;
2194 ciphertext[count3] += charbuf[count2 + 1]; 2198 ciphertext[count3] += charbuf[count2 + 1];
2195 2199
2196 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2200 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2197 iv[count3] = plaintext[count3]; 2201 iv[count3] = plaintext[count3];
2198 } /* for (count2) */ 2202 } /* for (count2) */
2199 2203
2200 krc2->rc2_decrypt (plaintext); 2204 krc2->rc2_decrypt (plaintext);
2201 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2205 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2202 bufferIndex += 8; 2206 bufferIndex += 8;
2203 buffer[bufferIndex + 1] = '\0'; 2207 buffer[bufferIndex + 1] = '\0';
2204 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2208 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2205 size -= buffer[size - 1]; 2209 size -= buffer[size - 1];
2206 lastcount = 0; 2210 lastcount = 0;
2207 2211
2208 /* This will point to the starting index */ 2212 /* This will point to the starting index */
2209 bufferIndex = 0; 2213 bufferIndex = 0;
2210 return PWERR_GOOD; 2214 return PWERR_GOOD;
2211} 2215}
2212 2216
2213int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2217int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2214{ 2218{
2215 /* Strip off PKCS 5 padding 2219 /* Strip off PKCS 5 padding
2216 * Should check to make sure it's good here 2220 * Should check to make sure it's good here
2217 */ 2221 */
2218 int count, count1=0; 2222 int count, count1=0;
2219 2223
2220 for (count = lastcount; count < size; count++) { 2224 for (count = lastcount; count < size; count++) {
2221 if ((unsigned char) (buffer[count]) == 255) { 2225 if ((unsigned char) (buffer[count]) == 255) {
2222 if (buffer[bufferIndex] == '\0') { 2226 if (buffer[bufferIndex] == '\0') {
2223 bufferIndex++; 2227 bufferIndex++;
2224 } 2228 }
2225 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2229 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2226 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2230 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2227 entry[count1][count - bufferIndex] = '\0'; 2231 entry[count1][count - bufferIndex] = '\0';
2228 count++; 2232 count++;
2229 bufferIndex = count; 2233 bufferIndex = count;
2230 count1++; 2234 count1++;
2231 if (count1 == FIELD_SIZE) { 2235 if (count1 == FIELD_SIZE) {
2232 lastcount = count; 2236 lastcount = count;
2233 return 1; 2237 return 1;
2234 } 2238 }
2235 } /* if ((unsigned char) (buffer[count]) == 255) */ 2239 } /* if ((unsigned char) (buffer[count]) == 255) */
2236 } /* for (count = 0; count < size; count++) */ 2240 } /* for (count = 0; count < size; count++) */
2237 2241
2238 return 2; 2242 return 2;
2239} 2243}
2240 2244
2241int ZSafe::loadFinalize(void) 2245int ZSafe::loadFinalize(void)
2242{ 2246{
2243 fclose (fd); 2247 fclose (fd);
2244 if (buffer) free(buffer); 2248 if (buffer) free(buffer);
2245 return PWERR_GOOD; 2249 return PWERR_GOOD;
2246} 2250}
2247 2251
2248bool ZSafe::saveDocument(const char* _filename, 2252bool ZSafe::saveDocument(const char* _filename,
2249 bool withPwd, 2253 bool withPwd,
2250 const char* ) 2254 const char* )
2251{ 2255{
2252 if (filename.isEmpty()) 2256 if (filename.isEmpty())
2253 { 2257 {
2254 QMessageBox::critical( 0, tr("ZSafe"), 2258 QMessageBox::critical( 0, tr("ZSafe"),
2255 tr("No document defined.\nYou have to create a new document")); 2259 tr("No document defined.\nYou have to create a new document"));
2256 return false; 2260 return false;
2257 } 2261 }
2258 2262
2259 // if (m_password.isEmpty()) 2263 // if (m_password.isEmpty())
2260 // withPwd = true; // the document must be saved with a valid password 2264 // withPwd = true; // the document must be saved with a valid password
2261 if (withPwd) 2265 if (withPwd)
2262 { 2266 {
2263 bool pwdOk = FALSE; 2267 bool pwdOk = FALSE;
2264 while (!pwdOk) 2268 while (!pwdOk)
2265 { 2269 {
2266 getDocPassword(tr("Enter Password")); 2270 getDocPassword(tr("Enter Password"));
2267 if (m_password.isEmpty()) 2271 if (m_password.isEmpty())
2268 { 2272 {
2269 2273
2270 QMessageBox::critical( 0, tr("ZSafe"), 2274 QMessageBox::critical( 0, tr("ZSafe"),
2271 tr("Password is empty.\nPlease enter again.")); 2275 tr("Password is empty.\nPlease enter again."));
2272 continue; 2276 continue;
2273 } 2277 }
2274 2278
2275 QString firstPasswd = m_password; 2279 QString firstPasswd = m_password;
2276 2280
2277 getDocPassword(tr("Reenter Password")); 2281 getDocPassword(tr("Reenter Password"));
2278 if (m_password.isEmpty()) 2282 if (m_password.isEmpty())
2279 { 2283 {
2280 QMessageBox::critical( 0, tr("ZSafe"), 2284 QMessageBox::critical( 0, tr("ZSafe"),
2281 tr("Password is empty.\nPlease enter again.")); 2285 tr("Password is empty.\nPlease enter again."));
2282 continue; 2286 continue;
2283 } 2287 }
2284 if (firstPasswd != m_password) 2288 if (firstPasswd != m_password)
2285 { 2289 {
2286 2290
2287 QMessageBox::critical( 0, tr("ZSafe"), 2291 QMessageBox::critical( 0, tr("ZSafe"),
2288 tr("Passwords must be identical.\nPlease enter again.")); 2292 tr("Passwords must be identical.\nPlease enter again."));
2289 continue; 2293 continue;
2290 } 2294 }
2291 pwdOk = TRUE; 2295 pwdOk = TRUE;
2292 modified = false; 2296 modified = false;
2293 } 2297 }
2294 } 2298 }
2295 else if (modified) 2299 else if (modified)
2296 { 2300 {
2297 QString fns(_filename); 2301 QString fns(_filename);
2298 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2302 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2299 switch( QMessageBox::information( this, tr("ZSafe"), 2303 switch( QMessageBox::information( this, tr("ZSafe"),
2300 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2304 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2301 tr("&Save"), 2305 tr("&Save"),
2302 tr("&Don't Save"), 2306 tr("&Don't Save"),
2303 0 // Enter == button 0 2307 0 // Enter == button 0
2304 ) ) 2308 ) )
2305 { // Escape == button 2 2309 { // Escape == button 2
2306 case 0: // Save clicked, Alt-S or Enter pressed. 2310 case 0: // Save clicked, Alt-S or Enter pressed.
2307 modified = false; 2311 modified = false;
2308 break; 2312 break;
2309 case 1: // Don't Save clicked or Alt-D pressed 2313 case 1: // Don't Save clicked or Alt-D pressed
2310 modified = false; 2314 modified = false;
2311 return true; 2315 return true;
2312 } 2316 }
2313 } 2317 }
2314 modified = false; 2318 modified = false;
2315 2319
2316 if (m_password.isEmpty()) 2320 if (m_password.isEmpty())
2317 return false; 2321 return false;
2318 2322
2319 int retval = saveInit(_filename, m_password); 2323 int retval = saveInit(_filename, m_password);
2320 // int retval = saveInit(_filename, "test"); 2324 // int retval = saveInit(_filename, "test");
2321 if (retval != PWERR_GOOD) { 2325 if (retval != PWERR_GOOD) {
2322 return false; 2326 return false;
2323 } 2327 }
2324 2328
2325 char* entry[FIELD_SIZE]; 2329 char* entry[FIELD_SIZE];
2326 2330
2327 // save the validation entry 2331 // save the validation entry
2328 { 2332 {
2329 int i=0; 2333 int i=0;
2330 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2334 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2331 strcpy(entry[i++], "ZSAFECATEGORY"); 2335 strcpy(entry[i++], "ZSAFECATEGORY");
2332 entry[i] = (char*)malloc(strlen("name")+1); 2336 entry[i] = (char*)malloc(strlen("name")+1);
2333 strcpy(entry[i++], "name"); 2337 strcpy(entry[i++], "name");
2334 entry[i] = (char*)malloc(strlen("username")+1); 2338 entry[i] = (char*)malloc(strlen("username")+1);
2335 strcpy(entry[i++], "username"); 2339 strcpy(entry[i++], "username");
2336 entry[i] = (char*)malloc(strlen("password")+1); 2340 entry[i] = (char*)malloc(strlen("password")+1);
2337 strcpy(entry[i++], "password"); 2341 strcpy(entry[i++], "password");
2338 entry[i] = (char*)malloc(strlen("comment")+1); 2342 entry[i] = (char*)malloc(strlen("comment")+1);
2339 strcpy(entry[i++], "comment"); 2343 strcpy(entry[i++], "comment");
2340 2344
2341 entry[i] = (char*)malloc(strlen("field5")+1); 2345 entry[i] = (char*)malloc(strlen("field5")+1);
2342 strcpy(entry[i++], "field5"); 2346 strcpy(entry[i++], "field5");
2343 entry[i] = (char*)malloc(strlen("field6")+1); 2347 entry[i] = (char*)malloc(strlen("field6")+1);
2344 strcpy(entry[i++], "field6"); 2348 strcpy(entry[i++], "field6");
2345 2349
2346 retval = saveEntry(entry); 2350 retval = saveEntry(entry);
2347 for (int z=0; z<i; z++) free(entry[z]); 2351 for (int z=0; z<i; z++) free(entry[z]);
2348 if (retval == PWERR_DATA) { 2352 if (retval == PWERR_DATA) {
2349#ifndef NO_OPIE 2353#ifndef NO_OPIE
2350 owarn << "1: Error writing file, contents not saved" << oendl; 2354 owarn << "1: Error writing file, contents not saved" << oendl;
2351#else 2355#else
2352 qWarning("1: Error writing file, contents not saved"); 2356 qWarning("1: Error writing file, contents not saved");
2353#endif 2357#endif
2354 saveFinalize(); 2358 saveFinalize();
2355 return false; 2359 return false;
2356 } 2360 }
2357// #ifndef Q_WS_WIN 2361// #ifndef Q_WS_WIN
2358 conf->writeEntry(APP_KEY+"valzsafe", 1); 2362 conf->writeEntry(APP_KEY+"valzsafe", 1);
2359// #endif 2363// #endif
2360 saveConf(); 2364 saveConf();
2361 } 2365 }
2362 2366
2363 QListViewItem *i; 2367 QListViewItem *i;
2364 // step through all categories 2368 // step through all categories
2365 for (i = ListView->firstChild(); 2369 for (i = ListView->firstChild();
2366 i != NULL; 2370 i != NULL;
2367 i = i->nextSibling()) 2371 i = i->nextSibling())
2368 { 2372 {
2369 // step through all subitems 2373 // step through all subitems
2370 QListViewItem *si; 2374 QListViewItem *si;
2371 for (si = i->firstChild(); 2375 for (si = i->firstChild();
2372 si != NULL; 2376 si != NULL;
2373 si = si->nextSibling()) 2377 si = si->nextSibling())
2374 { 2378 {
2375 int j=0; 2379 int j=0;
2376 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2380 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2377 strcpy(entry[j++], i->text(0).utf8()); 2381 strcpy(entry[j++], i->text(0).utf8());
2378 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2382 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2379 strcpy(entry[j++], si->text(0).utf8()); 2383 strcpy(entry[j++], si->text(0).utf8());
2380 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2384 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2381 strcpy(entry[j++], si->text(1).utf8()); 2385 strcpy(entry[j++], si->text(1).utf8());
2382 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2386 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2383 strcpy(entry[j++], si->text(2).utf8()); 2387 strcpy(entry[j++], si->text(2).utf8());
2384 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2388 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2385 strcpy(entry[j++], si->text(3).utf8()); 2389 strcpy(entry[j++], si->text(3).utf8());
2386 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2390 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2387 strcpy(entry[j++], si->text(4).utf8()); 2391 strcpy(entry[j++], si->text(4).utf8());
2388 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2392 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2389 strcpy(entry[j++], si->text(5).utf8()); 2393 strcpy(entry[j++], si->text(5).utf8());
2390 2394
2391 retval = saveEntry(entry); 2395 retval = saveEntry(entry);
2392 for (int z=0; z<j; z++) 2396 for (int z=0; z<j; z++)
2393 { 2397 {
2394 free(entry[z]); 2398 free(entry[z]);
2395 } 2399 }
2396 if (retval == PWERR_DATA) { 2400 if (retval == PWERR_DATA) {
2397#ifndef NO_OPIE 2401#ifndef NO_OPIE
2398 owarn << "1: Error writing file, contents not saved" << oendl; 2402 owarn << "1: Error writing file, contents not saved" << oendl;
2399#else 2403#else
2400 qWarning("1: Error writing file, contents not saved"); 2404 qWarning("1: Error writing file, contents not saved");
2401#endif 2405#endif
2402 saveFinalize(); 2406 saveFinalize();
2403 return false; 2407 return false;
2404 } 2408 }
2405 2409
2406 } 2410 }
2407 } 2411 }
2408 2412
2409 if (saveFinalize() == PWERR_DATA) { 2413 if (saveFinalize() == PWERR_DATA) {
2410#ifndef NO_OPIE 2414#ifndef NO_OPIE
2411 owarn << "2: Error writing file, contents not saved" << oendl; 2415 owarn << "2: Error writing file, contents not saved" << oendl;
2412#else 2416#else
2413 qWarning("2: Error writing file, contents not saved"); 2417 qWarning("2: Error writing file, contents not saved");
2414#endif 2418#endif
2415 return false; 2419 return false;
2416 } else { 2420 } else {
2417#ifndef DESKTOP 2421#ifndef DESKTOP
2418 Global::statusMessage (tr("Password file saved.")); 2422 Global::statusMessage (tr("Password file saved."));
2419#endif 2423#endif
2420 modified = false; 2424 modified = false;
2421 return true; 2425 return true;
2422 } 2426 }
2423} 2427}
2424 2428
2425PasswordForm *newPwdDialog; 2429PasswordForm *newPwdDialog;
2426bool newPwdDialogResult = false; 2430bool newPwdDialogResult = false;
2427void ZSafe::setPasswordDialogDone() 2431void ZSafe::setPasswordDialogDone()
2428{ 2432{
2429 newPwdDialogResult = true; 2433 newPwdDialogResult = true;
2430 newPwdDialog->close(); 2434 newPwdDialog->close();
2431} 2435}
2432 2436
2433void ZSafe::getDocPassword(QString title) 2437void ZSafe::getDocPassword(QString title)
2434{ 2438{
2435#ifndef NO_OPIE 2439#ifndef NO_OPIE
2436 owarn << "getDocPassword" << oendl; 2440 owarn << "getDocPassword" << oendl;
2437#endif 2441#endif
2438 // open the 'Password' dialog 2442 // open the 'Password' dialog
2439 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2443 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2440 newPwdDialog = dialog; 2444 newPwdDialog = dialog;
2441 newPwdDialogResult = false; 2445 newPwdDialogResult = false;
2442 2446
2443 QPixmap image0( ( const char** ) zsafe_xpm ); 2447 QPixmap image0( ( const char** ) zsafe_xpm );
2444 dialog->setIcon( image0); 2448 dialog->setIcon( image0);
2445 2449
2446 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2450 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2447 this, SLOT( setPasswordDialogDone() ) ); 2451 this, SLOT( setPasswordDialogDone() ) );
2448 2452
2449 // CS: !!! 2453 // CS: !!!
2450 // int pos = filename.findRev ('/'); 2454 // int pos = filename.findRev ('/');
2451 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2455 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2452#ifdef Q_WS_WIN 2456#ifdef Q_WS_WIN
2453 dialog->setCaption("Qt " + ti); 2457 dialog->setCaption("Qt " + ti);
2454#else 2458#else
2455 dialog->setCaption(ti); 2459 dialog->setCaption(ti);
2456#endif 2460#endif
2457 // dialog->setCaption(title); 2461 // dialog->setCaption(title);
2458 2462
2459 dialog->PasswordField->setFocus(); 2463 dialog->PasswordField->setFocus();
2460 DialogCode result = (DialogCode) dialog->exec(); 2464 DialogCode result = (DialogCode) dialog->exec();
2461#ifdef DESKTOP 2465#ifdef DESKTOP
2462 result = Accepted; 2466 result = Accepted;
2463#endif 2467#endif
2464 2468
2465 QString password; 2469 QString password;
2466 if (result == Accepted || newPwdDialogResult) 2470 if (result == Accepted || newPwdDialogResult)
2467 { 2471 {
2468 m_password = dialog->PasswordField->text(); 2472 m_password = dialog->PasswordField->text();
2469 } 2473 }
2470 else 2474 else
2471 { 2475 {
2472 exitZs (1); 2476 exitZs (1);
2473 } 2477 }
2474} 2478}
2475 2479
2476int ZSafe::saveInit(const char *_filename, const char *password) 2480int ZSafe::saveInit(const char *_filename, const char *password)
2477{ 2481{
2478 char key[128]; 2482 char key[128];
2479 unsigned int j = 0; 2483 unsigned int j = 0;
2480 unsigned int keylength; 2484 unsigned int keylength;
2481 // int val; 2485 // int val;
2482 int count2; 2486 int count2;
2483 Krc2* krc2 = new Krc2(); 2487 Krc2* krc2 = new Krc2();
2484 2488
2485 /* first we should check the permissions of the filename */ 2489 /* first we should check the permissions of the filename */
2486/* 2490/*
2487 if (QFile::exists(_filename)) { 2491 if (QFile::exists(_filename)) {
2488 val = checkFile(_filename); 2492 val = checkFile(_filename);
2489 if (val != PWERR_GOOD) 2493 if (val != PWERR_GOOD)
2490 return val; 2494 return val;
2491 } else 2495 } else
2492 { 2496 {
2493 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2497 val = creat (_filename, (S_IRUSR | S_IWUSR));
2494 if (val == -1) 2498 if (val == -1)
2495 return PWERR_OPEN; 2499 return PWERR_OPEN;
2496 else 2500 else
2497 close(val); 2501 close(val);
2498 } 2502 }
2499*/ 2503*/
2500 QFileInfo f (_filename); 2504 QFileInfo f (_filename);
2501 save_buffer_length = f.size(); 2505 save_buffer_length = f.size();
2502 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2506 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2503 2507
2504 fd = fopen (_filename, "wb"); 2508 fd = fopen (_filename, "wb");
2505 if (fd == NULL) 2509 if (fd == NULL)
2506 return PWERR_OPEN; 2510 return PWERR_OPEN;
2507 2511
2508 buffer = (char*)malloc(save_buffer_length); 2512 buffer = (char*)malloc(save_buffer_length);
2509 2513
2510 /* make the key ready */ 2514 /* make the key ready */
2511 for (j = 0; password[j] != '\0'; j++) { 2515 for (j = 0; password[j] != '\0'; j++) {
2512 key[j] = password[j]; 2516 key[j] = password[j];
2513 } 2517 }
2514 keylength = j; 2518 keylength = j;
2515 krc2->rc2_expandkey (key, keylength, 128); 2519 krc2->rc2_expandkey (key, keylength, 128);
2516 2520
2517 /* First, we make the IV */ 2521 /* First, we make the IV */
2518 for (count2 = 0; count2 < 4; count2++) { 2522 for (count2 = 0; count2 < 4; count2++) {
2519 iv[count2] = rand (); 2523 iv[count2] = rand ();
2520 putc ((unsigned char) (iv[count2] >> 8), fd); 2524 putc ((unsigned char) (iv[count2] >> 8), fd);
2521 putc ((unsigned char) (iv[count2] & 0xff), fd); 2525 putc ((unsigned char) (iv[count2] & 0xff), fd);
2522 } 2526 }
2523 2527
2524 bufferIndex = 0; 2528 bufferIndex = 0;
2525 return PWERR_GOOD; 2529 return PWERR_GOOD;
2526} 2530}
2527 2531
2528 2532
2529int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2533int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2530{ 2534{
2531 char *text1; 2535 char *text1;
2532 int count2, count3; 2536 int count2, count3;
2533 unsigned short ciphertext[4]; 2537 unsigned short ciphertext[4];
2534 Krc2* krc2 = new Krc2(); 2538 Krc2* krc2 = new Krc2();
2535 2539
2536 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2540 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2537 2541
2538 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2542 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2539 text1 = entry[count2]; 2543 text1 = entry[count2];
2540 if (strlen (text1) == 0) { 2544 if (strlen (text1) == 0) {
2541 strncat(buffer, " ", strlen(" ")); 2545 strncat(buffer, " ", strlen(" "));
2542 } else { 2546 } else {
2543 strncat(buffer, text1, strlen(text1)); 2547 strncat(buffer, text1, strlen(text1));
2544 } 2548 }
2545 /* Use 255 as the marker. \n is too tough to test for */ 2549 /* Use 255 as the marker. \n is too tough to test for */
2546 buffer[strlen (buffer)] = 255; 2550 buffer[strlen (buffer)] = 255;
2547 } /*for (count2 = 0; count2 < 5; count2++)*/ 2551 } /*for (count2 = 0; count2 < 5; count2++)*/
2548 count2 = 0; 2552 count2 = 0;
2549 /* I'm using CBC mode and encrypting the data straight from top down. 2553 /* I'm using CBC mode and encrypting the data straight from top down.
2550 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2554 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2551 * PKCS 5 padding (explained at the code section 2555 * PKCS 5 padding (explained at the code section
2552 */ 2556 */
2553 while (count2 < (int)strlen (buffer)) { 2557 while (count2 < (int)strlen (buffer)) {
2554#ifndef WORDS_BIGENDIAN 2558#ifndef WORDS_BIGENDIAN
2555 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2559 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2556 plaintext[bufferIndex] += buffer[count2] & 0xff; 2560 plaintext[bufferIndex] += buffer[count2] & 0xff;
2557#endif 2561#endif
2558#ifdef WORDS_BIGENDIAN 2562#ifdef WORDS_BIGENDIAN
2559 plaintext[bufferIndex] = buffer[count2] << 8; 2563 plaintext[bufferIndex] = buffer[count2] << 8;
2560 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2564 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2561#endif 2565#endif
2562 bufferIndex++; 2566 bufferIndex++;
2563 if (bufferIndex == 4) { 2567 if (bufferIndex == 4) {
2564 krc2->rc2_encrypt (plaintext); 2568 krc2->rc2_encrypt (plaintext);
2565 2569
2566 for (count3 = 0; count3 < 4; count3++) { 2570 for (count3 = 0; count3 < 4; count3++) {
2567 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2571 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2568 2572
2569 /* Now store the ciphertext as the iv */ 2573 /* Now store the ciphertext as the iv */
2570 iv[count3] = plaintext[count3]; 2574 iv[count3] = plaintext[count3];
2571 2575
2572 /* reset the buffer index */ 2576 /* reset the buffer index */
2573 bufferIndex = 0; 2577 bufferIndex = 0;
2574 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2578 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2575 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2579 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2576 } /*for (count3 = 0; count3 < 5; count3++)*/ 2580 } /*for (count3 = 0; count3 < 5; count3++)*/
2577 } /*if (bufferIndex == 5)*/ 2581 } /*if (bufferIndex == 5)*/
2578 /* increment a short, not a byte */ 2582 /* increment a short, not a byte */
2579 count2 += 2; 2583 count2 += 2;
2580 } /*while (count2 < strlen (buffer))*/ 2584 } /*while (count2 < strlen (buffer))*/
2581 int ret = PWERR_GOOD; 2585 int ret = PWERR_GOOD;
2582 return ret; 2586 return ret;
2583} 2587}
2584 2588
2585int ZSafe::saveFinalize(void) 2589int ZSafe::saveFinalize(void)
2586{ 2590{
2587 int count1, retval = PWERR_GOOD; 2591 int count1, retval = PWERR_GOOD;
2588 unsigned short ciphertext[4]; 2592 unsigned short ciphertext[4];
2589 Krc2* krc2 = new Krc2(); 2593 Krc2* krc2 = new Krc2();
2590 2594
2591 /* Tack on the PKCS 5 padding 2595 /* Tack on the PKCS 5 padding
2592 * How it works is we fill up the last n bytes with the value n 2596 * How it works is we fill up the last n bytes with the value n
2593 * 2597 *
2594 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2598 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2595 * over, leaving us 3 short, so we fill it in with 3's. 2599 * over, leaving us 3 short, so we fill it in with 3's.
2596 * 2600 *
2597 * If we come out even, we fill it with 8 8s 2601 * If we come out even, we fill it with 8 8s
2598 * 2602 *
2599 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2603 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2600 * so, half everything 2604 * so, half everything
2601 */ 2605 */
2602 for (count1 = bufferIndex; count1 < 4; count1++) { 2606 for (count1 = bufferIndex; count1 < 4; count1++) {
2603 plaintext[count1] = (4 - bufferIndex); 2607 plaintext[count1] = (4 - bufferIndex);
2604 } 2608 }
2605 krc2->rc2_encrypt (plaintext); 2609 krc2->rc2_encrypt (plaintext);
2606 for (count1 = 0; count1 < 4; count1++) { 2610 for (count1 = 0; count1 < 4; count1++) {
2607 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2611 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2608 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2612 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2609 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2613 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2610 } 2614 }
2611 2615
2612 fclose (fd); 2616 fclose (fd);
2613 free(buffer); 2617 free(buffer);
2614 return retval; 2618 return retval;
2615} 2619}
2616 2620
2617void ZSafe::quitMe () 2621void ZSafe::quitMe ()
2618{ 2622{
2619#ifndef NO_OPIE 2623#ifndef NO_OPIE
2620 owarn << "QUIT..." << oendl; 2624 owarn << "QUIT..." << oendl;
2621#endif 2625#endif
2622 2626
2623 if (modified) 2627 if (modified)
2624 { 2628 {
2625 switch( QMessageBox::information( this, tr("ZSafe"), 2629 switch( QMessageBox::information( this, tr("ZSafe"),
2626 tr("Do you want to save\nbefore exiting?"), 2630 tr("Do you want to save\nbefore exiting?"),
2627 tr("&Save"), 2631 tr("&Save"),
2628 tr("S&ave with\nnew\npassword"), 2632 tr("S&ave with\nnew\npassword"),
2629 tr("&Don't Save"), 2633 tr("&Don't Save"),
2630 0 // Enter == button 0 2634 0 // Enter == button 0
2631 ) ) 2635 ) )
2632 { // Escape == button 2 2636 { // Escape == button 2
2633 case 0: // Save clicked, Alt-S or Enter pressed. 2637 case 0: // Save clicked, Alt-S or Enter pressed.
2634 // save 2638 // save
2635 modified = false; 2639 modified = false;
2636 saveDocument(filename, FALSE); 2640 saveDocument(filename, FALSE);
2637 exitZs (1); 2641 exitZs (1);
2638 break; 2642 break;
2639 case 1: // 2643 case 1: //
2640 // Save with new password 2644 // Save with new password
2641 modified = false; 2645 modified = false;
2642 saveDocument(filename, TRUE); 2646 saveDocument(filename, TRUE);
2643 exitZs (1); 2647 exitZs (1);
2644 break; 2648 break;
2645 case 2: // Don't Save clicked or Alt-D pressed 2649 case 2: // Don't Save clicked or Alt-D pressed
2646 // don't save but exitZs 2650 // don't save but exitZs
2647 exitZs (1); 2651 exitZs (1);
2648 break; 2652 break;
2649 } 2653 }
2650 } 2654 }
2651 exitZs (1); 2655 exitZs (1);
2652 2656
2653} 2657}
2654 2658
2655void ZSafe::categoryFieldActivated( const QString& category) 2659void ZSafe::categoryFieldActivated( const QString& category)
2656{ 2660{
2657 if (categoryDialog) 2661 if (categoryDialog)
2658 setCategoryDialogFields(categoryDialog, category); 2662 setCategoryDialogFields(categoryDialog, category);
2659} 2663}
2660 2664
2661void ZSafe::addCategory() 2665void ZSafe::addCategory()
2662{ 2666{
2663 if (filename.isEmpty()) 2667 if (filename.isEmpty())
2664 { 2668 {
2665 QMessageBox::critical( 0, tr("ZSafe"), 2669 QMessageBox::critical( 0, tr("ZSafe"),
2666 tr("No document defined.\nYou have to create a new document")); 2670 tr("No document defined.\nYou have to create a new document"));
2667 return; 2671 return;
2668 } 2672 }
2669 else 2673 else
2670 { 2674 {
2671 // open the 'Category' dialog 2675 // open the 'Category' dialog
2672 bool initIcons = false; 2676 bool initIcons = false;
2673 // open the 'Category' dialog 2677 // open the 'Category' dialog
2674 CategoryDialog *dialog; 2678 CategoryDialog *dialog;
2675 if (categoryDialog) 2679 if (categoryDialog)
2676 { 2680 {
2677 dialog = categoryDialog; 2681 dialog = categoryDialog;
2678 } 2682 }
2679 else 2683 else
2680 { 2684 {
2681 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2685 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2682#ifdef Q_WS_WIN 2686#ifdef Q_WS_WIN
2683 categoryDialog->setCaption ("Qt " + tr("Category")); 2687 categoryDialog->setCaption ("Qt " + tr("Category"));
2684#endif 2688#endif
2685 dialog = categoryDialog; 2689 dialog = categoryDialog;
2686 connect( dialog->CategoryField, 2690 connect( dialog->CategoryField,
2687 SIGNAL( activated(const QString&)), 2691 SIGNAL( activated(const QString&)),
2688 this, SLOT( categoryFieldActivated(const QString&) ) ); 2692 this, SLOT( categoryFieldActivated(const QString&) ) );
2689 initIcons = true; 2693 initIcons = true;
2690 } 2694 }
2691 2695
2692#ifdef DESKTOP 2696#ifdef DESKTOP
2693#ifndef Q_WS_WIN 2697#ifndef Q_WS_WIN
2694 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2698 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2695#else 2699#else
2696 // read all categories from the config file and store 2700 // read all categories from the config file and store
2697 // into a list 2701 // into a list
2698 QFile f (cfgFile); 2702 QFile f (cfgFile);
2699 QStringList list; 2703 QStringList list;
2700 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2704 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2701 QTextStream t( &f ); // use a text stream 2705 QTextStream t( &f ); // use a text stream
2702 QString s; 2706 QString s;
2703 int n = 1; 2707 int n = 1;
2704 while ( !t.eof() ) { // until end of file... 2708 while ( !t.eof() ) { // until end of file...
2705 s = t.readLine(); // line of text excluding '\n' 2709 s = t.readLine(); // line of text excluding '\n'
2706 list.append(s); 2710 list.append(s);
2707 } 2711 }
2708 f.close(); 2712 f.close();
2709 } 2713 }
2710#endif 2714#endif
2711#else 2715#else
2712 // read all categories from the config file and store 2716 // read all categories from the config file and store
2713 // into a list 2717 // into a list
2714 QFile f (cfgFile); 2718 QFile f (cfgFile);
2715 QStringList list; 2719 QStringList list;
2716 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2720 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2717 QTextStream t( &f ); // use a text stream 2721 QTextStream t( &f ); // use a text stream
2718 QString s; 2722 QString s;
2719 while ( !t.eof() ) { // until end of file... 2723 while ( !t.eof() ) { // until end of file...
2720 s = t.readLine(); // line of text excluding '\n' 2724 s = t.readLine(); // line of text excluding '\n'
2721 list.append(s); 2725 list.append(s);
2722 } 2726 }
2723 f.close(); 2727 f.close();
2724 } 2728 }
2725#endif 2729#endif
2726 QStringList::Iterator it = list.begin(); 2730 QStringList::Iterator it = list.begin();
2727 QString categ; 2731 QString categ;
2728 QString firstCategory; 2732 QString firstCategory;
2729 dialog->CategoryField->clear(); // remove all items 2733 dialog->CategoryField->clear(); // remove all items
2730 while( it != list.end() ) 2734 while( it != list.end() )
2731 { 2735 {
2732 QString *cat = new QString (*it); 2736 QString *cat = new QString (*it);
2733 if (cat->contains("-field1", FALSE)) 2737 if (cat->contains("-field1", FALSE))
2734 { 2738 {
2735#ifdef DESKTOP 2739#ifdef DESKTOP
2736#ifndef Q_WS_WIN 2740#ifndef Q_WS_WIN
2737 categ = cat->section ("-field1", 0, 0); 2741 categ = cat->section ("-field1", 0, 0);
2738#else 2742#else
2739 int pos = cat->find ("-field1"); 2743 int pos = cat->find ("-field1");
2740 categ = cat->left (pos); 2744 categ = cat->left (pos);
2741#endif 2745#endif
2742#else 2746#else
2743 int pos = cat->find ("-field1"); 2747 int pos = cat->find ("-field1");
2744 cat->truncate(pos); 2748 cat->truncate(pos);
2745 categ = *cat; 2749 categ = *cat;
2746#endif 2750#endif
2747 if (!categ.isEmpty()) 2751 if (!categ.isEmpty())
2748 { 2752 {
2749 dialog->CategoryField->insertItem (categ, -1); 2753 dialog->CategoryField->insertItem (categ, -1);
2750 if (firstCategory.isEmpty()) 2754 if (firstCategory.isEmpty())
2751 firstCategory = categ; 2755 firstCategory = categ;
2752 } 2756 }
2753 } 2757 }
2754 ++it; 2758 ++it;
2755 } 2759 }
2756 2760
2757 2761
2758 if (firstCategory.isEmpty()) 2762 if (firstCategory.isEmpty())
2759 setCategoryDialogFields(dialog); 2763 setCategoryDialogFields(dialog);
2760 else 2764 else
2761 setCategoryDialogFields(dialog, firstCategory); 2765 setCategoryDialogFields(dialog, firstCategory);
2762 2766
2763 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2767 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2764 2768
2765 if (initIcons) 2769 if (initIcons)
2766 { 2770 {
2767 Wait waitDialog(this, tr("Wait dialog")); 2771 Wait waitDialog(this, tr("Wait dialog"));
2768 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2772 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2769 waitDialog.show(); 2773 waitDialog.show();
2770 qApp->processEvents(); 2774 qApp->processEvents();
2771 2775
2772#ifdef DESKTOP 2776#ifdef DESKTOP
2773 QDir d(iconPath); 2777 QDir d(iconPath);
2774#else 2778#else
2775 QDir d(QPEApplication::qpeDir() + "/pics/"); 2779 QDir d(QPEApplication::qpeDir() + "/pics/");
2776#endif 2780#endif
2777 d.setFilter( QDir::Files); 2781 d.setFilter( QDir::Files);
2778 2782
2779 const QFileInfoList *list = d.entryInfoList(); 2783 const QFileInfoList *list = d.entryInfoList();
2780 QFileInfoListIterator it( *list ); // create list iterator 2784 QFileInfoListIterator it( *list ); // create list iterator
2781 QFileInfo *fi; // pointer for traversing 2785 QFileInfo *fi; // pointer for traversing
2782 2786
2783 dialog->IconField->insertItem("predefined"); 2787 dialog->IconField->insertItem("predefined");
2784 while ( (fi=it.current()) ) { // for each file... 2788 while ( (fi=it.current()) ) { // for each file...
2785 QString fileName = fi->fileName(); 2789 QString fileName = fi->fileName();
2786 if(fileName.right(4) == ".png"){ 2790 if(fileName.right(4) == ".png"){
2787 fileName = fileName.mid(0,fileName.length()-4); 2791 fileName = fileName.mid(0,fileName.length()-4);
2788#ifdef DESKTOP 2792#ifdef DESKTOP
2789 QPixmap imageOfFile; 2793 QPixmap imageOfFile;
2790 imageOfFile.load(iconPath + fi->fileName()); 2794 imageOfFile.load(iconPath + fi->fileName());
2791#else 2795#else
2792 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2796 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2793#endif 2797#endif
2794 QImage foo = imageOfFile.convertToImage(); 2798 QImage foo = imageOfFile.convertToImage();
2795 foo = foo.smoothScale(16,16); 2799 foo = foo.smoothScale(16,16);
2796 imageOfFile.convertFromImage(foo); 2800 imageOfFile.convertFromImage(foo);
2797 dialog->IconField->insertItem(imageOfFile,fileName); 2801 dialog->IconField->insertItem(imageOfFile,fileName);
2798 } 2802 }
2799 ++it; 2803 ++it;
2800 } 2804 }
2801 waitDialog.hide(); 2805 waitDialog.hide();
2802 } 2806 }
2803 2807
2804#ifndef Q_WS_WIN 2808#ifndef Q_WS_WIN
2805 dialog->show(); 2809 dialog->show();
2806#endif 2810#endif
2807#ifndef DESKTOP 2811#ifndef DESKTOP
2808 // dialog->move (20, 100); 2812 // dialog->move (20, 100);
2809#endif 2813#endif
2810 DialogCode result = (DialogCode) dialog->exec(); 2814 DialogCode result = (DialogCode) dialog->exec();
2811#ifdef DESKTOP 2815#ifdef DESKTOP
2812 result = Accepted; 2816 result = Accepted;
2813#endif 2817#endif
2814 2818
2815 QString category; 2819 QString category;
2816 QString icon; 2820 QString icon;
2817 QString fullIconPath; 2821 QString fullIconPath;
2818 QPixmap *pix; 2822 QPixmap *pix;
2819 if (result == Accepted) 2823 if (result == Accepted)
2820 { 2824 {
2821 modified = true; 2825 modified = true;
2822 category = dialog->CategoryField->currentText(); 2826 category = dialog->CategoryField->currentText();
2823 icon = dialog->IconField->currentText()+".png"; 2827 icon = dialog->IconField->currentText()+".png";
2824 2828
2825#ifndef NO_OPIE 2829#ifndef NO_OPIE
2826 owarn << category << oendl; 2830 owarn << category << oendl;
2827#endif 2831#endif
2828 2832
2829 QListViewItem *li = new ShadedListItem( 1, ListView ); 2833 QListViewItem *li = new ShadedListItem( 1, ListView );
2830 Category *c1 = new Category(); 2834 Category *c1 = new Category();
2831 c1->setCategoryName(category); 2835 c1->setCategoryName(category);
2832 2836
2833 // if (!icon.isEmpty() && !icon.isNull()) 2837 // if (!icon.isEmpty() && !icon.isNull())
2834 if (icon != "predefined.png") 2838 if (icon != "predefined.png")
2835 { 2839 {
2836 // build the full path 2840 // build the full path
2837 fullIconPath = iconPath + icon; 2841 fullIconPath = iconPath + icon;
2838 pix = new QPixmap (fullIconPath); 2842 pix = new QPixmap (fullIconPath);
2839 // pix->resize(14, 14); 2843 // pix->resize(14, 14);
2840 if (!pix->isNull()) 2844 if (!pix->isNull())
2841 { 2845 {
2842 // save the full pixmap name into the config file 2846 // save the full pixmap name into the config file
2843// #ifndef Q_WS_WIN 2847// #ifndef Q_WS_WIN
2844 conf->writeEntry(APP_KEY+category, icon); 2848 conf->writeEntry(APP_KEY+category, icon);
2845// #endif 2849// #endif
2846 saveConf(); 2850 saveConf();
2847 QImage img = pix->convertToImage(); 2851 QImage img = pix->convertToImage();
2848 pix->convertFromImage(img.smoothScale(14,14)); 2852 pix->convertFromImage(img.smoothScale(14,14));
2849 c1->setIcon (*pix); 2853 c1->setIcon (*pix);
2850 c1->setIconName(icon); 2854 c1->setIconName(icon);
2851 } 2855 }
2852 else 2856 else
2853 { 2857 {
2854 QPixmap folder( ( const char** ) general_data ); 2858 QPixmap folder( ( const char** ) general_data );
2855 c1->setIcon (folder); 2859 c1->setIcon (folder);
2856 } 2860 }
2857 } 2861 }
2858 else 2862 else
2859 { 2863 {
2860 c1->setIcon (*getPredefinedIcon(category)); 2864 c1->setIcon (*getPredefinedIcon(category));
2861 } 2865 }
2862 2866
2863 c1->setListItem (li); 2867 c1->setListItem (li);
2864 c1->initListItem(); 2868 c1->initListItem();
2865 categories.insert (c1->getCategoryName(), c1); 2869 categories.insert (c1->getCategoryName(), c1);
2866 2870
2867 saveCategoryDialogFields(dialog); 2871 saveCategoryDialogFields(dialog);
2868 } 2872 }
2869 else 2873 else
2870 { 2874 {
2871 // delete dialog; 2875 // delete dialog;
2872 dialog->hide(); 2876 dialog->hide();
2873 return; 2877 return;
2874 } 2878 }
2875 2879
2876 } 2880 }
2877 2881
2878} 2882}
2879 2883
2880void ZSafe::delCategory() 2884void ZSafe::delCategory()
2881{ 2885{
2882 if (!selectedItem) 2886 if (!selectedItem)
2883 return; 2887 return;
2884 if (isCategory(selectedItem)) 2888 if (isCategory(selectedItem))
2885 { 2889 {
2886 switch( QMessageBox::information( this, tr("ZSafe"), 2890 switch( QMessageBox::information( this, tr("ZSafe"),
2887 tr("Do you want to delete?"), 2891 tr("Do you want to delete?"),
2888 tr("&Delete"), tr("D&on't Delete"), 2892 tr("&Delete"), tr("D&on't Delete"),
2889 0 // Enter == button 0 2893 0 // Enter == button 0
2890 ) ) { // Escape == button 2 2894 ) ) { // Escape == button 2
2891 case 0: // Delete clicked, Alt-S or Enter pressed. 2895 case 0: // Delete clicked, Alt-S or Enter pressed.
2892 // Delete from the category list 2896 // Delete from the category list
2893 modified = true; 2897 modified = true;
2894 categories.remove (selectedItem->text(0)); 2898 categories.remove (selectedItem->text(0));
2895// #ifndef Q_WS_WIN 2899// #ifndef Q_WS_WIN
2896 conf->removeEntry (selectedItem->text(0)); 2900 conf->removeEntry (selectedItem->text(0));
2897// #endif 2901// #endif
2898 saveConf(); 2902 saveConf();
2899 2903
2900 // Delete the selected item and all subitems 2904 // Delete the selected item and all subitems
2901 // step through all subitems 2905 // step through all subitems
2902 QListViewItem *si; 2906 QListViewItem *si;
2903 for (si = selectedItem->firstChild(); 2907 for (si = selectedItem->firstChild();
2904 si != NULL; ) 2908 si != NULL; )
2905 { 2909 {
2906 QListViewItem *_si = si; 2910 QListViewItem *_si = si;
2907 si = si->nextSibling(); 2911 si = si->nextSibling();
2908 selectedItem->takeItem(_si); // remove from view list 2912 selectedItem->takeItem(_si); // remove from view list
2909 if (_si) delete _si; 2913 if (_si) delete _si;
2910 } 2914 }
2911 ListView->takeItem(selectedItem); 2915 ListView->takeItem(selectedItem);
2912 delete selectedItem; 2916 delete selectedItem;
2913 2917
2914 selectedItem = NULL; 2918 selectedItem = NULL;
2915 break; 2919 break;
2916 case 1: // Don't delete 2920 case 1: // Don't delete
2917 break; 2921 break;
2918 } 2922 }
2919 2923
2920 } 2924 }
2921} 2925}
2922 2926
2923void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2927void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2924{ 2928{
2925 if (!dialog) 2929 if (!dialog)
2926 return; 2930 return;
2927 2931
2928 QString icon; 2932 QString icon;
2929 if (selectedItem) 2933 if (selectedItem)
2930 { 2934 {
2931 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2935 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2932 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2936 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2933 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2937 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2934 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2938 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2935 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2939 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2936 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2940 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2937 2941
2938 Category *cat= categories.find (selectedItem->text(0)); 2942 Category *cat= categories.find (selectedItem->text(0));
2939 if (cat) 2943 if (cat)
2940 { 2944 {
2941 icon = cat->getIconName(); 2945 icon = cat->getIconName();
2942 } 2946 }
2943 else 2947 else
2944 icon = conf->readEntry(APP_KEY+selectedItem->text(0)); 2948 icon = conf->readEntry(APP_KEY+selectedItem->text(0));
2945 } 2949 }
2946 else 2950 else
2947 { 2951 {
2948 dialog->Field1->setText(tr("Name")); 2952 dialog->Field1->setText(tr("Name"));
2949 dialog->Field2->setText(tr("Username")); 2953 dialog->Field2->setText(tr("Username"));
2950 dialog->Field3->setText(tr("Password")); 2954 dialog->Field3->setText(tr("Password"));
2951 dialog->Field4->setText(tr("Comment")); 2955 dialog->Field4->setText(tr("Comment"));
2952 dialog->Field5->setText(tr("Field 4")); 2956 dialog->Field5->setText(tr("Field 4"));
2953 dialog->Field6->setText(tr("Field 5")); 2957 dialog->Field6->setText(tr("Field 5"));
2954 } 2958 }
2955 2959
2956#ifdef DESKTOP 2960#ifdef DESKTOP
2957 QDir d(iconPath); 2961 QDir d(iconPath);
2958#else 2962#else
2959 QDir d(QPEApplication::qpeDir() + "/pics/"); 2963 QDir d(QPEApplication::qpeDir() + "/pics/");
2960#endif 2964#endif
2961 d.setFilter( QDir::Files); 2965 d.setFilter( QDir::Files);
2962 2966
2963 const QFileInfoList *list = d.entryInfoList(); 2967 const QFileInfoList *list = d.entryInfoList();
2964 int i=0; 2968 int i=0;
2965 QFileInfoListIterator it( *list ); // create list iterator 2969 QFileInfoListIterator it( *list ); // create list iterator
2966 QFileInfo *fi; // pointer for traversing 2970 QFileInfo *fi; // pointer for traversing
2967 if (icon.isEmpty() || icon.isNull()) 2971 if (icon.isEmpty() || icon.isNull())
2968 { 2972 {
2969 dialog->IconField->setCurrentItem(0); 2973 dialog->IconField->setCurrentItem(0);
2970 } 2974 }
2971 else 2975 else
2972 { 2976 {
2973 while ( (fi=it.current()) ) 2977 while ( (fi=it.current()) )
2974 { // for each file... 2978 { // for each file...
2975 QString fileName = fi->fileName(); 2979 QString fileName = fi->fileName();
2976 if(fileName.right(4) == ".png") 2980 if(fileName.right(4) == ".png")
2977 { 2981 {
2978 fileName = fileName.mid(0,fileName.length()-4); 2982 fileName = fileName.mid(0,fileName.length()-4);
2979 2983
2980 if(fileName+".png"==icon) 2984 if(fileName+".png"==icon)
2981 { 2985 {
2982 dialog->IconField->setCurrentItem(i+1); 2986 dialog->IconField->setCurrentItem(i+1);
2983 break; 2987 break;
2984 } 2988 }
2985 ++i; 2989 ++i;
2986 } 2990 }
2987 ++it; 2991 ++it;
2988 } 2992 }
2989 } 2993 }
2990} 2994}
2991 2995
2992void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2996void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2993{ 2997{
2994 if (!dialog) 2998 if (!dialog)
2995 return; 2999 return;
2996 3000
2997 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 3001 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
2998 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 3002 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
2999 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 3003 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
3000 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 3004 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
3001 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 3005 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
3002 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 3006 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
3003 3007
3004 QString icon; 3008 QString icon;
3005 Category *cat= categories.find (category); 3009 Category *cat= categories.find (category);
3006 if (cat) 3010 if (cat)
3007 { 3011 {
3008 icon = cat->getIconName(); 3012 icon = cat->getIconName();
3009 } 3013 }
3010 else 3014 else
3011 icon = conf->readEntry(APP_KEY+category); 3015 icon = conf->readEntry(APP_KEY+category);
3012 3016
3013#ifdef DESKTOP 3017#ifdef DESKTOP
3014 QDir d(iconPath); 3018 QDir d(iconPath);
3015#else 3019#else
3016 QDir d(QPEApplication::qpeDir() + "/pics/"); 3020 QDir d(QPEApplication::qpeDir() + "/pics/");
3017#endif 3021#endif
3018 d.setFilter( QDir::Files); 3022 d.setFilter( QDir::Files);
3019 3023
3020 const QFileInfoList *list = d.entryInfoList(); 3024 const QFileInfoList *list = d.entryInfoList();
3021 int i=0; 3025 int i=0;
3022 QFileInfoListIterator it( *list ); // create list iterator 3026 QFileInfoListIterator it( *list ); // create list iterator
3023 QFileInfo *fi; // pointer for traversing 3027 QFileInfo *fi; // pointer for traversing
3024 if (icon.isEmpty() || icon.isNull()) 3028 if (icon.isEmpty() || icon.isNull())
3025 { 3029 {
3026 dialog->IconField->setCurrentItem(0); 3030 dialog->IconField->setCurrentItem(0);
3027 } 3031 }
3028 else 3032 else
3029 { 3033 {
3030 while ( (fi=it.current()) ) 3034 while ( (fi=it.current()) )
3031 { // for each file... 3035 { // for each file...
3032 QString fileName = fi->fileName(); 3036 QString fileName = fi->fileName();
3033 if(fileName.right(4) == ".png") 3037 if(fileName.right(4) == ".png")
3034 { 3038 {
3035 fileName = fileName.mid(0,fileName.length()-4); 3039 fileName = fileName.mid(0,fileName.length()-4);
3036 3040
3037 if(fileName+".png"==icon) 3041 if(fileName+".png"==icon)
3038 { 3042 {
3039 dialog->IconField->setCurrentItem(i+1); 3043 dialog->IconField->setCurrentItem(i+1);
3040 break; 3044 break;
3041 } 3045 }
3042 ++i; 3046 ++i;
3043 } 3047 }
3044 ++it; 3048 ++it;
3045 } 3049 }
3046 } 3050 }
3047} 3051}
3048 3052
3049void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 3053void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
3050{ 3054{
3051 QString app_key = APP_KEY; 3055 QString app_key = APP_KEY;
3052#ifndef DESKTOP 3056#ifndef DESKTOP
3053 conf->setGroup ("fieldDefs"); 3057 conf->setGroup ("fieldDefs");
3054#else 3058#else
3055#ifndef Q_WS_WIN 3059#ifndef Q_WS_WIN
3056 app_key += "/fieldDefs/"; 3060 app_key += "/fieldDefs/";
3057#endif 3061#endif
3058#endif 3062#endif
3059 QString category = dialog->CategoryField->currentText(); 3063 QString category = dialog->CategoryField->currentText();
3060// #ifndef Q_WS_WIN 3064// #ifndef Q_WS_WIN
3061 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 3065 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
3062 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 3066 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
3063 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 3067 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
3064 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 3068 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
3065 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 3069 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
3066 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 3070 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
3067// #endif 3071// #endif
3068 saveConf(); 3072 saveConf();
3069#ifndef DESKTOP 3073#ifndef DESKTOP
3070 conf->setGroup ("zsafe"); 3074 conf->setGroup ("zsafe");
3071#endif 3075#endif
3072} 3076}
3073 3077
3074void ZSafe::editCategory() 3078void ZSafe::editCategory()
3075{ 3079{
3076 if (!selectedItem) 3080 if (!selectedItem)
3077 return; 3081 return;
3078 if (isCategory(selectedItem)) 3082 if (isCategory(selectedItem))
3079 { 3083 {
3080 QString category = selectedItem->text(0); 3084 QString category = selectedItem->text(0);
3081 bool initIcons = false; 3085 bool initIcons = false;
3082 // open the 'Category' dialog 3086 // open the 'Category' dialog
3083 CategoryDialog *dialog; 3087 CategoryDialog *dialog;
3084 if (categoryDialog) 3088 if (categoryDialog)
3085 { 3089 {
3086 dialog = categoryDialog; 3090 dialog = categoryDialog;
3087 } 3091 }
3088 else 3092 else
3089 { 3093 {
3090 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 3094 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
3091#ifdef Q_WS_WIN 3095#ifdef Q_WS_WIN
3092 categoryDialog->setCaption ("Qt " + tr("Category")); 3096 categoryDialog->setCaption ("Qt " + tr("Category"));
3093#endif 3097#endif
3094 dialog = categoryDialog; 3098 dialog = categoryDialog;
3095 connect( dialog->CategoryField, 3099 connect( dialog->CategoryField,
3096 SIGNAL( activated(const QString&)), 3100 SIGNAL( activated(const QString&)),
3097 this, SLOT( categoryFieldActivated(const QString&) ) ); 3101 this, SLOT( categoryFieldActivated(const QString&) ) );
3098 initIcons = true; 3102 initIcons = true;
3099 } 3103 }
3100 setCategoryDialogFields(dialog); 3104 setCategoryDialogFields(dialog);
3101 3105
3102#ifdef DESKTOP 3106#ifdef DESKTOP
3103#ifndef Q_WS_WIN 3107#ifndef Q_WS_WIN
3104 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 3108 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
3105#else 3109#else
3106 // read all categories from the config file and store 3110 // read all categories from the config file and store
3107 // into a list 3111 // into a list
3108 QFile f (cfgFile); 3112 QFile f (cfgFile);
3109 QStringList list; 3113 QStringList list;
3110 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3114 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3111 QTextStream t( &f ); // use a text stream 3115 QTextStream t( &f ); // use a text stream
3112 QString s; 3116 QString s;
3113 int n = 1; 3117 int n = 1;
3114 while ( !t.eof() ) { // until end of file... 3118 while ( !t.eof() ) { // until end of file...
3115 s = t.readLine(); // line of text excluding '\n' 3119 s = t.readLine(); // line of text excluding '\n'
3116 list.append(s); 3120 list.append(s);
3117 } 3121 }
3118 f.close(); 3122 f.close();
3119 } 3123 }
3120#endif 3124#endif
3121#else 3125#else
3122 // read all categories from the config file and store 3126 // read all categories from the config file and store
3123 // into a list 3127 // into a list
3124 QFile f (cfgFile); 3128 QFile f (cfgFile);
3125 QStringList list; 3129 QStringList list;
3126 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3130 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3127 QTextStream t( &f ); // use a text stream 3131 QTextStream t( &f ); // use a text stream
3128 QString s; 3132 QString s;
3129 while ( !t.eof() ) { // until end of file... 3133 while ( !t.eof() ) { // until end of file...
3130 s = t.readLine(); // line of text excluding '\n' 3134 s = t.readLine(); // line of text excluding '\n'
3131 list.append(s); 3135 list.append(s);
3132 } 3136 }
3133 f.close(); 3137 f.close();
3134 } 3138 }
3135#endif 3139#endif
3136 QStringList::Iterator it = list.begin(); 3140 QStringList::Iterator it = list.begin();
3137 QString categ; 3141 QString categ;
3138 dialog->CategoryField->clear(); // remove all items 3142 dialog->CategoryField->clear(); // remove all items
3139 int i=0; 3143 int i=0;
3140 bool foundCategory = false; 3144 bool foundCategory = false;
3141 while( it != list.end() ) 3145 while( it != list.end() )
3142 { 3146 {
3143 QString *cat = new QString (*it); 3147 QString *cat = new QString (*it);
3144 if (cat->contains("-field1", FALSE)) 3148 if (cat->contains("-field1", FALSE))
3145 { 3149 {
3146#ifdef DESKTOP 3150#ifdef DESKTOP
3147#ifndef Q_WS_WIN 3151#ifndef Q_WS_WIN
3148 categ = cat->section ("-field1", 0, 0); 3152 categ = cat->section ("-field1", 0, 0);
3149#else 3153#else
3150 int pos = cat->find ("-field1"); 3154 int pos = cat->find ("-field1");
3151 categ = cat->left (pos); 3155 categ = cat->left (pos);
3152#endif 3156#endif
3153#else 3157#else
3154 int pos = cat->find ("-field1"); 3158 int pos = cat->find ("-field1");
3155 cat->truncate(pos); 3159 cat->truncate(pos);
3156 categ = *cat; 3160 categ = *cat;
3157#endif 3161#endif
3158 if (!categ.isEmpty()) 3162 if (!categ.isEmpty())
3159 { 3163 {
3160 dialog->CategoryField->insertItem (categ, i); 3164 dialog->CategoryField->insertItem (categ, i);
3161 if (category.compare(categ) == 0) 3165 if (category.compare(categ) == 0)
3162 { 3166 {
3163 dialog->CategoryField->setCurrentItem(i); 3167 dialog->CategoryField->setCurrentItem(i);
3164 foundCategory = true; 3168 foundCategory = true;
3165 } 3169 }
3166 i++; 3170 i++;
3167 } 3171 }
3168 } 3172 }
3169 ++it; 3173 ++it;
3170 } 3174 }
3171 if (!foundCategory) 3175 if (!foundCategory)
3172 { 3176 {
3173 dialog->CategoryField->insertItem (category, i); 3177 dialog->CategoryField->insertItem (category, i);
3174 dialog->CategoryField->setCurrentItem(i); 3178 dialog->CategoryField->setCurrentItem(i);
3175 } 3179 }
3176 3180
3177 QString icon; 3181 QString icon;
3178 Category *cat= categories.find (selectedItem->text(0)); 3182 Category *cat= categories.find (selectedItem->text(0));
3179 if (cat) 3183 if (cat)
3180 { 3184 {
3181 icon = cat->getIconName(); 3185 icon = cat->getIconName();
3182 } 3186 }
3183 3187
3184 if (initIcons) 3188 if (initIcons)
3185 { 3189 {
3186 3190
3187 Wait waitDialog(this, tr("Wait dialog")); 3191 Wait waitDialog(this, tr("Wait dialog"));
3188 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3192 waitDialog.waitLabel->setText(tr("Gathering icons..."));
3189 waitDialog.show(); 3193 waitDialog.show();
3190 qApp->processEvents(); 3194 qApp->processEvents();
3191 3195
3192#ifdef DESKTOP 3196#ifdef DESKTOP
3193 QDir d(iconPath); 3197 QDir d(iconPath);
3194#else 3198#else
3195 QDir d(QPEApplication::qpeDir() + "/pics/"); 3199 QDir d(QPEApplication::qpeDir() + "/pics/");
3196#endif 3200#endif
3197 d.setFilter( QDir::Files); 3201 d.setFilter( QDir::Files);
3198 3202
3199 const QFileInfoList *list = d.entryInfoList(); 3203 const QFileInfoList *list = d.entryInfoList();
3200 int i=0; 3204 int i=0;
3201 QFileInfoListIterator it( *list ); // create list iterator 3205 QFileInfoListIterator it( *list ); // create list iterator
3202 QFileInfo *fi; // pointer for traversing 3206 QFileInfo *fi; // pointer for traversing
3203 if (icon.isEmpty() || icon.isNull()) 3207 if (icon.isEmpty() || icon.isNull())
3204 { 3208 {
3205 dialog->IconField->setCurrentItem(0); 3209 dialog->IconField->setCurrentItem(0);
3206 } 3210 }
3207 3211
3208 dialog->IconField->insertItem("predefined"); 3212 dialog->IconField->insertItem("predefined");
3209 while ( (fi=it.current()) ) { // for each file... 3213 while ( (fi=it.current()) ) { // for each file...
3210 QString fileName = fi->fileName(); 3214 QString fileName = fi->fileName();
3211 if(fileName.right(4) == ".png") 3215 if(fileName.right(4) == ".png")
3212 { 3216 {
3213 fileName = fileName.mid(0,fileName.length()-4); 3217 fileName = fileName.mid(0,fileName.length()-4);
3214#ifdef DESKTOP 3218#ifdef DESKTOP
3215 QPixmap imageOfFile; 3219 QPixmap imageOfFile;
3216 imageOfFile.load(iconPath + fi->fileName()); 3220 imageOfFile.load(iconPath + fi->fileName());
3217#else 3221#else
3218 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3222 QPixmap imageOfFile(Resource::loadPixmap(fileName));
3219#endif 3223#endif
3220 QImage foo = imageOfFile.convertToImage(); 3224 QImage foo = imageOfFile.convertToImage();
3221 foo = foo.smoothScale(16,16); 3225 foo = foo.smoothScale(16,16);
3222 imageOfFile.convertFromImage(foo); 3226 imageOfFile.convertFromImage(foo);
3223 dialog->IconField->insertItem(imageOfFile,fileName); 3227 dialog->IconField->insertItem(imageOfFile,fileName);
3224 if(fileName+".png"==icon) 3228 if(fileName+".png"==icon)
3225 dialog->IconField->setCurrentItem(i+1); 3229 dialog->IconField->setCurrentItem(i+1);
3226 ++i; 3230 ++i;
3227 } 3231 }
3228 ++it; 3232 ++it;
3229 } 3233 }
3230 waitDialog.hide(); 3234 waitDialog.hide();
3231 } 3235 }
3232 else 3236 else
3233 { 3237 {
3234#ifdef DESKTOP 3238#ifdef DESKTOP
3235 // QDir d(QDir::homeDirPath() + "/pics/"); 3239 // QDir d(QDir::homeDirPath() + "/pics/");
3236 QDir d(iconPath); 3240 QDir d(iconPath);
3237#else 3241#else
3238 QDir d(QPEApplication::qpeDir() + "/pics/"); 3242 QDir d(QPEApplication::qpeDir() + "/pics/");
3239#endif 3243#endif
3240 d.setFilter( QDir::Files); 3244 d.setFilter( QDir::Files);
3241 3245
3242 const QFileInfoList *list = d.entryInfoList(); 3246 const QFileInfoList *list = d.entryInfoList();
3243 int i=0; 3247 int i=0;
3244 QFileInfoListIterator it( *list ); // create list iterator 3248 QFileInfoListIterator it( *list ); // create list iterator
3245 QFileInfo *fi; // pointer for traversing 3249 QFileInfo *fi; // pointer for traversing
3246 if (icon.isEmpty() || icon.isNull()) 3250 if (icon.isEmpty() || icon.isNull())
3247 { 3251 {
3248 dialog->IconField->setCurrentItem(0); 3252 dialog->IconField->setCurrentItem(0);
3249 } 3253 }
3250 else 3254 else
3251 { 3255 {
3252 3256
3253 while ( (fi=it.current()) ) 3257 while ( (fi=it.current()) )
3254 { // for each file... 3258 { // for each file...
3255 QString fileName = fi->fileName(); 3259 QString fileName = fi->fileName();
3256 if(fileName.right(4) == ".png") 3260 if(fileName.right(4) == ".png")
3257 { 3261 {
3258 fileName = fileName.mid(0,fileName.length()-4); 3262 fileName = fileName.mid(0,fileName.length()-4);
3259 3263
3260 3264
3261 if(fileName+".png"==icon) 3265 if(fileName+".png"==icon)
3262 { 3266 {
3263 dialog->IconField->setCurrentItem(i+1); 3267 dialog->IconField->setCurrentItem(i+1);
3264 break; 3268 break;
3265 } 3269 }
3266 ++i; 3270 ++i;
3267 } 3271 }
3268 ++it; 3272 ++it;
3269 } 3273 }
3270 } 3274 }
3271 } 3275 }
3272 3276
3273 // dialog->show(); 3277 // dialog->show();
3274#ifndef DESKTOP 3278#ifndef DESKTOP
3275 // dialog->move (20, 100); 3279 // dialog->move (20, 100);
3276#endif 3280#endif
3277 DialogCode result = (DialogCode) dialog->exec(); 3281 DialogCode result = (DialogCode) dialog->exec();
3278#ifdef DESKTOP 3282#ifdef DESKTOP
3279 result = Accepted; 3283 result = Accepted;
3280#endif 3284#endif
3281 3285
3282 QString fullIconPath; 3286 QString fullIconPath;
3283 QPixmap *pix; 3287 QPixmap *pix;
3284 if (result == Accepted) 3288 if (result == Accepted)
3285 { 3289 {
3286 modified = true; 3290 modified = true;
3287 if (category != dialog->CategoryField->currentText()) 3291 if (category != dialog->CategoryField->currentText())
3288 { 3292 {
3289 categories.remove (category); 3293 categories.remove (category);
3290// #ifndef Q_WS_WIN 3294// #ifndef Q_WS_WIN
3291 conf->removeEntry(category); 3295 conf->removeEntry(category);
3292// #endif 3296// #endif
3293 saveConf(); 3297 saveConf();
3294 } 3298 }
3295 3299
3296 category = dialog->CategoryField->currentText(); 3300 category = dialog->CategoryField->currentText();
3297 icon = dialog->IconField->currentText()+".png"; 3301 icon = dialog->IconField->currentText()+".png";
3298 3302
3299 if (cat) 3303 if (cat)
3300 { 3304 {
3301#ifndef NO_OPIE 3305#ifndef NO_OPIE
3302 owarn << "Category found" << oendl; 3306 owarn << "Category found" << oendl;
3303#else 3307#else
3304 qWarning("Category found"); 3308 qWarning("Category found");
3305#endif 3309#endif
3306 3310
3307 // if (!icon.isEmpty() && !icon.isNull()) 3311 // if (!icon.isEmpty() && !icon.isNull())
3308 if (icon != "predefined.png") 3312 if (icon != "predefined.png")
3309 { 3313 {
3310 // build the full path 3314 // build the full path
3311 fullIconPath = iconPath + icon; 3315 fullIconPath = iconPath + icon;
3312 pix = new QPixmap (fullIconPath); 3316 pix = new QPixmap (fullIconPath);
3313 if (!pix->isNull()) 3317 if (!pix->isNull())
3314 { 3318 {
3315 // save the full pixmap name into the config file 3319 // save the full pixmap name into the config file
3316// #ifndef Q_WS_WIN 3320// #ifndef Q_WS_WIN
3317 conf->writeEntry(APP_KEY+category, icon); 3321 conf->writeEntry(APP_KEY+category, icon);
3318// #endif 3322// #endif
3319 saveConf(); 3323 saveConf();
3320 QImage img = pix->convertToImage(); 3324 QImage img = pix->convertToImage();
3321 pix->convertFromImage(img.smoothScale(14,14)); 3325 pix->convertFromImage(img.smoothScale(14,14));
3322 cat->setIconName (icon); 3326 cat->setIconName (icon);
3323 cat->setIcon (*pix); 3327 cat->setIcon (*pix);
3324 } 3328 }
3325 } 3329 }
3326 else 3330 else
3327 { 3331 {
3328// #ifndef Q_WS_WIN 3332// #ifndef Q_WS_WIN
3329 conf->removeEntry (category); 3333 conf->removeEntry (category);
3330// #endif 3334// #endif
3331 saveConf(); 3335 saveConf();
3332 cat->setIcon (*getPredefinedIcon(category)); 3336 cat->setIcon (*getPredefinedIcon(category));
3333 } 3337 }
3334 3338
3335 // change the category name of the selected category 3339 // change the category name of the selected category
3336 QListViewItem *catItem = cat->getListItem(); 3340 QListViewItem *catItem = cat->getListItem();
3337 if (catItem) 3341 if (catItem)
3338 { 3342 {
3339#ifndef NO_OPIE 3343#ifndef NO_OPIE
3340 owarn << category << oendl; 3344 owarn << category << oendl;
3341#else 3345#else
3342 qWarning (category); 3346 qWarning (category);
3343#endif 3347#endif
3344 catItem->setText( 0, tr( category ) ); 3348 catItem->setText( 0, tr( category ) );
3345 cat->setCategoryName (tr(category)); 3349 cat->setCategoryName (tr(category));
3346 3350
3347 cat->initListItem(); 3351 cat->initListItem();
3348 categories.insert (category, cat); 3352 categories.insert (category, cat);
3349 } 3353 }
3350 } 3354 }
3351 saveCategoryDialogFields(dialog); 3355 saveCategoryDialogFields(dialog);
3352 } 3356 }
3353 else 3357 else
3354 { 3358 {
3355 // delete dialog; 3359 // delete dialog;
3356 dialog->hide(); 3360 dialog->hide();
3357 return; 3361 return;
3358 } 3362 }
3359 3363
3360 } 3364 }
3361} 3365}
3362 3366
3363void ZSafe::cutItem() 3367void ZSafe::cutItem()
3364{ 3368{
3365 if (!selectedItem) 3369 if (!selectedItem)
3366 return; 3370 return;
3367 if (!isCategory(selectedItem)) 3371 if (!isCategory(selectedItem))
3368 { 3372 {
3369 IsCut = true; 3373 IsCut = true;
3370 copiedItem = selectedItem; 3374 copiedItem = selectedItem;
3371 } 3375 }
3372} 3376}
3373 3377
3374void ZSafe::copyItem() 3378void ZSafe::copyItem()
3375{ 3379{
3376 if (!selectedItem) 3380 if (!selectedItem)
3377 return; 3381 return;
3378 if (!isCategory(selectedItem)) 3382 if (!isCategory(selectedItem))
3379 { 3383 {
3380 IsCopy = true; 3384 IsCopy = true;
3381 copiedItem = selectedItem; 3385 copiedItem = selectedItem;
3382 } 3386 }
3383} 3387}
3384 3388
3385// paste item into category 3389// paste item into category
3386void ZSafe::pasteItem() 3390void ZSafe::pasteItem()
3387{ 3391{
3388 if (!selectedItem) 3392 if (!selectedItem)
3389 return; 3393 return;
3390 if (isCategory(selectedItem)) 3394 if (isCategory(selectedItem))
3391 { 3395 {
3392 modified = true; 3396 modified = true;
3393 if (IsCut) 3397 if (IsCut)
3394 { 3398 {
3395 if (copiedItem) 3399 if (copiedItem)
3396 { 3400 {
3397 // add the new item 3401 // add the new item
3398 QListViewItem *i = new ShadedListItem (0, selectedItem); 3402 QListViewItem *i = new ShadedListItem (0, selectedItem);
3399 // i->setOpen (TRUE); 3403 // i->setOpen (TRUE);
3400 i->setText (0, copiedItem->text(0)); 3404 i->setText (0, copiedItem->text(0));
3401 i->setText (1, copiedItem->text(1)); 3405 i->setText (1, copiedItem->text(1));
3402 i->setText (2, copiedItem->text(2)); 3406 i->setText (2, copiedItem->text(2));
3403 i->setText (3, copiedItem->text(3)); 3407 i->setText (3, copiedItem->text(3));
3404 i->setText (4, copiedItem->text(4)); 3408 i->setText (4, copiedItem->text(4));
3405 i->setText (5, copiedItem->text(5)); 3409 i->setText (5, copiedItem->text(5));
3406 selectedItem->setOpen( TRUE ); 3410 selectedItem->setOpen( TRUE );
3407 3411
3408 // remove the cutted item 3412 // remove the cutted item
3409 copiedItem->parent()->takeItem(copiedItem); 3413 copiedItem->parent()->takeItem(copiedItem);
3410 selectedItem = NULL; 3414 selectedItem = NULL;
3411 } 3415 }
3412 } 3416 }
3413 else if (IsCopy) 3417 else if (IsCopy)
3414 { 3418 {
3415 if (copiedItem) 3419 if (copiedItem)
3416 { 3420 {
3417 // add the new item 3421 // add the new item
3418 QListViewItem *i = new ShadedListItem (0, selectedItem); 3422 QListViewItem *i = new ShadedListItem (0, selectedItem);
3419 // i->setOpen (TRUE); 3423 // i->setOpen (TRUE);
3420 i->setText (0, copiedItem->text(0)); 3424 i->setText (0, copiedItem->text(0));
3421 i->setText (1, copiedItem->text(1)); 3425 i->setText (1, copiedItem->text(1));
3422 i->setText (2, copiedItem->text(2)); 3426 i->setText (2, copiedItem->text(2));
3423 i->setText (3, copiedItem->text(3)); 3427 i->setText (3, copiedItem->text(3));
3424 i->setText (4, copiedItem->text(4)); 3428 i->setText (4, copiedItem->text(4));
3425 i->setText (5, copiedItem->text(5)); 3429 i->setText (5, copiedItem->text(5));
3426 selectedItem->setOpen( TRUE ); 3430 selectedItem->setOpen( TRUE );
3427 } 3431 }
3428 } 3432 }
3429 } 3433 }
3430 IsCut = false; 3434 IsCut = false;
3431 IsCopy = false; 3435 IsCopy = false;
3432} 3436}
3433 3437
3434void ZSafe::newDocument() 3438void ZSafe::newDocument()
3435{ 3439{
3436 3440
3437 // open the file dialog 3441 // open the file dialog
3438 QString newFile = zsaveDialog(); 3442 QString newFile = zsaveDialog();
3439 3443
3440 // open the new document 3444 // open the new document
3441 if (newFile && newFile.length() > 0 ) 3445 if (newFile && newFile.length() > 0 )
3442 { 3446 {
3443 // save the previous opened document 3447 // save the previous opened document
3444 if (!filename.isEmpty()) 3448 if (!filename.isEmpty())
3445 saveDocument(filename, FALSE); 3449 saveDocument(filename, FALSE);
3446 3450
3447 modified = true; 3451 modified = true;
3448 3452
3449 // clear the password list 3453 // clear the password list
3450 QListViewItem *i; 3454 QListViewItem *i;
3451 QListViewItem *c = NULL; 3455 QListViewItem *c = NULL;
3452 // step through all categories 3456 // step through all categories
3453 for (i = ListView->firstChild(); 3457 for (i = ListView->firstChild();
3454 i != NULL; 3458 i != NULL;
3455 i = i->nextSibling()) 3459 i = i->nextSibling())
3456 { 3460 {
3457 if (c) delete c; // delete the previous category 3461 if (c) delete c; // delete the previous category
3458 3462
3459 c = i; 3463 c = i;
3460 // step through all subitems 3464 // step through all subitems
3461 QListViewItem *si; 3465 QListViewItem *si;
3462 for (si = i->firstChild(); 3466 for (si = i->firstChild();
3463 si != NULL; ) 3467 si != NULL; )
3464 { 3468 {
3465 QListViewItem *_si = si; 3469 QListViewItem *_si = si;
3466 si = si->nextSibling(); 3470 si = si->nextSibling();
3467 i->takeItem(_si); // remove from view list 3471 i->takeItem(_si); // remove from view list
3468 if (_si) delete _si; 3472 if (_si) delete _si;
3469 } 3473 }
3470 } 3474 }
3471 if (c) delete c; // delete the previous category 3475 if (c) delete c; // delete the previous category
3472 categories.clear(); 3476 categories.clear();
3473 3477
3474 // m_password = ""; 3478 // m_password = "";
3475 selectedItem = NULL; 3479 selectedItem = NULL;
3476 3480
3477 filename = newFile; 3481 filename = newFile;
3478 3482
3479 // save the current filename to the config file 3483 // save the current filename to the config file
3480 conf->writeEntry(APP_KEY+"document", filename); 3484 conf->writeEntry(APP_KEY+"document", filename);
3481 saveConf(); 3485 saveConf();
3482 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3486 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3483#ifdef Q_WS_WIN 3487#ifdef Q_WS_WIN
3484 this->setCaption("Qt ZSafe: " + ti); 3488 this->setCaption("Qt ZSafe: " + ti);
3485#else 3489#else
3486 this->setCaption("ZSafe: " + ti); 3490 this->setCaption("ZSafe: " + ti);
3487#endif 3491#endif
3488 3492
3489 // openDocument(filename); 3493 // openDocument(filename);
3490 3494
3491 QMessageBox::information( this, tr("ZSafe"), 3495 QMessageBox::information( this, tr("ZSafe"),
3492 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3496 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3493 3497
3494 saveDocumentWithPwd(); 3498 saveDocumentWithPwd();
3495 } 3499 }
3496} 3500}
3497 3501
3498void ZSafe::loadDocument() 3502void ZSafe::loadDocument()
3499{ 3503{
3500 3504
3501 // open the file dialog 3505 // open the file dialog
3502#ifndef DESKTOP 3506#ifndef DESKTOP
3503#ifndef NO_OPIE 3507#ifndef NO_OPIE
3504 QMap<QString, QStringList> mimeTypes; 3508 QMap<QString, QStringList> mimeTypes;
3505 mimeTypes.insert(tr("All"), QStringList() ); 3509 mimeTypes.insert(tr("All"), QStringList() );
3506 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3510 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3507 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 3511 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
3508 QDir::homeDirPath() + "/Documents/application/zsafe", 3512 QDir::homeDirPath() + "/Documents/application/zsafe",
3509 QString::null, 3513 QString::null,
3510 mimeTypes, 3514 mimeTypes,
3511 this, 3515 this,
3512 tr ("Open ZSafe document")); 3516 tr ("Open ZSafe document"));
3513#else 3517#else
3514 QString newFile = ScQtFileEdit::getOpenFileName(this, 3518 QString newFile = ScQtFileEdit::getOpenFileName(this,
3515 tr ("Open ZSafe document"), 3519 tr ("Open ZSafe document"),
3516 QDir::homeDirPath() + "/Documents/application/zsafe", 3520 QDir::homeDirPath() + "/Documents/application/zsafe",
3517 "*.zsf"); 3521 "*.zsf");
3518#endif 3522#endif
3519#else 3523#else
3520 QString newFile = QFileDialog::getOpenFileName( 3524 QString newFile = QFileDialog::getOpenFileName(
3521 QDir::homeDirPath() + "/Documents/application/zsafe", 3525 QDir::homeDirPath() + "/Documents/application/zsafe",
3522 "ZSafe (*.zsf)", 3526 "ZSafe (*.zsf)",
3523 this, 3527 this,
3524 "ZSafe File Dialog" 3528 "ZSafe File Dialog"
3525 "Choose a ZSafe file" ); 3529 "Choose a ZSafe file" );
3526#endif 3530#endif
3527 3531
3528 // open the new document 3532 // open the new document
3529 if (newFile && newFile.length() > 0 ) 3533 if (newFile && newFile.length() > 0 )
3530 { 3534 {
3531 // save the previous opened document 3535 // save the previous opened document
3532 if (!filename.isEmpty()) 3536 if (!filename.isEmpty())
3533 saveDocument(filename, FALSE); 3537 saveDocument(filename, FALSE);
3534 3538
3535 // clear the password list 3539 // clear the password list
3536 QListViewItem *i; 3540 QListViewItem *i;
3537 QListViewItem *c = NULL; 3541 QListViewItem *c = NULL;
3538 // step through all categories 3542 // step through all categories
3539 for (i = ListView->firstChild(); 3543 for (i = ListView->firstChild();
3540 i != NULL; 3544 i != NULL;
3541 i = i->nextSibling()) 3545 i = i->nextSibling())
3542 { 3546 {
3543 if (c) delete c; // delete the previous category 3547 if (c) delete c; // delete the previous category
3544 3548
3545 c = i; 3549 c = i;
3546 // step through all subitems 3550 // step through all subitems
3547 QListViewItem *si; 3551 QListViewItem *si;
3548 for (si = i->firstChild(); 3552 for (si = i->firstChild();
3549 si != NULL; ) 3553 si != NULL; )
3550 { 3554 {
3551 QListViewItem *_si = si; 3555 QListViewItem *_si = si;
3552 si = si->nextSibling(); 3556 si = si->nextSibling();
3553 i->takeItem(_si); // remove from view list 3557 i->takeItem(_si); // remove from view list
3554 if (_si) delete _si; 3558 if (_si) delete _si;
3555 } 3559 }
3556 } 3560 }
3557 if (c) delete c; // delete the previous category 3561 if (c) delete c; // delete the previous category
3558 categories.clear(); 3562 categories.clear();
3559 m_password = ""; 3563 m_password = "";
3560 selectedItem = NULL; 3564 selectedItem = NULL;
3561 filename = newFile; 3565 filename = newFile;
3562 3566
3563 // save the current filename to the config file 3567 // save the current filename to the config file
3564 conf->writeEntry(APP_KEY+"document", filename); 3568 conf->writeEntry(APP_KEY+"document", filename);
3565 saveConf(); 3569 saveConf();
3566 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3570 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3567#ifdef Q_WS_WIN 3571#ifdef Q_WS_WIN
3568 this->setCaption("Qt ZSafe: " + ti); 3572 this->setCaption("Qt ZSafe: " + ti);
3569#else 3573#else
3570 this->setCaption("ZSafe: " + ti); 3574 this->setCaption("ZSafe: " + ti);
3571#endif 3575#endif
3572 3576
3573 openDocument(filename); 3577 openDocument(filename);
3574 } 3578 }
3575} 3579}
3576 3580
3577void ZSafe::saveDocumentAs() 3581void ZSafe::saveDocumentAs()
3578{ 3582{
3579 3583
3580QString newFile = zsaveDialog(); 3584QString newFile = zsaveDialog();
3581 // open the new document 3585 // open the new document
3582 if (newFile && newFile.length() > 0 ) 3586 if (newFile && newFile.length() > 0 )
3583 { 3587 {
3584 // save the previous opened document 3588 // save the previous opened document
3585 if (!filename.isEmpty()) 3589 if (!filename.isEmpty())
3586 saveDocument(filename, FALSE); 3590 saveDocument(filename, FALSE);
3587 3591
3588 selectedItem = NULL; 3592 selectedItem = NULL;
3589 filename = newFile; 3593 filename = newFile;
3590 3594
3591 // save the current filename to the config file 3595 // save the current filename to the config file
3592 conf->writeEntry(APP_KEY+"document", filename); 3596 conf->writeEntry(APP_KEY+"document", filename);
3593 saveConf(); 3597 saveConf();
3594 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3598 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3595#ifdef Q_WS_WIN 3599#ifdef Q_WS_WIN
3596 this->setCaption("Qt ZSafe: " + ti); 3600 this->setCaption("Qt ZSafe: " + ti);
3597#else 3601#else
3598 this->setCaption("ZSafe: " + ti); 3602 this->setCaption("ZSafe: " + ti);
3599#endif 3603#endif
3600 3604
3601 QMessageBox::information( this, tr("ZSafe"), 3605 QMessageBox::information( this, tr("ZSafe"),
3602 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3606 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3603 3607
3604 saveDocumentWithPwd(); 3608 saveDocumentWithPwd();
3605 } 3609 }
3606} 3610}
3607 3611
3608void ZSafe::saveDocumentWithoutPwd() 3612void ZSafe::saveDocumentWithoutPwd()
3609{ 3613{
3610 saveDocument(filename, FALSE); 3614 saveDocument(filename, FALSE);
3611} 3615}
3612 3616
3613void ZSafe::saveDocumentWithPwd() 3617void ZSafe::saveDocumentWithPwd()
3614{ 3618{
3615 saveDocument(filename, TRUE); 3619 saveDocument(filename, TRUE);
3616} 3620}
3617 3621
3618void ZSafe::about() 3622void ZSafe::about()
3619{ 3623{
3620 QString info; 3624 QString info;
3621#ifdef JPATCH_HDE 3625#ifdef JPATCH_HDE
3622 info = "<html><body><div align=""center"">"; 3626 info = "<html><body><div align=""center"">";
3623 info += "<b>"; 3627 info += "<b>";
3624 info += tr("Zaurus Password Manager<br>"); 3628 info += tr("Zaurus Password Manager<br>");
3625 info += tr("ZSafe version 2.1.2-jv01b<br>"); 3629 info += tr("ZSafe version 2.1.2-jv01b<br>");
3626 info += "</b>"; 3630 info += "</b>";
3627 info += tr("by Carsten Schneider<br>"); 3631 info += tr("by Carsten Schneider<br>");
3628 info += "zcarsten@gmx.net<br>"; 3632 info += "zcarsten@gmx.net<br>";
3629 info += "http://z-soft.z-portal.info/zsafe"; 3633 info += "http://z-soft.z-portal.info/zsafe";
3630 info += "<br>"; 3634 info += "<br>";
3631 info += tr("Translations by Robert Ernst<br>"); 3635 info += tr("Translations by Robert Ernst<br>");
3632 info += "robert.ernst@linux-solutions.at<br>"; 3636 info += "robert.ernst@linux-solutions.at<br>";
3633 3637
3634 info += "<br><br>"; 3638 info += "<br><br>";
3635 info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>"); 3639 info += QString::fromUtf8("æ~W¥æ~\\¬èª~^/VGA Zaurus対å¿~\\ã~C~Qã~C~Cã~C~Aä½~\\æ ~H~P<br>");
3636 info += "HADECO R&D<br>"; 3640 info += "HADECO R&D<br>";
3637 info += "r&d@hadeco.co.jp<br>"; 3641 info += "r&d@hadeco.co.jp<br>";
3638 info += "http://www.hadeco.co.jp/r&d/<br>"; 3642 info += "http://www.hadeco.co.jp/r&d/<br>";
3639 info += "<br></div>"; 3643 info += "<br></div>";
3640 info += "</body></html>"; 3644 info += "</body></html>";
3641#else 3645#else
3642 info = "<html><body><div align=""center"">"; 3646 info = "<html><body><div align=""center"">";
3643 info += "<b>"; 3647 info += "<b>";
3644 info += tr("Zaurus Password Manager<br>"); 3648 info += tr("Zaurus Password Manager<br>");
3645 info += tr("ZSafe version 2.1.2<br>"); 3649 info += tr("ZSafe version 2.1.2<br>");
3646 info += "</b>"; 3650 info += "</b>";
3647 info += tr("by Carsten Schneider<br>"); 3651 info += tr("by Carsten Schneider<br>");
3648 info += "zcarsten@gmx.net<br>"; 3652 info += "zcarsten@gmx.net<br>";
3649 info += "http://z-soft.z-portal.info/zsafe"; 3653 info += "http://z-soft.z-portal.info/zsafe";
3650 info += "<br>"; 3654 info += "<br>";
3651 info += tr("Translations by Robert Ernst<br>"); 3655 info += tr("Translations by Robert Ernst<br>");
3652 info += "robert.ernst@linux-solutions.at<br>"; 3656 info += "robert.ernst@linux-solutions.at<br>";
3653 info += "<br></div>"; 3657 info += "<br></div>";
3654 info += "</body></html>"; 3658 info += "</body></html>";
3655#endif 3659#endif
3656 3660
3657 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); 3661 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0);
3658 3662
3659 QMessageBox mb( this, tr("ZSafe")); 3663 QMessageBox mb( this, tr("ZSafe"));
3660 mb.setText (info); 3664 mb.setText (info);
3661 mb.setButtonText (QMessageBox::Ok, tr ("&OK")); 3665 mb.setButtonText (QMessageBox::Ok, tr ("&OK"));
3662 QPixmap zsafe_img((const char**) zsafe_xpm); 3666 QPixmap zsafe_img((const char**) zsafe_xpm);
3663 mb.setIconPixmap (zsafe_img); 3667 mb.setIconPixmap (zsafe_img);
3664 mb.exec(); 3668 mb.exec();
3665} 3669}
3666 3670
3667void ZSafe::setExpandFlag() 3671void ZSafe::setExpandFlag()
3668{ 3672{
3669 expandTree = !expandTree; 3673 expandTree = !expandTree;
3670 file->setItemChecked('o', expandTree); 3674 file->setItemChecked('o', expandTree);
3671#ifndef DESKTOP 3675#ifndef DESKTOP
3672 conf->setGroup ("zsafePrefs"); 3676 conf->setGroup ("zsafePrefs");
3673#endif 3677#endif
3674// #ifndef Q_WS_WIN 3678// #ifndef Q_WS_WIN
3675 conf->writeEntry (APP_KEY+"expandTree", expandTree); 3679 conf->writeEntry (APP_KEY+"expandTree", expandTree);
3676// #endif 3680// #endif
3677 saveConf(); 3681 saveConf();
3678 3682
3679} 3683}
3680 3684
3681void ZSafe::paintEvent( QPaintEvent * ) 3685void ZSafe::paintEvent( QPaintEvent * )
3682{ 3686{
3683 if (raiseFlag) 3687 if (raiseFlag)
3684 { 3688 {
3685 raiseFlag = false; 3689 raiseFlag = false;
3686 raiseTimer.start (1, true); 3690 raiseTimer.start (1, true);
3687 if (infoForm->isVisible()) 3691 if (infoForm->isVisible())
3688 infoForm->raise(); 3692 infoForm->raise();
3689 } 3693 }
3690} 3694}
3691 3695
3692void ZSafe::resizeEvent ( QResizeEvent * ) 3696void ZSafe::resizeEvent ( QResizeEvent * )
3693{ 3697{
3694 // owarn << "resizeEvent" << oendl; 3698 // owarn << "resizeEvent" << oendl;
3695#ifndef DESKTOP 3699#ifndef DESKTOP
3696 DeskW = appl->desktop()->width(); 3700 DeskW = appl->desktop()->width();
3697 DeskH = appl->desktop()->height(); 3701 DeskH = appl->desktop()->height();
3698#else 3702#else
3699 DeskW = this->width(); 3703 DeskW = this->width();
3700 DeskH = this->height(); 3704 DeskH = this->height();
3701#endif 3705#endif
3702 3706
3703 if (New) 3707 if (New)
3704 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); 3708 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
3705 if (Edit) 3709 if (Edit)
3706 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); 3710 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
3707 if (Delete) 3711 if (Delete)
3708 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 3712 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
3709 if (Find) 3713 if (Find)
3710 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); 3714 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
3711} 3715}
3712 3716
3713void ZSafe::slotRaiseTimer() 3717void ZSafe::slotRaiseTimer()
3714{ 3718{
3715 if (infoForm->isVisible()) 3719 if (infoForm->isVisible())
3716 infoForm->raise(); 3720 infoForm->raise();
3717 raiseFlag = true; 3721 raiseFlag = true;
3718} 3722}
3719 3723
3720QPixmap * ZSafe::getPredefinedIcon(QString category) 3724QPixmap * ZSafe::getPredefinedIcon(QString category)
3721{ 3725{
3722 QPixmap *pm; 3726 QPixmap *pm;
3723 if (category == "Bank cards") 3727 if (category == "Bank cards")
3724 pm = new QPixmap((const char**)bank_cards_data); 3728 pm = new QPixmap((const char**)bank_cards_data);
3725 else if (category == "Passwords") 3729 else if (category == "Passwords")
3726 pm = new QPixmap((const char**)passwords_data); 3730 pm = new QPixmap((const char**)passwords_data);
3727 else if (category == "Software") 3731 else if (category == "Software")
3728 pm = new QPixmap((const char**)software_data); 3732 pm = new QPixmap((const char**)software_data);
3729 else if (category == "General") 3733 else if (category == "General")
3730 pm = new QPixmap((const char**)general_data); 3734 pm = new QPixmap((const char**)general_data);
3731 else 3735 else
3732 pm = new QPixmap((const char**)general_data); 3736 pm = new QPixmap((const char**)general_data);
3733 return pm; 3737 return pm;
3734} 3738}
3735 3739
3736void ZSafe::setDocument(const QString& fileref) 3740void ZSafe::setDocument(const QString& fileref)
3737{ 3741{
3738#ifndef DESKTOP 3742#ifndef DESKTOP
3739 // stop the timer to prevent loading of the default document 3743 // stop the timer to prevent loading of the default document
3740 docuTimer.stop(); 3744 docuTimer.stop();
3741 3745
3742 DocLnk link(fileref); 3746 DocLnk link(fileref);
3743 if ( link.isValid() ) 3747 if ( link.isValid() )
3744 { 3748 {
3745 // if (filename != link.file()) 3749 // if (filename != link.file())
3746 // saveDocument(filename, FALSE); 3750 // saveDocument(filename, FALSE);
3747 filename = link.file(); 3751 filename = link.file();
3748 } 3752 }
3749 else 3753 else
3750 { 3754 {
3751 // if (filename != fileref) 3755 // if (filename != fileref)
3752 // saveDocument(filename, FALSE); 3756 // saveDocument(filename, FALSE);
3753 filename = fileref; 3757 filename = fileref;
3754 } 3758 }
3755 // save the current filename to the config file 3759 // save the current filename to the config file
3756 conf->writeEntry(APP_KEY+"document", filename); 3760 conf->writeEntry(APP_KEY+"document", filename);
3757 saveConf(); 3761 saveConf();
3758 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3762 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3759#ifdef Q_WS_WIN 3763#ifdef Q_WS_WIN
3760 this->setCaption("Qt ZSafe: " + ti); 3764 this->setCaption("Qt ZSafe: " + ti);
3761#else 3765#else
3762 this->setCaption("ZSafe: " + ti); 3766 this->setCaption("ZSafe: " + ti);
3763#endif 3767#endif
3764 3768
3765 // clear the password list 3769 // clear the password list
3766 QListViewItem *i; 3770 QListViewItem *i;
3767 QListViewItem *c = NULL; 3771 QListViewItem *c = NULL;
3768 // step through all categories 3772 // step through all categories
3769 for (i = ListView->firstChild(); 3773 for (i = ListView->firstChild();
3770 i != NULL; 3774 i != NULL;
3771 i = i->nextSibling()) 3775 i = i->nextSibling())
3772 { 3776 {
3773 if (c) delete c; // delete the previous category 3777 if (c) delete c; // delete the previous category
3774 3778
3775 c = i; 3779 c = i;
3776 // step through all subitems 3780 // step through all subitems
3777 QListViewItem *si; 3781 QListViewItem *si;
3778 for (si = i->firstChild(); 3782 for (si = i->firstChild();
3779 si != NULL; ) 3783 si != NULL; )
3780 { 3784 {
3781 QListViewItem *_si = si; 3785 QListViewItem *_si = si;
3782 si = si->nextSibling(); 3786 si = si->nextSibling();
3783 i->takeItem(_si); // remove from view list 3787 i->takeItem(_si); // remove from view list
3784 if (_si) delete _si; 3788 if (_si) delete _si;
3785 } 3789 }
3786 } 3790 }
3787 if (c) delete c; // delete the previous category 3791 if (c) delete c; // delete the previous category
3788 categories.clear(); 3792 categories.clear();
3789 3793
3790 m_password = ""; 3794 m_password = "";
3791 selectedItem = NULL; 3795 selectedItem = NULL;
3792 3796
3793 openDocument(filename); 3797 openDocument(filename);
3794#else 3798#else
3795Q_UNUSED(fileref); 3799Q_UNUSED(fileref);
3796#endif 3800#endif
3797} 3801}
3798 3802
3799 3803
3800void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { 3804void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) {
3801 if(item ==0) return; 3805 if(item ==0) return;
3802 switch (mouse) { 3806 switch (mouse) {
3803 case 1: 3807 case 1:
3804 { 3808 {
3805#ifdef DESKTOP 3809#ifdef DESKTOP
3806 QDragObject *d = new QTextDrag( item->text(column) , this ); 3810 QDragObject *d = new QTextDrag( item->text(column) , this );
3807 d->dragCopy(); 3811 d->dragCopy();
3808#endif 3812#endif
3809 } 3813 }
3810 break; 3814 break;
3811 case 2: 3815 case 2:
3812 { 3816 {
3813 QClipboard *cb = QApplication::clipboard(); 3817 QClipboard *cb = QApplication::clipboard();
3814 3818
3815 QIconSet copy_img((const char**) copy_xpm); 3819 QIconSet copy_img((const char**) copy_xpm);
3816 QIconSet edit_img((const char**) edit_xpm); 3820 QIconSet edit_img((const char**) edit_xpm);
3817 QPixmap folder_open_img((const char**) folder_open_xpm); 3821 QPixmap folder_open_img((const char**) folder_open_xpm);
3818 QPixmap editdelete_img((const char**) editdelete_xpm); 3822 QPixmap editdelete_img((const char**) editdelete_xpm);
3819 3823
3820 QPopupMenu *m = new QPopupMenu(this); 3824 QPopupMenu *m = new QPopupMenu(this);
3821 int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" )); 3825 int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" ));
3822 int editItem = m->insertItem(edit_img, tr( "Edit" )); 3826 int editItem = m->insertItem(edit_img, tr( "Edit" ));
3823 int showItem = m->insertItem(folder_open_img, tr( "Show Info" )); 3827 int showItem = m->insertItem(folder_open_img, tr( "Show Info" ));
3824 int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" )); 3828 int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" ));
3825 m->setFocus(); 3829 m->setFocus();
3826 int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ; 3830 int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ;
3827 if(me == copyItem) { 3831 if(me == copyItem) {
3828 copyClip( item->text(column) ) ; 3832 copyClip( item->text(column) ) ;
3829 } else if (me == cancelItem) { 3833 } else if (me == cancelItem) {
3830 cb->clear(); 3834 cb->clear();
3831 } else if (me == editItem) { 3835 } else if (me == editItem) {
3832 editPwd(); 3836 editPwd();
3833 } else if (me == showItem) { 3837 } else if (me == showItem) {
3834 showInfo(item); 3838 showInfo(item);
3835 } 3839 }
3836 } 3840 }
3837 break; 3841 break;
3838 }; 3842 };
3839} 3843}
3840 3844
3841void ZSafe::copyClip( const QString &text) { 3845void ZSafe::copyClip( const QString &text) {
3842 QClipboard *cb = QApplication::clipboard(); 3846 QClipboard *cb = QApplication::clipboard();
3843 cb->setText( text); 3847 cb->setText( text);
3844} 3848}
3845 3849
3846 3850
3847QString ZSafe::zsaveDialog() { 3851QString ZSafe::zsaveDialog() {
3848 3852
3849 QString fn; 3853 QString fn;
3850#ifndef DESKTOP 3854#ifndef DESKTOP
3851#ifndef NO_OPIE 3855#ifndef NO_OPIE
3852 QMap<QString, QStringList> mimeTypes; 3856 QMap<QString, QStringList> mimeTypes;
3853 mimeTypes.insert(tr("All"), QStringList() ); 3857 mimeTypes.insert(tr("All"), QStringList() );
3854 mimeTypes.insert(tr("Text"), "text/*" ); 3858 mimeTypes.insert(tr("Text"), "text/*" );
3855 fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3859 fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3856 QDir::homeDirPath() + "/Documents/application/zsafe", 3860 QDir::homeDirPath() + "/Documents/application/zsafe",
3857 QString::null, 3861 QString::null,
3858 mimeTypes, 3862 mimeTypes,
3859 this, 3863 this,
3860 tr ("Export text file")); 3864 tr ("Export text file"));
3861#else 3865#else
3862 fn = ScQtFileEdit::getSaveAsFileName(this, 3866 fn = ScQtFileEdit::getSaveAsFileName(this,
3863 tr ("Export text file"), 3867 tr ("Export text file"),
3864 QDir::homeDirPath() + "/Documents/application/zsafe", 3868 QDir::homeDirPath() + "/Documents/application/zsafe",
3865 "*.txt"); 3869 "*.txt");
3866#endif 3870#endif
3867#else 3871#else
3868 fn = QFileDialog::getSaveFileName( 3872 fn = QFileDialog::getSaveFileName(
3869 QDir::homeDirPath() + "/Documents/application/zsafe", 3873 QDir::homeDirPath() + "/Documents/application/zsafe",
3870 "ZSafe (*.txt)", 3874 "ZSafe (*.txt)",
3871 this, 3875 this,
3872 "ZSafe"); 3876 "ZSafe");
3873#endif 3877#endif
3874 return fn; 3878 return fn;
3875} 3879}