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