File indexing completed on 2025-01-19 03:55:38
0001 // 0002 // Created by michaelpollind on 3/13/17. 0003 // 0004 #ifndef O2_O0KEYCHAINSTORE_H 0005 #define O2_O0KEYCHAINSTORE_H 0006 0007 #include <QtCore/QMap> 0008 #include "o0abstractstore.h" 0009 #include <QString> 0010 0011 namespace QKeychain { 0012 class Job; 0013 } 0014 0015 /// Calling persist(), fetchFromKeychain() and clearFromKeychain() member 0016 /// functions is the responsibility of the user of this class. 0017 /// This is important to minimize the number of keychain accesses (and 0018 /// potentially the number of user password prompts). 0019 /// For example: fetchFromKeychain() can be called immediately after 0020 /// creating a keychain store; persist() - after a successful authorization; 0021 /// clearFromKeychain() - when the user logs out from the service. 0022 class O0_EXPORT o0keyChainStore : public O0AbstractStore{ 0023 Q_OBJECT 0024 public: 0025 explicit o0keyChainStore(const QString& app,const QString& name,QObject *parent = 0); 0026 0027 /// Retrieve a string value by key. 0028 QString value(const QString &key, const QString &defaultValue = QString()); 0029 0030 /// Set a string value for a key. 0031 void setValue(const QString &key, const QString &value); 0032 0033 // The functions below return QKeychain::Error casted to int. They don't 0034 // return the enumerator directly because it can not be forward-declared reliably, 0035 // and including <keychain.h> into this header may be undesirable. 0036 // Note that if 0 is returned, then there was no error. 0037 0038 int persist(); 0039 int fetchFromKeychain(); 0040 int clearFromKeychain(); 0041 0042 /// @return true if @p errorCode is equal to QKeychain::EntryNotFound. 0043 /// @note This function can be used to single out one type of an error 0044 /// returned from the functions above without including <keychain.h>. 0045 /// The EntryNotFound error type is special because it can be considered 0046 /// not an error if returned from clearFromKeychain(). 0047 static bool isEntryNotFoundError(int errorCode); 0048 0049 private: 0050 void initJob(QKeychain::Job &job) const; 0051 int executeJob(QKeychain::Job &job, const char *actionName) const; 0052 0053 QString app_; 0054 QString name_; 0055 QMap<QString,QString> pairs_; 0056 0057 }; 0058 0059 0060 #endif //O2_O0KEYCHAINSTORE_H