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