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 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