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