changeset 132:661cd91e5a7e

First implementation of marks for all photos.
author bruclik
date Fri, 13 Jul 2007 14:03:08 +0000
parents b1acdfc7271b
children 532c42d5ed4d
files src/image-overlay.c src/layout.c src/layout.h src/layout_util.c src/typedefs.h src/view_file_list.c src/view_file_list.h
diffstat 7 files changed, 170 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/image-overlay.c	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/image-overlay.c	Fri Jul 13 14:03:08 2007 +0000
@@ -88,8 +88,9 @@
 	gint n, t;
 	CollectionData *cd;
 	CollectInfo *info;
-	gchar *ct;
-
+    gchar *ct;
+    int i;
+    
 	name = image_get_name(imd);
 	if (name)
 		{
@@ -177,11 +178,16 @@
 				       n, t, name_escaped,
 				       w, h,
 				       text_from_time(imd->mtime), size);
-		}
+
+        
+
+        }
 	g_free(size);
 	g_free(ct);
 	g_free(name_escaped);
-
+    for (i=0; i < FILEDATA_MARKS_SIZE; i++) {
+        
+    
 	layout = gtk_widget_create_pango_layout(imd->pr, NULL);
 	pango_layout_set_markup(layout, text, -1);
 	g_free(text);
--- a/src/layout.c	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/layout.c	Fri Jul 13 14:03:08 2007 +0000
@@ -766,6 +766,11 @@
 	if (lw->vfl) vflist_thumb_set(lw->vfl, lw->thumbs_enabled);
 }
 
+static void layout_list_sync_marks(LayoutWindow *lw)
+{
+	if (lw->vfl) vflist_marks_set(lw->vfl, lw->marks_enabled);
+}
+
 static void layout_list_scroll_to_subpart(LayoutWindow *lw, const gchar *needle)
 {
 	if (!lw) return;
@@ -1042,6 +1047,19 @@
 	layout_list_sync_thumb(lw);
 }
 
+void layout_marks_set(LayoutWindow *lw, gint enable)
+{
+	if (!layout_valid(&lw)) return;
+
+	if (lw->marks_enabled == enable) return;
+
+	lw->marks_enabled = enable;
+
+    //	layout_util_sync_marks(lw);
+    layout_list_sync_marks(lw);
+    
+}
+
 gint layout_thumb_get(LayoutWindow *lw)
 {
 	if (!layout_valid(&lw)) return FALSE;
--- a/src/layout.h	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/layout.h	Fri Jul 13 14:03:08 2007 +0000
@@ -53,6 +53,8 @@
 void layout_thumb_set(LayoutWindow *lw, gint enable);
 gint layout_thumb_get(LayoutWindow *lw);
 
+void layout_marks_set(LayoutWindow *lw, gint enable);
+
 void layout_sort_set(LayoutWindow *lw, SortType type, gint ascend);
 gint layout_sort_get(LayoutWindow *lw, SortType *type, gint *ascend);
 
--- a/src/layout_util.c	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/layout_util.c	Fri Jul 13 14:03:08 2007 +0000
@@ -496,6 +496,13 @@
 	layout_thumb_set(lw, gtk_toggle_action_get_active(action));
 }
 
+static void layout_menu_marks_cb(GtkToggleAction *action, gpointer data)
+{
+	LayoutWindow *lw = data;
+
+	layout_marks_set(lw, gtk_toggle_action_get_active(action));
+}
+
 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
 {
 	LayoutWindow *lw = data;
@@ -836,6 +843,7 @@
 
 static GtkToggleActionEntry menu_toggle_entries[] = {
   { "Thumbnails",	NULL,		N_("_Thumbnails"),	"T",		NULL,	CB(layout_menu_thumb_cb) },
+  { "Marks",        NULL,		N_("_Marks"),	"M",		NULL,	CB(layout_menu_marks_cb) },  
   { "FolderTree",	NULL,		N_("Tr_ee"),		"<control>T",	NULL,	CB(layout_menu_tree_cb) },
   { "FloatTools",	NULL,		N_("_Float file list"),	"L",		NULL,	CB(layout_menu_float_cb) },
   { "HideToolbar",	NULL,		N_("Hide tool_bar"),	NULL,		NULL,	CB(layout_menu_toolbar_cb) },
@@ -913,6 +921,7 @@
 "      <menuitem action='ZoomFit'/>"
 "      <separator/>"
 "      <menuitem action='Thumbnails'/>"
+"      <menuitem action='Marks'/>"
 "      <menuitem action='ViewList'/>"
 "      <menuitem action='ViewIcons'/>"
 "      <separator/>"
--- a/src/typedefs.h	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/typedefs.h	Fri Jul 13 14:03:08 2007 +0000
@@ -320,12 +320,14 @@
 	gint delay_flip;
 };
 
+#define FILEDATA_MARKS_SIZE 10
+
 struct _FileData {
 	gchar *path;
 	const gchar *name;
 	gint64 size;
 	time_t date;
-
+    gboolean marks[FILEDATA_MARKS_SIZE];
 	GdkPixbuf *pixbuf;
 };
 
@@ -379,7 +381,8 @@
 
 	GtkWidget *thumb_button;
 	gint thumbs_enabled;
-
+    gint marks_enabled;
+    
 	/* dir view */
 
 	LayoutLocation dir_location;
@@ -515,7 +518,8 @@
 	FileData *select_fd;
 
 	gint thumbs_enabled;
-
+    gint marks_enabled;
+    
 	/* thumb updates */
 	gint thumbs_running;
 	gint thumbs_count;
--- a/src/view_file_list.c	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/view_file_list.c	Fri Jul 13 14:03:08 2007 +0000
@@ -26,6 +26,7 @@
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"
+#include "typedefs.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
@@ -37,6 +38,7 @@
 	FILE_COLUMN_SIZE,
 	FILE_COLUMN_DATE,
 	FILE_COLUMN_COLOR,
+    FILE_COLUMN_MARKS,
 	FILE_COLUMN_COUNT
 };
 
@@ -526,13 +528,20 @@
 	GtkTreePath *tpath;
 	GtkTreeIter iter;
 	FileData *fd = NULL;
-
+    GtkTreeViewColumn *column;
+    gint colnum;
+    
 	if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
-					  &tpath, NULL, NULL, NULL))
+					  &tpath, &column, NULL, NULL))
 		{
 		GtkTreeModel *store;
+        colnum = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column"));
+        
+        if (colnum <= FILE_COLUMN_MARKS - 2 + FILEDATA_MARKS_SIZE && colnum >= FILE_COLUMN_MARKS - 2)
+            return FALSE;
+        
+        store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
 
-		store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
 		gtk_tree_model_get_iter(store, &iter, tpath);
 		gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
 #if 0
@@ -827,7 +836,8 @@
 		{
 		FileData *fd;
 		gchar *size;
-
+        int i;
+        
 		fd = work->data;
 		size = text_from_size(fd->size);
 		gtk_list_store_append(store, &iter);
@@ -837,7 +847,10 @@
 						 FILE_COLUMN_SIZE, size,
 						 FILE_COLUMN_DATE, text_from_time(fd->date),
 						 FILE_COLUMN_COLOR, FALSE, -1);
-		g_free(size);
+        for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
+            gtk_list_store_set(store, &iter, FILE_COLUMN_MARKS + i, fd->marks[i], -1);
+            
+        g_free(size);
 
 		if (select_list && select_list->data == fd)
 			{
@@ -1313,7 +1326,7 @@
 	column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), FILE_COLUMN_THUMB - 1);
 	if (!column) return;
 
-	gtk_tree_view_column_set_fixed_width(column, (thumb) ? thumb_max_width : 4);
+	gtk_tree_view_column_set_fixed_width(column, (thumb) ? thumb_max_width : FILE_COLUMN_MARKS);
 
 	list = gtk_tree_view_column_get_cell_renderers(column);
 	if (!list) return;
@@ -1367,7 +1380,8 @@
 		while (!done)
 			{
 			FileData *old_fd = NULL;
-
+            int i;
+            
 			if (valid)
 				{
 				gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, -1);
@@ -1398,7 +1412,10 @@
 								FILE_COLUMN_SIZE, size,
 								FILE_COLUMN_DATE, text_from_time(fd->date),
 								FILE_COLUMN_COLOR, FALSE, -1);
-				g_free(size);
+                for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
+                    gtk_list_store_set(store, &new, FILE_COLUMN_MARKS + i, fd->marks[i], -1);
+
+                g_free(size);
 
 				done = TRUE;
 				}
@@ -1528,7 +1545,7 @@
 		     "cell-background-set", set, NULL);
 }
 
-static void vflist_listview_add_column(ViewFileList *vfl, gint n, const gchar *title, gint image, gint right_justify)
+static void vflist_listview_add_column(ViewFileList *vfl, gint n, const gchar *title, gint image, gint right_justify, gint expand)
 {
 	GtkTreeViewColumn *column;
 	GtkCellRenderer *renderer;
@@ -1547,7 +1564,9 @@
 			}
 		gtk_tree_view_column_pack_start(column, renderer, TRUE);
 		gtk_tree_view_column_add_attribute(column, renderer, "text", n);
-		}
+        if (expand)
+            gtk_tree_view_column_set_expand(column, TRUE);
+        }
 	else
 		{
 		gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
@@ -1562,6 +1581,52 @@
 	gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column);
 }
 
+static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkListStore *store)
+{
+    GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
+    guint *marks;
+    GtkTreeIter iter;
+    FileData *fd;
+    gboolean mark;
+    guint column;
+ 
+    if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path))
+        return;
+
+    column = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(cell), "column"));
+    
+    gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, column, &mark, -1);
+    mark ^= 1;
+    fd->marks[column] = mark;
+        
+    gtk_list_store_set(store, &iter, column, mark, -1);
+    gtk_tree_path_free(path);
+}
+
+static void vflist_listview_add_column_toggle(ViewFileList *vfl, gint n, const gchar *title)
+{
+    GtkTreeViewColumn *column;
+    GtkCellRenderer *renderer;
+    GtkListStore *store;
+    gint index;
+    
+	store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)));
+
+    renderer = gtk_cell_renderer_toggle_new();
+    column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL);
+
+    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+    g_object_set_data (G_OBJECT (column), "column", GUINT_TO_POINTER(n));
+    g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER(n));
+ 
+    index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column);
+    gtk_tree_view_column_set_fixed_width(column, 16);
+    gtk_tree_view_column_set_visible(column, vfl->marks_enabled);
+
+        
+    g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store);
+}
+
 /*
  *-----------------------------------------------------------------------------
  * base
@@ -1613,6 +1678,9 @@
 	GtkListStore *store;
 	GtkTreeSelection *selection;
 
+    GType *flist_types;
+    int i;
+    
 	vfl = g_new0(ViewFileList, 1);
 
 	vfl->path = NULL;
@@ -1639,9 +1707,20 @@
 	g_signal_connect(G_OBJECT(vfl->widget), "destroy",
 			 G_CALLBACK(vflist_destroy_cb), vfl);
 
-	store = gtk_list_store_new(6, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING,
-				   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
-	vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+    flist_types = g_new(GType, FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE);
+    flist_types[0] = G_TYPE_POINTER;
+    flist_types[1] = GDK_TYPE_PIXBUF;
+    flist_types[2] = G_TYPE_STRING;
+    flist_types[3] = G_TYPE_STRING;
+    flist_types[4] = G_TYPE_STRING;
+    flist_types[5] = G_TYPE_BOOLEAN;
+    for (i = FILE_COLUMN_MARKS; i < FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE; i++)
+        flist_types[i] = G_TYPE_BOOLEAN;
+
+    store = gtk_list_store_newv(FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE, flist_types);
+    g_free(flist_types);
+                               
+    vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
 	g_object_unref(store);
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview));
@@ -1651,24 +1730,28 @@
 	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE);
 	gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfl->listview), FALSE);
 
-	vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE);
-	vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE);
+	vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, TRUE);
 
-	g_signal_connect(G_OBJECT(vfl->listview), "key_press_event",
+    for(i = 0; i < FILEDATA_MARKS_SIZE;i++)
+        vflist_listview_add_column_toggle(vfl, i + FILE_COLUMN_MARKS, "");
+            
+    g_signal_connect(G_OBJECT(vfl->listview), "key_press_event",
 			 G_CALLBACK(vflist_press_key_cb), vfl);
 
 	gtk_container_add (GTK_CONTAINER(vfl->widget), vfl->listview);
 	gtk_widget_show(vfl->listview);
 
 	vflist_dnd_init(vfl);
-
+    
 	g_signal_connect(G_OBJECT(vfl->listview), "button_press_event",
 			 G_CALLBACK(vflist_press_cb), vfl);
 	g_signal_connect(G_OBJECT(vfl->listview), "button_release_event",
 			 G_CALLBACK(vflist_release_cb), vfl);
-
+    
+    
 	if (path) vflist_set_path(vfl, path);
 
 	return vfl;
@@ -1697,6 +1780,26 @@
 	vflist_refresh(vfl);
 }
 
+void vflist_marks_set(ViewFileList *vfl, gint enable)
+{
+    GtkListStore *store;
+    GtkTreeViewColumn *column;
+    int i;
+    
+	if (vfl->marks_enabled == enable) return;
+
+	vfl->marks_enabled = enable;
+    
+    for (i = 0; i < FILEDATA_MARKS_SIZE; i++) {
+        /* index - 2 because column's store != tree view */
+        column = gtk_tree_view_get_column(GTK_TREE_VIEW(vfl->listview), i + FILE_COLUMN_MARKS - 2);
+        
+        gtk_tree_view_column_set_visible(column, enable);
+    }
+    
+    //vflist_refresh(vfl);
+}
+
 void vflist_set_layout(ViewFileList *vfl, LayoutWindow *layout)
 {
 	vfl->layout = layout;
--- a/src/view_file_list.h	Thu Jul 12 20:46:28 2007 +0000
+++ b/src/view_file_list.h	Fri Jul 13 14:03:08 2007 +0000
@@ -30,6 +30,7 @@
 gint vflist_refresh(ViewFileList *vfl);
 
 void vflist_thumb_set(ViewFileList *vfl, gint enable);
+void vflist_marks_set(ViewFileList *vfl, gint enable);
 void vflist_sort_set(ViewFileList *vfl, SortType type, gint ascend);
 
 FileData *vflist_index_get_data(ViewFileList *vfl, gint row);