aboutsummaryrefslogtreecommitdiff
path: root/include/datetime
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-03-09 21:08:47 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-03-09 21:08:47 -0500
commit3f4d409f21bbb1f79f149a5ee66dcddaa505ddb1 (patch)
treeab1f4ba4e7635b3ea2cb600cc8de9b3e52a6c9d1 /include/datetime
parent375277fa6b2c8eaac2e2a824bd1e43bbd54b75e3 (diff)
downloadayatana-indicator-datetime-3f4d409f21bbb1f79f149a5ee66dcddaa505ddb1.tar.gz
ayatana-indicator-datetime-3f4d409f21bbb1f79f149a5ee66dcddaa505ddb1.tar.bz2
ayatana-indicator-datetime-3f4d409f21bbb1f79f149a5ee66dcddaa505ddb1.zip
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu).
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.h73
-rw-r--r--include/datetime/planner-eds.h23
-rw-r--r--include/datetime/planner-month.h56
-rw-r--r--include/datetime/planner-range.h62
-rw-r--r--include/datetime/planner-upcoming.h56
-rw-r--r--include/datetime/planner.h29
-rw-r--r--include/datetime/state.h14
9 files changed, 285 insertions, 42 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..e269167
--- /dev/null
+++ b/include/datetime/engine-eds.h
@@ -0,0 +1,73 @@
+/*
+ * 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/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:
+ 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/planner-eds.h b/include/datetime/planner-eds.h
index 3d558df..95b5d79 100644
--- a/include/datetime/planner-eds.h
+++ b/include/datetime/planner-eds.h
@@ -20,8 +20,9 @@
#ifndef INDICATOR_DATETIME_PLANNER_EDS_H
#define INDICATOR_DATETIME_PLANNER_EDS_H
-#include <datetime/clock.h>
-#include <datetime/planner.h>
+#include <datetime/planner-range.h>
+
+#include <datetime/engine-eds.h>
#include <datetime/timezone.h>
#include <memory> // shared_ptr, unique_ptr
@@ -31,18 +32,24 @@ namespace indicator {
namespace datetime {
/**
- * \brief Planner which uses EDS as its backend
+ * \brief An EDS-based #RangePlanner
*/
-class PlannerEds: public Planner
+class EdsPlanner: public RangePlanner
{
public:
- PlannerEds(const std::shared_ptr<Clock>& clock,
+ EdsPlanner(const std::shared_ptr<EdsEngine>& eds_engine,
const std::shared_ptr<Timezone>& timezone);
- virtual ~PlannerEds();
+ virtual ~EdsPlanner();
+
+ core::Property<std::vector<Appointment>>& appointments();
+
+protected:
+ void rebuild_now();
private:
- class Impl;
- std::unique_ptr<Impl> p;
+ std::shared_ptr<EdsEngine> m_engine;
+ std::shared_ptr<Timezone> m_timezone;
+ core::Property<std::vector<Appointment>> m_appointments;
};
} // namespace datetime
diff --git a/include/datetime/planner-month.h b/include/datetime/planner-month.h
new file mode 100644
index 0000000..492529f
--- /dev/null
+++ b/include/datetime/planner-month.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_MONTH_H
+#define INDICATOR_DATETIME_PLANNER_MONTH_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 #Planner that contains appointments for a specified calendar month
+ */
+class MonthPlanner: public Planner
+{
+public:
+ 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:
+ std::shared_ptr<RangePlanner> m_range_planner;
+ core::Property<DateTime> m_month;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#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..5306cdc
--- /dev/null
+++ b/include/datetime/planner-range.h
@@ -0,0 +1,62 @@
+/*
+ * 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>
+
+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();
+ core::Property<std::pair<DateTime,DateTime>>& range();
+
+protected:
+ RangePlanner();
+
+ void rebuild_soon();
+ virtual void rebuild_now() =0;
+
+private:
+ static gboolean rebuild_now_static(gpointer);
+ guint m_rebuild_tag = 0;
+ core::Property<std::pair<DateTime,DateTime>> m_range;
+
+ // we've got a GSignal tag here, so disable copying
+ RangePlanner(const RangePlanner&) =delete;
+ RangePlanner& 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;