diff --git a/src/backends/webdav/CalDAVSource.cpp b/src/backends/webdav/CalDAVSource.cpp index fa16935..14f84d1 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" @@ -1141,6 +1157,7 @@ CalDAVSource::Event &CalDAVSource::loadItem(Event &event) "\n" "\n", event.m_UID.c_str()); + Timespec deadline = createDeadline(); getSession()->startOperation("REPORT 'single item'", deadline); while (true) { @@ -1351,7 +1368,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 +1379,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..7e7e7b4 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, 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