aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkugiigi <kugi_eusebio@protonmail.com>2021-03-20 11:52:07 +0800
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2023-12-19 16:57:38 +0100
commit63a57fde6677d8f663e5880a259998b95b1da6c5 (patch)
treecff6527e6f869c465e0b90296e761e246a8a39c6 /src
parentecaacccacf853059ea4588c44bd13035faaba6af (diff)
downloadayatana-indicator-datetime-63a57fde6677d8f663e5880a259998b95b1da6c5.tar.gz
ayatana-indicator-datetime-63a57fde6677d8f663e5880a259998b95b1da6c5.tar.bz2
ayatana-indicator-datetime-63a57fde6677d8f663e5880a259998b95b1da6c5.zip
Add option to show/hide alarms
Diffstat (limited to 'src')
-rw-r--r--src/actions.cpp5
-rw-r--r--src/menu.cpp41
-rw-r--r--src/settings-live.cpp13
3 files changed, 48 insertions, 11 deletions
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/menu.cpp b/src/menu.cpp
index 0ee9242..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);
@@ -601,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();
@@ -609,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/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)