diff options
Diffstat (limited to 'include/datetime')
26 files changed, 1675 insertions, 0 deletions
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/actions-live.h b/include/datetime/actions-live.h new file mode 100644 index 0000000..949222d --- /dev/null +++ b/include/datetime/actions-live.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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_ACTIONS_LIVE_H +#define INDICATOR_DATETIME_ACTIONS_LIVE_H + +#include <datetime/actions.h> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Production implementation of the Actions interface. + * + * Delegates URLs, sets the timezone via org.freedesktop.timedate1, etc. + * + * @see MockActions + */ +class LiveActions: public Actions +{ +public: + LiveActions(const std::shared_ptr<State>& state_in): Actions(state_in) {} + ~LiveActions() =default; + + void open_desktop_settings(); + void open_phone_settings(); + void open_phone_clock_app(); + void open_planner(); + void open_planner_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&); + +protected: + virtual void execute_command(const std::string& command); + virtual void dispatch_url(const std::string& url); +}; + +} // 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..3686b95 --- /dev/null +++ b/include/datetime/actions.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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_ACTIONS_H +#define INDICATOR_DATETIME_ACTIONS_H + +#include <datetime/date-time.h> +#include <datetime/state.h> + +#include <memory> // shared_ptr +#include <string> + +#include <gio/gio.h> // GSimpleActionGroup + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \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 +{ +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; + void set_calendar_date(const DateTime&); + GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } + std::shared_ptr<State> state() { return m_state; } + +protected: + Actions(const std::shared_ptr<State>& state); + virtual ~Actions(); + +private: + std::shared_ptr<State> m_state; + GSimpleActionGroup* m_actions = nullptr; + void update_calendar_state(); + + // 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 new file mode 100644 index 0000000..e034c08 --- /dev/null +++ b/include/datetime/appointment.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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_APPOINTMENT_H +#define INDICATOR_DATETIME_APPOINTMENT_H + +#include <datetime/date-time.h> +#include <string> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Plain Old Data Structure that represents a calendar appointment. + * + * @see Planner + */ +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/clock-mock.h b/include/datetime/clock-mock.h new file mode 100644 index 0000000..27926ff --- /dev/null +++ b/include/datetime/clock-mock.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_CLOCK_MOCK_H +#define INDICATOR_DATETIME_CLOCK_MOCK_H + +#include <datetime/clock.h> + +namespace unity { +namespace indicator { +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; + + DateTime localtime() const { return m_localtime; } + + void set_localtime(const DateTime& dt) { + const auto old = m_localtime; + m_localtime = dt; + if (!DateTime::is_same_minute(old, m_localtime)) + minuteChanged(); + if (!DateTime::is_same_day(old, m_localtime)) + dateChanged(); + } + +private: + DateTime m_localtime; +}; + +} // 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..b3e3538 --- /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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_CLOCK_H +#define INDICATOR_DATETIME_CLOCK_H + +#include <datetime/date-time.h> + +#include <core/property.h> +#include <core/signal.h> + +#include <gio/gio.h> // GDBusConnection + +#include <memory> // std::shared_ptr, std::unique_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A clock. + */ +class Clock +{ +public: + virtual ~Clock(); + virtual DateTime localtime() const =0; + + /** \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); + + GCancellable * m_cancellable = nullptr; + GDBusConnection * m_system_bus = nullptr; + unsigned int m_sleep_subscription_id = 0; + + // we've got raw pointers and GSignal tags in here, so disable copying + Clock(const Clock&) =delete; + Clock& operator=(const Clock&) =delete; +}; + +/*** +**** +***/ + +class Timezones; + +/** + * \brief A live #Clock that provides the actual system time. + */ +class LiveClock: public Clock +{ +public: + LiveClock (const std::shared_ptr<Timezones>& zones); + virtual ~LiveClock(); + virtual DateTime localtime() const; + +private: + class Impl; + std::unique_ptr<Impl> p; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_H diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h new file mode 100644 index 0000000..c2429eb --- /dev/null +++ b/include/datetime/date-time.h @@ -0,0 +1,68 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_DATETIME_H +#define INDICATOR_DATETIME_DATETIME_H + +#include <glib.h> // GDateTime + +#include <ctime> // time_t +#include <memory> // std::shared_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A simple C++ wrapper for GDateTime to simplify ownership/refcounts + */ +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; } + 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; + + 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<GDateTime> m_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..c5ff6ab --- /dev/null +++ b/include/datetime/dbus-shared.h @@ -0,0 +1,25 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Ted Gould <ted@canonical.com> + * Charles Kerr <charles.kerr@canonical.com> + */ + + +#define BUS_NAME "com.canonical.indicator.datetime" + +#define BUS_PATH "/com/canonical/indicator/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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_EXPORTER_H +#define INDICATOR_DATETIME_EXPORTER_H + +#include <datetime/actions.h> +#include <datetime/menu.h> + +#include <core/signal.h> + +#include <gio/gio.h> // GActionGroup + +#include <memory> // std::shared_ptr +#include <vector> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Exports actions and menus to DBus. + */ +class Exporter +{ +public: + Exporter() =default; + ~Exporter(); + + core::Signal<> name_lost; + + void publish(std::shared_ptr<Actions>& actions, + std::vector<std::shared_ptr<Menu>>& menus); + +private: + static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis); + void on_bus_acquired(GDBusConnection*, const gchar *name); + + static void on_name_lost(GDBusConnection*, const gchar *name, gpointer gthis); + void on_name_lost(GDBusConnection*, const gchar *name); + + std::set<guint> m_exported_menu_ids; + guint m_own_id = 0; + guint m_exported_actions_id = 0; + GDBusConnection * m_dbus_connection = nullptr; + std::shared_ptr<Actions> m_actions; + std::vector<std::shared_ptr<Menu>> 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/formatter.h b/include/datetime/formatter.h new file mode 100644 index 0000000..86fa64a --- /dev/null +++ b/include/datetime/formatter.h @@ -0,0 +1,145 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_FORMATTER_H +#define INDICATOR_DATETIME_FORMATTER_H + +#include <core/property.h> +#include <core/signal.h> + +#include <datetime/clock.h> +#include <datetime/settings.h> + +#include <glib.h> + +#include <string> +#include <memory> + +namespace unity { +namespace indicator { +namespace datetime { + +class Clock; +class DateTime; + +/*** +**** +***/ + +/** + * \brief Provide the strftime() format strings + * + * 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. + * + * - 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 +{ +public: + + /** \brief The time format string for the menu header */ + core::Property<std::string> headerFormat; + + /** \brief The time string for the menu header. (eg, the headerFormat + the clock's time */ + core::Property<std::string> 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; + + /** \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<Clock>&); + virtual ~Formatter(); + + /** \brief Returns true if the current locale prefers 12h display instead of 24h */ + static bool is_locale_12h(); + + static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); + + /** \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<Impl> p; +}; + + +/** + * \brief A Formatter for the Desktop and DesktopGreeter profiles. + */ +class DesktopFormatter: public Formatter +{ +public: + DesktopFormatter(const std::shared_ptr<Clock>&, const std::shared_ptr<Settings>&); + +private: + std::shared_ptr<Settings> 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; + +}; + + +/** + * \brief A Formatter for Phone and PhoneGreeter profiles. + */ +class PhoneFormatter: public Formatter +{ +public: + PhoneFormatter(const std::shared_ptr<Clock>& clock): Formatter(clock) { + headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); + } +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_CLOCK_H diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h new file mode 100644 index 0000000..d01cbb5 --- /dev/null +++ b/include/datetime/locations-settings.h @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_LOCATIONS_H +#define INDICATOR_DATETIME_SETTINGS_LOCATIONS_H + +#include <datetime/locations.h> // base class + +#include <datetime/settings.h> +#include <datetime/timezones.h> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief #Locations implementation which builds its list from the #Settings. + */ +class SettingsLocations: public Locations +{ +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>& settings, + const std::shared_ptr<Timezones>& timezones); + +private: + std::shared_ptr<Settings> m_settings; + std::shared_ptr<Timezones> m_timezones; + 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..ee67615 --- /dev/null +++ b/include/datetime/locations.h @@ -0,0 +1,87 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_LOCATIONS_H +#define INDICATOR_DATETIME_LOCATIONS_H + +#include <datetime/date-time.h> + +#include <core/property.h> + +#include <string> +#include <vector> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A physical place and its timezone; eg, "America/Chicago" + "Oklahoma City" + * + * @see Locations + */ +class Location +{ +public: + const std::string& zone() const { return m_zone; } + + const std::string& name() const { return m_name; } + + 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); + +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; +}; + +/** + * Container which holds an ordered list of Locations + * + * @see Location + * @see State + */ +class Locations +{ +public: + Locations() =default; + virtual ~Locations() =default; + + /** \brief an ordered list of Location items */ + core::Property<std::vector<Location>> locations; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_LOCATIONS_H diff --git a/include/datetime/menu.h b/include/datetime/menu.h new file mode 100644 index 0000000..fcd709f --- /dev/null +++ b/include/datetime/menu.h @@ -0,0 +1,86 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_MENU_H +#define INDICATOR_DATETIME_MENU_H + +#include <datetime/actions.h> +#include <datetime/state.h> + +#include <memory> // std::shared_ptr +#include <vector> + +#include <gio/gio.h> // GMenuModel + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief A menu for a specific profile; eg, Desktop or Phone. + * + * @see MenuFactory + * @see Exporter + */ +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 + * + * @see Menu + * @see Exporter + */ +class MenuFactory +{ +public: + MenuFactory (std::shared_ptr<Actions>& actions, std::shared_ptr<State>& state); + std::shared_ptr<Menu> buildMenu(Menu::Profile profile); + std::shared_ptr<State> state() { return m_state; } + +private: + std::shared_ptr<Actions> m_actions; + std::shared_ptr<State> m_state; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_MENU_H diff --git a/include/datetime/planner-eds.h b/include/datetime/planner-eds.h new file mode 100644 index 0000000..f3abce0 --- /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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_PLANNER_EDS_H +#define INDICATOR_DATETIME_PLANNER_EDS_H + +#include <datetime/planner.h> + +#include <memory> // 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> p; +}; + +} // 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..a8f9941 --- /dev/null +++ b/include/datetime/planner.h @@ -0,0 +1,76 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_PLANNER_H +#define INDICATOR_DATETIME_PLANNER_H + +#include <datetime/appointment.h> +#include <datetime/date-time.h> + +#include <core/property.h> + +#include <vector> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Simple appointment book + * + * @see EdsPlanner + * @see State + */ +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<DateTime> time; + + /** + * \brief The next few appointments that follow the time specified in the time property. + */ + core::Property<std::vector<Appointment>> upcoming; + + /** + * \brief The appointments that occur in the same month as the time property + */ + core::Property<std::vector<Appointment>> thisMonth; + +protected: + Planner() =default; + +private: + + // disable copying + Planner(const Planner&) =delete; + Planner& operator=(const Planner&) =delete; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_PLANNER_H diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h new file mode 100644 index 0000000..202c998 --- /dev/null +++ b/include/datetime/settings-live.h @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_LIVE_H +#define INDICATOR_DATETIME_SETTINGS_LIVE_H + +#include <datetime/settings.h> // parent class + +#include <gio/gio.h> // GSettings + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief #Settings implementation which uses GSettings. + */ +class LiveSettings: public Settings +{ +public: + LiveSettings(); + virtual ~LiveSettings(); + +private: + 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; + + // 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 new file mode 100644 index 0000000..17a8ef0 --- /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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Ted Gould <ted@canonical.com> + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_SHARED +#define INDICATOR_DATETIME_SETTINGS_SHARED + +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 // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h new file mode 100644 index 0000000..ce234d9 --- /dev/null +++ b/include/datetime/settings.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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_SETTINGS_H +#define INDICATOR_DATETIME_SETTINGS_H + +#include <datetime/settings-shared.h> + +#include <core/property.h> + +#include <vector> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Interface that represents user-configurable settings. + * + * See the descriptions in data/com.canonical.indicator.datetime.gschema.xml + * for more information on specific properties. + */ +class Settings +{ +public: + Settings() =default; + virtual ~Settings() =default; + + core::Property<std::string> custom_time_format; + core::Property<std::vector<std::string>> locations; + core::Property<bool> show_calendar; + core::Property<bool> show_clock; + core::Property<bool> show_date; + core::Property<bool> show_day; + core::Property<bool> show_detected_location; + core::Property<bool> show_events; + core::Property<bool> show_locations; + core::Property<bool> show_seconds; + core::Property<bool> show_week_numbers; + core::Property<bool> show_year; + core::Property<TimeFormatMode> time_format_mode; + core::Property<std::string> timezone_name; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_SETTINGS_H 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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_STATE_LIVE_H +#define INDICATOR_DATETIME_STATE_LIVE_H + +#include <datetime/state.h> + +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 diff --git a/include/datetime/state.h b/include/datetime/state.h new file mode 100644 index 0000000..414be32 --- /dev/null +++ b/include/datetime/state.h @@ -0,0 +1,75 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_STATE_H +#define INDICATOR_DATETIME_STATE_H + +#include <datetime/clock.h> +#include <datetime/locations.h> +#include <datetime/planner.h> +#include <datetime/settings.h> +#include <datetime/timezones.h> + +#include <core/property.h> + +#include <memory> // std::shared_ptr + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Aggregates all the classes that represent the backend state. + * + * This is where the app comes together. It's a model that aggregates + * all of the backend appointments/alarms, locations, timezones, + * system time, and so on. The "view" code (ie, the Menus) need to + * respond to Signals from the State and update themselves accordingly. + * + * @see Menu + * @see MenuFactory + * @see Timezones + * @see Clock + * @see Planner + * @see Locations + * @see Settings + */ +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> clock; + + /** \brief The locations to be displayed in the Locations + section of the #Menu */ + std::shared_ptr<Locations> locations; + + /** \brief The appointments to be displayed in the Calendar and + Appointments sections of the #Menu */ + std::shared_ptr<Planner> planner; + + /** \brief Configuration options that modify the view */ + std::shared_ptr<Settings> settings; +}; + +} // 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 new file mode 100644 index 0000000..7f47df6 --- /dev/null +++ b/include/datetime/timezone-file.h @@ -0,0 +1,63 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_FILE_TIMEZONE_H +#define INDICATOR_DATETIME_FILE_TIMEZONE_H + +#include <datetime/timezone.h> // base class + +#include <string> // std::string + +#include <glib.h> +#include <gio/gio.h> + +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); + static void onFileChanged(gpointer gself); + void clear(); + void reload(); + + 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 +} // namespace unity + +#endif // INDICATOR_DATETIME_FILE_TIMEZONE_H diff --git a/include/datetime/timezone-geoclue.h b/include/datetime/timezone-geoclue.h new file mode 100644 index 0000000..4a5b726 --- /dev/null +++ b/include/datetime/timezone-geoclue.h @@ -0,0 +1,69 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H +#define INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H + +#include <datetime/timezone.h> // base class + +#include <string> + +#include <glib.h> +#include <gio/gio.h> + +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 * 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; +}; + + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_GEOCLUE_TIMEZONE_H + diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h new file mode 100644 index 0000000..ffa5a84 --- /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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_TIMEZONE_H +#define INDICATOR_DATETIME_TIMEZONE_H + +#include <core/property.h> + +#include <string> + +namespace unity { +namespace indicator { +namespace datetime { + +/** \brief Base a timezone, such as "America/Chicago". */ +class Timezone +{ +protected: + Timezone() =default; + +public: + //virtual ~Timezone() {} + core::Property<std::string> timezone; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_TIMEZONE_H diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h new file mode 100644 index 0000000..286c967 --- /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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_LIVE_TIMEZONES_H +#define INDICATOR_DATETIME_LIVE_TIMEZONES_H + +#include <datetime/settings.h> +#include <datetime/timezones.h> +#include <datetime/timezone-file.h> +#include <datetime/timezone-geoclue.h> + +#include <memory> // 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(std::shared_ptr<Settings>& settings, const std::string& filename); + +private: + void update_geolocation(); + void update_timezones(); + + FileTimezone m_file; + std::shared_ptr<Settings> m_settings; + std::shared_ptr<GeoclueTimezone> m_geo; +}; + +} // 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..d2842af --- /dev/null +++ b/include/datetime/timezones.h @@ -0,0 +1,59 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#ifndef INDICATOR_DATETIME_TIMEZONES_H +#define INDICATOR_DATETIME_TIMEZONES_H + +#include <datetime/timezone.h> + +#include <core/property.h> + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Helper class which aggregates one or more timezones + * + * @see LiveClock + * @see SettingsLocations + */ +class Timezones +{ +public: + Timezones() =default; + virtual ~Timezones() =default; + + /** + * \brief the current timezone + */ + core::Property<std::string> timezone; + + /** + * \brief all the detected timezones. + * The count is >1 iff the detection mechamisms disagree. + */ + core::Property<std::set<std::string> > 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..10e881f --- /dev/null +++ b/include/datetime/utils.h @@ -0,0 +1,48 @@ +/* -*- 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 <michael.terry@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef INDICATOR_DATETIME_UTILS_H +#define INDICATOR_DATETIME_UTILS_H + +#include <glib.h> +#include <gio/gio.h> /* GSettings */ + +G_BEGIN_DECLS + +gboolean is_locale_12h (void); + +void split_settings_location (const char * location, + char ** zone, + char ** name); + +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); + +G_END_DECLS + +#endif /* INDICATOR_DATETIME_UTILS_H */ |