summaryrefslogtreecommitdiffstats
path: root/kresources/carddav/resource.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/resource.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/resource.h')
-rw-r--r--kresources/carddav/resource.h214
1 files changed, 214 insertions, 0 deletions
diff --git a/kresources/carddav/resource.h b/kresources/carddav/resource.h
new file mode 100644
index 000000000..8df126e28
--- /dev/null
+++ b/kresources/carddav/resource.h
@@ -0,0 +1,214 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Main interface to the KResource system.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#ifndef KABC_RESOURCECARDDAV_H
+#define KABC_RESOURCECARDDAV_H
+
+#include "preferences.h"
+#include <qthread.h>
+#include <qptrqueue.h>
+
+#include <kabcresourcecached.h>
+#include <libkdepim/progressmanager.h>
+
+#include <kabc/locknull.h>
+
+#include <kdepimmacros.h>
+#include <kconfig.h>
+
+namespace KABC {
+
+class CardDavReader;
+class CardDavWriter;
+
+/*=========================================================================
+| CLASS
+ ========================================================================*/
+
+/**
+ * This class provides a resource for accessing calendars via CardDAV protocol.
+ */
+class KDE_EXPORT ResourceCardDav : public ResourceCached
+{
+ Q_OBJECT
+
+public:
+
+ explicit ResourceCardDav( const KConfig *config );
+ virtual ~ResourceCardDav();
+
+ void readConfig( const KConfig *config );
+ void writeConfig( KConfig *config );
+
+ virtual Ticket *requestSaveTicket();
+ virtual void releaseSaveTicket( Ticket* );
+
+ /**
+ * @return This resource preferences.
+ */
+ CardDavPrefs* prefs() {
+ return mPrefs;
+ }
+
+ /**
+ * @return This resource preferences.
+ */
+ const CardDavPrefs* prefs() const {
+ return mPrefs;
+ }
+
+ virtual void setReadOnly(bool v);
+
+protected slots:
+
+ void loadFinished();
+
+ virtual bool doSave();
+
+ void writingFinished();
+
+protected:
+
+ struct LoadingTask {
+ QString url;
+ };
+
+ struct WritingTask {
+ QString url;
+ QString added;
+ QString changed;
+ QString deleted;
+ };
+
+
+// virtual bool doLoad( bool syncCache );
+// virtual bool doSave( bool syncCache );
+
+ virtual bool load();
+
+ virtual bool save( Ticket* ticket );
+
+ virtual KABC::Lock* lock();
+
+ /**
+ * Creates prefs and configures them.
+ * @return a newly created preferences object. It should be removed by the caller.
+ */
+ CardDavPrefs* createPrefs() const;
+
+ /**
+ * Initializes internal state.
+ * Particulary, sets save and reload policies to default values,
+ * creates writing and reading jobs and preferences objects.
+ */
+ void init();
+
+ /**
+ * Initiates calendar loading process.
+ * @param url URL to load calendar data from.
+ */
+ void startLoading(const QString& url);
+
+ /**
+ * Checks if the data is correct and can be parsed.
+ * @param data ical string to check.
+ * @return true if the data is correct, false otherwise.
+ */
+ bool checkData(const QString& data);
+
+ /**
+ * Parses the data and adds events to the calendar.
+ * @param data calendar data.
+ * @return true on success, false on fail.
+ */
+ bool parseData(const QString& data);
+
+ /**
+ * Initiates calendar writing process.
+ * @param url URL to save calendar data to.
+ * @return true if write was queued successfully, false if not
+ */
+ bool startWriting(const QString& url);
+
+ /**
+ * Ensures incidences' read-only states are the same as the calendar's read-only state.
+ */
+ void ensureReadOnlyFlagHonored();
+
+ /**
+ * If the loading queue is empty or the loader is not ready, does nothing.
+ * Otherwise, pops a head element and starts a loading process for it.
+ */
+ void loadingQueuePop();
+
+ /**
+ * Pushes the given loading task to the loading queue.
+ * Then calls loadingQueuePop.
+ */
+ void loadingQueuePush(const LoadingTask *task);
+
+ /**
+ * If the writing queue is empty or the writer is not ready, does nothing.
+ * Otherwise, pops a head element and starts a writing process for it.
+ */
+ void writingQueuePop();
+
+ /**
+ * Pushes the given writing task to the writing queue.
+ * Then calls writingQueuePop.
+ */
+ void writingQueuePush(const WritingTask *task);
+
+ virtual bool event ( QEvent * e );
+
+private:
+
+ // constants: =============================================================
+
+ /// Termination waiting time in milliseconds. Used to terminate job threads.
+ static const unsigned long TERMINATION_WAITING_TIME;
+
+ /**
+ * Resource caches only events which are from the interval [-CACHE_DAYS, CACHE_DAYS].
+ */
+ static const int CACHE_DAYS;
+
+ static const int DEFAULT_RELOAD_INTERVAL;
+ static const int DEFAULT_SAVE_INTERVAL;
+ static const int DEFAULT_RELOAD_POLICY;
+ static const int DEFAULT_SAVE_POLICY;
+
+ // members: ===============================================================
+
+ KABC::LockNull mLock;
+ CardDavPrefs* mPrefs;
+ CardDavReader* mLoader;
+ CardDavWriter* mWriter;
+ KPIM::ProgressItem *mProgress;
+
+ bool mLoadingQueueReady;
+ QPtrQueue<LoadingTask> mLoadingQueue;
+
+ bool mWritingQueueReady;
+ QPtrQueue<WritingTask> mWritingQueue;
+
+};
+
+
+
+} // namespace KABC
+
+#endif // KABC_RESOURCECARDDAV_H
+