aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-22 14:28:20 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-22 14:28:20 -0600
commitaad7e86a109aeec75b3772cda20478363f966745 (patch)
tree5049662b13435cc5b422e1194bd617a1089e6fb6 /include
parente2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11 (diff)
downloadayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.tar.gz
ayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.tar.bz2
ayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.zip
Alarms is going to need to know when the clock's minute changes. We already have a timer for that in Formatter, so move it from there to Clock and add a corresponding public signal Clock.minuteChanged that both Formatter and Alarms can use. Sync unit tests.
Diffstat (limited to 'include')
-rw-r--r--include/datetime/clock-mock.h8
-rw-r--r--include/datetime/clock.h20
-rw-r--r--include/datetime/date-time.h5
3 files changed, 16 insertions, 17 deletions
diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h
index 19a859b..27926ff 100644
--- a/include/datetime/clock-mock.h
+++ b/include/datetime/clock-mock.h
@@ -42,11 +42,11 @@ public:
DateTime localtime() const { return m_localtime; }
void set_localtime(const DateTime& dt) {
- const auto old_day = m_localtime.day_of_year();
+ const auto old = m_localtime;
m_localtime = dt;
- skewDetected();
- const auto new_day = m_localtime.day_of_year();
- if (old_day != new_day)
+ if (!DateTime::is_same_minute(old, m_localtime))
+ minuteChanged();
+ if (!DateTime::is_same_day(old, m_localtime))
dateChanged();
}
diff --git a/include/datetime/clock.h b/include/datetime/clock.h
index 9e87082..b3e3538 100644
--- a/include/datetime/clock.h
+++ b/include/datetime/clock.h
@@ -35,21 +35,25 @@ namespace datetime {
/**
* \brief A clock.
- *
- * Provides a signal to notify when clock skew is detected, such as
- * when the timezone changes or when the system resumes from sleep.
*/
class Clock
{
public:
virtual ~Clock();
virtual DateTime localtime() const =0;
- core::Signal<> skewDetected;
+
+ /** \brief A signal which fires when the clock's minute changes */
+ core::Signal<> minuteChanged;
+
+ /** \brief A signal which fires when the clock's date changes */
core::Signal<> dateChanged;
protected:
Clock();
+ /** \brief Compares old and new times, emits minuteChanged() or dateChanged() signals if appropriate */
+ void maybe_emit (const DateTime& a, const DateTime& b);
+
private:
static void onSystemBusReady(GObject*, GAsyncResult*, gpointer);
static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer);
@@ -70,12 +74,7 @@ private:
class Timezones;
/**
- * \brief A live clock that provides the actual system time.
- *
- * This subclass also adds another clock skew detection test:
- * it wakes up every skewTestIntervalSec seconds to see how
- * much time has passed since the last wakeup. If the answer
- * isn't what it expected, the skewDetected signal is triggered.
+ * \brief A live #Clock that provides the actual system time.
*/
class LiveClock: public Clock
{
@@ -83,7 +82,6 @@ public:
LiveClock (const std::shared_ptr<Timezones>& zones);
virtual ~LiveClock();
virtual DateTime localtime() const;
- core::Property<unsigned int> skewTestIntervalSec;
private:
class Impl;
diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h
index 145e34e..c2429eb 100644
--- a/include/datetime/date-time.h
+++ b/include/datetime/date-time.h
@@ -49,13 +49,14 @@ public:
std::string format(const std::string& fmt) const;
int day_of_month() const;
int64_t to_unix() const;
- int day_of_year() const;
- gint64 difference(const DateTime& that) const;
bool operator<(const DateTime& that) const;
bool operator!=(const DateTime& that) const;
bool operator==(const DateTime& that) const;
+ static bool is_same_day(const DateTime& a, const DateTime& b);
+ static bool is_same_minute(const DateTime& a, const DateTime& b);
+
private:
std::shared_ptr<GDateTime> m_dt;
};