From 3f4d409f21bbb1f79f149a5ee66dcddaa505ddb1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 9 Mar 2014 21:08:47 -0500 Subject: 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). --- include/datetime/clock-watcher.h | 9 +++-- include/datetime/date-time.h | 5 +++ include/datetime/engine-eds.h | 73 +++++++++++++++++++++++++++++++++++++ include/datetime/planner-eds.h | 23 ++++++++---- include/datetime/planner-month.h | 56 ++++++++++++++++++++++++++++ include/datetime/planner-range.h | 62 +++++++++++++++++++++++++++++++ include/datetime/planner-upcoming.h | 56 ++++++++++++++++++++++++++++ include/datetime/planner.h | 29 +-------------- include/datetime/state.h | 14 +++++-- 9 files changed, 285 insertions(+), 42 deletions(-) create mode 100644 include/datetime/engine-eds.h create mode 100644 include/datetime/planner-month.h create mode 100644 include/datetime/planner-range.h create mode 100644 include/datetime/planner-upcoming.h (limited to 'include/datetime') 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 #include +#include +#include #include @@ -53,14 +54,16 @@ public: class ClockWatcherImpl: public ClockWatcher { public: - ClockWatcherImpl(const std::shared_ptr& state); + ClockWatcherImpl(const std::shared_ptr& clock, + const std::shared_ptr& upcoming_planner); ~ClockWatcherImpl() =default; core::Signal& alarm_reached(); private: void pulse(); std::set m_triggered; - std::shared_ptr m_state; + const std::shared_ptr m_clock; + const std::shared_ptr m_upcoming_planner; core::Signal 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_ENGINE_EDS__H +#define INDICATOR_DATETIME_ENGINE_EDS__H + +#include +#include +#include + +#include +#include + +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&)> appointment_func); + + core::Signal<>& changed(); + +private: + class Impl; + std::unique_ptr 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 -#include +#include + +#include #include #include // 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, + EdsPlanner(const std::shared_ptr& eds_engine, const std::shared_ptr& timezone); - virtual ~PlannerEds(); + virtual ~EdsPlanner(); + + core::Property>& appointments(); + +protected: + void rebuild_now(); private: - class Impl; - std::unique_ptr p; + std::shared_ptr m_engine; + std::shared_ptr m_timezone; + core::Property> 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_MONTH_H +#define INDICATOR_DATETIME_PLANNER_MONTH_H + +#include + +#include +#include + +#include // 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& range_planner, + const DateTime& month_in); + ~MonthPlanner() =default; + + core::Property>& appointments(); + core::Property& month(); + +private: + std::shared_ptr m_range_planner; + core::Property 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_RANGE_H +#define INDICATOR_DATETIME_PLANNER_RANGE_H + +#include + +#include + +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>& 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> 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_UPCOMING_H +#define INDICATOR_DATETIME_PLANNER_UPCOMING_H + +#include + +#include +#include + +#include // 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& range_planner, + const DateTime& date); + ~UpcomingPlanner() =default; + + core::Property>& appointments(); + core::Property& date(); + +private: + std::shared_ptr m_range_planner; + core::Property 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 time; - - /** - * \brief The next few appointments that follow the time specified in the time property. - */ - core::Property> upcoming; - - /** - * \brief The appointments that occur in the same month as the time property - */ - core::Property> this_month; + virtual core::Property>& 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 #include -#include +#include +#include #include #include @@ -60,9 +61,14 @@ struct State section of the #Menu */ std::shared_ptr locations; - /** \brief The appointments to be displayed in the Calendar and - Appointments sections of the #Menu */ - std::shared_ptr planner; + /** \brief Appointments in the month that's being displayed + in the calendar section of the #Menu */ + std::shared_ptr calendar_month; + + /** \brief The next appointments that follow highlighed date + highlighted in the calendar section of the #Menu + (default date = today) */ + std::shared_ptr calendar_upcoming; /** \brief Configuration options that modify the view */ std::shared_ptr settings; -- cgit v1.2.3