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