[nautilus/wip/csoriano/flow: 54/55] desktop-canvas-view-container: override compare icons
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/flow: 54/55] desktop-canvas-view-container: override compare icons
- Date: Thu, 7 Apr 2016 20:55:54 +0000 (UTC)
commit cb305ddf0d803d9b1e0eaddbfd3e35a4cb4d7124
Author: Carlos Soriano <csoriano gnome org>
Date: Mon Apr 4 12:35:22 2016 +0200
desktop-canvas-view-container: override compare icons
Now that we have a subclass we can override the function instead of
special casing in the parent.
Also we can remove the internal boolean "sort for desktop".
And finally we can remove any desktop dependency in canvas view container.
src/nautilus-canvas-view-container.c | 96 --------------------------
src/nautilus-canvas-view-container.h | 3 -
src/nautilus-desktop-canvas-view-container.c | 91 ++++++++++++++++++++++++
src/nautilus-desktop-canvas-view.c | 1 -
4 files changed, 91 insertions(+), 100 deletions(-)
---
diff --git a/src/nautilus-canvas-view-container.c b/src/nautilus-canvas-view-container.c
index efcb735..b4e0df6 100644
--- a/src/nautilus-canvas-view-container.c
+++ b/src/nautilus-canvas-view-container.c
@@ -30,7 +30,6 @@
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-file-attributes.h>
#include <libnautilus-private/nautilus-thumbnails.h>
-#include <libnautilus-private/nautilus-desktop-icon-file.h>
G_DEFINE_TYPE (NautilusCanvasViewContainer, nautilus_canvas_view_container, NAUTILUS_TYPE_CANVAS_CONTAINER);
@@ -284,89 +283,6 @@ nautilus_canvas_view_container_get_icon_text (NautilusCanvasContainer *container
}
}
-/* Sort as follows:
- * 0) home link
- * 1) network link
- * 2) mount links
- * 3) other
- * 4) trash link
- */
-typedef enum {
- SORT_HOME_LINK,
- SORT_NETWORK_LINK,
- SORT_MOUNT_LINK,
- SORT_OTHER,
- SORT_TRASH_LINK
-} SortCategory;
-
-static SortCategory
-get_sort_category (NautilusFile *file)
-{
- NautilusDesktopLink *link;
- SortCategory category;
-
- category = SORT_OTHER;
-
- if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
- if (link != NULL) {
- switch (nautilus_desktop_link_get_link_type (link)) {
- case NAUTILUS_DESKTOP_LINK_HOME:
- category = SORT_HOME_LINK;
- break;
- case NAUTILUS_DESKTOP_LINK_MOUNT:
- category = SORT_MOUNT_LINK;
- break;
- case NAUTILUS_DESKTOP_LINK_TRASH:
- category = SORT_TRASH_LINK;
- break;
- case NAUTILUS_DESKTOP_LINK_NETWORK:
- category = SORT_NETWORK_LINK;
- break;
- default:
- category = SORT_OTHER;
- break;
- }
- g_object_unref (link);
- }
- }
-
- return category;
-}
-
-static int
-fm_desktop_canvas_container_icons_compare (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data_a,
- NautilusCanvasIconData *data_b)
-{
- NautilusFile *file_a;
- NautilusFile *file_b;
- NautilusFilesView *directory_view;
- SortCategory category_a, category_b;
-
- file_a = (NautilusFile *) data_a;
- file_b = (NautilusFile *) data_b;
-
- directory_view = NAUTILUS_FILES_VIEW (NAUTILUS_CANVAS_VIEW_CONTAINER (container)->view);
- g_return_val_if_fail (directory_view != NULL, 0);
-
- category_a = get_sort_category (file_a);
- category_b = get_sort_category (file_b);
-
- if (category_a == category_b) {
- return nautilus_file_compare_for_sort
- (file_a, file_b, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- nautilus_files_view_should_sort_directories_first (directory_view),
- FALSE);
- }
-
- if (category_a < category_b) {
- return -1;
- } else {
- return +1;
- }
-}
-
static int
nautilus_canvas_view_container_compare_icons (NautilusCanvasContainer *container,
NautilusCanvasIconData *icon_a,
@@ -377,11 +293,6 @@ nautilus_canvas_view_container_compare_icons (NautilusCanvasContainer *container
canvas_view = get_canvas_view (container);
g_return_val_if_fail (canvas_view != NULL, 0);
- if (NAUTILUS_CANVAS_VIEW_CONTAINER (container)->sort_for_desktop) {
- return fm_desktop_canvas_container_icons_compare
- (container, icon_a, icon_b);
- }
-
/* Type unsafe comparisons for performance */
return nautilus_canvas_view_compare_files (canvas_view,
(NautilusFile *)icon_a,
@@ -447,10 +358,3 @@ nautilus_canvas_view_container_new (NautilusCanvasView *view)
(g_object_new (NAUTILUS_TYPE_CANVAS_VIEW_CONTAINER, NULL),
view);
}
-
-void
-nautilus_canvas_view_container_set_sort_desktop (NautilusCanvasViewContainer *container,
- gboolean desktop)
-{
- container->sort_for_desktop = desktop;
-}
diff --git a/src/nautilus-canvas-view-container.h b/src/nautilus-canvas-view-container.h
index b2ab506..2197519 100644
--- a/src/nautilus-canvas-view-container.h
+++ b/src/nautilus-canvas-view-container.h
@@ -50,7 +50,6 @@ struct NautilusCanvasViewContainer {
NautilusCanvasContainer parent;
NautilusCanvasView *view;
- gboolean sort_for_desktop;
};
struct NautilusCanvasViewContainerClass {
@@ -61,7 +60,5 @@ GType nautilus_canvas_view_container_get_type (void);
NautilusCanvasContainer *nautilus_canvas_view_container_construct (NautilusCanvasViewContainer
*canvas_container,
NautilusCanvasView *view);
NautilusCanvasContainer *nautilus_canvas_view_container_new (NautilusCanvasView *view);
-void nautilus_canvas_view_container_set_sort_desktop (NautilusCanvasViewContainer
*container,
- gboolean desktop);
#endif /* NAUTILUS_CANVAS_VIEW_CONTAINER_H */
diff --git a/src/nautilus-desktop-canvas-view-container.c b/src/nautilus-desktop-canvas-view-container.c
index 6c76f74..a92ca4f 100644
--- a/src/nautilus-desktop-canvas-view-container.c
+++ b/src/nautilus-desktop-canvas-view-container.c
@@ -26,6 +26,96 @@ struct _NautilusDesktopCanvasViewContainer
G_DEFINE_TYPE (NautilusDesktopCanvasViewContainer, nautilus_desktop_canvas_view_container,
NAUTILUS_TYPE_CANVAS_VIEW_CONTAINER)
+/* Sort as follows:
+ * 0) home link
+ * 1) network link
+ * 2) mount links
+ * 3) other
+ * 4) trash link
+ */
+typedef enum {
+ SORT_HOME_LINK,
+ SORT_NETWORK_LINK,
+ SORT_MOUNT_LINK,
+ SORT_OTHER,
+ SORT_TRASH_LINK
+} SortCategory;
+
+static SortCategory
+get_sort_category (NautilusFile *file)
+{
+ NautilusDesktopLink *link;
+ SortCategory category;
+
+ category = SORT_OTHER;
+
+ if (NAUTILUS_IS_DESKTOP_ICON_FILE (file))
+ {
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+ if (link != NULL)
+ {
+ switch (nautilus_desktop_link_get_link_type (link))
+ {
+ case NAUTILUS_DESKTOP_LINK_HOME:
+ category = SORT_HOME_LINK;
+ break;
+ case NAUTILUS_DESKTOP_LINK_MOUNT:
+ category = SORT_MOUNT_LINK;
+ break;
+ case NAUTILUS_DESKTOP_LINK_TRASH:
+ category = SORT_TRASH_LINK;
+ break;
+ case NAUTILUS_DESKTOP_LINK_NETWORK:
+ category = SORT_NETWORK_LINK;
+ break;
+ default:
+ category = SORT_OTHER;
+ break;
+ }
+ g_object_unref (link);
+ }
+ }
+
+ return category;
+}
+
+static int
+real_compare_icons (NautilusCanvasContainer *container,
+ NautilusCanvasIconData *data_a,
+ NautilusCanvasIconData *data_b)
+{
+ NautilusFile *file_a;
+ NautilusFile *file_b;
+ NautilusFilesView *directory_view;
+ SortCategory category_a, category_b;
+
+ file_a = (NautilusFile *) data_a;
+ file_b = (NautilusFile *) data_b;
+
+ directory_view = NAUTILUS_FILES_VIEW (NAUTILUS_CANVAS_VIEW_CONTAINER (container)->view);
+ g_return_val_if_fail (directory_view != NULL, 0);
+
+ category_a = get_sort_category (file_a);
+ category_b = get_sort_category (file_b);
+
+ if (category_a == category_b)
+ {
+ return nautilus_file_compare_for_sort (file_a,
+ file_b,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ nautilus_files_view_should_sort_directories_first
(directory_view),
+ FALSE);
+ }
+
+ if (category_a < category_b)
+ {
+ return -1;
+ }
+ else
+ {
+ return +1;
+ }
+}
static void
real_get_icon_text (NautilusCanvasContainer *container,
@@ -102,6 +192,7 @@ nautilus_desktop_canvas_view_container_class_init (NautilusDesktopCanvasViewCont
container_class->get_icon_description = real_get_icon_description;
container_class->get_icon_text = real_get_icon_text;
+ container_class->compare_icons = real_compare_icons;
}
static void
diff --git a/src/nautilus-desktop-canvas-view.c b/src/nautilus-desktop-canvas-view.c
index b53ead9..d86d01d 100644
--- a/src/nautilus-desktop-canvas-view.c
+++ b/src/nautilus-desktop-canvas-view.c
@@ -757,7 +757,6 @@ nautilus_desktop_canvas_view_init (NautilusDesktopCanvasView *desktop_canvas_vie
}
canvas_container = get_canvas_container (desktop_canvas_view);
- nautilus_canvas_view_container_set_sort_desktop (NAUTILUS_CANVAS_VIEW_CONTAINER (canvas_container),
TRUE);
nautilus_canvas_container_set_is_fixed_size (canvas_container, TRUE);
nautilus_canvas_container_set_is_desktop (canvas_container, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]