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