aboutsummaryrefslogtreecommitdiff
path: root/include/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'include/datetime')
-rw-r--r--include/datetime/clock-watcher.h9
-rw-r--r--include/datetime/date-time.h5
-rw-r--r--include/datetime/engine-eds.h75
-rw-r--r--include/datetime/engine-mock.h68
-rw-r--r--include/datetime/engine.h68
-rw-r--r--include/datetime/planner-month.h (renamed from include/datetime/planner-eds.h)30
-rw-r--r--include/datetime/planner-range.h84
-rw-r--r--include/datetime/planner-upcoming.h56
-rw-r--r--include/datetime/planner.h29
-rw-r--r--include/datetime/state.h14
10 files changed, 392 insertions, 46 deletions
diff --git a/include/datetime/clock-watcher.h b/include/datetime/clock-watcher.h
index e93b468..90bbb63 100644
--- a/include/datetime/clock-watcher.h
+++ b/include/datetime/clock-watcher.h
@@ -20,8 +20,9 @@
#ifndef INDICATOR_DATETIME_CLOCK_WATCHER_H
#define INDICATOR_DATETIME_CLOCK_WATCHER_H
-#include <datetime/state.h>
#include <datetime/appointment.h>
+#include <datetime/clock.h>
+#include <datetime/planner-upcoming.h>
#include <core/signal.h>
@@ -53,14 +54,16 @@ public:
class ClockWatcherImpl: public ClockWatcher
{
public:
- ClockWatcherImpl(const std::shared_ptr<const State>& state);
+ ClockWatcherImpl(const std::shared_ptr<Clock>& clock,
+ const std::shared_ptr<UpcomingPlanner>& upcoming_planner);
~ClockWatcherImpl() =default;
core::Signal<const Appointment&>& alarm_reached();
private:
void pulse();
std::set<std::string> m_triggered;
- std::shared_ptr<const State> m_state;
+ const std::shared_ptr<Clock> m_clock;
+ const std::shared_ptr<UpcomingPlanner> m_upcoming_planner;
core::Signal<const Appointment&> m_alarm_reached;
};
diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h
index b054a1f..f861c2e 100644
--- a/include/datetime/date-time.h
+++ b/include/datetime/date-time.h
@@ -36,6 +36,8 @@ class DateTime
{
public:
static DateTime NowLocal();
+ static DateTime Local(int years, int months, int days, int hours, int minutes, int seconds);
+
explicit DateTime(time_t t);
explicit DateTime(GDateTime* in=nullptr);
DateTime& operator=(GDateTime* in);
@@ -48,7 +50,10 @@ public:
GDateTime* operator()() const {return get();}
std::string format(const std::string& fmt) const;
+ void ymd(int& year, int& month, int& day) const;
int day_of_month() const;
+ int hour() const;
+ int minute() const;
double seconds() const;
int64_t to_unix() const;
diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h
new file mode 100644
index 0000000..4b260a8
--- /dev/null
+++ b/include/datetime/engine-eds.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_ENGINE_EDS__H
+#define INDICATOR_DATETIME_ENGINE_EDS__H
+
+#include <datetime/engine.h>
+
+#include <datetime/appointment.h>
+#include <datetime/date-time.h>
+#include <datetime/timezone.h>
+
+#include <functional>
+#include <vector>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/****
+*****
+****/
+
+/**
+ * Class wrapper around EDS so multiple #EdsPlanners can share resources
+ *
+ * @see EdsPlanner
+ */
+class EdsEngine: public Engine
+{
+public:
+ EdsEngine();
+ ~EdsEngine();
+
+ void get_appointments(const DateTime& begin,
+ const DateTime& end,
+ const Timezone& default_timezone,
+ std::function<void(const std::vector<Appointment>&)> appointment_func);
+
+ core::Signal<>& changed();
+
+private:
+ class Impl;
+ std::unique_ptr<Impl> p;
+
+ // we've got a unique_ptr here, disable copying...
+ EdsEngine(const EdsEngine&) =delete;
+ EdsEngine& operator=(const EdsEngine&) =delete;
+};
+
+/***
+****
+***/
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ENGINE_EDS__H
diff --git a/include/datetime/engine-mock.h b/include/datetime/engine-mock.h
new file mode 100644
index 0000000..ecbf102
--- /dev/null
+++ b/include/datetime/engine-mock.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_ENGINE_MOCK__H
+#define INDICATOR_DATETIME_ENGINE_MOCK__H
+
+#include <datetime/engine.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/****
+*****
+****/
+
+/**
+ * A no-op #Engine
+ *
+ * @see Engine
+ */
+class MockEngine: public Engine
+{
+public:
+ MockEngine() =default;
+ ~MockEngine() =default;
+
+ void get_appointments(const DateTime& /*begin*/,
+ const DateTime& /*end*/,
+ const Timezone& /*default_timezone*/,
+ std::function<void(const std::vector<Appointment>&)> appointment_func) {
+ appointment_func(m_appointments);
+ }
+
+ core::Signal<>& changed() {
+ return m_changed;
+ }
+
+private:
+ core::Signal<> m_changed;
+ std::vector<Appointment> m_appointments;
+};
+
+/***
+****
+***/
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ENGINE_NOOP__H
diff --git a/include/datetime/engine.h b/include/datetime/engine.h
new file mode 100644
index 0000000..2e8237e
--- /dev/null
+++ b/include/datetime/engine.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_ENGINE__H
+#define INDICATOR_DATETIME_ENGINE__H
+
+#include <datetime/appointment.h>
+#include <datetime/date-time.h>
+#include <datetime/timezone.h>
+
+#include <functional>
+#include <vector>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/****
+*****
+****/
+
+/**
+ * Class wrapper around the backend that generates appointments
+ *
+ * @see EdsEngine
+ * @see EdsPlanner
+ */
+class Engine
+{
+public:
+ virtual ~Engine() =default;
+
+ virtual void get_appointments(const DateTime& begin,
+ const DateTime& end,
+ const Timezone& default_timezone,
+ std::function<void(const std::vector<Appointment>&)> appointment_func) =0;
+
+ virtual core::Signal<>& changed() =0;
+
+protected:
+ Engine() =default;
+};
+
+/***
+****
+***/
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ENGINE__H
diff --git a/include/datetime/planner-eds.h b/include/datetime/planner-month.h
index a99f611..492529f 100644
--- a/include/datetime/planner-eds.h
+++ b/include/datetime/planner-month.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Canonical Ltd.
+ * Copyright 2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
@@ -17,34 +17,40 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#ifndef INDICATOR_DATETIME_PLANNER_EDS_H
-#define INDICATOR_DATETIME_PLANNER_EDS_H
+#ifndef INDICATOR_DATETIME_PLANNER_MONTH_H
+#define INDICATOR_DATETIME_PLANNER_MONTH_H
-#include <datetime/clock.h>
#include <datetime/planner.h>
-#include <memory> // shared_ptr, unique_ptr
+#include <datetime/date-time.h>
+#include <datetime/planner-range.h>
+
+#include <memory> // std::shared_ptr
namespace unity {
namespace indicator {
namespace datetime {
/**
- * \brief Planner which uses EDS as its backend
+ * \brief A #Planner that contains appointments for a specified calendar month
*/
-class PlannerEds: public Planner
+class MonthPlanner: public Planner
{
public:
- PlannerEds(const std::shared_ptr<Clock>& clock);
- virtual ~PlannerEds();
+ MonthPlanner(const std::shared_ptr<RangePlanner>& range_planner,
+ const DateTime& month_in);
+ ~MonthPlanner() =default;
+
+ core::Property<std::vector<Appointment>>& appointments();
+ core::Property<DateTime>& month();
private:
- class Impl;
- std::unique_ptr<Impl> p;
+ std::shared_ptr<RangePlanner> m_range_planner;
+ core::Property<DateTime> m_month;
};
} // namespace datetime
} // namespace indicator
} // namespace unity
-#endif // INDICATOR_DATETIME_PLANNER_EDS_H
+#endif // INDICATOR_DATETIME_PLANNER_MONTH_H
diff --git a/include/datetime/planner-range.h b/include/datetime/planner-range.h
new file mode 100644
index 0000000..25334a6
--- /dev/null
+++ b/include/datetime/planner-range.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_PLANNER_RANGE_H
+#define INDICATOR_DATETIME_PLANNER_RANGE_H
+
+#include <datetime/planner.h>
+
+#include <datetime/date-time.h>
+#include <datetime/engine.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief A #Planner that contains appointments in a specified date range
+ *
+ * @see Planner
+ */
+class RangePlanner: public Planner
+{
+public:
+ virtual ~RangePlanner() =default;
+ virtual core::Property<std::pair<DateTime,DateTime>>& range() =0;
+
+protected:
+ RangePlanner() =default;
+};
+
+/**
+ * \brief A #RangePlanner that uses an #Engine to generate appointments
+ *
+ * @see Planner
+ */
+class SimpleRangePlanner: public RangePlanner
+{
+public:
+ SimpleRangePlanner(const std::shared_ptr<Engine>& engine,
+ const std::shared_ptr<Timezone>& timezone);
+ virtual ~SimpleRangePlanner();
+
+ core::Property<std::vector<Appointment>>& appointments();
+ core::Property<std::pair<DateTime,DateTime>>& range();
+
+private:
+ // rebuild scaffolding
+ void rebuild_soon();
+ virtual void rebuild_now();
+ static gboolean rebuild_now_static(gpointer);
+ guint m_rebuild_tag = 0;
+
+ std::shared_ptr<Engine> m_engine;
+ std::shared_ptr<Timezone> m_timezone;
+ core::Property<std::pair<DateTime,DateTime>> m_range;
+ core::Property<std::vector<Appointment>> m_appointments;
+
+ // we've got a GSignal tag here, so disable copying
+ SimpleRangePlanner(const RangePlanner&) =delete;
+ SimpleRangePlanner& operator=(const RangePlanner&) =delete;
+};
+
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_PLANNER_RANGE_H
diff --git a/include/datetime/planner-upcoming.h b/include/datetime/planner-upcoming.h
new file mode 100644
index 0000000..683543f
--- /dev/null
+++ b/include/datetime/planner-upcoming.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef INDICATOR_DATETIME_PLANNER_UPCOMING_H
+#define INDICATOR_DATETIME_PLANNER_UPCOMING_H
+
+#include <datetime/planner.h>
+
+#include <datetime/date-time.h>
+#include <datetime/planner-range.h>
+
+#include <memory> // std::shared_ptr
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief A collection of upcoming appointments starting from the specified date
+ */
+class UpcomingPlanner: public Planner
+{
+public:
+ UpcomingPlanner(const std::shared_ptr<RangePlanner>& range_planner,
+ const DateTime& date);
+ ~UpcomingPlanner() =default;
+
+ core::Property<std::vector<Appointment>>& appointments();
+ core::Property<DateTime>& date();
+
+private:
+ std::shared_ptr<RangePlanner> m_range_planner;
+ core::Property<DateTime> m_date;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_PLANNER_UPCOMING_H
diff --git a/include/datetime/planner.h b/include/datetime/planner.h
index 376a31f..e6ef927 100644
--- a/include/datetime/planner.h
+++ b/include/datetime/planner.h
@@ -32,41 +32,16 @@ namespace indicator {
namespace datetime {
/**
- * \brief Simple appointment book
- *
- * @see EdsPlanner
- * @see State
+ * \brief Simple collection of appointments
*/
class Planner
{
public:
virtual ~Planner() =default;
-
- /**
- * \brief Timestamp used to determine the appointments in the `upcoming' and `this_month' properties.
- * Setting this value will cause the planner to re-query its backend and
- * update the `upcoming' and `this_month' properties.
- */
- core::Property<DateTime> time;
-
- /**
- * \brief The next few appointments that follow the time specified in the time property.
- */
- core::Property<std::vector<Appointment>> upcoming;
-
- /**
- * \brief The appointments that occur in the same month as the time property
- */
- core::Property<std::vector<Appointment>> this_month;
+ virtual core::Property<std::vector<Appointment>>& appointments() =0;
protected:
Planner() =default;
-
-private:
-
- // disable copying
- Planner(const Planner&) =delete;
- Planner& operator=(const Planner&) =delete;
};
} // namespace datetime
diff --git a/include/datetime/state.h b/include/datetime/state.h
index 414be32..0e1043c 100644
--- a/include/datetime/state.h
+++ b/include/datetime/state.h
@@ -22,7 +22,8 @@
#include <datetime/clock.h>
#include <datetime/locations.h>
-#include <datetime/planner.h>
+#include <datetime/planner-month.h>
+#include <datetime/planner-upcoming.h>
#include <datetime/settings.h>
#include <datetime/timezones.h>
@@ -60,9 +61,14 @@ struct State
section of the #Menu */
std::shared_ptr<Locations> locations;
- /** \brief The appointments to be displayed in the Calendar and
- Appointments sections of the #Menu */
- std::shared_ptr<Planner> planner;
+ /** \brief Appointments in the month that's being displayed
+ in the calendar section of the #Menu */
+ std::shared_ptr<MonthPlanner> calendar_month;
+
+ /** \brief The next appointments that follow highlighed date
+ highlighted in the calendar section of the #Menu
+ (default date = today) */
+ std::shared_ptr<UpcomingPlanner> calendar_upcoming;
/** \brief Configuration options that modify the view */
std::shared_ptr<Settings> settings;