summaryrefslogtreecommitdiffstats
path: root/kresources/carddav/preferences.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-31 07:49:08 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-31 07:49:08 +0000
commit7ef3b0e2a5e5bc9bf928e989e4f66932be096824 (patch)
treed1b924b843f78b9d9de26becb36bb8e12f7fef44 /kresources/carddav/preferences.h
parentf4a40d0495ff26b8767cf321fa8039e5ac633c12 (diff)
downloadtdepim-7ef3b0e2a5e5bc9bf928e989e4f66932be096824.tar.gz
tdepim-7ef3b0e2a5e5bc9bf928e989e4f66932be096824.zip
Added new carddav resource for kaddressbook
Lots of bugfixes for korganizer caldav resource git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1132701 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kresources/carddav/preferences.h')
-rw-r--r--kresources/carddav/preferences.h153
1 files changed, 153 insertions, 0 deletions
diff --git a/kresources/carddav/preferences.h b/kresources/carddav/preferences.h
new file mode 100644
index 00000000..c3f31ed2
--- /dev/null
+++ b/kresources/carddav/preferences.h
@@ -0,0 +1,153 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| CardDAV resource preferences class.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABC_CARDDAVPREFS_H
+#define KABC_CARDDAVPREFS_H
+
+#include "prefsskel.h"
+
+#include <kwallet.h>
+#include <kdebug.h>
+
+class QString;
+
+namespace KABC {
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * This class provides access to ResourceCardDav preferences.
+ * It inherits auto-generated CardDavPrefsSkel class to add password-handling code.
+ * KWallet is used for storing passwords.
+ * It also adds code to allow multiple CardDAV resources to store settings in the same
+ * config file.
+ */
+class CardDavPrefs : public CardDavPrefsSkel {
+
+public:
+
+ /**
+ * @param prefix Unique prefix of the resource instance (use identifier() method).
+ */
+ CardDavPrefs(const QString& prefix)
+ : mWallet(NULL)
+ , mNoWallet(false)
+ , mPrefix(prefix)
+ , mPassword(NO_PASSWORD)
+ {
+ addPrefix(prefix);
+ }
+
+ virtual ~CardDavPrefs() {
+ kdDebug() << "removing wallet";
+ removeWallet();
+ }
+
+ virtual void writeConfig();
+ virtual void readConfig();
+
+ /**
+ * Sets a new password. Also, if remember password flag is true,
+ * remembers the password in the wallet. So, if you want the password
+ * to be properly saved, call this method after ensuring the remember flag
+ * is set.
+ */
+ void setPassword(const QString& p);
+
+ /**
+ * Returns password. The password is taken from the wallet.
+ * May return an empty string, if there is no password available.
+ */
+ QString password();
+
+ /**
+ * Returns the username.
+ */
+ QString getusername();
+
+ void setRememberPassword(bool v);
+
+ /**
+ * @return A full URL to connect to CardDAV server (including username and password).
+ */
+ QString getFullUrl();
+
+protected:
+
+ /**
+ * Add an unique prefix to KConfigGroup, so that different instances of the resource
+ * can use the same config file.
+ * @param prefix Unique prefix of the resource instance.
+ */
+ void addPrefix(const QString& prefix);
+
+ /**
+ * Returns the wallet or NULL, if the wallet can't be obtained.
+ */
+ KWallet::Wallet* getWallet();
+
+ /**
+ * Tries to set a working folder for the wallet. If the wallet is not configured yet, does nothing.
+ * @param folder the wallet working folder
+ * @return true, if the folder has been set, and false otherwise.
+ */
+ bool setWalletFolder(const QString& folder);
+
+ /**
+ * Removes the wallet. If @p noWallet is set, the wallet has been marked inaccessible, so that subsequent
+ * getWallet calls will not try to recreate it.
+ */
+ void removeWallet(bool noWallet = false);
+
+ /**
+ * Wrire password to the wallet.
+ * @param password password to write
+ * @return true on success, false on failure
+ */
+ bool writePasswordToWallet(const QString& password);
+
+ /**
+ * Extracts password from the wallet.
+ * @param password a variable to save read password to.
+ * @return true on success, false on failure
+ */
+ bool readPasswordFromWallet(QString& password);
+
+ /**
+ * Clears password in the wallet.
+ * @return true on success, false on failure
+ */
+ bool removePasswordFromWallet();
+
+private:
+
+ static const QString NO_PASSWORD;
+ static const QString WALLET_FOLDER;
+ static const QString WALLET_PWD_SUFFIX;
+
+ KWallet::Wallet* mWallet;
+ bool mNoWallet;
+
+ QString mPrefix;
+ QString mPassword;
+};
+
+} // namespace KABC
+
+#endif // KABC_CARDDAVPREFS_H
+
+