-rw-r--r-- | pwmanager/pwmanager/addentrywnd_emb.cpp | 20 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywnd_emb.h | 5 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywndimpl.cpp | 22 | ||||
-rw-r--r-- | pwmanager/pwmanager/addentrywndimpl.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/commentbox.cpp | 87 | ||||
-rw-r--r-- | pwmanager/pwmanager/commentbox.h | 40 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 3 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmprefs.cpp | 3 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmprefs.h | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle.cpp | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmviewstyle_1.cpp | 6 |
12 files changed, 132 insertions, 65 deletions
diff --git a/pwmanager/pwmanager/addentrywnd_emb.cpp b/pwmanager/pwmanager/addentrywnd_emb.cpp index ed02e6d..dd09d13 100644 --- a/pwmanager/pwmanager/addentrywnd_emb.cpp +++ b/pwmanager/pwmanager/addentrywnd_emb.cpp | |||
@@ -1,213 +1,199 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of PwManager/Platform independent. | 2 | This file is part of PwManager/Platform independent. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | 22 | ||
23 | $Id$ | 23 | $Id$ |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include "addentrywnd_emb.h" | 26 | #include "addentrywnd_emb.h" |
27 | 27 | ||
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | #include <qgroupbox.h> | 31 | #include <qgroupbox.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | #include <kcombobox.h> | 33 | #include <kcombobox.h> |
34 | #include <klineedit.h> | 34 | #include <klineedit.h> |
35 | #include <qpushbutton.h> | 35 | #include <qpushbutton.h> |
36 | #include <qmultilineedit.h> | ||
36 | 37 | ||
37 | /* | 38 | /* |
38 | * Constructs a addEntryWnd as a child of 'parent', with the | 39 | * Constructs a addEntryWnd as a child of 'parent', with the |
39 | * name 'name' and widget flags set to 'f'. | 40 | * name 'name' and widget flags set to 'f'. |
40 | * | 41 | * |
41 | * The dialog will by default be modeless, unless you set 'modal' to | 42 | * The dialog will by default be modeless, unless you set 'modal' to |
42 | * TRUE to construct a modal dialog. | 43 | * TRUE to construct a modal dialog. |
43 | */ | 44 | */ |
44 | addEntryWnd::addEntryWnd( QWidget* parent, const char* name) | 45 | addEntryWnd::addEntryWnd( QWidget* parent, const char* name) |
45 | : KDialogBase( KDialogBase::Plain, i18n( "edit/add a password entry" ), | 46 | : KDialogBase( KDialogBase::Plain, i18n( "edit/add a password entry" ), |
46 | KDialogBase::Ok | KDialogBase::Cancel, | 47 | KDialogBase::Ok | KDialogBase::Cancel, |
47 | KDialogBase::Ok, parent, name, true ) | 48 | KDialogBase::Ok, parent, name, true ) |
48 | { | 49 | { |
49 | QWidget *page = plainPage(); | 50 | QWidget *page = plainPage(); |
50 | QVBoxLayout *pageLayout = new QVBoxLayout( page ); | 51 | QVBoxLayout *pageLayout = new QVBoxLayout( page ); |
51 | 52 | ||
52 | QTabWidget* mTabWidget = new QTabWidget( page ); | 53 | QTabWidget* mTabWidget = new QTabWidget( page ); |
53 | pageLayout->addWidget( mTabWidget ); | 54 | pageLayout->addWidget( mTabWidget ); |
54 | 55 | ||
55 | //////////////////////////////////////////////////////////////////// | 56 | //////////////////////////////////////////////////////////////////// |
56 | // This is the Password tab | 57 | // This is the Password tab |
57 | QWidget *tab1 = new QWidget( mTabWidget ); | 58 | QWidget *tab1 = new QWidget( mTabWidget ); |
58 | 59 | ||
59 | QGridLayout *layout = new QGridLayout( tab1, 3, 1 ); | 60 | QGridLayout *layout = new QGridLayout( tab1, 3, 1 ); |
60 | layout->setMargin( KDialogBase::marginHint() ); | 61 | layout->setMargin( KDialogBase::marginHint() ); |
61 | layout->setSpacing( KDialogBase::spacingHint() ); | 62 | layout->setSpacing( KDialogBase::spacingHint() ); |
62 | 63 | ||
63 | 64 | ||
64 | 65 | ||
65 | int i = 0; | 66 | int i = 0; |
66 | descLineEdit = new KLineEdit( tab1, "descLineEdit" ); | 67 | descLineEdit = new KLineEdit( tab1, "descLineEdit" ); |
67 | QLabel* label = new QLabel( descLineEdit, i18n("Description:"), tab1 ); | 68 | QLabel* label = new QLabel( descLineEdit, i18n("Description:"), tab1 ); |
68 | layout->addWidget( label, i, 0 ); | 69 | layout->addWidget( label, i, 0 ); |
69 | layout->addWidget( descLineEdit, i, 1 ); | 70 | layout->addWidget( descLineEdit, i, 1 ); |
70 | i++; | 71 | i++; |
71 | 72 | ||
72 | categoryComboBox = new KComboBox( tab1 ); | 73 | categoryComboBox = new KComboBox( tab1 ); |
73 | label = new QLabel( categoryComboBox, i18n("Category:"), tab1 ); | 74 | label = new QLabel( categoryComboBox, i18n("Category:"), tab1 ); |
74 | layout->addWidget( label, i, 0 ); | 75 | layout->addWidget( label, i, 0 ); |
75 | layout->addWidget( categoryComboBox, i, 1 ); | 76 | layout->addWidget( categoryComboBox, i, 1 ); |
76 | i++; | 77 | i++; |
77 | categoryComboBox->setEditable( TRUE ); | 78 | categoryComboBox->setEditable( TRUE ); |
78 | categoryComboBox->setSizeLimit( 100 ); | 79 | categoryComboBox->setSizeLimit( 100 ); |
79 | categoryComboBox->setAutoCompletion( TRUE ); | 80 | categoryComboBox->setAutoCompletion( TRUE ); |
80 | categoryComboBox->setDuplicatesEnabled( FALSE ); | 81 | categoryComboBox->setDuplicatesEnabled( FALSE ); |
81 | 82 | ||
82 | usernameLineEdit = new KLineEdit( tab1, "usernameLineEdit" ); | 83 | usernameLineEdit = new KLineEdit( tab1, "usernameLineEdit" ); |
83 | label = new QLabel( usernameLineEdit, i18n("Username:"), tab1 ); | 84 | label = new QLabel( usernameLineEdit, i18n("Username:"), tab1 ); |
84 | layout->addWidget( label, i, 0 ); | 85 | layout->addWidget( label, i, 0 ); |
85 | layout->addWidget( usernameLineEdit, i, 1 ); | 86 | layout->addWidget( usernameLineEdit, i, 1 ); |
86 | i++; | 87 | i++; |
87 | 88 | ||
88 | pwLineEdit = new KLineEdit( tab1, "pwLineEdit" ); | 89 | pwLineEdit = new KLineEdit( tab1, "pwLineEdit" ); |
89 | pwLineEdit->setEchoMode( QLineEdit::Password ); | 90 | pwLineEdit->setEchoMode( QLineEdit::Password ); |
90 | label = new QLabel( pwLineEdit, i18n("Password:"), tab1 ); | 91 | label = new QLabel( pwLineEdit, i18n("Password:"), tab1 ); |
91 | layout->addWidget( label, i, 0 ); | 92 | layout->addWidget( label, i, 0 ); |
92 | layout->addWidget( pwLineEdit, i, 1 ); | 93 | layout->addWidget( pwLineEdit, i, 1 ); |
93 | i++; | 94 | i++; |
94 | 95 | ||
95 | revealButton = new QPushButton( i18n("&Reveal"), tab1, "revealButton" ); | 96 | revealButton = new QPushButton( i18n("&Reveal"), tab1, "revealButton" ); |
96 | revealButton->setToggleButton( TRUE ); | 97 | revealButton->setToggleButton( TRUE ); |
97 | layout->addWidget( revealButton, i, 0 ); | 98 | layout->addWidget( revealButton, i, 0 ); |
98 | 99 | ||
99 | generateButton = new QPushButton( i18n("&Generate"), tab1, "generateButton" ); | 100 | generateButton = new QPushButton( i18n("&Generate"), tab1, "generateButton" ); |
100 | layout->addWidget( generateButton, i, 1 ); | 101 | layout->addWidget( generateButton, i, 1 ); |
101 | i++; | 102 | i++; |
102 | 103 | ||
103 | urlLineEdit = new KLineEdit( tab1, "urlLineEdit" ); | 104 | urlLineEdit = new KLineEdit( tab1, "urlLineEdit" ); |
104 | label = new QLabel( urlLineEdit, i18n("URL:"), tab1 ); | 105 | label = new QLabel( urlLineEdit, i18n("URL:"), tab1 ); |
105 | layout->addWidget( label, i, 0 ); | 106 | layout->addWidget( label, i, 0 ); |
106 | layout->addWidget( urlLineEdit, i, 1 ); | 107 | layout->addWidget( urlLineEdit, i, 1 ); |
107 | i++; | 108 | i++; |
108 | 109 | ||
109 | mTabWidget->addTab( tab1, i18n( "&Password" ) ); | 110 | mTabWidget->addTab( tab1, i18n( "&Password" ) ); |
110 | 111 | ||
111 | 112 | ||
112 | //////////////////////////////////////////////////////////////////// | 113 | //////////////////////////////////////////////////////////////////// |
113 | // This is the Comment tab | 114 | // This is the Comment tab |
114 | QWidget *tab2 = new QWidget( mTabWidget ); | 115 | QWidget *tab2 = new QWidget( mTabWidget ); |
115 | 116 | ||
116 | layout = new QGridLayout( tab2, 3, 1 ); | 117 | layout = new QGridLayout( tab2, 3, 1 ); |
117 | layout->setMargin( KDialogBase::marginHintSmall() ); | 118 | layout->setMargin( KDialogBase::marginHintSmall() ); |
118 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 119 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
119 | i = 0; | 120 | i = 0; |
120 | 121 | ||
121 | 122 | commentTextEdit = new QMultiLineEdit(tab2); | |
122 | 123 | layout->addMultiCellWidget( commentTextEdit, i, i, 0, 0 ); | |
123 | groupBox1 = new QGroupBox( tab2, "groupBox1" ); | ||
124 | commentDummy = new QLabel( groupBox1, "commentDummy" ); | ||
125 | commentDummy->setText( QString::null ); | ||
126 | |||
127 | groupBox1->setTitle( i18n( "Comment:" ) ); | ||
128 | |||
129 | layout->addMultiCellWidget( groupBox1, i, i, 0, 1 ); | ||
130 | i++; | ||
131 | |||
132 | |||
133 | advancedCommentButton = new QPushButton( i18n("advanced comment"), groupBox1, "advancedCommentButton" ); | ||
134 | advancedCommentButton->setToggleButton( FALSE ); | ||
135 | layout->addMultiCellWidget( advancedCommentButton, i, i, 0, 1 ); | ||
136 | i++; | 124 | i++; |
137 | 125 | ||
138 | 126 | ||
139 | mTabWidget->addTab( tab2, i18n( "&Comments" ) ); | 127 | mTabWidget->addTab( tab2, i18n( "&Comments" ) ); |
140 | 128 | ||
141 | 129 | ||
142 | //////////////////////////////////////////////////////////////////// | 130 | //////////////////////////////////////////////////////////////////// |
143 | // This is the Launcher tab | 131 | // This is the Launcher tab |
144 | QWidget *tab3 = new QWidget( mTabWidget ); | 132 | QWidget *tab3 = new QWidget( mTabWidget ); |
145 | 133 | ||
146 | layout = new QGridLayout( tab3, 3, 1 ); | 134 | layout = new QGridLayout( tab3, 3, 1 ); |
147 | layout->setMargin( KDialogBase::marginHintSmall() ); | 135 | layout->setMargin( KDialogBase::marginHintSmall() ); |
148 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 136 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
149 | i = 0; | 137 | i = 0; |
150 | 138 | ||
151 | launcherLineEdit = new KLineEdit( tab3, "launcherLineEdit" ); | 139 | launcherLineEdit = new KLineEdit( tab3, "launcherLineEdit" ); |
152 | label = new QLabel( launcherLineEdit, i18n("Launcher:"), tab3 ); | 140 | label = new QLabel( launcherLineEdit, i18n("Launcher:"), tab3 ); |
153 | 141 | ||
154 | QLabel* label1 = new QLabel( launcherLineEdit, i18n("$d = Description"), tab3 ); | 142 | QLabel* label1 = new QLabel( launcherLineEdit, i18n("$d = Description"), tab3 ); |
155 | QLabel* label2 = new QLabel( launcherLineEdit, i18n("$n = Username"), tab3 ); | 143 | QLabel* label2 = new QLabel( launcherLineEdit, i18n("$n = Username"), tab3 ); |
156 | QLabel* label3 = new QLabel( launcherLineEdit, i18n("$c = Comment"), tab3 ); | 144 | QLabel* label3 = new QLabel( launcherLineEdit, i18n("$c = Comment"), tab3 ); |
157 | QLabel* label4 = new QLabel( launcherLineEdit, i18n("$u = URL"), tab3 ); | 145 | QLabel* label4 = new QLabel( launcherLineEdit, i18n("$u = URL"), tab3 ); |
158 | QLabel* label5 = new QLabel( launcherLineEdit, i18n("$p = Password"), tab3 ); | 146 | QLabel* label5 = new QLabel( launcherLineEdit, i18n("$p = Password"), tab3 ); |
159 | 147 | ||
160 | label = new QLabel( launcherLineEdit, i18n("Launcher:"), tab3 ); | 148 | label = new QLabel( launcherLineEdit, i18n("Launcher:"), tab3 ); |
161 | 149 | ||
162 | layout->addWidget( label1, i, 0 ); | 150 | layout->addWidget( label1, i, 0 ); |
163 | layout->addWidget( label2, i, 1 ); | 151 | layout->addWidget( label2, i, 1 ); |
164 | i++; | 152 | i++; |
165 | layout->addWidget( label3, i, 0 ); | 153 | layout->addWidget( label3, i, 0 ); |
166 | layout->addWidget( label4, i, 1 ); | 154 | layout->addWidget( label4, i, 1 ); |
167 | i++; | 155 | i++; |
168 | layout->addWidget( label5, i, 0 ); | 156 | layout->addWidget( label5, i, 0 ); |
169 | i++; | 157 | i++; |
170 | 158 | ||
171 | layout->addWidget( label, i, 0 ); | 159 | layout->addWidget( label, i, 0 ); |
172 | layout->addWidget( launcherLineEdit, i, 1 ); | 160 | layout->addWidget( launcherLineEdit, i, 1 ); |
173 | i++; | 161 | i++; |
174 | 162 | ||
175 | 163 | ||
176 | mTabWidget->addTab( tab3, i18n( "&Launcher" ) ); | 164 | mTabWidget->addTab( tab3, i18n( "&Launcher" ) ); |
177 | 165 | ||
178 | // signals and slots connections | 166 | // signals and slots connections |
179 | connect( generateButton, SIGNAL( clicked() ), this, SLOT( generateButton_slot() ) ); | 167 | connect( generateButton, SIGNAL( clicked() ), this, SLOT( generateButton_slot() ) ); |
180 | connect( revealButton, SIGNAL( toggled(bool) ), this, SLOT( revealButton_slot() ) ); | 168 | connect( revealButton, SIGNAL( toggled(bool) ), this, SLOT( revealButton_slot() ) ); |
181 | connect( advancedCommentButton, SIGNAL( toggled(bool) ), this, SLOT( advancedCommentButton_slot(bool) ) ); | ||
182 | |||
183 | } | 169 | } |
184 | 170 | ||
185 | /* | 171 | /* |
186 | * Destroys the object and frees any allocated resources | 172 | * Destroys the object and frees any allocated resources |
187 | */ | 173 | */ |
188 | addEntryWnd::~addEntryWnd() | 174 | addEntryWnd::~addEntryWnd() |
189 | { | 175 | { |
190 | // no need to delete child widgets, Qt does it all for us | 176 | // no need to delete child widgets, Qt does it all for us |
191 | } | 177 | } |
192 | 178 | ||
193 | void addEntryWnd::slotOk() | 179 | void addEntryWnd::slotOk() |
194 | { | 180 | { |
195 | qWarning( "addEntryWnd::slotOk(): Not implemented yet" ); | 181 | qWarning( "addEntryWnd::slotOk(): Not implemented yet" ); |
196 | } | 182 | } |
197 | 183 | ||
198 | void addEntryWnd::revealButton_slot() | 184 | void addEntryWnd::revealButton_slot() |
199 | { | 185 | { |
200 | qWarning( "addEntryWnd::revealButton_slot(): Not implemented yet" ); | 186 | qWarning( "addEntryWnd::revealButton_slot(): Not implemented yet" ); |
201 | } | 187 | } |
202 | 188 | ||
203 | void addEntryWnd::generateButton_slot() | 189 | void addEntryWnd::generateButton_slot() |
204 | { | 190 | { |
205 | qWarning( "addEntryWnd::generateButton_slot(): Not implemented yet" ); | 191 | qWarning( "addEntryWnd::generateButton_slot(): Not implemented yet" ); |
206 | } | 192 | } |
207 | 193 | ||
208 | void addEntryWnd::advancedCommentButton_slot(bool) | 194 | void addEntryWnd::advancedCommentButton_slot(bool) |
209 | { | 195 | { |
210 | qWarning( "addEntryWnd::advancedCommentButton_slot(bool): Not implemented yet" ); | 196 | qWarning( "addEntryWnd::advancedCommentButton_slot(bool): Not implemented yet" ); |
211 | } | 197 | } |
212 | 198 | ||
213 | 199 | ||
diff --git a/pwmanager/pwmanager/addentrywnd_emb.h b/pwmanager/pwmanager/addentrywnd_emb.h index e368721..83761dc 100644 --- a/pwmanager/pwmanager/addentrywnd_emb.h +++ b/pwmanager/pwmanager/addentrywnd_emb.h | |||
@@ -1,73 +1,72 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of PwManager/Platform independent. | 2 | This file is part of PwManager/Platform independent. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | 22 | ||
23 | $Id$ | 23 | $Id$ |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #ifndef ADDENTRYWND_EMB_H | 26 | #ifndef ADDENTRYWND_EMB_H |
27 | #define ADDENTRYWND_EMB_H | 27 | #define ADDENTRYWND_EMB_H |
28 | 28 | ||
29 | #include <qvariant.h> | 29 | #include <qvariant.h> |
30 | #include <kdialogbase.h> | 30 | #include <kdialogbase.h> |
31 | 31 | ||
32 | class QVBoxLayout; | 32 | class QVBoxLayout; |
33 | class QHBoxLayout; | 33 | class QHBoxLayout; |
34 | class QGridLayout; | 34 | class QGridLayout; |
35 | class QSpacerItem; | 35 | class QSpacerItem; |
36 | class KLineEdit; | 36 | class KLineEdit; |
37 | class QPushButton; | 37 | class QPushButton; |
38 | class KComboBox; | 38 | class KComboBox; |
39 | class QLabel; | 39 | class QLabel; |
40 | class QGroupBox; | 40 | class QGroupBox; |
41 | class QMultiLineEdit; | ||
41 | 42 | ||
42 | class addEntryWnd : public KDialogBase | 43 | class addEntryWnd : public KDialogBase |
43 | { | 44 | { |
44 | Q_OBJECT | 45 | Q_OBJECT |
45 | 46 | ||
46 | public: | 47 | public: |
47 | addEntryWnd( QWidget* parent = 0, const char* name = 0); | 48 | addEntryWnd( QWidget* parent = 0, const char* name = 0); |
48 | ~addEntryWnd(); | 49 | ~addEntryWnd(); |
49 | 50 | ||
50 | KLineEdit* launcherLineEdit; | 51 | KLineEdit* launcherLineEdit; |
51 | QPushButton* generateButton; | 52 | QPushButton* generateButton; |
52 | KLineEdit* descLineEdit; | 53 | KLineEdit* descLineEdit; |
53 | KComboBox* categoryComboBox; | 54 | KComboBox* categoryComboBox; |
54 | KLineEdit* usernameLineEdit; | 55 | KLineEdit* usernameLineEdit; |
55 | KLineEdit* pwLineEdit; | 56 | KLineEdit* pwLineEdit; |
56 | KLineEdit* urlLineEdit; | 57 | KLineEdit* urlLineEdit; |
57 | 58 | ||
58 | QPushButton* revealButton; | 59 | QPushButton* revealButton; |
59 | QGroupBox* groupBox1; | 60 | QMultiLineEdit* commentTextEdit; |
60 | QLabel* commentDummy; | ||
61 | QPushButton* advancedCommentButton; | ||
62 | 61 | ||
63 | public slots: | 62 | public slots: |
64 | virtual void revealButton_slot(); | 63 | virtual void revealButton_slot(); |
65 | virtual void generateButton_slot(); | 64 | virtual void generateButton_slot(); |
66 | virtual void advancedCommentButton_slot(bool on); | 65 | virtual void advancedCommentButton_slot(bool on); |
67 | 66 | ||
68 | protected slots: | 67 | protected slots: |
69 | virtual void slotOk(); | 68 | virtual void slotOk(); |
70 | 69 | ||
71 | }; | 70 | }; |
72 | 71 | ||
73 | #endif // ADDENTRYWND_H | 72 | #endif // ADDENTRYWND_H |
diff --git a/pwmanager/pwmanager/addentrywndimpl.cpp b/pwmanager/pwmanager/addentrywndimpl.cpp index ffd301f..d47f32c 100644 --- a/pwmanager/pwmanager/addentrywndimpl.cpp +++ b/pwmanager/pwmanager/addentrywndimpl.cpp | |||
@@ -1,203 +1,217 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * Many very good improvements and the original implementations of * | 6 | * Many very good improvements and the original implementations of * |
7 | * them came from Matt Scifo <mscifo@o1.com> * | 7 | * them came from Matt Scifo <mscifo@o1.com> * |
8 | * * | 8 | * * |
9 | * This program is free software; you can redistribute it and/or modify * | 9 | * This program is free software; you can redistribute it and/or modify * |
10 | * it under the terms of the GNU General Public License version 2 * | 10 | * it under the terms of the GNU General Public License version 2 * |
11 | * as published by the Free Software Foundation. * | 11 | * as published by the Free Software Foundation. * |
12 | * * | 12 | * * |
13 | ***************************************************************************/ | 13 | ***************************************************************************/ |
14 | 14 | ||
15 | /*************************************************************************** | 15 | /*************************************************************************** |
16 | * copyright (C) 2004 by Ulf Schenk | 16 | * copyright (C) 2004 by Ulf Schenk |
17 | * This file is originaly based on version 1.0.1 of pwmanager | 17 | * This file is originaly based on version 1.0.1 of pwmanager |
18 | * and was modified to run on embedded devices that run microkde | 18 | * and was modified to run on embedded devices that run microkde |
19 | * | 19 | * |
20 | * $Id$ | 20 | * $Id$ |
21 | **************************************************************************/ | 21 | **************************************************************************/ |
22 | 22 | ||
23 | #include "addentrywndimpl.h" | 23 | #include "addentrywndimpl.h" |
24 | #include "pwmexception.h" | 24 | #include "pwmexception.h" |
25 | #include "pwgenwndimpl.h" | 25 | #include "pwgenwndimpl.h" |
26 | #ifndef PWM_EMBEDDED | 26 | #ifndef PWM_EMBEDDED |
27 | #include "advcommeditimpl.h" | 27 | #include "advcommeditimpl.h" |
28 | #endif | 28 | #endif |
29 | #include "htmlgen.h" | 29 | #include "htmlgen.h" |
30 | 30 | ||
31 | #include <kmessagebox.h> | 31 | #include <kmessagebox.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | 33 | ||
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qlabel.h> | 35 | #include <qlabel.h> |
36 | #include <qlayout.h> | ||
37 | |||
36 | 38 | ||
37 | #ifndef PWM_EMBEDDED | 39 | #ifndef PWM_EMBEDDED |
38 | AddEntryWndImpl::AddEntryWndImpl() | 40 | AddEntryWndImpl::AddEntryWndImpl() |
39 | : addEntryWnd( 0, "AddEntryWndImpl", TRUE) | 41 | : addEntryWnd( 0, "AddEntryWndImpl", TRUE) |
40 | #else | 42 | #else |
41 | AddEntryWndImpl::AddEntryWndImpl( QWidget* parent, const char* name) | 43 | AddEntryWndImpl::AddEntryWndImpl( QWidget* parent, const char* name) |
42 | : addEntryWnd( parent, name) | 44 | : addEntryWnd( parent, name) |
43 | #endif | 45 | #endif |
44 | { | 46 | { |
47 | #ifndef PWM_EMBEDDED | ||
45 | editAdvCommentButton = 0; | 48 | editAdvCommentButton = 0; |
46 | commentTextEdit = 0; | 49 | commentTextEdit = 0; |
50 | #endif | ||
47 | switchComment(false); | 51 | switchComment(false); |
48 | pwGen = new PwGenWndImpl(this); | 52 | pwGen = new PwGenWndImpl(this); |
49 | } | 53 | } |
50 | 54 | ||
51 | AddEntryWndImpl::~AddEntryWndImpl() | 55 | AddEntryWndImpl::~AddEntryWndImpl() |
52 | { | 56 | { |
57 | #ifndef PWM_EMBEDDED | ||
53 | delete_ifnot_null(editAdvCommentButton); | 58 | delete_ifnot_null(editAdvCommentButton); |
54 | delete_ifnot_null(commentTextEdit); | 59 | delete_ifnot_null(commentTextEdit); |
60 | #endif | ||
55 | delete pwGen; | 61 | delete pwGen; |
56 | } | 62 | } |
57 | 63 | ||
58 | #ifdef PWM_EMBEDDED | 64 | #ifdef PWM_EMBEDDED |
59 | void AddEntryWndImpl::slotOk() | 65 | void AddEntryWndImpl::slotOk() |
60 | { | 66 | { |
61 | slotApply(); | 67 | slotApply(); |
62 | 68 | ||
63 | if (pwLineEdit->text().isEmpty()) { | 69 | if (pwLineEdit->text().isEmpty()) { |
64 | KMessageBox::error(this, | 70 | KMessageBox::error(this, |
65 | i18n("Sorry, you haven't set a password."), | 71 | i18n("Sorry, you haven't set a password."), |
66 | i18n("no password")); | 72 | i18n("no password")); |
67 | return; | 73 | return; |
68 | } | 74 | } |
69 | 75 | ||
70 | if (descLineEdit->text().isEmpty()) { | 76 | if (descLineEdit->text().isEmpty()) { |
71 | KMessageBox::error(this, | 77 | KMessageBox::error(this, |
72 | i18n("You haven't set a \"Description\"."), | 78 | i18n("You haven't set a \"Description\"."), |
73 | i18n("Description not set")); | 79 | i18n("Description not set")); |
74 | return; | 80 | return; |
75 | } | 81 | } |
76 | 82 | ||
77 | KDialogBase::slotOk(); | 83 | KDialogBase::slotOk(); |
78 | } | 84 | } |
79 | #else | 85 | #else |
80 | 86 | ||
81 | void AddEntryWndImpl::okButton_slot() | 87 | void AddEntryWndImpl::okButton_slot() |
82 | { | 88 | { |
83 | if (pwLineEdit->text().isEmpty()) { | 89 | if (pwLineEdit->text().isEmpty()) { |
84 | KMessageBox::error(this, | 90 | KMessageBox::error(this, |
85 | i18n("Sorry, you haven't set a password."), | 91 | i18n("Sorry, you haven't set a password."), |
86 | i18n("no password")); | 92 | i18n("no password")); |
87 | return; | 93 | return; |
88 | } | 94 | } |
89 | if (descLineEdit->text().isEmpty()) { | 95 | if (descLineEdit->text().isEmpty()) { |
90 | KMessageBox::error(this, | 96 | KMessageBox::error(this, |
91 | i18n | 97 | i18n |
92 | ("You haven't set a \"Description\"."), | 98 | ("You haven't set a \"Description\"."), |
93 | i18n("Description not set")); | 99 | i18n("Description not set")); |
94 | return; | 100 | return; |
95 | } | 101 | } |
96 | done(1); | 102 | done(1); |
97 | } | 103 | } |
98 | 104 | ||
99 | void AddEntryWndImpl::cancelButton_slot() | 105 | void AddEntryWndImpl::cancelButton_slot() |
100 | { | 106 | { |
101 | done(2); | 107 | done(2); |
102 | } | 108 | } |
103 | #endif | 109 | #endif |
104 | 110 | ||
105 | void AddEntryWndImpl::setCurrCategory(const QString &cat) | 111 | void AddEntryWndImpl::setCurrCategory(const QString &cat) |
106 | { | 112 | { |
107 | int i, count = categoryComboBox->count(); | 113 | int i, count = categoryComboBox->count(); |
108 | 114 | ||
109 | for (i = 0; i < count; ++i) { | 115 | for (i = 0; i < count; ++i) { |
110 | if (categoryComboBox->text(i) == cat) { | 116 | if (categoryComboBox->text(i) == cat) { |
111 | categoryComboBox->setCurrentItem(i); | 117 | categoryComboBox->setCurrentItem(i); |
112 | return; | 118 | return; |
113 | } | 119 | } |
114 | } | 120 | } |
115 | BUG(); | 121 | BUG(); |
116 | } | 122 | } |
117 | 123 | ||
118 | void AddEntryWndImpl::revealButton_slot() | 124 | void AddEntryWndImpl::revealButton_slot() |
119 | { | 125 | { |
120 | if (revealButton->isOn()) { | 126 | if (revealButton->isOn()) { |
121 | pwLineEdit->setEchoMode(QLineEdit::Normal); | 127 | pwLineEdit->setEchoMode(QLineEdit::Normal); |
122 | } else { | 128 | } else { |
123 | pwLineEdit->setEchoMode(QLineEdit::Password); | 129 | pwLineEdit->setEchoMode(QLineEdit::Password); |
124 | } | 130 | } |
125 | } | 131 | } |
126 | 132 | ||
127 | void AddEntryWndImpl::generateButton_slot() | 133 | void AddEntryWndImpl::generateButton_slot() |
128 | { | 134 | { |
129 | if (!pwGen->exec()) | 135 | if (!pwGen->exec()) |
130 | return; | 136 | return; |
131 | setPassword(pwGen->getPassword()); | 137 | setPassword(pwGen->getPassword()); |
132 | } | 138 | } |
133 | 139 | ||
134 | QString AddEntryWndImpl::getComment() | 140 | QString AddEntryWndImpl::getComment() |
135 | { | 141 | { |
142 | #ifndef PWM_EMBEDDED | ||
136 | if (isAdvancedComment()) { | 143 | if (isAdvancedComment()) { |
137 | return advCommentDta; | 144 | return advCommentDta; |
138 | } | 145 | } |
146 | #endif | ||
139 | return commentTextEdit->text(); | 147 | return commentTextEdit->text(); |
140 | } | 148 | } |
141 | 149 | ||
142 | void AddEntryWndImpl::setComment(const QString &comm) | 150 | void AddEntryWndImpl::setComment(const QString &comm) |
143 | { | 151 | { |
152 | #ifndef PWM_EMBEDDED | ||
144 | if (HtmlGen::isHtml(comm)) { | 153 | if (HtmlGen::isHtml(comm)) { |
145 | advancedCommentButton->setOn(true); | 154 | advancedCommentButton->setOn(true); |
146 | advCommentDta = comm; | 155 | advCommentDta = comm; |
147 | } else { | 156 | } else { |
148 | advancedCommentButton->setOn(false); | 157 | advancedCommentButton->setOn(false); |
149 | commentTextEdit->setText(comm); | 158 | commentTextEdit->setText(comm); |
150 | } | 159 | } |
160 | #else | ||
161 | commentTextEdit->setText(comm); | ||
162 | #endif | ||
151 | } | 163 | } |
152 | 164 | ||
153 | void AddEntryWndImpl::advancedCommentButton_slot(bool on) | 165 | void AddEntryWndImpl::advancedCommentButton_slot(bool on) |
154 | { | 166 | { |
167 | #ifndef PWM_EMBEDDED | ||
155 | switchComment(on); | 168 | switchComment(on); |
169 | #endif | ||
156 | } | 170 | } |
157 | 171 | ||
158 | void AddEntryWndImpl::switchComment(bool toAdvanced) | 172 | void AddEntryWndImpl::switchComment(bool toAdvanced) |
159 | { | 173 | { |
174 | #ifndef PWM_EMBEDDED | ||
175 | |||
160 | useAdvComment = toAdvanced; | 176 | useAdvComment = toAdvanced; |
161 | if (toAdvanced) { | 177 | if (toAdvanced) { |
162 | if (commentTextEdit) { | 178 | if (commentTextEdit) { |
163 | savedCommentText = commentTextEdit->text(); | 179 | savedCommentText = commentTextEdit->text(); |
164 | delete_and_null(commentTextEdit); | 180 | delete_and_null(commentTextEdit); |
165 | } | 181 | } |
166 | if (editAdvCommentButton) | 182 | if (editAdvCommentButton) |
167 | return; | 183 | return; |
168 | editAdvCommentButton = new QPushButton(i18n("Edit advanced comment..."), | 184 | editAdvCommentButton = new QPushButton(i18n("Edit advanced comment..."), |
169 | commentDummy); | 185 | commentDummy); |
170 | editAdvCommentButton->resize(commentDummy->size().width(), 50); | 186 | editAdvCommentButton->resize(commentDummy->size().width(), 50); |
171 | connect(editAdvCommentButton, SIGNAL(clicked()), | 187 | connect(editAdvCommentButton, SIGNAL(clicked()), |
172 | this, SLOT(editAdvCommentButton_slot())); | 188 | this, SLOT(editAdvCommentButton_slot())); |
173 | editAdvCommentButton->show(); | 189 | editAdvCommentButton->show(); |
174 | } else { | 190 | } else { |
175 | delete_ifnot_null(editAdvCommentButton); | 191 | delete_ifnot_null(editAdvCommentButton); |
176 | if (commentTextEdit) | 192 | if (commentTextEdit) |
177 | return; | 193 | return; |
178 | #ifndef PWM_EMBEDDED | 194 | |
179 | commentTextEdit = new QTextEdit(commentDummy); | 195 | commentTextEdit = new QTextEdit(commentDummy); |
180 | commentTextEdit->setTextFormat(Qt::PlainText); | 196 | commentTextEdit->setTextFormat(Qt::PlainText); |
181 | #else | ||
182 | commentTextEdit = new QMultiLineEdit(commentDummy); | ||
183 | #endif | ||
184 | commentTextEdit->resize(commentDummy->size()); | 197 | commentTextEdit->resize(commentDummy->size()); |
185 | commentTextEdit->setText(savedCommentText); | 198 | commentTextEdit->setText(savedCommentText); |
186 | commentTextEdit->show(); | 199 | commentTextEdit->show(); |
187 | } | 200 | } |
201 | #endif | ||
188 | } | 202 | } |
189 | 203 | ||
190 | void AddEntryWndImpl::editAdvCommentButton_slot() | 204 | void AddEntryWndImpl::editAdvCommentButton_slot() |
191 | { | 205 | { |
192 | #ifndef PWM_EMBEDDED | 206 | #ifndef PWM_EMBEDDED |
193 | AdvCommEditImpl editor(this); | 207 | AdvCommEditImpl editor(this); |
194 | editor.setHtmlDta(advCommentDta); | 208 | editor.setHtmlDta(advCommentDta); |
195 | if (editor.exec()) | 209 | if (editor.exec()) |
196 | return; | 210 | return; |
197 | advCommentDta = editor.getHtmlDta(); | 211 | advCommentDta = editor.getHtmlDta(); |
198 | #endif | 212 | #endif |
199 | } | 213 | } |
200 | 214 | ||
201 | #ifndef PWM_EMBEDDED | 215 | #ifndef PWM_EMBEDDED |
202 | #include "addentrywndimpl.moc" | 216 | #include "addentrywndimpl.moc" |
203 | #endif | 217 | #endif |
diff --git a/pwmanager/pwmanager/addentrywndimpl.h b/pwmanager/pwmanager/addentrywndimpl.h index 622e9d2..ce9a594 100644 --- a/pwmanager/pwmanager/addentrywndimpl.h +++ b/pwmanager/pwmanager/addentrywndimpl.h | |||
@@ -1,127 +1,127 @@ | |||
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 __ADDENTRYWNDIMPL_H | 20 | #ifndef __ADDENTRYWNDIMPL_H |
21 | #define __ADDENTRYWNDIMPL_H | 21 | #define __ADDENTRYWNDIMPL_H |
22 | 22 | ||
23 | 23 | ||
24 | #ifndef PWM_EMBEDDED | 24 | #ifndef PWM_EMBEDDED |
25 | #include <qlineedit.h> | 25 | #include <qlineedit.h> |
26 | #include <qtextedit.h> | 26 | #include <qtextedit.h> |
27 | #include <qcombobox.h> | 27 | #include <qcombobox.h> |
28 | #include "addentrywnd.h" | 28 | #include "addentrywnd.h" |
29 | #else | 29 | #else |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <kcombobox.h> | 31 | #include <kcombobox.h> |
32 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
33 | #include "addentrywnd_emb.h" | 33 | #include "addentrywnd_emb.h" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #include <qpushbutton.h> | 36 | #include <qpushbutton.h> |
37 | 37 | ||
38 | class PwGenWndImpl; | 38 | class PwGenWndImpl; |
39 | 39 | ||
40 | /** "add/edit" Window */ | 40 | /** "add/edit" Window */ |
41 | class AddEntryWndImpl : public addEntryWnd | 41 | class AddEntryWndImpl : public addEntryWnd |
42 | { | 42 | { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | public: | 44 | public: |
45 | #ifndef PWM_EMBEDDED | 45 | #ifndef PWM_EMBEDDED |
46 | AddEntryWndImpl(); | 46 | AddEntryWndImpl(); |
47 | #else | 47 | #else |
48 | AddEntryWndImpl( QWidget* parent = 0, const char* name = 0); | 48 | AddEntryWndImpl( QWidget* parent = 0, const char* name = 0); |
49 | #endif | 49 | #endif |
50 | ~AddEntryWndImpl(); | 50 | ~AddEntryWndImpl(); |
51 | 51 | ||
52 | /* get... functions */ | 52 | /* get... functions */ |
53 | QString getDescription() | 53 | QString getDescription() |
54 | { return descLineEdit->text(); } | 54 | { return descLineEdit->text(); } |
55 | QString getCategory() | 55 | QString getCategory() |
56 | { return categoryComboBox->currentText(); } | 56 | { return categoryComboBox->currentText(); } |
57 | QString getUsername() | 57 | QString getUsername() |
58 | { return usernameLineEdit->text(); } | 58 | { return usernameLineEdit->text(); } |
59 | QString getPassword() | 59 | QString getPassword() |
60 | { return pwLineEdit->text(); } | 60 | { return pwLineEdit->text(); } |
61 | QString getUrl() | 61 | QString getUrl() |
62 | { return urlLineEdit->text(); } | 62 | { return urlLineEdit->text(); } |
63 | QString getLauncher() | 63 | QString getLauncher() |
64 | { return launcherLineEdit->text(); } | 64 | { return launcherLineEdit->text(); } |
65 | QString getComment(); | 65 | QString getComment(); |
66 | 66 | ||
67 | /* set... functions */ | 67 | /* set... functions */ |
68 | void setDescription(const QString &desc) | 68 | void setDescription(const QString &desc) |
69 | { descLineEdit->setText(desc); } | 69 | { descLineEdit->setText(desc); } |
70 | void setCurrCategory(const QString &cat); | 70 | void setCurrCategory(const QString &cat); |
71 | void addCategory(const QString &cat) | 71 | void addCategory(const QString &cat) |
72 | { categoryComboBox->insertItem(cat); } | 72 | { categoryComboBox->insertItem(cat); } |
73 | void setUsername(const QString &name) | 73 | void setUsername(const QString &name) |
74 | { usernameLineEdit->setText(name); } | 74 | { usernameLineEdit->setText(name); } |
75 | void setPassword(const QString &pw) | 75 | void setPassword(const QString &pw) |
76 | { pwLineEdit->setText(pw); } | 76 | { pwLineEdit->setText(pw); } |
77 | void setUrl(const QString &url) | 77 | void setUrl(const QString &url) |
78 | { urlLineEdit->setText(url); } | 78 | { urlLineEdit->setText(url); } |
79 | void setLauncher(const QString launcher) | 79 | void setLauncher(const QString launcher) |
80 | { launcherLineEdit->setText(launcher); } | 80 | { launcherLineEdit->setText(launcher); } |
81 | void setComment(const QString &comm); | 81 | void setComment(const QString &comm); |
82 | 82 | ||
83 | /** are we using an advanced comment */ | 83 | /** are we using an advanced comment */ |
84 | bool isAdvancedComment() | 84 | bool isAdvancedComment() |
85 | { return useAdvComment; } | 85 | { return useAdvComment; } |
86 | 86 | ||
87 | public slots: | 87 | public slots: |
88 | #ifndef PWM_EMBEDDED | 88 | #ifndef PWM_EMBEDDED |
89 | //MOC_SKIP_BEGIN | 89 | //MOC_SKIP_BEGIN |
90 | /** OK button pressed */ | 90 | /** OK button pressed */ |
91 | void okButton_slot(); | 91 | void okButton_slot(); |
92 | /** cancel button pressed */ | 92 | /** cancel button pressed */ |
93 | void cancelButton_slot(); | 93 | void cancelButton_slot(); |
94 | //MOC_SKIP_END | 94 | //MOC_SKIP_END |
95 | #else | 95 | #else |
96 | virtual void slotOk(); | 96 | virtual void slotOk(); |
97 | #endif | 97 | #endif |
98 | /** Reveal button pressed */ | 98 | /** Reveal button pressed */ |
99 | void revealButton_slot(); | 99 | void revealButton_slot(); |
100 | /** Generate button pressed */ | 100 | /** Generate button pressed */ |
101 | void generateButton_slot(); | 101 | void generateButton_slot(); |
102 | /** advanced comment button pressed */ | 102 | /** advanced comment button pressed */ |
103 | void advancedCommentButton_slot(bool on); | 103 | void advancedCommentButton_slot(bool on); |
104 | /** edit advanced comment button pressed */ | 104 | /** edit advanced comment button pressed */ |
105 | void editAdvCommentButton_slot(); | 105 | void editAdvCommentButton_slot(); |
106 | 106 | ||
107 | protected: | 107 | protected: |
108 | void switchComment(bool toAdvanced); | 108 | void switchComment(bool toAdvanced); |
109 | 109 | ||
110 | protected: | 110 | protected: |
111 | QPushButton *editAdvCommentButton; | 111 | QPushButton *editAdvCommentButton; |
112 | #ifndef PWM_EMBEDDED | 112 | #ifndef PWM_EMBEDDED |
113 | QTextEdit *commentTextEdit; | 113 | QTextEdit *commentTextEdit; |
114 | #else | 114 | #else |
115 | QMultiLineEdit * commentTextEdit; | 115 | //nothing here |
116 | #endif | 116 | #endif |
117 | /** saved data from normal comment text edit box */ | 117 | /** saved data from normal comment text edit box */ |
118 | QString savedCommentText; | 118 | QString savedCommentText; |
119 | /** use an advanced comment? */ | 119 | /** use an advanced comment? */ |
120 | bool useAdvComment; | 120 | bool useAdvComment; |
121 | /** data of advanced comment (if available) */ | 121 | /** data of advanced comment (if available) */ |
122 | QString advCommentDta; | 122 | QString advCommentDta; |
123 | /** password generation object */ | 123 | /** password generation object */ |
124 | PwGenWndImpl *pwGen; | 124 | PwGenWndImpl *pwGen; |
125 | }; | 125 | }; |
126 | 126 | ||
127 | #endif | 127 | #endif |
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp index 280b139..4a76f36 100644 --- a/pwmanager/pwmanager/commentbox.cpp +++ b/pwmanager/pwmanager/commentbox.cpp | |||
@@ -1,238 +1,281 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "commentbox.h" | 20 | #include "commentbox.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "htmlgen.h" | 22 | #include "htmlgen.h" |
23 | 23 | ||
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | 25 | ||
26 | #ifndef PWM_EMBEDDED | 26 | #ifndef PWM_EMBEDDED |
27 | #include <khtml_part.h> | 27 | #include <khtml_part.h> |
28 | #include <khtmlview.h> | 28 | #include <khtmlview.h> |
29 | #include <qtextedit.h> | 29 | #include <qtextedit.h> |
30 | #else | 30 | #else |
31 | #include <qmultilineedit.h> | 31 | #include <qmultilineedit.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | |||
35 | |||
36 | #ifndef PWM_EMBEDDED | ||
34 | CommentBox::CommentBox(QWidget *_parentWidget) | 37 | CommentBox::CommentBox(QWidget *_parentWidget) |
35 | { | 38 | { |
36 | PWM_ASSERT(_parentWidget); | 39 | PWM_ASSERT(_parentWidget); |
37 | parentWidget = _parentWidget; | 40 | parentWidget = _parentWidget; |
38 | textDta = 0; | 41 | textDta = 0; |
39 | #ifndef PWM_EMBEDDED | ||
40 | htmlDta = 0; | 42 | htmlDta = 0; |
41 | #endif | ||
42 | mode = mode_notSet; | 43 | mode = mode_notSet; |
43 | } | 44 | } |
44 | 45 | ||
45 | CommentBox::~CommentBox() | 46 | CommentBox::~CommentBox() |
46 | { | 47 | { |
47 | clearText(); | 48 | clearText(); |
48 | clearHtml(); | 49 | clearHtml(); |
49 | } | 50 | } |
50 | 51 | ||
51 | void CommentBox::clear() | 52 | void CommentBox::clear() |
52 | { | 53 | { |
53 | clearText(); | 54 | clearText(); |
54 | clearHtml(); | 55 | clearHtml(); |
55 | mode = mode_notSet; | 56 | mode = mode_notSet; |
57 | this->hide(); | ||
56 | } | 58 | } |
57 | 59 | ||
58 | void CommentBox::clearText() | 60 | void CommentBox::clearText() |
59 | { | 61 | { |
60 | delete_ifnot_null(textDta); | 62 | delete_ifnot_null(textDta); |
61 | } | 63 | } |
62 | 64 | ||
63 | void CommentBox::clearHtml() | 65 | void CommentBox::clearHtml() |
64 | { | 66 | { |
65 | #ifndef PWM_EMBEDDED | ||
66 | delete_ifnot_null(htmlDta); | 67 | delete_ifnot_null(htmlDta); |
67 | #endif | ||
68 | } | 68 | } |
69 | 69 | ||
70 | void CommentBox::setText(const QString &text) | 70 | void CommentBox::setText(const QString &text) |
71 | { | 71 | { |
72 | switchTo(mode_text); | 72 | switchTo(mode_text); |
73 | PWM_ASSERT(textDta); | 73 | PWM_ASSERT(textDta); |
74 | textDta->setText(i18n("Comment") + ": " + text); | 74 | textDta->setText(i18n("Comment") + ": " + text); |
75 | if (!textDta->isVisible()) | 75 | if (!textDta->isVisible()) |
76 | textDta->show(); | 76 | textDta->show(); |
77 | } | 77 | } |
78 | 78 | ||
79 | bool CommentBox::getText(QString *text) | 79 | bool CommentBox::getText(QString *text) |
80 | { | 80 | { |
81 | if (mode != mode_text) | 81 | if (mode != mode_text) |
82 | return false; | 82 | return false; |
83 | PWM_ASSERT(text); | 83 | PWM_ASSERT(text); |
84 | if (!textDta) { | 84 | if (!textDta) { |
85 | *text = ""; | 85 | *text = ""; |
86 | return true; | 86 | return true; |
87 | } | 87 | } |
88 | *text = textDta->text(); | 88 | *text = textDta->text(); |
89 | return true; | 89 | return true; |
90 | } | 90 | } |
91 | 91 | ||
92 | void CommentBox::setHtml(QString code) | 92 | void CommentBox::setHtml(QString code) |
93 | { | 93 | { |
94 | #ifndef PWM_EMBEDDED | ||
95 | switchTo(mode_html); | 94 | switchTo(mode_html); |
96 | PWM_ASSERT(htmlDta); | 95 | PWM_ASSERT(htmlDta); |
97 | if (!HtmlGen::replaceSSDummy(&code)) | 96 | if (!HtmlGen::replaceSSDummy(&code)) |
98 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); | 97 | printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); |
99 | htmlDta->begin(); | 98 | htmlDta->begin(); |
100 | htmlDta->write(code); | 99 | htmlDta->write(code); |
101 | htmlDta->end(); | 100 | htmlDta->end(); |
102 | htmlDta->show(); | 101 | htmlDta->show(); |
103 | #endif | ||
104 | } | 102 | } |
105 | 103 | ||
106 | void CommentBox::setContent(const QString &dta) | 104 | void CommentBox::setContent(const QString &dta) |
107 | { | 105 | { |
108 | // if there's no data, hide the comment-box | 106 | // if there's no data, hide the comment-box |
109 | if (dta.isEmpty()) { | 107 | if (dta.isEmpty()) { |
110 | clear(); | 108 | clear(); |
111 | return; | 109 | return; |
112 | } | 110 | } |
113 | #ifndef PWM_EMBEDDED | ||
114 | if (HtmlGen::isHtml(dta)) { | 111 | if (HtmlGen::isHtml(dta)) { |
115 | setHtml(dta); | 112 | setHtml(dta); |
116 | return; | 113 | return; |
117 | } | 114 | } |
118 | #endif | ||
119 | // we assume it's plain text | 115 | // we assume it's plain text |
120 | setText(dta); | 116 | setText(dta); |
121 | } | 117 | } |
122 | 118 | ||
123 | void CommentBox::switchTo(commentBoxMode newMode) | 119 | void CommentBox::switchTo(commentBoxMode newMode) |
124 | { | 120 | { |
125 | if (newMode == mode) | 121 | if (newMode == mode) |
126 | return; | 122 | return; |
127 | 123 | ||
128 | // cleanup old mode | 124 | // cleanup old mode |
129 | switch (mode) { | 125 | switch (mode) { |
130 | case mode_text: | 126 | case mode_text: |
131 | clearText(); | 127 | clearText(); |
132 | break; | 128 | break; |
133 | case mode_html: | 129 | case mode_html: |
134 | clearHtml(); | 130 | clearHtml(); |
135 | break; | 131 | break; |
136 | default: | 132 | default: |
137 | break; | 133 | break; |
138 | } | 134 | } |
139 | 135 | ||
140 | // setup new mode | 136 | // setup new mode |
141 | switch (newMode) { | 137 | switch (newMode) { |
142 | case mode_text: | 138 | case mode_text: |
143 | #ifndef PWM_EMBEDDED | ||
144 | textDta = new QTextEdit(parentWidget); | 139 | textDta = new QTextEdit(parentWidget); |
145 | textDta->setTextFormat(Qt::PlainText); | 140 | textDta->setTextFormat(Qt::PlainText); |
146 | #else | ||
147 | textDta = new QMultiLineEdit(parentWidget); | ||
148 | #endif | ||
149 | textDta->setReadOnly(true); | 141 | textDta->setReadOnly(true); |
150 | textDta->show(); | 142 | textDta->show(); |
151 | break; | 143 | break; |
152 | case mode_html: | 144 | case mode_html: |
153 | #ifndef PWM_EMBEDDED | ||
154 | htmlDta = new KHTMLPart(parentWidget, 0, | 145 | htmlDta = new KHTMLPart(parentWidget, 0, |
155 | parentWidget); | 146 | parentWidget); |
156 | htmlDta->show(); | 147 | htmlDta->show(); |
157 | #endif | ||
158 | break; | 148 | break; |
159 | default: | 149 | default: |
160 | BUG(); | 150 | BUG(); |
161 | break; | 151 | break; |
162 | } | 152 | } |
163 | 153 | ||
164 | mode = newMode; | 154 | mode = newMode; |
165 | } | 155 | } |
166 | 156 | ||
167 | void CommentBox::show() | 157 | void CommentBox::show() |
168 | { | 158 | { |
169 | switch (mode) { | 159 | switch (mode) { |
170 | case mode_text: | 160 | case mode_text: |
171 | PWM_ASSERT(textDta); | 161 | PWM_ASSERT(textDta); |
172 | textDta->show(); | 162 | textDta->show(); |
173 | break; | 163 | break; |
174 | case mode_html: | 164 | case mode_html: |
175 | #ifndef PWM_EMBEDDED | ||
176 | PWM_ASSERT(htmlDta); | 165 | PWM_ASSERT(htmlDta); |
177 | htmlDta->show(); | 166 | htmlDta->show(); |
178 | #endif | ||
179 | break; | 167 | break; |
180 | default: | 168 | default: |
181 | break; | 169 | break; |
182 | } | 170 | } |
171 | |||
183 | } | 172 | } |
184 | 173 | ||
185 | void CommentBox::hide() | 174 | void CommentBox::hide() |
186 | { | 175 | { |
187 | switch (mode) { | 176 | switch (mode) { |
188 | case mode_text: | 177 | case mode_text: |
189 | PWM_ASSERT(textDta); | 178 | PWM_ASSERT(textDta); |
190 | textDta->hide(); | 179 | textDta->hide(); |
191 | break; | 180 | break; |
192 | case mode_html: | 181 | case mode_html: |
193 | #ifndef PWM_EMBEDDED | ||
194 | PWM_ASSERT(htmlDta); | 182 | PWM_ASSERT(htmlDta); |
195 | htmlDta->hide(); | 183 | htmlDta->hide(); |
196 | #endif | ||
197 | break; | 184 | break; |
198 | default: | 185 | default: |
199 | break; | 186 | break; |
200 | } | 187 | } |
201 | } | 188 | } |
202 | 189 | ||
203 | void CommentBox::resize(const QSize &size) | 190 | void CommentBox::resize(const QSize &size) |
204 | { | 191 | { |
205 | switch (mode) { | 192 | switch (mode) { |
206 | case mode_text: | 193 | case mode_text: |
207 | PWM_ASSERT(textDta); | 194 | PWM_ASSERT(textDta); |
208 | textDta->resize(size); | 195 | textDta->resize(size); |
209 | break; | 196 | break; |
210 | case mode_html: | 197 | case mode_html: |
211 | #ifndef PWM_EMBEDDED | ||
212 | PWM_ASSERT(htmlDta); | 198 | PWM_ASSERT(htmlDta); |
213 | htmlDta->view()->resize(size); | 199 | htmlDta->view()->resize(size); |
214 | #endif | ||
215 | break; | 200 | break; |
216 | default: | 201 | default: |
217 | break; | 202 | break; |
218 | } | 203 | } |
204 | |||
219 | } | 205 | } |
220 | 206 | ||
221 | QSize CommentBox::size() | 207 | QSize CommentBox::size() |
222 | { | 208 | { |
223 | switch (mode) { | 209 | switch (mode) { |
224 | case mode_text: | 210 | case mode_text: |
225 | PWM_ASSERT(textDta); | 211 | PWM_ASSERT(textDta); |
226 | return textDta->size(); | 212 | return textDta->size(); |
227 | break; | 213 | break; |
228 | case mode_html: | 214 | case mode_html: |
229 | #ifndef PWM_EMBEDDED | ||
230 | PWM_ASSERT(htmlDta); | 215 | PWM_ASSERT(htmlDta); |
231 | return htmlDta->view()->size(); | 216 | return htmlDta->view()->size(); |
232 | #endif | ||
233 | break; | 217 | break; |
234 | default: | 218 | default: |
235 | break; | 219 | break; |
236 | } | 220 | } |
221 | |||
237 | return QSize(); | 222 | return QSize(); |
238 | } | 223 | } |
224 | |||
225 | |||
226 | //////////////////////////////////////////////////////////////////////// | ||
227 | |||
228 | #else | ||
229 | |||
230 | CommentBox::CommentBox(QWidget *_parentWidget) | ||
231 | : QMultiLineEdit(_parentWidget) | ||
232 | |||
233 | { | ||
234 | this->setReadOnly(true); | ||
235 | } | ||
236 | |||
237 | CommentBox::~CommentBox() | ||
238 | { | ||
239 | } | ||
240 | |||
241 | void CommentBox::clear() | ||
242 | { | ||
243 | this->hide(); | ||
244 | } | ||
245 | |||
246 | |||
247 | void CommentBox::setText(const QString &text) | ||
248 | { | ||
249 | QMultiLineEdit::setText(i18n("Comment") + ": " + text); | ||
250 | if (!this->isVisible()) | ||
251 | this->show(); | ||
252 | } | ||
253 | |||
254 | bool CommentBox::getText(QString *text) | ||
255 | { | ||
256 | *text = this->text(); | ||
257 | return true; | ||
258 | } | ||
259 | |||
260 | void CommentBox::setContent(const QString &dta) | ||
261 | { | ||
262 | // if there's no data, hide the comment-box | ||
263 | if (dta.isEmpty()) { | ||
264 | clear(); | ||
265 | return; | ||
266 | } | ||
267 | |||
268 | // we assume it's plain text | ||
269 | setText(dta); | ||
270 | } | ||
271 | |||
272 | #endif | ||
273 | |||
274 | |||
275 | |||
276 | |||
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
diff --git a/pwmanager/pwmanager/commentbox.h b/pwmanager/pwmanager/commentbox.h index a220acd..352867c 100644 --- a/pwmanager/pwmanager/commentbox.h +++ b/pwmanager/pwmanager/commentbox.h | |||
@@ -1,100 +1,124 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #ifndef COMMENTBOX_H | 20 | #ifndef COMMENTBOX_H |
21 | #define COMMENTBOX_H | 21 | #define COMMENTBOX_H |
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qsize.h> | 24 | #include <qsize.h> |
25 | |||
26 | class QWidget; | 25 | class QWidget; |
27 | class QTextEdit; | 26 | class QTextEdit; |
28 | class QMultiLineEdit; | ||
29 | class KHTMLPart; | 27 | class KHTMLPart; |
30 | 28 | ||
31 | /** Implementation of the advanced HTML comment box */ | 29 | #ifndef PWM_EMBEDDED |
32 | class CommentBox | 30 | |
31 | class CommentBox | ||
33 | { | 32 | { |
34 | protected: | 33 | protected: |
35 | enum commentBoxMode | 34 | enum commentBoxMode |
36 | { | 35 | { |
37 | mode_notSet = 0, | 36 | mode_notSet = 0, |
38 | mode_text, | 37 | mode_text, |
39 | mode_html | 38 | mode_html |
40 | }; | 39 | }; |
41 | 40 | ||
42 | public: | 41 | public: |
43 | CommentBox(QWidget *_parentWidget); | 42 | CommentBox(QWidget *_parentWidget); |
44 | ~CommentBox(); | 43 | ~CommentBox(); |
45 | 44 | ||
46 | /** clear all data in the comment box */ | 45 | /** clear all data in the comment box */ |
47 | void clear(); | 46 | void clear(); |
48 | /** show the comment box */ | 47 | /** show the comment box */ |
49 | void show(); | 48 | void show(); |
50 | /** hide the comment box */ | 49 | /** hide the comment box */ |
51 | void hide(); | 50 | void hide(); |
52 | /** resize the comment box */ | 51 | /** resize the comment box */ |
53 | void resize(const QSize &size); | 52 | void resize(const QSize &size); |
54 | void resize(int w, int h) | 53 | void resize(int w, int h) |
55 | { resize(QSize(w, h)); } | 54 | { resize(QSize(w, h)); } |
56 | /** get the size of the comment box */ | 55 | /** get the size of the comment box */ |
57 | QSize size(); | 56 | QSize size(); |
58 | /** if neccessary switch to text-mode and | 57 | /** if neccessary switch to text-mode and |
59 | * insert this text into the comment box | 58 | * insert this text into the comment box |
60 | */ | 59 | */ |
61 | void setText(const QString &text); | 60 | void setText(const QString &text); |
62 | /** get the text of the comment box. | 61 | /** get the text of the comment box. |
63 | * If it's not in text-mode it returns false | 62 | * If it's not in text-mode it returns false |
64 | */ | 63 | */ |
65 | bool getText(QString *text); | 64 | bool getText(QString *text); |
66 | /** if neccessary switch to HTML-mode and | 65 | /** if neccessary switch to HTML-mode and |
67 | * insert this html code into the comment box | 66 | * insert this html code into the comment box |
68 | */ | 67 | */ |
69 | void setHtml(QString code); | 68 | void setHtml(QString code); |
70 | /** checks "dta" for its type, sets the correct | 69 | /** checks "dta" for its type, sets the correct |
71 | * mode and writes "dta" to the comment box | 70 | * mode and writes "dta" to the comment box |
72 | */ | 71 | */ |
73 | void setContent(const QString &dta); | 72 | void setContent(const QString &dta); |
74 | 73 | ||
75 | protected: | 74 | protected: |
76 | /** switch the current mode */ | 75 | /** switch the current mode */ |
77 | void switchTo(commentBoxMode newMode); | 76 | void switchTo(commentBoxMode newMode); |
78 | /** clear all text data */ | 77 | /** clear all text data */ |
79 | void clearText(); | 78 | void clearText(); |
80 | /** clear all HTML data */ | 79 | /** clear all HTML data */ |
81 | void clearHtml(); | 80 | void clearHtml(); |
82 | 81 | ||
83 | protected: | 82 | protected: |
84 | /** parent widget for this comment box */ | 83 | /** parent widget for this comment box */ |
85 | QWidget *parentWidget; | 84 | QWidget *parentWidget; |
86 | /** current comment box usage type */ | 85 | /** current comment box usage type */ |
87 | commentBoxMode mode; | 86 | commentBoxMode mode; |
88 | #ifndef PWM_EMBEDDED | ||
89 | /** if the comment box is a normal textbox, data is stored here */ | 87 | /** if the comment box is a normal textbox, data is stored here */ |
90 | QTextEdit *textDta; | 88 | QTextEdit *textDta; |
91 | /** if the comment box is a HTML box, data is stored here */ | 89 | /** if the comment box is a HTML box, data is stored here */ |
92 | KHTMLPart *htmlDta; | 90 | KHTMLPart *htmlDta; |
91 | }; | ||
92 | |||
93 | #else | 93 | #else |
94 | /** if the comment box is a normal textbox, data is stored here */ | 94 | #include <qmultilineedit.h> |
95 | QMultiLineEdit *textDta; | 95 | /** Implementation of the advanced HTML comment box */ |
96 | #endif | 96 | //US ENH: CommentBox must be derived from QWidget, to allow the splitter to set a initial size |
97 | // without conflicting with the two display modes | ||
98 | |||
99 | class CommentBox : public QMultiLineEdit | ||
100 | { | ||
101 | public: | ||
102 | CommentBox(QWidget *_parentWidget); | ||
103 | ~CommentBox(); | ||
104 | |||
105 | /** clear all data in the comment box */ | ||
106 | void clear(); | ||
107 | /** if neccessary switch to text-mode and | ||
108 | * insert this text into the comment box | ||
109 | */ | ||
110 | void setText(const QString &text); | ||
111 | /** get the text of the comment box. | ||
112 | * If it's not in text-mode it returns false | ||
113 | */ | ||
114 | bool getText(QString *text); | ||
115 | /** if neccessary switch to HTML-mode and | ||
116 | * insert this html code into the comment box | ||
117 | */ | ||
118 | void setContent(const QString &dta); | ||
97 | 119 | ||
98 | }; | 120 | }; |
121 | #endif | ||
122 | |||
99 | 123 | ||
100 | #endif | 124 | #endif |
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro index 3bcf679..4e482ca 100644 --- a/pwmanager/pwmanager/pwmanagerE.pro +++ b/pwmanager/pwmanager/pwmanagerE.pro | |||
@@ -1,153 +1,154 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | 3 | ||
4 | 4 | ||
5 | TARGET = pwmpi | 5 | TARGET = pwmpi |
6 | OBJECTS_DIR = obj/$(PLATFORM) | 6 | OBJECTS_DIR = obj/$(PLATFORM) |
7 | MOC_DIR = moc/$(PLATFORM) | 7 | MOC_DIR = moc/$(PLATFORM) |
8 | DESTDIR=$(QPEDIR)/bin | 8 | DESTDIR=$(QPEDIR)/bin |
9 | 9 | ||
10 | INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include | 10 | INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../libkdepim ../../microkde ../../microkde/kdecore ../../microkde/kdeui ../../microkde/kutils $(QPEDIR)/include |
11 | DEFINES += PWM_EMBEDDED PWM_DEBUG | 11 | DEFINES += PWM_EMBEDDED CONFIG_DEBUG |
12 | |||
12 | LIBS += -lmicrokde | 13 | LIBS += -lmicrokde |
13 | LIBS += -lmicroqtcompat | 14 | LIBS += -lmicroqtcompat |
14 | LIBS += -lmicrokdepim | 15 | LIBS += -lmicrokdepim |
15 | LIBS += -L$(QPEDIR)/lib | 16 | LIBS += -L$(QPEDIR)/lib |
16 | LIBS += -lqpe | 17 | LIBS += -lqpe |
17 | LIBS += -lbz2 | 18 | LIBS += -lbz2 |
18 | LIBS += $(QTOPIALIB) | 19 | LIBS += $(QTOPIALIB) |
19 | 20 | ||
20 | #INTERFACES = \ | 21 | #INTERFACES = \ |
21 | #addentrywnd.ui \ | 22 | #addentrywnd.ui \ |
22 | #configwnd.ui \ | 23 | #configwnd.ui \ |
23 | #findwnd.ui \ | 24 | #findwnd.ui \ |
24 | #getmasterpwwnd.ui \ | 25 | #getmasterpwwnd.ui \ |
25 | #pwgenwnd.ui \ | 26 | #pwgenwnd.ui \ |
26 | #setmasterpwwnd.ui \ | 27 | #setmasterpwwnd.ui \ |
27 | #subtbledit.ui | 28 | #subtbledit.ui |
28 | 29 | ||
29 | #INTERFACES = \ | 30 | #INTERFACES = \ |
30 | #subtbledit.ui \ | 31 | #subtbledit.ui \ |
31 | 32 | ||
32 | 33 | ||
33 | 34 | ||
34 | #HEADERS = \ | 35 | #HEADERS = \ |
35 | #configuration_31compat.h \ | 36 | #configuration_31compat.h \ |
36 | #configuration.h \ | 37 | #configuration.h \ |
37 | #configwnd.h \ | 38 | #configwnd.h \ |
38 | #configwndimpl.h \ | 39 | #configwndimpl.h \ |
39 | #selftest.h | 40 | #selftest.h |
40 | #subtbledit.h \ | 41 | #subtbledit.h \ |
41 | #subtbleditimpl.h \ | 42 | #subtbleditimpl.h \ |
42 | 43 | ||
43 | HEADERS = \ | 44 | HEADERS = \ |
44 | addentrywnd_emb.h \ | 45 | addentrywnd_emb.h \ |
45 | addentrywndimpl.h \ | 46 | addentrywndimpl.h \ |
46 | base64.h \ | 47 | base64.h \ |
47 | binentrygen.h \ | 48 | binentrygen.h \ |
48 | blowfish.h \ | 49 | blowfish.h \ |
49 | commentbox.h \ | 50 | commentbox.h \ |
50 | compiler.h \ | 51 | compiler.h \ |
51 | compressbzip2.h \ | 52 | compressbzip2.h \ |
52 | compressgzip.h \ | 53 | compressgzip.h \ |
53 | findwnd_emb.h \ | 54 | findwnd_emb.h \ |
54 | findwndimpl.h \ | 55 | findwndimpl.h \ |
55 | genpasswd.h \ | 56 | genpasswd.h \ |
56 | getkeycardwnd.h \ | 57 | getkeycardwnd.h \ |
57 | getmasterpwwnd_emb.h \ | 58 | getmasterpwwnd_emb.h \ |
58 | getmasterpwwndimpl.h \ | 59 | getmasterpwwndimpl.h \ |
59 | globalstuff.h \ | 60 | globalstuff.h \ |
60 | gpasmanfile.h \ | 61 | gpasmanfile.h \ |
61 | htmlgen.h \ | 62 | htmlgen.h \ |
62 | htmlparse.h \ | 63 | htmlparse.h \ |
63 | ipc.h \ | 64 | ipc.h \ |
64 | listobjselectwnd.h \ | 65 | listobjselectwnd.h \ |
65 | listviewpwm.h \ | 66 | listviewpwm.h \ |
66 | printtext.h \ | 67 | printtext.h \ |
67 | pwgenwnd_emb.h \ | 68 | pwgenwnd_emb.h \ |
68 | pwgenwndimpl.h \ | 69 | pwgenwndimpl.h \ |
69 | pwmdoc.h \ | 70 | pwmdoc.h \ |
70 | pwmdocui.h \ | 71 | pwmdocui.h \ |
71 | pwmexception.h \ | 72 | pwmexception.h \ |
72 | pwm.h \ | 73 | pwm.h \ |
73 | pwminit.h \ | 74 | pwminit.h \ |
74 | pwmprefs.h \ | 75 | pwmprefs.h \ |
75 | pwmprint.h \ | 76 | pwmprint.h \ |
76 | pwmtray.h \ | 77 | pwmtray.h \ |
77 | pwmview.h \ | 78 | pwmview.h \ |
78 | pwmviewstyle_0.h \ | 79 | pwmviewstyle_0.h \ |
79 | pwmviewstyle_1.h \ | 80 | pwmviewstyle_1.h \ |
80 | pwmviewstyle.h \ | 81 | pwmviewstyle.h \ |
81 | randomizer.h \ | 82 | randomizer.h \ |
82 | rc2.h \ | 83 | rc2.h \ |
83 | rencatwnd.h \ | 84 | rencatwnd.h \ |
84 | serializer.h \ | 85 | serializer.h \ |
85 | setmasterpwwnd_emb.h \ | 86 | setmasterpwwnd_emb.h \ |
86 | setmasterpwwndimpl.h \ | 87 | setmasterpwwndimpl.h \ |
87 | sha1.h \ | 88 | sha1.h \ |
88 | waitwnd.h \ | 89 | waitwnd.h \ |
89 | kcmconfigs/kcmpwmconfig.h \ | 90 | kcmconfigs/kcmpwmconfig.h \ |
90 | kcmconfigs/pwmconfigwidget.h \ | 91 | kcmconfigs/pwmconfigwidget.h \ |
91 | 92 | ||
92 | #sources that need not be build | 93 | #sources that need not be build |
93 | #SOURCES = \ | 94 | #SOURCES = \ |
94 | #advcommeditimpl.cpp \ | 95 | #advcommeditimpl.cpp \ |
95 | #configuration.cpp \ | 96 | #configuration.cpp \ |
96 | #configwnd.cpp \ | 97 | #configwnd.cpp \ |
97 | #configwndimpl.cpp \ | 98 | #configwndimpl.cpp \ |
98 | #configuration_31compat.cpp \ | 99 | #configuration_31compat.cpp \ |
99 | #htmlparse.cpp \ | 100 | #htmlparse.cpp \ |
100 | #printtext.cpp \ | 101 | #printtext.cpp \ |
101 | #selftest.cpp \ | 102 | #selftest.cpp \ |
102 | #pwmprint.cpp \ | 103 | #pwmprint.cpp \ |
103 | #spinforsignal.cpp | 104 | #spinforsignal.cpp |
104 | #subtbledit.cpp \ | 105 | #subtbledit.cpp \ |
105 | #subtbleditimpl.cpp \ | 106 | #subtbleditimpl.cpp \ |
106 | 107 | ||
107 | SOURCES = \ | 108 | SOURCES = \ |
108 | addentrywnd_emb.cpp \ | 109 | addentrywnd_emb.cpp \ |
109 | addentrywndimpl.cpp \ | 110 | addentrywndimpl.cpp \ |
110 | base64.cpp \ | 111 | base64.cpp \ |
111 | binentrygen.cpp \ | 112 | binentrygen.cpp \ |
112 | blowfish.cpp \ | 113 | blowfish.cpp \ |
113 | commentbox.cpp \ | 114 | commentbox.cpp \ |
114 | compressbzip2.cpp \ | 115 | compressbzip2.cpp \ |
115 | compressgzip.cpp \ | 116 | compressgzip.cpp \ |
116 | findwnd_emb.cpp \ | 117 | findwnd_emb.cpp \ |
117 | findwndimpl.cpp \ | 118 | findwndimpl.cpp \ |
118 | genpasswd.cpp \ | 119 | genpasswd.cpp \ |
119 | getkeycardwnd.cpp \ | 120 | getkeycardwnd.cpp \ |
120 | getmasterpwwnd_emb.cpp \ | 121 | getmasterpwwnd_emb.cpp \ |
121 | getmasterpwwndimpl.cpp \ | 122 | getmasterpwwndimpl.cpp \ |
122 | globalstuff.cpp \ | 123 | globalstuff.cpp \ |
123 | gpasmanfile.cpp \ | 124 | gpasmanfile.cpp \ |
124 | htmlgen.cpp \ | 125 | htmlgen.cpp \ |
125 | ipc.cpp \ | 126 | ipc.cpp \ |
126 | listobjselectwnd.cpp \ | 127 | listobjselectwnd.cpp \ |
127 | listviewpwm.cpp \ | 128 | listviewpwm.cpp \ |
128 | main.cpp \ | 129 | main.cpp \ |
129 | pwgenwnd_emb.cpp \ | 130 | pwgenwnd_emb.cpp \ |
130 | pwgenwndimpl.cpp \ | 131 | pwgenwndimpl.cpp \ |
131 | pwm.cpp \ | 132 | pwm.cpp \ |
132 | pwmdoc.cpp \ | 133 | pwmdoc.cpp \ |
133 | pwmdocui.cpp \ | 134 | pwmdocui.cpp \ |
134 | pwmexception.cpp \ | 135 | pwmexception.cpp \ |
135 | pwminit.cpp \ | 136 | pwminit.cpp \ |
136 | pwmprefs.cpp \ | 137 | pwmprefs.cpp \ |
137 | pwmtray.cpp \ | 138 | pwmtray.cpp \ |
138 | pwmview.cpp \ | 139 | pwmview.cpp \ |
139 | pwmviewstyle_0.cpp \ | 140 | pwmviewstyle_0.cpp \ |
140 | pwmviewstyle_1.cpp \ | 141 | pwmviewstyle_1.cpp \ |
141 | pwmviewstyle.cpp \ | 142 | pwmviewstyle.cpp \ |
142 | randomizer.cpp \ | 143 | randomizer.cpp \ |
143 | rc2.cpp \ | 144 | rc2.cpp \ |
144 | rencatwnd.cpp \ | 145 | rencatwnd.cpp \ |
145 | serializer.cpp \ | 146 | serializer.cpp \ |
146 | setmasterpwwnd_emb.cpp \ | 147 | setmasterpwwnd_emb.cpp \ |
147 | setmasterpwwndimpl.cpp \ | 148 | setmasterpwwndimpl.cpp \ |
148 | sha1.cpp \ | 149 | sha1.cpp \ |
149 | waitwnd.cpp \ | 150 | waitwnd.cpp \ |
150 | kcmconfigs/kcmpwmconfig.cpp \ | 151 | kcmconfigs/kcmpwmconfig.cpp \ |
151 | kcmconfigs/pwmconfigwidget.cpp \ | 152 | kcmconfigs/pwmconfigwidget.cpp \ |
152 | 153 | ||
153 | 154 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index c167c2c..1b6d36f 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,2199 +1,2195 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 2.0 of pwmanager | 14 | * This file is originaly based on version 2.0 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmdoc.h" | 20 | #include "pwmdoc.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "blowfish.h" | 22 | #include "blowfish.h" |
23 | #include "sha1.h" | 23 | #include "sha1.h" |
24 | #include "globalstuff.h" | 24 | #include "globalstuff.h" |
25 | #include "gpasmanfile.h" | 25 | #include "gpasmanfile.h" |
26 | #include "serializer.h" | 26 | #include "serializer.h" |
27 | #include "compressgzip.h" | 27 | #include "compressgzip.h" |
28 | #include "compressbzip2.h" | 28 | #include "compressbzip2.h" |
29 | #include "randomizer.h" | 29 | #include "randomizer.h" |
30 | #include "pwminit.h" | 30 | #include "pwminit.h" |
31 | #ifndef PWM_EMBEDDED | 31 | #ifndef PWM_EMBEDDED |
32 | //US #include "libgryptif.h" | 32 | //US #include "libgryptif.h" |
33 | #else | 33 | #else |
34 | #include "pwmprefs.h" | 34 | #include "pwmprefs.h" |
35 | #include "kglobal.h" | 35 | #include "kglobal.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #ifdef CONFIG_KWALLETIF | 38 | #ifdef CONFIG_KWALLETIF |
39 | # include "kwalletemu.h" | 39 | # include "kwalletemu.h" |
40 | #endif // CONFIG_KWALLETIF | 40 | #endif // CONFIG_KWALLETIF |
41 | 41 | ||
42 | #include <qdatetime.h> | 42 | #include <qdatetime.h> |
43 | #include <qsize.h> | 43 | #include <qsize.h> |
44 | #include <qfileinfo.h> | 44 | #include <qfileinfo.h> |
45 | #include <qfile.h> | 45 | #include <qfile.h> |
46 | 46 | ||
47 | #define __USE_GNU | ||
48 | #define _GNU_SOURCE | ||
49 | #include <stdio.h> | 47 | #include <stdio.h> |
50 | #include <stdlib.h> | 48 | #include <stdlib.h> |
51 | #include <errno.h> | 49 | #include <errno.h> |
52 | #include <string.h> | 50 | #include <string.h> |
53 | //US#include <iostream> | 51 | //US#include <iostream> |
54 | #include <algorithm> | 52 | #include <algorithm> |
55 | #include <sys/types.h> | 53 | #include <sys/types.h> |
56 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
57 | #include <unistd.h> | 55 | #include <unistd.h> |
58 | #include <stdint.h> | 56 | #include <stdint.h> |
59 | 57 | ||
60 | //TODO: reset to its normal value. | 58 | //TODO: reset to its normal value. |
61 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 59 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
62 | 60 | ||
63 | using namespace std; | 61 | using namespace std; |
64 | 62 | ||
65 | 63 | ||
66 | void PwMDocList::add(PwMDoc *doc, const string &id) | 64 | void PwMDocList::add(PwMDoc *doc, const string &id) |
67 | { | 65 | { |
68 | #ifdef PWM_DEBUG | 66 | #ifdef PWM_DEBUG |
69 | // check for existance of object in debug mode only. | 67 | // check for existance of object in debug mode only. |
70 | vector<listItem>::iterator begin = docList.begin(), | 68 | vector<listItem>::iterator begin = docList.begin(), |
71 | end = docList.end(), | 69 | end = docList.end(), |
72 | i = begin; | 70 | i = begin; |
73 | while (i != end) { | 71 | while (i != end) { |
74 | if (i->doc == doc) { | 72 | if (i->doc == doc) { |
75 | BUG(); | 73 | BUG(); |
76 | return; | 74 | return; |
77 | } | 75 | } |
78 | ++i; | 76 | ++i; |
79 | } | 77 | } |
80 | #endif | 78 | #endif |
81 | listItem newItem; | 79 | listItem newItem; |
82 | newItem.doc = doc; | 80 | newItem.doc = doc; |
83 | newItem.docId = id; | 81 | newItem.docId = id; |
84 | docList.push_back(newItem); | 82 | docList.push_back(newItem); |
85 | } | 83 | } |
86 | 84 | ||
87 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 85 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
88 | { | 86 | { |
89 | vector<listItem>::iterator begin = docList.begin(), | 87 | vector<listItem>::iterator begin = docList.begin(), |
90 | end = docList.end(), | 88 | end = docList.end(), |
91 | i = begin; | 89 | i = begin; |
92 | while (i != end) { | 90 | while (i != end) { |
93 | if (i->doc == doc) { | 91 | if (i->doc == doc) { |
94 | i->docId = newId; | 92 | i->docId = newId; |
95 | return; | 93 | return; |
96 | } | 94 | } |
97 | ++i; | 95 | ++i; |
98 | } | 96 | } |
99 | } | 97 | } |
100 | 98 | ||
101 | void PwMDocList::del(PwMDoc *doc) | 99 | void PwMDocList::del(PwMDoc *doc) |
102 | { | 100 | { |
103 | vector<listItem>::iterator begin = docList.begin(), | 101 | vector<listItem>::iterator begin = docList.begin(), |
104 | end = docList.end(), | 102 | end = docList.end(), |
105 | i = begin; | 103 | i = begin; |
106 | while (i != end) { | 104 | while (i != end) { |
107 | if (i->doc == doc) { | 105 | if (i->doc == doc) { |
108 | docList.erase(i); | 106 | docList.erase(i); |
109 | return; | 107 | return; |
110 | } | 108 | } |
111 | ++i; | 109 | ++i; |
112 | } | 110 | } |
113 | } | 111 | } |
114 | 112 | ||
115 | bool PwMDocList::find(const string &id, listItem *ret) | 113 | bool PwMDocList::find(const string &id, listItem *ret) |
116 | { | 114 | { |
117 | vector<listItem>::iterator begin = docList.begin(), | 115 | vector<listItem>::iterator begin = docList.begin(), |
118 | end = docList.end(), | 116 | end = docList.end(), |
119 | i = begin; | 117 | i = begin; |
120 | while (i != end) { | 118 | while (i != end) { |
121 | if (i->docId == id) { | 119 | if (i->docId == id) { |
122 | if (ret) | 120 | if (ret) |
123 | *ret = *i; | 121 | *ret = *i; |
124 | return true; | 122 | return true; |
125 | } | 123 | } |
126 | ++i; | 124 | ++i; |
127 | } | 125 | } |
128 | return false; | 126 | return false; |
129 | } | 127 | } |
130 | 128 | ||
131 | 129 | ||
132 | 130 | ||
133 | DocTimer::DocTimer(PwMDoc *_doc) | 131 | DocTimer::DocTimer(PwMDoc *_doc) |
134 | : doc (_doc) | 132 | : doc (_doc) |
135 | , mpwLock (0) | 133 | , mpwLock (0) |
136 | , autoLockLock (0) | 134 | , autoLockLock (0) |
137 | , metaCheckLock (0) | 135 | , metaCheckLock (0) |
138 | { | 136 | { |
139 | mpwTimer = new QTimer; | 137 | mpwTimer = new QTimer; |
140 | autoLockTimer = new QTimer; | 138 | autoLockTimer = new QTimer; |
141 | metaCheckTimer = new QTimer; | 139 | metaCheckTimer = new QTimer; |
142 | connect(mpwTimer, SIGNAL(timeout()), | 140 | connect(mpwTimer, SIGNAL(timeout()), |
143 | this, SLOT(mpwTimeout())); | 141 | this, SLOT(mpwTimeout())); |
144 | connect(autoLockTimer, SIGNAL(timeout()), | 142 | connect(autoLockTimer, SIGNAL(timeout()), |
145 | this, SLOT(autoLockTimeout())); | 143 | this, SLOT(autoLockTimeout())); |
146 | connect(metaCheckTimer, SIGNAL(timeout()), | 144 | connect(metaCheckTimer, SIGNAL(timeout()), |
147 | this, SLOT(metaCheckTimeout())); | 145 | this, SLOT(metaCheckTimeout())); |
148 | } | 146 | } |
149 | 147 | ||
150 | DocTimer::~DocTimer() | 148 | DocTimer::~DocTimer() |
151 | { | 149 | { |
152 | delete mpwTimer; | 150 | delete mpwTimer; |
153 | delete autoLockTimer; | 151 | delete autoLockTimer; |
154 | delete metaCheckTimer; | 152 | delete metaCheckTimer; |
155 | } | 153 | } |
156 | 154 | ||
157 | void DocTimer::start(TimerIDs timer) | 155 | void DocTimer::start(TimerIDs timer) |
158 | { | 156 | { |
159 | switch (timer) { | 157 | switch (timer) { |
160 | case id_mpwTimer: | 158 | case id_mpwTimer: |
161 | if (mpwTimer->isActive()) | 159 | if (mpwTimer->isActive()) |
162 | mpwTimer->stop(); | 160 | mpwTimer->stop(); |
163 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 161 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
164 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 162 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
165 | break; | 163 | break; |
166 | case id_autoLockTimer: | 164 | case id_autoLockTimer: |
167 | if (autoLockTimer->isActive()) | 165 | if (autoLockTimer->isActive()) |
168 | autoLockTimer->stop(); | 166 | autoLockTimer->stop(); |
169 | if (conf()->confGlobLockTimeout() > 0) | 167 | if (conf()->confGlobLockTimeout() > 0) |
170 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 168 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
171 | break; | 169 | break; |
172 | case id_metaCheckTimer: | 170 | case id_metaCheckTimer: |
173 | if (metaCheckTimer->isActive()) | 171 | if (metaCheckTimer->isActive()) |
174 | metaCheckTimer->stop(); | 172 | metaCheckTimer->stop(); |
175 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 173 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
176 | break; | 174 | break; |
177 | } | 175 | } |
178 | } | 176 | } |
179 | 177 | ||
180 | void DocTimer::stop(TimerIDs timer) | 178 | void DocTimer::stop(TimerIDs timer) |
181 | { | 179 | { |
182 | switch (timer) { | 180 | switch (timer) { |
183 | case id_mpwTimer: | 181 | case id_mpwTimer: |
184 | mpwTimer->stop(); | 182 | mpwTimer->stop(); |
185 | break; | 183 | break; |
186 | case id_autoLockTimer: | 184 | case id_autoLockTimer: |
187 | autoLockTimer->stop(); | 185 | autoLockTimer->stop(); |
188 | break; | 186 | break; |
189 | case id_metaCheckTimer: | 187 | case id_metaCheckTimer: |
190 | metaCheckTimer->stop(); | 188 | metaCheckTimer->stop(); |
191 | break; | 189 | break; |
192 | } | 190 | } |
193 | } | 191 | } |
194 | 192 | ||
195 | void DocTimer::getLock(TimerIDs timer) | 193 | void DocTimer::getLock(TimerIDs timer) |
196 | { | 194 | { |
197 | switch (timer) { | 195 | switch (timer) { |
198 | case id_mpwTimer: | 196 | case id_mpwTimer: |
199 | ++mpwLock; | 197 | ++mpwLock; |
200 | break; | 198 | break; |
201 | case id_autoLockTimer: | 199 | case id_autoLockTimer: |
202 | ++autoLockLock; | 200 | ++autoLockLock; |
203 | break; | 201 | break; |
204 | case id_metaCheckTimer: | 202 | case id_metaCheckTimer: |
205 | ++metaCheckLock; | 203 | ++metaCheckLock; |
206 | break; | 204 | break; |
207 | } | 205 | } |
208 | } | 206 | } |
209 | 207 | ||
210 | void DocTimer::putLock(TimerIDs timer) | 208 | void DocTimer::putLock(TimerIDs timer) |
211 | { | 209 | { |
212 | switch (timer) { | 210 | switch (timer) { |
213 | case id_mpwTimer: | 211 | case id_mpwTimer: |
214 | if (mpwLock) | 212 | if (mpwLock) |
215 | --mpwLock; | 213 | --mpwLock; |
216 | break; | 214 | break; |
217 | case id_autoLockTimer: | 215 | case id_autoLockTimer: |
218 | if (autoLockLock) | 216 | if (autoLockLock) |
219 | --autoLockLock; | 217 | --autoLockLock; |
220 | break; | 218 | break; |
221 | case id_metaCheckTimer: | 219 | case id_metaCheckTimer: |
222 | if (metaCheckLock) | 220 | if (metaCheckLock) |
223 | --metaCheckLock; | 221 | --metaCheckLock; |
224 | break; | 222 | break; |
225 | } | 223 | } |
226 | } | 224 | } |
227 | 225 | ||
228 | void DocTimer::mpwTimeout() | 226 | void DocTimer::mpwTimeout() |
229 | { | 227 | { |
230 | if (mpwLock) { | 228 | if (mpwLock) { |
231 | mpwTimer->start(1000, true); | 229 | mpwTimer->start(1000, true); |
232 | return; | 230 | return; |
233 | } | 231 | } |
234 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 232 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
235 | } | 233 | } |
236 | 234 | ||
237 | void DocTimer::autoLockTimeout() | 235 | void DocTimer::autoLockTimeout() |
238 | { | 236 | { |
239 | if (autoLockLock) { | 237 | if (autoLockLock) { |
240 | autoLockTimer->start(1000, true); | 238 | autoLockTimer->start(1000, true); |
241 | return; | 239 | return; |
242 | } | 240 | } |
243 | if (conf()->confGlobAutoDeepLock() && | 241 | if (conf()->confGlobAutoDeepLock() && |
244 | doc->filename != QString::null && | 242 | doc->filename != QString::null && |
245 | doc->filename != "") { | 243 | doc->filename != "") { |
246 | doc->deepLock(true); | 244 | doc->deepLock(true); |
247 | } else { | 245 | } else { |
248 | doc->lockAll(true); | 246 | doc->lockAll(true); |
249 | } | 247 | } |
250 | } | 248 | } |
251 | 249 | ||
252 | void DocTimer::metaCheckTimeout() | 250 | void DocTimer::metaCheckTimeout() |
253 | { | 251 | { |
254 | if (metaCheckLock) { | 252 | if (metaCheckLock) { |
255 | // check again in one second. | 253 | // check again in one second. |
256 | metaCheckTimer->start(1000, true); | 254 | metaCheckTimer->start(1000, true); |
257 | return; | 255 | return; |
258 | } | 256 | } |
259 | if (doc->isDeepLocked()) { | 257 | if (doc->isDeepLocked()) { |
260 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 258 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
261 | return; | 259 | return; |
262 | } | 260 | } |
263 | if (doc->isDocEmpty()) { | 261 | if (doc->isDocEmpty()) { |
264 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 262 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
265 | return; | 263 | return; |
266 | } | 264 | } |
267 | #ifdef CONFIG_KWALLETIF | 265 | #ifdef CONFIG_KWALLETIF |
268 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 266 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
269 | if (kwlEmu) | 267 | if (kwlEmu) |
270 | kwlEmu->suspendDocSignals(); | 268 | kwlEmu->suspendDocSignals(); |
271 | #endif // CONFIG_KWALLETIF | 269 | #endif // CONFIG_KWALLETIF |
272 | /* We simply trigger all views to update their | 270 | /* We simply trigger all views to update their |
273 | * displayed values. This way they have a chance | 271 | * displayed values. This way they have a chance |
274 | * to get notified when some meta changes over time. | 272 | * to get notified when some meta changes over time. |
275 | * (for example an entry expired). | 273 | * (for example an entry expired). |
276 | * The _view_ is responsive for not updating its | 274 | * The _view_ is responsive for not updating its |
277 | * contents if nothing really changed! | 275 | * contents if nothing really changed! |
278 | */ | 276 | */ |
279 | emit doc->dataChanged(doc); | 277 | emit doc->dataChanged(doc); |
280 | #ifdef CONFIG_KWALLETIF | 278 | #ifdef CONFIG_KWALLETIF |
281 | if (kwlEmu) | 279 | if (kwlEmu) |
282 | kwlEmu->resumeDocSignals(); | 280 | kwlEmu->resumeDocSignals(); |
283 | #endif // CONFIG_KWALLETIF | 281 | #endif // CONFIG_KWALLETIF |
284 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 282 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
285 | } | 283 | } |
286 | 284 | ||
287 | 285 | ||
288 | 286 | ||
289 | PwMDocList PwMDoc::openDocList; | 287 | PwMDocList PwMDoc::openDocList; |
290 | unsigned int PwMDocList::unnamedDocCnt = 1; | 288 | unsigned int PwMDocList::unnamedDocCnt = 1; |
291 | 289 | ||
292 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 290 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
293 | : PwMDocUi(parent, name) | 291 | : PwMDocUi(parent, name) |
294 | , dataChangedLock (0) | 292 | , dataChangedLock (0) |
295 | { | 293 | { |
296 | deleted = false; | 294 | deleted = false; |
297 | unnamedNum = 0; | 295 | unnamedNum = 0; |
298 | getOpenDocList()->add(this, getTitle().latin1()); | 296 | getOpenDocList()->add(this, getTitle().latin1()); |
299 | curDocStat = 0; | 297 | curDocStat = 0; |
300 | setMaxNumEntries(); | 298 | setMaxNumEntries(); |
301 | _timer = new DocTimer(this); | 299 | _timer = new DocTimer(this); |
302 | timer()->start(DocTimer::id_mpwTimer); | 300 | timer()->start(DocTimer::id_mpwTimer); |
303 | timer()->start(DocTimer::id_autoLockTimer); | 301 | timer()->start(DocTimer::id_autoLockTimer); |
304 | timer()->start(DocTimer::id_metaCheckTimer); | 302 | timer()->start(DocTimer::id_metaCheckTimer); |
305 | addCategory(DEFAULT_CATEGORY, 0, false); | 303 | addCategory(DEFAULT_CATEGORY, 0, false); |
306 | listView = 0; | 304 | listView = 0; |
307 | emit docCreated(this); | 305 | emit docCreated(this); |
308 | } | 306 | } |
309 | 307 | ||
310 | PwMDoc::~PwMDoc() | 308 | PwMDoc::~PwMDoc() |
311 | { | 309 | { |
312 | emit docClosed(this); | 310 | emit docClosed(this); |
313 | getOpenDocList()->del(this); | 311 | getOpenDocList()->del(this); |
314 | delete _timer; | 312 | delete _timer; |
315 | } | 313 | } |
316 | 314 | ||
317 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 315 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
318 | { | 316 | { |
319 | PwMerror ret, e; | 317 | PwMerror ret, e; |
320 | if (!file) { | 318 | if (!file) { |
321 | if (filename == "") | 319 | if (filename == "") |
322 | return e_filename; | 320 | return e_filename; |
323 | } else { | 321 | } else { |
324 | if (*file == "" && filename == "") | 322 | if (*file == "" && filename == "") |
325 | return e_filename; | 323 | return e_filename; |
326 | if (*file != "") | 324 | if (*file != "") |
327 | filename = *file; | 325 | filename = *file; |
328 | } | 326 | } |
329 | 327 | ||
330 | bool wasDeepLocked = isDeepLocked(); | 328 | bool wasDeepLocked = isDeepLocked(); |
331 | if (wasDeepLocked) { | 329 | if (wasDeepLocked) { |
332 | if (deepLock(false) != e_success) | 330 | if (deepLock(false) != e_success) |
333 | return e_noPw; | 331 | return e_noPw; |
334 | } | 332 | } |
335 | 333 | ||
336 | if (!isPwAvailable()) { | 334 | if (!isPwAvailable()) { |
337 | /* password is not available. This means, the | 335 | /* password is not available. This means, the |
338 | * document wasn't saved, yet. | 336 | * document wasn't saved, yet. |
339 | */ | 337 | */ |
340 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 338 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
341 | QString pw(requestNewMpw(&useChipcard)); | 339 | QString pw(requestNewMpw(&useChipcard)); |
342 | if (pw != "") { | 340 | if (pw != "") { |
343 | currentPw = pw; | 341 | currentPw = pw; |
344 | } else { | 342 | } else { |
345 | return e_noPw; | 343 | return e_noPw; |
346 | } | 344 | } |
347 | if (useChipcard) { | 345 | if (useChipcard) { |
348 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 346 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
349 | } else { | 347 | } else { |
350 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 348 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
351 | } | 349 | } |
352 | } | 350 | } |
353 | #ifndef PWM_EMBEDDED | 351 | #ifndef PWM_EMBEDDED |
354 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 352 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
355 | int _hashAlgo = conf()->confGlobHashAlgo(); | 353 | int _hashAlgo = conf()->confGlobHashAlgo(); |
356 | #else | 354 | #else |
357 | int _cryptAlgo = PWM_CRYPT_BLOWFISH; | 355 | int _cryptAlgo = PWM_CRYPT_BLOWFISH; |
358 | int _hashAlgo = PWM_HASH_SHA1; | 356 | int _hashAlgo = PWM_HASH_SHA1; |
359 | #endif | 357 | #endif |
360 | 358 | ||
361 | // sanity check for the selected algorithms | 359 | // sanity check for the selected algorithms |
362 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 360 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
363 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 361 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
364 | printWarn("Invalid Crypto-Algorithm selected! " | 362 | printWarn("Invalid Crypto-Algorithm selected! " |
365 | "Config-file seems to be corrupt. " | 363 | "Config-file seems to be corrupt. " |
366 | "Falling back to Blowfish."); | 364 | "Falling back to Blowfish."); |
367 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 365 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
368 | } | 366 | } |
369 | if (_hashAlgo < PWM_HASH_SHA1 || | 367 | if (_hashAlgo < PWM_HASH_SHA1 || |
370 | _hashAlgo > PWM_HASH_TIGER) { | 368 | _hashAlgo > PWM_HASH_TIGER) { |
371 | printWarn("Invalid Hash-Algorithm selected! " | 369 | printWarn("Invalid Hash-Algorithm selected! " |
372 | "Config-file seems to be corrupt. " | 370 | "Config-file seems to be corrupt. " |
373 | "Falling back to SHA1."); | 371 | "Falling back to SHA1."); |
374 | _hashAlgo = PWM_HASH_SHA1; | 372 | _hashAlgo = PWM_HASH_SHA1; |
375 | } | 373 | } |
376 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 374 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
377 | char hashAlgo = static_cast<char>(_hashAlgo); | 375 | char hashAlgo = static_cast<char>(_hashAlgo); |
378 | 376 | ||
379 | if (conf()->confGlobMakeFileBackup()) { | 377 | if (conf()->confGlobMakeFileBackup()) { |
380 | if (!backupFile(filename)) | 378 | if (!backupFile(filename)) |
381 | return e_fileBackup; | 379 | return e_fileBackup; |
382 | } | 380 | } |
383 | QString tmpFileMoved(QString::null); | 381 | QString tmpFileMoved(QString::null); |
384 | if (QFile::exists(filename)) { | 382 | if (QFile::exists(filename)) { |
385 | /* Move the existing file to some tmp file. | 383 | /* Move the existing file to some tmp file. |
386 | * When saving file succeeds, delete tmp file. Otherwise | 384 | * When saving file succeeds, delete tmp file. Otherwise |
387 | * move tmp file back. See below. | 385 | * move tmp file back. See below. |
388 | */ | 386 | */ |
389 | Randomizer *rnd = Randomizer::obj(); | 387 | Randomizer *rnd = Randomizer::obj(); |
390 | char rnd_buf[5]; | 388 | char rnd_buf[5]; |
391 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, | 389 | sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF, |
392 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 390 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
393 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 391 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
394 | if (!copyFile(filename, tmpFileMoved)) | 392 | if (!copyFile(filename, tmpFileMoved)) |
395 | return e_openFile; | 393 | return e_openFile; |
396 | if (!QFile::remove(filename)) { | 394 | if (!QFile::remove(filename)) { |
397 | printWarn(string("removing orig file ") | 395 | printWarn(string("removing orig file ") |
398 | + filename.latin1() | 396 | + filename.latin1() |
399 | + " failed!"); | 397 | + " failed!"); |
400 | } | 398 | } |
401 | } | 399 | } |
402 | QFile f(filename); | 400 | QFile f(filename); |
403 | string serialized; | 401 | string serialized; |
404 | if (!f.open(IO_ReadWrite)) { | 402 | if (!f.open(IO_ReadWrite)) { |
405 | ret = e_openFile; | 403 | ret = e_openFile; |
406 | goto out_moveback; | 404 | goto out_moveback; |
407 | } | 405 | } |
408 | e = writeFileHeader(hashAlgo, hashAlgo, | 406 | e = writeFileHeader(hashAlgo, hashAlgo, |
409 | cryptAlgo, compress, | 407 | cryptAlgo, compress, |
410 | ¤tPw, &f); | 408 | ¤tPw, &f); |
411 | if (e == e_hashNotImpl) { | 409 | if (e == e_hashNotImpl) { |
412 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 410 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
413 | f.close(); | 411 | f.close(); |
414 | ret = e_hashNotImpl; | 412 | ret = e_hashNotImpl; |
415 | goto out_moveback; | 413 | goto out_moveback; |
416 | } else if (e != e_success) { | 414 | } else if (e != e_success) { |
417 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 415 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
418 | f.close(); | 416 | f.close(); |
419 | ret = e_writeHeader; | 417 | ret = e_writeHeader; |
420 | goto out_moveback; | 418 | goto out_moveback; |
421 | } | 419 | } |
422 | if (!serializeDta(&serialized)) { | 420 | if (!serializeDta(&serialized)) { |
423 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 421 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
424 | f.close(); | 422 | f.close(); |
425 | ret = e_serializeDta; | 423 | ret = e_serializeDta; |
426 | goto out_moveback; | 424 | goto out_moveback; |
427 | } | 425 | } |
428 | e = writeDataHash(hashAlgo, &serialized, &f); | 426 | e = writeDataHash(hashAlgo, &serialized, &f); |
429 | if (e == e_hashNotImpl) { | 427 | if (e == e_hashNotImpl) { |
430 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 428 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
431 | f.close(); | 429 | f.close(); |
432 | ret = e_hashNotImpl; | 430 | ret = e_hashNotImpl; |
433 | goto out_moveback; | 431 | goto out_moveback; |
434 | } else if (e != e_success) { | 432 | } else if (e != e_success) { |
435 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 433 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
436 | f.close(); | 434 | f.close(); |
437 | ret = e_writeHeader; | 435 | ret = e_writeHeader; |
438 | goto out_moveback; | 436 | goto out_moveback; |
439 | } | 437 | } |
440 | if (!compressDta(&serialized, compress)) { | 438 | if (!compressDta(&serialized, compress)) { |
441 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 439 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
442 | f.close(); | 440 | f.close(); |
443 | ret = e_enc; | 441 | ret = e_enc; |
444 | goto out_moveback; | 442 | goto out_moveback; |
445 | } | 443 | } |
446 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); | 444 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); |
447 | if (e == e_weakPw) { | 445 | if (e == e_weakPw) { |
448 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 446 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
449 | f.close(); | 447 | f.close(); |
450 | ret = e_weakPw; | 448 | ret = e_weakPw; |
451 | goto out_moveback; | 449 | goto out_moveback; |
452 | } else if (e == e_cryptNotImpl) { | 450 | } else if (e == e_cryptNotImpl) { |
453 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 451 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
454 | f.close(); | 452 | f.close(); |
455 | ret = e_cryptNotImpl; | 453 | ret = e_cryptNotImpl; |
456 | goto out_moveback; | 454 | goto out_moveback; |
457 | } else if (e != e_success) { | 455 | } else if (e != e_success) { |
458 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 456 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
459 | f.close(); | 457 | f.close(); |
460 | ret = e_enc; | 458 | ret = e_enc; |
461 | goto out_moveback; | 459 | goto out_moveback; |
462 | } | 460 | } |
463 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 461 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
464 | f.close(); | 462 | f.close(); |
465 | if (chmod(filename.latin1(), | 463 | if (chmod(filename.latin1(), |
466 | conf()->confGlobFilePermissions())) { | 464 | conf()->confGlobFilePermissions())) { |
467 | printWarn(string("chmod failed: ") + strerror(errno)); | 465 | printWarn(string("chmod failed: ") + strerror(errno)); |
468 | } | 466 | } |
469 | openDocList.edit(this, getTitle().latin1()); | 467 | openDocList.edit(this, getTitle().latin1()); |
470 | if (wasDeepLocked) | 468 | if (wasDeepLocked) |
471 | deepLock(true); | 469 | deepLock(true); |
472 | if (tmpFileMoved != QString::null) { | 470 | if (tmpFileMoved != QString::null) { |
473 | // now remove the moved file. | 471 | // now remove the moved file. |
474 | if (!QFile::remove(tmpFileMoved)) { | 472 | if (!QFile::remove(tmpFileMoved)) { |
475 | printWarn(string("removing file ") | 473 | printWarn(string("removing file ") |
476 | + tmpFileMoved.latin1() | 474 | + tmpFileMoved.latin1() |
477 | + " failed!"); | 475 | + " failed!"); |
478 | } | 476 | } |
479 | } | 477 | } |
480 | ret = e_success; | 478 | ret = e_success; |
481 | printDebug(string("writing file { compress: ") | 479 | printDebug(string("writing file { compress: ") |
482 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 480 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
483 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 481 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
484 | + tostr(static_cast<int>(hashAlgo)) | 482 | + tostr(static_cast<int>(hashAlgo)) |
485 | + " }"); | 483 | + " }"); |
486 | goto out; | 484 | goto out; |
487 | out_moveback: | 485 | out_moveback: |
488 | if (tmpFileMoved != QString::null) { | 486 | if (tmpFileMoved != QString::null) { |
489 | if (copyFile(tmpFileMoved, filename)) { | 487 | if (copyFile(tmpFileMoved, filename)) { |
490 | if (!QFile::remove(tmpFileMoved)) { | 488 | if (!QFile::remove(tmpFileMoved)) { |
491 | printWarn(string("removing tmp file ") | 489 | printWarn(string("removing tmp file ") |
492 | + filename.latin1() | 490 | + filename.latin1() |
493 | + " failed!"); | 491 | + " failed!"); |
494 | } | 492 | } |
495 | } else { | 493 | } else { |
496 | printWarn(string("couldn't copy file ") | 494 | printWarn(string("couldn't copy file ") |
497 | + tmpFileMoved.latin1() | 495 | + tmpFileMoved.latin1() |
498 | + " back to " | 496 | + " back to " |
499 | + filename.latin1()); | 497 | + filename.latin1()); |
500 | } | 498 | } |
501 | } | 499 | } |
502 | out: | 500 | out: |
503 | return ret; | 501 | return ret; |
504 | } | 502 | } |
505 | 503 | ||
506 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 504 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
507 | { | 505 | { |
508 | PWM_ASSERT(file); | 506 | PWM_ASSERT(file); |
509 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 507 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
510 | string decrypted, dataHash; | 508 | string decrypted, dataHash; |
511 | PwMerror ret; | 509 | PwMerror ret; |
512 | char cryptAlgo, dataHashType, compress; | 510 | char cryptAlgo, dataHashType, compress; |
513 | unsigned int headerLen; | 511 | unsigned int headerLen; |
514 | 512 | ||
515 | if (*file == "") | 513 | if (*file == "") |
516 | return e_readFile; | 514 | return e_readFile; |
517 | filename = *file; | 515 | filename = *file; |
518 | /* check if this file is already open. | 516 | /* check if this file is already open. |
519 | * This does not catch symlinks! | 517 | * This does not catch symlinks! |
520 | */ | 518 | */ |
521 | if (!isDeepLocked()) { | 519 | if (!isDeepLocked()) { |
522 | if (getOpenDocList()->find(filename.latin1())) | 520 | if (getOpenDocList()->find(filename.latin1())) |
523 | return e_alreadyOpen; | 521 | return e_alreadyOpen; |
524 | } | 522 | } |
525 | QFile f(filename); | 523 | QFile f(filename); |
526 | 524 | ||
527 | if (openLocked == 2) { | 525 | if (openLocked == 2) { |
528 | // open deep-locked | 526 | // open deep-locked |
529 | if (!QFile::exists(filename)) | 527 | if (!QFile::exists(filename)) |
530 | return e_openFile; | 528 | return e_openFile; |
531 | if (deepLock(true, false) != e_success) | 529 | if (deepLock(true, false) != e_success) |
532 | return e_openFile; | 530 | return e_openFile; |
533 | goto out_success; | 531 | goto out_success; |
534 | } | 532 | } |
535 | 533 | ||
536 | if (!f.open(IO_ReadOnly)) | 534 | if (!f.open(IO_ReadOnly)) |
537 | return e_openFile; | 535 | return e_openFile; |
538 | 536 | ||
539 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 537 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
540 | &dataHashType, &dataHash, &f); | 538 | &dataHashType, &dataHash, &f); |
541 | if (ret != e_success) { | 539 | if (ret != e_success) { |
542 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 540 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
543 | f.close(); | 541 | f.close(); |
544 | if (ret == e_wrongPw) { | 542 | if (ret == e_wrongPw) { |
545 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 543 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
546 | return ret; | 544 | return ret; |
547 | } else if (ret == e_noPw || | 545 | } else if (ret == e_noPw || |
548 | ret == e_fileVer || | 546 | ret == e_fileVer || |
549 | ret == e_fileFormat || | 547 | ret == e_fileFormat || |
550 | ret == e_hashNotImpl) { | 548 | ret == e_hashNotImpl) { |
551 | return ret; | 549 | return ret; |
552 | } else | 550 | } else |
553 | return e_readFile; | 551 | return e_readFile; |
554 | } | 552 | } |
555 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 553 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
556 | if (ret == e_cryptNotImpl) { | 554 | if (ret == e_cryptNotImpl) { |
557 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 555 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
558 | f.close(); | 556 | f.close(); |
559 | return e_cryptNotImpl; | 557 | return e_cryptNotImpl; |
560 | } else if (ret != e_success) { | 558 | } else if (ret != e_success) { |
561 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 559 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
562 | f.close(); | 560 | f.close(); |
563 | return e_readFile; | 561 | return e_readFile; |
564 | } | 562 | } |
565 | if (!decompressDta(&decrypted, compress)) { | 563 | if (!decompressDta(&decrypted, compress)) { |
566 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 564 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
567 | f.close(); | 565 | f.close(); |
568 | return e_fileCorrupt; | 566 | return e_fileCorrupt; |
569 | } | 567 | } |
570 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 568 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
571 | if (ret == e_hashNotImpl) { | 569 | if (ret == e_hashNotImpl) { |
572 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 570 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
573 | f.close(); | 571 | f.close(); |
574 | return e_hashNotImpl; | 572 | return e_hashNotImpl; |
575 | } else if (ret != e_success) { | 573 | } else if (ret != e_success) { |
576 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 574 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
577 | f.close(); | 575 | f.close(); |
578 | return e_fileCorrupt; | 576 | return e_fileCorrupt; |
579 | } | 577 | } |
580 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 578 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
581 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 579 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
582 | f.close(); | 580 | f.close(); |
583 | return e_readFile; | 581 | return e_readFile; |
584 | } | 582 | } |
585 | f.close(); | 583 | f.close(); |
586 | timer()->start(DocTimer::id_mpwTimer); | 584 | timer()->start(DocTimer::id_mpwTimer); |
587 | timer()->start(DocTimer::id_autoLockTimer); | 585 | timer()->start(DocTimer::id_autoLockTimer); |
588 | out_success: | 586 | out_success: |
589 | openDocList.edit(this, getTitle().latin1()); | 587 | openDocList.edit(this, getTitle().latin1()); |
590 | emit docOpened(this); | 588 | emit docOpened(this); |
591 | return e_success; | 589 | return e_success; |
592 | } | 590 | } |
593 | 591 | ||
594 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 592 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
595 | QString *pw, QFile *f) | 593 | QString *pw, QFile *f) |
596 | { | 594 | { |
597 | PWM_ASSERT(pw); | 595 | PWM_ASSERT(pw); |
598 | PWM_ASSERT(f); | 596 | PWM_ASSERT(f); |
599 | PWM_ASSERT(listView); | 597 | PWM_ASSERT(listView); |
600 | #ifndef PWM_EMBEDDED | 598 | #ifndef PWM_EMBEDDED |
601 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 599 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
602 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 600 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
603 | return e_writeFile; | 601 | return e_writeFile; |
604 | } | 602 | } |
605 | if (f->putch(PWM_FILE_VER) == -1 || | 603 | if (f->putch(PWM_FILE_VER) == -1 || |
606 | f->putch(keyHash) == -1 || | 604 | f->putch(keyHash) == -1 || |
607 | f->putch(dataHash) == -1 || | 605 | f->putch(dataHash) == -1 || |
608 | f->putch(crypt) == -1 || | 606 | f->putch(crypt) == -1 || |
609 | f->putch(compress) == -1 || | 607 | f->putch(compress) == -1 || |
610 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 608 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
611 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 609 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
612 | return e_writeFile; | 610 | return e_writeFile; |
613 | } | 611 | } |
614 | 612 | ||
615 | #else | 613 | #else |
616 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 614 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
617 | (long)(strlen(FILE_ID_HEADER))) { | 615 | (long)(strlen(FILE_ID_HEADER))) { |
618 | return e_writeFile; | 616 | return e_writeFile; |
619 | } | 617 | } |
620 | if (f->putch(PWM_FILE_VER) == -1 || | 618 | if (f->putch(PWM_FILE_VER) == -1 || |
621 | f->putch(keyHash) == -1 || | 619 | f->putch(keyHash) == -1 || |
622 | f->putch(dataHash) == -1 || | 620 | f->putch(dataHash) == -1 || |
623 | f->putch(crypt) == -1 || | 621 | f->putch(crypt) == -1 || |
624 | f->putch(compress) == -1 || | 622 | f->putch(compress) == -1 || |
625 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 623 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
626 | ((char)(0x01)) : ((char)(0x00))) == -1) { | 624 | ((char)(0x01)) : ((char)(0x00))) == -1) { |
627 | return e_writeFile; | 625 | return e_writeFile; |
628 | } | 626 | } |
629 | #endif | 627 | #endif |
630 | // write bytes of NUL-data. These bytes are reserved for future-use. | 628 | // write bytes of NUL-data. These bytes are reserved for future-use. |
631 | const int bufSize = 64; | 629 | const int bufSize = 64; |
632 | char tmp_buf[bufSize]; | 630 | char tmp_buf[bufSize]; |
633 | memset(tmp_buf, 0x00, bufSize); | 631 | memset(tmp_buf, 0x00, bufSize); |
634 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 632 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
635 | return e_writeFile; | 633 | return e_writeFile; |
636 | 634 | ||
637 | switch (keyHash) { | 635 | switch (keyHash) { |
638 | case PWM_HASH_SHA1: { | 636 | case PWM_HASH_SHA1: { |
639 | const int hashlen = SHA1_HASH_LEN_BYTE; | 637 | const int hashlen = SHA1_HASH_LEN_BYTE; |
640 | Sha1 hash; | 638 | Sha1 hash; |
641 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 639 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
642 | string ret = hash.sha1_read(); | 640 | string ret = hash.sha1_read(); |
643 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 641 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
644 | return e_writeFile; | 642 | return e_writeFile; |
645 | break; | 643 | break; |
646 | } | 644 | } |
647 | #ifndef PWM_EMBEDDED | 645 | #ifndef PWM_EMBEDDED |
648 | case PWM_HASH_SHA256: | 646 | case PWM_HASH_SHA256: |
649 | /*... fall through */ | 647 | /*... fall through */ |
650 | case PWM_HASH_SHA384: | 648 | case PWM_HASH_SHA384: |
651 | case PWM_HASH_SHA512: | 649 | case PWM_HASH_SHA512: |
652 | case PWM_HASH_MD5: | 650 | case PWM_HASH_MD5: |
653 | case PWM_HASH_RMD160: | 651 | case PWM_HASH_RMD160: |
654 | case PWM_HASH_TIGER: | 652 | case PWM_HASH_TIGER: |
655 | { | 653 | { |
656 | if (!LibGCryptIf::available()) | 654 | if (!LibGCryptIf::available()) |
657 | return e_hashNotImpl; | 655 | return e_hashNotImpl; |
658 | LibGCryptIf gc; | 656 | LibGCryptIf gc; |
659 | PwMerror err; | 657 | PwMerror err; |
660 | unsigned char *buf; | 658 | unsigned char *buf; |
661 | size_t hashLen; | 659 | size_t hashLen; |
662 | err = gc.hash(&buf, | 660 | err = gc.hash(&buf, |
663 | &hashLen, | 661 | &hashLen, |
664 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 662 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
665 | pw->length(), | 663 | pw->length(), |
666 | keyHash); | 664 | keyHash); |
667 | if (err != e_success) | 665 | if (err != e_success) |
668 | return e_hashNotImpl; | 666 | return e_hashNotImpl; |
669 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 667 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
670 | != static_cast<Q_LONG>(hashLen)) { | 668 | != static_cast<Q_LONG>(hashLen)) { |
671 | delete [] buf; | 669 | delete [] buf; |
672 | return e_hashNotImpl; | 670 | return e_hashNotImpl; |
673 | } | 671 | } |
674 | delete [] buf; | 672 | delete [] buf; |
675 | break; | 673 | break; |
676 | } | 674 | } |
677 | #endif | 675 | #endif |
678 | default: { | 676 | default: { |
679 | return e_hashNotImpl; | 677 | return e_hashNotImpl; |
680 | } } | 678 | } } |
681 | return e_success; | 679 | return e_success; |
682 | } | 680 | } |
683 | 681 | ||
684 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 682 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
685 | unsigned int *headerLength, char *dataHashType, | 683 | unsigned int *headerLength, char *dataHashType, |
686 | string *dataHash, QFile *f) | 684 | string *dataHash, QFile *f) |
687 | { | 685 | { |
688 | PWM_ASSERT(cryptAlgo); | 686 | PWM_ASSERT(cryptAlgo); |
689 | PWM_ASSERT(pw); | 687 | PWM_ASSERT(pw); |
690 | PWM_ASSERT(headerLength); | 688 | PWM_ASSERT(headerLength); |
691 | PWM_ASSERT(dataHashType); | 689 | PWM_ASSERT(dataHashType); |
692 | PWM_ASSERT(dataHash); | 690 | PWM_ASSERT(dataHash); |
693 | PWM_ASSERT(f); | 691 | PWM_ASSERT(f); |
694 | int tmpRet; | 692 | int tmpRet; |
695 | // check "magic" header | 693 | // check "magic" header |
696 | const char magicHdr[] = FILE_ID_HEADER; | 694 | const char magicHdr[] = FILE_ID_HEADER; |
697 | const int hdrLen = array_size(magicHdr) - 1; | 695 | const int hdrLen = array_size(magicHdr) - 1; |
698 | char tmp[hdrLen]; | 696 | char tmp[hdrLen]; |
699 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 697 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
700 | return e_readFile; | 698 | return e_readFile; |
701 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 699 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
702 | return e_fileFormat; | 700 | return e_fileFormat; |
703 | // read and check file ver | 701 | // read and check file ver |
704 | int fileV = f->getch(); | 702 | int fileV = f->getch(); |
705 | if (fileV == -1) | 703 | if (fileV == -1) |
706 | return e_fileFormat; | 704 | return e_fileFormat; |
707 | if (fileV != PWM_FILE_VER) | 705 | if (fileV != PWM_FILE_VER) |
708 | return e_fileVer; | 706 | return e_fileVer; |
709 | // read hash hash type | 707 | // read hash hash type |
710 | int keyHash = f->getch(); | 708 | int keyHash = f->getch(); |
711 | if (keyHash == -1) | 709 | if (keyHash == -1) |
712 | return e_fileFormat; | 710 | return e_fileFormat; |
713 | // read data hash type | 711 | // read data hash type |
714 | tmpRet = f->getch(); | 712 | tmpRet = f->getch(); |
715 | if (tmpRet == -1) | 713 | if (tmpRet == -1) |
716 | return e_fileFormat; | 714 | return e_fileFormat; |
717 | *dataHashType = tmpRet; | 715 | *dataHashType = tmpRet; |
718 | // read crypt algo | 716 | // read crypt algo |
719 | tmpRet = f->getch(); | 717 | tmpRet = f->getch(); |
720 | if (tmpRet == -1) | 718 | if (tmpRet == -1) |
721 | return e_fileFormat; | 719 | return e_fileFormat; |
722 | *cryptAlgo = tmpRet; | 720 | *cryptAlgo = tmpRet; |
723 | // get compression-algo | 721 | // get compression-algo |
724 | tmpRet = f->getch(); | 722 | tmpRet = f->getch(); |
725 | if (tmpRet == -1) | 723 | if (tmpRet == -1) |
726 | return e_fileFormat; | 724 | return e_fileFormat; |
727 | *compress = tmpRet; | 725 | *compress = tmpRet; |
728 | // get the MPW-flag | 726 | // get the MPW-flag |
729 | int mpw_flag = f->getch(); | 727 | int mpw_flag = f->getch(); |
730 | if (mpw_flag == -1) | 728 | if (mpw_flag == -1) |
731 | return e_fileFormat; | 729 | return e_fileFormat; |
732 | if (mpw_flag == 0x01) | 730 | if (mpw_flag == 0x01) |
733 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 731 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
734 | else | 732 | else |
735 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 733 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
736 | // skip the "RESERVED"-bytes | 734 | // skip the "RESERVED"-bytes |
737 | if (!(f->at(f->at() + 64))) | 735 | if (!(f->at(f->at() + 64))) |
738 | return e_fileFormat; | 736 | return e_fileFormat; |
739 | 737 | ||
740 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 738 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
741 | if (*pw == "") { | 739 | if (*pw == "") { |
742 | /* the user didn't give a master-password | 740 | /* the user didn't give a master-password |
743 | * or didn't insert a chipcard | 741 | * or didn't insert a chipcard |
744 | */ | 742 | */ |
745 | return e_noPw; | 743 | return e_noPw; |
746 | } | 744 | } |
747 | // verify key-hash | 745 | // verify key-hash |
748 | switch (keyHash) { | 746 | switch (keyHash) { |
749 | case PWM_HASH_SHA1: { | 747 | case PWM_HASH_SHA1: { |
750 | // read hash from header | 748 | // read hash from header |
751 | const int hashLen = SHA1_HASH_LEN_BYTE; | 749 | const int hashLen = SHA1_HASH_LEN_BYTE; |
752 | string readHash; | 750 | string readHash; |
753 | int i; | 751 | int i; |
754 | for (i = 0; i < hashLen; ++i) | 752 | for (i = 0; i < hashLen; ++i) |
755 | readHash.push_back(f->getch()); | 753 | readHash.push_back(f->getch()); |
756 | Sha1 hash; | 754 | Sha1 hash; |
757 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 755 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
758 | string ret = hash.sha1_read(); | 756 | string ret = hash.sha1_read(); |
759 | if (ret != readHash) | 757 | if (ret != readHash) |
760 | return e_wrongPw;// hash doesn't match (wrong key) | 758 | return e_wrongPw;// hash doesn't match (wrong key) |
761 | break; | 759 | break; |
762 | } | 760 | } |
763 | #ifndef PWM_EMBEDDED | 761 | #ifndef PWM_EMBEDDED |
764 | case PWM_HASH_SHA256: | 762 | case PWM_HASH_SHA256: |
765 | /*... fall through */ | 763 | /*... fall through */ |
766 | case PWM_HASH_SHA384: | 764 | case PWM_HASH_SHA384: |
767 | case PWM_HASH_SHA512: | 765 | case PWM_HASH_SHA512: |
768 | case PWM_HASH_MD5: | 766 | case PWM_HASH_MD5: |
769 | case PWM_HASH_RMD160: | 767 | case PWM_HASH_RMD160: |
770 | case PWM_HASH_TIGER: { | 768 | case PWM_HASH_TIGER: { |
771 | if (!LibGCryptIf::available()) | 769 | if (!LibGCryptIf::available()) |
772 | return e_hashNotImpl; | 770 | return e_hashNotImpl; |
773 | LibGCryptIf gc; | 771 | LibGCryptIf gc; |
774 | PwMerror err; | 772 | PwMerror err; |
775 | unsigned char *buf; | 773 | unsigned char *buf; |
776 | size_t hashLen; | 774 | size_t hashLen; |
777 | err = gc.hash(&buf, | 775 | err = gc.hash(&buf, |
778 | &hashLen, | 776 | &hashLen, |
779 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 777 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
780 | pw->length(), | 778 | pw->length(), |
781 | keyHash); | 779 | keyHash); |
782 | if (err != e_success) | 780 | if (err != e_success) |
783 | return e_hashNotImpl; | 781 | return e_hashNotImpl; |
784 | string calcHash(reinterpret_cast<const char *>(buf), | 782 | string calcHash(reinterpret_cast<const char *>(buf), |
785 | static_cast<string::size_type>(hashLen)); | 783 | static_cast<string::size_type>(hashLen)); |
786 | delete [] buf; | 784 | delete [] buf; |
787 | // read hash from header | 785 | // read hash from header |
788 | string readHash; | 786 | string readHash; |
789 | size_t i; | 787 | size_t i; |
790 | for (i = 0; i < hashLen; ++i) | 788 | for (i = 0; i < hashLen; ++i) |
791 | readHash.push_back(f->getch()); | 789 | readHash.push_back(f->getch()); |
792 | if (calcHash != readHash) | 790 | if (calcHash != readHash) |
793 | return e_wrongPw;// hash doesn't match (wrong key) | 791 | return e_wrongPw;// hash doesn't match (wrong key) |
794 | break; | 792 | break; |
795 | } | 793 | } |
796 | #endif | 794 | #endif |
797 | default: { | 795 | default: { |
798 | return e_hashNotImpl; | 796 | return e_hashNotImpl; |
799 | } } | 797 | } } |
800 | // read the data-hash from the file | 798 | // read the data-hash from the file |
801 | unsigned int hashLen, i; | 799 | unsigned int hashLen, i; |
802 | switch (*dataHashType) { | 800 | switch (*dataHashType) { |
803 | case PWM_HASH_SHA1: | 801 | case PWM_HASH_SHA1: |
804 | hashLen = SHA1_HASH_LEN_BYTE; | 802 | hashLen = SHA1_HASH_LEN_BYTE; |
805 | break; | 803 | break; |
806 | #ifndef PWM_EMBEDDED | 804 | #ifndef PWM_EMBEDDED |
807 | case PWM_HASH_SHA256: | 805 | case PWM_HASH_SHA256: |
808 | /*... fall through */ | 806 | /*... fall through */ |
809 | case PWM_HASH_SHA384: | 807 | case PWM_HASH_SHA384: |
810 | case PWM_HASH_SHA512: | 808 | case PWM_HASH_SHA512: |
811 | case PWM_HASH_MD5: | 809 | case PWM_HASH_MD5: |
812 | case PWM_HASH_RMD160: | 810 | case PWM_HASH_RMD160: |
813 | case PWM_HASH_TIGER: { | 811 | case PWM_HASH_TIGER: { |
814 | if (!LibGCryptIf::available()) | 812 | if (!LibGCryptIf::available()) |
815 | return e_hashNotImpl; | 813 | return e_hashNotImpl; |
816 | LibGCryptIf gc; | 814 | LibGCryptIf gc; |
817 | hashLen = gc.hashLength(*dataHashType); | 815 | hashLen = gc.hashLength(*dataHashType); |
818 | if (hashLen == 0) | 816 | if (hashLen == 0) |
819 | return e_hashNotImpl; | 817 | return e_hashNotImpl; |
820 | break; | 818 | break; |
821 | } | 819 | } |
822 | #endif | 820 | #endif |
823 | default: | 821 | default: |
824 | return e_hashNotImpl; | 822 | return e_hashNotImpl; |
825 | } | 823 | } |
826 | *dataHash = ""; | 824 | *dataHash = ""; |
827 | for (i = 0; i < hashLen; ++i) { | 825 | for (i = 0; i < hashLen; ++i) { |
828 | tmpRet = f->getch(); | 826 | tmpRet = f->getch(); |
829 | if (tmpRet == -1) | 827 | if (tmpRet == -1) |
830 | return e_fileFormat; | 828 | return e_fileFormat; |
831 | dataHash->push_back(static_cast<char>(tmpRet)); | 829 | dataHash->push_back(static_cast<char>(tmpRet)); |
832 | } | 830 | } |
833 | *headerLength = f->at(); | 831 | *headerLength = f->at(); |
834 | #ifndef PWM_EMBEDDED | 832 | #ifndef PWM_EMBEDDED |
835 | printDebug(string("opening file { compress: ") | 833 | printDebug(string("opening file { compress: ") |
836 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 834 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
837 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 835 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
838 | + tostr(static_cast<int>(keyHash)) | 836 | + tostr(static_cast<int>(keyHash)) |
839 | + " }"); | 837 | + " }"); |
840 | #else | 838 | #else |
841 | printDebug(string("opening file { compress: ") | 839 | printDebug(string("opening file { compress: ") |
842 | + tostr((int)(*compress)) + " cryptAlgo: " | 840 | + tostr((int)(*compress)) + " cryptAlgo: " |
843 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 841 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
844 | + tostr((int)(keyHash)) | 842 | + tostr((int)(keyHash)) |
845 | + " }"); | 843 | + " }"); |
846 | #endif | 844 | #endif |
847 | 845 | ||
848 | return e_success; | 846 | return e_success; |
849 | } | 847 | } |
850 | 848 | ||
851 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 849 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
852 | { | 850 | { |
853 | PWM_ASSERT(d); | 851 | PWM_ASSERT(d); |
854 | PWM_ASSERT(f); | 852 | PWM_ASSERT(f); |
855 | 853 | ||
856 | switch (dataHash) { | 854 | switch (dataHash) { |
857 | case PWM_HASH_SHA1: { | 855 | case PWM_HASH_SHA1: { |
858 | const int hashLen = SHA1_HASH_LEN_BYTE; | 856 | const int hashLen = SHA1_HASH_LEN_BYTE; |
859 | Sha1 h; | 857 | Sha1 h; |
860 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); | 858 | h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size()); |
861 | string hRet = h.sha1_read(); | 859 | string hRet = h.sha1_read(); |
862 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 860 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
863 | return e_writeFile; | 861 | return e_writeFile; |
864 | break; | 862 | break; |
865 | } | 863 | } |
866 | #ifndef PWM_EMBEDDED | 864 | #ifndef PWM_EMBEDDED |
867 | case PWM_HASH_SHA256: | 865 | case PWM_HASH_SHA256: |
868 | /*... fall through */ | 866 | /*... fall through */ |
869 | case PWM_HASH_SHA384: | 867 | case PWM_HASH_SHA384: |
870 | case PWM_HASH_SHA512: | 868 | case PWM_HASH_SHA512: |
871 | case PWM_HASH_MD5: | 869 | case PWM_HASH_MD5: |
872 | case PWM_HASH_RMD160: | 870 | case PWM_HASH_RMD160: |
873 | case PWM_HASH_TIGER: { | 871 | case PWM_HASH_TIGER: { |
874 | if (!LibGCryptIf::available()) | 872 | if (!LibGCryptIf::available()) |
875 | return e_hashNotImpl; | 873 | return e_hashNotImpl; |
876 | LibGCryptIf gc; | 874 | LibGCryptIf gc; |
877 | PwMerror err; | 875 | PwMerror err; |
878 | unsigned char *buf; | 876 | unsigned char *buf; |
879 | size_t hashLen; | 877 | size_t hashLen; |
880 | err = gc.hash(&buf, | 878 | err = gc.hash(&buf, |
881 | &hashLen, | 879 | &hashLen, |
882 | reinterpret_cast<const unsigned char *>(d->c_str()), | 880 | reinterpret_cast<const unsigned char *>(d->c_str()), |
883 | d->size(), | 881 | d->size(), |
884 | dataHash); | 882 | dataHash); |
885 | if (err != e_success) | 883 | if (err != e_success) |
886 | return e_hashNotImpl; | 884 | return e_hashNotImpl; |
887 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 885 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
888 | != static_cast<Q_LONG>(hashLen)) { | 886 | != static_cast<Q_LONG>(hashLen)) { |
889 | delete [] buf; | 887 | delete [] buf; |
890 | return e_hashNotImpl; | 888 | return e_hashNotImpl; |
891 | } | 889 | } |
892 | delete [] buf; | 890 | delete [] buf; |
893 | break; | 891 | break; |
894 | } | 892 | } |
895 | #endif | 893 | #endif |
896 | default: { | 894 | default: { |
897 | return e_hashNotImpl; | 895 | return e_hashNotImpl; |
898 | } } | 896 | } } |
899 | 897 | ||
900 | return e_success; | 898 | return e_success; |
901 | } | 899 | } |
902 | 900 | ||
903 | bool PwMDoc::backupFile(const QString &filePath) | 901 | bool PwMDoc::backupFile(const QString &filePath) |
904 | { | 902 | { |
905 | QFileInfo fi(filePath); | 903 | QFileInfo fi(filePath); |
906 | if (!fi.exists()) | 904 | if (!fi.exists()) |
907 | return true; // Yes, true is correct. | 905 | return true; // Yes, true is correct. |
908 | QString pathOnly(fi.dirPath(true)); | 906 | QString pathOnly(fi.dirPath(true)); |
909 | QString nameOnly(fi.fileName()); | 907 | QString nameOnly(fi.fileName()); |
910 | QString backupPath = pathOnly | 908 | QString backupPath = pathOnly |
911 | + "/~" | 909 | + "/~" |
912 | + nameOnly | 910 | + nameOnly |
913 | + ".backup"; | 911 | + ".backup"; |
914 | return copyFile(filePath, backupPath); | 912 | return copyFile(filePath, backupPath); |
915 | } | 913 | } |
916 | 914 | ||
917 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 915 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
918 | { | 916 | { |
919 | QFileInfo fi(src); | 917 | QFileInfo fi(src); |
920 | if (!fi.exists()) | 918 | if (!fi.exists()) |
921 | return false; | 919 | return false; |
922 | if (QFile::exists(dst)) { | 920 | if (QFile::exists(dst)) { |
923 | if (!QFile::remove(dst)) | 921 | if (!QFile::remove(dst)) |
924 | return false; | 922 | return false; |
925 | } | 923 | } |
926 | QFile srcFd(src); | 924 | QFile srcFd(src); |
927 | if (!srcFd.open(IO_ReadOnly)) | 925 | if (!srcFd.open(IO_ReadOnly)) |
928 | return false; | 926 | return false; |
929 | QFile dstFd(dst); | 927 | QFile dstFd(dst); |
930 | if (!dstFd.open(IO_ReadWrite)) { | 928 | if (!dstFd.open(IO_ReadWrite)) { |
931 | srcFd.close(); | 929 | srcFd.close(); |
932 | return false; | 930 | return false; |
933 | } | 931 | } |
934 | const int tmpBuf_size = 512; | 932 | const int tmpBuf_size = 512; |
935 | char tmpBuf[tmpBuf_size]; | 933 | char tmpBuf[tmpBuf_size]; |
936 | #ifndef PWM_EMBEDDED | 934 | #ifndef PWM_EMBEDDED |
937 | Q_LONG bytesRead, bytesWritten; | 935 | Q_LONG bytesRead, bytesWritten; |
938 | #else | 936 | #else |
939 | long bytesRead, bytesWritten; | 937 | long bytesRead, bytesWritten; |
940 | #endif | 938 | #endif |
941 | while (!srcFd.atEnd()) { | 939 | while (!srcFd.atEnd()) { |
942 | #ifndef PWM_EMBEDDED | 940 | #ifndef PWM_EMBEDDED |
943 | bytesRead = srcFd.readBlock(tmpBuf, | 941 | bytesRead = srcFd.readBlock(tmpBuf, |
944 | static_cast<Q_ULONG>(tmpBuf_size)); | 942 | static_cast<Q_ULONG>(tmpBuf_size)); |
945 | #else | 943 | #else |
946 | bytesRead = srcFd.readBlock(tmpBuf, | 944 | bytesRead = srcFd.readBlock(tmpBuf, |
947 | (unsigned long)(tmpBuf_size)); | 945 | (unsigned long)(tmpBuf_size)); |
948 | #endif | 946 | #endif |
949 | if (bytesRead == -1) { | 947 | if (bytesRead == -1) { |
950 | srcFd.close(); | 948 | srcFd.close(); |
951 | dstFd.close(); | 949 | dstFd.close(); |
952 | return false; | 950 | return false; |
953 | } | 951 | } |
954 | #ifndef PWM_EMBEDDED | 952 | #ifndef PWM_EMBEDDED |
955 | bytesWritten = dstFd.writeBlock(tmpBuf, | 953 | bytesWritten = dstFd.writeBlock(tmpBuf, |
956 | static_cast<Q_ULONG>(bytesRead)); | 954 | static_cast<Q_ULONG>(bytesRead)); |
957 | #else | 955 | #else |
958 | bytesWritten = dstFd.writeBlock(tmpBuf, | 956 | bytesWritten = dstFd.writeBlock(tmpBuf, |
959 | (unsigned long)(bytesRead)); | 957 | (unsigned long)(bytesRead)); |
960 | #endif | 958 | #endif |
961 | if (bytesWritten != bytesRead) { | 959 | if (bytesWritten != bytesRead) { |
962 | srcFd.close(); | 960 | srcFd.close(); |
963 | dstFd.close(); | 961 | dstFd.close(); |
964 | return false; | 962 | return false; |
965 | } | 963 | } |
966 | } | 964 | } |
967 | srcFd.close(); | 965 | srcFd.close(); |
968 | dstFd.close(); | 966 | dstFd.close(); |
969 | return true; | 967 | return true; |
970 | } | 968 | } |
971 | 969 | ||
972 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 970 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
973 | bool dontFlagDirty, bool updateMeta) | 971 | bool dontFlagDirty, bool updateMeta) |
974 | { | 972 | { |
975 | PWM_ASSERT(d); | 973 | PWM_ASSERT(d); |
976 | unsigned int cat = 0; | 974 | unsigned int cat = 0; |
977 | 975 | ||
978 | if (isDeepLocked()) { | 976 | if (isDeepLocked()) { |
979 | PwMerror ret; | 977 | PwMerror ret; |
980 | ret = deepLock(false); | 978 | ret = deepLock(false); |
981 | if (ret != e_success) | 979 | if (ret != e_success) |
982 | return e_lock; | 980 | return e_lock; |
983 | } | 981 | } |
984 | 982 | ||
985 | addCategory(category, &cat); | 983 | addCategory(category, &cat); |
986 | 984 | ||
987 | if (numEntries(category) >= maxEntries) | 985 | if (numEntries(category) >= maxEntries) |
988 | return e_maxAllowedEntr; | 986 | return e_maxAllowedEntr; |
989 | 987 | ||
990 | vector<unsigned int> foundPositions; | 988 | vector<unsigned int> foundPositions; |
991 | /* historically this was: | 989 | /* historically this was: |
992 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 990 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
993 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 991 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
994 | * But for now we only search in desc. | 992 | * But for now we only search in desc. |
995 | * That's a tweak to be KWallet compatible. But it should not add | 993 | * That's a tweak to be KWallet compatible. But it should not add |
996 | * usability-drop onto PwManager, does it? | 994 | * usability-drop onto PwManager, does it? |
997 | * (And yes, "int" was a bug. Correct is "unsigned int") | 995 | * (And yes, "int" was a bug. Correct is "unsigned int") |
998 | */ | 996 | */ |
999 | const unsigned int searchIn = SEARCH_IN_DESC; | 997 | const unsigned int searchIn = SEARCH_IN_DESC; |
1000 | findEntry(cat, *d, searchIn, &foundPositions, true); | 998 | findEntry(cat, *d, searchIn, &foundPositions, true); |
1001 | if (foundPositions.size()) { | 999 | if (foundPositions.size()) { |
1002 | // DOH! We found this entry. | 1000 | // DOH! We found this entry. |
1003 | return e_entryExists; | 1001 | return e_entryExists; |
1004 | } | 1002 | } |
1005 | 1003 | ||
1006 | d->listViewPos = -1; | 1004 | d->listViewPos = -1; |
1007 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1005 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1008 | if (updateMeta) { | 1006 | if (updateMeta) { |
1009 | d->meta.create = QDateTime::currentDateTime(); | 1007 | d->meta.create = QDateTime::currentDateTime(); |
1010 | d->meta.update = d->meta.create; | 1008 | d->meta.update = d->meta.create; |
1011 | } | 1009 | } |
1012 | dta[cat].d.push_back(*d); | 1010 | dta[cat].d.push_back(*d); |
1013 | 1011 | ||
1014 | delAllEmptyCat(true); | 1012 | delAllEmptyCat(true); |
1015 | 1013 | ||
1016 | if (!dontFlagDirty) | 1014 | if (!dontFlagDirty) |
1017 | flagDirty(); | 1015 | flagDirty(); |
1018 | return e_success; | 1016 | return e_success; |
1019 | } | 1017 | } |
1020 | 1018 | ||
1021 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1019 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1022 | bool checkIfExist) | 1020 | bool checkIfExist) |
1023 | { | 1021 | { |
1024 | if (isDeepLocked()) { | 1022 | if (isDeepLocked()) { |
1025 | PwMerror ret; | 1023 | PwMerror ret; |
1026 | ret = deepLock(false); | 1024 | ret = deepLock(false); |
1027 | if (ret != e_success) | 1025 | if (ret != e_success) |
1028 | return e_lock; | 1026 | return e_lock; |
1029 | } | 1027 | } |
1030 | if (checkIfExist) { | 1028 | if (checkIfExist) { |
1031 | if (findCategory(category, categoryIndex)) | 1029 | if (findCategory(category, categoryIndex)) |
1032 | return e_categoryExists; | 1030 | return e_categoryExists; |
1033 | } | 1031 | } |
1034 | PwMCategoryItem item; | 1032 | PwMCategoryItem item; |
1035 | item.name = category.latin1(); | 1033 | item.name = category.latin1(); |
1036 | dta.push_back(item); | 1034 | dta.push_back(item); |
1037 | if (categoryIndex) | 1035 | if (categoryIndex) |
1038 | *categoryIndex = dta.size() - 1; | 1036 | *categoryIndex = dta.size() - 1; |
1039 | return e_success; | 1037 | return e_success; |
1040 | } | 1038 | } |
1041 | 1039 | ||
1042 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1040 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1043 | { | 1041 | { |
1044 | unsigned int cat = 0; | 1042 | unsigned int cat = 0; |
1045 | 1043 | ||
1046 | if (!findCategory(category, &cat)) { | 1044 | if (!findCategory(category, &cat)) { |
1047 | BUG(); | 1045 | BUG(); |
1048 | return false; | 1046 | return false; |
1049 | } | 1047 | } |
1050 | 1048 | ||
1051 | return delEntry(cat, index, dontFlagDirty); | 1049 | return delEntry(cat, index, dontFlagDirty); |
1052 | } | 1050 | } |
1053 | 1051 | ||
1054 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1052 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1055 | { | 1053 | { |
1056 | if (isDeepLocked()) | 1054 | if (isDeepLocked()) |
1057 | return false; | 1055 | return false; |
1058 | if (index > dta[category].d.size() - 1) | 1056 | if (index > dta[category].d.size() - 1) |
1059 | return false; | 1057 | return false; |
1060 | getDataChangedLock(); | 1058 | getDataChangedLock(); |
1061 | if (!lockAt(category, index, false)) { | 1059 | if (!lockAt(category, index, false)) { |
1062 | putDataChangedLock(); | 1060 | putDataChangedLock(); |
1063 | return false; | 1061 | return false; |
1064 | } | 1062 | } |
1065 | putDataChangedLock(); | 1063 | putDataChangedLock(); |
1066 | int lvPos = dta[category].d[index].listViewPos; | 1064 | int lvPos = dta[category].d[index].listViewPos; |
1067 | 1065 | ||
1068 | // delete entry | 1066 | // delete entry |
1069 | dta[category].d.erase(dta[category].d.begin() + index); | 1067 | dta[category].d.erase(dta[category].d.begin() + index); |
1070 | 1068 | ||
1071 | unsigned int i, entries = numEntries(category); | 1069 | unsigned int i, entries = numEntries(category); |
1072 | if (!entries) { | 1070 | if (!entries) { |
1073 | // no more entries in this category, so | 1071 | // no more entries in this category, so |
1074 | // we can delete it, too. | 1072 | // we can delete it, too. |
1075 | BUG_ON(!delCategory(category)); | 1073 | BUG_ON(!delCategory(category)); |
1076 | // delCategory() flags it dirty, so we need not to do so. | 1074 | // delCategory() flags it dirty, so we need not to do so. |
1077 | return true; | 1075 | return true; |
1078 | } | 1076 | } |
1079 | for (i = 0; i < entries; ++i) { | 1077 | for (i = 0; i < entries; ++i) { |
1080 | // decrement all listViewPositions that are greater than the deleted. | 1078 | // decrement all listViewPositions that are greater than the deleted. |
1081 | if (dta[category].d[i].listViewPos > lvPos) | 1079 | if (dta[category].d[i].listViewPos > lvPos) |
1082 | --dta[category].d[i].listViewPos; | 1080 | --dta[category].d[i].listViewPos; |
1083 | } | 1081 | } |
1084 | 1082 | ||
1085 | if (!dontFlagDirty) | 1083 | if (!dontFlagDirty) |
1086 | flagDirty(); | 1084 | flagDirty(); |
1087 | return true; | 1085 | return true; |
1088 | } | 1086 | } |
1089 | 1087 | ||
1090 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1088 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1091 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1089 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1092 | { | 1090 | { |
1093 | PWM_ASSERT(d); | 1091 | PWM_ASSERT(d); |
1094 | unsigned int oldCat = 0; | 1092 | unsigned int oldCat = 0; |
1095 | 1093 | ||
1096 | if (!findCategory(oldCategory, &oldCat)) { | 1094 | if (!findCategory(oldCategory, &oldCat)) { |
1097 | BUG(); | 1095 | BUG(); |
1098 | return false; | 1096 | return false; |
1099 | } | 1097 | } |
1100 | 1098 | ||
1101 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1099 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1102 | } | 1100 | } |
1103 | 1101 | ||
1104 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1102 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1105 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1103 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1106 | { | 1104 | { |
1107 | if (isDeepLocked()) | 1105 | if (isDeepLocked()) |
1108 | return false; | 1106 | return false; |
1109 | if (updateMeta) { | 1107 | if (updateMeta) { |
1110 | d->meta.update = QDateTime::currentDateTime(); | 1108 | d->meta.update = QDateTime::currentDateTime(); |
1111 | if (d->meta.create.isNull()) { | 1109 | if (d->meta.create.isNull()) { |
1112 | d->meta.create = d->meta.update; | 1110 | d->meta.create = d->meta.update; |
1113 | } | 1111 | } |
1114 | } | 1112 | } |
1115 | if (dta[oldCategory].name != newCategory.latin1()) { | 1113 | if (dta[oldCategory].name != newCategory.latin1()) { |
1116 | // the user changed the category. | 1114 | // the user changed the category. |
1117 | PwMerror ret; | 1115 | PwMerror ret; |
1118 | d->rev = 0; | 1116 | d->rev = 0; |
1119 | ret = addEntry(newCategory, d, true, false); | 1117 | ret = addEntry(newCategory, d, true, false); |
1120 | if (ret != e_success) | 1118 | if (ret != e_success) |
1121 | return false; | 1119 | return false; |
1122 | if (!delEntry(oldCategory, index, true)) | 1120 | if (!delEntry(oldCategory, index, true)) |
1123 | return false; | 1121 | return false; |
1124 | } else { | 1122 | } else { |
1125 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1123 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1126 | dta[oldCategory].d[index] = *d; | 1124 | dta[oldCategory].d[index] = *d; |
1127 | } | 1125 | } |
1128 | flagDirty(); | 1126 | flagDirty(); |
1129 | return true; | 1127 | return true; |
1130 | } | 1128 | } |
1131 | 1129 | ||
1132 | unsigned int PwMDoc::numEntries(const QString &category) | 1130 | unsigned int PwMDoc::numEntries(const QString &category) |
1133 | { | 1131 | { |
1134 | unsigned int cat = 0; | 1132 | unsigned int cat = 0; |
1135 | 1133 | ||
1136 | if (!findCategory(category, &cat)) { | 1134 | if (!findCategory(category, &cat)) { |
1137 | BUG(); | 1135 | BUG(); |
1138 | return 0; | 1136 | return 0; |
1139 | } | 1137 | } |
1140 | 1138 | ||
1141 | return numEntries(cat); | 1139 | return numEntries(cat); |
1142 | } | 1140 | } |
1143 | 1141 | ||
1144 | bool PwMDoc::serializeDta(string *d) | 1142 | bool PwMDoc::serializeDta(string *d) |
1145 | { | 1143 | { |
1146 | PWM_ASSERT(d); | 1144 | PWM_ASSERT(d); |
1147 | Serializer ser; | 1145 | Serializer ser; |
1148 | if (!ser.serialize(dta)) | 1146 | if (!ser.serialize(dta)) |
1149 | return false; | 1147 | return false; |
1150 | d->assign(ser.getXml()); | 1148 | d->assign(ser.getXml()); |
1151 | if (!d->size()) | 1149 | if (!d->size()) |
1152 | return false; | 1150 | return false; |
1153 | return true; | 1151 | return true; |
1154 | } | 1152 | } |
1155 | 1153 | ||
1156 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1154 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1157 | { | 1155 | { |
1158 | PWM_ASSERT(d); | 1156 | PWM_ASSERT(d); |
1159 | #ifndef PWM_EMBEDDED | 1157 | #ifndef PWM_EMBEDDED |
1160 | try { | 1158 | try { |
1161 | 1159 | ||
1162 | Serializer ser(d->c_str()); | 1160 | Serializer ser(d->c_str()); |
1163 | ser.setDefaultLockStat(entriesLocked); | 1161 | ser.setDefaultLockStat(entriesLocked); |
1164 | if (!ser.deSerialize(&dta)) | 1162 | if (!ser.deSerialize(&dta)) |
1165 | return false; | 1163 | return false; |
1166 | } catch (PwMException) { | 1164 | } catch (PwMException) { |
1167 | return false; | 1165 | return false; |
1168 | } | 1166 | } |
1169 | #else | 1167 | #else |
1170 | Serializer ser(d->c_str()); | 1168 | Serializer ser(d->c_str()); |
1171 | ser.setDefaultLockStat(entriesLocked); | 1169 | ser.setDefaultLockStat(entriesLocked); |
1172 | if (!ser.deSerialize(&dta)) | 1170 | if (!ser.deSerialize(&dta)) |
1173 | return false; | 1171 | return false; |
1174 | else | ||
1175 | return false; | ||
1176 | #endif | 1172 | #endif |
1177 | 1173 | ||
1178 | emitDataChanged(this); | 1174 | emitDataChanged(this); |
1179 | return true; | 1175 | return true; |
1180 | } | 1176 | } |
1181 | 1177 | ||
1182 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1178 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1183 | PwMDataItem * d, bool unlockIfLocked) | 1179 | PwMDataItem * d, bool unlockIfLocked) |
1184 | { | 1180 | { |
1185 | PWM_ASSERT(d); | 1181 | PWM_ASSERT(d); |
1186 | unsigned int cat = 0; | 1182 | unsigned int cat = 0; |
1187 | 1183 | ||
1188 | if (!findCategory(category, &cat)) { | 1184 | if (!findCategory(category, &cat)) { |
1189 | BUG(); | 1185 | BUG(); |
1190 | return false; | 1186 | return false; |
1191 | } | 1187 | } |
1192 | 1188 | ||
1193 | return getEntry(cat, index, d, unlockIfLocked); | 1189 | return getEntry(cat, index, d, unlockIfLocked); |
1194 | } | 1190 | } |
1195 | 1191 | ||
1196 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1192 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1197 | PwMDataItem *d, bool unlockIfLocked) | 1193 | PwMDataItem *d, bool unlockIfLocked) |
1198 | { | 1194 | { |
1199 | if (index > dta[category].d.size() - 1) | 1195 | if (index > dta[category].d.size() - 1) |
1200 | return false; | 1196 | return false; |
1201 | 1197 | ||
1202 | bool locked = isLocked(category, index); | 1198 | bool locked = isLocked(category, index); |
1203 | if (locked) { | 1199 | if (locked) { |
1204 | /* this entry is locked. We don't return a password, | 1200 | /* this entry is locked. We don't return a password, |
1205 | * until it's unlocked by the user by inserting | 1201 | * until it's unlocked by the user by inserting |
1206 | * chipcard or entering the mpw | 1202 | * chipcard or entering the mpw |
1207 | */ | 1203 | */ |
1208 | if (unlockIfLocked) { | 1204 | if (unlockIfLocked) { |
1209 | if (!lockAt(category, index, false)) { | 1205 | if (!lockAt(category, index, false)) { |
1210 | return false; | 1206 | return false; |
1211 | } | 1207 | } |
1212 | locked = false; | 1208 | locked = false; |
1213 | } | 1209 | } |
1214 | } | 1210 | } |
1215 | 1211 | ||
1216 | *d = dta[category].d[index]; | 1212 | *d = dta[category].d[index]; |
1217 | if (locked) | 1213 | if (locked) |
1218 | d->pw = LOCKED_STRING.latin1(); | 1214 | d->pw = LOCKED_STRING.latin1(); |
1219 | 1215 | ||
1220 | return true; | 1216 | return true; |
1221 | } | 1217 | } |
1222 | 1218 | ||
1223 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1219 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1224 | string *foundComment) | 1220 | string *foundComment) |
1225 | { | 1221 | { |
1226 | PWM_ASSERT(foundComment); | 1222 | PWM_ASSERT(foundComment); |
1227 | unsigned int cat = 0; | 1223 | unsigned int cat = 0; |
1228 | 1224 | ||
1229 | if (!findCategory(category, &cat)) | 1225 | if (!findCategory(category, &cat)) |
1230 | return e_invalidArg; | 1226 | return e_invalidArg; |
1231 | 1227 | ||
1232 | unsigned int i, entries = numEntries(cat); | 1228 | unsigned int i, entries = numEntries(cat); |
1233 | for (i = 0; i < entries; ++i) { | 1229 | for (i = 0; i < entries; ++i) { |
1234 | if (dta[cat].d[i].listViewPos == listViewPos) { | 1230 | if (dta[cat].d[i].listViewPos == listViewPos) { |
1235 | *foundComment = dta[cat].d[i].comment; | 1231 | *foundComment = dta[cat].d[i].comment; |
1236 | if (dta[cat].d[i].binary) | 1232 | if (dta[cat].d[i].binary) |
1237 | return e_binEntry; | 1233 | return e_binEntry; |
1238 | return e_normalEntry; | 1234 | return e_normalEntry; |
1239 | } | 1235 | } |
1240 | } | 1236 | } |
1241 | BUG(); | 1237 | BUG(); |
1242 | return e_generic; | 1238 | return e_generic; |
1243 | } | 1239 | } |
1244 | 1240 | ||
1245 | bool PwMDoc::compressDta(string *d, char algo) | 1241 | bool PwMDoc::compressDta(string *d, char algo) |
1246 | { | 1242 | { |
1247 | PWM_ASSERT(d); | 1243 | PWM_ASSERT(d); |
1248 | switch (algo) { | 1244 | switch (algo) { |
1249 | case PWM_COMPRESS_GZIP: { | 1245 | case PWM_COMPRESS_GZIP: { |
1250 | CompressGzip comp; | 1246 | CompressGzip comp; |
1251 | return comp.compress(d); | 1247 | return comp.compress(d); |
1252 | } case PWM_COMPRESS_BZIP2: { | 1248 | } case PWM_COMPRESS_BZIP2: { |
1253 | CompressBzip2 comp; | 1249 | CompressBzip2 comp; |
1254 | return comp.compress(d); | 1250 | return comp.compress(d); |
1255 | } case PWM_COMPRESS_NONE: { | 1251 | } case PWM_COMPRESS_NONE: { |
1256 | return true; | 1252 | return true; |
1257 | } default: { | 1253 | } default: { |
1258 | BUG(); | 1254 | BUG(); |
1259 | } | 1255 | } |
1260 | } | 1256 | } |
1261 | return false; | 1257 | return false; |
1262 | } | 1258 | } |
1263 | 1259 | ||
1264 | bool PwMDoc::decompressDta(string *d, char algo) | 1260 | bool PwMDoc::decompressDta(string *d, char algo) |
1265 | { | 1261 | { |
1266 | PWM_ASSERT(d); | 1262 | PWM_ASSERT(d); |
1267 | switch (algo) { | 1263 | switch (algo) { |
1268 | case PWM_COMPRESS_GZIP: { | 1264 | case PWM_COMPRESS_GZIP: { |
1269 | CompressGzip comp; | 1265 | CompressGzip comp; |
1270 | return comp.decompress(d); | 1266 | return comp.decompress(d); |
1271 | } case PWM_COMPRESS_BZIP2: { | 1267 | } case PWM_COMPRESS_BZIP2: { |
1272 | CompressBzip2 comp; | 1268 | CompressBzip2 comp; |
1273 | return comp.decompress(d); | 1269 | return comp.decompress(d); |
1274 | } case PWM_COMPRESS_NONE: { | 1270 | } case PWM_COMPRESS_NONE: { |
1275 | return true; | 1271 | return true; |
1276 | } | 1272 | } |
1277 | } | 1273 | } |
1278 | return false; | 1274 | return false; |
1279 | } | 1275 | } |
1280 | 1276 | ||
1281 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1277 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1282 | { | 1278 | { |
1283 | PWM_ASSERT(d); | 1279 | PWM_ASSERT(d); |
1284 | PWM_ASSERT(pw); | 1280 | PWM_ASSERT(pw); |
1285 | PWM_ASSERT(f); | 1281 | PWM_ASSERT(f); |
1286 | 1282 | ||
1287 | size_t encSize; | 1283 | size_t encSize; |
1288 | byte *encrypted = 0; | 1284 | byte *encrypted = 0; |
1289 | 1285 | ||
1290 | switch (algo) { | 1286 | switch (algo) { |
1291 | case PWM_CRYPT_BLOWFISH: { | 1287 | case PWM_CRYPT_BLOWFISH: { |
1292 | Blowfish::padNull(d); | 1288 | Blowfish::padNull(d); |
1293 | encSize = d->length(); | 1289 | encSize = d->length(); |
1294 | encrypted = new byte[encSize]; | 1290 | encrypted = new byte[encSize]; |
1295 | Blowfish bf; | 1291 | Blowfish bf; |
1296 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1292 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1297 | delete [] encrypted; | 1293 | delete [] encrypted; |
1298 | return e_weakPw; | 1294 | return e_weakPw; |
1299 | } | 1295 | } |
1300 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1296 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1301 | break; | 1297 | break; |
1302 | } | 1298 | } |
1303 | #ifndef PWM_EMBEDDED | 1299 | #ifndef PWM_EMBEDDED |
1304 | case PWM_CRYPT_AES128: | 1300 | case PWM_CRYPT_AES128: |
1305 | /*... fall through */ | 1301 | /*... fall through */ |
1306 | case PWM_CRYPT_AES192: | 1302 | case PWM_CRYPT_AES192: |
1307 | case PWM_CRYPT_AES256: | 1303 | case PWM_CRYPT_AES256: |
1308 | case PWM_CRYPT_3DES: | 1304 | case PWM_CRYPT_3DES: |
1309 | case PWM_CRYPT_TWOFISH: | 1305 | case PWM_CRYPT_TWOFISH: |
1310 | case PWM_CRYPT_TWOFISH128: { | 1306 | case PWM_CRYPT_TWOFISH128: { |
1311 | if (!LibGCryptIf::available()) | 1307 | if (!LibGCryptIf::available()) |
1312 | return e_cryptNotImpl; | 1308 | return e_cryptNotImpl; |
1313 | LibGCryptIf gc; | 1309 | LibGCryptIf gc; |
1314 | PwMerror err; | 1310 | PwMerror err; |
1315 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1311 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1316 | memcpy(plain, d->c_str(), d->length()); | 1312 | memcpy(plain, d->c_str(), d->length()); |
1317 | err = gc.encrypt(&encrypted, | 1313 | err = gc.encrypt(&encrypted, |
1318 | &encSize, | 1314 | &encSize, |
1319 | plain, | 1315 | plain, |
1320 | d->length(), | 1316 | d->length(), |
1321 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1317 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1322 | pw->length(), | 1318 | pw->length(), |
1323 | algo); | 1319 | algo); |
1324 | delete [] plain; | 1320 | delete [] plain; |
1325 | if (err != e_success) | 1321 | if (err != e_success) |
1326 | return e_cryptNotImpl; | 1322 | return e_cryptNotImpl; |
1327 | break; | 1323 | break; |
1328 | } | 1324 | } |
1329 | #endif | 1325 | #endif |
1330 | default: { | 1326 | default: { |
1331 | delete_ifnot_null_array(encrypted); | 1327 | delete_ifnot_null_array(encrypted); |
1332 | return e_cryptNotImpl; | 1328 | return e_cryptNotImpl; |
1333 | } } | 1329 | } } |
1334 | 1330 | ||
1335 | // write encrypted data to file | 1331 | // write encrypted data to file |
1336 | #ifndef PWM_EMBEDDED | 1332 | #ifndef PWM_EMBEDDED |
1337 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1333 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1338 | static_cast<Q_ULONG>(encSize)) | 1334 | static_cast<Q_ULONG>(encSize)) |
1339 | != static_cast<Q_LONG>(encSize)) { | 1335 | != static_cast<Q_LONG>(encSize)) { |
1340 | delete_ifnot_null_array(encrypted); | 1336 | delete_ifnot_null_array(encrypted); |
1341 | return e_writeFile; | 1337 | return e_writeFile; |
1342 | } | 1338 | } |
1343 | #else | 1339 | #else |
1344 | if (f->writeBlock((const char *)(encrypted), | 1340 | if (f->writeBlock((const char *)(encrypted), |
1345 | (unsigned long)(encSize)) | 1341 | (unsigned long)(encSize)) |
1346 | != (long)(encSize)) { | 1342 | != (long)(encSize)) { |
1347 | delete_ifnot_null_array(encrypted); | 1343 | delete_ifnot_null_array(encrypted); |
1348 | return e_writeFile; | 1344 | return e_writeFile; |
1349 | } | 1345 | } |
1350 | #endif | 1346 | #endif |
1351 | delete_ifnot_null_array(encrypted); | 1347 | delete_ifnot_null_array(encrypted); |
1352 | return e_success; | 1348 | return e_success; |
1353 | } | 1349 | } |
1354 | 1350 | ||
1355 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1351 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1356 | char algo, QFile *f) | 1352 | char algo, QFile *f) |
1357 | { | 1353 | { |
1358 | PWM_ASSERT(d); | 1354 | PWM_ASSERT(d); |
1359 | PWM_ASSERT(pw); | 1355 | PWM_ASSERT(pw); |
1360 | PWM_ASSERT(f); | 1356 | PWM_ASSERT(f); |
1361 | 1357 | ||
1362 | unsigned int cryptLen = f->size() - pos; | 1358 | unsigned int cryptLen = f->size() - pos; |
1363 | byte *encrypted = new byte[cryptLen]; | 1359 | byte *encrypted = new byte[cryptLen]; |
1364 | byte *decrypted = new byte[cryptLen]; | 1360 | byte *decrypted = new byte[cryptLen]; |
1365 | 1361 | ||
1366 | f->at(pos); | 1362 | f->at(pos); |
1367 | #ifndef PWM_EMBEDDED | 1363 | #ifndef PWM_EMBEDDED |
1368 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1364 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1369 | static_cast<Q_ULONG>(cryptLen)) | 1365 | static_cast<Q_ULONG>(cryptLen)) |
1370 | != static_cast<Q_LONG>(cryptLen)) { | 1366 | != static_cast<Q_LONG>(cryptLen)) { |
1371 | delete [] encrypted; | 1367 | delete [] encrypted; |
1372 | delete [] decrypted; | 1368 | delete [] decrypted; |
1373 | return e_readFile; | 1369 | return e_readFile; |
1374 | } | 1370 | } |
1375 | #else | 1371 | #else |
1376 | if (f->readBlock((char *)(encrypted), | 1372 | if (f->readBlock((char *)(encrypted), |
1377 | (unsigned long)(cryptLen)) | 1373 | (unsigned long)(cryptLen)) |
1378 | != (long)(cryptLen)) { | 1374 | != (long)(cryptLen)) { |
1379 | delete [] encrypted; | 1375 | delete [] encrypted; |
1380 | delete [] decrypted; | 1376 | delete [] decrypted; |
1381 | return e_readFile; | 1377 | return e_readFile; |
1382 | } | 1378 | } |
1383 | #endif | 1379 | #endif |
1384 | switch (algo) { | 1380 | switch (algo) { |
1385 | case PWM_CRYPT_BLOWFISH: { | 1381 | case PWM_CRYPT_BLOWFISH: { |
1386 | Blowfish bf; | 1382 | Blowfish bf; |
1387 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1383 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1388 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1384 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1389 | break; | 1385 | break; |
1390 | } | 1386 | } |
1391 | #ifndef PWM_EMBEDDED | 1387 | #ifndef PWM_EMBEDDED |
1392 | case PWM_CRYPT_AES128: | 1388 | case PWM_CRYPT_AES128: |
1393 | /*... fall through */ | 1389 | /*... fall through */ |
1394 | case PWM_CRYPT_AES192: | 1390 | case PWM_CRYPT_AES192: |
1395 | case PWM_CRYPT_AES256: | 1391 | case PWM_CRYPT_AES256: |
1396 | case PWM_CRYPT_3DES: | 1392 | case PWM_CRYPT_3DES: |
1397 | case PWM_CRYPT_TWOFISH: | 1393 | case PWM_CRYPT_TWOFISH: |
1398 | case PWM_CRYPT_TWOFISH128: { | 1394 | case PWM_CRYPT_TWOFISH128: { |
1399 | if (!LibGCryptIf::available()) | 1395 | if (!LibGCryptIf::available()) |
1400 | return e_cryptNotImpl; | 1396 | return e_cryptNotImpl; |
1401 | LibGCryptIf gc; | 1397 | LibGCryptIf gc; |
1402 | PwMerror err; | 1398 | PwMerror err; |
1403 | err = gc.decrypt(&decrypted, | 1399 | err = gc.decrypt(&decrypted, |
1404 | &cryptLen, | 1400 | &cryptLen, |
1405 | encrypted, | 1401 | encrypted, |
1406 | cryptLen, | 1402 | cryptLen, |
1407 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1403 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1408 | pw->length(), | 1404 | pw->length(), |
1409 | algo); | 1405 | algo); |
1410 | if (err != e_success) { | 1406 | if (err != e_success) { |
1411 | delete [] encrypted; | 1407 | delete [] encrypted; |
1412 | delete [] decrypted; | 1408 | delete [] decrypted; |
1413 | return e_cryptNotImpl; | 1409 | return e_cryptNotImpl; |
1414 | } | 1410 | } |
1415 | break; | 1411 | break; |
1416 | } | 1412 | } |
1417 | #endif | 1413 | #endif |
1418 | default: { | 1414 | default: { |
1419 | delete [] encrypted; | 1415 | delete [] encrypted; |
1420 | delete [] decrypted; | 1416 | delete [] decrypted; |
1421 | return e_cryptNotImpl; | 1417 | return e_cryptNotImpl; |
1422 | } } | 1418 | } } |
1423 | delete [] encrypted; | 1419 | delete [] encrypted; |
1424 | #ifndef PWM_EMBEDDED | 1420 | #ifndef PWM_EMBEDDED |
1425 | d->assign(reinterpret_cast<const char *>(decrypted), | 1421 | d->assign(reinterpret_cast<const char *>(decrypted), |
1426 | static_cast<string::size_type>(cryptLen)); | 1422 | static_cast<string::size_type>(cryptLen)); |
1427 | #else | 1423 | #else |
1428 | d->assign((const char *)(decrypted), | 1424 | d->assign((const char *)(decrypted), |
1429 | (string::size_type)(cryptLen)); | 1425 | (string::size_type)(cryptLen)); |
1430 | #endif | 1426 | #endif |
1431 | delete [] decrypted; | 1427 | delete [] decrypted; |
1432 | if (algo == PWM_CRYPT_BLOWFISH) { | 1428 | if (algo == PWM_CRYPT_BLOWFISH) { |
1433 | if (!Blowfish::unpadNull(d)) { | 1429 | if (!Blowfish::unpadNull(d)) { |
1434 | BUG(); | 1430 | BUG(); |
1435 | return e_readFile; | 1431 | return e_readFile; |
1436 | } | 1432 | } |
1437 | } | 1433 | } |
1438 | return e_success; | 1434 | return e_success; |
1439 | } | 1435 | } |
1440 | 1436 | ||
1441 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1437 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1442 | const string *dataStream) | 1438 | const string *dataStream) |
1443 | { | 1439 | { |
1444 | PWM_ASSERT(dataHash); | 1440 | PWM_ASSERT(dataHash); |
1445 | PWM_ASSERT(dataStream); | 1441 | PWM_ASSERT(dataStream); |
1446 | switch(dataHashType) { | 1442 | switch(dataHashType) { |
1447 | case PWM_HASH_SHA1: { | 1443 | case PWM_HASH_SHA1: { |
1448 | Sha1 hash; | 1444 | Sha1 hash; |
1449 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1445 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1450 | string ret = hash.sha1_read(); | 1446 | string ret = hash.sha1_read(); |
1451 | if (ret != *dataHash) | 1447 | if (ret != *dataHash) |
1452 | return e_fileCorrupt; | 1448 | return e_fileCorrupt; |
1453 | break; | 1449 | break; |
1454 | } | 1450 | } |
1455 | #ifndef PWM_EMBEDDED | 1451 | #ifndef PWM_EMBEDDED |
1456 | case PWM_HASH_SHA256: | 1452 | case PWM_HASH_SHA256: |
1457 | /*... fall through */ | 1453 | /*... fall through */ |
1458 | case PWM_HASH_SHA384: | 1454 | case PWM_HASH_SHA384: |
1459 | case PWM_HASH_SHA512: | 1455 | case PWM_HASH_SHA512: |
1460 | case PWM_HASH_MD5: | 1456 | case PWM_HASH_MD5: |
1461 | case PWM_HASH_RMD160: | 1457 | case PWM_HASH_RMD160: |
1462 | case PWM_HASH_TIGER: { | 1458 | case PWM_HASH_TIGER: { |
1463 | if (!LibGCryptIf::available()) | 1459 | if (!LibGCryptIf::available()) |
1464 | return e_hashNotImpl; | 1460 | return e_hashNotImpl; |
1465 | LibGCryptIf gc; | 1461 | LibGCryptIf gc; |
1466 | PwMerror err; | 1462 | PwMerror err; |
1467 | unsigned char *buf; | 1463 | unsigned char *buf; |
1468 | size_t hashLen; | 1464 | size_t hashLen; |
1469 | err = gc.hash(&buf, | 1465 | err = gc.hash(&buf, |
1470 | &hashLen, | 1466 | &hashLen, |
1471 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1467 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1472 | dataStream->length(), | 1468 | dataStream->length(), |
1473 | dataHashType); | 1469 | dataHashType); |
1474 | if (err != e_success) | 1470 | if (err != e_success) |
1475 | return e_hashNotImpl; | 1471 | return e_hashNotImpl; |
1476 | string calcHash(reinterpret_cast<const char *>(buf), | 1472 | string calcHash(reinterpret_cast<const char *>(buf), |
1477 | static_cast<string::size_type>(hashLen)); | 1473 | static_cast<string::size_type>(hashLen)); |
1478 | delete [] buf; | 1474 | delete [] buf; |
1479 | if (calcHash != *dataHash) | 1475 | if (calcHash != *dataHash) |
1480 | return e_fileCorrupt; | 1476 | return e_fileCorrupt; |
1481 | break; | 1477 | break; |
1482 | } | 1478 | } |
1483 | #endif | 1479 | #endif |
1484 | default: | 1480 | default: |
1485 | return e_hashNotImpl; | 1481 | return e_hashNotImpl; |
1486 | } | 1482 | } |
1487 | return e_success; | 1483 | return e_success; |
1488 | } | 1484 | } |
1489 | 1485 | ||
1490 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1486 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1491 | bool lock) | 1487 | bool lock) |
1492 | { | 1488 | { |
1493 | if (index >= numEntries(category)) { | 1489 | if (index >= numEntries(category)) { |
1494 | BUG(); | 1490 | BUG(); |
1495 | return false; | 1491 | return false; |
1496 | } | 1492 | } |
1497 | if (lock == dta[category].d[index].lockStat) | 1493 | if (lock == dta[category].d[index].lockStat) |
1498 | return true; | 1494 | return true; |
1499 | 1495 | ||
1500 | if (!lock && currentPw != "") { | 1496 | if (!lock && currentPw != "") { |
1501 | // "unlocking" and "password is already set" | 1497 | // "unlocking" and "password is already set" |
1502 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1498 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1503 | // unlocking without pw not allowed | 1499 | // unlocking without pw not allowed |
1504 | QString pw; | 1500 | QString pw; |
1505 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1501 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1506 | if (pw != "") { | 1502 | if (pw != "") { |
1507 | if (pw != currentPw) { | 1503 | if (pw != currentPw) { |
1508 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1504 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1509 | return false; | 1505 | return false; |
1510 | } else { | 1506 | } else { |
1511 | timer()->start(DocTimer::id_mpwTimer); | 1507 | timer()->start(DocTimer::id_mpwTimer); |
1512 | } | 1508 | } |
1513 | } else { | 1509 | } else { |
1514 | return false; | 1510 | return false; |
1515 | } | 1511 | } |
1516 | } else { | 1512 | } else { |
1517 | timer()->start(DocTimer::id_mpwTimer); | 1513 | timer()->start(DocTimer::id_mpwTimer); |
1518 | } | 1514 | } |
1519 | } | 1515 | } |
1520 | 1516 | ||
1521 | dta[category].d[index].lockStat = lock; | 1517 | dta[category].d[index].lockStat = lock; |
1522 | dta[category].d[index].rev++; // increment revision counter. | 1518 | dta[category].d[index].rev++; // increment revision counter. |
1523 | 1519 | ||
1524 | emitDataChanged(this); | 1520 | emitDataChanged(this); |
1525 | if (!lock) | 1521 | if (!lock) |
1526 | timer()->start(DocTimer::id_autoLockTimer); | 1522 | timer()->start(DocTimer::id_autoLockTimer); |
1527 | 1523 | ||
1528 | return true; | 1524 | return true; |
1529 | 1525 | ||
1530 | } | 1526 | } |
1531 | 1527 | ||
1532 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1528 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1533 | bool lock) | 1529 | bool lock) |
1534 | { | 1530 | { |
1535 | unsigned int cat = 0; | 1531 | unsigned int cat = 0; |
1536 | 1532 | ||
1537 | if (!findCategory(category, &cat)) { | 1533 | if (!findCategory(category, &cat)) { |
1538 | BUG(); | 1534 | BUG(); |
1539 | return false; | 1535 | return false; |
1540 | } | 1536 | } |
1541 | 1537 | ||
1542 | return lockAt(cat, index, lock); | 1538 | return lockAt(cat, index, lock); |
1543 | } | 1539 | } |
1544 | 1540 | ||
1545 | bool PwMDoc::lockAll(bool lock) | 1541 | bool PwMDoc::lockAll(bool lock) |
1546 | { | 1542 | { |
1547 | if (!lock && isDeepLocked()) { | 1543 | if (!lock && isDeepLocked()) { |
1548 | PwMerror ret; | 1544 | PwMerror ret; |
1549 | ret = deepLock(false); | 1545 | ret = deepLock(false); |
1550 | if (ret != e_success) | 1546 | if (ret != e_success) |
1551 | return false; | 1547 | return false; |
1552 | return true; | 1548 | return true; |
1553 | } | 1549 | } |
1554 | if (isDocEmpty()) { | 1550 | if (isDocEmpty()) { |
1555 | return true; | 1551 | return true; |
1556 | } | 1552 | } |
1557 | if (!lock && currentPw != "") { | 1553 | if (!lock && currentPw != "") { |
1558 | // unlocking and password is already set | 1554 | // unlocking and password is already set |
1559 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1555 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1560 | // unlocking without pw not allowed | 1556 | // unlocking without pw not allowed |
1561 | QString pw; | 1557 | QString pw; |
1562 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1558 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1563 | if (pw != "") { | 1559 | if (pw != "") { |
1564 | if (pw != currentPw) { | 1560 | if (pw != currentPw) { |
1565 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1561 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1566 | return false; | 1562 | return false; |
1567 | } else { | 1563 | } else { |
1568 | timer()->start(DocTimer::id_mpwTimer); | 1564 | timer()->start(DocTimer::id_mpwTimer); |
1569 | } | 1565 | } |
1570 | } else { | 1566 | } else { |
1571 | return false; | 1567 | return false; |
1572 | } | 1568 | } |
1573 | } else { | 1569 | } else { |
1574 | timer()->start(DocTimer::id_mpwTimer); | 1570 | timer()->start(DocTimer::id_mpwTimer); |
1575 | } | 1571 | } |
1576 | } | 1572 | } |
1577 | 1573 | ||
1578 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1574 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), |
1579 | catEnd = dta.end(), | 1575 | catEnd = dta.end(), |
1580 | catI = catBegin; | 1576 | catI = catBegin; |
1581 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1577 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1582 | while (catI != catEnd) { | 1578 | while (catI != catEnd) { |
1583 | entrBegin = catI->d.begin(); | 1579 | entrBegin = catI->d.begin(); |
1584 | entrEnd = catI->d.end(); | 1580 | entrEnd = catI->d.end(); |
1585 | entrI = entrBegin; | 1581 | entrI = entrBegin; |
1586 | while (entrI != entrEnd) { | 1582 | while (entrI != entrEnd) { |
1587 | entrI->lockStat = lock; | 1583 | entrI->lockStat = lock; |
1588 | entrI->rev++; // increment revision counter. | 1584 | entrI->rev++; // increment revision counter. |
1589 | ++entrI; | 1585 | ++entrI; |
1590 | } | 1586 | } |
1591 | ++catI; | 1587 | ++catI; |
1592 | } | 1588 | } |
1593 | 1589 | ||
1594 | emitDataChanged(this); | 1590 | emitDataChanged(this); |
1595 | if (lock) | 1591 | if (lock) |
1596 | timer()->stop(DocTimer::id_autoLockTimer); | 1592 | timer()->stop(DocTimer::id_autoLockTimer); |
1597 | else | 1593 | else |
1598 | timer()->start(DocTimer::id_autoLockTimer); | 1594 | timer()->start(DocTimer::id_autoLockTimer); |
1599 | 1595 | ||
1600 | return true; | 1596 | return true; |
1601 | } | 1597 | } |
1602 | 1598 | ||
1603 | bool PwMDoc::isLocked(const QString &category, unsigned int index) | 1599 | bool PwMDoc::isLocked(const QString &category, unsigned int index) |
1604 | { | 1600 | { |
1605 | unsigned int cat = 0; | 1601 | unsigned int cat = 0; |
1606 | 1602 | ||
1607 | if (!findCategory(category, &cat)) { | 1603 | if (!findCategory(category, &cat)) { |
1608 | BUG(); | 1604 | BUG(); |
1609 | return false; | 1605 | return false; |
1610 | } | 1606 | } |
1611 | 1607 | ||
1612 | return isLocked(cat, index); | 1608 | return isLocked(cat, index); |
1613 | } | 1609 | } |
1614 | 1610 | ||
1615 | bool PwMDoc::unlockAll_tempoary(bool revert) | 1611 | bool PwMDoc::unlockAll_tempoary(bool revert) |
1616 | { | 1612 | { |
1617 | static vector< vector<bool> > *oldLockStates = 0; | 1613 | static vector< vector<bool> > *oldLockStates = 0; |
1618 | static bool wasDeepLocked; | 1614 | static bool wasDeepLocked; |
1619 | 1615 | ||
1620 | if (revert) {// revert the unlocking | 1616 | if (revert) {// revert the unlocking |
1621 | if (oldLockStates) { | 1617 | if (oldLockStates) { |
1622 | /* we actually _have_ unlocked something, because | 1618 | /* we actually _have_ unlocked something, because |
1623 | * we have allocated space for the oldLockStates. | 1619 | * we have allocated space for the oldLockStates. |
1624 | * So, go on and revert them! | 1620 | * So, go on and revert them! |
1625 | */ | 1621 | */ |
1626 | if (wasDeepLocked) { | 1622 | if (wasDeepLocked) { |
1627 | PwMerror ret = deepLock(true); | 1623 | PwMerror ret = deepLock(true); |
1628 | if (ret == e_success) { | 1624 | if (ret == e_success) { |
1629 | /* deep-lock succeed. We are save. | 1625 | /* deep-lock succeed. We are save. |
1630 | * (but if it failed, just go on | 1626 | * (but if it failed, just go on |
1631 | * lock them normally) | 1627 | * lock them normally) |
1632 | */ | 1628 | */ |
1633 | delete_and_null(oldLockStates); | 1629 | delete_and_null(oldLockStates); |
1634 | timer()->start(DocTimer::id_autoLockTimer); | 1630 | timer()->start(DocTimer::id_autoLockTimer); |
1635 | printDebug("tempoary unlocking of dta " | 1631 | printDebug("tempoary unlocking of dta " |
1636 | "reverted by deep-locking."); | 1632 | "reverted by deep-locking."); |
1637 | return true; | 1633 | return true; |
1638 | } | 1634 | } |
1639 | printDebug("deep-lock failed while reverting! " | 1635 | printDebug("deep-lock failed while reverting! " |
1640 | "Falling back to normal-lock."); | 1636 | "Falling back to normal-lock."); |
1641 | } | 1637 | } |
1642 | if (unlikely(!wasDeepLocked && | 1638 | if (unlikely(!wasDeepLocked && |
1643 | numCategories() != oldLockStates->size())) { | 1639 | numCategories() != oldLockStates->size())) { |
1644 | /* DOH! We have modified "dta" while | 1640 | /* DOH! We have modified "dta" while |
1645 | * it was unlocked tempoary. DON'T DO THIS! | 1641 | * it was unlocked tempoary. DON'T DO THIS! |
1646 | */ | 1642 | */ |
1647 | BUG(); | 1643 | BUG(); |
1648 | delete_and_null(oldLockStates); | 1644 | delete_and_null(oldLockStates); |
1649 | timer()->start(DocTimer::id_autoLockTimer); | 1645 | timer()->start(DocTimer::id_autoLockTimer); |
1650 | return false; | 1646 | return false; |
1651 | } | 1647 | } |
1652 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1648 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), |
1653 | catEnd = dta.end(), | 1649 | catEnd = dta.end(), |
1654 | catI = catBegin; | 1650 | catI = catBegin; |
1655 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1651 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1656 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); | 1652 | vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin(); |
1657 | vector<bool>::iterator oldEntrStatBegin, | 1653 | vector<bool>::iterator oldEntrStatBegin, |
1658 | oldEntrStatEnd, | 1654 | oldEntrStatEnd, |
1659 | oldEntrStatI; | 1655 | oldEntrStatI; |
1660 | while (catI != catEnd) { | 1656 | while (catI != catEnd) { |
1661 | entrBegin = catI->d.begin(); | 1657 | entrBegin = catI->d.begin(); |
1662 | entrEnd = catI->d.end(); | 1658 | entrEnd = catI->d.end(); |
1663 | entrI = entrBegin; | 1659 | entrI = entrBegin; |
1664 | if (likely(!wasDeepLocked)) { | 1660 | if (likely(!wasDeepLocked)) { |
1665 | oldEntrStatBegin = oldCatStatI->begin(); | 1661 | oldEntrStatBegin = oldCatStatI->begin(); |
1666 | oldEntrStatEnd = oldCatStatI->end(); | 1662 | oldEntrStatEnd = oldCatStatI->end(); |
1667 | oldEntrStatI = oldEntrStatBegin; | 1663 | oldEntrStatI = oldEntrStatBegin; |
1668 | if (unlikely(catI->d.size() != oldCatStatI->size())) { | 1664 | if (unlikely(catI->d.size() != oldCatStatI->size())) { |
1669 | /* DOH! We have modified "dta" while | 1665 | /* DOH! We have modified "dta" while |
1670 | * it was unlocked tempoary. DON'T DO THIS! | 1666 | * it was unlocked tempoary. DON'T DO THIS! |
1671 | */ | 1667 | */ |
1672 | BUG(); | 1668 | BUG(); |
1673 | delete_and_null(oldLockStates); | 1669 | delete_and_null(oldLockStates); |
1674 | timer()->start(DocTimer::id_autoLockTimer); | 1670 | timer()->start(DocTimer::id_autoLockTimer); |
1675 | return false; | 1671 | return false; |
1676 | } | 1672 | } |
1677 | } | 1673 | } |
1678 | while (entrI != entrEnd) { | 1674 | while (entrI != entrEnd) { |
1679 | if (wasDeepLocked) { | 1675 | if (wasDeepLocked) { |
1680 | /* this is an error-fallback if | 1676 | /* this is an error-fallback if |
1681 | * deeplock didn't succeed | 1677 | * deeplock didn't succeed |
1682 | */ | 1678 | */ |
1683 | entrI->lockStat = true; | 1679 | entrI->lockStat = true; |
1684 | } else { | 1680 | } else { |
1685 | entrI->lockStat = *oldEntrStatI; | 1681 | entrI->lockStat = *oldEntrStatI; |
1686 | } | 1682 | } |
1687 | ++entrI; | 1683 | ++entrI; |
1688 | if (likely(!wasDeepLocked)) | 1684 | if (likely(!wasDeepLocked)) |
1689 | ++oldEntrStatI; | 1685 | ++oldEntrStatI; |
1690 | } | 1686 | } |
1691 | ++catI; | 1687 | ++catI; |
1692 | if (likely(!wasDeepLocked)) | 1688 | if (likely(!wasDeepLocked)) |
1693 | ++oldCatStatI; | 1689 | ++oldCatStatI; |
1694 | } | 1690 | } |
1695 | delete_and_null(oldLockStates); | 1691 | delete_and_null(oldLockStates); |
1696 | if (unlikely(wasDeepLocked)) { | 1692 | if (unlikely(wasDeepLocked)) { |
1697 | /* error fallback... */ | 1693 | /* error fallback... */ |
1698 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1694 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1699 | emitDataChanged(this); | 1695 | emitDataChanged(this); |
1700 | printDebug("WARNING: unlockAll_tempoary(true) " | 1696 | printDebug("WARNING: unlockAll_tempoary(true) " |
1701 | "deeplock fallback!"); | 1697 | "deeplock fallback!"); |
1702 | } | 1698 | } |
1703 | printDebug("tempoary unlocking of dta reverted."); | 1699 | printDebug("tempoary unlocking of dta reverted."); |
1704 | } else { | 1700 | } else { |
1705 | printDebug("unlockAll_tempoary(true): nothing to do."); | 1701 | printDebug("unlockAll_tempoary(true): nothing to do."); |
1706 | } | 1702 | } |
1707 | timer()->start(DocTimer::id_autoLockTimer); | 1703 | timer()->start(DocTimer::id_autoLockTimer); |
1708 | } else {// unlock all data tempoary | 1704 | } else {// unlock all data tempoary |
1709 | if (unlikely(oldLockStates != 0)) { | 1705 | if (unlikely(oldLockStates != 0)) { |
1710 | /* DOH! We have already unlocked the data tempoarly. | 1706 | /* DOH! We have already unlocked the data tempoarly. |
1711 | * No need to do it twice. ;) | 1707 | * No need to do it twice. ;) |
1712 | */ | 1708 | */ |
1713 | BUG(); | 1709 | BUG(); |
1714 | return false; | 1710 | return false; |
1715 | } | 1711 | } |
1716 | wasDeepLocked = false; | 1712 | wasDeepLocked = false; |
1717 | bool mustUnlock = false; | 1713 | bool mustUnlock = false; |
1718 | if (isDeepLocked()) { | 1714 | if (isDeepLocked()) { |
1719 | PwMerror ret; | 1715 | PwMerror ret; |
1720 | while (1) { | 1716 | while (1) { |
1721 | ret = deepLock(false); | 1717 | ret = deepLock(false); |
1722 | if (ret == e_success) { | 1718 | if (ret == e_success) { |
1723 | break; | 1719 | break; |
1724 | } else if (ret == e_wrongPw) { | 1720 | } else if (ret == e_wrongPw) { |
1725 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1721 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1726 | } else { | 1722 | } else { |
1727 | printDebug("deep-unlocking failed while " | 1723 | printDebug("deep-unlocking failed while " |
1728 | "tempoary unlocking!"); | 1724 | "tempoary unlocking!"); |
1729 | return false; | 1725 | return false; |
1730 | } | 1726 | } |
1731 | } | 1727 | } |
1732 | wasDeepLocked = true; | 1728 | wasDeepLocked = true; |
1733 | mustUnlock = true; | 1729 | mustUnlock = true; |
1734 | } else { | 1730 | } else { |
1735 | // first check if it's needed to unlock some entries | 1731 | // first check if it's needed to unlock some entries |
1736 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1732 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), |
1737 | catEnd = dta.end(), | 1733 | catEnd = dta.end(), |
1738 | catI = catBegin; | 1734 | catI = catBegin; |
1739 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1735 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1740 | while (catI != catEnd) { | 1736 | while (catI != catEnd) { |
1741 | entrBegin = catI->d.begin(); | 1737 | entrBegin = catI->d.begin(); |
1742 | entrEnd = catI->d.end(); | 1738 | entrEnd = catI->d.end(); |
1743 | entrI = entrBegin; | 1739 | entrI = entrBegin; |
1744 | while (entrI != entrEnd) { | 1740 | while (entrI != entrEnd) { |
1745 | if (entrI->lockStat == true) { | 1741 | if (entrI->lockStat == true) { |
1746 | mustUnlock = true; | 1742 | mustUnlock = true; |
1747 | break; | 1743 | break; |
1748 | } | 1744 | } |
1749 | ++entrI; | 1745 | ++entrI; |
1750 | } | 1746 | } |
1751 | if (mustUnlock) | 1747 | if (mustUnlock) |
1752 | break; | 1748 | break; |
1753 | ++catI; | 1749 | ++catI; |
1754 | } | 1750 | } |
1755 | } | 1751 | } |
1756 | if (!mustUnlock) { | 1752 | if (!mustUnlock) { |
1757 | // nothing to do. | 1753 | // nothing to do. |
1758 | timer()->stop(DocTimer::id_autoLockTimer); | 1754 | timer()->stop(DocTimer::id_autoLockTimer); |
1759 | printDebug("unlockAll_tempoary(): nothing to do."); | 1755 | printDebug("unlockAll_tempoary(): nothing to do."); |
1760 | return true; | 1756 | return true; |
1761 | } else if (!wasDeepLocked) { | 1757 | } else if (!wasDeepLocked) { |
1762 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && | 1758 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) && |
1763 | currentPw != "") { | 1759 | currentPw != "") { |
1764 | /* we can't unlock without mpw, so | 1760 | /* we can't unlock without mpw, so |
1765 | * we need to ask for it. | 1761 | * we need to ask for it. |
1766 | */ | 1762 | */ |
1767 | QString pw; | 1763 | QString pw; |
1768 | while (1) { | 1764 | while (1) { |
1769 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1765 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1770 | if (pw == "") { | 1766 | if (pw == "") { |
1771 | return false; | 1767 | return false; |
1772 | } else if (pw == currentPw) { | 1768 | } else if (pw == currentPw) { |
1773 | break; | 1769 | break; |
1774 | } | 1770 | } |
1775 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1771 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1776 | } | 1772 | } |
1777 | } | 1773 | } |
1778 | } | 1774 | } |
1779 | timer()->stop(DocTimer::id_autoLockTimer); | 1775 | timer()->stop(DocTimer::id_autoLockTimer); |
1780 | oldLockStates = new vector< vector<bool> >; | 1776 | oldLockStates = new vector< vector<bool> >; |
1781 | vector<bool> tmp_vec; | 1777 | vector<bool> tmp_vec; |
1782 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1778 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), |
1783 | catEnd = dta.end(), | 1779 | catEnd = dta.end(), |
1784 | catI = catBegin; | 1780 | catI = catBegin; |
1785 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1781 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1786 | while (catI != catEnd) { | 1782 | while (catI != catEnd) { |
1787 | entrBegin = catI->d.begin(); | 1783 | entrBegin = catI->d.begin(); |
1788 | entrEnd = catI->d.end(); | 1784 | entrEnd = catI->d.end(); |
1789 | entrI = entrBegin; | 1785 | entrI = entrBegin; |
1790 | while (entrI != entrEnd) { | 1786 | while (entrI != entrEnd) { |
1791 | if (!wasDeepLocked) { | 1787 | if (!wasDeepLocked) { |
1792 | tmp_vec.push_back(entrI->lockStat); | 1788 | tmp_vec.push_back(entrI->lockStat); |
1793 | } | 1789 | } |
1794 | entrI->lockStat = false; | 1790 | entrI->lockStat = false; |
1795 | ++entrI; | 1791 | ++entrI; |
1796 | } | 1792 | } |
1797 | if (!wasDeepLocked) { | 1793 | if (!wasDeepLocked) { |
1798 | oldLockStates->push_back(tmp_vec); | 1794 | oldLockStates->push_back(tmp_vec); |
1799 | tmp_vec.clear(); | 1795 | tmp_vec.clear(); |
1800 | } | 1796 | } |
1801 | ++catI; | 1797 | ++catI; |
1802 | } | 1798 | } |
1803 | printDebug("tempoary unlocked dta."); | 1799 | printDebug("tempoary unlocked dta."); |
1804 | } | 1800 | } |
1805 | 1801 | ||
1806 | return true; | 1802 | return true; |
1807 | } | 1803 | } |
1808 | 1804 | ||
1809 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) | 1805 | PwMerror PwMDoc::deepLock(bool lock, bool saveToFile) |
1810 | { | 1806 | { |
1811 | PwMerror ret; | 1807 | PwMerror ret; |
1812 | 1808 | ||
1813 | if (lock) { | 1809 | if (lock) { |
1814 | if (isDeepLocked()) | 1810 | if (isDeepLocked()) |
1815 | return e_lock; | 1811 | return e_lock; |
1816 | if (saveToFile) { | 1812 | if (saveToFile) { |
1817 | if (isDocEmpty()) | 1813 | if (isDocEmpty()) |
1818 | return e_docIsEmpty; | 1814 | return e_docIsEmpty; |
1819 | ret = saveDoc(conf()->confGlobCompression()); | 1815 | ret = saveDoc(conf()->confGlobCompression()); |
1820 | if (ret == e_filename) { | 1816 | if (ret == e_filename) { |
1821 | /* the doc wasn't saved to a file | 1817 | /* the doc wasn't saved to a file |
1822 | * by the user, yet. | 1818 | * by the user, yet. |
1823 | */ | 1819 | */ |
1824 | cantDeeplock_notSavedMsgBox(); | 1820 | cantDeeplock_notSavedMsgBox(); |
1825 | return e_docNotSaved; | 1821 | return e_docNotSaved; |
1826 | } else if (ret != e_success) { | 1822 | } else if (ret != e_success) { |
1827 | return e_lock; | 1823 | return e_lock; |
1828 | } | 1824 | } |
1829 | } | 1825 | } |
1830 | timer()->stop(DocTimer::id_autoLockTimer); | 1826 | timer()->stop(DocTimer::id_autoLockTimer); |
1831 | clearDoc(); | 1827 | clearDoc(); |
1832 | PwMDataItem d; | 1828 | PwMDataItem d; |
1833 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); | 1829 | d.desc = IS_DEEPLOCKED_SHORTMSG.latin1(); |
1834 | d.comment = IS_DEEPLOCKED_MSG.latin1(); | 1830 | d.comment = IS_DEEPLOCKED_MSG.latin1(); |
1835 | d.listViewPos = 0; | 1831 | d.listViewPos = 0; |
1836 | addEntry(DEFAULT_CATEGORY, &d, true); | 1832 | addEntry(DEFAULT_CATEGORY, &d, true); |
1837 | lockAt(DEFAULT_CATEGORY, 0, true); | 1833 | lockAt(DEFAULT_CATEGORY, 0, true); |
1838 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 1834 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
1839 | setDocStatFlag(DOC_STAT_DEEPLOCKED); | 1835 | setDocStatFlag(DOC_STAT_DEEPLOCKED); |
1840 | } else { | 1836 | } else { |
1841 | if (!isDeepLocked()) | 1837 | if (!isDeepLocked()) |
1842 | return e_lock; | 1838 | return e_lock; |
1843 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) | 1839 | ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen()) |
1844 | ? 0 : 1); | 1840 | ? 0 : 1); |
1845 | if (ret == e_wrongPw) { | 1841 | if (ret == e_wrongPw) { |
1846 | return e_wrongPw; | 1842 | return e_wrongPw; |
1847 | } else if (ret != e_success) { | 1843 | } else if (ret != e_success) { |
1848 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") | 1844 | printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ") |
1849 | + tostr(static_cast<int>(ret))); | 1845 | + tostr(static_cast<int>(ret))); |
1850 | return e_lock; | 1846 | return e_lock; |
1851 | } | 1847 | } |
1852 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); | 1848 | unsetDocStatFlag(DOC_STAT_DEEPLOCKED); |
1853 | timer()->start(DocTimer::id_autoLockTimer); | 1849 | timer()->start(DocTimer::id_autoLockTimer); |
1854 | } | 1850 | } |
1855 | 1851 | ||
1856 | emitDataChanged(this); | 1852 | emitDataChanged(this); |
1857 | return e_success; | 1853 | return e_success; |
1858 | } | 1854 | } |
1859 | 1855 | ||
1860 | void PwMDoc::_deepUnlock() | 1856 | void PwMDoc::_deepUnlock() |
1861 | { | 1857 | { |
1862 | deepLock(false); | 1858 | deepLock(false); |
1863 | } | 1859 | } |
1864 | 1860 | ||
1865 | void PwMDoc::clearDoc() | 1861 | void PwMDoc::clearDoc() |
1866 | { | 1862 | { |
1867 | dta.clear(); | 1863 | dta.clear(); |
1868 | PwMCategoryItem d; | 1864 | PwMCategoryItem d; |
1869 | d.name = DEFAULT_CATEGORY.latin1(); | 1865 | d.name = DEFAULT_CATEGORY.latin1(); |
1870 | dta.push_back(d); | 1866 | dta.push_back(d); |
1871 | currentPw = ""; | 1867 | currentPw = ""; |
1872 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 1868 | unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
1873 | } | 1869 | } |
1874 | 1870 | ||
1875 | void PwMDoc::changeCurrentPw() | 1871 | void PwMDoc::changeCurrentPw() |
1876 | { | 1872 | { |
1877 | if (currentPw == "") | 1873 | if (currentPw == "") |
1878 | return; // doc hasn't been saved. No mpw available. | 1874 | return; // doc hasn't been saved. No mpw available. |
1879 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1875 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1880 | QString pw = requestMpwChange(¤tPw, &useChipcard); | 1876 | QString pw = requestMpwChange(¤tPw, &useChipcard); |
1881 | if (pw == "") | 1877 | if (pw == "") |
1882 | return; | 1878 | return; |
1883 | if (useChipcard) | 1879 | if (useChipcard) |
1884 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1880 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1885 | else | 1881 | else |
1886 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 1882 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
1887 | setCurrentPw(pw); | 1883 | setCurrentPw(pw); |
1888 | } | 1884 | } |
1889 | 1885 | ||
1890 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, | 1886 | void PwMDoc::setListViewPos(const QString &category, unsigned int index, |
1891 | int pos) | 1887 | int pos) |
1892 | { | 1888 | { |
1893 | unsigned int cat = 0; | 1889 | unsigned int cat = 0; |
1894 | 1890 | ||
1895 | if (!findCategory(category, &cat)) { | 1891 | if (!findCategory(category, &cat)) { |
1896 | BUG(); | 1892 | BUG(); |
1897 | return; | 1893 | return; |
1898 | } | 1894 | } |
1899 | setListViewPos(cat, index, pos); | 1895 | setListViewPos(cat, index, pos); |
1900 | } | 1896 | } |
1901 | 1897 | ||
1902 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, | 1898 | void PwMDoc::setListViewPos(unsigned int category, unsigned int index, |
1903 | int pos) | 1899 | int pos) |
1904 | { | 1900 | { |
1905 | dta[category].d[index].listViewPos = pos; | 1901 | dta[category].d[index].listViewPos = pos; |
1906 | 1902 | ||
1907 | /* FIXME workaround: don't flag dirty, because this function sometimes | 1903 | /* FIXME workaround: don't flag dirty, because this function sometimes |
1908 | * get's called when it shouldn't. It's because PwMView assumes | 1904 | * get's called when it shouldn't. It's because PwMView assumes |
1909 | * the user resorted the UI on behalf of signal layoutChanged(). | 1905 | * the user resorted the UI on behalf of signal layoutChanged(). |
1910 | * This is somewhat broken and incorrect, but I've no other | 1906 | * This is somewhat broken and incorrect, but I've no other |
1911 | * solution for now. | 1907 | * solution for now. |
1912 | */ | 1908 | */ |
1913 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); | 1909 | //setDocStatFlag(DOC_STAT_DISK_DIRTY); |
1914 | } | 1910 | } |
1915 | 1911 | ||
1916 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) | 1912 | int PwMDoc::getListViewPos(const QString &category, unsigned int index) |
1917 | { | 1913 | { |
1918 | unsigned int cat = 0; | 1914 | unsigned int cat = 0; |
1919 | 1915 | ||
1920 | if (!findCategory(category, &cat)) { | 1916 | if (!findCategory(category, &cat)) { |
1921 | BUG(); | 1917 | BUG(); |
1922 | return -1; | 1918 | return -1; |
1923 | } | 1919 | } |
1924 | 1920 | ||
1925 | return dta[cat].d[index].listViewPos; | 1921 | return dta[cat].d[index].listViewPos; |
1926 | } | 1922 | } |
1927 | 1923 | ||
1928 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 1924 | void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
1929 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 1925 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
1930 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 1926 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
1931 | { | 1927 | { |
1932 | PWM_ASSERT(foundPositions); | 1928 | PWM_ASSERT(foundPositions); |
1933 | PWM_ASSERT(searchIn); | 1929 | PWM_ASSERT(searchIn); |
1934 | foundPositions->clear(); | 1930 | foundPositions->clear(); |
1935 | 1931 | ||
1936 | unsigned int i, entries = numEntries(category); | 1932 | unsigned int i, entries = numEntries(category); |
1937 | for (i = 0; i < entries; ++i) { | 1933 | for (i = 0; i < entries; ++i) { |
1938 | if (searchIn & SEARCH_IN_DESC) { | 1934 | if (searchIn & SEARCH_IN_DESC) { |
1939 | if (!compareString(find.desc, dta[category].d[i].desc, | 1935 | if (!compareString(find.desc, dta[category].d[i].desc, |
1940 | caseSensitive, exactWordMatch)) { | 1936 | caseSensitive, exactWordMatch)) { |
1941 | continue; | 1937 | continue; |
1942 | } | 1938 | } |
1943 | } | 1939 | } |
1944 | if (searchIn & SEARCH_IN_NAME) { | 1940 | if (searchIn & SEARCH_IN_NAME) { |
1945 | if (!compareString(find.name, dta[category].d[i].name, | 1941 | if (!compareString(find.name, dta[category].d[i].name, |
1946 | caseSensitive, exactWordMatch)) { | 1942 | caseSensitive, exactWordMatch)) { |
1947 | continue; | 1943 | continue; |
1948 | } | 1944 | } |
1949 | } | 1945 | } |
1950 | if (searchIn & SEARCH_IN_PW) { | 1946 | if (searchIn & SEARCH_IN_PW) { |
1951 | bool wasLocked = isLocked(category, i); | 1947 | bool wasLocked = isLocked(category, i); |
1952 | getDataChangedLock(); | 1948 | getDataChangedLock(); |
1953 | lockAt(category, i, false); | 1949 | lockAt(category, i, false); |
1954 | if (!compareString(find.pw, dta[category].d[i].pw, | 1950 | if (!compareString(find.pw, dta[category].d[i].pw, |
1955 | caseSensitive, exactWordMatch)) { | 1951 | caseSensitive, exactWordMatch)) { |
1956 | lockAt(category, i, wasLocked); | 1952 | lockAt(category, i, wasLocked); |
1957 | putDataChangedLock(); | 1953 | putDataChangedLock(); |
1958 | continue; | 1954 | continue; |
1959 | } | 1955 | } |
1960 | lockAt(category, i, wasLocked); | 1956 | lockAt(category, i, wasLocked); |
1961 | putDataChangedLock(); | 1957 | putDataChangedLock(); |
1962 | } | 1958 | } |
1963 | if (searchIn & SEARCH_IN_COMMENT) { | 1959 | if (searchIn & SEARCH_IN_COMMENT) { |
1964 | if (!compareString(find.comment, dta[category].d[i].comment, | 1960 | if (!compareString(find.comment, dta[category].d[i].comment, |
1965 | caseSensitive, exactWordMatch)) { | 1961 | caseSensitive, exactWordMatch)) { |
1966 | continue; | 1962 | continue; |
1967 | } | 1963 | } |
1968 | } | 1964 | } |
1969 | if (searchIn & SEARCH_IN_URL) { | 1965 | if (searchIn & SEARCH_IN_URL) { |
1970 | if (!compareString(find.url, dta[category].d[i].url, | 1966 | if (!compareString(find.url, dta[category].d[i].url, |
1971 | caseSensitive, exactWordMatch)) { | 1967 | caseSensitive, exactWordMatch)) { |
1972 | continue; | 1968 | continue; |
1973 | } | 1969 | } |
1974 | } | 1970 | } |
1975 | if (searchIn & SEARCH_IN_LAUNCHER) { | 1971 | if (searchIn & SEARCH_IN_LAUNCHER) { |
1976 | if (!compareString(find.launcher, dta[category].d[i].launcher, | 1972 | if (!compareString(find.launcher, dta[category].d[i].launcher, |
1977 | caseSensitive, exactWordMatch)) { | 1973 | caseSensitive, exactWordMatch)) { |
1978 | continue; | 1974 | continue; |
1979 | } | 1975 | } |
1980 | } | 1976 | } |
1981 | 1977 | ||
1982 | // all selected "searchIn" matched. | 1978 | // all selected "searchIn" matched. |
1983 | foundPositions->push_back(i); | 1979 | foundPositions->push_back(i); |
1984 | if (breakAfterFound) | 1980 | if (breakAfterFound) |
1985 | break; | 1981 | break; |
1986 | } | 1982 | } |
1987 | 1983 | ||
1988 | if (sortByLvp && foundPositions->size() > 1) { | 1984 | if (sortByLvp && foundPositions->size() > 1) { |
1989 | vector< pair<unsigned int /* foundPosition (real doc pos) */, | 1985 | vector< pair<unsigned int /* foundPosition (real doc pos) */, |
1990 | unsigned int /* lvp-pos */> > tmp_vec; | 1986 | unsigned int /* lvp-pos */> > tmp_vec; |
1991 | 1987 | ||
1992 | unsigned int i, items = foundPositions->size(); | 1988 | unsigned int i, items = foundPositions->size(); |
1993 | pair<unsigned int, unsigned int> tmp_pair; | 1989 | pair<unsigned int, unsigned int> tmp_pair; |
1994 | for (i = 0; i < items; ++i) { | 1990 | for (i = 0; i < items; ++i) { |
1995 | tmp_pair.first = (*foundPositions)[i]; | 1991 | tmp_pair.first = (*foundPositions)[i]; |
1996 | tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos; | 1992 | tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos; |
1997 | tmp_vec.push_back(tmp_pair); | 1993 | tmp_vec.push_back(tmp_pair); |
1998 | } | 1994 | } |
1999 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); | 1995 | sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater()); |
2000 | foundPositions->clear(); | 1996 | foundPositions->clear(); |
2001 | for (i = 0; i < items; ++i) { | 1997 | for (i = 0; i < items; ++i) { |
2002 | foundPositions->push_back(tmp_vec[i].first); | 1998 | foundPositions->push_back(tmp_vec[i].first); |
2003 | } | 1999 | } |
2004 | } | 2000 | } |
2005 | } | 2001 | } |
2006 | 2002 | ||
2007 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 2003 | void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
2008 | vector<unsigned int> *foundPositions, bool breakAfterFound, | 2004 | vector<unsigned int> *foundPositions, bool breakAfterFound, |
2009 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) | 2005 | bool caseSensitive, bool exactWordMatch, bool sortByLvp) |
2010 | { | 2006 | { |
2011 | PWM_ASSERT(foundPositions); | 2007 | PWM_ASSERT(foundPositions); |
2012 | unsigned int cat = 0; | 2008 | unsigned int cat = 0; |
2013 | 2009 | ||
2014 | if (!findCategory(category, &cat)) { | 2010 | if (!findCategory(category, &cat)) { |
2015 | foundPositions->clear(); | 2011 | foundPositions->clear(); |
2016 | return; | 2012 | return; |
2017 | } | 2013 | } |
2018 | 2014 | ||
2019 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, | 2015 | findEntry(cat, find, searchIn, foundPositions, breakAfterFound, |
2020 | caseSensitive, exactWordMatch, sortByLvp); | 2016 | caseSensitive, exactWordMatch, sortByLvp); |
2021 | } | 2017 | } |
2022 | 2018 | ||
2023 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, | 2019 | bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive, |
2024 | bool exactWordMatch) | 2020 | bool exactWordMatch) |
2025 | { | 2021 | { |
2026 | QString _s1(s1.c_str()); | 2022 | QString _s1(s1.c_str()); |
2027 | QString _s2(s2.c_str()); | 2023 | QString _s2(s2.c_str()); |
2028 | if (!caseSensitive) { | 2024 | if (!caseSensitive) { |
2029 | _s1 = _s1.lower(); | 2025 | _s1 = _s1.lower(); |
2030 | _s2 = _s2.lower(); | 2026 | _s2 = _s2.lower(); |
2031 | } | 2027 | } |
2032 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) | 2028 | if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1)) |
2033 | return true; | 2029 | return true; |
2034 | return false; | 2030 | return false; |
2035 | } | 2031 | } |
2036 | 2032 | ||
2037 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) | 2033 | bool PwMDoc::findCategory(const QString &name, unsigned int *index) |
2038 | { | 2034 | { |
2039 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2035 | vector<PwMCategoryItem>::iterator i = dta.begin(), |
2040 | end = dta.end(); | 2036 | end = dta.end(); |
2041 | while (i != end) { | 2037 | while (i != end) { |
2042 | if ((*i).name == name.latin1()) { | 2038 | if ((*i).name == name.latin1()) { |
2043 | if (index) { | 2039 | if (index) { |
2044 | *index = i - dta.begin(); | 2040 | *index = i - dta.begin(); |
2045 | } | 2041 | } |
2046 | return true; | 2042 | return true; |
2047 | } | 2043 | } |
2048 | ++i; | 2044 | ++i; |
2049 | } | 2045 | } |
2050 | return false; | 2046 | return false; |
2051 | } | 2047 | } |
2052 | 2048 | ||
2053 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) | 2049 | bool PwMDoc::renameCategory(const QString &category, const QString &newName) |
2054 | { | 2050 | { |
2055 | unsigned int cat = 0; | 2051 | unsigned int cat = 0; |
2056 | 2052 | ||
2057 | if (!findCategory(category, &cat)) | 2053 | if (!findCategory(category, &cat)) |
2058 | return false; | 2054 | return false; |
2059 | 2055 | ||
2060 | return renameCategory(cat, newName); | 2056 | return renameCategory(cat, newName); |
2061 | } | 2057 | } |
2062 | 2058 | ||
2063 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, | 2059 | bool PwMDoc::renameCategory(unsigned int category, const QString &newName, |
2064 | bool dontFlagDirty) | 2060 | bool dontFlagDirty) |
2065 | { | 2061 | { |
2066 | if (category > numCategories() - 1) | 2062 | if (category > numCategories() - 1) |
2067 | return false; | 2063 | return false; |
2068 | 2064 | ||
2069 | dta[category].name = newName.latin1(); | 2065 | dta[category].name = newName.latin1(); |
2070 | if (!dontFlagDirty) | 2066 | if (!dontFlagDirty) |
2071 | flagDirty(); | 2067 | flagDirty(); |
2072 | 2068 | ||
2073 | return true; | 2069 | return true; |
2074 | } | 2070 | } |
2075 | 2071 | ||
2076 | bool PwMDoc::delCategory(const QString &category) | 2072 | bool PwMDoc::delCategory(const QString &category) |
2077 | { | 2073 | { |
2078 | unsigned int cat = 0; | 2074 | unsigned int cat = 0; |
2079 | 2075 | ||
2080 | if (!findCategory(category, &cat)) | 2076 | if (!findCategory(category, &cat)) |
2081 | return false; | 2077 | return false; |
2082 | 2078 | ||
2083 | return delCategory(cat); | 2079 | return delCategory(cat); |
2084 | } | 2080 | } |
2085 | 2081 | ||
2086 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) | 2082 | bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty) |
2087 | { | 2083 | { |
2088 | if (category > numCategories() - 1) | 2084 | if (category > numCategories() - 1) |
2089 | return false; | 2085 | return false; |
2090 | 2086 | ||
2091 | // We don't delete it, if it is the last existing | 2087 | // We don't delete it, if it is the last existing |
2092 | // category! Instead we rename it to "Default". | 2088 | // category! Instead we rename it to "Default". |
2093 | if (numCategories() > 1) { | 2089 | if (numCategories() > 1) { |
2094 | dta.erase(dta.begin() + category); | 2090 | dta.erase(dta.begin() + category); |
2095 | } else { | 2091 | } else { |
2096 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); | 2092 | renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty); |
2097 | return true; | 2093 | return true; |
2098 | } | 2094 | } |
2099 | if (!dontFlagDirty) | 2095 | if (!dontFlagDirty) |
2100 | flagDirty(); | 2096 | flagDirty(); |
2101 | 2097 | ||
2102 | return true; | 2098 | return true; |
2103 | } | 2099 | } |
2104 | 2100 | ||
2105 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) | 2101 | void PwMDoc::delAllEmptyCat(bool dontFlagDirty) |
2106 | { | 2102 | { |
2107 | vector<PwMCategoryItem>::iterator begin = dta.begin(), | 2103 | vector<PwMCategoryItem>::iterator begin = dta.begin(), |
2108 | end = dta.end(), | 2104 | end = dta.end(), |
2109 | i = begin; | 2105 | i = begin; |
2110 | while (i != end) { | 2106 | while (i != end) { |
2111 | if (i->d.empty()) { | 2107 | if (i->d.empty()) { |
2112 | delCategory(begin - i, dontFlagDirty); | 2108 | delCategory(begin - i, dontFlagDirty); |
2113 | } | 2109 | } |
2114 | ++i; | 2110 | ++i; |
2115 | } | 2111 | } |
2116 | } | 2112 | } |
2117 | 2113 | ||
2118 | void PwMDoc::getCategoryList(vector<string> *list) | 2114 | void PwMDoc::getCategoryList(vector<string> *list) |
2119 | { | 2115 | { |
2120 | PWM_ASSERT(list); | 2116 | PWM_ASSERT(list); |
2121 | list->clear(); | 2117 | list->clear(); |
2122 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2118 | vector<PwMCategoryItem>::iterator i = dta.begin(), |
2123 | end = dta.end(); | 2119 | end = dta.end(); |
2124 | while (i != end) { | 2120 | while (i != end) { |
2125 | list->push_back(i->name); | 2121 | list->push_back(i->name); |
2126 | ++i; | 2122 | ++i; |
2127 | } | 2123 | } |
2128 | } | 2124 | } |
2129 | 2125 | ||
2130 | void PwMDoc::getCategoryList(QStringList *list) | 2126 | void PwMDoc::getCategoryList(QStringList *list) |
2131 | { | 2127 | { |
2132 | PWM_ASSERT(list); | 2128 | PWM_ASSERT(list); |
2133 | list->clear(); | 2129 | list->clear(); |
2134 | vector<PwMCategoryItem>::iterator i = dta.begin(), | 2130 | vector<PwMCategoryItem>::iterator i = dta.begin(), |
2135 | end = dta.end(); | 2131 | end = dta.end(); |
2136 | while (i != end) { | 2132 | while (i != end) { |
2137 | #ifndef PWM_EMBEDDED | 2133 | #ifndef PWM_EMBEDDED |
2138 | list->push_back(i->name.c_str()); | 2134 | list->push_back(i->name.c_str()); |
2139 | #else | 2135 | #else |
2140 | list->append(i->name.c_str()); | 2136 | list->append(i->name.c_str()); |
2141 | #endif | 2137 | #endif |
2142 | ++i; | 2138 | ++i; |
2143 | } | 2139 | } |
2144 | } | 2140 | } |
2145 | 2141 | ||
2146 | void PwMDoc::getEntryList(const QString &category, QStringList *list) | 2142 | void PwMDoc::getEntryList(const QString &category, QStringList *list) |
2147 | { | 2143 | { |
2148 | PWM_ASSERT(list); | 2144 | PWM_ASSERT(list); |
2149 | unsigned int cat = 0; | 2145 | unsigned int cat = 0; |
2150 | if (!findCategory(category, &cat)) { | 2146 | if (!findCategory(category, &cat)) { |
2151 | list->clear(); | 2147 | list->clear(); |
2152 | return; | 2148 | return; |
2153 | } | 2149 | } |
2154 | getEntryList(cat, list); | 2150 | getEntryList(cat, list); |
2155 | } | 2151 | } |
2156 | 2152 | ||
2157 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) | 2153 | void PwMDoc::getEntryList(const QString &category, vector<string> *list) |
2158 | { | 2154 | { |
2159 | PWM_ASSERT(list); | 2155 | PWM_ASSERT(list); |
2160 | unsigned int cat = 0; | 2156 | unsigned int cat = 0; |
2161 | if (!findCategory(category, &cat)) { | 2157 | if (!findCategory(category, &cat)) { |
2162 | list->clear(); | 2158 | list->clear(); |
2163 | return; | 2159 | return; |
2164 | } | 2160 | } |
2165 | getEntryList(cat, list); | 2161 | getEntryList(cat, list); |
2166 | } | 2162 | } |
2167 | 2163 | ||
2168 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) | 2164 | void PwMDoc::getEntryList(unsigned int category, vector<string> *list) |
2169 | { | 2165 | { |
2170 | PWM_ASSERT(list); | 2166 | PWM_ASSERT(list); |
2171 | list->clear(); | 2167 | list->clear(); |
2172 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2168 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), |
2173 | end = dta[category].d.end(), | 2169 | end = dta[category].d.end(), |
2174 | i = begin; | 2170 | i = begin; |
2175 | while (i != end) { | 2171 | while (i != end) { |
2176 | list->push_back(i->desc); | 2172 | list->push_back(i->desc); |
2177 | ++i; | 2173 | ++i; |
2178 | } | 2174 | } |
2179 | } | 2175 | } |
2180 | 2176 | ||
2181 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) | 2177 | void PwMDoc::getEntryList(unsigned int category, QStringList *list) |
2182 | { | 2178 | { |
2183 | PWM_ASSERT(list); | 2179 | PWM_ASSERT(list); |
2184 | list->clear(); | 2180 | list->clear(); |
2185 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), | 2181 | vector<PwMDataItem>::iterator begin = dta[category].d.begin(), |
2186 | end = dta[category].d.end(), | 2182 | end = dta[category].d.end(), |
2187 | i = begin; | 2183 | i = begin; |
2188 | while (i != end) { | 2184 | while (i != end) { |
2189 | #ifndef PWM_EMBEDDED | 2185 | #ifndef PWM_EMBEDDED |
2190 | list->push_back(i->desc.c_str()); | 2186 | list->push_back(i->desc.c_str()); |
2191 | #else | 2187 | #else |
2192 | list->append(i->desc.c_str()); | 2188 | list->append(i->desc.c_str()); |
2193 | #endif | 2189 | #endif |
2194 | ++i; | 2190 | ++i; |
2195 | } | 2191 | } |
2196 | } | 2192 | } |
2197 | 2193 | ||
2198 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) | 2194 | bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex) |
2199 | { | 2195 | { |
diff --git a/pwmanager/pwmanager/pwmprefs.cpp b/pwmanager/pwmanager/pwmprefs.cpp index d3847f6..7fd347f 100644 --- a/pwmanager/pwmanager/pwmprefs.cpp +++ b/pwmanager/pwmanager/pwmprefs.cpp | |||
@@ -1,300 +1,301 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of PwManager/Pi | 2 | This file is part of PwManager/Pi |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | 22 | ||
23 | $Id$ | 23 | $Id$ |
24 | */ | 24 | */ |
25 | 25 | ||
26 | 26 | ||
27 | #include <kconfig.h> | 27 | #include <kconfig.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | #include <kstaticdeleter.h> | 29 | #include <kstaticdeleter.h> |
30 | 30 | ||
31 | #include "pwmprefs.h" | 31 | #include "pwmprefs.h" |
32 | 32 | ||
33 | PWMPrefs *PWMPrefs::sInstance = 0; | 33 | PWMPrefs *PWMPrefs::sInstance = 0; |
34 | static KStaticDeleter<PWMPrefs> staticDeleter; | 34 | static KStaticDeleter<PWMPrefs> staticDeleter; |
35 | 35 | ||
36 | PWMPrefs::PWMPrefs() | 36 | PWMPrefs::PWMPrefs() |
37 | : KPimPrefs("pwmanagerrc") | 37 | : KPimPrefs("pwmanagerrc") |
38 | { | 38 | { |
39 | KPrefs::setCurrentGroup( "Global" ); | 39 | KPrefs::setCurrentGroup( "Global" ); |
40 | 40 | ||
41 | addItemString( "autoStart", &mAutoStart, "" ); | 41 | addItemString( "autoStart", &mAutoStart, "" ); |
42 | addItemString( "browserCommand", &mBrowserCommand, "" ); | 42 | addItemString( "browserCommand", &mBrowserCommand, "" ); |
43 | addItemString( "xtermCommand", &mXTermCommand, CONF_DEFAULT_XTERMCOMMAND); | 43 | addItemString( "xtermCommand", &mXTermCommand, CONF_DEFAULT_XTERMCOMMAND); |
44 | addItemFont( "entryFont", &mEntryFont); | 44 | addItemFont( "entryFont", &mEntryFont); |
45 | addItemInt( "pwTimeout", &mPwTimeout, CONF_DEFAULT_PWTIMEOUT ); | 45 | addItemInt( "pwTimeout", &mPwTimeout, CONF_DEFAULT_PWTIMEOUT ); |
46 | addItemInt( "lockTimeout", &mLockTimeout, CONF_DEFAULT_LOCKTIMEOUT ); | 46 | addItemInt( "lockTimeout", &mLockTimeout, CONF_DEFAULT_LOCKTIMEOUT ); |
47 | addItemInt( "compression", &mCompression, CONF_DEFAULT_COMPRESSION ); | 47 | addItemInt( "compression", &mCompression, CONF_DEFAULT_COMPRESSION ); |
48 | addItemInt( "filePermissions", &mFilePermissions, CONF_DEFAULT_FILEPERMISSIONS ); | 48 | addItemInt( "filePermissions", &mFilePermissions, CONF_DEFAULT_FILEPERMISSIONS ); |
49 | addItemInt( "minimizeLock", &mMinimizeLock, CONF_DEFAULT_MINIMIZELOCK ); | 49 | addItemInt( "minimizeLock", &mMinimizeLock, CONF_DEFAULT_MINIMIZELOCK ); |
50 | addItemBool( "unlockOnOpen", &mUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN ); | 50 | addItemBool( "unlockOnOpen", &mUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN ); |
51 | addItemBool( "tray", &mTray, CONF_DEFAULT_TRAY ); | 51 | addItemBool( "tray", &mTray, CONF_DEFAULT_TRAY ); |
52 | addItemBool( "makeFileBackup", &mMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP ); | 52 | addItemBool( "makeFileBackup", &mMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP ); |
53 | addItemBool( "autostartDeepLocked", &mAutostartDeeplocked, CONF_DEFAULT_AUTOSTART_DEEPL ); | 53 | addItemBool( "autostartDeepLocked", &mAutostartDeeplocked, CONF_DEFAULT_AUTOSTART_DEEPL ); |
54 | addItemBool( "autoDeepLock", &mAutoDeeplock, CONF_DEFAULT_AUTODEEPLOCK ); | 54 | addItemBool( "autoDeepLock", &mAutoDeeplock, CONF_DEFAULT_AUTODEEPLOCK ); |
55 | addItemBool( "kwalletEmu", &mKWalletEmu, CONF_DEFAULT_KWALLETEMU ); | 55 | addItemBool( "kwalletEmu", &mKWalletEmu, CONF_DEFAULT_KWALLETEMU ); |
56 | addItemBool( "newEntrLockStat", &mNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT ); | 56 | addItemBool( "newEntrLockStat", &mNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT ); |
57 | 57 | ||
58 | KPrefs::setCurrentGroup( "Wnd" ); | 58 | KPrefs::setCurrentGroup( "Wnd" ); |
59 | 59 | ||
60 | addItemSize( "MainWndSize", &mMainWndSize); | 60 | addItemSize( "MainWndSize", &mMainWndSize); |
61 | addItemInt( "MainViewStyle", &mMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE ); | 61 | addItemInt( "MainViewStyle", &mMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE ); |
62 | addItemBool( "autoMinimizeOnStart", &mAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE ); | 62 | addItemBool( "autoMinimizeOnStart", &mAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE ); |
63 | addItemBool( "close", &mClose, CONF_DEFAULT_WNDCLOSE ); | 63 | addItemBool( "close", &mClose, CONF_DEFAULT_WNDCLOSE ); |
64 | addItemIntList( "CommentSplitter", &mCommentSplitter ); | 64 | addItemIntList( "commentSplitter", &mCommentSplitter ); |
65 | addItemIntList( "categorySplitter", &mCategorySplitter ); | ||
65 | } | 66 | } |
66 | 67 | ||
67 | PWMPrefs::~PWMPrefs() | 68 | PWMPrefs::~PWMPrefs() |
68 | { | 69 | { |
69 | } | 70 | } |
70 | 71 | ||
71 | PWMPrefs *PWMPrefs::instance() | 72 | PWMPrefs *PWMPrefs::instance() |
72 | { | 73 | { |
73 | if ( !sInstance ) { | 74 | if ( !sInstance ) { |
74 | #ifdef PWM_EMBEDDED | 75 | #ifdef PWM_EMBEDDED |
75 | sInstance = staticDeleter.setObject( new PWMPrefs() ); | 76 | sInstance = staticDeleter.setObject( new PWMPrefs() ); |
76 | #else //PWM_EMBEDDED | 77 | #else //PWM_EMBEDDED |
77 | //US the following line has changed ???. Why | 78 | //US the following line has changed ???. Why |
78 | staticDeleter.setObject( sInstance, new PWMPrefs() ); | 79 | staticDeleter.setObject( sInstance, new PWMPrefs() ); |
79 | #endif //KAB_EMBEDDED | 80 | #endif //KAB_EMBEDDED |
80 | sInstance->readConfig(); | 81 | sInstance->readConfig(); |
81 | } | 82 | } |
82 | 83 | ||
83 | return sInstance; | 84 | return sInstance; |
84 | } | 85 | } |
85 | 86 | ||
86 | // US introduce a nonconst way to return the config object. | 87 | // US introduce a nonconst way to return the config object. |
87 | KConfig* PWMPrefs::getConfig() | 88 | KConfig* PWMPrefs::getConfig() |
88 | { | 89 | { |
89 | return config(); | 90 | return config(); |
90 | } | 91 | } |
91 | 92 | ||
92 | /******************************************************************* | 93 | /******************************************************************* |
93 | * functions for reading the configuration settings | 94 | * functions for reading the configuration settings |
94 | *******************************************************************/ | 95 | *******************************************************************/ |
95 | 96 | ||
96 | QString PWMPrefs::confGlobAutoStart() | 97 | QString PWMPrefs::confGlobAutoStart() |
97 | { | 98 | { |
98 | return mAutoStart; | 99 | return mAutoStart; |
99 | } | 100 | } |
100 | 101 | ||
101 | QString PWMPrefs::confGlobBrowserCommand() | 102 | QString PWMPrefs::confGlobBrowserCommand() |
102 | { | 103 | { |
103 | return mBrowserCommand; | 104 | return mBrowserCommand; |
104 | } | 105 | } |
105 | 106 | ||
106 | QString PWMPrefs::confGlobXtermCommand() | 107 | QString PWMPrefs::confGlobXtermCommand() |
107 | { | 108 | { |
108 | return mXTermCommand; | 109 | return mXTermCommand; |
109 | } | 110 | } |
110 | 111 | ||
111 | QFont PWMPrefs::confGlobEntryFont() | 112 | QFont PWMPrefs::confGlobEntryFont() |
112 | { | 113 | { |
113 | return mEntryFont; | 114 | return mEntryFont; |
114 | } | 115 | } |
115 | 116 | ||
116 | int PWMPrefs::confGlobPwTimeout() | 117 | int PWMPrefs::confGlobPwTimeout() |
117 | { | 118 | { |
118 | return mPwTimeout; | 119 | return mPwTimeout; |
119 | } | 120 | } |
120 | 121 | ||
121 | int PWMPrefs::confGlobLockTimeout() | 122 | int PWMPrefs::confGlobLockTimeout() |
122 | { | 123 | { |
123 | return mLockTimeout; | 124 | return mLockTimeout; |
124 | } | 125 | } |
125 | 126 | ||
126 | int PWMPrefs::confGlobCompression() | 127 | int PWMPrefs::confGlobCompression() |
127 | { | 128 | { |
128 | return mCompression; | 129 | return mCompression; |
129 | } | 130 | } |
130 | 131 | ||
131 | int PWMPrefs::confGlobFilePermissions() | 132 | int PWMPrefs::confGlobFilePermissions() |
132 | { | 133 | { |
133 | return mFilePermissions; | 134 | return mFilePermissions; |
134 | } | 135 | } |
135 | 136 | ||
136 | int PWMPrefs::confGlobMinimizeLock() | 137 | int PWMPrefs::confGlobMinimizeLock() |
137 | { | 138 | { |
138 | return mMinimizeLock; | 139 | return mMinimizeLock; |
139 | } | 140 | } |
140 | 141 | ||
141 | bool PWMPrefs::confGlobUnlockOnOpen() | 142 | bool PWMPrefs::confGlobUnlockOnOpen() |
142 | { | 143 | { |
143 | return mUnlockOnOpen; | 144 | return mUnlockOnOpen; |
144 | } | 145 | } |
145 | 146 | ||
146 | bool PWMPrefs::confGlobTray() | 147 | bool PWMPrefs::confGlobTray() |
147 | { | 148 | { |
148 | return mTray; | 149 | return mTray; |
149 | } | 150 | } |
150 | 151 | ||
151 | bool PWMPrefs::confGlobMakeFileBackup() | 152 | bool PWMPrefs::confGlobMakeFileBackup() |
152 | { | 153 | { |
153 | return mMakeFileBackup; | 154 | return mMakeFileBackup; |
154 | } | 155 | } |
155 | 156 | ||
156 | bool PWMPrefs::confGlobAutostartDeepLocked() | 157 | bool PWMPrefs::confGlobAutostartDeepLocked() |
157 | { | 158 | { |
158 | return mAutostartDeeplocked; | 159 | return mAutostartDeeplocked; |
159 | } | 160 | } |
160 | 161 | ||
161 | bool PWMPrefs::confGlobAutoDeepLock() | 162 | bool PWMPrefs::confGlobAutoDeepLock() |
162 | { | 163 | { |
163 | return mAutoDeeplock; | 164 | return mAutoDeeplock; |
164 | } | 165 | } |
165 | 166 | ||
166 | bool PWMPrefs::confGlobKwalletEmu() | 167 | bool PWMPrefs::confGlobKwalletEmu() |
167 | { | 168 | { |
168 | return mKWalletEmu; | 169 | return mKWalletEmu; |
169 | } | 170 | } |
170 | 171 | ||
171 | bool PWMPrefs::confGlobNewEntrLockStat() | 172 | bool PWMPrefs::confGlobNewEntrLockStat() |
172 | { | 173 | { |
173 | return mNewEntrLockStat; | 174 | return mNewEntrLockStat; |
174 | } | 175 | } |
175 | 176 | ||
176 | QSize PWMPrefs::confWndMainWndSize() | 177 | QSize PWMPrefs::confWndMainWndSize() |
177 | { | 178 | { |
178 | return mMainWndSize; | 179 | return mMainWndSize; |
179 | } | 180 | } |
180 | 181 | ||
181 | int PWMPrefs::confWndMainViewStyle() | 182 | int PWMPrefs::confWndMainViewStyle() |
182 | { | 183 | { |
183 | return mMainViewStyle; | 184 | return mMainViewStyle; |
184 | } | 185 | } |
185 | 186 | ||
186 | bool PWMPrefs::confWndAutoMinimizeOnStart() | 187 | bool PWMPrefs::confWndAutoMinimizeOnStart() |
187 | { | 188 | { |
188 | return mAutoMinimizeOnStart; | 189 | return mAutoMinimizeOnStart; |
189 | } | 190 | } |
190 | 191 | ||
191 | bool PWMPrefs::confWndClose() | 192 | bool PWMPrefs::confWndClose() |
192 | { | 193 | { |
193 | return mClose; | 194 | return mClose; |
194 | } | 195 | } |
195 | 196 | ||
196 | /******************************************************************* | 197 | /******************************************************************* |
197 | * functions for writing the configuration settings | 198 | * functions for writing the configuration settings |
198 | *******************************************************************/ | 199 | *******************************************************************/ |
199 | 200 | ||
200 | void PWMPrefs::confGlobAutoStart(const QString &e) | 201 | void PWMPrefs::confGlobAutoStart(const QString &e) |
201 | { | 202 | { |
202 | mAutoStart = e; | 203 | mAutoStart = e; |
203 | } | 204 | } |
204 | 205 | ||
205 | void PWMPrefs::confGlobBrowserCommand(const QString &e) | 206 | void PWMPrefs::confGlobBrowserCommand(const QString &e) |
206 | { | 207 | { |
207 | mBrowserCommand = e; | 208 | mBrowserCommand = e; |
208 | } | 209 | } |
209 | 210 | ||
210 | void PWMPrefs::confGlobXtermCommand(const QString &e) | 211 | void PWMPrefs::confGlobXtermCommand(const QString &e) |
211 | { | 212 | { |
212 | mXTermCommand = e; | 213 | mXTermCommand = e; |
213 | } | 214 | } |
214 | 215 | ||
215 | void PWMPrefs::confGlobEntryFont(const QFont &e) | 216 | void PWMPrefs::confGlobEntryFont(const QFont &e) |
216 | { | 217 | { |
217 | mEntryFont = e; | 218 | mEntryFont = e; |
218 | } | 219 | } |
219 | 220 | ||
220 | void PWMPrefs::confGlobPwTimeout(int e) | 221 | void PWMPrefs::confGlobPwTimeout(int e) |
221 | { | 222 | { |
222 | mPwTimeout = e; | 223 | mPwTimeout = e; |
223 | } | 224 | } |
224 | 225 | ||
225 | void PWMPrefs::confGlobLockTimeout(int e) | 226 | void PWMPrefs::confGlobLockTimeout(int e) |
226 | { | 227 | { |
227 | mLockTimeout = e; | 228 | mLockTimeout = e; |
228 | } | 229 | } |
229 | 230 | ||
230 | void PWMPrefs::confGlobCompression(int e) | 231 | void PWMPrefs::confGlobCompression(int e) |
231 | { | 232 | { |
232 | mCompression = e; | 233 | mCompression = e; |
233 | } | 234 | } |
234 | 235 | ||
235 | void PWMPrefs::confGlobFilePermissions(int e) | 236 | void PWMPrefs::confGlobFilePermissions(int e) |
236 | { | 237 | { |
237 | mFilePermissions = e; | 238 | mFilePermissions = e; |
238 | } | 239 | } |
239 | 240 | ||
240 | void PWMPrefs::confGlobMinimizeLock(int e) | 241 | void PWMPrefs::confGlobMinimizeLock(int e) |
241 | { | 242 | { |
242 | mMinimizeLock = e; | 243 | mMinimizeLock = e; |
243 | } | 244 | } |
244 | 245 | ||
245 | void PWMPrefs::confGlobUnlockOnOpen(bool e) | 246 | void PWMPrefs::confGlobUnlockOnOpen(bool e) |
246 | { | 247 | { |
247 | mUnlockOnOpen = e; | 248 | mUnlockOnOpen = e; |
248 | } | 249 | } |
249 | 250 | ||
250 | void PWMPrefs::confGlobTray(bool e) | 251 | void PWMPrefs::confGlobTray(bool e) |
251 | { | 252 | { |
252 | mTray = e; | 253 | mTray = e; |
253 | } | 254 | } |
254 | 255 | ||
255 | void PWMPrefs::confGlobMakeFileBackup(bool e) | 256 | void PWMPrefs::confGlobMakeFileBackup(bool e) |
256 | { | 257 | { |
257 | mMakeFileBackup = e; | 258 | mMakeFileBackup = e; |
258 | } | 259 | } |
259 | 260 | ||
260 | void PWMPrefs::confGlobAutostartDeepLocked(bool e) | 261 | void PWMPrefs::confGlobAutostartDeepLocked(bool e) |
261 | { | 262 | { |
262 | mAutostartDeeplocked = e; | 263 | mAutostartDeeplocked = e; |
263 | } | 264 | } |
264 | 265 | ||
265 | void PWMPrefs::confGlobAutoDeepLock(bool e) | 266 | void PWMPrefs::confGlobAutoDeepLock(bool e) |
266 | { | 267 | { |
267 | mAutoDeeplock = e; | 268 | mAutoDeeplock = e; |
268 | } | 269 | } |
269 | 270 | ||
270 | void PWMPrefs::confGlobKwalletEmu(bool e) | 271 | void PWMPrefs::confGlobKwalletEmu(bool e) |
271 | { | 272 | { |
272 | mKWalletEmu = e; | 273 | mKWalletEmu = e; |
273 | } | 274 | } |
274 | 275 | ||
275 | void PWMPrefs::confGlobNewEntrLockStat(bool e) | 276 | void PWMPrefs::confGlobNewEntrLockStat(bool e) |
276 | { | 277 | { |
277 | mNewEntrLockStat = e; | 278 | mNewEntrLockStat = e; |
278 | } | 279 | } |
279 | 280 | ||
280 | void PWMPrefs::confWndMainWndSize(const QSize &e) | 281 | void PWMPrefs::confWndMainWndSize(const QSize &e) |
281 | { | 282 | { |
282 | mMainWndSize = e; | 283 | mMainWndSize = e; |
283 | } | 284 | } |
284 | 285 | ||
285 | void PWMPrefs::confWndMainViewStyle(int e) | 286 | void PWMPrefs::confWndMainViewStyle(int e) |
286 | { | 287 | { |
287 | mMainViewStyle = e; | 288 | mMainViewStyle = e; |
288 | } | 289 | } |
289 | 290 | ||
290 | void PWMPrefs::confWndAutoMinimizeOnStart(bool e) | 291 | void PWMPrefs::confWndAutoMinimizeOnStart(bool e) |
291 | { | 292 | { |
292 | mAutoMinimizeOnStart = e; | 293 | mAutoMinimizeOnStart = e; |
293 | } | 294 | } |
294 | 295 | ||
295 | void PWMPrefs::confWndClose(bool e) | 296 | void PWMPrefs::confWndClose(bool e) |
296 | { | 297 | { |
297 | mClose = e; | 298 | mClose = e; |
298 | } | 299 | } |
299 | 300 | ||
300 | 301 | ||
diff --git a/pwmanager/pwmanager/pwmprefs.h b/pwmanager/pwmanager/pwmprefs.h index 6a89d10..9fed7d2 100644 --- a/pwmanager/pwmanager/pwmprefs.h +++ b/pwmanager/pwmanager/pwmprefs.h | |||
@@ -1,150 +1,151 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of PwManager/Pi | 2 | This file is part of PwManager/Pi |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | 22 | ||
23 | $Id$ | 23 | $Id$ |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #ifndef PWMPREFS_H | 26 | #ifndef PWMPREFS_H |
27 | #define PWMPREFS_H | 27 | #define PWMPREFS_H |
28 | 28 | ||
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | #include <qsize.h> | 30 | #include <qsize.h> |
31 | 31 | ||
32 | #include <kpimprefs.h> | 32 | #include <kpimprefs.h> |
33 | 33 | ||
34 | class KConfig; | 34 | class KConfig; |
35 | 35 | ||
36 | #define conf() PWMPrefs::instance() | 36 | #define conf() PWMPrefs::instance() |
37 | 37 | ||
38 | 38 | ||
39 | #define CONF_DEFAULT_PWTIMEOUT 10/* 10 sec */ | 39 | #define CONF_DEFAULT_PWTIMEOUT 10/* 10 sec */ |
40 | #define CONF_DEFAULT_LOCKTIMEOUT 0/* 0 == disable */ | 40 | #define CONF_DEFAULT_LOCKTIMEOUT 0/* 0 == disable */ |
41 | #define CONF_DEFAULT_TRAY true | 41 | #define CONF_DEFAULT_TRAY true |
42 | #define CONF_DEFAULT_UNLOCKONOPENfalse | 42 | #define CONF_DEFAULT_UNLOCKONOPENfalse |
43 | #define CONF_DEFAULT_MAINVIEWSTYLE0 | 43 | #define CONF_DEFAULT_MAINVIEWSTYLE0 |
44 | #define CONF_DEFAULT_COMPRESSION 0x01/* gzip */ | 44 | #define CONF_DEFAULT_COMPRESSION 0x01/* gzip */ |
45 | #define CONF_DEFAULT_AUTOMINIMIZEfalse | 45 | #define CONF_DEFAULT_AUTOMINIMIZEfalse |
46 | #define CONF_DEFAULT_BROWSERCOMMAND"" | 46 | #define CONF_DEFAULT_BROWSERCOMMAND"" |
47 | #define CONF_DEFAULT_XTERMCOMMAND"konsole -e" | 47 | #define CONF_DEFAULT_XTERMCOMMAND"konsole -e" |
48 | #define CONF_DEFAULT_FILEPERMISSIONS0600 | 48 | #define CONF_DEFAULT_FILEPERMISSIONS0600 |
49 | #define CONF_DEFAULT_MAKEFILEBACKUPfalse | 49 | #define CONF_DEFAULT_MAKEFILEBACKUPfalse |
50 | #define CONF_DEFAULT_AUTOSTART_DEEPLtrue | 50 | #define CONF_DEFAULT_AUTOSTART_DEEPLtrue |
51 | #define CONF_DEFAULT_AUTODEEPLOCKtrue | 51 | #define CONF_DEFAULT_AUTODEEPLOCKtrue |
52 | #define CONF_DEFAULT_KWALLETEMU true | 52 | #define CONF_DEFAULT_KWALLETEMU true |
53 | #define CONF_DEFAULT_MINIMIZELOCK 2/* deep-lock */ | 53 | #define CONF_DEFAULT_MINIMIZELOCK 2/* deep-lock */ |
54 | #define CONF_DEFAULT_NEWENTRLOCKSTAT true/* locked */ | 54 | #define CONF_DEFAULT_NEWENTRLOCKSTAT true/* locked */ |
55 | #define CONF_DEFAULT_WNDCLOSE true/* don't minimize to tray */ | 55 | #define CONF_DEFAULT_WNDCLOSE true/* don't minimize to tray */ |
56 | 56 | ||
57 | class PWMPrefs : public KPimPrefs | 57 | class PWMPrefs : public KPimPrefs |
58 | { | 58 | { |
59 | public: | 59 | public: |
60 | virtual ~PWMPrefs(); | 60 | virtual ~PWMPrefs(); |
61 | 61 | ||
62 | static PWMPrefs *instance(); | 62 | static PWMPrefs *instance(); |
63 | 63 | ||
64 | public: | 64 | public: |
65 | /* functions for reading the configuration settings */ | 65 | /* functions for reading the configuration settings */ |
66 | /* GLOBAL */ | 66 | /* GLOBAL */ |
67 | QString confGlobAutoStart(); | 67 | QString confGlobAutoStart(); |
68 | QString confGlobBrowserCommand(); | 68 | QString confGlobBrowserCommand(); |
69 | QString confGlobXtermCommand(); | 69 | QString confGlobXtermCommand(); |
70 | QFont confGlobEntryFont(); | 70 | QFont confGlobEntryFont(); |
71 | int confGlobPwTimeout(); | 71 | int confGlobPwTimeout(); |
72 | int confGlobLockTimeout(); | 72 | int confGlobLockTimeout(); |
73 | int confGlobCompression(); | 73 | int confGlobCompression(); |
74 | int confGlobFilePermissions(); | 74 | int confGlobFilePermissions(); |
75 | int confGlobMinimizeLock(); | 75 | int confGlobMinimizeLock(); |
76 | bool confGlobUnlockOnOpen(); | 76 | bool confGlobUnlockOnOpen(); |
77 | bool confGlobTray(); | 77 | bool confGlobTray(); |
78 | bool confGlobMakeFileBackup(); | 78 | bool confGlobMakeFileBackup(); |
79 | bool confGlobAutostartDeepLocked(); | 79 | bool confGlobAutostartDeepLocked(); |
80 | bool confGlobAutoDeepLock(); | 80 | bool confGlobAutoDeepLock(); |
81 | bool confGlobKwalletEmu(); | 81 | bool confGlobKwalletEmu(); |
82 | bool confGlobNewEntrLockStat(); | 82 | bool confGlobNewEntrLockStat(); |
83 | /* WND */ | 83 | /* WND */ |
84 | QSize confWndMainWndSize(); | 84 | QSize confWndMainWndSize(); |
85 | int confWndMainViewStyle(); | 85 | int confWndMainViewStyle(); |
86 | bool confWndAutoMinimizeOnStart(); | 86 | bool confWndAutoMinimizeOnStart(); |
87 | bool confWndClose(); | 87 | bool confWndClose(); |
88 | 88 | ||
89 | public: | 89 | public: |
90 | /* functions for writing the configuration settings */ | 90 | /* functions for writing the configuration settings */ |
91 | /* GLOBAL */ | 91 | /* GLOBAL */ |
92 | void confGlobAutoStart(const QString &e); | 92 | void confGlobAutoStart(const QString &e); |
93 | void confGlobBrowserCommand(const QString &e); | 93 | void confGlobBrowserCommand(const QString &e); |
94 | void confGlobXtermCommand(const QString &e); | 94 | void confGlobXtermCommand(const QString &e); |
95 | void confGlobEntryFont(const QFont &e); | 95 | void confGlobEntryFont(const QFont &e); |
96 | void confGlobPwTimeout(int e); | 96 | void confGlobPwTimeout(int e); |
97 | void confGlobLockTimeout(int e); | 97 | void confGlobLockTimeout(int e); |
98 | void confGlobCompression(int e); | 98 | void confGlobCompression(int e); |
99 | void confGlobFilePermissions(int e); | 99 | void confGlobFilePermissions(int e); |
100 | void confGlobMinimizeLock(int e); | 100 | void confGlobMinimizeLock(int e); |
101 | void confGlobUnlockOnOpen(bool e); | 101 | void confGlobUnlockOnOpen(bool e); |
102 | void confGlobTray(bool e); | 102 | void confGlobTray(bool e); |
103 | void confGlobMakeFileBackup(bool e); | 103 | void confGlobMakeFileBackup(bool e); |
104 | void confGlobAutostartDeepLocked(bool e); | 104 | void confGlobAutostartDeepLocked(bool e); |
105 | void confGlobAutoDeepLock(bool e); | 105 | void confGlobAutoDeepLock(bool e); |
106 | void confGlobKwalletEmu(bool e); | 106 | void confGlobKwalletEmu(bool e); |
107 | void confGlobNewEntrLockStat(bool e); | 107 | void confGlobNewEntrLockStat(bool e); |
108 | /* WND */ | 108 | /* WND */ |
109 | void confWndMainWndSize(const QSize &e); | 109 | void confWndMainWndSize(const QSize &e); |
110 | void confWndMainViewStyle(int e); | 110 | void confWndMainViewStyle(int e); |
111 | void confWndAutoMinimizeOnStart(bool e); | 111 | void confWndAutoMinimizeOnStart(bool e); |
112 | void confWndClose(bool e); | 112 | void confWndClose(bool e); |
113 | 113 | ||
114 | 114 | ||
115 | 115 | ||
116 | QString mAutoStart; | 116 | QString mAutoStart; |
117 | QString mBrowserCommand; | 117 | QString mBrowserCommand; |
118 | QString mXTermCommand; | 118 | QString mXTermCommand; |
119 | QFont mEntryFont; | 119 | QFont mEntryFont; |
120 | int mPwTimeout; | 120 | int mPwTimeout; |
121 | int mLockTimeout; | 121 | int mLockTimeout; |
122 | int mCompression; | 122 | int mCompression; |
123 | int mFilePermissions; | 123 | int mFilePermissions; |
124 | int mMinimizeLock; | 124 | int mMinimizeLock; |
125 | bool mUnlockOnOpen; | 125 | bool mUnlockOnOpen; |
126 | bool mTray; | 126 | bool mTray; |
127 | bool mMakeFileBackup; | 127 | bool mMakeFileBackup; |
128 | bool mAutostartDeeplocked; | 128 | bool mAutostartDeeplocked; |
129 | bool mAutoDeeplock; | 129 | bool mAutoDeeplock; |
130 | bool mKWalletEmu; | 130 | bool mKWalletEmu; |
131 | bool mNewEntrLockStat; | 131 | bool mNewEntrLockStat; |
132 | QSize mMainWndSize; | 132 | QSize mMainWndSize; |
133 | int mMainViewStyle; | 133 | int mMainViewStyle; |
134 | bool mAutoMinimizeOnStart; | 134 | bool mAutoMinimizeOnStart; |
135 | bool mClose; | 135 | bool mClose; |
136 | 136 | ||
137 | //US ENH | 137 | //US ENH |
138 | QValueList<int> mCommentSplitter; | 138 | QValueList<int> mCommentSplitter; |
139 | QValueList<int> mCategorySplitter; | ||
139 | 140 | ||
140 | 141 | ||
141 | // US introduce a nonconst way to return the config object. | 142 | // US introduce a nonconst way to return the config object. |
142 | KConfig* getConfig(); | 143 | KConfig* getConfig(); |
143 | 144 | ||
144 | private: | 145 | private: |
145 | PWMPrefs(); | 146 | PWMPrefs(); |
146 | 147 | ||
147 | static PWMPrefs *sInstance; | 148 | static PWMPrefs *sInstance; |
148 | }; | 149 | }; |
149 | 150 | ||
150 | #endif | 151 | #endif |
diff --git a/pwmanager/pwmanager/pwmviewstyle.cpp b/pwmanager/pwmanager/pwmviewstyle.cpp index 9704615..0af1473 100644 --- a/pwmanager/pwmanager/pwmviewstyle.cpp +++ b/pwmanager/pwmanager/pwmviewstyle.cpp | |||
@@ -1,239 +1,239 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 1.0.1 of pwmanager | 15 | * This file is originaly based on version 1.0.1 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "pwmviewstyle.h" | 21 | #include "pwmviewstyle.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | #include "pwmviewstyle_0.h" | 23 | #include "pwmviewstyle_0.h" |
24 | #include "pwmviewstyle_1.h" | 24 | #include "pwmviewstyle_1.h" |
25 | #include "listviewpwm.h" | 25 | #include "listviewpwm.h" |
26 | #include "pwmview.h" | 26 | #include "pwmview.h" |
27 | #include "commentbox.h" | 27 | #include "commentbox.h" |
28 | #ifndef PWM_EMBEDDED | 28 | #ifndef PWM_EMBEDDED |
29 | #include "configuration.h" | 29 | #include "configuration.h" |
30 | #else | 30 | #else |
31 | #include "pwmprefs.h" | 31 | #include "pwmprefs.h" |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name) | 34 | PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name) |
35 | : QWidget(parent, name) | 35 | : QWidget(parent, name) |
36 | { | 36 | { |
37 | curStyle = style_notset; | 37 | curStyle = style_notset; |
38 | s0 = 0; | 38 | s0 = 0; |
39 | s1 = 0; | 39 | s1 = 0; |
40 | } | 40 | } |
41 | 41 | ||
42 | PwMViewStyle::~PwMViewStyle() | 42 | PwMViewStyle::~PwMViewStyle() |
43 | { | 43 | { |
44 | //US ENH : store the size of the listviewcolumns | 44 | //US ENH : store the size of the listviewcolumns |
45 | switch (curStyle) | 45 | switch (curStyle) |
46 | { | 46 | { |
47 | case style_0: | 47 | case style_0: |
48 | s0->saveSettings(PWMPrefs::instance()); | 48 | s0->saveSettings(PWMPrefs::instance()); |
49 | break; | 49 | break; |
50 | case style_1: | 50 | case style_1: |
51 | s1->saveSettings(PWMPrefs::instance()); | 51 | s1->saveSettings(PWMPrefs::instance()); |
52 | break; | 52 | break; |
53 | default: | 53 | default: |
54 | BUG(); | 54 | BUG(); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | PWMPrefs::instance()->getConfig()->sync(); | 58 | PWMPrefs::instance()->writeConfig(); |
59 | 59 | ||
60 | delete_ifnot_null(s0); | 60 | delete_ifnot_null(s0); |
61 | delete_ifnot_null(s1); | 61 | delete_ifnot_null(s1); |
62 | } | 62 | } |
63 | 63 | ||
64 | void PwMViewStyle::initStyle(style_t style) | 64 | void PwMViewStyle::initStyle(style_t style) |
65 | { | 65 | { |
66 | printDebug(string("initializing style ") + tostr(style)); | 66 | printDebug(string("initializing style ") + tostr(style)); |
67 | bool wasMaximized = v->isMaximized(); | 67 | bool wasMaximized = v->isMaximized(); |
68 | if (v->isVisible()) | 68 | if (v->isVisible()) |
69 | v->hide(); | 69 | v->hide(); |
70 | switch (style) { | 70 | switch (style) { |
71 | case style_0: | 71 | case style_0: |
72 | delete_ifnot_null(s0); | 72 | delete_ifnot_null(s0); |
73 | delete_ifnot_null(s1); | 73 | delete_ifnot_null(s1); |
74 | s0 = new PwMViewStyle_0(v); | 74 | s0 = new PwMViewStyle_0(v); |
75 | lv = s0->getLv(); | 75 | lv = s0->getLv(); |
76 | commentBox = s0->getCommentBox(); | 76 | commentBox = s0->getCommentBox(); |
77 | break; | 77 | break; |
78 | case style_1: | 78 | case style_1: |
79 | delete_ifnot_null(s0); | 79 | delete_ifnot_null(s0); |
80 | delete_ifnot_null(s1); | 80 | delete_ifnot_null(s1); |
81 | s1 = new PwMViewStyle_1(v); | 81 | s1 = new PwMViewStyle_1(v); |
82 | lv = s1->getLv(); | 82 | lv = s1->getLv(); |
83 | commentBox = s1->getCommentBox(); | 83 | commentBox = s1->getCommentBox(); |
84 | break; | 84 | break; |
85 | default: | 85 | default: |
86 | BUG(); | 86 | BUG(); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | curStyle = style; | 89 | curStyle = style; |
90 | connect(lv, SIGNAL(pressed(QListViewItem *)), | 90 | connect(lv, SIGNAL(pressed(QListViewItem *)), |
91 | v, SLOT(handleToggle(QListViewItem *))); | 91 | v, SLOT(handleToggle(QListViewItem *))); |
92 | connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), | 92 | connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), |
93 | v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int))); | 93 | v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int))); |
94 | connect(lv, SIGNAL(clicked(QListViewItem *)), | 94 | connect(lv, SIGNAL(clicked(QListViewItem *)), |
95 | v, SLOT(refreshCommentTextEdit(QListViewItem *))); | 95 | v, SLOT(refreshCommentTextEdit(QListViewItem *))); |
96 | lv->addColumn(i18n("Description"), 180); | 96 | lv->addColumn(i18n("Description"), 180); |
97 | lv->addColumn(i18n("Username"), 150); | 97 | lv->addColumn(i18n("Username"), 150); |
98 | lv->addColumn(i18n("Password"), 150); | 98 | lv->addColumn(i18n("Password"), 150); |
99 | lv->addColumn(i18n("URL"), 180); | 99 | lv->addColumn(i18n("URL"), 180); |
100 | lv->addColumn(i18n("Launcher"), 120); | 100 | lv->addColumn(i18n("Launcher"), 120); |
101 | v->tmpReEnableSort(); | 101 | v->tmpReEnableSort(); |
102 | 102 | ||
103 | //US ENH : load the size of the listviewcolumns | 103 | //US ENH : load the size of the listviewcolumns |
104 | switch (style) | 104 | switch (curStyle) |
105 | { | 105 | { |
106 | case style_0: | 106 | case style_0: |
107 | s0->restoreSettings(PWMPrefs::instance()); | 107 | s0->restoreSettings(PWMPrefs::instance()); |
108 | break; | 108 | break; |
109 | case style_1: | 109 | case style_1: |
110 | s1->restoreSettings(PWMPrefs::instance()); | 110 | s1->restoreSettings(PWMPrefs::instance()); |
111 | break; | 111 | break; |
112 | default: | 112 | default: |
113 | BUG(); | 113 | BUG(); |
114 | } | 114 | } |
115 | 115 | ||
116 | resizeView(v->size()); | 116 | resizeView(v->size()); |
117 | v->updateView(); | 117 | v->updateView(); |
118 | if (wasMaximized) { | 118 | if (wasMaximized) { |
119 | v->showMaximized(); | 119 | v->showMaximized(); |
120 | } else { | 120 | } else { |
121 | v->show(); | 121 | v->show(); |
122 | } | 122 | } |
123 | connect(lv, SIGNAL(layoutChanged()), | 123 | connect(lv, SIGNAL(layoutChanged()), |
124 | v, SLOT(reorgLp())); | 124 | v, SLOT(reorgLp())); |
125 | } | 125 | } |
126 | 126 | ||
127 | void PwMViewStyle::resizeView(const QSize &size) | 127 | void PwMViewStyle::resizeView(const QSize &size) |
128 | { | 128 | { |
129 | switch (curStyle) { | 129 | switch (curStyle) { |
130 | case style_0: | 130 | case style_0: |
131 | PWM_ASSERT(s0); | 131 | PWM_ASSERT(s0); |
132 | s0->resize(size); | 132 | s0->resize(size); |
133 | return; | 133 | return; |
134 | case style_1: | 134 | case style_1: |
135 | PWM_ASSERT(s1); | 135 | PWM_ASSERT(s1); |
136 | s1->resize(size); | 136 | s1->resize(size); |
137 | return; | 137 | return; |
138 | default: | 138 | default: |
139 | BUG(); | 139 | BUG(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | QString PwMViewStyle::getCurrentCategory() | 143 | QString PwMViewStyle::getCurrentCategory() |
144 | { | 144 | { |
145 | switch (curStyle) { | 145 | switch (curStyle) { |
146 | case style_0: | 146 | case style_0: |
147 | PWM_ASSERT(s0); | 147 | PWM_ASSERT(s0); |
148 | return s0->getCurrentCategory(); | 148 | return s0->getCurrentCategory(); |
149 | case style_1: | 149 | case style_1: |
150 | PWM_ASSERT(s1); | 150 | PWM_ASSERT(s1); |
151 | return s1->getCurrentCategory(); | 151 | return s1->getCurrentCategory(); |
152 | default: | 152 | default: |
153 | BUG(); | 153 | BUG(); |
154 | } | 154 | } |
155 | return ""; | 155 | return ""; |
156 | } | 156 | } |
157 | 157 | ||
158 | void PwMViewStyle::addCategory(const QString &cat) | 158 | void PwMViewStyle::addCategory(const QString &cat) |
159 | { | 159 | { |
160 | switch (curStyle) { | 160 | switch (curStyle) { |
161 | case style_0: | 161 | case style_0: |
162 | PWM_ASSERT(s0); | 162 | PWM_ASSERT(s0); |
163 | s0->addCategory(cat); | 163 | s0->addCategory(cat); |
164 | return; | 164 | return; |
165 | case style_1: | 165 | case style_1: |
166 | PWM_ASSERT(s1); | 166 | PWM_ASSERT(s1); |
167 | s1->addCategory(cat); | 167 | s1->addCategory(cat); |
168 | return; | 168 | return; |
169 | default: | 169 | default: |
170 | BUG(); | 170 | BUG(); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | void PwMViewStyle::delCategory(const QString &cat) | 174 | void PwMViewStyle::delCategory(const QString &cat) |
175 | { | 175 | { |
176 | switch (curStyle) { | 176 | switch (curStyle) { |
177 | case style_0: | 177 | case style_0: |
178 | PWM_ASSERT(s0); | 178 | PWM_ASSERT(s0); |
179 | s0->delCategory(cat); | 179 | s0->delCategory(cat); |
180 | return; | 180 | return; |
181 | case style_1: | 181 | case style_1: |
182 | PWM_ASSERT(s1); | 182 | PWM_ASSERT(s1); |
183 | s1->delCategory(cat); | 183 | s1->delCategory(cat); |
184 | return; | 184 | return; |
185 | default: | 185 | default: |
186 | BUG(); | 186 | BUG(); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void PwMViewStyle::delAllCategories() | 190 | void PwMViewStyle::delAllCategories() |
191 | { | 191 | { |
192 | switch (curStyle) { | 192 | switch (curStyle) { |
193 | case style_0: | 193 | case style_0: |
194 | PWM_ASSERT(s0); | 194 | PWM_ASSERT(s0); |
195 | s0->delAllCategories(); | 195 | s0->delAllCategories(); |
196 | return; | 196 | return; |
197 | case style_1: | 197 | case style_1: |
198 | PWM_ASSERT(s1); | 198 | PWM_ASSERT(s1); |
199 | s1->delAllCategories(); | 199 | s1->delAllCategories(); |
200 | return; | 200 | return; |
201 | default: | 201 | default: |
202 | BUG(); | 202 | BUG(); |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | void PwMViewStyle::selectCategory(const QString &cat) | 206 | void PwMViewStyle::selectCategory(const QString &cat) |
207 | { | 207 | { |
208 | switch (curStyle) { | 208 | switch (curStyle) { |
209 | case style_0: | 209 | case style_0: |
210 | PWM_ASSERT(s0); | 210 | PWM_ASSERT(s0); |
211 | s0->selectCategory(cat); | 211 | s0->selectCategory(cat); |
212 | return; | 212 | return; |
213 | case style_1: | 213 | case style_1: |
214 | PWM_ASSERT(s1); | 214 | PWM_ASSERT(s1); |
215 | s1->selectCategory(cat); | 215 | s1->selectCategory(cat); |
216 | return; | 216 | return; |
217 | default: | 217 | default: |
218 | BUG(); | 218 | BUG(); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | int PwMViewStyle::numCategories() | 222 | int PwMViewStyle::numCategories() |
223 | { | 223 | { |
224 | switch (curStyle) { | 224 | switch (curStyle) { |
225 | case style_0: | 225 | case style_0: |
226 | PWM_ASSERT(s0); | 226 | PWM_ASSERT(s0); |
227 | return s0->numCategories(); | 227 | return s0->numCategories(); |
228 | case style_1: | 228 | case style_1: |
229 | PWM_ASSERT(s1); | 229 | PWM_ASSERT(s1); |
230 | return s1->numCategories(); | 230 | return s1->numCategories(); |
231 | default: | 231 | default: |
232 | BUG(); | 232 | BUG(); |
233 | } | 233 | } |
234 | return 0; | 234 | return 0; |
235 | } | 235 | } |
236 | 236 | ||
237 | #ifndef PWM_EMBEDDED | 237 | #ifndef PWM_EMBEDDED |
238 | #include "pwmviewstyle.moc" | 238 | #include "pwmviewstyle.moc" |
239 | #endif | 239 | #endif |
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.cpp b/pwmanager/pwmanager/pwmviewstyle_1.cpp index 8b2d6d3..374c698 100644 --- a/pwmanager/pwmanager/pwmviewstyle_1.cpp +++ b/pwmanager/pwmanager/pwmviewstyle_1.cpp | |||
@@ -1,150 +1,152 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmviewstyle_1.h" | 20 | #include "pwmviewstyle_1.h" |
21 | #include "pwmview.h" | 21 | #include "pwmview.h" |
22 | #include "listviewpwm.h" | 22 | #include "listviewpwm.h" |
23 | #include "commentbox.h" | 23 | #include "commentbox.h" |
24 | 24 | ||
25 | #include <klocale.h> | 25 | #include <klocale.h> |
26 | #include "pwmprefs.h" | 26 | #include "pwmprefs.h" |
27 | 27 | ||
28 | #define INITIAL_CATEGORIES_WIDTH100 | 28 | #define INITIAL_CATEGORIES_WIDTH100 |
29 | 29 | ||
30 | PwMViewStyle_1::PwMViewStyle_1(PwMView *view) | 30 | PwMViewStyle_1::PwMViewStyle_1(PwMView *view) |
31 | : QObject() | 31 | : QObject() |
32 | { | 32 | { |
33 | #ifndef PWM_EMBEDDED | 33 | #ifndef PWM_EMBEDDED |
34 | splitter = new QSplitter(view); | 34 | splitter = new QSplitter(view); |
35 | #else | 35 | #else |
36 | splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); | 36 | splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view); |
37 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 37 | splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
38 | 38 | ||
39 | //US topLayout->addWidget(mMiniSplitter ); | 39 | //US topLayout->addWidget(mMiniSplitter ); |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | vbox1 = new QVBox(splitter); | 42 | vbox1 = new QVBox(splitter); |
43 | categoriesTitle = new QLabel(vbox1); | 43 | categoriesTitle = new QLabel(vbox1); |
44 | categoriesList = new QListBox(vbox1); | 44 | categoriesList = new QListBox(vbox1); |
45 | #ifndef PWM_EMBEDDED | 45 | #ifndef PWM_EMBEDDED |
46 | splitter2 = new QSplitter(splitter); | 46 | splitter2 = new QSplitter(splitter); |
47 | splitter2->setOrientation(Qt::Vertical); | 47 | splitter2->setOrientation(Qt::Vertical); |
48 | #else | 48 | #else |
49 | splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); | 49 | splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter); |
50 | splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 50 | splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
51 | 51 | ||
52 | //US topLayout->addWidget(mMiniSplitter ); | 52 | //US topLayout->addWidget(mMiniSplitter ); |
53 | #endif | 53 | #endif |
54 | lv = new ListViewPwM(splitter2); | 54 | lv = new ListViewPwM(splitter2); |
55 | commentBox = new CommentBox(splitter2); | 55 | commentBox = new CommentBox(splitter2); |
56 | // set sizes and styles | 56 | // set sizes and styles |
57 | commentBox->resize(commentBox->size().width(), 60); | 57 | //UScommentBox->resize(commentBox->size().width(), 60); |
58 | QValueList<int> sizes; | 58 | QValueList<int> sizes; |
59 | #ifndef PWM_EMBEDDED | 59 | #ifndef PWM_EMBEDDED |
60 | sizes.push_back(INITIAL_CATEGORIES_WIDTH); | 60 | sizes.push_back(INITIAL_CATEGORIES_WIDTH); |
61 | sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); | 61 | sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH); |
62 | #else | 62 | #else |
63 | sizes.append(INITIAL_CATEGORIES_WIDTH); | 63 | sizes.append(INITIAL_CATEGORIES_WIDTH); |
64 | sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); | 64 | sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH); |
65 | #endif | 65 | #endif |
66 | splitter->setSizes(sizes); | 66 | //USsplitter->setSizes(sizes); |
67 | categoriesTitle->setAlignment(Qt::AlignHCenter); | 67 | categoriesTitle->setAlignment(Qt::AlignHCenter); |
68 | #ifndef PWM_EMBEDDED | 68 | #ifndef PWM_EMBEDDED |
69 | categoriesTitle->setFrameShape(QFrame::MenuBarPanel); | 69 | categoriesTitle->setFrameShape(QFrame::MenuBarPanel); |
70 | #else | 70 | #else |
71 | categoriesTitle->setFrameShape(QFrame::StyledPanel); | 71 | categoriesTitle->setFrameShape(QFrame::StyledPanel); |
72 | #endif | 72 | #endif |
73 | categoriesTitle->setText(i18n("Categories:")); | 73 | categoriesTitle->setText(i18n("Categories:")); |
74 | catCtxMenu = new QPopupMenu(view); | 74 | catCtxMenu = new QPopupMenu(view); |
75 | catCtxMenu->insertItem(i18n("&Rename"), | 75 | catCtxMenu->insertItem(i18n("&Rename"), |
76 | view, SLOT(renCatButton_slot())); | 76 | view, SLOT(renCatButton_slot())); |
77 | catCtxMenu->insertItem(i18n("&Delete"), | 77 | catCtxMenu->insertItem(i18n("&Delete"), |
78 | view, SLOT(delCatButton_slot())); | 78 | view, SLOT(delCatButton_slot())); |
79 | // connections | 79 | // connections |
80 | connect(categoriesList, SIGNAL(highlighted(int)), | 80 | connect(categoriesList, SIGNAL(highlighted(int)), |
81 | view, SLOT(shiftToView())); | 81 | view, SLOT(shiftToView())); |
82 | connect(categoriesList, | 82 | connect(categoriesList, |
83 | SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), | 83 | SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), |
84 | this, | 84 | this, |
85 | SLOT(catRightClick(QListBoxItem *, const QPoint &))); | 85 | SLOT(catRightClick(QListBoxItem *, const QPoint &))); |
86 | } | 86 | } |
87 | 87 | ||
88 | PwMViewStyle_1::~PwMViewStyle_1() | 88 | PwMViewStyle_1::~PwMViewStyle_1() |
89 | { | 89 | { |
90 | delete catCtxMenu; | 90 | delete catCtxMenu; |
91 | delete splitter; | 91 | delete splitter; |
92 | } | 92 | } |
93 | 93 | ||
94 | void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) | 94 | void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point) |
95 | { | 95 | { |
96 | if (!item) | 96 | if (!item) |
97 | return; | 97 | return; |
98 | catCtxMenu->move(point); | 98 | catCtxMenu->move(point); |
99 | catCtxMenu->show(); | 99 | catCtxMenu->show(); |
100 | } | 100 | } |
101 | 101 | ||
102 | void PwMViewStyle_1::delCategory(const QString &cat) | 102 | void PwMViewStyle_1::delCategory(const QString &cat) |
103 | { | 103 | { |
104 | PWM_ASSERT(categoriesList); | 104 | PWM_ASSERT(categoriesList); |
105 | int i, count = categoriesList->count(); | 105 | int i, count = categoriesList->count(); |
106 | for (i = 0; i < count; ++i) { | 106 | for (i = 0; i < count; ++i) { |
107 | if (categoriesList->text(i) == cat) { | 107 | if (categoriesList->text(i) == cat) { |
108 | categoriesList->removeItem(i); | 108 | categoriesList->removeItem(i); |
109 | return; | 109 | return; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | BUG(); | 112 | BUG(); |
113 | } | 113 | } |
114 | 114 | ||
115 | void PwMViewStyle_1::selectCategory(const QString &cat) | 115 | void PwMViewStyle_1::selectCategory(const QString &cat) |
116 | { | 116 | { |
117 | PWM_ASSERT(categoriesList); | 117 | PWM_ASSERT(categoriesList); |
118 | int i, count = categoriesList->count(); | 118 | int i, count = categoriesList->count(); |
119 | for (i = 0; i < count; ++i) { | 119 | for (i = 0; i < count; ++i) { |
120 | if (categoriesList->text(i) == cat) { | 120 | if (categoriesList->text(i) == cat) { |
121 | categoriesList->setCurrentItem(i); | 121 | categoriesList->setCurrentItem(i); |
122 | return; | 122 | return; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | // fall back to 0 | 125 | // fall back to 0 |
126 | categoriesList->setCurrentItem(0); | 126 | categoriesList->setCurrentItem(0); |
127 | } | 127 | } |
128 | 128 | ||
129 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 129 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
130 | void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs) | 130 | void PwMViewStyle_1::restoreSettings(PWMPrefs* prefs) |
131 | { | 131 | { |
132 | //load and store the size of the listviewcolumns | 132 | //load and store the size of the listviewcolumns |
133 | lv->restoreLayout(prefs->getConfig(), "listview"); | 133 | lv->restoreLayout(prefs->getConfig(), "listview"); |
134 | splitter->setSizes( prefs->mCategorySplitter ); | ||
134 | splitter2->setSizes( prefs->mCommentSplitter ); | 135 | splitter2->setSizes( prefs->mCommentSplitter ); |
135 | 136 | ||
136 | } | 137 | } |
137 | 138 | ||
138 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize | 139 | //US ENH: I need a place to load the view dependend settings. Eg. splittersize |
139 | void PwMViewStyle_1::saveSettings(PWMPrefs* prefs) | 140 | void PwMViewStyle_1::saveSettings(PWMPrefs* prefs) |
140 | { | 141 | { |
141 | //store the size of the listviewcolumns | 142 | //store the size of the listviewcolumns |
142 | lv->saveLayout(prefs->getConfig(), "listview"); | 143 | lv->saveLayout(prefs->getConfig(), "listview"); |
144 | prefs->mCategorySplitter = splitter->sizes(); | ||
143 | prefs->mCommentSplitter = splitter2->sizes(); | 145 | prefs->mCommentSplitter = splitter2->sizes(); |
144 | 146 | ||
145 | } | 147 | } |
146 | 148 | ||
147 | 149 | ||
148 | #ifndef PWM_EMBEDDED | 150 | #ifndef PWM_EMBEDDED |
149 | #include "pwmviewstyle_1.moc" | 151 | #include "pwmviewstyle_1.moc" |
150 | #endif | 152 | #endif |