From f54505942ce2dcc73fcbad79d4f5cdce991bf8cb Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 8 Dec 2017 10:40:44 +0000 Subject: Make the datetime indicator build on non-Ubuntu systems (which mostly lack url-dispatcher and Ubuntu Touch sound schema files. --- CMakeLists.txt | 19 ++++++++++++++++++- debian/control | 2 +- include/datetime/actions-live.h | 4 ++++ include/datetime/actions.h | 2 ++ include/datetime/menu.h | 6 +++++- include/datetime/snap.h | 4 ++++ src/CMakeLists.txt | 12 +++++++----- src/actions-live.cpp | 12 +++++++++++- src/actions.cpp | 6 ++++-- src/main.cpp | 8 +++++++- src/menu.cpp | 19 +++++++++++++++++-- src/snap.cpp | 3 +++ tests/CMakeLists.txt | 5 +++++ tests/manual-test-snap.cpp | 4 ++++ tests/test-actions.cpp | 7 ++++++- tests/test-exporter.cpp | 4 ++++ tests/test-formatter.cpp | 1 + tests/test-live-actions.cpp | 2 ++ tests/test-menus.cpp | 8 ++++++++ tests/timedated-fixture.h | 2 ++ 20 files changed, 115 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b68a8a0..0d897c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,10 +44,27 @@ pkg_check_modules (SERVICE_DEPS REQUIRED libedataserver-1.2>=3.5 gstreamer-1.0>=1.2 libnotify>=0.7.6 - url-dispatcher-1>=1 properties-cpp>=0.0.1) include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) +set(URL_DISPATCHER_1_REQUIRED_VERSION 1) +pkg_check_modules(URLDISPATCHER + url-dispatcher-1>=${URL_DISPATCHER_1_REQUIRED_VERSION} +) +include_directories(${URLDISPATCHER_INCLUDE_DIRS}) + +# url-dispatcher support is optional... +if(URLDISPATCHER_FOUND) + add_definitions( -DHAS_URLDISPATCHER ) +endif() + +if(EXISTS "/usr/share/accountsservice/interfaces/com.ubuntu.touch.AccountsService.Sound.xml") + set (HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS ON) + add_definitions ( -DHAS_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS ) +else() + set (HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS OFF) +endif() + ## ## custom targets ## diff --git a/debian/control b/debian/control index a27d493..27927c5 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Build-Depends: cmake, libecal1.2-dev (>= 3.16), libical-dev (>= 1.0), libedataserver1.2-dev (>= 3.5), - liburl-dispatcher1-dev, + liburl-dispatcher1-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 2c348c6..1dcb122 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -45,16 +45,20 @@ public: void desktop_open_calendar_app(const DateTime&) override; void desktop_open_settings_app() override; +#ifdef HAS_URLDISPATCHER void phone_open_alarm_app() override; void phone_open_appointment(const Appointment&) override; void phone_open_calendar_app(const DateTime&) override; void phone_open_settings_app() override; +#endif void set_location(const std::string& zone, const std::string& name) override; protected: virtual void execute_command(const std::string& command); +#ifdef HAS_URLDISPATCHER virtual void dispatch_url(const std::string& url); +#endif }; } // namespace datetime diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 4780990..1a47adb 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -49,10 +49,12 @@ public: virtual void desktop_open_calendar_app(const DateTime&) =0; virtual void desktop_open_settings_app() =0; +#ifdef HAS_URLDISPATCHER virtual void phone_open_alarm_app() =0; virtual void phone_open_appointment(const Appointment&) =0; virtual void phone_open_calendar_app(const DateTime&) =0; virtual void phone_open_settings_app() =0; +#endif virtual void set_location(const std::string& zone, const std::string& name)=0; diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 39ecc68..acb0c89 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -41,7 +41,11 @@ namespace datetime { class Menu { public: - enum Profile { Desktop, DesktopGreeter, Phone, PhoneGreeter, NUM_PROFILES }; + enum Profile { Desktop, DesktopGreeter, +#ifdef HAS_URLDISPATCHER + Phone, PhoneGreeter, +#endif + NUM_PROFILES }; enum Section { Calendar, Appointments, Locations, Settings, NUM_SECTIONS }; const std::string& name() const; Profile profile() const; diff --git a/include/datetime/snap.h b/include/datetime/snap.h index a34f0fa..549e0e7 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -20,6 +20,8 @@ #ifndef INDICATOR_DATETIME_SNAP_H #define INDICATOR_DATETIME_SNAP_H +#ifdef HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS + #include #include @@ -57,4 +59,6 @@ private: } // namespace indicator } // namespace ayatana +#endif // HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS + #endif // INDICATOR_DATETIME_SNAP_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8d219a..f0c5e28 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,11 +44,13 @@ set (SERVICE_CXX_SOURCES include (GdbusCodegen) set(SERVICE_GENERATED_SOURCES) add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-alarm-properties - com.canonical.indicator - ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.AlarmProperties.xml) -add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-accounts-sound - com.ubuntu.touch - ${CMAKE_SOURCE_DIR}/src/com.ubuntu.touch.AccountsService.Sound.xml) + org.ayatana.indicator + ${CMAKE_SOURCE_DIR}/data/org.ayatana.indicator.datetime.AlarmProperties.xml) +if(HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS) + add_gdbus_codegen(SERVICE_GENERATED_SOURCES dbus-accounts-sound + com.ubuntu.touch + ${CMAKE_SOURCE_DIR}/src/com.ubuntu.touch.AccountsService.Sound.xml) +endif() # add warnings/coverage info on handwritten files # but not the autogenerated ones... diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 5f98dfd..994fc3c 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -19,7 +19,9 @@ #include +#ifdef HAS_URLDISPATCHER #include +#endif #include @@ -49,11 +51,13 @@ void LiveActions::execute_command(const std::string& cmdstr) } } +#ifdef HAS_URLDISPATCHER void LiveActions::dispatch_url(const std::string& url) { g_debug("Dispatching url '%s'", url.c_str()); url_dispatch_send(url.c_str(), nullptr, nullptr); } +#endif /*** **** @@ -61,11 +65,14 @@ void LiveActions::dispatch_url(const std::string& url) void LiveActions::desktop_open_settings_app() { +#ifdef HAS_URLDISPATCHER if (g_getenv ("MIR_SOCKET") != nullptr) { dispatch_url("settings:///system/time-date"); } - else if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)) + else +#endif + if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)) { execute_command("unity-control-center datetime"); } @@ -128,6 +135,7 @@ void LiveActions::desktop_open_calendar_app(const DateTime& dt) **** ***/ +#ifdef HAS_URLDISPATCHER void LiveActions::phone_open_alarm_app() { dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); @@ -135,6 +143,7 @@ void LiveActions::phone_open_alarm_app() void LiveActions::phone_open_appointment(const Appointment& appt) { + if (!appt.activation_url.empty()) { dispatch_url(appt.activation_url); @@ -160,6 +169,7 @@ void LiveActions::phone_open_settings_app() { dispatch_url("settings:///system/time-date"); } +#endif /*** **** diff --git a/src/actions.cpp b/src/actions.cpp index e89b116..d288a0e 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -88,6 +88,7 @@ void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) static_cast(gself)->desktop_open_settings_app(); } +#ifdef HAS_URLDISPATCHER void on_phone_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) { auto self = static_cast(gself); @@ -108,7 +109,7 @@ void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself) { static_cast(gself)->phone_open_settings_app(); } - +#endif void on_set_location(GSimpleAction * /*action*/, GVariant * param, @@ -204,11 +205,12 @@ Actions::Actions(const std::shared_ptr& state): { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr }, { "desktop.open-settings-app", on_desktop_settings_activated }, +#ifdef HAS_URLDISPATCHER { "phone.open-appointment", on_phone_appointment_activated, "s", 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 }, - +#endif { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } }; diff --git a/src/main.cpp b/src/main.cpp index 31654c9..fdd84b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,9 @@ #include #include #include +#ifdef HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS #include +#endif #include #include #include @@ -90,6 +92,7 @@ namespace return state; } +#ifdef HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS std::shared_ptr create_simple_alarm_queue(const std::shared_ptr& clock, const std::shared_ptr& snooze_planner, const std::shared_ptr& engine, @@ -113,6 +116,7 @@ namespace auto wakeup_timer = std::make_shared(clock); return std::make_shared(clock, planner, wakeup_timer); } +#endif } int @@ -133,9 +137,10 @@ main(int /*argc*/, char** /*argv*/) auto actions = std::make_shared(state); MenuFactory factory(actions, state); +#ifdef HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS // set up the snap decisions auto snooze_planner = std::make_shared(state->settings, state->clock); - auto notification_engine = std::make_shared("indicator-datetime-service"); + 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) { @@ -147,6 +152,7 @@ main(int /*argc*/, char** /*argv*/) engine->disable_ubuntu_alarm(appointment); }; alarm_queue->alarm_reached().connect(on_alarm_reached); +#endif // create the menus std::vector> menus; diff --git a/src/menu.cpp b/src/menu.cpp index 250cb72..7be3719 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -240,9 +240,12 @@ private: const char * action_name; +#ifdef HAS_URLDISPATCHER if (profile == Phone) action_name = "indicator.phone.open-calendar-app"; - else if (profile == Desktop) + else +#endif + if (profile == Desktop) action_name = "indicator.desktop.open-calendar-app"; else action_name = nullptr; @@ -288,9 +291,12 @@ private: const char * action_name; +#ifdef HAS_URLDISPATCHER if (profile == Phone) action_name = "indicator.phone.open-appointment"; - else if ((profile == Desktop) && m_actions->desktop_has_calendar_app()) + else +#endif + if ((profile == Desktop) && m_actions->desktop_has_calendar_app()) action_name = "indicator.desktop.open-appointment"; else action_name = nullptr; @@ -357,6 +363,7 @@ private: g_object_unref(menu_item); } } +#ifdef HAS_URLDISPATCHER else if (profile==Phone) { auto menu_item = g_menu_item_new (_("Clock"), "indicator.phone.open-alarm-app"); @@ -366,6 +373,7 @@ private: add_appointments (menu, profile); } +#endif return G_MENU_MODEL(menu); } @@ -405,8 +413,10 @@ private: if (profile == Desktop) action_name = "indicator.desktop.open-settings-app"; +#ifdef HAS_URLDISPATCHER else if (profile == Phone) action_name = "indicator.phone.open-settings-app"; +#endif else action_name = nullptr; @@ -493,6 +503,8 @@ public: DesktopBaseMenu(DesktopGreeter,"desktop_greeter", state_, actions_) {} }; + +#ifdef HAS_URLDISPATCHER class PhoneBaseMenu: public MenuImpl { protected: @@ -551,6 +563,7 @@ public: std::shared_ptr& actions_): PhoneBaseMenu(PhoneGreeter, "phone_greeter", state_, actions_) {} }; +#endif /**** ***** @@ -578,6 +591,7 @@ MenuFactory::buildMenu(Menu::Profile profile) menu.reset(new DesktopGreeterMenu(m_state, m_actions)); break; +#ifdef HAS_URLDISPATCHER case Menu::Phone: menu.reset(new PhoneMenu(m_state, m_actions)); break; @@ -585,6 +599,7 @@ MenuFactory::buildMenu(Menu::Profile profile) case Menu::PhoneGreeter: menu.reset(new PhoneGreeterMenu(m_state, m_actions)); break; +#endif default: g_warn_if_reached(); diff --git a/src/snap.cpp b/src/snap.cpp index 58ebd3b..2f1158a 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -17,6 +17,7 @@ * Charles Kerr */ +#ifdef HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS #include "dbus-accounts-sound.h" #include @@ -259,3 +260,5 @@ Snap::operator()(const Appointment& appointment, } // namespace datetime } // namespace indicator } // namespace ayatana + +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0302da9..8e5e187 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,7 +47,9 @@ function(add_test_by_name name) 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) add_test_by_name(test-snap) +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) @@ -66,6 +68,8 @@ set (TEST_NAME manual-test-snap) add_executable (${TEST_NAME} ${TEST_NAME}.cpp) target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) +if (URLDISPATCHER_FOUND) + ## ## EDS Tests ## @@ -92,6 +96,7 @@ add_eds_ics_test_by_name(test-eds-ics-missing-trigger) add_eds_ics_test_by_name(test-eds-ics-tzids) add_eds_ics_test_by_name(test-eds-ics-tzids-2) +endif() # disabling the timezone unit tests because they require # https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724 diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 95775c8..12d34f3 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -18,6 +18,8 @@ * with this program. If not, see . */ +#ifdef HAS_URLDISPATCHER + #include #include #include @@ -99,3 +101,5 @@ int main(int argc, const char* argv[]) g_main_loop_unref(loop); return 0; } + +#endif diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 7899d15..0586bcc 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -157,10 +157,13 @@ TEST_F(ActionsFixture, ActionsExist) "desktop.open-alarm-app", "desktop.open-calendar-app", "desktop.open-settings-app", +#ifdef HAS_URLDISPATCHER "phone.open-appointment", "phone.open-alarm-app", "phone.open-calendar-app", - "phone.open-settings-app" }; + "phone.open-settings-app" +#endif + }; for(const auto& name: names) { @@ -200,6 +203,7 @@ TEST_F(ActionsFixture, DesktopOpenSettingsApp) **** ***/ +#ifdef HAS_URLDISPATCHER TEST_F(ActionsFixture, PhoneOpenAlarmApp) { test_action_with_no_args("phone.open-alarm-app", @@ -223,6 +227,7 @@ TEST_F(ActionsFixture, PhoneOpenSettingsApp) test_action_with_no_args("phone.open-settings-app", MockActions::PhoneOpenSettingsApp); } +#endif /*** **** diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index bc8c70a..04c8445 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -111,15 +111,19 @@ TEST_F(ExporterFixture, Publish) EXPECT_EQ(1, names.count("desktop.open-appointment")); EXPECT_EQ(1, names.count("desktop.open-calendar-app")); EXPECT_EQ(1, names.count("desktop.open-settings-app")); +#ifdef HAS_URLDISPATCHER EXPECT_EQ(1, names.count("phone.open-alarm-app")); EXPECT_EQ(1, names.count("phone.open-appointment")); EXPECT_EQ(1, names.count("phone.open-calendar-app")); EXPECT_EQ(1, names.count("phone.open-settings-app")); +#endif EXPECT_EQ(1, names.count("calendar")); EXPECT_EQ(1, names.count("desktop_greeter-header")); EXPECT_EQ(1, names.count("desktop-header")); +#ifdef HAS_URLDISPATCHER EXPECT_EQ(1, names.count("phone_greeter-header")); EXPECT_EQ(1, names.count("phone-header")); +#endif EXPECT_EQ(1, names.count("set-location")); // try closing the connection prematurely diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index e9aa4e9..e61daa7 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -108,6 +108,7 @@ TEST_F(FormatterFixture, TestPhoneHeader) EXPECT_EQ(std::string(" 6:30 PM"), formatter.header.get()); } } +#endif #define EM_SPACE "\u2003" diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 9f17001..aade9c7 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -94,6 +94,7 @@ namespace const std::string calendar_app_url = "appid://com.ubuntu.calendar/calendar/current-user-version"; } +#ifdef HAS_URLDISPATCHER TEST_F(TimedateFixture, PhoneOpenAlarmApp) { m_actions->phone_open_alarm_app(); @@ -128,6 +129,7 @@ TEST_F(TimedateFixture, PhoneOpenSettingsApp) const std::string expected = "settings:///system/time-date"; EXPECT_EQ(expected, m_live_actions->last_url); } +#endif /*** **** diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index 6e88b7b..f0c5653 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -97,8 +97,10 @@ protected: if (profile == Menu::Desktop) expected_action = "indicator.desktop.open-calendar-app"; +#ifdef HAS_URLDISPATCHER else if (profile == Menu::Phone) expected_action = "indicator.phone.open-calendar-app"; +#endif else expected_action = nullptr; @@ -322,6 +324,7 @@ private: g_clear_object(&submenu); } +#ifdef HAS_URLDISPATCHER void InspectPhoneAppointments(GMenuModel* menu_model, bool can_open_planner) { auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); @@ -354,6 +357,7 @@ private: // cleanup g_clear_object(&submenu); } +#endif protected: @@ -371,6 +375,7 @@ protected: InspectEmptySection(menu_model, Menu::Appointments); break; +#ifdef HAS_URLDISPATCHER case Menu::Phone: InspectPhoneAppointments(menu_model, can_open_planner); break; @@ -378,6 +383,7 @@ protected: case Menu::PhoneGreeter: InspectEmptySection(menu_model, Menu::Appointments); break; +#endif default: g_warn_if_reached(); @@ -449,8 +455,10 @@ protected: if (profile == Menu::Desktop) expected_action = "indicator.desktop.open-settings-app"; +#ifdef HAS_URLDISPATCHER else if (profile == Menu::Phone) expected_action = "indicator.phone.open-settings-app"; +#endif // get the Settings section auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); diff --git a/tests/timedated-fixture.h b/tests/timedated-fixture.h index 00269e0..07b3d9f 100644 --- a/tests/timedated-fixture.h +++ b/tests/timedated-fixture.h @@ -36,7 +36,9 @@ public: ~MockLiveActions() {} protected: +#ifdef HAS_URLDISPATCHER void dispatch_url(const std::string& url) override { last_url = url; } +#endif void execute_command(const std::string& cmd) override { last_cmd = cmd; } }; -- cgit v1.2.3