aboutsummaryrefslogtreecommitdiff
path: root/src/engine-eds.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine-eds.cpp')
-rw-r--r--src/engine-eds.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp
index 23e2883..210ef42 100644
--- a/src/engine-eds.cpp
+++ b/src/engine-eds.cpp
@@ -136,6 +136,22 @@ public:
}
}
+ void disable_ubuntu_alarm(const Appointment& appointment)
+ {
+ if (appointment.is_ubuntu_alarm())
+ {
+ for (auto& kv : m_clients) // find the matching icalcomponent
+ {
+ e_cal_client_get_object(kv.second,
+ appointment.uid.c_str(),
+ nullptr,
+ m_cancellable,
+ on_object_ready_for_disable,
+ this);
+ }
+ }
+ }
+
private:
void set_dirty_now()
@@ -506,6 +522,67 @@ private:
return G_SOURCE_CONTINUE;
}
+
+ /***
+ ****
+ ***/
+
+ static void on_object_ready_for_disable(GObject * client,
+ GAsyncResult * result,
+ gpointer gself)
+ {
+ icalcomponent * icc = nullptr;
+ if (e_cal_client_get_object_finish (E_CAL_CLIENT(client), result, &icc, nullptr))
+ {
+ struct icaltimetype itt = icalcomponent_get_recurrenceid(icc);
+ if (icaltime_is_null_time(itt))
+ {
+ g_debug("'%s' appears to be a one-time alarm... adding 'disabled' tag.",
+ icalcomponent_as_ical_string(icc));
+
+ auto ecc = e_cal_component_new_from_icalcomponent (icc); // takes ownership of icc
+ icc = nullptr;
+
+ if (ecc != nullptr)
+ {
+ // add TAG_DISABLED to the list of categories
+ GSList * old_categories = nullptr;
+ e_cal_component_get_categories_list(ecc, &old_categories);
+ auto new_categories = g_slist_copy(old_categories);
+ new_categories = g_slist_append(new_categories, const_cast<char*>(TAG_DISABLED));
+ e_cal_component_set_categories_list(ecc, new_categories);
+ g_slist_free(new_categories);
+ e_cal_component_free_categories_list(old_categories);
+ e_cal_client_modify_object(E_CAL_CLIENT(client),
+ e_cal_component_get_icalcomponent(ecc),
+ E_CAL_OBJ_MOD_THIS,
+ static_cast<Impl*>(gself)->m_cancellable,
+ on_disable_done,
+ nullptr);
+
+ g_clear_object(&ecc);
+ }
+ }
+
+ g_clear_pointer(&icc, icalcomponent_free);
+ }
+ }
+
+ static void on_disable_done (GObject* gclient, GAsyncResult *res, gpointer)
+ {
+ GError * error = nullptr;
+ if (!e_cal_client_modify_object_finish (E_CAL_CLIENT(gclient), res, &error))
+ {
+ if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning("indicator-datetime cannot mark one-time alarm as disabled: %s", error->message);
+
+ g_error_free(error);
+ }
+ }
+
+ /***
+ ****
+ ***/
core::Signal<> m_changed;
std::set<ESource*> m_sources;
@@ -541,6 +618,11 @@ void EdsEngine::get_appointments(const DateTime& begin,
p->get_appointments(begin, end, tz, func);
}
+void EdsEngine::disable_ubuntu_alarm(const Appointment& appointment)
+{
+ p->disable_ubuntu_alarm(appointment);
+}
+
/***
****
***/