[PATCH] Zooming for icons in list view + MVC design problem?



Upside: This patch makes the icons in the list view zoomable.

Downside: FMListModel contains the pixbufs used in FMListView, thus in
order to implement zooming I had to change code in the model.  My
question is: isn't this a MVC design problem?  Shouldn't the view be
independent of the model?

If this isn't a big deal, well, great! :)

Otherwise, can anyone see a way around this without redesigning
FMListModel (probably too late in the game for that...)?
Index: ./src/file-manager/fm-list-model.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-model.c,v
retrieving revision 1.13
diff -p -u -r1.13 fm-list-model.c
--- ./src/file-manager/fm-list-model.c	24 Apr 2002 14:40:56 -0000	1.13
+++ ./src/file-manager/fm-list-model.c	29 Apr 2002 21:07:28 -0000
@@ -46,6 +46,11 @@ struct FMListModelDetails {
 	GtkSortType order;
 
 	gboolean sort_directories_first;
+
+	/* FUBAR: FMListModel contains pixbufs so the zoom can't be done
+	   entirely from FMListView.  Obviously this screws up the whole
+	   purpose of the MVC design... */
+	NautilusZoomLevel zoom_level;
 };
 
 typedef struct {
@@ -158,6 +163,32 @@ fm_list_model_get_path (GtkTreeModel *tr
 	return path;
 }
 
+NautilusZoomLevel
+fm_list_model_get_zoom_level (FMListModel *model)
+{
+	return model->details->zoom_level;
+}
+
+void
+fm_list_model_set_zoom_level (FMListModel *model,
+			      NautilusZoomLevel new_level)
+{
+	model->details->zoom_level = new_level;
+}
+
+static int
+get_icon_size_for_zoom_level (NautilusZoomLevel zoom_level)
+{
+	int icon_sizes[7] = { NAUTILUS_ICON_SIZE_SMALLEST,
+			      NAUTILUS_ICON_SIZE_SMALLER,
+			      NAUTILUS_ICON_SIZE_SMALL,
+			      NAUTILUS_ICON_SIZE_STANDARD,
+			      NAUTILUS_ICON_SIZE_LARGE,
+			      NAUTILUS_ICON_SIZE_LARGER,
+			      NAUTILUS_ICON_SIZE_LARGEST };
+
+	return icon_sizes[zoom_level];
+}
 
 static void
 fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
@@ -188,7 +219,8 @@ fm_list_model_get_value (GtkTreeModel *t
 	case FM_LIST_MODEL_ICON_COLUMN:
 		g_value_init (value, GDK_TYPE_PIXBUF);
 
-		icon = nautilus_icon_factory_get_pixbuf_for_file (file, NULL, NAUTILUS_ICON_SIZE_SMALLER);
+		icon = nautilus_icon_factory_get_pixbuf_for_file (file, NULL,
+								  get_icon_size_for_zoom_level (model->details->zoom_level));
 		g_value_set_object (value, icon);
 		g_object_unref (icon);
 		break;
Index: ./src/file-manager/fm-list-model.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-model.h,v
retrieving revision 1.4
diff -p -u -r1.4 fm-list-model.h
--- ./src/file-manager/fm-list-model.h	24 Apr 2002 00:16:50 -0000	1.4
+++ ./src/file-manager/fm-list-model.h	29 Apr 2002 21:07:28 -0000
@@ -24,6 +24,7 @@
 
 #include <gtk/gtktreemodel.h>
 #include <libnautilus-private/nautilus-file.h>
+#include <libnautilus-private/nautilus-icon-factory.h>
 
 #ifndef FM_LIST_MODEL_H
 #define FM_LIST_MODEL_H
@@ -73,5 +74,9 @@ void     fm_list_model_set_should_sort_d
 int      fm_list_model_get_sort_column_id_from_attribute (const char           *attribute);
 int      fm_list_model_get_sort_column_id_from_sort_type (NautilusFileSortType  sort_type);
 char    *fm_list_model_get_attribute_from_sort_column_id (int                   sort_column_id);
+
+NautilusZoomLevel fm_list_model_get_zoom_level           (FMListModel          *model);
+void     fm_list_model_set_zoom_level                    (FMListModel          *model,
+							  NautilusZoomLevel     new_level);
 
 #endif /* FM_LIST_MODEL_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]