From 3ce3c805e0db96ef61790ea6e74b6bde28f8c9e2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 26 Feb 2014 10:09:35 -0600 Subject: don't log E_CLIENT_ERROR_NOT_SUPPORTED errors returned by e_cal_client_get_attachment_uris() -- we can silently interpret that as 'no attachments' --- src/planner-eds.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/planner-eds.cpp b/src/planner-eds.cpp index da406eb..241e97f 100644 --- a/src/planner-eds.cpp +++ b/src/planner-eds.cpp @@ -516,8 +516,11 @@ private: 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)) + 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); } -- cgit v1.2.3 From d857a4d1cbc7c0853a88064536957dd0d225418f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 26 Feb 2014 10:48:21 -0600 Subject: in DateTime::format(), don't assign NULL to a std::string --- src/date-time.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/date-time.cpp b/src/date-time.cpp index e6d99cd..432d877 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -85,9 +85,15 @@ GDateTime* DateTime::get() const std::string DateTime::format(const std::string& fmt) const { - const auto str = g_date_time_format(get(), fmt.c_str()); - std::string ret = str; - g_free(str); + std::string ret; + + gchar* str = g_date_time_format(get(), fmt.c_str()); + if (str) + { + ret = str; + g_free(str); + } + return ret; } -- cgit v1.2.3 From 69ed3bfcd45fc26e1fce01cba731494dc31554f2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 26 Feb 2014 11:34:20 -0600 Subject: in EdsPlanner's get_appointments(), sort 'em before returning them to the caller. --- src/planner-eds.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/planner-eds.cpp b/src/planner-eds.cpp index da406eb..4f12ec1 100644 --- a/src/planner-eds.cpp +++ b/src/planner-eds.cpp @@ -26,6 +26,7 @@ #include #include +#include // std::sort() #include #include @@ -407,11 +408,17 @@ private: *** walk through the sources to build the appointment list **/ - std::shared_ptr main_task(new Task(this, func), [](Task* task){ + auto task_deleter = [](Task* task){ + // give the caller the (sorted) finished product + auto& a = task->appointments; + std::sort(a.begin(), a.end(), [](const Appointment& a, const Appointment& b){return a.begin < b.begin;}); + task->func(a); + // we're done; delete the task g_debug("time to delete task %p", (void*)task); - task->func(task->appointments); delete task; - }); + }; + + std::shared_ptr main_task(new Task(this, func), task_deleter); for (auto& kv : m_clients) { -- cgit v1.2.3 From 115955981f63e477b5a82c07038a1fae55b423d0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 26 Feb 2014 14:45:46 -0600 Subject: tie the stop-the-ringtone action to the notification being closed, so that it stops no matter which button was pressed. --- src/snap.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index f2d075a..655fc70 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -157,18 +157,21 @@ struct SnapData void on_snap_show(NotifyNotification*, gchar* /*action*/, gpointer gdata) { - stop_alarm_sound(); auto data = static_cast(gdata); data->show(data->appointment); } void on_snap_dismiss(NotifyNotification*, gchar* /*action*/, gpointer gdata) { - stop_alarm_sound(); auto data = static_cast(gdata); data->dismiss(data->appointment); } +void on_snap_closed(NotifyNotification*, gpointer) +{ + stop_alarm_sound(); +} + void snap_data_destroy_notify(gpointer gdata) { delete static_cast(gdata); @@ -188,6 +191,7 @@ void show_snap_decision(SnapData* data) notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true"); notify_notification_add_action(nn, "show", _("Show"), on_snap_show, data, nullptr); notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_dismiss, data, nullptr); + g_signal_connect(G_OBJECT(nn), "closed", G_CALLBACK(on_snap_closed), data); g_object_set_data_full(G_OBJECT(nn), "snap-data", data, snap_data_destroy_notify); GError * error = nullptr; -- cgit v1.2.3 From a0d9eadc2ad022dc00af7fb7fb1f055cef79108c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 26 Feb 2014 16:03:57 -0600 Subject: when notifying of alarms on the desktop, use bubble notifications instead of a confirmation dialog + audio feedback. --- src/snap.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 655fc70..dcad68a 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -177,7 +177,44 @@ void snap_data_destroy_notify(gpointer gdata) delete static_cast(gdata); } -void show_snap_decision(SnapData* data) +bool server_is_notify_osd(void) +{ + static bool tested = false; + static bool is_notify_osd = false; + + if (G_UNLIKELY(!tested)) + { + gchar* name=nullptr; + notify_get_server_info(&name, nullptr, nullptr, nullptr); + is_notify_osd = !g_strcmp0(name, "notify-osd"); + g_free(name); + + tested = true; + } + + return is_notify_osd; +} + +typedef enum +{ + // just a bubble... no actions, no audio + NOTIFY_MODE_BUBBLE, + + // a snap decision popup dialog + audio + NOTIFY_MODE_SNAP +} +NotifyMode; + +NotifyMode get_notify_mode() +{ + // no real point in showing snap decisions on the desktop... + if (server_is_notify_osd()) + return NOTIFY_MODE_BUBBLE; + + return NOTIFY_MODE_SNAP; +} + +void show_notification (SnapData* data, NotifyMode mode) { const Appointment& appointment = data->appointment; @@ -187,11 +224,14 @@ void show_snap_decision(SnapData* data) const gchar* icon_name = "alarm-clock"; auto nn = notify_notification_new(title, body.c_str(), icon_name); - notify_notification_set_hint_string(nn, "x-canonical-snap-decisions", "true"); - notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true"); - notify_notification_add_action(nn, "show", _("Show"), on_snap_show, data, nullptr); - notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_dismiss, data, nullptr); - g_signal_connect(G_OBJECT(nn), "closed", G_CALLBACK(on_snap_closed), data); + if (mode == NOTIFY_MODE_SNAP) + { + notify_notification_set_hint_string(nn, "x-canonical-snap-decisions", "true"); + notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true"); + notify_notification_add_action(nn, "show", _("Show"), on_snap_show, data, nullptr); + notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_dismiss, data, nullptr); + g_signal_connect(G_OBJECT(nn), "closed", G_CALLBACK(on_snap_closed), data); + } g_object_set_data_full(G_OBJECT(nn), "snap-data", data, snap_data_destroy_notify); GError * error = nullptr; @@ -219,8 +259,17 @@ void notify(const Appointment& appointment, data->show = show; data->dismiss = dismiss; - play_alarm_sound(); - show_snap_decision(data); + switch (get_notify_mode()) + { + case NOTIFY_MODE_BUBBLE: + show_notification(data, NOTIFY_MODE_BUBBLE); + break; + + default: + show_notification(data, NOTIFY_MODE_SNAP); + play_alarm_sound(); + break; + } } } // unnamed namespace -- cgit v1.2.3 From e365214c51f8673feb293c8175c87c92672666b9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 27 Feb 2014 11:13:08 -0500 Subject: when deciding whether to do a bubble or snap notification, see if the server supports actions. --- src/snap.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index dcad68a..b1a2e51 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include + #define ALARM_SOUND_FILENAME "/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg" namespace unity { @@ -177,22 +180,14 @@ void snap_data_destroy_notify(gpointer gdata) delete static_cast(gdata); } -bool server_is_notify_osd(void) +std::set get_server_caps() { - static bool tested = false; - static bool is_notify_osd = false; - - if (G_UNLIKELY(!tested)) - { - gchar* name=nullptr; - notify_get_server_info(&name, nullptr, nullptr, nullptr); - is_notify_osd = !g_strcmp0(name, "notify-osd"); - g_free(name); - - tested = true; - } - - return is_notify_osd; + std::set caps_set; + auto caps_gl = notify_get_server_caps(); + for(auto l=caps_gl; l!=nullptr; l=l->next) + caps_set.insert((const char*)l->data); + g_list_free_full(caps_gl, g_free); + return caps_set; } typedef enum @@ -207,11 +202,22 @@ NotifyMode; NotifyMode get_notify_mode() { - // no real point in showing snap decisions on the desktop... - if (server_is_notify_osd()) - return NOTIFY_MODE_BUBBLE; + static NotifyMode mode; + static bool mode_inited = false; + + if (G_UNLIKELY(!mode_inited)) + { + const auto caps = get_server_caps(); + + if (caps.count("actions")) + mode = NOTIFY_MODE_SNAP; + else + mode = NOTIFY_MODE_BUBBLE; + + mode_inited = true; + } - return NOTIFY_MODE_SNAP; + return mode; } void show_notification (SnapData* data, NotifyMode mode) -- cgit v1.2.3 From 00fcc7da2f9aa1ed98794bf4f3487237cc1c3a47 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 27 Feb 2014 11:14:52 -0500 Subject: when a notify action is activated, call stop_audio_loop() in case the notify server doesn't also send back a 'closed' signal. --- src/snap.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index b1a2e51..5cf6063 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -160,12 +160,14 @@ struct SnapData void on_snap_show(NotifyNotification*, gchar* /*action*/, gpointer gdata) { + stop_alarm_sound(); auto data = static_cast(gdata); data->show(data->appointment); } void on_snap_dismiss(NotifyNotification*, gchar* /*action*/, gpointer gdata) { + stop_alarm_sound(); auto data = static_cast(gdata); data->dismiss(data->appointment); } -- cgit v1.2.3