From 44de5223f9c446d574987c588255d2690f3f9029 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 15 Sep 2013 10:27:16 +0300 Subject: [PATCH] Change how icon positions are saved (Bug 9192) First a version stamp has been added to the RC file so that it will hopefully preserve most of the old positions to the new format. Next, most icons are stored based on the file path rather than the icon label. This way icons with the same label don't cause an issue. For volume icons the uuid of the icon is used (when available), otherwise it will fallback to the label. --- common/xfdesktop-common.h | 1 + src/xfdesktop-file-icon-manager.c | 42 ++++++++++++++++++++++++++++++++------- src/xfdesktop-file-icon-manager.h | 1 + src/xfdesktop-icon-view.c | 8 ++++++++ src/xfdesktop-icon.c | 17 ++++++++++++++++ src/xfdesktop-icon.h | 5 +++++ src/xfdesktop-regular-file-icon.c | 15 ++++++++++++++ src/xfdesktop-special-file-icon.c | 15 ++++++++++++++ src/xfdesktop-volume-icon.c | 16 +++++++++++++++ src/xfdesktop-window-icon.c | 8 ++++++++ 10 files changed, 121 insertions(+), 7 deletions(-) diff --git a/common/xfdesktop-common.h b/common/xfdesktop-common.h index 8e5947c..6ce5b06 100644 --- a/common/xfdesktop-common.h +++ b/common/xfdesktop-common.h @@ -42,6 +42,7 @@ #define LIST_TEXT "# xfce backdrop list" #define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d" #define XFDESKTOP_IMAGE_FILE_FMT "XFDESKTOP_IMAGE_FILE_%d" +#define XFDESKTOP_RC_VERSION_STAMP "xfdesktop-version-4.10.3+-rcfile_format" #define RELOAD_MESSAGE "reload" #define MENU_MESSAGE "menu" diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c index 46342d5..95367c7 100644 --- a/src/xfdesktop-file-icon-manager.c +++ b/src/xfdesktop-file-icon-manager.c @@ -1666,12 +1666,21 @@ file_icon_hash_write_icons(gpointer key, XfceRc *rcfile = data; XfdesktopIcon *icon = value; guint16 row, col; - + gchar *identifier = xfdesktop_icon_get_identifier(icon); + if(xfdesktop_icon_get_position(icon, &row, &col)) { - xfce_rc_set_group(rcfile, xfdesktop_icon_peek_label(icon)); + /* Attempt to use the identifier, fall back to using the labels. */ + if(identifier) + xfce_rc_set_group(rcfile, identifier); + else + xfce_rc_set_group(rcfile, xfdesktop_icon_peek_label(icon)); + xfce_rc_write_int_entry(rcfile, "row", row); xfce_rc_write_int_entry(rcfile, "col", col); } + + if(identifier) + g_free(identifier); } static gboolean @@ -1712,7 +1721,10 @@ xfdesktop_file_icon_manager_save_icons(gpointer user_data) g_free(tmppath); return FALSE; } - + + xfce_rc_set_group(rcfile, XFDESKTOP_RC_VERSION_STAMP); + xfce_rc_write_bool_entry(rcfile, "4.10.3+", TRUE); + g_hash_table_foreach(fmanager->priv->icons, file_icon_hash_write_icons, rcfile); if(fmanager->priv->show_removable_media) { @@ -1761,6 +1773,7 @@ xfdesktop_file_icon_position_changed(XfdesktopFileIcon *icon, gboolean xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *fmanager, const gchar *name, + const gchar *identifier, gint16 *row, gint16 *col) { @@ -1795,10 +1808,18 @@ xfdesktop_file_icon_manager_get_cached_icon_position(XfdesktopFileIconManager *f if(filename != NULL) { XfceRc *rcfile; + const gchar *icon_name; rcfile = xfce_rc_simple_open(filename, TRUE); - if(xfce_rc_has_group(rcfile, name)) { - xfce_rc_set_group(rcfile, name); + /* Newer versions use the identifier rather than the icon label when + * possible */ + if(xfce_rc_has_group(rcfile, XFDESKTOP_RC_VERSION_STAMP) && identifier) + icon_name = identifier; + else + icon_name = name; + + if(xfce_rc_has_group(rcfile, icon_name)) { + xfce_rc_set_group(rcfile, icon_name); *row = xfce_rc_read_int_entry(rcfile, "row", -1); *col = xfce_rc_read_int_entry(rcfile, "col", -1); if(*row >= 0 && *col >= 0) @@ -1933,15 +1954,19 @@ xfdesktop_file_icon_manager_add_icon(XfdesktopFileIconManager *fmanager, GFile *file = xfdesktop_file_icon_peek_file(icon); gboolean do_add = FALSE; const gchar *name; + gchar *identifier; xfdesktop_file_icon_manager_queue_thumbnail(fmanager, icon); name = xfdesktop_icon_peek_label(XFDESKTOP_ICON(icon)); + identifier = xfdesktop_icon_get_identifier(XFDESKTOP_ICON(icon)); + if(row >= 0 && col >= 0) { DBG("attempting to set icon '%s' to position (%d,%d)", name, row, col); xfdesktop_icon_set_position(XFDESKTOP_ICON(icon), row, col); do_add = TRUE; - } else if(xfdesktop_file_icon_manager_get_cached_icon_position(fmanager, name, + } else if(xfdesktop_file_icon_manager_get_cached_icon_position(fmanager, + name, identifier, &row, &col)) { DBG("attempting to set icon '%s' to position (%d,%d)", name, row, col); @@ -1969,7 +1994,10 @@ xfdesktop_file_icon_manager_add_icon(XfdesktopFileIconManager *fmanager, g_object_weak_ref(G_OBJECT(icon), _icon_notify_destroy, NULL); } #endif - + + if(identifier) + g_free(identifier); + return do_add; } diff --git a/src/xfdesktop-file-icon-manager.h b/src/xfdesktop-file-icon-manager.h index decdb74..42c3939 100644 --- a/src/xfdesktop-file-icon-manager.h +++ b/src/xfdesktop-file-icon-manager.h @@ -71,6 +71,7 @@ gboolean xfdesktop_file_icon_manager_get_show_thumbnails(XfdesktopFileIconManage gboolean xfdesktop_file_icon_manager_get_cached_icon_position( XfdesktopFileIconManager *fmanager, const gchar *name, + const gchar *identifier, gint16 *row, gint16 *col); diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c index 3bec49d..42cec45 100644 --- a/src/xfdesktop-icon-view.c +++ b/src/xfdesktop-icon-view.c @@ -3131,11 +3131,16 @@ xfdesktop_move_all_cached_icons_to_desktop(XfdesktopIconView *icon_view) for(l = icon_view->priv->pending_icons; l; l = l->next) { gint16 row, col; XfdesktopIcon *icon = XFDESKTOP_ICON(l->data); + gchar *identifier = xfdesktop_icon_get_identifier(icon); + + if(!XFDESKTOP_IS_FILE_ICON(icon)) + continue; /* Try to get the cached position for the new resolution */ if(xfdesktop_file_icon_manager_get_cached_icon_position( fmanager, xfdesktop_icon_peek_label(icon), + identifier, &row, &col)) { @@ -3152,6 +3157,9 @@ xfdesktop_move_all_cached_icons_to_desktop(XfdesktopIconView *icon_view) } else { leftovers = g_list_prepend(leftovers, icon); } + + if(identifier) + g_free(identifier); } g_list_free(icon_view->priv->pending_icons); diff --git a/src/xfdesktop-icon.c b/src/xfdesktop-icon.c index b6c2ce7..6e79eec 100644 --- a/src/xfdesktop-icon.c +++ b/src/xfdesktop-icon.c @@ -230,6 +230,22 @@ xfdesktop_icon_peek_label(XfdesktopIcon *icon) return klass->peek_label(icon); } +/*< required >*/ +gchar * +xfdesktop_icon_get_identifier(XfdesktopIcon *icon) +{ + XfdesktopIconClass *klass; + + g_return_val_if_fail(XFDESKTOP_IS_ICON(icon), NULL); + + klass = XFDESKTOP_ICON_GET_CLASS(icon); + + if(!klass->get_identifier) + return NULL; + + return klass->get_identifier(icon); +} + /*< optional; drags aren't allowed if not provided >*/ GdkDragAction xfdesktop_icon_get_allowed_drag_actions(XfdesktopIcon *icon) @@ -322,6 +338,7 @@ xfdesktop_icon_peek_tooltip(XfdesktopIcon *icon) return klass->peek_tooltip(icon); } + /*< optional >*/ void xfdesktop_icon_delete_thumbnail(XfdesktopIcon *icon) { diff --git a/src/xfdesktop-icon.h b/src/xfdesktop-icon.h index 00b3fe2..d8ad56c 100644 --- a/src/xfdesktop-icon.h +++ b/src/xfdesktop-icon.h @@ -73,6 +73,8 @@ struct _XfdesktopIconClass GdkPixbuf *(*peek_tooltip_pixbuf)(XfdesktopIcon *icon, gint width, gint height); G_CONST_RETURN gchar *(*peek_tooltip)(XfdesktopIcon *icon); + + gchar *(*get_identifier)(XfdesktopIcon *icon); void (*set_thumbnail_file)(XfdesktopIcon *icon, GFile *file); void (*delete_thumbnail_file)(XfdesktopIcon *icon); @@ -94,6 +96,9 @@ GdkPixbuf *xfdesktop_icon_peek_tooltip_pixbuf(XfdesktopIcon *icon, gint height); G_CONST_RETURN gchar *xfdesktop_icon_peek_tooltip(XfdesktopIcon *icon); +/* returns a unique identifier for the icon, free when done using it */ +gchar *xfdesktop_icon_get_identifier(XfdesktopIcon *icon); + void xfdesktop_icon_set_position(XfdesktopIcon *icon, gint16 row, gint16 col); diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c index 342f806..bb5067f 100644 --- a/src/xfdesktop-regular-file-icon.c +++ b/src/xfdesktop-regular-file-icon.c @@ -77,6 +77,7 @@ static void xfdesktop_regular_file_icon_delete_thumbnail_file(XfdesktopIcon *ico static GdkPixbuf *xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_label(XfdesktopIcon *icon); +static gchar *xfdesktop_regular_file_icon_get_identifier(XfdesktopIcon *icon); static GdkPixbuf *xfdesktop_regular_file_icon_peek_tooltip_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon); @@ -122,6 +123,7 @@ xfdesktop_regular_file_icon_class_init(XfdesktopRegularFileIconClass *klass) icon_class->peek_pixbuf = xfdesktop_regular_file_icon_peek_pixbuf; icon_class->peek_label = xfdesktop_regular_file_icon_peek_label; + icon_class->get_identifier = xfdesktop_regular_file_icon_get_identifier; icon_class->peek_tooltip_pixbuf = xfdesktop_regular_file_icon_peek_tooltip_pixbuf; icon_class->peek_tooltip = xfdesktop_regular_file_icon_peek_tooltip; icon_class->get_allowed_drag_actions = xfdesktop_regular_file_icon_get_allowed_drag_actions; @@ -390,6 +392,19 @@ xfdesktop_regular_file_icon_peek_label(XfdesktopIcon *icon) return regular_file_icon->priv->display_name; } +static gchar * +xfdesktop_regular_file_icon_get_identifier(XfdesktopIcon *icon) +{ + XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon); + + g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL); + + if(xfdesktop_file_icon_peek_file(file_icon) == NULL) + return NULL; + + return g_file_get_path(xfdesktop_file_icon_peek_file(file_icon)); +} + static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c index 7509528..efe2ef8 100644 --- a/src/xfdesktop-special-file-icon.c +++ b/src/xfdesktop-special-file-icon.c @@ -71,6 +71,7 @@ static void xfdesktop_special_file_icon_finalize(GObject *obj); static GdkPixbuf *xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_label(XfdesktopIcon *icon); +static gchar *xfdesktop_special_file_icon_get_identifier(XfdesktopIcon *icon); static GdkPixbuf *xfdesktop_special_file_icon_peek_tooltip_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon); @@ -121,6 +122,7 @@ xfdesktop_special_file_icon_class_init(XfdesktopSpecialFileIconClass *klass) icon_class->peek_pixbuf = xfdesktop_special_file_icon_peek_pixbuf; icon_class->peek_label = xfdesktop_special_file_icon_peek_label; + icon_class->get_identifier = xfdesktop_special_file_icon_get_identifier; icon_class->peek_tooltip_pixbuf = xfdesktop_special_file_icon_peek_tooltip_pixbuf; icon_class->peek_tooltip = xfdesktop_special_file_icon_peek_tooltip; icon_class->get_allowed_drag_actions = xfdesktop_special_file_icon_get_allowed_drag_actions; @@ -297,6 +299,19 @@ xfdesktop_special_file_icon_peek_label(XfdesktopIcon *icon) return info ? g_file_info_get_display_name(info) : NULL; } +static gchar * +xfdesktop_special_file_icon_get_identifier(XfdesktopIcon *icon) +{ + XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon); + + g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL); + + if(xfdesktop_file_icon_peek_file(file_icon) == NULL) + return NULL; + + return g_file_get_path(xfdesktop_file_icon_peek_file(file_icon)); +} + static GdkDragAction xfdesktop_special_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c index e29bd99..610681d 100644 --- a/src/xfdesktop-volume-icon.c +++ b/src/xfdesktop-volume-icon.c @@ -77,6 +77,7 @@ static void xfdesktop_volume_icon_finalize(GObject *obj); static GdkPixbuf *xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_label(XfdesktopIcon *icon); +static gchar *xfdesktop_volume_icon_get_identifier(XfdesktopIcon *icon); static GdkPixbuf *xfdesktop_volume_icon_peek_tooltip_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_tooltip(XfdesktopIcon *icon); @@ -133,6 +134,7 @@ xfdesktop_volume_icon_class_init(XfdesktopVolumeIconClass *klass) icon_class->peek_pixbuf = xfdesktop_volume_icon_peek_pixbuf; icon_class->peek_label = xfdesktop_volume_icon_peek_label; + icon_class->get_identifier = xfdesktop_volume_icon_get_identifier; icon_class->peek_tooltip_pixbuf = xfdesktop_volume_icon_peek_tooltip_pixbuf; icon_class->peek_tooltip = xfdesktop_volume_icon_peek_tooltip; icon_class->get_allowed_drag_actions = xfdesktop_volume_icon_get_allowed_drag_actions; @@ -318,6 +320,20 @@ xfdesktop_volume_icon_peek_label(XfdesktopIcon *icon) return volume_icon->priv->label; } +static gchar * +xfdesktop_volume_icon_get_identifier(XfdesktopIcon *icon) +{ + XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); + gchar *uuid; + + uuid = g_volume_get_identifier(volume_icon->priv->volume, G_VOLUME_IDENTIFIER_KIND_UUID); + + if(uuid == NULL) + return g_strdup(xfdesktop_volume_icon_peek_label(icon)); + + return uuid; +} + static GdkDragAction xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { diff --git a/src/xfdesktop-window-icon.c b/src/xfdesktop-window-icon.c index adeb2f7..1b2c123 100644 --- a/src/xfdesktop-window-icon.c +++ b/src/xfdesktop-window-icon.c @@ -44,6 +44,7 @@ static void xfdesktop_window_icon_finalize(GObject *obj); static GdkPixbuf *xfdesktop_window_icon_peek_pixbuf(XfdesktopIcon *icon, gint width, gint height); static G_CONST_RETURN gchar *xfdesktop_window_icon_peek_label(XfdesktopIcon *icon); +static gchar *xfdesktop_window_icon_get_identifier(XfdesktopIcon *icon); static gboolean xfdesktop_window_icon_activated(XfdesktopIcon *icon); static gboolean xfdesktop_window_icon_populate_context_menu(XfdesktopIcon *icon, @@ -70,6 +71,7 @@ xfdesktop_window_icon_class_init(XfdesktopWindowIconClass *klass) icon_class->peek_pixbuf = xfdesktop_window_icon_peek_pixbuf; icon_class->peek_label = xfdesktop_window_icon_peek_label; + icon_class->get_identifier = xfdesktop_window_icon_get_identifier; icon_class->activated = xfdesktop_window_icon_activated; icon_class->populate_context_menu = xfdesktop_window_icon_populate_context_menu; } @@ -165,6 +167,12 @@ xfdesktop_window_icon_peek_label(XfdesktopIcon *icon) return window_icon->priv->label; } +static gchar * +xfdesktop_window_icon_get_identifier(XfdesktopIcon *icon) +{ + return g_strdup(xfdesktop_window_icon_peek_label(icon)); +} + static gboolean xfdesktop_window_icon_activated(XfdesktopIcon *icon) { -- 1.8.3.2