summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/editcategory.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/editcategory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/editcategory.cpp188
1 files changed, 188 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/editcategory.cpp b/pwmanager/pwmanager/editcategory.cpp
new file mode 100644
index 0000000..4e55de8
--- a/dev/null
+++ b/pwmanager/pwmanager/editcategory.cpp
@@ -0,0 +1,188 @@
1/*
2 This file is part of PwManager/Platform independent.
3 Copyright (c) 2004 Ulf Schenk
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22
23$Id$
24*/
25
26#include "editcategory.h"
27#include "pwmdoc.h"
28
29#include <qlayout.h>
30#include <qlabel.h>
31#include <qgroupbox.h>
32#include <klocale.h>
33#include <kcombobox.h>
34#include <klineedit.h>
35#include <qpushbutton.h>
36
37
38/*
39 * Constructs a addEntryWnd as a child of 'parent', with the
40 * name 'name' and widget flags set to 'f'.
41 *
42 * The dialog will by default be modeless, unless you set 'modal' to
43 * TRUE to construct a modal dialog.
44 */
45editCategoryWnd::editCategoryWnd( PwMDoc* d, QWidget* parent, const char* name)
46 : KDialogBase( KDialogBase::Plain, i18n( "edit category descriptions" ),
47 Apply | User2 | Ok,
48 Ok, parent, name, true ),
49 doc(d)
50{
51 findButton( Ok )->setText (i18n("Close" )) ;
52 findButton( User2 )->setText (i18n("Cancel" )) ;
53 connect(this,SIGNAL(user2Clicked()), SLOT(cancel_slot()));
54 enableButton( KDialogBase::Apply, false );
55
56
57 QWidget *page = plainPage();
58 QGridLayout *layout = new QGridLayout( page, 3, 1 );
59 layout->setMargin( KDialogBase::marginHint() );
60 layout->setSpacing( KDialogBase::spacingHint() );
61
62 int i = 0;
63 categoryComboBox = new KComboBox( page );
64 QLabel* label = new QLabel( categoryComboBox, i18n("Category:"), page );
65 layout->addWidget( label, i, 0 );
66 layout->addWidget( categoryComboBox, i, 1 );
67 i++;
68 categoryComboBox->setEditable( FALSE );
69 categoryComboBox->setSizeLimit( 100 );
70 connect(categoryComboBox,SIGNAL(activated(const QString&)), SLOT(categorySelected(const QString&)));
71
72
73 descLineEdit = new KLineEdit( page, "descLineEdit" );
74 label = new QLabel( descLineEdit, i18n("Text1 (Description):"), page );
75 layout->addWidget( label, i, 0 );
76 layout->addWidget( descLineEdit, i, 1 );
77 connect( descLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) );
78 i++;
79
80 usernameLineEdit = new KLineEdit( page, "usernameLineEdit" );
81 label = new QLabel( usernameLineEdit, i18n("Text2 (Username):"), page );
82 layout->addWidget( label, i, 0 );
83 layout->addWidget( usernameLineEdit, i, 1 );
84 connect( usernameLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) );
85 i++;
86
87 pwLineEdit = new KLineEdit( page, "pwLineEdit" );
88 label = new QLabel( pwLineEdit, i18n("Text3 (Password):"), page );
89 layout->addWidget( label, i, 0 );
90 layout->addWidget( pwLineEdit, i, 1 );
91 connect( pwLineEdit, SIGNAL( textChanged ( const QString & ) ), SLOT( widgetModified(const QString &) ) );
92 i++;
93
94 unsigned int count = doc->numCategories();
95
96 for (unsigned int i = 0; i < count; ++i) {
97 categoryComboBox->insertItem(doc->getCategory(i)->c_str());
98 }
99
100 //PwMCategoryItem* getCategoryEntry(unsigned int index)
101 // { return &(dti.dta[index]); }
102
103
104
105}
106
107/*
108 * Destroys the object and frees any allocated resources
109 */
110editCategoryWnd::~editCategoryWnd()
111{
112 // no need to delete child widgets, Qt does it all for us
113}
114
115void editCategoryWnd::slotOk()
116{
117 // qDebug( "addEntryWnd::slotOk(): Not implemented yet" );
118 slotApply();
119 accept();
120}
121
122void editCategoryWnd::slotApply()
123{
124 QString cat = categoryComboBox->currentText();
125
126 unsigned int idx;
127 bool found = doc->findCategory(cat, &idx);
128
129 if (found == true)
130 {
131 PwMCategoryItem* catitem = doc->getCategoryEntry(idx);
132
133 catitem->desc_text = descLineEdit->text().latin1();
134 catitem->name_text = usernameLineEdit->text().latin1();
135 catitem->pw_text = pwLineEdit->text().latin1();
136 enableButton( KDialogBase::Apply, false );
137 return;
138 }
139
140 BUG();
141
142}
143
144void editCategoryWnd::cancel_slot()
145{
146 QString cat = categoryComboBox->currentText();
147 categorySelected ( cat );
148}
149
150void editCategoryWnd::setCurrCategory(const QString &cat)
151{
152 int i, count = categoryComboBox->count();
153
154 for (i = 0; i < count; ++i) {
155 if (categoryComboBox->text(i) == cat) {
156 categoryComboBox->setCurrentItem(i);
157 categorySelected ( cat );
158 return;
159 }
160 }
161 BUG();
162}
163
164void editCategoryWnd::categorySelected ( const QString & string )
165{
166 unsigned int idx;
167 bool found = doc->findCategory(string, &idx);
168
169 if (found == true)
170 {
171 PwMCategoryItem* catitem = doc->getCategoryEntry(idx);
172
173 descLineEdit->setText(catitem->desc_text.c_str());
174 usernameLineEdit->setText(catitem->name_text.c_str());
175 pwLineEdit->setText(catitem->pw_text.c_str());
176 enableButton( KDialogBase::Apply, false );
177 return;
178 }
179
180 BUG();
181
182}
183
184void editCategoryWnd::widgetModified(const QString &)
185{
186 enableButton( KDialogBase::Apply, true );
187}
188