From 76422d4997401b8f278b7316a23a324655c12c92 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 May 2013 14:57:00 -0700 Subject: rename the 'DatetimeLocation' classes to the more accurate name 'DatetimeTimezone' --- src/Makefile.am | 12 +-- src/datetime-service.c | 18 ++-- src/location-file.c | 235 -------------------------------------------- src/location-file.h | 61 ------------ src/location-geoclue.c | 261 ------------------------------------------------- src/location-geoclue.h | 61 ------------ src/location.c | 108 -------------------- src/location.h | 68 ------------- src/timezone-file.c | 235 ++++++++++++++++++++++++++++++++++++++++++++ src/timezone-file.h | 61 ++++++++++++ src/timezone-geoclue.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++ src/timezone-geoclue.h | 61 ++++++++++++ src/timezone.c | 108 ++++++++++++++++++++ src/timezone.h | 68 +++++++++++++ 14 files changed, 809 insertions(+), 809 deletions(-) delete mode 100644 src/location-file.c delete mode 100644 src/location-file.h delete mode 100644 src/location-geoclue.c delete mode 100644 src/location-geoclue.h delete mode 100644 src/location.c delete mode 100644 src/location.h create mode 100644 src/timezone-file.c create mode 100644 src/timezone-file.h create mode 100644 src/timezone-geoclue.c create mode 100644 src/timezone-geoclue.h create mode 100644 src/timezone.c create mode 100644 src/timezone.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 2efff8f..67b085a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,12 +11,12 @@ indicator_datetime_service_SOURCES = \ datetime-interface.h \ gen-datetime-service.xml.c \ datetime-service.c \ - location.c \ - location.h \ - location-file.c \ - location-file.h \ - location-geoclue.c \ - location-geoclue.h \ + timezone.c \ + timezone.h \ + timezone-file.c \ + timezone-file.h \ + timezone-geoclue.c \ + timezone-geoclue.h \ utils.c \ utils.h \ dbus-shared.h \ diff --git a/src/datetime-service.c b/src/datetime-service.c index 35a5e53..0551068 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -45,9 +45,9 @@ with this program. If not, see . #include "datetime-interface.h" #include "dbus-shared.h" -#include "location-file.h" -#include "location-geoclue.h" #include "settings-shared.h" +#include "timezone-file.h" +#include "timezone-geoclue.h" #include "utils.h" /* how often to check for clock skew */ @@ -91,8 +91,8 @@ static time_t start_time_appointments = (time_t) 0; static GSettings * conf = NULL; static ESourceRegistry * source_registry = NULL; static GList * appointment_sources = NULL; -static IndicatorDatetimeLocation * geo_location = NULL; -static IndicatorDatetimeLocation * tz_file = NULL; +static IndicatorDatetimeTimezone * geo_location = NULL; +static IndicatorDatetimeTimezone * tz_file = NULL; struct comp_instance { ECalComponent *comp; @@ -184,7 +184,7 @@ update_location_menu_items (void) /* maybe add geo_timezone */ if (geo_location != NULL) { - const char * geo_timezone = indicator_datetime_location_get_timezone (geo_location); + const char * geo_timezone = indicator_datetime_timezone_get_timezone (geo_location); if (geo_timezone && *geo_timezone) { const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (geo_timezone); @@ -195,7 +195,7 @@ update_location_menu_items (void) /* maybe add current_timezone */ if (tz_file != NULL) { - const char * tz = indicator_datetime_location_get_timezone (tz_file); + const char * tz = indicator_datetime_timezone_get_timezone (tz_file); if (tz && *tz) { const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (tz); @@ -704,7 +704,7 @@ update_appointment_menu_items (gpointer user_data __attribute__ ((unused))) g_list_free_full (comp_instances, (GDestroyNotify)comp_instance_free); comp_instances = NULL; - current_timezone = indicator_datetime_location_get_timezone (tz_file); + current_timezone = indicator_datetime_timezone_get_timezone (tz_file); // Generate instances for all sources for (s=appointment_sources; s!=NULL; s=s->next) { @@ -1233,7 +1233,7 @@ on_use_geoclue_changed_cb (GSettings *settings, } else if (use_geoclue && !geo_location) { - geo_location = indicator_datetime_location_geoclue_new (); + geo_location = indicator_datetime_timezone_geoclue_new (); g_signal_connect (geo_location, "notify::timezone", G_CALLBACK(update_location_menu_items), NULL); } @@ -1291,7 +1291,7 @@ main (int argc, char ** argv) dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL); /* Setup timezone watch */ - tz_file = indicator_datetime_location_file_new (TIMEZONE_FILE); + tz_file = indicator_datetime_timezone_file_new (TIMEZONE_FILE); g_signal_connect (tz_file, "notify::timezone", G_CALLBACK(on_timezone_changed), NULL); /* Set up the day timer */ diff --git a/src/location-file.c b/src/location-file.c deleted file mode 100644 index ff6fd47..0000000 --- a/src/location-file.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 . - */ - -#include "config.h" - -#include -#include -#include - -#include "location-file.h" - -enum -{ - PROP_0, - PROP_FILENAME, - PROP_LAST -}; - -static GParamSpec * properties[PROP_LAST] = { 0 }; - -struct _IndicatorDatetimeLocationFilePriv -{ - gchar * filename; - GFile * file; - GFileMonitor * monitor; - gchar * timezone; -}; - -typedef IndicatorDatetimeLocationFilePriv priv_t; - -G_DEFINE_TYPE (IndicatorDatetimeLocationFile, - indicator_datetime_location_file, - INDICATOR_TYPE_DATETIME_LOCATION) - -/*** -**** -***/ - -static void -reload (IndicatorDatetimeLocationFile * self) -{ - priv_t * p = self->priv; - - GError * err = NULL; - gchar * new_timezone = NULL; - - if (!g_file_get_contents (p->filename, &new_timezone, NULL, &err)) - { - g_warning ("Unable to read timezone file '%s': %s", p->filename, err->message); - g_error_free (err); - } - else - { - g_strstrip (new_timezone); - g_free (p->timezone); - p->timezone = new_timezone; - indicator_datetime_location_notify_timezone (INDICATOR_DATETIME_LOCATION(self)); - } -} - -static void -set_filename (IndicatorDatetimeLocationFile * self, const char * filename) -{ - GError * err; - priv_t * p = self->priv; - - g_clear_object (&p->monitor); - g_clear_object (&p->file); - g_free (p->filename); - - p->filename = g_strdup (filename); - p->file = g_file_new_for_path (p->filename); - - err = NULL; - p->monitor = g_file_monitor_file (p->file, G_FILE_MONITOR_NONE, NULL, &err); - if (err != NULL) - { - g_warning ("Unable to monitor timezone file '%s': %s", TIMEZONE_FILE, err->message); - g_error_free (err); - } - else - { - g_signal_connect_swapped (p->monitor, "changed", G_CALLBACK(reload), self); - g_debug ("Monitoring timezone file '%s'", p->filename); - } - - reload (self); -} - -/*** -**** IndicatorDatetimeLocationClass funcs -***/ - -static const char * -my_get_timezone (IndicatorDatetimeLocation * self) -{ - return INDICATOR_DATETIME_LOCATION_FILE(self)->priv->timezone; -} - -/*** -**** GObjectClass funcs -***/ - -static void -my_get_property (GObject * o, - guint property_id, - GValue * value, - GParamSpec * pspec) -{ - IndicatorDatetimeLocationFile * self = INDICATOR_DATETIME_LOCATION_FILE (o); - - switch (property_id) - { - case PROP_FILENAME: - g_value_set_string (value, self->priv->filename); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - } -} - -static void -my_set_property (GObject * o, - guint property_id, - const GValue * value, - GParamSpec * pspec) -{ - IndicatorDatetimeLocationFile * self = INDICATOR_DATETIME_LOCATION_FILE (o); - - switch (property_id) - { - case PROP_FILENAME: - set_filename (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - } -} - -static void -my_dispose (GObject * o) -{ - IndicatorDatetimeLocationFile * self = INDICATOR_DATETIME_LOCATION_FILE (o); - priv_t * p = self->priv; - - g_clear_object (&p->monitor); - g_clear_object (&p->file); - - G_OBJECT_CLASS (indicator_datetime_location_file_parent_class)->dispose (o); -} - -static void -my_finalize (GObject * o) -{ - IndicatorDatetimeLocationFile * self = INDICATOR_DATETIME_LOCATION_FILE (o); - priv_t * p = self->priv; - - g_free (p->filename); - g_free (p->timezone); - - G_OBJECT_CLASS (indicator_datetime_location_file_parent_class)->finalize (o); -} - -/*** -**** -***/ - -static void -indicator_datetime_location_file_class_init (IndicatorDatetimeLocationFileClass * klass) -{ - GObjectClass * object_class; - IndicatorDatetimeLocationClass * location_class; - const GParamFlags flags = G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS; - - object_class = G_OBJECT_CLASS (klass); - object_class->dispose = my_dispose; - object_class->finalize = my_finalize; - object_class->set_property = my_set_property; - object_class->get_property = my_get_property; - - location_class = INDICATOR_DATETIME_LOCATION_CLASS (klass); - location_class->get_timezone = my_get_timezone; - - g_type_class_add_private (klass, sizeof (IndicatorDatetimeLocationFilePriv)); - - /* install properties */ - - properties[PROP_0] = NULL; - - properties[PROP_FILENAME] = g_param_spec_string ("filename", - "Filename", - "Filename to monitor for TZ changes", - "", - flags); - - g_object_class_install_properties (object_class, PROP_LAST, properties); -} - -static void -indicator_datetime_location_file_init (IndicatorDatetimeLocationFile * self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - INDICATOR_TYPE_DATETIME_LOCATION_FILE, - IndicatorDatetimeLocationFilePriv); -} - -/*** -**** Public -***/ - -IndicatorDatetimeLocation * -indicator_datetime_location_file_new (const char * filename) -{ - gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_LOCATION_FILE, "filename", filename, NULL); - - return INDICATOR_DATETIME_LOCATION (o); -} diff --git a/src/location-file.h b/src/location-file.h deleted file mode 100644 index 8ed87ad..0000000 --- a/src/location-file.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 __INDICATOR_DATETIME_LOCATION_FILE__H__ -#define __INDICATOR_DATETIME_LOCATION_FILE__H__ - -#include -#include - -#include "location.h" /* parent class */ - -G_BEGIN_DECLS - -#define INDICATOR_TYPE_DATETIME_LOCATION_FILE (indicator_datetime_location_file_get_type()) -#define INDICATOR_DATETIME_LOCATION_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_LOCATION_FILE, IndicatorDatetimeLocationFile)) -#define INDICATOR_DATETIME_LOCATION_FILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_LOCATION_FILE, IndicatorDatetimeLocationFileClass)) -#define INDICATOR_IS_DATETIME_LOCATION_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_LOCATION_FILE)) - -typedef struct _IndicatorDatetimeLocationFile IndicatorDatetimeLocationFile; -typedef struct _IndicatorDatetimeLocationFilePriv IndicatorDatetimeLocationFilePriv; -typedef struct _IndicatorDatetimeLocationFileClass IndicatorDatetimeLocationFileClass; - -GType indicator_datetime_location_file_get_type (void); - -/** - * An implementation of IndicatorDatetimeLocation which determines the timezone - * from monitoring a local file, such as /etc/timezone - */ -struct _IndicatorDatetimeLocationFile -{ - /*< private >*/ - IndicatorDatetimeLocation parent; - IndicatorDatetimeLocationFilePriv * priv; -}; - -struct _IndicatorDatetimeLocationFileClass -{ - IndicatorDatetimeLocationClass parent_class; -}; - -IndicatorDatetimeLocation * indicator_datetime_location_file_new (const char * filename); - -G_END_DECLS - -#endif /* __INDICATOR_DATETIME_LOCATION_FILE__H__ */ diff --git a/src/location-geoclue.c b/src/location-geoclue.c deleted file mode 100644 index 87358fb..0000000 --- a/src/location-geoclue.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 . - */ - -#include "config.h" - -#include -#include - -#include -#include - -#include "location-geoclue.h" - -struct _IndicatorDatetimeLocationGeocluePriv -{ - GeoclueMaster * master; - GeoclueMasterClient * client; - GeoclueAddress * address; - gchar * timezone; -}; - -typedef IndicatorDatetimeLocationGeocluePriv priv_t; - -G_DEFINE_TYPE (IndicatorDatetimeLocationGeoclue, - indicator_datetime_location_geoclue, - INDICATOR_TYPE_DATETIME_LOCATION) - -static void geo_restart (IndicatorDatetimeLocationGeoclue * self); - -/*** -**** -***/ - -static void -set_timezone (IndicatorDatetimeLocationGeoclue * self, const gchar * timezone) -{ - priv_t * p = self->priv; - - if (g_strcmp0 (p->timezone, timezone)) - { - g_free (p->timezone); - p->timezone = g_strdup (timezone); - indicator_datetime_location_notify_timezone (INDICATOR_DATETIME_LOCATION(self)); - } -} - -static void -on_address_changed (GeoclueAddress * address, - int timestamp, - GHashTable * addy_data, - GeoclueAccuracy * accuracy, - GError * error, - gpointer gself) -{ - if (error != NULL) - { - g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); - g_error_free (error); - } - else - { - IndicatorDatetimeLocationGeoclue * self = INDICATOR_DATETIME_LOCATION_GEOCLUE (gself); - const char * timezone = g_hash_table_lookup (addy_data, "timezone"); - set_timezone (self, timezone); - } -} - -static void -on_address_created (GeoclueMasterClient * master, - GeoclueAddress * address, - GError * error, - gpointer gself) -{ - if (error != NULL) - { - g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); - g_error_free (error); - } - else - { - priv_t * p = INDICATOR_DATETIME_LOCATION_GEOCLUE(gself)->priv; - - g_assert (p->address == NULL); - p->address = g_object_ref (address); - - geoclue_address_get_address_async (address, on_address_changed, gself); - g_signal_connect (address, "address-changed", G_CALLBACK(on_address_changed), gself); - } -} - -static void -on_requirements_set (GeoclueMasterClient * master, GError * error, gpointer user_data) -{ - if (error != NULL) - { - g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); - g_error_free (error); - } -} - -static void -on_client_created (GeoclueMaster * master, - GeoclueMasterClient * client, - gchar * path, - GError * error, - gpointer gself) -{ - g_debug ("Created Geoclue client at: %s", path); - - if (error != NULL) - { - g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); - g_error_free (error); - } - else if (client == NULL) - { - g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); - } - else - { - IndicatorDatetimeLocationGeoclue * self = INDICATOR_DATETIME_LOCATION_GEOCLUE (gself); - priv_t * p = self->priv; - - g_clear_object (&p->client); - p->client = g_object_ref (client); - g_signal_connect_swapped (p->client, "invalidated", G_CALLBACK(geo_restart), gself); - - geoclue_master_client_set_requirements_async (p->client, - GEOCLUE_ACCURACY_LEVEL_REGION, - 0, - FALSE, - GEOCLUE_RESOURCE_ALL, - on_requirements_set, - NULL); - - geoclue_master_client_create_address_async (p->client, on_address_created, gself); - } -} - -static void -geo_start (IndicatorDatetimeLocationGeoclue * self) -{ - priv_t * p = self->priv; - - g_assert (p->master == NULL); - p->master = geoclue_master_get_default (); - geoclue_master_create_client_async (p->master, on_client_created, self); -} - -static void -geo_stop (IndicatorDatetimeLocationGeoclue * self) -{ - priv_t * p = self->priv; - - if (p->address != NULL) - { - g_signal_handlers_disconnect_by_func (p->address, on_address_changed, self); - g_clear_object (&p->address); - } - - if (p->client != NULL) - { - g_signal_handlers_disconnect_by_func (p->client, geo_restart, self); - g_clear_object (&p->client); - } - - g_clear_object (&p->master); -} - -static void -geo_restart (IndicatorDatetimeLocationGeoclue * self) -{ - geo_stop (self); - geo_start (self); -} - -/*** -**** -***/ - -static const char * -my_get_timezone (IndicatorDatetimeLocation * self) -{ - return INDICATOR_DATETIME_LOCATION_GEOCLUE(self)->priv->timezone; -} - -static void -my_dispose (GObject * o) -{ - geo_stop (INDICATOR_DATETIME_LOCATION_GEOCLUE (o)); - - G_OBJECT_CLASS (indicator_datetime_location_geoclue_parent_class)->dispose (o); -} - -static void -my_finalize (GObject * o) -{ - IndicatorDatetimeLocationGeoclue * self = INDICATOR_DATETIME_LOCATION_GEOCLUE (o); - priv_t * p = self->priv; - - g_free (p->timezone); - - G_OBJECT_CLASS (indicator_datetime_location_geoclue_parent_class)->finalize (o); -} - -static void -indicator_datetime_location_geoclue_class_init (IndicatorDatetimeLocationGeoclueClass * klass) -{ - GObjectClass * object_class; - IndicatorDatetimeLocationClass * location_class; - - object_class = G_OBJECT_CLASS (klass); - object_class->dispose = my_dispose; - object_class->finalize = my_finalize; - - location_class = INDICATOR_DATETIME_LOCATION_CLASS (klass); - location_class->get_timezone = my_get_timezone; - - g_type_class_add_private (klass, sizeof (IndicatorDatetimeLocationGeocluePriv)); -} - -static void -indicator_datetime_location_geoclue_init (IndicatorDatetimeLocationGeoclue * self) -{ - priv_t * p; - - p = G_TYPE_INSTANCE_GET_PRIVATE (self, - INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE, - IndicatorDatetimeLocationGeocluePriv); - self->priv = p; - - geo_start (self); -} - -/*** -**** Public -***/ - -IndicatorDatetimeLocation * -indicator_datetime_location_geoclue_new (void) -{ - gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE, NULL); - - return INDICATOR_DATETIME_LOCATION (o); -} diff --git a/src/location-geoclue.h b/src/location-geoclue.h deleted file mode 100644 index 5b6d232..0000000 --- a/src/location-geoclue.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 __INDICATOR_DATETIME_LOCATION_GEOCLUE__H__ -#define __INDICATOR_DATETIME_LOCATION_GEOCLUE__H__ - -#include -#include - -#include "location.h" /* parent class */ - -G_BEGIN_DECLS - -#define INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE (indicator_datetime_location_geoclue_get_type()) -#define INDICATOR_DATETIME_LOCATION_GEOCLUE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE, IndicatorDatetimeLocationGeoclue)) -#define INDICATOR_DATETIME_LOCATION_GEOCLUE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE, IndicatorDatetimeLocationGeoclueClass)) -#define INDICATOR_IS_DATETIME_LOCATION_GEOCLUE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_LOCATION_GEOCLUE)) - -typedef struct _IndicatorDatetimeLocationGeoclue IndicatorDatetimeLocationGeoclue; -typedef struct _IndicatorDatetimeLocationGeocluePriv IndicatorDatetimeLocationGeocluePriv; -typedef struct _IndicatorDatetimeLocationGeoclueClass IndicatorDatetimeLocationGeoclueClass; - -GType indicator_datetime_location_geoclue_get_type (void); - -/** - * An implementation of IndicatorDatetimeLocation which determines the timezone - * from calling a GeoClue service over DBus. - */ -struct _IndicatorDatetimeLocationGeoclue -{ - /*< private >*/ - IndicatorDatetimeLocation parent; - IndicatorDatetimeLocationGeocluePriv * priv; -}; - -struct _IndicatorDatetimeLocationGeoclueClass -{ - IndicatorDatetimeLocationClass parent_class; -}; - -IndicatorDatetimeLocation * indicator_datetime_location_geoclue_new (void); - -G_END_DECLS - -#endif /* __INDICATOR_DATETIME_LOCATION_GEOCLUE__H__ */ diff --git a/src/location.c b/src/location.c deleted file mode 100644 index 12e25c3..0000000 --- a/src/location.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 . - */ - -#include "location.h" - -G_DEFINE_TYPE (IndicatorDatetimeLocation, - indicator_datetime_location, - G_TYPE_OBJECT) - -enum -{ - PROP_0, - PROP_TIMEZONE, - PROP_LAST -}; - -static GParamSpec * properties[PROP_LAST] = { 0 }; - -static void -my_get_property (GObject * o, - guint property_id, - GValue * value, - GParamSpec * pspec) -{ - IndicatorDatetimeLocation * self = INDICATOR_DATETIME_LOCATION (o); - - switch (property_id) - { - case PROP_TIMEZONE: - g_value_set_string (value, indicator_datetime_location_get_timezone (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - } -} - -static void -my_dispose (GObject * object) -{ - G_OBJECT_CLASS (indicator_datetime_location_parent_class)->dispose (object); -} - -static void -/* cppcheck-suppress unusedFunction */ -indicator_datetime_location_class_init (IndicatorDatetimeLocationClass * klass) -{ - GObjectClass * object_class; - const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS; - - object_class = G_OBJECT_CLASS (klass); - object_class->get_property = my_get_property; - object_class->dispose = my_dispose; - - klass->get_timezone = NULL; - - properties[PROP_0] = NULL; - - properties[PROP_TIMEZONE] = g_param_spec_string ("timezone", - "Timezone", - "Timezone", - "", - flags); - - g_object_class_install_properties (object_class, PROP_LAST, properties); -} - -static void -indicator_datetime_location_init (IndicatorDatetimeLocation * self G_GNUC_UNUSED) -{ -} - -/*** -**** -***/ - -const char * -indicator_datetime_location_get_timezone (IndicatorDatetimeLocation * self) -{ - g_return_val_if_fail (INDICATOR_IS_DATETIME_LOCATION (self), NULL); - - return INDICATOR_DATETIME_LOCATION_GET_CLASS (self)->get_timezone (self); -} - -void -indicator_datetime_location_notify_timezone (IndicatorDatetimeLocation * self) -{ - g_return_if_fail (INDICATOR_IS_DATETIME_LOCATION (self)); - - g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_TIMEZONE]); -} - diff --git a/src/location.h b/src/location.h deleted file mode 100644 index f9fd2ce..0000000 --- a/src/location.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * Authors: - * Charles Kerr - * - * 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 __INDICATOR_DATETIME_LOCATION__H__ -#define __INDICATOR_DATETIME_LOCATION__H__ - -#include -#include - -G_BEGIN_DECLS - -#define INDICATOR_TYPE_DATETIME_LOCATION (indicator_datetime_location_get_type()) -#define INDICATOR_DATETIME_LOCATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_LOCATION, IndicatorDatetimeLocation)) -#define INDICATOR_DATETIME_LOCATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_LOCATION, IndicatorDatetimeLocationClass)) -#define INDICATOR_DATETIME_LOCATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_DATETIME_LOCATION, IndicatorDatetimeLocationClass)) -#define INDICATOR_IS_DATETIME_LOCATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_LOCATION)) - -typedef struct _IndicatorDatetimeLocation IndicatorDatetimeLocation; -typedef struct _IndicatorDatetimeLocationClass IndicatorDatetimeLocationClass; - -GType indicator_datetime_location_get_type (void); - -/** - * Abstract Base Class for the mechanisms that determine timezone by location - */ -struct _IndicatorDatetimeLocation -{ - /*< private >*/ - GObject parent; -}; - -struct _IndicatorDatetimeLocationClass -{ - GObjectClass parent_class; - - /* virtual functions */ - const char * (*get_timezone) (IndicatorDatetimeLocation * self); -}; - -/*** -**** -***/ - -#define INDICATOR_DATETIME_LOCATION_PROPERTY_TIMEZONE "timezone" - -const char * indicator_datetime_location_get_timezone (IndicatorDatetimeLocation *); - -void indicator_datetime_location_notify_timezone (IndicatorDatetimeLocation *); - -G_END_DECLS - -#endif /* __INDICATOR_DATETIME_LOCATION__H__ */ diff --git a/src/timezone-file.c b/src/timezone-file.c new file mode 100644 index 0000000..c7c2cf6 --- /dev/null +++ b/src/timezone-file.c @@ -0,0 +1,235 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 . + */ + +#include "config.h" + +#include +#include +#include + +#include "timezone-file.h" + +enum +{ + PROP_0, + PROP_FILENAME, + PROP_LAST +}; + +static GParamSpec * properties[PROP_LAST] = { 0 }; + +struct _IndicatorDatetimeTimezoneFilePriv +{ + gchar * filename; + GFile * file; + GFileMonitor * monitor; + gchar * timezone; +}; + +typedef IndicatorDatetimeTimezoneFilePriv priv_t; + +G_DEFINE_TYPE (IndicatorDatetimeTimezoneFile, + indicator_datetime_timezone_file, + INDICATOR_TYPE_DATETIME_TIMEZONE) + +/*** +**** +***/ + +static void +reload (IndicatorDatetimeTimezoneFile * self) +{ + priv_t * p = self->priv; + + GError * err = NULL; + gchar * new_timezone = NULL; + + if (!g_file_get_contents (p->filename, &new_timezone, NULL, &err)) + { + g_warning ("Unable to read timezone file '%s': %s", p->filename, err->message); + g_error_free (err); + } + else + { + g_strstrip (new_timezone); + g_free (p->timezone); + p->timezone = new_timezone; + indicator_datetime_timezone_notify_timezone (INDICATOR_DATETIME_TIMEZONE(self)); + } +} + +static void +set_filename (IndicatorDatetimeTimezoneFile * self, const char * filename) +{ + GError * err; + priv_t * p = self->priv; + + g_clear_object (&p->monitor); + g_clear_object (&p->file); + g_free (p->filename); + + p->filename = g_strdup (filename); + p->file = g_file_new_for_path (p->filename); + + err = NULL; + p->monitor = g_file_monitor_file (p->file, G_FILE_MONITOR_NONE, NULL, &err); + if (err != NULL) + { + g_warning ("Unable to monitor timezone file '%s': %s", TIMEZONE_FILE, err->message); + g_error_free (err); + } + else + { + g_signal_connect_swapped (p->monitor, "changed", G_CALLBACK(reload), self); + g_debug ("Monitoring timezone file '%s'", p->filename); + } + + reload (self); +} + +/*** +**** IndicatorDatetimeTimezoneClass funcs +***/ + +static const char * +my_get_timezone (IndicatorDatetimeTimezone * self) +{ + return INDICATOR_DATETIME_TIMEZONE_FILE(self)->priv->timezone; +} + +/*** +**** GObjectClass funcs +***/ + +static void +my_get_property (GObject * o, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + IndicatorDatetimeTimezoneFile * self = INDICATOR_DATETIME_TIMEZONE_FILE (o); + + switch (property_id) + { + case PROP_FILENAME: + g_value_set_string (value, self->priv->filename); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + } +} + +static void +my_set_property (GObject * o, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + IndicatorDatetimeTimezoneFile * self = INDICATOR_DATETIME_TIMEZONE_FILE (o); + + switch (property_id) + { + case PROP_FILENAME: + set_filename (self, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + } +} + +static void +my_dispose (GObject * o) +{ + IndicatorDatetimeTimezoneFile * self = INDICATOR_DATETIME_TIMEZONE_FILE (o); + priv_t * p = self->priv; + + g_clear_object (&p->monitor); + g_clear_object (&p->file); + + G_OBJECT_CLASS (indicator_datetime_timezone_file_parent_class)->dispose (o); +} + +static void +my_finalize (GObject * o) +{ + IndicatorDatetimeTimezoneFile * self = INDICATOR_DATETIME_TIMEZONE_FILE (o); + priv_t * p = self->priv; + + g_free (p->filename); + g_free (p->timezone); + + G_OBJECT_CLASS (indicator_datetime_timezone_file_parent_class)->finalize (o); +} + +/*** +**** +***/ + +static void +indicator_datetime_timezone_file_class_init (IndicatorDatetimeTimezoneFileClass * klass) +{ + GObjectClass * object_class; + IndicatorDatetimeTimezoneClass * location_class; + const GParamFlags flags = G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS; + + object_class = G_OBJECT_CLASS (klass); + object_class->dispose = my_dispose; + object_class->finalize = my_finalize; + object_class->set_property = my_set_property; + object_class->get_property = my_get_property; + + location_class = INDICATOR_DATETIME_TIMEZONE_CLASS (klass); + location_class->get_timezone = my_get_timezone; + + g_type_class_add_private (klass, sizeof (IndicatorDatetimeTimezoneFilePriv)); + + /* install properties */ + + properties[PROP_0] = NULL; + + properties[PROP_FILENAME] = g_param_spec_string ("filename", + "Filename", + "Filename to monitor for TZ changes", + "", + flags); + + g_object_class_install_properties (object_class, PROP_LAST, properties); +} + +static void +indicator_datetime_timezone_file_init (IndicatorDatetimeTimezoneFile * self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_TYPE_DATETIME_TIMEZONE_FILE, + IndicatorDatetimeTimezoneFilePriv); +} + +/*** +**** Public +***/ + +IndicatorDatetimeTimezone * +indicator_datetime_timezone_file_new (const char * filename) +{ + gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_TIMEZONE_FILE, "filename", filename, NULL); + + return INDICATOR_DATETIME_TIMEZONE (o); +} diff --git a/src/timezone-file.h b/src/timezone-file.h new file mode 100644 index 0000000..7186beb --- /dev/null +++ b/src/timezone-file.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 __INDICATOR_DATETIME_TIMEZONE_FILE__H__ +#define __INDICATOR_DATETIME_TIMEZONE_FILE__H__ + +#include +#include + +#include "timezone.h" /* parent class */ + +G_BEGIN_DECLS + +#define INDICATOR_TYPE_DATETIME_TIMEZONE_FILE (indicator_datetime_timezone_file_get_type()) +#define INDICATOR_DATETIME_TIMEZONE_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_FILE, IndicatorDatetimeTimezoneFile)) +#define INDICATOR_DATETIME_TIMEZONE_FILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_FILE, IndicatorDatetimeTimezoneFileClass)) +#define INDICATOR_IS_DATETIME_TIMEZONE_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_FILE)) + +typedef struct _IndicatorDatetimeTimezoneFile IndicatorDatetimeTimezoneFile; +typedef struct _IndicatorDatetimeTimezoneFilePriv IndicatorDatetimeTimezoneFilePriv; +typedef struct _IndicatorDatetimeTimezoneFileClass IndicatorDatetimeTimezoneFileClass; + +GType indicator_datetime_timezone_file_get_type (void); + +/** + * An implementation of IndicatorDatetimeTimezone which determines the timezone + * from monitoring a local file, such as /etc/timezone + */ +struct _IndicatorDatetimeTimezoneFile +{ + /*< private >*/ + IndicatorDatetimeTimezone parent; + IndicatorDatetimeTimezoneFilePriv * priv; +}; + +struct _IndicatorDatetimeTimezoneFileClass +{ + IndicatorDatetimeTimezoneClass parent_class; +}; + +IndicatorDatetimeTimezone * indicator_datetime_timezone_file_new (const char * filename); + +G_END_DECLS + +#endif /* __INDICATOR_DATETIME_TIMEZONE_FILE__H__ */ diff --git a/src/timezone-geoclue.c b/src/timezone-geoclue.c new file mode 100644 index 0000000..5271945 --- /dev/null +++ b/src/timezone-geoclue.c @@ -0,0 +1,261 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 . + */ + +#include "config.h" + +#include +#include + +#include +#include + +#include "timezone-geoclue.h" + +struct _IndicatorDatetimeTimezoneGeocluePriv +{ + GeoclueMaster * master; + GeoclueMasterClient * client; + GeoclueAddress * address; + gchar * timezone; +}; + +typedef IndicatorDatetimeTimezoneGeocluePriv priv_t; + +G_DEFINE_TYPE (IndicatorDatetimeTimezoneGeoclue, + indicator_datetime_timezone_geoclue, + INDICATOR_TYPE_DATETIME_TIMEZONE) + +static void geo_restart (IndicatorDatetimeTimezoneGeoclue * self); + +/*** +**** +***/ + +static void +set_timezone (IndicatorDatetimeTimezoneGeoclue * self, const gchar * timezone) +{ + priv_t * p = self->priv; + + if (g_strcmp0 (p->timezone, timezone)) + { + g_free (p->timezone); + p->timezone = g_strdup (timezone); + indicator_datetime_timezone_notify_timezone (INDICATOR_DATETIME_TIMEZONE(self)); + } +} + +static void +on_address_changed (GeoclueAddress * address, + int timestamp, + GHashTable * addy_data, + GeoclueAccuracy * accuracy, + GError * error, + gpointer gself) +{ + if (error != NULL) + { + g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); + g_error_free (error); + } + else + { + IndicatorDatetimeTimezoneGeoclue * self = INDICATOR_DATETIME_TIMEZONE_GEOCLUE (gself); + const char * timezone = g_hash_table_lookup (addy_data, "timezone"); + set_timezone (self, timezone); + } +} + +static void +on_address_created (GeoclueMasterClient * master, + GeoclueAddress * address, + GError * error, + gpointer gself) +{ + if (error != NULL) + { + g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); + g_error_free (error); + } + else + { + priv_t * p = INDICATOR_DATETIME_TIMEZONE_GEOCLUE(gself)->priv; + + g_assert (p->address == NULL); + p->address = g_object_ref (address); + + geoclue_address_get_address_async (address, on_address_changed, gself); + g_signal_connect (address, "address-changed", G_CALLBACK(on_address_changed), gself); + } +} + +static void +on_requirements_set (GeoclueMasterClient * master, GError * error, gpointer user_data) +{ + if (error != NULL) + { + g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); + g_error_free (error); + } +} + +static void +on_client_created (GeoclueMaster * master, + GeoclueMasterClient * client, + gchar * path, + GError * error, + gpointer gself) +{ + g_debug ("Created Geoclue client at: %s", path); + + if (error != NULL) + { + g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); + g_error_free (error); + } + else if (client == NULL) + { + g_warning ("%s Unable to get timezone from GeoClue: %s", G_STRFUNC, error->message); + } + else + { + IndicatorDatetimeTimezoneGeoclue * self = INDICATOR_DATETIME_TIMEZONE_GEOCLUE (gself); + priv_t * p = self->priv; + + g_clear_object (&p->client); + p->client = g_object_ref (client); + g_signal_connect_swapped (p->client, "invalidated", G_CALLBACK(geo_restart), gself); + + geoclue_master_client_set_requirements_async (p->client, + GEOCLUE_ACCURACY_LEVEL_REGION, + 0, + FALSE, + GEOCLUE_RESOURCE_ALL, + on_requirements_set, + NULL); + + geoclue_master_client_create_address_async (p->client, on_address_created, gself); + } +} + +static void +geo_start (IndicatorDatetimeTimezoneGeoclue * self) +{ + priv_t * p = self->priv; + + g_assert (p->master == NULL); + p->master = geoclue_master_get_default (); + geoclue_master_create_client_async (p->master, on_client_created, self); +} + +static void +geo_stop (IndicatorDatetimeTimezoneGeoclue * self) +{ + priv_t * p = self->priv; + + if (p->address != NULL) + { + g_signal_handlers_disconnect_by_func (p->address, on_address_changed, self); + g_clear_object (&p->address); + } + + if (p->client != NULL) + { + g_signal_handlers_disconnect_by_func (p->client, geo_restart, self); + g_clear_object (&p->client); + } + + g_clear_object (&p->master); +} + +static void +geo_restart (IndicatorDatetimeTimezoneGeoclue * self) +{ + geo_stop (self); + geo_start (self); +} + +/*** +**** +***/ + +static const char * +my_get_timezone (IndicatorDatetimeTimezone * self) +{ + return INDICATOR_DATETIME_TIMEZONE_GEOCLUE(self)->priv->timezone; +} + +static void +my_dispose (GObject * o) +{ + geo_stop (INDICATOR_DATETIME_TIMEZONE_GEOCLUE (o)); + + G_OBJECT_CLASS (indicator_datetime_timezone_geoclue_parent_class)->dispose (o); +} + +static void +my_finalize (GObject * o) +{ + IndicatorDatetimeTimezoneGeoclue * self = INDICATOR_DATETIME_TIMEZONE_GEOCLUE (o); + priv_t * p = self->priv; + + g_free (p->timezone); + + G_OBJECT_CLASS (indicator_datetime_timezone_geoclue_parent_class)->finalize (o); +} + +static void +indicator_datetime_timezone_geoclue_class_init (IndicatorDatetimeTimezoneGeoclueClass * klass) +{ + GObjectClass * object_class; + IndicatorDatetimeTimezoneClass * location_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->dispose = my_dispose; + object_class->finalize = my_finalize; + + location_class = INDICATOR_DATETIME_TIMEZONE_CLASS (klass); + location_class->get_timezone = my_get_timezone; + + g_type_class_add_private (klass, sizeof (IndicatorDatetimeTimezoneGeocluePriv)); +} + +static void +indicator_datetime_timezone_geoclue_init (IndicatorDatetimeTimezoneGeoclue * self) +{ + priv_t * p; + + p = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE, + IndicatorDatetimeTimezoneGeocluePriv); + self->priv = p; + + geo_start (self); +} + +/*** +**** Public +***/ + +IndicatorDatetimeTimezone * +indicator_datetime_timezone_geoclue_new (void) +{ + gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE, NULL); + + return INDICATOR_DATETIME_TIMEZONE (o); +} diff --git a/src/timezone-geoclue.h b/src/timezone-geoclue.h new file mode 100644 index 0000000..fcb3ab7 --- /dev/null +++ b/src/timezone-geoclue.h @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 __INDICATOR_DATETIME_TIMEZONE_GEOCLUE__H__ +#define __INDICATOR_DATETIME_TIMEZONE_GEOCLUE__H__ + +#include +#include + +#include "timezone.h" /* parent class */ + +G_BEGIN_DECLS + +#define INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE (indicator_datetime_timezone_geoclue_get_type()) +#define INDICATOR_DATETIME_TIMEZONE_GEOCLUE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE, IndicatorDatetimeTimezoneGeoclue)) +#define INDICATOR_DATETIME_TIMEZONE_GEOCLUE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE, IndicatorDatetimeTimezoneGeoclueClass)) +#define INDICATOR_IS_DATETIME_TIMEZONE_GEOCLUE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_TIMEZONE_GEOCLUE)) + +typedef struct _IndicatorDatetimeTimezoneGeoclue IndicatorDatetimeTimezoneGeoclue; +typedef struct _IndicatorDatetimeTimezoneGeocluePriv IndicatorDatetimeTimezoneGeocluePriv; +typedef struct _IndicatorDatetimeTimezoneGeoclueClass IndicatorDatetimeTimezoneGeoclueClass; + +GType indicator_datetime_timezone_geoclue_get_type (void); + +/** + * An implementation of IndicatorDatetimeTimezone which determines the timezone + * from calling a GeoClue service over DBus. + */ +struct _IndicatorDatetimeTimezoneGeoclue +{ + /*< private >*/ + IndicatorDatetimeTimezone parent; + IndicatorDatetimeTimezoneGeocluePriv * priv; +}; + +struct _IndicatorDatetimeTimezoneGeoclueClass +{ + IndicatorDatetimeTimezoneClass parent_class; +}; + +IndicatorDatetimeTimezone * indicator_datetime_timezone_geoclue_new (void); + +G_END_DECLS + +#endif /* __INDICATOR_DATETIME_TIMEZONE_GEOCLUE__H__ */ diff --git a/src/timezone.c b/src/timezone.c new file mode 100644 index 0000000..9e671ed --- /dev/null +++ b/src/timezone.c @@ -0,0 +1,108 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 . + */ + +#include "timezone.h" + +G_DEFINE_TYPE (IndicatorDatetimeTimezone, + indicator_datetime_timezone, + G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_TIMEZONE, + PROP_LAST +}; + +static GParamSpec * properties[PROP_LAST] = { 0 }; + +static void +my_get_property (GObject * o, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + IndicatorDatetimeTimezone * self = INDICATOR_DATETIME_TIMEZONE (o); + + switch (property_id) + { + case PROP_TIMEZONE: + g_value_set_string (value, indicator_datetime_timezone_get_timezone (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + } +} + +static void +my_dispose (GObject * object) +{ + G_OBJECT_CLASS (indicator_datetime_timezone_parent_class)->dispose (object); +} + +static void +/* cppcheck-suppress unusedFunction */ +indicator_datetime_timezone_class_init (IndicatorDatetimeTimezoneClass * klass) +{ + GObjectClass * object_class; + const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS; + + object_class = G_OBJECT_CLASS (klass); + object_class->get_property = my_get_property; + object_class->dispose = my_dispose; + + klass->get_timezone = NULL; + + properties[PROP_0] = NULL; + + properties[PROP_TIMEZONE] = g_param_spec_string ("timezone", + "Timezone", + "Timezone", + "", + flags); + + g_object_class_install_properties (object_class, PROP_LAST, properties); +} + +static void +indicator_datetime_timezone_init (IndicatorDatetimeTimezone * self G_GNUC_UNUSED) +{ +} + +/*** +**** +***/ + +const char * +indicator_datetime_timezone_get_timezone (IndicatorDatetimeTimezone * self) +{ + g_return_val_if_fail (INDICATOR_IS_DATETIME_TIMEZONE (self), NULL); + + return INDICATOR_DATETIME_TIMEZONE_GET_CLASS (self)->get_timezone (self); +} + +void +indicator_datetime_timezone_notify_timezone (IndicatorDatetimeTimezone * self) +{ + g_return_if_fail (INDICATOR_IS_DATETIME_TIMEZONE (self)); + + g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_TIMEZONE]); +} + diff --git a/src/timezone.h b/src/timezone.h new file mode 100644 index 0000000..ac48e6e --- /dev/null +++ b/src/timezone.h @@ -0,0 +1,68 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * 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 __INDICATOR_DATETIME_TIMEZONE__H__ +#define __INDICATOR_DATETIME_TIMEZONE__H__ + +#include +#include + +G_BEGIN_DECLS + +#define INDICATOR_TYPE_DATETIME_TIMEZONE (indicator_datetime_timezone_get_type()) +#define INDICATOR_DATETIME_TIMEZONE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_TIMEZONE, IndicatorDatetimeTimezone)) +#define INDICATOR_DATETIME_TIMEZONE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_TIMEZONE, IndicatorDatetimeTimezoneClass)) +#define INDICATOR_DATETIME_TIMEZONE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), INDICATOR_TYPE_DATETIME_TIMEZONE, IndicatorDatetimeTimezoneClass)) +#define INDICATOR_IS_DATETIME_TIMEZONE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_TIMEZONE)) + +typedef struct _IndicatorDatetimeTimezone IndicatorDatetimeTimezone; +typedef struct _IndicatorDatetimeTimezoneClass IndicatorDatetimeTimezoneClass; + +GType indicator_datetime_timezone_get_type (void); + +/** + * Abstract Base Class for the mechanisms that determine timezone by location + */ +struct _IndicatorDatetimeTimezone +{ + /*< private >*/ + GObject parent; +}; + +struct _IndicatorDatetimeTimezoneClass +{ + GObjectClass parent_class; + + /* virtual functions */ + const char * (*get_timezone) (IndicatorDatetimeTimezone * self); +}; + +/*** +**** +***/ + +#define INDICATOR_DATETIME_TIMEZONE_PROPERTY_TIMEZONE "timezone" + +const char * indicator_datetime_timezone_get_timezone (IndicatorDatetimeTimezone *); + +void indicator_datetime_timezone_notify_timezone (IndicatorDatetimeTimezone *); + +G_END_DECLS + +#endif /* __INDICATOR_DATETIME_TIMEZONE__H__ */ -- cgit v1.2.3