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