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