From 676b6c35768e707710a7121ed9f71002c6226bd7 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 16:53:36 -0300 Subject: Update code as requested by reviewer. --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') 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; } -- cgit v1.2.3 From 3cd2c8e20343ef4b4efe7a34daba72f9af23205d 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 'src/main.cpp') 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 bb7b522ef52b240718f33f37b577bacc4fea2db6 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 18 Apr 2016 23:42:53 -0300 Subject: Post message on messaging menu if the notification get timeout. --- data/CMakeLists.txt | 7 +- data/ayatana-indicator-datetime.desktop.in | 1 + include/notifications/notifications.h | 11 ++- src/main.cpp | 5 +- src/notifications.cpp | 127 +++++++++++++++++++++++++++-- src/snap.cpp | 12 ++- tests/test-notification.cpp | 2 +- tests/test-sound.cpp | 2 +- 8 files changed, 154 insertions(+), 13 deletions(-) (limited to 'src/main.cpp') diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index c460586..14d36b8 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -32,6 +32,7 @@ if (${SYSTEMD_FOUND}) # build it set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}") + set (messaging_menu_icon "${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/suru/actions/scalable/appointment.svg") configure_file ("${SYSTEMD_USER_FILE_IN}" "${SYSTEMD_USER_FILE}") # install it @@ -55,7 +56,11 @@ set (XDG_AUTOSTART_FILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/${XDG_AUTOSTART_NAME}.in set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}") configure_file ("${XDG_AUTOSTART_FILE_IN}" "${XDG_AUTOSTART_FILE}") -# install it +# install desktop file used by messaging-menu +install (FILES "${XDG_AUTOSTART_FILE}" + DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications/") + +# install XDG autostart install (FILES "${XDG_AUTOSTART_FILE}" DESTINATION "${XDG_AUTOSTART_DIR}") diff --git a/data/ayatana-indicator-datetime.desktop.in b/data/ayatana-indicator-datetime.desktop.in index 70df0d7..6d27166 100644 --- a/data/ayatana-indicator-datetime.desktop.in +++ b/data/ayatana-indicator-datetime.desktop.in @@ -6,3 +6,4 @@ OnlyShowIn=MATE;Unity;XFCE;Pantheon; NoDisplay=true StartupNotify=false Terminal=false +Icon=@messaging_menu_icon@ diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index 0de1e23..2bb6694 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -50,6 +50,8 @@ public: void set_icon_name (const std::string& icon_name); + void set_start_time(uint64_t time); + /* Set an interval, after which the notification will automatically be closed. If not set, the notification server's default timeout is used. */ @@ -62,19 +64,24 @@ public: static constexpr char const * HINT_NONSHAPED_ICON {"x-canonical-non-shaped-icon"}; static constexpr char const * HINT_AFFIRMATIVE_HINT {"x-canonical-private-affirmative-tint"}; static constexpr char const * HINT_REJECTION_TINT {"x-canonical-private-rejection-tint"}; + static constexpr char const * HINT_INTERACTIVE {"x-canonical-switch-to-application"}; /* Add an action button. This may fail if the Engine doesn't support actions. @see Engine::supports_actions() */ void add_action (const std::string& action, const std::string& label); - /** Sets the closed callback. This will be called exactly once. */ + /** Sets the closed callback. This will be called exactly once. After notification dissapear */ void set_closed_callback (std::function); + /** Sets the time-out callback. This will be called exactly once. */ + void set_missed_click_callback (std::function); + + private: friend class Engine; class Impl; - std::unique_ptr impl; + std::shared_ptr impl; }; /** diff --git a/src/main.cpp b/src/main.cpp index bb77c0e..f9a934a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -156,7 +156,10 @@ main(int /*argc*/, char** /*argv*/) auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) { snooze_planner->add(appointment, alarm); }; - auto on_ok = [](const Appointment&, const Alarm&){}; + auto on_ok = [actions](const Appointment& app, const Alarm&){ + //TODO: add support for desktop + actions->phone_open_appointment(app, app.begin); + }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { (*snap)(appointment, alarm, on_snooze, on_ok); engine->disable_ubuntu_alarm(appointment); diff --git a/src/notifications.cpp b/src/notifications.cpp index 051653d..2d22087 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -21,10 +21,18 @@ #include +#include +#include + + +#include + #include #include #include #include +#include + namespace ayatana { namespace indicator { @@ -45,9 +53,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; + gint64 m_start_time; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; + std::function m_missed_click_callback; }; Builder::Builder(): @@ -101,6 +111,18 @@ Builder::set_closed_callback (std::function cb) impl->m_closed_callback.swap (cb); } +void +Builder::set_missed_click_callback (std::function cb) +{ + impl->m_missed_click_callback.swap (cb); +} + +void +Builder::set_start_time (uint64_t time) +{ + impl->m_start_time = time; +} + /*** **** ***/ @@ -110,23 +132,39 @@ class Engine::Impl struct notification_data { std::shared_ptr nn; - std::function closed_callback; + Builder::Impl data; + }; + + struct messaging_menu_data + { + std::shared_ptr mm; + std::function callback; }; public: Impl(const std::string& app_name): + m_messaging_app(messaging_menu_app_new(DATETIME_INDICATOR_DESKTOP_FILE), g_object_unref), m_app_name(app_name) { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); + + // messaging menu + GIcon *icon = g_themed_icon_new("calendar-app"); + + messaging_menu_app_register(m_messaging_app.get()); + messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), icon, "Calendar"); + g_object_unref(icon); } ~Impl() { close_all (); + remove_all (); notify_uninit (); + messaging_menu_app_unregister (m_messaging_app.get()); } const std::string& app_name() const @@ -217,7 +255,7 @@ public: notification_key_quark(), GINT_TO_POINTER(key)); - m_notifications[key] = { nn, info.m_closed_callback }; + m_notifications[key] = { nn, info }; g_signal_connect (nn.get(), "closed", G_CALLBACK(on_notification_closed), this); @@ -238,6 +276,59 @@ public: return ret; } + std::string post(const Builder::Impl& data) + { + uuid_t message_uuid; + uuid_generate(message_uuid); + + char message_id[37]; + uuid_unparse(message_uuid, message_id); + + GIcon *icon = g_themed_icon_new(data.m_icon_name.c_str()); + std::shared_ptr msg (messaging_menu_message_new(message_id, + icon, + data.m_title.c_str(), + nullptr, + data.m_body.c_str(), + data.m_start_time * 1000000), // secs -> microsecs + g_object_ref); + g_object_unref(icon); + if (msg) + { + m_messaging_messages[std::string(message_id)] = { msg, data.m_missed_click_callback }; + g_signal_connect(msg.get(), "activate", + G_CALLBACK(on_message_activated), this); + messaging_menu_app_append_message(m_messaging_app.get(), msg.get(), m_app_name.c_str(), false); + return message_id; + } else { + g_warning("Fail to create messaging menu message"); + } + return ""; + } + + void remove (const std::string &key) + { + auto it = m_messaging_messages.find(key); + if (it != m_messaging_messages.end()) + { + // tell the server to remove message + messaging_menu_app_remove_message(m_messaging_app.get(), it->second.mm.get()); + m_messaging_messages.erase(it); + } + } + + void remove_all () + { + // call remove() on all our keys + + std::set keys; + for (const auto& it : m_messaging_messages) + keys.insert (it.first); + + for (const std::string &key : keys) + remove (key); + } + private: const std::set& server_caps() const @@ -279,6 +370,22 @@ private: static_cast(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey)); } + static void on_message_activated (MessagingMenuMessage *, + const char *actionId, + GVariant *, + gpointer gself) + { + auto self = static_cast(gself); + auto it = self->m_messaging_messages.find(actionId); + g_return_if_fail (it != self->m_messaging_messages.end()); + const auto& ndata = it->second; + + if (ndata.callback) + ndata.callback(); + + self->m_messaging_messages.erase(it); + } + void remove_closed_notification (int key) { auto it = m_notifications.find(key); @@ -286,16 +393,20 @@ private: const auto& ndata = it->second; auto nn = ndata.nn.get(); - if (ndata.closed_callback) + + if (ndata.data.m_closed_callback) { std::string action; - const GQuark q = notification_action_quark(); const gpointer p = g_object_get_qdata(G_OBJECT(nn), q); if (p != nullptr) action = static_cast(p); - ndata.closed_callback (action); + ndata.data.m_closed_callback (action); + // empty action means that the notification got timeout + // post a message on messaging menu + if (action.empty()) + post(ndata.data); } m_notifications.erase(it); @@ -305,6 +416,10 @@ private: **** ***/ + // messaging menu + std::shared_ptr m_messaging_app; + std::map m_messaging_messages; + const std::string m_app_name; // key-to-data @@ -315,6 +430,8 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; + static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; + static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** diff --git a/src/snap.cpp b/src/snap.cpp index 259592e..5c530be 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -122,8 +122,9 @@ public: const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); ain::Builder b; b.set_body (appointment.summary); - b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "reminder"); + b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "appointment"); b.add_hint (ain::Builder::HINT_NONSHAPED_ICON); + b.set_start_time (appointment.begin.to_unix()); const char * timefmt; if (is_locale_12h()) { @@ -152,6 +153,9 @@ public: b.add_hint (ain::Builder::HINT_AFFIRMATIVE_HINT); b.add_action ("ok", _("OK")); b.add_action ("snooze", _("Snooze")); + } else { + b.add_hint (ain::Builder::HINT_INTERACTIVE); + b.add_action ("ok", _("OK")); } // add 'sound', 'haptic', and 'awake' objects to the capture so @@ -161,10 +165,14 @@ public: (const std::string& action){ if (action == "snooze") snooze(appointment, alarm); - else + else if (action == "ok") ok(appointment, alarm); }); + b.set_missed_click_callback([appointment, alarm, ok](){ + ok(appointment, alarm); + }); + const auto key = m_engine->show(b); if (key) m_notifications.insert (key); diff --git a/tests/test-notification.cpp b/tests/test-notification.cpp index 4c11dca..b951cee 100644 --- a/tests/test-notification.cpp +++ b/tests/test-notification.cpp @@ -63,7 +63,7 @@ TEST_F(NotificationFixture,Notification) bool expected_notify_called; bool expected_vibrate_called; } test_appts[] = { - { appt, "reminder", "Event", true, true }, + { appt, "appointment", "Event", true, true }, { ualarm, "alarm-clock", "Alarm", true, true } }; diff --git a/tests/test-sound.cpp b/tests/test-sound.cpp index a222f39..59c1a28 100644 --- a/tests/test-sound.cpp +++ b/tests/test-sound.cpp @@ -85,7 +85,7 @@ TEST_F(NotificationFixture, InteractiveDuration) // confirm that the icon passed to Notify was "alarm-clock" g_variant_get_child (params, 2, "&s", &str); - ASSERT_STREQ("reminder", str); + ASSERT_STREQ("appointment", str); // confirm that the hints passed to Notify included a timeout matching duration_minutes int32_t i32; -- cgit v1.2.3 From 0fb4679e9043ba2591055f46445294cf508be0fb Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 28 Apr 2016 09:35:05 -0300 Subject: Small fixes requeted by charles during the review. --- include/notifications/notifications.h | 2 +- src/main.cpp | 1 - src/notifications.cpp | 39 +++++++++++++++-------------------- src/snap.cpp | 2 +- 4 files changed, 19 insertions(+), 25 deletions(-) (limited to 'src/main.cpp') diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index 4b66800..450c45b 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -75,7 +75,7 @@ public: void set_closed_callback (std::function); /** Sets the time-out callback. This will be called exactly once. */ - void set_missed_click_callback (std::function); + void set_timeout_callback (std::function); private: diff --git a/src/main.cpp b/src/main.cpp index f9a934a..729f0e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,7 +157,6 @@ main(int /*argc*/, char** /*argv*/) snooze_planner->add(appointment, alarm); }; auto on_ok = [actions](const Appointment& app, const Alarm&){ - //TODO: add support for desktop actions->phone_open_appointment(app, app.begin); }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { diff --git a/src/notifications.cpp b/src/notifications.cpp index 9817686..3c90e57 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -58,11 +58,11 @@ public: std::string m_body; std::string m_icon_name; std::chrono::seconds m_duration; - gint64 m_start_time; + gint64 m_start_time {}; std::set m_string_hints; std::vector> m_actions; std::function m_closed_callback; - std::function m_missed_click_callback; + std::function m_timeout_callback; }; Builder::Builder(): @@ -117,9 +117,9 @@ Builder::set_closed_callback (std::function cb) } void -Builder::set_missed_click_callback (std::function cb) +Builder::set_timeout_callback (std::function cb) { - impl->m_missed_click_callback.swap (cb); + impl->m_timeout_callback.swap (cb); } void @@ -312,7 +312,7 @@ public: data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs if (msg) { - std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_missed_click_callback, this}); + std::shared_ptr msg_data(new messaging_menu_data{message_id, data.m_timeout_callback, this}); m_messaging_messages[message_id] = msg_data; g_signal_connect(G_OBJECT(msg), "activate", G_CALLBACK(on_message_activated), msg_data.get()); @@ -344,13 +344,8 @@ public: void remove_all () { // call remove() on all our keys - - std::set keys; - for (const auto& it : m_messaging_messages) - keys.insert (it.first); - - for (const std::string &key : keys) - remove (key); + while (!m_messaging_messages.empty()) + remove(m_messaging_messages.begin()->first); } private: @@ -400,7 +395,7 @@ private: gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); g_return_if_fail (it != msg_data->self->m_messaging_messages.end()); const auto& ndata = it->second; @@ -411,7 +406,7 @@ private: static void on_message_destroyed(gpointer data) { auto msg_data = static_cast(data); - auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id.c_str()); + auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id); if (it != msg_data->self->m_messaging_messages.end()) msg_data->self->m_messaging_messages.erase(it); } @@ -448,6 +443,7 @@ private: auto app_id = lomiri::app_launch::AppID::discover("com.lomiri.calendar"); if (!app_id.empty()) + // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id. return std::string(app_id) + ".desktop"; else return std::string(); @@ -463,13 +459,14 @@ private: if (app_desktop != nullptr) { auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon"); g_object_unref(app_desktop); - std::string result(icon_name); - g_free(icon_name); - return result; - } else { - g_warning("Fail to get calendar icon"); - return std::string(); + if (icon_name) { + std::string result(icon_name); + g_free(icon_name); + return result; + } } + g_warning("Fail to get calendar icon"); + return std::string(); } /*** @@ -490,8 +487,6 @@ private: mutable std::set m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; - static constexpr char const * DATETIME_INDICATOR_DESKTOP_FILE {"indicator-datetime.desktop"}; - static constexpr char const * DATETIME_INDICATOR_SOURCE_ID {"indicator-datetime"}; }; /*** diff --git a/src/snap.cpp b/src/snap.cpp index 60005f3..4078dd7 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -173,7 +173,7 @@ public: //TODO: we need to extend it to support alarms appoitments if (!appointment.is_ubuntu_alarm()) { - b.set_missed_click_callback([appointment, alarm, ok](){ + b.set_timeout_callback([appointment, alarm, ok](){ ok(appointment, alarm); }); } -- cgit v1.2.3 From a6422822a9b9a18bae705e56f2b53ee0b61ff1dc 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 | 1 - 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(+), 213 deletions(-) (limited to 'src/main.cpp') diff --git a/.build.yml b/.build.yml index 553e339..8dc516a 100644 --- a/.build.yml +++ b/.build.yml @@ -87,7 +87,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 5dbc921..57ac0ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,17 +69,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 946b4c2..f819bea 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,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 b639e39dc4a2aa82a40f0a6922577b65ff3dd35f 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 'src/main.cpp') 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 5ab8ee23903ec5a1eb1779164d65cb944195dc76 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Oct 2016 12:39:49 -0500 Subject: In main.cpp and tests where Snap is instantiated, provide the system_bus to Snap's constructor --- src/main.cpp | 4 ++-- src/settings-live.cpp | 26 +++++++++++++++----------- tests/manual-test-snap.cpp | 4 +++- tests/notification-fixture.h | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 9defed0..6cad190 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,9 +151,9 @@ main(int /*argc*/, char** /*argv*/) // set up the snap decisions auto snooze_planner = std::make_shared(state->settings, state->clock); auto notification_engine = std::make_shared("ayatana-indicator-datetime-service"); - std::unique_ptr snap (new Snap(notification_engine, state->settings)); - auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); auto sound_builder = std::make_shared(); + std::unique_ptr snap (new Snap(notification_engine, sound_builder, state->settings, system_bus)); + auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); auto on_response = [snooze_planner, actions](const Appointment& appointment, const Alarm& alarm, const Snap::Response& response) { switch(response) { case Snap::Response::Snooze: diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 66590e0..59c133f 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -40,13 +40,9 @@ LiveSettings::~LiveSettings() } LiveSettings::LiveSettings(): - m_settings(g_settings_new(SETTINGS_INTERFACE)), - m_settings_cal_notification(g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH)), - m_settings_general_notification(g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID)) + m_settings(g_settings_new(SETTINGS_INTERFACE)) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); - g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); // init the Properties from the GSettings backend update_custom_time_format(); @@ -68,12 +64,20 @@ LiveSettings::LiveSettings(): update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); - update_cal_notification_enabled(); - update_cal_notification_sounds(); - update_cal_notification_vibrations(); - update_cal_notification_bubbles(); - update_cal_notification_list(); - update_vibrate_silent_mode(); + + if (ayatana_common_utils_is_lomiri()) + { + m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + m_settings_general_notification = g_settings_new(SETTINGS_NOTIFY_APPS_SCHEMA_ID); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + g_signal_connect (m_settings_general_notification, "changed", G_CALLBACK(on_changed_general_notification), this); + update_cal_notification_enabled(); + update_cal_notification_sounds(); + update_cal_notification_vibrations(); + update_cal_notification_bubbles(); + update_cal_notification_list(); + update_vibrate_silent_mode(); + } // now listen for clients to change the properties s.t. we can sync update GSettings diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 02cbb9f..72fd374 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -95,10 +95,12 @@ int main(int argc, const char* argv[]) auto notification_engine = std::make_shared("ayatana-indicator-datetime-service"); auto sound_builder = std::make_shared(); - Snap snap (notification_engine, settings); + auto system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr); + Snap snap (notification_engine, sound_builder, settings, system_bus); snap(a, a.alarms.front(), on_response); g_main_loop_run(loop); g_main_loop_unref(loop); + g_clear_object(&system_bus); return 0; } diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h index 0c24843..cbce9ff 100644 --- a/tests/notification-fixture.h +++ b/tests/notification-fixture.h @@ -334,7 +334,7 @@ protected: const std::shared_ptr& sb, const std::shared_ptr& settings) { - auto snap = std::make_shared(ne, sb, settings); + auto snap = std::make_shared(ne, sb, settings, system_bus); wait_msec(100); // wait a moment for the Snap to finish its async dbus bootstrapping return snap; } -- cgit v1.2.3