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 --- include/datetime/settings.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/datetime') diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 253a00a..d5e81c6 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -61,6 +61,7 @@ public: core::Property alarm_volume; core::Property alarm_duration; core::Property snooze_duration; + core::Property>> muted_apps; }; } // namespace datetime -- 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 --- include/datetime/settings-live.h | 8 +++- include/datetime/settings-shared.h | 3 ++ src/settings-live.cpp | 80 ++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 10 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index ccf7122..330b8e8 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -38,8 +38,10 @@ public: virtual ~LiveSettings(); private: - static void on_changed(GSettings*, gchar*, gpointer); - void update_key(const std::string& key); + static void on_changed_ccid(GSettings*, gchar*, gpointer); + static void on_changed_cunh(GSettings*, gchar*, gpointer); + void update_key_ccid(const std::string& key); + void update_key_cunh(const std::string& key); void update_custom_time_format(); void update_locations(); @@ -60,8 +62,10 @@ private: void update_alarm_duration(); void update_alarm_haptic(); void update_snooze_duration(); + void update_muted_apps(); GSettings* m_settings; + GSettings* m_settings_cunh; // we've got a raw pointer here, so disable copying LiveSettings(const LiveSettings&) =delete; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index bd84a2d..f385e7a 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -51,4 +51,7 @@ TimeFormatMode; #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" +#define SETTINGS_CUNH_SCHEMA_ID "com.lomiri.notifications.hub" +#define SETTINGS_CUNH_BLACKLIST_S "blacklist" + #endif // INDICATOR_DATETIME_SETTINGS_SHARED 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 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. --- include/datetime/date-time.h | 2 + include/datetime/menu.h | 6 +++ src/date-time.cpp | 10 ++++ src/menu.cpp | 111 ++++++++++++++++++++++++++++++++++++------- tests/CMakeLists.txt | 1 + tests/print-to.h | 10 ++++ 6 files changed, 122 insertions(+), 18 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index fc83388..845716d 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -68,7 +68,9 @@ public: int64_t to_unix() const; bool operator<(const DateTime& that) const; + bool operator>(const DateTime& that) const; bool operator<=(const DateTime& that) const; + bool operator>=(const DateTime& that) const; bool operator!=(const DateTime& that) const; bool operator==(const DateTime& that) const; int64_t operator- (const DateTime& that) const; diff --git a/include/datetime/menu.h b/include/datetime/menu.h index acd9ed8..0074ea5 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -21,6 +21,7 @@ #define INDICATOR_DATETIME_MENU_H #include +#include #include #include // std::shared_ptr @@ -49,6 +50,11 @@ public: Profile profile() const; GMenuModel* menu_model(); + static std::vector get_display_appointments( + const std::vector&, + const DateTime& start, + unsigned int max_items=5); + protected: Menu (Profile profile_in, const std::string& name_in); virtual ~Menu() =default; 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) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bec0010..aa69ca1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,6 +59,7 @@ add_test_by_name(test-exporter) add_test_by_name(test-formatter) add_test_by_name(test-live-actions) add_test_by_name(test-locations) +add_test_by_name(test-menu-appointments) add_test_by_name(test-menus) add_test_by_name(test-planner) add_test_by_name(test-settings) diff --git a/tests/print-to.h b/tests/print-to.h index 19367ac..652da52 100644 --- a/tests/print-to.h +++ b/tests/print-to.h @@ -21,6 +21,7 @@ #define INDICATOR_DATETIME_TESTS_PRINT_TO #include +#include #include @@ -71,6 +72,15 @@ PrintTo(const Appointment& appointment, std::ostream* os) *os << '}'; } +void +PrintTo(const std::vector& appointments, std::ostream* os) +{ + *os << '{'; + for (const auto& appointment : appointments) + PrintTo(appointment, os); + *os << '}'; +} + } // namespace datetime } // namespace indicator } // namespace ayatana -- 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. --- include/datetime/actions-live.h | 4 ++-- include/datetime/actions.h | 4 ++-- src/actions-live.cpp | 8 ++++---- src/actions.cpp | 29 +++++++++++++++-------------- src/menu.cpp | 7 +++++-- tests/actions-mock.h | 6 ++++-- tests/test-actions.cpp | 4 ++-- tests/test-live-actions.cpp | 11 ++++++----- 8 files changed, 40 insertions(+), 33 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 2c348c6..1f84659 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -41,12 +41,12 @@ public: bool desktop_has_calendar_app() const override; void desktop_open_alarm_app() override; - void desktop_open_appointment(const Appointment&) override; + void desktop_open_appointment(const Appointment&, const DateTime&) override; void desktop_open_calendar_app(const DateTime&) override; void desktop_open_settings_app() override; void phone_open_alarm_app() override; - void phone_open_appointment(const Appointment&) override; + void phone_open_appointment(const Appointment&, const DateTime &) override; void phone_open_calendar_app(const DateTime&) override; void phone_open_settings_app() override; diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 47931ac..ea163e4 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -45,12 +45,12 @@ public: virtual bool desktop_has_calendar_app() const =0; virtual void desktop_open_alarm_app() =0; - virtual void desktop_open_appointment(const Appointment&) =0; + virtual void desktop_open_appointment(const Appointment&, const DateTime&) =0; virtual void desktop_open_calendar_app(const DateTime&) =0; virtual void desktop_open_settings_app() =0; virtual void phone_open_alarm_app() =0; - virtual void phone_open_appointment(const Appointment&) =0; + virtual void phone_open_appointment(const Appointment&, const DateTime&) =0; virtual void phone_open_calendar_app(const DateTime&) =0; virtual void phone_open_settings_app() =0; 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); diff --git a/tests/actions-mock.h b/tests/actions-mock.h index 59a0912..346a8f6 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -57,8 +57,9 @@ public: void desktop_open_alarm_app() { m_history.push_back(DesktopOpenAlarmApp); } - void desktop_open_appointment(const Appointment& appt) { + void desktop_open_appointment(const Appointment& appt, const DateTime& dt) { m_appt = appt; + m_date_time = dt; m_history.push_back(DesktopOpenAppt); } void desktop_open_calendar_app(const DateTime& dt) { @@ -72,8 +73,9 @@ public: void phone_open_alarm_app() { m_history.push_back(PhoneOpenAlarmApp); } - void phone_open_appointment(const Appointment& appt) { + void phone_open_appointment(const Appointment& appt, const DateTime& dt) { m_appt = appt; + m_date_time = dt; m_history.push_back(PhoneOpenAppt); } void phone_open_calendar_app(const DateTime& dt) { diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index aa608a8..96da7cc 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -116,7 +116,7 @@ protected: m_mock_state->mock_range_planner->appointments().set(appointments); // activate the action - auto v = g_variant_new_string(appointments[0].uid.c_str()); + auto v = g_variant_new("(sx)", appointments[0].uid.c_str(), 0); g_action_group_activate_action(action_group, action_name, v); // test the results @@ -134,7 +134,7 @@ protected: EXPECT_TRUE(m_mock_actions->history().empty()); // activate the action - v = g_variant_new_string("this-uid-is-not-one-that-we-have"); + v = g_variant_new("(sx)", "this-uid-is-not-one-that-we-have", 0); g_action_group_activate_action(action_group, action_name, v); // test the results diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 3f79d7d..e7cb1a2 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -64,7 +64,7 @@ TEST_F(TimedateFixture, DesktopOpenAppointment) Appointment a; a.uid = "some-uid"; a.begin = DateTime::NowLocal(); - m_actions->desktop_open_appointment(a); + m_actions->desktop_open_appointment(a, a.begin); const std::string expected_substr = "evolution \"calendar:///?startdate="; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } @@ -106,12 +106,13 @@ TEST_F(TimedateFixture, PhoneOpenAppointment) a.source_uid = "source-uid"; a.begin = DateTime::NowLocal(); a.type = Appointment::EVENT; - m_actions->phone_open_appointment(a); - const std::string appointment_app_url = "calendar://eventid=source-uid/event-uid"; + auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0); + m_actions->phone_open_appointment(a, ocurrenceDate); + const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); EXPECT_EQ(appointment_app_url, m_live_actions->last_url); a.type = Appointment::UBUNTU_ALARM; - m_actions->phone_open_appointment(a); + m_actions->phone_open_appointment(a, a.begin); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } @@ -119,7 +120,7 @@ TEST_F(TimedateFixture, PhoneOpenCalendarApp) { auto now = DateTime::NowLocal(); m_actions->phone_open_calendar_app(now); - const std::string expected = now.format("calendar:///?startdate=%Y%m%dT%H%M%SZ"); + const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); EXPECT_EQ(expected, m_live_actions->last_url); } -- 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] --- include/datetime/myself.h | 62 ------------------------------------- src/myself.cpp | 79 ----------------------------------------------- 2 files changed, 141 deletions(-) delete mode 100644 include/datetime/myself.h delete mode 100644 src/myself.cpp (limited to 'include/datetime') diff --git a/include/datetime/myself.h b/include/datetime/myself.h deleted file mode 100644 index 67e938d..0000000 --- a/include/datetime/myself.h +++ /dev/null @@ -1,62 +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 - */ - -#ifndef INDICATOR_DATETIME_MYSELF_H -#define INDICATOR_DATETIME_MYSELF_H - -#include - -#include -#include -#include -#include - -typedef struct _AgManager AgManager; - -namespace ayatana { -namespace indicator { -namespace datetime { - -class Myself -{ -public: - Myself(); - - const core::Property>& emails() - { - return m_emails; - } - - bool isMyEmail(const std::string &email); - -private: - std::shared_ptr m_accounts_manager; - core::Property > m_emails; - - static void on_accounts_changed(AgManager*, guint, Myself*); - void reloadEmails(); - -}; - - -} // namespace datetime -} // namespace indicator -} // namespace ayatana - -#endif // INDICATOR_DATETIME_MYSELF_H 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. --- include/datetime/engine-eds.h | 2 +- include/datetime/myself.h | 61 ++++++++++++++++++++++++++++++++++++ src/engine-eds.cpp | 15 ++++----- src/myself.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 include/datetime/myself.h create mode 100644 src/myself.cpp (limited to 'include/datetime') diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h index 12425b3..0b854e5 100644 --- a/include/datetime/engine-eds.h +++ b/include/datetime/engine-eds.h @@ -48,7 +48,7 @@ class EdsEngine: public Engine { public: EdsEngine(); - explicit EdsEngine(const std::shared_ptr &myself); + explicit EdsEngine(const std::unique_ptr &myself); ~EdsEngine(); void get_appointments(const DateTime& begin, diff --git a/include/datetime/myself.h b/include/datetime/myself.h new file mode 100644 index 0000000..c381780 --- /dev/null +++ b/include/datetime/myself.h @@ -0,0 +1,61 @@ +/* + * 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 + */ + +#ifndef INDICATOR_DATETIME_MYSELF_H +#define INDICATOR_DATETIME_MYSELF_H + +#include + +#include + +#include +#include +#include + +namespace ayatana { +namespace indicator { +namespace datetime { + +class Myself +{ +public: + Myself(); + + core::Property>& emails() + { + return m_emails; + } + + bool isMyEmail(const std::string &email); + +private: + std::shared_ptr m_accounts_manager; + core::Property > m_emails; + + static void on_accounts_changed(AgManager*, guint, Myself*); + void reloadEmails(); + +}; + + +} // namespace datetime +} // namespace indicator +} // namespace ayatana + +#endif // INDICATOR_DATETIME_MYSELF_H 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. --- include/datetime/appointment.h | 6 ++++++ src/engine-eds.cpp | 24 +++++++++++++++--------- src/snap.cpp | 4 ++++ tests/manual-test-snap.cpp | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 950f4bb..5b4c27e 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -34,9 +34,15 @@ namespace datetime { */ struct Alarm { + enum Type { + EMAIL = 0x001, + SOUND = 0x010, + TEXT = 0x100 + }; std::string text; std::string audio_url; DateTime time; + int type; bool operator== (const Alarm& that) const; bool has_sound() const; 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())) diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index a0f80f2..5aa49a7 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); - a.alarms.push_back(Alarm{"Alarm Text", "", a.begin}); + a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, Alarm::SOUND}); auto loop = g_main_loop_new(nullptr, false); auto on_snooze = [loop](const Appointment& appt, const Alarm&){ -- 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. --- include/datetime/appointment.h | 9 ++++++++- src/appointment.cpp | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 5b4c27e..14adb5d 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -42,7 +42,14 @@ struct Alarm std::string text; std::string audio_url; DateTime time; - int type; + int type = TEXT; + + Alarm(const std::string &text_, const std::string &audio_url_, const DateTime & time_, int type_ = TEXT) + : text(text_), audio_url(audio_url_), time(time_), type(type_) + {} + + Alarm() + {} bool operator== (const Alarm& that) const; bool has_sound() const; 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 0b5b8b3d31eaff2302c2fd3eb11e68be96f1d219 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 09:41:29 -0300 Subject: Remove constructors from Alarm. --- include/datetime/appointment.h | 9 +-------- tests/test-alarm-queue.cpp | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 14adb5d..2c225fc 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -42,14 +42,7 @@ struct Alarm std::string text; std::string audio_url; DateTime time; - int type = TEXT; - - Alarm(const std::string &text_, const std::string &audio_url_, const DateTime & time_, int type_ = TEXT) - : text(text_), audio_url(audio_url_), time(time_), type(type_) - {} - - Alarm() - {} + int type : SOUND; bool operator== (const Alarm& that) const; bool has_sound() const; diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index 42edf74..c1f7929 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -79,7 +79,7 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; - a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin}); + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, (int) Alarm::SOUND}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); -- 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. --- include/datetime/appointment.h | 8 ++++---- src/appointment.cpp | 18 +++++++++--------- tests/manual-test-snap.cpp | 2 +- tests/notification-fixture.h | 4 ++-- tests/test-alarm-queue.cpp | 4 ++-- tests/test-eds-ics-missing-trigger.cpp | 1 + tests/test-eds-ics-nonrepeating-events.cpp | 4 ++-- tests/test-eds-ics-repeating-events.cpp | 18 +++++++++--------- tests/test-eds-ics-repeating-valarms.cpp | 16 ++++++++-------- tests/test-eds-ics-tzids-2.cpp | 2 +- 10 files changed, 39 insertions(+), 38 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 2c225fc..ae9e8ff 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -35,21 +35,21 @@ namespace datetime { struct Alarm { enum Type { + None = 0, EMAIL = 0x001, SOUND = 0x010, TEXT = 0x100 }; + int type; std::string text; std::string audio_url; DateTime time; - int type : SOUND; bool operator== (const Alarm& that) const; - bool has_sound() const; - bool has_text() const; + Alarm(); + Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_); }; - /** * \brief An instance of an appointment; e.g. a calendar event or clock-app alarm * 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 diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 5aa49a7..1479ef9 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); - a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, Alarm::SOUND}); + a.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a.begin}); auto loop = g_main_loop_new(nullptr, false); auto on_snooze = [loop](const Appointment& appt, const Alarm&){ diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h index a2f1179..40f7cee 100644 --- a/tests/notification-fixture.h +++ b/tests/notification-fixture.h @@ -111,7 +111,7 @@ protected: const auto christmas = ayatana::indicator::datetime::DateTime::Local(2015,12,25,0,0,0); appt.begin = christmas.start_of_day(); appt.end = christmas.end_of_day(); - appt.alarms.push_back(ayatana::indicator::datetime::Alarm{"Ho Ho Ho!", "", appt.begin, ayatana::indicator::datetime::Alarm::SOUND }); + appt.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "Ho Ho Ho!", "", appt.begin }); // init a Lomiri Alarm ualarm.color = "red"; @@ -121,7 +121,7 @@ protected: const auto tomorrow = ayatana::indicator::datetime::DateTime::NowLocal().add_days(1); ualarm.begin = tomorrow; ualarm.end = tomorrow; - ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{"It's Tomorrow!", "", appt.begin}); + ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "It's Tomorrow!", "", appt.begin}); /// /// Add the AccountsService mock diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index c1f7929..49bd933 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -79,7 +79,7 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; - a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, (int) Alarm::SOUND}); + a1.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a1.begin}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); @@ -92,7 +92,7 @@ protected: a2.type = Appointment::EVENT; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; - a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin}); + a2.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a2.begin}); return std::vector({a1, a2}); } diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp index 0aa00c6..3894569 100644 --- a/tests/test-eds-ics-missing-trigger.cpp +++ b/tests/test-eds-ics-missing-trigger.cpp @@ -91,6 +91,7 @@ TEST_F(VAlarmFixture, MissingTriggers) a.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND; a.alarms[0].time = a.begin; a.alarms[0].text = a.summary; + a.alarms[0].type = Alarm::SOUND | Alarm::TEXT; expected.push_back(a); // build expected: recurring alarm diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index e79ab1a..fe0d851 100644 --- a/tests/test-eds-ics-nonrepeating-events.cpp +++ b/tests/test-eds-ics-nonrepeating-events.cpp @@ -80,11 +80,11 @@ TEST_F(VAlarmFixture, MultipleAppointments) // what we expect to get... Appointment expected_appt; - expected_appt.uid = "20150520T000726Z-3878-32011-1770-81@ubuntu-phablet"; + expected_appt.uid = "20150520T000726Z-3878-32011-1770-81@lomiri-phablet"; expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array expected_alarms = { - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)}) + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)}) }; // compare it to what we actually loaded... diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index d4f0026..cdc0bbc 100644 --- a/tests/test-eds-ics-repeating-events.cpp +++ b/tests/test-eds-ics-repeating-events.cpp @@ -80,18 +80,18 @@ TEST_F(VAlarmFixture, MultipleAppointments) // what we expect to get... Appointment expected_appt; - expected_appt.uid = "20150507T211449Z-4262-32011-1418-1@ubuntu-phablet"; + expected_appt.uid = "20150507T211449Z-4262-32011-1418-1@lomiri-phablet"; expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array expected_alarms = { - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}), - Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)}) + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}), + Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)}) }; // compare it to what we actually loaded... diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp index 2132b71..49ec41b 100644 --- a/tests/test-eds-ics-repeating-valarms.cpp +++ b/tests/test-eds-ics-repeating-valarms.cpp @@ -83,14 +83,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) ASSERT_EQ(1, appts.size()); const auto& appt = appts.front(); ASSERT_EQ(8, appt.alarms.size()); - EXPECT_EQ(Alarm({"Time to pack!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]); - EXPECT_EQ(Alarm({"Time to pack!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]); - EXPECT_EQ(Alarm({"Time to pack!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]); - EXPECT_EQ(Alarm({"Time to pack!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]); - EXPECT_EQ(Alarm({"Go to the airport!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]); - EXPECT_EQ(Alarm({"Go to the airport!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]); - EXPECT_EQ(Alarm({"Go to the airport!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]); - EXPECT_EQ(Alarm({"Go to the airport!", "file://" CALENDAR_DEFAULT_SOUND, DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]); + EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]); // now let's try this out with AlarmQueue... // hook the planner up to a SimpleAlarmQueue and confirm that it triggers for each of the reminders diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index c8b0370..b1a344a 100644 --- a/tests/test-eds-ics-tzids-2.cpp +++ b/tests/test-eds-ics-tzids-2.cpp @@ -86,7 +86,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) appt->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar"; appt->begin = DateTime{gtz,2014,1,21,11,0,0}; appt->end = DateTime{gtz,2014,1,21,13,0,0}; - appt->alarms = std::vector{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; + appt->alarms = std::vector{ Alarm({Alarm::TEXT, "Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; // compare it to what we actually loaded... const auto appts = planner->appointments().get(); -- 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. --- include/datetime/appointment.h | 11 ++--------- src/appointment.cpp | 17 ++++++++--------- src/engine-eds.cpp | 22 +++++++--------------- src/snap.cpp | 5 ----- tests/manual-test-snap.cpp | 2 +- tests/notification-fixture.h | 4 ++-- tests/test-alarm-queue.cpp | 4 ++-- tests/test-eds-ics-missing-trigger.cpp | 1 - tests/test-eds-ics-nonrepeating-events.cpp | 2 +- tests/test-eds-ics-repeating-events.cpp | 16 ++++++++-------- tests/test-eds-ics-repeating-valarms.cpp | 16 ++++++++-------- tests/test-eds-ics-tzids-2.cpp | 2 +- 12 files changed, 40 insertions(+), 62 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index ae9e8ff..faf8a18 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -34,20 +34,13 @@ namespace datetime { */ struct Alarm { - enum Type { - None = 0, - EMAIL = 0x001, - SOUND = 0x010, - TEXT = 0x100 - }; - int type; std::string text; std::string audio_url; DateTime time; bool operator== (const Alarm& that) const; - Alarm(); - Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_); + bool has_sound() const; + bool has_text() const; }; /** 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())) diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 1479ef9..a0f80f2 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); - a.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a.begin}); + a.alarms.push_back(Alarm{"Alarm Text", "", a.begin}); auto loop = g_main_loop_new(nullptr, false); auto on_snooze = [loop](const Appointment& appt, const Alarm&){ diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h index 40f7cee..29066c0 100644 --- a/tests/notification-fixture.h +++ b/tests/notification-fixture.h @@ -111,7 +111,7 @@ protected: const auto christmas = ayatana::indicator::datetime::DateTime::Local(2015,12,25,0,0,0); appt.begin = christmas.start_of_day(); appt.end = christmas.end_of_day(); - appt.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "Ho Ho Ho!", "", appt.begin }); + appt.alarms.push_back(ayatana::indicator::datetime::Alarm{"Ho Ho Ho!", "", appt.begin }); // init a Lomiri Alarm ualarm.color = "red"; @@ -121,7 +121,7 @@ protected: const auto tomorrow = ayatana::indicator::datetime::DateTime::NowLocal().add_days(1); ualarm.begin = tomorrow; ualarm.end = tomorrow; - ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "It's Tomorrow!", "", appt.begin}); + ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{"It's Tomorrow!", "", appt.begin}); /// /// Add the AccountsService mock diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index 49bd933..42edf74 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -79,7 +79,7 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; - a1.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a1.begin}); + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); @@ -92,7 +92,7 @@ protected: a2.type = Appointment::EVENT; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; - a2.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a2.begin}); + a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin}); return std::vector({a1, a2}); } diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp index 3894569..0aa00c6 100644 --- a/tests/test-eds-ics-missing-trigger.cpp +++ b/tests/test-eds-ics-missing-trigger.cpp @@ -91,7 +91,6 @@ TEST_F(VAlarmFixture, MissingTriggers) a.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND; a.alarms[0].time = a.begin; a.alarms[0].text = a.summary; - a.alarms[0].type = Alarm::SOUND | Alarm::TEXT; expected.push_back(a); // build expected: recurring alarm diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index fe0d851..ff0ef3f 100644 --- a/tests/test-eds-ics-nonrepeating-events.cpp +++ b/tests/test-eds-ics-nonrepeating-events.cpp @@ -84,7 +84,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array expected_alarms = { - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)}) + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)}) }; // compare it to what we actually loaded... diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index cdc0bbc..5d2a2ee 100644 --- a/tests/test-eds-ics-repeating-events.cpp +++ b/tests/test-eds-ics-repeating-events.cpp @@ -84,14 +84,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array expected_alarms = { - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}), - Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)}) + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}), + Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)}) }; // compare it to what we actually loaded... diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp index 49ec41b..4f53e68 100644 --- a/tests/test-eds-ics-repeating-valarms.cpp +++ b/tests/test-eds-ics-repeating-valarms.cpp @@ -83,14 +83,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) ASSERT_EQ(1, appts.size()); const auto& appt = appts.front(); ASSERT_EQ(8, appt.alarms.size()); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]); - EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]); // now let's try this out with AlarmQueue... // hook the planner up to a SimpleAlarmQueue and confirm that it triggers for each of the reminders diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index b1a344a..c8b0370 100644 --- a/tests/test-eds-ics-tzids-2.cpp +++ b/tests/test-eds-ics-tzids-2.cpp @@ -86,7 +86,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) appt->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar"; appt->begin = DateTime{gtz,2014,1,21,11,0,0}; appt->end = DateTime{gtz,2014,1,21,13,0,0}; - appt->alarms = std::vector{ Alarm({Alarm::TEXT, "Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; + appt->alarms = std::vector{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; // compare it to what we actually loaded... const auto appts = planner->appointments().get(); -- 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. --- include/datetime/engine-eds.h | 3 +-- include/datetime/myself.h | 9 +++++---- src/engine-eds.cpp | 16 +++++----------- src/main.cpp | 3 ++- src/myself.cpp | 13 ++++++++----- tests/test-eds-ics-all-day-events.cpp | 3 ++- tests/test-eds-ics-missing-trigger.cpp | 5 +++-- tests/test-eds-ics-non-attending-alarms.cpp | 3 ++- tests/test-eds-ics-nonrepeating-events.cpp | 3 ++- tests/test-eds-ics-repeating-events.cpp | 3 ++- tests/test-eds-ics-repeating-valarms.cpp | 3 ++- tests/test-eds-ics-tzids-2.cpp | 3 ++- tests/test-eds-ics-tzids-utc.cpp | 3 ++- tests/test-eds-ics-tzids.cpp | 3 ++- 14 files changed, 40 insertions(+), 33 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h index 0b854e5..96b0f76 100644 --- a/include/datetime/engine-eds.h +++ b/include/datetime/engine-eds.h @@ -47,8 +47,7 @@ class Myself; class EdsEngine: public Engine { public: - EdsEngine(); - explicit EdsEngine(const std::unique_ptr &myself); + EdsEngine(const std::shared_ptr &myself); ~EdsEngine(); void get_appointments(const DateTime& begin, diff --git a/include/datetime/myself.h b/include/datetime/myself.h index c381780..452fa53 100644 --- a/include/datetime/myself.h +++ b/include/datetime/myself.h @@ -20,13 +20,14 @@ #ifndef INDICATOR_DATETIME_MYSELF_H #define INDICATOR_DATETIME_MYSELF_H -#include - #include #include #include #include +#include + +typedef struct _AgManager AgManager; namespace ayatana { namespace indicator { @@ -37,7 +38,7 @@ class Myself public: Myself(); - core::Property>& emails() + const core::Property>& emails() { return m_emails; } @@ -46,7 +47,7 @@ public: private: std::shared_ptr m_accounts_manager; - core::Property > m_emails; + core::Property > m_emails; static void on_accounts_changed(AgManager*, guint, Myself*); void reloadEmails(); 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); diff --git a/tests/test-eds-ics-all-day-events.cpp b/tests/test-eds-ics-all-day-events.cpp index 68a3c95..5d7cdc6 100644 --- a/tests/test-eds-ics-all-day-events.cpp +++ b/tests/test-eds-ics-all-day-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp index 0aa00c6..3da53ae 100644 --- a/tests/test-eds-ics-missing-trigger.cpp +++ b/tests/test-eds-ics-missing-trigger.cpp @@ -21,9 +21,10 @@ #include -#include #include #include +#include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MissingTriggers) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-non-attending-alarms.cpp b/tests/test-eds-ics-non-attending-alarms.cpp index 796dd2d..b636e6f 100644 --- a/tests/test-eds-ics-non-attending-alarms.cpp +++ b/tests/test-eds-ics-non-attending-alarms.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, NonAttendingEvent) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Recife"}; diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index ff0ef3f..8aa2b82 100644 --- a/tests/test-eds-ics-nonrepeating-events.cpp +++ b/tests/test-eds-ics-nonrepeating-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index 5d2a2ee..4125623 100644 --- a/tests/test-eds-ics-repeating-events.cpp +++ b/tests/test-eds-ics-repeating-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp index 53a6d41..5e418f8 100644 --- a/tests/test-eds-ics-repeating-valarms.cpp +++ b/tests/test-eds-ics-repeating-valarms.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index c8b0370..a1d2f5a 100644 --- a/tests/test-eds-ics-tzids-2.cpp +++ b/tests/test-eds-ics-tzids-2.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Los_Angeles"}; diff --git a/tests/test-eds-ics-tzids-utc.cpp b/tests/test-eds-ics-tzids-utc.cpp index 3ea40d0..f79bf3e 100644 --- a/tests/test-eds-ics-tzids-utc.cpp +++ b/tests/test-eds-ics-tzids-utc.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, UTCAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Recife"}; diff --git a/tests/test-eds-ics-tzids.cpp b/tests/test-eds-ics-tzids.cpp index c80feb2..11d44b7 100644 --- a/tests/test-eds-ics-tzids.cpp +++ b/tests/test-eds-ics-tzids.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"Europe/Berlin"}; -- cgit v1.2.3 From ba6591e1fb0235d6e4ba5cb00dcb64fb74308ff8 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 1 Apr 2016 11:53:55 -0300 Subject: Include the correct header for set. --- include/datetime/myself.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/datetime') diff --git a/include/datetime/myself.h b/include/datetime/myself.h index 452fa53..67e938d 100644 --- a/include/datetime/myself.h +++ b/include/datetime/myself.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include -- 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 --- include/datetime/dbus-shared.h | 42 ++++++ include/datetime/timezone-timedated.h | 6 +- src/timezone-timedated.cpp | 249 ++++++++++++++++++---------------- tests/test-timezone-timedated.cpp | 184 ++++++++++++++----------- 4 files changed, 283 insertions(+), 198 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index 057ac6b..fd43ae8 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -28,5 +28,47 @@ #define BUS_POWERD_PATH "/com/canonical/powerd" #define BUS_POWERD_INTERFACE "com.canonical.powerd" +namespace ayatana { +namespace indicator { +namespace datetime { + +namespace Bus +{ + namespace Timedate1 + { + static constexpr char const * BUSNAME {"org.freedesktop.timedate1"}; + static constexpr char const * ADDR {"/org/freedesktop/timedate1"}; + static constexpr char const * IFACE {"org.freedesktop.timedate1"}; + + namespace Properties + { + static constexpr char const * TIMEZONE {"Timezone"}; + } + + namespace Methods + { + static constexpr char const * SET_TIMEZONE {"SetTimezone"}; + } + } + + namespace Properties + { + static constexpr char const * IFACE {"org.freedesktop.DBus.Properties"}; + + namespace Methods + { + static constexpr char const * GET {"Get"}; + } + + namespace Signals + { + static constexpr char const * PROPERTIES_CHANGED {"PropertiesChanged"}; + } + } +} + +} // namespace datetime +} // namespace indicator +} // namespace ayatana #endif /* INDICATOR_DATETIME_DBUS_SHARED_H */ diff --git a/include/datetime/timezone-timedated.h b/include/datetime/timezone-timedated.h index 336a148..0857706 100644 --- a/include/datetime/timezone-timedated.h +++ b/include/datetime/timezone-timedated.h @@ -20,8 +20,6 @@ #ifndef INDICATOR_DATETIME_TIMEDATED_TIMEZONE_H #define INDICATOR_DATETIME_TIMEDATED_TIMEZONE_H -#define DEFAULT_FILENAME "/etc/timezone" - #include // base class #include // std::string @@ -31,12 +29,12 @@ namespace indicator { namespace datetime { /** - * \brief A #Timezone that gets its information from monitoring a file, such as /etc/timezone + * \brief A #Timezone that gets its information from org.freedesktop.timedate1 */ class TimedatedTimezone: public Timezone { public: - TimedatedTimezone(std::string filename = DEFAULT_FILENAME); + TimedatedTimezone(); ~TimedatedTimezone(); private: 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}} { } diff --git a/tests/test-timezone-timedated.cpp b/tests/test-timezone-timedated.cpp index 2fdec12..b293e59 100644 --- a/tests/test-timezone-timedated.cpp +++ b/tests/test-timezone-timedated.cpp @@ -1,9 +1,5 @@ - /* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr + * Copyright © 2014-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 @@ -16,127 +12,155 @@ * * You should have received a copy of the GNU General Public License along * with this program. If not, see . + * + * Authors: + * Charles Kerr + * Ted Gould */ -#include "timedated-fixture.h" +#include "glib-fixture.h" +#include #include -using ayatana::indicator::datetime::TimedatedTimezone; +#include -/*** -**** -***/ -#define TIMEZONE_FILE (SANDBOX"/timezone") +using namespace ayatana::indicator::datetime; + -class TimezoneFixture: public TimedateFixture +struct Timedate1Fixture: public GlibFixture { - private: +private: + + typedef GlibFixture super; - typedef TimedateFixture super; +protected: - protected: + GDBusConnection* m_bus {}; + GTestDBus* m_test_bus {}; void SetUp() override { - super::SetUp(); + super::SetUp(); + + // use a fake bus + m_test_bus = g_test_dbus_new(G_TEST_DBUS_NONE); + g_test_dbus_up(m_test_bus); + const char * address = g_test_dbus_get_bus_address(m_test_bus); + g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); + g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); + g_debug("test_dbus's address is %s", address); + + // get the bus + m_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); + g_dbus_connection_set_exit_on_close(m_bus, FALSE); + g_object_add_weak_pointer(G_OBJECT(m_bus), (gpointer*)&m_bus); } void TearDown() override { - super::TearDown(); + g_clear_object(&m_bus); + g_clear_object(&m_test_bus); + + super::TearDown(); } - public: + void start_timedate1(const std::string& tzid) + { + // start the store + auto json_parameters = g_strdup_printf("{\"Timezone\": \"%s\"}", tzid.c_str()); + const gchar* child_argv[] = { "python3", "-m", "dbusmock", "--template", "timedated", "--parameters", json_parameters, nullptr }; + GError* error = nullptr; + g_spawn_async(nullptr, (gchar**)child_argv, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, &error); + g_assert_no_error(error); + g_free(json_parameters); + + // wait for it to appear on the bus + wait_for_name_owned(m_bus, Bus::Timedate1::BUSNAME); + } + + bool wait_for_tzid(Timezone& tz, const std::string& tzid) + { + return wait_for([&tz, &tzid](){return tzid == tz.timezone.get();}); + } - /* convenience func to set the timezone file */ - void set_file(const std::string& text) + void set_timedate1_timezone(const std::string& tzid) { - g_debug("set_file %s %s", TIMEZONE_FILE, text.c_str()); - auto fp = fopen(TIMEZONE_FILE, "w+"); - fprintf(fp, "%s\n", text.c_str()); - fclose(fp); - sync(); + GError* error {}; + auto v = g_dbus_connection_call_sync( + m_bus, + Bus::Timedate1::BUSNAME, + Bus::Timedate1::ADDR, + Bus::Timedate1::IFACE, + Bus::Timedate1::Methods::SET_TIMEZONE, + g_variant_new("(sb)", tzid.c_str(), FALSE), + nullptr, + G_DBUS_CALL_FLAGS_NONE, + -1, + nullptr, + &error); + g_clear_pointer(&v, g_variant_unref); + g_assert_no_error(error); } }; -/** - * Test that timezone-timedated warns, but doesn't crash, if the timezone file doesn't exist - */ -TEST_F(TimezoneFixture, NoFile) -{ - remove(TIMEZONE_FILE); - ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS)); +/*** +**** +***/ - expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*"); - TimedatedTimezone tz(TIMEZONE_FILE); +TEST_F(Timedate1Fixture, HelloWorld) +{ } /** - * Test that timezone-timedated gives a default of UTC if the file doesn't exist + * Test that we get a default timezone of UTC if timedate1 isn't available on the bus */ -TEST_F(TimezoneFixture, DefaultValueNoFile) +TEST_F(Timedate1Fixture, DefaultTimezone) { - const std::string expected_timezone = "Etc/Utc"; - remove(TIMEZONE_FILE); - ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS)); + const std::string expected_tzid{"Etc/Utc"}; - expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*"); - TimedatedTimezone tz(TIMEZONE_FILE); - ASSERT_EQ(expected_timezone, tz.timezone.get()); + TimedatedTimezone tmp; + EXPECT_TRUE(wait_for_tzid(tmp, expected_tzid)) << "expected " << expected_tzid << " got " << tmp.timezone.get(); } /** - * Test that timezone-timedated picks up the initial value + * Test that we get the right tzid if timedated shows up on the bus BEFORE we start */ -TEST_F(TimezoneFixture, InitialValue) +TEST_F(Timedate1Fixture, Timedate1First) { - const std::string expected_timezone = "America/Chicago"; - set_file(expected_timezone); - TimedatedTimezone tz(TIMEZONE_FILE); + const std::string expected_tzid{"America/Chicago"}; + + start_timedate1(expected_tzid); + TimedatedTimezone tmp; + EXPECT_TRUE(wait_for_tzid(tmp, expected_tzid)) << "expected " << expected_tzid << " got " << tmp.timezone.get(); } /** - * Test that changing the tz after we are running works. + * Test that we get the right tzid if timedated shows up on the bus AFTER we start */ -TEST_F(TimezoneFixture, ChangedValue) +TEST_F(Timedate1Fixture, Timedate1Last) { - const std::string initial_timezone = "America/Chicago"; - const std::string changed_timezone = "America/New_York"; - - set_file(initial_timezone); + const std::string expected_tzid("America/Los_Angeles"); - TimedatedTimezone tz(TIMEZONE_FILE); - ASSERT_EQ(initial_timezone, tz.timezone.get()); - - bool changed = false; - tz.timezone.changed().connect( - [&changed, this](const std::string& s){ - g_message("timezone changed to %s", s.c_str()); - changed = true; - g_main_loop_quit(loop); - }); - - g_idle_add([](gpointer gself){ - static_cast(gself)->set_timezone("America/New_York"); - return G_SOURCE_REMOVE; - }, this); - - g_main_loop_run(loop); - - ASSERT_TRUE(changed); - ASSERT_EQ(changed_timezone, tz.timezone.get()); + TimedatedTimezone tmp; + start_timedate1(expected_tzid); + EXPECT_TRUE(wait_for_tzid(tmp, expected_tzid)) << "expected " << expected_tzid << " got " << tmp.timezone.get(); } /** - * Test that timezone-timedated picks up the initial value + * Test that the timezone core::Property changes when timedate1's property changes */ -TEST_F(TimezoneFixture, IgnoreComments) +TEST_F(Timedate1Fixture, TimezoneChange) { - const std::string comment = "# Created by cloud-init v. 0.7.5 on Thu, 24 Apr 2014 14:03:29 +0000"; - const std::string expected_timezone = "Europe/Berlin"; - set_file(comment + "\n" + expected_timezone); - TimedatedTimezone tz(TIMEZONE_FILE); - ASSERT_EQ(expected_timezone, tz.timezone.get()); + const std::vector expected_tzids{"America/Los_Angeles", "America/Chicago", "Etc/Utc"}; + + TimedatedTimezone tmp; + start_timedate1("America/New_York"); + + for(const auto& expected_tzid : expected_tzids) + { + set_timedate1_timezone(expected_tzid); + EXPECT_TRUE(wait_for_tzid(tmp, expected_tzid)) << "expected " << expected_tzid << " got " << tmp.timezone.get(); + } } -- cgit v1.2.3 From 5c53bbf1552457307fecb8099e0623f078bd68fb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 9 Apr 2016 19:07:04 -0500 Subject: update test-live-actions to last commit's TimedatedFixture changes --- include/datetime/dbus-shared.h | 8 ---- tests/test-live-actions.cpp | 94 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 26 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index fd43ae8..9c80336 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -28,10 +28,6 @@ #define BUS_POWERD_PATH "/com/canonical/powerd" #define BUS_POWERD_INTERFACE "com.canonical.powerd" -namespace ayatana { -namespace indicator { -namespace datetime { - namespace Bus { namespace Timedate1 @@ -67,8 +63,4 @@ namespace Bus } } -} // namespace datetime -} // namespace indicator -} // namespace ayatana - #endif /* INDICATOR_DATETIME_DBUS_SHARED_H */ diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index e7cb1a2..d38893f 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -17,18 +17,75 @@ * Charles Kerr */ +#include "state-mock.h" #include "timedated-fixture.h" +#include + +using namespace ayatana::indicator::datetime; + +class MockLiveActions: public LiveActions +{ +public: + std::string last_cmd; + std::string last_url; + explicit MockLiveActions(const std::shared_ptr& state_in): LiveActions(state_in) {} + ~MockLiveActions() {} + +protected: + void dispatch_url(const std::string& url) override { last_url = url; } + void execute_command(const std::string& cmd) override { last_cmd = cmd; } +}; + +class TestLiveActionsFixture: public TimedatedFixture +{ +private: + + using super = TimedatedFixture; + +protected: + + std::shared_ptr m_mock_state; + std::shared_ptr m_state; + std::shared_ptr m_live_actions; + std::shared_ptr m_actions; + + void SetUp() override + { + super::SetUp(); + + // create the State and Actions + m_mock_state.reset(new MockState); + m_mock_state->settings.reset(new Settings); + m_state = std::dynamic_pointer_cast(m_mock_state); + m_live_actions.reset(new MockLiveActions(m_state)); + m_actions = std::dynamic_pointer_cast(m_live_actions); + + // start the timedate1 dbusmock + start_timedate1("Etc/Utc"); + } + + void TearDown() override + { + m_actions.reset(); + m_live_actions.reset(); + m_state.reset(); + m_mock_state.reset(); + + super::TearDown(); + } +}; + /*** **** ***/ -TEST_F(TimedateFixture, HelloWorld) +TEST_F(TestLiveActionsFixture, HelloWorld) { EXPECT_TRUE(true); } -TEST_F(TimedateFixture, SetLocation) +TEST_F(TestLiveActionsFixture, SetLocation) { const std::string tzid = "America/Chicago"; const std::string name = "Oklahoma City"; @@ -36,30 +93,31 @@ TEST_F(TimedateFixture, SetLocation) EXPECT_NE(expected, m_state->settings->timezone_name.get()); - m_actions->set_location(tzid, name); + std::string new_name; m_state->settings->timezone_name.changed().connect( - [this](const std::string&){ - g_main_loop_quit(loop); - }); - g_main_loop_run(loop); - EXPECT_EQ(attempted_tzid, tzid); - wait_msec(); + [&new_name](const std::string& n){new_name = n;} + ); + + m_actions->set_location(tzid, name); + EXPECT_TRUE(wait_for([&new_name](){return !new_name.empty();})); + EXPECT_EQ(expected, new_name); EXPECT_EQ(expected, m_state->settings->timezone_name.get()); + EXPECT_EQ(tzid, get_timedate1_timezone()); } /*** **** ***/ -TEST_F(TimedateFixture, DesktopOpenAlarmApp) +TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) { m_actions->desktop_open_alarm_app(); const std::string expected = "evolution -c calendar"; EXPECT_EQ(expected, m_live_actions->last_cmd); } -TEST_F(TimedateFixture, DesktopOpenAppointment) +TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) { Appointment a; a.uid = "some-uid"; @@ -69,14 +127,14 @@ TEST_F(TimedateFixture, DesktopOpenAppointment) EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } -TEST_F(TimedateFixture, DesktopOpenCalendarApp) +TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) { m_actions->desktop_open_calendar_app(DateTime::NowLocal()); const std::string expected_substr = "evolution \"calendar:///?startdate="; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } -TEST_F(TimedateFixture, DesktopOpenSettingsApp) +TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) { m_actions->desktop_open_settings_app(); const std::string expected_substr = "control-center"; @@ -92,13 +150,13 @@ namespace const std::string clock_app_url = "appid://com.ubuntu.clock/clock/current-user-version"; } -TEST_F(TimedateFixture, PhoneOpenAlarmApp) +TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) { m_actions->phone_open_alarm_app(); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(TimedateFixture, PhoneOpenAppointment) +TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) { Appointment a; @@ -116,7 +174,7 @@ TEST_F(TimedateFixture, PhoneOpenAppointment) EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(TimedateFixture, PhoneOpenCalendarApp) +TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) { auto now = DateTime::NowLocal(); m_actions->phone_open_calendar_app(now); @@ -125,7 +183,7 @@ TEST_F(TimedateFixture, PhoneOpenCalendarApp) } -TEST_F(TimedateFixture, PhoneOpenSettingsApp) +TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) { m_actions->phone_open_settings_app(); const std::string expected = "settings:///system/time-date"; @@ -136,7 +194,7 @@ TEST_F(TimedateFixture, PhoneOpenSettingsApp) **** ***/ -TEST_F(TimedateFixture, CalendarState) +TEST_F(TestLiveActionsFixture, CalendarState) { // init the clock auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); -- 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 --- include/datetime/timezone-timedated.h | 4 +- src/main.cpp | 14 ++++++- src/timezone-timedated.cpp | 71 +++++++++++++---------------------- 3 files changed, 42 insertions(+), 47 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/timezone-timedated.h b/include/datetime/timezone-timedated.h index 0857706..e0af184 100644 --- a/include/datetime/timezone-timedated.h +++ b/include/datetime/timezone-timedated.h @@ -22,6 +22,8 @@ #include // base class +#include // GDBusConnection* + #include // std::string namespace ayatana { @@ -34,7 +36,7 @@ namespace datetime { class TimedatedTimezone: public Timezone { public: - TimedatedTimezone(); + TimedatedTimezone(GDBusConnection* connection); ~TimedatedTimezone(); private: 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. --- include/datetime/timezones-live.h | 5 ++--- src/timezones-live.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h index e722576..8b8b5fa 100644 --- a/include/datetime/timezones-live.h +++ b/include/datetime/timezones-live.h @@ -23,7 +23,6 @@ #include #include #include -#include #include // shared_ptr<> @@ -38,13 +37,13 @@ namespace datetime { class LiveTimezones: public Timezones { public: - LiveTimezones(const std::shared_ptr& settings); + LiveTimezones(const std::shared_ptr& settings, const std::shared_ptr& primary_timezone); private: void update_geolocation(); void update_timezones(); - TimedatedTimezone m_file; + std::shared_ptr m_primary_timezone; std::shared_ptr m_settings; std::shared_ptr m_geo; }; 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 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. --- .build.yml | 2 - CMakeLists.txt | 11 ---- debian/control | 1 - include/datetime/actions-live.h | 17 ++---- include/datetime/actions.h | 12 ++-- src/CMakeLists.txt | 2 +- src/actions-live.cpp | 126 ++++++++++++++-------------------------- src/actions.cpp | 64 +++++++------------- src/main.cpp | 2 +- tests/CMakeLists.txt | 2 +- tests/actions-mock.h | 44 ++++---------- tests/test-actions.cpp | 16 ++--- tests/test-live-actions.cpp | 23 ++++---- 13 files changed, 108 insertions(+), 214 deletions(-) (limited to 'include/datetime') diff --git a/.build.yml b/.build.yml index e590320..aff4f03 100644 --- a/.build.yml +++ b/.build.yml @@ -41,7 +41,6 @@ requires: - libecal2.0-dev - libical-dev - libedataserver1.2-dev - - liblomiri-url-dispatcher-dev - libproperties-cpp-dev # for the test harness: - libgtest-dev @@ -74,7 +73,6 @@ requires: - libecal2.0-dev - libical-dev - libedataserver1.2-dev - - liblomiri-url-dispatcher-dev - libproperties-cpp-dev ubuntu:focal: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8451544..5cbe59f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,17 +61,6 @@ pkg_check_modules (SERVICE_DEPS REQUIRED libaccounts-glib>=1.18) include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) -set(URL_DISPATCHER_REQUIRED_VERSION 0) -pkg_check_modules(URLDISPATCHER - lomiri-url-dispatcher>=${URL_DISPATCHER_REQUIRED_VERSION} -) -include_directories(${URLDISPATCHER_INCLUDE_DIRS}) - -# url-dispatcher support is optional... -if(URLDISPATCHER_FOUND) - add_definitions( -DHAS_URLDISPATCHER ) -endif() - # lomiri-app-launch pkg_check_modules(LOMIRIAPPLAUNCH lomiri-app-launch>=0) diff --git a/debian/control b/debian/control index 0ede198..a45596d 100644 --- a/debian/control +++ b/debian/control @@ -16,7 +16,6 @@ Build-Depends: cmake, libical-dev (>= 1.0), libedataserver1.2-dev (>= 3.5), accountsservice-ubuntu-schemas | hello, - liblomiri-url-dispatcher-dev | hello, libproperties-cpp-dev, # for the test harness: libgtest-dev , diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 1f84659..1eb34ec 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -40,21 +40,16 @@ public: virtual ~LiveActions() =default; bool desktop_has_calendar_app() const override; - void desktop_open_alarm_app() override; - void desktop_open_appointment(const Appointment&, const DateTime&) override; - void desktop_open_calendar_app(const DateTime&) override; - void desktop_open_settings_app() override; - - void phone_open_alarm_app() override; - void phone_open_appointment(const Appointment&, const DateTime &) override; - void phone_open_calendar_app(const DateTime&) override; - void phone_open_settings_app() override; + void open_alarm_app() override; + void open_appointment(const Appointment&, const DateTime&) override; + void open_calendar_app(const DateTime&) override; + void open_settings_app() override; void set_location(const std::string& zone, const std::string& name) override; protected: - virtual void execute_command(const std::string& command); - virtual void dispatch_url(const std::string& url); + + void lomiri_open_appointment(const Appointment& appt, const DateTime& date); }; } // namespace datetime diff --git a/include/datetime/actions.h b/include/datetime/actions.h index ea163e4..d866b00 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -44,15 +44,11 @@ class Actions public: virtual bool desktop_has_calendar_app() const =0; - virtual void desktop_open_alarm_app() =0; - virtual void desktop_open_appointment(const Appointment&, const DateTime&) =0; - virtual void desktop_open_calendar_app(const DateTime&) =0; - virtual void desktop_open_settings_app() =0; - virtual void phone_open_alarm_app() =0; - virtual void phone_open_appointment(const Appointment&, const DateTime&) =0; - virtual void phone_open_calendar_app(const DateTime&) =0; - virtual void phone_open_settings_app() =0; + virtual void open_alarm_app() =0; + virtual void open_appointment(const Appointment&, const DateTime&) =0; + virtual void open_calendar_app(const DateTime&) =0; + virtual void open_settings_app() =0; virtual void set_location(const std::string& zone, const std::string& name)=0; 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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b9a804..5c44ba3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,7 +44,7 @@ function(add_test_by_name name) set (TEST_NAME ${name}) add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) add_test (${TEST_NAME} ${TEST_NAME}) - target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS} ${URLDISPATCHER_LIBRARIES}) + target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) endfunction() add_test_by_name(test-datetime) if(HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS) diff --git a/tests/actions-mock.h b/tests/actions-mock.h index 346a8f6..a02a7e2 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -34,14 +34,10 @@ public: explicit MockActions(const std::shared_ptr& state_in): Actions(state_in) {} ~MockActions() =default; - enum Action { DesktopOpenAlarmApp, - DesktopOpenAppt, - DesktopOpenCalendarApp, - DesktopOpenSettingsApp, - PhoneOpenAlarmApp, - PhoneOpenAppt, - PhoneOpenCalendarApp, - PhoneOpenSettingsApp, + enum Action { OpenAlarmApp, + OpenAppt, + OpenCalendarApp, + OpenSettingsApp, SetLocation }; const std::vector& history() const { return m_history; } @@ -54,36 +50,20 @@ public: bool desktop_has_calendar_app() const { return m_desktop_has_calendar_app; } - void desktop_open_alarm_app() { - m_history.push_back(DesktopOpenAlarmApp); + void open_alarm_app() { + m_history.push_back(OpenAlarmApp); } - void desktop_open_appointment(const Appointment& appt, const DateTime& dt) { + void open_appointment(const Appointment& appt, const DateTime& dt) { m_appt = appt; m_date_time = dt; - m_history.push_back(DesktopOpenAppt); + m_history.push_back(OpenAppt); } - void desktop_open_calendar_app(const DateTime& dt) { + void open_calendar_app(const DateTime& dt) { m_date_time = dt; - m_history.push_back(DesktopOpenCalendarApp); + m_history.push_back(OpenCalendarApp); } - void desktop_open_settings_app() { - m_history.push_back(DesktopOpenSettingsApp); - } - - void phone_open_alarm_app() { - m_history.push_back(PhoneOpenAlarmApp); - } - void phone_open_appointment(const Appointment& appt, const DateTime& dt) { - m_appt = appt; - m_date_time = dt; - m_history.push_back(PhoneOpenAppt); - } - void phone_open_calendar_app(const DateTime& dt) { - m_date_time = dt; - m_history.push_back(PhoneOpenCalendarApp); - } - void phone_open_settings_app() { - m_history.push_back(PhoneOpenSettingsApp); + void open_settings_app() { + m_history.push_back(OpenSettingsApp); } void set_location(const std::string& zone_, const std::string& name_) { diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 96da7cc..a01fb83 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -176,25 +176,25 @@ TEST_F(ActionsFixture, ActionsExist) TEST_F(ActionsFixture, DesktopOpenAlarmApp) { test_action_with_no_args("desktop.open-alarm-app", - MockActions::DesktopOpenAlarmApp); + MockActions::OpenAlarmApp); } TEST_F(ActionsFixture, DesktopOpenAppointment) { test_action_with_appt_arg("desktop.open-appointment", - MockActions::DesktopOpenAppt); + MockActions::OpenAppt); } TEST_F(ActionsFixture, DesktopOpenCalendarApp) { test_action_with_time_arg("desktop.open-calendar-app", - MockActions::DesktopOpenCalendarApp); + MockActions::OpenCalendarApp); } TEST_F(ActionsFixture, DesktopOpenSettingsApp) { test_action_with_no_args("desktop.open-settings-app", - MockActions::DesktopOpenSettingsApp); + MockActions::OpenSettingsApp); } /*** @@ -204,25 +204,25 @@ TEST_F(ActionsFixture, DesktopOpenSettingsApp) TEST_F(ActionsFixture, PhoneOpenAlarmApp) { test_action_with_no_args("phone.open-alarm-app", - MockActions::PhoneOpenAlarmApp); + MockActions::OpenAlarmApp); } TEST_F(ActionsFixture, PhoneOpenAppointment) { test_action_with_appt_arg("phone.open-appointment", - MockActions::PhoneOpenAppt); + MockActions::OpenAppt); } TEST_F(ActionsFixture, PhoneOpenCalendarApp) { test_action_with_time_arg("phone.open-calendar-app", - MockActions::PhoneOpenCalendarApp); + MockActions::OpenCalendarApp); } TEST_F(ActionsFixture, PhoneOpenSettingsApp) { test_action_with_no_args("phone.open-settings-app", - MockActions::PhoneOpenSettingsApp); + MockActions::OpenSettingsApp); } /*** diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index d38893f..12ef362 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -29,12 +29,9 @@ class MockLiveActions: public LiveActions public: std::string last_cmd; std::string last_url; + explicit MockLiveActions(const std::shared_ptr& state_in): LiveActions(state_in) {} ~MockLiveActions() {} - -protected: - void dispatch_url(const std::string& url) override { last_url = url; } - void execute_command(const std::string& cmd) override { last_cmd = cmd; } }; class TestLiveActionsFixture: public TimedatedFixture @@ -112,7 +109,7 @@ TEST_F(TestLiveActionsFixture, SetLocation) TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) { - m_actions->desktop_open_alarm_app(); + m_actions->open_alarm_app(); const std::string expected = "evolution -c calendar"; EXPECT_EQ(expected, m_live_actions->last_cmd); } @@ -122,21 +119,21 @@ TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) Appointment a; a.uid = "some-uid"; a.begin = DateTime::NowLocal(); - m_actions->desktop_open_appointment(a, a.begin); + m_actions->open_appointment(a, a.begin); const std::string expected_substr = "evolution \"calendar:///?startdate="; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) { - m_actions->desktop_open_calendar_app(DateTime::NowLocal()); + m_actions->open_calendar_app(DateTime::NowLocal()); const std::string expected_substr = "evolution \"calendar:///?startdate="; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) { - m_actions->desktop_open_settings_app(); + m_actions->open_settings_app(); const std::string expected_substr = "control-center"; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } @@ -152,7 +149,7 @@ namespace TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->phone_open_alarm_app(); + m_actions->open_alarm_app(); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } @@ -165,19 +162,19 @@ TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) a.begin = DateTime::NowLocal(); a.type = Appointment::EVENT; auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0); - m_actions->phone_open_appointment(a, ocurrenceDate); + m_actions->open_appointment(a, ocurrenceDate); const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); EXPECT_EQ(appointment_app_url, m_live_actions->last_url); a.type = Appointment::UBUNTU_ALARM; - m_actions->phone_open_appointment(a, a.begin); + m_actions->open_appointment(a, a.begin); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) { auto now = DateTime::NowLocal(); - m_actions->phone_open_calendar_app(now); + m_actions->open_calendar_app(now); const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); EXPECT_EQ(expected, m_live_actions->last_url); } @@ -185,7 +182,7 @@ TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) { - m_actions->phone_open_settings_app(); + m_actions->open_settings_app(); const std::string expected = "settings:///system/time-date"; EXPECT_EQ(expected, m_live_actions->last_url); } -- 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 --- include/datetime/snap.h | 6 +++--- src/main.cpp | 21 ++++++++++++++------- src/snap.cpp | 39 +++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 26 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/snap.h b/include/datetime/snap.h index a295d9f..099426b 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -42,11 +42,11 @@ public: const std::shared_ptr& settings); virtual ~Snap(); - typedef std::function appointment_func; + enum class Response { None, Snooze, ShowApp }; + typedef std::function response_func; void operator()(const Appointment& appointment, const Alarm& alarm, - appointment_func snooze, - appointment_func ok); + response_func on_response); private: class Impl; 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 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 --- include/datetime/settings-live.h | 12 ++-- include/datetime/settings-shared.h | 9 ++- include/datetime/settings.h | 6 +- src/settings-live.cpp | 115 ++++++++++++++++++++++--------------- src/snap.cpp | 45 ++++++++++----- tests/test-notification.cpp | 26 ++++----- tests/test-settings.cpp | 111 ++++++++++++++--------------------- 7 files changed, 173 insertions(+), 151 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 330b8e8..4aeaa9b 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -39,9 +39,9 @@ public: private: static void on_changed_ccid(GSettings*, gchar*, gpointer); - static void on_changed_cunh(GSettings*, gchar*, gpointer); + static void on_changed_cal_notification(GSettings*, gchar*, gpointer); void update_key_ccid(const std::string& key); - void update_key_cunh(const std::string& key); + void update_key_cal_notification(const std::string& key); void update_custom_time_format(); void update_locations(); @@ -62,10 +62,14 @@ private: void update_alarm_duration(); void update_alarm_haptic(); void update_snooze_duration(); - void update_muted_apps(); + void update_cal_notification_enabled(); + void update_cal_notification_sounds(); + void update_cal_notification_vibrations(); + void update_cal_notification_bubbles(); + void update_cal_notification_list(); GSettings* m_settings; - GSettings* m_settings_cunh; + GSettings* m_settings_cal_notification; // we've got a raw pointer here, so disable copying LiveSettings(const LiveSettings&) =delete; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index f385e7a..236b8f1 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -51,7 +51,12 @@ TimeFormatMode; #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" -#define SETTINGS_CUNH_SCHEMA_ID "com.lomiri.notifications.hub" -#define SETTINGS_CUNH_BLACKLIST_S "blacklist" +#define SETTINGS_NOTIFY_SCHEMA_ID "com.lomiri.notifications.settings" +#define SETTINGS_NOTIFY_CALENDAR_PATH "/com/lomiri/NotificationSettings/com.lomiri.calendar/calendar/" +#define SETTINGS_NOTIFY_ENABLED_KEY "enable-notifications" +#define SETTINGS_NOTIFY_SOUNDS_KEY "use-sounds-notifications" +#define SETTINGS_NOTIFY_VIBRATIONS_KEY "use-vibrations-notifications" +#define SETTINGS_NOTIFY_BUBBLES_KEY "use-bubbles-notifications" +#define SETTINGS_NOTIFY_LIST_KEY "use-list-notifications" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index d5e81c6..5ae00f6 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -61,7 +61,11 @@ public: core::Property alarm_volume; core::Property alarm_duration; core::Property snooze_duration; - core::Property>> muted_apps; + core::Property cal_notification_enabled; + core::Property cal_notification_sounds; + core::Property cal_notification_vibrations; + core::Property cal_notification_bubbles; + core::Property cal_notification_list; }; } // namespace datetime 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) diff --git a/tests/test-notification.cpp b/tests/test-notification.cpp index 50d7b57..b84c6f8 100644 --- a/tests/test-notification.cpp +++ b/tests/test-notification.cpp @@ -87,18 +87,16 @@ TEST_F(NotificationFixture,Notification) { false, true, false } }; - // combinatorial factor #4: system settings' notifications app blacklist - const std::set> blacklist_calendar { std::make_pair(std::string{"com.lomiri.calendar"}, std::string{"calendar-app"}) }; - const std::set> blacklist_empty; + // combinatorial factor #4: system settings' notifications disabled struct { - std::set> muted_apps; // apps that should not trigger notifications + bool cal_notification_enabled; // calendar app can trigger notifications std::set expected_notify_called; // do we expect the notification to show? std::set expected_vibrate_called; // do we expect the phone to vibrate? - } test_muted_apps[] = { - { blacklist_empty, std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT }, - std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } }, - { blacklist_calendar, std::set{ Appointment::Type::UBUNTU_ALARM }, - std::set{ Appointment::Type::UBUNTU_ALARM } } + } test_cal_disabled[] = { + { true, std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT }, + std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } }, + { false, std::set{ Appointment::Type::UBUNTU_ALARM }, + std::set{ Appointment::Type::UBUNTU_ALARM } } }; for (const auto& test_appt : test_appts) @@ -107,20 +105,20 @@ TEST_F(NotificationFixture,Notification) { for (const auto& test_vibes : test_other_vibrations) { - for (const auto& test_muted : test_muted_apps) + for (const auto& test_disabled : test_cal_disabled) { const bool expected_notify_called = test_appt.expected_notify_called && test_vibes.expected_notify_called - && (test_muted.expected_notify_called.count(test_appt.appt.type) > 0) + && (test_disabled.expected_notify_called.count(test_appt.appt.type) > 0) && test_haptic.expected_notify_called; const bool expected_vibrate_called = test_appt.expected_vibrate_called && test_vibes.expected_vibrate_called - && (test_muted.expected_vibrate_called.count(test_appt.appt.type) > 0) + && (test_disabled.expected_vibrate_called.count(test_appt.appt.type) > 0) && test_haptic.expected_vibrate_called; - // set test case properties: blacklist - settings->muted_apps.set(test_muted.muted_apps); + // set test case properties: cal_notification_enabled + settings->cal_notification_enabled.set(test_disabled.cal_notification_enabled); // set test case properties: haptic mode settings->alarm_haptic.set(test_haptic.haptic_mode); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index d18b58a..d0ee369 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -43,7 +43,7 @@ protected: std::shared_ptr m_live; std::shared_ptr m_settings; GSettings * m_gsettings; - GSettings * m_gsettings_cunh; + GSettings * m_gsettings_cal_notification; void SetUp() override { @@ -53,7 +53,7 @@ protected: if (ayatana_common_utils_is_lomiri()) { - m_gsettings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); } m_live.reset(new LiveSettings); @@ -62,7 +62,7 @@ protected: void TearDown() override { - g_clear_object(&m_gsettings_cunh); + g_clear_object(&m_gsettings_cal_notification); g_clear_object(&m_gsettings); m_settings.reset(); m_live.reset(); @@ -70,62 +70,62 @@ protected: super::TearDown(); } - void TestBoolProperty(core::Property& property, const gchar* key) + void TestBoolProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - EXPECT_EQ(g_settings_get_boolean(m_gsettings, key), property.get()); - g_settings_set_boolean(m_gsettings, key, false); + EXPECT_EQ(g_settings_get_boolean(gsettings, key), property.get()); + g_settings_set_boolean(gsettings, key, false); EXPECT_FALSE(property.get()); - g_settings_set_boolean(m_gsettings, key, true); + g_settings_set_boolean(gsettings, key, true); EXPECT_TRUE(property.get()); property.set(false); - EXPECT_FALSE(g_settings_get_boolean(m_gsettings, key)); + EXPECT_FALSE(g_settings_get_boolean(gsettings, key)); property.set(true); - EXPECT_TRUE(g_settings_get_boolean(m_gsettings, key)); + EXPECT_TRUE(g_settings_get_boolean(gsettings, key)); } - void TestStringProperty(core::Property& property, const gchar* key) + void TestStringProperty(GSettings* gsettings, core::Property& property, const gchar* key) { gchar* tmp; std::string str; - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(tmp, property.get()); g_clear_pointer(&tmp, g_free); str = "a"; - g_settings_set_string(m_gsettings, key, str.c_str()); + g_settings_set_string(gsettings, key, str.c_str()); EXPECT_EQ(str, property.get()); str = "b"; - g_settings_set_string(m_gsettings, key, str.c_str()); + g_settings_set_string(gsettings, key, str.c_str()); EXPECT_EQ(str, property.get()); str = "a"; property.set(str); - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(str, tmp); g_clear_pointer(&tmp, g_free); str = "b"; property.set(str); - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(str, tmp); g_clear_pointer(&tmp, g_free); } - void TestUIntProperty(core::Property& property, const gchar* key) + void TestUIntProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get()); + EXPECT_EQ(g_settings_get_uint(gsettings, key), property.get()); unsigned int expected_values[] = { 1, 2, 3 }; // modify GSettings and confirm that the new value is propagated for(const auto& expected_value : expected_values) { - g_settings_set_uint(m_gsettings, key, expected_value); + g_settings_set_uint(gsettings, key, expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key)); } // modify the property and confirm that the new value is propagated @@ -133,7 +133,7 @@ protected: { property.set(expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key)); } } }; @@ -149,31 +149,31 @@ TEST_F(SettingsFixture, HelloWorld) TEST_F(SettingsFixture, BoolProperties) { - TestBoolProperty(m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); - TestBoolProperty(m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); - TestBoolProperty(m_settings->show_date, SETTINGS_SHOW_DATE_S); - TestBoolProperty(m_settings->show_day, SETTINGS_SHOW_DAY_S); - TestBoolProperty(m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S); - TestBoolProperty(m_settings->show_events, SETTINGS_SHOW_EVENTS_S); - TestBoolProperty(m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S); - TestBoolProperty(m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S); - TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S); + TestBoolProperty(m_gsettings, m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); + TestBoolProperty(m_gsettings, m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); + TestBoolProperty(m_gsettings, m_settings->show_date, SETTINGS_SHOW_DATE_S); + TestBoolProperty(m_gsettings, m_settings->show_day, SETTINGS_SHOW_DAY_S); + TestBoolProperty(m_gsettings, m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S); + TestBoolProperty(m_gsettings, m_settings->show_events, SETTINGS_SHOW_EVENTS_S); + TestBoolProperty(m_gsettings, m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S); + TestBoolProperty(m_gsettings, m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S); + TestBoolProperty(m_gsettings, m_settings->show_year, SETTINGS_SHOW_YEAR_S); } TEST_F(SettingsFixture, UIntProperties) { - TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); - TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); - TestUIntProperty(m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); + TestUIntProperty(m_gsettings, m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestUIntProperty(m_gsettings, m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); + TestUIntProperty(m_gsettings, m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); } TEST_F(SettingsFixture, StringProperties) { - TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); - TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); - TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); - TestStringProperty(m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S); - TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); + TestStringProperty(m_gsettings, m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); + TestStringProperty(m_gsettings, m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); + TestStringProperty(m_gsettings, m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); + TestStringProperty(m_gsettings, m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S); + TestStringProperty(m_gsettings, m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); } TEST_F(SettingsFixture, TimeFormatMode) @@ -237,36 +237,9 @@ TEST_F(SettingsFixture, Locations) TEST_F(SettingsFixture, MutedApps) { - const auto key = SETTINGS_CUNH_BLACKLIST_S; - - struct { - std::string pkgname; - std::string appname; - } apps[] = { - { "", "lomiri-system-settings" }, - { "com.lomiri.calendar", "calendar" }, - { "com.lomiri.developer.webapps.webapp-facebook", "webapp-facebook" }, - { "com.lomiri.reminders", "reminders" } - }; - std::set> apps_set; - for (const auto& app : apps) - apps_set.insert(std::make_pair(app.pkgname, app.appname)); - - // test that changing Settings is reflected in the schema - m_settings->muted_apps.set(apps_set); - auto v = g_settings_get_value(m_gsettings_cunh, key); - auto str = g_variant_print(v, true); - EXPECT_STREQ("[('', 'lomiri-system-settings'), ('com.lomiri.calendar', 'calendar'), ('com.lomiri.developer.webapps.webapp-facebook', 'webapp-facebook'), ('com.lomiri.reminders', 'reminders')]", str); - g_clear_pointer(&str, g_free); - - // test that clearing the schema clears the settings - g_settings_reset(m_gsettings_cunh, key); - EXPECT_EQ(0, m_settings->muted_apps.get().size()); - - // test thst setting the schema updates the settings - g_settings_set_value(m_gsettings_cunh, key, v); - EXPECT_EQ(apps_set, m_settings->muted_apps.get()); - - // cleanup - g_clear_pointer(&v, g_variant_unref); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_bubbles, SETTINGS_NOTIFY_BUBBLES_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_list, SETTINGS_NOTIFY_LIST_KEY); } -- 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 --- include/datetime/settings-live.h | 4 ++++ include/datetime/settings-shared.h | 2 ++ include/datetime/settings.h | 1 + src/settings-live.cpp | 38 +++++++++++++++++++++++++++++++++++--- src/snap.cpp | 20 ++++++++++++++------ 5 files changed, 56 insertions(+), 9 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 4aeaa9b..85071ce 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -40,8 +40,10 @@ public: private: static void on_changed_ccid(GSettings*, gchar*, gpointer); static void on_changed_cal_notification(GSettings*, gchar*, gpointer); + static void on_changed_general_notification(GSettings*, gchar*, gpointer); void update_key_ccid(const std::string& key); void update_key_cal_notification(const std::string& key); + void update_key_general_notification(const std::string& key); void update_custom_time_format(); void update_locations(); @@ -67,9 +69,11 @@ private: void update_cal_notification_vibrations(); void update_cal_notification_bubbles(); void update_cal_notification_list(); + void update_vibrate_silent_mode(); GSettings* m_settings; GSettings* m_settings_cal_notification; + GSettings* m_settings_general_notification; // we've got a raw pointer here, so disable copying LiveSettings(const LiveSettings&) =delete; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 236b8f1..7280c16 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -51,6 +51,8 @@ TimeFormatMode; #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" +#define SETTINGS_NOTIFY_APPS_SCHEMA_ID "com.lomiri.notifications.settings.applications" +#define SETTINGS_VIBRATE_SILENT_KEY "vibrate-silent-mode" #define SETTINGS_NOTIFY_SCHEMA_ID "com.lomiri.notifications.settings" #define SETTINGS_NOTIFY_CALENDAR_PATH "/com/lomiri/NotificationSettings/com.lomiri.calendar/calendar/" #define SETTINGS_NOTIFY_ENABLED_KEY "enable-notifications" diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 5ae00f6..af9227d 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -66,6 +66,7 @@ public: core::Property cal_notification_vibrations; core::Property cal_notification_bubbles; core::Property cal_notification_list; + core::Property vibrate_silent_mode; }; } // namespace datetime 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 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 --- include/datetime/snap.h | 7 ++++++- src/snap.cpp | 36 +++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/snap.h b/include/datetime/snap.h index 099426b..baa765b 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -24,6 +24,9 @@ #include #include +#include + +#include // GDBusConnection #include #include @@ -39,7 +42,9 @@ class Snap { public: Snap(const std::shared_ptr& engine, - const std::shared_ptr& settings); + const std::shared_ptr& sound_builder, + const std::shared_ptr& settings, + GDBusConnection* system_bus); virtual ~Snap(); enum class Response { None, Snooze, ShowApp }; 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 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 --- .build.yml | 22 +++++++------- include/datetime/actions-live.h | 8 +++--- include/datetime/actions.h | 8 +++--- src/actions-live.cpp | 57 +++++++++++++++++++++++++----------- tests/CMakeLists.txt | 39 ++++++++++++++----------- tests/actions-mock.h | 16 ++++++++--- tests/run-eds-ics-test.sh | 2 -- tests/test-formatter.cpp | 2 +- tests/test-live-actions.cpp | 64 +++++++++++++++++++++++++++-------------- tests/test-settings.cpp | 18 ++++++++---- tests/test-timezones.cpp | 21 +++----------- 11 files changed, 153 insertions(+), 104 deletions(-) (limited to 'include/datetime') diff --git a/.build.yml b/.build.yml index ee79826..e38f4ae 100644 --- a/.build.yml +++ b/.build.yml @@ -159,14 +159,14 @@ build_scripts: - scan-build $CHECKERS --keep-cc -o html-report make - fi -#after_scripts: -# - if [ ${BUILD_TYPE} == "scripts" ];then -# - XVFB_RUN="$(which xvfb-run || true)" -# - if [ ${DISTRO_NAME} == "debian" ];then -# - if [ -e ./autogen.sh ]; then -# - ${XVFB_RUN} make check -# - elif [ -e ./CMakeLists.txt ]; then -# - ${XVFB_RUN} make test -# - fi -# - fi -# - fi +after_scripts: + - if [ ${BUILD_TYPE} == "scripts" ];then + - XVFB_RUN="$(which xvfb-run || true)" + - if [ ${DISTRO_NAME} == "debian" ];then + - if [ -e ./autogen.sh ]; then + - ${XVFB_RUN} make check + - elif [ -e ./CMakeLists.txt ]; then + - ${XVFB_RUN} make test + - fi + - fi + - fi diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 1eb34ec..136812c 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -40,10 +40,10 @@ public: virtual ~LiveActions() =default; bool desktop_has_calendar_app() const override; - void open_alarm_app() override; - void open_appointment(const Appointment&, const DateTime&) override; - void open_calendar_app(const DateTime&) override; - void open_settings_app() override; + std::string open_alarm_app() override; + std::string open_appointment(const Appointment&, const DateTime&) override; + std::string open_calendar_app(const DateTime&) override; + std::string open_settings_app() override; void set_location(const std::string& zone, const std::string& name) override; diff --git a/include/datetime/actions.h b/include/datetime/actions.h index d866b00..5927967 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -45,10 +45,10 @@ public: virtual bool desktop_has_calendar_app() const =0; - virtual void open_alarm_app() =0; - virtual void open_appointment(const Appointment&, const DateTime&) =0; - virtual void open_calendar_app(const DateTime&) =0; - virtual void open_settings_app() =0; + virtual std::string open_alarm_app() =0; + virtual std::string open_appointment(const Appointment&, const DateTime&) =0; + virtual std::string open_calendar_app(const DateTime&) =0; + virtual std::string open_settings_app() =0; virtual void set_location(const std::string& zone, const std::string& name)=0; 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; } /*** diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 71235dd..3a476e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,7 +22,7 @@ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compil OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled DEPENDS ${CMAKE_BINARY_DIR}/data/org.ayatana.indicator.datetime.gschema.xml - COMMAND cp -n ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} + COMMAND cp -n ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} || echo "Skip copying schema file, another thread is doing it already" COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) # look for headers in our src dir, and also in the directories where we autogenerate files... @@ -50,14 +50,22 @@ add_test_by_name(test-notification-response) endif() add_test_by_name(test-actions) add_test_by_name(test-alarm-queue) -add_test(NAME dear-reader-the-next-test-takes-60-seconds COMMAND true) -add_test_by_name(test-clock) -add_test_by_name(test-exporter) + +if (NOT DEFINED ENV{TRAVIS}) + add_test(NAME dear-reader-the-next-test-takes-60-seconds COMMAND true) + add_test_by_name(test-clock) + add_test_by_name(test-exporter) +endif() + add_test_by_name(test-formatter) add_test_by_name(test-live-actions) add_test_by_name(test-locations) add_test_by_name(test-menu-appointments) -add_test_by_name(test-menus) + +if (NOT DEFINED ENV{TRAVIS}) + add_test_by_name(test-menus) +endif() + add_test_by_name(test-planner) add_test_by_name(test-settings) add_test_by_name(test-timezone-timedated) @@ -103,18 +111,15 @@ add_eds_ics_test_by_name(test-eds-ics-tzids-utc) add_eds_ics_test_by_name(test-eds-ics-non-attending-alarms) add_eds_ics_test_by_name(test-eds-ics-repeating-events-with-individual-change) -# disabling the timezone unit tests because they require -# https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724 -# which hasn't landed yet. These can be re-enabled as soon as that lands. -#function(add_dbusmock_test_by_name name) -# set (TEST_NAME ${name}) -# set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) -# add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) -# add_test (${TEST_NAME} ${TEST_NAME}) -# target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) -#endfunction() -#add_dbusmock_test_by_name(test-timezone-geoclue) -#add_dbusmock_test_by_name(test-timezones) +function(add_dbusmock_test_by_name name) + set (TEST_NAME ${name}) + set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) + add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) + add_test (${TEST_NAME} ${TEST_NAME}) + target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) +endfunction() +add_dbusmock_test_by_name(test-timezone-geoclue) +add_dbusmock_test_by_name(test-timezones) set( COVERAGE_TEST_TARGETS diff --git a/tests/actions-mock.h b/tests/actions-mock.h index a02a7e2..8de1357 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -50,20 +50,28 @@ public: bool desktop_has_calendar_app() const { return m_desktop_has_calendar_app; } - void open_alarm_app() { + std::string open_alarm_app() { m_history.push_back(OpenAlarmApp); + + return ""; } - void open_appointment(const Appointment& appt, const DateTime& dt) { + std::string open_appointment(const Appointment& appt, const DateTime& dt) { m_appt = appt; m_date_time = dt; m_history.push_back(OpenAppt); + + return ""; } - void open_calendar_app(const DateTime& dt) { + std::string open_calendar_app(const DateTime& dt) { m_date_time = dt; m_history.push_back(OpenCalendarApp); + + return ""; } - void open_settings_app() { + std::string open_settings_app() { m_history.push_back(OpenSettingsApp); + + return ""; } void set_location(const std::string& zone_, const std::string& name_) { diff --git a/tests/run-eds-ics-test.sh b/tests/run-eds-ics-test.sh index b38fe77..7db9f1b 100755 --- a/tests/run-eds-ics-test.sh +++ b/tests/run-eds-ics-test.sh @@ -71,5 +71,3 @@ rv=$? if [ $rv -eq 0 ]; then rm -rf $TEST_TMP_DIR fi - -return $rv diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index 87c6475..a8d798b 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -72,7 +72,7 @@ class FormatterFixture: public GlibFixture } else { - g_warning("Unable to set locale to %s; skipping %s locale tests. (Current LC_TIME: %s)", + g_message("Unable to set locale to %s; skipping %s locale tests. (Current LC_TIME: %s)", expected_locale, name, setlocale(LC_TIME, nullptr)); return false; } diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 2d6ac9b..403aeef 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -22,13 +22,16 @@ #include +extern "C" +{ + #include +} + using namespace ayatana::indicator::datetime; class MockLiveActions: public LiveActions { public: - std::string last_cmd; - std::string last_url; explicit MockLiveActions(const std::shared_ptr& state_in): LiveActions(state_in) {} ~MockLiveActions() {} @@ -109,9 +112,9 @@ TEST_F(TestLiveActionsFixture, SetLocation) TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) { - m_actions->open_alarm_app(); + std::string sReturn = m_actions->open_alarm_app(); const std::string expected = "evolution -c calendar"; - EXPECT_EQ(expected, m_live_actions->last_cmd); + EXPECT_EQ(expected, sReturn); } TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) @@ -119,23 +122,33 @@ TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) Appointment a; a.uid = "some-uid"; a.begin = DateTime::NowLocal(); - m_actions->open_appointment(a, a.begin); + std::string sReturn = m_actions->open_appointment(a, a.begin); const std::string expected_substr = "evolution \"calendar:///?startdate="; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + EXPECT_NE(sReturn.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) { - m_actions->open_calendar_app(DateTime::NowLocal()); + std::string sReturn = m_actions->open_calendar_app(DateTime::NowLocal()); const std::string expected_substr = "evolution \"calendar:///?startdate="; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + EXPECT_NE(sReturn.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) { - m_actions->open_settings_app(); - const std::string expected_substr = "control-center"; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + std::string sReturn = m_actions->open_settings_app(); + std::string expected_substr = "gnome-control-center datetime"; + + if (ayatana_common_utils_is_unity()) + { + expected_substr = "unity-control-center datetime"; + } + else if (ayatana_common_utils_is_mate()) + { + expected_substr = "mate-time-admin"; + } + + EXPECT_EQ(expected_substr, sReturn); } /*** @@ -149,12 +162,16 @@ namespace TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->open_alarm_app(); - EXPECT_EQ(clock_app_url, m_live_actions->last_url); + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + std::string sReturn = m_actions->open_alarm_app(); + EXPECT_EQ(clock_app_url, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) { + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + Appointment a; a.uid = "event-uid"; @@ -162,29 +179,34 @@ TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) a.begin = DateTime::NowLocal(); a.type = Appointment::EVENT; auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0); - m_actions->open_appointment(a, ocurrenceDate); + std::string sReturn = m_actions->open_appointment(a, ocurrenceDate); const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - EXPECT_EQ(appointment_app_url, m_live_actions->last_url); + EXPECT_EQ(appointment_app_url, sReturn); a.type = Appointment::UBUNTU_ALARM; - m_actions->open_appointment(a, a.begin); - EXPECT_EQ(clock_app_url, m_live_actions->last_url); + sReturn = m_actions->open_appointment(a, a.begin); + EXPECT_EQ(clock_app_url, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) { + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); auto now = DateTime::NowLocal(); - m_actions->open_calendar_app(now); + std::string sReturn = m_actions->open_calendar_app(now); const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - EXPECT_EQ(expected, m_live_actions->last_url); + EXPECT_EQ(expected, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) { - m_actions->open_settings_app(); + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + std::string sReturn = m_actions->open_settings_app(); const std::string expected = "settings:///system/time-date"; - EXPECT_EQ(expected, m_live_actions->last_url); + EXPECT_EQ(expected, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } /*** diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index b9658f4..e24228d 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -22,11 +22,6 @@ #include #include -extern "C" -{ - #include -} - using namespace ayatana::indicator::datetime; /*** @@ -50,7 +45,18 @@ protected: super::SetUp(); m_gsettings = g_settings_new(SETTINGS_INTERFACE); - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + GSettingsSchemaSource *pSource = g_settings_schema_source_get_default(); + GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, SETTINGS_NOTIFY_SCHEMA_ID, TRUE); + + if (pSchema != NULL) + { + g_settings_schema_unref(pSchema); + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } + else + { + m_gsettings_cal_notification = NULL; + } m_live.reset(new LiveSettings); m_settings = std::dynamic_pointer_cast(m_live); diff --git a/tests/test-timezones.cpp b/tests/test-timezones.cpp index 362fcf7..7144aaf 100644 --- a/tests/test-timezones.cpp +++ b/tests/test-timezones.cpp @@ -18,10 +18,10 @@ */ #include "geoclue-fixture.h" - +#include "timezone-mock.h" #include #include - +#include #include // std::shared_ptr #include // fopen() @@ -53,7 +53,8 @@ TEST_F(TimezonesFixture, ManagerTest) set_file(timezone_file); auto settings = std::make_shared(); - LiveTimezones z(settings, TIMEZONE_FILE); + auto timezone = std::make_shared(timezone_file); + LiveTimezones z(settings, timezone); wait_msec(500); // wait for the bus to get set up EXPECT_EQ(timezone_file, z.timezone.get()); auto zones = z.timezones.get(); @@ -105,20 +106,6 @@ TEST_F(TimezonesFixture, ManagerTest) EXPECT_EQ(2, zones.size()); EXPECT_EQ(1, zones.count(timezone_file)); EXPECT_EQ(1, zones.count(timezone_geo)); - - // now set the file value... this should change both the primary property and set property - zone_changed = false; - zones_changed = false; - timezone_file = "America/Los_Angeles"; - EXPECT_EQ(0, zones.count(timezone_file)); - g_idle_add([](gpointer str) {set_file(static_cast(str)); return G_SOURCE_REMOVE;}, const_cast(timezone_file.c_str())); - g_main_loop_run(loop); - EXPECT_TRUE(zone_changed); - EXPECT_TRUE(zones_changed); - EXPECT_EQ(timezone_file, z.timezone.get()); - EXPECT_EQ(2, zones.size()); - EXPECT_EQ(1, zones.count(timezone_file)); - EXPECT_EQ(1, zones.count(timezone_geo)); } -- 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 --- include/datetime/dbus-shared.h | 6 +++--- include/notifications/dbus-shared.h | 6 +++--- src/clock.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index 9c80336..0b6aa95 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -24,9 +24,9 @@ #define BUS_DATETIME_NAME "org.ayatana.indicator.datetime" #define BUS_DATETIME_PATH "/org/ayatana/indicator/datetime" -#define BUS_POWERD_NAME "com.canonical.powerd" -#define BUS_POWERD_PATH "/com/canonical/powerd" -#define BUS_POWERD_INTERFACE "com.canonical.powerd" +#define BUS_POWERD_NAME "com.lomiri.Repowerd" +#define BUS_POWERD_PATH "/com/lomiri/Repowerd" +#define BUS_POWERD_INTERFACE "com.lomiri.Repowerd" namespace Bus { diff --git a/include/notifications/dbus-shared.h b/include/notifications/dbus-shared.h index 523fb2a..31df219 100644 --- a/include/notifications/dbus-shared.h +++ b/include/notifications/dbus-shared.h @@ -25,9 +25,9 @@ #define BUS_SCREEN_PATH "/com/canonical/Unity/Screen" #define BUS_SCREEN_INTERFACE "com.canonical.Unity.Screen" -#define BUS_POWERD_NAME "com.canonical.powerd" -#define BUS_POWERD_PATH "/com/canonical/powerd" -#define BUS_POWERD_INTERFACE "com.canonical.powerd" +#define BUS_POWERD_NAME "com.lomiri.Repowerd" +#define BUS_POWERD_PATH "/com/lomiri/Repowerd" +#define BUS_POWERD_INTERFACE "com.lomiri.Repowerd" #define BUS_HAPTIC_NAME "com.canonical.usensord" #define BUS_HAPTIC_PATH "/com/canonical/usensord/haptic" 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 1297caa82d05f0bfa2b1dd64f0bb56c4a4aca85e Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 28 Jul 2021 21:53:06 +0200 Subject: Some fixes in UBports patches after a review - debian/control: Add liblomiri-url-dispatcher-dev as optional - .build.yml: Add liblomiri-url-dispatcher-dev dependency - CMakeLists.txt: Remove duplicate enable_testing() - include/datetime/actions-live.h: Remove lomiri_open_appointment --- .build.yml | 1 + CMakeLists.txt | 1 - debian/control | 1 + include/datetime/actions-live.h | 4 ---- 4 files changed, 2 insertions(+), 5 deletions(-) (limited to 'include/datetime') diff --git a/.build.yml b/.build.yml index d9ee9a5..a126486 100644 --- a/.build.yml +++ b/.build.yml @@ -53,6 +53,7 @@ requires: - libedataserver1.2-dev - libproperties-cpp-dev - libmessaging-menu-dev + - liblomiri-url-dispatcher-dev # for the test harness: - libgtest-dev - libdbustest1-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index ef09a60..8e682ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ if (ENABLE_TESTS) include(CTest) pkg_check_modules (DBUSTEST REQUIRED dbustest-1>=14.04.0) - enable_testing () enable_testing() add_subdirectory(tests) diff --git a/debian/control b/debian/control index f819bea..93d2b76 100644 --- a/debian/control +++ b/debian/control @@ -18,6 +18,7 @@ Build-Depends: cmake, libedataserver1.2-dev (>= 3.5), accountsservice-ubuntu-schemas | hello, libproperties-cpp-dev, + liblomiri-url-dispatcher-dev | hello, # for the test harness: libgtest-dev , libdbustest1-dev , diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 136812c..857c3a6 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -46,10 +46,6 @@ public: std::string open_settings_app() override; void set_location(const std::string& zone, const std::string& name) override; - -protected: - - void lomiri_open_appointment(const Appointment& appt, const DateTime& date); }; } // namespace datetime -- cgit v1.2.3