aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-02-05 18:09:49 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-02-05 18:09:49 -0600
commitbf68bbe34cf8a8769345d1f36cc09cdc5d0ae07c (patch)
tree489206583514d4cf640c54d62458e98969a92001
parentdfd4f783102a0ca98b994fb80153e8accd3721ad (diff)
downloadayatana-indicator-datetime-bf68bbe34cf8a8769345d1f36cc09cdc5d0ae07c.tar.gz
ayatana-indicator-datetime-bf68bbe34cf8a8769345d1f36cc09cdc5d0ae07c.tar.bz2
ayatana-indicator-datetime-bf68bbe34cf8a8769345d1f36cc09cdc5d0ae07c.zip
another pass at removing alarms from the menu once they're no longer upcoming. This version fixes the header's icon as well.
-rw-r--r--include/datetime/date-time.h3
-rw-r--r--src/date-time.cpp18
-rw-r--r--src/menu.cpp37
3 files changed, 49 insertions, 9 deletions
diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h
index 2ad7856..b054a1f 100644
--- a/include/datetime/date-time.h
+++ b/include/datetime/date-time.h
@@ -41,6 +41,7 @@ public:
DateTime& operator=(GDateTime* in);
DateTime& operator=(const DateTime& in);
DateTime to_timezone(const std::string& zone) const;
+ DateTime add_full(int years, int months, int days, int hours, int minutes, double seconds) const;
void reset(GDateTime* in=nullptr);
GDateTime* get() const;
@@ -48,9 +49,11 @@ public:
std::string format(const std::string& fmt) const;
int day_of_month() const;
+ double seconds() const;
int64_t to_unix() const;
bool operator<(const DateTime& that) const;
+ bool operator<=(const DateTime& that) const;
bool operator!=(const DateTime& that) const;
bool operator==(const DateTime& that) const;
diff --git a/src/date-time.cpp b/src/date-time.cpp
index a634c5e..e6d99cd 100644
--- a/src/date-time.cpp
+++ b/src/date-time.cpp
@@ -69,6 +69,14 @@ DateTime DateTime::to_timezone(const std::string& zone) const
return dt;
}
+DateTime DateTime::add_full(int years, int months, int days, int hours, int minutes, double seconds) const
+{
+ auto gdt = g_date_time_add_full(get(), years, months, days, hours, minutes, seconds);
+ DateTime dt(gdt);
+ g_date_time_unref(gdt);
+ return dt;
+}
+
GDateTime* DateTime::get() const
{
g_assert(m_dt);
@@ -88,6 +96,11 @@ int DateTime::day_of_month() const
return g_date_time_get_day_of_month(get());
}
+double DateTime::seconds() const
+{
+ return g_date_time_get_seconds(get());
+}
+
int64_t DateTime::to_unix() const
{
return g_date_time_to_unix(get());
@@ -112,6 +125,11 @@ bool DateTime::operator<(const DateTime& that) const
return g_date_time_compare(get(), that.get()) < 0;
}
+bool DateTime::operator<=(const DateTime& that) const
+{
+ return g_date_time_compare(get(), that.get()) <= 0;
+}
+
bool DateTime::operator!=(const DateTime& that) const
{
// return true if this isn't set, or if it's not equal
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 <glib/gi18n.h>
#include <gio/gio.h>
+#include <vector>
+
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<Appointment>&){
- 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<Location>&) {
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<Appointment> 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<const State> m_state;
std::shared_ptr<Actions> m_actions;
std::shared_ptr<const Formatter> m_formatter;
@@ -149,6 +171,8 @@ protected:
return m_serialized_alarm_icon;
}
+ std::vector<Appointment> 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<std::string> 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.begin<now) || DateTime::is_same_minute(now,appt.begin))
- continue;
-
added.insert(appt.uid);
GDateTime* begin = appt.begin();
@@ -460,7 +479,7 @@ protected:
{
// are there alarms?
bool has_alarms = false;
- for(const auto& appointment : m_state->planner->upcoming.get())
+ for(const auto& appointment : m_upcoming)
if((has_alarms = appointment.has_alarms))
break;