From 1d6f24837736fd72b517b45334d37b5bc8ee7c23 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 1 Apr 2015 12:06:48 -0300 Subject: [PATCH] Implement a way to configure the initial date used for calendar sync Added SyncInterval property to allow configure the calendar sync interval. --- src/backends/evolution/EvolutionCalendarSource.cpp | 17 +++++++-- src/backends/webdav/CalDAVSource.cpp | 42 ++++++++++++++++------ src/syncevo/SyncConfig.cpp | 31 +++++++++++++++- src/syncevo/SyncConfig.h | 5 +++ 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/backends/evolution/EvolutionCalendarSource.cpp b/src/backends/evolution/EvolutionCalendarSource.cpp index 3ec63c4..11ab00f 100644 --- a/src/backends/evolution/EvolutionCalendarSource.cpp +++ b/src/backends/evolution/EvolutionCalendarSource.cpp @@ -383,10 +383,23 @@ static void list_revisions(const GSList *objects, EvolutionCalendarSource::Revis void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions) { GErrorCXX gerror; + std::string startDateFilter = getStartDate(); + eptr sexp; + + if (!startDateFilter.empty()) { + // get the biggest date + eptr endDateFilter(isodate_from_time_t (INT_MAX)); + sexp = g_strdup_printf ("(occur-in-time-range? " + "(make-time \"%s\") (make-time \"%s\"))", + startDateFilter.c_str(), + endDateFilter.get()); + } else { + sexp = g_strdup ("#t"); + } #ifdef USE_EDS_CLIENT ECalClientView *view; - if (!e_cal_client_get_view_sync (m_calendar, "#t", &view, NULL, gerror)) { + if (!e_cal_client_get_view_sync (m_calendar, sexp.get(), &view, NULL, gerror)) { throwError(SE_HERE, "getting the view" , gerror); } ECalClientViewCXX viewPtr = ECalClientViewCXX::steal(view); @@ -409,7 +422,7 @@ void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions) m_allLUIDs.clear(); if (!e_cal_get_object_list_as_comp(m_calendar, - "#t", + sexp.get(), &nextItem, gerror)) { throwError(SE_HERE, "reading all items", gerror); diff --git a/src/backends/webdav/CalDAVSource.cpp b/src/backends/webdav/CalDAVSource.cpp index fa16935..8b31ee9 100644 --- a/src/backends/webdav/CalDAVSource.cpp +++ b/src/backends/webdav/CalDAVSource.cpp @@ -60,7 +60,7 @@ void CalDAVSource::listAllSubItems(SubRevisionMap_t &revisions) { revisions.clear(); - const std::string query = + std::string query = "\n" "\n" @@ -96,8 +96,13 @@ void CalDAVSource::listAllSubItems(SubRevisionMap_t &revisions) // filter expected by Yahoo! Calendar "\n" "\n" - "\n" - "\n" + "\n"; + + std::string startDateFilter = getStartDate(); + if (!startDateFilter.empty()) + query += "\n"; + + query += "\n" "\n" "\n" "\n"; @@ -135,7 +140,7 @@ void CalDAVSource::addResource(StringMap &items, void CalDAVSource::updateAllSubItems(SubRevisionMap_t &revisions) { // list items to identify new, updated and removed ones - const std::string query = + std::string query = "\n" "\n" @@ -145,7 +150,13 @@ void CalDAVSource::updateAllSubItems(SubRevisionMap_t &revisions) // filter expected by Yahoo! Calendar "\n" "\n" - "\n" + "\n"; + + std::string startDateFilter = getStartDate(); + if (!startDateFilter.empty()) + query += "\n"; + + query += "\n" "\n" "\n" @@ -1122,7 +1133,7 @@ CalDAVSource::Event &CalDAVSource::loadItem(Event &event) report.run(); #else std::string query = - StringPrintf("\n" + "\n" "\n" "\n" @@ -1132,8 +1143,13 @@ CalDAVSource::Event &CalDAVSource::loadItem(Event &event) // filter expected by Yahoo! Calendar "\n" "\n" - "\n" - "\n" + "\n"; + + std::string startDateFilter = getStartDate(); + if (!startDateFilter.empty()) + query += "\n"; + + query += StringPrintf("\n" "\n" "\n" "\n" @@ -1351,7 +1367,7 @@ void CalDAVSource::backupData(const SyncSource::Operations::ConstBackupInfo &old cache.init(oldBackup, newBackup, false); // stream directly from REPORT with full data into backup - const std::string query = + std::string query = "\n" "\n" @@ -1362,7 +1378,13 @@ void CalDAVSource::backupData(const SyncSource::Operations::ConstBackupInfo &old // filter expected by Yahoo! Calendar "\n" "\n" - "\n" + "\n"; + + std::string startDateFilter = getStartDate(); + if (!startDateFilter.empty()) + query += "\n"; + + query += "\n" "\n" "\n" diff --git a/src/syncevo/SyncConfig.cpp b/src/syncevo/SyncConfig.cpp index e63a9d7..146f6f6 100644 --- a/src/syncevo/SyncConfig.cpp +++ b/src/syncevo/SyncConfig.cpp @@ -2847,6 +2847,12 @@ static ConfigProperty sourcePropDatabaseID(Aliases("database") + "evolutionsourc "data datastore is marked with at the end\n" "of the line, if there is a default.\n"); +static ConfigProperty sourcePropCalendarSyncInterval(Aliases("syncInterval"), + "Defines the number of days before the current date that should be use as start date for the calendar sync.\n" + "This can be set do limit the number of events imported from the source calendar.\n" + "\n" + "Leave it empty if you want to import all events.\n"); + static StringConfigProperty sourcePropDatabaseFormat("databaseFormat", "Defines the data format to be used by the backend for its\n" "own storage. Typically backends only support one format\n" @@ -2941,6 +2947,7 @@ public: registry.push_back(&sourcePropSyncFormat); registry.push_back(&sourcePropForceSyncFormat); registry.push_back(&sourcePropDatabaseID); + registry.push_back(&sourcePropCalendarSyncInterval); registry.push_back(&sourcePropDatabaseFormat); registry.push_back(&sourcePropUser); registry.push_back(&sourcePropPassword); @@ -2966,6 +2973,7 @@ public: // peer independent source properties sourcePropBackend.setSharing(ConfigProperty::SOURCE_SET_SHARING); sourcePropDatabaseID.setSharing(ConfigProperty::SOURCE_SET_SHARING); + sourcePropCalendarSyncInterval.setSharing(ConfigProperty::SOURCE_SET_SHARING); sourcePropDatabaseFormat.setSharing(ConfigProperty::SOURCE_SET_SHARING); sourcePropUser.setSharing(ConfigProperty::SOURCE_SET_SHARING); sourcePropPassword.setSharing(ConfigProperty::SOURCE_SET_SHARING); @@ -3036,12 +3044,33 @@ SyncSourceNodes::getNode(const ConfigProperty &prop) const InitStateString SyncSourceConfig::getDatabaseID() const { return sourcePropDatabaseID.getProperty(*getNode(sourcePropDatabaseID)); } void SyncSourceConfig::setDatabaseID(const string &value, bool temporarily) { sourcePropDatabaseID.setProperty(*getNode(sourcePropDatabaseID), value, temporarily); } +InitStateString SyncSourceConfig::getSyncInterval() const { return sourcePropCalendarSyncInterval.getProperty(*getNode(sourcePropCalendarSyncInterval)); } +void SyncSourceConfig::setSyncInterval(const string &value, bool temporarily) { + sourcePropCalendarSyncInterval.setProperty(*getNode(sourcePropCalendarSyncInterval), value, temporarily); +} + +string SyncSourceConfig::getStartDate() const +{ + InitStateString intevalInDays = getSyncInterval(); + if (intevalInDays.empty()) { + return std::string(""); + } + + // 86400 number of secs in a day + int secs = atoi(intevalInDays.c_str()) * 86400; + struct tm tm; + time_t fullTime = time(0); + fullTime -= secs; + gmtime_r(&fullTime, &tm); + + return StringPrintf("%d%02d%02dT000000Z", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); +} + UserIdentity SyncSourceConfig::getUser() const { InitStateString user = sourcePropUser.getProperty(*getNode(sourcePropUser)); UserIdentity id(UserIdentity::fromString(user)); return id; } - void SyncSourceConfig::setUsername(const string &value, bool temporarily) { sourcePropUser.setProperty(*getNode(sourcePropUser), value, temporarily); } InitStateString SyncSourceConfig::getPassword() const { return sourcePropPassword.getProperty(*getNode(sourcePropPassword)); diff --git a/src/syncevo/SyncConfig.h b/src/syncevo/SyncConfig.h index c692362..d5a7f31 100644 --- a/src/syncevo/SyncConfig.h +++ b/src/syncevo/SyncConfig.h @@ -1920,6 +1920,11 @@ class SyncSourceConfig { virtual InitStateString getDatabaseID() const; virtual void setDatabaseID(const std::string &value, bool temporarily = false); + /** selects the start date for calendar sync */ + std::string getStartDate() const; + virtual InitStateString getSyncInterval() const; + virtual void setSyncInterval(const std::string &value, bool temporarily = false); + /** * internal property: unique integer ID for the source, needed by Synthesis XML , * zero if unset -- 2.1.0