From bf68bbe34cf8a8769345d1f36cc09cdc5d0ae07c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 5 Feb 2014 18:09:49 -0600 Subject: another pass at removing alarms from the menu once they're no longer upcoming. This version fixes the header's icon as well. --- src/menu.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 50a0087..b2562db 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace unity { namespace indicator { namespace datetime { @@ -103,13 +105,15 @@ protected: update_section(Appointments); // showing events got toggled }); m_state->planner->upcoming.changed().connect([this](const std::vector&){ - update_header(); // show an 'alarm' icon if there are upcoming alarms - update_section(Appointments); // "upcoming" is the list of Appointments we show + update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time }); m_state->clock->date_changed.connect([this](){ update_section(Calendar); // need to update the Date menuitem update_section(Locations); // locations' relative time may have changed }); + m_state->clock->minute_changed.connect([this](){ + update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time + }); m_state->locations->locations.changed().connect([this](const std::vector&) { update_section(Locations); // "locations" is the list of Locations we show }); @@ -132,6 +136,24 @@ protected: g_action_group_change_action_state(action_group, action_name.c_str(), state); } + void update_upcoming() + { + const auto now = m_state->clock->localtime(); + const auto next_minute = now.add_full(0,0,0,0,1,-now.seconds()); + + std::vector upcoming; + for(const auto& a : m_state->planner->upcoming.get()) + if (next_minute <= a.begin) + upcoming.push_back(a); + + if (m_upcoming != upcoming) + { + m_upcoming.swap(upcoming); + update_header(); // show an 'alarm' icon if there are upcoming alarms + update_section(Appointments); // "upcoming" is the list of Appointments we show + } + } + std::shared_ptr m_state; std::shared_ptr m_actions; std::shared_ptr m_formatter; @@ -149,6 +171,8 @@ protected: return m_serialized_alarm_icon; } + std::vector m_upcoming; + private: GVariant* get_serialized_calendar_icon() @@ -239,10 +263,9 @@ private: { int n = 0; const int MAX_APPTS = 5; - const auto now = m_state->clock->localtime(); std::set added; - for (const auto& appt : m_state->planner->upcoming.get()) + for (const auto& appt : m_upcoming) { // don't show too many if (n++ >= MAX_APPTS) @@ -252,10 +275,6 @@ private: if (added.count(appt.uid)) continue; - // don't show appointments that have already started - if ((appt.beginplanner->upcoming.get()) + for(const auto& appointment : m_upcoming) if((has_alarms = appointment.has_alarms)) break; -- cgit v1.2.3