File gconf-editor-vendor-defaults-support.patch of Package gconf-editor

Support for editing of vendor defaults (fate#301464, bgo#522055).

Many vendors create default configuration, which consists of four system path
elements:

* Keys defined in schemas
* Defaults defined by vendor
* Defaults defined by system administrator
* Mandatory defined by system administrator

It allows to provide vendor branding and make "Keys defined in schemas"
unchanged.

Attached patch allows to set vendor defaults using gconf-editor.

In the current version, GUI for vendor defaults is equal to system defaults.

================================================================================
--- configure.in
+++ configure.in
@@ -66,6 +66,14 @@
 AC_DEFINE_UNQUOTED(GCONF_MANDATORY_SOURCE, "$GCONF_MANDATORY_SOURCE", [GConf mandatory source])
 AC_MSG_RESULT([Using config source $GCONF_MANDATORY_SOURCE for mandatory values])
 
+GCONF_VENDOR_SOURCE=`echo $GCONF_DEFAULTS_SOURCE | sed -e s/gconf.xml.defaults/gconf.xml.vendor/`
+AC_ARG_WITH(gconf-vendor-source,
+  AC_HELP_STRING([--with-gconf-vendor-source],
+                 [The GConf source of the vendor defaults values]),
+        GCONF_VENDOR_SOURCE="$withval",)
+AC_DEFINE_UNQUOTED(GCONF_VENDOR_SOURCE, "$GCONF_VENDOR_SOURCE", [GConf vendor defaults source])
+AC_MSG_RESULT([Using config source $GCONF_VENDOR_SOURCE for vendor defaults values])
+
 AC_CONFIG_FILES([
 Makefile
 data/Makefile
@@ -81,4 +89,5 @@
 echo "
 Configuration Sources:
 GConf default values source: ${GCONF_DEFAULTS_SOURCE}
-GConf mandatory values source: ${GCONF_MANDATORY_SOURCE}"
+GConf mandatory values source: ${GCONF_MANDATORY_SOURCE}
+GConf vendor defaults values source: ${GCONF_VENDOR_SOURCE}"
--- src/gconf-editor-application.c
+++ src/gconf-editor-application.c
@@ -73,6 +73,15 @@
 		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (gconfwindow->ui_manager, "/GConfKeyPopupMenu/MandatoryKey"),
 					  FALSE);
 	
+	if (!gconf_util_can_edit_vendor ()) {
+		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (gconfwindow->ui_manager, "/GConfKeyPopupMenu/VendorKey"),
+					  FALSE);
+		gtk_action_set_sensitive (gtk_ui_manager_get_action (gconfwindow->ui_manager, "/GConfEditorMenu/FileMenu/NewVendorWindow"),
+					  FALSE);
+	} else if (gconfwindow->type == GCONF_EDITOR_WINDOW_TYPE_VENDOR)
+		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (gconfwindow->ui_manager, "/GConfKeyPopupMenu/VendorKey"),
+					  FALSE);
+	
 	g_signal_connect (window, "destroy",
 			  G_CALLBACK (gconf_editor_application_window_destroyed), NULL);
 	
--- src/gconf-editor-window.c
+++ src/gconf-editor-window.c
@@ -357,6 +357,15 @@
 }
 
 static void
+gconf_editor_window_new_vendor_window (GtkAction *action, GtkWidget *callback_data)
+{
+	GtkWidget *new_window;
+
+	new_window = gconf_editor_application_create_editor_window (GCONF_EDITOR_WINDOW_TYPE_VENDOR);
+	gtk_widget_show (new_window);
+}
+
+static void
 help_cb (GtkAction *action, GtkWidget *callback_data)
 {
         GError *error = NULL;
@@ -717,6 +726,41 @@
   g_object_unref (client);
 }
 
+static void
+gconf_editor_popup_window_set_as_vendor (GtkAction *action, GtkWidget *callback_data)
+{
+  GConfEditorWindow *gconfwindow = GCONF_EDITOR_WINDOW (callback_data);
+  GtkWindow *window = GTK_WINDOW (callback_data);
+
+  GError *error = NULL;
+  GtkTreeIter iter;
+  GConfValue *value;
+  char *path = NULL;
+  GConfClient *client;
+  
+
+  client = gconf_editor_window_get_client (GCONF_EDITOR_WINDOW_TYPE_VENDOR);
+  if (client == NULL) {
+    g_print ("Could not create GConf client\n");
+    return;
+  }
+	
+  gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (gconfwindow->list_view)),
+                                   NULL, &iter);
+  gtk_tree_model_get (gconfwindow->sorted_list_model, &iter,
+                      GCONF_LIST_MODEL_KEY_PATH_COLUMN, &path,
+                      GCONF_LIST_MODEL_VALUE_COLUMN, &value,
+                      -1);
+
+  gconf_client_set (client, path, value, NULL);
+
+  gconf_client_suggest_sync (client, &error);
+  if (error) {
+    gconf_editor_window_popup_error_dialog (window, _("Could not sync value. Error was:\n%s"), error);
+  }
+  g_object_unref (client);
+}
+
 static GtkActionEntry entries[] = {
 	{ "FileMenu", NULL, N_("_File"), NULL, NULL, NULL },
 	{ "EditMenu", NULL, N_("_Edit"), NULL, NULL, NULL },
@@ -733,6 +777,9 @@
 	{ "NewMandatoryWindow", GTK_STOCK_NEW, N_("New _Mandatory Window"), "<control>M", 
           N_("Open a new Configuration Editor window editing system mandatory settings"), 
 	  G_CALLBACK (gconf_editor_window_new_mandatory_window) },
+	{ "NewVendorWindow", GTK_STOCK_NEW, N_("New _Vendor Defaults Window"), "<control>B", 
+          N_("Open a new Configuration Editor window editing vendor defaults settings"), 
+	  G_CALLBACK (gconf_editor_window_new_vendor_window) },
 	{ "CloseWindow", GTK_STOCK_CLOSE, N_("_Close Window"), "<control>W", N_("Close this window"), 
 	  G_CALLBACK (gconf_editor_window_close_window) },
 	{ "QuitGConfEditor", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q", N_("Quit the Configuration Editor"), 
@@ -764,7 +811,9 @@
 	{ "DefaultKey", NULL, N_("Set as _Default"), NULL, N_("Set the selected key to be the default"),
 	  G_CALLBACK (gconf_editor_popup_window_set_as_default) },
 	{ "MandatoryKey", NULL, N_("Set as _Mandatory"), NULL, N_("Set the selected key to the mandatory"),
-	  G_CALLBACK (gconf_editor_popup_window_set_as_mandatory) }	
+	  G_CALLBACK (gconf_editor_popup_window_set_as_mandatory) },
+	{ "VendorKey", NULL, N_("Set as _Vendor Default"), NULL, N_("Set the selected key to be the vendor default"),
+	  G_CALLBACK (gconf_editor_popup_window_set_as_vendor) }	
 };
 
 static const char *ui_description = 
@@ -774,6 +823,7 @@
 	"			<menuitem action='NewWindow'/>"
 	"			<menuitem action='NewDefaultsWindow'/>"
 	"			<menuitem action='NewMandatoryWindow'/>"
+	"			<menuitem action='NewVendorWindow'/>"
 	"			<menuitem action='CloseWindow'/>"
 	"			<separator/>"
 	"			<menuitem action='QuitGConfEditor'/>"
@@ -803,6 +853,8 @@
 	"		<menuitem action='DefaultKey'/>"	
 	"		<separator/>"
 	"		<menuitem action='MandatoryKey'/>"	
+	"		<separator/>"
+	"		<menuitem action='VendorKey'/>"	
 	"	</popup>"
 	"</ui>";
 
@@ -810,6 +862,7 @@
 	"/GConfEditorMenu/FileMenu/NewWindow",
 	"/GConfEditorMenu/FileMenu/NewDefaultsWindow",
 	"/GConfEditorMenu/FileMenu/NewMandatoryWindow",
+	"/GConfEditorMenu/FileMenu/NewVendorWindow",
 	"/GConfEditorMenu/FileMenu/CloseWindow",
 	"/GConfEditorMenu/FileMenu/QuitGConfEditor",
 
@@ -850,6 +903,9 @@
 	case GCONF_EDITOR_WINDOW_TYPE_MANDATORY:
 		base_title = _("Configuration Editor (Mandatory settings)");
 		break;
+	case GCONF_EDITOR_WINDOW_TYPE_VENDOR:
+		base_title = _("Configuration Editor (Vendor Defaults settings)");
+		break;
 	default:
 		base_title = _("Configuration Editor");
 	}
@@ -910,6 +966,8 @@
 						  TRUE);
 			gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/MandatoryKey"), 
 						  TRUE);
+			gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/VendorKey"), 
+						  TRUE);
 			
 			gtk_tree_path_free (path);
 		}
@@ -922,6 +980,8 @@
 						  FALSE);
 			gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/MandatoryKey"), 
 						  FALSE);
+			gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/VendorKey"), 
+						  FALSE);
 
 		}
 		
@@ -1011,6 +1071,8 @@
 					  TRUE);
 		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/MandatoryKey"), 
 					  TRUE);
+		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/VendorKey"), 
+					  TRUE);
 			
 	}
 	else {
@@ -1022,6 +1084,8 @@
 					  FALSE);
 		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/MandatoryKey"), 
 					  FALSE);
+		gtk_widget_set_sensitive (gtk_ui_manager_get_widget (window->ui_manager, "/GConfKeyPopupMenu/VendorKey"), 
+					  FALSE);
 
 	}
 	
@@ -1314,6 +1378,16 @@
 		client = gconf_client_get_for_engine (engine);
 		gconf_engine_unref (engine);
 		break;
+	case GCONF_EDITOR_WINDOW_TYPE_VENDOR:
+		engine = gconf_engine_get_for_address (GCONF_VENDOR_SOURCE, &error);
+		if (error) {
+			gconf_editor_window_popup_error_dialog (NULL,
+			_("Cannot create GConf engine. Error was:\n%s"), error);
+			return NULL;
+		}
+		client = gconf_client_get_for_engine (engine);
+		gconf_engine_unref (engine);
+		break;
 	default:
 		g_assert_not_reached ();
 	}
@@ -1341,6 +1415,9 @@
 			case GCONF_EDITOR_WINDOW_TYPE_MANDATORY:
 				gtk_window_set_title (GTK_WINDOW (gconfwindow), _("Configuration Editor (Mandatory settings)"));
 				break;
+			case GCONF_EDITOR_WINDOW_TYPE_VENDOR:
+				gtk_window_set_title (GTK_WINDOW (gconfwindow), _("Configuration Editor (Vendor Defaults settings)"));
+				break;
 			default:
 				gtk_window_set_title (GTK_WINDOW (gconfwindow), _("Configuration Editor"));
 			}
@@ -1406,7 +1483,7 @@
 					 g_param_spec_int ("type",
 					 _("Type"),
 					 _("The Configuration Editor window type."),
-					 GCONF_EDITOR_WINDOW_TYPE_NORMAL, GCONF_EDITOR_WINDOW_TYPE_MANDATORY,
+					 GCONF_EDITOR_WINDOW_TYPE_NORMAL, GCONF_EDITOR_WINDOW_TYPE_VENDOR,
 					 GCONF_EDITOR_WINDOW_TYPE_NORMAL, 
 					 (G_PARAM_WRITABLE |
 					 G_PARAM_CONSTRUCT_ONLY)));
--- src/gconf-editor-window.h
+++ src/gconf-editor-window.h
@@ -40,7 +40,8 @@
 enum {
         GCONF_EDITOR_WINDOW_TYPE_NORMAL,
         GCONF_EDITOR_WINDOW_TYPE_DEFAULTS,
-        GCONF_EDITOR_WINDOW_TYPE_MANDATORY
+        GCONF_EDITOR_WINDOW_TYPE_MANDATORY,
+        GCONF_EDITOR_WINDOW_TYPE_VENDOR
 };
 
 enum {
--- src/gconf-util.c
+++ src/gconf-util.c
@@ -151,5 +151,16 @@
 	return can_edit_mandatory;
 }
 
+gboolean
+gconf_util_can_edit_vendor (void)
+{
+	static int can_edit_vendor = GCONF_NOT_SET;
+
+	if (can_edit_vendor == GCONF_NOT_SET)
+		can_edit_vendor = can_edit_source (GCONF_VENDOR_SOURCE);
+
+	return can_edit_vendor;
+}
+
 	
 
--- src/gconf-util.h
+++ src/gconf-util.h
@@ -34,5 +34,6 @@
 GConfSchema *gconf_client_get_schema_for_key (GConfClient *client, const char *key);
 gboolean gconf_util_can_edit_defaults (void);
 gboolean gconf_util_can_edit_mandatory (void);
+gboolean gconf_util_can_edit_vendor (void);
 
 #endif /* __GCONF_UTIL_H__ */
openSUSE Build Service is sponsored by