aboutsummaryrefslogtreecommitdiff
path: root/src/menu.cpp
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/menu.cpp
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/menu.cpp')
-rw-r--r--src/menu.cpp41
1 files changed, 31 insertions, 10 deletions
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
{