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