diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/datetime/actions-live.h | 1 | ||||
-rw-r--r-- | include/datetime/actions.h | 1 | ||||
-rw-r--r-- | include/datetime/clock-watcher.h | 75 | ||||
-rw-r--r-- | include/datetime/date-time.h | 8 | ||||
-rw-r--r-- | include/datetime/engine-eds.h | 75 | ||||
-rw-r--r-- | include/datetime/engine-mock.h | 68 | ||||
-rw-r--r-- | include/datetime/engine.h | 68 | ||||
-rw-r--r-- | include/datetime/planner-month.h | 56 | ||||
-rw-r--r-- | include/datetime/planner-range.h | 84 | ||||
-rw-r--r-- | include/datetime/planner-upcoming.h | 56 | ||||
-rw-r--r-- | include/datetime/planner.h | 29 | ||||
-rw-r--r-- | include/datetime/snap.h (renamed from include/datetime/planner-eds.h) | 28 | ||||
-rw-r--r-- | include/datetime/state.h | 14 | ||||
-rw-r--r-- | include/datetime/timezone-file.h | 4 |
14 files changed, 521 insertions, 46 deletions
diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 3607836..a24b844 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -42,6 +42,7 @@ public: void open_desktop_settings(); void open_phone_settings(); void open_phone_clock_app(); + bool can_open_planner() const; void open_planner(); void open_planner_at(const DateTime&); void open_appointment(const std::string& uid); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 99e78f5..2c4217c 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -45,6 +45,7 @@ public: virtual void open_desktop_settings() =0; virtual void open_phone_settings() =0; virtual void open_phone_clock_app() =0; + virtual bool can_open_planner() const = 0; virtual void open_planner() =0; virtual void open_planner_at(const DateTime&) =0; virtual void open_appointment(const std::string& uid) =0; diff --git a/include/datetime/clock-watcher.h b/include/datetime/clock-watcher.h new file mode 100644 index 0000000..90bbb63 --- /dev/null +++ b/include/datetime/clock-watcher.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_CLOCK_WATCHER_H +#define INDICATOR_DATETIME_CLOCK_WATCHER_H + +#include <datetime/appointment.h> +#include <datetime/clock.h> +#include <datetime/planner-upcoming.h> + +#include <core/signal.h> + +#include <memory> +#include <set> +#include <string> + +namespace unity { +namespace indicator { +namespace datetime { + + +/** + * \brief Watches the clock and appointments to notify when an + * appointment's time is reached. + */ +class ClockWatcher +{ +public: + ClockWatcher() =default; + virtual ~ClockWatcher() =default; + virtual core::Signal<const Appointment&>& alarm_reached() = 0; +}; + + +/** + * \brief A #ClockWatcher implementation + */ +class ClockWatcherImpl: public ClockWatcher +{ +public: + 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; + const std::shared_ptr<Clock> m_clock; + const std::shared_ptr<UpcomingPlanner> m_upcoming_planner; + core::Signal<const Appointment&> m_alarm_reached; +}; + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_WATCHER_H diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 2ad7856..f861c2e 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -36,21 +36,29 @@ 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); 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; 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; 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/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-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..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/planner-eds.h b/include/datetime/snap.h index f3abce0..a493772 100644 --- a/include/datetime/planner-eds.h +++ b/include/datetime/snap.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,33 +17,35 @@ * Charles Kerr <charles.kerr@canonical.com> */ -#ifndef INDICATOR_DATETIME_PLANNER_EDS_H -#define INDICATOR_DATETIME_PLANNER_EDS_H +#ifndef INDICATOR_DATETIME_SNAP_H +#define INDICATOR_DATETIME_SNAP_H -#include <datetime/planner.h> +#include <datetime/appointment.h> -#include <memory> // unique_ptr +#include <memory> +#include <functional> namespace unity { namespace indicator { namespace datetime { /** - * \brief Planner which uses EDS as its backend + * \brief Pops up Snap Decisions for appointments */ -class PlannerEds: public Planner +class Snap { public: - PlannerEds(); - virtual ~PlannerEds(); + Snap(); + virtual ~Snap(); -private: - class Impl; - std::unique_ptr<Impl> p; + typedef std::function<void(const Appointment&)> appointment_func; + void operator()(const Appointment& appointment, + appointment_func show, + appointment_func dismiss); }; } // namespace datetime } // namespace indicator } // namespace unity -#endif // INDICATOR_DATETIME_PLANNER_EDS_H +#endif // INDICATOR_DATETIME_SNAP_H 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; diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index d77aaae..a67c01a 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -42,8 +42,8 @@ public: ~FileTimezone(); private: - void setFilename(const std::string& filename); - static void onFileChanged(gpointer gself); + void set_filename(const std::string& filename); + static void on_file_changed(gpointer gself); void clear(); void reload(); |