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. --- src/CMakeLists.txt | 2 +- src/actions-live.cpp | 126 ++++++++++++++++++--------------------------------- src/actions.cpp | 64 ++++++++------------------ src/main.cpp | 2 +- 4 files changed, 67 insertions(+), 127 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96284fb..823a9b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,5 +70,5 @@ link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) add_executable (${SERVICE_EXEC} main.cpp) set_source_files_properties(${SERVICE_SOURCES} main.cpp PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -g -std=c++11") -target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS} ${URLDISPATCHER_LIBRARIES}) +target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ${GCOV_LIBS}) install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}) diff --git a/src/actions-live.cpp b/src/actions-live.cpp index e3237b7..11643cd 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -20,14 +20,15 @@ #include #include -#ifdef HAS_URLDISPATCHER -#include -#endif - #include #include +extern "C" +{ + #include +} + namespace ayatana { namespace indicator { namespace datetime { @@ -41,53 +42,55 @@ LiveActions::LiveActions(const std::shared_ptr& state_in): { } -void LiveActions::execute_command(const std::string& cmdstr) -{ - const auto cmd = cmdstr.c_str(); - g_debug("Issuing command '%s'", cmd); +/*** +**** +***/ - GError* error = nullptr; - if (!g_spawn_command_line_async(cmd, &error)) +void LiveActions::open_alarm_app() +{ + if (ayatana_common_utils_is_lomiri()) { - g_warning("Unable to start \"%s\": %s", cmd, error->message); - g_error_free(error); + ayatana_common_utils_open_url("appid://com.lomiri.clock/clock/current-user-version"); + } + else + { + ayatana_common_utils_execute_command("evolution -c calendar"); } } -void LiveActions::dispatch_url(const std::string& url) +void LiveActions::open_calendar_app(const DateTime& dt) { - g_debug("Dispatching url '%s'", url.c_str()); -#ifdef HAS_URLDISPATCHER - lomiri_url_dispatch_send(url.c_str(), nullptr, nullptr); -#else - // FIXME: Deal with this, if we build without liburl-dispatcher... -#endif + if (ayatana_common_utils_is_lomiri()) + { + const auto utc = dt.to_timezone("UTC"); + auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); + ayatana_common_utils_open_url(cmd.c_str()); + } + else + { + const auto utc = dt.start_of_day().to_timezone("UTC"); + auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); + ayatana_common_utils_execute_command(cmd.c_str()); + } } -/*** -**** -***/ - -void LiveActions::desktop_open_settings_app() +void LiveActions::open_settings_app() { - if (g_getenv ("MIR_SOCKET") != nullptr) + if (ayatana_common_utils_is_lomiri()) + { + ayatana_common_utils_open_url("settings:///system/time-date"); + } + else if (ayatana_common_utils_is_unity()) { - dispatch_url("settings:///system/time-date"); + ayatana_common_utils_execute_command("unity-control-center datetime"); + } + else if (ayatana_common_utils_is_mate()) + { + ayatana_common_utils_execute_command("mate-time-admin"); } else { - if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)) - { - execute_command("unity-control-center datetime"); - } - else if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "MATE") == 0)) - { - execute_command("mate-time-admin"); - } - else - { - execute_command("gnome-control-center datetime"); - } + ayatana_common_utils_execute_command("gnome-control-center datetime"); } } @@ -123,64 +126,25 @@ bool LiveActions::desktop_has_calendar_app() const return have_calendar; } -void LiveActions::desktop_open_alarm_app() -{ - execute_command("evolution -c calendar"); -} - -void LiveActions::desktop_open_appointment(const Appointment&, const DateTime& date) -{ - desktop_open_calendar_app(date); -} - -void LiveActions::desktop_open_calendar_app(const DateTime& dt) -{ - const auto utc = dt.start_of_day().to_timezone("UTC"); - auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - execute_command(cmd.c_str()); -} - -/*** -**** -***/ - -void LiveActions::phone_open_alarm_app() -{ - dispatch_url("appid://com.ubuntu.clock/clock/current-user-version"); -} - -void LiveActions::phone_open_appointment(const Appointment& appt, const DateTime& date) +void LiveActions::open_appointment(const Appointment& appt, const DateTime& date) { - if (!appt.activation_url.empty()) { - dispatch_url(appt.activation_url); + ayatana_common_utils_open_url(appt.activation_url.c_str()); } else switch (appt.type) { case Appointment::UBUNTU_ALARM: - phone_open_alarm_app(); + open_alarm_app(); break; case Appointment::EVENT: default: - phone_open_calendar_app(date); + open_calendar_app(date); break; } } -void LiveActions::phone_open_calendar_app(const DateTime& dt) -{ - const auto utc = dt.to_timezone("UTC"); - auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - dispatch_url(cmd); -} - -void LiveActions::phone_open_settings_app() -{ - dispatch_url("settings:///system/time-date"); -} - /*** **** ***/ diff --git a/src/actions.cpp b/src/actions.cpp index ea68d3e..315340a 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -62,7 +62,7 @@ bool lookup_appointment_by_uid(const std::shared_ptr& state, const gchar* return false; } -void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) +void on_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) { auto self = static_cast(gself); Appointment appt; @@ -70,44 +70,20 @@ void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gint64 time = 0; g_variant_get(vdata, "(&sx)", &uid, &time); if (lookup_appointment_by_uid(self->state(), uid, appt)) - self->desktop_open_appointment(appt, DateTime::Local(time)); + self->open_appointment(appt, DateTime::Local(time)); } -void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) +void on_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) { - static_cast(gself)->desktop_open_alarm_app(); + static_cast(gself)->open_alarm_app(); } -void on_desktop_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) +void on_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) { const auto dt = datetime_from_timet_variant(vt); - static_cast(gself)->desktop_open_calendar_app(dt); + static_cast(gself)->open_calendar_app(dt); } -void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) +void on_settings_activated (GSimpleAction*, GVariant*, gpointer gself) { - static_cast(gself)->desktop_open_settings_app(); -} - -void on_phone_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) -{ - auto self = static_cast(gself); - Appointment appt; - const gchar* uid = nullptr; - gint64 time = 0; - g_variant_get(vdata, "(&sx)", &uid, &time); - if (lookup_appointment_by_uid(self->state(), uid, appt)) - self->phone_open_appointment(appt, DateTime::Local(time)); -} -void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast(gself)->phone_open_alarm_app(); -} -void on_phone_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself) -{ - const auto dt = datetime_from_timet_variant(vt); - static_cast(gself)->phone_open_calendar_app(dt); -} -void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast(gself)->phone_open_settings_app(); + static_cast(gself)->open_settings_app(); } void on_set_location(GSimpleAction * /*action*/, @@ -135,9 +111,9 @@ void on_calendar_active_changed(GSimpleAction * /*action*/, } } -void on_calendar_activated(GSimpleAction * /*action*/, - GVariant * state, - gpointer gself) +void on_calendar_date_activated(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) { const time_t t = g_variant_get_int64(state); @@ -199,15 +175,15 @@ Actions::Actions(const std::shared_ptr& state): { GActionEntry entries[] = { - { "desktop.open-appointment", on_desktop_appointment_activated, "(sx)", nullptr }, - { "desktop.open-alarm-app", on_desktop_alarm_activated }, - { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr }, - { "desktop.open-settings-app", on_desktop_settings_activated }, + { "desktop.open-appointment", on_appointment_activated, "(sx)", nullptr }, + { "desktop.open-alarm-app", on_alarm_activated }, + { "desktop.open-calendar-app", on_calendar_activated, "x", nullptr }, + { "desktop.open-settings-app", on_settings_activated }, - { "phone.open-appointment", on_phone_appointment_activated, "(sx)", nullptr }, - { "phone.open-alarm-app", on_phone_alarm_activated }, - { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr }, - { "phone.open-settings-app", on_phone_settings_activated }, + { "phone.open-appointment", on_appointment_activated, "(sx)", nullptr }, + { "phone.open-alarm-app", on_alarm_activated }, + { "phone.open-calendar-app", on_calendar_activated, "x", nullptr }, + { "phone.open-settings-app", on_settings_activated }, { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } @@ -241,7 +217,7 @@ Actions::Actions(const std::shared_ptr& state): v = create_calendar_state(state); a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v); g_action_map_add_action(gam, G_ACTION(a)); - g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this); + g_signal_connect(a, "activate", G_CALLBACK(on_calendar_date_activated), this); g_object_unref(a); /// diff --git a/src/main.cpp b/src/main.cpp index 729f0e5..034a5ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -157,7 +157,7 @@ main(int /*argc*/, char** /*argv*/) snooze_planner->add(appointment, alarm); }; auto on_ok = [actions](const Appointment& app, const Alarm&){ - actions->phone_open_appointment(app, app.begin); + actions->open_appointment(app, app.begin); }; auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { (*snap)(appointment, alarm, on_snooze, on_ok); -- cgit v1.2.3