summaryrefslogtreecommitdiff
path: root/src/xfdesktop-file-icon-manager.c
diff options
context:
space:
mode:
authorBrian Tarricone <brian@tarricone.org>2007-11-07 05:49:14 +0000
committerBrian Tarricone <brian@tarricone.org>2007-11-07 05:49:14 +0000
commit8aaccbf0499e9a1c54a00d2ae194a68d2eb84687 (patch)
tree01debf5390849312ab7c4411118a8c631f243691 /src/xfdesktop-file-icon-manager.c
parent67c68d775144e74ef0b8ae2e956222d036da2a7f (diff)
downloadxfdesktop-8aaccbf0499e9a1c54a00d2ae194a68d2eb84687.tar.gz
rewrite entire icon positions file to clean out stale entries (bug 3267)
(Old svn revision: 26267)
Diffstat (limited to 'src/xfdesktop-file-icon-manager.c')
-rw-r--r--src/xfdesktop-file-icon-manager.c68
1 files changed, 44 insertions, 24 deletions
diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 86893bde..5a3dce1e 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -106,7 +106,6 @@ struct _XfdesktopFileIconManagerPrivate
gboolean show_removable_media;
gboolean show_special[XFDESKTOP_SPECIAL_FILE_ICON_TRASH+1];
- GList *icons_to_save;
guint save_icons_id;
GList *deferred_icons;
@@ -791,6 +790,8 @@ xfdesktop_file_icon_manager_delete_selected(XfdesktopFileIconManager *fmanager,
g_list_foreach(selected, (GFunc)g_object_unref, NULL);
g_list_free(selected);
}
+
+ xfdesktop_file_icon_position_changed(NULL, fmanager);
}
static void
@@ -1982,45 +1983,67 @@ xfdesktop_file_icon_manager_populate_context_menu(XfceDesktop *desktop,
/* don't free |selected|. the menu deactivated handler does that */
}
+static void
+file_icon_hash_write_icons(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ XfceRc *rcfile = data;
+ XfdesktopIcon *icon = value;
+ guint16 row, col;
+
+ if(xfdesktop_icon_get_position(icon, &row, &col)) {
+ 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);
+ }
+}
+
static gboolean
xfdesktop_file_icon_manager_save_icons(gpointer user_data)
{
XfdesktopFileIconManager *fmanager = XFDESKTOP_FILE_ICON_MANAGER(user_data);
- gchar relpath[PATH_MAX];
+ gchar relpath[PATH_MAX], *tmppath, *path;
XfceRc *rcfile;
- GList *l;
- XfdesktopIcon *icon;
- guint16 row, col;
fmanager->priv->save_icons_id = 0;
- g_return_val_if_fail(fmanager->priv->icons_to_save, FALSE);
-
g_snprintf(relpath, PATH_MAX, "xfce4/desktop/icons.screen%d.rc",
gdk_screen_get_number(fmanager->priv->gscreen));
+ path = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, relpath, TRUE);
+ if(!path)
+ return FALSE;
+
+ tmppath = g_strconcat(path, ".new", NULL);
- rcfile = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, relpath, FALSE);
+ rcfile = xfce_rc_simple_open(tmppath, FALSE);
if(!rcfile) {
- g_critical("Unable to determine location of icon position cache file. " \
- "Icon positions will not be saved.");
+ g_warning("Unable to determine location of icon position cache file. " \
+ "Icon positions will not be saved.");
+ g_free(path);
+ g_free(tmppath);
return FALSE;
}
- for(l = fmanager->priv->icons_to_save; l; l = l->next) {
- icon = XFDESKTOP_ICON(l->data);
- if(xfdesktop_icon_get_position(icon, &row, &col)) {
- 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);
- }
- g_object_unref(G_OBJECT(icon));
- }
- g_list_free(fmanager->priv->icons_to_save);
- fmanager->priv->icons_to_save = NULL;
+ g_hash_table_foreach(fmanager->priv->icons,
+ file_icon_hash_write_icons, rcfile);
+ g_hash_table_foreach(fmanager->priv->removable_icons,
+ file_icon_hash_write_icons, rcfile);
+ g_hash_table_foreach(fmanager->priv->special_icons,
+ file_icon_hash_write_icons, rcfile);
xfce_rc_flush(rcfile);
xfce_rc_close(rcfile);
+ if(rename(tmppath, path)) {
+ g_warning("Unable to rename temp file to %s: %s", path,
+ strerror(errno));
+ unlink(tmppath);
+ }
+
+ g_free(path);
+ g_free(tmppath);
+
return FALSE;
}
@@ -2033,9 +2056,6 @@ xfdesktop_file_icon_position_changed(XfdesktopFileIcon *icon,
if(fmanager->priv->save_icons_id)
g_source_remove(fmanager->priv->save_icons_id);
- fmanager->priv->icons_to_save = g_list_prepend(fmanager->priv->icons_to_save,
- g_object_ref(G_OBJECT(icon)));
-
fmanager->priv->save_icons_id = g_timeout_add(SAVE_DELAY,
xfdesktop_file_icon_manager_save_icons,
fmanager);