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