-rw-r--r-- | pwmanager/pwmanager/editcategory.cpp | 188 | ||||
-rw-r--r-- | pwmanager/pwmanager/editcategory.h | 77 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 69 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanager.pro | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 5 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 14 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 10 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 44 |
10 files changed, 411 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/editcategory.cpp b/pwmanager/pwmanager/editcategory.cpp new file mode 100644 index 0000000..4e55de8 --- a/dev/null +++ b/pwmanager/pwmanager/editcategory.cpp | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | This file is part of PwManager/Platform independent. | ||
3 | Copyright (c) 2004 Ulf Schenk | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | |||
23 | $Id$ | ||
24 | */ | ||
25 | |||
26 | #include "editcategory.h" | ||
27 | #include "pwmdoc.h" | ||
28 | |||
29 | #include <qlayout.h> | ||
30 | #include <qlabel.h> | ||
31 | #include <qgroupbox.h> | ||
32 | #include <klocale.h> | ||
33 | #include <kcombobox.h> | ||
34 | #include <klineedit.h> | ||
35 | #include <qpushbutton.h> | ||
36 | |||
37 | |||
38 | /* | ||
39 | * Constructs a addEntryWnd as a child of 'parent', with the | ||
40 | * name 'name' and widget flags set to 'f'. | ||
41 | * | ||
42 | * The dialog will by default be modeless, unless you set 'modal' to | ||
43 | * TRUE to construct a modal dialog. | ||
44 | */ | ||
45 | editCategoryWnd::editCategoryWnd( PwMDoc* d, QWidget* parent, const char* name) | ||
46 | : KDialogBase( KDialogBase::Plain, i18n( "edit category descriptions" ), | ||
47 | Apply | User2 | Ok, | ||
48 | Ok, parent, name, true ), | ||
49 | doc(d) | ||
50 | { | ||
51 | findButton( Ok )->setText (i18n("Close" )) ; | ||
52 | findButton( User2 )->setText (i18n("Cancel" )) ; | ||
53 | connect(this,SIGNAL(user2Clicked()), SLOT(cancel_slot())); | ||
54 | enableButton( KDialogBase::Apply, false ); | ||
55 | |||
56 | |||
57 | QWidget *page = plainPage(); | ||
58 | QGridLayout *layout = new QGridLayout( page, 3, 1 ); | ||
59 | layout->setMargin( KDialogBase::marginHint() ); | ||
60 | layout->setSpacing( KDialogBase::spacingHint() ); | ||
61 | |||
62 | int i = 0; | ||
63 | categoryComboBox = new KComboBox( page ); | ||
64 | QLabel* label = new QLabel( categoryComboBox, i18n("Category:"), page ); | ||
65 | layout->addWidget( label, i, 0 ); | ||
66 | layout->addWidget( categoryComboBox, i, 1 ); | ||
67 | i++; | ||
68 | categoryComboBox->setEditable( FALSE ); | ||
69 | categoryComboBox->setSizeLimit( 100 ); | ||
70 | connect(categoryComboBox,SIGNAL(activated(const QString&)), SLOT(categorySelected(const QString&))); | ||
71 | |||
72 | |||
73 | descLineEdit = new KLineEdit( page, "descLineEdit" ); | ||
74 | label = new QLabel( descLineEdit, i18n("Text1 (Description):"), page ); | ||
75 | layout->addWidget( label, i, 0 ); | ||
76 | layout->addWidget( descLineEdit, i, 1 ); | ||
77 | connect( descLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) ); | ||
78 | i++; | ||
79 | |||
80 | usernameLineEdit = new KLineEdit( page, "usernameLineEdit" ); | ||
81 | label = new QLabel( usernameLineEdit, i18n("Text2 (Username):"), page ); | ||
82 | layout->addWidget( label, i, 0 ); | ||
83 | layout->addWidget( usernameLineEdit, i, 1 ); | ||
84 | connect( usernameLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) ); | ||
85 | i++; | ||
86 | |||
87 | pwLineEdit = new KLineEdit( page, "pwLineEdit" ); | ||
88 | label = new QLabel( pwLineEdit, i18n("Text3 (Password):"), page ); | ||
89 | layout->addWidget( label, i, 0 ); | ||
90 | layout->addWidget( pwLineEdit, i, 1 ); | ||
91 | connect( pwLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) ); | ||
92 | i++; | ||
93 | |||
94 | unsigned int count = doc->numCategories(); | ||
95 | |||
96 | for (unsigned int i = 0; i < count; ++i) { | ||
97 | categoryComboBox->insertItem(doc->getCategory(i)->c_str()); | ||
98 | } | ||
99 | |||
100 | //PwMCategoryItem* getCategoryEntry(unsigned int index) | ||
101 | // { return &(dti.dta[index]); } | ||
102 | |||
103 | |||
104 | |||
105 | } | ||
106 | |||
107 | /* | ||
108 | * Destroys the object and frees any allocated resources | ||
109 | */ | ||
110 | editCategoryWnd::~editCategoryWnd() | ||
111 | { | ||
112 | // no need to delete child widgets, Qt does it all for us | ||
113 | } | ||
114 | |||
115 | void editCategoryWnd::slotOk() | ||
116 | { | ||
117 | // qDebug( "addEntryWnd::slotOk(): Not implemented yet" ); | ||
118 | slotApply(); | ||
119 | accept(); | ||
120 | } | ||
121 | |||
122 | void editCategoryWnd::slotApply() | ||
123 | { | ||
124 | QString cat = categoryComboBox->currentText(); | ||
125 | |||
126 | unsigned int idx; | ||
127 | bool found = doc->findCategory(cat, &idx); | ||
128 | |||
129 | if (found == true) | ||
130 | { | ||
131 | PwMCategoryItem* catitem = doc->getCategoryEntry(idx); | ||
132 | |||
133 | catitem->desc_text = descLineEdit->text().latin1(); | ||
134 | catitem->name_text = usernameLineEdit->text().latin1(); | ||
135 | catitem->pw_text = pwLineEdit->text().latin1(); | ||
136 | enableButton( KDialogBase::Apply, false ); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | BUG(); | ||
141 | |||
142 | } | ||
143 | |||
144 | void editCategoryWnd::cancel_slot() | ||
145 | { | ||
146 | QString cat = categoryComboBox->currentText(); | ||
147 | categorySelected ( cat ); | ||
148 | } | ||
149 | |||
150 | void editCategoryWnd::setCurrCategory(const QString &cat) | ||
151 | { | ||
152 | int i, count = categoryComboBox->count(); | ||
153 | |||
154 | for (i = 0; i < count; ++i) { | ||
155 | if (categoryComboBox->text(i) == cat) { | ||
156 | categoryComboBox->setCurrentItem(i); | ||
157 | categorySelected ( cat ); | ||
158 | return; | ||
159 | } | ||
160 | } | ||
161 | BUG(); | ||
162 | } | ||
163 | |||
164 | void editCategoryWnd::categorySelected ( const QString & string ) | ||
165 | { | ||
166 | unsigned int idx; | ||
167 | bool found = doc->findCategory(string, &idx); | ||
168 | |||
169 | if (found == true) | ||
170 | { | ||
171 | PwMCategoryItem* catitem = doc->getCategoryEntry(idx); | ||
172 | |||
173 | descLineEdit->setText(catitem->desc_text.c_str()); | ||
174 | usernameLineEdit->setText(catitem->name_text.c_str()); | ||
175 | pwLineEdit->setText(catitem->pw_text.c_str()); | ||
176 | enableButton( KDialogBase::Apply, false ); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | BUG(); | ||
181 | |||
182 | } | ||
183 | |||
184 | void editCategoryWnd::widgetModified(const QString &) | ||
185 | { | ||
186 | enableButton( KDialogBase::Apply, true ); | ||
187 | } | ||
188 | |||
diff --git a/pwmanager/pwmanager/editcategory.h b/pwmanager/pwmanager/editcategory.h new file mode 100644 index 0000000..90b685b --- a/dev/null +++ b/pwmanager/pwmanager/editcategory.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | This file is part of PwManager/Platform independent. | ||
3 | Copyright (c) 2004 Ulf Schenk | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | |||
23 | $Id$ | ||
24 | */ | ||
25 | |||
26 | #ifndef EDITCATEGORY_H | ||
27 | #define EDITCATEGORY_H | ||
28 | |||
29 | #include <qvariant.h> | ||
30 | #include <kdialogbase.h> | ||
31 | |||
32 | class QVBoxLayout; | ||
33 | class QHBoxLayout; | ||
34 | class QGridLayout; | ||
35 | class QSpacerItem; | ||
36 | class KLineEdit; | ||
37 | class QPushButton; | ||
38 | class KComboBox; | ||
39 | class QLabel; | ||
40 | class QGroupBox; | ||
41 | class QMultiLineEdit; | ||
42 | class PwMDoc; | ||
43 | |||
44 | class editCategoryWnd : public KDialogBase | ||
45 | { | ||
46 | Q_OBJECT | ||
47 | |||
48 | public: | ||
49 | editCategoryWnd( PwMDoc* doc, QWidget* parent = 0, const char* name = 0); | ||
50 | ~editCategoryWnd(); | ||
51 | |||
52 | void setCurrCategory(const QString &cat); | ||
53 | |||
54 | KComboBox* categoryComboBox; | ||
55 | KLineEdit* descLineEdit; | ||
56 | KLineEdit* usernameLineEdit; | ||
57 | KLineEdit* pwLineEdit; | ||
58 | |||
59 | //public slots: | ||
60 | // virtual void revealButton_slot(); | ||
61 | // virtual void generateButton_slot(); | ||
62 | // virtual void advancedCommentButton_slot(bool on); | ||
63 | |||
64 | protected slots: | ||
65 | virtual void slotOk(); | ||
66 | virtual void slotApply(); | ||
67 | virtual void cancel_slot(); | ||
68 | |||
69 | virtual void categorySelected ( const QString & string ); | ||
70 | virtual void widgetModified(const QString &); | ||
71 | |||
72 | private: | ||
73 | PwMDoc* doc; | ||
74 | |||
75 | }; | ||
76 | |||
77 | #endif // EDITCATEGORY_H | ||
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index 6ae6e28..bd98d72 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,746 +1,756 @@ | |||
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 <klocale.h> | 20 | #include <klocale.h> |
21 | #include <klistview.h> | 21 | #include <klistview.h> |
22 | #include <ktoolbar.h> | 22 | #include <ktoolbar.h> |
23 | #include <kfiledialog.h> | 23 | #include <kfiledialog.h> |
24 | #include <kiconloader.h> | 24 | #include <kiconloader.h> |
25 | #include <kmessagebox.h> | 25 | #include <kmessagebox.h> |
26 | 26 | ||
27 | #include <qstatusbar.h> | 27 | #include <qstatusbar.h> |
28 | 28 | ||
29 | #ifndef PWM_EMBEDDED | 29 | #ifndef PWM_EMBEDDED |
30 | #include <kmenubar.h> | 30 | #include <kmenubar.h> |
31 | #include <kstatusbar.h> | 31 | #include <kstatusbar.h> |
32 | #include <dcopclient.h> | 32 | #include <dcopclient.h> |
33 | #include "configwndimpl.h" | 33 | #include "configwndimpl.h" |
34 | #include "configuration.h" | 34 | #include "configuration.h" |
35 | #else | 35 | #else |
36 | #include <qmenubar.h> | 36 | #include <qmenubar.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <pwmprefs.h> | 38 | #include <pwmprefs.h> |
39 | #include <kpimglobalprefs.h> | 39 | #include <kpimglobalprefs.h> |
40 | #include <kcmconfigs/kcmpwmconfig.h> | 40 | #include <kcmconfigs/kcmpwmconfig.h> |
41 | #include <kcmconfigs/kcmkdepimconfig.h> | 41 | #include <kcmconfigs/kcmkdepimconfig.h> |
42 | #include <kcmultidialog.h> | 42 | #include <kcmultidialog.h> |
43 | #include "editcategory.h" | ||
43 | #endif | 44 | #endif |
44 | 45 | ||
45 | 46 | ||
46 | #ifndef DESKTOP_VERSION | 47 | #ifndef DESKTOP_VERSION |
47 | #include <qpe/global.h> | 48 | #include <qpe/global.h> |
48 | #endif | 49 | #endif |
49 | 50 | ||
50 | #include <qpixmap.h> | 51 | #include <qpixmap.h> |
51 | #include <qcheckbox.h> | 52 | #include <qcheckbox.h> |
52 | #include <qspinbox.h> | 53 | #include <qspinbox.h> |
53 | #include <qlineedit.h> | 54 | #include <qlineedit.h> |
54 | #include <qfileinfo.h> | 55 | #include <qfileinfo.h> |
55 | #include <qclipboard.h> | 56 | #include <qclipboard.h> |
56 | 57 | ||
57 | 58 | ||
58 | #include <stdio.h> | 59 | #include <stdio.h> |
59 | 60 | ||
60 | #include "pwm.h" | 61 | #include "pwm.h" |
61 | #include "pwminit.h" | 62 | #include "pwminit.h" |
62 | #include "pwmprint.h" | 63 | #include "pwmprint.h" |
63 | #include "addentrywndimpl.h" | 64 | #include "addentrywndimpl.h" |
64 | #include "globalstuff.h" | 65 | #include "globalstuff.h" |
65 | #include "findwndimpl.h" | 66 | #include "findwndimpl.h" |
66 | #include "csv.h" | 67 | #include "csv.h" |
67 | 68 | ||
68 | #ifdef CONFIG_KWALLETIF | 69 | #ifdef CONFIG_KWALLETIF |
69 | # include "kwalletif.h" | 70 | # include "kwalletif.h" |
70 | # include "kwalletemu.h" | 71 | # include "kwalletemu.h" |
71 | #endif | 72 | #endif |
72 | #ifdef CONFIG_KEYCARD | 73 | #ifdef CONFIG_KEYCARD |
73 | # include "pwmkeycard.h" | 74 | # include "pwmkeycard.h" |
74 | #endif | 75 | #endif |
75 | 76 | ||
76 | 77 | ||
77 | #define DEFAULT_SIZE (QSize(700, 400)) | 78 | #define DEFAULT_SIZE (QSize(700, 400)) |
78 | 79 | ||
79 | // Button IDs for "file" popup menu | 80 | // Button IDs for "file" popup menu |
80 | enum { | 81 | enum { |
81 | BUTTON_POPUP_FILE_NEW = 0, | 82 | BUTTON_POPUP_FILE_NEW = 0, |
82 | BUTTON_POPUP_FILE_OPEN, | 83 | BUTTON_POPUP_FILE_OPEN, |
83 | BUTTON_POPUP_FILE_CLOSE, | 84 | BUTTON_POPUP_FILE_CLOSE, |
84 | BUTTON_POPUP_FILE_SAVE, | 85 | BUTTON_POPUP_FILE_SAVE, |
85 | BUTTON_POPUP_FILE_SAVEAS, | 86 | BUTTON_POPUP_FILE_SAVEAS, |
86 | BUTTON_POPUP_FILE_EXPORT, | 87 | BUTTON_POPUP_FILE_EXPORT, |
87 | BUTTON_POPUP_FILE_IMPORT, | 88 | BUTTON_POPUP_FILE_IMPORT, |
88 | BUTTON_POPUP_FILE_PRINT, | 89 | BUTTON_POPUP_FILE_PRINT, |
89 | BUTTON_POPUP_FILE_QUIT | 90 | BUTTON_POPUP_FILE_QUIT |
90 | }; | 91 | }; |
91 | // Button IDs for "manage" popup menu | 92 | // Button IDs for "manage" popup menu |
92 | enum { | 93 | enum { |
93 | BUTTON_POPUP_MANAGE_ADD = 0, | 94 | BUTTON_POPUP_MANAGE_ADD = 0, |
94 | BUTTON_POPUP_MANAGE_EDIT, | 95 | BUTTON_POPUP_MANAGE_EDIT, |
95 | BUTTON_POPUP_MANAGE_DEL, | 96 | BUTTON_POPUP_MANAGE_DEL, |
96 | BUTTON_POPUP_MANAGE_CHANGEMP | 97 | BUTTON_POPUP_MANAGE_CHANGEMP |
97 | }; | 98 | }; |
98 | // Button IDs for chipcard popup menu | 99 | // Button IDs for chipcard popup menu |
99 | enum { | 100 | enum { |
100 | #ifdef CONFIG_KEYCARD | 101 | #ifdef CONFIG_KEYCARD |
101 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, | 102 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, |
102 | BUTTON_POPUP_CHIPCARD_DEL, | 103 | BUTTON_POPUP_CHIPCARD_DEL, |
103 | BUTTON_POPUP_CHIPCARD_READID, | 104 | BUTTON_POPUP_CHIPCARD_READID, |
104 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, | 105 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, |
105 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP | 106 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP |
106 | #else // CONFIG_KEYCARD | 107 | #else // CONFIG_KEYCARD |
107 | BUTTON_POPUP_CHIPCARD_NO = 0 | 108 | BUTTON_POPUP_CHIPCARD_NO = 0 |
108 | #endif // CONFIG_KEYCARD | 109 | #endif // CONFIG_KEYCARD |
109 | }; | 110 | }; |
110 | // Button IDs for "view" popup menu | 111 | // Button IDs for "view" popup menu |
111 | enum { | 112 | enum { |
112 | BUTTON_POPUP_VIEW_FIND = 0, | 113 | BUTTON_POPUP_VIEW_FIND = 0, |
113 | BUTTON_POPUP_VIEW_LOCK, | 114 | BUTTON_POPUP_VIEW_LOCK, |
114 | BUTTON_POPUP_VIEW_DEEPLOCK, | 115 | BUTTON_POPUP_VIEW_DEEPLOCK, |
115 | BUTTON_POPUP_VIEW_UNLOCK | 116 | BUTTON_POPUP_VIEW_UNLOCK |
116 | }; | 117 | }; |
117 | // Button IDs for "options" popup menu | 118 | // Button IDs for "options" popup menu |
118 | enum { | 119 | enum { |
119 | BUTTON_POPUP_OPTIONS_CONFIG = 0 | 120 | BUTTON_POPUP_OPTIONS_CONFIG = 0 |
121 | #ifdef PWM_EMBEDDED | ||
122 | ,BUTTON_POPUP_OPTIONS_CATEGORY | ||
123 | #endif | ||
120 | }; | 124 | }; |
121 | // Button IDs for "export" popup menu (in "file" popup menu) | 125 | // Button IDs for "export" popup menu (in "file" popup menu) |
122 | enum { | 126 | enum { |
123 | BUTTON_POPUP_EXPORT_TEXT = 0, | 127 | BUTTON_POPUP_EXPORT_TEXT = 0, |
124 | BUTTON_POPUP_EXPORT_GPASMAN, | 128 | BUTTON_POPUP_EXPORT_GPASMAN, |
125 | BUTTON_POPUP_EXPORT_CSV | 129 | BUTTON_POPUP_EXPORT_CSV |
126 | #ifdef CONFIG_KWALLETIF | 130 | #ifdef CONFIG_KWALLETIF |
127 | ,BUTTON_POPUP_EXPORT_KWALLET | 131 | ,BUTTON_POPUP_EXPORT_KWALLET |
128 | #endif | 132 | #endif |
129 | }; | 133 | }; |
130 | // Button IDs for "import" popup menu (in "file" popup menu) | 134 | // Button IDs for "import" popup menu (in "file" popup menu) |
131 | enum { | 135 | enum { |
132 | BUTTON_POPUP_IMPORT_TEXT = 0, | 136 | BUTTON_POPUP_IMPORT_TEXT = 0, |
133 | BUTTON_POPUP_IMPORT_GPASMAN, | 137 | BUTTON_POPUP_IMPORT_GPASMAN, |
134 | BUTTON_POPUP_IMPORT_CSV | 138 | BUTTON_POPUP_IMPORT_CSV |
135 | #ifdef CONFIG_KWALLETIF | 139 | #ifdef CONFIG_KWALLETIF |
136 | ,BUTTON_POPUP_IMPORT_KWALLET | 140 | ,BUTTON_POPUP_IMPORT_KWALLET |
137 | #endif | 141 | #endif |
138 | }; | 142 | }; |
139 | 143 | ||
140 | #ifdef PWM_EMBEDDED | 144 | #ifdef PWM_EMBEDDED |
141 | // Button IDs for "help" popup menu | 145 | // Button IDs for "help" popup menu |
142 | enum { | 146 | enum { |
143 | BUTTON_POPUP_HELP_LICENSE = 0, | 147 | BUTTON_POPUP_HELP_LICENSE = 0, |
144 | BUTTON_POPUP_HELP_FAQ, | 148 | BUTTON_POPUP_HELP_FAQ, |
145 | BUTTON_POPUP_HELP_ABOUT, | 149 | BUTTON_POPUP_HELP_ABOUT, |
146 | BUTTON_POPUP_HELP_SYNC, | 150 | BUTTON_POPUP_HELP_SYNC, |
147 | BUTTON_POPUP_HELP_WHATSNEW | 151 | BUTTON_POPUP_HELP_WHATSNEW |
148 | }; | 152 | }; |
149 | #endif | 153 | #endif |
150 | 154 | ||
151 | // Button IDs for toolbar | 155 | // Button IDs for toolbar |
152 | enum { | 156 | enum { |
153 | BUTTON_TOOL_NEW = 0, | 157 | BUTTON_TOOL_NEW = 0, |
154 | BUTTON_TOOL_OPEN, | 158 | BUTTON_TOOL_OPEN, |
155 | BUTTON_TOOL_SAVE, | 159 | BUTTON_TOOL_SAVE, |
156 | BUTTON_TOOL_SAVEAS, | 160 | BUTTON_TOOL_SAVEAS, |
157 | BUTTON_TOOL_PRINT, | 161 | BUTTON_TOOL_PRINT, |
158 | BUTTON_TOOL_ADD, | 162 | BUTTON_TOOL_ADD, |
159 | BUTTON_TOOL_EDIT, | 163 | BUTTON_TOOL_EDIT, |
160 | BUTTON_TOOL_DEL, | 164 | BUTTON_TOOL_DEL, |
161 | BUTTON_TOOL_FIND, | 165 | BUTTON_TOOL_FIND, |
162 | BUTTON_TOOL_LOCK, | 166 | BUTTON_TOOL_LOCK, |
163 | BUTTON_TOOL_DEEPLOCK, | 167 | BUTTON_TOOL_DEEPLOCK, |
164 | BUTTON_TOOL_UNLOCK | 168 | BUTTON_TOOL_UNLOCK |
165 | }; | 169 | }; |
166 | 170 | ||
167 | 171 | ||
168 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 172 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
169 | bool virginity, | 173 | bool virginity, |
170 | QWidget *parent, const char *name) | 174 | QWidget *parent, const char *name) |
171 | : KMainWindow(parent, "HALLO") | 175 | : KMainWindow(parent, "HALLO") |
172 | , forceQuit (false) | 176 | , forceQuit (false) |
173 | , forceMinimizeToTray (false) | 177 | , forceMinimizeToTray (false) |
174 | { | 178 | { |
175 | syncManager = 0; | 179 | syncManager = 0; |
176 | virgin = !virginity; | 180 | virgin = !virginity; |
177 | init = _init; | 181 | init = _init; |
178 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 182 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
179 | this, SLOT(docClosed(PwMDoc *))); | 183 | this, SLOT(docClosed(PwMDoc *))); |
180 | initMenubar(); | 184 | initMenubar(); |
181 | initToolbar(); | 185 | initToolbar(); |
182 | initMetrics(); | 186 | initMetrics(); |
183 | setVirgin(virginity); | 187 | setVirgin(virginity); |
184 | setFocusPolicy(QWidget::WheelFocus); | 188 | setFocusPolicy(QWidget::WheelFocus); |
185 | #ifndef PWM_EMBEDDED | 189 | #ifndef PWM_EMBEDDED |
186 | statusBar()->show(); | 190 | statusBar()->show(); |
187 | #endif | 191 | #endif |
188 | view = makeNewListView(doc); | 192 | view = makeNewListView(doc); |
189 | setCentralWidget(view); | 193 | setCentralWidget(view); |
190 | updateCaption(); | 194 | updateCaption(); |
191 | showStatMsg(i18n("Ready.")); | 195 | showStatMsg(i18n("Ready.")); |
192 | } | 196 | } |
193 | 197 | ||
194 | PwM::~PwM() | 198 | PwM::~PwM() |
195 | { | 199 | { |
196 | qDebug("PwM::~PwM() %x", this); | 200 | qDebug("PwM::~PwM() %x", this); |
197 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 201 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
198 | this, SLOT(docClosed(PwMDoc *))); | 202 | this, SLOT(docClosed(PwMDoc *))); |
199 | conf()->confWndMainWndSize(size()); | 203 | conf()->confWndMainWndSize(size()); |
200 | //LR closing of windows changed | 204 | //LR closing of windows changed |
201 | //needed for fastload option on PDA | 205 | //needed for fastload option on PDA |
202 | //emit closed(this); | 206 | //emit closed(this); |
203 | //qDebug("PwM::~PwM() emited closed(this)"); | 207 | //qDebug("PwM::~PwM() emited closed(this)"); |
204 | delete view; | 208 | delete view; |
205 | delete syncManager; | 209 | delete syncManager; |
206 | } | 210 | } |
207 | 211 | ||
208 | void PwM::initMenubar() | 212 | void PwM::initMenubar() |
209 | { | 213 | { |
210 | KIconLoader* picons; | 214 | KIconLoader* picons; |
211 | #ifndef PWM_EMBEDDED | 215 | #ifndef PWM_EMBEDDED |
212 | KIconLoader icons; | 216 | KIconLoader icons; |
213 | picons = &icons; | 217 | picons = &icons; |
214 | #else | 218 | #else |
215 | picons = KGlobal::iconLoader(); | 219 | picons = KGlobal::iconLoader(); |
216 | 220 | ||
217 | 221 | ||
218 | syncPopup = new KPopupMenu(this); | 222 | syncPopup = new KPopupMenu(this); |
219 | 223 | ||
220 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); | 224 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::PWMPI, PWMPrefs::instance(), syncPopup); |
221 | syncManager->setBlockSave(false); | 225 | syncManager->setBlockSave(false); |
222 | 226 | ||
223 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 227 | connect ( syncPopup, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
224 | syncManager->fillSyncMenu(); | 228 | syncManager->fillSyncMenu(); |
225 | 229 | ||
226 | #endif | 230 | #endif |
227 | filePopup = new KPopupMenu(this); | 231 | filePopup = new KPopupMenu(this); |
228 | importPopup = new KPopupMenu(filePopup); | 232 | importPopup = new KPopupMenu(filePopup); |
229 | exportPopup = new KPopupMenu(filePopup); | 233 | exportPopup = new KPopupMenu(filePopup); |
230 | managePopup = new KPopupMenu(this); | 234 | managePopup = new KPopupMenu(this); |
231 | #ifdef CONFIG_KEYCARD | 235 | #ifdef CONFIG_KEYCARD |
232 | chipcardPopup = new KPopupMenu(this); | 236 | chipcardPopup = new KPopupMenu(this); |
233 | #endif // CONFIG_KEYCARD | 237 | #endif // CONFIG_KEYCARD |
234 | viewPopup = new KPopupMenu(this); | 238 | viewPopup = new KPopupMenu(this); |
235 | optionsPopup = new KPopupMenu(this); | 239 | optionsPopup = new KPopupMenu(this); |
236 | 240 | ||
237 | // "file" popup menu | 241 | // "file" popup menu |
238 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 242 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
239 | i18n("&New"), this, | 243 | i18n("&New"), this, |
240 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 244 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
241 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 245 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
242 | i18n("&Open"), this, | 246 | i18n("&Open"), this, |
243 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 247 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
244 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
245 | i18n("&Close"), this, | 249 | i18n("&Close"), this, |
246 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 250 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
247 | filePopup->insertSeparator(); | 251 | filePopup->insertSeparator(); |
248 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 252 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
249 | i18n("&Save"), this, | 253 | i18n("&Save"), this, |
250 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 254 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
251 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 255 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
252 | i18n("Save &as..."), | 256 | i18n("Save &as..."), |
253 | this, SLOT(saveAs_slot()), 0, | 257 | this, SLOT(saveAs_slot()), 0, |
254 | BUTTON_POPUP_FILE_SAVEAS); | 258 | BUTTON_POPUP_FILE_SAVEAS); |
255 | filePopup->insertSeparator(); | 259 | filePopup->insertSeparator(); |
256 | // "file/export" popup menu | 260 | // "file/export" popup menu |
257 | exportPopup->insertItem(i18n("&Text-file..."), this, | 261 | exportPopup->insertItem(i18n("&Text-file..."), this, |
258 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 262 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
259 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 263 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
260 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 264 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
261 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 265 | exportPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
262 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); | 266 | SLOT(exportToCsv()), 0, BUTTON_POPUP_EXPORT_CSV); |
263 | #ifdef CONFIG_KWALLETIF | 267 | #ifdef CONFIG_KWALLETIF |
264 | exportPopup->insertItem(i18n("&KWallet..."), this, | 268 | exportPopup->insertItem(i18n("&KWallet..."), this, |
265 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 269 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
266 | #endif | 270 | #endif |
267 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 271 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
268 | i18n("E&xport"), exportPopup, | 272 | i18n("E&xport"), exportPopup, |
269 | BUTTON_POPUP_FILE_EXPORT); | 273 | BUTTON_POPUP_FILE_EXPORT); |
270 | // "file/import" popup menu | 274 | // "file/import" popup menu |
271 | importPopup->insertItem(i18n("&Text-file..."), this, | 275 | importPopup->insertItem(i18n("&Text-file..."), this, |
272 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 276 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
273 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 277 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
274 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 278 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
275 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, | 279 | importPopup->insertItem(i18n("&CSV (Comma Separated Value) ..."), this, |
276 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); | 280 | SLOT(importCsv()), 0, BUTTON_POPUP_IMPORT_CSV); |
277 | #ifdef CONFIG_KWALLETIF | 281 | #ifdef CONFIG_KWALLETIF |
278 | importPopup->insertItem(i18n("&KWallet..."), this, | 282 | importPopup->insertItem(i18n("&KWallet..."), this, |
279 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 283 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
280 | #endif | 284 | #endif |
281 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 285 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
282 | i18n("I&mport"), importPopup, | 286 | i18n("I&mport"), importPopup, |
283 | BUTTON_POPUP_FILE_IMPORT); | 287 | BUTTON_POPUP_FILE_IMPORT); |
284 | filePopup->insertSeparator(); | 288 | filePopup->insertSeparator(); |
285 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 289 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
286 | i18n("&Print..."), this, | 290 | i18n("&Print..."), this, |
287 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 291 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
288 | filePopup->insertSeparator(); | 292 | filePopup->insertSeparator(); |
289 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 293 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
290 | i18n("&Quit"), this, | 294 | i18n("&Quit"), this, |
291 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 295 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
292 | menuBar()->insertItem(i18n("&File"), filePopup); | 296 | menuBar()->insertItem(i18n("&File"), filePopup); |
293 | // "manage" popup menu | 297 | // "manage" popup menu |
294 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 298 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
295 | i18n("&Add password"), this, | 299 | i18n("&Add password"), this, |
296 | SLOT(addPwd_slot()), 0, | 300 | SLOT(addPwd_slot()), 0, |
297 | BUTTON_POPUP_MANAGE_ADD); | 301 | BUTTON_POPUP_MANAGE_ADD); |
298 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 302 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
299 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 303 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
300 | BUTTON_POPUP_MANAGE_EDIT); | 304 | BUTTON_POPUP_MANAGE_EDIT); |
301 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 305 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
302 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 306 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
303 | 0, BUTTON_POPUP_MANAGE_DEL); | 307 | 0, BUTTON_POPUP_MANAGE_DEL); |
304 | managePopup->insertSeparator(); | 308 | managePopup->insertSeparator(); |
305 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 309 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
306 | i18n("Change &Master Password"), this, | 310 | i18n("Change &Master Password"), this, |
307 | SLOT(changeMasterPwd_slot()), 0, | 311 | SLOT(changeMasterPwd_slot()), 0, |
308 | BUTTON_POPUP_MANAGE_CHANGEMP); | 312 | BUTTON_POPUP_MANAGE_CHANGEMP); |
309 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 313 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
310 | // "chipcard" popup menu | 314 | // "chipcard" popup menu |
311 | #ifdef CONFIG_KEYCARD | 315 | #ifdef CONFIG_KEYCARD |
312 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 316 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
313 | i18n("&Generate new key-card"), this, | 317 | i18n("&Generate new key-card"), this, |
314 | SLOT(genNewCard_slot()), 0, | 318 | SLOT(genNewCard_slot()), 0, |
315 | BUTTON_POPUP_CHIPCARD_GENNEW); | 319 | BUTTON_POPUP_CHIPCARD_GENNEW); |
316 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 320 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
317 | i18n("&Erase key-card"), this, | 321 | i18n("&Erase key-card"), this, |
318 | SLOT(eraseCard_slot()), 0, | 322 | SLOT(eraseCard_slot()), 0, |
319 | BUTTON_POPUP_CHIPCARD_DEL); | 323 | BUTTON_POPUP_CHIPCARD_DEL); |
320 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 324 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
321 | i18n("Read card-&ID"), this, | 325 | i18n("Read card-&ID"), this, |
322 | SLOT(readCardId_slot()), 0, | 326 | SLOT(readCardId_slot()), 0, |
323 | BUTTON_POPUP_CHIPCARD_READID); | 327 | BUTTON_POPUP_CHIPCARD_READID); |
324 | chipcardPopup->insertSeparator(); | 328 | chipcardPopup->insertSeparator(); |
325 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 329 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
326 | i18n("&Make card backup-image"), this, | 330 | i18n("&Make card backup-image"), this, |
327 | SLOT(makeCardBackup_slot()), 0, | 331 | SLOT(makeCardBackup_slot()), 0, |
328 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 332 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
329 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 333 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
330 | i18n("&Replay card backup-image"), this, | 334 | i18n("&Replay card backup-image"), this, |
331 | SLOT(replayCardBackup_slot()), 0, | 335 | SLOT(replayCardBackup_slot()), 0, |
332 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 336 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
333 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 337 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
334 | #endif // CONFIG_KEYCARD | 338 | #endif // CONFIG_KEYCARD |
335 | // "view" popup menu | 339 | // "view" popup menu |
336 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 340 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
337 | i18n("&Find"), this, | 341 | i18n("&Find"), this, |
338 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 342 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
339 | viewPopup->insertSeparator(); | 343 | viewPopup->insertSeparator(); |
340 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 344 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
341 | i18n("&Lock all entries"), this, | 345 | i18n("&Lock all entries"), this, |
342 | SLOT(lockWnd_slot()), 0, | 346 | SLOT(lockWnd_slot()), 0, |
343 | BUTTON_POPUP_VIEW_LOCK); | 347 | BUTTON_POPUP_VIEW_LOCK); |
344 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 348 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
345 | i18n("&Deep-lock all entries"), this, | 349 | i18n("&Deep-lock all entries"), this, |
346 | SLOT(deepLockWnd_slot()), 0, | 350 | SLOT(deepLockWnd_slot()), 0, |
347 | BUTTON_POPUP_VIEW_DEEPLOCK); | 351 | BUTTON_POPUP_VIEW_DEEPLOCK); |
348 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 352 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
349 | i18n("&Unlock all entries"), this, | 353 | i18n("&Unlock all entries"), this, |
350 | SLOT(unlockWnd_slot()), 0, | 354 | SLOT(unlockWnd_slot()), 0, |
351 | BUTTON_POPUP_VIEW_UNLOCK); | 355 | BUTTON_POPUP_VIEW_UNLOCK); |
352 | menuBar()->insertItem(i18n("&View"), viewPopup); | 356 | menuBar()->insertItem(i18n("&View"), viewPopup); |
353 | // "options" popup menu | 357 | // "options" popup menu |
354 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 358 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
355 | i18n("&Configure..."), this, | 359 | i18n("&Configure..."), this, |
356 | SLOT(config_slot()), | 360 | SLOT(config_slot()), |
357 | BUTTON_POPUP_OPTIONS_CONFIG); | 361 | BUTTON_POPUP_OPTIONS_CONFIG); |
358 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 362 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
359 | // "help" popup menu | 363 | // "help" popup menu |
360 | #ifndef PWM_EMBEDDED | 364 | #ifndef PWM_EMBEDDED |
361 | helpPopup = helpMenu(QString::null, false); | 365 | helpPopup = helpMenu(QString::null, false); |
362 | #else | 366 | #else |
367 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | ||
368 | i18n("C&ategories..."), this, | ||
369 | SLOT(category_slot()), | ||
370 | BUTTON_POPUP_OPTIONS_CATEGORY); | ||
371 | |||
372 | |||
363 | menuBar()->insertItem(i18n("&Sync"), syncPopup); | 373 | menuBar()->insertItem(i18n("&Sync"), syncPopup); |
364 | 374 | ||
365 | 375 | ||
366 | 376 | ||
367 | 377 | ||
368 | 378 | ||
369 | helpPopup = new KPopupMenu(this); | 379 | helpPopup = new KPopupMenu(this); |
370 | 380 | ||
371 | 381 | ||
372 | helpPopup->insertItem(i18n("&License"), this, | 382 | helpPopup->insertItem(i18n("&License"), this, |
373 | SLOT(showLicense_slot()), 0, | 383 | SLOT(showLicense_slot()), 0, |
374 | BUTTON_POPUP_HELP_LICENSE); | 384 | BUTTON_POPUP_HELP_LICENSE); |
375 | 385 | ||
376 | helpPopup->insertItem(i18n("&Faq"), this, | 386 | helpPopup->insertItem(i18n("&Faq"), this, |
377 | SLOT(faq_slot()), 0, | 387 | SLOT(faq_slot()), 0, |
378 | BUTTON_POPUP_HELP_FAQ); | 388 | BUTTON_POPUP_HELP_FAQ); |
379 | 389 | ||
380 | helpPopup->insertItem(i18n("&About PwManager"), this, | 390 | helpPopup->insertItem(i18n("&About PwManager"), this, |
381 | SLOT(createAboutData_slot()), 0, | 391 | SLOT(createAboutData_slot()), 0, |
382 | BUTTON_POPUP_HELP_ABOUT); | 392 | BUTTON_POPUP_HELP_ABOUT); |
383 | 393 | ||
384 | helpPopup->insertItem(i18n("&Sync HowTo"), this, | 394 | helpPopup->insertItem(i18n("&Sync HowTo"), this, |
385 | SLOT(syncHowTo_slot()), 0, | 395 | SLOT(syncHowTo_slot()), 0, |
386 | BUTTON_POPUP_HELP_SYNC); | 396 | BUTTON_POPUP_HELP_SYNC); |
387 | 397 | ||
388 | helpPopup->insertItem(i18n("&What's New"), this, | 398 | helpPopup->insertItem(i18n("&What's New"), this, |
389 | SLOT(whatsnew_slot()), 0, | 399 | SLOT(whatsnew_slot()), 0, |
390 | BUTTON_POPUP_HELP_WHATSNEW); | 400 | BUTTON_POPUP_HELP_WHATSNEW); |
391 | 401 | ||
392 | #endif | 402 | #endif |
393 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 403 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
394 | 404 | ||
395 | } | 405 | } |
396 | 406 | ||
397 | void PwM::initToolbar() | 407 | void PwM::initToolbar() |
398 | { | 408 | { |
399 | KIconLoader* picons; | 409 | KIconLoader* picons; |
400 | #ifndef PWM_EMBEDDED | 410 | #ifndef PWM_EMBEDDED |
401 | KIconLoader icons; | 411 | KIconLoader icons; |
402 | picons = &icons; | 412 | picons = &icons; |
403 | #else | 413 | #else |
404 | picons = KGlobal::iconLoader(); | 414 | picons = KGlobal::iconLoader(); |
405 | #endif | 415 | #endif |
406 | 416 | ||
407 | #ifdef PWM_EMBEDDED | 417 | #ifdef PWM_EMBEDDED |
408 | if ( QApplication::desktop()->width() > 320 ) | 418 | if ( QApplication::desktop()->width() > 320 ) |
409 | #endif | 419 | #endif |
410 | { | 420 | { |
411 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 421 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
412 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 422 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
413 | SLOT(new_slot()), true, i18n("New")); | 423 | SLOT(new_slot()), true, i18n("New")); |
414 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 424 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
415 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 425 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
416 | SLOT(open_slot()), true, i18n("Open")); | 426 | SLOT(open_slot()), true, i18n("Open")); |
417 | toolBar()->insertSeparator(); | 427 | toolBar()->insertSeparator(); |
418 | } | 428 | } |
419 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), | 429 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), |
420 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, | 430 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, |
421 | SLOT(save_slot()), true, i18n("Save")); | 431 | SLOT(save_slot()), true, i18n("Save")); |
422 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), | 432 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), |
423 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, | 433 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, |
424 | SLOT(saveAs_slot()), true, i18n("Save as")); | 434 | SLOT(saveAs_slot()), true, i18n("Save as")); |
425 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), | 435 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), |
426 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, | 436 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, |
427 | SLOT(print_slot()), true, i18n("Print...")); | 437 | SLOT(print_slot()), true, i18n("Print...")); |
428 | toolBar()->insertSeparator(); | 438 | toolBar()->insertSeparator(); |
429 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), | 439 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), |
430 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, | 440 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, |
431 | SLOT(addPwd_slot()), true, | 441 | SLOT(addPwd_slot()), true, |
432 | i18n("Add password")); | 442 | i18n("Add password")); |
433 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), | 443 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), |
434 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, | 444 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, |
435 | SLOT(editPwd_slot()), true, | 445 | SLOT(editPwd_slot()), true, |
436 | i18n("Edit password")); | 446 | i18n("Edit password")); |
437 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), | 447 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), |
438 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, | 448 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, |
439 | SLOT(deletePwd_slot()), true, | 449 | SLOT(deletePwd_slot()), true, |
440 | i18n("Delete password")); | 450 | i18n("Delete password")); |
441 | toolBar()->insertSeparator(); | 451 | toolBar()->insertSeparator(); |
442 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), | 452 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), |
443 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, | 453 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, |
444 | SLOT(find_slot()), true, i18n("Find entry")); | 454 | SLOT(find_slot()), true, i18n("Find entry")); |
445 | toolBar()->insertSeparator(); | 455 | toolBar()->insertSeparator(); |
446 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), | 456 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), |
447 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, | 457 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, |
448 | SLOT(lockWnd_slot()), true, | 458 | SLOT(lockWnd_slot()), true, |
449 | i18n("Lock all entries")); | 459 | i18n("Lock all entries")); |
450 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), | 460 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), |
451 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, | 461 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, |
452 | SLOT(deepLockWnd_slot()), true, | 462 | SLOT(deepLockWnd_slot()), true, |
453 | i18n("Deep-Lock all entries")); | 463 | i18n("Deep-Lock all entries")); |
454 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), | 464 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), |
455 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, | 465 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, |
456 | SLOT(unlockWnd_slot()), true, | 466 | SLOT(unlockWnd_slot()), true, |
457 | i18n("Unlock all entries")); | 467 | i18n("Unlock all entries")); |
458 | } | 468 | } |
459 | 469 | ||
460 | void PwM::initMetrics() | 470 | void PwM::initMetrics() |
461 | { | 471 | { |
462 | QSize s = conf()->confWndMainWndSize(); | 472 | QSize s = conf()->confWndMainWndSize(); |
463 | if (s.isValid()) | 473 | if (s.isValid()) |
464 | resize(s); | 474 | resize(s); |
465 | else | 475 | else |
466 | resize(DEFAULT_SIZE); | 476 | resize(DEFAULT_SIZE); |
467 | } | 477 | } |
468 | 478 | ||
469 | void PwM::updateCaption() | 479 | void PwM::updateCaption() |
470 | { | 480 | { |
471 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); | 481 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); |
472 | } | 482 | } |
473 | 483 | ||
474 | void PwM::hideEvent(QHideEvent *) | 484 | void PwM::hideEvent(QHideEvent *) |
475 | { | 485 | { |
476 | if (isMinimized()) { | 486 | if (isMinimized()) { |
477 | if (init->tray()) { | 487 | if (init->tray()) { |
478 | forceMinimizeToTray = true; | 488 | forceMinimizeToTray = true; |
479 | close(); | 489 | close(); |
480 | } | 490 | } |
481 | int mmlock = conf()->confGlobMinimizeLock(); | 491 | int mmlock = conf()->confGlobMinimizeLock(); |
482 | switch (mmlock) { | 492 | switch (mmlock) { |
483 | case 0: // don't lock anything | 493 | case 0: // don't lock anything |
484 | break; | 494 | break; |
485 | case 1: {// normal lock | 495 | case 1: {// normal lock |
486 | curDoc()->lockAll(true); | 496 | curDoc()->lockAll(true); |
487 | break; | 497 | break; |
488 | } case 2: {// deep-lock | 498 | } case 2: {// deep-lock |
489 | curDoc()->deepLock(); | 499 | curDoc()->deepLock(); |
490 | break; | 500 | break; |
491 | } default: | 501 | } default: |
492 | WARN(); | 502 | WARN(); |
493 | } | 503 | } |
494 | } | 504 | } |
495 | } | 505 | } |
496 | 506 | ||
497 | void PwM::setVirgin(bool v) | 507 | void PwM::setVirgin(bool v) |
498 | { | 508 | { |
499 | if (virgin == v) | 509 | if (virgin == v) |
500 | return; | 510 | return; |
501 | virgin = v; | 511 | virgin = v; |
502 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); | 512 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); |
503 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); | 513 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); |
504 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); | 514 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); |
505 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); | 515 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); |
506 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); | 516 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); |
507 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); | 517 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); |
508 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); | 518 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); |
509 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); | 519 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); |
510 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); | 520 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); |
511 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); | 521 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); |
512 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); | 522 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); |
513 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); | 523 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); |
514 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); | 524 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); |
515 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); | 525 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); |
516 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); | 526 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); |
517 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); | 527 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); |
518 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); | 528 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); |
519 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); | 529 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); |
520 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); | 530 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); |
521 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); | 531 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); |
522 | } | 532 | } |
523 | 533 | ||
524 | void PwM::new_slot() | 534 | void PwM::new_slot() |
525 | { | 535 | { |
526 | init->createMainWnd(); | 536 | init->createMainWnd(); |
527 | } | 537 | } |
528 | 538 | ||
529 | //US ENH | 539 | //US ENH |
530 | void PwM::open_slot() | 540 | void PwM::open_slot() |
531 | { | 541 | { |
532 | open_slot(""); | 542 | open_slot(""); |
533 | } | 543 | } |
534 | 544 | ||
535 | void PwM::open_slot(QString fn) | 545 | void PwM::open_slot(QString fn) |
536 | { | 546 | { |
537 | openDoc(fn); | 547 | openDoc(fn); |
538 | } | 548 | } |
539 | 549 | ||
540 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) | 550 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) |
541 | { | 551 | { |
542 | if (!isVirgin()) { | 552 | if (!isVirgin()) { |
543 | // open the document in a new window. | 553 | // open the document in a new window. |
544 | PwM *newInstance = init->createMainWnd(); | 554 | PwM *newInstance = init->createMainWnd(); |
545 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); | 555 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); |
546 | if (!newDoc) { | 556 | if (!newDoc) { |
547 | newInstance->setForceQuit(true); | 557 | newInstance->setForceQuit(true); |
548 | delete_and_null(newInstance); | 558 | delete_and_null(newInstance); |
549 | } | 559 | } |
550 | return newDoc; | 560 | return newDoc; |
551 | } | 561 | } |
552 | 562 | ||
553 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) | 563 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) |
554 | return 0; | 564 | return 0; |
555 | showStatMsg(i18n("Successfully opened file.")); | 565 | showStatMsg(i18n("Successfully opened file.")); |
556 | updateCaption(); | 566 | updateCaption(); |
557 | setVirgin(false); | 567 | setVirgin(false); |
558 | return curDoc(); | 568 | return curDoc(); |
559 | } | 569 | } |
560 | 570 | ||
561 | PwMView * PwM::makeNewListView(PwMDoc *doc) | 571 | PwMView * PwM::makeNewListView(PwMDoc *doc) |
562 | { | 572 | { |
563 | PwMView *ret = new PwMView(this, this, doc); | 573 | PwMView *ret = new PwMView(this, this, doc); |
564 | ret->setFont(conf()->confGlobEntryFont()); | 574 | ret->setFont(conf()->confGlobEntryFont()); |
565 | ret->show(); | 575 | ret->show(); |
566 | return ret; | 576 | return ret; |
567 | } | 577 | } |
568 | 578 | ||
569 | void PwM::close_slot() | 579 | void PwM::close_slot() |
570 | { | 580 | { |
571 | close(); | 581 | close(); |
572 | } | 582 | } |
573 | 583 | ||
574 | void PwM::quitButton_slot() | 584 | void PwM::quitButton_slot() |
575 | { | 585 | { |
576 | init->shutdownApp(0); | 586 | init->shutdownApp(0); |
577 | } | 587 | } |
578 | 588 | ||
579 | void PwM::save_slot() | 589 | void PwM::save_slot() |
580 | { | 590 | { |
581 | save(); | 591 | save(); |
582 | } | 592 | } |
583 | 593 | ||
584 | bool PwM::save() | 594 | bool PwM::save() |
585 | { | 595 | { |
586 | if (!curDoc()->saveDocUi(curDoc())) | 596 | if (!curDoc()->saveDocUi(curDoc())) |
587 | return false; | 597 | return false; |
588 | showStatMsg(i18n("Successfully saved data.")); | 598 | showStatMsg(i18n("Successfully saved data.")); |
589 | updateCaption(); | 599 | updateCaption(); |
590 | return true; | 600 | return true; |
591 | } | 601 | } |
592 | 602 | ||
593 | void PwM::saveAs_slot() | 603 | void PwM::saveAs_slot() |
594 | { | 604 | { |
595 | saveAs(); | 605 | saveAs(); |
596 | } | 606 | } |
597 | 607 | ||
598 | bool PwM::saveAs() | 608 | bool PwM::saveAs() |
599 | { | 609 | { |
600 | if (!curDoc()->saveAsDocUi(curDoc())) | 610 | if (!curDoc()->saveAsDocUi(curDoc())) |
601 | return false; | 611 | return false; |
602 | showStatMsg(i18n("Successfully saved data.")); | 612 | showStatMsg(i18n("Successfully saved data.")); |
603 | updateCaption(); | 613 | updateCaption(); |
604 | return true; | 614 | return true; |
605 | } | 615 | } |
606 | 616 | ||
607 | //US ENH : changed code to run with older MOC | 617 | //US ENH : changed code to run with older MOC |
608 | void PwM::addPwd_slot() | 618 | void PwM::addPwd_slot() |
609 | { | 619 | { |
610 | addPwd_slot1(0, 0); | 620 | addPwd_slot1(0, 0); |
611 | } | 621 | } |
612 | 622 | ||
613 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) | 623 | void PwM::addPwd_slot1(QString *pw, PwMDoc *_doc) |
614 | { | 624 | { |
615 | PwMDoc *doc; | 625 | PwMDoc *doc; |
616 | if (_doc) { | 626 | if (_doc) { |
617 | doc = _doc; | 627 | doc = _doc; |
618 | } else { | 628 | } else { |
619 | doc = curDoc(); | 629 | doc = curDoc(); |
620 | } | 630 | } |
621 | PWM_ASSERT(doc); | 631 | PWM_ASSERT(doc); |
622 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 632 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
623 | #ifndef PWM_EMBEDDED | 633 | #ifndef PWM_EMBEDDED |
624 | AddEntryWndImpl w; | 634 | AddEntryWndImpl w; |
625 | #else | 635 | #else |
626 | AddEntryWndImpl w(this, "addentrywndimpl"); | 636 | AddEntryWndImpl w(this, "addentrywndimpl"); |
627 | #endif | 637 | #endif |
628 | 638 | ||
629 | vector<string> catList; | 639 | vector<string> catList; |
630 | doc->getCategoryList(&catList); | 640 | doc->getCategoryList(&catList); |
631 | unsigned i, size = catList.size(); | 641 | unsigned i, size = catList.size(); |
632 | for (i = 0; i < size; ++i) { | 642 | for (i = 0; i < size; ++i) { |
633 | w.addCategory(catList[i].c_str()); | 643 | w.addCategory(catList[i].c_str()); |
634 | } | 644 | } |
635 | w.setCurrCategory(view->getCurrentCategory()); | 645 | w.setCurrCategory(view->getCurrentCategory()); |
636 | if (pw) | 646 | if (pw) |
637 | w.pwLineEdit->setText(*pw); | 647 | w.pwLineEdit->setText(*pw); |
638 | 648 | ||
639 | tryAgain: | 649 | tryAgain: |
640 | if (w.exec() == 1) | 650 | if (w.exec() == 1) |
641 | { | 651 | { |
642 | PwMDataItem d; | 652 | PwMDataItem d; |
643 | 653 | ||
644 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 654 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
645 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | 655 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. |
646 | // another option would be to create a constructor for PwMDataItem | 656 | // another option would be to create a constructor for PwMDataItem |
647 | d.clear(true); | 657 | d.clear(true); |
648 | 658 | ||
649 | d.desc = w.getDescription().latin1(); | 659 | d.desc = w.getDescription().latin1(); |
650 | d.name = w.getUsername().latin1(); | 660 | d.name = w.getUsername().latin1(); |
651 | d.pw = w.getPassword().latin1(); | 661 | d.pw = w.getPassword().latin1(); |
652 | d.comment = w.getComment().latin1(); | 662 | d.comment = w.getComment().latin1(); |
653 | d.url = w.getUrl().latin1(); | 663 | d.url = w.getUrl().latin1(); |
654 | d.launcher = w.getLauncher().latin1(); | 664 | d.launcher = w.getLauncher().latin1(); |
655 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 665 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
656 | if (ret == e_entryExists) { | 666 | if (ret == e_entryExists) { |
657 | KMessageBox::error(this, | 667 | KMessageBox::error(this, |
658 | i18n | 668 | i18n |
659 | ("An entry with this \"Description\",\n" | 669 | ("An entry with this \"Description\",\n" |
660 | "does already exist.\n" | 670 | "does already exist.\n" |
661 | "Please select another description."), | 671 | "Please select another description."), |
662 | i18n("entry already exists.")); | 672 | i18n("entry already exists.")); |
663 | goto tryAgain; | 673 | goto tryAgain; |
664 | } else if (ret == e_maxAllowedEntr) { | 674 | } else if (ret == e_maxAllowedEntr) { |
665 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" | 675 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" |
666 | "has been reached.\nYou can't add more entries."), | 676 | "has been reached.\nYou can't add more entries."), |
667 | i18n("maximum number of entries")); | 677 | i18n("maximum number of entries")); |
668 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 678 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
669 | return; | 679 | return; |
670 | } | 680 | } |
671 | } | 681 | } |
672 | setVirgin(false); | 682 | setVirgin(false); |
673 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 683 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
674 | } | 684 | } |
675 | 685 | ||
676 | //US ENH : changed code to run with older MOC | 686 | //US ENH : changed code to run with older MOC |
677 | void PwM::editPwd_slot() | 687 | void PwM::editPwd_slot() |
678 | { | 688 | { |
679 | editPwd_slot3(0,0,0); | 689 | editPwd_slot3(0,0,0); |
680 | } | 690 | } |
681 | 691 | ||
682 | void PwM::editPwd_slot1(const QString *category) | 692 | void PwM::editPwd_slot1(const QString *category) |
683 | { | 693 | { |
684 | editPwd_slot3(category, 0, 0); | 694 | editPwd_slot3(category, 0, 0); |
685 | } | 695 | } |
686 | 696 | ||
687 | void PwM::editPwd_slot3(const QString *category, const int *index, | 697 | void PwM::editPwd_slot3(const QString *category, const int *index, |
688 | PwMDoc *_doc) | 698 | PwMDoc *_doc) |
689 | { | 699 | { |
690 | PwMDoc *doc; | 700 | PwMDoc *doc; |
691 | if (_doc) { | 701 | if (_doc) { |
692 | doc = _doc; | 702 | doc = _doc; |
693 | } else { | 703 | } else { |
694 | doc = curDoc(); | 704 | doc = curDoc(); |
695 | } | 705 | } |
696 | PWM_ASSERT(doc); | 706 | PWM_ASSERT(doc); |
697 | if (doc->isDocEmpty()) | 707 | if (doc->isDocEmpty()) |
698 | return; | 708 | return; |
699 | if (doc->isDeepLocked()) | 709 | if (doc->isDeepLocked()) |
700 | return; | 710 | return; |
701 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 711 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
702 | unsigned int curEntryIndex; | 712 | unsigned int curEntryIndex; |
703 | if (index) { | 713 | if (index) { |
704 | curEntryIndex = *index; | 714 | curEntryIndex = *index; |
705 | } else { | 715 | } else { |
706 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 716 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
707 | printDebug("couldn't get index. Maybe we have a binary entry here."); | 717 | printDebug("couldn't get index. Maybe we have a binary entry here."); |
708 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 718 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
709 | return; | 719 | return; |
710 | } | 720 | } |
711 | } | 721 | } |
712 | QString curCategory; | 722 | QString curCategory; |
713 | if (category) { | 723 | if (category) { |
714 | curCategory = *category; | 724 | curCategory = *category; |
715 | } else { | 725 | } else { |
716 | curCategory = view->getCurrentCategory(); | 726 | curCategory = view->getCurrentCategory(); |
717 | } | 727 | } |
718 | PwMDataItem currItem; | 728 | PwMDataItem currItem; |
719 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { | 729 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { |
720 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 730 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
721 | return; | 731 | return; |
722 | } | 732 | } |
723 | BUG_ON(currItem.binary); | 733 | BUG_ON(currItem.binary); |
724 | 734 | ||
725 | AddEntryWndImpl w; | 735 | AddEntryWndImpl w; |
726 | vector<string> catList; | 736 | vector<string> catList; |
727 | doc->getCategoryList(&catList); | 737 | doc->getCategoryList(&catList); |
728 | unsigned i, size = catList.size(); | 738 | unsigned i, size = catList.size(); |
729 | for (i = 0; i < size; ++i) { | 739 | for (i = 0; i < size; ++i) { |
730 | w.addCategory(catList[i].c_str()); | 740 | w.addCategory(catList[i].c_str()); |
731 | } | 741 | } |
732 | w.setCurrCategory(curCategory); | 742 | w.setCurrCategory(curCategory); |
733 | w.setDescription(currItem.desc.c_str()); | 743 | w.setDescription(currItem.desc.c_str()); |
734 | w.setUsername(currItem.name.c_str()); | 744 | w.setUsername(currItem.name.c_str()); |
735 | w.setPassword(currItem.pw.c_str()); | 745 | w.setPassword(currItem.pw.c_str()); |
736 | w.setUrl(currItem.url.c_str()); | 746 | w.setUrl(currItem.url.c_str()); |
737 | w.setLauncher(currItem.launcher.c_str()); | 747 | w.setLauncher(currItem.launcher.c_str()); |
738 | w.setComment(currItem.comment.c_str()); | 748 | w.setComment(currItem.comment.c_str()); |
739 | if (w.exec() == 1) { | 749 | if (w.exec() == 1) { |
740 | currItem.desc = w.getDescription().latin1(); | 750 | currItem.desc = w.getDescription().latin1(); |
741 | currItem.name = w.getUsername().latin1(); | 751 | currItem.name = w.getUsername().latin1(); |
742 | currItem.pw = w.getPassword().latin1(); | 752 | currItem.pw = w.getPassword().latin1(); |
743 | currItem.comment = w.getComment().latin1(); | 753 | currItem.comment = w.getComment().latin1(); |
744 | currItem.url = w.getUrl().latin1(); | 754 | currItem.url = w.getUrl().latin1(); |
745 | currItem.launcher = w.getLauncher().latin1(); | 755 | currItem.launcher = w.getLauncher().latin1(); |
746 | if (!doc->editEntry(curCategory, w.getCategory(), | 756 | if (!doc->editEntry(curCategory, w.getCategory(), |
@@ -1010,469 +1020,528 @@ void PwM::exportToGpasman() | |||
1010 | PWM_ASSERT(curDoc()); | 1020 | PWM_ASSERT(curDoc()); |
1011 | if (curDoc()->isDocEmpty()) { | 1021 | if (curDoc()->isDocEmpty()) { |
1012 | KMessageBox::information(this, | 1022 | KMessageBox::information(this, |
1013 | i18n | 1023 | i18n |
1014 | ("Sorry, there's nothing to export.\n" | 1024 | ("Sorry, there's nothing to export.\n" |
1015 | "Please first add some passwords."), | 1025 | "Please first add some passwords."), |
1016 | i18n("nothing to do")); | 1026 | i18n("nothing to do")); |
1017 | return; | 1027 | return; |
1018 | } | 1028 | } |
1019 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1029 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1020 | QString fn(KFileDialog::getSaveFileName(QString::null, | 1030 | QString fn(KFileDialog::getSaveFileName(QString::null, |
1021 | i18n("*|Gpasman or Kpasman file"), | 1031 | i18n("*|Gpasman or Kpasman file"), |
1022 | this)); | 1032 | this)); |
1023 | if (fn == "") { | 1033 | if (fn == "") { |
1024 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1034 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1025 | return; | 1035 | return; |
1026 | } | 1036 | } |
1027 | 1037 | ||
1028 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 1038 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
1029 | if (ret != e_success) { | 1039 | if (ret != e_success) { |
1030 | if (ret == e_noPw) { | 1040 | if (ret == e_noPw) { |
1031 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1041 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1032 | return; | 1042 | return; |
1033 | } | 1043 | } |
1034 | KMessageBox::error(this, | 1044 | KMessageBox::error(this, |
1035 | i18n("Error: Couldn't write to file.\n" | 1045 | i18n("Error: Couldn't write to file.\n" |
1036 | "Please check if you have permission to write " | 1046 | "Please check if you have permission to write " |
1037 | "to the file in that directory."), | 1047 | "to the file in that directory."), |
1038 | i18n("error while writing")); | 1048 | i18n("error while writing")); |
1039 | } else | 1049 | } else |
1040 | showStatMsg(i18n("Successfully exported data.")); | 1050 | showStatMsg(i18n("Successfully exported data.")); |
1041 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1051 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1042 | } | 1052 | } |
1043 | 1053 | ||
1044 | 1054 | ||
1045 | 1055 | ||
1046 | void PwM::exportToCsv() | 1056 | void PwM::exportToCsv() |
1047 | { | 1057 | { |
1048 | PWM_ASSERT(curDoc()); | 1058 | PWM_ASSERT(curDoc()); |
1049 | if (curDoc()->isDocEmpty()) { | 1059 | if (curDoc()->isDocEmpty()) { |
1050 | KMessageBox::information(this, | 1060 | KMessageBox::information(this, |
1051 | i18n | 1061 | i18n |
1052 | ("Sorry, there is nothing to export;\n" | 1062 | ("Sorry, there is nothing to export;\n" |
1053 | "please add some passwords first."), | 1063 | "please add some passwords first."), |
1054 | i18n("Nothing to Do")); | 1064 | i18n("Nothing to Do")); |
1055 | return; | 1065 | return; |
1056 | } | 1066 | } |
1057 | 1067 | ||
1058 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1068 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1059 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); | 1069 | QString fn(KFileDialog::getSaveFileName("*.csv", i18n("*|CSV Text File"), this)); |
1060 | if (fn.isEmpty()) { | 1070 | if (fn.isEmpty()) { |
1061 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1071 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1062 | return; | 1072 | return; |
1063 | } | 1073 | } |
1064 | 1074 | ||
1065 | Csv csv(this); | 1075 | Csv csv(this); |
1066 | if (!csv.exportData(fn, curDoc())) { | 1076 | if (!csv.exportData(fn, curDoc())) { |
1067 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1077 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1068 | showStatMsg(i18n("CSV file export failed.")); | 1078 | showStatMsg(i18n("CSV file export failed.")); |
1069 | return; | 1079 | return; |
1070 | } | 1080 | } |
1071 | showStatMsg(i18n("Successfully exported data.")); | 1081 | showStatMsg(i18n("Successfully exported data.")); |
1072 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1082 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1073 | } | 1083 | } |
1074 | 1084 | ||
1075 | bool PwM::importCsv() | 1085 | bool PwM::importCsv() |
1076 | { | 1086 | { |
1077 | Csv csv(this); | 1087 | Csv csv(this); |
1078 | if (!isVirgin()) { | 1088 | if (!isVirgin()) { |
1079 | if (KMessageBox::questionYesNo(this, | 1089 | if (KMessageBox::questionYesNo(this, |
1080 | i18n("Do you want to import the data\n" | 1090 | i18n("Do you want to import the data\n" |
1081 | "into the current document? (If you\n" | 1091 | "into the current document? (If you\n" |
1082 | "select \"no\", a new document will be\n" | 1092 | "select \"no\", a new document will be\n" |
1083 | "opened.)"), | 1093 | "opened.)"), |
1084 | i18n("Import into This Document?")) | 1094 | i18n("Import into This Document?")) |
1085 | == KMessageBox::No) { | 1095 | == KMessageBox::No) { |
1086 | // import the data to a new window. | 1096 | // import the data to a new window. |
1087 | PwM *newInstance = init->createMainWnd(); | 1097 | PwM *newInstance = init->createMainWnd(); |
1088 | bool ok = newInstance->importCsv(); | 1098 | bool ok = newInstance->importCsv(); |
1089 | if (!ok) { | 1099 | if (!ok) { |
1090 | newInstance->setForceQuit(true); | 1100 | newInstance->setForceQuit(true); |
1091 | delete_and_null(newInstance); | 1101 | delete_and_null(newInstance); |
1092 | } | 1102 | } |
1093 | return ok; | 1103 | return ok; |
1094 | } | 1104 | } |
1095 | } | 1105 | } |
1096 | 1106 | ||
1097 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); | 1107 | QString filename = KFileDialog::getOpenFileName("*.csv", i18n("*|CSV Text File"), this); |
1098 | if (filename.isEmpty()) | 1108 | if (filename.isEmpty()) |
1099 | return false; | 1109 | return false; |
1100 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1110 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1101 | if (!csv.importData(filename, curDoc())) { | 1111 | if (!csv.importData(filename, curDoc())) { |
1102 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1112 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1103 | showStatMsg(i18n("CSV file import failed.")); | 1113 | showStatMsg(i18n("CSV file import failed.")); |
1104 | return false; | 1114 | return false; |
1105 | } | 1115 | } |
1106 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1116 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1107 | KMessageBox::information(this, | 1117 | KMessageBox::information(this, |
1108 | i18n("Successfully imported the CSV data\n" | 1118 | i18n("Successfully imported the CSV data\n" |
1109 | "into the current document."), i18n("Successfully Imported")); | 1119 | "into the current document."), i18n("Successfully Imported")); |
1110 | showStatMsg(i18n("Successfully imported")); | 1120 | showStatMsg(i18n("Successfully imported")); |
1111 | setVirgin(false); | 1121 | setVirgin(false); |
1112 | return true; | 1122 | return true; |
1113 | } | 1123 | } |
1114 | 1124 | ||
1115 | 1125 | ||
1116 | void PwM::exportToKWallet() | 1126 | void PwM::exportToKWallet() |
1117 | { | 1127 | { |
1118 | #ifdef CONFIG_KWALLETIF | 1128 | #ifdef CONFIG_KWALLETIF |
1119 | if (!checkAndAskForKWalletEmu()) | 1129 | if (!checkAndAskForKWalletEmu()) |
1120 | return; | 1130 | return; |
1121 | PWM_ASSERT(curDoc()); | 1131 | PWM_ASSERT(curDoc()); |
1122 | if (curDoc()->isDocEmpty()) { | 1132 | if (curDoc()->isDocEmpty()) { |
1123 | KMessageBox::information(this, | 1133 | KMessageBox::information(this, |
1124 | i18n | 1134 | i18n |
1125 | ("Sorry, there's nothing to export.\n" | 1135 | ("Sorry, there's nothing to export.\n" |
1126 | "Please first add some passwords."), | 1136 | "Please first add some passwords."), |
1127 | i18n("nothing to do")); | 1137 | i18n("nothing to do")); |
1128 | init->initKWalletEmu(); | 1138 | init->initKWalletEmu(); |
1129 | return; | 1139 | return; |
1130 | } | 1140 | } |
1131 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1141 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1132 | KWalletIf walletIf(this); | 1142 | KWalletIf walletIf(this); |
1133 | if (walletIf.kwalletExport(curDoc())) { | 1143 | if (walletIf.kwalletExport(curDoc())) { |
1134 | KMessageBox::information(this, | 1144 | KMessageBox::information(this, |
1135 | i18n("Successfully exported the data of the current " | 1145 | i18n("Successfully exported the data of the current " |
1136 | "document to KWallet."), | 1146 | "document to KWallet."), |
1137 | i18n("Successfully exported data.")); | 1147 | i18n("Successfully exported data.")); |
1138 | showStatMsg(i18n("Successfully exported data.")); | 1148 | showStatMsg(i18n("Successfully exported data.")); |
1139 | } | 1149 | } |
1140 | init->initKWalletEmu(); | 1150 | init->initKWalletEmu(); |
1141 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1151 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1142 | #endif // CONFIG_KWALLETIF | 1152 | #endif // CONFIG_KWALLETIF |
1143 | } | 1153 | } |
1144 | 1154 | ||
1145 | bool PwM::importFromGpasman() | 1155 | bool PwM::importFromGpasman() |
1146 | { | 1156 | { |
1147 | if (!isVirgin()) { | 1157 | if (!isVirgin()) { |
1148 | if (KMessageBox::questionYesNo(this, | 1158 | if (KMessageBox::questionYesNo(this, |
1149 | i18n("Do you want to import the data\n" | 1159 | i18n("Do you want to import the data\n" |
1150 | "into the current document? (If you\n" | 1160 | "into the current document? (If you\n" |
1151 | "select \"no\", a new document will be\n" | 1161 | "select \"no\", a new document will be\n" |
1152 | "opened.)"), | 1162 | "opened.)"), |
1153 | i18n("import into this document?")) | 1163 | i18n("import into this document?")) |
1154 | == KMessageBox::No) { | 1164 | == KMessageBox::No) { |
1155 | // import the data to a new window. | 1165 | // import the data to a new window. |
1156 | PwM *newInstance = init->createMainWnd(); | 1166 | PwM *newInstance = init->createMainWnd(); |
1157 | bool ok = newInstance->importFromGpasman(); | 1167 | bool ok = newInstance->importFromGpasman(); |
1158 | if (!ok) { | 1168 | if (!ok) { |
1159 | newInstance->setForceQuit(true); | 1169 | newInstance->setForceQuit(true); |
1160 | delete_and_null(newInstance); | 1170 | delete_and_null(newInstance); |
1161 | } | 1171 | } |
1162 | return ok; | 1172 | return ok; |
1163 | } | 1173 | } |
1164 | } | 1174 | } |
1165 | 1175 | ||
1166 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1176 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1167 | PwMerror ret; | 1177 | PwMerror ret; |
1168 | QString path(KFileDialog::getOpenFileName(QString::null, | 1178 | QString path(KFileDialog::getOpenFileName(QString::null, |
1169 | i18n("*|Gpasman or Kpasman file"), this)); | 1179 | i18n("*|Gpasman or Kpasman file"), this)); |
1170 | if (path == "") | 1180 | if (path == "") |
1171 | goto cancelImport; | 1181 | goto cancelImport; |
1172 | ret = curDoc()->importFromGpasman(&path); | 1182 | ret = curDoc()->importFromGpasman(&path); |
1173 | if (ret == e_wrongPw) { | 1183 | if (ret == e_wrongPw) { |
1174 | if (KMessageBox::questionYesNo(this, | 1184 | if (KMessageBox::questionYesNo(this, |
1175 | i18n | 1185 | i18n |
1176 | ("This is probably the wrong master-password\n" | 1186 | ("This is probably the wrong master-password\n" |
1177 | "you have typed in.\n" | 1187 | "you have typed in.\n" |
1178 | "There is no real way to determine the\n" | 1188 | "There is no real way to determine the\n" |
1179 | "correctness of the password in the Gpasman\n" | 1189 | "correctness of the password in the Gpasman\n" |
1180 | "file-format. But I think this\n" | 1190 | "file-format. But I think this\n" |
1181 | "password ist wrong.\n" | 1191 | "password ist wrong.\n" |
1182 | "Do you want to continue nevertheless?"), | 1192 | "Do you want to continue nevertheless?"), |
1183 | i18n("password error")) | 1193 | i18n("password error")) |
1184 | == KMessageBox::No) { | 1194 | == KMessageBox::No) { |
1185 | goto cancelImport; | 1195 | goto cancelImport; |
1186 | } | 1196 | } |
1187 | } else if (ret != e_success) { | 1197 | } else if (ret != e_success) { |
1188 | KMessageBox::error(this, | 1198 | KMessageBox::error(this, |
1189 | i18n("Could not import file!\n" | 1199 | i18n("Could not import file!\n" |
1190 | "Do you have permission to read this file?"), | 1200 | "Do you have permission to read this file?"), |
1191 | i18n("import failed")); | 1201 | i18n("import failed")); |
1192 | goto cancelImport; | 1202 | goto cancelImport; |
1193 | } | 1203 | } |
1194 | setVirgin(false); | 1204 | setVirgin(false); |
1195 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1205 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1196 | return true; | 1206 | return true; |
1197 | 1207 | ||
1198 | cancelImport: | 1208 | cancelImport: |
1199 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1209 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1200 | return false; | 1210 | return false; |
1201 | } | 1211 | } |
1202 | 1212 | ||
1203 | #ifdef CONFIG_KWALLETIF | 1213 | #ifdef CONFIG_KWALLETIF |
1204 | bool PwM::checkAndAskForKWalletEmu() | 1214 | bool PwM::checkAndAskForKWalletEmu() |
1205 | { | 1215 | { |
1206 | if (init->kwalletEmu()) { | 1216 | if (init->kwalletEmu()) { |
1207 | /* KWallet emulation is enabled. We can't import/export | 1217 | /* KWallet emulation is enabled. We can't import/export |
1208 | * data from/to it, while emulation is active. | 1218 | * data from/to it, while emulation is active. |
1209 | */ | 1219 | */ |
1210 | if (KMessageBox::questionYesNo(this, | 1220 | if (KMessageBox::questionYesNo(this, |
1211 | i18n("KWallet emulation is enabled.\n" | 1221 | i18n("KWallet emulation is enabled.\n" |
1212 | "You can't import or export data from/to " | 1222 | "You can't import or export data from/to " |
1213 | "the original KWallet, while the emulation " | 1223 | "the original KWallet, while the emulation " |
1214 | "is active.\n" | 1224 | "is active.\n" |
1215 | "Do you want to tempoarly disable the KWallet emulation?"), | 1225 | "Do you want to tempoarly disable the KWallet emulation?"), |
1216 | i18n("Tempoarly disable KWallet emulation?")) | 1226 | i18n("Tempoarly disable KWallet emulation?")) |
1217 | == KMessageBox::Yes) { | 1227 | == KMessageBox::Yes) { |
1218 | init->initKWalletEmu(true); | 1228 | init->initKWalletEmu(true); |
1219 | PWM_ASSERT(!init->kwalletEmu()); | 1229 | PWM_ASSERT(!init->kwalletEmu()); |
1220 | return true; | 1230 | return true; |
1221 | } | 1231 | } |
1222 | return false; | 1232 | return false; |
1223 | } | 1233 | } |
1224 | return true; | 1234 | return true; |
1225 | } | 1235 | } |
1226 | #endif // CONFIG_KWALLETIF | 1236 | #endif // CONFIG_KWALLETIF |
1227 | 1237 | ||
1228 | bool PwM::importKWallet() | 1238 | bool PwM::importKWallet() |
1229 | { | 1239 | { |
1230 | #ifdef CONFIG_KWALLETIF | 1240 | #ifdef CONFIG_KWALLETIF |
1231 | if (!checkAndAskForKWalletEmu()) | 1241 | if (!checkAndAskForKWalletEmu()) |
1232 | return false; | 1242 | return false; |
1233 | KWalletIf walletIf(this); | 1243 | KWalletIf walletIf(this); |
1234 | if (!isVirgin()) { | 1244 | if (!isVirgin()) { |
1235 | if (KMessageBox::questionYesNo(this, | 1245 | if (KMessageBox::questionYesNo(this, |
1236 | i18n("Do you want to import the data " | 1246 | i18n("Do you want to import the data " |
1237 | "into the current document? (If you " | 1247 | "into the current document? (If you " |
1238 | "select \"no\", a new document will be " | 1248 | "select \"no\", a new document will be " |
1239 | "opened.)"), | 1249 | "opened.)"), |
1240 | i18n("import into this document?")) | 1250 | i18n("import into this document?")) |
1241 | == KMessageBox::No) { | 1251 | == KMessageBox::No) { |
1242 | // import the data to a new window. | 1252 | // import the data to a new window. |
1243 | PwM *newInstance = init->createMainWnd(); | 1253 | PwM *newInstance = init->createMainWnd(); |
1244 | bool ok = newInstance->importKWallet(); | 1254 | bool ok = newInstance->importKWallet(); |
1245 | if (!ok) { | 1255 | if (!ok) { |
1246 | newInstance->setForceQuit(true); | 1256 | newInstance->setForceQuit(true); |
1247 | delete_and_null(newInstance); | 1257 | delete_and_null(newInstance); |
1248 | goto exit_fail; | 1258 | goto exit_fail; |
1249 | } else { | 1259 | } else { |
1250 | goto exit_ok; | 1260 | goto exit_ok; |
1251 | } | 1261 | } |
1252 | } | 1262 | } |
1253 | } | 1263 | } |
1254 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1264 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1255 | if (!walletIf.kwalletImport(curDoc())) { | 1265 | if (!walletIf.kwalletImport(curDoc())) { |
1256 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1266 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1257 | showStatMsg(i18n("KWallet import failed")); | 1267 | showStatMsg(i18n("KWallet import failed")); |
1258 | goto exit_fail; | 1268 | goto exit_fail; |
1259 | } | 1269 | } |
1260 | KMessageBox::information(this, | 1270 | KMessageBox::information(this, |
1261 | i18n("Successfully imported the KWallet data " | 1271 | i18n("Successfully imported the KWallet data " |
1262 | "into the current document."), | 1272 | "into the current document."), |
1263 | i18n("successfully imported")); | 1273 | i18n("successfully imported")); |
1264 | showStatMsg(i18n("successfully imported")); | 1274 | showStatMsg(i18n("successfully imported")); |
1265 | setVirgin(false); | 1275 | setVirgin(false); |
1266 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1276 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1267 | 1277 | ||
1268 | exit_ok: | 1278 | exit_ok: |
1269 | init->initKWalletEmu(); | 1279 | init->initKWalletEmu(); |
1270 | return true; | 1280 | return true; |
1271 | 1281 | ||
1272 | exit_fail: | 1282 | exit_fail: |
1273 | init->initKWalletEmu(); | 1283 | init->initKWalletEmu(); |
1274 | #endif // CONFIG_KWALLETIF | 1284 | #endif // CONFIG_KWALLETIF |
1275 | return false; | 1285 | return false; |
1276 | } | 1286 | } |
1277 | 1287 | ||
1278 | void PwM::print_slot() | 1288 | void PwM::print_slot() |
1279 | { | 1289 | { |
1280 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1290 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1281 | #ifndef PWM_EMBEDDED | 1291 | #ifndef PWM_EMBEDDED |
1282 | PwMPrint p(curDoc(), this); | 1292 | PwMPrint p(curDoc(), this); |
1283 | p.printNow(); | 1293 | p.printNow(); |
1284 | #else | 1294 | #else |
1285 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1295 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1286 | #endif | 1296 | #endif |
1287 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1297 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1288 | } | 1298 | } |
1289 | 1299 | ||
1290 | void PwM::genNewCard_slot() | 1300 | void PwM::genNewCard_slot() |
1291 | { | 1301 | { |
1292 | #ifdef CONFIG_KEYCARD | 1302 | #ifdef CONFIG_KEYCARD |
1293 | init->keycard()->genNewCard(); | 1303 | init->keycard()->genNewCard(); |
1294 | #endif | 1304 | #endif |
1295 | } | 1305 | } |
1296 | 1306 | ||
1297 | void PwM::eraseCard_slot() | 1307 | void PwM::eraseCard_slot() |
1298 | { | 1308 | { |
1299 | #ifdef CONFIG_KEYCARD | 1309 | #ifdef CONFIG_KEYCARD |
1300 | init->keycard()->eraseCard(); | 1310 | init->keycard()->eraseCard(); |
1301 | #endif | 1311 | #endif |
1302 | } | 1312 | } |
1303 | 1313 | ||
1304 | void PwM::readCardId_slot() | 1314 | void PwM::readCardId_slot() |
1305 | { | 1315 | { |
1306 | #ifdef CONFIG_KEYCARD | 1316 | #ifdef CONFIG_KEYCARD |
1307 | init->keycard()->displayKey(); | 1317 | init->keycard()->displayKey(); |
1308 | #endif | 1318 | #endif |
1309 | } | 1319 | } |
1310 | 1320 | ||
1311 | void PwM::makeCardBackup_slot() | 1321 | void PwM::makeCardBackup_slot() |
1312 | { | 1322 | { |
1313 | #ifdef CONFIG_KEYCARD | 1323 | #ifdef CONFIG_KEYCARD |
1314 | init->keycard()->makeBackupImage(); | 1324 | init->keycard()->makeBackupImage(); |
1315 | #endif | 1325 | #endif |
1316 | } | 1326 | } |
1317 | 1327 | ||
1318 | void PwM::replayCardBackup_slot() | 1328 | void PwM::replayCardBackup_slot() |
1319 | { | 1329 | { |
1320 | #ifdef CONFIG_KEYCARD | 1330 | #ifdef CONFIG_KEYCARD |
1321 | init->keycard()->replayBackupImage(); | 1331 | init->keycard()->replayBackupImage(); |
1322 | #endif | 1332 | #endif |
1323 | } | 1333 | } |
1324 | 1334 | ||
1325 | void PwM::execLauncher_slot() | 1335 | void PwM::execLauncher_slot() |
1326 | { | 1336 | { |
1327 | PWM_ASSERT(curDoc()); | 1337 | PWM_ASSERT(curDoc()); |
1328 | if (curDoc()->isDeepLocked()) | 1338 | if (curDoc()->isDeepLocked()) |
1329 | return; | 1339 | return; |
1330 | unsigned int curEntryIndex; | 1340 | unsigned int curEntryIndex; |
1331 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1341 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1332 | return; | 1342 | return; |
1333 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1343 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1334 | curEntryIndex); | 1344 | curEntryIndex); |
1335 | if (ret) | 1345 | if (ret) |
1336 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1346 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1337 | else | 1347 | else |
1338 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1348 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1339 | } | 1349 | } |
1340 | 1350 | ||
1341 | void PwM::goToURL_slot() | 1351 | void PwM::goToURL_slot() |
1342 | { | 1352 | { |
1343 | PWM_ASSERT(curDoc()); | 1353 | PWM_ASSERT(curDoc()); |
1344 | if (curDoc()->isDeepLocked()) | 1354 | if (curDoc()->isDeepLocked()) |
1345 | return; | 1355 | return; |
1346 | unsigned int curEntryIndex; | 1356 | unsigned int curEntryIndex; |
1347 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1357 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1348 | return; | 1358 | return; |
1349 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1359 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1350 | curEntryIndex); | 1360 | curEntryIndex); |
1351 | if (ret) | 1361 | if (ret) |
1352 | showStatMsg(i18n("started browser with current URL.")); | 1362 | showStatMsg(i18n("started browser with current URL.")); |
1353 | else | 1363 | else |
1354 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1364 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1355 | } | 1365 | } |
1356 | 1366 | ||
1357 | void PwM::copyToClipboard(const QString &s) | 1367 | void PwM::copyToClipboard(const QString &s) |
1358 | { | 1368 | { |
1359 | QClipboard *cb = QApplication::clipboard(); | 1369 | QClipboard *cb = QApplication::clipboard(); |
1360 | #ifndef PWM_EMBEDDED | 1370 | #ifndef PWM_EMBEDDED |
1361 | if (cb->supportsSelection()) | 1371 | if (cb->supportsSelection()) |
1362 | cb->setText(s, QClipboard::Selection); | 1372 | cb->setText(s, QClipboard::Selection); |
1363 | cb->setText(s, QClipboard::Clipboard); | 1373 | cb->setText(s, QClipboard::Clipboard); |
1364 | #else | 1374 | #else |
1365 | cb->setText(s); | 1375 | cb->setText(s); |
1366 | 1376 | ||
1367 | #endif | 1377 | #endif |
1368 | 1378 | ||
1369 | } | 1379 | } |
1370 | 1380 | ||
1371 | 1381 | ||
1372 | void PwM::showStatMsg(const QString &msg) | 1382 | void PwM::showStatMsg(const QString &msg) |
1373 | { | 1383 | { |
1374 | #ifdef DESKTOP_VERSION | 1384 | #ifdef DESKTOP_VERSION |
1375 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1385 | statusBar()->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1376 | #else | 1386 | #else |
1377 | qDebug("Statusbar : %s",msg.latin1()); | 1387 | qDebug("Statusbar : %s",msg.latin1()); |
1378 | Global::statusMessage(msg); | 1388 | Global::statusMessage(msg); |
1379 | #endif | 1389 | #endif |
1380 | } | 1390 | } |
1381 | 1391 | ||
1382 | void PwM::focusInEvent(QFocusEvent *e) | 1392 | void PwM::focusInEvent(QFocusEvent *e) |
1383 | { | 1393 | { |
1384 | if (e->gotFocus()) { | 1394 | if (e->gotFocus()) { |
1385 | emit gotFocus(this); | 1395 | emit gotFocus(this); |
1386 | } else if (e->lostFocus()) { | 1396 | } else if (e->lostFocus()) { |
1387 | emit lostFocus(this); | 1397 | emit lostFocus(this); |
1388 | } | 1398 | } |
1389 | } | 1399 | } |
1390 | 1400 | ||
1391 | 1401 | ||
1392 | #ifdef PWM_EMBEDDED | 1402 | #ifdef PWM_EMBEDDED |
1393 | 1403 | ||
1404 | void PwM::category_slot() | ||
1405 | { | ||
1406 | PwMDoc *doc = curDoc(); | ||
1407 | PWM_ASSERT(doc); | ||
1408 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | ||
1409 | |||
1410 | editCategoryWnd w(doc, this, "editcategory"); | ||
1411 | /* | ||
1412 | vector<string> catList; | ||
1413 | doc->getCategoryList(&catList); | ||
1414 | unsigned i, size = catList.size(); | ||
1415 | for (i = 0; i < size; ++i) { | ||
1416 | w.addCategory(catList[i].c_str()); | ||
1417 | } | ||
1418 | w.setCurrCategory(view->getCurrentCategory()); | ||
1419 | if (pw) | ||
1420 | w.pwLineEdit->setText(*pw); | ||
1421 | */ | ||
1422 | w.setCurrCategory(view->getCurrentCategory()); | ||
1423 | |||
1424 | tryAgain: | ||
1425 | if (w.exec() == 1) | ||
1426 | { | ||
1427 | PwMDataItem d; | ||
1428 | |||
1429 | //US BUG: to initialize all values of curEntr with meaningfulldata, | ||
1430 | // we call clear on it. Reason: Metadata will be uninitialized otherwise. | ||
1431 | // another option would be to create a constructor for PwMDataItem | ||
1432 | d.clear(true); | ||
1433 | /* | ||
1434 | d.desc = w.getDescription().latin1(); | ||
1435 | d.name = w.getUsername().latin1(); | ||
1436 | d.pw = w.getPassword().latin1(); | ||
1437 | d.comment = w.getComment().latin1(); | ||
1438 | d.url = w.getUrl().latin1(); | ||
1439 | d.launcher = w.getLauncher().latin1(); | ||
1440 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | ||
1441 | if (ret == e_entryExists) { | ||
1442 | KMessageBox::error(this, | ||
1443 | i18n | ||
1444 | ("An entry with this \"Description\",\n" | ||
1445 | "does already exist.\n" | ||
1446 | "Please select another description."), | ||
1447 | i18n("entry already exists.")); | ||
1448 | goto tryAgain; | ||
1449 | } else if (ret == e_maxAllowedEntr) { | ||
1450 | KMessageBox::error(this, i18n("The maximum possible number of\nentries" | ||
1451 | "has been reached.\nYou can't add more entries."), | ||
1452 | i18n("maximum number of entries")); | ||
1453 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | ||
1454 | return; | ||
1455 | } | ||
1456 | */ | ||
1457 | } | ||
1458 | setVirgin(false); | ||
1459 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | ||
1460 | } | ||
1461 | |||
1462 | |||
1394 | void PwM::whatsnew_slot() | 1463 | void PwM::whatsnew_slot() |
1395 | { | 1464 | { |
1396 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); | 1465 | KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); |
1397 | } | 1466 | } |
1398 | 1467 | ||
1399 | void PwM::showLicense_slot() | 1468 | void PwM::showLicense_slot() |
1400 | { | 1469 | { |
1401 | KApplication::showLicence(); | 1470 | KApplication::showLicence(); |
1402 | } | 1471 | } |
1403 | 1472 | ||
1404 | void PwM::faq_slot() | 1473 | void PwM::faq_slot() |
1405 | { | 1474 | { |
1406 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1475 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1407 | } | 1476 | } |
1408 | 1477 | ||
1409 | void PwM::syncHowTo_slot() | 1478 | void PwM::syncHowTo_slot() |
1410 | { | 1479 | { |
1411 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); | 1480 | KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); |
1412 | } | 1481 | } |
1413 | 1482 | ||
1414 | 1483 | ||
1415 | void PwM::createAboutData_slot() | 1484 | void PwM::createAboutData_slot() |
1416 | { | 1485 | { |
1417 | QString version; | 1486 | QString version; |
1418 | #include <../version> | 1487 | #include <../version> |
1419 | ; | 1488 | ; |
1420 | QMessageBox::about( this, "About PwManager/Pi", | 1489 | QMessageBox::about( this, "About PwManager/Pi", |
1421 | "PwManager/Platform-independent\n" | 1490 | "PwManager/Platform-independent\n" |
1422 | "(PWM/Pi) " +version + " - " + | 1491 | "(PWM/Pi) " +version + " - " + |
1423 | #ifdef DESKTOP_VERSION | 1492 | #ifdef DESKTOP_VERSION |
1424 | "Desktop Edition\n" | 1493 | "Desktop Edition\n" |
1425 | #else | 1494 | #else |
1426 | "PDA-Edition\n" | 1495 | "PDA-Edition\n" |
1427 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1496 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1428 | #endif | 1497 | #endif |
1429 | 1498 | ||
1430 | "(c) 2004 Ulf Schenk\n" | 1499 | "(c) 2004 Ulf Schenk\n" |
1431 | "(c) 2004 Lutz Rogowski\n" | 1500 | "(c) 2004 Lutz Rogowski\n" |
1432 | "(c) 1997-2004, The KDE PIM Team\n" | 1501 | "(c) 1997-2004, The KDE PIM Team\n" |
1433 | 1502 | ||
1434 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" | 1503 | "(c) Michael Buesch - main programming\nand current maintainer\nmbuesch@freenet.de\n" |
1435 | "Matt Scifo - mscifo@o1.com\n" | 1504 | "Matt Scifo - mscifo@o1.com\n" |
1436 | "Elias Probst - elias.probst@gmx.de\n" | 1505 | "Elias Probst - elias.probst@gmx.de\n" |
1437 | "George Staikos - staikos@kde.org\n" | 1506 | "George Staikos - staikos@kde.org\n" |
1438 | "Matthew Palmer - mjp16@uow.edu.au\n" | 1507 | "Matthew Palmer - mjp16@uow.edu.au\n" |
1439 | "Olivier Sessink - gpasman@nl.linux.org\n" | 1508 | "Olivier Sessink - gpasman@nl.linux.org\n" |
1440 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1509 | "The libgcrypt developers -\nBlowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1441 | "Troy Engel - tengel@sonic.net\n" | 1510 | "Troy Engel - tengel@sonic.net\n" |
1442 | "Wickey - wickey@gmx.at\n" | 1511 | "Wickey - wickey@gmx.at\n" |
1443 | "Ian MacGregor - original documentation author.\n" | 1512 | "Ian MacGregor - original documentation author.\n" |
1444 | ); | 1513 | ); |
1445 | } | 1514 | } |
1446 | 1515 | ||
1447 | 1516 | ||
1448 | //this are the overwritten callbackmethods from the syncinterface | 1517 | //this are the overwritten callbackmethods from the syncinterface |
1449 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) | 1518 | bool PwM::sync(KSyncManager* manager, QString filename, int mode) |
1450 | { | 1519 | { |
1451 | PWM_ASSERT(curDoc()); | 1520 | PWM_ASSERT(curDoc()); |
1452 | 1521 | ||
1453 | bool ret = curDoc()->sync(manager, filename, mode); | 1522 | bool ret = curDoc()->sync(manager, filename, mode); |
1454 | 1523 | ||
1455 | qDebug("PwM::sync save now: ret=%i", ret); | 1524 | qDebug("PwM::sync save now: ret=%i", ret); |
1456 | 1525 | ||
1457 | if (ret == true) { | 1526 | if (ret == true) { |
1458 | //US BUG: what can we call here to update the view of the current doc? | 1527 | //US BUG: what can we call here to update the view of the current doc? |
1459 | //mViewManager->refreshView(); | 1528 | //mViewManager->refreshView(); |
1460 | 1529 | ||
1461 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. | 1530 | //US curDoc()->sync sets the dirtyFlag in case the sync was successfull. |
1462 | save(); | 1531 | save(); |
1463 | } | 1532 | } |
1464 | 1533 | ||
1465 | return ret; | 1534 | return ret; |
1466 | } | 1535 | } |
1467 | 1536 | ||
1468 | void PwM::removeSyncInfo( QString syncProfile) | 1537 | void PwM::removeSyncInfo( QString syncProfile) |
1469 | { | 1538 | { |
1470 | qDebug("PWM::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); | 1539 | qDebug("PWM::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); |
1471 | } | 1540 | } |
1472 | 1541 | ||
1473 | #endif | 1542 | #endif |
1474 | 1543 | ||
1475 | 1544 | ||
1476 | #ifndef PWM_EMBEDDED | 1545 | #ifndef PWM_EMBEDDED |
1477 | #include "pwm.moc" | 1546 | #include "pwm.moc" |
1478 | #endif | 1547 | #endif |
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h index fb34bca..9fa9edc 100644 --- a/pwmanager/pwmanager/pwm.h +++ b/pwmanager/pwmanager/pwm.h | |||
@@ -1,298 +1,299 @@ | |||
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 __PWM_H | 20 | #ifndef __PWM_H |
21 | #define __PWM_H | 21 | #define __PWM_H |
22 | 22 | ||
23 | 23 | ||
24 | #include <kpopupmenu.h> | 24 | #include <kpopupmenu.h> |
25 | #include <klistview.h> | 25 | #include <klistview.h> |
26 | #include <kmainwindow.h> | 26 | #include <kmainwindow.h> |
27 | 27 | ||
28 | #ifndef PWM_EMBEDDED | 28 | #ifndef PWM_EMBEDDED |
29 | #include <kwin.h> | 29 | #include <kwin.h> |
30 | #include <kapp.h> | 30 | #include <kapp.h> |
31 | #include <kdeversion.h> | 31 | #include <kdeversion.h> |
32 | #else | 32 | #else |
33 | #include <ksyncmanager.h> | 33 | #include <ksyncmanager.h> |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #include <kaction.h> | 36 | #include <kaction.h> |
37 | 37 | ||
38 | #include <qglobal.h> | 38 | #include <qglobal.h> |
39 | 39 | ||
40 | #include "pwmview.h" | 40 | #include "pwmview.h" |
41 | #include "pwmexception.h" | 41 | #include "pwmexception.h" |
42 | 42 | ||
43 | 43 | ||
44 | /** timeout for displaying a message on the status-bar (in seconds) */ | 44 | /** timeout for displaying a message on the status-bar (in seconds) */ |
45 | #define STATUSBAR_MSG_TIMEOUT5 | 45 | #define STATUSBAR_MSG_TIMEOUT5 |
46 | 46 | ||
47 | 47 | ||
48 | class PwMInit; | 48 | class PwMInit; |
49 | class KSyncManager; | 49 | class KSyncManager; |
50 | 50 | ||
51 | /** PwM is the base class of the project */ | 51 | /** PwM is the base class of the project */ |
52 | #ifndef PWM_EMBEDDED | 52 | #ifndef PWM_EMBEDDED |
53 | //MOC_SKIP_BEGIN | 53 | //MOC_SKIP_BEGIN |
54 | class PwM : public KMainWindow | 54 | class PwM : public KMainWindow |
55 | //MOC_SKIP_END | 55 | //MOC_SKIP_END |
56 | #else | 56 | #else |
57 | class PwM : public KMainWindow, public KSyncInterface | 57 | class PwM : public KMainWindow, public KSyncInterface |
58 | #endif | 58 | #endif |
59 | { | 59 | { |
60 | Q_OBJECT | 60 | Q_OBJECT |
61 | public: | 61 | public: |
62 | friend class PwMView; | 62 | friend class PwMView; |
63 | /** construtor */ | 63 | /** construtor */ |
64 | PwM(PwMInit *_init, PwMDoc *doc, | 64 | PwM(PwMInit *_init, PwMDoc *doc, |
65 | bool virginity = true, | 65 | bool virginity = true, |
66 | QWidget* parent = 0, const char *name = 0); | 66 | QWidget* parent = 0, const char *name = 0); |
67 | /** destructor */ | 67 | /** destructor */ |
68 | ~PwM(); | 68 | ~PwM(); |
69 | 69 | ||
70 | /** copy some text to the global clipboard */ | 70 | /** copy some text to the global clipboard */ |
71 | static void copyToClipboard(const QString &s); | 71 | static void copyToClipboard(const QString &s); |
72 | 72 | ||
73 | /** returns pointer to the view */ | 73 | /** returns pointer to the view */ |
74 | PwMView * curView() | 74 | PwMView * curView() |
75 | { return view; } | 75 | { return view; } |
76 | /** returns pointer to the currently using document. */ | 76 | /** returns pointer to the currently using document. */ |
77 | PwMDoc * curDoc() | 77 | PwMDoc * curDoc() |
78 | { return curView()->document(); } | 78 | { return curView()->document(); } |
79 | /** open a new doc with the given filename */ | 79 | /** open a new doc with the given filename */ |
80 | PwMDoc * openDoc(QString filename, bool openDeepLocked = false); | 80 | PwMDoc * openDoc(QString filename, bool openDeepLocked = false); |
81 | /** show a message on the global status bar. | 81 | /** show a message on the global status bar. |
82 | * The message times out after some seconds. | 82 | * The message times out after some seconds. |
83 | */ | 83 | */ |
84 | void showStatMsg(const QString &msg); | 84 | void showStatMsg(const QString &msg); |
85 | /** ask the user where to save the doc (if it has not been saved, yet) | 85 | /** ask the user where to save the doc (if it has not been saved, yet) |
86 | * and write the data to disk. | 86 | * and write the data to disk. |
87 | */ | 87 | */ |
88 | bool save(); | 88 | bool save(); |
89 | /** ask the user where to save the doc | 89 | /** ask the user where to save the doc |
90 | * and write the data to disk. | 90 | * and write the data to disk. |
91 | */ | 91 | */ |
92 | bool saveAs(); | 92 | bool saveAs(); |
93 | /** force quit. Quit this window, always! Don't minimize it */ | 93 | /** force quit. Quit this window, always! Don't minimize it */ |
94 | bool isForceQuit() | 94 | bool isForceQuit() |
95 | { return forceQuit; } | 95 | { return forceQuit; } |
96 | /** set forceQuit */ | 96 | /** set forceQuit */ |
97 | void setForceQuit(bool force) | 97 | void setForceQuit(bool force) |
98 | { forceQuit = force; } | 98 | { forceQuit = force; } |
99 | /** force minimize this window */ | 99 | /** force minimize this window */ |
100 | bool isForceMinimizeToTray() | 100 | bool isForceMinimizeToTray() |
101 | { return forceMinimizeToTray; } | 101 | { return forceMinimizeToTray; } |
102 | /** set forceMinimizeToTray */ | 102 | /** set forceMinimizeToTray */ |
103 | void setForceMinimizeToTray(bool force) | 103 | void setForceMinimizeToTray(bool force) |
104 | { forceMinimizeToTray = force; } | 104 | { forceMinimizeToTray = force; } |
105 | 105 | ||
106 | public slots: | 106 | public slots: |
107 | /** file/new triggered */ | 107 | /** file/new triggered */ |
108 | void new_slot(); | 108 | void new_slot(); |
109 | /** file/open triggered */ | 109 | /** file/open triggered */ |
110 | //US ENH | 110 | //US ENH |
111 | void open_slot(); | 111 | void open_slot(); |
112 | void open_slot(QString fn); | 112 | void open_slot(QString fn); |
113 | /** file/close triggered */ | 113 | /** file/close triggered */ |
114 | void close_slot(); | 114 | void close_slot(); |
115 | /** file/quit triggered */ | 115 | /** file/quit triggered */ |
116 | void quitButton_slot(); | 116 | void quitButton_slot(); |
117 | /** file/save triggered */ | 117 | /** file/save triggered */ |
118 | void save_slot(); | 118 | void save_slot(); |
119 | /** file/saveAs triggered */ | 119 | /** file/saveAs triggered */ |
120 | void saveAs_slot(); | 120 | void saveAs_slot(); |
121 | /** file/export/text triggered */ | 121 | /** file/export/text triggered */ |
122 | void exportToText(); | 122 | void exportToText(); |
123 | /** file/export/gpasman triggered */ | 123 | /** file/export/gpasman triggered */ |
124 | void exportToGpasman(); | 124 | void exportToGpasman(); |
125 | /** file/export/kwallet triggered */ | 125 | /** file/export/kwallet triggered */ |
126 | void exportToKWallet(); | 126 | void exportToKWallet(); |
127 | /** file/export/csv triggered */ | 127 | /** file/export/csv triggered */ |
128 | void exportToCsv(); | 128 | void exportToCsv(); |
129 | /** file/import/text triggered */ | 129 | /** file/import/text triggered */ |
130 | bool importFromText(); | 130 | bool importFromText(); |
131 | /** file/import/gpasman triggered */ | 131 | /** file/import/gpasman triggered */ |
132 | bool importFromGpasman(); | 132 | bool importFromGpasman(); |
133 | /** file/import/kwallet triggered */ | 133 | /** file/import/kwallet triggered */ |
134 | bool importKWallet(); | 134 | bool importKWallet(); |
135 | /** file/import/csv triggered */ | 135 | /** file/import/csv triggered */ |
136 | bool importCsv(); | 136 | bool importCsv(); |
137 | /** file/print triggered */ | 137 | /** file/print triggered */ |
138 | void print_slot(); | 138 | void print_slot(); |
139 | /** manage/add triggered */ | 139 | /** manage/add triggered */ |
140 | //US ENH : changed code to run with older MOC | 140 | //US ENH : changed code to run with older MOC |
141 | 141 | ||
142 | void addPwd_slot(); | 142 | void addPwd_slot(); |
143 | void addPwd_slot1(QString *pw, PwMDoc *_doc); | 143 | void addPwd_slot1(QString *pw, PwMDoc *_doc); |
144 | /** manage/edit triggered */ | 144 | /** manage/edit triggered */ |
145 | //US ENH : changed code to run with older MOC | 145 | //US ENH : changed code to run with older MOC |
146 | void editPwd_slot(); | 146 | void editPwd_slot(); |
147 | void editPwd_slot1(const QString *category); | 147 | void editPwd_slot1(const QString *category); |
148 | void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc ); | 148 | void editPwd_slot3(const QString *category, const int *index ,PwMDoc *_doc ); |
149 | 149 | ||
150 | /** manage/delete triggered */ | 150 | /** manage/delete triggered */ |
151 | void deletePwd_slot(); | 151 | void deletePwd_slot(); |
152 | /** execute the "Launcher" entry */ | 152 | /** execute the "Launcher" entry */ |
153 | void execLauncher_slot(); | 153 | void execLauncher_slot(); |
154 | /** open browser with URL entry */ | 154 | /** open browser with URL entry */ |
155 | void goToURL_slot(); | 155 | void goToURL_slot(); |
156 | /** manage/changeMasterPwd triggered */ | 156 | /** manage/changeMasterPwd triggered */ |
157 | void changeMasterPwd_slot(); | 157 | void changeMasterPwd_slot(); |
158 | /** lock current document */ | 158 | /** lock current document */ |
159 | void lockWnd_slot(); | 159 | void lockWnd_slot(); |
160 | /** deeplock current document */ | 160 | /** deeplock current document */ |
161 | void deepLockWnd_slot(); | 161 | void deepLockWnd_slot(); |
162 | /** window/unlock triggered */ | 162 | /** window/unlock triggered */ |
163 | void unlockWnd_slot(); | 163 | void unlockWnd_slot(); |
164 | /** find item */ | 164 | /** find item */ |
165 | void find_slot(); | 165 | void find_slot(); |
166 | /** configure clicked */ | 166 | /** configure clicked */ |
167 | void config_slot(); | 167 | void config_slot(); |
168 | /** (de)activate the "change master pw" button in the menu-bar */ | 168 | /** (de)activate the "change master pw" button in the menu-bar */ |
169 | void activateMpButton(bool activate = true); | 169 | void activateMpButton(bool activate = true); |
170 | /** generate a new chipcard */ | 170 | /** generate a new chipcard */ |
171 | void genNewCard_slot(); | 171 | void genNewCard_slot(); |
172 | /** completely erase the current card */ | 172 | /** completely erase the current card */ |
173 | void eraseCard_slot(); | 173 | void eraseCard_slot(); |
174 | /** returns the ID number of the current card */ | 174 | /** returns the ID number of the current card */ |
175 | void readCardId_slot(); | 175 | void readCardId_slot(); |
176 | /** make backup image of the current card */ | 176 | /** make backup image of the current card */ |
177 | void makeCardBackup_slot(); | 177 | void makeCardBackup_slot(); |
178 | /** write backup image to current card */ | 178 | /** write backup image to current card */ |
179 | void replayCardBackup_slot(); | 179 | void replayCardBackup_slot(); |
180 | 180 | ||
181 | #ifdef PWM_EMBEDDED | 181 | #ifdef PWM_EMBEDDED |
182 | void category_slot(); | ||
182 | void whatsnew_slot(); | 183 | void whatsnew_slot(); |
183 | void showLicense_slot(); | 184 | void showLicense_slot(); |
184 | void faq_slot(); | 185 | void faq_slot(); |
185 | void createAboutData_slot(); | 186 | void createAboutData_slot(); |
186 | void syncHowTo_slot(); | 187 | void syncHowTo_slot(); |
187 | #endif | 188 | #endif |
188 | 189 | ||
189 | protected: | 190 | protected: |
190 | /** is this window virgin? */ | 191 | /** is this window virgin? */ |
191 | bool isVirgin() | 192 | bool isVirgin() |
192 | { return virgin; } | 193 | { return virgin; } |
193 | /** add/remove virginity */ | 194 | /** add/remove virginity */ |
194 | void setVirgin(bool v); | 195 | void setVirgin(bool v); |
195 | /** initialize the menubar */ | 196 | /** initialize the menubar */ |
196 | void initMenubar(); | 197 | void initMenubar(); |
197 | /** initialize the toolbar */ | 198 | /** initialize the toolbar */ |
198 | void initToolbar(); | 199 | void initToolbar(); |
199 | /** initialize the window-metrics */ | 200 | /** initialize the window-metrics */ |
200 | void initMetrics(); | 201 | void initMetrics(); |
201 | /** close-event */ | 202 | /** close-event */ |
202 | void closeEvent(QCloseEvent *e); | 203 | void closeEvent(QCloseEvent *e); |
203 | /** creates a new PwM-ListView and returns it */ | 204 | /** creates a new PwM-ListView and returns it */ |
204 | PwMView * makeNewListView(PwMDoc *doc); | 205 | PwMView * makeNewListView(PwMDoc *doc); |
205 | /** Window hide-event */ | 206 | /** Window hide-event */ |
206 | void hideEvent(QHideEvent *); | 207 | void hideEvent(QHideEvent *); |
207 | /** is this window minimized? */ | 208 | /** is this window minimized? */ |
208 | bool isMinimized() | 209 | bool isMinimized() |
209 | { | 210 | { |
210 | #ifndef PWM_EMBEDDED | 211 | #ifndef PWM_EMBEDDED |
211 | #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) | 212 | #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0) |
212 | return KWin::windowInfo(winId()).isMinimized(); | 213 | return KWin::windowInfo(winId()).isMinimized(); |
213 | #else // KDE_VERSION | 214 | #else // KDE_VERSION |
214 | return KWin::info(winId()).isIconified(); | 215 | return KWin::info(winId()).isIconified(); |
215 | #endif // KDE_VERSION | 216 | #endif // KDE_VERSION |
216 | #else | 217 | #else |
217 | return false; | 218 | return false; |
218 | #endif | 219 | #endif |
219 | } | 220 | } |
220 | /** window got the focus */ | 221 | /** window got the focus */ |
221 | void focusInEvent(QFocusEvent *e); | 222 | void focusInEvent(QFocusEvent *e); |
222 | /** update the caption string */ | 223 | /** update the caption string */ |
223 | void updateCaption(); | 224 | void updateCaption(); |
224 | #ifdef CONFIG_KWALLETIF | 225 | #ifdef CONFIG_KWALLETIF |
225 | /** check if kwalletemu is enabled and ask the user what to do */ | 226 | /** check if kwalletemu is enabled and ask the user what to do */ |
226 | bool checkAndAskForKWalletEmu(); | 227 | bool checkAndAskForKWalletEmu(); |
227 | #endif // CONFIG_KWALLETIF | 228 | #endif // CONFIG_KWALLETIF |
228 | 229 | ||
229 | protected slots: | 230 | protected slots: |
230 | /** doc got closed */ | 231 | /** doc got closed */ |
231 | void docClosed(PwMDoc *doc); | 232 | void docClosed(PwMDoc *doc); |
232 | 233 | ||
233 | signals: | 234 | signals: |
234 | /** window got closed (by user or someone else) */ | 235 | /** window got closed (by user or someone else) */ |
235 | void closed(PwM *wnd); | 236 | void closed(PwM *wnd); |
236 | /** window got the focus (was brought to foreground) */ | 237 | /** window got the focus (was brought to foreground) */ |
237 | void gotFocus(PwM *wnd); | 238 | void gotFocus(PwM *wnd); |
238 | /** window lost the focus */ | 239 | /** window lost the focus */ |
239 | void lostFocus(PwM *wnd); | 240 | void lostFocus(PwM *wnd); |
240 | 241 | ||
241 | protected: | 242 | protected: |
242 | /** pointer to the view active in this KMainWindow */ | 243 | /** pointer to the view active in this KMainWindow */ |
243 | PwMView *view; | 244 | PwMView *view; |
244 | /** pointer to the init class */ | 245 | /** pointer to the init class */ |
245 | PwMInit *init; | 246 | PwMInit *init; |
246 | /** has this window already lost its virginity? | 247 | /** has this window already lost its virginity? |
247 | * Means is there an open working document | 248 | * Means is there an open working document |
248 | */ | 249 | */ |
249 | bool virgin; | 250 | bool virgin; |
250 | /** "file" popup-menu */ | 251 | /** "file" popup-menu */ |
251 | KPopupMenu *filePopup; | 252 | KPopupMenu *filePopup; |
252 | 253 | ||
253 | /** "manage" popup-menu */ | 254 | /** "manage" popup-menu */ |
254 | KPopupMenu *managePopup; | 255 | KPopupMenu *managePopup; |
255 | #ifdef CONFIG_KEYCARD | 256 | #ifdef CONFIG_KEYCARD |
256 | /** "chipcard" popup-menu */ | 257 | /** "chipcard" popup-menu */ |
257 | KPopupMenu *chipcardPopup; | 258 | KPopupMenu *chipcardPopup; |
258 | #endif // CONFIG_KEYCARD | 259 | #endif // CONFIG_KEYCARD |
259 | /** "view" popup-menu */ | 260 | /** "view" popup-menu */ |
260 | KPopupMenu *viewPopup; | 261 | KPopupMenu *viewPopup; |
261 | /** "options" popup-menu */ | 262 | /** "options" popup-menu */ |
262 | KPopupMenu *optionsPopup; | 263 | KPopupMenu *optionsPopup; |
263 | /** "help" popup-menu */ | 264 | /** "help" popup-menu */ |
264 | KPopupMenu *helpPopup; | 265 | KPopupMenu *helpPopup; |
265 | /** "export" popup-menu */ | 266 | /** "export" popup-menu */ |
266 | KPopupMenu *exportPopup; | 267 | KPopupMenu *exportPopup; |
267 | /** "import" popup-menu */ | 268 | /** "import" popup-menu */ |
268 | KPopupMenu *importPopup; | 269 | KPopupMenu *importPopup; |
269 | /** force quit this window? */ | 270 | /** force quit this window? */ |
270 | bool forceQuit; | 271 | bool forceQuit; |
271 | /** force minimize this window to the tray */ | 272 | /** force minimize this window to the tray */ |
272 | bool forceMinimizeToTray; | 273 | bool forceMinimizeToTray; |
273 | 274 | ||
274 | 275 | ||
275 | 276 | ||
276 | 277 | ||
277 | private: | 278 | private: |
278 | #ifdef PWM_EMBEDDED | 279 | #ifdef PWM_EMBEDDED |
279 | //this are the overwritten callbackmethods from the syncinterface | 280 | //this are the overwritten callbackmethods from the syncinterface |
280 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 281 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
281 | virtual void removeSyncInfo( QString syncProfile); | 282 | virtual void removeSyncInfo( QString syncProfile); |
282 | 283 | ||
283 | // LR ******************************* | 284 | // LR ******************************* |
284 | // sync stuff! | 285 | // sync stuff! |
285 | QPopupMenu *syncPopup; | 286 | QPopupMenu *syncPopup; |
286 | KSyncManager* syncManager; | 287 | KSyncManager* syncManager; |
287 | #endif | 288 | #endif |
288 | 289 | ||
289 | 290 | ||
290 | 291 | ||
291 | 292 | ||
292 | 293 | ||
293 | 294 | ||
294 | 295 | ||
295 | 296 | ||
296 | }; | 297 | }; |
297 | 298 | ||
298 | #endif | 299 | #endif |
diff --git a/pwmanager/pwmanager/pwmanager.pro b/pwmanager/pwmanager/pwmanager.pro index fbc0554..7efe45c 100644 --- a/pwmanager/pwmanager/pwmanager.pro +++ b/pwmanager/pwmanager/pwmanager.pro | |||
@@ -1,175 +1,177 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG += qt warn_off | 2 | CONFIG += qt warn_off |
3 | DESTDIR= ../../bin | 3 | DESTDIR= ../../bin |
4 | TARGET = pwmpi | 4 | TARGET = pwmpi |
5 | include( ../../variables.pri ) | 5 | include( ../../variables.pri ) |
6 | 6 | ||
7 | INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils ../libcrypt/crypt ../libcrypt/error ../libcrypt/zlib | 7 | INCLUDEPATH += . ../../ ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils ../libcrypt/crypt ../libcrypt/error ../libcrypt/zlib |
8 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION | 8 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY DESKTOP_VERSION |
9 | 9 | ||
10 | #enable this setting if you want debugoutput for pwmanager | 10 | #enable this setting if you want debugoutput for pwmanager |
11 | #DEFINES += CONFIG_DEBUG | 11 | #DEFINES += CONFIG_DEBUG |
12 | LIBS += -L../libcrypt/ | 12 | LIBS += -L../libcrypt/ |
13 | LIBS += -L../../bin/ | 13 | LIBS += -L../../bin/ |
14 | LIBS += -lmicrokde | 14 | LIBS += -lmicrokde |
15 | LIBS += -lmicrokdepim | 15 | LIBS += -lmicrokdepim |
16 | LIBS += -lzlib | 16 | LIBS += -lzlib |
17 | LIBS += -lkpmicrocipher | 17 | LIBS += -lkpmicrocipher |
18 | LIBS += -lkpmicroerror | 18 | LIBS += -lkpmicroerror |
19 | LIBS += -lkpmicrompi | 19 | LIBS += -lkpmicrompi |
20 | LIBS += -lstdc++ | 20 | LIBS += -lstdc++ |
21 | 21 | ||
22 | unix:{ | 22 | unix:{ |
23 | OBJECTS_DIR = obj/unix | 23 | OBJECTS_DIR = obj/unix |
24 | MOC_DIR = moc/unix | 24 | MOC_DIR = moc/unix |
25 | 25 | ||
26 | } | 26 | } |
27 | win32:{ | 27 | win32:{ |
28 | 28 | ||
29 | DEFINES += _WIN32_ | 29 | DEFINES += _WIN32_ |
30 | OBJECTS_DIR = obj/win | 30 | OBJECTS_DIR = obj/win |
31 | MOC_DIR = moc/win | 31 | MOC_DIR = moc/win |
32 | QMAKE_LINK += /NODEFAULTLIB:LIBC | 32 | QMAKE_LINK += /NODEFAULTLIB:LIBC |
33 | QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc | 33 | QMAKE_CXXFLAGS += /TP /GX /GR /Ehsc |
34 | } | 34 | } |
35 | 35 | ||
36 | #INTERFACES = \ | 36 | #INTERFACES = \ |
37 | #addentrywnd.ui \ | 37 | #addentrywnd.ui \ |
38 | #configwnd.ui \ | 38 | #configwnd.ui \ |
39 | #findwnd.ui \ | 39 | #findwnd.ui \ |
40 | #getmasterpwwnd.ui \ | 40 | #getmasterpwwnd.ui \ |
41 | #pwgenwnd.ui \ | 41 | #pwgenwnd.ui \ |
42 | #setmasterpwwnd.ui \ | 42 | #setmasterpwwnd.ui \ |
43 | #subtbledit.ui | 43 | #subtbledit.ui |
44 | 44 | ||
45 | #INTERFACES = \ | 45 | #INTERFACES = \ |
46 | #subtbledit.ui \ | 46 | #subtbledit.ui \ |
47 | 47 | ||
48 | 48 | ||
49 | 49 | ||
50 | #HEADERS = \ | 50 | #HEADERS = \ |
51 | #configuration_31compat.h \ | 51 | #configuration_31compat.h \ |
52 | #configuration.h \ | 52 | #configuration.h \ |
53 | #configwnd.h \ | 53 | #configwnd.h \ |
54 | #configwndimpl.h \ | 54 | #configwndimpl.h \ |
55 | #selftest.h | 55 | #selftest.h |
56 | #subtbledit.h \ | 56 | #subtbledit.h \ |
57 | #subtbleditimpl.h \ | 57 | #subtbleditimpl.h \ |
58 | #compressbzip2.h \ | 58 | #compressbzip2.h \ |
59 | 59 | ||
60 | HEADERS = \ | 60 | HEADERS = \ |
61 | addentrywnd_emb.h \ | 61 | addentrywnd_emb.h \ |
62 | addentrywndimpl.h \ | 62 | addentrywndimpl.h \ |
63 | base64.h \ | 63 | base64.h \ |
64 | binentrygen.h \ | 64 | binentrygen.h \ |
65 | blowfish.h \ | 65 | blowfish.h \ |
66 | commentbox.h \ | 66 | commentbox.h \ |
67 | compiler.h \ | 67 | compiler.h \ |
68 | compressgzip.h \ | 68 | compressgzip.h \ |
69 | csv.h \ | 69 | csv.h \ |
70 | editcategory.h \ | ||
70 | findwnd_emb.h \ | 71 | findwnd_emb.h \ |
71 | findwndimpl.h \ | 72 | findwndimpl.h \ |
72 | genpasswd.h \ | 73 | genpasswd.h \ |
73 | getkeycardwnd.h \ | 74 | getkeycardwnd.h \ |
74 | getmasterpwwnd_emb.h \ | 75 | getmasterpwwnd_emb.h \ |
75 | getmasterpwwndimpl.h \ | 76 | getmasterpwwndimpl.h \ |
76 | globalstuff.h \ | 77 | globalstuff.h \ |
77 | gpasmanfile.h \ | 78 | gpasmanfile.h \ |
78 | htmlgen.h \ | 79 | htmlgen.h \ |
79 | htmlparse.h \ | 80 | htmlparse.h \ |
80 | ipc.h \ | 81 | ipc.h \ |
81 | libgcryptif.h \ | 82 | libgcryptif.h \ |
82 | listobjselectwnd.h \ | 83 | listobjselectwnd.h \ |
83 | listviewpwm.h \ | 84 | listviewpwm.h \ |
84 | printtext.h \ | 85 | printtext.h \ |
85 | pwgenwnd_emb.h \ | 86 | pwgenwnd_emb.h \ |
86 | pwgenwndimpl.h \ | 87 | pwgenwndimpl.h \ |
87 | pwmdoc.h \ | 88 | pwmdoc.h \ |
88 | pwmdocui.h \ | 89 | pwmdocui.h \ |
89 | pwmexception.h \ | 90 | pwmexception.h \ |
90 | pwm.h \ | 91 | pwm.h \ |
91 | pwminit.h \ | 92 | pwminit.h \ |
92 | pwmprefs.h \ | 93 | pwmprefs.h \ |
93 | pwmprint.h \ | 94 | pwmprint.h \ |
94 | pwmtray.h \ | 95 | pwmtray.h \ |
95 | pwmview.h \ | 96 | pwmview.h \ |
96 | pwmviewstyle_0.h \ | 97 | pwmviewstyle_0.h \ |
97 | pwmviewstyle_1.h \ | 98 | pwmviewstyle_1.h \ |
98 | pwmviewstyle.h \ | 99 | pwmviewstyle.h \ |
99 | randomizer.h \ | 100 | randomizer.h \ |
100 | rc2.h \ | 101 | rc2.h \ |
101 | rencatwnd.h \ | 102 | rencatwnd.h \ |
102 | serializer.h \ | 103 | serializer.h \ |
103 | setmasterpwwnd_emb.h \ | 104 | setmasterpwwnd_emb.h \ |
104 | setmasterpwwndimpl.h \ | 105 | setmasterpwwndimpl.h \ |
105 | sha1.h \ | 106 | sha1.h \ |
106 | waitwnd.h \ | 107 | waitwnd.h \ |
107 | kcmconfigs/kcmpwmconfig.h \ | 108 | kcmconfigs/kcmpwmconfig.h \ |
108 | kcmconfigs/pwmconfigwidget.h | 109 | kcmconfigs/pwmconfigwidget.h |
109 | 110 | ||
110 | #sources that need not be build | 111 | #sources that need not be build |
111 | #SOURCES = \ | 112 | #SOURCES = \ |
112 | #advcommeditimpl.cpp \ | 113 | #advcommeditimpl.cpp \ |
113 | #configuration.cpp \ | 114 | #configuration.cpp \ |
114 | #configwnd.cpp \ | 115 | #configwnd.cpp \ |
115 | #configwndimpl.cpp \ | 116 | #configwndimpl.cpp \ |
116 | #configuration_31compat.cpp \ | 117 | #configuration_31compat.cpp \ |
117 | #htmlparse.cpp \ | 118 | #htmlparse.cpp \ |
118 | #printtext.cpp \ | 119 | #printtext.cpp \ |
119 | #selftest.cpp \ | 120 | #selftest.cpp \ |
120 | #pwmprint.cpp \ | 121 | #pwmprint.cpp \ |
121 | #spinforsignal.cpp | 122 | #spinforsignal.cpp |
122 | #subtbledit.cpp \ | 123 | #subtbledit.cpp \ |
123 | #subtbleditimpl.cpp \ | 124 | #subtbleditimpl.cpp \ |
124 | #compressbzip2.cpp | 125 | #compressbzip2.cpp |
125 | 126 | ||
126 | 127 | ||
127 | SOURCES = \ | 128 | SOURCES = \ |
128 | addentrywnd_emb.cpp \ | 129 | addentrywnd_emb.cpp \ |
129 | addentrywndimpl.cpp \ | 130 | addentrywndimpl.cpp \ |
130 | base64.cpp \ | 131 | base64.cpp \ |
131 | binentrygen.cpp \ | 132 | binentrygen.cpp \ |
132 | blowfish.cpp \ | 133 | blowfish.cpp \ |
133 | commentbox.cpp \ | 134 | commentbox.cpp \ |
134 | compressgzip.cpp \ | 135 | compressgzip.cpp \ |
135 | csv.cpp \ | 136 | csv.cpp \ |
137 | editcategory.cpp \ | ||
136 | findwnd_emb.cpp \ | 138 | findwnd_emb.cpp \ |
137 | findwndimpl.cpp \ | 139 | findwndimpl.cpp \ |
138 | genpasswd.cpp \ | 140 | genpasswd.cpp \ |
139 | getkeycardwnd.cpp \ | 141 | getkeycardwnd.cpp \ |
140 | getmasterpwwnd_emb.cpp \ | 142 | getmasterpwwnd_emb.cpp \ |
141 | getmasterpwwndimpl.cpp \ | 143 | getmasterpwwndimpl.cpp \ |
142 | globalstuff.cpp \ | 144 | globalstuff.cpp \ |
143 | gpasmanfile.cpp \ | 145 | gpasmanfile.cpp \ |
144 | htmlgen.cpp \ | 146 | htmlgen.cpp \ |
145 | ipc.cpp \ | 147 | ipc.cpp \ |
146 | libgcryptif.cpp \ | 148 | libgcryptif.cpp \ |
147 | listobjselectwnd.cpp \ | 149 | listobjselectwnd.cpp \ |
148 | listviewpwm.cpp \ | 150 | listviewpwm.cpp \ |
149 | main.cpp \ | 151 | main.cpp \ |
150 | pwgenwnd_emb.cpp \ | 152 | pwgenwnd_emb.cpp \ |
151 | pwgenwndimpl.cpp \ | 153 | pwgenwndimpl.cpp \ |
152 | pwm.cpp \ | 154 | pwm.cpp \ |
153 | pwmdoc.cpp \ | 155 | pwmdoc.cpp \ |
154 | pwmdocui.cpp \ | 156 | pwmdocui.cpp \ |
155 | pwmexception.cpp \ | 157 | pwmexception.cpp \ |
156 | pwminit.cpp \ | 158 | pwminit.cpp \ |
157 | pwmprefs.cpp \ | 159 | pwmprefs.cpp \ |
158 | pwmtray.cpp \ | 160 | pwmtray.cpp \ |
159 | pwmview.cpp \ | 161 | pwmview.cpp \ |
160 | pwmviewstyle_0.cpp \ | 162 | pwmviewstyle_0.cpp \ |
161 | pwmviewstyle_1.cpp \ | 163 | pwmviewstyle_1.cpp \ |
162 | pwmviewstyle.cpp \ | 164 | pwmviewstyle.cpp \ |
163 | randomizer.cpp \ | 165 | randomizer.cpp \ |
164 | rc2.cpp \ | 166 | rc2.cpp \ |
165 | rencatwnd.cpp \ | 167 | rencatwnd.cpp \ |
166 | serializer.cpp \ | 168 | serializer.cpp \ |
167 | setmasterpwwnd_emb.cpp \ | 169 | setmasterpwwnd_emb.cpp \ |
168 | setmasterpwwndimpl.cpp \ | 170 | setmasterpwwndimpl.cpp \ |
169 | sha1.cpp \ | 171 | sha1.cpp \ |
170 | waitwnd.cpp \ | 172 | waitwnd.cpp \ |
171 | kcmconfigs/kcmpwmconfig.cpp \ | 173 | kcmconfigs/kcmpwmconfig.cpp \ |
172 | kcmconfigs/pwmconfigwidget.cpp | 174 | kcmconfigs/pwmconfigwidget.cpp |
173 | 175 | ||
174 | 176 | ||
175 | 177 | ||
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro index e195178..6b68514 100644 --- a/pwmanager/pwmanager/pwmanagerE.pro +++ b/pwmanager/pwmanager/pwmanagerE.pro | |||
@@ -1,173 +1,175 @@ | |||
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 ../libcrypt/crypt ../libcrypt/error $(QPEDIR)/include | 10 | INCLUDEPATH += . ../../ ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils ../libcrypt/crypt ../libcrypt/error $(QPEDIR)/include |
11 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY | 11 | DEFINES += PWM_EMBEDDED CONFIG_PWMANAGER_GCRY |
12 | 12 | ||
13 | #enable this setting if you want debugoutput for pwmanager | 13 | #enable this setting if you want debugoutput for pwmanager |
14 | #DEFINES += CONFIG_DEBUG | 14 | #DEFINES += CONFIG_DEBUG |
15 | 15 | ||
16 | LIBS += -L../libcrypt/$(PLATFORM) | 16 | LIBS += -L../libcrypt/$(PLATFORM) |
17 | LIBS += -lmicrokde | 17 | LIBS += -lmicrokde |
18 | LIBS += -lmicroqtcompat | 18 | LIBS += -lmicroqtcompat |
19 | LIBS += -lmicrokdepim | 19 | LIBS += -lmicrokdepim |
20 | LIBS += -L$(QPEDIR)/lib | 20 | LIBS += -L$(QPEDIR)/lib |
21 | LIBS += -lqpe | 21 | LIBS += -lqpe |
22 | LIBS += -lzlib | 22 | LIBS += -lzlib |
23 | #LIBS += -lbz2 | 23 | #LIBS += -lbz2 |
24 | #LIBS += -lkpmicrogcrypt | 24 | #LIBS += -lkpmicrogcrypt |
25 | LIBS += -ljpeg | 25 | LIBS += -ljpeg |
26 | LIBS += $(QTOPIALIB) | 26 | LIBS += $(QTOPIALIB) |
27 | LIBS += -lkpmicrocipher | 27 | LIBS += -lkpmicrocipher |
28 | LIBS += -lkpmicroerror | 28 | LIBS += -lkpmicroerror |
29 | LIBS += -lkpmicrompi | 29 | LIBS += -lkpmicrompi |
30 | LIBS += -lstdc++ | 30 | LIBS += -lstdc++ |
31 | LIBS += $(GCC3EXTRALIB1) | 31 | LIBS += $(GCC3EXTRALIB1) |
32 | LIBS += $(GCC3EXTRALIB2) | 32 | LIBS += $(GCC3EXTRALIB2) |
33 | 33 | ||
34 | #INTERFACES = \ | 34 | #INTERFACES = \ |
35 | #addentrywnd.ui \ | 35 | #addentrywnd.ui \ |
36 | #configwnd.ui \ | 36 | #configwnd.ui \ |
37 | #findwnd.ui \ | 37 | #findwnd.ui \ |
38 | #getmasterpwwnd.ui \ | 38 | #getmasterpwwnd.ui \ |
39 | #pwgenwnd.ui \ | 39 | #pwgenwnd.ui \ |
40 | #setmasterpwwnd.ui \ | 40 | #setmasterpwwnd.ui \ |
41 | #subtbledit.ui | 41 | #subtbledit.ui |
42 | 42 | ||
43 | #INTERFACES = \ | 43 | #INTERFACES = \ |
44 | #subtbledit.ui \ | 44 | #subtbledit.ui \ |
45 | 45 | ||
46 | 46 | ||
47 | 47 | ||
48 | #HEADERS = \ | 48 | #HEADERS = \ |
49 | #configuration_31compat.h \ | 49 | #configuration_31compat.h \ |
50 | #configuration.h \ | 50 | #configuration.h \ |
51 | #configwnd.h \ | 51 | #configwnd.h \ |
52 | #configwndimpl.h \ | 52 | #configwndimpl.h \ |
53 | #selftest.h | 53 | #selftest.h |
54 | #subtbledit.h \ | 54 | #subtbledit.h \ |
55 | #subtbleditimpl.h \ | 55 | #subtbleditimpl.h \ |
56 | #compressbzip2.h \ | 56 | #compressbzip2.h \ |
57 | 57 | ||
58 | HEADERS = \ | 58 | HEADERS = \ |
59 | addentrywnd_emb.h \ | 59 | addentrywnd_emb.h \ |
60 | addentrywndimpl.h \ | 60 | addentrywndimpl.h \ |
61 | base64.h \ | 61 | base64.h \ |
62 | binentrygen.h \ | 62 | binentrygen.h \ |
63 | blowfish.h \ | 63 | blowfish.h \ |
64 | commentbox.h \ | 64 | commentbox.h \ |
65 | compiler.h \ | 65 | compiler.h \ |
66 | compressgzip.h \ | 66 | compressgzip.h \ |
67 | csv.h \ | 67 | csv.h \ |
68 | editcategory.h \ | ||
68 | findwnd_emb.h \ | 69 | findwnd_emb.h \ |
69 | findwndimpl.h \ | 70 | findwndimpl.h \ |
70 | genpasswd.h \ | 71 | genpasswd.h \ |
71 | getkeycardwnd.h \ | 72 | getkeycardwnd.h \ |
72 | getmasterpwwnd_emb.h \ | 73 | getmasterpwwnd_emb.h \ |
73 | getmasterpwwndimpl.h \ | 74 | getmasterpwwndimpl.h \ |
74 | globalstuff.h \ | 75 | globalstuff.h \ |
75 | gpasmanfile.h \ | 76 | gpasmanfile.h \ |
76 | htmlgen.h \ | 77 | htmlgen.h \ |
77 | htmlparse.h \ | 78 | htmlparse.h \ |
78 | ipc.h \ | 79 | ipc.h \ |
79 | libgcryptif.h \ | 80 | libgcryptif.h \ |
80 | listobjselectwnd.h \ | 81 | listobjselectwnd.h \ |
81 | listviewpwm.h \ | 82 | listviewpwm.h \ |
82 | printtext.h \ | 83 | printtext.h \ |
83 | pwgenwnd_emb.h \ | 84 | pwgenwnd_emb.h \ |
84 | pwgenwndimpl.h \ | 85 | pwgenwndimpl.h \ |
85 | pwmdoc.h \ | 86 | pwmdoc.h \ |
86 | pwmdocui.h \ | 87 | pwmdocui.h \ |
87 | pwmexception.h \ | 88 | pwmexception.h \ |
88 | pwm.h \ | 89 | pwm.h \ |
89 | pwminit.h \ | 90 | pwminit.h \ |
90 | pwmprefs.h \ | 91 | pwmprefs.h \ |
91 | pwmprint.h \ | 92 | pwmprint.h \ |
92 | pwmtray.h \ | 93 | pwmtray.h \ |
93 | pwmview.h \ | 94 | pwmview.h \ |
94 | pwmviewstyle_0.h \ | 95 | pwmviewstyle_0.h \ |
95 | pwmviewstyle_1.h \ | 96 | pwmviewstyle_1.h \ |
96 | pwmviewstyle.h \ | 97 | pwmviewstyle.h \ |
97 | randomizer.h \ | 98 | randomizer.h \ |
98 | rc2.h \ | 99 | rc2.h \ |
99 | rencatwnd.h \ | 100 | rencatwnd.h \ |
100 | serializer.h \ | 101 | serializer.h \ |
101 | setmasterpwwnd_emb.h \ | 102 | setmasterpwwnd_emb.h \ |
102 | setmasterpwwndimpl.h \ | 103 | setmasterpwwndimpl.h \ |
103 | sha1.h \ | 104 | sha1.h \ |
104 | waitwnd.h \ | 105 | waitwnd.h \ |
105 | kcmconfigs/kcmpwmconfig.h \ | 106 | kcmconfigs/kcmpwmconfig.h \ |
106 | kcmconfigs/pwmconfigwidget.h | 107 | kcmconfigs/pwmconfigwidget.h |
107 | 108 | ||
108 | #sources that need not be build | 109 | #sources that need not be build |
109 | #SOURCES = \ | 110 | #SOURCES = \ |
110 | #advcommeditimpl.cpp \ | 111 | #advcommeditimpl.cpp \ |
111 | #configuration.cpp \ | 112 | #configuration.cpp \ |
112 | #configwnd.cpp \ | 113 | #configwnd.cpp \ |
113 | #configwndimpl.cpp \ | 114 | #configwndimpl.cpp \ |
114 | #configuration_31compat.cpp \ | 115 | #configuration_31compat.cpp \ |
115 | #htmlparse.cpp \ | 116 | #htmlparse.cpp \ |
116 | #printtext.cpp \ | 117 | #printtext.cpp \ |
117 | #selftest.cpp \ | 118 | #selftest.cpp \ |
118 | #pwmprint.cpp \ | 119 | #pwmprint.cpp \ |
119 | #spinforsignal.cpp | 120 | #spinforsignal.cpp |
120 | #subtbledit.cpp \ | 121 | #subtbledit.cpp \ |
121 | #subtbleditimpl.cpp \ | 122 | #subtbleditimpl.cpp \ |
122 | #compressbzip2.cpp | 123 | #compressbzip2.cpp |
123 | 124 | ||
124 | 125 | ||
125 | SOURCES = \ | 126 | SOURCES = \ |
126 | addentrywnd_emb.cpp \ | 127 | addentrywnd_emb.cpp \ |
127 | addentrywndimpl.cpp \ | 128 | addentrywndimpl.cpp \ |
128 | base64.cpp \ | 129 | base64.cpp \ |
129 | binentrygen.cpp \ | 130 | binentrygen.cpp \ |
130 | blowfish.cpp \ | 131 | blowfish.cpp \ |
131 | commentbox.cpp \ | 132 | commentbox.cpp \ |
132 | compressgzip.cpp \ | 133 | compressgzip.cpp \ |
133 | csv.cpp \ | 134 | csv.cpp \ |
135 | editcategory.cpp \ | ||
134 | findwnd_emb.cpp \ | 136 | findwnd_emb.cpp \ |
135 | findwndimpl.cpp \ | 137 | findwndimpl.cpp \ |
136 | genpasswd.cpp \ | 138 | genpasswd.cpp \ |
137 | getkeycardwnd.cpp \ | 139 | getkeycardwnd.cpp \ |
138 | getmasterpwwnd_emb.cpp \ | 140 | getmasterpwwnd_emb.cpp \ |
139 | getmasterpwwndimpl.cpp \ | 141 | getmasterpwwndimpl.cpp \ |
140 | globalstuff.cpp \ | 142 | globalstuff.cpp \ |
141 | gpasmanfile.cpp \ | 143 | gpasmanfile.cpp \ |
142 | htmlgen.cpp \ | 144 | htmlgen.cpp \ |
143 | ipc.cpp \ | 145 | ipc.cpp \ |
144 | libgcryptif.cpp \ | 146 | libgcryptif.cpp \ |
145 | listobjselectwnd.cpp \ | 147 | listobjselectwnd.cpp \ |
146 | listviewpwm.cpp \ | 148 | listviewpwm.cpp \ |
147 | main.cpp \ | 149 | main.cpp \ |
148 | pwgenwnd_emb.cpp \ | 150 | pwgenwnd_emb.cpp \ |
149 | pwgenwndimpl.cpp \ | 151 | pwgenwndimpl.cpp \ |
150 | pwm.cpp \ | 152 | pwm.cpp \ |
151 | pwmdoc.cpp \ | 153 | pwmdoc.cpp \ |
152 | pwmdocui.cpp \ | 154 | pwmdocui.cpp \ |
153 | pwmexception.cpp \ | 155 | pwmexception.cpp \ |
154 | pwminit.cpp \ | 156 | pwminit.cpp \ |
155 | pwmprefs.cpp \ | 157 | pwmprefs.cpp \ |
156 | pwmtray.cpp \ | 158 | pwmtray.cpp \ |
157 | pwmview.cpp \ | 159 | pwmview.cpp \ |
158 | pwmviewstyle_0.cpp \ | 160 | pwmviewstyle_0.cpp \ |
159 | pwmviewstyle_1.cpp \ | 161 | pwmviewstyle_1.cpp \ |
160 | pwmviewstyle.cpp \ | 162 | pwmviewstyle.cpp \ |
161 | randomizer.cpp \ | 163 | randomizer.cpp \ |
162 | rc2.cpp \ | 164 | rc2.cpp \ |
163 | rencatwnd.cpp \ | 165 | rencatwnd.cpp \ |
164 | serializer.cpp \ | 166 | serializer.cpp \ |
165 | setmasterpwwnd_emb.cpp \ | 167 | setmasterpwwnd_emb.cpp \ |
166 | setmasterpwwndimpl.cpp \ | 168 | setmasterpwwndimpl.cpp \ |
167 | sha1.cpp \ | 169 | sha1.cpp \ |
168 | waitwnd.cpp \ | 170 | waitwnd.cpp \ |
169 | kcmconfigs/kcmpwmconfig.cpp \ | 171 | kcmconfigs/kcmpwmconfig.cpp \ |
170 | kcmconfigs/pwmconfigwidget.cpp | 172 | kcmconfigs/pwmconfigwidget.cpp |
171 | 173 | ||
172 | 174 | ||
173 | 175 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 9043acc..ddbf4f2 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -671,768 +671,771 @@ PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char c | |||
671 | // write bytes of NUL-data. These bytes are reserved for future-use. | 671 | // write bytes of NUL-data. These bytes are reserved for future-use. |
672 | const int bufSize = 64; | 672 | const int bufSize = 64; |
673 | char tmp_buf[bufSize]; | 673 | char tmp_buf[bufSize]; |
674 | memset(tmp_buf, 0x00, bufSize); | 674 | memset(tmp_buf, 0x00, bufSize); |
675 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 675 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
676 | return e_writeFile; | 676 | return e_writeFile; |
677 | 677 | ||
678 | switch (keyHash) { | 678 | switch (keyHash) { |
679 | case PWM_HASH_SHA1: { | 679 | case PWM_HASH_SHA1: { |
680 | const int hashlen = SHA1_HASH_LEN_BYTE; | 680 | const int hashlen = SHA1_HASH_LEN_BYTE; |
681 | Sha1 hash; | 681 | Sha1 hash; |
682 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 682 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
683 | string ret = hash.sha1_read(); | 683 | string ret = hash.sha1_read(); |
684 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 684 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
685 | return e_writeFile; | 685 | return e_writeFile; |
686 | break; | 686 | break; |
687 | } | 687 | } |
688 | case PWM_HASH_SHA256: | 688 | case PWM_HASH_SHA256: |
689 | /*... fall through */ | 689 | /*... fall through */ |
690 | case PWM_HASH_SHA384: | 690 | case PWM_HASH_SHA384: |
691 | case PWM_HASH_SHA512: | 691 | case PWM_HASH_SHA512: |
692 | case PWM_HASH_MD5: | 692 | case PWM_HASH_MD5: |
693 | case PWM_HASH_RMD160: | 693 | case PWM_HASH_RMD160: |
694 | case PWM_HASH_TIGER: | 694 | case PWM_HASH_TIGER: |
695 | { | 695 | { |
696 | if (!LibGCryptIf::available()) | 696 | if (!LibGCryptIf::available()) |
697 | return e_hashNotImpl; | 697 | return e_hashNotImpl; |
698 | LibGCryptIf gc; | 698 | LibGCryptIf gc; |
699 | PwMerror err; | 699 | PwMerror err; |
700 | unsigned char *buf; | 700 | unsigned char *buf; |
701 | size_t hashLen; | 701 | size_t hashLen; |
702 | err = gc.hash(&buf, | 702 | err = gc.hash(&buf, |
703 | &hashLen, | 703 | &hashLen, |
704 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 704 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
705 | pw->length(), | 705 | pw->length(), |
706 | keyHash); | 706 | keyHash); |
707 | if (err != e_success) | 707 | if (err != e_success) |
708 | return e_hashNotImpl; | 708 | return e_hashNotImpl; |
709 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 709 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
710 | != static_cast<Q_LONG>(hashLen)) { | 710 | != static_cast<Q_LONG>(hashLen)) { |
711 | delete [] buf; | 711 | delete [] buf; |
712 | return e_hashNotImpl; | 712 | return e_hashNotImpl; |
713 | } | 713 | } |
714 | delete [] buf; | 714 | delete [] buf; |
715 | break; | 715 | break; |
716 | } | 716 | } |
717 | default: { | 717 | default: { |
718 | return e_hashNotImpl; | 718 | return e_hashNotImpl; |
719 | } } | 719 | } } |
720 | return e_success; | 720 | return e_success; |
721 | } | 721 | } |
722 | 722 | ||
723 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 723 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
724 | unsigned int *headerLength, char *dataHashType, | 724 | unsigned int *headerLength, char *dataHashType, |
725 | string *dataHash, QFile *f) | 725 | string *dataHash, QFile *f) |
726 | { | 726 | { |
727 | PWM_ASSERT(cryptAlgo); | 727 | PWM_ASSERT(cryptAlgo); |
728 | PWM_ASSERT(pw); | 728 | PWM_ASSERT(pw); |
729 | PWM_ASSERT(headerLength); | 729 | PWM_ASSERT(headerLength); |
730 | PWM_ASSERT(dataHashType); | 730 | PWM_ASSERT(dataHashType); |
731 | PWM_ASSERT(dataHash); | 731 | PWM_ASSERT(dataHash); |
732 | PWM_ASSERT(f); | 732 | PWM_ASSERT(f); |
733 | int tmpRet; | 733 | int tmpRet; |
734 | // check "magic" header | 734 | // check "magic" header |
735 | const char magicHdr[] = FILE_ID_HEADER; | 735 | const char magicHdr[] = FILE_ID_HEADER; |
736 | const int hdrLen = array_size(magicHdr) - 1; | 736 | const int hdrLen = array_size(magicHdr) - 1; |
737 | char tmp[hdrLen]; | 737 | char tmp[hdrLen]; |
738 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 738 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
739 | return e_readFile; | 739 | return e_readFile; |
740 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 740 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
741 | return e_fileFormat; | 741 | return e_fileFormat; |
742 | // read and check file ver | 742 | // read and check file ver |
743 | int fileV = f->getch(); | 743 | int fileV = f->getch(); |
744 | if (fileV == -1) | 744 | if (fileV == -1) |
745 | return e_fileFormat; | 745 | return e_fileFormat; |
746 | if (fileV != PWM_FILE_VER) | 746 | if (fileV != PWM_FILE_VER) |
747 | return e_fileVer; | 747 | return e_fileVer; |
748 | // read hash hash type | 748 | // read hash hash type |
749 | int keyHash = f->getch(); | 749 | int keyHash = f->getch(); |
750 | if (keyHash == -1) | 750 | if (keyHash == -1) |
751 | return e_fileFormat; | 751 | return e_fileFormat; |
752 | // read data hash type | 752 | // read data hash type |
753 | tmpRet = f->getch(); | 753 | tmpRet = f->getch(); |
754 | if (tmpRet == -1) | 754 | if (tmpRet == -1) |
755 | return e_fileFormat; | 755 | return e_fileFormat; |
756 | *dataHashType = tmpRet; | 756 | *dataHashType = tmpRet; |
757 | // read crypt algo | 757 | // read crypt algo |
758 | tmpRet = f->getch(); | 758 | tmpRet = f->getch(); |
759 | if (tmpRet == -1) | 759 | if (tmpRet == -1) |
760 | return e_fileFormat; | 760 | return e_fileFormat; |
761 | *cryptAlgo = tmpRet; | 761 | *cryptAlgo = tmpRet; |
762 | // get compression-algo | 762 | // get compression-algo |
763 | tmpRet = f->getch(); | 763 | tmpRet = f->getch(); |
764 | if (tmpRet == -1) | 764 | if (tmpRet == -1) |
765 | return e_fileFormat; | 765 | return e_fileFormat; |
766 | *compress = tmpRet; | 766 | *compress = tmpRet; |
767 | // get the MPW-flag | 767 | // get the MPW-flag |
768 | int mpw_flag = f->getch(); | 768 | int mpw_flag = f->getch(); |
769 | if (mpw_flag == -1) | 769 | if (mpw_flag == -1) |
770 | return e_fileFormat; | 770 | return e_fileFormat; |
771 | if (mpw_flag == 0x01) | 771 | if (mpw_flag == 0x01) |
772 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 772 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
773 | else | 773 | else |
774 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 774 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
775 | // skip the "RESERVED"-bytes | 775 | // skip the "RESERVED"-bytes |
776 | if (!(f->at(f->at() + 64))) | 776 | if (!(f->at(f->at() + 64))) |
777 | return e_fileFormat; | 777 | return e_fileFormat; |
778 | 778 | ||
779 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 779 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
780 | if (*pw == "") { | 780 | if (*pw == "") { |
781 | /* the user didn't give a master-password | 781 | /* the user didn't give a master-password |
782 | * or didn't insert a chipcard | 782 | * or didn't insert a chipcard |
783 | */ | 783 | */ |
784 | return e_noPw; | 784 | return e_noPw; |
785 | } | 785 | } |
786 | // verify key-hash | 786 | // verify key-hash |
787 | switch (keyHash) { | 787 | switch (keyHash) { |
788 | case PWM_HASH_SHA1: { | 788 | case PWM_HASH_SHA1: { |
789 | // read hash from header | 789 | // read hash from header |
790 | const int hashLen = SHA1_HASH_LEN_BYTE; | 790 | const int hashLen = SHA1_HASH_LEN_BYTE; |
791 | string readHash; | 791 | string readHash; |
792 | int i; | 792 | int i; |
793 | for (i = 0; i < hashLen; ++i) | 793 | for (i = 0; i < hashLen; ++i) |
794 | readHash.push_back(f->getch()); | 794 | readHash.push_back(f->getch()); |
795 | Sha1 hash; | 795 | Sha1 hash; |
796 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 796 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
797 | string ret = hash.sha1_read(); | 797 | string ret = hash.sha1_read(); |
798 | if (ret != readHash) | 798 | if (ret != readHash) |
799 | return e_wrongPw;// hash doesn't match (wrong key) | 799 | return e_wrongPw;// hash doesn't match (wrong key) |
800 | break; | 800 | break; |
801 | } | 801 | } |
802 | case PWM_HASH_SHA256: | 802 | case PWM_HASH_SHA256: |
803 | /*... fall through */ | 803 | /*... fall through */ |
804 | case PWM_HASH_SHA384: | 804 | case PWM_HASH_SHA384: |
805 | case PWM_HASH_SHA512: | 805 | case PWM_HASH_SHA512: |
806 | case PWM_HASH_MD5: | 806 | case PWM_HASH_MD5: |
807 | case PWM_HASH_RMD160: | 807 | case PWM_HASH_RMD160: |
808 | case PWM_HASH_TIGER: { | 808 | case PWM_HASH_TIGER: { |
809 | if (!LibGCryptIf::available()) | 809 | if (!LibGCryptIf::available()) |
810 | return e_hashNotImpl; | 810 | return e_hashNotImpl; |
811 | LibGCryptIf gc; | 811 | LibGCryptIf gc; |
812 | PwMerror err; | 812 | PwMerror err; |
813 | unsigned char *buf; | 813 | unsigned char *buf; |
814 | size_t hashLen; | 814 | size_t hashLen; |
815 | err = gc.hash(&buf, | 815 | err = gc.hash(&buf, |
816 | &hashLen, | 816 | &hashLen, |
817 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 817 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
818 | pw->length(), | 818 | pw->length(), |
819 | keyHash); | 819 | keyHash); |
820 | if (err != e_success) | 820 | if (err != e_success) |
821 | return e_hashNotImpl; | 821 | return e_hashNotImpl; |
822 | string calcHash(reinterpret_cast<const char *>(buf), | 822 | string calcHash(reinterpret_cast<const char *>(buf), |
823 | static_cast<string::size_type>(hashLen)); | 823 | static_cast<string::size_type>(hashLen)); |
824 | delete [] buf; | 824 | delete [] buf; |
825 | // read hash from header | 825 | // read hash from header |
826 | string readHash; | 826 | string readHash; |
827 | size_t i; | 827 | size_t i; |
828 | for (i = 0; i < hashLen; ++i) | 828 | for (i = 0; i < hashLen; ++i) |
829 | readHash.push_back(f->getch()); | 829 | readHash.push_back(f->getch()); |
830 | if (calcHash != readHash) | 830 | if (calcHash != readHash) |
831 | return e_wrongPw;// hash doesn't match (wrong key) | 831 | return e_wrongPw;// hash doesn't match (wrong key) |
832 | break; | 832 | break; |
833 | } | 833 | } |
834 | default: { | 834 | default: { |
835 | return e_hashNotImpl; | 835 | return e_hashNotImpl; |
836 | } } | 836 | } } |
837 | // read the data-hash from the file | 837 | // read the data-hash from the file |
838 | unsigned int hashLen, i; | 838 | unsigned int hashLen, i; |
839 | switch (*dataHashType) { | 839 | switch (*dataHashType) { |
840 | case PWM_HASH_SHA1: | 840 | case PWM_HASH_SHA1: |
841 | hashLen = SHA1_HASH_LEN_BYTE; | 841 | hashLen = SHA1_HASH_LEN_BYTE; |
842 | break; | 842 | break; |
843 | case PWM_HASH_SHA256: | 843 | case PWM_HASH_SHA256: |
844 | /*... fall through */ | 844 | /*... fall through */ |
845 | case PWM_HASH_SHA384: | 845 | case PWM_HASH_SHA384: |
846 | case PWM_HASH_SHA512: | 846 | case PWM_HASH_SHA512: |
847 | case PWM_HASH_MD5: | 847 | case PWM_HASH_MD5: |
848 | case PWM_HASH_RMD160: | 848 | case PWM_HASH_RMD160: |
849 | case PWM_HASH_TIGER: { | 849 | case PWM_HASH_TIGER: { |
850 | if (!LibGCryptIf::available()) | 850 | if (!LibGCryptIf::available()) |
851 | return e_hashNotImpl; | 851 | return e_hashNotImpl; |
852 | LibGCryptIf gc; | 852 | LibGCryptIf gc; |
853 | hashLen = gc.hashLength(*dataHashType); | 853 | hashLen = gc.hashLength(*dataHashType); |
854 | if (hashLen == 0) | 854 | if (hashLen == 0) |
855 | return e_hashNotImpl; | 855 | return e_hashNotImpl; |
856 | break; | 856 | break; |
857 | } | 857 | } |
858 | default: | 858 | default: |
859 | return e_hashNotImpl; | 859 | return e_hashNotImpl; |
860 | } | 860 | } |
861 | *dataHash = ""; | 861 | *dataHash = ""; |
862 | for (i = 0; i < hashLen; ++i) { | 862 | for (i = 0; i < hashLen; ++i) { |
863 | tmpRet = f->getch(); | 863 | tmpRet = f->getch(); |
864 | if (tmpRet == -1) | 864 | if (tmpRet == -1) |
865 | return e_fileFormat; | 865 | return e_fileFormat; |
866 | dataHash->push_back(static_cast<char>(tmpRet)); | 866 | dataHash->push_back(static_cast<char>(tmpRet)); |
867 | } | 867 | } |
868 | *headerLength = f->at(); | 868 | *headerLength = f->at(); |
869 | #ifndef PWM_EMBEDDED | 869 | #ifndef PWM_EMBEDDED |
870 | printDebug(string("opening file { compress: ") | 870 | printDebug(string("opening file { compress: ") |
871 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 871 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
872 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 872 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
873 | + tostr(static_cast<int>(keyHash)) | 873 | + tostr(static_cast<int>(keyHash)) |
874 | + " }"); | 874 | + " }"); |
875 | #else | 875 | #else |
876 | printDebug(string("opening file { compress: ") | 876 | printDebug(string("opening file { compress: ") |
877 | + tostr((int)(*compress)) + " cryptAlgo: " | 877 | + tostr((int)(*compress)) + " cryptAlgo: " |
878 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 878 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
879 | + tostr((int)(keyHash)) | 879 | + tostr((int)(keyHash)) |
880 | + " }"); | 880 | + " }"); |
881 | #endif | 881 | #endif |
882 | 882 | ||
883 | return e_success; | 883 | return e_success; |
884 | } | 884 | } |
885 | 885 | ||
886 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 886 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
887 | { | 887 | { |
888 | PWM_ASSERT(d); | 888 | PWM_ASSERT(d); |
889 | PWM_ASSERT(f); | 889 | PWM_ASSERT(f); |
890 | 890 | ||
891 | switch (dataHash) { | 891 | switch (dataHash) { |
892 | case PWM_HASH_SHA1: { | 892 | case PWM_HASH_SHA1: { |
893 | const int hashLen = SHA1_HASH_LEN_BYTE; | 893 | const int hashLen = SHA1_HASH_LEN_BYTE; |
894 | Sha1 h; | 894 | Sha1 h; |
895 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 895 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
896 | string hRet = h.sha1_read(); | 896 | string hRet = h.sha1_read(); |
897 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 897 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
898 | return e_writeFile; | 898 | return e_writeFile; |
899 | break; | 899 | break; |
900 | } | 900 | } |
901 | case PWM_HASH_SHA256: | 901 | case PWM_HASH_SHA256: |
902 | /*... fall through */ | 902 | /*... fall through */ |
903 | case PWM_HASH_SHA384: | 903 | case PWM_HASH_SHA384: |
904 | case PWM_HASH_SHA512: | 904 | case PWM_HASH_SHA512: |
905 | case PWM_HASH_MD5: | 905 | case PWM_HASH_MD5: |
906 | case PWM_HASH_RMD160: | 906 | case PWM_HASH_RMD160: |
907 | case PWM_HASH_TIGER: { | 907 | case PWM_HASH_TIGER: { |
908 | if (!LibGCryptIf::available()) | 908 | if (!LibGCryptIf::available()) |
909 | return e_hashNotImpl; | 909 | return e_hashNotImpl; |
910 | LibGCryptIf gc; | 910 | LibGCryptIf gc; |
911 | PwMerror err; | 911 | PwMerror err; |
912 | unsigned char *buf; | 912 | unsigned char *buf; |
913 | size_t hashLen; | 913 | size_t hashLen; |
914 | err = gc.hash(&buf, | 914 | err = gc.hash(&buf, |
915 | &hashLen, | 915 | &hashLen, |
916 | reinterpret_cast<const unsigned char *>(d->c_str()), | 916 | reinterpret_cast<const unsigned char *>(d->c_str()), |
917 | d->size(), | 917 | d->size(), |
918 | dataHash); | 918 | dataHash); |
919 | if (err != e_success) | 919 | if (err != e_success) |
920 | return e_hashNotImpl; | 920 | return e_hashNotImpl; |
921 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 921 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
922 | != static_cast<Q_LONG>(hashLen)) { | 922 | != static_cast<Q_LONG>(hashLen)) { |
923 | delete [] buf; | 923 | delete [] buf; |
924 | return e_hashNotImpl; | 924 | return e_hashNotImpl; |
925 | } | 925 | } |
926 | delete [] buf; | 926 | delete [] buf; |
927 | break; | 927 | break; |
928 | } | 928 | } |
929 | default: { | 929 | default: { |
930 | return e_hashNotImpl; | 930 | return e_hashNotImpl; |
931 | } } | 931 | } } |
932 | 932 | ||
933 | return e_success; | 933 | return e_success; |
934 | } | 934 | } |
935 | 935 | ||
936 | bool PwMDoc::backupFile(const QString &filePath) | 936 | bool PwMDoc::backupFile(const QString &filePath) |
937 | { | 937 | { |
938 | QFileInfo fi(filePath); | 938 | QFileInfo fi(filePath); |
939 | if (!fi.exists()) | 939 | if (!fi.exists()) |
940 | return true; // Yes, true is correct. | 940 | return true; // Yes, true is correct. |
941 | QString pathOnly(fi.dirPath(true)); | 941 | QString pathOnly(fi.dirPath(true)); |
942 | QString nameOnly(fi.fileName()); | 942 | QString nameOnly(fi.fileName()); |
943 | QString backupPath = pathOnly | 943 | QString backupPath = pathOnly |
944 | + "/~" | 944 | + "/~" |
945 | + nameOnly | 945 | + nameOnly |
946 | + ".backup"; | 946 | + ".backup"; |
947 | return copyFile(filePath, backupPath); | 947 | return copyFile(filePath, backupPath); |
948 | } | 948 | } |
949 | 949 | ||
950 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 950 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
951 | { | 951 | { |
952 | QFileInfo fi(src); | 952 | QFileInfo fi(src); |
953 | if (!fi.exists()) | 953 | if (!fi.exists()) |
954 | return false; | 954 | return false; |
955 | if (QFile::exists(dst)) { | 955 | if (QFile::exists(dst)) { |
956 | if (!QFile::remove(dst)) | 956 | if (!QFile::remove(dst)) |
957 | return false; | 957 | return false; |
958 | } | 958 | } |
959 | QFile srcFd(src); | 959 | QFile srcFd(src); |
960 | if (!srcFd.open(IO_ReadOnly)) | 960 | if (!srcFd.open(IO_ReadOnly)) |
961 | return false; | 961 | return false; |
962 | QFile dstFd(dst); | 962 | QFile dstFd(dst); |
963 | if (!dstFd.open(IO_ReadWrite)) { | 963 | if (!dstFd.open(IO_ReadWrite)) { |
964 | srcFd.close(); | 964 | srcFd.close(); |
965 | return false; | 965 | return false; |
966 | } | 966 | } |
967 | const int tmpBuf_size = 512; | 967 | const int tmpBuf_size = 512; |
968 | char tmpBuf[tmpBuf_size]; | 968 | char tmpBuf[tmpBuf_size]; |
969 | Q_LONG bytesRead, bytesWritten; | 969 | Q_LONG bytesRead, bytesWritten; |
970 | 970 | ||
971 | while (!srcFd.atEnd()) { | 971 | while (!srcFd.atEnd()) { |
972 | bytesRead = srcFd.readBlock(tmpBuf, | 972 | bytesRead = srcFd.readBlock(tmpBuf, |
973 | static_cast<Q_ULONG>(tmpBuf_size)); | 973 | static_cast<Q_ULONG>(tmpBuf_size)); |
974 | if (bytesRead == -1) { | 974 | if (bytesRead == -1) { |
975 | srcFd.close(); | 975 | srcFd.close(); |
976 | dstFd.close(); | 976 | dstFd.close(); |
977 | return false; | 977 | return false; |
978 | } | 978 | } |
979 | bytesWritten = dstFd.writeBlock(tmpBuf, | 979 | bytesWritten = dstFd.writeBlock(tmpBuf, |
980 | static_cast<Q_ULONG>(bytesRead)); | 980 | static_cast<Q_ULONG>(bytesRead)); |
981 | if (bytesWritten != bytesRead) { | 981 | if (bytesWritten != bytesRead) { |
982 | srcFd.close(); | 982 | srcFd.close(); |
983 | dstFd.close(); | 983 | dstFd.close(); |
984 | return false; | 984 | return false; |
985 | } | 985 | } |
986 | } | 986 | } |
987 | srcFd.close(); | 987 | srcFd.close(); |
988 | dstFd.close(); | 988 | dstFd.close(); |
989 | return true; | 989 | return true; |
990 | } | 990 | } |
991 | 991 | ||
992 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 992 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
993 | bool dontFlagDirty, bool updateMeta) | 993 | bool dontFlagDirty, bool updateMeta) |
994 | { | 994 | { |
995 | PWM_ASSERT(d); | 995 | PWM_ASSERT(d); |
996 | unsigned int cat = 0; | 996 | unsigned int cat = 0; |
997 | 997 | ||
998 | if (isDeepLocked()) { | 998 | if (isDeepLocked()) { |
999 | PwMerror ret; | 999 | PwMerror ret; |
1000 | ret = deepLock(false); | 1000 | ret = deepLock(false); |
1001 | if (ret != e_success) | 1001 | if (ret != e_success) |
1002 | return e_lock; | 1002 | return e_lock; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | addCategory(category, &cat); | 1005 | addCategory(category, &cat); |
1006 | 1006 | ||
1007 | if (numEntries(category) >= maxEntries) | 1007 | if (numEntries(category) >= maxEntries) |
1008 | return e_maxAllowedEntr; | 1008 | return e_maxAllowedEntr; |
1009 | 1009 | ||
1010 | vector<unsigned int> foundPositions; | 1010 | vector<unsigned int> foundPositions; |
1011 | /* historically this was: | 1011 | /* historically this was: |
1012 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 1012 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
1013 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 1013 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
1014 | * But for now we only search in desc. | 1014 | * But for now we only search in desc. |
1015 | * That's a tweak to be KWallet compatible. But it should not add | 1015 | * That's a tweak to be KWallet compatible. But it should not add |
1016 | * usability-drop onto PwManager, does it? | 1016 | * usability-drop onto PwManager, does it? |
1017 | * (And yes, "int" was a bug. Correct is "unsigned int") | 1017 | * (And yes, "int" was a bug. Correct is "unsigned int") |
1018 | */ | 1018 | */ |
1019 | const unsigned int searchIn = SEARCH_IN_DESC; | 1019 | const unsigned int searchIn = SEARCH_IN_DESC; |
1020 | findEntry(cat, *d, searchIn, &foundPositions, true); | 1020 | findEntry(cat, *d, searchIn, &foundPositions, true); |
1021 | if (foundPositions.size()) { | 1021 | if (foundPositions.size()) { |
1022 | // DOH! We found this entry. | 1022 | // DOH! We found this entry. |
1023 | return e_entryExists; | 1023 | return e_entryExists; |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | d->listViewPos = -1; | 1026 | d->listViewPos = -1; |
1027 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1027 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1028 | if (updateMeta) { | 1028 | if (updateMeta) { |
1029 | d->meta.create = QDateTime::currentDateTime(); | 1029 | d->meta.create = QDateTime::currentDateTime(); |
1030 | d->meta.update = d->meta.create; | 1030 | d->meta.update = d->meta.create; |
1031 | } | 1031 | } |
1032 | dti.dta[cat].d.push_back(*d); | 1032 | dti.dta[cat].d.push_back(*d); |
1033 | 1033 | ||
1034 | delAllEmptyCat(true); | 1034 | delAllEmptyCat(true); |
1035 | 1035 | ||
1036 | if (!dontFlagDirty) | 1036 | if (!dontFlagDirty) |
1037 | flagDirty(); | 1037 | flagDirty(); |
1038 | return e_success; | 1038 | return e_success; |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1041 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1042 | bool checkIfExist) | 1042 | bool checkIfExist) |
1043 | { | 1043 | { |
1044 | if (isDeepLocked()) { | 1044 | if (isDeepLocked()) { |
1045 | PwMerror ret; | 1045 | PwMerror ret; |
1046 | ret = deepLock(false); | 1046 | ret = deepLock(false); |
1047 | if (ret != e_success) | 1047 | if (ret != e_success) |
1048 | return e_lock; | 1048 | return e_lock; |
1049 | } | 1049 | } |
1050 | if (checkIfExist) { | 1050 | if (checkIfExist) { |
1051 | if (findCategory(category, categoryIndex)) | 1051 | if (findCategory(category, categoryIndex)) |
1052 | return e_categoryExists; | 1052 | return e_categoryExists; |
1053 | } | 1053 | } |
1054 | PwMCategoryItem item; | 1054 | PwMCategoryItem item; |
1055 | //US ENH: clear item to initialize with default values, or create a constructor | ||
1056 | item.clear(); | ||
1057 | |||
1055 | item.name = category.latin1(); | 1058 | item.name = category.latin1(); |
1056 | dti.dta.push_back(item); | 1059 | dti.dta.push_back(item); |
1057 | if (categoryIndex) | 1060 | if (categoryIndex) |
1058 | *categoryIndex = dti.dta.size() - 1; | 1061 | *categoryIndex = dti.dta.size() - 1; |
1059 | return e_success; | 1062 | return e_success; |
1060 | } | 1063 | } |
1061 | 1064 | ||
1062 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1065 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1063 | { | 1066 | { |
1064 | unsigned int cat = 0; | 1067 | unsigned int cat = 0; |
1065 | 1068 | ||
1066 | if (!findCategory(category, &cat)) { | 1069 | if (!findCategory(category, &cat)) { |
1067 | BUG(); | 1070 | BUG(); |
1068 | return false; | 1071 | return false; |
1069 | } | 1072 | } |
1070 | 1073 | ||
1071 | return delEntry(cat, index, dontFlagDirty); | 1074 | return delEntry(cat, index, dontFlagDirty); |
1072 | } | 1075 | } |
1073 | 1076 | ||
1074 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1077 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1075 | { | 1078 | { |
1076 | if (isDeepLocked()) | 1079 | if (isDeepLocked()) |
1077 | return false; | 1080 | return false; |
1078 | if (index > dti.dta[category].d.size() - 1) | 1081 | if (index > dti.dta[category].d.size() - 1) |
1079 | return false; | 1082 | return false; |
1080 | getDataChangedLock(); | 1083 | getDataChangedLock(); |
1081 | if (!lockAt(category, index, false)) { | 1084 | if (!lockAt(category, index, false)) { |
1082 | putDataChangedLock(); | 1085 | putDataChangedLock(); |
1083 | return false; | 1086 | return false; |
1084 | } | 1087 | } |
1085 | putDataChangedLock(); | 1088 | putDataChangedLock(); |
1086 | int lvPos = dti.dta[category].d[index].listViewPos; | 1089 | int lvPos = dti.dta[category].d[index].listViewPos; |
1087 | 1090 | ||
1088 | // delete entry | 1091 | // delete entry |
1089 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); | 1092 | dti.dta[category].d.erase(dti.dta[category].d.begin() + index); |
1090 | 1093 | ||
1091 | unsigned int i, entries = numEntries(category); | 1094 | unsigned int i, entries = numEntries(category); |
1092 | if (!entries) { | 1095 | if (!entries) { |
1093 | // no more entries in this category, so | 1096 | // no more entries in this category, so |
1094 | // we can delete it, too. | 1097 | // we can delete it, too. |
1095 | BUG_ON(!delCategory(category)); | 1098 | BUG_ON(!delCategory(category)); |
1096 | // delCategory() flags it dirty, so we need not to do so. | 1099 | // delCategory() flags it dirty, so we need not to do so. |
1097 | return true; | 1100 | return true; |
1098 | } | 1101 | } |
1099 | for (i = 0; i < entries; ++i) { | 1102 | for (i = 0; i < entries; ++i) { |
1100 | // decrement all listViewPositions that are greater than the deleted. | 1103 | // decrement all listViewPositions that are greater than the deleted. |
1101 | if (dti.dta[category].d[i].listViewPos > lvPos) | 1104 | if (dti.dta[category].d[i].listViewPos > lvPos) |
1102 | --dti.dta[category].d[i].listViewPos; | 1105 | --dti.dta[category].d[i].listViewPos; |
1103 | } | 1106 | } |
1104 | 1107 | ||
1105 | if (!dontFlagDirty) | 1108 | if (!dontFlagDirty) |
1106 | flagDirty(); | 1109 | flagDirty(); |
1107 | return true; | 1110 | return true; |
1108 | } | 1111 | } |
1109 | 1112 | ||
1110 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1113 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1111 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1114 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1112 | { | 1115 | { |
1113 | PWM_ASSERT(d); | 1116 | PWM_ASSERT(d); |
1114 | unsigned int oldCat = 0; | 1117 | unsigned int oldCat = 0; |
1115 | 1118 | ||
1116 | if (!findCategory(oldCategory, &oldCat)) { | 1119 | if (!findCategory(oldCategory, &oldCat)) { |
1117 | BUG(); | 1120 | BUG(); |
1118 | return false; | 1121 | return false; |
1119 | } | 1122 | } |
1120 | 1123 | ||
1121 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1124 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1122 | } | 1125 | } |
1123 | 1126 | ||
1124 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1127 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1125 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1128 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1126 | { | 1129 | { |
1127 | if (isDeepLocked()) | 1130 | if (isDeepLocked()) |
1128 | return false; | 1131 | return false; |
1129 | if (updateMeta) { | 1132 | if (updateMeta) { |
1130 | d->meta.update = QDateTime::currentDateTime(); | 1133 | d->meta.update = QDateTime::currentDateTime(); |
1131 | if (d->meta.create.isNull()) { | 1134 | if (d->meta.create.isNull()) { |
1132 | d->meta.create = d->meta.update; | 1135 | d->meta.create = d->meta.update; |
1133 | } | 1136 | } |
1134 | } | 1137 | } |
1135 | if (dti.dta[oldCategory].name != newCategory.latin1()) { | 1138 | if (dti.dta[oldCategory].name != newCategory.latin1()) { |
1136 | // the user changed the category. | 1139 | // the user changed the category. |
1137 | PwMerror ret; | 1140 | PwMerror ret; |
1138 | d->rev = 0; | 1141 | d->rev = 0; |
1139 | ret = addEntry(newCategory, d, true, false); | 1142 | ret = addEntry(newCategory, d, true, false); |
1140 | if (ret != e_success) | 1143 | if (ret != e_success) |
1141 | return false; | 1144 | return false; |
1142 | if (!delEntry(oldCategory, index, true)) | 1145 | if (!delEntry(oldCategory, index, true)) |
1143 | return false; | 1146 | return false; |
1144 | } else { | 1147 | } else { |
1145 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1148 | d->rev = dti.dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1146 | dti.dta[oldCategory].d[index] = *d; | 1149 | dti.dta[oldCategory].d[index] = *d; |
1147 | } | 1150 | } |
1148 | flagDirty(); | 1151 | flagDirty(); |
1149 | return true; | 1152 | return true; |
1150 | } | 1153 | } |
1151 | 1154 | ||
1152 | unsigned int PwMDoc::numEntries(const QString &category) | 1155 | unsigned int PwMDoc::numEntries(const QString &category) |
1153 | { | 1156 | { |
1154 | unsigned int cat = 0; | 1157 | unsigned int cat = 0; |
1155 | 1158 | ||
1156 | if (!findCategory(category, &cat)) { | 1159 | if (!findCategory(category, &cat)) { |
1157 | BUG(); | 1160 | BUG(); |
1158 | return 0; | 1161 | return 0; |
1159 | } | 1162 | } |
1160 | 1163 | ||
1161 | return numEntries(cat); | 1164 | return numEntries(cat); |
1162 | } | 1165 | } |
1163 | 1166 | ||
1164 | bool PwMDoc::serializeDta(string *d) | 1167 | bool PwMDoc::serializeDta(string *d) |
1165 | { | 1168 | { |
1166 | PWM_ASSERT(d); | 1169 | PWM_ASSERT(d); |
1167 | Serializer ser; | 1170 | Serializer ser; |
1168 | if (!ser.serialize(dti)) | 1171 | if (!ser.serialize(dti)) |
1169 | return false; | 1172 | return false; |
1170 | d->assign(ser.getXml()); | 1173 | d->assign(ser.getXml()); |
1171 | if (!d->size()) | 1174 | if (!d->size()) |
1172 | return false; | 1175 | return false; |
1173 | return true; | 1176 | return true; |
1174 | } | 1177 | } |
1175 | 1178 | ||
1176 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1179 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1177 | { | 1180 | { |
1178 | PWM_ASSERT(d); | 1181 | PWM_ASSERT(d); |
1179 | #ifndef PWM_EMBEDDED | 1182 | #ifndef PWM_EMBEDDED |
1180 | try { | 1183 | try { |
1181 | 1184 | ||
1182 | Serializer ser(d->c_str()); | 1185 | Serializer ser(d->c_str()); |
1183 | ser.setDefaultLockStat(entriesLocked); | 1186 | ser.setDefaultLockStat(entriesLocked); |
1184 | if (!ser.deSerialize(&dti)) | 1187 | if (!ser.deSerialize(&dti)) |
1185 | return false; | 1188 | return false; |
1186 | } catch (PwMException) { | 1189 | } catch (PwMException) { |
1187 | return false; | 1190 | return false; |
1188 | } | 1191 | } |
1189 | #else | 1192 | #else |
1190 | Serializer ser(d->c_str()); | 1193 | Serializer ser(d->c_str()); |
1191 | ser.setDefaultLockStat(entriesLocked); | 1194 | ser.setDefaultLockStat(entriesLocked); |
1192 | if (!ser.deSerialize(&dti)) | 1195 | if (!ser.deSerialize(&dti)) |
1193 | return false; | 1196 | return false; |
1194 | #endif | 1197 | #endif |
1195 | 1198 | ||
1196 | emitDataChanged(this); | 1199 | emitDataChanged(this); |
1197 | return true; | 1200 | return true; |
1198 | } | 1201 | } |
1199 | 1202 | ||
1200 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1203 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1201 | PwMDataItem * d, bool unlockIfLocked) | 1204 | PwMDataItem * d, bool unlockIfLocked) |
1202 | { | 1205 | { |
1203 | PWM_ASSERT(d); | 1206 | PWM_ASSERT(d); |
1204 | unsigned int cat = 0; | 1207 | unsigned int cat = 0; |
1205 | 1208 | ||
1206 | if (!findCategory(category, &cat)) { | 1209 | if (!findCategory(category, &cat)) { |
1207 | BUG(); | 1210 | BUG(); |
1208 | return false; | 1211 | return false; |
1209 | } | 1212 | } |
1210 | 1213 | ||
1211 | return getEntry(cat, index, d, unlockIfLocked); | 1214 | return getEntry(cat, index, d, unlockIfLocked); |
1212 | } | 1215 | } |
1213 | 1216 | ||
1214 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1217 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1215 | PwMDataItem *d, bool unlockIfLocked) | 1218 | PwMDataItem *d, bool unlockIfLocked) |
1216 | { | 1219 | { |
1217 | if (index > dti.dta[category].d.size() - 1) | 1220 | if (index > dti.dta[category].d.size() - 1) |
1218 | return false; | 1221 | return false; |
1219 | 1222 | ||
1220 | bool locked = isLocked(category, index); | 1223 | bool locked = isLocked(category, index); |
1221 | if (locked) { | 1224 | if (locked) { |
1222 | /* this entry is locked. We don't return a password, | 1225 | /* this entry is locked. We don't return a password, |
1223 | * until it's unlocked by the user by inserting | 1226 | * until it's unlocked by the user by inserting |
1224 | * chipcard or entering the mpw | 1227 | * chipcard or entering the mpw |
1225 | */ | 1228 | */ |
1226 | if (unlockIfLocked) { | 1229 | if (unlockIfLocked) { |
1227 | if (!lockAt(category, index, false)) { | 1230 | if (!lockAt(category, index, false)) { |
1228 | return false; | 1231 | return false; |
1229 | } | 1232 | } |
1230 | locked = false; | 1233 | locked = false; |
1231 | } | 1234 | } |
1232 | } | 1235 | } |
1233 | 1236 | ||
1234 | *d = dti.dta[category].d[index]; | 1237 | *d = dti.dta[category].d[index]; |
1235 | if (locked) | 1238 | if (locked) |
1236 | d->pw = LOCKED_STRING.latin1(); | 1239 | d->pw = LOCKED_STRING.latin1(); |
1237 | 1240 | ||
1238 | return true; | 1241 | return true; |
1239 | } | 1242 | } |
1240 | 1243 | ||
1241 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1244 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1242 | string *foundComment) | 1245 | string *foundComment) |
1243 | { | 1246 | { |
1244 | PWM_ASSERT(foundComment); | 1247 | PWM_ASSERT(foundComment); |
1245 | unsigned int cat = 0; | 1248 | unsigned int cat = 0; |
1246 | 1249 | ||
1247 | if (!findCategory(category, &cat)) | 1250 | if (!findCategory(category, &cat)) |
1248 | return e_invalidArg; | 1251 | return e_invalidArg; |
1249 | 1252 | ||
1250 | unsigned int i, entries = numEntries(cat); | 1253 | unsigned int i, entries = numEntries(cat); |
1251 | for (i = 0; i < entries; ++i) { | 1254 | for (i = 0; i < entries; ++i) { |
1252 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { | 1255 | if (dti.dta[cat].d[i].listViewPos == listViewPos) { |
1253 | *foundComment = dti.dta[cat].d[i].comment; | 1256 | *foundComment = dti.dta[cat].d[i].comment; |
1254 | if (dti.dta[cat].d[i].binary) | 1257 | if (dti.dta[cat].d[i].binary) |
1255 | return e_binEntry; | 1258 | return e_binEntry; |
1256 | return e_normalEntry; | 1259 | return e_normalEntry; |
1257 | } | 1260 | } |
1258 | } | 1261 | } |
1259 | BUG(); | 1262 | BUG(); |
1260 | return e_generic; | 1263 | return e_generic; |
1261 | } | 1264 | } |
1262 | 1265 | ||
1263 | bool PwMDoc::compressDta(string *d, char algo) | 1266 | bool PwMDoc::compressDta(string *d, char algo) |
1264 | { | 1267 | { |
1265 | PWM_ASSERT(d); | 1268 | PWM_ASSERT(d); |
1266 | switch (algo) { | 1269 | switch (algo) { |
1267 | case PWM_COMPRESS_GZIP: { | 1270 | case PWM_COMPRESS_GZIP: { |
1268 | CompressGzip comp; | 1271 | CompressGzip comp; |
1269 | return comp.compress(d); | 1272 | return comp.compress(d); |
1270 | } | 1273 | } |
1271 | #ifndef PWM_EMBEDDED | 1274 | #ifndef PWM_EMBEDDED |
1272 | case PWM_COMPRESS_BZIP2: { | 1275 | case PWM_COMPRESS_BZIP2: { |
1273 | CompressBzip2 comp; | 1276 | CompressBzip2 comp; |
1274 | return comp.compress(d); | 1277 | return comp.compress(d); |
1275 | } | 1278 | } |
1276 | #endif | 1279 | #endif |
1277 | case PWM_COMPRESS_NONE: { | 1280 | case PWM_COMPRESS_NONE: { |
1278 | return true; | 1281 | return true; |
1279 | } default: { | 1282 | } default: { |
1280 | BUG(); | 1283 | BUG(); |
1281 | } | 1284 | } |
1282 | } | 1285 | } |
1283 | return false; | 1286 | return false; |
1284 | } | 1287 | } |
1285 | 1288 | ||
1286 | bool PwMDoc::decompressDta(string *d, char algo) | 1289 | bool PwMDoc::decompressDta(string *d, char algo) |
1287 | { | 1290 | { |
1288 | PWM_ASSERT(d); | 1291 | PWM_ASSERT(d); |
1289 | switch (algo) { | 1292 | switch (algo) { |
1290 | case PWM_COMPRESS_GZIP: { | 1293 | case PWM_COMPRESS_GZIP: { |
1291 | CompressGzip comp; | 1294 | CompressGzip comp; |
1292 | return comp.decompress(d); | 1295 | return comp.decompress(d); |
1293 | } | 1296 | } |
1294 | #ifndef PWM_EMBEDDED | 1297 | #ifndef PWM_EMBEDDED |
1295 | case PWM_COMPRESS_BZIP2: { | 1298 | case PWM_COMPRESS_BZIP2: { |
1296 | CompressBzip2 comp; | 1299 | CompressBzip2 comp; |
1297 | return comp.decompress(d); | 1300 | return comp.decompress(d); |
1298 | } | 1301 | } |
1299 | #endif | 1302 | #endif |
1300 | case PWM_COMPRESS_NONE: { | 1303 | case PWM_COMPRESS_NONE: { |
1301 | return true; | 1304 | return true; |
1302 | } | 1305 | } |
1303 | } | 1306 | } |
1304 | return false; | 1307 | return false; |
1305 | } | 1308 | } |
1306 | 1309 | ||
1307 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1310 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1308 | { | 1311 | { |
1309 | PWM_ASSERT(d); | 1312 | PWM_ASSERT(d); |
1310 | PWM_ASSERT(pw); | 1313 | PWM_ASSERT(pw); |
1311 | PWM_ASSERT(f); | 1314 | PWM_ASSERT(f); |
1312 | 1315 | ||
1313 | size_t encSize; | 1316 | size_t encSize; |
1314 | byte *encrypted = 0; | 1317 | byte *encrypted = 0; |
1315 | 1318 | ||
1316 | switch (algo) { | 1319 | switch (algo) { |
1317 | case PWM_CRYPT_BLOWFISH: { | 1320 | case PWM_CRYPT_BLOWFISH: { |
1318 | Blowfish::padNull(d); | 1321 | Blowfish::padNull(d); |
1319 | encSize = d->length(); | 1322 | encSize = d->length(); |
1320 | encrypted = new byte[encSize]; | 1323 | encrypted = new byte[encSize]; |
1321 | Blowfish bf; | 1324 | Blowfish bf; |
1322 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1325 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1323 | delete [] encrypted; | 1326 | delete [] encrypted; |
1324 | return e_weakPw; | 1327 | return e_weakPw; |
1325 | } | 1328 | } |
1326 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1329 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1327 | break; | 1330 | break; |
1328 | } | 1331 | } |
1329 | case PWM_CRYPT_AES128: | 1332 | case PWM_CRYPT_AES128: |
1330 | /*... fall through */ | 1333 | /*... fall through */ |
1331 | case PWM_CRYPT_AES192: | 1334 | case PWM_CRYPT_AES192: |
1332 | case PWM_CRYPT_AES256: | 1335 | case PWM_CRYPT_AES256: |
1333 | case PWM_CRYPT_3DES: | 1336 | case PWM_CRYPT_3DES: |
1334 | case PWM_CRYPT_TWOFISH: | 1337 | case PWM_CRYPT_TWOFISH: |
1335 | case PWM_CRYPT_TWOFISH128: { | 1338 | case PWM_CRYPT_TWOFISH128: { |
1336 | if (!LibGCryptIf::available()) | 1339 | if (!LibGCryptIf::available()) |
1337 | return e_cryptNotImpl; | 1340 | return e_cryptNotImpl; |
1338 | LibGCryptIf gc; | 1341 | LibGCryptIf gc; |
1339 | PwMerror err; | 1342 | PwMerror err; |
1340 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1343 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1341 | memcpy(plain, d->c_str(), d->length()); | 1344 | memcpy(plain, d->c_str(), d->length()); |
1342 | err = gc.encrypt(&encrypted, | 1345 | err = gc.encrypt(&encrypted, |
1343 | &encSize, | 1346 | &encSize, |
1344 | plain, | 1347 | plain, |
1345 | d->length(), | 1348 | d->length(), |
1346 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1349 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1347 | pw->length(), | 1350 | pw->length(), |
1348 | algo); | 1351 | algo); |
1349 | delete [] plain; | 1352 | delete [] plain; |
1350 | if (err != e_success) | 1353 | if (err != e_success) |
1351 | return e_cryptNotImpl; | 1354 | return e_cryptNotImpl; |
1352 | break; | 1355 | break; |
1353 | } | 1356 | } |
1354 | default: { | 1357 | default: { |
1355 | delete_ifnot_null_array(encrypted); | 1358 | delete_ifnot_null_array(encrypted); |
1356 | return e_cryptNotImpl; | 1359 | return e_cryptNotImpl; |
1357 | } } | 1360 | } } |
1358 | 1361 | ||
1359 | // write encrypted data to file | 1362 | // write encrypted data to file |
1360 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1363 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1361 | static_cast<Q_ULONG>(encSize)) | 1364 | static_cast<Q_ULONG>(encSize)) |
1362 | != static_cast<Q_LONG>(encSize)) { | 1365 | != static_cast<Q_LONG>(encSize)) { |
1363 | delete_ifnot_null_array(encrypted); | 1366 | delete_ifnot_null_array(encrypted); |
1364 | return e_writeFile; | 1367 | return e_writeFile; |
1365 | } | 1368 | } |
1366 | delete_ifnot_null_array(encrypted); | 1369 | delete_ifnot_null_array(encrypted); |
1367 | return e_success; | 1370 | return e_success; |
1368 | } | 1371 | } |
1369 | 1372 | ||
1370 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1373 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1371 | char algo, QFile *f) | 1374 | char algo, QFile *f) |
1372 | { | 1375 | { |
1373 | PWM_ASSERT(d); | 1376 | PWM_ASSERT(d); |
1374 | PWM_ASSERT(pw); | 1377 | PWM_ASSERT(pw); |
1375 | PWM_ASSERT(f); | 1378 | PWM_ASSERT(f); |
1376 | 1379 | ||
1377 | unsigned int cryptLen = f->size() - pos; | 1380 | unsigned int cryptLen = f->size() - pos; |
1378 | byte *encrypted = new byte[cryptLen]; | 1381 | byte *encrypted = new byte[cryptLen]; |
1379 | byte *decrypted = new byte[cryptLen]; | 1382 | byte *decrypted = new byte[cryptLen]; |
1380 | 1383 | ||
1381 | f->at(pos); | 1384 | f->at(pos); |
1382 | #ifndef PWM_EMBEDDED | 1385 | #ifndef PWM_EMBEDDED |
1383 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1386 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1384 | static_cast<Q_ULONG>(cryptLen)) | 1387 | static_cast<Q_ULONG>(cryptLen)) |
1385 | != static_cast<Q_LONG>(cryptLen)) { | 1388 | != static_cast<Q_LONG>(cryptLen)) { |
1386 | delete [] encrypted; | 1389 | delete [] encrypted; |
1387 | delete [] decrypted; | 1390 | delete [] decrypted; |
1388 | return e_readFile; | 1391 | return e_readFile; |
1389 | } | 1392 | } |
1390 | #else | 1393 | #else |
1391 | if (f->readBlock((char *)(encrypted), | 1394 | if (f->readBlock((char *)(encrypted), |
1392 | (unsigned long)(cryptLen)) | 1395 | (unsigned long)(cryptLen)) |
1393 | != (long)(cryptLen)) { | 1396 | != (long)(cryptLen)) { |
1394 | delete [] encrypted; | 1397 | delete [] encrypted; |
1395 | delete [] decrypted; | 1398 | delete [] decrypted; |
1396 | return e_readFile; | 1399 | return e_readFile; |
1397 | } | 1400 | } |
1398 | #endif | 1401 | #endif |
1399 | switch (algo) { | 1402 | switch (algo) { |
1400 | case PWM_CRYPT_BLOWFISH: { | 1403 | case PWM_CRYPT_BLOWFISH: { |
1401 | Blowfish bf; | 1404 | Blowfish bf; |
1402 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1405 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1403 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1406 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1404 | break; | 1407 | break; |
1405 | } | 1408 | } |
1406 | case PWM_CRYPT_AES128: | 1409 | case PWM_CRYPT_AES128: |
1407 | /*... fall through */ | 1410 | /*... fall through */ |
1408 | case PWM_CRYPT_AES192: | 1411 | case PWM_CRYPT_AES192: |
1409 | case PWM_CRYPT_AES256: | 1412 | case PWM_CRYPT_AES256: |
1410 | case PWM_CRYPT_3DES: | 1413 | case PWM_CRYPT_3DES: |
1411 | case PWM_CRYPT_TWOFISH: | 1414 | case PWM_CRYPT_TWOFISH: |
1412 | case PWM_CRYPT_TWOFISH128: { | 1415 | case PWM_CRYPT_TWOFISH128: { |
1413 | if (!LibGCryptIf::available()) | 1416 | if (!LibGCryptIf::available()) |
1414 | return e_cryptNotImpl; | 1417 | return e_cryptNotImpl; |
1415 | LibGCryptIf gc; | 1418 | LibGCryptIf gc; |
1416 | PwMerror err; | 1419 | PwMerror err; |
1417 | err = gc.decrypt(&decrypted, | 1420 | err = gc.decrypt(&decrypted, |
1418 | &cryptLen, | 1421 | &cryptLen, |
1419 | encrypted, | 1422 | encrypted, |
1420 | cryptLen, | 1423 | cryptLen, |
1421 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1424 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1422 | pw->length(), | 1425 | pw->length(), |
1423 | algo); | 1426 | algo); |
1424 | if (err != e_success) { | 1427 | if (err != e_success) { |
1425 | delete [] encrypted; | 1428 | delete [] encrypted; |
1426 | delete [] decrypted; | 1429 | delete [] decrypted; |
1427 | return e_cryptNotImpl; | 1430 | return e_cryptNotImpl; |
1428 | } | 1431 | } |
1429 | break; | 1432 | break; |
1430 | } | 1433 | } |
1431 | default: { | 1434 | default: { |
1432 | delete [] encrypted; | 1435 | delete [] encrypted; |
1433 | delete [] decrypted; | 1436 | delete [] decrypted; |
1434 | return e_cryptNotImpl; | 1437 | return e_cryptNotImpl; |
1435 | } } | 1438 | } } |
1436 | delete [] encrypted; | 1439 | delete [] encrypted; |
1437 | #ifndef PWM_EMBEDDED | 1440 | #ifndef PWM_EMBEDDED |
1438 | d->assign(reinterpret_cast<const char *>(decrypted), | 1441 | d->assign(reinterpret_cast<const char *>(decrypted), |
@@ -1499,768 +1502,770 @@ PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | |||
1499 | } | 1502 | } |
1500 | 1503 | ||
1501 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1504 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1502 | bool lock) | 1505 | bool lock) |
1503 | { | 1506 | { |
1504 | if (index >= numEntries(category)) { | 1507 | if (index >= numEntries(category)) { |
1505 | BUG(); | 1508 | BUG(); |
1506 | return false; | 1509 | return false; |
1507 | } | 1510 | } |
1508 | if (lock == dti.dta[category].d[index].lockStat) | 1511 | if (lock == dti.dta[category].d[index].lockStat) |
1509 | return true; | 1512 | return true; |
1510 | 1513 | ||
1511 | if (!lock && currentPw != "") { | 1514 | if (!lock && currentPw != "") { |
1512 | // "unlocking" and "password is already set" | 1515 | // "unlocking" and "password is already set" |
1513 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1516 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1514 | // unlocking without pw not allowed | 1517 | // unlocking without pw not allowed |
1515 | QString pw; | 1518 | QString pw; |
1516 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1519 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1517 | if (pw != "") { | 1520 | if (pw != "") { |
1518 | if (pw != currentPw) { | 1521 | if (pw != currentPw) { |
1519 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1522 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1520 | return false; | 1523 | return false; |
1521 | } else { | 1524 | } else { |
1522 | timer()->start(DocTimer::id_mpwTimer); | 1525 | timer()->start(DocTimer::id_mpwTimer); |
1523 | } | 1526 | } |
1524 | } else { | 1527 | } else { |
1525 | return false; | 1528 | return false; |
1526 | } | 1529 | } |
1527 | } else { | 1530 | } else { |
1528 | timer()->start(DocTimer::id_mpwTimer); | 1531 | timer()->start(DocTimer::id_mpwTimer); |
1529 | } | 1532 | } |
1530 | } | 1533 | } |
1531 | 1534 | ||
1532 | dti.dta[category].d[index].lockStat = lock; | 1535 | dti.dta[category].d[index].lockStat = lock; |
1533 | dti.dta[category].d[index].rev++; // increment revision counter. | 1536 | dti.dta[category].d[index].rev++; // increment revision counter. |
1534 | 1537 | ||
1535 | emitDataChanged(this); | 1538 | emitDataChanged(this); |
1536 | if (!lock) | 1539 | if (!lock) |
1537 | timer()->start(DocTimer::id_autoLockTimer); | 1540 | timer()->start(DocTimer::id_autoLockTimer); |
1538 | 1541 | ||
1539 | return true; | 1542 | return true; |
1540 | 1543 | ||
1541 | } | 1544 | } |
1542 | 1545 | ||
1543 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1546 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1544 | bool lock) | 1547 | bool lock) |
1545 | { | 1548 | { |
1546 | unsigned int cat = 0; | 1549 | unsigned int cat = 0; |
1547 | 1550 | ||
1548 | if (!findCategory(category, &cat)) { | 1551 | if (!findCategory(category, &cat)) { |
1549 | BUG(); | 1552 | BUG(); |
1550 | return false; | 1553 | return false; |
1551 | } | 1554 | } |
1552 | 1555 | ||
1553 | return lockAt(cat, index, lock); | 1556 | return lockAt(cat, index, lock); |
1554 | } | 1557 | } |
1555 | 1558 | ||
1556 | bool PwMDoc::lockAll(bool lock) | 1559 | bool PwMDoc::lockAll(bool lock) |
1557 | { | 1560 | { |
1558 | if (!lock && isDeepLocked()) { | 1561 | if (!lock && isDeepLocked()) { |
1559 | PwMerror ret; | 1562 | PwMerror ret; |
1560 | ret = deepLock(false); | 1563 | ret = deepLock(false); |
1561 | if (ret != e_success) | 1564 | if (ret != e_success) |
1562 | return false; | 1565 | return false; |
1563 | return true; | 1566 | return true; |
1564 | } | 1567 | } |
1565 | if (isDocEmpty()) { | 1568 | if (isDocEmpty()) { |
1566 | return true; | 1569 | return true; |
1567 | } | 1570 | } |
1568 | if (!lock && currentPw != "") { | 1571 | if (!lock && currentPw != "") { |
1569 | // unlocking and password is already set | 1572 | // unlocking and password is already set |
1570 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1573 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1571 | // unlocking without pw not allowed | 1574 | // unlocking without pw not allowed |
1572 | QString pw; | 1575 | QString pw; |
1573 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1576 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1574 | if (pw != "") { | 1577 | if (pw != "") { |
1575 | if (pw != currentPw) { | 1578 | if (pw != currentPw) { |
1576 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1579 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1577 | return false; | 1580 | return false; |
1578 | } else { | 1581 | } else { |
1579 | timer()->start(DocTimer::id_mpwTimer); | 1582 | timer()->start(DocTimer::id_mpwTimer); |
1580 | } | 1583 | } |
1581 | } else { | 1584 | } else { |
1582 | return false; | 1585 | return false; |
1583 | } | 1586 | } |
1584 | } else { | 1587 | } else { |
1585 | timer()->start(DocTimer::id_mpwTimer); | 1588 | timer()->start(DocTimer::id_mpwTimer); |
1586 | } | 1589 | } |
1587 | } | 1590 | } |
1588 | 1591 | ||
1589 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1592 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1590 | catEnd = dti.dta.end(), | 1593 | catEnd = dti.dta.end(), |
1591 | catI = catBegin; | 1594 | catI = catBegin; |
1592 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1595 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1593 | while (catI != catEnd) { | 1596 | while (catI != catEnd) { |
1594 | entrBegin = catI->d.begin(); | 1597 | entrBegin = catI->d.begin(); |
1595 | entrEnd = catI->d.end(); | 1598 | entrEnd = catI->d.end(); |
1596 | entrI = entrBegin; | 1599 | entrI = entrBegin; |
1597 | while (entrI != entrEnd) { | 1600 | while (entrI != entrEnd) { |
1598 | entrI->lockStat = lock; | 1601 | entrI->lockStat = lock; |
1599 | entrI->rev++; // increment revision counter. | 1602 | entrI->rev++; // increment revision counter. |
1600 | ++entrI; | 1603 | ++entrI; |
1601 | } | 1604 | } |
1602 | ++catI; | 1605 | ++catI; |
1603 | } | 1606 | } |
1604 | 1607 | ||
1605 | emitDataChanged(this); | 1608 | emitDataChanged(this); |
1606 | if (lock) | 1609 | if (lock) |
1607 | timer()->stop(DocTimer::id_autoLockTimer); | 1610 | timer()->stop(DocTimer::id_autoLockTimer); |
1608 | else | 1611 | else |
1609 | timer()->start(DocTimer::id_autoLockTimer); | 1612 | timer()->start(DocTimer::id_autoLockTimer); |
1610 | 1613 | ||
1611 | return true; | 1614 | return true; |
1612 | } | 1615 | } |
1613 | 1616 | ||
1614 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1617 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1615 | { | 1618 | { |
1616 | unsigned int cat = 0; | 1619 | unsigned int cat = 0; |
1617 | 1620 | ||
1618 | if (!findCategory(category, &cat)) { | 1621 | if (!findCategory(category, &cat)) { |
1619 | BUG(); | 1622 | BUG(); |
1620 | return false; | 1623 | return false; |
1621 | } | 1624 | } |
1622 | 1625 | ||
1623 | return isLocked(cat, index); | 1626 | return isLocked(cat, index); |
1624 | } | 1627 | } |
1625 | 1628 | ||
1626 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1629 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1627 | { | 1630 | { |
1628 | static vector< vector<bool> > *oldLockStates = 0; | 1631 | static vector< vector<bool> > *oldLockStates = 0; |
1629 | static bool wasDeepLocked; | 1632 | static bool wasDeepLocked; |
1630 | 1633 | ||
1631 | if (revert) {// revert the unlocking | 1634 | if (revert) {// revert the unlocking |
1632 | if (oldLockStates) { | 1635 | if (oldLockStates) { |
1633 | /* we actually _have_ unlocked something, because | 1636 | /* we actually _have_ unlocked something, because |
1634 | * we have allocated space for the oldLockStates. | 1637 | * we have allocated space for the oldLockStates. |
1635 | * So, go on and revert them! | 1638 | * So, go on and revert them! |
1636 | */ | 1639 | */ |
1637 | if (wasDeepLocked) { | 1640 | if (wasDeepLocked) { |
1638 | PwMerror ret = deepLock(true); | 1641 | PwMerror ret = deepLock(true); |
1639 | if (ret == e_success) { | 1642 | if (ret == e_success) { |
1640 | /* deep-lock succeed. We are save. | 1643 | /* deep-lock succeed. We are save. |
1641 | * (but if it failed, just go on | 1644 | * (but if it failed, just go on |
1642 | * lock them normally) | 1645 | * lock them normally) |
1643 | */ | 1646 | */ |
1644 | delete_and_null(oldLockStates); | 1647 | delete_and_null(oldLockStates); |
1645 | timer()->start(DocTimer::id_autoLockTimer); | 1648 | timer()->start(DocTimer::id_autoLockTimer); |
1646 | printDebug("tempoary unlocking of dta " | 1649 | printDebug("tempoary unlocking of dta " |
1647 | "reverted by deep-locking."); | 1650 | "reverted by deep-locking."); |
1648 | return true; | 1651 | return true; |
1649 | } | 1652 | } |
1650 | printDebug("deep-lock failed while reverting! " | 1653 | printDebug("deep-lock failed while reverting! " |
1651 | "Falling back to normal-lock."); | 1654 | "Falling back to normal-lock."); |
1652 | } | 1655 | } |
1653 | if (unlikely(!wasDeepLocked && | 1656 | if (unlikely(!wasDeepLocked && |
1654 | numCategories() != oldLockStates->size())) { | 1657 | numCategories() != oldLockStates->size())) { |
1655 | /* DOH! We have modified "dta" while | 1658 | /* DOH! We have modified "dta" while |
1656 | * it was unlocked tempoary. DON'T DO THIS! | 1659 | * it was unlocked tempoary. DON'T DO THIS! |
1657 | */ | 1660 | */ |
1658 | BUG(); | 1661 | BUG(); |
1659 | delete_and_null(oldLockStates); | 1662 | delete_and_null(oldLockStates); |
1660 | timer()->start(DocTimer::id_autoLockTimer); | 1663 | timer()->start(DocTimer::id_autoLockTimer); |
1661 | return false; | 1664 | return false; |
1662 | } | 1665 | } |
1663 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1666 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1664 | catEnd = dti.dta.end(), | 1667 | catEnd = dti.dta.end(), |
1665 | catI = catBegin; | 1668 | catI = catBegin; |
1666 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1669 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1667 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1670 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1668 | vector<bool>::iterator oldEntrStatBegin, | 1671 | vector<bool>::iterator oldEntrStatBegin, |
1669 | oldEntrStatEnd, | 1672 | oldEntrStatEnd, |
1670 | oldEntrStatI; | 1673 | oldEntrStatI; |
1671 | while (catI != catEnd) { | 1674 | while (catI != catEnd) { |
1672 | entrBegin = catI->d.begin(); | 1675 | entrBegin = catI->d.begin(); |
1673 | entrEnd = catI->d.end(); | 1676 | entrEnd = catI->d.end(); |
1674 | entrI = entrBegin; | 1677 | entrI = entrBegin; |
1675 | if (likely(!wasDeepLocked)) { | 1678 | if (likely(!wasDeepLocked)) { |
1676 | oldEntrStatBegin = oldCatStatI->begin(); | 1679 | oldEntrStatBegin = oldCatStatI->begin(); |
1677 | oldEntrStatEnd = oldCatStatI->end(); | 1680 | oldEntrStatEnd = oldCatStatI->end(); |
1678 | oldEntrStatI = oldEntrStatBegin; | 1681 | oldEntrStatI = oldEntrStatBegin; |
1679 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1682 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1680 | /* DOH! We have modified "dta" while | 1683 | /* DOH! We have modified "dta" while |
1681 | * it was unlocked tempoary. DON'T DO THIS! | 1684 | * it was unlocked tempoary. DON'T DO THIS! |
1682 | */ | 1685 | */ |
1683 | BUG(); | 1686 | BUG(); |
1684 | delete_and_null(oldLockStates); | 1687 | delete_and_null(oldLockStates); |
1685 | timer()->start(DocTimer::id_autoLockTimer); | 1688 | timer()->start(DocTimer::id_autoLockTimer); |
1686 | return false; | 1689 | return false; |
1687 | } | 1690 | } |
1688 | } | 1691 | } |
1689 | while (entrI != entrEnd) { | 1692 | while (entrI != entrEnd) { |
1690 | if (wasDeepLocked) { | 1693 | if (wasDeepLocked) { |
1691 | /* this is an error-fallback if | 1694 | /* this is an error-fallback if |
1692 | * deeplock didn't succeed | 1695 | * deeplock didn't succeed |
1693 | */ | 1696 | */ |
1694 | entrI->lockStat = true; | 1697 | entrI->lockStat = true; |
1695 | } else { | 1698 | } else { |
1696 | entrI->lockStat = *oldEntrStatI; | 1699 | entrI->lockStat = *oldEntrStatI; |
1697 | } | 1700 | } |
1698 | ++entrI; | 1701 | ++entrI; |
1699 | if (likely(!wasDeepLocked)) | 1702 | if (likely(!wasDeepLocked)) |
1700 | ++oldEntrStatI; | 1703 | ++oldEntrStatI; |
1701 | } | 1704 | } |
1702 | ++catI; | 1705 | ++catI; |
1703 | if (likely(!wasDeepLocked)) | 1706 | if (likely(!wasDeepLocked)) |
1704 | ++oldCatStatI; | 1707 | ++oldCatStatI; |
1705 | } | 1708 | } |
1706 | delete_and_null(oldLockStates); | 1709 | delete_and_null(oldLockStates); |
1707 | if (unlikely(wasDeepLocked)) { | 1710 | if (unlikely(wasDeepLocked)) { |
1708 | /* error fallback... */ | 1711 | /* error fallback... */ |
1709 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1712 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1710 | emitDataChanged(this); | 1713 | emitDataChanged(this); |
1711 | printDebug("WARNING: unlockAll_tempoary(true) " | 1714 | printDebug("WARNING: unlockAll_tempoary(true) " |
1712 | "deeplock fallback!"); | 1715 | "deeplock fallback!"); |
1713 | } | 1716 | } |
1714 | printDebug("tempoary unlocking of dta reverted."); | 1717 | printDebug("tempoary unlocking of dta reverted."); |
1715 | } else { | 1718 | } else { |
1716 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1719 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1717 | } | 1720 | } |
1718 | timer()->start(DocTimer::id_autoLockTimer); | 1721 | timer()->start(DocTimer::id_autoLockTimer); |
1719 | } else {// unlock all data tempoary | 1722 | } else {// unlock all data tempoary |
1720 | if (unlikely(oldLockStates != 0)) { | 1723 | if (unlikely(oldLockStates != 0)) { |
1721 | /* DOH! We have already unlocked the data tempoarly. | 1724 | /* DOH! We have already unlocked the data tempoarly. |
1722 | * No need to do it twice. ;) | 1725 | * No need to do it twice. ;) |
1723 | */ | 1726 | */ |
1724 | BUG(); | 1727 | BUG(); |
1725 | return false; | 1728 | return false; |
1726 | } | 1729 | } |
1727 | wasDeepLocked = false; | 1730 | wasDeepLocked = false; |
1728 | bool mustUnlock = false; | 1731 | bool mustUnlock = false; |
1729 | if (isDeepLocked()) { | 1732 | if (isDeepLocked()) { |
1730 | PwMerror ret; | 1733 | PwMerror ret; |
1731 | while (1) { | 1734 | while (1) { |
1732 | ret = deepLock(false); | 1735 | ret = deepLock(false); |
1733 | if (ret == e_success) { | 1736 | if (ret == e_success) { |
1734 | break; | 1737 | break; |
1735 | } else if (ret == e_wrongPw) { | 1738 | } else if (ret == e_wrongPw) { |
1736 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1739 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1737 | } else { | 1740 | } else { |
1738 | printDebug("deep-unlocking failed while " | 1741 | printDebug("deep-unlocking failed while " |
1739 | "tempoary unlocking!"); | 1742 | "tempoary unlocking!"); |
1740 | return false; | 1743 | return false; |
1741 | } | 1744 | } |
1742 | } | 1745 | } |
1743 | wasDeepLocked = true; | 1746 | wasDeepLocked = true; |
1744 | mustUnlock = true; | 1747 | mustUnlock = true; |
1745 | } else { | 1748 | } else { |
1746 | // first check if it's needed to unlock some entries | 1749 | // first check if it's needed to unlock some entries |
1747 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1750 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1748 | catEnd = dti.dta.end(), | 1751 | catEnd = dti.dta.end(), |
1749 | catI = catBegin; | 1752 | catI = catBegin; |
1750 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1753 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1751 | while (catI != catEnd) { | 1754 | while (catI != catEnd) { |
1752 | entrBegin = catI->d.begin(); | 1755 | entrBegin = catI->d.begin(); |
1753 | entrEnd = catI->d.end(); | 1756 | entrEnd = catI->d.end(); |
1754 | entrI = entrBegin; | 1757 | entrI = entrBegin; |
1755 | while (entrI != entrEnd) { | 1758 | while (entrI != entrEnd) { |
1756 | if (entrI->lockStat == true) { | 1759 | if (entrI->lockStat == true) { |
1757 | mustUnlock = true; | 1760 | mustUnlock = true; |
1758 | break; | 1761 | break; |
1759 | } | 1762 | } |
1760 | ++entrI; | 1763 | ++entrI; |
1761 | } | 1764 | } |
1762 | if (mustUnlock) | 1765 | if (mustUnlock) |
1763 | break; | 1766 | break; |
1764 | ++catI; | 1767 | ++catI; |
1765 | } | 1768 | } |
1766 | } | 1769 | } |
1767 | if (!mustUnlock) { | 1770 | if (!mustUnlock) { |
1768 | // nothing to do. | 1771 | // nothing to do. |
1769 | timer()->stop(DocTimer::id_autoLockTimer); | 1772 | timer()->stop(DocTimer::id_autoLockTimer); |
1770 | printDebug("unlockAll_tempoary(): nothing to do."); | 1773 | printDebug("unlockAll_tempoary(): nothing to do."); |
1771 | return true; | 1774 | return true; |
1772 | } else if (!wasDeepLocked) { | 1775 | } else if (!wasDeepLocked) { |
1773 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1776 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1774 | currentPw != "") { | 1777 | currentPw != "") { |
1775 | /* we can't unlock without mpw, so | 1778 | /* we can't unlock without mpw, so |
1776 | * we need to ask for it. | 1779 | * we need to ask for it. |
1777 | */ | 1780 | */ |
1778 | QString pw; | 1781 | QString pw; |
1779 | while (1) { | 1782 | while (1) { |
1780 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1783 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1781 | if (pw == "") { | 1784 | if (pw == "") { |
1782 | return false; | 1785 | return false; |
1783 | } else if (pw == currentPw) { | 1786 | } else if (pw == currentPw) { |
1784 | break; | 1787 | break; |
1785 | } | 1788 | } |
1786 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1789 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1787 | } | 1790 | } |
1788 | } | 1791 | } |
1789 | } | 1792 | } |
1790 | timer()->stop(DocTimer::id_autoLockTimer); | 1793 | timer()->stop(DocTimer::id_autoLockTimer); |
1791 | oldLockStates = new vector< vector<bool> >; | 1794 | oldLockStates = new vector< vector<bool> >; |
1792 | vector<bool> tmp_vec; | 1795 | vector<bool> tmp_vec; |
1793 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 1796 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
1794 | catEnd = dti.dta.end(), | 1797 | catEnd = dti.dta.end(), |
1795 | catI = catBegin; | 1798 | catI = catBegin; |
1796 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1799 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1797 | while (catI != catEnd) { | 1800 | while (catI != catEnd) { |
1798 | entrBegin = catI->d.begin(); | 1801 | entrBegin = catI->d.begin(); |
1799 | entrEnd = catI->d.end(); | 1802 | entrEnd = catI->d.end(); |
1800 | entrI = entrBegin; | 1803 | entrI = entrBegin; |
1801 | while (entrI != entrEnd) { | 1804 | while (entrI != entrEnd) { |
1802 | if (!wasDeepLocked) { | 1805 | if (!wasDeepLocked) { |
1803 | tmp_vec.push_back(entrI->lockStat); | 1806 | tmp_vec.push_back(entrI->lockStat); |
1804 | } | 1807 | } |
1805 | entrI->lockStat = false; | 1808 | entrI->lockStat = false; |
1806 | ++entrI; | 1809 | ++entrI; |
1807 | } | 1810 | } |
1808 | if (!wasDeepLocked) { | 1811 | if (!wasDeepLocked) { |
1809 | oldLockStates->push_back(tmp_vec); | 1812 | oldLockStates->push_back(tmp_vec); |
1810 | tmp_vec.clear(); | 1813 | tmp_vec.clear(); |
1811 | } | 1814 | } |
1812 | ++catI; | 1815 | ++catI; |
1813 | } | 1816 | } |
1814 | printDebug("tempoary unlocked dta."); | 1817 | printDebug("tempoary unlocked dta."); |
1815 | } | 1818 | } |
1816 | 1819 | ||
1817 | return true; | 1820 | return true; |
1818 | } | 1821 | } |
1819 | 1822 | ||
1820 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1823 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1821 | { | 1824 | { |
1822 | PwMerror ret; | 1825 | PwMerror ret; |
1823 | /* NOTE: saveDoc() depends on this function to return | 1826 | /* NOTE: saveDoc() depends on this function to return |
1824 | * e_success if saveToFile == false | 1827 | * e_success if saveToFile == false |
1825 | */ | 1828 | */ |
1826 | 1829 | ||
1827 | if (lock) { | 1830 | if (lock) { |
1828 | if (isDeepLocked()) | 1831 | if (isDeepLocked()) |
1829 | return e_lock; | 1832 | return e_lock; |
1830 | if (saveToFile) { | 1833 | if (saveToFile) { |
1831 | if (isDocEmpty()) | 1834 | if (isDocEmpty()) |
1832 | return e_docIsEmpty; | 1835 | return e_docIsEmpty; |
1833 | ret = saveDoc(conf()->confGlobCompression()); | 1836 | ret = saveDoc(conf()->confGlobCompression()); |
1834 | if (ret == e_filename) { | 1837 | if (ret == e_filename) { |
1835 | /* the doc wasn't saved to a file | 1838 | /* the doc wasn't saved to a file |
1836 | * by the user, yet. | 1839 | * by the user, yet. |
1837 | */ | 1840 | */ |
1838 | cantDeeplock_notSavedMsgBox(); | 1841 | cantDeeplock_notSavedMsgBox(); |
1839 | return e_docNotSaved; | 1842 | return e_docNotSaved; |
1840 | } else if (ret != e_success) { | 1843 | } else if (ret != e_success) { |
1841 | return e_lock; | 1844 | return e_lock; |
1842 | } | 1845 | } |
1843 | } | 1846 | } |
1844 | timer()->stop(DocTimer::id_autoLockTimer); | 1847 | timer()->stop(DocTimer::id_autoLockTimer); |
1845 | clearDoc(); | 1848 | clearDoc(); |
1846 | PwMDataItem d; | 1849 | PwMDataItem d; |
1847 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1850 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1848 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1851 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1849 | d.listViewPos = 0; | 1852 | d.listViewPos = 0; |
1850 | addEntry(DEFAULT_CATEGORY, &d, true); | 1853 | addEntry(DEFAULT_CATEGORY, &d, true); |
1851 | lockAt(DEFAULT_CATEGORY, 0, true); | 1854 | lockAt(DEFAULT_CATEGORY, 0, true); |
1852 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1855 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1853 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1856 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1854 | } else { | 1857 | } else { |
1855 | if (!isDeepLocked()) | 1858 | if (!isDeepLocked()) |
1856 | return e_lock; | 1859 | return e_lock; |
1857 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1860 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1858 | ? 0 : 1); | 1861 | ? 0 : 1); |
1859 | if (ret == e_wrongPw) { | 1862 | if (ret == e_wrongPw) { |
1860 | return e_wrongPw; | 1863 | return e_wrongPw; |
1861 | } else if (ret != e_success) { | 1864 | } else if (ret != e_success) { |
1862 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1865 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1863 | + tostr(static_cast<int>(ret))); | 1866 | + tostr(static_cast<int>(ret))); |
1864 | return e_lock; | 1867 | return e_lock; |
1865 | } | 1868 | } |
1866 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1869 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1867 | timer()->start(DocTimer::id_autoLockTimer); | 1870 | timer()->start(DocTimer::id_autoLockTimer); |
1868 | } | 1871 | } |
1869 | 1872 | ||
1870 | emitDataChanged(this); | 1873 | emitDataChanged(this); |
1871 | return e_success; | 1874 | return e_success; |
1872 | } | 1875 | } |
1873 | 1876 | ||
1874 | void PwMDoc::_deepUnlock() | 1877 | void PwMDoc::_deepUnlock() |
1875 | { | 1878 | { |
1876 | deepLock(false); | 1879 | deepLock(false); |
1877 | } | 1880 | } |
1878 | 1881 | ||
1879 | void PwMDoc::clearDoc() | 1882 | void PwMDoc::clearDoc() |
1880 | { | 1883 | { |
1881 | dti.clear(); | 1884 | dti.clear(); |
1882 | PwMCategoryItem d; | 1885 | PwMCategoryItem d; |
1886 | //US ENH: to initialize all members with meaningfull data. | ||
1887 | d.clear(); | ||
1883 | d.name = DEFAULT_CATEGORY.latin1(); | 1888 | d.name = DEFAULT_CATEGORY.latin1(); |
1884 | dti.dta.push_back(d); | 1889 | dti.dta.push_back(d); |
1885 | currentPw = ""; | 1890 | currentPw = ""; |
1886 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1891 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1887 | } | 1892 | } |
1888 | 1893 | ||
1889 | void PwMDoc::changeCurrentPw() | 1894 | void PwMDoc::changeCurrentPw() |
1890 | { | 1895 | { |
1891 | if (currentPw == "") | 1896 | if (currentPw == "") |
1892 | return; // doc hasn't been saved. No mpw available. | 1897 | return; // doc hasn't been saved. No mpw available. |
1893 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1898 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1894 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1899 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1895 | if (pw == "") | 1900 | if (pw == "") |
1896 | return; | 1901 | return; |
1897 | if (useChipcard) | 1902 | if (useChipcard) |
1898 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1903 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1899 | else | 1904 | else |
1900 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1905 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1901 | setCurrentPw(pw); | 1906 | setCurrentPw(pw); |
1902 | } | 1907 | } |
1903 | 1908 | ||
1904 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1909 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1905 | int pos) | 1910 | int pos) |
1906 | { | 1911 | { |
1907 | unsigned int cat = 0; | 1912 | unsigned int cat = 0; |
1908 | 1913 | ||
1909 | if (!findCategory(category, &cat)) { | 1914 | if (!findCategory(category, &cat)) { |
1910 | BUG(); | 1915 | BUG(); |
1911 | return; | 1916 | return; |
1912 | } | 1917 | } |
1913 | setListViewPos(cat, index, pos); | 1918 | setListViewPos(cat, index, pos); |
1914 | } | 1919 | } |
1915 | 1920 | ||
1916 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1921 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1917 | int pos) | 1922 | int pos) |
1918 | { | 1923 | { |
1919 | dti.dta[category].d[index].listViewPos = pos; | 1924 | dti.dta[category].d[index].listViewPos = pos; |
1920 | 1925 | ||
1921 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1926 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1922 | * get's called when it shouldn't. It's because PwMView assumes | 1927 | * get's called when it shouldn't. It's because PwMView assumes |
1923 | * the user resorted the UI on behalf of signal layoutChanged(). | 1928 | * the user resorted the UI on behalf of signal layoutChanged(). |
1924 | * This is somewhat broken and incorrect, but I've no other | 1929 | * This is somewhat broken and incorrect, but I've no other |
1925 | * solution for now. | 1930 | * solution for now. |
1926 | */ | 1931 | */ |
1927 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1932 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1928 | } | 1933 | } |
1929 | 1934 | ||
1930 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1935 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1931 | { | 1936 | { |
1932 | unsigned int cat = 0; | 1937 | unsigned int cat = 0; |
1933 | 1938 | ||
1934 | if (!findCategory(category, &cat)) { | 1939 | if (!findCategory(category, &cat)) { |
1935 | BUG(); | 1940 | BUG(); |
1936 | return -1; | 1941 | return -1; |
1937 | } | 1942 | } |
1938 | 1943 | ||
1939 | return dti.dta[cat].d[index].listViewPos; | 1944 | return dti.dta[cat].d[index].listViewPos; |
1940 | } | 1945 | } |
1941 | 1946 | ||
1942 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1947 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1943 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1948 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1944 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1949 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1945 | { | 1950 | { |
1946 | PWM_ASSERT(foundPositions); | 1951 | PWM_ASSERT(foundPositions); |
1947 | PWM_ASSERT(searchIn); | 1952 | PWM_ASSERT(searchIn); |
1948 | foundPositions->clear(); | 1953 | foundPositions->clear(); |
1949 | 1954 | ||
1950 | unsigned int i, entries = numEntries(category); | 1955 | unsigned int i, entries = numEntries(category); |
1951 | for (i = 0; i < entries; ++i) { | 1956 | for (i = 0; i < entries; ++i) { |
1952 | if (searchIn & SEARCH_IN_DESC) { | 1957 | if (searchIn & SEARCH_IN_DESC) { |
1953 | if (!compareString(find.desc, dti.dta[category].d[i].desc, | 1958 | if (!compareString(find.desc, dti.dta[category].d[i].desc, |
1954 | caseSensitive, exactWordMatch)) { | 1959 | caseSensitive, exactWordMatch)) { |
1955 | continue; | 1960 | continue; |
1956 | } | 1961 | } |
1957 | } | 1962 | } |
1958 | if (searchIn & SEARCH_IN_NAME) { | 1963 | if (searchIn & SEARCH_IN_NAME) { |
1959 | if (!compareString(find.name, dti.dta[category].d[i].name, | 1964 | if (!compareString(find.name, dti.dta[category].d[i].name, |
1960 | caseSensitive, exactWordMatch)) { | 1965 | caseSensitive, exactWordMatch)) { |
1961 | continue; | 1966 | continue; |
1962 | } | 1967 | } |
1963 | } | 1968 | } |
1964 | if (searchIn & SEARCH_IN_PW) { | 1969 | if (searchIn & SEARCH_IN_PW) { |
1965 | bool wasLocked = isLocked(category, i); | 1970 | bool wasLocked = isLocked(category, i); |
1966 | getDataChangedLock(); | 1971 | getDataChangedLock(); |
1967 | lockAt(category, i, false); | 1972 | lockAt(category, i, false); |
1968 | if (!compareString(find.pw, dti.dta[category].d[i].pw, | 1973 | if (!compareString(find.pw, dti.dta[category].d[i].pw, |
1969 | caseSensitive, exactWordMatch)) { | 1974 | caseSensitive, exactWordMatch)) { |
1970 | lockAt(category, i, wasLocked); | 1975 | lockAt(category, i, wasLocked); |
1971 | putDataChangedLock(); | 1976 | putDataChangedLock(); |
1972 | continue; | 1977 | continue; |
1973 | } | 1978 | } |
1974 | lockAt(category, i, wasLocked); | 1979 | lockAt(category, i, wasLocked); |
1975 | putDataChangedLock(); | 1980 | putDataChangedLock(); |
1976 | } | 1981 | } |
1977 | if (searchIn & SEARCH_IN_COMMENT) { | 1982 | if (searchIn & SEARCH_IN_COMMENT) { |
1978 | if (!compareString(find.comment, dti.dta[category].d[i].comment, | 1983 | if (!compareString(find.comment, dti.dta[category].d[i].comment, |
1979 | caseSensitive, exactWordMatch)) { | 1984 | caseSensitive, exactWordMatch)) { |
1980 | continue; | 1985 | continue; |
1981 | } | 1986 | } |
1982 | } | 1987 | } |
1983 | if (searchIn & SEARCH_IN_URL) { | 1988 | if (searchIn & SEARCH_IN_URL) { |
1984 | if (!compareString(find.url, dti.dta[category].d[i].url, | 1989 | if (!compareString(find.url, dti.dta[category].d[i].url, |
1985 | caseSensitive, exactWordMatch)) { | 1990 | caseSensitive, exactWordMatch)) { |
1986 | continue; | 1991 | continue; |
1987 | } | 1992 | } |
1988 | } | 1993 | } |
1989 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1994 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1990 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, | 1995 | if (!compareString(find.launcher, dti.dta[category].d[i].launcher, |
1991 | caseSensitive, exactWordMatch)) { | 1996 | caseSensitive, exactWordMatch)) { |
1992 | continue; | 1997 | continue; |
1993 | } | 1998 | } |
1994 | } | 1999 | } |
1995 | 2000 | ||
1996 | // all selected "searchIn" matched. | 2001 | // all selected "searchIn" matched. |
1997 | foundPositions->push_back(i); | 2002 | foundPositions->push_back(i); |
1998 | if (breakAfterFound) | 2003 | if (breakAfterFound) |
1999 | break; | 2004 | break; |
2000 | } | 2005 | } |
2001 | 2006 | ||
2002 | if (sortByLvp && foundPositions->size() > 1) { | 2007 | if (sortByLvp && foundPositions->size() > 1) { |
2003 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 2008 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
2004 | unsigned int /* lvp-pos */> > tmp_vec; | 2009 | unsigned int /* lvp-pos */> > tmp_vec; |
2005 | 2010 | ||
2006 | unsigned int i, items = foundPositions->size(); | 2011 | unsigned int i, items = foundPositions->size(); |
2007 | pair<unsigned int, unsigned int> tmp_pair; | 2012 | pair<unsigned int, unsigned int> tmp_pair; |
2008 | for (i = 0; i < items; ++i) { | 2013 | for (i = 0; i < items; ++i) { |
2009 | tmp_pair.first = (*foundPositions)[i]; | 2014 | tmp_pair.first = (*foundPositions)[i]; |
2010 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; | 2015 | tmp_pair.second = dti.dta[category].d[(*foundPositions)[i]].listViewPos; |
2011 | tmp_vec.push_back(tmp_pair); | 2016 | tmp_vec.push_back(tmp_pair); |
2012 | } | 2017 | } |
2013 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 2018 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
2014 | foundPositions->clear(); | 2019 | foundPositions->clear(); |
2015 | for (i = 0; i < items; ++i) { | 2020 | for (i = 0; i < items; ++i) { |
2016 | foundPositions->push_back(tmp_vec[i].first); | 2021 | foundPositions->push_back(tmp_vec[i].first); |
2017 | } | 2022 | } |
2018 | } | 2023 | } |
2019 | } | 2024 | } |
2020 | 2025 | ||
2021 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2026 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2022 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2027 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2023 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2028 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2024 | { | 2029 | { |
2025 | PWM_ASSERT(foundPositions); | 2030 | PWM_ASSERT(foundPositions); |
2026 | unsigned int cat = 0; | 2031 | unsigned int cat = 0; |
2027 | 2032 | ||
2028 | if (!findCategory(category, &cat)) { | 2033 | if (!findCategory(category, &cat)) { |
2029 | foundPositions->clear(); | 2034 | foundPositions->clear(); |
2030 | return; | 2035 | return; |
2031 | } | 2036 | } |
2032 | 2037 | ||
2033 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2038 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2034 | caseSensitive, exactWordMatch, sortByLvp); | 2039 | caseSensitive, exactWordMatch, sortByLvp); |
2035 | } | 2040 | } |
2036 | 2041 | ||
2037 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2042 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2038 | bool exactWordMatch) | 2043 | bool exactWordMatch) |
2039 | { | 2044 | { |
2040 | QString _s1(s1.c_str()); | 2045 | QString _s1(s1.c_str()); |
2041 | QString _s2(s2.c_str()); | 2046 | QString _s2(s2.c_str()); |
2042 | if (!caseSensitive) { | 2047 | if (!caseSensitive) { |
2043 | _s1 = _s1.lower(); | 2048 | _s1 = _s1.lower(); |
2044 | _s2 = _s2.lower(); | 2049 | _s2 = _s2.lower(); |
2045 | } | 2050 | } |
2046 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2051 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2047 | return true; | 2052 | return true; |
2048 | return false; | 2053 | return false; |
2049 | } | 2054 | } |
2050 | 2055 | ||
2051 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2056 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2052 | { | 2057 | { |
2053 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2058 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2054 | end = dti.dta.end(); | 2059 | end = dti.dta.end(); |
2055 | while (i != end) { | 2060 | while (i != end) { |
2056 | if ((*i).name == name.latin1()) { | 2061 | if ((*i).name == name.latin1()) { |
2057 | if (index) { | 2062 | if (index) { |
2058 | *index = i - dti.dta.begin(); | 2063 | *index = i - dti.dta.begin(); |
2059 | } | 2064 | } |
2060 | return true; | 2065 | return true; |
2061 | } | 2066 | } |
2062 | ++i; | 2067 | ++i; |
2063 | } | 2068 | } |
2064 | return false; | 2069 | return false; |
2065 | } | 2070 | } |
2066 | 2071 | ||
2067 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2072 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2068 | { | 2073 | { |
2069 | unsigned int cat = 0; | 2074 | unsigned int cat = 0; |
2070 | 2075 | ||
2071 | if (!findCategory(category, &cat)) | 2076 | if (!findCategory(category, &cat)) |
2072 | return false; | 2077 | return false; |
2073 | 2078 | ||
2074 | return renameCategory(cat, newName); | 2079 | return renameCategory(cat, newName); |
2075 | } | 2080 | } |
2076 | 2081 | ||
2077 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2082 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2078 | bool dontFlagDirty) | 2083 | bool dontFlagDirty) |
2079 | { | 2084 | { |
2080 | if (category > numCategories() - 1) | 2085 | if (category > numCategories() - 1) |
2081 | return false; | 2086 | return false; |
2082 | 2087 | ||
2083 | dti.dta[category].name = newName.latin1(); | 2088 | dti.dta[category].name = newName.latin1(); |
2084 | if (!dontFlagDirty) | 2089 | if (!dontFlagDirty) |
2085 | flagDirty(); | 2090 | flagDirty(); |
2086 | 2091 | ||
2087 | return true; | 2092 | return true; |
2088 | } | 2093 | } |
2089 | 2094 | ||
2090 | bool PwMDoc::delCategory(const QString &category) | 2095 | bool PwMDoc::delCategory(const QString &category) |
2091 | { | 2096 | { |
2092 | unsigned int cat = 0; | 2097 | unsigned int cat = 0; |
2093 | 2098 | ||
2094 | if (!findCategory(category, &cat)) | 2099 | if (!findCategory(category, &cat)) |
2095 | return false; | 2100 | return false; |
2096 | 2101 | ||
2097 | return delCategory(cat); | 2102 | return delCategory(cat); |
2098 | } | 2103 | } |
2099 | 2104 | ||
2100 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2105 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2101 | { | 2106 | { |
2102 | if (category > numCategories() - 1) | 2107 | if (category > numCategories() - 1) |
2103 | return false; | 2108 | return false; |
2104 | 2109 | ||
2105 | // We don't delete it, if it is the last existing | 2110 | // We don't delete it, if it is the last existing |
2106 | // category! Instead we rename it to "Default". | 2111 | // category! Instead we rename it to "Default". |
2107 | if (numCategories() > 1) { | 2112 | if (numCategories() > 1) { |
2108 | dti.dta.erase(dti.dta.begin() + category); | 2113 | dti.dta.erase(dti.dta.begin() + category); |
2109 | } else { | 2114 | } else { |
2110 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2115 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2111 | return true; | 2116 | return true; |
2112 | } | 2117 | } |
2113 | if (!dontFlagDirty) | 2118 | if (!dontFlagDirty) |
2114 | flagDirty(); | 2119 | flagDirty(); |
2115 | 2120 | ||
2116 | return true; | 2121 | return true; |
2117 | } | 2122 | } |
2118 | 2123 | ||
2119 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2124 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2120 | { | 2125 | { |
2121 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), | 2126 | vector<PwMCategoryItem>::iterator begin = dti.dta.begin(), |
2122 | end = dti.dta.end(), | 2127 | end = dti.dta.end(), |
2123 | i = begin; | 2128 | i = begin; |
2124 | while (i != end) { | 2129 | while (i != end) { |
2125 | if (i->d.empty()) { | 2130 | if (i->d.empty()) { |
2126 | delCategory(begin - i, dontFlagDirty); | 2131 | delCategory(begin - i, dontFlagDirty); |
2127 | } | 2132 | } |
2128 | ++i; | 2133 | ++i; |
2129 | } | 2134 | } |
2130 | } | 2135 | } |
2131 | 2136 | ||
2132 | void PwMDoc::getCategoryList(vector<string> *list) | 2137 | void PwMDoc::getCategoryList(vector<string> *list) |
2133 | { | 2138 | { |
2134 | PWM_ASSERT(list); | 2139 | PWM_ASSERT(list); |
2135 | list->clear(); | 2140 | list->clear(); |
2136 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2141 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2137 | end = dti.dta.end(); | 2142 | end = dti.dta.end(); |
2138 | while (i != end) { | 2143 | while (i != end) { |
2139 | list->push_back(i->name); | 2144 | list->push_back(i->name); |
2140 | ++i; | 2145 | ++i; |
2141 | } | 2146 | } |
2142 | } | 2147 | } |
2143 | 2148 | ||
2144 | void PwMDoc::getCategoryList(QStringList *list) | 2149 | void PwMDoc::getCategoryList(QStringList *list) |
2145 | { | 2150 | { |
2146 | PWM_ASSERT(list); | 2151 | PWM_ASSERT(list); |
2147 | list->clear(); | 2152 | list->clear(); |
2148 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), | 2153 | vector<PwMCategoryItem>::iterator i = dti.dta.begin(), |
2149 | end = dti.dta.end(); | 2154 | end = dti.dta.end(); |
2150 | while (i != end) { | 2155 | while (i != end) { |
2151 | #ifndef PWM_EMBEDDED | 2156 | #ifndef PWM_EMBEDDED |
2152 | list->push_back(i->name.c_str()); | 2157 | list->push_back(i->name.c_str()); |
2153 | #else | 2158 | #else |
2154 | list->append(i->name.c_str()); | 2159 | list->append(i->name.c_str()); |
2155 | #endif | 2160 | #endif |
2156 | ++i; | 2161 | ++i; |
2157 | } | 2162 | } |
2158 | } | 2163 | } |
2159 | 2164 | ||
2160 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2165 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2161 | { | 2166 | { |
2162 | PWM_ASSERT(list); | 2167 | PWM_ASSERT(list); |
2163 | unsigned int cat = 0; | 2168 | unsigned int cat = 0; |
2164 | if (!findCategory(category, &cat)) { | 2169 | if (!findCategory(category, &cat)) { |
2165 | list->clear(); | 2170 | list->clear(); |
2166 | return; | 2171 | return; |
2167 | } | 2172 | } |
2168 | getEntryList(cat, list); | 2173 | getEntryList(cat, list); |
2169 | } | 2174 | } |
2170 | 2175 | ||
2171 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2176 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2172 | { | 2177 | { |
2173 | PWM_ASSERT(list); | 2178 | PWM_ASSERT(list); |
2174 | unsigned int cat = 0; | 2179 | unsigned int cat = 0; |
2175 | if (!findCategory(category, &cat)) { | 2180 | if (!findCategory(category, &cat)) { |
2176 | list->clear(); | 2181 | list->clear(); |
2177 | return; | 2182 | return; |
2178 | } | 2183 | } |
2179 | getEntryList(cat, list); | 2184 | getEntryList(cat, list); |
2180 | } | 2185 | } |
2181 | 2186 | ||
2182 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2187 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2183 | { | 2188 | { |
2184 | PWM_ASSERT(list); | 2189 | PWM_ASSERT(list); |
2185 | list->clear(); | 2190 | list->clear(); |
2186 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2191 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2187 | end = dti.dta[category].d.end(), | 2192 | end = dti.dta[category].d.end(), |
2188 | i = begin; | 2193 | i = begin; |
2189 | while (i != end) { | 2194 | while (i != end) { |
2190 | list->push_back(i->desc); | 2195 | list->push_back(i->desc); |
2191 | ++i; | 2196 | ++i; |
2192 | } | 2197 | } |
2193 | } | 2198 | } |
2194 | 2199 | ||
2195 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2200 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2196 | { | 2201 | { |
2197 | PWM_ASSERT(list); | 2202 | PWM_ASSERT(list); |
2198 | list->clear(); | 2203 | list->clear(); |
2199 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), | 2204 | vector<PwMDataItem>::iterator begin = dti.dta[category].d.begin(), |
2200 | end = dti.dta[category].d.end(), | 2205 | end = dti.dta[category].d.end(), |
2201 | i = begin; | 2206 | i = begin; |
2202 | while (i != end) { | 2207 | while (i != end) { |
2203 | #ifndef PWM_EMBEDDED | 2208 | #ifndef PWM_EMBEDDED |
2204 | list->push_back(i->desc.c_str()); | 2209 | list->push_back(i->desc.c_str()); |
2205 | #else | 2210 | #else |
2206 | list->append(i->desc.c_str()); | 2211 | list->append(i->desc.c_str()); |
2207 | #endif | 2212 | #endif |
2208 | ++i; | 2213 | ++i; |
2209 | } | 2214 | } |
2210 | } | 2215 | } |
2211 | 2216 | ||
2212 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2217 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2213 | { | 2218 | { |
2214 | unsigned int cat = 0; | 2219 | unsigned int cat = 0; |
2215 | 2220 | ||
2216 | if (!findCategory(category, &cat)) | 2221 | if (!findCategory(category, &cat)) |
2217 | return false; | 2222 | return false; |
2218 | 2223 | ||
2219 | return execLauncher(cat, entryIndex); | 2224 | return execLauncher(cat, entryIndex); |
2220 | } | 2225 | } |
2221 | 2226 | ||
2222 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) | 2227 | bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex) |
2223 | { | 2228 | { |
2224 | #ifndef _WIN32_ | 2229 | #ifndef _WIN32_ |
2225 | if (geteuid() == 0) { | 2230 | if (geteuid() == 0) { |
2226 | rootAlertMsgBox(); | 2231 | rootAlertMsgBox(); |
2227 | return false; | 2232 | return false; |
2228 | } | 2233 | } |
2229 | #endif | 2234 | #endif |
2230 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); | 2235 | QString command(dti.dta[category].d[entryIndex].launcher.c_str()); |
2231 | bool wasLocked = isLocked(category, entryIndex); | 2236 | bool wasLocked = isLocked(category, entryIndex); |
2232 | 2237 | ||
2233 | if (command.find("$p") != -1) { | 2238 | if (command.find("$p") != -1) { |
2234 | /* the user requested the password to be included | 2239 | /* the user requested the password to be included |
2235 | * into the command. We have to ask for the password, | 2240 | * into the command. We have to ask for the password, |
2236 | * if it's locked. We do that by unlocking the entry | 2241 | * if it's locked. We do that by unlocking the entry |
2237 | */ | 2242 | */ |
2238 | if (!lockAt(category, entryIndex, false)) | 2243 | if (!lockAt(category, entryIndex, false)) |
2239 | return false; | 2244 | return false; |
2240 | } | 2245 | } |
2241 | #ifndef PWM_EMBEDDED | 2246 | #ifndef PWM_EMBEDDED |
2242 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); | 2247 | command.replace("$d", dti.dta[category].d[entryIndex].desc.c_str()); |
2243 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); | 2248 | command.replace("$n", dti.dta[category].d[entryIndex].name.c_str()); |
2244 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); | 2249 | command.replace("$p", dti.dta[category].d[entryIndex].pw.c_str()); |
2245 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); | 2250 | command.replace("$u", dti.dta[category].d[entryIndex].url.c_str()); |
2246 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); | 2251 | command.replace("$c", dti.dta[category].d[entryIndex].comment.c_str()); |
2247 | #else | 2252 | #else |
2248 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); | 2253 | command.replace(QRegExp("$d"), dti.dta[category].d[entryIndex].desc.c_str()); |
2249 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); | 2254 | command.replace(QRegExp("$n"), dti.dta[category].d[entryIndex].name.c_str()); |
2250 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); | 2255 | command.replace(QRegExp("$p"), dti.dta[category].d[entryIndex].pw.c_str()); |
2251 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); | 2256 | command.replace(QRegExp("$u"), dti.dta[category].d[entryIndex].url.c_str()); |
2252 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); | 2257 | command.replace(QRegExp("$c"), dti.dta[category].d[entryIndex].comment.c_str()); |
2253 | #endif | 2258 | #endif |
2254 | command.append(" &"); | 2259 | command.append(" &"); |
2255 | 2260 | ||
2256 | QString customXterm(conf()->confGlobXtermCommand()); | 2261 | QString customXterm(conf()->confGlobXtermCommand()); |
2257 | if (!customXterm.isEmpty()) | 2262 | if (!customXterm.isEmpty()) |
2258 | command = customXterm + " " + command; | 2263 | command = customXterm + " " + command; |
2259 | 2264 | ||
2260 | system(command.latin1()); | 2265 | system(command.latin1()); |
2261 | 2266 | ||
2262 | lockAt(category, entryIndex, wasLocked); | 2267 | lockAt(category, entryIndex, wasLocked); |
2263 | return true; | 2268 | return true; |
2264 | } | 2269 | } |
2265 | 2270 | ||
2266 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) | 2271 | bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex) |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 09923ab..ef81dfc 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -1,809 +1,823 @@ | |||
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.1 of pwmanager | 14 | * This file is originaly based on version 1.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 __PWMDOC_H | 20 | #ifndef __PWMDOC_H |
21 | #define __PWMDOC_H | 21 | #define __PWMDOC_H |
22 | #ifdef _WIN32_ | 22 | #ifdef _WIN32_ |
23 | #define ssize_t unsigned int | 23 | #define ssize_t unsigned int |
24 | #endif | 24 | #endif |
25 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 25 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
26 | 26 | ||
27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 27 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 28 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 29 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 30 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 31 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 32 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 33 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
34 | 34 | ||
35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 35 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 36 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 37 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 38 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 39 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 40 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 41 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
42 | 42 | ||
43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 43 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 44 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 45 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
46 | 46 | ||
47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 47 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 48 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
49 | 49 | ||
50 | 50 | ||
51 | #include "pwmexception.h" | 51 | #include "pwmexception.h" |
52 | #include "pwmdocui.h" | 52 | #include "pwmdocui.h" |
53 | 53 | ||
54 | #include <qobject.h> | 54 | #include <qobject.h> |
55 | #include <qtimer.h> | 55 | #include <qtimer.h> |
56 | #include <qdatetime.h> | 56 | #include <qdatetime.h> |
57 | 57 | ||
58 | #include <kprocess.h> | 58 | #include <kprocess.h> |
59 | 59 | ||
60 | #ifndef PWM_EMBEDDED | 60 | #ifndef PWM_EMBEDDED |
61 | #include "configuration.h" | 61 | #include "configuration.h" |
62 | #else | 62 | #else |
63 | #include <kapplication.h> | 63 | #include <kapplication.h> |
64 | #include <ksyncmanager.h> | 64 | #include <ksyncmanager.h> |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #include <string> | 67 | #include <string> |
68 | #include <vector> | 68 | #include <vector> |
69 | #include <utility> | 69 | #include <utility> |
70 | 70 | ||
71 | using std::vector; | 71 | using std::vector; |
72 | using std::string; | 72 | using std::string; |
73 | using std::pair; | 73 | using std::pair; |
74 | 74 | ||
75 | /* used in findEntry() function */ | 75 | /* used in findEntry() function */ |
76 | #define SEARCH_IN_DESC (1) | 76 | #define SEARCH_IN_DESC (1) |
77 | #define SEARCH_IN_NAME (1 << 1) | 77 | #define SEARCH_IN_NAME (1 << 1) |
78 | #define SEARCH_IN_PW (1 << 2) | 78 | #define SEARCH_IN_PW (1 << 2) |
79 | #define SEARCH_IN_COMMENT(1 << 3) | 79 | #define SEARCH_IN_COMMENT(1 << 3) |
80 | #define SEARCH_IN_URL (1 << 4) | 80 | #define SEARCH_IN_URL (1 << 4) |
81 | #define SEARCH_IN_LAUNCHER(1 << 5) | 81 | #define SEARCH_IN_LAUNCHER(1 << 5) |
82 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 82 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
83 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 83 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
84 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 84 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
85 | 85 | ||
86 | /** document deeplocked. Data is out for lunch to disk */ | 86 | /** document deeplocked. Data is out for lunch to disk */ |
87 | #define DOC_STAT_DEEPLOCKED (1) | 87 | #define DOC_STAT_DEEPLOCKED (1) |
88 | /** encrypted document on disk is dirty. data has to go to disk. */ | 88 | /** encrypted document on disk is dirty. data has to go to disk. */ |
89 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 89 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
90 | /** we are using a chipcard to encrypt the data */ | 90 | /** we are using a chipcard to encrypt the data */ |
91 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 91 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
92 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 92 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
93 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 93 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
94 | 94 | ||
95 | class PwMDoc; | 95 | class PwMDoc; |
96 | class PwMView; | 96 | class PwMView; |
97 | class QFile; | 97 | class QFile; |
98 | 98 | ||
99 | /* meta data for a PwMDataItem */ | 99 | /* meta data for a PwMDataItem */ |
100 | struct PwMMetaData | 100 | struct PwMMetaData |
101 | { | 101 | { |
102 | PwMMetaData() | 102 | PwMMetaData() |
103 | : updateInt (0) | 103 | : updateInt (0) |
104 | { } | 104 | { } |
105 | /** creation date of the PwMDataItem to which | 105 | /** creation date of the PwMDataItem to which |
106 | * this meta data belongs. | 106 | * this meta data belongs. |
107 | */ | 107 | */ |
108 | QDateTimecreate; | 108 | QDateTimecreate; |
109 | /** becomes valid on this date */ | 109 | /** becomes valid on this date */ |
110 | QDateTimevalid; | 110 | QDateTimevalid; |
111 | /** expire date */ | 111 | /** expire date */ |
112 | QDateTimeexpire; | 112 | QDateTimeexpire; |
113 | /** update date (last updated at this date) */ | 113 | /** update date (last updated at this date) */ |
114 | QDateTimeupdate; | 114 | QDateTimeupdate; |
115 | /** update interval (in minutes). Time since the | 115 | /** update interval (in minutes). Time since the |
116 | * last update to remind the user to update the item. | 116 | * last update to remind the user to update the item. |
117 | * 0 disables. | 117 | * 0 disables. |
118 | */ | 118 | */ |
119 | unsigned long updateInt; | 119 | unsigned long updateInt; |
120 | 120 | ||
121 | //US ENH: enhancements of the filestructure | 121 | //US ENH: enhancements of the filestructure |
122 | /* each entry gets a unique id assigned */ | 122 | /* each entry gets a unique id assigned */ |
123 | string uniqueid; | 123 | string uniqueid; |
124 | 124 | ||
125 | 125 | ||
126 | void clear() | 126 | void clear() |
127 | { | 127 | { |
128 | create = QDateTime(); | 128 | create = QDateTime(); |
129 | expire = QDateTime(); | 129 | expire = QDateTime(); |
130 | update = QDateTime(); | 130 | update = QDateTime(); |
131 | updateInt = 0; | 131 | updateInt = 0; |
132 | uniqueid = KApplication::randomString(8).latin1(); | 132 | uniqueid = KApplication::randomString(8).latin1(); |
133 | } | 133 | } |
134 | 134 | ||
135 | inline bool isValid() const | 135 | inline bool isValid() const |
136 | { | 136 | { |
137 | if (valid.isNull()) | 137 | if (valid.isNull()) |
138 | return true; | 138 | return true; |
139 | return (valid < QDateTime::currentDateTime()); | 139 | return (valid < QDateTime::currentDateTime()); |
140 | } | 140 | } |
141 | inline bool isExpired() const | 141 | inline bool isExpired() const |
142 | { | 142 | { |
143 | if (expire.isNull()) | 143 | if (expire.isNull()) |
144 | return false; | 144 | return false; |
145 | return (expire < QDateTime::currentDateTime()); | 145 | return (expire < QDateTime::currentDateTime()); |
146 | } | 146 | } |
147 | inline bool isUpdateIntOver() const | 147 | inline bool isUpdateIntOver() const |
148 | { | 148 | { |
149 | if (updateInt == 0 || | 149 | if (updateInt == 0 || |
150 | update.isNull()) | 150 | update.isNull()) |
151 | return false; | 151 | return false; |
152 | QDateTime d(update); | 152 | QDateTime d(update); |
153 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 153 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
154 | } | 154 | } |
155 | }; | 155 | }; |
156 | 156 | ||
157 | struct PwMDataItem | 157 | struct PwMDataItem |
158 | { | 158 | { |
159 | PwMDataItem() | 159 | PwMDataItem() |
160 | : lockStat (true) | 160 | : lockStat (true) |
161 | , listViewPos (-1) | 161 | , listViewPos (-1) |
162 | , binary (false) | 162 | , binary (false) |
163 | , rev (0) | 163 | , rev (0) |
164 | { } | 164 | { } |
165 | 165 | ||
166 | /** password description */ | 166 | /** password description */ |
167 | stringdesc; | 167 | stringdesc; |
168 | /** user-name */ | 168 | /** user-name */ |
169 | stringname; | 169 | stringname; |
170 | /** the password itself */ | 170 | /** the password itself */ |
171 | stringpw; | 171 | stringpw; |
172 | /** some comment */ | 172 | /** some comment */ |
173 | stringcomment; | 173 | stringcomment; |
174 | /** an URL string */ | 174 | /** an URL string */ |
175 | stringurl; | 175 | stringurl; |
176 | /** launcher. Can be executed as a system() command */ | 176 | /** launcher. Can be executed as a system() command */ |
177 | stringlauncher; | 177 | stringlauncher; |
178 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 178 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
179 | boollockStat; | 179 | boollockStat; |
180 | /** position of this item in main "list-view" | 180 | /** position of this item in main "list-view" |
181 | * If -1, the position is not yet specified and should be appended to the list | 181 | * If -1, the position is not yet specified and should be appended to the list |
182 | */ | 182 | */ |
183 | intlistViewPos; | 183 | intlistViewPos; |
184 | /** does this entry contain binary data? */ | 184 | /** does this entry contain binary data? */ |
185 | bool binary; | 185 | bool binary; |
186 | /** meta data for this data item. */ | 186 | /** meta data for this data item. */ |
187 | PwMMetaData meta; | 187 | PwMMetaData meta; |
188 | /** data revision counter. This counter can be used | 188 | /** data revision counter. This counter can be used |
189 | * to easily, efficiently determine if this data item | 189 | * to easily, efficiently determine if this data item |
190 | * has changed since some time. | 190 | * has changed since some time. |
191 | * This counter is incremented on every update. | 191 | * This counter is incremented on every update. |
192 | */ | 192 | */ |
193 | unsigned int rev; | 193 | unsigned int rev; |
194 | 194 | ||
195 | void clear(bool clearMeta = true) | 195 | void clear(bool clearMeta = true) |
196 | { | 196 | { |
197 | /* NOTE: Don't use .clear() here to be | 197 | /* NOTE: Don't use .clear() here to be |
198 | * backward compatible with gcc-2 (Debian Woody) | 198 | * backward compatible with gcc-2 (Debian Woody) |
199 | */ | 199 | */ |
200 | desc = ""; | 200 | desc = ""; |
201 | name = ""; | 201 | name = ""; |
202 | pw = ""; | 202 | pw = ""; |
203 | comment = ""; | 203 | comment = ""; |
204 | url = ""; | 204 | url = ""; |
205 | launcher = ""; | 205 | launcher = ""; |
206 | lockStat = true; | 206 | lockStat = true; |
207 | listViewPos = -1; | 207 | listViewPos = -1; |
208 | binary = false; | 208 | binary = false; |
209 | if (clearMeta) | 209 | if (clearMeta) |
210 | meta.clear(); | 210 | meta.clear(); |
211 | } | 211 | } |
212 | //US ENH: we need this operator to compare two items if we have no unique ids | 212 | //US ENH: we need this operator to compare two items if we have no unique ids |
213 | //available. Generaly this happens before the first sync | 213 | //available. Generaly this happens before the first sync |
214 | 214 | ||
215 | bool PwMDataItem::operator==( const PwMDataItem &a ) const | 215 | bool PwMDataItem::operator==( const PwMDataItem &a ) const |
216 | { | 216 | { |
217 | //qDebug("oper==%s", a.desc.c_str()); | 217 | //qDebug("oper==%s", a.desc.c_str()); |
218 | if ( desc != a.desc ) return false; | 218 | if ( desc != a.desc ) return false; |
219 | if ( name != a.name ) return false; | 219 | if ( name != a.name ) return false; |
220 | if ( pw != a.pw ) return false; | 220 | if ( pw != a.pw ) return false; |
221 | if ( comment != a.comment ) return false; | 221 | if ( comment != a.comment ) return false; |
222 | if ( url != a.url ) return false; | 222 | if ( url != a.url ) return false; |
223 | if ( launcher != a.launcher ) return false; | 223 | if ( launcher != a.launcher ) return false; |
224 | //all other field will not be checked. | 224 | //all other field will not be checked. |
225 | return true; | 225 | return true; |
226 | } | 226 | } |
227 | 227 | ||
228 | //US ENH: this sync method actually copies all values from the parameter like the =operator | 228 | //US ENH: this sync method actually copies all values from the parameter like the =operator |
229 | //does with two exceptions: listViewPos will not be changed, and the launcher only if required. | 229 | //does with two exceptions: listViewPos will not be changed, and the launcher only if required. |
230 | bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) | 230 | bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true ) |
231 | { | 231 | { |
232 | desc = a.desc; | 232 | desc = a.desc; |
233 | name = a.name; | 233 | name = a.name; |
234 | pw = a.pw; | 234 | pw = a.pw; |
235 | comment = a.comment; | 235 | comment = a.comment; |
236 | url = a.url; | 236 | url = a.url; |
237 | if (syncLauncher == true) | 237 | if (syncLauncher == true) |
238 | launcher = a.launcher; | 238 | launcher = a.launcher; |
239 | meta = a.meta; | 239 | meta = a.meta; |
240 | binary = a.binary; | 240 | binary = a.binary; |
241 | lockStat = a.lockStat; | 241 | lockStat = a.lockStat; |
242 | rev = a.rev; | 242 | rev = a.rev; |
243 | 243 | ||
244 | return true; | 244 | return true; |
245 | } | 245 | } |
246 | 246 | ||
247 | }; | 247 | }; |
248 | 248 | ||
249 | struct PwMCategoryItem | 249 | struct PwMCategoryItem |
250 | { | 250 | { |
251 | /** all PwMDataItems (all passwords) within this category */ | 251 | /** all PwMDataItems (all passwords) within this category */ |
252 | vector<PwMDataItem>d; | 252 | vector<PwMDataItem>d; |
253 | /** category name/description */ | 253 | /** category name/description */ |
254 | string name; | 254 | string name; |
255 | 255 | ||
256 | //US ENH: enhancements of the filestructure | ||
257 | /* each category stores the text for description,name and password */ | ||
258 | string desc_text; | ||
259 | string name_text; | ||
260 | string pw_text; | ||
261 | |||
256 | void clear() | 262 | void clear() |
257 | { | 263 | { |
258 | d.clear(); | 264 | d.clear(); |
259 | name = ""; | 265 | name = ""; |
266 | desc_text = "Description"; | ||
267 | name_text = "Username"; | ||
268 | pw_text = "Password"; | ||
260 | } | 269 | } |
261 | }; | 270 | }; |
262 | 271 | ||
263 | struct PwMSyncItem | 272 | struct PwMSyncItem |
264 | { | 273 | { |
265 | string syncName; | 274 | string syncName; |
266 | QDateTime lastSyncDate; | 275 | QDateTime lastSyncDate; |
267 | 276 | ||
268 | void clear() | 277 | void clear() |
269 | { | 278 | { |
270 | lastSyncDate = QDateTime(); | 279 | lastSyncDate = QDateTime(); |
271 | syncName = ""; | 280 | syncName = ""; |
272 | } | 281 | } |
273 | }; | 282 | }; |
274 | 283 | ||
275 | struct PwMItem | 284 | struct PwMItem |
276 | { | 285 | { |
277 | vector<PwMCategoryItem> dta; | 286 | vector<PwMCategoryItem> dta; |
278 | vector<PwMSyncItem> syncDta; | 287 | vector<PwMSyncItem> syncDta; |
279 | 288 | ||
280 | void clear() | 289 | void clear() |
281 | { | 290 | { |
282 | dta.clear(); | 291 | dta.clear(); |
283 | syncDta.clear(); | 292 | syncDta.clear(); |
284 | } | 293 | } |
285 | }; | 294 | }; |
286 | 295 | ||
287 | 296 | ||
288 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 297 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
289 | class dta_lvp_greater | 298 | class dta_lvp_greater |
290 | { | 299 | { |
291 | public: | 300 | public: |
292 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 301 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
293 | const pair<unsigned int, unsigned int> &d2) | 302 | const pair<unsigned int, unsigned int> &d2) |
294 | { | 303 | { |
295 | return d1.second > d2.second; | 304 | return d1.second > d2.second; |
296 | } | 305 | } |
297 | }; | 306 | }; |
298 | 307 | ||
299 | /** list of PwMDoc documents and it's IDs */ | 308 | /** list of PwMDoc documents and it's IDs */ |
300 | class PwMDocList | 309 | class PwMDocList |
301 | { | 310 | { |
302 | public: | 311 | public: |
303 | struct listItem | 312 | struct listItem |
304 | { | 313 | { |
305 | /** document filename (known as ID, here) */ | 314 | /** document filename (known as ID, here) */ |
306 | string docId; | 315 | string docId; |
307 | /** pointer to the document class */ | 316 | /** pointer to the document class */ |
308 | PwMDoc *doc; | 317 | PwMDoc *doc; |
309 | }; | 318 | }; |
310 | 319 | ||
311 | PwMDocList() {} | 320 | PwMDocList() {} |
312 | 321 | ||
313 | /** add a new item to the list */ | 322 | /** add a new item to the list */ |
314 | void add(PwMDoc *doc, const string &id); | 323 | void add(PwMDoc *doc, const string &id); |
315 | /** changes the contents of an existing item */ | 324 | /** changes the contents of an existing item */ |
316 | void edit(PwMDoc *doc, const string &newId); | 325 | void edit(PwMDoc *doc, const string &newId); |
317 | /** remove the given item */ | 326 | /** remove the given item */ |
318 | void del(PwMDoc *doc); | 327 | void del(PwMDoc *doc); |
319 | /** get the item at index */ | 328 | /** get the item at index */ |
320 | listItem getAt(int index) | 329 | listItem getAt(int index) |
321 | { return docList[index]; } | 330 | { return docList[index]; } |
322 | /** find an entry with this id */ | 331 | /** find an entry with this id */ |
323 | bool find(const string &id, listItem *ret = 0); | 332 | bool find(const string &id, listItem *ret = 0); |
324 | /** returns a copy of the list */ | 333 | /** returns a copy of the list */ |
325 | const vector<listItem>* getList() const | 334 | const vector<listItem>* getList() const |
326 | { return &docList; } | 335 | { return &docList; } |
327 | 336 | ||
328 | 337 | ||
329 | /** returns a new unique number to extend the name of | 338 | /** returns a new unique number to extend the name of |
330 | * an unnamed document. | 339 | * an unnamed document. |
331 | */ | 340 | */ |
332 | static unsigned int getNewUnnamedNumber() | 341 | static unsigned int getNewUnnamedNumber() |
333 | { return unnamedDocCnt++; } | 342 | { return unnamedDocCnt++; } |
334 | 343 | ||
335 | protected: | 344 | protected: |
336 | /* Hm, I think we shouldn't really use a "list" here, should we? | 345 | /* Hm, I think we shouldn't really use a "list" here, should we? |
337 | * So I decided to actually use a vector. | 346 | * So I decided to actually use a vector. |
338 | */ | 347 | */ |
339 | vector<listItem> docList; | 348 | vector<listItem> docList; |
340 | /** This value is used to get a new number for yet unnamed | 349 | /** This value is used to get a new number for yet unnamed |
341 | * documents. It is incremented on every request. So it's | 350 | * documents. It is incremented on every request. So it's |
342 | * theoretically possible to overflow it, but... :) | 351 | * theoretically possible to overflow it, but... :) |
343 | */ | 352 | */ |
344 | static unsigned int unnamedDocCnt; | 353 | static unsigned int unnamedDocCnt; |
345 | }; | 354 | }; |
346 | 355 | ||
347 | /** implements timers for the document */ | 356 | /** implements timers for the document */ |
348 | class DocTimer : public QObject | 357 | class DocTimer : public QObject |
349 | { | 358 | { |
350 | Q_OBJECT | 359 | Q_OBJECT |
351 | public: | 360 | public: |
352 | enum TimerIDs | 361 | enum TimerIDs |
353 | { | 362 | { |
354 | id_mpwTimer, | 363 | id_mpwTimer, |
355 | id_autoLockTimer, | 364 | id_autoLockTimer, |
356 | id_metaCheckTimer | 365 | id_metaCheckTimer |
357 | }; | 366 | }; |
358 | 367 | ||
359 | public: | 368 | public: |
360 | DocTimer(PwMDoc *_doc); | 369 | DocTimer(PwMDoc *_doc); |
361 | ~DocTimer(); | 370 | ~DocTimer(); |
362 | 371 | ||
363 | /** start the timer */ | 372 | /** start the timer */ |
364 | void start(TimerIDs timer); | 373 | void start(TimerIDs timer); |
365 | /** stop the timer */ | 374 | /** stop the timer */ |
366 | void stop(TimerIDs timer); | 375 | void stop(TimerIDs timer); |
367 | /** get the lock for a timer. | 376 | /** get the lock for a timer. |
368 | * This lock is a recursive lock. When a lock is | 377 | * This lock is a recursive lock. When a lock is |
369 | * held, the timer will be stopped and timeout is | 378 | * held, the timer will be stopped and timeout is |
370 | * guaranteed to not happen | 379 | * guaranteed to not happen |
371 | */ | 380 | */ |
372 | void getLock(TimerIDs timer); | 381 | void getLock(TimerIDs timer); |
373 | /** put a recursive timer lock */ | 382 | /** put a recursive timer lock */ |
374 | void putLock(TimerIDs timer); | 383 | void putLock(TimerIDs timer); |
375 | 384 | ||
376 | protected slots: | 385 | protected slots: |
377 | /** timeout slot for the mpw timer */ | 386 | /** timeout slot for the mpw timer */ |
378 | void mpwTimeout(); | 387 | void mpwTimeout(); |
379 | /** timeout slot for the autoLock timer */ | 388 | /** timeout slot for the autoLock timer */ |
380 | void autoLockTimeout(); | 389 | void autoLockTimeout(); |
381 | /** timeout slot for the metaCheck timer */ | 390 | /** timeout slot for the metaCheck timer */ |
382 | void metaCheckTimeout(); | 391 | void metaCheckTimeout(); |
383 | 392 | ||
384 | protected: | 393 | protected: |
385 | /** pointer to the document associated with this timer. */ | 394 | /** pointer to the document associated with this timer. */ |
386 | PwMDoc *doc; | 395 | PwMDoc *doc; |
387 | /** timer object for mpw timer */ | 396 | /** timer object for mpw timer */ |
388 | QTimer *mpwTimer; | 397 | QTimer *mpwTimer; |
389 | /** timer object for the autoLock timer */ | 398 | /** timer object for the autoLock timer */ |
390 | QTimer *autoLockTimer; | 399 | QTimer *autoLockTimer; |
391 | /** timer object for the metaCheck timer */ | 400 | /** timer object for the metaCheck timer */ |
392 | QTimer *metaCheckTimer; | 401 | QTimer *metaCheckTimer; |
393 | /** lock counter for the mpw timer */ | 402 | /** lock counter for the mpw timer */ |
394 | unsigned int mpwLock; | 403 | unsigned int mpwLock; |
395 | /** lock counter for the autoLock timer */ | 404 | /** lock counter for the autoLock timer */ |
396 | unsigned int autoLockLock; | 405 | unsigned int autoLockLock; |
397 | /** lock counter for the metaCheck timer */ | 406 | /** lock counter for the metaCheck timer */ |
398 | unsigned int metaCheckLock; | 407 | unsigned int metaCheckLock; |
399 | }; | 408 | }; |
400 | 409 | ||
401 | /** Document class for PwM */ | 410 | /** Document class for PwM */ |
402 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. | 411 | //US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. |
403 | // But PwMDoc is handling the sync by itself. | 412 | // But PwMDoc is handling the sync by itself. |
404 | class PwMDoc : public PwMDocUi, public KSyncInterface | 413 | class PwMDoc : public PwMDocUi, public KSyncInterface |
405 | 414 | ||
406 | { | 415 | { |
407 | Q_OBJECT | 416 | Q_OBJECT |
408 | friend class DocTimer; | 417 | friend class DocTimer; |
409 | 418 | ||
410 | public: | 419 | public: |
411 | /** construtor */ | 420 | /** construtor */ |
412 | PwMDoc(QObject* parent = 0, const char *name = 0); | 421 | PwMDoc(QObject* parent = 0, const char *name = 0); |
413 | /** destructor */ | 422 | /** destructor */ |
414 | ~PwMDoc(); | 423 | ~PwMDoc(); |
415 | 424 | ||
416 | /** returns a pointer to a list of all open documents */ | 425 | /** returns a pointer to a list of all open documents */ |
417 | static PwMDocList* getOpenDocList() | 426 | static PwMDocList* getOpenDocList() |
418 | { return &openDocList; } | 427 | { return &openDocList; } |
419 | 428 | ||
420 | /** flag document dirty. dta changed */ | 429 | /** flag document dirty. dta changed */ |
421 | void flagDirty() | 430 | void flagDirty() |
422 | { | 431 | { |
423 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 432 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
424 | emitDataChanged(this); | 433 | emitDataChanged(this); |
425 | } | 434 | } |
426 | /** modified? */ | 435 | /** modified? */ |
427 | bool isDirty() | 436 | bool isDirty() |
428 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 437 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
429 | /** save document to disk */ | 438 | /** save document to disk */ |
430 | PwMerror saveDoc(char compress, const QString *file = 0); | 439 | PwMerror saveDoc(char compress, const QString *file = 0); |
431 | /** read document from file. | 440 | /** read document from file. |
432 | * "openLocked is must be set to either of these values: | 441 | * "openLocked is must be set to either of these values: |
433 | * 0 == open with all entries unlocked | 442 | * 0 == open with all entries unlocked |
434 | * 1 == open with all entries locked | 443 | * 1 == open with all entries locked |
435 | * 2 == open deep-locked | 444 | * 2 == open deep-locked |
436 | */ | 445 | */ |
437 | PwMerror openDoc(const QString *file, int openLocked); | 446 | PwMerror openDoc(const QString *file, int openLocked); |
438 | /** export document to ascii-textfile */ | 447 | /** export document to ascii-textfile */ |
439 | PwMerror exportToText(const QString *file); | 448 | PwMerror exportToText(const QString *file); |
440 | /** export document to gpasman / kpasman file */ | 449 | /** export document to gpasman / kpasman file */ |
441 | PwMerror exportToGpasman(const QString *file); | 450 | PwMerror exportToGpasman(const QString *file); |
442 | /** import document from ascii-textfile */ | 451 | /** import document from ascii-textfile */ |
443 | PwMerror importFromText(const QString *file, int format = -1); | 452 | PwMerror importFromText(const QString *file, int format = -1); |
444 | /** import document from gpasman / kpasman file */ | 453 | /** import document from gpasman / kpasman file */ |
445 | PwMerror importFromGpasman(const QString *file); | 454 | PwMerror importFromGpasman(const QString *file); |
446 | /** add new entry */ | 455 | /** add new entry */ |
447 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 456 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
448 | bool dontFlagDirty = false, bool updateMeta = true); | 457 | bool dontFlagDirty = false, bool updateMeta = true); |
449 | /** add new category. This function doesn't flag the document dirty! */ | 458 | /** add new category. This function doesn't flag the document dirty! */ |
450 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 459 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
451 | bool checkIfExist = true); | 460 | bool checkIfExist = true); |
452 | /** rename an existing category */ | 461 | /** rename an existing category */ |
453 | bool renameCategory(const QString &category, const QString &newName); | 462 | bool renameCategory(const QString &category, const QString &newName); |
454 | /** rename an existing category */ | 463 | /** rename an existing category */ |
455 | bool renameCategory(unsigned int category, const QString &newName, | 464 | bool renameCategory(unsigned int category, const QString &newName, |
456 | bool dontFlagDirty = false); | 465 | bool dontFlagDirty = false); |
457 | /** delete an existing category */ | 466 | /** delete an existing category */ |
458 | bool delCategory(const QString &category); | 467 | bool delCategory(const QString &category); |
459 | /** delete an existing category */ | 468 | /** delete an existing category */ |
460 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 469 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
461 | /** returns a list of all category-names */ | 470 | /** returns a list of all category-names */ |
462 | void getCategoryList(vector<string> *list); | 471 | void getCategoryList(vector<string> *list); |
463 | /** returns a list of all category-names */ | 472 | /** returns a list of all category-names */ |
464 | void getCategoryList(QStringList *list); | 473 | void getCategoryList(QStringList *list); |
465 | /** returns a list of all entry-descs in the given category */ | 474 | /** returns a list of all entry-descs in the given category */ |
466 | void getEntryList(const QString &category, QStringList *list); | 475 | void getEntryList(const QString &category, QStringList *list); |
467 | /** returns a list of all entry-descs in the given category */ | 476 | /** returns a list of all entry-descs in the given category */ |
468 | void getEntryList(const QString &category, vector<string> *list); | 477 | void getEntryList(const QString &category, vector<string> *list); |
469 | /** returns a list of all entry-descs in the given category */ | 478 | /** returns a list of all entry-descs in the given category */ |
470 | void getEntryList(unsigned int category, vector<string> *list); | 479 | void getEntryList(unsigned int category, vector<string> *list); |
471 | /** returns a list of all entry-descs in the given category */ | 480 | /** returns a list of all entry-descs in the given category */ |
472 | void getEntryList(unsigned int category, QStringList *list); | 481 | void getEntryList(unsigned int category, QStringList *list); |
473 | /** delete entry */ | 482 | /** delete entry */ |
474 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 483 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
475 | /** delete entry */ | 484 | /** delete entry */ |
476 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 485 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
477 | /** edit entry */ | 486 | /** edit entry */ |
478 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 487 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
479 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 488 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
480 | /** edit entry */ | 489 | /** edit entry */ |
481 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 490 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
482 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 491 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
483 | /** finds the category with the "name" and return it's index */ | 492 | /** finds the category with the "name" and return it's index */ |
484 | bool findCategory(const QString &name, unsigned int *index); | 493 | bool findCategory(const QString &name, unsigned int *index); |
485 | /** search for an entry "find" and check while searching only for | 494 | /** search for an entry "find" and check while searching only for |
486 | * the data-fields specified by "searchIn". To set the "searchIn" | 495 | * the data-fields specified by "searchIn". To set the "searchIn" |
487 | * value, we may use one or more of the SEARCH_IN_* defines at | 496 | * value, we may use one or more of the SEARCH_IN_* defines at |
488 | * the top of this header-file. It returns the positions of all | 497 | * the top of this header-file. It returns the positions of all |
489 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 498 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
490 | * the function terminates after the first occurence of the entry | 499 | * the function terminates after the first occurence of the entry |
491 | * and doesn't go on searching. So foundPositions->size() is never | 500 | * and doesn't go on searching. So foundPositions->size() is never |
492 | * > 1 if breakAfterFound is true. | 501 | * > 1 if breakAfterFound is true. |
493 | */ | 502 | */ |
494 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 503 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
495 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 504 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
496 | bool caseSensitive = true, bool exactWordMatch = true, | 505 | bool caseSensitive = true, bool exactWordMatch = true, |
497 | bool sortByLvp = false); | 506 | bool sortByLvp = false); |
498 | /** see the above funtion. This function allows to set the category by name. */ | 507 | /** see the above funtion. This function allows to set the category by name. */ |
499 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 508 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
500 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 509 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
501 | bool caseSensitive = true, bool exactWordMatch = true, | 510 | bool caseSensitive = true, bool exactWordMatch = true, |
502 | bool sortByLvp = false); | 511 | bool sortByLvp = false); |
503 | /** returns number of entries */ | 512 | /** returns number of entries */ |
504 | unsigned int numEntries(const QString &category); | 513 | unsigned int numEntries(const QString &category); |
505 | unsigned int numEntries(unsigned int category) | 514 | unsigned int numEntries(unsigned int category) |
506 | { return dti.dta[category].d.size(); } | 515 | { return dti.dta[category].d.size(); } |
507 | /** returns number of categories */ | 516 | /** returns number of categories */ |
508 | unsigned int numCategories() | 517 | unsigned int numCategories() |
509 | { return dti.dta.size(); } | 518 | { return dti.dta.size(); } |
510 | /** returns the name of the category at "index" */ | 519 | /** returns the name of the category at "index" */ |
511 | const string* getCategory(unsigned int index) | 520 | const string* getCategory(unsigned int index) |
512 | { return (&(dti.dta[index].name)); } | 521 | { return (&(dti.dta[index].name)); } |
513 | 522 | ||
514 | /** returns the data of item at "index". | 523 | /** returns the data of item at "index". |
515 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 524 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
516 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 525 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
517 | * the pw. | 526 | * the pw. |
518 | */ | 527 | */ |
519 | bool getEntry(const QString &category, unsigned int index, | 528 | bool getEntry(const QString &category, unsigned int index, |
520 | PwMDataItem *d, bool unlockIfLocked = false); | 529 | PwMDataItem *d, bool unlockIfLocked = false); |
521 | bool getEntry(unsigned int category, unsigned int index, | 530 | bool getEntry(unsigned int category, unsigned int index, |
522 | PwMDataItem *d, bool unlockIfLocked = false); | 531 | PwMDataItem *d, bool unlockIfLocked = false); |
523 | /** returns the comment-string by looking at the category | 532 | /** returns the comment-string by looking at the category |
524 | * and the listViewPos | 533 | * and the listViewPos |
525 | */ | 534 | */ |
526 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 535 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
527 | string *foundComment); | 536 | string *foundComment); |
528 | /** checks if a password is already available. (currentPw) */ | 537 | /** checks if a password is already available. (currentPw) */ |
529 | bool isPwAvailable() | 538 | bool isPwAvailable() |
530 | { return (currentPw != ""); } | 539 | { return (currentPw != ""); } |
531 | /** un/lock entry at "index". If needed, ask for password. */ | 540 | /** un/lock entry at "index". If needed, ask for password. */ |
532 | bool lockAt(const QString &category, unsigned int index, | 541 | bool lockAt(const QString &category, unsigned int index, |
533 | bool lock = true); | 542 | bool lock = true); |
534 | bool lockAt(unsigned int category, unsigned int index, | 543 | bool lockAt(unsigned int category, unsigned int index, |
535 | bool lock = true); | 544 | bool lock = true); |
536 | /** returns the lock-status at "index" */ | 545 | /** returns the lock-status at "index" */ |
537 | bool isLocked(const QString &category, unsigned int index); | 546 | bool isLocked(const QString &category, unsigned int index); |
538 | bool isLocked(unsigned int category, unsigned int index) | 547 | bool isLocked(unsigned int category, unsigned int index) |
539 | { return dti.dta[category].d[index].lockStat; } | 548 | { return dti.dta[category].d[index].lockStat; } |
540 | /** returns the deeplock status */ | 549 | /** returns the deeplock status */ |
541 | bool isDeepLocked() | 550 | bool isDeepLocked() |
542 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 551 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
543 | /** (un)lock all entries */ | 552 | /** (un)lock all entries */ |
544 | bool lockAll(bool lock); | 553 | bool lockAll(bool lock); |
545 | /** unlocks all entries tempoarly. | 554 | /** unlocks all entries tempoarly. |
546 | * 1st NOTE: Be very careful with this function! :) | 555 | * 1st NOTE: Be very careful with this function! :) |
547 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 556 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
548 | * please DON'T forget to call unlockAll_Tempoary(true); | 557 | * please DON'T forget to call unlockAll_Tempoary(true); |
549 | * _before_ the user (or someone else) is able to change | 558 | * _before_ the user (or someone else) is able to change |
550 | * the document! | 559 | * the document! |
551 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 560 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
552 | * unlocked! This will cause corruption. | 561 | * unlocked! This will cause corruption. |
553 | */ | 562 | */ |
554 | bool unlockAll_tempoary(bool revert = false); | 563 | bool unlockAll_tempoary(bool revert = false); |
555 | /** deep-(un)locks the document. | 564 | /** deep-(un)locks the document. |
556 | * deep-locking writes all data to the file, deletes all data | 565 | * deep-locking writes all data to the file, deletes all data |
557 | * in memory, but doesn't close the document. | 566 | * in memory, but doesn't close the document. |
558 | * deep-locking is only available, if the user previously saved | 567 | * deep-locking is only available, if the user previously saved |
559 | * the doc to a file (with a password). | 568 | * the doc to a file (with a password). |
560 | * If "saveToFile" is false, it does NOT write the data to the file! | 569 | * If "saveToFile" is false, it does NOT write the data to the file! |
561 | */ | 570 | */ |
562 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 571 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
563 | /** is unlockable without pw? */ | 572 | /** is unlockable without pw? */ |
564 | bool unlockWoPw() | 573 | bool unlockWoPw() |
565 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 574 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
566 | /** get the "currentPassword" */ | 575 | /** get the "currentPassword" */ |
567 | const QString& getCurrentPw() | 576 | const QString& getCurrentPw() |
568 | { return currentPw; } | 577 | { return currentPw; } |
569 | /** open a window and request the user to change the mpw */ | 578 | /** open a window and request the user to change the mpw */ |
570 | void changeCurrentPw(); | 579 | void changeCurrentPw(); |
571 | /** set the "listViewPos" variable of "dta" */ | 580 | /** set the "listViewPos" variable of "dta" */ |
572 | void setListViewPos(const QString &category, unsigned int index, | 581 | void setListViewPos(const QString &category, unsigned int index, |
573 | int pos); | 582 | int pos); |
574 | /** set the "listViewPos" variable of "dta" */ | 583 | /** set the "listViewPos" variable of "dta" */ |
575 | void setListViewPos(unsigned int category, unsigned int index, | 584 | void setListViewPos(unsigned int category, unsigned int index, |
576 | int pos); | 585 | int pos); |
577 | /** get the "listViewPos" variable of "dta" */ | 586 | /** get the "listViewPos" variable of "dta" */ |
578 | int getListViewPos(const QString &category, unsigned int index); | 587 | int getListViewPos(const QString &category, unsigned int index); |
579 | /** set the maximum number of entries allowed */ | 588 | /** set the maximum number of entries allowed */ |
580 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 589 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
581 | { maxEntries = num; } | 590 | { maxEntries = num; } |
582 | /** get the maximum number of entries allowed */ | 591 | /** get the maximum number of entries allowed */ |
583 | unsigned int getMaxNumEntries() | 592 | unsigned int getMaxNumEntries() |
584 | { return maxEntries; } | 593 | { return maxEntries; } |
585 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 594 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
586 | * If there are some undefined entries, add them to the end of | 595 | * If there are some undefined entries, add them to the end of |
587 | * the listViewPos(itions). */ | 596 | * the listViewPos(itions). */ |
588 | void ensureLvp(); | 597 | void ensureLvp(); |
589 | /** execute the "launcher" of this entry */ | 598 | /** execute the "launcher" of this entry */ |
590 | bool execLauncher(const QString &category, unsigned int entryIndex); | 599 | bool execLauncher(const QString &category, unsigned int entryIndex); |
591 | /** see above */ | 600 | /** see above */ |
592 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 601 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
593 | /** open a browser with the URL-section of the given entry */ | 602 | /** open a browser with the URL-section of the given entry */ |
594 | bool goToURL(const QString &category, unsigned int entryIndex); | 603 | bool goToURL(const QString &category, unsigned int entryIndex); |
595 | /** see above */ | 604 | /** see above */ |
596 | bool goToURL(unsigned int category, unsigned int entryIndex); | 605 | bool goToURL(unsigned int category, unsigned int entryIndex); |
597 | /** returns true if there is no entry present in the document. | 606 | /** returns true if there is no entry present in the document. |
598 | * Note: The "default" Category is present everytime, so | 607 | * Note: The "default" Category is present everytime, so |
599 | * it's checked for it's entries. | 608 | * it's checked for it's entries. |
600 | */ | 609 | */ |
601 | bool isDocEmpty() | 610 | bool isDocEmpty() |
602 | { | 611 | { |
603 | if (numCategories() > 1) | 612 | if (numCategories() > 1) |
604 | return false; | 613 | return false; |
605 | if (numEntries(0)) | 614 | if (numEntries(0)) |
606 | return false; | 615 | return false; |
607 | return true; | 616 | return true; |
608 | } | 617 | } |
609 | /** returns the filename of this doc */ | 618 | /** returns the filename of this doc */ |
610 | const QString& getFilename() | 619 | const QString& getFilename() |
611 | { return filename; } | 620 | { return filename; } |
612 | /** returns the title of the doc */ | 621 | /** returns the title of the doc */ |
613 | QString getTitle(); | 622 | QString getTitle(); |
614 | /** sets the list-view-pointer hold in the doc */ | 623 | /** sets the list-view-pointer hold in the doc */ |
615 | void setListViewPointer(PwMView *_listView) | 624 | void setListViewPointer(PwMView *_listView) |
616 | { listView = _listView; } | 625 | { listView = _listView; } |
617 | /** returns the list-view-pointer */ | 626 | /** returns the list-view-pointer */ |
618 | PwMView * getListViewPointer() | 627 | PwMView * getListViewPointer() |
619 | { return listView; } | 628 | { return listView; } |
620 | /** try to delete the doc. The user may be asked to save | 629 | /** try to delete the doc. The user may be asked to save |
621 | * the data. The user may cancel the whole operation. | 630 | * the data. The user may cancel the whole operation. |
622 | * false is returned, then. | 631 | * false is returned, then. |
623 | */ | 632 | */ |
624 | bool tryDelete(); | 633 | bool tryDelete(); |
625 | /** is the doc deleted? (with tryDelete() ) */ | 634 | /** is the doc deleted? (with tryDelete() ) */ |
626 | bool isDeleted() | 635 | bool isDeleted() |
627 | { return deleted; } | 636 | { return deleted; } |
628 | /** returns the document timer object */ | 637 | /** returns the document timer object */ |
629 | DocTimer * timer() | 638 | DocTimer * timer() |
630 | { return _timer; } | 639 | { return _timer; } |
631 | /** get a lock on the dataChanged signal. | 640 | /** get a lock on the dataChanged signal. |
632 | * If someone is holding a lock, the signal is not emitted. | 641 | * If someone is holding a lock, the signal is not emitted. |
633 | */ | 642 | */ |
634 | void getDataChangedLock() | 643 | void getDataChangedLock() |
635 | { ++dataChangedLock; } | 644 | { ++dataChangedLock; } |
636 | /** put the dataChanged lock */ | 645 | /** put the dataChanged lock */ |
637 | void putDataChangedLock() | 646 | void putDataChangedLock() |
638 | { --dataChangedLock; } | 647 | { --dataChangedLock; } |
639 | /** returns the revision count of the item at cat/index */ | 648 | /** returns the revision count of the item at cat/index */ |
640 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 649 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
641 | { return dti.dta[category].d[index].rev; } | 650 | { return dti.dta[category].d[index].rev; } |
642 | /** returns a const pointer to the entries meta */ | 651 | /** returns a const pointer to the entries meta */ |
643 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 652 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
644 | { return &(dti.dta[category].d[index].meta); } | 653 | { return &(dti.dta[category].d[index].meta); } |
645 | /** is the entry at "category" "index" a binary entry? */ | 654 | /** is the entry at "category" "index" a binary entry? */ |
646 | bool isBinEntry(unsigned int category, unsigned int index) | 655 | bool isBinEntry(unsigned int category, unsigned int index) |
647 | { return dti.dta[category].d[index].binary; } | 656 | { return dti.dta[category].d[index].binary; } |
648 | 657 | ||
649 | public slots: | 658 | public slots: |
650 | /** wrapper for PwMTray */ | 659 | /** wrapper for PwMTray */ |
651 | void _deepUnlock(); | 660 | void _deepUnlock(); |
652 | 661 | ||
653 | signals: | 662 | signals: |
654 | /** the data of the document has changed and must be updated | 663 | /** the data of the document has changed and must be updated |
655 | * in all views. | 664 | * in all views. |
656 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 665 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
657 | */ | 666 | */ |
658 | void dataChanged(PwMDoc *document); | 667 | void dataChanged(PwMDoc *document); |
659 | /** the document class is going to close. This signal may be | 668 | /** the document class is going to close. This signal may be |
660 | * used to nofify all views, that the user closed the document, | 669 | * used to nofify all views, that the user closed the document, |
661 | * so the views can go down, too. | 670 | * so the views can go down, too. |
662 | */ | 671 | */ |
663 | void docClosed(PwMDoc *document); | 672 | void docClosed(PwMDoc *document); |
664 | /** somebody just opened the document */ | 673 | /** somebody just opened the document */ |
665 | void docOpened(PwMDoc *document); | 674 | void docOpened(PwMDoc *document); |
666 | /** this document object just got created */ | 675 | /** this document object just got created */ |
667 | void docCreated(PwMDoc *document); | 676 | void docCreated(PwMDoc *document); |
668 | 677 | ||
669 | public: | 678 | public: |
670 | /** emit the dataChanged signal after checking for a lock */ | 679 | /** emit the dataChanged signal after checking for a lock */ |
671 | void emitDataChanged(PwMDoc *document) | 680 | void emitDataChanged(PwMDoc *document) |
672 | { | 681 | { |
673 | if (!dataChangedLock) | 682 | if (!dataChangedLock) |
674 | emit dataChanged(document); | 683 | emit dataChanged(document); |
675 | } | 684 | } |
676 | 685 | ||
677 | protected: | 686 | protected: |
678 | /** current file for this doc */ | 687 | /** current file for this doc */ |
679 | QString filename; | 688 | QString filename; |
680 | //US ENH: we need a place where we keep the syncentries. So I invented | 689 | //US ENH: we need a place where we keep the syncentries. So I invented |
681 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem | 690 | // struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem |
682 | /** holds all data */ | 691 | /** holds all data */ |
683 | PwMItem dti; | 692 | PwMItem dti; |
684 | /** maximum number of entries */ | 693 | /** maximum number of entries */ |
685 | unsigned int maxEntries; | 694 | unsigned int maxEntries; |
686 | /** currently used password to encrypt data */ | 695 | /** currently used password to encrypt data */ |
687 | QString currentPw; | 696 | QString currentPw; |
688 | /** current global document status flags */ | 697 | /** current global document status flags */ |
689 | unsigned int curDocStat; | 698 | unsigned int curDocStat; |
690 | /** browser process for goToURL() */ | 699 | /** browser process for goToURL() */ |
691 | KProcess browserProc; | 700 | KProcess browserProc; |
692 | /** pointer to the list-view, using this document. | 701 | /** pointer to the list-view, using this document. |
693 | * As there can only be one list-view per doc, we | 702 | * As there can only be one list-view per doc, we |
694 | * don't need a list here. | 703 | * don't need a list here. |
695 | */ | 704 | */ |
696 | PwMView *listView; | 705 | PwMView *listView; |
697 | /** unnamedNum is used to store the "unnamed counter" | 706 | /** unnamedNum is used to store the "unnamed counter" |
698 | * for this document, while it's unnamed. If it's 0, | 707 | * for this document, while it's unnamed. If it's 0, |
699 | * we have to get a new unique one. | 708 | * we have to get a new unique one. |
700 | */ | 709 | */ |
701 | unsigned int unnamedNum; | 710 | unsigned int unnamedNum; |
702 | /** is this doc going to be deleted (executing in destructor context) */ | 711 | /** is this doc going to be deleted (executing in destructor context) */ |
703 | bool deleted; | 712 | bool deleted; |
704 | /** document timer */ | 713 | /** document timer */ |
705 | DocTimer *_timer; | 714 | DocTimer *_timer; |
706 | /** lock counter for the "dataChanged" signal */ | 715 | /** lock counter for the "dataChanged" signal */ |
707 | unsigned int dataChangedLock; | 716 | unsigned int dataChangedLock; |
708 | 717 | ||
709 | /** list of all open documents */ | 718 | /** list of all open documents */ |
710 | static PwMDocList openDocList; | 719 | static PwMDocList openDocList; |
711 | 720 | ||
712 | protected: | 721 | protected: |
713 | /** serialize "dta" and return it in "d". */ | 722 | /** serialize "dta" and return it in "d". */ |
714 | bool serializeDta(string *d); | 723 | bool serializeDta(string *d); |
715 | /** de-serialize "d" and overwrite "dta" */ | 724 | /** de-serialize "d" and overwrite "dta" */ |
716 | bool deSerializeDta(const string *d, bool entriesLocked); | 725 | bool deSerializeDta(const string *d, bool entriesLocked); |
717 | /** write header to file */ | 726 | /** write header to file */ |
718 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 727 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
719 | QString *pw, QFile *f); | 728 | QString *pw, QFile *f); |
720 | /** write data-hash to file */ | 729 | /** write data-hash to file */ |
721 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 730 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
722 | /** check header. Read header info and verify key-hash and filever. | 731 | /** check header. Read header info and verify key-hash and filever. |
723 | * returns length of header in "headerLength" */ | 732 | * returns length of header in "headerLength" */ |
724 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 733 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
725 | unsigned int *headerLength, char *dataHashType, | 734 | unsigned int *headerLength, char *dataHashType, |
726 | string *dataHash, QFile *f); | 735 | string *dataHash, QFile *f); |
727 | /** check the data-hash */ | 736 | /** check the data-hash */ |
728 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 737 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
729 | /** encrypt data "d" and write to "filename" */ | 738 | /** encrypt data "d" and write to "filename" */ |
730 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 739 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
731 | /** read data from file beginning at "pos", decrypt and return it */ | 740 | /** read data from file beginning at "pos", decrypt and return it */ |
732 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); | 741 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); |
733 | /** compress the data */ | 742 | /** compress the data */ |
734 | bool compressDta(string *d, char algo); | 743 | bool compressDta(string *d, char algo); |
735 | /** uncompress the data */ | 744 | /** uncompress the data */ |
736 | bool decompressDta(string *d, char algo); | 745 | bool decompressDta(string *d, char algo); |
737 | /** internal import function for a text-file generated by PwM. | 746 | /** internal import function for a text-file generated by PwM. |
738 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 747 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
739 | PwMerror importText_PwM(const QString *file); | 748 | PwMerror importText_PwM(const QString *file); |
740 | /** PwM-text-import helper function to extract the name/pw/comment out | 749 | /** PwM-text-import helper function to extract the name/pw/comment out |
741 | * of one entry-line */ | 750 | * of one entry-line */ |
742 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 751 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
743 | /** compare two strings */ | 752 | /** compare two strings */ |
744 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 753 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
745 | bool exactWordMatch); | 754 | bool exactWordMatch); |
746 | /** clears all document-data */ | 755 | /** clears all document-data */ |
747 | void clearDoc(); | 756 | void clearDoc(); |
748 | /** delete all empty categories */ | 757 | /** delete all empty categories */ |
749 | void delAllEmptyCat(bool dontFlagDirty); | 758 | void delAllEmptyCat(bool dontFlagDirty); |
750 | /** set a document status flag */ | 759 | /** set a document status flag */ |
751 | void setDocStatFlag(unsigned int statFlag) | 760 | void setDocStatFlag(unsigned int statFlag) |
752 | { curDocStat |= statFlag; } | 761 | { curDocStat |= statFlag; } |
753 | /** unset a document status flag */ | 762 | /** unset a document status flag */ |
754 | void unsetDocStatFlag(unsigned int statFlag) | 763 | void unsetDocStatFlag(unsigned int statFlag) |
755 | { curDocStat &= ~statFlag; } | 764 | { curDocStat &= ~statFlag; } |
756 | /** get a document status flag */ | 765 | /** get a document status flag */ |
757 | bool getDocStatFlag(unsigned int statFlag) const | 766 | bool getDocStatFlag(unsigned int statFlag) const |
758 | { return (curDocStat & statFlag); } | 767 | { return (curDocStat & statFlag); } |
759 | /** set the "currentPassword" */ | 768 | /** set the "currentPassword" */ |
760 | void setCurrentPw(const QString &pw) | 769 | void setCurrentPw(const QString &pw) |
761 | { | 770 | { |
762 | currentPw = pw; | 771 | currentPw = pw; |
763 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 772 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
764 | } | 773 | } |
765 | /** make a backup-copy of the given file */ | 774 | /** make a backup-copy of the given file */ |
766 | bool backupFile(const QString &filePath); | 775 | bool backupFile(const QString &filePath); |
767 | /** copy a file from src to dst */ | 776 | /** copy a file from src to dst */ |
768 | bool copyFile(const QString &src, const QString &dst); | 777 | bool copyFile(const QString &src, const QString &dst); |
769 | 778 | ||
770 | 779 | ||
771 | public: | 780 | public: |
772 | #ifdef PWM_EMBEDDED | 781 | #ifdef PWM_EMBEDDED |
773 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. | 782 | //US ENH: this is the magic function that syncronizes the local doc with the remote doc. |
774 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); | 783 | PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); |
775 | 784 | ||
776 | //takePwMDataItem returns the following values | 785 | //takePwMDataItem returns the following values |
777 | // 0 equal | 786 | // 0 equal |
778 | // 1 take local | 787 | // 1 take local |
779 | // 2 take remote | 788 | // 2 take remote |
780 | // 3 cancel | 789 | // 3 cancel |
781 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | 790 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); |
782 | 791 | ||
783 | //the following methods are the overwritten callbackmethods from the syncinterface | 792 | //the following methods are the overwritten callbackmethods from the syncinterface |
784 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 793 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
785 | virtual void removeSyncInfo( QString syncProfile); | 794 | virtual void removeSyncInfo( QString syncProfile); |
786 | 795 | ||
787 | #endif | 796 | #endif |
797 | //US ENH: helpermethods to return a whole category entry | ||
798 | /** returns a pointer to the categoryitem */ | ||
799 | PwMCategoryItem* getCategoryEntry(unsigned int index) | ||
800 | { return &(dti.dta[index]); } | ||
801 | |||
788 | private: | 802 | private: |
789 | //US ENH: helpermethods to access the sync data for a certain syncname. | 803 | //US ENH: helpermethods to access the sync data for a certain syncname. |
790 | // It returns the syncdatas index | 804 | // It returns the syncdatas index |
791 | bool findSyncData(const QString &syncname, unsigned int *index); | 805 | bool findSyncData(const QString &syncname, unsigned int *index); |
792 | 806 | ||
793 | /** add new syncdataentry */ | 807 | /** add new syncdataentry */ |
794 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 808 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
795 | 809 | ||
796 | /** returns a pointer to the syncdata */ | 810 | /** returns a pointer to the syncdata */ |
797 | PwMSyncItem* getSyncDataEntry(unsigned int index) | 811 | PwMSyncItem* getSyncDataEntry(unsigned int index) |
798 | { return &(dti.syncDta[index]); } | 812 | { return &(dti.syncDta[index]); } |
799 | 813 | ||
800 | /** delete entry */ | 814 | /** delete entry */ |
801 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 815 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
802 | 816 | ||
803 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 817 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
804 | 818 | ||
805 | QStringList getIDEntryList(); | 819 | QStringList getIDEntryList(); |
806 | 820 | ||
807 | }; | 821 | }; |
808 | 822 | ||
809 | #endif | 823 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index 5aaf66e..7733028 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,609 +1,619 @@ | |||
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 | //qDebug("PwMView::shiftToView: %s, %i", currItem.desc.c_str(), currItem.listViewPos); |
257 | tmpSorted[currItem.listViewPos] = currItem; | 257 | tmpSorted[currItem.listViewPos] = currItem; |
258 | } | 258 | } |
259 | 259 | ||
260 | // shift tempoary data to ListView. | 260 | // shift tempoary data to ListView. |
261 | tmpDisableSort(); | 261 | tmpDisableSort(); |
262 | lv->clear(); | 262 | lv->clear(); |
263 | |||
264 | //US ENH: adjust the headers of the table according the category texts | ||
265 | { | ||
266 | PwMCategoryItem* catItem = doc->getCategoryEntry(catDocIndex); | ||
267 | // qDebug("PwMView::ShiftToView CAT: %i, %s", catDocIndex, catItem->name.c_str()); | ||
268 | lv->setColumnText(COLUMN_DESC, catItem->desc_text.c_str()); | ||
269 | lv->setColumnText(COLUMN_NAME, catItem->name_text.c_str()); | ||
270 | lv->setColumnText(COLUMN_PW, catItem->pw_text.c_str()); | ||
271 | } | ||
272 | |||
263 | QCheckListItem *newItem; | 273 | QCheckListItem *newItem; |
264 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), | 274 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), |
265 | end = tmpSorted.end(); | 275 | end = tmpSorted.end(); |
266 | while (it != end) { | 276 | while (it != end) { |
267 | newItem = new ListViewItemPwM(lv); | 277 | newItem = new ListViewItemPwM(lv); |
268 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 278 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
269 | if ((*it).binary) { | 279 | if ((*it).binary) { |
270 | newItem->setText(COLUMN_NAME, ""); | 280 | newItem->setText(COLUMN_NAME, ""); |
271 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 281 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
272 | newItem->setText(COLUMN_URL, ""); | 282 | newItem->setText(COLUMN_URL, ""); |
273 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 283 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
274 | } else { | 284 | } else { |
275 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 285 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
276 | if ((*it).lockStat) { | 286 | if ((*it).lockStat) { |
277 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 287 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
278 | + " " | 288 | + " " |
279 | + i18n("To unlock click the icon on the left.")); | 289 | + i18n("To unlock click the icon on the left.")); |
280 | } else { | 290 | } else { |
281 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 291 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
282 | } | 292 | } |
283 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 293 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
284 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 294 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
285 | } | 295 | } |
286 | newItem->setOn(!((*it).lockStat)); | 296 | newItem->setOn(!((*it).lockStat)); |
287 | lv->insertItem(newItem); | 297 | lv->insertItem(newItem); |
288 | ++it; | 298 | ++it; |
289 | } | 299 | } |
290 | tmpReEnableSort(); | 300 | tmpReEnableSort(); |
291 | 301 | ||
292 | if (cY || cX) | 302 | if (cY || cX) |
293 | lv->setContentsPos(cX, cY); | 303 | lv->setContentsPos(cX, cY); |
294 | } | 304 | } |
295 | 305 | ||
296 | void PwMView::reorgLp() | 306 | void PwMView::reorgLp() |
297 | { | 307 | { |
298 | if (!lv->childCount()) | 308 | if (!lv->childCount()) |
299 | return; | 309 | return; |
300 | PWM_ASSERT(doc); | 310 | PWM_ASSERT(doc); |
301 | PWM_ASSERT(!doc->isDocEmpty()); | 311 | PWM_ASSERT(!doc->isDocEmpty()); |
302 | QListViewItem *currItem; | 312 | QListViewItem *currItem; |
303 | vector<unsigned int> foundPos; | 313 | vector<unsigned int> foundPos; |
304 | /* This searchIn _should_ be: | 314 | /* This searchIn _should_ be: |
305 | *const unsigned int searchIn = SEARCH_IN_DESC; | 315 | *const unsigned int searchIn = SEARCH_IN_DESC; |
306 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 316 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
307 | * So we need to search again, if we don't find the entry. (see below) | 317 | * So we need to search again, if we don't find the entry. (see below) |
308 | */ | 318 | */ |
309 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 319 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
310 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 320 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
311 | QString curCat(getCurrentCategory()); | 321 | QString curCat(getCurrentCategory()); |
312 | PwMDataItem findThis; | 322 | PwMDataItem findThis; |
313 | unsigned int i, cnt = lv->childCount(); | 323 | unsigned int i, cnt = lv->childCount(); |
314 | for (i = 0; i < cnt; ++i) { | 324 | for (i = 0; i < cnt; ++i) { |
315 | currItem = lv->itemAtIndex(i); | 325 | currItem = lv->itemAtIndex(i); |
316 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 326 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
317 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 327 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
318 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 328 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
319 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 329 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
320 | doc->findEntry(curCat, findThis, searchIn, | 330 | doc->findEntry(curCat, findThis, searchIn, |
321 | &foundPos, true); | 331 | &foundPos, true); |
322 | if (!foundPos.size()) { | 332 | if (!foundPos.size()) { |
323 | /* Did not find the entry. We seem to have a binary | 333 | /* Did not find the entry. We seem to have a binary |
324 | * entry here (pray for it!). So search again with | 334 | * entry here (pray for it!). So search again with |
325 | * the "correct" searchIn flags. | 335 | * the "correct" searchIn flags. |
326 | */ | 336 | */ |
327 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 337 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
328 | doc->findEntry(curCat, findThis, searchIn2, | 338 | doc->findEntry(curCat, findThis, searchIn2, |
329 | &foundPos, true); | 339 | &foundPos, true); |
330 | if (unlikely(!foundPos.size())) { | 340 | if (unlikely(!foundPos.size())) { |
331 | BUG(); | 341 | BUG(); |
332 | continue; | 342 | continue; |
333 | } | 343 | } |
334 | /* We assert that it's a binary entry, now. | 344 | /* We assert that it's a binary entry, now. |
335 | * No chance to efficiently verify it here. | 345 | * No chance to efficiently verify it here. |
336 | */ | 346 | */ |
337 | } | 347 | } |
338 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 348 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
339 | } | 349 | } |
340 | } | 350 | } |
341 | 351 | ||
342 | void PwMView::selAt(int index) | 352 | void PwMView::selAt(int index) |
343 | { | 353 | { |
344 | QListViewItem *item = lv->itemAtIndex(index); | 354 | QListViewItem *item = lv->itemAtIndex(index); |
345 | if (!item) | 355 | if (!item) |
346 | return; | 356 | return; |
347 | lv->setCurrentItem(item); | 357 | lv->setCurrentItem(item); |
348 | lv->ensureItemVisible(item); | 358 | lv->ensureItemVisible(item); |
349 | } | 359 | } |
350 | 360 | ||
351 | void PwMView::renCatButton_slot() | 361 | void PwMView::renCatButton_slot() |
352 | { | 362 | { |
353 | if (doc->isDeepLocked()) | 363 | if (doc->isDeepLocked()) |
354 | return; | 364 | return; |
355 | RenCatWnd wnd(this); | 365 | RenCatWnd wnd(this); |
356 | if (wnd.exec() == 1) { | 366 | if (wnd.exec() == 1) { |
357 | QString newName(wnd.getNewName()); | 367 | QString newName(wnd.getNewName()); |
358 | if (newName == "") | 368 | if (newName == "") |
359 | return; | 369 | return; |
360 | document()->renameCategory(getCurrentCategory(), | 370 | document()->renameCategory(getCurrentCategory(), |
361 | newName); | 371 | newName); |
362 | } | 372 | } |
363 | } | 373 | } |
364 | 374 | ||
365 | void PwMView::delCatButton_slot() | 375 | void PwMView::delCatButton_slot() |
366 | { | 376 | { |
367 | if (doc->isDeepLocked()) | 377 | if (doc->isDeepLocked()) |
368 | return; | 378 | return; |
369 | if (numCategories() <= 1) { | 379 | if (numCategories() <= 1) { |
370 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 380 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
371 | return; | 381 | return; |
372 | } | 382 | } |
373 | if (KMessageBox::questionYesNo(this, | 383 | if (KMessageBox::questionYesNo(this, |
374 | i18n("Do you really want to\n" | 384 | i18n("Do you really want to\n" |
375 | "delete the selected\n" | 385 | "delete the selected\n" |
376 | "category? All password-\n" | 386 | "category? All password-\n" |
377 | "entries will be lost in\n" | 387 | "entries will be lost in\n" |
378 | "this category!\n"), | 388 | "this category!\n"), |
379 | i18n("Delete category?")) | 389 | i18n("Delete category?")) |
380 | == KMessageBox::No) { | 390 | == KMessageBox::No) { |
381 | return; | 391 | return; |
382 | } | 392 | } |
383 | document()->delCategory(getCurrentCategory()); | 393 | document()->delCategory(getCurrentCategory()); |
384 | } | 394 | } |
385 | 395 | ||
386 | void PwMView::copyPwToClip() | 396 | void PwMView::copyPwToClip() |
387 | { | 397 | { |
388 | if (doc->isDeepLocked()) | 398 | if (doc->isDeepLocked()) |
389 | return; | 399 | return; |
390 | unsigned int curIndex = 0; | 400 | unsigned int curIndex = 0; |
391 | if (!getCurEntryIndex(&curIndex)) | 401 | if (!getCurEntryIndex(&curIndex)) |
392 | return; | 402 | return; |
393 | PwMDataItem d; | 403 | PwMDataItem d; |
394 | document()->getDataChangedLock(); | 404 | document()->getDataChangedLock(); |
395 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 405 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
396 | document()->putDataChangedLock(); | 406 | document()->putDataChangedLock(); |
397 | PwM::copyToClipboard(d.pw.c_str()); | 407 | PwM::copyToClipboard(d.pw.c_str()); |
398 | } | 408 | } |
399 | 409 | ||
400 | void PwMView::copyNameToClip() | 410 | void PwMView::copyNameToClip() |
401 | { | 411 | { |
402 | if (doc->isDeepLocked()) | 412 | if (doc->isDeepLocked()) |
403 | return; | 413 | return; |
404 | unsigned int curIndex = 0; | 414 | unsigned int curIndex = 0; |
405 | if (!getCurEntryIndex(&curIndex)) | 415 | if (!getCurEntryIndex(&curIndex)) |
406 | return; | 416 | return; |
407 | PwMDataItem d; | 417 | PwMDataItem d; |
408 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 418 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
409 | PwM::copyToClipboard(d.name.c_str()); | 419 | PwM::copyToClipboard(d.name.c_str()); |
410 | } | 420 | } |
411 | 421 | ||
412 | void PwMView::copyDescToClip() | 422 | void PwMView::copyDescToClip() |
413 | { | 423 | { |
414 | if (doc->isDeepLocked()) | 424 | if (doc->isDeepLocked()) |
415 | return; | 425 | return; |
416 | unsigned int curIndex = 0; | 426 | unsigned int curIndex = 0; |
417 | if (!getCurEntryIndex(&curIndex)) | 427 | if (!getCurEntryIndex(&curIndex)) |
418 | return; | 428 | return; |
419 | PwMDataItem d; | 429 | PwMDataItem d; |
420 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 430 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
421 | PwM::copyToClipboard(d.desc.c_str()); | 431 | PwM::copyToClipboard(d.desc.c_str()); |
422 | } | 432 | } |
423 | 433 | ||
424 | void PwMView::copyUrlToClip() | 434 | void PwMView::copyUrlToClip() |
425 | { | 435 | { |
426 | if (doc->isDeepLocked()) | 436 | if (doc->isDeepLocked()) |
427 | return; | 437 | return; |
428 | unsigned int curIndex = 0; | 438 | unsigned int curIndex = 0; |
429 | if (!getCurEntryIndex(&curIndex)) | 439 | if (!getCurEntryIndex(&curIndex)) |
430 | return; | 440 | return; |
431 | PwMDataItem d; | 441 | PwMDataItem d; |
432 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 442 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
433 | PwM::copyToClipboard(d.url.c_str()); | 443 | PwM::copyToClipboard(d.url.c_str()); |
434 | } | 444 | } |
435 | 445 | ||
436 | void PwMView::copyLauncherToClip() | 446 | void PwMView::copyLauncherToClip() |
437 | { | 447 | { |
438 | if (doc->isDeepLocked()) | 448 | if (doc->isDeepLocked()) |
439 | return; | 449 | return; |
440 | unsigned int curIndex = 0; | 450 | unsigned int curIndex = 0; |
441 | if (!getCurEntryIndex(&curIndex)) | 451 | if (!getCurEntryIndex(&curIndex)) |
442 | return; | 452 | return; |
443 | PwMDataItem d; | 453 | PwMDataItem d; |
444 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 454 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
445 | PwM::copyToClipboard(d.launcher.c_str()); | 455 | PwM::copyToClipboard(d.launcher.c_str()); |
446 | } | 456 | } |
447 | 457 | ||
448 | void PwMView::copyCommentToClip() | 458 | void PwMView::copyCommentToClip() |
449 | { | 459 | { |
450 | if (doc->isDeepLocked()) | 460 | if (doc->isDeepLocked()) |
451 | return; | 461 | return; |
452 | unsigned int curIndex = 0; | 462 | unsigned int curIndex = 0; |
453 | if (!getCurEntryIndex(&curIndex)) | 463 | if (!getCurEntryIndex(&curIndex)) |
454 | return; | 464 | return; |
455 | PwMDataItem d; | 465 | PwMDataItem d; |
456 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 466 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
457 | PwM::copyToClipboard(d.comment.c_str()); | 467 | PwM::copyToClipboard(d.comment.c_str()); |
458 | } | 468 | } |
459 | 469 | ||
460 | /************************************************************************ | 470 | /************************************************************************ |
461 | * | 471 | * |
462 | * | 472 | * |
463 | * | 473 | * |
464 | ************************************************************************/ | 474 | ************************************************************************/ |
465 | 475 | ||
466 | 476 | ||
467 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) | 477 | PwMDataItemView::PwMDataItemView( QWidget *parent, const char *name ) |
468 | : QTextBrowser( parent, name ) | 478 | : QTextBrowser( parent, name ) |
469 | 479 | ||
470 | 480 | ||
471 | { | 481 | { |
472 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); | 482 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); |
473 | setLinkUnderline( false ); | 483 | setLinkUnderline( false ); |
474 | // setVScrollBarMode( QScrollView::AlwaysOff ); | 484 | // setVScrollBarMode( QScrollView::AlwaysOff ); |
475 | //setHScrollBarMode( QScrollView::AlwaysOff ); | 485 | //setHScrollBarMode( QScrollView::AlwaysOff ); |
476 | 486 | ||
477 | //US QStyleSheet *sheet = styleSheet(); | 487 | //US QStyleSheet *sheet = styleSheet(); |
478 | //US QStyleSheetItem *link = sheet->item( "a" ); | 488 | //US QStyleSheetItem *link = sheet->item( "a" ); |
479 | //US link->setColor( KGlobalSettings::linkColor() ); | 489 | //US link->setColor( KGlobalSettings::linkColor() ); |
480 | 490 | ||
481 | } | 491 | } |
482 | 492 | ||
483 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) | 493 | void PwMDataItemView::setPwMDataItem( const PwMDataItem& a ) |
484 | 494 | ||
485 | { | 495 | { |
486 | mItem = a; | 496 | mItem = a; |
487 | // clear view | 497 | // clear view |
488 | setText( QString::null ); | 498 | setText( QString::null ); |
489 | 499 | ||
490 | 500 | ||
491 | QString dynamicPart; | 501 | QString dynamicPart; |
492 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" | 502 | QString format = "<tr><td align=\"right\"><b>%1</b></td>" |
493 | "<td align=\"left\">%2</td></tr>"; | 503 | "<td align=\"left\">%2</td></tr>"; |
494 | 504 | ||
495 | dynamicPart += format | 505 | dynamicPart += format |
496 | .arg( i18n("LastUpdate") ) | 506 | .arg( i18n("LastUpdate") ) |
497 | .arg( mItem.meta.update.toString().latin1() ); | 507 | .arg( mItem.meta.update.toString().latin1() ); |
498 | 508 | ||
499 | dynamicPart += format | 509 | dynamicPart += format |
500 | .arg( i18n("Description") ) | 510 | .arg( i18n("Description") ) |
501 | .arg( mItem.desc.c_str() ); | 511 | .arg( mItem.desc.c_str() ); |
502 | 512 | ||
503 | dynamicPart += format | 513 | dynamicPart += format |
504 | .arg( i18n("Name") ) | 514 | .arg( i18n("Name") ) |
505 | .arg( mItem.name.c_str() ); | 515 | .arg( mItem.name.c_str() ); |
506 | 516 | ||
507 | dynamicPart += format | 517 | dynamicPart += format |
508 | .arg( i18n("Password") ) | 518 | .arg( i18n("Password") ) |
509 | .arg( mItem.pw.c_str() ); | 519 | .arg( mItem.pw.c_str() ); |
510 | 520 | ||
511 | QString comment(mItem.pw.c_str()); | 521 | QString comment(mItem.pw.c_str()); |
512 | dynamicPart += format | 522 | dynamicPart += format |
513 | .arg( i18n("Comment") ) | 523 | .arg( i18n("Comment") ) |
514 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); | 524 | .arg( comment.replace( QRegExp("\n"), "<br>" ) ); |
515 | 525 | ||
516 | dynamicPart += format | 526 | dynamicPart += format |
517 | .arg( i18n("URL") ) | 527 | .arg( i18n("URL") ) |
518 | .arg( mItem.url.c_str() ); | 528 | .arg( mItem.url.c_str() ); |
519 | 529 | ||
520 | dynamicPart += format | 530 | dynamicPart += format |
521 | .arg( i18n("Launcher") ) | 531 | .arg( i18n("Launcher") ) |
522 | .arg( mItem.launcher.c_str() ); | 532 | .arg( mItem.launcher.c_str() ); |
523 | 533 | ||
524 | QString mText = "<table><td colspan=\"2\"> </td>"; | 534 | QString mText = "<table><td colspan=\"2\"> </td>"; |
525 | 535 | ||
526 | mText += dynamicPart; | 536 | mText += dynamicPart; |
527 | mText += "</table>"; | 537 | mText += "</table>"; |
528 | 538 | ||
529 | // at last display it... | 539 | // at last display it... |
530 | setText( mText ); | 540 | setText( mText ); |
531 | 541 | ||
532 | } | 542 | } |
533 | 543 | ||
534 | PwMDataItem PwMDataItemView::pwmdataitem() const | 544 | PwMDataItem PwMDataItemView::pwmdataitem() const |
535 | { | 545 | { |
536 | return mItem; | 546 | return mItem; |
537 | } | 547 | } |
538 | 548 | ||
539 | /************************************************************************ | 549 | /************************************************************************ |
540 | * | 550 | * |
541 | * | 551 | * |
542 | * | 552 | * |
543 | ************************************************************************/ | 553 | ************************************************************************/ |
544 | 554 | ||
545 | 555 | ||
546 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) | 556 | PwMDataItemChooser::PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent, const char *name ) |
547 | : KDialogBase(parent, name, true , | 557 | : KDialogBase(parent, name, true , |
548 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) | 558 | i18n("Conflict! Please choose Entry!"),Ok|User1|Close,Close, false) |
549 | { | 559 | { |
550 | findButton( Close )->setText( i18n("Cancel Sync")); | 560 | findButton( Close )->setText( i18n("Cancel Sync")); |
551 | findButton( Ok )->setText( i18n("Remote")); | 561 | findButton( Ok )->setText( i18n("Remote")); |
552 | findButton( User1 )->setText( i18n("Local")); | 562 | findButton( User1 )->setText( i18n("Local")); |
553 | QWidget* topframe = new QWidget( this ); | 563 | QWidget* topframe = new QWidget( this ); |
554 | setMainWidget( topframe ); | 564 | setMainWidget( topframe ); |
555 | QBoxLayout* bl; | 565 | QBoxLayout* bl; |
556 | if ( QApplication::desktop()->width() < 640 ) { | 566 | if ( QApplication::desktop()->width() < 640 ) { |
557 | bl = new QVBoxLayout( topframe ); | 567 | bl = new QVBoxLayout( topframe ); |
558 | } else { | 568 | } else { |
559 | bl = new QHBoxLayout( topframe ); | 569 | bl = new QHBoxLayout( topframe ); |
560 | } | 570 | } |
561 | QVBox* subframe = new QVBox( topframe ); | 571 | QVBox* subframe = new QVBox( topframe ); |
562 | bl->addWidget(subframe ); | 572 | bl->addWidget(subframe ); |
563 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); | 573 | QLabel* lab = new QLabel( i18n("Local Entry"), subframe ); |
564 | if ( takeloc ) | 574 | if ( takeloc ) |
565 | lab->setBackgroundColor(Qt::green.light() ); | 575 | lab->setBackgroundColor(Qt::green.light() ); |
566 | PwMDataItemView * av = new PwMDataItemView( subframe ); | 576 | PwMDataItemView * av = new PwMDataItemView( subframe ); |
567 | av->setPwMDataItem( loc ); | 577 | av->setPwMDataItem( loc ); |
568 | subframe = new QVBox( topframe ); | 578 | subframe = new QVBox( topframe ); |
569 | bl->addWidget(subframe ); | 579 | bl->addWidget(subframe ); |
570 | lab = new QLabel( i18n("Remote Entry"), subframe ); | 580 | lab = new QLabel( i18n("Remote Entry"), subframe ); |
571 | if ( !takeloc ) | 581 | if ( !takeloc ) |
572 | lab->setBackgroundColor(Qt::green.light() ); | 582 | lab->setBackgroundColor(Qt::green.light() ); |
573 | av = new PwMDataItemView( subframe ); | 583 | av = new PwMDataItemView( subframe ); |
574 | av->setPwMDataItem( rem ); | 584 | av->setPwMDataItem( rem ); |
575 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); | 585 | QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); |
576 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); | 586 | QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); |
577 | #ifndef DESKTOP_VERSION | 587 | #ifndef DESKTOP_VERSION |
578 | showMaximized(); | 588 | showMaximized(); |
579 | #else | 589 | #else |
580 | resize ( 640, 400 ); | 590 | resize ( 640, 400 ); |
581 | #endif | 591 | #endif |
582 | } | 592 | } |
583 | 593 | ||
584 | int PwMDataItemChooser::executeD( bool local ) | 594 | int PwMDataItemChooser::executeD( bool local ) |
585 | { | 595 | { |
586 | mSyncResult = 3; | 596 | mSyncResult = 3; |
587 | if ( local ) | 597 | if ( local ) |
588 | findButton( User1 )->setFocus(); | 598 | findButton( User1 )->setFocus(); |
589 | else | 599 | else |
590 | findButton( Ok )->setFocus(); | 600 | findButton( Ok )->setFocus(); |
591 | exec(); | 601 | exec(); |
592 | return mSyncResult; | 602 | return mSyncResult; |
593 | } | 603 | } |
594 | void PwMDataItemChooser::slot_remote() | 604 | void PwMDataItemChooser::slot_remote() |
595 | { | 605 | { |
596 | mSyncResult = 2; | 606 | mSyncResult = 2; |
597 | accept(); | 607 | accept(); |
598 | } | 608 | } |
599 | void PwMDataItemChooser::slot_local() | 609 | void PwMDataItemChooser::slot_local() |
600 | { | 610 | { |
601 | mSyncResult = 1; | 611 | mSyncResult = 1; |
602 | accept(); | 612 | accept(); |
603 | } | 613 | } |
604 | 614 | ||
605 | 615 | ||
606 | 616 | ||
607 | #ifndef PWM_EMBEDDED | 617 | #ifndef PWM_EMBEDDED |
608 | #include "pwmview.moc" | 618 | #include "pwmview.moc" |
609 | #endif | 619 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index 5753c1d..507fa30 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,792 +1,834 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 1.1 of pwmanager | 15 | * This file is originaly based on version 1.1 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "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_DEBUG0 | 30 | #define SERIALIZER_DEBUG0 |
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 and sync information |
43 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
44 | #define SYNC_ROOT "s" | 44 | #define SYNC_ROOT "s" |
45 | #define SYNC_TARGET_PREFIX "t" | 45 | #define SYNC_TARGET_PREFIX "t" |
46 | #define SYNC_TARGET_NAME "n" | 46 | #define SYNC_TARGET_NAME "n" |
47 | 47 | ||
48 | 48 | ||
49 | /* This is compatibility stuff. | 49 | /* This is compatibility stuff. |
50 | * The names of the entries have changed and here are the | 50 | * The names of the entries have changed and here are the |
51 | * new and old ones | 51 | * new and old ones |
52 | */ | 52 | */ |
53 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 53 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
54 | #define VER_STR_OLD "ver" | 54 | #define VER_STR_OLD "ver" |
55 | #define COMPAT_VER_OLD "0x02" | 55 | #define COMPAT_VER_OLD "0x02" |
56 | #define CAT_ROOT_OLD "categories" | 56 | #define CAT_ROOT_OLD "categories" |
57 | #define CAT_PREFIX_OLD "cat_" | 57 | #define CAT_PREFIX_OLD "cat_" |
58 | #define CAT_NAME_OLD "name" | 58 | #define CAT_NAME_OLD "name" |
59 | //US ENH : optional text for categories | ||
60 | #define CAT_TEXT_OLD "text" | ||
61 | |||
59 | #define ENTRY_PREFIX_OLD"entry_" | 62 | #define ENTRY_PREFIX_OLD"entry_" |
60 | #define ENTRY_DESC_OLD "desc" | 63 | #define ENTRY_DESC_OLD "desc" |
61 | #define ENTRY_NAME_OLD "name" | 64 | #define ENTRY_NAME_OLD "name" |
62 | #define ENTRY_PW_OLD "pw" | 65 | #define ENTRY_PW_OLD "pw" |
63 | #define ENTRY_COMMENT_OLD"comment" | 66 | #define ENTRY_COMMENT_OLD"comment" |
64 | #define ENTRY_URL_OLD "url" | 67 | #define ENTRY_URL_OLD "url" |
65 | #define ENTRY_LAUNCHER_OLD"launcher" | 68 | #define ENTRY_LAUNCHER_OLD"launcher" |
66 | #define ENTRY_LVP_OLD "listViewPos" | 69 | #define ENTRY_LVP_OLD "listViewPos" |
67 | #define ENTRY_BIN_OLD "b" | 70 | #define ENTRY_BIN_OLD "b" |
68 | #define ENTRY_META_OLD "m" | 71 | #define ENTRY_META_OLD "m" |
69 | 72 | ||
70 | #define ROOT_MAGIC_NEW "P" | 73 | #define ROOT_MAGIC_NEW "P" |
71 | #define VER_STR_NEW "v" | 74 | #define VER_STR_NEW "v" |
72 | #define COMPAT_VER_NEW "2" | 75 | #define COMPAT_VER_NEW "2" |
73 | #define CAT_ROOT_NEW "c" | 76 | #define CAT_ROOT_NEW "c" |
74 | #define CAT_PREFIX_NEW "c" | 77 | #define CAT_PREFIX_NEW "c" |
75 | #define CAT_NAME_NEW "n" | 78 | #define CAT_NAME_NEW "n" |
79 | //US ENH : optional text for categories | ||
80 | #define CAT_TEXT_NEW "t" | ||
81 | |||
76 | #define ENTRY_PREFIX_NEW"e" | 82 | #define ENTRY_PREFIX_NEW"e" |
77 | #define ENTRY_DESC_NEW "d" | 83 | #define ENTRY_DESC_NEW "d" |
78 | #define ENTRY_NAME_NEW "n" | 84 | #define ENTRY_NAME_NEW "n" |
79 | #define ENTRY_PW_NEW "p" | 85 | #define ENTRY_PW_NEW "p" |
80 | #define ENTRY_COMMENT_NEW"c" | 86 | #define ENTRY_COMMENT_NEW"c" |
81 | #define ENTRY_URL_NEW "u" | 87 | #define ENTRY_URL_NEW "u" |
82 | #define ENTRY_LAUNCHER_NEW"l" | 88 | #define ENTRY_LAUNCHER_NEW"l" |
83 | #define ENTRY_LVP_NEW "v" | 89 | #define ENTRY_LVP_NEW "v" |
84 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 90 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
85 | #define ENTRY_META_NEW ENTRY_META_OLD | 91 | #define ENTRY_META_NEW ENTRY_META_OLD |
86 | 92 | ||
87 | #if USE_OLD_TAGS != 0 | 93 | #if USE_OLD_TAGS != 0 |
88 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 94 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
89 | # define VER_STR_WR VER_STR_OLD | 95 | # define VER_STR_WR VER_STR_OLD |
90 | # define COMPAT_VER_WR COMPAT_VER_OLD | 96 | # define COMPAT_VER_WR COMPAT_VER_OLD |
91 | # define CAT_ROOT_WR CAT_ROOT_OLD | 97 | # define CAT_ROOT_WR CAT_ROOT_OLD |
92 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 98 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
93 | # define CAT_NAME_WR CAT_NAME_OLD | 99 | # define CAT_NAME_WR CAT_NAME_OLD |
100 | |||
101 | //US ENH : optional text for categories | ||
102 | # define CAT_TEXT_WR CAT_TEXT_OLD | ||
103 | |||
94 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 104 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
95 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 105 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
96 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 106 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
97 | # define ENTRY_PW_WR ENTRY_PW_OLD | 107 | # define ENTRY_PW_WR ENTRY_PW_OLD |
98 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 108 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
99 | # define ENTRY_URL_WR ENTRY_URL_OLD | 109 | # define ENTRY_URL_WR ENTRY_URL_OLD |
100 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 110 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
101 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 111 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
102 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 112 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
103 | # define ENTRY_META_WR ENTRY_META_OLD | 113 | # define ENTRY_META_WR ENTRY_META_OLD |
104 | #else | 114 | #else |
105 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 115 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
106 | # define VER_STR_WR VER_STR_NEW | 116 | # define VER_STR_WR VER_STR_NEW |
107 | # define COMPAT_VER_WR COMPAT_VER_NEW | 117 | # define COMPAT_VER_WR COMPAT_VER_NEW |
108 | # define CAT_ROOT_WR CAT_ROOT_NEW | 118 | # define CAT_ROOT_WR CAT_ROOT_NEW |
109 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 119 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
110 | # define CAT_NAME_WR CAT_NAME_NEW | 120 | # define CAT_NAME_WR CAT_NAME_NEW |
121 | |||
122 | //US ENH : optional text for categories | ||
123 | # define CAT_TEXT_WR CAT_TEXT_NEW | ||
124 | |||
111 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 125 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
112 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 126 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
113 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 127 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
114 | # define ENTRY_PW_WR ENTRY_PW_NEW | 128 | # define ENTRY_PW_WR ENTRY_PW_NEW |
115 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 129 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
116 | # define ENTRY_URL_WR ENTRY_URL_NEW | 130 | # define ENTRY_URL_WR ENTRY_URL_NEW |
117 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 131 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
118 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 132 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
119 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 133 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
120 | # define ENTRY_META_WR ENTRY_META_NEW | 134 | # define ENTRY_META_WR ENTRY_META_NEW |
121 | #endif | 135 | #endif |
122 | 136 | ||
123 | 137 | ||
124 | Serializer::Serializer() | 138 | Serializer::Serializer() |
125 | { | 139 | { |
126 | defaultLockStat = true; | 140 | defaultLockStat = true; |
127 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 141 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
128 | #ifndef PWM_EMBEDDED | 142 | #ifndef PWM_EMBEDDED |
129 | domDoc = new QDomDocument; | 143 | domDoc = new QDomDocument; |
130 | #else | 144 | #else |
131 | domDoc = new QDomDocument("mydoc"); | 145 | domDoc = new QDomDocument("mydoc"); |
132 | #endif | 146 | #endif |
133 | } | 147 | } |
134 | 148 | ||
135 | Serializer::Serializer(const QCString &buffer) | 149 | Serializer::Serializer(const QCString &buffer) |
136 | { | 150 | { |
137 | defaultLockStat = true; | 151 | defaultLockStat = true; |
138 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing | 152 | //US BUG: I needed to specify a document name. Otherwise impl will not be created for serializing |
139 | #ifndef PWM_EMBEDDED | 153 | #ifndef PWM_EMBEDDED |
140 | domDoc = new QDomDocument; | 154 | domDoc = new QDomDocument; |
141 | #else | 155 | #else |
142 | domDoc = new QDomDocument("mydoc"); | 156 | domDoc = new QDomDocument("mydoc"); |
143 | #endif | 157 | #endif |
144 | 158 | ||
145 | if (!parseXml(buffer)) { | 159 | if (!parseXml(buffer)) { |
146 | delete domDoc; | 160 | delete domDoc; |
147 | #ifndef PWM_EMBEDDED | 161 | #ifndef PWM_EMBEDDED |
148 | throw PwMException(PwMException::EX_PARSE); | 162 | throw PwMException(PwMException::EX_PARSE); |
149 | #else | 163 | #else |
150 | qDebug("Serializer::Serializer : Parse Exception "); | 164 | qDebug("Serializer::Serializer : Parse Exception "); |
151 | #endif | 165 | #endif |
152 | } | 166 | } |
153 | } | 167 | } |
154 | 168 | ||
155 | Serializer::~Serializer() | 169 | Serializer::~Serializer() |
156 | { | 170 | { |
157 | delete_ifnot_null(domDoc); | 171 | delete_ifnot_null(domDoc); |
158 | } | 172 | } |
159 | 173 | ||
160 | void Serializer::clear() | 174 | void Serializer::clear() |
161 | { | 175 | { |
162 | delete_ifnot_null(domDoc); | 176 | delete_ifnot_null(domDoc); |
163 | domDoc = new QDomDocument; | 177 | domDoc = new QDomDocument; |
164 | } | 178 | } |
165 | 179 | ||
166 | bool Serializer::parseXml(const QCString &buffer) | 180 | bool Serializer::parseXml(const QCString &buffer) |
167 | { | 181 | { |
168 | //abort(); | 182 | //abort(); |
169 | //qDebug("parse %s ", buffer.data()); | 183 | //qDebug("parse %s ", buffer.data()); |
170 | PWM_ASSERT(domDoc); | 184 | PWM_ASSERT(domDoc); |
171 | #ifndef PWM_EMBEDDED | 185 | #ifndef PWM_EMBEDDED |
172 | if (!domDoc->setContent(buffer, true)) | 186 | if (!domDoc->setContent(buffer, true)) |
173 | return false; | 187 | return false; |
174 | #else | 188 | #else |
175 | #ifdef DESKTOP_VERSION | 189 | #ifdef DESKTOP_VERSION |
176 | if (!domDoc->setContent(buffer, true)) | 190 | if (!domDoc->setContent(buffer, true)) |
177 | #else | 191 | #else |
178 | if (!domDoc->setContent(buffer)) | 192 | if (!domDoc->setContent(buffer)) |
179 | #endif | 193 | #endif |
180 | return false; | 194 | return false; |
181 | #endif | 195 | #endif |
182 | if (!checkValid()) | 196 | if (!checkValid()) |
183 | return false; | 197 | return false; |
184 | return true; | 198 | return true; |
185 | } | 199 | } |
186 | 200 | ||
187 | QCString Serializer::getXml() | 201 | QCString Serializer::getXml() |
188 | { | 202 | { |
189 | PWM_ASSERT(domDoc); | 203 | PWM_ASSERT(domDoc); |
190 | 204 | ||
191 | #ifndef PWM_EMBEDDED | 205 | #ifndef PWM_EMBEDDED |
192 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 206 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
193 | QCString tmp(domDoc->toCString(8)); | 207 | QCString tmp(domDoc->toCString(8)); |
194 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 208 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
195 | cout << tmp << endl; | 209 | cout << tmp << endl; |
196 | printDebug("<END Serializer::getXml() dump>"); | 210 | printDebug("<END Serializer::getXml() dump>"); |
197 | #endif // DEBUG | 211 | #endif // DEBUG |
198 | 212 | ||
199 | QCString ret(domDoc->toCString(0)); | 213 | QCString ret(domDoc->toCString(0)); |
200 | ret.replace('\n', ""); | 214 | ret.replace('\n', ""); |
201 | return ret; | 215 | return ret; |
202 | #else | 216 | #else |
203 | 217 | ||
204 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 218 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
205 | QCString tmp(" " + domDoc->toCString()); | 219 | QCString tmp(" " + domDoc->toCString()); |
206 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 220 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
207 | qDebug(tmp); | 221 | qDebug(tmp); |
208 | cout << tmp << endl; | 222 | cout << tmp << endl; |
209 | printDebug("<END Serializer::getXml() dump>"); | 223 | printDebug("<END Serializer::getXml() dump>"); |
210 | #endif // DEBUG | 224 | #endif // DEBUG |
211 | 225 | ||
212 | QCString ret(domDoc->toCString()); | 226 | QCString ret(domDoc->toCString()); |
213 | ret.replace(QRegExp("\n"), ""); | 227 | ret.replace(QRegExp("\n"), ""); |
214 | return ret; | 228 | return ret; |
215 | 229 | ||
216 | #endif | 230 | #endif |
217 | } | 231 | } |
218 | 232 | ||
219 | bool Serializer::serialize(PwMItem &dta) | 233 | bool Serializer::serialize(PwMItem &dta) |
220 | { | 234 | { |
221 | PWM_ASSERT(domDoc); | 235 | PWM_ASSERT(domDoc); |
222 | QDomElement root(genNewRoot()); | 236 | QDomElement root(genNewRoot()); |
223 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 237 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
224 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); | 238 | QDomElement syncNode(domDoc->createElement(SYNC_ROOT)); |
225 | if (!addSyncData(&syncNode, dta.syncDta)) | 239 | if (!addSyncData(&syncNode, dta.syncDta)) |
226 | return false; | 240 | return false; |
227 | root.appendChild(syncNode); | 241 | root.appendChild(syncNode); |
228 | if (!addCategories(&catNode, dta.dta)) | 242 | if (!addCategories(&catNode, dta.dta)) |
229 | return false; | 243 | return false; |
230 | root.appendChild(catNode); | 244 | root.appendChild(catNode); |
231 | return true; | 245 | return true; |
232 | } | 246 | } |
233 | 247 | ||
234 | bool Serializer::deSerialize(PwMItem *dta) | 248 | bool Serializer::deSerialize(PwMItem *dta) |
235 | { | 249 | { |
236 | PWM_ASSERT(domDoc); | 250 | PWM_ASSERT(domDoc); |
237 | PWM_ASSERT(dta); | 251 | PWM_ASSERT(dta); |
238 | QDomElement root(domDoc->documentElement()); | 252 | QDomElement root(domDoc->documentElement()); |
239 | QDomNode n; | 253 | QDomNode n; |
240 | 254 | ||
241 | dta->clear(); | 255 | dta->clear(); |
242 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 256 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
243 | // find <categories> ... </categories> | 257 | // find <categories> ... </categories> |
244 | // <c> ... </c> | 258 | // <c> ... </c> |
245 | if (n.nodeName() == CAT_ROOT_NEW || | 259 | if (n.nodeName() == CAT_ROOT_NEW || |
246 | n.nodeName() == CAT_ROOT_OLD) { | 260 | n.nodeName() == CAT_ROOT_OLD) { |
247 | if (!readCategories(n, &(dta->dta))) { | 261 | if (!readCategories(n, &(dta->dta))) { |
248 | return false; | 262 | return false; |
249 | } | 263 | } |
250 | continue; | 264 | continue; |
251 | } | 265 | } |
252 | else if (n.nodeName() == SYNC_ROOT) { | 266 | else if (n.nodeName() == SYNC_ROOT) { |
253 | if (!readSyncData(n, &(dta->syncDta))) { | 267 | if (!readSyncData(n, &(dta->syncDta))) { |
254 | return false; | 268 | return false; |
255 | } | 269 | } |
256 | continue; | 270 | continue; |
257 | } | 271 | } |
258 | 272 | ||
259 | /* NOTE: We can stop processing here, as we | 273 | /* NOTE: We can stop processing here, as we |
260 | * don't have more nodes in root, yet. | 274 | * don't have more nodes in root, yet. |
261 | */ | 275 | */ |
262 | return false; | 276 | return false; |
263 | 277 | ||
264 | } | 278 | } |
265 | return true; | 279 | return true; |
266 | } | 280 | } |
267 | 281 | ||
268 | bool Serializer::readCategories(const QDomNode &n, | 282 | bool Serializer::readCategories(const QDomNode &n, |
269 | vector<PwMCategoryItem> *dta) | 283 | vector<PwMCategoryItem> *dta) |
270 | { | 284 | { |
271 | QDomNodeList nl(n.childNodes()); | 285 | QDomNodeList nl(n.childNodes()); |
272 | QDomNode cur; | 286 | QDomNode cur; |
273 | QString name; | 287 | QString name; |
288 | QString text; | ||
274 | unsigned int numCat = nl.count(), i; | 289 | unsigned int numCat = nl.count(), i; |
275 | PwMCategoryItem curCat; | 290 | PwMCategoryItem curCat; |
276 | vector<PwMDataItem> curEntr; | 291 | vector<PwMDataItem> curEntr; |
277 | 292 | ||
278 | if (!numCat) { | 293 | if (!numCat) { |
279 | printDebug("Serializer::readCategories(): empty"); | 294 | printDebug("Serializer::readCategories(): empty"); |
280 | return false; | 295 | return false; |
281 | } | 296 | } |
282 | for (i = 0; i < numCat; ++i) { | 297 | for (i = 0; i < numCat; ++i) { |
283 | cur = nl.item(i); | 298 | cur = nl.item(i); |
284 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 299 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
285 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 300 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
286 | name = cur.toElement().attribute(CAT_NAME_NEW); | 301 | name = cur.toElement().attribute(CAT_NAME_NEW); |
287 | if (name == QString::null) | 302 | if (name == QString::null) |
288 | name = cur.toElement().attribute(CAT_NAME_OLD); | 303 | name = cur.toElement().attribute(CAT_NAME_OLD); |
289 | PWM_ASSERT(name != QString::null); | 304 | PWM_ASSERT(name != QString::null); |
290 | PWM_ASSERT(name != ""); | 305 | PWM_ASSERT(name != ""); |
291 | curCat.clear(); | 306 | curCat.clear(); |
292 | curCat.name = name.latin1(); | 307 | curCat.name = name.latin1(); |
308 | |||
309 | //US ENH: new version might include text for description, name and pw | ||
310 | text = cur.toElement().attribute(CAT_TEXT_NEW); | ||
311 | if (text == QString::null) | ||
312 | text = cur.toElement().attribute(CAT_TEXT_OLD); | ||
313 | if (text != QString::null) | ||
314 | { | ||
315 | QStringList textlist = QStringList::split(";", text, true); | ||
316 | unsigned int num = textlist.count(); | ||
317 | if (num > 0) | ||
318 | curCat.desc_text = textlist[0].latin1(); | ||
319 | if (num > 1) | ||
320 | curCat.name_text = textlist[1].latin1(); | ||
321 | if (num > 2) | ||
322 | curCat.pw_text = textlist[2].latin1(); | ||
323 | } | ||
324 | |||
293 | if (!readEntries(cur, &curEntr)) { | 325 | if (!readEntries(cur, &curEntr)) { |
294 | dta->clear(); | 326 | dta->clear(); |
295 | return false; | 327 | return false; |
296 | } | 328 | } |
297 | curCat.d = curEntr; | 329 | curCat.d = curEntr; |
298 | dta->push_back(curCat); | 330 | dta->push_back(curCat); |
299 | } else { | 331 | } else { |
300 | printDebug("Serializer::readCategories(): uh? not a category?"); | 332 | printDebug("Serializer::readCategories(): uh? not a category?"); |
301 | } | 333 | } |
302 | } | 334 | } |
303 | return true; | 335 | return true; |
304 | } | 336 | } |
305 | 337 | ||
306 | bool Serializer::readEntries(const QDomNode &n, | 338 | bool Serializer::readEntries(const QDomNode &n, |
307 | vector<PwMDataItem> *dta) | 339 | vector<PwMDataItem> *dta) |
308 | { | 340 | { |
309 | QDomNodeList nl(n.childNodes()); | 341 | QDomNodeList nl(n.childNodes()); |
310 | QDomNode cur; | 342 | QDomNode cur; |
311 | unsigned int numEntr = nl.count(), i; | 343 | unsigned int numEntr = nl.count(), i; |
312 | PwMDataItem curEntr; | 344 | PwMDataItem curEntr; |
313 | //US BUG: to initialize all values of curEntr with meaningfulldata, | 345 | //US BUG: to initialize all values of curEntr with meaningfulldata, |
314 | // we call clear on it. Reason: Information in the file we will read might be incomplete. | 346 | // we call clear on it. Reason: Information in the file we will read might be incomplete. |
315 | // e.g. the metadata is missing. | 347 | // e.g. the metadata is missing. |
316 | curEntr.clear(true); | 348 | curEntr.clear(true); |
317 | 349 | ||
318 | dta->clear(); | 350 | dta->clear(); |
319 | for (i = 0; i < numEntr; ++i) { | 351 | for (i = 0; i < numEntr; ++i) { |
320 | cur = nl.item(i); | 352 | cur = nl.item(i); |
321 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 353 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
322 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 354 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
323 | if (!extractEntry(cur, &curEntr)) { | 355 | if (!extractEntry(cur, &curEntr)) { |
324 | return false; | 356 | return false; |
325 | } | 357 | } |
326 | dta->push_back(curEntr); | 358 | dta->push_back(curEntr); |
327 | } else { | 359 | } else { |
328 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 360 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
329 | } | 361 | } |
330 | } | 362 | } |
331 | return true; | 363 | return true; |
332 | } | 364 | } |
333 | 365 | ||
334 | bool Serializer::extractEntry(const QDomNode &n, | 366 | bool Serializer::extractEntry(const QDomNode &n, |
335 | PwMDataItem *dta) | 367 | PwMDataItem *dta) |
336 | { | 368 | { |
337 | QDomNodeList nl(n.childNodes()); | 369 | QDomNodeList nl(n.childNodes()); |
338 | QDomNode cur, cdata; | 370 | QDomNode cur, cdata; |
339 | unsigned int cnt = nl.count(), i; | 371 | unsigned int cnt = nl.count(), i; |
340 | QString name, text; | 372 | QString name, text; |
341 | 373 | ||
342 | if (!cnt) { | 374 | if (!cnt) { |
343 | printDebug("Serializer::extractEntry(): empty"); | 375 | printDebug("Serializer::extractEntry(): empty"); |
344 | return false; | 376 | return false; |
345 | } | 377 | } |
346 | dta->clear(); | 378 | dta->clear(); |
347 | for (i = 0; i < cnt; ++i) { | 379 | for (i = 0; i < cnt; ++i) { |
348 | cur = nl.item(i); | 380 | cur = nl.item(i); |
349 | name = cur.nodeName(); | 381 | name = cur.nodeName(); |
350 | cdata = cur.firstChild(); | 382 | cdata = cur.firstChild(); |
351 | if (unlikely(cdata.isCDATASection())) { | 383 | if (unlikely(cdata.isCDATASection())) { |
352 | text = cdata.toCDATASection().data(); | 384 | text = cdata.toCDATASection().data(); |
353 | } else if (likely(cur.isElement())) { | 385 | } else if (likely(cur.isElement())) { |
354 | text = cur.toElement().text(); | 386 | text = cur.toElement().text(); |
355 | } else { | 387 | } else { |
356 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 388 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
357 | return false; | 389 | return false; |
358 | } | 390 | } |
359 | if (text == " ") | 391 | if (text == " ") |
360 | text = ""; // for backward compatibility. | 392 | text = ""; // for backward compatibility. |
361 | //qDebug("entry %s ",unescapeEntryData(text).latin1()); | 393 | //qDebug("entry %s ",unescapeEntryData(text).latin1()); |
362 | if (name == ENTRY_DESC_NEW || | 394 | if (name == ENTRY_DESC_NEW || |
363 | name == ENTRY_DESC_OLD) { | 395 | name == ENTRY_DESC_OLD) { |
364 | dta->desc = unescapeEntryData(text).latin1(); | 396 | dta->desc = unescapeEntryData(text).latin1(); |
365 | } else if (name == ENTRY_NAME_NEW || | 397 | } else if (name == ENTRY_NAME_NEW || |
366 | name == ENTRY_NAME_OLD) { | 398 | name == ENTRY_NAME_OLD) { |
367 | dta->name = unescapeEntryData(text).latin1(); | 399 | dta->name = unescapeEntryData(text).latin1(); |
368 | } else if (name == ENTRY_PW_NEW || | 400 | } else if (name == ENTRY_PW_NEW || |
369 | name == ENTRY_PW_OLD) { | 401 | name == ENTRY_PW_OLD) { |
370 | dta->pw = unescapeEntryData(text).latin1(); | 402 | dta->pw = unescapeEntryData(text).latin1(); |
371 | } else if (name == ENTRY_COMMENT_NEW || | 403 | } else if (name == ENTRY_COMMENT_NEW || |
372 | name == ENTRY_COMMENT_OLD) { | 404 | name == ENTRY_COMMENT_OLD) { |
373 | dta->comment = unescapeEntryData(text).latin1(); | 405 | dta->comment = unescapeEntryData(text).latin1(); |
374 | } else if (name == ENTRY_URL_NEW || | 406 | } else if (name == ENTRY_URL_NEW || |
375 | name == ENTRY_URL_OLD) { | 407 | name == ENTRY_URL_OLD) { |
376 | dta->url = unescapeEntryData(text).latin1(); | 408 | dta->url = unescapeEntryData(text).latin1(); |
377 | } else if (name == ENTRY_LAUNCHER_NEW || | 409 | } else if (name == ENTRY_LAUNCHER_NEW || |
378 | name == ENTRY_LAUNCHER_OLD) { | 410 | name == ENTRY_LAUNCHER_OLD) { |
379 | dta->launcher = unescapeEntryData(text).latin1(); | 411 | dta->launcher = unescapeEntryData(text).latin1(); |
380 | } else if (name == ENTRY_LVP_NEW || | 412 | } else if (name == ENTRY_LVP_NEW || |
381 | name == ENTRY_LVP_OLD) { | 413 | name == ENTRY_LVP_OLD) { |
382 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 414 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
383 | } else if (name == ENTRY_BIN_NEW) { | 415 | } else if (name == ENTRY_BIN_NEW) { |
384 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 416 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
385 | if (text == "0") { | 417 | if (text == "0") { |
386 | dta->binary = false; | 418 | dta->binary = false; |
387 | } else { | 419 | } else { |
388 | dta->binary = true; | 420 | dta->binary = true; |
389 | } | 421 | } |
390 | } else if (name == ENTRY_META_NEW) { | 422 | } else if (name == ENTRY_META_NEW) { |
391 | // ENTRY_META_NEW == ENTRY_META_OLD | 423 | // ENTRY_META_NEW == ENTRY_META_OLD |
392 | if (!extractMeta(cur, &dta->meta)) | 424 | if (!extractMeta(cur, &dta->meta)) |
393 | return false; | 425 | return false; |
394 | } else { | 426 | } else { |
395 | printDebug(string("Serializer::extractEntry(): invalid: ") | 427 | printDebug(string("Serializer::extractEntry(): invalid: ") |
396 | + name.latin1()); | 428 | + name.latin1()); |
397 | } | 429 | } |
398 | } | 430 | } |
399 | dta->lockStat = defaultLockStat; | 431 | dta->lockStat = defaultLockStat; |
400 | return true; | 432 | return true; |
401 | } | 433 | } |
402 | 434 | ||
403 | bool Serializer::extractMeta(const QDomNode &n, | 435 | bool Serializer::extractMeta(const QDomNode &n, |
404 | PwMMetaData *dta) | 436 | PwMMetaData *dta) |
405 | { | 437 | { |
406 | QDomNode cur(n.firstChild()); | 438 | QDomNode cur(n.firstChild()); |
407 | QString name, val; | 439 | QString name, val; |
408 | while (!cur.isNull()) { | 440 | while (!cur.isNull()) { |
409 | name = cur.nodeName(); | 441 | name = cur.nodeName(); |
410 | val = cur.toElement().text(); | 442 | val = cur.toElement().text(); |
411 | if (val == "") { | 443 | if (val == "") { |
412 | cur = cur.nextSibling(); | 444 | cur = cur.nextSibling(); |
413 | continue; | 445 | continue; |
414 | } | 446 | } |
415 | 447 | ||
416 | //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. | 448 | //US BUG: The transformation of an empty date into an ISO date and back is different on different systems/compilers. |
417 | //because of that it is possible that here some values are not set, which means they are null. | 449 | //because of that it is possible that here some values are not set, which means they are null. |
418 | //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates. | 450 | //US ENH: at the same moment we need backwardcompatibility. So older versions might have stored invalid dates. |
419 | 451 | ||
420 | QDateTime dtval; //dtval should be invalid by definition. | 452 | QDateTime dtval; //dtval should be invalid by definition. |
421 | 453 | ||
422 | if ((name == META_CREATE_DATE) || | 454 | if ((name == META_CREATE_DATE) || |
423 | (name == META_VALID_DATE) || | 455 | (name == META_VALID_DATE) || |
424 | (name == META_EXPIRE_DATE) || | 456 | (name == META_EXPIRE_DATE) || |
425 | (name == META_UPDATE_DATE)) | 457 | (name == META_UPDATE_DATE)) |
426 | { | 458 | { |
427 | //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); | 459 | //qDebug("Serializer::extractMeta:: val:%s, empty:%i, length:%i",val.utf8(), val.isEmpty(), val.length()); |
428 | 460 | ||
429 | #ifndef PWM_EMBEDDED | 461 | #ifndef PWM_EMBEDDED |
430 | dtval = QDateTime::fromString(val, Qt::ISODate); | 462 | dtval = QDateTime::fromString(val, Qt::ISODate); |
431 | #else | 463 | #else |
432 | bool ok; | 464 | bool ok; |
433 | dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 465 | dtval = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
434 | 466 | ||
435 | if (ok == false) | 467 | if (ok == false) |
436 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 468 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
437 | #endif | 469 | #endif |
438 | 470 | ||
439 | //if the parsed data is wrong, dtval should be invalid at this time. | 471 | //if the parsed data is wrong, dtval should be invalid at this time. |
440 | 472 | ||
441 | } | 473 | } |
442 | 474 | ||
443 | if (name == META_CREATE_DATE) { | 475 | if (name == META_CREATE_DATE) { |
444 | dta->create = dtval; | 476 | dta->create = dtval; |
445 | } else if (name == META_VALID_DATE) { | 477 | } else if (name == META_VALID_DATE) { |
446 | dta->valid = dtval; | 478 | dta->valid = dtval; |
447 | } else if (name == META_EXPIRE_DATE) { | 479 | } else if (name == META_EXPIRE_DATE) { |
448 | dta->expire = dtval; | 480 | dta->expire = dtval; |
449 | } else if (name == META_UPDATE_DATE) { | 481 | } else if (name == META_UPDATE_DATE) { |
450 | dta->update = dtval; | 482 | dta->update = dtval; |
451 | } else if (name == META_UPDATE_INT) { | 483 | } else if (name == META_UPDATE_INT) { |
452 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 484 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
453 | } else if (name == META_UNIQUEID) { | 485 | } else if (name == META_UNIQUEID) { |
454 | dta->uniqueid = unescapeEntryData(val).latin1(); | 486 | dta->uniqueid = unescapeEntryData(val).latin1(); |
455 | } else { | 487 | } else { |
456 | printDebug(string("extractMeta(): invalid: ") | 488 | printDebug(string("extractMeta(): invalid: ") |
457 | + name.latin1()); | 489 | + name.latin1()); |
458 | } | 490 | } |
459 | 491 | ||
460 | cur = cur.nextSibling(); | 492 | cur = cur.nextSibling(); |
461 | } | 493 | } |
462 | return true; | 494 | return true; |
463 | } | 495 | } |
464 | 496 | ||
465 | bool Serializer::checkValid() | 497 | bool Serializer::checkValid() |
466 | { | 498 | { |
467 | PWM_ASSERT(domDoc); | 499 | PWM_ASSERT(domDoc); |
468 | QDomElement root(domDoc->documentElement()); | 500 | QDomElement root(domDoc->documentElement()); |
469 | if (root.nodeName() != ROOT_MAGIC_NEW && | 501 | if (root.nodeName() != ROOT_MAGIC_NEW && |
470 | root.nodeName() != ROOT_MAGIC_OLD) { | 502 | root.nodeName() != ROOT_MAGIC_OLD) { |
471 | printDebug("Serializer: wrong magic"); | 503 | printDebug("Serializer: wrong magic"); |
472 | return false; | 504 | return false; |
473 | } | 505 | } |
474 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 506 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
475 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 507 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
476 | printDebug("Serializer: wrong version"); | 508 | printDebug("Serializer: wrong version"); |
477 | return false; | 509 | return false; |
478 | } | 510 | } |
479 | return true; | 511 | return true; |
480 | } | 512 | } |
481 | 513 | ||
482 | QDomElement Serializer::genNewRoot() | 514 | QDomElement Serializer::genNewRoot() |
483 | { | 515 | { |
484 | PWM_ASSERT(domDoc); | 516 | PWM_ASSERT(domDoc); |
485 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 517 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
486 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 518 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
487 | domDoc->appendChild(root); | 519 | domDoc->appendChild(root); |
488 | return root; | 520 | return root; |
489 | } | 521 | } |
490 | 522 | ||
491 | bool Serializer::addCategories(QDomElement *e, | 523 | bool Serializer::addCategories(QDomElement *e, |
492 | const vector<PwMCategoryItem> &dta) | 524 | const vector<PwMCategoryItem> &dta) |
493 | { | 525 | { |
494 | unsigned int numCat = dta.size(), i; | 526 | unsigned int numCat = dta.size(), i; |
495 | QString curId, curName; | 527 | QString curId, curName; |
496 | QDomElement curCat; | 528 | QDomElement curCat; |
497 | 529 | ||
498 | for (i = 0; i < numCat; ++i) { | 530 | for (i = 0; i < numCat; ++i) { |
499 | curId = CAT_PREFIX_WR; | 531 | curId = CAT_PREFIX_WR; |
500 | curId += tostr(i).c_str(); | 532 | curId += tostr(i).c_str(); |
501 | curName = dta[i].name.c_str(); | 533 | curName = dta[i].name.c_str(); |
502 | curCat = domDoc->createElement(curId); | 534 | curCat = domDoc->createElement(curId); |
503 | curCat.setAttribute(CAT_NAME_WR, curName); | 535 | curCat.setAttribute(CAT_NAME_WR, curName); |
536 | |||
537 | //US ENH: new version includes text for description, name and pw | ||
538 | QStringList curTextList; | ||
539 | curTextList << dta[i].desc_text.c_str(); | ||
540 | curTextList << dta[i].name_text.c_str(); | ||
541 | curTextList << dta[i].pw_text.c_str(); | ||
542 | QString text = curTextList.join(";"); | ||
543 | curCat.setAttribute(CAT_TEXT_WR, text); | ||
544 | |||
545 | |||
504 | if (!addEntries(&curCat, dta[i].d)) { | 546 | if (!addEntries(&curCat, dta[i].d)) { |
505 | return false; | 547 | return false; |
506 | } | 548 | } |
507 | e->appendChild(curCat); | 549 | e->appendChild(curCat); |
508 | } | 550 | } |
509 | return true; | 551 | return true; |
510 | } | 552 | } |
511 | 553 | ||
512 | bool Serializer::addEntries(QDomElement *e, | 554 | bool Serializer::addEntries(QDomElement *e, |
513 | const vector<PwMDataItem> &dta) | 555 | const vector<PwMDataItem> &dta) |
514 | { | 556 | { |
515 | unsigned int numEntr = dta.size(), i; | 557 | unsigned int numEntr = dta.size(), i; |
516 | QString curId; | 558 | QString curId; |
517 | QDomElement curEntr; | 559 | QDomElement curEntr; |
518 | 560 | ||
519 | for (i = 0; i < numEntr; ++i) { | 561 | for (i = 0; i < numEntr; ++i) { |
520 | curId = ENTRY_PREFIX_WR; | 562 | curId = ENTRY_PREFIX_WR; |
521 | curId += tostr(i).c_str(); | 563 | curId += tostr(i).c_str(); |
522 | curEntr = domDoc->createElement(curId); | 564 | curEntr = domDoc->createElement(curId); |
523 | if (!writeEntry(&curEntr, dta[i])) { | 565 | if (!writeEntry(&curEntr, dta[i])) { |
524 | return false; | 566 | return false; |
525 | } | 567 | } |
526 | e->appendChild(curEntr); | 568 | e->appendChild(curEntr); |
527 | } | 569 | } |
528 | return true; | 570 | return true; |
529 | } | 571 | } |
530 | 572 | ||
531 | bool Serializer::writeEntry(QDomElement *e, | 573 | bool Serializer::writeEntry(QDomElement *e, |
532 | const PwMDataItem &_dta) | 574 | const PwMDataItem &_dta) |
533 | { | 575 | { |
534 | #if WRITE_CDATA_SEC != 0 | 576 | #if WRITE_CDATA_SEC != 0 |
535 | # define new_text(x)domDoc->createCDATASection(x) | 577 | # define new_text(x)domDoc->createCDATASection(x) |
536 | QDomCDATASection curText; | 578 | QDomCDATASection curText; |
537 | #else | 579 | #else |
538 | # define new_text(x)domDoc->createTextNode(x) | 580 | # define new_text(x)domDoc->createTextNode(x) |
539 | QDomText curText; | 581 | QDomText curText; |
540 | #endif | 582 | #endif |
541 | 583 | ||
542 | QDomText plainText; | 584 | QDomText plainText; |
543 | QDomElement tag; | 585 | QDomElement tag; |
544 | 586 | ||
545 | // begin -- This is for compatibility with the old serializer | 587 | // begin -- This is for compatibility with the old serializer |
546 | PwMDataItem dta = _dta; | 588 | PwMDataItem dta = _dta; |
547 | if (!dta.desc.size()) | 589 | if (!dta.desc.size()) |
548 | dta.desc = " "; | 590 | dta.desc = " "; |
549 | if (!dta.name.size()) | 591 | if (!dta.name.size()) |
550 | dta.name = " "; | 592 | dta.name = " "; |
551 | if (!dta.pw.size()) | 593 | if (!dta.pw.size()) |
552 | dta.pw = " "; | 594 | dta.pw = " "; |
553 | if (!dta.comment.size()) | 595 | if (!dta.comment.size()) |
554 | dta.comment = " "; | 596 | dta.comment = " "; |
555 | if (!dta.url.size()) | 597 | if (!dta.url.size()) |
556 | dta.url = " "; | 598 | dta.url = " "; |
557 | if (!dta.launcher.size()) | 599 | if (!dta.launcher.size()) |
558 | dta.launcher = " "; | 600 | dta.launcher = " "; |
559 | // end -- This is for compatibility with the old serializer | 601 | // end -- This is for compatibility with the old serializer |
560 | 602 | ||
561 | tag = domDoc->createElement(ENTRY_DESC_WR); | 603 | tag = domDoc->createElement(ENTRY_DESC_WR); |
562 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 604 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
563 | tag.appendChild(curText); | 605 | tag.appendChild(curText); |
564 | e->appendChild(tag); | 606 | e->appendChild(tag); |
565 | 607 | ||
566 | tag = domDoc->createElement(ENTRY_NAME_WR); | 608 | tag = domDoc->createElement(ENTRY_NAME_WR); |
567 | curText = new_text(escapeEntryData(dta.name.c_str())); | 609 | curText = new_text(escapeEntryData(dta.name.c_str())); |
568 | tag.appendChild(curText); | 610 | tag.appendChild(curText); |
569 | e->appendChild(tag); | 611 | e->appendChild(tag); |
570 | 612 | ||
571 | tag = domDoc->createElement(ENTRY_PW_WR); | 613 | tag = domDoc->createElement(ENTRY_PW_WR); |
572 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 614 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
573 | tag.appendChild(curText); | 615 | tag.appendChild(curText); |
574 | e->appendChild(tag); | 616 | e->appendChild(tag); |
575 | 617 | ||
576 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 618 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
577 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 619 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
578 | tag.appendChild(curText); | 620 | tag.appendChild(curText); |
579 | e->appendChild(tag); | 621 | e->appendChild(tag); |
580 | 622 | ||
581 | tag = domDoc->createElement(ENTRY_URL_WR); | 623 | tag = domDoc->createElement(ENTRY_URL_WR); |
582 | curText = new_text(escapeEntryData(dta.url.c_str())); | 624 | curText = new_text(escapeEntryData(dta.url.c_str())); |
583 | tag.appendChild(curText); | 625 | tag.appendChild(curText); |
584 | e->appendChild(tag); | 626 | e->appendChild(tag); |
585 | 627 | ||
586 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 628 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
587 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 629 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
588 | tag.appendChild(curText); | 630 | tag.appendChild(curText); |
589 | e->appendChild(tag); | 631 | e->appendChild(tag); |
590 | 632 | ||
591 | tag = domDoc->createElement(ENTRY_LVP_WR); | 633 | tag = domDoc->createElement(ENTRY_LVP_WR); |
592 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 634 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
593 | tag.appendChild(plainText); | 635 | tag.appendChild(plainText); |
594 | e->appendChild(tag); | 636 | e->appendChild(tag); |
595 | 637 | ||
596 | tag = domDoc->createElement(ENTRY_BIN_WR); | 638 | tag = domDoc->createElement(ENTRY_BIN_WR); |
597 | if (dta.binary) | 639 | if (dta.binary) |
598 | plainText = domDoc->createTextNode("1"); | 640 | plainText = domDoc->createTextNode("1"); |
599 | else | 641 | else |
600 | plainText = domDoc->createTextNode("0"); | 642 | plainText = domDoc->createTextNode("0"); |
601 | tag.appendChild(plainText); | 643 | tag.appendChild(plainText); |
602 | e->appendChild(tag); | 644 | e->appendChild(tag); |
603 | 645 | ||
604 | tag = domDoc->createElement(ENTRY_META_WR); | 646 | tag = domDoc->createElement(ENTRY_META_WR); |
605 | if (!writeMeta(&tag, dta.meta)) | 647 | if (!writeMeta(&tag, dta.meta)) |
606 | return false; | 648 | return false; |
607 | e->appendChild(tag); | 649 | e->appendChild(tag); |
608 | 650 | ||
609 | #undef new_text | 651 | #undef new_text |
610 | return true; | 652 | return true; |
611 | } | 653 | } |
612 | 654 | ||
613 | bool Serializer::writeMeta(QDomElement *e, | 655 | bool Serializer::writeMeta(QDomElement *e, |
614 | const PwMMetaData &dta) | 656 | const PwMMetaData &dta) |
615 | { | 657 | { |
616 | QDomText text; | 658 | QDomText text; |
617 | QDomElement tag; | 659 | QDomElement tag; |
618 | 660 | ||
619 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 661 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
620 | //So do not transform an empty value at all. | 662 | //So do not transform an empty value at all. |
621 | if (dta.create.isValid()) | 663 | if (dta.create.isValid()) |
622 | { | 664 | { |
623 | tag = domDoc->createElement(META_CREATE_DATE); | 665 | tag = domDoc->createElement(META_CREATE_DATE); |
624 | #ifndef PWM_EMBEDDED | 666 | #ifndef PWM_EMBEDDED |
625 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 667 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
626 | #else | 668 | #else |
627 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 669 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
628 | #endif | 670 | #endif |
629 | tag.appendChild(text); | 671 | tag.appendChild(text); |
630 | e->appendChild(tag); | 672 | e->appendChild(tag); |
631 | } | 673 | } |
632 | 674 | ||
633 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 675 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
634 | //So do not transform an empty value at all. | 676 | //So do not transform an empty value at all. |
635 | if (dta.valid.isValid()) | 677 | if (dta.valid.isValid()) |
636 | { | 678 | { |
637 | tag = domDoc->createElement(META_VALID_DATE); | 679 | tag = domDoc->createElement(META_VALID_DATE); |
638 | #ifndef PWM_EMBEDDED | 680 | #ifndef PWM_EMBEDDED |
639 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 681 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
640 | #else | 682 | #else |
641 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 683 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
642 | #endif | 684 | #endif |
643 | tag.appendChild(text); | 685 | tag.appendChild(text); |
644 | e->appendChild(tag); | 686 | e->appendChild(tag); |
645 | } | 687 | } |
646 | 688 | ||
647 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 689 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
648 | //So do not transform an empty value at all. | 690 | //So do not transform an empty value at all. |
649 | if (dta.expire.isValid()) | 691 | if (dta.expire.isValid()) |
650 | { | 692 | { |
651 | tag = domDoc->createElement(META_EXPIRE_DATE); | 693 | tag = domDoc->createElement(META_EXPIRE_DATE); |
652 | #ifndef PWM_EMBEDDED | 694 | #ifndef PWM_EMBEDDED |
653 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 695 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
654 | #else | 696 | #else |
655 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 697 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
656 | #endif | 698 | #endif |
657 | tag.appendChild(text); | 699 | tag.appendChild(text); |
658 | e->appendChild(tag); | 700 | e->appendChild(tag); |
659 | } | 701 | } |
660 | 702 | ||
661 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. | 703 | //US BUG!!!: The transformation of an empty date into an ISO date is different on different systems/compilers. |
662 | //So do not transform an empty value at all. | 704 | //So do not transform an empty value at all. |
663 | if (dta.update.isValid()) | 705 | if (dta.update.isValid()) |
664 | { | 706 | { |
665 | tag = domDoc->createElement(META_UPDATE_DATE); | 707 | tag = domDoc->createElement(META_UPDATE_DATE); |
666 | #ifndef PWM_EMBEDDED | 708 | #ifndef PWM_EMBEDDED |
667 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 709 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
668 | #else | 710 | #else |
669 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 711 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
670 | #endif | 712 | #endif |
671 | tag.appendChild(text); | 713 | tag.appendChild(text); |
672 | e->appendChild(tag); | 714 | e->appendChild(tag); |
673 | } | 715 | } |
674 | 716 | ||
675 | tag = domDoc->createElement(META_UPDATE_INT); | 717 | tag = domDoc->createElement(META_UPDATE_INT); |
676 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 718 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
677 | tag.appendChild(text); | 719 | tag.appendChild(text); |
678 | e->appendChild(tag); | 720 | e->appendChild(tag); |
679 | 721 | ||
680 | tag = domDoc->createElement(META_UNIQUEID); | 722 | tag = domDoc->createElement(META_UNIQUEID); |
681 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); | 723 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); |
682 | tag.appendChild(text); | 724 | tag.appendChild(text); |
683 | e->appendChild(tag); | 725 | e->appendChild(tag); |
684 | 726 | ||
685 | #undef new_text | 727 | #undef new_text |
686 | return true; | 728 | return true; |
687 | } | 729 | } |
688 | 730 | ||
689 | QString Serializer::escapeEntryData(QString dta) | 731 | QString Serializer::escapeEntryData(QString dta) |
690 | { | 732 | { |
691 | #ifndef PWM_EMBEDDED | 733 | #ifndef PWM_EMBEDDED |
692 | dta.replace('\n', "$>--endl--<$"); | 734 | dta.replace('\n', "$>--endl--<$"); |
693 | dta.replace("]]>", "||>"); | 735 | dta.replace("]]>", "||>"); |
694 | #else | 736 | #else |
695 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 737 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
696 | dta.replace(QRegExp("]]>"), "||>"); | 738 | dta.replace(QRegExp("]]>"), "||>"); |
697 | #endif | 739 | #endif |
698 | return dta; | 740 | return dta; |
699 | } | 741 | } |
700 | 742 | ||
701 | QString Serializer::unescapeEntryData(QString dta) | 743 | QString Serializer::unescapeEntryData(QString dta) |
702 | { | 744 | { |
703 | #ifndef PWM_EMBEDDED | 745 | #ifndef PWM_EMBEDDED |
704 | dta.replace("$>--endl--<$", "\n"); | 746 | dta.replace("$>--endl--<$", "\n"); |
705 | dta.replace("||>", "]]>"); | 747 | dta.replace("||>", "]]>"); |
706 | #else | 748 | #else |
707 | #ifdef DESKTOP_VERSION | 749 | #ifdef DESKTOP_VERSION |
708 | dta.replace("$>--endl--<$", "\n"); | 750 | dta.replace("$>--endl--<$", "\n"); |
709 | dta.replace("||>", "]]>"); | 751 | dta.replace("||>", "]]>"); |
710 | #else | 752 | #else |
711 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); | 753 | dta.replace(QRegExp("\\$>--endl--<\\$"), "\n"); |
712 | dta.replace(QRegExp("||>"), "]]>"); | 754 | dta.replace(QRegExp("||>"), "]]>"); |
713 | #endif | 755 | #endif |
714 | #endif | 756 | #endif |
715 | return dta; | 757 | return dta; |
716 | } | 758 | } |
717 | 759 | ||
718 | 760 | ||
719 | //US ENH: the following methods are getting used to write/read sync entries | 761 | //US ENH: the following methods are getting used to write/read sync entries |
720 | /** read the syncentries in the node "n" */ | 762 | /** read the syncentries in the node "n" */ |
721 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) | 763 | bool Serializer::readSyncData(const QDomNode &n, vector<PwMSyncItem> *dta) |
722 | { | 764 | { |
723 | QDomNodeList nl(n.childNodes()); | 765 | QDomNodeList nl(n.childNodes()); |
724 | QDomNode cur; | 766 | QDomNode cur; |
725 | 767 | ||
726 | QString devicename, val; | 768 | QString devicename, val; |
727 | unsigned int numSync = nl.count(), i; | 769 | unsigned int numSync = nl.count(), i; |
728 | PwMSyncItem curSync; | 770 | PwMSyncItem curSync; |
729 | bool ok = true; | 771 | bool ok = true; |
730 | 772 | ||
731 | if (!numSync) { | 773 | if (!numSync) { |
732 | //no sync entries is a possible result | 774 | //no sync entries is a possible result |
733 | printDebug("Serializer::readSyncData(): empty"); | 775 | printDebug("Serializer::readSyncData(): empty"); |
734 | return true; | 776 | return true; |
735 | } | 777 | } |
736 | for (i = 0; i < numSync; ++i) { | 778 | for (i = 0; i < numSync; ++i) { |
737 | cur = nl.item(i); | 779 | cur = nl.item(i); |
738 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { | 780 | if (cur.nodeName().left(1) == SYNC_TARGET_PREFIX) { |
739 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); | 781 | devicename = cur.toElement().attribute(SYNC_TARGET_NAME); |
740 | val = cur.toElement().text(); | 782 | val = cur.toElement().text(); |
741 | 783 | ||
742 | if ((val == "") || (devicename == QString::null)) { | 784 | if ((val == "") || (devicename == QString::null)) { |
743 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); | 785 | printDebug("Serializer::readSyncData(): empty synctarget name or syncdate"); |
744 | continue; | 786 | continue; |
745 | } | 787 | } |
746 | 788 | ||
747 | curSync.syncName = devicename.latin1(); | 789 | curSync.syncName = devicename.latin1(); |
748 | #ifndef PWM_EMBEDDED | 790 | #ifndef PWM_EMBEDDED |
749 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); | 791 | curSync.lastSyncDate = QDateTime::fromString(val, Qt::ISODate); |
750 | #else | 792 | #else |
751 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); | 793 | curSync.lastSyncDate = KGlobal::locale()->readDateTime(val, KLocale::ISODate, &ok); |
752 | if (ok == false) | 794 | if (ok == false) |
753 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); | 795 | qDebug("Serializer::readSyncData(): could not parse syncdate:%s",val.latin1()); |
754 | 796 | ||
755 | #endif | 797 | #endif |
756 | dta->push_back(curSync); | 798 | dta->push_back(curSync); |
757 | } | 799 | } |
758 | } | 800 | } |
759 | return true; | 801 | return true; |
760 | 802 | ||
761 | } | 803 | } |
762 | 804 | ||
763 | 805 | ||
764 | 806 | ||
765 | bool Serializer::addSyncData(QDomElement *e, | 807 | bool Serializer::addSyncData(QDomElement *e, |
766 | const vector<PwMSyncItem> &dta) | 808 | const vector<PwMSyncItem> &dta) |
767 | { | 809 | { |
768 | unsigned int numSync = dta.size(), i; | 810 | unsigned int numSync = dta.size(), i; |
769 | QString curId, curDeviceName; | 811 | QString curId, curDeviceName; |
770 | QDomElement curSync; | 812 | QDomElement curSync; |
771 | QDomText text; | 813 | QDomText text; |
772 | 814 | ||
773 | for (i = 0; i < numSync; ++i) { | 815 | for (i = 0; i < numSync; ++i) { |
774 | curId = SYNC_TARGET_PREFIX; | 816 | curId = SYNC_TARGET_PREFIX; |
775 | curId += tostr(i).c_str(); | 817 | curId += tostr(i).c_str(); |
776 | curDeviceName = dta[i].syncName.c_str(); | 818 | curDeviceName = dta[i].syncName.c_str(); |
777 | curSync = domDoc->createElement(curId); | 819 | curSync = domDoc->createElement(curId); |
778 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); | 820 | curSync.setAttribute(SYNC_TARGET_NAME, curDeviceName); |
779 | 821 | ||
780 | #ifndef PWM_EMBEDDED | 822 | #ifndef PWM_EMBEDDED |
781 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); | 823 | text = domDoc->createTextNode(dta[i].lastSyncDate.toString(Qt::ISODate)); |
782 | #else | 824 | #else |
783 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); | 825 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta[i].lastSyncDate, KLocale::ISODate)); |
784 | #endif | 826 | #endif |
785 | curSync.appendChild(text); | 827 | curSync.appendChild(text); |
786 | 828 | ||
787 | e->appendChild(curSync); | 829 | e->appendChild(curSync); |
788 | 830 | ||
789 | } | 831 | } |
790 | return true; | 832 | return true; |
791 | } | 833 | } |
792 | 834 | ||