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