diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/actions.cpp | 5 | ||||
-rw-r--r-- | src/engine-eds.cpp | 43 | ||||
-rw-r--r-- | src/haptic.cpp | 14 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/menu.cpp | 83 | ||||
-rw-r--r-- | src/notifications.cpp | 26 | ||||
-rw-r--r-- | src/settings-live.cpp | 13 | ||||
-rw-r--r-- | src/snap.cpp | 19 |
9 files changed, 148 insertions, 62 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index faf4341..69a2dfc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,7 @@ endif() # add the bin dir to our include path so our code can find the generated header files include_directories (${CMAKE_CURRENT_BINARY_DIR}) +set_source_files_properties (engine-eds.cpp PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -Wno-enum-constexpr-conversion") add_library (${SERVICE_LIB} STATIC ${SERVICE_C_SOURCES} ${SERVICE_CXX_SOURCES} ${SERVICE_GENERATED_SOURCES}) include_directories (${CMAKE_SOURCE_DIR}) link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) diff --git a/src/actions.cpp b/src/actions.cpp index c184aef..18b99e8 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -142,7 +142,10 @@ GVariant* create_calendar_state(const std::shared_ptr<State>& state) { gboolean days[32] = { 0 }; for (const auto& appt : state->calendar_month->appointments().get()) - days[appt.begin.day_of_month()] = true; + if (!appt.is_alarm() || state->settings->show_alarms.get()) + { + days[appt.begin.day_of_month()] = true; + } GVariantBuilder day_builder; g_variant_builder_init(&day_builder, G_VARIANT_TYPE("ai")); diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index b7f4682..7a61fc0 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 Robert Tari * * 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 @@ -635,19 +635,18 @@ private: auto action = e_cal_component_alarm_get_action(alarm); if (action == E_CAL_COMPONENT_ALARM_AUDIO) { - ICalAttach *attach = nullptr; auto attachments = e_cal_component_alarm_get_attachments(alarm); - if (attachments != nullptr && attachments->next != nullptr) - attach = I_CAL_ATTACH (attachments->data); + for (; attachments != nullptr; attachments = attachments->next) { + ICalAttach *attach = I_CAL_ATTACH (attachments->data); - if (attach != nullptr) - { - if (i_cal_attach_get_is_url (attach)) + if (attach != nullptr && i_cal_attach_get_is_url (attach)) { const char* url = i_cal_attach_get_url(attach); - if (url != nullptr) + if (url != nullptr) { ret = url; + break; + } } } if (ret.empty()) @@ -1075,6 +1074,34 @@ private: } g_slist_free_full(categ_list, g_free); + // Get the colour - we might need this override in the future + + /*if (icc) + { + ECalComponentPropertyBag *pBag = e_cal_component_property_bag_new_from_component (icc, NULL, NULL); + + if (pBag) + { + guint nProperties = e_cal_component_property_bag_get_count (pBag); + + for (guint nProperty = 0; nProperty < nProperties; nProperty++) + { + ICalProperty *pProperty = e_cal_component_property_bag_get (pBag, nProperty); + gchar *sName = i_cal_property_get_property_name (pProperty); + gboolean bColour = !g_strcmp0 (sName, "COLOR"); + + if (bColour) + { + baseline.color = i_cal_property_get_value_as_string (pProperty); + + break; + } + } + + e_cal_component_property_bag_free (pBag); + } + }*/ + g_debug("%s got appointment from %s to %s: %s", G_STRLOC, baseline.begin.format("%F %T %z").c_str(), baseline.end.format("%F %T %z").c_str(), diff --git a/src/haptic.cpp b/src/haptic.cpp index 370f0f9..2b0af4c 100644 --- a/src/haptic.cpp +++ b/src/haptic.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2022 Robert Tari * * 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 @@ -43,7 +43,7 @@ public: m_cancellable(g_cancellable_new()), m_repeat(repeat) { - g_bus_get (G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this); + g_bus_get (G_BUS_TYPE_SYSTEM, m_cancellable, on_bus_ready, this); } ~Impl() @@ -105,20 +105,14 @@ private: void call_vibrate() { - GVariantBuilder builder; - auto duration = g_variant_new_int32 (1000); - - g_variant_builder_init (&builder, G_VARIANT_TYPE_INT32); - g_variant_builder_add_value (&builder, duration); - - auto vibrate_arg = g_variant_builder_end (&builder); + auto duration = g_variant_new ("(i)", 1000); g_dbus_connection_call (m_bus, BUS_HAPTIC_NAME, BUS_HAPTIC_PATH, BUS_HAPTIC_INTERFACE, "vibrate", - vibrate_arg, + duration, nullptr, G_DBUS_CALL_FLAGS_NONE, -1, diff --git a/src/main.cpp b/src/main.cpp index 4590e84..29e4472 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,9 +32,7 @@ #include <datetime/planner-snooze.h> #include <datetime/planner-range.h> #include <datetime/settings-live.h> -#ifdef LOMIRI_FEATURES_ENABLED #include <datetime/snap.h> -#endif #include <datetime/state.h> #include <datetime/timezones-live.h> #include <datetime/timezone-timedated.h> @@ -95,7 +93,6 @@ namespace return state; } -#ifdef LOMIRI_FEATURES_ENABLED std::shared_ptr<AlarmQueue> create_simple_alarm_queue(const std::shared_ptr<Clock>& clock, const std::shared_ptr<Planner>& snooze_planner, const std::shared_ptr<Engine>& engine, @@ -119,7 +116,6 @@ namespace auto wakeup_timer = std::make_shared<PowerdWakeupTimer>(clock); return std::make_shared<SimpleAlarmQueue>(clock, planner, wakeup_timer); } -#endif } int @@ -149,7 +145,6 @@ main(int /*argc*/, char** /*argv*/) auto actions = std::make_shared<LiveActions>(state); MenuFactory factory(actions, state); -#ifdef LOMIRI_FEATURES_ENABLED // set up the snap decisions auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock); auto notification_engine = std::make_shared<ain::Engine>("ayatana-indicator-datetime-service"); @@ -173,7 +168,6 @@ main(int /*argc*/, char** /*argv*/) engine->disable_alarm(appointment); }; alarm_queue->alarm_reached().connect(on_alarm_reached); -#endif // create the menus std::vector<std::shared_ptr<Menu>> menus; diff --git a/src/menu.cpp b/src/menu.cpp index 1f80cd4..b8ef1b6 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -72,13 +72,14 @@ GMenuModel* Menu::menu_model() std::vector<Appointment> Menu::get_display_appointments(const std::vector<Appointment>& appointments_in, const DateTime& now, - unsigned int max_items) + unsigned int max_items, + const bool include_alarms) { std::vector<Appointment> appointments; std::copy_if(appointments_in.begin(), appointments_in.end(), std::back_inserter(appointments), - [now](const Appointment& a){return a.end >= now;}); + [now, include_alarms](const Appointment& a){return a.end >= now && (!a.is_alarm() || include_alarms);}); if (appointments.size() > max_items) { @@ -186,6 +187,9 @@ protected: m_state->settings->show_events.changed().connect([this](bool){ update_section(Appointments); // showing events got toggled }); + m_state->settings->show_alarms.changed().connect([this](bool){ + update_section(Appointments); // showing alarms got toggled + }); m_state->calendar_upcoming->date().changed().connect([this](const DateTime&){ update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time }); @@ -240,7 +244,9 @@ protected: auto upcoming = get_display_appointments( m_state->calendar_upcoming->appointments().get(), - begin + begin, + 5, + m_state->settings->show_alarms.get() ); if (m_upcoming != upcoming) @@ -268,10 +274,6 @@ protected: return m_serialized_alarm_icon; } - std::vector<Appointment> m_upcoming; - -private: - GVariant* get_serialized_calendar_icon() { if (G_UNLIKELY(m_serialized_calendar_icon == nullptr)) @@ -284,6 +286,10 @@ private: return m_serialized_calendar_icon; } + std::vector<Appointment> m_upcoming; + +private: + void create_gmenu() { g_assert(m_submenu == nullptr); @@ -428,29 +434,32 @@ private: { auto menu = g_menu_new(); - if ((profile==Desktop) && m_state->settings->show_events.get()) + if (m_state->settings->show_events.get()) { - add_appointments (menu, profile); - - if (m_actions->desktop_has_calendar_app()) + if (profile==Desktop) { - // add the 'Add Event…' menuitem - auto menu_item = g_menu_item_new(_("Add Event…"), nullptr); - const gchar* action_name = "indicator.desktop.open-calendar-app"; - auto v = g_variant_new_int64(0); - g_menu_item_set_action_and_target_value(menu_item, action_name, v); - g_menu_append_item(menu, menu_item); - g_object_unref(menu_item); + add_appointments (menu, profile); + + if (m_actions->desktop_has_calendar_app()) + { + // add the 'Add Event…' menuitem + auto menu_item = g_menu_item_new(_("Add Event…"), nullptr); + const gchar* action_name = "indicator.desktop.open-calendar-app"; + auto v = g_variant_new_int64(0); + g_menu_item_set_action_and_target_value(menu_item, action_name, v); + g_menu_append_item(menu, menu_item); + g_object_unref(menu_item); + } } - } - else if (profile==Phone) - { - auto menu_item = g_menu_item_new (_("Clock"), "indicator.phone.open-alarm-app"); - g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon()); - g_menu_append_item (menu, menu_item); - g_object_unref (menu_item); + else if (profile==Phone) + { + auto menu_item = g_menu_item_new (_("Clock"), "indicator.phone.open-alarm-app"); + g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon()); + g_menu_append_item (menu, menu_item); + g_object_unref (menu_item); - add_appointments (menu, profile); + add_appointments (menu, profile); + } } return G_MENU_MODEL(menu); @@ -561,6 +570,7 @@ protected: g_variant_builder_add(&b, "{sv}", "label", label); g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string(title)); g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(TRUE)); + g_variant_builder_add(&b, "{sv}", "tooltip", g_variant_new_string (_("Time & date settings, quick calendar access"))); return g_variant_builder_end(&b); } }; @@ -597,6 +607,7 @@ protected: { // are there alarms? bool has_alarms = false; + bool has_non_alarm_events = false; for(const auto& appointment : m_upcoming) { has_alarms = appointment.is_alarm(); @@ -605,19 +616,33 @@ protected: { break; } + else + { + has_non_alarm_events = true; + } } + GVariantBuilder b; g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string (_("Time and Date"))); g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean (TRUE)); - if (has_alarms) + if (has_alarms || has_non_alarm_events) + { auto label = m_formatter->header.get(); - auto a11y = g_strdup_printf(_("%s (has alarms)"), label.c_str()); + auto a11y = g_strdup_printf(_("%s (has events)"), label.c_str()); g_variant_builder_add(&b, "{sv}", "label", g_variant_new_string(label.c_str())); g_variant_builder_add(&b, "{sv}", "accessible-desc", g_variant_new_take_string(a11y)); - g_variant_builder_add(&b, "{sv}", "icon", get_serialized_alarm_icon()); + + if (has_alarms && m_state->settings->show_alarms.get()) + { + g_variant_builder_add(&b, "{sv}", "icon", get_serialized_alarm_icon()); + } + else + { + g_variant_builder_add(&b, "{sv}", "icon", get_serialized_calendar_icon()); + } } else { diff --git a/src/notifications.cpp b/src/notifications.cpp index bb0e05c..4049851 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2023 Robert Tari * * 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 @@ -199,6 +199,13 @@ public: return server_caps().count("actions") != 0; } +#ifdef LOMIRI_FEATURES_ENABLED + bool requires_hint_lomiri_timeout() const + { + return server_caps().count(HINT_LOMIRI_TIMEOUT) != 0; + } +#endif + void close_all () { // call close() on all our keys @@ -248,10 +255,15 @@ public: { const auto& d= info.m_duration; auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(d); - - notify_notification_set_hint (nn.get(), - HINT_TIMEOUT, - g_variant_new_int32(ms.count())); + notify_notification_set_timeout (nn.get (), ms.count ()); +#ifdef LOMIRI_FEATURES_ENABLED + if (requires_hint_lomiri_timeout()) { + // Lomiri has its own logic regarding timeout. + notify_notification_set_hint (nn.get(), + HINT_LOMIRI_TIMEOUT, + g_variant_new_int32(ms.count())); + } +#endif } for (const auto& hint : info.m_string_hints) @@ -513,7 +525,9 @@ private: // as the name indicates, don't use this directly: use server_caps() instead mutable std::set<std::string> m_lazy_caps; - static constexpr char const * HINT_TIMEOUT {"x-lomiri-snap-decisions-timeout"}; +#ifdef LOMIRI_FEATURES_ENABLED + static constexpr char const * HINT_LOMIRI_TIMEOUT {"x-lomiri-snap-decisions-timeout"}; +#endif }; /*** diff --git a/src/settings-live.cpp b/src/settings-live.cpp index cf18739..9cbc23c 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -47,6 +47,7 @@ LiveSettings::LiveSettings(): update_show_day(); update_show_detected_locations(); update_show_events(); + update_show_alarms(); update_show_locations(); update_show_seconds(); update_show_week_numbers(); @@ -117,6 +118,10 @@ LiveSettings::LiveSettings(): g_settings_set_boolean(m_settings, SETTINGS_SHOW_EVENTS_S, value); }); + show_alarms.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings, SETTINGS_SHOW_ALARMS_S, value); + }); + show_locations.changed().connect([this](bool value){ g_settings_set_boolean(m_settings, SETTINGS_SHOW_LOCATIONS_S, value); }); @@ -239,6 +244,12 @@ void LiveSettings::update_show_events() show_events.set(val); } +void LiveSettings::update_show_alarms() +{ + const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_ALARMS_S); + show_alarms.set(val); +} + void LiveSettings::update_show_locations() { const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_LOCATIONS_S); @@ -415,6 +426,8 @@ void LiveSettings::update_key_ccid(const std::string& key) update_show_week_numbers(); else if (key == SETTINGS_SHOW_EVENTS_S) update_show_events(); + else if (key == SETTINGS_SHOW_ALARMS_S) + update_show_alarms(); else if (key == SETTINGS_SHOW_LOCATIONS_S) update_show_locations(); else if (key == SETTINGS_SHOW_DETECTED_S) diff --git a/src/snap.cpp b/src/snap.cpp index 46f1d7b..c18f955 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -21,6 +21,7 @@ #ifdef LOMIRI_FEATURES_ENABLED #include "dbus-accounts-sound.h" +#endif #include <datetime/snap.h> #include <datetime/utils.h> // is_locale_12h() @@ -64,6 +65,7 @@ public: m_cancellable(g_cancellable_new()), m_system_bus{G_DBUS_CONNECTION(g_object_ref(system_bus))} { + #ifdef LOMIRI_FEATURES_ENABLED auto object_path = g_strdup_printf("/org/freedesktop/Accounts/User%lu", (gulong)getuid()); @@ -75,13 +77,16 @@ public: on_sound_proxy_ready, this); g_free(object_path); + #endif } ~Impl() { g_cancellable_cancel(m_cancellable); g_clear_object(&m_cancellable); + #ifdef LOMIRI_FEATURES_ENABLED g_clear_object(&m_accounts_service_sound_proxy); + #endif g_clear_object(&m_system_bus); for (const auto& key : m_notifications) @@ -235,6 +240,7 @@ private: return m_settings->vibrate_silent_mode.get(); } +#ifdef LOMIRI_FEATURES_ENABLED static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) { GError * error; @@ -253,17 +259,26 @@ private: static_cast<Impl*>(gself)->m_accounts_service_sound_proxy = proxy; } } +#endif bool silent_mode() const { +#ifdef LOMIRI_FEATURES_ENABLED return (m_accounts_service_sound_proxy != nullptr) && (accounts_service_sound_get_silent_mode(m_accounts_service_sound_proxy)); +#else + return false; +#endif } bool should_vibrate() const { +#ifdef LOMIRI_FEATURES_ENABLED return (m_accounts_service_sound_proxy != nullptr) && (accounts_service_sound_get_other_vibrate(m_accounts_service_sound_proxy)); +#else + return true; +#endif } std::string get_alarm_uri(const Appointment& appointment, @@ -306,7 +321,9 @@ private: const std::shared_ptr<const Settings> m_settings; std::set<int> m_notifications; GCancellable * m_cancellable {nullptr}; +#ifdef LOMIRI_FEATURES_ENABLED AccountsServiceSound * m_accounts_service_sound_proxy {nullptr}; +#endif GDBusConnection * m_system_bus {nullptr}; static constexpr char const * ACTION_NONE {"none"}; @@ -345,5 +362,3 @@ Snap::operator()(const Appointment& appointment, } // namespace datetime } // namespace indicator } // namespace ayatana - -#endif |