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