aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/datetime/actions-live.h57
-rw-r--r--include/datetime/actions.h70
-rw-r--r--include/datetime/appointment.h4
-rw-r--r--include/datetime/clock-mock.h28
-rw-r--r--include/datetime/clock.h25
-rw-r--r--include/datetime/date-time.h103
-rw-r--r--include/datetime/dbus-shared.h37
-rw-r--r--include/datetime/formatter.h29
-rw-r--r--include/datetime/locations-settings.h11
-rw-r--r--include/datetime/locations.h38
-rw-r--r--include/datetime/menu.h82
-rw-r--r--include/datetime/planner-eds.h2
-rw-r--r--include/datetime/planner-mock.h44
-rw-r--r--include/datetime/planner.h3
-rw-r--r--include/datetime/service.h72
-rw-r--r--include/datetime/settings-live.h57
-rw-r--r--include/datetime/settings-shared.h6
-rw-r--r--include/datetime/settings.h63
-rw-r--r--include/datetime/state.h68
-rw-r--r--include/datetime/timezone-file.h13
-rw-r--r--include/datetime/timezone-geoclue.h12
-rw-r--r--include/datetime/timezone.h4
-rw-r--r--include/datetime/timezones-live.h13
-rw-r--r--include/datetime/timezones.h4
-rw-r--r--include/datetime/utils.h28
25 files changed, 732 insertions, 141 deletions
diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h
new file mode 100644
index 0000000..2059a4d
--- /dev/null
+++ b/include/datetime/actions-live.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 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_ACTIONS_LIVE_H
+#define INDICATOR_DATETIME_ACTIONS_LIVE_H
+
+#include <datetime/actions.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief Production implentation of the Actions interface.
+ *
+ * Delegates URLs, sets the timezone via org.freedesktop.timedate1, etc.
+ *
+ * @see MockActions
+ */
+class LiveActions: public Actions
+{
+public:
+ LiveActions(std::shared_ptr<State>& state): Actions(state) {}
+ ~LiveActions() =default;
+
+ void open_desktop_settings();
+ void open_phone_settings();
+ void open_phone_clock();
+ void open_phone_planner();
+ void open_planner_at(const DateTime&);
+ void open_calendar_at(const DateTime&);
+ void open_appointment(const std::string& uid);
+ void set_location(const std::string& zone, const std::string& name);
+ void set_calendar_date(const DateTime&);
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ACTIONS_H
diff --git a/include/datetime/actions.h b/include/datetime/actions.h
new file mode 100644
index 0000000..ed45c3c
--- /dev/null
+++ b/include/datetime/actions.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2013 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_ACTIONS_H
+#define INDICATOR_DATETIME_ACTIONS_H
+
+#include <datetime/date-time.h>
+#include <datetime/state.h>
+
+#include <memory> // shared_ptr
+#include <string>
+
+#include <gio/gio.h> // GSimpleActionGroup
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * Interface for all the actions that can be activated by users via the menu.
+ */
+class Actions
+{
+public:
+ virtual void open_desktop_settings() =0;
+ virtual void open_phone_settings() =0;
+ virtual void open_phone_clock_app() =0;
+ virtual void open_planner() =0;
+ virtual void open_planner_at(const DateTime&) =0;
+ virtual void open_appointment(const std::string& uid) =0;
+ virtual void set_location(const std::string& zone, const std::string& name)=0;
+ virtual void set_calendar_date(const DateTime&) =0;
+
+ GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); }
+ std::shared_ptr<State> state() { return m_state; }
+
+protected:
+ Actions(std::shared_ptr<State>& state);
+ virtual ~Actions();
+
+private:
+ std::shared_ptr<State> m_state;
+ GSimpleActionGroup* m_actions = nullptr;
+
+ // we've got raw pointers in here, so disable copying
+ Actions(const Actions&) =delete;
+ Actions& operator=(const Actions&) =delete;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_ACTIONS_H
diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h
index 098b0d0..e034c08 100644
--- a/include/datetime/appointment.h
+++ b/include/datetime/appointment.h
@@ -28,7 +28,9 @@ namespace indicator {
namespace datetime {
/**
- * PODS representing a calendar appointment
+ * \brief Plain Old Data Structure that represents a calendar appointment.
+ *
+ * @see Planner
*/
struct Appointment
{
diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h
index 814b29a..19a859b 100644
--- a/include/datetime/clock-mock.h
+++ b/include/datetime/clock-mock.h
@@ -30,30 +30,28 @@ namespace datetime {
****
***/
+/**
+ * \brief A clock that uses a client-provided time instead of the system time.
+ */
class MockClock: public Clock
{
public:
+ MockClock(const DateTime& dt): m_localtime(dt) {}
+ ~MockClock() =default;
- MockClock(GDateTime * dt) { setLocaltime(dt); }
-
- ~MockClock() {
- g_clear_pointer(&localtime_, g_date_time_unref);
- }
-
- GDateTime* localtime() const {
- g_assert (localtime_ != nullptr);
- return g_date_time_ref(localtime_);
- }
+ DateTime localtime() const { return m_localtime; }
- void setLocaltime(GDateTime* dt) {
- g_clear_pointer(&localtime_, g_date_time_unref);
- localtime_ = g_date_time_ref(dt);
+ void set_localtime(const DateTime& dt) {
+ const auto old_day = m_localtime.day_of_year();
+ m_localtime = dt;
skewDetected();
+ const auto new_day = m_localtime.day_of_year();
+ if (old_day != new_day)
+ dateChanged();
}
private:
-
- GDateTime * localtime_ = nullptr;
+ DateTime m_localtime;
};
} // namespace datetime
diff --git a/include/datetime/clock.h b/include/datetime/clock.h
index 978be27..c8e6c16 100644
--- a/include/datetime/clock.h
+++ b/include/datetime/clock.h
@@ -20,12 +20,12 @@
#ifndef INDICATOR_DATETIME_CLOCK_H
#define INDICATOR_DATETIME_CLOCK_H
+#include <datetime/date-time.h>
#include <datetime/timezones.h>
#include <core/property.h>
#include <core/signal.h>
-#include <glib.h>
#include <gio/gio.h>
#include <set>
@@ -45,9 +45,10 @@ class Clock
{
public:
virtual ~Clock();
- virtual GDateTime* localtime() const = 0;
- core::Property<std::set<std::string> > timezones;
+ virtual DateTime localtime() const =0;
+ core::Property<std::set<std::string>> timezones;
core::Signal<> skewDetected;
+ core::Signal<> dateChanged;
protected:
Clock();
@@ -56,12 +57,13 @@ private:
static void onSystemBusReady(GObject*, GAsyncResult*, gpointer);
static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer);
+ GCancellable * m_cancellable = nullptr;
+ GDBusConnection * m_system_bus = nullptr;
+ unsigned int m_sleep_subscription_id = 0;
+
+ // we've got raw pointers in here, so disable copying
Clock(const Clock&) =delete;
Clock& operator=(const Clock&) =delete;
-
- GCancellable * cancellable_ = nullptr;
- GDBusConnection * system_bus_ = nullptr;
- unsigned int sleep_subscription_id_ = 0;
};
/***
@@ -71,16 +73,17 @@ private:
/**
* \brief A live clock that provides the actual system time.
*
- * Adds another clock skew detection test: wakes up every
- * skewTestIntervalSec seconds to see how much time has passed
- * since the last time it checked.
+ * This subclass also adds another clock skew detection test:
+ * it wakes up every skewTestIntervalSec seconds to see how
+ * much time has passed since the last wakeup. If the answer
+ * isn't what it expected, the skewDetected signal is triggered.
*/
class LiveClock: public Clock
{
public:
LiveClock (const std::shared_ptr<Timezones>& zones);
virtual ~LiveClock();
- virtual GDateTime* localtime() const;
+ virtual DateTime localtime() const;
core::Property<unsigned int> skewTestIntervalSec;
private:
diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h
index bbcd00a..5b9421f 100644
--- a/include/datetime/date-time.h
+++ b/include/datetime/date-time.h
@@ -22,6 +22,7 @@
#include <glib.h> // GDateTime
+#include <ctime> // time_t
#include <memory> // std::shared_ptr
namespace unity {
@@ -29,61 +30,111 @@ namespace indicator {
namespace datetime {
/**
- * C++ wrapper class for GDateTime
+ * \brief A simple C++ wrapper for GDateTime to simplify ownership/refcounts
*/
class DateTime
{
public:
- GDateTime* get() const
- {
- return dt_.get();
+ explicit DateTime(GDateTime* in=nullptr) { reset(in); }
+
+ explicit DateTime(time_t t) { reset(g_date_time_new_from_unix_local(t)); }
+
+ static DateTime NowLocal() {
+ GDateTime * gdt = g_date_time_new_now_local();
+ DateTime dt(gdt);
+ g_date_time_unref(gdt);
+ return dt;
+ }
+
+ DateTime to_timezone(const std::string& zone) const {
+ auto gtz = g_time_zone_new(zone.c_str());
+ auto gdt = g_date_time_to_timezone(get(), gtz);
+ DateTime dt(gdt);
+ g_time_zone_unref(gtz);
+ g_date_time_unref(gdt);
+ return dt;
}
- GDateTime* operator()() const
- {
+
+ GDateTime* get() const {
+ g_assert(m_dt);
+ return m_dt.get();
+ }
+
+ GDateTime* operator()() const {
return get();
}
- void set (GDateTime* in) {
- auto deleter = [](GDateTime* dt){g_date_time_unref(dt);};
- dt_ = std::shared_ptr<GDateTime>(g_date_time_ref(in), deleter);
+
+ std::string format(const std::string& fmt) const {
+ auto str = g_date_time_format(get(), fmt.c_str());
+ std::string ret = str;
+ g_free(str);
+ return ret;
+ }
+
+ int day_of_month() const { return g_date_time_get_day_of_month(get()); }
+
+ int64_t to_unix() const { return g_date_time_to_unix(get()); }
+
+ int day_of_year() const { return m_dt ? g_date_time_get_day_of_year(get()) : -1; }
+
+ void reset(GDateTime* in=nullptr) {
+ if (in) {
+ auto deleter = [](GDateTime* dt){g_date_time_unref(dt);};
+ m_dt = std::shared_ptr<GDateTime>(g_date_time_ref(in), deleter);
+ g_assert(m_dt);
+ } else {
+ m_dt.reset();
+ }
}
- DateTime& operator=(GDateTime* in)
- {
- set (in);
+ DateTime& operator=(GDateTime* in) {
+ reset(in);
return *this;
}
- DateTime& operator=(const DateTime& in)
- {
- set (in.get());
+ DateTime& operator=(const DateTime& in) {
+ m_dt = in.m_dt;
return *this;
}
- bool operator<(const DateTime& that) const
- {
- return g_date_time_compare (get(), that.get()) < 0;
+ gint64 difference(const DateTime& that) const {
+ const auto dt = get();
+ const auto tdt = that.get();
+
+ gint64 ret;
+ if (dt && tdt)
+ ret = g_date_time_difference(dt, tdt);
+ else if (dt)
+ ret = to_unix();
+ else if (tdt)
+ ret = that.to_unix();
+ else
+ ret = 0;
+ return ret;
+ }
+
+ bool operator<(const DateTime& that) const {
+ return g_date_time_compare(get(), that.get()) < 0;
}
- bool operator!=(const DateTime& that) const
- {
- return !(*this == that);
+ bool operator!=(const DateTime& that) const {
+ // return true if this isn't set, or if it's not equal
+ return (!m_dt) || !(*this == that);
}
- bool operator==(const DateTime& that) const
- {
+ bool operator==(const DateTime& that) const {
GDateTime * dt = get();
GDateTime * tdt = that.get();
if (!dt && !tdt) return true;
if (!dt || !tdt) return false;
- return g_date_time_compare (get(), that.get()) == 0;
+ return g_date_time_compare(get(), that.get()) == 0;
}
private:
-
- std::shared_ptr<GDateTime> dt_;
+ std::shared_ptr<GDateTime> m_dt;
};
} // namespace datetime
diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h
index 24319e3..c5ff6ab 100644
--- a/include/datetime/dbus-shared.h
+++ b/include/datetime/dbus-shared.h
@@ -1,24 +1,25 @@
/*
-An indicator to show date and time information.
+ * Copyright 2013 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:
+ * Ted Gould <ted@canonical.com>
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
-Copyright 2010 Canonical Ltd.
-
-Authors:
- Ted Gould <ted@canonical.com>
-
-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/>.
-*/
#define BUS_NAME "com.canonical.indicator.datetime"
+
#define BUS_PATH "/com/canonical/indicator/datetime"
diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h
index 66dc212..09ed035 100644
--- a/include/datetime/formatter.h
+++ b/include/datetime/formatter.h
@@ -37,7 +37,26 @@ class DateTime;
***/
/**
- * \brief Provides the right time format strings based on the profile and user's settings
+ * \brief Provide the strftime() format strings
+ *
+ * This mission's been moved out into its own class because there are
+ * a lot of options and edge cases:
+ *
+ * - The default time format can change based on the locale.
+ *
+ * - The user's settings can change or completely override the format string.
+ *
+ * - The time formats are different on the Phone and Desktop profiles.
+ *
+ * - The time format string in the Locations' menuitems uses (mostly)
+ * the same time format as the header, except for some changes.
+ *
+ * - The 'current time' format string in the Locations' menuitems also
+ * prepends the string 'Yesterday' or 'Today' if it differs from the
+ * local time, so Formatter needs to have a Clock for its state.
+ *
+ * So the Formatter monitors system settings, the current timezone, etc.
+ * and upate its time format properties appropriately.
*/
class Formatter
{
@@ -51,7 +70,8 @@ public:
/** \brief Signal to denote when the relativeFormat has changed.
When this is emitted, clients will want to rebuild their
- menuitems that contain relative time strings */
+ menuitems that contain relative time strings
+ (ie, the Appointments and Locations menuitems) */
core::Signal<> relativeFormatChanged;
/** \brief Generate a relative time format for some time (or time range)
@@ -60,19 +80,18 @@ public:
std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const;
protected:
-
Formatter(const std::shared_ptr<Clock>&);
virtual ~Formatter();
/** \brief Returns true if the current locale prefers 12h display instead of 24h */
static bool is_locale_12h();
- static const char * getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds);
+ static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds);
/** \brief Translate the string based on LC_TIME instead of LC_MESSAGES.
The intent of this is to let users set LC_TIME to override
their other locale settings when generating time format string */
- static const char * T_(const char * fmt);
+ static const char* T_(const char * fmt);
private:
diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h
index d343fe3..eaabf73 100644
--- a/include/datetime/locations-settings.h
+++ b/include/datetime/locations-settings.h
@@ -32,8 +32,8 @@ namespace datetime {
class Timezones;
/**
- * \brief An ordered list of Location objects found from
- * the system timezone and from the user's GSettings
+ * \brief Settings implentation which builds its list from the
+ * user's GSettings and from the Timezones passed in the ctor.
*/
class SettingsLocations: public Locations
{
@@ -42,11 +42,12 @@ public:
* @param[in] schemaId the settings schema to load
* @param[in] timezones the timezones to always show first in the list
*/
- SettingsLocations (const std::string& schemaId, const std::shared_ptr<Timezones>& timezones);
+ SettingsLocations (const std::string& schemaId,
+ const std::shared_ptr<Timezones>& timezones);
protected:
- std::unique_ptr<GSettings,std::function<void(GSettings*)>> settings_;
- std::shared_ptr<Timezones> timezones_;
+ std::unique_ptr<GSettings,std::function<void(GSettings*)>> m_settings;
+ std::shared_ptr<Timezones> m_timezones;
private:
static void onSettingsChanged (gpointer gself);
diff --git a/include/datetime/locations.h b/include/datetime/locations.h
index a06d1cc..ee67615 100644
--- a/include/datetime/locations.h
+++ b/include/datetime/locations.h
@@ -20,6 +20,8 @@
#ifndef INDICATOR_DATETIME_LOCATIONS_H
#define INDICATOR_DATETIME_LOCATIONS_H
+#include <datetime/date-time.h>
+
#include <core/property.h>
#include <string>
@@ -31,28 +33,42 @@ namespace datetime {
/**
* \brief A physical place and its timezone; eg, "America/Chicago" + "Oklahoma City"
+ *
+ * @see Locations
*/
-struct Location
+class Location
{
- /** timezone; eg, "America/Chicago" */
- std::string zone;
-
- /* human-readable location name; eg, "Oklahoma City" */
- std::string name;
+public:
+ const std::string& zone() const { return m_zone; }
- /** offset from UTC in microseconds */
- int64_t offset = 0;
+ const std::string& name() const { return m_name; }
bool operator== (const Location& that) const
{
- return (name == that.name) && (zone == that.zone) && (offset == that.offset);
+ return (name() == that.name()) &&
+ (zone() == that.zone()) &&
+ (m_offset == that.m_offset);
}
Location (const std::string& zone, const std::string& name);
+
+private:
+
+ /** timezone; eg, "America/Chicago" */
+ std::string m_zone;
+
+ /* human-readable location name; eg, "Oklahoma City" */
+ std::string m_name;
+
+ /** offset from UTC in microseconds */
+ int64_t m_offset = 0;
};
/**
- * A container for an ordered list of Locations.
+ * Container which holds an ordered list of Locations
+ *
+ * @see Location
+ * @see State
*/
class Locations
{
@@ -61,7 +77,7 @@ public:
virtual ~Locations() =default;
/** \brief an ordered list of Location items */
- core::Property<std::vector<Location> > locations;
+ core::Property<std::vector<Location>> locations;
};
} // namespace datetime
diff --git a/include/datetime/menu.h b/include/datetime/menu.h
new file mode 100644
index 0000000..0bc3781
--- /dev/null
+++ b/include/datetime/menu.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2013 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_MENU_H
+#define INDICATOR_DATETIME_MENU_H
+
+#include <datetime/actions.h>
+#include <datetime/state.h>
+
+#include <memory> // std::shared_ptr
+#include <vector>
+
+#include <gio/gio.h> // GMenuModel
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief A menu for a specific profile; eg, Desktop or Phone.
+ *
+ * @see MenuFactory
+ */
+class Menu
+{
+public:
+ enum Profile { Desktop, DesktopGreeter, Phone, PhoneGreeter, NUM_PROFILES };
+ enum Section { Calendar, Appointments, Locations, Settings, NUM_SECTIONS };
+ const std::string& name() const { return m_name; }
+ Profile profile() const { return m_profile; }
+ GMenuModel* menu_model() { return G_MENU_MODEL(m_menu); }
+
+protected:
+ Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {}
+ virtual ~Menu() =default;
+ GMenu* m_menu = nullptr;
+
+private:
+ const Profile m_profile;
+ const std::string m_name;
+
+ // we've got raw pointers in here, so disable copying
+ Menu(const Menu&) =delete;
+ Menu& operator=(const Menu&) =delete;
+};
+
+/**
+ * \brief Builds a Menu for a given state and profile
+ */
+class MenuFactory
+{
+public:
+ MenuFactory (std::shared_ptr<Actions>& actions, std::shared_ptr<State>& state);
+ std::shared_ptr<Menu> buildMenu(Menu::Profile profile);
+ std::shared_ptr<State> state() { return m_state; }
+
+private:
+ std::shared_ptr<Actions> m_actions;
+ std::shared_ptr<State> m_state;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_MENU_H
diff --git a/include/datetime/planner-eds.h b/include/datetime/planner-eds.h
index 43f222e..f3abce0 100644
--- a/include/datetime/planner-eds.h
+++ b/include/datetime/planner-eds.h
@@ -39,7 +39,7 @@ public:
private:
class Impl;
- std::unique_ptr<Impl> impl_;
+ std::unique_ptr<Impl> p;
};
} // namespace datetime
diff --git a/include/datetime/planner-mock.h b/include/datetime/planner-mock.h
new file mode 100644
index 0000000..bb3ff53
--- /dev/null
+++ b/include/datetime/planner-mock.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013 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_MOCK_H
+#define INDICATOR_DATETIME_PLANNER_MOCK_H
+
+#include <datetime/planner.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief Planner which does nothing on its own and requires
+ * its client to set its appointments property.
+ */
+class MockPlanner: public Planner
+{
+public:
+ MockPlanner() =default;
+ virtual ~MockPlanner() =default;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_PLANNER_MOCK_H
diff --git a/include/datetime/planner.h b/include/datetime/planner.h
index 4d27a2b..198b6fa 100644
--- a/include/datetime/planner.h
+++ b/include/datetime/planner.h
@@ -33,6 +33,9 @@ namespace datetime {
/**
* \brief Simple appointment book
+ *
+ * @see EdsPlanner
+ * @see State
*/
class Planner
{
diff --git a/include/datetime/service.h b/include/datetime/service.h
new file mode 100644
index 0000000..c7171b7
--- /dev/null
+++ b/include/datetime/service.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2013 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_EXPORTER_H
+#define INDICATOR_DATETIME_EXPORTER_H
+
+#include <datetime/menu.h>
+
+#include <core/signal.h>
+
+#include <gio/gio.h> // GActionGroup
+
+#include <memory> // std::shared_ptr
+#include <vector>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief Exports actions and menus to DBus.
+ */
+class Service
+{
+public:
+ Service() =default;
+ ~Service();
+
+ core::Signal<> name_lost;
+
+ void publish (GActionGroup* actions, std::vector<std::shared_ptr<Menu>>& menus);
+
+private:
+ static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis);
+ void on_bus_acquired(GDBusConnection*, const gchar *name);
+
+ static void on_name_lost(GDBusConnection*, const gchar *name, gpointer gthis);
+ void on_name_lost(GDBusConnection*, const gchar *name);
+
+ std::set<guint> m_exported_menu_ids;
+ guint m_own_id = 0;
+ guint m_exported_actions_id = 0;
+ GDBusConnection * m_dbus_connection = nullptr;
+ GActionGroup* m_actions = nullptr;
+ std::vector<std::shared_ptr<Menu>> m_menus;
+
+ // we've got raw pointers and gsignal tags in here, so disable copying
+ Service(const Service&) =delete;
+ Service& operator=(const Service&) =delete;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_EXPORTER_H
diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h
new file mode 100644
index 0000000..44e27b0
--- /dev/null
+++ b/include/datetime/settings-live.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2013 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_SETTINGS_LIVE_H
+#define INDICATOR_DATETIME_SETTINGS_LIVE_H
+
+#include <datetime/settings.h> // parent class
+
+#include <gio/gio.h> // GSettings
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief #Settings implementation which uses GSettings.
+ */
+class LiveSettings: public Settings
+{
+public:
+ LiveSettings();
+ virtual ~LiveSettings();
+
+private:
+ void update_show_clock();
+
+ void update_key(const std::string& key);
+ static void on_changed(GSettings*, gchar*, gpointer);
+
+ GSettings* m_settings;
+
+ // we've got a raw pointer here, so disable copying
+ LiveSettings(const LiveSettings&) =delete;
+ LiveSettings& operator=(const LiveSettings&) =delete;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H
diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h
index 896db95..17a8ef0 100644
--- a/include/datetime/settings-shared.h
+++ b/include/datetime/settings-shared.h
@@ -18,8 +18,8 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#ifndef __DATETIME_SETTINGS_SHARED_H__
-#define __DATETIME_SETTINGS_SHARED_H__
+#ifndef INDICATOR_DATETIME_SETTINGS_SHARED
+#define INDICATOR_DATETIME_SETTINGS_SHARED
typedef enum
{
@@ -46,4 +46,4 @@ TimeFormatMode;
#define SETTINGS_LOCATIONS_S "locations"
#define SETTINGS_TIMEZONE_NAME_S "timezone-name"
-#endif /* __DATETIME_SETTINGS_SHARED_H__ */
+#endif // INDICATOR_DATETIME_SETTINGS_SHARED
diff --git a/include/datetime/settings.h b/include/datetime/settings.h
new file mode 100644
index 0000000..3d4bc33
--- /dev/null
+++ b/include/datetime/settings.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2013 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_SETTINGS_H
+#define INDICATOR_DATETIME_SETTINGS_H
+
+#include <datetime/settings-shared.h>
+
+#include <core/property.h>
+
+#include <vector>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief Interface that represents user-configurable settings.
+ *
+ * See the descriptions in data/com.canonical.indicator.datetime.gschema.xml
+ * For more information.
+ */
+class Settings
+{
+public:
+ Settings() =default;
+ virtual ~Settings() =default;
+
+ core::Property<TimeFormatMode> time_format_mode;
+ core::Property<bool> show_clock;
+ core::Property<bool> show_day;
+ core::Property<bool> show_year;
+ core::Property<bool> show_seconds;
+ core::Property<std::string> custom_time_format;
+ core::Property<bool> show_calendar;
+ core::Property<bool> show_events;
+ core::Property<bool> show_locations;
+ core::Property<bool> show_auto_detected_location;
+ core::Property<std::vector<std::string>> locations;
+ core::Property<std::string> timezone_name;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_SETTINGS_H
diff --git a/include/datetime/state.h b/include/datetime/state.h
new file mode 100644
index 0000000..a82bb4b
--- /dev/null
+++ b/include/datetime/state.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2013 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_STATE_H
+#define INDICATOR_DATETIME_STATE_H
+
+#include <datetime/clock.h>
+#include <datetime/timezones.h>
+#include <datetime/planner.h>
+#include <datetime/locations.h>
+
+#include <core/property.h>
+
+#include <memory> // std::shared_ptr
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+/**
+ * \brief Aggregates all the classes that represent the backend state.
+ *
+ * This is where the app comes together. It's a model that aggregates
+ * all of the backend appointments/alarms, locations, timezones,
+ * system time, and so on. The "view" code (ie, the Menus) need to
+ * respond to Signals from the State and update themselves accordingly.
+ *
+ * @see Menu
+ * @see MenuFactory
+ * @see Timezones
+ * @see Clock
+ * @see Planner
+ * @see Locations
+ */
+struct State
+{
+ std::shared_ptr<Timezones> timezones;
+ std::shared_ptr<Clock> clock;
+ std::shared_ptr<Planner> planner;
+ std::shared_ptr<Locations> locations;
+
+ core::Property<bool> show_events;
+ core::Property<bool> show_clock;
+ core::Property<DateTime> calendar_day;
+ core::Property<bool> show_week_numbers;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_STATE_H
diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h
index 39a3d83..7f47df6 100644
--- a/include/datetime/timezone-file.h
+++ b/include/datetime/timezone-file.h
@@ -43,15 +43,18 @@ public:
private:
void setFilename(const std::string& filename);
- void clear();
static void onFileChanged(gpointer gself);
+ void clear();
void reload();
- std::string filename_;
- GFileMonitor * monitor_ = nullptr;
- unsigned long monitor_handler_id_ = 0;
-};
+ std::string m_filename;
+ GFileMonitor * m_monitor = nullptr;
+ unsigned long m_monitor_handler_id = 0;
+ // we have raw pointers and glib tags in here, so disable copying
+ FileTimezone(const FileTimezone&) =delete;
+ FileTimezone& operator=(const FileTimezone&) =delete;
+};
} // namespace datetime
} // namespace indicator
diff --git a/include/datetime/timezone-geoclue.h b/include/datetime/timezone-geoclue.h
index 382b3cc..4a5b726 100644
--- a/include/datetime/timezone-geoclue.h
+++ b/include/datetime/timezone-geoclue.h
@@ -50,10 +50,14 @@ private:
void setTimezoneFromAddressVariant (GVariant*);
static GVariant * call_finish (GObject*, GAsyncResult*);
- GCancellable * cancellable_ = nullptr;
- GDBusConnection * connection_ = nullptr;
- std::string client_object_path_;
- guint signal_subscription_ = 0;
+ GCancellable * m_cancellable = nullptr;
+ GDBusConnection * m_connection = nullptr;
+ std::string m_client_object_path;
+ guint m_signal_subscription = 0;
+
+ // we've got pointers and gsignal tags in here, so don't allow copying
+ GeoclueTimezone(const GeoclueTimezone&) =delete;
+ GeoclueTimezone& operator=(const GeoclueTimezone&) =delete;
};
diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h
index 218e219..ffa5a84 100644
--- a/include/datetime/timezone.h
+++ b/include/datetime/timezone.h
@@ -28,11 +28,11 @@ namespace unity {
namespace indicator {
namespace datetime {
-/** \brief Base class for objects that use various means to detect the system's timezone */
+/** \brief Base a timezone, such as "America/Chicago". */
class Timezone
{
protected:
- Timezone() {}
+ Timezone() =default;
public:
//virtual ~Timezone() {}
diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h
index 3075bd8..5f2cb3e 100644
--- a/include/datetime/timezones-live.h
+++ b/include/datetime/timezones-live.h
@@ -31,7 +31,7 @@ namespace indicator {
namespace datetime {
/**
- * \brief Timezones object that uses a #FileTimezone and #GeoclueTimezone
+ * \brief #Timezones object that uses a #FileTimezone and #GeoclueTimezone
* to detect what timezone we're in
*/
class LiveTimezones: public Timezones
@@ -40,13 +40,14 @@ public:
LiveTimezones(const std::string& filename);
/** \brief Whether or not to track location by IP address */
- core::Property<bool> geolocationEnabled = core::Property<bool>(false);
+ core::Property<bool> geolocation_enabled = core::Property<bool>(false);
private:
- FileTimezone file_;
- std::shared_ptr<GeoclueTimezone> geo_;
- void updateGeolocation();
- void updateTimezones();
+ void update_geolocation();
+ void update_timezones();
+
+ FileTimezone m_file;
+ std::shared_ptr<GeoclueTimezone> m_geo;
};
} // namespace datetime
diff --git a/include/datetime/timezones.h b/include/datetime/timezones.h
index 0b97683..10c4e97 100644
--- a/include/datetime/timezones.h
+++ b/include/datetime/timezones.h
@@ -28,13 +28,11 @@ namespace unity {
namespace indicator {
namespace datetime {
-/** \brief Aggregates one or more timezone detectors and decides which to use */
+/** \brief Aggregates one or more timezone detectors and decides which to give precedence to */
class Timezones
{
public:
-
Timezones() =default;
-
virtual ~Timezones() =default;
/**
diff --git a/include/datetime/utils.h b/include/datetime/utils.h
index bd2e132..fbc80d7 100644
--- a/include/datetime/utils.h
+++ b/include/datetime/utils.h
@@ -20,8 +20,8 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __DATETIME_UTILS_H__
-#define __DATETIME_UTILS_H__
+#ifndef INDICATOR_DATETIME_UTILS_H
+#define INDICATOR_DATETIME_UTILS_H
#include <glib.h>
#include <gio/gio.h> /* GSettings */
@@ -37,31 +37,9 @@ void split_settings_location (const char * location,
gchar * get_current_zone_name (const char * location,
GSettings * settings);
-#if 0
-gchar* join_date_and_time_format_strings (const char * date_fmt,
- const char * time_fmt);
-/***
-****
-***/
-
-const gchar * get_terse_time_format_string (GDateTime * time);
-
-const gchar * get_terse_header_time_format_string (void);
-
-const gchar * get_full_time_format_string (GSettings * settings);
-
-gchar * generate_terse_format_string_at_time (GDateTime * now,
- GDateTime * time);
-
-gchar * generate_full_format_string (gboolean show_day,
- gboolean show_date,
- gboolean show_year,
- GSettings * settings);
-#endif
-
gchar * generate_full_format_string_at_time (GDateTime * now,
GDateTime * time);
G_END_DECLS
-#endif
+#endif /* INDICATOR_DATETIME_UTILS_H */