From 060bc69d8bdfe9860a71109ecf92810beb99f4da Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 21:59:43 -0600 Subject: add clock + tests --- include/datetime/clock-mock.h | 63 +++++++++++++++++++++++++++ include/datetime/clock.h | 99 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 include/datetime/clock-mock.h create mode 100644 include/datetime/clock.h (limited to 'include/datetime') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h new file mode 100644 index 0000000..814b29a --- /dev/null +++ b/include/datetime/clock-mock.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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_CLOCK_MOCK_H +#define INDICATOR_DATETIME_CLOCK_MOCK_H + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class MockClock: public Clock +{ +public: + + 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_); + } + + void setLocaltime(GDateTime* dt) { + g_clear_pointer(&localtime_, g_date_time_unref); + localtime_ = g_date_time_ref(dt); + skewDetected(); + } + +private: + + GDateTime * localtime_ = nullptr; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_MOCK_H diff --git a/include/datetime/clock.h b/include/datetime/clock.h new file mode 100644 index 0000000..978be27 --- /dev/null +++ b/include/datetime/clock.h @@ -0,0 +1,99 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_CLOCK_H +#define INDICATOR_DATETIME_CLOCK_H + +#include + +#include +#include + +#include +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A clock. + * + * Provides a signal to notify when clock skew is detected, such as + * when the timezone changes or when the system resumes from sleep. + */ +class Clock +{ +public: + virtual ~Clock(); + virtual GDateTime* localtime() const = 0; + core::Property > timezones; + core::Signal<> skewDetected; + +protected: + Clock(); + +private: + static void onSystemBusReady(GObject*, GAsyncResult*, gpointer); + static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); + + Clock(const Clock&) =delete; + Clock& operator=(const Clock&) =delete; + + GCancellable * cancellable_ = nullptr; + GDBusConnection * system_bus_ = nullptr; + unsigned int sleep_subscription_id_ = 0; +}; + +/*** +**** +***/ + +/** + * \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. + */ +class LiveClock: public Clock +{ +public: + LiveClock (const std::shared_ptr& zones); + virtual ~LiveClock(); + virtual GDateTime* localtime() const; + core::Property skewTestIntervalSec; + +private: + class Impl; + std::unique_ptr p; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_H -- cgit v1.2.3 From 36d8e8ee2d9f2b7967cef6c74c6f779263727eb9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:00:32 -0600 Subject: add timezone-file + tests --- include/datetime/timezone-file.h | 60 ++++++++++++++++++++++++++++++++++++++++ include/datetime/timezone.h | 46 ++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 include/datetime/timezone-file.h create mode 100644 include/datetime/timezone.h (limited to 'include/datetime') diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h new file mode 100644 index 0000000..39a3d83 --- /dev/null +++ b/include/datetime/timezone-file.h @@ -0,0 +1,60 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_FILE_TIMEZONE_H +#define INDICATOR_DATETIME_FILE_TIMEZONE_H + +#include // base class + +#include // std::string + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A #Timezone that gets its information from monitoring a file, such as /etc/timezone + */ +class FileTimezone: public Timezone +{ +public: + FileTimezone() {} + FileTimezone(const std::string& filename) { setFilename(filename); } + ~FileTimezone() {clear();} + +private: + void setFilename(const std::string& filename); + void clear(); + static void onFileChanged(gpointer gself); + void reload(); + + std::string filename_; + GFileMonitor * monitor_ = nullptr; + unsigned long monitor_handler_id_ = 0; +}; + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_FILE_TIMEZONE_H diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h new file mode 100644 index 0000000..218e219 --- /dev/null +++ b/include/datetime/timezone.h @@ -0,0 +1,46 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_TIMEZONE_H +#define INDICATOR_DATETIME_TIMEZONE_H + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** \brief Base class for objects that use various means to detect the system's timezone */ +class Timezone +{ +protected: + Timezone() {} + +public: + //virtual ~Timezone() {} + core::Property timezone; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_TIMEZONE_H -- cgit v1.2.3 From a1cb4d7802e6e024c842f2a4fa41b91b67162698 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:00:51 -0600 Subject: add timezone-geoclue + tests --- include/datetime/timezone-geoclue.h | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 include/datetime/timezone-geoclue.h (limited to 'include/datetime') diff --git a/include/datetime/timezone-geoclue.h b/include/datetime/timezone-geoclue.h new file mode 100644 index 0000000..382b3cc --- /dev/null +++ b/include/datetime/timezone-geoclue.h @@ -0,0 +1,65 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H +#define INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H + +#include // base class + +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A #Timezone that gets its information from asking GeoClue + */ +class GeoclueTimezone: public Timezone +{ +public: + GeoclueTimezone(); + ~GeoclueTimezone(); + +private: + static void on_bus_got (GObject*, GAsyncResult*, gpointer); + static void on_client_created (GObject*, GAsyncResult*, gpointer); + static void on_address_changed (GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); + static void on_requirements_set (GObject*, GAsyncResult*, gpointer); + static void on_address_started (GObject*, GAsyncResult*, gpointer); + static void on_address_got (GObject*, GAsyncResult*, gpointer); + void setTimezoneFromAddressVariant (GVariant*); + static GVariant * call_finish (GObject*, GAsyncResult*); + + GCancellable * cancellable_ = nullptr; + GDBusConnection * connection_ = nullptr; + std::string client_object_path_; + guint signal_subscription_ = 0; +}; + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H + -- cgit v1.2.3 From 172246c997d7b20d7e98fc25a7b23f4a79a0f6a6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:02:06 -0600 Subject: add formatter + tests --- include/datetime/formatter.h | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 include/datetime/formatter.h (limited to 'include/datetime') diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h new file mode 100644 index 0000000..66dc212 --- /dev/null +++ b/include/datetime/formatter.h @@ -0,0 +1,118 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_FORMATTER_H +#define INDICATOR_DATETIME_FORMATTER_H + +#include +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +class Clock; +class DateTime; + +/*** +**** +***/ + +/** + * \brief Provides the right time format strings based on the profile and user's settings + */ +class Formatter +{ +public: + + /** \brief The time format string for the menu header */ + core::Property headerFormat; + + /** \brief The time string for the menu header. (eg, the headerFormat + the clock's time */ + core::Property header; + + /** \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 */ + core::Signal<> relativeFormatChanged; + + /** \brief Generate a relative time format for some time (or time range) + from the current clock's value. For example, a full-day interval + starting at the end of the current clock's day yields "Tomorrow" */ + std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; + +protected: + + Formatter(const std::shared_ptr&); + 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); + + /** \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); + +private: + + Formatter(const Formatter&) =delete; + Formatter& operator=(const Formatter&) =delete; + + class Impl; + std::unique_ptr p; +}; + + +/** + * \brief A Formatter for the Desktop and DesktopGreeter profiles. + */ +class DesktopFormatter: public Formatter +{ +public: + DesktopFormatter(const std::shared_ptr&); + ~DesktopFormatter(); + +private: + class Impl; + friend Impl; + std::unique_ptr p; +}; + + +/** + * \brief A Formatter for Phone and PhoneGreeter profiles. + */ +class PhoneFormatter: public Formatter +{ +public: + PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { + headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); + } +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_H -- cgit v1.2.3 From 38b878589ffb08d2272169d2529703e887933be9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:03:12 -0600 Subject: add planner + tests --- include/datetime/planner-eds.h | 49 +++++++++++++++++++++++++++++ include/datetime/planner.h | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 include/datetime/planner-eds.h create mode 100644 include/datetime/planner.h (limited to 'include/datetime') diff --git a/include/datetime/planner-eds.h b/include/datetime/planner-eds.h new file mode 100644 index 0000000..43f222e --- /dev/null +++ b/include/datetime/planner-eds.h @@ -0,0 +1,49 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_EDS_H +#define INDICATOR_DATETIME_PLANNER_EDS_H + +#include + +#include // unique_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Planner which uses EDS as its backend + */ +class PlannerEds: public Planner +{ +public: + PlannerEds(); + virtual ~PlannerEds(); + +private: + class Impl; + std::unique_ptr impl_; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_PLANNER_EDS_H diff --git a/include/datetime/planner.h b/include/datetime/planner.h new file mode 100644 index 0000000..4d27a2b --- /dev/null +++ b/include/datetime/planner.h @@ -0,0 +1,71 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_H +#define INDICATOR_DATETIME_PLANNER_H + +#include +#include + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Simple appointment book + */ +class Planner +{ +public: + virtual ~Planner() =default; + + /** + * \brief Timestamp used to determine the appointments in the `upcoming' and `thisMonth' properties. + * Setting this value will cause the planner to re-query its backend and + * update the `upcoming' and `thisMonth' 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> thisMonth; + +protected: + Planner() =default; + +private: + Planner(const Planner&) =delete; + Planner& operator=(const Planner&) =delete; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_PLANNER_H -- cgit v1.2.3 From db7b874bbf1a98f85ffe511be230164c40fe080d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:03:43 -0600 Subject: add locations + tests --- include/datetime/locations-settings.h | 60 +++++++++++++++++++++++++++++ include/datetime/locations.h | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 include/datetime/locations-settings.h create mode 100644 include/datetime/locations.h (limited to 'include/datetime') diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h new file mode 100644 index 0000000..d343fe3 --- /dev/null +++ b/include/datetime/locations-settings.h @@ -0,0 +1,60 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_LOCATIONS_H +#define INDICATOR_DATETIME_SETTINGS_LOCATIONS_H + +#include // base class + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +class Timezones; + +/** + * \brief An ordered list of Location objects found from + * the system timezone and from the user's GSettings + */ +class SettingsLocations: public Locations +{ +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); + +protected: + std::unique_ptr> settings_; + std::shared_ptr timezones_; + +private: + static void onSettingsChanged (gpointer gself); + void reload(); +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_SETTINGS_LOCATIONS_H diff --git a/include/datetime/locations.h b/include/datetime/locations.h new file mode 100644 index 0000000..a06d1cc --- /dev/null +++ b/include/datetime/locations.h @@ -0,0 +1,71 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_LOCATIONS_H +#define INDICATOR_DATETIME_LOCATIONS_H + +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A physical place and its timezone; eg, "America/Chicago" + "Oklahoma City" + */ +struct Location +{ + /** timezone; eg, "America/Chicago" */ + std::string zone; + + /* human-readable location name; eg, "Oklahoma City" */ + std::string name; + + /** offset from UTC in microseconds */ + int64_t offset = 0; + + bool operator== (const Location& that) const + { + return (name == that.name) && (zone == that.zone) && (offset == that.offset); + } + + Location (const std::string& zone, const std::string& name); +}; + +/** + * A container for an ordered list of Locations. + */ +class Locations +{ +public: + Locations() =default; + virtual ~Locations() =default; + + /** \brief an ordered list of Location items */ + core::Property > locations; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_LOCATIONS_H -- cgit v1.2.3 From 0e11a8ac5e0e90ae1b576287e13011593dcdc88c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:08:08 -0600 Subject: add other datetime header files --- include/datetime/CMakeLists.txt | 2 + include/datetime/appointment.h | 63 ++++++++++++++++++++++++++ include/datetime/date-time.h | 93 ++++++++++++++++++++++++++++++++++++++ include/datetime/dbus-shared.h | 24 ++++++++++ include/datetime/settings-shared.h | 49 ++++++++++++++++++++ include/datetime/timezones-live.h | 56 +++++++++++++++++++++++ include/datetime/timezones.h | 56 +++++++++++++++++++++++ include/datetime/utils.h | 67 +++++++++++++++++++++++++++ 8 files changed, 410 insertions(+) create mode 100644 include/datetime/CMakeLists.txt create mode 100644 include/datetime/appointment.h create mode 100644 include/datetime/date-time.h create mode 100644 include/datetime/dbus-shared.h create mode 100644 include/datetime/settings-shared.h create mode 100644 include/datetime/timezones-live.h create mode 100644 include/datetime/timezones.h create mode 100644 include/datetime/utils.h (limited to 'include/datetime') diff --git a/include/datetime/CMakeLists.txt b/include/datetime/CMakeLists.txt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/include/datetime/CMakeLists.txt @@ -0,0 +1,2 @@ + + diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h new file mode 100644 index 0000000..098b0d0 --- /dev/null +++ b/include/datetime/appointment.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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_APPOINTMENT_H +#define INDICATOR_DATETIME_APPOINTMENT_H + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * PODS representing a calendar appointment + */ +struct Appointment +{ +public: + std::string color; + std::string summary; + std::string url; + std::string uid; + bool is_event = false; + bool is_daily = false; + bool has_alarms = false; + DateTime begin; + DateTime end; + + bool operator== (const Appointment& that) const + { + return (color==that.color) && + (summary==that.summary) && + (url==that.url) && + (uid==that.uid) && + (is_event==that.is_event) && + (has_alarms==that.has_alarms) && + (begin==that.begin) && + (end==that.end); + } +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_APPOINTMENT_H diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h new file mode 100644 index 0000000..bbcd00a --- /dev/null +++ b/include/datetime/date-time.h @@ -0,0 +1,93 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_DATETIME_H +#define INDICATOR_DATETIME_DATETIME_H + +#include // GDateTime + +#include // std::shared_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * C++ wrapper class for GDateTime + */ +class DateTime +{ +public: + + GDateTime* get() const + { + return dt_.get(); + } + + GDateTime* operator()() const + { + return get(); + } + + void set (GDateTime* in) { + auto deleter = [](GDateTime* dt){g_date_time_unref(dt);}; + dt_ = std::shared_ptr(g_date_time_ref(in), deleter); + } + + DateTime& operator=(GDateTime* in) + { + set (in); + return *this; + } + + DateTime& operator=(const DateTime& in) + { + set (in.get()); + return *this; + } + + 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 + { + 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; + } + +private: + + std::shared_ptr dt_; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_DATETIME_H diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h new file mode 100644 index 0000000..24319e3 --- /dev/null +++ b/include/datetime/dbus-shared.h @@ -0,0 +1,24 @@ +/* +An indicator to show date and time information. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +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 . +*/ + +#define BUS_NAME "com.canonical.indicator.datetime" +#define BUS_PATH "/com/canonical/indicator/datetime" + diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h new file mode 100644 index 0000000..896db95 --- /dev/null +++ b/include/datetime/settings-shared.h @@ -0,0 +1,49 @@ +/* + * Copyright 2010 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: + * Ted Gould + * Charles Kerr + */ + +#ifndef __DATETIME_SETTINGS_SHARED_H__ +#define __DATETIME_SETTINGS_SHARED_H__ + +typedef enum +{ + TIME_FORMAT_MODE_LOCALE_DEFAULT, + TIME_FORMAT_MODE_12_HOUR, + TIME_FORMAT_MODE_24_HOUR, + TIME_FORMAT_MODE_CUSTOM +} +TimeFormatMode; + +#define SETTINGS_INTERFACE "com.canonical.indicator.datetime" +#define SETTINGS_SHOW_CLOCK_S "show-clock" +#define SETTINGS_TIME_FORMAT_S "time-format" +#define SETTINGS_SHOW_SECONDS_S "show-seconds" +#define SETTINGS_SHOW_DAY_S "show-day" +#define SETTINGS_SHOW_DATE_S "show-date" +#define SETTINGS_SHOW_YEAR_S "show-year" +#define SETTINGS_CUSTOM_TIME_FORMAT_S "custom-time-format" +#define SETTINGS_SHOW_CALENDAR_S "show-calendar" +#define SETTINGS_SHOW_WEEK_NUMBERS_S "show-week-numbers" +#define SETTINGS_SHOW_EVENTS_S "show-events" +#define SETTINGS_SHOW_LOCATIONS_S "show-locations" +#define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location" +#define SETTINGS_LOCATIONS_S "locations" +#define SETTINGS_TIMEZONE_NAME_S "timezone-name" + +#endif /* __DATETIME_SETTINGS_SHARED_H__ */ diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h new file mode 100644 index 0000000..3075bd8 --- /dev/null +++ b/include/datetime/timezones-live.h @@ -0,0 +1,56 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_LIVE_TIMEZONES_H +#define INDICATOR_DATETIME_LIVE_TIMEZONES_H + +#include // base class +#include // aggregated +#include // aggregated + +#include // shared_ptr<> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Timezones object that uses a #FileTimezone and #GeoclueTimezone + * to detect what timezone we're in + */ +class LiveTimezones: public Timezones +{ +public: + LiveTimezones(const std::string& filename); + + /** \brief Whether or not to track location by IP address */ + core::Property geolocationEnabled = core::Property(false); + +private: + FileTimezone file_; + std::shared_ptr geo_; + void updateGeolocation(); + void updateTimezones(); +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_LIVE_TIMEZONES_H diff --git a/include/datetime/timezones.h b/include/datetime/timezones.h new file mode 100644 index 0000000..0b97683 --- /dev/null +++ b/include/datetime/timezones.h @@ -0,0 +1,56 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_TIMEZONES_H +#define INDICATOR_DATETIME_TIMEZONES_H + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** \brief Aggregates one or more timezone detectors and decides which to use */ +class Timezones +{ +public: + + Timezones() =default; + + virtual ~Timezones() =default; + + /** + * \brief the current timezone + */ + core::Property timezone; + + /** + * \brief all the detected timezones. + * The count is >1 iff the detection mechamisms disagree. + */ + core::Property > timezones; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_TIMEZONES_H diff --git a/include/datetime/utils.h b/include/datetime/utils.h new file mode 100644 index 0000000..bd2e132 --- /dev/null +++ b/include/datetime/utils.h @@ -0,0 +1,67 @@ +/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- + +A dialog for setting time and date preferences. + +Copyright 2010 Canonical Ltd. + +Authors: + Michael Terry + +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 . +*/ + +#ifndef __DATETIME_UTILS_H__ +#define __DATETIME_UTILS_H__ + +#include +#include /* GSettings */ + +G_BEGIN_DECLS + +gboolean is_locale_12h (void); + +void split_settings_location (const char * location, + char ** zone, + char ** name); + +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 -- cgit v1.2.3 From ee64bb2698adfe27e55615a8856b0e2c78ad8469 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Jan 2014 23:07:10 -0600 Subject: Function: add fully-tested ActionGroups, per-profile Menus, state object. Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again --- include/datetime/actions-live.h | 57 +++++++++++++++++++ include/datetime/actions.h | 70 +++++++++++++++++++++++ include/datetime/appointment.h | 4 +- include/datetime/clock-mock.h | 28 +++++---- include/datetime/clock.h | 25 +++++---- include/datetime/date-time.h | 103 +++++++++++++++++++++++++--------- include/datetime/dbus-shared.h | 37 ++++++------ include/datetime/formatter.h | 29 ++++++++-- include/datetime/locations-settings.h | 11 ++-- include/datetime/locations.h | 38 +++++++++---- include/datetime/menu.h | 82 +++++++++++++++++++++++++++ include/datetime/planner-eds.h | 2 +- include/datetime/planner-mock.h | 44 +++++++++++++++ include/datetime/planner.h | 3 + include/datetime/service.h | 72 ++++++++++++++++++++++++ include/datetime/settings-live.h | 57 +++++++++++++++++++ include/datetime/settings-shared.h | 6 +- include/datetime/settings.h | 63 +++++++++++++++++++++ include/datetime/state.h | 68 ++++++++++++++++++++++ include/datetime/timezone-file.h | 13 +++-- include/datetime/timezone-geoclue.h | 12 ++-- include/datetime/timezone.h | 4 +- include/datetime/timezones-live.h | 13 +++-- include/datetime/timezones.h | 4 +- include/datetime/utils.h | 28 +-------- 25 files changed, 732 insertions(+), 141 deletions(-) create mode 100644 include/datetime/actions-live.h create mode 100644 include/datetime/actions.h create mode 100644 include/datetime/menu.h create mode 100644 include/datetime/planner-mock.h create mode 100644 include/datetime/service.h create mode 100644 include/datetime/settings-live.h create mode 100644 include/datetime/settings.h create mode 100644 include/datetime/state.h (limited to 'include/datetime') 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_ACTIONS_LIVE_H +#define INDICATOR_DATETIME_ACTIONS_LIVE_H + +#include + +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): 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_ACTIONS_H +#define INDICATOR_DATETIME_ACTIONS_H + +#include +#include + +#include // shared_ptr +#include + +#include // 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() { return m_state; } + +protected: + Actions(std::shared_ptr& state); + virtual ~Actions(); + +private: + std::shared_ptr 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 #include #include #include -#include #include #include @@ -45,9 +45,10 @@ class Clock { public: virtual ~Clock(); - virtual GDateTime* localtime() const = 0; - core::Property > timezones; + virtual DateTime localtime() const =0; + core::Property> 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& zones); virtual ~LiveClock(); - virtual GDateTime* localtime() const; + virtual DateTime localtime() const; core::Property 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 // GDateTime +#include // time_t #include // 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(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(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 dt_; + std::shared_ptr 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 . + * + * Authors: + * Ted Gould + * Charles Kerr + */ -Copyright 2010 Canonical Ltd. - -Authors: - Ted Gould - -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 . -*/ #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&); 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); + SettingsLocations (const std::string& schemaId, + const std::shared_ptr& timezones); protected: - std::unique_ptr> settings_; - std::shared_ptr timezones_; + std::unique_ptr> m_settings; + std::shared_ptr 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 + #include #include @@ -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 > locations; + core::Property> 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_MENU_H +#define INDICATOR_DATETIME_MENU_H + +#include +#include + +#include // std::shared_ptr +#include + +#include // 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, std::shared_ptr& state); + std::shared_ptr buildMenu(Menu::Profile profile); + std::shared_ptr state() { return m_state; } + +private: + std::shared_ptr m_actions; + std::shared_ptr 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_; + std::unique_ptr 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_MOCK_H +#define INDICATOR_DATETIME_PLANNER_MOCK_H + +#include + +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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_EXPORTER_H +#define INDICATOR_DATETIME_EXPORTER_H + +#include + +#include + +#include // GActionGroup + +#include // std::shared_ptr +#include + +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>& 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 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> 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_LIVE_H +#define INDICATOR_DATETIME_SETTINGS_LIVE_H + +#include // parent class + +#include // 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 */ -#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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_H +#define INDICATOR_DATETIME_SETTINGS_H + +#include + +#include + +#include + +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 time_format_mode; + core::Property show_clock; + core::Property show_day; + core::Property show_year; + core::Property show_seconds; + core::Property custom_time_format; + core::Property show_calendar; + core::Property show_events; + core::Property show_locations; + core::Property show_auto_detected_location; + core::Property> locations; + core::Property 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_STATE_H +#define INDICATOR_DATETIME_STATE_H + +#include +#include +#include +#include + +#include + +#include // 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; + std::shared_ptr clock; + std::shared_ptr planner; + std::shared_ptr locations; + + core::Property show_events; + core::Property show_clock; + core::Property calendar_day; + core::Property 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 geolocationEnabled = core::Property(false); + core::Property geolocation_enabled = core::Property(false); private: - FileTimezone file_; - std::shared_ptr geo_; - void updateGeolocation(); - void updateTimezones(); + void update_geolocation(); + void update_timezones(); + + FileTimezone m_file; + std::shared_ptr 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 . */ -#ifndef __DATETIME_UTILS_H__ -#define __DATETIME_UTILS_H__ +#ifndef INDICATOR_DATETIME_UTILS_H +#define INDICATOR_DATETIME_UTILS_H #include #include /* 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 */ -- cgit v1.2.3 From bcff13b6bce18604472e5954eb5ab7af4bb43b0f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 15:10:39 -0600 Subject: Implement Settings, a properties-cpp wrapper around GSettings --- include/datetime/settings-live.h | 19 ++++++++++++++++--- include/datetime/settings.h | 16 +++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 44e27b0..202c998 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -38,10 +38,23 @@ public: virtual ~LiveSettings(); private: - void update_show_clock(); - - void update_key(const std::string& key); static void on_changed(GSettings*, gchar*, gpointer); + void update_key(const std::string& key); + + void update_custom_time_format(); + void update_locations(); + void update_show_calendar(); + void update_show_clock(); + void update_show_date(); + void update_show_day(); + void update_show_detected_locations(); + void update_show_events(); + void update_show_locations(); + void update_show_seconds(); + void update_show_week_numbers(); + void update_show_year(); + void update_time_format_mode(); + void update_timezone_name(); GSettings* m_settings; diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 3d4bc33..418bc33 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -42,17 +42,19 @@ public: Settings() =default; virtual ~Settings() =default; - core::Property time_format_mode; - core::Property show_clock; - core::Property show_day; - core::Property show_year; - core::Property show_seconds; core::Property custom_time_format; + core::Property> locations; core::Property show_calendar; + core::Property show_clock; + core::Property show_date; + core::Property show_day; + core::Property show_detected_location; core::Property show_events; core::Property show_locations; - core::Property show_auto_detected_location; - core::Property> locations; + core::Property show_seconds; + core::Property show_week_numbers; + core::Property show_year; + core::Property time_format_mode; core::Property timezone_name; }; -- cgit v1.2.3 From 78d0a231c12c159d1130ec080efab472f59851af Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 16:42:36 -0600 Subject: update DesktopFormatter class to use the "Settings" class instead of using GSettings directly. --- include/datetime/formatter.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index 09ed035..d8736c7 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -23,8 +23,14 @@ #include #include +#include +#include + #include +#include +#include + namespace unity { namespace indicator { namespace datetime { @@ -109,13 +115,16 @@ private: class DesktopFormatter: public Formatter { public: - DesktopFormatter(const std::shared_ptr&); - ~DesktopFormatter(); + DesktopFormatter(const std::shared_ptr&, const std::shared_ptr&); private: - class Impl; - friend Impl; - std::unique_ptr p; + std::shared_ptr m_settings; + + void rebuildHeaderFormat(); + const gchar* getFullTimeFormatString() const; + std::string getHeaderLabelFormatString() const; + const gchar* getDateFormat(bool show_day, bool show_date, bool show_year) const; + }; -- cgit v1.2.3 From 9c81a4d60d06b1f33001602cd0cde9844c9233a6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 16:44:06 -0600 Subject: update SettingsLocations class to use the "Settings" class instead of using GSettings directly. --- include/datetime/locations-settings.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h index eaabf73..4072736 100644 --- a/include/datetime/locations-settings.h +++ b/include/datetime/locations-settings.h @@ -22,18 +22,15 @@ #include // base class -#include -#include +#include +#include namespace unity { namespace indicator { namespace datetime { -class Timezones; - /** - * \brief Settings implentation which builds its list from the - * user's GSettings and from the Timezones passed in the ctor. + * \brief #Locations implementation which builds its list from the #Settings. */ class SettingsLocations: public Locations { @@ -42,15 +39,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, + SettingsLocations (const std::shared_ptr& settings, const std::shared_ptr& timezones); -protected: - std::unique_ptr> m_settings; - std::shared_ptr m_timezones; - private: - static void onSettingsChanged (gpointer gself); + std::shared_ptr m_settings; + std::shared_ptr m_timezones; void reload(); }; -- cgit v1.2.3 From a2b5c79157fa8db36d94786de1b86b756308912d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 16:45:40 -0600 Subject: Plug the Settings object into the State container s.t. menus and actions can update themselves when the user's settings change. --- include/datetime/state.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/state.h b/include/datetime/state.h index a82bb4b..e735b6f 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -21,9 +21,10 @@ #define INDICATOR_DATETIME_STATE_H #include -#include -#include #include +#include +#include +#include #include @@ -47,18 +48,17 @@ namespace datetime { * @see Clock * @see Planner * @see Locations + * @see Settings */ struct State { - std::shared_ptr timezones; std::shared_ptr clock; - std::shared_ptr planner; std::shared_ptr locations; + std::shared_ptr planner; + std::shared_ptr settings; + std::shared_ptr timezones; - core::Property show_events; - core::Property show_clock; core::Property calendar_day; - core::Property show_week_numbers; }; } // namespace datetime -- cgit v1.2.3 From 4cc19729c540ffba163d5c9a53b9352fe61fe8af Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 17:28:37 -0600 Subject: in utils.c, make a version of get_timezone_name() that doesn't require a GSettings argument. Update utils tests. --- include/datetime/utils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/datetime') diff --git a/include/datetime/utils.h b/include/datetime/utils.h index fbc80d7..10e881f 100644 --- a/include/datetime/utils.h +++ b/include/datetime/utils.h @@ -34,9 +34,12 @@ void split_settings_location (const char * location, char ** zone, char ** name); -gchar * get_current_zone_name (const char * location, +gchar * get_timezone_name (const char * timezone, GSettings * settings); +gchar * get_beautified_timezone_name (const char * timezone, + const char * saved_location); + gchar * generate_full_format_string_at_time (GDateTime * now, GDateTime * time); -- cgit v1.2.3 From 40689ea36c360cb6fb42048f5d93303237745b86 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 17:42:43 -0600 Subject: update timezones-live to use Settings to tell when the user has enabled/disabled GeoClue lookups --- include/datetime/timezones-live.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h index 5f2cb3e..286c967 100644 --- a/include/datetime/timezones-live.h +++ b/include/datetime/timezones-live.h @@ -20,9 +20,10 @@ #ifndef INDICATOR_DATETIME_LIVE_TIMEZONES_H #define INDICATOR_DATETIME_LIVE_TIMEZONES_H -#include // base class -#include // aggregated -#include // aggregated +#include +#include +#include +#include #include // shared_ptr<> @@ -37,16 +38,14 @@ namespace datetime { class LiveTimezones: public Timezones { public: - LiveTimezones(const std::string& filename); - - /** \brief Whether or not to track location by IP address */ - core::Property geolocation_enabled = core::Property(false); + LiveTimezones(std::shared_ptr& settings, const std::string& filename); private: void update_geolocation(); void update_timezones(); FileTimezone m_file; + std::shared_ptr m_settings; std::shared_ptr m_geo; }; -- cgit v1.2.3 From 2e9d3bb48946ccebf49cff64ab5de67e5714e1e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 21:23:57 -0600 Subject: get timezone, clock tests running again with Settings & State --- include/datetime/actions-live.h | 7 +++---- include/datetime/actions.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 2059a4d..3d04660 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,15 +36,14 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(std::shared_ptr& state): Actions(state) {} + LiveActions(const std::shared_ptr& state): Actions(state) {} ~LiveActions() =default; void open_desktop_settings(); void open_phone_settings(); - void open_phone_clock(); - void open_phone_planner(); + void open_phone_clock_app(); + void open_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&); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index ed45c3c..a4c6017 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: std::shared_ptr state() { return m_state; } protected: - Actions(std::shared_ptr& state); + Actions(const std::shared_ptr& state); virtual ~Actions(); private: -- cgit v1.2.3 From 74f8897902c99180e721d616614a9962c819d90b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 21 Jan 2014 23:29:19 -0600 Subject: add LiveActions implementation and unit tests --- include/datetime/actions-live.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/datetime') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 3d04660..1947e6e 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,7 +36,7 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr& state): Actions(state) {} + LiveActions(const std::shared_ptr& state_in): Actions(state_in) {} ~LiveActions() =default; void open_desktop_settings(); @@ -47,6 +47,10 @@ public: void open_appointment(const std::string& uid); void set_location(const std::string& zone, const std::string& name); void set_calendar_date(const DateTime&); + +protected: + virtual void execute_command(const std::string& command); + virtual void dispatch_url(const std::string& url); }; } // namespace datetime -- cgit v1.2.3 From 74fcc162abf2224bd74e564978afb338252c29ce Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:15:34 -0600 Subject: Fix GDateTime leak in DateTime::DateTime(time_t) --- include/datetime/date-time.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/datetime') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 5b9421f..33f8b40 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -38,7 +38,11 @@ public: explicit DateTime(GDateTime* in=nullptr) { reset(in); } - explicit DateTime(time_t t) { reset(g_date_time_new_from_unix_local(t)); } + explicit DateTime(time_t t) { + GDateTime * gdt = g_date_time_new_from_unix_local(t); + reset(gdt); + g_date_time_unref(gdt); + } static DateTime NowLocal() { GDateTime * gdt = g_date_time_new_now_local(); -- cgit v1.2.3 From 2b857f6ca1c9c67a023fb9ad2eb6ec97f59e4335 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:34:25 -0600 Subject: move DateTime's impl from the header to a cc file --- include/datetime/date-time.h | 121 +++++++------------------------------------ 1 file changed, 20 insertions(+), 101 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 33f8b40..145e34e 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -35,107 +35,26 @@ namespace datetime { class DateTime { public: - - explicit DateTime(GDateTime* in=nullptr) { reset(in); } - - explicit DateTime(time_t t) { - GDateTime * gdt = g_date_time_new_from_unix_local(t); - reset(gdt); - g_date_time_unref(gdt); - } - - 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* get() const { - g_assert(m_dt); - return m_dt.get(); - } - - GDateTime* operator()() const { - return get(); - } - - - 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(g_date_time_ref(in), deleter); - g_assert(m_dt); - } else { - m_dt.reset(); - } - } - - DateTime& operator=(GDateTime* in) { - reset(in); - return *this; - } - - DateTime& operator=(const DateTime& in) { - m_dt = in.m_dt; - return *this; - } - - 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 true if this isn't set, or if it's not equal - return (!m_dt) || !(*this == that); - } - - 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; - } + static DateTime NowLocal(); + explicit DateTime(time_t t); + explicit DateTime(GDateTime* in=nullptr) {reset(in);} + DateTime& operator=(GDateTime* in) {reset(in); return *this;} + DateTime& operator=(const DateTime& in) {m_dt=in.m_dt; return *this; } + DateTime to_timezone(const std::string& zone) const; + void reset(GDateTime* in=nullptr); + + GDateTime* get() const; + GDateTime* operator()() const {return get();} + + std::string format(const std::string& fmt) const; + int day_of_month() const; + int64_t to_unix() const; + int day_of_year() const; + gint64 difference(const DateTime& that) const; + + bool operator<(const DateTime& that) const; + bool operator!=(const DateTime& that) const; + bool operator==(const DateTime& that) const; private: std::shared_ptr m_dt; -- cgit v1.2.3 From d611929649cc4ef6b04ad9c453f14c85e1108842 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:36:07 -0600 Subject: extract LiveState to its own State subclass to make main()'s flow easier to follow --- include/datetime/state-live.h | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 include/datetime/state-live.h (limited to 'include/datetime') diff --git a/include/datetime/state-live.h b/include/datetime/state-live.h new file mode 100644 index 0000000..2b93722 --- /dev/null +++ b/include/datetime/state-live.h @@ -0,0 +1,49 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_STATE_LIVE_H +#define INDICATOR_DATETIME_STATE_LIVE_H + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class LiveState: public State +{ +public: + LiveState(); + virtual ~LiveState() =default; +}; + +/*** +**** +***/ + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H -- cgit v1.2.3 From f0fee18c0baf7ef0fb27351db716ee3708c021c6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 00:41:16 -0600 Subject: copyediting: rename Service as Exporter & tweak comments --- include/datetime/exporter.h | 74 +++++++++++++++++++++++++++++++++++++++++++++ include/datetime/service.h | 72 ------------------------------------------- 2 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 include/datetime/exporter.h delete mode 100644 include/datetime/service.h (limited to 'include/datetime') diff --git a/include/datetime/exporter.h b/include/datetime/exporter.h new file mode 100644 index 0000000..a32b941 --- /dev/null +++ b/include/datetime/exporter.h @@ -0,0 +1,74 @@ +/* + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_EXPORTER_H +#define INDICATOR_DATETIME_EXPORTER_H + +#include +#include + +#include + +#include // GActionGroup + +#include // std::shared_ptr +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Exports actions and menus to DBus. + */ +class Exporter +{ +public: + Exporter() =default; + ~Exporter(); + + core::Signal<> name_lost; + + void publish(std::shared_ptr& actions, + std::vector>& 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 m_exported_menu_ids; + guint m_own_id = 0; + guint m_exported_actions_id = 0; + GDBusConnection * m_dbus_connection = nullptr; + std::shared_ptr m_actions; + std::vector> m_menus; + + // we've got raw pointers and gsignal tags in here, so disable copying + Exporter(const Exporter&) =delete; + Exporter& operator=(const Exporter&) =delete; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_EXPORTER_H diff --git a/include/datetime/service.h b/include/datetime/service.h deleted file mode 100644 index c7171b7..0000000 --- a/include/datetime/service.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 . - * - * Authors: - * Charles Kerr - */ - -#ifndef INDICATOR_DATETIME_EXPORTER_H -#define INDICATOR_DATETIME_EXPORTER_H - -#include - -#include - -#include // GActionGroup - -#include // std::shared_ptr -#include - -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>& 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 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> 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 -- cgit v1.2.3 From 2db8f6e7c4b7148377800400c72bb2e59b793d3a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 10:01:20 -0600 Subject: remove the State.timezones property. Timezones is a helper class for LiveClock and doesn't need to be public in State. --- include/datetime/state.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/datetime') diff --git a/include/datetime/state.h b/include/datetime/state.h index e735b6f..b14908e 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -52,11 +52,20 @@ namespace datetime { */ struct State { + /** \brief The current time. Used by the header, by the date menuitem, + and by the locations for relative timestamp */ std::shared_ptr clock; + + /** \brief The locations to be displayed in the Locations + 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 Configuration options that modify the view */ std::shared_ptr settings; - std::shared_ptr timezones; core::Property calendar_day; }; -- cgit v1.2.3 From 0f6a8f9bcf57e0c77b9c8d7f83d93dd1be178d41 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 10:03:57 -0600 Subject: copyediting: slightly better header comments/docs --- include/datetime/actions-live.h | 2 +- include/datetime/actions.h | 6 +++++- include/datetime/clock.h | 2 +- include/datetime/formatter.h | 3 +-- include/datetime/locations-settings.h | 4 ++-- include/datetime/menu.h | 4 ++++ include/datetime/planner-mock.h | 4 ++-- include/datetime/planner.h | 2 ++ include/datetime/settings.h | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 1947e6e..949222d 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -27,7 +27,7 @@ namespace indicator { namespace datetime { /** - * \brief Production implentation of the Actions interface. + * \brief Production implementation of the Actions interface. * * Delegates URLs, sets the timezone via org.freedesktop.timedate1, etc. * diff --git a/include/datetime/actions.h b/include/datetime/actions.h index a4c6017..18286dc 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -33,7 +33,11 @@ namespace indicator { namespace datetime { /** - * Interface for all the actions that can be activated by users via the menu. + * \brief Interface for all the actions that can be activated by users. + * + * This is a simple C++ wrapper around our GActionGroup that gets exported + * onto the bus. Subclasses implement the actual code that should be run + * when a particular action is triggered. */ class Actions { diff --git a/include/datetime/clock.h b/include/datetime/clock.h index c8e6c16..ffaf4f8 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -61,7 +61,7 @@ private: GDBusConnection * m_system_bus = nullptr; unsigned int m_sleep_subscription_id = 0; - // we've got raw pointers in here, so disable copying + // we've got raw pointers and GSignal tags in here, so disable copying Clock(const Clock&) =delete; Clock& operator=(const Clock&) =delete; }; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index d8736c7..86fa64a 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -45,8 +45,7 @@ class DateTime; /** * \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: + * This is a simple goal, but getting there has a lot of options and edge cases: * * - The default time format can change based on the locale. * diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h index 4072736..d01cbb5 100644 --- a/include/datetime/locations-settings.h +++ b/include/datetime/locations-settings.h @@ -36,8 +36,8 @@ class SettingsLocations: public Locations { public: /** - * @param[in] schemaId the settings schema to load - * @param[in] timezones the timezones to always show first in the list + * @param[in] settings the #Settings whose locations property is to be used + * @param[in] timezones the #Timezones to always show first in the list */ SettingsLocations (const std::shared_ptr& settings, const std::shared_ptr& timezones); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 0bc3781..fcd709f 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -36,6 +36,7 @@ namespace datetime { * \brief A menu for a specific profile; eg, Desktop or Phone. * * @see MenuFactory + * @see Exporter */ class Menu { @@ -62,6 +63,9 @@ private: /** * \brief Builds a Menu for a given state and profile + * + * @see Menu + * @see Exporter */ class MenuFactory { diff --git a/include/datetime/planner-mock.h b/include/datetime/planner-mock.h index bb3ff53..44d30c7 100644 --- a/include/datetime/planner-mock.h +++ b/include/datetime/planner-mock.h @@ -27,8 +27,8 @@ namespace indicator { namespace datetime { /** - * \brief Planner which does nothing on its own and requires - * its client to set its appointments property. + * \brief Planner which does nothing on its own. + * It requires its client must set its appointments property. */ class MockPlanner: public Planner { diff --git a/include/datetime/planner.h b/include/datetime/planner.h index 198b6fa..a8f9941 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -63,6 +63,8 @@ protected: Planner() =default; private: + + // disable copying Planner(const Planner&) =delete; Planner& operator=(const Planner&) =delete; }; diff --git a/include/datetime/settings.h b/include/datetime/settings.h index 418bc33..ce234d9 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -34,7 +34,7 @@ namespace datetime { * \brief Interface that represents user-configurable settings. * * See the descriptions in data/com.canonical.indicator.datetime.gschema.xml - * For more information. + * for more information on specific properties. */ class Settings { -- cgit v1.2.3 From 08b1cfd6bc97cae18b916d97a03781986e7421fe Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 10:15:56 -0600 Subject: move planner-mock.h from include/datetime/ to tests/ because it's only needed by the tests. --- include/datetime/planner-mock.h | 44 ----------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 include/datetime/planner-mock.h (limited to 'include/datetime') diff --git a/include/datetime/planner-mock.h b/include/datetime/planner-mock.h deleted file mode 100644 index 44d30c7..0000000 --- a/include/datetime/planner-mock.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 . - * - * Authors: - * Charles Kerr - */ - -#ifndef INDICATOR_DATETIME_PLANNER_MOCK_H -#define INDICATOR_DATETIME_PLANNER_MOCK_H - -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/** - * \brief Planner which does nothing on its own. - * It requires its client must 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 -- cgit v1.2.3 From 9ea8a269f3c984901e721e8bb0c796942bffb082 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 11:29:10 -0600 Subject: Remove the Timezones property from Clock; it's only needed by the subclass LiveClock --- include/datetime/clock.h | 9 ++++----- include/datetime/timezones.h | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/clock.h b/include/datetime/clock.h index ffaf4f8..9e87082 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -21,15 +21,13 @@ #define INDICATOR_DATETIME_CLOCK_H #include -#include #include #include -#include +#include // GDBusConnection -#include -#include +#include // std::shared_ptr, std::unique_ptr namespace unity { namespace indicator { @@ -46,7 +44,6 @@ class Clock public: virtual ~Clock(); virtual DateTime localtime() const =0; - core::Property> timezones; core::Signal<> skewDetected; core::Signal<> dateChanged; @@ -70,6 +67,8 @@ private: **** ***/ +class Timezones; + /** * \brief A live clock that provides the actual system time. * diff --git a/include/datetime/timezones.h b/include/datetime/timezones.h index 10c4e97..d2842af 100644 --- a/include/datetime/timezones.h +++ b/include/datetime/timezones.h @@ -28,7 +28,12 @@ namespace unity { namespace indicator { namespace datetime { -/** \brief Aggregates one or more timezone detectors and decides which to give precedence to */ +/** + * \brief Helper class which aggregates one or more timezones + * + * @see LiveClock + * @see SettingsLocations + */ class Timezones { public: -- cgit v1.2.3 From aad7e86a109aeec75b3772cda20478363f966745 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 14:28:20 -0600 Subject: Alarms is going to need to know when the clock's minute changes. We already have a timer for that in Formatter, so move it from there to Clock and add a corresponding public signal Clock.minuteChanged that both Formatter and Alarms can use. Sync unit tests. --- include/datetime/clock-mock.h | 8 ++++---- include/datetime/clock.h | 20 +++++++++----------- include/datetime/date-time.h | 5 +++-- 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 19a859b..27926ff 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -42,11 +42,11 @@ public: DateTime localtime() const { return m_localtime; } void set_localtime(const DateTime& dt) { - const auto old_day = m_localtime.day_of_year(); + const auto old = m_localtime; m_localtime = dt; - skewDetected(); - const auto new_day = m_localtime.day_of_year(); - if (old_day != new_day) + if (!DateTime::is_same_minute(old, m_localtime)) + minuteChanged(); + if (!DateTime::is_same_day(old, m_localtime)) dateChanged(); } diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 9e87082..b3e3538 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -35,21 +35,25 @@ namespace datetime { /** * \brief A clock. - * - * Provides a signal to notify when clock skew is detected, such as - * when the timezone changes or when the system resumes from sleep. */ class Clock { public: virtual ~Clock(); virtual DateTime localtime() const =0; - core::Signal<> skewDetected; + + /** \brief A signal which fires when the clock's minute changes */ + core::Signal<> minuteChanged; + + /** \brief A signal which fires when the clock's date changes */ core::Signal<> dateChanged; protected: Clock(); + /** \brief Compares old and new times, emits minuteChanged() or dateChanged() signals if appropriate */ + void maybe_emit (const DateTime& a, const DateTime& b); + private: static void onSystemBusReady(GObject*, GAsyncResult*, gpointer); static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); @@ -70,12 +74,7 @@ private: class Timezones; /** - * \brief A live clock that provides the actual system time. - * - * 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. + * \brief A live #Clock that provides the actual system time. */ class LiveClock: public Clock { @@ -83,7 +82,6 @@ public: LiveClock (const std::shared_ptr& zones); virtual ~LiveClock(); virtual DateTime localtime() const; - core::Property skewTestIntervalSec; private: class Impl; diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 145e34e..c2429eb 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -49,13 +49,14 @@ public: std::string format(const std::string& fmt) const; int day_of_month() const; int64_t to_unix() const; - int day_of_year() const; - gint64 difference(const DateTime& that) const; bool operator<(const DateTime& that) const; bool operator!=(const DateTime& that) const; bool operator==(const DateTime& that) const; + static bool is_same_day(const DateTime& a, const DateTime& b); + static bool is_same_minute(const DateTime& a, const DateTime& b); + private: std::shared_ptr m_dt; }; -- cgit v1.2.3 From 7b09a0ff5652bdca7c8d8e046d2af6a696f94147 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 25 Jan 2014 16:54:41 -0600 Subject: sync the exported calendar state with the #State backend --- include/datetime/actions.h | 4 ++-- include/datetime/state.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 18286dc..3686b95 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -49,8 +49,7 @@ public: 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; - + void set_calendar_date(const DateTime&); GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } std::shared_ptr state() { return m_state; } @@ -61,6 +60,7 @@ protected: private: std::shared_ptr m_state; GSimpleActionGroup* m_actions = nullptr; + void update_calendar_state(); // we've got raw pointers in here, so disable copying Actions(const Actions&) =delete; diff --git a/include/datetime/state.h b/include/datetime/state.h index b14908e..414be32 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -66,8 +66,6 @@ struct State /** \brief Configuration options that modify the view */ std::shared_ptr settings; - - core::Property calendar_day; }; } // namespace datetime -- cgit v1.2.3 From ee9f4c7ef822a101cea8d12c565d8a8a93d9caf5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 28 Jan 2014 16:26:45 -0600 Subject: make utils.cpp's generate_full_format_string_at_time() a standalone function so that the panels can use the utils functions without a libindicatordatetime dependency --- include/datetime/utils.h | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/utils.h b/include/datetime/utils.h index 10e881f..7cac9fd 100644 --- a/include/datetime/utils.h +++ b/include/datetime/utils.h @@ -1,24 +1,22 @@ -/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- - -A dialog for setting time and date preferences. - -Copyright 2010 Canonical Ltd. - -Authors: - Michael Terry - -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 . -*/ +/* + * Copyright 2010, 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: + * Michael Terry + * Charles Kerr + */ #ifndef INDICATOR_DATETIME_UTILS_H #define INDICATOR_DATETIME_UTILS_H @@ -28,6 +26,7 @@ with this program. If not, see . G_BEGIN_DECLS +/** \brief Returns true if the current locale prefers 12h display instead of 24h */ gboolean is_locale_12h (void); void split_settings_location (const char * location, @@ -41,7 +40,14 @@ gchar * get_beautified_timezone_name (const char * timezone, const char * saved_location); gchar * generate_full_format_string_at_time (GDateTime * now, - GDateTime * time); + GDateTime * then_begin, + GDateTime * then_end); + +/** \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 */ +const char* T_ (const char * msg); + G_END_DECLS -- cgit v1.2.3 From fd92ac35f12176225e910f1d25f57acf16a35cda Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 28 Jan 2014 16:28:40 -0600 Subject: cleanup from previous commit: since Formatter code was migrated to utils.c so that it could be used standalone by the panels, there's now code duplication between Utils and Formatter. Remove code duplication s.t. Formatter uses the Utils code as well. --- include/datetime/formatter.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index 86fa64a..3de109e 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -25,6 +25,7 @@ #include #include +#include // is_locale_12h() #include @@ -88,16 +89,8 @@ protected: Formatter(const std::shared_ptr&); 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); - /** \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); - private: Formatter(const Formatter&) =delete; -- cgit v1.2.3 From d2caa37e18191c31d866dd3042b676c135bae50d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 12:45:50 -0600 Subject: as per review, don't inline getters --- include/datetime/actions.h | 4 ++-- include/datetime/locations.h | 4 ++-- include/datetime/menu.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 3686b95..6817b4c 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -50,8 +50,8 @@ public: virtual void open_appointment(const std::string& uid) =0; virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); - GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } - std::shared_ptr state() { return m_state; } + GActionGroup* action_group(); + std::shared_ptr state(); protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index ee67615..fc776bb 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,9 +39,9 @@ namespace datetime { class Location { public: - const std::string& zone() const { return m_zone; } + const std::string& zone() const; - const std::string& name() const { return m_name; } + const std::string& name() const; bool operator== (const Location& that) const { diff --git a/include/datetime/menu.h b/include/datetime/menu.h index fcd709f..f097b02 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -43,9 +43,9 @@ 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); } + const std::string& name() const; + Profile profile() const; + GMenuModel* menu_model(); protected: Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} @@ -72,7 +72,7 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state() { return m_state; } + std::shared_ptr state(); private: std::shared_ptr m_actions; -- cgit v1.2.3 From cc2ad2ad457313cb87e4483bf0278f670a5a5cea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:00:22 -0600 Subject: as per review, don't inline unless there are performance issues --- include/datetime/actions-live.h | 2 +- include/datetime/appointment.h | 12 +----------- include/datetime/date-time.h | 6 +++--- include/datetime/locations.h | 12 ++---------- include/datetime/menu.h | 2 +- include/datetime/timezone-file.h | 6 +++--- include/datetime/timezone.h | 1 - 7 files changed, 11 insertions(+), 30 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 949222d..3607836 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,7 +36,7 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr& state_in): Actions(state_in) {} + LiveActions(const std::shared_ptr& state_in); ~LiveActions() =default; void open_desktop_settings(); diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index e034c08..a5283c9 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -45,17 +45,7 @@ public: DateTime begin; DateTime end; - bool operator== (const Appointment& that) const - { - return (color==that.color) && - (summary==that.summary) && - (url==that.url) && - (uid==that.uid) && - (is_event==that.is_event) && - (has_alarms==that.has_alarms) && - (begin==that.begin) && - (end==that.end); - } + bool operator== (const Appointment& that) const; }; } // namespace datetime diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index c2429eb..2ad7856 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -37,9 +37,9 @@ class DateTime public: static DateTime NowLocal(); explicit DateTime(time_t t); - explicit DateTime(GDateTime* in=nullptr) {reset(in);} - DateTime& operator=(GDateTime* in) {reset(in); return *this;} - DateTime& operator=(const DateTime& in) {m_dt=in.m_dt; return *this; } + explicit DateTime(GDateTime* in=nullptr); + DateTime& operator=(GDateTime* in); + DateTime& operator=(const DateTime& in); DateTime to_timezone(const std::string& zone) const; void reset(GDateTime* in=nullptr); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index fc776bb..b840436 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,18 +39,10 @@ namespace datetime { class Location { public: + Location (const std::string& zone, const std::string& name); const std::string& zone() const; - const std::string& name() const; - - bool operator== (const Location& that) const - { - return (name() == that.name()) && - (zone() == that.zone()) && - (m_offset == that.m_offset); - } - - Location (const std::string& zone, const std::string& name); + bool operator== (const Location& that) const; private: diff --git a/include/datetime/menu.h b/include/datetime/menu.h index f097b02..526cd9f 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -48,7 +48,7 @@ public: GMenuModel* menu_model(); protected: - Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} + Menu (Profile profile_in, const std::string& name_in); virtual ~Menu() =default; GMenu* m_menu = nullptr; diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index 7f47df6..d77aaae 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -37,9 +37,9 @@ namespace datetime { class FileTimezone: public Timezone { public: - FileTimezone() {} - FileTimezone(const std::string& filename) { setFilename(filename); } - ~FileTimezone() {clear();} + FileTimezone(); + FileTimezone(const std::string& filename); + ~FileTimezone(); private: void setFilename(const std::string& filename); diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h index ffa5a84..7d2ace8 100644 --- a/include/datetime/timezone.h +++ b/include/datetime/timezone.h @@ -35,7 +35,6 @@ protected: Timezone() =default; public: - //virtual ~Timezone() {} core::Property timezone; }; -- cgit v1.2.3 From fee34f529e85e97cb439ea9fbbb210cffd51a6cf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:06:33 -0600 Subject: as per review, make explicit the dependency injection that was implicit in main() --- include/datetime/state-live.h | 49 ------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 include/datetime/state-live.h (limited to 'include/datetime') diff --git a/include/datetime/state-live.h b/include/datetime/state-live.h deleted file mode 100644 index 2b93722..0000000 --- a/include/datetime/state-live.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 . - * - * Authors: - * Charles Kerr - */ - -#ifndef INDICATOR_DATETIME_STATE_LIVE_H -#define INDICATOR_DATETIME_STATE_LIVE_H - -#include - -namespace unity { -namespace indicator { -namespace datetime { - -/*** -**** -***/ - -class LiveState: public State -{ -public: - LiveState(); - virtual ~LiveState() =default; -}; - -/*** -**** -***/ - - -} // namespace datetime -} // namespace indicator -} // namespace unity - -#endif // INDICATOR_DATETIME_SETTINGS_LIVE_H -- cgit v1.2.3 From b56293e7b4fb4b253da17119ad153990744dac3b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:17:11 -0600 Subject: as per review, constify getters where possible. This isn't always possible due to system APIs asking for non-const pointers. --- include/datetime/actions.h | 2 +- include/datetime/menu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 6817b4c..99e78f5 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); GActionGroup* action_group(); - std::shared_ptr state(); + const std::shared_ptr state() const; protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 526cd9f..5821e33 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -72,7 +72,6 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state(); private: std::shared_ptr m_actions; -- cgit v1.2.3 From 0f384f4c9607b785d7df4da8566fe2b869ef11e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:28:48 -0600 Subject: as per review, there were a few places that accidentally passed a shared_ptr& instead of a const shared_ptr& --- include/datetime/exporter.h | 4 ++-- include/datetime/menu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/exporter.h b/include/datetime/exporter.h index a32b941..c228cc1 100644 --- a/include/datetime/exporter.h +++ b/include/datetime/exporter.h @@ -45,8 +45,8 @@ public: core::Signal<> name_lost; - void publish(std::shared_ptr& actions, - std::vector>& menus); + void publish(const std::shared_ptr& actions, + const std::vector>& menus); private: static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 5821e33..a95be10 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -70,7 +70,7 @@ private: class MenuFactory { public: - MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); + MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); private: -- cgit v1.2.3 From 197309468247c893bdaa37ef47a98db695b2ea78 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:44:12 -0600 Subject: following on the review comment covered in the last commit, use shared_ptr instead of shared_ptr where possible. --- include/datetime/clock.h | 2 +- include/datetime/formatter.h | 8 ++++---- include/datetime/locations-settings.h | 8 ++++---- include/datetime/menu.h | 4 ++-- include/datetime/timezones-live.h | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/clock.h b/include/datetime/clock.h index b3e3538..4a9db8f 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -79,7 +79,7 @@ class Timezones; class LiveClock: public Clock { public: - LiveClock (const std::shared_ptr& zones); + LiveClock (const std::shared_ptr& zones); virtual ~LiveClock(); virtual DateTime localtime() const; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index 3de109e..f323858 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -86,7 +86,7 @@ public: std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; protected: - Formatter(const std::shared_ptr&); + Formatter(const std::shared_ptr&); virtual ~Formatter(); static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); @@ -107,10 +107,10 @@ private: class DesktopFormatter: public Formatter { public: - DesktopFormatter(const std::shared_ptr&, const std::shared_ptr&); + DesktopFormatter(const std::shared_ptr&, const std::shared_ptr&); private: - std::shared_ptr m_settings; + std::shared_ptr m_settings; void rebuildHeaderFormat(); const gchar* getFullTimeFormatString() const; @@ -126,7 +126,7 @@ private: class PhoneFormatter: public Formatter { public: - PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { + PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); } }; diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h index d01cbb5..8757f43 100644 --- a/include/datetime/locations-settings.h +++ b/include/datetime/locations-settings.h @@ -39,12 +39,12 @@ public: * @param[in] settings the #Settings whose locations property is to be used * @param[in] timezones the #Timezones to always show first in the list */ - SettingsLocations (const std::shared_ptr& settings, - const std::shared_ptr& timezones); + SettingsLocations (const std::shared_ptr& settings, + const std::shared_ptr& timezones); private: - std::shared_ptr m_settings; - std::shared_ptr m_timezones; + std::shared_ptr m_settings; + std::shared_ptr m_timezones; void reload(); }; diff --git a/include/datetime/menu.h b/include/datetime/menu.h index a95be10..7b351c3 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -70,12 +70,12 @@ private: class MenuFactory { public: - MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); + MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); private: std::shared_ptr m_actions; - std::shared_ptr m_state; + std::shared_ptr m_state; }; } // namespace datetime diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h index 286c967..ca4ef31 100644 --- a/include/datetime/timezones-live.h +++ b/include/datetime/timezones-live.h @@ -38,14 +38,14 @@ namespace datetime { class LiveTimezones: public Timezones { public: - LiveTimezones(std::shared_ptr& settings, const std::string& filename); + LiveTimezones(const std::shared_ptr& settings, const std::string& filename); private: void update_geolocation(); void update_timezones(); FileTimezone m_file; - std::shared_ptr m_settings; + std::shared_ptr m_settings; std::shared_ptr m_geo; }; -- cgit v1.2.3 From a7a09a5ca5012fb1c48f259d2587542316e7349b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 18:33:14 -0600 Subject: copyediting: as per review, use name_of_thing() instead of get_name_of_thing() or getNameOfThing() --- include/datetime/clock-mock.h | 4 ++-- include/datetime/clock.h | 10 +++++----- include/datetime/formatter.h | 12 ++++++------ include/datetime/planner.h | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 27926ff..fb9b52f 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -45,9 +45,9 @@ public: const auto old = m_localtime; m_localtime = dt; if (!DateTime::is_same_minute(old, m_localtime)) - minuteChanged(); + minute_changed(); if (!DateTime::is_same_day(old, m_localtime)) - dateChanged(); + date_changed(); } private: diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 4a9db8f..1d488d1 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -43,20 +43,20 @@ public: virtual DateTime localtime() const =0; /** \brief A signal which fires when the clock's minute changes */ - core::Signal<> minuteChanged; + core::Signal<> minute_changed; /** \brief A signal which fires when the clock's date changes */ - core::Signal<> dateChanged; + core::Signal<> date_changed; protected: Clock(); - /** \brief Compares old and new times, emits minuteChanged() or dateChanged() signals if appropriate */ + /** \brief Compares old and new times, emits minute_changed() or date_changed() signals if appropriate */ void maybe_emit (const DateTime& a, const DateTime& b); private: - static void onSystemBusReady(GObject*, GAsyncResult*, gpointer); - static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); + static void on_system_bus_ready(GObject*, GAsyncResult*, gpointer); + static void on_prepare_for_sleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index f323858..0d695e2 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -69,27 +69,27 @@ class Formatter public: /** \brief The time format string for the menu header */ - core::Property headerFormat; + core::Property header_format; - /** \brief The time string for the menu header. (eg, the headerFormat + the clock's time */ + /** \brief The time string for the menu header. (eg, the header_format + the clock's time */ core::Property header; /** \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 (ie, the Appointments and Locations menuitems) */ - core::Signal<> relativeFormatChanged; + core::Signal<> relative_format_changed; /** \brief Generate a relative time format for some time (or time range) from the current clock's value. For example, a full-day interval starting at the end of the current clock's day yields "Tomorrow" */ - std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; + std::string relative_format(GDateTime* then, GDateTime* then_end=nullptr) const; protected: Formatter(const std::shared_ptr&); virtual ~Formatter(); - static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); + static const char* default_header_time_format(bool twelvehour, bool show_seconds); private: @@ -127,7 +127,7 @@ class PhoneFormatter: public Formatter { public: PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { - headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); + header_format.set(default_header_time_format(is_locale_12h(), false)); } }; diff --git a/include/datetime/planner.h b/include/datetime/planner.h index a8f9941..376a31f 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -43,9 +43,9 @@ public: virtual ~Planner() =default; /** - * \brief Timestamp used to determine the appointments in the `upcoming' and `thisMonth' properties. + * \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 `thisMonth' properties. + * update the `upcoming' and `this_month' properties. */ core::Property time; @@ -57,7 +57,7 @@ public: /** * \brief The appointments that occur in the same month as the time property */ - core::Property> thisMonth; + core::Property> this_month; protected: Planner() =default; -- cgit v1.2.3