Mercurial > geeqie.yaz
annotate src/view_file_list.c @ 150:976fba0add7c
more operations with file marks
author | nadvornik |
---|---|
date | Sun, 25 Nov 2007 10:25:25 +0000 |
parents | f0c79a514c06 |
children | b73743a01384 |
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 | |
150 | 372 static void vflist_pop_menu_sel_mark_cb(GtkWidget *widget, gpointer data) |
373 { | |
374 ViewFileList *vfl = data; | |
375 vflist_select_marked(vfl, vfl->active_mark); | |
376 } | |
377 | |
378 static void vflist_pop_menu_set_mark_sel_cb(GtkWidget *widget, gpointer data) | |
379 { | |
380 ViewFileList *vfl = data; | |
381 vflist_mark_selected(vfl, vfl->active_mark, 1); | |
382 } | |
383 | |
384 static void vflist_pop_menu_res_mark_sel_cb(GtkWidget *widget, gpointer data) | |
385 { | |
386 ViewFileList *vfl = data; | |
387 vflist_mark_selected(vfl, vfl->active_mark, 0); | |
388 } | |
389 | |
390 static void vflist_pop_menu_toggle_mark_sel_cb(GtkWidget *widget, gpointer data) | |
391 { | |
392 ViewFileList *vfl = data; | |
393 vflist_mark_selected(vfl, vfl->active_mark, -1); | |
394 } | |
395 | |
396 | |
9 | 397 static void vflist_popup_destroy_cb(GtkWidget *widget, gpointer data) |
398 { | |
399 ViewFileList *vfl = data; | |
400 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
401 vfl->click_fd = NULL; | |
402 vfl->popup = NULL; | |
403 } | |
404 | |
150 | 405 |
406 static GtkWidget *vflist_pop_menu(ViewFileList *vfl, FileData *fd, gint col_idx) | |
9 | 407 { |
408 GtkWidget *menu; | |
409 GtkWidget *item; | |
410 GtkWidget *submenu; | |
411 gint active; | |
412 | |
413 vflist_color_set(vfl, fd, TRUE); | |
414 active = (fd != NULL); | |
415 | |
416 menu = popup_menu_short_lived(); | |
417 g_signal_connect(G_OBJECT(menu), "destroy", | |
418 G_CALLBACK(vflist_popup_destroy_cb), vfl); | |
419 | |
150 | 420 if (col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST) |
421 { | |
422 gint mark = col_idx - FILE_COLUMN_MARKS; | |
423 gchar *str_set_mark = g_strdup_printf(_("_Set mark %d"), mark + 1); | |
424 gchar *str_res_mark = g_strdup_printf(_("_Reset mark %d"), mark + 1); | |
425 gchar *str_toggle_mark = g_strdup_printf(_("_Toggle mark %d"), mark + 1); | |
426 gchar *str_sel_mark = g_strdup_printf(_("_Select mark %d"), mark + 1); | |
427 | |
428 | |
429 vfl->active_mark = mark; | |
430 menu_item_add_sensitive(menu, str_set_mark, active, | |
431 G_CALLBACK(vflist_pop_menu_set_mark_sel_cb), vfl); | |
432 | |
433 menu_item_add_sensitive(menu, str_res_mark, active, | |
434 G_CALLBACK(vflist_pop_menu_res_mark_sel_cb), vfl); | |
435 | |
436 menu_item_add_sensitive(menu, str_toggle_mark, active, | |
437 G_CALLBACK(vflist_pop_menu_toggle_mark_sel_cb), vfl); | |
438 | |
439 menu_item_add_sensitive(menu, str_sel_mark, active, | |
440 G_CALLBACK(vflist_pop_menu_sel_mark_cb), vfl); | |
441 | |
442 menu_item_add_divider(menu); | |
443 | |
444 g_free(str_set_mark); | |
445 g_free(str_res_mark); | |
446 g_free(str_toggle_mark); | |
447 g_free(str_sel_mark); | |
448 } | |
449 | |
9 | 450 submenu_add_edit(menu, &item, G_CALLBACK(vflist_pop_menu_edit_cb), vfl); |
451 gtk_widget_set_sensitive(item, active); | |
452 | |
453 menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, active, | |
454 G_CALLBACK(vflist_pop_menu_info_cb), vfl); | |
455 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active, | |
456 G_CALLBACK(vflist_pop_menu_view_cb), vfl); | |
457 | |
458 menu_item_add_divider(menu); | |
459 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, active, | |
460 G_CALLBACK(vflist_pop_menu_copy_cb), vfl); | |
461 menu_item_add_sensitive(menu, _("_Move..."), active, | |
462 G_CALLBACK(vflist_pop_menu_move_cb), vfl); | |
463 menu_item_add_sensitive(menu, _("_Rename..."), active, | |
464 G_CALLBACK(vflist_pop_menu_rename_cb), vfl); | |
465 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active, | |
466 G_CALLBACK(vflist_pop_menu_delete_cb), vfl); | |
467 | |
468 menu_item_add_divider(menu); | |
469 | |
470 submenu = submenu_add_sort(NULL, G_CALLBACK(vflist_pop_menu_sort_cb), vfl, | |
471 FALSE, FALSE, TRUE, vfl->sort_method); | |
472 menu_item_add_divider(submenu); | |
473 menu_item_add_check(submenu, _("Ascending"), vfl->sort_ascend, | |
474 G_CALLBACK(vflist_pop_menu_sort_ascend_cb), vfl); | |
475 | |
476 item = menu_item_add(menu, _("_Sort"), NULL, NULL); | |
477 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
478 | |
479 menu_item_add_check(menu, _("View as _icons"), FALSE, | |
480 G_CALLBACK(vflist_pop_menu_icons_cb), vfl); | |
481 menu_item_add_check(menu, _("Show _thumbnails"), vfl->thumbs_enabled, | |
482 G_CALLBACK(vflist_pop_menu_thumbs_cb), vfl); | |
483 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vflist_pop_menu_refresh_cb), vfl); | |
484 | |
485 return menu; | |
486 } | |
487 | |
488 /* | |
489 *----------------------------------------------------------------------------- | |
490 * callbacks | |
491 *----------------------------------------------------------------------------- | |
492 */ | |
493 | |
494 static gint vflist_row_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
495 { | |
496 ViewFileList *vfl = data; | |
497 gchar *old_path; | |
498 gchar *new_path; | |
499 | |
500 if (strlen(new) == 0) return FALSE; | |
501 | |
502 old_path = concat_dir_and_file(vfl->path, old); | |
503 new_path = concat_dir_and_file(vfl->path, new); | |
504 | |
505 if (strchr(new, '/') != NULL) | |
506 { | |
507 gchar *text = g_strdup_printf(_("Invalid file name:\n%s"), new); | |
508 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
509 g_free(text); | |
510 } | |
511 else if (isfile(new_path)) | |
512 { | |
513 gchar *text = g_strdup_printf(_("A file with name %s already exists."), new); | |
514 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
515 g_free(text); | |
516 } | |
138 | 517 else |
9 | 518 { |
138 | 519 gint row = vflist_index_by_path(vfl, old_path); |
520 if (row >= 0) | |
521 { | |
522 GList *work = g_list_nth(vfl->list, row); | |
523 FileData *fd = work->data; | |
143
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
142
diff
changeset
|
524 |
0d1bf3ac6cd8
improved FileDataChangeInfo structure, check for another file operation in progress
nadvornik
parents:
142
diff
changeset
|
525 if (!file_data_add_change_info(fd, FILEDATA_CHANGE_RENAME, old_path, new_path) || !rename_file_ext(fd)) |
138 | 526 { |
527 gchar *text = g_strdup_printf(_("Unable to rename file:\n%s\nto:\n%s"), old, new); | |
528 file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vfl->listview); | |
529 g_free(text); | |
530 } | |
531 } | |
532 | |
9 | 533 } |
534 g_free(old_path); | |
535 g_free(new_path); | |
536 | |
537 return FALSE; | |
538 } | |
539 | |
540 static void vflist_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
541 { | |
542 ViewFileList *vfl = data; | |
543 GtkTreeModel *store; | |
544 GtkTreeIter iter; | |
545 GtkTreePath *tpath; | |
546 gint cw, ch; | |
547 | |
548 if (vflist_find_row(vfl, vfl->click_fd, &iter) < 0) return; | |
549 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
550 tpath = gtk_tree_model_get_path(store, &iter); | |
551 tree_view_get_cell_clamped(GTK_TREE_VIEW(vfl->listview), tpath, FILE_COLUMN_NAME - 1, TRUE, x, y, &cw, &ch); | |
552 gtk_tree_path_free(tpath); | |
553 *y += ch; | |
554 popup_menu_position_clamp(menu, x, y, 0); | |
555 } | |
556 | |
557 static gint vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
558 { | |
559 ViewFileList *vfl = data; | |
560 GtkTreePath *tpath; | |
561 | |
562 if (event->keyval != GDK_Menu) return FALSE; | |
563 | |
564 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vfl->listview), &tpath, NULL); | |
565 if (tpath) | |
566 { | |
567 GtkTreeModel *store; | |
568 GtkTreeIter iter; | |
569 | |
570 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
571 gtk_tree_model_get_iter(store, &iter, tpath); | |
572 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vfl->click_fd, -1); | |
573 gtk_tree_path_free(tpath); | |
574 } | |
575 else | |
576 { | |
577 vfl->click_fd = NULL; | |
578 } | |
579 | |
150 | 580 vfl->popup = vflist_pop_menu(vfl, vfl->click_fd, 0); |
9 | 581 gtk_menu_popup(GTK_MENU(vfl->popup), NULL, NULL, vflist_menu_position_cb, vfl, 0, GDK_CURRENT_TIME); |
582 | |
583 return TRUE; | |
584 } | |
585 | |
586 static gint vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
587 { | |
588 ViewFileList *vfl = data; | |
589 GtkTreePath *tpath; | |
590 GtkTreeIter iter; | |
591 FileData *fd = NULL; | |
149 | 592 GtkTreeViewColumn *column; |
150 | 593 gint col_idx = 0; |
132 | 594 |
9 | 595 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, |
132 | 596 &tpath, &column, NULL, NULL)) |
9 | 597 { |
598 GtkTreeModel *store; | |
149 | 599 col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column_store_idx")); |
132 | 600 |
149 | 601 if (bevent->button == 1 && |
602 col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST) | |
603 return FALSE; | |
132 | 604 |
149 | 605 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); |
9 | 606 |
607 gtk_tree_model_get_iter(store, &iter, tpath); | |
608 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
609 #if 0 | |
610 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
611 #endif | |
612 gtk_tree_path_free(tpath); | |
613 } | |
614 | |
615 vfl->click_fd = fd; | |
616 | |
617 if (bevent->button == 3) | |
618 { | |
150 | 619 vfl->popup = vflist_pop_menu(vfl, vfl->click_fd, col_idx); |
9 | 620 gtk_menu_popup(GTK_MENU(vfl->popup), NULL, NULL, NULL, NULL, |
621 bevent->button, bevent->time); | |
622 return TRUE; | |
623 } | |
624 | |
625 if (!fd) return FALSE; | |
626 | |
627 if (bevent->button == 2) | |
628 { | |
629 if (!vflist_row_is_selected(vfl, fd)) | |
630 { | |
631 vflist_color_set(vfl, fd, TRUE); | |
632 } | |
633 return TRUE; | |
634 } | |
635 | |
636 | |
637 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS && | |
638 !(bevent->state & GDK_SHIFT_MASK ) && | |
639 !(bevent->state & GDK_CONTROL_MASK ) && | |
640 vflist_row_is_selected(vfl, fd)) | |
641 { | |
642 gtk_widget_grab_focus(widget); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
643 // return TRUE; // FIXME - expand |
9 | 644 } |
645 | |
646 #if 0 | |
647 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) | |
648 { | |
649 if (vfl->layout) layout_image_full_screen_start(vfl->layout); | |
650 } | |
651 #endif | |
652 | |
653 return FALSE; | |
654 } | |
655 | |
656 static gint vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
657 { | |
658 ViewFileList *vfl = data; | |
659 GtkTreePath *tpath; | |
660 GtkTreeIter iter; | |
661 FileData *fd = NULL; | |
662 | |
663 if (bevent->button == 2) | |
664 { | |
665 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
666 } | |
667 | |
668 if (bevent->button != 1 && bevent->button != 2) | |
669 { | |
670 return TRUE; | |
671 } | |
672 | |
673 if ((bevent->x != 0 || bevent->y != 0) && | |
674 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
675 &tpath, NULL, NULL, NULL)) | |
676 { | |
677 GtkTreeModel *store; | |
678 | |
679 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
680 gtk_tree_model_get_iter(store, &iter, tpath); | |
681 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
682 gtk_tree_path_free(tpath); | |
683 } | |
684 | |
685 if (bevent->button == 2) | |
686 { | |
687 if (fd && vfl->click_fd == fd) | |
688 { | |
689 GtkTreeSelection *selection; | |
690 | |
691 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
692 if (vflist_row_is_selected(vfl, fd)) | |
693 { | |
694 gtk_tree_selection_unselect_iter(selection, &iter); | |
695 } | |
696 else | |
697 { | |
698 gtk_tree_selection_select_iter(selection, &iter); | |
699 } | |
700 } | |
701 return TRUE; | |
702 } | |
703 | |
704 if (fd && vfl->click_fd == fd && | |
705 !(bevent->state & GDK_SHIFT_MASK ) && | |
706 !(bevent->state & GDK_CONTROL_MASK ) && | |
707 vflist_row_is_selected(vfl, fd)) | |
708 { | |
709 GtkTreeSelection *selection; | |
710 | |
711 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
712 gtk_tree_selection_unselect_all(selection); | |
713 gtk_tree_selection_select_iter(selection, &iter); | |
714 vflist_move_cursor(vfl, &iter); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
715 // return TRUE;// FIXME - expand |
9 | 716 } |
717 | |
718 return FALSE; | |
719 } | |
720 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
721 static void vflist_select_image(ViewFileList *vfl, FileData *sel_fd) |
9 | 722 { |
138 | 723 FileData *read_ahead_fd = NULL; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
724 gint row; |
144 | 725 FileData *cur_fd; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
726 if (!sel_fd) return; |
144 | 727 |
728 cur_fd = layout_image_get_fd(vfl->layout); | |
729 if (sel_fd == cur_fd) return; /* no change */ | |
730 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
731 row = g_list_index(vfl->list, sel_fd); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
732 // FIXME sidecar data |
9 | 733 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
734 if (sel_fd && enable_read_ahead && row >= 0) |
9 | 735 { |
144 | 736 if (row > g_list_index(vfl->list, cur_fd) && |
9 | 737 row + 1 < vflist_count(vfl, NULL)) |
738 { | |
144 | 739 read_ahead_fd = vflist_index_get_data(vfl, row + 1); |
9 | 740 } |
741 else if (row > 0) | |
742 { | |
144 | 743 read_ahead_fd = vflist_index_get_data(vfl, row - 1); |
9 | 744 } |
745 } | |
746 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
747 layout_image_set_with_ahead(vfl->layout, sel_fd, read_ahead_fd); |
9 | 748 } |
749 | |
750 static gint vflist_select_idle_cb(gpointer data) | |
751 { | |
752 ViewFileList *vfl = data; | |
753 | |
754 if (!vfl->layout) | |
755 { | |
756 vfl->select_idle_id = -1; | |
757 return FALSE; | |
758 } | |
759 | |
760 vflist_send_update(vfl); | |
761 | |
762 if (vfl->select_fd) | |
763 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
764 vflist_select_image(vfl, vfl->select_fd); |
9 | 765 vfl->select_fd = NULL; |
766 } | |
767 | |
768 vfl->select_idle_id = -1; | |
769 return FALSE; | |
770 } | |
771 | |
772 static void vflist_select_idle_cancel(ViewFileList *vfl) | |
773 { | |
774 if (vfl->select_idle_id != -1) g_source_remove(vfl->select_idle_id); | |
775 vfl->select_idle_id = -1; | |
776 } | |
777 | |
778 static gboolean vflist_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
779 gboolean path_currently_selected, gpointer data) | |
780 { | |
781 ViewFileList *vfl = data; | |
782 GtkTreeIter iter; | |
783 | |
784 if (!path_currently_selected && | |
785 gtk_tree_model_get_iter(store, &iter, tpath)) | |
786 { | |
787 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vfl->select_fd, -1); | |
788 } | |
789 else | |
790 { | |
791 vfl->select_fd = NULL; | |
792 } | |
793 | |
794 if (vfl->layout && | |
795 vfl->select_idle_id == -1) | |
796 { | |
797 vfl->select_idle_id = g_idle_add(vflist_select_idle_cb, vfl); | |
798 } | |
799 | |
800 return TRUE; | |
801 } | |
802 | |
803 /* | |
804 *----------------------------------------------------------------------------- | |
805 * misc | |
806 *----------------------------------------------------------------------------- | |
807 */ | |
808 | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
809 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
|
810 gboolean path_currently_selected, gpointer data) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
811 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
812 return TRUE; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
813 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
814 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
815 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
816 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
817 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
|
818 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
819 gchar *size; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
820 gchar *sidecars; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
821 int i; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
822 GList *work; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
823 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
824 sidecars = sidecar_file_data_list_to_string(fd); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
825 size = text_from_size(fd->size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
826 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
827 if (before) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
828 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
829 gtk_tree_store_insert_before(store, iter, NULL, before); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
830 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
831 else |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
832 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
833 gtk_tree_store_append(store, iter, NULL); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
834 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
835 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
836 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
|
837 FILE_COLUMN_THUMB, (vfl->thumbs_enabled) ? fd->pixbuf : NULL, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
838 FILE_COLUMN_NAME, fd->name, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
839 FILE_COLUMN_SIDECARS, sidecars, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
840 FILE_COLUMN_SIZE, size, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
841 FILE_COLUMN_DATE, text_from_time(fd->date), |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
842 FILE_COLUMN_COLOR, FALSE, -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
843 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
844 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
|
845 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
846 g_free(size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
847 g_free(sidecars); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
848 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
849 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
850 work = fd->sidecar_files; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
851 while (work) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
852 { |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
853 GtkTreeIter s_iter; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
854 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
855 FileData *sfd = work->data; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
856 work = work->next; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
857 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
858 size = text_from_size(sfd->size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
859 gtk_tree_store_append(store, &s_iter, iter); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
860 gtk_tree_store_set(store, &s_iter, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
861 FILE_COLUMN_POINTER, sfd, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
862 FILE_COLUMN_NAME, sfd->name, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
863 FILE_COLUMN_SIZE, size, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
864 FILE_COLUMN_DATE, text_from_time(sfd->date), |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
865 -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
866 g_free(size); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
867 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
868 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
869 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
870 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
871 |
9 | 872 void vflist_sort_set(ViewFileList *vfl, SortType type, gint ascend) |
873 { | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
874 GtkTreeModel *model; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
875 GtkTreeStore *store; |
9 | 876 GList *work; |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
877 GtkTreeSelection *selection; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
878 GtkTreePath *tpath; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
879 GtkTreeIter iter; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
880 GList *select_list; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
881 FileData *cursor_fd = NULL; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
882 gint single_select; |
9 | 883 |
884 if (vfl->sort_method == type && vfl->sort_ascend == ascend) return; | |
885 | |
886 vfl->sort_method = type; | |
887 vfl->sort_ascend = ascend; | |
888 | |
889 if (!vfl->list) return; | |
890 | |
891 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
892 | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
893 /* 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
|
894 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
895 #if 0 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
896 /* this is simpler, but much slower */ |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
897 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 898 |
899 work = g_list_last(vfl->list); | |
900 while (work) | |
901 { | |
902 FileData *fd; | |
903 GtkTreeIter iter; | |
904 | |
905 fd = work->data; | |
906 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
907 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
908 gtk_tree_store_move_after(store, &iter, NULL); |
9 | 909 } |
910 | |
911 work = work->prev; | |
912 } | |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
913 #endif |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
914 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
915 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
|
916 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
917 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
|
918 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
919 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
|
920 work = select_list; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
921 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
|
922 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
923 FileData *fd; |
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 tpath = work->data; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
926 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
|
927 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
|
928 gtk_tree_path_free(tpath); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
929 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
930 work->data = fd; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
931 work = work->next; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
932 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
933 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
934 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
|
935 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
936 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
|
937 if (tpath) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
938 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
939 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
|
940 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
941 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
|
942 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
943 gtk_tree_path_free(tpath); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
944 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
945 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
946 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
|
947 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
|
948 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
949 store = GTK_TREE_STORE(model); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
950 gtk_tree_store_clear(store); |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
951 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
952 work = vfl->list; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
953 while (work) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
954 { |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
955 FileData *fd = work->data; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
956 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
957 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
|
958 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
959 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
|
960 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
961 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
|
962 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
|
963 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
964 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
965 work = work->next; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
966 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
967 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
968 g_list_free(select_list); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
969 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
970 if (cursor_fd && |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
971 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
|
972 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
973 if (single_select) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
974 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
975 vflist_move_cursor(vfl, &iter); |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
976 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
977 else |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
978 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
979 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
|
980 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
981 } |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
982 |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
983 gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL); |
9 | 984 } |
985 | |
986 /* | |
987 *----------------------------------------------------------------------------- | |
988 * thumb updates | |
989 *----------------------------------------------------------------------------- | |
990 */ | |
991 | |
992 static gint vflist_thumb_next(ViewFileList *vfl); | |
993 | |
994 static void vflist_thumb_status(ViewFileList *vfl, gdouble val, const gchar *text) | |
995 { | |
996 if (vfl->func_thumb_status) | |
997 { | |
998 vfl->func_thumb_status(vfl, val, text, vfl->data_thumb_status); | |
999 } | |
1000 } | |
1001 | |
1002 static void vflist_thumb_cleanup(ViewFileList *vfl) | |
1003 { | |
1004 vflist_thumb_status(vfl, 0.0, NULL); | |
1005 | |
1006 vfl->thumbs_count = 0; | |
1007 vfl->thumbs_running = FALSE; | |
1008 | |
1009 thumb_loader_free(vfl->thumbs_loader); | |
1010 vfl->thumbs_loader = NULL; | |
1011 | |
1012 vfl->thumbs_filedata = NULL; | |
1013 } | |
1014 | |
1015 static void vflist_thumb_stop(ViewFileList *vfl) | |
1016 { | |
1017 if (vfl->thumbs_running) vflist_thumb_cleanup(vfl); | |
1018 } | |
1019 | |
1020 static void vflist_thumb_do(ViewFileList *vfl, ThumbLoader *tl, FileData *fd) | |
1021 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1022 GtkTreeStore *store; |
9 | 1023 GtkTreeIter iter; |
1024 | |
1025 if (!fd || vflist_find_row(vfl, fd, &iter) < 0) return; | |
1026 | |
1027 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
1028 fd->pixbuf = thumb_loader_get_pixbuf(tl, TRUE); | |
1029 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1030 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
|
1031 gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, fd->pixbuf, -1); |
9 | 1032 |
1033 vflist_thumb_status(vfl, (gdouble)(vfl->thumbs_count) / g_list_length(vfl->list), _("Loading thumbs...")); | |
1034 } | |
1035 | |
1036 static void vflist_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1037 { | |
1038 ViewFileList *vfl = data; | |
1039 | |
1040 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
1041 { | |
1042 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
1043 } | |
1044 | |
1045 while (vflist_thumb_next(vfl)); | |
1046 } | |
1047 | |
1048 static void vflist_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1049 { | |
1050 ViewFileList *vfl = data; | |
1051 | |
1052 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
1053 { | |
1054 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
1055 } | |
1056 | |
1057 while (vflist_thumb_next(vfl)); | |
1058 } | |
1059 | |
1060 static gint vflist_thumb_next(ViewFileList *vfl) | |
1061 { | |
1062 GtkTreePath *tpath; | |
1063 FileData *fd = NULL; | |
1064 | |
1065 /* first check the visible files */ | |
1066 | |
1067 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1068 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1069 { | |
1070 GtkTreeModel *store; | |
1071 GtkTreeIter iter; | |
1072 gint valid = TRUE; | |
1073 | |
1074 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1075 gtk_tree_model_get_iter(store, &iter, tpath); | |
1076 gtk_tree_path_free(tpath); | |
1077 | |
1078 while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vfl->listview), &iter, FALSE) == 0) | |
1079 { | |
1080 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1081 if (fd->pixbuf) fd = NULL; | |
1082 | |
1083 valid = gtk_tree_model_iter_next(store, &iter); | |
1084 } | |
1085 } | |
1086 | |
1087 /* then find first undone */ | |
1088 | |
1089 if (!fd) | |
1090 { | |
1091 GList *work = vfl->list; | |
1092 while (work && !fd) | |
1093 { | |
1094 FileData *fd_p = work->data; | |
1095 work = work->next; | |
1096 | |
1097 if (!fd_p->pixbuf) fd = fd_p; | |
1098 } | |
1099 } | |
1100 | |
1101 if (!fd) | |
1102 { | |
1103 /* done */ | |
1104 vflist_thumb_cleanup(vfl); | |
1105 return FALSE; | |
1106 } | |
1107 | |
1108 vfl->thumbs_count++; | |
1109 | |
1110 vfl->thumbs_filedata = fd; | |
1111 | |
1112 thumb_loader_free(vfl->thumbs_loader); | |
1113 | |
1114 vfl->thumbs_loader = thumb_loader_new(thumb_max_width, thumb_max_height); | |
1115 thumb_loader_set_callbacks(vfl->thumbs_loader, | |
1116 vflist_thumb_done_cb, | |
1117 vflist_thumb_error_cb, | |
1118 NULL, | |
1119 vfl); | |
1120 | |
1121 if (!thumb_loader_start(vfl->thumbs_loader, fd->path)) | |
1122 { | |
1123 /* set icon to unknown, continue */ | |
1124 if (debug) printf("thumb loader start failed %s\n", vfl->thumbs_loader->path); | |
1125 vflist_thumb_do(vfl, vfl->thumbs_loader, fd); | |
1126 | |
1127 return TRUE; | |
1128 } | |
1129 | |
1130 return FALSE; | |
1131 } | |
1132 | |
1133 static void vflist_thumb_update(ViewFileList *vfl) | |
1134 { | |
1135 vflist_thumb_stop(vfl); | |
1136 if (!vfl->thumbs_enabled) return; | |
1137 | |
1138 vflist_thumb_status(vfl, 0.0, _("Loading thumbs...")); | |
1139 vfl->thumbs_running = TRUE; | |
1140 | |
1141 while (vflist_thumb_next(vfl)); | |
1142 } | |
1143 | |
1144 /* | |
1145 *----------------------------------------------------------------------------- | |
1146 * row stuff | |
1147 *----------------------------------------------------------------------------- | |
1148 */ | |
1149 | |
1150 FileData *vflist_index_get_data(ViewFileList *vfl, gint row) | |
1151 { | |
1152 return g_list_nth_data(vfl->list, row); | |
1153 } | |
1154 | |
1155 gchar *vflist_index_get_path(ViewFileList *vfl, gint row) | |
1156 { | |
1157 FileData *fd; | |
1158 | |
1159 fd = g_list_nth_data(vfl->list, row); | |
1160 | |
1161 return (fd ? fd->path : NULL); | |
1162 } | |
1163 | |
1164 static gint vflist_row_by_path(ViewFileList *vfl, const gchar *path, FileData **fd) | |
1165 { | |
1166 gint p = 0; | |
1167 GList *work; | |
1168 | |
1169 if (!path) return -1; | |
1170 | |
1171 work = vfl->list; | |
1172 while (work) | |
1173 { | |
1174 FileData *fd_n = work->data; | |
1175 if (strcmp(path, fd_n->path) == 0) | |
1176 { | |
1177 if (fd) *fd = fd_n; | |
1178 return p; | |
1179 } | |
1180 work = work->next; | |
1181 p++; | |
1182 } | |
1183 | |
1184 if (fd) *fd = NULL; | |
1185 return -1; | |
1186 } | |
1187 | |
1188 gint vflist_index_by_path(ViewFileList *vfl, const gchar *path) | |
1189 { | |
1190 return vflist_row_by_path(vfl, path, NULL); | |
1191 } | |
1192 | |
1193 gint vflist_count(ViewFileList *vfl, gint64 *bytes) | |
1194 { | |
1195 if (bytes) | |
1196 { | |
1197 gint64 b = 0; | |
1198 GList *work; | |
1199 | |
1200 work = vfl->list; | |
1201 while (work) | |
1202 { | |
1203 FileData *fd = work->data; | |
1204 work = work->next; | |
1205 b += fd->size; | |
1206 } | |
1207 | |
1208 *bytes = b; | |
1209 } | |
1210 | |
1211 return g_list_length(vfl->list); | |
1212 } | |
1213 | |
1214 GList *vflist_get_list(ViewFileList *vfl) | |
1215 { | |
1216 GList *list = NULL; | |
1217 GList *work; | |
1218 | |
1219 work = vfl->list; | |
1220 while (work) | |
1221 { | |
1222 FileData *fd = work->data; | |
1223 work = work->next; | |
1224 | |
138 | 1225 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1226 } |
1227 | |
1228 return g_list_reverse(list); | |
1229 } | |
1230 | |
1231 /* | |
1232 *----------------------------------------------------------------------------- | |
1233 * selections | |
1234 *----------------------------------------------------------------------------- | |
1235 */ | |
1236 | |
1237 static gint vflist_row_is_selected(ViewFileList *vfl, FileData *fd) | |
1238 { | |
1239 GtkTreeModel *store; | |
1240 GtkTreeSelection *selection; | |
1241 GList *slist; | |
1242 GList *work; | |
1243 gint found = FALSE; | |
1244 | |
1245 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1246 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1247 work = slist; | |
1248 while (!found && work) | |
1249 { | |
1250 GtkTreePath *tpath = work->data; | |
1251 FileData *fd_n; | |
1252 GtkTreeIter iter; | |
1253 | |
1254 gtk_tree_model_get_iter(store, &iter, tpath); | |
1255 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1); | |
1256 if (fd_n == fd) found = TRUE; | |
1257 work = work->next; | |
1258 } | |
1259 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1260 g_list_free(slist); | |
1261 | |
1262 return found; | |
1263 } | |
1264 | |
1265 gint vflist_index_is_selected(ViewFileList *vfl, gint row) | |
1266 { | |
1267 FileData *fd; | |
1268 | |
1269 fd = vflist_index_get_data(vfl, row); | |
1270 return vflist_row_is_selected(vfl, fd); | |
1271 } | |
1272 | |
1273 gint vflist_selection_count(ViewFileList *vfl, gint64 *bytes) | |
1274 { | |
1275 GtkTreeModel *store; | |
1276 GtkTreeSelection *selection; | |
1277 GList *slist; | |
1278 gint count; | |
1279 | |
1280 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1281 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1282 | |
1283 if (bytes) | |
1284 { | |
1285 gint64 b = 0; | |
1286 GList *work; | |
1287 | |
1288 work = slist; | |
1289 while (work) | |
1290 { | |
1291 GtkTreePath *tpath = work->data; | |
1292 GtkTreeIter iter; | |
1293 FileData *fd; | |
1294 | |
1295 gtk_tree_model_get_iter(store, &iter, tpath); | |
1296 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1297 b += fd->size; | |
1298 | |
1299 work = work->next; | |
1300 } | |
1301 | |
1302 *bytes = b; | |
1303 } | |
1304 | |
1305 count = g_list_length(slist); | |
1306 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1307 g_list_free(slist); | |
1308 | |
1309 return count; | |
1310 } | |
1311 | |
1312 GList *vflist_selection_get_list(ViewFileList *vfl) | |
1313 { | |
1314 GtkTreeModel *store; | |
1315 GtkTreeSelection *selection; | |
1316 GList *slist; | |
1317 GList *list = NULL; | |
1318 GList *work; | |
1319 | |
1320 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1321 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1322 work = slist; | |
1323 while (work) | |
1324 { | |
1325 GtkTreePath *tpath = work->data; | |
1326 FileData *fd; | |
1327 GtkTreeIter iter; | |
1328 | |
1329 gtk_tree_model_get_iter(store, &iter, tpath); | |
1330 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1331 | |
138 | 1332 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1333 |
1334 work = work->next; | |
1335 } | |
1336 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1337 g_list_free(slist); | |
1338 | |
1339 return g_list_reverse(list); | |
1340 } | |
1341 | |
1342 GList *vflist_selection_get_list_by_index(ViewFileList *vfl) | |
1343 { | |
1344 GtkTreeModel *store; | |
1345 GtkTreeSelection *selection; | |
1346 GList *slist; | |
1347 GList *list = NULL; | |
1348 GList *work; | |
1349 | |
1350 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1351 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1352 work = slist; | |
1353 while (work) | |
1354 { | |
1355 GtkTreePath *tpath = work->data; | |
1356 FileData *fd; | |
1357 GtkTreeIter iter; | |
1358 | |
1359 gtk_tree_model_get_iter(store, &iter, tpath); | |
1360 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1361 | |
1362 list = g_list_prepend(list, GINT_TO_POINTER(g_list_index(vfl->list, fd))); | |
1363 | |
1364 work = work->next; | |
1365 } | |
1366 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1367 g_list_free(slist); | |
1368 | |
1369 return g_list_reverse(list); | |
1370 } | |
1371 | |
1372 void vflist_select_all(ViewFileList *vfl) | |
1373 { | |
1374 GtkTreeSelection *selection; | |
1375 | |
1376 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1377 gtk_tree_selection_select_all(selection); | |
1378 | |
1379 vfl->select_fd = NULL; | |
1380 } | |
1381 | |
1382 void vflist_select_none(ViewFileList *vfl) | |
1383 { | |
1384 GtkTreeSelection *selection; | |
1385 | |
1386 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1387 gtk_tree_selection_unselect_all(selection); | |
1388 } | |
1389 | |
1390 void vflist_select_by_path(ViewFileList *vfl, const gchar *path) | |
1391 { | |
1392 FileData *fd; | |
138 | 1393 |
1394 if (vflist_row_by_path(vfl, path, &fd) < 0) return; | |
1395 | |
1396 vflist_select_by_fd(vfl, fd); | |
1397 } | |
1398 | |
1399 void vflist_select_by_fd(ViewFileList *vfl, FileData *fd) | |
1400 { | |
9 | 1401 GtkTreeIter iter; |
1402 | |
1403 if (vflist_find_row(vfl, fd, &iter) < 0) return; | |
1404 | |
1405 tree_view_row_make_visible(GTK_TREE_VIEW(vfl->listview), &iter, TRUE); | |
1406 | |
1407 if (!vflist_row_is_selected(vfl, fd)) | |
1408 { | |
1409 GtkTreeSelection *selection; | |
1410 GtkTreeModel *store; | |
1411 GtkTreePath *tpath; | |
1412 | |
1413 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1414 gtk_tree_selection_unselect_all(selection); | |
1415 gtk_tree_selection_select_iter(selection, &iter); | |
1416 vflist_move_cursor(vfl, &iter); | |
1417 | |
1418 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1419 tpath = gtk_tree_model_get_path(store, &iter); | |
1420 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vfl->listview), tpath, NULL, FALSE); | |
1421 gtk_tree_path_free(tpath); | |
1422 } | |
1423 } | |
1424 | |
150 | 1425 void vflist_select_marked(ViewFileList *vfl, gint mark) |
1426 { | |
1427 GtkTreeModel *store; | |
1428 GtkTreeIter iter; | |
1429 GtkTreeSelection *selection; | |
1430 gint valid; | |
1431 | |
1432 g_assert(mark >= 0 && mark < FILEDATA_MARKS_SIZE); | |
1433 | |
1434 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1435 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1436 gtk_tree_selection_unselect_all(selection); | |
1437 | |
1438 valid = gtk_tree_model_get_iter_first(store, &iter); | |
1439 while (valid) | |
1440 { | |
1441 FileData *fd; | |
1442 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1443 | |
1444 if (fd->marks[mark]) | |
1445 gtk_tree_selection_select_iter(selection, &iter); | |
1446 | |
1447 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1448 } | |
1449 | |
1450 } | |
1451 | |
1452 void vflist_mark_selected(ViewFileList *vfl, gint mark, gint value) | |
1453 { | |
1454 GtkTreeModel *store; | |
1455 GtkTreeSelection *selection; | |
1456 GList *slist; | |
1457 GList *work; | |
1458 | |
1459 g_assert(mark >= 0 && mark < FILEDATA_MARKS_SIZE); | |
1460 | |
1461 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1462 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1463 work = slist; | |
1464 while (work) | |
1465 { | |
1466 GtkTreePath *tpath = work->data; | |
1467 FileData *fd; | |
1468 GtkTreeIter iter; | |
1469 | |
1470 gtk_tree_model_get_iter(store, &iter, tpath); | |
1471 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1472 | |
1473 if (value == -1) | |
1474 fd->marks[mark] = !fd->marks[mark]; | |
1475 else | |
1476 fd->marks[mark] = value; | |
1477 | |
1478 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + mark, fd->marks[mark], -1); | |
1479 | |
1480 work = work->next; | |
1481 } | |
1482 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1483 g_list_free(slist); | |
1484 } | |
1485 | |
9 | 1486 /* |
1487 *----------------------------------------------------------------------------- | |
1488 * core (population) | |
1489 *----------------------------------------------------------------------------- | |
1490 */ | |
1491 | |
1492 static void vflist_listview_set_height(GtkWidget *listview, gint thumb) | |
1493 { | |
1494 GtkTreeViewColumn *column; | |
1495 GtkCellRenderer *cell; | |
1496 GList *list; | |
1497 | |
1498 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), FILE_COLUMN_THUMB - 1); | |
1499 if (!column) return; | |
1500 | |
149 | 1501 gtk_tree_view_column_set_fixed_width(column, ((thumb) ? thumb_max_width : 4) + 10); |
9 | 1502 |
1503 list = gtk_tree_view_column_get_cell_renderers(column); | |
1504 if (!list) return; | |
1505 cell = list->data; | |
1506 g_list_free(list); | |
1507 | |
1508 g_object_set(G_OBJECT(cell), "height", (thumb) ? thumb_max_height : -1, NULL); | |
1509 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview)); | |
1510 } | |
1511 | |
1512 static void vflist_populate_view(ViewFileList *vfl) | |
1513 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1514 GtkTreeStore *store; |
9 | 1515 GtkTreeIter iter; |
1516 gint thumbs; | |
1517 GList *work; | |
1518 GtkTreeRowReference *visible_row = NULL; | |
1519 GtkTreePath *tpath; | |
1520 gint valid; | |
1521 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1522 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 1523 thumbs = vfl->thumbs_enabled; |
1524 | |
1525 vflist_thumb_stop(vfl); | |
1526 | |
1527 if (!vfl->list) | |
1528 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1529 gtk_tree_store_clear(store); |
9 | 1530 vflist_send_update(vfl); |
1531 return; | |
1532 } | |
1533 | |
1534 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1535 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1536 { | |
1537 visible_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), tpath); | |
1538 gtk_tree_path_free(tpath); | |
1539 } | |
1540 | |
1541 vflist_listview_set_height(vfl->listview, thumbs); | |
1542 | |
1543 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); | |
1544 | |
1545 work = vfl->list; | |
1546 while (work) | |
1547 { | |
1548 gint match; | |
1549 FileData *fd = work->data; | |
1550 gint done = FALSE; | |
1551 | |
1552 while (!done) | |
1553 { | |
1554 FileData *old_fd = NULL; | |
132 | 1555 int i; |
1556 | |
9 | 1557 if (valid) |
1558 { | |
1559 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, -1); | |
1560 match = CASE_SORT(fd->name, old_fd->name); | |
1561 } | |
1562 else | |
1563 { | |
1564 match = -1; | |
1565 } | |
1566 | |
1567 if (match < 0) | |
1568 { | |
1569 GtkTreeIter new; | |
139 | 1570 |
9 | 1571 if (valid) |
1572 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1573 vflist_setup_iter(vfl, store, &new, fd, &iter); |
9 | 1574 } |
1575 else | |
1576 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1577 vflist_setup_iter(vfl, store, &new, fd, NULL); |
9 | 1578 } |
1579 | |
1580 done = TRUE; | |
1581 } | |
1582 else if (match > 0) | |
1583 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1584 valid = gtk_tree_store_remove(store, &iter); |
9 | 1585 } |
1586 else | |
1587 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1588 gtk_tree_store_set(store, &iter, FILE_COLUMN_POINTER, fd, -1); |
9 | 1589 if (fd->date != old_fd->date) |
1590 { | |
1591 gchar *size; | |
1592 | |
1593 /* update, file changed */ | |
1594 size = text_from_size(fd->size); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1595 gtk_tree_store_set(store, &iter, FILE_COLUMN_SIZE, size, |
9 | 1596 FILE_COLUMN_DATE, text_from_time(fd->date), -1); |
1597 g_free(size); | |
1598 } | |
1599 else if (fd != old_fd) | |
1600 { | |
1601 /* preserve thumbnail */ | |
1602 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
1603 fd->pixbuf = old_fd->pixbuf; | |
1604 if (fd->pixbuf) g_object_ref(fd->pixbuf); | |
1605 } | |
1606 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1607 gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, (thumbs) ? fd->pixbuf : NULL, -1); |
9 | 1608 |
1609 if (vfl->select_fd == old_fd) vfl->select_fd = fd; | |
1610 | |
1611 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1612 | |
1613 done = TRUE; | |
1614 } | |
1615 } | |
1616 work = work->next; | |
1617 } | |
1618 | |
1619 while (valid) | |
1620 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1621 valid = gtk_tree_store_remove(store, &iter); |
9 | 1622 } |
1623 | |
1624 if (visible_row) | |
1625 { | |
1626 if (gtk_tree_row_reference_valid(visible_row)) | |
1627 { | |
1628 tpath = gtk_tree_row_reference_get_path(visible_row); | |
1629 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vfl->listview), tpath, NULL, TRUE, 0.0, 0.0); | |
1630 gtk_tree_path_free(tpath); | |
1631 } | |
1632 gtk_tree_row_reference_free(visible_row); | |
1633 } | |
1634 | |
1635 vflist_send_update(vfl); | |
1636 vflist_thumb_update(vfl); | |
1637 } | |
1638 | |
1639 gint vflist_refresh(ViewFileList *vfl) | |
1640 { | |
1641 GList *old_list; | |
1642 gint ret = TRUE; | |
1643 | |
1644 old_list = vfl->list; | |
1645 vfl->list = NULL; | |
1646 | |
1647 if (vfl->path) | |
1648 { | |
1649 ret = filelist_read(vfl->path, &vfl->list, NULL); | |
1650 } | |
1651 | |
1652 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
1653 vflist_populate_view(vfl); | |
1654 | |
1655 filelist_free(old_list); | |
1656 | |
1657 return ret; | |
1658 } | |
1659 | |
1660 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ | |
1661 | |
1662 #define CELL_HEIGHT_OVERRIDE 512 | |
1663 | |
1664 static void cell_renderer_height_override(GtkCellRenderer *renderer) | |
1665 { | |
1666 GParamSpec *spec; | |
1667 | |
1668 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height"); | |
1669 if (spec && G_IS_PARAM_SPEC_INT(spec)) | |
1670 { | |
1671 GParamSpecInt *spec_int; | |
1672 | |
1673 spec_int = G_PARAM_SPEC_INT(spec); | |
1674 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE; | |
1675 } | |
1676 } | |
1677 | |
1678 static GdkColor *vflist_listview_color_shifted(GtkWidget *widget) | |
1679 { | |
1680 static GdkColor color; | |
1681 static GtkWidget *done = NULL; | |
1682 | |
1683 if (done != widget) | |
1684 { | |
1685 GtkStyle *style; | |
1686 | |
1687 style = gtk_widget_get_style(widget); | |
1688 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1689 shift_color(&color, -1, 0); | |
1690 done = widget; | |
1691 } | |
1692 | |
1693 return &color; | |
1694 } | |
1695 | |
1696 static void vflist_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1697 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1698 { | |
1699 ViewFileList *vfl = data; | |
1700 gboolean set; | |
1701 | |
1702 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1); | |
1703 g_object_set(G_OBJECT(cell), | |
1704 "cell-background-gdk", vflist_listview_color_shifted(vfl->listview), | |
1705 "cell-background-set", set, NULL); | |
1706 } | |
1707 | |
132 | 1708 static void vflist_listview_add_column(ViewFileList *vfl, gint n, const gchar *title, gint image, gint right_justify, gint expand) |
9 | 1709 { |
1710 GtkTreeViewColumn *column; | |
1711 GtkCellRenderer *renderer; | |
1712 | |
1713 column = gtk_tree_view_column_new(); | |
1714 gtk_tree_view_column_set_title(column, title); | |
1715 gtk_tree_view_column_set_min_width(column, 4); | |
1716 | |
1717 if (!image) | |
1718 { | |
149 | 1719 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); |
9 | 1720 renderer = gtk_cell_renderer_text_new(); |
1721 if (right_justify) | |
1722 { | |
1723 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
1724 } | |
1725 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1726 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
149 | 1727 if (expand) |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1728 gtk_tree_view_column_set_expand(column, TRUE); |
149 | 1729 } |
9 | 1730 else |
1731 { | |
1732 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
1733 renderer = gtk_cell_renderer_pixbuf_new(); | |
1734 cell_renderer_height_override(renderer); | |
1735 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1736 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
1737 } | |
1738 | |
1739 gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vfl, NULL); | |
149 | 1740 g_object_set_data (G_OBJECT (column), "column_store_idx", GUINT_TO_POINTER(n)); |
1741 g_object_set_data (G_OBJECT (renderer), "column_store_idx", GUINT_TO_POINTER(n)); | |
9 | 1742 |
1743 gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); | |
1744 } | |
1745 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1746 static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store) |
132 | 1747 { |
149 | 1748 GtkTreePath *path = gtk_tree_path_new_from_string(path_str); |
1749 guint *marks; | |
1750 GtkTreeIter iter; | |
1751 FileData *fd; | |
1752 gboolean mark; | |
1753 guint col_idx; | |
132 | 1754 |
149 | 1755 if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path)) |
1756 return; | |
132 | 1757 |
149 | 1758 col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(cell), "column_store_idx")); |
1759 | |
1760 g_assert(col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST); | |
132 | 1761 |
149 | 1762 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1); |
150 | 1763 mark = !mark; |
149 | 1764 fd->marks[col_idx - FILE_COLUMN_MARKS] = mark; |
132 | 1765 |
149 | 1766 gtk_tree_store_set(store, &iter, col_idx, mark, -1); |
1767 gtk_tree_path_free(path); | |
132 | 1768 } |
1769 | |
1770 static void vflist_listview_add_column_toggle(ViewFileList *vfl, gint n, const gchar *title) | |
1771 { | |
149 | 1772 GtkTreeViewColumn *column; |
1773 GtkCellRenderer *renderer; | |
1774 GtkTreeStore *store; | |
1775 gint index; | |
132 | 1776 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1777 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
132 | 1778 |
149 | 1779 renderer = gtk_cell_renderer_toggle_new(); |
1780 column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL); | |
132 | 1781 |
149 | 1782 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); |
1783 g_object_set_data (G_OBJECT (column), "column_store_idx", GUINT_TO_POINTER(n)); | |
1784 g_object_set_data (G_OBJECT (renderer), "column_store_idx", GUINT_TO_POINTER(n)); | |
132 | 1785 |
149 | 1786 index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); |
1787 gtk_tree_view_column_set_fixed_width(column, 16); | |
1788 gtk_tree_view_column_set_visible(column, vfl->marks_enabled); | |
132 | 1789 |
1790 | |
149 | 1791 g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store); |
132 | 1792 } |
1793 | |
9 | 1794 /* |
1795 *----------------------------------------------------------------------------- | |
1796 * base | |
1797 *----------------------------------------------------------------------------- | |
1798 */ | |
1799 | |
1800 gint vflist_set_path(ViewFileList *vfl, const gchar *path) | |
1801 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1802 GtkTreeStore *store; |
9 | 1803 |
1804 if (!path) return FALSE; | |
1805 if (vfl->path && strcmp(path, vfl->path) == 0) return TRUE; | |
1806 | |
1807 g_free(vfl->path); | |
1808 vfl->path = g_strdup(path); | |
1809 | |
1810 /* force complete reload */ | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1811 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
|
1812 gtk_tree_store_clear(store); |
9 | 1813 |
1814 filelist_free(vfl->list); | |
1815 vfl->list = NULL; | |
1816 | |
1817 return vflist_refresh(vfl); | |
1818 } | |
1819 | |
1820 static void vflist_destroy_cb(GtkWidget *widget, gpointer data) | |
1821 { | |
1822 ViewFileList *vfl = data; | |
1823 | |
1824 if (vfl->popup) | |
1825 { | |
1826 g_signal_handlers_disconnect_matched(G_OBJECT(vfl->popup), G_SIGNAL_MATCH_DATA, | |
1827 0, 0, 0, NULL, vfl); | |
1828 gtk_widget_destroy(vfl->popup); | |
1829 } | |
1830 | |
1831 vflist_select_idle_cancel(vfl); | |
1832 vflist_thumb_stop(vfl); | |
1833 | |
1834 g_free(vfl->path); | |
1835 filelist_free(vfl->list); | |
1836 g_free(vfl); | |
1837 } | |
1838 | |
1839 ViewFileList *vflist_new(const gchar *path, gint thumbs) | |
1840 { | |
1841 ViewFileList *vfl; | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1842 GtkTreeStore *store; |
9 | 1843 GtkTreeSelection *selection; |
1844 | |
149 | 1845 GType flist_types[FILE_COLUMN_COUNT]; |
1846 int i; | |
132 | 1847 |
9 | 1848 vfl = g_new0(ViewFileList, 1); |
1849 | |
1850 vfl->path = NULL; | |
1851 vfl->list = NULL; | |
1852 vfl->click_fd = NULL; | |
1853 vfl->select_fd = NULL; | |
1854 vfl->sort_method = SORT_NAME; | |
1855 vfl->sort_ascend = TRUE; | |
1856 vfl->thumbs_enabled = thumbs; | |
1857 | |
1858 vfl->thumbs_running = FALSE; | |
1859 vfl->thumbs_count = 0; | |
1860 vfl->thumbs_loader = NULL; | |
1861 vfl->thumbs_filedata = NULL; | |
1862 | |
1863 vfl->select_idle_id = -1; | |
1864 | |
1865 vfl->popup = NULL; | |
1866 | |
1867 vfl->widget = gtk_scrolled_window_new(NULL, NULL); | |
1868 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vfl->widget), GTK_SHADOW_IN); | |
1869 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vfl->widget), | |
1870 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1871 g_signal_connect(G_OBJECT(vfl->widget), "destroy", | |
1872 G_CALLBACK(vflist_destroy_cb), vfl); | |
1873 | |
139 | 1874 flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER; |
1875 flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF; | |
1876 flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING; | |
1877 flist_types[FILE_COLUMN_SIDECARS] = G_TYPE_STRING; | |
1878 flist_types[FILE_COLUMN_SIZE] = G_TYPE_STRING; | |
1879 flist_types[FILE_COLUMN_DATE] = G_TYPE_STRING; | |
1880 flist_types[FILE_COLUMN_COLOR] = G_TYPE_BOOLEAN; | |
1881 for (i = FILE_COLUMN_MARKS; i < FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE; i++) | |
1882 flist_types[i] = G_TYPE_BOOLEAN; | |
132 | 1883 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1884 store = gtk_tree_store_newv(FILE_COLUMN_COUNT, flist_types); |
132 | 1885 |
139 | 1886 vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 1887 g_object_unref(store); |
1888 | |
1889 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1890 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
1891 gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL); | |
1892 | |
149 | 1893 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE); |
9 | 1894 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfl->listview), FALSE); |
1895 | |
132 | 1896 vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE); |
9 | 1897 |
139 | 1898 for(i = 0; i < FILEDATA_MARKS_SIZE;i++) |
1899 vflist_listview_add_column_toggle(vfl, i + FILE_COLUMN_MARKS, ""); | |
1900 | |
149 | 1901 vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE); |
1902 vflist_listview_add_column(vfl, FILE_COLUMN_SIDECARS, _("SC"), FALSE, FALSE, FALSE); | |
1903 | |
1904 vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE); | |
1905 vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE); | |
1906 | |
132 | 1907 |
139 | 1908 g_signal_connect(G_OBJECT(vfl->listview), "key_press_event", |
9 | 1909 G_CALLBACK(vflist_press_key_cb), vfl); |
1910 | |
1911 gtk_container_add (GTK_CONTAINER(vfl->widget), vfl->listview); | |
1912 gtk_widget_show(vfl->listview); | |
1913 | |
1914 vflist_dnd_init(vfl); | |
132 | 1915 |
9 | 1916 g_signal_connect(G_OBJECT(vfl->listview), "button_press_event", |
1917 G_CALLBACK(vflist_press_cb), vfl); | |
1918 g_signal_connect(G_OBJECT(vfl->listview), "button_release_event", | |
1919 G_CALLBACK(vflist_release_cb), vfl); | |
132 | 1920 |
1921 | |
9 | 1922 if (path) vflist_set_path(vfl, path); |
1923 | |
1924 return vfl; | |
1925 } | |
1926 | |
1927 void vflist_set_status_func(ViewFileList *vfl, | |
1928 void (*func)(ViewFileList *vfl, gpointer data), gpointer data) | |
1929 { | |
1930 vfl->func_status = func; | |
1931 vfl->data_status = data; | |
1932 } | |
1933 | |
1934 void vflist_set_thumb_status_func(ViewFileList *vfl, | |
1935 void (*func)(ViewFileList *vfl, gdouble val, const gchar *text, gpointer data), | |
1936 gpointer data) | |
1937 { | |
1938 vfl->func_thumb_status = func; | |
1939 vfl->data_thumb_status = data; | |
1940 } | |
1941 | |
1942 void vflist_thumb_set(ViewFileList *vfl, gint enable) | |
1943 { | |
1944 if (vfl->thumbs_enabled == enable) return; | |
1945 | |
1946 vfl->thumbs_enabled = enable; | |
1947 vflist_refresh(vfl); | |
1948 } | |
1949 | |
132 | 1950 void vflist_marks_set(ViewFileList *vfl, gint enable) |
1951 { | |
149 | 1952 GtkTreeStore *store; |
1953 GtkTreeViewColumn *column; | |
1954 GList *columns, *work; | |
132 | 1955 |
1956 if (vfl->marks_enabled == enable) return; | |
1957 | |
1958 vfl->marks_enabled = enable; | |
1959 | |
149 | 1960 columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vfl->listview)); |
1961 | |
1962 work = columns; | |
1963 while (work) | |
1964 { | |
1965 GtkTreeViewColumn *column = work->data; | |
1966 gint col_idx = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(column), "column_store_idx")); | |
1967 work = work->next; | |
1968 | |
1969 if (col_idx <= FILE_COLUMN_MARKS_LAST && col_idx >= FILE_COLUMN_MARKS) | |
1970 gtk_tree_view_column_set_visible(column, enable); | |
1971 } | |
132 | 1972 |
149 | 1973 g_list_free(columns); |
1974 //vflist_refresh(vfl); | |
132 | 1975 } |
1976 | |
9 | 1977 void vflist_set_layout(ViewFileList *vfl, LayoutWindow *layout) |
1978 { | |
1979 vfl->layout = layout; | |
1980 } | |
1981 | |
1982 /* | |
1983 *----------------------------------------------------------------------------- | |
1984 * maintenance (for rename, move, remove) | |
1985 *----------------------------------------------------------------------------- | |
1986 */ | |
1987 | |
1988 static gint vflist_maint_find_closest(ViewFileList *vfl, gint row, gint count, GList *ignore_list) | |
1989 { | |
1990 GList *list = NULL; | |
1991 GList *work; | |
1992 gint rev = row - 1; | |
1993 row ++; | |
1994 | |
1995 work = ignore_list; | |
1996 while (work) | |
1997 { | |
1998 gint f = vflist_index_by_path(vfl, work->data); | |
1999 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); | |
2000 work = work->next; | |
2001 } | |
2002 | |
2003 while (list) | |
2004 { | |
2005 gint c = TRUE; | |
2006 work = list; | |
2007 while (work && c) | |
2008 { | |
2009 gpointer p = work->data; | |
2010 work = work->next; | |
2011 if (row == GPOINTER_TO_INT(p)) | |
2012 { | |
2013 row++; | |
2014 c = FALSE; | |
2015 } | |
2016 if (rev == GPOINTER_TO_INT(p)) | |
2017 { | |
2018 rev--; | |
2019 c = FALSE; | |
2020 } | |
2021 if (!c) list = g_list_remove(list, p); | |
2022 } | |
2023 if (c && list) | |
2024 { | |
2025 g_list_free(list); | |
2026 list = NULL; | |
2027 } | |
2028 } | |
2029 if (row > count - 1) | |
2030 { | |
2031 if (rev < 0) | |
2032 return -1; | |
2033 else | |
2034 return rev; | |
2035 } | |
2036 else | |
2037 { | |
2038 return row; | |
2039 } | |
2040 } | |
2041 | |
138 | 2042 gint vflist_maint_renamed(ViewFileList *vfl, FileData *fd) |
9 | 2043 { |
2044 gint ret = FALSE; | |
2045 gint row; | |
2046 gchar *source_base; | |
2047 gchar *dest_base; | |
2048 GList *work; | |
2049 | |
138 | 2050 row = g_list_index(vfl->list, fd); |
9 | 2051 if (row < 0) return FALSE; |
2052 | |
138 | 2053 source_base = remove_level_from_path(fd->change->source); |
2054 dest_base = remove_level_from_path(fd->change->dest); | |
9 | 2055 |
2056 | |
2057 if (strcmp(source_base, dest_base) == 0) | |
2058 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2059 GtkTreeStore *store; |
9 | 2060 GtkTreeIter iter; |
2061 GtkTreeIter position; | |
2062 gint old_row; | |
2063 gint n; | |
2064 | |
2065 old_row = g_list_index(vfl->list, fd); | |
2066 | |
2067 vfl->list = g_list_remove(vfl->list, fd); | |
2068 | |
2069 vfl->list = filelist_insert_sort(vfl->list, fd, vfl->sort_method, vfl->sort_ascend); | |
2070 n = g_list_index(vfl->list, fd); | |
2071 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2072 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 2073 row = vflist_find_row(vfl, fd, &iter); |
2074 if (vflist_find_row(vfl, fd, &iter) >= 0 && | |
2075 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &position, NULL, n)) | |
2076 { | |
2077 if (old_row >= n) | |
2078 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2079 gtk_tree_store_move_before(store, &iter, &position); |
9 | 2080 } |
2081 else | |
2082 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2083 gtk_tree_store_move_after(store, &iter, &position); |
9 | 2084 } |
2085 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2086 gtk_tree_store_set(store, &iter, FILE_COLUMN_NAME, fd->name, -1); |
9 | 2087 |
2088 ret = TRUE; | |
2089 } | |
2090 else | |
2091 { | |
138 | 2092 ret = vflist_maint_removed(vfl, fd, NULL); |
9 | 2093 } |
2094 | |
2095 g_free(source_base); | |
2096 g_free(dest_base); | |
2097 | |
2098 return ret; | |
2099 } | |
2100 | |
138 | 2101 gint vflist_maint_removed(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 2102 { |
2103 GtkTreeIter iter; | |
2104 GList *list; | |
2105 gint row; | |
2106 gint new_row = -1; | |
2107 | |
138 | 2108 row = g_list_index(vfl->list, fd); |
9 | 2109 if (row < 0) return FALSE; |
2110 | |
2111 if (vflist_index_is_selected(vfl, row) && | |
2112 layout_image_get_collection(vfl->layout, NULL) == NULL) | |
2113 { | |
2114 gint n; | |
2115 | |
2116 n = vflist_count(vfl, NULL); | |
2117 if (ignore_list) | |
2118 { | |
2119 new_row = vflist_maint_find_closest(vfl, row, n, ignore_list); | |
2120 if (debug) printf("row = %d, closest is %d\n", row, new_row); | |
2121 } | |
2122 else | |
2123 { | |
2124 if (row + 1 < n) | |
2125 { | |
2126 new_row = row + 1; | |
2127 } | |
2128 else if (row > 0) | |
2129 { | |
2130 new_row = row - 1; | |
2131 } | |
2132 } | |
2133 vflist_select_none(vfl); | |
2134 if (new_row >= 0) | |
2135 { | |
2136 fd = vflist_index_get_data(vfl, new_row); | |
2137 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2138 { | |
2139 GtkTreeSelection *selection; | |
2140 | |
2141 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
2142 gtk_tree_selection_select_iter(selection, &iter); | |
2143 vflist_move_cursor(vfl, &iter); | |
2144 } | |
2145 } | |
2146 } | |
2147 | |
2148 fd = vflist_index_get_data(vfl, row); | |
2149 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2150 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2151 GtkTreeStore *store; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2152 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
|
2153 gtk_tree_store_remove(store, &iter); |
9 | 2154 } |
2155 list = g_list_nth(vfl->list, row); | |
2156 fd = list->data; | |
2157 | |
2158 /* thumbnail loader check */ | |
2159 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
|
2160 if (vfl->thumbs_count > 0) vfl->thumbs_count--; |
9 | 2161 |
2162 vfl->list = g_list_remove(vfl->list, fd); | |
138 | 2163 file_data_unref(fd); |
9 | 2164 |
2165 vflist_send_update(vfl); | |
2166 | |
2167 return TRUE; | |
2168 } | |
2169 | |
138 | 2170 gint vflist_maint_moved(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 2171 { |
2172 gint ret = FALSE; | |
2173 gchar *buf; | |
2174 | |
138 | 2175 if (!fd->change->source || !vfl->path) return FALSE; |
9 | 2176 |
138 | 2177 buf = remove_level_from_path(fd->change->source); |
9 | 2178 |
2179 if (strcmp(buf, vfl->path) == 0) | |
2180 { | |
138 | 2181 ret = vflist_maint_removed(vfl, fd, ignore_list); |
9 | 2182 } |
2183 | |
2184 g_free(buf); | |
2185 | |
2186 return ret; | |
2187 } | |
2188 |