summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp15
-rw-r--r--pwmanager/pwmanager/pwmprefs.cpp1
-rw-r--r--pwmanager/pwmanager/pwmprefs.h4
-rw-r--r--pwmanager/pwmanager/pwmviewstyle.cpp32
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_0.cpp21
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_0.h6
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_1.cpp20
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_1.h5
-rw-r--r--pwmanager/pwmanager/serializer.cpp34
9 files changed, 107 insertions, 31 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 9fe4809..c167c2c 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -1,307 +1,309 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager 14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmdoc.h" 20#include "pwmdoc.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "blowfish.h" 22#include "blowfish.h"
23#include "sha1.h" 23#include "sha1.h"
24#include "globalstuff.h" 24#include "globalstuff.h"
25#include "gpasmanfile.h" 25#include "gpasmanfile.h"
26#include "serializer.h" 26#include "serializer.h"
27#include "compressgzip.h" 27#include "compressgzip.h"
28#include "compressbzip2.h" 28#include "compressbzip2.h"
29#include "randomizer.h" 29#include "randomizer.h"
30#include "pwminit.h" 30#include "pwminit.h"
31#ifndef PWM_EMBEDDED 31#ifndef PWM_EMBEDDED
32//US #include "libgryptif.h" 32//US #include "libgryptif.h"
33#else 33#else
34#include "pwmprefs.h" 34#include "pwmprefs.h"
35#include "kglobal.h" 35#include "kglobal.h"
36#endif 36#endif
37 37
38#ifdef CONFIG_KWALLETIF 38#ifdef CONFIG_KWALLETIF
39# include "kwalletemu.h" 39# include "kwalletemu.h"
40#endif // CONFIG_KWALLETIF 40#endif // CONFIG_KWALLETIF
41 41
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qsize.h> 43#include <qsize.h>
44#include <qfileinfo.h> 44#include <qfileinfo.h>
45#include <qfile.h> 45#include <qfile.h>
46 46
47#define __USE_GNU
48#define _GNU_SOURCE
47#include <stdio.h> 49#include <stdio.h>
48#include <stdlib.h> 50#include <stdlib.h>
49#include <errno.h> 51#include <errno.h>
50#include <string.h> 52#include <string.h>
51#include <iostream> 53//US#include <iostream>
52#include <algorithm> 54#include <algorithm>
53#include <sys/types.h> 55#include <sys/types.h>
54#include <sys/stat.h> 56#include <sys/stat.h>
55#include <unistd.h> 57#include <unistd.h>
56#include <stdint.h> 58#include <stdint.h>
57 59
58//TODO: reset to its normal value. 60//TODO: reset to its normal value.
59 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ 61 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */
60 62
61using namespace std; 63using namespace std;
62 64
63 65
64void PwMDocList::add(PwMDoc *doc, const string &id) 66void PwMDocList::add(PwMDoc *doc, const string &id)
65{ 67{
66#ifdef PWM_DEBUG 68#ifdef PWM_DEBUG
67 // check for existance of object in debug mode only. 69 // check for existance of object in debug mode only.
68 vector<listItem>::iterator begin = docList.begin(), 70 vector<listItem>::iterator begin = docList.begin(),
69 end = docList.end(), 71 end = docList.end(),
70 i = begin; 72 i = begin;
71 while (i != end) { 73 while (i != end) {
72 if (i->doc == doc) { 74 if (i->doc == doc) {
73 BUG(); 75 BUG();
74 return; 76 return;
75 } 77 }
76 ++i; 78 ++i;
77 } 79 }
78#endif 80#endif
79 listItem newItem; 81 listItem newItem;
80 newItem.doc = doc; 82 newItem.doc = doc;
81 newItem.docId = id; 83 newItem.docId = id;
82 docList.push_back(newItem); 84 docList.push_back(newItem);
83} 85}
84 86
85void PwMDocList::edit(PwMDoc *doc, const string &newId) 87void PwMDocList::edit(PwMDoc *doc, const string &newId)
86{ 88{
87 vector<listItem>::iterator begin = docList.begin(), 89 vector<listItem>::iterator begin = docList.begin(),
88 end = docList.end(), 90 end = docList.end(),
89 i = begin; 91 i = begin;
90 while (i != end) { 92 while (i != end) {
91 if (i->doc == doc) { 93 if (i->doc == doc) {
92 i->docId = newId; 94 i->docId = newId;
93 return; 95 return;
94 } 96 }
95 ++i; 97 ++i;
96 } 98 }
97} 99}
98 100
99void PwMDocList::del(PwMDoc *doc) 101void PwMDocList::del(PwMDoc *doc)
100{ 102{
101 vector<listItem>::iterator begin = docList.begin(), 103 vector<listItem>::iterator begin = docList.begin(),
102 end = docList.end(), 104 end = docList.end(),
103 i = begin; 105 i = begin;
104 while (i != end) { 106 while (i != end) {
105 if (i->doc == doc) { 107 if (i->doc == doc) {
106 docList.erase(i); 108 docList.erase(i);
107 return; 109 return;
108 } 110 }
109 ++i; 111 ++i;
110 } 112 }
111} 113}
112 114
113bool PwMDocList::find(const string &id, listItem *ret) 115bool PwMDocList::find(const string &id, listItem *ret)
114{ 116{
115 vector<listItem>::iterator begin = docList.begin(), 117 vector<listItem>::iterator begin = docList.begin(),
116 end = docList.end(), 118 end = docList.end(),
117 i = begin; 119 i = begin;
118 while (i != end) { 120 while (i != end) {
119 if (i->docId == id) { 121 if (i->docId == id) {
120 if (ret) 122 if (ret)
121 *ret = *i; 123 *ret = *i;
122 return true; 124 return true;
123 } 125 }
124 ++i; 126 ++i;
125 } 127 }
126 return false; 128 return false;
127} 129}
128 130
129 131
130 132
131DocTimer::DocTimer(PwMDoc *_doc) 133DocTimer::DocTimer(PwMDoc *_doc)
132 : doc (_doc) 134 : doc (_doc)
133 , mpwLock (0) 135 , mpwLock (0)
134 , autoLockLock (0) 136 , autoLockLock (0)
135 , metaCheckLock (0) 137 , metaCheckLock (0)
136{ 138{
137 mpwTimer = new QTimer; 139 mpwTimer = new QTimer;
138 autoLockTimer = new QTimer; 140 autoLockTimer = new QTimer;
139 metaCheckTimer = new QTimer; 141 metaCheckTimer = new QTimer;
140 connect(mpwTimer, SIGNAL(timeout()), 142 connect(mpwTimer, SIGNAL(timeout()),
141 this, SLOT(mpwTimeout())); 143 this, SLOT(mpwTimeout()));
142 connect(autoLockTimer, SIGNAL(timeout()), 144 connect(autoLockTimer, SIGNAL(timeout()),
143 this, SLOT(autoLockTimeout())); 145 this, SLOT(autoLockTimeout()));
144 connect(metaCheckTimer, SIGNAL(timeout()), 146 connect(metaCheckTimer, SIGNAL(timeout()),
145 this, SLOT(metaCheckTimeout())); 147 this, SLOT(metaCheckTimeout()));
146} 148}
147 149
148DocTimer::~DocTimer() 150DocTimer::~DocTimer()
149{ 151{
150 delete mpwTimer; 152 delete mpwTimer;
151 delete autoLockTimer; 153 delete autoLockTimer;
152 delete metaCheckTimer; 154 delete metaCheckTimer;
153} 155}
154 156
155void DocTimer::start(TimerIDs timer) 157void DocTimer::start(TimerIDs timer)
156{ 158{
157 switch (timer) { 159 switch (timer) {
158 case id_mpwTimer: 160 case id_mpwTimer:
159 if (mpwTimer->isActive()) 161 if (mpwTimer->isActive())
160 mpwTimer->stop(); 162 mpwTimer->stop();
161 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 163 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
162 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); 164 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
163 break; 165 break;
164 case id_autoLockTimer: 166 case id_autoLockTimer:
165 if (autoLockTimer->isActive()) 167 if (autoLockTimer->isActive())
166 autoLockTimer->stop(); 168 autoLockTimer->stop();
167 if (conf()->confGlobLockTimeout() > 0) 169 if (conf()->confGlobLockTimeout() > 0)
168 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); 170 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
169 break; 171 break;
170 case id_metaCheckTimer: 172 case id_metaCheckTimer:
171 if (metaCheckTimer->isActive()) 173 if (metaCheckTimer->isActive())
172 metaCheckTimer->stop(); 174 metaCheckTimer->stop();
173 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 175 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
174 break; 176 break;
175 } 177 }
176} 178}
177 179
178void DocTimer::stop(TimerIDs timer) 180void DocTimer::stop(TimerIDs timer)
179{ 181{
180 switch (timer) { 182 switch (timer) {
181 case id_mpwTimer: 183 case id_mpwTimer:
182 mpwTimer->stop(); 184 mpwTimer->stop();
183 break; 185 break;
184 case id_autoLockTimer: 186 case id_autoLockTimer:
185 autoLockTimer->stop(); 187 autoLockTimer->stop();
186 break; 188 break;
187 case id_metaCheckTimer: 189 case id_metaCheckTimer:
188 metaCheckTimer->stop(); 190 metaCheckTimer->stop();
189 break; 191 break;
190 } 192 }
191} 193}
192 194
193void DocTimer::getLock(TimerIDs timer) 195void DocTimer::getLock(TimerIDs timer)
194{ 196{
195 switch (timer) { 197 switch (timer) {
196 case id_mpwTimer: 198 case id_mpwTimer:
197 ++mpwLock; 199 ++mpwLock;
198 break; 200 break;
199 case id_autoLockTimer: 201 case id_autoLockTimer:
200 ++autoLockLock; 202 ++autoLockLock;
201 break; 203 break;
202 case id_metaCheckTimer: 204 case id_metaCheckTimer:
203 ++metaCheckLock; 205 ++metaCheckLock;
204 break; 206 break;
205 } 207 }
206} 208}
207 209
208void DocTimer::putLock(TimerIDs timer) 210void DocTimer::putLock(TimerIDs timer)
209{ 211{
210 switch (timer) { 212 switch (timer) {
211 case id_mpwTimer: 213 case id_mpwTimer:
212 if (mpwLock) 214 if (mpwLock)
213 --mpwLock; 215 --mpwLock;
214 break; 216 break;
215 case id_autoLockTimer: 217 case id_autoLockTimer:
216 if (autoLockLock) 218 if (autoLockLock)
217 --autoLockLock; 219 --autoLockLock;
218 break; 220 break;
219 case id_metaCheckTimer: 221 case id_metaCheckTimer:
220 if (metaCheckLock) 222 if (metaCheckLock)
221 --metaCheckLock; 223 --metaCheckLock;
222 break; 224 break;
223 } 225 }
224} 226}
225 227
226void DocTimer::mpwTimeout() 228void DocTimer::mpwTimeout()
227{ 229{
228 if (mpwLock) { 230 if (mpwLock) {
229 mpwTimer->start(1000, true); 231 mpwTimer->start(1000, true);
230 return; 232 return;
231 } 233 }
232 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); 234 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
233} 235}
234 236
235void DocTimer::autoLockTimeout() 237void DocTimer::autoLockTimeout()
236{ 238{
237 if (autoLockLock) { 239 if (autoLockLock) {
238 autoLockTimer->start(1000, true); 240 autoLockTimer->start(1000, true);
239 return; 241 return;
240 } 242 }
241 if (conf()->confGlobAutoDeepLock() && 243 if (conf()->confGlobAutoDeepLock() &&
242 doc->filename != QString::null && 244 doc->filename != QString::null &&
243 doc->filename != "") { 245 doc->filename != "") {
244 doc->deepLock(true); 246 doc->deepLock(true);
245 } else { 247 } else {
246 doc->lockAll(true); 248 doc->lockAll(true);
247 } 249 }
248} 250}
249 251
250void DocTimer::metaCheckTimeout() 252void DocTimer::metaCheckTimeout()
251{ 253{
252 if (metaCheckLock) { 254 if (metaCheckLock) {
253 // check again in one second. 255 // check again in one second.
254 metaCheckTimer->start(1000, true); 256 metaCheckTimer->start(1000, true);
255 return; 257 return;
256 } 258 }
257 if (doc->isDeepLocked()) { 259 if (doc->isDeepLocked()) {
258 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 260 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
259 return; 261 return;
260 } 262 }
261 if (doc->isDocEmpty()) { 263 if (doc->isDocEmpty()) {
262 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 264 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
263 return; 265 return;
264 } 266 }
265#ifdef CONFIG_KWALLETIF 267#ifdef CONFIG_KWALLETIF
266 KWalletEmu *kwlEmu = doc->init->kwalletEmu(); 268 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
267 if (kwlEmu) 269 if (kwlEmu)
268 kwlEmu->suspendDocSignals(); 270 kwlEmu->suspendDocSignals();
269#endif // CONFIG_KWALLETIF 271#endif // CONFIG_KWALLETIF
270 /* We simply trigger all views to update their 272 /* We simply trigger all views to update their
271 * displayed values. This way they have a chance 273 * displayed values. This way they have a chance
272 * to get notified when some meta changes over time. 274 * to get notified when some meta changes over time.
273 * (for example an entry expired). 275 * (for example an entry expired).
274 * The _view_ is responsive for not updating its 276 * The _view_ is responsive for not updating its
275 * contents if nothing really changed! 277 * contents if nothing really changed!
276 */ 278 */
277 emit doc->dataChanged(doc); 279 emit doc->dataChanged(doc);
278#ifdef CONFIG_KWALLETIF 280#ifdef CONFIG_KWALLETIF
279 if (kwlEmu) 281 if (kwlEmu)
280 kwlEmu->resumeDocSignals(); 282 kwlEmu->resumeDocSignals();
281#endif // CONFIG_KWALLETIF 283#endif // CONFIG_KWALLETIF
282 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); 284 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
283} 285}
284 286
285 287
286 288
287PwMDocList PwMDoc::openDocList; 289PwMDocList PwMDoc::openDocList;
288unsigned int PwMDocList::unnamedDocCnt = 1; 290unsigned int PwMDocList::unnamedDocCnt = 1;
289 291
290PwMDoc::PwMDoc(QObject *parent, const char *name) 292PwMDoc::PwMDoc(QObject *parent, const char *name)
291 : PwMDocUi(parent, name) 293 : PwMDocUi(parent, name)
292 , dataChangedLock (0) 294 , dataChangedLock (0)
293{ 295{
294 deleted = false; 296 deleted = false;
295 unnamedNum = 0; 297 unnamedNum = 0;
296 getOpenDocList()->add(this, getTitle().latin1()); 298 getOpenDocList()->add(this, getTitle().latin1());
297 curDocStat = 0; 299 curDocStat = 0;
298 setMaxNumEntries(); 300 setMaxNumEntries();
299 _timer = new DocTimer(this); 301 _timer = new DocTimer(this);
300 timer()->start(DocTimer::id_mpwTimer); 302 timer()->start(DocTimer::id_mpwTimer);
301 timer()->start(DocTimer::id_autoLockTimer); 303 timer()->start(DocTimer::id_autoLockTimer);
302 timer()->start(DocTimer::id_metaCheckTimer); 304 timer()->start(DocTimer::id_metaCheckTimer);
303 addCategory(DEFAULT_CATEGORY, 0, false); 305 addCategory(DEFAULT_CATEGORY, 0, false);
304 listView = 0; 306 listView = 0;
305 emit docCreated(this); 307 emit docCreated(this);
306} 308}
307 309
@@ -901,520 +903,531 @@ PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
901bool PwMDoc::backupFile(const QString &filePath) 903bool PwMDoc::backupFile(const QString &filePath)
902{ 904{
903 QFileInfo fi(filePath); 905 QFileInfo fi(filePath);
904 if (!fi.exists()) 906 if (!fi.exists())
905 return true; // Yes, true is correct. 907 return true; // Yes, true is correct.
906 QString pathOnly(fi.dirPath(true)); 908 QString pathOnly(fi.dirPath(true));
907 QString nameOnly(fi.fileName()); 909 QString nameOnly(fi.fileName());
908 QString backupPath = pathOnly 910 QString backupPath = pathOnly
909 + "/~" 911 + "/~"
910 + nameOnly 912 + nameOnly
911 + ".backup"; 913 + ".backup";
912 return copyFile(filePath, backupPath); 914 return copyFile(filePath, backupPath);
913} 915}
914 916
915bool PwMDoc::copyFile(const QString &src, const QString &dst) 917bool PwMDoc::copyFile(const QString &src, const QString &dst)
916{ 918{
917 QFileInfo fi(src); 919 QFileInfo fi(src);
918 if (!fi.exists()) 920 if (!fi.exists())
919 return false; 921 return false;
920 if (QFile::exists(dst)) { 922 if (QFile::exists(dst)) {
921 if (!QFile::remove(dst)) 923 if (!QFile::remove(dst))
922 return false; 924 return false;
923 } 925 }
924 QFile srcFd(src); 926 QFile srcFd(src);
925 if (!srcFd.open(IO_ReadOnly)) 927 if (!srcFd.open(IO_ReadOnly))
926 return false; 928 return false;
927 QFile dstFd(dst); 929 QFile dstFd(dst);
928 if (!dstFd.open(IO_ReadWrite)) { 930 if (!dstFd.open(IO_ReadWrite)) {
929 srcFd.close(); 931 srcFd.close();
930 return false; 932 return false;
931 } 933 }
932 const int tmpBuf_size = 512; 934 const int tmpBuf_size = 512;
933 char tmpBuf[tmpBuf_size]; 935 char tmpBuf[tmpBuf_size];
934#ifndef PWM_EMBEDDED 936#ifndef PWM_EMBEDDED
935 Q_LONG bytesRead, bytesWritten; 937 Q_LONG bytesRead, bytesWritten;
936#else 938#else
937 long bytesRead, bytesWritten; 939 long bytesRead, bytesWritten;
938#endif 940#endif
939 while (!srcFd.atEnd()) { 941 while (!srcFd.atEnd()) {
940#ifndef PWM_EMBEDDED 942#ifndef PWM_EMBEDDED
941 bytesRead = srcFd.readBlock(tmpBuf, 943 bytesRead = srcFd.readBlock(tmpBuf,
942 static_cast<Q_ULONG>(tmpBuf_size)); 944 static_cast<Q_ULONG>(tmpBuf_size));
943#else 945#else
944 bytesRead = srcFd.readBlock(tmpBuf, 946 bytesRead = srcFd.readBlock(tmpBuf,
945 (unsigned long)(tmpBuf_size)); 947 (unsigned long)(tmpBuf_size));
946#endif 948#endif
947 if (bytesRead == -1) { 949 if (bytesRead == -1) {
948 srcFd.close(); 950 srcFd.close();
949 dstFd.close(); 951 dstFd.close();
950 return false; 952 return false;
951 } 953 }
952#ifndef PWM_EMBEDDED 954#ifndef PWM_EMBEDDED
953 bytesWritten = dstFd.writeBlock(tmpBuf, 955 bytesWritten = dstFd.writeBlock(tmpBuf,
954 static_cast<Q_ULONG>(bytesRead)); 956 static_cast<Q_ULONG>(bytesRead));
955#else 957#else
956 bytesWritten = dstFd.writeBlock(tmpBuf, 958 bytesWritten = dstFd.writeBlock(tmpBuf,
957 (unsigned long)(bytesRead)); 959 (unsigned long)(bytesRead));
958#endif 960#endif
959 if (bytesWritten != bytesRead) { 961 if (bytesWritten != bytesRead) {
960 srcFd.close(); 962 srcFd.close();
961 dstFd.close(); 963 dstFd.close();
962 return false; 964 return false;
963 } 965 }
964 } 966 }
965 srcFd.close(); 967 srcFd.close();
966 dstFd.close(); 968 dstFd.close();
967 return true; 969 return true;
968} 970}
969 971
970PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, 972PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
971 bool dontFlagDirty, bool updateMeta) 973 bool dontFlagDirty, bool updateMeta)
972{ 974{
973 PWM_ASSERT(d); 975 PWM_ASSERT(d);
974 unsigned int cat = 0; 976 unsigned int cat = 0;
975 977
976 if (isDeepLocked()) { 978 if (isDeepLocked()) {
977 PwMerror ret; 979 PwMerror ret;
978 ret = deepLock(false); 980 ret = deepLock(false);
979 if (ret != e_success) 981 if (ret != e_success)
980 return e_lock; 982 return e_lock;
981 } 983 }
982 984
983 addCategory(category, &cat); 985 addCategory(category, &cat);
984 986
985 if (numEntries(category) >= maxEntries) 987 if (numEntries(category) >= maxEntries)
986 return e_maxAllowedEntr; 988 return e_maxAllowedEntr;
987 989
988 vector<unsigned int> foundPositions; 990 vector<unsigned int> foundPositions;
989 /* historically this was: 991 /* historically this was:
990 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | 992 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
991 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; 993 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
992 * But for now we only search in desc. 994 * But for now we only search in desc.
993 * That's a tweak to be KWallet compatible. But it should not add 995 * That's a tweak to be KWallet compatible. But it should not add
994 * usability-drop onto PwManager, does it? 996 * usability-drop onto PwManager, does it?
995 * (And yes, "int" was a bug. Correct is "unsigned int") 997 * (And yes, "int" was a bug. Correct is "unsigned int")
996 */ 998 */
997 const unsigned int searchIn = SEARCH_IN_DESC; 999 const unsigned int searchIn = SEARCH_IN_DESC;
998 findEntry(cat, *d, searchIn, &foundPositions, true); 1000 findEntry(cat, *d, searchIn, &foundPositions, true);
999 if (foundPositions.size()) { 1001 if (foundPositions.size()) {
1000 // DOH! We found this entry. 1002 // DOH! We found this entry.
1001 return e_entryExists; 1003 return e_entryExists;
1002 } 1004 }
1003 1005
1004 d->listViewPos = -1; 1006 d->listViewPos = -1;
1005 d->lockStat = conf()->confGlobNewEntrLockStat(); 1007 d->lockStat = conf()->confGlobNewEntrLockStat();
1006 if (updateMeta) { 1008 if (updateMeta) {
1007 d->meta.create = QDateTime::currentDateTime(); 1009 d->meta.create = QDateTime::currentDateTime();
1008 d->meta.update = d->meta.create; 1010 d->meta.update = d->meta.create;
1009 } 1011 }
1010 dta[cat].d.push_back(*d); 1012 dta[cat].d.push_back(*d);
1011 1013
1012 delAllEmptyCat(true); 1014 delAllEmptyCat(true);
1013 1015
1014 if (!dontFlagDirty) 1016 if (!dontFlagDirty)
1015 flagDirty(); 1017 flagDirty();
1016 return e_success; 1018 return e_success;
1017} 1019}
1018 1020
1019PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, 1021PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
1020 bool checkIfExist) 1022 bool checkIfExist)
1021{ 1023{
1022 if (isDeepLocked()) { 1024 if (isDeepLocked()) {
1023 PwMerror ret; 1025 PwMerror ret;
1024 ret = deepLock(false); 1026 ret = deepLock(false);
1025 if (ret != e_success) 1027 if (ret != e_success)
1026 return e_lock; 1028 return e_lock;
1027 } 1029 }
1028 if (checkIfExist) { 1030 if (checkIfExist) {
1029 if (findCategory(category, categoryIndex)) 1031 if (findCategory(category, categoryIndex))
1030 return e_categoryExists; 1032 return e_categoryExists;
1031 } 1033 }
1032 PwMCategoryItem item; 1034 PwMCategoryItem item;
1033 item.name = category.latin1(); 1035 item.name = category.latin1();
1034 dta.push_back(item); 1036 dta.push_back(item);
1035 if (categoryIndex) 1037 if (categoryIndex)
1036 *categoryIndex = dta.size() - 1; 1038 *categoryIndex = dta.size() - 1;
1037 return e_success; 1039 return e_success;
1038} 1040}
1039 1041
1040bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) 1042bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1041{ 1043{
1042 unsigned int cat = 0; 1044 unsigned int cat = 0;
1043 1045
1044 if (!findCategory(category, &cat)) { 1046 if (!findCategory(category, &cat)) {
1045 BUG(); 1047 BUG();
1046 return false; 1048 return false;
1047 } 1049 }
1048 1050
1049 return delEntry(cat, index, dontFlagDirty); 1051 return delEntry(cat, index, dontFlagDirty);
1050} 1052}
1051 1053
1052bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) 1054bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1053{ 1055{
1054 if (isDeepLocked()) 1056 if (isDeepLocked())
1055 return false; 1057 return false;
1056 if (index > dta[category].d.size() - 1) 1058 if (index > dta[category].d.size() - 1)
1057 return false; 1059 return false;
1058 getDataChangedLock(); 1060 getDataChangedLock();
1059 if (!lockAt(category, index, false)) { 1061 if (!lockAt(category, index, false)) {
1060 putDataChangedLock(); 1062 putDataChangedLock();
1061 return false; 1063 return false;
1062 } 1064 }
1063 putDataChangedLock(); 1065 putDataChangedLock();
1064 int lvPos = dta[category].d[index].listViewPos; 1066 int lvPos = dta[category].d[index].listViewPos;
1065 1067
1066 // delete entry 1068 // delete entry
1067 dta[category].d.erase(dta[category].d.begin() + index); 1069 dta[category].d.erase(dta[category].d.begin() + index);
1068 1070
1069 unsigned int i, entries = numEntries(category); 1071 unsigned int i, entries = numEntries(category);
1070 if (!entries) { 1072 if (!entries) {
1071 // no more entries in this category, so 1073 // no more entries in this category, so
1072 // we can delete it, too. 1074 // we can delete it, too.
1073 BUG_ON(!delCategory(category)); 1075 BUG_ON(!delCategory(category));
1074 // delCategory() flags it dirty, so we need not to do so. 1076 // delCategory() flags it dirty, so we need not to do so.
1075 return true; 1077 return true;
1076 } 1078 }
1077 for (i = 0; i < entries; ++i) { 1079 for (i = 0; i < entries; ++i) {
1078 // decrement all listViewPositions that are greater than the deleted. 1080 // decrement all listViewPositions that are greater than the deleted.
1079 if (dta[category].d[i].listViewPos > lvPos) 1081 if (dta[category].d[i].listViewPos > lvPos)
1080 --dta[category].d[i].listViewPos; 1082 --dta[category].d[i].listViewPos;
1081 } 1083 }
1082 1084
1083 if (!dontFlagDirty) 1085 if (!dontFlagDirty)
1084 flagDirty(); 1086 flagDirty();
1085 return true; 1087 return true;
1086} 1088}
1087 1089
1088bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, 1090bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1089 unsigned int index, PwMDataItem *d, bool updateMeta) 1091 unsigned int index, PwMDataItem *d, bool updateMeta)
1090{ 1092{
1091 PWM_ASSERT(d); 1093 PWM_ASSERT(d);
1092 unsigned int oldCat = 0; 1094 unsigned int oldCat = 0;
1093 1095
1094 if (!findCategory(oldCategory, &oldCat)) { 1096 if (!findCategory(oldCategory, &oldCat)) {
1095 BUG(); 1097 BUG();
1096 return false; 1098 return false;
1097 } 1099 }
1098 1100
1099 return editEntry(oldCat, newCategory, index, d, updateMeta); 1101 return editEntry(oldCat, newCategory, index, d, updateMeta);
1100} 1102}
1101 1103
1102bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, 1104bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1103 unsigned int index, PwMDataItem *d, bool updateMeta) 1105 unsigned int index, PwMDataItem *d, bool updateMeta)
1104{ 1106{
1105 if (isDeepLocked()) 1107 if (isDeepLocked())
1106 return false; 1108 return false;
1107 if (updateMeta) { 1109 if (updateMeta) {
1108 d->meta.update = QDateTime::currentDateTime(); 1110 d->meta.update = QDateTime::currentDateTime();
1109 if (d->meta.create.isNull()) { 1111 if (d->meta.create.isNull()) {
1110 d->meta.create = d->meta.update; 1112 d->meta.create = d->meta.update;
1111 } 1113 }
1112 } 1114 }
1113 if (dta[oldCategory].name != newCategory.latin1()) { 1115 if (dta[oldCategory].name != newCategory.latin1()) {
1114 // the user changed the category. 1116 // the user changed the category.
1115 PwMerror ret; 1117 PwMerror ret;
1116 d->rev = 0; 1118 d->rev = 0;
1117 ret = addEntry(newCategory, d, true, false); 1119 ret = addEntry(newCategory, d, true, false);
1118 if (ret != e_success) 1120 if (ret != e_success)
1119 return false; 1121 return false;
1120 if (!delEntry(oldCategory, index, true)) 1122 if (!delEntry(oldCategory, index, true))
1121 return false; 1123 return false;
1122 } else { 1124 } else {
1123 d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. 1125 d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter.
1124 dta[oldCategory].d[index] = *d; 1126 dta[oldCategory].d[index] = *d;
1125 } 1127 }
1126 flagDirty(); 1128 flagDirty();
1127 return true; 1129 return true;
1128} 1130}
1129 1131
1130unsigned int PwMDoc::numEntries(const QString &category) 1132unsigned int PwMDoc::numEntries(const QString &category)
1131{ 1133{
1132 unsigned int cat = 0; 1134 unsigned int cat = 0;
1133 1135
1134 if (!findCategory(category, &cat)) { 1136 if (!findCategory(category, &cat)) {
1135 BUG(); 1137 BUG();
1136 return 0; 1138 return 0;
1137 } 1139 }
1138 1140
1139 return numEntries(cat); 1141 return numEntries(cat);
1140} 1142}
1141 1143
1142bool PwMDoc::serializeDta(string *d) 1144bool PwMDoc::serializeDta(string *d)
1143{ 1145{
1144 PWM_ASSERT(d); 1146 PWM_ASSERT(d);
1145 Serializer ser; 1147 Serializer ser;
1146 if (!ser.serialize(dta)) 1148 if (!ser.serialize(dta))
1147 return false; 1149 return false;
1148 d->assign(ser.getXml()); 1150 d->assign(ser.getXml());
1149 if (!d->size()) 1151 if (!d->size())
1150 return false; 1152 return false;
1151 return true; 1153 return true;
1152} 1154}
1153 1155
1154bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) 1156bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1155{ 1157{
1156 PWM_ASSERT(d); 1158 PWM_ASSERT(d);
1159#ifndef PWM_EMBEDDED
1157 try { 1160 try {
1161
1158 Serializer ser(d->c_str()); 1162 Serializer ser(d->c_str());
1159 ser.setDefaultLockStat(entriesLocked); 1163 ser.setDefaultLockStat(entriesLocked);
1160 if (!ser.deSerialize(&dta)) 1164 if (!ser.deSerialize(&dta))
1161 return false; 1165 return false;
1162 } catch (PwMException) { 1166 } catch (PwMException) {
1163 return false; 1167 return false;
1164 } 1168 }
1169#else
1170 Serializer ser(d->c_str());
1171 ser.setDefaultLockStat(entriesLocked);
1172 if (!ser.deSerialize(&dta))
1173 return false;
1174 else
1175 return false;
1176#endif
1177
1165 emitDataChanged(this); 1178 emitDataChanged(this);
1166 return true; 1179 return true;
1167} 1180}
1168 1181
1169bool PwMDoc::getEntry(const QString &category, unsigned int index, 1182bool PwMDoc::getEntry(const QString &category, unsigned int index,
1170 PwMDataItem * d, bool unlockIfLocked) 1183 PwMDataItem * d, bool unlockIfLocked)
1171{ 1184{
1172 PWM_ASSERT(d); 1185 PWM_ASSERT(d);
1173 unsigned int cat = 0; 1186 unsigned int cat = 0;
1174 1187
1175 if (!findCategory(category, &cat)) { 1188 if (!findCategory(category, &cat)) {
1176 BUG(); 1189 BUG();
1177 return false; 1190 return false;
1178 } 1191 }
1179 1192
1180 return getEntry(cat, index, d, unlockIfLocked); 1193 return getEntry(cat, index, d, unlockIfLocked);
1181} 1194}
1182 1195
1183bool PwMDoc::getEntry(unsigned int category, unsigned int index, 1196bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1184 PwMDataItem *d, bool unlockIfLocked) 1197 PwMDataItem *d, bool unlockIfLocked)
1185{ 1198{
1186 if (index > dta[category].d.size() - 1) 1199 if (index > dta[category].d.size() - 1)
1187 return false; 1200 return false;
1188 1201
1189 bool locked = isLocked(category, index); 1202 bool locked = isLocked(category, index);
1190 if (locked) { 1203 if (locked) {
1191 /* this entry is locked. We don't return a password, 1204 /* this entry is locked. We don't return a password,
1192 * until it's unlocked by the user by inserting 1205 * until it's unlocked by the user by inserting
1193 * chipcard or entering the mpw 1206 * chipcard or entering the mpw
1194 */ 1207 */
1195 if (unlockIfLocked) { 1208 if (unlockIfLocked) {
1196 if (!lockAt(category, index, false)) { 1209 if (!lockAt(category, index, false)) {
1197 return false; 1210 return false;
1198 } 1211 }
1199 locked = false; 1212 locked = false;
1200 } 1213 }
1201 } 1214 }
1202 1215
1203 *d = dta[category].d[index]; 1216 *d = dta[category].d[index];
1204 if (locked) 1217 if (locked)
1205 d->pw = LOCKED_STRING.latin1(); 1218 d->pw = LOCKED_STRING.latin1();
1206 1219
1207 return true; 1220 return true;
1208} 1221}
1209 1222
1210PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, 1223PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1211 string *foundComment) 1224 string *foundComment)
1212{ 1225{
1213 PWM_ASSERT(foundComment); 1226 PWM_ASSERT(foundComment);
1214 unsigned int cat = 0; 1227 unsigned int cat = 0;
1215 1228
1216 if (!findCategory(category, &cat)) 1229 if (!findCategory(category, &cat))
1217 return e_invalidArg; 1230 return e_invalidArg;
1218 1231
1219 unsigned int i, entries = numEntries(cat); 1232 unsigned int i, entries = numEntries(cat);
1220 for (i = 0; i < entries; ++i) { 1233 for (i = 0; i < entries; ++i) {
1221 if (dta[cat].d[i].listViewPos == listViewPos) { 1234 if (dta[cat].d[i].listViewPos == listViewPos) {
1222 *foundComment = dta[cat].d[i].comment; 1235 *foundComment = dta[cat].d[i].comment;
1223 if (dta[cat].d[i].binary) 1236 if (dta[cat].d[i].binary)
1224 return e_binEntry; 1237 return e_binEntry;
1225 return e_normalEntry; 1238 return e_normalEntry;
1226 } 1239 }
1227 } 1240 }
1228 BUG(); 1241 BUG();
1229 return e_generic; 1242 return e_generic;
1230} 1243}
1231 1244
1232bool PwMDoc::compressDta(string *d, char algo) 1245bool PwMDoc::compressDta(string *d, char algo)
1233{ 1246{
1234 PWM_ASSERT(d); 1247 PWM_ASSERT(d);
1235 switch (algo) { 1248 switch (algo) {
1236 case PWM_COMPRESS_GZIP: { 1249 case PWM_COMPRESS_GZIP: {
1237 CompressGzip comp; 1250 CompressGzip comp;
1238 return comp.compress(d); 1251 return comp.compress(d);
1239 } case PWM_COMPRESS_BZIP2: { 1252 } case PWM_COMPRESS_BZIP2: {
1240 CompressBzip2 comp; 1253 CompressBzip2 comp;
1241 return comp.compress(d); 1254 return comp.compress(d);
1242 } case PWM_COMPRESS_NONE: { 1255 } case PWM_COMPRESS_NONE: {
1243 return true; 1256 return true;
1244 } default: { 1257 } default: {
1245 BUG(); 1258 BUG();
1246 } 1259 }
1247 } 1260 }
1248 return false; 1261 return false;
1249} 1262}
1250 1263
1251bool PwMDoc::decompressDta(string *d, char algo) 1264bool PwMDoc::decompressDta(string *d, char algo)
1252{ 1265{
1253 PWM_ASSERT(d); 1266 PWM_ASSERT(d);
1254 switch (algo) { 1267 switch (algo) {
1255 case PWM_COMPRESS_GZIP: { 1268 case PWM_COMPRESS_GZIP: {
1256 CompressGzip comp; 1269 CompressGzip comp;
1257 return comp.decompress(d); 1270 return comp.decompress(d);
1258 } case PWM_COMPRESS_BZIP2: { 1271 } case PWM_COMPRESS_BZIP2: {
1259 CompressBzip2 comp; 1272 CompressBzip2 comp;
1260 return comp.decompress(d); 1273 return comp.decompress(d);
1261 } case PWM_COMPRESS_NONE: { 1274 } case PWM_COMPRESS_NONE: {
1262 return true; 1275 return true;
1263 } 1276 }
1264 } 1277 }
1265 return false; 1278 return false;
1266} 1279}
1267 1280
1268PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) 1281PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
1269{ 1282{
1270 PWM_ASSERT(d); 1283 PWM_ASSERT(d);
1271 PWM_ASSERT(pw); 1284 PWM_ASSERT(pw);
1272 PWM_ASSERT(f); 1285 PWM_ASSERT(f);
1273 1286
1274 size_t encSize; 1287 size_t encSize;
1275 byte *encrypted = 0; 1288 byte *encrypted = 0;
1276 1289
1277 switch (algo) { 1290 switch (algo) {
1278 case PWM_CRYPT_BLOWFISH: { 1291 case PWM_CRYPT_BLOWFISH: {
1279 Blowfish::padNull(d); 1292 Blowfish::padNull(d);
1280 encSize = d->length(); 1293 encSize = d->length();
1281 encrypted = new byte[encSize]; 1294 encrypted = new byte[encSize];
1282 Blowfish bf; 1295 Blowfish bf;
1283 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { 1296 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1284 delete [] encrypted; 1297 delete [] encrypted;
1285 return e_weakPw; 1298 return e_weakPw;
1286 } 1299 }
1287 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); 1300 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1288 break; 1301 break;
1289 } 1302 }
1290 #ifndef PWM_EMBEDDED 1303 #ifndef PWM_EMBEDDED
1291 case PWM_CRYPT_AES128: 1304 case PWM_CRYPT_AES128:
1292 /*... fall through */ 1305 /*... fall through */
1293 case PWM_CRYPT_AES192: 1306 case PWM_CRYPT_AES192:
1294 case PWM_CRYPT_AES256: 1307 case PWM_CRYPT_AES256:
1295 case PWM_CRYPT_3DES: 1308 case PWM_CRYPT_3DES:
1296 case PWM_CRYPT_TWOFISH: 1309 case PWM_CRYPT_TWOFISH:
1297 case PWM_CRYPT_TWOFISH128: { 1310 case PWM_CRYPT_TWOFISH128: {
1298 if (!LibGCryptIf::available()) 1311 if (!LibGCryptIf::available())
1299 return e_cryptNotImpl; 1312 return e_cryptNotImpl;
1300 LibGCryptIf gc; 1313 LibGCryptIf gc;
1301 PwMerror err; 1314 PwMerror err;
1302 unsigned char *plain = new unsigned char[d->length() + 1024]; 1315 unsigned char *plain = new unsigned char[d->length() + 1024];
1303 memcpy(plain, d->c_str(), d->length()); 1316 memcpy(plain, d->c_str(), d->length());
1304 err = gc.encrypt(&encrypted, 1317 err = gc.encrypt(&encrypted,
1305 &encSize, 1318 &encSize,
1306 plain, 1319 plain,
1307 d->length(), 1320 d->length(),
1308 reinterpret_cast<const unsigned char *>(pw->latin1()), 1321 reinterpret_cast<const unsigned char *>(pw->latin1()),
1309 pw->length(), 1322 pw->length(),
1310 algo); 1323 algo);
1311 delete [] plain; 1324 delete [] plain;
1312 if (err != e_success) 1325 if (err != e_success)
1313 return e_cryptNotImpl; 1326 return e_cryptNotImpl;
1314 break; 1327 break;
1315 } 1328 }
1316#endif 1329#endif
1317 default: { 1330 default: {
1318 delete_ifnot_null_array(encrypted); 1331 delete_ifnot_null_array(encrypted);
1319 return e_cryptNotImpl; 1332 return e_cryptNotImpl;
1320 } } 1333 } }
1321 1334
1322 // write encrypted data to file 1335 // write encrypted data to file
1323#ifndef PWM_EMBEDDED 1336#ifndef PWM_EMBEDDED
1324 if (f->writeBlock(reinterpret_cast<const char *>(encrypted), 1337 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1325 static_cast<Q_ULONG>(encSize)) 1338 static_cast<Q_ULONG>(encSize))
1326 != static_cast<Q_LONG>(encSize)) { 1339 != static_cast<Q_LONG>(encSize)) {
1327 delete_ifnot_null_array(encrypted); 1340 delete_ifnot_null_array(encrypted);
1328 return e_writeFile; 1341 return e_writeFile;
1329 } 1342 }
1330#else 1343#else
1331 if (f->writeBlock((const char *)(encrypted), 1344 if (f->writeBlock((const char *)(encrypted),
1332 (unsigned long)(encSize)) 1345 (unsigned long)(encSize))
1333 != (long)(encSize)) { 1346 != (long)(encSize)) {
1334 delete_ifnot_null_array(encrypted); 1347 delete_ifnot_null_array(encrypted);
1335 return e_writeFile; 1348 return e_writeFile;
1336 } 1349 }
1337#endif 1350#endif
1338 delete_ifnot_null_array(encrypted); 1351 delete_ifnot_null_array(encrypted);
1339 return e_success; 1352 return e_success;
1340} 1353}
1341 1354
1342PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, 1355PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1343 char algo, QFile *f) 1356 char algo, QFile *f)
1344{ 1357{
1345 PWM_ASSERT(d); 1358 PWM_ASSERT(d);
1346 PWM_ASSERT(pw); 1359 PWM_ASSERT(pw);
1347 PWM_ASSERT(f); 1360 PWM_ASSERT(f);
1348 1361
1349 unsigned int cryptLen = f->size() - pos; 1362 unsigned int cryptLen = f->size() - pos;
1350 byte *encrypted = new byte[cryptLen]; 1363 byte *encrypted = new byte[cryptLen];
1351 byte *decrypted = new byte[cryptLen]; 1364 byte *decrypted = new byte[cryptLen];
1352 1365
1353 f->at(pos); 1366 f->at(pos);
1354#ifndef PWM_EMBEDDED 1367#ifndef PWM_EMBEDDED
1355 if (f->readBlock(reinterpret_cast<char *>(encrypted), 1368 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1356 static_cast<Q_ULONG>(cryptLen)) 1369 static_cast<Q_ULONG>(cryptLen))
1357 != static_cast<Q_LONG>(cryptLen)) { 1370 != static_cast<Q_LONG>(cryptLen)) {
1358 delete [] encrypted; 1371 delete [] encrypted;
1359 delete [] decrypted; 1372 delete [] decrypted;
1360 return e_readFile; 1373 return e_readFile;
1361 } 1374 }
1362#else 1375#else
1363 if (f->readBlock((char *)(encrypted), 1376 if (f->readBlock((char *)(encrypted),
1364 (unsigned long)(cryptLen)) 1377 (unsigned long)(cryptLen))
1365 != (long)(cryptLen)) { 1378 != (long)(cryptLen)) {
1366 delete [] encrypted; 1379 delete [] encrypted;
1367 delete [] decrypted; 1380 delete [] decrypted;
1368 return e_readFile; 1381 return e_readFile;
1369 } 1382 }
1370#endif 1383#endif
1371 switch (algo) { 1384 switch (algo) {
1372 case PWM_CRYPT_BLOWFISH: { 1385 case PWM_CRYPT_BLOWFISH: {
1373 Blowfish bf; 1386 Blowfish bf;
1374 bf.bf_setkey((byte *) pw->latin1(), pw->length()); 1387 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1375 bf.bf_decrypt(decrypted, encrypted, cryptLen); 1388 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1376 break; 1389 break;
1377 } 1390 }
1378#ifndef PWM_EMBEDDED 1391#ifndef PWM_EMBEDDED
1379 case PWM_CRYPT_AES128: 1392 case PWM_CRYPT_AES128:
1380 /*... fall through */ 1393 /*... fall through */
1381 case PWM_CRYPT_AES192: 1394 case PWM_CRYPT_AES192:
1382 case PWM_CRYPT_AES256: 1395 case PWM_CRYPT_AES256:
1383 case PWM_CRYPT_3DES: 1396 case PWM_CRYPT_3DES:
1384 case PWM_CRYPT_TWOFISH: 1397 case PWM_CRYPT_TWOFISH:
1385 case PWM_CRYPT_TWOFISH128: { 1398 case PWM_CRYPT_TWOFISH128: {
1386 if (!LibGCryptIf::available()) 1399 if (!LibGCryptIf::available())
1387 return e_cryptNotImpl; 1400 return e_cryptNotImpl;
1388 LibGCryptIf gc; 1401 LibGCryptIf gc;
1389 PwMerror err; 1402 PwMerror err;
1390 err = gc.decrypt(&decrypted, 1403 err = gc.decrypt(&decrypted,
1391 &cryptLen, 1404 &cryptLen,
1392 encrypted, 1405 encrypted,
1393 cryptLen, 1406 cryptLen,
1394 reinterpret_cast<const unsigned char *>(pw->latin1()), 1407 reinterpret_cast<const unsigned char *>(pw->latin1()),
1395 pw->length(), 1408 pw->length(),
1396 algo); 1409 algo);
1397 if (err != e_success) { 1410 if (err != e_success) {
1398 delete [] encrypted; 1411 delete [] encrypted;
1399 delete [] decrypted; 1412 delete [] decrypted;
1400 return e_cryptNotImpl; 1413 return e_cryptNotImpl;
1401 } 1414 }
1402 break; 1415 break;
1403 } 1416 }
1404#endif 1417#endif
1405 default: { 1418 default: {
1406 delete [] encrypted; 1419 delete [] encrypted;
1407 delete [] decrypted; 1420 delete [] decrypted;
1408 return e_cryptNotImpl; 1421 return e_cryptNotImpl;
1409 } } 1422 } }
1410 delete [] encrypted; 1423 delete [] encrypted;
1411#ifndef PWM_EMBEDDED 1424#ifndef PWM_EMBEDDED
1412 d->assign(reinterpret_cast<const char *>(decrypted), 1425 d->assign(reinterpret_cast<const char *>(decrypted),
1413 static_cast<string::size_type>(cryptLen)); 1426 static_cast<string::size_type>(cryptLen));
1414#else 1427#else
1415 d->assign((const char *)(decrypted), 1428 d->assign((const char *)(decrypted),
1416 (string::size_type)(cryptLen)); 1429 (string::size_type)(cryptLen));
1417#endif 1430#endif
1418 delete [] decrypted; 1431 delete [] decrypted;
1419 if (algo == PWM_CRYPT_BLOWFISH) { 1432 if (algo == PWM_CRYPT_BLOWFISH) {
1420 if (!Blowfish::unpadNull(d)) { 1433 if (!Blowfish::unpadNull(d)) {
diff --git a/pwmanager/pwmanager/pwmprefs.cpp b/pwmanager/pwmanager/pwmprefs.cpp
index 5779ecc..d3847f6 100644
--- a/pwmanager/pwmanager/pwmprefs.cpp
+++ b/pwmanager/pwmanager/pwmprefs.cpp
@@ -1,299 +1,300 @@
1/* 1/*
2 This file is part of PwManager/Pi 2 This file is part of PwManager/Pi
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22 22
23 $Id$ 23 $Id$
24*/ 24*/
25 25
26 26
27#include <kconfig.h> 27#include <kconfig.h>
28#include <klocale.h> 28#include <klocale.h>
29#include <kstaticdeleter.h> 29#include <kstaticdeleter.h>
30 30
31#include "pwmprefs.h" 31#include "pwmprefs.h"
32 32
33PWMPrefs *PWMPrefs::sInstance = 0; 33PWMPrefs *PWMPrefs::sInstance = 0;
34static KStaticDeleter<PWMPrefs> staticDeleter; 34static KStaticDeleter<PWMPrefs> staticDeleter;
35 35
36PWMPrefs::PWMPrefs() 36PWMPrefs::PWMPrefs()
37 : KPimPrefs("pwmanagerrc") 37 : KPimPrefs("pwmanagerrc")
38{ 38{
39 KPrefs::setCurrentGroup( "Global" ); 39 KPrefs::setCurrentGroup( "Global" );
40 40
41 addItemString( "autoStart", &mAutoStart, "" ); 41 addItemString( "autoStart", &mAutoStart, "" );
42 addItemString( "browserCommand", &mBrowserCommand, "" ); 42 addItemString( "browserCommand", &mBrowserCommand, "" );
43 addItemString( "xtermCommand", &mXTermCommand, CONF_DEFAULT_XTERMCOMMAND); 43 addItemString( "xtermCommand", &mXTermCommand, CONF_DEFAULT_XTERMCOMMAND);
44 addItemFont( "entryFont", &mEntryFont); 44 addItemFont( "entryFont", &mEntryFont);
45 addItemInt( "pwTimeout", &mPwTimeout, CONF_DEFAULT_PWTIMEOUT ); 45 addItemInt( "pwTimeout", &mPwTimeout, CONF_DEFAULT_PWTIMEOUT );
46 addItemInt( "lockTimeout", &mLockTimeout, CONF_DEFAULT_LOCKTIMEOUT ); 46 addItemInt( "lockTimeout", &mLockTimeout, CONF_DEFAULT_LOCKTIMEOUT );
47 addItemInt( "compression", &mCompression, CONF_DEFAULT_COMPRESSION ); 47 addItemInt( "compression", &mCompression, CONF_DEFAULT_COMPRESSION );
48 addItemInt( "filePermissions", &mFilePermissions, CONF_DEFAULT_FILEPERMISSIONS ); 48 addItemInt( "filePermissions", &mFilePermissions, CONF_DEFAULT_FILEPERMISSIONS );
49 addItemInt( "minimizeLock", &mMinimizeLock, CONF_DEFAULT_MINIMIZELOCK ); 49 addItemInt( "minimizeLock", &mMinimizeLock, CONF_DEFAULT_MINIMIZELOCK );
50 addItemBool( "unlockOnOpen", &mUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN ); 50 addItemBool( "unlockOnOpen", &mUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN );
51 addItemBool( "tray", &mTray, CONF_DEFAULT_TRAY ); 51 addItemBool( "tray", &mTray, CONF_DEFAULT_TRAY );
52 addItemBool( "makeFileBackup", &mMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP ); 52 addItemBool( "makeFileBackup", &mMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP );
53 addItemBool( "autostartDeepLocked", &mAutostartDeeplocked, CONF_DEFAULT_AUTOSTART_DEEPL ); 53 addItemBool( "autostartDeepLocked", &mAutostartDeeplocked, CONF_DEFAULT_AUTOSTART_DEEPL );
54 addItemBool( "autoDeepLock", &mAutoDeeplock, CONF_DEFAULT_AUTODEEPLOCK ); 54 addItemBool( "autoDeepLock", &mAutoDeeplock, CONF_DEFAULT_AUTODEEPLOCK );
55 addItemBool( "kwalletEmu", &mKWalletEmu, CONF_DEFAULT_KWALLETEMU ); 55 addItemBool( "kwalletEmu", &mKWalletEmu, CONF_DEFAULT_KWALLETEMU );
56 addItemBool( "newEntrLockStat", &mNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT ); 56 addItemBool( "newEntrLockStat", &mNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT );
57 57
58 KPrefs::setCurrentGroup( "Wnd" ); 58 KPrefs::setCurrentGroup( "Wnd" );
59 59
60 addItemSize( "MainWndSize", &mMainWndSize); 60 addItemSize( "MainWndSize", &mMainWndSize);
61 addItemInt( "MainViewStyle", &mMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE ); 61 addItemInt( "MainViewStyle", &mMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE );
62 addItemBool( "autoMinimizeOnStart", &mAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE ); 62 addItemBool( "autoMinimizeOnStart", &mAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE );
63 addItemBool( "close", &mClose, CONF_DEFAULT_WNDCLOSE ); 63 addItemBool( "close", &mClose, CONF_DEFAULT_WNDCLOSE );
64 addItemIntList( "CommentSplitter", &mCommentSplitter );
64} 65}
65 66
66PWMPrefs::~PWMPrefs() 67PWMPrefs::~PWMPrefs()
67{ 68{
68} 69}
69 70
70PWMPrefs *PWMPrefs::instance() 71PWMPrefs *PWMPrefs::instance()
71{ 72{
72 if ( !sInstance ) { 73 if ( !sInstance ) {
73#ifdef PWM_EMBEDDED 74#ifdef PWM_EMBEDDED
74 sInstance = staticDeleter.setObject( new PWMPrefs() ); 75 sInstance = staticDeleter.setObject( new PWMPrefs() );
75#else //PWM_EMBEDDED 76#else //PWM_EMBEDDED
76 //US the following line has changed ???. Why 77 //US the following line has changed ???. Why
77 staticDeleter.setObject( sInstance, new PWMPrefs() ); 78 staticDeleter.setObject( sInstance, new PWMPrefs() );
78#endif //KAB_EMBEDDED 79#endif //KAB_EMBEDDED
79 sInstance->readConfig(); 80 sInstance->readConfig();
80 } 81 }
81 82
82 return sInstance; 83 return sInstance;
83} 84}
84 85
85 // US introduce a nonconst way to return the config object. 86 // US introduce a nonconst way to return the config object.
86KConfig* PWMPrefs::getConfig() 87KConfig* PWMPrefs::getConfig()
87{ 88{
88 return config(); 89 return config();
89} 90}
90 91
91/******************************************************************* 92/*******************************************************************
92 * functions for reading the configuration settings 93 * functions for reading the configuration settings
93 *******************************************************************/ 94 *******************************************************************/
94 95
95QString PWMPrefs::confGlobAutoStart() 96QString PWMPrefs::confGlobAutoStart()
96{ 97{
97 return mAutoStart; 98 return mAutoStart;
98} 99}
99 100
100QString PWMPrefs::confGlobBrowserCommand() 101QString PWMPrefs::confGlobBrowserCommand()
101{ 102{
102 return mBrowserCommand; 103 return mBrowserCommand;
103} 104}
104 105
105QString PWMPrefs::confGlobXtermCommand() 106QString PWMPrefs::confGlobXtermCommand()
106{ 107{
107 return mXTermCommand; 108 return mXTermCommand;
108} 109}
109 110
110QFont PWMPrefs::confGlobEntryFont() 111QFont PWMPrefs::confGlobEntryFont()
111{ 112{
112 return mEntryFont; 113 return mEntryFont;
113} 114}
114 115
115int PWMPrefs::confGlobPwTimeout() 116int PWMPrefs::confGlobPwTimeout()
116{ 117{
117 return mPwTimeout; 118 return mPwTimeout;
118} 119}
119 120
120int PWMPrefs::confGlobLockTimeout() 121int PWMPrefs::confGlobLockTimeout()
121{ 122{
122 return mLockTimeout; 123 return mLockTimeout;
123} 124}
124 125
125int PWMPrefs::confGlobCompression() 126int PWMPrefs::confGlobCompression()
126{ 127{
127 return mCompression; 128 return mCompression;
128} 129}
129 130
130int PWMPrefs::confGlobFilePermissions() 131int PWMPrefs::confGlobFilePermissions()
131{ 132{
132 return mFilePermissions; 133 return mFilePermissions;
133} 134}
134 135
135int PWMPrefs::confGlobMinimizeLock() 136int PWMPrefs::confGlobMinimizeLock()
136{ 137{
137 return mMinimizeLock; 138 return mMinimizeLock;
138} 139}
139 140
140bool PWMPrefs::confGlobUnlockOnOpen() 141bool PWMPrefs::confGlobUnlockOnOpen()
141{ 142{
142 return mUnlockOnOpen; 143 return mUnlockOnOpen;
143} 144}
144 145
145bool PWMPrefs::confGlobTray() 146bool PWMPrefs::confGlobTray()
146{ 147{
147 return mTray; 148 return mTray;
148} 149}
149 150
150bool PWMPrefs::confGlobMakeFileBackup() 151bool PWMPrefs::confGlobMakeFileBackup()
151{ 152{
152 return mMakeFileBackup; 153 return mMakeFileBackup;
153} 154}
154 155
155bool PWMPrefs::confGlobAutostartDeepLocked() 156bool PWMPrefs::confGlobAutostartDeepLocked()
156{ 157{
157 return mAutostartDeeplocked; 158 return mAutostartDeeplocked;
158} 159}
159 160
160bool PWMPrefs::confGlobAutoDeepLock() 161bool PWMPrefs::confGlobAutoDeepLock()
161{ 162{
162 return mAutoDeeplock; 163 return mAutoDeeplock;
163} 164}
164 165
165bool PWMPrefs::confGlobKwalletEmu() 166bool PWMPrefs::confGlobKwalletEmu()
166{ 167{
167 return mKWalletEmu; 168 return mKWalletEmu;
168} 169}
169 170
170bool PWMPrefs::confGlobNewEntrLockStat() 171bool PWMPrefs::confGlobNewEntrLockStat()
171{ 172{
172 return mNewEntrLockStat; 173 return mNewEntrLockStat;
173} 174}
174 175
175QSize PWMPrefs::confWndMainWndSize() 176QSize PWMPrefs::confWndMainWndSize()
176{ 177{
177 return mMainWndSize; 178 return mMainWndSize;
178} 179}
179 180
180int PWMPrefs::confWndMainViewStyle() 181int PWMPrefs::confWndMainViewStyle()
181{ 182{
182 return mMainViewStyle; 183 return mMainViewStyle;
183} 184}
184 185
185bool PWMPrefs::confWndAutoMinimizeOnStart() 186bool PWMPrefs::confWndAutoMinimizeOnStart()
186{ 187{
187 return mAutoMinimizeOnStart; 188 return mAutoMinimizeOnStart;
188} 189}
189 190
190bool PWMPrefs::confWndClose() 191bool PWMPrefs::confWndClose()
191{ 192{
192 return mClose; 193 return mClose;
193} 194}
194 195
195/******************************************************************* 196/*******************************************************************
196 * functions for writing the configuration settings 197 * functions for writing the configuration settings
197 *******************************************************************/ 198 *******************************************************************/
198 199
199void PWMPrefs::confGlobAutoStart(const QString &e) 200void PWMPrefs::confGlobAutoStart(const QString &e)
200{ 201{
201 mAutoStart = e; 202 mAutoStart = e;
202} 203}
203 204
204void PWMPrefs::confGlobBrowserCommand(const QString &e) 205void PWMPrefs::confGlobBrowserCommand(const QString &e)
205{ 206{
206 mBrowserCommand = e; 207 mBrowserCommand = e;
207} 208}
208 209
209void PWMPrefs::confGlobXtermCommand(const QString &e) 210void PWMPrefs::confGlobXtermCommand(const QString &e)
210{ 211{
211 mXTermCommand = e; 212 mXTermCommand = e;
212} 213}
213 214
214void PWMPrefs::confGlobEntryFont(const QFont &e) 215void PWMPrefs::confGlobEntryFont(const QFont &e)
215{ 216{
216 mEntryFont = e; 217 mEntryFont = e;
217} 218}
218 219
219void PWMPrefs::confGlobPwTimeout(int e) 220void PWMPrefs::confGlobPwTimeout(int e)
220{ 221{
221 mPwTimeout = e; 222 mPwTimeout = e;
222} 223}
223 224
224void PWMPrefs::confGlobLockTimeout(int e) 225void PWMPrefs::confGlobLockTimeout(int e)
225{ 226{
226 mLockTimeout = e; 227 mLockTimeout = e;
227} 228}
228 229
229void PWMPrefs::confGlobCompression(int e) 230void PWMPrefs::confGlobCompression(int e)
230{ 231{
231 mCompression = e; 232 mCompression = e;
232} 233}
233 234
234void PWMPrefs::confGlobFilePermissions(int e) 235void PWMPrefs::confGlobFilePermissions(int e)
235{ 236{
236 mFilePermissions = e; 237 mFilePermissions = e;
237} 238}
238 239
239void PWMPrefs::confGlobMinimizeLock(int e) 240void PWMPrefs::confGlobMinimizeLock(int e)
240{ 241{
241 mMinimizeLock = e; 242 mMinimizeLock = e;
242} 243}
243 244
244void PWMPrefs::confGlobUnlockOnOpen(bool e) 245void PWMPrefs::confGlobUnlockOnOpen(bool e)
245{ 246{
246 mUnlockOnOpen = e; 247 mUnlockOnOpen = e;
247} 248}
248 249
249void PWMPrefs::confGlobTray(bool e) 250void PWMPrefs::confGlobTray(bool e)
250{ 251{
251 mTray = e; 252 mTray = e;
252} 253}
253 254
254void PWMPrefs::confGlobMakeFileBackup(bool e) 255void PWMPrefs::confGlobMakeFileBackup(bool e)
255{ 256{
256 mMakeFileBackup = e; 257 mMakeFileBackup = e;
257} 258}
258 259
259void PWMPrefs::confGlobAutostartDeepLocked(bool e) 260void PWMPrefs::confGlobAutostartDeepLocked(bool e)
260{ 261{
261 mAutostartDeeplocked = e; 262 mAutostartDeeplocked = e;
262} 263}
263 264
264void PWMPrefs::confGlobAutoDeepLock(bool e) 265void PWMPrefs::confGlobAutoDeepLock(bool e)
265{ 266{
266 mAutoDeeplock = e; 267 mAutoDeeplock = e;
267} 268}
268 269
269void PWMPrefs::confGlobKwalletEmu(bool e) 270void PWMPrefs::confGlobKwalletEmu(bool e)
270{ 271{
271 mKWalletEmu = e; 272 mKWalletEmu = e;
272} 273}
273 274
274void PWMPrefs::confGlobNewEntrLockStat(bool e) 275void PWMPrefs::confGlobNewEntrLockStat(bool e)
275{ 276{
276 mNewEntrLockStat = e; 277 mNewEntrLockStat = e;
277} 278}
278 279
279void PWMPrefs::confWndMainWndSize(const QSize &e) 280void PWMPrefs::confWndMainWndSize(const QSize &e)
280{ 281{
281 mMainWndSize = e; 282 mMainWndSize = e;
282} 283}
283 284
284void PWMPrefs::confWndMainViewStyle(int e) 285void PWMPrefs::confWndMainViewStyle(int e)
285{ 286{
286 mMainViewStyle = e; 287 mMainViewStyle = e;
287} 288}
288 289
289void PWMPrefs::confWndAutoMinimizeOnStart(bool e) 290void PWMPrefs::confWndAutoMinimizeOnStart(bool e)
290{ 291{
291 mAutoMinimizeOnStart = e; 292 mAutoMinimizeOnStart = e;
292} 293}
293 294
294void PWMPrefs::confWndClose(bool e) 295void PWMPrefs::confWndClose(bool e)
295{ 296{
296 mClose = e; 297 mClose = e;
297} 298}
298 299
299 300
diff --git a/pwmanager/pwmanager/pwmprefs.h b/pwmanager/pwmanager/pwmprefs.h
index bf7d8b1..6a89d10 100644
--- a/pwmanager/pwmanager/pwmprefs.h
+++ b/pwmanager/pwmanager/pwmprefs.h
@@ -1,146 +1,150 @@
1/* 1/*
2 This file is part of PwManager/Pi 2 This file is part of PwManager/Pi
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22 22
23 $Id$ 23 $Id$
24*/ 24*/
25 25
26#ifndef PWMPREFS_H 26#ifndef PWMPREFS_H
27#define PWMPREFS_H 27#define PWMPREFS_H
28 28
29#include <qstringlist.h> 29#include <qstringlist.h>
30#include <qsize.h> 30#include <qsize.h>
31 31
32#include <kpimprefs.h> 32#include <kpimprefs.h>
33 33
34class KConfig; 34class KConfig;
35 35
36#define conf() PWMPrefs::instance() 36#define conf() PWMPrefs::instance()
37 37
38 38
39 #define CONF_DEFAULT_PWTIMEOUT 10/* 10 sec */ 39 #define CONF_DEFAULT_PWTIMEOUT 10/* 10 sec */
40 #define CONF_DEFAULT_LOCKTIMEOUT 0/* 0 == disable */ 40 #define CONF_DEFAULT_LOCKTIMEOUT 0/* 0 == disable */
41 #define CONF_DEFAULT_TRAY true 41 #define CONF_DEFAULT_TRAY true
42 #define CONF_DEFAULT_UNLOCKONOPENfalse 42 #define CONF_DEFAULT_UNLOCKONOPENfalse
43 #define CONF_DEFAULT_MAINVIEWSTYLE0 43 #define CONF_DEFAULT_MAINVIEWSTYLE0
44 #define CONF_DEFAULT_COMPRESSION 0x01/* gzip */ 44 #define CONF_DEFAULT_COMPRESSION 0x01/* gzip */
45 #define CONF_DEFAULT_AUTOMINIMIZEfalse 45 #define CONF_DEFAULT_AUTOMINIMIZEfalse
46 #define CONF_DEFAULT_BROWSERCOMMAND"" 46 #define CONF_DEFAULT_BROWSERCOMMAND""
47 #define CONF_DEFAULT_XTERMCOMMAND"konsole -e" 47 #define CONF_DEFAULT_XTERMCOMMAND"konsole -e"
48 #define CONF_DEFAULT_FILEPERMISSIONS0600 48 #define CONF_DEFAULT_FILEPERMISSIONS0600
49 #define CONF_DEFAULT_MAKEFILEBACKUPfalse 49 #define CONF_DEFAULT_MAKEFILEBACKUPfalse
50 #define CONF_DEFAULT_AUTOSTART_DEEPLtrue 50 #define CONF_DEFAULT_AUTOSTART_DEEPLtrue
51 #define CONF_DEFAULT_AUTODEEPLOCKtrue 51 #define CONF_DEFAULT_AUTODEEPLOCKtrue
52 #define CONF_DEFAULT_KWALLETEMU true 52 #define CONF_DEFAULT_KWALLETEMU true
53 #define CONF_DEFAULT_MINIMIZELOCK 2/* deep-lock */ 53 #define CONF_DEFAULT_MINIMIZELOCK 2/* deep-lock */
54 #define CONF_DEFAULT_NEWENTRLOCKSTAT true/* locked */ 54 #define CONF_DEFAULT_NEWENTRLOCKSTAT true/* locked */
55 #define CONF_DEFAULT_WNDCLOSE true/* don't minimize to tray */ 55 #define CONF_DEFAULT_WNDCLOSE true/* don't minimize to tray */
56 56
57class PWMPrefs : public KPimPrefs 57class PWMPrefs : public KPimPrefs
58{ 58{
59 public: 59 public:
60 virtual ~PWMPrefs(); 60 virtual ~PWMPrefs();
61 61
62 static PWMPrefs *instance(); 62 static PWMPrefs *instance();
63 63
64public: 64public:
65 /* functions for reading the configuration settings */ 65 /* functions for reading the configuration settings */
66 /* GLOBAL */ 66 /* GLOBAL */
67 QString confGlobAutoStart(); 67 QString confGlobAutoStart();
68 QString confGlobBrowserCommand(); 68 QString confGlobBrowserCommand();
69 QString confGlobXtermCommand(); 69 QString confGlobXtermCommand();
70 QFont confGlobEntryFont(); 70 QFont confGlobEntryFont();
71 int confGlobPwTimeout(); 71 int confGlobPwTimeout();
72 int confGlobLockTimeout(); 72 int confGlobLockTimeout();
73 int confGlobCompression(); 73 int confGlobCompression();
74 int confGlobFilePermissions(); 74 int confGlobFilePermissions();
75 int confGlobMinimizeLock(); 75 int confGlobMinimizeLock();
76 bool confGlobUnlockOnOpen(); 76 bool confGlobUnlockOnOpen();
77 bool confGlobTray(); 77 bool confGlobTray();
78 bool confGlobMakeFileBackup(); 78 bool confGlobMakeFileBackup();
79 bool confGlobAutostartDeepLocked(); 79 bool confGlobAutostartDeepLocked();
80 bool confGlobAutoDeepLock(); 80 bool confGlobAutoDeepLock();
81 bool confGlobKwalletEmu(); 81 bool confGlobKwalletEmu();
82 bool confGlobNewEntrLockStat(); 82 bool confGlobNewEntrLockStat();
83 /* WND */ 83 /* WND */
84 QSize confWndMainWndSize(); 84 QSize confWndMainWndSize();
85 int confWndMainViewStyle(); 85 int confWndMainViewStyle();
86 bool confWndAutoMinimizeOnStart(); 86 bool confWndAutoMinimizeOnStart();
87 bool confWndClose(); 87 bool confWndClose();
88 88
89public: 89public:
90 /* functions for writing the configuration settings */ 90 /* functions for writing the configuration settings */
91 /* GLOBAL */ 91 /* GLOBAL */
92 void confGlobAutoStart(const QString &e); 92 void confGlobAutoStart(const QString &e);
93 void confGlobBrowserCommand(const QString &e); 93 void confGlobBrowserCommand(const QString &e);
94 void confGlobXtermCommand(const QString &e); 94 void confGlobXtermCommand(const QString &e);
95 void confGlobEntryFont(const QFont &e); 95 void confGlobEntryFont(const QFont &e);
96 void confGlobPwTimeout(int e); 96 void confGlobPwTimeout(int e);
97 void confGlobLockTimeout(int e); 97 void confGlobLockTimeout(int e);
98 void confGlobCompression(int e); 98 void confGlobCompression(int e);
99 void confGlobFilePermissions(int e); 99 void confGlobFilePermissions(int e);
100 void confGlobMinimizeLock(int e); 100 void confGlobMinimizeLock(int e);
101 void confGlobUnlockOnOpen(bool e); 101 void confGlobUnlockOnOpen(bool e);
102 void confGlobTray(bool e); 102 void confGlobTray(bool e);
103 void confGlobMakeFileBackup(bool e); 103 void confGlobMakeFileBackup(bool e);
104 void confGlobAutostartDeepLocked(bool e); 104 void confGlobAutostartDeepLocked(bool e);
105 void confGlobAutoDeepLock(bool e); 105 void confGlobAutoDeepLock(bool e);
106 void confGlobKwalletEmu(bool e); 106 void confGlobKwalletEmu(bool e);
107 void confGlobNewEntrLockStat(bool e); 107 void confGlobNewEntrLockStat(bool e);
108 /* WND */ 108 /* WND */
109 void confWndMainWndSize(const QSize &e); 109 void confWndMainWndSize(const QSize &e);
110 void confWndMainViewStyle(int e); 110 void confWndMainViewStyle(int e);
111 void confWndAutoMinimizeOnStart(bool e); 111 void confWndAutoMinimizeOnStart(bool e);
112 void confWndClose(bool e); 112 void confWndClose(bool e);
113 113
114 114
115 115
116 QString mAutoStart; 116 QString mAutoStart;
117 QString mBrowserCommand; 117 QString mBrowserCommand;
118 QString mXTermCommand; 118 QString mXTermCommand;
119 QFont mEntryFont; 119 QFont mEntryFont;
120 int mPwTimeout; 120 int mPwTimeout;
121 int mLockTimeout; 121 int mLockTimeout;
122 int mCompression; 122 int mCompression;
123 int mFilePermissions; 123 int mFilePermissions;
124 int mMinimizeLock; 124 int mMinimizeLock;
125 bool mUnlockOnOpen; 125 bool mUnlockOnOpen;
126 bool mTray; 126 bool mTray;
127 bool mMakeFileBackup; 127 bool mMakeFileBackup;
128 bool mAutostartDeeplocked; 128 bool mAutostartDeeplocked;
129 bool mAutoDeeplock; 129 bool mAutoDeeplock;
130 bool mKWalletEmu; 130 bool mKWalletEmu;
131 bool mNewEntrLockStat; 131 bool mNewEntrLockStat;
132 QSize mMainWndSize; 132 QSize mMainWndSize;
133 int mMainViewStyle; 133 int mMainViewStyle;
134 bool mAutoMinimizeOnStart; 134 bool mAutoMinimizeOnStart;
135 bool mClose; 135 bool mClose;
136 136
137 //US ENH
138 QValueList<int> mCommentSplitter;
139
140
137 // US introduce a nonconst way to return the config object. 141 // US introduce a nonconst way to return the config object.
138 KConfig* getConfig(); 142 KConfig* getConfig();
139 143
140 private: 144 private:
141 PWMPrefs(); 145 PWMPrefs();
142 146
143 static PWMPrefs *sInstance; 147 static PWMPrefs *sInstance;
144}; 148};
145 149
146#endif 150#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle.cpp b/pwmanager/pwmanager/pwmviewstyle.cpp
index 51d8f6c..9704615 100644
--- a/pwmanager/pwmanager/pwmviewstyle.cpp
+++ b/pwmanager/pwmanager/pwmviewstyle.cpp
@@ -1,217 +1,239 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12 12
13/*************************************************************************** 13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk 14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager 15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde 16 * and was modified to run on embedded devices that run microkde
17 * 17 *
18 * $Id$ 18 * $Id$
19 **************************************************************************/ 19 **************************************************************************/
20 20
21#include "pwmviewstyle.h" 21#include "pwmviewstyle.h"
22#include "pwmexception.h" 22#include "pwmexception.h"
23#include "pwmviewstyle_0.h" 23#include "pwmviewstyle_0.h"
24#include "pwmviewstyle_1.h" 24#include "pwmviewstyle_1.h"
25#include "listviewpwm.h" 25#include "listviewpwm.h"
26#include "pwmview.h" 26#include "pwmview.h"
27#include "commentbox.h" 27#include "commentbox.h"
28#ifndef PWM_EMBEDDED 28#ifndef PWM_EMBEDDED
29#include "configuration.h" 29#include "configuration.h"
30#else 30#else
31#include "pwmprefs.h" 31#include "pwmprefs.h"
32#endif 32#endif
33 33
34PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name) 34PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name)
35 : QWidget(parent, name) 35 : QWidget(parent, name)
36{ 36{
37 curStyle = style_notset; 37 curStyle = style_notset;
38 s0 = 0; 38 s0 = 0;
39 s1 = 0; 39 s1 = 0;
40} 40}
41 41
42PwMViewStyle::~PwMViewStyle() 42PwMViewStyle::~PwMViewStyle()
43{ 43{
44 //US ENH : load and store the size of the listviewcolumns 44 //US ENH : store the size of the listviewcolumns
45 lv->saveLayout(conf()->getConfig(), "listview"); 45 switch (curStyle)
46 conf()->getConfig()->sync(); 46 {
47 case style_0:
48 s0->saveSettings(PWMPrefs::instance());
49 break;
50 case style_1:
51 s1->saveSettings(PWMPrefs::instance());
52 break;
53 default:
54 BUG();
55 }
56
57
58 PWMPrefs::instance()->getConfig()->sync();
47 59
48 delete_ifnot_null(s0); 60 delete_ifnot_null(s0);
49 delete_ifnot_null(s1); 61 delete_ifnot_null(s1);
50} 62}
51 63
52void PwMViewStyle::initStyle(style_t style) 64void PwMViewStyle::initStyle(style_t style)
53{ 65{
54 printDebug(string("initializing style ") + tostr(style)); 66 printDebug(string("initializing style ") + tostr(style));
55 bool wasMaximized = v->isMaximized(); 67 bool wasMaximized = v->isMaximized();
56 if (v->isVisible()) 68 if (v->isVisible())
57 v->hide(); 69 v->hide();
58 switch (style) { 70 switch (style) {
59 case style_0: 71 case style_0:
60 delete_ifnot_null(s0); 72 delete_ifnot_null(s0);
61 delete_ifnot_null(s1); 73 delete_ifnot_null(s1);
62 s0 = new PwMViewStyle_0(v); 74 s0 = new PwMViewStyle_0(v);
63 lv = s0->getLv(); 75 lv = s0->getLv();
64 commentBox = s0->getCommentBox(); 76 commentBox = s0->getCommentBox();
65 break; 77 break;
66 case style_1: 78 case style_1:
67 delete_ifnot_null(s0); 79 delete_ifnot_null(s0);
68 delete_ifnot_null(s1); 80 delete_ifnot_null(s1);
69 s1 = new PwMViewStyle_1(v); 81 s1 = new PwMViewStyle_1(v);
70 lv = s1->getLv(); 82 lv = s1->getLv();
71 commentBox = s1->getCommentBox(); 83 commentBox = s1->getCommentBox();
72 break; 84 break;
73 default: 85 default:
74 BUG(); 86 BUG();
75 return; 87 return;
76 } 88 }
77 curStyle = style; 89 curStyle = style;
78 connect(lv, SIGNAL(pressed(QListViewItem *)), 90 connect(lv, SIGNAL(pressed(QListViewItem *)),
79 v, SLOT(handleToggle(QListViewItem *))); 91 v, SLOT(handleToggle(QListViewItem *)));
80 connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), 92 connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)),
81 v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int))); 93 v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int)));
82 connect(lv, SIGNAL(clicked(QListViewItem *)), 94 connect(lv, SIGNAL(clicked(QListViewItem *)),
83 v, SLOT(refreshCommentTextEdit(QListViewItem *))); 95 v, SLOT(refreshCommentTextEdit(QListViewItem *)));
84 lv->addColumn(i18n("Description"), 180); 96 lv->addColumn(i18n("Description"), 180);
85 lv->addColumn(i18n("Username"), 150); 97 lv->addColumn(i18n("Username"), 150);
86 lv->addColumn(i18n("Password"), 150); 98 lv->addColumn(i18n("Password"), 150);
87 lv->addColumn(i18n("URL"), 180); 99 lv->addColumn(i18n("URL"), 180);
88 lv->addColumn(i18n("Launcher"), 120); 100 lv->addColumn(i18n("Launcher"), 120);
89 v->tmpReEnableSort(); 101 v->tmpReEnableSort();
90 102
91 //US ENH : load and store the size of the listviewcolumns 103 //US ENH : load the size of the listviewcolumns
92 lv->restoreLayout(conf()->getConfig(), "listview"); 104 switch (style)
105 {
106 case style_0:
107 s0->restoreSettings(PWMPrefs::instance());
108 break;
109 case style_1:
110 s1->restoreSettings(PWMPrefs::instance());
111 break;
112 default:
113 BUG();
114 }
93 115
94 resizeView(v->size()); 116 resizeView(v->size());
95 v->updateView(); 117 v->updateView();
96 if (wasMaximized) { 118 if (wasMaximized) {
97 v->showMaximized(); 119 v->showMaximized();
98 } else { 120 } else {
99 v->show(); 121 v->show();
100 } 122 }
101 connect(lv, SIGNAL(layoutChanged()), 123 connect(lv, SIGNAL(layoutChanged()),
102 v, SLOT(reorgLp())); 124 v, SLOT(reorgLp()));
103} 125}
104 126
105void PwMViewStyle::resizeView(const QSize &size) 127void PwMViewStyle::resizeView(const QSize &size)
106{ 128{
107 switch (curStyle) { 129 switch (curStyle) {
108 case style_0: 130 case style_0:
109 PWM_ASSERT(s0); 131 PWM_ASSERT(s0);
110 s0->resize(size); 132 s0->resize(size);
111 return; 133 return;
112 case style_1: 134 case style_1:
113 PWM_ASSERT(s1); 135 PWM_ASSERT(s1);
114 s1->resize(size); 136 s1->resize(size);
115 return; 137 return;
116 default: 138 default:
117 BUG(); 139 BUG();
118 } 140 }
119} 141}
120 142
121QString PwMViewStyle::getCurrentCategory() 143QString PwMViewStyle::getCurrentCategory()
122{ 144{
123 switch (curStyle) { 145 switch (curStyle) {
124 case style_0: 146 case style_0:
125 PWM_ASSERT(s0); 147 PWM_ASSERT(s0);
126 return s0->getCurrentCategory(); 148 return s0->getCurrentCategory();
127 case style_1: 149 case style_1:
128 PWM_ASSERT(s1); 150 PWM_ASSERT(s1);
129 return s1->getCurrentCategory(); 151 return s1->getCurrentCategory();
130 default: 152 default:
131 BUG(); 153 BUG();
132 } 154 }
133 return ""; 155 return "";
134} 156}
135 157
136void PwMViewStyle::addCategory(const QString &cat) 158void PwMViewStyle::addCategory(const QString &cat)
137{ 159{
138 switch (curStyle) { 160 switch (curStyle) {
139 case style_0: 161 case style_0:
140 PWM_ASSERT(s0); 162 PWM_ASSERT(s0);
141 s0->addCategory(cat); 163 s0->addCategory(cat);
142 return; 164 return;
143 case style_1: 165 case style_1:
144 PWM_ASSERT(s1); 166 PWM_ASSERT(s1);
145 s1->addCategory(cat); 167 s1->addCategory(cat);
146 return; 168 return;
147 default: 169 default:
148 BUG(); 170 BUG();
149 } 171 }
150} 172}
151 173
152void PwMViewStyle::delCategory(const QString &cat) 174void PwMViewStyle::delCategory(const QString &cat)
153{ 175{
154 switch (curStyle) { 176 switch (curStyle) {
155 case style_0: 177 case style_0:
156 PWM_ASSERT(s0); 178 PWM_ASSERT(s0);
157 s0->delCategory(cat); 179 s0->delCategory(cat);
158 return; 180 return;
159 case style_1: 181 case style_1:
160 PWM_ASSERT(s1); 182 PWM_ASSERT(s1);
161 s1->delCategory(cat); 183 s1->delCategory(cat);
162 return; 184 return;
163 default: 185 default:
164 BUG(); 186 BUG();
165 } 187 }
166} 188}
167 189
168void PwMViewStyle::delAllCategories() 190void PwMViewStyle::delAllCategories()
169{ 191{
170 switch (curStyle) { 192 switch (curStyle) {
171 case style_0: 193 case style_0:
172 PWM_ASSERT(s0); 194 PWM_ASSERT(s0);
173 s0->delAllCategories(); 195 s0->delAllCategories();
174 return; 196 return;
175 case style_1: 197 case style_1:
176 PWM_ASSERT(s1); 198 PWM_ASSERT(s1);
177 s1->delAllCategories(); 199 s1->delAllCategories();
178 return; 200 return;
179 default: 201 default:
180 BUG(); 202 BUG();
181 } 203 }
182} 204}
183 205
184void PwMViewStyle::selectCategory(const QString &cat) 206void PwMViewStyle::selectCategory(const QString &cat)
185{ 207{
186 switch (curStyle) { 208 switch (curStyle) {
187 case style_0: 209 case style_0:
188 PWM_ASSERT(s0); 210 PWM_ASSERT(s0);
189 s0->selectCategory(cat); 211 s0->selectCategory(cat);
190 return; 212 return;
191 case style_1: 213 case style_1:
192 PWM_ASSERT(s1); 214 PWM_ASSERT(s1);
193 s1->selectCategory(cat); 215 s1->selectCategory(cat);
194 return; 216 return;
195 default: 217 default:
196 BUG(); 218 BUG();
197 } 219 }
198} 220}
199 221
200int PwMViewStyle::numCategories() 222int PwMViewStyle::numCategories()
201{ 223{
202 switch (curStyle) { 224 switch (curStyle) {
203 case style_0: 225 case style_0:
204 PWM_ASSERT(s0); 226 PWM_ASSERT(s0);
205 return s0->numCategories(); 227 return s0->numCategories();
206 case style_1: 228 case style_1:
207 PWM_ASSERT(s1); 229 PWM_ASSERT(s1);
208 return s1->numCategories(); 230 return s1->numCategories();
209 default: 231 default:
210 BUG(); 232 BUG();
211 } 233 }
212 return 0; 234 return 0;
213} 235}
214 236
215#ifndef PWM_EMBEDDED 237#ifndef PWM_EMBEDDED
216#include "pwmviewstyle.moc" 238#include "pwmviewstyle.moc"
217#endif 239#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.cpp b/pwmanager/pwmanager/pwmviewstyle_0.cpp
index 6d46ac6..7262684 100644
--- a/pwmanager/pwmanager/pwmviewstyle_0.cpp
+++ b/pwmanager/pwmanager/pwmviewstyle_0.cpp
@@ -1,93 +1,112 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmviewstyle_0.h" 20#include "pwmviewstyle_0.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "listviewpwm.h" 22#include "listviewpwm.h"
23#include "commentbox.h" 23#include "commentbox.h"
24 24
25#include <klocale.h> 25#include <klocale.h>
26 26#include "pwmprefs.h"
27 27
28PwMViewStyle_0::PwMViewStyle_0(PwMView *view) 28PwMViewStyle_0::PwMViewStyle_0(PwMView *view)
29 : QObject() 29 : QObject()
30{ 30{
31 vbox1 = new QVBox(view); 31 vbox1 = new QVBox(view);
32 vbox1->setSpacing(3); 32 vbox1->setSpacing(3);
33 hbox1 = new QHBox(vbox1); 33 hbox1 = new QHBox(vbox1);
34 hbox1->setSpacing(10); 34 hbox1->setSpacing(10);
35 categoriesTitle = new QLabel(hbox1); 35 categoriesTitle = new QLabel(hbox1);
36 categoriesTitle->setText(i18n("Categories:")); 36 categoriesTitle->setText(i18n("Categories:"));
37 categoriesCombo = new QComboBox(hbox1); 37 categoriesCombo = new QComboBox(hbox1);
38 renCatButton = new QPushButton(i18n("&Rename"), hbox1); 38 renCatButton = new QPushButton(i18n("&Rename"), hbox1);
39 delCatButton = new QPushButton(i18n("&Delete"), hbox1); 39 delCatButton = new QPushButton(i18n("&Delete"), hbox1);
40#ifndef PWM_EMBEDDED 40#ifndef PWM_EMBEDDED
41 splitter1 = new QSplitter(vbox1); 41 splitter1 = new QSplitter(vbox1);
42 splitter1->setOrientation(Qt::Vertical); 42 splitter1->setOrientation(Qt::Vertical);
43#else 43#else
44 splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1); 44 splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1);
45 splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 45 splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
46 46
47 //US topLayout->addWidget(mMiniSplitter ); 47 //US topLayout->addWidget(mMiniSplitter );
48#endif 48#endif
49 lv = new ListViewPwM(splitter1); 49 lv = new ListViewPwM(splitter1);
50 commentBox = new CommentBox(splitter1); 50 commentBox = new CommentBox(splitter1);
51 // set sizes and styles 51 // set sizes and styles
52 commentBox->resize(commentBox->size().width(), 60); 52 commentBox->resize(commentBox->size().width(), 60);
53 categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight); 53 categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
54 // connections 54 // connections
55 connect(categoriesCombo, SIGNAL(activated(int)), 55 connect(categoriesCombo, SIGNAL(activated(int)),
56 view, SLOT(shiftToView())); 56 view, SLOT(shiftToView()));
57 connect(renCatButton, SIGNAL(clicked()), 57 connect(renCatButton, SIGNAL(clicked()),
58 view, SLOT(renCatButton_slot())); 58 view, SLOT(renCatButton_slot()));
59 connect(delCatButton, SIGNAL(clicked()), 59 connect(delCatButton, SIGNAL(clicked()),
60 view, SLOT(delCatButton_slot())); 60 view, SLOT(delCatButton_slot()));
61} 61}
62 62
63PwMViewStyle_0::~PwMViewStyle_0() 63PwMViewStyle_0::~PwMViewStyle_0()
64{ 64{
65 delete vbox1; 65 delete vbox1;
66} 66}
67 67
68void PwMViewStyle_0::delCategory(const QString &cat) 68void PwMViewStyle_0::delCategory(const QString &cat)
69{ 69{
70 PWM_ASSERT(categoriesCombo); 70 PWM_ASSERT(categoriesCombo);
71 int i, count = categoriesCombo->count(); 71 int i, count = categoriesCombo->count();
72 for (i = 0; i < count; ++i) { 72 for (i = 0; i < count; ++i) {
73 if (categoriesCombo->text(i) == cat) { 73 if (categoriesCombo->text(i) == cat) {
74 categoriesCombo->removeItem(i); 74 categoriesCombo->removeItem(i);
75 return; 75 return;
76 } 76 }
77 } 77 }
78 BUG(); 78 BUG();
79} 79}
80 80
81void PwMViewStyle_0::selectCategory(const QString &cat) 81void PwMViewStyle_0::selectCategory(const QString &cat)
82{ 82{
83 PWM_ASSERT(categoriesCombo); 83 PWM_ASSERT(categoriesCombo);
84 int i, count = categoriesCombo->count(); 84 int i, count = categoriesCombo->count();
85 for (i = 0; i < count; ++i) { 85 for (i = 0; i < count; ++i) {
86 if (categoriesCombo->text(i) == cat) { 86 if (categoriesCombo->text(i) == cat) {
87 categoriesCombo->setCurrentItem(i); 87 categoriesCombo->setCurrentItem(i);
88 return; 88 return;
89 } 89 }
90 } 90 }
91 // fall back to 0 91 // fall back to 0
92 categoriesCombo->setCurrentItem(0); 92 categoriesCombo->setCurrentItem(0);
93} 93}
94
95
96//US ENH: I need a place to load the view dependend settings. Eg. splittersize
97void PwMViewStyle_0::restoreSettings(PWMPrefs* prefs)
98{
99 //load and store the size of the listviewcolumns
100 lv->restoreLayout(prefs->getConfig(), "listview");
101 splitter1->setSizes( prefs->mCommentSplitter );
102
103}
104
105//US ENH: I need a place to load the view dependend settings. Eg. splittersize
106void PwMViewStyle_0::saveSettings(PWMPrefs* prefs)
107{
108 //store the size of the listviewcolumns
109 lv->saveLayout(prefs->getConfig(), "listview");
110 prefs->mCommentSplitter = splitter1->sizes();
111
112}
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.h b/pwmanager/pwmanager/pwmviewstyle_0.h
index cc564c3..bd93c06 100644
--- a/pwmanager/pwmanager/pwmviewstyle_0.h
+++ b/pwmanager/pwmanager/pwmviewstyle_0.h
@@ -1,99 +1,105 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef PWMVIEWSTYLE_0_H 20#ifndef PWMVIEWSTYLE_0_H
21#define PWMVIEWSTYLE_0_H 21#define PWMVIEWSTYLE_0_H
22 22
23#include <qhbox.h> 23#include <qhbox.h>
24#include <qvbox.h> 24#include <qvbox.h>
25#include <qpushbutton.h> 25#include <qpushbutton.h>
26#ifndef PWM_EMBEDDED 26#ifndef PWM_EMBEDDED
27#include <qtextedit.h> 27#include <qtextedit.h>
28#include <qsplitter.h> 28#include <qsplitter.h>
29#else 29#else
30#include <qmultilineedit.h> 30#include <qmultilineedit.h>
31#include <KDGanttMinimizeSplitter.h> 31#include <KDGanttMinimizeSplitter.h>
32#endif 32#endif
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35 35
36class PwMView; 36class PwMView;
37class ListViewPwM; 37class ListViewPwM;
38class CommentBox; 38class CommentBox;
39class PWMPrefs;
39 40
40class PwMViewStyle_0 : public QObject 41class PwMViewStyle_0 : public QObject
41{ 42{
42public: 43public:
43 PwMViewStyle_0(PwMView *view); 44 PwMViewStyle_0(PwMView *view);
44 ~PwMViewStyle_0(); 45 ~PwMViewStyle_0();
45 46
46 ListViewPwM * getLv() 47 ListViewPwM * getLv()
47 { return lv; } 48 { return lv; }
48 CommentBox * getCommentBox() 49 CommentBox * getCommentBox()
49 { return commentBox; } 50 { return commentBox; }
50 51
51 /** returns the currently selected category */ 52 /** returns the currently selected category */
52 QString getCurrentCategory() 53 QString getCurrentCategory()
53 { return categoriesCombo->currentText(); } 54 { return categoriesCombo->currentText(); }
54 /** add Category to the view */ 55 /** add Category to the view */
55 void addCategory(const QString &cat) 56 void addCategory(const QString &cat)
56 { categoriesCombo->insertItem(cat); } 57 { categoriesCombo->insertItem(cat); }
57 /** delete Category from view */ 58 /** delete Category from view */
58 void delCategory(const QString &cat); 59 void delCategory(const QString &cat);
59 /** delete all categories from view */ 60 /** delete all categories from view */
60 void delAllCategories() 61 void delAllCategories()
61 { categoriesCombo->clear(); } 62 { categoriesCombo->clear(); }
62 /** select the specified category */ 63 /** select the specified category */
63 void selectCategory(const QString &cat); 64 void selectCategory(const QString &cat);
64 /** returns the number of categories in this view. 65 /** returns the number of categories in this view.
65 * This value dosn't say anything about the number of 66 * This value dosn't say anything about the number of
66 * categories in the document. 67 * categories in the document.
67 */ 68 */
68 int numCategories() 69 int numCategories()
69 { return categoriesCombo->count(); } 70 { return categoriesCombo->count(); }
70 /** resize the view */ 71 /** resize the view */
71 void resize(const QSize &size) 72 void resize(const QSize &size)
72 { vbox1->resize(size); } 73 { vbox1->resize(size); }
73 74
75 //US ENH: I need a place to load the view dependend settings. Eg. splittersize
76 void restoreSettings(PWMPrefs* prefs);
77 void saveSettings(PWMPrefs* prefs);
78
79
74protected: 80protected:
75 /** main list view */ 81 /** main list view */
76 ListViewPwM *lv; 82 ListViewPwM *lv;
77 /** categories combo-box */ 83 /** categories combo-box */
78 QComboBox *categoriesCombo; 84 QComboBox *categoriesCombo;
79 /** title string for the categories combo or list box */ 85 /** title string for the categories combo or list box */
80 QLabel *categoriesTitle; 86 QLabel *categoriesTitle;
81 /** hbox1 for widget style */ 87 /** hbox1 for widget style */
82 QHBox *hbox1; 88 QHBox *hbox1;
83 /** vbox1 for widget style */ 89 /** vbox1 for widget style */
84 QVBox *vbox1; 90 QVBox *vbox1;
85 /** splitter for commentTextEdit */ 91 /** splitter for commentTextEdit */
86 #ifndef PWM_EMBEDDED 92 #ifndef PWM_EMBEDDED
87 QSplitter *splitter1; 93 QSplitter *splitter1;
88#else 94#else
89 KDGanttMinimizeSplitter * splitter1; 95 KDGanttMinimizeSplitter * splitter1;
90#endif 96#endif
91 /** push button to change the category name */ 97 /** push button to change the category name */
92 QPushButton *renCatButton; 98 QPushButton *renCatButton;
93 /** push button to delete the category */ 99 /** push button to delete the category */
94 QPushButton *delCatButton; 100 QPushButton *delCatButton;
95 /** comment box */ 101 /** comment box */
96 CommentBox *commentBox; 102 CommentBox *commentBox;
97}; 103};
98 104
99#endif 105#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.cpp b/pwmanager/pwmanager/pwmviewstyle_1.cpp
index 4c24bc4..8b2d6d3 100644
--- a/pwmanager/pwmanager/pwmviewstyle_1.cpp
+++ b/pwmanager/pwmanager/pwmviewstyle_1.cpp
@@ -1,130 +1,150 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "pwmviewstyle_1.h" 20#include "pwmviewstyle_1.h"
21#include "pwmview.h" 21#include "pwmview.h"
22#include "listviewpwm.h" 22#include "listviewpwm.h"
23#include "commentbox.h" 23#include "commentbox.h"
24 24
25#include <klocale.h> 25#include <klocale.h>
26#include "pwmprefs.h"
26 27
27 #define INITIAL_CATEGORIES_WIDTH100 28 #define INITIAL_CATEGORIES_WIDTH100
28 29
29PwMViewStyle_1::PwMViewStyle_1(PwMView *view) 30PwMViewStyle_1::PwMViewStyle_1(PwMView *view)
30 : QObject() 31 : QObject()
31{ 32{
32#ifndef PWM_EMBEDDED 33#ifndef PWM_EMBEDDED
33 splitter = new QSplitter(view); 34 splitter = new QSplitter(view);
34#else 35#else
35 splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); 36 splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view);
36 splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 37 splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
37 38
38 //US topLayout->addWidget(mMiniSplitter ); 39 //US topLayout->addWidget(mMiniSplitter );
39#endif 40#endif
40 41
41 vbox1 = new QVBox(splitter); 42 vbox1 = new QVBox(splitter);
42 categoriesTitle = new QLabel(vbox1); 43 categoriesTitle = new QLabel(vbox1);
43 categoriesList = new QListBox(vbox1); 44 categoriesList = new QListBox(vbox1);
44#ifndef PWM_EMBEDDED 45#ifndef PWM_EMBEDDED
45 splitter2 = new QSplitter(splitter); 46 splitter2 = new QSplitter(splitter);
46 splitter2->setOrientation(Qt::Vertical); 47 splitter2->setOrientation(Qt::Vertical);
47#else 48#else
48 splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); 49 splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter);
49 splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 50 splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
50 51
51 //US topLayout->addWidget(mMiniSplitter ); 52 //US topLayout->addWidget(mMiniSplitter );
52#endif 53#endif
53 lv = new ListViewPwM(splitter2); 54 lv = new ListViewPwM(splitter2);
54 commentBox = new CommentBox(splitter2); 55 commentBox = new CommentBox(splitter2);
55 // set sizes and styles 56 // set sizes and styles
56 commentBox->resize(commentBox->size().width(), 60); 57 commentBox->resize(commentBox->size().width(), 60);
57 QValueList<int> sizes; 58 QValueList<int> sizes;
58#ifndef PWM_EMBEDDED 59#ifndef PWM_EMBEDDED
59 sizes.push_back(INITIAL_CATEGORIES_WIDTH); 60 sizes.push_back(INITIAL_CATEGORIES_WIDTH);
60 sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); 61 sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH);
61#else 62#else
62 sizes.append(INITIAL_CATEGORIES_WIDTH); 63 sizes.append(INITIAL_CATEGORIES_WIDTH);
63 sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); 64 sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH);
64#endif 65#endif
65 splitter->setSizes(sizes); 66 splitter->setSizes(sizes);
66 categoriesTitle->setAlignment(Qt::AlignHCenter); 67 categoriesTitle->setAlignment(Qt::AlignHCenter);
67#ifndef PWM_EMBEDDED 68#ifndef PWM_EMBEDDED
68 categoriesTitle->setFrameShape(QFrame::MenuBarPanel); 69 categoriesTitle->setFrameShape(QFrame::MenuBarPanel);
69#else 70#else
70 categoriesTitle->setFrameShape(QFrame::StyledPanel); 71 categoriesTitle->setFrameShape(QFrame::StyledPanel);
71#endif 72#endif
72 categoriesTitle->setText(i18n("Categories:")); 73 categoriesTitle->setText(i18n("Categories:"));
73 catCtxMenu = new QPopupMenu(view); 74 catCtxMenu = new QPopupMenu(view);
74 catCtxMenu->insertItem(i18n("&Rename"), 75 catCtxMenu->insertItem(i18n("&Rename"),
75 view, SLOT(renCatButton_slot())); 76 view, SLOT(renCatButton_slot()));
76 catCtxMenu->insertItem(i18n("&Delete"), 77 catCtxMenu->insertItem(i18n("&Delete"),
77 view, SLOT(delCatButton_slot())); 78 view, SLOT(delCatButton_slot()));
78 // connections 79 // connections
79 connect(categoriesList, SIGNAL(highlighted(int)), 80 connect(categoriesList, SIGNAL(highlighted(int)),
80 view, SLOT(shiftToView())); 81 view, SLOT(shiftToView()));
81 connect(categoriesList, 82 connect(categoriesList,
82 SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), 83 SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
83 this, 84 this,
84 SLOT(catRightClick(QListBoxItem *, const QPoint &))); 85 SLOT(catRightClick(QListBoxItem *, const QPoint &)));
85} 86}
86 87
87PwMViewStyle_1::~PwMViewStyle_1() 88PwMViewStyle_1::~PwMViewStyle_1()
88{ 89{
89 delete catCtxMenu; 90 delete catCtxMenu;
90 delete splitter; 91 delete splitter;
91} 92}
92 93
93void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) 94void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point)
94{ 95{
95 if (!item) 96 if (!item)
96 return; 97 return;
97 catCtxMenu->move(point); 98 catCtxMenu->move(point);
98 catCtxMenu->show(); 99 catCtxMenu->show();
99} 100}
100 101
101void PwMViewStyle_1::delCategory(const QString &cat) 102void PwMViewStyle_1::delCategory(const QString &cat)
102{ 103{
103 PWM_ASSERT(categoriesList); 104 PWM_ASSERT(categoriesList);
104 int i, count = categoriesList->count(); 105 int i, count = categoriesList->count();
105 for (i = 0; i < count; ++i) { 106 for (i = 0; i < count; ++i) {
106 if (categoriesList->text(i) == cat) { 107 if (categoriesList->text(i) == cat) {
107 categoriesList->removeItem(i); 108 categoriesList->removeItem(i);
108 return; 109 return;
109 } 110 }
110 } 111 }
111 BUG(); 112 BUG();
112} 113}
113 114
114void PwMViewStyle_1::selectCategory(const QString &cat) 115void PwMViewStyle_1::selectCategory(const QString &cat)
115{ 116{
116 PWM_ASSERT(categoriesList); 117 PWM_ASSERT(categoriesList);
117 int i, count = categoriesList->count(); 118 int i, count = categoriesList->count();
118 for (i = 0; i < count; ++i) { 119 for (i = 0; i < count; ++i) {
119 if (categoriesList->text(i) == cat) { 120 if (categoriesList->text(i) == cat) {
120 categoriesList->setCurrentItem(i); 121 categoriesList->setCurrentItem(i);
121 return; 122 return;
122 } 123 }
123 } 124 }
124 // fall back to 0 125 // fall back to 0
125 categoriesList->setCurrentItem(0); 126 categoriesList->setCurrentItem(0);
126} 127}
127 128
129//US ENH: I need a place to load the view dependend settings. Eg. splittersize
130void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs)
131{
132 //load and store the size of the listviewcolumns
133 lv->restoreLayout(prefs->getConfig(), "listview");
134 splitter2->setSizes( prefs->mCommentSplitter );
135
136}
137
138//US ENH: I need a place to load the view dependend settings. Eg. splittersize
139void PwMViewStyle_1::saveSettings(PWMPrefs* prefs)
140{
141 //store the size of the listviewcolumns
142 lv->saveLayout(prefs->getConfig(), "listview");
143 prefs->mCommentSplitter = splitter2->sizes();
144
145}
146
147
128#ifndef PWM_EMBEDDED 148#ifndef PWM_EMBEDDED
129#include "pwmviewstyle_1.moc" 149#include "pwmviewstyle_1.moc"
130#endif 150#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.h b/pwmanager/pwmanager/pwmviewstyle_1.h
index a50f587..a7f100c 100644
--- a/pwmanager/pwmanager/pwmviewstyle_1.h
+++ b/pwmanager/pwmanager/pwmviewstyle_1.h
@@ -1,107 +1,112 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef PWMVIEWSTYLE_1_H 20#ifndef PWMVIEWSTYLE_1_H
21#define PWMVIEWSTYLE_1_H 21#define PWMVIEWSTYLE_1_H
22 22
23#include <qvbox.h> 23#include <qvbox.h>
24 24
25#ifndef PWM_EMBEDDED 25#ifndef PWM_EMBEDDED
26#include <qtextedit.h> 26#include <qtextedit.h>
27#include <qsplitter.h> 27#include <qsplitter.h>
28#else 28#else
29#include <qmultilineedit.h> 29#include <qmultilineedit.h>
30#include <KDGanttMinimizeSplitter.h> 30#include <KDGanttMinimizeSplitter.h>
31#endif 31#endif
32 32
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qlistbox.h> 34#include <qlistbox.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36 36
37class PwMView; 37class PwMView;
38class ListViewPwM; 38class ListViewPwM;
39class CommentBox; 39class CommentBox;
40class PWMPrefs;
40 41
41class PwMViewStyle_1 : public QObject 42class PwMViewStyle_1 : public QObject
42{ 43{
43 Q_OBJECT 44 Q_OBJECT
44public: 45public:
45 PwMViewStyle_1(PwMView *view); 46 PwMViewStyle_1(PwMView *view);
46 ~PwMViewStyle_1(); 47 ~PwMViewStyle_1();
47 48
48 ListViewPwM * getLv() 49 ListViewPwM * getLv()
49 { return lv; } 50 { return lv; }
50 CommentBox * getCommentBox() 51 CommentBox * getCommentBox()
51 { return commentBox; } 52 { return commentBox; }
52 53
53 /** returns the currently selected category */ 54 /** returns the currently selected category */
54 QString getCurrentCategory() 55 QString getCurrentCategory()
55 { return categoriesList->currentText(); } 56 { return categoriesList->currentText(); }
56 /** add Category to the view */ 57 /** add Category to the view */
57 void addCategory(const QString &cat) 58 void addCategory(const QString &cat)
58 { categoriesList->insertItem(cat); } 59 { categoriesList->insertItem(cat); }
59 /** delete Category from view */ 60 /** delete Category from view */
60 void delCategory(const QString &cat); 61 void delCategory(const QString &cat);
61 /** delete all categories from view */ 62 /** delete all categories from view */
62 void delAllCategories() 63 void delAllCategories()
63 { categoriesList->clear(); } 64 { categoriesList->clear(); }
64 /** select the specified category */ 65 /** select the specified category */
65 void selectCategory(const QString &cat); 66 void selectCategory(const QString &cat);
66 /** returns the number of categories in this view. 67 /** returns the number of categories in this view.
67 * This value dosn't say anything about the number of 68 * This value dosn't say anything about the number of
68 * categories in the document. 69 * categories in the document.
69 */ 70 */
70 int numCategories() 71 int numCategories()
71 { return categoriesList->count(); } 72 { return categoriesList->count(); }
72 /** resize the view */ 73 /** resize the view */
73 void resize(const QSize &size) 74 void resize(const QSize &size)
74 { splitter->resize(size); } 75 { splitter->resize(size); }
75 76
77 //US ENH: I need a place to load the view dependend settings. Eg. splittersize
78 void restoreSettings(PWMPrefs* prefs);
79 void saveSettings(PWMPrefs* prefs);
80
76protected slots: 81protected slots:
77 /** user clicked right button in category list */ 82 /** user clicked right button in category list */
78 void catRightClick(QListBoxItem *item, const QPoint &point); 83 void catRightClick(QListBoxItem *item, const QPoint &point);
79 84
80protected: 85protected:
81 /** main list view */ 86 /** main list view */
82 ListViewPwM *lv; 87 ListViewPwM *lv;
83#ifndef PWM_EMBEDDED 88#ifndef PWM_EMBEDDED
84 /** main splitter widget */ 89 /** main splitter widget */
85 QSplitter *splitter; 90 QSplitter *splitter;
86 /** commentTextEdit splitter */ 91 /** commentTextEdit splitter */
87 QSplitter *splitter2; 92 QSplitter *splitter2;
88#else 93#else
89 /** main splitter widget */ 94 /** main splitter widget */
90 KDGanttMinimizeSplitter *splitter; 95 KDGanttMinimizeSplitter *splitter;
91 /** commentTextEdit splitter */ 96 /** commentTextEdit splitter */
92 KDGanttMinimizeSplitter *splitter2; 97 KDGanttMinimizeSplitter *splitter2;
93#endif 98#endif
94 99
95 /** categories list-box */ 100 /** categories list-box */
96 QListBox *categoriesList; 101 QListBox *categoriesList;
97 /** title string for the categories combo or list box */ 102 /** title string for the categories combo or list box */
98 QLabel *categoriesTitle; 103 QLabel *categoriesTitle;
99 /** hbox1 for widget style */ 104 /** hbox1 for widget style */
100 QVBox *vbox1; 105 QVBox *vbox1;
101 /** text-edit to display the comment */ 106 /** text-edit to display the comment */
102 CommentBox *commentBox; 107 CommentBox *commentBox;
103 /** category list context menu */ 108 /** category list context menu */
104 QPopupMenu *catCtxMenu; 109 QPopupMenu *catCtxMenu;
105}; 110};
106 111
107#endif 112#endif
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
index 9377e3d..a54ba8a 100644
--- a/pwmanager/pwmanager/serializer.cpp
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -151,527 +151,513 @@ Serializer::Serializer(const QCString &buffer)
151Serializer::~Serializer() 151Serializer::~Serializer()
152{ 152{
153 delete_ifnot_null(domDoc); 153 delete_ifnot_null(domDoc);
154} 154}
155 155
156void Serializer::clear() 156void Serializer::clear()
157{ 157{
158 delete_ifnot_null(domDoc); 158 delete_ifnot_null(domDoc);
159 domDoc = new QDomDocument; 159 domDoc = new QDomDocument;
160} 160}
161 161
162bool Serializer::parseXml(const QCString &buffer) 162bool Serializer::parseXml(const QCString &buffer)
163{ 163{
164 PWM_ASSERT(domDoc); 164 PWM_ASSERT(domDoc);
165#ifndef PWM_EMBEDDED 165#ifndef PWM_EMBEDDED
166 if (!domDoc->setContent(buffer, true)) 166 if (!domDoc->setContent(buffer, true))
167 return false; 167 return false;
168#else 168#else
169 if (!domDoc->setContent(buffer)) 169 if (!domDoc->setContent(buffer))
170 return false; 170 return false;
171#endif 171#endif
172 if (!checkValid()) 172 if (!checkValid())
173 return false; 173 return false;
174 return true; 174 return true;
175} 175}
176 176
177QCString Serializer::getXml() 177QCString Serializer::getXml()
178{ 178{
179 PWM_ASSERT(domDoc); 179 PWM_ASSERT(domDoc);
180 180
181#ifndef PWM_EMBEDDED 181#ifndef PWM_EMBEDDED
182#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 182#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
183 QCString tmp(domDoc->toCString(8)); 183 QCString tmp(domDoc->toCString(8));
184 printDebug("<BEGIN Serializer::getXml() dump>\n"); 184 printDebug("<BEGIN Serializer::getXml() dump>\n");
185 cout << tmp << endl; 185 cout << tmp << endl;
186 printDebug("<END Serializer::getXml() dump>"); 186 printDebug("<END Serializer::getXml() dump>");
187#endif // DEBUG 187#endif // DEBUG
188 188
189 QCString ret(domDoc->toCString(0)); 189 QCString ret(domDoc->toCString(0));
190 ret.replace('\n', ""); 190 ret.replace('\n', "");
191 return ret; 191 return ret;
192#else 192#else
193 193
194#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 194#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
195 QCString tmp(" " + domDoc->toCString()); 195 QCString tmp(" " + domDoc->toCString());
196 printDebug("<BEGIN Serializer::getXml() dump>\n"); 196 printDebug("<BEGIN Serializer::getXml() dump>\n");
197 qDebug(tmp); 197 qDebug(tmp);
198 cout << tmp << endl; 198 cout << tmp << endl;
199 printDebug("<END Serializer::getXml() dump>"); 199 printDebug("<END Serializer::getXml() dump>");
200#endif // DEBUG 200#endif // DEBUG
201 201
202 QCString ret(domDoc->toCString()); 202 QCString ret(domDoc->toCString());
203 ret.replace(QRegExp("\n"), ""); 203 ret.replace(QRegExp("\n"), "");
204 return ret; 204 return ret;
205 205
206#endif 206#endif
207} 207}
208 208
209bool Serializer::serialize(const vector<PwMCategoryItem> &dta) 209bool Serializer::serialize(const vector<PwMCategoryItem> &dta)
210{ 210{
211 PWM_ASSERT(domDoc); 211 PWM_ASSERT(domDoc);
212 QDomElement root(genNewRoot()); 212 QDomElement root(genNewRoot());
213 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); 213 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
214 root.appendChild(catNode); 214 root.appendChild(catNode);
215 if (!addCategories(&catNode, dta)) 215 if (!addCategories(&catNode, dta))
216 return false; 216 return false;
217 return true; 217 return true;
218} 218}
219 219
220bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) 220bool Serializer::deSerialize(vector<PwMCategoryItem> *dta)
221{ 221{
222 PWM_ASSERT(domDoc); 222 PWM_ASSERT(domDoc);
223 PWM_ASSERT(dta); 223 PWM_ASSERT(dta);
224 QDomElement root(domDoc->documentElement()); 224 QDomElement root(domDoc->documentElement());
225 QDomNode n; 225 QDomNode n;
226 226
227 dta->clear(); 227 dta->clear();
228 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { 228 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
229 // find <categories> ... </categories> 229 // find <categories> ... </categories>
230 // <c> ... </c> 230 // <c> ... </c>
231 if (n.nodeName() == CAT_ROOT_NEW || 231 if (n.nodeName() == CAT_ROOT_NEW ||
232 n.nodeName() == CAT_ROOT_OLD) { 232 n.nodeName() == CAT_ROOT_OLD) {
233 if (!readCategories(n, dta)) { 233 if (!readCategories(n, dta)) {
234 return false; 234 return false;
235 } 235 }
236 236
237 /* NOTE: We can stop processing here, as we 237 /* NOTE: We can stop processing here, as we
238 * don't have more nodes in root, yet. 238 * don't have more nodes in root, yet.
239 */ 239 */
240 return true; 240 return true;
241 } 241 }
242 } 242 }
243 return false; 243 return false;
244} 244}
245 245
246bool Serializer::readCategories(const QDomNode &n, 246bool Serializer::readCategories(const QDomNode &n,
247 vector<PwMCategoryItem> *dta) 247 vector<PwMCategoryItem> *dta)
248{ 248{
249 QDomNodeList nl(n.childNodes()); 249 QDomNodeList nl(n.childNodes());
250 QDomNode cur; 250 QDomNode cur;
251 QString name; 251 QString name;
252 unsigned int numCat = nl.count(), i; 252 unsigned int numCat = nl.count(), i;
253 PwMCategoryItem curCat; 253 PwMCategoryItem curCat;
254 vector<PwMDataItem> curEntr; 254 vector<PwMDataItem> curEntr;
255 255
256 if (!numCat) { 256 if (!numCat) {
257 printDebug("Serializer::readCategories(): empty"); 257 printDebug("Serializer::readCategories(): empty");
258 return false; 258 return false;
259 } 259 }
260 for (i = 0; i < numCat; ++i) { 260 for (i = 0; i < numCat; ++i) {
261 cur = nl.item(i); 261 cur = nl.item(i);
262 if (cur.nodeName().left(1) == CAT_PREFIX_NEW || 262 if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
263 cur.nodeName().left(4) == CAT_PREFIX_OLD) { 263 cur.nodeName().left(4) == CAT_PREFIX_OLD) {
264 name = cur.toElement().attribute(CAT_NAME_NEW); 264 name = cur.toElement().attribute(CAT_NAME_NEW);
265 if (name == QString::null) 265 if (name == QString::null)
266 name = cur.toElement().attribute(CAT_NAME_OLD); 266 name = cur.toElement().attribute(CAT_NAME_OLD);
267 PWM_ASSERT(name != QString::null); 267 PWM_ASSERT(name != QString::null);
268 PWM_ASSERT(name != ""); 268 PWM_ASSERT(name != "");
269 curCat.clear(); 269 curCat.clear();
270 curCat.name = name.latin1(); 270 curCat.name = name.latin1();
271 if (!readEntries(cur, &curEntr)) { 271 if (!readEntries(cur, &curEntr)) {
272 dta->clear(); 272 dta->clear();
273 return false; 273 return false;
274 } 274 }
275 curCat.d = curEntr; 275 curCat.d = curEntr;
276 dta->push_back(curCat); 276 dta->push_back(curCat);
277 } else { 277 } else {
278 printDebug("Serializer::readCategories(): uh? not a category?"); 278 printDebug("Serializer::readCategories(): uh? not a category?");
279 } 279 }
280 } 280 }
281 return true; 281 return true;
282} 282}
283 283
284bool Serializer::readEntries(const QDomNode &n, 284bool Serializer::readEntries(const QDomNode &n,
285 vector<PwMDataItem> *dta) 285 vector<PwMDataItem> *dta)
286{ 286{
287 QDomNodeList nl(n.childNodes()); 287 QDomNodeList nl(n.childNodes());
288 QDomNode cur; 288 QDomNode cur;
289 unsigned int numEntr = nl.count(), i; 289 unsigned int numEntr = nl.count(), i;
290 PwMDataItem curEntr; 290 PwMDataItem curEntr;
291 291
292 dta->clear(); 292 dta->clear();
293 for (i = 0; i < numEntr; ++i) { 293 for (i = 0; i < numEntr; ++i) {
294 cur = nl.item(i); 294 cur = nl.item(i);
295 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || 295 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
296 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { 296 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
297 if (!extractEntry(cur, &curEntr)) { 297 if (!extractEntry(cur, &curEntr)) {
298 return false; 298 return false;
299 } 299 }
300 dta->push_back(curEntr); 300 dta->push_back(curEntr);
301 } else { 301 } else {
302 printDebug("Serializer::readEntries(): hm? not an entry?"); 302 printDebug("Serializer::readEntries(): hm? not an entry?");
303 } 303 }
304 } 304 }
305 return true; 305 return true;
306} 306}
307 307
308bool Serializer::extractEntry(const QDomNode &n, 308bool Serializer::extractEntry(const QDomNode &n,
309 PwMDataItem *dta) 309 PwMDataItem *dta)
310{ 310{
311 QDomNodeList nl(n.childNodes()); 311 QDomNodeList nl(n.childNodes());
312 QDomNode cur, cdata; 312 QDomNode cur, cdata;
313 unsigned int cnt = nl.count(), i; 313 unsigned int cnt = nl.count(), i;
314 QString name, text; 314 QString name, text;
315 315
316 if (!cnt) { 316 if (!cnt) {
317 printDebug("Serializer::extractEntry(): empty"); 317 printDebug("Serializer::extractEntry(): empty");
318 return false; 318 return false;
319 } 319 }
320 dta->clear(); 320 dta->clear();
321 for (i = 0; i < cnt; ++i) { 321 for (i = 0; i < cnt; ++i) {
322 cur = nl.item(i); 322 cur = nl.item(i);
323 name = cur.nodeName(); 323 name = cur.nodeName();
324 cdata = cur.firstChild(); 324 cdata = cur.firstChild();
325 if (unlikely(cdata.isCDATASection())) { 325 if (unlikely(cdata.isCDATASection())) {
326 text = cdata.toCDATASection().data(); 326 text = cdata.toCDATASection().data();
327 } else if (likely(cur.isElement())) { 327 } else if (likely(cur.isElement())) {
328 text = cur.toElement().text(); 328 text = cur.toElement().text();
329 } else { 329 } else {
330 printDebug("Serializer::extractEntry(): neither CDATA nor element."); 330 printDebug("Serializer::extractEntry(): neither CDATA nor element.");
331 return false; 331 return false;
332 } 332 }
333 if (text == " ") 333 if (text == " ")
334 text = ""; // for backward compatibility. 334 text = ""; // for backward compatibility.
335 if (name == ENTRY_DESC_NEW || 335 if (name == ENTRY_DESC_NEW ||
336 name == ENTRY_DESC_OLD) { 336 name == ENTRY_DESC_OLD) {
337 dta->desc = unescapeEntryData(text).latin1(); 337 dta->desc = unescapeEntryData(text).latin1();
338 } else if (name == ENTRY_NAME_NEW || 338 } else if (name == ENTRY_NAME_NEW ||
339 name == ENTRY_NAME_OLD) { 339 name == ENTRY_NAME_OLD) {
340 dta->name = unescapeEntryData(text).latin1(); 340 dta->name = unescapeEntryData(text).latin1();
341 } else if (name == ENTRY_PW_NEW || 341 } else if (name == ENTRY_PW_NEW ||
342 name == ENTRY_PW_OLD) { 342 name == ENTRY_PW_OLD) {
343 dta->pw = unescapeEntryData(text).latin1(); 343 dta->pw = unescapeEntryData(text).latin1();
344 } else if (name == ENTRY_COMMENT_NEW || 344 } else if (name == ENTRY_COMMENT_NEW ||
345 name == ENTRY_COMMENT_OLD) { 345 name == ENTRY_COMMENT_OLD) {
346 dta->comment = unescapeEntryData(text).latin1(); 346 dta->comment = unescapeEntryData(text).latin1();
347 } else if (name == ENTRY_URL_NEW || 347 } else if (name == ENTRY_URL_NEW ||
348 name == ENTRY_URL_OLD) { 348 name == ENTRY_URL_OLD) {
349 dta->url = unescapeEntryData(text).latin1(); 349 dta->url = unescapeEntryData(text).latin1();
350 } else if (name == ENTRY_LAUNCHER_NEW || 350 } else if (name == ENTRY_LAUNCHER_NEW ||
351 name == ENTRY_LAUNCHER_OLD) { 351 name == ENTRY_LAUNCHER_OLD) {
352 dta->launcher = unescapeEntryData(text).latin1(); 352 dta->launcher = unescapeEntryData(text).latin1();
353 } else if (name == ENTRY_LVP_NEW || 353 } else if (name == ENTRY_LVP_NEW ||
354 name == ENTRY_LVP_OLD) { 354 name == ENTRY_LVP_OLD) {
355 dta->listViewPos = strtol(text.latin1(), 0, 10); 355 dta->listViewPos = strtol(text.latin1(), 0, 10);
356 } else if (name == ENTRY_BIN_NEW) { 356 } else if (name == ENTRY_BIN_NEW) {
357 // ENTRY_BIN_NEW == ENTRY_BIN_OLD 357 // ENTRY_BIN_NEW == ENTRY_BIN_OLD
358 if (text == "0") { 358 if (text == "0") {
359 dta->binary = false; 359 dta->binary = false;
360 } else { 360 } else {
361 dta->binary = true; 361 dta->binary = true;
362 } 362 }
363 } else if (name == ENTRY_META_NEW) { 363 } else if (name == ENTRY_META_NEW) {
364 // ENTRY_META_NEW == ENTRY_META_OLD 364 // ENTRY_META_NEW == ENTRY_META_OLD
365 if (!extractMeta(cur, &dta->meta)) 365 if (!extractMeta(cur, &dta->meta))
366 return false; 366 return false;
367 } else { 367 } else {
368 printDebug(string("Serializer::extractEntry(): invalid: ") 368 printDebug(string("Serializer::extractEntry(): invalid: ")
369 + name.latin1()); 369 + name.latin1());
370 } 370 }
371 } 371 }
372 dta->lockStat = defaultLockStat; 372 dta->lockStat = defaultLockStat;
373 return true; 373 return true;
374} 374}
375 375
376bool Serializer::extractMeta(const QDomNode &n, 376bool Serializer::extractMeta(const QDomNode &n,
377 PwMMetaData *dta) 377 PwMMetaData *dta)
378{ 378{
379 QDomNode cur(n.firstChild()); 379 QDomNode cur(n.firstChild());
380 QString name, val; 380 QString name, val;
381 while (!cur.isNull()) { 381 while (!cur.isNull()) {
382 name = cur.nodeName(); 382 name = cur.nodeName();
383 val = cur.toElement().text(); 383 val = cur.toElement().text();
384 if (val == "") { 384 if (val == "") {
385 cur = cur.nextSibling(); 385 cur = cur.nextSibling();
386 continue; 386 continue;
387 } 387 }
388#ifndef PWM_EMBEDDED 388#ifndef PWM_EMBEDDED
389 if (name == META_CREATE_DATE) { 389 if (name == META_CREATE_DATE) {
390 dta->create = QDateTime::fromString(val, Qt::ISODate); 390 dta->create = QDateTime::fromString(val, Qt::ISODate);
391 } else if (name == META_VALID_DATE) { 391 } else if (name == META_VALID_DATE) {
392 dta->valid = QDateTime::fromString(val, Qt::ISODate); 392 dta->valid = QDateTime::fromString(val, Qt::ISODate);
393 } else if (name == META_EXPIRE_DATE) { 393 } else if (name == META_EXPIRE_DATE) {
394 dta->expire = QDateTime::fromString(val, Qt::ISODate); 394 dta->expire = QDateTime::fromString(val, Qt::ISODate);
395 } else if (name == META_UPDATE_DATE) { 395 } else if (name == META_UPDATE_DATE) {
396 dta->update = QDateTime::fromString(val, Qt::ISODate); 396 dta->update = QDateTime::fromString(val, Qt::ISODate);
397 } else if (name == META_UPDATE_INT) { 397 } else if (name == META_UPDATE_INT) {
398 dta->updateInt = strtoul(val.latin1(), 0, 10); 398 dta->updateInt = strtoul(val.latin1(), 0, 10);
399 } else if (name == META_UNIQUEID) { 399 } else if (name == META_UNIQUEID) {
400 dta->uniqueid = unescapeEntryData(val).latin1(); 400 dta->uniqueid = unescapeEntryData(val).latin1();
401 } else { 401 } else {
402 printDebug(string("extractMeta(): invalid: ") 402 printDebug(string("extractMeta(): invalid: ")
403 + name.latin1()); 403 + name.latin1());
404 } 404 }
405#else 405#else
406 406
407 QDateTime m_dt;
408
409 if ((name == META_CREATE_DATE) ||
410 (name == META_VALID_DATE) ||
411 (name == META_EXPIRE_DATE) ||
412 (name == META_UPDATE_DATE))
413 {
414 int pos = val.find("T");
415 QString date = val.left(pos);
416 QString time = val.mid(pos+1);
417 qDebug("Serializer::extractMeta from %s to date=%s ,time=%s",val.latin1(), date.latin1(), time.latin1() );
418 bool ok1, ok2;
419
420 QDate m_date = KGlobal::locale()->readDate(date, &ok1);
421 QTime m_time = KGlobal::locale()->readTime(time, &ok2);
422 if ((ok1 == false) || (ok2 == false))
423 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
424 m_dt.setDate(m_date);
425 m_dt.setTime(m_time);
426 }
427 407
408 bool ok = true;
428 409
429 if (name == META_CREATE_DATE) { 410 if (name == META_CREATE_DATE) {
430 dta->create = m_dt; 411 dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
431 } else if (name == META_VALID_DATE) { 412 } else if (name == META_VALID_DATE) {
432 dta->valid = m_dt; 413 dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
433 } else if (name == META_EXPIRE_DATE) { 414 } else if (name == META_EXPIRE_DATE) {
434 dta->expire = m_dt; 415 dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
435 } else if (name == META_UPDATE_DATE) { 416 } else if (name == META_UPDATE_DATE) {
436 dta->update = m_dt; 417 dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok);
437 } else if (name == META_UPDATE_INT) { 418 } else if (name == META_UPDATE_INT) {
438 dta->updateInt = strtoul(val.latin1(), 0, 10); 419 dta->updateInt = strtoul(val.latin1(), 0, 10);
439 } else if (name == META_UNIQUEID) { 420 } else if (name == META_UNIQUEID) {
440 dta->uniqueid = unescapeEntryData(val).latin1(); 421 dta->uniqueid = unescapeEntryData(val).latin1();
441 } else { 422 } else {
442 printDebug(string("extractMeta(): invalid: ") 423 printDebug(string("extractMeta(): invalid: ")
443 + name.latin1()); 424 + name.latin1());
444 } 425 }
426
427 if (ok == false)
428 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
429
430
445#endif 431#endif
446 cur = cur.nextSibling(); 432 cur = cur.nextSibling();
447 } 433 }
448 return true; 434 return true;
449} 435}
450 436
451bool Serializer::checkValid() 437bool Serializer::checkValid()
452{ 438{
453 PWM_ASSERT(domDoc); 439 PWM_ASSERT(domDoc);
454 QDomElement root(domDoc->documentElement()); 440 QDomElement root(domDoc->documentElement());
455 if (root.nodeName() != ROOT_MAGIC_NEW && 441 if (root.nodeName() != ROOT_MAGIC_NEW &&
456 root.nodeName() != ROOT_MAGIC_OLD) { 442 root.nodeName() != ROOT_MAGIC_OLD) {
457 printDebug("Serializer: wrong magic"); 443 printDebug("Serializer: wrong magic");
458 return false; 444 return false;
459 } 445 }
460 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && 446 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW &&
461 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { 447 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) {
462 printDebug("Serializer: wrong version"); 448 printDebug("Serializer: wrong version");
463 return false; 449 return false;
464 } 450 }
465 return true; 451 return true;
466} 452}
467 453
468QDomElement Serializer::genNewRoot() 454QDomElement Serializer::genNewRoot()
469{ 455{
470 PWM_ASSERT(domDoc); 456 PWM_ASSERT(domDoc);
471 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); 457 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR));
472 root.setAttribute(VER_STR_WR, COMPAT_VER_WR); 458 root.setAttribute(VER_STR_WR, COMPAT_VER_WR);
473 domDoc->appendChild(root); 459 domDoc->appendChild(root);
474 return root; 460 return root;
475} 461}
476 462
477bool Serializer::addCategories(QDomElement *e, 463bool Serializer::addCategories(QDomElement *e,
478 const vector<PwMCategoryItem> &dta) 464 const vector<PwMCategoryItem> &dta)
479{ 465{
480 unsigned int numCat = dta.size(), i; 466 unsigned int numCat = dta.size(), i;
481 QString curId, curName; 467 QString curId, curName;
482 QDomElement curCat; 468 QDomElement curCat;
483 469
484 for (i = 0; i < numCat; ++i) { 470 for (i = 0; i < numCat; ++i) {
485 curId = CAT_PREFIX_WR; 471 curId = CAT_PREFIX_WR;
486 curId += tostr(i).c_str(); 472 curId += tostr(i).c_str();
487 curName = dta[i].name.c_str(); 473 curName = dta[i].name.c_str();
488 curCat = domDoc->createElement(curId); 474 curCat = domDoc->createElement(curId);
489 curCat.setAttribute(CAT_NAME_WR, curName); 475 curCat.setAttribute(CAT_NAME_WR, curName);
490 if (!addEntries(&curCat, dta[i].d)) { 476 if (!addEntries(&curCat, dta[i].d)) {
491 return false; 477 return false;
492 } 478 }
493 e->appendChild(curCat); 479 e->appendChild(curCat);
494 } 480 }
495 return true; 481 return true;
496} 482}
497 483
498bool Serializer::addEntries(QDomElement *e, 484bool Serializer::addEntries(QDomElement *e,
499 const vector<PwMDataItem> &dta) 485 const vector<PwMDataItem> &dta)
500{ 486{
501 unsigned int numEntr = dta.size(), i; 487 unsigned int numEntr = dta.size(), i;
502 QString curId; 488 QString curId;
503 QDomElement curEntr; 489 QDomElement curEntr;
504 490
505 for (i = 0; i < numEntr; ++i) { 491 for (i = 0; i < numEntr; ++i) {
506 curId = ENTRY_PREFIX_WR; 492 curId = ENTRY_PREFIX_WR;
507 curId += tostr(i).c_str(); 493 curId += tostr(i).c_str();
508 curEntr = domDoc->createElement(curId); 494 curEntr = domDoc->createElement(curId);
509 if (!writeEntry(&curEntr, dta[i])) { 495 if (!writeEntry(&curEntr, dta[i])) {
510 return false; 496 return false;
511 } 497 }
512 e->appendChild(curEntr); 498 e->appendChild(curEntr);
513 } 499 }
514 return true; 500 return true;
515} 501}
516 502
517bool Serializer::writeEntry(QDomElement *e, 503bool Serializer::writeEntry(QDomElement *e,
518 const PwMDataItem &_dta) 504 const PwMDataItem &_dta)
519{ 505{
520#if WRITE_CDATA_SEC != 0 506#if WRITE_CDATA_SEC != 0
521 # define new_text(x)domDoc->createCDATASection(x) 507 # define new_text(x)domDoc->createCDATASection(x)
522 QDomCDATASection curText; 508 QDomCDATASection curText;
523#else 509#else
524 # define new_text(x)domDoc->createTextNode(x) 510 # define new_text(x)domDoc->createTextNode(x)
525 QDomText curText; 511 QDomText curText;
526#endif 512#endif
527 513
528 QDomText plainText; 514 QDomText plainText;
529 QDomElement tag; 515 QDomElement tag;
530 516
531 // begin -- This is for compatibility with the old serializer 517 // begin -- This is for compatibility with the old serializer
532 PwMDataItem dta = _dta; 518 PwMDataItem dta = _dta;
533 if (!dta.desc.size()) 519 if (!dta.desc.size())
534 dta.desc = " "; 520 dta.desc = " ";
535 if (!dta.name.size()) 521 if (!dta.name.size())
536 dta.name = " "; 522 dta.name = " ";
537 if (!dta.pw.size()) 523 if (!dta.pw.size())
538 dta.pw = " "; 524 dta.pw = " ";
539 if (!dta.comment.size()) 525 if (!dta.comment.size())
540 dta.comment = " "; 526 dta.comment = " ";
541 if (!dta.url.size()) 527 if (!dta.url.size())
542 dta.url = " "; 528 dta.url = " ";
543 if (!dta.launcher.size()) 529 if (!dta.launcher.size())
544 dta.launcher = " "; 530 dta.launcher = " ";
545 // end -- This is for compatibility with the old serializer 531 // end -- This is for compatibility with the old serializer
546 532
547 tag = domDoc->createElement(ENTRY_DESC_WR); 533 tag = domDoc->createElement(ENTRY_DESC_WR);
548 curText = new_text(escapeEntryData(dta.desc.c_str())); 534 curText = new_text(escapeEntryData(dta.desc.c_str()));
549 tag.appendChild(curText); 535 tag.appendChild(curText);
550 e->appendChild(tag); 536 e->appendChild(tag);
551 537
552 tag = domDoc->createElement(ENTRY_NAME_WR); 538 tag = domDoc->createElement(ENTRY_NAME_WR);
553 curText = new_text(escapeEntryData(dta.name.c_str())); 539 curText = new_text(escapeEntryData(dta.name.c_str()));
554 tag.appendChild(curText); 540 tag.appendChild(curText);
555 e->appendChild(tag); 541 e->appendChild(tag);
556 542
557 tag = domDoc->createElement(ENTRY_PW_WR); 543 tag = domDoc->createElement(ENTRY_PW_WR);
558 curText = new_text(escapeEntryData(dta.pw.c_str())); 544 curText = new_text(escapeEntryData(dta.pw.c_str()));
559 tag.appendChild(curText); 545 tag.appendChild(curText);
560 e->appendChild(tag); 546 e->appendChild(tag);
561 547
562 tag = domDoc->createElement(ENTRY_COMMENT_WR); 548 tag = domDoc->createElement(ENTRY_COMMENT_WR);
563 curText = new_text(escapeEntryData(dta.comment.c_str())); 549 curText = new_text(escapeEntryData(dta.comment.c_str()));
564 tag.appendChild(curText); 550 tag.appendChild(curText);
565 e->appendChild(tag); 551 e->appendChild(tag);
566 552
567 tag = domDoc->createElement(ENTRY_URL_WR); 553 tag = domDoc->createElement(ENTRY_URL_WR);
568 curText = new_text(escapeEntryData(dta.url.c_str())); 554 curText = new_text(escapeEntryData(dta.url.c_str()));
569 tag.appendChild(curText); 555 tag.appendChild(curText);
570 e->appendChild(tag); 556 e->appendChild(tag);
571 557
572 tag = domDoc->createElement(ENTRY_LAUNCHER_WR); 558 tag = domDoc->createElement(ENTRY_LAUNCHER_WR);
573 curText = new_text(escapeEntryData(dta.launcher.c_str())); 559 curText = new_text(escapeEntryData(dta.launcher.c_str()));
574 tag.appendChild(curText); 560 tag.appendChild(curText);
575 e->appendChild(tag); 561 e->appendChild(tag);
576 562
577 tag = domDoc->createElement(ENTRY_LVP_WR); 563 tag = domDoc->createElement(ENTRY_LVP_WR);
578 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); 564 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str());
579 tag.appendChild(plainText); 565 tag.appendChild(plainText);
580 e->appendChild(tag); 566 e->appendChild(tag);
581 567
582 tag = domDoc->createElement(ENTRY_BIN_WR); 568 tag = domDoc->createElement(ENTRY_BIN_WR);
583 if (dta.binary) 569 if (dta.binary)
584 plainText = domDoc->createTextNode("1"); 570 plainText = domDoc->createTextNode("1");
585 else 571 else
586 plainText = domDoc->createTextNode("0"); 572 plainText = domDoc->createTextNode("0");
587 tag.appendChild(plainText); 573 tag.appendChild(plainText);
588 e->appendChild(tag); 574 e->appendChild(tag);
589 575
590 tag = domDoc->createElement(ENTRY_META_WR); 576 tag = domDoc->createElement(ENTRY_META_WR);
591 if (!writeMeta(&tag, dta.meta)) 577 if (!writeMeta(&tag, dta.meta))
592 return false; 578 return false;
593 e->appendChild(tag); 579 e->appendChild(tag);
594 580
595#undef new_text 581#undef new_text
596 return true; 582 return true;
597} 583}
598 584
599bool Serializer::writeMeta(QDomElement *e, 585bool Serializer::writeMeta(QDomElement *e,
600 const PwMMetaData &dta) 586 const PwMMetaData &dta)
601{ 587{
602 QDomText text; 588 QDomText text;
603 QDomElement tag; 589 QDomElement tag;
604 590
605 tag = domDoc->createElement(META_CREATE_DATE); 591 tag = domDoc->createElement(META_CREATE_DATE);
606#ifndef PWM_EMBEDDED 592#ifndef PWM_EMBEDDED
607 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); 593 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
608#else 594#else
609 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); 595 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
610#endif 596#endif
611 tag.appendChild(text); 597 tag.appendChild(text);
612 e->appendChild(tag); 598 e->appendChild(tag);
613 599
614 tag = domDoc->createElement(META_VALID_DATE); 600 tag = domDoc->createElement(META_VALID_DATE);
615#ifndef PWM_EMBEDDED 601#ifndef PWM_EMBEDDED
616 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); 602 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
617#else 603#else
618 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); 604 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
619#endif 605#endif
620 tag.appendChild(text); 606 tag.appendChild(text);
621 e->appendChild(tag); 607 e->appendChild(tag);
622 608
623 tag = domDoc->createElement(META_EXPIRE_DATE); 609 tag = domDoc->createElement(META_EXPIRE_DATE);
624#ifndef PWM_EMBEDDED 610#ifndef PWM_EMBEDDED
625 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); 611 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
626#else 612#else
627 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); 613 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
628#endif 614#endif
629 tag.appendChild(text); 615 tag.appendChild(text);
630 e->appendChild(tag); 616 e->appendChild(tag);
631 617
632 tag = domDoc->createElement(META_UPDATE_DATE); 618 tag = domDoc->createElement(META_UPDATE_DATE);
633#ifndef PWM_EMBEDDED 619#ifndef PWM_EMBEDDED
634 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); 620 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
635#else 621#else
636 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); 622 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
637#endif 623#endif
638 tag.appendChild(text); 624 tag.appendChild(text);
639 e->appendChild(tag); 625 e->appendChild(tag);
640 626
641 tag = domDoc->createElement(META_UPDATE_INT); 627 tag = domDoc->createElement(META_UPDATE_INT);
642 text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); 628 text = domDoc->createTextNode(tostr(dta.updateInt).c_str());
643 tag.appendChild(text); 629 tag.appendChild(text);
644 e->appendChild(tag); 630 e->appendChild(tag);
645 631
646 tag = domDoc->createElement(META_UNIQUEID); 632 tag = domDoc->createElement(META_UNIQUEID);
647 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); 633 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid));
648 tag.appendChild(text); 634 tag.appendChild(text);
649 e->appendChild(tag); 635 e->appendChild(tag);
650 636
651#undef new_text 637#undef new_text
652 return true; 638 return true;
653} 639}
654 640
655QString Serializer::escapeEntryData(QString dta) 641QString Serializer::escapeEntryData(QString dta)
656{ 642{
657#ifndef PWM_EMBEDDED 643#ifndef PWM_EMBEDDED
658 dta.replace('\n', "$>--endl--<$"); 644 dta.replace('\n', "$>--endl--<$");
659 dta.replace("]]>", "||>"); 645 dta.replace("]]>", "||>");
660#else 646#else
661 dta.replace(QRegExp("\n"), "$>--endl--<$"); 647 dta.replace(QRegExp("\n"), "$>--endl--<$");
662 dta.replace(QRegExp("]]>"), "||>"); 648 dta.replace(QRegExp("]]>"), "||>");
663#endif 649#endif
664 return dta; 650 return dta;
665} 651}
666 652
667QString Serializer::unescapeEntryData(QString dta) 653QString Serializer::unescapeEntryData(QString dta)
668{ 654{
669#ifndef PWM_EMBEDDED 655#ifndef PWM_EMBEDDED
670 dta.replace("$>--endl--<$", "\n"); 656 dta.replace("$>--endl--<$", "\n");
671 dta.replace("||>", "]]>"); 657 dta.replace("||>", "]]>");
672#else 658#else
673 dta.replace(QRegExp("$>--endl--<$"), "\n"); 659 dta.replace(QRegExp("$>--endl--<$"), "\n");
674 dta.replace(QRegExp("||>"), "]]>"); 660 dta.replace(QRegExp("||>"), "]]>");
675#endif 661#endif
676 return dta; 662 return dta;
677} 663}