1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/*
Copyright (C) 2003 George Staikos <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "konfigurator.h"
#include "walletconfigwidget.h"
#include <dcopclient.h>
#include <dcopref.h>
#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kdialog.h>
#include <kgenericfactory.h>
#include <kinputdialog.h>
#include <tdepopupmenu.h>
#include <tdewallet.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqlistview.h>
#include <tqpushbutton.h>
#include <tqspinbox.h>
#include <tqtabwidget.h>
typedef KGenericFactory<TDEWalletConfig, TQWidget> TDEWalletFactory;
K_EXPORT_COMPONENT_FACTORY(kcm_tdewallet, TDEWalletFactory("kcmtdewallet"))
TDEWalletConfig::TDEWalletConfig(TQWidget *parent, const char *name, const TQStringList&)
: TDECModule(TDEWalletFactory::instance(), parent, name) {
TDEAboutData *about =
new TDEAboutData(I18N_NOOP("kcmtdewallet"),
I18N_NOOP("TDE Wallet Control Module"),
0, 0, TDEAboutData::License_GPL,
I18N_NOOP("(c) 2003 George Staikos"));
about->addAuthor("George Staikos", 0, "[email protected]");
setAboutData( about );
_cfg = new TDEConfig("tdewalletrc", false, false);
TQVBoxLayout *vbox = new TQVBoxLayout(this, 0, KDialog::spacingHint());
vbox->add(_wcw = new WalletConfigWidget(this));
connect(_wcw->_enabled, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_launchManager, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_autocloseManager, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_autoclose, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_closeIdle, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_openPrompt, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_screensaverLock, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_localWalletSelected, TQ_SIGNAL(clicked()), this, TQ_SLOT(configChanged()));
connect(_wcw->_idleTime, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(configChanged()));
connect(_wcw->_launch, TQ_SIGNAL(clicked()), this, TQ_SLOT(launchManager()));
connect(_wcw->_newWallet, TQ_SIGNAL(clicked()), this, TQ_SLOT(newNetworkWallet()));
connect(_wcw->_newLocalWallet, TQ_SIGNAL(clicked()), this, TQ_SLOT(newLocalWallet()));
connect(_wcw->_localWallet, TQ_SIGNAL(activated(int)), this, TQ_SLOT(configChanged()));
connect(_wcw->_defaultWallet, TQ_SIGNAL(activated(int)), this, TQ_SLOT(configChanged()));
connect(_wcw->_accessList, TQ_SIGNAL(contextMenuRequested(TQListViewItem*, const TQPoint&, int)), this, TQ_SLOT(contextMenuRequested(TQListViewItem*, const TQPoint&, int)));
_wcw->_accessList->setAllColumnsShowFocus(true);
updateWalletLists();
load();
if (DCOPClient::mainClient()->isApplicationRegistered("tdewalletmanager")) {
_wcw->_launch->hide();
}
}
TDEWalletConfig::~TDEWalletConfig() {
delete _cfg;
_cfg = 0L;
}
void TDEWalletConfig::updateWalletLists() {
TQString p1, p2;
p1 = _wcw->_localWallet->currentText();
p2 = _wcw->_defaultWallet->currentText();
_wcw->_localWallet->clear();
_wcw->_defaultWallet->clear();
TQStringList wl = TDEWallet::Wallet::walletList();
_wcw->_localWallet->insertStringList(wl);
_wcw->_defaultWallet->insertStringList(wl);
if (wl.contains(p1)) {
_wcw->_localWallet->setCurrentText(p1);
}
if (wl.contains(p2)) {
_wcw->_defaultWallet->setCurrentText(p2);
}
}
TQString TDEWalletConfig::newWallet() {
bool ok;
TQString n = KInputDialog::getText(i18n("New Wallet"),
i18n("Please choose a name for the new wallet:"),
TQString(),
&ok,
this);
if (!ok) {
return TQString();
}
TDEWallet::Wallet *w = TDEWallet::Wallet::openWallet(n);
if (!w) {
return TQString();
}
delete w;
return n;
}
void TDEWalletConfig::newLocalWallet() {
TQString n = newWallet();
if (n.isEmpty()) {
return;
}
updateWalletLists();
_wcw->_localWallet->setCurrentText(n);
emit changed(true);
}
void TDEWalletConfig::newNetworkWallet() {
TQString n = newWallet();
if (n.isEmpty()) {
return;
}
updateWalletLists();
_wcw->_defaultWallet->setCurrentText(n);
emit changed(true);
}
void TDEWalletConfig::launchManager() {
if (!DCOPClient::mainClient()->isApplicationRegistered("tdewalletmanager")) {
TDEApplication::startServiceByDesktopName("tdewalletmanager_show");
} else {
DCOPRef r("tdewalletmanager", "tdewalletmanager-mainwindow#1");
r.send("show");
r.send("raise");
}
}
void TDEWalletConfig::configChanged() {
emit changed(true);
}
void TDEWalletConfig::load() {
load( false );
}
void TDEWalletConfig::load(bool useDefaults) {
TDEConfigGroup config(_cfg, "Wallet");
config.setReadDefaults( useDefaults );
_wcw->_enabled->setChecked(config.readBoolEntry("Enabled", true));
_wcw->_openPrompt->setChecked(config.readBoolEntry("Prompt on Open", true));
_wcw->_launchManager->setChecked(config.readBoolEntry("Launch Manager", true));
_wcw->_autocloseManager->setChecked(! config.readBoolEntry("Leave Manager Open", false));
_wcw->_screensaverLock->setChecked(config.readBoolEntry("Close on Screensaver", false));
_wcw->_autoclose->setChecked(!config.readBoolEntry("Leave Open", false));
_wcw->_closeIdle->setChecked(config.readBoolEntry("Close When Idle", false));
_wcw->_idleTime->setValue(config.readNumEntry("Idle Timeout", 10));
if (config.hasKey("Default Wallet")) {
_wcw->_defaultWallet->setCurrentText(config.readEntry("Default Wallet"));
} else {
_wcw->_defaultWallet->setCurrentItem(0);
}
if (config.hasKey("Local Wallet")) {
_wcw->_localWalletSelected->setChecked( !config.readBoolEntry("Use One Wallet") );
_wcw->_localWallet->setCurrentText(config.readEntry("Local Wallet"));
} else {
_wcw->_localWalletSelected->setChecked(false);
}
_wcw->_accessList->clear();
_cfg->setGroup("Auto Deny");
TQStringList denykeys = _cfg->entryMap("Auto Deny").keys();
_cfg->setGroup("Auto Allow");
TQStringList keys = _cfg->entryMap("Auto Allow").keys();
for (TQStringList::Iterator i = keys.begin(); i != keys.end(); ++i) {
_cfg->setGroup("Auto Allow");
TQStringList apps = _cfg->readListEntry(*i);
_cfg->setGroup("Auto Deny");
TQStringList denyapps = _cfg->readListEntry(*i);
denykeys.remove(*i);
TQListViewItem *lvi = new TQListViewItem(_wcw->_accessList, *i);
for (TQStringList::Iterator j = apps.begin(); j != apps.end(); ++j) {
new TQListViewItem(lvi, TQString(), *j, i18n("Always Allow"));
}
for (TQStringList::Iterator j = denyapps.begin(); j != denyapps.end(); ++j) {
new TQListViewItem(lvi, TQString(), *j, i18n("Always Deny"));
}
}
_cfg->setGroup("Auto Deny");
for (TQStringList::Iterator i = denykeys.begin(); i != denykeys.end(); ++i) {
TQStringList denyapps = _cfg->readListEntry(*i);
TQListViewItem *lvi = new TQListViewItem(_wcw->_accessList, *i);
for (TQStringList::Iterator j = denyapps.begin(); j != denyapps.end(); ++j) {
new TQListViewItem(lvi, TQString(), *j, i18n("Always Deny"));
}
}
emit changed(useDefaults);
}
void TDEWalletConfig::save() {
TDEConfigGroup config(_cfg, "Wallet");
config.writeEntry("Enabled", _wcw->_enabled->isChecked());
config.writeEntry("Launch Manager", _wcw->_launchManager->isChecked());
config.writeEntry("Leave Manager Open", !_wcw->_autocloseManager->isChecked());
config.writeEntry("Leave Open", !_wcw->_autoclose->isChecked());
config.writeEntry("Close When Idle", _wcw->_closeIdle->isChecked());
config.writeEntry("Idle Timeout", _wcw->_idleTime->value());
config.writeEntry("Prompt on Open", _wcw->_openPrompt->isChecked());
config.writeEntry("Close on Screensaver", _wcw->_screensaverLock->isChecked());
config.writeEntry("Use One Wallet", !_wcw->_localWalletSelected->isChecked());
if (_wcw->_localWalletSelected->isChecked()) {
config.writeEntry("Local Wallet", _wcw->_localWallet->currentText());
} else {
config.deleteEntry("Local Wallet");
}
if (_wcw->_defaultWallet->currentItem() != -1) {
config.writeEntry("Default Wallet", _wcw->_defaultWallet->currentText());
} else {
config.deleteEntry("Default Wallet");
}
// FIXME: won't survive a language change
_cfg->deleteGroup("Auto Allow");
_cfg->deleteGroup("Auto Deny");
_cfg->setGroup("Auto Allow");
for (TQListViewItem *i = _wcw->_accessList->firstChild(); i; i = i->nextSibling()) {
TQStringList al;
for (TQListViewItem *j = i->firstChild(); j; j = j->nextSibling()) {
if (j->text(2) == i18n("Always Allow")) {
al << j->text(1);
}
}
_cfg->writeEntry(i->text(0), al);
}
_cfg->setGroup("Auto Deny");
for (TQListViewItem *i = _wcw->_accessList->firstChild(); i; i = i->nextSibling()) {
TQStringList al;
for (TQListViewItem *j = i->firstChild(); j; j = j->nextSibling()) {
if (j->text(2) == i18n("Always Deny")) {
al << j->text(1);
}
}
_cfg->writeEntry(i->text(0), al);
}
_cfg->sync();
DCOPRef("kded", "tdewalletd").call("reconfigure()");
emit changed(false);
}
TQString TDEWalletConfig::handbookSection() const
{
int index = _wcw->tabWidget2->currentPageIndex();
if (index == 0)
return "wallet-preferences";
else if (index == 1)
return "wallet-access-control";
else
return TQString::null;
}
void TDEWalletConfig::defaults() {
load( true );
}
TQString TDEWalletConfig::quickHelp() const {
return i18n("This configuration module allows you to configure the TDE wallet system.");
}
void TDEWalletConfig::contextMenuRequested(TQListViewItem *item, const TQPoint& pos, int col) {
Q_UNUSED(col)
if (item && item->parent()) {
TDEPopupMenu *m = new TDEPopupMenu(this);
m->insertTitle(item->parent()->text(0));
m->insertItem(i18n("&Delete"), this, TQ_SLOT(deleteEntry()), Key_Delete);
m->popup(pos);
}
}
void TDEWalletConfig::deleteEntry() {
TQListViewItem *item = _wcw->_accessList->selectedItem();
if (item) {
delete item;
emit changed(true);
}
}
#include "konfigurator.moc"
|