[gnome-control-center] info-panel: Set the hostname only after a small delay



commit 53d06c70856541c2ee05d43ab0008eab92184ba0
Author: Thomas Wood <thomas wood intel com>
Date:   Mon Nov 5 11:24:00 2012 +0000

    info-panel: Set the hostname only after a small delay
    
    Avoid setting the hostname from the entry on every single key press and
    instead wait for a second after the last key press.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679284

 panels/info/cc-info-panel.c |   52 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index 8049d0f..8f58443 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -55,6 +55,8 @@
 #define GNOME_SESSION_MANAGER_SCHEMA        "org.gnome.desktop.session"
 #define KEY_SESSION_NAME          "session-name"
 
+#define SET_HOSTNAME_TIMEOUT 1
+
 #define WID(w) (GtkWidget *) gtk_builder_get_object (self->priv->builder, w)
 
 CC_PANEL_REGISTER (CcInfoPanel, cc_info_panel)
@@ -109,6 +111,7 @@ struct _CcInfoPanelPrivate
   GDBusProxy          *pk_proxy;
   GDBusProxy          *pk_transaction_proxy;
   GDBusProxy          *hostnamed_proxy;
+  guint                set_hostname_timeout_source_id;
   GSettings           *session_settings;
 
   GraphicsData  *graphics_data;
@@ -116,6 +119,7 @@ struct _CcInfoPanelPrivate
 
 static void get_primary_disc_info_start (CcInfoPanel *self);
 static void refresh_update_button (CcInfoPanel *self);
+static void info_panel_set_hostname (CcInfoPanel *self);
 
 typedef struct
 {
@@ -472,6 +476,37 @@ get_current_is_fallback (CcInfoPanel  *self)
   return is_fallback;
 }
 
+static gboolean
+set_hostname_timeout (CcInfoPanel *self)
+{
+  self->priv->set_hostname_timeout_source_id = 0;
+
+  info_panel_set_hostname (self);
+
+  return FALSE;
+}
+
+static void
+remove_hostname_timeout (CcInfoPanel *panel)
+{
+  CcInfoPanelPrivate *priv = panel->priv;
+
+  if (priv->set_hostname_timeout_source_id)
+    g_source_remove (priv->set_hostname_timeout_source_id);
+
+  priv->set_hostname_timeout_source_id = 0;
+}
+
+static void
+reset_hostname_timeout (CcInfoPanel *panel)
+{
+  remove_hostname_timeout (panel);
+
+  panel->priv->set_hostname_timeout_source_id = g_timeout_add_seconds (SET_HOSTNAME_TIMEOUT,
+                                                                       (GSourceFunc) set_hostname_timeout,
+                                                                       panel);
+}
+
 static void
 cc_info_panel_get_property (GObject    *object,
                             guint       property_id,
@@ -503,6 +538,12 @@ cc_info_panel_dispose (GObject *object)
 {
   CcInfoPanelPrivate *priv = CC_INFO_PANEL (object)->priv;
 
+  if (priv->set_hostname_timeout_source_id)
+    {
+      remove_hostname_timeout (CC_INFO_PANEL (object));
+      set_hostname_timeout (CC_INFO_PANEL (object));
+    }
+
   if (priv->builder != NULL)
     {
       g_object_unref (priv->builder);
@@ -1704,12 +1745,14 @@ info_panel_get_hostname (CcInfoPanel  *self)
 }
 
 static void
-info_panel_set_hostname (CcInfoPanel *self,
-                         const char  *text)
+info_panel_set_hostname (CcInfoPanel *self)
 {
   char *hostname;
   GVariant *variant;
   GError *error = NULL;
+  const gchar *text;
+
+  text = gtk_entry_get_text (GTK_ENTRY (WID ("name_entry")));
 
   g_debug ("Setting PrettyHostname to '%s'", text);
   variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
@@ -1754,10 +1797,7 @@ static void
 text_changed_cb (GtkEntry        *entry,
                  CcInfoPanel     *self)
 {
-  const char *text;
-
-  text = gtk_entry_get_text (GTK_ENTRY (entry));
-  info_panel_set_hostname (self, text);
+  reset_hostname_timeout (self);
 }
 
 static void



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