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