Mercurial > geeqie.yaz
annotate src/view_file_list.c @ 517:d84f2210a73c
6 for() vs 201 for (): winner is for ().
author | zas_ |
---|---|
date | Thu, 24 Apr 2008 15:53:08 +0000 |
parents | 985fdfebd89e |
children | e56c74e89da9 |
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 { | |
771 gtk_widget_grab_focus(widget); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
772 // return TRUE; // FIXME - expand |
9 | 773 } |
774 | |
775 #if 0 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
776 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS) |
9 | 777 { |
778 if (vfl->layout) layout_image_full_screen_start(vfl->layout); | |
779 } | |
780 #endif | |
781 | |
782 return FALSE; | |
783 } | |
784 | |
785 static gint vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
786 { | |
787 ViewFileList *vfl = data; | |
788 GtkTreePath *tpath; | |
789 GtkTreeIter iter; | |
790 FileData *fd = NULL; | |
791 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
792 if (bevent->button == MOUSE_BUTTON_MIDDLE) |
9 | 793 { |
794 vflist_color_set(vfl, vfl->click_fd, FALSE); | |
795 } | |
796 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
797 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) |
9 | 798 { |
799 return TRUE; | |
800 } | |
801 | |
802 if ((bevent->x != 0 || bevent->y != 0) && | |
803 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
804 &tpath, NULL, NULL, NULL)) | |
805 { | |
806 GtkTreeModel *store; | |
807 | |
808 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
809 gtk_tree_model_get_iter(store, &iter, tpath); | |
810 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
811 gtk_tree_path_free(tpath); | |
812 } | |
813 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
814 if (bevent->button == MOUSE_BUTTON_MIDDLE) |
9 | 815 { |
816 if (fd && vfl->click_fd == fd) | |
817 { | |
818 GtkTreeSelection *selection; | |
819 | |
820 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
821 if (vflist_row_is_selected(vfl, fd)) | |
822 { | |
823 gtk_tree_selection_unselect_iter(selection, &iter); | |
824 } | |
825 else | |
826 { | |
827 gtk_tree_selection_select_iter(selection, &iter); | |
828 } | |
829 } | |
830 return TRUE; | |
831 } | |
832 | |
833 if (fd && vfl->click_fd == fd && | |
834 !(bevent->state & GDK_SHIFT_MASK ) && | |
835 !(bevent->state & GDK_CONTROL_MASK ) && | |
836 vflist_row_is_selected(vfl, fd)) | |
837 { | |
838 GtkTreeSelection *selection; | |
839 | |
840 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
841 gtk_tree_selection_unselect_all(selection); | |
842 gtk_tree_selection_select_iter(selection, &iter); | |
843 vflist_move_cursor(vfl, &iter); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
844 // return TRUE;// FIXME - expand |
9 | 845 } |
846 | |
847 return FALSE; | |
848 } | |
849 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
850 static void vflist_select_image(ViewFileList *vfl, FileData *sel_fd) |
9 | 851 { |
138 | 852 FileData *read_ahead_fd = NULL; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
853 gint row; |
144 | 854 FileData *cur_fd; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
855 if (!sel_fd) return; |
442 | 856 |
144 | 857 cur_fd = layout_image_get_fd(vfl->layout); |
858 if (sel_fd == cur_fd) return; /* no change */ | |
442 | 859 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
860 row = g_list_index(vfl->list, sel_fd); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
861 // FIXME sidecar data |
9 | 862 |
334 | 863 if (sel_fd && options->image.enable_read_ahead && row >= 0) |
9 | 864 { |
144 | 865 if (row > g_list_index(vfl->list, cur_fd) && |
9 | 866 row + 1 < vflist_count(vfl, NULL)) |
867 { | |
144 | 868 read_ahead_fd = vflist_index_get_data(vfl, row + 1); |
9 | 869 } |
870 else if (row > 0) | |
871 { | |
144 | 872 read_ahead_fd = vflist_index_get_data(vfl, row - 1); |
9 | 873 } |
874 } | |
875 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
876 layout_image_set_with_ahead(vfl->layout, sel_fd, read_ahead_fd); |
9 | 877 } |
878 | |
879 static gint vflist_select_idle_cb(gpointer data) | |
880 { | |
881 ViewFileList *vfl = data; | |
882 | |
883 if (!vfl->layout) | |
884 { | |
885 vfl->select_idle_id = -1; | |
886 return FALSE; | |
887 } | |
888 | |
889 vflist_send_update(vfl); | |
890 | |
891 if (vfl->select_fd) | |
892 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
893 vflist_select_image(vfl, vfl->select_fd); |
9 | 894 vfl->select_fd = NULL; |
895 } | |
896 | |
897 vfl->select_idle_id = -1; | |
898 return FALSE; | |
899 } | |
900 | |
901 static void vflist_select_idle_cancel(ViewFileList *vfl) | |
902 { | |
903 if (vfl->select_idle_id != -1) g_source_remove(vfl->select_idle_id); | |
904 vfl->select_idle_id = -1; | |
905 } | |
906 | |
907 static gboolean vflist_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
908 gboolean path_currently_selected, gpointer data) | |
909 { | |
910 ViewFileList *vfl = data; | |
911 GtkTreeIter iter; | |
912 | |
913 if (!path_currently_selected && | |
914 gtk_tree_model_get_iter(store, &iter, tpath)) | |
915 { | |
916 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &vfl->select_fd, -1); | |
917 } | |
918 else | |
919 { | |
920 vfl->select_fd = NULL; | |
921 } | |
922 | |
923 if (vfl->layout && | |
924 vfl->select_idle_id == -1) | |
925 { | |
926 vfl->select_idle_id = g_idle_add(vflist_select_idle_cb, vfl); | |
927 } | |
928 | |
929 return TRUE; | |
930 } | |
931 | |
932 /* | |
933 *----------------------------------------------------------------------------- | |
934 * misc | |
935 *----------------------------------------------------------------------------- | |
936 */ | |
937 | |
259 | 938 /* |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
939 static gboolean vflist_dummy_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, |
442 | 940 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
|
941 { |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
942 return TRUE; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
943 } |
259 | 944 */ |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
945 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
946 |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
947 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
|
948 { |
167 | 949 int i; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
950 gchar *size; |
167 | 951 gchar *sidecars = NULL; |
952 | |
953 if (fd->sidecar_files) | |
954 sidecars = sidecar_file_data_list_to_string(fd); | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
955 size = text_from_size(fd->size); |
442 | 956 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
957 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
|
958 FILE_COLUMN_THUMB, (vfl->thumbs_enabled) ? fd->pixbuf : NULL, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
959 FILE_COLUMN_NAME, fd->name, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
960 FILE_COLUMN_SIDECARS, sidecars, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
961 FILE_COLUMN_SIZE, size, |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
962 FILE_COLUMN_DATE, text_from_time(fd->date), |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
963 FILE_COLUMN_COLOR, FALSE, -1); |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
964 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
965 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
|
966 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
967 g_free(size); |
167 | 968 if (sidecars) |
969 g_free(sidecars); | |
970 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
971 |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
972 static void vflist_setup_iter_with_sidecars(ViewFileList *vfl, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd) |
167 | 973 { |
974 GList *work; | |
975 GtkTreeIter s_iter; | |
976 gint valid; | |
977 | |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
978 vflist_setup_iter(vfl, store, iter, fd); |
167 | 979 |
980 | |
442 | 981 /* this is almost the same code as in vflist_populate_view |
167 | 982 maybe it should be made more generic and used in both places */ |
442 | 983 |
984 | |
167 | 985 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
|
986 |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
987 work = fd->sidecar_files; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
988 while (work) |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
989 { |
167 | 990 gint match; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
991 FileData *sfd = work->data; |
167 | 992 gint done = FALSE; |
993 | |
994 while (!done) | |
995 { | |
996 FileData *old_sfd = NULL; | |
442 | 997 |
167 | 998 if (valid) |
999 { | |
1000 gtk_tree_model_get(GTK_TREE_MODEL(store), &s_iter, FILE_COLUMN_POINTER, &old_sfd, -1); | |
442 | 1001 |
167 | 1002 if (sfd == old_sfd) |
1003 { | |
1004 match = 0; | |
1005 } | |
1006 else | |
1007 { | |
1008 match = filelist_sort_compare_filedata_full(sfd, old_sfd, SORT_NAME, TRUE); | |
1009 } | |
1010 } | |
442 | 1011 |
167 | 1012 else |
1013 { | |
1014 match = -1; | |
1015 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1016 |
167 | 1017 if (match < 0) |
1018 { | |
1019 GtkTreeIter new; | |
442 | 1020 |
167 | 1021 if (valid) |
1022 { | |
1023 gtk_tree_store_insert_before(store, &new, iter, &s_iter); | |
1024 } | |
1025 else | |
1026 { | |
1027 gtk_tree_store_append(store, &new, iter); | |
1028 } | |
442 | 1029 |
167 | 1030 vflist_setup_iter(vfl, store, &new, sfd); |
1031 | |
1032 done = TRUE; | |
1033 } | |
1034 else if (match > 0) | |
1035 { | |
1036 valid = gtk_tree_store_remove(store, &s_iter); | |
1037 } | |
1038 else | |
1039 { | |
1040 vflist_setup_iter(vfl, store, &s_iter, sfd); | |
1041 | |
1042 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &s_iter); | |
1043 | |
1044 done = TRUE; | |
1045 } | |
1046 } | |
1047 work = work->next; | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1048 } |
167 | 1049 |
1050 while (valid) | |
1051 { | |
1052 valid = gtk_tree_store_remove(store, &s_iter); | |
1053 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1054 } |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1055 |
9 | 1056 void vflist_sort_set(ViewFileList *vfl, SortType type, gint ascend) |
1057 { | |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1058 gint i; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1059 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
|
1060 gint *new_order; |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1061 GtkTreeStore *store; |
9 | 1062 GList *work; |
1063 | |
1064 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
|
1065 if (!vfl->list) return; |
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 work = vfl->list; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1068 i = 0; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1069 while (work) |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1070 { |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1071 FileData *fd = work->data; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1072 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
|
1073 i++; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1074 work = work->next; |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1075 } |
9 | 1076 |
1077 vfl->sort_method = type; | |
1078 vfl->sort_ascend = ascend; | |
1079 | |
1080 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
442 | 1081 |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1082 new_order = g_malloc(i * sizeof(gint)); |
442 | 1083 |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1084 work = vfl->list; |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1085 i = 0; |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1086 while (work) |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1087 { |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1088 FileData *fd = work->data; |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1089 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
|
1090 i++; |
93
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1091 work = work->next; |
f1c8f8632e23
Thu Nov 2 14:38:54 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1092 } |
442 | 1093 |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1094 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
|
1095 gtk_tree_store_reorder(store, NULL, new_order); |
442 | 1096 |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1097 g_free(new_order); |
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
1098 g_hash_table_destroy(fd_idx_hash); |
9 | 1099 } |
1100 | |
1101 /* | |
1102 *----------------------------------------------------------------------------- | |
1103 * thumb updates | |
1104 *----------------------------------------------------------------------------- | |
1105 */ | |
1106 | |
1107 static gint vflist_thumb_next(ViewFileList *vfl); | |
1108 | |
1109 static void vflist_thumb_status(ViewFileList *vfl, gdouble val, const gchar *text) | |
1110 { | |
1111 if (vfl->func_thumb_status) | |
1112 { | |
1113 vfl->func_thumb_status(vfl, val, text, vfl->data_thumb_status); | |
1114 } | |
1115 } | |
1116 | |
1117 static void vflist_thumb_cleanup(ViewFileList *vfl) | |
1118 { | |
1119 vflist_thumb_status(vfl, 0.0, NULL); | |
1120 | |
1121 vfl->thumbs_count = 0; | |
1122 vfl->thumbs_running = FALSE; | |
1123 | |
1124 thumb_loader_free(vfl->thumbs_loader); | |
1125 vfl->thumbs_loader = NULL; | |
1126 | |
1127 vfl->thumbs_filedata = NULL; | |
1128 } | |
1129 | |
1130 static void vflist_thumb_stop(ViewFileList *vfl) | |
1131 { | |
442 | 1132 if (vfl->thumbs_running) vflist_thumb_cleanup(vfl); |
9 | 1133 } |
1134 | |
1135 static void vflist_thumb_do(ViewFileList *vfl, ThumbLoader *tl, FileData *fd) | |
1136 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1137 GtkTreeStore *store; |
9 | 1138 GtkTreeIter iter; |
1139 | |
1140 if (!fd || vflist_find_row(vfl, fd, &iter) < 0) return; | |
1141 | |
1142 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
1143 fd->pixbuf = thumb_loader_get_pixbuf(tl, TRUE); | |
1144 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1145 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
|
1146 gtk_tree_store_set(store, &iter, FILE_COLUMN_THUMB, fd->pixbuf, -1); |
9 | 1147 |
169 | 1148 vflist_thumb_status(vfl, (gdouble)(vfl->thumbs_count) / vflist_sidecar_list_count(vfl->list), _("Loading thumbs...")); |
9 | 1149 } |
1150 | |
1151 static void vflist_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1152 { | |
1153 ViewFileList *vfl = data; | |
1154 | |
1155 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
1156 { | |
1157 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
1158 } | |
1159 | |
1160 while (vflist_thumb_next(vfl)); | |
1161 } | |
1162 | |
1163 static void vflist_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1164 { | |
1165 ViewFileList *vfl = data; | |
1166 | |
1167 if (vfl->thumbs_filedata && vfl->thumbs_loader == tl) | |
1168 { | |
1169 vflist_thumb_do(vfl, tl, vfl->thumbs_filedata); | |
1170 } | |
1171 | |
1172 while (vflist_thumb_next(vfl)); | |
1173 } | |
1174 | |
1175 static gint vflist_thumb_next(ViewFileList *vfl) | |
1176 { | |
1177 GtkTreePath *tpath; | |
1178 FileData *fd = NULL; | |
1179 | |
1180 /* first check the visible files */ | |
1181 | |
1182 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1183 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1184 { | |
1185 GtkTreeModel *store; | |
1186 GtkTreeIter iter; | |
1187 gint valid = TRUE; | |
1188 | |
1189 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1190 gtk_tree_model_get_iter(store, &iter, tpath); | |
1191 gtk_tree_path_free(tpath); | |
1192 | |
1193 while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vfl->listview), &iter, FALSE) == 0) | |
1194 { | |
1195 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1196 if (fd->pixbuf) fd = NULL; | |
1197 | |
1198 valid = gtk_tree_model_iter_next(store, &iter); | |
1199 } | |
1200 } | |
1201 | |
1202 /* then find first undone */ | |
1203 | |
1204 if (!fd) | |
1205 { | |
1206 GList *work = vfl->list; | |
1207 while (work && !fd) | |
1208 { | |
1209 FileData *fd_p = work->data; | |
442 | 1210 if (!fd_p->pixbuf) |
169 | 1211 fd = fd_p; |
1212 else | |
1213 { | |
1214 GList *work2 = fd_p->sidecar_files; | |
442 | 1215 |
169 | 1216 while (work2 && !fd) |
1217 { | |
442 | 1218 fd_p = work2->data; |
169 | 1219 if (!fd_p->pixbuf) fd = fd_p; |
1220 work2 = work2->next; | |
1221 } | |
1222 } | |
9 | 1223 work = work->next; |
1224 } | |
1225 } | |
1226 | |
1227 if (!fd) | |
1228 { | |
1229 /* done */ | |
1230 vflist_thumb_cleanup(vfl); | |
1231 return FALSE; | |
1232 } | |
1233 | |
1234 vfl->thumbs_count++; | |
1235 | |
1236 vfl->thumbs_filedata = fd; | |
1237 | |
1238 thumb_loader_free(vfl->thumbs_loader); | |
1239 | |
333 | 1240 vfl->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 1241 thumb_loader_set_callbacks(vfl->thumbs_loader, |
1242 vflist_thumb_done_cb, | |
1243 vflist_thumb_error_cb, | |
1244 NULL, | |
1245 vfl); | |
1246 | |
1247 if (!thumb_loader_start(vfl->thumbs_loader, fd->path)) | |
1248 { | |
1249 /* set icon to unknown, continue */ | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1250 DEBUG_1("thumb loader start failed %s", vfl->thumbs_loader->path); |
9 | 1251 vflist_thumb_do(vfl, vfl->thumbs_loader, fd); |
1252 | |
1253 return TRUE; | |
1254 } | |
1255 | |
1256 return FALSE; | |
1257 } | |
1258 | |
1259 static void vflist_thumb_update(ViewFileList *vfl) | |
1260 { | |
1261 vflist_thumb_stop(vfl); | |
1262 if (!vfl->thumbs_enabled) return; | |
1263 | |
1264 vflist_thumb_status(vfl, 0.0, _("Loading thumbs...")); | |
1265 vfl->thumbs_running = TRUE; | |
1266 | |
1267 while (vflist_thumb_next(vfl)); | |
1268 } | |
1269 | |
1270 /* | |
1271 *----------------------------------------------------------------------------- | |
1272 * row stuff | |
1273 *----------------------------------------------------------------------------- | |
1274 */ | |
1275 | |
1276 FileData *vflist_index_get_data(ViewFileList *vfl, gint row) | |
1277 { | |
1278 return g_list_nth_data(vfl->list, row); | |
1279 } | |
1280 | |
1281 gchar *vflist_index_get_path(ViewFileList *vfl, gint row) | |
1282 { | |
1283 FileData *fd; | |
1284 | |
1285 fd = g_list_nth_data(vfl->list, row); | |
1286 | |
1287 return (fd ? fd->path : NULL); | |
1288 } | |
1289 | |
1290 static gint vflist_row_by_path(ViewFileList *vfl, const gchar *path, FileData **fd) | |
1291 { | |
1292 gint p = 0; | |
1293 GList *work; | |
1294 | |
1295 if (!path) return -1; | |
1296 | |
1297 work = vfl->list; | |
1298 while (work) | |
1299 { | |
1300 FileData *fd_n = work->data; | |
1301 if (strcmp(path, fd_n->path) == 0) | |
1302 { | |
1303 if (fd) *fd = fd_n; | |
1304 return p; | |
1305 } | |
1306 work = work->next; | |
1307 p++; | |
1308 } | |
1309 | |
1310 if (fd) *fd = NULL; | |
1311 return -1; | |
1312 } | |
1313 | |
1314 gint vflist_index_by_path(ViewFileList *vfl, const gchar *path) | |
1315 { | |
1316 return vflist_row_by_path(vfl, path, NULL); | |
1317 } | |
1318 | |
1319 gint vflist_count(ViewFileList *vfl, gint64 *bytes) | |
1320 { | |
1321 if (bytes) | |
1322 { | |
1323 gint64 b = 0; | |
1324 GList *work; | |
1325 | |
1326 work = vfl->list; | |
1327 while (work) | |
1328 { | |
1329 FileData *fd = work->data; | |
1330 work = work->next; | |
1331 b += fd->size; | |
1332 } | |
1333 | |
1334 *bytes = b; | |
1335 } | |
1336 | |
1337 return g_list_length(vfl->list); | |
1338 } | |
1339 | |
1340 GList *vflist_get_list(ViewFileList *vfl) | |
1341 { | |
1342 GList *list = NULL; | |
1343 GList *work; | |
1344 | |
1345 work = vfl->list; | |
1346 while (work) | |
1347 { | |
1348 FileData *fd = work->data; | |
1349 work = work->next; | |
1350 | |
138 | 1351 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1352 } |
1353 | |
1354 return g_list_reverse(list); | |
1355 } | |
1356 | |
1357 /* | |
1358 *----------------------------------------------------------------------------- | |
1359 * selections | |
1360 *----------------------------------------------------------------------------- | |
1361 */ | |
1362 | |
1363 static gint vflist_row_is_selected(ViewFileList *vfl, FileData *fd) | |
1364 { | |
1365 GtkTreeModel *store; | |
1366 GtkTreeSelection *selection; | |
1367 GList *slist; | |
1368 GList *work; | |
1369 gint found = FALSE; | |
1370 | |
1371 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1372 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1373 work = slist; | |
1374 while (!found && work) | |
1375 { | |
1376 GtkTreePath *tpath = work->data; | |
1377 FileData *fd_n; | |
1378 GtkTreeIter iter; | |
1379 | |
1380 gtk_tree_model_get_iter(store, &iter, tpath); | |
1381 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1); | |
1382 if (fd_n == fd) found = TRUE; | |
1383 work = work->next; | |
1384 } | |
1385 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1386 g_list_free(slist); | |
1387 | |
1388 return found; | |
1389 } | |
1390 | |
1391 gint vflist_index_is_selected(ViewFileList *vfl, gint row) | |
1392 { | |
1393 FileData *fd; | |
1394 | |
1395 fd = vflist_index_get_data(vfl, row); | |
1396 return vflist_row_is_selected(vfl, fd); | |
1397 } | |
1398 | |
1399 gint vflist_selection_count(ViewFileList *vfl, gint64 *bytes) | |
1400 { | |
1401 GtkTreeModel *store; | |
1402 GtkTreeSelection *selection; | |
1403 GList *slist; | |
1404 gint count; | |
1405 | |
1406 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1407 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1408 | |
1409 if (bytes) | |
1410 { | |
1411 gint64 b = 0; | |
1412 GList *work; | |
1413 | |
1414 work = slist; | |
1415 while (work) | |
1416 { | |
1417 GtkTreePath *tpath = work->data; | |
1418 GtkTreeIter iter; | |
1419 FileData *fd; | |
1420 | |
1421 gtk_tree_model_get_iter(store, &iter, tpath); | |
1422 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1423 b += fd->size; | |
1424 | |
1425 work = work->next; | |
1426 } | |
1427 | |
1428 *bytes = b; | |
1429 } | |
1430 | |
1431 count = g_list_length(slist); | |
1432 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1433 g_list_free(slist); | |
1434 | |
1435 return count; | |
1436 } | |
1437 | |
1438 GList *vflist_selection_get_list(ViewFileList *vfl) | |
1439 { | |
1440 GtkTreeModel *store; | |
1441 GtkTreeSelection *selection; | |
1442 GList *slist; | |
1443 GList *list = NULL; | |
1444 GList *work; | |
1445 | |
1446 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1447 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1448 work = slist; | |
1449 while (work) | |
1450 { | |
1451 GtkTreePath *tpath = work->data; | |
1452 FileData *fd; | |
1453 GtkTreeIter iter; | |
1454 | |
1455 gtk_tree_model_get_iter(store, &iter, tpath); | |
1456 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1457 | |
138 | 1458 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 1459 |
1460 work = work->next; | |
1461 } | |
1462 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1463 g_list_free(slist); | |
1464 | |
1465 return g_list_reverse(list); | |
1466 } | |
1467 | |
1468 GList *vflist_selection_get_list_by_index(ViewFileList *vfl) | |
1469 { | |
1470 GtkTreeModel *store; | |
1471 GtkTreeSelection *selection; | |
1472 GList *slist; | |
1473 GList *list = NULL; | |
1474 GList *work; | |
1475 | |
1476 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1477 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1478 work = slist; | |
1479 while (work) | |
1480 { | |
1481 GtkTreePath *tpath = work->data; | |
1482 FileData *fd; | |
1483 GtkTreeIter iter; | |
1484 | |
1485 gtk_tree_model_get_iter(store, &iter, tpath); | |
1486 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
1487 | |
1488 list = g_list_prepend(list, GINT_TO_POINTER(g_list_index(vfl->list, fd))); | |
1489 | |
1490 work = work->next; | |
1491 } | |
1492 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1493 g_list_free(slist); | |
1494 | |
1495 return g_list_reverse(list); | |
1496 } | |
1497 | |
1498 void vflist_select_all(ViewFileList *vfl) | |
1499 { | |
1500 GtkTreeSelection *selection; | |
1501 | |
1502 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1503 gtk_tree_selection_select_all(selection); | |
1504 | |
1505 vfl->select_fd = NULL; | |
1506 } | |
1507 | |
1508 void vflist_select_none(ViewFileList *vfl) | |
1509 { | |
1510 GtkTreeSelection *selection; | |
1511 | |
1512 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1513 gtk_tree_selection_unselect_all(selection); | |
1514 } | |
1515 | |
1516 void vflist_select_by_path(ViewFileList *vfl, const gchar *path) | |
1517 { | |
1518 FileData *fd; | |
138 | 1519 |
1520 if (vflist_row_by_path(vfl, path, &fd) < 0) return; | |
1521 | |
1522 vflist_select_by_fd(vfl, fd); | |
1523 } | |
1524 | |
1525 void vflist_select_by_fd(ViewFileList *vfl, FileData *fd) | |
1526 { | |
9 | 1527 GtkTreeIter iter; |
1528 | |
1529 if (vflist_find_row(vfl, fd, &iter) < 0) return; | |
1530 | |
1531 tree_view_row_make_visible(GTK_TREE_VIEW(vfl->listview), &iter, TRUE); | |
1532 | |
1533 if (!vflist_row_is_selected(vfl, fd)) | |
1534 { | |
1535 GtkTreeSelection *selection; | |
1536 GtkTreeModel *store; | |
1537 GtkTreePath *tpath; | |
1538 | |
1539 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1540 gtk_tree_selection_unselect_all(selection); | |
1541 gtk_tree_selection_select_iter(selection, &iter); | |
1542 vflist_move_cursor(vfl, &iter); | |
1543 | |
1544 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1545 tpath = gtk_tree_model_get_path(store, &iter); | |
1546 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vfl->listview), tpath, NULL, FALSE); | |
1547 gtk_tree_path_free(tpath); | |
1548 } | |
1549 } | |
1550 | |
161 | 1551 void vflist_mark_to_selection(ViewFileList *vfl, gint mark, MarkToSelectionMode mode) |
150 | 1552 { |
1553 GtkTreeModel *store; | |
1554 GtkTreeIter iter; | |
1555 GtkTreeSelection *selection; | |
1556 gint valid; | |
442 | 1557 |
150 | 1558 g_assert(mark >= 0 && mark < FILEDATA_MARKS_SIZE); |
1559 | |
1560 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)); | |
1561 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
442 | 1562 |
150 | 1563 valid = gtk_tree_model_get_iter_first(store, &iter); |
1564 while (valid) | |
1565 { | |
1566 FileData *fd; | |
161 | 1567 gboolean mark_val, selected; |
150 | 1568 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, -1); |
442 | 1569 |
161 | 1570 mark_val = fd->marks[mark]; |
1571 selected = gtk_tree_selection_iter_is_selected(selection, &iter); | |
442 | 1572 |
1573 switch (mode) | |
161 | 1574 { |
1575 case MTS_MODE_SET: selected = mark_val; | |
1576 break; | |
1577 case MTS_MODE_OR: selected = mark_val | selected; | |
1578 break; | |
1579 case MTS_MODE_AND: selected = mark_val & selected; | |
1580 break; | |
1581 case MTS_MODE_MINUS: selected = !mark_val & selected; | |
1582 break; | |
1583 } | |
442 | 1584 |
161 | 1585 if (selected) |
150 | 1586 gtk_tree_selection_select_iter(selection, &iter); |
161 | 1587 else |
1588 gtk_tree_selection_unselect_iter(selection, &iter); | |
150 | 1589 |
1590 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1591 } | |
1592 } | |
1593 | |
161 | 1594 void vflist_selection_to_mark(ViewFileList *vfl, gint mark, SelectionToMarkMode mode) |
150 | 1595 { |
1596 GtkTreeModel *store; | |
1597 GtkTreeSelection *selection; | |
1598 GList *slist; | |
1599 GList *work; | |
1600 | |
1601 g_assert(mark >= 0 && mark < FILEDATA_MARKS_SIZE); | |
1602 | |
1603 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
1604 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1605 work = slist; | |
1606 while (work) | |
1607 { | |
1608 GtkTreePath *tpath = work->data; | |
1609 FileData *fd; | |
1610 GtkTreeIter iter; | |
1611 | |
1612 gtk_tree_model_get_iter(store, &iter, tpath); | |
1613 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); | |
442 | 1614 |
161 | 1615 switch (mode) |
1616 { | |
1617 case STM_MODE_SET: fd->marks[mark] = 1; | |
1618 break; | |
1619 case STM_MODE_RESET: fd->marks[mark] = 0; | |
1620 break; | |
1621 case STM_MODE_TOGGLE: fd->marks[mark] = !fd->marks[mark]; | |
1622 break; | |
1623 } | |
442 | 1624 |
1625 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + mark, fd->marks[mark], -1); | |
150 | 1626 |
1627 work = work->next; | |
1628 } | |
1629 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1630 g_list_free(slist); | |
1631 } | |
1632 | |
9 | 1633 /* |
1634 *----------------------------------------------------------------------------- | |
1635 * core (population) | |
1636 *----------------------------------------------------------------------------- | |
1637 */ | |
1638 | |
1639 static void vflist_listview_set_height(GtkWidget *listview, gint thumb) | |
1640 { | |
1641 GtkTreeViewColumn *column; | |
1642 GtkCellRenderer *cell; | |
1643 GList *list; | |
1644 | |
1645 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), FILE_COLUMN_THUMB - 1); | |
1646 if (!column) return; | |
1647 | |
333 | 1648 gtk_tree_view_column_set_fixed_width(column, ((thumb) ? options->thumbnails.max_width : 4) + 10); |
9 | 1649 |
1650 list = gtk_tree_view_column_get_cell_renderers(column); | |
1651 if (!list) return; | |
1652 cell = list->data; | |
1653 g_list_free(list); | |
1654 | |
333 | 1655 g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumbnails.max_height : -1, NULL); |
9 | 1656 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview)); |
1657 } | |
1658 | |
1659 static void vflist_populate_view(ViewFileList *vfl) | |
1660 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1661 GtkTreeStore *store; |
9 | 1662 GtkTreeIter iter; |
1663 gint thumbs; | |
1664 GList *work; | |
1665 GtkTreeRowReference *visible_row = NULL; | |
1666 GtkTreePath *tpath; | |
1667 gint valid; | |
1668 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1669 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 1670 thumbs = vfl->thumbs_enabled; |
1671 | |
1672 vflist_thumb_stop(vfl); | |
1673 | |
1674 if (!vfl->list) | |
1675 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1676 gtk_tree_store_clear(store); |
9 | 1677 vflist_send_update(vfl); |
1678 return; | |
1679 } | |
1680 | |
1681 if (GTK_WIDGET_REALIZED(vfl->listview) && | |
1682 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfl->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1683 { | |
1684 visible_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), tpath); | |
1685 gtk_tree_path_free(tpath); | |
1686 } | |
1687 | |
1688 vflist_listview_set_height(vfl->listview, thumbs); | |
1689 | |
1690 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); | |
1691 | |
1692 work = vfl->list; | |
1693 while (work) | |
1694 { | |
1695 gint match; | |
1696 FileData *fd = work->data; | |
1697 gint done = FALSE; | |
1698 | |
1699 while (!done) | |
1700 { | |
1701 FileData *old_fd = NULL; | |
442 | 1702 |
9 | 1703 if (valid) |
1704 { | |
1705 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, -1); | |
442 | 1706 |
167 | 1707 if (fd == old_fd) |
1708 { | |
1709 match = 0; | |
1710 } | |
1711 else | |
1712 { | |
1713 match = filelist_sort_compare_filedata_full(fd, old_fd, vfl->sort_method, vfl->sort_ascend); | |
1714 if (match == 0) | |
1715 match = -1; /* probably should not happen*/ | |
1716 } | |
9 | 1717 } |
442 | 1718 |
9 | 1719 else |
1720 { | |
1721 match = -1; | |
1722 } | |
1723 | |
1724 if (match < 0) | |
1725 { | |
1726 GtkTreeIter new; | |
442 | 1727 |
9 | 1728 if (valid) |
1729 { | |
167 | 1730 gtk_tree_store_insert_before(store, &new, NULL, &iter); |
9 | 1731 } |
1732 else | |
1733 { | |
167 | 1734 gtk_tree_store_append(store, &new, NULL); |
9 | 1735 } |
167 | 1736 vflist_setup_iter_with_sidecars(vfl, store, &new, fd); |
9 | 1737 |
1738 done = TRUE; | |
1739 } | |
1740 else if (match > 0) | |
1741 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1742 valid = gtk_tree_store_remove(store, &iter); |
9 | 1743 } |
1744 else | |
1745 { | |
167 | 1746 vflist_setup_iter_with_sidecars(vfl, store, &iter, fd); |
9 | 1747 |
1748 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
1749 | |
1750 done = TRUE; | |
1751 } | |
1752 } | |
1753 work = work->next; | |
1754 } | |
1755 | |
1756 while (valid) | |
1757 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1758 valid = gtk_tree_store_remove(store, &iter); |
9 | 1759 } |
1760 | |
1761 if (visible_row) | |
1762 { | |
1763 if (gtk_tree_row_reference_valid(visible_row)) | |
1764 { | |
1765 tpath = gtk_tree_row_reference_get_path(visible_row); | |
1766 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vfl->listview), tpath, NULL, TRUE, 0.0, 0.0); | |
1767 gtk_tree_path_free(tpath); | |
1768 } | |
1769 gtk_tree_row_reference_free(visible_row); | |
1770 } | |
1771 | |
1772 vflist_send_update(vfl); | |
1773 vflist_thumb_update(vfl); | |
1774 } | |
1775 | |
1776 gint vflist_refresh(ViewFileList *vfl) | |
1777 { | |
1778 GList *old_list; | |
1779 gint ret = TRUE; | |
1780 | |
1781 old_list = vfl->list; | |
1782 vfl->list = NULL; | |
1783 | |
1784 if (vfl->path) | |
1785 { | |
1786 ret = filelist_read(vfl->path, &vfl->list, NULL); | |
1787 } | |
1788 | |
1789 vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend); | |
1790 vflist_populate_view(vfl); | |
1791 | |
1792 filelist_free(old_list); | |
1793 | |
1794 return ret; | |
1795 } | |
1796 | |
1797 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ | |
1798 | |
1799 #define CELL_HEIGHT_OVERRIDE 512 | |
1800 | |
1801 static void cell_renderer_height_override(GtkCellRenderer *renderer) | |
1802 { | |
1803 GParamSpec *spec; | |
1804 | |
1805 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height"); | |
1806 if (spec && G_IS_PARAM_SPEC_INT(spec)) | |
1807 { | |
1808 GParamSpecInt *spec_int; | |
1809 | |
1810 spec_int = G_PARAM_SPEC_INT(spec); | |
1811 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE; | |
1812 } | |
1813 } | |
1814 | |
1815 static GdkColor *vflist_listview_color_shifted(GtkWidget *widget) | |
1816 { | |
1817 static GdkColor color; | |
1818 static GtkWidget *done = NULL; | |
1819 | |
1820 if (done != widget) | |
1821 { | |
1822 GtkStyle *style; | |
1823 | |
1824 style = gtk_widget_get_style(widget); | |
1825 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1826 shift_color(&color, -1, 0); | |
1827 done = widget; | |
1828 } | |
1829 | |
1830 return &color; | |
1831 } | |
1832 | |
1833 static void vflist_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1834 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1835 { | |
1836 ViewFileList *vfl = data; | |
1837 gboolean set; | |
1838 | |
1839 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1); | |
1840 g_object_set(G_OBJECT(cell), | |
1841 "cell-background-gdk", vflist_listview_color_shifted(vfl->listview), | |
1842 "cell-background-set", set, NULL); | |
1843 } | |
1844 | |
132 | 1845 static void vflist_listview_add_column(ViewFileList *vfl, gint n, const gchar *title, gint image, gint right_justify, gint expand) |
9 | 1846 { |
1847 GtkTreeViewColumn *column; | |
1848 GtkCellRenderer *renderer; | |
1849 | |
1850 column = gtk_tree_view_column_new(); | |
1851 gtk_tree_view_column_set_title(column, title); | |
1852 gtk_tree_view_column_set_min_width(column, 4); | |
1853 | |
1854 if (!image) | |
1855 { | |
149 | 1856 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); |
9 | 1857 renderer = gtk_cell_renderer_text_new(); |
1858 if (right_justify) | |
1859 { | |
1860 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
1861 } | |
1862 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1863 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
149 | 1864 if (expand) |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1865 gtk_tree_view_column_set_expand(column, TRUE); |
149 | 1866 } |
9 | 1867 else |
1868 { | |
1869 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
1870 renderer = gtk_cell_renderer_pixbuf_new(); | |
1871 cell_renderer_height_override(renderer); | |
1872 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1873 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
1874 } | |
1875 | |
1876 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
|
1877 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
|
1878 g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n)); |
9 | 1879 |
1880 gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); | |
1881 } | |
1882 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1883 static void vflist_listview_mark_toggled(GtkCellRendererToggle *cell, gchar *path_str, GtkTreeStore *store) |
132 | 1884 { |
149 | 1885 GtkTreePath *path = gtk_tree_path_new_from_string(path_str); |
1886 GtkTreeIter iter; | |
1887 FileData *fd; | |
1888 gboolean mark; | |
1889 guint col_idx; | |
442 | 1890 |
149 | 1891 if (!path || !gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path)) |
1892 return; | |
132 | 1893 |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
1894 col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cell), "column_store_idx")); |
442 | 1895 |
149 | 1896 g_assert(col_idx >= FILE_COLUMN_MARKS && col_idx <= FILE_COLUMN_MARKS_LAST); |
442 | 1897 |
149 | 1898 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &mark, -1); |
150 | 1899 mark = !mark; |
149 | 1900 fd->marks[col_idx - FILE_COLUMN_MARKS] = mark; |
442 | 1901 |
149 | 1902 gtk_tree_store_set(store, &iter, col_idx, mark, -1); |
1903 gtk_tree_path_free(path); | |
132 | 1904 } |
1905 | |
1906 static void vflist_listview_add_column_toggle(ViewFileList *vfl, gint n, const gchar *title) | |
1907 { | |
149 | 1908 GtkTreeViewColumn *column; |
1909 GtkCellRenderer *renderer; | |
1910 GtkTreeStore *store; | |
1911 gint index; | |
442 | 1912 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1913 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
132 | 1914 |
149 | 1915 renderer = gtk_cell_renderer_toggle_new(); |
1916 column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL); | |
132 | 1917 |
149 | 1918 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
|
1919 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
|
1920 g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n)); |
442 | 1921 |
149 | 1922 index = gtk_tree_view_append_column(GTK_TREE_VIEW(vfl->listview), column); |
1923 gtk_tree_view_column_set_fixed_width(column, 16); | |
1924 gtk_tree_view_column_set_visible(column, vfl->marks_enabled); | |
132 | 1925 |
442 | 1926 |
149 | 1927 g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(vflist_listview_mark_toggled), store); |
132 | 1928 } |
1929 | |
9 | 1930 /* |
1931 *----------------------------------------------------------------------------- | |
1932 * base | |
1933 *----------------------------------------------------------------------------- | |
1934 */ | |
1935 | |
1936 gint vflist_set_path(ViewFileList *vfl, const gchar *path) | |
1937 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1938 GtkTreeStore *store; |
9 | 1939 |
1940 if (!path) return FALSE; | |
1941 if (vfl->path && strcmp(path, vfl->path) == 0) return TRUE; | |
1942 | |
1943 g_free(vfl->path); | |
1944 vfl->path = g_strdup(path); | |
1945 | |
1946 /* force complete reload */ | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1947 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
|
1948 gtk_tree_store_clear(store); |
9 | 1949 |
1950 filelist_free(vfl->list); | |
1951 vfl->list = NULL; | |
1952 | |
1953 return vflist_refresh(vfl); | |
1954 } | |
1955 | |
1956 static void vflist_destroy_cb(GtkWidget *widget, gpointer data) | |
1957 { | |
1958 ViewFileList *vfl = data; | |
1959 | |
1960 if (vfl->popup) | |
1961 { | |
1962 g_signal_handlers_disconnect_matched(G_OBJECT(vfl->popup), G_SIGNAL_MATCH_DATA, | |
1963 0, 0, 0, NULL, vfl); | |
1964 gtk_widget_destroy(vfl->popup); | |
1965 } | |
1966 | |
1967 vflist_select_idle_cancel(vfl); | |
1968 vflist_thumb_stop(vfl); | |
1969 | |
1970 g_free(vfl->path); | |
1971 filelist_free(vfl->list); | |
1972 g_free(vfl); | |
1973 } | |
1974 | |
1975 ViewFileList *vflist_new(const gchar *path, gint thumbs) | |
1976 { | |
1977 ViewFileList *vfl; | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
1978 GtkTreeStore *store; |
9 | 1979 GtkTreeSelection *selection; |
1980 | |
149 | 1981 GType flist_types[FILE_COLUMN_COUNT]; |
1982 int i; | |
442 | 1983 |
9 | 1984 vfl = g_new0(ViewFileList, 1); |
1985 | |
1986 vfl->path = NULL; | |
1987 vfl->list = NULL; | |
1988 vfl->click_fd = NULL; | |
1989 vfl->select_fd = NULL; | |
1990 vfl->sort_method = SORT_NAME; | |
1991 vfl->sort_ascend = TRUE; | |
1992 vfl->thumbs_enabled = thumbs; | |
1993 | |
1994 vfl->thumbs_running = FALSE; | |
1995 vfl->thumbs_count = 0; | |
1996 vfl->thumbs_loader = NULL; | |
1997 vfl->thumbs_filedata = NULL; | |
1998 | |
1999 vfl->select_idle_id = -1; | |
2000 | |
2001 vfl->popup = NULL; | |
2002 | |
2003 vfl->widget = gtk_scrolled_window_new(NULL, NULL); | |
2004 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vfl->widget), GTK_SHADOW_IN); | |
2005 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vfl->widget), | |
2006 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
2007 g_signal_connect(G_OBJECT(vfl->widget), "destroy", | |
2008 G_CALLBACK(vflist_destroy_cb), vfl); | |
2009 | |
139 | 2010 flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER; |
2011 flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF; | |
2012 flist_types[FILE_COLUMN_NAME] = G_TYPE_STRING; | |
2013 flist_types[FILE_COLUMN_SIDECARS] = G_TYPE_STRING; | |
2014 flist_types[FILE_COLUMN_SIZE] = G_TYPE_STRING; | |
2015 flist_types[FILE_COLUMN_DATE] = G_TYPE_STRING; | |
2016 flist_types[FILE_COLUMN_COLOR] = G_TYPE_BOOLEAN; | |
2017 for (i = FILE_COLUMN_MARKS; i < FILE_COLUMN_MARKS + FILEDATA_MARKS_SIZE; i++) | |
2018 flist_types[i] = G_TYPE_BOOLEAN; | |
132 | 2019 |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2020 store = gtk_tree_store_newv(FILE_COLUMN_COUNT, flist_types); |
442 | 2021 |
139 | 2022 vfl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 2023 g_object_unref(store); |
2024 | |
2025 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
2026 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
2027 gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL); | |
2028 | |
149 | 2029 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfl->listview), FALSE); |
9 | 2030 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfl->listview), FALSE); |
2031 | |
132 | 2032 vflist_listview_add_column(vfl, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE); |
9 | 2033 |
517 | 2034 for (i = 0; i < FILEDATA_MARKS_SIZE;i++) |
139 | 2035 vflist_listview_add_column_toggle(vfl, i + FILE_COLUMN_MARKS, ""); |
2036 | |
149 | 2037 vflist_listview_add_column(vfl, FILE_COLUMN_NAME, _("Name"), FALSE, FALSE, FALSE); |
2038 vflist_listview_add_column(vfl, FILE_COLUMN_SIDECARS, _("SC"), FALSE, FALSE, FALSE); | |
2039 | |
2040 vflist_listview_add_column(vfl, FILE_COLUMN_SIZE, _("Size"), FALSE, TRUE, FALSE); | |
2041 vflist_listview_add_column(vfl, FILE_COLUMN_DATE, _("Date"), FALSE, TRUE, FALSE); | |
2042 | |
442 | 2043 |
139 | 2044 g_signal_connect(G_OBJECT(vfl->listview), "key_press_event", |
9 | 2045 G_CALLBACK(vflist_press_key_cb), vfl); |
2046 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
2047 gtk_container_add(GTK_CONTAINER(vfl->widget), vfl->listview); |
9 | 2048 gtk_widget_show(vfl->listview); |
2049 | |
2050 vflist_dnd_init(vfl); | |
442 | 2051 |
9 | 2052 g_signal_connect(G_OBJECT(vfl->listview), "button_press_event", |
2053 G_CALLBACK(vflist_press_cb), vfl); | |
2054 g_signal_connect(G_OBJECT(vfl->listview), "button_release_event", | |
2055 G_CALLBACK(vflist_release_cb), vfl); | |
442 | 2056 |
2057 | |
9 | 2058 if (path) vflist_set_path(vfl, path); |
2059 | |
2060 return vfl; | |
2061 } | |
2062 | |
2063 void vflist_set_status_func(ViewFileList *vfl, | |
2064 void (*func)(ViewFileList *vfl, gpointer data), gpointer data) | |
2065 { | |
2066 vfl->func_status = func; | |
2067 vfl->data_status = data; | |
2068 } | |
2069 | |
2070 void vflist_set_thumb_status_func(ViewFileList *vfl, | |
2071 void (*func)(ViewFileList *vfl, gdouble val, const gchar *text, gpointer data), | |
2072 gpointer data) | |
2073 { | |
2074 vfl->func_thumb_status = func; | |
2075 vfl->data_thumb_status = data; | |
2076 } | |
2077 | |
2078 void vflist_thumb_set(ViewFileList *vfl, gint enable) | |
2079 { | |
2080 if (vfl->thumbs_enabled == enable) return; | |
2081 | |
2082 vfl->thumbs_enabled = enable; | |
2083 vflist_refresh(vfl); | |
2084 } | |
2085 | |
132 | 2086 void vflist_marks_set(ViewFileList *vfl, gint enable) |
2087 { | |
149 | 2088 GList *columns, *work; |
442 | 2089 |
132 | 2090 if (vfl->marks_enabled == enable) return; |
2091 | |
2092 vfl->marks_enabled = enable; | |
442 | 2093 |
149 | 2094 columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vfl->listview)); |
442 | 2095 |
149 | 2096 work = columns; |
2097 while (work) | |
2098 { | |
2099 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
|
2100 gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx")); |
149 | 2101 work = work->next; |
442 | 2102 |
2103 if (col_idx <= FILE_COLUMN_MARKS_LAST && col_idx >= FILE_COLUMN_MARKS) | |
149 | 2104 gtk_tree_view_column_set_visible(column, enable); |
2105 } | |
442 | 2106 |
149 | 2107 g_list_free(columns); |
2108 //vflist_refresh(vfl); | |
132 | 2109 } |
2110 | |
9 | 2111 void vflist_set_layout(ViewFileList *vfl, LayoutWindow *layout) |
2112 { | |
2113 vfl->layout = layout; | |
2114 } | |
2115 | |
2116 /* | |
2117 *----------------------------------------------------------------------------- | |
2118 * maintenance (for rename, move, remove) | |
2119 *----------------------------------------------------------------------------- | |
2120 */ | |
2121 | |
2122 static gint vflist_maint_find_closest(ViewFileList *vfl, gint row, gint count, GList *ignore_list) | |
2123 { | |
2124 GList *list = NULL; | |
2125 GList *work; | |
2126 gint rev = row - 1; | |
2127 row ++; | |
2128 | |
2129 work = ignore_list; | |
2130 while (work) | |
2131 { | |
2132 gint f = vflist_index_by_path(vfl, work->data); | |
2133 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); | |
2134 work = work->next; | |
2135 } | |
2136 | |
2137 while (list) | |
2138 { | |
2139 gint c = TRUE; | |
2140 work = list; | |
2141 while (work && c) | |
2142 { | |
2143 gpointer p = work->data; | |
2144 work = work->next; | |
2145 if (row == GPOINTER_TO_INT(p)) | |
2146 { | |
2147 row++; | |
2148 c = FALSE; | |
2149 } | |
2150 if (rev == GPOINTER_TO_INT(p)) | |
2151 { | |
2152 rev--; | |
2153 c = FALSE; | |
2154 } | |
2155 if (!c) list = g_list_remove(list, p); | |
2156 } | |
2157 if (c && list) | |
2158 { | |
2159 g_list_free(list); | |
2160 list = NULL; | |
2161 } | |
2162 } | |
2163 if (row > count - 1) | |
2164 { | |
2165 if (rev < 0) | |
2166 return -1; | |
2167 else | |
2168 return rev; | |
2169 } | |
2170 else | |
2171 { | |
2172 return row; | |
2173 } | |
2174 } | |
2175 | |
138 | 2176 gint vflist_maint_renamed(ViewFileList *vfl, FileData *fd) |
9 | 2177 { |
2178 gint ret = FALSE; | |
2179 gchar *source_base; | |
2180 gchar *dest_base; | |
2181 | |
168
a55ada12322a
fixed vflist_find_row and vflist_sort_set to work correctly with sidecar
nadvornik
parents:
167
diff
changeset
|
2182 if (g_list_index(vfl->list, fd) < 0) return FALSE; |
9 | 2183 |
138 | 2184 source_base = remove_level_from_path(fd->change->source); |
2185 dest_base = remove_level_from_path(fd->change->dest); | |
9 | 2186 |
2187 | |
2188 if (strcmp(source_base, dest_base) == 0) | |
2189 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2190 GtkTreeStore *store; |
9 | 2191 GtkTreeIter iter; |
2192 GtkTreeIter position; | |
2193 gint old_row; | |
2194 gint n; | |
2195 | |
2196 old_row = g_list_index(vfl->list, fd); | |
2197 | |
2198 vfl->list = g_list_remove(vfl->list, fd); | |
2199 | |
2200 vfl->list = filelist_insert_sort(vfl->list, fd, vfl->sort_method, vfl->sort_ascend); | |
2201 n = g_list_index(vfl->list, fd); | |
2202 | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2203 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview))); |
9 | 2204 if (vflist_find_row(vfl, fd, &iter) >= 0 && |
2205 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &position, NULL, n)) | |
2206 { | |
2207 if (old_row >= n) | |
2208 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2209 gtk_tree_store_move_before(store, &iter, &position); |
9 | 2210 } |
2211 else | |
2212 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2213 gtk_tree_store_move_after(store, &iter, &position); |
9 | 2214 } |
2215 } | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2216 gtk_tree_store_set(store, &iter, FILE_COLUMN_NAME, fd->name, -1); |
9 | 2217 |
2218 ret = TRUE; | |
2219 } | |
2220 else | |
2221 { | |
138 | 2222 ret = vflist_maint_removed(vfl, fd, NULL); |
9 | 2223 } |
2224 | |
2225 g_free(source_base); | |
2226 g_free(dest_base); | |
2227 | |
2228 return ret; | |
2229 } | |
2230 | |
138 | 2231 gint vflist_maint_removed(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 2232 { |
2233 GtkTreeIter iter; | |
2234 GList *list; | |
2235 gint row; | |
2236 gint new_row = -1; | |
2237 | |
138 | 2238 row = g_list_index(vfl->list, fd); |
9 | 2239 if (row < 0) return FALSE; |
2240 | |
2241 if (vflist_index_is_selected(vfl, row) && | |
2242 layout_image_get_collection(vfl->layout, NULL) == NULL) | |
2243 { | |
2244 gint n; | |
2245 | |
2246 n = vflist_count(vfl, NULL); | |
2247 if (ignore_list) | |
2248 { | |
2249 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
|
2250 DEBUG_1("row = %d, closest is %d", row, new_row); |
9 | 2251 } |
2252 else | |
2253 { | |
2254 if (row + 1 < n) | |
2255 { | |
2256 new_row = row + 1; | |
2257 } | |
2258 else if (row > 0) | |
2259 { | |
2260 new_row = row - 1; | |
2261 } | |
2262 } | |
2263 vflist_select_none(vfl); | |
2264 if (new_row >= 0) | |
2265 { | |
2266 fd = vflist_index_get_data(vfl, new_row); | |
2267 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2268 { | |
2269 GtkTreeSelection *selection; | |
2270 | |
2271 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview)); | |
2272 gtk_tree_selection_select_iter(selection, &iter); | |
2273 vflist_move_cursor(vfl, &iter); | |
2274 } | |
2275 } | |
2276 } | |
2277 | |
2278 fd = vflist_index_get_data(vfl, row); | |
2279 if (vflist_find_row(vfl, fd, &iter) >= 0) | |
2280 { | |
142
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2281 GtkTreeStore *store; |
b5aa95241859
display sidecar files (jpeg + raw) using gtk_tree_store
nadvornik
parents:
139
diff
changeset
|
2282 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
|
2283 gtk_tree_store_remove(store, &iter); |
9 | 2284 } |
2285 list = g_list_nth(vfl->list, row); | |
2286 fd = list->data; | |
2287 | |
2288 /* thumbnail loader check */ | |
2289 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
|
2290 if (vfl->thumbs_count > 0) vfl->thumbs_count--; |
9 | 2291 |
2292 vfl->list = g_list_remove(vfl->list, fd); | |
138 | 2293 file_data_unref(fd); |
9 | 2294 |
2295 vflist_send_update(vfl); | |
2296 | |
2297 return TRUE; | |
2298 } | |
2299 | |
138 | 2300 gint vflist_maint_moved(ViewFileList *vfl, FileData *fd, GList *ignore_list) |
9 | 2301 { |
2302 gint ret = FALSE; | |
2303 gchar *buf; | |
2304 | |
138 | 2305 if (!fd->change->source || !vfl->path) return FALSE; |
9 | 2306 |
138 | 2307 buf = remove_level_from_path(fd->change->source); |
9 | 2308 |
2309 if (strcmp(buf, vfl->path) == 0) | |
2310 { | |
138 | 2311 ret = vflist_maint_removed(vfl, fd, ignore_list); |
9 | 2312 } |
2313 | |
2314 g_free(buf); | |
2315 | |
2316 return ret; | |
2317 } |