-rw-r--r-- | pwmanager/pwmanager/configwnd.cpp | 11 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwm.cpp | 35 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmanagerE.pro | 27 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 2 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdocui.cpp | 1 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwminit.cpp | 19 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmtray.cpp | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmview.cpp | 4 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 1 |
10 files changed, 83 insertions, 23 deletions
diff --git a/pwmanager/pwmanager/configwnd.cpp b/pwmanager/pwmanager/configwnd.cpp index 230ca1b..108c40f 100644 --- a/pwmanager/pwmanager/configwnd.cpp +++ b/pwmanager/pwmanager/configwnd.cpp | |||
@@ -1,264 +1,265 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** Form implementation generated from reading ui file 'configwnd.ui' | 2 | ** Form implementation generated from reading ui file 'configwnd.ui' |
3 | ** | 3 | ** |
4 | ** Created: Tue Sep 14 15:20:58 2004 | 4 | ** Created: Tue Sep 14 15:20:58 2004 |
5 | ** by: The User Interface Compiler ($Id$) | 5 | ** by: The User Interface Compiler ($Id$) |
6 | ** | 6 | ** |
7 | ** WARNING! All changes made in this file will be lost! | 7 | ** WARNING! All changes made in this file will be lost! |
8 | ****************************************************************************/ | 8 | ****************************************************************************/ |
9 | 9 | ||
10 | #include "configwnd.h" | 10 | #include "configwnd.h" |
11 | 11 | ||
12 | #include <qvariant.h> | 12 | #include <qvariant.h> |
13 | #include <qpushbutton.h> | 13 | #include <qpushbutton.h> |
14 | #include <qtabwidget.h> | 14 | #include <qtabwidget.h> |
15 | #include <qwidget.h> | 15 | #include <qwidget.h> |
16 | #include <qcombobox.h> | 16 | #include <qcombobox.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | #include <qlineedit.h> | 18 | #include <qlineedit.h> |
19 | #include <qcheckbox.h> | 19 | #include <qcheckbox.h> |
20 | #include <qspinbox.h> | 20 | #include <qspinbox.h> |
21 | #include <qlayout.h> | 21 | #include <qlayout.h> |
22 | #include <qtooltip.h> | 22 | #include <qtooltip.h> |
23 | #include <qwhatsthis.h> | 23 | #include <qwhatsthis.h> |
24 | 24 | ||
25 | /* | 25 | /* |
26 | * Constructs a configWnd as a child of 'parent', with the | 26 | * Constructs a configWnd as a child of 'parent', with the |
27 | * name 'name' and widget flags set to 'f'. | 27 | * name 'name' and widget flags set to 'f'. |
28 | * | 28 | * |
29 | * The dialog will by default be modeless, unless you set 'modal' to | 29 | * The dialog will by default be modeless, unless you set 'modal' to |
30 | * TRUE to construct a modal dialog. | 30 | * TRUE to construct a modal dialog. |
31 | */ | 31 | */ |
32 | configWnd::configWnd( QWidget* parent, const char* name, bool modal, WFlags fl ) | 32 | configWnd::configWnd( QWidget* parent, const char* name, bool modal, WFlags fl ) |
33 | : QDialog( parent, name, modal, fl ) | 33 | : QDialog( parent, name, modal, fl ) |
34 | { | 34 | { |
35 | if ( !name ) | 35 | if ( !name ) |
36 | setName( "configWnd" ); | 36 | setName( "configWnd" ); |
37 | 37 | ||
38 | okButton = new QPushButton( this, "okButton" ); | 38 | okButton = new QPushButton( this, "okButton" ); |
39 | okButton->setGeometry( QRect( 10, 280, 107, 27 ) ); | 39 | okButton->setGeometry( QRect( 10, 280, 107, 27 ) ); |
40 | 40 | ||
41 | cancelButton = new QPushButton( this, "cancelButton" ); | 41 | cancelButton = new QPushButton( this, "cancelButton" ); |
42 | cancelButton->setGeometry( QRect( 370, 280, 107, 27 ) ); | 42 | cancelButton->setGeometry( QRect( 370, 280, 107, 27 ) ); |
43 | 43 | ||
44 | tabWidget2 = new QTabWidget( this, "tabWidget2" ); | 44 | tabWidget2 = new QTabWidget( this, "tabWidget2" ); |
45 | tabWidget2->setGeometry( QRect( 10, 10, 470, 260 ) ); | 45 | tabWidget2->setGeometry( QRect( 10, 10, 470, 260 ) ); |
46 | 46 | ||
47 | ////////////////////////////// | ||
47 | tab = new QWidget( tabWidget2, "tab" ); | 48 | tab = new QWidget( tabWidget2, "tab" ); |
48 | 49 | ||
49 | windowStyleComboBox = new QComboBox( FALSE, tab, "windowStyleComboBox" ); | 50 | windowStyleComboBox = new QComboBox( FALSE, tab, "windowStyleComboBox" ); |
50 | windowStyleComboBox->setGeometry( QRect( 220, 180, 210, 28 ) ); | 51 | windowStyleComboBox->setGeometry( QRect( 220, 180, 210, 28 ) ); |
51 | 52 | ||
52 | textLabel1_5 = new QLabel( tab, "textLabel1_5" ); | 53 | textLabel1_5 = new QLabel( tab, "textLabel1_5" ); |
53 | textLabel1_5->setGeometry( QRect( 30, 180, 180, 20 ) ); | 54 | textLabel1_5->setGeometry( QRect( 30, 180, 180, 20 ) ); |
54 | textLabel1_5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 55 | textLabel1_5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
55 | 56 | ||
56 | textLabel1_4 = new QLabel( tab, "textLabel1_4" ); | 57 | textLabel1_4 = new QLabel( tab, "textLabel1_4" ); |
57 | textLabel1_4->setGeometry( QRect( 30, 40, 400, 20 ) ); | 58 | textLabel1_4->setGeometry( QRect( 30, 40, 400, 20 ) ); |
58 | 59 | ||
59 | selEntrFontButton = new QPushButton( tab, "selEntrFontButton" ); | 60 | selEntrFontButton = new QPushButton( tab, "selEntrFontButton" ); |
60 | selEntrFontButton->setGeometry( QRect( 30, 90, 160, 27 ) ); | 61 | selEntrFontButton->setGeometry( QRect( 30, 90, 160, 27 ) ); |
61 | 62 | ||
62 | currEntrFont = new QLabel( tab, "currEntrFont" ); | 63 | currEntrFont = new QLabel( tab, "currEntrFont" ); |
63 | currEntrFont->setGeometry( QRect( 30, 70, 230, 20 ) ); | 64 | currEntrFont->setGeometry( QRect( 30, 70, 230, 20 ) ); |
64 | tabWidget2->insertTab( tab, QString("") ); | 65 | tabWidget2->insertTab( tab, QString("") ); |
65 | 66 | ////////////////////////////////////// | |
66 | TabPage = new QWidget( tabWidget2, "TabPage" ); | 67 | TabPage = new QWidget( tabWidget2, "TabPage" ); |
67 | 68 | ||
68 | compressionComboBox = new QComboBox( FALSE, TabPage, "compressionComboBox" ); | 69 | compressionComboBox = new QComboBox( FALSE, TabPage, "compressionComboBox" ); |
69 | compressionComboBox->setGeometry( QRect( 290, 50, 150, 28 ) ); | 70 | compressionComboBox->setGeometry( QRect( 290, 50, 150, 28 ) ); |
70 | 71 | ||
71 | textLabel1_6 = new QLabel( TabPage, "textLabel1_6" ); | 72 | textLabel1_6 = new QLabel( TabPage, "textLabel1_6" ); |
72 | textLabel1_6->setGeometry( QRect( 10, 50, 270, 20 ) ); | 73 | textLabel1_6->setGeometry( QRect( 10, 50, 270, 20 ) ); |
73 | textLabel1_6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 74 | textLabel1_6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
74 | 75 | ||
75 | textLabel1_8 = new QLabel( TabPage, "textLabel1_8" ); | 76 | textLabel1_8 = new QLabel( TabPage, "textLabel1_8" ); |
76 | textLabel1_8->setGeometry( QRect( 10, 90, 270, 20 ) ); | 77 | textLabel1_8->setGeometry( QRect( 10, 90, 270, 20 ) ); |
77 | textLabel1_8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 78 | textLabel1_8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
78 | 79 | ||
79 | permissionLineEdit = new QLineEdit( TabPage, "permissionLineEdit" ); | 80 | permissionLineEdit = new QLineEdit( TabPage, "permissionLineEdit" ); |
80 | permissionLineEdit->setGeometry( QRect( 290, 90, 142, 27 ) ); | 81 | permissionLineEdit->setGeometry( QRect( 290, 90, 142, 27 ) ); |
81 | permissionLineEdit->setMaxLength( 3 ); | 82 | permissionLineEdit->setMaxLength( 3 ); |
82 | 83 | ||
83 | fileBackupCheckBox = new QCheckBox( TabPage, "fileBackupCheckBox" ); | 84 | fileBackupCheckBox = new QCheckBox( TabPage, "fileBackupCheckBox" ); |
84 | fileBackupCheckBox->setGeometry( QRect( 80, 140, 360, 23 ) ); | 85 | fileBackupCheckBox->setGeometry( QRect( 80, 140, 360, 23 ) ); |
85 | tabWidget2->insertTab( TabPage, QString("") ); | 86 | tabWidget2->insertTab( TabPage, QString("") ); |
86 | 87 | ////////////////////////////////////// | |
87 | tab_2 = new QWidget( tabWidget2, "tab_2" ); | 88 | tab_2 = new QWidget( tabWidget2, "tab_2" ); |
88 | 89 | ||
89 | pwTimeoutSpinBox = new QSpinBox( tab_2, "pwTimeoutSpinBox" ); | 90 | pwTimeoutSpinBox = new QSpinBox( tab_2, "pwTimeoutSpinBox" ); |
90 | pwTimeoutSpinBox->setGeometry( QRect( 390, 50, 55, 23 ) ); | 91 | pwTimeoutSpinBox->setGeometry( QRect( 390, 50, 55, 23 ) ); |
91 | 92 | ||
92 | textLabel1 = new QLabel( tab_2, "textLabel1" ); | 93 | textLabel1 = new QLabel( tab_2, "textLabel1" ); |
93 | textLabel1->setGeometry( QRect( 10, 20, 370, 80 ) ); | 94 | textLabel1->setGeometry( QRect( 10, 20, 370, 80 ) ); |
94 | textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); | 95 | textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); |
95 | 96 | ||
96 | textLabel1_7 = new QLabel( tab_2, "textLabel1_7" ); | 97 | textLabel1_7 = new QLabel( tab_2, "textLabel1_7" ); |
97 | textLabel1_7->setGeometry( QRect( 10, 110, 370, 80 ) ); | 98 | textLabel1_7->setGeometry( QRect( 10, 110, 370, 80 ) ); |
98 | textLabel1_7->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); | 99 | textLabel1_7->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); |
99 | 100 | ||
100 | lockTimeoutSpinBox = new QSpinBox( tab_2, "lockTimeoutSpinBox" ); | 101 | lockTimeoutSpinBox = new QSpinBox( tab_2, "lockTimeoutSpinBox" ); |
101 | lockTimeoutSpinBox->setGeometry( QRect( 390, 140, 55, 23 ) ); | 102 | lockTimeoutSpinBox->setGeometry( QRect( 390, 140, 55, 23 ) ); |
102 | 103 | ||
103 | autoDeepLockCheckBox = new QCheckBox( tab_2, "autoDeepLockCheckBox" ); | 104 | autoDeepLockCheckBox = new QCheckBox( tab_2, "autoDeepLockCheckBox" ); |
104 | autoDeepLockCheckBox->setGeometry( QRect( 60, 180, 380, 25 ) ); | 105 | autoDeepLockCheckBox->setGeometry( QRect( 60, 180, 380, 25 ) ); |
105 | tabWidget2->insertTab( tab_2, QString("") ); | 106 | tabWidget2->insertTab( tab_2, QString("") ); |
106 | 107 | /////////////////////////////////////////// | |
107 | tab_3 = new QWidget( tabWidget2, "tab_3" ); | 108 | tab_3 = new QWidget( tabWidget2, "tab_3" ); |
108 | 109 | ||
109 | textLabel1_3 = new QLabel( tab_3, "textLabel1_3" ); | 110 | textLabel1_3 = new QLabel( tab_3, "textLabel1_3" ); |
110 | textLabel1_3->setGeometry( QRect( 30, 30, 400, 20 ) ); | 111 | textLabel1_3->setGeometry( QRect( 30, 30, 400, 20 ) ); |
111 | 112 | ||
112 | autoStartLineEdit = new QLineEdit( tab_3, "autoStartLineEdit" ); | 113 | autoStartLineEdit = new QLineEdit( tab_3, "autoStartLineEdit" ); |
113 | autoStartLineEdit->setGeometry( QRect( 30, 50, 360, 20 ) ); | 114 | autoStartLineEdit->setGeometry( QRect( 30, 50, 360, 20 ) ); |
114 | 115 | ||
115 | browseAutoStButton = new QPushButton( tab_3, "browseAutoStButton" ); | 116 | browseAutoStButton = new QPushButton( tab_3, "browseAutoStButton" ); |
116 | browseAutoStButton->setGeometry( QRect( 400, 50, 30, 20 ) ); | 117 | browseAutoStButton->setGeometry( QRect( 400, 50, 30, 20 ) ); |
117 | 118 | ||
118 | autostartDeeplockedCheckBox = new QCheckBox( tab_3, "autostartDeeplockedCheckBox" ); | 119 | autostartDeeplockedCheckBox = new QCheckBox( tab_3, "autostartDeeplockedCheckBox" ); |
119 | autostartDeeplockedCheckBox->setGeometry( QRect( 40, 80, 390, 25 ) ); | 120 | autostartDeeplockedCheckBox->setGeometry( QRect( 40, 80, 390, 25 ) ); |
120 | tabWidget2->insertTab( tab_3, QString("") ); | 121 | tabWidget2->insertTab( tab_3, QString("") ); |
121 | 122 | //////////////////////////////////////////// | |
122 | tab_4 = new QWidget( tabWidget2, "tab_4" ); | 123 | tab_4 = new QWidget( tabWidget2, "tab_4" ); |
123 | 124 | ||
124 | textLabel2 = new QLabel( tab_4, "textLabel2" ); | 125 | textLabel2 = new QLabel( tab_4, "textLabel2" ); |
125 | textLabel2->setGeometry( QRect( 20, 40, 280, 20 ) ); | 126 | textLabel2->setGeometry( QRect( 20, 40, 280, 20 ) ); |
126 | textLabel2->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 127 | textLabel2->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
127 | 128 | ||
128 | browserLineEdit = new QLineEdit( tab_4, "browserLineEdit" ); | 129 | browserLineEdit = new QLineEdit( tab_4, "browserLineEdit" ); |
129 | browserLineEdit->setGeometry( QRect( 310, 40, 130, 27 ) ); | 130 | browserLineEdit->setGeometry( QRect( 310, 40, 130, 27 ) ); |
130 | 131 | ||
131 | xtermLineEdit = new QLineEdit( tab_4, "xtermLineEdit" ); | 132 | xtermLineEdit = new QLineEdit( tab_4, "xtermLineEdit" ); |
132 | xtermLineEdit->setGeometry( QRect( 310, 100, 130, 27 ) ); | 133 | xtermLineEdit->setGeometry( QRect( 310, 100, 130, 27 ) ); |
133 | 134 | ||
134 | textLabel3 = new QLabel( tab_4, "textLabel3" ); | 135 | textLabel3 = new QLabel( tab_4, "textLabel3" ); |
135 | textLabel3->setGeometry( QRect( 20, 100, 280, 20 ) ); | 136 | textLabel3->setGeometry( QRect( 20, 100, 280, 20 ) ); |
136 | textLabel3->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 137 | textLabel3->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
137 | tabWidget2->insertTab( tab_4, QString("") ); | 138 | tabWidget2->insertTab( tab_4, QString("") ); |
138 | 139 | /////////////////////////////////////////////// | |
139 | tab_5 = new QWidget( tabWidget2, "tab_5" ); | 140 | tab_5 = new QWidget( tabWidget2, "tab_5" ); |
140 | 141 | ||
141 | trayCheckBox = new QCheckBox( tab_5, "trayCheckBox" ); | 142 | trayCheckBox = new QCheckBox( tab_5, "trayCheckBox" ); |
142 | trayCheckBox->setGeometry( QRect( 30, 30, 400, 20 ) ); | 143 | trayCheckBox->setGeometry( QRect( 30, 30, 400, 20 ) ); |
143 | 144 | ||
144 | openUnlockedCheckBox = new QCheckBox( tab_5, "openUnlockedCheckBox" ); | 145 | openUnlockedCheckBox = new QCheckBox( tab_5, "openUnlockedCheckBox" ); |
145 | openUnlockedCheckBox->setGeometry( QRect( 30, 80, 400, 20 ) ); | 146 | openUnlockedCheckBox->setGeometry( QRect( 30, 80, 400, 20 ) ); |
146 | 147 | ||
147 | autoMinimizeCheckBox = new QCheckBox( tab_5, "autoMinimizeCheckBox" ); | 148 | autoMinimizeCheckBox = new QCheckBox( tab_5, "autoMinimizeCheckBox" ); |
148 | autoMinimizeCheckBox->setEnabled( FALSE ); | 149 | autoMinimizeCheckBox->setEnabled( FALSE ); |
149 | autoMinimizeCheckBox->setGeometry( QRect( 50, 50, 380, 25 ) ); | 150 | autoMinimizeCheckBox->setGeometry( QRect( 50, 50, 380, 25 ) ); |
150 | 151 | ||
151 | minimizeLockComboBox = new QComboBox( FALSE, tab_5, "minimizeLockComboBox" ); | 152 | minimizeLockComboBox = new QComboBox( FALSE, tab_5, "minimizeLockComboBox" ); |
152 | minimizeLockComboBox->setGeometry( QRect( 310, 170, 120, 27 ) ); | 153 | minimizeLockComboBox->setGeometry( QRect( 310, 170, 120, 27 ) ); |
153 | 154 | ||
154 | textLabel1_9 = new QLabel( tab_5, "textLabel1_9" ); | 155 | textLabel1_9 = new QLabel( tab_5, "textLabel1_9" ); |
155 | textLabel1_9->setGeometry( QRect( 30, 180, 270, 20 ) ); | 156 | textLabel1_9->setGeometry( QRect( 30, 180, 270, 20 ) ); |
156 | textLabel1_9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); | 157 | textLabel1_9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); |
157 | 158 | ||
158 | kwalletEmuCheckBox = new QCheckBox( tab_5, "kwalletEmuCheckBox" ); | 159 | kwalletEmuCheckBox = new QCheckBox( tab_5, "kwalletEmuCheckBox" ); |
159 | kwalletEmuCheckBox->setGeometry( QRect( 30, 110, 400, 25 ) ); | 160 | kwalletEmuCheckBox->setGeometry( QRect( 30, 110, 400, 25 ) ); |
160 | 161 | ||
161 | wndCloseCheckBox = new QCheckBox( tab_5, "wndCloseCheckBox" ); | 162 | wndCloseCheckBox = new QCheckBox( tab_5, "wndCloseCheckBox" ); |
162 | wndCloseCheckBox->setGeometry( QRect( 30, 140, 430, 24 ) ); | 163 | wndCloseCheckBox->setGeometry( QRect( 30, 140, 430, 24 ) ); |
163 | tabWidget2->insertTab( tab_5, QString("") ); | 164 | tabWidget2->insertTab( tab_5, QString("") ); |
164 | languageChange(); | 165 | languageChange(); |
165 | resize( QSize(490, 318).expandedTo(minimumSizeHint()) ); | 166 | resize( QSize(490, 318).expandedTo(minimumSizeHint()) ); |
166 | clearWState( WState_Polished ); | 167 | clearWState( WState_Polished ); |
167 | 168 | ||
168 | // signals and slots connections | 169 | // signals and slots connections |
169 | connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) ); | 170 | connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) ); |
170 | connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) ); | 171 | connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) ); |
171 | connect( browseAutoStButton, SIGNAL( clicked() ), this, SLOT( browseAutoStButton_slot() ) ); | 172 | connect( browseAutoStButton, SIGNAL( clicked() ), this, SLOT( browseAutoStButton_slot() ) ); |
172 | connect( selEntrFontButton, SIGNAL( clicked() ), this, SLOT( selEntrFontButton_slot() ) ); | 173 | connect( selEntrFontButton, SIGNAL( clicked() ), this, SLOT( selEntrFontButton_slot() ) ); |
173 | connect( trayCheckBox, SIGNAL( toggled(bool) ), autoMinimizeCheckBox, SLOT( setEnabled(bool) ) ); | 174 | connect( trayCheckBox, SIGNAL( toggled(bool) ), autoMinimizeCheckBox, SLOT( setEnabled(bool) ) ); |
174 | 175 | ||
175 | // tab order | 176 | // tab order |
176 | setTabOrder( pwTimeoutSpinBox, trayCheckBox ); | 177 | setTabOrder( pwTimeoutSpinBox, trayCheckBox ); |
177 | setTabOrder( trayCheckBox, okButton ); | 178 | setTabOrder( trayCheckBox, okButton ); |
178 | setTabOrder( okButton, cancelButton ); | 179 | setTabOrder( okButton, cancelButton ); |
179 | } | 180 | } |
180 | 181 | ||
181 | /* | 182 | /* |
182 | * Destroys the object and frees any allocated resources | 183 | * Destroys the object and frees any allocated resources |
183 | */ | 184 | */ |
184 | configWnd::~configWnd() | 185 | configWnd::~configWnd() |
185 | { | 186 | { |
186 | // no need to delete child widgets, Qt does it all for us | 187 | // no need to delete child widgets, Qt does it all for us |
187 | } | 188 | } |
188 | 189 | ||
189 | /* | 190 | /* |
190 | * Sets the strings of the subwidgets using the current | 191 | * Sets the strings of the subwidgets using the current |
191 | * language. | 192 | * language. |
192 | */ | 193 | */ |
193 | void configWnd::languageChange() | 194 | void configWnd::languageChange() |
194 | { | 195 | { |
195 | setCaption( tr( "PwManager Configuration" ) ); | 196 | setCaption( tr( "PwManager Configuration" ) ); |
196 | okButton->setText( tr( "&OK" ) ); | 197 | okButton->setText( tr( "&OK" ) ); |
197 | //US ENH okButton->setAccel( QKeySequence( tr( "Alt+O" ) ) ); | 198 | //US ENH okButton->setAccel( QKeySequence( tr( "Alt+O" ) ) ); |
198 | cancelButton->setText( tr( "&Cancel" ) ); | 199 | cancelButton->setText( tr( "&Cancel" ) ); |
199 | //US ENH cancelButton->setAccel( QKeySequence( tr( "Alt+C" ) ) ); | 200 | //US ENH cancelButton->setAccel( QKeySequence( tr( "Alt+C" ) ) ); |
200 | windowStyleComboBox->clear(); | 201 | windowStyleComboBox->clear(); |
201 | windowStyleComboBox->insertItem( tr( "Category on top" ) ); | 202 | windowStyleComboBox->insertItem( tr( "Category on top" ) ); |
202 | windowStyleComboBox->insertItem( tr( "Category-list left" ) ); | 203 | windowStyleComboBox->insertItem( tr( "Category-list left" ) ); |
203 | textLabel1_5->setText( tr( "Window-style:" ) ); | 204 | textLabel1_5->setText( tr( "Window-style:" ) ); |
204 | textLabel1_4->setText( tr( "Font for the password entries:" ) ); | 205 | textLabel1_4->setText( tr( "Font for the password entries:" ) ); |
205 | selEntrFontButton->setText( tr( "select Font" ) ); | 206 | selEntrFontButton->setText( tr( "select Font" ) ); |
206 | currEntrFont->setText( QString::null ); | 207 | currEntrFont->setText( QString::null ); |
207 | tabWidget2->changeTab( tab, tr( "Look && feel" ) ); | 208 | tabWidget2->changeTab( tab, tr( "Look && feel" ) ); |
208 | compressionComboBox->clear(); | 209 | compressionComboBox->clear(); |
209 | compressionComboBox->insertItem( tr( "none" ) ); | 210 | compressionComboBox->insertItem( tr( "none" ) ); |
210 | compressionComboBox->insertItem( tr( "gzip" ) ); | 211 | compressionComboBox->insertItem( tr( "gzip" ) ); |
211 | compressionComboBox->insertItem( tr( "bzip2" ) ); | 212 | compressionComboBox->insertItem( tr( "bzip2" ) ); |
212 | textLabel1_6->setText( tr( "*.pwm file compression:" ) ); | 213 | textLabel1_6->setText( tr( "*.pwm file compression:" ) ); |
213 | textLabel1_8->setText( tr( "permissions:" ) ); | 214 | textLabel1_8->setText( tr( "permissions:" ) ); |
214 | fileBackupCheckBox->setText( tr( "Make file backup before saving" ) ); | 215 | fileBackupCheckBox->setText( tr( "Make file backup before saving" ) ); |
215 | tabWidget2->changeTab( TabPage, tr( "File" ) ); | 216 | tabWidget2->changeTab( TabPage, tr( "File" ) ); |
216 | textLabel1->setText( tr( "Password timeout (timeout to hold password in memory, so you don't have to re-enter it, if you already have entered it) [set to 0 to disable]:" ) ); | 217 | textLabel1->setText( tr( "Password timeout (timeout to hold password in memory, so you don't have to re-enter it, if you already have entered it) [set to 0 to disable]:" ) ); |
217 | textLabel1_7->setText( tr( "Auto-lock timeout (auto lock document after this amount of seconds) [set to 0 to disable]:" ) ); | 218 | textLabel1_7->setText( tr( "Auto-lock timeout (auto lock document after this amount of seconds) [set to 0 to disable]:" ) ); |
218 | autoDeepLockCheckBox->setText( tr( "deep-lock on autolock" ) ); | 219 | autoDeepLockCheckBox->setText( tr( "deep-lock on autolock" ) ); |
219 | tabWidget2->changeTab( tab_2, tr( "Timeout" ) ); | 220 | tabWidget2->changeTab( tab_2, tr( "Timeout" ) ); |
220 | textLabel1_3->setText( tr( "Open this file automatically on startup:" ) ); | 221 | textLabel1_3->setText( tr( "Open this file automatically on startup:" ) ); |
221 | browseAutoStButton->setText( tr( "..." ) ); | 222 | browseAutoStButton->setText( tr( "..." ) ); |
222 | autostartDeeplockedCheckBox->setText( tr( "open deeplocked" ) ); | 223 | autostartDeeplockedCheckBox->setText( tr( "open deeplocked" ) ); |
223 | tabWidget2->changeTab( tab_3, tr( "Autostart" ) ); | 224 | tabWidget2->changeTab( tab_3, tr( "Autostart" ) ); |
224 | textLabel2->setText( tr( "Favourite browser:" ) ); | 225 | textLabel2->setText( tr( "Favourite browser:" ) ); |
225 | textLabel3->setText( tr( "Favourite X-terminal:" ) ); | 226 | textLabel3->setText( tr( "Favourite X-terminal:" ) ); |
226 | tabWidget2->changeTab( tab_4, tr( "External apps" ) ); | 227 | tabWidget2->changeTab( tab_4, tr( "External apps" ) ); |
227 | trayCheckBox->setText( tr( "Show icon in system-tray" ) ); | 228 | trayCheckBox->setText( tr( "Show icon in system-tray" ) ); |
228 | openUnlockedCheckBox->setText( tr( "Open document with passwords unlocked" ) ); | 229 | openUnlockedCheckBox->setText( tr( "Open document with passwords unlocked" ) ); |
229 | autoMinimizeCheckBox->setText( tr( "auto-minimize to tray on startup" ) ); | 230 | autoMinimizeCheckBox->setText( tr( "auto-minimize to tray on startup" ) ); |
230 | minimizeLockComboBox->clear(); | 231 | minimizeLockComboBox->clear(); |
231 | minimizeLockComboBox->insertItem( tr( "don't lock" ) ); | 232 | minimizeLockComboBox->insertItem( tr( "don't lock" ) ); |
232 | minimizeLockComboBox->insertItem( tr( "normal lock" ) ); | 233 | minimizeLockComboBox->insertItem( tr( "normal lock" ) ); |
233 | minimizeLockComboBox->insertItem( tr( "deep-lock" ) ); | 234 | minimizeLockComboBox->insertItem( tr( "deep-lock" ) ); |
234 | textLabel1_9->setText( tr( "auto-lock on minimize:" ) ); | 235 | textLabel1_9->setText( tr( "auto-lock on minimize:" ) ); |
235 | kwalletEmuCheckBox->setText( tr( "KWallet emulation" ) ); | 236 | kwalletEmuCheckBox->setText( tr( "KWallet emulation" ) ); |
236 | wndCloseCheckBox->setText( tr( "Do not minimize windows into tray. (Close the window)" ) ); | 237 | wndCloseCheckBox->setText( tr( "Do not minimize windows into tray. (Close the window)" ) ); |
237 | tabWidget2->changeTab( tab_5, tr( "Miscellaneous" ) ); | 238 | tabWidget2->changeTab( tab_5, tr( "Miscellaneous" ) ); |
238 | } | 239 | } |
239 | 240 | ||
240 | void configWnd::okButton_slot() | 241 | void configWnd::okButton_slot() |
241 | { | 242 | { |
242 | qWarning( "configWnd::okButton_slot(): Not implemented yet" ); | 243 | qWarning( "configWnd::okButton_slot(): Not implemented yet" ); |
243 | } | 244 | } |
244 | 245 | ||
245 | void configWnd::cancelButton_slot() | 246 | void configWnd::cancelButton_slot() |
246 | { | 247 | { |
247 | qWarning( "configWnd::cancelButton_slot(): Not implemented yet" ); | 248 | qWarning( "configWnd::cancelButton_slot(): Not implemented yet" ); |
248 | } | 249 | } |
249 | 250 | ||
250 | void configWnd::browseBgButton_slot() | 251 | void configWnd::browseBgButton_slot() |
251 | { | 252 | { |
252 | qWarning( "configWnd::browseBgButton_slot(): Not implemented yet" ); | 253 | qWarning( "configWnd::browseBgButton_slot(): Not implemented yet" ); |
253 | } | 254 | } |
254 | 255 | ||
255 | void configWnd::browseAutoStButton_slot() | 256 | void configWnd::browseAutoStButton_slot() |
256 | { | 257 | { |
257 | qWarning( "configWnd::browseAutoStButton_slot(): Not implemented yet" ); | 258 | qWarning( "configWnd::browseAutoStButton_slot(): Not implemented yet" ); |
258 | } | 259 | } |
259 | 260 | ||
260 | void configWnd::selEntrFontButton_slot() | 261 | void configWnd::selEntrFontButton_slot() |
261 | { | 262 | { |
262 | qWarning( "configWnd::selEntrFontButton_slot(): Not implemented yet" ); | 263 | qWarning( "configWnd::selEntrFontButton_slot(): Not implemented yet" ); |
263 | } | 264 | } |
264 | 265 | ||
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp index e5579f8..08fcb25 100644 --- a/pwmanager/pwmanager/pwm.cpp +++ b/pwmanager/pwmanager/pwm.cpp | |||
@@ -1,1283 +1,1304 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include <klocale.h> | 20 | #include <klocale.h> |
21 | #include <klistview.h> | 21 | #include <klistview.h> |
22 | #include <ktoolbar.h> | 22 | #include <ktoolbar.h> |
23 | #include <kfiledialog.h> | 23 | #include <kfiledialog.h> |
24 | #include <kiconloader.h> | 24 | #include <kiconloader.h> |
25 | #include <kmessagebox.h> | 25 | #include <kmessagebox.h> |
26 | 26 | ||
27 | #ifndef PWM_EMBEDDED | 27 | #ifndef PWM_EMBEDDED |
28 | #include <kmenubar.h> | 28 | #include <kmenubar.h> |
29 | #include <kstatusbar.h> | 29 | #include <kstatusbar.h> |
30 | #include <dcopclient.h> | 30 | #include <dcopclient.h> |
31 | #include "configwndimpl.h" | ||
32 | #include "configuration.h" | ||
31 | #else | 33 | #else |
32 | #include <qmenubar.h> | 34 | #include <qmenubar.h> |
33 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | #include <pwmprefs.h> | ||
37 | #include <kpimglobalprefs.h> | ||
38 | #include <kcmconfigs/kcmpwmconfig.h> | ||
39 | #include <kcmconfigs/kcmkdepimconfig.h> | ||
40 | #include <kcmultidialog.h> | ||
34 | #endif | 41 | #endif |
35 | 42 | ||
36 | #include <qpixmap.h> | 43 | #include <qpixmap.h> |
37 | #include <qcheckbox.h> | 44 | #include <qcheckbox.h> |
38 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
39 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
40 | #include <qfileinfo.h> | 47 | #include <qfileinfo.h> |
41 | #include <qclipboard.h> | 48 | #include <qclipboard.h> |
42 | 49 | ||
43 | 50 | ||
44 | #include <stdio.h> | 51 | #include <stdio.h> |
45 | 52 | ||
46 | #include "pwm.h" | 53 | #include "pwm.h" |
47 | #include "pwminit.h" | 54 | #include "pwminit.h" |
48 | #include "configwndimpl.h" | ||
49 | #include "pwmprint.h" | 55 | #include "pwmprint.h" |
50 | #include "addentrywndimpl.h" | 56 | #include "addentrywndimpl.h" |
51 | #include "globalstuff.h" | 57 | #include "globalstuff.h" |
52 | #include "findwndimpl.h" | 58 | #include "findwndimpl.h" |
53 | #include "configuration.h" | ||
54 | 59 | ||
55 | #ifdef CONFIG_KWALLETIF | 60 | #ifdef CONFIG_KWALLETIF |
56 | # include "kwalletif.h" | 61 | # include "kwalletif.h" |
57 | # include "kwalletemu.h" | 62 | # include "kwalletemu.h" |
58 | #endif | 63 | #endif |
59 | #ifdef CONFIG_KEYCARD | 64 | #ifdef CONFIG_KEYCARD |
60 | # include "pwmkeycard.h" | 65 | # include "pwmkeycard.h" |
61 | #endif | 66 | #endif |
62 | 67 | ||
63 | 68 | ||
64 | #define DEFAULT_SIZE (QSize(700, 400)) | 69 | #define DEFAULT_SIZE (QSize(700, 400)) |
65 | 70 | ||
66 | // Button IDs for "file" popup menu | 71 | // Button IDs for "file" popup menu |
67 | enum { | 72 | enum { |
68 | BUTTON_POPUP_FILE_NEW = 0, | 73 | BUTTON_POPUP_FILE_NEW = 0, |
69 | BUTTON_POPUP_FILE_OPEN, | 74 | BUTTON_POPUP_FILE_OPEN, |
70 | BUTTON_POPUP_FILE_CLOSE, | 75 | BUTTON_POPUP_FILE_CLOSE, |
71 | BUTTON_POPUP_FILE_SAVE, | 76 | BUTTON_POPUP_FILE_SAVE, |
72 | BUTTON_POPUP_FILE_SAVEAS, | 77 | BUTTON_POPUP_FILE_SAVEAS, |
73 | BUTTON_POPUP_FILE_EXPORT, | 78 | BUTTON_POPUP_FILE_EXPORT, |
74 | BUTTON_POPUP_FILE_IMPORT, | 79 | BUTTON_POPUP_FILE_IMPORT, |
75 | BUTTON_POPUP_FILE_PRINT, | 80 | BUTTON_POPUP_FILE_PRINT, |
76 | BUTTON_POPUP_FILE_QUIT | 81 | BUTTON_POPUP_FILE_QUIT |
77 | }; | 82 | }; |
78 | // Button IDs for "manage" popup menu | 83 | // Button IDs for "manage" popup menu |
79 | enum { | 84 | enum { |
80 | BUTTON_POPUP_MANAGE_ADD = 0, | 85 | BUTTON_POPUP_MANAGE_ADD = 0, |
81 | BUTTON_POPUP_MANAGE_EDIT, | 86 | BUTTON_POPUP_MANAGE_EDIT, |
82 | BUTTON_POPUP_MANAGE_DEL, | 87 | BUTTON_POPUP_MANAGE_DEL, |
83 | BUTTON_POPUP_MANAGE_CHANGEMP | 88 | BUTTON_POPUP_MANAGE_CHANGEMP |
84 | }; | 89 | }; |
85 | // Button IDs for chipcard popup menu | 90 | // Button IDs for chipcard popup menu |
86 | enum { | 91 | enum { |
87 | #ifdef CONFIG_KEYCARD | 92 | #ifdef CONFIG_KEYCARD |
88 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, | 93 | BUTTON_POPUP_CHIPCARD_GENNEW = 0, |
89 | BUTTON_POPUP_CHIPCARD_DEL, | 94 | BUTTON_POPUP_CHIPCARD_DEL, |
90 | BUTTON_POPUP_CHIPCARD_READID, | 95 | BUTTON_POPUP_CHIPCARD_READID, |
91 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, | 96 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP, |
92 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP | 97 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP |
93 | #else // CONFIG_KEYCARD | 98 | #else // CONFIG_KEYCARD |
94 | BUTTON_POPUP_CHIPCARD_NO = 0 | 99 | BUTTON_POPUP_CHIPCARD_NO = 0 |
95 | #endif // CONFIG_KEYCARD | 100 | #endif // CONFIG_KEYCARD |
96 | }; | 101 | }; |
97 | // Button IDs for "view" popup menu | 102 | // Button IDs for "view" popup menu |
98 | enum { | 103 | enum { |
99 | BUTTON_POPUP_VIEW_FIND = 0, | 104 | BUTTON_POPUP_VIEW_FIND = 0, |
100 | BUTTON_POPUP_VIEW_LOCK, | 105 | BUTTON_POPUP_VIEW_LOCK, |
101 | BUTTON_POPUP_VIEW_DEEPLOCK, | 106 | BUTTON_POPUP_VIEW_DEEPLOCK, |
102 | BUTTON_POPUP_VIEW_UNLOCK | 107 | BUTTON_POPUP_VIEW_UNLOCK |
103 | }; | 108 | }; |
104 | // Button IDs for "options" popup menu | 109 | // Button IDs for "options" popup menu |
105 | enum { | 110 | enum { |
106 | BUTTON_POPUP_OPTIONS_CONFIG = 0 | 111 | BUTTON_POPUP_OPTIONS_CONFIG = 0 |
107 | }; | 112 | }; |
108 | // Button IDs for "export" popup menu (in "file" popup menu) | 113 | // Button IDs for "export" popup menu (in "file" popup menu) |
109 | enum { | 114 | enum { |
110 | BUTTON_POPUP_EXPORT_TEXT = 0, | 115 | BUTTON_POPUP_EXPORT_TEXT = 0, |
111 | BUTTON_POPUP_EXPORT_GPASMAN | 116 | BUTTON_POPUP_EXPORT_GPASMAN |
112 | #ifdef CONFIG_KWALLETIF | 117 | #ifdef CONFIG_KWALLETIF |
113 | ,BUTTON_POPUP_EXPORT_KWALLET | 118 | ,BUTTON_POPUP_EXPORT_KWALLET |
114 | #endif | 119 | #endif |
115 | }; | 120 | }; |
116 | // Button IDs for "import" popup menu (in "file" popup menu) | 121 | // Button IDs for "import" popup menu (in "file" popup menu) |
117 | enum { | 122 | enum { |
118 | BUTTON_POPUP_IMPORT_TEXT = 0, | 123 | BUTTON_POPUP_IMPORT_TEXT = 0, |
119 | BUTTON_POPUP_IMPORT_GPASMAN | 124 | BUTTON_POPUP_IMPORT_GPASMAN |
120 | #ifdef CONFIG_KWALLETIF | 125 | #ifdef CONFIG_KWALLETIF |
121 | ,BUTTON_POPUP_IMPORT_KWALLET | 126 | ,BUTTON_POPUP_IMPORT_KWALLET |
122 | #endif | 127 | #endif |
123 | }; | 128 | }; |
124 | 129 | ||
125 | #ifdef PWM_EMBEDDED | 130 | #ifdef PWM_EMBEDDED |
126 | // Button IDs for "help" popup menu | 131 | // Button IDs for "help" popup menu |
127 | enum { | 132 | enum { |
128 | BUTTON_POPUP_HELP_LICENSE = 0, | 133 | BUTTON_POPUP_HELP_LICENSE = 0, |
129 | BUTTON_POPUP_HELP_FAQ, | 134 | BUTTON_POPUP_HELP_FAQ, |
130 | BUTTON_POPUP_HELP_ABOUT | 135 | BUTTON_POPUP_HELP_ABOUT |
131 | }; | 136 | }; |
132 | #endif | 137 | #endif |
133 | 138 | ||
134 | // Button IDs for toolbar | 139 | // Button IDs for toolbar |
135 | enum { | 140 | enum { |
136 | BUTTON_TOOL_NEW = 0, | 141 | BUTTON_TOOL_NEW = 0, |
137 | BUTTON_TOOL_OPEN, | 142 | BUTTON_TOOL_OPEN, |
138 | BUTTON_TOOL_SAVE, | 143 | BUTTON_TOOL_SAVE, |
139 | BUTTON_TOOL_SAVEAS, | 144 | BUTTON_TOOL_SAVEAS, |
140 | BUTTON_TOOL_PRINT, | 145 | BUTTON_TOOL_PRINT, |
141 | BUTTON_TOOL_ADD, | 146 | BUTTON_TOOL_ADD, |
142 | BUTTON_TOOL_EDIT, | 147 | BUTTON_TOOL_EDIT, |
143 | BUTTON_TOOL_DEL, | 148 | BUTTON_TOOL_DEL, |
144 | BUTTON_TOOL_FIND, | 149 | BUTTON_TOOL_FIND, |
145 | BUTTON_TOOL_LOCK, | 150 | BUTTON_TOOL_LOCK, |
146 | BUTTON_TOOL_DEEPLOCK, | 151 | BUTTON_TOOL_DEEPLOCK, |
147 | BUTTON_TOOL_UNLOCK | 152 | BUTTON_TOOL_UNLOCK |
148 | }; | 153 | }; |
149 | 154 | ||
150 | 155 | ||
151 | PwM::PwM(PwMInit *_init, PwMDoc *doc, | 156 | PwM::PwM(PwMInit *_init, PwMDoc *doc, |
152 | bool virginity, | 157 | bool virginity, |
153 | QWidget *parent, const char *name) | 158 | QWidget *parent, const char *name) |
154 | : KMainWindow(parent, name) | 159 | : KMainWindow(parent, name) |
155 | , forceQuit (false) | 160 | , forceQuit (false) |
156 | , forceMinimizeToTray (false) | 161 | , forceMinimizeToTray (false) |
157 | { | 162 | { |
158 | init = _init; | 163 | init = _init; |
159 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 164 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
160 | this, SLOT(docClosed(PwMDoc *))); | 165 | this, SLOT(docClosed(PwMDoc *))); |
161 | initMenubar(); | 166 | initMenubar(); |
162 | initToolbar(); | 167 | initToolbar(); |
163 | initMetrics(); | 168 | initMetrics(); |
164 | setVirgin(virginity); | 169 | setVirgin(virginity); |
165 | setFocusPolicy(QWidget::WheelFocus); | 170 | setFocusPolicy(QWidget::WheelFocus); |
166 | #ifndef PWM_EMBEDDED | 171 | #ifndef PWM_EMBEDDED |
167 | statusBar()->show(); | 172 | statusBar()->show(); |
168 | #endif | 173 | #endif |
169 | view = makeNewListView(doc); | 174 | view = makeNewListView(doc); |
170 | setCentralWidget(view); | 175 | setCentralWidget(view); |
171 | updateCaption(); | 176 | updateCaption(); |
172 | showStatMsg(i18n("Ready.")); | 177 | showStatMsg(i18n("Ready.")); |
173 | } | 178 | } |
174 | 179 | ||
175 | PwM::~PwM() | 180 | PwM::~PwM() |
176 | { | 181 | { |
177 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), | 182 | disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)), |
178 | this, SLOT(docClosed(PwMDoc *))); | 183 | this, SLOT(docClosed(PwMDoc *))); |
179 | conf()->confWndMainWndSize(size()); | 184 | conf()->confWndMainWndSize(size()); |
180 | emit closed(this); | 185 | emit closed(this); |
181 | delete view; | 186 | delete view; |
182 | } | 187 | } |
183 | 188 | ||
184 | void PwM::initMenubar() | 189 | void PwM::initMenubar() |
185 | { | 190 | { |
186 | KIconLoader* picons; | 191 | KIconLoader* picons; |
187 | #ifndef PWM_EMBEDDED | 192 | #ifndef PWM_EMBEDDED |
188 | KIconLoader icons; | 193 | KIconLoader icons; |
189 | picons = &icons; | 194 | picons = &icons; |
190 | #else | 195 | #else |
191 | picons = KGlobal::iconLoader(); | 196 | picons = KGlobal::iconLoader(); |
192 | #endif | 197 | #endif |
193 | filePopup = new KPopupMenu(this); | 198 | filePopup = new KPopupMenu(this); |
194 | importPopup = new KPopupMenu(filePopup); | 199 | importPopup = new KPopupMenu(filePopup); |
195 | exportPopup = new KPopupMenu(filePopup); | 200 | exportPopup = new KPopupMenu(filePopup); |
196 | managePopup = new KPopupMenu(this); | 201 | managePopup = new KPopupMenu(this); |
197 | #ifdef CONFIG_KEYCARD | 202 | #ifdef CONFIG_KEYCARD |
198 | chipcardPopup = new KPopupMenu(this); | 203 | chipcardPopup = new KPopupMenu(this); |
199 | #endif // CONFIG_KEYCARD | 204 | #endif // CONFIG_KEYCARD |
200 | viewPopup = new KPopupMenu(this); | 205 | viewPopup = new KPopupMenu(this); |
201 | optionsPopup = new KPopupMenu(this); | 206 | optionsPopup = new KPopupMenu(this); |
202 | 207 | ||
203 | // "file" popup menu | 208 | // "file" popup menu |
204 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 209 | filePopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
205 | i18n("&New"), this, | 210 | i18n("&New"), this, |
206 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); | 211 | SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW); |
207 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), | 212 | filePopup->insertItem(QIconSet(picons->loadIcon("fileopen", KIcon::Small)), |
208 | i18n("&Open"), this, | 213 | i18n("&Open"), this, |
209 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); | 214 | SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN); |
210 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), | 215 | filePopup->insertItem(QIconSet(picons->loadIcon("fileclose", KIcon::Small)), |
211 | i18n("&Close"), this, | 216 | i18n("&Close"), this, |
212 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); | 217 | SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE); |
213 | filePopup->insertSeparator(); | 218 | filePopup->insertSeparator(); |
214 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), | 219 | filePopup->insertItem(QIconSet(picons->loadIcon("filesave", KIcon::Small)), |
215 | i18n("&Save"), this, | 220 | i18n("&Save"), this, |
216 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); | 221 | SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE); |
217 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), | 222 | filePopup->insertItem(QIconSet(picons->loadIcon("filesaveas", KIcon::Small)), |
218 | i18n("Save &as..."), | 223 | i18n("Save &as..."), |
219 | this, SLOT(saveAs_slot()), 0, | 224 | this, SLOT(saveAs_slot()), 0, |
220 | BUTTON_POPUP_FILE_SAVEAS); | 225 | BUTTON_POPUP_FILE_SAVEAS); |
221 | filePopup->insertSeparator(); | 226 | filePopup->insertSeparator(); |
222 | // "file/export" popup menu | 227 | // "file/export" popup menu |
223 | exportPopup->insertItem(i18n("&Text-file..."), this, | 228 | exportPopup->insertItem(i18n("&Text-file..."), this, |
224 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); | 229 | SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT); |
225 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 230 | exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
226 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); | 231 | SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN); |
227 | #ifdef CONFIG_KWALLETIF | 232 | #ifdef CONFIG_KWALLETIF |
228 | exportPopup->insertItem(i18n("&KWallet..."), this, | 233 | exportPopup->insertItem(i18n("&KWallet..."), this, |
229 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); | 234 | SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET); |
230 | #endif | 235 | #endif |
231 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), | 236 | filePopup->insertItem(QIconSet(picons->loadIcon("fileexport", KIcon::Small)), |
232 | i18n("E&xport"), exportPopup, | 237 | i18n("E&xport"), exportPopup, |
233 | BUTTON_POPUP_FILE_EXPORT); | 238 | BUTTON_POPUP_FILE_EXPORT); |
234 | // "file/import" popup menu | 239 | // "file/import" popup menu |
235 | importPopup->insertItem(i18n("&Text-file..."), this, | 240 | importPopup->insertItem(i18n("&Text-file..."), this, |
236 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); | 241 | SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT); |
237 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, | 242 | importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this, |
238 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); | 243 | SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN); |
239 | #ifdef CONFIG_KWALLETIF | 244 | #ifdef CONFIG_KWALLETIF |
240 | importPopup->insertItem(i18n("&KWallet..."), this, | 245 | importPopup->insertItem(i18n("&KWallet..."), this, |
241 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); | 246 | SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET); |
242 | #endif | 247 | #endif |
243 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), | 248 | filePopup->insertItem(QIconSet(picons->loadIcon("fileimport", KIcon::Small)), |
244 | i18n("I&mport"), importPopup, | 249 | i18n("I&mport"), importPopup, |
245 | BUTTON_POPUP_FILE_IMPORT); | 250 | BUTTON_POPUP_FILE_IMPORT); |
246 | filePopup->insertSeparator(); | 251 | filePopup->insertSeparator(); |
247 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), | 252 | filePopup->insertItem(QIconSet(picons->loadIcon("fileprint", KIcon::Small)), |
248 | i18n("&Print..."), this, | 253 | i18n("&Print..."), this, |
249 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); | 254 | SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT); |
250 | filePopup->insertSeparator(); | 255 | filePopup->insertSeparator(); |
251 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), | 256 | filePopup->insertItem(QIconSet(picons->loadIcon("exit", KIcon::Small)), |
252 | i18n("&Quit"), this, | 257 | i18n("&Quit"), this, |
253 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); | 258 | SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT); |
254 | menuBar()->insertItem(i18n("&File"), filePopup); | 259 | menuBar()->insertItem(i18n("&File"), filePopup); |
255 | // "manage" popup menu | 260 | // "manage" popup menu |
256 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), | 261 | managePopup->insertItem(QIconSet(picons->loadIcon("pencil", KIcon::Small)), |
257 | i18n("&Add password"), this, | 262 | i18n("&Add password"), this, |
258 | SLOT(addPwd_slot()), 0, | 263 | SLOT(addPwd_slot()), 0, |
259 | BUTTON_POPUP_MANAGE_ADD); | 264 | BUTTON_POPUP_MANAGE_ADD); |
260 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), | 265 | managePopup->insertItem(QIconSet(picons->loadIcon("edit", KIcon::Small)), |
261 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, | 266 | i18n("&Edit"), this, SLOT(editPwd_slot()), 0, |
262 | BUTTON_POPUP_MANAGE_EDIT); | 267 | BUTTON_POPUP_MANAGE_EDIT); |
263 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 268 | managePopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
264 | i18n("&Delete"), this, SLOT(deletePwd_slot()), | 269 | i18n("&Delete"), this, SLOT(deletePwd_slot()), |
265 | 0, BUTTON_POPUP_MANAGE_DEL); | 270 | 0, BUTTON_POPUP_MANAGE_DEL); |
266 | managePopup->insertSeparator(); | 271 | managePopup->insertSeparator(); |
267 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), | 272 | managePopup->insertItem(QIconSet(picons->loadIcon("rotate", KIcon::Small)), |
268 | i18n("Change &Master Password"), this, | 273 | i18n("Change &Master Password"), this, |
269 | SLOT(changeMasterPwd_slot()), 0, | 274 | SLOT(changeMasterPwd_slot()), 0, |
270 | BUTTON_POPUP_MANAGE_CHANGEMP); | 275 | BUTTON_POPUP_MANAGE_CHANGEMP); |
271 | menuBar()->insertItem(i18n("&Manage"), managePopup); | 276 | menuBar()->insertItem(i18n("&Manage"), managePopup); |
272 | // "chipcard" popup menu | 277 | // "chipcard" popup menu |
273 | #ifdef CONFIG_KEYCARD | 278 | #ifdef CONFIG_KEYCARD |
274 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), | 279 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("filenew", KIcon::Small)), |
275 | i18n("&Generate new key-card"), this, | 280 | i18n("&Generate new key-card"), this, |
276 | SLOT(genNewCard_slot()), 0, | 281 | SLOT(genNewCard_slot()), 0, |
277 | BUTTON_POPUP_CHIPCARD_GENNEW); | 282 | BUTTON_POPUP_CHIPCARD_GENNEW); |
278 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), | 283 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("editdelete", KIcon::Small)), |
279 | i18n("&Erase key-card"), this, | 284 | i18n("&Erase key-card"), this, |
280 | SLOT(eraseCard_slot()), 0, | 285 | SLOT(eraseCard_slot()), 0, |
281 | BUTTON_POPUP_CHIPCARD_DEL); | 286 | BUTTON_POPUP_CHIPCARD_DEL); |
282 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), | 287 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("", KIcon::Small)), |
283 | i18n("Read card-&ID"), this, | 288 | i18n("Read card-&ID"), this, |
284 | SLOT(readCardId_slot()), 0, | 289 | SLOT(readCardId_slot()), 0, |
285 | BUTTON_POPUP_CHIPCARD_READID); | 290 | BUTTON_POPUP_CHIPCARD_READID); |
286 | chipcardPopup->insertSeparator(); | 291 | chipcardPopup->insertSeparator(); |
287 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), | 292 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2rightarrow", KIcon::Small)), |
288 | i18n("&Make card backup-image"), this, | 293 | i18n("&Make card backup-image"), this, |
289 | SLOT(makeCardBackup_slot()), 0, | 294 | SLOT(makeCardBackup_slot()), 0, |
290 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); | 295 | BUTTON_POPUP_CHIPCARD_SAVEBACKUP); |
291 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), | 296 | chipcardPopup->insertItem(QIconSet(picons->loadIcon("2leftarrow", KIcon::Small)), |
292 | i18n("&Replay card backup-image"), this, | 297 | i18n("&Replay card backup-image"), this, |
293 | SLOT(replayCardBackup_slot()), 0, | 298 | SLOT(replayCardBackup_slot()), 0, |
294 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); | 299 | BUTTON_POPUP_CHIPCARD_REPLAYBACKUP); |
295 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); | 300 | menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup); |
296 | #endif // CONFIG_KEYCARD | 301 | #endif // CONFIG_KEYCARD |
297 | // "view" popup menu | 302 | // "view" popup menu |
298 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), | 303 | viewPopup->insertItem(QIconSet(picons->loadIcon("find", KIcon::Small)), |
299 | i18n("&Find"), this, | 304 | i18n("&Find"), this, |
300 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); | 305 | SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND); |
301 | viewPopup->insertSeparator(); | 306 | viewPopup->insertSeparator(); |
302 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), | 307 | viewPopup->insertItem(QIconSet(picons->loadIcon("halfencrypted", KIcon::Small)), |
303 | i18n("&Lock all entries"), this, | 308 | i18n("&Lock all entries"), this, |
304 | SLOT(lockWnd_slot()), 0, | 309 | SLOT(lockWnd_slot()), 0, |
305 | BUTTON_POPUP_VIEW_LOCK); | 310 | BUTTON_POPUP_VIEW_LOCK); |
306 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), | 311 | viewPopup->insertItem(QIconSet(picons->loadIcon("encrypted", KIcon::Small)), |
307 | i18n("&Deep-lock all entries"), this, | 312 | i18n("&Deep-lock all entries"), this, |
308 | SLOT(deepLockWnd_slot()), 0, | 313 | SLOT(deepLockWnd_slot()), 0, |
309 | BUTTON_POPUP_VIEW_DEEPLOCK); | 314 | BUTTON_POPUP_VIEW_DEEPLOCK); |
310 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), | 315 | viewPopup->insertItem(QIconSet(picons->loadIcon("decrypted", KIcon::Small)), |
311 | i18n("&Unlock all entries"), this, | 316 | i18n("&Unlock all entries"), this, |
312 | SLOT(unlockWnd_slot()), 0, | 317 | SLOT(unlockWnd_slot()), 0, |
313 | BUTTON_POPUP_VIEW_UNLOCK); | 318 | BUTTON_POPUP_VIEW_UNLOCK); |
314 | menuBar()->insertItem(i18n("&View"), viewPopup); | 319 | menuBar()->insertItem(i18n("&View"), viewPopup); |
315 | // "options" popup menu | 320 | // "options" popup menu |
316 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), | 321 | optionsPopup->insertItem(QIconSet(picons->loadIcon("configure", KIcon::Small)), |
317 | i18n("&Configure..."), this, | 322 | i18n("&Configure..."), this, |
318 | SLOT(config_slot()), | 323 | SLOT(config_slot()), |
319 | BUTTON_POPUP_OPTIONS_CONFIG); | 324 | BUTTON_POPUP_OPTIONS_CONFIG); |
320 | menuBar()->insertItem(i18n("&Options"), optionsPopup); | 325 | menuBar()->insertItem(i18n("&Options"), optionsPopup); |
321 | // "help" popup menu | 326 | // "help" popup menu |
322 | #ifndef PWM_EMBEDDED | 327 | #ifndef PWM_EMBEDDED |
323 | helpPopup = helpMenu(QString::null, false); | 328 | helpPopup = helpMenu(QString::null, false); |
324 | #else | 329 | #else |
325 | helpPopup = new KPopupMenu(this); | 330 | helpPopup = new KPopupMenu(this); |
326 | 331 | ||
327 | 332 | ||
328 | helpPopup->insertItem(i18n("&License"), this, | 333 | helpPopup->insertItem(i18n("&License"), this, |
329 | SLOT(showLicense_slot()), 0, | 334 | SLOT(showLicense_slot()), 0, |
330 | BUTTON_POPUP_HELP_LICENSE); | 335 | BUTTON_POPUP_HELP_LICENSE); |
331 | 336 | ||
332 | helpPopup->insertItem(i18n("&Faq"), this, | 337 | helpPopup->insertItem(i18n("&Faq"), this, |
333 | SLOT(faq_slot()), 0, | 338 | SLOT(faq_slot()), 0, |
334 | BUTTON_POPUP_HELP_FAQ); | 339 | BUTTON_POPUP_HELP_FAQ); |
335 | 340 | ||
336 | helpPopup->insertItem(i18n("&About PwManager"), this, | 341 | helpPopup->insertItem(i18n("&About PwManager"), this, |
337 | SLOT(createAboutData_slot()), 0, | 342 | SLOT(createAboutData_slot()), 0, |
338 | BUTTON_POPUP_HELP_ABOUT); | 343 | BUTTON_POPUP_HELP_ABOUT); |
339 | 344 | ||
340 | #endif | 345 | #endif |
341 | menuBar()->insertItem(i18n("&Help"), helpPopup); | 346 | menuBar()->insertItem(i18n("&Help"), helpPopup); |
342 | 347 | ||
343 | } | 348 | } |
344 | 349 | ||
345 | void PwM::initToolbar() | 350 | void PwM::initToolbar() |
346 | { | 351 | { |
347 | KIconLoader* picons; | 352 | KIconLoader* picons; |
348 | #ifndef PWM_EMBEDDED | 353 | #ifndef PWM_EMBEDDED |
349 | KIconLoader icons; | 354 | KIconLoader icons; |
350 | picons = &icons; | 355 | picons = &icons; |
351 | #else | 356 | #else |
352 | picons = KGlobal::iconLoader(); | 357 | picons = KGlobal::iconLoader(); |
353 | #endif | 358 | #endif |
354 | 359 | ||
355 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), | 360 | toolBar()->insertButton(picons->loadIcon("filenew", KIcon::Toolbar), |
356 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, | 361 | BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this, |
357 | SLOT(new_slot()), true, i18n("New")); | 362 | SLOT(new_slot()), true, i18n("New")); |
358 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), | 363 | toolBar()->insertButton(picons->loadIcon("fileopen", KIcon::Toolbar), |
359 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, | 364 | BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this, |
360 | SLOT(open_slot()), true, i18n("Open")); | 365 | SLOT(open_slot()), true, i18n("Open")); |
361 | toolBar()->insertSeparator(); | 366 | toolBar()->insertSeparator(); |
362 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), | 367 | toolBar()->insertButton(picons->loadIcon("filesave", KIcon::Toolbar), |
363 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, | 368 | BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this, |
364 | SLOT(save_slot()), true, i18n("Save")); | 369 | SLOT(save_slot()), true, i18n("Save")); |
365 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), | 370 | toolBar()->insertButton(picons->loadIcon("filesaveas", KIcon::Toolbar), |
366 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, | 371 | BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this, |
367 | SLOT(saveAs_slot()), true, i18n("Save as")); | 372 | SLOT(saveAs_slot()), true, i18n("Save as")); |
368 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), | 373 | toolBar()->insertButton(picons->loadIcon("fileprint", KIcon::Toolbar), |
369 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, | 374 | BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this, |
370 | SLOT(print_slot()), true, i18n("Print...")); | 375 | SLOT(print_slot()), true, i18n("Print...")); |
371 | toolBar()->insertSeparator(); | 376 | toolBar()->insertSeparator(); |
372 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), | 377 | toolBar()->insertButton(picons->loadIcon("pencil", KIcon::Toolbar), |
373 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, | 378 | BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this, |
374 | SLOT(addPwd_slot()), true, | 379 | SLOT(addPwd_slot()), true, |
375 | i18n("Add password")); | 380 | i18n("Add password")); |
376 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), | 381 | toolBar()->insertButton(picons->loadIcon("edit", KIcon::Toolbar), |
377 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, | 382 | BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this, |
378 | SLOT(editPwd_slot()), true, | 383 | SLOT(editPwd_slot()), true, |
379 | i18n("Edit password")); | 384 | i18n("Edit password")); |
380 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), | 385 | toolBar()->insertButton(picons->loadIcon("editdelete", KIcon::Toolbar), |
381 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, | 386 | BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this, |
382 | SLOT(deletePwd_slot()), true, | 387 | SLOT(deletePwd_slot()), true, |
383 | i18n("Delete password")); | 388 | i18n("Delete password")); |
384 | toolBar()->insertSeparator(); | 389 | toolBar()->insertSeparator(); |
385 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), | 390 | toolBar()->insertButton(picons->loadIcon("find", KIcon::Toolbar), |
386 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, | 391 | BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this, |
387 | SLOT(find_slot()), true, i18n("Find entry")); | 392 | SLOT(find_slot()), true, i18n("Find entry")); |
388 | toolBar()->insertSeparator(); | 393 | toolBar()->insertSeparator(); |
389 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), | 394 | toolBar()->insertButton(picons->loadIcon("halfencrypted", KIcon::Toolbar), |
390 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, | 395 | BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this, |
391 | SLOT(lockWnd_slot()), true, | 396 | SLOT(lockWnd_slot()), true, |
392 | i18n("Lock all entries")); | 397 | i18n("Lock all entries")); |
393 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), | 398 | toolBar()->insertButton(picons->loadIcon("encrypted", KIcon::Toolbar), |
394 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, | 399 | BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this, |
395 | SLOT(deepLockWnd_slot()), true, | 400 | SLOT(deepLockWnd_slot()), true, |
396 | i18n("Deep-Lock all entries")); | 401 | i18n("Deep-Lock all entries")); |
397 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), | 402 | toolBar()->insertButton(picons->loadIcon("decrypted", KIcon::Toolbar), |
398 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, | 403 | BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this, |
399 | SLOT(unlockWnd_slot()), true, | 404 | SLOT(unlockWnd_slot()), true, |
400 | i18n("Unlock all entries")); | 405 | i18n("Unlock all entries")); |
401 | } | 406 | } |
402 | 407 | ||
403 | void PwM::initMetrics() | 408 | void PwM::initMetrics() |
404 | { | 409 | { |
405 | QSize s = conf()->confWndMainWndSize(); | 410 | QSize s = conf()->confWndMainWndSize(); |
406 | if (s.isValid()) | 411 | if (s.isValid()) |
407 | resize(s); | 412 | resize(s); |
408 | else | 413 | else |
409 | resize(DEFAULT_SIZE); | 414 | resize(DEFAULT_SIZE); |
410 | } | 415 | } |
411 | 416 | ||
412 | void PwM::updateCaption() | 417 | void PwM::updateCaption() |
413 | { | 418 | { |
414 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); | 419 | setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER); |
415 | } | 420 | } |
416 | 421 | ||
417 | void PwM::hideEvent(QHideEvent *) | 422 | void PwM::hideEvent(QHideEvent *) |
418 | { | 423 | { |
419 | if (isMinimized()) { | 424 | if (isMinimized()) { |
420 | if (init->tray()) { | 425 | if (init->tray()) { |
421 | forceMinimizeToTray = true; | 426 | forceMinimizeToTray = true; |
422 | close(); | 427 | close(); |
423 | } | 428 | } |
424 | int mmlock = conf()->confGlobMinimizeLock(); | 429 | int mmlock = conf()->confGlobMinimizeLock(); |
425 | switch (mmlock) { | 430 | switch (mmlock) { |
426 | case 0: // don't lock anything | 431 | case 0: // don't lock anything |
427 | break; | 432 | break; |
428 | case 1: {// normal lock | 433 | case 1: {// normal lock |
429 | curDoc()->lockAll(true); | 434 | curDoc()->lockAll(true); |
430 | break; | 435 | break; |
431 | } case 2: {// deep-lock | 436 | } case 2: {// deep-lock |
432 | curDoc()->deepLock(); | 437 | curDoc()->deepLock(); |
433 | break; | 438 | break; |
434 | } default: | 439 | } default: |
435 | WARN(); | 440 | WARN(); |
436 | } | 441 | } |
437 | } | 442 | } |
438 | } | 443 | } |
439 | 444 | ||
440 | void PwM::setVirgin(bool v) | 445 | void PwM::setVirgin(bool v) |
441 | { | 446 | { |
442 | if (virgin == v) | 447 | if (virgin == v) |
443 | return; | 448 | return; |
444 | virgin = v; | 449 | virgin = v; |
445 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); | 450 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v); |
446 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); | 451 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v); |
447 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); | 452 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v); |
448 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); | 453 | filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v); |
449 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); | 454 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v); |
450 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); | 455 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v); |
451 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); | 456 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v); |
452 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); | 457 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v); |
453 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); | 458 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v); |
454 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); | 459 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v); |
455 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); | 460 | viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v); |
456 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); | 461 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v); |
457 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); | 462 | toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v); |
458 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); | 463 | toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v); |
459 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); | 464 | toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v); |
460 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); | 465 | toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v); |
461 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); | 466 | toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v); |
462 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); | 467 | toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v); |
463 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); | 468 | toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v); |
464 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); | 469 | toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v); |
465 | } | 470 | } |
466 | 471 | ||
467 | void PwM::new_slot() | 472 | void PwM::new_slot() |
468 | { | 473 | { |
469 | init->createMainWnd(); | 474 | init->createMainWnd(); |
470 | } | 475 | } |
471 | 476 | ||
472 | //US ENH | 477 | //US ENH |
473 | void PwM::open_slot() | 478 | void PwM::open_slot() |
474 | { | 479 | { |
475 | open_slot(""); | 480 | open_slot(""); |
476 | } | 481 | } |
477 | 482 | ||
478 | void PwM::open_slot(QString fn) | 483 | void PwM::open_slot(QString fn) |
479 | { | 484 | { |
480 | openDoc(fn); | 485 | openDoc(fn); |
481 | } | 486 | } |
482 | 487 | ||
483 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) | 488 | PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked) |
484 | { | 489 | { |
485 | if (!isVirgin()) { | 490 | if (!isVirgin()) { |
486 | // open the document in a new window. | 491 | // open the document in a new window. |
487 | PwM *newInstance = init->createMainWnd(); | 492 | PwM *newInstance = init->createMainWnd(); |
488 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); | 493 | PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked); |
489 | if (!newDoc) { | 494 | if (!newDoc) { |
490 | newInstance->setForceQuit(true); | 495 | newInstance->setForceQuit(true); |
491 | delete_and_null(newInstance); | 496 | delete_and_null(newInstance); |
492 | } | 497 | } |
493 | return newDoc; | 498 | return newDoc; |
494 | } | 499 | } |
495 | 500 | ||
496 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) | 501 | if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked)) |
497 | return 0; | 502 | return 0; |
498 | showStatMsg(i18n("Successfully opened file.")); | 503 | showStatMsg(i18n("Successfully opened file.")); |
499 | updateCaption(); | 504 | updateCaption(); |
500 | setVirgin(false); | 505 | setVirgin(false); |
501 | return curDoc(); | 506 | return curDoc(); |
502 | } | 507 | } |
503 | 508 | ||
504 | PwMView * PwM::makeNewListView(PwMDoc *doc) | 509 | PwMView * PwM::makeNewListView(PwMDoc *doc) |
505 | { | 510 | { |
506 | PwMView *ret = new PwMView(this, this, doc); | 511 | PwMView *ret = new PwMView(this, this, doc); |
507 | ret->setFont(conf()->confGlobEntryFont()); | 512 | ret->setFont(conf()->confGlobEntryFont()); |
508 | ret->show(); | 513 | ret->show(); |
509 | return ret; | 514 | return ret; |
510 | } | 515 | } |
511 | 516 | ||
512 | void PwM::close_slot() | 517 | void PwM::close_slot() |
513 | { | 518 | { |
514 | close(); | 519 | close(); |
515 | } | 520 | } |
516 | 521 | ||
517 | void PwM::quitButton_slot() | 522 | void PwM::quitButton_slot() |
518 | { | 523 | { |
519 | init->shutdownApp(0); | 524 | init->shutdownApp(0); |
520 | } | 525 | } |
521 | 526 | ||
522 | void PwM::save_slot() | 527 | void PwM::save_slot() |
523 | { | 528 | { |
524 | save(); | 529 | save(); |
525 | } | 530 | } |
526 | 531 | ||
527 | bool PwM::save() | 532 | bool PwM::save() |
528 | { | 533 | { |
529 | if (!curDoc()->saveDocUi(curDoc())) | 534 | if (!curDoc()->saveDocUi(curDoc())) |
530 | return false; | 535 | return false; |
531 | showStatMsg(i18n("Successfully saved data.")); | 536 | showStatMsg(i18n("Successfully saved data.")); |
532 | updateCaption(); | 537 | updateCaption(); |
533 | return true; | 538 | return true; |
534 | } | 539 | } |
535 | 540 | ||
536 | void PwM::saveAs_slot() | 541 | void PwM::saveAs_slot() |
537 | { | 542 | { |
538 | saveAs(); | 543 | saveAs(); |
539 | } | 544 | } |
540 | 545 | ||
541 | bool PwM::saveAs() | 546 | bool PwM::saveAs() |
542 | { | 547 | { |
543 | if (!curDoc()->saveAsDocUi(curDoc())) | 548 | if (!curDoc()->saveAsDocUi(curDoc())) |
544 | return false; | 549 | return false; |
545 | showStatMsg(i18n("Successfully saved data.")); | 550 | showStatMsg(i18n("Successfully saved data.")); |
546 | updateCaption(); | 551 | updateCaption(); |
547 | return true; | 552 | return true; |
548 | } | 553 | } |
549 | 554 | ||
550 | //US ENH : changed code to run with older MOC | 555 | //US ENH : changed code to run with older MOC |
551 | void PwM::addPwd_slot() | 556 | void PwM::addPwd_slot() |
552 | { | 557 | { |
553 | addPwd_slot(0, 0); | 558 | addPwd_slot(0, 0); |
554 | } | 559 | } |
555 | 560 | ||
556 | void PwM::addPwd_slot(QString *pw, PwMDoc *_doc) | 561 | void PwM::addPwd_slot(QString *pw, PwMDoc *_doc) |
557 | { | 562 | { |
558 | PwMDoc *doc; | 563 | PwMDoc *doc; |
559 | if (_doc) { | 564 | if (_doc) { |
560 | doc = _doc; | 565 | doc = _doc; |
561 | } else { | 566 | } else { |
562 | doc = curDoc(); | 567 | doc = curDoc(); |
563 | } | 568 | } |
564 | PWM_ASSERT(doc); | 569 | PWM_ASSERT(doc); |
565 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 570 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
566 | AddEntryWndImpl w; | 571 | AddEntryWndImpl w; |
567 | vector<string> catList; | 572 | vector<string> catList; |
568 | doc->getCategoryList(&catList); | 573 | doc->getCategoryList(&catList); |
569 | unsigned i, size = catList.size(); | 574 | unsigned i, size = catList.size(); |
570 | for (i = 0; i < size; ++i) { | 575 | for (i = 0; i < size; ++i) { |
571 | w.addCategory(catList[i].c_str()); | 576 | w.addCategory(catList[i].c_str()); |
572 | } | 577 | } |
573 | w.setCurrCategory(view->getCurrentCategory()); | 578 | w.setCurrCategory(view->getCurrentCategory()); |
574 | if (pw) | 579 | if (pw) |
575 | w.pwLineEdit->setText(*pw); | 580 | w.pwLineEdit->setText(*pw); |
576 | 581 | ||
577 | tryAgain: | 582 | tryAgain: |
578 | if (w.exec() == 1) | 583 | if (w.exec() == 1) |
579 | { | 584 | { |
580 | PwMDataItem d; | 585 | PwMDataItem d; |
581 | d.desc = w.getDescription().latin1(); | 586 | d.desc = w.getDescription().latin1(); |
582 | d.name = w.getUsername().latin1(); | 587 | d.name = w.getUsername().latin1(); |
583 | d.pw = w.getPassword().latin1(); | 588 | d.pw = w.getPassword().latin1(); |
584 | d.comment = w.getComment().latin1(); | 589 | d.comment = w.getComment().latin1(); |
585 | d.url = w.getUrl().latin1(); | 590 | d.url = w.getUrl().latin1(); |
586 | d.launcher = w.getLauncher().latin1(); | 591 | d.launcher = w.getLauncher().latin1(); |
587 | PwMerror ret = doc->addEntry(w.getCategory(), &d); | 592 | PwMerror ret = doc->addEntry(w.getCategory(), &d); |
588 | if (ret == e_entryExists) { | 593 | if (ret == e_entryExists) { |
589 | KMessageBox::error(this, | 594 | KMessageBox::error(this, |
590 | i18n | 595 | i18n |
591 | ("An entry with this \"Description\", " | 596 | ("An entry with this \"Description\", " |
592 | "does already exist.\n" | 597 | "does already exist.\n" |
593 | "Please select another description."), | 598 | "Please select another description."), |
594 | i18n("entry already exists.")); | 599 | i18n("entry already exists.")); |
595 | goto tryAgain; | 600 | goto tryAgain; |
596 | } else if (ret == e_maxAllowedEntr) { | 601 | } else if (ret == e_maxAllowedEntr) { |
597 | KMessageBox::error(this, i18n("The maximum possible number of entries " | 602 | KMessageBox::error(this, i18n("The maximum possible number of entries " |
598 | "has been reached. You can't add more entries."), | 603 | "has been reached. You can't add more entries."), |
599 | i18n("maximum number of entries")); | 604 | i18n("maximum number of entries")); |
600 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 605 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
601 | return; | 606 | return; |
602 | } | 607 | } |
603 | } | 608 | } |
604 | setVirgin(false); | 609 | setVirgin(false); |
605 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 610 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
606 | } | 611 | } |
607 | 612 | ||
608 | //US ENH : changed code to run with older MOC | 613 | //US ENH : changed code to run with older MOC |
609 | void PwM::editPwd_slot() | 614 | void PwM::editPwd_slot() |
610 | { | 615 | { |
611 | editPwd_slot(0,0,0); | 616 | editPwd_slot(0,0,0); |
612 | } | 617 | } |
613 | 618 | ||
614 | void PwM::editPwd_slot(const QString *category) | 619 | void PwM::editPwd_slot(const QString *category) |
615 | { | 620 | { |
616 | editPwd_slot(category, 0, 0); | 621 | editPwd_slot(category, 0, 0); |
617 | } | 622 | } |
618 | 623 | ||
619 | void PwM::editPwd_slot(const QString *category, const int *index, | 624 | void PwM::editPwd_slot(const QString *category, const int *index, |
620 | PwMDoc *_doc) | 625 | PwMDoc *_doc) |
621 | { | 626 | { |
622 | PwMDoc *doc; | 627 | PwMDoc *doc; |
623 | if (_doc) { | 628 | if (_doc) { |
624 | doc = _doc; | 629 | doc = _doc; |
625 | } else { | 630 | } else { |
626 | doc = curDoc(); | 631 | doc = curDoc(); |
627 | } | 632 | } |
628 | PWM_ASSERT(doc); | 633 | PWM_ASSERT(doc); |
629 | if (doc->isDocEmpty()) | 634 | if (doc->isDocEmpty()) |
630 | return; | 635 | return; |
631 | if (doc->isDeepLocked()) | 636 | if (doc->isDeepLocked()) |
632 | return; | 637 | return; |
633 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 638 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
634 | unsigned int curEntryIndex; | 639 | unsigned int curEntryIndex; |
635 | if (index) { | 640 | if (index) { |
636 | curEntryIndex = *index; | 641 | curEntryIndex = *index; |
637 | } else { | 642 | } else { |
638 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 643 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
639 | printDebug("couldn't get index. Maybe we have a binary entry here."); | 644 | printDebug("couldn't get index. Maybe we have a binary entry here."); |
640 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 645 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
641 | return; | 646 | return; |
642 | } | 647 | } |
643 | } | 648 | } |
644 | QString curCategory; | 649 | QString curCategory; |
645 | if (category) { | 650 | if (category) { |
646 | curCategory = *category; | 651 | curCategory = *category; |
647 | } else { | 652 | } else { |
648 | curCategory = view->getCurrentCategory(); | 653 | curCategory = view->getCurrentCategory(); |
649 | } | 654 | } |
650 | PwMDataItem currItem; | 655 | PwMDataItem currItem; |
651 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { | 656 | if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) { |
652 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 657 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
653 | return; | 658 | return; |
654 | } | 659 | } |
655 | BUG_ON(currItem.binary); | 660 | BUG_ON(currItem.binary); |
656 | 661 | ||
657 | AddEntryWndImpl w; | 662 | AddEntryWndImpl w; |
658 | vector<string> catList; | 663 | vector<string> catList; |
659 | doc->getCategoryList(&catList); | 664 | doc->getCategoryList(&catList); |
660 | unsigned i, size = catList.size(); | 665 | unsigned i, size = catList.size(); |
661 | for (i = 0; i < size; ++i) { | 666 | for (i = 0; i < size; ++i) { |
662 | w.addCategory(catList[i].c_str()); | 667 | w.addCategory(catList[i].c_str()); |
663 | } | 668 | } |
664 | w.setCurrCategory(curCategory); | 669 | w.setCurrCategory(curCategory); |
665 | w.setDescription(currItem.desc.c_str()); | 670 | w.setDescription(currItem.desc.c_str()); |
666 | w.setUsername(currItem.name.c_str()); | 671 | w.setUsername(currItem.name.c_str()); |
667 | w.setPassword(currItem.pw.c_str()); | 672 | w.setPassword(currItem.pw.c_str()); |
668 | w.setUrl(currItem.url.c_str()); | 673 | w.setUrl(currItem.url.c_str()); |
669 | w.setLauncher(currItem.launcher.c_str()); | 674 | w.setLauncher(currItem.launcher.c_str()); |
670 | w.setComment(currItem.comment.c_str()); | 675 | w.setComment(currItem.comment.c_str()); |
671 | if (w.exec() == 1) { | 676 | if (w.exec() == 1) { |
672 | currItem.desc = w.getDescription().latin1(); | 677 | currItem.desc = w.getDescription().latin1(); |
673 | currItem.name = w.getUsername().latin1(); | 678 | currItem.name = w.getUsername().latin1(); |
674 | currItem.pw = w.getPassword().latin1(); | 679 | currItem.pw = w.getPassword().latin1(); |
675 | currItem.comment = w.getComment().latin1(); | 680 | currItem.comment = w.getComment().latin1(); |
676 | currItem.url = w.getUrl().latin1(); | 681 | currItem.url = w.getUrl().latin1(); |
677 | currItem.launcher = w.getLauncher().latin1(); | 682 | currItem.launcher = w.getLauncher().latin1(); |
678 | if (!doc->editEntry(curCategory, w.getCategory(), | 683 | if (!doc->editEntry(curCategory, w.getCategory(), |
679 | curEntryIndex, &currItem)) { | 684 | curEntryIndex, &currItem)) { |
680 | KMessageBox::error(this, | 685 | KMessageBox::error(this, |
681 | i18n("Couldn't edit the entry.\n" | 686 | i18n("Couldn't edit the entry.\n" |
682 | "Maybe you changed the category and " | 687 | "Maybe you changed the category and " |
683 | "this entry is already present in the new " | 688 | "this entry is already present in the new " |
684 | "category?"), | 689 | "category?"), |
685 | i18n("couldn't edit entry.")); | 690 | i18n("couldn't edit entry.")); |
686 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 691 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
687 | return; | 692 | return; |
688 | } | 693 | } |
689 | } | 694 | } |
690 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 695 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
691 | } | 696 | } |
692 | 697 | ||
693 | void PwM::deletePwd_slot() | 698 | void PwM::deletePwd_slot() |
694 | { | 699 | { |
695 | PWM_ASSERT(curDoc()); | 700 | PWM_ASSERT(curDoc()); |
696 | if (curDoc()->isDocEmpty()) | 701 | if (curDoc()->isDocEmpty()) |
697 | return; | 702 | return; |
698 | if (curDoc()->isDeepLocked()) | 703 | if (curDoc()->isDeepLocked()) |
699 | return; | 704 | return; |
700 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 705 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
701 | unsigned int curEntryIndex = 0; | 706 | unsigned int curEntryIndex = 0; |
702 | if (!(view->getCurEntryIndex(&curEntryIndex))) { | 707 | if (!(view->getCurEntryIndex(&curEntryIndex))) { |
703 | printDebug("couldn't get index"); | 708 | printDebug("couldn't get index"); |
704 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 709 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
705 | return; | 710 | return; |
706 | } | 711 | } |
707 | 712 | ||
708 | PwMDataItem currItem; | 713 | PwMDataItem currItem; |
709 | QString curCategory = view->getCurrentCategory(); | 714 | QString curCategory = view->getCurrentCategory(); |
710 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { | 715 | if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) { |
711 | printDebug("couldn't get entry"); | 716 | printDebug("couldn't get entry"); |
712 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 717 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
713 | return; | 718 | return; |
714 | } | 719 | } |
715 | if (KMessageBox:: | 720 | if (KMessageBox:: |
716 | questionYesNo(this, | 721 | questionYesNo(this, |
717 | i18n | 722 | i18n |
718 | ("Do you really want to delete the selected entry") + | 723 | ("Do you really want to delete the selected entry") + |
719 | " \"" + QString(currItem.desc.c_str()) | 724 | " \"" + QString(currItem.desc.c_str()) |
720 | + "\" ?", i18n("delete?")) | 725 | + "\" ?", i18n("delete?")) |
721 | == KMessageBox::Yes) { | 726 | == KMessageBox::Yes) { |
722 | 727 | ||
723 | curDoc()->delEntry(curCategory, curEntryIndex); | 728 | curDoc()->delEntry(curCategory, curEntryIndex); |
724 | } | 729 | } |
725 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 730 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
726 | } | 731 | } |
727 | 732 | ||
728 | void PwM::changeMasterPwd_slot() | 733 | void PwM::changeMasterPwd_slot() |
729 | { | 734 | { |
730 | PWM_ASSERT(curDoc()); | 735 | PWM_ASSERT(curDoc()); |
731 | curDoc()->changeCurrentPw(); | 736 | curDoc()->changeCurrentPw(); |
732 | } | 737 | } |
733 | 738 | ||
734 | void PwM::lockWnd_slot() | 739 | void PwM::lockWnd_slot() |
735 | { | 740 | { |
736 | PWM_ASSERT(curDoc()); | 741 | PWM_ASSERT(curDoc()); |
737 | curDoc()->lockAll(true); | 742 | curDoc()->lockAll(true); |
738 | } | 743 | } |
739 | 744 | ||
740 | void PwM::deepLockWnd_slot() | 745 | void PwM::deepLockWnd_slot() |
741 | { | 746 | { |
742 | PWM_ASSERT(curDoc()); | 747 | PWM_ASSERT(curDoc()); |
743 | curDoc()->deepLock(); | 748 | curDoc()->deepLock(); |
744 | } | 749 | } |
745 | 750 | ||
746 | void PwM::unlockWnd_slot() | 751 | void PwM::unlockWnd_slot() |
747 | { | 752 | { |
748 | PWM_ASSERT(curDoc()); | 753 | PWM_ASSERT(curDoc()); |
749 | curDoc()->lockAll(false); | 754 | curDoc()->lockAll(false); |
750 | } | 755 | } |
751 | 756 | ||
752 | void PwM::config_slot() | 757 | void PwM::config_slot() |
753 | { | 758 | { |
754 | Configuration *conf = Configuration::obj(); | 759 | int oldStyle = conf()->confWndMainViewStyle(); |
755 | int oldStyle = conf->confWndMainViewStyle(); | 760 | #ifdef PWM_EMBEDDED |
761 | KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"pwmconfigdialog", true ); | ||
762 | |||
763 | KCMPwmConfig* pwmcfg = new KCMPwmConfig( ConfigureDialog->getNewVBoxPage(i18n( "PwManager")) , "KCMPwmConfig" ); | ||
764 | ConfigureDialog->addModule(pwmcfg ); | ||
756 | 765 | ||
766 | KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); | ||
767 | ConfigureDialog->addModule(kdelibcfg ); | ||
768 | |||
769 | #ifndef DESKTOP_VERSION | ||
770 | ConfigureDialog->showMaximized(); | ||
771 | #endif | ||
772 | if ( ConfigureDialog->exec() ) | ||
773 | KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); | ||
774 | delete ConfigureDialog; | ||
775 | |||
776 | #else //PWM_EMBEDDED | ||
757 | // display the configuration window (modal mode) | 777 | // display the configuration window (modal mode) |
758 | if (!conf->showConfWnd(this)) | 778 | if (!conf()->showConfWnd(this)) |
759 | return; | 779 | return; |
780 | #endif | ||
760 | 781 | ||
761 | int newStyle = conf->confWndMainViewStyle(); | 782 | int newStyle = conf()->confWndMainViewStyle(); |
762 | // reinitialize tray | 783 | // reinitialize tray |
763 | init->initTray(); | 784 | init->initTray(); |
764 | // reinitialize KWallet emulation | 785 | // reinitialize KWallet emulation |
765 | init->initKWalletEmu(); | 786 | init->initKWalletEmu(); |
766 | 787 | ||
767 | PwMDocList *_dl = PwMDoc::getOpenDocList(); | 788 | PwMDocList *_dl = PwMDoc::getOpenDocList(); |
768 | const vector<PwMDocList::listItem> *dl = _dl->getList(); | 789 | const vector<PwMDocList::listItem> *dl = _dl->getList(); |
769 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), | 790 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), |
770 | end = dl->end(); | 791 | end = dl->end(); |
771 | PwMDoc *doc; | 792 | PwMDoc *doc; |
772 | while (i != end) { | 793 | while (i != end) { |
773 | doc = (*i).doc; | 794 | doc = (*i).doc; |
774 | // unlock-without-mpw timeout | 795 | // unlock-without-mpw timeout |
775 | doc->timer()->start(DocTimer::id_mpwTimer); | 796 | doc->timer()->start(DocTimer::id_mpwTimer); |
776 | // auto-lock timeout | 797 | // auto-lock timeout |
777 | doc->timer()->start(DocTimer::id_autoLockTimer); | 798 | doc->timer()->start(DocTimer::id_autoLockTimer); |
778 | ++i; | 799 | ++i; |
779 | } | 800 | } |
780 | 801 | ||
781 | const QValueList<PwM *> *ml = init->mainWndList(); | 802 | const QValueList<PwM *> *ml = init->mainWndList(); |
782 | #ifndef PWM_EMBEDDED | 803 | #ifndef PWM_EMBEDDED |
783 | QValueList<PwM *>::const_iterator i2 = ml->begin(), | 804 | QValueList<PwM *>::const_iterator i2 = ml->begin(), |
784 | end2 = ml->end(); | 805 | end2 = ml->end(); |
785 | #else | 806 | #else |
786 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), | 807 | QValueList<PwM *>::ConstIterator i2 = ml->begin(), |
787 | end2 = ml->end(); | 808 | end2 = ml->end(); |
788 | #endif | 809 | #endif |
789 | PwM *pwm; | 810 | PwM *pwm; |
790 | while (i2 != end2) { | 811 | while (i2 != end2) { |
791 | pwm = *i2; | 812 | pwm = *i2; |
792 | // reinitialize the window style. | 813 | // reinitialize the window style. |
793 | if (oldStyle != newStyle) | 814 | if (oldStyle != newStyle) |
794 | pwm->curView()->initStyle(newStyle); | 815 | pwm->curView()->initStyle(newStyle); |
795 | // set the new font | 816 | // set the new font |
796 | pwm->curView()->setFont(conf->confGlobEntryFont()); | 817 | pwm->curView()->setFont(conf()->confGlobEntryFont()); |
797 | ++i2; | 818 | ++i2; |
798 | } | 819 | } |
799 | } | 820 | } |
800 | 821 | ||
801 | void PwM::activateMpButton(bool activate) | 822 | void PwM::activateMpButton(bool activate) |
802 | { | 823 | { |
803 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); | 824 | managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate); |
804 | } | 825 | } |
805 | 826 | ||
806 | void PwM::closeEvent(QCloseEvent *e) | 827 | void PwM::closeEvent(QCloseEvent *e) |
807 | { | 828 | { |
808 | e->accept(); | 829 | e->accept(); |
809 | } | 830 | } |
810 | 831 | ||
811 | void PwM::docClosed(PwMDoc *doc) | 832 | void PwM::docClosed(PwMDoc *doc) |
812 | { | 833 | { |
813 | PARAM_UNUSED(doc); | 834 | PARAM_UNUSED(doc); |
814 | PWM_ASSERT(doc == curDoc()); | 835 | PWM_ASSERT(doc == curDoc()); |
815 | close(); | 836 | close(); |
816 | } | 837 | } |
817 | 838 | ||
818 | void PwM::find_slot() | 839 | void PwM::find_slot() |
819 | { | 840 | { |
820 | PWM_ASSERT(curDoc()); | 841 | PWM_ASSERT(curDoc()); |
821 | if (curDoc()->isDocEmpty()) | 842 | if (curDoc()->isDocEmpty()) |
822 | return; | 843 | return; |
823 | if (curDoc()->isDeepLocked()) | 844 | if (curDoc()->isDeepLocked()) |
824 | return; | 845 | return; |
825 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 846 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
826 | FindWndImpl findWnd(view); | 847 | FindWndImpl findWnd(view); |
827 | findWnd.exec(); | 848 | findWnd.exec(); |
828 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 849 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
829 | } | 850 | } |
830 | 851 | ||
831 | void PwM::exportToText() | 852 | void PwM::exportToText() |
832 | { | 853 | { |
833 | PWM_ASSERT(curDoc()); | 854 | PWM_ASSERT(curDoc()); |
834 | if (curDoc()->isDocEmpty()) { | 855 | if (curDoc()->isDocEmpty()) { |
835 | KMessageBox::information(this, | 856 | KMessageBox::information(this, |
836 | i18n | 857 | i18n |
837 | ("Sorry, there's nothing to export.\n" | 858 | ("Sorry, there's nothing to export.\n" |
838 | "Please first add some passwords."), | 859 | "Please first add some passwords."), |
839 | i18n("nothing to do")); | 860 | i18n("nothing to do")); |
840 | return; | 861 | return; |
841 | } | 862 | } |
842 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 863 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
843 | QString fn(KFileDialog::getSaveFileName(QString::null, | 864 | QString fn(KFileDialog::getSaveFileName(QString::null, |
844 | i18n("*|plain-text file"), | 865 | i18n("*|plain-text file"), |
845 | this)); | 866 | this)); |
846 | if (fn == "") { | 867 | if (fn == "") { |
847 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 868 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
848 | return; | 869 | return; |
849 | } | 870 | } |
850 | 871 | ||
851 | PwMerror ret = curDoc()->exportToText(&fn); | 872 | PwMerror ret = curDoc()->exportToText(&fn); |
852 | if (ret != e_success) { | 873 | if (ret != e_success) { |
853 | KMessageBox::error(this, | 874 | KMessageBox::error(this, |
854 | i18n("Error: Couldn't write to file.\n" | 875 | i18n("Error: Couldn't write to file.\n" |
855 | "Please check if you have permission to write " | 876 | "Please check if you have permission to write " |
856 | "to the file in that directory."), | 877 | "to the file in that directory."), |
857 | i18n("error while writing")); | 878 | i18n("error while writing")); |
858 | } else | 879 | } else |
859 | showStatMsg(i18n("Successfully exported data.")); | 880 | showStatMsg(i18n("Successfully exported data.")); |
860 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 881 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
861 | } | 882 | } |
862 | 883 | ||
863 | bool PwM::importFromText() | 884 | bool PwM::importFromText() |
864 | { | 885 | { |
865 | if (!isVirgin()) { | 886 | if (!isVirgin()) { |
866 | if (KMessageBox::questionYesNo(this, | 887 | if (KMessageBox::questionYesNo(this, |
867 | i18n("Do you want to import the data " | 888 | i18n("Do you want to import the data " |
868 | "into the current document? (If you " | 889 | "into the current document? (If you " |
869 | "select \"no\", a new document will be " | 890 | "select \"no\", a new document will be " |
870 | "opened.)"), | 891 | "opened.)"), |
871 | i18n("import into this document?")) | 892 | i18n("import into this document?")) |
872 | == KMessageBox::No) { | 893 | == KMessageBox::No) { |
873 | // import the data to a new window. | 894 | // import the data to a new window. |
874 | PwM *newInstance = init->createMainWnd(); | 895 | PwM *newInstance = init->createMainWnd(); |
875 | bool ok = newInstance->importFromText(); | 896 | bool ok = newInstance->importFromText(); |
876 | if (!ok) { | 897 | if (!ok) { |
877 | newInstance->setForceQuit(true); | 898 | newInstance->setForceQuit(true); |
878 | delete_and_null(newInstance); | 899 | delete_and_null(newInstance); |
879 | } | 900 | } |
880 | return ok; | 901 | return ok; |
881 | } | 902 | } |
882 | } | 903 | } |
883 | 904 | ||
884 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 905 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
885 | PwMerror ret; | 906 | PwMerror ret; |
886 | QString path(KFileDialog::getOpenFileName(QString::null, | 907 | QString path(KFileDialog::getOpenFileName(QString::null, |
887 | i18n("*|PWM-exported text file"), | 908 | i18n("*|PWM-exported text file"), |
888 | this)); | 909 | this)); |
889 | if (path == "") | 910 | if (path == "") |
890 | goto cancelImport; | 911 | goto cancelImport; |
891 | 912 | ||
892 | ret = curDoc()->importFromText(&path, 0); | 913 | ret = curDoc()->importFromText(&path, 0); |
893 | if (ret == e_fileFormat) { | 914 | if (ret == e_fileFormat) { |
894 | KMessageBox::error(this, | 915 | KMessageBox::error(this, |
895 | i18n("Could not read file-format.\n" | 916 | i18n("Could not read file-format.\n" |
896 | "This seems to be _not_ a valid file " | 917 | "This seems to be _not_ a valid file " |
897 | "exported by PwM."), | 918 | "exported by PwM."), |
898 | i18n("invalid file-format")); | 919 | i18n("invalid file-format")); |
899 | goto cancelImport; | 920 | goto cancelImport; |
900 | } else if (ret == e_invalidArg) { | 921 | } else if (ret == e_invalidArg) { |
901 | BUG(); | 922 | BUG(); |
902 | goto cancelImport; | 923 | goto cancelImport; |
903 | } else if (ret != e_success) { | 924 | } else if (ret != e_success) { |
904 | KMessageBox::error(this, | 925 | KMessageBox::error(this, |
905 | i18n("Could not import file!\n" | 926 | i18n("Could not import file!\n" |
906 | "Do you have permission to read this file? " | 927 | "Do you have permission to read this file? " |
907 | "Do you have enough free memory?"), | 928 | "Do you have enough free memory?"), |
908 | i18n("import failed")); | 929 | i18n("import failed")); |
909 | goto cancelImport; | 930 | goto cancelImport; |
910 | } | 931 | } |
911 | setVirgin(false); | 932 | setVirgin(false); |
912 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 933 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
913 | return true; | 934 | return true; |
914 | 935 | ||
915 | cancelImport: | 936 | cancelImport: |
916 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 937 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
917 | return false; | 938 | return false; |
918 | } | 939 | } |
919 | 940 | ||
920 | void PwM::exportToGpasman() | 941 | void PwM::exportToGpasman() |
921 | { | 942 | { |
922 | PWM_ASSERT(curDoc()); | 943 | PWM_ASSERT(curDoc()); |
923 | if (curDoc()->isDocEmpty()) { | 944 | if (curDoc()->isDocEmpty()) { |
924 | KMessageBox::information(this, | 945 | KMessageBox::information(this, |
925 | i18n | 946 | i18n |
926 | ("Sorry, there's nothing to export.\n" | 947 | ("Sorry, there's nothing to export.\n" |
927 | "Please first add some passwords."), | 948 | "Please first add some passwords."), |
928 | i18n("nothing to do")); | 949 | i18n("nothing to do")); |
929 | return; | 950 | return; |
930 | } | 951 | } |
931 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 952 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
932 | QString fn(KFileDialog::getSaveFileName(QString::null, | 953 | QString fn(KFileDialog::getSaveFileName(QString::null, |
933 | i18n("*|Gpasman or Kpasman file"), | 954 | i18n("*|Gpasman or Kpasman file"), |
934 | this)); | 955 | this)); |
935 | if (fn == "") { | 956 | if (fn == "") { |
936 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 957 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
937 | return; | 958 | return; |
938 | } | 959 | } |
939 | 960 | ||
940 | PwMerror ret = curDoc()->exportToGpasman(&fn); | 961 | PwMerror ret = curDoc()->exportToGpasman(&fn); |
941 | if (ret != e_success) { | 962 | if (ret != e_success) { |
942 | if (ret == e_noPw) { | 963 | if (ret == e_noPw) { |
943 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 964 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
944 | return; | 965 | return; |
945 | } | 966 | } |
946 | KMessageBox::error(this, | 967 | KMessageBox::error(this, |
947 | i18n("Error: Couldn't write to file.\n" | 968 | i18n("Error: Couldn't write to file.\n" |
948 | "Please check if you have permission to write " | 969 | "Please check if you have permission to write " |
949 | "to the file in that directory."), | 970 | "to the file in that directory."), |
950 | i18n("error while writing")); | 971 | i18n("error while writing")); |
951 | } else | 972 | } else |
952 | showStatMsg(i18n("Successfully exported data.")); | 973 | showStatMsg(i18n("Successfully exported data.")); |
953 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 974 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
954 | } | 975 | } |
955 | 976 | ||
956 | void PwM::exportToKWallet() | 977 | void PwM::exportToKWallet() |
957 | { | 978 | { |
958 | #ifdef CONFIG_KWALLETIF | 979 | #ifdef CONFIG_KWALLETIF |
959 | if (!checkAndAskForKWalletEmu()) | 980 | if (!checkAndAskForKWalletEmu()) |
960 | return; | 981 | return; |
961 | PWM_ASSERT(curDoc()); | 982 | PWM_ASSERT(curDoc()); |
962 | if (curDoc()->isDocEmpty()) { | 983 | if (curDoc()->isDocEmpty()) { |
963 | KMessageBox::information(this, | 984 | KMessageBox::information(this, |
964 | i18n | 985 | i18n |
965 | ("Sorry, there's nothing to export.\n" | 986 | ("Sorry, there's nothing to export.\n" |
966 | "Please first add some passwords."), | 987 | "Please first add some passwords."), |
967 | i18n("nothing to do")); | 988 | i18n("nothing to do")); |
968 | init->initKWalletEmu(); | 989 | init->initKWalletEmu(); |
969 | return; | 990 | return; |
970 | } | 991 | } |
971 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 992 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
972 | KWalletIf walletIf(this); | 993 | KWalletIf walletIf(this); |
973 | if (walletIf.kwalletExport(curDoc())) { | 994 | if (walletIf.kwalletExport(curDoc())) { |
974 | KMessageBox::information(this, | 995 | KMessageBox::information(this, |
975 | i18n("Successfully exported the data of the current " | 996 | i18n("Successfully exported the data of the current " |
976 | "document to KWallet."), | 997 | "document to KWallet."), |
977 | i18n("Successfully exported data.")); | 998 | i18n("Successfully exported data.")); |
978 | showStatMsg(i18n("Successfully exported data.")); | 999 | showStatMsg(i18n("Successfully exported data.")); |
979 | } | 1000 | } |
980 | init->initKWalletEmu(); | 1001 | init->initKWalletEmu(); |
981 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1002 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
982 | #endif // CONFIG_KWALLETIF | 1003 | #endif // CONFIG_KWALLETIF |
983 | } | 1004 | } |
984 | 1005 | ||
985 | bool PwM::importFromGpasman() | 1006 | bool PwM::importFromGpasman() |
986 | { | 1007 | { |
987 | if (!isVirgin()) { | 1008 | if (!isVirgin()) { |
988 | if (KMessageBox::questionYesNo(this, | 1009 | if (KMessageBox::questionYesNo(this, |
989 | i18n("Do you want to import the data " | 1010 | i18n("Do you want to import the data " |
990 | "into the current document? (If you " | 1011 | "into the current document? (If you " |
991 | "select \"no\", a new document will be " | 1012 | "select \"no\", a new document will be " |
992 | "opened.)"), | 1013 | "opened.)"), |
993 | i18n("import into this document?")) | 1014 | i18n("import into this document?")) |
994 | == KMessageBox::No) { | 1015 | == KMessageBox::No) { |
995 | // import the data to a new window. | 1016 | // import the data to a new window. |
996 | PwM *newInstance = init->createMainWnd(); | 1017 | PwM *newInstance = init->createMainWnd(); |
997 | bool ok = newInstance->importFromGpasman(); | 1018 | bool ok = newInstance->importFromGpasman(); |
998 | if (!ok) { | 1019 | if (!ok) { |
999 | newInstance->setForceQuit(true); | 1020 | newInstance->setForceQuit(true); |
1000 | delete_and_null(newInstance); | 1021 | delete_and_null(newInstance); |
1001 | } | 1022 | } |
1002 | return ok; | 1023 | return ok; |
1003 | } | 1024 | } |
1004 | } | 1025 | } |
1005 | 1026 | ||
1006 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1027 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1007 | PwMerror ret; | 1028 | PwMerror ret; |
1008 | QString path(KFileDialog::getOpenFileName(QString::null, | 1029 | QString path(KFileDialog::getOpenFileName(QString::null, |
1009 | i18n("*|Gpasman or Kpasman file"), this)); | 1030 | i18n("*|Gpasman or Kpasman file"), this)); |
1010 | if (path == "") | 1031 | if (path == "") |
1011 | goto cancelImport; | 1032 | goto cancelImport; |
1012 | ret = curDoc()->importFromGpasman(&path); | 1033 | ret = curDoc()->importFromGpasman(&path); |
1013 | if (ret == e_wrongPw) { | 1034 | if (ret == e_wrongPw) { |
1014 | if (KMessageBox::questionYesNo(this, | 1035 | if (KMessageBox::questionYesNo(this, |
1015 | i18n | 1036 | i18n |
1016 | ("This is probably the wrong master-password" | 1037 | ("This is probably the wrong master-password" |
1017 | "you have typed in.\n" | 1038 | "you have typed in.\n" |
1018 | "There is no real way to determine the " | 1039 | "There is no real way to determine the " |
1019 | "correctness of the password in the Gpasman " | 1040 | "correctness of the password in the Gpasman " |
1020 | "file-format. But I think this " | 1041 | "file-format. But I think this " |
1021 | "password ist wrong.\n" | 1042 | "password ist wrong.\n" |
1022 | "Do you want to continue nevertheless?"), | 1043 | "Do you want to continue nevertheless?"), |
1023 | i18n("password error")) | 1044 | i18n("password error")) |
1024 | == KMessageBox::No) { | 1045 | == KMessageBox::No) { |
1025 | goto cancelImport; | 1046 | goto cancelImport; |
1026 | } | 1047 | } |
1027 | } else if (ret != e_success) { | 1048 | } else if (ret != e_success) { |
1028 | KMessageBox::error(this, | 1049 | KMessageBox::error(this, |
1029 | i18n("Could not import file!\n" | 1050 | i18n("Could not import file!\n" |
1030 | "Do you have permission to read this file?"), | 1051 | "Do you have permission to read this file?"), |
1031 | i18n("import failed")); | 1052 | i18n("import failed")); |
1032 | goto cancelImport; | 1053 | goto cancelImport; |
1033 | } | 1054 | } |
1034 | setVirgin(false); | 1055 | setVirgin(false); |
1035 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1056 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1036 | return true; | 1057 | return true; |
1037 | 1058 | ||
1038 | cancelImport: | 1059 | cancelImport: |
1039 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1060 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1040 | return false; | 1061 | return false; |
1041 | } | 1062 | } |
1042 | 1063 | ||
1043 | #ifdef CONFIG_KWALLETIF | 1064 | #ifdef CONFIG_KWALLETIF |
1044 | bool PwM::checkAndAskForKWalletEmu() | 1065 | bool PwM::checkAndAskForKWalletEmu() |
1045 | { | 1066 | { |
1046 | if (init->kwalletEmu()) { | 1067 | if (init->kwalletEmu()) { |
1047 | /* KWallet emulation is enabled. We can't import/export | 1068 | /* KWallet emulation is enabled. We can't import/export |
1048 | * data from/to it, while emulation is active. | 1069 | * data from/to it, while emulation is active. |
1049 | */ | 1070 | */ |
1050 | if (KMessageBox::questionYesNo(this, | 1071 | if (KMessageBox::questionYesNo(this, |
1051 | i18n("KWallet emulation is enabled.\n" | 1072 | i18n("KWallet emulation is enabled.\n" |
1052 | "You can't import or export data from/to " | 1073 | "You can't import or export data from/to " |
1053 | "the original KWallet, while the emulation " | 1074 | "the original KWallet, while the emulation " |
1054 | "is active.\n" | 1075 | "is active.\n" |
1055 | "Do you want to tempoarly disable the KWallet emulation?"), | 1076 | "Do you want to tempoarly disable the KWallet emulation?"), |
1056 | i18n("Tempoarly disable KWallet emulation?")) | 1077 | i18n("Tempoarly disable KWallet emulation?")) |
1057 | == KMessageBox::Yes) { | 1078 | == KMessageBox::Yes) { |
1058 | init->initKWalletEmu(true); | 1079 | init->initKWalletEmu(true); |
1059 | PWM_ASSERT(!init->kwalletEmu()); | 1080 | PWM_ASSERT(!init->kwalletEmu()); |
1060 | return true; | 1081 | return true; |
1061 | } | 1082 | } |
1062 | return false; | 1083 | return false; |
1063 | } | 1084 | } |
1064 | return true; | 1085 | return true; |
1065 | } | 1086 | } |
1066 | #endif // CONFIG_KWALLETIF | 1087 | #endif // CONFIG_KWALLETIF |
1067 | 1088 | ||
1068 | bool PwM::importKWallet() | 1089 | bool PwM::importKWallet() |
1069 | { | 1090 | { |
1070 | #ifdef CONFIG_KWALLETIF | 1091 | #ifdef CONFIG_KWALLETIF |
1071 | if (!checkAndAskForKWalletEmu()) | 1092 | if (!checkAndAskForKWalletEmu()) |
1072 | return false; | 1093 | return false; |
1073 | KWalletIf walletIf(this); | 1094 | KWalletIf walletIf(this); |
1074 | if (!isVirgin()) { | 1095 | if (!isVirgin()) { |
1075 | if (KMessageBox::questionYesNo(this, | 1096 | if (KMessageBox::questionYesNo(this, |
1076 | i18n("Do you want to import the data " | 1097 | i18n("Do you want to import the data " |
1077 | "into the current document? (If you " | 1098 | "into the current document? (If you " |
1078 | "select \"no\", a new document will be " | 1099 | "select \"no\", a new document will be " |
1079 | "opened.)"), | 1100 | "opened.)"), |
1080 | i18n("import into this document?")) | 1101 | i18n("import into this document?")) |
1081 | == KMessageBox::No) { | 1102 | == KMessageBox::No) { |
1082 | // import the data to a new window. | 1103 | // import the data to a new window. |
1083 | PwM *newInstance = init->createMainWnd(); | 1104 | PwM *newInstance = init->createMainWnd(); |
1084 | bool ok = newInstance->importKWallet(); | 1105 | bool ok = newInstance->importKWallet(); |
1085 | if (!ok) { | 1106 | if (!ok) { |
1086 | newInstance->setForceQuit(true); | 1107 | newInstance->setForceQuit(true); |
1087 | delete_and_null(newInstance); | 1108 | delete_and_null(newInstance); |
1088 | goto exit_fail; | 1109 | goto exit_fail; |
1089 | } else { | 1110 | } else { |
1090 | goto exit_ok; | 1111 | goto exit_ok; |
1091 | } | 1112 | } |
1092 | } | 1113 | } |
1093 | } | 1114 | } |
1094 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1115 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1095 | if (!walletIf.kwalletImport(curDoc())) { | 1116 | if (!walletIf.kwalletImport(curDoc())) { |
1096 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1117 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1097 | showStatMsg(i18n("KWallet import failed")); | 1118 | showStatMsg(i18n("KWallet import failed")); |
1098 | goto exit_fail; | 1119 | goto exit_fail; |
1099 | } | 1120 | } |
1100 | KMessageBox::information(this, | 1121 | KMessageBox::information(this, |
1101 | i18n("Successfully imported the KWallet data " | 1122 | i18n("Successfully imported the KWallet data " |
1102 | "into the current document."), | 1123 | "into the current document."), |
1103 | i18n("successfully imported")); | 1124 | i18n("successfully imported")); |
1104 | showStatMsg(i18n("successfully imported")); | 1125 | showStatMsg(i18n("successfully imported")); |
1105 | setVirgin(false); | 1126 | setVirgin(false); |
1106 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1127 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1107 | 1128 | ||
1108 | exit_ok: | 1129 | exit_ok: |
1109 | init->initKWalletEmu(); | 1130 | init->initKWalletEmu(); |
1110 | return true; | 1131 | return true; |
1111 | 1132 | ||
1112 | exit_fail: | 1133 | exit_fail: |
1113 | init->initKWalletEmu(); | 1134 | init->initKWalletEmu(); |
1114 | #endif // CONFIG_KWALLETIF | 1135 | #endif // CONFIG_KWALLETIF |
1115 | return false; | 1136 | return false; |
1116 | } | 1137 | } |
1117 | 1138 | ||
1118 | void PwM::print_slot() | 1139 | void PwM::print_slot() |
1119 | { | 1140 | { |
1120 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); | 1141 | curDoc()->timer()->getLock(DocTimer::id_autoLockTimer); |
1121 | #ifndef PWM_EMBEDDED | 1142 | #ifndef PWM_EMBEDDED |
1122 | PwMPrint p(curDoc(), this); | 1143 | PwMPrint p(curDoc(), this); |
1123 | p.printNow(); | 1144 | p.printNow(); |
1124 | #else | 1145 | #else |
1125 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); | 1146 | qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED"); |
1126 | #endif | 1147 | #endif |
1127 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); | 1148 | curDoc()->timer()->putLock(DocTimer::id_autoLockTimer); |
1128 | } | 1149 | } |
1129 | 1150 | ||
1130 | void PwM::genNewCard_slot() | 1151 | void PwM::genNewCard_slot() |
1131 | { | 1152 | { |
1132 | #ifdef CONFIG_KEYCARD | 1153 | #ifdef CONFIG_KEYCARD |
1133 | init->keycard()->genNewCard(); | 1154 | init->keycard()->genNewCard(); |
1134 | #endif | 1155 | #endif |
1135 | } | 1156 | } |
1136 | 1157 | ||
1137 | void PwM::eraseCard_slot() | 1158 | void PwM::eraseCard_slot() |
1138 | { | 1159 | { |
1139 | #ifdef CONFIG_KEYCARD | 1160 | #ifdef CONFIG_KEYCARD |
1140 | init->keycard()->eraseCard(); | 1161 | init->keycard()->eraseCard(); |
1141 | #endif | 1162 | #endif |
1142 | } | 1163 | } |
1143 | 1164 | ||
1144 | void PwM::readCardId_slot() | 1165 | void PwM::readCardId_slot() |
1145 | { | 1166 | { |
1146 | #ifdef CONFIG_KEYCARD | 1167 | #ifdef CONFIG_KEYCARD |
1147 | init->keycard()->displayKey(); | 1168 | init->keycard()->displayKey(); |
1148 | #endif | 1169 | #endif |
1149 | } | 1170 | } |
1150 | 1171 | ||
1151 | void PwM::makeCardBackup_slot() | 1172 | void PwM::makeCardBackup_slot() |
1152 | { | 1173 | { |
1153 | #ifdef CONFIG_KEYCARD | 1174 | #ifdef CONFIG_KEYCARD |
1154 | init->keycard()->makeBackupImage(); | 1175 | init->keycard()->makeBackupImage(); |
1155 | #endif | 1176 | #endif |
1156 | } | 1177 | } |
1157 | 1178 | ||
1158 | void PwM::replayCardBackup_slot() | 1179 | void PwM::replayCardBackup_slot() |
1159 | { | 1180 | { |
1160 | #ifdef CONFIG_KEYCARD | 1181 | #ifdef CONFIG_KEYCARD |
1161 | init->keycard()->replayBackupImage(); | 1182 | init->keycard()->replayBackupImage(); |
1162 | #endif | 1183 | #endif |
1163 | } | 1184 | } |
1164 | 1185 | ||
1165 | void PwM::execLauncher_slot() | 1186 | void PwM::execLauncher_slot() |
1166 | { | 1187 | { |
1167 | PWM_ASSERT(curDoc()); | 1188 | PWM_ASSERT(curDoc()); |
1168 | if (curDoc()->isDeepLocked()) | 1189 | if (curDoc()->isDeepLocked()) |
1169 | return; | 1190 | return; |
1170 | unsigned int curEntryIndex; | 1191 | unsigned int curEntryIndex; |
1171 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1192 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1172 | return; | 1193 | return; |
1173 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), | 1194 | bool ret = curDoc()->execLauncher(view->getCurrentCategory(), |
1174 | curEntryIndex); | 1195 | curEntryIndex); |
1175 | if (ret) | 1196 | if (ret) |
1176 | showStatMsg(i18n("Executed the \"Launcher\".")); | 1197 | showStatMsg(i18n("Executed the \"Launcher\".")); |
1177 | else | 1198 | else |
1178 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); | 1199 | showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!")); |
1179 | } | 1200 | } |
1180 | 1201 | ||
1181 | void PwM::goToURL_slot() | 1202 | void PwM::goToURL_slot() |
1182 | { | 1203 | { |
1183 | PWM_ASSERT(curDoc()); | 1204 | PWM_ASSERT(curDoc()); |
1184 | if (curDoc()->isDeepLocked()) | 1205 | if (curDoc()->isDeepLocked()) |
1185 | return; | 1206 | return; |
1186 | unsigned int curEntryIndex; | 1207 | unsigned int curEntryIndex; |
1187 | if (!view->getCurEntryIndex(&curEntryIndex)) | 1208 | if (!view->getCurEntryIndex(&curEntryIndex)) |
1188 | return; | 1209 | return; |
1189 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), | 1210 | bool ret = curDoc()->goToURL(view->getCurrentCategory(), |
1190 | curEntryIndex); | 1211 | curEntryIndex); |
1191 | if (ret) | 1212 | if (ret) |
1192 | showStatMsg(i18n("started browser with current URL.")); | 1213 | showStatMsg(i18n("started browser with current URL.")); |
1193 | else | 1214 | else |
1194 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); | 1215 | showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?")); |
1195 | } | 1216 | } |
1196 | 1217 | ||
1197 | void PwM::copyToClipboard(const QString &s) | 1218 | void PwM::copyToClipboard(const QString &s) |
1198 | { | 1219 | { |
1199 | QClipboard *cb = QApplication::clipboard(); | 1220 | QClipboard *cb = QApplication::clipboard(); |
1200 | #ifndef PWM_EMBEDDED | 1221 | #ifndef PWM_EMBEDDED |
1201 | if (cb->supportsSelection()) | 1222 | if (cb->supportsSelection()) |
1202 | cb->setText(s, QClipboard::Selection); | 1223 | cb->setText(s, QClipboard::Selection); |
1203 | cb->setText(s, QClipboard::Clipboard); | 1224 | cb->setText(s, QClipboard::Clipboard); |
1204 | #else | 1225 | #else |
1205 | cb->setText(s); | 1226 | cb->setText(s); |
1206 | 1227 | ||
1207 | #endif | 1228 | #endif |
1208 | 1229 | ||
1209 | } | 1230 | } |
1210 | 1231 | ||
1211 | void PwM::showStatMsg(const QString &msg) | 1232 | void PwM::showStatMsg(const QString &msg) |
1212 | { | 1233 | { |
1213 | #ifndef PWM_EMBEDDED | 1234 | #ifndef PWM_EMBEDDED |
1214 | KStatusBar *statBar = statusBar(); | 1235 | KStatusBar *statBar = statusBar(); |
1215 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); | 1236 | statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000); |
1216 | #else | 1237 | #else |
1217 | qDebug("Statusbar : %s",msg.latin1()); | 1238 | qDebug("Statusbar : %s",msg.latin1()); |
1218 | #endif | 1239 | #endif |
1219 | } | 1240 | } |
1220 | 1241 | ||
1221 | void PwM::focusInEvent(QFocusEvent *e) | 1242 | void PwM::focusInEvent(QFocusEvent *e) |
1222 | { | 1243 | { |
1223 | if (e->gotFocus()) { | 1244 | if (e->gotFocus()) { |
1224 | emit gotFocus(this); | 1245 | emit gotFocus(this); |
1225 | } else if (e->lostFocus()) { | 1246 | } else if (e->lostFocus()) { |
1226 | emit lostFocus(this); | 1247 | emit lostFocus(this); |
1227 | } | 1248 | } |
1228 | } | 1249 | } |
1229 | 1250 | ||
1230 | 1251 | ||
1231 | #ifdef PWM_EMBEDDED | 1252 | #ifdef PWM_EMBEDDED |
1232 | 1253 | ||
1233 | void PwM::showLicense_slot() | 1254 | void PwM::showLicense_slot() |
1234 | { | 1255 | { |
1235 | KApplication::showLicence(); | 1256 | KApplication::showLicence(); |
1236 | } | 1257 | } |
1237 | 1258 | ||
1238 | void PwM::faq_slot() | 1259 | void PwM::faq_slot() |
1239 | { | 1260 | { |
1240 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); | 1261 | KApplication::showFile( "PWM/Pi FAQ", "kdepim/pwmanager/pwmanagerFAQ.txt" ); |
1241 | } | 1262 | } |
1242 | 1263 | ||
1243 | void PwM::createAboutData_slot() | 1264 | void PwM::createAboutData_slot() |
1244 | { | 1265 | { |
1245 | QString version; | 1266 | QString version; |
1246 | #include <../version> | 1267 | #include <../version> |
1247 | QMessageBox::about( this, "About PwManager/Pi", | 1268 | QMessageBox::about( this, "About PwManager/Pi", |
1248 | "PwManager/Platform-independent\n" | 1269 | "PwManager/Platform-independent\n" |
1249 | "(PWM/Pi) " +version + " - " + | 1270 | "(PWM/Pi) " +version + " - " + |
1250 | #ifdef DESKTOP_VERSION | 1271 | #ifdef DESKTOP_VERSION |
1251 | "Desktop Edition\n" | 1272 | "Desktop Edition\n" |
1252 | #else | 1273 | #else |
1253 | "PDA-Edition\n" | 1274 | "PDA-Edition\n" |
1254 | "for: Zaurus 5500 / 7x0 / 8x0\n" | 1275 | "for: Zaurus 5500 / 7x0 / 8x0\n" |
1255 | #endif | 1276 | #endif |
1256 | 1277 | ||
1257 | "(c) 2004 Ulf Schenk\n" | 1278 | "(c) 2004 Ulf Schenk\n" |
1258 | "(c) 2004 Lutz Rogowski\n" | 1279 | "(c) 2004 Lutz Rogowski\n" |
1259 | "(c) 1997-2003, The KDE PIM Team\n" | 1280 | "(c) 1997-2003, The KDE PIM Team\n" |
1260 | 1281 | ||
1261 | "Michael Buesch - main programming and current maintainer\nmbuesch@freenet.de\n" | 1282 | "Michael Buesch - main programming and current maintainer\nmbuesch@freenet.de\n" |
1262 | "Matt Scifo - original implementaion of \n" | 1283 | "Matt Scifo - original implementaion of \n" |
1263 | "\"categories\" and the password-tree \n" | 1284 | "\"categories\" and the password-tree \n" |
1264 | "in the system-tray. Original implementations of \n" | 1285 | "in the system-tray. Original implementations of \n" |
1265 | "numerous view-improvements.\n" | 1286 | "numerous view-improvements.\n" |
1266 | "mscifo@o1.com\n" | 1287 | "mscifo@o1.com\n" |
1267 | "Elias Probst - Gentoo ebuild maintainer.\nelias.probst@gmx.de\n" | 1288 | "Elias Probst - Gentoo ebuild maintainer.\nelias.probst@gmx.de\n" |
1268 | "George Staikos - KWallet\nstaikos@kde.org\n" | 1289 | "George Staikos - KWallet\nstaikos@kde.org\n" |
1269 | "Matthew Palmer - rc2 code\nmjp16@uow.edu.au\n" | 1290 | "Matthew Palmer - rc2 code\nmjp16@uow.edu.au\n" |
1270 | "Olivier Sessink - gpasman\ngpasman@nl.linux.org\n" | 1291 | "Olivier Sessink - gpasman\ngpasman@nl.linux.org\n" |
1271 | "The libgcrypt developers - Blowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" | 1292 | "The libgcrypt developers - Blowfish and SHA1 algorithms\nftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/\n" |
1272 | "Troy Engel - kpasman\n tengel@sonic.net\n" | 1293 | "Troy Engel - kpasman\n tengel@sonic.net\n" |
1273 | "Wickey - graphics-design in older versions\nwickey@gmx.at\n" | 1294 | "Wickey - graphics-design in older versions\nwickey@gmx.at\n" |
1274 | "Ian MacGregor - original documentation author.\n" | 1295 | "Ian MacGregor - original documentation author.\n" |
1275 | ); | 1296 | ); |
1276 | } | 1297 | } |
1277 | 1298 | ||
1278 | #endif | 1299 | #endif |
1279 | 1300 | ||
1280 | 1301 | ||
1281 | #ifndef PWM_EMBEDDED | 1302 | #ifndef PWM_EMBEDDED |
1282 | #include "pwm.moc" | 1303 | #include "pwm.moc" |
1283 | #endif | 1304 | #endif |
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro index 2cd69a5..5c29ea4 100644 --- a/pwmanager/pwmanager/pwmanagerE.pro +++ b/pwmanager/pwmanager/pwmanagerE.pro | |||
@@ -1,144 +1,153 @@ | |||
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 ../../microkde ../../microkde/kdecore ../../microkde/kdeui $(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 PWM_DEBUG |
12 | LIBS += -lmicrokde | 12 | LIBS += -lmicrokde |
13 | LIBS += -lmicroqtcompat | 13 | LIBS += -lmicroqtcompat |
14 | LIBS += -lmicrokdepim | ||
14 | LIBS += -L$(QPEDIR)/lib | 15 | LIBS += -L$(QPEDIR)/lib |
15 | LIBS += -lqpe | 16 | LIBS += -lqpe |
16 | LIBS += -lbz2 | 17 | LIBS += -lbz2 |
17 | LIBS += $(QTOPIALIB) | 18 | LIBS += $(QTOPIALIB) |
18 | 19 | ||
19 | #INTERFACES = \ | 20 | #INTERFACES = \ |
20 | #addentrywnd.ui \ | 21 | #addentrywnd.ui \ |
21 | #configwnd.ui \ | 22 | #configwnd.ui \ |
22 | #findwnd.ui \ | 23 | #findwnd.ui \ |
23 | #getmasterpwwnd.ui \ | 24 | #getmasterpwwnd.ui \ |
24 | #pwgenwnd.ui \ | 25 | #pwgenwnd.ui \ |
25 | #setmasterpwwnd.ui \ | 26 | #setmasterpwwnd.ui \ |
26 | #subtbledit.ui | 27 | #subtbledit.ui |
27 | 28 | ||
28 | #INTERFACES = \ | 29 | #INTERFACES = \ |
29 | #subtbledit.ui \ | 30 | #subtbledit.ui \ |
30 | 31 | ||
31 | 32 | ||
32 | 33 | ||
33 | #HEADERS = \ | 34 | #HEADERS = \ |
35 | #configuration_31compat.h \ | ||
36 | #configuration.h \ | ||
37 | #configwnd.h \ | ||
38 | #configwndimpl.h \ | ||
34 | #selftest.h | 39 | #selftest.h |
35 | 40 | ||
36 | HEADERS = \ | 41 | HEADERS = \ |
37 | addentrywnd.h \ | 42 | addentrywnd.h \ |
38 | addentrywndimpl.h \ | 43 | addentrywndimpl.h \ |
39 | base64.h \ | 44 | base64.h \ |
40 | binentrygen.h \ | 45 | binentrygen.h \ |
41 | blowfish.h \ | 46 | blowfish.h \ |
42 | commentbox.h \ | 47 | commentbox.h \ |
43 | compiler.h \ | 48 | compiler.h \ |
44 | compressbzip2.h \ | 49 | compressbzip2.h \ |
45 | compressgzip.h \ | 50 | compressgzip.h \ |
46 | configuration_31compat.h \ | ||
47 | configuration.h \ | ||
48 | configwnd.h \ | ||
49 | configwndimpl.h \ | ||
50 | findwnd.h \ | 51 | findwnd.h \ |
51 | findwndimpl.h \ | 52 | findwndimpl.h \ |
52 | genpasswd.h \ | 53 | genpasswd.h \ |
53 | getkeycardwnd.h \ | 54 | getkeycardwnd.h \ |
54 | getmasterpwwnd.h \ | 55 | getmasterpwwnd.h \ |
55 | getmasterpwwndimpl.h \ | 56 | getmasterpwwndimpl.h \ |
56 | globalstuff.h \ | 57 | globalstuff.h \ |
57 | gpasmanfile.h \ | 58 | gpasmanfile.h \ |
58 | htmlgen.h \ | 59 | htmlgen.h \ |
59 | htmlparse.h \ | 60 | htmlparse.h \ |
60 | ipc.h \ | 61 | ipc.h \ |
61 | listobjselectwnd.h \ | 62 | listobjselectwnd.h \ |
62 | listviewpwm.h \ | 63 | listviewpwm.h \ |
63 | printtext.h \ | 64 | printtext.h \ |
64 | pwgenwnd.h \ | 65 | pwgenwnd.h \ |
65 | pwgenwndimpl.h \ | 66 | pwgenwndimpl.h \ |
66 | pwmdoc.h \ | 67 | pwmdoc.h \ |
67 | pwmdocui.h \ | 68 | pwmdocui.h \ |
68 | pwmexception.h \ | 69 | pwmexception.h \ |
69 | pwm.h \ | 70 | pwm.h \ |
70 | pwminit.h \ | 71 | pwminit.h \ |
72 | pwmprefs.h \ | ||
71 | pwmprint.h \ | 73 | pwmprint.h \ |
72 | pwmtray.h \ | 74 | pwmtray.h \ |
73 | pwmview.h \ | 75 | pwmview.h \ |
74 | pwmviewstyle_0.h \ | 76 | pwmviewstyle_0.h \ |
75 | pwmviewstyle_1.h \ | 77 | pwmviewstyle_1.h \ |
76 | pwmviewstyle.h \ | 78 | pwmviewstyle.h \ |
77 | randomizer.h \ | 79 | randomizer.h \ |
78 | rc2.h \ | 80 | rc2.h \ |
79 | rencatwnd.h \ | 81 | rencatwnd.h \ |
80 | serializer.h \ | 82 | serializer.h \ |
81 | setmasterpwwnd.h \ | 83 | setmasterpwwnd.h \ |
82 | setmasterpwwndimpl.h \ | 84 | setmasterpwwndimpl.h \ |
83 | sha1.h \ | 85 | sha1.h \ |
84 | subtbledit.h \ | 86 | subtbledit.h \ |
85 | subtbleditimpl.h \ | 87 | subtbleditimpl.h \ |
86 | waitwnd.h | 88 | waitwnd.h \ |
89 | kcmconfigs/kcmpwmconfig.h \ | ||
90 | kcmconfigs/pwmconfigwidget.h \ | ||
87 | 91 | ||
92 | #sources that need not be build | ||
88 | #SOURCES = \ | 93 | #SOURCES = \ |
89 | #advcommeditimpl.cpp \ | 94 | #advcommeditimpl.cpp \ |
95 | #configuration.cpp \ | ||
96 | #configwnd.cpp \ | ||
97 | #configwndimpl.cpp \ | ||
90 | #configuration_31compat.cpp \ | 98 | #configuration_31compat.cpp \ |
91 | #htmlparse.cpp \ | 99 | #htmlparse.cpp \ |
92 | #printtext.cpp \ | 100 | #printtext.cpp \ |
93 | #selftest.cpp \ | 101 | #selftest.cpp \ |
94 | #pwmprint.cpp \ | 102 | #pwmprint.cpp \ |
95 | #spinforsignal.cpp | 103 | #spinforsignal.cpp |
96 | 104 | ||
97 | SOURCES = \ | 105 | SOURCES = \ |
98 | addentrywnd.cpp \ | 106 | addentrywnd.cpp \ |
99 | addentrywndimpl.cpp \ | 107 | addentrywndimpl.cpp \ |
100 | base64.cpp \ | 108 | base64.cpp \ |
101 | binentrygen.cpp \ | 109 | binentrygen.cpp \ |
102 | blowfish.cpp \ | 110 | blowfish.cpp \ |
103 | commentbox.cpp \ | 111 | commentbox.cpp \ |
104 | compressbzip2.cpp \ | 112 | compressbzip2.cpp \ |
105 | compressgzip.cpp \ | 113 | compressgzip.cpp \ |
106 | configuration.cpp \ | ||
107 | configwnd.cpp \ | ||
108 | configwndimpl.cpp \ | ||
109 | findwnd.cpp \ | 114 | findwnd.cpp \ |
110 | findwndimpl.cpp \ | 115 | findwndimpl.cpp \ |
111 | genpasswd.cpp \ | 116 | genpasswd.cpp \ |
112 | getkeycardwnd.cpp \ | 117 | getkeycardwnd.cpp \ |
113 | getmasterpwwnd.cpp \ | 118 | getmasterpwwnd.cpp \ |
114 | getmasterpwwndimpl.cpp \ | 119 | getmasterpwwndimpl.cpp \ |
115 | globalstuff.cpp \ | 120 | globalstuff.cpp \ |
116 | gpasmanfile.cpp \ | 121 | gpasmanfile.cpp \ |
117 | htmlgen.cpp \ | 122 | htmlgen.cpp \ |
118 | ipc.cpp \ | 123 | ipc.cpp \ |
119 | listobjselectwnd.cpp \ | 124 | listobjselectwnd.cpp \ |
120 | listviewpwm.cpp \ | 125 | listviewpwm.cpp \ |
121 | main.cpp \ | 126 | main.cpp \ |
122 | pwgenwnd.cpp \ | 127 | pwgenwnd.cpp \ |
123 | pwgenwndimpl.cpp \ | 128 | pwgenwndimpl.cpp \ |
124 | pwm.cpp \ | 129 | pwm.cpp \ |
125 | pwmdoc.cpp \ | 130 | pwmdoc.cpp \ |
126 | pwmdocui.cpp \ | 131 | pwmdocui.cpp \ |
127 | pwmexception.cpp \ | 132 | pwmexception.cpp \ |
128 | pwminit.cpp \ | 133 | pwminit.cpp \ |
134 | pwmprefs.cpp \ | ||
129 | pwmtray.cpp \ | 135 | pwmtray.cpp \ |
130 | pwmview.cpp \ | 136 | pwmview.cpp \ |
131 | pwmviewstyle_0.cpp \ | 137 | pwmviewstyle_0.cpp \ |
132 | pwmviewstyle_1.cpp \ | 138 | pwmviewstyle_1.cpp \ |
133 | pwmviewstyle.cpp \ | 139 | pwmviewstyle.cpp \ |
134 | randomizer.cpp \ | 140 | randomizer.cpp \ |
135 | rc2.cpp \ | 141 | rc2.cpp \ |
136 | rencatwnd.cpp \ | 142 | rencatwnd.cpp \ |
137 | serializer.cpp \ | 143 | serializer.cpp \ |
138 | setmasterpwwnd.cpp \ | 144 | setmasterpwwnd.cpp \ |
139 | setmasterpwwndimpl.cpp \ | 145 | setmasterpwwndimpl.cpp \ |
140 | sha1.cpp \ | 146 | sha1.cpp \ |
141 | subtbledit.cpp \ | 147 | subtbledit.cpp \ |
142 | subtbleditimpl.cpp \ | 148 | subtbleditimpl.cpp \ |
143 | waitwnd.cpp \ | 149 | waitwnd.cpp \ |
150 | kcmconfigs/kcmpwmconfig.cpp \ | ||
151 | kcmconfigs/pwmconfigwidget.cpp \ | ||
152 | |||
144 | 153 | ||
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 04af360..9fe4809 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -1,1569 +1,1571 @@ | |||
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" | ||
35 | #include "kglobal.h" | ||
34 | #endif | 36 | #endif |
35 | 37 | ||
36 | #ifdef CONFIG_KWALLETIF | 38 | #ifdef CONFIG_KWALLETIF |
37 | # include "kwalletemu.h" | 39 | # include "kwalletemu.h" |
38 | #endif // CONFIG_KWALLETIF | 40 | #endif // CONFIG_KWALLETIF |
39 | 41 | ||
40 | #include <qdatetime.h> | 42 | #include <qdatetime.h> |
41 | #include <qsize.h> | 43 | #include <qsize.h> |
42 | #include <qfileinfo.h> | 44 | #include <qfileinfo.h> |
43 | #include <qfile.h> | 45 | #include <qfile.h> |
44 | 46 | ||
45 | #include <stdio.h> | 47 | #include <stdio.h> |
46 | #include <stdlib.h> | 48 | #include <stdlib.h> |
47 | #include <errno.h> | 49 | #include <errno.h> |
48 | #include <string.h> | 50 | #include <string.h> |
49 | #include <iostream> | 51 | #include <iostream> |
50 | #include <algorithm> | 52 | #include <algorithm> |
51 | #include <sys/types.h> | 53 | #include <sys/types.h> |
52 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
53 | #include <unistd.h> | 55 | #include <unistd.h> |
54 | #include <stdint.h> | 56 | #include <stdint.h> |
55 | 57 | ||
56 | //TODO: reset to its normal value. | 58 | //TODO: reset to its normal value. |
57 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ | 59 | #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */ |
58 | 60 | ||
59 | using namespace std; | 61 | using namespace std; |
60 | 62 | ||
61 | 63 | ||
62 | void PwMDocList::add(PwMDoc *doc, const string &id) | 64 | void PwMDocList::add(PwMDoc *doc, const string &id) |
63 | { | 65 | { |
64 | #ifdef PWM_DEBUG | 66 | #ifdef PWM_DEBUG |
65 | // check for existance of object in debug mode only. | 67 | // check for existance of object in debug mode only. |
66 | vector<listItem>::iterator begin = docList.begin(), | 68 | vector<listItem>::iterator begin = docList.begin(), |
67 | end = docList.end(), | 69 | end = docList.end(), |
68 | i = begin; | 70 | i = begin; |
69 | while (i != end) { | 71 | while (i != end) { |
70 | if (i->doc == doc) { | 72 | if (i->doc == doc) { |
71 | BUG(); | 73 | BUG(); |
72 | return; | 74 | return; |
73 | } | 75 | } |
74 | ++i; | 76 | ++i; |
75 | } | 77 | } |
76 | #endif | 78 | #endif |
77 | listItem newItem; | 79 | listItem newItem; |
78 | newItem.doc = doc; | 80 | newItem.doc = doc; |
79 | newItem.docId = id; | 81 | newItem.docId = id; |
80 | docList.push_back(newItem); | 82 | docList.push_back(newItem); |
81 | } | 83 | } |
82 | 84 | ||
83 | void PwMDocList::edit(PwMDoc *doc, const string &newId) | 85 | void PwMDocList::edit(PwMDoc *doc, const string &newId) |
84 | { | 86 | { |
85 | vector<listItem>::iterator begin = docList.begin(), | 87 | vector<listItem>::iterator begin = docList.begin(), |
86 | end = docList.end(), | 88 | end = docList.end(), |
87 | i = begin; | 89 | i = begin; |
88 | while (i != end) { | 90 | while (i != end) { |
89 | if (i->doc == doc) { | 91 | if (i->doc == doc) { |
90 | i->docId = newId; | 92 | i->docId = newId; |
91 | return; | 93 | return; |
92 | } | 94 | } |
93 | ++i; | 95 | ++i; |
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
97 | void PwMDocList::del(PwMDoc *doc) | 99 | void PwMDocList::del(PwMDoc *doc) |
98 | { | 100 | { |
99 | vector<listItem>::iterator begin = docList.begin(), | 101 | vector<listItem>::iterator begin = docList.begin(), |
100 | end = docList.end(), | 102 | end = docList.end(), |
101 | i = begin; | 103 | i = begin; |
102 | while (i != end) { | 104 | while (i != end) { |
103 | if (i->doc == doc) { | 105 | if (i->doc == doc) { |
104 | docList.erase(i); | 106 | docList.erase(i); |
105 | return; | 107 | return; |
106 | } | 108 | } |
107 | ++i; | 109 | ++i; |
108 | } | 110 | } |
109 | } | 111 | } |
110 | 112 | ||
111 | bool PwMDocList::find(const string &id, listItem *ret) | 113 | bool PwMDocList::find(const string &id, listItem *ret) |
112 | { | 114 | { |
113 | vector<listItem>::iterator begin = docList.begin(), | 115 | vector<listItem>::iterator begin = docList.begin(), |
114 | end = docList.end(), | 116 | end = docList.end(), |
115 | i = begin; | 117 | i = begin; |
116 | while (i != end) { | 118 | while (i != end) { |
117 | if (i->docId == id) { | 119 | if (i->docId == id) { |
118 | if (ret) | 120 | if (ret) |
119 | *ret = *i; | 121 | *ret = *i; |
120 | return true; | 122 | return true; |
121 | } | 123 | } |
122 | ++i; | 124 | ++i; |
123 | } | 125 | } |
124 | return false; | 126 | return false; |
125 | } | 127 | } |
126 | 128 | ||
127 | 129 | ||
128 | 130 | ||
129 | DocTimer::DocTimer(PwMDoc *_doc) | 131 | DocTimer::DocTimer(PwMDoc *_doc) |
130 | : doc (_doc) | 132 | : doc (_doc) |
131 | , mpwLock (0) | 133 | , mpwLock (0) |
132 | , autoLockLock (0) | 134 | , autoLockLock (0) |
133 | , metaCheckLock (0) | 135 | , metaCheckLock (0) |
134 | { | 136 | { |
135 | mpwTimer = new QTimer; | 137 | mpwTimer = new QTimer; |
136 | autoLockTimer = new QTimer; | 138 | autoLockTimer = new QTimer; |
137 | metaCheckTimer = new QTimer; | 139 | metaCheckTimer = new QTimer; |
138 | connect(mpwTimer, SIGNAL(timeout()), | 140 | connect(mpwTimer, SIGNAL(timeout()), |
139 | this, SLOT(mpwTimeout())); | 141 | this, SLOT(mpwTimeout())); |
140 | connect(autoLockTimer, SIGNAL(timeout()), | 142 | connect(autoLockTimer, SIGNAL(timeout()), |
141 | this, SLOT(autoLockTimeout())); | 143 | this, SLOT(autoLockTimeout())); |
142 | connect(metaCheckTimer, SIGNAL(timeout()), | 144 | connect(metaCheckTimer, SIGNAL(timeout()), |
143 | this, SLOT(metaCheckTimeout())); | 145 | this, SLOT(metaCheckTimeout())); |
144 | } | 146 | } |
145 | 147 | ||
146 | DocTimer::~DocTimer() | 148 | DocTimer::~DocTimer() |
147 | { | 149 | { |
148 | delete mpwTimer; | 150 | delete mpwTimer; |
149 | delete autoLockTimer; | 151 | delete autoLockTimer; |
150 | delete metaCheckTimer; | 152 | delete metaCheckTimer; |
151 | } | 153 | } |
152 | 154 | ||
153 | void DocTimer::start(TimerIDs timer) | 155 | void DocTimer::start(TimerIDs timer) |
154 | { | 156 | { |
155 | switch (timer) { | 157 | switch (timer) { |
156 | case id_mpwTimer: | 158 | case id_mpwTimer: |
157 | if (mpwTimer->isActive()) | 159 | if (mpwTimer->isActive()) |
158 | mpwTimer->stop(); | 160 | mpwTimer->stop(); |
159 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 161 | doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
160 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); | 162 | mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true); |
161 | break; | 163 | break; |
162 | case id_autoLockTimer: | 164 | case id_autoLockTimer: |
163 | if (autoLockTimer->isActive()) | 165 | if (autoLockTimer->isActive()) |
164 | autoLockTimer->stop(); | 166 | autoLockTimer->stop(); |
165 | if (conf()->confGlobLockTimeout() > 0) | 167 | if (conf()->confGlobLockTimeout() > 0) |
166 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); | 168 | autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true); |
167 | break; | 169 | break; |
168 | case id_metaCheckTimer: | 170 | case id_metaCheckTimer: |
169 | if (metaCheckTimer->isActive()) | 171 | if (metaCheckTimer->isActive()) |
170 | metaCheckTimer->stop(); | 172 | metaCheckTimer->stop(); |
171 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 173 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
172 | break; | 174 | break; |
173 | } | 175 | } |
174 | } | 176 | } |
175 | 177 | ||
176 | void DocTimer::stop(TimerIDs timer) | 178 | void DocTimer::stop(TimerIDs timer) |
177 | { | 179 | { |
178 | switch (timer) { | 180 | switch (timer) { |
179 | case id_mpwTimer: | 181 | case id_mpwTimer: |
180 | mpwTimer->stop(); | 182 | mpwTimer->stop(); |
181 | break; | 183 | break; |
182 | case id_autoLockTimer: | 184 | case id_autoLockTimer: |
183 | autoLockTimer->stop(); | 185 | autoLockTimer->stop(); |
184 | break; | 186 | break; |
185 | case id_metaCheckTimer: | 187 | case id_metaCheckTimer: |
186 | metaCheckTimer->stop(); | 188 | metaCheckTimer->stop(); |
187 | break; | 189 | break; |
188 | } | 190 | } |
189 | } | 191 | } |
190 | 192 | ||
191 | void DocTimer::getLock(TimerIDs timer) | 193 | void DocTimer::getLock(TimerIDs timer) |
192 | { | 194 | { |
193 | switch (timer) { | 195 | switch (timer) { |
194 | case id_mpwTimer: | 196 | case id_mpwTimer: |
195 | ++mpwLock; | 197 | ++mpwLock; |
196 | break; | 198 | break; |
197 | case id_autoLockTimer: | 199 | case id_autoLockTimer: |
198 | ++autoLockLock; | 200 | ++autoLockLock; |
199 | break; | 201 | break; |
200 | case id_metaCheckTimer: | 202 | case id_metaCheckTimer: |
201 | ++metaCheckLock; | 203 | ++metaCheckLock; |
202 | break; | 204 | break; |
203 | } | 205 | } |
204 | } | 206 | } |
205 | 207 | ||
206 | void DocTimer::putLock(TimerIDs timer) | 208 | void DocTimer::putLock(TimerIDs timer) |
207 | { | 209 | { |
208 | switch (timer) { | 210 | switch (timer) { |
209 | case id_mpwTimer: | 211 | case id_mpwTimer: |
210 | if (mpwLock) | 212 | if (mpwLock) |
211 | --mpwLock; | 213 | --mpwLock; |
212 | break; | 214 | break; |
213 | case id_autoLockTimer: | 215 | case id_autoLockTimer: |
214 | if (autoLockLock) | 216 | if (autoLockLock) |
215 | --autoLockLock; | 217 | --autoLockLock; |
216 | break; | 218 | break; |
217 | case id_metaCheckTimer: | 219 | case id_metaCheckTimer: |
218 | if (metaCheckLock) | 220 | if (metaCheckLock) |
219 | --metaCheckLock; | 221 | --metaCheckLock; |
220 | break; | 222 | break; |
221 | } | 223 | } |
222 | } | 224 | } |
223 | 225 | ||
224 | void DocTimer::mpwTimeout() | 226 | void DocTimer::mpwTimeout() |
225 | { | 227 | { |
226 | if (mpwLock) { | 228 | if (mpwLock) { |
227 | mpwTimer->start(1000, true); | 229 | mpwTimer->start(1000, true); |
228 | return; | 230 | return; |
229 | } | 231 | } |
230 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); | 232 | doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); |
231 | } | 233 | } |
232 | 234 | ||
233 | void DocTimer::autoLockTimeout() | 235 | void DocTimer::autoLockTimeout() |
234 | { | 236 | { |
235 | if (autoLockLock) { | 237 | if (autoLockLock) { |
236 | autoLockTimer->start(1000, true); | 238 | autoLockTimer->start(1000, true); |
237 | return; | 239 | return; |
238 | } | 240 | } |
239 | if (conf()->confGlobAutoDeepLock() && | 241 | if (conf()->confGlobAutoDeepLock() && |
240 | doc->filename != QString::null && | 242 | doc->filename != QString::null && |
241 | doc->filename != "") { | 243 | doc->filename != "") { |
242 | doc->deepLock(true); | 244 | doc->deepLock(true); |
243 | } else { | 245 | } else { |
244 | doc->lockAll(true); | 246 | doc->lockAll(true); |
245 | } | 247 | } |
246 | } | 248 | } |
247 | 249 | ||
248 | void DocTimer::metaCheckTimeout() | 250 | void DocTimer::metaCheckTimeout() |
249 | { | 251 | { |
250 | if (metaCheckLock) { | 252 | if (metaCheckLock) { |
251 | // check again in one second. | 253 | // check again in one second. |
252 | metaCheckTimer->start(1000, true); | 254 | metaCheckTimer->start(1000, true); |
253 | return; | 255 | return; |
254 | } | 256 | } |
255 | if (doc->isDeepLocked()) { | 257 | if (doc->isDeepLocked()) { |
256 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 258 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
257 | return; | 259 | return; |
258 | } | 260 | } |
259 | if (doc->isDocEmpty()) { | 261 | if (doc->isDocEmpty()) { |
260 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 262 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
261 | return; | 263 | return; |
262 | } | 264 | } |
263 | #ifdef CONFIG_KWALLETIF | 265 | #ifdef CONFIG_KWALLETIF |
264 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); | 266 | KWalletEmu *kwlEmu = doc->init->kwalletEmu(); |
265 | if (kwlEmu) | 267 | if (kwlEmu) |
266 | kwlEmu->suspendDocSignals(); | 268 | kwlEmu->suspendDocSignals(); |
267 | #endif // CONFIG_KWALLETIF | 269 | #endif // CONFIG_KWALLETIF |
268 | /* We simply trigger all views to update their | 270 | /* We simply trigger all views to update their |
269 | * displayed values. This way they have a chance | 271 | * displayed values. This way they have a chance |
270 | * to get notified when some meta changes over time. | 272 | * to get notified when some meta changes over time. |
271 | * (for example an entry expired). | 273 | * (for example an entry expired). |
272 | * The _view_ is responsive for not updating its | 274 | * The _view_ is responsive for not updating its |
273 | * contents if nothing really changed! | 275 | * contents if nothing really changed! |
274 | */ | 276 | */ |
275 | emit doc->dataChanged(doc); | 277 | emit doc->dataChanged(doc); |
276 | #ifdef CONFIG_KWALLETIF | 278 | #ifdef CONFIG_KWALLETIF |
277 | if (kwlEmu) | 279 | if (kwlEmu) |
278 | kwlEmu->resumeDocSignals(); | 280 | kwlEmu->resumeDocSignals(); |
279 | #endif // CONFIG_KWALLETIF | 281 | #endif // CONFIG_KWALLETIF |
280 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); | 282 | metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true); |
281 | } | 283 | } |
282 | 284 | ||
283 | 285 | ||
284 | 286 | ||
285 | PwMDocList PwMDoc::openDocList; | 287 | PwMDocList PwMDoc::openDocList; |
286 | unsigned int PwMDocList::unnamedDocCnt = 1; | 288 | unsigned int PwMDocList::unnamedDocCnt = 1; |
287 | 289 | ||
288 | PwMDoc::PwMDoc(QObject *parent, const char *name) | 290 | PwMDoc::PwMDoc(QObject *parent, const char *name) |
289 | : PwMDocUi(parent, name) | 291 | : PwMDocUi(parent, name) |
290 | , dataChangedLock (0) | 292 | , dataChangedLock (0) |
291 | { | 293 | { |
292 | deleted = false; | 294 | deleted = false; |
293 | unnamedNum = 0; | 295 | unnamedNum = 0; |
294 | getOpenDocList()->add(this, getTitle().latin1()); | 296 | getOpenDocList()->add(this, getTitle().latin1()); |
295 | curDocStat = 0; | 297 | curDocStat = 0; |
296 | setMaxNumEntries(); | 298 | setMaxNumEntries(); |
297 | _timer = new DocTimer(this); | 299 | _timer = new DocTimer(this); |
298 | timer()->start(DocTimer::id_mpwTimer); | 300 | timer()->start(DocTimer::id_mpwTimer); |
299 | timer()->start(DocTimer::id_autoLockTimer); | 301 | timer()->start(DocTimer::id_autoLockTimer); |
300 | timer()->start(DocTimer::id_metaCheckTimer); | 302 | timer()->start(DocTimer::id_metaCheckTimer); |
301 | addCategory(DEFAULT_CATEGORY, 0, false); | 303 | addCategory(DEFAULT_CATEGORY, 0, false); |
302 | listView = 0; | 304 | listView = 0; |
303 | emit docCreated(this); | 305 | emit docCreated(this); |
304 | } | 306 | } |
305 | 307 | ||
306 | PwMDoc::~PwMDoc() | 308 | PwMDoc::~PwMDoc() |
307 | { | 309 | { |
308 | emit docClosed(this); | 310 | emit docClosed(this); |
309 | getOpenDocList()->del(this); | 311 | getOpenDocList()->del(this); |
310 | delete _timer; | 312 | delete _timer; |
311 | } | 313 | } |
312 | 314 | ||
313 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) | 315 | PwMerror PwMDoc::saveDoc(char compress, const QString *file) |
314 | { | 316 | { |
315 | PwMerror ret, e; | 317 | PwMerror ret, e; |
316 | if (!file) { | 318 | if (!file) { |
317 | if (filename == "") | 319 | if (filename == "") |
318 | return e_filename; | 320 | return e_filename; |
319 | } else { | 321 | } else { |
320 | if (*file == "" && filename == "") | 322 | if (*file == "" && filename == "") |
321 | return e_filename; | 323 | return e_filename; |
322 | if (*file != "") | 324 | if (*file != "") |
323 | filename = *file; | 325 | filename = *file; |
324 | } | 326 | } |
325 | 327 | ||
326 | bool wasDeepLocked = isDeepLocked(); | 328 | bool wasDeepLocked = isDeepLocked(); |
327 | if (wasDeepLocked) { | 329 | if (wasDeepLocked) { |
328 | if (deepLock(false) != e_success) | 330 | if (deepLock(false) != e_success) |
329 | return e_noPw; | 331 | return e_noPw; |
330 | } | 332 | } |
331 | 333 | ||
332 | if (!isPwAvailable()) { | 334 | if (!isPwAvailable()) { |
333 | /* password is not available. This means, the | 335 | /* password is not available. This means, the |
334 | * document wasn't saved, yet. | 336 | * document wasn't saved, yet. |
335 | */ | 337 | */ |
336 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); | 338 | bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD); |
337 | QString pw(requestNewMpw(&useChipcard)); | 339 | QString pw(requestNewMpw(&useChipcard)); |
338 | if (pw != "") { | 340 | if (pw != "") { |
339 | currentPw = pw; | 341 | currentPw = pw; |
340 | } else { | 342 | } else { |
341 | return e_noPw; | 343 | return e_noPw; |
342 | } | 344 | } |
343 | if (useChipcard) { | 345 | if (useChipcard) { |
344 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 346 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
345 | } else { | 347 | } else { |
346 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 348 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
347 | } | 349 | } |
348 | } | 350 | } |
349 | #ifndef PWM_EMBEDDED | 351 | #ifndef PWM_EMBEDDED |
350 | int _cryptAlgo = conf()->confGlobCryptAlgo(); | 352 | int _cryptAlgo = conf()->confGlobCryptAlgo(); |
351 | int _hashAlgo = conf()->confGlobHashAlgo(); | 353 | int _hashAlgo = conf()->confGlobHashAlgo(); |
352 | #else | 354 | #else |
353 | int _cryptAlgo = PWM_CRYPT_BLOWFISH; | 355 | int _cryptAlgo = PWM_CRYPT_BLOWFISH; |
354 | int _hashAlgo = PWM_HASH_SHA1; | 356 | int _hashAlgo = PWM_HASH_SHA1; |
355 | #endif | 357 | #endif |
356 | 358 | ||
357 | // sanity check for the selected algorithms | 359 | // sanity check for the selected algorithms |
358 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || | 360 | if (_cryptAlgo < PWM_CRYPT_BLOWFISH || |
359 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { | 361 | _cryptAlgo > PWM_CRYPT_TWOFISH128) { |
360 | printWarn("Invalid Crypto-Algorithm selected! " | 362 | printWarn("Invalid Crypto-Algorithm selected! " |
361 | "Config-file seems to be corrupt. " | 363 | "Config-file seems to be corrupt. " |
362 | "Falling back to Blowfish."); | 364 | "Falling back to Blowfish."); |
363 | _cryptAlgo = PWM_CRYPT_BLOWFISH; | 365 | _cryptAlgo = PWM_CRYPT_BLOWFISH; |
364 | } | 366 | } |
365 | if (_hashAlgo < PWM_HASH_SHA1 || | 367 | if (_hashAlgo < PWM_HASH_SHA1 || |
366 | _hashAlgo > PWM_HASH_TIGER) { | 368 | _hashAlgo > PWM_HASH_TIGER) { |
367 | printWarn("Invalid Hash-Algorithm selected! " | 369 | printWarn("Invalid Hash-Algorithm selected! " |
368 | "Config-file seems to be corrupt. " | 370 | "Config-file seems to be corrupt. " |
369 | "Falling back to SHA1."); | 371 | "Falling back to SHA1."); |
370 | _hashAlgo = PWM_HASH_SHA1; | 372 | _hashAlgo = PWM_HASH_SHA1; |
371 | } | 373 | } |
372 | char cryptAlgo = static_cast<char>(_cryptAlgo); | 374 | char cryptAlgo = static_cast<char>(_cryptAlgo); |
373 | char hashAlgo = static_cast<char>(_hashAlgo); | 375 | char hashAlgo = static_cast<char>(_hashAlgo); |
374 | 376 | ||
375 | if (conf()->confGlobMakeFileBackup()) { | 377 | if (conf()->confGlobMakeFileBackup()) { |
376 | if (!backupFile(filename)) | 378 | if (!backupFile(filename)) |
377 | return e_fileBackup; | 379 | return e_fileBackup; |
378 | } | 380 | } |
379 | QString tmpFileMoved(QString::null); | 381 | QString tmpFileMoved(QString::null); |
380 | if (QFile::exists(filename)) { | 382 | if (QFile::exists(filename)) { |
381 | /* Move the existing file to some tmp file. | 383 | /* Move the existing file to some tmp file. |
382 | * When saving file succeeds, delete tmp file. Otherwise | 384 | * When saving file succeeds, delete tmp file. Otherwise |
383 | * move tmp file back. See below. | 385 | * move tmp file back. See below. |
384 | */ | 386 | */ |
385 | Randomizer *rnd = Randomizer::obj(); | 387 | Randomizer *rnd = Randomizer::obj(); |
386 | char rnd_buf[5]; | 388 | char rnd_buf[5]; |
387 | 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, |
388 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); | 390 | rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF); |
389 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; | 391 | tmpFileMoved = filename + "." + rnd_buf + ".mv"; |
390 | if (!copyFile(filename, tmpFileMoved)) | 392 | if (!copyFile(filename, tmpFileMoved)) |
391 | return e_openFile; | 393 | return e_openFile; |
392 | if (!QFile::remove(filename)) { | 394 | if (!QFile::remove(filename)) { |
393 | printWarn(string("removing orig file ") | 395 | printWarn(string("removing orig file ") |
394 | + filename.latin1() | 396 | + filename.latin1() |
395 | + " failed!"); | 397 | + " failed!"); |
396 | } | 398 | } |
397 | } | 399 | } |
398 | QFile f(filename); | 400 | QFile f(filename); |
399 | string serialized; | 401 | string serialized; |
400 | if (!f.open(IO_ReadWrite)) { | 402 | if (!f.open(IO_ReadWrite)) { |
401 | ret = e_openFile; | 403 | ret = e_openFile; |
402 | goto out_moveback; | 404 | goto out_moveback; |
403 | } | 405 | } |
404 | e = writeFileHeader(hashAlgo, hashAlgo, | 406 | e = writeFileHeader(hashAlgo, hashAlgo, |
405 | cryptAlgo, compress, | 407 | cryptAlgo, compress, |
406 | ¤tPw, &f); | 408 | ¤tPw, &f); |
407 | if (e == e_hashNotImpl) { | 409 | if (e == e_hashNotImpl) { |
408 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); | 410 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl"); |
409 | f.close(); | 411 | f.close(); |
410 | ret = e_hashNotImpl; | 412 | ret = e_hashNotImpl; |
411 | goto out_moveback; | 413 | goto out_moveback; |
412 | } else if (e != e_success) { | 414 | } else if (e != e_success) { |
413 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); | 415 | printDebug("PwMDoc::saveDoc(): writeFileHeader() failed"); |
414 | f.close(); | 416 | f.close(); |
415 | ret = e_writeHeader; | 417 | ret = e_writeHeader; |
416 | goto out_moveback; | 418 | goto out_moveback; |
417 | } | 419 | } |
418 | if (!serializeDta(&serialized)) { | 420 | if (!serializeDta(&serialized)) { |
419 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); | 421 | printDebug("PwMDoc::saveDoc(): serializeDta() failed"); |
420 | f.close(); | 422 | f.close(); |
421 | ret = e_serializeDta; | 423 | ret = e_serializeDta; |
422 | goto out_moveback; | 424 | goto out_moveback; |
423 | } | 425 | } |
424 | e = writeDataHash(hashAlgo, &serialized, &f); | 426 | e = writeDataHash(hashAlgo, &serialized, &f); |
425 | if (e == e_hashNotImpl) { | 427 | if (e == e_hashNotImpl) { |
426 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); | 428 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl"); |
427 | f.close(); | 429 | f.close(); |
428 | ret = e_hashNotImpl; | 430 | ret = e_hashNotImpl; |
429 | goto out_moveback; | 431 | goto out_moveback; |
430 | } else if (e != e_success) { | 432 | } else if (e != e_success) { |
431 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); | 433 | printDebug("PwMDoc::saveDoc(): writeDataHash() failed"); |
432 | f.close(); | 434 | f.close(); |
433 | ret = e_writeHeader; | 435 | ret = e_writeHeader; |
434 | goto out_moveback; | 436 | goto out_moveback; |
435 | } | 437 | } |
436 | if (!compressDta(&serialized, compress)) { | 438 | if (!compressDta(&serialized, compress)) { |
437 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); | 439 | printDebug("PwMDoc::saveDoc(): compressDta() failed"); |
438 | f.close(); | 440 | f.close(); |
439 | ret = e_enc; | 441 | ret = e_enc; |
440 | goto out_moveback; | 442 | goto out_moveback; |
441 | } | 443 | } |
442 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); | 444 | e = encrypt(&serialized, ¤tPw, &f, cryptAlgo); |
443 | if (e == e_weakPw) { | 445 | if (e == e_weakPw) { |
444 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); | 446 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw"); |
445 | f.close(); | 447 | f.close(); |
446 | ret = e_weakPw; | 448 | ret = e_weakPw; |
447 | goto out_moveback; | 449 | goto out_moveback; |
448 | } else if (e == e_cryptNotImpl) { | 450 | } else if (e == e_cryptNotImpl) { |
449 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); | 451 | printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl"); |
450 | f.close(); | 452 | f.close(); |
451 | ret = e_cryptNotImpl; | 453 | ret = e_cryptNotImpl; |
452 | goto out_moveback; | 454 | goto out_moveback; |
453 | } else if (e != e_success) { | 455 | } else if (e != e_success) { |
454 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); | 456 | printDebug("PwMDoc::saveDoc(): encrypt() failed"); |
455 | f.close(); | 457 | f.close(); |
456 | ret = e_enc; | 458 | ret = e_enc; |
457 | goto out_moveback; | 459 | goto out_moveback; |
458 | } | 460 | } |
459 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); | 461 | unsetDocStatFlag(DOC_STAT_DISK_DIRTY); |
460 | f.close(); | 462 | f.close(); |
461 | if (chmod(filename.latin1(), | 463 | if (chmod(filename.latin1(), |
462 | conf()->confGlobFilePermissions())) { | 464 | conf()->confGlobFilePermissions())) { |
463 | printWarn(string("chmod failed: ") + strerror(errno)); | 465 | printWarn(string("chmod failed: ") + strerror(errno)); |
464 | } | 466 | } |
465 | openDocList.edit(this, getTitle().latin1()); | 467 | openDocList.edit(this, getTitle().latin1()); |
466 | if (wasDeepLocked) | 468 | if (wasDeepLocked) |
467 | deepLock(true); | 469 | deepLock(true); |
468 | if (tmpFileMoved != QString::null) { | 470 | if (tmpFileMoved != QString::null) { |
469 | // now remove the moved file. | 471 | // now remove the moved file. |
470 | if (!QFile::remove(tmpFileMoved)) { | 472 | if (!QFile::remove(tmpFileMoved)) { |
471 | printWarn(string("removing file ") | 473 | printWarn(string("removing file ") |
472 | + tmpFileMoved.latin1() | 474 | + tmpFileMoved.latin1() |
473 | + " failed!"); | 475 | + " failed!"); |
474 | } | 476 | } |
475 | } | 477 | } |
476 | ret = e_success; | 478 | ret = e_success; |
477 | printDebug(string("writing file { compress: ") | 479 | printDebug(string("writing file { compress: ") |
478 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 480 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
479 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 481 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
480 | + tostr(static_cast<int>(hashAlgo)) | 482 | + tostr(static_cast<int>(hashAlgo)) |
481 | + " }"); | 483 | + " }"); |
482 | goto out; | 484 | goto out; |
483 | out_moveback: | 485 | out_moveback: |
484 | if (tmpFileMoved != QString::null) { | 486 | if (tmpFileMoved != QString::null) { |
485 | if (copyFile(tmpFileMoved, filename)) { | 487 | if (copyFile(tmpFileMoved, filename)) { |
486 | if (!QFile::remove(tmpFileMoved)) { | 488 | if (!QFile::remove(tmpFileMoved)) { |
487 | printWarn(string("removing tmp file ") | 489 | printWarn(string("removing tmp file ") |
488 | + filename.latin1() | 490 | + filename.latin1() |
489 | + " failed!"); | 491 | + " failed!"); |
490 | } | 492 | } |
491 | } else { | 493 | } else { |
492 | printWarn(string("couldn't copy file ") | 494 | printWarn(string("couldn't copy file ") |
493 | + tmpFileMoved.latin1() | 495 | + tmpFileMoved.latin1() |
494 | + " back to " | 496 | + " back to " |
495 | + filename.latin1()); | 497 | + filename.latin1()); |
496 | } | 498 | } |
497 | } | 499 | } |
498 | out: | 500 | out: |
499 | return ret; | 501 | return ret; |
500 | } | 502 | } |
501 | 503 | ||
502 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) | 504 | PwMerror PwMDoc::openDoc(const QString *file, int openLocked) |
503 | { | 505 | { |
504 | PWM_ASSERT(file); | 506 | PWM_ASSERT(file); |
505 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); | 507 | PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2); |
506 | string decrypted, dataHash; | 508 | string decrypted, dataHash; |
507 | PwMerror ret; | 509 | PwMerror ret; |
508 | char cryptAlgo, dataHashType, compress; | 510 | char cryptAlgo, dataHashType, compress; |
509 | unsigned int headerLen; | 511 | unsigned int headerLen; |
510 | 512 | ||
511 | if (*file == "") | 513 | if (*file == "") |
512 | return e_readFile; | 514 | return e_readFile; |
513 | filename = *file; | 515 | filename = *file; |
514 | /* check if this file is already open. | 516 | /* check if this file is already open. |
515 | * This does not catch symlinks! | 517 | * This does not catch symlinks! |
516 | */ | 518 | */ |
517 | if (!isDeepLocked()) { | 519 | if (!isDeepLocked()) { |
518 | if (getOpenDocList()->find(filename.latin1())) | 520 | if (getOpenDocList()->find(filename.latin1())) |
519 | return e_alreadyOpen; | 521 | return e_alreadyOpen; |
520 | } | 522 | } |
521 | QFile f(filename); | 523 | QFile f(filename); |
522 | 524 | ||
523 | if (openLocked == 2) { | 525 | if (openLocked == 2) { |
524 | // open deep-locked | 526 | // open deep-locked |
525 | if (!QFile::exists(filename)) | 527 | if (!QFile::exists(filename)) |
526 | return e_openFile; | 528 | return e_openFile; |
527 | if (deepLock(true, false) != e_success) | 529 | if (deepLock(true, false) != e_success) |
528 | return e_openFile; | 530 | return e_openFile; |
529 | goto out_success; | 531 | goto out_success; |
530 | } | 532 | } |
531 | 533 | ||
532 | if (!f.open(IO_ReadOnly)) | 534 | if (!f.open(IO_ReadOnly)) |
533 | return e_openFile; | 535 | return e_openFile; |
534 | 536 | ||
535 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, | 537 | ret = checkHeader(&cryptAlgo, ¤tPw, &compress, &headerLen, |
536 | &dataHashType, &dataHash, &f); | 538 | &dataHashType, &dataHash, &f); |
537 | if (ret != e_success) { | 539 | if (ret != e_success) { |
538 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); | 540 | printDebug("PwMDoc::openDoc(): checkHeader() failed"); |
539 | f.close(); | 541 | f.close(); |
540 | if (ret == e_wrongPw) { | 542 | if (ret == e_wrongPw) { |
541 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 543 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
542 | return ret; | 544 | return ret; |
543 | } else if (ret == e_noPw || | 545 | } else if (ret == e_noPw || |
544 | ret == e_fileVer || | 546 | ret == e_fileVer || |
545 | ret == e_fileFormat || | 547 | ret == e_fileFormat || |
546 | ret == e_hashNotImpl) { | 548 | ret == e_hashNotImpl) { |
547 | return ret; | 549 | return ret; |
548 | } else | 550 | } else |
549 | return e_readFile; | 551 | return e_readFile; |
550 | } | 552 | } |
551 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); | 553 | ret = decrypt(&decrypted, headerLen, ¤tPw, cryptAlgo, &f); |
552 | if (ret == e_cryptNotImpl) { | 554 | if (ret == e_cryptNotImpl) { |
553 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); | 555 | printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl"); |
554 | f.close(); | 556 | f.close(); |
555 | return e_cryptNotImpl; | 557 | return e_cryptNotImpl; |
556 | } else if (ret != e_success) { | 558 | } else if (ret != e_success) { |
557 | printDebug("PwMDoc::openDoc(): decrypt() failed"); | 559 | printDebug("PwMDoc::openDoc(): decrypt() failed"); |
558 | f.close(); | 560 | f.close(); |
559 | return e_readFile; | 561 | return e_readFile; |
560 | } | 562 | } |
561 | if (!decompressDta(&decrypted, compress)) { | 563 | if (!decompressDta(&decrypted, compress)) { |
562 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); | 564 | printDebug("PwMDoc::openDoc(): decompressDta() failed"); |
563 | f.close(); | 565 | f.close(); |
564 | return e_fileCorrupt; | 566 | return e_fileCorrupt; |
565 | } | 567 | } |
566 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); | 568 | ret = checkDataHash(dataHashType, &dataHash, &decrypted); |
567 | if (ret == e_hashNotImpl) { | 569 | if (ret == e_hashNotImpl) { |
568 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); | 570 | printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl"); |
569 | f.close(); | 571 | f.close(); |
570 | return e_hashNotImpl; | 572 | return e_hashNotImpl; |
571 | } else if (ret != e_success) { | 573 | } else if (ret != e_success) { |
572 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); | 574 | printDebug("PwMDoc::openDoc(): checkDataHash() failed"); |
573 | f.close(); | 575 | f.close(); |
574 | return e_fileCorrupt; | 576 | return e_fileCorrupt; |
575 | } | 577 | } |
576 | if (!deSerializeDta(&decrypted, openLocked == 1)) { | 578 | if (!deSerializeDta(&decrypted, openLocked == 1)) { |
577 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); | 579 | printDebug("PwMDoc::openDoc(): deSerializeDta() failed"); |
578 | f.close(); | 580 | f.close(); |
579 | return e_readFile; | 581 | return e_readFile; |
580 | } | 582 | } |
581 | f.close(); | 583 | f.close(); |
582 | timer()->start(DocTimer::id_mpwTimer); | 584 | timer()->start(DocTimer::id_mpwTimer); |
583 | timer()->start(DocTimer::id_autoLockTimer); | 585 | timer()->start(DocTimer::id_autoLockTimer); |
584 | out_success: | 586 | out_success: |
585 | openDocList.edit(this, getTitle().latin1()); | 587 | openDocList.edit(this, getTitle().latin1()); |
586 | emit docOpened(this); | 588 | emit docOpened(this); |
587 | return e_success; | 589 | return e_success; |
588 | } | 590 | } |
589 | 591 | ||
590 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 592 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
591 | QString *pw, QFile *f) | 593 | QString *pw, QFile *f) |
592 | { | 594 | { |
593 | PWM_ASSERT(pw); | 595 | PWM_ASSERT(pw); |
594 | PWM_ASSERT(f); | 596 | PWM_ASSERT(f); |
595 | PWM_ASSERT(listView); | 597 | PWM_ASSERT(listView); |
596 | #ifndef PWM_EMBEDDED | 598 | #ifndef PWM_EMBEDDED |
597 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 599 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
598 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 600 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
599 | return e_writeFile; | 601 | return e_writeFile; |
600 | } | 602 | } |
601 | if (f->putch(PWM_FILE_VER) == -1 || | 603 | if (f->putch(PWM_FILE_VER) == -1 || |
602 | f->putch(keyHash) == -1 || | 604 | f->putch(keyHash) == -1 || |
603 | f->putch(dataHash) == -1 || | 605 | f->putch(dataHash) == -1 || |
604 | f->putch(crypt) == -1 || | 606 | f->putch(crypt) == -1 || |
605 | f->putch(compress) == -1 || | 607 | f->putch(compress) == -1 || |
606 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 608 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
607 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { | 609 | (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) { |
608 | return e_writeFile; | 610 | return e_writeFile; |
609 | } | 611 | } |
610 | 612 | ||
611 | #else | 613 | #else |
612 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 614 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
613 | (long)(strlen(FILE_ID_HEADER))) { | 615 | (long)(strlen(FILE_ID_HEADER))) { |
614 | return e_writeFile; | 616 | return e_writeFile; |
615 | } | 617 | } |
616 | if (f->putch(PWM_FILE_VER) == -1 || | 618 | if (f->putch(PWM_FILE_VER) == -1 || |
617 | f->putch(keyHash) == -1 || | 619 | f->putch(keyHash) == -1 || |
618 | f->putch(dataHash) == -1 || | 620 | f->putch(dataHash) == -1 || |
619 | f->putch(crypt) == -1 || | 621 | f->putch(crypt) == -1 || |
620 | f->putch(compress) == -1 || | 622 | f->putch(compress) == -1 || |
621 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? | 623 | f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ? |
622 | ((char)(0x01)) : ((char)(0x00))) == -1) { | 624 | ((char)(0x01)) : ((char)(0x00))) == -1) { |
623 | return e_writeFile; | 625 | return e_writeFile; |
624 | } | 626 | } |
625 | #endif | 627 | #endif |
626 | // 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. |
627 | const int bufSize = 64; | 629 | const int bufSize = 64; |
628 | char tmp_buf[bufSize]; | 630 | char tmp_buf[bufSize]; |
629 | memset(tmp_buf, 0x00, bufSize); | 631 | memset(tmp_buf, 0x00, bufSize); |
630 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) | 632 | if (f->writeBlock(tmp_buf, bufSize) != bufSize) |
631 | return e_writeFile; | 633 | return e_writeFile; |
632 | 634 | ||
633 | switch (keyHash) { | 635 | switch (keyHash) { |
634 | case PWM_HASH_SHA1: { | 636 | case PWM_HASH_SHA1: { |
635 | const int hashlen = SHA1_HASH_LEN_BYTE; | 637 | const int hashlen = SHA1_HASH_LEN_BYTE; |
636 | Sha1 hash; | 638 | Sha1 hash; |
637 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 639 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
638 | string ret = hash.sha1_read(); | 640 | string ret = hash.sha1_read(); |
639 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) | 641 | if (f->writeBlock(ret.c_str(), hashlen) != hashlen) |
640 | return e_writeFile; | 642 | return e_writeFile; |
641 | break; | 643 | break; |
642 | } | 644 | } |
643 | #ifndef PWM_EMBEDDED | 645 | #ifndef PWM_EMBEDDED |
644 | case PWM_HASH_SHA256: | 646 | case PWM_HASH_SHA256: |
645 | /*... fall through */ | 647 | /*... fall through */ |
646 | case PWM_HASH_SHA384: | 648 | case PWM_HASH_SHA384: |
647 | case PWM_HASH_SHA512: | 649 | case PWM_HASH_SHA512: |
648 | case PWM_HASH_MD5: | 650 | case PWM_HASH_MD5: |
649 | case PWM_HASH_RMD160: | 651 | case PWM_HASH_RMD160: |
650 | case PWM_HASH_TIGER: | 652 | case PWM_HASH_TIGER: |
651 | { | 653 | { |
652 | if (!LibGCryptIf::available()) | 654 | if (!LibGCryptIf::available()) |
653 | return e_hashNotImpl; | 655 | return e_hashNotImpl; |
654 | LibGCryptIf gc; | 656 | LibGCryptIf gc; |
655 | PwMerror err; | 657 | PwMerror err; |
656 | unsigned char *buf; | 658 | unsigned char *buf; |
657 | size_t hashLen; | 659 | size_t hashLen; |
658 | err = gc.hash(&buf, | 660 | err = gc.hash(&buf, |
659 | &hashLen, | 661 | &hashLen, |
660 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 662 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
661 | pw->length(), | 663 | pw->length(), |
662 | keyHash); | 664 | keyHash); |
663 | if (err != e_success) | 665 | if (err != e_success) |
664 | return e_hashNotImpl; | 666 | return e_hashNotImpl; |
665 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 667 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
666 | != static_cast<Q_LONG>(hashLen)) { | 668 | != static_cast<Q_LONG>(hashLen)) { |
667 | delete [] buf; | 669 | delete [] buf; |
668 | return e_hashNotImpl; | 670 | return e_hashNotImpl; |
669 | } | 671 | } |
670 | delete [] buf; | 672 | delete [] buf; |
671 | break; | 673 | break; |
672 | } | 674 | } |
673 | #endif | 675 | #endif |
674 | default: { | 676 | default: { |
675 | return e_hashNotImpl; | 677 | return e_hashNotImpl; |
676 | } } | 678 | } } |
677 | return e_success; | 679 | return e_success; |
678 | } | 680 | } |
679 | 681 | ||
680 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, | 682 | PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress, |
681 | unsigned int *headerLength, char *dataHashType, | 683 | unsigned int *headerLength, char *dataHashType, |
682 | string *dataHash, QFile *f) | 684 | string *dataHash, QFile *f) |
683 | { | 685 | { |
684 | PWM_ASSERT(cryptAlgo); | 686 | PWM_ASSERT(cryptAlgo); |
685 | PWM_ASSERT(pw); | 687 | PWM_ASSERT(pw); |
686 | PWM_ASSERT(headerLength); | 688 | PWM_ASSERT(headerLength); |
687 | PWM_ASSERT(dataHashType); | 689 | PWM_ASSERT(dataHashType); |
688 | PWM_ASSERT(dataHash); | 690 | PWM_ASSERT(dataHash); |
689 | PWM_ASSERT(f); | 691 | PWM_ASSERT(f); |
690 | int tmpRet; | 692 | int tmpRet; |
691 | // check "magic" header | 693 | // check "magic" header |
692 | const char magicHdr[] = FILE_ID_HEADER; | 694 | const char magicHdr[] = FILE_ID_HEADER; |
693 | const int hdrLen = array_size(magicHdr) - 1; | 695 | const int hdrLen = array_size(magicHdr) - 1; |
694 | char tmp[hdrLen]; | 696 | char tmp[hdrLen]; |
695 | if (f->readBlock(tmp, hdrLen) != hdrLen) | 697 | if (f->readBlock(tmp, hdrLen) != hdrLen) |
696 | return e_readFile; | 698 | return e_readFile; |
697 | if (memcmp(tmp, magicHdr, hdrLen) != 0) | 699 | if (memcmp(tmp, magicHdr, hdrLen) != 0) |
698 | return e_fileFormat; | 700 | return e_fileFormat; |
699 | // read and check file ver | 701 | // read and check file ver |
700 | int fileV = f->getch(); | 702 | int fileV = f->getch(); |
701 | if (fileV == -1) | 703 | if (fileV == -1) |
702 | return e_fileFormat; | 704 | return e_fileFormat; |
703 | if (fileV != PWM_FILE_VER) | 705 | if (fileV != PWM_FILE_VER) |
704 | return e_fileVer; | 706 | return e_fileVer; |
705 | // read hash hash type | 707 | // read hash hash type |
706 | int keyHash = f->getch(); | 708 | int keyHash = f->getch(); |
707 | if (keyHash == -1) | 709 | if (keyHash == -1) |
708 | return e_fileFormat; | 710 | return e_fileFormat; |
709 | // read data hash type | 711 | // read data hash type |
710 | tmpRet = f->getch(); | 712 | tmpRet = f->getch(); |
711 | if (tmpRet == -1) | 713 | if (tmpRet == -1) |
712 | return e_fileFormat; | 714 | return e_fileFormat; |
713 | *dataHashType = tmpRet; | 715 | *dataHashType = tmpRet; |
714 | // read crypt algo | 716 | // read crypt algo |
715 | tmpRet = f->getch(); | 717 | tmpRet = f->getch(); |
716 | if (tmpRet == -1) | 718 | if (tmpRet == -1) |
717 | return e_fileFormat; | 719 | return e_fileFormat; |
718 | *cryptAlgo = tmpRet; | 720 | *cryptAlgo = tmpRet; |
719 | // get compression-algo | 721 | // get compression-algo |
720 | tmpRet = f->getch(); | 722 | tmpRet = f->getch(); |
721 | if (tmpRet == -1) | 723 | if (tmpRet == -1) |
722 | return e_fileFormat; | 724 | return e_fileFormat; |
723 | *compress = tmpRet; | 725 | *compress = tmpRet; |
724 | // get the MPW-flag | 726 | // get the MPW-flag |
725 | int mpw_flag = f->getch(); | 727 | int mpw_flag = f->getch(); |
726 | if (mpw_flag == -1) | 728 | if (mpw_flag == -1) |
727 | return e_fileFormat; | 729 | return e_fileFormat; |
728 | if (mpw_flag == 0x01) | 730 | if (mpw_flag == 0x01) |
729 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); | 731 | setDocStatFlag(DOC_STAT_USE_CHIPCARD); |
730 | else | 732 | else |
731 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); | 733 | unsetDocStatFlag(DOC_STAT_USE_CHIPCARD); |
732 | // skip the "RESERVED"-bytes | 734 | // skip the "RESERVED"-bytes |
733 | if (!(f->at(f->at() + 64))) | 735 | if (!(f->at(f->at() + 64))) |
734 | return e_fileFormat; | 736 | return e_fileFormat; |
735 | 737 | ||
736 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 738 | *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
737 | if (*pw == "") { | 739 | if (*pw == "") { |
738 | /* the user didn't give a master-password | 740 | /* the user didn't give a master-password |
739 | * or didn't insert a chipcard | 741 | * or didn't insert a chipcard |
740 | */ | 742 | */ |
741 | return e_noPw; | 743 | return e_noPw; |
742 | } | 744 | } |
743 | // verify key-hash | 745 | // verify key-hash |
744 | switch (keyHash) { | 746 | switch (keyHash) { |
745 | case PWM_HASH_SHA1: { | 747 | case PWM_HASH_SHA1: { |
746 | // read hash from header | 748 | // read hash from header |
747 | const int hashLen = SHA1_HASH_LEN_BYTE; | 749 | const int hashLen = SHA1_HASH_LEN_BYTE; |
748 | string readHash; | 750 | string readHash; |
749 | int i; | 751 | int i; |
750 | for (i = 0; i < hashLen; ++i) | 752 | for (i = 0; i < hashLen; ++i) |
751 | readHash.push_back(f->getch()); | 753 | readHash.push_back(f->getch()); |
752 | Sha1 hash; | 754 | Sha1 hash; |
753 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); | 755 | hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length()); |
754 | string ret = hash.sha1_read(); | 756 | string ret = hash.sha1_read(); |
755 | if (ret != readHash) | 757 | if (ret != readHash) |
756 | return e_wrongPw;// hash doesn't match (wrong key) | 758 | return e_wrongPw;// hash doesn't match (wrong key) |
757 | break; | 759 | break; |
758 | } | 760 | } |
759 | #ifndef PWM_EMBEDDED | 761 | #ifndef PWM_EMBEDDED |
760 | case PWM_HASH_SHA256: | 762 | case PWM_HASH_SHA256: |
761 | /*... fall through */ | 763 | /*... fall through */ |
762 | case PWM_HASH_SHA384: | 764 | case PWM_HASH_SHA384: |
763 | case PWM_HASH_SHA512: | 765 | case PWM_HASH_SHA512: |
764 | case PWM_HASH_MD5: | 766 | case PWM_HASH_MD5: |
765 | case PWM_HASH_RMD160: | 767 | case PWM_HASH_RMD160: |
766 | case PWM_HASH_TIGER: { | 768 | case PWM_HASH_TIGER: { |
767 | if (!LibGCryptIf::available()) | 769 | if (!LibGCryptIf::available()) |
768 | return e_hashNotImpl; | 770 | return e_hashNotImpl; |
769 | LibGCryptIf gc; | 771 | LibGCryptIf gc; |
770 | PwMerror err; | 772 | PwMerror err; |
771 | unsigned char *buf; | 773 | unsigned char *buf; |
772 | size_t hashLen; | 774 | size_t hashLen; |
773 | err = gc.hash(&buf, | 775 | err = gc.hash(&buf, |
774 | &hashLen, | 776 | &hashLen, |
775 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 777 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
776 | pw->length(), | 778 | pw->length(), |
777 | keyHash); | 779 | keyHash); |
778 | if (err != e_success) | 780 | if (err != e_success) |
779 | return e_hashNotImpl; | 781 | return e_hashNotImpl; |
780 | string calcHash(reinterpret_cast<const char *>(buf), | 782 | string calcHash(reinterpret_cast<const char *>(buf), |
781 | static_cast<string::size_type>(hashLen)); | 783 | static_cast<string::size_type>(hashLen)); |
782 | delete [] buf; | 784 | delete [] buf; |
783 | // read hash from header | 785 | // read hash from header |
784 | string readHash; | 786 | string readHash; |
785 | size_t i; | 787 | size_t i; |
786 | for (i = 0; i < hashLen; ++i) | 788 | for (i = 0; i < hashLen; ++i) |
787 | readHash.push_back(f->getch()); | 789 | readHash.push_back(f->getch()); |
788 | if (calcHash != readHash) | 790 | if (calcHash != readHash) |
789 | return e_wrongPw;// hash doesn't match (wrong key) | 791 | return e_wrongPw;// hash doesn't match (wrong key) |
790 | break; | 792 | break; |
791 | } | 793 | } |
792 | #endif | 794 | #endif |
793 | default: { | 795 | default: { |
794 | return e_hashNotImpl; | 796 | return e_hashNotImpl; |
795 | } } | 797 | } } |
796 | // read the data-hash from the file | 798 | // read the data-hash from the file |
797 | unsigned int hashLen, i; | 799 | unsigned int hashLen, i; |
798 | switch (*dataHashType) { | 800 | switch (*dataHashType) { |
799 | case PWM_HASH_SHA1: | 801 | case PWM_HASH_SHA1: |
800 | hashLen = SHA1_HASH_LEN_BYTE; | 802 | hashLen = SHA1_HASH_LEN_BYTE; |
801 | break; | 803 | break; |
802 | #ifndef PWM_EMBEDDED | 804 | #ifndef PWM_EMBEDDED |
803 | case PWM_HASH_SHA256: | 805 | case PWM_HASH_SHA256: |
804 | /*... fall through */ | 806 | /*... fall through */ |
805 | case PWM_HASH_SHA384: | 807 | case PWM_HASH_SHA384: |
806 | case PWM_HASH_SHA512: | 808 | case PWM_HASH_SHA512: |
807 | case PWM_HASH_MD5: | 809 | case PWM_HASH_MD5: |
808 | case PWM_HASH_RMD160: | 810 | case PWM_HASH_RMD160: |
809 | case PWM_HASH_TIGER: { | 811 | case PWM_HASH_TIGER: { |
810 | if (!LibGCryptIf::available()) | 812 | if (!LibGCryptIf::available()) |
811 | return e_hashNotImpl; | 813 | return e_hashNotImpl; |
812 | LibGCryptIf gc; | 814 | LibGCryptIf gc; |
813 | hashLen = gc.hashLength(*dataHashType); | 815 | hashLen = gc.hashLength(*dataHashType); |
814 | if (hashLen == 0) | 816 | if (hashLen == 0) |
815 | return e_hashNotImpl; | 817 | return e_hashNotImpl; |
816 | break; | 818 | break; |
817 | } | 819 | } |
818 | #endif | 820 | #endif |
819 | default: | 821 | default: |
820 | return e_hashNotImpl; | 822 | return e_hashNotImpl; |
821 | } | 823 | } |
822 | *dataHash = ""; | 824 | *dataHash = ""; |
823 | for (i = 0; i < hashLen; ++i) { | 825 | for (i = 0; i < hashLen; ++i) { |
824 | tmpRet = f->getch(); | 826 | tmpRet = f->getch(); |
825 | if (tmpRet == -1) | 827 | if (tmpRet == -1) |
826 | return e_fileFormat; | 828 | return e_fileFormat; |
827 | dataHash->push_back(static_cast<char>(tmpRet)); | 829 | dataHash->push_back(static_cast<char>(tmpRet)); |
828 | } | 830 | } |
829 | *headerLength = f->at(); | 831 | *headerLength = f->at(); |
830 | #ifndef PWM_EMBEDDED | 832 | #ifndef PWM_EMBEDDED |
831 | printDebug(string("opening file { compress: ") | 833 | printDebug(string("opening file { compress: ") |
832 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " | 834 | + tostr(static_cast<int>(*compress)) + " cryptAlgo: " |
833 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " | 835 | + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: " |
834 | + tostr(static_cast<int>(keyHash)) | 836 | + tostr(static_cast<int>(keyHash)) |
835 | + " }"); | 837 | + " }"); |
836 | #else | 838 | #else |
837 | printDebug(string("opening file { compress: ") | 839 | printDebug(string("opening file { compress: ") |
838 | + tostr((int)(*compress)) + " cryptAlgo: " | 840 | + tostr((int)(*compress)) + " cryptAlgo: " |
839 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " | 841 | + tostr((int)(*cryptAlgo)) + " keyHashAlgo: " |
840 | + tostr((int)(keyHash)) | 842 | + tostr((int)(keyHash)) |
841 | + " }"); | 843 | + " }"); |
842 | #endif | 844 | #endif |
843 | 845 | ||
844 | return e_success; | 846 | return e_success; |
845 | } | 847 | } |
846 | 848 | ||
847 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) | 849 | PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f) |
848 | { | 850 | { |
849 | PWM_ASSERT(d); | 851 | PWM_ASSERT(d); |
850 | PWM_ASSERT(f); | 852 | PWM_ASSERT(f); |
851 | 853 | ||
852 | switch (dataHash) { | 854 | switch (dataHash) { |
853 | case PWM_HASH_SHA1: { | 855 | case PWM_HASH_SHA1: { |
854 | const int hashLen = SHA1_HASH_LEN_BYTE; | 856 | const int hashLen = SHA1_HASH_LEN_BYTE; |
855 | Sha1 h; | 857 | Sha1 h; |
856 | 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()); |
857 | string hRet = h.sha1_read(); | 859 | string hRet = h.sha1_read(); |
858 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) | 860 | if (f->writeBlock(hRet.c_str(), hashLen) != hashLen) |
859 | return e_writeFile; | 861 | return e_writeFile; |
860 | break; | 862 | break; |
861 | } | 863 | } |
862 | #ifndef PWM_EMBEDDED | 864 | #ifndef PWM_EMBEDDED |
863 | case PWM_HASH_SHA256: | 865 | case PWM_HASH_SHA256: |
864 | /*... fall through */ | 866 | /*... fall through */ |
865 | case PWM_HASH_SHA384: | 867 | case PWM_HASH_SHA384: |
866 | case PWM_HASH_SHA512: | 868 | case PWM_HASH_SHA512: |
867 | case PWM_HASH_MD5: | 869 | case PWM_HASH_MD5: |
868 | case PWM_HASH_RMD160: | 870 | case PWM_HASH_RMD160: |
869 | case PWM_HASH_TIGER: { | 871 | case PWM_HASH_TIGER: { |
870 | if (!LibGCryptIf::available()) | 872 | if (!LibGCryptIf::available()) |
871 | return e_hashNotImpl; | 873 | return e_hashNotImpl; |
872 | LibGCryptIf gc; | 874 | LibGCryptIf gc; |
873 | PwMerror err; | 875 | PwMerror err; |
874 | unsigned char *buf; | 876 | unsigned char *buf; |
875 | size_t hashLen; | 877 | size_t hashLen; |
876 | err = gc.hash(&buf, | 878 | err = gc.hash(&buf, |
877 | &hashLen, | 879 | &hashLen, |
878 | reinterpret_cast<const unsigned char *>(d->c_str()), | 880 | reinterpret_cast<const unsigned char *>(d->c_str()), |
879 | d->size(), | 881 | d->size(), |
880 | dataHash); | 882 | dataHash); |
881 | if (err != e_success) | 883 | if (err != e_success) |
882 | return e_hashNotImpl; | 884 | return e_hashNotImpl; |
883 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) | 885 | if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen) |
884 | != static_cast<Q_LONG>(hashLen)) { | 886 | != static_cast<Q_LONG>(hashLen)) { |
885 | delete [] buf; | 887 | delete [] buf; |
886 | return e_hashNotImpl; | 888 | return e_hashNotImpl; |
887 | } | 889 | } |
888 | delete [] buf; | 890 | delete [] buf; |
889 | break; | 891 | break; |
890 | } | 892 | } |
891 | #endif | 893 | #endif |
892 | default: { | 894 | default: { |
893 | return e_hashNotImpl; | 895 | return e_hashNotImpl; |
894 | } } | 896 | } } |
895 | 897 | ||
896 | return e_success; | 898 | return e_success; |
897 | } | 899 | } |
898 | 900 | ||
899 | bool PwMDoc::backupFile(const QString &filePath) | 901 | bool PwMDoc::backupFile(const QString &filePath) |
900 | { | 902 | { |
901 | QFileInfo fi(filePath); | 903 | QFileInfo fi(filePath); |
902 | if (!fi.exists()) | 904 | if (!fi.exists()) |
903 | return true; // Yes, true is correct. | 905 | return true; // Yes, true is correct. |
904 | QString pathOnly(fi.dirPath(true)); | 906 | QString pathOnly(fi.dirPath(true)); |
905 | QString nameOnly(fi.fileName()); | 907 | QString nameOnly(fi.fileName()); |
906 | QString backupPath = pathOnly | 908 | QString backupPath = pathOnly |
907 | + "/~" | 909 | + "/~" |
908 | + nameOnly | 910 | + nameOnly |
909 | + ".backup"; | 911 | + ".backup"; |
910 | return copyFile(filePath, backupPath); | 912 | return copyFile(filePath, backupPath); |
911 | } | 913 | } |
912 | 914 | ||
913 | bool PwMDoc::copyFile(const QString &src, const QString &dst) | 915 | bool PwMDoc::copyFile(const QString &src, const QString &dst) |
914 | { | 916 | { |
915 | QFileInfo fi(src); | 917 | QFileInfo fi(src); |
916 | if (!fi.exists()) | 918 | if (!fi.exists()) |
917 | return false; | 919 | return false; |
918 | if (QFile::exists(dst)) { | 920 | if (QFile::exists(dst)) { |
919 | if (!QFile::remove(dst)) | 921 | if (!QFile::remove(dst)) |
920 | return false; | 922 | return false; |
921 | } | 923 | } |
922 | QFile srcFd(src); | 924 | QFile srcFd(src); |
923 | if (!srcFd.open(IO_ReadOnly)) | 925 | if (!srcFd.open(IO_ReadOnly)) |
924 | return false; | 926 | return false; |
925 | QFile dstFd(dst); | 927 | QFile dstFd(dst); |
926 | if (!dstFd.open(IO_ReadWrite)) { | 928 | if (!dstFd.open(IO_ReadWrite)) { |
927 | srcFd.close(); | 929 | srcFd.close(); |
928 | return false; | 930 | return false; |
929 | } | 931 | } |
930 | const int tmpBuf_size = 512; | 932 | const int tmpBuf_size = 512; |
931 | char tmpBuf[tmpBuf_size]; | 933 | char tmpBuf[tmpBuf_size]; |
932 | #ifndef PWM_EMBEDDED | 934 | #ifndef PWM_EMBEDDED |
933 | Q_LONG bytesRead, bytesWritten; | 935 | Q_LONG bytesRead, bytesWritten; |
934 | #else | 936 | #else |
935 | long bytesRead, bytesWritten; | 937 | long bytesRead, bytesWritten; |
936 | #endif | 938 | #endif |
937 | while (!srcFd.atEnd()) { | 939 | while (!srcFd.atEnd()) { |
938 | #ifndef PWM_EMBEDDED | 940 | #ifndef PWM_EMBEDDED |
939 | bytesRead = srcFd.readBlock(tmpBuf, | 941 | bytesRead = srcFd.readBlock(tmpBuf, |
940 | static_cast<Q_ULONG>(tmpBuf_size)); | 942 | static_cast<Q_ULONG>(tmpBuf_size)); |
941 | #else | 943 | #else |
942 | bytesRead = srcFd.readBlock(tmpBuf, | 944 | bytesRead = srcFd.readBlock(tmpBuf, |
943 | (unsigned long)(tmpBuf_size)); | 945 | (unsigned long)(tmpBuf_size)); |
944 | #endif | 946 | #endif |
945 | if (bytesRead == -1) { | 947 | if (bytesRead == -1) { |
946 | srcFd.close(); | 948 | srcFd.close(); |
947 | dstFd.close(); | 949 | dstFd.close(); |
948 | return false; | 950 | return false; |
949 | } | 951 | } |
950 | #ifndef PWM_EMBEDDED | 952 | #ifndef PWM_EMBEDDED |
951 | bytesWritten = dstFd.writeBlock(tmpBuf, | 953 | bytesWritten = dstFd.writeBlock(tmpBuf, |
952 | static_cast<Q_ULONG>(bytesRead)); | 954 | static_cast<Q_ULONG>(bytesRead)); |
953 | #else | 955 | #else |
954 | bytesWritten = dstFd.writeBlock(tmpBuf, | 956 | bytesWritten = dstFd.writeBlock(tmpBuf, |
955 | (unsigned long)(bytesRead)); | 957 | (unsigned long)(bytesRead)); |
956 | #endif | 958 | #endif |
957 | if (bytesWritten != bytesRead) { | 959 | if (bytesWritten != bytesRead) { |
958 | srcFd.close(); | 960 | srcFd.close(); |
959 | dstFd.close(); | 961 | dstFd.close(); |
960 | return false; | 962 | return false; |
961 | } | 963 | } |
962 | } | 964 | } |
963 | srcFd.close(); | 965 | srcFd.close(); |
964 | dstFd.close(); | 966 | dstFd.close(); |
965 | return true; | 967 | return true; |
966 | } | 968 | } |
967 | 969 | ||
968 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, | 970 | PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d, |
969 | bool dontFlagDirty, bool updateMeta) | 971 | bool dontFlagDirty, bool updateMeta) |
970 | { | 972 | { |
971 | PWM_ASSERT(d); | 973 | PWM_ASSERT(d); |
972 | unsigned int cat = 0; | 974 | unsigned int cat = 0; |
973 | 975 | ||
974 | if (isDeepLocked()) { | 976 | if (isDeepLocked()) { |
975 | PwMerror ret; | 977 | PwMerror ret; |
976 | ret = deepLock(false); | 978 | ret = deepLock(false); |
977 | if (ret != e_success) | 979 | if (ret != e_success) |
978 | return e_lock; | 980 | return e_lock; |
979 | } | 981 | } |
980 | 982 | ||
981 | addCategory(category, &cat); | 983 | addCategory(category, &cat); |
982 | 984 | ||
983 | if (numEntries(category) >= maxEntries) | 985 | if (numEntries(category) >= maxEntries) |
984 | return e_maxAllowedEntr; | 986 | return e_maxAllowedEntr; |
985 | 987 | ||
986 | vector<unsigned int> foundPositions; | 988 | vector<unsigned int> foundPositions; |
987 | /* historically this was: | 989 | /* historically this was: |
988 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 990 | *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
989 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 991 | * SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
990 | * But for now we only search in desc. | 992 | * But for now we only search in desc. |
991 | * 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 |
992 | * usability-drop onto PwManager, does it? | 994 | * usability-drop onto PwManager, does it? |
993 | * (And yes, "int" was a bug. Correct is "unsigned int") | 995 | * (And yes, "int" was a bug. Correct is "unsigned int") |
994 | */ | 996 | */ |
995 | const unsigned int searchIn = SEARCH_IN_DESC; | 997 | const unsigned int searchIn = SEARCH_IN_DESC; |
996 | findEntry(cat, *d, searchIn, &foundPositions, true); | 998 | findEntry(cat, *d, searchIn, &foundPositions, true); |
997 | if (foundPositions.size()) { | 999 | if (foundPositions.size()) { |
998 | // DOH! We found this entry. | 1000 | // DOH! We found this entry. |
999 | return e_entryExists; | 1001 | return e_entryExists; |
1000 | } | 1002 | } |
1001 | 1003 | ||
1002 | d->listViewPos = -1; | 1004 | d->listViewPos = -1; |
1003 | d->lockStat = conf()->confGlobNewEntrLockStat(); | 1005 | d->lockStat = conf()->confGlobNewEntrLockStat(); |
1004 | if (updateMeta) { | 1006 | if (updateMeta) { |
1005 | d->meta.create = QDateTime::currentDateTime(); | 1007 | d->meta.create = QDateTime::currentDateTime(); |
1006 | d->meta.update = d->meta.create; | 1008 | d->meta.update = d->meta.create; |
1007 | } | 1009 | } |
1008 | dta[cat].d.push_back(*d); | 1010 | dta[cat].d.push_back(*d); |
1009 | 1011 | ||
1010 | delAllEmptyCat(true); | 1012 | delAllEmptyCat(true); |
1011 | 1013 | ||
1012 | if (!dontFlagDirty) | 1014 | if (!dontFlagDirty) |
1013 | flagDirty(); | 1015 | flagDirty(); |
1014 | return e_success; | 1016 | return e_success; |
1015 | } | 1017 | } |
1016 | 1018 | ||
1017 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, | 1019 | PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex, |
1018 | bool checkIfExist) | 1020 | bool checkIfExist) |
1019 | { | 1021 | { |
1020 | if (isDeepLocked()) { | 1022 | if (isDeepLocked()) { |
1021 | PwMerror ret; | 1023 | PwMerror ret; |
1022 | ret = deepLock(false); | 1024 | ret = deepLock(false); |
1023 | if (ret != e_success) | 1025 | if (ret != e_success) |
1024 | return e_lock; | 1026 | return e_lock; |
1025 | } | 1027 | } |
1026 | if (checkIfExist) { | 1028 | if (checkIfExist) { |
1027 | if (findCategory(category, categoryIndex)) | 1029 | if (findCategory(category, categoryIndex)) |
1028 | return e_categoryExists; | 1030 | return e_categoryExists; |
1029 | } | 1031 | } |
1030 | PwMCategoryItem item; | 1032 | PwMCategoryItem item; |
1031 | item.name = category.latin1(); | 1033 | item.name = category.latin1(); |
1032 | dta.push_back(item); | 1034 | dta.push_back(item); |
1033 | if (categoryIndex) | 1035 | if (categoryIndex) |
1034 | *categoryIndex = dta.size() - 1; | 1036 | *categoryIndex = dta.size() - 1; |
1035 | return e_success; | 1037 | return e_success; |
1036 | } | 1038 | } |
1037 | 1039 | ||
1038 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) | 1040 | bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty) |
1039 | { | 1041 | { |
1040 | unsigned int cat = 0; | 1042 | unsigned int cat = 0; |
1041 | 1043 | ||
1042 | if (!findCategory(category, &cat)) { | 1044 | if (!findCategory(category, &cat)) { |
1043 | BUG(); | 1045 | BUG(); |
1044 | return false; | 1046 | return false; |
1045 | } | 1047 | } |
1046 | 1048 | ||
1047 | return delEntry(cat, index, dontFlagDirty); | 1049 | return delEntry(cat, index, dontFlagDirty); |
1048 | } | 1050 | } |
1049 | 1051 | ||
1050 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) | 1052 | bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty) |
1051 | { | 1053 | { |
1052 | if (isDeepLocked()) | 1054 | if (isDeepLocked()) |
1053 | return false; | 1055 | return false; |
1054 | if (index > dta[category].d.size() - 1) | 1056 | if (index > dta[category].d.size() - 1) |
1055 | return false; | 1057 | return false; |
1056 | getDataChangedLock(); | 1058 | getDataChangedLock(); |
1057 | if (!lockAt(category, index, false)) { | 1059 | if (!lockAt(category, index, false)) { |
1058 | putDataChangedLock(); | 1060 | putDataChangedLock(); |
1059 | return false; | 1061 | return false; |
1060 | } | 1062 | } |
1061 | putDataChangedLock(); | 1063 | putDataChangedLock(); |
1062 | int lvPos = dta[category].d[index].listViewPos; | 1064 | int lvPos = dta[category].d[index].listViewPos; |
1063 | 1065 | ||
1064 | // delete entry | 1066 | // delete entry |
1065 | dta[category].d.erase(dta[category].d.begin() + index); | 1067 | dta[category].d.erase(dta[category].d.begin() + index); |
1066 | 1068 | ||
1067 | unsigned int i, entries = numEntries(category); | 1069 | unsigned int i, entries = numEntries(category); |
1068 | if (!entries) { | 1070 | if (!entries) { |
1069 | // no more entries in this category, so | 1071 | // no more entries in this category, so |
1070 | // we can delete it, too. | 1072 | // we can delete it, too. |
1071 | BUG_ON(!delCategory(category)); | 1073 | BUG_ON(!delCategory(category)); |
1072 | // delCategory() flags it dirty, so we need not to do so. | 1074 | // delCategory() flags it dirty, so we need not to do so. |
1073 | return true; | 1075 | return true; |
1074 | } | 1076 | } |
1075 | for (i = 0; i < entries; ++i) { | 1077 | for (i = 0; i < entries; ++i) { |
1076 | // decrement all listViewPositions that are greater than the deleted. | 1078 | // decrement all listViewPositions that are greater than the deleted. |
1077 | if (dta[category].d[i].listViewPos > lvPos) | 1079 | if (dta[category].d[i].listViewPos > lvPos) |
1078 | --dta[category].d[i].listViewPos; | 1080 | --dta[category].d[i].listViewPos; |
1079 | } | 1081 | } |
1080 | 1082 | ||
1081 | if (!dontFlagDirty) | 1083 | if (!dontFlagDirty) |
1082 | flagDirty(); | 1084 | flagDirty(); |
1083 | return true; | 1085 | return true; |
1084 | } | 1086 | } |
1085 | 1087 | ||
1086 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, | 1088 | bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory, |
1087 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1089 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1088 | { | 1090 | { |
1089 | PWM_ASSERT(d); | 1091 | PWM_ASSERT(d); |
1090 | unsigned int oldCat = 0; | 1092 | unsigned int oldCat = 0; |
1091 | 1093 | ||
1092 | if (!findCategory(oldCategory, &oldCat)) { | 1094 | if (!findCategory(oldCategory, &oldCat)) { |
1093 | BUG(); | 1095 | BUG(); |
1094 | return false; | 1096 | return false; |
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | return editEntry(oldCat, newCategory, index, d, updateMeta); | 1099 | return editEntry(oldCat, newCategory, index, d, updateMeta); |
1098 | } | 1100 | } |
1099 | 1101 | ||
1100 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, | 1102 | bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory, |
1101 | unsigned int index, PwMDataItem *d, bool updateMeta) | 1103 | unsigned int index, PwMDataItem *d, bool updateMeta) |
1102 | { | 1104 | { |
1103 | if (isDeepLocked()) | 1105 | if (isDeepLocked()) |
1104 | return false; | 1106 | return false; |
1105 | if (updateMeta) { | 1107 | if (updateMeta) { |
1106 | d->meta.update = QDateTime::currentDateTime(); | 1108 | d->meta.update = QDateTime::currentDateTime(); |
1107 | if (d->meta.create.isNull()) { | 1109 | if (d->meta.create.isNull()) { |
1108 | d->meta.create = d->meta.update; | 1110 | d->meta.create = d->meta.update; |
1109 | } | 1111 | } |
1110 | } | 1112 | } |
1111 | if (dta[oldCategory].name != newCategory.latin1()) { | 1113 | if (dta[oldCategory].name != newCategory.latin1()) { |
1112 | // the user changed the category. | 1114 | // the user changed the category. |
1113 | PwMerror ret; | 1115 | PwMerror ret; |
1114 | d->rev = 0; | 1116 | d->rev = 0; |
1115 | ret = addEntry(newCategory, d, true, false); | 1117 | ret = addEntry(newCategory, d, true, false); |
1116 | if (ret != e_success) | 1118 | if (ret != e_success) |
1117 | return false; | 1119 | return false; |
1118 | if (!delEntry(oldCategory, index, true)) | 1120 | if (!delEntry(oldCategory, index, true)) |
1119 | return false; | 1121 | return false; |
1120 | } else { | 1122 | } else { |
1121 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. | 1123 | d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter. |
1122 | dta[oldCategory].d[index] = *d; | 1124 | dta[oldCategory].d[index] = *d; |
1123 | } | 1125 | } |
1124 | flagDirty(); | 1126 | flagDirty(); |
1125 | return true; | 1127 | return true; |
1126 | } | 1128 | } |
1127 | 1129 | ||
1128 | unsigned int PwMDoc::numEntries(const QString &category) | 1130 | unsigned int PwMDoc::numEntries(const QString &category) |
1129 | { | 1131 | { |
1130 | unsigned int cat = 0; | 1132 | unsigned int cat = 0; |
1131 | 1133 | ||
1132 | if (!findCategory(category, &cat)) { | 1134 | if (!findCategory(category, &cat)) { |
1133 | BUG(); | 1135 | BUG(); |
1134 | return 0; | 1136 | return 0; |
1135 | } | 1137 | } |
1136 | 1138 | ||
1137 | return numEntries(cat); | 1139 | return numEntries(cat); |
1138 | } | 1140 | } |
1139 | 1141 | ||
1140 | bool PwMDoc::serializeDta(string *d) | 1142 | bool PwMDoc::serializeDta(string *d) |
1141 | { | 1143 | { |
1142 | PWM_ASSERT(d); | 1144 | PWM_ASSERT(d); |
1143 | Serializer ser; | 1145 | Serializer ser; |
1144 | if (!ser.serialize(dta)) | 1146 | if (!ser.serialize(dta)) |
1145 | return false; | 1147 | return false; |
1146 | d->assign(ser.getXml()); | 1148 | d->assign(ser.getXml()); |
1147 | if (!d->size()) | 1149 | if (!d->size()) |
1148 | return false; | 1150 | return false; |
1149 | return true; | 1151 | return true; |
1150 | } | 1152 | } |
1151 | 1153 | ||
1152 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) | 1154 | bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked) |
1153 | { | 1155 | { |
1154 | PWM_ASSERT(d); | 1156 | PWM_ASSERT(d); |
1155 | try { | 1157 | try { |
1156 | Serializer ser(d->c_str()); | 1158 | Serializer ser(d->c_str()); |
1157 | ser.setDefaultLockStat(entriesLocked); | 1159 | ser.setDefaultLockStat(entriesLocked); |
1158 | if (!ser.deSerialize(&dta)) | 1160 | if (!ser.deSerialize(&dta)) |
1159 | return false; | 1161 | return false; |
1160 | } catch (PwMException) { | 1162 | } catch (PwMException) { |
1161 | return false; | 1163 | return false; |
1162 | } | 1164 | } |
1163 | emitDataChanged(this); | 1165 | emitDataChanged(this); |
1164 | return true; | 1166 | return true; |
1165 | } | 1167 | } |
1166 | 1168 | ||
1167 | bool PwMDoc::getEntry(const QString &category, unsigned int index, | 1169 | bool PwMDoc::getEntry(const QString &category, unsigned int index, |
1168 | PwMDataItem * d, bool unlockIfLocked) | 1170 | PwMDataItem * d, bool unlockIfLocked) |
1169 | { | 1171 | { |
1170 | PWM_ASSERT(d); | 1172 | PWM_ASSERT(d); |
1171 | unsigned int cat = 0; | 1173 | unsigned int cat = 0; |
1172 | 1174 | ||
1173 | if (!findCategory(category, &cat)) { | 1175 | if (!findCategory(category, &cat)) { |
1174 | BUG(); | 1176 | BUG(); |
1175 | return false; | 1177 | return false; |
1176 | } | 1178 | } |
1177 | 1179 | ||
1178 | return getEntry(cat, index, d, unlockIfLocked); | 1180 | return getEntry(cat, index, d, unlockIfLocked); |
1179 | } | 1181 | } |
1180 | 1182 | ||
1181 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, | 1183 | bool PwMDoc::getEntry(unsigned int category, unsigned int index, |
1182 | PwMDataItem *d, bool unlockIfLocked) | 1184 | PwMDataItem *d, bool unlockIfLocked) |
1183 | { | 1185 | { |
1184 | if (index > dta[category].d.size() - 1) | 1186 | if (index > dta[category].d.size() - 1) |
1185 | return false; | 1187 | return false; |
1186 | 1188 | ||
1187 | bool locked = isLocked(category, index); | 1189 | bool locked = isLocked(category, index); |
1188 | if (locked) { | 1190 | if (locked) { |
1189 | /* this entry is locked. We don't return a password, | 1191 | /* this entry is locked. We don't return a password, |
1190 | * until it's unlocked by the user by inserting | 1192 | * until it's unlocked by the user by inserting |
1191 | * chipcard or entering the mpw | 1193 | * chipcard or entering the mpw |
1192 | */ | 1194 | */ |
1193 | if (unlockIfLocked) { | 1195 | if (unlockIfLocked) { |
1194 | if (!lockAt(category, index, false)) { | 1196 | if (!lockAt(category, index, false)) { |
1195 | return false; | 1197 | return false; |
1196 | } | 1198 | } |
1197 | locked = false; | 1199 | locked = false; |
1198 | } | 1200 | } |
1199 | } | 1201 | } |
1200 | 1202 | ||
1201 | *d = dta[category].d[index]; | 1203 | *d = dta[category].d[index]; |
1202 | if (locked) | 1204 | if (locked) |
1203 | d->pw = LOCKED_STRING.latin1(); | 1205 | d->pw = LOCKED_STRING.latin1(); |
1204 | 1206 | ||
1205 | return true; | 1207 | return true; |
1206 | } | 1208 | } |
1207 | 1209 | ||
1208 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, | 1210 | PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos, |
1209 | string *foundComment) | 1211 | string *foundComment) |
1210 | { | 1212 | { |
1211 | PWM_ASSERT(foundComment); | 1213 | PWM_ASSERT(foundComment); |
1212 | unsigned int cat = 0; | 1214 | unsigned int cat = 0; |
1213 | 1215 | ||
1214 | if (!findCategory(category, &cat)) | 1216 | if (!findCategory(category, &cat)) |
1215 | return e_invalidArg; | 1217 | return e_invalidArg; |
1216 | 1218 | ||
1217 | unsigned int i, entries = numEntries(cat); | 1219 | unsigned int i, entries = numEntries(cat); |
1218 | for (i = 0; i < entries; ++i) { | 1220 | for (i = 0; i < entries; ++i) { |
1219 | if (dta[cat].d[i].listViewPos == listViewPos) { | 1221 | if (dta[cat].d[i].listViewPos == listViewPos) { |
1220 | *foundComment = dta[cat].d[i].comment; | 1222 | *foundComment = dta[cat].d[i].comment; |
1221 | if (dta[cat].d[i].binary) | 1223 | if (dta[cat].d[i].binary) |
1222 | return e_binEntry; | 1224 | return e_binEntry; |
1223 | return e_normalEntry; | 1225 | return e_normalEntry; |
1224 | } | 1226 | } |
1225 | } | 1227 | } |
1226 | BUG(); | 1228 | BUG(); |
1227 | return e_generic; | 1229 | return e_generic; |
1228 | } | 1230 | } |
1229 | 1231 | ||
1230 | bool PwMDoc::compressDta(string *d, char algo) | 1232 | bool PwMDoc::compressDta(string *d, char algo) |
1231 | { | 1233 | { |
1232 | PWM_ASSERT(d); | 1234 | PWM_ASSERT(d); |
1233 | switch (algo) { | 1235 | switch (algo) { |
1234 | case PWM_COMPRESS_GZIP: { | 1236 | case PWM_COMPRESS_GZIP: { |
1235 | CompressGzip comp; | 1237 | CompressGzip comp; |
1236 | return comp.compress(d); | 1238 | return comp.compress(d); |
1237 | } case PWM_COMPRESS_BZIP2: { | 1239 | } case PWM_COMPRESS_BZIP2: { |
1238 | CompressBzip2 comp; | 1240 | CompressBzip2 comp; |
1239 | return comp.compress(d); | 1241 | return comp.compress(d); |
1240 | } case PWM_COMPRESS_NONE: { | 1242 | } case PWM_COMPRESS_NONE: { |
1241 | return true; | 1243 | return true; |
1242 | } default: { | 1244 | } default: { |
1243 | BUG(); | 1245 | BUG(); |
1244 | } | 1246 | } |
1245 | } | 1247 | } |
1246 | return false; | 1248 | return false; |
1247 | } | 1249 | } |
1248 | 1250 | ||
1249 | bool PwMDoc::decompressDta(string *d, char algo) | 1251 | bool PwMDoc::decompressDta(string *d, char algo) |
1250 | { | 1252 | { |
1251 | PWM_ASSERT(d); | 1253 | PWM_ASSERT(d); |
1252 | switch (algo) { | 1254 | switch (algo) { |
1253 | case PWM_COMPRESS_GZIP: { | 1255 | case PWM_COMPRESS_GZIP: { |
1254 | CompressGzip comp; | 1256 | CompressGzip comp; |
1255 | return comp.decompress(d); | 1257 | return comp.decompress(d); |
1256 | } case PWM_COMPRESS_BZIP2: { | 1258 | } case PWM_COMPRESS_BZIP2: { |
1257 | CompressBzip2 comp; | 1259 | CompressBzip2 comp; |
1258 | return comp.decompress(d); | 1260 | return comp.decompress(d); |
1259 | } case PWM_COMPRESS_NONE: { | 1261 | } case PWM_COMPRESS_NONE: { |
1260 | return true; | 1262 | return true; |
1261 | } | 1263 | } |
1262 | } | 1264 | } |
1263 | return false; | 1265 | return false; |
1264 | } | 1266 | } |
1265 | 1267 | ||
1266 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) | 1268 | PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo) |
1267 | { | 1269 | { |
1268 | PWM_ASSERT(d); | 1270 | PWM_ASSERT(d); |
1269 | PWM_ASSERT(pw); | 1271 | PWM_ASSERT(pw); |
1270 | PWM_ASSERT(f); | 1272 | PWM_ASSERT(f); |
1271 | 1273 | ||
1272 | size_t encSize; | 1274 | size_t encSize; |
1273 | byte *encrypted = 0; | 1275 | byte *encrypted = 0; |
1274 | 1276 | ||
1275 | switch (algo) { | 1277 | switch (algo) { |
1276 | case PWM_CRYPT_BLOWFISH: { | 1278 | case PWM_CRYPT_BLOWFISH: { |
1277 | Blowfish::padNull(d); | 1279 | Blowfish::padNull(d); |
1278 | encSize = d->length(); | 1280 | encSize = d->length(); |
1279 | encrypted = new byte[encSize]; | 1281 | encrypted = new byte[encSize]; |
1280 | Blowfish bf; | 1282 | Blowfish bf; |
1281 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { | 1283 | if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) { |
1282 | delete [] encrypted; | 1284 | delete [] encrypted; |
1283 | return e_weakPw; | 1285 | return e_weakPw; |
1284 | } | 1286 | } |
1285 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); | 1287 | bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize); |
1286 | break; | 1288 | break; |
1287 | } | 1289 | } |
1288 | #ifndef PWM_EMBEDDED | 1290 | #ifndef PWM_EMBEDDED |
1289 | case PWM_CRYPT_AES128: | 1291 | case PWM_CRYPT_AES128: |
1290 | /*... fall through */ | 1292 | /*... fall through */ |
1291 | case PWM_CRYPT_AES192: | 1293 | case PWM_CRYPT_AES192: |
1292 | case PWM_CRYPT_AES256: | 1294 | case PWM_CRYPT_AES256: |
1293 | case PWM_CRYPT_3DES: | 1295 | case PWM_CRYPT_3DES: |
1294 | case PWM_CRYPT_TWOFISH: | 1296 | case PWM_CRYPT_TWOFISH: |
1295 | case PWM_CRYPT_TWOFISH128: { | 1297 | case PWM_CRYPT_TWOFISH128: { |
1296 | if (!LibGCryptIf::available()) | 1298 | if (!LibGCryptIf::available()) |
1297 | return e_cryptNotImpl; | 1299 | return e_cryptNotImpl; |
1298 | LibGCryptIf gc; | 1300 | LibGCryptIf gc; |
1299 | PwMerror err; | 1301 | PwMerror err; |
1300 | unsigned char *plain = new unsigned char[d->length() + 1024]; | 1302 | unsigned char *plain = new unsigned char[d->length() + 1024]; |
1301 | memcpy(plain, d->c_str(), d->length()); | 1303 | memcpy(plain, d->c_str(), d->length()); |
1302 | err = gc.encrypt(&encrypted, | 1304 | err = gc.encrypt(&encrypted, |
1303 | &encSize, | 1305 | &encSize, |
1304 | plain, | 1306 | plain, |
1305 | d->length(), | 1307 | d->length(), |
1306 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1308 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1307 | pw->length(), | 1309 | pw->length(), |
1308 | algo); | 1310 | algo); |
1309 | delete [] plain; | 1311 | delete [] plain; |
1310 | if (err != e_success) | 1312 | if (err != e_success) |
1311 | return e_cryptNotImpl; | 1313 | return e_cryptNotImpl; |
1312 | break; | 1314 | break; |
1313 | } | 1315 | } |
1314 | #endif | 1316 | #endif |
1315 | default: { | 1317 | default: { |
1316 | delete_ifnot_null_array(encrypted); | 1318 | delete_ifnot_null_array(encrypted); |
1317 | return e_cryptNotImpl; | 1319 | return e_cryptNotImpl; |
1318 | } } | 1320 | } } |
1319 | 1321 | ||
1320 | // write encrypted data to file | 1322 | // write encrypted data to file |
1321 | #ifndef PWM_EMBEDDED | 1323 | #ifndef PWM_EMBEDDED |
1322 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), | 1324 | if (f->writeBlock(reinterpret_cast<const char *>(encrypted), |
1323 | static_cast<Q_ULONG>(encSize)) | 1325 | static_cast<Q_ULONG>(encSize)) |
1324 | != static_cast<Q_LONG>(encSize)) { | 1326 | != static_cast<Q_LONG>(encSize)) { |
1325 | delete_ifnot_null_array(encrypted); | 1327 | delete_ifnot_null_array(encrypted); |
1326 | return e_writeFile; | 1328 | return e_writeFile; |
1327 | } | 1329 | } |
1328 | #else | 1330 | #else |
1329 | if (f->writeBlock((const char *)(encrypted), | 1331 | if (f->writeBlock((const char *)(encrypted), |
1330 | (unsigned long)(encSize)) | 1332 | (unsigned long)(encSize)) |
1331 | != (long)(encSize)) { | 1333 | != (long)(encSize)) { |
1332 | delete_ifnot_null_array(encrypted); | 1334 | delete_ifnot_null_array(encrypted); |
1333 | return e_writeFile; | 1335 | return e_writeFile; |
1334 | } | 1336 | } |
1335 | #endif | 1337 | #endif |
1336 | delete_ifnot_null_array(encrypted); | 1338 | delete_ifnot_null_array(encrypted); |
1337 | return e_success; | 1339 | return e_success; |
1338 | } | 1340 | } |
1339 | 1341 | ||
1340 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, | 1342 | PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw, |
1341 | char algo, QFile *f) | 1343 | char algo, QFile *f) |
1342 | { | 1344 | { |
1343 | PWM_ASSERT(d); | 1345 | PWM_ASSERT(d); |
1344 | PWM_ASSERT(pw); | 1346 | PWM_ASSERT(pw); |
1345 | PWM_ASSERT(f); | 1347 | PWM_ASSERT(f); |
1346 | 1348 | ||
1347 | unsigned int cryptLen = f->size() - pos; | 1349 | unsigned int cryptLen = f->size() - pos; |
1348 | byte *encrypted = new byte[cryptLen]; | 1350 | byte *encrypted = new byte[cryptLen]; |
1349 | byte *decrypted = new byte[cryptLen]; | 1351 | byte *decrypted = new byte[cryptLen]; |
1350 | 1352 | ||
1351 | f->at(pos); | 1353 | f->at(pos); |
1352 | #ifndef PWM_EMBEDDED | 1354 | #ifndef PWM_EMBEDDED |
1353 | if (f->readBlock(reinterpret_cast<char *>(encrypted), | 1355 | if (f->readBlock(reinterpret_cast<char *>(encrypted), |
1354 | static_cast<Q_ULONG>(cryptLen)) | 1356 | static_cast<Q_ULONG>(cryptLen)) |
1355 | != static_cast<Q_LONG>(cryptLen)) { | 1357 | != static_cast<Q_LONG>(cryptLen)) { |
1356 | delete [] encrypted; | 1358 | delete [] encrypted; |
1357 | delete [] decrypted; | 1359 | delete [] decrypted; |
1358 | return e_readFile; | 1360 | return e_readFile; |
1359 | } | 1361 | } |
1360 | #else | 1362 | #else |
1361 | if (f->readBlock((char *)(encrypted), | 1363 | if (f->readBlock((char *)(encrypted), |
1362 | (unsigned long)(cryptLen)) | 1364 | (unsigned long)(cryptLen)) |
1363 | != (long)(cryptLen)) { | 1365 | != (long)(cryptLen)) { |
1364 | delete [] encrypted; | 1366 | delete [] encrypted; |
1365 | delete [] decrypted; | 1367 | delete [] decrypted; |
1366 | return e_readFile; | 1368 | return e_readFile; |
1367 | } | 1369 | } |
1368 | #endif | 1370 | #endif |
1369 | switch (algo) { | 1371 | switch (algo) { |
1370 | case PWM_CRYPT_BLOWFISH: { | 1372 | case PWM_CRYPT_BLOWFISH: { |
1371 | Blowfish bf; | 1373 | Blowfish bf; |
1372 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); | 1374 | bf.bf_setkey((byte *) pw->latin1(), pw->length()); |
1373 | bf.bf_decrypt(decrypted, encrypted, cryptLen); | 1375 | bf.bf_decrypt(decrypted, encrypted, cryptLen); |
1374 | break; | 1376 | break; |
1375 | } | 1377 | } |
1376 | #ifndef PWM_EMBEDDED | 1378 | #ifndef PWM_EMBEDDED |
1377 | case PWM_CRYPT_AES128: | 1379 | case PWM_CRYPT_AES128: |
1378 | /*... fall through */ | 1380 | /*... fall through */ |
1379 | case PWM_CRYPT_AES192: | 1381 | case PWM_CRYPT_AES192: |
1380 | case PWM_CRYPT_AES256: | 1382 | case PWM_CRYPT_AES256: |
1381 | case PWM_CRYPT_3DES: | 1383 | case PWM_CRYPT_3DES: |
1382 | case PWM_CRYPT_TWOFISH: | 1384 | case PWM_CRYPT_TWOFISH: |
1383 | case PWM_CRYPT_TWOFISH128: { | 1385 | case PWM_CRYPT_TWOFISH128: { |
1384 | if (!LibGCryptIf::available()) | 1386 | if (!LibGCryptIf::available()) |
1385 | return e_cryptNotImpl; | 1387 | return e_cryptNotImpl; |
1386 | LibGCryptIf gc; | 1388 | LibGCryptIf gc; |
1387 | PwMerror err; | 1389 | PwMerror err; |
1388 | err = gc.decrypt(&decrypted, | 1390 | err = gc.decrypt(&decrypted, |
1389 | &cryptLen, | 1391 | &cryptLen, |
1390 | encrypted, | 1392 | encrypted, |
1391 | cryptLen, | 1393 | cryptLen, |
1392 | reinterpret_cast<const unsigned char *>(pw->latin1()), | 1394 | reinterpret_cast<const unsigned char *>(pw->latin1()), |
1393 | pw->length(), | 1395 | pw->length(), |
1394 | algo); | 1396 | algo); |
1395 | if (err != e_success) { | 1397 | if (err != e_success) { |
1396 | delete [] encrypted; | 1398 | delete [] encrypted; |
1397 | delete [] decrypted; | 1399 | delete [] decrypted; |
1398 | return e_cryptNotImpl; | 1400 | return e_cryptNotImpl; |
1399 | } | 1401 | } |
1400 | break; | 1402 | break; |
1401 | } | 1403 | } |
1402 | #endif | 1404 | #endif |
1403 | default: { | 1405 | default: { |
1404 | delete [] encrypted; | 1406 | delete [] encrypted; |
1405 | delete [] decrypted; | 1407 | delete [] decrypted; |
1406 | return e_cryptNotImpl; | 1408 | return e_cryptNotImpl; |
1407 | } } | 1409 | } } |
1408 | delete [] encrypted; | 1410 | delete [] encrypted; |
1409 | #ifndef PWM_EMBEDDED | 1411 | #ifndef PWM_EMBEDDED |
1410 | d->assign(reinterpret_cast<const char *>(decrypted), | 1412 | d->assign(reinterpret_cast<const char *>(decrypted), |
1411 | static_cast<string::size_type>(cryptLen)); | 1413 | static_cast<string::size_type>(cryptLen)); |
1412 | #else | 1414 | #else |
1413 | d->assign((const char *)(decrypted), | 1415 | d->assign((const char *)(decrypted), |
1414 | (string::size_type)(cryptLen)); | 1416 | (string::size_type)(cryptLen)); |
1415 | #endif | 1417 | #endif |
1416 | delete [] decrypted; | 1418 | delete [] decrypted; |
1417 | if (algo == PWM_CRYPT_BLOWFISH) { | 1419 | if (algo == PWM_CRYPT_BLOWFISH) { |
1418 | if (!Blowfish::unpadNull(d)) { | 1420 | if (!Blowfish::unpadNull(d)) { |
1419 | BUG(); | 1421 | BUG(); |
1420 | return e_readFile; | 1422 | return e_readFile; |
1421 | } | 1423 | } |
1422 | } | 1424 | } |
1423 | return e_success; | 1425 | return e_success; |
1424 | } | 1426 | } |
1425 | 1427 | ||
1426 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, | 1428 | PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash, |
1427 | const string *dataStream) | 1429 | const string *dataStream) |
1428 | { | 1430 | { |
1429 | PWM_ASSERT(dataHash); | 1431 | PWM_ASSERT(dataHash); |
1430 | PWM_ASSERT(dataStream); | 1432 | PWM_ASSERT(dataStream); |
1431 | switch(dataHashType) { | 1433 | switch(dataHashType) { |
1432 | case PWM_HASH_SHA1: { | 1434 | case PWM_HASH_SHA1: { |
1433 | Sha1 hash; | 1435 | Sha1 hash; |
1434 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); | 1436 | hash.sha1_write((byte*)dataStream->c_str(), dataStream->length()); |
1435 | string ret = hash.sha1_read(); | 1437 | string ret = hash.sha1_read(); |
1436 | if (ret != *dataHash) | 1438 | if (ret != *dataHash) |
1437 | return e_fileCorrupt; | 1439 | return e_fileCorrupt; |
1438 | break; | 1440 | break; |
1439 | } | 1441 | } |
1440 | #ifndef PWM_EMBEDDED | 1442 | #ifndef PWM_EMBEDDED |
1441 | case PWM_HASH_SHA256: | 1443 | case PWM_HASH_SHA256: |
1442 | /*... fall through */ | 1444 | /*... fall through */ |
1443 | case PWM_HASH_SHA384: | 1445 | case PWM_HASH_SHA384: |
1444 | case PWM_HASH_SHA512: | 1446 | case PWM_HASH_SHA512: |
1445 | case PWM_HASH_MD5: | 1447 | case PWM_HASH_MD5: |
1446 | case PWM_HASH_RMD160: | 1448 | case PWM_HASH_RMD160: |
1447 | case PWM_HASH_TIGER: { | 1449 | case PWM_HASH_TIGER: { |
1448 | if (!LibGCryptIf::available()) | 1450 | if (!LibGCryptIf::available()) |
1449 | return e_hashNotImpl; | 1451 | return e_hashNotImpl; |
1450 | LibGCryptIf gc; | 1452 | LibGCryptIf gc; |
1451 | PwMerror err; | 1453 | PwMerror err; |
1452 | unsigned char *buf; | 1454 | unsigned char *buf; |
1453 | size_t hashLen; | 1455 | size_t hashLen; |
1454 | err = gc.hash(&buf, | 1456 | err = gc.hash(&buf, |
1455 | &hashLen, | 1457 | &hashLen, |
1456 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), | 1458 | reinterpret_cast<const unsigned char *>(dataStream->c_str()), |
1457 | dataStream->length(), | 1459 | dataStream->length(), |
1458 | dataHashType); | 1460 | dataHashType); |
1459 | if (err != e_success) | 1461 | if (err != e_success) |
1460 | return e_hashNotImpl; | 1462 | return e_hashNotImpl; |
1461 | string calcHash(reinterpret_cast<const char *>(buf), | 1463 | string calcHash(reinterpret_cast<const char *>(buf), |
1462 | static_cast<string::size_type>(hashLen)); | 1464 | static_cast<string::size_type>(hashLen)); |
1463 | delete [] buf; | 1465 | delete [] buf; |
1464 | if (calcHash != *dataHash) | 1466 | if (calcHash != *dataHash) |
1465 | return e_fileCorrupt; | 1467 | return e_fileCorrupt; |
1466 | break; | 1468 | break; |
1467 | } | 1469 | } |
1468 | #endif | 1470 | #endif |
1469 | default: | 1471 | default: |
1470 | return e_hashNotImpl; | 1472 | return e_hashNotImpl; |
1471 | } | 1473 | } |
1472 | return e_success; | 1474 | return e_success; |
1473 | } | 1475 | } |
1474 | 1476 | ||
1475 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, | 1477 | bool PwMDoc::lockAt(unsigned int category, unsigned int index, |
1476 | bool lock) | 1478 | bool lock) |
1477 | { | 1479 | { |
1478 | if (index >= numEntries(category)) { | 1480 | if (index >= numEntries(category)) { |
1479 | BUG(); | 1481 | BUG(); |
1480 | return false; | 1482 | return false; |
1481 | } | 1483 | } |
1482 | if (lock == dta[category].d[index].lockStat) | 1484 | if (lock == dta[category].d[index].lockStat) |
1483 | return true; | 1485 | return true; |
1484 | 1486 | ||
1485 | if (!lock && currentPw != "") { | 1487 | if (!lock && currentPw != "") { |
1486 | // "unlocking" and "password is already set" | 1488 | // "unlocking" and "password is already set" |
1487 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1489 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1488 | // unlocking without pw not allowed | 1490 | // unlocking without pw not allowed |
1489 | QString pw; | 1491 | QString pw; |
1490 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1492 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1491 | if (pw != "") { | 1493 | if (pw != "") { |
1492 | if (pw != currentPw) { | 1494 | if (pw != currentPw) { |
1493 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1495 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1494 | return false; | 1496 | return false; |
1495 | } else { | 1497 | } else { |
1496 | timer()->start(DocTimer::id_mpwTimer); | 1498 | timer()->start(DocTimer::id_mpwTimer); |
1497 | } | 1499 | } |
1498 | } else { | 1500 | } else { |
1499 | return false; | 1501 | return false; |
1500 | } | 1502 | } |
1501 | } else { | 1503 | } else { |
1502 | timer()->start(DocTimer::id_mpwTimer); | 1504 | timer()->start(DocTimer::id_mpwTimer); |
1503 | } | 1505 | } |
1504 | } | 1506 | } |
1505 | 1507 | ||
1506 | dta[category].d[index].lockStat = lock; | 1508 | dta[category].d[index].lockStat = lock; |
1507 | dta[category].d[index].rev++; // increment revision counter. | 1509 | dta[category].d[index].rev++; // increment revision counter. |
1508 | 1510 | ||
1509 | emitDataChanged(this); | 1511 | emitDataChanged(this); |
1510 | if (!lock) | 1512 | if (!lock) |
1511 | timer()->start(DocTimer::id_autoLockTimer); | 1513 | timer()->start(DocTimer::id_autoLockTimer); |
1512 | 1514 | ||
1513 | return true; | 1515 | return true; |
1514 | 1516 | ||
1515 | } | 1517 | } |
1516 | 1518 | ||
1517 | bool PwMDoc::lockAt(const QString &category,unsigned int index, | 1519 | bool PwMDoc::lockAt(const QString &category,unsigned int index, |
1518 | bool lock) | 1520 | bool lock) |
1519 | { | 1521 | { |
1520 | unsigned int cat = 0; | 1522 | unsigned int cat = 0; |
1521 | 1523 | ||
1522 | if (!findCategory(category, &cat)) { | 1524 | if (!findCategory(category, &cat)) { |
1523 | BUG(); | 1525 | BUG(); |
1524 | return false; | 1526 | return false; |
1525 | } | 1527 | } |
1526 | 1528 | ||
1527 | return lockAt(cat, index, lock); | 1529 | return lockAt(cat, index, lock); |
1528 | } | 1530 | } |
1529 | 1531 | ||
1530 | bool PwMDoc::lockAll(bool lock) | 1532 | bool PwMDoc::lockAll(bool lock) |
1531 | { | 1533 | { |
1532 | if (!lock && isDeepLocked()) { | 1534 | if (!lock && isDeepLocked()) { |
1533 | PwMerror ret; | 1535 | PwMerror ret; |
1534 | ret = deepLock(false); | 1536 | ret = deepLock(false); |
1535 | if (ret != e_success) | 1537 | if (ret != e_success) |
1536 | return false; | 1538 | return false; |
1537 | return true; | 1539 | return true; |
1538 | } | 1540 | } |
1539 | if (isDocEmpty()) { | 1541 | if (isDocEmpty()) { |
1540 | return true; | 1542 | return true; |
1541 | } | 1543 | } |
1542 | if (!lock && currentPw != "") { | 1544 | if (!lock && currentPw != "") { |
1543 | // unlocking and password is already set | 1545 | // unlocking and password is already set |
1544 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { | 1546 | if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) { |
1545 | // unlocking without pw not allowed | 1547 | // unlocking without pw not allowed |
1546 | QString pw; | 1548 | QString pw; |
1547 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1549 | pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1548 | if (pw != "") { | 1550 | if (pw != "") { |
1549 | if (pw != currentPw) { | 1551 | if (pw != currentPw) { |
1550 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); | 1552 | wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD)); |
1551 | return false; | 1553 | return false; |
1552 | } else { | 1554 | } else { |
1553 | timer()->start(DocTimer::id_mpwTimer); | 1555 | timer()->start(DocTimer::id_mpwTimer); |
1554 | } | 1556 | } |
1555 | } else { | 1557 | } else { |
1556 | return false; | 1558 | return false; |
1557 | } | 1559 | } |
1558 | } else { | 1560 | } else { |
1559 | timer()->start(DocTimer::id_mpwTimer); | 1561 | timer()->start(DocTimer::id_mpwTimer); |
1560 | } | 1562 | } |
1561 | } | 1563 | } |
1562 | 1564 | ||
1563 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), | 1565 | vector<PwMCategoryItem>::iterator catBegin = dta.begin(), |
1564 | catEnd = dta.end(), | 1566 | catEnd = dta.end(), |
1565 | catI = catBegin; | 1567 | catI = catBegin; |
1566 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 1568 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
1567 | while (catI != catEnd) { | 1569 | while (catI != catEnd) { |
1568 | entrBegin = catI->d.begin(); | 1570 | entrBegin = catI->d.begin(); |
1569 | entrEnd = catI->d.end(); | 1571 | entrEnd = catI->d.end(); |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 9650d55..193247e 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -1,701 +1,701 @@ | |||
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 | #ifndef __PWMDOC_H | 20 | #ifndef __PWMDOC_H |
21 | #define __PWMDOC_H | 21 | #define __PWMDOC_H |
22 | 22 | ||
23 | #define PWM_FILE_VER (static_cast<char>(0x05)) | 23 | #define PWM_FILE_VER (static_cast<char>(0x05)) |
24 | 24 | ||
25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) | 25 | #define PWM_HASH_SHA1 (static_cast<char>(0x01)) |
26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) | 26 | #define PWM_HASH_SHA256 (static_cast<char>(0x02)) |
27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) | 27 | #define PWM_HASH_SHA384 (static_cast<char>(0x03)) |
28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) | 28 | #define PWM_HASH_SHA512 (static_cast<char>(0x04)) |
29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) | 29 | #define PWM_HASH_MD5 (static_cast<char>(0x05)) |
30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) | 30 | #define PWM_HASH_RMD160 (static_cast<char>(0x06)) |
31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) | 31 | #define PWM_HASH_TIGER (static_cast<char>(0x07)) |
32 | 32 | ||
33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) | 33 | #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) |
34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) | 34 | #define PWM_CRYPT_AES128(static_cast<char>(0x02)) |
35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) | 35 | #define PWM_CRYPT_AES192(static_cast<char>(0x03)) |
36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) | 36 | #define PWM_CRYPT_AES256(static_cast<char>(0x04)) |
37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) | 37 | #define PWM_CRYPT_3DES (static_cast<char>(0x05)) |
38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) | 38 | #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) |
39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) | 39 | #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) |
40 | 40 | ||
41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) | 41 | #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) |
42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) | 42 | #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) |
43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) | 43 | #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) |
44 | 44 | ||
45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) | 45 | #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) |
46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" | 46 | #define FILE_ID_HEADER "PWM_PASSWORD_FILE" |
47 | 47 | ||
48 | 48 | ||
49 | #include "pwmexception.h" | 49 | #include "pwmexception.h" |
50 | #include "pwmdocui.h" | 50 | #include "pwmdocui.h" |
51 | #include "configuration.h" | ||
52 | 51 | ||
53 | #include <qobject.h> | 52 | #include <qobject.h> |
54 | #include <qtimer.h> | 53 | #include <qtimer.h> |
55 | #include <qdatetime.h> | 54 | #include <qdatetime.h> |
56 | 55 | ||
57 | #include <kprocess.h> | 56 | #include <kprocess.h> |
58 | 57 | ||
59 | #ifndef PWM_EMBEDDED | 58 | #ifndef PWM_EMBEDDED |
59 | #include "configuration.h" | ||
60 | #else | 60 | #else |
61 | #include <kapplication.h> | 61 | #include <kapplication.h> |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #include <string> | 64 | #include <string> |
65 | #include <vector> | 65 | #include <vector> |
66 | #include <utility> | 66 | #include <utility> |
67 | 67 | ||
68 | using std::vector; | 68 | using std::vector; |
69 | using std::string; | 69 | using std::string; |
70 | using std::pair; | 70 | using std::pair; |
71 | 71 | ||
72 | /* used in findEntry() function */ | 72 | /* used in findEntry() function */ |
73 | #define SEARCH_IN_DESC (1) | 73 | #define SEARCH_IN_DESC (1) |
74 | #define SEARCH_IN_NAME (1 << 1) | 74 | #define SEARCH_IN_NAME (1 << 1) |
75 | #define SEARCH_IN_PW (1 << 2) | 75 | #define SEARCH_IN_PW (1 << 2) |
76 | #define SEARCH_IN_COMMENT(1 << 3) | 76 | #define SEARCH_IN_COMMENT(1 << 3) |
77 | #define SEARCH_IN_URL (1 << 4) | 77 | #define SEARCH_IN_URL (1 << 4) |
78 | #define SEARCH_IN_LAUNCHER(1 << 5) | 78 | #define SEARCH_IN_LAUNCHER(1 << 5) |
79 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ | 79 | #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ |
80 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ | 80 | SEARCH_IN_PW | SEARCH_IN_COMMENT| \ |
81 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) | 81 | SEARCH_IN_URL| SEARCH_IN_LAUNCHER) |
82 | 82 | ||
83 | /** document deeplocked. Data is out for lunch to disk */ | 83 | /** document deeplocked. Data is out for lunch to disk */ |
84 | #define DOC_STAT_DEEPLOCKED (1) | 84 | #define DOC_STAT_DEEPLOCKED (1) |
85 | /** encrypted document on disk is dirty. data has to go to disk. */ | 85 | /** encrypted document on disk is dirty. data has to go to disk. */ |
86 | #define DOC_STAT_DISK_DIRTY (1 << 1) | 86 | #define DOC_STAT_DISK_DIRTY (1 << 1) |
87 | /** we are using a chipcard to encrypt the data */ | 87 | /** we are using a chipcard to encrypt the data */ |
88 | #define DOC_STAT_USE_CHIPCARD (1 << 2) | 88 | #define DOC_STAT_USE_CHIPCARD (1 << 2) |
89 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ | 89 | /** use "currentPw" to unlock. (This flag is set/unset by a timer) */ |
90 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) | 90 | #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) |
91 | 91 | ||
92 | class PwMDoc; | 92 | class PwMDoc; |
93 | class PwMView; | 93 | class PwMView; |
94 | class QFile; | 94 | class QFile; |
95 | 95 | ||
96 | /* meta data for a PwMDataItem */ | 96 | /* meta data for a PwMDataItem */ |
97 | struct PwMMetaData | 97 | struct PwMMetaData |
98 | { | 98 | { |
99 | PwMMetaData() | 99 | PwMMetaData() |
100 | : updateInt (0) | 100 | : updateInt (0) |
101 | { } | 101 | { } |
102 | /** creation date of the PwMDataItem to which | 102 | /** creation date of the PwMDataItem to which |
103 | * this meta data belongs. | 103 | * this meta data belongs. |
104 | */ | 104 | */ |
105 | QDateTimecreate; | 105 | QDateTimecreate; |
106 | /** becomes valid on this date */ | 106 | /** becomes valid on this date */ |
107 | QDateTimevalid; | 107 | QDateTimevalid; |
108 | /** expire date */ | 108 | /** expire date */ |
109 | QDateTimeexpire; | 109 | QDateTimeexpire; |
110 | /** update date (last updated at this date) */ | 110 | /** update date (last updated at this date) */ |
111 | QDateTimeupdate; | 111 | QDateTimeupdate; |
112 | /** update interval (in minutes). Time since the | 112 | /** update interval (in minutes). Time since the |
113 | * last update to remind the user to update the item. | 113 | * last update to remind the user to update the item. |
114 | * 0 disables. | 114 | * 0 disables. |
115 | */ | 115 | */ |
116 | unsigned long updateInt; | 116 | unsigned long updateInt; |
117 | 117 | ||
118 | //US ENH: enhancements of the filestructure | 118 | //US ENH: enhancements of the filestructure |
119 | /* each entry gets a unique id assigned */ | 119 | /* each entry gets a unique id assigned */ |
120 | QString uniqueid; | 120 | QString uniqueid; |
121 | 121 | ||
122 | 122 | ||
123 | void clear() | 123 | void clear() |
124 | { | 124 | { |
125 | create = QDateTime(); | 125 | create = QDateTime(); |
126 | expire = QDateTime(); | 126 | expire = QDateTime(); |
127 | update = QDateTime(); | 127 | update = QDateTime(); |
128 | updateInt = 0; | 128 | updateInt = 0; |
129 | uniqueid = KApplication::randomString(8); | 129 | uniqueid = KApplication::randomString(8); |
130 | } | 130 | } |
131 | inline bool isValid() const | 131 | inline bool isValid() const |
132 | { | 132 | { |
133 | if (valid.isNull()) | 133 | if (valid.isNull()) |
134 | return true; | 134 | return true; |
135 | return (valid < QDateTime::currentDateTime()); | 135 | return (valid < QDateTime::currentDateTime()); |
136 | } | 136 | } |
137 | inline bool isExpired() const | 137 | inline bool isExpired() const |
138 | { | 138 | { |
139 | if (expire.isNull()) | 139 | if (expire.isNull()) |
140 | return false; | 140 | return false; |
141 | return (expire < QDateTime::currentDateTime()); | 141 | return (expire < QDateTime::currentDateTime()); |
142 | } | 142 | } |
143 | inline bool isUpdateIntOver() const | 143 | inline bool isUpdateIntOver() const |
144 | { | 144 | { |
145 | if (updateInt == 0 || | 145 | if (updateInt == 0 || |
146 | update.isNull()) | 146 | update.isNull()) |
147 | return false; | 147 | return false; |
148 | QDateTime d(update); | 148 | QDateTime d(update); |
149 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 149 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
150 | } | 150 | } |
151 | }; | 151 | }; |
152 | 152 | ||
153 | struct PwMDataItem | 153 | struct PwMDataItem |
154 | { | 154 | { |
155 | PwMDataItem() | 155 | PwMDataItem() |
156 | : lockStat (true) | 156 | : lockStat (true) |
157 | , listViewPos (-1) | 157 | , listViewPos (-1) |
158 | , binary (false) | 158 | , binary (false) |
159 | , rev (0) | 159 | , rev (0) |
160 | { } | 160 | { } |
161 | 161 | ||
162 | /** password description */ | 162 | /** password description */ |
163 | stringdesc; | 163 | stringdesc; |
164 | /** user-name */ | 164 | /** user-name */ |
165 | stringname; | 165 | stringname; |
166 | /** the password itself */ | 166 | /** the password itself */ |
167 | stringpw; | 167 | stringpw; |
168 | /** some comment */ | 168 | /** some comment */ |
169 | stringcomment; | 169 | stringcomment; |
170 | /** an URL string */ | 170 | /** an URL string */ |
171 | stringurl; | 171 | stringurl; |
172 | /** launcher. Can be executed as a system() command */ | 172 | /** launcher. Can be executed as a system() command */ |
173 | stringlauncher; | 173 | stringlauncher; |
174 | /** locking status. If locked (true), pw is not emitted through getEntry() */ | 174 | /** locking status. If locked (true), pw is not emitted through getEntry() */ |
175 | boollockStat; | 175 | boollockStat; |
176 | /** position of this item in main "list-view" | 176 | /** position of this item in main "list-view" |
177 | * If -1, the position is not yet specified and should be appended to the list | 177 | * If -1, the position is not yet specified and should be appended to the list |
178 | */ | 178 | */ |
179 | intlistViewPos; | 179 | intlistViewPos; |
180 | /** does this entry contain binary data? */ | 180 | /** does this entry contain binary data? */ |
181 | bool binary; | 181 | bool binary; |
182 | /** meta data for this data item. */ | 182 | /** meta data for this data item. */ |
183 | PwMMetaData meta; | 183 | PwMMetaData meta; |
184 | /** data revision counter. This counter can be used | 184 | /** data revision counter. This counter can be used |
185 | * to easily, efficiently determine if this data item | 185 | * to easily, efficiently determine if this data item |
186 | * has changed since some time. | 186 | * has changed since some time. |
187 | * This counter is incremented on every update. | 187 | * This counter is incremented on every update. |
188 | */ | 188 | */ |
189 | unsigned int rev; | 189 | unsigned int rev; |
190 | 190 | ||
191 | void clear(bool clearMeta = true) | 191 | void clear(bool clearMeta = true) |
192 | { | 192 | { |
193 | /* NOTE: Don't use .clear() here to be | 193 | /* NOTE: Don't use .clear() here to be |
194 | * backward compatible with gcc-2 (Debian Woody) | 194 | * backward compatible with gcc-2 (Debian Woody) |
195 | */ | 195 | */ |
196 | desc = ""; | 196 | desc = ""; |
197 | name = ""; | 197 | name = ""; |
198 | pw = ""; | 198 | pw = ""; |
199 | comment = ""; | 199 | comment = ""; |
200 | url = ""; | 200 | url = ""; |
201 | launcher = ""; | 201 | launcher = ""; |
202 | lockStat = true; | 202 | lockStat = true; |
203 | listViewPos = -1; | 203 | listViewPos = -1; |
204 | binary = false; | 204 | binary = false; |
205 | if (clearMeta) | 205 | if (clearMeta) |
206 | meta.clear(); | 206 | meta.clear(); |
207 | } | 207 | } |
208 | }; | 208 | }; |
209 | 209 | ||
210 | struct PwMCategoryItem | 210 | struct PwMCategoryItem |
211 | { | 211 | { |
212 | /** all PwMDataItems (all passwords) within this category */ | 212 | /** all PwMDataItems (all passwords) within this category */ |
213 | vector<PwMDataItem>d; | 213 | vector<PwMDataItem>d; |
214 | /** category name/description */ | 214 | /** category name/description */ |
215 | string name; | 215 | string name; |
216 | 216 | ||
217 | void clear() | 217 | void clear() |
218 | { | 218 | { |
219 | d.clear(); | 219 | d.clear(); |
220 | name = ""; | 220 | name = ""; |
221 | } | 221 | } |
222 | }; | 222 | }; |
223 | 223 | ||
224 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ | 224 | /** "Function Object" for sort()ing PwMDataItem::listViewPos */ |
225 | class dta_lvp_greater | 225 | class dta_lvp_greater |
226 | { | 226 | { |
227 | public: | 227 | public: |
228 | bool operator() (const pair<unsigned int, unsigned int> &d1, | 228 | bool operator() (const pair<unsigned int, unsigned int> &d1, |
229 | const pair<unsigned int, unsigned int> &d2) | 229 | const pair<unsigned int, unsigned int> &d2) |
230 | { | 230 | { |
231 | return d1.second > d2.second; | 231 | return d1.second > d2.second; |
232 | } | 232 | } |
233 | }; | 233 | }; |
234 | 234 | ||
235 | /** list of PwMDoc documents and it's IDs */ | 235 | /** list of PwMDoc documents and it's IDs */ |
236 | class PwMDocList | 236 | class PwMDocList |
237 | { | 237 | { |
238 | public: | 238 | public: |
239 | struct listItem | 239 | struct listItem |
240 | { | 240 | { |
241 | /** document filename (known as ID, here) */ | 241 | /** document filename (known as ID, here) */ |
242 | string docId; | 242 | string docId; |
243 | /** pointer to the document class */ | 243 | /** pointer to the document class */ |
244 | PwMDoc *doc; | 244 | PwMDoc *doc; |
245 | }; | 245 | }; |
246 | 246 | ||
247 | PwMDocList() {} | 247 | PwMDocList() {} |
248 | 248 | ||
249 | /** add a new item to the list */ | 249 | /** add a new item to the list */ |
250 | void add(PwMDoc *doc, const string &id); | 250 | void add(PwMDoc *doc, const string &id); |
251 | /** changes the contents of an existing item */ | 251 | /** changes the contents of an existing item */ |
252 | void edit(PwMDoc *doc, const string &newId); | 252 | void edit(PwMDoc *doc, const string &newId); |
253 | /** remove the given item */ | 253 | /** remove the given item */ |
254 | void del(PwMDoc *doc); | 254 | void del(PwMDoc *doc); |
255 | /** get the item at index */ | 255 | /** get the item at index */ |
256 | listItem getAt(int index) | 256 | listItem getAt(int index) |
257 | { return docList[index]; } | 257 | { return docList[index]; } |
258 | /** find an entry with this id */ | 258 | /** find an entry with this id */ |
259 | bool find(const string &id, listItem *ret = 0); | 259 | bool find(const string &id, listItem *ret = 0); |
260 | /** returns a copy of the list */ | 260 | /** returns a copy of the list */ |
261 | const vector<listItem>* getList() const | 261 | const vector<listItem>* getList() const |
262 | { return &docList; } | 262 | { return &docList; } |
263 | 263 | ||
264 | 264 | ||
265 | /** returns a new unique number to extend the name of | 265 | /** returns a new unique number to extend the name of |
266 | * an unnamed document. | 266 | * an unnamed document. |
267 | */ | 267 | */ |
268 | static unsigned int getNewUnnamedNumber() | 268 | static unsigned int getNewUnnamedNumber() |
269 | { return unnamedDocCnt++; } | 269 | { return unnamedDocCnt++; } |
270 | 270 | ||
271 | protected: | 271 | protected: |
272 | /* Hm, I think we shouldn't really use a "list" here, should we? | 272 | /* Hm, I think we shouldn't really use a "list" here, should we? |
273 | * So I decided to actually use a vector. | 273 | * So I decided to actually use a vector. |
274 | */ | 274 | */ |
275 | vector<listItem> docList; | 275 | vector<listItem> docList; |
276 | /** This value is used to get a new number for yet unnamed | 276 | /** This value is used to get a new number for yet unnamed |
277 | * documents. It is incremented on every request. So it's | 277 | * documents. It is incremented on every request. So it's |
278 | * theoretically possible to overflow it, but... :) | 278 | * theoretically possible to overflow it, but... :) |
279 | */ | 279 | */ |
280 | static unsigned int unnamedDocCnt; | 280 | static unsigned int unnamedDocCnt; |
281 | }; | 281 | }; |
282 | 282 | ||
283 | /** implements timers for the document */ | 283 | /** implements timers for the document */ |
284 | class DocTimer : public QObject | 284 | class DocTimer : public QObject |
285 | { | 285 | { |
286 | Q_OBJECT | 286 | Q_OBJECT |
287 | public: | 287 | public: |
288 | enum TimerIDs | 288 | enum TimerIDs |
289 | { | 289 | { |
290 | id_mpwTimer, | 290 | id_mpwTimer, |
291 | id_autoLockTimer, | 291 | id_autoLockTimer, |
292 | id_metaCheckTimer | 292 | id_metaCheckTimer |
293 | }; | 293 | }; |
294 | 294 | ||
295 | public: | 295 | public: |
296 | DocTimer(PwMDoc *_doc); | 296 | DocTimer(PwMDoc *_doc); |
297 | ~DocTimer(); | 297 | ~DocTimer(); |
298 | 298 | ||
299 | /** start the timer */ | 299 | /** start the timer */ |
300 | void start(TimerIDs timer); | 300 | void start(TimerIDs timer); |
301 | /** stop the timer */ | 301 | /** stop the timer */ |
302 | void stop(TimerIDs timer); | 302 | void stop(TimerIDs timer); |
303 | /** get the lock for a timer. | 303 | /** get the lock for a timer. |
304 | * This lock is a recursive lock. When a lock is | 304 | * This lock is a recursive lock. When a lock is |
305 | * held, the timer will be stopped and timeout is | 305 | * held, the timer will be stopped and timeout is |
306 | * guaranteed to not happen | 306 | * guaranteed to not happen |
307 | */ | 307 | */ |
308 | void getLock(TimerIDs timer); | 308 | void getLock(TimerIDs timer); |
309 | /** put a recursive timer lock */ | 309 | /** put a recursive timer lock */ |
310 | void putLock(TimerIDs timer); | 310 | void putLock(TimerIDs timer); |
311 | 311 | ||
312 | protected slots: | 312 | protected slots: |
313 | /** timeout slot for the mpw timer */ | 313 | /** timeout slot for the mpw timer */ |
314 | void mpwTimeout(); | 314 | void mpwTimeout(); |
315 | /** timeout slot for the autoLock timer */ | 315 | /** timeout slot for the autoLock timer */ |
316 | void autoLockTimeout(); | 316 | void autoLockTimeout(); |
317 | /** timeout slot for the metaCheck timer */ | 317 | /** timeout slot for the metaCheck timer */ |
318 | void metaCheckTimeout(); | 318 | void metaCheckTimeout(); |
319 | 319 | ||
320 | protected: | 320 | protected: |
321 | /** pointer to the document associated with this timer. */ | 321 | /** pointer to the document associated with this timer. */ |
322 | PwMDoc *doc; | 322 | PwMDoc *doc; |
323 | /** timer object for mpw timer */ | 323 | /** timer object for mpw timer */ |
324 | QTimer *mpwTimer; | 324 | QTimer *mpwTimer; |
325 | /** timer object for the autoLock timer */ | 325 | /** timer object for the autoLock timer */ |
326 | QTimer *autoLockTimer; | 326 | QTimer *autoLockTimer; |
327 | /** timer object for the metaCheck timer */ | 327 | /** timer object for the metaCheck timer */ |
328 | QTimer *metaCheckTimer; | 328 | QTimer *metaCheckTimer; |
329 | /** lock counter for the mpw timer */ | 329 | /** lock counter for the mpw timer */ |
330 | unsigned int mpwLock; | 330 | unsigned int mpwLock; |
331 | /** lock counter for the autoLock timer */ | 331 | /** lock counter for the autoLock timer */ |
332 | unsigned int autoLockLock; | 332 | unsigned int autoLockLock; |
333 | /** lock counter for the metaCheck timer */ | 333 | /** lock counter for the metaCheck timer */ |
334 | unsigned int metaCheckLock; | 334 | unsigned int metaCheckLock; |
335 | }; | 335 | }; |
336 | 336 | ||
337 | /** Document class for PwM */ | 337 | /** Document class for PwM */ |
338 | class PwMDoc : public PwMDocUi | 338 | class PwMDoc : public PwMDocUi |
339 | { | 339 | { |
340 | Q_OBJECT | 340 | Q_OBJECT |
341 | friend class DocTimer; | 341 | friend class DocTimer; |
342 | 342 | ||
343 | public: | 343 | public: |
344 | /** construtor */ | 344 | /** construtor */ |
345 | PwMDoc(QObject* parent = 0, const char *name = 0); | 345 | PwMDoc(QObject* parent = 0, const char *name = 0); |
346 | /** destructor */ | 346 | /** destructor */ |
347 | ~PwMDoc(); | 347 | ~PwMDoc(); |
348 | 348 | ||
349 | /** returns a pointer to a list of all open documents */ | 349 | /** returns a pointer to a list of all open documents */ |
350 | static PwMDocList* getOpenDocList() | 350 | static PwMDocList* getOpenDocList() |
351 | { return &openDocList; } | 351 | { return &openDocList; } |
352 | 352 | ||
353 | /** flag document dirty. dta changed */ | 353 | /** flag document dirty. dta changed */ |
354 | void flagDirty() | 354 | void flagDirty() |
355 | { | 355 | { |
356 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 356 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
357 | emitDataChanged(this); | 357 | emitDataChanged(this); |
358 | } | 358 | } |
359 | /** modified? */ | 359 | /** modified? */ |
360 | bool isDirty() | 360 | bool isDirty() |
361 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } | 361 | { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } |
362 | /** save document to disk */ | 362 | /** save document to disk */ |
363 | PwMerror saveDoc(char compress, const QString *file = 0); | 363 | PwMerror saveDoc(char compress, const QString *file = 0); |
364 | /** read document from file. | 364 | /** read document from file. |
365 | * "openLocked is must be set to either of these values: | 365 | * "openLocked is must be set to either of these values: |
366 | * 0 == open with all entries unlocked | 366 | * 0 == open with all entries unlocked |
367 | * 1 == open with all entries locked | 367 | * 1 == open with all entries locked |
368 | * 2 == open deep-locked | 368 | * 2 == open deep-locked |
369 | */ | 369 | */ |
370 | PwMerror openDoc(const QString *file, int openLocked); | 370 | PwMerror openDoc(const QString *file, int openLocked); |
371 | /** export document to ascii-textfile */ | 371 | /** export document to ascii-textfile */ |
372 | PwMerror exportToText(const QString *file); | 372 | PwMerror exportToText(const QString *file); |
373 | /** export document to gpasman / kpasman file */ | 373 | /** export document to gpasman / kpasman file */ |
374 | PwMerror exportToGpasman(const QString *file); | 374 | PwMerror exportToGpasman(const QString *file); |
375 | /** import document from ascii-textfile */ | 375 | /** import document from ascii-textfile */ |
376 | PwMerror importFromText(const QString *file, int format = -1); | 376 | PwMerror importFromText(const QString *file, int format = -1); |
377 | /** import document from gpasman / kpasman file */ | 377 | /** import document from gpasman / kpasman file */ |
378 | PwMerror importFromGpasman(const QString *file); | 378 | PwMerror importFromGpasman(const QString *file); |
379 | /** add new entry */ | 379 | /** add new entry */ |
380 | PwMerror addEntry(const QString &category, PwMDataItem *d, | 380 | PwMerror addEntry(const QString &category, PwMDataItem *d, |
381 | bool dontFlagDirty = false, bool updateMeta = true); | 381 | bool dontFlagDirty = false, bool updateMeta = true); |
382 | /** add new category. This function doesn't flag the document dirty! */ | 382 | /** add new category. This function doesn't flag the document dirty! */ |
383 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, | 383 | PwMerror addCategory(const QString &category, unsigned int *categoryIndex, |
384 | bool checkIfExist = true); | 384 | bool checkIfExist = true); |
385 | /** rename an existing category */ | 385 | /** rename an existing category */ |
386 | bool renameCategory(const QString &category, const QString &newName); | 386 | bool renameCategory(const QString &category, const QString &newName); |
387 | /** rename an existing category */ | 387 | /** rename an existing category */ |
388 | bool renameCategory(unsigned int category, const QString &newName, | 388 | bool renameCategory(unsigned int category, const QString &newName, |
389 | bool dontFlagDirty = false); | 389 | bool dontFlagDirty = false); |
390 | /** delete an existing category */ | 390 | /** delete an existing category */ |
391 | bool delCategory(const QString &category); | 391 | bool delCategory(const QString &category); |
392 | /** delete an existing category */ | 392 | /** delete an existing category */ |
393 | bool delCategory(unsigned int category, bool dontFlagDirty = false); | 393 | bool delCategory(unsigned int category, bool dontFlagDirty = false); |
394 | /** returns a list of all category-names */ | 394 | /** returns a list of all category-names */ |
395 | void getCategoryList(vector<string> *list); | 395 | void getCategoryList(vector<string> *list); |
396 | /** returns a list of all category-names */ | 396 | /** returns a list of all category-names */ |
397 | void getCategoryList(QStringList *list); | 397 | void getCategoryList(QStringList *list); |
398 | /** returns a list of all entry-descs in the given category */ | 398 | /** returns a list of all entry-descs in the given category */ |
399 | void getEntryList(const QString &category, QStringList *list); | 399 | void getEntryList(const QString &category, QStringList *list); |
400 | /** returns a list of all entry-descs in the given category */ | 400 | /** returns a list of all entry-descs in the given category */ |
401 | void getEntryList(const QString &category, vector<string> *list); | 401 | void getEntryList(const QString &category, vector<string> *list); |
402 | /** returns a list of all entry-descs in the given category */ | 402 | /** returns a list of all entry-descs in the given category */ |
403 | void getEntryList(unsigned int category, vector<string> *list); | 403 | void getEntryList(unsigned int category, vector<string> *list); |
404 | /** returns a list of all entry-descs in the given category */ | 404 | /** returns a list of all entry-descs in the given category */ |
405 | void getEntryList(unsigned int category, QStringList *list); | 405 | void getEntryList(unsigned int category, QStringList *list); |
406 | /** delete entry */ | 406 | /** delete entry */ |
407 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); | 407 | bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false); |
408 | /** delete entry */ | 408 | /** delete entry */ |
409 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); | 409 | bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false); |
410 | /** edit entry */ | 410 | /** edit entry */ |
411 | bool editEntry(const QString &oldCategory, const QString &newCategory, | 411 | bool editEntry(const QString &oldCategory, const QString &newCategory, |
412 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 412 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
413 | /** edit entry */ | 413 | /** edit entry */ |
414 | bool editEntry(unsigned int oldCategory, const QString &newCategory, | 414 | bool editEntry(unsigned int oldCategory, const QString &newCategory, |
415 | unsigned int index, PwMDataItem *d, bool updateMeta = true); | 415 | unsigned int index, PwMDataItem *d, bool updateMeta = true); |
416 | /** finds the category with the "name" and return it's index */ | 416 | /** finds the category with the "name" and return it's index */ |
417 | bool findCategory(const QString &name, unsigned int *index); | 417 | bool findCategory(const QString &name, unsigned int *index); |
418 | /** search for an entry "find" and check while searching only for | 418 | /** search for an entry "find" and check while searching only for |
419 | * the data-fields specified by "searchIn". To set the "searchIn" | 419 | * the data-fields specified by "searchIn". To set the "searchIn" |
420 | * value, we may use one or more of the SEARCH_IN_* defines at | 420 | * value, we may use one or more of the SEARCH_IN_* defines at |
421 | * the top of this header-file. It returns the positions of all | 421 | * the top of this header-file. It returns the positions of all |
422 | * matched entries in "foundPositions". If "breakAfterFound" is true, | 422 | * matched entries in "foundPositions". If "breakAfterFound" is true, |
423 | * the function terminates after the first occurence of the entry | 423 | * the function terminates after the first occurence of the entry |
424 | * and doesn't go on searching. So foundPositions->size() is never | 424 | * and doesn't go on searching. So foundPositions->size() is never |
425 | * > 1 if breakAfterFound is true. | 425 | * > 1 if breakAfterFound is true. |
426 | */ | 426 | */ |
427 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, | 427 | void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn, |
428 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 428 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
429 | bool caseSensitive = true, bool exactWordMatch = true, | 429 | bool caseSensitive = true, bool exactWordMatch = true, |
430 | bool sortByLvp = false); | 430 | bool sortByLvp = false); |
431 | /** see the above funtion. This function allows to set the category by name. */ | 431 | /** see the above funtion. This function allows to set the category by name. */ |
432 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, | 432 | void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn, |
433 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, | 433 | vector<unsigned int> *foundPositions, bool breakAfterFound = false, |
434 | bool caseSensitive = true, bool exactWordMatch = true, | 434 | bool caseSensitive = true, bool exactWordMatch = true, |
435 | bool sortByLvp = false); | 435 | bool sortByLvp = false); |
436 | /** returns number of entries */ | 436 | /** returns number of entries */ |
437 | unsigned int numEntries(const QString &category); | 437 | unsigned int numEntries(const QString &category); |
438 | unsigned int numEntries(unsigned int category) | 438 | unsigned int numEntries(unsigned int category) |
439 | { return dta[category].d.size(); } | 439 | { return dta[category].d.size(); } |
440 | /** returns number of categories */ | 440 | /** returns number of categories */ |
441 | unsigned int numCategories() | 441 | unsigned int numCategories() |
442 | { return dta.size(); } | 442 | { return dta.size(); } |
443 | /** returns the name of the category at "index" */ | 443 | /** returns the name of the category at "index" */ |
444 | const string* getCategory(unsigned int index) | 444 | const string* getCategory(unsigned int index) |
445 | { return (&(dta[index].name)); } | 445 | { return (&(dta[index].name)); } |
446 | /** returns the data of item at "index". | 446 | /** returns the data of item at "index". |
447 | * It unlocks the entry if it's locked and unlockIfLocked is true. | 447 | * It unlocks the entry if it's locked and unlockIfLocked is true. |
448 | * If the entry is locked, but unlockIfLocked is false, it'll not return | 448 | * If the entry is locked, but unlockIfLocked is false, it'll not return |
449 | * the pw. | 449 | * the pw. |
450 | */ | 450 | */ |
451 | bool getEntry(const QString &category, unsigned int index, | 451 | bool getEntry(const QString &category, unsigned int index, |
452 | PwMDataItem *d, bool unlockIfLocked = false); | 452 | PwMDataItem *d, bool unlockIfLocked = false); |
453 | bool getEntry(unsigned int category, unsigned int index, | 453 | bool getEntry(unsigned int category, unsigned int index, |
454 | PwMDataItem *d, bool unlockIfLocked = false); | 454 | PwMDataItem *d, bool unlockIfLocked = false); |
455 | /** returns the comment-string by looking at the category | 455 | /** returns the comment-string by looking at the category |
456 | * and the listViewPos | 456 | * and the listViewPos |
457 | */ | 457 | */ |
458 | PwMerror getCommentByLvp(const QString &category, int listViewPos, | 458 | PwMerror getCommentByLvp(const QString &category, int listViewPos, |
459 | string *foundComment); | 459 | string *foundComment); |
460 | /** checks if a password is already available. (currentPw) */ | 460 | /** checks if a password is already available. (currentPw) */ |
461 | bool isPwAvailable() | 461 | bool isPwAvailable() |
462 | { return (currentPw != ""); } | 462 | { return (currentPw != ""); } |
463 | /** un/lock entry at "index". If needed, ask for password. */ | 463 | /** un/lock entry at "index". If needed, ask for password. */ |
464 | bool lockAt(const QString &category, unsigned int index, | 464 | bool lockAt(const QString &category, unsigned int index, |
465 | bool lock = true); | 465 | bool lock = true); |
466 | bool lockAt(unsigned int category, unsigned int index, | 466 | bool lockAt(unsigned int category, unsigned int index, |
467 | bool lock = true); | 467 | bool lock = true); |
468 | /** returns the lock-status at "index" */ | 468 | /** returns the lock-status at "index" */ |
469 | bool isLocked(const QString &category, unsigned int index); | 469 | bool isLocked(const QString &category, unsigned int index); |
470 | bool isLocked(unsigned int category, unsigned int index) | 470 | bool isLocked(unsigned int category, unsigned int index) |
471 | { return dta[category].d[index].lockStat; } | 471 | { return dta[category].d[index].lockStat; } |
472 | /** returns the deeplock status */ | 472 | /** returns the deeplock status */ |
473 | bool isDeepLocked() | 473 | bool isDeepLocked() |
474 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } | 474 | { return getDocStatFlag(DOC_STAT_DEEPLOCKED); } |
475 | /** (un)lock all entries */ | 475 | /** (un)lock all entries */ |
476 | bool lockAll(bool lock); | 476 | bool lockAll(bool lock); |
477 | /** unlocks all entries tempoarly. | 477 | /** unlocks all entries tempoarly. |
478 | * 1st NOTE: Be very careful with this function! :) | 478 | * 1st NOTE: Be very careful with this function! :) |
479 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , | 479 | * 2nd NOTE: After you have called unlockAll_Tempoary(); , |
480 | * please DON'T forget to call unlockAll_Tempoary(true); | 480 | * please DON'T forget to call unlockAll_Tempoary(true); |
481 | * _before_ the user (or someone else) is able to change | 481 | * _before_ the user (or someone else) is able to change |
482 | * the document! | 482 | * the document! |
483 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary | 483 | * 3rd NOTE: Please DON'T change "dta" while the data is tempoary |
484 | * unlocked! This will cause corruption. | 484 | * unlocked! This will cause corruption. |
485 | */ | 485 | */ |
486 | bool unlockAll_tempoary(bool revert = false); | 486 | bool unlockAll_tempoary(bool revert = false); |
487 | /** deep-(un)locks the document. | 487 | /** deep-(un)locks the document. |
488 | * deep-locking writes all data to the file, deletes all data | 488 | * deep-locking writes all data to the file, deletes all data |
489 | * in memory, but doesn't close the document. | 489 | * in memory, but doesn't close the document. |
490 | * deep-locking is only available, if the user previously saved | 490 | * deep-locking is only available, if the user previously saved |
491 | * the doc to a file (with a password). | 491 | * the doc to a file (with a password). |
492 | * If "saveToFile" is false, it does NOT write the data to the file! | 492 | * If "saveToFile" is false, it does NOT write the data to the file! |
493 | */ | 493 | */ |
494 | PwMerror deepLock(bool lock = true, bool saveToFile = true); | 494 | PwMerror deepLock(bool lock = true, bool saveToFile = true); |
495 | /** is unlockable without pw? */ | 495 | /** is unlockable without pw? */ |
496 | bool unlockWoPw() | 496 | bool unlockWoPw() |
497 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } | 497 | { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); } |
498 | /** get the "currentPassword" */ | 498 | /** get the "currentPassword" */ |
499 | const QString& getCurrentPw() | 499 | const QString& getCurrentPw() |
500 | { return currentPw; } | 500 | { return currentPw; } |
501 | /** open a window and request the user to change the mpw */ | 501 | /** open a window and request the user to change the mpw */ |
502 | void changeCurrentPw(); | 502 | void changeCurrentPw(); |
503 | /** set the "listViewPos" variable of "dta" */ | 503 | /** set the "listViewPos" variable of "dta" */ |
504 | void setListViewPos(const QString &category, unsigned int index, | 504 | void setListViewPos(const QString &category, unsigned int index, |
505 | int pos); | 505 | int pos); |
506 | /** set the "listViewPos" variable of "dta" */ | 506 | /** set the "listViewPos" variable of "dta" */ |
507 | void setListViewPos(unsigned int category, unsigned int index, | 507 | void setListViewPos(unsigned int category, unsigned int index, |
508 | int pos); | 508 | int pos); |
509 | /** get the "listViewPos" variable of "dta" */ | 509 | /** get the "listViewPos" variable of "dta" */ |
510 | int getListViewPos(const QString &category, unsigned int index); | 510 | int getListViewPos(const QString &category, unsigned int index); |
511 | /** set the maximum number of entries allowed */ | 511 | /** set the maximum number of entries allowed */ |
512 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) | 512 | void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES) |
513 | { maxEntries = num; } | 513 | { maxEntries = num; } |
514 | /** get the maximum number of entries allowed */ | 514 | /** get the maximum number of entries allowed */ |
515 | unsigned int getMaxNumEntries() | 515 | unsigned int getMaxNumEntries() |
516 | { return maxEntries; } | 516 | { return maxEntries; } |
517 | /** ensure all listViewPos of all dta items are set. (are ! -1). | 517 | /** ensure all listViewPos of all dta items are set. (are ! -1). |
518 | * If there are some undefined entries, add them to the end of | 518 | * If there are some undefined entries, add them to the end of |
519 | * the listViewPos(itions). */ | 519 | * the listViewPos(itions). */ |
520 | void ensureLvp(); | 520 | void ensureLvp(); |
521 | /** execute the "launcher" of this entry */ | 521 | /** execute the "launcher" of this entry */ |
522 | bool execLauncher(const QString &category, unsigned int entryIndex); | 522 | bool execLauncher(const QString &category, unsigned int entryIndex); |
523 | /** see above */ | 523 | /** see above */ |
524 | bool execLauncher(unsigned int category, unsigned int entryIndex); | 524 | bool execLauncher(unsigned int category, unsigned int entryIndex); |
525 | /** open a browser with the URL-section of the given entry */ | 525 | /** open a browser with the URL-section of the given entry */ |
526 | bool goToURL(const QString &category, unsigned int entryIndex); | 526 | bool goToURL(const QString &category, unsigned int entryIndex); |
527 | /** see above */ | 527 | /** see above */ |
528 | bool goToURL(unsigned int category, unsigned int entryIndex); | 528 | bool goToURL(unsigned int category, unsigned int entryIndex); |
529 | /** returns true if there is no entry present in the document. | 529 | /** returns true if there is no entry present in the document. |
530 | * Note: The "default" Category is present everytime, so | 530 | * Note: The "default" Category is present everytime, so |
531 | * it's checked for it's entries. | 531 | * it's checked for it's entries. |
532 | */ | 532 | */ |
533 | bool isDocEmpty() | 533 | bool isDocEmpty() |
534 | { | 534 | { |
535 | if (numCategories() > 1) | 535 | if (numCategories() > 1) |
536 | return false; | 536 | return false; |
537 | if (numEntries(0)) | 537 | if (numEntries(0)) |
538 | return false; | 538 | return false; |
539 | return true; | 539 | return true; |
540 | } | 540 | } |
541 | /** returns the filename of this doc */ | 541 | /** returns the filename of this doc */ |
542 | const QString& getFilename() | 542 | const QString& getFilename() |
543 | { return filename; } | 543 | { return filename; } |
544 | /** returns the title of the doc */ | 544 | /** returns the title of the doc */ |
545 | QString getTitle(); | 545 | QString getTitle(); |
546 | /** sets the list-view-pointer hold in the doc */ | 546 | /** sets the list-view-pointer hold in the doc */ |
547 | void setListViewPointer(PwMView *_listView) | 547 | void setListViewPointer(PwMView *_listView) |
548 | { listView = _listView; } | 548 | { listView = _listView; } |
549 | /** returns the list-view-pointer */ | 549 | /** returns the list-view-pointer */ |
550 | PwMView * getListViewPointer() | 550 | PwMView * getListViewPointer() |
551 | { return listView; } | 551 | { return listView; } |
552 | /** try to delete the doc. The user may be asked to save | 552 | /** try to delete the doc. The user may be asked to save |
553 | * the data. The user may cancel the whole operation. | 553 | * the data. The user may cancel the whole operation. |
554 | * false is returned, then. | 554 | * false is returned, then. |
555 | */ | 555 | */ |
556 | bool tryDelete(); | 556 | bool tryDelete(); |
557 | /** is the doc deleted? (with tryDelete() ) */ | 557 | /** is the doc deleted? (with tryDelete() ) */ |
558 | bool isDeleted() | 558 | bool isDeleted() |
559 | { return deleted; } | 559 | { return deleted; } |
560 | /** returns the document timer object */ | 560 | /** returns the document timer object */ |
561 | DocTimer * timer() | 561 | DocTimer * timer() |
562 | { return _timer; } | 562 | { return _timer; } |
563 | /** get a lock on the dataChanged signal. | 563 | /** get a lock on the dataChanged signal. |
564 | * If someone is holding a lock, the signal is not emitted. | 564 | * If someone is holding a lock, the signal is not emitted. |
565 | */ | 565 | */ |
566 | void getDataChangedLock() | 566 | void getDataChangedLock() |
567 | { ++dataChangedLock; } | 567 | { ++dataChangedLock; } |
568 | /** put the dataChanged lock */ | 568 | /** put the dataChanged lock */ |
569 | void putDataChangedLock() | 569 | void putDataChangedLock() |
570 | { --dataChangedLock; } | 570 | { --dataChangedLock; } |
571 | /** returns the revision count of the item at cat/index */ | 571 | /** returns the revision count of the item at cat/index */ |
572 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) | 572 | unsigned int getEntryRevCnt(unsigned int category, unsigned int index) |
573 | { return dta[category].d[index].rev; } | 573 | { return dta[category].d[index].rev; } |
574 | /** returns a const pointer to the entries meta */ | 574 | /** returns a const pointer to the entries meta */ |
575 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) | 575 | const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) |
576 | { return &(dta[category].d[index].meta); } | 576 | { return &(dta[category].d[index].meta); } |
577 | /** is the entry at "category" "index" a binary entry? */ | 577 | /** is the entry at "category" "index" a binary entry? */ |
578 | bool isBinEntry(unsigned int category, unsigned int index) | 578 | bool isBinEntry(unsigned int category, unsigned int index) |
579 | { return dta[category].d[index].binary; } | 579 | { return dta[category].d[index].binary; } |
580 | 580 | ||
581 | public slots: | 581 | public slots: |
582 | /** wrapper for PwMTray */ | 582 | /** wrapper for PwMTray */ |
583 | void _deepUnlock(); | 583 | void _deepUnlock(); |
584 | 584 | ||
585 | signals: | 585 | signals: |
586 | /** the data of the document has changed and must be updated | 586 | /** the data of the document has changed and must be updated |
587 | * in all views. | 587 | * in all views. |
588 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! | 588 | * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! |
589 | */ | 589 | */ |
590 | void dataChanged(PwMDoc *document); | 590 | void dataChanged(PwMDoc *document); |
591 | /** the document class is going to close. This signal may be | 591 | /** the document class is going to close. This signal may be |
592 | * used to nofify all views, that the user closed the document, | 592 | * used to nofify all views, that the user closed the document, |
593 | * so the views can go down, too. | 593 | * so the views can go down, too. |
594 | */ | 594 | */ |
595 | void docClosed(PwMDoc *document); | 595 | void docClosed(PwMDoc *document); |
596 | /** somebody just opened the document */ | 596 | /** somebody just opened the document */ |
597 | void docOpened(PwMDoc *document); | 597 | void docOpened(PwMDoc *document); |
598 | /** this document object just got created */ | 598 | /** this document object just got created */ |
599 | void docCreated(PwMDoc *document); | 599 | void docCreated(PwMDoc *document); |
600 | 600 | ||
601 | public: | 601 | public: |
602 | /** emit the dataChanged signal after checking for a lock */ | 602 | /** emit the dataChanged signal after checking for a lock */ |
603 | void emitDataChanged(PwMDoc *document) | 603 | void emitDataChanged(PwMDoc *document) |
604 | { | 604 | { |
605 | if (!dataChangedLock) | 605 | if (!dataChangedLock) |
606 | emit dataChanged(document); | 606 | emit dataChanged(document); |
607 | } | 607 | } |
608 | 608 | ||
609 | protected: | 609 | protected: |
610 | /** current file for this doc */ | 610 | /** current file for this doc */ |
611 | QString filename; | 611 | QString filename; |
612 | /** holds all data */ | 612 | /** holds all data */ |
613 | vector<PwMCategoryItem> dta; | 613 | vector<PwMCategoryItem> dta; |
614 | /** maximum number of entries */ | 614 | /** maximum number of entries */ |
615 | unsigned int maxEntries; | 615 | unsigned int maxEntries; |
616 | /** currently used password to encrypt data */ | 616 | /** currently used password to encrypt data */ |
617 | QString currentPw; | 617 | QString currentPw; |
618 | /** current global document status flags */ | 618 | /** current global document status flags */ |
619 | unsigned int curDocStat; | 619 | unsigned int curDocStat; |
620 | /** browser process for goToURL() */ | 620 | /** browser process for goToURL() */ |
621 | KProcess browserProc; | 621 | KProcess browserProc; |
622 | /** pointer to the list-view, using this document. | 622 | /** pointer to the list-view, using this document. |
623 | * As there can only be one list-view per doc, we | 623 | * As there can only be one list-view per doc, we |
624 | * don't need a list here. | 624 | * don't need a list here. |
625 | */ | 625 | */ |
626 | PwMView *listView; | 626 | PwMView *listView; |
627 | /** unnamedNum is used to store the "unnamed counter" | 627 | /** unnamedNum is used to store the "unnamed counter" |
628 | * for this document, while it's unnamed. If it's 0, | 628 | * for this document, while it's unnamed. If it's 0, |
629 | * we have to get a new unique one. | 629 | * we have to get a new unique one. |
630 | */ | 630 | */ |
631 | unsigned int unnamedNum; | 631 | unsigned int unnamedNum; |
632 | /** is this doc going to be deleted (executing in destructor context) */ | 632 | /** is this doc going to be deleted (executing in destructor context) */ |
633 | bool deleted; | 633 | bool deleted; |
634 | /** document timer */ | 634 | /** document timer */ |
635 | DocTimer *_timer; | 635 | DocTimer *_timer; |
636 | /** lock counter for the "dataChanged" signal */ | 636 | /** lock counter for the "dataChanged" signal */ |
637 | unsigned int dataChangedLock; | 637 | unsigned int dataChangedLock; |
638 | 638 | ||
639 | /** list of all open documents */ | 639 | /** list of all open documents */ |
640 | static PwMDocList openDocList; | 640 | static PwMDocList openDocList; |
641 | 641 | ||
642 | protected: | 642 | protected: |
643 | /** serialize "dta" and return it in "d". */ | 643 | /** serialize "dta" and return it in "d". */ |
644 | bool serializeDta(string *d); | 644 | bool serializeDta(string *d); |
645 | /** de-serialize "d" and overwrite "dta" */ | 645 | /** de-serialize "d" and overwrite "dta" */ |
646 | bool deSerializeDta(const string *d, bool entriesLocked); | 646 | bool deSerializeDta(const string *d, bool entriesLocked); |
647 | /** write header to file */ | 647 | /** write header to file */ |
648 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 648 | PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
649 | QString *pw, QFile *f); | 649 | QString *pw, QFile *f); |
650 | /** write data-hash to file */ | 650 | /** write data-hash to file */ |
651 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); | 651 | PwMerror writeDataHash(char dataHash, string *d, QFile *f); |
652 | /** check header. Read header info and verify key-hash and filever. | 652 | /** check header. Read header info and verify key-hash and filever. |
653 | * returns length of header in "headerLength" */ | 653 | * returns length of header in "headerLength" */ |
654 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, | 654 | PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, |
655 | unsigned int *headerLength, char *dataHashType, | 655 | unsigned int *headerLength, char *dataHashType, |
656 | string *dataHash, QFile *f); | 656 | string *dataHash, QFile *f); |
657 | /** check the data-hash */ | 657 | /** check the data-hash */ |
658 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); | 658 | PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); |
659 | /** encrypt data "d" and write to "filename" */ | 659 | /** encrypt data "d" and write to "filename" */ |
660 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); | 660 | PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); |
661 | /** read data from file beginning at "pos", decrypt and return it */ | 661 | /** read data from file beginning at "pos", decrypt and return it */ |
662 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); | 662 | PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); |
663 | /** compress the data */ | 663 | /** compress the data */ |
664 | bool compressDta(string *d, char algo); | 664 | bool compressDta(string *d, char algo); |
665 | /** uncompress the data */ | 665 | /** uncompress the data */ |
666 | bool decompressDta(string *d, char algo); | 666 | bool decompressDta(string *d, char algo); |
667 | /** internal import function for a text-file generated by PwM. | 667 | /** internal import function for a text-file generated by PwM. |
668 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ | 668 | * If this is not a valid PwM-exported file, it returns e_fileFormat */ |
669 | PwMerror importText_PwM(const QString *file); | 669 | PwMerror importText_PwM(const QString *file); |
670 | /** PwM-text-import helper function to extract the name/pw/comment out | 670 | /** PwM-text-import helper function to extract the name/pw/comment out |
671 | * of one entry-line */ | 671 | * of one entry-line */ |
672 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); | 672 | bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); |
673 | /** compare two strings */ | 673 | /** compare two strings */ |
674 | bool compareString(const string &s1, const string &s2, bool caseSensitive, | 674 | bool compareString(const string &s1, const string &s2, bool caseSensitive, |
675 | bool exactWordMatch); | 675 | bool exactWordMatch); |
676 | /** clears all document-data */ | 676 | /** clears all document-data */ |
677 | void clearDoc(); | 677 | void clearDoc(); |
678 | /** delete all empty categories */ | 678 | /** delete all empty categories */ |
679 | void delAllEmptyCat(bool dontFlagDirty); | 679 | void delAllEmptyCat(bool dontFlagDirty); |
680 | /** set a document status flag */ | 680 | /** set a document status flag */ |
681 | void setDocStatFlag(unsigned int statFlag) | 681 | void setDocStatFlag(unsigned int statFlag) |
682 | { curDocStat |= statFlag; } | 682 | { curDocStat |= statFlag; } |
683 | /** unset a document status flag */ | 683 | /** unset a document status flag */ |
684 | void unsetDocStatFlag(unsigned int statFlag) | 684 | void unsetDocStatFlag(unsigned int statFlag) |
685 | { curDocStat &= ~statFlag; } | 685 | { curDocStat &= ~statFlag; } |
686 | /** get a document status flag */ | 686 | /** get a document status flag */ |
687 | bool getDocStatFlag(unsigned int statFlag) const | 687 | bool getDocStatFlag(unsigned int statFlag) const |
688 | { return (curDocStat & statFlag); } | 688 | { return (curDocStat & statFlag); } |
689 | /** set the "currentPassword" */ | 689 | /** set the "currentPassword" */ |
690 | void setCurrentPw(const QString &pw) | 690 | void setCurrentPw(const QString &pw) |
691 | { | 691 | { |
692 | currentPw = pw; | 692 | currentPw = pw; |
693 | setDocStatFlag(DOC_STAT_DISK_DIRTY); | 693 | setDocStatFlag(DOC_STAT_DISK_DIRTY); |
694 | } | 694 | } |
695 | /** make a backup-copy of the given file */ | 695 | /** make a backup-copy of the given file */ |
696 | bool backupFile(const QString &filePath); | 696 | bool backupFile(const QString &filePath); |
697 | /** copy a file from src to dst */ | 697 | /** copy a file from src to dst */ |
698 | bool copyFile(const QString &src, const QString &dst); | 698 | bool copyFile(const QString &src, const QString &dst); |
699 | }; | 699 | }; |
700 | 700 | ||
701 | #endif | 701 | #endif |
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp index b308b40..3993fa8 100644 --- a/pwmanager/pwmanager/pwmdocui.cpp +++ b/pwmanager/pwmanager/pwmdocui.cpp | |||
@@ -1,453 +1,454 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmdocui.h" | 20 | #include "pwmdocui.h" |
21 | #include "setmasterpwwndimpl.h" | 21 | #include "setmasterpwwndimpl.h" |
22 | #include "getmasterpwwndimpl.h" | 22 | #include "getmasterpwwndimpl.h" |
23 | #include "pwmexception.h" | 23 | #include "pwmexception.h" |
24 | #include "getkeycardwnd.h" | 24 | #include "getkeycardwnd.h" |
25 | #include "pwm.h" | 25 | #include "pwm.h" |
26 | #include "globalstuff.h" | 26 | #include "globalstuff.h" |
27 | #include "spinforsignal.h" | 27 | #include "spinforsignal.h" |
28 | 28 | ||
29 | #include <qlineedit.h> | 29 | #include <qlineedit.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | 31 | ||
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <kfiledialog.h> | 33 | #include <kfiledialog.h> |
34 | 34 | ||
35 | #ifndef PWM_EMBEDDED | 35 | #ifndef PWM_EMBEDDED |
36 | #include <kwin.h> | 36 | #include <kwin.h> |
37 | #else | 37 | #else |
38 | #include <qdir.h> | 38 | #include <qdir.h> |
39 | #include "pwmprefs.h" | ||
39 | #endif | 40 | #endif |
40 | 41 | ||
41 | 42 | ||
42 | #ifdef CONFIG_KEYCARD | 43 | #ifdef CONFIG_KEYCARD |
43 | # include "pwmkeycard.h" | 44 | # include "pwmkeycard.h" |
44 | #endif | 45 | #endif |
45 | 46 | ||
46 | 47 | ||
47 | PwMDocUi::PwMDocUi(QObject *parent, const char *name) | 48 | PwMDocUi::PwMDocUi(QObject *parent, const char *name) |
48 | : QObject(parent, name) | 49 | : QObject(parent, name) |
49 | { | 50 | { |
50 | currentView = 0; | 51 | currentView = 0; |
51 | keyCard = 0; | 52 | keyCard = 0; |
52 | } | 53 | } |
53 | 54 | ||
54 | PwMDocUi::~PwMDocUi() | 55 | PwMDocUi::~PwMDocUi() |
55 | { | 56 | { |
56 | } | 57 | } |
57 | 58 | ||
58 | QString PwMDocUi::requestMpw(bool chipcard) | 59 | QString PwMDocUi::requestMpw(bool chipcard) |
59 | { | 60 | { |
60 | QString pw; | 61 | QString pw; |
61 | 62 | ||
62 | if (chipcard) { | 63 | if (chipcard) { |
63 | #ifdef CONFIG_KEYCARD | 64 | #ifdef CONFIG_KEYCARD |
64 | PWM_ASSERT(keyCard); | 65 | PWM_ASSERT(keyCard); |
65 | uint32_t id; | 66 | uint32_t id; |
66 | string ret; | 67 | string ret; |
67 | SpinForSignal *spinner = keyCard->getSpinner(); | 68 | SpinForSignal *spinner = keyCard->getSpinner(); |
68 | connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), | 69 | connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), |
69 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); | 70 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); |
70 | keyCard->getKey(); | 71 | keyCard->getKey(); |
71 | spinner->spin(&id, &ret); | 72 | spinner->spin(&id, &ret); |
72 | disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), | 73 | disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)), |
73 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); | 74 | spinner, SLOT(u32_str_slot(uint32_t, const string &))); |
74 | if (ret == "") | 75 | if (ret == "") |
75 | return ""; | 76 | return ""; |
76 | pw = ret.c_str(); | 77 | pw = ret.c_str(); |
77 | #else // CONFIG_KEYCARD | 78 | #else // CONFIG_KEYCARD |
78 | no_keycard_support_msg_box(currentView); | 79 | no_keycard_support_msg_box(currentView); |
79 | #endif // CONFIG_KEYCARD | 80 | #endif // CONFIG_KEYCARD |
80 | } else { | 81 | } else { |
81 | GetMasterPwWndImpl pwWnd; | 82 | GetMasterPwWndImpl pwWnd; |
82 | #ifndef PWM_EMBEDDED | 83 | #ifndef PWM_EMBEDDED |
83 | KWin::setState(pwWnd.winId(), NET::StaysOnTop); | 84 | KWin::setState(pwWnd.winId(), NET::StaysOnTop); |
84 | #endif | 85 | #endif |
85 | if (pwWnd.exec() != 1) | 86 | if (pwWnd.exec() != 1) |
86 | return ""; | 87 | return ""; |
87 | pw = pwWnd.pwLineEdit->text(); | 88 | pw = pwWnd.pwLineEdit->text(); |
88 | } | 89 | } |
89 | 90 | ||
90 | return pw; | 91 | return pw; |
91 | } | 92 | } |
92 | 93 | ||
93 | QString PwMDocUi::requestNewMpw(bool *chipcard) | 94 | QString PwMDocUi::requestNewMpw(bool *chipcard) |
94 | { | 95 | { |
95 | QString pw; | 96 | QString pw; |
96 | SetMasterPwWndImpl pwWnd(currentView); | 97 | SetMasterPwWndImpl pwWnd(currentView); |
97 | pwWnd.setPwMKeyCard(keyCard); | 98 | pwWnd.setPwMKeyCard(keyCard); |
98 | #ifndef PWM_EMBEDDED | 99 | #ifndef PWM_EMBEDDED |
99 | if (!chipcard) { | 100 | if (!chipcard) { |
100 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); | 101 | pwWnd.mainTab->removePage(pwWnd.mainTab->page(1)); |
101 | } | 102 | } |
102 | #else | 103 | #else |
103 | qDebug("PwMDocUi::requestNewMpw must be implemented"); | 104 | qDebug("PwMDocUi::requestNewMpw must be implemented"); |
104 | #endif | 105 | #endif |
105 | 106 | ||
106 | if (pwWnd.exec() != 1) | 107 | if (pwWnd.exec() != 1) |
107 | return ""; | 108 | return ""; |
108 | pw = pwWnd.getPw(chipcard).c_str(); | 109 | pw = pwWnd.getPw(chipcard).c_str(); |
109 | 110 | ||
110 | return pw; | 111 | return pw; |
111 | } | 112 | } |
112 | 113 | ||
113 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) | 114 | QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard) |
114 | { | 115 | { |
115 | QString pw(requestMpw(*chipcard)); | 116 | QString pw(requestMpw(*chipcard)); |
116 | if (pw == "") | 117 | if (pw == "") |
117 | return ""; | 118 | return ""; |
118 | if (pw != *currentPw) { | 119 | if (pw != *currentPw) { |
119 | wrongMpwMsgBox(*chipcard); | 120 | wrongMpwMsgBox(*chipcard); |
120 | return ""; | 121 | return ""; |
121 | } | 122 | } |
122 | 123 | ||
123 | pw = requestNewMpw(chipcard); | 124 | pw = requestNewMpw(chipcard); |
124 | if (pw == "") | 125 | if (pw == "") |
125 | return ""; | 126 | return ""; |
126 | return pw; | 127 | return pw; |
127 | } | 128 | } |
128 | 129 | ||
129 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 130 | void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
130 | { | 131 | { |
131 | QString msg; | 132 | QString msg; |
132 | if (prefix != "") { | 133 | if (prefix != "") { |
133 | msg += prefix; | 134 | msg += prefix; |
134 | msg += "\n"; | 135 | msg += "\n"; |
135 | } | 136 | } |
136 | 137 | ||
137 | if (chipcard) { | 138 | if (chipcard) { |
138 | msg += i18n("Wrong key-card!\n" | 139 | msg += i18n("Wrong key-card!\n" |
139 | "Please try again with the " | 140 | "Please try again with the " |
140 | "correct key-card."); | 141 | "correct key-card."); |
141 | } else { | 142 | } else { |
142 | msg += i18n("Wrong master-password!\n" | 143 | msg += i18n("Wrong master-password!\n" |
143 | "Please try again."); | 144 | "Please try again."); |
144 | } | 145 | } |
145 | 146 | ||
146 | if (postfix != "") { | 147 | if (postfix != "") { |
147 | msg += "\n"; | 148 | msg += "\n"; |
148 | msg += postfix; | 149 | msg += postfix; |
149 | } | 150 | } |
150 | KMessageBox::error(currentView, msg, | 151 | KMessageBox::error(currentView, msg, |
151 | (chipcard) ? (i18n("wrong chipcard")) | 152 | (chipcard) ? (i18n("wrong chipcard")) |
152 | : (i18n("password error"))); | 153 | : (i18n("password error"))); |
153 | } | 154 | } |
154 | 155 | ||
155 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) | 156 | void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix) |
156 | { | 157 | { |
157 | QString msg; | 158 | QString msg; |
158 | if (prefix != "") { | 159 | if (prefix != "") { |
159 | msg += prefix; | 160 | msg += prefix; |
160 | msg += "\n"; | 161 | msg += "\n"; |
161 | } | 162 | } |
162 | 163 | ||
163 | if (chipcard) { | 164 | if (chipcard) { |
164 | msg += i18n("No key-card found!\n" | 165 | msg += i18n("No key-card found!\n" |
165 | "Please insert the " | 166 | "Please insert the " |
166 | "correct key-card."); | 167 | "correct key-card."); |
167 | } else { | 168 | } else { |
168 | msg += i18n("No master-password given!"); | 169 | msg += i18n("No master-password given!"); |
169 | } | 170 | } |
170 | 171 | ||
171 | if (postfix != "") { | 172 | if (postfix != "") { |
172 | msg += "\n"; | 173 | msg += "\n"; |
173 | msg += postfix; | 174 | msg += postfix; |
174 | } | 175 | } |
175 | KMessageBox::error(currentView, msg, | 176 | KMessageBox::error(currentView, msg, |
176 | (chipcard) ? (i18n("no chipcard")) | 177 | (chipcard) ? (i18n("no chipcard")) |
177 | : (i18n("password error"))); | 178 | : (i18n("password error"))); |
178 | } | 179 | } |
179 | 180 | ||
180 | void PwMDocUi::rootAlertMsgBox() | 181 | void PwMDocUi::rootAlertMsgBox() |
181 | { | 182 | { |
182 | KMessageBox::error(currentView, | 183 | KMessageBox::error(currentView, |
183 | i18n("This feature is not available, " | 184 | i18n("This feature is not available, " |
184 | "if you execute PwM with \"root\" " | 185 | "if you execute PwM with \"root\" " |
185 | "UID 0 privileges, for security reasons!"), | 186 | "UID 0 privileges, for security reasons!"), |
186 | i18n("not allowed as root!")); | 187 | i18n("not allowed as root!")); |
187 | } | 188 | } |
188 | 189 | ||
189 | void PwMDocUi::cantDeeplock_notSavedMsgBox() | 190 | void PwMDocUi::cantDeeplock_notSavedMsgBox() |
190 | { | 191 | { |
191 | KMessageBox::error(currentView, | 192 | KMessageBox::error(currentView, |
192 | i18n("Can't deep-lock, because the document " | 193 | i18n("Can't deep-lock, because the document " |
193 | "hasn't been saved, yet. Please save " | 194 | "hasn't been saved, yet. Please save " |
194 | "to a file and try again."), | 195 | "to a file and try again."), |
195 | i18n("not saved, yet")); | 196 | i18n("not saved, yet")); |
196 | } | 197 | } |
197 | 198 | ||
198 | void PwMDocUi::gpmPwLenErrMsgBox() | 199 | void PwMDocUi::gpmPwLenErrMsgBox() |
199 | { | 200 | { |
200 | KMessageBox::error(currentView, | 201 | KMessageBox::error(currentView, |
201 | i18n("GPasman does not support passwords " | 202 | i18n("GPasman does not support passwords " |
202 | "shorter than 4 characters! Please try " | 203 | "shorter than 4 characters! Please try " |
203 | "again with a longer password."), | 204 | "again with a longer password."), |
204 | i18n("password too short")); | 205 | i18n("password too short")); |
205 | } | 206 | } |
206 | 207 | ||
207 | int PwMDocUi::dirtyAskSave(const QString &docTitle) | 208 | int PwMDocUi::dirtyAskSave(const QString &docTitle) |
208 | { | 209 | { |
209 | int ret; | 210 | int ret; |
210 | #ifndef PWM_EMBEDDED | 211 | #ifndef PWM_EMBEDDED |
211 | ret = KMessageBox::questionYesNoCancel(currentView, | 212 | ret = KMessageBox::questionYesNoCancel(currentView, |
212 | i18n("The list \"") + | 213 | i18n("The list \"") + |
213 | docTitle + | 214 | docTitle + |
214 | i18n | 215 | i18n |
215 | ("\" has been modified.\n" | 216 | ("\" has been modified.\n" |
216 | "Do you want to save it?"), | 217 | "Do you want to save it?"), |
217 | i18n("save?")); | 218 | i18n("save?")); |
218 | if (ret == KMessageBox::Yes) { | 219 | if (ret == KMessageBox::Yes) { |
219 | return 0; | 220 | return 0; |
220 | } else if (ret == KMessageBox::No) { | 221 | } else if (ret == KMessageBox::No) { |
221 | return 1; | 222 | return 1; |
222 | } | 223 | } |
223 | #else | 224 | #else |
224 | ret = KMessageBox::warningYesNoCancel(currentView, | 225 | ret = KMessageBox::warningYesNoCancel(currentView, |
225 | i18n("The list \"") + | 226 | i18n("The list \"") + |
226 | docTitle + | 227 | docTitle + |
227 | i18n | 228 | i18n |
228 | ("\" has been modified.\n" | 229 | ("\" has been modified.\n" |
229 | "Do you want to save it?"), | 230 | "Do you want to save it?"), |
230 | i18n("save?")); | 231 | i18n("save?")); |
231 | if (ret == KMessageBox::Yes) { | 232 | if (ret == KMessageBox::Yes) { |
232 | return 0; | 233 | return 0; |
233 | } else if (ret == KMessageBox::No) { | 234 | } else if (ret == KMessageBox::No) { |
234 | return 1; | 235 | return 1; |
235 | } | 236 | } |
236 | 237 | ||
237 | #endif | 238 | #endif |
238 | 239 | ||
239 | // cancel | 240 | // cancel |
240 | return -1; | 241 | return -1; |
241 | } | 242 | } |
242 | 243 | ||
243 | bool PwMDocUi::saveDocUi(PwMDoc *doc) | 244 | bool PwMDocUi::saveDocUi(PwMDoc *doc) |
244 | { | 245 | { |
245 | PWM_ASSERT(doc); | 246 | PWM_ASSERT(doc); |
246 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 247 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
247 | if (doc->isDocEmpty()) { | 248 | if (doc->isDocEmpty()) { |
248 | KMessageBox::information(currentView, | 249 | KMessageBox::information(currentView, |
249 | i18n | 250 | i18n |
250 | ("Sorry, there's nothing to save.\n" | 251 | ("Sorry, there's nothing to save.\n" |
251 | "Please first add some passwords."), | 252 | "Please first add some passwords."), |
252 | i18n("nothing to do")); | 253 | i18n("nothing to do")); |
253 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 254 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
254 | return true; | 255 | return true; |
255 | } | 256 | } |
256 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); | 257 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression()); |
257 | if (ret == e_filename) { | 258 | if (ret == e_filename) { |
258 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 259 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
259 | return saveAsDocUi(doc); | 260 | return saveAsDocUi(doc); |
260 | } else if (ret == e_weakPw) { | 261 | } else if (ret == e_weakPw) { |
261 | KMessageBox::error(currentView, | 262 | KMessageBox::error(currentView, |
262 | i18n("Error: This is a weak password.\n" | 263 | i18n("Error: This is a weak password.\n" |
263 | "Please select another password."), | 264 | "Please select another password."), |
264 | i18n("weak password")); | 265 | i18n("weak password")); |
265 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 266 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
266 | return false; | 267 | return false; |
267 | } else if (ret == e_fileBackup) { | 268 | } else if (ret == e_fileBackup) { |
268 | KMessageBox::error(currentView, | 269 | KMessageBox::error(currentView, |
269 | i18n("Error: Couldn't make backup-file!"), | 270 | i18n("Error: Couldn't make backup-file!"), |
270 | i18n("backup failed")); | 271 | i18n("backup failed")); |
271 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 272 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
272 | return false; | 273 | return false; |
273 | } else if (ret != e_success) { | 274 | } else if (ret != e_success) { |
274 | KMessageBox::error(currentView, | 275 | KMessageBox::error(currentView, |
275 | i18n("Error: Couldn't write to file.\n" | 276 | i18n("Error: Couldn't write to file.\n" |
276 | "Please check if you have permission to " | 277 | "Please check if you have permission to " |
277 | "write to the file in that directory."), | 278 | "write to the file in that directory."), |
278 | i18n("error while writing")); | 279 | i18n("error while writing")); |
279 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 280 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
280 | return false; | 281 | return false; |
281 | } | 282 | } |
282 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 283 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
283 | return true; | 284 | return true; |
284 | } | 285 | } |
285 | 286 | ||
286 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) | 287 | bool PwMDocUi::saveAsDocUi(PwMDoc *doc) |
287 | { | 288 | { |
288 | PWM_ASSERT(doc); | 289 | PWM_ASSERT(doc); |
289 | doc->timer()->getLock(DocTimer::id_autoLockTimer); | 290 | doc->timer()->getLock(DocTimer::id_autoLockTimer); |
290 | if (doc->isDocEmpty()) { | 291 | if (doc->isDocEmpty()) { |
291 | KMessageBox::information(currentView, | 292 | KMessageBox::information(currentView, |
292 | i18n | 293 | i18n |
293 | ("Sorry, there's nothing to save.\n" | 294 | ("Sorry, there's nothing to save.\n" |
294 | "Please first add some passwords."), | 295 | "Please first add some passwords."), |
295 | i18n("nothing to do")); | 296 | i18n("nothing to do")); |
296 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 297 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
297 | return true; | 298 | return true; |
298 | } | 299 | } |
299 | #ifndef PWM_EMBEDDED | 300 | #ifndef PWM_EMBEDDED |
300 | QString fn(KFileDialog::getSaveFileName(QString::null, | 301 | QString fn(KFileDialog::getSaveFileName(QString::null, |
301 | i18n("*.pwm|PwManager Password file"), | 302 | i18n("*.pwm|PwManager Password file"), |
302 | currentView)); | 303 | currentView)); |
303 | #else | 304 | #else |
304 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); | 305 | QString fn = locateLocal( "data", KGlobal::getAppName() + "/*.pwm" ); |
305 | fn = KFileDialog::getSaveFileName(fn, | 306 | fn = KFileDialog::getSaveFileName(fn, |
306 | i18n("password filename(*.pwm)"), | 307 | i18n("password filename(*.pwm)"), |
307 | currentView); | 308 | currentView); |
308 | 309 | ||
309 | #endif | 310 | #endif |
310 | if (fn == "") { | 311 | if (fn == "") { |
311 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 312 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
312 | return false; | 313 | return false; |
313 | } | 314 | } |
314 | if (fn.right(4) != ".pwm") | 315 | if (fn.right(4) != ".pwm") |
315 | fn += ".pwm"; | 316 | fn += ".pwm"; |
316 | 317 | ||
317 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); | 318 | PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn); |
318 | if (ret != e_success) { | 319 | if (ret != e_success) { |
319 | KMessageBox::error(currentView, | 320 | KMessageBox::error(currentView, |
320 | i18n("Error: Couldn't write to file.\n" | 321 | i18n("Error: Couldn't write to file.\n" |
321 | "Please check if you have permission to " | 322 | "Please check if you have permission to " |
322 | "write to the file in that directory."), | 323 | "write to the file in that directory."), |
323 | i18n("error while writing")); | 324 | i18n("error while writing")); |
324 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 325 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
325 | return false; | 326 | return false; |
326 | } | 327 | } |
327 | doc->timer()->putLock(DocTimer::id_autoLockTimer); | 328 | doc->timer()->putLock(DocTimer::id_autoLockTimer); |
328 | return true; | 329 | return true; |
329 | } | 330 | } |
330 | 331 | ||
331 | bool PwMDocUi::openDocUi(PwMDoc *doc, | 332 | bool PwMDocUi::openDocUi(PwMDoc *doc, |
332 | QString filename, | 333 | QString filename, |
333 | bool openDeepLocked) | 334 | bool openDeepLocked) |
334 | { | 335 | { |
335 | if (filename.isEmpty()) | 336 | if (filename.isEmpty()) |
336 | { | 337 | { |
337 | #ifndef PWM_EMBEDDED | 338 | #ifndef PWM_EMBEDDED |
338 | filename = KFileDialog::getOpenFileName(QString::null, | 339 | filename = KFileDialog::getOpenFileName(QString::null, |
339 | i18n("*.pwm|PwManager Password file\n" | 340 | i18n("*.pwm|PwManager Password file\n" |
340 | "*|All files"), getCurrentView()); | 341 | "*|All files"), getCurrentView()); |
341 | #else | 342 | #else |
342 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); | 343 | filename = locateLocal( "data", KGlobal::getAppName() + "/*.pwm"); |
343 | filename = KFileDialog::getOpenFileName(filename, | 344 | filename = KFileDialog::getOpenFileName(filename, |
344 | i18n("password filename(*.pwm)"), getCurrentView()); | 345 | i18n("password filename(*.pwm)"), getCurrentView()); |
345 | #endif | 346 | #endif |
346 | } | 347 | } |
347 | if (filename.isEmpty()) | 348 | if (filename.isEmpty()) |
348 | goto cancelOpen; | 349 | goto cancelOpen; |
349 | PwMerror ret; | 350 | PwMerror ret; |
350 | while (true) { | 351 | while (true) { |
351 | int lockStat = -1; | 352 | int lockStat = -1; |
352 | if (openDeepLocked) { | 353 | if (openDeepLocked) { |
353 | lockStat = 2; | 354 | lockStat = 2; |
354 | } else { | 355 | } else { |
355 | if (conf()->confGlobUnlockOnOpen()) { | 356 | if (conf()->confGlobUnlockOnOpen()) { |
356 | lockStat = 0; | 357 | lockStat = 0; |
357 | } else { | 358 | } else { |
358 | lockStat = 1; | 359 | lockStat = 1; |
359 | } | 360 | } |
360 | } | 361 | } |
361 | ret = doc->openDoc(&filename, lockStat); | 362 | ret = doc->openDoc(&filename, lockStat); |
362 | if (ret != e_success) { | 363 | if (ret != e_success) { |
363 | if (ret == e_readFile || ret == e_openFile) { | 364 | if (ret == e_readFile || ret == e_openFile) { |
364 | KMessageBox::error(getCurrentView(), | 365 | KMessageBox::error(getCurrentView(), |
365 | i18n("Could not read file!") | 366 | i18n("Could not read file!") |
366 | + "\n" | 367 | + "\n" |
367 | + filename, | 368 | + filename, |
368 | i18n("file error")); | 369 | i18n("file error")); |
369 | goto cancelOpen; | 370 | goto cancelOpen; |
370 | } | 371 | } |
371 | if (ret == e_alreadyOpen) { | 372 | if (ret == e_alreadyOpen) { |
372 | KMessageBox::error(getCurrentView(), | 373 | KMessageBox::error(getCurrentView(), |
373 | i18n("This file is already open."), | 374 | i18n("This file is already open."), |
374 | i18n("already open")); | 375 | i18n("already open")); |
375 | goto cancelOpen; | 376 | goto cancelOpen; |
376 | } | 377 | } |
377 | if (ret == e_fileVer) { | 378 | if (ret == e_fileVer) { |
378 | KMessageBox::error(getCurrentView(), | 379 | KMessageBox::error(getCurrentView(), |
379 | i18n | 380 | i18n |
380 | ("File-version is not supported!\n" | 381 | ("File-version is not supported!\n" |
381 | "Did you create this file with an older or newer version of PwM?"), | 382 | "Did you create this file with an older or newer version of PwM?"), |
382 | i18n | 383 | i18n |
383 | ("incompatible version")); | 384 | ("incompatible version")); |
384 | goto cancelOpen; | 385 | goto cancelOpen; |
385 | } | 386 | } |
386 | if (ret == e_wrongPw) { | 387 | if (ret == e_wrongPw) { |
387 | continue; | 388 | continue; |
388 | } | 389 | } |
389 | if (ret == e_noPw) { | 390 | if (ret == e_noPw) { |
390 | goto cancelOpen; | 391 | goto cancelOpen; |
391 | } | 392 | } |
392 | if (ret == e_fileFormat) { | 393 | if (ret == e_fileFormat) { |
393 | KMessageBox::error(getCurrentView(), | 394 | KMessageBox::error(getCurrentView(), |
394 | i18n | 395 | i18n |
395 | ("Sorry, this file has not been recognized " | 396 | ("Sorry, this file has not been recognized " |
396 | "as a PwM Password file.\n" | 397 | "as a PwM Password file.\n" |
397 | "Probably you have selected the wrong file."), | 398 | "Probably you have selected the wrong file."), |
398 | i18n | 399 | i18n |
399 | ("no PwM password-file")); | 400 | ("no PwM password-file")); |
400 | goto cancelOpen; | 401 | goto cancelOpen; |
401 | } | 402 | } |
402 | if (ret == e_fileCorrupt) { | 403 | if (ret == e_fileCorrupt) { |
403 | KMessageBox::error(getCurrentView(), | 404 | KMessageBox::error(getCurrentView(), |
404 | i18n | 405 | i18n |
405 | ("File corrupt!\n" | 406 | ("File corrupt!\n" |
406 | "Maybe the media, you stored this file on, " | 407 | "Maybe the media, you stored this file on, " |
407 | "had bad sectors?"), | 408 | "had bad sectors?"), |
408 | i18n | 409 | i18n |
409 | ("checksum error")); | 410 | ("checksum error")); |
410 | goto cancelOpen; | 411 | goto cancelOpen; |
411 | } | 412 | } |
412 | } | 413 | } |
413 | break; | 414 | break; |
414 | } | 415 | } |
415 | return true; | 416 | return true; |
416 | 417 | ||
417 | cancelOpen: | 418 | cancelOpen: |
418 | return false; | 419 | return false; |
419 | } | 420 | } |
420 | 421 | ||
421 | QString PwMDocUi::string_defaultCategory() | 422 | QString PwMDocUi::string_defaultCategory() |
422 | { | 423 | { |
423 | return i18n("Default"); | 424 | return i18n("Default"); |
424 | } | 425 | } |
425 | 426 | ||
426 | QString PwMDocUi::string_locked() | 427 | QString PwMDocUi::string_locked() |
427 | { | 428 | { |
428 | return i18n("<LOCKED>"); | 429 | return i18n("<LOCKED>"); |
429 | } | 430 | } |
430 | 431 | ||
431 | QString PwMDocUi::string_deepLockedShort() | 432 | QString PwMDocUi::string_deepLockedShort() |
432 | { | 433 | { |
433 | return i18n("DEEP-LOCKED"); | 434 | return i18n("DEEP-LOCKED"); |
434 | } | 435 | } |
435 | 436 | ||
436 | QString PwMDocUi::string_deepLockedLong() | 437 | QString PwMDocUi::string_deepLockedLong() |
437 | { | 438 | { |
438 | return i18n("This file is DEEP-LOCKED!\n" | 439 | return i18n("This file is DEEP-LOCKED!\n" |
439 | "That means all data has been encrypted " | 440 | "That means all data has been encrypted " |
440 | "and written out to the file. If you want " | 441 | "and written out to the file. If you want " |
441 | "to see the entries, please UNLOCK the file. " | 442 | "to see the entries, please UNLOCK the file. " |
442 | "While unlocking, you will be prompted for the " | 443 | "While unlocking, you will be prompted for the " |
443 | "master-password or the key-card."); | 444 | "master-password or the key-card."); |
444 | } | 445 | } |
445 | 446 | ||
446 | QString PwMDocUi::string_defaultTitle() | 447 | QString PwMDocUi::string_defaultTitle() |
447 | { | 448 | { |
448 | return i18n("Untitled"); | 449 | return i18n("Untitled"); |
449 | } | 450 | } |
450 | 451 | ||
451 | #ifndef PWM_EMBEDDED | 452 | #ifndef PWM_EMBEDDED |
452 | #include "pwmdocui.moc" | 453 | #include "pwmdocui.moc" |
453 | #endif | 454 | #endif |
diff --git a/pwmanager/pwmanager/pwminit.cpp b/pwmanager/pwmanager/pwminit.cpp index 2f1aa4e..8946443 100644 --- a/pwmanager/pwmanager/pwminit.cpp +++ b/pwmanager/pwmanager/pwminit.cpp | |||
@@ -1,615 +1,632 @@ | |||
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 "pwminit.h" | 20 | #include "pwminit.h" |
21 | #include "configuration.h" | ||
22 | #include "randomizer.h" | 21 | #include "randomizer.h" |
23 | 22 | ||
24 | #ifndef PWM_EMBEDDED | 23 | #ifndef PWM_EMBEDDED |
25 | #include "selftest.h" | 24 | #include "selftest.h" |
25 | #include "configuration.h" | ||
26 | #else | ||
27 | #include "pwmprefs.h" | ||
26 | #endif | 28 | #endif |
27 | 29 | ||
28 | #include "pwm.h" | 30 | #include "pwm.h" |
29 | #include "pwmexception.h" | 31 | #include "pwmexception.h" |
30 | #include "pwmtray.h" | 32 | #include "pwmtray.h" |
31 | #include "pwmdoc.h" | 33 | #include "pwmdoc.h" |
32 | 34 | ||
33 | #ifdef CONFIG_KWALLETIF | 35 | #ifdef CONFIG_KWALLETIF |
34 | # include "kwalletemu.h" | 36 | # include "kwalletemu.h" |
35 | #endif // CONFIG_KWALLETIF | 37 | #endif // CONFIG_KWALLETIF |
36 | #ifdef CONFIG_KEYCARD | 38 | #ifdef CONFIG_KEYCARD |
37 | # include "pwmkeycard.h" | 39 | # include "pwmkeycard.h" |
38 | #endif // CONFIG_KEYCARD | 40 | #endif // CONFIG_KEYCARD |
39 | 41 | ||
40 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
41 | 43 | ||
42 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
43 | #ifndef PWM_EMBEDDED | 45 | #ifndef PWM_EMBEDDED |
44 | #include <kcmdlineargs.h> | 46 | #include <kcmdlineargs.h> |
45 | #include <kwin.h> | 47 | #include <kwin.h> |
46 | #include <dcopclient.h> | 48 | #include <dcopclient.h> |
47 | #endif | 49 | #endif |
48 | 50 | ||
49 | #include <kapplication.h> | 51 | #include <kapplication.h> |
50 | #include <kiconloader.h> | 52 | #include <kiconloader.h> |
51 | 53 | ||
52 | #include <signal.h> | 54 | #include <signal.h> |
53 | 55 | ||
54 | static PwMInit *sig_init_pointer; | 56 | static PwMInit *sig_init_pointer; |
55 | static NOREGPARM void sig_handler(int signum) | 57 | static NOREGPARM void sig_handler(int signum) |
56 | { | 58 | { |
57 | switch (signum) { | 59 | switch (signum) { |
58 | case SIGINT: | 60 | case SIGINT: |
59 | case SIGTERM: | 61 | case SIGTERM: |
60 | sig_init_pointer->shutdownApp(20 + signum); | 62 | sig_init_pointer->shutdownApp(20 + signum); |
61 | break; | 63 | break; |
62 | default: | 64 | default: |
63 | printDebug(string("unhandled signal ") | 65 | printDebug(string("unhandled signal ") |
64 | + tostr(signum)); | 66 | + tostr(signum)); |
65 | } | 67 | } |
66 | } | 68 | } |
67 | 69 | ||
68 | 70 | ||
69 | 71 | ||
70 | 72 | ||
71 | PwMInit::PwMInit(PwMApplication *_app) | 73 | PwMInit::PwMInit(PwMApplication *_app) |
72 | : runStatus (unknown) | 74 | : runStatus (unknown) |
73 | , _curWidget (0) | 75 | , _curWidget (0) |
74 | , _dcopClient (0) | 76 | , _dcopClient (0) |
75 | , _kwalletEmu (0) | 77 | , _kwalletEmu (0) |
76 | , _keycard (0) | 78 | , _keycard (0) |
77 | , _tray (0) | 79 | , _tray (0) |
78 | { | 80 | { |
79 | sig_init_pointer = this; | 81 | sig_init_pointer = this; |
80 | app = _app; | 82 | app = _app; |
81 | } | 83 | } |
82 | 84 | ||
83 | PwMInit::~PwMInit() | 85 | PwMInit::~PwMInit() |
84 | { | 86 | { |
85 | #ifndef PWM_EMBEDDED | 87 | #ifndef PWM_EMBEDDED |
86 | SelfTest::cancel(); | 88 | SelfTest::cancel(); |
87 | // close all open mainwnds | 89 | // close all open mainwnds |
88 | QValueList<PwM *>::iterator i = _mainWndList.begin(), | 90 | QValueList<PwM *>::iterator i = _mainWndList.begin(), |
89 | end = _mainWndList.end(); | 91 | end = _mainWndList.end(); |
90 | 92 | ||
91 | #else | 93 | #else |
92 | // close all open mainwnds | 94 | // close all open mainwnds |
93 | QValueList<PwM *>::Iterator i = _mainWndList.begin(), | 95 | QValueList<PwM *>::Iterator i = _mainWndList.begin(), |
94 | end = _mainWndList.end(); | 96 | end = _mainWndList.end(); |
95 | #endif | 97 | #endif |
96 | while (i != end) { | 98 | while (i != end) { |
97 | disconnect(*i, SIGNAL(closed(PwM *)), | 99 | disconnect(*i, SIGNAL(closed(PwM *)), |
98 | this, SLOT(mainWndClosed(PwM *))); | 100 | this, SLOT(mainWndClosed(PwM *))); |
99 | delete *i; | 101 | delete *i; |
100 | ++i; | 102 | ++i; |
101 | } | 103 | } |
102 | _mainWndList.clear(); | 104 | _mainWndList.clear(); |
103 | // close all remaining open documents | 105 | // close all remaining open documents |
104 | PwMDocList *_dl = PwMDoc::getOpenDocList(); | 106 | PwMDocList *_dl = PwMDoc::getOpenDocList(); |
105 | vector<PwMDocList::listItem> dl = *(_dl->getList()); | 107 | vector<PwMDocList::listItem> dl = *(_dl->getList()); |
106 | vector<PwMDocList::listItem>::iterator i2 = dl.begin(), | 108 | vector<PwMDocList::listItem>::iterator i2 = dl.begin(), |
107 | end2 = dl.end(); | 109 | end2 = dl.end(); |
108 | while (i2 != end2) { | 110 | while (i2 != end2) { |
109 | delete (*i2).doc; | 111 | delete (*i2).doc; |
110 | ++i2; | 112 | ++i2; |
111 | } | 113 | } |
112 | 114 | ||
113 | #ifdef CONFIG_KWALLETIF | 115 | #ifdef CONFIG_KWALLETIF |
114 | delete_ifnot_null(_kwalletEmu); | 116 | delete_ifnot_null(_kwalletEmu); |
115 | #endif // CONFIG_KWALLETIF | 117 | #endif // CONFIG_KWALLETIF |
116 | #ifdef CONFIG_KEYCARD | 118 | #ifdef CONFIG_KEYCARD |
117 | delete_ifnot_null(_keycard); | 119 | delete_ifnot_null(_keycard); |
118 | #endif // CONFIG_KEYCARD | 120 | #endif // CONFIG_KEYCARD |
119 | delete_ifnot_null(_tray); | 121 | delete_ifnot_null(_tray); |
120 | 122 | ||
121 | Randomizer::cleanup(); | 123 | Randomizer::cleanup(); |
124 | #ifndef PWM_EMBEDDED | ||
122 | Configuration::cleanup(); | 125 | Configuration::cleanup(); |
126 | #endif | ||
123 | } | 127 | } |
124 | 128 | ||
125 | void PwMInit::initializeApp() | 129 | void PwMInit::initializeApp() |
126 | { | 130 | { |
127 | PWM_ASSERT(runStatus == unknown); | 131 | PWM_ASSERT(runStatus == unknown); |
128 | runStatus = init; | 132 | runStatus = init; |
129 | initPosixSignalHandler(); | 133 | initPosixSignalHandler(); |
130 | Randomizer::init(); | 134 | Randomizer::init(); |
135 | #ifndef PWM_EMBEDDED | ||
131 | Configuration::init(); | 136 | Configuration::init(); |
137 | #endif | ||
132 | initDCOP(); | 138 | initDCOP(); |
133 | initKWalletEmu(); | 139 | initKWalletEmu(); |
134 | initKeycard(); | 140 | initKeycard(); |
135 | initTray(); | 141 | initTray(); |
136 | handleCmdLineArgs(); | 142 | handleCmdLineArgs(); |
137 | 143 | ||
138 | bool openDeeplocked = false; | 144 | bool openDeeplocked = false; |
139 | if (conf()->confGlobAutostartDeepLocked() || | 145 | if (conf()->confGlobAutostartDeepLocked() || |
140 | savedCmd.open_deeplocked) | 146 | savedCmd.open_deeplocked) |
141 | openDeeplocked = true; | 147 | openDeeplocked = true; |
142 | if (conf()->confWndAutoMinimizeOnStart() || | 148 | if (conf()->confWndAutoMinimizeOnStart() || |
143 | savedCmd.minToTray) { | 149 | savedCmd.minToTray) { |
144 | PwMDoc *newDoc = createDoc(); | 150 | PwMDoc *newDoc = createDoc(); |
145 | if (!newDoc->openDocUi(newDoc, | 151 | if (!newDoc->openDocUi(newDoc, |
146 | conf()->confGlobAutoStart(), | 152 | conf()->confGlobAutoStart(), |
147 | openDeeplocked)) { | 153 | openDeeplocked)) { |
148 | delete newDoc; | 154 | delete newDoc; |
155 | |||
156 | //US ENH for embedded devices: in the case of failure, open a document the default way | ||
157 | createMainWnd(conf()->confGlobAutoStart(), | ||
158 | openDeeplocked, | ||
159 | true, | ||
160 | 0, | ||
161 | savedCmd.minimized); | ||
162 | |||
163 | |||
164 | |||
165 | |||
149 | } | 166 | } |
150 | } else { | 167 | } else { |
151 | createMainWnd(conf()->confGlobAutoStart(), | 168 | createMainWnd(conf()->confGlobAutoStart(), |
152 | openDeeplocked, | 169 | openDeeplocked, |
153 | true, | 170 | true, |
154 | 0, | 171 | 0, |
155 | savedCmd.minimized); | 172 | savedCmd.minimized); |
156 | } | 173 | } |
157 | 174 | ||
158 | runStatus = running; | 175 | runStatus = running; |
159 | } | 176 | } |
160 | 177 | ||
161 | void PwMInit::shutdownApp(int exitStatus) | 178 | void PwMInit::shutdownApp(int exitStatus) |
162 | { | 179 | { |
163 | printDebug(string("PwMInit::shutdownApp(") | 180 | printDebug(string("PwMInit::shutdownApp(") |
164 | + tostr(exitStatus) + ") called."); | 181 | + tostr(exitStatus) + ") called."); |
165 | PWM_ASSERT((runStatus == running) || (runStatus == init)); | 182 | PWM_ASSERT((runStatus == running) || (runStatus == init)); |
166 | runStatus = shutdown; | 183 | runStatus = shutdown; |
167 | QApplication::exit(exitStatus); | 184 | QApplication::exit(exitStatus); |
168 | /* The destructor of PwMInit is called when control | 185 | /* The destructor of PwMInit is called when control |
169 | * leaves main() | 186 | * leaves main() |
170 | */ | 187 | */ |
171 | } | 188 | } |
172 | 189 | ||
173 | void PwMInit::initPosixSignalHandler() | 190 | void PwMInit::initPosixSignalHandler() |
174 | { | 191 | { |
175 | signal(SIGINT, sig_handler); | 192 | signal(SIGINT, sig_handler); |
176 | signal(SIGTERM, sig_handler); | 193 | signal(SIGTERM, sig_handler); |
177 | } | 194 | } |
178 | 195 | ||
179 | void PwMInit::initDCOP() | 196 | void PwMInit::initDCOP() |
180 | { | 197 | { |
181 | #ifndef PWM_EMBEDDED | 198 | #ifndef PWM_EMBEDDED |
182 | _dcopClient = app->dcopClient(); | 199 | _dcopClient = app->dcopClient(); |
183 | _dcopClient->setNotifications(true); | 200 | _dcopClient->setNotifications(true); |
184 | #endif | 201 | #endif |
185 | 202 | ||
186 | } | 203 | } |
187 | 204 | ||
188 | void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload) | 205 | void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload) |
189 | { | 206 | { |
190 | #ifdef CONFIG_KWALLETIF | 207 | #ifdef CONFIG_KWALLETIF |
191 | if (!conf()->confGlobKwalletEmu() || | 208 | if (!conf()->confGlobKwalletEmu() || |
192 | forceDisable) { | 209 | forceDisable) { |
193 | delete_ifnot_null(_kwalletEmu); | 210 | delete_ifnot_null(_kwalletEmu); |
194 | return; | 211 | return; |
195 | } | 212 | } |
196 | try { | 213 | try { |
197 | if (_kwalletEmu && forceReload) | 214 | if (_kwalletEmu && forceReload) |
198 | delete_and_null(_kwalletEmu); | 215 | delete_and_null(_kwalletEmu); |
199 | if (!_kwalletEmu) | 216 | if (!_kwalletEmu) |
200 | _kwalletEmu = new KWalletEmu(this); | 217 | _kwalletEmu = new KWalletEmu(this); |
201 | } catch (PwMException e) { | 218 | } catch (PwMException e) { |
202 | string errMsg("initializing KWallet emulation failed. ID: "); | 219 | string errMsg("initializing KWallet emulation failed. ID: "); |
203 | errMsg += tostr(static_cast<int>(e.getId())); | 220 | errMsg += tostr(static_cast<int>(e.getId())); |
204 | errMsg += " err-message: "; | 221 | errMsg += " err-message: "; |
205 | errMsg += e.getMessage(); | 222 | errMsg += e.getMessage(); |
206 | printWarn(errMsg); | 223 | printWarn(errMsg); |
207 | return; | 224 | return; |
208 | } | 225 | } |
209 | #else // CONFIG_KWALLETIF | 226 | #else // CONFIG_KWALLETIF |
210 | PARAM_UNUSED(forceDisable); | 227 | PARAM_UNUSED(forceDisable); |
211 | PARAM_UNUSED(forceReload); | 228 | PARAM_UNUSED(forceReload); |
212 | #endif // CONFIG_KWALLETIF | 229 | #endif // CONFIG_KWALLETIF |
213 | } | 230 | } |
214 | 231 | ||
215 | void PwMInit::initKeycard() | 232 | void PwMInit::initKeycard() |
216 | { | 233 | { |
217 | #ifdef CONFIG_KEYCARD | 234 | #ifdef CONFIG_KEYCARD |
218 | PWM_ASSERT(!_keycard); | 235 | PWM_ASSERT(!_keycard); |
219 | _keycard = new PwMKeyCard(this); | 236 | _keycard = new PwMKeyCard(this); |
220 | #endif // CONFIG_KEYCARD | 237 | #endif // CONFIG_KEYCARD |
221 | } | 238 | } |
222 | 239 | ||
223 | void PwMInit::initTray() | 240 | void PwMInit::initTray() |
224 | { | 241 | { |
225 | #ifdef PWM_EMBEDDED | 242 | #ifdef PWM_EMBEDDED |
226 | //US ENH : embedded version does not support a tray | 243 | //US ENH : embedded version does not support a tray |
227 | return; | 244 | return; |
228 | #endif | 245 | #endif |
229 | 246 | ||
230 | if (!conf()->confGlobTray()) { | 247 | if (!conf()->confGlobTray()) { |
231 | if (!_tray) | 248 | if (!_tray) |
232 | return; | 249 | return; |
233 | _tray->hide(); | 250 | _tray->hide(); |
234 | delete_and_null(_tray); | 251 | delete_and_null(_tray); |
235 | return; | 252 | return; |
236 | } | 253 | } |
237 | if (_tray) | 254 | if (_tray) |
238 | return; | 255 | return; |
239 | _tray = new PwMTray(this); | 256 | _tray = new PwMTray(this); |
240 | connect(_tray, SIGNAL(quitSelected()), | 257 | connect(_tray, SIGNAL(quitSelected()), |
241 | this, SLOT(removeTrayAndQuit())); | 258 | this, SLOT(removeTrayAndQuit())); |
242 | connect(_tray, SIGNAL(closed(PwMTray *)), | 259 | connect(_tray, SIGNAL(closed(PwMTray *)), |
243 | this, SLOT(trayIconClosed(PwMTray *))); | 260 | this, SLOT(trayIconClosed(PwMTray *))); |
244 | KIconLoader icons; | 261 | KIconLoader icons; |
245 | #ifndef PWM_EMBEDDED | 262 | #ifndef PWM_EMBEDDED |
246 | _tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small)); | 263 | _tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small)); |
247 | #endif | 264 | #endif |
248 | _tray->show(); | 265 | _tray->show(); |
249 | // connect the signals of all open documents. | 266 | // connect the signals of all open documents. |
250 | const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList(); | 267 | const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList(); |
251 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), | 268 | vector<PwMDocList::listItem>::const_iterator i = dl->begin(), |
252 | end = dl->end(); | 269 | end = dl->end(); |
253 | while (i != end) { | 270 | while (i != end) { |
254 | _tray->connectDocToTray((*i).doc); | 271 | _tray->connectDocToTray((*i).doc); |
255 | ++i; | 272 | ++i; |
256 | } | 273 | } |
257 | } | 274 | } |
258 | 275 | ||
259 | void PwMInit::removeTrayAndQuit() | 276 | void PwMInit::removeTrayAndQuit() |
260 | { | 277 | { |
261 | PWM_ASSERT(_tray); | 278 | PWM_ASSERT(_tray); |
262 | // _tray is deleted in ~PwMInit | 279 | // _tray is deleted in ~PwMInit |
263 | shutdownApp(0); | 280 | shutdownApp(0); |
264 | } | 281 | } |
265 | 282 | ||
266 | PwM * PwMInit::createMainWnd(const QString &loadFile, | 283 | PwM * PwMInit::createMainWnd(const QString &loadFile, |
267 | bool loadFileDeepLocked, | 284 | bool loadFileDeepLocked, |
268 | bool virginity, | 285 | bool virginity, |
269 | PwMDoc *doc, | 286 | PwMDoc *doc, |
270 | bool minimized) | 287 | bool minimized) |
271 | { | 288 | { |
272 | PwM *newWnd; | 289 | PwM *newWnd; |
273 | if (!doc) | 290 | if (!doc) |
274 | doc = createDoc(); | 291 | doc = createDoc(); |
275 | newWnd = new PwM(this, doc, virginity); | 292 | newWnd = new PwM(this, doc, virginity); |
276 | #ifndef PWM_EMBEDDED | 293 | #ifndef PWM_EMBEDDED |
277 | _mainWndList.push_back(newWnd); | 294 | _mainWndList.push_back(newWnd); |
278 | #else | 295 | #else |
279 | _mainWndList.append(newWnd); | 296 | _mainWndList.append(newWnd); |
280 | #endif | 297 | #endif |
281 | connect(newWnd, SIGNAL(closed(PwM *)), | 298 | connect(newWnd, SIGNAL(closed(PwM *)), |
282 | this, SLOT(mainWndClosed(PwM *))); | 299 | this, SLOT(mainWndClosed(PwM *))); |
283 | connect(newWnd, SIGNAL(gotFocus(PwM *)), | 300 | connect(newWnd, SIGNAL(gotFocus(PwM *)), |
284 | this, SLOT(setCurWidget(PwM *))); | 301 | this, SLOT(setCurWidget(PwM *))); |
285 | connect(newWnd, SIGNAL(lostFocus(PwM *)), | 302 | connect(newWnd, SIGNAL(lostFocus(PwM *)), |
286 | this, SLOT(resetCurWidget())); | 303 | this, SLOT(resetCurWidget())); |
287 | 304 | ||
288 | //US ENH | 305 | //US ENH |
289 | #ifndef PWM_EMBEDDED | 306 | #ifndef PWM_EMBEDDED |
290 | if (minimized) | 307 | if (minimized) |
291 | newWnd->showMinimized(); | 308 | newWnd->showMinimized(); |
292 | else | 309 | else |
293 | newWnd->show(); | 310 | newWnd->show(); |
294 | 311 | ||
295 | #else //PWM_EMBEDDED | 312 | #else //PWM_EMBEDDED |
296 | 313 | ||
297 | #ifndef DESKTOP_VERSION | 314 | #ifndef DESKTOP_VERSION |
298 | app->showMainWidget( newWnd ); | 315 | app->showMainWidget( newWnd ); |
299 | #else //DESKTOP_VERSION | 316 | #else //DESKTOP_VERSION |
300 | app->setMainWidget( newWnd ); | 317 | app->setMainWidget( newWnd ); |
301 | newWnd->resize (640, 480 ); | 318 | newWnd->resize (640, 480 ); |
302 | newWnd->show(); | 319 | newWnd->show(); |
303 | #endif //DESKTOP_VERSION | 320 | #endif //DESKTOP_VERSION |
304 | 321 | ||
305 | #endif //PWM_EMBEDDED | 322 | #endif //PWM_EMBEDDED |
306 | 323 | ||
307 | if (loadFile != QString::null && | 324 | if (loadFile != QString::null && |
308 | loadFile != "") { | 325 | loadFile != "") { |
309 | newWnd->openDoc(loadFile, loadFileDeepLocked); | 326 | newWnd->openDoc(loadFile, loadFileDeepLocked); |
310 | } | 327 | } |
311 | return newWnd; | 328 | return newWnd; |
312 | } | 329 | } |
313 | 330 | ||
314 | PwMDoc * PwMInit::createDoc() | 331 | PwMDoc * PwMInit::createDoc() |
315 | { | 332 | { |
316 | PwMDoc *doc = new PwMDoc(this); | 333 | PwMDoc *doc = new PwMDoc(this); |
317 | #ifdef CONFIG_KEYCARD | 334 | #ifdef CONFIG_KEYCARD |
318 | doc->setPwMKeyCard(keycard()); | 335 | doc->setPwMKeyCard(keycard()); |
319 | #endif | 336 | #endif |
320 | #ifdef CONFIG_KWALLETIF | 337 | #ifdef CONFIG_KWALLETIF |
321 | if (kwalletEmu()) | 338 | if (kwalletEmu()) |
322 | kwalletEmu()->connectDocSignals(doc); | 339 | kwalletEmu()->connectDocSignals(doc); |
323 | #endif | 340 | #endif |
324 | 341 | ||
325 | if (_tray) | 342 | if (_tray) |
326 | _tray->connectDocToTray(doc); | 343 | _tray->connectDocToTray(doc); |
327 | 344 | ||
328 | return doc; | 345 | return doc; |
329 | 346 | ||
330 | } | 347 | } |
331 | 348 | ||
332 | void PwMInit::mainWndClosed(PwM *wnd) | 349 | void PwMInit::mainWndClosed(PwM *wnd) |
333 | { | 350 | { |
334 | bool doMinimizeToTray = false; | 351 | bool doMinimizeToTray = false; |
335 | bool doDeleteDoc = false; | 352 | bool doDeleteDoc = false; |
336 | #ifndef PWM_EMBEDDED | 353 | #ifndef PWM_EMBEDDED |
337 | dcopClient()->suspend(); | 354 | dcopClient()->suspend(); |
338 | dcopClient()->setAcceptCalls(false); | 355 | dcopClient()->setAcceptCalls(false); |
339 | #endif | 356 | #endif |
340 | again: | 357 | again: |
341 | 358 | ||
342 | if (wnd->isForceMinimizeToTray()) { | 359 | if (wnd->isForceMinimizeToTray()) { |
343 | if (unlikely(!_tray)) { | 360 | if (unlikely(!_tray)) { |
344 | /* This should not happen! If we set forceMinimizeToTray , | 361 | /* This should not happen! If we set forceMinimizeToTray , |
345 | * we must be sure that _tray exists. | 362 | * we must be sure that _tray exists. |
346 | */ | 363 | */ |
347 | BUG(); | 364 | BUG(); |
348 | wnd->setForceMinimizeToTray(false); | 365 | wnd->setForceMinimizeToTray(false); |
349 | goto again; | 366 | goto again; |
350 | } | 367 | } |
351 | doMinimizeToTray = true; | 368 | doMinimizeToTray = true; |
352 | } else { | 369 | } else { |
353 | // Ask to minimize to tray. If not, delete doc. | 370 | // Ask to minimize to tray. If not, delete doc. |
354 | if (_tray && | 371 | if (_tray && |
355 | runStatus != shutdown && | 372 | runStatus != shutdown && |
356 | !wnd->isForceQuit() && | 373 | !wnd->isForceQuit() && |
357 | !wnd->curDoc()->isDeleted()) { | 374 | !wnd->curDoc()->isDeleted()) { |
358 | if (conf()->confWndClose()) | 375 | if (conf()->confWndClose()) |
359 | doDeleteDoc = true; | 376 | doDeleteDoc = true; |
360 | else | 377 | else |
361 | doMinimizeToTray = true; | 378 | doMinimizeToTray = true; |
362 | } else { | 379 | } else { |
363 | doDeleteDoc = true; | 380 | doDeleteDoc = true; |
364 | } | 381 | } |
365 | } | 382 | } |
366 | 383 | ||
367 | if (doMinimizeToTray) { | 384 | if (doMinimizeToTray) { |
368 | 385 | ||
369 | PWM_ASSERT(_tray); | 386 | PWM_ASSERT(_tray); |
370 | int mmlock = conf()->confGlobMinimizeLock(); | 387 | int mmlock = conf()->confGlobMinimizeLock(); |
371 | switch (mmlock) { | 388 | switch (mmlock) { |
372 | case 0: // don't lock anything | 389 | case 0: // don't lock anything |
373 | break; | 390 | break; |
374 | case 1: // normal lock | 391 | case 1: // normal lock |
375 | wnd->curDoc()->lockAll(true); | 392 | wnd->curDoc()->lockAll(true); |
376 | break; | 393 | break; |
377 | case 2: // deep-lock | 394 | case 2: // deep-lock |
378 | wnd->curDoc()->deepLock(); | 395 | wnd->curDoc()->deepLock(); |
379 | break; | 396 | break; |
380 | default: | 397 | default: |
381 | WARN(); | 398 | WARN(); |
382 | } | 399 | } |
383 | } else if (doDeleteDoc) { | 400 | } else if (doDeleteDoc) { |
384 | if (!wnd->curDoc()->tryDelete()) { | 401 | if (!wnd->curDoc()->tryDelete()) { |
385 | /* We failed deleting the doc, | 402 | /* We failed deleting the doc, |
386 | * so open a new window with it, again. | 403 | * so open a new window with it, again. |
387 | */ | 404 | */ |
388 | createMainWnd(QString::null, false, | 405 | createMainWnd(QString::null, false, |
389 | false, wnd->curDoc()); | 406 | false, wnd->curDoc()); |
390 | } | 407 | } |
391 | } | 408 | } |
392 | #ifndef PWM_EMBEDDED | 409 | #ifndef PWM_EMBEDDED |
393 | // find the closed window in the "mainWndList" and delete it. | 410 | // find the closed window in the "mainWndList" and delete it. |
394 | QValueList<PwM *>::iterator i = _mainWndList.begin(), | 411 | QValueList<PwM *>::iterator i = _mainWndList.begin(), |
395 | end = _mainWndList.end(); | 412 | end = _mainWndList.end(); |
396 | #else | 413 | #else |
397 | // find the closed window in the "mainWndList" and delete it. | 414 | // find the closed window in the "mainWndList" and delete it. |
398 | QValueList<PwM *>::Iterator i = _mainWndList.begin(), | 415 | QValueList<PwM *>::Iterator i = _mainWndList.begin(), |
399 | end = _mainWndList.end(); | 416 | end = _mainWndList.end(); |
400 | #endif | 417 | #endif |
401 | while (i != end) { | 418 | while (i != end) { |
402 | if (*i == wnd) { | 419 | if (*i == wnd) { |
403 | #ifndef PWM_EMBEDDED | 420 | #ifndef PWM_EMBEDDED |
404 | _mainWndList.erase(i); | 421 | _mainWndList.erase(i); |
405 | #else | 422 | #else |
406 | _mainWndList.remove(i); | 423 | _mainWndList.remove(i); |
407 | #endif | 424 | #endif |
408 | goto out_success; | 425 | goto out_success; |
409 | } | 426 | } |
410 | ++i; | 427 | ++i; |
411 | } | 428 | } |
412 | BUG(); | 429 | BUG(); |
413 | out_success: | 430 | out_success: |
414 | #ifndef PWM_EMBEDDED | 431 | #ifndef PWM_EMBEDDED |
415 | if (!_mainWndList.size()) | 432 | if (!_mainWndList.size()) |
416 | #else | 433 | #else |
417 | if (!_mainWndList.count()) | 434 | if (!_mainWndList.count()) |
418 | #endif | 435 | #endif |
419 | 436 | ||
420 | { | 437 | { |
421 | /* If there's no main window and no tray icon | 438 | /* If there's no main window and no tray icon |
422 | * left, we have no user interface, so we can | 439 | * left, we have no user interface, so we can |
423 | * shut down the application. | 440 | * shut down the application. |
424 | */ | 441 | */ |
425 | if (!_tray) { | 442 | if (!_tray) { |
426 | #ifndef PWM_EMBEDDED | 443 | #ifndef PWM_EMBEDDED |
427 | dcopClient()->setAcceptCalls(true); | 444 | dcopClient()->setAcceptCalls(true); |
428 | dcopClient()->resume(); | 445 | dcopClient()->resume(); |
429 | #endif | 446 | #endif |
430 | shutdownApp(0); | 447 | shutdownApp(0); |
431 | return; | 448 | return; |
432 | } | 449 | } |
433 | /* There is no widget left, so set | 450 | /* There is no widget left, so set |
434 | * _curWidget to 0 | 451 | * _curWidget to 0 |
435 | */ | 452 | */ |
436 | resetCurWidget(); | 453 | resetCurWidget(); |
437 | } | 454 | } |
438 | #ifndef PWM_EMBEDDED | 455 | #ifndef PWM_EMBEDDED |
439 | dcopClient()->setAcceptCalls(true); | 456 | dcopClient()->setAcceptCalls(true); |
440 | dcopClient()->resume(); | 457 | dcopClient()->resume(); |
441 | #endif | 458 | #endif |
442 | } | 459 | } |
443 | 460 | ||
444 | void PwMInit::trayIconClosed(PwMTray *tray) | 461 | void PwMInit::trayIconClosed(PwMTray *tray) |
445 | { | 462 | { |
446 | if (runStatus != running) | 463 | if (runStatus != running) |
447 | return; | 464 | return; |
448 | PARAM_UNUSED(tray); | 465 | PARAM_UNUSED(tray); |
449 | PWM_ASSERT(tray == _tray); | 466 | PWM_ASSERT(tray == _tray); |
450 | /* If there's no main wnd left we have to | 467 | /* If there's no main wnd left we have to |
451 | * shutdown the app (same as in mainWndClosed()) | 468 | * shutdown the app (same as in mainWndClosed()) |
452 | */ | 469 | */ |
453 | #ifndef PWM_EMBEDDED | 470 | #ifndef PWM_EMBEDDED |
454 | if (!_mainWndList.size()) | 471 | if (!_mainWndList.size()) |
455 | shutdownApp(0); | 472 | shutdownApp(0); |
456 | #else | 473 | #else |
457 | if (!_mainWndList.count()) | 474 | if (!_mainWndList.count()) |
458 | shutdownApp(0); | 475 | shutdownApp(0); |
459 | #endif | 476 | #endif |
460 | } | 477 | } |
461 | 478 | ||
462 | void PwMInit::handleCmdLineArgs(bool initial) | 479 | void PwMInit::handleCmdLineArgs(bool initial) |
463 | { | 480 | { |
464 | #ifndef PWM_EMBEDDED | 481 | #ifndef PWM_EMBEDDED |
465 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); | 482 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
466 | PWM_ASSERT(args); | 483 | PWM_ASSERT(args); |
467 | int i, numArgs = args->count(); | 484 | int i, numArgs = args->count(); |
468 | const char *curArg; | 485 | const char *curArg; |
469 | 486 | ||
470 | // read all cmdline options | 487 | // read all cmdline options |
471 | savedCmd.open_deeplocked = args->isSet("open-deeplocked"); | 488 | savedCmd.open_deeplocked = args->isSet("open-deeplocked"); |
472 | savedCmd.minimized = args->isSet("minimized"); | 489 | savedCmd.minimized = args->isSet("minimized"); |
473 | savedCmd.minToTray = args->isSet("mintray"); | 490 | savedCmd.minToTray = args->isSet("mintray"); |
474 | savedCmd.skipSelfTest = args->isSet("skip-self-test"); | 491 | savedCmd.skipSelfTest = args->isSet("skip-self-test"); |
475 | if (savedCmd.minimized && | 492 | if (savedCmd.minimized && |
476 | savedCmd.minToTray) { | 493 | savedCmd.minToTray) { |
477 | printInfo(i18n("Commandline option \"--minimized\" and " | 494 | printInfo(i18n("Commandline option \"--minimized\" and " |
478 | "\"--mintray\" selected. These are incompatible. " | 495 | "\"--mintray\" selected. These are incompatible. " |
479 | "\"--mintray\" will be selected.").latin1()); | 496 | "\"--mintray\" will be selected.").latin1()); |
480 | } | 497 | } |
481 | /* Iterate through all non-option arguments. | 498 | /* Iterate through all non-option arguments. |
482 | * Every non-option arg is a filename to open. | 499 | * Every non-option arg is a filename to open. |
483 | */ | 500 | */ |
484 | for (i = 0; i < numArgs; ++i) { | 501 | for (i = 0; i < numArgs; ++i) { |
485 | curArg = args->arg(i); | 502 | curArg = args->arg(i); |
486 | PWM_ASSERT(curArg); | 503 | PWM_ASSERT(curArg); |
487 | if (savedCmd.minToTray) { | 504 | if (savedCmd.minToTray) { |
488 | PwMDoc *newDoc = createDoc(); | 505 | PwMDoc *newDoc = createDoc(); |
489 | if (!newDoc->openDocUi(newDoc, | 506 | if (!newDoc->openDocUi(newDoc, |
490 | curArg, | 507 | curArg, |
491 | savedCmd.open_deeplocked)) { | 508 | savedCmd.open_deeplocked)) { |
492 | delete newDoc; | 509 | delete newDoc; |
493 | } | 510 | } |
494 | } else { | 511 | } else { |
495 | PwM *newInstance = createMainWnd(QString::null, | 512 | PwM *newInstance = createMainWnd(QString::null, |
496 | false, | 513 | false, |
497 | true, | 514 | true, |
498 | 0, | 515 | 0, |
499 | savedCmd.minimized); | 516 | savedCmd.minimized); |
500 | PwMDoc *newDoc = newInstance->openDoc(curArg, | 517 | PwMDoc *newDoc = newInstance->openDoc(curArg, |
501 | savedCmd.open_deeplocked); | 518 | savedCmd.open_deeplocked); |
502 | if (!newDoc) { | 519 | if (!newDoc) { |
503 | newInstance->setForceQuit(true); | 520 | newInstance->setForceQuit(true); |
504 | delete_and_null(newInstance); | 521 | delete_and_null(newInstance); |
505 | } | 522 | } |
506 | } | 523 | } |
507 | } | 524 | } |
508 | 525 | ||
509 | if (savedCmd.minToTray) { | 526 | if (savedCmd.minToTray) { |
510 | minimizeAllMainWnd(true); | 527 | minimizeAllMainWnd(true); |
511 | } else if (savedCmd.minimized) { | 528 | } else if (savedCmd.minimized) { |
512 | minimizeAllMainWnd(false); | 529 | minimizeAllMainWnd(false); |
513 | } | 530 | } |
514 | if (!savedCmd.skipSelfTest && initial) { | 531 | if (!savedCmd.skipSelfTest && initial) { |
515 | SelfTest::schedule(); | 532 | SelfTest::schedule(); |
516 | } | 533 | } |
517 | args->clear(); | 534 | args->clear(); |
518 | #endif | 535 | #endif |
519 | } | 536 | } |
520 | 537 | ||
521 | void PwMInit::minimizeAllMainWnd(bool toTray) | 538 | void PwMInit::minimizeAllMainWnd(bool toTray) |
522 | { | 539 | { |
523 | #ifndef PWM_EMBEDDED | 540 | #ifndef PWM_EMBEDDED |
524 | if (!_mainWndList.size()) | 541 | if (!_mainWndList.size()) |
525 | return; | 542 | return; |
526 | #else | 543 | #else |
527 | if (!_mainWndList.count()) | 544 | if (!_mainWndList.count()) |
528 | return; | 545 | return; |
529 | #endif | 546 | #endif |
530 | const QValueList<PwM *> *ml = mainWndList(); | 547 | const QValueList<PwM *> *ml = mainWndList(); |
531 | #ifndef PWM_EMBEDDED | 548 | #ifndef PWM_EMBEDDED |
532 | QValueList<PwM *>::const_iterator it = ml->begin(), | 549 | QValueList<PwM *>::const_iterator it = ml->begin(), |
533 | end = ml->end(); | 550 | end = ml->end(); |
534 | #else | 551 | #else |
535 | QValueList<PwM *>::ConstIterator it = ml->begin(), | 552 | QValueList<PwM *>::ConstIterator it = ml->begin(), |
536 | end = ml->end(); | 553 | end = ml->end(); |
537 | #endif | 554 | #endif |
538 | PwM *wnd; | 555 | PwM *wnd; |
539 | if (toTray && _tray) { | 556 | if (toTray && _tray) { |
540 | /* minimize to tray. | 557 | /* minimize to tray. |
541 | * close all mainWnd. | 558 | * close all mainWnd. |
542 | */ | 559 | */ |
543 | while (it != end) { | 560 | while (it != end) { |
544 | wnd = *it; | 561 | wnd = *it; |
545 | wnd->setForceMinimizeToTray(true); | 562 | wnd->setForceMinimizeToTray(true); |
546 | wnd->close_slot(); | 563 | wnd->close_slot(); |
547 | ++it; | 564 | ++it; |
548 | } | 565 | } |
549 | } else { | 566 | } else { |
550 | // normal minimize | 567 | // normal minimize |
551 | while (it != end) { | 568 | while (it != end) { |
552 | wnd = *it; | 569 | wnd = *it; |
553 | wnd->hide(); | 570 | wnd->hide(); |
554 | wnd->showMinimized(); | 571 | wnd->showMinimized(); |
555 | ++it; | 572 | ++it; |
556 | } | 573 | } |
557 | } | 574 | } |
558 | } | 575 | } |
559 | 576 | ||
560 | #ifdef PWM_EMBEDDED | 577 | #ifdef PWM_EMBEDDED |
561 | 578 | ||
562 | #ifndef DESKTOP_VERSION | 579 | #ifndef DESKTOP_VERSION |
563 | 580 | ||
564 | PwMApplication::PwMApplication(int & argc, char ** argv) | 581 | PwMApplication::PwMApplication(int & argc, char ** argv) |
565 | : QPEApplication( argc, argv ) | 582 | : QPEApplication( argc, argv ) |
566 | , init (0) | 583 | , init (0) |
567 | { | 584 | { |
568 | this->setKeepRunning (); | 585 | this->setKeepRunning (); |
569 | } | 586 | } |
570 | 587 | ||
571 | PwMApplication::~PwMApplication() | 588 | PwMApplication::~PwMApplication() |
572 | { | 589 | { |
573 | delete_ifnot_null(init); | 590 | delete_ifnot_null(init); |
574 | } | 591 | } |
575 | #else //DESKTOP_VERSION | 592 | #else //DESKTOP_VERSION |
576 | 593 | ||
577 | PwMApplication::PwMApplication(int & argc, char ** argv) | 594 | PwMApplication::PwMApplication(int & argc, char ** argv) |
578 | : QApplication( argc, argv ) | 595 | : QApplication( argc, argv ) |
579 | , init (0) | 596 | , init (0) |
580 | { | 597 | { |
581 | setStyle( new QPlatinumStyle ()); | 598 | setStyle( new QPlatinumStyle ()); |
582 | QString hdir = QDir::homeDirPath(); | 599 | QString hdir = QDir::homeDirPath(); |
583 | // there is a bug when creating dirs for WIN 98 | 600 | // there is a bug when creating dirs for WIN 98 |
584 | // it is difficult to fix, because we have no WIN 98 runnung | 601 | // it is difficult to fix, because we have no WIN 98 runnung |
585 | // such that we try it to create the dirs at startup here | 602 | // such that we try it to create the dirs at startup here |
586 | if ( hdir == "C:\\" ) | 603 | if ( hdir == "C:\\" ) |
587 | { | 604 | { |
588 | // win 98 or ME | 605 | // win 98 or ME |
589 | QDir app_dir; | 606 | QDir app_dir; |
590 | if ( !app_dir.exists("C:\\kdepim") ) | 607 | if ( !app_dir.exists("C:\\kdepim") ) |
591 | app_dir.mkdir ("C:\\kdepim"); | 608 | app_dir.mkdir ("C:\\kdepim"); |
592 | if ( !app_dir.exists("C:\\kdepim\\apps") ) | 609 | if ( !app_dir.exists("C:\\kdepim\\apps") ) |
593 | app_dir.mkdir ("C:\\kdepim\\apps"); | 610 | app_dir.mkdir ("C:\\kdepim\\apps"); |
594 | if ( !app_dir.exists("C:\\kdepim\\config") ) | 611 | if ( !app_dir.exists("C:\\kdepim\\config") ) |
595 | app_dir.mkdir ("C:\\kdepim\\config"); | 612 | app_dir.mkdir ("C:\\kdepim\\config"); |
596 | if ( !app_dir.exists("C:\\kdepim\\apps\\pwmanager") ) | 613 | if ( !app_dir.exists("C:\\kdepim\\apps\\pwmanager") ) |
597 | app_dir.mkdir ("C:\\kdepim\\apps\\pwmanager"); | 614 | app_dir.mkdir ("C:\\kdepim\\apps\\pwmanager"); |
598 | } | 615 | } |
599 | } | 616 | } |
600 | 617 | ||
601 | PwMApplication::~PwMApplication() | 618 | PwMApplication::~PwMApplication() |
602 | { | 619 | { |
603 | delete_ifnot_null(init); | 620 | delete_ifnot_null(init); |
604 | } | 621 | } |
605 | 622 | ||
606 | #endif //DESKTOP_VERSION | 623 | #endif //DESKTOP_VERSION |
607 | 624 | ||
608 | #endif //PWM_EMBEDDED | 625 | #endif //PWM_EMBEDDED |
609 | 626 | ||
610 | 627 | ||
611 | 628 | ||
612 | 629 | ||
613 | #ifndef PWM_EMBEDDED | 630 | #ifndef PWM_EMBEDDED |
614 | #include "pwminit.moc" | 631 | #include "pwminit.moc" |
615 | #endif | 632 | #endif |
diff --git a/pwmanager/pwmanager/pwmtray.cpp b/pwmanager/pwmanager/pwmtray.cpp index 0f286c1..fe074ca 100644 --- a/pwmanager/pwmanager/pwmtray.cpp +++ b/pwmanager/pwmanager/pwmtray.cpp | |||
@@ -1,482 +1,486 @@ | |||
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 | * Original implementation of the tray-tree * | 6 | * Original implementation of the tray-tree * |
7 | * (c) by Matt Scifo <mscifo@o1.com> * | 7 | * (c) by 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 "pwmtray.h" | 23 | #include "pwmtray.h" |
24 | #include "pwmexception.h" | 24 | #include "pwmexception.h" |
25 | #include "pwm.h" | 25 | #include "pwm.h" |
26 | #include "pwmdoc.h" | 26 | #include "pwmdoc.h" |
27 | #include "pwminit.h" | 27 | #include "pwminit.h" |
28 | #ifndef PWM_EMBEDDED | ||
28 | #include "configuration.h" | 29 | #include "configuration.h" |
30 | #else | ||
31 | #include "pwmprefs.h" | ||
32 | #endif | ||
29 | 33 | ||
30 | #include <klocale.h> | 34 | #include <klocale.h> |
31 | 35 | ||
32 | 36 | ||
33 | void ActiveTreeItem::execIt() | 37 | void ActiveTreeItem::execIt() |
34 | { | 38 | { |
35 | #ifndef PWM_EMBEDDED | 39 | #ifndef PWM_EMBEDDED |
36 | unsigned int entr = static_cast<unsigned int>(entry); | 40 | unsigned int entr = static_cast<unsigned int>(entry); |
37 | unsigned int cat = static_cast<unsigned int>(category); | 41 | unsigned int cat = static_cast<unsigned int>(category); |
38 | #else | 42 | #else |
39 | unsigned int entr = (unsigned int)(entry); | 43 | unsigned int entr = (unsigned int)(entry); |
40 | unsigned int cat = (unsigned int)(category); | 44 | unsigned int cat = (unsigned int)(category); |
41 | #endif | 45 | #endif |
42 | switch (task) { | 46 | switch (task) { |
43 | case pwToClipboard: { | 47 | case pwToClipboard: { |
44 | PwMDataItem d; | 48 | PwMDataItem d; |
45 | doc->getDataChangedLock(); | 49 | doc->getDataChangedLock(); |
46 | bool wasLocked = doc->isLocked(cat, entr); | 50 | bool wasLocked = doc->isLocked(cat, entr); |
47 | doc->getEntry(cat, entr, &d, true); | 51 | doc->getEntry(cat, entr, &d, true); |
48 | if (wasLocked) | 52 | if (wasLocked) |
49 | doc->lockAt(cat, entr, true); | 53 | doc->lockAt(cat, entr, true); |
50 | doc->putDataChangedLock(); | 54 | doc->putDataChangedLock(); |
51 | PwM::copyToClipboard(d.pw.c_str()); | 55 | PwM::copyToClipboard(d.pw.c_str()); |
52 | break; | 56 | break; |
53 | } case nameToClipboard: { | 57 | } case nameToClipboard: { |
54 | PwMDataItem d; | 58 | PwMDataItem d; |
55 | doc->getEntry(cat, entr, &d); | 59 | doc->getEntry(cat, entr, &d); |
56 | PwM::copyToClipboard(d.name.c_str()); | 60 | PwM::copyToClipboard(d.name.c_str()); |
57 | break; | 61 | break; |
58 | } case descToClipboard: { | 62 | } case descToClipboard: { |
59 | PwMDataItem d; | 63 | PwMDataItem d; |
60 | doc->getEntry(cat, entr, &d); | 64 | doc->getEntry(cat, entr, &d); |
61 | PwM::copyToClipboard(d.desc.c_str()); | 65 | PwM::copyToClipboard(d.desc.c_str()); |
62 | break; | 66 | break; |
63 | } case urlToClipboard: { | 67 | } case urlToClipboard: { |
64 | PwMDataItem d; | 68 | PwMDataItem d; |
65 | doc->getEntry(cat, entr, &d); | 69 | doc->getEntry(cat, entr, &d); |
66 | PwM::copyToClipboard(d.url.c_str()); | 70 | PwM::copyToClipboard(d.url.c_str()); |
67 | break; | 71 | break; |
68 | } case launcherToClipboard: { | 72 | } case launcherToClipboard: { |
69 | PwMDataItem d; | 73 | PwMDataItem d; |
70 | doc->getEntry(cat, entr, &d); | 74 | doc->getEntry(cat, entr, &d); |
71 | PwM::copyToClipboard(d.launcher.c_str()); | 75 | PwM::copyToClipboard(d.launcher.c_str()); |
72 | break; | 76 | break; |
73 | } case commentToClipboard: { | 77 | } case commentToClipboard: { |
74 | PwMDataItem d; | 78 | PwMDataItem d; |
75 | doc->getEntry(cat, entr, &d); | 79 | doc->getEntry(cat, entr, &d); |
76 | PwM::copyToClipboard(d.comment.c_str()); | 80 | PwM::copyToClipboard(d.comment.c_str()); |
77 | break; | 81 | break; |
78 | } case execLauncher: { | 82 | } case execLauncher: { |
79 | doc->execLauncher(cat, entr); | 83 | doc->execLauncher(cat, entr); |
80 | break; | 84 | break; |
81 | } case goToURL: { | 85 | } case goToURL: { |
82 | doc->goToURL(cat, entr); | 86 | doc->goToURL(cat, entr); |
83 | break; | 87 | break; |
84 | } case openMainWnd: { | 88 | } case openMainWnd: { |
85 | // search if there is already an open window. | 89 | // search if there is already an open window. |
86 | const QValueList<PwM *> *wl = tray->init->mainWndList(); | 90 | const QValueList<PwM *> *wl = tray->init->mainWndList(); |
87 | #ifndef PWM_EMBEDDED | 91 | #ifndef PWM_EMBEDDED |
88 | QValueList<PwM *>::const_iterator i = wl->begin(), | 92 | QValueList<PwM *>::const_iterator i = wl->begin(), |
89 | end = wl->end(); | 93 | end = wl->end(); |
90 | #else | 94 | #else |
91 | QValueList<PwM *>::ConstIterator i = wl->begin(), | 95 | QValueList<PwM *>::ConstIterator i = wl->begin(), |
92 | end = wl->end(); | 96 | end = wl->end(); |
93 | #endif | 97 | #endif |
94 | PwM *wnd; | 98 | PwM *wnd; |
95 | while (i != end) { | 99 | while (i != end) { |
96 | wnd = *i; | 100 | wnd = *i; |
97 | if (wnd->curDoc() == doc) { | 101 | if (wnd->curDoc() == doc) { |
98 | // now bring this window to the foreground. | 102 | // now bring this window to the foreground. |
99 | if (!wnd->hasFocus()) { | 103 | if (!wnd->hasFocus()) { |
100 | wnd->hide(); | 104 | wnd->hide(); |
101 | wnd->showNormal(); | 105 | wnd->showNormal(); |
102 | wnd->setFocus(); | 106 | wnd->setFocus(); |
103 | } | 107 | } |
104 | return; | 108 | return; |
105 | } | 109 | } |
106 | ++i; | 110 | ++i; |
107 | } | 111 | } |
108 | // there is no open window, so open a new one. | 112 | // there is no open window, so open a new one. |
109 | tray->init->createMainWnd(QString::null, false, false, doc); | 113 | tray->init->createMainWnd(QString::null, false, false, doc); |
110 | break; | 114 | break; |
111 | } case closeDoc: { | 115 | } case closeDoc: { |
112 | doc->tryDelete(); | 116 | doc->tryDelete(); |
113 | break; | 117 | break; |
114 | } case lock: { | 118 | } case lock: { |
115 | doc->lockAll(true); | 119 | doc->lockAll(true); |
116 | break; | 120 | break; |
117 | } case deepLock: { | 121 | } case deepLock: { |
118 | doc->deepLock(); | 122 | doc->deepLock(); |
119 | break; | 123 | break; |
120 | } case unlock: { | 124 | } case unlock: { |
121 | doc->lockAll(false); | 125 | doc->lockAll(false); |
122 | break; | 126 | break; |
123 | } default: { | 127 | } default: { |
124 | BUG(); | 128 | BUG(); |
125 | } | 129 | } |
126 | } | 130 | } |
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
130 | 134 | ||
131 | #ifndef PWM_EMBEDDED | 135 | #ifndef PWM_EMBEDDED |
132 | PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name) | 136 | PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name) |
133 | : KSystemTray(parent, name) | 137 | : KSystemTray(parent, name) |
134 | #else | 138 | #else |
135 | PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name) | 139 | PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name) |
136 | : QWidget(parent, name) | 140 | : QWidget(parent, name) |
137 | #endif | 141 | #endif |
138 | { | 142 | { |
139 | init = _init; | 143 | init = _init; |
140 | buildMain(); | 144 | buildMain(); |
141 | } | 145 | } |
142 | 146 | ||
143 | PwMTray::~PwMTray() | 147 | PwMTray::~PwMTray() |
144 | { | 148 | { |
145 | emit closed(this); | 149 | emit closed(this); |
146 | } | 150 | } |
147 | 151 | ||
148 | //US ENH for embedded tray class | 152 | //US ENH for embedded tray class |
149 | KPopupMenu* PwMTray::contextMenu() | 153 | KPopupMenu* PwMTray::contextMenu() |
150 | { | 154 | { |
151 | if (m_ctxMenu == 0) | 155 | if (m_ctxMenu == 0) |
152 | { | 156 | { |
153 | m_ctxMenu = new KPopupMenu(); | 157 | m_ctxMenu = new KPopupMenu(); |
154 | } | 158 | } |
155 | 159 | ||
156 | return m_ctxMenu; | 160 | return m_ctxMenu; |
157 | } | 161 | } |
158 | 162 | ||
159 | 163 | ||
160 | void PwMTray::buildMain() | 164 | void PwMTray::buildMain() |
161 | { | 165 | { |
162 | KPopupMenu *ctxMenu = contextMenu(); | 166 | KPopupMenu *ctxMenu = contextMenu(); |
163 | 167 | ||
164 | ctxMenu->insertSeparator(); | 168 | ctxMenu->insertSeparator(); |
165 | ctxMenu->insertItem(i18n("&New main window..."), this, | 169 | ctxMenu->insertItem(i18n("&New main window..."), this, |
166 | SLOT(newMainWnd())); | 170 | SLOT(newMainWnd())); |
167 | ctxMenu->insertItem(i18n("&Open file..."), this, | 171 | ctxMenu->insertItem(i18n("&Open file..."), this, |
168 | SLOT(openDoc())); | 172 | SLOT(openDoc())); |
169 | ctxMenu->insertSeparator(); | 173 | ctxMenu->insertSeparator(); |
170 | ctxMenu->insertItem(i18n("&Remove from tray"), this, | 174 | ctxMenu->insertItem(i18n("&Remove from tray"), this, |
171 | SLOT(undock())); | 175 | SLOT(undock())); |
172 | } | 176 | } |
173 | 177 | ||
174 | void PwMTray::insertActiveTreeItem(KPopupMenu *insertIn, const QString &text, | 178 | void PwMTray::insertActiveTreeItem(KPopupMenu *insertIn, const QString &text, |
175 | ActiveTreeItem::Task task, PwMDoc *doc, | 179 | ActiveTreeItem::Task task, PwMDoc *doc, |
176 | int docCategory, int docEntry, | 180 | int docCategory, int docEntry, |
177 | QValueList<int> *activeItemsList) | 181 | QValueList<int> *activeItemsList) |
178 | { | 182 | { |
179 | ActiveTreeItem *activeItem; | 183 | ActiveTreeItem *activeItem; |
180 | int id; | 184 | int id; |
181 | 185 | ||
182 | activeItem = new ActiveTreeItem(text, insertIn->font(), task, | 186 | activeItem = new ActiveTreeItem(text, insertIn->font(), task, |
183 | doc, docCategory, docEntry, | 187 | doc, docCategory, docEntry, |
184 | this); | 188 | this); |
185 | id = insertIn->insertItem(activeItem); | 189 | id = insertIn->insertItem(activeItem); |
186 | insertIn->connectItem(id, activeItem, SLOT(execIt())); | 190 | insertIn->connectItem(id, activeItem, SLOT(execIt())); |
187 | #ifndef PWM_EMBEDDED | 191 | #ifndef PWM_EMBEDDED |
188 | activeItemsList->push_back(id); | 192 | activeItemsList->push_back(id); |
189 | #else | 193 | #else |
190 | activeItemsList->append(id); | 194 | activeItemsList->append(id); |
191 | #endif | 195 | #endif |
192 | } | 196 | } |
193 | 197 | ||
194 | void PwMTray::rebuildTree(KPopupMenu *popup, PwMDoc *doc, | 198 | void PwMTray::rebuildTree(KPopupMenu *popup, PwMDoc *doc, |
195 | QValueList<int> *activeItems) | 199 | QValueList<int> *activeItems) |
196 | { | 200 | { |
197 | PWM_ASSERT(doc); | 201 | PWM_ASSERT(doc); |
198 | PWM_ASSERT(popup); | 202 | PWM_ASSERT(popup); |
199 | activeItems->clear(); | 203 | activeItems->clear(); |
200 | popup->clear(); | 204 | popup->clear(); |
201 | #ifndef PWM_EMBEDDED | 205 | #ifndef PWM_EMBEDDED |
202 | popup->insertTitle(i18n("Categories:")); | 206 | popup->insertTitle(i18n("Categories:")); |
203 | #endif | 207 | #endif |
204 | vector<string> catList; | 208 | vector<string> catList; |
205 | vector<string> entrList; | 209 | vector<string> entrList; |
206 | doc->getCategoryList(&catList); | 210 | doc->getCategoryList(&catList); |
207 | KPopupMenu *newCatMenu; | 211 | KPopupMenu *newCatMenu; |
208 | KPopupMenu *newEntrMenu; | 212 | KPopupMenu *newEntrMenu; |
209 | int i, size = catList.size(); | 213 | int i, size = catList.size(); |
210 | int j, entries; | 214 | int j, entries; |
211 | for (i = 0; i < size; ++i) { | 215 | for (i = 0; i < size; ++i) { |
212 | newCatMenu = new KPopupMenu(popup); | 216 | newCatMenu = new KPopupMenu(popup); |
213 | popup->insertItem(catList[i].c_str(), newCatMenu); | 217 | popup->insertItem(catList[i].c_str(), newCatMenu); |
214 | doc->getEntryList(i, &entrList); | 218 | doc->getEntryList(i, &entrList); |
215 | 219 | ||
216 | entries = entrList.size(); | 220 | entries = entrList.size(); |
217 | for (j = 0; j < entries; ++j) { | 221 | for (j = 0; j < entries; ++j) { |
218 | newEntrMenu = new KPopupMenu(newCatMenu); | 222 | newEntrMenu = new KPopupMenu(newCatMenu); |
219 | newCatMenu->insertItem(entrList[j].c_str(), newEntrMenu); | 223 | newCatMenu->insertItem(entrList[j].c_str(), newEntrMenu); |
220 | 224 | ||
221 | if (doc->isBinEntry(i, j)) { | 225 | if (doc->isBinEntry(i, j)) { |
222 | /* This is a binary entry. Don't insert the usual | 226 | /* This is a binary entry. Don't insert the usual |
223 | * menu items. | 227 | * menu items. |
224 | */ | 228 | */ |
225 | #ifndef PWM_EMBEDDED | 229 | #ifndef PWM_EMBEDDED |
226 | newEntrMenu->insertTitle(i18n("This is a binary entry.\n" | 230 | newEntrMenu->insertTitle(i18n("This is a binary entry.\n" |
227 | "It is not a normal password-entry, as it contains " | 231 | "It is not a normal password-entry, as it contains " |
228 | "binary data, which PwManager can't display here.")); | 232 | "binary data, which PwManager can't display here.")); |
229 | #endif | 233 | #endif |
230 | continue; | 234 | continue; |
231 | } | 235 | } |
232 | 236 | ||
233 | insertActiveTreeItem(newEntrMenu, | 237 | insertActiveTreeItem(newEntrMenu, |
234 | i18n("copy password to clipboard"), | 238 | i18n("copy password to clipboard"), |
235 | ActiveTreeItem::pwToClipboard, doc, i, j, | 239 | ActiveTreeItem::pwToClipboard, doc, i, j, |
236 | activeItems); | 240 | activeItems); |
237 | 241 | ||
238 | insertActiveTreeItem(newEntrMenu, | 242 | insertActiveTreeItem(newEntrMenu, |
239 | i18n("copy username to clipboard"), | 243 | i18n("copy username to clipboard"), |
240 | ActiveTreeItem::nameToClipboard, doc, i, j, | 244 | ActiveTreeItem::nameToClipboard, doc, i, j, |
241 | activeItems); | 245 | activeItems); |
242 | 246 | ||
243 | insertActiveTreeItem(newEntrMenu, | 247 | insertActiveTreeItem(newEntrMenu, |
244 | i18n("copy description to clipboard"), | 248 | i18n("copy description to clipboard"), |
245 | ActiveTreeItem::descToClipboard, doc, i, j, | 249 | ActiveTreeItem::descToClipboard, doc, i, j, |
246 | activeItems); | 250 | activeItems); |
247 | 251 | ||
248 | insertActiveTreeItem(newEntrMenu, | 252 | insertActiveTreeItem(newEntrMenu, |
249 | i18n("copy url to clipboard"), | 253 | i18n("copy url to clipboard"), |
250 | ActiveTreeItem::urlToClipboard, doc, i, j, | 254 | ActiveTreeItem::urlToClipboard, doc, i, j, |
251 | activeItems); | 255 | activeItems); |
252 | 256 | ||
253 | insertActiveTreeItem(newEntrMenu, | 257 | insertActiveTreeItem(newEntrMenu, |
254 | i18n("copy launcher to clipboard"), | 258 | i18n("copy launcher to clipboard"), |
255 | ActiveTreeItem::launcherToClipboard, doc, i, j, | 259 | ActiveTreeItem::launcherToClipboard, doc, i, j, |
256 | activeItems); | 260 | activeItems); |
257 | 261 | ||
258 | insertActiveTreeItem(newEntrMenu, | 262 | insertActiveTreeItem(newEntrMenu, |
259 | i18n("copy comment to clipboard"), | 263 | i18n("copy comment to clipboard"), |
260 | ActiveTreeItem::commentToClipboard, doc, i, j, | 264 | ActiveTreeItem::commentToClipboard, doc, i, j, |
261 | activeItems); | 265 | activeItems); |
262 | 266 | ||
263 | newEntrMenu->insertSeparator(); | 267 | newEntrMenu->insertSeparator(); |
264 | 268 | ||
265 | insertActiveTreeItem(newEntrMenu, | 269 | insertActiveTreeItem(newEntrMenu, |
266 | i18n("Execute \"Launcher\""), | 270 | i18n("Execute \"Launcher\""), |
267 | ActiveTreeItem::execLauncher, doc, i, j, | 271 | ActiveTreeItem::execLauncher, doc, i, j, |
268 | activeItems); | 272 | activeItems); |
269 | 273 | ||
270 | insertActiveTreeItem(newEntrMenu, | 274 | insertActiveTreeItem(newEntrMenu, |
271 | i18n("Go to \"URL\""), | 275 | i18n("Go to \"URL\""), |
272 | ActiveTreeItem::goToURL, doc, i, j, | 276 | ActiveTreeItem::goToURL, doc, i, j, |
273 | activeItems); | 277 | activeItems); |
274 | } | 278 | } |
275 | } | 279 | } |
276 | insertMainWndCtrl(popup, doc); | 280 | insertMainWndCtrl(popup, doc); |
277 | } | 281 | } |
278 | 282 | ||
279 | void PwMTray::insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc) | 283 | void PwMTray::insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc) |
280 | { | 284 | { |
281 | ActiveTreeItem *activeItem; | 285 | ActiveTreeItem *activeItem; |
282 | int id; | 286 | int id; |
283 | 287 | ||
284 | #ifndef PWM_EMBEDDED | 288 | #ifndef PWM_EMBEDDED |
285 | menu->insertTitle(i18n("Manager:")); | 289 | menu->insertTitle(i18n("Manager:")); |
286 | #endif | 290 | #endif |
287 | activeItem = new ActiveTreeItem(i18n("&Open main manager window ..."), | 291 | activeItem = new ActiveTreeItem(i18n("&Open main manager window ..."), |
288 | menu->font(), ActiveTreeItem::openMainWnd, | 292 | menu->font(), ActiveTreeItem::openMainWnd, |
289 | doc, 0, 0, this); | 293 | doc, 0, 0, this); |
290 | id = menu->insertItem(activeItem); | 294 | id = menu->insertItem(activeItem); |
291 | menu->connectItem(id, activeItem, SLOT(execIt())); | 295 | menu->connectItem(id, activeItem, SLOT(execIt())); |
292 | 296 | ||
293 | activeItem = new ActiveTreeItem(i18n("&Close this document ..."), | 297 | activeItem = new ActiveTreeItem(i18n("&Close this document ..."), |
294 | menu->font(), ActiveTreeItem::closeDoc, | 298 | menu->font(), ActiveTreeItem::closeDoc, |
295 | doc, 0, 0, this); | 299 | doc, 0, 0, this); |
296 | id = menu->insertItem(activeItem); | 300 | id = menu->insertItem(activeItem); |
297 | menu->connectItem(id, activeItem, SLOT(execIt())); | 301 | menu->connectItem(id, activeItem, SLOT(execIt())); |
298 | 302 | ||
299 | menu->insertSeparator(); | 303 | menu->insertSeparator(); |
300 | 304 | ||
301 | activeItem = new ActiveTreeItem(i18n("&Lock all entries"), | 305 | activeItem = new ActiveTreeItem(i18n("&Lock all entries"), |
302 | menu->font(), ActiveTreeItem::lock, | 306 | menu->font(), ActiveTreeItem::lock, |
303 | doc, 0, 0, this); | 307 | doc, 0, 0, this); |
304 | id = menu->insertItem(activeItem); | 308 | id = menu->insertItem(activeItem); |
305 | menu->connectItem(id, activeItem, SLOT(execIt())); | 309 | menu->connectItem(id, activeItem, SLOT(execIt())); |
306 | 310 | ||
307 | activeItem = new ActiveTreeItem(i18n("&Deep-lock all entries"), | 311 | activeItem = new ActiveTreeItem(i18n("&Deep-lock all entries"), |
308 | menu->font(), ActiveTreeItem::deepLock, | 312 | menu->font(), ActiveTreeItem::deepLock, |
309 | doc, 0, 0, this); | 313 | doc, 0, 0, this); |
310 | id = menu->insertItem(activeItem); | 314 | id = menu->insertItem(activeItem); |
311 | menu->connectItem(id, activeItem, SLOT(execIt())); | 315 | menu->connectItem(id, activeItem, SLOT(execIt())); |
312 | 316 | ||
313 | activeItem = new ActiveTreeItem(i18n("&Unlock all entries"), | 317 | activeItem = new ActiveTreeItem(i18n("&Unlock all entries"), |
314 | menu->font(), ActiveTreeItem::unlock, | 318 | menu->font(), ActiveTreeItem::unlock, |
315 | doc, 0, 0, this); | 319 | doc, 0, 0, this); |
316 | id = menu->insertItem(activeItem); | 320 | id = menu->insertItem(activeItem); |
317 | menu->connectItem(id, activeItem, SLOT(execIt())); | 321 | menu->connectItem(id, activeItem, SLOT(execIt())); |
318 | } | 322 | } |
319 | 323 | ||
320 | void PwMTray::updateTree(PwMDoc *document) | 324 | void PwMTray::updateTree(PwMDoc *document) |
321 | { | 325 | { |
322 | PWM_ASSERT(document); | 326 | PWM_ASSERT(document); |
323 | KPopupMenu *treeEntry; | 327 | KPopupMenu *treeEntry; |
324 | int treeItemNum = -1; | 328 | int treeItemNum = -1; |
325 | int id = findTreeEntry(document, &treeEntry, &treeItemNum); | 329 | int id = findTreeEntry(document, &treeEntry, &treeItemNum); |
326 | if (id == -1) { | 330 | if (id == -1) { |
327 | // tree-entry doesn't exist, yet. | 331 | // tree-entry doesn't exist, yet. |
328 | id = insertTreeEntry(document, &treeEntry); | 332 | id = insertTreeEntry(document, &treeEntry); |
329 | } | 333 | } |
330 | if (treeItemNum != -1) { | 334 | if (treeItemNum != -1) { |
331 | // delete all *old* active items | 335 | // delete all *old* active items |
332 | KPopupMenu *ctxMenu = contextMenu(); | 336 | KPopupMenu *ctxMenu = contextMenu(); |
333 | QValueList<int> *oldItems = &tree[treeItemNum].activeItems; | 337 | QValueList<int> *oldItems = &tree[treeItemNum].activeItems; |
334 | #ifndef PWM_EMBEDDED | 338 | #ifndef PWM_EMBEDDED |
335 | QValueList<int>::iterator i = oldItems->begin(); | 339 | QValueList<int>::iterator i = oldItems->begin(); |
336 | #else | 340 | #else |
337 | QValueList<int>::Iterator i = oldItems->begin(); | 341 | QValueList<int>::Iterator i = oldItems->begin(); |
338 | #endif | 342 | #endif |
339 | while (i != oldItems->end()) { | 343 | while (i != oldItems->end()) { |
340 | ctxMenu->removeItem(*i); | 344 | ctxMenu->removeItem(*i); |
341 | ++i; | 345 | ++i; |
342 | } | 346 | } |
343 | oldItems->clear(); | 347 | oldItems->clear(); |
344 | ctxMenu->changeItem(id, document->getTitle()); | 348 | ctxMenu->changeItem(id, document->getTitle()); |
345 | } | 349 | } |
346 | 350 | ||
347 | treeItem newTreeItem; | 351 | treeItem newTreeItem; |
348 | if (document->isDeepLocked()) { | 352 | if (document->isDeepLocked()) { |
349 | treeEntry->clear(); | 353 | treeEntry->clear(); |
350 | #ifndef PWM_EMBEDDED | 354 | #ifndef PWM_EMBEDDED |
351 | treeEntry->insertTitle(i18n("Categories:")); | 355 | treeEntry->insertTitle(i18n("Categories:")); |
352 | #endif | 356 | #endif |
353 | QString msg(IS_DEEPLOCKED_SHORTMSG); | 357 | QString msg(IS_DEEPLOCKED_SHORTMSG); |
354 | msg += " "; | 358 | msg += " "; |
355 | msg += i18n("(Click here to unlock)"); | 359 | msg += i18n("(Click here to unlock)"); |
356 | treeEntry->insertItem(msg, document, | 360 | treeEntry->insertItem(msg, document, |
357 | SLOT(_deepUnlock())); | 361 | SLOT(_deepUnlock())); |
358 | insertMainWndCtrl(treeEntry, document); | 362 | insertMainWndCtrl(treeEntry, document); |
359 | } else { | 363 | } else { |
360 | rebuildTree(treeEntry, document, &newTreeItem.activeItems); | 364 | rebuildTree(treeEntry, document, &newTreeItem.activeItems); |
361 | } | 365 | } |
362 | newTreeItem.menuId = id; | 366 | newTreeItem.menuId = id; |
363 | newTreeItem.doc = document; | 367 | newTreeItem.doc = document; |
364 | newTreeItem.menu = treeEntry; | 368 | newTreeItem.menu = treeEntry; |
365 | if (treeItemNum == -1) { | 369 | if (treeItemNum == -1) { |
366 | #ifndef PWM_EMBEDDED | 370 | #ifndef PWM_EMBEDDED |
367 | tree.push_back(newTreeItem); | 371 | tree.push_back(newTreeItem); |
368 | #else | 372 | #else |
369 | tree.append(newTreeItem); | 373 | tree.append(newTreeItem); |
370 | #endif | 374 | #endif |
371 | } else { | 375 | } else { |
372 | tree[treeItemNum] = newTreeItem; | 376 | tree[treeItemNum] = newTreeItem; |
373 | } | 377 | } |
374 | } | 378 | } |
375 | 379 | ||
376 | void PwMTray::closeTreeEntry(PwMDoc *document) | 380 | void PwMTray::closeTreeEntry(PwMDoc *document) |
377 | { | 381 | { |
378 | KPopupMenu *menu; | 382 | KPopupMenu *menu; |
379 | int treeItem; | 383 | int treeItem; |
380 | int id = findTreeEntry(document, &menu, &treeItem); | 384 | int id = findTreeEntry(document, &menu, &treeItem); |
381 | if (id != -1) { | 385 | if (id != -1) { |
382 | removeTreeEntry(id, treeItem, &menu); | 386 | removeTreeEntry(id, treeItem, &menu); |
383 | } | 387 | } |
384 | } | 388 | } |
385 | 389 | ||
386 | int PwMTray::findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem) | 390 | int PwMTray::findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem) |
387 | { | 391 | { |
388 | PWM_ASSERT(doc); | 392 | PWM_ASSERT(doc); |
389 | #ifndef PWM_EMBEDDED | 393 | #ifndef PWM_EMBEDDED |
390 | int i, count = tree.size(); | 394 | int i, count = tree.size(); |
391 | #else | 395 | #else |
392 | int i, count = tree.count(); | 396 | int i, count = tree.count(); |
393 | #endif | 397 | #endif |
394 | for (i = 0; i < count; ++i) { | 398 | for (i = 0; i < count; ++i) { |
395 | if (tree[i].doc == doc) { | 399 | if (tree[i].doc == doc) { |
396 | if (menu) | 400 | if (menu) |
397 | *menu = tree[i].menu; | 401 | *menu = tree[i].menu; |
398 | if (treeItem) | 402 | if (treeItem) |
399 | *treeItem = i; | 403 | *treeItem = i; |
400 | return tree[i].menuId; | 404 | return tree[i].menuId; |
401 | } | 405 | } |
402 | } | 406 | } |
403 | if (menu) | 407 | if (menu) |
404 | *menu = 0; | 408 | *menu = 0; |
405 | if (treeItem) | 409 | if (treeItem) |
406 | *treeItem = -1; | 410 | *treeItem = -1; |
407 | return -1; | 411 | return -1; |
408 | } | 412 | } |
409 | 413 | ||
410 | int PwMTray::insertTreeEntry(PwMDoc *doc, KPopupMenu **popup) | 414 | int PwMTray::insertTreeEntry(PwMDoc *doc, KPopupMenu **popup) |
411 | { | 415 | { |
412 | PWM_ASSERT(doc); | 416 | PWM_ASSERT(doc); |
413 | PWM_ASSERT(popup); | 417 | PWM_ASSERT(popup); |
414 | KPopupMenu *ctxMenu = contextMenu(); | 418 | KPopupMenu *ctxMenu = contextMenu(); |
415 | *popup = new KPopupMenu(ctxMenu); | 419 | *popup = new KPopupMenu(ctxMenu); |
416 | return ctxMenu->insertItem(doc->getTitle(), *popup, -1, 1); | 420 | return ctxMenu->insertItem(doc->getTitle(), *popup, -1, 1); |
417 | } | 421 | } |
418 | 422 | ||
419 | void PwMTray::removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu) | 423 | void PwMTray::removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu) |
420 | { | 424 | { |
421 | PWM_ASSERT(menu); | 425 | PWM_ASSERT(menu); |
422 | KPopupMenu *ctxMenu = contextMenu(); | 426 | KPopupMenu *ctxMenu = contextMenu(); |
423 | ctxMenu->removeItem(menuId); | 427 | ctxMenu->removeItem(menuId); |
424 | delete_and_null(*menu); | 428 | delete_and_null(*menu); |
425 | #ifndef PWM_EMBEDDED | 429 | #ifndef PWM_EMBEDDED |
426 | tree.erase(tree.at(treeItem)); | 430 | tree.erase(tree.at(treeItem)); |
427 | #else | 431 | #else |
428 | tree.remove(tree.at(treeItem)); | 432 | tree.remove(tree.at(treeItem)); |
429 | #endif | 433 | #endif |
430 | } | 434 | } |
431 | 435 | ||
432 | void PwMTray::mouseReleaseEvent(QMouseEvent *e) | 436 | void PwMTray::mouseReleaseEvent(QMouseEvent *e) |
433 | { | 437 | { |
434 | QWidget *curWnd = init->curWidget(); | 438 | QWidget *curWnd = init->curWidget(); |
435 | KPopupMenu *ctxMenu = contextMenu(); | 439 | KPopupMenu *ctxMenu = contextMenu(); |
436 | // give focus to init->curWidget() | 440 | // give focus to init->curWidget() |
437 | if (curWnd && !curWnd->hasFocus()) { | 441 | if (curWnd && !curWnd->hasFocus()) { |
438 | curWnd->hide(); | 442 | curWnd->hide(); |
439 | curWnd->showNormal(); | 443 | curWnd->showNormal(); |
440 | curWnd->setFocus(); | 444 | curWnd->setFocus(); |
441 | } | 445 | } |
442 | // popup the context menu | 446 | // popup the context menu |
443 | ctxMenu->popup(e->globalPos()); | 447 | ctxMenu->popup(e->globalPos()); |
444 | emit clickedIcon(this); | 448 | emit clickedIcon(this); |
445 | } | 449 | } |
446 | 450 | ||
447 | void PwMTray::connectDocToTray(PwMDoc *doc) | 451 | void PwMTray::connectDocToTray(PwMDoc *doc) |
448 | { | 452 | { |
449 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), | 453 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), |
450 | this, SLOT(updateTree(PwMDoc *))); | 454 | this, SLOT(updateTree(PwMDoc *))); |
451 | connect(doc, SIGNAL(docClosed(PwMDoc *)), | 455 | connect(doc, SIGNAL(docClosed(PwMDoc *)), |
452 | this, SLOT(closeTreeEntry(PwMDoc *))); | 456 | this, SLOT(closeTreeEntry(PwMDoc *))); |
453 | // fake a dataChanged signal for this doc to update the tray tree. | 457 | // fake a dataChanged signal for this doc to update the tray tree. |
454 | updateTree(doc); | 458 | updateTree(doc); |
455 | } | 459 | } |
456 | 460 | ||
457 | void PwMTray::openDoc() | 461 | void PwMTray::openDoc() |
458 | { | 462 | { |
459 | // open the document in a new window. | 463 | // open the document in a new window. |
460 | PwM *newInstance = init->createMainWnd(); | 464 | PwM *newInstance = init->createMainWnd(); |
461 | PwMDoc *newDoc = newInstance->openDoc(""); | 465 | PwMDoc *newDoc = newInstance->openDoc(""); |
462 | if (!newDoc) { | 466 | if (!newDoc) { |
463 | newInstance->setForceQuit(true); | 467 | newInstance->setForceQuit(true); |
464 | delete_and_null(newInstance); | 468 | delete_and_null(newInstance); |
465 | } | 469 | } |
466 | } | 470 | } |
467 | 471 | ||
468 | void PwMTray::newMainWnd() | 472 | void PwMTray::newMainWnd() |
469 | { | 473 | { |
470 | init->createMainWnd(); | 474 | init->createMainWnd(); |
471 | } | 475 | } |
472 | 476 | ||
473 | void PwMTray::undock() | 477 | void PwMTray::undock() |
474 | { | 478 | { |
475 | conf()->confGlobTray(false); | 479 | conf()->confGlobTray(false); |
476 | init->initTray(); | 480 | init->initTray(); |
477 | // Attention! "this" is already deleted here! | 481 | // Attention! "this" is already deleted here! |
478 | } | 482 | } |
479 | 483 | ||
480 | #ifndef PWM_EMBEDDED | 484 | #ifndef PWM_EMBEDDED |
481 | #include "pwmtray.moc" | 485 | #include "pwmtray.moc" |
482 | #endif | 486 | #endif |
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp index c09fbf5..58c2fca 100644 --- a/pwmanager/pwmanager/pwmview.cpp +++ b/pwmanager/pwmanager/pwmview.cpp | |||
@@ -1,452 +1,456 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2003, 2004 by Michael Buesch * | 3 | * copyright (C) 2003, 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * copyright (C) 2004 by Ulf Schenk | 13 | * copyright (C) 2004 by Ulf Schenk |
14 | * This file is originaly based on version 1.0.1 of pwmanager | 14 | * This file is originaly based on version 1.0.1 of pwmanager |
15 | * and was modified to run on embedded devices that run microkde | 15 | * and was modified to run on embedded devices that run microkde |
16 | * | 16 | * |
17 | * $Id$ | 17 | * $Id$ |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | 19 | ||
20 | #include "pwmview.h" | 20 | #include "pwmview.h" |
21 | #include "pwmexception.h" | 21 | #include "pwmexception.h" |
22 | #include "globalstuff.h" | 22 | #include "globalstuff.h" |
23 | #include "pwm.h" | 23 | #include "pwm.h" |
24 | #include "rencatwnd.h" | 24 | #include "rencatwnd.h" |
25 | #ifndef PWM_EMBEDDED | ||
25 | #include "configuration.h" | 26 | #include "configuration.h" |
27 | #else | ||
28 | #include "pwmprefs.h" | ||
29 | #endif | ||
26 | #include "commentbox.h" | 30 | #include "commentbox.h" |
27 | 31 | ||
28 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
29 | #include <klocale.h> | 33 | #include <klocale.h> |
30 | 34 | ||
31 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
32 | #include <qpoint.h> | 36 | #include <qpoint.h> |
33 | #include <qapplication.h> | 37 | #include <qapplication.h> |
34 | 38 | ||
35 | #define COLUMN_DESC 0 | 39 | #define COLUMN_DESC 0 |
36 | #define COLUMN_NAME 1 | 40 | #define COLUMN_NAME 1 |
37 | #define COLUMN_PW 2 | 41 | #define COLUMN_PW 2 |
38 | #define COLUMN_URL 3 | 42 | #define COLUMN_URL 3 |
39 | #define COLUMN_LAUNCHER 4 | 43 | #define COLUMN_LAUNCHER 4 |
40 | 44 | ||
41 | 45 | ||
42 | PwMView::PwMView(PwM *_mainClass, | 46 | PwMView::PwMView(PwM *_mainClass, |
43 | QWidget *parent, PwMDoc *_doc, | 47 | QWidget *parent, PwMDoc *_doc, |
44 | const char *name) | 48 | const char *name) |
45 | : PwMViewStyle(parent, name) | 49 | : PwMViewStyle(parent, name) |
46 | { | 50 | { |
47 | PWM_ASSERT(_mainClass); | 51 | PWM_ASSERT(_mainClass); |
48 | PWM_ASSERT(parent); | 52 | PWM_ASSERT(parent); |
49 | PWM_ASSERT(_doc); | 53 | PWM_ASSERT(_doc); |
50 | setView(this); | 54 | setView(this); |
51 | doc = _doc; | 55 | doc = _doc; |
52 | doc->setListViewPointer(this); | 56 | doc->setListViewPointer(this); |
53 | mainClass = _mainClass; | 57 | mainClass = _mainClass; |
54 | resize(_mainClass->size()); | 58 | resize(_mainClass->size()); |
55 | initStyle(conf()->confWndMainViewStyle()); | 59 | initStyle(conf()->confWndMainViewStyle()); |
56 | initCtxMenu(); | 60 | initCtxMenu(); |
57 | doc->setCurrentView(this); | 61 | doc->setCurrentView(this); |
58 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); | 62 | connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView())); |
59 | } | 63 | } |
60 | 64 | ||
61 | PwMView::~PwMView() | 65 | PwMView::~PwMView() |
62 | { | 66 | { |
63 | } | 67 | } |
64 | 68 | ||
65 | void PwMView::initCtxMenu() | 69 | void PwMView::initCtxMenu() |
66 | { | 70 | { |
67 | ctxMenu = new QPopupMenu(this); | 71 | ctxMenu = new QPopupMenu(this); |
68 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); | 72 | ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot())); |
69 | ctxMenu->insertSeparator(); | 73 | ctxMenu->insertSeparator(); |
70 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); | 74 | ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot())); |
71 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); | 75 | ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot())); |
72 | ctxMenu->insertSeparator(); | 76 | ctxMenu->insertSeparator(); |
73 | ctxMenu->insertItem(i18n("copy password to clipboard"), | 77 | ctxMenu->insertItem(i18n("copy password to clipboard"), |
74 | this, SLOT(copyPwToClip())); | 78 | this, SLOT(copyPwToClip())); |
75 | ctxMenu->insertItem(i18n("copy username to clipboard"), | 79 | ctxMenu->insertItem(i18n("copy username to clipboard"), |
76 | this, SLOT(copyNameToClip())); | 80 | this, SLOT(copyNameToClip())); |
77 | ctxMenu->insertItem(i18n("copy description to clipboard"), | 81 | ctxMenu->insertItem(i18n("copy description to clipboard"), |
78 | this, SLOT(copyDescToClip())); | 82 | this, SLOT(copyDescToClip())); |
79 | ctxMenu->insertItem(i18n("copy url to clipboard"), | 83 | ctxMenu->insertItem(i18n("copy url to clipboard"), |
80 | this, SLOT(copyUrlToClip())); | 84 | this, SLOT(copyUrlToClip())); |
81 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), | 85 | ctxMenu->insertItem(i18n("copy launcher to clipboard"), |
82 | this, SLOT(copyLauncherToClip())); | 86 | this, SLOT(copyLauncherToClip())); |
83 | ctxMenu->insertItem(i18n("copy comment to clipboard"), | 87 | ctxMenu->insertItem(i18n("copy comment to clipboard"), |
84 | this, SLOT(copyCommentToClip())); | 88 | this, SLOT(copyCommentToClip())); |
85 | ctxMenu->insertSeparator(); | 89 | ctxMenu->insertSeparator(); |
86 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, | 90 | ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass, |
87 | SLOT(execLauncher_slot())); | 91 | SLOT(execLauncher_slot())); |
88 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, | 92 | ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass, |
89 | SLOT(goToURL_slot())); | 93 | SLOT(goToURL_slot())); |
90 | } | 94 | } |
91 | 95 | ||
92 | void PwMView::resizeEvent(QResizeEvent *) | 96 | void PwMView::resizeEvent(QResizeEvent *) |
93 | { | 97 | { |
94 | resizeView(size()); | 98 | resizeView(size()); |
95 | } | 99 | } |
96 | 100 | ||
97 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) | 101 | void PwMView::refreshCommentTextEdit(QListViewItem *curItem) |
98 | { | 102 | { |
99 | PWM_ASSERT(commentBox); | 103 | PWM_ASSERT(commentBox); |
100 | if (!curItem) | 104 | if (!curItem) |
101 | return; | 105 | return; |
102 | string comment; | 106 | string comment; |
103 | PwMerror ret; | 107 | PwMerror ret; |
104 | ret = document()->getCommentByLvp(getCurrentCategory(), | 108 | ret = document()->getCommentByLvp(getCurrentCategory(), |
105 | lv->childCount() - lv->itemIndex(curItem) - 1, | 109 | lv->childCount() - lv->itemIndex(curItem) - 1, |
106 | &comment); | 110 | &comment); |
107 | if (ret == e_binEntry) { | 111 | if (ret == e_binEntry) { |
108 | commentBox->setContent(i18n("This is a binary entry.\n" | 112 | commentBox->setContent(i18n("This is a binary entry.\n" |
109 | "It is not a normal password-entry, as it contains " | 113 | "It is not a normal password-entry, as it contains " |
110 | "binary data, which PwManager can't display here.")); | 114 | "binary data, which PwManager can't display here.")); |
111 | } else if (ret == e_normalEntry) { | 115 | } else if (ret == e_normalEntry) { |
112 | commentBox->setContent(comment.c_str()); | 116 | commentBox->setContent(comment.c_str()); |
113 | } else { | 117 | } else { |
114 | BUG(); | 118 | BUG(); |
115 | return; | 119 | return; |
116 | } | 120 | } |
117 | lv->ensureItemVisible(curItem); | 121 | lv->ensureItemVisible(curItem); |
118 | } | 122 | } |
119 | 123 | ||
120 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) | 124 | void PwMView::keyReleaseEvent(QKeyEvent * /*e*/) |
121 | { | 125 | { |
122 | refreshCommentTextEdit(lv->currentItem()); | 126 | refreshCommentTextEdit(lv->currentItem()); |
123 | } | 127 | } |
124 | 128 | ||
125 | bool PwMView::getCurEntryIndex(unsigned int *index) | 129 | bool PwMView::getCurEntryIndex(unsigned int *index) |
126 | { | 130 | { |
127 | QListViewItem *current = lv->currentItem(); | 131 | QListViewItem *current = lv->currentItem(); |
128 | if (!current) | 132 | if (!current) |
129 | return false; | 133 | return false; |
130 | return getDocEntryIndex(index, current); | 134 | return getDocEntryIndex(index, current); |
131 | } | 135 | } |
132 | 136 | ||
133 | bool PwMView::getDocEntryIndex(unsigned int *index, | 137 | bool PwMView::getDocEntryIndex(unsigned int *index, |
134 | const QListViewItem *item) | 138 | const QListViewItem *item) |
135 | { | 139 | { |
136 | vector<unsigned int> foundPositions; | 140 | vector<unsigned int> foundPositions; |
137 | PwMDataItem curItem; | 141 | PwMDataItem curItem; |
138 | curItem.desc = item->text(COLUMN_DESC).latin1(); | 142 | curItem.desc = item->text(COLUMN_DESC).latin1(); |
139 | curItem.name = item->text(COLUMN_NAME).latin1(); | 143 | curItem.name = item->text(COLUMN_NAME).latin1(); |
140 | document()->getCommentByLvp(getCurrentCategory(), | 144 | document()->getCommentByLvp(getCurrentCategory(), |
141 | lv->childCount() - lv->itemIndex(item) - 1, | 145 | lv->childCount() - lv->itemIndex(item) - 1, |
142 | &curItem.comment); | 146 | &curItem.comment); |
143 | curItem.url = item->text(COLUMN_URL).latin1(); | 147 | curItem.url = item->text(COLUMN_URL).latin1(); |
144 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); | 148 | curItem.launcher = item->text(COLUMN_LAUNCHER).latin1(); |
145 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | | 149 | document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC | |
146 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | | 150 | SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL | |
147 | SEARCH_IN_LAUNCHER, | 151 | SEARCH_IN_LAUNCHER, |
148 | &foundPositions, true); | 152 | &foundPositions, true); |
149 | if (foundPositions.size()) { | 153 | if (foundPositions.size()) { |
150 | *index = foundPositions[0]; | 154 | *index = foundPositions[0]; |
151 | return true; | 155 | return true; |
152 | } | 156 | } |
153 | 157 | ||
154 | return false; | 158 | return false; |
155 | } | 159 | } |
156 | 160 | ||
157 | void PwMView::handleToggle(QListViewItem *item) | 161 | void PwMView::handleToggle(QListViewItem *item) |
158 | { | 162 | { |
159 | PWM_ASSERT(doc); | 163 | PWM_ASSERT(doc); |
160 | if (!item) | 164 | if (!item) |
161 | return; | 165 | return; |
162 | QCheckListItem *clItem = (QCheckListItem *)item; | 166 | QCheckListItem *clItem = (QCheckListItem *)item; |
163 | QString curCat(getCurrentCategory()); | 167 | QString curCat(getCurrentCategory()); |
164 | 168 | ||
165 | // find document position of this entry. | 169 | // find document position of this entry. |
166 | unsigned int curEntryDocIndex; | 170 | unsigned int curEntryDocIndex; |
167 | if (!getDocEntryIndex(&curEntryDocIndex, item)) | 171 | if (!getDocEntryIndex(&curEntryDocIndex, item)) |
168 | return; | 172 | return; |
169 | 173 | ||
170 | // hack to refresh the comment, if only one item is present | 174 | // hack to refresh the comment, if only one item is present |
171 | if (lv->childCount() == 1) | 175 | if (lv->childCount() == 1) |
172 | refreshCommentTextEdit(lv->currentItem()); | 176 | refreshCommentTextEdit(lv->currentItem()); |
173 | 177 | ||
174 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) | 178 | if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn()) |
175 | return; // this is just a click somewhere on the entry | 179 | return; // this is just a click somewhere on the entry |
176 | if (doc->isDeepLocked()) { | 180 | if (doc->isDeepLocked()) { |
177 | PwMerror ret; | 181 | PwMerror ret; |
178 | ret = doc->deepLock(false); | 182 | ret = doc->deepLock(false); |
179 | if (ret != e_success) | 183 | if (ret != e_success) |
180 | clItem->setOn(false); | 184 | clItem->setOn(false); |
181 | return; | 185 | return; |
182 | } | 186 | } |
183 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); | 187 | doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn()); |
184 | } | 188 | } |
185 | 189 | ||
186 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) | 190 | void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int) |
187 | { | 191 | { |
188 | if (!item) | 192 | if (!item) |
189 | return; | 193 | return; |
190 | ctxMenu->move(point); | 194 | ctxMenu->move(point); |
191 | /* don't use ctxMenu->exec() here, as it generates race conditions | 195 | /* don't use ctxMenu->exec() here, as it generates race conditions |
192 | * with the card interface code. Believe it or not. :) | 196 | * with the card interface code. Believe it or not. :) |
193 | */ | 197 | */ |
194 | ctxMenu->show(); | 198 | ctxMenu->show(); |
195 | } | 199 | } |
196 | 200 | ||
197 | void PwMView::updateCategories() | 201 | void PwMView::updateCategories() |
198 | { | 202 | { |
199 | QString oldSel(getCurrentCategory()); | 203 | QString oldSel(getCurrentCategory()); |
200 | delAllCategories(); | 204 | delAllCategories(); |
201 | QStringList catList; | 205 | QStringList catList; |
202 | document()->getCategoryList(&catList); | 206 | document()->getCategoryList(&catList); |
203 | catList.sort(); | 207 | catList.sort(); |
204 | #ifndef PWM_EMBEDDED | 208 | #ifndef PWM_EMBEDDED |
205 | QStringList::iterator i = catList.begin(), | 209 | QStringList::iterator i = catList.begin(), |
206 | end = catList.end(); | 210 | end = catList.end(); |
207 | #else | 211 | #else |
208 | QStringList::Iterator i = catList.begin(), | 212 | QStringList::Iterator i = catList.begin(), |
209 | end = catList.end(); | 213 | end = catList.end(); |
210 | #endif | 214 | #endif |
211 | while (i != end) { | 215 | while (i != end) { |
212 | addCategory(*i); | 216 | addCategory(*i); |
213 | ++i; | 217 | ++i; |
214 | } | 218 | } |
215 | selectCategory(oldSel); | 219 | selectCategory(oldSel); |
216 | } | 220 | } |
217 | 221 | ||
218 | void PwMView::shiftToView() | 222 | void PwMView::shiftToView() |
219 | { | 223 | { |
220 | int cX = lv->contentsX(); | 224 | int cX = lv->contentsX(); |
221 | int cY = lv->contentsY(); | 225 | int cY = lv->contentsY(); |
222 | commentBox->clear(); | 226 | commentBox->clear(); |
223 | 227 | ||
224 | unsigned int catDocIndex; | 228 | unsigned int catDocIndex; |
225 | if (unlikely( | 229 | if (unlikely( |
226 | !(document()->findCategory(getCurrentCategory(), | 230 | !(document()->findCategory(getCurrentCategory(), |
227 | &catDocIndex)))) { | 231 | &catDocIndex)))) { |
228 | BUG(); | 232 | BUG(); |
229 | } | 233 | } |
230 | 234 | ||
231 | // ensure all listViewPos are set | 235 | // ensure all listViewPos are set |
232 | doc->ensureLvp(); | 236 | doc->ensureLvp(); |
233 | 237 | ||
234 | // clear all tmp-data vectors | 238 | // clear all tmp-data vectors |
235 | unsigned int i, entries = doc->numEntries(catDocIndex); | 239 | unsigned int i, entries = doc->numEntries(catDocIndex); |
236 | if (entries) { | 240 | if (entries) { |
237 | mainClass->setVirgin(false); | 241 | mainClass->setVirgin(false); |
238 | } | 242 | } |
239 | vector<PwMDataItem> tmpSorted; | 243 | vector<PwMDataItem> tmpSorted; |
240 | PwMDataItem currItem; | 244 | PwMDataItem currItem; |
241 | currItem.clear(); | 245 | currItem.clear(); |
242 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); | 246 | tmpSorted.insert(tmpSorted.begin(), entries, currItem); |
243 | 247 | ||
244 | // Sort items and store them in tempoary tmpSorted. | 248 | // Sort items and store them in tempoary tmpSorted. |
245 | for (i = 0; i < entries; ++i) { | 249 | for (i = 0; i < entries; ++i) { |
246 | doc->getEntry(catDocIndex, i, &currItem); | 250 | doc->getEntry(catDocIndex, i, &currItem); |
247 | tmpSorted[currItem.listViewPos] = currItem; | 251 | tmpSorted[currItem.listViewPos] = currItem; |
248 | } | 252 | } |
249 | 253 | ||
250 | // shift tempoary data to ListView. | 254 | // shift tempoary data to ListView. |
251 | tmpDisableSort(); | 255 | tmpDisableSort(); |
252 | lv->clear(); | 256 | lv->clear(); |
253 | QCheckListItem *newItem; | 257 | QCheckListItem *newItem; |
254 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), | 258 | vector<PwMDataItem>::iterator it = tmpSorted.begin(), |
255 | end = tmpSorted.end(); | 259 | end = tmpSorted.end(); |
256 | while (it != end) { | 260 | while (it != end) { |
257 | newItem = new ListViewItemPwM(lv); | 261 | newItem = new ListViewItemPwM(lv); |
258 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); | 262 | newItem->setText(COLUMN_DESC, (*it).desc.c_str()); |
259 | if ((*it).binary) { | 263 | if ((*it).binary) { |
260 | newItem->setText(COLUMN_NAME, ""); | 264 | newItem->setText(COLUMN_NAME, ""); |
261 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); | 265 | newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>")); |
262 | newItem->setText(COLUMN_URL, ""); | 266 | newItem->setText(COLUMN_URL, ""); |
263 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 267 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
264 | } else { | 268 | } else { |
265 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); | 269 | newItem->setText(COLUMN_NAME, (*it).name.c_str()); |
266 | if ((*it).lockStat) { | 270 | if ((*it).lockStat) { |
267 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) | 271 | newItem->setText(COLUMN_PW, QString((*it).pw.c_str()) |
268 | + " " | 272 | + " " |
269 | + i18n("To unlock click the icon on the left.")); | 273 | + i18n("To unlock click the icon on the left.")); |
270 | } else { | 274 | } else { |
271 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); | 275 | newItem->setText(COLUMN_PW, (*it).pw.c_str()); |
272 | } | 276 | } |
273 | newItem->setText(COLUMN_URL, (*it).url.c_str()); | 277 | newItem->setText(COLUMN_URL, (*it).url.c_str()); |
274 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); | 278 | newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str()); |
275 | } | 279 | } |
276 | newItem->setOn(!((*it).lockStat)); | 280 | newItem->setOn(!((*it).lockStat)); |
277 | lv->insertItem(newItem); | 281 | lv->insertItem(newItem); |
278 | ++it; | 282 | ++it; |
279 | } | 283 | } |
280 | tmpReEnableSort(); | 284 | tmpReEnableSort(); |
281 | 285 | ||
282 | if (cY || cX) | 286 | if (cY || cX) |
283 | lv->setContentsPos(cX, cY); | 287 | lv->setContentsPos(cX, cY); |
284 | } | 288 | } |
285 | 289 | ||
286 | void PwMView::reorgLp() | 290 | void PwMView::reorgLp() |
287 | { | 291 | { |
288 | if (!lv->childCount()) | 292 | if (!lv->childCount()) |
289 | return; | 293 | return; |
290 | PWM_ASSERT(doc); | 294 | PWM_ASSERT(doc); |
291 | PWM_ASSERT(!doc->isDocEmpty()); | 295 | PWM_ASSERT(!doc->isDocEmpty()); |
292 | QListViewItem *currItem; | 296 | QListViewItem *currItem; |
293 | vector<unsigned int> foundPos; | 297 | vector<unsigned int> foundPos; |
294 | /* This searchIn _should_ be: | 298 | /* This searchIn _should_ be: |
295 | *const unsigned int searchIn = SEARCH_IN_DESC; | 299 | *const unsigned int searchIn = SEARCH_IN_DESC; |
296 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). | 300 | * But we want backward compatibility (see comment in PwMDoc::addEntry()). |
297 | * So we need to search again, if we don't find the entry. (see below) | 301 | * So we need to search again, if we don't find the entry. (see below) |
298 | */ | 302 | */ |
299 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | | 303 | const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME | |
300 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; | 304 | SEARCH_IN_URL | SEARCH_IN_LAUNCHER; |
301 | QString curCat(getCurrentCategory()); | 305 | QString curCat(getCurrentCategory()); |
302 | PwMDataItem findThis; | 306 | PwMDataItem findThis; |
303 | unsigned int i, cnt = lv->childCount(); | 307 | unsigned int i, cnt = lv->childCount(); |
304 | for (i = 0; i < cnt; ++i) { | 308 | for (i = 0; i < cnt; ++i) { |
305 | currItem = lv->itemAtIndex(i); | 309 | currItem = lv->itemAtIndex(i); |
306 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); | 310 | findThis.desc = currItem->text(COLUMN_DESC).latin1(); |
307 | findThis.name = currItem->text(COLUMN_NAME).latin1(); | 311 | findThis.name = currItem->text(COLUMN_NAME).latin1(); |
308 | findThis.url = currItem->text(COLUMN_URL).latin1(); | 312 | findThis.url = currItem->text(COLUMN_URL).latin1(); |
309 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); | 313 | findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1(); |
310 | doc->findEntry(curCat, findThis, searchIn, | 314 | doc->findEntry(curCat, findThis, searchIn, |
311 | &foundPos, true); | 315 | &foundPos, true); |
312 | if (!foundPos.size()) { | 316 | if (!foundPos.size()) { |
313 | /* Did not find the entry. We seem to have a binary | 317 | /* Did not find the entry. We seem to have a binary |
314 | * entry here (pray for it!). So search again with | 318 | * entry here (pray for it!). So search again with |
315 | * the "correct" searchIn flags. | 319 | * the "correct" searchIn flags. |
316 | */ | 320 | */ |
317 | const unsigned int searchIn2 = SEARCH_IN_DESC; | 321 | const unsigned int searchIn2 = SEARCH_IN_DESC; |
318 | doc->findEntry(curCat, findThis, searchIn2, | 322 | doc->findEntry(curCat, findThis, searchIn2, |
319 | &foundPos, true); | 323 | &foundPos, true); |
320 | if (unlikely(!foundPos.size())) { | 324 | if (unlikely(!foundPos.size())) { |
321 | BUG(); | 325 | BUG(); |
322 | continue; | 326 | continue; |
323 | } | 327 | } |
324 | /* We assert that it's a binary entry, now. | 328 | /* We assert that it's a binary entry, now. |
325 | * No chance to efficiently verify it here. | 329 | * No chance to efficiently verify it here. |
326 | */ | 330 | */ |
327 | } | 331 | } |
328 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); | 332 | doc->setListViewPos(curCat, foundPos[0], cnt - i - 1); |
329 | } | 333 | } |
330 | } | 334 | } |
331 | 335 | ||
332 | void PwMView::selAt(int index) | 336 | void PwMView::selAt(int index) |
333 | { | 337 | { |
334 | QListViewItem *item = lv->itemAtIndex(index); | 338 | QListViewItem *item = lv->itemAtIndex(index); |
335 | if (!item) | 339 | if (!item) |
336 | return; | 340 | return; |
337 | lv->setCurrentItem(item); | 341 | lv->setCurrentItem(item); |
338 | lv->ensureItemVisible(item); | 342 | lv->ensureItemVisible(item); |
339 | } | 343 | } |
340 | 344 | ||
341 | void PwMView::renCatButton_slot() | 345 | void PwMView::renCatButton_slot() |
342 | { | 346 | { |
343 | if (doc->isDeepLocked()) | 347 | if (doc->isDeepLocked()) |
344 | return; | 348 | return; |
345 | RenCatWnd wnd(this); | 349 | RenCatWnd wnd(this); |
346 | if (wnd.exec() == 1) { | 350 | if (wnd.exec() == 1) { |
347 | QString newName(wnd.getNewName()); | 351 | QString newName(wnd.getNewName()); |
348 | if (newName == "") | 352 | if (newName == "") |
349 | return; | 353 | return; |
350 | document()->renameCategory(getCurrentCategory(), | 354 | document()->renameCategory(getCurrentCategory(), |
351 | newName); | 355 | newName); |
352 | } | 356 | } |
353 | } | 357 | } |
354 | 358 | ||
355 | void PwMView::delCatButton_slot() | 359 | void PwMView::delCatButton_slot() |
356 | { | 360 | { |
357 | if (doc->isDeepLocked()) | 361 | if (doc->isDeepLocked()) |
358 | return; | 362 | return; |
359 | if (numCategories() <= 1) { | 363 | if (numCategories() <= 1) { |
360 | mainClass->showStatMsg(i18n("Can't remove the last category.")); | 364 | mainClass->showStatMsg(i18n("Can't remove the last category.")); |
361 | return; | 365 | return; |
362 | } | 366 | } |
363 | if (KMessageBox::questionYesNo(this, | 367 | if (KMessageBox::questionYesNo(this, |
364 | i18n("Do you really want to " | 368 | i18n("Do you really want to " |
365 | "delete the selected " | 369 | "delete the selected " |
366 | "category? All password-" | 370 | "category? All password-" |
367 | "entries will be lost in " | 371 | "entries will be lost in " |
368 | "this category!"), | 372 | "this category!"), |
369 | i18n("Delete category?")) | 373 | i18n("Delete category?")) |
370 | == KMessageBox::No) { | 374 | == KMessageBox::No) { |
371 | return; | 375 | return; |
372 | } | 376 | } |
373 | document()->delCategory(getCurrentCategory()); | 377 | document()->delCategory(getCurrentCategory()); |
374 | } | 378 | } |
375 | 379 | ||
376 | void PwMView::copyPwToClip() | 380 | void PwMView::copyPwToClip() |
377 | { | 381 | { |
378 | if (doc->isDeepLocked()) | 382 | if (doc->isDeepLocked()) |
379 | return; | 383 | return; |
380 | unsigned int curIndex = 0; | 384 | unsigned int curIndex = 0; |
381 | if (!getCurEntryIndex(&curIndex)) | 385 | if (!getCurEntryIndex(&curIndex)) |
382 | return; | 386 | return; |
383 | PwMDataItem d; | 387 | PwMDataItem d; |
384 | document()->getDataChangedLock(); | 388 | document()->getDataChangedLock(); |
385 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); | 389 | document()->getEntry(getCurrentCategory(), curIndex, &d, true); |
386 | document()->putDataChangedLock(); | 390 | document()->putDataChangedLock(); |
387 | PwM::copyToClipboard(d.pw.c_str()); | 391 | PwM::copyToClipboard(d.pw.c_str()); |
388 | } | 392 | } |
389 | 393 | ||
390 | void PwMView::copyNameToClip() | 394 | void PwMView::copyNameToClip() |
391 | { | 395 | { |
392 | if (doc->isDeepLocked()) | 396 | if (doc->isDeepLocked()) |
393 | return; | 397 | return; |
394 | unsigned int curIndex = 0; | 398 | unsigned int curIndex = 0; |
395 | if (!getCurEntryIndex(&curIndex)) | 399 | if (!getCurEntryIndex(&curIndex)) |
396 | return; | 400 | return; |
397 | PwMDataItem d; | 401 | PwMDataItem d; |
398 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 402 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
399 | PwM::copyToClipboard(d.name.c_str()); | 403 | PwM::copyToClipboard(d.name.c_str()); |
400 | } | 404 | } |
401 | 405 | ||
402 | void PwMView::copyDescToClip() | 406 | void PwMView::copyDescToClip() |
403 | { | 407 | { |
404 | if (doc->isDeepLocked()) | 408 | if (doc->isDeepLocked()) |
405 | return; | 409 | return; |
406 | unsigned int curIndex = 0; | 410 | unsigned int curIndex = 0; |
407 | if (!getCurEntryIndex(&curIndex)) | 411 | if (!getCurEntryIndex(&curIndex)) |
408 | return; | 412 | return; |
409 | PwMDataItem d; | 413 | PwMDataItem d; |
410 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 414 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
411 | PwM::copyToClipboard(d.desc.c_str()); | 415 | PwM::copyToClipboard(d.desc.c_str()); |
412 | } | 416 | } |
413 | 417 | ||
414 | void PwMView::copyUrlToClip() | 418 | void PwMView::copyUrlToClip() |
415 | { | 419 | { |
416 | if (doc->isDeepLocked()) | 420 | if (doc->isDeepLocked()) |
417 | return; | 421 | return; |
418 | unsigned int curIndex = 0; | 422 | unsigned int curIndex = 0; |
419 | if (!getCurEntryIndex(&curIndex)) | 423 | if (!getCurEntryIndex(&curIndex)) |
420 | return; | 424 | return; |
421 | PwMDataItem d; | 425 | PwMDataItem d; |
422 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 426 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
423 | PwM::copyToClipboard(d.url.c_str()); | 427 | PwM::copyToClipboard(d.url.c_str()); |
424 | } | 428 | } |
425 | 429 | ||
426 | void PwMView::copyLauncherToClip() | 430 | void PwMView::copyLauncherToClip() |
427 | { | 431 | { |
428 | if (doc->isDeepLocked()) | 432 | if (doc->isDeepLocked()) |
429 | return; | 433 | return; |
430 | unsigned int curIndex = 0; | 434 | unsigned int curIndex = 0; |
431 | if (!getCurEntryIndex(&curIndex)) | 435 | if (!getCurEntryIndex(&curIndex)) |
432 | return; | 436 | return; |
433 | PwMDataItem d; | 437 | PwMDataItem d; |
434 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 438 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
435 | PwM::copyToClipboard(d.launcher.c_str()); | 439 | PwM::copyToClipboard(d.launcher.c_str()); |
436 | } | 440 | } |
437 | 441 | ||
438 | void PwMView::copyCommentToClip() | 442 | void PwMView::copyCommentToClip() |
439 | { | 443 | { |
440 | if (doc->isDeepLocked()) | 444 | if (doc->isDeepLocked()) |
441 | return; | 445 | return; |
442 | unsigned int curIndex = 0; | 446 | unsigned int curIndex = 0; |
443 | if (!getCurEntryIndex(&curIndex)) | 447 | if (!getCurEntryIndex(&curIndex)) |
444 | return; | 448 | return; |
445 | PwMDataItem d; | 449 | PwMDataItem d; |
446 | document()->getEntry(getCurrentCategory(), curIndex, &d); | 450 | document()->getEntry(getCurrentCategory(), curIndex, &d); |
447 | PwM::copyToClipboard(d.comment.c_str()); | 451 | PwM::copyToClipboard(d.comment.c_str()); |
448 | } | 452 | } |
449 | 453 | ||
450 | #ifndef PWM_EMBEDDED | 454 | #ifndef PWM_EMBEDDED |
451 | #include "pwmview.moc" | 455 | #include "pwmview.moc" |
452 | #endif | 456 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index 65e442d..f29ef6c 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -1,664 +1,665 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * copyright (C) 2004 by Michael Buesch * | 3 | * copyright (C) 2004 by Michael Buesch * |
4 | * email: mbuesch@freenet.de * | 4 | * email: mbuesch@freenet.de * |
5 | * * | 5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License version 2 * | 7 | * it under the terms of the GNU General Public License version 2 * |
8 | * as published by the Free Software Foundation. * | 8 | * as published by the Free Software Foundation. * |
9 | * * | 9 | * * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | 12 | ||
13 | /*************************************************************************** | 13 | /*************************************************************************** |
14 | * copyright (C) 2004 by Ulf Schenk | 14 | * copyright (C) 2004 by Ulf Schenk |
15 | * This file is originaly based on version 2.0 of pwmanager | 15 | * This file is originaly based on version 2.0 of pwmanager |
16 | * and was modified to run on embedded devices that run microkde | 16 | * and was modified to run on embedded devices that run microkde |
17 | * | 17 | * |
18 | * $Id$ | 18 | * $Id$ |
19 | **************************************************************************/ | 19 | **************************************************************************/ |
20 | 20 | ||
21 | #include "serializer.h" | 21 | #include "serializer.h" |
22 | #include "pwmexception.h" | 22 | #include "pwmexception.h" |
23 | 23 | ||
24 | #ifdef PWM_EMBEDDED | 24 | #ifdef PWM_EMBEDDED |
25 | #include <kglobal.h> | ||
25 | #include <klocale.h> | 26 | #include <klocale.h> |
26 | #endif | 27 | #endif |
27 | 28 | ||
28 | /* enable/disable serializer debugging (0/1) */ | 29 | /* enable/disable serializer debugging (0/1) */ |
29 | #define SERIALIZER_DEBUG0 | 30 | #define SERIALIZER_DEBUG0 |
30 | /* use the old xml tags for writing (0/1) */ | 31 | /* use the old xml tags for writing (0/1) */ |
31 | #define USE_OLD_TAGS 0 | 32 | #define USE_OLD_TAGS 0 |
32 | /* write a CDATA section (0/1) */ | 33 | /* write a CDATA section (0/1) */ |
33 | #define WRITE_CDATA_SEC 0 | 34 | #define WRITE_CDATA_SEC 0 |
34 | 35 | ||
35 | 36 | ||
36 | #define META_CREATE_DATE"c" | 37 | #define META_CREATE_DATE"c" |
37 | #define META_VALID_DATE "v" | 38 | #define META_VALID_DATE "v" |
38 | #define META_EXPIRE_DATE"e" | 39 | #define META_EXPIRE_DATE"e" |
39 | #define META_UPDATE_DATE"u" | 40 | #define META_UPDATE_DATE"u" |
40 | #define META_UPDATE_INT "i" | 41 | #define META_UPDATE_INT "i" |
41 | //US ENH : uniqueid | 42 | //US ENH : uniqueid |
42 | #define META_UNIQUEID "n" | 43 | #define META_UNIQUEID "n" |
43 | 44 | ||
44 | /* This is compatibility stuff. | 45 | /* This is compatibility stuff. |
45 | * The names of the entries have changed and here are the | 46 | * The names of the entries have changed and here are the |
46 | * new and old ones | 47 | * new and old ones |
47 | */ | 48 | */ |
48 | #define ROOT_MAGIC_OLD "PwM-xml-dat" | 49 | #define ROOT_MAGIC_OLD "PwM-xml-dat" |
49 | #define VER_STR_OLD "ver" | 50 | #define VER_STR_OLD "ver" |
50 | #define COMPAT_VER_OLD "0x02" | 51 | #define COMPAT_VER_OLD "0x02" |
51 | #define CAT_ROOT_OLD "categories" | 52 | #define CAT_ROOT_OLD "categories" |
52 | #define CAT_PREFIX_OLD "cat_" | 53 | #define CAT_PREFIX_OLD "cat_" |
53 | #define CAT_NAME_OLD "name" | 54 | #define CAT_NAME_OLD "name" |
54 | #define ENTRY_PREFIX_OLD"entry_" | 55 | #define ENTRY_PREFIX_OLD"entry_" |
55 | #define ENTRY_DESC_OLD "desc" | 56 | #define ENTRY_DESC_OLD "desc" |
56 | #define ENTRY_NAME_OLD "name" | 57 | #define ENTRY_NAME_OLD "name" |
57 | #define ENTRY_PW_OLD "pw" | 58 | #define ENTRY_PW_OLD "pw" |
58 | #define ENTRY_COMMENT_OLD"comment" | 59 | #define ENTRY_COMMENT_OLD"comment" |
59 | #define ENTRY_URL_OLD "url" | 60 | #define ENTRY_URL_OLD "url" |
60 | #define ENTRY_LAUNCHER_OLD"launcher" | 61 | #define ENTRY_LAUNCHER_OLD"launcher" |
61 | #define ENTRY_LVP_OLD "listViewPos" | 62 | #define ENTRY_LVP_OLD "listViewPos" |
62 | #define ENTRY_BIN_OLD "b" | 63 | #define ENTRY_BIN_OLD "b" |
63 | #define ENTRY_META_OLD "m" | 64 | #define ENTRY_META_OLD "m" |
64 | 65 | ||
65 | #define ROOT_MAGIC_NEW "P" | 66 | #define ROOT_MAGIC_NEW "P" |
66 | #define VER_STR_NEW "v" | 67 | #define VER_STR_NEW "v" |
67 | #define COMPAT_VER_NEW "2" | 68 | #define COMPAT_VER_NEW "2" |
68 | #define CAT_ROOT_NEW "c" | 69 | #define CAT_ROOT_NEW "c" |
69 | #define CAT_PREFIX_NEW "c" | 70 | #define CAT_PREFIX_NEW "c" |
70 | #define CAT_NAME_NEW "n" | 71 | #define CAT_NAME_NEW "n" |
71 | #define ENTRY_PREFIX_NEW"e" | 72 | #define ENTRY_PREFIX_NEW"e" |
72 | #define ENTRY_DESC_NEW "d" | 73 | #define ENTRY_DESC_NEW "d" |
73 | #define ENTRY_NAME_NEW "n" | 74 | #define ENTRY_NAME_NEW "n" |
74 | #define ENTRY_PW_NEW "p" | 75 | #define ENTRY_PW_NEW "p" |
75 | #define ENTRY_COMMENT_NEW"c" | 76 | #define ENTRY_COMMENT_NEW"c" |
76 | #define ENTRY_URL_NEW "u" | 77 | #define ENTRY_URL_NEW "u" |
77 | #define ENTRY_LAUNCHER_NEW"l" | 78 | #define ENTRY_LAUNCHER_NEW"l" |
78 | #define ENTRY_LVP_NEW "v" | 79 | #define ENTRY_LVP_NEW "v" |
79 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD | 80 | #define ENTRY_BIN_NEW ENTRY_BIN_OLD |
80 | #define ENTRY_META_NEW ENTRY_META_OLD | 81 | #define ENTRY_META_NEW ENTRY_META_OLD |
81 | 82 | ||
82 | #if USE_OLD_TAGS != 0 | 83 | #if USE_OLD_TAGS != 0 |
83 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD | 84 | # define ROOT_MAGIC_WR ROOT_MAGIC_OLD |
84 | # define VER_STR_WR VER_STR_OLD | 85 | # define VER_STR_WR VER_STR_OLD |
85 | # define COMPAT_VER_WR COMPAT_VER_OLD | 86 | # define COMPAT_VER_WR COMPAT_VER_OLD |
86 | # define CAT_ROOT_WR CAT_ROOT_OLD | 87 | # define CAT_ROOT_WR CAT_ROOT_OLD |
87 | # define CAT_PREFIX_WR CAT_PREFIX_OLD | 88 | # define CAT_PREFIX_WR CAT_PREFIX_OLD |
88 | # define CAT_NAME_WR CAT_NAME_OLD | 89 | # define CAT_NAME_WR CAT_NAME_OLD |
89 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD | 90 | # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD |
90 | # define ENTRY_DESC_WR ENTRY_DESC_OLD | 91 | # define ENTRY_DESC_WR ENTRY_DESC_OLD |
91 | # define ENTRY_NAME_WR ENTRY_NAME_OLD | 92 | # define ENTRY_NAME_WR ENTRY_NAME_OLD |
92 | # define ENTRY_PW_WR ENTRY_PW_OLD | 93 | # define ENTRY_PW_WR ENTRY_PW_OLD |
93 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD | 94 | # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD |
94 | # define ENTRY_URL_WR ENTRY_URL_OLD | 95 | # define ENTRY_URL_WR ENTRY_URL_OLD |
95 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD | 96 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD |
96 | # define ENTRY_LVP_WR ENTRY_LVP_OLD | 97 | # define ENTRY_LVP_WR ENTRY_LVP_OLD |
97 | # define ENTRY_BIN_WR ENTRY_BIN_OLD | 98 | # define ENTRY_BIN_WR ENTRY_BIN_OLD |
98 | # define ENTRY_META_WR ENTRY_META_OLD | 99 | # define ENTRY_META_WR ENTRY_META_OLD |
99 | #else | 100 | #else |
100 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW | 101 | # define ROOT_MAGIC_WR ROOT_MAGIC_NEW |
101 | # define VER_STR_WR VER_STR_NEW | 102 | # define VER_STR_WR VER_STR_NEW |
102 | # define COMPAT_VER_WR COMPAT_VER_NEW | 103 | # define COMPAT_VER_WR COMPAT_VER_NEW |
103 | # define CAT_ROOT_WR CAT_ROOT_NEW | 104 | # define CAT_ROOT_WR CAT_ROOT_NEW |
104 | # define CAT_PREFIX_WR CAT_PREFIX_NEW | 105 | # define CAT_PREFIX_WR CAT_PREFIX_NEW |
105 | # define CAT_NAME_WR CAT_NAME_NEW | 106 | # define CAT_NAME_WR CAT_NAME_NEW |
106 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW | 107 | # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW |
107 | # define ENTRY_DESC_WR ENTRY_DESC_NEW | 108 | # define ENTRY_DESC_WR ENTRY_DESC_NEW |
108 | # define ENTRY_NAME_WR ENTRY_NAME_NEW | 109 | # define ENTRY_NAME_WR ENTRY_NAME_NEW |
109 | # define ENTRY_PW_WR ENTRY_PW_NEW | 110 | # define ENTRY_PW_WR ENTRY_PW_NEW |
110 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW | 111 | # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW |
111 | # define ENTRY_URL_WR ENTRY_URL_NEW | 112 | # define ENTRY_URL_WR ENTRY_URL_NEW |
112 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW | 113 | # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW |
113 | # define ENTRY_LVP_WR ENTRY_LVP_NEW | 114 | # define ENTRY_LVP_WR ENTRY_LVP_NEW |
114 | # define ENTRY_BIN_WR ENTRY_BIN_NEW | 115 | # define ENTRY_BIN_WR ENTRY_BIN_NEW |
115 | # define ENTRY_META_WR ENTRY_META_NEW | 116 | # define ENTRY_META_WR ENTRY_META_NEW |
116 | #endif | 117 | #endif |
117 | 118 | ||
118 | 119 | ||
119 | Serializer::Serializer() | 120 | Serializer::Serializer() |
120 | { | 121 | { |
121 | defaultLockStat = true; | 122 | defaultLockStat = true; |
122 | domDoc = new QDomDocument; | 123 | domDoc = new QDomDocument; |
123 | } | 124 | } |
124 | 125 | ||
125 | Serializer::Serializer(const QCString &buffer) | 126 | Serializer::Serializer(const QCString &buffer) |
126 | { | 127 | { |
127 | defaultLockStat = true; | 128 | defaultLockStat = true; |
128 | domDoc = new QDomDocument; | 129 | domDoc = new QDomDocument; |
129 | if (!parseXml(buffer)) { | 130 | if (!parseXml(buffer)) { |
130 | delete domDoc; | 131 | delete domDoc; |
131 | #ifndef PWM_EMBEDDED | 132 | #ifndef PWM_EMBEDDED |
132 | throw PwMException(PwMException::EX_PARSE); | 133 | throw PwMException(PwMException::EX_PARSE); |
133 | #else | 134 | #else |
134 | qDebug("Serializer::Serializer : Parse Exception "); | 135 | qDebug("Serializer::Serializer : Parse Exception "); |
135 | #endif | 136 | #endif |
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
139 | Serializer::~Serializer() | 140 | Serializer::~Serializer() |
140 | { | 141 | { |
141 | delete_ifnot_null(domDoc); | 142 | delete_ifnot_null(domDoc); |
142 | } | 143 | } |
143 | 144 | ||
144 | void Serializer::clear() | 145 | void Serializer::clear() |
145 | { | 146 | { |
146 | delete_ifnot_null(domDoc); | 147 | delete_ifnot_null(domDoc); |
147 | domDoc = new QDomDocument; | 148 | domDoc = new QDomDocument; |
148 | } | 149 | } |
149 | 150 | ||
150 | bool Serializer::parseXml(const QCString &buffer) | 151 | bool Serializer::parseXml(const QCString &buffer) |
151 | { | 152 | { |
152 | PWM_ASSERT(domDoc); | 153 | PWM_ASSERT(domDoc); |
153 | #ifndef PWM_EMBEDDED | 154 | #ifndef PWM_EMBEDDED |
154 | if (!domDoc->setContent(buffer, true)) | 155 | if (!domDoc->setContent(buffer, true)) |
155 | return false; | 156 | return false; |
156 | #else | 157 | #else |
157 | if (!domDoc->setContent(buffer)) | 158 | if (!domDoc->setContent(buffer)) |
158 | return false; | 159 | return false; |
159 | #endif | 160 | #endif |
160 | if (!checkValid()) | 161 | if (!checkValid()) |
161 | return false; | 162 | return false; |
162 | return true; | 163 | return true; |
163 | } | 164 | } |
164 | 165 | ||
165 | QCString Serializer::getXml() | 166 | QCString Serializer::getXml() |
166 | { | 167 | { |
167 | PWM_ASSERT(domDoc); | 168 | PWM_ASSERT(domDoc); |
168 | 169 | ||
169 | #ifndef PWM_EMBEDDED | 170 | #ifndef PWM_EMBEDDED |
170 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 171 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
171 | QCString tmp(domDoc->toCString(8)); | 172 | QCString tmp(domDoc->toCString(8)); |
172 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 173 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
173 | cout << tmp << endl; | 174 | cout << tmp << endl; |
174 | printDebug("<END Serializer::getXml() dump>"); | 175 | printDebug("<END Serializer::getXml() dump>"); |
175 | #endif // DEBUG | 176 | #endif // DEBUG |
176 | 177 | ||
177 | QCString ret(domDoc->toCString(0)); | 178 | QCString ret(domDoc->toCString(0)); |
178 | ret.replace('\n', ""); | 179 | ret.replace('\n', ""); |
179 | return ret; | 180 | return ret; |
180 | #else | 181 | #else |
181 | 182 | ||
182 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 | 183 | #if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0 |
183 | QCString tmp(" " + domDoc->toCString()); | 184 | QCString tmp(" " + domDoc->toCString()); |
184 | printDebug("<BEGIN Serializer::getXml() dump>\n"); | 185 | printDebug("<BEGIN Serializer::getXml() dump>\n"); |
185 | cout << tmp << endl; | 186 | cout << tmp << endl; |
186 | printDebug("<END Serializer::getXml() dump>"); | 187 | printDebug("<END Serializer::getXml() dump>"); |
187 | #endif // DEBUG | 188 | #endif // DEBUG |
188 | 189 | ||
189 | QCString ret(domDoc->toCString()); | 190 | QCString ret(domDoc->toCString()); |
190 | ret.replace(QRegExp("\n"), ""); | 191 | ret.replace(QRegExp("\n"), ""); |
191 | return ret; | 192 | return ret; |
192 | 193 | ||
193 | #endif | 194 | #endif |
194 | } | 195 | } |
195 | 196 | ||
196 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) | 197 | bool Serializer::serialize(const vector<PwMCategoryItem> &dta) |
197 | { | 198 | { |
198 | PWM_ASSERT(domDoc); | 199 | PWM_ASSERT(domDoc); |
199 | QDomElement root(genNewRoot()); | 200 | QDomElement root(genNewRoot()); |
200 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); | 201 | QDomElement catNode(domDoc->createElement(CAT_ROOT_WR)); |
201 | root.appendChild(catNode); | 202 | root.appendChild(catNode); |
202 | if (!addCategories(&catNode, dta)) | 203 | if (!addCategories(&catNode, dta)) |
203 | return false; | 204 | return false; |
204 | return true; | 205 | return true; |
205 | } | 206 | } |
206 | 207 | ||
207 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) | 208 | bool Serializer::deSerialize(vector<PwMCategoryItem> *dta) |
208 | { | 209 | { |
209 | PWM_ASSERT(domDoc); | 210 | PWM_ASSERT(domDoc); |
210 | PWM_ASSERT(dta); | 211 | PWM_ASSERT(dta); |
211 | QDomElement root(domDoc->documentElement()); | 212 | QDomElement root(domDoc->documentElement()); |
212 | QDomNode n; | 213 | QDomNode n; |
213 | 214 | ||
214 | dta->clear(); | 215 | dta->clear(); |
215 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { | 216 | for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) { |
216 | // find <categories> ... </categories> | 217 | // find <categories> ... </categories> |
217 | // <c> ... </c> | 218 | // <c> ... </c> |
218 | if (n.nodeName() == CAT_ROOT_NEW || | 219 | if (n.nodeName() == CAT_ROOT_NEW || |
219 | n.nodeName() == CAT_ROOT_OLD) { | 220 | n.nodeName() == CAT_ROOT_OLD) { |
220 | if (!readCategories(n, dta)) { | 221 | if (!readCategories(n, dta)) { |
221 | return false; | 222 | return false; |
222 | } | 223 | } |
223 | 224 | ||
224 | /* NOTE: We can stop processing here, as we | 225 | /* NOTE: We can stop processing here, as we |
225 | * don't have more nodes in root, yet. | 226 | * don't have more nodes in root, yet. |
226 | */ | 227 | */ |
227 | return true; | 228 | return true; |
228 | } | 229 | } |
229 | } | 230 | } |
230 | return false; | 231 | return false; |
231 | } | 232 | } |
232 | 233 | ||
233 | bool Serializer::readCategories(const QDomNode &n, | 234 | bool Serializer::readCategories(const QDomNode &n, |
234 | vector<PwMCategoryItem> *dta) | 235 | vector<PwMCategoryItem> *dta) |
235 | { | 236 | { |
236 | QDomNodeList nl(n.childNodes()); | 237 | QDomNodeList nl(n.childNodes()); |
237 | QDomNode cur; | 238 | QDomNode cur; |
238 | QString name; | 239 | QString name; |
239 | unsigned int numCat = nl.count(), i; | 240 | unsigned int numCat = nl.count(), i; |
240 | PwMCategoryItem curCat; | 241 | PwMCategoryItem curCat; |
241 | vector<PwMDataItem> curEntr; | 242 | vector<PwMDataItem> curEntr; |
242 | 243 | ||
243 | if (!numCat) { | 244 | if (!numCat) { |
244 | printDebug("Serializer::readCategories(): empty"); | 245 | printDebug("Serializer::readCategories(): empty"); |
245 | return false; | 246 | return false; |
246 | } | 247 | } |
247 | for (i = 0; i < numCat; ++i) { | 248 | for (i = 0; i < numCat; ++i) { |
248 | cur = nl.item(i); | 249 | cur = nl.item(i); |
249 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || | 250 | if (cur.nodeName().left(1) == CAT_PREFIX_NEW || |
250 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { | 251 | cur.nodeName().left(4) == CAT_PREFIX_OLD) { |
251 | name = cur.toElement().attribute(CAT_NAME_NEW); | 252 | name = cur.toElement().attribute(CAT_NAME_NEW); |
252 | if (name == QString::null) | 253 | if (name == QString::null) |
253 | name = cur.toElement().attribute(CAT_NAME_OLD); | 254 | name = cur.toElement().attribute(CAT_NAME_OLD); |
254 | PWM_ASSERT(name != QString::null); | 255 | PWM_ASSERT(name != QString::null); |
255 | PWM_ASSERT(name != ""); | 256 | PWM_ASSERT(name != ""); |
256 | curCat.clear(); | 257 | curCat.clear(); |
257 | curCat.name = name.latin1(); | 258 | curCat.name = name.latin1(); |
258 | if (!readEntries(cur, &curEntr)) { | 259 | if (!readEntries(cur, &curEntr)) { |
259 | dta->clear(); | 260 | dta->clear(); |
260 | return false; | 261 | return false; |
261 | } | 262 | } |
262 | curCat.d = curEntr; | 263 | curCat.d = curEntr; |
263 | dta->push_back(curCat); | 264 | dta->push_back(curCat); |
264 | } else { | 265 | } else { |
265 | printDebug("Serializer::readCategories(): uh? not a category?"); | 266 | printDebug("Serializer::readCategories(): uh? not a category?"); |
266 | } | 267 | } |
267 | } | 268 | } |
268 | return true; | 269 | return true; |
269 | } | 270 | } |
270 | 271 | ||
271 | bool Serializer::readEntries(const QDomNode &n, | 272 | bool Serializer::readEntries(const QDomNode &n, |
272 | vector<PwMDataItem> *dta) | 273 | vector<PwMDataItem> *dta) |
273 | { | 274 | { |
274 | QDomNodeList nl(n.childNodes()); | 275 | QDomNodeList nl(n.childNodes()); |
275 | QDomNode cur; | 276 | QDomNode cur; |
276 | unsigned int numEntr = nl.count(), i; | 277 | unsigned int numEntr = nl.count(), i; |
277 | PwMDataItem curEntr; | 278 | PwMDataItem curEntr; |
278 | 279 | ||
279 | dta->clear(); | 280 | dta->clear(); |
280 | for (i = 0; i < numEntr; ++i) { | 281 | for (i = 0; i < numEntr; ++i) { |
281 | cur = nl.item(i); | 282 | cur = nl.item(i); |
282 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || | 283 | if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW || |
283 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { | 284 | cur.nodeName().left(6) == ENTRY_PREFIX_OLD) { |
284 | if (!extractEntry(cur, &curEntr)) { | 285 | if (!extractEntry(cur, &curEntr)) { |
285 | return false; | 286 | return false; |
286 | } | 287 | } |
287 | dta->push_back(curEntr); | 288 | dta->push_back(curEntr); |
288 | } else { | 289 | } else { |
289 | printDebug("Serializer::readEntries(): hm? not an entry?"); | 290 | printDebug("Serializer::readEntries(): hm? not an entry?"); |
290 | } | 291 | } |
291 | } | 292 | } |
292 | return true; | 293 | return true; |
293 | } | 294 | } |
294 | 295 | ||
295 | bool Serializer::extractEntry(const QDomNode &n, | 296 | bool Serializer::extractEntry(const QDomNode &n, |
296 | PwMDataItem *dta) | 297 | PwMDataItem *dta) |
297 | { | 298 | { |
298 | QDomNodeList nl(n.childNodes()); | 299 | QDomNodeList nl(n.childNodes()); |
299 | QDomNode cur, cdata; | 300 | QDomNode cur, cdata; |
300 | unsigned int cnt = nl.count(), i; | 301 | unsigned int cnt = nl.count(), i; |
301 | QString name, text; | 302 | QString name, text; |
302 | 303 | ||
303 | if (!cnt) { | 304 | if (!cnt) { |
304 | printDebug("Serializer::extractEntry(): empty"); | 305 | printDebug("Serializer::extractEntry(): empty"); |
305 | return false; | 306 | return false; |
306 | } | 307 | } |
307 | dta->clear(); | 308 | dta->clear(); |
308 | for (i = 0; i < cnt; ++i) { | 309 | for (i = 0; i < cnt; ++i) { |
309 | cur = nl.item(i); | 310 | cur = nl.item(i); |
310 | name = cur.nodeName(); | 311 | name = cur.nodeName(); |
311 | cdata = cur.firstChild(); | 312 | cdata = cur.firstChild(); |
312 | if (unlikely(cdata.isCDATASection())) { | 313 | if (unlikely(cdata.isCDATASection())) { |
313 | text = cdata.toCDATASection().data(); | 314 | text = cdata.toCDATASection().data(); |
314 | } else if (likely(cur.isElement())) { | 315 | } else if (likely(cur.isElement())) { |
315 | text = cur.toElement().text(); | 316 | text = cur.toElement().text(); |
316 | } else { | 317 | } else { |
317 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); | 318 | printDebug("Serializer::extractEntry(): neither CDATA nor element."); |
318 | return false; | 319 | return false; |
319 | } | 320 | } |
320 | if (text == " ") | 321 | if (text == " ") |
321 | text = ""; // for backward compatibility. | 322 | text = ""; // for backward compatibility. |
322 | if (name == ENTRY_DESC_NEW || | 323 | if (name == ENTRY_DESC_NEW || |
323 | name == ENTRY_DESC_OLD) { | 324 | name == ENTRY_DESC_OLD) { |
324 | dta->desc = unescapeEntryData(text).latin1(); | 325 | dta->desc = unescapeEntryData(text).latin1(); |
325 | } else if (name == ENTRY_NAME_NEW || | 326 | } else if (name == ENTRY_NAME_NEW || |
326 | name == ENTRY_NAME_OLD) { | 327 | name == ENTRY_NAME_OLD) { |
327 | dta->name = unescapeEntryData(text).latin1(); | 328 | dta->name = unescapeEntryData(text).latin1(); |
328 | } else if (name == ENTRY_PW_NEW || | 329 | } else if (name == ENTRY_PW_NEW || |
329 | name == ENTRY_PW_OLD) { | 330 | name == ENTRY_PW_OLD) { |
330 | dta->pw = unescapeEntryData(text).latin1(); | 331 | dta->pw = unescapeEntryData(text).latin1(); |
331 | } else if (name == ENTRY_COMMENT_NEW || | 332 | } else if (name == ENTRY_COMMENT_NEW || |
332 | name == ENTRY_COMMENT_OLD) { | 333 | name == ENTRY_COMMENT_OLD) { |
333 | dta->comment = unescapeEntryData(text).latin1(); | 334 | dta->comment = unescapeEntryData(text).latin1(); |
334 | } else if (name == ENTRY_URL_NEW || | 335 | } else if (name == ENTRY_URL_NEW || |
335 | name == ENTRY_URL_OLD) { | 336 | name == ENTRY_URL_OLD) { |
336 | dta->url = unescapeEntryData(text).latin1(); | 337 | dta->url = unescapeEntryData(text).latin1(); |
337 | } else if (name == ENTRY_LAUNCHER_NEW || | 338 | } else if (name == ENTRY_LAUNCHER_NEW || |
338 | name == ENTRY_LAUNCHER_OLD) { | 339 | name == ENTRY_LAUNCHER_OLD) { |
339 | dta->launcher = unescapeEntryData(text).latin1(); | 340 | dta->launcher = unescapeEntryData(text).latin1(); |
340 | } else if (name == ENTRY_LVP_NEW || | 341 | } else if (name == ENTRY_LVP_NEW || |
341 | name == ENTRY_LVP_OLD) { | 342 | name == ENTRY_LVP_OLD) { |
342 | dta->listViewPos = strtol(text.latin1(), 0, 10); | 343 | dta->listViewPos = strtol(text.latin1(), 0, 10); |
343 | } else if (name == ENTRY_BIN_NEW) { | 344 | } else if (name == ENTRY_BIN_NEW) { |
344 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD | 345 | // ENTRY_BIN_NEW == ENTRY_BIN_OLD |
345 | if (text == "0") { | 346 | if (text == "0") { |
346 | dta->binary = false; | 347 | dta->binary = false; |
347 | } else { | 348 | } else { |
348 | dta->binary = true; | 349 | dta->binary = true; |
349 | } | 350 | } |
350 | } else if (name == ENTRY_META_NEW) { | 351 | } else if (name == ENTRY_META_NEW) { |
351 | // ENTRY_META_NEW == ENTRY_META_OLD | 352 | // ENTRY_META_NEW == ENTRY_META_OLD |
352 | if (!extractMeta(cur, &dta->meta)) | 353 | if (!extractMeta(cur, &dta->meta)) |
353 | return false; | 354 | return false; |
354 | } else { | 355 | } else { |
355 | printDebug(string("Serializer::extractEntry(): invalid: ") | 356 | printDebug(string("Serializer::extractEntry(): invalid: ") |
356 | + name.latin1()); | 357 | + name.latin1()); |
357 | } | 358 | } |
358 | } | 359 | } |
359 | dta->lockStat = defaultLockStat; | 360 | dta->lockStat = defaultLockStat; |
360 | return true; | 361 | return true; |
361 | } | 362 | } |
362 | 363 | ||
363 | bool Serializer::extractMeta(const QDomNode &n, | 364 | bool Serializer::extractMeta(const QDomNode &n, |
364 | PwMMetaData *dta) | 365 | PwMMetaData *dta) |
365 | { | 366 | { |
366 | QDomNode cur(n.firstChild()); | 367 | QDomNode cur(n.firstChild()); |
367 | QString name, val; | 368 | QString name, val; |
368 | while (!cur.isNull()) { | 369 | while (!cur.isNull()) { |
369 | name = cur.nodeName(); | 370 | name = cur.nodeName(); |
370 | val = cur.toElement().text(); | 371 | val = cur.toElement().text(); |
371 | if (val == "") { | 372 | if (val == "") { |
372 | cur = cur.nextSibling(); | 373 | cur = cur.nextSibling(); |
373 | continue; | 374 | continue; |
374 | } | 375 | } |
375 | #ifndef PWM_EMBEDDED | 376 | #ifndef PWM_EMBEDDED |
376 | if (name == META_CREATE_DATE) { | 377 | if (name == META_CREATE_DATE) { |
377 | dta->create = QDateTime::fromString(val, Qt::ISODate); | 378 | dta->create = QDateTime::fromString(val, Qt::ISODate); |
378 | } else if (name == META_VALID_DATE) { | 379 | } else if (name == META_VALID_DATE) { |
379 | dta->valid = QDateTime::fromString(val, Qt::ISODate); | 380 | dta->valid = QDateTime::fromString(val, Qt::ISODate); |
380 | } else if (name == META_EXPIRE_DATE) { | 381 | } else if (name == META_EXPIRE_DATE) { |
381 | dta->expire = QDateTime::fromString(val, Qt::ISODate); | 382 | dta->expire = QDateTime::fromString(val, Qt::ISODate); |
382 | } else if (name == META_UPDATE_DATE) { | 383 | } else if (name == META_UPDATE_DATE) { |
383 | dta->update = QDateTime::fromString(val, Qt::ISODate); | 384 | dta->update = QDateTime::fromString(val, Qt::ISODate); |
384 | } else if (name == META_UPDATE_INT) { | 385 | } else if (name == META_UPDATE_INT) { |
385 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 386 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
386 | } else if (name == META_UNIQUEID) { | 387 | } else if (name == META_UNIQUEID) { |
387 | dta->uniqueid = unescapeEntryData(val).latin1(); | 388 | dta->uniqueid = unescapeEntryData(val).latin1(); |
388 | } else { | 389 | } else { |
389 | printDebug(string("extractMeta(): invalid: ") | 390 | printDebug(string("extractMeta(): invalid: ") |
390 | + name.latin1()); | 391 | + name.latin1()); |
391 | } | 392 | } |
392 | #else | 393 | #else |
393 | 394 | ||
394 | QDateTime m_dt; | 395 | QDateTime m_dt; |
395 | 396 | ||
396 | if ((name == META_CREATE_DATE) || | 397 | if ((name == META_CREATE_DATE) || |
397 | (name == META_VALID_DATE) || | 398 | (name == META_VALID_DATE) || |
398 | (name == META_EXPIRE_DATE) || | 399 | (name == META_EXPIRE_DATE) || |
399 | (name == META_UPDATE_DATE)) | 400 | (name == META_UPDATE_DATE)) |
400 | { | 401 | { |
401 | int pos = val.find("T"); | 402 | int pos = val.find("T"); |
402 | QString date = val.left(pos); | 403 | QString date = val.left(pos); |
403 | QString time = val.mid(pos+1); | 404 | QString time = val.mid(pos+1); |
404 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); | 405 | qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() ); |
405 | bool ok1, ok2; | 406 | bool ok1, ok2; |
406 | 407 | ||
407 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); | 408 | QDate m_date = KGlobal::locale()->readDate(date, &ok1); |
408 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); | 409 | QTime m_time = KGlobal::locale()->readTime(time, &ok2); |
409 | if ((ok1 == false) || (ok2 == false)) | 410 | if ((ok1 == false) || (ok2 == false)) |
410 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); | 411 | qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!"); |
411 | m_dt.setDate(m_date); | 412 | m_dt.setDate(m_date); |
412 | m_dt.setTime(m_time); | 413 | m_dt.setTime(m_time); |
413 | } | 414 | } |
414 | 415 | ||
415 | 416 | ||
416 | if (name == META_CREATE_DATE) { | 417 | if (name == META_CREATE_DATE) { |
417 | dta->create = m_dt; | 418 | dta->create = m_dt; |
418 | } else if (name == META_VALID_DATE) { | 419 | } else if (name == META_VALID_DATE) { |
419 | dta->valid = m_dt; | 420 | dta->valid = m_dt; |
420 | } else if (name == META_EXPIRE_DATE) { | 421 | } else if (name == META_EXPIRE_DATE) { |
421 | dta->expire = m_dt; | 422 | dta->expire = m_dt; |
422 | } else if (name == META_UPDATE_DATE) { | 423 | } else if (name == META_UPDATE_DATE) { |
423 | dta->update = m_dt; | 424 | dta->update = m_dt; |
424 | } else if (name == META_UPDATE_INT) { | 425 | } else if (name == META_UPDATE_INT) { |
425 | dta->updateInt = strtoul(val.latin1(), 0, 10); | 426 | dta->updateInt = strtoul(val.latin1(), 0, 10); |
426 | } else if (name == META_UNIQUEID) { | 427 | } else if (name == META_UNIQUEID) { |
427 | dta->uniqueid = unescapeEntryData(val).latin1(); | 428 | dta->uniqueid = unescapeEntryData(val).latin1(); |
428 | } else { | 429 | } else { |
429 | printDebug(string("extractMeta(): invalid: ") | 430 | printDebug(string("extractMeta(): invalid: ") |
430 | + name.latin1()); | 431 | + name.latin1()); |
431 | } | 432 | } |
432 | #endif | 433 | #endif |
433 | cur = cur.nextSibling(); | 434 | cur = cur.nextSibling(); |
434 | } | 435 | } |
435 | return true; | 436 | return true; |
436 | } | 437 | } |
437 | 438 | ||
438 | bool Serializer::checkValid() | 439 | bool Serializer::checkValid() |
439 | { | 440 | { |
440 | PWM_ASSERT(domDoc); | 441 | PWM_ASSERT(domDoc); |
441 | QDomElement root(domDoc->documentElement()); | 442 | QDomElement root(domDoc->documentElement()); |
442 | if (root.nodeName() != ROOT_MAGIC_NEW && | 443 | if (root.nodeName() != ROOT_MAGIC_NEW && |
443 | root.nodeName() != ROOT_MAGIC_OLD) { | 444 | root.nodeName() != ROOT_MAGIC_OLD) { |
444 | printDebug("Serializer: wrong magic"); | 445 | printDebug("Serializer: wrong magic"); |
445 | return false; | 446 | return false; |
446 | } | 447 | } |
447 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && | 448 | if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW && |
448 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { | 449 | root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) { |
449 | printDebug("Serializer: wrong version"); | 450 | printDebug("Serializer: wrong version"); |
450 | return false; | 451 | return false; |
451 | } | 452 | } |
452 | return true; | 453 | return true; |
453 | } | 454 | } |
454 | 455 | ||
455 | QDomElement Serializer::genNewRoot() | 456 | QDomElement Serializer::genNewRoot() |
456 | { | 457 | { |
457 | PWM_ASSERT(domDoc); | 458 | PWM_ASSERT(domDoc); |
458 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); | 459 | QDomElement root(domDoc->createElement(ROOT_MAGIC_WR)); |
459 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); | 460 | root.setAttribute(VER_STR_WR, COMPAT_VER_WR); |
460 | domDoc->appendChild(root); | 461 | domDoc->appendChild(root); |
461 | return root; | 462 | return root; |
462 | } | 463 | } |
463 | 464 | ||
464 | bool Serializer::addCategories(QDomElement *e, | 465 | bool Serializer::addCategories(QDomElement *e, |
465 | const vector<PwMCategoryItem> &dta) | 466 | const vector<PwMCategoryItem> &dta) |
466 | { | 467 | { |
467 | unsigned int numCat = dta.size(), i; | 468 | unsigned int numCat = dta.size(), i; |
468 | QString curId, curName; | 469 | QString curId, curName; |
469 | QDomElement curCat; | 470 | QDomElement curCat; |
470 | 471 | ||
471 | for (i = 0; i < numCat; ++i) { | 472 | for (i = 0; i < numCat; ++i) { |
472 | curId = CAT_PREFIX_WR; | 473 | curId = CAT_PREFIX_WR; |
473 | curId += tostr(i).c_str(); | 474 | curId += tostr(i).c_str(); |
474 | curName = dta[i].name.c_str(); | 475 | curName = dta[i].name.c_str(); |
475 | curCat = domDoc->createElement(curId); | 476 | curCat = domDoc->createElement(curId); |
476 | curCat.setAttribute(CAT_NAME_WR, curName); | 477 | curCat.setAttribute(CAT_NAME_WR, curName); |
477 | if (!addEntries(&curCat, dta[i].d)) { | 478 | if (!addEntries(&curCat, dta[i].d)) { |
478 | return false; | 479 | return false; |
479 | } | 480 | } |
480 | e->appendChild(curCat); | 481 | e->appendChild(curCat); |
481 | } | 482 | } |
482 | return true; | 483 | return true; |
483 | } | 484 | } |
484 | 485 | ||
485 | bool Serializer::addEntries(QDomElement *e, | 486 | bool Serializer::addEntries(QDomElement *e, |
486 | const vector<PwMDataItem> &dta) | 487 | const vector<PwMDataItem> &dta) |
487 | { | 488 | { |
488 | unsigned int numEntr = dta.size(), i; | 489 | unsigned int numEntr = dta.size(), i; |
489 | QString curId; | 490 | QString curId; |
490 | QDomElement curEntr; | 491 | QDomElement curEntr; |
491 | 492 | ||
492 | for (i = 0; i < numEntr; ++i) { | 493 | for (i = 0; i < numEntr; ++i) { |
493 | curId = ENTRY_PREFIX_WR; | 494 | curId = ENTRY_PREFIX_WR; |
494 | curId += tostr(i).c_str(); | 495 | curId += tostr(i).c_str(); |
495 | curEntr = domDoc->createElement(curId); | 496 | curEntr = domDoc->createElement(curId); |
496 | if (!writeEntry(&curEntr, dta[i])) { | 497 | if (!writeEntry(&curEntr, dta[i])) { |
497 | return false; | 498 | return false; |
498 | } | 499 | } |
499 | e->appendChild(curEntr); | 500 | e->appendChild(curEntr); |
500 | } | 501 | } |
501 | return true; | 502 | return true; |
502 | } | 503 | } |
503 | 504 | ||
504 | bool Serializer::writeEntry(QDomElement *e, | 505 | bool Serializer::writeEntry(QDomElement *e, |
505 | const PwMDataItem &_dta) | 506 | const PwMDataItem &_dta) |
506 | { | 507 | { |
507 | #if WRITE_CDATA_SEC != 0 | 508 | #if WRITE_CDATA_SEC != 0 |
508 | # define new_text(x)domDoc->createCDATASection(x) | 509 | # define new_text(x)domDoc->createCDATASection(x) |
509 | QDomCDATASection curText; | 510 | QDomCDATASection curText; |
510 | #else | 511 | #else |
511 | # define new_text(x)domDoc->createTextNode(x) | 512 | # define new_text(x)domDoc->createTextNode(x) |
512 | QDomText curText; | 513 | QDomText curText; |
513 | #endif | 514 | #endif |
514 | 515 | ||
515 | QDomText plainText; | 516 | QDomText plainText; |
516 | QDomElement tag; | 517 | QDomElement tag; |
517 | 518 | ||
518 | // begin -- This is for compatibility with the old serializer | 519 | // begin -- This is for compatibility with the old serializer |
519 | PwMDataItem dta = _dta; | 520 | PwMDataItem dta = _dta; |
520 | if (!dta.desc.size()) | 521 | if (!dta.desc.size()) |
521 | dta.desc = " "; | 522 | dta.desc = " "; |
522 | if (!dta.name.size()) | 523 | if (!dta.name.size()) |
523 | dta.name = " "; | 524 | dta.name = " "; |
524 | if (!dta.pw.size()) | 525 | if (!dta.pw.size()) |
525 | dta.pw = " "; | 526 | dta.pw = " "; |
526 | if (!dta.comment.size()) | 527 | if (!dta.comment.size()) |
527 | dta.comment = " "; | 528 | dta.comment = " "; |
528 | if (!dta.url.size()) | 529 | if (!dta.url.size()) |
529 | dta.url = " "; | 530 | dta.url = " "; |
530 | if (!dta.launcher.size()) | 531 | if (!dta.launcher.size()) |
531 | dta.launcher = " "; | 532 | dta.launcher = " "; |
532 | // end -- This is for compatibility with the old serializer | 533 | // end -- This is for compatibility with the old serializer |
533 | 534 | ||
534 | tag = domDoc->createElement(ENTRY_DESC_WR); | 535 | tag = domDoc->createElement(ENTRY_DESC_WR); |
535 | curText = new_text(escapeEntryData(dta.desc.c_str())); | 536 | curText = new_text(escapeEntryData(dta.desc.c_str())); |
536 | tag.appendChild(curText); | 537 | tag.appendChild(curText); |
537 | e->appendChild(tag); | 538 | e->appendChild(tag); |
538 | 539 | ||
539 | tag = domDoc->createElement(ENTRY_NAME_WR); | 540 | tag = domDoc->createElement(ENTRY_NAME_WR); |
540 | curText = new_text(escapeEntryData(dta.name.c_str())); | 541 | curText = new_text(escapeEntryData(dta.name.c_str())); |
541 | tag.appendChild(curText); | 542 | tag.appendChild(curText); |
542 | e->appendChild(tag); | 543 | e->appendChild(tag); |
543 | 544 | ||
544 | tag = domDoc->createElement(ENTRY_PW_WR); | 545 | tag = domDoc->createElement(ENTRY_PW_WR); |
545 | curText = new_text(escapeEntryData(dta.pw.c_str())); | 546 | curText = new_text(escapeEntryData(dta.pw.c_str())); |
546 | tag.appendChild(curText); | 547 | tag.appendChild(curText); |
547 | e->appendChild(tag); | 548 | e->appendChild(tag); |
548 | 549 | ||
549 | tag = domDoc->createElement(ENTRY_COMMENT_WR); | 550 | tag = domDoc->createElement(ENTRY_COMMENT_WR); |
550 | curText = new_text(escapeEntryData(dta.comment.c_str())); | 551 | curText = new_text(escapeEntryData(dta.comment.c_str())); |
551 | tag.appendChild(curText); | 552 | tag.appendChild(curText); |
552 | e->appendChild(tag); | 553 | e->appendChild(tag); |
553 | 554 | ||
554 | tag = domDoc->createElement(ENTRY_URL_WR); | 555 | tag = domDoc->createElement(ENTRY_URL_WR); |
555 | curText = new_text(escapeEntryData(dta.url.c_str())); | 556 | curText = new_text(escapeEntryData(dta.url.c_str())); |
556 | tag.appendChild(curText); | 557 | tag.appendChild(curText); |
557 | e->appendChild(tag); | 558 | e->appendChild(tag); |
558 | 559 | ||
559 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); | 560 | tag = domDoc->createElement(ENTRY_LAUNCHER_WR); |
560 | curText = new_text(escapeEntryData(dta.launcher.c_str())); | 561 | curText = new_text(escapeEntryData(dta.launcher.c_str())); |
561 | tag.appendChild(curText); | 562 | tag.appendChild(curText); |
562 | e->appendChild(tag); | 563 | e->appendChild(tag); |
563 | 564 | ||
564 | tag = domDoc->createElement(ENTRY_LVP_WR); | 565 | tag = domDoc->createElement(ENTRY_LVP_WR); |
565 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); | 566 | plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str()); |
566 | tag.appendChild(plainText); | 567 | tag.appendChild(plainText); |
567 | e->appendChild(tag); | 568 | e->appendChild(tag); |
568 | 569 | ||
569 | tag = domDoc->createElement(ENTRY_BIN_WR); | 570 | tag = domDoc->createElement(ENTRY_BIN_WR); |
570 | if (dta.binary) | 571 | if (dta.binary) |
571 | plainText = domDoc->createTextNode("1"); | 572 | plainText = domDoc->createTextNode("1"); |
572 | else | 573 | else |
573 | plainText = domDoc->createTextNode("0"); | 574 | plainText = domDoc->createTextNode("0"); |
574 | tag.appendChild(plainText); | 575 | tag.appendChild(plainText); |
575 | e->appendChild(tag); | 576 | e->appendChild(tag); |
576 | 577 | ||
577 | tag = domDoc->createElement(ENTRY_META_WR); | 578 | tag = domDoc->createElement(ENTRY_META_WR); |
578 | if (!writeMeta(&tag, dta.meta)) | 579 | if (!writeMeta(&tag, dta.meta)) |
579 | return false; | 580 | return false; |
580 | e->appendChild(tag); | 581 | e->appendChild(tag); |
581 | 582 | ||
582 | #undef new_text | 583 | #undef new_text |
583 | return true; | 584 | return true; |
584 | } | 585 | } |
585 | 586 | ||
586 | bool Serializer::writeMeta(QDomElement *e, | 587 | bool Serializer::writeMeta(QDomElement *e, |
587 | const PwMMetaData &dta) | 588 | const PwMMetaData &dta) |
588 | { | 589 | { |
589 | QDomText text; | 590 | QDomText text; |
590 | QDomElement tag; | 591 | QDomElement tag; |
591 | 592 | ||
592 | tag = domDoc->createElement(META_CREATE_DATE); | 593 | tag = domDoc->createElement(META_CREATE_DATE); |
593 | #ifndef PWM_EMBEDDED | 594 | #ifndef PWM_EMBEDDED |
594 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); | 595 | text = domDoc->createTextNode(dta.create.toString(Qt::ISODate)); |
595 | #else | 596 | #else |
596 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); | 597 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate)); |
597 | #endif | 598 | #endif |
598 | tag.appendChild(text); | 599 | tag.appendChild(text); |
599 | e->appendChild(tag); | 600 | e->appendChild(tag); |
600 | 601 | ||
601 | tag = domDoc->createElement(META_VALID_DATE); | 602 | tag = domDoc->createElement(META_VALID_DATE); |
602 | #ifndef PWM_EMBEDDED | 603 | #ifndef PWM_EMBEDDED |
603 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); | 604 | text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate)); |
604 | #else | 605 | #else |
605 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); | 606 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate)); |
606 | #endif | 607 | #endif |
607 | tag.appendChild(text); | 608 | tag.appendChild(text); |
608 | e->appendChild(tag); | 609 | e->appendChild(tag); |
609 | 610 | ||
610 | tag = domDoc->createElement(META_EXPIRE_DATE); | 611 | tag = domDoc->createElement(META_EXPIRE_DATE); |
611 | #ifndef PWM_EMBEDDED | 612 | #ifndef PWM_EMBEDDED |
612 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 613 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
613 | #else | 614 | #else |
614 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 615 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
615 | #endif | 616 | #endif |
616 | tag.appendChild(text); | 617 | tag.appendChild(text); |
617 | e->appendChild(tag); | 618 | e->appendChild(tag); |
618 | 619 | ||
619 | tag = domDoc->createElement(META_UPDATE_DATE); | 620 | tag = domDoc->createElement(META_UPDATE_DATE); |
620 | #ifndef PWM_EMBEDDED | 621 | #ifndef PWM_EMBEDDED |
621 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 622 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
622 | #else | 623 | #else |
623 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 624 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
624 | #endif | 625 | #endif |
625 | tag.appendChild(text); | 626 | tag.appendChild(text); |
626 | e->appendChild(tag); | 627 | e->appendChild(tag); |
627 | 628 | ||
628 | tag = domDoc->createElement(META_UPDATE_INT); | 629 | tag = domDoc->createElement(META_UPDATE_INT); |
629 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 630 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
630 | tag.appendChild(text); | 631 | tag.appendChild(text); |
631 | e->appendChild(tag); | 632 | e->appendChild(tag); |
632 | 633 | ||
633 | tag = domDoc->createElement(META_UNIQUEID); | 634 | tag = domDoc->createElement(META_UNIQUEID); |
634 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); | 635 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); |
635 | tag.appendChild(text); | 636 | tag.appendChild(text); |
636 | e->appendChild(tag); | 637 | e->appendChild(tag); |
637 | 638 | ||
638 | #undef new_text | 639 | #undef new_text |
639 | return true; | 640 | return true; |
640 | } | 641 | } |
641 | 642 | ||
642 | QString Serializer::escapeEntryData(QString dta) | 643 | QString Serializer::escapeEntryData(QString dta) |
643 | { | 644 | { |
644 | #ifndef PWM_EMBEDDED | 645 | #ifndef PWM_EMBEDDED |
645 | dta.replace('\n', "$>--endl--<$"); | 646 | dta.replace('\n', "$>--endl--<$"); |
646 | dta.replace("]]>", "||>"); | 647 | dta.replace("]]>", "||>"); |
647 | #else | 648 | #else |
648 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 649 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
649 | dta.replace(QRegExp("]]>"), "||>"); | 650 | dta.replace(QRegExp("]]>"), "||>"); |
650 | #endif | 651 | #endif |
651 | return dta; | 652 | return dta; |
652 | } | 653 | } |
653 | 654 | ||
654 | QString Serializer::unescapeEntryData(QString dta) | 655 | QString Serializer::unescapeEntryData(QString dta) |
655 | { | 656 | { |
656 | #ifndef PWM_EMBEDDED | 657 | #ifndef PWM_EMBEDDED |
657 | dta.replace("$>--endl--<$", "\n"); | 658 | dta.replace("$>--endl--<$", "\n"); |
658 | dta.replace("||>", "]]>"); | 659 | dta.replace("||>", "]]>"); |
659 | #else | 660 | #else |
660 | dta.replace(QRegExp("$>--endl--<$"), "\n"); | 661 | dta.replace(QRegExp("$>--endl--<$"), "\n"); |
661 | dta.replace(QRegExp("||>"), "]]>"); | 662 | dta.replace(QRegExp("||>"), "]]>"); |
662 | #endif | 663 | #endif |
663 | return dta; | 664 | return dta; |
664 | } | 665 | } |