[gnome-settings-daemon] datetime: Remove TZ monitoring



commit 595958f343ec630184b8f96e1bdf3838c6370f50
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 8 17:47:34 2010 +0000

    datetime: Remove TZ monitoring
    
    This can be done in user-space, and seeing as this is a
    mechanism, we wouldn't be running all the time anyway.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=626346

 plugins/datetime/system-timezone.c      |  108 +------------------------------
 plugins/datetime/system-timezone.h      |    3 -
 plugins/datetime/test-system-timezone.c |   22 +------
 3 files changed, 2 insertions(+), 131 deletions(-)
---
diff --git a/plugins/datetime/system-timezone.c b/plugins/datetime/system-timezone.c
index 4fcbf7b..ace76f3 100644
--- a/plugins/datetime/system-timezone.c
+++ b/plugins/datetime/system-timezone.c
@@ -54,8 +54,7 @@
 
 #include "system-timezone.h"
 
-/* Files that we look at and that should be monitored */
-#define CHECK_NB 5
+/* Files that we look at */
 #define ETC_TIMEZONE        "/etc/timezone"
 #define ETC_TIMEZONE_MAJ    "/etc/TIMEZONE"
 #define ETC_RC_CONF         "/etc/rc.conf"
@@ -66,14 +65,6 @@
 /* The first 4 characters in a timezone file, from tzfile.h */
 #define TZ_MAGIC "TZif"
 
-static char *files_to_check[CHECK_NB] = {
-        ETC_TIMEZONE,
-        ETC_TIMEZONE_MAJ,
-        ETC_SYSCONFIG_CLOCK,
-        ETC_CONF_D_CLOCK,
-        ETC_LOCALTIME
-};
-
 static GObject *systz_singleton = NULL;
 
 G_DEFINE_TYPE (SystemTimezone, system_timezone, G_TYPE_OBJECT)
@@ -81,27 +72,13 @@ G_DEFINE_TYPE (SystemTimezone, system_timezone, G_TYPE_OBJECT)
 typedef struct {
         char *tz;
         char *env_tz;
-        GFileMonitor *monitors[CHECK_NB];
 } SystemTimezonePrivate;
 
-enum {
-	CHANGED,
-	LAST_SIGNAL
-};
-
-static guint system_timezone_signals[LAST_SIGNAL] = { 0 };
-
 static GObject *system_timezone_constructor (GType                  type,
                                              guint                  n_construct_properties,
                                              GObjectConstructParam *construct_properties);
 static void system_timezone_finalize (GObject *obj);
 
-static void system_timezone_monitor_changed (GFileMonitor *handle,
-                                             GFile *file,
-                                             GFile *other_file,
-                                             GFileMonitorEvent event,
-                                             gpointer user_data);
-
 #define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SYSTEM_TIMEZONE_TYPE, SystemTimezonePrivate))
 
 SystemTimezone *
@@ -140,28 +117,16 @@ system_timezone_class_init (SystemTimezoneClass *class)
         g_obj_class->constructor = system_timezone_constructor;
         g_obj_class->finalize = system_timezone_finalize;
 
-        system_timezone_signals[CHANGED] =
-		g_signal_new ("changed",
-			      G_OBJECT_CLASS_TYPE (g_obj_class),
-			      G_SIGNAL_RUN_FIRST,
-			      G_STRUCT_OFFSET (SystemTimezoneClass, changed),
-			      NULL, NULL,
-			      g_cclosure_marshal_VOID__STRING,
-			      G_TYPE_NONE, 1, G_TYPE_STRING);
-
         g_type_class_add_private (class, sizeof (SystemTimezonePrivate));
 }
 
 static void
 system_timezone_init (SystemTimezone *systz)
 {
-        int i;
         SystemTimezonePrivate *priv = PRIVATE (systz);
 
         priv->tz = NULL;
         priv->env_tz = NULL;
-        for (i = 0; i < CHECK_NB; i++) 
-                priv->monitors[i] = NULL;
 }
 
 static GObject *
@@ -171,7 +136,6 @@ system_timezone_constructor (GType                  type,
 {
         GObject *obj;
         SystemTimezonePrivate *priv;
-        int i;
 
         /* This is a singleton, we don't need to have it per-applet */
         if (systz_singleton)
@@ -188,37 +152,6 @@ system_timezone_constructor (GType                  type,
 
         priv->env_tz = g_strdup (g_getenv ("TZ"));
 
-        for (i = 0; i < CHECK_NB; i++) {
-                GFile     *file;
-                GFile     *parent;
-                GFileType  parent_type;
-
-                file = g_file_new_for_path (files_to_check[i]);
-
-                parent = g_file_get_parent (file);
-                parent_type = g_file_query_file_type (parent, G_FILE_QUERY_INFO_NONE, NULL);
-                g_object_unref (parent);
-
-                /* We don't try to monitor the file if the parent directory
-                 * doesn't exist: this means we're on a system where this file
-                 * is not useful to determine the system timezone.
-                 * Since gio does not monitor file in non-existing directories
-                 * in a clever way (as of gio 2.22, it just polls every other
-                 * seconds to see if the directory now exists), this avoids
-                 * unnecessary wakeups. */
-                if (parent_type == G_FILE_TYPE_DIRECTORY)
-                        priv->monitors[i] = g_file_monitor_file (file,
-                                                                 G_FILE_MONITOR_NONE,
-                                                                 NULL, NULL);
-                g_object_unref (file);
-
-                if (priv->monitors[i])
-                        g_signal_connect (G_OBJECT (priv->monitors[i]),
-                                          "changed", 
-                                          G_CALLBACK (system_timezone_monitor_changed),
-                                          obj);
-        }
-
         systz_singleton = obj;
 
         return systz_singleton;
@@ -227,7 +160,6 @@ system_timezone_constructor (GType                  type,
 static void
 system_timezone_finalize (GObject *obj)
 {
-        int i;
         SystemTimezonePrivate *priv = PRIVATE (obj);
 
         if (priv->tz) {
@@ -240,12 +172,6 @@ system_timezone_finalize (GObject *obj)
                 priv->env_tz = NULL;
         }
 
-        for (i = 0; i < CHECK_NB; i++) {
-                if (priv->monitors[i])
-                        g_object_unref (priv->monitors[i]);
-                priv->monitors[i] = NULL;
-        }
-
         G_OBJECT_CLASS (system_timezone_parent_class)->finalize (obj);
 
         g_assert (obj == systz_singleton);
@@ -253,38 +179,6 @@ system_timezone_finalize (GObject *obj)
         systz_singleton = NULL;
 }
 
-static void
-system_timezone_monitor_changed (GFileMonitor *handle,
-                                 GFile *file,
-                                 GFile *other_file,
-                                 GFileMonitorEvent event,
-                                 gpointer user_data)
-{
-        SystemTimezonePrivate *priv = PRIVATE (user_data);
-        char *new_tz;
-
-        if (event != G_FILE_MONITOR_EVENT_CHANGED &&
-            event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT &&
-            event != G_FILE_MONITOR_EVENT_DELETED &&
-            event != G_FILE_MONITOR_EVENT_CREATED)
-                return;
-
-        new_tz = system_timezone_find ();
-
-        g_assert (priv->tz != NULL && new_tz != NULL);
-
-        if (strcmp (priv->tz, new_tz) != 0) {
-                g_free (priv->tz);
-                priv->tz = new_tz;
-
-                g_signal_emit (G_OBJECT (user_data),
-                               system_timezone_signals[CHANGED],
-                               0, priv->tz);
-        } else
-                g_free (new_tz);
-}
-
-
 /*
  * Code to deal with the system timezone on all distros.
  * There's no dependency on the SystemTimezone GObject here.
diff --git a/plugins/datetime/system-timezone.h b/plugins/datetime/system-timezone.h
index 3fd35b2..176ca4d 100644
--- a/plugins/datetime/system-timezone.h
+++ b/plugins/datetime/system-timezone.h
@@ -49,9 +49,6 @@ typedef struct
 typedef struct
 {
         GObjectClass g_object_class;
-
-	void (* changed) (SystemTimezone *systz,
-			  const char     *tz);
 } SystemTimezoneClass;
 
 GType system_timezone_get_type (void);
diff --git a/plugins/datetime/test-system-timezone.c b/plugins/datetime/test-system-timezone.c
index 42a8061..4380df4 100644
--- a/plugins/datetime/test-system-timezone.c
+++ b/plugins/datetime/test-system-timezone.c
@@ -55,23 +55,6 @@ timezone_changed (SystemTimezone *systz,
 	g_print ("Timezone changed to: %s\n", new_tz);
 }
 
-static void
-timezone_monitor (void)
-{
-	SystemTimezone *systz;
-	GMainLoop      *mainloop;
-
-	systz = system_timezone_new ();
-	g_signal_connect (systz, "changed",
-			  G_CALLBACK (timezone_changed), NULL);
-
-	mainloop = g_main_loop_new (NULL, FALSE);
-	g_main_loop_run (mainloop);
-	g_main_loop_unref (mainloop);
-
-	g_object_unref (systz);
-}
-
 int
 main (int    argc,
       char **argv)
@@ -87,7 +70,6 @@ main (int    argc,
         GOptionEntry options[] = {
                 { "get", 'g', 0, G_OPTION_ARG_NONE, &get, "Get the current timezone", NULL },
                 { "set", 's', 0, G_OPTION_ARG_STRING, &tz_set, "Set the timezone to TIMEZONE", "TIMEZONE" },
-                { "monitor", 'm', 0, G_OPTION_ARG_NONE, &monitor, "Monitor timezone changes", NULL },
                 { NULL, 0, 0, 0, NULL, NULL, NULL }
         };
 
@@ -109,12 +91,10 @@ main (int    argc,
 
 	g_option_context_free (context);
 
-	if (get || (!tz_set && !monitor))
+	if (get || (!tz_set))
 		timezone_print ();
 	else if (tz_set)
 		retval = timezone_set (tz_set);
-	else if (monitor)
-		timezone_monitor ();
 	else
 		g_assert_not_reached ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]