File indexing completed on 2023-12-03 05:01:59
0001 /* 0002 Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Lesser General Public License for more details. 0013 0014 You should have received a copy of the GNU Lesser General Public 0015 License along with this library; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 #include "wallet-utils.h" 0020 0021 #include <TelepathyQt/PendingOperation> 0022 #include <TelepathyQt/Account> 0023 0024 #include <KTp/wallet-interface.h> 0025 #include <KTp/pending-wallet.h> 0026 0027 class SetAccountPasswordOp : public Tp::PendingOperation 0028 { 0029 Q_OBJECT 0030 public: 0031 explicit SetAccountPasswordOp(const Tp::AccountPtr &account, const QString &password); 0032 0033 static Tp::PendingOperation * setAccountPassword(const Tp::AccountPtr &account, const QString &password); 0034 0035 private Q_SLOTS: 0036 void onWalletOpened(Tp::PendingOperation *op); 0037 private: 0038 Tp::AccountPtr m_account; 0039 QString m_password; 0040 }; 0041 0042 class RemoveAccountPasswordOp : public Tp::PendingOperation 0043 { 0044 Q_OBJECT 0045 public: 0046 explicit RemoveAccountPasswordOp(const Tp::AccountPtr &account); 0047 0048 private Q_SLOTS: 0049 void onWalletOpened(Tp::PendingOperation *op); 0050 private: 0051 Tp::AccountPtr m_account; 0052 }; 0053 0054 0055 Tp::PendingOperation* KTp::WalletUtils::setAccountPassword(const Tp::AccountPtr &account, const QString &password) 0056 { 0057 return new SetAccountPasswordOp(account, password); 0058 } 0059 0060 Tp::PendingOperation* KTp::WalletUtils::removeAccountPassword(const Tp::AccountPtr &account) 0061 { 0062 return new RemoveAccountPasswordOp(account); 0063 } 0064 0065 SetAccountPasswordOp::SetAccountPasswordOp(const Tp::AccountPtr &account, const QString &password) : 0066 Tp::PendingOperation(account), 0067 m_account(account), 0068 m_password(password) 0069 { 0070 connect(KTp::WalletInterface::openWallet(), 0071 SIGNAL(finished(Tp::PendingOperation*)), 0072 SLOT(onWalletOpened(Tp::PendingOperation*))); 0073 } 0074 0075 void SetAccountPasswordOp::onWalletOpened(Tp::PendingOperation *op) 0076 { 0077 KTp::PendingWallet *walletOp = qobject_cast<KTp::PendingWallet*>(op); 0078 Q_ASSERT(walletOp); 0079 0080 KTp::WalletInterface *walletInterface = walletOp->walletInterface(); 0081 0082 //note deliberate using isNull, not isEmpty, as the password could be empty which is valid 0083 if (m_password.isNull()) { 0084 walletInterface->removePassword(m_account); 0085 } else { 0086 walletInterface->setPassword(m_account, m_password); 0087 } 0088 } 0089 0090 0091 RemoveAccountPasswordOp::RemoveAccountPasswordOp(const Tp::AccountPtr &account) : 0092 Tp::PendingOperation(account), 0093 m_account(account) 0094 { 0095 connect(KTp::WalletInterface::openWallet(), 0096 SIGNAL(finished(Tp::PendingOperation*)), 0097 SLOT(onWalletOpened(Tp::PendingOperation*))); 0098 } 0099 0100 void RemoveAccountPasswordOp::onWalletOpened(Tp::PendingOperation *op) 0101 { 0102 KTp::PendingWallet *walletOp = qobject_cast<KTp::PendingWallet*>(op); 0103 Q_ASSERT(walletOp); 0104 0105 KTp::WalletInterface *walletInterface = walletOp->walletInterface(); 0106 walletInterface->removeAccount(m_account); 0107 setFinished(); 0108 } 0109 0110 #include "wallet-utils.moc"