Diffstat (limited to 'pwmanager/pwmanager/subtbleditimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/subtbleditimpl.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/subtbleditimpl.cpp b/pwmanager/pwmanager/subtbleditimpl.cpp new file mode 100644 index 0000000..cfc66dd --- a/dev/null +++ b/pwmanager/pwmanager/subtbleditimpl.cpp | |||
@@ -0,0 +1,138 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2004 by Michael Buesch * | ||
4 | * email: mbuesch@freenet.de * | ||
5 | * * | ||
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 * | ||
8 | * as published by the Free Software Foundation. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | /*************************************************************************** | ||
13 | * copyright (C) 2004 by Ulf Schenk | ||
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 | ||
16 | * | ||
17 | * $Id$ | ||
18 | **************************************************************************/ | ||
19 | |||
20 | #include "subtbleditimpl.h" | ||
21 | #include "pwmexception.h" | ||
22 | |||
23 | #include <qmessagebox.h> | ||
24 | |||
25 | #include <klocale.h> | ||
26 | |||
27 | |||
28 | SubTblEditImpl::SubTblEditImpl(QWidget* parent, | ||
29 | const char* name, | ||
30 | WFlags fl) | ||
31 | : subTblEdit(parent, name, fl) | ||
32 | { | ||
33 | prevSelection = -1; | ||
34 | connect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)), | ||
35 | this, SLOT(selectedEntry_slot())); | ||
36 | } | ||
37 | |||
38 | SubTblEditImpl::~SubTblEditImpl() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | void SubTblEditImpl::okButton_slot() | ||
43 | { | ||
44 | if (getTitle().isEmpty()) { | ||
45 | QMessageBox::information(this, | ||
46 | i18n("no title"), | ||
47 | i18n("Please enter a title.")); | ||
48 | return; | ||
49 | } | ||
50 | if (!entries.size()) { | ||
51 | QMessageBox::information(this, | ||
52 | i18n("no entries"), | ||
53 | i18n("Please add some entries.")); | ||
54 | return; | ||
55 | } | ||
56 | int index = curIndex(); | ||
57 | if (index != -1) { | ||
58 | entries[index].first = nameLineEdit->text(); | ||
59 | entries[index].second = valueLineEdit->text(); | ||
60 | } | ||
61 | done(0); | ||
62 | } | ||
63 | |||
64 | void SubTblEditImpl::cancelButton_slot() | ||
65 | { | ||
66 | done(1); | ||
67 | } | ||
68 | |||
69 | void SubTblEditImpl::addButton_slot() | ||
70 | { | ||
71 | QString name(nameLineEdit->text()); | ||
72 | if (name.isEmpty()) | ||
73 | return; | ||
74 | QString value(valueLineEdit->text()); | ||
75 | prevSelection = -1; | ||
76 | nameLineEdit->clear(); | ||
77 | valueLineEdit->clear(); | ||
78 | #ifndef PWM_EMBEDDED | ||
79 | entryListBox->setSelected(entryListBox->index( | ||
80 | entryListBox->selectedItem()), | ||
81 | false); | ||
82 | #else | ||
83 | entryListBox->setSelected(entryListBox->currentItem(), | ||
84 | false); | ||
85 | #endif | ||
86 | pair<QString, QString> p; | ||
87 | p.first = name; | ||
88 | p.second = value; | ||
89 | entries.push_back(p); | ||
90 | entryListBox->insertItem(name); | ||
91 | } | ||
92 | |||
93 | void SubTblEditImpl::delButton_slot() | ||
94 | { | ||
95 | int index = curIndex(); | ||
96 | if (index == -1) | ||
97 | return; | ||
98 | entries.erase(entries.begin() + index); | ||
99 | entryListBox->removeItem(index); | ||
100 | } | ||
101 | |||
102 | void SubTblEditImpl::selectedEntry_slot() | ||
103 | { | ||
104 | int index = curIndex(); | ||
105 | if (index == -1) | ||
106 | return; | ||
107 | disconnect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)), | ||
108 | this, SLOT(selectedEntry_slot())); | ||
109 | if ((prevSelection != -1) && (prevSelection != index)) { | ||
110 | entries[prevSelection].first = nameLineEdit->text(); | ||
111 | entries[prevSelection].second = valueLineEdit->text(); | ||
112 | entryListBox->changeItem(nameLineEdit->text(), prevSelection); | ||
113 | } | ||
114 | pair<QString, QString> p(entries[index]); | ||
115 | nameLineEdit->setText(p.first); | ||
116 | valueLineEdit->setText(p.second); | ||
117 | prevSelection = index; | ||
118 | entryListBox->setSelected(index, true); | ||
119 | connect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)), | ||
120 | this, SLOT(selectedEntry_slot())); | ||
121 | } | ||
122 | |||
123 | void SubTblEditImpl::setContent(const QString &title, | ||
124 | const vector< pair<QString, QString> > *_entries) | ||
125 | { | ||
126 | entries = *_entries; | ||
127 | titleLineEdit->setText(title); | ||
128 | vector< pair<QString, QString> >::iterator i = entries.begin(), | ||
129 | end = entries.end(); | ||
130 | while (i != end) { | ||
131 | entryListBox->insertItem(i->first); | ||
132 | ++i; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | #ifndef PWM_EMBEDDED | ||
137 | #include "subtbleditimpl.moc" | ||
138 | #endif | ||