aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-12-08 23:09:08 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2014-12-08 23:09:08 +0000
commitb05f411503474231de48ee038d16e2d0e49bed4f (patch)
tree160077bd77534638e0c5431670d1c6dc97b98dd2 /src
parent6de98acd45d855789fdd4bfdf45fa826eef22828 (diff)
parentf84d3bdb7006eee351942a31d033ca0d62f3292a (diff)
downloadayatana-indicator-datetime-b05f411503474231de48ee038d16e2d0e49bed4f.tar.gz
ayatana-indicator-datetime-b05f411503474231de48ee038d16e2d0e49bed4f.tar.bz2
ayatana-indicator-datetime-b05f411503474231de48ee038d16e2d0e49bed4f.zip
After a one-time Ubuntu alarm's notification is displayed, disable the alarm. Fixes: #1362341
Approved by: Ted Gould, PS Jenkins bot
Diffstat (limited to 'src')
-rw-r--r--src/engine-eds.cpp82
-rw-r--r--src/main.cpp5
2 files changed, 86 insertions, 1 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);
+}
+
/***
****
***/
diff --git a/src/main.cpp b/src/main.cpp
index aa8f829..1761f84 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -139,7 +139,10 @@ main(int /*argc*/, char** /*argv*/)
auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_);
auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);};
auto on_ok = [](const Appointment&){};
- auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);};
+ auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& a) {
+ (*snap)(a, on_snooze, on_ok);
+ engine->disable_ubuntu_alarm(a);
+ };
alarm_queue->alarm_reached().connect(on_alarm_reached);
// create the menus