2
Copyright (C) 2013 Valentin Rusu <kde@rusu.info>
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.
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.
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.
20
#include "walletcontrolwidget.h"
21
#include "kwalleteditor.h"
22
#include "applicationsmanager.h"
24
#include <QPropertyAnimation>
27
#include <QToolButton>
30
#include <kmessagebox.h>
35
WalletControlWidget::WalletControlWidget(QWidget* parent, const QString& walletName):
37
_walletName(walletName),
40
_applicationsManager(0)
45
QTimer::singleShot(1, this, SLOT(onSetupWidget()));
48
bool WalletControlWidget::openWallet()
51
if (_wallet && _wallet->isOpen()) {
52
result = true; // already opened
54
_wallet = KWallet::Wallet::openWallet(_walletName, winId());
55
result = _wallet != 0;
61
void WalletControlWidget::onSetupWidget()
63
if (KWallet::Wallet::isOpen(_walletName)) {
65
_wallet = KWallet::Wallet::openWallet(_walletName, winId());
67
kDebug() << "Weird situation: wallet could not be opened when setting-up the widget.";
73
connect(_wallet, SIGNAL(walletClosed()), this, SLOT(onWalletClosed()));
74
_openClose->setText(i18n("&Close"));
76
if (0 == _walletEditor) {
77
_walletEditor = new KWalletEditor(_editorFrame);
78
_editorFrameLayout->addWidget(_walletEditor);
79
_walletEditor->setVisible(true);
81
_walletEditor->setWallet(_wallet);
83
if (0 == _applicationsManager) {
84
_applicationsManager = new ApplicationsManager(_applicationsFrame);
85
_applicationsFrameLayout->addWidget(_applicationsManager);
86
_applicationsManager->setVisible(true);
88
_applicationsManager->setWallet(_wallet);
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));
94
_openClose->setText(i18n("&Open..."));
97
_walletEditor->setVisible(false);
98
delete _walletEditor, _walletEditor =0;
101
if (_applicationsManager) {
102
_applicationsManager->setVisible(false);
103
delete _applicationsManager, _applicationsManager = 0;
105
_changePassword->setEnabled(false);
106
_stateLabel->setText(i18n("The wallet is currently closed"));
107
_tabs->setTabIcon(0, QIcon::fromTheme( QLatin1String("wallet-closed")).pixmap(16));
111
void WalletControlWidget::onOpenClose()
113
// TODO create some fancy animation here to make _walletEditor appear or dissapear in a fancy way
115
// Wallet is open, attempt close it
116
int rc = KWallet::Wallet::closeWallet(_walletName, false);
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);
122
KMessageBox::sorry(this, i18n("Unable to force the wallet closed. Error code was %1.", rc));
132
_wallet = KWallet::Wallet::openWallet(_walletName, winId());
137
void WalletControlWidget::onWalletClosed()
143
void WalletControlWidget::updateWalletDisplay()
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);
154
void WalletControlWidget::onDisconnectApplication()
156
QAction *a = qobject_cast<QAction *>(sender());
159
KWallet::Wallet::disconnectApplication(_walletName, a->data().toString());
163
void WalletControlWidget::onChangePassword()
165
KWallet::Wallet::changePassword(_walletName, winId());
168
void WalletControlWidget::hideEvent(QHideEvent* )
172
void WalletControlWidget::showEvent(QShowEvent* ev)
176
#include "walletcontrolwidget.moc"