gnome-power-manager r2792 - in trunk: . data src



Author: rhughes
Date: Mon May 12 15:10:50 2008
New Revision: 2792
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2792&view=rev

Log:
2008-05-12  Richard Hughes  <richard hughsie com>

* configure.ac:
* data/gpm-prefs.glade:
* src/Makefile.am:
* src/gpm-prefs-core.c: (pk_prefs_set_defaults_cb),
(gpk_prefs_create_custom_widget), (gpk_prefs_setup_policykit),
(gpm_prefs_init):
Rework a patch from Matthias Clasen adding a default button for GConf settings.
This option requires an optional dep on polkit-gnome.


Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/data/gpm-prefs.glade
   trunk/src/Makefile.am
   trunk/src/gpm-prefs-core.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Mon May 12 15:10:50 2008
@@ -63,6 +63,7 @@
 LIBPANEL_REQUIRED=2.0.0
 GSTREAMER_REQUIRED=0.10
 XRANDR_REQUIRED=1.2.0
+POLKIT_GNOME_REQUIRED=0.8
 
 dnl ---------------------------------------------------------------------------
 dnl - Make above strings available for packaging files (e.g. rpm spec files)
@@ -82,6 +83,7 @@
 AC_SUBST(LIBPANEL_REQUIRED)
 AC_SUBST(GSTREAMER_REQUIRED)
 AC_SUBST(XRANDR_REQUIRED)
+AC_SUBST(POLKIT_GNOME_REQUIRED)
 
 dnl ---------------------------------------------------------------------------
 dnl - Check library dependencies
@@ -204,6 +206,23 @@
 AM_CONDITIONAL([HAVE_TESTS], [test $have_tests = yes])
 
 dnl ---------------------------------------------------------------------------
+dnl - Build gconf default button?
+dnl ---------------------------------------------------------------------------
+AC_ARG_ENABLE(gconfdefaults, [  --gconf-defaults        Allow setting gconf default settings],
+              enable_gconfdefaults=$enableval,enable_gconfdefaults=yes)
+AC_MSG_CHECKING([whether to support gconf defaults])
+have_gconfdefaults=no
+if test x$enable_gconfdefaults = xyes ; then
+    PKG_CHECK_MODULES(POLKIT_GNOME, \
+                      polkit-gnome >= $POLKIT_GNOME_REQUIRED)
+    AC_SUBST(POLKIT_GNOME_CFLAGS)
+    AC_SUBST(POLKIT_GNOME_LIBS)
+    have_gconfdefaults=yes
+    AC_DEFINE(HAVE_GCONF_DEFAULTS, 1, [Define if have policykit-gnome])
+fi
+AM_CONDITIONAL([HAVE_GCONF_DEFAULTS], [test $have_gconfdefaults = yes])
+
+dnl ---------------------------------------------------------------------------
 dnl - Build applets
 dnl ---------------------------------------------------------------------------
 AC_ARG_ENABLE(applets, [  --enable-applets        Build the extra power applets],enable_applets=$enableval,enable_applets=yes)
@@ -578,6 +597,7 @@
         PolicyKit support:         ${have_polkit}
         XEVENTS support:           ${have_xevents}
         Self test support:         ${have_tests}
+        GConf default support:     ${have_gconfdefaults}
         Docbook support:           ${enable_docbook_docs}
         documentation dir:         $DOCDIR
         dbus-1 system.d dir:       $DBUS_SYS_DIR

Modified: trunk/data/gpm-prefs.glade
==============================================================================
--- trunk/data/gpm-prefs.glade	(original)
+++ trunk/data/gpm-prefs.glade	Mon May 12 15:10:50 2008
@@ -1081,6 +1081,7 @@
           <widget class="GtkHButtonBox" id="hbuttonbox_main">
             <property name="visible">True</property>
             <property name="spacing">12</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
             <child>
               <widget class="GtkButton" id="button_help">
                 <property name="visible">True</property>
@@ -1090,95 +1091,16 @@
                 <property name="use_stock">True</property>
                 <property name="response_id">0</property>
               </widget>
-            </child>
-            <child>
-              <widget class="GtkButton" id="button_reset_default">
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="response_id">0</property>
-                <child>
-                  <widget class="GtkAlignment" id="alignment42">
-                    <property name="visible">True</property>
-                    <property name="xscale">0</property>
-                    <property name="yscale">0</property>
-                    <child>
-                      <widget class="GtkHBox" id="hbox1">
-                        <property name="visible">True</property>
-                        <property name="spacing">2</property>
-                        <child>
-                          <widget class="GtkImage" id="image1">
-                            <property name="visible">True</property>
-                            <property name="stock">gtk-undo</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkLabel" id="label95">
-                            <property name="visible">True</property>
-                            <property name="label">_Reset to defaults</property>
-                            <property name="use_underline">True</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
               <packing>
-                <property name="position">1</property>
+                <property name="secondary">True</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="button_make_default">
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="response_id">0</property>
-                <child>
-                  <widget class="GtkAlignment" id="alignment43">
-                    <property name="visible">True</property>
-                    <property name="xscale">0</property>
-                    <property name="yscale">0</property>
-                    <child>
-                      <widget class="GtkHBox" id="hbox2">
-                        <property name="visible">True</property>
-                        <property name="spacing">2</property>
-                        <child>
-                          <widget class="GtkImage" id="image2">
-                            <property name="visible">True</property>
-                            <property name="stock">gtk-media-record</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkLabel" id="label96">
-                            <property name="visible">True</property>
-                            <property name="label" translatable="yes">Make _default</property>
-                            <property name="use_underline">True</property>
-                          </widget>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
+              <widget class="Custom" id="button_default">
+                <property name="visible">True</property>
               </widget>
               <packing>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
             <child>
@@ -1191,7 +1113,7 @@
                 <property name="response_id">0</property>
               </widget>
               <packing>
-                <property name="position">3</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </widget>

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon May 12 15:10:50 2008
@@ -18,6 +18,7 @@
 	$(LIBNOTIFY_CFLAGS)				\
 	$(GTKUNIQUE_CFLAGS)				\
 	$(GSTREAMER_CFLAGS)				\
+	$(POLKIT_GNOME_CFLAGS)				\
 	-DBINDIR=\"$(bindir)\"			 	\
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"	\
 	-DDATADIR=\"$(datadir)\"			\
@@ -112,6 +113,7 @@
 	$(GNOME_LIBS)					\
 	$(HAL_LIBS)					\
 	$(DBUS_LIBS)					\
+	$(POLKIT_GNOME_LIBS)				\
 	$(GPM_EXTRA_LIBS)				\
 	$(LOCAL_LIBHAL_LIBS)				\
 	$(LOCAL_LIBDBUS_LIBS)				\

Modified: trunk/src/gpm-prefs-core.c
==============================================================================
--- trunk/src/gpm-prefs-core.c	(original)
+++ trunk/src/gpm-prefs-core.c	Mon May 12 15:10:50 2008
@@ -44,6 +44,10 @@
 #include "gpm-screensaver.h"
 #include "gpm-prefs-server.h"
 
+#ifdef HAVE_GCONF_DEFAULTS
+#include <polkit-gnome/polkit-gnome.h>
+#endif
+
 static void     gpm_prefs_class_init (GpmPrefsClass *klass);
 static void     gpm_prefs_init       (GpmPrefs      *prefs);
 static void     gpm_prefs_finalize   (GObject	    *object);
@@ -64,6 +68,9 @@
 	gboolean		 can_hibernate;
 	GpmConf			*conf;
 	GpmScreensaver		*screensaver;
+#ifdef HAVE_GCONF_DEFAULTS
+	PolKitGnomeAction	*default_action;
+#endif
 };
 
 enum {
@@ -957,6 +964,92 @@
 	}
 }
 
+#ifdef HAVE_GCONF_DEFAULTS
+/**
+ * pk_prefs_set_defaults_cb:
+ **/
+static void
+pk_prefs_set_defaults_cb (PolKitGnomeAction *default_action, GpmPrefs *prefs)
+{
+	DBusGProxy *proxy;
+	DBusGConnection *connection;
+	GError *error;
+	gchar *keys[5] = {
+		"/apps/gnome-power-manager/actions",
+		"/apps/gnome-power-manager/ui",
+		"/apps/gnome-power-manager/buttons",
+		"/apps/gnome-power-manager/backlight",
+		"/apps/gnome-power-manager/timeout"
+	};
+
+	error = NULL;
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (error != NULL) {
+		g_warning ("failed to get system bus connection: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+
+	proxy = dbus_g_proxy_new_for_name (connection,
+					   "org.gnome.GConf.Defaults",
+					   "/",
+					   "org.gnome.GConf.Defaults");
+	if (proxy == NULL) {
+		g_warning ("Cannot connect to defaults mechanism");
+		return;
+	}
+
+	dbus_g_proxy_call (proxy, "SetSystem", &error,
+			   G_TYPE_STRV, keys,
+			   G_TYPE_STRV, NULL,
+			   G_TYPE_INVALID, G_TYPE_INVALID);
+
+	g_object_unref (proxy);
+}
+
+/**
+ * gpk_prefs_create_custom_widget:
+ **/
+static GtkWidget *
+gpk_prefs_create_custom_widget (GladeXML *xml, gchar *func_name, gchar *name,
+				     gchar *string1, gchar *string2,
+				     gint int1, gint int2, gpointer user_data)
+{
+	GpmPrefs *prefs = GPM_PREFS (user_data);
+	if (strcmp (name, "button_default") == 0) {
+		return polkit_gnome_action_create_button (prefs->priv->default_action);
+	}
+	gpm_warning ("name unknown=%s", name);
+	return NULL;
+}
+
+/**
+ * gpk_prefs_setup_policykit:
+ *
+ * We have to do this before the glade stuff if done as the custom handler needs the actions setup
+ **/
+static void
+gpk_prefs_setup_policykit (GpmPrefs *prefs)
+{
+	PolKitAction *pk_action;
+
+	g_return_if_fail (GPM_IS_PREFS (prefs));
+
+	/* set default */
+	pk_action = polkit_action_new ();
+	polkit_action_set_action_id (pk_action, "org.freedesktop.packagekit.set-defaults");
+	prefs->priv->default_action = polkit_gnome_action_new_default ("set-defaults", pk_action,
+								       _("Make Default"), NULL);
+	g_object_set (prefs->priv->default_action,
+		      "no-icon-name", GTK_STOCK_FLOPPY,
+		      "auth-icon-name", GTK_STOCK_FLOPPY,
+		      "yes-icon-name", GTK_STOCK_FLOPPY,
+		      "self-blocked-icon-name", GTK_STOCK_FLOPPY,
+		      NULL);
+	polkit_action_unref (pk_action);
+}
+#endif
+
 /**
  * gpm_prefs_init:
  * @prefs: This prefs class instance
@@ -990,6 +1083,14 @@
 	prefs->priv->can_hibernate = gpm_dbus_method_bool ("CanHibernate");
 	gpm_debug ("caps=%i", caps);
 
+#ifdef HAVE_GCONF_DEFAULTS
+	/* use custom widgets */
+	glade_set_custom_handler (gpk_prefs_create_custom_widget, prefs);
+
+	/* we have to do this before we connect up the glade file */
+	gpk_prefs_setup_policykit (prefs);
+#endif
+
 	prefs->priv->glade_xml = glade_xml_new (GPM_DATA "/gpm-prefs.glade", NULL, NULL);
 	if (prefs->priv->glade_xml == NULL) {
 		g_error ("Cannot find 'gpm-prefs.glade'");
@@ -1014,6 +1115,11 @@
 	g_signal_connect (widget, "clicked",
 			  G_CALLBACK (gpm_prefs_help_cb), prefs);
 
+#ifdef HAVE_GCONF_DEFAULTS
+	g_signal_connect (prefs->priv->default_action, "activate",
+			  G_CALLBACK (pk_prefs_set_defaults_cb), prefs);
+#endif
+
 	prefs_setup_ac (prefs);
 	prefs_setup_battery (prefs);
 	prefs_setup_ups (prefs);



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