• 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
  • 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, effectiveWinId());
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, effectiveWinId());
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  } else {
131  _wallet = KWallet::Wallet::openWallet(_walletName, window()->winId());
132  }
133  onSetupWidget();
134 }
135 
136 void WalletControlWidget::onWalletClosed()
137 {
138  _wallet = 0;
139  onSetupWidget();
140 }
141 
142 void WalletControlWidget::updateWalletDisplay()
143 {
144 // QList<QAction*> existingActions = _disconnect->actions();
145 // QList<QAction*>::const_iterator i = existingActions.constBegin();
146 // QList<QAction*>::const_iterator ie = existingActions.constEnd();
147 // for ( ; i != ie; i++ ) {
148 // _disconnect->removeAction(*i);
149 // }
150 //
151 }
152 
153 void WalletControlWidget::onDisconnectApplication()
154 {
155  QAction *a = qobject_cast<QAction *>(sender());
156  Q_ASSERT(a);
157  if (a) {
158  KWallet::Wallet::disconnectApplication(_walletName, a->data().toString());
159  }
160 }
161 
162 void WalletControlWidget::onChangePassword()
163 {
164  KWallet::Wallet::changePassword(_walletName, effectiveWinId());
165 }
166 
167 void WalletControlWidget::hideEvent(QHideEvent* )
168 {
169 }
170 
171 void WalletControlWidget::showEvent(QShowEvent* ev)
172 {
173 }
174 
175 #include "walletcontrolwidget.moc"
QHideEvent
WalletControlWidget::onWalletClosed
void onWalletClosed()
Definition: walletcontrolwidget.cpp:136
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
ApplicationsManager
Definition: applicationsmanager.h:33
WalletControlWidget::showEvent
virtual void showEvent(QShowEvent *)
Definition: walletcontrolwidget.cpp:171
WalletControlWidget::WalletControlWidget
WalletControlWidget(QWidget *parent, const QString &walletName)
Definition: walletcontrolwidget.cpp:35
QWidget::window
QWidget * window() const
WalletControlWidget::onChangePassword
void onChangePassword()
Definition: walletcontrolwidget.cpp:162
QObject::sender
QObject * sender() const
applicationsmanager.h
QAction::data
QVariant data() const
kwalleteditor.h
QWidget::setVisible
virtual void setVisible(bool visible)
KWalletEditor::setWallet
void setWallet(KWallet::Wallet *wallet, bool isPath=false)
Definition: kwalleteditor.cpp:175
WalletControlWidget::updateWalletDisplay
void updateWalletDisplay()
Definition: walletcontrolwidget.cpp:142
QWidget::setEnabled
void setEnabled(bool)
WalletControlWidget::onDisconnectApplication
void onDisconnectApplication()
Definition: walletcontrolwidget.cpp:153
QShowEvent
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
QWidget::winId
WId winId() const
QString
walletcontrolwidget.h
QLatin1String
Yes
Definition: kwalleteditor.cpp:945
KWalletEditor
Definition: kwalleteditor.h:42
QAction
WalletControlWidget::openWallet
bool openWallet()
Definition: walletcontrolwidget.cpp:48
QIcon::fromTheme
QIcon fromTheme(const QString &name, const QIcon &fallback)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QWidget::effectiveWinId
WId effectiveWinId() const
QVariant::toString
QString toString() const
QTimer::singleShot
singleShot
WalletControlWidget::hideEvent
virtual void hideEvent(QHideEvent *)
Definition: walletcontrolwidget.cpp:167
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