-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 568 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 70 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmexception.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 64 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.h | 22 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 109 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.h | 17 |
9 files changed, 746 insertions, 109 deletions
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro index 2558aca..95f5bf3 100644 --- a/pwmanager/pwmanager/pwmanagerE.pro +++ b/pwmanager/pwmanager/pwmanagerE.pro | |||
@@ -1,156 +1,156 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | 3 | ||
4 | 4 | ||
5 | TARGET = pwmpi | 5 | TARGET = pwmpi |
6 | OBJECTS_DIR = obj/$(PLATFORM) | 6 | OBJECTS_DIR = obj/$(PLATFORM) |
7 | MOC_DIR = moc/$(PLATFORM) | 7 | MOC_DIR = moc/$(PLATFORM) |
8 | DESTDIR=$(QPEDIR)/bin | 8 | DESTDIR=$(QPEDIR)/bin |
9 | 9 | ||
10 | INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include | 10 | INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include |
11 | DEFINES += PWM_EMBEDDED | 11 | DEFINES += PWM_EMBEDDED |
12 | #enable this setting if you want debugoutput for pwmanager | 12 | #enable this setting if you want debugoutput for pwmanager |
13 | #DEFINES += CONFIG_DEBUG | 13 | #DEFINES += CONFIG_DEBUG |
14 | 14 | ||
15 | LIBS += -lmicrokde | 15 | LIBS += -lmicrokde |
16 | LIBS += -lmicroqtcompat | 16 | LIBS += -lmicroqtcompat |
17 | LIBS += -lmicrokdepim | 17 | LIBS += -lmicrokdepim |
18 | LIBS += -L$(QPEDIR)/lib | 18 | LIBS += -L$(QPEDIR)/lib |
19 | LIBS += -lqpe | 19 | LIBS += -lqpe |
20 | LIBS += -lbz2 | 20 | LIBS += -lbz2 |
21 | LIBS += $(QTOPIALIB) | 21 | LIBS += $(QTOPIALIB) |
22 | 22 | ||
23 | #INTERFACES = \ | 23 | #INTERFACES = \ |
24 | #addentrywnd.ui \ | 24 | #addentrywnd.ui \ |
25 | #configwnd.ui \ | 25 | #configwnd.ui \ |
26 | #findwnd.ui \ | 26 | #findwnd.ui \ |
27 | #getmasterpwwnd.ui \ | 27 | #getmasterpwwnd.ui \ |
28 | #pwgenwnd.ui \ | 28 | #pwgenwnd.ui \ |
29 | #setmasterpwwnd.ui \ | 29 | #setmasterpwwnd.ui \ |
30 | #subtbledit.ui | 30 | #subtbledit.ui |
31 | 31 | ||
32 | #INTERFACES = \ | 32 | #INTERFACES = \ |
33 | #subtbledit.ui \ | 33 | #subtbledit.ui \ |
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | #HEADERS = \ | 37 | #HEADERS = \ |
38 | #configuration_31compat.h \ | 38 | #configuration_31compat.h \ |
39 | #configuration.h \ | 39 | #configuration.h \ |
40 | #configwnd.h \ | 40 | #configwnd.h \ |
41 | #configwndimpl.h \ | 41 | #configwndimpl.h \ |
42 | #selftest.h | 42 | #selftest.h |
43 | #subtbledit.h \ | 43 | #subtbledit.h \ |
44 | #subtbleditimpl.h \ | 44 | #subtbleditimpl.h \ |
45 | 45 | ||
46 | HEADERS = \ | 46 | HEADERS = \ |
47 | addentrywnd_emb.h \ | 47 | addentrywnd_emb.h \ |
48 | addentrywndimpl.h \ | 48 | addentrywndimpl.h \ |
49 | base64.h \ | 49 | base64.h \ |
50 | binentrygen.h \ | 50 | binentrygen.h \ |
51 | blowfish.h \ | 51 | blowfish.h \ |
52 | commentbox.h \ | 52 | commentbox.h \ |
53 | compiler.h \ | 53 | compiler.h \ |
54 | compressbzip2.h \ | 54 | compressbzip2.h \ |
55 | compressgzip.h \ | 55 | compressgzip.h \ |
56 | findwnd_emb.h \ | 56 | findwnd_emb.h \ |
57 | findwndimpl.h \ | 57 | findwndimpl.h \ |
58 | genpasswd.h \ | 58 | genpasswd.h \ |
59 | getkeycardwnd.h \ | 59 | getkeycardwnd.h \ |
60 | getmasterpwwnd_emb.h \ | 60 | getmasterpwwnd_emb.h \ |
61 | getmasterpwwndimpl.h \ | 61 | getmasterpwwndimpl.h \ |
62 | globalstuff.h \ | 62 | globalstuff.h \ |
63 | gpasmanfile.h \ | 63 | gpasmanfile.h \ |
64 | htmlgen.h \ | 64 | htmlgen.h \ |
65 | htmlparse.h \ | 65 | htmlparse.h \ |
66 | ipc.h \ | 66 | ipc.h \ |
67 | listobjselectwnd.h \ | 67 | listobjselectwnd.h \ |
68 | listviewpwm.h \ | 68 | listviewpwm.h \ |
69 | printtext.h \ | 69 | printtext.h \ |
70 | pwgenwnd_emb.h \ | 70 | pwgenwnd_emb.h \ |
71 | pwgenwndimpl.h \ | 71 | pwgenwndimpl.h \ |
72 | pwmdoc.h \ | 72 | pwmdoc.h \ |
73 | pwmdocui.h \ | 73 | pwmdocui.h \ |
74 | pwmexception.h \ | 74 | pwmexception.h \ |
75 | pwm.h \ | 75 | pwm.h \ |
76 | pwminit.h \ | 76 | pwminit.h \ |
77 | pwmprefs.h \ | 77 | pwmprefs.h \ |
78 | pwmprint.h \ | 78 | pwmprint.h \ |
79 | pwmtray.h \ | 79 | pwmtray.h \ |
80 | pwmview.h \ | 80 | pwmview.h \ |
81 | pwmviewstyle_0.h \ | 81 | pwmviewstyle_0.h \ |
82 | pwmviewstyle_1.h \ | 82 | pwmviewstyle_1.h \ |
83 | pwmviewstyle.h \ | 83 | pwmviewstyle.h \ |
84 | randomizer.h \ | 84 | randomizer.h \ |
85 | rc2.h \ | 85 | rc2.h \ |
86 | rencatwnd.h \ | 86 | rencatwnd.h \ |
87 | serializer.h \ | 87 | serializer.h \ |
88 | setmasterpwwnd_emb.h \ | 88 | setmasterpwwnd_emb.h \ |
89 | setmasterpwwndimpl.h \ | 89 | setmasterpwwndimpl.h \ |
90 | sha1.h \ | 90 | sha1.h \ |
91 | waitwnd.h \ | 91 | waitwnd.h \ |
92 | kcmconfigs/kcmpwmconfig.h \ | 92 | kcmconfigs/kcmpwmconfig.h \ |
93 | kcmconfigs/pwmconfigwidget.h \ | 93 | kcmconfigs/pwmconfigwidget.h \ |
94 | 94 | ||
95 | #sources that need not be build | 95 | #sources that need not be build |
96 | #SOURCES = \ | 96 | #SOURCES = \ |
97 | #advcommeditimpl.cpp \ | 97 | #advcommeditimpl.cpp \ |
98 | #configuration.cpp \ | 98 | #configuration.cpp \ |
99 | #configwnd.cpp \ | 99 | #configwnd.cpp \ |
100 | #configwndimpl.cpp \ | 100 | #configwndimpl.cpp \ |
101 | #configuration_31compat.cpp \ | 101 | #configuration_31compat.cpp \ |
102 | #htmlparse.cpp \ | 102 | #htmlparse.cpp \ |
103 | #printtext.cpp \ | 103 | #printtext.cpp \ |
104 | #selftest.cpp \ | 104 | #selftest.cpp \ |
105 | #pwmprint.cpp \ | 105 | #pwmprint.cpp \ |
106 | #spinforsignal.cpp | 106 | #spinforsignal.cpp |
107 | #subtbledit.cpp \ | 107 | #subtbledit.cpp \ |
108 | #subtbleditimpl.cpp \ | 108 | #subtbleditimpl.cpp \ |
109 | 109 | ||
110 | SOURCES = \ | 110 | SOURCES = \ |
111 | addentrywnd_emb.cpp \ | 111 | addentrywnd_emb.cpp \ |
112 | addentrywndimpl.cpp \ | 112 | addentrywndimpl.cpp \ |
113 | base64.cpp \ | 113 | base64.cpp \ |
114 | binentrygen.cpp \ | 114 | binentrygen.cpp \ |
115 | blowfish.cpp \ | 115 | blowfish.cpp \ |
116 | commentbox.cpp \ | 116 | commentbox.cpp \ |
117 | compressbzip2.cpp \ | 117 | compressbzip2.cpp \ |
118 | compressgzip.cpp \ | 118 | compressgzip.cpp \ |
119 | findwnd_emb.cpp \ | 119 | findwnd_emb.cpp \ |
120 | findwndimpl.cpp \ | 120 | findwndimpl.cpp \ |
121 | genpasswd.cpp \ | 121 | genpasswd.cpp \ |
122 | getkeycardwnd.cpp \ | 122 | getkeycardwnd.cpp \ |
123 | getmasterpwwnd_emb.cpp \ | 123 | getmasterpwwnd_emb.cpp \ |
124 | getmasterpwwndimpl.cpp \ | 124 | getmasterpwwndimpl.cpp \ |
125 | globalstuff.cpp \ | 125 | globalstuff.cpp \ |
126 | gpasmanfile.cpp \ | 126 | gpasmanfile.cpp \ |
127 | htmlgen.cpp \ | 127 | htmlgen.cpp \ |
128 | ipc.cpp \ | 128 | ipc.cpp \ |
129 | listobjselectwnd.cpp \ | 129 | listobjselectwnd.cpp \ |
130 | listviewpwm.cpp \ | 130 | listviewpwm.cpp \ |
131 | main.cpp \ | 131 | main.cpp \ |
132 | pwgenwnd_emb.cpp \ | 132 | pwgenwnd_emb.cpp \ |
133 | pwgenwndimpl.cpp \ | 133 | pwgenwndimpl.cpp \ |
134 | pwm.cpp \ | 134 | pwm.cpp \ |
135 | pwmdoc.cpp \ | 135 | pwmdoc.cpp \ |
136 | pwmdocui.cpp \ | 136 | pwmdocui.cpp \ |
137 | pwmexception.cpp \ | 137 | pwmexception.cpp \ |
138 | pwminit.cpp \ | 138 | pwminit.cpp \ |
139 | pwmprefs.cpp \ | 139 | pwmprefs.cpp \ |
140 | pwmtray.cpp \ | 140 | pwmtray.cpp \ |
141 | pwmview.cpp \ | 141 | pwmview.cpp \ |
142 | pwmviewstyle_0.cpp \ | 142 | pwmviewstyle_0.cpp \ |
143 | pwmviewstyle_1.cpp \ | 143 | pwmviewstyle_1.cpp \ |
144 | pwmviewstyle.cpp \ | 144 | pwmviewstyle.cpp \ |
145 | randomizer.cpp \ | 145 | randomizer.cpp \ |
146 | rc2.cpp \ | 146 | rc2.cpp \ |
147 | rencatwnd.cpp \ | 147 | rencatwnd.cpp \ |
148 | serializer.cpp \ | 148 | serializer.cpp \ |
149 | setmasterpwwnd_emb.cpp \ | 149 | setmasterpwwnd_emb.cpp \ |
150 | setmasterpwwndimpl.cpp \ | 150 | setmasterpwwndimpl.cpp \ |
151 | sha1.cpp \ | 151 | sha1.cpp \ |
152 | waitwnd.cpp \ | 152 | waitwnd.cpp \ |
153 | kcmconfigs/kcmpwmconfig.cpp \ | 153 | kcmconfigs/kcmpwmconfig.cpp \ |
154 | kcmconfigs/pwmconfigwidget.cpp \ | 154 | kcmconfigs/pwmconfigwidget.cpp \ |
155 | 155 | ||
156 | 156 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 82fc746..4e8a603 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,229 +1,233 @@ | |||
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 | #include <kmessagebox.h> | ||
39 | #include <libkcal/syncdefines.h> | ||
40 | |||
41 | |||
38 | #ifdef CONFIG_KWALLETIF | 42 | #ifdef CONFIG_KWALLETIF |
39 | # include "kwalletemu.h" | 43 | # include "kwalletemu.h" |
40 | #endif // CONFIG_KWALLETIF | 44 | #endif // CONFIG_KWALLETIF |
41 | 45 | ||
42 | #include <qdatetime.h> | 46 | #include <qdatetime.h> |
43 | #include <qsize.h> | 47 | #include <qsize.h> |
44 | #include <qfileinfo.h> | 48 | #include <qfileinfo.h> |
45 | #include <qfile.h> | 49 | #include <qfile.h> |
46 | 50 | ||
47 | #include <stdio.h> | 51 | #include <stdio.h> |
48 | #include <stdlib.h> | 52 | #include <stdlib.h> |
49 | #include <errno.h> | 53 | #include <errno.h> |
50 | #include <string.h> | 54 | #include <string.h> |
51 | //US#include <iostream> | 55 | //US#include <iostream> |
52 | #include <algorithm> | 56 | #include <algorithm> |
53 | #include <sys/types.h> | 57 | #include <sys/types.h> |
54 | #include <sys/stat.h> | 58 | #include <sys/stat.h> |
55 | #include <unistd.h> | 59 | #include <unistd.h> |
56 | #include <stdint.h> | 60 | #include <stdint.h> |
57 | 61 | ||
58 | //TODO: reset to its normal value. | 62 | //TODO: reset to its normal value. |
59 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 63 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
60 | 64 | ||
61 | using namespace std; | 65 | using namespace std; |
62 | 66 | ||
63 | 67 | ||
64 | void PwMDocList::add(PwMDoc *doc, const string &id) | 68 | void PwMDocList::add(PwMDoc *doc, const string &id) |
65 | { | 69 | { |
66 | #ifdef PWM_DEBUG | 70 | #ifdef PWM_DEBUG |
67 | // check for existance of object in debug mode only. | 71 | // check for existance of object in debug mode only. |
68 | vector<listItem>::iterator begin = docList.begin(), | 72 | vector<listItem>::iterator begin = docList.begin(), |
69 | end = docList.end(), | 73 | end = docList.end(), |
70 | i = begin; | 74 | i = begin; |
71 | while (i != end) { | 75 | while (i != end) { |
72 | if (i->doc == doc) { | 76 | if (i->doc == doc) { |
73 | BUG(); | 77 | BUG(); |
74 | return; | 78 | return; |
75 | } | 79 | } |
76 | ++i; | 80 | ++i; |
77 | } | 81 | } |
78 | #endif | 82 | #endif |
79 | listItem newItem; | 83 | listItem newItem; |
80 | newItem.doc = doc; | 84 | newItem.doc = doc; |
81 | newItem.docId = id; | 85 | newItem.docId = id; |
82 | docList.push_back(newItem); | 86 | docList.push_back(newItem); |
83 | } | 87 | } |
84 | 88 | ||
85 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 89 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
86 | { | 90 | { |
87 | vector<listItem>::iterator begin = docList.begin(), | 91 | vector<listItem>::iterator begin = docList.begin(), |
88 | end = docList.end(), | 92 | end = docList.end(), |
89 | i = begin; | 93 | i = begin; |
90 | while (i != end) { | 94 | while (i != end) { |
91 | if (i->doc == doc) { | 95 | if (i->doc == doc) { |
92 | i->docId = newId; | 96 | i->docId = newId; |
93 | return; | 97 | return; |
94 | } | 98 | } |
95 | ++i; | 99 | ++i; |
96 | } | 100 | } |
97 | } | 101 | } |
98 | 102 | ||
99 | void PwMDocList::del(PwMDoc *doc) | 103 | void PwMDocList::del(PwMDoc *doc) |
100 | { | 104 | { |
101 | vector<listItem>::iterator begin = docList.begin(), | 105 | vector<listItem>::iterator begin = docList.begin(), |
102 | end = docList.end(), | 106 | end = docList.end(), |
103 | i = begin; | 107 | i = begin; |
104 | while (i != end) { | 108 | while (i != end) { |
105 | if (i->doc == doc) { | 109 | if (i->doc == doc) { |
106 | docList.erase(i); | 110 | docList.erase(i); |
107 | return; | 111 | return; |
108 | } | 112 | } |
109 | ++i; | 113 | ++i; |
110 | } | 114 | } |
111 | } | 115 | } |
112 | 116 | ||
113 | bool PwMDocList::find(const string &id, listItem *ret) | 117 | bool PwMDocList::find(const string &id, listItem *ret) |
114 | { | 118 | { |
115 | vector<listItem>::iterator begin = docList.begin(), | 119 | vector<listItem>::iterator begin = docList.begin(), |
116 | end = docList.end(), | 120 | end = docList.end(), |
117 | i = begin; | 121 | i = begin; |
118 | while (i != end) { | 122 | while (i != end) { |
119 | if (i->docId == id) { | 123 | if (i->docId == id) { |
120 | if (ret) | 124 | if (ret) |
121 | *ret = *i; | 125 | *ret = *i; |
122 | return true; | 126 | return true; |
123 | } | 127 | } |
124 | ++i; | 128 | ++i; |
125 | } | 129 | } |
126 | return false; | 130 | return false; |
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
130 | 134 | ||
131 | DocTimer::DocTimer(PwMDoc *_doc) | 135 | DocTimer::DocTimer(PwMDoc *_doc) |
132 | : doc (_doc) | 136 | : doc (_doc) |
133 | , mpwLock (0) | 137 | , mpwLock (0) |
134 | , autoLockLock (0) | 138 | , autoLockLock (0) |
135 | , metaCheckLock (0) | 139 | , metaCheckLock (0) |
136 | { | 140 | { |
137 | mpwTimer = new QTimer; | 141 | mpwTimer = new QTimer; |
138 | autoLockTimer = new QTimer; | 142 | autoLockTimer = new QTimer; |
139 | metaCheckTimer = new QTimer; | 143 | metaCheckTimer = new QTimer; |
140 | connect(mpwTimer, SIGNAL(timeout()), | 144 | connect(mpwTimer, SIGNAL(timeout()), |
141 | this, SLOT(mpwTimeout())); | 145 | this, SLOT(mpwTimeout())); |
142 | connect(autoLockTimer, SIGNAL(timeout()), | 146 | connect(autoLockTimer, SIGNAL(timeout()), |
143 | this, SLOT(autoLockTimeout())); | 147 | this, SLOT(autoLockTimeout())); |
144 | connect(metaCheckTimer, SIGNAL(timeout()), | 148 | connect(metaCheckTimer, SIGNAL(timeout()), |
145 | this, SLOT(metaCheckTimeout())); | 149 | this, SLOT(metaCheckTimeout())); |
146 | } | 150 | } |
147 | 151 | ||
148 | DocTimer::~DocTimer() | 152 | DocTimer::~DocTimer() |
149 | { | 153 | { |
150 | delete mpwTimer; | 154 | delete mpwTimer; |
151 | delete autoLockTimer; | 155 | delete autoLockTimer; |
152 | delete metaCheckTimer; | 156 | delete metaCheckTimer; |
153 | } | 157 | } |
154 | 158 | ||
155 | void DocTimer::start(TimerIDs timer) | 159 | void DocTimer::start(TimerIDs timer) |
156 | { | 160 | { |
157 | switch (timer) { | 161 | switch (timer) { |
158 | case id_mpwTimer: | 162 | case id_mpwTimer: |
159 | if (mpwTimer->isActive()) | 163 | if (mpwTimer->isActive()) |
160 | mpwTimer->stop(); | 164 | mpwTimer->stop(); |
161 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 165 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
162 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 166 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
163 | break; | 167 | break; |
164 | case id_autoLockTimer: | 168 | case id_autoLockTimer: |
165 | if (autoLockTimer->isActive()) | 169 | if (autoLockTimer->isActive()) |
166 | autoLockTimer->stop(); | 170 | autoLockTimer->stop(); |
167 | if (conf()->confGlobLockTimeout() > 0) | 171 | if (conf()->confGlobLockTimeout() > 0) |
168 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 172 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
169 | break; | 173 | break; |
170 | case id_metaCheckTimer: | 174 | case id_metaCheckTimer: |
171 | if (metaCheckTimer->isActive()) | 175 | if (metaCheckTimer->isActive()) |
172 | metaCheckTimer->stop(); | 176 | metaCheckTimer->stop(); |
173 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 177 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
174 | break; | 178 | break; |
175 | } | 179 | } |
176 | } | 180 | } |
177 | 181 | ||
178 | void DocTimer::stop(TimerIDs timer) | 182 | void DocTimer::stop(TimerIDs timer) |
179 | { | 183 | { |
180 | switch (timer) { | 184 | switch (timer) { |
181 | case id_mpwTimer: | 185 | case id_mpwTimer: |
182 | mpwTimer->stop(); | 186 | mpwTimer->stop(); |
183 | break; | 187 | break; |
184 | case id_autoLockTimer: | 188 | case id_autoLockTimer: |
185 | autoLockTimer->stop(); | 189 | autoLockTimer->stop(); |
186 | break; | 190 | break; |
187 | case id_metaCheckTimer: | 191 | case id_metaCheckTimer: |
188 | metaCheckTimer->stop(); | 192 | metaCheckTimer->stop(); |
189 | break; | 193 | break; |
190 | } | 194 | } |
191 | } | 195 | } |
192 | 196 | ||
193 | void DocTimer::getLock(TimerIDs timer) | 197 | void DocTimer::getLock(TimerIDs timer) |
194 | { | 198 | { |
195 | switch (timer) { | 199 | switch (timer) { |
196 | case id_mpwTimer: | 200 | case id_mpwTimer: |
197 | ++mpwLock; | 201 | ++mpwLock; |
198 | break; | 202 | break; |
199 | case id_autoLockTimer: | 203 | case id_autoLockTimer: |
200 | ++autoLockLock; | 204 | ++autoLockLock; |
201 | break; | 205 | break; |
202 | case id_metaCheckTimer: | 206 | case id_metaCheckTimer: |
203 | ++metaCheckLock; | 207 | ++metaCheckLock; |
204 | break; | 208 | break; |
205 | } | 209 | } |
206 | } | 210 | } |
207 | 211 | ||
208 | void DocTimer::putLock(TimerIDs timer) | 212 | void DocTimer::putLock(TimerIDs timer) |
209 | { | 213 | { |
210 | switch (timer) { | 214 | switch (timer) { |
211 | case id_mpwTimer: | 215 | case id_mpwTimer: |
212 | if (mpwLock) | 216 | if (mpwLock) |
213 | --mpwLock; | 217 | --mpwLock; |
214 | break; | 218 | break; |
215 | case id_autoLockTimer: | 219 | case id_autoLockTimer: |
216 | if (autoLockLock) | 220 | if (autoLockLock) |
217 | --autoLockLock; | 221 | --autoLockLock; |
218 | break; | 222 | break; |
219 | case id_metaCheckTimer: | 223 | case id_metaCheckTimer: |
220 | if (metaCheckLock) | 224 | if (metaCheckLock) |
221 | --metaCheckLock; | 225 | --metaCheckLock; |
222 | break; | 226 | break; |
223 | } | 227 | } |
224 | } | 228 | } |
225 | 229 | ||
226 | void DocTimer::mpwTimeout() | 230 | void DocTimer::mpwTimeout() |
227 | { | 231 | { |
228 | if (mpwLock) { | 232 | if (mpwLock) { |
229 | mpwTimer->start(1000, true); | 233 | mpwTimer->start(1000, true); |
@@ -818,2061 +822,2447 @@ PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | |||
818 | break; | 822 | break; |
819 | } | 823 | } |
820 | #endif | 824 | #endif |
821 | default: | 825 | default: |
822 | return e_hashNotImpl; | 826 | return e_hashNotImpl; |
823 | } | 827 | } |
824 | *dataHash = ""; | 828 | *dataHash = ""; |
825 | for (i = 0; i < hashLen; ++i) { | 829 | for (i = 0; i < hashLen; ++i) { |
826 | tmpRet = f->getch(); | 830 | tmpRet = f->getch(); |
827 | if (tmpRet == -1) | 831 | if (tmpRet == -1) |
828 | return e_fileFormat; | 832 | return e_fileFormat; |
829 | dataHash->push_back(static_cast<char>(tmpRet)); | 833 | dataHash->push_back(static_cast<char>(tmpRet)); |
830 | } | 834 | } |
831 | *headerLength = f->at(); | 835 | *headerLength = f->at(); |
832 | #ifndef PWM_EMBEDDED | 836 | #ifndef PWM_EMBEDDED |
833 | printDebug(string("opening file { compress: ") | 837 | printDebug(string("opening file { compress: ") |
834 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 838 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
835 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 839 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
836 | + tostr(static_cast<int>(keyHash)) | 840 | + tostr(static_cast<int>(keyHash)) |
837 | + " }"); | 841 | + " }"); |
838 | #else | 842 | #else |
839 | printDebug(string("opening file { compress: ") | 843 | printDebug(string("opening file { compress: ") |
840 | + tostr((int)(*compress)) + " cryptAlgo: " | 844 | + tostr((int)(*compress)) + " cryptAlgo: " |
841 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 845 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
842 | + tostr((int)(keyHash)) | 846 | + tostr((int)(keyHash)) |
843 | + " }"); | 847 | + " }"); |
844 | #endif | 848 | #endif |
845 | 849 | ||
846 | return e_success; | 850 | return e_success; |
847 | } | 851 | } |
848 | 852 | ||
849 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 853 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
850 | { | 854 | { |
851 | PWM_ASSERT(d); | 855 | PWM_ASSERT(d); |
852 | PWM_ASSERT(f); | 856 | PWM_ASSERT(f); |
853 | 857 | ||
854 | switch (dataHash) { | 858 | switch (dataHash) { |
855 | case PWM_HASH_SHA1: { | 859 | case PWM_HASH_SHA1: { |
856 | const int hashLen = SHA1_HASH_LEN_BYTE; | 860 | const int hashLen = SHA1_HASH_LEN_BYTE; |
857 | Sha1 h; | 861 | Sha1 h; |
858 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 862 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
859 | string hRet = h.sha1_read(); | 863 | string hRet = h.sha1_read(); |
860 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 864 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
861 | return e_writeFile; | 865 | return e_writeFile; |
862 | break; | 866 | break; |
863 | } | 867 | } |
864 | #ifndef PWM_EMBEDDED | 868 | #ifndef PWM_EMBEDDED |
865 | case PWM_HASH_SHA256: | 869 | case PWM_HASH_SHA256: |
866 | /*... fall through */ | 870 | /*... fall through */ |
867 | case PWM_HASH_SHA384: | 871 | case PWM_HASH_SHA384: |
868 | case PWM_HASH_SHA512: | 872 | case PWM_HASH_SHA512: |
869 | case PWM_HASH_MD5: | 873 | case PWM_HASH_MD5: |
870 | case PWM_HASH_RMD160: | 874 | case PWM_HASH_RMD160: |
871 | case PWM_HASH_TIGER: { | 875 | case PWM_HASH_TIGER: { |
872 | if (!LibGCryptIf::available()) | 876 | if (!LibGCryptIf::available()) |
873 | return e_hashNotImpl; | 877 | return e_hashNotImpl; |
874 | LibGCryptIf gc; | 878 | LibGCryptIf gc; |
875 | PwMerror err; | 879 | PwMerror err; |
876 | unsigned char *buf; | 880 | unsigned char *buf; |
877 | size_t hashLen; | 881 | size_t hashLen; |
878 | err = gc.hash(&buf, | 882 | err = gc.hash(&buf, |
879 | &hashLen, | 883 | &hashLen, |
880 | reinterpret_cast<const unsigned char *>(d->c_str()), | 884 | reinterpret_cast<const unsigned char *>(d->c_str()), |
881 | d->size(), | 885 | d->size(), |
882 | dataHash); | 886 | dataHash); |
883 | if (err != e_success) | 887 | if (err != e_success) |
884 | return e_hashNotImpl; | 888 | return e_hashNotImpl; |
885 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 889 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
886 | != static_cast<Q_LONG>(hashLen)) { | 890 | != static_cast<Q_LONG>(hashLen)) { |
887 | delete [] buf; | 891 | delete [] buf; |
888 | return e_hashNotImpl; | 892 | return e_hashNotImpl; |
889 | } | 893 | } |
890 | delete [] buf; | 894 | delete [] buf; |
891 | break; | 895 | break; |
892 | } | 896 | } |
893 | #endif | 897 | #endif |
894 | default: { | 898 | default: { |
895 | return e_hashNotImpl; | 899 | return e_hashNotImpl; |
896 | } } | 900 | } } |
897 | 901 | ||
898 | return e_success; | 902 | return e_success; |
899 | } | 903 | } |
900 | 904 | ||
901 | bool PwMDoc::backupFile(const QString &filePath) | 905 | bool PwMDoc::backupFile(const QString &filePath) |
902 | { | 906 | { |
903 | QFileInfo fi(filePath); | 907 | QFileInfo fi(filePath); |
904 | if (!fi.exists()) | 908 | if (!fi.exists()) |
905 | return true; // Yes, true is correct. | 909 | return true; // Yes, true is correct. |
906 | QString pathOnly(fi.dirPath(true)); | 910 | QString pathOnly(fi.dirPath(true)); |
907 | QString nameOnly(fi.fileName()); | 911 | QString nameOnly(fi.fileName()); |
908 | QString backupPath = pathOnly | 912 | QString backupPath = pathOnly |
909 | + "/~" | 913 | + "/~" |
910 | + nameOnly | 914 | + nameOnly |
911 | + ".backup"; | 915 | + ".backup"; |
912 | return copyFile(filePath, backupPath); | 916 | return copyFile(filePath, backupPath); |
913 | } | 917 | } |
914 | 918 | ||
915 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 919 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
916 | { | 920 | { |
917 | QFileInfo fi(src); | 921 | QFileInfo fi(src); |
918 | if (!fi.exists()) | 922 | if (!fi.exists()) |
919 | return false; | 923 | return false; |
920 | if (QFile::exists(dst)) { | 924 | if (QFile::exists(dst)) { |
921 | if (!QFile::remove(dst)) | 925 | if (!QFile::remove(dst)) |
922 | return false; | 926 | return false; |
923 | } | 927 | } |
924 | QFile srcFd(src); | 928 | QFile srcFd(src); |
925 | if (!srcFd.open(IO_ReadOnly)) | 929 | if (!srcFd.open(IO_ReadOnly)) |
926 | return false; | 930 | return false; |
927 | QFile dstFd(dst); | 931 | QFile dstFd(dst); |
928 | if (!dstFd.open(IO_ReadWrite)) { | 932 | if (!dstFd.open(IO_ReadWrite)) { |
929 | srcFd.close(); | 933 | srcFd.close(); |
930 | return false; | 934 | return false; |
931 | } | 935 | } |
932 | const int tmpBuf_size = 512; | 936 | const int tmpBuf_size = 512; |
933 | char tmpBuf[tmpBuf_size]; | 937 | char tmpBuf[tmpBuf_size]; |
934 | #ifndef PWM_EMBEDDED | 938 | #ifndef PWM_EMBEDDED |
935 | Q_LONG bytesRead, bytesWritten; | 939 | Q_LONG bytesRead, bytesWritten; |
936 | #else | 940 | #else |
937 | long bytesRead, bytesWritten; | 941 | long bytesRead, bytesWritten; |
938 | #endif | 942 | #endif |
939 | while (!srcFd.atEnd()) { | 943 | while (!srcFd.atEnd()) { |
940 | #ifndef PWM_EMBEDDED | 944 | #ifndef PWM_EMBEDDED |
941 | bytesRead = srcFd.readBlock(tmpBuf, | 945 | bytesRead = srcFd.readBlock(tmpBuf, |
942 | static_cast<Q_ULONG>(tmpBuf_size)); | 946 | static_cast<Q_ULONG>(tmpBuf_size)); |
943 | #else | 947 | #else |
944 | bytesRead = srcFd.readBlock(tmpBuf, | 948 | bytesRead = srcFd.readBlock(tmpBuf, |
945 | (unsigned long)(tmpBuf_size)); | 949 | (unsigned long)(tmpBuf_size)); |
946 | #endif | 950 | #endif |
947 | if (bytesRead == -1) { | 951 | if (bytesRead == -1) { |
948 | srcFd.close(); | 952 | srcFd.close(); |
949 | dstFd.close(); | 953 | dstFd.close(); |
950 | return false; | 954 | return false; |
951 | } | 955 | } |
952 | #ifndef PWM_EMBEDDED | 956 | #ifndef PWM_EMBEDDED |
953 | bytesWritten = dstFd.writeBlock(tmpBuf, | 957 | bytesWritten = dstFd.writeBlock(tmpBuf, |
954 | static_cast<Q_ULONG>(bytesRead)); | 958 | static_cast<Q_ULONG>(bytesRead)); |
955 | #else | 959 | #else |
956 | bytesWritten = dstFd.writeBlock(tmpBuf, | 960 | bytesWritten = dstFd.writeBlock(tmpBuf, |
957 | (unsigned long)(bytesRead)); | 961 | (unsigned long)(bytesRead)); |
958 | #endif | 962 | #endif |
959 | if (bytesWritten != bytesRead) { | 963 | if (bytesWritten != bytesRead) { |
960 | srcFd.close(); | 964 | srcFd.close(); |
961 | dstFd.close(); | 965 | dstFd.close(); |
962 | return false; | 966 | return false; |
963 | } | 967 | } |
964 | } | 968 | } |
965 | srcFd.close(); | 969 | srcFd.close(); |
966 | dstFd.close(); | 970 | dstFd.close(); |
967 | return true; | 971 | return true; |
968 | } | 972 | } |
969 | 973 | ||
970 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 974 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
971 | bool dontFlagDirty, bool updateMeta) | 975 | bool dontFlagDirty, bool updateMeta) |
972 | { | 976 | { |
973 | PWM_ASSERT(d); | 977 | PWM_ASSERT(d); |
974 | unsigned int cat = 0; | 978 | unsigned int cat = 0; |
975 | 979 | ||
976 | if (isDeepLocked()) { | 980 | if (isDeepLocked()) { |
977 | PwMerror ret; | 981 | PwMerror ret; |
978 | ret = deepLock(false); | 982 | ret = deepLock(false); |
979 | if (ret != e_success) | 983 | if (ret != e_success) |
980 | return e_lock; | 984 | return e_lock; |
981 | } | 985 | } |
982 | 986 | ||
983 | addCategory(category, &cat); | 987 | addCategory(category, &cat); |
984 | 988 | ||
985 | if (numEntries(category) >= maxEntries) | 989 | if (numEntries(category) >= maxEntries) |
986 | return e_maxAllowedEntr; | 990 | return e_maxAllowedEntr; |
987 | 991 | ||
988 | vector<unsigned int> foundPositions; | 992 | vector<unsigned int> foundPositions; |
989 | /* historically this was: | 993 | /* historically this was: |
990 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 994 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
991 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 995 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
992 | * But for now we only search in desc. | 996 | * But for now we only search in desc. |
993 | * That's a tweak to be KWallet compatible. But it should not add | 997 | * That's a tweak to be KWallet compatible. But it should not add |
994 | * usability-drop onto PwManager, does it? | 998 | * usability-drop onto PwManager, does it? |
995 | * (And yes, "int" was a bug. Correct is "unsigned int") | 999 | * (And yes, "int" was a bug. Correct is "unsigned int") |
996 | */ | 1000 | */ |
997 | const unsigned int searchIn = SEARCH_IN_DESC; | 1001 | const unsigned int searchIn = SEARCH_IN_DESC; |
998 | findEntry(cat, *d, searchIn, &foundPositions, true); | 1002 | findEntry(cat, *d, searchIn, &foundPositions, true); |
999 | if (foundPositions.size()) { | 1003 | if (foundPositions.size()) { |
1000 | // DOH! We found this entry. | 1004 | // DOH! We found this entry. |
1001 | return e_entryExists; | 1005 | return e_entryExists; |
1002 | } | 1006 | } |
1003 | 1007 | ||
1004 | d->listViewPos = -1; | 1008 | d->listViewPos = -1; |
1005 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1009 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1006 | if (updateMeta) { | 1010 | if (updateMeta) { |
1007 | d->meta.create = QDateTime::currentDateTime(); | 1011 | d->meta.create = QDateTime::currentDateTime(); |
1008 | d->meta.update = d->meta.create; | 1012 | d->meta.update = d->meta.create; |
1009 | } | 1013 | } |
1010 | dta[cat].d.push_back(*d); | 1014 | dti.dta[cat].d.push_back(*d); |
1011 | 1015 | ||
1012 | delAllEmptyCat(true); | 1016 | delAllEmptyCat(true); |
1013 | 1017 | ||
1014 | if (!dontFlagDirty) | 1018 | if (!dontFlagDirty) |
1015 | flagDirty(); | 1019 | flagDirty(); |
1016 | return e_success; | 1020 | return e_success; |
1017 | } | 1021 | } |
1018 | 1022 | ||
1019 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1023 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1020 | bool checkIfExist) | 1024 | bool checkIfExist) |
1021 | { | 1025 | { |
1022 | if (isDeepLocked()) { | 1026 | if (isDeepLocked()) { |
1023 | PwMerror ret; | 1027 | PwMerror ret; |
1024 | ret = deepLock(false); | 1028 | ret = deepLock(false); |
1025 | if (ret != e_success) | 1029 | if (ret != e_success) |
1026 | return e_lock; | 1030 | return e_lock; |
1027 | } | 1031 | } |
1028 | if (checkIfExist) { | 1032 | if (checkIfExist) { |
1029 | if (findCategory(category, categoryIndex)) | 1033 | if (findCategory(category, categoryIndex)) |
1030 | return e_categoryExists; | 1034 | return e_categoryExists; |
1031 | } | 1035 | } |
1032 | PwMCategoryItem item; | 1036 | PwMCategoryItem item; |
1033 | item.name = category.latin1(); | 1037 | item.name = category.latin1(); |
1034 | dta.push_back(item); | 1038 | dti.dta.push_back(item); |
1035 | if (categoryIndex) | 1039 | if (categoryIndex) |
1036 | *categoryIndex = dta.size() - 1; | 1040 | *categoryIndex = dti.dta.size() - 1; |
1037 | return e_success; | 1041 | return e_success; |
1038 | } | 1042 | } |
1039 | 1043 | ||
1040 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1044 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1041 | { | 1045 | { |
1042 | unsigned int cat = 0; | 1046 | unsigned int cat = 0; |
1043 | 1047 | ||
1044 | if (!findCategory(category, &cat)) { | 1048 | if (!findCategory(category, &cat)) { |
1045 | BUG(); | 1049 | BUG(); |
1046 | return false; | 1050 | return false; |
1047 | } | 1051 | } |
1048 | 1052 | ||
1049 | return delEntry(cat, index, dontFlagDirty); | 1053 | return delEntry(cat, index, dontFlagDirty); |
1050 | } | 1054 | } |
1051 | 1055 | ||
1052 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1056 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1053 | { | 1057 | { |
1054 | if (isDeepLocked()) | 1058 | if (isDeepLocked()) |
1055 | return false; | 1059 | return false; |
1056 | if (index > dta[category].d.size() - 1) | 1060 | if (index > dti.dta[category].d.size() - 1) |
1057 | return false; | 1061 | return false; |
1058 | getDataChangedLock(); | 1062 | getDataChangedLock(); |
1059 | if (!lockAt(category, index, false)) { | 1063 | if (!lockAt(category, index, false)) { |
1060 | putDataChangedLock(); | 1064 | putDataChangedLock(); |
1061 | return false; | 1065 | return false; |
1062 | } | 1066 | } |
1063 | putDataChangedLock(); | 1067 | putDataChangedLock(); |
1064 | int lvPos = dta[category].d[index].listViewPos; | 1068 | int lvPos = dti.dta[category].d[index].listViewPos; |
1065 | 1069 | ||
1066 | // delete entry | 1070 | // delete entry |
1067 | dta[category].d.erase(dta[category].d.begin() + index); | 1071 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1068 | 1072 | ||
1069 | unsigned int i, entries = numEntries(category); | 1073 | unsigned int i, entries = numEntries(category); |
1070 | if (!entries) { | 1074 | if (!entries) { |
1071 | // no more entries in this category, so | 1075 | // no more entries in this category, so |
1072 | // we can delete it, too. | 1076 | // we can delete it, too. |
1073 | BUG_ON(!delCategory(category)); | 1077 | BUG_ON(!delCategory(category)); |
1074 | // delCategory() flags it dirty, so we need not to do so. | 1078 | // delCategory() flags it dirty, so we need not to do so. |
1075 | return true; | 1079 | return true; |
1076 | } | 1080 | } |
1077 | for (i = 0; i < entries; ++i) { | 1081 | for (i = 0; i < entries; ++i) { |
1078 | // decrement all listViewPositions that are greater than the deleted. | 1082 | // decrement all listViewPositions that are greater than the deleted. |
1079 | if (dta[category].d[i].listViewPos > lvPos) | 1083 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1080 | --dta[category].d[i].listViewPos; | 1084 | --dti.dta[category].d[i].listViewPos; |
1081 | } | 1085 | } |
1082 | 1086 | ||
1083 | if (!dontFlagDirty) | 1087 | if (!dontFlagDirty) |
1084 | flagDirty(); | 1088 | flagDirty(); |
1085 | return true; | 1089 | return true; |
1086 | } | 1090 | } |
1087 | 1091 | ||
1088 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1092 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1089 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1093 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1090 | { | 1094 | { |
1091 | PWM_ASSERT(d); | 1095 | PWM_ASSERT(d); |
1092 | unsigned int oldCat = 0; | 1096 | unsigned int oldCat = 0; |
1093 | 1097 | ||
1094 | if (!findCategory(oldCategory, &oldCat)) { | 1098 | if (!findCategory(oldCategory, &oldCat)) { |
1095 | BUG(); | 1099 | BUG(); |
1096 | return false; | 1100 | return false; |
1097 | } | 1101 | } |
1098 | 1102 | ||
1099 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1103 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1100 | } | 1104 | } |
1101 | 1105 | ||
1102 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1106 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1103 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1107 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1104 | { | 1108 | { |
1105 | if (isDeepLocked()) | 1109 | if (isDeepLocked()) |
1106 | return false; | 1110 | return false; |
1107 | if (updateMeta) { | 1111 | if (updateMeta) { |
1108 | d->meta.update = QDateTime::currentDateTime(); | 1112 | d->meta.update = QDateTime::currentDateTime(); |
1109 | if (d->meta.create.isNull()) { | 1113 | if (d->meta.create.isNull()) { |
1110 | d->meta.create = d->meta.update; | 1114 | d->meta.create = d->meta.update; |
1111 | } | 1115 | } |
1112 | } | 1116 | } |
1113 | if (dta[oldCategory].name != newCategory.latin1()) { | 1117 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1114 | // the user changed the category. | 1118 | // the user changed the category. |
1115 | PwMerror ret; | 1119 | PwMerror ret; |
1116 | d->rev = 0; | 1120 | d->rev = 0; |
1117 | ret = addEntry(newCategory, d, true, false); | 1121 | ret = addEntry(newCategory, d, true, false); |
1118 | if (ret != e_success) | 1122 | if (ret != e_success) |
1119 | return false; | 1123 | return false; |
1120 | if (!delEntry(oldCategory, index, true)) | 1124 | if (!delEntry(oldCategory, index, true)) |
1121 | return false; | 1125 | return false; |
1122 | } else { | 1126 | } else { |
1123 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1127 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1124 | dta[oldCategory].d[index] = *d; | 1128 | dti.dta[oldCategory].d[index] = *d; |
1125 | } | 1129 | } |
1126 | flagDirty(); | 1130 | flagDirty(); |
1127 | return true; | 1131 | return true; |
1128 | } | 1132 | } |
1129 | 1133 | ||
1130 | unsigned int PwMDoc::numEntries(const QString &category) | 1134 | unsigned int PwMDoc::numEntries(const QString &category) |
1131 | { | 1135 | { |
1132 | unsigned int cat = 0; | 1136 | unsigned int cat = 0; |
1133 | 1137 | ||
1134 | if (!findCategory(category, &cat)) { | 1138 | if (!findCategory(category, &cat)) { |
1135 | BUG(); | 1139 | BUG(); |
1136 | return 0; | 1140 | return 0; |
1137 | } | 1141 | } |
1138 | 1142 | ||
1139 | return numEntries(cat); | 1143 | return numEntries(cat); |
1140 | } | 1144 | } |
1141 | 1145 | ||
1142 | bool PwMDoc::serializeDta(string *d) | 1146 | bool PwMDoc::serializeDta(string *d) |
1143 | { | 1147 | { |
1144 | PWM_ASSERT(d); | 1148 | PWM_ASSERT(d); |
1145 | Serializer ser; | 1149 | Serializer ser; |
1146 | if (!ser.serialize(dta)) | 1150 | if (!ser.serialize(dti)) |
1147 | return false; | 1151 | return false; |
1148 | d->assign(ser.getXml()); | 1152 | d->assign(ser.getXml()); |
1149 | if (!d->size()) | 1153 | if (!d->size()) |
1150 | return false; | 1154 | return false; |
1151 | return true; | 1155 | return true; |
1152 | } | 1156 | } |
1153 | 1157 | ||
1154 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1158 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1155 | { | 1159 | { |
1156 | PWM_ASSERT(d); | 1160 | PWM_ASSERT(d); |
1157 | #ifndef PWM_EMBEDDED | 1161 | #ifndef PWM_EMBEDDED |
1158 | try { | 1162 | try { |
1159 | 1163 | ||
1160 | Serializer ser(d->c_str()); | 1164 | Serializer ser(d->c_str()); |
1161 | ser.setDefaultLockStat(entriesLocked); | 1165 | ser.setDefaultLockStat(entriesLocked); |
1162 | if (!ser.deSerialize(&dta)) | 1166 | if (!ser.deSerialize(&dti)) |
1163 | return false; | 1167 | return false; |
1164 | } catch (PwMException) { | 1168 | } catch (PwMException) { |
1165 | return false; | 1169 | return false; |
1166 | } | 1170 | } |
1167 | #else | 1171 | #else |
1168 | Serializer ser(d->c_str()); | 1172 | Serializer ser(d->c_str()); |
1169 | ser.setDefaultLockStat(entriesLocked); | 1173 | ser.setDefaultLockStat(entriesLocked); |
1170 | if (!ser.deSerialize(&dta)) | 1174 | if (!ser.deSerialize(&dti)) |
1171 | return false; | 1175 | return false; |
1172 | #endif | 1176 | #endif |
1173 | 1177 | ||
1174 | emitDataChanged(this); | 1178 | emitDataChanged(this); |
1175 | return true; | 1179 | return true; |
1176 | } | 1180 | } |
1177 | 1181 | ||
1178 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1182 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1179 | PwMDataItem * d, bool unlockIfLocked) | 1183 | PwMDataItem * d, bool unlockIfLocked) |
1180 | { | 1184 | { |
1181 | PWM_ASSERT(d); | 1185 | PWM_ASSERT(d); |
1182 | unsigned int cat = 0; | 1186 | unsigned int cat = 0; |
1183 | 1187 | ||
1184 | if (!findCategory(category, &cat)) { | 1188 | if (!findCategory(category, &cat)) { |
1185 | BUG(); | 1189 | BUG(); |
1186 | return false; | 1190 | return false; |
1187 | } | 1191 | } |
1188 | 1192 | ||
1189 | return getEntry(cat, index, d, unlockIfLocked); | 1193 | return getEntry(cat, index, d, unlockIfLocked); |
1190 | } | 1194 | } |
1191 | 1195 | ||
1192 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1196 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1193 | PwMDataItem *d, bool unlockIfLocked) | 1197 | PwMDataItem *d, bool unlockIfLocked) |
1194 | { | 1198 | { |
1195 | if (index > dta[category].d.size() - 1) | 1199 | if (index > dti.dta[category].d.size() - 1) |
1196 | return false; | 1200 | return false; |
1197 | 1201 | ||
1198 | bool locked = isLocked(category, index); | 1202 | bool locked = isLocked(category, index); |
1199 | if (locked) { | 1203 | if (locked) { |
1200 | /* this entry is locked. We don't return a password, | 1204 | /* this entry is locked. We don't return a password, |
1201 | * until it's unlocked by the user by inserting | 1205 | * until it's unlocked by the user by inserting |
1202 | * chipcard or entering the mpw | 1206 | * chipcard or entering the mpw |
1203 | */ | 1207 | */ |
1204 | if (unlockIfLocked) { | 1208 | if (unlockIfLocked) { |
1205 | if (!lockAt(category, index, false)) { | 1209 | if (!lockAt(category, index, false)) { |
1206 | return false; | 1210 | return false; |
1207 | } | 1211 | } |
1208 | locked = false; | 1212 | locked = false; |
1209 | } | 1213 | } |
1210 | } | 1214 | } |
1211 | 1215 | ||
1212 | *d = dta[category].d[index]; | 1216 | *d = dti.dta[category].d[index]; |
1213 | if (locked) | 1217 | if (locked) |
1214 | d->pw = LOCKED_STRING.latin1(); | 1218 | d->pw = LOCKED_STRING.latin1(); |
1215 | 1219 | ||
1216 | return true; | 1220 | return true; |
1217 | } | 1221 | } |
1218 | 1222 | ||
1219 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1223 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1220 | string *foundComment) | 1224 | string *foundComment) |
1221 | { | 1225 | { |
1222 | PWM_ASSERT(foundComment); | 1226 | PWM_ASSERT(foundComment); |
1223 | unsigned int cat = 0; | 1227 | unsigned int cat = 0; |
1224 | 1228 | ||
1225 | if (!findCategory(category, &cat)) | 1229 | if (!findCategory(category, &cat)) |
1226 | return e_invalidArg; | 1230 | return e_invalidArg; |
1227 | 1231 | ||
1228 | unsigned int i, entries = numEntries(cat); | 1232 | unsigned int i, entries = numEntries(cat); |
1229 | for (i = 0; i < entries; ++i) { | 1233 | for (i = 0; i < entries; ++i) { |
1230 | if (dta[cat].d[i].listViewPos == listViewPos) { | 1234 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1231 | *foundComment = dta[cat].d[i].comment; | 1235 | *foundComment = dti.dta[cat].d[i].comment; |
1232 | if (dta[cat].d[i].binary) | 1236 | if (dti.dta[cat].d[i].binary) |
1233 | return e_binEntry; | 1237 | return e_binEntry; |
1234 | return e_normalEntry; | 1238 | return e_normalEntry; |
1235 | } | 1239 | } |
1236 | } | 1240 | } |
1237 | BUG(); | 1241 | BUG(); |
1238 | return e_generic; | 1242 | return e_generic; |
1239 | } | 1243 | } |
1240 | 1244 | ||
1241 | bool PwMDoc::compressDta(string *d, char algo) | 1245 | bool PwMDoc::compressDta(string *d, char algo) |
1242 | { | 1246 | { |
1243 | PWM_ASSERT(d); | 1247 | PWM_ASSERT(d); |
1244 | switch (algo) { | 1248 | switch (algo) { |
1245 | case PWM_COMPRESS_GZIP: { | 1249 | case PWM_COMPRESS_GZIP: { |
1246 | CompressGzip comp; | 1250 | CompressGzip comp; |
1247 | return comp.compress(d); | 1251 | return comp.compress(d); |
1248 | } case PWM_COMPRESS_BZIP2: { | 1252 | } case PWM_COMPRESS_BZIP2: { |
1249 | CompressBzip2 comp; | 1253 | CompressBzip2 comp; |
1250 | return comp.compress(d); | 1254 | return comp.compress(d); |
1251 | } case PWM_COMPRESS_NONE: { | 1255 | } case PWM_COMPRESS_NONE: { |
1252 | return true; | 1256 | return true; |
1253 | } default: { | 1257 | } default: { |
1254 | BUG(); | 1258 | BUG(); |
1255 | } | 1259 | } |
1256 | } | 1260 | } |
1257 | return false; | 1261 | return false; |
1258 | } | 1262 | } |
1259 | 1263 | ||
1260 | bool PwMDoc::decompressDta(string *d, char algo) | 1264 | bool PwMDoc::decompressDta(string *d, char algo) |
1261 | { | 1265 | { |
1262 | PWM_ASSERT(d); | 1266 | PWM_ASSERT(d); |
1263 | switch (algo) { | 1267 | switch (algo) { |
1264 | case PWM_COMPRESS_GZIP: { | 1268 | case PWM_COMPRESS_GZIP: { |
1265 | CompressGzip comp; | 1269 | CompressGzip comp; |
1266 | return comp.decompress(d); | 1270 | return comp.decompress(d); |
1267 | } case PWM_COMPRESS_BZIP2: { | 1271 | } case PWM_COMPRESS_BZIP2: { |
1268 | CompressBzip2 comp; | 1272 | CompressBzip2 comp; |
1269 | return comp.decompress(d); | 1273 | return comp.decompress(d); |
1270 | } case PWM_COMPRESS_NONE: { | 1274 | } case PWM_COMPRESS_NONE: { |
1271 | return true; | 1275 | return true; |
1272 | } | 1276 | } |
1273 | } | 1277 | } |
1274 | return false; | 1278 | return false; |
1275 | } | 1279 | } |
1276 | 1280 | ||
1277 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1281 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1278 | { | 1282 | { |
1279 | PWM_ASSERT(d); | 1283 | PWM_ASSERT(d); |
1280 | PWM_ASSERT(pw); | 1284 | PWM_ASSERT(pw); |
1281 | PWM_ASSERT(f); | 1285 | PWM_ASSERT(f); |
1282 | 1286 | ||
1283 | size_t encSize; | 1287 | size_t encSize; |
1284 | byte *encrypted = 0; | 1288 | byte *encrypted = 0; |
1285 | 1289 | ||
1286 | switch (algo) { | 1290 | switch (algo) { |
1287 | case PWM_CRYPT_BLOWFISH: { | 1291 | case PWM_CRYPT_BLOWFISH: { |
1288 | Blowfish::padNull(d); | 1292 | Blowfish::padNull(d); |
1289 | encSize = d->length(); | 1293 | encSize = d->length(); |
1290 | encrypted = new byte[encSize]; | 1294 | encrypted = new byte[encSize]; |
1291 | Blowfish bf; | 1295 | Blowfish bf; |
1292 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1296 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1293 | delete [] encrypted; | 1297 | delete [] encrypted; |
1294 | return e_weakPw; | 1298 | return e_weakPw; |
1295 | } | 1299 | } |
1296 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1300 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1297 | break; | 1301 | break; |
1298 | } | 1302 | } |
1299 | #ifndef PWM_EMBEDDED | 1303 | #ifndef PWM_EMBEDDED |
1300 | case PWM_CRYPT_AES128: | 1304 | case PWM_CRYPT_AES128: |
1301 | /*... fall through */ | 1305 | /*... fall through */ |
1302 | case PWM_CRYPT_AES192: | 1306 | case PWM_CRYPT_AES192: |
1303 | case PWM_CRYPT_AES256: | 1307 | case PWM_CRYPT_AES256: |
1304 | case PWM_CRYPT_3DES: | 1308 | case PWM_CRYPT_3DES: |
1305 | case PWM_CRYPT_TWOFISH: | 1309 | case PWM_CRYPT_TWOFISH: |
1306 | case PWM_CRYPT_TWOFISH128: { | 1310 | case PWM_CRYPT_TWOFISH128: { |
1307 | if (!LibGCryptIf::available()) | 1311 | if (!LibGCryptIf::available()) |
1308 | return e_cryptNotImpl; | 1312 | return e_cryptNotImpl; |
1309 | LibGCryptIf gc; | 1313 | LibGCryptIf gc; |
1310 | PwMerror err; | 1314 | PwMerror err; |
1311 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1315 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1312 | memcpy(plain, d->c_str(), d->length()); | 1316 | memcpy(plain, d->c_str(), d->length()); |
1313 | err = gc.encrypt(&encrypted, | 1317 | err = gc.encrypt(&encrypted, |
1314 | &encSize, | 1318 | &encSize, |
1315 | plain, | 1319 | plain, |
1316 | d->length(), | 1320 | d->length(), |
1317 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1321 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1318 | pw->length(), | 1322 | pw->length(), |
1319 | algo); | 1323 | algo); |
1320 | delete [] plain; | 1324 | delete [] plain; |
1321 | if (err != e_success) | 1325 | if (err != e_success) |
1322 | return e_cryptNotImpl; | 1326 | return e_cryptNotImpl; |
1323 | break; | 1327 | break; |
1324 | } | 1328 | } |
1325 | #endif | 1329 | #endif |
1326 | default: { | 1330 | default: { |
1327 | delete_ifnot_null_array(encrypted); | 1331 | delete_ifnot_null_array(encrypted); |
1328 | return e_cryptNotImpl; | 1332 | return e_cryptNotImpl; |
1329 | } } | 1333 | } } |
1330 | 1334 | ||
1331 | // write encrypted data to file | 1335 | // write encrypted data to file |
1332 | #ifndef PWM_EMBEDDED | 1336 | #ifndef PWM_EMBEDDED |
1333 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1337 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1334 | static_cast<Q_ULONG>(encSize)) | 1338 | static_cast<Q_ULONG>(encSize)) |
1335 | != static_cast<Q_LONG>(encSize)) { | 1339 | != static_cast<Q_LONG>(encSize)) { |
1336 | delete_ifnot_null_array(encrypted); | 1340 | delete_ifnot_null_array(encrypted); |
1337 | return e_writeFile; | 1341 | return e_writeFile; |
1338 | } | 1342 | } |
1339 | #else | 1343 | #else |
1340 | if (f->writeBlock((const char *)(encrypted), | 1344 | if (f->writeBlock((const char *)(encrypted), |
1341 | (unsigned long)(encSize)) | 1345 | (unsigned long)(encSize)) |
1342 | != (long)(encSize)) { | 1346 | != (long)(encSize)) { |
1343 | delete_ifnot_null_array(encrypted); | 1347 | delete_ifnot_null_array(encrypted); |
1344 | return e_writeFile; | 1348 | return e_writeFile; |
1345 | } | 1349 | } |
1346 | #endif | 1350 | #endif |
1347 | delete_ifnot_null_array(encrypted); | 1351 | delete_ifnot_null_array(encrypted); |
1348 | return e_success; | 1352 | return e_success; |
1349 | } | 1353 | } |
1350 | 1354 | ||
1351 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1355 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1352 | char algo, QFile *f) | 1356 | char algo, QFile *f) |
1353 | { | 1357 | { |
1354 | PWM_ASSERT(d); | 1358 | PWM_ASSERT(d); |
1355 | PWM_ASSERT(pw); | 1359 | PWM_ASSERT(pw); |
1356 | PWM_ASSERT(f); | 1360 | PWM_ASSERT(f); |
1357 | 1361 | ||
1358 | unsigned int cryptLen = f->size() - pos; | 1362 | unsigned int cryptLen = f->size() - pos; |
1359 | byte *encrypted = new byte[cryptLen]; | 1363 | byte *encrypted = new byte[cryptLen]; |
1360 | byte *decrypted = new byte[cryptLen]; | 1364 | byte *decrypted = new byte[cryptLen]; |
1361 | 1365 | ||
1362 | f->at(pos); | 1366 | f->at(pos); |
1363 | #ifndef PWM_EMBEDDED | 1367 | #ifndef PWM_EMBEDDED |
1364 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1368 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1365 | static_cast<Q_ULONG>(cryptLen)) | 1369 | static_cast<Q_ULONG>(cryptLen)) |
1366 | != static_cast<Q_LONG>(cryptLen)) { | 1370 | != static_cast<Q_LONG>(cryptLen)) { |
1367 | delete [] encrypted; | 1371 | delete [] encrypted; |
1368 | delete [] decrypted; | 1372 | delete [] decrypted; |
1369 | return e_readFile; | 1373 | return e_readFile; |
1370 | } | 1374 | } |
1371 | #else | 1375 | #else |
1372 | if (f->readBlock((char *)(encrypted), | 1376 | if (f->readBlock((char *)(encrypted), |
1373 | (unsigned long)(cryptLen)) | 1377 | (unsigned long)(cryptLen)) |
1374 | != (long)(cryptLen)) { | 1378 | != (long)(cryptLen)) { |
1375 | delete [] encrypted; | 1379 | delete [] encrypted; |
1376 | delete [] decrypted; | 1380 | delete [] decrypted; |
1377 | return e_readFile; | 1381 | return e_readFile; |
1378 | } | 1382 | } |
1379 | #endif | 1383 | #endif |
1380 | switch (algo) { | 1384 | switch (algo) { |
1381 | case PWM_CRYPT_BLOWFISH: { | 1385 | case PWM_CRYPT_BLOWFISH: { |
1382 | Blowfish bf; | 1386 | Blowfish bf; |
1383 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1387 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1384 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1388 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1385 | break; | 1389 | break; |
1386 | } | 1390 | } |
1387 | #ifndef PWM_EMBEDDED | 1391 | #ifndef PWM_EMBEDDED |
1388 | case PWM_CRYPT_AES128: | 1392 | case PWM_CRYPT_AES128: |
1389 | /*... fall through */ | 1393 | /*... fall through */ |
1390 | case PWM_CRYPT_AES192: | 1394 | case PWM_CRYPT_AES192: |
1391 | case PWM_CRYPT_AES256: | 1395 | case PWM_CRYPT_AES256: |
1392 | case PWM_CRYPT_3DES: | 1396 | case PWM_CRYPT_3DES: |
1393 | case PWM_CRYPT_TWOFISH: | 1397 | case PWM_CRYPT_TWOFISH: |
1394 | case PWM_CRYPT_TWOFISH128: { | 1398 | case PWM_CRYPT_TWOFISH128: { |
1395 | if (!LibGCryptIf::available()) | 1399 | if (!LibGCryptIf::available()) |
1396 | return e_cryptNotImpl; | 1400 | return e_cryptNotImpl; |
1397 | LibGCryptIf gc; | 1401 | LibGCryptIf gc; |
1398 | PwMerror err; | 1402 | PwMerror err; |
1399 | err = gc.decrypt(&decrypted, | 1403 | err = gc.decrypt(&decrypted, |
1400 | &cryptLen, | 1404 | &cryptLen, |
1401 | encrypted, | 1405 | encrypted, |
1402 | cryptLen, | 1406 | cryptLen, |
1403 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1407 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1404 | pw->length(), | 1408 | pw->length(), |
1405 | algo); | 1409 | algo); |
1406 | if (err != e_success) { | 1410 | if (err != e_success) { |
1407 | delete [] encrypted; | 1411 | delete [] encrypted; |
1408 | delete [] decrypted; | 1412 | delete [] decrypted; |
1409 | return e_cryptNotImpl; | 1413 | return e_cryptNotImpl; |
1410 | } | 1414 | } |
1411 | break; | 1415 | break; |
1412 | } | 1416 | } |
1413 | #endif | 1417 | #endif |
1414 | default: { | 1418 | default: { |
1415 | delete [] encrypted; | 1419 | delete [] encrypted; |
1416 | delete [] decrypted; | 1420 | delete [] decrypted; |
1417 | return e_cryptNotImpl; | 1421 | return e_cryptNotImpl; |
1418 | } } | 1422 | } } |
1419 | delete [] encrypted; | 1423 | delete [] encrypted; |
1420 | #ifndef PWM_EMBEDDED | 1424 | #ifndef PWM_EMBEDDED |
1421 | d->assign(reinterpret_cast<const char *>(decrypted), | 1425 | d->assign(reinterpret_cast<const char *>(decrypted), |
1422 | static_cast<string::size_type>(cryptLen)); | 1426 | static_cast<string::size_type>(cryptLen)); |
1423 | #else | 1427 | #else |
1424 | d->assign((const char *)(decrypted), | 1428 | d->assign((const char *)(decrypted), |
1425 | (string::size_type)(cryptLen)); | 1429 | (string::size_type)(cryptLen)); |
1426 | #endif | 1430 | #endif |
1427 | delete [] decrypted; | 1431 | delete [] decrypted; |
1428 | if (algo == PWM_CRYPT_BLOWFISH) { | 1432 | if (algo == PWM_CRYPT_BLOWFISH) { |
1429 | if (!Blowfish::unpadNull(d)) { | 1433 | if (!Blowfish::unpadNull(d)) { |
1430 | BUG(); | 1434 | BUG(); |
1431 | return e_readFile; | 1435 | return e_readFile; |
1432 | } | 1436 | } |
1433 | } | 1437 | } |
1434 | return e_success; | 1438 | return e_success; |
1435 | } | 1439 | } |
1436 | 1440 | ||
1437 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1441 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1438 | const string *dataStream) | 1442 | const string *dataStream) |
1439 | { | 1443 | { |
1440 | PWM_ASSERT(dataHash); | 1444 | PWM_ASSERT(dataHash); |
1441 | PWM_ASSERT(dataStream); | 1445 | PWM_ASSERT(dataStream); |
1442 | switch(dataHashType) { | 1446 | switch(dataHashType) { |
1443 | case PWM_HASH_SHA1: { | 1447 | case PWM_HASH_SHA1: { |
1444 | Sha1 hash; | 1448 | Sha1 hash; |
1445 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1449 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1446 | string ret = hash.sha1_read(); | 1450 | string ret = hash.sha1_read(); |
1447 | if (ret != *dataHash) | 1451 | if (ret != *dataHash) |
1448 | return e_fileCorrupt; | 1452 | return e_fileCorrupt; |
1449 | break; | 1453 | break; |
1450 | } | 1454 | } |
1451 | #ifndef PWM_EMBEDDED | 1455 | #ifndef PWM_EMBEDDED |
1452 | case PWM_HASH_SHA256: | 1456 | case PWM_HASH_SHA256: |
1453 | /*... fall through */ | 1457 | /*... fall through */ |
1454 | case PWM_HASH_SHA384: | 1458 | case PWM_HASH_SHA384: |
1455 | case PWM_HASH_SHA512: | 1459 | case PWM_HASH_SHA512: |
1456 | case PWM_HASH_MD5: | 1460 | case PWM_HASH_MD5: |
1457 | case PWM_HASH_RMD160: | 1461 | case PWM_HASH_RMD160: |
1458 | case PWM_HASH_TIGER: { | 1462 | case PWM_HASH_TIGER: { |
1459 | if (!LibGCryptIf::available()) | 1463 | if (!LibGCryptIf::available()) |
1460 | return e_hashNotImpl; | 1464 | return e_hashNotImpl; |
1461 | LibGCryptIf gc; | 1465 | LibGCryptIf gc; |
1462 | PwMerror err; | 1466 | PwMerror err; |
1463 | unsigned char *buf; | 1467 | unsigned char *buf; |
1464 | size_t hashLen; | 1468 | size_t hashLen; |
1465 | err = gc.hash(&buf, | 1469 | err = gc.hash(&buf, |
1466 | &hashLen, | 1470 | &hashLen, |
1467 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1471 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1468 | dataStream->length(), | 1472 | dataStream->length(), |
1469 | dataHashType); | 1473 | dataHashType); |
1470 | if (err != e_success) | 1474 | if (err != e_success) |
1471 | return e_hashNotImpl; | 1475 | return e_hashNotImpl; |
1472 | string calcHash(reinterpret_cast<const char *>(buf), | 1476 | string calcHash(reinterpret_cast<const char *>(buf), |
1473 | static_cast<string::size_type>(hashLen)); | 1477 | static_cast<string::size_type>(hashLen)); |
1474 | delete [] buf; | 1478 | delete [] buf; |
1475 | if (calcHash != *dataHash) | 1479 | if (calcHash != *dataHash) |
1476 | return e_fileCorrupt; | 1480 | return e_fileCorrupt; |
1477 | break; | 1481 | break; |
1478 | } | 1482 | } |
1479 | #endif | 1483 | #endif |
1480 | default: | 1484 | default: |
1481 | return e_hashNotImpl; | 1485 | return e_hashNotImpl; |
1482 | } | 1486 | } |
1483 | return e_success; | 1487 | return e_success; |
1484 | } | 1488 | } |
1485 | 1489 | ||
1486 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1490 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1487 | bool lock) | 1491 | bool lock) |
1488 | { | 1492 | { |
1489 | if (index >= numEntries(category)) { | 1493 | if (index >= numEntries(category)) { |
1490 | BUG(); | 1494 | BUG(); |
1491 | return false; | 1495 | return false; |
1492 | } | 1496 | } |
1493 | if (lock == dta[category].d[index].lockStat) | 1497 | if (lock == dti.dta[category].d[index].lockStat) |
1494 | return true; | 1498 | return true; |
1495 | 1499 | ||
1496 | if (!lock && currentPw != "") { | 1500 | if (!lock && currentPw != "") { |
1497 | // "unlocking" and "password is already set" | 1501 | // "unlocking" and "password is already set" |
1498 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1502 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1499 | // unlocking without pw not allowed | 1503 | // unlocking without pw not allowed |
1500 | QString pw; | 1504 | QString pw; |
1501 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1505 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1502 | if (pw != "") { | 1506 | if (pw != "") { |
1503 | if (pw != currentPw) { | 1507 | if (pw != currentPw) { |
1504 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1508 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1505 | return false; | 1509 | return false; |
1506 | } else { | 1510 | } else { |
1507 | timer()->start(DocTimer::id_mpwTimer); | 1511 | timer()->start(DocTimer::id_mpwTimer); |
1508 | } | 1512 | } |
1509 | } else { | 1513 | } else { |
1510 | return false; | 1514 | return false; |
1511 | } | 1515 | } |
1512 | } else { | 1516 | } else { |
1513 | timer()->start(DocTimer::id_mpwTimer); | 1517 | timer()->start(DocTimer::id_mpwTimer); |
1514 | } | 1518 | } |
1515 | } | 1519 | } |
1516 | 1520 | ||
1517 | dta[category].d[index].lockStat = lock; | 1521 | dti.dta[category].d[index].lockStat = lock; |
1518 | dta[category].d[index].rev++; // increment revision counter. | 1522 | dti.dta[category].d[index].rev++; // increment revision counter. |
1519 | 1523 | ||
1520 | emitDataChanged(this); | 1524 | emitDataChanged(this); |
1521 | if (!lock) | 1525 | if (!lock) |
1522 | timer()->start(DocTimer::id_autoLockTimer); | 1526 | timer()->start(DocTimer::id_autoLockTimer); |
1523 | 1527 | ||
1524 | return true; | 1528 | return true; |
1525 | 1529 | ||
1526 | } | 1530 | } |
1527 | 1531 | ||
1528 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1532 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1529 | bool lock) | 1533 | bool lock) |
1530 | { | 1534 | { |
1531 | unsigned int cat = 0; | 1535 | unsigned int cat = 0; |
1532 | 1536 | ||
1533 | if (!findCategory(category, &cat)) { | 1537 | if (!findCategory(category, &cat)) { |
1534 | BUG(); | 1538 | BUG(); |
1535 | return false; | 1539 | return false; |
1536 | } | 1540 | } |
1537 | 1541 | ||
1538 | return lockAt(cat, index, lock); | 1542 | return lockAt(cat, index, lock); |
1539 | } | 1543 | } |
1540 | 1544 | ||
1541 | bool PwMDoc::lockAll(bool lock) | 1545 | bool PwMDoc::lockAll(bool lock) |
1542 | { | 1546 | { |
1543 | if (!lock && isDeepLocked()) { | 1547 | if (!lock && isDeepLocked()) { |
1544 | PwMerror ret; | 1548 | PwMerror ret; |
1545 | ret = deepLock(false); | 1549 | ret = deepLock(false); |
1546 | if (ret != e_success) | 1550 | if (ret != e_success) |
1547 | return false; | 1551 | return false; |
1548 | return true; | 1552 | return true; |
1549 | } | 1553 | } |
1550 | if (isDocEmpty()) { | 1554 | if (isDocEmpty()) { |
1551 | return true; | 1555 | return true; |
1552 | } | 1556 | } |
1553 | if (!lock && currentPw != "") { | 1557 | if (!lock && currentPw != "") { |
1554 | // unlocking and password is already set | 1558 | // unlocking and password is already set |
1555 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1559 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1556 | // unlocking without pw not allowed | 1560 | // unlocking without pw not allowed |
1557 | QString pw; | 1561 | QString pw; |
1558 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1562 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1559 | if (pw != "") { | 1563 | if (pw != "") { |
1560 | if (pw != currentPw) { | 1564 | if (pw != currentPw) { |
1561 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1565 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1562 | return false; | 1566 | return false; |
1563 | } else { | 1567 | } else { |
1564 | timer()->start(DocTimer::id_mpwTimer); | 1568 | timer()->start(DocTimer::id_mpwTimer); |
1565 | } | 1569 | } |
1566 | } else { | 1570 | } else { |
1567 | return false; | 1571 | return false; |
1568 | } | 1572 | } |
1569 | } else { | 1573 | } else { |
1570 | timer()->start(DocTimer::id_mpwTimer); | 1574 | timer()->start(DocTimer::id_mpwTimer); |
1571 | } | 1575 | } |
1572 | } | 1576 | } |
1573 | 1577 | ||
1574 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1578 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1575 | catEnd = dta.end(), | 1579 | catEnd = dti.dta.end(), |
1576 | catI = catBegin; | 1580 | catI = catBegin; |
1577 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1581 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1578 | while (catI != catEnd) { | 1582 | while (catI != catEnd) { |
1579 | entrBegin = catI->d.begin(); | 1583 | entrBegin = catI->d.begin(); |
1580 | entrEnd = catI->d.end(); | 1584 | entrEnd = catI->d.end(); |
1581 | entrI = entrBegin; | 1585 | entrI = entrBegin; |
1582 | while (entrI != entrEnd) { | 1586 | while (entrI != entrEnd) { |
1583 | entrI->lockStat = lock; | 1587 | entrI->lockStat = lock; |
1584 | entrI->rev++; // increment revision counter. | 1588 | entrI->rev++; // increment revision counter. |
1585 | ++entrI; | 1589 | ++entrI; |
1586 | } | 1590 | } |
1587 | ++catI; | 1591 | ++catI; |
1588 | } | 1592 | } |
1589 | 1593 | ||
1590 | emitDataChanged(this); | 1594 | emitDataChanged(this); |
1591 | if (lock) | 1595 | if (lock) |
1592 | timer()->stop(DocTimer::id_autoLockTimer); | 1596 | timer()->stop(DocTimer::id_autoLockTimer); |
1593 | else | 1597 | else |
1594 | timer()->start(DocTimer::id_autoLockTimer); | 1598 | timer()->start(DocTimer::id_autoLockTimer); |
1595 | 1599 | ||
1596 | return true; | 1600 | return true; |
1597 | } | 1601 | } |
1598 | 1602 | ||
1599 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1603 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1600 | { | 1604 | { |
1601 | unsigned int cat = 0; | 1605 | unsigned int cat = 0; |
1602 | 1606 | ||
1603 | if (!findCategory(category, &cat)) { | 1607 | if (!findCategory(category, &cat)) { |
1604 | BUG(); | 1608 | BUG(); |
1605 | return false; | 1609 | return false; |
1606 | } | 1610 | } |
1607 | 1611 | ||
1608 | return isLocked(cat, index); | 1612 | return isLocked(cat, index); |
1609 | } | 1613 | } |
1610 | 1614 | ||
1611 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1615 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1612 | { | 1616 | { |
1613 | static vector< vector<bool> > *oldLockStates = 0; | 1617 | static vector< vector<bool> > *oldLockStates = 0; |
1614 | static bool wasDeepLocked; | 1618 | static bool wasDeepLocked; |
1615 | 1619 | ||
1616 | if (revert) {// revert the unlocking | 1620 | if (revert) {// revert the unlocking |
1617 | if (oldLockStates) { | 1621 | if (oldLockStates) { |
1618 | /* we actually _have_ unlocked something, because | 1622 | /* we actually _have_ unlocked something, because |
1619 | * we have allocated space for the oldLockStates. | 1623 | * we have allocated space for the oldLockStates. |
1620 | * So, go on and revert them! | 1624 | * So, go on and revert them! |
1621 | */ | 1625 | */ |
1622 | if (wasDeepLocked) { | 1626 | if (wasDeepLocked) { |
1623 | PwMerror ret = deepLock(true); | 1627 | PwMerror ret = deepLock(true); |
1624 | if (ret == e_success) { | 1628 | if (ret == e_success) { |
1625 | /* deep-lock succeed. We are save. | 1629 | /* deep-lock succeed. We are save. |
1626 | * (but if it failed, just go on | 1630 | * (but if it failed, just go on |
1627 | * lock them normally) | 1631 | * lock them normally) |
1628 | */ | 1632 | */ |
1629 | delete_and_null(oldLockStates); | 1633 | delete_and_null(oldLockStates); |
1630 | timer()->start(DocTimer::id_autoLockTimer); | 1634 | timer()->start(DocTimer::id_autoLockTimer); |
1631 | printDebug("tempoary unlocking of dta " | 1635 | printDebug("tempoary unlocking of dta " |
1632 | "reverted by deep-locking."); | 1636 | "reverted by deep-locking."); |
1633 | return true; | 1637 | return true; |
1634 | } | 1638 | } |
1635 | printDebug("deep-lock failed while reverting! " | 1639 | printDebug("deep-lock failed while reverting! " |
1636 | "Falling back to normal-lock."); | 1640 | "Falling back to normal-lock."); |
1637 | } | 1641 | } |
1638 | if (unlikely(!wasDeepLocked && | 1642 | if (unlikely(!wasDeepLocked && |
1639 | numCategories() != oldLockStates->size())) { | 1643 | numCategories() != oldLockStates->size())) { |
1640 | /* DOH! We have modified "dta" while | 1644 | /* DOH! We have modified "dta" while |
1641 | * it was unlocked tempoary. DON'T DO THIS! | 1645 | * it was unlocked tempoary. DON'T DO THIS! |
1642 | */ | 1646 | */ |
1643 | BUG(); | 1647 | BUG(); |
1644 | delete_and_null(oldLockStates); | 1648 | delete_and_null(oldLockStates); |
1645 | timer()->start(DocTimer::id_autoLockTimer); | 1649 | timer()->start(DocTimer::id_autoLockTimer); |
1646 | return false; | 1650 | return false; |
1647 | } | 1651 | } |
1648 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1652 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1649 | catEnd = dta.end(), | 1653 | catEnd = dti.dta.end(), |
1650 | catI = catBegin; | 1654 | catI = catBegin; |
1651 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1655 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1652 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1656 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1653 | vector<bool>::iterator oldEntrStatBegin, | 1657 | vector<bool>::iterator oldEntrStatBegin, |
1654 | oldEntrStatEnd, | 1658 | oldEntrStatEnd, |
1655 | oldEntrStatI; | 1659 | oldEntrStatI; |
1656 | while (catI != catEnd) { | 1660 | while (catI != catEnd) { |
1657 | entrBegin = catI->d.begin(); | 1661 | entrBegin = catI->d.begin(); |
1658 | entrEnd = catI->d.end(); | 1662 | entrEnd = catI->d.end(); |
1659 | entrI = entrBegin; | 1663 | entrI = entrBegin; |
1660 | if (likely(!wasDeepLocked)) { | 1664 | if (likely(!wasDeepLocked)) { |
1661 | oldEntrStatBegin = oldCatStatI->begin(); | 1665 | oldEntrStatBegin = oldCatStatI->begin(); |
1662 | oldEntrStatEnd = oldCatStatI->end(); | 1666 | oldEntrStatEnd = oldCatStatI->end(); |
1663 | oldEntrStatI = oldEntrStatBegin; | 1667 | oldEntrStatI = oldEntrStatBegin; |
1664 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1668 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1665 | /* DOH! We have modified "dta" while | 1669 | /* DOH! We have modified "dta" while |
1666 | * it was unlocked tempoary. DON'T DO THIS! | 1670 | * it was unlocked tempoary. DON'T DO THIS! |
1667 | */ | 1671 | */ |
1668 | BUG(); | 1672 | BUG(); |
1669 | delete_and_null(oldLockStates); | 1673 | delete_and_null(oldLockStates); |
1670 | timer()->start(DocTimer::id_autoLockTimer); | 1674 | timer()->start(DocTimer::id_autoLockTimer); |
1671 | return false; | 1675 | return false; |
1672 | } | 1676 | } |
1673 | } | 1677 | } |
1674 | while (entrI != entrEnd) { | 1678 | while (entrI != entrEnd) { |
1675 | if (wasDeepLocked) { | 1679 | if (wasDeepLocked) { |
1676 | /* this is an error-fallback if | 1680 | /* this is an error-fallback if |
1677 | * deeplock didn't succeed | 1681 | * deeplock didn't succeed |
1678 | */ | 1682 | */ |
1679 | entrI->lockStat = true; | 1683 | entrI->lockStat = true; |
1680 | } else { | 1684 | } else { |
1681 | entrI->lockStat = *oldEntrStatI; | 1685 | entrI->lockStat = *oldEntrStatI; |
1682 | } | 1686 | } |
1683 | ++entrI; | 1687 | ++entrI; |
1684 | if (likely(!wasDeepLocked)) | 1688 | if (likely(!wasDeepLocked)) |
1685 | ++oldEntrStatI; | 1689 | ++oldEntrStatI; |
1686 | } | 1690 | } |
1687 | ++catI; | 1691 | ++catI; |
1688 | if (likely(!wasDeepLocked)) | 1692 | if (likely(!wasDeepLocked)) |
1689 | ++oldCatStatI; | 1693 | ++oldCatStatI; |
1690 | } | 1694 | } |
1691 | delete_and_null(oldLockStates); | 1695 | delete_and_null(oldLockStates); |
1692 | if (unlikely(wasDeepLocked)) { | 1696 | if (unlikely(wasDeepLocked)) { |
1693 | /* error fallback... */ | 1697 | /* error fallback... */ |
1694 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1698 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1695 | emitDataChanged(this); | 1699 | emitDataChanged(this); |
1696 | printDebug("WARNING: unlockAll_tempoary(true) " | 1700 | printDebug("WARNING: unlockAll_tempoary(true) " |
1697 | "deeplock fallback!"); | 1701 | "deeplock fallback!"); |
1698 | } | 1702 | } |
1699 | printDebug("tempoary unlocking of dta reverted."); | 1703 | printDebug("tempoary unlocking of dta reverted."); |
1700 | } else { | 1704 | } else { |
1701 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1705 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1702 | } | 1706 | } |
1703 | timer()->start(DocTimer::id_autoLockTimer); | 1707 | timer()->start(DocTimer::id_autoLockTimer); |
1704 | } else {// unlock all data tempoary | 1708 | } else {// unlock all data tempoary |
1705 | if (unlikely(oldLockStates != 0)) { | 1709 | if (unlikely(oldLockStates != 0)) { |
1706 | /* DOH! We have already unlocked the data tempoarly. | 1710 | /* DOH! We have already unlocked the data tempoarly. |
1707 | * No need to do it twice. ;) | 1711 | * No need to do it twice. ;) |
1708 | */ | 1712 | */ |
1709 | BUG(); | 1713 | BUG(); |
1710 | return false; | 1714 | return false; |
1711 | } | 1715 | } |
1712 | wasDeepLocked = false; | 1716 | wasDeepLocked = false; |
1713 | bool mustUnlock = false; | 1717 | bool mustUnlock = false; |
1714 | if (isDeepLocked()) { | 1718 | if (isDeepLocked()) { |
1715 | PwMerror ret; | 1719 | PwMerror ret; |
1716 | while (1) { | 1720 | while (1) { |
1717 | ret = deepLock(false); | 1721 | ret = deepLock(false); |
1718 | if (ret == e_success) { | 1722 | if (ret == e_success) { |
1719 | break; | 1723 | break; |
1720 | } else if (ret == e_wrongPw) { | 1724 | } else if (ret == e_wrongPw) { |
1721 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1725 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1722 | } else { | 1726 | } else { |
1723 | printDebug("deep-unlocking failed while " | 1727 | printDebug("deep-unlocking failed while " |
1724 | "tempoary unlocking!"); | 1728 | "tempoary unlocking!"); |
1725 | return false; | 1729 | return false; |
1726 | } | 1730 | } |
1727 | } | 1731 | } |
1728 | wasDeepLocked = true; | 1732 | wasDeepLocked = true; |
1729 | mustUnlock = true; | 1733 | mustUnlock = true; |
1730 | } else { | 1734 | } else { |
1731 | // first check if it's needed to unlock some entries | 1735 | // first check if it's needed to unlock some entries |
1732 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1736 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1733 | catEnd = dta.end(), | 1737 | catEnd = dti.dta.end(), |
1734 | catI = catBegin; | 1738 | catI = catBegin; |
1735 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1739 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1736 | while (catI != catEnd) { | 1740 | while (catI != catEnd) { |
1737 | entrBegin = catI->d.begin(); | 1741 | entrBegin = catI->d.begin(); |
1738 | entrEnd = catI->d.end(); | 1742 | entrEnd = catI->d.end(); |
1739 | entrI = entrBegin; | 1743 | entrI = entrBegin; |
1740 | while (entrI != entrEnd) { | 1744 | while (entrI != entrEnd) { |
1741 | if (entrI->lockStat == true) { | 1745 | if (entrI->lockStat == true) { |
1742 | mustUnlock = true; | 1746 | mustUnlock = true; |
1743 | break; | 1747 | break; |
1744 | } | 1748 | } |
1745 | ++entrI; | 1749 | ++entrI; |
1746 | } | 1750 | } |
1747 | if (mustUnlock) | 1751 | if (mustUnlock) |
1748 | break; | 1752 | break; |
1749 | ++catI; | 1753 | ++catI; |
1750 | } | 1754 | } |
1751 | } | 1755 | } |
1752 | if (!mustUnlock) { | 1756 | if (!mustUnlock) { |
1753 | // nothing to do. | 1757 | // nothing to do. |
1754 | timer()->stop(DocTimer::id_autoLockTimer); | 1758 | timer()->stop(DocTimer::id_autoLockTimer); |
1755 | printDebug("unlockAll_tempoary(): nothing to do."); | 1759 | printDebug("unlockAll_tempoary(): nothing to do."); |
1756 | return true; | 1760 | return true; |
1757 | } else if (!wasDeepLocked) { | 1761 | } else if (!wasDeepLocked) { |
1758 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1762 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1759 | currentPw != "") { | 1763 | currentPw != "") { |
1760 | /* we can't unlock without mpw, so | 1764 | /* we can't unlock without mpw, so |
1761 | * we need to ask for it. | 1765 | * we need to ask for it. |
1762 | */ | 1766 | */ |
1763 | QString pw; | 1767 | QString pw; |
1764 | while (1) { | 1768 | while (1) { |
1765 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1769 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1766 | if (pw == "") { | 1770 | if (pw == "") { |
1767 | return false; | 1771 | return false; |
1768 | } else if (pw == currentPw) { | 1772 | } else if (pw == currentPw) { |
1769 | break; | 1773 | break; |
1770 | } | 1774 | } |
1771 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1775 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1772 | } | 1776 | } |
1773 | } | 1777 | } |
1774 | } | 1778 | } |
1775 | timer()->stop(DocTimer::id_autoLockTimer); | 1779 | timer()->stop(DocTimer::id_autoLockTimer); |
1776 | oldLockStates = new vector< vector<bool> >; | 1780 | oldLockStates = new vector< vector<bool> >; |
1777 | vector<bool> tmp_vec; | 1781 | vector<bool> tmp_vec; |
1778 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1782 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1779 | catEnd = dta.end(), | 1783 | catEnd = dti.dta.end(), |
1780 | catI = catBegin; | 1784 | catI = catBegin; |
1781 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1785 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1782 | while (catI != catEnd) { | 1786 | while (catI != catEnd) { |
1783 | entrBegin = catI->d.begin(); | 1787 | entrBegin = catI->d.begin(); |
1784 | entrEnd = catI->d.end(); | 1788 | entrEnd = catI->d.end(); |
1785 | entrI = entrBegin; | 1789 | entrI = entrBegin; |
1786 | while (entrI != entrEnd) { | 1790 | while (entrI != entrEnd) { |
1787 | if (!wasDeepLocked) { | 1791 | if (!wasDeepLocked) { |
1788 | tmp_vec.push_back(entrI->lockStat); | 1792 | tmp_vec.push_back(entrI->lockStat); |
1789 | } | 1793 | } |
1790 | entrI->lockStat = false; | 1794 | entrI->lockStat = false; |
1791 | ++entrI; | 1795 | ++entrI; |
1792 | } | 1796 | } |
1793 | if (!wasDeepLocked) { | 1797 | if (!wasDeepLocked) { |
1794 | oldLockStates->push_back(tmp_vec); | 1798 | oldLockStates->push_back(tmp_vec); |
1795 | tmp_vec.clear(); | 1799 | tmp_vec.clear(); |
1796 | } | 1800 | } |
1797 | ++catI; | 1801 | ++catI; |
1798 | } | 1802 | } |
1799 | printDebug("tempoary unlocked dta."); | 1803 | printDebug("tempoary unlocked dta."); |
1800 | } | 1804 | } |
1801 | 1805 | ||
1802 | return true; | 1806 | return true; |
1803 | } | 1807 | } |
1804 | 1808 | ||
1805 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1809 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1806 | { | 1810 | { |
1807 | PwMerror ret; | 1811 | PwMerror ret; |
1808 | 1812 | ||
1809 | if (lock) { | 1813 | if (lock) { |
1810 | if (isDeepLocked()) | 1814 | if (isDeepLocked()) |
1811 | return e_lock; | 1815 | return e_lock; |
1812 | if (saveToFile) { | 1816 | if (saveToFile) { |
1813 | if (isDocEmpty()) | 1817 | if (isDocEmpty()) |
1814 | return e_docIsEmpty; | 1818 | return e_docIsEmpty; |
1815 | ret = saveDoc(conf()->confGlobCompression()); | 1819 | ret = saveDoc(conf()->confGlobCompression()); |
1816 | if (ret == e_filename) { | 1820 | if (ret == e_filename) { |
1817 | /* the doc wasn't saved to a file | 1821 | /* the doc wasn't saved to a file |
1818 | * by the user, yet. | 1822 | * by the user, yet. |
1819 | */ | 1823 | */ |
1820 | cantDeeplock_notSavedMsgBox(); | 1824 | cantDeeplock_notSavedMsgBox(); |
1821 | return e_docNotSaved; | 1825 | return e_docNotSaved; |
1822 | } else if (ret != e_success) { | 1826 | } else if (ret != e_success) { |
1823 | return e_lock; | 1827 | return e_lock; |
1824 | } | 1828 | } |
1825 | } | 1829 | } |
1826 | timer()->stop(DocTimer::id_autoLockTimer); | 1830 | timer()->stop(DocTimer::id_autoLockTimer); |
1827 | clearDoc(); | 1831 | clearDoc(); |
1828 | PwMDataItem d; | 1832 | PwMDataItem d; |
1829 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1833 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1830 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1834 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1831 | d.listViewPos = 0; | 1835 | d.listViewPos = 0; |
1832 | addEntry(DEFAULT_CATEGORY, &d, true); | 1836 | addEntry(DEFAULT_CATEGORY, &d, true); |
1833 | lockAt(DEFAULT_CATEGORY, 0, true); | 1837 | lockAt(DEFAULT_CATEGORY, 0, true); |
1834 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1838 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1835 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1839 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1836 | } else { | 1840 | } else { |
1837 | if (!isDeepLocked()) | 1841 | if (!isDeepLocked()) |
1838 | return e_lock; | 1842 | return e_lock; |
1839 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1843 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1840 | ? 0 : 1); | 1844 | ? 0 : 1); |
1841 | if (ret == e_wrongPw) { | 1845 | if (ret == e_wrongPw) { |
1842 | return e_wrongPw; | 1846 | return e_wrongPw; |
1843 | } else if (ret != e_success) { | 1847 | } else if (ret != e_success) { |
1844 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1848 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1845 | + tostr(static_cast<int>(ret))); | 1849 | + tostr(static_cast<int>(ret))); |
1846 | return e_lock; | 1850 | return e_lock; |
1847 | } | 1851 | } |
1848 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1852 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1849 | timer()->start(DocTimer::id_autoLockTimer); | 1853 | timer()->start(DocTimer::id_autoLockTimer); |
1850 | } | 1854 | } |
1851 | 1855 | ||
1852 | emitDataChanged(this); | 1856 | emitDataChanged(this); |
1853 | return e_success; | 1857 | return e_success; |
1854 | } | 1858 | } |
1855 | 1859 | ||
1856 | void PwMDoc::_deepUnlock() | 1860 | void PwMDoc::_deepUnlock() |
1857 | { | 1861 | { |
1858 | deepLock(false); | 1862 | deepLock(false); |
1859 | } | 1863 | } |
1860 | 1864 | ||
1861 | void PwMDoc::clearDoc() | 1865 | void PwMDoc::clearDoc() |
1862 | { | 1866 | { |
1863 | dta.clear(); | 1867 | dti.clear(); |
1864 | PwMCategoryItem d; | 1868 | PwMCategoryItem d; |
1865 | d.name = DEFAULT_CATEGORY.latin1(); | 1869 | d.name = DEFAULT_CATEGORY.latin1(); |
1866 | dta.push_back(d); | 1870 | dti.dta.push_back(d); |
1867 | currentPw = ""; | 1871 | currentPw = ""; |
1868 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1872 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1869 | } | 1873 | } |
1870 | 1874 | ||
1871 | void PwMDoc::changeCurrentPw() | 1875 | void PwMDoc::changeCurrentPw() |
1872 | { | 1876 | { |
1873 | if (currentPw == "") | 1877 | if (currentPw == "") |
1874 | return; // doc hasn't been saved. No mpw available. | 1878 | return; // doc hasn't been saved. No mpw available. |
1875 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1879 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1876 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1880 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1877 | if (pw == "") | 1881 | if (pw == "") |
1878 | return; | 1882 | return; |
1879 | if (useChipcard) | 1883 | if (useChipcard) |
1880 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1884 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1881 | else | 1885 | else |
1882 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1886 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1883 | setCurrentPw(pw); | 1887 | setCurrentPw(pw); |
1884 | } | 1888 | } |
1885 | 1889 | ||
1886 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1890 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1887 | int pos) | 1891 | int pos) |
1888 | { | 1892 | { |
1889 | unsigned int cat = 0; | 1893 | unsigned int cat = 0; |
1890 | 1894 | ||
1891 | if (!findCategory(category, &cat)) { | 1895 | if (!findCategory(category, &cat)) { |
1892 | BUG(); | 1896 | BUG(); |
1893 | return; | 1897 | return; |
1894 | } | 1898 | } |
1895 | setListViewPos(cat, index, pos); | 1899 | setListViewPos(cat, index, pos); |
1896 | } | 1900 | } |
1897 | 1901 | ||
1898 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1902 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1899 | int pos) | 1903 | int pos) |
1900 | { | 1904 | { |
1901 | dta[category].d[index].listViewPos = pos; | 1905 | dti.dta[category].d[index].listViewPos = pos; |
1902 | 1906 | ||
1903 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1907 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1904 | * get's called when it shouldn't. It's because PwMView assumes | 1908 | * get's called when it shouldn't. It's because PwMView assumes |
1905 | * the user resorted the UI on behalf of signal layoutChanged(). | 1909 | * the user resorted the UI on behalf of signal layoutChanged(). |
1906 | * This is somewhat broken and incorrect, but I've no other | 1910 | * This is somewhat broken and incorrect, but I've no other |
1907 | * solution for now. | 1911 | * solution for now. |
1908 | */ | 1912 | */ |
1909 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1913 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1910 | } | 1914 | } |
1911 | 1915 | ||
1912 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1916 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1913 | { | 1917 | { |
1914 | unsigned int cat = 0; | 1918 | unsigned int cat = 0; |
1915 | 1919 | ||
1916 | if (!findCategory(category, &cat)) { | 1920 | if (!findCategory(category, &cat)) { |
1917 | BUG(); | 1921 | BUG(); |
1918 | return -1; | 1922 | return -1; |
1919 | } | 1923 | } |
1920 | 1924 | ||
1921 | return dta[cat].d[index].listViewPos; | 1925 | return dti.dta[cat].d[index].listViewPos; |
1922 | } | 1926 | } |
1923 | 1927 | ||
1924 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1928 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1925 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1929 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1926 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1930 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1927 | { | 1931 | { |
1928 | PWM_ASSERT(foundPositions); | 1932 | PWM_ASSERT(foundPositions); |
1929 | PWM_ASSERT(searchIn); | 1933 | PWM_ASSERT(searchIn); |
1930 | foundPositions->clear(); | 1934 | foundPositions->clear(); |
1931 | 1935 | ||
1932 | unsigned int i, entries = numEntries(category); | 1936 | unsigned int i, entries = numEntries(category); |
1933 | for (i = 0; i < entries; ++i) { | 1937 | for (i = 0; i < entries; ++i) { |
1934 | if (searchIn & SEARCH_IN_DESC) { | 1938 | if (searchIn & SEARCH_IN_DESC) { |
1935 | if (!compareString(find.desc, dta[category].d[i].desc, | 1939 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1936 | caseSensitive, exactWordMatch)) { | 1940 | caseSensitive, exactWordMatch)) { |
1937 | continue; | 1941 | continue; |
1938 | } | 1942 | } |
1939 | } | 1943 | } |
1940 | if (searchIn & SEARCH_IN_NAME) { | 1944 | if (searchIn & SEARCH_IN_NAME) { |
1941 | if (!compareString(find.name, dta[category].d[i].name, | 1945 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1942 | caseSensitive, exactWordMatch)) { | 1946 | caseSensitive, exactWordMatch)) { |
1943 | continue; | 1947 | continue; |
1944 | } | 1948 | } |
1945 | } | 1949 | } |
1946 | if (searchIn & SEARCH_IN_PW) { | 1950 | if (searchIn & SEARCH_IN_PW) { |
1947 | bool wasLocked = isLocked(category, i); | 1951 | bool wasLocked = isLocked(category, i); |
1948 | getDataChangedLock(); | 1952 | getDataChangedLock(); |
1949 | lockAt(category, i, false); | 1953 | lockAt(category, i, false); |
1950 | if (!compareString(find.pw, dta[category].d[i].pw, | 1954 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1951 | caseSensitive, exactWordMatch)) { | 1955 | caseSensitive, exactWordMatch)) { |
1952 | lockAt(category, i, wasLocked); | 1956 | lockAt(category, i, wasLocked); |
1953 | putDataChangedLock(); | 1957 | putDataChangedLock(); |
1954 | continue; | 1958 | continue; |
1955 | } | 1959 | } |
1956 | lockAt(category, i, wasLocked); | 1960 | lockAt(category, i, wasLocked); |
1957 | putDataChangedLock(); | 1961 | putDataChangedLock(); |
1958 | } | 1962 | } |
1959 | if (searchIn & SEARCH_IN_COMMENT) { | 1963 | if (searchIn & SEARCH_IN_COMMENT) { |
1960 | if (!compareString(find.comment, dta[category].d[i].comment, | 1964 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1961 | caseSensitive, exactWordMatch)) { | 1965 | caseSensitive, exactWordMatch)) { |
1962 | continue; | 1966 | continue; |
1963 | } | 1967 | } |
1964 | } | 1968 | } |
1965 | if (searchIn & SEARCH_IN_URL) { | 1969 | if (searchIn & SEARCH_IN_URL) { |
1966 | if (!compareString(find.url, dta[category].d[i].url, | 1970 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1967 | caseSensitive, exactWordMatch)) { | 1971 | caseSensitive, exactWordMatch)) { |
1968 | continue; | 1972 | continue; |
1969 | } | 1973 | } |
1970 | } | 1974 | } |
1971 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1975 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1972 | if (!compareString(find.launcher, dta[category].d[i].launcher, | 1976 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1973 | caseSensitive, exactWordMatch)) { | 1977 | caseSensitive, exactWordMatch)) { |
1974 | continue; | 1978 | continue; |
1975 | } | 1979 | } |
1976 | } | 1980 | } |
1977 | 1981 | ||
1978 | // all selected "searchIn" matched. | 1982 | // all selected "searchIn" matched. |
1979 | foundPositions->push_back(i); | 1983 | foundPositions->push_back(i); |
1980 | if (breakAfterFound) | 1984 | if (breakAfterFound) |
1981 | break; | 1985 | break; |
1982 | } | 1986 | } |
1983 | 1987 | ||
1984 | if (sortByLvp && foundPositions->size() > 1) { | 1988 | if (sortByLvp && foundPositions->size() > 1) { |
1985 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 1989 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
1986 | unsigned int /* lvp-pos */> > tmp_vec; | 1990 | unsigned int /* lvp-pos */> > tmp_vec; |
1987 | 1991 | ||
1988 | unsigned int i, items = foundPositions->size(); | 1992 | unsigned int i, items = foundPositions->size(); |
1989 | pair<unsigned int, unsigned int> tmp_pair; | 1993 | pair<unsigned int, unsigned int> tmp_pair; |
1990 | for (i = 0; i < items; ++i) { | 1994 | for (i = 0; i < items; ++i) { |
1991 | tmp_pair.first = (*foundPositions)[i]; | 1995 | tmp_pair.first = (*foundPositions)[i]; |
1992 | tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos; | 1996 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
1993 | tmp_vec.push_back(tmp_pair); | 1997 | tmp_vec.push_back(tmp_pair); |
1994 | } | 1998 | } |
1995 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 1999 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
1996 | foundPositions->clear(); | 2000 | foundPositions->clear(); |
1997 | for (i = 0; i < items; ++i) { | 2001 | for (i = 0; i < items; ++i) { |
1998 | foundPositions->push_back(tmp_vec[i].first); | 2002 | foundPositions->push_back(tmp_vec[i].first); |
1999 | } | 2003 | } |
2000 | } | 2004 | } |
2001 | } | 2005 | } |
2002 | 2006 | ||
2003 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2007 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2004 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2008 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2005 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2009 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2006 | { | 2010 | { |
2007 | PWM_ASSERT(foundPositions); | 2011 | PWM_ASSERT(foundPositions); |
2008 | unsigned int cat = 0; | 2012 | unsigned int cat = 0; |
2009 | 2013 | ||
2010 | if (!findCategory(category, &cat)) { | 2014 | if (!findCategory(category, &cat)) { |
2011 | foundPositions->clear(); | 2015 | foundPositions->clear(); |
2012 | return; | 2016 | return; |
2013 | } | 2017 | } |
2014 | 2018 | ||
2015 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2019 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2016 | caseSensitive, exactWordMatch, sortByLvp); | 2020 | caseSensitive, exactWordMatch, sortByLvp); |
2017 | } | 2021 | } |
2018 | 2022 | ||
2019 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2023 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2020 | bool exactWordMatch) | 2024 | bool exactWordMatch) |
2021 | { | 2025 | { |
2022 | QString _s1(s1.c_str()); | 2026 | QString _s1(s1.c_str()); |
2023 | QString _s2(s2.c_str()); | 2027 | QString _s2(s2.c_str()); |
2024 | if (!caseSensitive) { | 2028 | if (!caseSensitive) { |
2025 | _s1 = _s1.lower(); | 2029 | _s1 = _s1.lower(); |
2026 | _s2 = _s2.lower(); | 2030 | _s2 = _s2.lower(); |
2027 | } | 2031 | } |
2028 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2032 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2029 | return true; | 2033 | return true; |
2030 | return false; | 2034 | return false; |
2031 | } | 2035 | } |
2032 | 2036 | ||
2033 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2037 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2034 | { | 2038 | { |
2035 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2039 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2036 | end = dta.end(); | 2040 | end = dti.dta.end(); |
2037 | while (i != end) { | 2041 | while (i != end) { |
2038 | if ((*i).name == name.latin1()) { | 2042 | if ((*i).name == name.latin1()) { |
2039 | if (index) { | 2043 | if (index) { |
2040 | *index = i - dta.begin(); | 2044 | *index = i - dti.dta.begin(); |
2041 | } | 2045 | } |
2042 | return true; | 2046 | return true; |
2043 | } | 2047 | } |
2044 | ++i; | 2048 | ++i; |
2045 | } | 2049 | } |
2046 | return false; | 2050 | return false; |
2047 | } | 2051 | } |
2048 | 2052 | ||
2049 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2053 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2050 | { | 2054 | { |
2051 | unsigned int cat = 0; | 2055 | unsigned int cat = 0; |
2052 | 2056 | ||
2053 | if (!findCategory(category, &cat)) | 2057 | if (!findCategory(category, &cat)) |
2054 | return false; | 2058 | return false; |
2055 | 2059 | ||
2056 | return renameCategory(cat, newName); | 2060 | return renameCategory(cat, newName); |
2057 | } | 2061 | } |
2058 | 2062 | ||
2059 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2063 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2060 | bool dontFlagDirty) | 2064 | bool dontFlagDirty) |
2061 | { | 2065 | { |
2062 | if (category > numCategories() - 1) | 2066 | if (category > numCategories() - 1) |
2063 | return false; | 2067 | return false; |
2064 | 2068 | ||
2065 | dta[category].name = newName.latin1(); | 2069 | dti.dta[category].name = newName.latin1(); |
2066 | if (!dontFlagDirty) | 2070 | if (!dontFlagDirty) |
2067 | flagDirty(); | 2071 | flagDirty(); |
2068 | 2072 | ||
2069 | return true; | 2073 | return true; |
2070 | } | 2074 | } |
2071 | 2075 | ||
2072 | bool PwMDoc::delCategory(const QString &category) | 2076 | bool PwMDoc::delCategory(const QString &category) |
2073 | { | 2077 | { |
2074 | unsigned int cat = 0; | 2078 | unsigned int cat = 0; |
2075 | 2079 | ||
2076 | if (!findCategory(category, &cat)) | 2080 | if (!findCategory(category, &cat)) |
2077 | return false; | 2081 | return false; |
2078 | 2082 | ||
2079 | return delCategory(cat); | 2083 | return delCategory(cat); |
2080 | } | 2084 | } |
2081 | 2085 | ||
2082 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2086 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2083 | { | 2087 | { |
2084 | if (category > numCategories() - 1) | 2088 | if (category > numCategories() - 1) |
2085 | return false; | 2089 | return false; |
2086 | 2090 | ||
2087 | // We don't delete it, if it is the last existing | 2091 | // We don't delete it, if it is the last existing |
2088 | // category! Instead we rename it to "Default". | 2092 | // category! Instead we rename it to "Default". |
2089 | if (numCategories() > 1) { | 2093 | if (numCategories() > 1) { |
2090 | dta.erase(dta.begin() + category); | 2094 | dti.dta.erase(dti.dta.begin() + category); |
2091 | } else { | 2095 | } else { |
2092 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2096 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2093 | return true; | 2097 | return true; |
2094 | } | 2098 | } |
2095 | if (!dontFlagDirty) | 2099 | if (!dontFlagDirty) |
2096 | flagDirty(); | 2100 | flagDirty(); |
2097 | 2101 | ||
2098 | return true; | 2102 | return true; |
2099 | } | 2103 | } |
2100 | 2104 | ||
2101 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2105 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2102 | { | 2106 | { |
2103 | vector<PwMCategoryItem>::iterator begin = dta.begin(), | 2107 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2104 | end = dta.end(), | 2108 | end = dti.dta.end(), |
2105 | i = begin; | 2109 | i = begin; |
2106 | while (i != end) { | 2110 | while (i != end) { |
2107 | if (i->d.empty()) { | 2111 | if (i->d.empty()) { |
2108 | delCategory(begin - i, dontFlagDirty); | 2112 | delCategory(begin - i, dontFlagDirty); |
2109 | } | 2113 | } |
2110 | ++i; | 2114 | ++i; |
2111 | } | 2115 | } |
2112 | } | 2116 | } |
2113 | 2117 | ||
2114 | void PwMDoc::getCategoryList(vector<string> *list) | 2118 | void PwMDoc::getCategoryList(vector<string> *list) |
2115 | { | 2119 | { |
2116 | PWM_ASSERT(list); | 2120 | PWM_ASSERT(list); |
2117 | list->clear(); | 2121 | list->clear(); |
2118 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2122 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2119 | end = dta.end(); | 2123 | end = dti.dta.end(); |
2120 | while (i != end) { | 2124 | while (i != end) { |
2121 | list->push_back(i->name); | 2125 | list->push_back(i->name); |
2122 | ++i; | 2126 | ++i; |
2123 | } | 2127 | } |
2124 | } | 2128 | } |
2125 | 2129 | ||
2126 | void PwMDoc::getCategoryList(QStringList *list) | 2130 | void PwMDoc::getCategoryList(QStringList *list) |
2127 | { | 2131 | { |
2128 | PWM_ASSERT(list); | 2132 | PWM_ASSERT(list); |
2129 | list->clear(); | 2133 | list->clear(); |
2130 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2134 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2131 | end = dta.end(); | 2135 | end = dti.dta.end(); |
2132 | while (i != end) { | 2136 | while (i != end) { |
2133 | #ifndef PWM_EMBEDDED | 2137 | #ifndef PWM_EMBEDDED |
2134 | list->push_back(i->name.c_str()); | 2138 | list->push_back(i->name.c_str()); |
2135 | #else | 2139 | #else |
2136 | list->append(i->name.c_str()); | 2140 | list->append(i->name.c_str()); |
2137 | #endif | 2141 | #endif |
2138 | ++i; | 2142 | ++i; |
2139 | } | 2143 | } |
2140 | } | 2144 | } |
2141 | 2145 | ||
2142 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2146 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2143 | { | 2147 | { |
2144 | PWM_ASSERT(list); | 2148 | PWM_ASSERT(list); |
2145 | unsigned int cat = 0; | 2149 | unsigned int cat = 0; |
2146 | if (!findCategory(category, &cat)) { | 2150 | if (!findCategory(category, &cat)) { |
2147 | list->clear(); | 2151 | list->clear(); |
2148 | return; | 2152 | return; |
2149 | } | 2153 | } |
2150 | getEntryList(cat, list); | 2154 | getEntryList(cat, list); |
2151 | } | 2155 | } |
2152 | 2156 | ||
2153 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2157 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2154 | { | 2158 | { |
2155 | PWM_ASSERT(list); | 2159 | PWM_ASSERT(list); |
2156 | unsigned int cat = 0; | 2160 | unsigned int cat = 0; |
2157 | if (!findCategory(category, &cat)) { | 2161 | if (!findCategory(category, &cat)) { |
2158 | list->clear(); | 2162 | list->clear(); |
2159 | return; | 2163 | return; |
2160 | } | 2164 | } |
2161 | getEntryList(cat, list); | 2165 | getEntryList(cat, list); |
2162 | } | 2166 | } |
2163 | 2167 | ||
2164 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2168 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2165 | { | 2169 | { |
2166 | PWM_ASSERT(list); | 2170 | PWM_ASSERT(list); |
2167 | list->clear(); | 2171 | list->clear(); |
2168 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2172 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2169 | end = dta[category].d.end(), | 2173 | end = dti.dta[category].d.end(), |
2170 | i = begin; | 2174 | i = begin; |
2171 | while (i != end) { | 2175 | while (i != end) { |
2172 | list->push_back(i->desc); | 2176 | list->push_back(i->desc); |
2173 | ++i; | 2177 | ++i; |
2174 | } | 2178 | } |
2175 | } | 2179 | } |
2176 | 2180 | ||
2177 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2181 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2178 | { | 2182 | { |
2179 | PWM_ASSERT(list); | 2183 | PWM_ASSERT(list); |
2180 | list->clear(); | 2184 | list->clear(); |
2181 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2185 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2182 | end = dta[category].d.end(), | 2186 | end = dti.dta[category].d.end(), |
2183 | i = begin; | 2187 | i = begin; |
2184 | while (i != end) { | 2188 | while (i != end) { |
2185 | #ifndef PWM_EMBEDDED | 2189 | #ifndef PWM_EMBEDDED |
2186 | list->push_back(i->desc.c_str()); | 2190 | list->push_back(i->desc.c_str()); |
2187 | #else | 2191 | #else |
2188 | list->append(i->desc.c_str()); | 2192 | list->append(i->desc.c_str()); |
2189 | #endif | 2193 | #endif |
2190 | ++i; | 2194 | ++i; |
2191 | } | 2195 | } |
2192 | } | 2196 | } |
2193 | 2197 | ||
2194 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2198 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2195 | { | 2199 | { |
2196 | unsigned int cat = 0; | 2200 | unsigned int cat = 0; |
2197 | 2201 | ||
2198 | if (!findCategory(category, &cat)) | 2202 | if (!findCategory(category, &cat)) |
2199 | return false; | 2203 | return false; |
2200 | 2204 | ||
2201 | return execLauncher(cat, entryIndex); | 2205 | return execLauncher(cat, entryIndex); |
2202 | } | 2206 | } |
2203 | 2207 | ||
2204 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2208 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2205 | { | 2209 | { |
2206 | if (geteuid() == 0) { | 2210 | if (geteuid() == 0) { |
2207 | rootAlertMsgBox(); | 2211 | rootAlertMsgBox(); |
2208 | return false; | 2212 | return false; |
2209 | } | 2213 | } |
2210 | QString command(dta[category].d[entryIndex].launcher.c_str()); | 2214 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2211 | bool wasLocked = isLocked(category, entryIndex); | 2215 | bool wasLocked = isLocked(category, entryIndex); |
2212 | 2216 | ||
2213 | if (command.find("$p") != -1) { | 2217 | if (command.find("$p") != -1) { |
2214 | /* the user requested the password to be included | 2218 | /* the user requested the password to be included |
2215 | * into the command. We have to ask for the password, | 2219 | * into the command. We have to ask for the password, |
2216 | * if it's locked. We do that by unlocking the entry | 2220 | * if it's locked. We do that by unlocking the entry |
2217 | */ | 2221 | */ |
2218 | if (!lockAt(category, entryIndex, false)) | 2222 | if (!lockAt(category, entryIndex, false)) |
2219 | return false; | 2223 | return false; |
2220 | } | 2224 | } |
2221 | #ifndef PWM_EMBEDDED | 2225 | #ifndef PWM_EMBEDDED |
2222 | command.replace("$d", dta[category].d[entryIndex].desc.c_str()); | 2226 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2223 | command.replace("$n", dta[category].d[entryIndex].name.c_str()); | 2227 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2224 | command.replace("$p", dta[category].d[entryIndex].pw.c_str()); | 2228 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2225 | command.replace("$u", dta[category].d[entryIndex].url.c_str()); | 2229 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2226 | command.replace("$c", dta[category].d[entryIndex].comment.c_str()); | 2230 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2227 | #else | 2231 | #else |
2228 | command.replace(QRegExp("$d"), dta[category].d[entryIndex].desc.c_str()); | 2232 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2229 | command.replace(QRegExp("$n"), dta[category].d[entryIndex].name.c_str()); | 2233 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2230 | command.replace(QRegExp("$p"), dta[category].d[entryIndex].pw.c_str()); | 2234 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2231 | command.replace(QRegExp("$u"), dta[category].d[entryIndex].url.c_str()); | 2235 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2232 | command.replace(QRegExp("$c"), dta[category].d[entryIndex].comment.c_str()); | 2236 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2233 | #endif | 2237 | #endif |
2234 | command.append(" &"); | 2238 | command.append(" &"); |
2235 | 2239 | ||
2236 | QString customXterm(conf()->confGlobXtermCommand()); | 2240 | QString customXterm(conf()->confGlobXtermCommand()); |
2237 | if (!customXterm.isEmpty()) | 2241 | if (!customXterm.isEmpty()) |
2238 | command = customXterm + " " + command; | 2242 | command = customXterm + " " + command; |
2239 | 2243 | ||
2240 | system(command.latin1()); | 2244 | system(command.latin1()); |
2241 | 2245 | ||
2242 | lockAt(category, entryIndex, wasLocked); | 2246 | lockAt(category, entryIndex, wasLocked); |
2243 | return true; | 2247 | return true; |
2244 | } | 2248 | } |
2245 | 2249 | ||
2246 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2250 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
2247 | { | 2251 | { |
2248 | unsigned int cat = 0; | 2252 | unsigned int cat = 0; |
2249 | 2253 | ||
2250 | if (!findCategory(category, &cat)) | 2254 | if (!findCategory(category, &cat)) |
2251 | return false; | 2255 | return false; |
2252 | 2256 | ||
2253 | return goToURL(cat, entryIndex); | 2257 | return goToURL(cat, entryIndex); |
2254 | } | 2258 | } |
2255 | 2259 | ||
2256 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) | 2260 | bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex) |
2257 | { | 2261 | { |
2258 | if (geteuid() == 0) { | 2262 | if (geteuid() == 0) { |
2259 | rootAlertMsgBox(); | 2263 | rootAlertMsgBox(); |
2260 | return false; | 2264 | return false; |
2261 | } | 2265 | } |
2262 | QString url(dta[category].d[entryIndex].url.c_str()); | 2266 | QString url(dti.dta[category].d[entryIndex].url.c_str()); |
2263 | if (url.isEmpty()) | 2267 | if (url.isEmpty()) |
2264 | return false; | 2268 | return false; |
2265 | 2269 | ||
2266 | QString customBrowser(conf()->confGlobBrowserCommand()); | 2270 | QString customBrowser(conf()->confGlobBrowserCommand()); |
2267 | if (!customBrowser.isEmpty()) { | 2271 | if (!customBrowser.isEmpty()) { |
2268 | browserProc.clearArguments(); | 2272 | browserProc.clearArguments(); |
2269 | browserProc << customBrowser << url; | 2273 | browserProc << customBrowser << url; |
2270 | if (browserProc.start(KProcess::DontCare)) | 2274 | if (browserProc.start(KProcess::DontCare)) |
2271 | return true; | 2275 | return true; |
2272 | } | 2276 | } |
2273 | 2277 | ||
2274 | browserProc.clearArguments(); | 2278 | browserProc.clearArguments(); |
2275 | browserProc << "konqueror" << url; | 2279 | browserProc << "konqueror" << url; |
2276 | if (browserProc.start(KProcess::DontCare)) | 2280 | if (browserProc.start(KProcess::DontCare)) |
2277 | return true; | 2281 | return true; |
2278 | 2282 | ||
2279 | browserProc.clearArguments(); | 2283 | browserProc.clearArguments(); |
2280 | browserProc << "mozilla" << url; | 2284 | browserProc << "mozilla" << url; |
2281 | if (browserProc.start(KProcess::DontCare)) | 2285 | if (browserProc.start(KProcess::DontCare)) |
2282 | return true; | 2286 | return true; |
2283 | 2287 | ||
2284 | browserProc.clearArguments(); | 2288 | browserProc.clearArguments(); |
2285 | browserProc << "opera" << url; | 2289 | browserProc << "opera" << url; |
2286 | if (browserProc.start(KProcess::DontCare)) | 2290 | if (browserProc.start(KProcess::DontCare)) |
2287 | return true; | 2291 | return true; |
2288 | return false; | 2292 | return false; |
2289 | } | 2293 | } |
2290 | 2294 | ||
2291 | PwMerror PwMDoc::exportToText(const QString *file) | 2295 | PwMerror PwMDoc::exportToText(const QString *file) |
2292 | { | 2296 | { |
2293 | PWM_ASSERT(file); | 2297 | PWM_ASSERT(file); |
2294 | if (QFile::exists(*file)) { | 2298 | if (QFile::exists(*file)) { |
2295 | if (!QFile::remove(*file)) | 2299 | if (!QFile::remove(*file)) |
2296 | return e_accessFile; | 2300 | return e_accessFile; |
2297 | } | 2301 | } |
2298 | QFile f(*file); | 2302 | QFile f(*file); |
2299 | if (!f.open(IO_ReadWrite)) | 2303 | if (!f.open(IO_ReadWrite)) |
2300 | return e_openFile; | 2304 | return e_openFile; |
2301 | 2305 | ||
2302 | if (!unlockAll_tempoary()) { | 2306 | if (!unlockAll_tempoary()) { |
2303 | f.close(); | 2307 | f.close(); |
2304 | return e_lock; | 2308 | return e_lock; |
2305 | } | 2309 | } |
2306 | 2310 | ||
2307 | // write header | 2311 | // write header |
2308 | string header = i18n("Password table generated by\nPwM v").latin1(); | 2312 | string header = i18n("Password table generated by\nPwM v").latin1(); |
2309 | header += PACKAGE_VER; | 2313 | header += PACKAGE_VER; |
2310 | header += i18n("\non ").latin1(); | 2314 | header += i18n("\non ").latin1(); |
2311 | QDate currDate = QDate::currentDate(); | 2315 | QDate currDate = QDate::currentDate(); |
2312 | QTime currTime = QTime::currentTime(); | 2316 | QTime currTime = QTime::currentTime(); |
2313 | 2317 | ||
2314 | #ifndef PWM_EMBEDDED | 2318 | #ifndef PWM_EMBEDDED |
2315 | header += currDate.toString("ddd MMMM d ").latin1(); | 2319 | header += currDate.toString("ddd MMMM d ").latin1(); |
2316 | header += currTime.toString("hh:mm:ss ").latin1(); | 2320 | header += currTime.toString("hh:mm:ss ").latin1(); |
2317 | #else | 2321 | #else |
2318 | QString dfs = KGlobal::locale()->dateFormatShort(); | 2322 | QString dfs = KGlobal::locale()->dateFormatShort(); |
2319 | bool ampm = KGlobal::locale()->use12Clock(); | 2323 | bool ampm = KGlobal::locale()->use12Clock(); |
2320 | KGlobal::locale()->setDateFormatShort("%A %B %d"); | 2324 | KGlobal::locale()->setDateFormatShort("%A %B %d"); |
2321 | KGlobal::locale()->setHore24Format(true); | 2325 | KGlobal::locale()->setHore24Format(true); |
2322 | 2326 | ||
2323 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); | 2327 | header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined); |
2324 | header += KGlobal::locale()->formatTime(currTime, true); | 2328 | header += KGlobal::locale()->formatTime(currTime, true); |
2325 | KGlobal::locale()->setDateFormatShort(dfs); | 2329 | KGlobal::locale()->setDateFormatShort(dfs); |
2326 | KGlobal::locale()->setHore24Format(!ampm); | 2330 | KGlobal::locale()->setHore24Format(!ampm); |
2327 | 2331 | ||
2328 | #endif | 2332 | #endif |
2329 | header += tostr(currDate.year()); | 2333 | header += tostr(currDate.year()); |
2330 | header += "\n==============================\n\n"; | 2334 | header += "\n==============================\n\n"; |
2331 | 2335 | ||
2332 | 2336 | ||
2333 | #ifndef PWM_EMBEDDED | 2337 | #ifndef PWM_EMBEDDED |
2334 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { | 2338 | if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) { |
2335 | unlockAll_tempoary(true); | 2339 | unlockAll_tempoary(true); |
2336 | f.close(); | 2340 | f.close(); |
2337 | return e_writeFile; | 2341 | return e_writeFile; |
2338 | } | 2342 | } |
2339 | #else | 2343 | #else |
2340 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { | 2344 | if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) { |
2341 | unlockAll_tempoary(true); | 2345 | unlockAll_tempoary(true); |
2342 | f.close(); | 2346 | f.close(); |
2343 | return e_writeFile; | 2347 | return e_writeFile; |
2344 | } | 2348 | } |
2345 | #endif | 2349 | #endif |
2346 | unsigned int i, numCat = numCategories(); | 2350 | unsigned int i, numCat = numCategories(); |
2347 | unsigned int j, numEnt; | 2351 | unsigned int j, numEnt; |
2348 | string exp; | 2352 | string exp; |
2349 | for (i = 0; i < numCat; ++i) { | 2353 | for (i = 0; i < numCat; ++i) { |
2350 | numEnt = numEntries(i); | 2354 | numEnt = numEntries(i); |
2351 | 2355 | ||
2352 | exp = "\n== Category: "; | 2356 | exp = "\n== Category: "; |
2353 | exp += dta[i].name; | 2357 | exp += dti.dta[i].name; |
2354 | exp += " ==\n"; | 2358 | exp += " ==\n"; |
2355 | #ifndef PWM_EMBEDDED | 2359 | #ifndef PWM_EMBEDDED |
2356 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2360 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2357 | unlockAll_tempoary(true); | 2361 | unlockAll_tempoary(true); |
2358 | f.close(); | 2362 | f.close(); |
2359 | return e_writeFile; | 2363 | return e_writeFile; |
2360 | } | 2364 | } |
2361 | #else | 2365 | #else |
2362 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2366 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2363 | unlockAll_tempoary(true); | 2367 | unlockAll_tempoary(true); |
2364 | f.close(); | 2368 | f.close(); |
2365 | return e_writeFile; | 2369 | return e_writeFile; |
2366 | } | 2370 | } |
2367 | #endif | 2371 | #endif |
2368 | for (j = 0; j < numEnt; ++j) { | 2372 | for (j = 0; j < numEnt; ++j) { |
2369 | exp = "\n-- "; | 2373 | exp = "\n-- "; |
2370 | exp += dta[i].d[j].desc; | 2374 | exp += dti.dta[i].d[j].desc; |
2371 | exp += " --\n"; | 2375 | exp += " --\n"; |
2372 | 2376 | ||
2373 | exp += i18n("Username: ").latin1(); | 2377 | exp += i18n("Username: ").latin1(); |
2374 | exp += dta[i].d[j].name; | 2378 | exp += dti.dta[i].d[j].name; |
2375 | exp += "\n"; | 2379 | exp += "\n"; |
2376 | 2380 | ||
2377 | exp += i18n("Password: ").latin1(); | 2381 | exp += i18n("Password: ").latin1(); |
2378 | exp += dta[i].d[j].pw; | 2382 | exp += dti.dta[i].d[j].pw; |
2379 | exp += "\n"; | 2383 | exp += "\n"; |
2380 | 2384 | ||
2381 | exp += i18n("Comment: ").latin1(); | 2385 | exp += i18n("Comment: ").latin1(); |
2382 | exp += dta[i].d[j].comment; | 2386 | exp += dti.dta[i].d[j].comment; |
2383 | exp += "\n"; | 2387 | exp += "\n"; |
2384 | 2388 | ||
2385 | exp += i18n("URL: ").latin1(); | 2389 | exp += i18n("URL: ").latin1(); |
2386 | exp += dta[i].d[j].url; | 2390 | exp += dti.dta[i].d[j].url; |
2387 | exp += "\n"; | 2391 | exp += "\n"; |
2388 | 2392 | ||
2389 | exp += i18n("Launcher: ").latin1(); | 2393 | exp += i18n("Launcher: ").latin1(); |
2390 | exp += dta[i].d[j].launcher; | 2394 | exp += dti.dta[i].d[j].launcher; |
2391 | exp += "\n"; | 2395 | exp += "\n"; |
2392 | 2396 | ||
2393 | #ifndef PWM_EMBEDDED | 2397 | #ifndef PWM_EMBEDDED |
2394 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { | 2398 | if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) { |
2395 | unlockAll_tempoary(true); | 2399 | unlockAll_tempoary(true); |
2396 | f.close(); | 2400 | f.close(); |
2397 | return e_writeFile; | 2401 | return e_writeFile; |
2398 | } | 2402 | } |
2399 | #else | 2403 | #else |
2400 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { | 2404 | if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) { |
2401 | unlockAll_tempoary(true); | 2405 | unlockAll_tempoary(true); |
2402 | f.close(); | 2406 | f.close(); |
2403 | return e_writeFile; | 2407 | return e_writeFile; |
2404 | } | 2408 | } |
2405 | #endif | 2409 | #endif |
2406 | } | 2410 | } |
2407 | } | 2411 | } |
2408 | unlockAll_tempoary(true); | 2412 | unlockAll_tempoary(true); |
2409 | f.close(); | 2413 | f.close(); |
2410 | 2414 | ||
2411 | return e_success; | 2415 | return e_success; |
2412 | } | 2416 | } |
2413 | 2417 | ||
2414 | PwMerror PwMDoc::importFromText(const QString *file, int format) | 2418 | PwMerror PwMDoc::importFromText(const QString *file, int format) |
2415 | { | 2419 | { |
2416 | PWM_ASSERT(file); | 2420 | PWM_ASSERT(file); |
2417 | if (format == 0) | 2421 | if (format == 0) |
2418 | return importText_PwM(file); | 2422 | return importText_PwM(file); |
2419 | else if (format == -1) { | 2423 | else if (format == -1) { |
2420 | // probe for all formats | 2424 | // probe for all formats |
2421 | if (importText_PwM(file) == e_success) | 2425 | if (importText_PwM(file) == e_success) |
2422 | return e_success; | 2426 | return e_success; |
2423 | dta.clear(); | 2427 | dti.clear(); |
2424 | emitDataChanged(this); | 2428 | emitDataChanged(this); |
2425 | // add next format here... | 2429 | // add next format here... |
2426 | return e_fileFormat; | 2430 | return e_fileFormat; |
2427 | } | 2431 | } |
2428 | return e_invalidArg; | 2432 | return e_invalidArg; |
2429 | } | 2433 | } |
2430 | 2434 | ||
2431 | PwMerror PwMDoc::importText_PwM(const QString *file) | 2435 | PwMerror PwMDoc::importText_PwM(const QString *file) |
2432 | { | 2436 | { |
2433 | PWM_ASSERT(file); | 2437 | PWM_ASSERT(file); |
2434 | FILE *f; | 2438 | FILE *f; |
2435 | int tmp; | 2439 | int tmp; |
2436 | ssize_t ret; | 2440 | ssize_t ret; |
2437 | string curCat; | 2441 | string curCat; |
2438 | unsigned int entriesRead = 0; | 2442 | unsigned int entriesRead = 0; |
2439 | PwMDataItem currItem; | 2443 | PwMDataItem currItem; |
2440 | f = fopen(file->latin1(), "r"); | 2444 | f = fopen(file->latin1(), "r"); |
2441 | if (!f) | 2445 | if (!f) |
2442 | return e_openFile; | 2446 | return e_openFile; |
2443 | size_t ch_tmp_size = 1024; | 2447 | size_t ch_tmp_size = 1024; |
2444 | char *ch_tmp = (char*)malloc(ch_tmp_size); | 2448 | char *ch_tmp = (char*)malloc(ch_tmp_size); |
2445 | if (!ch_tmp) { | 2449 | if (!ch_tmp) { |
2446 | fclose(f); | 2450 | fclose(f); |
2447 | return e_outOfMem; | 2451 | return e_outOfMem; |
2448 | } | 2452 | } |
2449 | 2453 | ||
2450 | // - check header | 2454 | // - check header |
2451 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. | 2455 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line. |
2452 | goto formatError; | 2456 | goto formatError; |
2453 | // check version-string and return version in "ch_tmp". | 2457 | // check version-string and return version in "ch_tmp". |
2454 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { | 2458 | if (fscanf(f, "PwM v%s", ch_tmp) != 1) { |
2455 | // header not recognized as PwM generated header | 2459 | // header not recognized as PwM generated header |
2456 | goto formatError; | 2460 | goto formatError; |
2457 | } | 2461 | } |
2458 | // set filepointer behind version-string-line previously checked | 2462 | // set filepointer behind version-string-line previously checked |
2459 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2463 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2460 | goto formatError; | 2464 | goto formatError; |
2461 | // skip next line containing the build-date | 2465 | // skip next line containing the build-date |
2462 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2466 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2463 | goto formatError; | 2467 | goto formatError; |
2464 | // read header termination line | 2468 | // read header termination line |
2465 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2469 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2466 | goto formatError; | 2470 | goto formatError; |
2467 | if (strcmp(ch_tmp, "==============================\n")) | 2471 | if (strcmp(ch_tmp, "==============================\n")) |
2468 | goto formatError; | 2472 | goto formatError; |
2469 | 2473 | ||
2470 | // - read entries | 2474 | // - read entries |
2471 | do { | 2475 | do { |
2472 | // find beginning of next category | 2476 | // find beginning of next category |
2473 | do { | 2477 | do { |
2474 | tmp = fgetc(f); | 2478 | tmp = fgetc(f); |
2475 | } while (tmp == '\n' && tmp != EOF); | 2479 | } while (tmp == '\n' && tmp != EOF); |
2476 | if (tmp == EOF) | 2480 | if (tmp == EOF) |
2477 | break; | 2481 | break; |
2478 | 2482 | ||
2479 | // decrement filepos by one | 2483 | // decrement filepos by one |
2480 | fseek(f, -1, SEEK_CUR); | 2484 | fseek(f, -1, SEEK_CUR); |
2481 | // read cat-name | 2485 | // read cat-name |
2482 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2486 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2483 | goto formatError; | 2487 | goto formatError; |
2484 | // check cat-name format | 2488 | // check cat-name format |
2485 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) | 2489 | if (memcmp(ch_tmp, "== Category: ", 13) != 0) |
2486 | goto formatError; | 2490 | goto formatError; |
2487 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) | 2491 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0) |
2488 | goto formatError; | 2492 | goto formatError; |
2489 | // copy cat-name | 2493 | // copy cat-name |
2490 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); | 2494 | curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16); |
2491 | 2495 | ||
2492 | do { | 2496 | do { |
2493 | // find beginning of next entry | 2497 | // find beginning of next entry |
2494 | do { | 2498 | do { |
2495 | tmp = fgetc(f); | 2499 | tmp = fgetc(f); |
2496 | } while (tmp == '\n' && tmp != EOF && tmp != '='); | 2500 | } while (tmp == '\n' && tmp != EOF && tmp != '='); |
2497 | if (tmp == EOF) | 2501 | if (tmp == EOF) |
2498 | break; | 2502 | break; |
2499 | if (tmp == '=') { | 2503 | if (tmp == '=') { |
2500 | fseek(f, -1, SEEK_CUR); | 2504 | fseek(f, -1, SEEK_CUR); |
2501 | break; | 2505 | break; |
2502 | } | 2506 | } |
2503 | // decrement filepos by one | 2507 | // decrement filepos by one |
2504 | fseek(f, -1, SEEK_CUR); | 2508 | fseek(f, -1, SEEK_CUR); |
2505 | // read desc-line | 2509 | // read desc-line |
2506 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) | 2510 | if (getline(&ch_tmp, &ch_tmp_size, f) == -1) |
2507 | goto formatError; | 2511 | goto formatError; |
2508 | // check desc-line format | 2512 | // check desc-line format |
2509 | if (memcmp(ch_tmp, "-- ", 3) != 0) | 2513 | if (memcmp(ch_tmp, "-- ", 3) != 0) |
2510 | goto formatError; | 2514 | goto formatError; |
2511 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) | 2515 | if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0) |
2512 | goto formatError; | 2516 | goto formatError; |
2513 | // add desc-line | 2517 | // add desc-line |
2514 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); | 2518 | currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6); |
2515 | 2519 | ||
2516 | // read username-line | 2520 | // read username-line |
2517 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2521 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2518 | goto formatError; | 2522 | goto formatError; |
2519 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) | 2523 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name)) |
2520 | goto formatError; | 2524 | goto formatError; |
2521 | 2525 | ||
2522 | // read pw-line | 2526 | // read pw-line |
2523 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2527 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2524 | goto formatError; | 2528 | goto formatError; |
2525 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) | 2529 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw)) |
2526 | goto formatError; | 2530 | goto formatError; |
2527 | 2531 | ||
2528 | // read comment-line | 2532 | // read comment-line |
2529 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2533 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2530 | goto formatError; | 2534 | goto formatError; |
2531 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) | 2535 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment)) |
2532 | goto formatError; | 2536 | goto formatError; |
2533 | 2537 | ||
2534 | // read URL-line | 2538 | // read URL-line |
2535 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2539 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2536 | goto formatError; | 2540 | goto formatError; |
2537 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) | 2541 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url)) |
2538 | goto formatError; | 2542 | goto formatError; |
2539 | 2543 | ||
2540 | // read launcher-line | 2544 | // read launcher-line |
2541 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) | 2545 | if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1) |
2542 | goto formatError; | 2546 | goto formatError; |
2543 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) | 2547 | if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher)) |
2544 | goto formatError; | 2548 | goto formatError; |
2545 | 2549 | ||
2546 | currItem.lockStat = true; | 2550 | currItem.lockStat = true; |
2547 | currItem.listViewPos = -1; | 2551 | currItem.listViewPos = -1; |
2548 | addEntry(curCat.c_str(), &currItem, true); | 2552 | addEntry(curCat.c_str(), &currItem, true); |
2549 | ++entriesRead; | 2553 | ++entriesRead; |
2550 | } while (1); | 2554 | } while (1); |
2551 | } while (1); | 2555 | } while (1); |
2552 | if (!entriesRead) | 2556 | if (!entriesRead) |
2553 | goto formatError; | 2557 | goto formatError; |
2554 | 2558 | ||
2555 | free(ch_tmp); | 2559 | free(ch_tmp); |
2556 | fclose(f); | 2560 | fclose(f); |
2557 | flagDirty(); | 2561 | flagDirty(); |
2558 | return e_success; | 2562 | return e_success; |
2559 | 2563 | ||
2560 | formatError: | 2564 | formatError: |
2561 | free(ch_tmp); | 2565 | free(ch_tmp); |
2562 | fclose(f); | 2566 | fclose(f); |
2563 | return e_fileFormat; | 2567 | return e_fileFormat; |
2564 | } | 2568 | } |
2565 | 2569 | ||
2566 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) | 2570 | bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out) |
2567 | { | 2571 | { |
2568 | PWM_ASSERT(in && out); | 2572 | PWM_ASSERT(in && out); |
2569 | ssize_t i = 0, len = in_size - 1; | 2573 | ssize_t i = 0, len = in_size - 1; |
2570 | while (i < len) { | 2574 | while (i < len) { |
2571 | if (in[i] == ':') | 2575 | if (in[i] == ':') |
2572 | break; | 2576 | break; |
2573 | ++i; | 2577 | ++i; |
2574 | } | 2578 | } |
2575 | i += 2; | 2579 | i += 2; |
2576 | *out = ""; | 2580 | *out = ""; |
2577 | out->append(in + i, in_size - i - 1); | 2581 | out->append(in + i, in_size - i - 1); |
2578 | return true; | 2582 | return true; |
2579 | } | 2583 | } |
2580 | 2584 | ||
2581 | PwMerror PwMDoc::exportToGpasman(const QString *file) | 2585 | PwMerror PwMDoc::exportToGpasman(const QString *file) |
2582 | { | 2586 | { |
2583 | PWM_ASSERT(file); | 2587 | PWM_ASSERT(file); |
2584 | GpasmanFile gp; | 2588 | GpasmanFile gp; |
2585 | int ret; | 2589 | int ret; |
2586 | 2590 | ||
2587 | if (!unlockAll_tempoary()) | 2591 | if (!unlockAll_tempoary()) |
2588 | return e_lock; | 2592 | return e_lock; |
2589 | 2593 | ||
2590 | QString gpmPassword; | 2594 | QString gpmPassword; |
2591 | while (1) { | 2595 | while (1) { |
2592 | gpmPassword = requestNewMpw(0); | 2596 | gpmPassword = requestNewMpw(0); |
2593 | if (gpmPassword == "") { | 2597 | if (gpmPassword == "") { |
2594 | unlockAll_tempoary(true); | 2598 | unlockAll_tempoary(true); |
2595 | return e_noPw; | 2599 | return e_noPw; |
2596 | } | 2600 | } |
2597 | if (gpmPassword.length() < 4) { | 2601 | if (gpmPassword.length() < 4) { |
2598 | gpmPwLenErrMsgBox(); | 2602 | gpmPwLenErrMsgBox(); |
2599 | } else { | 2603 | } else { |
2600 | break; | 2604 | break; |
2601 | } | 2605 | } |
2602 | } | 2606 | } |
2603 | 2607 | ||
2604 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); | 2608 | ret = gp.save_init(file->latin1(), gpmPassword.latin1()); |
2605 | if (ret != 1) { | 2609 | if (ret != 1) { |
2606 | unlockAll_tempoary(true); | 2610 | unlockAll_tempoary(true); |
2607 | return e_accessFile; | 2611 | return e_accessFile; |
2608 | } | 2612 | } |
2609 | 2613 | ||
2610 | char *entry[4]; | 2614 | char *entry[4]; |
2611 | unsigned int numCat = numCategories(), i; | 2615 | unsigned int numCat = numCategories(), i; |
2612 | unsigned int numEntr, j; | 2616 | unsigned int numEntr, j; |
2613 | int descLen, nameLen, pwLen, commentLen; | 2617 | int descLen, nameLen, pwLen, commentLen; |
2614 | for (i = 0; i < numCat; ++i) { | 2618 | for (i = 0; i < numCat; ++i) { |
2615 | numEntr = numEntries(i); | 2619 | numEntr = numEntries(i); |
2616 | for (j = 0; j < numEntr; ++j) { | 2620 | for (j = 0; j < numEntr; ++j) { |
2617 | descLen = dta[i].d[j].desc.length(); | 2621 | descLen = dti.dta[i].d[j].desc.length(); |
2618 | nameLen = dta[i].d[j].name.length(); | 2622 | nameLen = dti.dta[i].d[j].name.length(); |
2619 | pwLen = dta[i].d[j].pw.length(); | 2623 | pwLen = dti.dta[i].d[j].pw.length(); |
2620 | commentLen = dta[i].d[j].comment.length(); | 2624 | commentLen = dti.dta[i].d[j].comment.length(); |
2621 | entry[0] = new char[descLen + 1]; | 2625 | entry[0] = new char[descLen + 1]; |
2622 | entry[1] = new char[nameLen + 1]; | 2626 | entry[1] = new char[nameLen + 1]; |
2623 | entry[2] = new char[pwLen + 1]; | 2627 | entry[2] = new char[pwLen + 1]; |
2624 | entry[3] = new char[commentLen + 1]; | 2628 | entry[3] = new char[commentLen + 1]; |
2625 | strcpy(entry[0], descLen == 0 ? " " : dta[i].d[j].desc.c_str()); | 2629 | strcpy(entry[0], descLen == 0 ? " " : dti.dta[i].d[j].desc.c_str()); |
2626 | strcpy(entry[1], nameLen == 0 ? " " : dta[i].d[j].name.c_str()); | 2630 | strcpy(entry[1], nameLen == 0 ? " " : dti.dta[i].d[j].name.c_str()); |
2627 | strcpy(entry[2], pwLen == 0 ? " " : dta[i].d[j].pw.c_str()); | 2631 | strcpy(entry[2], pwLen == 0 ? " " : dti.dta[i].d[j].pw.c_str()); |
2628 | strcpy(entry[3], commentLen == 0 ? " " : dta[i].d[j].comment.c_str()); | 2632 | strcpy(entry[3], commentLen == 0 ? " " : dti.dta[i].d[j].comment.c_str()); |
2629 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; | 2633 | entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0'; |
2630 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; | 2634 | entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0'; |
2631 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; | 2635 | entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0'; |
2632 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; | 2636 | entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0'; |
2633 | 2637 | ||
2634 | ret = gp.save_entry(entry); | 2638 | ret = gp.save_entry(entry); |
2635 | if (ret == -1){ | 2639 | if (ret == -1){ |
2636 | delete [] entry[0]; | 2640 | delete [] entry[0]; |
2637 | delete [] entry[1]; | 2641 | delete [] entry[1]; |
2638 | delete [] entry[2]; | 2642 | delete [] entry[2]; |
2639 | delete [] entry[3]; | 2643 | delete [] entry[3]; |
2640 | gp.save_finalize(); | 2644 | gp.save_finalize(); |
2641 | unlockAll_tempoary(true); | 2645 | unlockAll_tempoary(true); |
2642 | return e_writeFile; | 2646 | return e_writeFile; |
2643 | } | 2647 | } |
2644 | 2648 | ||
2645 | delete [] entry[0]; | 2649 | delete [] entry[0]; |
2646 | delete [] entry[1]; | 2650 | delete [] entry[1]; |
2647 | delete [] entry[2]; | 2651 | delete [] entry[2]; |
2648 | delete [] entry[3]; | 2652 | delete [] entry[3]; |
2649 | } | 2653 | } |
2650 | } | 2654 | } |
2651 | unlockAll_tempoary(true); | 2655 | unlockAll_tempoary(true); |
2652 | if (gp.save_finalize() == -1) | 2656 | if (gp.save_finalize() == -1) |
2653 | return e_writeFile; | 2657 | return e_writeFile; |
2654 | 2658 | ||
2655 | return e_success; | 2659 | return e_success; |
2656 | } | 2660 | } |
2657 | 2661 | ||
2658 | PwMerror PwMDoc::importFromGpasman(const QString *file) | 2662 | PwMerror PwMDoc::importFromGpasman(const QString *file) |
2659 | { | 2663 | { |
2660 | PWM_ASSERT(file); | 2664 | PWM_ASSERT(file); |
2661 | QString pw = requestMpw(false); | 2665 | QString pw = requestMpw(false); |
2662 | if (pw == "") | 2666 | if (pw == "") |
2663 | return e_noPw; | 2667 | return e_noPw; |
2664 | GpasmanFile gp; | 2668 | GpasmanFile gp; |
2665 | int ret, i; | 2669 | int ret, i; |
2666 | PwMerror ret2; | 2670 | PwMerror ret2; |
2667 | char *entry[4]; | 2671 | char *entry[4]; |
2668 | PwMDataItem tmpData; | 2672 | PwMDataItem tmpData; |
2669 | ret = gp.load_init(file->latin1(), pw.latin1()); | 2673 | ret = gp.load_init(file->latin1(), pw.latin1()); |
2670 | if (ret != 1) | 2674 | if (ret != 1) |
2671 | return e_accessFile; | 2675 | return e_accessFile; |
2672 | 2676 | ||
2673 | do { | 2677 | do { |
2674 | ret = gp.load_entry(entry); | 2678 | ret = gp.load_entry(entry); |
2675 | if(ret != 1) | 2679 | if(ret != 1) |
2676 | break; | 2680 | break; |
2677 | tmpData.desc = entry[0]; | 2681 | tmpData.desc = entry[0]; |
2678 | tmpData.name = entry[1]; | 2682 | tmpData.name = entry[1]; |
2679 | tmpData.pw = entry[2]; | 2683 | tmpData.pw = entry[2]; |
2680 | tmpData.comment = entry[3]; | 2684 | tmpData.comment = entry[3]; |
2681 | tmpData.lockStat = true; | 2685 | tmpData.lockStat = true; |
2682 | tmpData.listViewPos = -1; | 2686 | tmpData.listViewPos = -1; |
2683 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); | 2687 | ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); |
2684 | for (i = 0; i < 4; ++i) | 2688 | for (i = 0; i < 4; ++i) |
2685 | free(entry[i]); | 2689 | free(entry[i]); |
2686 | if (ret2 == e_maxAllowedEntr) { | 2690 | if (ret2 == e_maxAllowedEntr) { |
2687 | gp.load_finalize(); | 2691 | gp.load_finalize(); |
2688 | return e_maxAllowedEntr; | 2692 | return e_maxAllowedEntr; |
2689 | } | 2693 | } |
2690 | } while (1); | 2694 | } while (1); |
2691 | gp.load_finalize(); | 2695 | gp.load_finalize(); |
2692 | if (isDocEmpty()) | 2696 | if (isDocEmpty()) |
2693 | return e_wrongPw; // we assume this. | 2697 | return e_wrongPw; // we assume this. |
2694 | 2698 | ||
2695 | flagDirty(); | 2699 | flagDirty(); |
2696 | return e_success; | 2700 | return e_success; |
2697 | } | 2701 | } |
2698 | 2702 | ||
2699 | void PwMDoc::ensureLvp() | 2703 | void PwMDoc::ensureLvp() |
2700 | { | 2704 | { |
2701 | if (isDocEmpty()) | 2705 | if (isDocEmpty()) |
2702 | return; | 2706 | return; |
2703 | 2707 | ||
2704 | vector< vector<PwMDataItem>::iterator > undefined; | 2708 | vector< vector<PwMDataItem>::iterator > undefined; |
2705 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2709 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, |
2706 | undefEnd, | 2710 | undefEnd, |
2707 | undefI; | 2711 | undefI; |
2708 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 2712 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2709 | catEnd = dta.end(), | 2713 | catEnd = dti.dta.end(), |
2710 | catI = catBegin; | 2714 | catI = catBegin; |
2711 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2715 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2712 | int lvpTop, tmpLvp; | 2716 | int lvpTop, tmpLvp; |
2713 | 2717 | ||
2714 | while (catI != catEnd) { | 2718 | while (catI != catEnd) { |
2715 | lvpTop = -1; | 2719 | lvpTop = -1; |
2716 | undefined.clear(); | 2720 | undefined.clear(); |
2717 | 2721 | ||
2718 | entrBegin = catI->d.begin(); | 2722 | entrBegin = catI->d.begin(); |
2719 | entrEnd = catI->d.end(); | 2723 | entrEnd = catI->d.end(); |
2720 | entrI = entrBegin; | 2724 | entrI = entrBegin; |
2721 | 2725 | ||
2722 | while (entrI != entrEnd) { | 2726 | while (entrI != entrEnd) { |
2723 | tmpLvp = entrI->listViewPos; | 2727 | tmpLvp = entrI->listViewPos; |
2724 | if (tmpLvp == -1) | 2728 | if (tmpLvp == -1) |
2725 | undefined.push_back(entrI); | 2729 | undefined.push_back(entrI); |
2726 | else if (tmpLvp > lvpTop) | 2730 | else if (tmpLvp > lvpTop) |
2727 | lvpTop = tmpLvp; | 2731 | lvpTop = tmpLvp; |
2728 | ++entrI; | 2732 | ++entrI; |
2729 | } | 2733 | } |
2730 | undefBegin = undefined.begin(); | 2734 | undefBegin = undefined.begin(); |
2731 | undefEnd = undefined.end(); | 2735 | undefEnd = undefined.end(); |
2732 | undefI = undefBegin; | 2736 | undefI = undefBegin; |
2733 | while (undefI != undefEnd) { | 2737 | while (undefI != undefEnd) { |
2734 | (*undefI)->listViewPos = ++lvpTop; | 2738 | (*undefI)->listViewPos = ++lvpTop; |
2735 | ++undefI; | 2739 | ++undefI; |
2736 | } | 2740 | } |
2737 | ++catI; | 2741 | ++catI; |
2738 | } | 2742 | } |
2739 | } | 2743 | } |
2740 | 2744 | ||
2741 | QString PwMDoc::getTitle() | 2745 | QString PwMDoc::getTitle() |
2742 | { | 2746 | { |
2743 | /* NOTE: We have to ensure, that the returned title | 2747 | /* NOTE: We have to ensure, that the returned title |
2744 | * is unique and not reused somewhere else while | 2748 | * is unique and not reused somewhere else while |
2745 | * this document is valid (open). | 2749 | * this document is valid (open). |
2746 | */ | 2750 | */ |
2747 | QString title(getFilename()); | 2751 | QString title(getFilename()); |
2748 | if (title.isEmpty()) { | 2752 | if (title.isEmpty()) { |
2749 | if (unnamedNum == 0) { | 2753 | if (unnamedNum == 0) { |
2750 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2754 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2751 | PWM_ASSERT(unnamedNum != 0); | 2755 | PWM_ASSERT(unnamedNum != 0); |
2752 | } | 2756 | } |
2753 | title = DEFAULT_TITLE; | 2757 | title = DEFAULT_TITLE; |
2754 | title += " "; | 2758 | title += " "; |
2755 | title += tostr(unnamedNum).c_str(); | 2759 | title += tostr(unnamedNum).c_str(); |
2756 | } | 2760 | } |
2757 | return title; | 2761 | return title; |
2758 | } | 2762 | } |
2759 | 2763 | ||
2760 | bool PwMDoc::tryDelete() | 2764 | bool PwMDoc::tryDelete() |
2761 | { | 2765 | { |
2762 | if (deleted) | 2766 | if (deleted) |
2763 | return true; | 2767 | return true; |
2764 | int ret; | 2768 | int ret; |
2765 | if (isDirty()) { | 2769 | if (isDirty()) { |
2766 | ret = dirtyAskSave(getTitle()); | 2770 | ret = dirtyAskSave(getTitle()); |
2767 | if (ret == 0) { // save to disk | 2771 | if (ret == 0) { // save to disk |
2768 | if (!saveDocUi(this)) | 2772 | if (!saveDocUi(this)) |
2769 | goto out_ignore; | 2773 | goto out_ignore; |
2770 | } else if (ret == 1) { // don't save and delete | 2774 | } else if (ret == 1) { // don't save and delete |
2771 | goto out_accept; | 2775 | goto out_accept; |
2772 | } else { // cancel operation | 2776 | } else { // cancel operation |
2773 | goto out_ignore; | 2777 | goto out_ignore; |
2774 | } | 2778 | } |
2775 | } | 2779 | } |
2776 | out_accept: | 2780 | out_accept: |
2777 | deleted = true; | 2781 | deleted = true; |
2778 | delete this; | 2782 | delete this; |
2779 | return true; | 2783 | return true; |
2780 | out_ignore: | 2784 | out_ignore: |
2781 | return false; | 2785 | return false; |
2782 | } | 2786 | } |
2783 | 2787 | ||
2784 | 2788 | ||
2785 | 2789 | ||
2786 | #ifdef PWM_EMBEDDED | 2790 | #ifdef PWM_EMBEDDED |
2787 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2792 | //US it could have been defined as static, but I did not want to. | ||
2788 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2789 | { | 2794 | { |
2790 | bool syncOK = true; | ||
2791 | int addedPasswordsLocal = 0; | 2795 | int addedPasswordsLocal = 0; |
2792 | int addedPasswordsRemote = 0; | 2796 | int addedPasswordsRemote = 0; |
2793 | int deletedPasswordsRemote = 0; | 2797 | int deletedPasswordsRemote = 0; |
2794 | int deletedPasswordsLocal = 0; | 2798 | int deletedPasswordsLocal = 0; |
2795 | int changedLocal = 0; | 2799 | int changedLocal = 0; |
2796 | int changedRemote = 0; | 2800 | int changedRemote = 0; |
2797 | 2801 | ||
2802 | PwMSyncItem* syncItemLocal; | ||
2803 | PwMSyncItem* syncItemRemote; | ||
2804 | |||
2798 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2799 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2800 | 2807 | ||
2808 | bool fullDateRange = false; | ||
2809 | int take; | ||
2810 | // local->resetTempSyncStat(); | ||
2811 | QDateTime mLastSync = QDateTime::currentDateTime(); | ||
2812 | QDateTime modifiedSync = mLastSync; | ||
2813 | |||
2814 | unsigned int index; | ||
2815 | //Step 1. Find syncinfo in Local file and create if not existent. | ||
2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | ||
2817 | if (found == false) | ||
2818 | { | ||
2819 | PwMSyncItem newSyncItemLocal; | ||
2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; | ||
2821 | newSyncItemLocal.lastSyncDate = mLastSync; | ||
2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | ||
2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | ||
2824 | if (found == false) { | ||
2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | ||
2826 | return e_syncError; | ||
2827 | } | ||
2828 | } | ||
2829 | |||
2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); | ||
2831 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | ||
2832 | |||
2833 | //Step 2. Find syncinfo in remote file and create if not existent. | ||
2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | ||
2835 | if (found == false) | ||
2836 | { | ||
2837 | qDebug("FULLDATE 1"); | ||
2838 | fullDateRange = true; | ||
2839 | PwMSyncItem newSyncItemRemote; | ||
2840 | newSyncItemRemote.syncName = mCurrentSyncName; | ||
2841 | newSyncItemRemote.lastSyncDate = mLastSync; | ||
2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | ||
2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | ||
2844 | if (found == false) { | ||
2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | ||
2846 | return e_syncError; | ||
2847 | } | ||
2848 | } | ||
2849 | |||
2850 | syncItemRemote = syncRemote->getSyncDataEntry(index); | ||
2851 | //and remove the found entry here. We will reenter it later again. | ||
2852 | syncRemote->delSyncDataEntry(index, true); | ||
2801 | 2853 | ||
2802 | 2854 | ||
2855 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | ||
2856 | qDebug("FULLDATE 2"); | ||
2857 | fullDateRange = true; | ||
2858 | } | ||
2859 | |||
2860 | if ( ! fullDateRange ) { | ||
2861 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | ||
2862 | |||
2863 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | ||
2864 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | ||
2865 | fullDateRange = true; | ||
2866 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | ||
2867 | } | ||
2868 | } | ||
2869 | // fullDateRange = true; // debug only! | ||
2870 | if ( fullDateRange ) | ||
2871 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | ||
2872 | else | ||
2873 | mLastSync = syncItemLocal->lastSyncDate; | ||
2874 | |||
2875 | |||
2876 | qDebug("*************************** "); | ||
2877 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | ||
2878 | QStringList er = syncRemote->getIDEntryList(); | ||
2879 | PwMDataItem* inRemote ;//= er.first(); | ||
2880 | PwMDataItem* inLocal; | ||
2881 | unsigned int catLocal, indexLocal; | ||
2882 | unsigned int catRemote, indexRemote; | ||
2883 | |||
2884 | QString uid; | ||
2885 | manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | ||
2886 | |||
2887 | int modulo = (er.count()/10)+1; | ||
2888 | unsigned int incCounter = 0; | ||
2889 | while ( incCounter < er.count()) { | ||
2890 | if (manager->isProgressBarCanceled()) | ||
2891 | return e_syncError; | ||
2892 | if ( incCounter % modulo == 0 ) | ||
2893 | manager->showProgressBar(incCounter); | ||
2894 | |||
2895 | uid = er[ incCounter ]; | ||
2896 | qApp->processEvents(); | ||
2897 | |||
2898 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | ||
2899 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | ||
2900 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | ||
2901 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | ||
2902 | //qDebug("take %d %s ", take, inL.summary().latin1()); | ||
2903 | if ( take == 3 ) | ||
2904 | return e_syncError; | ||
2905 | if ( take == 1 ) {// take local | ||
2906 | //US syncRemote->removeAddressee( inRemote ); | ||
2907 | (*inRemote) = (*inLocal); | ||
2908 | //US syncRemote->insertAddressee( inRemote , false); | ||
2909 | ++changedRemote; | ||
2910 | } else { // take == 2 take remote | ||
2911 | //US syncLocal->removeAddressee( inLocal ); | ||
2912 | (*inLocal) = (*inRemote); | ||
2913 | //US syncLocal->insertAddressee( inLocal , false ); | ||
2914 | ++changedLocal; | ||
2915 | } | ||
2916 | } | ||
2917 | } else { // no conflict | ||
2918 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | ||
2919 | inRemote->meta.update = modifiedSync; | ||
2920 | //US syncRemote->insertAddressee( inRemote, false ); | ||
2921 | //US syncLocal->insertAddressee( inRemote, false ); | ||
2922 | syncLocal->addEntry("newcategory", inRemote, true, false); | ||
2923 | |||
2924 | ++addedPasswordsLocal; | ||
2925 | } else { | ||
2926 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | ||
2927 | syncRemote->delEntry(catRemote, indexRemote, true); | ||
2928 | //USsyncRemote->removeAddressee( inRemote ); | ||
2929 | ++deletedPasswordsRemote; | ||
2930 | } | ||
2931 | } | ||
2932 | |||
2933 | ++incCounter; | ||
2934 | } | ||
2803 | 2935 | ||
2804 | 2936 | ||
2937 | er.clear(); | ||
2938 | QStringList el = syncLocal->getIDEntryList(); | ||
2939 | modulo = (el.count()/10)+1; | ||
2940 | |||
2941 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | ||
2942 | incCounter = 0; | ||
2943 | while ( incCounter < el.count()) { | ||
2944 | qApp->processEvents(); | ||
2945 | if (manager->isProgressBarCanceled()) | ||
2946 | return e_syncError; | ||
2947 | if ( incCounter % modulo == 0 ) | ||
2948 | manager->showProgressBar(incCounter); | ||
2949 | uid = el[ incCounter ]; | ||
2950 | |||
2951 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | ||
2952 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | ||
2953 | if ( inRemote == 0 ) { | ||
2954 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | ||
2955 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | ||
2956 | syncLocal->delEntry(catLocal, indexLocal, true); | ||
2957 | //USsyncLocal->removeAddressee( inLocal ); | ||
2958 | ++deletedPasswordsLocal; | ||
2959 | } else { | ||
2960 | if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { | ||
2961 | ++addedPasswordsRemote; | ||
2962 | inLocal->meta.update = modifiedSync; | ||
2963 | //USsyncLocal->insertAddressee( inLocal, false ); | ||
2964 | (*inRemote) = (*inLocal); | ||
2965 | //USsyncRemote->insertAddressee( inRemote, false ); | ||
2966 | syncRemote->addEntry("newcategory", inRemote, true, false); | ||
2967 | |||
2968 | } | ||
2969 | } | ||
2970 | |||
2971 | } | ||
2972 | ++incCounter; | ||
2973 | } | ||
2974 | el.clear(); | ||
2975 | manager->hideProgressBar(); | ||
2976 | |||
2977 | // Now write the info back into the sync data space of the files | ||
2805 | 2978 | ||
2979 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | ||
2980 | // get rid of micro seconds | ||
2981 | QTime t = mLastSync.time(); | ||
2982 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | ||
2806 | 2983 | ||
2984 | |||
2985 | syncItemLocal->lastSyncDate = mLastSync; | ||
2986 | syncItemRemote->lastSyncDate = mLastSync; | ||
2807 | 2987 | ||
2988 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | ||
2989 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | ||
2808 | 2990 | ||
2991 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | ||
2992 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | ||
2993 | QString mes; | ||
2994 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); | ||
2995 | if ( PWMPrefs::instance()->mShowSyncSummary ) { | ||
2996 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | ||
2997 | } | ||
2998 | qDebug( mes ); | ||
2809 | return e_success; | 2999 | return e_success; |
2810 | } | 3000 | } |
2811 | 3001 | ||
2812 | 3002 | ||
3003 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | ||
3004 | { | ||
3005 | // 0 equal | ||
3006 | // 1 take local | ||
3007 | // 2 take remote | ||
3008 | // 3 cancel | ||
3009 | QDateTime localMod = local->meta.update; | ||
3010 | QDateTime remoteMod = remote->meta.update; | ||
3011 | |||
3012 | //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | ||
3013 | |||
3014 | if ( localMod == remoteMod ) | ||
3015 | return 0; | ||
3016 | |||
3017 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | ||
3018 | |||
3019 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | ||
3020 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | ||
3021 | //full = true; //debug only | ||
3022 | if ( full ) { | ||
3023 | bool equ = true;//US ( (*local) == (*remote) ); | ||
3024 | if ( equ ) { | ||
3025 | //qDebug("equal "); | ||
3026 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | ||
3027 | return 0; | ||
3028 | |||
3029 | }//else //debug only | ||
3030 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | ||
3031 | } | ||
3032 | |||
3033 | int result; | ||
3034 | bool localIsNew; | ||
3035 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | ||
3036 | |||
3037 | if ( full && mode < SYNC_PREF_NEWEST ) | ||
3038 | mode = SYNC_PREF_ASK; | ||
3039 | |||
3040 | switch( mode ) { | ||
3041 | case SYNC_PREF_LOCAL: | ||
3042 | if ( lastSync > remoteMod ) | ||
3043 | return 1; | ||
3044 | if ( lastSync > localMod ) | ||
3045 | return 2; | ||
3046 | return 1; | ||
3047 | break; | ||
3048 | case SYNC_PREF_REMOTE: | ||
3049 | if ( lastSync > remoteMod ) | ||
3050 | return 1; | ||
3051 | if ( lastSync > localMod ) | ||
3052 | return 2; | ||
3053 | return 2; | ||
3054 | break; | ||
3055 | case SYNC_PREF_NEWEST: | ||
3056 | if ( localMod > remoteMod ) | ||
3057 | return 1; | ||
3058 | else | ||
3059 | return 2; | ||
3060 | break; | ||
3061 | case SYNC_PREF_ASK: | ||
3062 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | ||
3063 | if ( lastSync > remoteMod ) | ||
3064 | return 1; | ||
3065 | if ( lastSync > localMod ) | ||
3066 | return 2; | ||
3067 | localIsNew = localMod >= remoteMod; | ||
3068 | //qDebug("conflict! ************************************** "); | ||
3069 | { | ||
3070 | PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); | ||
3071 | result = acd.executeD(localIsNew); | ||
3072 | return result; | ||
3073 | } | ||
3074 | break; | ||
3075 | case SYNC_PREF_FORCE_LOCAL: | ||
3076 | return 1; | ||
3077 | break; | ||
3078 | case SYNC_PREF_FORCE_REMOTE: | ||
3079 | return 2; | ||
3080 | break; | ||
3081 | |||
3082 | default: | ||
3083 | // SYNC_PREF_TAKE_BOTH not implemented | ||
3084 | break; | ||
3085 | } | ||
3086 | return 0; | ||
3087 | } | ||
3088 | |||
3089 | |||
3090 | |||
2813 | 3091 | ||
2814 | //this are the overwritten callbackmethods from the syncinterface | 3092 | //this are the overwritten callbackmethods from the syncinterface |
2815 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | 3093 | bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) |
2816 | { | 3094 | { |
2817 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 3095 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2818 | 3096 | ||
2819 | // construct on the stack = automatic cleanup. | 3097 | // construct on the stack = automatic cleanup. |
2820 | PwMDoc syncTarget(this, "synctarget"); | 3098 | PwMDoc syncTarget(this, "synctarget"); |
2821 | 3099 | ||
2822 | PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/); | 3100 | PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/); |
2823 | 3101 | ||
2824 | if (err != e_success) | 3102 | if (err != e_success) |
2825 | return false; | 3103 | return false; |
2826 | 3104 | ||
2827 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); | 3105 | qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); |
2828 | 3106 | ||
2829 | 3107 | ||
2830 | err = syncronize(manager, this, &syncTarget, mode ); | 3108 | err = syncronize(manager, this, &syncTarget, mode ); |
2831 | 3109 | ||
2832 | if (err == e_success) { | 3110 | if (err == e_success) { |
2833 | if ( PWMPrefs::instance()->mWriteBackFile ){ | 3111 | if ( PWMPrefs::instance()->mWriteBackFile ){ |
2834 | qDebug("Saving remote PWManager file"); | 3112 | qDebug("Saving remote PWManager file"); |
2835 | err = syncTarget.saveDoc(conf()->confGlobCompression()); | 3113 | err = syncTarget.saveDoc(conf()->confGlobCompression()); |
2836 | if (err != e_success) | 3114 | if (err != e_success) |
2837 | return false; | 3115 | return false; |
2838 | 3116 | ||
2839 | } | 3117 | } |
2840 | 3118 | ||
2841 | flagDirty(); | 3119 | flagDirty(); |
2842 | return true; | 3120 | return true; |
2843 | } | 3121 | } |
2844 | else { | 3122 | else { |
2845 | return false; | 3123 | return false; |
2846 | } | 3124 | } |
2847 | } | 3125 | } |
2848 | 3126 | ||
2849 | //called by the syncmanager to indicate that the work has to marked as dirty. | 3127 | //called by the syncmanager to indicate that the work has to marked as dirty. |
2850 | void PwMDoc::sync_setModified() | 3128 | void PwMDoc::sync_setModified() |
2851 | { | 3129 | { |
2852 | flagDirty(); | 3130 | flagDirty(); |
2853 | } | 3131 | } |
2854 | 3132 | ||
2855 | //called by the syncmanager to ask if the dirty flag is set. | 3133 | //called by the syncmanager to ask if the dirty flag is set. |
2856 | bool PwMDoc::sync_isModified() | 3134 | bool PwMDoc::sync_isModified() |
2857 | { | 3135 | { |
2858 | return isDirty(); | 3136 | return isDirty(); |
2859 | } | 3137 | } |
2860 | 3138 | ||
2861 | //called by the syncmanager to indicate that the work has to be saved. | 3139 | //called by the syncmanager to indicate that the work has to be saved. |
2862 | void PwMDoc::sync_save() | 3140 | void PwMDoc::sync_save() |
2863 | { | 3141 | { |
2864 | PwMerror ret = saveDoc(conf()->confGlobCompression()); | 3142 | saveDoc(conf()->confGlobCompression()); |
2865 | } | 3143 | } |
2866 | |||
2867 | #endif | 3144 | #endif |
2868 | 3145 | ||
2869 | 3146 | ||
3147 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | ||
3148 | { | ||
3149 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | ||
3150 | end = dti.syncDta.end(); | ||
3151 | |||
3152 | while (i != end) { | ||
3153 | if ((*i).syncName == syncname.latin1()) { | ||
3154 | if (index) { | ||
3155 | *index = i - dti.syncDta.begin(); | ||
3156 | } | ||
3157 | return true; | ||
3158 | } | ||
3159 | ++i; | ||
3160 | } | ||
3161 | return false; | ||
3162 | }; | ||
3163 | |||
3164 | /** add new syncdataentry */ | ||
3165 | PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) | ||
3166 | { | ||
3167 | PWM_ASSERT(d); | ||
3168 | |||
3169 | if (isDeepLocked()) { | ||
3170 | PwMerror ret; | ||
3171 | ret = deepLock(false); | ||
3172 | if (ret != e_success) | ||
3173 | return e_lock; | ||
3174 | } | ||
3175 | unsigned int index; | ||
3176 | |||
3177 | const QString tmp = d->syncName.c_str(); | ||
3178 | bool exists = findSyncData(d->syncName.c_str(), &index); | ||
3179 | |||
3180 | if (exists == true) { | ||
3181 | // DOH! We found this entry. | ||
3182 | return e_entryExists; | ||
3183 | } | ||
3184 | |||
3185 | dti.syncDta.push_back(*d); | ||
3186 | |||
3187 | if (!dontFlagDirty) | ||
3188 | flagDirty(); | ||
3189 | return e_success; | ||
3190 | } | ||
3191 | |||
3192 | |||
2870 | 3193 | ||
3194 | /** delete syncdata entry */ | ||
3195 | bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) | ||
3196 | { | ||
3197 | if (isDeepLocked()) | ||
3198 | return false; | ||
3199 | if (index > dti.syncDta.size() - 1) | ||
3200 | return false; | ||
3201 | |||
3202 | // delete entry | ||
3203 | dti.syncDta.erase(dti.syncDta.begin() + index); | ||
3204 | |||
3205 | if (!dontFlagDirty) | ||
3206 | flagDirty(); | ||
3207 | return true; | ||
3208 | } | ||
3209 | |||
3210 | |||
3211 | PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) | ||
3212 | { | ||
3213 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | ||
3214 | catend = dti.dta.end(); | ||
3215 | |||
3216 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | ||
3217 | |||
3218 | while (catcounter != catend) { | ||
3219 | entrBegin = catcounter->d.begin(); | ||
3220 | entrEnd = catcounter->d.end(); | ||
3221 | entrI = entrBegin; | ||
3222 | while (entrI != entrEnd) { | ||
3223 | if ((*entrI).meta.uniqueid == uid.latin1()) { | ||
3224 | if (category) | ||
3225 | *category = catcounter - dti.dta.begin(); | ||
3226 | if (index) | ||
3227 | *index = entrI - entrBegin; | ||
3228 | |||
3229 | return &(*entrI); | ||
3230 | } | ||
3231 | ++entrI; | ||
3232 | } | ||
3233 | ++catcounter; | ||
3234 | } | ||
3235 | |||
3236 | return 0; | ||
3237 | } | ||
3238 | |||
3239 | QStringList PwMDoc::getIDEntryList() | ||
3240 | { | ||
3241 | QStringList results; | ||
3242 | |||
3243 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | ||
3244 | catend = dti.dta.end(); | ||
3245 | |||
3246 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | ||
3247 | |||
3248 | while (catcounter != catend) { | ||
3249 | entrBegin = catcounter->d.begin(); | ||
3250 | entrEnd = catcounter->d.end(); | ||
3251 | entrI = entrBegin; | ||
3252 | while (entrI != entrEnd) { | ||
3253 | results.append( (*entrI).meta.uniqueid ); | ||
3254 | ++entrI; | ||
3255 | } | ||
3256 | ++catcounter; | ||
3257 | } | ||
3258 | |||
3259 | return results; | ||
3260 | } | ||
2871 | 3261 | ||
2872 | 3262 | ||
2873 | 3263 | ||
2874 | 3264 | ||
2875 | 3265 | ||
2876 | #ifndef PWM_EMBEDDED | 3266 | #ifndef PWM_EMBEDDED |
2877 | #include "pwmdoc.moc" | 3267 | #include "pwmdoc.moc" |
2878 | #endif | 3268 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index ea4d687..91277f6 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -17,708 +17,762 @@ | |||
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef __PWMDOC_H | 20 | #ifndef __PWMDOC_H |
21 | #define __PWMDOC_H | 21 | #define __PWMDOC_H |
22 | 22 | ||
23 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 23 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
24 | 24 | ||
25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
32 | 32 | ||
33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
40 | 40 | ||
41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
44 | 44 | ||
45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
47 | 47 | ||
48 | 48 | ||
49 | #include "pwmexception.h" | 49 | #include "pwmexception.h" |
50 | #include "pwmdocui.h" | 50 | #include "pwmdocui.h" |
51 | 51 | ||
52 | #include <qobject.h> | 52 | #include <qobject.h> |
53 | #include <qtimer.h> | 53 | #include <qtimer.h> |
54 | #include <qdatetime.h> | 54 | #include <qdatetime.h> |
55 | 55 | ||
56 | #include <kprocess.h> | 56 | #include <kprocess.h> |
57 | 57 | ||
58 | #ifndef PWM_EMBEDDED | 58 | #ifndef PWM_EMBEDDED |
59 | #include "configuration.h" | 59 | #include "configuration.h" |
60 | #else | 60 | #else |
61 | #include <kapplication.h> | 61 | #include <kapplication.h> |
62 | #include <ksyncmanager.h> | 62 | #include <ksyncmanager.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #include <string> | 65 | #include <string> |
66 | #include <vector> | 66 | #include <vector> |
67 | #include <utility> | 67 | #include <utility> |
68 | 68 | ||
69 | using std::vector; | 69 | using std::vector; |
70 | using std::string; | 70 | using std::string; |
71 | using std::pair; | 71 | using std::pair; |
72 | 72 | ||
73 | /* used in findEntry() function */ | 73 | /* used in findEntry() function */ |
74 | #define SEARCH_IN_DESC (1) | 74 | #define SEARCH_IN_DESC (1) |
75 | #define SEARCH_IN_NAME (1 << 1) | 75 | #define SEARCH_IN_NAME (1 << 1) |
76 | #define SEARCH_IN_PW (1 << 2) | 76 | #define SEARCH_IN_PW (1 << 2) |
77 | #define SEARCH_IN_COMMENT(1 << 3) | 77 | #define SEARCH_IN_COMMENT(1 << 3) |
78 | #define SEARCH_IN_URL (1 << 4) | 78 | #define SEARCH_IN_URL (1 << 4) |
79 | #define SEARCH_IN_LAUNCHER(1 << 5) | 79 | #define SEARCH_IN_LAUNCHER(1 << 5) |
80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 80 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 81 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 82 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
83 | 83 | ||
84 | /** document deeplocked. Data is out for lunch to disk */ | 84 | /** document deeplocked. Data is out for lunch to disk */ |
85 | #define DOC_STAT_DEEPLOCKED (1) | 85 | #define DOC_STAT_DEEPLOCKED (1) |
86 | /** encrypted document on disk is dirty. data has to go to disk. */ | 86 | /** encrypted document on disk is dirty. data has to go to disk. */ |
87 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 87 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
88 | /** we are using a chipcard to encrypt the data */ | 88 | /** we are using a chipcard to encrypt the data */ |
89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 89 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 90 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 91 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
92 | 92 | ||
93 | class PwMDoc; | 93 | class PwMDoc; |
94 | class PwMView; | 94 | class PwMView; |
95 | class QFile; | 95 | class QFile; |
96 | 96 | ||
97 | /* meta data for a PwMDataItem */ | 97 | /* meta data for a PwMDataItem */ |
98 | struct PwMMetaData | 98 | struct PwMMetaData |
99 | { | 99 | { |
100 | PwMMetaData() | 100 | PwMMetaData() |
101 | : updateInt (0) | 101 | : updateInt (0) |
102 | { } | 102 | { } |
103 | /** creation date of the PwMDataItem to which | 103 | /** creation date of the PwMDataItem to which |
104 | * this meta data belongs. | 104 | * this meta data belongs. |
105 | */ | 105 | */ |
106 | QDateTimecreate; | 106 | QDateTimecreate; |
107 | /** becomes valid on this date */ | 107 | /** becomes valid on this date */ |
108 | QDateTimevalid; | 108 | QDateTimevalid; |
109 | /** expire date */ | 109 | /** expire date */ |
110 | QDateTimeexpire; | 110 | QDateTimeexpire; |
111 | /** update date (last updated at this date) */ | 111 | /** update date (last updated at this date) */ |
112 | QDateTimeupdate; | 112 | QDateTimeupdate; |
113 | /** update interval (in minutes). Time since the | 113 | /** update interval (in minutes). Time since the |
114 | * last update to remind the user to update the item. | 114 | * last update to remind the user to update the item. |
115 | * 0 disables. | 115 | * 0 disables. |
116 | */ | 116 | */ |
117 | unsigned long updateInt; | 117 | unsigned long updateInt; |
118 | 118 | ||
119 | //US ENH: enhancements of the filestructure | 119 | //US ENH: enhancements of the filestructure |
120 | /* each entry gets a unique id assigned */ | 120 | /* each entry gets a unique id assigned */ |
121 | QString uniqueid; | 121 | QString uniqueid; |
122 | 122 | ||
123 | 123 | ||
124 | void clear() | 124 | void clear() |
125 | { | 125 | { |
126 | create = QDateTime(); | 126 | create = QDateTime(); |
127 | expire = QDateTime(); | 127 | expire = QDateTime(); |
128 | update = QDateTime(); | 128 | update = QDateTime(); |
129 | updateInt = 0; | 129 | updateInt = 0; |
130 | uniqueid = KApplication::randomString(8); | 130 | uniqueid = KApplication::randomString(8); |
131 | } | 131 | } |
132 | inline bool isValid() const | 132 | inline bool isValid() const |
133 | { | 133 | { |
134 | if (valid.isNull()) | 134 | if (valid.isNull()) |
135 | return true; | 135 | return true; |
136 | return (valid < QDateTime::currentDateTime()); | 136 | return (valid < QDateTime::currentDateTime()); |
137 | } | 137 | } |
138 | inline bool isExpired() const | 138 | inline bool isExpired() const |
139 | { | 139 | { |
140 | if (expire.isNull()) | 140 | if (expire.isNull()) |
141 | return false; | 141 | return false; |
142 | return (expire < QDateTime::currentDateTime()); | 142 | return (expire < QDateTime::currentDateTime()); |
143 | } | 143 | } |
144 | inline bool isUpdateIntOver() const | 144 | inline bool isUpdateIntOver() const |
145 | { | 145 | { |
146 | if (updateInt == 0 || | 146 | if (updateInt == 0 || |
147 | update.isNull()) | 147 | update.isNull()) |
148 | return false; | 148 | return false; |
149 | QDateTime d(update); | 149 | QDateTime d(update); |
150 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 150 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
151 | } | 151 | } |
152 | }; | 152 | }; |
153 | 153 | ||
154 | struct PwMDataItem | 154 | struct PwMDataItem |
155 | { | 155 | { |
156 | PwMDataItem() | 156 | PwMDataItem() |
157 | : lockStat (true) | 157 | : lockStat (true) |
158 | , listViewPos (-1) | 158 | , listViewPos (-1) |
159 | , binary (false) | 159 | , binary (false) |
160 | , rev (0) | 160 | , rev (0) |
161 | { } | 161 | { } |
162 | 162 | ||
163 | /** password description */ | 163 | /** password description */ |
164 | stringdesc; | 164 | stringdesc; |
165 | /** user-name */ | 165 | /** user-name */ |
166 | stringname; | 166 | stringname; |
167 | /** the password itself */ | 167 | /** the password itself */ |
168 | stringpw; | 168 | stringpw; |
169 | /** some comment */ | 169 | /** some comment */ |
170 | stringcomment; | 170 | stringcomment; |
171 | /** an URL string */ | 171 | /** an URL string */ |
172 | stringurl; | 172 | stringurl; |
173 | /** launcher. Can be executed as a system() command */ | 173 | /** launcher. Can be executed as a system() command */ |
174 | stringlauncher; | 174 | stringlauncher; |
175 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 175 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
176 | boollockStat; | 176 | boollockStat; |
177 | /** position of this item in main "list-view" | 177 | /** position of this item in main "list-view" |
178 | * If -1, the position is not yet specified and should be appended to the list | 178 | * If -1, the position is not yet specified and should be appended to the list |
179 | */ | 179 | */ |
180 | intlistViewPos; | 180 | intlistViewPos; |
181 | /** does this entry contain binary data? */ | 181 | /** does this entry contain binary data? */ |
182 | bool binary; | 182 | bool binary; |
183 | /** meta data for this data item. */ | 183 | /** meta data for this data item. */ |
184 | PwMMetaData meta; | 184 | PwMMetaData meta; |
185 | /** data revision counter. This counter can be used | 185 | /** data revision counter. This counter can be used |
186 | * to easily, efficiently determine if this data item | 186 | * to easily, efficiently determine if this data item |
187 | * has changed since some time. | 187 | * has changed since some time. |
188 | * This counter is incremented on every update. | 188 | * This counter is incremented on every update. |
189 | */ | 189 | */ |
190 | unsigned int rev; | 190 | unsigned int rev; |
191 | 191 | ||
192 | void clear(bool clearMeta = true) | 192 | void clear(bool clearMeta = true) |
193 | { | 193 | { |
194 | /* NOTE: Don't use .clear() here to be | 194 | /* NOTE: Don't use .clear() here to be |
195 | * backward compatible with gcc-2 (Debian Woody) | 195 | * backward compatible with gcc-2 (Debian Woody) |
196 | */ | 196 | */ |
197 | desc = ""; | 197 | desc = ""; |
198 | name = ""; | 198 | name = ""; |
199 | pw = ""; | 199 | pw = ""; |
200 | comment = ""; | 200 | comment = ""; |
201 | url = ""; | 201 | url = ""; |
202 | launcher = ""; | 202 | launcher = ""; |
203 | lockStat = true; | 203 | lockStat = true; |
204 | listViewPos = -1; | 204 | listViewPos = -1; |
205 | binary = false; | 205 | binary = false; |
206 | if (clearMeta) | 206 | if (clearMeta) |
207 | meta.clear(); | 207 | meta.clear(); |
208 | } | 208 | } |
209 | |||
209 | }; | 210 | }; |
210 | 211 | ||
211 | struct PwMCategoryItem | 212 | struct PwMCategoryItem |
212 | { | 213 | { |
213 | /** all PwMDataItems (all passwords) within this category */ | 214 | /** all PwMDataItems (all passwords) within this category */ |
214 | vector<PwMDataItem>d; | 215 | vector<PwMDataItem>d; |
215 | /** category name/description */ | 216 | /** category name/description */ |
216 | string name; | 217 | string name; |
217 | 218 | ||
218 | void clear() | 219 | void clear() |
219 | { | 220 | { |
220 | d.clear(); | 221 | d.clear(); |
221 | name = ""; | 222 | name = ""; |
222 | } | 223 | } |
223 | }; | 224 | }; |
224 | 225 | ||
226 | struct PwMSyncItem | ||
227 | { | ||
228 | string syncName; | ||
229 | QDateTime lastSyncDate; | ||
230 | |||
231 | void clear() | ||
232 | { | ||
233 | lastSyncDate = QDateTime(); | ||
234 | syncName = ""; | ||
235 | } | ||
236 | }; | ||
237 | |||
238 | struct PwMItem | ||
239 | { | ||
240 | vector<PwMCategoryItem> dta; | ||
241 | vector<PwMSyncItem> syncDta; | ||
242 | |||
243 | void clear() | ||
244 | { | ||
245 | dta.clear(); | ||
246 | syncDta.clear(); | ||
247 | } | ||
248 | }; | ||
249 | |||
250 | |||
225 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 251 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
226 | class dta_lvp_greater | 252 | class dta_lvp_greater |
227 | { | 253 | { |
228 | public: | 254 | public: |
229 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 255 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
230 | const pair<unsigned int, unsigned int> &d2) | 256 | const pair<unsigned int, unsigned int> &d2) |
231 | { | 257 | { |
232 | return d1.second > d2.second; | 258 | return d1.second > d2.second; |
233 | } | 259 | } |
234 | }; | 260 | }; |
235 | 261 | ||
236 | /** list of PwMDoc documents and it's IDs */ | 262 | /** list of PwMDoc documents and it's IDs */ |
237 | class PwMDocList | 263 | class PwMDocList |
238 | { | 264 | { |
239 | public: | 265 | public: |
240 | struct listItem | 266 | struct listItem |
241 | { | 267 | { |
242 | /** document filename (known as ID, here) */ | 268 | /** document filename (known as ID, here) */ |
243 | string docId; | 269 | string docId; |
244 | /** pointer to the document class */ | 270 | /** pointer to the document class */ |
245 | PwMDoc *doc; | 271 | PwMDoc *doc; |
246 | }; | 272 | }; |
247 | 273 | ||
248 | PwMDocList() {} | 274 | PwMDocList() {} |
249 | 275 | ||
250 | /** add a new item to the list */ | 276 | /** add a new item to the list */ |
251 | void add(PwMDoc *doc, const string &id); | 277 | void add(PwMDoc *doc, const string &id); |
252 | /** changes the contents of an existing item */ | 278 | /** changes the contents of an existing item */ |
253 | void edit(PwMDoc *doc, const string &newId); | 279 | void edit(PwMDoc *doc, const string &newId); |
254 | /** remove the given item */ | 280 | /** remove the given item */ |
255 | void del(PwMDoc *doc); | 281 | void del(PwMDoc *doc); |
256 | /** get the item at index */ | 282 | /** get the item at index */ |
257 | listItem getAt(int index) | 283 | listItem getAt(int index) |
258 | { return docList[index]; } | 284 | { return docList[index]; } |
259 | /** find an entry with this id */ | 285 | /** find an entry with this id */ |
260 | bool find(const string &id, listItem *ret = 0); | 286 | bool find(const string &id, listItem *ret = 0); |
261 | /** returns a copy of the list */ | 287 | /** returns a copy of the list */ |
262 | const vector<listItem>* getList() const | 288 | const vector<listItem>* getList() const |
263 | { return &docList; } | 289 | { return &docList; } |
264 | 290 | ||
265 | 291 | ||
266 | /** returns a new unique number to extend the name of | 292 | /** returns a new unique number to extend the name of |
267 | * an unnamed document. | 293 | * an unnamed document. |
268 | */ | 294 | */ |
269 | static unsigned int getNewUnnamedNumber() | 295 | static unsigned int getNewUnnamedNumber() |
270 | { return unnamedDocCnt++; } | 296 | { return unnamedDocCnt++; } |
271 | 297 | ||
272 | protected: | 298 | protected: |
273 | /* Hm, I think we shouldn't really use a "list" here, should we? | 299 | /* Hm, I think we shouldn't really use a "list" here, should we? |
274 | * So I decided to actually use a vector. | 300 | * So I decided to actually use a vector. |
275 | */ | 301 | */ |
276 | vector<listItem> docList; | 302 | vector<listItem> docList; |
277 | /** This value is used to get a new number for yet unnamed | 303 | /** This value is used to get a new number for yet unnamed |
278 | * documents. It is incremented on every request. So it's | 304 | * documents. It is incremented on every request. So it's |
279 | * theoretically possible to overflow it, but... :) | 305 | * theoretically possible to overflow it, but... :) |
280 | */ | 306 | */ |
281 | static unsigned int unnamedDocCnt; | 307 | static unsigned int unnamedDocCnt; |
282 | }; | 308 | }; |
283 | 309 | ||
284 | /** implements timers for the document */ | 310 | /** implements timers for the document */ |
285 | class DocTimer : public QObject | 311 | class DocTimer : public QObject |
286 | { | 312 | { |
287 | Q_OBJECT | 313 | Q_OBJECT |
288 | public: | 314 | public: |
289 | enum TimerIDs | 315 | enum TimerIDs |
290 | { | 316 | { |
291 | id_mpwTimer, | 317 | id_mpwTimer, |
292 | id_autoLockTimer, | 318 | id_autoLockTimer, |
293 | id_metaCheckTimer | 319 | id_metaCheckTimer |
294 | }; | 320 | }; |
295 | 321 | ||
296 | public: | 322 | public: |
297 | DocTimer(PwMDoc *_doc); | 323 | DocTimer(PwMDoc *_doc); |
298 | ~DocTimer(); | 324 | ~DocTimer(); |
299 | 325 | ||
300 | /** start the timer */ | 326 | /** start the timer */ |
301 | void start(TimerIDs timer); | 327 | void start(TimerIDs timer); |
302 | /** stop the timer */ | 328 | /** stop the timer */ |
303 | void stop(TimerIDs timer); | 329 | void stop(TimerIDs timer); |
304 | /** get the lock for a timer. | 330 | /** get the lock for a timer. |
305 | * This lock is a recursive lock. When a lock is | 331 | * This lock is a recursive lock. When a lock is |
306 | * held, the timer will be stopped and timeout is | 332 | * held, the timer will be stopped and timeout is |
307 | * guaranteed to not happen | 333 | * guaranteed to not happen |
308 | */ | 334 | */ |
309 | void getLock(TimerIDs timer); | 335 | void getLock(TimerIDs timer); |
310 | /** put a recursive timer lock */ | 336 | /** put a recursive timer lock */ |
311 | void putLock(TimerIDs timer); | 337 | void putLock(TimerIDs timer); |
312 | 338 | ||
313 | protected slots: | 339 | protected slots: |
314 | /** timeout slot for the mpw timer */ | 340 | /** timeout slot for the mpw timer */ |
315 | void mpwTimeout(); | 341 | void mpwTimeout(); |
316 | /** timeout slot for the autoLock timer */ | 342 | /** timeout slot for the autoLock timer */ |
317 | void autoLockTimeout(); | 343 | void autoLockTimeout(); |
318 | /** timeout slot for the metaCheck timer */ | 344 | /** timeout slot for the metaCheck timer */ |
319 | void metaCheckTimeout(); | 345 | void metaCheckTimeout(); |
320 | 346 | ||
321 | protected: | 347 | protected: |
322 | /** pointer to the document associated with this timer. */ | 348 | /** pointer to the document associated with this timer. */ |
323 | PwMDoc *doc; | 349 | PwMDoc *doc; |
324 | /** timer object for mpw timer */ | 350 | /** timer object for mpw timer */ |
325 | QTimer *mpwTimer; | 351 | QTimer *mpwTimer; |
326 | /** timer object for the autoLock timer */ | 352 | /** timer object for the autoLock timer */ |
327 | QTimer *autoLockTimer; | 353 | QTimer *autoLockTimer; |
328 | /** timer object for the metaCheck timer */ | 354 | /** timer object for the metaCheck timer */ |
329 | QTimer *metaCheckTimer; | 355 | QTimer *metaCheckTimer; |
330 | /** lock counter for the mpw timer */ | 356 | /** lock counter for the mpw timer */ |
331 | unsigned int mpwLock; | 357 | unsigned int mpwLock; |
332 | /** lock counter for the autoLock timer */ | 358 | /** lock counter for the autoLock timer */ |
333 | unsigned int autoLockLock; | 359 | unsigned int autoLockLock; |
334 | /** lock counter for the metaCheck timer */ | 360 | /** lock counter for the metaCheck timer */ |
335 | unsigned int metaCheckLock; | 361 | unsigned int metaCheckLock; |
336 | }; | 362 | }; |
337 | 363 | ||
338 | /** Document class for PwM */ | 364 | /** Document class for PwM */ |
339 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. | 365 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. |
340 | // But PwMDoc is handling the sync by itself. | 366 | // But PwMDoc is handling the sync by itself. |
341 | class PwMDoc : public PwMDocUi, public KSyncInterface | 367 | class PwMDoc : public PwMDocUi, public KSyncInterface |
342 | 368 | ||
343 | { | 369 | { |
344 | Q_OBJECT | 370 | Q_OBJECT |
345 | friend class DocTimer; | 371 | friend class DocTimer; |
346 | 372 | ||
347 | public: | 373 | public: |
348 | /** construtor */ | 374 | /** construtor */ |
349 | PwMDoc(QObject* parent = 0, const char *name = 0); | 375 | PwMDoc(QObject* parent = 0, const char *name = 0); |
350 | /** destructor */ | 376 | /** destructor */ |
351 | ~PwMDoc(); | 377 | ~PwMDoc(); |
352 | 378 | ||
353 | /** returns a pointer to a list of all open documents */ | 379 | /** returns a pointer to a list of all open documents */ |
354 | static PwMDocList* getOpenDocList() | 380 | static PwMDocList* getOpenDocList() |
355 | { return &openDocList; } | 381 | { return &openDocList; } |
356 | 382 | ||
357 | /** flag document dirty. dta changed */ | 383 | /** flag document dirty. dta changed */ |
358 | void flagDirty() | 384 | void flagDirty() |
359 | { | 385 | { |
360 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 386 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
361 | emitDataChanged(this); | 387 | emitDataChanged(this); |
362 | } | 388 | } |
363 | /** modified? */ | 389 | /** modified? */ |
364 | bool isDirty() | 390 | bool isDirty() |
365 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 391 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
366 | /** save document to disk */ | 392 | /** save document to disk */ |
367 | PwMerror saveDoc(char compress, const QString *file = 0); | 393 | PwMerror saveDoc(char compress, const QString *file = 0); |
368 | /** read document from file. | 394 | /** read document from file. |
369 | * "openLocked is must be set to either of these values: | 395 | * "openLocked is must be set to either of these values: |
370 | * 0 == open with all entries unlocked | 396 | * 0 == open with all entries unlocked |
371 | * 1 == open with all entries locked | 397 | * 1 == open with all entries locked |
372 | * 2 == open deep-locked | 398 | * 2 == open deep-locked |
373 | */ | 399 | */ |
374 | PwMerror openDoc(const QString *file, int openLocked); | 400 | PwMerror openDoc(const QString *file, int openLocked); |
375 | /** export document to ascii-textfile */ | 401 | /** export document to ascii-textfile */ |
376 | PwMerror exportToText(const QString *file); | 402 | PwMerror exportToText(const QString *file); |
377 | /** export document to gpasman / kpasman file */ | 403 | /** export document to gpasman / kpasman file */ |
378 | PwMerror exportToGpasman(const QString *file); | 404 | PwMerror exportToGpasman(const QString *file); |
379 | /** import document from ascii-textfile */ | 405 | /** import document from ascii-textfile */ |
380 | PwMerror importFromText(const QString *file, int format = -1); | 406 | PwMerror importFromText(const QString *file, int format = -1); |
381 | /** import document from gpasman / kpasman file */ | 407 | /** import document from gpasman / kpasman file */ |
382 | PwMerror importFromGpasman(const QString *file); | 408 | PwMerror importFromGpasman(const QString *file); |
383 | /** add new entry */ | 409 | /** add new entry */ |
384 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 410 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
385 | bool dontFlagDirty = false, bool updateMeta = true); | 411 | bool dontFlagDirty = false, bool updateMeta = true); |
386 | /** add new category. This function doesn't flag the document dirty! */ | 412 | /** add new category. This function doesn't flag the document dirty! */ |
387 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 413 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
388 | bool checkIfExist = true); | 414 | bool checkIfExist = true); |
389 | /** rename an existing category */ | 415 | /** rename an existing category */ |
390 | bool renameCategory(const QString &category, const QString &newName); | 416 | bool renameCategory(const QString &category, const QString &newName); |
391 | /** rename an existing category */ | 417 | /** rename an existing category */ |
392 | bool renameCategory(unsigned int category, const QString &newName, | 418 | bool renameCategory(unsigned int category, const QString &newName, |
393 | bool dontFlagDirty = false); | 419 | bool dontFlagDirty = false); |
394 | /** delete an existing category */ | 420 | /** delete an existing category */ |
395 | bool delCategory(const QString &category); | 421 | bool delCategory(const QString &category); |
396 | /** delete an existing category */ | 422 | /** delete an existing category */ |
397 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 423 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
398 | /** returns a list of all category-names */ | 424 | /** returns a list of all category-names */ |
399 | void getCategoryList(vector<string> *list); | 425 | void getCategoryList(vector<string> *list); |
400 | /** returns a list of all category-names */ | 426 | /** returns a list of all category-names */ |
401 | void getCategoryList(QStringList *list); | 427 | void getCategoryList(QStringList *list); |
402 | /** returns a list of all entry-descs in the given category */ | 428 | /** returns a list of all entry-descs in the given category */ |
403 | void getEntryList(const QString &category, QStringList *list); | 429 | void getEntryList(const QString &category, QStringList *list); |
404 | /** returns a list of all entry-descs in the given category */ | 430 | /** returns a list of all entry-descs in the given category */ |
405 | void getEntryList(const QString &category, vector<string> *list); | 431 | void getEntryList(const QString &category, vector<string> *list); |
406 | /** returns a list of all entry-descs in the given category */ | 432 | /** returns a list of all entry-descs in the given category */ |
407 | void getEntryList(unsigned int category, vector<string> *list); | 433 | void getEntryList(unsigned int category, vector<string> *list); |
408 | /** returns a list of all entry-descs in the given category */ | 434 | /** returns a list of all entry-descs in the given category */ |
409 | void getEntryList(unsigned int category, QStringList *list); | 435 | void getEntryList(unsigned int category, QStringList *list); |
410 | /** delete entry */ | 436 | /** delete entry */ |
411 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 437 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
412 | /** delete entry */ | 438 | /** delete entry */ |
413 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 439 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
414 | /** edit entry */ | 440 | /** edit entry */ |
415 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 441 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
416 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 442 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
417 | /** edit entry */ | 443 | /** edit entry */ |
418 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 444 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
419 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 445 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
420 | /** finds the category with the "name" and return it's index */ | 446 | /** finds the category with the "name" and return it's index */ |
421 | bool findCategory(const QString &name, unsigned int *index); | 447 | bool findCategory(const QString &name, unsigned int *index); |
422 | /** search for an entry "find" and check while searching only for | 448 | /** search for an entry "find" and check while searching only for |
423 | * the data-fields specified by "searchIn". To set the "searchIn" | 449 | * the data-fields specified by "searchIn". To set the "searchIn" |
424 | * value, we may use one or more of the SEARCH_IN_* defines at | 450 | * value, we may use one or more of the SEARCH_IN_* defines at |
425 | * the top of this header-file. It returns the positions of all | 451 | * the top of this header-file. It returns the positions of all |
426 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 452 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
427 | * the function terminates after the first occurence of the entry | 453 | * the function terminates after the first occurence of the entry |
428 | * and doesn't go on searching. So foundPositions->size() is never | 454 | * and doesn't go on searching. So foundPositions->size() is never |
429 | * > 1 if breakAfterFound is true. | 455 | * > 1 if breakAfterFound is true. |
430 | */ | 456 | */ |
431 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 457 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
432 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 458 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
433 | bool caseSensitive = true, bool exactWordMatch = true, | 459 | bool caseSensitive = true, bool exactWordMatch = true, |
434 | bool sortByLvp = false); | 460 | bool sortByLvp = false); |
435 | /** see the above funtion. This function allows to set the category by name. */ | 461 | /** see the above funtion. This function allows to set the category by name. */ |
436 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 462 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
437 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 463 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
438 | bool caseSensitive = true, bool exactWordMatch = true, | 464 | bool caseSensitive = true, bool exactWordMatch = true, |
439 | bool sortByLvp = false); | 465 | bool sortByLvp = false); |
440 | /** returns number of entries */ | 466 | /** returns number of entries */ |
441 | unsigned int numEntries(const QString &category); | 467 | unsigned int numEntries(const QString &category); |
442 | unsigned int numEntries(unsigned int category) | 468 | unsigned int numEntries(unsigned int category) |
443 | { return dta[category].d.size(); } | 469 | { return dti.dta[category].d.size(); } |
444 | /** returns number of categories */ | 470 | /** returns number of categories */ |
445 | unsigned int numCategories() | 471 | unsigned int numCategories() |
446 | { return dta.size(); } | 472 | { return dti.dta.size(); } |
447 | /** returns the name of the category at "index" */ | 473 | /** returns the name of the category at "index" */ |
448 | const string* getCategory(unsigned int index) | 474 | const string* getCategory(unsigned int index) |
449 | { return (&(dta[index].name)); } | 475 | { return (&(dti.dta[index].name)); } |
476 | |||
450 | /** returns the data of item at "index". | 477 | /** returns the data of item at "index". |
451 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 478 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
452 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 479 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
453 | * the pw. | 480 | * the pw. |
454 | */ | 481 | */ |
455 | bool getEntry(const QString &category, unsigned int index, | 482 | bool getEntry(const QString &category, unsigned int index, |
456 | PwMDataItem *d, bool unlockIfLocked = false); | 483 | PwMDataItem *d, bool unlockIfLocked = false); |
457 | bool getEntry(unsigned int category, unsigned int index, | 484 | bool getEntry(unsigned int category, unsigned int index, |
458 | PwMDataItem *d, bool unlockIfLocked = false); | 485 | PwMDataItem *d, bool unlockIfLocked = false); |
459 | /** returns the comment-string by looking at the category | 486 | /** returns the comment-string by looking at the category |
460 | * and the listViewPos | 487 | * and the listViewPos |
461 | */ | 488 | */ |
462 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 489 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
463 | string *foundComment); | 490 | string *foundComment); |
464 | /** checks if a password is already available. (currentPw) */ | 491 | /** checks if a password is already available. (currentPw) */ |
465 | bool isPwAvailable() | 492 | bool isPwAvailable() |
466 | { return (currentPw != ""); } | 493 | { return (currentPw != ""); } |
467 | /** un/lock entry at "index". If needed, ask for password. */ | 494 | /** un/lock entry at "index". If needed, ask for password. */ |
468 | bool lockAt(const QString &category, unsigned int index, | 495 | bool lockAt(const QString &category, unsigned int index, |
469 | bool lock = true); | 496 | bool lock = true); |
470 | bool lockAt(unsigned int category, unsigned int index, | 497 | bool lockAt(unsigned int category, unsigned int index, |
471 | bool lock = true); | 498 | bool lock = true); |
472 | /** returns the lock-status at "index" */ | 499 | /** returns the lock-status at "index" */ |
473 | bool isLocked(const QString &category, unsigned int index); | 500 | bool isLocked(const QString &category, unsigned int index); |
474 | bool isLocked(unsigned int category, unsigned int index) | 501 | bool isLocked(unsigned int category, unsigned int index) |
475 | { return dta[category].d[index].lockStat; } | 502 | { return dti.dta[category].d[index].lockStat; } |
476 | /** returns the deeplock status */ | 503 | /** returns the deeplock status */ |
477 | bool isDeepLocked() | 504 | bool isDeepLocked() |
478 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 505 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
479 | /** (un)lock all entries */ | 506 | /** (un)lock all entries */ |
480 | bool lockAll(bool lock); | 507 | bool lockAll(bool lock); |
481 | /** unlocks all entries tempoarly. | 508 | /** unlocks all entries tempoarly. |
482 | * 1st NOTE: Be very careful with this function! :) | 509 | * 1st NOTE: Be very careful with this function! :) |
483 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 510 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
484 | * please DON'T forget to call unlockAll_Tempoary(true); | 511 | * please DON'T forget to call unlockAll_Tempoary(true); |
485 | * _before_ the user (or someone else) is able to change | 512 | * _before_ the user (or someone else) is able to change |
486 | * the document! | 513 | * the document! |
487 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 514 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
488 | * unlocked! This will cause corruption. | 515 | * unlocked! This will cause corruption. |
489 | */ | 516 | */ |
490 | bool unlockAll_tempoary(bool revert = false); | 517 | bool unlockAll_tempoary(bool revert = false); |
491 | /** deep-(un)locks the document. | 518 | /** deep-(un)locks the document. |
492 | * deep-locking writes all data to the file, deletes all data | 519 | * deep-locking writes all data to the file, deletes all data |
493 | * in memory, but doesn't close the document. | 520 | * in memory, but doesn't close the document. |
494 | * deep-locking is only available, if the user previously saved | 521 | * deep-locking is only available, if the user previously saved |
495 | * the doc to a file (with a password). | 522 | * the doc to a file (with a password). |
496 | * If "saveToFile" is false, it does NOT write the data to the file! | 523 | * If "saveToFile" is false, it does NOT write the data to the file! |
497 | */ | 524 | */ |
498 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 525 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
499 | /** is unlockable without pw? */ | 526 | /** is unlockable without pw? */ |
500 | bool unlockWoPw() | 527 | bool unlockWoPw() |
501 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 528 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
502 | /** get the "currentPassword" */ | 529 | /** get the "currentPassword" */ |
503 | const QString& getCurrentPw() | 530 | const QString& getCurrentPw() |
504 | { return currentPw; } | 531 | { return currentPw; } |
505 | /** open a window and request the user to change the mpw */ | 532 | /** open a window and request the user to change the mpw */ |
506 | void changeCurrentPw(); | 533 | void changeCurrentPw(); |
507 | /** set the "listViewPos" variable of "dta" */ | 534 | /** set the "listViewPos" variable of "dta" */ |
508 | void setListViewPos(const QString &category, unsigned int index, | 535 | void setListViewPos(const QString &category, unsigned int index, |
509 | int pos); | 536 | int pos); |
510 | /** set the "listViewPos" variable of "dta" */ | 537 | /** set the "listViewPos" variable of "dta" */ |
511 | void setListViewPos(unsigned int category, unsigned int index, | 538 | void setListViewPos(unsigned int category, unsigned int index, |
512 | int pos); | 539 | int pos); |
513 | /** get the "listViewPos" variable of "dta" */ | 540 | /** get the "listViewPos" variable of "dta" */ |
514 | int getListViewPos(const QString &category, unsigned int index); | 541 | int getListViewPos(const QString &category, unsigned int index); |
515 | /** set the maximum number of entries allowed */ | 542 | /** set the maximum number of entries allowed */ |
516 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 543 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
517 | { maxEntries = num; } | 544 | { maxEntries = num; } |
518 | /** get the maximum number of entries allowed */ | 545 | /** get the maximum number of entries allowed */ |
519 | unsigned int getMaxNumEntries() | 546 | unsigned int getMaxNumEntries() |
520 | { return maxEntries; } | 547 | { return maxEntries; } |
521 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 548 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
522 | * If there are some undefined entries, add them to the end of | 549 | * If there are some undefined entries, add them to the end of |
523 | * the listViewPos(itions). */ | 550 | * the listViewPos(itions). */ |
524 | void ensureLvp(); | 551 | void ensureLvp(); |
525 | /** execute the "launcher" of this entry */ | 552 | /** execute the "launcher" of this entry */ |
526 | bool execLauncher(const QString &category, unsigned int entryIndex); | 553 | bool execLauncher(const QString &category, unsigned int entryIndex); |
527 | /** see above */ | 554 | /** see above */ |
528 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 555 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
529 | /** open a browser with the URL-section of the given entry */ | 556 | /** open a browser with the URL-section of the given entry */ |
530 | bool goToURL(const QString &category, unsigned int entryIndex); | 557 | bool goToURL(const QString &category, unsigned int entryIndex); |
531 | /** see above */ | 558 | /** see above */ |
532 | bool goToURL(unsigned int category, unsigned int entryIndex); | 559 | bool goToURL(unsigned int category, unsigned int entryIndex); |
533 | /** returns true if there is no entry present in the document. | 560 | /** returns true if there is no entry present in the document. |
534 | * Note: The "default" Category is present everytime, so | 561 | * Note: The "default" Category is present everytime, so |
535 | * it's checked for it's entries. | 562 | * it's checked for it's entries. |
536 | */ | 563 | */ |
537 | bool isDocEmpty() | 564 | bool isDocEmpty() |
538 | { | 565 | { |
539 | if (numCategories() > 1) | 566 | if (numCategories() > 1) |
540 | return false; | 567 | return false; |
541 | if (numEntries(0)) | 568 | if (numEntries(0)) |
542 | return false; | 569 | return false; |
543 | return true; | 570 | return true; |
544 | } | 571 | } |
545 | /** returns the filename of this doc */ | 572 | /** returns the filename of this doc */ |
546 | const QString& getFilename() | 573 | const QString& getFilename() |
547 | { return filename; } | 574 | { return filename; } |
548 | /** returns the title of the doc */ | 575 | /** returns the title of the doc */ |
549 | QString getTitle(); | 576 | QString getTitle(); |
550 | /** sets the list-view-pointer hold in the doc */ | 577 | /** sets the list-view-pointer hold in the doc */ |
551 | void setListViewPointer(PwMView *_listView) | 578 | void setListViewPointer(PwMView *_listView) |
552 | { listView = _listView; } | 579 | { listView = _listView; } |
553 | /** returns the list-view-pointer */ | 580 | /** returns the list-view-pointer */ |
554 | PwMView * getListViewPointer() | 581 | PwMView * getListViewPointer() |
555 | { return listView; } | 582 | { return listView; } |
556 | /** try to delete the doc. The user may be asked to save | 583 | /** try to delete the doc. The user may be asked to save |
557 | * the data. The user may cancel the whole operation. | 584 | * the data. The user may cancel the whole operation. |
558 | * false is returned, then. | 585 | * false is returned, then. |
559 | */ | 586 | */ |
560 | bool tryDelete(); | 587 | bool tryDelete(); |
561 | /** is the doc deleted? (with tryDelete() ) */ | 588 | /** is the doc deleted? (with tryDelete() ) */ |
562 | bool isDeleted() | 589 | bool isDeleted() |
563 | { return deleted; } | 590 | { return deleted; } |
564 | /** returns the document timer object */ | 591 | /** returns the document timer object */ |
565 | DocTimer * timer() | 592 | DocTimer * timer() |
566 | { return _timer; } | 593 | { return _timer; } |
567 | /** get a lock on the dataChanged signal. | 594 | /** get a lock on the dataChanged signal. |
568 | * If someone is holding a lock, the signal is not emitted. | 595 | * If someone is holding a lock, the signal is not emitted. |
569 | */ | 596 | */ |
570 | void getDataChangedLock() | 597 | void getDataChangedLock() |
571 | { ++dataChangedLock; } | 598 | { ++dataChangedLock; } |
572 | /** put the dataChanged lock */ | 599 | /** put the dataChanged lock */ |
573 | void putDataChangedLock() | 600 | void putDataChangedLock() |
574 | { --dataChangedLock; } | 601 | { --dataChangedLock; } |
575 | /** returns the revision count of the item at cat/index */ | 602 | /** returns the revision count of the item at cat/index */ |
576 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 603 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
577 | { return dta[category].d[index].rev; } | 604 | { return dti.dta[category].d[index].rev; } |
578 | /** returns a const pointer to the entries meta */ | 605 | /** returns a const pointer to the entries meta */ |
579 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 606 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
580 | { return &(dta[category].d[index].meta); } | 607 | { return &(dti.dta[category].d[index].meta); } |
581 | /** is the entry at "category" "index" a binary entry? */ | 608 | /** is the entry at "category" "index" a binary entry? */ |
582 | bool isBinEntry(unsigned int category, unsigned int index) | 609 | bool isBinEntry(unsigned int category, unsigned int index) |
583 | { return dta[category].d[index].binary; } | 610 | { return dti.dta[category].d[index].binary; } |
584 | 611 | ||
585 | public slots: | 612 | public slots: |
586 | /** wrapper for PwMTray */ | 613 | /** wrapper for PwMTray */ |
587 | void _deepUnlock(); | 614 | void _deepUnlock(); |
588 | 615 | ||
589 | signals: | 616 | signals: |
590 | /** the data of the document has changed and must be updated | 617 | /** the data of the document has changed and must be updated |
591 | * in all views. | 618 | * in all views. |
592 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 619 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
593 | */ | 620 | */ |
594 | void dataChanged(PwMDoc *document); | 621 | void dataChanged(PwMDoc *document); |
595 | /** the document class is going to close. This signal may be | 622 | /** the document class is going to close. This signal may be |
596 | * used to nofify all views, that the user closed the document, | 623 | * used to nofify all views, that the user closed the document, |
597 | * so the views can go down, too. | 624 | * so the views can go down, too. |
598 | */ | 625 | */ |
599 | void docClosed(PwMDoc *document); | 626 | void docClosed(PwMDoc *document); |
600 | /** somebody just opened the document */ | 627 | /** somebody just opened the document */ |
601 | void docOpened(PwMDoc *document); | 628 | void docOpened(PwMDoc *document); |
602 | /** this document object just got created */ | 629 | /** this document object just got created */ |
603 | void docCreated(PwMDoc *document); | 630 | void docCreated(PwMDoc *document); |
604 | 631 | ||
605 | public: | 632 | public: |
606 | /** emit the dataChanged signal after checking for a lock */ | 633 | /** emit the dataChanged signal after checking for a lock */ |
607 | void emitDataChanged(PwMDoc *document) | 634 | void emitDataChanged(PwMDoc *document) |
608 | { | 635 | { |
609 | if (!dataChangedLock) | 636 | if (!dataChangedLock) |
610 | emit dataChanged(document); | 637 | emit dataChanged(document); |
611 | } | 638 | } |
612 | 639 | ||
613 | protected: | 640 | protected: |
614 | /** current file for this doc */ | 641 | /** current file for this doc */ |
615 | QString filename; | 642 | QString filename; |
643 | //US ENH: we need a place where we keep the syncentries. So I invented | ||
644 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | ||
616 | /** holds all data */ | 645 | /** holds all data */ |
617 | vector<PwMCategoryItem> dta; | 646 | PwMItem dti; |
618 | /** maximum number of entries */ | 647 | /** maximum number of entries */ |
619 | unsigned int maxEntries; | 648 | unsigned int maxEntries; |
620 | /** currently used password to encrypt data */ | 649 | /** currently used password to encrypt data */ |
621 | QString currentPw; | 650 | QString currentPw; |
622 | /** current global document status flags */ | 651 | /** current global document status flags */ |
623 | unsigned int curDocStat; | 652 | unsigned int curDocStat; |
624 | /** browser process for goToURL() */ | 653 | /** browser process for goToURL() */ |
625 | KProcess browserProc; | 654 | KProcess browserProc; |
626 | /** pointer to the list-view, using this document. | 655 | /** pointer to the list-view, using this document. |
627 | * As there can only be one list-view per doc, we | 656 | * As there can only be one list-view per doc, we |
628 | * don't need a list here. | 657 | * don't need a list here. |
629 | */ | 658 | */ |
630 | PwMView *listView; | 659 | PwMView *listView; |
631 | /** unnamedNum is used to store the "unnamed counter" | 660 | /** unnamedNum is used to store the "unnamed counter" |
632 | * for this document, while it's unnamed. If it's 0, | 661 | * for this document, while it's unnamed. If it's 0, |
633 | * we have to get a new unique one. | 662 | * we have to get a new unique one. |
634 | */ | 663 | */ |
635 | unsigned int unnamedNum; | 664 | unsigned int unnamedNum; |
636 | /** is this doc going to be deleted (executing in destructor context) */ | 665 | /** is this doc going to be deleted (executing in destructor context) */ |
637 | bool deleted; | 666 | bool deleted; |
638 | /** document timer */ | 667 | /** document timer */ |
639 | DocTimer *_timer; | 668 | DocTimer *_timer; |
640 | /** lock counter for the "dataChanged" signal */ | 669 | /** lock counter for the "dataChanged" signal */ |
641 | unsigned int dataChangedLock; | 670 | unsigned int dataChangedLock; |
642 | 671 | ||
643 | /** list of all open documents */ | 672 | /** list of all open documents */ |
644 | static PwMDocList openDocList; | 673 | static PwMDocList openDocList; |
645 | 674 | ||
646 | protected: | 675 | protected: |
647 | /** serialize "dta" and return it in "d". */ | 676 | /** serialize "dta" and return it in "d". */ |
648 | bool serializeDta(string *d); | 677 | bool serializeDta(string *d); |
649 | /** de-serialize "d" and overwrite "dta" */ | 678 | /** de-serialize "d" and overwrite "dta" */ |
650 | bool deSerializeDta(const string *d, bool entriesLocked); | 679 | bool deSerializeDta(const string *d, bool entriesLocked); |
651 | /** write header to file */ | 680 | /** write header to file */ |
652 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 681 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
653 | QString *pw, QFile *f); | 682 | QString *pw, QFile *f); |
654 | /** write data-hash to file */ | 683 | /** write data-hash to file */ |
655 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 684 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
656 | /** check header. Read header info and verify key-hash and filever. | 685 | /** check header. Read header info and verify key-hash and filever. |
657 | * returns length of header in "headerLength" */ | 686 | * returns length of header in "headerLength" */ |
658 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 687 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
659 | unsigned int *headerLength, char *dataHashType, | 688 | unsigned int *headerLength, char *dataHashType, |
660 | string *dataHash, QFile *f); | 689 | string *dataHash, QFile *f); |
661 | /** check the data-hash */ | 690 | /** check the data-hash */ |
662 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 691 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
663 | /** encrypt data "d" and write to "filename" */ | 692 | /** encrypt data "d" and write to "filename" */ |
664 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 693 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
665 | /** read data from file beginning at "pos", decrypt and return it */ | 694 | /** read data from file beginning at "pos", decrypt and return it */ |
666 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); | 695 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); |
667 | /** compress the data */ | 696 | /** compress the data */ |
668 | bool compressDta(string *d, char algo); | 697 | bool compressDta(string *d, char algo); |
669 | /** uncompress the data */ | 698 | /** uncompress the data */ |
670 | bool decompressDta(string *d, char algo); | 699 | bool decompressDta(string *d, char algo); |
671 | /** internal import function for a text-file generated by PwM. | 700 | /** internal import function for a text-file generated by PwM. |
672 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 701 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
673 | PwMerror importText_PwM(const QString *file); | 702 | PwMerror importText_PwM(const QString *file); |
674 | /** PwM-text-import helper function to extract the name/pw/comment out | 703 | /** PwM-text-import helper function to extract the name/pw/comment out |
675 | * of one entry-line */ | 704 | * of one entry-line */ |
676 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 705 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
677 | /** compare two strings */ | 706 | /** compare two strings */ |
678 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 707 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
679 | bool exactWordMatch); | 708 | bool exactWordMatch); |
680 | /** clears all document-data */ | 709 | /** clears all document-data */ |
681 | void clearDoc(); | 710 | void clearDoc(); |
682 | /** delete all empty categories */ | 711 | /** delete all empty categories */ |
683 | void delAllEmptyCat(bool dontFlagDirty); | 712 | void delAllEmptyCat(bool dontFlagDirty); |
684 | /** set a document status flag */ | 713 | /** set a document status flag */ |
685 | void setDocStatFlag(unsigned int statFlag) | 714 | void setDocStatFlag(unsigned int statFlag) |
686 | { curDocStat |= statFlag; } | 715 | { curDocStat |= statFlag; } |
687 | /** unset a document status flag */ | 716 | /** unset a document status flag */ |
688 | void unsetDocStatFlag(unsigned int statFlag) | 717 | void unsetDocStatFlag(unsigned int statFlag) |
689 | { curDocStat &= ~statFlag; } | 718 | { curDocStat &= ~statFlag; } |
690 | /** get a document status flag */ | 719 | /** get a document status flag */ |
691 | bool getDocStatFlag(unsigned int statFlag) const | 720 | bool getDocStatFlag(unsigned int statFlag) const |
692 | { return (curDocStat & statFlag); } | 721 | { return (curDocStat & statFlag); } |
693 | /** set the "currentPassword" */ | 722 | /** set the "currentPassword" */ |
694 | void setCurrentPw(const QString &pw) | 723 | void setCurrentPw(const QString &pw) |
695 | { | 724 | { |
696 | currentPw = pw; | 725 | currentPw = pw; |
697 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 726 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
698 | } | 727 | } |
699 | /** make a backup-copy of the given file */ | 728 | /** make a backup-copy of the given file */ |
700 | bool backupFile(const QString &filePath); | 729 | bool backupFile(const QString &filePath); |
701 | /** copy a file from src to dst */ | 730 | /** copy a file from src to dst */ |
702 | bool copyFile(const QString &src, const QString &dst); | 731 | bool copyFile(const QString &src, const QString &dst); |
703 | 732 | ||
704 | 733 | ||
705 | public: | 734 | public: |
706 | #ifdef PWM_EMBEDDED | 735 | #ifdef PWM_EMBEDDED |
707 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 736 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
708 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 737 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
709 | 738 | ||
739 | //takePwMDataItem returns the following values | ||
740 | // 0 equal | ||
741 | // 1 take local | ||
742 | // 2 take remote | ||
743 | // 3 cancel | ||
744 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | ||
710 | 745 | ||
711 | //the following methods are the overwritten callbackmethods from the syncinterface | 746 | //the following methods are the overwritten callbackmethods from the syncinterface |
712 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 747 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
713 | 748 | ||
714 | //called by the syncmanager to indicate that the work has to be marked as dirty. | 749 | //called by the syncmanager to indicate that the work has to be marked as dirty. |
715 | virtual void sync_setModified(); | 750 | virtual void sync_setModified(); |
716 | //called by the syncmanager to ask if the dirty flag is set. | 751 | //called by the syncmanager to ask if the dirty flag is set. |
717 | virtual bool sync_isModified(); | 752 | virtual bool sync_isModified(); |
718 | //called by the syncmanager to indicate that the work has to be saved. | 753 | //called by the syncmanager to indicate that the work has to be saved. |
719 | virtual void sync_save(); | 754 | virtual void sync_save(); |
755 | |||
720 | #endif | 756 | #endif |
757 | private: | ||
758 | //US ENH: helpermethods to access the sync data for a certain syncname. | ||
759 | // It returns the syncdatas index | ||
760 | bool findSyncData(const QString &syncname, unsigned int *index); | ||
761 | |||
762 | /** add new syncdataentry */ | ||
763 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | ||
764 | |||
765 | /** returns a pointer to the syncdata */ | ||
766 | PwMSyncItem* getSyncDataEntry(unsigned int index) | ||
767 | { return &(dti.syncDta[index]); } | ||
768 | |||
769 | /** delete entry */ | ||
770 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | ||
771 | |||
772 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | ||
773 | |||
774 | QStringList getIDEntryList(); | ||
721 | 775 | ||
722 | }; | 776 | }; |
723 | 777 | ||
724 | #endif | 778 | #endif |
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp index 5e675fc..41afa6a 100644 --- a/pwmanager/pwmanager/pwmdocui.cpp +++ b/pwmanager/pwmanager/pwmdocui.cpp | |||
@@ -87,371 +87,371 @@ QString PwMDocUi::requestMpw(bool chipcard) | |||
87 | #endif | 87 | #endif |
88 | if (pwWnd.exec() != 1) | 88 | if (pwWnd.exec() != 1) |
89 | return ""; | 89 | return ""; |
90 | pw = pwWnd.pwLineEdit->text(); | 90 | pw = pwWnd.pwLineEdit->text(); |
91 | } | 91 | } |
92 | 92 | ||
93 | return pw; | 93 | return pw; |
94 | } | 94 | } |
95 | 95 | ||
96 | QString PwMDocUi::requestNewMpw(bool *chipcard) | 96 | QString PwMDocUi::requestNewMpw(bool *chipcard) |
97 | { | 97 | { |
98 | QString pw; | 98 | QString pw; |
99 | SetMasterPwWndImpl pwWnd(currentView); | 99 | SetMasterPwWndImpl pwWnd(currentView); |
100 | pwWnd.setPwMKeyCard(keyCard); | 100 | pwWnd.setPwMKeyCard(keyCard); |
101 | if (!chipcard) { | 101 | if (!chipcard) { |
102 | #ifndef PWM_EMBEDDED | 102 | #ifndef PWM_EMBEDDED |
103 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); | 103 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); |
104 | #else | 104 | #else |
105 | pwWnd.mainTab->removePage(pwWnd.tab_2); | 105 | pwWnd.mainTab->removePage(pwWnd.tab_2); |
106 | #endif | 106 | #endif |
107 | } | 107 | } |
108 | 108 | ||
109 | if (pwWnd.exec() != 1) | 109 | if (pwWnd.exec() != 1) |
110 | return ""; | 110 | return ""; |
111 | pw = pwWnd.getPw(chipcard).c_str(); | 111 | pw = pwWnd.getPw(chipcard).c_str(); |
112 | 112 | ||
113 | return pw; | 113 | return pw; |
114 | } | 114 | } |
115 | 115 | ||
116 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) | 116 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) |
117 | { | 117 | { |
118 | QString pw(requestMpw(*chipcard)); | 118 | QString pw(requestMpw(*chipcard)); |
119 | if (pw == "") | 119 | if (pw == "") |
120 | return ""; | 120 | return ""; |
121 | if (pw != *currentPw) { | 121 | if (pw != *currentPw) { |
122 | wrongMpwMsgBox(*chipcard); | 122 | wrongMpwMsgBox(*chipcard); |
123 | return ""; | 123 | return ""; |
124 | } | 124 | } |
125 | 125 | ||
126 | pw = requestNewMpw(chipcard); | 126 | pw = requestNewMpw(chipcard); |
127 | if (pw == "") | 127 | if (pw == "") |
128 | return ""; | 128 | return ""; |
129 | return pw; | 129 | return pw; |
130 | } | 130 | } |
131 | 131 | ||
132 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 132 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
133 | { | 133 | { |
134 | QString msg; | 134 | QString msg; |
135 | if (prefix != "") { | 135 | if (prefix != "") { |
136 | msg += prefix; | 136 | msg += prefix; |
137 | msg += "\n"; | 137 | msg += "\n"; |
138 | } | 138 | } |
139 | 139 | ||
140 | if (chipcard) { | 140 | if (chipcard) { |
141 | msg += i18n("Wrong key-card!\n" | 141 | msg += i18n("Wrong key-card!\n" |
142 | "Please try again with the\n" | 142 | "Please try again with the\n" |
143 | "correct key-card."); | 143 | "correct key-card."); |
144 | } else { | 144 | } else { |
145 | msg += i18n("Wrong master-password!\n" | 145 | msg += i18n("Wrong master-password!\n" |
146 | "Please try again."); | 146 | "Please try again."); |
147 | } | 147 | } |
148 | 148 | ||
149 | if (postfix != "") { | 149 | if (postfix != "") { |
150 | msg += "\n"; | 150 | msg += "\n"; |
151 | msg += postfix; | 151 | msg += postfix; |
152 | } | 152 | } |
153 | KMessageBox::error(currentView, msg, | 153 | KMessageBox::error(currentView, msg, |
154 | (chipcard) ? (i18n("wrong chipcard")) | 154 | (chipcard) ? (i18n("wrong chipcard")) |
155 | : (i18n("password error"))); | 155 | : (i18n("password error"))); |
156 | } | 156 | } |
157 | 157 | ||
158 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 158 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
159 | { | 159 | { |
160 | QString msg; | 160 | QString msg; |
161 | if (prefix != "") { | 161 | if (prefix != "") { |
162 | msg += prefix; | 162 | msg += prefix; |
163 | msg += "\n"; | 163 | msg += "\n"; |
164 | } | 164 | } |
165 | 165 | ||
166 | if (chipcard) { | 166 | if (chipcard) { |
167 | msg += i18n("No key-card found!\n" | 167 | msg += i18n("No key-card found!\n" |
168 | "Please insert the\n" | 168 | "Please insert the\n" |
169 | "correct key-card."); | 169 | "correct key-card."); |
170 | } else { | 170 | } else { |
171 | msg += i18n("No master-password given!"); | 171 | msg += i18n("No master-password given!"); |
172 | } | 172 | } |
173 | 173 | ||
174 | if (postfix != "") { | 174 | if (postfix != "") { |
175 | msg += "\n"; | 175 | msg += "\n"; |
176 | msg += postfix; | 176 | msg += postfix; |
177 | } | 177 | } |
178 | KMessageBox::error(currentView, msg, | 178 | KMessageBox::error(currentView, msg, |
179 | (chipcard) ? (i18n("no chipcard")) | 179 | (chipcard) ? (i18n("no chipcard")) |
180 | : (i18n("password error"))); | 180 | : (i18n("password error"))); |
181 | } | 181 | } |
182 | 182 | ||
183 | void PwMDocUi::rootAlertMsgBox() | 183 | void PwMDocUi::rootAlertMsgBox() |
184 | { | 184 | { |
185 | KMessageBox::error(currentView, | 185 | KMessageBox::error(currentView, |
186 | i18n("This feature is not available, " | 186 | i18n("This feature is not available, " |
187 | "if you execute PwM with \"root\" " | 187 | "if you execute PwM with \"root\" " |
188 | "UID 0 privileges, for security reasons!"), | 188 | "UID 0 privileges, for security reasons!"), |
189 | i18n("not allowed as root!")); | 189 | i18n("not allowed as root!")); |
190 | } | 190 | } |
191 | 191 | ||
192 | void PwMDocUi::cantDeeplock_notSavedMsgBox() | 192 | void PwMDocUi::cantDeeplock_notSavedMsgBox() |
193 | { | 193 | { |
194 | KMessageBox::error(currentView, | 194 | KMessageBox::error(currentView, |
195 | i18n("Can't deep-lock, because the document " | 195 | i18n("Can't deep-lock, because the document " |
196 | "hasn't been saved, yet. Please save " | 196 | "hasn't been saved, yet. Please save " |
197 | "to a file and try again."), | 197 | "to a file and try again."), |
198 | i18n("not saved, yet")); | 198 | i18n("not saved, yet")); |
199 | } | 199 | } |
200 | 200 | ||
201 | void PwMDocUi::gpmPwLenErrMsgBox() | 201 | void PwMDocUi::gpmPwLenErrMsgBox() |
202 | { | 202 | { |
203 | KMessageBox::error(currentView, | 203 | KMessageBox::error(currentView, |
204 | i18n("GPasman does not support passwords " | 204 | i18n("GPasman does not support passwords " |
205 | "shorter than 4 characters! Please try " | 205 | "shorter than 4 characters! Please try " |
206 | "again with a longer password."), | 206 | "again with a longer password."), |
207 | i18n("password too short")); | 207 | i18n("password too short")); |
208 | } | 208 | } |
209 | 209 | ||
210 | int PwMDocUi::dirtyAskSave(const QString &docTitle) | 210 | int PwMDocUi::dirtyAskSave(const QString &docTitle) |
211 | { | 211 | { |
212 | int ret; | 212 | int ret; |
213 | #ifndef PWM_EMBEDDED | 213 | #ifndef PWM_EMBEDDED |
214 | ret = KMessageBox::questionYesNoCancel(currentView, | 214 | ret = KMessageBox::questionYesNoCancel(currentView, |
215 | i18n("The list \"") + | 215 | i18n("The list \"") + |
216 | docTitle + | 216 | docTitle + |
217 | i18n | 217 | i18n |
218 | ("\" has been modified.\n" | 218 | ("\" has been modified.\n" |
219 | "Do you want to save it?"), | 219 | "Do you want to save it?"), |
220 | i18n("save?")); | 220 | i18n("save?")); |
221 | if (ret == KMessageBox::Yes) { | 221 | if (ret == KMessageBox::Yes) { |
222 | return 0; | 222 | return 0; |
223 | } else if (ret == KMessageBox::No) { | 223 | } else if (ret == KMessageBox::No) { |
224 | return 1; | 224 | return 1; |
225 | } | 225 | } |
226 | #else | 226 | #else |
227 | ret = KMessageBox::warningYesNoCancel(currentView, | 227 | ret = KMessageBox::warningYesNoCancel(currentView, |
228 | i18n("The list \"") + | 228 | i18n("The list \"") + |
229 | docTitle + | 229 | docTitle + |
230 | i18n | 230 | i18n |
231 | ("\" has been modified.\n" | 231 | ("\" has been modified.\n" |
232 | "Do you want to save it?"), | 232 | "Do you want to save it?"), |
233 | i18n("save?")); | 233 | i18n("save?")); |
234 | if (ret == KMessageBox::Yes) { | 234 | if (ret == KMessageBox::Yes) { |
235 | return 0; | 235 | return 0; |
236 | } else if (ret == KMessageBox::No) { | 236 | } else if (ret == KMessageBox::No) { |
237 | return 1; | 237 | return 1; |
238 | } | 238 | } |
239 | 239 | ||
240 | #endif | 240 | #endif |
241 | 241 | ||
242 | // cancel | 242 | // cancel |
243 | return -1; | 243 | return -1; |
244 | } | 244 | } |
245 | 245 | ||
246 | bool PwMDocUi::saveDocUi(PwMDoc *doc) | 246 | bool PwMDocUi::saveDocUi(PwMDoc *doc) |
247 | { | 247 | { |
248 | PWM_ASSERT(doc); | 248 | PWM_ASSERT(doc); |
249 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 249 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
250 | if (doc->isDocEmpty()) { | 250 | if (doc->isDocEmpty()) { |
251 | KMessageBox::information(currentView, | 251 | KMessageBox::information(currentView, |
252 | i18n | 252 | i18n |
253 | ("Sorry, there's nothing to save.\n" | 253 | ("Sorry, there's nothing to save.\n" |
254 | "Please first add some passwords."), | 254 | "Please first add some passwords."), |
255 | i18n("nothing to do")); | 255 | i18n("nothing to do")); |
256 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 256 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
257 | return true; | 257 | return true; |
258 | } | 258 | } |
259 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); | 259 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); |
260 | if (ret == e_filename) { | 260 | if (ret == e_filename) { |
261 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 261 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
262 | return saveAsDocUi(doc); | 262 | return saveAsDocUi(doc); |
263 | } else if (ret == e_weakPw) { | 263 | } else if (ret == e_weakPw) { |
264 | KMessageBox::error(currentView, | 264 | KMessageBox::error(currentView, |
265 | i18n("Error: This is a weak password.\n" | 265 | i18n("Error: This is a weak password.\n" |
266 | "Please select another password."), | 266 | "Please select another password."), |
267 | i18n("weak password")); | 267 | i18n("weak password")); |
268 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 268 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
269 | return false; | 269 | return false; |
270 | } else if (ret == e_fileBackup) { | 270 | } else if (ret == e_fileBackup) { |
271 | KMessageBox::error(currentView, | 271 | KMessageBox::error(currentView, |
272 | i18n("Error: Couldn't make backup-file!"), | 272 | i18n("Error: Couldn't make backup-file!"), |
273 | i18n("backup failed")); | 273 | i18n("backup failed")); |
274 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 274 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
275 | return false; | 275 | return false; |
276 | } else if (ret != e_success) { | 276 | } else if (ret != e_success) { |
277 | KMessageBox::error(currentView, | 277 | KMessageBox::error(currentView, |
278 | i18n("Error: Couldn't write to file.\n" | 278 | i18n("Error: Couldn't write to file.\n" |
279 | "Please check if you have permission to " | 279 | "Please check if you have permission to\n" |
280 | "write to the file in that directory."), | 280 | "write to the file in that directory."), |
281 | i18n("error while writing")); | 281 | i18n("error while writing")); |
282 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 282 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
283 | return false; | 283 | return false; |
284 | } | 284 | } |
285 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 285 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
286 | return true; | 286 | return true; |
287 | } | 287 | } |
288 | 288 | ||
289 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) | 289 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) |
290 | { | 290 | { |
291 | PWM_ASSERT(doc); | 291 | PWM_ASSERT(doc); |
292 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 292 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
293 | if (doc->isDocEmpty()) { | 293 | if (doc->isDocEmpty()) { |
294 | KMessageBox::information(currentView, | 294 | KMessageBox::information(currentView, |
295 | i18n | 295 | i18n |
296 | ("Sorry, there's nothing to save.\n" | 296 | ("Sorry, there's nothing to save.\n" |
297 | "Please first add some passwords."), | 297 | "Please first add some passwords."), |
298 | i18n("nothing to do")); | 298 | i18n("nothing to do")); |
299 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 299 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
300 | return true; | 300 | return true; |
301 | } | 301 | } |
302 | #ifndef PWM_EMBEDDED | 302 | #ifndef PWM_EMBEDDED |
303 | QString fn(KFileDialog::getSaveFileName(QString::null, | 303 | QString fn(KFileDialog::getSaveFileName(QString::null, |
304 | i18n("*.pwm|PwManager Password file"), | 304 | i18n("*.pwm|PwManager Password file"), |
305 | currentView)); | 305 | currentView)); |
306 | #else | 306 | #else |
307 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); | 307 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); |
308 | fn = KFileDialog::getSaveFileName(fn, | 308 | fn = KFileDialog::getSaveFileName(fn, |
309 | i18n("password filename(*.pwm)"), | 309 | i18n("password filename(*.pwm)"), |
310 | currentView); | 310 | currentView); |
311 | 311 | ||
312 | #endif | 312 | #endif |
313 | if (fn == "") { | 313 | if (fn == "") { |
314 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 314 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
315 | return false; | 315 | return false; |
316 | } | 316 | } |
317 | if (fn.right(4) != ".pwm") | 317 | if (fn.right(4) != ".pwm") |
318 | fn += ".pwm"; | 318 | fn += ".pwm"; |
319 | 319 | ||
320 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); | 320 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); |
321 | if (ret != e_success) { | 321 | if (ret != e_success) { |
322 | KMessageBox::error(currentView, | 322 | KMessageBox::error(currentView, |
323 | i18n("Error: Couldn't write to file.\n" | 323 | i18n("Error: Couldn't write to file.\n" |
324 | "Please check if you have permission to " | 324 | "Please check if you have permission to " |
325 | "write to the file in that directory."), | 325 | "write to the file in that directory."), |
326 | i18n("error while writing")); | 326 | i18n("error while writing")); |
327 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 327 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
328 | return false; | 328 | return false; |
329 | } | 329 | } |
330 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 330 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
331 | return true; | 331 | return true; |
332 | } | 332 | } |
333 | 333 | ||
334 | bool PwMDocUi::openDocUi(PwMDoc *doc, | 334 | bool PwMDocUi::openDocUi(PwMDoc *doc, |
335 | QString filename, | 335 | QString filename, |
336 | bool openDeepLocked) | 336 | bool openDeepLocked) |
337 | { | 337 | { |
338 | if (filename.isEmpty()) | 338 | if (filename.isEmpty()) |
339 | { | 339 | { |
340 | #ifndef PWM_EMBEDDED | 340 | #ifndef PWM_EMBEDDED |
341 | filename = KFileDialog::getOpenFileName(QString::null, | 341 | filename = KFileDialog::getOpenFileName(QString::null, |
342 | i18n("*.pwm|PwManager Password file\n" | 342 | i18n("*.pwm|PwManager Password file\n" |
343 | "*|All files"), getCurrentView()); | 343 | "*|All files"), getCurrentView()); |
344 | #else | 344 | #else |
345 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); | 345 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); |
346 | filename = KFileDialog::getOpenFileName(filename, | 346 | filename = KFileDialog::getOpenFileName(filename, |
347 | i18n("password filename(*.pwm)"), getCurrentView()); | 347 | i18n("password filename(*.pwm)"), getCurrentView()); |
348 | #endif | 348 | #endif |
349 | } | 349 | } |
350 | if (filename.isEmpty()) | 350 | if (filename.isEmpty()) |
351 | goto cancelOpen; | 351 | goto cancelOpen; |
352 | PwMerror ret; | 352 | PwMerror ret; |
353 | while (true) { | 353 | while (true) { |
354 | int lockStat = -1; | 354 | int lockStat = -1; |
355 | if (openDeepLocked) { | 355 | if (openDeepLocked) { |
356 | lockStat = 2; | 356 | lockStat = 2; |
357 | } else { | 357 | } else { |
358 | if (conf()->confGlobUnlockOnOpen()) { | 358 | if (conf()->confGlobUnlockOnOpen()) { |
359 | lockStat = 0; | 359 | lockStat = 0; |
360 | } else { | 360 | } else { |
361 | lockStat = 1; | 361 | lockStat = 1; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | ret = doc->openDoc(&filename, lockStat); | 364 | ret = doc->openDoc(&filename, lockStat); |
365 | qDebug("pwmdocui::OpenDocui %i", ret); | 365 | qDebug("pwmdocui::OpenDocui %i", ret); |
366 | if (ret != e_success) { | 366 | if (ret != e_success) { |
367 | if (ret == e_readFile || ret == e_openFile) { | 367 | if (ret == e_readFile || ret == e_openFile) { |
368 | KMessageBox::error(getCurrentView(), | 368 | KMessageBox::error(getCurrentView(), |
369 | i18n("Could not read file!") | 369 | i18n("Could not read file!") |
370 | + "\n" | 370 | + "\n" |
371 | + filename, | 371 | + filename, |
372 | i18n("file error")); | 372 | i18n("file error")); |
373 | goto cancelOpen; | 373 | goto cancelOpen; |
374 | } | 374 | } |
375 | if (ret == e_alreadyOpen) { | 375 | if (ret == e_alreadyOpen) { |
376 | KMessageBox::error(getCurrentView(), | 376 | KMessageBox::error(getCurrentView(), |
377 | i18n("This file is already open."), | 377 | i18n("This file is already open."), |
378 | i18n("already open")); | 378 | i18n("already open")); |
379 | goto cancelOpen; | 379 | goto cancelOpen; |
380 | } | 380 | } |
381 | if (ret == e_fileVer) { | 381 | if (ret == e_fileVer) { |
382 | KMessageBox::error(getCurrentView(), | 382 | KMessageBox::error(getCurrentView(), |
383 | i18n | 383 | i18n |
384 | ("File-version is not supported!\n" | 384 | ("File-version is not supported!\n" |
385 | "Did you create this file with an older or newer version of PwM?"), | 385 | "Did you create this file with an older or newer version of PwM?"), |
386 | i18n | 386 | i18n |
387 | ("incompatible version")); | 387 | ("incompatible version")); |
388 | goto cancelOpen; | 388 | goto cancelOpen; |
389 | } | 389 | } |
390 | if (ret == e_wrongPw) { | 390 | if (ret == e_wrongPw) { |
391 | continue; | 391 | continue; |
392 | } | 392 | } |
393 | if (ret == e_noPw) { | 393 | if (ret == e_noPw) { |
394 | goto cancelOpen; | 394 | goto cancelOpen; |
395 | } | 395 | } |
396 | if (ret == e_fileFormat) { | 396 | if (ret == e_fileFormat) { |
397 | KMessageBox::error(getCurrentView(), | 397 | KMessageBox::error(getCurrentView(), |
398 | i18n | 398 | i18n |
399 | ("Sorry, this file has not been recognized " | 399 | ("Sorry, this file has not been recognized " |
400 | "as a PwM Password file.\n" | 400 | "as a PwM Password file.\n" |
401 | "Probably you have selected the wrong file."), | 401 | "Probably you have selected the wrong file."), |
402 | i18n | 402 | i18n |
403 | ("no PwM password-file")); | 403 | ("no PwM password-file")); |
404 | goto cancelOpen; | 404 | goto cancelOpen; |
405 | } | 405 | } |
406 | if (ret == e_fileCorrupt) { | 406 | if (ret == e_fileCorrupt) { |
407 | KMessageBox::error(getCurrentView(), | 407 | KMessageBox::error(getCurrentView(), |
408 | i18n | 408 | i18n |
409 | ("File corrupt!\n" | 409 | ("File corrupt!\n" |
410 | "Maybe the media, you stored this file on, " | 410 | "Maybe the media, you stored this file on, " |
411 | "had bad sectors?"), | 411 | "had bad sectors?"), |
412 | i18n | 412 | i18n |
413 | ("checksum error")); | 413 | ("checksum error")); |
414 | goto cancelOpen; | 414 | goto cancelOpen; |
415 | } | 415 | } |
416 | } | 416 | } |
417 | break; | 417 | break; |
418 | } | 418 | } |
419 | return true; | 419 | return true; |
420 | 420 | ||
421 | cancelOpen: | 421 | cancelOpen: |
422 | return false; | 422 | return false; |
423 | } | 423 | } |
424 | 424 | ||
425 | QString PwMDocUi::string_defaultCategory() | 425 | QString PwMDocUi::string_defaultCategory() |
426 | { | 426 | { |
427 | return i18n("Default"); | 427 | return i18n("Default"); |
428 | } | 428 | } |
429 | 429 | ||
430 | QString PwMDocUi::string_locked() | 430 | QString PwMDocUi::string_locked() |
431 | { | 431 | { |
432 | return i18n("<LOCKED>"); | 432 | return i18n("<LOCKED>"); |
433 | } | 433 | } |
434 | 434 | ||
435 | QString PwMDocUi::string_deepLockedShort() | 435 | QString PwMDocUi::string_deepLockedShort() |
436 | { | 436 | { |
437 | return i18n("DEEP-LOCKED"); | 437 | return i18n("DEEP-LOCKED"); |
438 | } | 438 | } |
439 | 439 | ||
440 | QString PwMDocUi::string_deepLockedLong() | 440 | QString PwMDocUi::string_deepLockedLong() |
441 | { | 441 | { |
442 | return i18n("This file is DEEP-LOCKED!\n" | 442 | return i18n("This file is DEEP-LOCKED!\n" |
443 | "That means all data has been encrypted\n" | 443 | "That means all data has been encrypted\n" |
444 | "and written out to the file. If you want\n" | 444 | "and written out to the file. If you want\n" |
445 | "to see the entries, please UNLOCK the file.\n" | 445 | "to see the entries, please UNLOCK the file.\n" |
446 | "While unlocking, you will be prompted for the\n" | 446 | "While unlocking, you will be prompted for the\n" |
447 | "master-password or the key-card."); | 447 | "master-password or the key-card."); |
448 | } | 448 | } |
449 | 449 | ||
450 | QString PwMDocUi::string_defaultTitle() | 450 | QString PwMDocUi::string_defaultTitle() |
451 | { | 451 | { |
452 | return i18n("Untitled"); | 452 | return i18n("Untitled"); |
453 | } | 453 | } |
454 | 454 | ||
455 | #ifndef PWM_EMBEDDED | 455 | #ifndef PWM_EMBEDDED |
456 | #include "pwmdocui.moc" | 456 | #include "pwmdocui.moc" |
457 | #endif | 457 | #endif |
diff --git a/pwmanager/pwmanager/pwmexception.h b/pwmanager/pwmanager/pwmexception.h index c8a8c0f..301ebd7 100644 --- a/pwmanager/pwmanager/pwmexception.h +++ b/pwmanager/pwmanager/pwmexception.h | |||
@@ -1,216 +1,217 @@ | |||
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 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 __PWMEXCEPTION_H | 20 | #ifndef __PWMEXCEPTION_H |
21 | #define __PWMEXCEPTION_H | 21 | #define __PWMEXCEPTION_H |
22 | 22 | ||
23 | #include "globalstuff.h" | 23 | #include "globalstuff.h" |
24 | 24 | ||
25 | #include <iostream> | 25 | #include <iostream> |
26 | #include <string> | 26 | #include <string> |
27 | using std::string; | 27 | using std::string; |
28 | using std::cerr; | 28 | using std::cerr; |
29 | using std::cout; | 29 | using std::cout; |
30 | using std::endl; | 30 | using std::endl; |
31 | 31 | ||
32 | /* This is an internal function to reduce code-overhead | 32 | /* This is an internal function to reduce code-overhead |
33 | * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use | 33 | * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use |
34 | * these macros instead of calling this function directly. | 34 | * these macros instead of calling this function directly. |
35 | */ | 35 | */ |
36 | void pwmFatal(const char *id, | 36 | void pwmFatal(const char *id, |
37 | const char *file, | 37 | const char *file, |
38 | int line); | 38 | int line); |
39 | 39 | ||
40 | /** Use PWM_ASSERT(condition) for debugging assertions. | 40 | /** Use PWM_ASSERT(condition) for debugging assertions. |
41 | * "condition" is eaten up and replaced with a NOP | 41 | * "condition" is eaten up and replaced with a NOP |
42 | * when debugging is disabled. | 42 | * when debugging is disabled. |
43 | * | 43 | * |
44 | * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition), | 44 | * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition), |
45 | * but it does _not_ eat up "condition" and ensures that | 45 | * but it does _not_ eat up "condition" and ensures that |
46 | * condition is always evaluated. | 46 | * condition is always evaluated. |
47 | */ | 47 | */ |
48 | #ifdef PWM_ASSERT | 48 | #ifdef PWM_ASSERT |
49 | # undef PWM_ASSERT | 49 | # undef PWM_ASSERT |
50 | #endif | 50 | #endif |
51 | #ifdef PWM_ASSERT_NOEAT | 51 | #ifdef PWM_ASSERT_NOEAT |
52 | # undef PWM_ASSERT_NOEAT | 52 | # undef PWM_ASSERT_NOEAT |
53 | #endif | 53 | #endif |
54 | #ifdef PWM_DEBUG | 54 | #ifdef PWM_DEBUG |
55 | # define PWM_ASSERT(x) do { \ | 55 | # define PWM_ASSERT(x) do { \ |
56 | if (unlikely(!(x))) { \ | 56 | if (unlikely(!(x))) { \ |
57 | cerr << "PWM_ASSERT failed: (" << #x\ | 57 | cerr << "PWM_ASSERT failed: (" << #x\ |
58 | << ") in " << __FILE__ \ | 58 | << ") in " << __FILE__ \ |
59 | << ":" << __LINE__ \ | 59 | << ":" << __LINE__ \ |
60 | << endl; \ | 60 | << endl; \ |
61 | } \ | 61 | } \ |
62 | } while (0) | 62 | } while (0) |
63 | # define PWM_ASSERT_NOEAT(x)do { PWM_ASSERT(x); } while (0) | 63 | # define PWM_ASSERT_NOEAT(x)do { PWM_ASSERT(x); } while (0) |
64 | #else // PWM_DEBUG | 64 | #else // PWM_DEBUG |
65 | # define PWM_ASSERT(x) do { } while (0) | 65 | # define PWM_ASSERT(x) do { } while (0) |
66 | # define PWM_ASSERT_NOEAT(x)do { if (x) ; } while (0) | 66 | # define PWM_ASSERT_NOEAT(x)do { if (x) ; } while (0) |
67 | #endif // PWM_DEBUG | 67 | #endif // PWM_DEBUG |
68 | 68 | ||
69 | /** Insert a BUG() into code paths which clearly show | 69 | /** Insert a BUG() into code paths which clearly show |
70 | * a bug in the code and which should, under normal | 70 | * a bug in the code and which should, under normal |
71 | * circumstances, never execute. | 71 | * circumstances, never execute. |
72 | */ | 72 | */ |
73 | #ifdef BUG | 73 | #ifdef BUG |
74 | # undef BUG | 74 | # undef BUG |
75 | #endif | 75 | #endif |
76 | #define BUG()do { pwmFatal("BUG", __FILE__, __LINE__); } while (0) | 76 | #define BUG()do { pwmFatal("BUG", __FILE__, __LINE__); } while (0) |
77 | 77 | ||
78 | /** Use BUG_ON(condition) to print a bug-message if "condition" | 78 | /** Use BUG_ON(condition) to print a bug-message if "condition" |
79 | * is true. This is also enabled in non-debugging code. | 79 | * is true. This is also enabled in non-debugging code. |
80 | */ | 80 | */ |
81 | #ifdef BUG_ON | 81 | #ifdef BUG_ON |
82 | # undef BUG_ON | 82 | # undef BUG_ON |
83 | #endif | 83 | #endif |
84 | #define BUG_ON(x) do { if (unlikely(x))BUG(); } while (0) | 84 | #define BUG_ON(x) do { if (unlikely(x))BUG(); } while (0) |
85 | 85 | ||
86 | /** Insert a WARN() into code-paths which should not | 86 | /** Insert a WARN() into code-paths which should not |
87 | * execute normally, but if they do it's non-fatal. | 87 | * execute normally, but if they do it's non-fatal. |
88 | */ | 88 | */ |
89 | #ifdef WARN | 89 | #ifdef WARN |
90 | # undef WARN | 90 | # undef WARN |
91 | #endif | 91 | #endif |
92 | #define WARN()do { pwmFatal("badness", __FILE__, __LINE__); } while (0) | 92 | #define WARN()do { pwmFatal("badness", __FILE__, __LINE__); } while (0) |
93 | 93 | ||
94 | /** Same as BUG_ON() but prints a warning-message */ | 94 | /** Same as BUG_ON() but prints a warning-message */ |
95 | #ifdef WARN_ON | 95 | #ifdef WARN_ON |
96 | # undef WARN_ON | 96 | # undef WARN_ON |
97 | #endif | 97 | #endif |
98 | #define WARN_ON(x) do { if (unlikely(x))WARN(); } while (0) | 98 | #define WARN_ON(x) do { if (unlikely(x))WARN(); } while (0) |
99 | 99 | ||
100 | /** Insert this into code which is incomplete */ | 100 | /** Insert this into code which is incomplete */ |
101 | #ifdef TODO | 101 | #ifdef TODO |
102 | # undef TODO | 102 | # undef TODO |
103 | #endif | 103 | #endif |
104 | #define TODO()do { pwmFatal("TODO", __FILE__, __LINE__); } while (0) | 104 | #define TODO()do { pwmFatal("TODO", __FILE__, __LINE__); } while (0) |
105 | 105 | ||
106 | /** Insert this into code which likely contains bugs */ | 106 | /** Insert this into code which likely contains bugs */ |
107 | #ifdef FIXME | 107 | #ifdef FIXME |
108 | # undef FIXME | 108 | # undef FIXME |
109 | #endif | 109 | #endif |
110 | #define FIXME()do { pwmFatal("FIXME", __FILE__, __LINE__); } while (0) | 110 | #define FIXME()do { pwmFatal("FIXME", __FILE__, __LINE__); } while (0) |
111 | 111 | ||
112 | 112 | ||
113 | /** PwM error codes */ | 113 | /** PwM error codes */ |
114 | enum PwMerror { | 114 | enum PwMerror { |
115 | e_success = 0, | 115 | e_success = 0, |
116 | 116 | ||
117 | // file access errors | 117 | // file access errors |
118 | e_filename, | 118 | e_filename, |
119 | e_readFile, | 119 | e_readFile, |
120 | e_writeFile, | 120 | e_writeFile, |
121 | e_openFile, | 121 | e_openFile, |
122 | e_accessFile, // permission error, etc... | 122 | e_accessFile, // permission error, etc... |
123 | e_fileGeneric, | 123 | e_fileGeneric, |
124 | e_alreadyOpen, | 124 | e_alreadyOpen, |
125 | 125 | ||
126 | // other file errors | 126 | // other file errors |
127 | e_fileVer, | 127 | e_fileVer, |
128 | e_fileFormat, // format error | 128 | e_fileFormat, // format error |
129 | e_unsupportedFormat,// completely unsupported format | 129 | e_unsupportedFormat,// completely unsupported format |
130 | e_setFilePointer, | 130 | e_setFilePointer, |
131 | e_fileBackup, | 131 | e_fileBackup, |
132 | e_fileCorrupt, // file data has correct format, | 132 | e_fileCorrupt, // file data has correct format, |
133 | // but is corrupt (checksum error, etc) | 133 | // but is corrupt (checksum error, etc) |
134 | 134 | ||
135 | // password errors | 135 | // password errors |
136 | e_wrongPw, | 136 | e_wrongPw, |
137 | e_getPw, | 137 | e_getPw, |
138 | e_weakPw, | 138 | e_weakPw, |
139 | e_noPw, | 139 | e_noPw, |
140 | 140 | ||
141 | // action not implemented errors | 141 | // action not implemented errors |
142 | e_hashNotImpl, | 142 | e_hashNotImpl, |
143 | e_cryptNotImpl, | 143 | e_cryptNotImpl, |
144 | 144 | ||
145 | // argument/parameter errors | 145 | // argument/parameter errors |
146 | e_incompleteArg, | 146 | e_incompleteArg, |
147 | e_invalidArg, | 147 | e_invalidArg, |
148 | 148 | ||
149 | // misc | 149 | // misc |
150 | e_writeHeader, | 150 | e_writeHeader, |
151 | e_serializeDta, | 151 | e_serializeDta, |
152 | e_enc, | 152 | e_enc, |
153 | e_entryExists, | 153 | e_entryExists, |
154 | e_categoryExists, | 154 | e_categoryExists, |
155 | e_maxAllowedEntr,// no more entries can be added. | 155 | e_maxAllowedEntr,// no more entries can be added. |
156 | e_outOfMem, | 156 | e_outOfMem, |
157 | e_lock, // error while (un)locking | 157 | e_lock, // error while (un)locking |
158 | e_docNotSaved, // doc wasn't saved to a file, yet. | 158 | e_docNotSaved, // doc wasn't saved to a file, yet. |
159 | e_docIsEmpty, | 159 | e_docIsEmpty, |
160 | e_binEntry, | 160 | e_binEntry, |
161 | e_normalEntry, | 161 | e_normalEntry, |
162 | e_syncError, | ||
162 | 163 | ||
163 | e_generic | 164 | e_generic |
164 | }; | 165 | }; |
165 | 166 | ||
166 | /** can be used for general exception faults */ | 167 | /** can be used for general exception faults */ |
167 | class PwMException | 168 | class PwMException |
168 | { | 169 | { |
169 | public: | 170 | public: |
170 | enum exceptionId | 171 | enum exceptionId |
171 | { | 172 | { |
172 | EX_GENERIC = 0, | 173 | EX_GENERIC = 0, |
173 | EX_OPEN, | 174 | EX_OPEN, |
174 | EX_CLOSE, | 175 | EX_CLOSE, |
175 | EX_READ, | 176 | EX_READ, |
176 | EX_WRITE, | 177 | EX_WRITE, |
177 | EX_LOAD_MODULE, | 178 | EX_LOAD_MODULE, |
178 | EX_PARSE | 179 | EX_PARSE |
179 | }; | 180 | }; |
180 | 181 | ||
181 | public: | 182 | public: |
182 | PwMException(exceptionId id = EX_GENERIC, | 183 | PwMException(exceptionId id = EX_GENERIC, |
183 | const char *message = "") | 184 | const char *message = "") |
184 | { | 185 | { |
185 | exId = id; | 186 | exId = id; |
186 | exMsg = message; | 187 | exMsg = message; |
187 | } | 188 | } |
188 | 189 | ||
189 | exceptionId getId() | 190 | exceptionId getId() |
190 | { return exId; } | 191 | { return exId; } |
191 | const char* getMessage() | 192 | const char* getMessage() |
192 | { return exMsg; } | 193 | { return exMsg; } |
193 | 194 | ||
194 | protected: | 195 | protected: |
195 | /** ID of this exception */ | 196 | /** ID of this exception */ |
196 | exceptionId exId; | 197 | exceptionId exId; |
197 | /** additional error-message for this exception */ | 198 | /** additional error-message for this exception */ |
198 | const char *exMsg; | 199 | const char *exMsg; |
199 | }; | 200 | }; |
200 | 201 | ||
201 | void __printInfo(const string &msg); | 202 | void __printInfo(const string &msg); |
202 | void __printWarn(const string &msg); | 203 | void __printWarn(const string &msg); |
203 | void __printError(const string &msg); | 204 | void __printError(const string &msg); |
204 | 205 | ||
205 | #ifdef PWM_DEBUG | 206 | #ifdef PWM_DEBUG |
206 | void __printDebug(const string &msg); | 207 | void __printDebug(const string &msg); |
207 | # define printDebug(x)__printDebug(x) | 208 | # define printDebug(x)__printDebug(x) |
208 | #else | 209 | #else |
209 | # define printDebug(x)do { } while (0) | 210 | # define printDebug(x)do { } while (0) |
210 | #endif | 211 | #endif |
211 | 212 | ||
212 | #define printInfo(x)__printInfo(x) | 213 | #define printInfo(x)__printInfo(x) |
213 | #define printWarn(x)__printWarn(x) | 214 | #define printWarn(x)__printWarn(x) |
214 | #define printError(x)__printError(x) | 215 | #define printError(x)__printError(x) |
215 | 216 | ||
216 | #endif // __PWMEXCEPTION_H | 217 | #endif // __PWMEXCEPTION_H |
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index d192119..e23ce25 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,229 +1,230 @@ | |||
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 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 "pwmview.h" | 20 | #include "pwmview.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "globalstuff.h" | 22 | #include "globalstuff.h" |
23 | #include "pwm.h" | 23 | #include "pwm.h" |
24 | #include "rencatwnd.h" | 24 | #include "rencatwnd.h" |
25 | #ifndef PWM_EMBEDDED | 25 | #ifndef PWM_EMBEDDED |
26 | #include "configuration.h" | 26 | #include "configuration.h" |
27 | #else | 27 | #else |
28 | #include "pwmprefs.h" | 28 | #include "pwmprefs.h" |
29 | #endif | 29 | #endif |
30 | #include "commentbox.h" | 30 | #include "commentbox.h" |
31 | 31 | ||
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qpoint.h> | 36 | #include <qpoint.h> |
37 | #include <qapplication.h> | 37 | #include <qapplication.h> |
38 | #include <qlayout.h> | ||
38 | 39 | ||
39 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 40 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
40 | //US ENH: for examle in listviewpwm.cpp | 41 | //US ENH: for examle in listviewpwm.cpp |
41 | //US ENH: Because of that I transfer them into the headerfile. | 42 | //US ENH: Because of that I transfer them into the headerfile. |
42 | /* | 43 | /* |
43 | #define COLUMN_DESC 0 | 44 | #define COLUMN_DESC 0 |
44 | #define COLUMN_NAME 1 | 45 | #define COLUMN_NAME 1 |
45 | #define COLUMN_PW 2 | 46 | #define COLUMN_PW 2 |
46 | #define COLUMN_URL 3 | 47 | #define COLUMN_URL 3 |
47 | #define COLUMN_LAUNCHER 4 | 48 | #define COLUMN_LAUNCHER 4 |
48 | */ | 49 | */ |
49 | 50 | ||
50 | PwMView::PwMView(PwM *_mainClass, | 51 | PwMView::PwMView(PwM *_mainClass, |
51 | QWidget *parent, PwMDoc *_doc, | 52 | QWidget *parent, PwMDoc *_doc, |
52 | const char *name) | 53 | const char *name) |
53 | : PwMViewStyle(parent, name) | 54 | : PwMViewStyle(parent, name) |
54 | { | 55 | { |
55 | PWM_ASSERT(_mainClass); | 56 | PWM_ASSERT(_mainClass); |
56 | PWM_ASSERT(parent); | 57 | PWM_ASSERT(parent); |
57 | PWM_ASSERT(_doc); | 58 | PWM_ASSERT(_doc); |
58 | setView(this); | 59 | setView(this); |
59 | doc = _doc; | 60 | doc = _doc; |
60 | doc->setListViewPointer(this); | 61 | doc->setListViewPointer(this); |
61 | mainClass = _mainClass; | 62 | mainClass = _mainClass; |
62 | resize(_mainClass->size()); | 63 | resize(_mainClass->size()); |
63 | initStyle(conf()->confWndMainViewStyle()); | 64 | initStyle(conf()->confWndMainViewStyle()); |
64 | initCtxMenu(); | 65 | initCtxMenu(); |
65 | doc->setCurrentView(this); | 66 | doc->setCurrentView(this); |
66 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); | 67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); |
67 | } | 68 | } |
68 | 69 | ||
69 | PwMView::~PwMView() | 70 | PwMView::~PwMView() |
70 | { | 71 | { |
71 | } | 72 | } |
72 | 73 | ||
73 | void PwMView::initCtxMenu() | 74 | void PwMView::initCtxMenu() |
74 | { | 75 | { |
75 | ctxMenu = new QPopupMenu(this); | 76 | ctxMenu = new QPopupMenu(this); |
76 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); | 77 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); |
77 | ctxMenu->insertSeparator(); | 78 | ctxMenu->insertSeparator(); |
78 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); | 79 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); |
79 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); | 80 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); |
80 | ctxMenu->insertSeparator(); | 81 | ctxMenu->insertSeparator(); |
81 | ctxMenu->insertItem(i18n("copy password to clipboard"), | 82 | ctxMenu->insertItem(i18n("copy password to clipboard"), |
82 | this, SLOT(copyPwToClip())); | 83 | this, SLOT(copyPwToClip())); |
83 | ctxMenu->insertItem(i18n("copy username to clipboard"), | 84 | ctxMenu->insertItem(i18n("copy username to clipboard"), |
84 | this, SLOT(copyNameToClip())); | 85 | this, SLOT(copyNameToClip())); |
85 | ctxMenu->insertItem(i18n("copy description to clipboard"), | 86 | ctxMenu->insertItem(i18n("copy description to clipboard"), |
86 | this, SLOT(copyDescToClip())); | 87 | this, SLOT(copyDescToClip())); |
87 | ctxMenu->insertItem(i18n("copy url to clipboard"), | 88 | ctxMenu->insertItem(i18n("copy url to clipboard"), |
88 | this, SLOT(copyUrlToClip())); | 89 | this, SLOT(copyUrlToClip())); |
89 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), | 90 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), |
90 | this, SLOT(copyLauncherToClip())); | 91 | this, SLOT(copyLauncherToClip())); |
91 | ctxMenu->insertItem(i18n("copy comment to clipboard"), | 92 | ctxMenu->insertItem(i18n("copy comment to clipboard"), |
92 | this, SLOT(copyCommentToClip())); | 93 | this, SLOT(copyCommentToClip())); |
93 | ctxMenu->insertSeparator(); | 94 | ctxMenu->insertSeparator(); |
94 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, | 95 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, |
95 | SLOT(execLauncher_slot())); | 96 | SLOT(execLauncher_slot())); |
96 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, | 97 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, |
97 | SLOT(goToURL_slot())); | 98 | SLOT(goToURL_slot())); |
98 | } | 99 | } |
99 | 100 | ||
100 | void PwMView::resizeEvent(QResizeEvent *) | 101 | void PwMView::resizeEvent(QResizeEvent *) |
101 | { | 102 | { |
102 | resizeView(size()); | 103 | resizeView(size()); |
103 | } | 104 | } |
104 | 105 | ||
105 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) | 106 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) |
106 | { | 107 | { |
107 | PWM_ASSERT(commentBox); | 108 | PWM_ASSERT(commentBox); |
108 | if (!curItem) | 109 | if (!curItem) |
109 | return; | 110 | return; |
110 | string comment; | 111 | string comment; |
111 | PwMerror ret; | 112 | PwMerror ret; |
112 | ret = document()->getCommentByLvp(getCurrentCategory(), | 113 | ret = document()->getCommentByLvp(getCurrentCategory(), |
113 | lv->childCount() - lv->itemIndex(curItem) - 1, | 114 | lv->childCount() - lv->itemIndex(curItem) - 1, |
114 | &comment); | 115 | &comment); |
115 | if (ret == e_binEntry) { | 116 | if (ret == e_binEntry) { |
116 | commentBox->setContent(i18n("This is a binary entry.\n" | 117 | commentBox->setContent(i18n("This is a binary entry.\n" |
117 | "It is not a normal password-entry, as it contains " | 118 | "It is not a normal password-entry, as it contains " |
118 | "binary data, which PwManager can't display here.")); | 119 | "binary data, which PwManager can't display here.")); |
119 | } else if (ret == e_normalEntry) { | 120 | } else if (ret == e_normalEntry) { |
120 | commentBox->setContent(comment.c_str()); | 121 | commentBox->setContent(comment.c_str()); |
121 | } else { | 122 | } else { |
122 | BUG(); | 123 | BUG(); |
123 | return; | 124 | return; |
124 | } | 125 | } |
125 | lv->ensureItemVisible(curItem); | 126 | lv->ensureItemVisible(curItem); |
126 | } | 127 | } |
127 | 128 | ||
128 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) | 129 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) |
129 | { | 130 | { |
130 | refreshCommentTextEdit(lv->currentItem()); | 131 | refreshCommentTextEdit(lv->currentItem()); |
131 | } | 132 | } |
132 | 133 | ||
133 | bool PwMView::getCurEntryIndex(unsigned int *index) | 134 | bool PwMView::getCurEntryIndex(unsigned int *index) |
134 | { | 135 | { |
135 | QListViewItem *current = lv->currentItem(); | 136 | QListViewItem *current = lv->currentItem(); |
136 | if (!current) | 137 | if (!current) |
137 | return false; | 138 | return false; |
138 | return getDocEntryIndex(index, current); | 139 | return getDocEntryIndex(index, current); |
139 | } | 140 | } |
140 | 141 | ||
141 | bool PwMView::getDocEntryIndex(unsigned int *index, | 142 | bool PwMView::getDocEntryIndex(unsigned int *index, |
142 | const QListViewItem *item) | 143 | const QListViewItem *item) |
143 | { | 144 | { |
144 | vector<unsigned int> foundPositions; | 145 | vector<unsigned int> foundPositions; |
145 | PwMDataItem curItem; | 146 | PwMDataItem curItem; |
146 | curItem.desc = item->text(COLUMN_DESC).latin1(); | 147 | curItem.desc = item->text(COLUMN_DESC).latin1(); |
147 | curItem.name = item->text(COLUMN_NAME).latin1(); | 148 | curItem.name = item->text(COLUMN_NAME).latin1(); |
148 | document()->getCommentByLvp(getCurrentCategory(), | 149 | document()->getCommentByLvp(getCurrentCategory(), |
149 | lv->childCount() - lv->itemIndex(item) - 1, | 150 | lv->childCount() - lv->itemIndex(item) - 1, |
150 | &curItem.comment); | 151 | &curItem.comment); |
151 | curItem.url = item->text(COLUMN_URL).latin1(); | 152 | curItem.url = item->text(COLUMN_URL).latin1(); |
152 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); | 153 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); |
153 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | | 154 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | |
154 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | | 155 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | |
155 | SEARCH_IN_LAUNCHER, | 156 | SEARCH_IN_LAUNCHER, |
156 | &foundPositions, true); | 157 | &foundPositions, true); |
157 | if (foundPositions.size()) { | 158 | if (foundPositions.size()) { |
158 | *index = foundPositions[0]; | 159 | *index = foundPositions[0]; |
159 | return true; | 160 | return true; |
160 | } | 161 | } |
161 | 162 | ||
162 | return false; | 163 | return false; |
163 | } | 164 | } |
164 | 165 | ||
165 | void PwMView::handleToggle(QListViewItem *item) | 166 | void PwMView::handleToggle(QListViewItem *item) |
166 | { | 167 | { |
167 | PWM_ASSERT(doc); | 168 | PWM_ASSERT(doc); |
168 | if (!item) | 169 | if (!item) |
169 | return; | 170 | return; |
170 | QCheckListItem *clItem = (QCheckListItem *)item; | 171 | QCheckListItem *clItem = (QCheckListItem *)item; |
171 | QString curCat(getCurrentCategory()); | 172 | QString curCat(getCurrentCategory()); |
172 | 173 | ||
173 | // find document position of this entry. | 174 | // find document position of this entry. |
174 | unsigned int curEntryDocIndex; | 175 | unsigned int curEntryDocIndex; |
175 | if (!getDocEntryIndex(&curEntryDocIndex, item)) | 176 | if (!getDocEntryIndex(&curEntryDocIndex, item)) |
176 | return; | 177 | return; |
177 | 178 | ||
178 | // hack to refresh the comment, if only one item is present | 179 | // hack to refresh the comment, if only one item is present |
179 | if (lv->childCount() == 1) | 180 | if (lv->childCount() == 1) |
180 | refreshCommentTextEdit(lv->currentItem()); | 181 | refreshCommentTextEdit(lv->currentItem()); |
181 | 182 | ||
182 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) | 183 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) |
183 | return; // this is just a click somewhere on the entry | 184 | return; // this is just a click somewhere on the entry |
184 | if (doc->isDeepLocked()) { | 185 | if (doc->isDeepLocked()) { |
185 | PwMerror ret; | 186 | PwMerror ret; |
186 | ret = doc->deepLock(false); | 187 | ret = doc->deepLock(false); |
187 | if (ret != e_success) | 188 | if (ret != e_success) |
188 | clItem->setOn(false); | 189 | clItem->setOn(false); |
189 | return; | 190 | return; |
190 | } | 191 | } |
191 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); | 192 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); |
192 | } | 193 | } |
193 | 194 | ||
194 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) | 195 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) |
195 | { | 196 | { |
196 | if (!item) | 197 | if (!item) |
197 | return; | 198 | return; |
198 | ctxMenu->move(point); | 199 | ctxMenu->move(point); |
199 | /* don't use ctxMenu->exec() here, as it generates race conditions | 200 | /* don't use ctxMenu->exec() here, as it generates race conditions |
200 | * with the card interface code. Believe it or not. :) | 201 | * with the card interface code. Believe it or not. :) |
201 | */ | 202 | */ |
202 | ctxMenu->show(); | 203 | ctxMenu->show(); |
203 | } | 204 | } |
204 | 205 | ||
205 | void PwMView::updateCategories() | 206 | void PwMView::updateCategories() |
206 | { | 207 | { |
207 | QString oldSel(getCurrentCategory()); | 208 | QString oldSel(getCurrentCategory()); |
208 | delAllCategories(); | 209 | delAllCategories(); |
209 | QStringList catList; | 210 | QStringList catList; |
210 | document()->getCategoryList(&catList); | 211 | document()->getCategoryList(&catList); |
211 | catList.sort(); | 212 | catList.sort(); |
212 | #ifndef PWM_EMBEDDED | 213 | #ifndef PWM_EMBEDDED |
213 | QStringList::iterator i = catList.begin(), | 214 | QStringList::iterator i = catList.begin(), |
214 | end = catList.end(); | 215 | end = catList.end(); |
215 | #else | 216 | #else |
216 | QStringList::Iterator i = catList.begin(), | 217 | QStringList::Iterator i = catList.begin(), |
217 | end = catList.end(); | 218 | end = catList.end(); |
218 | #endif | 219 | #endif |
219 | while (i != end) { | 220 | while (i != end) { |
220 | addCategory(*i); | 221 | addCategory(*i); |
221 | ++i; | 222 | ++i; |
222 | } | 223 | } |
223 | selectCategory(oldSel); | 224 | selectCategory(oldSel); |
224 | } | 225 | } |
225 | 226 | ||
226 | void PwMView::shiftToView() | 227 | void PwMView::shiftToView() |
227 | { | 228 | { |
228 | int cX = lv->contentsX(); | 229 | int cX = lv->contentsX(); |
229 | int cY = lv->contentsY(); | 230 | int cY = lv->contentsY(); |
@@ -266,195 +267,258 @@ void PwMView::shiftToView() | |||
266 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 267 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
267 | if ((*it).binary) { | 268 | if ((*it).binary) { |
268 | newItem->setText(COLUMN_NAME, ""); | 269 | newItem->setText(COLUMN_NAME, ""); |
269 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 270 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
270 | newItem->setText(COLUMN_URL, ""); | 271 | newItem->setText(COLUMN_URL, ""); |
271 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 272 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
272 | } else { | 273 | } else { |
273 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 274 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
274 | if ((*it).lockStat) { | 275 | if ((*it).lockStat) { |
275 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 276 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
276 | + " " | 277 | + " " |
277 | + i18n("To unlock click the icon on the left.")); | 278 | + i18n("To unlock click the icon on the left.")); |
278 | } else { | 279 | } else { |
279 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 280 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
280 | } | 281 | } |
281 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 282 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
282 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 283 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
283 | } | 284 | } |
284 | newItem->setOn(!((*it).lockStat)); | 285 | newItem->setOn(!((*it).lockStat)); |
285 | lv->insertItem(newItem); | 286 | lv->insertItem(newItem); |
286 | ++it; | 287 | ++it; |
287 | } | 288 | } |
288 | tmpReEnableSort(); | 289 | tmpReEnableSort(); |
289 | 290 | ||
290 | if (cY || cX) | 291 | if (cY || cX) |
291 | lv->setContentsPos(cX, cY); | 292 | lv->setContentsPos(cX, cY); |
292 | } | 293 | } |
293 | 294 | ||
294 | void PwMView::reorgLp() | 295 | void PwMView::reorgLp() |
295 | { | 296 | { |
296 | if (!lv->childCount()) | 297 | if (!lv->childCount()) |
297 | return; | 298 | return; |
298 | PWM_ASSERT(doc); | 299 | PWM_ASSERT(doc); |
299 | PWM_ASSERT(!doc->isDocEmpty()); | 300 | PWM_ASSERT(!doc->isDocEmpty()); |
300 | QListViewItem *currItem; | 301 | QListViewItem *currItem; |
301 | vector<unsigned int> foundPos; | 302 | vector<unsigned int> foundPos; |
302 | /* This searchIn _should_ be: | 303 | /* This searchIn _should_ be: |
303 | *const unsigned int searchIn = SEARCH_IN_DESC; | 304 | *const unsigned int searchIn = SEARCH_IN_DESC; |
304 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 305 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
305 | * So we need to search again, if we don't find the entry. (see below) | 306 | * So we need to search again, if we don't find the entry. (see below) |
306 | */ | 307 | */ |
307 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 308 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
308 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 309 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
309 | QString curCat(getCurrentCategory()); | 310 | QString curCat(getCurrentCategory()); |
310 | PwMDataItem findThis; | 311 | PwMDataItem findThis; |
311 | unsigned int i, cnt = lv->childCount(); | 312 | unsigned int i, cnt = lv->childCount(); |
312 | for (i = 0; i < cnt; ++i) { | 313 | for (i = 0; i < cnt; ++i) { |
313 | currItem = lv->itemAtIndex(i); | 314 | currItem = lv->itemAtIndex(i); |
314 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 315 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
315 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 316 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
316 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 317 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
317 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 318 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
318 | doc->findEntry(curCat, findThis, searchIn, | 319 | doc->findEntry(curCat, findThis, searchIn, |
319 | &foundPos, true); | 320 | &foundPos, true); |
320 | if (!foundPos.size()) { | 321 | if (!foundPos.size()) { |
321 | /* Did not find the entry. We seem to have a binary | 322 | /* Did not find the entry. We seem to have a binary |
322 | * entry here (pray for it!). So search again with | 323 | * entry here (pray for it!). So search again with |
323 | * the "correct" searchIn flags. | 324 | * the "correct" searchIn flags. |
324 | */ | 325 | */ |
325 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 326 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
326 | doc->findEntry(curCat, findThis, searchIn2, | 327 | doc->findEntry(curCat, findThis, searchIn2, |
327 | &foundPos, true); | 328 | &foundPos, true); |
328 | if (unlikely(!foundPos.size())) { | 329 | if (unlikely(!foundPos.size())) { |
329 | BUG(); | 330 | BUG(); |
330 | continue; | 331 | continue; |
331 | } | 332 | } |
332 | /* We assert that it's a binary entry, now. | 333 | /* We assert that it's a binary entry, now. |
333 | * No chance to efficiently verify it here. | 334 | * No chance to efficiently verify it here. |
334 | */ | 335 | */ |
335 | } | 336 | } |
336 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 337 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
337 | } | 338 | } |
338 | } | 339 | } |
339 | 340 | ||
340 | void PwMView::selAt(int index) | 341 | void PwMView::selAt(int index) |
341 | { | 342 | { |
342 | QListViewItem *item = lv->itemAtIndex(index); | 343 | QListViewItem *item = lv->itemAtIndex(index); |
343 | if (!item) | 344 | if (!item) |
344 | return; | 345 | return; |
345 | lv->setCurrentItem(item); | 346 | lv->setCurrentItem(item); |
346 | lv->ensureItemVisible(item); | 347 | lv->ensureItemVisible(item); |
347 | } | 348 | } |
348 | 349 | ||
349 | void PwMView::renCatButton_slot() | 350 | void PwMView::renCatButton_slot() |
350 | { | 351 | { |
351 | if (doc->isDeepLocked()) | 352 | if (doc->isDeepLocked()) |
352 | return; | 353 | return; |
353 | RenCatWnd wnd(this); | 354 | RenCatWnd wnd(this); |
354 | if (wnd.exec() == 1) { | 355 | if (wnd.exec() == 1) { |
355 | QString newName(wnd.getNewName()); | 356 | QString newName(wnd.getNewName()); |
356 | if (newName == "") | 357 | if (newName == "") |
357 | return; | 358 | return; |
358 | document()->renameCategory(getCurrentCategory(), | 359 | document()->renameCategory(getCurrentCategory(), |
359 | newName); | 360 | newName); |
360 | } | 361 | } |
361 | } | 362 | } |
362 | 363 | ||
363 | void PwMView::delCatButton_slot() | 364 | void PwMView::delCatButton_slot() |
364 | { | 365 | { |
365 | if (doc->isDeepLocked()) | 366 | if (doc->isDeepLocked()) |
366 | return; | 367 | return; |
367 | if (numCategories() <= 1) { | 368 | if (numCategories() <= 1) { |
368 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 369 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
369 | return; | 370 | return; |
370 | } | 371 | } |
371 | if (KMessageBox::questionYesNo(this, | 372 | if (KMessageBox::questionYesNo(this, |
372 | i18n("Do you really want to\n" | 373 | i18n("Do you really want to\n" |
373 | "delete the selected\n" | 374 | "delete the selected\n" |
374 | "category? All password-\n" | 375 | "category? All password-\n" |
375 | "entries will be lost in\n" | 376 | "entries will be lost in\n" |
376 | "this category!\n"), | 377 | "this category!\n"), |
377 | i18n("Delete category?")) | 378 | i18n("Delete category?")) |
378 | == KMessageBox::No) { | 379 | == KMessageBox::No) { |
379 | return; | 380 | return; |
380 | } | 381 | } |
381 | document()->delCategory(getCurrentCategory()); | 382 | document()->delCategory(getCurrentCategory()); |
382 | } | 383 | } |
383 | 384 | ||
384 | void PwMView::copyPwToClip() | 385 | void PwMView::copyPwToClip() |
385 | { | 386 | { |
386 | if (doc->isDeepLocked()) | 387 | if (doc->isDeepLocked()) |
387 | return; | 388 | return; |
388 | unsigned int curIndex = 0; | 389 | unsigned int curIndex = 0; |
389 | if (!getCurEntryIndex(&curIndex)) | 390 | if (!getCurEntryIndex(&curIndex)) |
390 | return; | 391 | return; |
391 | PwMDataItem d; | 392 | PwMDataItem d; |
392 | document()->getDataChangedLock(); | 393 | document()->getDataChangedLock(); |
393 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 394 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
394 | document()->putDataChangedLock(); | 395 | document()->putDataChangedLock(); |
395 | PwM::copyToClipboard(d.pw.c_str()); | 396 | PwM::copyToClipboard(d.pw.c_str()); |
396 | } | 397 | } |
397 | 398 | ||
398 | void PwMView::copyNameToClip() | 399 | void PwMView::copyNameToClip() |
399 | { | 400 | { |
400 | if (doc->isDeepLocked()) | 401 | if (doc->isDeepLocked()) |
401 | return; | 402 | return; |
402 | unsigned int curIndex = 0; | 403 | unsigned int curIndex = 0; |
403 | if (!getCurEntryIndex(&curIndex)) | 404 | if (!getCurEntryIndex(&curIndex)) |
404 | return; | 405 | return; |
405 | PwMDataItem d; | 406 | PwMDataItem d; |
406 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 407 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
407 | PwM::copyToClipboard(d.name.c_str()); | 408 | PwM::copyToClipboard(d.name.c_str()); |
408 | } | 409 | } |
409 | 410 | ||
410 | void PwMView::copyDescToClip() | 411 | void PwMView::copyDescToClip() |
411 | { | 412 | { |
412 | if (doc->isDeepLocked()) | 413 | if (doc->isDeepLocked()) |
413 | return; | 414 | return; |
414 | unsigned int curIndex = 0; | 415 | unsigned int curIndex = 0; |
415 | if (!getCurEntryIndex(&curIndex)) | 416 | if (!getCurEntryIndex(&curIndex)) |
416 | return; | 417 | return; |
417 | PwMDataItem d; | 418 | PwMDataItem d; |
418 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 419 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
419 | PwM::copyToClipboard(d.desc.c_str()); | 420 | PwM::copyToClipboard(d.desc.c_str()); |
420 | } | 421 | } |
421 | 422 | ||
422 | void PwMView::copyUrlToClip() | 423 | void PwMView::copyUrlToClip() |
423 | { | 424 | { |
424 | if (doc->isDeepLocked()) | 425 | if (doc->isDeepLocked()) |
425 | return; | 426 | return; |
426 | unsigned int curIndex = 0; | 427 | unsigned int curIndex = 0; |
427 | if (!getCurEntryIndex(&curIndex)) | 428 | if (!getCurEntryIndex(&curIndex)) |
428 | return; | 429 | return; |
429 | PwMDataItem d; | 430 | PwMDataItem d; |
430 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 431 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
431 | PwM::copyToClipboard(d.url.c_str()); | 432 | PwM::copyToClipboard(d.url.c_str()); |
432 | } | 433 | } |
433 | 434 | ||
434 | void PwMView::copyLauncherToClip() | 435 | void PwMView::copyLauncherToClip() |
435 | { | 436 | { |
436 | if (doc->isDeepLocked()) | 437 | if (doc->isDeepLocked()) |
437 | return; | 438 | return; |
438 | unsigned int curIndex = 0; | 439 | unsigned int curIndex = 0; |
439 | if (!getCurEntryIndex(&curIndex)) | 440 | if (!getCurEntryIndex(&curIndex)) |
440 | return; | 441 | return; |
441 | PwMDataItem d; | 442 | PwMDataItem d; |
442 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 443 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
443 | PwM::copyToClipboard(d.launcher.c_str()); | 444 | PwM::copyToClipboard(d.launcher.c_str()); |
444 | } | 445 | } |
445 | 446 | ||
446 | void PwMView::copyCommentToClip() | 447 | void PwMView::copyCommentToClip() |
447 | { | 448 | { |
448 | if (doc->isDeepLocked()) | 449 | if (doc->isDeepLocked()) |
449 | return; | 450 | return; |
450 | unsigned int curIndex = 0; | 451 | unsigned int curIndex = 0; |
451 | if (!getCurEntryIndex(&curIndex)) | 452 | if (!getCurEntryIndex(&curIndex)) |
452 | return; | 453 | return; |
453 | PwMDataItem d; | 454 | PwMDataItem d; |
454 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 455 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
455 | PwM::copyToClipboard(d.comment.c_str()); | 456 | PwM::copyToClipboard(d.comment.c_str()); |
456 | } | 457 | } |
457 | 458 | ||
459 | |||
460 | |||
461 | |||
462 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, | ||
463 | true ,i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | ||
464 | { | ||
465 | findButton( Close )->setText( i18n("Cancel Sync")); | ||
466 | findButton( Ok )->setText( i18n("Remote")); | ||
467 | findButton( User1 )->setText( i18n("Local")); | ||
468 | QWidget* topframe = new QWidget( this ); | ||
469 | setMainWidget( topframe ); | ||
470 | QBoxLayout* bl; | ||
471 | if ( QApplication::desktop()->width() < 640 ) { | ||
472 | bl = new QVBoxLayout( topframe ); | ||
473 | } else { | ||
474 | bl = new QHBoxLayout( topframe ); | ||
475 | } | ||
476 | QVBox* subframe = new QVBox( topframe ); | ||
477 | bl->addWidget(subframe ); | ||
478 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | ||
479 | if ( takeloc ) | ||
480 | lab->setBackgroundColor(Qt::green.light() ); | ||
481 | // AddresseeView * av = new AddresseeView( subframe ); | ||
482 | // av->setAddressee( loc ); | ||
483 | subframe = new QVBox( topframe ); | ||
484 | bl->addWidget(subframe ); | ||
485 | lab = new QLabel( i18n("Remote Entry"), subframe ); | ||
486 | if ( !takeloc ) | ||
487 | lab->setBackgroundColor(Qt::green.light() ); | ||
488 | // av = new AddresseeView( subframe ); | ||
489 | // av->setAddressee( rem ); | ||
490 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | ||
491 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | ||
492 | #ifndef DESKTOP_VERSION | ||
493 | showMaximized(); | ||
494 | #else | ||
495 | resize ( 640, 400 ); | ||
496 | #endif | ||
497 | } | ||
498 | |||
499 | int PwMDataItemChooser::executeD( bool local ) | ||
500 | { | ||
501 | mSyncResult = 3; | ||
502 | if ( local ) | ||
503 | findButton( User1 )->setFocus(); | ||
504 | else | ||
505 | findButton( Ok )->setFocus(); | ||
506 | exec(); | ||
507 | return mSyncResult; | ||
508 | } | ||
509 | void PwMDataItemChooser::slot_remote() | ||
510 | { | ||
511 | mSyncResult = 2; | ||
512 | accept(); | ||
513 | } | ||
514 | void PwMDataItemChooser::slot_local() | ||
515 | { | ||
516 | mSyncResult = 1; | ||
517 | accept(); | ||
518 | } | ||
519 | |||
520 | |||
521 | |||
458 | #ifndef PWM_EMBEDDED | 522 | #ifndef PWM_EMBEDDED |
459 | #include "pwmview.moc" | 523 | #include "pwmview.moc" |
460 | #endif | 524 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.h b/pwmanager/pwmanager/pwmview.h index 5a326d3..75cce51 100644 --- a/pwmanager/pwmanager/pwmview.h +++ b/pwmanager/pwmanager/pwmview.h | |||
@@ -1,150 +1,172 @@ | |||
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 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 PWMVIEW_H | 20 | #ifndef PWMVIEW_H |
21 | #define PWMVIEW_H | 21 | #define PWMVIEW_H |
22 | 22 | ||
23 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. | 23 | //US ENH: wouldn't it be a good idea if we could use this consts everywhere else. |
24 | //US ENH: for examle in listviewpwm.cpp | 24 | //US ENH: for examle in listviewpwm.cpp |
25 | //US ENH: Because of that I transfer them into the headerfile. | 25 | //US ENH: Because of that I transfer them into the headerfile. |
26 | #define COLUMN_DESC 0 | 26 | #define COLUMN_DESC 0 |
27 | #define COLUMN_NAME 1 | 27 | #define COLUMN_NAME 1 |
28 | #define COLUMN_PW 2 | 28 | #define COLUMN_PW 2 |
29 | #define COLUMN_URL 3 | 29 | #define COLUMN_URL 3 |
30 | #define COLUMN_LAUNCHER 4 | 30 | #define COLUMN_LAUNCHER 4 |
31 | 31 | ||
32 | 32 | ||
33 | #include "listviewpwm.h" | 33 | #include "listviewpwm.h" |
34 | #include "pwmdoc.h" | 34 | #include "pwmdoc.h" |
35 | #include "pwmviewstyle.h" | 35 | #include "pwmviewstyle.h" |
36 | 36 | ||
37 | #include <kconfig.h> | 37 | #include <kconfig.h> |
38 | #include <klocale.h> | 38 | #include <klocale.h> |
39 | #include <kdialogbase.h> | ||
39 | 40 | ||
40 | #include <qevent.h> | 41 | #include <qevent.h> |
41 | #include <qfont.h> | 42 | #include <qfont.h> |
42 | #include <qobject.h> | 43 | #include <qobject.h> |
43 | 44 | ||
44 | #include <vector> | 45 | #include <vector> |
45 | #include <string> | 46 | #include <string> |
46 | 47 | ||
47 | using std::string; | 48 | using std::string; |
48 | using std::vector; | 49 | using std::vector; |
49 | 50 | ||
50 | class PwM; | 51 | class PwM; |
51 | class ConfFile; | 52 | class ConfFile; |
52 | class PwMStatusBar; | 53 | class PwMStatusBar; |
53 | 54 | ||
54 | 55 | ||
55 | /** View class for PwM */ | 56 | /** View class for PwM */ |
56 | class PwMView : public PwMViewStyle | 57 | class PwMView : public PwMViewStyle |
57 | { | 58 | { |
58 | Q_OBJECT | 59 | Q_OBJECT |
59 | friend class PwMViewStyle; | 60 | friend class PwMViewStyle; |
60 | public: | 61 | public: |
61 | /** construtor */ | 62 | /** construtor */ |
62 | PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc, | 63 | PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc, |
63 | const char *name = 0); | 64 | const char *name = 0); |
64 | /** destructor */ | 65 | /** destructor */ |
65 | ~PwMView(); | 66 | ~PwMView(); |
66 | 67 | ||
67 | /** returns pointer to the document */ | 68 | /** returns pointer to the document */ |
68 | PwMDoc* document() | 69 | PwMDoc* document() |
69 | { return doc; } | 70 | { return doc; } |
70 | /** returns the index of the currently selected entry. | 71 | /** returns the index of the currently selected entry. |
71 | * (index as represented in PwMDoc !) | 72 | * (index as represented in PwMDoc !) |
72 | */ | 73 | */ |
73 | bool getCurEntryIndex(unsigned int *index); | 74 | bool getCurEntryIndex(unsigned int *index); |
74 | /** returns the position of the given item in the document | 75 | /** returns the position of the given item in the document |
75 | * Note: This func only serches in the current category. | 76 | * Note: This func only serches in the current category. |
76 | */ | 77 | */ |
77 | bool getDocEntryIndex(unsigned int *index, | 78 | bool getDocEntryIndex(unsigned int *index, |
78 | const QListViewItem *item); | 79 | const QListViewItem *item); |
79 | 80 | ||
80 | public slots: | 81 | public slots: |
81 | /** update the view (call if dirty) */ | 82 | /** update the view (call if dirty) */ |
82 | void updateView() | 83 | void updateView() |
83 | { | 84 | { |
84 | updateCategories(); | 85 | updateCategories(); |
85 | shiftToView(); | 86 | shiftToView(); |
86 | } | 87 | } |
87 | /** (re)sort all items and (re)shift them to listView. */ | 88 | /** (re)sort all items and (re)shift them to listView. */ |
88 | void shiftToView(); | 89 | void shiftToView(); |
89 | /** handle clicking on an item */ | 90 | /** handle clicking on an item */ |
90 | void handleToggle(QListViewItem *item); | 91 | void handleToggle(QListViewItem *item); |
91 | /** handle right-clicking on an item */ | 92 | /** handle right-clicking on an item */ |
92 | void handleRightClick(QListViewItem *item, const QPoint &point, int); | 93 | void handleRightClick(QListViewItem *item, const QPoint &point, int); |
93 | /** selects the item at "index" */ | 94 | /** selects the item at "index" */ |
94 | void selAt(int index); | 95 | void selAt(int index); |
95 | /** rename category button pressed */ | 96 | /** rename category button pressed */ |
96 | void renCatButton_slot(); | 97 | void renCatButton_slot(); |
97 | /** delete category button pressed */ | 98 | /** delete category button pressed */ |
98 | void delCatButton_slot(); | 99 | void delCatButton_slot(); |
99 | 100 | ||
100 | protected: | 101 | protected: |
101 | /** right-click context-menu */ | 102 | /** right-click context-menu */ |
102 | QPopupMenu *ctxMenu; | 103 | QPopupMenu *ctxMenu; |
103 | 104 | ||
104 | protected: | 105 | protected: |
105 | /** update the categories from document */ | 106 | /** update the categories from document */ |
106 | void updateCategories(); | 107 | void updateCategories(); |
107 | /** widget resize event */ | 108 | /** widget resize event */ |
108 | void resizeEvent(QResizeEvent *); | 109 | void resizeEvent(QResizeEvent *); |
109 | /** initialize context-menu */ | 110 | /** initialize context-menu */ |
110 | void initCtxMenu(); | 111 | void initCtxMenu(); |
111 | /** tempoarly disable auto-sorting and user-sorting */ | 112 | /** tempoarly disable auto-sorting and user-sorting */ |
112 | void tmpDisableSort() | 113 | void tmpDisableSort() |
113 | { lv->setSorting(-1); } | 114 | { lv->setSorting(-1); } |
114 | /** re-enable tempoarly disabled sorting */ | 115 | /** re-enable tempoarly disabled sorting */ |
115 | void tmpReEnableSort() | 116 | void tmpReEnableSort() |
116 | { | 117 | { |
117 | lv->setSorting(lv->columns() + 1, | 118 | lv->setSorting(lv->columns() + 1, |
118 | true/*lv->sortOrder() == Qt::Ascending*/); | 119 | true/*lv->sortOrder() == Qt::Ascending*/); |
119 | } | 120 | } |
120 | /** The user pressed and released a key. */ | 121 | /** The user pressed and released a key. */ |
121 | void keyReleaseEvent(QKeyEvent *e); | 122 | void keyReleaseEvent(QKeyEvent *e); |
122 | 123 | ||
123 | protected slots: | 124 | protected slots: |
124 | /** changes the comment text-edit, because a new item has been selected */ | 125 | /** changes the comment text-edit, because a new item has been selected */ |
125 | void refreshCommentTextEdit(QListViewItem *curItem); | 126 | void refreshCommentTextEdit(QListViewItem *curItem); |
126 | /** copy pw to clipboard */ | 127 | /** copy pw to clipboard */ |
127 | void copyPwToClip(); | 128 | void copyPwToClip(); |
128 | /** copy name to clipboard */ | 129 | /** copy name to clipboard */ |
129 | void copyNameToClip(); | 130 | void copyNameToClip(); |
130 | /** copy desc to clipboard */ | 131 | /** copy desc to clipboard */ |
131 | void copyDescToClip(); | 132 | void copyDescToClip(); |
132 | /** copy url to clipboard */ | 133 | /** copy url to clipboard */ |
133 | void copyUrlToClip(); | 134 | void copyUrlToClip(); |
134 | /** copy launcher to clipboard */ | 135 | /** copy launcher to clipboard */ |
135 | void copyLauncherToClip(); | 136 | void copyLauncherToClip(); |
136 | /** copy comment to clipboard */ | 137 | /** copy comment to clipboard */ |
137 | void copyCommentToClip(); | 138 | void copyCommentToClip(); |
138 | /** reorganize the "listViewPos" positions in the document | 139 | /** reorganize the "listViewPos" positions in the document |
139 | * (for the current category only!) | 140 | * (for the current category only!) |
140 | */ | 141 | */ |
141 | void reorgLp(); | 142 | void reorgLp(); |
142 | 143 | ||
143 | private: | 144 | private: |
144 | /** document */ | 145 | /** document */ |
145 | PwMDoc *doc; | 146 | PwMDoc *doc; |
146 | /** pointer to the main class "PwM" */ | 147 | /** pointer to the main class "PwM" */ |
147 | PwM *mainClass; | 148 | PwM *mainClass; |
148 | }; | 149 | }; |
149 | 150 | ||
151 | |||
152 | //US ENH we need this chooser when syncing results in a conflict | ||
153 | class PwMDataItemChooser : public KDialogBase | ||
154 | { | ||
155 | Q_OBJECT | ||
156 | |||
157 | public: | ||
158 | PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); | ||
159 | |||
160 | int executeD( bool local ); | ||
161 | |||
162 | private: | ||
163 | int mSyncResult; | ||
164 | |||
165 | private slots: | ||
166 | void slot_remote(); | ||
167 | void slot_local(); | ||
168 | |||
169 | }; | ||
170 | |||
171 | |||
150 | #endif | 172 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index a54ba8a..f615082 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,435 +1,451 @@ | |||
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 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 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 "serializer.h" | 21 | #include "serializer.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | 23 | ||
24 | #ifdef PWM_EMBEDDED | 24 | #ifdef PWM_EMBEDDED |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | /* enable/disable serializer debugging (0/1) */ | 29 | /* enable/disable serializer debugging (0/1) */ |
30 | #define SERIALIZER_DEBUG1 | 30 | #define SERIALIZER_DEBUG1 |
31 | /* use the old xml tags for writing (0/1) */ | 31 | /* use the old xml tags for writing (0/1) */ |
32 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
33 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
34 | #define WRITE_CDATA_SEC 0 | 34 | #define WRITE_CDATA_SEC 0 |
35 | 35 | ||
36 | 36 | ||
37 | #define META_CREATE_DATE"c" | 37 | #define META_CREATE_DATE"c" |
38 | #define META_VALID_DATE "v" | 38 | #define META_VALID_DATE "v" |
39 | #define META_EXPIRE_DATE"e" | 39 | #define META_EXPIRE_DATE"e" |
40 | #define META_UPDATE_DATE"u" | 40 | #define META_UPDATE_DATE"u" |
41 | #define META_UPDATE_INT "i" | 41 | #define META_UPDATE_INT "i" |
42 | //US ENH : uniqueid | 42 | //US ENH : uniqueid |
43 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
44 | #define SYNC_ROOT "s" | ||
45 | #define SYNC_TARGET_PREFIX "t" | ||
46 | #define SYNC_TARGET_NAME "n" | ||
47 | |||
44 | 48 | ||
45 | /* This is compatibility stuff. | 49 | /* This is compatibility stuff. |
46 | * The names of the entries have changed and here are the | 50 | * The names of the entries have changed and here are the |
47 | * new and old ones | 51 | * new and old ones |
48 | */ | 52 | */ |
49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 53 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
50 | #define VER_STR_OLD "ver" | 54 | #define VER_STR_OLD "ver" |
51 | #define COMPAT_VER_OLD "0x02" | 55 | #define COMPAT_VER_OLD "0x02" |
52 | #define CAT_ROOT_OLD "categories" | 56 | #define CAT_ROOT_OLD "categories" |
53 | #define CAT_PREFIX_OLD "cat_" | 57 | #define CAT_PREFIX_OLD "cat_" |
54 | #define CAT_NAME_OLD "name" | 58 | #define CAT_NAME_OLD "name" |
55 | #define ENTRY_PREFIX_OLD"entry_" | 59 | #define ENTRY_PREFIX_OLD"entry_" |
56 | #define ENTRY_DESC_OLD "desc" | 60 | #define ENTRY_DESC_OLD "desc" |
57 | #define ENTRY_NAME_OLD "name" | 61 | #define ENTRY_NAME_OLD "name" |
58 | #define ENTRY_PW_OLD "pw" | 62 | #define ENTRY_PW_OLD "pw" |
59 | #define ENTRY_COMMENT_OLD"comment" | 63 | #define ENTRY_COMMENT_OLD"comment" |
60 | #define ENTRY_URL_OLD "url" | 64 | #define ENTRY_URL_OLD "url" |
61 | #define ENTRY_LAUNCHER_OLD"launcher" | 65 | #define ENTRY_LAUNCHER_OLD"launcher" |
62 | #define ENTRY_LVP_OLD "listViewPos" | 66 | #define ENTRY_LVP_OLD "listViewPos" |
63 | #define ENTRY_BIN_OLD "b" | 67 | #define ENTRY_BIN_OLD "b" |
64 | #define ENTRY_META_OLD "m" | 68 | #define ENTRY_META_OLD "m" |
65 | 69 | ||
66 | #define ROOT_MAGIC_NEW "P" | 70 | #define ROOT_MAGIC_NEW "P" |
67 | #define VER_STR_NEW "v" | 71 | #define VER_STR_NEW "v" |
68 | #define COMPAT_VER_NEW "2" | 72 | #define COMPAT_VER_NEW "2" |
69 | #define CAT_ROOT_NEW "c" | 73 | #define CAT_ROOT_NEW "c" |
70 | #define CAT_PREFIX_NEW "c" | 74 | #define CAT_PREFIX_NEW "c" |
71 | #define CAT_NAME_NEW "n" | 75 | #define CAT_NAME_NEW "n" |
72 | #define ENTRY_PREFIX_NEW"e" | 76 | #define ENTRY_PREFIX_NEW"e" |
73 | #define ENTRY_DESC_NEW "d" | 77 | #define ENTRY_DESC_NEW "d" |
74 | #define ENTRY_NAME_NEW "n" | 78 | #define ENTRY_NAME_NEW "n" |
75 | #define ENTRY_PW_NEW "p" | 79 | #define ENTRY_PW_NEW "p" |
76 | #define ENTRY_COMMENT_NEW"c" | 80 | #define ENTRY_COMMENT_NEW"c" |
77 | #define ENTRY_URL_NEW "u" | 81 | #define ENTRY_URL_NEW "u" |
78 | #define ENTRY_LAUNCHER_NEW"l" | 82 | #define ENTRY_LAUNCHER_NEW"l" |
79 | #define ENTRY_LVP_NEW "v" | 83 | #define ENTRY_LVP_NEW "v" |
80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 84 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
81 | #define ENTRY_META_NEW ENTRY_META_OLD | 85 | #define ENTRY_META_NEW ENTRY_META_OLD |
82 | 86 | ||
83 | #if USE_OLD_TAGS != 0 | 87 | #if USE_OLD_TAGS != 0 |
84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 88 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
85 | # define VER_STR_WR VER_STR_OLD | 89 | # define VER_STR_WR VER_STR_OLD |
86 | # define COMPAT_VER_WR COMPAT_VER_OLD | 90 | # define COMPAT_VER_WR COMPAT_VER_OLD |
87 | # define CAT_ROOT_WR CAT_ROOT_OLD | 91 | # define CAT_ROOT_WR CAT_ROOT_OLD |
88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 92 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
89 | # define CAT_NAME_WR CAT_NAME_OLD | 93 | # define CAT_NAME_WR CAT_NAME_OLD |
90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 94 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 95 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 96 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
93 | # define ENTRY_PW_WR ENTRY_PW_OLD | 97 | # define ENTRY_PW_WR ENTRY_PW_OLD |
94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 98 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
95 | # define ENTRY_URL_WR ENTRY_URL_OLD | 99 | # define ENTRY_URL_WR ENTRY_URL_OLD |
96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 100 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 101 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 102 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
99 | # define ENTRY_META_WR ENTRY_META_OLD | 103 | # define ENTRY_META_WR ENTRY_META_OLD |
100 | #else | 104 | #else |
101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 105 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
102 | # define VER_STR_WR VER_STR_NEW | 106 | # define VER_STR_WR VER_STR_NEW |
103 | # define COMPAT_VER_WR COMPAT_VER_NEW | 107 | # define COMPAT_VER_WR COMPAT_VER_NEW |
104 | # define CAT_ROOT_WR CAT_ROOT_NEW | 108 | # define CAT_ROOT_WR CAT_ROOT_NEW |
105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 109 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
106 | # define CAT_NAME_WR CAT_NAME_NEW | 110 | # define CAT_NAME_WR CAT_NAME_NEW |
107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 111 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 112 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 113 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
110 | # define ENTRY_PW_WR ENTRY_PW_NEW | 114 | # define ENTRY_PW_WR ENTRY_PW_NEW |
111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 115 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
112 | # define ENTRY_URL_WR ENTRY_URL_NEW | 116 | # define ENTRY_URL_WR ENTRY_URL_NEW |
113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 117 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 118 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 119 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
116 | # define ENTRY_META_WR ENTRY_META_NEW | 120 | # define ENTRY_META_WR ENTRY_META_NEW |
117 | #endif | 121 | #endif |
118 | 122 | ||
119 | 123 | ||
120 | Serializer::Serializer() | 124 | Serializer::Serializer() |
121 | { | 125 | { |
122 | defaultLockStat = true; | 126 | defaultLockStat = true; |
123 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 127 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
124 | #ifndef PWM_EMBEDDED | 128 | #ifndef PWM_EMBEDDED |
125 | domDoc = new QDomDocument; | 129 | domDoc = new QDomDocument; |
126 | #else | 130 | #else |
127 | domDoc = new QDomDocument("mydoc"); | 131 | domDoc = new QDomDocument("mydoc"); |
128 | #endif | 132 | #endif |
129 | } | 133 | } |
130 | 134 | ||
131 | Serializer::Serializer(const QCString &buffer) | 135 | Serializer::Serializer(const QCString &buffer) |
132 | { | 136 | { |
133 | defaultLockStat = true; | 137 | defaultLockStat = true; |
134 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 138 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
135 | #ifndef PWM_EMBEDDED | 139 | #ifndef PWM_EMBEDDED |
136 | domDoc = new QDomDocument; | 140 | domDoc = new QDomDocument; |
137 | #else | 141 | #else |
138 | domDoc = new QDomDocument("mydoc"); | 142 | domDoc = new QDomDocument("mydoc"); |
139 | #endif | 143 | #endif |
140 | 144 | ||
141 | if (!parseXml(buffer)) { | 145 | if (!parseXml(buffer)) { |
142 | delete domDoc; | 146 | delete domDoc; |
143 | #ifndef PWM_EMBEDDED | 147 | #ifndef PWM_EMBEDDED |
144 | throw PwMException(PwMException::EX_PARSE); | 148 | throw PwMException(PwMException::EX_PARSE); |
145 | #else | 149 | #else |
146 | qDebug("Serializer::Serializer : Parse Exception "); | 150 | qDebug("Serializer::Serializer : Parse Exception "); |
147 | #endif | 151 | #endif |
148 | } | 152 | } |
149 | } | 153 | } |
150 | 154 | ||
151 | Serializer::~Serializer() | 155 | Serializer::~Serializer() |
152 | { | 156 | { |
153 | delete_ifnot_null(domDoc); | 157 | delete_ifnot_null(domDoc); |
154 | } | 158 | } |
155 | 159 | ||
156 | void Serializer::clear() | 160 | void Serializer::clear() |
157 | { | 161 | { |
158 | delete_ifnot_null(domDoc); | 162 | delete_ifnot_null(domDoc); |
159 | domDoc = new QDomDocument; | 163 | domDoc = new QDomDocument; |
160 | } | 164 | } |
161 | 165 | ||
162 | bool Serializer::parseXml(const QCString &buffer) | 166 | bool Serializer::parseXml(const QCString &buffer) |
163 | { | 167 | { |
164 | PWM_ASSERT(domDoc); | 168 | PWM_ASSERT(domDoc); |
165 | #ifndef PWM_EMBEDDED | 169 | #ifndef PWM_EMBEDDED |
166 | if (!domDoc->setContent(buffer, true)) | 170 | if (!domDoc->setContent(buffer, true)) |
167 | return false; | 171 | return false; |
168 | #else | 172 | #else |
169 | if (!domDoc->setContent(buffer)) | 173 | if (!domDoc->setContent(buffer)) |
170 | return false; | 174 | return false; |
171 | #endif | 175 | #endif |
172 | if (!checkValid()) | 176 | if (!checkValid()) |
173 | return false; | 177 | return false; |
174 | return true; | 178 | return true; |
175 | } | 179 | } |
176 | 180 | ||
177 | QCString Serializer::getXml() | 181 | QCString Serializer::getXml() |
178 | { | 182 | { |
179 | PWM_ASSERT(domDoc); | 183 | PWM_ASSERT(domDoc); |
180 | 184 | ||
181 | #ifndef PWM_EMBEDDED | 185 | #ifndef PWM_EMBEDDED |
182 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 186 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
183 | QCString tmp(domDoc->toCString(8)); | 187 | QCString tmp(domDoc->toCString(8)); |
184 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 188 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
185 | cout << tmp << endl; | 189 | cout << tmp << endl; |
186 | printDebug("<END Serializer::getXml() dump>"); | 190 | printDebug("<END Serializer::getXml() dump>"); |
187 | #endif // DEBUG | 191 | #endif // DEBUG |
188 | 192 | ||
189 | QCString ret(domDoc->toCString(0)); | 193 | QCString ret(domDoc->toCString(0)); |
190 | ret.replace('\n', ""); | 194 | ret.replace('\n', ""); |
191 | return ret; | 195 | return ret; |
192 | #else | 196 | #else |
193 | 197 | ||
194 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 198 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
195 | QCString tmp(" " + domDoc->toCString()); | 199 | QCString tmp(" " + domDoc->toCString()); |
196 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 200 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
197 | qDebug(tmp); | 201 | qDebug(tmp); |
198 | cout << tmp << endl; | 202 | cout << tmp << endl; |
199 | printDebug("<END Serializer::getXml() dump>"); | 203 | printDebug("<END Serializer::getXml() dump>"); |
200 | #endif // DEBUG | 204 | #endif // DEBUG |
201 | 205 | ||
202 | QCString ret(domDoc->toCString()); | 206 | QCString ret(domDoc->toCString()); |
203 | ret.replace(QRegExp("\n"), ""); | 207 | ret.replace(QRegExp("\n"), ""); |
204 | return ret; | 208 | return ret; |
205 | 209 | ||
206 | #endif | 210 | #endif |
207 | } | 211 | } |
208 | 212 | ||
209 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) | 213 | bool Serializer::serialize(PwMItem &dta) |
210 | { | 214 | { |
211 | PWM_ASSERT(domDoc); | 215 | PWM_ASSERT(domDoc); |
212 | QDomElement root(genNewRoot()); | 216 | QDomElement root(genNewRoot()); |
213 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 217 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
214 | root.appendChild(catNode); | 218 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); |
215 | if (!addCategories(&catNode, dta)) | 219 | if (!addSyncData(&syncNode, dta.syncDta)) |
216 | return false; | 220 | return false; |
221 | root.appendChild(syncNode); | ||
222 | if (!addCategories(&catNode, dta.dta)) | ||
223 | return false; | ||
224 | root.appendChild(catNode); | ||
217 | return true; | 225 | return true; |
218 | } | 226 | } |
219 | 227 | ||
220 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | 228 | bool Serializer::deSerialize(PwMItem *dta) |
221 | { | 229 | { |
222 | PWM_ASSERT(domDoc); | 230 | PWM_ASSERT(domDoc); |
223 | PWM_ASSERT(dta); | 231 | PWM_ASSERT(dta); |
224 | QDomElement root(domDoc->documentElement()); | 232 | QDomElement root(domDoc->documentElement()); |
225 | QDomNode n; | 233 | QDomNode n; |
226 | 234 | ||
227 | dta->clear(); | 235 | dta->clear(); |
228 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 236 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
229 | // find <categories> ... </categories> | 237 | // find <categories> ... </categories> |
230 | // <c> ... </c> | 238 | // <c> ... </c> |
231 | if (n.nodeName() == CAT_ROOT_NEW || | 239 | if (n.nodeName() == CAT_ROOT_NEW || |
232 | n.nodeName() == CAT_ROOT_OLD) { | 240 | n.nodeName() == CAT_ROOT_OLD) { |
233 | if (!readCategories(n, dta)) { | 241 | if (!readCategories(n, &(dta->dta))) { |
234 | return false; | 242 | return false; |
235 | } | 243 | } |
244 | continue; | ||
245 | } | ||
246 | else if (n.nodeName() == SYNC_ROOT) { | ||
247 | if (!readSyncData(n, &(dta->syncDta))) { | ||
248 | return false; | ||
249 | } | ||
250 | continue; | ||
251 | } | ||
236 | 252 | ||
237 | /* NOTE: We can stop processing here, as we | 253 | /* NOTE: We can stop processing here, as we |
238 | * don't have more nodes in root, yet. | 254 | * don't have more nodes in root, yet. |
239 | */ | 255 | */ |
240 | return true; | 256 | return false; |
241 | } | 257 | |
242 | } | 258 | } |
243 | return false; | 259 | return true; |
244 | } | 260 | } |
245 | 261 | ||
246 | bool Serializer::readCategories(const QDomNode &n, | 262 | bool Serializer::readCategories(const QDomNode &n, |
247 | vector<PwMCategoryItem> *dta) | 263 | vector<PwMCategoryItem> *dta) |
248 | { | 264 | { |
249 | QDomNodeList nl(n.childNodes()); | 265 | QDomNodeList nl(n.childNodes()); |
250 | QDomNode cur; | 266 | QDomNode cur; |
251 | QString name; | 267 | QString name; |
252 | unsigned int numCat = nl.count(), i; | 268 | unsigned int numCat = nl.count(), i; |
253 | PwMCategoryItem curCat; | 269 | PwMCategoryItem curCat; |
254 | vector<PwMDataItem> curEntr; | 270 | vector<PwMDataItem> curEntr; |
255 | 271 | ||
256 | if (!numCat) { | 272 | if (!numCat) { |
257 | printDebug("Serializer::readCategories(): empty"); | 273 | printDebug("Serializer::readCategories(): empty"); |
258 | return false; | 274 | return false; |
259 | } | 275 | } |
260 | for (i = 0; i < numCat; ++i) { | 276 | for (i = 0; i < numCat; ++i) { |
261 | cur = nl.item(i); | 277 | cur = nl.item(i); |
262 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 278 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
263 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 279 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
264 | name = cur.toElement().attribute(CAT_NAME_NEW); | 280 | name = cur.toElement().attribute(CAT_NAME_NEW); |
265 | if (name == QString::null) | 281 | if (name == QString::null) |
266 | name = cur.toElement().attribute(CAT_NAME_OLD); | 282 | name = cur.toElement().attribute(CAT_NAME_OLD); |
267 | PWM_ASSERT(name != QString::null); | 283 | PWM_ASSERT(name != QString::null); |
268 | PWM_ASSERT(name != ""); | 284 | PWM_ASSERT(name != ""); |
269 | curCat.clear(); | 285 | curCat.clear(); |
270 | curCat.name = name.latin1(); | 286 | curCat.name = name.latin1(); |
271 | if (!readEntries(cur, &curEntr)) { | 287 | if (!readEntries(cur, &curEntr)) { |
272 | dta->clear(); | 288 | dta->clear(); |
273 | return false; | 289 | return false; |
274 | } | 290 | } |
275 | curCat.d = curEntr; | 291 | curCat.d = curEntr; |
276 | dta->push_back(curCat); | 292 | dta->push_back(curCat); |
277 | } else { | 293 | } else { |
278 | printDebug("Serializer::readCategories(): uh? not a category?"); | 294 | printDebug("Serializer::readCategories(): uh? not a category?"); |
279 | } | 295 | } |
280 | } | 296 | } |
281 | return true; | 297 | return true; |
282 | } | 298 | } |
283 | 299 | ||
284 | bool Serializer::readEntries(const QDomNode &n, | 300 | bool Serializer::readEntries(const QDomNode &n, |
285 | vector<PwMDataItem> *dta) | 301 | vector<PwMDataItem> *dta) |
286 | { | 302 | { |
287 | QDomNodeList nl(n.childNodes()); | 303 | QDomNodeList nl(n.childNodes()); |
288 | QDomNode cur; | 304 | QDomNode cur; |
289 | unsigned int numEntr = nl.count(), i; | 305 | unsigned int numEntr = nl.count(), i; |
290 | PwMDataItem curEntr; | 306 | PwMDataItem curEntr; |
291 | 307 | ||
292 | dta->clear(); | 308 | dta->clear(); |
293 | for (i = 0; i < numEntr; ++i) { | 309 | for (i = 0; i < numEntr; ++i) { |
294 | cur = nl.item(i); | 310 | cur = nl.item(i); |
295 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 311 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
296 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 312 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
297 | if (!extractEntry(cur, &curEntr)) { | 313 | if (!extractEntry(cur, &curEntr)) { |
298 | return false; | 314 | return false; |
299 | } | 315 | } |
300 | dta->push_back(curEntr); | 316 | dta->push_back(curEntr); |
301 | } else { | 317 | } else { |
302 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 318 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
303 | } | 319 | } |
304 | } | 320 | } |
305 | return true; | 321 | return true; |
306 | } | 322 | } |
307 | 323 | ||
308 | bool Serializer::extractEntry(const QDomNode &n, | 324 | bool Serializer::extractEntry(const QDomNode &n, |
309 | PwMDataItem *dta) | 325 | PwMDataItem *dta) |
310 | { | 326 | { |
311 | QDomNodeList nl(n.childNodes()); | 327 | QDomNodeList nl(n.childNodes()); |
312 | QDomNode cur, cdata; | 328 | QDomNode cur, cdata; |
313 | unsigned int cnt = nl.count(), i; | 329 | unsigned int cnt = nl.count(), i; |
314 | QString name, text; | 330 | QString name, text; |
315 | 331 | ||
316 | if (!cnt) { | 332 | if (!cnt) { |
317 | printDebug("Serializer::extractEntry(): empty"); | 333 | printDebug("Serializer::extractEntry(): empty"); |
318 | return false; | 334 | return false; |
319 | } | 335 | } |
320 | dta->clear(); | 336 | dta->clear(); |
321 | for (i = 0; i < cnt; ++i) { | 337 | for (i = 0; i < cnt; ++i) { |
322 | cur = nl.item(i); | 338 | cur = nl.item(i); |
323 | name = cur.nodeName(); | 339 | name = cur.nodeName(); |
324 | cdata = cur.firstChild(); | 340 | cdata = cur.firstChild(); |
325 | if (unlikely(cdata.isCDATASection())) { | 341 | if (unlikely(cdata.isCDATASection())) { |
326 | text = cdata.toCDATASection().data(); | 342 | text = cdata.toCDATASection().data(); |
327 | } else if (likely(cur.isElement())) { | 343 | } else if (likely(cur.isElement())) { |
328 | text = cur.toElement().text(); | 344 | text = cur.toElement().text(); |
329 | } else { | 345 | } else { |
330 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 346 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
331 | return false; | 347 | return false; |
332 | } | 348 | } |
333 | if (text == " ") | 349 | if (text == " ") |
334 | text = ""; // for backward compatibility. | 350 | text = ""; // for backward compatibility. |
335 | if (name == ENTRY_DESC_NEW || | 351 | if (name == ENTRY_DESC_NEW || |
336 | name == ENTRY_DESC_OLD) { | 352 | name == ENTRY_DESC_OLD) { |
337 | dta->desc = unescapeEntryData(text).latin1(); | 353 | dta->desc = unescapeEntryData(text).latin1(); |
338 | } else if (name == ENTRY_NAME_NEW || | 354 | } else if (name == ENTRY_NAME_NEW || |
339 | name == ENTRY_NAME_OLD) { | 355 | name == ENTRY_NAME_OLD) { |
340 | dta->name = unescapeEntryData(text).latin1(); | 356 | dta->name = unescapeEntryData(text).latin1(); |
341 | } else if (name == ENTRY_PW_NEW || | 357 | } else if (name == ENTRY_PW_NEW || |
342 | name == ENTRY_PW_OLD) { | 358 | name == ENTRY_PW_OLD) { |
343 | dta->pw = unescapeEntryData(text).latin1(); | 359 | dta->pw = unescapeEntryData(text).latin1(); |
344 | } else if (name == ENTRY_COMMENT_NEW || | 360 | } else if (name == ENTRY_COMMENT_NEW || |
345 | name == ENTRY_COMMENT_OLD) { | 361 | name == ENTRY_COMMENT_OLD) { |
346 | dta->comment = unescapeEntryData(text).latin1(); | 362 | dta->comment = unescapeEntryData(text).latin1(); |
347 | } else if (name == ENTRY_URL_NEW || | 363 | } else if (name == ENTRY_URL_NEW || |
348 | name == ENTRY_URL_OLD) { | 364 | name == ENTRY_URL_OLD) { |
349 | dta->url = unescapeEntryData(text).latin1(); | 365 | dta->url = unescapeEntryData(text).latin1(); |
350 | } else if (name == ENTRY_LAUNCHER_NEW || | 366 | } else if (name == ENTRY_LAUNCHER_NEW || |
351 | name == ENTRY_LAUNCHER_OLD) { | 367 | name == ENTRY_LAUNCHER_OLD) { |
352 | dta->launcher = unescapeEntryData(text).latin1(); | 368 | dta->launcher = unescapeEntryData(text).latin1(); |
353 | } else if (name == ENTRY_LVP_NEW || | 369 | } else if (name == ENTRY_LVP_NEW || |
354 | name == ENTRY_LVP_OLD) { | 370 | name == ENTRY_LVP_OLD) { |
355 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 371 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
356 | } else if (name == ENTRY_BIN_NEW) { | 372 | } else if (name == ENTRY_BIN_NEW) { |
357 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 373 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
358 | if (text == "0") { | 374 | if (text == "0") { |
359 | dta->binary = false; | 375 | dta->binary = false; |
360 | } else { | 376 | } else { |
361 | dta->binary = true; | 377 | dta->binary = true; |
362 | } | 378 | } |
363 | } else if (name == ENTRY_META_NEW) { | 379 | } else if (name == ENTRY_META_NEW) { |
364 | // ENTRY_META_NEW == ENTRY_META_OLD | 380 | // ENTRY_META_NEW == ENTRY_META_OLD |
365 | if (!extractMeta(cur, &dta->meta)) | 381 | if (!extractMeta(cur, &dta->meta)) |
366 | return false; | 382 | return false; |
367 | } else { | 383 | } else { |
368 | printDebug(string("Serializer::extractEntry(): invalid: ") | 384 | printDebug(string("Serializer::extractEntry(): invalid: ") |
369 | + name.latin1()); | 385 | + name.latin1()); |
370 | } | 386 | } |
371 | } | 387 | } |
372 | dta->lockStat = defaultLockStat; | 388 | dta->lockStat = defaultLockStat; |
373 | return true; | 389 | return true; |
374 | } | 390 | } |
375 | 391 | ||
376 | bool Serializer::extractMeta(const QDomNode &n, | 392 | bool Serializer::extractMeta(const QDomNode &n, |
377 | PwMMetaData *dta) | 393 | PwMMetaData *dta) |
378 | { | 394 | { |
379 | QDomNode cur(n.firstChild()); | 395 | QDomNode cur(n.firstChild()); |
380 | QString name, val; | 396 | QString name, val; |
381 | while (!cur.isNull()) { | 397 | while (!cur.isNull()) { |
382 | name = cur.nodeName(); | 398 | name = cur.nodeName(); |
383 | val = cur.toElement().text(); | 399 | val = cur.toElement().text(); |
384 | if (val == "") { | 400 | if (val == "") { |
385 | cur = cur.nextSibling(); | 401 | cur = cur.nextSibling(); |
386 | continue; | 402 | continue; |
387 | } | 403 | } |
388 | #ifndef PWM_EMBEDDED | 404 | #ifndef PWM_EMBEDDED |
389 | if (name == META_CREATE_DATE) { | 405 | if (name == META_CREATE_DATE) { |
390 | dta->create = QDateTime::fromString(val, Qt::ISODate); | 406 | dta->create = QDateTime::fromString(val, Qt::ISODate); |
391 | } else if (name == META_VALID_DATE) { | 407 | } else if (name == META_VALID_DATE) { |
392 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | 408 | dta->valid = QDateTime::fromString(val, Qt::ISODate); |
393 | } else if (name == META_EXPIRE_DATE) { | 409 | } else if (name == META_EXPIRE_DATE) { |
394 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | 410 | dta->expire = QDateTime::fromString(val, Qt::ISODate); |
395 | } else if (name == META_UPDATE_DATE) { | 411 | } else if (name == META_UPDATE_DATE) { |
396 | dta->update = QDateTime::fromString(val, Qt::ISODate); | 412 | dta->update = QDateTime::fromString(val, Qt::ISODate); |
397 | } else if (name == META_UPDATE_INT) { | 413 | } else if (name == META_UPDATE_INT) { |
398 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 414 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
399 | } else if (name == META_UNIQUEID) { | 415 | } else if (name == META_UNIQUEID) { |
400 | dta->uniqueid = unescapeEntryData(val).latin1(); | 416 | dta->uniqueid = unescapeEntryData(val).latin1(); |
401 | } else { | 417 | } else { |
402 | printDebug(string("extractMeta(): invalid: ") | 418 | printDebug(string("extractMeta(): invalid: ") |
403 | + name.latin1()); | 419 | + name.latin1()); |
404 | } | 420 | } |
405 | #else | 421 | #else |
406 | 422 | ||
407 | 423 | ||
408 | bool ok = true; | 424 | bool ok = true; |
409 | 425 | ||
410 | if (name == META_CREATE_DATE) { | 426 | if (name == META_CREATE_DATE) { |
411 | dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 427 | dta->create = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
412 | } else if (name == META_VALID_DATE) { | 428 | } else if (name == META_VALID_DATE) { |
413 | dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 429 | dta->valid = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
414 | } else if (name == META_EXPIRE_DATE) { | 430 | } else if (name == META_EXPIRE_DATE) { |
415 | dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 431 | dta->expire = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
416 | } else if (name == META_UPDATE_DATE) { | 432 | } else if (name == META_UPDATE_DATE) { |
417 | dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 433 | dta->update = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
418 | } else if (name == META_UPDATE_INT) { | 434 | } else if (name == META_UPDATE_INT) { |
419 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 435 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
420 | } else if (name == META_UNIQUEID) { | 436 | } else if (name == META_UNIQUEID) { |
421 | dta->uniqueid = unescapeEntryData(val).latin1(); | 437 | dta->uniqueid = unescapeEntryData(val).latin1(); |
422 | } else { | 438 | } else { |
423 | printDebug(string("extractMeta(): invalid: ") | 439 | printDebug(string("extractMeta(): invalid: ") |
424 | + name.latin1()); | 440 | + name.latin1()); |
425 | } | 441 | } |
426 | 442 | ||
427 | if (ok == false) | 443 | if (ok == false) |
428 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 444 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
429 | 445 | ||
430 | 446 | ||
431 | #endif | 447 | #endif |
432 | cur = cur.nextSibling(); | 448 | cur = cur.nextSibling(); |
433 | } | 449 | } |
434 | return true; | 450 | return true; |
435 | } | 451 | } |
@@ -472,192 +488,269 @@ bool Serializer::addCategories(QDomElement *e, | |||
472 | curId += tostr(i).c_str(); | 488 | curId += tostr(i).c_str(); |
473 | curName = dta[i].name.c_str(); | 489 | curName = dta[i].name.c_str(); |
474 | curCat = domDoc->createElement(curId); | 490 | curCat = domDoc->createElement(curId); |
475 | curCat.setAttribute(CAT_NAME_WR, curName); | 491 | curCat.setAttribute(CAT_NAME_WR, curName); |
476 | if (!addEntries(&curCat, dta[i].d)) { | 492 | if (!addEntries(&curCat, dta[i].d)) { |
477 | return false; | 493 | return false; |
478 | } | 494 | } |
479 | e->appendChild(curCat); | 495 | e->appendChild(curCat); |
480 | } | 496 | } |
481 | return true; | 497 | return true; |
482 | } | 498 | } |
483 | 499 | ||
484 | bool Serializer::addEntries(QDomElement *e, | 500 | bool Serializer::addEntries(QDomElement *e, |
485 | const vector<PwMDataItem> &dta) | 501 | const vector<PwMDataItem> &dta) |
486 | { | 502 | { |
487 | unsigned int numEntr = dta.size(), i; | 503 | unsigned int numEntr = dta.size(), i; |
488 | QString curId; | 504 | QString curId; |
489 | QDomElement curEntr; | 505 | QDomElement curEntr; |
490 | 506 | ||
491 | for (i = 0; i < numEntr; ++i) { | 507 | for (i = 0; i < numEntr; ++i) { |
492 | curId = ENTRY_PREFIX_WR; | 508 | curId = ENTRY_PREFIX_WR; |
493 | curId += tostr(i).c_str(); | 509 | curId += tostr(i).c_str(); |
494 | curEntr = domDoc->createElement(curId); | 510 | curEntr = domDoc->createElement(curId); |
495 | if (!writeEntry(&curEntr, dta[i])) { | 511 | if (!writeEntry(&curEntr, dta[i])) { |
496 | return false; | 512 | return false; |
497 | } | 513 | } |
498 | e->appendChild(curEntr); | 514 | e->appendChild(curEntr); |
499 | } | 515 | } |
500 | return true; | 516 | return true; |
501 | } | 517 | } |
502 | 518 | ||
503 | bool Serializer::writeEntry(QDomElement *e, | 519 | bool Serializer::writeEntry(QDomElement *e, |
504 | const PwMDataItem &_dta) | 520 | const PwMDataItem &_dta) |
505 | { | 521 | { |
506 | #if WRITE_CDATA_SEC != 0 | 522 | #if WRITE_CDATA_SEC != 0 |
507 | # define new_text(x)domDoc->createCDATASection(x) | 523 | # define new_text(x)domDoc->createCDATASection(x) |
508 | QDomCDATASection curText; | 524 | QDomCDATASection curText; |
509 | #else | 525 | #else |
510 | # define new_text(x)domDoc->createTextNode(x) | 526 | # define new_text(x)domDoc->createTextNode(x) |
511 | QDomText curText; | 527 | QDomText curText; |
512 | #endif | 528 | #endif |
513 | 529 | ||
514 | QDomText plainText; | 530 | QDomText plainText; |
515 | QDomElement tag; | 531 | QDomElement tag; |
516 | 532 | ||
517 | // begin -- This is for compatibility with the old serializer | 533 | // begin -- This is for compatibility with the old serializer |
518 | PwMDataItem dta = _dta; | 534 | PwMDataItem dta = _dta; |
519 | if (!dta.desc.size()) | 535 | if (!dta.desc.size()) |
520 | dta.desc = " "; | 536 | dta.desc = " "; |
521 | if (!dta.name.size()) | 537 | if (!dta.name.size()) |
522 | dta.name = " "; | 538 | dta.name = " "; |
523 | if (!dta.pw.size()) | 539 | if (!dta.pw.size()) |
524 | dta.pw = " "; | 540 | dta.pw = " "; |
525 | if (!dta.comment.size()) | 541 | if (!dta.comment.size()) |
526 | dta.comment = " "; | 542 | dta.comment = " "; |
527 | if (!dta.url.size()) | 543 | if (!dta.url.size()) |
528 | dta.url = " "; | 544 | dta.url = " "; |
529 | if (!dta.launcher.size()) | 545 | if (!dta.launcher.size()) |
530 | dta.launcher = " "; | 546 | dta.launcher = " "; |
531 | // end -- This is for compatibility with the old serializer | 547 | // end -- This is for compatibility with the old serializer |
532 | 548 | ||
533 | tag = domDoc->createElement(ENTRY_DESC_WR); | 549 | tag = domDoc->createElement(ENTRY_DESC_WR); |
534 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 550 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
535 | tag.appendChild(curText); | 551 | tag.appendChild(curText); |
536 | e->appendChild(tag); | 552 | e->appendChild(tag); |
537 | 553 | ||
538 | tag = domDoc->createElement(ENTRY_NAME_WR); | 554 | tag = domDoc->createElement(ENTRY_NAME_WR); |
539 | curText = new_text(escapeEntryData(dta.name.c_str())); | 555 | curText = new_text(escapeEntryData(dta.name.c_str())); |
540 | tag.appendChild(curText); | 556 | tag.appendChild(curText); |
541 | e->appendChild(tag); | 557 | e->appendChild(tag); |
542 | 558 | ||
543 | tag = domDoc->createElement(ENTRY_PW_WR); | 559 | tag = domDoc->createElement(ENTRY_PW_WR); |
544 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 560 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
545 | tag.appendChild(curText); | 561 | tag.appendChild(curText); |
546 | e->appendChild(tag); | 562 | e->appendChild(tag); |
547 | 563 | ||
548 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 564 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
549 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 565 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
550 | tag.appendChild(curText); | 566 | tag.appendChild(curText); |
551 | e->appendChild(tag); | 567 | e->appendChild(tag); |
552 | 568 | ||
553 | tag = domDoc->createElement(ENTRY_URL_WR); | 569 | tag = domDoc->createElement(ENTRY_URL_WR); |
554 | curText = new_text(escapeEntryData(dta.url.c_str())); | 570 | curText = new_text(escapeEntryData(dta.url.c_str())); |
555 | tag.appendChild(curText); | 571 | tag.appendChild(curText); |
556 | e->appendChild(tag); | 572 | e->appendChild(tag); |
557 | 573 | ||
558 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 574 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
559 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 575 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
560 | tag.appendChild(curText); | 576 | tag.appendChild(curText); |
561 | e->appendChild(tag); | 577 | e->appendChild(tag); |
562 | 578 | ||
563 | tag = domDoc->createElement(ENTRY_LVP_WR); | 579 | tag = domDoc->createElement(ENTRY_LVP_WR); |
564 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 580 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
565 | tag.appendChild(plainText); | 581 | tag.appendChild(plainText); |
566 | e->appendChild(tag); | 582 | e->appendChild(tag); |
567 | 583 | ||
568 | tag = domDoc->createElement(ENTRY_BIN_WR); | 584 | tag = domDoc->createElement(ENTRY_BIN_WR); |
569 | if (dta.binary) | 585 | if (dta.binary) |
570 | plainText = domDoc->createTextNode("1"); | 586 | plainText = domDoc->createTextNode("1"); |
571 | else | 587 | else |
572 | plainText = domDoc->createTextNode("0"); | 588 | plainText = domDoc->createTextNode("0"); |
573 | tag.appendChild(plainText); | 589 | tag.appendChild(plainText); |
574 | e->appendChild(tag); | 590 | e->appendChild(tag); |
575 | 591 | ||
576 | tag = domDoc->createElement(ENTRY_META_WR); | 592 | tag = domDoc->createElement(ENTRY_META_WR); |
577 | if (!writeMeta(&tag, dta.meta)) | 593 | if (!writeMeta(&tag, dta.meta)) |
578 | return false; | 594 | return false; |
579 | e->appendChild(tag); | 595 | e->appendChild(tag); |
580 | 596 | ||
581 | #undef new_text | 597 | #undef new_text |
582 | return true; | 598 | return true; |
583 | } | 599 | } |
584 | 600 | ||
585 | bool Serializer::writeMeta(QDomElement *e, | 601 | bool Serializer::writeMeta(QDomElement *e, |
586 | const PwMMetaData &dta) | 602 | const PwMMetaData &dta) |
587 | { | 603 | { |
588 | QDomText text; | 604 | QDomText text; |
589 | QDomElement tag; | 605 | QDomElement tag; |
590 | 606 | ||
591 | tag = domDoc->createElement(META_CREATE_DATE); | 607 | tag = domDoc->createElement(META_CREATE_DATE); |
592 | #ifndef PWM_EMBEDDED | 608 | #ifndef PWM_EMBEDDED |
593 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 609 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
594 | #else | 610 | #else |
595 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 611 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
596 | #endif | 612 | #endif |
597 | tag.appendChild(text); | 613 | tag.appendChild(text); |
598 | e->appendChild(tag); | 614 | e->appendChild(tag); |
599 | 615 | ||
600 | tag = domDoc->createElement(META_VALID_DATE); | 616 | tag = domDoc->createElement(META_VALID_DATE); |
601 | #ifndef PWM_EMBEDDED | 617 | #ifndef PWM_EMBEDDED |
602 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 618 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
603 | #else | 619 | #else |
604 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 620 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
605 | #endif | 621 | #endif |
606 | tag.appendChild(text); | 622 | tag.appendChild(text); |
607 | e->appendChild(tag); | 623 | e->appendChild(tag); |
608 | 624 | ||
609 | tag = domDoc->createElement(META_EXPIRE_DATE); | 625 | tag = domDoc->createElement(META_EXPIRE_DATE); |
610 | #ifndef PWM_EMBEDDED | 626 | #ifndef PWM_EMBEDDED |
611 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
612 | #else | 628 | #else |
613 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
614 | #endif | 630 | #endif |
615 | tag.appendChild(text); | 631 | tag.appendChild(text); |
616 | e->appendChild(tag); | 632 | e->appendChild(tag); |
617 | 633 | ||
618 | tag = domDoc->createElement(META_UPDATE_DATE); | 634 | tag = domDoc->createElement(META_UPDATE_DATE); |
619 | #ifndef PWM_EMBEDDED | 635 | #ifndef PWM_EMBEDDED |
620 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
621 | #else | 637 | #else |
622 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
623 | #endif | 639 | #endif |
624 | tag.appendChild(text); | 640 | tag.appendChild(text); |
625 | e->appendChild(tag); | 641 | e->appendChild(tag); |
626 | 642 | ||
627 | tag = domDoc->createElement(META_UPDATE_INT); | 643 | tag = domDoc->createElement(META_UPDATE_INT); |
628 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
629 | tag.appendChild(text); | 645 | tag.appendChild(text); |
630 | e->appendChild(tag); | 646 | e->appendChild(tag); |
631 | 647 | ||
632 | tag = domDoc->createElement(META_UNIQUEID); | 648 | tag = domDoc->createElement(META_UNIQUEID); |
633 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); | 649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); |
634 | tag.appendChild(text); | 650 | tag.appendChild(text); |
635 | e->appendChild(tag); | 651 | e->appendChild(tag); |
636 | 652 | ||
637 | #undef new_text | 653 | #undef new_text |
638 | return true; | 654 | return true; |
639 | } | 655 | } |
640 | 656 | ||
641 | QString Serializer::escapeEntryData(QString dta) | 657 | QString Serializer::escapeEntryData(QString dta) |
642 | { | 658 | { |
643 | #ifndef PWM_EMBEDDED | 659 | #ifndef PWM_EMBEDDED |
644 | dta.replace('\n', "$>--endl--<$"); | 660 | dta.replace('\n', "$>--endl--<$"); |
645 | dta.replace("]]>", "||>"); | 661 | dta.replace("]]>", "||>"); |
646 | #else | 662 | #else |
647 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
648 | dta.replace(QRegExp("]]>"), "||>"); | 664 | dta.replace(QRegExp("]]>"), "||>"); |
649 | #endif | 665 | #endif |
650 | return dta; | 666 | return dta; |
651 | } | 667 | } |
652 | 668 | ||
653 | QString Serializer::unescapeEntryData(QString dta) | 669 | QString Serializer::unescapeEntryData(QString dta) |
654 | { | 670 | { |
655 | #ifndef PWM_EMBEDDED | 671 | #ifndef PWM_EMBEDDED |
656 | dta.replace("$>--endl--<$", "\n"); | 672 | dta.replace("$>--endl--<$", "\n"); |
657 | dta.replace("||>", "]]>"); | 673 | dta.replace("||>", "]]>"); |
658 | #else | 674 | #else |
659 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 675 | dta.replace(QRegExp("$>--endl--<$"), "\n"); |
660 | dta.replace(QRegExp("||>"), "]]>"); | 676 | dta.replace(QRegExp("||>"), "]]>"); |
661 | #endif | 677 | #endif |
662 | return dta; | 678 | return dta; |
663 | } | 679 | } |
680 | |||
681 | |||
682 | //US ENH: the following methods are getting used to write/read sync entries | ||
683 | /** read the syncentries in the node "n" */ | ||
684 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) | ||
685 | { | ||
686 | QDomNodeList nl(n.childNodes()); | ||
687 | QDomNode cur; | ||
688 | |||
689 | QString devicename, val; | ||
690 | unsigned int numSync = nl.count(), i; | ||
691 | PwMSyncItem curSync; | ||
692 | bool ok = true; | ||
693 | |||
694 | if (!numSync) { | ||
695 | //no sync entries is a possible result | ||
696 | printDebug("Serializer::readSyncData(): empty"); | ||
697 | return true; | ||
698 | } | ||
699 | for (i = 0; i < numSync; ++i) { | ||
700 | cur = nl.item(i); | ||
701 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { | ||
702 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); | ||
703 | val = cur.toElement().text(); | ||
704 | |||
705 | if ((val == "") || (devicename == QString::null)) { | ||
706 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); | ||
707 | continue; | ||
708 | } | ||
709 | |||
710 | curSync.syncName = devicename; | ||
711 | #ifndef PWM_EMBEDDED | ||
712 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); | ||
713 | #else | ||
714 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | ||
715 | if (ok == false) | ||
716 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); | ||
717 | |||
718 | #endif | ||
719 | dta->push_back(curSync); | ||
720 | } | ||
721 | } | ||
722 | return true; | ||
723 | |||
724 | } | ||
725 | |||
726 | |||
727 | |||
728 | bool Serializer::addSyncData(QDomElement *e, | ||
729 | const vector<PwMSyncItem> &dta) | ||
730 | { | ||
731 | unsigned int numSync = dta.size(), i; | ||
732 | QString curId, curDeviceName; | ||
733 | QDomElement curSync, curSyncDate; | ||
734 | QDomText text; | ||
735 | |||
736 | for (i = 0; i < numSync; ++i) { | ||
737 | curId = SYNC_TARGET_PREFIX; | ||
738 | curId += tostr(i).c_str(); | ||
739 | curDeviceName = dta[i].syncName.c_str(); | ||
740 | curSync = domDoc->createElement(curId); | ||
741 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); | ||
742 | |||
743 | #ifndef PWM_EMBEDDED | ||
744 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); | ||
745 | #else | ||
746 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); | ||
747 | #endif | ||
748 | curSyncDate.appendChild(text); | ||
749 | curSync.appendChild(curSyncDate); | ||
750 | |||
751 | e->appendChild(curSync); | ||
752 | |||
753 | } | ||
754 | return true; | ||
755 | } | ||
756 | |||
diff --git a/pwmanager/pwmanager/serializer.h b/pwmanager/pwmanager/serializer.h index 245fcee..ee61b94 100644 --- a/pwmanager/pwmanager/serializer.h +++ b/pwmanager/pwmanager/serializer.h | |||
@@ -1,102 +1,115 @@ | |||
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 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 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 | #ifndef __SERIALIZER_H | 21 | #ifndef __SERIALIZER_H |
22 | #define __SERIALIZER_H | 22 | #define __SERIALIZER_H |
23 | 23 | ||
24 | #include "pwmdoc.h" | 24 | #include "pwmdoc.h" |
25 | 25 | ||
26 | #include <qcstring.h> | 26 | #include <qcstring.h> |
27 | #include <qdom.h> | 27 | #include <qdom.h> |
28 | 28 | ||
29 | #include <vector> | 29 | #include <vector> |
30 | 30 | ||
31 | using std::vector; | 31 | using std::vector; |
32 | 32 | ||
33 | /** This serializes its input data into | 33 | /** This serializes its input data into |
34 | * the PwManager-XML-datastream, that becomes | 34 | * the PwManager-XML-datastream, that becomes |
35 | * encrypted and maybe compressed | 35 | * encrypted and maybe compressed |
36 | */ | 36 | */ |
37 | class Serializer | 37 | class Serializer |
38 | { | 38 | { |
39 | public: | 39 | public: |
40 | /** construct an empty serializer document */ | 40 | /** construct an empty serializer document */ |
41 | Serializer(); | 41 | Serializer(); |
42 | /** construct a serializer document and parse "buffer" */ | 42 | /** construct a serializer document and parse "buffer" */ |
43 | Serializer(const QCString &buffer); | 43 | Serializer(const QCString &buffer); |
44 | /** destructor */ | 44 | /** destructor */ |
45 | virtual ~Serializer(); | 45 | virtual ~Serializer(); |
46 | 46 | ||
47 | /** clears all data */ | 47 | /** clears all data */ |
48 | void clear(); | 48 | void clear(); |
49 | /** parse the given data buffer */ | 49 | /** parse the given data buffer */ |
50 | bool parseXml(const QCString &buffer); | 50 | bool parseXml(const QCString &buffer); |
51 | /** returns the current XML data */ | 51 | /** returns the current XML data */ |
52 | QCString getXml(); | 52 | QCString getXml(); |
53 | /** serialize "dta" and store it as XML data */ | 53 | /** serialize "dta" and store it as XML data */ |
54 | bool serialize(const vector<PwMCategoryItem> &dta); | 54 | //US ENH: we need to serialize and deserialize not only categories, but also synctargets |
55 | bool serialize(PwMItem &dta); | ||
55 | /** deserialize the (parsed) XML data and store it in "dta" */ | 56 | /** deserialize the (parsed) XML data and store it in "dta" */ |
56 | bool deSerialize(vector<PwMCategoryItem> *dta); | 57 | bool deSerialize(PwMItem *dta); |
57 | /** sets the initial default lockStat we should assign */ | 58 | /** sets the initial default lockStat we should assign */ |
58 | void setDefaultLockStat(bool stat) | 59 | void setDefaultLockStat(bool stat) |
59 | { defaultLockStat = stat; } | 60 | { defaultLockStat = stat; } |
60 | 61 | ||
61 | protected: | 62 | protected: |
62 | /** main data holder */ | 63 | /** main data holder */ |
63 | QDomDocument *domDoc; | 64 | QDomDocument *domDoc; |
64 | /** default lockStat to assign */ | 65 | /** default lockStat to assign */ |
65 | bool defaultLockStat; | 66 | bool defaultLockStat; |
66 | 67 | ||
67 | protected: | 68 | protected: |
68 | /** check if this is valid PwManager XML data */ | 69 | /** check if this is valid PwManager XML data */ |
69 | bool checkValid(); | 70 | bool checkValid(); |
70 | /** read the categories in the node "n" */ | 71 | /** read the categories in the node "n" */ |
71 | bool readCategories(const QDomNode &n, | 72 | bool readCategories(const QDomNode &n, |
72 | vector<PwMCategoryItem> *dta); | 73 | vector<PwMCategoryItem> *dta); |
73 | /** read the entries in the node "n" */ | 74 | /** read the entries in the node "n" */ |
74 | bool readEntries(const QDomNode &n, | 75 | bool readEntries(const QDomNode &n, |
75 | vector<PwMDataItem> *dta); | 76 | vector<PwMDataItem> *dta); |
76 | /** extract the data out of the given item at "n" */ | 77 | /** extract the data out of the given item at "n" */ |
77 | bool extractEntry(const QDomNode &n, | 78 | bool extractEntry(const QDomNode &n, |
78 | PwMDataItem *dta); | 79 | PwMDataItem *dta); |
79 | /** extract the meta-data */ | 80 | /** extract the meta-data */ |
80 | bool extractMeta(const QDomNode &n, | 81 | bool extractMeta(const QDomNode &n, |
81 | PwMMetaData *dta); | 82 | PwMMetaData *dta); |
82 | /** generates a new root node and sets all initial parameters */ | 83 | /** generates a new root node and sets all initial parameters */ |
83 | QDomElement genNewRoot(); | 84 | QDomElement genNewRoot(); |
84 | /** add new categories to the XML data stream in e */ | 85 | /** add new categories to the XML data stream in e */ |
85 | bool addCategories(QDomElement *e, | 86 | bool addCategories(QDomElement *e, |
86 | const vector<PwMCategoryItem> &dta); | 87 | const vector<PwMCategoryItem> &dta); |
87 | /** add the given new entries to the XML data stream in e */ | 88 | /** add the given new entries to the XML data stream in e */ |
88 | bool addEntries(QDomElement *e, | 89 | bool addEntries(QDomElement *e, |
89 | const vector<PwMDataItem> &dta); | 90 | const vector<PwMDataItem> &dta); |
90 | /** do serialize and write the given entry to the XML stream */ | 91 | /** do serialize and write the given entry to the XML stream */ |
91 | bool writeEntry(QDomElement *e, | 92 | bool writeEntry(QDomElement *e, |
92 | const PwMDataItem &_dta); | 93 | const PwMDataItem &_dta); |
93 | /** write the entry meta data to the xml stream */ | 94 | /** write the entry meta data to the xml stream */ |
94 | bool writeMeta(QDomElement *e, | 95 | bool writeMeta(QDomElement *e, |
95 | const PwMMetaData &dta); | 96 | const PwMMetaData &dta); |
96 | /** escape illegal characters out of the given entry data string */ | 97 | /** escape illegal characters out of the given entry data string */ |
97 | QString escapeEntryData(QString dta); | 98 | QString escapeEntryData(QString dta); |
98 | /** un-escape illegal characters out of the given entry data string */ | 99 | /** un-escape illegal characters out of the given entry data string */ |
99 | QString unescapeEntryData(QString dta); | 100 | QString unescapeEntryData(QString dta); |
101 | |||
102 | |||
103 | |||
104 | //US ENH: the following methods are getting used to write/read sync entries | ||
105 | /** read the syncentries in the node "n" */ | ||
106 | bool readSyncData(const QDomNode &n, | ||
107 | vector<PwMSyncItem> *dta); | ||
108 | |||
109 | /** add new syncentries to the XML data stream in e */ | ||
110 | bool addSyncData(QDomElement *e, | ||
111 | const vector<PwMSyncItem> &dta); | ||
112 | |||
100 | }; | 113 | }; |
101 | 114 | ||
102 | #endif // __SERIALIZER_H | 115 | #endif // __SERIALIZER_H |