[gnome-color-manager] Add a default button to copy the profiles system-wide using PolicyKit
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add a default button to copy the profiles system-wide using PolicyKit
- Date: Fri, 1 Jan 2010 18:48:05 +0000 (UTC)
commit 09d7c8d1add9c60bae1592d27aa552f30bea654c
Author: Richard Hughes <richard hughsie com>
Date: Fri Jan 1 18:47:33 2010 +0000
Add a default button to copy the profiles system-wide using PolicyKit
data/gcm-prefs.ui | 18 ++++++++++++-
src/gcm-prefs.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/data/gcm-prefs.ui b/data/gcm-prefs.ui
index 97beba0..e88c9f2 100644
--- a/data/gcm-prefs.ui
+++ b/data/gcm-prefs.ui
@@ -1606,6 +1606,21 @@
</packing>
</child>
<child>
+ <object class="GtkButton" id="button_default">
+ <property name="label" translatable="yes">_Set default</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Save these profiles for all users</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkButton" id="button_close">
<property name="label">gtk-close</property>
<property name="visible">True</property>
@@ -1616,7 +1631,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
@@ -1630,6 +1645,7 @@
</child>
<action-widgets>
<action-widget response="0">button_help</action-widget>
+ <action-widget response="0">button_default</action-widget>
<action-widget response="0">button_close</action-widget>
</action-widgets>
</object>
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index b6ea05d..1089d7e 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -92,6 +92,77 @@ gcm_prefs_close_cb (GtkWidget *widget, gpointer data)
}
/**
+ * gcm_prefs_set_default:
+ **/
+static gboolean
+gcm_prefs_set_default (GcmDevice *device)
+{
+ GError *error = NULL;
+ gboolean ret;
+ gchar *cmdline = NULL;
+ gchar *filename = NULL;
+ gchar *id = NULL;
+ const gchar *install_cmd = "/usr/sbin/gcm-install-system-wide";
+
+ /* get device properties */
+ g_object_get (device,
+ "profile-filename", &filename,
+ "id", &id,
+ NULL);
+
+ /* nothing set */
+ if (filename == NULL)
+ goto out;
+
+ /* run using PolicyKit */
+ cmdline = g_strdup_printf ("pkexec %s --id %s \"%s\"", install_cmd, id, filename);
+ egg_debug ("running: %s", cmdline);
+ ret = g_spawn_command_line_sync (cmdline, NULL, NULL, NULL, &error);
+ if (!ret) {
+ egg_warning ("failed to set default: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+out:
+ g_free (id);
+ g_free (cmdline);
+ g_free (filename);
+ return ret;
+}
+
+/**
+ * gcm_prefs_default_cb:
+ **/
+static void
+gcm_prefs_default_cb (GtkWidget *widget, gpointer data)
+{
+ GPtrArray *array = NULL;
+ GcmDevice *device;
+ GcmDeviceType type;
+ gboolean ret;
+ guint i;
+
+ /* set for each output */
+ array = gcm_client_get_devices (gcm_client);
+ for (i=0; i<array->len; i++) {
+ device = g_ptr_array_index (array, i);
+ g_object_get (device,
+ "type", &type,
+ NULL);
+
+ /* not a xrandr panel */
+ if (type != GCM_DEVICE_TYPE_DISPLAY)
+ continue;
+
+ /* set for this device */
+ ret = gcm_prefs_set_default (device);
+ if (!ret)
+ break;
+ }
+ g_ptr_array_unref (array);
+}
+
+/**
* gcm_prefs_help_cb:
**/
static void
@@ -2530,6 +2601,9 @@ main (int argc, char **argv)
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
g_signal_connect (widget, "clicked",
G_CALLBACK (gcm_prefs_close_cb), loop);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_default"));
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gcm_prefs_default_cb), loop);
widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
g_signal_connect (widget, "clicked",
G_CALLBACK (gcm_prefs_help_cb), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]