aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/datetime/engine-eds.h4
-rw-r--r--include/datetime/engine-mock.h68
-rw-r--r--include/datetime/engine.h (renamed from include/datetime/planner-eds.h)49
-rw-r--r--include/datetime/planner-range.h36
4 files changed, 129 insertions, 28 deletions
diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h
index e269167..4b260a8 100644
--- a/include/datetime/engine-eds.h
+++ b/include/datetime/engine-eds.h
@@ -20,6 +20,8 @@
#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>
@@ -40,7 +42,7 @@ namespace datetime {
*
* @see EdsPlanner
*/
-class EdsEngine
+class EdsEngine: public Engine
{
public:
EdsEngine();
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/planner-eds.h b/include/datetime/engine.h
index 95b5d79..2e8237e 100644
--- a/include/datetime/planner-eds.h
+++ b/include/datetime/engine.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,43 +17,52 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#ifndef INDICATOR_DATETIME_PLANNER_EDS_H
-#define INDICATOR_DATETIME_PLANNER_EDS_H
+#ifndef INDICATOR_DATETIME_ENGINE__H
+#define INDICATOR_DATETIME_ENGINE__H
-#include <datetime/planner-range.h>
-
-#include <datetime/engine-eds.h>
+#include <datetime/appointment.h>
+#include <datetime/date-time.h>
#include <datetime/timezone.h>
-#include <memory> // shared_ptr, unique_ptr
+#include <functional>
+#include <vector>
namespace unity {
namespace indicator {
namespace datetime {
+/****
+*****
+****/
+
/**
- * \brief An EDS-based #RangePlanner
+ * Class wrapper around the backend that generates appointments
+ *
+ * @see EdsEngine
+ * @see EdsPlanner
*/
-class EdsPlanner: public RangePlanner
+class Engine
{
public:
- EdsPlanner(const std::shared_ptr<EdsEngine>& eds_engine,
- const std::shared_ptr<Timezone>& timezone);
- virtual ~EdsPlanner();
+ virtual ~Engine() =default;
- core::Property<std::vector<Appointment>>& appointments();
+ virtual void get_appointments(const DateTime& begin,
+ const DateTime& end,
+ const Timezone& default_timezone,
+ std::function<void(const std::vector<Appointment>&)> appointment_func) =0;
-protected:
- void rebuild_now();
+ virtual core::Signal<>& changed() =0;
-private:
- std::shared_ptr<EdsEngine> m_engine;
- std::shared_ptr<Timezone> m_timezone;
- core::Property<std::vector<Appointment>> m_appointments;
+protected:
+ Engine() =default;
};
+/***
+****
+***/
+
} // namespace datetime
} // namespace indicator
} // namespace unity
-#endif // INDICATOR_DATETIME_PLANNER_EDS_H
+#endif // INDICATOR_DATETIME_ENGINE__H
diff --git a/include/datetime/planner-range.h b/include/datetime/planner-range.h
index 5306cdc..25334a6 100644
--- a/include/datetime/planner-range.h
+++ b/include/datetime/planner-range.h
@@ -23,6 +23,7 @@
#include <datetime/planner.h>
#include <datetime/date-time.h>
+#include <datetime/engine.h>
namespace unity {
namespace indicator {
@@ -36,25 +37,46 @@ namespace datetime {
class RangePlanner: public Planner
{
public:
- virtual ~RangePlanner();
- core::Property<std::pair<DateTime,DateTime>>& range();
+ virtual ~RangePlanner() =default;
+ virtual core::Property<std::pair<DateTime,DateTime>>& range() =0;
protected:
- RangePlanner();
+ RangePlanner() =default;
+};
- void rebuild_soon();
- virtual void rebuild_now() =0;
+/**
+ * \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
- RangePlanner(const RangePlanner&) =delete;
- RangePlanner& operator=(const RangePlanner&) =delete;
+ SimpleRangePlanner(const RangePlanner&) =delete;
+ SimpleRangePlanner& operator=(const RangePlanner&) =delete;
};
+
} // namespace datetime
} // namespace indicator
} // namespace unity