author | ulf69 <ulf69> | 2004-10-19 00:47:53 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-19 00:47:53 (UTC) |
commit | 08c6df8a9f7804278ac4029299d9d6de51976856 (patch) (unidiff) | |
tree | 95fc8b69fc8ecaf683e7a62e4305b41f67b48b53 /pwmanager | |
parent | 0f35c6660ed4c304b7c75f2a607f0f27ba436601 (diff) | |
download | kdepimpi-08c6df8a9f7804278ac4029299d9d6de51976856.zip kdepimpi-08c6df8a9f7804278ac4029299d9d6de51976856.tar.gz kdepimpi-08c6df8a9f7804278ac4029299d9d6de51976856.tar.bz2 |
added lastupdate info and removed debug output
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index e53124f..5aaf66e 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,604 +1,609 @@ | |||
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 | #include <qlayout.h> |
39 | 39 | ||
40 | //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. |
41 | //US ENH: for examle in listviewpwm.cpp | 41 | //US ENH: for examle in listviewpwm.cpp |
42 | //US ENH: Because of that I transfer them into the headerfile. | 42 | //US ENH: Because of that I transfer them into the headerfile. |
43 | /* | 43 | /* |
44 | #define COLUMN_DESC 0 | 44 | #define COLUMN_DESC 0 |
45 | #define COLUMN_NAME 1 | 45 | #define COLUMN_NAME 1 |
46 | #define COLUMN_PW 2 | 46 | #define COLUMN_PW 2 |
47 | #define COLUMN_URL 3 | 47 | #define COLUMN_URL 3 |
48 | #define COLUMN_LAUNCHER 4 | 48 | #define COLUMN_LAUNCHER 4 |
49 | */ | 49 | */ |
50 | 50 | ||
51 | PwMView::PwMView(PwM *_mainClass, | 51 | PwMView::PwMView(PwM *_mainClass, |
52 | QWidget *parent, PwMDoc *_doc, | 52 | QWidget *parent, PwMDoc *_doc, |
53 | const char *name) | 53 | const char *name) |
54 | : PwMViewStyle(parent, name) | 54 | : PwMViewStyle(parent, name) |
55 | { | 55 | { |
56 | PWM_ASSERT(_mainClass); | 56 | PWM_ASSERT(_mainClass); |
57 | PWM_ASSERT(parent); | 57 | PWM_ASSERT(parent); |
58 | PWM_ASSERT(_doc); | 58 | PWM_ASSERT(_doc); |
59 | setView(this); | 59 | setView(this); |
60 | doc = _doc; | 60 | doc = _doc; |
61 | doc->setListViewPointer(this); | 61 | doc->setListViewPointer(this); |
62 | mainClass = _mainClass; | 62 | mainClass = _mainClass; |
63 | resize(_mainClass->size()); | 63 | resize(_mainClass->size()); |
64 | initStyle(conf()->confWndMainViewStyle()); | 64 | initStyle(conf()->confWndMainViewStyle()); |
65 | initCtxMenu(); | 65 | initCtxMenu(); |
66 | doc->setCurrentView(this); | 66 | doc->setCurrentView(this); |
67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); | 67 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); |
68 | } | 68 | } |
69 | 69 | ||
70 | PwMView::~PwMView() | 70 | PwMView::~PwMView() |
71 | { | 71 | { |
72 | } | 72 | } |
73 | 73 | ||
74 | void PwMView::initCtxMenu() | 74 | void PwMView::initCtxMenu() |
75 | { | 75 | { |
76 | ctxMenu = new QPopupMenu(this); | 76 | ctxMenu = new QPopupMenu(this); |
77 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); | 77 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); |
78 | ctxMenu->insertSeparator(); | 78 | ctxMenu->insertSeparator(); |
79 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); | 79 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); |
80 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); | 80 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); |
81 | ctxMenu->insertSeparator(); | 81 | ctxMenu->insertSeparator(); |
82 | ctxMenu->insertItem(i18n("copy password to clipboard"), | 82 | ctxMenu->insertItem(i18n("copy password to clipboard"), |
83 | this, SLOT(copyPwToClip())); | 83 | this, SLOT(copyPwToClip())); |
84 | ctxMenu->insertItem(i18n("copy username to clipboard"), | 84 | ctxMenu->insertItem(i18n("copy username to clipboard"), |
85 | this, SLOT(copyNameToClip())); | 85 | this, SLOT(copyNameToClip())); |
86 | ctxMenu->insertItem(i18n("copy description to clipboard"), | 86 | ctxMenu->insertItem(i18n("copy description to clipboard"), |
87 | this, SLOT(copyDescToClip())); | 87 | this, SLOT(copyDescToClip())); |
88 | ctxMenu->insertItem(i18n("copy url to clipboard"), | 88 | ctxMenu->insertItem(i18n("copy url to clipboard"), |
89 | this, SLOT(copyUrlToClip())); | 89 | this, SLOT(copyUrlToClip())); |
90 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), | 90 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), |
91 | this, SLOT(copyLauncherToClip())); | 91 | this, SLOT(copyLauncherToClip())); |
92 | ctxMenu->insertItem(i18n("copy comment to clipboard"), | 92 | ctxMenu->insertItem(i18n("copy comment to clipboard"), |
93 | this, SLOT(copyCommentToClip())); | 93 | this, SLOT(copyCommentToClip())); |
94 | ctxMenu->insertSeparator(); | 94 | ctxMenu->insertSeparator(); |
95 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, | 95 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, |
96 | SLOT(execLauncher_slot())); | 96 | SLOT(execLauncher_slot())); |
97 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, | 97 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, |
98 | SLOT(goToURL_slot())); | 98 | SLOT(goToURL_slot())); |
99 | } | 99 | } |
100 | 100 | ||
101 | void PwMView::resizeEvent(QResizeEvent *) | 101 | void PwMView::resizeEvent(QResizeEvent *) |
102 | { | 102 | { |
103 | resizeView(size()); | 103 | resizeView(size()); |
104 | } | 104 | } |
105 | 105 | ||
106 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) | 106 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) |
107 | { | 107 | { |
108 | PWM_ASSERT(commentBox); | 108 | PWM_ASSERT(commentBox); |
109 | if (!curItem) | 109 | if (!curItem) |
110 | return; | 110 | return; |
111 | string comment; | 111 | string comment; |
112 | PwMerror ret; | 112 | PwMerror ret; |
113 | ret = document()->getCommentByLvp(getCurrentCategory(), | 113 | ret = document()->getCommentByLvp(getCurrentCategory(), |
114 | lv->childCount() - lv->itemIndex(curItem) - 1, | 114 | lv->childCount() - lv->itemIndex(curItem) - 1, |
115 | &comment); | 115 | &comment); |
116 | if (ret == e_binEntry) { | 116 | if (ret == e_binEntry) { |
117 | commentBox->setContent(i18n("This is a binary entry.\n" | 117 | commentBox->setContent(i18n("This is a binary entry.\n" |
118 | "It is not a normal password-entry, as it contains " | 118 | "It is not a normal password-entry, as it contains " |
119 | "binary data, which PwManager can't display here.")); | 119 | "binary data, which PwManager can't display here.")); |
120 | } else if (ret == e_normalEntry) { | 120 | } else if (ret == e_normalEntry) { |
121 | commentBox->setContent(comment.c_str()); | 121 | commentBox->setContent(comment.c_str()); |
122 | } else { | 122 | } else { |
123 | BUG(); | 123 | BUG(); |
124 | return; | 124 | return; |
125 | } | 125 | } |
126 | lv->ensureItemVisible(curItem); | 126 | lv->ensureItemVisible(curItem); |
127 | } | 127 | } |
128 | 128 | ||
129 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) | 129 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) |
130 | { | 130 | { |
131 | refreshCommentTextEdit(lv->currentItem()); | 131 | refreshCommentTextEdit(lv->currentItem()); |
132 | } | 132 | } |
133 | 133 | ||
134 | bool PwMView::getCurEntryIndex(unsigned int *index) | 134 | bool PwMView::getCurEntryIndex(unsigned int *index) |
135 | { | 135 | { |
136 | QListViewItem *current = lv->currentItem(); | 136 | QListViewItem *current = lv->currentItem(); |
137 | if (!current) | 137 | if (!current) |
138 | return false; | 138 | return false; |
139 | return getDocEntryIndex(index, current); | 139 | return getDocEntryIndex(index, current); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool PwMView::getDocEntryIndex(unsigned int *index, | 142 | bool PwMView::getDocEntryIndex(unsigned int *index, |
143 | const QListViewItem *item) | 143 | const QListViewItem *item) |
144 | { | 144 | { |
145 | vector<unsigned int> foundPositions; | 145 | vector<unsigned int> foundPositions; |
146 | PwMDataItem curItem; | 146 | PwMDataItem curItem; |
147 | curItem.desc = item->text(COLUMN_DESC).latin1(); | 147 | curItem.desc = item->text(COLUMN_DESC).latin1(); |
148 | curItem.name = item->text(COLUMN_NAME).latin1(); | 148 | curItem.name = item->text(COLUMN_NAME).latin1(); |
149 | document()->getCommentByLvp(getCurrentCategory(), | 149 | document()->getCommentByLvp(getCurrentCategory(), |
150 | lv->childCount() - lv->itemIndex(item) - 1, | 150 | lv->childCount() - lv->itemIndex(item) - 1, |
151 | &curItem.comment); | 151 | &curItem.comment); |
152 | curItem.url = item->text(COLUMN_URL).latin1(); | 152 | curItem.url = item->text(COLUMN_URL).latin1(); |
153 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); | 153 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); |
154 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | | 154 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | |
155 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | | 155 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | |
156 | SEARCH_IN_LAUNCHER, | 156 | SEARCH_IN_LAUNCHER, |
157 | &foundPositions, true); | 157 | &foundPositions, true); |
158 | if (foundPositions.size()) { | 158 | if (foundPositions.size()) { |
159 | *index = foundPositions[0]; | 159 | *index = foundPositions[0]; |
160 | return true; | 160 | return true; |
161 | } | 161 | } |
162 | 162 | ||
163 | return false; | 163 | return false; |
164 | } | 164 | } |
165 | 165 | ||
166 | void PwMView::handleToggle(QListViewItem *item) | 166 | void PwMView::handleToggle(QListViewItem *item) |
167 | { | 167 | { |
168 | PWM_ASSERT(doc); | 168 | PWM_ASSERT(doc); |
169 | if (!item) | 169 | if (!item) |
170 | return; | 170 | return; |
171 | QCheckListItem *clItem = (QCheckListItem *)item; | 171 | QCheckListItem *clItem = (QCheckListItem *)item; |
172 | QString curCat(getCurrentCategory()); | 172 | QString curCat(getCurrentCategory()); |
173 | 173 | ||
174 | // find document position of this entry. | 174 | // find document position of this entry. |
175 | unsigned int curEntryDocIndex; | 175 | unsigned int curEntryDocIndex; |
176 | if (!getDocEntryIndex(&curEntryDocIndex, item)) | 176 | if (!getDocEntryIndex(&curEntryDocIndex, item)) |
177 | return; | 177 | return; |
178 | 178 | ||
179 | // hack to refresh the comment, if only one item is present | 179 | // hack to refresh the comment, if only one item is present |
180 | if (lv->childCount() == 1) | 180 | if (lv->childCount() == 1) |
181 | refreshCommentTextEdit(lv->currentItem()); | 181 | refreshCommentTextEdit(lv->currentItem()); |
182 | 182 | ||
183 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) | 183 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) |
184 | return; // this is just a click somewhere on the entry | 184 | return; // this is just a click somewhere on the entry |
185 | if (doc->isDeepLocked()) { | 185 | if (doc->isDeepLocked()) { |
186 | PwMerror ret; | 186 | PwMerror ret; |
187 | ret = doc->deepLock(false); | 187 | ret = doc->deepLock(false); |
188 | if (ret != e_success) | 188 | if (ret != e_success) |
189 | clItem->setOn(false); | 189 | clItem->setOn(false); |
190 | return; | 190 | return; |
191 | } | 191 | } |
192 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); | 192 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); |
193 | } | 193 | } |
194 | 194 | ||
195 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) | 195 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) |
196 | { | 196 | { |
197 | if (!item) | 197 | if (!item) |
198 | return; | 198 | return; |
199 | ctxMenu->move(point); | 199 | ctxMenu->move(point); |
200 | /* don't use ctxMenu->exec() here, as it generates race conditions | 200 | /* don't use ctxMenu->exec() here, as it generates race conditions |
201 | * with the card interface code. Believe it or not. :) | 201 | * with the card interface code. Believe it or not. :) |
202 | */ | 202 | */ |
203 | ctxMenu->show(); | 203 | ctxMenu->show(); |
204 | } | 204 | } |
205 | 205 | ||
206 | void PwMView::updateCategories() | 206 | void PwMView::updateCategories() |
207 | { | 207 | { |
208 | QString oldSel(getCurrentCategory()); | 208 | QString oldSel(getCurrentCategory()); |
209 | delAllCategories(); | 209 | delAllCategories(); |
210 | QStringList catList; | 210 | QStringList catList; |
211 | document()->getCategoryList(&catList); | 211 | document()->getCategoryList(&catList); |
212 | catList.sort(); | 212 | catList.sort(); |
213 | #ifndef PWM_EMBEDDED | 213 | #ifndef PWM_EMBEDDED |
214 | QStringList::iterator i = catList.begin(), | 214 | QStringList::iterator i = catList.begin(), |
215 | end = catList.end(); | 215 | end = catList.end(); |
216 | #else | 216 | #else |
217 | QStringList::Iterator i = catList.begin(), | 217 | QStringList::Iterator i = catList.begin(), |
218 | end = catList.end(); | 218 | end = catList.end(); |
219 | #endif | 219 | #endif |
220 | while (i != end) { | 220 | while (i != end) { |
221 | addCategory(*i); | 221 | addCategory(*i); |
222 | ++i; | 222 | ++i; |
223 | } | 223 | } |
224 | selectCategory(oldSel); | 224 | selectCategory(oldSel); |
225 | } | 225 | } |
226 | 226 | ||
227 | void PwMView::shiftToView() | 227 | void PwMView::shiftToView() |
228 | { | 228 | { |
229 | int cX = lv->contentsX(); | 229 | int cX = lv->contentsX(); |
230 | int cY = lv->contentsY(); | 230 | int cY = lv->contentsY(); |
231 | commentBox->clear(); | 231 | commentBox->clear(); |
232 | 232 | ||
233 | unsigned int catDocIndex; | 233 | unsigned int catDocIndex; |
234 | if (unlikely( | 234 | if (unlikely( |
235 | !(document()->findCategory(getCurrentCategory(), | 235 | !(document()->findCategory(getCurrentCategory(), |
236 | &catDocIndex)))) { | 236 | &catDocIndex)))) { |
237 | BUG(); | 237 | BUG(); |
238 | } | 238 | } |
239 | 239 | ||
240 | // ensure all listViewPos are set | 240 | // ensure all listViewPos are set |
241 | doc->ensureLvp(); | 241 | doc->ensureLvp(); |
242 | 242 | ||
243 | // clear all tmp-data vectors | 243 | // clear all tmp-data vectors |
244 | unsigned int i, entries = doc->numEntries(catDocIndex); | 244 | unsigned int i, entries = doc->numEntries(catDocIndex); |
245 | if (entries) { | 245 | if (entries) { |
246 | mainClass->setVirgin(false); | 246 | mainClass->setVirgin(false); |
247 | } | 247 | } |
248 | vector<PwMDataItem> tmpSorted; | 248 | vector<PwMDataItem> tmpSorted; |
249 | PwMDataItem currItem; | 249 | PwMDataItem currItem; |
250 | currItem.clear(); | 250 | currItem.clear(); |
251 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); | 251 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); |
252 | 252 | ||
253 | // Sort items and store them in tempoary tmpSorted. | 253 | // Sort items and store them in tempoary tmpSorted. |
254 | for (i = 0; i < entries; ++i) { | 254 | for (i = 0; i < entries; ++i) { |
255 | doc->getEntry(catDocIndex, i, &currItem); | 255 | doc->getEntry(catDocIndex, i, &currItem); |
256 | //qDebug("PwMView::shiftToView: %s, %i", currItem.desc.c_str(), currItem.listViewPos); | ||
256 | tmpSorted[currItem.listViewPos] = currItem; | 257 | tmpSorted[currItem.listViewPos] = currItem; |
257 | } | 258 | } |
258 | 259 | ||
259 | // shift tempoary data to ListView. | 260 | // shift tempoary data to ListView. |
260 | tmpDisableSort(); | 261 | tmpDisableSort(); |
261 | lv->clear(); | 262 | lv->clear(); |
262 | QCheckListItem *newItem; | 263 | QCheckListItem *newItem; |
263 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), | 264 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), |
264 | end = tmpSorted.end(); | 265 | end = tmpSorted.end(); |
265 | while (it != end) { | 266 | while (it != end) { |
266 | newItem = new ListViewItemPwM(lv); | 267 | newItem = new ListViewItemPwM(lv); |
267 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 268 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
268 | if ((*it).binary) { | 269 | if ((*it).binary) { |
269 | newItem->setText(COLUMN_NAME, ""); | 270 | newItem->setText(COLUMN_NAME, ""); |
270 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 271 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
271 | newItem->setText(COLUMN_URL, ""); | 272 | newItem->setText(COLUMN_URL, ""); |
272 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 273 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
273 | } else { | 274 | } else { |
274 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 275 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
275 | if ((*it).lockStat) { | 276 | if ((*it).lockStat) { |
276 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 277 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
277 | + " " | 278 | + " " |
278 | + i18n("To unlock click the icon on the left.")); | 279 | + i18n("To unlock click the icon on the left.")); |
279 | } else { | 280 | } else { |
280 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 281 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
281 | } | 282 | } |
282 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 283 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
283 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 284 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
284 | } | 285 | } |
285 | newItem->setOn(!((*it).lockStat)); | 286 | newItem->setOn(!((*it).lockStat)); |
286 | lv->insertItem(newItem); | 287 | lv->insertItem(newItem); |
287 | ++it; | 288 | ++it; |
288 | } | 289 | } |
289 | tmpReEnableSort(); | 290 | tmpReEnableSort(); |
290 | 291 | ||
291 | if (cY || cX) | 292 | if (cY || cX) |
292 | lv->setContentsPos(cX, cY); | 293 | lv->setContentsPos(cX, cY); |
293 | } | 294 | } |
294 | 295 | ||
295 | void PwMView::reorgLp() | 296 | void PwMView::reorgLp() |
296 | { | 297 | { |
297 | if (!lv->childCount()) | 298 | if (!lv->childCount()) |
298 | return; | 299 | return; |
299 | PWM_ASSERT(doc); | 300 | PWM_ASSERT(doc); |
300 | PWM_ASSERT(!doc->isDocEmpty()); | 301 | PWM_ASSERT(!doc->isDocEmpty()); |
301 | QListViewItem *currItem; | 302 | QListViewItem *currItem; |
302 | vector<unsigned int> foundPos; | 303 | vector<unsigned int> foundPos; |
303 | /* This searchIn _should_ be: | 304 | /* This searchIn _should_ be: |
304 | *const unsigned int searchIn = SEARCH_IN_DESC; | 305 | *const unsigned int searchIn = SEARCH_IN_DESC; |
305 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 306 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
306 | * So we need to search again, if we don't find the entry. (see below) | 307 | * So we need to search again, if we don't find the entry. (see below) |
307 | */ | 308 | */ |
308 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 309 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
309 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 310 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
310 | QString curCat(getCurrentCategory()); | 311 | QString curCat(getCurrentCategory()); |
311 | PwMDataItem findThis; | 312 | PwMDataItem findThis; |
312 | unsigned int i, cnt = lv->childCount(); | 313 | unsigned int i, cnt = lv->childCount(); |
313 | for (i = 0; i < cnt; ++i) { | 314 | for (i = 0; i < cnt; ++i) { |
314 | currItem = lv->itemAtIndex(i); | 315 | currItem = lv->itemAtIndex(i); |
315 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 316 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
316 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 317 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
317 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 318 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
318 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 319 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
319 | doc->findEntry(curCat, findThis, searchIn, | 320 | doc->findEntry(curCat, findThis, searchIn, |
320 | &foundPos, true); | 321 | &foundPos, true); |
321 | if (!foundPos.size()) { | 322 | if (!foundPos.size()) { |
322 | /* Did not find the entry. We seem to have a binary | 323 | /* Did not find the entry. We seem to have a binary |
323 | * entry here (pray for it!). So search again with | 324 | * entry here (pray for it!). So search again with |
324 | * the "correct" searchIn flags. | 325 | * the "correct" searchIn flags. |
325 | */ | 326 | */ |
326 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 327 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
327 | doc->findEntry(curCat, findThis, searchIn2, | 328 | doc->findEntry(curCat, findThis, searchIn2, |
328 | &foundPos, true); | 329 | &foundPos, true); |
329 | if (unlikely(!foundPos.size())) { | 330 | if (unlikely(!foundPos.size())) { |
330 | BUG(); | 331 | BUG(); |
331 | continue; | 332 | continue; |
332 | } | 333 | } |
333 | /* We assert that it's a binary entry, now. | 334 | /* We assert that it's a binary entry, now. |
334 | * No chance to efficiently verify it here. | 335 | * No chance to efficiently verify it here. |
335 | */ | 336 | */ |
336 | } | 337 | } |
337 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 338 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
338 | } | 339 | } |
339 | } | 340 | } |
340 | 341 | ||
341 | void PwMView::selAt(int index) | 342 | void PwMView::selAt(int index) |
342 | { | 343 | { |
343 | QListViewItem *item = lv->itemAtIndex(index); | 344 | QListViewItem *item = lv->itemAtIndex(index); |
344 | if (!item) | 345 | if (!item) |
345 | return; | 346 | return; |
346 | lv->setCurrentItem(item); | 347 | lv->setCurrentItem(item); |
347 | lv->ensureItemVisible(item); | 348 | lv->ensureItemVisible(item); |
348 | } | 349 | } |
349 | 350 | ||
350 | void PwMView::renCatButton_slot() | 351 | void PwMView::renCatButton_slot() |
351 | { | 352 | { |
352 | if (doc->isDeepLocked()) | 353 | if (doc->isDeepLocked()) |
353 | return; | 354 | return; |
354 | RenCatWnd wnd(this); | 355 | RenCatWnd wnd(this); |
355 | if (wnd.exec() == 1) { | 356 | if (wnd.exec() == 1) { |
356 | QString newName(wnd.getNewName()); | 357 | QString newName(wnd.getNewName()); |
357 | if (newName == "") | 358 | if (newName == "") |
358 | return; | 359 | return; |
359 | document()->renameCategory(getCurrentCategory(), | 360 | document()->renameCategory(getCurrentCategory(), |
360 | newName); | 361 | newName); |
361 | } | 362 | } |
362 | } | 363 | } |
363 | 364 | ||
364 | void PwMView::delCatButton_slot() | 365 | void PwMView::delCatButton_slot() |
365 | { | 366 | { |
366 | if (doc->isDeepLocked()) | 367 | if (doc->isDeepLocked()) |
367 | return; | 368 | return; |
368 | if (numCategories() <= 1) { | 369 | if (numCategories() <= 1) { |
369 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 370 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
370 | return; | 371 | return; |
371 | } | 372 | } |
372 | if (KMessageBox::questionYesNo(this, | 373 | if (KMessageBox::questionYesNo(this, |
373 | i18n("Do you really want to\n" | 374 | i18n("Do you really want to\n" |
374 | "delete the selected\n" | 375 | "delete the selected\n" |
375 | "category? All password-\n" | 376 | "category? All password-\n" |
376 | "entries will be lost in\n" | 377 | "entries will be lost in\n" |
377 | "this category!\n"), | 378 | "this category!\n"), |
378 | i18n("Delete category?")) | 379 | i18n("Delete category?")) |
379 | == KMessageBox::No) { | 380 | == KMessageBox::No) { |
380 | return; | 381 | return; |
381 | } | 382 | } |
382 | document()->delCategory(getCurrentCategory()); | 383 | document()->delCategory(getCurrentCategory()); |
383 | } | 384 | } |
384 | 385 | ||
385 | void PwMView::copyPwToClip() | 386 | void PwMView::copyPwToClip() |
386 | { | 387 | { |
387 | if (doc->isDeepLocked()) | 388 | if (doc->isDeepLocked()) |
388 | return; | 389 | return; |
389 | unsigned int curIndex = 0; | 390 | unsigned int curIndex = 0; |
390 | if (!getCurEntryIndex(&curIndex)) | 391 | if (!getCurEntryIndex(&curIndex)) |
391 | return; | 392 | return; |
392 | PwMDataItem d; | 393 | PwMDataItem d; |
393 | document()->getDataChangedLock(); | 394 | document()->getDataChangedLock(); |
394 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 395 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
395 | document()->putDataChangedLock(); | 396 | document()->putDataChangedLock(); |
396 | PwM::copyToClipboard(d.pw.c_str()); | 397 | PwM::copyToClipboard(d.pw.c_str()); |
397 | } | 398 | } |
398 | 399 | ||
399 | void PwMView::copyNameToClip() | 400 | void PwMView::copyNameToClip() |
400 | { | 401 | { |
401 | if (doc->isDeepLocked()) | 402 | if (doc->isDeepLocked()) |
402 | return; | 403 | return; |
403 | unsigned int curIndex = 0; | 404 | unsigned int curIndex = 0; |
404 | if (!getCurEntryIndex(&curIndex)) | 405 | if (!getCurEntryIndex(&curIndex)) |
405 | return; | 406 | return; |
406 | PwMDataItem d; | 407 | PwMDataItem d; |
407 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 408 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
408 | PwM::copyToClipboard(d.name.c_str()); | 409 | PwM::copyToClipboard(d.name.c_str()); |
409 | } | 410 | } |
410 | 411 | ||
411 | void PwMView::copyDescToClip() | 412 | void PwMView::copyDescToClip() |
412 | { | 413 | { |
413 | if (doc->isDeepLocked()) | 414 | if (doc->isDeepLocked()) |
414 | return; | 415 | return; |
415 | unsigned int curIndex = 0; | 416 | unsigned int curIndex = 0; |
416 | if (!getCurEntryIndex(&curIndex)) | 417 | if (!getCurEntryIndex(&curIndex)) |
417 | return; | 418 | return; |
418 | PwMDataItem d; | 419 | PwMDataItem d; |
419 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 420 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
420 | PwM::copyToClipboard(d.desc.c_str()); | 421 | PwM::copyToClipboard(d.desc.c_str()); |
421 | } | 422 | } |
422 | 423 | ||
423 | void PwMView::copyUrlToClip() | 424 | void PwMView::copyUrlToClip() |
424 | { | 425 | { |
425 | if (doc->isDeepLocked()) | 426 | if (doc->isDeepLocked()) |
426 | return; | 427 | return; |
427 | unsigned int curIndex = 0; | 428 | unsigned int curIndex = 0; |
428 | if (!getCurEntryIndex(&curIndex)) | 429 | if (!getCurEntryIndex(&curIndex)) |
429 | return; | 430 | return; |
430 | PwMDataItem d; | 431 | PwMDataItem d; |
431 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 432 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
432 | PwM::copyToClipboard(d.url.c_str()); | 433 | PwM::copyToClipboard(d.url.c_str()); |
433 | } | 434 | } |
434 | 435 | ||
435 | void PwMView::copyLauncherToClip() | 436 | void PwMView::copyLauncherToClip() |
436 | { | 437 | { |
437 | if (doc->isDeepLocked()) | 438 | if (doc->isDeepLocked()) |
438 | return; | 439 | return; |
439 | unsigned int curIndex = 0; | 440 | unsigned int curIndex = 0; |
440 | if (!getCurEntryIndex(&curIndex)) | 441 | if (!getCurEntryIndex(&curIndex)) |
441 | return; | 442 | return; |
442 | PwMDataItem d; | 443 | PwMDataItem d; |
443 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 444 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
444 | PwM::copyToClipboard(d.launcher.c_str()); | 445 | PwM::copyToClipboard(d.launcher.c_str()); |
445 | } | 446 | } |
446 | 447 | ||
447 | void PwMView::copyCommentToClip() | 448 | void PwMView::copyCommentToClip() |
448 | { | 449 | { |
449 | if (doc->isDeepLocked()) | 450 | if (doc->isDeepLocked()) |
450 | return; | 451 | return; |
451 | unsigned int curIndex = 0; | 452 | unsigned int curIndex = 0; |
452 | if (!getCurEntryIndex(&curIndex)) | 453 | if (!getCurEntryIndex(&curIndex)) |
453 | return; | 454 | return; |
454 | PwMDataItem d; | 455 | PwMDataItem d; |
455 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 456 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
456 | PwM::copyToClipboard(d.comment.c_str()); | 457 | PwM::copyToClipboard(d.comment.c_str()); |
457 | } | 458 | } |
458 | 459 | ||
459 | /************************************************************************ | 460 | /************************************************************************ |
460 | * | 461 | * |
461 | * | 462 | * |
462 | * | 463 | * |
463 | ************************************************************************/ | 464 | ************************************************************************/ |
464 | 465 | ||
465 | 466 | ||
466 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) | 467 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) |
467 | : QTextBrowser( parent, name ) | 468 | : QTextBrowser( parent, name ) |
468 | 469 | ||
469 | 470 | ||
470 | { | 471 | { |
471 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); | 472 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); |
472 | setLinkUnderline( false ); | 473 | setLinkUnderline( false ); |
473 | // setVScrollBarMode( QScrollView::AlwaysOff ); | 474 | // setVScrollBarMode( QScrollView::AlwaysOff ); |
474 | //setHScrollBarMode( QScrollView::AlwaysOff ); | 475 | //setHScrollBarMode( QScrollView::AlwaysOff ); |
475 | 476 | ||
476 | //US QStyleSheet *sheet = styleSheet(); | 477 | //US QStyleSheet *sheet = styleSheet(); |
477 | //US QStyleSheetItem *link = sheet->item( "a" ); | 478 | //US QStyleSheetItem *link = sheet->item( "a" ); |
478 | //US link->setColor( KGlobalSettings::linkColor() ); | 479 | //US link->setColor( KGlobalSettings::linkColor() ); |
479 | 480 | ||
480 | } | 481 | } |
481 | 482 | ||
482 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) | 483 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) |
483 | 484 | ||
484 | { | 485 | { |
485 | mItem = a; | 486 | mItem = a; |
486 | // clear view | 487 | // clear view |
487 | setText( QString::null ); | 488 | setText( QString::null ); |
488 | 489 | ||
489 | 490 | ||
490 | QString dynamicPart; | 491 | QString dynamicPart; |
491 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" | 492 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" |
492 | "<td align=\"left\">%2</td></tr>"; | 493 | "<td align=\"left\">%2</td></tr>"; |
493 | 494 | ||
494 | dynamicPart += format | 495 | dynamicPart += format |
496 | .arg( i18n("LastUpdate") ) | ||
497 | .arg( mItem.meta.update.toString().latin1() ); | ||
498 | |||
499 | dynamicPart += format | ||
495 | .arg( i18n("Description") ) | 500 | .arg( i18n("Description") ) |
496 | .arg( mItem.desc.c_str() ); | 501 | .arg( mItem.desc.c_str() ); |
497 | 502 | ||
498 | dynamicPart += format | 503 | dynamicPart += format |
499 | .arg( i18n("Name") ) | 504 | .arg( i18n("Name") ) |
500 | .arg( mItem.name.c_str() ); | 505 | .arg( mItem.name.c_str() ); |
501 | 506 | ||
502 | dynamicPart += format | 507 | dynamicPart += format |
503 | .arg( i18n("Password") ) | 508 | .arg( i18n("Password") ) |
504 | .arg( mItem.pw.c_str() ); | 509 | .arg( mItem.pw.c_str() ); |
505 | 510 | ||
506 | QString comment(mItem.pw.c_str()); | 511 | QString comment(mItem.pw.c_str()); |
507 | dynamicPart += format | 512 | dynamicPart += format |
508 | .arg( i18n("Comment") ) | 513 | .arg( i18n("Comment") ) |
509 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); | 514 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); |
510 | 515 | ||
511 | dynamicPart += format | 516 | dynamicPart += format |
512 | .arg( i18n("URL") ) | 517 | .arg( i18n("URL") ) |
513 | .arg( mItem.url.c_str() ); | 518 | .arg( mItem.url.c_str() ); |
514 | 519 | ||
515 | dynamicPart += format | 520 | dynamicPart += format |
516 | .arg( i18n("Launcher") ) | 521 | .arg( i18n("Launcher") ) |
517 | .arg( mItem.launcher.c_str() ); | 522 | .arg( mItem.launcher.c_str() ); |
518 | 523 | ||
519 | QString mText = "<table><td colspan=\"2\"> </td>"; | 524 | QString mText = "<table><td colspan=\"2\"> </td>"; |
520 | 525 | ||
521 | mText += dynamicPart; | 526 | mText += dynamicPart; |
522 | mText += "</table>"; | 527 | mText += "</table>"; |
523 | 528 | ||
524 | // at last display it... | 529 | // at last display it... |
525 | setText( mText ); | 530 | setText( mText ); |
526 | 531 | ||
527 | } | 532 | } |
528 | 533 | ||
529 | PwMDataItem PwMDataItemView::pwmdataitem() const | 534 | PwMDataItem PwMDataItemView::pwmdataitem() const |
530 | { | 535 | { |
531 | return mItem; | 536 | return mItem; |
532 | } | 537 | } |
533 | 538 | ||
534 | /************************************************************************ | 539 | /************************************************************************ |
535 | * | 540 | * |
536 | * | 541 | * |
537 | * | 542 | * |
538 | ************************************************************************/ | 543 | ************************************************************************/ |
539 | 544 | ||
540 | 545 | ||
541 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) | 546 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) |
542 | : KDialogBase(parent, name, true , | 547 | : KDialogBase(parent, name, true , |
543 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | 548 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) |
544 | { | 549 | { |
545 | findButton( Close )->setText( i18n("Cancel Sync")); | 550 | findButton( Close )->setText( i18n("Cancel Sync")); |
546 | findButton( Ok )->setText( i18n("Remote")); | 551 | findButton( Ok )->setText( i18n("Remote")); |
547 | findButton( User1 )->setText( i18n("Local")); | 552 | findButton( User1 )->setText( i18n("Local")); |
548 | QWidget* topframe = new QWidget( this ); | 553 | QWidget* topframe = new QWidget( this ); |
549 | setMainWidget( topframe ); | 554 | setMainWidget( topframe ); |
550 | QBoxLayout* bl; | 555 | QBoxLayout* bl; |
551 | if ( QApplication::desktop()->width() < 640 ) { | 556 | if ( QApplication::desktop()->width() < 640 ) { |
552 | bl = new QVBoxLayout( topframe ); | 557 | bl = new QVBoxLayout( topframe ); |
553 | } else { | 558 | } else { |
554 | bl = new QHBoxLayout( topframe ); | 559 | bl = new QHBoxLayout( topframe ); |
555 | } | 560 | } |
556 | QVBox* subframe = new QVBox( topframe ); | 561 | QVBox* subframe = new QVBox( topframe ); |
557 | bl->addWidget(subframe ); | 562 | bl->addWidget(subframe ); |
558 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | 563 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); |
559 | if ( takeloc ) | 564 | if ( takeloc ) |
560 | lab->setBackgroundColor(Qt::green.light() ); | 565 | lab->setBackgroundColor(Qt::green.light() ); |
561 | PwMDataItemView * av = new PwMDataItemView( subframe ); | 566 | PwMDataItemView * av = new PwMDataItemView( subframe ); |
562 | av->setPwMDataItem( loc ); | 567 | av->setPwMDataItem( loc ); |
563 | subframe = new QVBox( topframe ); | 568 | subframe = new QVBox( topframe ); |
564 | bl->addWidget(subframe ); | 569 | bl->addWidget(subframe ); |
565 | lab = new QLabel( i18n("Remote Entry"), subframe ); | 570 | lab = new QLabel( i18n("Remote Entry"), subframe ); |
566 | if ( !takeloc ) | 571 | if ( !takeloc ) |
567 | lab->setBackgroundColor(Qt::green.light() ); | 572 | lab->setBackgroundColor(Qt::green.light() ); |
568 | av = new PwMDataItemView( subframe ); | 573 | av = new PwMDataItemView( subframe ); |
569 | av->setPwMDataItem( rem ); | 574 | av->setPwMDataItem( rem ); |
570 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | 575 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); |
571 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | 576 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); |
572 | #ifndef DESKTOP_VERSION | 577 | #ifndef DESKTOP_VERSION |
573 | showMaximized(); | 578 | showMaximized(); |
574 | #else | 579 | #else |
575 | resize ( 640, 400 ); | 580 | resize ( 640, 400 ); |
576 | #endif | 581 | #endif |
577 | } | 582 | } |
578 | 583 | ||
579 | int PwMDataItemChooser::executeD( bool local ) | 584 | int PwMDataItemChooser::executeD( bool local ) |
580 | { | 585 | { |
581 | mSyncResult = 3; | 586 | mSyncResult = 3; |
582 | if ( local ) | 587 | if ( local ) |
583 | findButton( User1 )->setFocus(); | 588 | findButton( User1 )->setFocus(); |
584 | else | 589 | else |
585 | findButton( Ok )->setFocus(); | 590 | findButton( Ok )->setFocus(); |
586 | exec(); | 591 | exec(); |
587 | return mSyncResult; | 592 | return mSyncResult; |
588 | } | 593 | } |
589 | void PwMDataItemChooser::slot_remote() | 594 | void PwMDataItemChooser::slot_remote() |
590 | { | 595 | { |
591 | mSyncResult = 2; | 596 | mSyncResult = 2; |
592 | accept(); | 597 | accept(); |
593 | } | 598 | } |
594 | void PwMDataItemChooser::slot_local() | 599 | void PwMDataItemChooser::slot_local() |
595 | { | 600 | { |
596 | mSyncResult = 1; | 601 | mSyncResult = 1; |
597 | accept(); | 602 | accept(); |
598 | } | 603 | } |
599 | 604 | ||
600 | 605 | ||
601 | 606 | ||
602 | #ifndef PWM_EMBEDDED | 607 | #ifndef PWM_EMBEDDED |
603 | #include "pwmview.moc" | 608 | #include "pwmview.moc" |
604 | #endif | 609 | #endif |