diff options
Diffstat (limited to 'src/actions.cpp')
-rw-r--r-- | src/actions.cpp | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index 93629a0..315340a 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>& state, GVariant* vuid, Appointment& setme) +bool lookup_appointment_by_uid(const std::shared_ptr<State>& 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,46 +62,28 @@ bool lookup_appointment_by_uid_variant(const std::shared_ptr<State>& state, GVar return false; } -void on_desktop_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) +void on_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself) { auto self = static_cast<Actions*>(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->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<Actions*>(gself)->desktop_open_alarm_app(); + static_cast<Actions*>(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<Actions*>(gself)->desktop_open_calendar_app(dt); + static_cast<Actions*>(gself)->open_calendar_app(dt); } -void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself) +void on_settings_activated (GSimpleAction*, GVariant*, gpointer gself) { - static_cast<Actions*>(gself)->desktop_open_settings_app(); -} - -void on_phone_appointment_activated (GSimpleAction*, GVariant *vuid, gpointer gself) -{ - auto self = static_cast<Actions*>(gself); - Appointment appt; - if (lookup_appointment_by_uid_variant(self->state(), vuid, appt)) - self->phone_open_appointment(appt); -} -void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast<Actions*>(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<Actions*>(gself)->phone_open_calendar_app(dt); -} -void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself) -{ - static_cast<Actions*>(gself)->phone_open_settings_app(); + static_cast<Actions*>(gself)->open_settings_app(); } void on_set_location(GSimpleAction * /*action*/, @@ -134,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); @@ -198,15 +175,15 @@ Actions::Actions(const std::shared_ptr<State>& state): { GActionEntry entries[] = { - { "desktop.open-appointment", on_desktop_appointment_activated, "s", 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, "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 }, + { "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" } @@ -240,7 +217,7 @@ Actions::Actions(const std::shared_ptr<State>& 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); /// |