[gnome-packagekit] Port the preferences dialog to libgnome-control-center



commit a22a05aacf8867bb2be31288a1d97e32ae2e43ae
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jun 19 10:26:53 2010 +0100

    Port the preferences dialog to libgnome-control-center

 configure.ac                           |    6 +
 contrib/gnome-packagekit.spec.in       |    6 +-
 data/gpk-prefs.desktop.in              |    4 +-
 data/gpk-prefs.ui                      |   16 --
 man/Makefile.am                        |    4 -
 man/gpk-prefs.sgml                     |   78 ---------
 po/POTFILES.in                         |    2 +-
 src/Makefile.am                        |   25 ++-
 src/{gpk-prefs.c => cc-update-panel.c} |  284 ++++++++++++++------------------
 src/cc-update-panel.h                  |   54 ++++++
 10 files changed, 208 insertions(+), 271 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 36317e9..f1c0cb5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,12 @@ PKG_CHECK_MODULES(UPOWER, [
 PKG_CHECK_MODULES(CANBERRA, libcanberra-gtk3 >= 0.10)
 PKG_CHECK_MODULES(X11, x11)
 
+dnl Required for the properties window
+PKG_CHECK_MODULES(CONTROL_CENTER, [
+ libgnome-control-center >= 2.31.3])
+PANELS_DIR="${libdir}/control-center-1/panels"
+AC_SUBST(PANELS_DIR)
+
 dnl **** Check for LIBNOTIFY ****
 PKG_CHECK_MODULES(LIBNOTIFY, libnotify3 >= 0.4.3, has_libnotify=yes, has_libnotify=no)
 AM_CONDITIONAL(HAVE_LIBNOTIFY, test x$libnotify = xyes)
diff --git a/contrib/gnome-packagekit.spec.in b/contrib/gnome-packagekit.spec.in
index 4d2f565..c84adc8 100644
--- a/contrib/gnome-packagekit.spec.in
+++ b/contrib/gnome-packagekit.spec.in
@@ -51,6 +51,7 @@ BuildRequires: fontconfig-devel
 BuildRequires: libcanberra-devel
 BuildRequires: libgudev1-devel
 BuildRequires: upower-devel >= 0.9.0
+BuildRequires: control-center
 
 %description
 gnome-packagekit provides session applications for the PackageKit API.
@@ -88,6 +89,9 @@ for i in gpk-application gpk-update-viewer gpk-install-file gpk-log gpk-prefs gp
     $RPM_BUILD_ROOT%{_datadir}/applications/$i.desktop
 done
 
+rm -f $RPM_BUILD_ROOT%{_libdir}/control-center-1/panels/*.a
+rm -f $RPM_BUILD_ROOT%{_libdir}/control-center-1/panels/*.la
+
 %find_lang %name --with-gnome
 
 %clean
@@ -117,11 +121,11 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
 %{_bindir}/gpk-application
 %{_bindir}/gpk-install-*
 %{_bindir}/gpk-log
-%{_bindir}/gpk-prefs
 %{_bindir}/gpk-repo
 %{_bindir}/gpk-update-icon
 %{_bindir}/gpk-update-viewer
 %{_bindir}/gpk-dbus-service
+%{_libdir}/control-center-1/panels/*.so
 %dir %{_datadir}/gnome-packagekit
 %{_datadir}/gnome-packagekit/gpk-application.ui
 %{_datadir}/gnome-packagekit/gpk-client.ui
diff --git a/data/gpk-prefs.desktop.in b/data/gpk-prefs.desktop.in
index 54a16e5..f9dc2c1 100644
--- a/data/gpk-prefs.desktop.in
+++ b/data/gpk-prefs.desktop.in
@@ -2,10 +2,10 @@
 _Name=Software Updates
 _Comment=Change software update preferences
 Icon=gpk-prefs
-Exec=gpk-prefs
+Exec=gnome-control-center update
 Terminal=false
 Type=Application
 Categories=Settings;X-GNOME-SystemSettings;
 NotShowIn=KDE;
 StartupNotify=true
-
+X-GNOME-Settings-Panel=update
diff --git a/data/gpk-prefs.ui b/data/gpk-prefs.ui
index f952314..9203dcb 100644
--- a/data/gpk-prefs.ui
+++ b/data/gpk-prefs.ui
@@ -224,21 +224,6 @@
                 <property name="secondary">True</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="button_close">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -250,7 +235,6 @@
     </child>
     <action-widgets>
       <action-widget response="0">button_help</action-widget>
-      <action-widget response="0">button_close</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/man/Makefile.am b/man/Makefile.am
index 344b717..23427a4 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -5,7 +5,6 @@ EXTRA_DIST =						\
 	gpk-install-mime-type.sgml			\
 	gpk-install-package-name.sgml			\
 	gpk-install-provide-file.sgml			\
-	gpk-prefs.sgml					\
 	gpk-repo.sgml					\
 	gpk-update-icon.sgml				\
 	gpk-update-viewer.sgml
@@ -18,7 +17,6 @@ man_MANS =						\
 	gpk-install-mime-type.1			\
 	gpk-install-package-name.1			\
 	gpk-install-provide-file.1			\
-	gpk-prefs.1					\
 	gpk-repo.1					\
 	gpk-update-icon.1				\
 	gpk-update-viewer.1
@@ -37,8 +35,6 @@ gpk-install-provide-file.1: gpk-install-provide-file.sgml
 	docbook2man $? > /dev/null
 gpk-install-mime-type.1: gpk-install-mime-type.sgml
 	docbook2man $? > /dev/null
-gpk-prefs.1: gpk-prefs.sgml
-	docbook2man $? > /dev/null
 gpk-repo.1: gpk-repo.sgml
 	docbook2man $? > /dev/null
 gpk-update-icon.1: gpk-update-icon.sgml
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5a58a0c..60c9ba6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,6 +23,7 @@ data/gpk-update-icon.desktop.in
 data/gpk-update-viewer.desktop.in
 [type: gettext/glade]data/gpk-update-viewer.ui
 python/packagekit/gtkwidgets.py
+src/cc-update-panel.c
 src/gpk-application.c
 src/gpk-application-main.c
 src/gpk-backend-status.c
@@ -46,7 +47,6 @@ src/gpk-install-package-name.c
 src/gpk-install-provide-file.c
 src/gpk-log.c
 src/gpk-modal-dialog.c
-src/gpk-prefs.c
 src/gpk-repo.c
 src/gpk-service-pack.c
 src/gpk-update-icon.c
diff --git a/src/Makefile.am b/src/Makefile.am
index ea16d12..c5ae9dd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ INCLUDES =						\
 	$(PACKAGEKIT_CFLAGS)				\
 	$(GUDEV_CFLAGS)					\
 	$(GNOME_MENUS_CFLAGS)				\
+	$(CONTROL_CENTER_CFLAGS)			\
 	-DI_KNOW_THE_UPOWER_API_IS_SUBJECT_TO_CHANGE	\
 	-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE	\
 	-DG_UDEV_API_IS_SUBJECT_TO_CHANGE		\
@@ -27,10 +28,12 @@ INCLUDES =						\
 	-DGPK_DATA=\"$(pkgdatadir)\"			\
 	$(NULL)
 
+ccpanelsdir = $(PANELS_DIR)
+ccpanels_LTLIBRARIES = libupdate.la
+
 bin_PROGRAMS =						\
 	gpk-application					\
 	gpk-repo					\
-	gpk-prefs					\
 	gpk-service-pack				\
 	gpk-install-catalog				\
 	gpk-install-local-file				\
@@ -41,7 +44,7 @@ bin_PROGRAMS =						\
 	gpk-update-viewer				\
 	gpk-log						\
 	gpk-backend-status				\
-	gpk-dbus-service					\
+	gpk-dbus-service				\
 	$(NULL)
 
 noinst_LIBRARIES = libgpkshared.a
@@ -205,14 +208,20 @@ gpk_service_pack_LDADD =				\
 	$(shared_LIBS)					\
 	$(NULL)
 
-gpk_prefs_SOURCES =					\
-	gpk-prefs.c					\
+libupdate_la_SOURCES =					\
+	egg-debug.h					\
+	egg-debug.c					\
+	cc-update-panel.c				\
+	cc-update-panel.h				\
 	$(NULL)
 
-gpk_prefs_LDADD =					\
-	libgpkshared.a					\
-	$(shared_LIBS)					\
-	$(NULL)
+libupdate_la_LIBADD =					\
+	$(GLIB_LIBS)					\
+	$(CONTROL_CENTER_LIBS)				\
+	-lm
+
+libupdate_la_LDFLAGS = -avoid-version -module
+libupdate_la_CFLAGS = $(WARNINGFLAGS)
 
 gpk_update_viewer_SOURCES =				\
 	gpk-update-viewer-main.c			\
diff --git a/src/gpk-prefs.c b/src/cc-update-panel.c
similarity index 58%
rename from src/gpk-prefs.c
rename to src/cc-update-panel.c
index fe58b9a..475b96e 100644
--- a/src/gpk-prefs.c
+++ b/src/cc-update-panel.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -19,25 +19,34 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <locale.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-#include <math.h>
-#include <string.h>
-#include <dbus/dbus-glib.h>
 #include <packagekit-glib2/packagekit.h>
 
-#include <gpk-common.h>
-#include <gpk-gnome.h>
-
 #include "egg-debug.h"
+
+#include "cc-update-panel.h"
+
+#include "gpk-common.h"
+#include "gpk-gnome.h"
 #include "gpk-enum.h"
 
+struct _CcUpdatePanelPrivate {
+	GtkBuilder		*builder;
+	GSettings		*settings;
+};
+
+G_DEFINE_DYNAMIC_TYPE (CcUpdatePanel, cc_update_panel, CC_TYPE_PANEL)
+
+static void cc_update_panel_finalize (GObject *object);
+
+#define CC_UPDATE_PREFS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_UPDATE_PANEL, CcUpdatePanelPrivate))
+
+
 /* TRANSLATORS: check once an hour */
 #define PK_FREQ_HOURLY_TEXT		_("Hourly")
 /* TRANSLATORS: check once a day */
@@ -59,23 +68,20 @@
 #define GPK_PREFS_VALUE_DAILY		(60*60*24)
 #define GPK_PREFS_VALUE_WEEKLY		(60*60*24*7)
 
-static GtkBuilder *builder = NULL;
-static GSettings *settings = NULL;
-
 /**
- * gpk_prefs_help_cb:
+ * cc_update_panel_help_cb:
  **/
 static void
-gpk_prefs_help_cb (GtkWidget *widget, gpointer data)
+cc_update_panel_help_cb (GtkWidget *widget, CcUpdatePanel *panel)
 {
 	gpk_gnome_help ("prefs");
 }
 
 /**
- * gpk_prefs_update_freq_combo_changed:
+ * cc_update_panel_update_freq_combo_changed:
  **/
 static void
-gpk_prefs_update_freq_combo_changed (GtkWidget *widget, gpointer data)
+cc_update_panel_update_freq_combo_changed (GtkWidget *widget, CcUpdatePanel *panel)
 {
 	gchar *value;
 	guint freq = 0;
@@ -93,15 +99,15 @@ gpk_prefs_update_freq_combo_changed (GtkWidget *widget, gpointer data)
 		g_assert (FALSE);
 
 	egg_debug ("Changing %s to %i", GPK_SETTINGS_FREQUENCY_GET_UPDATES, freq);
-	g_settings_set_int (settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES, freq);
+	g_settings_set_int (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES, freq);
 	g_free (value);
 }
 
 /**
- * gpk_prefs_upgrade_freq_combo_changed:
+ * cc_update_panel_upgrade_freq_combo_changed:
  **/
 static void
-gpk_prefs_upgrade_freq_combo_changed (GtkWidget *widget, gpointer data)
+cc_update_panel_upgrade_freq_combo_changed (GtkWidget *widget, CcUpdatePanel *panel)
 {
 	gchar *value;
 	guint freq = 0;
@@ -117,15 +123,15 @@ gpk_prefs_upgrade_freq_combo_changed (GtkWidget *widget, gpointer data)
 		g_assert (FALSE);
 
 	egg_debug ("Changing %s to %i", GPK_SETTINGS_FREQUENCY_GET_UPGRADES, freq);
-	g_settings_set_int (settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES, freq);
+	g_settings_set_int (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES, freq);
 	g_free (value);
 }
 
 /**
- * gpk_prefs_update_combo_changed:
+ * cc_update_panel_update_combo_changed:
  **/
 static void
-gpk_prefs_update_combo_changed (GtkWidget *widget, gpointer data)
+cc_update_panel_update_combo_changed (GtkWidget *widget, CcUpdatePanel *panel)
 {
 	gchar *value;
 	const gchar *action;
@@ -148,15 +154,15 @@ gpk_prefs_update_combo_changed (GtkWidget *widget, gpointer data)
 
 	action = gpk_update_enum_to_text (update);
 	egg_debug ("Changing %s to %s", GPK_SETTINGS_AUTO_UPDATE, action);
-	g_settings_set_string (settings, GPK_SETTINGS_AUTO_UPDATE, action);
+	g_settings_set_string (panel->priv->settings, GPK_SETTINGS_AUTO_UPDATE, action);
 	g_free (value);
 }
 
 /**
- * gpk_prefs_set_combo_model_simple_text:
+ * cc_update_panel_set_combo_model_simple_text:
  **/
 static void
-gpk_prefs_update_freq_combo_simple_text (GtkWidget *combo_box)
+cc_update_panel_update_freq_combo_simple_text (GtkWidget *combo_box)
 {
 	GtkCellRenderer *cell;
 	GtkListStore *store;
@@ -173,25 +179,25 @@ gpk_prefs_update_freq_combo_simple_text (GtkWidget *combo_box)
 }
 
 /**
- * gpk_prefs_update_freq_combo_setup:
+ * cc_update_panel_update_freq_combo_setup:
  **/
 static void
-gpk_prefs_update_freq_combo_setup (void)
+cc_update_panel_update_freq_combo_setup (CcUpdatePanel *panel)
 {
 	guint value;
 	gboolean is_writable;
 	GtkWidget *widget;
 
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_check"));
-	is_writable = g_settings_is_writable (settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES);
-	value = g_settings_get_int (settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES);
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "combobox_check"));
+	is_writable = g_settings_is_writable (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES);
+	value = g_settings_get_int (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPDATES);
 	egg_debug ("value from settings %i", value);
 
 	/* do we have permission to write? */
 	gtk_widget_set_sensitive (widget, is_writable);
 
 	/* set a simple text model */
-	gpk_prefs_update_freq_combo_simple_text (widget);
+	cc_update_panel_update_freq_combo_simple_text (widget);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_HOURLY_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_DAILY_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_WEEKLY_TEXT);
@@ -209,29 +215,29 @@ gpk_prefs_update_freq_combo_setup (void)
 
 	/* only do this after else we redraw the window */
 	g_signal_connect (G_OBJECT (widget), "changed",
-			  G_CALLBACK (gpk_prefs_update_freq_combo_changed), NULL);
+			  G_CALLBACK (cc_update_panel_update_freq_combo_changed), NULL);
 }
 
 /**
- * gpk_prefs_upgrade_freq_combo_setup:
+ * cc_update_panel_upgrade_freq_combo_setup:
  **/
 static void
-gpk_prefs_upgrade_freq_combo_setup (void)
+cc_update_panel_upgrade_freq_combo_setup (CcUpdatePanel *panel)
 {
 	guint value;
 	gboolean is_writable;
 	GtkWidget *widget;
 
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_upgrade"));
-	is_writable = g_settings_is_writable (settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES);
-	value = g_settings_get_int (settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES);
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "combobox_upgrade"));
+	is_writable = g_settings_is_writable (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES);
+	value = g_settings_get_int (panel->priv->settings, GPK_SETTINGS_FREQUENCY_GET_UPGRADES);
 	egg_debug ("value from settings %i", value);
 
 	/* do we have permission to write? */
 	gtk_widget_set_sensitive (widget, is_writable);
 
 	/* set a simple text model */
-	gpk_prefs_update_freq_combo_simple_text (widget);
+	cc_update_panel_update_freq_combo_simple_text (widget);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_DAILY_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_WEEKLY_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_FREQ_NEVER_TEXT);
@@ -246,23 +252,23 @@ gpk_prefs_upgrade_freq_combo_setup (void)
 
 	/* only do this after else we redraw the window */
 	g_signal_connect (G_OBJECT (widget), "changed",
-			  G_CALLBACK (gpk_prefs_upgrade_freq_combo_changed), NULL);
+			  G_CALLBACK (cc_update_panel_upgrade_freq_combo_changed), NULL);
 }
 
 /**
- * gpk_prefs_auto_update_combo_setup:
+ * cc_update_panel_auto_update_combo_setup:
  **/
 static void
-gpk_prefs_auto_update_combo_setup (void)
+cc_update_panel_auto_update_combo_setup (CcUpdatePanel *panel)
 {
 	gchar *value;
 	gboolean is_writable;
 	GtkWidget *widget;
 	GpkUpdateEnum update;
 
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_install"));
-	is_writable = g_settings_is_writable (settings, GPK_SETTINGS_AUTO_UPDATE);
-	value = g_settings_get_string (settings, GPK_SETTINGS_AUTO_UPDATE);
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "combobox_install"));
+	is_writable = g_settings_is_writable (panel->priv->settings, GPK_SETTINGS_AUTO_UPDATE);
+	value = g_settings_get_string (panel->priv->settings, GPK_SETTINGS_AUTO_UPDATE);
 	if (value == NULL) {
 		egg_warning ("invalid schema, please re-install");
 		return;
@@ -275,7 +281,7 @@ gpk_prefs_auto_update_combo_setup (void)
 	gtk_widget_set_sensitive (widget, is_writable);
 
 	/* set a simple text model */
-	gpk_prefs_update_freq_combo_simple_text (widget);
+	cc_update_panel_update_freq_combo_simple_text (widget);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_ALL_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_SECURITY_TEXT);
 	gtk_combo_box_append_text (GTK_COMBO_BOX (widget), PK_UPDATE_NONE_TEXT);
@@ -284,14 +290,14 @@ gpk_prefs_auto_update_combo_setup (void)
 
 	/* only do this after else we redraw the window */
 	g_signal_connect (G_OBJECT (widget), "changed",
-			  G_CALLBACK (gpk_prefs_update_combo_changed), NULL);
+			  G_CALLBACK (cc_update_panel_update_combo_changed), NULL);
 }
 
 /**
- * gpk_prefs_notify_network_state_cb:
+ * cc_update_panel_notify_network_state_cb:
  **/
 static void
-gpk_prefs_notify_network_state_cb (PkControl *control, GParamSpec *pspec, gpointer data)
+cc_update_panel_notify_network_state_cb (PkControl *control, GParamSpec *pspec, CcUpdatePanel *panel)
 {
 	GtkWidget *widget;
 	PkNetworkEnum state;
@@ -300,7 +306,7 @@ gpk_prefs_notify_network_state_cb (PkControl *control, GParamSpec *pspec, gpoint
 	g_object_get (control,
 		      "network-state", &state,
 		      NULL);
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_mobile_broadband"));
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "hbox_mobile_broadband"));
 	if (state == PK_NETWORK_ENUM_MOBILE)
 		gtk_widget_show (widget);
 	else
@@ -308,10 +314,10 @@ gpk_prefs_notify_network_state_cb (PkControl *control, GParamSpec *pspec, gpoint
 }
 
 /**
- * gpk_prefs_get_properties_cb:
+ * cc_update_panel_get_properties_cb:
  **/
 static void
-gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GMainLoop *loop)
+cc_update_panel_get_properties_cb (GObject *object, GAsyncResult *res, CcUpdatePanel *panel)
 {
 	GtkWidget *widget;
 	GError *error = NULL;
@@ -326,7 +332,6 @@ gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GMainLoop *loop
 		/* TRANSLATORS: backend is broken, and won't tell us what it supports */
 		g_print ("%s: %s\n", _("Exiting as backend details could not be retrieved"), error->message);
 		g_error_free (error);
-		g_main_loop_quit (loop);
 		goto out;
 	}
 
@@ -337,160 +342,117 @@ gpk_prefs_get_properties_cb (GObject *object, GAsyncResult *res, GMainLoop *loop
 		      NULL);
 
 	/* only show label on mobile broadband */
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "hbox_mobile_broadband"));
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "hbox_mobile_broadband"));
 	gtk_widget_set_visible (widget, (state == PK_NETWORK_ENUM_MOBILE));
 
 	/* hide if not supported */
 	if (!pk_bitfield_contain (roles, PK_ROLE_ENUM_GET_DISTRO_UPGRADES)) {
-		widget = GTK_WIDGET (gtk_builder_get_object (builder, "label_upgrade"));
+		widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "label_upgrade"));
 		gtk_widget_hide (widget);
-		widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_upgrade"));
+		widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "combobox_upgrade"));
 		gtk_widget_hide (widget);
 	}
 out:
 	return;
 }
 
-/**
- * gpk_prefs_close_cb:
- **/
 static void
-gpk_prefs_close_cb (GtkWidget *widget, gpointer data)
+cc_update_panel_class_init (CcUpdatePanelClass *klass)
 {
-	GMainLoop *loop = (GMainLoop *) data;
-	g_main_loop_quit (loop);
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	g_type_class_add_private (klass, sizeof (CcUpdatePanelPrivate));
+	object_class->finalize = cc_update_panel_finalize;
 }
 
-/**
- * gpk_prefs_delete_event_cb:
- **/
-static gboolean
-gpk_prefs_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
+static void
+cc_update_panel_class_finalize (CcUpdatePanelClass *klass)
 {
-	gpk_prefs_close_cb (widget, data);
-	return FALSE;
 }
 
-/**
- * main:
- **/
-int
-main (int argc, char *argv[])
+static void
+cc_update_panel_finalize (GObject *object)
+{
+	CcUpdatePanel *panel = CC_UPDATE_PANEL (object);
+	g_object_unref (panel->priv->builder);
+	g_object_unref (panel->priv->settings);
+	G_OBJECT_CLASS (cc_update_panel_parent_class)->finalize (object);
+}
+
+static void
+cc_update_panel_init (CcUpdatePanel *panel)
 {
-	gboolean program_version = FALSE;
-	GOptionContext *context;
 	GtkWidget *main_window;
 	GtkWidget *widget;
 	PkControl *control;
-	GtkApplication *application;
 	guint retval;
-	guint xid = 0;
 	GError *error = NULL;
-	GMainLoop *loop;
-
-	const GOptionEntry options[] = {
-		{ "version", '\0', 0, G_OPTION_ARG_NONE, &program_version,
-		  _("Show the program version and exit"), NULL },
-		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
-		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
-		  _("Set the parent window to make this modal"), NULL },
-		{ NULL}
-	};
 
-	setlocale (LC_ALL, "");
-
-	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-	textdomain (GETTEXT_PACKAGE);
-
-	if (! g_thread_supported ())
-		g_thread_init (NULL);
-	dbus_g_thread_init ();
-	g_type_init ();
-	gtk_init (&argc, &argv);
-
-	context = g_option_context_new (NULL);
-	/* TRANSLATORS: program name, an application to set per-user policy for updates */
-	g_option_context_set_summary(context, _("Software Update Preferences"));
-	g_option_context_add_main_entries (context, options, NULL);
-	g_option_context_add_group (context, egg_debug_get_option_group ());
-	g_option_context_add_group (context, gtk_get_option_group (TRUE));
-	g_option_context_parse (context, &argc, &argv, NULL);
-	g_option_context_free (context);
-
-	if (program_version) {
-		g_print (VERSION "\n");
-		return 0;
-	}
-
-	/* are we already activated? */
-	application = gtk_application_new ("org.freedesktop.PackageKit.Prefs", &argc, &argv);
+	panel->priv = CC_UPDATE_PREFS_GET_PRIVATE (panel);
 
 	/* load settings */
-	settings = g_settings_new (GPK_SETTINGS_SCHEMA);
+	panel->priv->settings = g_settings_new (GPK_SETTINGS_SCHEMA);
 
 	/* get actions */
-	loop = g_main_loop_new (NULL, FALSE);
 	control = pk_control_new ();
 	g_signal_connect (control, "notify::network-state",
-			  G_CALLBACK (gpk_prefs_notify_network_state_cb), NULL);
+			  G_CALLBACK (cc_update_panel_notify_network_state_cb), panel);
 
 	/* get UI */
-	builder = gtk_builder_new ();
-	retval = gtk_builder_add_from_file (builder, GPK_DATA "/gpk-prefs.ui", &error);
+	panel->priv->builder = gtk_builder_new ();
+	retval = gtk_builder_add_from_file (panel->priv->builder, GPK_DATA "/gpk-prefs.ui", &error);
 	if (retval == 0) {
 		egg_warning ("failed to load ui: %s", error->message);
 		g_error_free (error);
-		goto out_build;
+		goto out;
 	}
 
-	main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_prefs"));
-	gtk_application_add_window (application, GTK_WINDOW (main_window));
-
-	/* Hide window first so that the dialogue resizes itself without redrawing */
-	gtk_widget_hide (main_window);
-	gtk_window_set_icon_name (GTK_WINDOW (main_window), GPK_ICON_SOFTWARE_UPDATE_PREFS);
-	g_signal_connect (main_window, "delete_event",
-			  G_CALLBACK (gpk_prefs_delete_event_cb), loop);
-
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "checkbutton_mobile_broadband"));
-	g_settings_bind (settings,
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "checkbutton_mobile_broadband"));
+	g_settings_bind (panel->priv->settings,
 			 GPK_SETTINGS_CONNECTION_USE_MOBILE,
 			 widget, "active",
 			 G_SETTINGS_BIND_DEFAULT);
 
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
-	g_signal_connect (widget, "clicked",
-			  G_CALLBACK (gpk_prefs_close_cb), loop);
-	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
+	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "button_help"));
 	g_signal_connect (widget, "clicked",
-			  G_CALLBACK (gpk_prefs_help_cb), NULL);
+			  G_CALLBACK (cc_update_panel_help_cb), panel);
 
 	/* update the combo boxes */
-	gpk_prefs_update_freq_combo_setup ();
-	gpk_prefs_upgrade_freq_combo_setup ();
-	gpk_prefs_auto_update_combo_setup ();
+	cc_update_panel_update_freq_combo_setup (panel);
+	cc_update_panel_upgrade_freq_combo_setup (panel);
+	cc_update_panel_auto_update_combo_setup (panel);
 
-	gtk_widget_show (main_window);
+	/* get some data */
+	pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) cc_update_panel_get_properties_cb, panel);
+out:
+	g_object_unref (control);
+	main_window = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "dialog_prefs"));
+	widget = gtk_dialog_get_content_area (GTK_DIALOG (main_window));
+	gtk_widget_unparent (widget);
 
-	/* set the parent window if it is specified */
-	if (xid != 0) {
-		egg_debug ("Setting xid %i", xid);
-		gpk_window_set_parent_xid (GTK_WINDOW (main_window), xid);
-	}
+	gtk_container_add (GTK_CONTAINER (panel), widget);
+}
 
-	/* get some data */
-	pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) gpk_prefs_get_properties_cb, loop);
+void
+cc_update_panel_register (GIOModule *module)
+{
+	cc_update_panel_register_type (G_TYPE_MODULE (module));
+	g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
+					CC_TYPE_UPDATE_PANEL,
+					"update", 0);
+}
 
-	/* wait */
-	g_main_loop_run (loop);
+/* GIO extension stuff */
+void
+g_io_module_load (GIOModule *module)
+{
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-out_build:
-	g_main_loop_unref (loop);
-	g_object_unref (control);
-	g_object_unref (builder);
-	g_object_unref (settings);
-	g_object_unref (application);
+	/* register the panel */
+	cc_update_panel_register (module);
+}
 
-	return 0;
+void
+g_io_module_unload (GIOModule *module)
+{
 }
diff --git a/src/cc-update-panel.h b/src/cc-update-panel.h
new file mode 100644
index 0000000..c8b9b67
--- /dev/null
+++ b/src/cc-update-panel.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _CC_UPDATE_PANEL_H
+#define _CC_UPDATE_PANEL_H
+
+#include <libgnome-control-center/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_UPDATE_PANEL		cc_update_panel_get_type()
+#define CC_UPDATE_PANEL(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_UPDATE_PANEL, CcUpdatePanel))
+#define CC_UPDATE_PANEL_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_UPDATE_PANEL, CcUpdatePanelClass))
+#define CC_IS_UPDATE_PANEL(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_UPDATE_PANEL))
+#define CC_IS_UPDATE_PANEL_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_UPDATE_PANEL))
+#define CC_UPDATE_PANEL_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_UPDATE_PANEL, CcUpdatePanelClass))
+
+typedef struct _CcUpdatePanel		CcUpdatePanel;
+typedef struct _CcUpdatePanelClass	CcUpdatePanelClass;
+typedef struct _CcUpdatePanelPrivate	CcUpdatePanelPrivate;
+
+struct _CcUpdatePanel {
+	CcPanel			 parent;
+	CcUpdatePanelPrivate	*priv;
+};
+
+struct _CcUpdatePanelClass {
+	CcPanelClass parent_class;
+};
+
+GType cc_update_panel_get_type	(void) G_GNUC_CONST;
+void  cc_update_panel_register	(GIOModule		*module);
+
+G_END_DECLS
+
+#endif /* _CC_UPDATE_PANEL_H */



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