From 2241aff419d1ccacc5c4807caf342dc1c86ceae4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 11 Apr 2014 14:41:18 -0500 Subject: if we have a flood of EDS events coming in, wait a longer interval before requerying the EDS engine --- src/engine-eds.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index c557857..c20731d 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -25,6 +25,7 @@ #include #include // std::sort() +#include // time() #include #include @@ -144,16 +145,29 @@ private: { auto self = static_cast(gself); self->m_rebuild_tag = 0; + self->m_rebuild_deadline = 0; self->set_dirty_now(); return G_SOURCE_REMOVE; } void set_dirty_soon() { - static const int ARBITRARY_BATCH_MSEC = 200; + static constexpr int MIN_BATCH_SEC = 1; + static constexpr int MAX_BATCH_SEC = 60; + static_assert(MIN_BATCH_SEC <= MAX_BATCH_SEC, "bad boundaries"); - if (m_rebuild_tag == 0) - m_rebuild_tag = g_timeout_add(ARBITRARY_BATCH_MSEC, set_dirty_now_static, this); + const auto now = time(nullptr); + + if (m_rebuild_deadline == 0) // first pass + { + m_rebuild_deadline = now + MAX_BATCH_SEC; + m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this); + } + else if (now < m_rebuild_deadline) + { + g_source_remove (m_rebuild_tag); + m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this); + } } static void on_source_registry_ready(GObject* /*source*/, GAsyncResult* res, gpointer gself) @@ -496,6 +510,7 @@ private: GCancellable* m_cancellable = nullptr; ESourceRegistry* m_source_registry = nullptr; guint m_rebuild_tag = 0; + time_t m_rebuild_deadline = 0; }; /*** -- cgit v1.2.3 From 0b6ccb4966df230661ee6802bdcae0e884b61b6a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 11 Apr 2014 15:28:16 -0500 Subject: remove some extraneous EDS events on startup --- src/engine-eds.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index c20731d..5e2484e 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -286,6 +286,7 @@ private: if (e_cal_client_get_view_finish (E_CAL_CLIENT(client), res, &view, &error)) { // add the view to our collection + e_cal_client_view_set_flags(view, E_CAL_CLIENT_VIEW_FLAGS_NONE, NULL); e_cal_client_view_start(view, &error); g_debug("got a view for %s", e_cal_client_get_local_attachment_store(E_CAL_CLIENT(client))); auto self = static_cast(gself); -- cgit v1.2.3 From 0a097229d2ae182f30f657738b41f6bddc6a2c8c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Apr 2014 09:50:07 -0500 Subject: remove unused field Appointment.is_event --- include/datetime/appointment.h | 1 - src/appointment.cpp | 1 - src/engine-eds.cpp | 1 - tests/manual-test-snap.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index a5283c9..441aae1 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -39,7 +39,6 @@ public: std::string summary; std::string url; std::string uid; - bool is_event = false; bool is_daily = false; bool has_alarms = false; DateTime begin; diff --git a/src/appointment.cpp b/src/appointment.cpp index 6e742c3..98cc062 100644 --- a/src/appointment.cpp +++ b/src/appointment.cpp @@ -33,7 +33,6 @@ bool Appointment::operator==(const Appointment& that) const && (summary==that.summary) && (url==that.url) && (uid==that.uid) - && (is_event==that.is_event) && (has_alarms==that.has_alarms) && (begin==that.begin) && (end==that.end); diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 5e2484e..4b5a1b9 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -455,7 +455,6 @@ private: appointment.begin = DateTime(begin); appointment.end = DateTime(end); appointment.color = subtask->color; - appointment.is_event = vtype == E_CAL_COMPONENT_EVENT; appointment.uid = uid; GList * alarm_uids = e_cal_component_get_alarm_uids(component); diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 51556cd..23d607f 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -36,7 +36,6 @@ int main() a.summary = "Alarm"; a.url = "alarm:///hello-world"; a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; - a.is_event = false; a.is_daily = false; a.has_alarms = true; auto begin = g_date_time_new_local(2014,12,25,0,0,0); -- cgit v1.2.3 From 61be4cf3e7aa796dd61ea8295ef6c6dbbe600a4a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Apr 2014 10:40:31 -0500 Subject: remove unused field Appointment.is_daily --- include/datetime/appointment.h | 1 - src/engine-eds.cpp | 14 -------------- tests/manual-test-snap.cpp | 1 - 3 files changed, 16 deletions(-) diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 441aae1..4778293 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -39,7 +39,6 @@ public: std::string summary; std::string url; std::string uid; - bool is_daily = false; bool has_alarms = false; DateTime begin; DateTime end; diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 4b5a1b9..5b67001 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -432,20 +432,6 @@ private: { Appointment appointment; - /* Determine whether this is a recurring event. - NB: icalrecurrencetype supports complex recurrence patterns; - however, since design only allows daily recurrence, - that's all we support here. */ - GSList * recur_list; - e_cal_component_get_rrule_list(component, &recur_list); - for (auto l=recur_list; l!=nullptr; l=l->next) - { - const auto recur = static_cast(l->data); - appointment.is_daily |= ((recur->freq == ICAL_DAILY_RECURRENCE) - && (recur->interval == 1)); - } - e_cal_component_free_recur_list(recur_list); - ECalComponentText text; text.value = nullptr; e_cal_component_get_summary(component, &text); diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 23d607f..16e606a 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -36,7 +36,6 @@ int main() a.summary = "Alarm"; a.url = "alarm:///hello-world"; a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; - a.is_daily = false; a.has_alarms = true; auto begin = g_date_time_new_local(2014,12,25,0,0,0); auto end = g_date_time_add_full(begin,0,0,1,0,0,-1); -- cgit v1.2.3 From dd8adf4fd9ad60b0fc615a4cea7e57602b5afddf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Apr 2014 11:01:56 -0500 Subject: sync with lp:~renatofilho/qtorganizer5-eds/fix-1284375's method of storing alarm urls. Happily this supercedes our code that used to call e_cal_client_get_attachment_uris(), so this means fewer round trip calls to EDS --- src/engine-eds.cpp | 82 ++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 5b67001..8a105a6 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -401,14 +401,6 @@ private: } }; - struct UrlSubtask - { - std::shared_ptr task; - Appointment appointment; - UrlSubtask(const std::shared_ptr& task_in, const Appointment& appointment_in): - task(task_in), appointment(appointment_in) {} - }; - static gboolean my_get_appointments_foreach(ECalComponent* component, time_t begin, @@ -443,51 +435,45 @@ private: appointment.color = subtask->color; appointment.uid = uid; - GList * alarm_uids = e_cal_component_get_alarm_uids(component); + // if the component has display alarms that have a url, + // snag it for our Appointment.url + auto alarm_uids = e_cal_component_get_alarm_uids(component); appointment.has_alarms = alarm_uids != nullptr; + for(auto walk=alarm_uids; appointment.url.empty() && walk!=nullptr; walk=walk->next) + { + auto alarm = e_cal_component_get_alarm(component, static_cast(walk->data)); + + ECalComponentAlarmAction action; + e_cal_component_alarm_get_action(alarm, &action); + if (action == E_CAL_COMPONENT_ALARM_DISPLAY) + { + icalattach* attach = nullptr; + e_cal_component_alarm_get_attach(alarm, &attach); + if (attach != nullptr) + { + if (icalattach_get_is_url (attach)) + { + const char* url = icalattach_get_url(attach); + if (url != nullptr) + appointment.url = url; + } + + icalattach_unref(attach); + } + } + + e_cal_component_alarm_free(alarm); + } cal_obj_uid_list_free(alarm_uids); - e_cal_client_get_attachment_uris(subtask->client, - uid, - nullptr, - subtask->task->p->m_cancellable, - on_appointment_uris_ready, - new UrlSubtask(subtask->task, appointment)); - } - } - + g_debug("adding appointment '%s' '%s'", appointment.summary.c_str(), appointment.url.c_str()); + subtask->task->appointments.push_back(appointment); + } + } + return G_SOURCE_CONTINUE; } - - static void on_appointment_uris_ready(GObject* client, GAsyncResult* res, gpointer gsubtask) - { - auto subtask = static_cast(gsubtask); - - GSList * uris = nullptr; - GError * error = nullptr; - e_cal_client_get_attachment_uris_finish(E_CAL_CLIENT(client), res, &uris, &error); - if (error != nullptr) - { - if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && - !g_error_matches(error, E_CLIENT_ERROR, E_CLIENT_ERROR_NOT_SUPPORTED)) - { - g_warning("Error getting appointment uris: %s", error->message); - } - - g_error_free(error); - } - else if (uris != nullptr) - { - subtask->appointment.url = (const char*) uris->data; // copy the first URL - g_debug("found url '%s' for appointment '%s'", subtask->appointment.url.c_str(), subtask->appointment.summary.c_str()); - e_client_util_free_string_slist(uris); - } - - g_debug("adding appointment '%s' '%s'", subtask->appointment.summary.c_str(), subtask->appointment.url.c_str()); - subtask->task->appointments.push_back(subtask->appointment); - delete subtask; - } - + EdsEngine& m_owner; core::Signal<> m_changed; std::set m_sources; -- cgit v1.2.3 From 61af48e621e774b774f9c7f61e8a972ab8201f15 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Apr 2014 11:11:34 -0500 Subject: copyediting: fix indentation/formatting --- src/engine-eds.cpp | 116 ++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 8a105a6..da93206 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -412,64 +412,64 @@ private: if ((vtype == E_CAL_COMPONENT_EVENT) || (vtype == E_CAL_COMPONENT_TODO)) { - const gchar* uid = nullptr; - e_cal_component_get_uid(component, &uid); - - auto status = ICAL_STATUS_NONE; - e_cal_component_get_status(component, &status); - - if ((uid != nullptr) && - (status != ICAL_STATUS_COMPLETED) && - (status != ICAL_STATUS_CANCELLED)) - { - Appointment appointment; - - ECalComponentText text; - text.value = nullptr; - e_cal_component_get_summary(component, &text); - if (text.value) - appointment.summary = text.value; - - appointment.begin = DateTime(begin); - appointment.end = DateTime(end); - appointment.color = subtask->color; - appointment.uid = uid; - - // if the component has display alarms that have a url, - // snag it for our Appointment.url - auto alarm_uids = e_cal_component_get_alarm_uids(component); - appointment.has_alarms = alarm_uids != nullptr; - for(auto walk=alarm_uids; appointment.url.empty() && walk!=nullptr; walk=walk->next) - { - auto alarm = e_cal_component_get_alarm(component, static_cast(walk->data)); - - ECalComponentAlarmAction action; - e_cal_component_alarm_get_action(alarm, &action); - if (action == E_CAL_COMPONENT_ALARM_DISPLAY) - { - icalattach* attach = nullptr; - e_cal_component_alarm_get_attach(alarm, &attach); - if (attach != nullptr) - { - if (icalattach_get_is_url (attach)) - { - const char* url = icalattach_get_url(attach); - if (url != nullptr) - appointment.url = url; - } - - icalattach_unref(attach); - } - } - - e_cal_component_alarm_free(alarm); - } - cal_obj_uid_list_free(alarm_uids); - - g_debug("adding appointment '%s' '%s'", appointment.summary.c_str(), appointment.url.c_str()); - subtask->task->appointments.push_back(appointment); - } - } + const gchar* uid = nullptr; + e_cal_component_get_uid(component, &uid); + + auto status = ICAL_STATUS_NONE; + e_cal_component_get_status(component, &status); + + if ((uid != nullptr) && + (status != ICAL_STATUS_COMPLETED) && + (status != ICAL_STATUS_CANCELLED)) + { + Appointment appointment; + + ECalComponentText text; + text.value = nullptr; + e_cal_component_get_summary(component, &text); + if (text.value) + appointment.summary = text.value; + + appointment.begin = DateTime(begin); + appointment.end = DateTime(end); + appointment.color = subtask->color; + appointment.uid = uid; + + // if the component has display alarms that have a url, + // use the first one as our Appointment.url + auto alarm_uids = e_cal_component_get_alarm_uids(component); + appointment.has_alarms = alarm_uids != nullptr; + for(auto walk=alarm_uids; appointment.url.empty() && walk!=nullptr; walk=walk->next) + { + auto alarm = e_cal_component_get_alarm(component, static_cast(walk->data)); + + ECalComponentAlarmAction action; + e_cal_component_alarm_get_action(alarm, &action); + if (action == E_CAL_COMPONENT_ALARM_DISPLAY) + { + icalattach* attach = nullptr; + e_cal_component_alarm_get_attach(alarm, &attach); + if (attach != nullptr) + { + if (icalattach_get_is_url (attach)) + { + const char* url = icalattach_get_url(attach); + if (url != nullptr) + appointment.url = url; + } + + icalattach_unref(attach); + } + } + + e_cal_component_alarm_free(alarm); + } + cal_obj_uid_list_free(alarm_uids); + + g_debug("adding appointment '%s' '%s'", appointment.summary.c_str(), appointment.url.c_str()); + subtask->task->appointments.push_back(appointment); + } + } return G_SOURCE_CONTINUE; } -- cgit v1.2.3