desktop-canvas-view: reorder if icon size changes

We changed the icons zoom levels icon sizes, which works fine on
the common nautilus window since the icons are positioned every time
we create a new view, etc.

The desktop view save the icon positions, so when we changed to a
larger size of icons by default the icons overlapped each one, looking
really bad for the people who update from an older version of nautilus.
This doesn't happen in clean installs, since there is not saved
positions of the icons.

To fix this rearrange the icons every time we found that the icons were
stored with a icon size different than what we have now or if we don't
have this metadata available.
That will only happen the first time the user runs nautilus with this
patch, since that key of the metadata won't be available; or every time
we change the hardcoded icon sizes for the zoom levels.

https://bugzilla.gnome.org/show_bug.cgi?id=745669
parent 13b4ba8f
......@@ -355,7 +355,7 @@ icon_set_position (NautilusCanvasIcon *icon,
}
static guint
guint
nautilus_canvas_container_get_icon_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level)
{
switch (zoom_level) {
......
......@@ -325,6 +325,7 @@ void nautilus_canvas_container_set_store_layout_timestamps (Nauti
void nautilus_canvas_container_widget_to_file_operation_position (NautilusCanvasContainer *container,
GdkPoint *position);
guint nautilus_canvas_container_get_icon_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level);
#define CANVAS_WIDTH(container,allocation) ((allocation.width \
- container->details->left_margin \
......
......@@ -30,6 +30,7 @@ static char *used_metadata_names[] = {
NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP,
NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
......
......@@ -41,6 +41,8 @@
#define NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED "nautilus-icon-view-keep-aligned"
#define NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP "nautilus-icon-view-layout-timestamp"
#define NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE "nautilus-desktop-icon-size"
#define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN "nautilus-list-view-sort-column"
#define NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED "nautilus-list-view-sort-reversed"
#define NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS "nautilus-list-view-visible-columns"
......
......@@ -24,6 +24,7 @@
*/
#include <config.h>
#include <stdlib.h>
#include "nautilus-desktop-canvas-view.h"
......@@ -257,6 +258,42 @@ nautilus_desktop_canvas_view_dispose (GObject *object)
G_OBJECT_CLASS (nautilus_desktop_canvas_view_parent_class)->dispose (object);
}
static void
nautilus_desktop_canvas_view_end_loading (NautilusView *view,
gboolean all_files_seen)
{
gboolean needs_reorganization;
gchar *stored_size_icon;
guint current_zoom;
guint current_icon_size;
gchar *current_icon_size_string;
NautilusFile *file;
NAUTILUS_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->end_loading (view, all_files_seen);
if (!all_files_seen)
return;
file = nautilus_view_get_directory_as_file (view);
g_return_if_fail (file != NULL);
stored_size_icon = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE, NULL);
current_zoom = nautilus_canvas_container_get_zoom_level (get_canvas_container (view));
current_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (current_zoom);
needs_reorganization = stored_size_icon == NULL || atoi (stored_size_icon) != current_icon_size;
if (needs_reorganization) {
current_icon_size_string = g_strdup_printf ("%d", current_icon_size);
nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (view));
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
NULL, current_icon_size_string);
g_free (current_icon_size_string);
}
g_free (stored_size_icon);
}
static void
nautilus_desktop_canvas_view_class_init (NautilusDesktopCanvasViewClass *class)
{
......@@ -268,6 +305,7 @@ nautilus_desktop_canvas_view_class_init (NautilusDesktopCanvasViewClass *class)
vclass->update_context_menus = real_update_context_menus;
vclass->get_view_id = real_get_id;
vclass->end_loading = nautilus_desktop_canvas_view_end_loading;
g_type_class_add_private (class, sizeof (NautilusDesktopCanvasViewDetails));
}
......@@ -329,17 +367,36 @@ get_default_zoom_level (void)
return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
}
static void
set_up_zoom_level (NautilusDesktopCanvasView *desktop_canvas_view)
{
NautilusCanvasZoomLevel new_level;
new_level = get_default_zoom_level ();
nautilus_canvas_container_set_zoom_level (get_canvas_container (desktop_canvas_view),
new_level);
}
static void
default_zoom_level_changed (gpointer user_data)
{
NautilusCanvasZoomLevel new_level;
NautilusDesktopCanvasView *desktop_canvas_view;
gint new_icon_size;
NautilusFile *file;
gchar *new_icon_size_string;
desktop_canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (user_data);
file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (user_data));
new_level = get_default_zoom_level ();
new_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (new_level);
new_icon_size_string = g_strdup_printf ("%d", new_icon_size);
nautilus_canvas_container_set_zoom_level (get_canvas_container (desktop_canvas_view),
new_level);
nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
NULL, new_icon_size_string);
set_up_zoom_level (desktop_canvas_view);
g_free (new_icon_size_string);
}
static gboolean
......@@ -671,7 +728,7 @@ nautilus_desktop_canvas_view_init (NautilusDesktopCanvasView *desktop_canvas_vie
G_CALLBACK (font_changed_callback),
desktop_canvas_view);
default_zoom_level_changed (desktop_canvas_view);
set_up_zoom_level (desktop_canvas_view);
nautilus_desktop_canvas_view_update_canvas_container_fonts (desktop_canvas_view);
g_signal_connect_swapped (gnome_lockdown_preferences,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment