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