From b4ff1a2458802e3238d952c69f9dd664f013137b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 18:05:45 -0600 Subject: don't show calendar event notifications if com.ubuntu.calendar's notifications are blacklisted --- src/snap.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index f0300af..934ad19 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -84,6 +84,12 @@ public: appointment_func snooze, appointment_func ok) { + // If calendar notifications are muted, don't show them + if (!appointment.is_ubuntu_alarm() && calendar_events_are_muted()) { + g_debug("Skipping muted calendar event '%s' notification", appointment.summary.c_str()); + return; + } + /* Alarms and calendar events are treated differently. Alarms should require manual intervention to dismiss. Calendar events are less urgent and shouldn't require manual @@ -159,6 +165,17 @@ public: private: + bool calendar_events_are_muted() const + { + for(const auto& app : m_settings->muted_apps.get()) { + if (app.first == "com.ubuntu.calendar") { + return true; + } + } + + return false; + } + static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) { GError * error; -- cgit v1.2.3 From 0b4ad877e1a5b083eda5c31227e476d969d00925 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 18:07:18 -0600 Subject: in LiveSettings, add gschema support for notification app blacklisting --- src/settings-live.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 5c2addb..e63bcbe 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -19,6 +19,11 @@ #include +extern "C" +{ + #include +} + namespace ayatana { namespace indicator { namespace datetime { @@ -29,13 +34,19 @@ namespace datetime { LiveSettings::~LiveSettings() { + g_clear_object(&m_settings_cunh); g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): - m_settings(g_settings_new(SETTINGS_INTERFACE)) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) { - g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed), this); + g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); + + if (ayatana_common_utils_is_lomiri()) + { + m_settings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); + g_signal_connect (m_settings_cunh, "changed", G_CALLBACK(on_changed_cunh), this); + } // init the Properties from the GSettings backend update_custom_time_format(); @@ -57,6 +68,7 @@ LiveSettings::LiveSettings(): update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); + update_muted_apps(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -64,6 +76,20 @@ LiveSettings::LiveSettings(): g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str()); }); + if (ayatana_common_utils_is_lomiri()) + { + muted_apps.changed().connect([this](const std::set>& value){ + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); + for(const auto& app : value){ + const auto& pkgname {app.first}; + const auto& appname {app.second}; + g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str()); + } + g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder)); + }); + } + locations.changed().connect([this](const std::vector& value){ const int n = value.size(); gchar** strv = g_new0(gchar*, n+1); @@ -163,6 +189,27 @@ void LiveSettings::update_locations() locations.set(l); } +void LiveSettings::update_muted_apps() +{ + if (ayatana_common_utils_is_lomiri()) + { + std::set> apps; + + auto blacklist = g_settings_get_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S); + GVariantIter* iter {nullptr}; + g_variant_get (blacklist, "a(ss)", &iter); + gchar* pkgname; + gchar* appname; + while (g_variant_iter_loop (iter, "(ss)", &pkgname, &appname)) { + apps.insert(std::make_pair(pkgname,appname)); + } + g_variant_iter_free (iter); + g_clear_pointer(&blacklist, g_variant_unref); + + muted_apps.set(apps); + } +} + void LiveSettings::update_show_calendar() { const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S); @@ -265,14 +312,31 @@ void LiveSettings::update_snooze_duration() **** ***/ -void LiveSettings::on_changed(GSettings* /*settings*/, - gchar* key, - gpointer gself) +void LiveSettings::on_changed_cunh(GSettings* /*settings*/, + gchar* key, + gpointer gself) +{ + static_cast(gself)->update_key_cunh(key); +} + +void LiveSettings::update_key_cunh(const std::string& key) +{ + if (key == SETTINGS_CUNH_BLACKLIST_S) + update_muted_apps(); +} + +/*** +**** +***/ + +void LiveSettings::on_changed_ccid(GSettings* /*settings*/, + gchar* key, + gpointer gself) { - static_cast(gself)->update_key(key); + static_cast(gself)->update_key_ccid(key); } -void LiveSettings::update_key(const std::string& key) +void LiveSettings::update_key_ccid(const std::string& key) { if (key == SETTINGS_LOCATIONS_S) update_locations(); -- cgit v1.2.3 From 990df2335fddc985aa789d82d184eaa83409b73b Mon Sep 17 00:00:00 2001 From: David Barth Date: Wed, 3 Feb 2016 15:47:29 +0100 Subject: adjust title and notification icon according to the event type --- src/snap.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 934ad19..9c2b4b6 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -122,7 +122,7 @@ public: const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); ain::Builder b; b.set_body (appointment.summary); - b.set_icon_name ("alarm-clock"); + b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "reminder"); b.add_hint (ain::Builder::HINT_NONSHAPED_ICON); const char * timefmt; @@ -136,7 +136,14 @@ public: timefmt = _("%a, %H:%M"); } const auto timestr = appointment.begin.format(timefmt); - auto title = g_strdup_printf(_("Alarm %s"), timestr.c_str()); + + const char * titlefmt; + if (appointment.is_ubuntu_alarm()) { + titlefmt = _("Alarm %s"); + } else { + titlefmt = _("Event %s"); + } + auto title = g_strdup_printf(titlefmt, timestr.c_str()); b.set_title (title); g_free (title); b.set_timeout (std::chrono::duration_cast(minutes)); -- cgit v1.2.3 From b6f3a8d8e4db3f786ec35322dff0724cfc74a2f4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 3 Feb 2016 14:25:19 -0600 Subject: in settings-live.cpp, use std::string instead of auto to make g++ 4.9.2 happy on vivid --- src/settings-live.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index e63bcbe..6504d7d 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -82,8 +82,8 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); for(const auto& app : value){ - const auto& pkgname {app.first}; - const auto& appname {app.second}; + const std::string& pkgname {app.first}; + const std::string& appname {app.second}; g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str()); } g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder)); -- cgit v1.2.3 From 8b3ff84240470f403a93b577a6cec1a10311512d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 16 Mar 2016 11:42:06 -0300 Subject: calls 'calendar://eventId=' when clicking on an event in the indicator. --- src/actions-live.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 271d2f3..6ac1878 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -25,6 +25,8 @@ #include +#include + namespace ayatana { namespace indicator { namespace datetime { @@ -159,15 +161,27 @@ void LiveActions::phone_open_appointment(const Appointment& appt) phone_open_alarm_app(); break; + case Appointment::EVENT: + if (!appt.source_uid.empty() && !appt.uid.empty()) + { + std::stringstream cmd; + // event-id format: / + cmd << "calendar://eventid=" + << appt.source_uid + << "/" + << appt.uid; + dispatch_url(cmd.str()); + break; + } default: phone_open_calendar_app(appt.begin); } } -void LiveActions::phone_open_calendar_app(const DateTime&) +void LiveActions::phone_open_calendar_app(const DateTime& dt) { - // does calendar app have a mechanism for specifying dates? - dispatch_url("appid://com.ubuntu.calendar/calendar/current-user-version"); + auto cmd = dt.format("calendar:///?startdate=%Y%m%dT%H%M%SZ"); + dispatch_url(cmd); } void LiveActions::phone_open_settings_app() -- cgit v1.2.3 From e47d49aca4da2d97c06acccc967abdf5698b044d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 18 Mar 2016 10:17:55 -0500 Subject: get event selection up-to-date with the spec, including showing in-progress events. add unit tests to cover event priority and display order. --- src/date-time.cpp | 10 +++++ src/menu.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/date-time.cpp b/src/date-time.cpp index 169426c..911fb7a 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -245,11 +245,21 @@ bool DateTime::operator<(const DateTime& that) const return g_date_time_compare(get(), that.get()) < 0; } +bool DateTime::operator>(const DateTime& that) const +{ + return g_date_time_compare(get(), that.get()) > 0; +} + bool DateTime::operator<=(const DateTime& that) const { return g_date_time_compare(get(), that.get()) <= 0; } +bool DateTime::operator>=(const DateTime& that) const +{ + return g_date_time_compare(get(), that.get()) >= 0; +} + bool DateTime::operator!=(const DateTime& that) const { // return true if this isn't set, or if it's not equal diff --git a/src/menu.cpp b/src/menu.cpp index d19ad73..0cd3f9b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include extern "C" @@ -58,11 +60,90 @@ GMenuModel* Menu::menu_model() return G_MENU_MODEL(m_menu); } +/** + * To avoid a giant menu on the PC, and to avoid pushing lower menu items + * off-screen on the phone, the menu should show the + * next five calendar events, if any. + * + * The list might include multiple occurrences of the same event (bug 1515821). + */ +std::vector +Menu::get_display_appointments(const std::vector& appointments_in, + const DateTime& now, + unsigned int max_items) +{ + std::vector appointments; + std::copy_if(appointments_in.begin(), + appointments_in.end(), + std::back_inserter(appointments), + [now](const Appointment& a){return a.end >= now;}); + + if (appointments.size() > max_items) + { + const auto next_minute = now.add_full(0,0,0,0,1,-now.seconds()); + const auto start_of_day = now.start_of_day(); + const auto end_of_day = now.end_of_day(); + + /* + * If there are more than five, the events shown should be, in order of priority: + * 1. any events that start or end (bug 1329048) after the current minute today; + * 2. any full-day events that span all of today (bug 1302004); + * 3. any events that start or end tomorrow; + * 4. any events that start or end the day after tomorrow; and so on. + */ + auto compare = [next_minute, start_of_day, end_of_day]( + const Appointment& a, + const Appointment& b) + { + const bool a_later_today = (a.begin >= next_minute) || (a.end <= end_of_day); + const bool b_later_today = (b.begin >= next_minute) || (b.end <= end_of_day); + if (a_later_today != b_later_today) + return a_later_today; + + const bool a_full_day_today = (a.begin <= start_of_day) && (end_of_day <= a.end); + const bool b_full_day_today = (b.begin <= start_of_day) && (end_of_day <= b.end); + if (a_full_day_today != b_full_day_today) + return a_full_day_today; + + const bool a_after_today = (a.begin > end_of_day) || (a.end > end_of_day); + const bool b_after_today = (a.begin > end_of_day) || (a.end > end_of_day); + if (a_after_today != b_after_today) + return a_after_today; + if (a.begin != b.begin) + return a.begin < b.begin; + if (b.end != b.end) + return a.end < b.end; + + return false; + }; + std::sort(appointments.begin(), appointments.end(), compare); + appointments.resize(max_items); + } + + /* + * However, the display order should be the reverse: full-day events + * first (since they start first), part-day events afterward in + * chronological order. If multiple events have exactly the same start+end + * time, they should be sorted alphabetically. + */ + auto compare = [](const Appointment& a, const Appointment& b) + { + if (a.begin != b.begin) + return a.begin < b.begin; + + if (a.end != b.end) + return a.end < b.end; + + return a.summary < b.summary; + }; + std::sort(appointments.begin(), appointments.end(), compare); + return appointments; +} + /**** ***** ****/ - #define ALARM_ICON_NAME "alarm-clock" #define CALENDAR_ICON_NAME "calendar" @@ -150,25 +231,19 @@ protected: void update_upcoming() { - // The usual case is on desktop (and /only/ case on phone) - // is that we're looking at the current date and want to see - // "the next five calendar events, if any." - // - // However on the Desktop when the user clicks onto a different - // calendar date, show the next five calendar events starting - // from the beginning of that clicked day. - DateTime begin; + // The usual case is to show events germane to the current time. + // However when the user clicks onto a different calendar date, + // we pick events starting from the beginning of that clicked day. const auto now = m_state->clock->localtime(); const auto calendar_day = m_state->calendar_month->month().get(); - if ((profile() == Desktop) && !DateTime::is_same_day(now, calendar_day)) - begin = calendar_day.start_of_day(); - else - begin = now.start_of_minute(); - - std::vector upcoming; - for(const auto& a : m_state->calendar_upcoming->appointments().get()) - if (begin <= a.begin) - upcoming.push_back(a); + const auto begin = DateTime::is_same_day(now, calendar_day) + ? now.start_of_minute() + : calendar_day.start_of_day(); + + auto upcoming = get_display_appointments( + m_state->calendar_upcoming->appointments().get(), + begin + ); if (m_upcoming != upcoming) { -- cgit v1.2.3 From bf7746273c111b004c56a0868bb1702d96ecb67f Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 18 Mar 2016 22:20:03 -0300 Subject: Lauch calendar app using the event start time. --- src/actions-live.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 6ac1878..4fe2f39 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -162,25 +162,16 @@ void LiveActions::phone_open_appointment(const Appointment& appt) break; case Appointment::EVENT: - if (!appt.source_uid.empty() && !appt.uid.empty()) - { - std::stringstream cmd; - // event-id format: / - cmd << "calendar://eventid=" - << appt.source_uid - << "/" - << appt.uid; - dispatch_url(cmd.str()); - break; - } default: phone_open_calendar_app(appt.begin); + break; } } void LiveActions::phone_open_calendar_app(const DateTime& dt) { - auto cmd = dt.format("calendar:///?startdate=%Y%m%dT%H%M%SZ"); + const auto utc = dt.to_timezone("UTC"); + auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); dispatch_url(cmd); } -- cgit v1.2.3 From d1935f872fe600f224aa89eff3ab70a48d52c16d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 21 Mar 2016 14:32:39 -0300 Subject: Make sure that the ocurrence time is used to build the url to launch external application. --- src/actions-live.cpp | 8 ++++---- src/actions.cpp | 29 +++++++++++++++-------------- src/menu.cpp | 7 +++++-- 3 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 4fe2f39..231fb33 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -127,9 +127,9 @@ void LiveActions::desktop_open_alarm_app() execute_command("evolution -c calendar"); } -void LiveActions::desktop_open_appointment(const Appointment& appt) +void LiveActions::desktop_open_appointment(const Appointment&, const DateTime& date) { - desktop_open_calendar_app(appt.begin); + desktop_open_calendar_app(date); } void LiveActions::desktop_open_calendar_app(const DateTime& dt) @@ -148,7 +148,7 @@ void LiveActions::phone_open_alarm_app() dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); } -void LiveActions::phone_open_appointment(const Appointment& appt) +void LiveActions::phone_open_appointment(const Appointment& appt, const DateTime& date) { if (!appt.activation_url.empty()) @@ -163,7 +163,7 @@ void LiveActions::phone_open_appointment(const Appointment& appt) case Appointment::EVENT: default: - phone_open_calendar_app(appt.begin); + phone_open_calendar_app(date); break; } } diff --git a/src/actions.cpp b/src/actions.cpp index 93629a0..ea68d3e 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -48,13 +48,8 @@ DateTime datetime_from_timet_variant(GVariant* v) return DateTime::NowLocal(); } -bool lookup_appointment_by_uid_variant(const std::shared_ptr& state, GVariant* vuid, Appointment& setme) +bool lookup_appointment_by_uid(const std::shared_ptr& state, const gchar* uid, Appointment& setme) { - g_return_val_if_fail(vuid != nullptr, false); - g_return_val_if_fail(g_variant_type_equal(G_VARIANT_TYPE_STRING,g_variant_get_type(vuid)), false); - const auto uid = g_variant_get_string(vuid, nullptr); - g_return_val_if_fail(uid && *uid, false); - for(const auto& appt : state->calendar_upcoming->appointments().get()) { if (appt.uid == uid) @@ -67,12 +62,15 @@ bool lookup_appointment_by_uid_variant(const std::shared_ptr& state, GVar return false; } -void on_desktop_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) +void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) { auto self = static_cast(gself); Appointment appt; - if (lookup_appointment_by_uid_variant(self->state(), vuid, appt)) - self->desktop_open_appointment(appt); + const gchar* uid = nullptr; + gint64 time = 0; + g_variant_get(vdata, "(&sx)", &uid, &time); + if (lookup_appointment_by_uid(self->state(), uid, appt)) + self->desktop_open_appointment(appt, DateTime::Local(time)); } void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) { @@ -88,12 +86,15 @@ void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) static_cast(gself)->desktop_open_settings_app(); } -void on_phone_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) +void on_phone_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) { auto self = static_cast(gself); Appointment appt; - if (lookup_appointment_by_uid_variant(self->state(), vuid, appt)) - self->phone_open_appointment(appt); + const gchar* uid = nullptr; + gint64 time = 0; + g_variant_get(vdata, "(&sx)", &uid, &time); + if (lookup_appointment_by_uid(self->state(), uid, appt)) + self->phone_open_appointment(appt, DateTime::Local(time)); } void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) { @@ -198,12 +199,12 @@ Actions::Actions(const std::shared_ptr& state): { GActionEntry entries[] = { - { "desktop.open-appointment", on_desktop_appointment_activated, "s", nullptr }, + { "desktop.open-appointment", on_desktop_appointment_activated, "(sx)", nullptr }, { "desktop.open-alarm-app", on_desktop_alarm_activated }, { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr }, { "desktop.open-settings-app", on_desktop_settings_activated }, - { "phone.open-appointment", on_phone_appointment_activated, "s", nullptr }, + { "phone.open-appointment", on_phone_appointment_activated, "(sx)", nullptr }, { "phone.open-alarm-app", on_phone_alarm_activated }, { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr }, { "phone.open-settings-app", on_phone_settings_activated }, diff --git a/src/menu.cpp b/src/menu.cpp index 0cd3f9b..b1ac75c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -414,9 +414,12 @@ private: if (!appt.color.empty()) g_menu_item_set_attribute (menu_item, "x-ayatana-color", "s", appt.color.c_str()); - if (action_name != nullptr) + if (action_name != nullptr) { g_menu_item_set_action_and_target_value (menu_item, action_name, - g_variant_new_string (appt.uid.c_str())); + g_variant_new ("(sx)", + appt.uid.c_str(), + unix_time)); + } g_menu_append_item (menu, menu_item); g_object_unref (menu_item); -- cgit v1.2.3 From af623be7fec87a2fc720fed8a0daa7a4b3984573 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 22 Mar 2016 17:29:04 -0500 Subject: revert r426 & r427 to remove the calendar from the phone profile --- src/menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/menu.cpp b/src/menu.cpp index b1ac75c..f9b6485 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -319,7 +319,7 @@ private: GMenuModel* create_calendar_section(Profile profile) { const bool show_calendar = m_state->settings->show_calendar.get() && - ((profile == Desktop) || (profile == DesktopGreeter) || (profile == Phone)); + ((profile == Desktop) || (profile == DesktopGreeter)); auto menu = g_menu_new(); const char * action_name; @@ -464,7 +464,7 @@ private: const auto now = m_state->clock->localtime(); - if (profile == Desktop || profile == Phone) + if (profile == Desktop) { for(const auto& location : m_state->locations->locations.get()) { -- cgit v1.2.3 From b5996d6441811eda94b738e79b4d673f3375e6f0 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 2 Jul 2021 02:01:24 +0200 Subject: Drop myself.[h|cpp] --- src/myself.cpp | 79 ---------------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 src/myself.cpp (limited to 'src') diff --git a/src/myself.cpp b/src/myself.cpp deleted file mode 100644 index 9c02054..0000000 --- a/src/myself.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "datetime/myself.h" - -#if GLIB_CHECK_VERSION(2, 66, 0) - #include -#else - #include -#endif - -#include - -namespace ayatana { -namespace indicator { -namespace datetime { - -Myself::Myself() - : m_accounts_manager(ag_manager_new(), g_object_unref) -{ - reloadEmails(); - g_object_connect(m_accounts_manager.get(), - "signal::account-created", on_accounts_changed, this, - "signal::account-deleted", on_accounts_changed, this, - "signal::account-updated", on_accounts_changed, this, - nullptr); -} - -bool Myself::isMyEmail(const std::string &email) -{ - return m_emails.get().count(email) > 0; -} - -void Myself::on_accounts_changed(AgManager *, guint, Myself *self) -{ - self->reloadEmails(); -} - -void Myself::reloadEmails() -{ - std::set emails; - - auto manager = m_accounts_manager.get(); - auto ids = ag_manager_list(manager); - for (auto l=ids; l!=nullptr; l=l->next) - { - auto acc = ag_manager_get_account(manager, GPOINTER_TO_UINT(l->data)); - if (acc) { - auto account_name = ag_account_get_display_name(acc); - if (account_name != nullptr) - emails.insert(account_name); - g_object_unref(acc); - } - } - ag_manager_list_free(ids); - - m_emails.set(emails); -} - -} // namespace datetime -} // namespace indicator -} // namespace ayatana - -- cgit v1.2.3 From ba0581ac2fd8df5a5023fdc126351dafbbba07ed Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 30 Mar 2016 13:26:14 -0300 Subject: Ignore alarms for events marked as not attending. --- src/engine-eds.cpp | 15 +++++------ src/myself.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 src/myself.cpp (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index fc6a45b..becd40f 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -50,8 +50,7 @@ class EdsEngine::Impl { public: - Impl(const std::shared_ptr &myself) - : m_myself(myself) + Impl(const std::unique_ptr &myself) { auto cancellable_deleter = [](GCancellable * c) { g_cancellable_cancel(c); @@ -60,9 +59,11 @@ public: m_cancellable = std::shared_ptr(g_cancellable_new(), cancellable_deleter); e_source_registry_new(m_cancellable.get(), on_source_registry_ready, this); - m_myself->emails().changed().connect([this](const std::set &) { + + m_myself = std::unique_ptr(new Myself()); + /*m_myself->emails().changed().connect([this](const std::set &) { set_dirty_soon(); - }); + });*/ } ~Impl() @@ -1253,7 +1254,7 @@ private: ESourceRegistry* m_source_registry {}; guint m_rebuild_tag {}; time_t m_rebuild_deadline {}; - std::shared_ptr m_myself; + std::unique_ptr m_myself; }; /*** @@ -1261,11 +1262,11 @@ private: ***/ EdsEngine::EdsEngine(): - p(new Impl(std::shared_ptr(new Myself))) + p(new Impl(std::unique_ptr(new Myself))) { } -EdsEngine::EdsEngine(const std::shared_ptr &myself): +EdsEngine::EdsEngine(const std::unique_ptr &myself): p(new Impl(myself)) { } diff --git a/src/myself.cpp b/src/myself.cpp new file mode 100644 index 0000000..04c2126 --- /dev/null +++ b/src/myself.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2016 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "datetime/myself.h" + +#include +#include + +#include + +namespace ayatana { +namespace indicator { +namespace datetime { + +Myself::Myself() + : m_accounts_manager(ag_manager_new(), g_object_unref) +{ + reloadEmails(); + g_object_connect(m_accounts_manager.get(), + "signal::account-created", on_accounts_changed, this, + "signal::account-deleted", on_accounts_changed, this, + "signal::account-updated", on_accounts_changed, this, + nullptr); +} + +bool Myself::isMyEmail(const std::string &email) +{ + auto emails = m_emails.get(); + return (std::find(emails.begin(), emails.end(), email) != emails.end()); +} + +void Myself::on_accounts_changed(AgManager *, guint, Myself *self) +{ + self->reloadEmails(); +} + +void Myself::reloadEmails() +{ + std::vector emails; + + auto manager = m_accounts_manager.get(); + auto ids = ag_manager_list(manager); + for (auto l=ids; l!=nullptr; l=l->next) + { + auto acc = ag_manager_get_account(manager, GPOINTER_TO_UINT(l->data)); + auto account_name = ag_account_get_display_name(acc); + emails.push_back(account_name); + } + ag_manager_list_free(ids); + + m_emails.set(emails); +} + +} // namespace datetime +} // namespace indicator +} // namespace ayatana + -- cgit v1.2.3 From 8c57742f1e42bf8076b38b4509a109a911b811c7 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 30 Mar 2016 16:52:02 -0300 Subject: Only play a sound alert if the event contains a SOUND reminder. --- src/engine-eds.cpp | 24 +++++++++++++++--------- src/snap.cpp | 4 ++++ 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index becd40f..f3b08cd 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -604,13 +604,14 @@ private: } }; - static std::string get_alarm_text(ECalComponentAlarm * alarm) + static std::string get_alarm_text(ECalComponentAlarm * alarm, bool * hasText) { std::string ret; auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_DISPLAY) { + *hasText = true; auto text = e_cal_component_alarm_get_description(alarm); if (text != nullptr) @@ -627,13 +628,14 @@ private: return ret; } - static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, const std::string & default_sound) + static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, bool * hasSound) { std::string ret; auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_AUDIO) { + *hasSound = true; ICalAttach *attach = nullptr; auto attachments = e_cal_component_alarm_get_attachments(alarm); @@ -649,8 +651,6 @@ private: ret = url; } } - if (ret.empty()) - ret = default_sound; } return ret; @@ -1138,17 +1138,23 @@ private: DateTime{gtz, e_cal_component_alarm_instance_get_occur_end(ai)}); auto trigger_time = DateTime{gtz, e_cal_component_alarm_instance_get_time(ai)}; auto& alarm = alarms[instance_time][trigger_time]; + bool hasText = false; + bool hasSound = false; + if (alarm.text.empty()) - alarm.text = get_alarm_text(a); + alarm.text = get_alarm_text(a, &hasText); if (alarm.audio_url.empty()) - alarm.audio_url = get_alarm_sound_url(a, (baseline.is_ubuntu_alarm() ? - "file://" ALARM_DEFAULT_SOUND : - "file://" CALENDAR_DEFAULT_SOUND)); + alarm.audio_url = get_alarm_sound_url(a, &hasSound); if (!alarm.time.is_set()) alarm.time = trigger_time; + if (hasText) + alarm.type = alarm.type | Alarm::TEXT; + if (hasSound) + alarm.type = alarm.type | Alarm::SOUND; + e_cal_component_alarm_free(a); } @@ -1160,7 +1166,7 @@ private: appointment.alarms.reserve(i.second.size()); for (auto& j : i.second) { - if (j.second.has_text() || j.second.has_sound()) + if ((j.second.type & Alarm::TEXT) || (j.second.type & Alarm::SOUND)) appointment.alarms.push_back(j.second); } subtask->task->appointments.push_back(appointment); diff --git a/src/snap.cpp b/src/snap.cpp index 9c2b4b6..72d68a2 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -227,6 +227,10 @@ private: std::string uri; + // does not play any sound if alarm is not set as sound + if (!is_alarm && !(alarm.type & Alarm::SOUND)) + return uri; + for(const auto& candidate : candidates) { if (gst_uri_is_valid (candidate.c_str())) -- cgit v1.2.3 From 05564ab71ebdadbb100ffac690d278c9982224f5 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 30 Mar 2016 21:41:08 -0300 Subject: Create a constructor for Alarm class. --- src/appointment.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/appointment.cpp b/src/appointment.cpp index ebd5a47..a6800dd 100644 --- a/src/appointment.cpp +++ b/src/appointment.cpp @@ -29,7 +29,8 @@ namespace datetime { bool Alarm::operator==(const Alarm& that) const { - return (text==that.text) + return (type==that.type) + && (text==that.text) && (audio_url==that.audio_url) && (this->time==that.time); } -- cgit v1.2.3 From 6874753bfba638ab819bfa92ad8cd7a878ae7701 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 10:55:01 -0300 Subject: Update tests. --- src/appointment.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/appointment.cpp b/src/appointment.cpp index a6800dd..e014a85 100644 --- a/src/appointment.cpp +++ b/src/appointment.cpp @@ -27,22 +27,22 @@ namespace datetime { ***** ****/ -bool Alarm::operator==(const Alarm& that) const +Alarm::Alarm() + : type(Alarm::None) { - return (type==that.type) - && (text==that.text) - && (audio_url==that.audio_url) - && (this->time==that.time); } -bool Alarm::has_sound() const +Alarm::Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_) + : type(type_), text(text_), audio_url(audio_url_), time(time_) { - return !audio_url.empty(); } -bool Alarm::has_text() const +bool Alarm::operator==(const Alarm& that) const { - return !text.empty(); + return (type==that.type) + && (text==that.text) + && (audio_url==that.audio_url) + && (this->time==that.time); } bool Appointment::operator==(const Appointment& that) const -- cgit v1.2.3 From 7965d5b411db00de44f5c43dffac935e70347ec6 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 12:42:33 -0300 Subject: Rebuild events list in case of accounts changed. --- src/engine-eds.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index f3b08cd..bd94251 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -61,9 +61,9 @@ public: e_source_registry_new(m_cancellable.get(), on_source_registry_ready, this); m_myself = std::unique_ptr(new Myself()); - /*m_myself->emails().changed().connect([this](const std::set &) { + m_myself->emails().changed().connect([this](std::vector) { set_dirty_soon(); - });*/ + }); } ~Impl() -- cgit v1.2.3 From b1031b1de834f246bba806cd51bfbb22f5c15b16 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 15:51:29 -0300 Subject: Remove type property from Alarm. --- src/appointment.cpp | 17 ++++++++--------- src/engine-eds.cpp | 22 +++++++--------------- src/snap.cpp | 5 ----- 3 files changed, 15 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/appointment.cpp b/src/appointment.cpp index e014a85..ebd5a47 100644 --- a/src/appointment.cpp +++ b/src/appointment.cpp @@ -27,22 +27,21 @@ namespace datetime { ***** ****/ -Alarm::Alarm() - : type(Alarm::None) +bool Alarm::operator==(const Alarm& that) const { + return (text==that.text) + && (audio_url==that.audio_url) + && (this->time==that.time); } -Alarm::Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_) - : type(type_), text(text_), audio_url(audio_url_), time(time_) +bool Alarm::has_sound() const { + return !audio_url.empty(); } -bool Alarm::operator==(const Alarm& that) const +bool Alarm::has_text() const { - return (type==that.type) - && (text==that.text) - && (audio_url==that.audio_url) - && (this->time==that.time); + return !text.empty(); } bool Appointment::operator==(const Appointment& that) const diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index bd94251..68e2bdd 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -604,14 +604,13 @@ private: } }; - static std::string get_alarm_text(ECalComponentAlarm * alarm, bool * hasText) + static std::string get_alarm_text(ECalComponentAlarm * alarm) { std::string ret; auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_DISPLAY) { - *hasText = true; auto text = e_cal_component_alarm_get_description(alarm); if (text != nullptr) @@ -628,14 +627,14 @@ private: return ret; } - static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, bool * hasSound) + static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, const std::string & default_sound) { std::string ret; auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_AUDIO) { - *hasSound = true; + ret = default_sound; ICalAttach *attach = nullptr; auto attachments = e_cal_component_alarm_get_attachments(alarm); @@ -1138,23 +1137,16 @@ private: DateTime{gtz, e_cal_component_alarm_instance_get_occur_end(ai)}); auto trigger_time = DateTime{gtz, e_cal_component_alarm_instance_get_time(ai)}; auto& alarm = alarms[instance_time][trigger_time]; - bool hasText = false; - bool hasSound = false; - if (alarm.text.empty()) - alarm.text = get_alarm_text(a, &hasText); + alarm.text = get_alarm_text(a); if (alarm.audio_url.empty()) - alarm.audio_url = get_alarm_sound_url(a, &hasSound); + alarm.audio_url = get_alarm_sound_url(a, baseline.is_ubuntu_alarm() ? + ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND); if (!alarm.time.is_set()) alarm.time = trigger_time; - if (hasText) - alarm.type = alarm.type | Alarm::TEXT; - if (hasSound) - alarm.type = alarm.type | Alarm::SOUND; - e_cal_component_alarm_free(a); } @@ -1166,7 +1158,7 @@ private: appointment.alarms.reserve(i.second.size()); for (auto& j : i.second) { - if ((j.second.type & Alarm::TEXT) || (j.second.type & Alarm::SOUND)) + if (j.second.has_text() || (j.second.has_sound())) appointment.alarms.push_back(j.second); } subtask->task->appointments.push_back(appointment); diff --git a/src/snap.cpp b/src/snap.cpp index 72d68a2..97fcbab 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -226,11 +226,6 @@ private: }; std::string uri; - - // does not play any sound if alarm is not set as sound - if (!is_alarm && !(alarm.type & Alarm::SOUND)) - return uri; - for(const auto& candidate : candidates) { if (gst_uri_is_valid (candidate.c_str())) -- cgit v1.2.3 From 6df38ca1d68d1eb2fed2aca024ea938fb00d306c Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 16:26:27 -0300 Subject: Update tests. --- src/engine-eds.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 68e2bdd..7450beb 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -634,7 +634,6 @@ private: auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_AUDIO) { - ret = default_sound; ICalAttach *attach = nullptr; auto attachments = e_cal_component_alarm_get_attachments(alarm); @@ -650,6 +649,8 @@ private: ret = url; } } + if (ret.empty()) + ret = default_sound; } return ret; @@ -1141,8 +1142,9 @@ private: alarm.text = get_alarm_text(a); if (alarm.audio_url.empty()) - alarm.audio_url = get_alarm_sound_url(a, baseline.is_ubuntu_alarm() ? - ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND); + alarm.audio_url = get_alarm_sound_url(a, (baseline.is_ubuntu_alarm() ? + "file://" ALARM_DEFAULT_SOUND : + "file://" ALARM_DEFAULT_SOUND)); if (!alarm.time.is_set()) alarm.time = trigger_time; @@ -1158,7 +1160,7 @@ private: appointment.alarms.reserve(i.second.size()); for (auto& j : i.second) { - if (j.second.has_text() || (j.second.has_sound())) + if (j.second.has_text() || j.second.has_sound()) appointment.alarms.push_back(j.second); } subtask->task->appointments.push_back(appointment); -- cgit v1.2.3 From 30b0ba7facf333209ea60db9f3b5820dc0f4d5f3 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 16:53:36 -0300 Subject: Update code as requested by reviewer. --- src/engine-eds.cpp | 16 +++++----------- src/main.cpp | 3 ++- src/myself.cpp | 13 ++++++++----- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 7450beb..585841b 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -50,7 +50,8 @@ class EdsEngine::Impl { public: - Impl(const std::unique_ptr &myself) + Impl(const std::shared_ptr &myself) + : m_myself(myself) { auto cancellable_deleter = [](GCancellable * c) { g_cancellable_cancel(c); @@ -59,9 +60,7 @@ public: m_cancellable = std::shared_ptr(g_cancellable_new(), cancellable_deleter); e_source_registry_new(m_cancellable.get(), on_source_registry_ready, this); - - m_myself = std::unique_ptr(new Myself()); - m_myself->emails().changed().connect([this](std::vector) { + m_myself->emails().changed().connect([this](const std::set &) { set_dirty_soon(); }); } @@ -1254,19 +1253,14 @@ private: ESourceRegistry* m_source_registry {}; guint m_rebuild_tag {}; time_t m_rebuild_deadline {}; - std::unique_ptr m_myself; + std::shared_ptr m_myself; }; /*** **** ***/ -EdsEngine::EdsEngine(): - p(new Impl(std::unique_ptr(new Myself))) -{ -} - -EdsEngine::EdsEngine(const std::unique_ptr &myself): +EdsEngine::EdsEngine(const std::shared_ptr &myself): p(new Impl(myself)) { } diff --git a/src/main.cpp b/src/main.cpp index fdd84b5..0da55a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ namespace if (!g_strcmp0("lightdm", g_get_user_name())) engine.reset(new MockEngine); else - engine.reset(new EdsEngine); + engine.reset(new EdsEngine(std::shared_ptr(new Myself))); return engine; } diff --git a/src/myself.cpp b/src/myself.cpp index 04c2126..0debfe4 100644 --- a/src/myself.cpp +++ b/src/myself.cpp @@ -41,8 +41,7 @@ Myself::Myself() bool Myself::isMyEmail(const std::string &email) { - auto emails = m_emails.get(); - return (std::find(emails.begin(), emails.end(), email) != emails.end()); + return m_emails.get().count(email) > 0; } void Myself::on_accounts_changed(AgManager *, guint, Myself *self) @@ -52,15 +51,19 @@ void Myself::on_accounts_changed(AgManager *, guint, Myself *self) void Myself::reloadEmails() { - std::vector emails; + std::set emails; auto manager = m_accounts_manager.get(); auto ids = ag_manager_list(manager); for (auto l=ids; l!=nullptr; l=l->next) { auto acc = ag_manager_get_account(manager, GPOINTER_TO_UINT(l->data)); - auto account_name = ag_account_get_display_name(acc); - emails.push_back(account_name); + if (acc) { + auto account_name = ag_account_get_display_name(acc); + if (account_name != nullptr) + emails.insert(account_name); + g_object_unref(acc); + } } ag_manager_list_free(ids); -- cgit v1.2.3 From e4e139f59dbff3cdd5db2f2e175dd78ce56ad956 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 1 Apr 2016 10:05:52 -0300 Subject: Does not play sound for events without a sound set. --- src/snap.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 97fcbab..ca89851 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -226,6 +226,9 @@ private: }; std::string uri; + if (!alarm.has_sound() && !is_alarm) + return uri; + for(const auto& candidate : candidates) { if (gst_uri_is_valid (candidate.c_str())) -- cgit v1.2.3 From c1fb6eece72a362bbc801e9a1d84d05fc8a06532 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 1 Apr 2016 10:13:49 -0300 Subject: better code. --- src/snap.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index ca89851..259592e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -101,7 +101,7 @@ public: // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - if (appointment.is_ubuntu_alarm() || !silent_mode()) { + if (appointment.is_ubuntu_alarm() || (alarm.has_sound() && !silent_mode())) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); @@ -226,8 +226,6 @@ private: }; std::string uri; - if (!alarm.has_sound() && !is_alarm) - return uri; for(const auto& candidate : candidates) { -- cgit v1.2.3 From 272067d4a6aa76117b23b231b3b1888df54ce880 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 6 Apr 2016 10:37:28 -0300 Subject: Generate instance of object to get individual alarm information. --- src/engine-eds.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 585841b..7f5e080 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -102,6 +102,8 @@ public: auto gtz = timezone_from_name(tz, nullptr, nullptr, &default_timezone); if (gtz == nullptr) { gtz = g_time_zone_new_local(); + } else { + g_time_zone_ref(gtz); } g_debug("default_timezone is %s", default_timezone ? i_cal_timezone_get_display_name(default_timezone) : "null"); -- cgit v1.2.3 From 5532e39c7072d05ce21735335a5dbdd9e1857660 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 6 Apr 2016 15:19:36 -0300 Subject: Does not add extra ref to timezone object. --- src/engine-eds.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 7f5e080..585841b 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -102,8 +102,6 @@ public: auto gtz = timezone_from_name(tz, nullptr, nullptr, &default_timezone); if (gtz == nullptr) { gtz = g_time_zone_new_local(); - } else { - g_time_zone_ref(gtz); } g_debug("default_timezone is %s", default_timezone ? i_cal_timezone_get_display_name(default_timezone) : "null"); -- cgit v1.2.3 From bbac8b00a721c762aceff0051bab0e7dc753eab2 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 6 Apr 2016 15:42:27 -0300 Subject: Fixed sound file used by event alarms. --- src/engine-eds.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 585841b..4228258 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -1143,7 +1143,7 @@ private: if (alarm.audio_url.empty()) alarm.audio_url = get_alarm_sound_url(a, (baseline.is_ubuntu_alarm() ? "file://" ALARM_DEFAULT_SOUND : - "file://" ALARM_DEFAULT_SOUND)); + "file://" CALENDAR_DEFAULT_SOUND)); if (!alarm.time.is_set()) alarm.time = trigger_time; -- cgit v1.2.3 From 328cdb7015136ff831a14f686d08f41f4e7421a1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 8 Apr 2016 15:46:50 -0500 Subject: pull the timezone from timedate1 regardless of whether it appears on the bus before or after we startup --- src/timezone-timedated.cpp | 249 ++++++++++++++++++++++++--------------------- 1 file changed, 135 insertions(+), 114 deletions(-) (limited to 'src') diff --git a/src/timezone-timedated.cpp b/src/timezone-timedated.cpp index d38557b..9254612 100644 --- a/src/timezone-timedated.cpp +++ b/src/timezone-timedated.cpp @@ -17,6 +17,7 @@ * Charles Kerr */ +#include #include #include @@ -36,166 +37,186 @@ class TimedatedTimezone::Impl { public: - Impl(TimedatedTimezone& owner, std::string filename): - m_owner(owner), - m_filename(filename) + Impl(TimedatedTimezone& owner): + m_owner{owner}, + m_cancellable{g_cancellable_new()} { - g_debug("Filename is '%s'", filename.c_str()); - monitor_timezone_property(); + // set the fallback value + m_owner.timezone.set("Etc/Utc"); + + // watch for timedate1 on the bus + m_watcher_id = g_bus_watch_name( + G_BUS_TYPE_SYSTEM, + Bus::Timedate1::BUSNAME, + G_BUS_NAME_WATCHER_FLAGS_AUTO_START, + on_timedate1_appeared, + on_timedate1_vanished, + this, + nullptr); } ~Impl() { - clear(); - } + g_cancellable_cancel(m_cancellable); + g_clear_object(&m_cancellable); -private: + g_bus_unwatch_name(m_watcher_id); - void clear() - { - if (m_connection && m_signal_subscription_id) + if (m_connection != nullptr) { - g_dbus_connection_signal_unsubscribe (m_connection, m_signal_subscription_id); - m_signal_subscription_id = 0; - } + if (m_signal_subscription_id) + g_dbus_connection_signal_unsubscribe(m_connection, m_signal_subscription_id); - g_clear_object(&m_connection); + g_clear_object(&m_connection); + } } - static void on_properties_changed (GDBusConnection *connection G_GNUC_UNUSED, - const gchar *sender_name G_GNUC_UNUSED, - const gchar *object_path G_GNUC_UNUSED, - const gchar *interface_name G_GNUC_UNUSED, - const gchar *signal_name G_GNUC_UNUSED, - GVariant *parameters, - gpointer gself) - { - auto self = static_cast(gself); - const char *tz; - GVariant *changed_properties; - gchar **invalidated_properties; - - g_variant_get (parameters, "(s@a{sv}^as)", NULL, &changed_properties, &invalidated_properties); +private: - if (g_variant_lookup(changed_properties, "Timezone", "&s", &tz, NULL)) - self->notify_timezone(tz); - else if (g_strv_contains (invalidated_properties, "Timezone")) - self->notify_timezone(self->get_timezone_from_file(self->m_filename)); + static void on_timedate1_appeared(GDBusConnection * connection, + const gchar * /*name*/, + const gchar * /*name_owner*/, + gpointer gself) + { + static_cast(gself)->timedate1_appeared(connection); + } + void timedate1_appeared(GDBusConnection* connection) + { + // cache m_connection for later... + g_clear_object(&m_connection); + m_connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(connection))); - g_variant_unref (changed_properties); - g_strfreev (invalidated_properties); + ensure_propchange_subscription(); + ask_for_timezone(); } - void monitor_timezone_property() + void ensure_propchange_subscription() { - GError *err = nullptr; - - /* - * There is an unlikely race which happens if there is an activation - * and timezone change before our match rule is added. - */ - notify_timezone(get_timezone_from_file(m_filename)); - - /* - * Make sure the bus is around at least until we add the match rules, - * otherwise things (tests) are sad. - */ - m_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, - nullptr, - &err); - - if (err) + if (m_signal_subscription_id == 0) { - g_warning("Couldn't get bus connection: '%s'", err->message); - g_error_free(err); - return; - } - - m_signal_subscription_id = g_dbus_connection_signal_subscribe(m_connection, - "org.freedesktop.timedate1", - "org.freedesktop.DBus.Properties", - "PropertiesChanged", - "/org/freedesktop/timedate1", - NULL, G_DBUS_SIGNAL_FLAGS_NONE, + m_signal_subscription_id = g_dbus_connection_signal_subscribe( + m_connection, + Bus::Timedate1::IFACE, + Bus::Properties::IFACE, + Bus::Properties::Signals::PROPERTIES_CHANGED, + Bus::Timedate1::ADDR, + nullptr, + G_DBUS_SIGNAL_FLAGS_NONE, on_properties_changed, - this, nullptr); + this, + nullptr); + } } - void notify_timezone(std::string new_timezone) + static void on_timedate1_vanished(GDBusConnection * /*connection*/, + const gchar * name, + gpointer /*gself*/) { - g_debug("notify_timezone '%s'", new_timezone.c_str()); - if (!new_timezone.empty()) - m_owner.timezone.set(new_timezone); + g_debug("%s not present on system bus", name); } - std::string get_timezone_from_file(const std::string& filename) + static void on_properties_changed(GDBusConnection * /*connection*/, + const gchar * /*sender_name*/, + const gchar * /*object_path*/, + const gchar * /*interface_name*/, + const gchar * /*signal_name*/, + GVariant * parameters, + gpointer gself) { - GError * error; - GIOChannel * io_channel; - std::string ret; - - // read through filename line-by-line until we fine a nonempty non-comment line - error = nullptr; - io_channel = g_io_channel_new_file(filename.c_str(), "r", &error); - if (error == nullptr) - { - auto line = g_string_new(nullptr); - - while(ret.empty()) - { - const auto io_status = g_io_channel_read_line_string(io_channel, line, nullptr, &error); - if ((io_status == G_IO_STATUS_EOF) || (io_status == G_IO_STATUS_ERROR)) - break; - if (error != nullptr) - break; - - g_strstrip(line->str); + auto self = static_cast(gself); - if (!line->len) // skip empty lines - continue; + GVariant* changed_properties {}; + gchar** invalidated_properties {}; + g_variant_get(parameters, "(s@a{sv}^as)", NULL, &changed_properties, &invalidated_properties); - if (*line->str=='#') // skip comments - continue; + const char* tz {}; + if (g_variant_lookup(changed_properties, Bus::Timedate1::Properties::TIMEZONE, "&s", &tz, NULL)) + { + if (tz != nullptr) + self->set_timezone(tz); + else + g_warning("%s no timezone found", G_STRLOC); + } + else if (g_strv_contains(invalidated_properties, Bus::Timedate1::Properties::TIMEZONE)) + { + self->ask_for_timezone(); + } - ret = line->str; - } + g_variant_unref(changed_properties); + g_strfreev(invalidated_properties); + } - g_string_free(line, true); - } else - /* Default to UTC */ - ret = "Etc/Utc"; + void ask_for_timezone() + { + g_return_if_fail(m_connection != nullptr); + + g_dbus_connection_call( + m_connection, + Bus::Timedate1::BUSNAME, + Bus::Timedate1::ADDR, + Bus::Properties::IFACE, + Bus::Properties::Methods::GET, + g_variant_new("(ss)", Bus::Timedate1::IFACE, Bus::Timedate1::Properties::TIMEZONE), + G_VARIANT_TYPE("(v)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + m_cancellable, + on_get_timezone_ready, + this); + } - if (io_channel != nullptr) + static void on_get_timezone_ready(GObject * connection, + GAsyncResult * res, + gpointer gself) + { + GError* error {}; + GVariant* v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(connection), res, &error); + if (v == nullptr) { - g_io_channel_shutdown(io_channel, false, nullptr); - g_io_channel_unref(io_channel); + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("%s Couldn't get timezone: %s", G_STRLOC, error->message); } - - if (error != nullptr) + else { - g_warning("%s Unable to read timezone file '%s': %s", G_STRLOC, filename.c_str(), error->message); - g_error_free(error); + GVariant* tzv {}; + g_variant_get(v, "(v)", &tzv); + const char* tz = g_variant_get_string(tzv, nullptr); + + if (tz != nullptr) + static_cast(gself)->set_timezone(tz); + else + g_warning("%s no timezone found", G_STRLOC); + + g_clear_pointer(&tzv, g_variant_unref); + g_clear_pointer(&v, g_variant_unref); } + } + + void set_timezone(const std::string& tz) + { + g_return_if_fail(!tz.empty()); - return ret; + g_debug("set timezone: '%s'", tz.c_str()); + m_owner.timezone.set(tz); } /*** **** ***/ - TimedatedTimezone & m_owner; - GDBusConnection *m_connection = nullptr; - unsigned long m_signal_subscription_id = 0; - std::string m_filename; + TimedatedTimezone& m_owner; + GCancellable* m_cancellable {}; + GDBusConnection* m_connection {}; + unsigned long m_signal_subscription_id {}; + unsigned int m_watcher_id {}; }; /*** **** ***/ -TimedatedTimezone::TimedatedTimezone(std::string filename): - impl(new Impl{*this, filename}) +TimedatedTimezone::TimedatedTimezone(): + impl{new Impl{*this}} { } -- cgit v1.2.3 From 85f702d540c998b91f5004b9c9629faaacfc37bd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 8 Apr 2016 16:37:55 -0500 Subject: in timezone-timedated, check for error!=nullptr before passing it to g_error_matches() --- src/timezone-timedated.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/timezone-timedated.cpp b/src/timezone-timedated.cpp index 9254612..e123531 100644 --- a/src/timezone-timedated.cpp +++ b/src/timezone-timedated.cpp @@ -171,12 +171,12 @@ private: { GError* error {}; GVariant* v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(connection), res, &error); - if (v == nullptr) + if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning("%s Couldn't get timezone: %s", G_STRLOC, error->message); } - else + else if (v != nullptr) { GVariant* tzv {}; g_variant_get(v, "(v)", &tzv); -- cgit v1.2.3 From 7ac0160b0e7ce9245e13750429790cb2a999528b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 9 Apr 2016 19:03:57 -0500 Subject: in actions-live, don't hardcode the bus strings --- src/actions-live.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 231fb33..e3237b7 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -17,6 +17,7 @@ * Charles Kerr */ +#include #include #ifdef HAS_URLDISPATCHER @@ -240,7 +241,7 @@ on_datetime1_proxy_ready (GObject * object G_GNUC_UNUSED, else { g_dbus_proxy_call(proxy, - "SetTimezone", + Bus::Timedate1::Methods::SET_TIMEZONE, g_variant_new ("(sb)", data->tzid.c_str(), TRUE), G_DBUS_CALL_FLAGS_NONE, -1, @@ -268,9 +269,9 @@ void LiveActions::set_location(const std::string& tzid, const std::string& name) g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr, - "org.freedesktop.timedate1", - "/org/freedesktop/timedate1", - "org.freedesktop.timedate1", + Bus::Timedate1::BUSNAME, + Bus::Timedate1::ADDR, + Bus::Timedate1::IFACE, nullptr, on_datetime1_proxy_ready, data); -- cgit v1.2.3 From ad95b394c94c9ba958d54c5243f376e7854683b8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Apr 2016 12:03:36 -0500 Subject: in TimedatedTimezone, take a GDBusConnection argument in the ctor to simplify state management --- src/main.cpp | 14 +++++++-- src/timezone-timedated.cpp | 71 ++++++++++++++++++---------------------------- 2 files changed, 39 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 0da55a2..bb77c0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,7 +71,7 @@ namespace { // create the live objects auto live_settings = std::make_shared(); - auto live_timezones = std::make_shared(live_settings); + auto live_timezones = std::make_shared(live_settings, timezone_); auto live_clock = std::make_shared(timezone_); // create a full-month planner currently pointing to the current month @@ -132,8 +132,17 @@ main(int /*argc*/, char** /*argv*/) bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); + // get the system bus + GError* error {}; + auto system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error); + if (error != nullptr) { + g_critical("Unable to get system bus: %s", error->message); + g_clear_error(&error); + return 0; + } + auto engine = create_engine(); - auto timezone_ = std::make_shared(); + auto timezone_ = std::make_shared(system_bus); auto state = create_state(engine, timezone_); auto actions = std::make_shared(state); MenuFactory factory(actions, state); @@ -171,5 +180,6 @@ main(int /*argc*/, char** /*argv*/) g_main_loop_run(loop); g_main_loop_unref(loop); + g_clear_object(&system_bus); return 0; } diff --git a/src/timezone-timedated.cpp b/src/timezone-timedated.cpp index e123531..1b6497e 100644 --- a/src/timezone-timedated.cpp +++ b/src/timezone-timedated.cpp @@ -37,22 +37,36 @@ class TimedatedTimezone::Impl { public: - Impl(TimedatedTimezone& owner): + Impl(TimedatedTimezone& owner, GDBusConnection* connection): m_owner{owner}, + m_connection{G_DBUS_CONNECTION(g_object_ref(G_OBJECT(connection)))}, m_cancellable{g_cancellable_new()} { // set the fallback value m_owner.timezone.set("Etc/Utc"); // watch for timedate1 on the bus - m_watcher_id = g_bus_watch_name( - G_BUS_TYPE_SYSTEM, + m_watcher_id = g_bus_watch_name_on_connection( + m_connection, Bus::Timedate1::BUSNAME, G_BUS_NAME_WATCHER_FLAGS_AUTO_START, on_timedate1_appeared, on_timedate1_vanished, this, nullptr); + + // listen for changed properties + m_signal_subscription_id = g_dbus_connection_signal_subscribe( + m_connection, + Bus::Timedate1::IFACE, + Bus::Properties::IFACE, + Bus::Properties::Signals::PROPERTIES_CHANGED, + Bus::Timedate1::ADDR, + nullptr, + G_DBUS_SIGNAL_FLAGS_NONE, + on_properties_changed, + this, + nullptr); } ~Impl() @@ -62,57 +76,28 @@ public: g_bus_unwatch_name(m_watcher_id); - if (m_connection != nullptr) - { - if (m_signal_subscription_id) - g_dbus_connection_signal_unsubscribe(m_connection, m_signal_subscription_id); + g_dbus_connection_signal_unsubscribe(m_connection, m_signal_subscription_id); - g_clear_object(&m_connection); - } + g_clear_object(&m_connection); } private: - static void on_timedate1_appeared(GDBusConnection * connection, - const gchar * /*name*/, + static void on_timedate1_appeared(GDBusConnection * /*connection*/, + const gchar * name, const gchar * /*name_owner*/, gpointer gself) { - static_cast(gself)->timedate1_appeared(connection); - } - void timedate1_appeared(GDBusConnection* connection) - { - // cache m_connection for later... - g_clear_object(&m_connection); - m_connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(connection))); + g_debug("%s appeared on bus", name); - ensure_propchange_subscription(); - ask_for_timezone(); - } - - void ensure_propchange_subscription() - { - if (m_signal_subscription_id == 0) - { - m_signal_subscription_id = g_dbus_connection_signal_subscribe( - m_connection, - Bus::Timedate1::IFACE, - Bus::Properties::IFACE, - Bus::Properties::Signals::PROPERTIES_CHANGED, - Bus::Timedate1::ADDR, - nullptr, - G_DBUS_SIGNAL_FLAGS_NONE, - on_properties_changed, - this, - nullptr); - } + static_cast(gself)->ask_for_timezone(); } static void on_timedate1_vanished(GDBusConnection * /*connection*/, const gchar * name, gpointer /*gself*/) { - g_debug("%s not present on system bus", name); + g_debug("%s not present on bus", name); } static void on_properties_changed(GDBusConnection * /*connection*/, @@ -148,8 +133,6 @@ private: void ask_for_timezone() { - g_return_if_fail(m_connection != nullptr); - g_dbus_connection_call( m_connection, Bus::Timedate1::BUSNAME, @@ -205,8 +188,8 @@ private: ***/ TimedatedTimezone& m_owner; - GCancellable* m_cancellable {}; GDBusConnection* m_connection {}; + GCancellable* m_cancellable {}; unsigned long m_signal_subscription_id {}; unsigned int m_watcher_id {}; }; @@ -215,8 +198,8 @@ private: **** ***/ -TimedatedTimezone::TimedatedTimezone(): - impl{new Impl{*this}} +TimedatedTimezone::TimedatedTimezone(GDBusConnection* connection): + impl{new Impl{*this, connection}} { } -- cgit v1.2.3 From 6c96dc57eff3f64155c913e1b011da5f5a6887fb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 12 Apr 2016 12:05:11 -0500 Subject: in LiveTimezones, pass the primary timezone to it on construction. We used to create it implicitly but can't do that anymore now that TimedatedTimezone takes its own ctor argument. --- src/timezones-live.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp index 2979036..f3bd02d 100644 --- a/src/timezones-live.cpp +++ b/src/timezones-live.cpp @@ -25,11 +25,14 @@ namespace ayatana { namespace indicator { namespace datetime { -LiveTimezones::LiveTimezones(const std::shared_ptr& settings): - m_file(), +LiveTimezones::LiveTimezones( + const std::shared_ptr& settings, + const std::shared_ptr& primary_timezone +): + m_primary_timezone(primary_timezone), m_settings(settings) { - m_file.timezone.changed().connect([this](const std::string&){update_timezones();}); + m_primary_timezone->timezone.changed().connect([this](const std::string&){update_timezones();}); m_settings->show_detected_location.changed().connect([this](bool){update_geolocation();}); update_geolocation(); @@ -53,7 +56,7 @@ void LiveTimezones::update_geolocation() void LiveTimezones::update_timezones() { - const auto a = m_file.timezone.get(); + const auto a = m_primary_timezone->timezone.get(); const auto b = m_geo ? m_geo->timezone.get() : ""; timezone.set(a.empty() ? b : a); -- cgit v1.2.3 From 629e74043b1815bd8aad6eab154fc26a6a74c8d4 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 14 Apr 2016 18:23:44 -0300 Subject: Play event sound even if the event has only text reminders. --- src/snap.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 259592e..a1caf62 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -101,7 +101,10 @@ public: // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - if (appointment.is_ubuntu_alarm() || (alarm.has_sound() && !silent_mode())) { + // play reminder sound even if the event is only a text reminder. + // we choose that because events synced from google only get text reminders + bool play_sound = (alarm.has_sound() || alarm.has_text()); + if (appointment.is_ubuntu_alarm() || (play_sound && !silent_mode())) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); -- cgit v1.2.3 From 442818a849f468649121d19adfc0d3589387dda0 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 15 Apr 2016 14:23:40 -0300 Subject: revert last change. --- src/snap.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index a1caf62..259592e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -101,10 +101,7 @@ public: // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - // play reminder sound even if the event is only a text reminder. - // we choose that because events synced from google only get text reminders - bool play_sound = (alarm.has_sound() || alarm.has_text()); - if (appointment.is_ubuntu_alarm() || (play_sound && !silent_mode())) { + if (appointment.is_ubuntu_alarm() || (alarm.has_sound() && !silent_mode())) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); -- cgit v1.2.3 From 13978702ac61845927889986310085e8f90821da Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 18 Apr 2016 23:42:53 -0300 Subject: Post message on messaging menu if the notification get timeout. --- src/main.cpp | 5 +- src/notifications.cpp | 127 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/snap.cpp | 12 ++++- 3 files changed, 136 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index bb77c0e..f9a934a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -156,7 +156,10 @@ main(int /*argc*/, char** /*argv*/) auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) { snooze_planner->add(appointment, alarm); }; - auto on_ok = [](const Appointment&, const Alarm&){}; + auto on_ok = [actions](const Appointment& app, const Alarm&){ + //TODO: add support for desktop + actions->phone_open_appointment(app, app.begin); + }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { (*snap)(appointment, alarm, on_snooze, on_ok); engine->disable_ubuntu_alarm(appointment); diff --git a/src/notifications.cpp b/src/notifications.cpp index 051653d..2d22087 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -21,10 +21,18 @@ #include +#include +#include + + +#include + #include #include #include #include +#include + namespace ayatana { namespace indicator { @@ -45,9 +53,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; + gint64 m_start_time; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; + std::function m_missed_click_callback; }; Builder::Builder(): @@ -101,6 +111,18 @@ Builder::set_closed_callback (std::function cb) impl->m_closed_callback.swap (cb); } +void +Builder::set_missed_click_callback (std::function cb) +{ + impl->m_missed_click_callback.swap (cb); +} + +void +Builder::set_start_time (uint64_t time) +{ + impl->m_start_time = time; +} + /*** **** ***/ @@ -110,23 +132,39 @@ class Engine::Impl struct notification_data { std::shared_ptr nn; - std::function closed_callback; + Builder::Impl data; + }; + + struct messaging_menu_data + { + std::shared_ptr mm; + std::function callback; }; public: Impl(const std::string& app_name): + m_messaging_app(messaging_menu_app_new(DATETIME_INDICATOR_DESKTOP_FILE), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); + + // messaging menu + GIcon *icon = g_themed_icon_new("calendar-app"); + + messaging_menu_app_register(m_messaging_app.get()); + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + g_object_unref(icon); } ~Impl() { close_all (); + remove_all (); notify_uninit (); + messaging_menu_app_unregister (m_messaging_app.get()); } const std::string& app_name() const @@ -217,7 +255,7 @@ public: notification_key_quark(), GINT_TO_POINTER(key)); - m_notifications[key] = { nn, info.m_closed_callback }; + m_notifications[key] = { nn, info }; g_signal_connect (nn.get(), "closed", G_CALLBACK(on_notification_closed), this); @@ -238,6 +276,59 @@ public: return ret; } + std::string post(const Builder::Impl& data) + { + uuid_t message_uuid; + uuid_generate(message_uuid); + + char message_id[37]; + uuid_unparse(message_uuid, message_id); + + GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); + std::shared_ptr msg (messaging_menu_message_new(message_id, + icon, + data.m_title.c_str(), + nullptr, + data.m_body.c_str(), + data.m_start_time * 1000000), // secs -> microsecs + g_object_ref); + g_object_unref(icon); + if (msg) + { + m_messaging_messages[std::string(message_id)] = { msg, data.m_missed_click_callback }; + g_signal_connect(msg.get(), "activate", + G_CALLBACK(on_message_activated), this); + messaging_menu_app_append_message(m_messaging_app.get(), msg.get(), m_app_name.c_str(), false); + return message_id; + } else { + g_warning("Fail to create messaging menu message"); + } + return ""; + } + + void remove (const std::string &key) + { + auto it = m_messaging_messages.find(key); + if (it != m_messaging_messages.end()) + { + // tell the server to remove message + messaging_menu_app_remove_message(m_messaging_app.get(), it->second.mm.get()); + m_messaging_messages.erase(it); + } + } + + void remove_all () + { + // call remove() on all our keys + + std::set keys; + for (const auto& it : m_messaging_messages) + keys.insert (it.first); + + for (const std::string &key : keys) + remove (key); + } + private: const std::set& server_caps() const @@ -279,6 +370,22 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } + static void on_message_activated (MessagingMenuMessage *, + const char *actionId, + GVariant *, + gpointer gself) + { + auto self = static_cast(gself); + auto it = self->m_messaging_messages.find(actionId); + g_return_if_fail (it != self->m_messaging_messages.end()); + const auto& ndata = it->second; + + if (ndata.callback) + ndata.callback(); + + self->m_messaging_messages.erase(it); + } + void remove_closed_notification (int key) { auto it = m_notifications.find(key); @@ -286,16 +393,20 @@ private: const auto& ndata = it->second; auto nn = ndata.nn.get(); - if (ndata.closed_callback) + + if (ndata.data.m_closed_callback) { std::string action; - const GQuark q = notification_action_quark(); const gpointer p = g_object_get_qdata(G_OBJECT(nn), q); if (p != nullptr) action = static_cast(p); - ndata.closed_callback (action); + ndata.data.m_closed_callback (action); + // empty action means that the notification got timeout + // post a message on messaging menu + if (action.empty()) + post(ndata.data); } m_notifications.erase(it); @@ -305,6 +416,10 @@ private: **** ***/ + // messaging menu + std::shared_ptr m_messaging_app; + std::map m_messaging_messages; + const std::string m_app_name; // key-to-data @@ -315,6 +430,8 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; + static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; + static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** diff --git a/src/snap.cpp b/src/snap.cpp index 259592e..5c530be 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -122,8 +122,9 @@ public: const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); ain::Builder b; b.set_body (appointment.summary); - b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "reminder"); + b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "appointment"); b.add_hint (ain::Builder::HINT_NONSHAPED_ICON); + b.set_start_time (appointment.begin.to_unix()); const char * timefmt; if (is_locale_12h()) { @@ -152,6 +153,9 @@ public: b.add_hint (ain::Builder::HINT_AFFIRMATIVE_HINT); b.add_action ("ok", _("OK")); b.add_action ("snooze", _("Snooze")); + } else { + b.add_hint (ain::Builder::HINT_INTERACTIVE); + b.add_action ("ok", _("OK")); } // add 'sound', 'haptic', and 'awake' objects to the capture so @@ -161,10 +165,14 @@ public: (const std::string& action){ if (action == "snooze") snooze(appointment, alarm); - else + else if (action == "ok") ok(appointment, alarm); }); + b.set_missed_click_callback([appointment, alarm, ok](){ + ok(appointment, alarm); + }); + const auto key = m_engine->show(b); if (key) m_notifications.insert (key); -- cgit v1.2.3 From 14fbc83d449bbf2a4ed4d0716a37d6b4c433d55e Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 19 Apr 2016 12:09:03 -0300 Subject: Fixed crash when clicking on messaging menu. --- src/notifications.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 2d22087..5b64471 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -291,7 +291,7 @@ public: nullptr, data.m_body.c_str(), data.m_start_time * 1000000), // secs -> microsecs - g_object_ref); + g_object_unref); g_object_unref(icon); if (msg) { @@ -370,13 +370,13 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } - static void on_message_activated (MessagingMenuMessage *, - const char *actionId, + static void on_message_activated (MessagingMenuMessage *msg, + const char *, GVariant *, gpointer gself) { auto self = static_cast(gself); - auto it = self->m_messaging_messages.find(actionId); + auto it = self->m_messaging_messages.find(messaging_menu_message_get_id(msg)); g_return_if_fail (it != self->m_messaging_messages.end()); const auto& ndata = it->second; -- cgit v1.2.3 From 6e9b1ac9d055f45cb04842b9ab5d86810eb7d2c8 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 19 Apr 2016 13:12:54 -0300 Subject: Only play sounds for alarms. --- src/snap.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 5c530be..4736498 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -101,7 +101,9 @@ public: // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - if (appointment.is_ubuntu_alarm() || (alarm.has_sound() && !silent_mode())) { + // FIXME: only play sounds for alarms for now, we should itegrate it with + // system settings to decide if we should play sounds for calendar notification or not + if (appointment.is_ubuntu_alarm()) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); -- cgit v1.2.3 From aeba43c7b4be927c23eb61c2644e60182be22bd5 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 20 Apr 2016 11:00:35 -0300 Subject: Fix memory leak on messaging_menu. --- src/notifications.cpp | 68 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 5b64471..076ad13 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -137,8 +137,9 @@ class Engine::Impl struct messaging_menu_data { - std::shared_ptr mm; + std::string msg_id; std::function callback; + Engine::Impl *self; }; public: @@ -151,11 +152,7 @@ public: g_critical("Unable to initialize libnotify!"); // messaging menu - GIcon *icon = g_themed_icon_new("calendar-app"); - messaging_menu_app_register(m_messaging_app.get()); - messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); - g_object_unref(icon); } ~Impl() @@ -285,20 +282,31 @@ public: uuid_unparse(message_uuid, message_id); GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); - std::shared_ptr msg (messaging_menu_message_new(message_id, - icon, - data.m_title.c_str(), - nullptr, - data.m_body.c_str(), - data.m_start_time * 1000000), // secs -> microsecs - g_object_unref); + + // check if source exists + if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + + auto msg = messaging_menu_message_new(message_id, + icon, + data.m_title.c_str(), + nullptr, + data.m_body.c_str(), + data.m_start_time * 1000000); // secs -> microsecs g_object_unref(icon); if (msg) { - m_messaging_messages[std::string(message_id)] = { msg, data.m_missed_click_callback }; - g_signal_connect(msg.get(), "activate", - G_CALLBACK(on_message_activated), this); - messaging_menu_app_append_message(m_messaging_app.get(), msg.get(), m_app_name.c_str(), false); + std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); + m_messaging_messages[std::string(message_id)] = msg_data; + g_signal_connect(G_OBJECT(msg), "activate", + G_CALLBACK(on_message_activated), msg_data.get()); + messaging_menu_app_append_message(m_messaging_app.get(), msg, m_app_name.c_str(), false); + + // we use that to keep track of messaging, in case of message get cleared from menu + g_object_set_data_full(G_OBJECT(msg), "destroy-notify", msg_data.get(), on_message_destroyed); + // keep the message control with message_menu + g_object_unref(msg); + return message_id; } else { g_warning("Fail to create messaging menu message"); @@ -312,8 +320,8 @@ public: if (it != m_messaging_messages.end()) { // tell the server to remove message - messaging_menu_app_remove_message(m_messaging_app.get(), it->second.mm.get()); - m_messaging_messages.erase(it); + messaging_menu_app_remove_message_by_id(m_messaging_app.get(), it->second->msg_id.c_str()); + // message will be remove by on_message_destroyed cb. } } @@ -370,20 +378,26 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } - static void on_message_activated (MessagingMenuMessage *msg, + static void on_message_activated (MessagingMenuMessage *, const char *, GVariant *, - gpointer gself) + gpointer data) { - auto self = static_cast(gself); - auto it = self->m_messaging_messages.find(messaging_menu_message_get_id(msg)); - g_return_if_fail (it != self->m_messaging_messages.end()); + auto msg_data = static_cast(data); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + g_return_if_fail (it != msg_data->self->m_messaging_messages.end()); const auto& ndata = it->second; - if (ndata.callback) - ndata.callback(); + if (ndata->callback) + ndata->callback(); + } - self->m_messaging_messages.erase(it); + static void on_message_destroyed(gpointer data) + { + auto msg_data = static_cast(data); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + if (it != msg_data->self->m_messaging_messages.end()) + msg_data->self->m_messaging_messages.erase(it); } void remove_closed_notification (int key) @@ -418,7 +432,7 @@ private: // messaging menu std::shared_ptr m_messaging_app; - std::map m_messaging_messages; + std::map > m_messaging_messages; const std::string m_app_name; -- cgit v1.2.3 From d39dd6255625021cb5e3596ef4c5b921d59797b5 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 20 Apr 2016 17:59:25 -0300 Subject: Vibrate only once when notification about calendar events. --- src/haptic.cpp | 20 +++++++++++++------- src/snap.cpp | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/haptic.cpp b/src/haptic.cpp index 7430c04..dc2cb82 100644 --- a/src/haptic.cpp +++ b/src/haptic.cpp @@ -37,9 +37,10 @@ class Haptic::Impl { public: - Impl(const Mode& mode): + Impl(const Mode& mode, bool repeat): m_mode(mode), - m_cancellable(g_cancellable_new()) + m_cancellable(g_cancellable_new()), + m_repeat(repeat) { g_bus_get (G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this); } @@ -93,11 +94,15 @@ private: // one second on, one second off. m_pattern = std::vector({1000u, 1000u}); break; + } - // Set up a loop to keep repeating the pattern - auto msec = std::accumulate(m_pattern.begin(), m_pattern.end(), 0u); - m_tag = g_timeout_add(msec, call_vibrate_pattern_static, this); + if (m_repeat) + { + // Set up a loop to keep repeating the pattern + auto msec = std::accumulate(m_pattern.begin(), m_pattern.end(), 0u); + m_tag = g_timeout_add(msec, call_vibrate_pattern_static, this); + } call_vibrate_pattern(); } @@ -146,14 +151,15 @@ private: GDBusConnection * m_bus = nullptr; std::vector m_pattern; guint m_tag = 0; + bool m_repeat = false; }; /*** **** ***/ -Haptic::Haptic(const Mode& mode): - impl(new Impl (mode)) +Haptic::Haptic(const Mode& mode, bool repeat): + impl(new Impl (mode, repeat)) { } diff --git a/src/snap.cpp b/src/snap.cpp index 4736498..217b6df 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -117,7 +117,7 @@ public: if (should_vibrate()) { const auto haptic_mode = m_settings->alarm_haptic.get(); if (haptic_mode == "pulse") - haptic = std::make_shared(ain::Haptic::MODE_PULSE); + haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); } // show a notification... -- cgit v1.2.3 From 32db30a126d9d96de51a2a0fa8d6fa820dc8d341 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 26 Apr 2016 12:02:03 -0300 Subject: Fixed as reviewer requested. --- src/notifications.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 076ad13..f3dcb14 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -278,8 +278,9 @@ public: uuid_t message_uuid; uuid_generate(message_uuid); - char message_id[37]; - uuid_unparse(message_uuid, message_id); + char uuid_buf[37]; + uuid_unparse(message_uuid, uuid_buf); + const std::string message_id(uuid_buf); GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); @@ -287,7 +288,7 @@ public: if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); - auto msg = messaging_menu_message_new(message_id, + auto msg = messaging_menu_message_new(message_id.c_str(), icon, data.m_title.c_str(), nullptr, @@ -297,7 +298,7 @@ public: if (msg) { std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); - m_messaging_messages[std::string(message_id)] = msg_data; + m_messaging_messages[message_id] = msg_data; g_signal_connect(G_OBJECT(msg), "activate", G_CALLBACK(on_message_activated), msg_data.get()); messaging_menu_app_append_message(m_messaging_app.get(), msg, m_app_name.c_str(), false); -- cgit v1.2.3 From ba5a55ca476fef0fdb3a4f0bdd53fe771ea272c7 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 26 Apr 2016 15:34:30 -0300 Subject: Make use of G_USEC_PER_SEC. --- src/notifications.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index f3dcb14..f59a421 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -293,7 +293,7 @@ public: data.m_title.c_str(), nullptr, data.m_body.c_str(), - data.m_start_time * 1000000); // secs -> microsecs + data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs g_object_unref(icon); if (msg) { -- cgit v1.2.3 From 0cfd764abbb319aa994788e993267d75bb955ccd Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 26 Apr 2016 21:43:03 -0300 Subject: Update notifications to use the new calendar icon. --- src/snap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 217b6df..1e7dd5e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -124,7 +124,7 @@ public: const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); ain::Builder b; b.set_body (appointment.summary); - b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "appointment"); + b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "calendar"); b.add_hint (ain::Builder::HINT_NONSHAPED_ICON); b.set_start_time (appointment.begin.to_unix()); -- cgit v1.2.3 From ec226fce51ed4ba7f16c5f1d3f87c180c6335918 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 27 Apr 2016 14:01:28 -0300 Subject: Use calendar app icon. --- src/notifications.cpp | 41 +++++++++++++++++++++++++++++++++++++---- src/snap.cpp | 11 +++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index f59a421..dc42534 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -24,9 +24,14 @@ #include #include +#ifdef HAS_LOMIRIAPPLAUNCH +#include +#endif #include +#include + #include #include #include @@ -145,7 +150,7 @@ class Engine::Impl public: Impl(const std::string& app_name): - m_messaging_app(messaging_menu_app_new(DATETIME_INDICATOR_DESKTOP_FILE), g_object_unref), + m_messaging_app(messaging_menu_app_new(calendar_app_id().c_str()), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) @@ -282,11 +287,15 @@ public: uuid_unparse(message_uuid, uuid_buf); const std::string message_id(uuid_buf); - GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); + // use full icon path name, "calendar-app" does not work with themed icons + auto icon_file = g_file_new_for_path(calendar_app_icon().c_str()); + // messaging_menu_message_new: will take control of icon object + GIcon *icon = g_file_icon_new(icon_file); + g_object_unref(icon_file); // check if source exists if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str())) - messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), nullptr, "Calendar"); auto msg = messaging_menu_message_new(message_id.c_str(), icon, @@ -294,7 +303,6 @@ public: nullptr, data.m_body.c_str(), data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs - g_object_unref(icon); if (msg) { std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); @@ -427,6 +435,31 @@ private: m_notifications.erase(it); } + static std::string calendar_app_id() + { + #ifdef HAS_LOMIRIAPPLAUNCH + auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); + return std::string(app_id) + ".desktop"; + #else + return ""; + #endif + } + + static std::string calendar_app_icon() + { + auto app_desktop = g_desktop_app_info_new(calendar_app_id().c_str()); + if (app_desktop != nullptr) { + auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon"); + g_object_unref(app_desktop); + std::string result(icon_name); + g_free(icon_name); + return result; + } else { + g_warning("Fail to get calendar icon"); + return std::string(); + } + } + /*** **** ***/ diff --git a/src/snap.cpp b/src/snap.cpp index 1e7dd5e..60005f3 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -124,7 +124,7 @@ public: const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); ain::Builder b; b.set_body (appointment.summary); - b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "calendar"); + b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "calendar-app"); b.add_hint (ain::Builder::HINT_NONSHAPED_ICON); b.set_start_time (appointment.begin.to_unix()); @@ -171,9 +171,12 @@ public: ok(appointment, alarm); }); - b.set_missed_click_callback([appointment, alarm, ok](){ - ok(appointment, alarm); - }); + //TODO: we need to extend it to support alarms appoitments + if (!appointment.is_ubuntu_alarm()) { + b.set_missed_click_callback([appointment, alarm, ok](){ + ok(appointment, alarm); + }); + } const auto key = m_engine->show(b); if (key) -- cgit v1.2.3 From 76e3bd94724e9bc7bedd24548103e31d85334d53 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 27 Apr 2016 14:31:28 -0300 Subject: Only creates messaging menu if calendar app is instaled. Update tests. --- src/notifications.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index dc42534..9817686 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -150,14 +150,17 @@ class Engine::Impl public: Impl(const std::string& app_name): - m_messaging_app(messaging_menu_app_new(calendar_app_id().c_str()), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); // messaging menu - messaging_menu_app_register(m_messaging_app.get()); + auto app_id = calendar_app_id(); + if (!app_id.empty()) { + m_messaging_app.reset(messaging_menu_app_new(app_id.c_str()), g_object_unref); + messaging_menu_app_register(m_messaging_app.get()); + } } ~Impl() @@ -166,7 +169,8 @@ public: remove_all (); notify_uninit (); - messaging_menu_app_unregister (m_messaging_app.get()); + if (m_messaging_app) + messaging_menu_app_unregister (m_messaging_app.get()); } const std::string& app_name() const @@ -280,6 +284,9 @@ public: std::string post(const Builder::Impl& data) { + if (!m_messaging_app) { + return std::string(); + } uuid_t message_uuid; uuid_generate(message_uuid); @@ -439,9 +446,14 @@ private: { #ifdef HAS_LOMIRIAPPLAUNCH auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); - return std::string(app_id) + ".desktop"; + + if (!app_id.empty()) + return std::string(app_id) + ".desktop"; + else + return std::string(); + #else - return ""; + return std::string(); #endif } -- cgit v1.2.3 From 846dfb9d7b16aec7923444083256a8565f308013 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 28 Apr 2016 09:35:05 -0300 Subject: Small fixes requeted by charles during the review. --- src/main.cpp | 1 - src/notifications.cpp | 39 +++++++++++++++++---------------------- src/snap.cpp | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index f9a934a..729f0e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,7 +157,6 @@ main(int /*argc*/, char** /*argv*/) snooze_planner->add(appointment, alarm); }; auto on_ok = [actions](const Appointment& app, const Alarm&){ - //TODO: add support for desktop actions->phone_open_appointment(app, app.begin); }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { diff --git a/src/notifications.cpp b/src/notifications.cpp index 9817686..3c90e57 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -58,11 +58,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; - gint64 m_start_time; + gint64 m_start_time {}; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; - std::function m_missed_click_callback; + std::function m_timeout_callback; }; Builder::Builder(): @@ -117,9 +117,9 @@ Builder::set_closed_callback (std::function cb) } void -Builder::set_missed_click_callback (std::function cb) +Builder::set_timeout_callback (std::function cb) { - impl->m_missed_click_callback.swap (cb); + impl->m_timeout_callback.swap (cb); } void @@ -312,7 +312,7 @@ public: data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs if (msg) { - std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); + std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_timeout_callback, this}); m_messaging_messages[message_id] = msg_data; g_signal_connect(G_OBJECT(msg), "activate", G_CALLBACK(on_message_activated), msg_data.get()); @@ -344,13 +344,8 @@ public: void remove_all () { // call remove() on all our keys - - std::set keys; - for (const auto& it : m_messaging_messages) - keys.insert (it.first); - - for (const std::string &key : keys) - remove (key); + while (!m_messaging_messages.empty()) + remove(m_messaging_messages.begin()->first); } private: @@ -400,7 +395,7 @@ private: gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); g_return_if_fail (it != msg_data->self->m_messaging_messages.end()); const auto& ndata = it->second; @@ -411,7 +406,7 @@ private: static void on_message_destroyed(gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); if (it != msg_data->self->m_messaging_messages.end()) msg_data->self->m_messaging_messages.erase(it); } @@ -448,6 +443,7 @@ private: auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); if (!app_id.empty()) + // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. return std::string(app_id) + ".desktop"; else return std::string(); @@ -463,13 +459,14 @@ private: if (app_desktop != nullptr) { auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon"); g_object_unref(app_desktop); - std::string result(icon_name); - g_free(icon_name); - return result; - } else { - g_warning("Fail to get calendar icon"); - return std::string(); + if (icon_name) { + std::string result(icon_name); + g_free(icon_name); + return result; + } } + g_warning("Fail to get calendar icon"); + return std::string(); } /*** @@ -490,8 +487,6 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; - static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; - static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** diff --git a/src/snap.cpp b/src/snap.cpp index 60005f3..4078dd7 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -173,7 +173,7 @@ public: //TODO: we need to extend it to support alarms appoitments if (!appointment.is_ubuntu_alarm()) { - b.set_missed_click_callback([appointment, alarm, ok](){ + b.set_timeout_callback([appointment, alarm, ok](){ ok(appointment, alarm); }); } -- cgit v1.2.3 From 85cb430bd147719fed43f4ccf04b9d22cad33bfc Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 28 Apr 2016 11:56:11 -0300 Subject: Detect desktop to launch applications. --- src/CMakeLists.txt | 2 +- src/actions-live.cpp | 126 ++++++++++++++++++--------------------------------- src/actions.cpp | 64 ++++++++------------------ src/main.cpp | 2 +- 4 files changed, 67 insertions(+), 127 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96284fb..823a9b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,5 +70,5 @@ link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) add_executable (${SERVICE_EXEC} main.cpp) set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") -target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS} ${URLDISPATCHER_LIBRARIES}) +target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS}) install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}) diff --git a/src/actions-live.cpp b/src/actions-live.cpp index e3237b7..11643cd 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -20,14 +20,15 @@ #include #include -#ifdef HAS_URLDISPATCHER -#include -#endif - #include #include +extern "C" +{ + #include +} + namespace ayatana { namespace indicator { namespace datetime { @@ -41,53 +42,55 @@ LiveActions::LiveActions(const std::shared_ptr& state_in): { } -void LiveActions::execute_command(const std::string& cmdstr) -{ - const auto cmd = cmdstr.c_str(); - g_debug("Issuing command '%s'", cmd); +/*** +**** +***/ - GError* error = nullptr; - if (!g_spawn_command_line_async(cmd, &error)) +void LiveActions::open_alarm_app() +{ + if (ayatana_common_utils_is_lomiri()) { - g_warning("Unable to start \"%s\": %s", cmd, error->message); - g_error_free(error); + ayatana_common_utils_open_url("appid://com.lomiri.clock/clock/current-user-version"); + } + else + { + ayatana_common_utils_execute_command("evolution -c calendar"); } } -void LiveActions::dispatch_url(const std::string& url) +void LiveActions::open_calendar_app(const DateTime& dt) { - g_debug("Dispatching url '%s'", url.c_str()); -#ifdef HAS_URLDISPATCHER - lomiri_url_dispatch_send(url.c_str(), nullptr, nullptr); -#else - // FIXME: Deal with this, if we build without liburl-dispatcher... -#endif + if (ayatana_common_utils_is_lomiri()) + { + const auto utc = dt.to_timezone("UTC"); + auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); + ayatana_common_utils_open_url(cmd.c_str()); + } + else + { + const auto utc = dt.start_of_day().to_timezone("UTC"); + auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); + ayatana_common_utils_execute_command(cmd.c_str()); + } } -/*** -**** -***/ - -void LiveActions::desktop_open_settings_app() +void LiveActions::open_settings_app() { - if (g_getenv ("MIR_SOCKET") != nullptr) + if (ayatana_common_utils_is_lomiri()) + { + ayatana_common_utils_open_url("settings:///system/time-date"); + } + else if (ayatana_common_utils_is_unity()) { - dispatch_url("settings:///system/time-date"); + ayatana_common_utils_execute_command("unity-control-center datetime"); + } + else if (ayatana_common_utils_is_mate()) + { + ayatana_common_utils_execute_command("mate-time-admin"); } else { - if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)) - { - execute_command("unity-control-center datetime"); - } - else if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "MATE") == 0)) - { - execute_command("mate-time-admin"); - } - else - { - execute_command("gnome-control-center datetime"); - } + ayatana_common_utils_execute_command("gnome-control-center datetime"); } } @@ -123,64 +126,25 @@ bool LiveActions::desktop_has_calendar_app() const return have_calendar; } -void LiveActions::desktop_open_alarm_app() -{ - execute_command("evolution -c calendar"); -} - -void LiveActions::desktop_open_appointment(const Appointment&, const DateTime& date) -{ - desktop_open_calendar_app(date); -} - -void LiveActions::desktop_open_calendar_app(const DateTime& dt) -{ - const auto utc = dt.start_of_day().to_timezone("UTC"); - auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - execute_command(cmd.c_str()); -} - -/*** -**** -***/ - -void LiveActions::phone_open_alarm_app() -{ - dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); -} - -void LiveActions::phone_open_appointment(const Appointment& appt, const DateTime& date) +void LiveActions::open_appointment(const Appointment& appt, const DateTime& date) { - if (!appt.activation_url.empty()) { - dispatch_url(appt.activation_url); + ayatana_common_utils_open_url(appt.activation_url.c_str()); } else switch (appt.type) { case Appointment::UBUNTU_ALARM: - phone_open_alarm_app(); + open_alarm_app(); break; case Appointment::EVENT: default: - phone_open_calendar_app(date); + open_calendar_app(date); break; } } -void LiveActions::phone_open_calendar_app(const DateTime& dt) -{ - const auto utc = dt.to_timezone("UTC"); - auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - dispatch_url(cmd); -} - -void LiveActions::phone_open_settings_app() -{ - dispatch_url("settings:///system/time-date"); -} - /*** **** ***/ diff --git a/src/actions.cpp b/src/actions.cpp index ea68d3e..315340a 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -62,7 +62,7 @@ bool lookup_appointment_by_uid(const std::shared_ptr& state, const gchar* return false; } -void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) +void on_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) { auto self = static_cast(gself); Appointment appt; @@ -70,44 +70,20 @@ void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gint64 time = 0; g_variant_get(vdata, "(&sx)", &uid, &time); if (lookup_appointment_by_uid(self->state(), uid, appt)) - self->desktop_open_appointment(appt, DateTime::Local(time)); + self->open_appointment(appt, DateTime::Local(time)); } -void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) +void on_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) { - static_cast(gself)->desktop_open_alarm_app(); + static_cast(gself)->open_alarm_app(); } -void on_desktop_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) +void on_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) { const auto dt = datetime_from_timet_variant(vt); - static_cast(gself)->desktop_open_calendar_app(dt); + static_cast(gself)->open_calendar_app(dt); } -void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) +void on_settings_activated (GSimpleAction*, GVariant*, gpointer gself) { - static_cast(gself)->desktop_open_settings_app(); -} - -void on_phone_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) -{ - auto self = static_cast(gself); - Appointment appt; - const gchar* uid = nullptr; - gint64 time = 0; - g_variant_get(vdata, "(&sx)", &uid, &time); - if (lookup_appointment_by_uid(self->state(), uid, appt)) - self->phone_open_appointment(appt, DateTime::Local(time)); -} -void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast(gself)->phone_open_alarm_app(); -} -void on_phone_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) -{ - const auto dt = datetime_from_timet_variant(vt); - static_cast(gself)->phone_open_calendar_app(dt); -} -void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast(gself)->phone_open_settings_app(); + static_cast(gself)->open_settings_app(); } void on_set_location(GSimpleAction * /*action*/, @@ -135,9 +111,9 @@ void on_calendar_active_changed(GSimpleAction * /*action*/, } } -void on_calendar_activated(GSimpleAction * /*action*/, - GVariant * state, - gpointer gself) +void on_calendar_date_activated(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) { const time_t t = g_variant_get_int64(state); @@ -199,15 +175,15 @@ Actions::Actions(const std::shared_ptr& state): { GActionEntry entries[] = { - { "desktop.open-appointment", on_desktop_appointment_activated, "(sx)", nullptr }, - { "desktop.open-alarm-app", on_desktop_alarm_activated }, - { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr }, - { "desktop.open-settings-app", on_desktop_settings_activated }, + { "desktop.open-appointment", on_appointment_activated, "(sx)", nullptr }, + { "desktop.open-alarm-app", on_alarm_activated }, + { "desktop.open-calendar-app", on_calendar_activated, "x", nullptr }, + { "desktop.open-settings-app", on_settings_activated }, - { "phone.open-appointment", on_phone_appointment_activated, "(sx)", nullptr }, - { "phone.open-alarm-app", on_phone_alarm_activated }, - { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr }, - { "phone.open-settings-app", on_phone_settings_activated }, + { "phone.open-appointment", on_appointment_activated, "(sx)", nullptr }, + { "phone.open-alarm-app", on_alarm_activated }, + { "phone.open-calendar-app", on_calendar_activated, "x", nullptr }, + { "phone.open-settings-app", on_settings_activated }, { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } @@ -241,7 +217,7 @@ Actions::Actions(const std::shared_ptr& state): v = create_calendar_state(state); a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v); g_action_map_add_action(gam, G_ACTION(a)); - g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this); + g_signal_connect(a, "activate", G_CALLBACK(on_calendar_date_activated), this); g_object_unref(a); /// diff --git a/src/main.cpp b/src/main.cpp index 729f0e5..034a5ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,7 +157,7 @@ main(int /*argc*/, char** /*argv*/) snooze_planner->add(appointment, alarm); }; auto on_ok = [actions](const Appointment& app, const Alarm&){ - actions->phone_open_appointment(app, app.begin); + actions->open_appointment(app, app.begin); }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { (*snap)(appointment, alarm, on_snooze, on_ok); -- cgit v1.2.3 From 8c7997ad86cffd8fb0b1578e2bc632395744d0b8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 14 May 2016 12:18:45 -0500 Subject: add a new Snap::Response enum for more flexible handling of snap decisions --- src/main.cpp | 21 ++++++++++++++------- src/snap.cpp | 39 +++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 034a5ef..9defed0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,14 +153,21 @@ main(int /*argc*/, char** /*argv*/) auto notification_engine = std::make_shared("ayatana-indicator-datetime-service"); std::unique_ptr snap (new Snap(notification_engine, state->settings)); auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); - auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) { - snooze_planner->add(appointment, alarm); + auto sound_builder = std::make_shared(); + auto on_response = [snooze_planner, actions](const Appointment& appointment, const Alarm& alarm, const Snap::Response& response) { + switch(response) { + case Snap::Response::Snooze: + snooze_planner->add(appointment, alarm); + break; + case Snap::Response::ShowApp: + actions->open_appointment(appointment, appointment.begin); + break; + case Snap::Response::None: + break; + } }; - auto on_ok = [actions](const Appointment& app, const Alarm&){ - actions->open_appointment(app, app.begin); - }; - auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { - (*snap)(appointment, alarm, on_snooze, on_ok); + auto on_alarm_reached = [&engine, &snap, &on_response](const Appointment& appointment, const Alarm& alarm) { + (*snap)(appointment, alarm, on_response); engine->disable_ubuntu_alarm(appointment); }; alarm_queue->alarm_reached().connect(on_alarm_reached); diff --git a/src/snap.cpp b/src/snap.cpp index 4078dd7..51d04ae 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -81,8 +81,7 @@ public: void operator()(const Appointment& appointment, const Alarm& alarm, - appointment_func snooze, - appointment_func ok) + response_func on_response) { // If calendar notifications are muted, don't show them if (!appointment.is_ubuntu_alarm() && calendar_events_are_muted()) { @@ -153,28 +152,33 @@ public: if (interactive) { b.add_hint (ain::Builder::HINT_SNAP); b.add_hint (ain::Builder::HINT_AFFIRMATIVE_HINT); - b.add_action ("ok", _("OK")); - b.add_action ("snooze", _("Snooze")); + b.add_action (ACTION_NONE, _("OK")); + b.add_action (ACTION_SNOOZE, _("Snooze")); } else { b.add_hint (ain::Builder::HINT_INTERACTIVE); - b.add_action ("ok", _("OK")); + b.add_action (ACTION_SHOW_APP, _("OK")); } // add 'sound', 'haptic', and 'awake' objects to the capture so // they stay alive until the closed callback is called; i.e., // for the lifespan of the notficiation - b.set_closed_callback([appointment, alarm, snooze, ok, sound, awake, haptic] + b.set_closed_callback([appointment, alarm, on_response, sound, awake, haptic] (const std::string& action){ - if (action == "snooze") - snooze(appointment, alarm); - else if (action == "ok") - ok(appointment, alarm); + Snap::Response response; + if (action == ACTION_SNOOZE) + response = Snap::Response::Snooze; + else if (action == ACTION_SHOW_APP) + response = Snap::Response::ShowApp; + else + response = Snap::Response::None; + + on_response(appointment, alarm, response); }); - //TODO: we need to extend it to support alarms appoitments + //TODO: we need to extend it to support alarms appointments if (!appointment.is_ubuntu_alarm()) { - b.set_timeout_callback([appointment, alarm, ok](){ - ok(appointment, alarm); + b.set_timeout_callback([appointment, alarm, on_response](){ + on_response(appointment, alarm, Snap::Response::ShowApp); }); } @@ -267,6 +271,10 @@ private: std::set m_notifications; GCancellable * m_cancellable {nullptr}; AccountsServiceSound * m_accounts_service_sound_proxy {nullptr}; + + static constexpr char const * ACTION_NONE {"none"}; + static constexpr char const * ACTION_SNOOZE {"snooze"}; + static constexpr char const * ACTION_SHOW_APP {"show-app"}; }; /*** @@ -286,10 +294,9 @@ Snap::~Snap() void Snap::operator()(const Appointment& appointment, const Alarm& alarm, - appointment_func show, - appointment_func ok) + response_func on_response) { - (*impl)(appointment, alarm, show, ok); + (*impl)(appointment, alarm, on_response); } /*** -- cgit v1.2.3 From 2098623e0db448eed4801acc05a54d17734e2cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Thu, 16 Jun 2016 18:55:27 +0200 Subject: re-enable the calendar component in phone mode too --- src/menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/menu.cpp b/src/menu.cpp index f9b6485..b1ac75c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -319,7 +319,7 @@ private: GMenuModel* create_calendar_section(Profile profile) { const bool show_calendar = m_state->settings->show_calendar.get() && - ((profile == Desktop) || (profile == DesktopGreeter)); + ((profile == Desktop) || (profile == DesktopGreeter) || (profile == Phone)); auto menu = g_menu_new(); const char * action_name; @@ -464,7 +464,7 @@ private: const auto now = m_state->clock->localtime(); - if (profile == Desktop) + if (profile == Desktop || profile == Phone) { for(const auto& location : m_state->locations->locations.get()) { -- cgit v1.2.3 From 9c7c869ae51fffe7ce560faf0d3d2cecf5743563 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 22 Jun 2016 15:37:55 -0300 Subject: Update indicator-datetime to work with the new notification settings --- src/settings-live.cpp | 115 ++++++++++++++++++++++++++++++-------------------- src/snap.cpp | 45 +++++++++++++------- 2 files changed, 99 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 6504d7d..f908c05 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -34,7 +34,7 @@ namespace datetime { LiveSettings::~LiveSettings() { - g_clear_object(&m_settings_cunh); + g_clear_object(&m_settings_cal_notification); g_clear_object(&m_settings); } @@ -44,8 +44,8 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) if (ayatana_common_utils_is_lomiri()) { - m_settings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); - g_signal_connect (m_settings_cunh, "changed", G_CALLBACK(on_changed_cunh), this); + m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); } // init the Properties from the GSettings backend @@ -68,7 +68,11 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); - update_muted_apps(); + update_cal_notification_enabled(); + update_cal_notification_sounds(); + update_cal_notification_vibrations(); + update_cal_notification_bubbles(); + update_cal_notification_list(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -76,20 +80,6 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str()); }); - if (ayatana_common_utils_is_lomiri()) - { - muted_apps.changed().connect([this](const std::set>& value){ - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); - for(const auto& app : value){ - const std::string& pkgname {app.first}; - const std::string& appname {app.second}; - g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str()); - } - g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder)); - }); - } - locations.changed().connect([this](const std::vector& value){ const int n = value.size(); gchar** strv = g_new0(gchar*, n+1); @@ -166,6 +156,26 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) snooze_duration.changed().connect([this](unsigned int value){ g_settings_set_uint(m_settings, SETTINGS_SNOOZE_DURATION_S, value); }); + + cal_notification_enabled.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY, value); + }); + + cal_notification_sounds.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY, value); + }); + + cal_notification_vibrations.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY, value); + }); + + cal_notification_bubbles.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY, value); + }); + + cal_notification_list.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY, value); + }); } /*** @@ -189,27 +199,6 @@ void LiveSettings::update_locations() locations.set(l); } -void LiveSettings::update_muted_apps() -{ - if (ayatana_common_utils_is_lomiri()) - { - std::set> apps; - - auto blacklist = g_settings_get_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S); - GVariantIter* iter {nullptr}; - g_variant_get (blacklist, "a(ss)", &iter); - gchar* pkgname; - gchar* appname; - while (g_variant_iter_loop (iter, "(ss)", &pkgname, &appname)) { - apps.insert(std::make_pair(pkgname,appname)); - } - g_variant_iter_free (iter); - g_clear_pointer(&blacklist, g_variant_unref); - - muted_apps.set(apps); - } -} - void LiveSettings::update_show_calendar() { const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S); @@ -308,21 +297,55 @@ void LiveSettings::update_snooze_duration() snooze_duration.set(g_settings_get_uint(m_settings, SETTINGS_SNOOZE_DURATION_S)); } +void LiveSettings::update_cal_notification_enabled() +{ + cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); +} + +void LiveSettings::update_cal_notification_sounds() +{ + cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); +} + +void LiveSettings::update_cal_notification_vibrations() +{ + cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); +} + +void LiveSettings::update_cal_notification_bubbles() +{ + cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); +} + +void LiveSettings::update_cal_notification_list() +{ + cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); +} + /*** **** ***/ -void LiveSettings::on_changed_cunh(GSettings* /*settings*/, - gchar* key, - gpointer gself) +void LiveSettings::on_changed_cal_notification(GSettings* /*settings*/, + gchar* key, + gpointer gself) { - static_cast(gself)->update_key_cunh(key); + static_cast(gself)->update_key_cal_notification(key); } -void LiveSettings::update_key_cunh(const std::string& key) + +void LiveSettings::update_key_cal_notification(const std::string& key) { - if (key == SETTINGS_CUNH_BLACKLIST_S) - update_muted_apps(); + if (key == SETTINGS_NOTIFY_ENABLED_KEY) + update_cal_notification_enabled(); + else if (key == SETTINGS_NOTIFY_SOUNDS_KEY) + update_cal_notification_sounds(); + else if (key == SETTINGS_NOTIFY_VIBRATIONS_KEY) + update_cal_notification_vibrations(); + else if (key == SETTINGS_NOTIFY_BUBBLES_KEY) + update_cal_notification_bubbles(); + else if (key == SETTINGS_NOTIFY_LIST_KEY) + update_cal_notification_list(); } /*** diff --git a/src/snap.cpp b/src/snap.cpp index 51d04ae..1e71e7b 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -83,9 +83,9 @@ public: const Alarm& alarm, response_func on_response) { - // If calendar notifications are muted, don't show them - if (!appointment.is_ubuntu_alarm() && calendar_events_are_muted()) { - g_debug("Skipping muted calendar event '%s' notification", appointment.summary.c_str()); + // If calendar notifications are disabled, don't show them + if (!appointment.is_ubuntu_alarm() && !calendar_notifications_are_enabled()) { + g_debug("Skipping disabled calendar event '%s' notification", appointment.summary.c_str()); return; } @@ -96,13 +96,14 @@ public: const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions(); // force the system to stay awake - auto awake = std::make_shared(m_engine->app_name()); + std::shared_ptr awake; + if (calendar_bubbles_enabled()) { + awake = std::make_shared(m_engine->app_name()); + } // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - // FIXME: only play sounds for alarms for now, we should itegrate it with - // system settings to decide if we should play sounds for calendar notification or not - if (appointment.is_ubuntu_alarm()) { + if (appointment.is_ubuntu_alarm() || calendar_sounds_enabled()) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); @@ -113,7 +114,7 @@ public: // create the haptic feedback... std::shared_ptr haptic; - if (should_vibrate()) { + if (should_vibrate() && calendar_vibrations_enabled()) { const auto haptic_mode = m_settings->alarm_haptic.get(); if (haptic_mode == "pulse") haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); @@ -189,15 +190,29 @@ public: private: - bool calendar_events_are_muted() const + bool calendar_notifications_are_enabled() const { - for(const auto& app : m_settings->muted_apps.get()) { - if (app.first == "com.ubuntu.calendar") { - return true; - } - } + return m_settings->cal_notification_enabled.get(); + } + + bool calendar_sounds_enabled() const + { + return m_settings->cal_notification_sounds.get(); + } - return false; + bool calendar_vibrations_enabled() const + { + return m_settings->cal_notification_vibrations.get(); + } + + bool calendar_bubbles_enabled() const + { + return m_settings->cal_notification_bubbles.get(); + } + + bool calendar_list_enabled() const + { + return m_settings->cal_notification_list.get(); } static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) -- cgit v1.2.3 From 033735a671e29307271f0a900b8b10090f28f153 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Thu, 23 Jun 2016 16:04:50 -0300 Subject: Set calendar notification settings to true in case GSettings schema is not available Make sure calendar notification settings are correct during tests --- src/settings-live.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index f908c05..39d8e18 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -299,27 +299,47 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); + if (m_settings_cal_notification) { + cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); + } else { + cal_notification_enabled.set(true); + } } void LiveSettings::update_cal_notification_sounds() { - cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); + if (m_settings_cal_notification) { + cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); + } else { + cal_notification_sounds.set(true); + } } void LiveSettings::update_cal_notification_vibrations() { - cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); + if (m_settings_cal_notification) { + cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); + } else { + cal_notification_vibrations.set(true); + } } void LiveSettings::update_cal_notification_bubbles() { - cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); + if (m_settings_cal_notification) { + cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); + } else { + cal_notification_bubbles.set(true); + } } void LiveSettings::update_cal_notification_list() { - cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); + if (m_settings_cal_notification) { + cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); + } else { + cal_notification_list.set(true); + } } /*** -- cgit v1.2.3 From c0f53270674c6dbfe2eadf38e999c2536c4af4e3 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 09:26:06 -0300 Subject: Make sure that calendar settings do not affect alarm notifications --- src/snap.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 1e71e7b..273f125 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -97,8 +97,8 @@ public: // force the system to stay awake std::shared_ptr awake; - if (calendar_bubbles_enabled()) { - awake = std::make_shared(m_engine->app_name()); + if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()) { + awake = std::make_shared(m_engine->app_name()); } // calendar events are muted in silent mode; alarm clocks never are @@ -114,7 +114,7 @@ public: // create the haptic feedback... std::shared_ptr haptic; - if (should_vibrate() && calendar_vibrations_enabled()) { + if (should_vibrate() && (appointment.is_ubuntu_alarm() || calendar_vibrations_enabled())) { const auto haptic_mode = m_settings->alarm_haptic.get(); if (haptic_mode == "pulse") haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); -- cgit v1.2.3 From 2203d0b2031b7dc99fe7381a9efac431bc3ad410 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 11:45:30 -0300 Subject: Do not fail tests if schema is not installed --- src/settings-live.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 39d8e18..17c0ef7 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -38,14 +38,20 @@ LiveSettings::~LiveSettings() g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_gsettings_cal_notification(NULL) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); if (ayatana_common_utils_is_lomiri()) { - m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + GSettingsSchemaSource *source = g_settings_schema_source_get_default(); + if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } + + if (m_gsettings_cal_notification) { + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + } } // init the Properties from the GSettings backend -- cgit v1.2.3 From 6a78e3849eadf536e526b9f49613881ef1bc7cdb Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 11:49:11 -0300 Subject: Fix typo --- src/settings-live.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 17c0ef7..d1ea91b 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -38,7 +38,7 @@ LiveSettings::~LiveSettings() g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_gsettings_cal_notification(NULL) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_settings_cal_notification(NULL) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); @@ -46,10 +46,10 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_ { GSettingsSchemaSource *source = g_settings_schema_source_get_default(); if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); } - if (m_gsettings_cal_notification) { + if (m_settings_cal_notification) { g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); } } -- cgit v1.2.3 From e23f7c25c0e6558d529239db1b034e66220f8d27 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 16:55:50 -0300 Subject: Fix settings test check so we do not fail if GSettings schema is missing --- src/settings-live.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index d1ea91b..8060a08 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -305,7 +305,7 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); } else { cal_notification_enabled.set(true); @@ -314,7 +314,7 @@ void LiveSettings::update_cal_notification_enabled() void LiveSettings::update_cal_notification_sounds() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); } else { cal_notification_sounds.set(true); @@ -323,7 +323,7 @@ void LiveSettings::update_cal_notification_sounds() void LiveSettings::update_cal_notification_vibrations() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); } else { cal_notification_vibrations.set(true); @@ -332,7 +332,7 @@ void LiveSettings::update_cal_notification_vibrations() void LiveSettings::update_cal_notification_bubbles() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); } else { cal_notification_bubbles.set(true); @@ -341,7 +341,7 @@ void LiveSettings::update_cal_notification_bubbles() void LiveSettings::update_cal_notification_list() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } else { cal_notification_list.set(true); -- cgit v1.2.3 From 1893e15b2ccb06b72df6bbd522ba8707eccedac1 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 29 Jun 2016 21:31:01 -0300 Subject: Undo revisions 456/457 --- src/settings-live.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 8060a08..d1ea91b 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -305,7 +305,7 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); } else { cal_notification_enabled.set(true); @@ -314,7 +314,7 @@ void LiveSettings::update_cal_notification_enabled() void LiveSettings::update_cal_notification_sounds() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); } else { cal_notification_sounds.set(true); @@ -323,7 +323,7 @@ void LiveSettings::update_cal_notification_sounds() void LiveSettings::update_cal_notification_vibrations() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); } else { cal_notification_vibrations.set(true); @@ -332,7 +332,7 @@ void LiveSettings::update_cal_notification_vibrations() void LiveSettings::update_cal_notification_bubbles() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); } else { cal_notification_bubbles.set(true); @@ -341,7 +341,7 @@ void LiveSettings::update_cal_notification_bubbles() void LiveSettings::update_cal_notification_list() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } else { cal_notification_list.set(true); -- cgit v1.2.3 From fb29c9e706c143e38726ea057fdb754a8e30c2aa Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 29 Jun 2016 21:37:56 -0300 Subject: Fix notifications so it respects if it should or not show bubbles or add to notification list --- src/notifications.cpp | 23 +++++++++++++++++++++++ src/snap.cpp | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 3c90e57..4a2c846 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -63,6 +63,8 @@ public: std::vector> m_actions; std::function m_closed_callback; std::function m_timeout_callback; + bool m_show_notification_bubble; + bool m_post_to_messaging_menu; }; Builder::Builder(): @@ -128,6 +130,18 @@ Builder::set_start_time (uint64_t time) impl->m_start_time = time; } +void +Builder::set_show_notification_bubble (bool show) +{ + impl->m_show_notification_bubble = show; +} + +void +Builder::set_post_to_messaging_menu (bool post) +{ + impl->m_post_to_messaging_menu = post; +} + /*** **** ***/ @@ -265,6 +279,11 @@ public: g_signal_connect (nn.get(), "closed", G_CALLBACK(on_notification_closed), this); + if (!info.m_show_notification_bubble) { + post(info); + return ret; + } + GError * error = nullptr; if (notify_notification_show(nn.get(), &error)) { @@ -284,6 +303,10 @@ public: std::string post(const Builder::Impl& data) { + if (!data.m_post_to_messaging_menu) { + return ""; + } + if (!m_messaging_app) { return std::string(); } diff --git a/src/snap.cpp b/src/snap.cpp index 273f125..1b7c183 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -96,10 +96,7 @@ public: const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions(); // force the system to stay awake - std::shared_ptr awake; - if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()) { - awake = std::make_shared(m_engine->app_name()); - } + std::shared_ptr awake = std::make_shared(m_engine->app_name()); // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; @@ -183,6 +180,9 @@ public: }); } + b.set_show_notification_bubble(appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()); + b.set_post_to_messaging_menu(appointment.is_ubuntu_alarm() || calendar_list_enabled()); + const auto key = m_engine->show(b); if (key) m_notifications.insert (key); -- cgit v1.2.3 From 559730101e171a821f9bb75c0e90cc9b19c60023 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 1 Jul 2016 16:35:21 -0300 Subject: Do not fail gracefully if gsettings schema is not installed --- src/settings-live.cpp | 45 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index d1ea91b..01de7b8 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -38,21 +38,10 @@ LiveSettings::~LiveSettings() g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_settings_cal_notification(NULL) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); - - if (ayatana_common_utils_is_lomiri()) - { - GSettingsSchemaSource *source = g_settings_schema_source_get_default(); - if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { - m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - } - - if (m_settings_cal_notification) { - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); - } - } + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); // init the Properties from the GSettings backend update_custom_time_format(); @@ -305,47 +294,27 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - if (m_settings_cal_notification) { - cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); - } else { - cal_notification_enabled.set(true); - } + cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); } void LiveSettings::update_cal_notification_sounds() { - if (m_settings_cal_notification) { - cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); - } else { - cal_notification_sounds.set(true); - } + cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); } void LiveSettings::update_cal_notification_vibrations() { - if (m_settings_cal_notification) { - cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); - } else { - cal_notification_vibrations.set(true); - } + cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); } void LiveSettings::update_cal_notification_bubbles() { - if (m_settings_cal_notification) { - cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); - } else { - cal_notification_bubbles.set(true); - } + cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); } void LiveSettings::update_cal_notification_list() { - if (m_settings_cal_notification) { - cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); - } else { - cal_notification_list.set(true); - } + cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } /*** -- cgit v1.2.3 From 46b0ac44948f06f37d93886996e21c0ed9e014cd Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 1 Jul 2016 18:26:46 -0300 Subject: Only wake device if bubbles notifications are enabled --- src/snap.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 1b7c183..d0c12a0 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -96,7 +96,10 @@ public: const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions(); // force the system to stay awake - std::shared_ptr awake = std::make_shared(m_engine->app_name()); + std::shared_ptr awake; + if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()) { + awake = std::make_shared(m_engine->app_name()); + } // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; -- cgit v1.2.3 From d61975b6145c245bf8df5322942395b101ca57c9 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Mon, 4 Jul 2016 16:30:18 -0300 Subject: If in silent mode should only vibrate if the settings say so --- src/settings-live.cpp | 38 +++++++++++++++++++++++++++++++++++--- src/snap.cpp | 20 ++++++++++++++------ 2 files changed, 49 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 01de7b8..66590e0 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -34,14 +34,19 @@ namespace datetime { LiveSettings::~LiveSettings() { + g_clear_object(&m_settings_general_notification); g_clear_object(&m_settings_cal_notification); g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)) +LiveSettings::LiveSettings(): + m_settings(g_settings_new(SETTINGS_INTERFACE)), + m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)), + m_settings_general_notification(g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID)) { - g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); // init the Properties from the GSettings backend update_custom_time_format(); @@ -68,6 +73,7 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_ update_cal_notification_vibrations(); update_cal_notification_bubbles(); update_cal_notification_list(); + update_vibrate_silent_mode(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -171,6 +177,10 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_ cal_notification_list.changed().connect([this](bool value){ g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY, value); }); + + vibrate_silent_mode.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY, value); + }); } /*** @@ -317,6 +327,11 @@ void LiveSettings::update_cal_notification_list() cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } +void LiveSettings::update_vibrate_silent_mode() +{ + vibrate_silent_mode.set(g_settings_get_boolean(m_settings_general_notification, SETTINGS_VIBRATE_SILENT_KEY)); +} + /*** **** ***/ @@ -347,6 +362,23 @@ void LiveSettings::update_key_cal_notification(const std::string& key) **** ***/ +void LiveSettings::on_changed_general_notification(GSettings* /*settings*/, + gchar* key, + gpointer gself) +{ + static_cast(gself)->update_key_general_notification(key); +} + +void LiveSettings::update_key_general_notification(const std::string& key) +{ + if (key == SETTINGS_VIBRATE_SILENT_KEY) + update_vibrate_silent_mode(); +} + +/*** +**** +***/ + void LiveSettings::on_changed_ccid(GSettings* /*settings*/, gchar* key, gpointer gself) diff --git a/src/snap.cpp b/src/snap.cpp index d0c12a0..363e0df 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -97,9 +97,9 @@ public: // force the system to stay awake std::shared_ptr awake; - if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled()) { - awake = std::make_shared(m_engine->app_name()); - } + if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled() || calendar_list_enabled()) { + awake = std::make_shared(m_engine->app_name()); + } // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; @@ -115,9 +115,12 @@ public: // create the haptic feedback... std::shared_ptr haptic; if (should_vibrate() && (appointment.is_ubuntu_alarm() || calendar_vibrations_enabled())) { - const auto haptic_mode = m_settings->alarm_haptic.get(); - if (haptic_mode == "pulse") - haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); + // when in silent mode should only vibrate if user defined so + if (!silent_mode() || vibrate_in_silent_mode_enabled()) { + const auto haptic_mode = m_settings->alarm_haptic.get(); + if (haptic_mode == "pulse") + haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); + } } // show a notification... @@ -218,6 +221,11 @@ private: return m_settings->cal_notification_list.get(); } + bool vibrate_in_silent_mode_enabled() const + { + return m_settings->vibrate_silent_mode.get(); + } + static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) { GError * error; -- cgit v1.2.3 From b4654663d3973bcbfd3a75c33d78220e55852fc7 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Mon, 4 Jul 2016 20:44:47 -0300 Subject: Should not use sounds notifications for calendar in silent mode --- src/snap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index 363e0df..c834f72 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -103,7 +103,7 @@ public: // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - if (appointment.is_ubuntu_alarm() || calendar_sounds_enabled()) { + if (appointment.is_ubuntu_alarm() || (calendar_sounds_enabled() && !silent_mode())) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); -- cgit v1.2.3 From 2425f66e98b3b1d201c5d2388611edb37be0ee7e Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Tue, 5 Jul 2016 16:42:21 -0300 Subject: Remove call to keepDisplayOn since that now is handled by Unity during Notifications --- src/awake.cpp | 107 ---------------------------------------------------------- 1 file changed, 107 deletions(-) (limited to 'src') diff --git a/src/awake.cpp b/src/awake.cpp index dd41c35..dc49436 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -48,16 +48,9 @@ public: g_cancellable_cancel (m_cancellable); g_object_unref (m_cancellable); - if (m_display_on_timer) - { - g_source_remove (m_display_on_timer); - m_display_on_timer = 0; - } - if (m_system_bus != nullptr) { unforce_awake (); - remove_display_on_request (); g_object_unref (m_system_bus); } } @@ -101,20 +94,6 @@ private: on_force_awake_response, self); - // ask unity-system-compositor to turn on the screen - g_dbus_connection_call (system_bus, - BUS_SCREEN_NAME, - BUS_SCREEN_PATH, - BUS_SCREEN_INTERFACE, - "keepDisplayOn", - nullptr, - G_VARIANT_TYPE("(i)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_keep_display_on_response, - self); - g_object_unref (system_bus); } } @@ -152,54 +131,6 @@ private: } } - static void on_keep_display_on_response (GObject * connection, - GAsyncResult * res, - gpointer gself) - { - GError * error; - GVariant * args; - - error = nullptr; - args = g_dbus_connection_call_finish (G_DBUS_CONNECTION(connection), - res, - &error); - if (error != nullptr) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && - !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) - { - g_warning ("Unable to turn on the screen: %s", error->message); - } - - g_error_free (error); - } - else - { - auto self = static_cast(gself); - - self->m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - g_variant_get (args, "(i)", &self->m_display_on_cookie); - g_debug ("m_display_on_cookie is now '%d'", self->m_display_on_cookie); - - self->m_display_on_timer = g_timeout_add_seconds (self->m_display_on_seconds, - on_display_on_timer, - gself); - - g_variant_unref (args); - } - } - - static gboolean on_display_on_timer (gpointer gself) - { - auto self = static_cast(gself); - - self->m_display_on_timer = 0; - self->remove_display_on_request(); - - return G_SOURCE_REMOVE; - } - - void unforce_awake () { g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); @@ -223,48 +154,10 @@ private: } } - void remove_display_on_request () - { - g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); - - if (m_display_on_cookie != NO_DISPLAY_ON_COOKIE) - { - g_dbus_connection_call (m_system_bus, - BUS_SCREEN_NAME, - BUS_SCREEN_PATH, - BUS_SCREEN_INTERFACE, - "removeDisplayOnRequest", - g_variant_new("(i)", m_display_on_cookie), - nullptr, - G_DBUS_CALL_FLAGS_NONE, - -1, - nullptr, - nullptr, - nullptr); - - m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - } - } - const std::string m_app_name; GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; char * m_awake_cookie = nullptr; - - /** - * As described by bug #1434637, alarms should have the display turn on, - * dim, and turn off "just like it would if you'd woken it up yourself". - * USC may be adding an intent-based bus API to handle this use case, - * e.g. turnDisplayOnTemporarily(intent), but there's no timeframe for it. - * - * Until that's avaialble, we can get close to Design's specs by - * requesting a display-on cookie and then releasing the cookie - * a moment later. */ - const guint m_display_on_seconds = 1; - guint m_display_on_timer = 0; - int32_t m_display_on_cookie = NO_DISPLAY_ON_COOKIE; - - static constexpr int32_t NO_DISPLAY_ON_COOKIE { std::numeric_limits::min() }; }; /*** -- cgit v1.2.3 From 7244cca7fbb45f9b67e53da46731e29b0c7bb620 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 21 Sep 2016 17:07:33 -0500 Subject: Use an explicit registry object so that it gets free'd when the function exits --- src/notifications.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 4a2c846..a0ceb6f 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -26,6 +26,7 @@ #ifdef HAS_LOMIRIAPPLAUNCH #include +#include #endif #include @@ -463,7 +464,8 @@ private: static std::string calendar_app_id() { #ifdef HAS_LOMIRIAPPLAUNCH - auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); + auto registry = std::make_shared(); + auto app_id = lomiri::app_launch::AppID::discover(registry, "com.lomiri.calendar"); if (!app_id.empty()) // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. -- cgit v1.2.3 From 14870108857877b8015bd0f12e2daae4085fa39f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Oct 2016 12:07:05 -0500 Subject: in Awake, remove an unnecessary async call by passing the system bus into the constructor instead of fetching it asynchronously --- src/awake.cpp | 66 ++++++++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/awake.cpp b/src/awake.cpp index dc49436..3bcd8ed 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -36,11 +36,26 @@ class Awake::Impl { public: - Impl(const std::string& app_name): + Impl(GDBusConnection* bus, const std::string& app_name): m_app_name(app_name), - m_cancellable(g_cancellable_new()) + m_cancellable(g_cancellable_new()), + m_system_bus{G_DBUS_CONNECTION(g_object_ref(bus))} { - g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, on_system_bus_ready, this); + // ask repowerd to keep the system awake + static constexpr int32_t POWERD_SYS_STATE_ACTIVE = 1; + g_dbus_connection_call (m_system_bus, + BUS_POWERD_NAME, + BUS_POWERD_PATH, + BUS_POWERD_INTERFACE, + "requestSysState", + g_variant_new("(si)", m_app_name.c_str(), POWERD_SYS_STATE_ACTIVE), + G_VARIANT_TYPE("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + m_cancellable, + on_force_awake_response, + this); + } ~Impl() @@ -57,47 +72,6 @@ public: private: - static void on_system_bus_ready (GObject *, - GAsyncResult *res, - gpointer gself) - { - GError * error; - GDBusConnection * system_bus; - - error = nullptr; - system_bus = g_bus_get_finish (res, &error); - if (error != nullptr) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Unable to get bus: %s", error->message); - - g_error_free (error); - } - else if (system_bus != nullptr) - { - auto self = static_cast(gself); - - self->m_system_bus = G_DBUS_CONNECTION (g_object_ref (system_bus)); - - // ask powerd to keep the system awake - static constexpr int32_t POWERD_SYS_STATE_ACTIVE = 1; - g_dbus_connection_call (system_bus, - BUS_POWERD_NAME, - BUS_POWERD_PATH, - BUS_POWERD_INTERFACE, - "requestSysState", - g_variant_new("(si)", self->m_app_name.c_str(), POWERD_SYS_STATE_ACTIVE), - G_VARIANT_TYPE("(s)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_force_awake_response, - self); - - g_object_unref (system_bus); - } - } - static void on_force_awake_response (GObject * connection, GAsyncResult * res, gpointer gself) @@ -164,8 +138,8 @@ private: **** ***/ -Awake::Awake(const std::string& app_name): - impl(new Impl(app_name)) +Awake::Awake(GDBusConnection* system_bus, const std::string& app_name): + impl{new Impl{system_bus, app_name}} { } -- cgit v1.2.3 From 34f44f959b63d64f0eec2f16e322796a5bea7c3a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Oct 2016 12:08:29 -0500 Subject: in Snap, add a constructor arg for the system bus because we need it when instantiating Awake objects --- src/snap.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index c834f72..a55f760 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -53,19 +53,25 @@ class Snap::Impl public: Impl(const std::shared_ptr& engine, - const std::shared_ptr& settings): + const std::shared_ptr& sound_builder, + const std::shared_ptr& settings, + GDBusConnection* system_bus): m_engine(engine), + m_sound_builder(sound_builder), m_settings(settings), - m_cancellable(g_cancellable_new()) + m_cancellable(g_cancellable_new()), + m_system_bus{G_DBUS_CONNECTION(g_object_ref(system_bus))} { auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); - accounts_service_sound_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, - "org.freedesktop.Accounts", - object_path, - m_cancellable, - on_sound_proxy_ready, - this); + + + accounts_service_sound_proxy_new(m_system_bus, + G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, + "org.freedesktop.Accounts", + object_path, + m_cancellable, + on_sound_proxy_ready, + this); g_free(object_path); } @@ -74,6 +80,7 @@ public: g_cancellable_cancel(m_cancellable); g_clear_object(&m_cancellable); g_clear_object(&m_accounts_service_sound_proxy); + g_clear_object(&m_system_bus); for (const auto& key : m_notifications) m_engine->close (key); @@ -98,7 +105,7 @@ public: // force the system to stay awake std::shared_ptr awake; if (appointment.is_ubuntu_alarm() || calendar_bubbles_enabled() || calendar_list_enabled()) { - awake = std::make_shared(m_engine->app_name()); + awake = std::make_shared(m_system_bus, m_engine->app_name()); } // calendar events are muted in silent mode; alarm clocks never are @@ -231,7 +238,7 @@ private: GError * error; error = nullptr; - auto proxy = accounts_service_sound_proxy_new_for_bus_finish (res, &error); + auto proxy = accounts_service_sound_proxy_new_finish (res, &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -297,6 +304,7 @@ private: std::set m_notifications; GCancellable * m_cancellable {nullptr}; AccountsServiceSound * m_accounts_service_sound_proxy {nullptr}; + GDBusConnection * m_system_bus {nullptr}; static constexpr char const * ACTION_NONE {"none"}; static constexpr char const * ACTION_SNOOZE {"snooze"}; @@ -308,8 +316,10 @@ private: ***/ Snap::Snap(const std::shared_ptr& engine, - const std::shared_ptr& settings): - impl(new Impl(engine, settings)) + const std::shared_ptr& sound_builder, + const std::shared_ptr& settings, + GDBusConnection* system_bus): + impl(new Impl(engine, sound_builder, settings, system_bus)) { } -- cgit v1.2.3 From 0e7d17165316c373dcf936bc5b56fb39f17283a4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Oct 2016 12:39:49 -0500 Subject: In main.cpp and tests where Snap is instantiated, provide the system_bus to Snap's constructor --- src/main.cpp | 4 ++-- src/settings-live.cpp | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 9defed0..6cad190 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,9 +151,9 @@ main(int /*argc*/, char** /*argv*/) // set up the snap decisions auto snooze_planner = std::make_shared(state->settings, state->clock); auto notification_engine = std::make_shared("ayatana-indicator-datetime-service"); - std::unique_ptr snap (new Snap(notification_engine, state->settings)); - auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); auto sound_builder = std::make_shared(); + std::unique_ptr snap (new Snap(notification_engine, sound_builder, state->settings, system_bus)); + auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); auto on_response = [snooze_planner, actions](const Appointment& appointment, const Alarm& alarm, const Snap::Response& response) { switch(response) { case Snap::Response::Snooze: diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 66590e0..59c133f 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -40,13 +40,9 @@ LiveSettings::~LiveSettings() } LiveSettings::LiveSettings(): - m_settings(g_settings_new(SETTINGS_INTERFACE)), - m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)), - m_settings_general_notification(g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID)) + m_settings(g_settings_new(SETTINGS_INTERFACE)) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); - g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); // init the Properties from the GSettings backend update_custom_time_format(); @@ -68,12 +64,20 @@ LiveSettings::LiveSettings(): update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); - update_cal_notification_enabled(); - update_cal_notification_sounds(); - update_cal_notification_vibrations(); - update_cal_notification_bubbles(); - update_cal_notification_list(); - update_vibrate_silent_mode(); + + if (ayatana_common_utils_is_lomiri()) + { + m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + m_settings_general_notification = g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); + update_cal_notification_enabled(); + update_cal_notification_sounds(); + update_cal_notification_vibrations(); + update_cal_notification_bubbles(); + update_cal_notification_list(); + update_vibrate_silent_mode(); + } // now listen for clients to change the properties s.t. we can sync update GSettings -- cgit v1.2.3 From 46d007f0e15aba176d191d349f8a916ee77d5a72 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 4 Nov 2016 11:00:24 -0500 Subject: remove unnecessary test in Awake::Impl::~Impl() --- src/awake.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/awake.cpp b/src/awake.cpp index 3bcd8ed..9ee337e 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -62,12 +62,8 @@ public: { g_cancellable_cancel (m_cancellable); g_object_unref (m_cancellable); - - if (m_system_bus != nullptr) - { - unforce_awake (); - g_object_unref (m_system_bus); - } + unforce_awake (); + g_clear_object (&m_system_bus); } private: @@ -99,7 +95,6 @@ private: g_clear_pointer (&self->m_awake_cookie, g_free); g_variant_get (args, "(s)", &self->m_awake_cookie); - g_debug ("m_awake_cookie is now '%s'", self->m_awake_cookie); g_variant_unref (args); } @@ -120,7 +115,7 @@ private: nullptr, G_DBUS_CALL_FLAGS_NONE, -1, - nullptr, + m_cancellable, nullptr, nullptr); -- cgit v1.2.3 From c1666c0ad2a0ad0ca846b1c6b77c2a81c2ce45ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 16 Nov 2016 02:54:56 +0100 Subject: UpcomingPlanner: don't get events from the day before of the selected one We only need events from the midnight of the selected date to the next month --- src/planner-upcoming.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/planner-upcoming.cpp b/src/planner-upcoming.cpp index 918ebbe..149ac09 100644 --- a/src/planner-upcoming.cpp +++ b/src/planner-upcoming.cpp @@ -33,7 +33,7 @@ UpcomingPlanner::UpcomingPlanner(const std::shared_ptr& range_plan { date().changed().connect([this](const DateTime& dt){ // set the range to the upcoming month - const auto b = dt.add_days(-1).start_of_day(); + const auto b = dt.start_of_day(); const auto e = b.add_full(0, 1, 0, 0, 0, 0); g_debug("%p setting date range to [%s..%s]", this, b.format("%F %T").c_str(), e.format("%F %T").c_str()); m_range_planner->range().set(std::pair(b,e)); -- cgit v1.2.3 From 75343eccb826c999fcd6f2dd2010bf04d986f836 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Wed, 1 Feb 2017 16:55:16 -0500 Subject: Update app name usage to match snaps. --- src/actions-live.cpp | 2 +- src/notifications.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 11643cd..8fa894d 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -50,7 +50,7 @@ void LiveActions::open_alarm_app() { if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("appid://com.lomiri.clock/clock/current-user-version"); + ayatana_common_utils_open_url("appid://lomiri-clock-app/lomiri-clock-app/current-user-version"); } else { diff --git a/src/notifications.cpp b/src/notifications.cpp index a0ceb6f..49300d8 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -465,7 +465,7 @@ private: { #ifdef HAS_LOMIRIAPPLAUNCH auto registry = std::make_shared(); - auto app_id = lomiri::app_launch::AppID::discover(registry, "com.lomiri.calendar"); + auto app_id = lomiri::app_launch::AppID::discover(registry, "lomiri-calendar-app"); if (!app_id.empty()) // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. -- cgit v1.2.3 From 76789a3a3bd92c08e694b6d05020d20b49bff50f Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Thu, 2 Feb 2017 15:52:03 -0500 Subject: Use cmake-extras for coverage support and always enable testing. --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 823a9b8..37baf86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,9 +57,9 @@ endif() # add warnings/coverage info on handwritten files # but not the autogenerated ones... set_source_files_properties(${SERVICE_CXX_SOURCES} - PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} ${GCOV_FLAGS} -g -std=c++11") + PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") set_source_files_properties(${SERVICE_C_SOURCES} - PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} ${GCOV_FLAGS} -g -std=c99") + PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c99") # add the bin dir to our include path so our code can find the generated header files include_directories (${CMAKE_CURRENT_BINARY_DIR}) @@ -70,5 +70,5 @@ link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) add_executable (${SERVICE_EXEC} main.cpp) set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") -target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS}) +target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES}) install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}) -- cgit v1.2.3 From eff92a3b2f836ab59b35bfe11ea91938b224bf59 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Fri, 10 Feb 2017 11:15:07 -0500 Subject: Remove the hard-coding of -g compiler flag. --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37baf86..a64a50e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,9 +57,9 @@ endif() # add warnings/coverage info on handwritten files # but not the autogenerated ones... set_source_files_properties(${SERVICE_CXX_SOURCES} - PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") + PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -std=c++11") set_source_files_properties(${SERVICE_C_SOURCES} - PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c99") + PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -std=c99") # add the bin dir to our include path so our code can find the generated header files include_directories (${CMAKE_CURRENT_BINARY_DIR}) @@ -69,6 +69,6 @@ include_directories (${CMAKE_SOURCE_DIR}) link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) add_executable (${SERVICE_EXEC} main.cpp) -set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") +set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -std=c++11") target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES}) install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}) -- cgit v1.2.3 From d2fc9c2d86789797c93811ad4665bdd67adf9661 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Wed, 31 Oct 2018 21:16:15 -0400 Subject: Fix clock app URL. --- src/actions-live.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 8fa894d..5c49bc4 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -50,7 +50,7 @@ void LiveActions::open_alarm_app() { if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("appid://lomiri-clock-app/lomiri-clock-app/current-user-version"); + ayatana_common_utils_open_url("alarm://"); } else { -- cgit v1.2.3 From bdf012f78b2ffd7356adcaa707b977889671c190 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Wed, 31 Oct 2018 21:56:05 -0400 Subject: Replace ual with url-dispatcher. We don't really hneed ubuntu-app-launch here directly, as the API provided by url-dispatcher gives us a way to query what app handles the calendar URL, as the indicator is a trusted process. This removes the extra dependency and simplifies building slightly. --- src/notifications.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 49300d8..7098cfc 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -24,9 +24,8 @@ #include #include -#ifdef HAS_LOMIRIAPPLAUNCH -#include -#include +#ifdef HAS_URLDISPATCHER +#include #endif #include @@ -463,16 +462,17 @@ private: static std::string calendar_app_id() { - #ifdef HAS_LOMIRIAPPLAUNCH - auto registry = std::make_shared(); - auto app_id = lomiri::app_launch::AppID::discover(registry, "lomiri-calendar-app"); - - if (!app_id.empty()) + #ifdef HAS_URLDISPATCHER + auto urls = g_strsplit("calendar://", ",", 0); + auto appids = lomiri_url_dispatch_url_appid(const_cast(urls)); + g_strfreev(urls); + std::string result; + if (appids != nullptr) { // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. - return std::string(app_id) + ".desktop"; - else - return std::string(); - + result = std::string(appids[0]) + ".desktop"; + g_strfreev(appids); + } + return result; #else return std::string(); #endif -- cgit v1.2.3 From e4b4a10a52805cc78a351f8b08b56d81d5a42b75 Mon Sep 17 00:00:00 2001 From: farkasdvd <30418389+farkasdvd@users.noreply.github.com> Date: Tue, 25 May 2021 19:47:50 +0200 Subject: Snooze starts from the current minute (#30) SnoozePlanner just added the snooze duration to the start of the alarm. If the Snooze button was pressed 10 minutes after the alarm started and the snooze duration is 5 minutes then the alarm is planned into the past. This PR adds every whole minute passed between the start of the alarm and the Snooze action. --- src/planner-snooze.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/planner-snooze.cpp b/src/planner-snooze.cpp index cb365ca..b81c912 100644 --- a/src/planner-snooze.cpp +++ b/src/planner-snooze.cpp @@ -59,7 +59,9 @@ public: appt.alarms.push_back(alarm); // reschedule the alarm to go off N minutes from now - const auto offset = std::chrono::minutes(m_settings->snooze_duration.get()); + // also take into count every whole minute since the alarm went off + const auto offset_to_now = std::chrono::duration_cast(std::chrono::microseconds(DateTime::NowLocal() - appt.begin)); + const auto offset = offset_to_now + std::chrono::minutes(m_settings->snooze_duration.get()); appt.begin += offset; appt.end += offset; appt.alarms[0].time += offset; -- cgit v1.2.3 From 7c5e7e737ab1c68fb3695ff8ff9ea37883fc3888 Mon Sep 17 00:00:00 2001 From: farkasdvd <30418389+farkasdvd@users.noreply.github.com> Date: Wed, 26 May 2021 00:07:13 +0200 Subject: Alarm snoozes after timeout (#29) Changes the default behavior for an alarm timeout from "no action" to "snooze". --- src/snap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index a55f760..00c4743 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -176,7 +176,7 @@ public: b.set_closed_callback([appointment, alarm, on_response, sound, awake, haptic] (const std::string& action){ Snap::Response response; - if (action == ACTION_SNOOZE) + if ((action == ACTION_SNOOZE) || (appointment.is_ubuntu_alarm() && action.empty())) response = Snap::Response::Snooze; else if (action == ACTION_SHOW_APP) response = Snap::Response::ShowApp; -- cgit v1.2.3 From b8d44d2f6bfd4019d7b794200035bf209487f85d Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 15 Jul 2021 01:39:43 +0200 Subject: src/settings-live.cpp: initialise m_settings_cal_notification and m_settings_general_notification to NULL if we are not on Lomiri --- src/settings-live.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 59c133f..00caa74 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -78,6 +78,11 @@ LiveSettings::LiveSettings(): update_cal_notification_list(); update_vibrate_silent_mode(); } + else + { + m_settings_cal_notification = NULL; + m_settings_general_notification = NULL; + } // now listen for clients to change the properties s.t. we can sync update GSettings -- cgit v1.2.3 From 7b495005c1998aaf148c17ceb4f5576835d87ba2 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 15 Jul 2021 02:57:23 +0200 Subject: src/myself.cpp: Fix libaccounts-glib.h inclusion in Focal --- src/myself.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/myself.cpp b/src/myself.cpp index 0debfe4..ae2f061 100644 --- a/src/myself.cpp +++ b/src/myself.cpp @@ -19,7 +19,12 @@ #include "datetime/myself.h" -#include +#if GLIB_CHECK_VERSION(2, 66, 0) + #include +#else + #include +#endif + #include #include -- cgit v1.2.3 From 217b48352a2591150413c77ca85b6a1ef158e6d5 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 16 Jul 2021 21:52:08 +0200 Subject: Fix failing tests - include/actions-mock.h: Set return value to std::string and return an empty string - include/actions.h: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - include/actions-live.h: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - src/actions-live.cpp: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - tests/test-live-actions.cpp: Drop last_cmd and last_url variables + use return values of actions-live functions for testing + test phone functions on lomiri only - tests/test-live-actions.cpp: test phone functions after setting XDG_CURRENT_DESKTOP - tests/test-settings.cpp: Use SETTINGS_NOTIFY_SCHEMA_ID only if it exists - tests/run-eds-ics-test.sh: Remove return statement - tests/CMakeLists.txt: Enable the timezone unit tests - tests/CMakeLists.txt: Catch race condition while attempting to copy schemas - tests/CMakeLists.txt: Exclude blocking tests on Travis for now - tests/tests-timezones.cpp: Use MockTimezone to construct LiveTimezones + drop section expecting changes after /timezone is modified (not monitored) - tests/test-formater: Change warning to plain message otherwise it can crash the test - .build.yml: Replace libmessaging-menu-dev with ayatana-indicator-messages Git build --- src/actions-live.cpp | 57 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 5c49bc4..50add68 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -46,52 +46,70 @@ LiveActions::LiveActions(const std::shared_ptr& state_in): **** ***/ -void LiveActions::open_alarm_app() +std::string LiveActions::open_alarm_app() { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("alarm://"); + sReturn = "alarm://"; + ayatana_common_utils_open_url(sReturn.c_str()); } else { - ayatana_common_utils_execute_command("evolution -c calendar"); + sReturn = "evolution -c calendar"; + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } -void LiveActions::open_calendar_app(const DateTime& dt) +std::string LiveActions::open_calendar_app(const DateTime& dt) { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { const auto utc = dt.to_timezone("UTC"); - auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - ayatana_common_utils_open_url(cmd.c_str()); + sReturn = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); + ayatana_common_utils_open_url(sReturn.c_str()); } else { const auto utc = dt.start_of_day().to_timezone("UTC"); - auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - ayatana_common_utils_execute_command(cmd.c_str()); + sReturn = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } -void LiveActions::open_settings_app() +std::string LiveActions::open_settings_app() { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("settings:///system/time-date"); + sReturn = "settings:///system/time-date"; + ayatana_common_utils_open_url(sReturn.c_str()); } else if (ayatana_common_utils_is_unity()) { - ayatana_common_utils_execute_command("unity-control-center datetime"); + sReturn = "unity-control-center datetime"; + ayatana_common_utils_execute_command(sReturn.c_str()); } else if (ayatana_common_utils_is_mate()) { - ayatana_common_utils_execute_command("mate-time-admin"); + sReturn = "mate-time-admin"; + ayatana_common_utils_execute_command(sReturn.c_str()); } else { - ayatana_common_utils_execute_command("gnome-control-center datetime"); + sReturn = "gnome-control-center datetime"; + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } bool LiveActions::desktop_has_calendar_app() const @@ -126,23 +144,28 @@ bool LiveActions::desktop_has_calendar_app() const return have_calendar; } -void LiveActions::open_appointment(const Appointment& appt, const DateTime& date) +std::string LiveActions::open_appointment(const Appointment& appt, const DateTime& date) { + std::string sReturn = ""; + if (!appt.activation_url.empty()) { - ayatana_common_utils_open_url(appt.activation_url.c_str()); + sReturn = appt.activation_url; + ayatana_common_utils_open_url(sReturn.c_str()); } else switch (appt.type) { case Appointment::UBUNTU_ALARM: - open_alarm_app(); + sReturn = open_alarm_app(); break; case Appointment::EVENT: default: - open_calendar_app(date); + sReturn = open_calendar_app(date); break; } + + return sReturn; } /*** -- cgit v1.2.3 From 86ff05f7d1a592f59ec846faaead83ece1513ca1 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 19 Jul 2021 00:19:07 +0200 Subject: Rename com.canonical.powerd -> com.lomiri.Repowerd --- src/clock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/clock.cpp b/src/clock.cpp index a2ef387..47eebe6 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -155,7 +155,7 @@ private: } /** - *** DBus Chatter: com.canonical.powerd + *** DBus Chatter: com.lomiri.Repowerd *** *** Fire Clock::minute_changed() signal when powerd says the system's *** has awoken from sleep -- the old timestamp is likely out-of-date -- cgit v1.2.3 From 4e5e49fd380b19ff65f0d2aed8838a668aa4a97f Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 29 Aug 2021 13:53:48 +0200 Subject: src/notifications.cpp: No indentation of #ifdef-#else-#endif compiler macro. --- src/notifications.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/notifications.cpp b/src/notifications.cpp index 7098cfc..b36227b 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -462,7 +462,7 @@ private: static std::string calendar_app_id() { - #ifdef HAS_URLDISPATCHER +#ifdef HAS_URLDISPATCHER auto urls = g_strsplit("calendar://", ",", 0); auto appids = lomiri_url_dispatch_url_appid(const_cast(urls)); g_strfreev(urls); @@ -473,9 +473,9 @@ private: g_strfreev(appids); } return result; - #else +#else return std::string(); - #endif +#endif } static std::string calendar_app_icon() -- cgit v1.2.3 From 71b4866df5e9089b778fffc624a80269b9f47067 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 29 Aug 2021 13:55:55 +0200 Subject: src/settings-live.cpp: White-space change, drop blanks in between parameters in function call. --- src/settings-live.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 00caa74..dc90d0e 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -42,7 +42,7 @@ LiveSettings::~LiveSettings() LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) { - g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); + g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); // init the Properties from the GSettings backend update_custom_time_format(); -- cgit v1.2.3