Mercurial > geeqie
annotate src/view_file_list.c @ 144:2310066cc55a
fixed preloading images in file list
author | nadvornik |
---|---|
date | Mon, 22 Oct 2007 19:58:47 +0000 |
parents | 0d1bf3ac6cd8 |
children | f0c79a514c06 |
rev | line source |
---|---|
9 | 1 /* |
2 * GQview | |
3 * (C) 2004 John Ellis | |
4 * | |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 #include "gqview.h" | |
13 #include "view_file_list.h" | |
14 | |
15 #include "cache_maint.h" | |
16 #include "dnd.h" | |
17 #include "editors.h" | |
18 #include "img-view.h" | |
19 #include "info.h" | |
20 #include "layout.h" | |
21 #include "layout_image.h" | |
22 #include "menu.h" | |
23 #include "thumb.h" | |
24 #include "utilops.h" | |
25 #include "ui_bookmark.h" | |
26 #include "ui_fileops.h" | |
27 #include "ui_menu.h" | |
28 #include "ui_tree_edit.h" | |
132 | 29 #include "typedefs.h" |
9 | 30 |
31 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
32 | |
33 | |
34 enum { | |
35 FILE_COLUMN_POINTER = 0, | |
36 FILE_COLUMN_THUMB, | |
37 FILE_COLUMN_NAME, | |
139 | 38 FILE_COLUMN_SIDECARS, |
9 | 39 FILE_COLUMN_SIZE, |
40 FILE_COLUMN_DATE, | |
41 FILE_COLUMN_COLOR, | |
139 | 42 FILE_COLUMN_MARKS, |
43 FILE_COLUMN_MARKS_LAST = FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE - 1, | |
9 | 44 FILE_COLUMN_COUNT |
45 }; | |
46 | |
47 | |
48 static gint vflist_row_is_selected(ViewFileList *vfl, FileData *fd); | |
49 static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data); | |
50 static void vflist_populate_view(ViewFileList *vfl); | |
51 | |
52 /* | |
53 *----------------------------------------------------------------------------- | |
54 * signals | |
55 *----------------------------------------------------------------------------- | |
56 */ | |
57 | |
58 static void vflist_send_update(ViewFileList *vfl) | |
59 { | |
60 if (vfl->func_status) vfl->func_status(vfl, vfl->data_status); | |
61 } | |
62 | |
63 /* | |
64 *----------------------------------------------------------------------------- | |
65 * misc | |
66 *----------------------------------------------------------------------------- | |
67 */ | |
68 | |
69 static gint vflist_find_row(ViewFileList *vfl, FileData *fd, GtkTreeIter *iter) | |
70 { | |
71 GtkTreeModel *store; | |
72 gint valid; | |
73 gint row = 0; | |
74 | |
75 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
76 valid = gtk_tree_model_get_iter_first(store, iter); | |
77 while (valid) | |
78 { | |
79 FileData *fd_n; | |
80 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, FILE_COLUMN_POINTER, &fd_n, -1); | |
81 if (fd_n == fd) return row; | |
82 | |
83 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
84 row++; | |
85 } | |
86 | |
87 return -1; | |
88 } | |
89 | |
90 static void vflist_color_set(ViewFileList *vfl, FileData *fd, gint color_set) | |
91 { | |
92 GtkTreeModel *store; | |
93 GtkTreeIter iter; | |
94 | |
95 if (vflist_find_row(vfl, fd, &iter) < 0) return; | |
96 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
97 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_COLOR, color_set, -1); |
9 | 98 } |
99 | |
100 static void vflist_move_cursor(ViewFileList *vfl, GtkTreeIter *iter) | |
101 { | |
102 GtkTreeModel *store; | |
103 GtkTreePath *tpath; | |
104 | |
105 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
106 | |
107 tpath = gtk_tree_model_get_path(store, iter); | |
108 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vfl->listview), tpath, NULL, FALSE); | |
109 gtk_tree_path_free(tpath); | |
110 } | |
111 | |
112 /* | |
113 *----------------------------------------------------------------------------- | |
114 * dnd | |
115 *----------------------------------------------------------------------------- | |
116 */ | |
117 | |
118 static void vflist_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
119 GtkSelectionData *selection_data, guint info, | |
120 guint time, gpointer data) | |
121 { | |
122 ViewFileList *vfl = data; | |
123 GList *list = NULL; | |
124 gchar *uri_text = NULL; | |
125 gint total; | |
126 | |
127 if (!vfl->click_fd) return; | |
128 | |
129 if (vflist_row_is_selected(vfl, vfl->click_fd)) | |
130 { | |
131 list = vflist_selection_get_list(vfl); | |
132 } | |
133 else | |
134 { | |
138 | 135 list = g_list_append(NULL, file_data_ref(vfl->click_fd)); |
9 | 136 } |
137 | |
138 if (!list) return; | |
139 | |
138 | 140 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN)); |
141 filelist_free(list); | |
9 | 142 |
143 if (debug) printf(uri_text); | |
144 | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
145 gtk_selection_data_set(selection_data, selection_data->target, |
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
146 8, (guchar *)uri_text, total); |
9 | 147 g_free(uri_text); |
148 } | |
149 | |
150 static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
151 { | |
152 ViewFileList *vfl = data; | |
153 | |
154 vflist_color_set(vfl, vfl->click_fd, TRUE); | |
155 | |
156 if (vfl->thumbs_enabled && | |
157 vfl->click_fd && vfl->click_fd->pixbuf) | |
158 { | |
159 gint items; | |
160 | |
161 if (vflist_row_is_selected(vfl, vfl->click_fd)) | |
162 items = vflist_selection_count(vfl, NULL); | |
163 else | |
164 items = 1; | |
165 | |
166 dnd_set_drag_icon(widget, context, vfl->click_fd->pixbuf, items); | |
167 } | |
168 } | |
169 | |
170 static void vflist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
171 { | |
172 ViewFileList *vfl = data; | |
173 | |
174 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
175 | |
176 if (context->action == GDK_ACTION_MOVE) | |
177 { | |
178 vflist_refresh(vfl); | |
179 } | |
180 } | |
181 | |
182 static void vflist_dnd_init(ViewFileList *vfl) | |
183 { | |
184 gtk_drag_source_set(vfl->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
185 dnd_file_drag_types, dnd_file_drag_types_count, | |
186 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
187 g_signal_connect(G_OBJECT(vfl->listview), "drag_data_get", | |
188 G_CALLBACK(vflist_dnd_get), vfl); | |
189 g_signal_connect(G_OBJECT(vfl->listview), "drag_begin", | |
190 G_CALLBACK(vflist_dnd_begin), vfl); | |
191 g_signal_connect(G_OBJECT(vfl->listview), "drag_end", | |
192 G_CALLBACK(vflist_dnd_end), vfl); | |
193 } | |
194 | |
195 /* | |
196 *----------------------------------------------------------------------------- | |
197 * pop-up menu | |
198 *----------------------------------------------------------------------------- | |
199 */ | |
200 | |
201 static GList *vflist_pop_menu_file_list(ViewFileList *vfl) | |
202 { | |
203 if (!vfl->click_fd) return NULL; | |
204 | |
205 if (vflist_row_is_selected(vfl, vfl->click_fd)) | |
206 { | |
207 return vflist_selection_get_list(vfl); | |
208 } | |
209 | |
138 | 210 return g_list_append(NULL, file_data_ref(vfl->click_fd)); |
9 | 211 } |
212 | |
213 static void vflist_pop_menu_edit_cb(GtkWidget *widget, gpointer data) | |
214 { | |
215 ViewFileList *vfl; | |
216 gint n; | |
217 GList *list; | |
218 | |
219 vfl = submenu_item_get_data(widget); | |
220 n = GPOINTER_TO_INT(data); | |
221 | |
222 if (!vfl) return; | |
223 | |
224 list = vflist_pop_menu_file_list(vfl); | |
138 | 225 start_editor_from_filelist(n, list); |
226 filelist_free(list); | |
9 | 227 } |
228 | |
229 static void vflist_pop_menu_info_cb(GtkWidget *widget, gpointer data) | |
230 { | |
231 ViewFileList *vfl = data; | |
232 | |
233 info_window_new(NULL, vflist_pop_menu_file_list(vfl)); | |
234 } | |
235 | |
236 static void vflist_pop_menu_view_cb(GtkWidget *widget, gpointer data) | |
237 { | |
238 ViewFileList *vfl = data; | |
239 | |
240 if (vflist_row_is_selected(vfl, vfl->click_fd)) | |
241 { | |
242 GList *list; | |
243 | |
244 list = vflist_selection_get_list(vfl); | |
245 view_window_new_from_list(list); | |
138 | 246 filelist_free(list); |
9 | 247 } |
248 else | |
249 { | |
138 | 250 view_window_new(vfl->click_fd); |
9 | 251 } |
252 } | |
253 | |
254 static void vflist_pop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
255 { | |
256 ViewFileList *vfl = data; | |
257 | |
258 file_util_copy(NULL, vflist_pop_menu_file_list(vfl), NULL, vfl->listview); | |
259 } | |
260 | |
261 static void vflist_pop_menu_move_cb(GtkWidget *widget, gpointer data) | |
262 { | |
263 ViewFileList *vfl = data; | |
264 | |
265 file_util_move(NULL, vflist_pop_menu_file_list(vfl), NULL, vfl->listview); | |
266 } | |
267 | |
268 static void vflist_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
269 { | |
270 ViewFileList *vfl = data; | |
271 GList *list; | |
272 | |
273 list = vflist_pop_menu_file_list(vfl); | |
274 if (enable_in_place_rename && | |
275 list && !list->next && vfl->click_fd) | |
276 { | |
277 GtkTreeModel *store; | |
278 GtkTreeIter iter; | |
279 | |
138 | 280 filelist_free(list); |
9 | 281 |
282 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
283 if (vflist_find_row(vfl, vfl->click_fd, &iter) >= 0) | |
284 { | |
285 GtkTreePath *tpath; | |
286 | |
287 tpath = gtk_tree_model_get_path(store, &iter); | |
288 tree_edit_by_path(GTK_TREE_VIEW(vfl->listview), tpath, | |
289 FILE_COLUMN_NAME -1, vfl->click_fd->name, | |
290 vflist_row_rename_cb, vfl); | |
291 gtk_tree_path_free(tpath); | |
292 } | |
293 return; | |
294 } | |
295 | |
296 file_util_rename(NULL, list, vfl->listview); | |
297 } | |
298 | |
299 static void vflist_pop_menu_delete_cb(GtkWidget *widget, gpointer data) | |
300 { | |
301 ViewFileList *vfl = data; | |
302 | |
303 file_util_delete(NULL, vflist_pop_menu_file_list(vfl), vfl->listview); | |
304 } | |
305 | |
306 static void vflist_pop_menu_sort_cb(GtkWidget *widget, gpointer data) | |
307 { | |
308 ViewFileList *vfl; | |
309 SortType type; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
111
diff
changeset
|
310 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
111
diff
changeset
|
311 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return; |
9 | 312 |
313 vfl = submenu_item_get_data(widget); | |
314 if (!vfl) return; | |
315 | |
316 type = (SortType)GPOINTER_TO_INT(data); | |
317 | |
318 if (vfl->layout) | |
319 { | |
320 layout_sort_set(vfl->layout, type, vfl->sort_ascend); | |
321 } | |
322 else | |
323 { | |
324 vflist_sort_set(vfl, type, vfl->sort_ascend); | |
325 } | |
326 } | |
327 | |
328 static void vflist_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data) | |
329 { | |
330 ViewFileList *vfl = data; | |
331 | |
332 if (vfl->layout) | |
333 { | |
334 layout_sort_set(vfl->layout, vfl->sort_method, !vfl->sort_ascend); | |
335 } | |
336 else | |
337 { | |
338 vflist_sort_set(vfl, vfl->sort_method, !vfl->sort_ascend); | |
339 } | |
340 } | |
341 | |
342 static void vflist_pop_menu_icons_cb(GtkWidget *widget, gpointer data) | |
343 { | |
344 ViewFileList *vfl = data; | |
345 | |
346 if (vfl->layout) layout_views_set(vfl->layout, vfl->layout->tree_view, TRUE); | |
347 } | |
348 | |
349 static void vflist_pop_menu_thumbs_cb(GtkWidget *widget, gpointer data) | |
350 { | |
351 ViewFileList *vfl = data; | |
352 | |
353 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
354 if (vfl->layout) | |
355 { | |
356 layout_thumb_set(vfl->layout, !vfl->thumbs_enabled); | |
357 } | |
358 else | |
359 { | |
360 vflist_thumb_set(vfl, !vfl->thumbs_enabled); | |
361 } | |
362 } | |
363 | |
364 static void vflist_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
365 { | |
366 ViewFileList *vfl = data; | |
367 | |
368 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
369 vflist_refresh(vfl); | |
370 } | |
371 | |
372 static void vflist_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
373 { | |
374 ViewFileList *vfl = data; | |
375 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
376 vfl->click_fd = NULL; | |
377 vfl->popup = NULL; | |
378 } | |
379 | |
380 static GtkWidget *vflist_pop_menu(ViewFileList *vfl, FileData *fd) | |
381 { | |
382 GtkWidget *menu; | |
383 GtkWidget *item; | |
384 GtkWidget *submenu; | |
385 gint active; | |
386 | |
387 vflist_color_set(vfl, fd, TRUE); | |
388 active = (fd != NULL); | |
389 | |
390 menu = popup_menu_short_lived(); | |
391 g_signal_connect(G_OBJECT(menu), "destroy", | |
392 G_CALLBACK(vflist_popup_destroy_cb), vfl); | |
393 | |
394 submenu_add_edit(menu, &item, G_CALLBACK(vflist_pop_menu_edit_cb), vfl); | |
395 gtk_widget_set_sensitive(item, active); | |
396 | |
397 menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, active, | |
398 G_CALLBACK(vflist_pop_menu_info_cb), vfl); | |
399 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active, | |
400 G_CALLBACK(vflist_pop_menu_view_cb), vfl); | |
401 | |
402 menu_item_add_divider(menu); | |
403 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active, | |
404 G_CALLBACK(vflist_pop_menu_copy_cb), vfl); | |
405 menu_item_add_sensitive(menu, _("_Move..."), active, | |
406 G_CALLBACK(vflist_pop_menu_move_cb), vfl); | |
407 menu_item_add_sensitive(menu, _("_Rename..."), active, | |
408 G_CALLBACK(vflist_pop_menu_rename_cb), vfl); | |
409 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active, | |
410 G_CALLBACK(vflist_pop_menu_delete_cb), vfl); | |
411 | |
412 menu_item_add_divider(menu); | |
413 | |
414 submenu = submenu_add_sort(NULL, G_CALLBACK(vflist_pop_menu_sort_cb), vfl, | |
415 FALSE, FALSE, TRUE, vfl->sort_method); | |
416 menu_item_add_divider(submenu); | |
417 menu_item_add_check(submenu, _("Ascending"), vfl->sort_ascend, | |
418 G_CALLBACK(vflist_pop_menu_sort_ascend_cb), vfl); | |
419 | |
420 item = menu_item_add(menu, _("_Sort"), NULL, NULL); | |
421 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
422 | |
423 menu_item_add_check(menu, _("View as _icons"), FALSE, | |
424 G_CALLBACK(vflist_pop_menu_icons_cb), vfl); | |
425 menu_item_add_check(menu, _("Show _thumbnails"), vfl->thumbs_enabled, | |
426 G_CALLBACK(vflist_pop_menu_thumbs_cb), vfl); | |
427 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vflist_pop_menu_refresh_cb), vfl); | |
428 | |
429 return menu; | |
430 } | |
431 | |
432 /* | |
433 *----------------------------------------------------------------------------- | |
434 * callbacks | |
435 *----------------------------------------------------------------------------- | |
436 */ | |
437 | |
438 static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
439 { | |
440 ViewFileList *vfl = data; | |
441 gchar *old_path; | |
442 gchar *new_path; | |
443 | |
444 if (strlen(new) == 0) return FALSE; | |
445 | |
446 old_path = concat_dir_and_file(vfl->path, old); | |
447 new_path = concat_dir_and_file(vfl->path, new); | |
448 | |
449 if (strchr(new, '/') != NULL) | |
450 { | |
451 gchar *text = g_strdup_printf(_("Invalid file name:\n%s"), new); | |
452 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
453 g_free(text); | |
454 } | |
455 else if (isfile(new_path)) | |
456 { | |
457 gchar *text = g_strdup_printf(_("A file with name %s already exists."), new); | |
458 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
459 g_free(text); | |
460 } | |
138 | 461 else |
9 | 462 { |
138 | 463 gint row = vflist_index_by_path(vfl, old_path); |
464 if (row >= 0) | |
465 { | |
466 GList *work = g_list_nth(vfl->list, row); | |
467 FileData *fd = work->data; | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
142
diff
changeset
|
468 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
142
diff
changeset
|
469 if (!file_data_add_change_info(fd, FILEDATA_CHANGE_RENAME, old_path, new_path) || !rename_file_ext(fd)) |
138 | 470 { |
471 gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\nto:\n%s"), old, new); | |
472 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
473 g_free(text); | |
474 } | |
475 } | |
476 | |
9 | 477 } |
478 g_free(old_path); | |
479 g_free(new_path); | |
480 | |
481 return FALSE; | |
482 } | |
483 | |
484 static void vflist_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
485 { | |
486 ViewFileList *vfl = data; | |
487 GtkTreeModel *store; | |
488 GtkTreeIter iter; | |
489 GtkTreePath *tpath; | |
490 gint cw, ch; | |
491 | |
492 if (vflist_find_row(vfl, vfl->click_fd, &iter) < 0) return; | |
493 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
494 tpath = gtk_tree_model_get_path(store, &iter); | |
495 tree_view_get_cell_clamped(GTK_TREE_VIEW(vfl->listview), tpath, FILE_COLUMN_NAME - 1, TRUE, x, y, &cw, &ch); | |
496 gtk_tree_path_free(tpath); | |
497 *y += ch; | |
498 popup_menu_position_clamp(menu, x, y, 0); | |
499 } | |
500 | |
501 static gint vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
502 { | |
503 ViewFileList *vfl = data; | |
504 GtkTreePath *tpath; | |
505 | |
506 if (event->keyval != GDK_Menu) return FALSE; | |
507 | |
508 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vfl->listview), &tpath, NULL); | |
509 if (tpath) | |
510 { | |
511 GtkTreeModel *store; | |
512 GtkTreeIter iter; | |
513 | |
514 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
515 gtk_tree_model_get_iter(store, &iter, tpath); | |
516 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vfl->click_fd, -1); | |
517 gtk_tree_path_free(tpath); | |
518 } | |
519 else | |
520 { | |
521 vfl->click_fd = NULL; | |
522 } | |
523 | |
524 vfl->popup = vflist_pop_menu(vfl, vfl->click_fd); | |
525 gtk_menu_popup(GTK_MENU(vfl->popup), NULL, NULL, vflist_menu_position_cb, vfl, 0, GDK_CURRENT_TIME); | |
526 | |
527 return TRUE; | |
528 } | |
529 | |
530 static gint vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
531 { | |
532 ViewFileList *vfl = data; | |
533 GtkTreePath *tpath; | |
534 GtkTreeIter iter; | |
535 FileData *fd = NULL; | |
132 | 536 GtkTreeViewColumn *column; |
537 gint colnum; | |
538 | |
9 | 539 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, |
132 | 540 &tpath, &column, NULL, NULL)) |
9 | 541 { |
542 GtkTreeModel *store; | |
132 | 543 colnum = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column")); |
544 | |
545 if (colnum <= FILE_COLUMN_MARKS - 2 + FILEDATA_MARKS_SIZE && colnum >= FILE_COLUMN_MARKS - 2) | |
546 return FALSE; | |
547 | |
548 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
9 | 549 |
550 gtk_tree_model_get_iter(store, &iter, tpath); | |
551 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
552 #if 0 | |
553 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
554 #endif | |
555 gtk_tree_path_free(tpath); | |
556 } | |
557 | |
558 vfl->click_fd = fd; | |
559 | |
560 if (bevent->button == 3) | |
561 { | |
562 vfl->popup = vflist_pop_menu(vfl, vfl->click_fd); | |
563 gtk_menu_popup(GTK_MENU(vfl->popup), NULL, NULL, NULL, NULL, | |
564 bevent->button, bevent->time); | |
565 return TRUE; | |
566 } | |
567 | |
568 if (!fd) return FALSE; | |
569 | |
570 if (bevent->button == 2) | |
571 { | |
572 if (!vflist_row_is_selected(vfl, fd)) | |
573 { | |
574 vflist_color_set(vfl, fd, TRUE); | |
575 } | |
576 return TRUE; | |
577 } | |
578 | |
579 | |
580 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS && | |
581 !(bevent->state & GDK_SHIFT_MASK ) && | |
582 !(bevent->state & GDK_CONTROL_MASK ) && | |
583 vflist_row_is_selected(vfl, fd)) | |
584 { | |
585 gtk_widget_grab_focus(widget); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
586 // return TRUE; // FIXME - expand |
9 | 587 } |
588 | |
589 #if 0 | |
590 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) | |
591 { | |
592 if (vfl->layout) layout_image_full_screen_start(vfl->layout); | |
593 } | |
594 #endif | |
595 | |
596 return FALSE; | |
597 } | |
598 | |
599 static gint vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
600 { | |
601 ViewFileList *vfl = data; | |
602 GtkTreePath *tpath; | |
603 GtkTreeIter iter; | |
604 FileData *fd = NULL; | |
605 | |
606 if (bevent->button == 2) | |
607 { | |
608 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
609 } | |
610 | |
611 if (bevent->button != 1 && bevent->button != 2) | |
612 { | |
613 return TRUE; | |
614 } | |
615 | |
616 if ((bevent->x != 0 || bevent->y != 0) && | |
617 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
618 &tpath, NULL, NULL, NULL)) | |
619 { | |
620 GtkTreeModel *store; | |
621 | |
622 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
623 gtk_tree_model_get_iter(store, &iter, tpath); | |
624 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
625 gtk_tree_path_free(tpath); | |
626 } | |
627 | |
628 if (bevent->button == 2) | |
629 { | |
630 if (fd && vfl->click_fd == fd) | |
631 { | |
632 GtkTreeSelection *selection; | |
633 | |
634 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
635 if (vflist_row_is_selected(vfl, fd)) | |
636 { | |
637 gtk_tree_selection_unselect_iter(selection, &iter); | |
638 } | |
639 else | |
640 { | |
641 gtk_tree_selection_select_iter(selection, &iter); | |
642 } | |
643 } | |
644 return TRUE; | |
645 } | |
646 | |
647 if (fd && vfl->click_fd == fd && | |
648 !(bevent->state & GDK_SHIFT_MASK ) && | |
649 !(bevent->state & GDK_CONTROL_MASK ) && | |
650 vflist_row_is_selected(vfl, fd)) | |
651 { | |
652 GtkTreeSelection *selection; | |
653 | |
654 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
655 gtk_tree_selection_unselect_all(selection); | |
656 gtk_tree_selection_select_iter(selection, &iter); | |
657 vflist_move_cursor(vfl, &iter); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
658 // return TRUE;// FIXME - expand |
9 | 659 } |
660 | |
661 return FALSE; | |
662 } | |
663 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
664 static void vflist_select_image(ViewFileList *vfl, FileData *sel_fd) |
9 | 665 { |
138 | 666 FileData *read_ahead_fd = NULL; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
667 gint row; |
144 | 668 FileData *cur_fd; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
669 if (!sel_fd) return; |
144 | 670 |
671 cur_fd = layout_image_get_fd(vfl->layout); | |
672 if (sel_fd == cur_fd) return; /* no change */ | |
673 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
674 row = g_list_index(vfl->list, sel_fd); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
675 // FIXME sidecar data |
9 | 676 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
677 if (sel_fd && enable_read_ahead && row >= 0) |
9 | 678 { |
144 | 679 if (row > g_list_index(vfl->list, cur_fd) && |
9 | 680 row + 1 < vflist_count(vfl, NULL)) |
681 { | |
144 | 682 read_ahead_fd = vflist_index_get_data(vfl, row + 1); |
9 | 683 } |
684 else if (row > 0) | |
685 { | |
144 | 686 read_ahead_fd = vflist_index_get_data(vfl, row - 1); |
9 | 687 } |
688 } | |
689 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
690 layout_image_set_with_ahead(vfl->layout, sel_fd, read_ahead_fd); |
9 | 691 } |
692 | |
693 static gint vflist_select_idle_cb(gpointer data) | |
694 { | |
695 ViewFileList *vfl = data; | |
696 | |
697 if (!vfl->layout) | |
698 { | |
699 vfl->select_idle_id = -1; | |
700 return FALSE; | |
701 } | |
702 | |
703 vflist_send_update(vfl); | |
704 | |
705 if (vfl->select_fd) | |
706 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
707 vflist_select_image(vfl, vfl->select_fd); |
9 | 708 vfl->select_fd = NULL; |
709 } | |
710 | |
711 vfl->select_idle_id = -1; | |
712 return FALSE; | |
713 } | |
714 | |
715 static void vflist_select_idle_cancel(ViewFileList *vfl) | |
716 { | |
717 if (vfl->select_idle_id != -1) g_source_remove(vfl->select_idle_id); | |
718 vfl->select_idle_id = -1; | |
719 } | |
720 | |
721 static gboolean vflist_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
722 gboolean path_currently_selected, gpointer data) | |
723 { | |
724 ViewFileList *vfl = data; | |
725 GtkTreeIter iter; | |
726 | |
727 if (!path_currently_selected && | |
728 gtk_tree_model_get_iter(store, &iter, tpath)) | |
729 { | |
730 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vfl->select_fd, -1); | |
731 } | |
732 else | |
733 { | |
734 vfl->select_fd = NULL; | |
735 } | |
736 | |
737 if (vfl->layout && | |
738 vfl->select_idle_id == -1) | |
739 { | |
740 vfl->select_idle_id = g_idle_add(vflist_select_idle_cb, vfl); | |
741 } | |
742 | |
743 return TRUE; | |
744 } | |
745 | |
746 /* | |
747 *----------------------------------------------------------------------------- | |
748 * misc | |
749 *----------------------------------------------------------------------------- | |
750 */ | |
751 | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
752 static gboolean vflist_dummy_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
753 gboolean path_currently_selected, gpointer data) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
754 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
755 return TRUE; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
756 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
757 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
758 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
759 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
760 void vflist_setup_iter(ViewFileList *vfl, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd, GtkTreeIter *before) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
761 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
762 gchar *size; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
763 gchar *sidecars; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
764 int i; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
765 GList *work; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
766 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
767 sidecars = sidecar_file_data_list_to_string(fd); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
768 size = text_from_size(fd->size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
769 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
770 if (before) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
771 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
772 gtk_tree_store_insert_before(store, iter, NULL, before); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
773 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
774 else |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
775 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
776 gtk_tree_store_append(store, iter, NULL); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
777 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
778 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
779 gtk_tree_store_set(store, iter, FILE_COLUMN_POINTER, fd, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
780 FILE_COLUMN_THUMB, (vfl->thumbs_enabled) ? fd->pixbuf : NULL, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
781 FILE_COLUMN_NAME, fd->name, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
782 FILE_COLUMN_SIDECARS, sidecars, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
783 FILE_COLUMN_SIZE, size, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
784 FILE_COLUMN_DATE, text_from_time(fd->date), |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
785 FILE_COLUMN_COLOR, FALSE, -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
786 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
787 gtk_tree_store_set(store, iter, FILE_COLUMN_MARKS + i, fd->marks[i], -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
788 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
789 g_free(size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
790 g_free(sidecars); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
791 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
792 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
793 work = fd->sidecar_files; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
794 while (work) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
795 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
796 GtkTreeIter s_iter; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
797 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
798 FileData *sfd = work->data; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
799 work = work->next; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
800 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
801 size = text_from_size(sfd->size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
802 gtk_tree_store_append(store, &s_iter, iter); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
803 gtk_tree_store_set(store, &s_iter, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
804 FILE_COLUMN_POINTER, sfd, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
805 FILE_COLUMN_NAME, sfd->name, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
806 FILE_COLUMN_SIZE, size, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
807 FILE_COLUMN_DATE, text_from_time(sfd->date), |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
808 -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
809 g_free(size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
810 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
811 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
812 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
813 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
814 |
9 | 815 void vflist_sort_set(ViewFileList *vfl, SortType type, gint ascend) |
816 { | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
817 GtkTreeModel *model; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
818 GtkTreeStore *store; |
9 | 819 GList *work; |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
820 GtkTreeSelection *selection; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
821 GtkTreePath *tpath; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
822 GtkTreeIter iter; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
823 GList *select_list; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
824 FileData *cursor_fd = NULL; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
825 gint single_select; |
9 | 826 |
827 if (vfl->sort_method == type && vfl->sort_ascend == ascend) return; | |
828 | |
829 vfl->sort_method = type; | |
830 vfl->sort_ascend = ascend; | |
831 | |
832 if (!vfl->list) return; | |
833 | |
834 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
835 | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
836 /* now reorder the treeview, maintaining current selection */ |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
837 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
838 #if 0 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
839 /* this is simpler, but much slower */ |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
840 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 841 |
842 work = g_list_last(vfl->list); | |
843 while (work) | |
844 { | |
845 FileData *fd; | |
846 GtkTreeIter iter; | |
847 | |
848 fd = work->data; | |
849 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
850 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
851 gtk_tree_store_move_after(store, &iter, NULL); |
9 | 852 } |
853 | |
854 work = work->prev; | |
855 } | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
856 #endif |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
857 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
858 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
859 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
860 gtk_tree_selection_set_select_function(selection, vflist_dummy_select_cb, vfl, NULL); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
861 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
862 select_list = gtk_tree_selection_get_selected_rows(selection, &model); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
863 work = select_list; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
864 while (work) // FIXME this does not work for tree view |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
865 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
866 FileData *fd; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
867 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
868 tpath = work->data; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
869 gtk_tree_model_get_iter(model, &iter, tpath); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
870 gtk_tree_model_get(model, &iter, FILE_COLUMN_POINTER, &fd, -1); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
871 gtk_tree_path_free(tpath); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
872 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
873 work->data = fd; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
874 work = work->next; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
875 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
876 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
877 select_list = filelist_sort(select_list, vfl->sort_method, vfl->sort_ascend); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
878 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
879 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vfl->listview), &tpath, NULL); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
880 if (tpath) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
881 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
882 if (gtk_tree_model_get_iter(model, &iter, tpath)) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
883 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
884 gtk_tree_model_get(model, &iter, FILE_COLUMN_POINTER, &cursor_fd, -1); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
885 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
886 gtk_tree_path_free(tpath); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
887 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
888 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
889 single_select = (select_list && !select_list->next); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
890 if (single_select) cursor_fd = select_list->data; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
891 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
892 store = GTK_TREE_STORE(model); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
893 gtk_tree_store_clear(store); |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
894 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
895 work = vfl->list; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
896 while (work) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
897 { |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
898 FileData *fd = work->data; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
899 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
900 vflist_setup_iter(vfl, store, &iter, fd, NULL); |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
901 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
902 if (select_list && select_list->data == fd) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
903 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
904 select_list = g_list_remove(select_list, fd); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
905 gtk_tree_selection_select_iter(selection, &iter); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
906 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
907 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
908 work = work->next; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
909 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
910 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
911 g_list_free(select_list); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
912 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
913 if (cursor_fd && |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
914 vflist_find_row(vfl, cursor_fd, &iter) >= 0) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
915 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
916 if (single_select) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
917 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
918 vflist_move_cursor(vfl, &iter); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
919 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
920 else |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
921 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
922 tree_view_row_make_visible(GTK_TREE_VIEW(vfl->listview), &iter, TRUE); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
923 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
924 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
925 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
926 gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL); |
9 | 927 } |
928 | |
929 /* | |
930 *----------------------------------------------------------------------------- | |
931 * thumb updates | |
932 *----------------------------------------------------------------------------- | |
933 */ | |
934 | |
935 static gint vflist_thumb_next(ViewFileList *vfl); | |
936 | |
937 static void vflist_thumb_status(ViewFileList *vfl, gdouble val, const gchar *text) | |
938 { | |
939 if (vfl->func_thumb_status) | |
940 { | |
941 vfl->func_thumb_status(vfl, val, text, vfl->data_thumb_status); | |
942 } | |
943 } | |
944 | |
945 static void vflist_thumb_cleanup(ViewFileList *vfl) | |
946 { | |
947 vflist_thumb_status(vfl, 0.0, NULL); | |
948 | |
949 vfl->thumbs_count = 0; | |
950 vfl->thumbs_running = FALSE; | |
951 | |
952 thumb_loader_free(vfl->thumbs_loader); | |
953 vfl->thumbs_loader = NULL; | |
954 | |
955 vfl->thumbs_filedata = NULL; | |
956 } | |
957 | |
958 static void vflist_thumb_stop(ViewFileList *vfl) | |
959 { | |
960 if (vfl->thumbs_running) vflist_thumb_cleanup(vfl); | |
961 } | |
962 | |
963 static void vflist_thumb_do(ViewFileList *vfl, ThumbLoader *tl, FileData *fd) | |
964 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
965 GtkTreeStore *store; |
9 | 966 GtkTreeIter iter; |
967 | |
968 if (!fd || vflist_find_row(vfl, fd, &iter) < 0) return; | |
969 | |
970 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
971 fd->pixbuf = thumb_loader_get_pixbuf(tl, TRUE); | |
972 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
973 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
974 gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, fd->pixbuf, -1); |
9 | 975 |
976 vflist_thumb_status(vfl, (gdouble)(vfl->thumbs_count) / g_list_length(vfl->list), _("Loading thumbs...")); | |
977 } | |
978 | |
979 static void vflist_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
980 { | |
981 ViewFileList *vfl = data; | |
982 | |
983 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
984 { | |
985 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
986 } | |
987 | |
988 while (vflist_thumb_next(vfl)); | |
989 } | |
990 | |
991 static void vflist_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
992 { | |
993 ViewFileList *vfl = data; | |
994 | |
995 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
996 { | |
997 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
998 } | |
999 | |
1000 while (vflist_thumb_next(vfl)); | |
1001 } | |
1002 | |
1003 static gint vflist_thumb_next(ViewFileList *vfl) | |
1004 { | |
1005 GtkTreePath *tpath; | |
1006 FileData *fd = NULL; | |
1007 | |
1008 /* first check the visible files */ | |
1009 | |
1010 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1011 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1012 { | |
1013 GtkTreeModel *store; | |
1014 GtkTreeIter iter; | |
1015 gint valid = TRUE; | |
1016 | |
1017 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1018 gtk_tree_model_get_iter(store, &iter, tpath); | |
1019 gtk_tree_path_free(tpath); | |
1020 | |
1021 while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vfl->listview), &iter, FALSE) == 0) | |
1022 { | |
1023 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1024 if (fd->pixbuf) fd = NULL; | |
1025 | |
1026 valid = gtk_tree_model_iter_next(store, &iter); | |
1027 } | |
1028 } | |
1029 | |
1030 /* then find first undone */ | |
1031 | |
1032 if (!fd) | |
1033 { | |
1034 GList *work = vfl->list; | |
1035 while (work && !fd) | |
1036 { | |
1037 FileData *fd_p = work->data; | |
1038 work = work->next; | |
1039 | |
1040 if (!fd_p->pixbuf) fd = fd_p; | |
1041 } | |
1042 } | |
1043 | |
1044 if (!fd) | |
1045 { | |
1046 /* done */ | |
1047 vflist_thumb_cleanup(vfl); | |
1048 return FALSE; | |
1049 } | |
1050 | |
1051 vfl->thumbs_count++; | |
1052 | |
1053 vfl->thumbs_filedata = fd; | |
1054 | |
1055 thumb_loader_free(vfl->thumbs_loader); | |
1056 | |
1057 vfl->thumbs_loader = thumb_loader_new(thumb_max_width, thumb_max_height); | |
1058 thumb_loader_set_callbacks(vfl->thumbs_loader, | |
1059 vflist_thumb_done_cb, | |
1060 vflist_thumb_error_cb, | |
1061 NULL, | |
1062 vfl); | |
1063 | |
1064 if (!thumb_loader_start(vfl->thumbs_loader, fd->path)) | |
1065 { | |
1066 /* set icon to unknown, continue */ | |
1067 if (debug) printf("thumb loader start failed %s\n", vfl->thumbs_loader->path); | |
1068 vflist_thumb_do(vfl, vfl->thumbs_loader, fd); | |
1069 | |
1070 return TRUE; | |
1071 } | |
1072 | |
1073 return FALSE; | |
1074 } | |
1075 | |
1076 static void vflist_thumb_update(ViewFileList *vfl) | |
1077 { | |
1078 vflist_thumb_stop(vfl); | |
1079 if (!vfl->thumbs_enabled) return; | |
1080 | |
1081 vflist_thumb_status(vfl, 0.0, _("Loading thumbs...")); | |
1082 vfl->thumbs_running = TRUE; | |
1083 | |
1084 while (vflist_thumb_next(vfl)); | |
1085 } | |
1086 | |
1087 /* | |
1088 *----------------------------------------------------------------------------- | |
1089 * row stuff | |
1090 *----------------------------------------------------------------------------- | |
1091 */ | |
1092 | |
1093 FileData *vflist_index_get_data(ViewFileList *vfl, gint row) | |
1094 { | |
1095 return g_list_nth_data(vfl->list, row); | |
1096 } | |
1097 | |
1098 gchar *vflist_index_get_path(ViewFileList *vfl, gint row) | |
1099 { | |
1100 FileData *fd; | |
1101 | |
1102 fd = g_list_nth_data(vfl->list, row); | |
1103 | |
1104 return (fd ? fd->path : NULL); | |
1105 } | |
1106 | |
1107 static gint vflist_row_by_path(ViewFileList *vfl, const gchar *path, FileData **fd) | |
1108 { | |
1109 gint p = 0; | |
1110 GList *work; | |
1111 | |
1112 if (!path) return -1; | |
1113 | |
1114 work = vfl->list; | |
1115 while (work) | |
1116 { | |
1117 FileData *fd_n = work->data; | |
1118 if (strcmp(path, fd_n->path) == 0) | |
1119 { | |
1120 if (fd) *fd = fd_n; | |
1121 return p; | |
1122 } | |
1123 work = work->next; | |
1124 p++; | |
1125 } | |
1126 | |
1127 if (fd) *fd = NULL; | |
1128 return -1; | |
1129 } | |
1130 | |
1131 gint vflist_index_by_path(ViewFileList *vfl, const gchar *path) | |
1132 { | |
1133 return vflist_row_by_path(vfl, path, NULL); | |
1134 } | |
1135 | |
1136 gint vflist_count(ViewFileList *vfl, gint64 *bytes) | |
1137 { | |
1138 if (bytes) | |
1139 { | |
1140 gint64 b = 0; | |
1141 GList *work; | |
1142 | |
1143 work = vfl->list; | |
1144 while (work) | |
1145 { | |
1146 FileData *fd = work->data; | |
1147 work = work->next; | |
1148 b += fd->size; | |
1149 } | |
1150 | |
1151 *bytes = b; | |
1152 } | |
1153 | |
1154 return g_list_length(vfl->list); | |
1155 } | |
1156 | |
1157 GList *vflist_get_list(ViewFileList *vfl) | |
1158 { | |
1159 GList *list = NULL; | |
1160 GList *work; | |
1161 | |
1162 work = vfl->list; | |
1163 while (work) | |
1164 { | |
1165 FileData *fd = work->data; | |
1166 work = work->next; | |
1167 | |
138 | 1168 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1169 } |
1170 | |
1171 return g_list_reverse(list); | |
1172 } | |
1173 | |
1174 /* | |
1175 *----------------------------------------------------------------------------- | |
1176 * selections | |
1177 *----------------------------------------------------------------------------- | |
1178 */ | |
1179 | |
1180 static gint vflist_row_is_selected(ViewFileList *vfl, FileData *fd) | |
1181 { | |
1182 GtkTreeModel *store; | |
1183 GtkTreeSelection *selection; | |
1184 GList *slist; | |
1185 GList *work; | |
1186 gint found = FALSE; | |
1187 | |
1188 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1189 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1190 work = slist; | |
1191 while (!found && work) | |
1192 { | |
1193 GtkTreePath *tpath = work->data; | |
1194 FileData *fd_n; | |
1195 GtkTreeIter iter; | |
1196 | |
1197 gtk_tree_model_get_iter(store, &iter, tpath); | |
1198 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1); | |
1199 if (fd_n == fd) found = TRUE; | |
1200 work = work->next; | |
1201 } | |
1202 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1203 g_list_free(slist); | |
1204 | |
1205 return found; | |
1206 } | |
1207 | |
1208 gint vflist_index_is_selected(ViewFileList *vfl, gint row) | |
1209 { | |
1210 FileData *fd; | |
1211 | |
1212 fd = vflist_index_get_data(vfl, row); | |
1213 return vflist_row_is_selected(vfl, fd); | |
1214 } | |
1215 | |
1216 gint vflist_selection_count(ViewFileList *vfl, gint64 *bytes) | |
1217 { | |
1218 GtkTreeModel *store; | |
1219 GtkTreeSelection *selection; | |
1220 GList *slist; | |
1221 gint count; | |
1222 | |
1223 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1224 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1225 | |
1226 if (bytes) | |
1227 { | |
1228 gint64 b = 0; | |
1229 GList *work; | |
1230 | |
1231 work = slist; | |
1232 while (work) | |
1233 { | |
1234 GtkTreePath *tpath = work->data; | |
1235 GtkTreeIter iter; | |
1236 FileData *fd; | |
1237 | |
1238 gtk_tree_model_get_iter(store, &iter, tpath); | |
1239 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1240 b += fd->size; | |
1241 | |
1242 work = work->next; | |
1243 } | |
1244 | |
1245 *bytes = b; | |
1246 } | |
1247 | |
1248 count = g_list_length(slist); | |
1249 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1250 g_list_free(slist); | |
1251 | |
1252 return count; | |
1253 } | |
1254 | |
1255 GList *vflist_selection_get_list(ViewFileList *vfl) | |
1256 { | |
1257 GtkTreeModel *store; | |
1258 GtkTreeSelection *selection; | |
1259 GList *slist; | |
1260 GList *list = NULL; | |
1261 GList *work; | |
1262 | |
1263 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1264 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1265 work = slist; | |
1266 while (work) | |
1267 { | |
1268 GtkTreePath *tpath = work->data; | |
1269 FileData *fd; | |
1270 GtkTreeIter iter; | |
1271 | |
1272 gtk_tree_model_get_iter(store, &iter, tpath); | |
1273 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1274 | |
138 | 1275 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1276 |
1277 work = work->next; | |
1278 } | |
1279 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1280 g_list_free(slist); | |
1281 | |
1282 return g_list_reverse(list); | |
1283 } | |
1284 | |
1285 GList *vflist_selection_get_list_by_index(ViewFileList *vfl) | |
1286 { | |
1287 GtkTreeModel *store; | |
1288 GtkTreeSelection *selection; | |
1289 GList *slist; | |
1290 GList *list = NULL; | |
1291 GList *work; | |
1292 | |
1293 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1294 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1295 work = slist; | |
1296 while (work) | |
1297 { | |
1298 GtkTreePath *tpath = work->data; | |
1299 FileData *fd; | |
1300 GtkTreeIter iter; | |
1301 | |
1302 gtk_tree_model_get_iter(store, &iter, tpath); | |
1303 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1304 | |
1305 list = g_list_prepend(list, GINT_TO_POINTER(g_list_index(vfl->list, fd))); | |
1306 | |
1307 work = work->next; | |
1308 } | |
1309 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1310 g_list_free(slist); | |
1311 | |
1312 return g_list_reverse(list); | |
1313 } | |
1314 | |
1315 void vflist_select_all(ViewFileList *vfl) | |
1316 { | |
1317 GtkTreeSelection *selection; | |
1318 | |
1319 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1320 gtk_tree_selection_select_all(selection); | |
1321 | |
1322 vfl->select_fd = NULL; | |
1323 } | |
1324 | |
1325 void vflist_select_none(ViewFileList *vfl) | |
1326 { | |
1327 GtkTreeSelection *selection; | |
1328 | |
1329 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1330 gtk_tree_selection_unselect_all(selection); | |
1331 } | |
1332 | |
1333 void vflist_select_by_path(ViewFileList *vfl, const gchar *path) | |
1334 { | |
1335 FileData *fd; | |
138 | 1336 |
1337 if (vflist_row_by_path(vfl, path, &fd) < 0) return; | |
1338 | |
1339 vflist_select_by_fd(vfl, fd); | |
1340 } | |
1341 | |
1342 void vflist_select_by_fd(ViewFileList *vfl, FileData *fd) | |
1343 { | |
9 | 1344 GtkTreeIter iter; |
1345 | |
1346 if (vflist_find_row(vfl, fd, &iter) < 0) return; | |
1347 | |
1348 tree_view_row_make_visible(GTK_TREE_VIEW(vfl->listview), &iter, TRUE); | |
1349 | |
1350 if (!vflist_row_is_selected(vfl, fd)) | |
1351 { | |
1352 GtkTreeSelection *selection; | |
1353 GtkTreeModel *store; | |
1354 GtkTreePath *tpath; | |
1355 | |
1356 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1357 gtk_tree_selection_unselect_all(selection); | |
1358 gtk_tree_selection_select_iter(selection, &iter); | |
1359 vflist_move_cursor(vfl, &iter); | |
1360 | |
1361 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1362 tpath = gtk_tree_model_get_path(store, &iter); | |
1363 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vfl->listview), tpath, NULL, FALSE); | |
1364 gtk_tree_path_free(tpath); | |
1365 } | |
1366 } | |
1367 | |
1368 /* | |
1369 *----------------------------------------------------------------------------- | |
1370 * core (population) | |
1371 *----------------------------------------------------------------------------- | |
1372 */ | |
1373 | |
1374 static void vflist_listview_set_height(GtkWidget *listview, gint thumb) | |
1375 { | |
1376 GtkTreeViewColumn *column; | |
1377 GtkCellRenderer *cell; | |
1378 GList *list; | |
1379 | |
1380 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), FILE_COLUMN_THUMB - 1); | |
1381 if (!column) return; | |
1382 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1383 gtk_tree_view_column_set_fixed_width(column, ((thumb) ? thumb_max_width : 4) + 50); |
9 | 1384 |
1385 list = gtk_tree_view_column_get_cell_renderers(column); | |
1386 if (!list) return; | |
1387 cell = list->data; | |
1388 g_list_free(list); | |
1389 | |
1390 g_object_set(G_OBJECT(cell), "height", (thumb) ? thumb_max_height : -1, NULL); | |
1391 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview)); | |
1392 } | |
1393 | |
1394 static void vflist_populate_view(ViewFileList *vfl) | |
1395 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1396 GtkTreeStore *store; |
9 | 1397 GtkTreeIter iter; |
1398 gint thumbs; | |
1399 GList *work; | |
1400 GtkTreeRowReference *visible_row = NULL; | |
1401 GtkTreePath *tpath; | |
1402 gint valid; | |
1403 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1404 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 1405 thumbs = vfl->thumbs_enabled; |
1406 | |
1407 vflist_thumb_stop(vfl); | |
1408 | |
1409 if (!vfl->list) | |
1410 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1411 gtk_tree_store_clear(store); |
9 | 1412 vflist_send_update(vfl); |
1413 return; | |
1414 } | |
1415 | |
1416 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1417 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1418 { | |
1419 visible_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), tpath); | |
1420 gtk_tree_path_free(tpath); | |
1421 } | |
1422 | |
1423 vflist_listview_set_height(vfl->listview, thumbs); | |
1424 | |
1425 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); | |
1426 | |
1427 work = vfl->list; | |
1428 while (work) | |
1429 { | |
1430 gint match; | |
1431 FileData *fd = work->data; | |
1432 gint done = FALSE; | |
1433 | |
1434 while (!done) | |
1435 { | |
1436 FileData *old_fd = NULL; | |
132 | 1437 int i; |
1438 | |
9 | 1439 if (valid) |
1440 { | |
1441 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, -1); | |
1442 match = CASE_SORT(fd->name, old_fd->name); | |
1443 } | |
1444 else | |
1445 { | |
1446 match = -1; | |
1447 } | |
1448 | |
1449 if (match < 0) | |
1450 { | |
1451 GtkTreeIter new; | |
139 | 1452 |
9 | 1453 if (valid) |
1454 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1455 vflist_setup_iter(vfl, store, &new, fd, &iter); |
9 | 1456 } |
1457 else | |
1458 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1459 vflist_setup_iter(vfl, store, &new, fd, NULL); |
9 | 1460 } |
1461 | |
1462 done = TRUE; | |
1463 } | |
1464 else if (match > 0) | |
1465 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1466 valid = gtk_tree_store_remove(store, &iter); |
9 | 1467 } |
1468 else | |
1469 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1470 gtk_tree_store_set(store, &iter, FILE_COLUMN_POINTER, fd, -1); |
9 | 1471 if (fd->date != old_fd->date) |
1472 { | |
1473 gchar *size; | |
1474 | |
1475 /* update, file changed */ | |
1476 size = text_from_size(fd->size); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1477 gtk_tree_store_set(store, &iter, FILE_COLUMN_SIZE, size, |
9 | 1478 FILE_COLUMN_DATE, text_from_time(fd->date), -1); |
1479 g_free(size); | |
1480 } | |
1481 else if (fd != old_fd) | |
1482 { | |
1483 /* preserve thumbnail */ | |
1484 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
1485 fd->pixbuf = old_fd->pixbuf; | |
1486 if (fd->pixbuf) g_object_ref(fd->pixbuf); | |
1487 } | |
1488 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1489 gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, (thumbs) ? fd->pixbuf : NULL, -1); |
9 | 1490 |
1491 if (vfl->select_fd == old_fd) vfl->select_fd = fd; | |
1492 | |
1493 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1494 | |
1495 done = TRUE; | |
1496 } | |
1497 } | |
1498 work = work->next; | |
1499 } | |
1500 | |
1501 while (valid) | |
1502 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1503 valid = gtk_tree_store_remove(store, &iter); |
9 | 1504 } |
1505 | |
1506 if (visible_row) | |
1507 { | |
1508 if (gtk_tree_row_reference_valid(visible_row)) | |
1509 { | |
1510 tpath = gtk_tree_row_reference_get_path(visible_row); | |
1511 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vfl->listview), tpath, NULL, TRUE, 0.0, 0.0); | |
1512 gtk_tree_path_free(tpath); | |
1513 } | |
1514 gtk_tree_row_reference_free(visible_row); | |
1515 } | |
1516 | |
1517 vflist_send_update(vfl); | |
1518 vflist_thumb_update(vfl); | |
1519 } | |
1520 | |
1521 gint vflist_refresh(ViewFileList *vfl) | |
1522 { | |
1523 GList *old_list; | |
1524 gint ret = TRUE; | |
1525 | |
1526 old_list = vfl->list; | |
1527 vfl->list = NULL; | |
1528 | |
1529 if (vfl->path) | |
1530 { | |
1531 ret = filelist_read(vfl->path, &vfl->list, NULL); | |
1532 } | |
1533 | |
1534 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
1535 vflist_populate_view(vfl); | |
1536 | |
1537 filelist_free(old_list); | |
1538 | |
1539 return ret; | |
1540 } | |
1541 | |
1542 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ | |
1543 | |
1544 #define CELL_HEIGHT_OVERRIDE 512 | |
1545 | |
1546 static void cell_renderer_height_override(GtkCellRenderer *renderer) | |
1547 { | |
1548 GParamSpec *spec; | |
1549 | |
1550 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height"); | |
1551 if (spec && G_IS_PARAM_SPEC_INT(spec)) | |
1552 { | |
1553 GParamSpecInt *spec_int; | |
1554 | |
1555 spec_int = G_PARAM_SPEC_INT(spec); | |
1556 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE; | |
1557 } | |
1558 } | |
1559 | |
1560 static GdkColor *vflist_listview_color_shifted(GtkWidget *widget) | |
1561 { | |
1562 static GdkColor color; | |
1563 static GtkWidget *done = NULL; | |
1564 | |
1565 if (done != widget) | |
1566 { | |
1567 GtkStyle *style; | |
1568 | |
1569 style = gtk_widget_get_style(widget); | |
1570 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1571 shift_color(&color, -1, 0); | |
1572 done = widget; | |
1573 } | |
1574 | |
1575 return &color; | |
1576 } | |
1577 | |
1578 static void vflist_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1579 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1580 { | |
1581 ViewFileList *vfl = data; | |
1582 gboolean set; | |
1583 | |
1584 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1); | |
1585 g_object_set(G_OBJECT(cell), | |
1586 "cell-background-gdk", vflist_listview_color_shifted(vfl->listview), | |
1587 "cell-background-set", set, NULL); | |
1588 } | |
1589 | |
132 | 1590 static void vflist_listview_add_column(ViewFileList *vfl, gint n, const gchar *title, gint image, gint right_justify, gint expand) |
9 | 1591 { |
1592 GtkTreeViewColumn *column; | |
1593 GtkCellRenderer *renderer; | |
1594 | |
1595 column = gtk_tree_view_column_new(); | |
1596 gtk_tree_view_column_set_title(column, title); | |
1597 gtk_tree_view_column_set_min_width(column, 4); | |
1598 | |
1599 if (!image) | |
1600 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1601 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); |
9 | 1602 renderer = gtk_cell_renderer_text_new(); |
1603 if (right_justify) | |
1604 { | |
1605 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
1606 } | |
1607 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1608 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1609 if (expand) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1610 gtk_tree_view_column_set_expand(column, TRUE); |
132 | 1611 } |
9 | 1612 else |
1613 { | |
1614 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
1615 renderer = gtk_cell_renderer_pixbuf_new(); | |
1616 cell_renderer_height_override(renderer); | |
1617 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1618 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
1619 } | |
1620 | |
1621 gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vfl, NULL); | |
1622 | |
1623 gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); | |
1624 } | |
1625 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1626 static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store) |
132 | 1627 { |
1628 GtkTreePath *path = gtk_tree_path_new_from_string(path_str); | |
1629 guint *marks; | |
1630 GtkTreeIter iter; | |
1631 FileData *fd; | |
1632 gboolean mark; | |
1633 guint column; | |
1634 | |
1635 if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path)) | |
1636 return; | |
1637 | |
1638 column = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(cell), "column")); | |
1639 | |
1640 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, column, &mark, -1); | |
1641 mark ^= 1; | |
1642 fd->marks[column] = mark; | |
1643 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1644 gtk_tree_store_set(store, &iter, column, mark, -1); |
132 | 1645 gtk_tree_path_free(path); |
1646 } | |
1647 | |
1648 static void vflist_listview_add_column_toggle(ViewFileList *vfl, gint n, const gchar *title) | |
1649 { | |
1650 GtkTreeViewColumn *column; | |
1651 GtkCellRenderer *renderer; | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1652 GtkTreeStore *store; |
132 | 1653 gint index; |
1654 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1655 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
132 | 1656 |
1657 renderer = gtk_cell_renderer_toggle_new(); | |
1658 column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL); | |
1659 | |
1660 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
1661 g_object_set_data (G_OBJECT (column), "column", GUINT_TO_POINTER(n)); | |
1662 g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER(n)); | |
1663 | |
1664 index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); | |
1665 gtk_tree_view_column_set_fixed_width(column, 16); | |
1666 gtk_tree_view_column_set_visible(column, vfl->marks_enabled); | |
1667 | |
1668 | |
1669 g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store); | |
1670 } | |
1671 | |
9 | 1672 /* |
1673 *----------------------------------------------------------------------------- | |
1674 * base | |
1675 *----------------------------------------------------------------------------- | |
1676 */ | |
1677 | |
1678 gint vflist_set_path(ViewFileList *vfl, const gchar *path) | |
1679 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1680 GtkTreeStore *store; |
9 | 1681 |
1682 if (!path) return FALSE; | |
1683 if (vfl->path && strcmp(path, vfl->path) == 0) return TRUE; | |
1684 | |
1685 g_free(vfl->path); | |
1686 vfl->path = g_strdup(path); | |
1687 | |
1688 /* force complete reload */ | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1689 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1690 gtk_tree_store_clear(store); |
9 | 1691 |
1692 filelist_free(vfl->list); | |
1693 vfl->list = NULL; | |
1694 | |
1695 return vflist_refresh(vfl); | |
1696 } | |
1697 | |
1698 static void vflist_destroy_cb(GtkWidget *widget, gpointer data) | |
1699 { | |
1700 ViewFileList *vfl = data; | |
1701 | |
1702 if (vfl->popup) | |
1703 { | |
1704 g_signal_handlers_disconnect_matched(G_OBJECT(vfl->popup), G_SIGNAL_MATCH_DATA, | |
1705 0, 0, 0, NULL, vfl); | |
1706 gtk_widget_destroy(vfl->popup); | |
1707 } | |
1708 | |
1709 vflist_select_idle_cancel(vfl); | |
1710 vflist_thumb_stop(vfl); | |
1711 | |
1712 g_free(vfl->path); | |
1713 filelist_free(vfl->list); | |
1714 g_free(vfl); | |
1715 } | |
1716 | |
1717 ViewFileList *vflist_new(const gchar *path, gint thumbs) | |
1718 { | |
1719 ViewFileList *vfl; | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1720 GtkTreeStore *store; |
9 | 1721 GtkTreeSelection *selection; |
1722 | |
132 | 1723 GType *flist_types; |
1724 int i; | |
1725 | |
9 | 1726 vfl = g_new0(ViewFileList, 1); |
1727 | |
1728 vfl->path = NULL; | |
1729 vfl->list = NULL; | |
1730 vfl->click_fd = NULL; | |
1731 vfl->select_fd = NULL; | |
1732 vfl->sort_method = SORT_NAME; | |
1733 vfl->sort_ascend = TRUE; | |
1734 vfl->thumbs_enabled = thumbs; | |
1735 | |
1736 vfl->thumbs_running = FALSE; | |
1737 vfl->thumbs_count = 0; | |
1738 vfl->thumbs_loader = NULL; | |
1739 vfl->thumbs_filedata = NULL; | |
1740 | |
1741 vfl->select_idle_id = -1; | |
1742 | |
1743 vfl->popup = NULL; | |
1744 | |
1745 vfl->widget = gtk_scrolled_window_new(NULL, NULL); | |
1746 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vfl->widget), GTK_SHADOW_IN); | |
1747 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vfl->widget), | |
1748 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1749 g_signal_connect(G_OBJECT(vfl->widget), "destroy", | |
1750 G_CALLBACK(vflist_destroy_cb), vfl); | |
1751 | |
139 | 1752 flist_types = g_new(GType, FILE_COLUMN_COUNT); |
1753 flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER; | |
1754 flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF; | |
1755 flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING; | |
1756 flist_types[FILE_COLUMN_SIDECARS] = G_TYPE_STRING; | |
1757 flist_types[FILE_COLUMN_SIZE] = G_TYPE_STRING; | |
1758 flist_types[FILE_COLUMN_DATE] = G_TYPE_STRING; | |
1759 flist_types[FILE_COLUMN_COLOR] = G_TYPE_BOOLEAN; | |
1760 for (i = FILE_COLUMN_MARKS; i < FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE; i++) | |
1761 flist_types[i] = G_TYPE_BOOLEAN; | |
132 | 1762 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1763 store = gtk_tree_store_newv(FILE_COLUMN_COUNT, flist_types); |
139 | 1764 g_free(flist_types); |
132 | 1765 |
139 | 1766 vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 1767 g_object_unref(store); |
1768 | |
1769 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1770 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
1771 gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL); | |
1772 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1773 // gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE); |
9 | 1774 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfl->listview), FALSE); |
1775 | |
132 | 1776 vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE); |
1777 vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1778 vflist_listview_add_column(vfl, FILE_COLUMN_SIDECARS, _("Sidecars"), FALSE, FALSE, FALSE); |
132 | 1779 vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE); |
1780 vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, TRUE); | |
9 | 1781 |
139 | 1782 for(i = 0; i < FILEDATA_MARKS_SIZE;i++) |
1783 vflist_listview_add_column_toggle(vfl, i + FILE_COLUMN_MARKS, ""); | |
1784 | |
132 | 1785 |
139 | 1786 g_signal_connect(G_OBJECT(vfl->listview), "key_press_event", |
9 | 1787 G_CALLBACK(vflist_press_key_cb), vfl); |
1788 | |
1789 gtk_container_add (GTK_CONTAINER(vfl->widget), vfl->listview); | |
1790 gtk_widget_show(vfl->listview); | |
1791 | |
1792 vflist_dnd_init(vfl); | |
132 | 1793 |
9 | 1794 g_signal_connect(G_OBJECT(vfl->listview), "button_press_event", |
1795 G_CALLBACK(vflist_press_cb), vfl); | |
1796 g_signal_connect(G_OBJECT(vfl->listview), "button_release_event", | |
1797 G_CALLBACK(vflist_release_cb), vfl); | |
132 | 1798 |
1799 | |
9 | 1800 if (path) vflist_set_path(vfl, path); |
1801 | |
1802 return vfl; | |
1803 } | |
1804 | |
1805 void vflist_set_status_func(ViewFileList *vfl, | |
1806 void (*func)(ViewFileList *vfl, gpointer data), gpointer data) | |
1807 { | |
1808 vfl->func_status = func; | |
1809 vfl->data_status = data; | |
1810 } | |
1811 | |
1812 void vflist_set_thumb_status_func(ViewFileList *vfl, | |
1813 void (*func)(ViewFileList *vfl, gdouble val, const gchar *text, gpointer data), | |
1814 gpointer data) | |
1815 { | |
1816 vfl->func_thumb_status = func; | |
1817 vfl->data_thumb_status = data; | |
1818 } | |
1819 | |
1820 void vflist_thumb_set(ViewFileList *vfl, gint enable) | |
1821 { | |
1822 if (vfl->thumbs_enabled == enable) return; | |
1823 | |
1824 vfl->thumbs_enabled = enable; | |
1825 vflist_refresh(vfl); | |
1826 } | |
1827 | |
132 | 1828 void vflist_marks_set(ViewFileList *vfl, gint enable) |
1829 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1830 GtkTreeStore *store; |
132 | 1831 GtkTreeViewColumn *column; |
1832 int i; | |
1833 | |
1834 if (vfl->marks_enabled == enable) return; | |
1835 | |
1836 vfl->marks_enabled = enable; | |
1837 | |
1838 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) { | |
1839 /* index - 2 because column's store != tree view */ | |
1840 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vfl->listview), i + FILE_COLUMN_MARKS - 2); | |
1841 | |
1842 gtk_tree_view_column_set_visible(column, enable); | |
1843 } | |
1844 | |
1845 //vflist_refresh(vfl); | |
1846 } | |
1847 | |
9 | 1848 void vflist_set_layout(ViewFileList *vfl, LayoutWindow *layout) |
1849 { | |
1850 vfl->layout = layout; | |
1851 } | |
1852 | |
1853 /* | |
1854 *----------------------------------------------------------------------------- | |
1855 * maintenance (for rename, move, remove) | |
1856 *----------------------------------------------------------------------------- | |
1857 */ | |
1858 | |
1859 static gint vflist_maint_find_closest(ViewFileList *vfl, gint row, gint count, GList *ignore_list) | |
1860 { | |
1861 GList *list = NULL; | |
1862 GList *work; | |
1863 gint rev = row - 1; | |
1864 row ++; | |
1865 | |
1866 work = ignore_list; | |
1867 while (work) | |
1868 { | |
1869 gint f = vflist_index_by_path(vfl, work->data); | |
1870 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); | |
1871 work = work->next; | |
1872 } | |
1873 | |
1874 while (list) | |
1875 { | |
1876 gint c = TRUE; | |
1877 work = list; | |
1878 while (work && c) | |
1879 { | |
1880 gpointer p = work->data; | |
1881 work = work->next; | |
1882 if (row == GPOINTER_TO_INT(p)) | |
1883 { | |
1884 row++; | |
1885 c = FALSE; | |
1886 } | |
1887 if (rev == GPOINTER_TO_INT(p)) | |
1888 { | |
1889 rev--; | |
1890 c = FALSE; | |
1891 } | |
1892 if (!c) list = g_list_remove(list, p); | |
1893 } | |
1894 if (c && list) | |
1895 { | |
1896 g_list_free(list); | |
1897 list = NULL; | |
1898 } | |
1899 } | |
1900 if (row > count - 1) | |
1901 { | |
1902 if (rev < 0) | |
1903 return -1; | |
1904 else | |
1905 return rev; | |
1906 } | |
1907 else | |
1908 { | |
1909 return row; | |
1910 } | |
1911 } | |
1912 | |
138 | 1913 gint vflist_maint_renamed(ViewFileList *vfl, FileData *fd) |
9 | 1914 { |
1915 gint ret = FALSE; | |
1916 gint row; | |
1917 gchar *source_base; | |
1918 gchar *dest_base; | |
1919 GList *work; | |
1920 | |
138 | 1921 row = g_list_index(vfl->list, fd); |
9 | 1922 if (row < 0) return FALSE; |
1923 | |
138 | 1924 source_base = remove_level_from_path(fd->change->source); |
1925 dest_base = remove_level_from_path(fd->change->dest); | |
9 | 1926 |
1927 | |
1928 if (strcmp(source_base, dest_base) == 0) | |
1929 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1930 GtkTreeStore *store; |
9 | 1931 GtkTreeIter iter; |
1932 GtkTreeIter position; | |
1933 gint old_row; | |
1934 gint n; | |
1935 | |
1936 old_row = g_list_index(vfl->list, fd); | |
1937 | |
1938 vfl->list = g_list_remove(vfl->list, fd); | |
1939 | |
1940 vfl->list = filelist_insert_sort(vfl->list, fd, vfl->sort_method, vfl->sort_ascend); | |
1941 n = g_list_index(vfl->list, fd); | |
1942 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1943 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 1944 row = vflist_find_row(vfl, fd, &iter); |
1945 if (vflist_find_row(vfl, fd, &iter) >= 0 && | |
1946 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &position, NULL, n)) | |
1947 { | |
1948 if (old_row >= n) | |
1949 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1950 gtk_tree_store_move_before(store, &iter, &position); |
9 | 1951 } |
1952 else | |
1953 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1954 gtk_tree_store_move_after(store, &iter, &position); |
9 | 1955 } |
1956 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1957 gtk_tree_store_set(store, &iter, FILE_COLUMN_NAME, fd->name, -1); |
9 | 1958 |
1959 ret = TRUE; | |
1960 } | |
1961 else | |
1962 { | |
138 | 1963 ret = vflist_maint_removed(vfl, fd, NULL); |
9 | 1964 } |
1965 | |
1966 g_free(source_base); | |
1967 g_free(dest_base); | |
1968 | |
1969 return ret; | |
1970 } | |
1971 | |
138 | 1972 gint vflist_maint_removed(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 1973 { |
1974 GtkTreeIter iter; | |
1975 GList *list; | |
1976 gint row; | |
1977 gint new_row = -1; | |
1978 | |
138 | 1979 row = g_list_index(vfl->list, fd); |
9 | 1980 if (row < 0) return FALSE; |
1981 | |
1982 if (vflist_index_is_selected(vfl, row) && | |
1983 layout_image_get_collection(vfl->layout, NULL) == NULL) | |
1984 { | |
1985 gint n; | |
1986 | |
1987 n = vflist_count(vfl, NULL); | |
1988 if (ignore_list) | |
1989 { | |
1990 new_row = vflist_maint_find_closest(vfl, row, n, ignore_list); | |
1991 if (debug) printf("row = %d, closest is %d\n", row, new_row); | |
1992 } | |
1993 else | |
1994 { | |
1995 if (row + 1 < n) | |
1996 { | |
1997 new_row = row + 1; | |
1998 } | |
1999 else if (row > 0) | |
2000 { | |
2001 new_row = row - 1; | |
2002 } | |
2003 } | |
2004 vflist_select_none(vfl); | |
2005 if (new_row >= 0) | |
2006 { | |
2007 fd = vflist_index_get_data(vfl, new_row); | |
2008 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2009 { | |
2010 GtkTreeSelection *selection; | |
2011 | |
2012 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
2013 gtk_tree_selection_select_iter(selection, &iter); | |
2014 vflist_move_cursor(vfl, &iter); | |
2015 } | |
2016 } | |
2017 } | |
2018 | |
2019 fd = vflist_index_get_data(vfl, row); | |
2020 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2021 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2022 GtkTreeStore *store; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2023 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2024 gtk_tree_store_remove(store, &iter); |
9 | 2025 } |
2026 list = g_list_nth(vfl->list, row); | |
2027 fd = list->data; | |
2028 | |
2029 /* thumbnail loader check */ | |
2030 if (fd == vfl->thumbs_filedata) vfl->thumbs_filedata = NULL; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
93
diff
changeset
|
2031 if (vfl->thumbs_count > 0) vfl->thumbs_count--; |
9 | 2032 |
2033 vfl->list = g_list_remove(vfl->list, fd); | |
138 | 2034 file_data_unref(fd); |
9 | 2035 |
2036 vflist_send_update(vfl); | |
2037 | |
2038 return TRUE; | |
2039 } | |
2040 | |
138 | 2041 gint vflist_maint_moved(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 2042 { |
2043 gint ret = FALSE; | |
2044 gchar *buf; | |
2045 | |
138 | 2046 if (!fd->change->source || !vfl->path) return FALSE; |
9 | 2047 |
138 | 2048 buf = remove_level_from_path(fd->change->source); |
9 | 2049 |
2050 if (strcmp(buf, vfl->path) == 0) | |
2051 { | |
138 | 2052 ret = vflist_maint_removed(vfl, fd, ignore_list); |
9 | 2053 } |
2054 | |
2055 g_free(buf); | |
2056 | |
2057 return ret; | |
2058 } | |
2059 |