[nautilus] Convert preview settings to gsettings



commit 75ade49a17470a86354eb8b591212d512c2ab08b
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Jul 22 18:28:07 2010 +0200

    Convert preview settings to gsettings

 libnautilus-private/nautilus-file.c               |   28 ++++---
 libnautilus-private/nautilus-global-preferences.c |   28 -------
 libnautilus-private/nautilus-global-preferences.h |    8 +-
 src/file-manager/fm-directory-view.c              |    9 +-
 src/file-manager/fm-icon-view.c                   |    7 +-
 src/nautilus-file-management-properties.c         |   87 +++++++++++++++++----
 6 files changed, 101 insertions(+), 66 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 16b77f2..ee3165f 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -4012,7 +4012,7 @@ get_custom_icon (NautilusFile *file)
 }
 
 
-static guint cached_thumbnail_limit;
+static guint64 cached_thumbnail_limit;
 int cached_thumbnail_size;
 static int show_image_thumbs;
 
@@ -8028,14 +8028,16 @@ nautilus_extract_top_left_text (const char *text,
 	}
  done:
 	g_free (text_copy);
- 
+
 	return g_string_free(buffer, FALSE);
 }
 
 static void
 thumbnail_limit_changed_callback (gpointer user_data)
 {
-	cached_thumbnail_limit = eel_preferences_get_uint (NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT);
+	g_settings_get (nautilus_preferences,
+			NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
+			"t", &cached_thumbnail_limit);
 
 	/* Tell the world that icons might have changed. We could invent a narrower-scope
 	 * signal to mean only "thumbnails might have changed" if this ends up being slow
@@ -8059,7 +8061,7 @@ thumbnail_size_changed_callback (gpointer user_data)
 static void
 show_thumbnails_changed_callback (gpointer user_data)
 {
-	show_image_thumbs = eel_preferences_get_enum (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS);
+	show_image_thumbs = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS);
 
 	/* Tell the world that icons might have changed. We could invent a narrower-scope
 	 * signal to mean only "thumbnails might have changed" if this ends up being slow
@@ -8068,7 +8070,7 @@ show_thumbnails_changed_callback (gpointer user_data)
 	emit_change_signals_for_all_files_in_all_directories ();
 }
 
-static void       
+static void
 mime_type_data_changed_callback (GObject *signaller, gpointer user_data)
 {
 	/* Tell the world that icons might have changed. We could invent a narrower-scope
@@ -8084,7 +8086,7 @@ icon_theme_changed_callback (GtkIconTheme *icon_theme,
 {
 	/* Clear all pixmap caches as the icon => pixmap lookup changed */
 	nautilus_icon_info_clear_caches ();
-	
+
 	/* Tell the world that icons might have changed. We could invent a narrower-scope
 	 * signal to mean only "thumbnails might have changed" if this ends up being slow
 	 * for some reason.
@@ -8157,17 +8159,19 @@ nautilus_file_class_init (NautilusFileClass *class)
 				      &date_format_pref);
 
 	thumbnail_limit_changed_callback (NULL);
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
-				      thumbnail_limit_changed_callback,
-				      NULL);
+	g_signal_connect_swapped (nautilus_preferences,
+				  "changed::" NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
+				  G_CALLBACK (thumbnail_limit_changed_callback),
+				  NULL);
 	thumbnail_size_changed_callback (NULL);
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE,
 				      thumbnail_size_changed_callback,
 				      NULL);
 	show_thumbnails_changed_callback (NULL);
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
-				      show_thumbnails_changed_callback,
-				      NULL);
+	g_signal_connect_swapped (nautilus_preferences,
+				  "changed::" NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
+				  G_CALLBACK (show_thumbnails_changed_callback),
+				  NULL);
 
 	icon_theme = gtk_icon_theme_get_default ();
 	g_signal_connect_object (icon_theme,
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index d822aad..4dbb9a3 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -63,13 +63,6 @@ typedef enum
 	PREFERENCE_STRING_ARRAY
 } PreferenceType;
 
-/* Enumerations used to qualify some INTEGER preferences */
-static EelEnumerationEntry speed_tradeoff_enum_entries[] = {
-	{ "always",	    N_("_Always"),		NAUTILUS_SPEED_TRADEOFF_ALWAYS },
-	{ "local_only",	    N_("_Local File Only"),	NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY },
-	{ "never",	    N_("_Never"),		NAUTILUS_SPEED_TRADEOFF_NEVER }
-};
-
 static EelEnumerationEntry default_zoom_level_enum_entries[] = {
 	/* xgettext:no-c-format */
 	{ "smallest",	    N_("25%"),		NAUTILUS_ZOOM_LEVEL_SMALLEST },
@@ -185,24 +178,6 @@ static const PreferenceDefault preference_defaults[] = {
 	 * for FTP. If we make this fast enough for FTP in particular,
 	 * we should change this default to ALWAYS.
 	 */
-	{ NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
-	  PREFERENCE_STRING,
-	  "local_only",
-	  NULL, NULL,
-	  "speed_tradeoff"
-	},
-	{ NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
-	  PREFERENCE_INTEGER,
-	  GINT_TO_POINTER(10485760),
-	  NULL, NULL,
-	  "file_size"
-	},
-	{ NAUTILUS_PREFERENCES_PREVIEW_SOUND,
-	  PREFERENCE_STRING,
-	  "local_only",
-	  NULL, NULL,
-	  "speed_tradeoff"
-	},
 	{ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
 	  PREFERENCE_STRING_ARRAY,
 	  "size,date_modified,type",
@@ -404,9 +379,6 @@ global_preferences_register_enumerations (void)
 	eel_enumeration_register ("file_size",
 				  file_size_enum_entries,
 				  G_N_ELEMENTS (file_size_enum_entries));
-	eel_enumeration_register ("speed_tradeoff",
-				  speed_tradeoff_enum_entries,
-				  G_N_ELEMENTS (speed_tradeoff_enum_entries));
 	eel_enumeration_register ("standard_font_size",
 				  standard_font_size_entries,
 				  G_N_ELEMENTS (standard_font_size_entries));
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 7800b4f..89630aa 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -45,7 +45,7 @@ G_BEGIN_DECLS
 #define NAUTILUS_PREFERENCES_SIDE_PANE_BACKGROUND_URI           "side-pane-background-uri"
 
 /* Automount options */
-#define NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT	                "automount"
+#define NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT			"automount"
 #define NAUTILUS_PREFERENCES_MEDIA_AUTOMOUNT_OPEN		"automount-open"
 
 /* Autorun options */
@@ -200,9 +200,9 @@ typedef enum
 
 #define NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS		"show-icon-text"
 #define NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS "show-directory-item-counts"
-#define NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS	"preferences/show_image_thumbnails"
-#define NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT	"preferences/thumbnail_limit"
-#define NAUTILUS_PREFERENCES_PREVIEW_SOUND		"preferences/preview_sound"
+#define NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS	"show-image-thumbnails"
+#define NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT	"thumbnail-limit"
+#define NAUTILUS_PREFERENCES_PREVIEW_SOUND		"preview-sound"
 
 typedef enum
 {
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 633d346..469aa24 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -1989,8 +1989,9 @@ fm_directory_view_init (FMDirectoryView *view)
 				      schedule_update_menus_callback, view);
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
 				      text_attribute_names_changed_callback, view);
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
-				      image_display_policy_changed_callback, view);
+	g_signal_connect_swapped (nautilus_preferences,
+				  "changed::" NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
+				  G_CALLBACK (image_display_policy_changed_callback), view);
 	g_signal_connect_swapped (nautilus_preferences,
 				  "changed::" NAUTILUS_PREFERENCES_CLICK_POLICY,
 				  G_CALLBACK(click_policy_changed_callback),
@@ -2108,8 +2109,8 @@ fm_directory_view_finalize (GObject *object)
 					 schedule_update_menus_callback, view);
 	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
 					 text_attribute_names_changed_callback, view);
-	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
-					 image_display_policy_changed_callback, view);
+	g_signal_handlers_disconnect_by_func (nautilus_preferences,
+					      image_display_policy_changed_callback, view);
 	g_signal_handlers_disconnect_by_func (nautilus_preferences,
 					      click_policy_changed_callback, view);
 	g_signal_handlers_disconnect_by_func (nautilus_preferences,
diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c
index 033ca4c..8f6d9ed 100644
--- a/src/file-manager/fm-icon-view.c
+++ b/src/file-manager/fm-icon-view.c
@@ -3061,9 +3061,10 @@ fm_icon_view_init (FMIconView *icon_view)
 						 NAUTILUS_ICON_LAYOUT_L_R_T_B);
 
 	if (!setup_sound_preview) {
-		eel_preferences_add_auto_enum (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
-					       &preview_sound_auto_value);
-		
+		eel_g_settings_add_auto_enum (nautilus_preferences,
+					      NAUTILUS_PREFERENCES_PREVIEW_SOUND,
+					      &preview_sound_auto_value);
+
 		setup_sound_preview = TRUE;
 	}
 
diff --git a/src/nautilus-file-management-properties.c b/src/nautilus-file-management-properties.c
index fce46c1..4cddb69 100644
--- a/src/nautilus-file-management-properties.c
+++ b/src/nautilus-file-management-properties.c
@@ -141,7 +141,7 @@ static const char * const executable_text_values[] = {
 	NULL
 };
 
-static const guint thumbnail_limit_values[] = {
+static const guint64 thumbnail_limit_values[] = {
 	102400,
 	512000,
 	1048576,
@@ -151,7 +151,7 @@ static const guint thumbnail_limit_values[] = {
 	104857600,
 	1073741824,
 	2147483648U,
- 	4294967295U
+	4294967295U
 };
 
 static const char * const icon_captions_components[] = {
@@ -755,6 +755,63 @@ bind_builder_enum (GtkBuilder *builder,
 }
 
 typedef struct {
+	const guint64 *values;
+	int n_values;
+} UIntEnumBinding;
+
+static gboolean
+uint_enum_get_mapping (GValue             *value,
+		       GVariant           *variant,
+		       gpointer            user_data)
+{
+	UIntEnumBinding *binding = user_data;
+	guint64 v;
+	int i;
+
+	v = g_variant_get_uint64 (variant);
+	for (i = 0; i < binding->n_values; i++) {
+		if (binding->values[i] >= v) {
+			g_value_set_int (value, i);
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+static GVariant *
+uint_enum_set_mapping (const GValue       *value,
+		       const GVariantType *expected_type,
+		       gpointer            user_data)
+{
+	UIntEnumBinding *binding = user_data;
+
+	return g_variant_new_uint64 (binding->values[g_value_get_int (value)]);
+}
+
+static void
+bind_builder_uint_enum (GtkBuilder *builder,
+			GSettings *settings,
+			const char *widget_name,
+			const char *prefs,
+			const guint64 *values,
+			int n_values)
+{
+	UIntEnumBinding *binding;
+
+	binding = g_new (UIntEnumBinding, 1);
+	binding->values = values;
+	binding->n_values = n_values;
+
+	g_settings_bind_with_mapping (settings, prefs,
+				      gtk_builder_get_object (builder, widget_name),
+				      "active", G_SETTINGS_BIND_DEFAULT,
+				      uint_enum_get_mapping,
+				      uint_enum_set_mapping,
+				      binding, g_free);
+}
+
+typedef struct {
 	GtkWidget *button;
 	const char *value;
 	const char *key;
@@ -925,14 +982,14 @@ nautilus_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow
 			   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_TEXT_WIDGET,
 			   NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
 			   (const char **) preview_values);
-	eel_preferences_builder_connect_string_enum_combo_box (builder,
-							       NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_IMAGE_WIDGET,
-							       NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
-							       (const char **) preview_values);
-	eel_preferences_builder_connect_string_enum_combo_box (builder,
-							       NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_SOUND_WIDGET,
-							       NAUTILUS_PREFERENCES_PREVIEW_SOUND,
-							       (const char **) preview_values);
+	bind_builder_enum (builder, nautilus_preferences,
+			   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_IMAGE_WIDGET,
+			   NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
+			   (const char **) preview_values);
+	bind_builder_enum (builder, nautilus_preferences,
+			   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_SOUND_WIDGET,
+			   NAUTILUS_PREFERENCES_PREVIEW_SOUND,
+			   (const char **) preview_values);
 	bind_builder_enum (builder, nautilus_preferences,
 			   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_PREVIEW_FOLDER_WIDGET,
 			   NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
@@ -952,11 +1009,11 @@ nautilus_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow
 			    NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
 			    (const char **) executable_text_values);
 
-	eel_preferences_builder_connect_uint_enum (builder,
-						   NAUTILUS_FILE_MANAGEMENT_PROPERTIES_THUMBNAIL_LIMIT_WIDGET,
-						   NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
-						   (const guint *) thumbnail_limit_values,
-						   G_N_ELEMENTS (thumbnail_limit_values));
+	bind_builder_uint_enum (builder, nautilus_preferences,
+				NAUTILUS_FILE_MANAGEMENT_PROPERTIES_THUMBNAIL_LIMIT_WIDGET,
+				NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
+				thumbnail_limit_values,
+				G_N_ELEMENTS (thumbnail_limit_values));
 
 	nautilus_file_management_properties_dialog_setup_icon_caption_page (builder);
 	nautilus_file_management_properties_dialog_setup_list_column_page (builder);



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