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