[nautilus] Convert executable-text-activation to GSettings



commit cf4f7f10baa305cc3cbacb0b3c27c1eb45ae65f4
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Jul 22 15:34:18 2010 +0200

    Convert executable-text-activation to GSettings

 libnautilus-private/nautilus-global-preferences.c |   24 ------
 libnautilus-private/nautilus-global-preferences.h |    2 +-
 libnautilus-private/nautilus-mime-actions.c       |    8 +-
 src/nautilus-file-management-properties.c         |   87 ++++++++++++++++++++-
 4 files changed, 88 insertions(+), 33 deletions(-)
---
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index ca23905..07b9f96 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -111,21 +111,6 @@ static EelEnumerationEntry click_policy_enum_entries[] = {
 	}
 };
 
-static EelEnumerationEntry executable_text_activation_enum_entries[] = {
-	{ "launch",
-	  N_("E_xecute files when they are clicked"),
-	  NAUTILUS_EXECUTABLE_TEXT_LAUNCH
-	},
-	{ "display",
-	  N_("Display _files when they are clicked"),
-	  NAUTILUS_EXECUTABLE_TEXT_DISPLAY
-	},
-	{ "ask",
-	  N_("_Ask each time"),
-	  NAUTILUS_EXECUTABLE_TEXT_ASK
-	}
-};
-
 static EelEnumerationEntry search_bar_type_enum_entries[] = {
 	{ "search by text",
 	  N_("Search for files by file name only"),
@@ -256,12 +241,6 @@ static const PreferenceDefault preference_defaults[] = {
 	  NULL, NULL,
 	  "click_policy"
 	},
-	{ NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
-	  PREFERENCE_STRING,
-	  "ask",
-	  NULL, NULL,
-	  "executable_text_activation"
-	},
 	{ NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION,
 	  PREFERENCE_BOOLEAN,
 	  GINT_TO_POINTER (TRUE)
@@ -542,9 +521,6 @@ global_preferences_register_enumerations (void)
 	eel_enumeration_register ("default_zoom_level",
 				  default_zoom_level_enum_entries,
 				  G_N_ELEMENTS (default_zoom_level_enum_entries));
-	eel_enumeration_register ("executable_text_activation",
-				  executable_text_activation_enum_entries,
-				  G_N_ELEMENTS (executable_text_activation_enum_entries));
 	eel_enumeration_register ("file_size",
 				  file_size_enum_entries,
 				  G_N_ELEMENTS (file_size_enum_entries));
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 1322750..cfe0860 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -96,7 +96,7 @@ typedef enum
 #define NAUTILUS_PREFERENCES_CLICK_POLICY			"preferences/click_policy"
 
 /* Activating executable text files */
-#define NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION		"preferences/executable_text_activation"
+#define NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION		"executable-text-activation"
 
 /* Installing new packages when unknown mime type activated */
 #define NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION		"preferences/install_mime_activation"
diff --git a/libnautilus-private/nautilus-mime-actions.c b/libnautilus-private/nautilus-mime-actions.c
index 1884f9b..a24df92 100644
--- a/libnautilus-private/nautilus-mime-actions.c
+++ b/libnautilus-private/nautilus-mime-actions.c
@@ -757,8 +757,8 @@ get_executable_text_file_action (GtkWindow *parent_window, NautilusFile *file)
 
 	g_assert (nautilus_file_contains_text (file));
 
-	preferences_value = eel_preferences_get_enum 
-		(NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
+	preferences_value = g_settings_get_enum	(nautilus_preferences,
+						 NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
 	switch (preferences_value) {
 	case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
 		return ACTIVATION_ACTION_LAUNCH;
@@ -814,8 +814,8 @@ get_default_executable_text_file_action (void)
 {
 	int preferences_value;
 
-	preferences_value = eel_preferences_get_enum 
-		(NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
+	preferences_value = g_settings_get_enum	(nautilus_preferences,
+						 NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
 	switch (preferences_value) {
 	case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
 		return ACTIVATION_ACTION_LAUNCH;
diff --git a/src/nautilus-file-management-properties.c b/src/nautilus-file-management-properties.c
index 5e2bf54..dc0f3ed 100644
--- a/src/nautilus-file-management-properties.c
+++ b/src/nautilus-file-management-properties.c
@@ -723,6 +723,84 @@ bind_builder_enum (GtkBuilder *builder,
 				      enum_values, NULL);
 }
 
+typedef struct {
+	GtkWidget *button;
+	const char *value;
+	const char *key;
+	GSettings *settings;
+} RadioBinding;
+
+static void
+radio_binding_setting_changed (GSettings   *settings,
+			       const gchar *key,
+			       gpointer     user_data)
+{
+	RadioBinding *binding = user_data;
+	char *value;
+
+	value = g_settings_get_string (settings, key);
+
+	if (strcmp (value, binding->value) == 0) {
+		/* This will unset the currently active, no need
+		   to do that manually */
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (binding->button), TRUE);
+	}
+	g_free (value);
+}
+
+static void
+radio_binding_button_toggled (GtkToggleButton *toggle_button,
+			      RadioBinding *binding)
+{
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (binding->button))) {
+		g_settings_set_string (binding->settings, binding->key, binding->value);
+	}
+}
+
+static void
+free_radio_binding (gpointer	 data,
+		    GClosure	*closure)
+{
+	RadioBinding *binding = data;
+
+	g_object_unref (binding->settings);
+	g_free (binding);
+}
+
+static void
+bind_builder_radio (GtkBuilder *builder,
+		    GSettings *settings,
+		    const char **widget_names,
+		    const char *prefs,
+		    const char **values)
+{
+	GtkWidget *button;
+	int i;
+	char *detailed_signal;
+	RadioBinding *binding;
+
+	detailed_signal = g_strdup_printf ("changed::%s", prefs);
+
+	for (i = 0; widget_names[i] != NULL; i++) {
+		button = GTK_WIDGET (gtk_builder_get_object (builder, widget_names[i]));
+
+		binding = g_new (RadioBinding, 1);
+		binding->button = button;
+		binding->value = values[i];
+		binding->key = prefs;
+		binding->settings = g_object_ref (settings);
+
+		g_signal_connect (settings, detailed_signal,
+				  G_CALLBACK(radio_binding_setting_changed),
+				  binding);
+
+		g_signal_connect_data (G_OBJECT (button), "toggled",
+				       G_CALLBACK (radio_binding_button_toggled),
+				       binding, free_radio_binding, 0);
+	}
+}
+
+
 static  void
 nautilus_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow *window)
 {
@@ -833,14 +911,15 @@ nautilus_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow
 			   NAUTILUS_PREFERENCES_DATE_FORMAT,
 			   (const char **) date_format_values);
 
+
 	eel_preferences_builder_connect_string_enum_radio_button (builder,
 								  (const char **) click_behavior_components,
 								  NAUTILUS_PREFERENCES_CLICK_POLICY,
 								  (const char **) click_behavior_values);
-	eel_preferences_builder_connect_string_enum_radio_button (builder,
-								  (const char **) executable_text_components,
-								  NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
-								  (const char **) executable_text_values);
+	bind_builder_radio (builder, nautilus_preferences,
+			    (const char **) executable_text_components,
+			    NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
+			    (const char **) executable_text_values);
 
 	eel_preferences_builder_connect_uint_enum (builder,
 						   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_THUMBNAIL_LIMIT_WIDGET,



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