File indexing completed on 2024-05-19 05:55:47
0001 /* 0002 SPDX-FileCopyrightText: 2003 George Staikos <staikos@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kwalletpopup.h" 0008 0009 #include <KStandardAction> 0010 #include <KActionCollection> 0011 #include <QAction> 0012 #include <KLocalizedString> 0013 #include <KMessageBox> 0014 #include <KWallet> 0015 0016 0017 KWalletPopup::KWalletPopup(const QString &wallet, QWidget *parent, const QString &name) 0018 : QMenu(parent), _walletName(wallet) 0019 { 0020 addSection(wallet); 0021 setObjectName(name); 0022 auto ac = new KActionCollection(this/*, "kwallet context actions"*/); 0023 ac->setObjectName(QStringLiteral("kwallet context actions")); 0024 QAction *act; 0025 0026 act = ac->addAction(QStringLiteral("wallet_create")); 0027 act->setText(i18n("&New Wallet...")); 0028 connect(act, &QAction::triggered, this, &KWalletPopup::createWallet); 0029 addAction(act); 0030 0031 act = ac->addAction(QStringLiteral("wallet-open")); 0032 act->setText(i18n("&Open...")); 0033 connect(act, &QAction::triggered, this, &KWalletPopup::openWallet); 0034 act->setShortcut(QKeySequence(Qt::Key_Return)); 0035 addAction(act); 0036 0037 act = ac->addAction(QStringLiteral("wallet_password")); 0038 act->setText(i18n("Change &Password...")); 0039 connect(act, &QAction::triggered, this, &KWalletPopup::changeWalletPassword); 0040 addAction(act); 0041 0042 const QStringList ul = KWallet::Wallet::users(wallet); 0043 if (!ul.isEmpty()) { 0044 auto pm = new QMenu(this); 0045 pm->setObjectName(QStringLiteral("Disconnect Apps")); 0046 for (QStringList::const_iterator it = ul.begin(), end(ul.end()); it != end; ++it) { 0047 QAction *a = pm->addAction(*it, this, &KWalletPopup::disconnectApp); 0048 a->setData(*it); 0049 } 0050 QAction *act = addMenu(pm); 0051 act->setText(i18n("Disconnec&t")); 0052 } 0053 0054 act = KStandardAction::close(this, 0055 SLOT(closeWallet()), ac); 0056 ac->addAction(QStringLiteral("wallet_close"), act); 0057 // FIXME: let's track this inside the manager so we don't need a dcop 0058 // roundtrip here. 0059 act->setEnabled(KWallet::Wallet::isOpen(wallet)); 0060 addAction(act); 0061 0062 act = ac->addAction(QStringLiteral("wallet_delete")); 0063 act->setText(i18n("&Delete")); 0064 0065 connect(act, &QAction::triggered, this, &KWalletPopup::deleteWallet); 0066 act->setShortcut(QKeySequence(Qt::Key_Delete)); 0067 addAction(act); 0068 } 0069 0070 KWalletPopup::~KWalletPopup() = default; 0071 0072 void KWalletPopup::openWallet() 0073 { 0074 Q_EMIT walletOpened(_walletName); 0075 } 0076 0077 void KWalletPopup::deleteWallet() 0078 { 0079 Q_EMIT walletDeleted(_walletName); 0080 } 0081 0082 void KWalletPopup::closeWallet() 0083 { 0084 Q_EMIT walletClosed(_walletName); 0085 } 0086 0087 void KWalletPopup::changeWalletPassword() 0088 { 0089 Q_EMIT walletChangePassword(_walletName); 0090 } 0091 0092 void KWalletPopup::createWallet() 0093 { 0094 Q_EMIT walletCreated(); 0095 } 0096 0097 void KWalletPopup::disconnectApp() 0098 { 0099 auto a = qobject_cast<QAction *>(sender()); 0100 Q_ASSERT(a); 0101 if (a) { 0102 KWallet::Wallet::disconnectApplication(_walletName, a->data().toString()); 0103 } 0104 } 0105 0106 #include "moc_kwalletpopup.cpp"