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

kwallet

  • sources
  • kde-4.12
  • kdeutils
  • kwalletmanager
  • src
  • manager
walletcontrolwidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 Valentin Rusu <kde@rusu.info>
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 
20 #include "walletcontrolwidget.h"
21 #include "kwalleteditor.h"
22 #include "applicationsmanager.h"
23 
24 #include <QPropertyAnimation>
25 #include <QTimer>
26 #include <QFrame>
27 #include <QToolButton>
28 #include <qevent.h>
29 #include <kwallet.h>
30 #include <kmessagebox.h>
31 #include <kmenu.h>
32 #include <KTabWidget>
33 #include <kdebug.h>
34 
35 WalletControlWidget::WalletControlWidget(QWidget* parent, const QString& walletName):
36  QWidget(parent),
37  _walletName(walletName),
38  _wallet(0),
39  _walletEditor(0),
40  _applicationsManager(0)
41 {
42  setupUi(this);
43  onSetupWidget();
44 
45  QTimer::singleShot(1, this, SLOT(onSetupWidget()));
46 }
47 
48 bool WalletControlWidget::openWallet()
49 {
50  bool result = false;
51  if (_wallet && _wallet->isOpen()) {
52  result = true; // already opened
53  } else {
54  _wallet = KWallet::Wallet::openWallet(_walletName, winId());
55  result = _wallet != 0;
56  onSetupWidget();
57  }
58  return result;
59 }
60 
61 void WalletControlWidget::onSetupWidget()
62 {
63  if (KWallet::Wallet::isOpen(_walletName)) {
64  if (0 == _wallet) {
65  _wallet = KWallet::Wallet::openWallet(_walletName, winId());
66  if (0 == _wallet) {
67  kDebug() << "Weird situation: wallet could not be opened when setting-up the widget.";
68  }
69  }
70  }
71 
72  if (_wallet) {
73  connect(_wallet, SIGNAL(walletClosed()), this, SLOT(onWalletClosed()));
74  _openClose->setText(i18n("&Close"));
75 
76  if (0 == _walletEditor) {
77  _walletEditor = new KWalletEditor(_editorFrame);
78  _editorFrameLayout->addWidget(_walletEditor);
79  _walletEditor->setVisible(true);
80  }
81  _walletEditor->setWallet(_wallet);
82 
83  if (0 == _applicationsManager) {
84  _applicationsManager = new ApplicationsManager(_applicationsFrame);
85  _applicationsFrameLayout->addWidget(_applicationsManager);
86  _applicationsManager->setVisible(true);
87  }
88  _applicationsManager->setWallet(_wallet);
89 
90  _changePassword->setEnabled(true);
91  _stateLabel->setText(i18nc("the 'kdewallet' is currently open (e.g. %1 will be replaced with current wallet name)", "The '%1' wallet is currently open", _walletName));
92  _tabs->setTabIcon(0, QIcon::fromTheme( QLatin1String("wallet-open")).pixmap(16));
93  } else {
94  _openClose->setText(i18n("&Open..."));
95 
96  if (_walletEditor) {
97  _walletEditor->setVisible(false);
98  delete _walletEditor, _walletEditor =0;
99  }
100 
101  if (_applicationsManager) {
102  _applicationsManager->setVisible(false);
103  delete _applicationsManager, _applicationsManager = 0;
104  }
105  _changePassword->setEnabled(false);
106  _stateLabel->setText(i18n("The wallet is currently closed"));
107  _tabs->setTabIcon(0, QIcon::fromTheme( QLatin1String("wallet-closed")).pixmap(16));
108  }
109 }
110 
111 void WalletControlWidget::onOpenClose()
112 {
113  // TODO create some fancy animation here to make _walletEditor appear or dissapear in a fancy way
114  if (_wallet) {
115  // Wallet is open, attempt close it
116  int rc = KWallet::Wallet::closeWallet(_walletName, false);
117  if (rc != 0) {
118  rc = KMessageBox::warningYesNo(this, i18n("Unable to close wallet cleanly. It is probably in use by other applications. Do you wish to force it closed?"), QString(), KGuiItem(i18n("Force Closure")), KGuiItem(i18n("Do Not Force")));
119  if (rc == KMessageBox::Yes) {
120  rc = KWallet::Wallet::closeWallet(_walletName, true);
121  if (rc != 0) {
122  KMessageBox::sorry(this, i18n("Unable to force the wallet closed. Error code was %1.", rc));
123  } else {
124  _wallet = 0;
125  }
126  }
127  } else {
128  _wallet = 0;
129  }
130  }
131  else {
132  _wallet = KWallet::Wallet::openWallet(_walletName, winId());
133  }
134  onSetupWidget();
135 }
136 
137 void WalletControlWidget::onWalletClosed()
138 {
139  _wallet = 0;
140  onSetupWidget();
141 }
142 
143 void WalletControlWidget::updateWalletDisplay()
144 {
145 // QList<QAction*> existingActions = _disconnect->actions();
146 // QList<QAction*>::const_iterator i = existingActions.constBegin();
147 // QList<QAction*>::const_iterator ie = existingActions.constEnd();
148 // for ( ; i != ie; i++ ) {
149 // _disconnect->removeAction(*i);
150 // }
151 //
152 }
153 
154 void WalletControlWidget::onDisconnectApplication()
155 {
156  QAction *a = qobject_cast<QAction *>(sender());
157  Q_ASSERT(a);
158  if (a) {
159  KWallet::Wallet::disconnectApplication(_walletName, a->data().toString());
160  }
161 }
162 
163 void WalletControlWidget::onChangePassword()
164 {
165  KWallet::Wallet::changePassword(_walletName, winId());
166 }
167 
168 void WalletControlWidget::hideEvent(QHideEvent* )
169 {
170 }
171 
172 void WalletControlWidget::showEvent(QShowEvent* ev)
173 {
174 }
175 
176 #include "walletcontrolwidget.moc"
WalletControlWidget::onWalletClosed
void onWalletClosed()
Definition: walletcontrolwidget.cpp:137
ApplicationsManager
Definition: applicationsmanager.h:33
WalletControlWidget::showEvent
virtual void showEvent(QShowEvent *)
Definition: walletcontrolwidget.cpp:172
WalletControlWidget::WalletControlWidget
WalletControlWidget(QWidget *parent, const QString &walletName)
Definition: walletcontrolwidget.cpp:35
WalletControlWidget::onChangePassword
void onChangePassword()
Definition: walletcontrolwidget.cpp:163
applicationsmanager.h
kwalleteditor.h
QWidget
KWalletEditor::setWallet
void setWallet(KWallet::Wallet *wallet, bool isPath=false)
Definition: kwalleteditor.cpp:175
WalletControlWidget::updateWalletDisplay
void updateWalletDisplay()
Definition: walletcontrolwidget.cpp:143
WalletControlWidget::onDisconnectApplication
void onDisconnectApplication()
Definition: walletcontrolwidget.cpp:154
ApplicationsManager::setWallet
void setWallet(KWallet::Wallet *wallet)
Definition: applicationsmanager.cpp:45
WalletControlWidget::onOpenClose
void onOpenClose()
Definition: walletcontrolwidget.cpp:111
WalletControlWidget::onSetupWidget
void onSetupWidget()
Definition: walletcontrolwidget.cpp:61
walletcontrolwidget.h
Yes
Definition: kwalleteditor.cpp:944
KWalletEditor
Definition: kwalleteditor.h:42
WalletControlWidget::openWallet
bool openWallet()
Definition: walletcontrolwidget.cpp:48
WalletControlWidget::hideEvent
virtual void hideEvent(QHideEvent *)
Definition: walletcontrolwidget.cpp:168
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:38 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
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • 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