File indexing completed on 2024-04-21 05:01:41
0001 /* 0002 This is the wallet manager of Smb4K. 0003 0004 SPDX-FileCopyrightText: 2008-2022 Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SMB4KWALLETMANAGER_H 0009 #define SMB4KWALLETMANAGER_H 0010 0011 // application specific includes 0012 #include "smb4kglobal.h" 0013 0014 // Qt includes 0015 #include <QList> 0016 #include <QWidget> 0017 0018 // forward declarations 0019 class Smb4KAuthInfo; 0020 class Smb4KWalletManagerPrivate; 0021 0022 /** 0023 * This class manages the access to the digital wallet where the login 0024 * credentials are stored. 0025 * 0026 * If the user chooses to not use the wallet, a password dialog is shown every 0027 * time authentication information is needed. 0028 * 0029 * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net> 0030 */ 0031 0032 class Q_DECL_EXPORT Smb4KWalletManager : public QObject 0033 { 0034 Q_OBJECT 0035 0036 friend class Smb4KWalletManagerPrivate; 0037 0038 public: 0039 /** 0040 * The constructor 0041 */ 0042 explicit Smb4KWalletManager(QObject *parent = nullptr); 0043 0044 /** 0045 * The destructor 0046 */ 0047 ~Smb4KWalletManager(); 0048 0049 /** 0050 * This is a static pointer to this class. 0051 */ 0052 static Smb4KWalletManager *self(); 0053 0054 /** 0055 * Read the login credentials for the given @p networkItem object. 0056 * 0057 * @param networkItem The NetworkItemPtr object 0058 */ 0059 void readLoginCredentials(const NetworkItemPtr &networkItem); 0060 0061 /** 0062 * Read the login credentials for the given URL in the @p authInfo object. 0063 * 0064 * To get the default login credetials, pass an Smb4KAuthInfo object with 0065 * type Smb4KGlobal::UnknownNetworkItem to this function. 0066 * 0067 * @param authInfo The Smb4KAuthInfo object 0068 */ 0069 void readLoginCredentials(Smb4KAuthInfo *authInfo); 0070 0071 /** 0072 * Write the login credentials stored in the @p networkItem object to the 0073 * wallet. 0074 * 0075 * @param networkItem The NetworkItemPtr object that holds the credentials 0076 */ 0077 void writeLoginCredentials(const NetworkItemPtr &networkItem); 0078 0079 /** 0080 * Write the login credentials stored in the @p authInfo object to the wallet. 0081 * 0082 * If the wallet system is disabled, this function will do nothing. 0083 * 0084 * @param authInfo The Smb4KAuthInfo object that holds the credentials 0085 */ 0086 void writeLoginCredentials(Smb4KAuthInfo *authInfo); 0087 0088 /** 0089 * Write login credentials stored in the list @p list to the wallet. 0090 * 0091 * If the wallet system is disabled, this function will do nothing. 0092 * 0093 * @param list The login credentials list 0094 */ 0095 void writeLoginCredentialsList(const QList<Smb4KAuthInfo *> &list); 0096 0097 /** 0098 * Returns the list of login credentials stored in the wallet or an empty 0099 * list if the wallet is not open, no entries are defined or the wallet 0100 * system is disabled. 0101 * 0102 * @returns a list of all login credentials 0103 */ 0104 QList<Smb4KAuthInfo *> loginCredentialsList(); 0105 0106 /** 0107 * This function returns TRUE if the wallet system can be/is used and 0108 * FALSE otherwise. 0109 * 0110 * @returns TRUE if the wallet system can be/is used. 0111 */ 0112 bool useWalletSystem() const; 0113 0114 /** 0115 * This function returns TRUE if the wallet contains already default 0116 * credentials. 0117 * 0118 * @returns TRUE if the wallet contains a default credentials entry. 0119 */ 0120 bool hasDefaultCredentials(); 0121 0122 Q_SIGNALS: 0123 /** 0124 * This signal is emitted when the wallet manager was initialized 0125 * and is ready to process authentication information. 0126 */ 0127 void initialized(); 0128 0129 /** 0130 * This signal is emitted when the credentials for @param url were updated. 0131 * If the list of credentials was cleared, an empty URL is emitted. 0132 * 0133 * @param QUrl The URL for which the credentials were updated/added 0134 */ 0135 void credentialsUpdated(const QUrl &url); 0136 0137 private: 0138 /** 0139 * Initialize the wallet manager 0140 */ 0141 bool init(); 0142 0143 /** 0144 * Read credentials form the wallet 0145 */ 0146 bool read(Smb4KAuthInfo *authInfo); 0147 0148 /** 0149 * Write credentials to the wallet 0150 */ 0151 void write(Smb4KAuthInfo *authInfo); 0152 0153 /** 0154 * Remove all credentials from the wallet 0155 */ 0156 void clear(); 0157 0158 /** 0159 * Pointer to the Smb4KWalletManagerPrivate class 0160 */ 0161 const QScopedPointer<Smb4KWalletManagerPrivate> d; 0162 }; 0163 0164 #endif