diff options
author | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-02-07 12:55:09 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-02-07 12:55:09 +0000 |
commit | e46f32bed42a3c00109b27a39ba3df16896f8e85 (patch) | |
tree | 81fc5141978b53e67e8d90a5bfd883a4f306aad4 | |
parent | 1d87a73e66e20e2dc41302cd9760374040e4a819 (diff) | |
download | nautilus-e46f32bed42a3c00109b27a39ba3df16896f8e85.tar.gz |
reviewed by: Pavel Cisler <pavel@eazel.com>
* libnautilus-extensions/nautilus-directory-async.c:
(show_hidden_files_changed_callback),
(show_backup_files_changed_callback),
(get_filter_options_for_directory_count):
* libnautilus-extensions/nautilus-file.c:
(show_text_in_icons_changed_callback),
(show_directory_item_count_changed_callback),
(get_speed_tradeoff_preference_for_file),
(nautilus_file_should_show_directory_item_count),
(nautilus_file_should_get_top_left_text):
* libnautilus-extensions/nautilus-theme.c:
(theme_changed_callback), (nautilus_theme_get_theme),
(nautilus_theme_get_theme_data), (nautilus_theme_get_image_path):
* src/file-manager/fm-directory-view.c:
(confirm_trash_changed_callback), (real_update_menus):
* src/file-manager/fm-icon-text-window.c:
(icon_captions_changed_callback),
(fm_get_text_attribute_names_preference_or_default):
Use calllbacks for some preferences values instead of peeking
diectly. The preferences in question here are peeked a lot during
large directory loads, even though they hardly ever change. This
should get preferences stuff mostly out of Pavel's profiles. Now,
im still working on bug 6054 which is about making peeking
preferences in general faster.
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-directory-async.c | 43 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-file.c | 107 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-theme.c | 28 | ||||
-rw-r--r-- | libnautilus-private/nautilus-directory-async.c | 43 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 107 | ||||
-rw-r--r-- | libnautilus-private/nautilus-theme.c | 28 | ||||
-rw-r--r-- | src/file-manager/fm-directory-view.c | 22 | ||||
-rw-r--r-- | src/file-manager/fm-icon-text-window.c | 39 |
9 files changed, 367 insertions, 79 deletions
@@ -1,3 +1,32 @@ +2001-02-07 Ramiro Estrugo <ramiro@eazel.com> + + reviewed by: Pavel Cisler <pavel@eazel.com> + + * libnautilus-extensions/nautilus-directory-async.c: + (show_hidden_files_changed_callback), + (show_backup_files_changed_callback), + (get_filter_options_for_directory_count): + * libnautilus-extensions/nautilus-file.c: + (show_text_in_icons_changed_callback), + (show_directory_item_count_changed_callback), + (get_speed_tradeoff_preference_for_file), + (nautilus_file_should_show_directory_item_count), + (nautilus_file_should_get_top_left_text): + * libnautilus-extensions/nautilus-theme.c: + (theme_changed_callback), (nautilus_theme_get_theme), + (nautilus_theme_get_theme_data), (nautilus_theme_get_image_path): + * src/file-manager/fm-directory-view.c: + (confirm_trash_changed_callback), (real_update_menus): + * src/file-manager/fm-icon-text-window.c: + (icon_captions_changed_callback), + (fm_get_text_attribute_names_preference_or_default): + Use calllbacks for some preferences values instead of peeking + diectly. The preferences in question here are peeked a lot during + large directory loads, even though they hardly ever change. This + should get preferences stuff mostly out of Pavel's profiles. Now, + im still working on bug 6054 which is about making peeking + preferences in general faster. + 2001-02-06 Pavel Cisler <pavel@eazel.com> reviewed by: Mike Fleming <mfleming@eazel.com> diff --git a/libnautilus-extensions/nautilus-directory-async.c b/libnautilus-extensions/nautilus-directory-async.c index 695e1ecf3..007a68096 100644 --- a/libnautilus-extensions/nautilus-directory-async.c +++ b/libnautilus-extensions/nautilus-directory-async.c @@ -1147,18 +1147,57 @@ set_file_unconfirmed (NautilusFile *file, gboolean unconfirmed) } } +static gboolean show_hidden_files = TRUE; +static gboolean show_backup_files = TRUE; + +static void +show_hidden_files_changed_callback (gpointer callback_data) +{ + show_hidden_files = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES); +} + +static void +show_backup_files_changed_callback (gpointer callback_data) +{ + show_backup_files = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES); +} + static GnomeVFSDirectoryFilterOptions get_filter_options_for_directory_count (void) { + static gboolean show_hidden_files_changed_callback_installed = FALSE; + static gboolean show_backup_files_changed_callback_installed = FALSE; GnomeVFSDirectoryFilterOptions filter_options; filter_options = GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR; + + /* Add the callback once for the life of our process */ + if (!show_hidden_files_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES, + show_hidden_files_changed_callback, + NULL); + show_hidden_files_changed_callback_installed = TRUE; + + /* Peek for the first time */ + show_hidden_files_changed_callback (NULL); + } + + /* Add the callback once for the life of our process */ + if (!show_backup_files_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES, + show_backup_files_changed_callback, + NULL); + show_backup_files_changed_callback_installed = TRUE; + + /* Peek for the first time */ + show_backup_files_changed_callback (NULL); + } - if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES)) { + if (!show_hidden_files) { filter_options |= GNOME_VFS_DIRECTORY_FILTER_NODOTFILES; } - if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES)) { + if (!show_backup_files) { filter_options |= GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES; } diff --git a/libnautilus-extensions/nautilus-file.c b/libnautilus-extensions/nautilus-file.c index 6924cf782..c720ed21c 100644 --- a/libnautilus-extensions/nautilus-file.c +++ b/libnautilus-extensions/nautilus-file.c @@ -1070,34 +1070,6 @@ nautilus_file_is_local (NautilusFile *file) return nautilus_directory_is_local (file->details->directory); } -static gboolean -get_speed_tradeoff_preference_for_file (NautilusFile *file, const char *preference_name) -{ - NautilusSpeedTradeoffValue preference_value; - - g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); - - preference_value = nautilus_preferences_get_integer (preference_name); - - if (preference_value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { - return TRUE; - } - - if (preference_value == NAUTILUS_SPEED_TRADEOFF_NEVER) { - return FALSE; - } - - g_assert (preference_value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY); - return nautilus_file_is_local (file); -} - -gboolean -nautilus_file_should_get_top_left_text (NautilusFile *file) -{ - return get_speed_tradeoff_preference_for_file - (file, NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS); -} - static void update_link (NautilusFile *link_file, NautilusFile *target_file) { @@ -2292,11 +2264,86 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type return nautilus_strdup_strftime (format, file_time); } +static NautilusSpeedTradeoffValue show_directory_item_count; +static NautilusSpeedTradeoffValue show_text_in_icons; + +static void +show_text_in_icons_changed_callback (gpointer callback_data) +{ + show_text_in_icons = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS); +} + +static void +show_directory_item_count_changed_callback (gpointer callback_data) +{ + show_directory_item_count = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS); +} + +static gboolean +get_speed_tradeoff_preference_for_file (NautilusFile *file, NautilusSpeedTradeoffValue value) +{ + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { + return TRUE; + } + + if (value == NAUTILUS_SPEED_TRADEOFF_NEVER) { + return FALSE; + } + + g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY); + return nautilus_file_is_local (file); +} + gboolean nautilus_file_should_show_directory_item_count (NautilusFile *file) { - return get_speed_tradeoff_preference_for_file - (file, NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS); + static gboolean show_directory_item_count_callback_added = FALSE; + + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + /* Add the callback once for the life of our process */ + if (!show_directory_item_count_callback_added) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS, + show_directory_item_count_changed_callback, + NULL); + show_directory_item_count_callback_added = TRUE; + + /* Peek for the first time */ + show_directory_item_count_changed_callback (NULL); + } + + return get_speed_tradeoff_preference_for_file (file, show_directory_item_count); +} + +gboolean +nautilus_file_should_get_top_left_text (NautilusFile *file) +{ + static gboolean show_text_in_icons_callback_added = FALSE; + + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + /* Add the callback once for the life of our process */ + if (!show_text_in_icons_callback_added) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS, + show_text_in_icons_changed_callback, + NULL); + show_text_in_icons_callback_added = TRUE; + + /* Peek for the first time */ + show_text_in_icons_changed_callback (NULL); + } + + if (show_text_in_icons == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { + return TRUE; + } + + if (show_text_in_icons == NAUTILUS_SPEED_TRADEOFF_NEVER) { + return FALSE; + } + + return get_speed_tradeoff_preference_for_file (file, show_text_in_icons); } /** diff --git a/libnautilus-extensions/nautilus-theme.c b/libnautilus-extensions/nautilus-theme.c index e8d09616e..fbf8ef060 100644 --- a/libnautilus-extensions/nautilus-theme.c +++ b/libnautilus-extensions/nautilus-theme.c @@ -48,11 +48,33 @@ static char *last_theme_name = NULL; static xmlDocPtr last_theme_document = NULL; static xmlDocPtr default_theme_document = NULL; +static char *theme_from_preferences = NULL; + +static void +theme_changed_callback (gpointer callback_data) +{ + g_free (theme_from_preferences); + theme_from_preferences = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); +} + /* return the current theme by asking the preferences machinery */ char * nautilus_theme_get_theme (void) { - return nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + static gboolean theme_changed_callback_installed = FALSE; + + /* Add the callback once for the life of our process */ + if (!theme_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_THEME, + theme_changed_callback, + NULL); + theme_changed_callback_installed = TRUE; + + /* Peek for the first time */ + theme_changed_callback (NULL); + } + + return g_strdup (theme_from_preferences); } /* set the current theme */ @@ -198,7 +220,7 @@ nautilus_theme_get_theme_data (const char *resource_name, const char *property_n { char *result; char *theme_name; - theme_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + theme_name = nautilus_theme_get_theme (); result = nautilus_theme_get_theme_data_from_theme (resource_name, property_name, theme_name); g_free (theme_name); return result; @@ -290,7 +312,7 @@ nautilus_theme_get_image_path (const char *image_name) { char *theme_name, *image_path; - theme_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + theme_name = nautilus_theme_get_theme (); image_path = nautilus_theme_get_image_path_from_theme (image_name, theme_name); g_free (theme_name); diff --git a/libnautilus-private/nautilus-directory-async.c b/libnautilus-private/nautilus-directory-async.c index 695e1ecf3..007a68096 100644 --- a/libnautilus-private/nautilus-directory-async.c +++ b/libnautilus-private/nautilus-directory-async.c @@ -1147,18 +1147,57 @@ set_file_unconfirmed (NautilusFile *file, gboolean unconfirmed) } } +static gboolean show_hidden_files = TRUE; +static gboolean show_backup_files = TRUE; + +static void +show_hidden_files_changed_callback (gpointer callback_data) +{ + show_hidden_files = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES); +} + +static void +show_backup_files_changed_callback (gpointer callback_data) +{ + show_backup_files = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES); +} + static GnomeVFSDirectoryFilterOptions get_filter_options_for_directory_count (void) { + static gboolean show_hidden_files_changed_callback_installed = FALSE; + static gboolean show_backup_files_changed_callback_installed = FALSE; GnomeVFSDirectoryFilterOptions filter_options; filter_options = GNOME_VFS_DIRECTORY_FILTER_NOSELFDIR | GNOME_VFS_DIRECTORY_FILTER_NOPARENTDIR; + + /* Add the callback once for the life of our process */ + if (!show_hidden_files_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES, + show_hidden_files_changed_callback, + NULL); + show_hidden_files_changed_callback_installed = TRUE; + + /* Peek for the first time */ + show_hidden_files_changed_callback (NULL); + } + + /* Add the callback once for the life of our process */ + if (!show_backup_files_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES, + show_backup_files_changed_callback, + NULL); + show_backup_files_changed_callback_installed = TRUE; + + /* Peek for the first time */ + show_backup_files_changed_callback (NULL); + } - if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES)) { + if (!show_hidden_files) { filter_options |= GNOME_VFS_DIRECTORY_FILTER_NODOTFILES; } - if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES)) { + if (!show_backup_files) { filter_options |= GNOME_VFS_DIRECTORY_FILTER_NOBACKUPFILES; } diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index 6924cf782..c720ed21c 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -1070,34 +1070,6 @@ nautilus_file_is_local (NautilusFile *file) return nautilus_directory_is_local (file->details->directory); } -static gboolean -get_speed_tradeoff_preference_for_file (NautilusFile *file, const char *preference_name) -{ - NautilusSpeedTradeoffValue preference_value; - - g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); - - preference_value = nautilus_preferences_get_integer (preference_name); - - if (preference_value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { - return TRUE; - } - - if (preference_value == NAUTILUS_SPEED_TRADEOFF_NEVER) { - return FALSE; - } - - g_assert (preference_value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY); - return nautilus_file_is_local (file); -} - -gboolean -nautilus_file_should_get_top_left_text (NautilusFile *file) -{ - return get_speed_tradeoff_preference_for_file - (file, NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS); -} - static void update_link (NautilusFile *link_file, NautilusFile *target_file) { @@ -2292,11 +2264,86 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type return nautilus_strdup_strftime (format, file_time); } +static NautilusSpeedTradeoffValue show_directory_item_count; +static NautilusSpeedTradeoffValue show_text_in_icons; + +static void +show_text_in_icons_changed_callback (gpointer callback_data) +{ + show_text_in_icons = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS); +} + +static void +show_directory_item_count_changed_callback (gpointer callback_data) +{ + show_directory_item_count = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS); +} + +static gboolean +get_speed_tradeoff_preference_for_file (NautilusFile *file, NautilusSpeedTradeoffValue value) +{ + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { + return TRUE; + } + + if (value == NAUTILUS_SPEED_TRADEOFF_NEVER) { + return FALSE; + } + + g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY); + return nautilus_file_is_local (file); +} + gboolean nautilus_file_should_show_directory_item_count (NautilusFile *file) { - return get_speed_tradeoff_preference_for_file - (file, NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS); + static gboolean show_directory_item_count_callback_added = FALSE; + + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + /* Add the callback once for the life of our process */ + if (!show_directory_item_count_callback_added) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS, + show_directory_item_count_changed_callback, + NULL); + show_directory_item_count_callback_added = TRUE; + + /* Peek for the first time */ + show_directory_item_count_changed_callback (NULL); + } + + return get_speed_tradeoff_preference_for_file (file, show_directory_item_count); +} + +gboolean +nautilus_file_should_get_top_left_text (NautilusFile *file) +{ + static gboolean show_text_in_icons_callback_added = FALSE; + + g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE); + + /* Add the callback once for the life of our process */ + if (!show_text_in_icons_callback_added) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS, + show_text_in_icons_changed_callback, + NULL); + show_text_in_icons_callback_added = TRUE; + + /* Peek for the first time */ + show_text_in_icons_changed_callback (NULL); + } + + if (show_text_in_icons == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { + return TRUE; + } + + if (show_text_in_icons == NAUTILUS_SPEED_TRADEOFF_NEVER) { + return FALSE; + } + + return get_speed_tradeoff_preference_for_file (file, show_text_in_icons); } /** diff --git a/libnautilus-private/nautilus-theme.c b/libnautilus-private/nautilus-theme.c index e8d09616e..fbf8ef060 100644 --- a/libnautilus-private/nautilus-theme.c +++ b/libnautilus-private/nautilus-theme.c @@ -48,11 +48,33 @@ static char *last_theme_name = NULL; static xmlDocPtr last_theme_document = NULL; static xmlDocPtr default_theme_document = NULL; +static char *theme_from_preferences = NULL; + +static void +theme_changed_callback (gpointer callback_data) +{ + g_free (theme_from_preferences); + theme_from_preferences = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); +} + /* return the current theme by asking the preferences machinery */ char * nautilus_theme_get_theme (void) { - return nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + static gboolean theme_changed_callback_installed = FALSE; + + /* Add the callback once for the life of our process */ + if (!theme_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_THEME, + theme_changed_callback, + NULL); + theme_changed_callback_installed = TRUE; + + /* Peek for the first time */ + theme_changed_callback (NULL); + } + + return g_strdup (theme_from_preferences); } /* set the current theme */ @@ -198,7 +220,7 @@ nautilus_theme_get_theme_data (const char *resource_name, const char *property_n { char *result; char *theme_name; - theme_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + theme_name = nautilus_theme_get_theme (); result = nautilus_theme_get_theme_data_from_theme (resource_name, property_name, theme_name); g_free (theme_name); return result; @@ -290,7 +312,7 @@ nautilus_theme_get_image_path (const char *image_name) { char *theme_name, *image_path; - theme_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_THEME); + theme_name = nautilus_theme_get_theme (); image_path = nautilus_theme_get_image_path_from_theme (image_name, theme_name); g_free (theme_name); diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index cc4898f57..6014dfb1f 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -3114,21 +3114,39 @@ real_merge_menus (FMDirectoryView *view) } } +static gboolean confirm_trash = TRUE; + +static void +confirm_trash_changed_callback (gpointer callback_data) +{ + confirm_trash = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH); +} + static void real_update_menus (FMDirectoryView *view) { + static gboolean confirm_trash_changed_callback_installed = FALSE; GList *selection; gint selection_count; char *label_with_underscore; - gboolean confirm_trash; gboolean selection_contains_special_link; gboolean can_create_files; NautilusBackground *background; selection = fm_directory_view_get_selection (view); selection_count = g_list_length (selection); + + /* Add the callback once for the life of our process */ + if (!confirm_trash_changed_callback_installed) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_CONFIRM_TRASH, + confirm_trash_changed_callback, + NULL); + confirm_trash_changed_callback_installed = TRUE; + + /* Peek for the first time */ + confirm_trash_changed_callback (NULL); + } - confirm_trash = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH); selection_contains_special_link = special_link_in_selection (view); can_create_files = fm_directory_view_supports_creating_files (view); diff --git a/src/file-manager/fm-icon-text-window.c b/src/file-manager/fm-icon-text-window.c index 653c0592b..84fec6a1c 100644 --- a/src/file-manager/fm-icon-text-window.c +++ b/src/file-manager/fm-icon-text-window.c @@ -394,16 +394,41 @@ fm_icon_text_window_get_or_create (void) return GTK_WINDOW (icon_text_window); } +/* This string will leak at exit time */ +static char *icon_captions = NULL; + +static void +icon_captions_changed_callback (gpointer callback_data) +{ + char *new_icon_captions = NULL; + + g_free (icon_captions); + + new_icon_captions = nautilus_preferences_get (NAUTILUS_PREFERENCES_ICON_CAPTIONS); + + if (attribute_names_string_is_good (new_icon_captions)) { + icon_captions = new_icon_captions; + return; + } + + icon_captions = g_strdup (DEFAULT_ATTRIBUTE_NAMES); +} + char * fm_get_text_attribute_names_preference_or_default (void) { - char *preference; + static gboolean icon_captions_callback_added = FALSE; + + /* Add the callback once for the life of our process */ + if (!icon_captions_callback_added) { + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_CAPTIONS, + icon_captions_changed_callback, + NULL); + icon_captions_callback_added = TRUE; - preference = nautilus_preferences_get (NAUTILUS_PREFERENCES_ICON_CAPTIONS); - if (preference && attribute_names_string_is_good (preference)) { - return preference; + /* Peek for the first time */ + icon_captions_changed_callback (NULL); } - if (preference) - g_free (preference); - return g_strdup (DEFAULT_ATTRIBUTE_NAMES); + + return g_strdup (icon_captions); } |