File indexing completed on 2023-11-26 04:55:47

0001 /*
0002  * This file is part of telepathy-accounts-kcm
0003  *
0004  * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #ifndef WALLETINTERFACE_H
0022 #define WALLETINTERFACE_H
0023 
0024 #include <TelepathyQt/Account>
0025 #include <TelepathyQt/PendingOperation>
0026 
0027 #include <KWallet/KWallet>
0028 
0029 #include <QScopedPointer>
0030 
0031 #include <KTp/ktpcommoninternals_export.h>
0032 
0033 namespace KTp
0034 {
0035 
0036 class WalletInterfacePrivate;
0037 class PendingWallet;
0038 
0039 
0040 /** Class wraps interface around KWallet. A singleton is used to make sure that the wallet is only even opened once if multiple instances of
0041     this class are used throughout the application*/
0042 
0043 class KTPCOMMONINTERNALS_EXPORT WalletInterface
0044 {
0045     friend class WalletInterfacePrivate;
0046 public:
0047 
0048     /** Tries to open the wallet. Op contains a pointer to the wallet operation interface*/
0049     static KTp::PendingWallet *openWallet();
0050 
0051     /** Returns true if a password is stored for the given account */
0052     bool hasPassword(const Tp::AccountPtr &account);
0053 
0054     /** Returns the stored password for the given account */
0055     QString password(const Tp::AccountPtr &account);
0056 
0057     /** Set the password for the given account to a new password */
0058     void setPassword(const Tp::AccountPtr &account, const QString &password);
0059 
0060     /** Sets whether using the password failed */
0061     void setLastLoginFailed(const Tp::AccountPtr &account, bool failed);
0062 
0063     /** Returns whether using the password failed */
0064     bool lastLoginFailed(const Tp::AccountPtr &account);
0065 
0066     /** Remove the password for the given account from kwallet */
0067     void removePassword(const Tp::AccountPtr &account);
0068 
0069     /** Returns true if a given entry is stored for the given account */
0070     bool hasEntry(const Tp::AccountPtr &account, const QString &key);
0071 
0072     /** Returns the stored entry for the given account */
0073     QString entry(const Tp::AccountPtr &account, const QString &key);
0074 
0075     /** Set an entry for the given account to a new value */
0076     void setEntry(const Tp::AccountPtr &account, const QString &key, const QString &value);
0077 
0078     /** Remove the entry for the given account from kwallet */
0079     void removeEntry(const Tp::AccountPtr &account, const QString &key);
0080 
0081     /** Remove all the entries for the given account from kwallet */
0082     void removeAllEntries(const Tp::AccountPtr &account);
0083 
0084     /** Remove entries and password for the account from kwallet */
0085     void removeAccount(const Tp::AccountPtr &account);
0086 
0087     /** Determine if the wallet is open, and is a valid wallet handle */
0088     bool isOpen();
0089 
0090     /** Raw access to the underlying wallet. Should not be used.*/
0091     KWallet::Wallet* wallet() const;
0092 
0093 private:
0094     Q_DISABLE_COPY(WalletInterface)
0095     WalletInterface();
0096     virtual ~WalletInterface();
0097     WalletInterfacePrivate * const d;
0098 };
0099 
0100 } // namespace KTp
0101 
0102 #endif // WALLETINTERFACE_H