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

Nepomuk-Core

  • KTp
wallet-utils.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 David Edmundson <kde@davidedmundson.co.uk>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library 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  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "wallet-utils.h"
20 
21 #include <TelepathyQt/PendingOperation>
22 #include <TelepathyQt/Account>
23 
24 #include <KTp/wallet-interface.h>
25 #include <KTp/pending-wallet.h>
26 
27 class SetAccountPasswordOp : public Tp::PendingOperation
28 {
29  Q_OBJECT
30 public:
31  explicit SetAccountPasswordOp(const Tp::AccountPtr &account, const QString &password);
32 
33  static Tp::PendingOperation * setAccountPassword(const Tp::AccountPtr &account, const QString &password);
34 
35 private Q_SLOTS:
36  void onWalletOpened(Tp::PendingOperation *op);
37 private:
38  Tp::AccountPtr m_account;
39  QString m_password;
40 };
41 
42 class RemoveAccountPasswordOp : public Tp::PendingOperation
43 {
44  Q_OBJECT
45 public:
46  explicit RemoveAccountPasswordOp(const Tp::AccountPtr &account);
47 
48 private Q_SLOTS:
49  void onWalletOpened(Tp::PendingOperation *op);
50 private:
51  Tp::AccountPtr m_account;
52 };
53 
54 
55 Tp::PendingOperation* KTp::WalletUtils::setAccountPassword(const Tp::AccountPtr &account, const QString &password)
56 {
57  return new SetAccountPasswordOp(account, password);
58 }
59 
60 Tp::PendingOperation* KTp::WalletUtils::removeAccountPassword(const Tp::AccountPtr &account)
61 {
62  return new RemoveAccountPasswordOp(account);
63 }
64 
65 SetAccountPasswordOp::SetAccountPasswordOp(const Tp::AccountPtr &account, const QString &password) :
66  Tp::PendingOperation(account),
67  m_account(account),
68  m_password(password)
69 {
70  connect(KTp::WalletInterface::openWallet(),
71  SIGNAL(finished(Tp::PendingOperation*)),
72  SLOT(onWalletOpened(Tp::PendingOperation*)));
73 }
74 
75 void SetAccountPasswordOp::onWalletOpened(Tp::PendingOperation *op)
76 {
77  KTp::PendingWallet *walletOp = qobject_cast<KTp::PendingWallet*>(op);
78  Q_ASSERT(walletOp);
79 
80  KTp::WalletInterface *walletInterface = walletOp->walletInterface();
81 
82  //note deliberate using isNull, not isEmpty, as the password could be empty which is valid
83  if (m_password.isNull()) {
84  walletInterface->removePassword(m_account);
85  } else {
86  walletInterface->setPassword(m_account, m_password);
87  }
88 }
89 
90 
91 RemoveAccountPasswordOp::RemoveAccountPasswordOp(const Tp::AccountPtr &account) :
92  Tp::PendingOperation(account),
93  m_account(account)
94 {
95  connect(KTp::WalletInterface::openWallet(),
96  SIGNAL(finished(Tp::PendingOperation*)),
97  SLOT(onWalletOpened(Tp::PendingOperation*)));
98 }
99 
100 void RemoveAccountPasswordOp::onWalletOpened(Tp::PendingOperation *op)
101 {
102  KTp::PendingWallet *walletOp = qobject_cast<KTp::PendingWallet*>(op);
103  Q_ASSERT(walletOp);
104 
105  KTp::WalletInterface *walletInterface = walletOp->walletInterface();
106  walletInterface->removeAccount(m_account);
107  setFinished();
108 }
109 
110 #include "wallet-utils.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
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