• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kwallet

  • sources
  • kde-4.14
  • kdeutils
  • kwalletmanager
  • src
  • konfigurator
konfigurator.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 George Staikos <staikos@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 #include "konfigurator.h"
20 
21 #include <QtDBus/QtDBus>
22 #include <kaboutdata.h>
23 #include <kapplication.h>
24 #include <ksharedconfig.h>
25 #include <kdialog.h>
26 #include <kpluginfactory.h>
27 #include <kpluginloader.h>
28 #include <kinputdialog.h>
29 #include <kmenu.h>
30 #include <kwallet.h>
31 #include <kauthaction.h>
32 #include <kdebug.h>
33 
34 #include <QCheckBox>
35 #include <QPushButton>
36 #include <QVBoxLayout>
37 #include <ktoolinvocation.h>
38 #include <kconfiggroup.h>
39 #include <kmessagebox.h>
40 #include <kstandarddirs.h>
41 #define KWALLETMANAGERINTERFACE "org.kde.KWallet"
42 
43 K_PLUGIN_FACTORY(KWalletFactory, registerPlugin<KWalletConfig>();)
44 K_EXPORT_PLUGIN(KWalletFactory("kcmkwallet"))
45 
46 
47 KWalletConfig::KWalletConfig(QWidget *parent, const QVariantList& args)
48 : KCModule(KWalletFactory::componentData(), parent, args),
49  _cfg(KSharedConfig::openConfig(QLatin1String( "kwalletrc" ), KConfig::NoGlobals)) {
50 
51  KAboutData *about =
52  new KAboutData(I18N_NOOP("kcmkwallet"), 0,
53  ki18n("KDE Wallet Control Module"),
54  0, KLocalizedString(), KAboutData::License_GPL,
55  ki18n("(c) 2003 George Staikos"));
56  about->addAuthor(ki18n("George Staikos"), KLocalizedString(), "staikos@kde.org");
57  setAboutData( about );
58 
59  setNeedsAuthorization(true);
60 
61  QVBoxLayout *vbox = new QVBoxLayout(this);
62  vbox->setSpacing(KDialog::spacingHint());
63  vbox->setMargin(0);
64  _wcw = new WalletConfigWidget(this);
65  vbox->addWidget(_wcw);
66 
67  connect(_wcw->_enabled, SIGNAL(clicked()), this, SLOT(configChanged()));
68  connect(_wcw->_launchManager, SIGNAL(clicked()), this, SLOT(configChanged()));
69  connect(_wcw->_autocloseManager, SIGNAL(clicked()), this, SLOT(configChanged()));
70  connect(_wcw->_autoclose, SIGNAL(clicked()), this, SLOT(configChanged()));
71  connect(_wcw->_closeIdle, SIGNAL(clicked()), this, SLOT(configChanged()));
72  connect(_wcw->_openPrompt, SIGNAL(clicked()), this, SLOT(configChanged()));
73  connect(_wcw->_screensaverLock, SIGNAL(clicked()), this, SLOT(configChanged()));
74  connect(_wcw->_localWalletSelected, SIGNAL(clicked()), this, SLOT(configChanged()));
75  connect(_wcw->_idleTime, SIGNAL(valueChanged(int)), this, SLOT(configChanged()));
76  connect(_wcw->_launch, SIGNAL(clicked()), this, SLOT(launchManager()));
77  connect(_wcw->_newWallet, SIGNAL(clicked()), this, SLOT(newNetworkWallet()));
78  connect(_wcw->_newLocalWallet, SIGNAL(clicked()), this, SLOT(newLocalWallet()));
79  connect(_wcw->_localWallet, SIGNAL(activated(int)), this, SLOT(configChanged()));
80  connect(_wcw->_defaultWallet, SIGNAL(activated(int)), this, SLOT(configChanged()));
81  connect(_wcw->_accessList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
82 
83  _wcw->_accessList->setAllColumnsShowFocus(true);
84  _wcw->_accessList->setContextMenuPolicy(Qt::CustomContextMenu);
85  updateWalletLists();
86 
87  if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String( "org.kde.kwalletmanager" ))) {
88  _wcw->_launch->hide();
89  }
90 
91 }
92 
93 
94 KWalletConfig::~KWalletConfig() {
95 }
96 
97 
98 void KWalletConfig::updateWalletLists() {
99  const QString p1( _wcw->_localWallet->currentText() );
100  const QString p2( _wcw->_defaultWallet->currentText() );
101 
102  _wcw->_localWallet->clear();
103  _wcw->_defaultWallet->clear();
104 
105  const QStringList wl = KWallet::Wallet::walletList();
106  _wcw->_localWallet->addItems(wl);
107  _wcw->_defaultWallet->addItems(wl);
108 
109  int index = wl.indexOf(p1);
110  if (index != -1) {
111  _wcw->_localWallet->setCurrentIndex(index);
112  }
113 
114  index = wl.indexOf(p2);
115  if (index != -1) {
116  _wcw->_defaultWallet->setCurrentIndex(index);
117  }
118 }
119 
120 
121 QString KWalletConfig::newWallet() {
122  bool ok;
123 
124  const QString n = KInputDialog::getText(i18n("New Wallet"),
125  i18n("Please choose a name for the new wallet:"),
126  QString(),
127  &ok,
128  this);
129 
130  if (!ok) {
131  return QString();
132  }
133 
134  KWallet::Wallet *w = KWallet::Wallet::openWallet(n, topLevelWidget()->winId());
135  if (!w) {
136  return QString();
137  }
138 
139  delete w;
140  return n;
141 }
142 
143 
144 void KWalletConfig::newLocalWallet() {
145  const QString n = newWallet();
146  if (n.isEmpty()) {
147  return;
148  }
149 
150  updateWalletLists();
151 
152  _wcw->_localWallet->setCurrentIndex(_wcw->_localWallet->findText(n));
153 
154  emit changed(true);
155 }
156 
157 
158 void KWalletConfig::newNetworkWallet() {
159  const QString n = newWallet();
160  if (n.isEmpty()) {
161  return;
162  }
163 
164  updateWalletLists();
165 
166  _wcw->_defaultWallet->setCurrentIndex(_wcw->_defaultWallet->findText(n));
167 
168  emit changed(true);
169 }
170 
171 
172 void KWalletConfig::launchManager() {
173  if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String( "org.kde.kwalletmanager" ))) {
174  KToolInvocation::startServiceByDesktopName( QLatin1String( "kwalletmanager_show" ));
175  } else {
176  QDBusInterface kwalletd(QLatin1String( "org.kde.kwalletmanager" ), QLatin1String( "/kwalletmanager/MainWindow_1" ));
177  kwalletd.call( QLatin1String( "show" ));
178  kwalletd.call( QLatin1String( "raise" ) );
179  }
180 }
181 
182 
183 void KWalletConfig::configChanged() {
184  emit changed(true);
185 }
186 
187 void KWalletConfig::load() {
188  KConfigGroup config(_cfg, "Wallet");
189  _wcw->_enabled->setChecked(config.readEntry("Enabled", true));
190  _wcw->_openPrompt->setChecked(config.readEntry("Prompt on Open", false));
191  _wcw->_launchManager->setChecked(config.readEntry("Launch Manager", false));
192  _wcw->_autocloseManager->setChecked(! config.readEntry("Leave Manager Open", false));
193  _wcw->_screensaverLock->setChecked(config.readEntry("Close on Screensaver", false));
194  _wcw->_autoclose->setChecked(!config.readEntry("Leave Open", false));
195  _wcw->_closeIdle->setChecked(config.readEntry("Close When Idle", false));
196  _wcw->_idleTime->setValue(config.readEntry("Idle Timeout", 10));
197  if (config.hasKey("Default Wallet")) {
198  int defaultWallet_idx = _wcw->_defaultWallet->findText(config.readEntry("Default Wallet"));
199  if (defaultWallet_idx != -1) {
200  _wcw->_defaultWallet->setCurrentIndex(defaultWallet_idx);
201  } else {
202  _wcw->_defaultWallet->setCurrentIndex(0);
203  }
204  } else {
205  _wcw->_defaultWallet->setCurrentIndex(0);
206  }
207  if (config.hasKey("Local Wallet")) {
208  _wcw->_localWalletSelected->setChecked( !config.readEntry("Use One Wallet", false) );
209  int localWallet_idx = _wcw->_localWallet->findText(config.readEntry("Local Wallet"));
210  if (localWallet_idx != -1) {
211  _wcw->_localWallet->setCurrentIndex(localWallet_idx);
212  } else {
213  _wcw->_localWallet->setCurrentIndex(0);
214  }
215  } else {
216  _wcw->_localWalletSelected->setChecked(false);
217  }
218  _wcw->_accessList->clear();
219  KConfigGroup ad(_cfg, "Auto Deny");
220  KConfigGroup aa(_cfg, "Auto Allow");
221  QStringList denykeys = ad.entryMap().keys();
222  const QStringList keys = aa.entryMap().keys();
223  for (QStringList::const_iterator i = keys.begin(); i != keys.end(); ++i) {
224  QString walletName = *i;
225  // perform cleanup in the kwalletrc file, by removing entries that correspond to non-existent
226  // (previously deleted, for example) wallets
227  QString path = KGlobal::dirs()->locateLocal("data", QString("kwallet/%1.kwl").arg(walletName));
228  if (!QFile::exists(path)) {
229  // if the wallet no longer exists, delete the entries from the configuration file and skip to next entry
230  KConfigGroup cfgAllow = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow");
231  cfgAllow.deleteEntry(walletName);
232 
233  KConfigGroup cfgDeny = KSharedConfig::openConfig("kwalletrc")->group("Auto Deny");
234  cfgDeny.deleteEntry(walletName);
235  continue;
236  }
237 
238  const QStringList apps = aa.readEntry(*i,QStringList());
239  const QStringList denyapps = ad.readEntry(*i, QStringList());
240  denykeys.removeAll(walletName);
241  QTreeWidgetItem *twi = new QTreeWidgetItem(_wcw->_accessList, QStringList() << walletName);
242  for (QStringList::const_iterator j = apps.begin(); j != apps.end(); ++j) {
243  new QTreeWidgetItem(twi, QStringList() << QString() << *j << i18n("Always Allow"));
244  }
245  for (QStringList::const_iterator j = denyapps.begin(); j != denyapps.end(); ++j) {
246  new QTreeWidgetItem(twi, QStringList() << QString() << *j << i18n("Always Deny"));
247  }
248  }
249  for (QStringList::const_iterator i = denykeys.constBegin(); i != denykeys.constEnd(); ++i) {
250  const QStringList denyapps = ad.readEntry(*i,QStringList());
251  QTreeWidgetItem *twi = new QTreeWidgetItem(_wcw->_accessList, QStringList() << *i);
252  for (QStringList::const_iterator j = denyapps.begin(); j != denyapps.end(); ++j) {
253  new QTreeWidgetItem(twi, QStringList() << QString() << *j << i18n("Always Deny"));
254  }
255  }
256  _wcw->_accessList->header()->setResizeMode(QHeaderView::ResizeToContents);
257  emit changed(false);
258 }
259 
260 
261 void KWalletConfig::save() {
262  QVariantMap args;
263  KAuth::Action *action = authAction();
264  if (0 == action) {
265  kDebug() << "There's no authAction, not saving settings";
266  return;
267  }
268  action->setArguments(args);
269 
270  KAuth::ActionReply reply = action->execute();
271 
272  if (reply.failed()) {
273  if (reply.type() == KAuth::ActionReply::KAuthError){
274  kDebug() << "Save action was not authorized!";
275  KMessageBox::error(this, i18n("Sorry, the system security policy didn't allow you to save the changes."), i18n("KDE Wallet Control Module"));
276  } else {
277  KMessageBox::error(this, reply.errorDescription(), i18n("KDE Wallet Control Module"));
278  kDebug() << "Save action failed. Not saving the settings.";
279  }
280  load();
281  return;
282  }
283 
284  KConfigGroup config(_cfg, "Wallet");
285  config.writeEntry("Enabled", _wcw->_enabled->isChecked());
286  config.writeEntry("Launch Manager", _wcw->_launchManager->isChecked());
287  config.writeEntry("Leave Manager Open", !_wcw->_autocloseManager->isChecked());
288  config.writeEntry("Leave Open", !_wcw->_autoclose->isChecked());
289  config.writeEntry("Close When Idle", _wcw->_closeIdle->isChecked());
290  config.writeEntry("Idle Timeout", _wcw->_idleTime->value());
291  config.writeEntry("Prompt on Open", _wcw->_openPrompt->isChecked());
292  config.writeEntry("Close on Screensaver", _wcw->_screensaverLock->isChecked());
293 
294  config.writeEntry("Use One Wallet", !_wcw->_localWalletSelected->isChecked());
295  if (_wcw->_localWalletSelected->isChecked()) {
296  config.writeEntry("Local Wallet", _wcw->_localWallet->currentText());
297  } else {
298  config.deleteEntry("Local Wallet");
299  }
300 
301  if (_wcw->_defaultWallet->currentIndex() != -1) {
302  config.writeEntry("Default Wallet", _wcw->_defaultWallet->currentText());
303  } else {
304  config.deleteEntry("Default Wallet");
305  }
306 
307  // FIXME: won't survive a language change
308  _cfg->deleteGroup("Auto Allow");
309  _cfg->deleteGroup("Auto Deny");
310  config = _cfg->group("Auto Allow");
311  for (int i = 0; i < _wcw->_accessList->topLevelItemCount(); ++i) {
312  QTreeWidgetItem *parentItem = _wcw->_accessList->topLevelItem(i);
313  QStringList al;
314  for (int j = 0; j < parentItem->childCount(); ++j) {
315  QTreeWidgetItem *childItem = parentItem->child(j);
316  if (childItem->text(2) == i18n("Always Allow")) {
317  al << childItem->text(1);
318  }
319  }
320  config.writeEntry(parentItem->text(0), al);
321  }
322 
323  config = _cfg->group("Auto Deny");
324  for (int i = 0; i < _wcw->_accessList->topLevelItemCount(); ++i) {
325  QTreeWidgetItem *parentItem = _wcw->_accessList->topLevelItem(i);
326  QStringList al;
327  for (int j = 0; j < parentItem->childCount(); ++j) {
328  QTreeWidgetItem *childItem = parentItem->child(j);
329  if (childItem->text(2) == i18n("Always Deny")) {
330  al << childItem->text(1);
331  }
332  }
333  config.writeEntry(parentItem->text(0), al);
334  }
335 
336  _cfg->sync();
337 
338  // this restarts kwalletd if necessary
339  if (KWallet::Wallet::isEnabled()) {
340  QDBusInterface kwalletd(QLatin1String( "org.kde.kwalletd" ), QLatin1String( "/modules/kwalletd" ),QLatin1String( KWALLETMANAGERINTERFACE ));
341  kwalletd.call( QLatin1String( "reconfigure" ) );
342  }
343  emit changed(false);
344 }
345 
346 
347 void KWalletConfig::defaults() {
348  _wcw->_enabled->setChecked(true);
349  _wcw->_openPrompt->setChecked(false);
350  _wcw->_launchManager->setChecked(true);
351  _wcw->_autocloseManager->setChecked(false);
352  _wcw->_screensaverLock->setChecked(false);
353  _wcw->_autoclose->setChecked(true);
354  _wcw->_closeIdle->setChecked(false);
355  _wcw->_idleTime->setValue(10);
356  _wcw->_defaultWallet->setCurrentIndex(0);
357  _wcw->_localWalletSelected->setChecked(false);
358  _wcw->_localWallet->setCurrentIndex( 0 );
359  _wcw->_accessList->clear();
360  emit changed(true);
361 }
362 
363 
364 QString KWalletConfig::quickHelp() const {
365  return i18n("This configuration module allows you to configure the KDE wallet system.");
366 }
367 
368 
369 void KWalletConfig::customContextMenuRequested(const QPoint& pos) {
370  QTreeWidgetItem *item = _wcw->_accessList->itemAt(pos);
371  if (item && item->parent()) {
372  KMenu *m = new KMenu(this);
373  m->addTitle(item->parent()->text(0));
374  m->addAction( i18n("&Delete" ), this, SLOT(deleteEntry()), Qt::Key_Delete);
375  m->exec(_wcw->_accessList->mapToGlobal(pos));
376  delete m;
377  }
378 }
379 
380 
381 void KWalletConfig::deleteEntry() {
382  QList<QTreeWidgetItem*> items = _wcw->_accessList->selectedItems();
383  if (items.count() == 1 && items[0] ) {
384  delete items[0];
385  emit changed(true);
386  }
387 }
388 
389 #include "konfigurator.moc"
390 
KWalletConfig::~KWalletConfig
virtual ~KWalletConfig()
Definition: konfigurator.cpp:94
QWidget
KWALLETMANAGERINTERFACE
#define KWALLETMANAGERINTERFACE
Definition: konfigurator.cpp:41
KWalletConfig::updateWalletLists
void updateWalletLists()
Definition: konfigurator.cpp:98
KWalletConfig::defaults
void defaults()
Definition: konfigurator.cpp:347
QTreeWidgetItem::child
QTreeWidgetItem * child(int index) const
KMenu
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
QDBusConnection::sessionBus
QDBusConnection sessionBus()
QPoint
QFile::exists
bool exists() const
KWalletConfig::quickHelp
QString quickHelp() const
Definition: konfigurator.cpp:364
QList::const_iterator
konfigurator.h
QDBusAbstractInterface::call
QDBusMessage call(const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8)
KWalletConfig::launchManager
void launchManager()
Definition: konfigurator.cpp:172
KWalletConfig::newLocalWallet
void newLocalWallet()
Definition: konfigurator.cpp:144
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
KWalletConfig::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
Definition: konfigurator.cpp:369
QString::isEmpty
bool isEmpty() const
QList::removeAll
int removeAll(const T &value)
QVBoxLayout
KWalletConfig
Definition: konfigurator.h:35
QString
QList
KWalletConfig::newNetworkWallet
void newNetworkWallet()
Definition: konfigurator.cpp:158
WalletConfigWidget
Definition: konfigurator.h:26
QLayout::setMargin
void setMargin(int margin)
QStringList
QDBusInterface
QList::end
iterator end()
KWalletConfig::save
void save()
Definition: konfigurator.cpp:261
QTreeWidgetItem::parent
QTreeWidgetItem * parent() const
KWalletConfig::configChanged
void configChanged()
Definition: konfigurator.cpp:183
QTreeWidgetItem
QLatin1String
KWalletConfig::deleteEntry
void deleteEntry()
Definition: konfigurator.cpp:381
KWalletConfig::load
void load()
Definition: konfigurator.cpp:187
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
QTreeWidgetItem::childCount
int childCount() const
QTreeWidgetItem::text
QString text(int column) const
QList::begin
iterator begin()
KCModule
QBoxLayout::setSpacing
void setSpacing(int spacing)
KWalletConfig::newWallet
QString newWallet()
Definition: konfigurator.cpp:121
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kwallet

Skip menu "kwallet"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal