[gnome-control-center] Add CcHostnameEntry widget and use it in the info panel



commit f3a35fb57373c581c470c1bfbe72f3baf80ec3b2
Author: Thomas Wood <thomas wood intel com>
Date:   Tue Jan 8 11:46:13 2013 +0000

    Add CcHostnameEntry widget and use it in the info panel
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687772

 configure.ac                              |    2 +-
 panels/info/Makefile.am                   |   14 +--
 panels/info/cc-info-panel.c               |  237 -----------------------
 panels/info/info.ui                       |    8 +-
 panels/info/test-hostname                 |  Bin 0 -> 18159 bytes
 shell/Makefile.am                         |   16 ++
 shell/cc-hostname-entry.c                 |  299 +++++++++++++++++++++++++++++
 shell/cc-hostname-entry.h                 |   73 +++++++
 {panels/info => shell}/hostname-helper.c  |    0
 {panels/info => shell}/hostname-helper.h  |    0
 {panels/info => shell}/hostnames-test.txt |    0
 {panels/info => shell}/test-hostname.c    |    0
 12 files changed, 393 insertions(+), 256 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 65bdb3b..a8803cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,7 +123,7 @@ PKG_CHECK_MODULES(LIBLANGUAGE, $COMMON_MODULES gnome-desktop-3.0 fontconfig)
 PKG_CHECK_MODULES(LIBSHORTCUTS, $COMMON_MODULES x11)
 # egg-list-box is a static library, so it must be shared among all panels
 # or it breaks GType registration
-PKG_CHECK_MODULES(SHELL, $COMMON_MODULES x11 egg-list-box)
+PKG_CHECK_MODULES(SHELL, $COMMON_MODULES x11 egg-list-box polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
 PKG_CHECK_MODULES(BACKGROUND_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0
                   gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
 PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES
diff --git a/panels/info/Makefile.am b/panels/info/Makefile.am
index 4923057..9333bb7 100644
--- a/panels/info/Makefile.am
+++ b/panels/info/Makefile.am
@@ -7,16 +7,6 @@ INCLUDES = 						\
 	-DDATADIR="\"$(datadir)\""			\
 	$(NULL)
 
-noinst_PROGRAMS = test-hostname
-test_hostname_SOURCES = hostname-helper.c hostname-helper.h test-hostname.c
-test_hostname_LDADD = $(PANEL_LIBS) $(INFO_PANEL_LIBS)
-test_hostname_CFLAGS = $(INCLUDES)
-
-all-local: check-local
-
-check-local: test-hostname
-	$(builddir)/test-hostname $(srcdir)/hostnames-test.txt > /dev/null
-
 noinst_LTLIBRARIES = libinfo.la
 
 BUILT_SOURCES =			\
@@ -27,8 +17,6 @@ libinfo_la_SOURCES =		\
 	$(BUILT_SOURCES)	\
 	cc-info-panel.c		\
 	cc-info-panel.h		\
-	hostname-helper.c	\
-	hostname-helper.h	\
 	gsd-disk-space-helper.h	\
 	gsd-disk-space-helper.c
 
@@ -53,6 +41,6 @@ update-from-gsd:
 	git commit -m "info: Update from gnome-settings-daemon" $(SPACEFILES)
 
 CLEANFILES = $(desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES)
-EXTRA_DIST = hostnames-test.txt $(resource_files) info.gresource.xml
+EXTRA_DIST = $(resource_files) info.gresource.xml
 
 -include $(top_srcdir)/git.mk
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index 033cee7..ff8c1bd 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -24,8 +24,6 @@
 #include "cc-info-panel.h"
 #include "cc-info-resources.h"
 
-#include <polkit/polkit.h>
-
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gio/gio.h>
@@ -37,7 +35,6 @@
 #include <glibtop/mem.h>
 #include <glibtop/sysinfo.h>
 
-#include "hostname-helper.h"
 #include "gsd-disk-space-helper.h"
 
 /* Autorun options */
@@ -56,8 +53,6 @@
 #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)
@@ -111,15 +106,12 @@ struct _CcInfoPanelPrivate
   GDBusConnection     *session_bus;
   GDBusProxy          *pk_proxy;
   GDBusProxy          *pk_transaction_proxy;
-  GDBusProxy          *hostnamed_proxy;
-  guint                set_hostname_timeout_source_id;
 
   GraphicsData  *graphics_data;
 };
 
 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
 {
@@ -442,48 +434,11 @@ get_graphics_data (void)
   return result;
 }
 
-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_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);
@@ -521,7 +476,6 @@ cc_info_panel_finalize (GObject *object)
   g_free (priv->gnome_date);
   g_free (priv->gnome_distributor);
 
-  g_clear_object (&priv->hostnamed_proxy);
   g_clear_object (&priv->media_settings);
 
   G_OBJECT_CLASS (cc_info_panel_parent_class)->finalize (object);
@@ -1564,192 +1518,6 @@ info_panel_setup_selector (CcInfoPanel  *self)
   gtk_widget_show_all (GTK_WIDGET (view));
 }
 
-static char *
-get_hostname_property (CcInfoPanel *self,
-		       const char  *property)
-{
-  GVariant *variant;
-  char *str;
-
-  variant = g_dbus_proxy_get_cached_property (self->priv->hostnamed_proxy,
-                                              property);
-  if (!variant)
-    {
-      GError *error = NULL;
-      GVariant *inner;
-
-      /* Work around systemd-hostname not sending us back
-       * the property value when changing values */
-      variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
-                                        "org.freedesktop.DBus.Properties.Get",
-                                        g_variant_new ("(ss)", "org.freedesktop.hostname1", property),
-                                        G_DBUS_CALL_FLAGS_NONE,
-                                        -1,
-                                        NULL,
-                                        &error);
-      if (variant == NULL)
-        {
-          g_warning ("Failed to get property '%s': %s", property, error->message);
-          g_error_free (error);
-          return NULL;
-        }
-
-      g_variant_get (variant, "(v)", &inner);
-      str = g_variant_dup_string (inner, NULL);
-      g_variant_unref (variant);
-    }
-  else
-    {
-      str = g_variant_dup_string (variant, NULL);
-      g_variant_unref (variant);
-    }
-
-  return str;
-}
-
-static char *
-info_panel_get_hostname (CcInfoPanel  *self)
-{
-  char *str;
-
-  str = get_hostname_property (self, "PrettyHostname");
-
-  /* Empty strings means that we need to fallback */
-  if (str != NULL &&
-      *str == '\0')
-    {
-      g_free (str);
-      str = get_hostname_property (self, "Hostname");
-    }
-
-  return str;
-}
-
-static void
-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,
-                                    "SetPrettyHostname",
-                                    g_variant_new ("(sb)", text, FALSE),
-                                    G_DBUS_CALL_FLAGS_NONE,
-                                    -1, NULL, &error);
-  if (variant == NULL)
-    {
-      g_warning ("Could not set PrettyHostname: %s", error->message);
-      g_error_free (error);
-      error = NULL;
-    }
-  else
-    {
-      g_variant_unref (variant);
-    }
-
-  /* Set the static and transient hostname */
-  hostname = pretty_hostname_to_static (text, FALSE);
-  g_assert (hostname);
-
-  g_debug ("Setting StaticHostname to '%s'", hostname);
-  variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
-                                    "SetStaticHostname",
-                                    g_variant_new ("(sb)", hostname, FALSE),
-                                    G_DBUS_CALL_FLAGS_NONE,
-                                    -1, NULL, &error);
-  if (variant == NULL)
-    {
-      g_warning ("Could not set StaticHostname: %s", error->message);
-      g_error_free (error);
-    }
-  else
-    {
-      g_variant_unref (variant);
-    }
-
-  g_debug ("Setting Hostname to '%s'", hostname);
-  variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
-                                    "SetHostname",
-                                    g_variant_new ("(sb)", hostname, FALSE),
-                                    G_DBUS_CALL_FLAGS_NONE,
-                                    -1, NULL, &error);
-  if (variant == NULL)
-    {
-      g_warning ("Could not set Hostname: %s", error->message);
-      g_error_free (error);
-    }
-  else
-    {
-      g_variant_unref (variant);
-    }
-  g_free (hostname);
-}
-
-static void
-text_changed_cb (GtkEntry        *entry,
-                 CcInfoPanel     *self)
-{
-  reset_hostname_timeout (self);
-}
-
-static void
-info_panel_setup_hostname (CcInfoPanel  *self,
-                           GPermission  *permission)
-{
-  char *str;
-  GtkWidget *entry;
-  GError *error = NULL;
-
-  if (permission == NULL)
-    {
-      g_debug ("Will not show hostname, hostnamed not installed");
-      return;
-    }
-
-  entry = WID ("name_entry");
-
-  if (g_permission_get_allowed (permission))
-    gtk_widget_set_sensitive (entry, TRUE);
-  else
-    g_debug ("Not allowed to change the hostname");
-
-  self->priv->hostnamed_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
-                                                               G_DBUS_PROXY_FLAGS_NONE,
-                                                               NULL,
-                                                               "org.freedesktop.hostname1",
-                                                               "/org/freedesktop/hostname1",
-                                                               "org.freedesktop.hostname1",
-                                                               NULL,
-                                                               &error);
-
-  /* This could only happen if the policy file was installed
-   * but not hostnamed, which points to a system bug */
-  if (self->priv->hostnamed_proxy == NULL)
-    {
-      g_debug ("Couldn't get hostnamed to start, bailing: %s", error->message);
-      g_error_free (error);
-      return;
-    }
-
-  gtk_widget_show (WID ("label4"));
-  gtk_widget_show (entry);
-
-  str = info_panel_get_hostname (self);
-  if (str != NULL)
-    gtk_entry_set_text (GTK_ENTRY (entry), str);
-  else
-    gtk_entry_set_text (GTK_ENTRY (entry), "");
-  g_free (str);
-
-  g_signal_connect (G_OBJECT (entry), "changed",
-		    G_CALLBACK (text_changed_cb), self);
-}
-
 static void
 info_panel_setup_overview (CcInfoPanel  *self)
 {
@@ -1758,11 +1526,6 @@ info_panel_setup_overview (CcInfoPanel  *self)
   glibtop_mem mem;
   const glibtop_sysinfo *info;
   char       *text;
-  GPermission *permission;
-
-  permission = polkit_permission_new_sync ("org.freedesktop.hostname1.set-static-hostname", NULL, NULL, NULL);
-  /* Is hostnamed installed? */
-    info_panel_setup_hostname (self, permission);
 
   res = load_gnome_version (&self->priv->gnome_version,
                             &self->priv->gnome_distributor,
diff --git a/panels/info/info.ui b/panels/info/info.ui
index 0064a16..c7b193a 100644
--- a/panels/info/info.ui
+++ b/panels/info/info.ui
@@ -277,8 +277,8 @@
                                 <property name="row_spacing">5</property>
                                 <child>
                                   <object class="GtkLabel" id="label4">
+                                    <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="no_show_all">True</property>
                                     <property name="xalign">1</property>
                                     <property name="label" translatable="yes">Device name</property>
                                     <property name="mnemonic_widget">name_entry</property>
@@ -352,11 +352,9 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkEntry" id="name_entry">
-                                    <property name="visible">False</property>
+                                  <object class="CcHostnameEntry" id="name_entry">
+                                    <property name="visible">True</property>
                                     <property name="xalign">0</property>
-                                    <property name="text"></property>
-                                    <property name="sensitive">False</property>
                                   </object>
                                   <packing>
                                     <property name="left_attach">1</property>
diff --git a/panels/info/test-hostname b/panels/info/test-hostname
new file mode 100755
index 0000000..961d12c
Binary files /dev/null and b/panels/info/test-hostname differ
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 76166ee..a238cb1 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -4,6 +4,8 @@ INCLUDES =					\
 	$(CHEESE_CFLAGS)			\
 	-I$(top_srcdir)/libgd
 
+all-local: check-local
+
 bin_PROGRAMS = gnome-control-center
 
 BUILT_SOURCES =			\
@@ -31,6 +33,10 @@ gnome_control_center_SOURCES =			\
 	cc-panel.h				\
 	cc-shell.c				\
 	cc-shell.h				\
+	hostname-helper.c			\
+	hostname-helper.h			\
+	cc-hostname-entry.c			\
+	cc-hostname-entry.h			\
 	$(MARSHAL_FILES)
 
 gnome_control_center_LDFLAGS = -export-dynamic
@@ -102,4 +108,14 @@ EXTRA_DIST =					\
 CLEANFILES = $(BUILT_SOURCES) $(completion_DATA)
 DISTCLEANFILES = gnome-control-center.desktop gnome-control-center.desktop.in
 
+noinst_PROGRAMS = test-hostname
+test_hostname_SOURCES = hostname-helper.c hostname-helper.h test-hostname.c
+test_hostname_LDADD = $(PANEL_LIBS) $(INFO_PANEL_LIBS)
+test_hostname_CFLAGS = $(INCLUDES)
+
+EXTRA_DIST = hostnames-test.txt
+check-local: test-hostname
+	$(builddir)/test-hostname $(srcdir)/hostnames-test.txt > /dev/null
+
+
 -include $(top_srcdir)/git.mk
diff --git a/shell/cc-hostname-entry.c b/shell/cc-hostname-entry.c
new file mode 100644
index 0000000..f10df4f
--- /dev/null
+++ b/shell/cc-hostname-entry.c
@@ -0,0 +1,299 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2013 Intel, Inc
+ * Copyright (C) 2011,2012 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#include "cc-hostname-entry.h"
+#include "hostname-helper.h"
+
+#include <polkit/polkit.h>
+
+
+G_DEFINE_TYPE (CcHostnameEntry, cc_hostname_entry, GTK_TYPE_ENTRY)
+
+#define HOSTNAME_ENTRY_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_HOSTNAME_ENTRY, CcHostnameEntryPrivate))
+
+#define SET_HOSTNAME_TIMEOUT 1
+
+struct _CcHostnameEntryPrivate
+{
+  GDBusProxy          *hostnamed_proxy;
+  guint                set_hostname_timeout_source_id;
+};
+
+static void
+cc_hostname_entry_set_hostname (CcHostnameEntry *self)
+{
+  char *hostname;
+  GVariant *variant;
+  GError *error = NULL;
+  const gchar *text;
+
+  text = gtk_entry_get_text (GTK_ENTRY (self));
+
+  g_debug ("Setting PrettyHostname to '%s'", text);
+  variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
+                                    "SetPrettyHostname",
+                                    g_variant_new ("(sb)", text, FALSE),
+                                    G_DBUS_CALL_FLAGS_NONE,
+                                    -1, NULL, &error);
+  if (variant == NULL)
+    {
+      g_warning ("Could not set PrettyHostname: %s", error->message);
+      g_error_free (error);
+      error = NULL;
+    }
+  else
+    {
+      g_variant_unref (variant);
+    }
+
+  /* Set the static hostname */
+  hostname = pretty_hostname_to_static (text, FALSE);
+  g_assert (hostname);
+
+  g_debug ("Setting StaticHostname to '%s'", hostname);
+  variant = g_dbus_proxy_call_sync (self->priv->hostnamed_proxy,
+                                    "SetStaticHostname",
+                                    g_variant_new ("(sb)", hostname, FALSE),
+                                    G_DBUS_CALL_FLAGS_NONE,
+                                    -1, NULL, &error);
+  if (variant == NULL)
+    {
+      g_warning ("Could not set StaticHostname: %s", error->message);
+      g_error_free (error);
+    }
+  else
+    {
+      g_variant_unref (variant);
+    }
+  g_free (hostname);
+}
+
+static char *
+get_hostname_property (CcHostnameEntry *self,
+                       const char      *property)
+{
+  CcHostnameEntryPrivate *priv = self->priv;
+  GVariant *variant;
+  char *str;
+
+  if (!priv->hostnamed_proxy)
+    return g_strdup ("");
+
+  variant = g_dbus_proxy_get_cached_property (priv->hostnamed_proxy,
+                                              property);
+  if (!variant)
+    {
+      GError *error = NULL;
+      GVariant *inner;
+
+      /* Work around systemd-hostname not sending us back
+       * the property value when changing values */
+      variant = g_dbus_proxy_call_sync (priv->hostnamed_proxy,
+                                        "org.freedesktop.DBus.Properties.Get",
+                                        g_variant_new ("(ss)", "org.freedesktop.hostname1", property),
+                                        G_DBUS_CALL_FLAGS_NONE,
+                                        -1,
+                                        NULL,
+                                        &error);
+      if (variant == NULL)
+        {
+          g_warning ("Failed to get property '%s': %s", property, error->message);
+          g_error_free (error);
+          return NULL;
+        }
+
+      g_variant_get (variant, "(v)", &inner);
+      str = g_variant_dup_string (inner, NULL);
+      g_variant_unref (variant);
+    }
+  else
+    {
+      str = g_variant_dup_string (variant, NULL);
+      g_variant_unref (variant);
+    }
+
+  return str;
+}
+
+static char *
+cc_hostname_entry_get_display_hostname (CcHostnameEntry  *self)
+{
+  char *str;
+
+  str = get_hostname_property (self, "PrettyHostname");
+
+  /* Empty strings means that we need to fallback */
+  if (str != NULL &&
+      *str == '\0')
+    {
+      g_free (str);
+      str = get_hostname_property (self, "Hostname");
+    }
+
+  return str;
+}
+
+static gboolean
+set_hostname_timeout (CcHostnameEntry *self)
+{
+  self->priv->set_hostname_timeout_source_id = 0;
+
+  cc_hostname_entry_set_hostname (self);
+
+  return FALSE;
+}
+
+static void
+remove_hostname_timeout (CcHostnameEntry *entry)
+{
+  CcHostnameEntryPrivate *priv = entry->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 (CcHostnameEntry *entry)
+{
+  remove_hostname_timeout (entry);
+
+  entry->priv->set_hostname_timeout_source_id = g_timeout_add_seconds (SET_HOSTNAME_TIMEOUT,
+                                                                       (GSourceFunc) set_hostname_timeout,
+                                                                       entry);
+}
+
+static void
+text_changed_cb (CcHostnameEntry *entry)
+{
+  reset_hostname_timeout (entry);
+}
+
+static void
+cc_hostname_entry_dispose (GObject *object)
+{
+  CcHostnameEntry *entry = CC_HOSTNAME_ENTRY (object);
+  CcHostnameEntryPrivate *priv = entry->priv;
+
+  if (priv->set_hostname_timeout_source_id)
+    {
+      remove_hostname_timeout (entry);
+      set_hostname_timeout (entry);
+    }
+
+  g_clear_object (&priv->hostnamed_proxy);
+
+  G_OBJECT_CLASS (cc_hostname_entry_parent_class)->dispose (object);
+}
+
+static void
+cc_hostname_entry_constructed (GObject *self)
+{
+  CcHostnameEntryPrivate *priv = CC_HOSTNAME_ENTRY (self)->priv;
+  GError *error = NULL;
+  GPermission *permission;
+  char *str;
+
+  permission = polkit_permission_new_sync ("org.freedesktop.hostname1.set-static-hostname",
+                                           NULL, NULL, NULL);
+
+  /* Is hostnamed installed? */
+  if (permission == NULL)
+    {
+      g_debug ("Will not show hostname, hostnamed not installed");
+
+      gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
+
+      return;
+    }
+
+  if (g_permission_get_allowed (permission))
+    gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
+  else
+    {
+      g_debug ("Not allowed to change the hostname");
+      gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
+    }
+
+  gtk_widget_set_sensitive (GTK_WIDGET (self),
+                            g_permission_get_allowed (permission));
+
+  priv->hostnamed_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                         G_DBUS_PROXY_FLAGS_NONE,
+                                                         NULL,
+                                                         "org.freedesktop.hostname1",
+                                                         "/org/freedesktop/hostname1",
+                                                         "org.freedesktop.hostname1",
+                                                         NULL,
+                                                         &error);
+
+  /* This could only happen if the policy file was installed
+   * but not hostnamed, which points to a system bug */
+  if (priv->hostnamed_proxy == NULL)
+    {
+      g_debug ("Couldn't get hostnamed to start, bailing: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  str = cc_hostname_entry_get_display_hostname (CC_HOSTNAME_ENTRY (self));
+
+  if (str != NULL)
+    gtk_entry_set_text (GTK_ENTRY (self), str);
+  else
+    gtk_entry_set_text (GTK_ENTRY (self), "");
+  g_free (str);
+
+  g_signal_connect (G_OBJECT (self), "changed", G_CALLBACK (text_changed_cb),
+                    self);
+}
+
+static void
+cc_hostname_entry_class_init (CcHostnameEntryClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (CcHostnameEntryPrivate));
+
+  object_class->constructed = cc_hostname_entry_constructed;
+  object_class->dispose = cc_hostname_entry_dispose;
+}
+
+static void
+cc_hostname_entry_init (CcHostnameEntry *self)
+{
+  self->priv = HOSTNAME_ENTRY_PRIVATE (self);
+}
+
+CcHostnameEntry *
+cc_hostname_entry_new (void)
+{
+  return g_object_new (CC_TYPE_HOSTNAME_ENTRY, NULL);
+}
+
+gchar*
+cc_hostname_entry_get_hostname (CcHostnameEntry *entry)
+{
+  return get_hostname_property (entry, "Hostname");
+}
diff --git a/shell/cc-hostname-entry.h b/shell/cc-hostname-entry.h
new file mode 100644
index 0000000..a806695
--- /dev/null
+++ b/shell/cc-hostname-entry.h
@@ -0,0 +1,73 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2013 Intel, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __CC_HOSTNAME_ENTRY_H__
+#define __CC_HOSTNAME_ENTRY_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_HOSTNAME_ENTRY cc_hostname_entry_get_type()
+
+#define CC_HOSTNAME_ENTRY(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+  CC_TYPE_HOSTNAME_ENTRY, CcHostnameEntry))
+
+#define CC_HOSTNAME_ENTRY_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+  CC_TYPE_HOSTNAME_ENTRY, CcHostnameEntryClass))
+
+#define CC_IS_HOSTNAME_ENTRY(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+  CC_TYPE_HOSTNAME_ENTRY))
+
+#define CC_IS_HOSTNAME_ENTRY_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+  CC_TYPE_HOSTNAME_ENTRY))
+
+#define CC_HOSTNAME_ENTRY_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+  CC_TYPE_HOSTNAME_ENTRY, CcHostnameEntryClass))
+
+typedef struct _CcHostnameEntry CcHostnameEntry;
+typedef struct _CcHostnameEntryClass CcHostnameEntryClass;
+typedef struct _CcHostnameEntryPrivate CcHostnameEntryPrivate;
+
+struct _CcHostnameEntry
+{
+  GtkEntry parent;
+
+  CcHostnameEntryPrivate *priv;
+};
+
+struct _CcHostnameEntryClass
+{
+  GtkEntryClass parent_class;
+};
+
+GType cc_hostname_entry_get_type (void) G_GNUC_CONST;
+
+CcHostnameEntry *cc_hostname_entry_new (void);
+gchar* cc_hostname_entry_get_hostname (CcHostnameEntry *entry);
+
+G_END_DECLS
+
+#endif /* __CC_HOSTNAME_ENTRY_H__ */
diff --git a/panels/info/hostname-helper.c b/shell/hostname-helper.c
similarity index 100%
rename from panels/info/hostname-helper.c
rename to shell/hostname-helper.c
diff --git a/panels/info/hostname-helper.h b/shell/hostname-helper.h
similarity index 100%
rename from panels/info/hostname-helper.h
rename to shell/hostname-helper.h
diff --git a/panels/info/hostnames-test.txt b/shell/hostnames-test.txt
similarity index 100%
rename from panels/info/hostnames-test.txt
rename to shell/hostnames-test.txt
diff --git a/panels/info/test-hostname.c b/shell/test-hostname.c
similarity index 100%
rename from panels/info/test-hostname.c
rename to shell/test-hostname.c



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