41fbd88f6ed5a30d9ff6e8dfe1527465d9121085
[geeqie.git] / src / layout_util.c
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
13 #include "gqview.h"
14 #include "layout_util.h"
15
16 #include "bar_info.h"
17 #include "bar_exif.h"
18 #include "bar_sort.h"
19 #include "cache_maint.h"
20 #include "collect.h"
21 #include "collect-dlg.h"
22 #include "dupe.h"
23 #include "editors.h"
24 #include "info.h"
25 #include "layout_image.h"
26 #include "pan-view.h"
27 #include "pixbuf_util.h"
28 #include "preferences.h"
29 #include "print.h"
30 #include "search.h"
31 #include "utilops.h"
32 #include "ui_bookmark.h"
33 #include "ui_fileops.h"
34 #include "ui_menu.h"
35 #include "ui_misc.h"
36 #include "ui_tabcomp.h"
37
38 #include <gdk/gdkkeysyms.h> /* for keyboard values */
39
40
41 #define MENU_EDIT_ACTION_OFFSET 16
42
43
44 /*
45  *-----------------------------------------------------------------------------
46  * keyboard handler
47  *-----------------------------------------------------------------------------
48  */
49
50 static guint tree_key_overrides[] = {
51         GDK_Page_Up,    GDK_KP_Page_Up,
52         GDK_Page_Down,  GDK_KP_Page_Down,
53         GDK_Home,       GDK_KP_Home,
54         GDK_End,        GDK_KP_End
55 };
56
57 static gint layout_key_match(guint keyval)
58 {
59         gint i;
60
61         for (i = 0; i < sizeof(tree_key_overrides) / sizeof(guint); i++)
62                 {
63                 if (keyval == tree_key_overrides[i]) return TRUE;
64                 }
65
66         return FALSE;
67 }
68
69 static gint layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
70 {
71         LayoutWindow *lw = data;
72         gint stop_signal = FALSE;
73         gint x = 0;
74         gint y = 0;
75
76         if (lw->path_entry && GTK_WIDGET_HAS_FOCUS(lw->path_entry))
77                 {
78                 if (event->keyval == GDK_Escape && lw->path)
79                         {
80                         gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->path);
81                         }
82
83                 /* the gtkaccelgroup of the window is stealing presses before they get to the entry (and more),
84                  * so when the some widgets have focus, give them priority (HACK)
85                  */
86                 if (gtk_widget_event(lw->path_entry, (GdkEvent *)event))
87                         {
88                         return TRUE;
89                         }
90                 }
91         if (lw->vdt && GTK_WIDGET_HAS_FOCUS(lw->vdt->treeview) &&
92             !layout_key_match(event->keyval) &&
93             gtk_widget_event(lw->vdt->treeview, (GdkEvent *)event))
94                 {
95                 return TRUE;
96                 }
97         if (lw->bar_info &&
98             bar_info_event(lw->bar_info, (GdkEvent *)event))
99                 {
100                 return TRUE;
101                 }
102
103         if (lw->image &&
104             (GTK_WIDGET_HAS_FOCUS(lw->image->widget) || (lw->tools && widget == lw->window)) )
105                 {
106                 stop_signal = TRUE;
107                 switch (event->keyval)
108                         {
109                         case GDK_Left: case GDK_KP_Left:
110                                 x -= 1;
111                                 break;
112                         case GDK_Right: case GDK_KP_Right:
113                                 x += 1;
114                                 break;
115                         case GDK_Up: case GDK_KP_Up:
116                                 y -= 1;
117                                 break;
118                         case GDK_Down: case GDK_KP_Down:
119                                 y += 1;
120                                 break;
121                         case GDK_BackSpace:
122                         case 'B': case 'b':
123                                 layout_image_prev(lw);
124                                 break;
125                         case GDK_space:
126                         case 'N': case 'n':
127                                 layout_image_next(lw);
128                                 break;
129                         case GDK_Menu:
130                                 layout_image_menu_popup(lw);
131                                 break;
132                         default:
133                                 stop_signal = FALSE;
134                                 break;
135                         }
136                 }
137
138         if (x != 0 || y!= 0)
139                 {
140                 if (event->state & GDK_SHIFT_MASK)
141                         {
142                         x *= 3;
143                         y *= 3;
144                         }
145
146                 keyboard_scroll_calc(&x, &y, event);
147                 layout_image_scroll(lw, x, y);
148                 }
149
150         if (stop_signal) return stop_signal;
151
152         if (!(event->state & GDK_CONTROL_MASK))
153                 {
154                 stop_signal = TRUE;
155                 switch (event->keyval)
156                         {
157                         case '+': case GDK_KP_Add:
158                                 layout_image_zoom_adjust(lw, get_zoom_increment());
159                                 break;
160                         case GDK_KP_Subtract:
161                                 layout_image_zoom_adjust(lw, -get_zoom_increment());
162                                 break;
163                         case GDK_KP_Multiply:
164                                 layout_image_zoom_set(lw, 0.0);
165                                 break;
166                         case GDK_KP_Divide:
167                         case '1':
168                                 layout_image_zoom_set(lw, 1.0);
169                                 break;
170                         case '2':
171                                 layout_image_zoom_set(lw, 2.0);
172                                 break;
173                         case '3':
174                                 layout_image_zoom_set(lw, 3.0);
175                                 break;
176                         case '4':
177                                 layout_image_zoom_set(lw, 4.0);
178                                 break;
179                         case '7':
180                                 layout_image_zoom_set(lw, -4.0);
181                                 break;
182                         case '8':
183                                 layout_image_zoom_set(lw, -3.0);
184                                 break;
185                         case '9':
186                                 layout_image_zoom_set(lw, -2.0);
187                                 break;
188                         case 'W': case 'w':
189                                 layout_image_zoom_set_fill_geometry(lw, FALSE);
190                                 break;
191                         case 'H': case 'h':
192                                 layout_image_zoom_set_fill_geometry(lw, TRUE);
193                                 break;
194                         case GDK_Page_Up: case GDK_KP_Page_Up:
195                                 layout_image_prev(lw);
196                                 break;
197                         case GDK_Page_Down: case GDK_KP_Page_Down:
198                                 layout_image_next(lw);
199                                 break;
200                         case GDK_Home: case GDK_KP_Home:
201                                 layout_image_first(lw);
202                                 break;
203                         case GDK_End: case GDK_KP_End:
204                                 layout_image_last(lw);
205                                 break;
206                         case GDK_Delete: case GDK_KP_Delete:
207                                 if (enable_delete_key)
208                                         {
209                                         file_util_delete(NULL, layout_selection_list(lw), widget);
210                                         }
211                                 break;
212                         case GDK_Escape:
213                                 /* FIXME:interrupting thumbs no longer allowed */
214 #if 0
215                                 interrupt_thumbs();
216 #endif
217                                 break;
218                         case 'P': case 'p':
219                                 layout_image_slideshow_pause_toggle(lw);
220                                 break;
221                         case 'V': case 'v':
222                                 if (!(event->state & GDK_MOD1_MASK)) layout_image_full_screen_toggle(lw);
223                                 break;
224                         default:
225                                 stop_signal = FALSE;
226                                 break;
227                         }
228                 }
229
230 #if 0
231         if (stop_signal) g_signal_stop_emission_by_name(G_OBJECT(widget), "key_press_event");
232 #endif
233
234         return stop_signal;
235 }
236
237 void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window)
238 {
239         g_signal_connect(G_OBJECT(window), "key_press_event",
240                          G_CALLBACK(layout_key_press_cb), lw);
241 }
242
243 /*
244  *-----------------------------------------------------------------------------
245  * menu callbacks
246  *-----------------------------------------------------------------------------
247  */
248
249 static void layout_menu_new_window_cb(GtkAction *action, gpointer data)
250 {
251         LayoutWindow *lw = data;
252         LayoutWindow *nw;
253
254         nw = layout_new(NULL, FALSE, FALSE);
255         layout_sort_set(nw, file_sort_method, file_sort_ascending);
256         layout_set_path(nw, layout_get_path(lw));
257 }
258
259 static void layout_menu_new_cb(GtkAction *action, gpointer data)
260 {
261         collection_window_new(NULL);
262 }
263
264 static void layout_menu_open_cb(GtkAction *action, gpointer data)
265 {
266         collection_dialog_load(NULL);
267 }
268
269 static void layout_menu_search_cb(GtkAction *action, gpointer data)
270 {
271         LayoutWindow *lw = data;
272
273         search_new(lw->path, layout_image_get_path(lw));
274 }
275
276 static void layout_menu_dupes_cb(GtkAction *action, gpointer data)
277 {
278         dupe_window_new(DUPE_MATCH_NAME);
279 }
280
281 static void layout_menu_pan_cb(GtkAction *action, gpointer data)
282 {
283         LayoutWindow *lw = data;
284
285         pan_window_new(layout_get_path(lw));
286 }
287
288 static void layout_menu_print_cb(GtkAction *action, gpointer data)
289 {
290         LayoutWindow *lw = data;
291
292         print_window_new(layout_image_get_path(lw), layout_selection_list(lw), layout_list(lw), lw->window);
293 }
294
295 static void layout_menu_dir_cb(GtkAction *action, gpointer data)
296 {
297         LayoutWindow *lw = data;
298
299         file_util_create_dir(lw->path, lw->window);
300 }
301
302 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
303 {
304         LayoutWindow *lw = data;
305
306         file_util_copy(NULL, layout_selection_list(lw), NULL, lw->window);
307 }
308
309 static void layout_menu_move_cb(GtkAction *action, gpointer data)
310 {
311         LayoutWindow *lw = data;
312
313         file_util_move(NULL, layout_selection_list(lw), NULL, lw->window);
314 }
315
316 static void layout_menu_rename_cb(GtkAction *action, gpointer data)
317 {
318         LayoutWindow *lw = data;
319
320         file_util_rename(NULL, layout_selection_list(lw), lw->window);
321 }
322
323 static void layout_menu_delete_cb(GtkAction *action, gpointer data)
324 {
325         LayoutWindow *lw = data;
326
327         file_util_delete(NULL, layout_selection_list(lw), lw->window);
328 }
329
330 static void layout_menu_close_cb(GtkAction *action, gpointer data)
331 {
332         LayoutWindow *lw = data;
333
334         layout_close(lw);
335 }
336
337 static void layout_menu_exit_cb(GtkAction *action, gpointer data)
338 {
339         exit_gqview();
340 }
341
342 static void layout_menu_alter_90_cb(GtkAction *action, gpointer data)
343 {
344         LayoutWindow *lw = data;
345
346         layout_image_alter(lw, ALTER_ROTATE_90);
347 }
348
349 static void layout_menu_alter_90cc_cb(GtkAction *action, gpointer data)
350 {
351         LayoutWindow *lw = data;
352
353         layout_image_alter(lw, ALTER_ROTATE_90_CC);
354 }
355
356 static void layout_menu_alter_180_cb(GtkAction *action, gpointer data)
357 {
358         LayoutWindow *lw = data;
359
360         layout_image_alter(lw, ALTER_ROTATE_180);
361 }
362
363 static void layout_menu_alter_mirror_cb(GtkAction *action, gpointer data)
364 {
365         LayoutWindow *lw = data;
366
367         layout_image_alter(lw, ALTER_MIRROR);
368 }
369
370 static void layout_menu_alter_flip_cb(GtkAction *action, gpointer data)
371 {
372         LayoutWindow *lw = data;
373
374         layout_image_alter(lw, ALTER_FLIP);
375 }
376
377 static void layout_menu_alter_desaturate_cb(GtkAction *action, gpointer data)
378 {
379         LayoutWindow *lw = data;
380
381         layout_image_alter(lw, ALTER_DESATURATE);
382 }
383
384 static void layout_menu_info_cb(GtkAction *action, gpointer data)
385 {
386         LayoutWindow *lw = data;
387         GList *list;
388         const gchar *path = NULL;
389
390         list = layout_selection_list(lw);
391         if (!list) path = layout_image_get_path(lw);
392
393         info_window_new(path, list);
394 }
395
396 static void layout_menu_select_all_cb(GtkAction *action, gpointer data)
397 {
398         LayoutWindow *lw = data;
399
400         layout_select_all(lw);
401 }
402
403 static void layout_menu_unselect_all_cb(GtkAction *action, gpointer data)
404 {
405         LayoutWindow *lw = data;
406
407         layout_select_none(lw);
408 }
409
410 static void layout_menu_config_cb(GtkAction *action, gpointer data)
411 {
412         show_config_window();
413 }
414
415 static void layout_menu_remove_thumb_cb(GtkAction *action, gpointer data)
416 {
417         cache_manager_show();
418 }
419
420 static void layout_menu_wallpaper_cb(GtkAction *action, gpointer data)
421 {
422         LayoutWindow *lw = data;
423
424         layout_image_to_root(lw);
425 }
426
427 static void layout_menu_zoom_in_cb(GtkAction *action, gpointer data)
428 {
429         LayoutWindow *lw = data;
430
431         layout_image_zoom_adjust(lw, get_zoom_increment());
432 }
433
434 static void layout_menu_zoom_out_cb(GtkAction *action, gpointer data)
435 {
436         LayoutWindow *lw = data;
437
438         layout_image_zoom_adjust(lw, -get_zoom_increment());
439 }
440
441 static void layout_menu_zoom_1_1_cb(GtkAction *action, gpointer data)
442 {
443         LayoutWindow *lw = data;
444
445         layout_image_zoom_set(lw, 1.0);
446 }
447
448 static void layout_menu_zoom_fit_cb(GtkAction *action, gpointer data)
449 {
450         LayoutWindow *lw = data;
451
452         layout_image_zoom_set(lw, 0.0);
453 }
454
455 static void layout_menu_thumb_cb(GtkToggleAction *action, gpointer data)
456 {
457         LayoutWindow *lw = data;
458
459         layout_thumb_set(lw, gtk_toggle_action_get_active(action));
460 }
461
462 static void layout_menu_list_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
463 {
464         LayoutWindow *lw = data;
465
466         layout_views_set(lw, lw->tree_view, (gtk_radio_action_get_current_value(action) == 1));
467 }
468
469 static void layout_menu_tree_cb(GtkToggleAction *action, gpointer data)
470 {
471         LayoutWindow *lw = data;
472
473         layout_views_set(lw, gtk_toggle_action_get_active(action), lw->icon_view);
474 }
475
476 static void layout_menu_fullscreen_cb(GtkAction *action, gpointer data)
477 {
478         LayoutWindow *lw = data;
479
480         layout_image_full_screen_toggle(lw);
481 }
482
483 static void layout_menu_refresh_cb(GtkAction *action, gpointer data)
484 {
485         LayoutWindow *lw = data;
486
487         layout_refresh(lw);
488 }
489
490 static void layout_menu_float_cb(GtkToggleAction *action, gpointer data)
491 {
492         LayoutWindow *lw = data;
493
494         if (lw->tools_float != gtk_toggle_action_get_active(action))
495                 {
496                 layout_tools_float_toggle(lw);
497                 }
498 }
499
500 static void layout_menu_hide_cb(GtkAction *action, gpointer data)
501 {
502         LayoutWindow *lw = data;
503
504         layout_tools_hide_toggle(lw);
505 }
506
507 static void layout_menu_toolbar_cb(GtkToggleAction *action, gpointer data)
508 {
509         LayoutWindow *lw = data;
510
511         if (lw->toolbar_hidden != gtk_toggle_action_get_active(action))
512                 {
513                 layout_toolbar_toggle(lw);
514                 }
515 }
516
517 static void layout_menu_bar_info_cb(GtkToggleAction *action, gpointer data)
518 {
519         LayoutWindow *lw = data;
520
521         if (lw->bar_info_enabled != gtk_toggle_action_get_active(action))
522                 {
523                 layout_bar_info_toggle(lw);
524                 }
525 }
526
527 static void layout_menu_bar_exif_cb(GtkToggleAction *action, gpointer data)
528 {
529         LayoutWindow *lw = data;
530
531         if (lw->bar_exif_enabled != gtk_toggle_action_get_active(action))
532                 {
533                 layout_bar_exif_toggle(lw);
534                 }
535 }
536
537 static void layout_menu_bar_sort_cb(GtkToggleAction *action, gpointer data)
538 {
539         LayoutWindow *lw = data;
540
541         if (lw->bar_sort_enabled != gtk_toggle_action_get_active(action))
542                 {
543                 layout_bar_sort_toggle(lw);
544                 }
545 }
546
547 static void layout_menu_slideshow_cb(GtkAction *action, gpointer data)
548 {
549         LayoutWindow *lw = data;
550
551         layout_image_slideshow_toggle(lw);
552 }
553
554 static void layout_menu_help_cb(GtkAction *action, gpointer data)
555 {
556         help_window_show("html_contents");
557 }
558
559 static void layout_menu_help_keys_cb(GtkAction *action, gpointer data)
560 {
561         help_window_show("documentation");
562 }
563
564 static void layout_menu_notes_cb(GtkAction *action, gpointer data)
565 {
566         help_window_show("release_notes");
567 }
568
569 static void layout_menu_about_cb(GtkAction *action, gpointer data)
570 {
571         show_about_window();
572 }
573
574 /*
575  *-----------------------------------------------------------------------------
576  * edit menu
577  *-----------------------------------------------------------------------------
578  */ 
579
580 static void layout_menu_edit_cb(GtkAction *action, gpointer data)
581 {
582         LayoutWindow *lw = data;
583         GList *list;
584         gint n;
585
586         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "edit_index"));
587
588         list = layout_selection_list(lw);
589         start_editor_from_path_list(n, list);
590         path_list_free(list);
591 }
592
593 static void layout_menu_edit_update(LayoutWindow *lw)
594 {
595         gint i;
596
597         /* main edit menu */
598
599         if (!lw->action_group) return;
600
601         for (i = 0; i < 10; i++)
602                 {
603                 gchar *key;
604                 GtkAction *action;
605
606                 key = g_strdup_printf("Editor%d", i);
607
608                 action = gtk_action_group_get_action(lw->action_group, key);
609                 g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i));
610
611                 if (editor_command[i] && strlen(editor_command[i]) > 0)
612                         {
613                         gchar *text;
614
615                         if (editor_name[i] && strlen(editor_name[i]) > 0)
616                                 {
617                                 text = g_strdup_printf(_("in %s..."), editor_name[i]);
618                                 }
619                         else
620                                 {
621                                 text = g_strdup(_("in (unknown)..."));
622                                 }
623                         g_object_set(action, "label", text,
624                                              "sensitive", TRUE, NULL);
625                         g_free(text);
626                         }
627                 else
628                         {
629                         g_object_set(action, "label", _("empty"),
630                                              "sensitive", FALSE, NULL);
631                         }
632
633                 g_free(key);
634                 }
635 }
636
637 void layout_edit_update_all(void)
638 {
639         GList *work;
640
641         work = layout_window_list;
642         while (work)
643                 {
644                 LayoutWindow *lw = work->data;
645                 work = work->next;
646
647                 layout_menu_edit_update(lw);
648                 }
649 }
650
651 /*
652  *-----------------------------------------------------------------------------
653  * recent menu
654  *-----------------------------------------------------------------------------
655  */
656
657 static void layout_menu_recent_cb(GtkWidget *widget, gpointer data)
658 {
659         gint n;
660         gchar *path;
661
662         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "recent_index"));
663
664         path = g_list_nth_data(history_list_get_by_key("recent"), n);
665
666         if (!path) return;
667
668         /* make a copy of it */
669         path = g_strdup(path);
670         collection_window_new(path);
671         g_free(path);
672 }
673
674 static void layout_menu_recent_update(LayoutWindow *lw)
675 {
676         GtkWidget *menu;
677         GtkWidget *recent;
678         GtkWidget *item;
679         GList *list;
680         gint n;
681
682         if (!lw->ui_manager) return;
683
684         list = history_list_get_by_key("recent");
685         n = 0;
686
687         menu = gtk_menu_new();
688
689         while (list)
690                 {
691                 item = menu_item_add_simple(menu, filename_from_path((gchar *)list->data),
692                                             G_CALLBACK(layout_menu_recent_cb), lw);
693                 g_object_set_data(G_OBJECT(item), "recent_index", GINT_TO_POINTER(n));
694                 list = list->next;
695                 n++;
696                 }
697
698         if (n == 0)
699                 {
700                 menu_item_add(menu, _("Empty"), NULL, NULL);
701                 }
702
703         recent = gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu/FileMenu/OpenRecent");
704         gtk_menu_item_set_submenu(GTK_MENU_ITEM(recent), menu);
705         gtk_widget_set_sensitive(recent, (n != 0));
706 }
707
708 void layout_recent_update_all(void)
709 {
710         GList *work;
711
712         work = layout_window_list;
713         while (work)
714                 {
715                 LayoutWindow *lw = work->data;
716                 work = work->next;
717
718                 layout_menu_recent_update(lw);
719                 }
720 }
721
722 void layout_recent_add_path(const gchar *path)
723 {
724         if (!path) return;
725
726         history_list_add_to_key("recent", path, recent_list_max);
727
728         layout_recent_update_all();
729 }
730
731 /*
732  *-----------------------------------------------------------------------------
733  * menu
734  *-----------------------------------------------------------------------------
735  */ 
736
737 #define CB G_CALLBACK
738
739 static GtkActionEntry menu_entries[] = {
740   { "FileMenu",         NULL,           N_("_File") },
741   { "EditMenu",         NULL,           N_("_Edit") },
742   { "AdjustMenu",       NULL,           N_("_Adjust") },
743   { "ViewMenu",         NULL,           N_("_View") },
744   { "HelpMenu",         NULL,           N_("_Help") },
745
746   { "NewWindow",        GTK_STOCK_NEW,  N_("New _window"),      NULL,           NULL,   CB(layout_menu_new_window_cb) },
747   { "NewCollection",    GTK_STOCK_INDEX,N_("_New collection"),  "C",            NULL,   CB(layout_menu_new_cb) },
748   { "OpenCollection",   GTK_STOCK_OPEN, N_("_Open collection..."),"O",          NULL,   CB(layout_menu_open_cb) },
749   { "OpenRecent",       NULL,           N_("Open _recent") },
750   { "Search",           GTK_STOCK_FIND, N_("_Search..."),       "F3",           NULL,   CB(layout_menu_search_cb) },
751   { "FindDupes",        GTK_STOCK_FIND, N_("_Find duplicates..."),"D",          NULL,   CB(layout_menu_dupes_cb) },
752   { "PanView",          NULL,           N_("Pan _view"),        "<control>J",   NULL,   CB(layout_menu_pan_cb) },
753   { "Print",            GTK_STOCK_PRINT,N_("_Print..."),        "<shift>P",     NULL,   CB(layout_menu_print_cb) },
754   { "NewFolder",        NULL,           N_("N_ew folder..."),   "<control>F",   NULL,   CB(layout_menu_dir_cb) },
755   { "Copy",             NULL,           N_("_Copy..."),         "<control>C",   NULL,   CB(layout_menu_copy_cb) },
756   { "Move",             NULL,           N_("_Move..."),         "<control>M",   NULL,   CB(layout_menu_move_cb) },
757   { "Rename",           NULL,           N_("_Rename..."),       "<control>R",   NULL,   CB(layout_menu_rename_cb) },
758   { "Delete",   GTK_STOCK_DELETE,       N_("_Delete..."),       "<control>D",   NULL,   CB(layout_menu_delete_cb) },
759   { "CloseWindow",      GTK_STOCK_CLOSE,N_("C_lose window"),    "<control>W",   NULL,   CB(layout_menu_close_cb) },
760   { "Quit",             GTK_STOCK_QUIT, N_("_Quit"),            "<control>Q",   NULL,   CB(layout_menu_exit_cb) },
761
762   { "Editor0",          NULL,           "editor0",              "<control>1",   NULL,   CB(layout_menu_edit_cb) },
763   { "Editor1",          NULL,           "editor1",              "<control>2",   NULL,   CB(layout_menu_edit_cb) },
764   { "Editor2",          NULL,           "editor2",              "<control>3",   NULL,   CB(layout_menu_edit_cb) },
765   { "Editor3",          NULL,           "editor3",              "<control>4",   NULL,   CB(layout_menu_edit_cb) },
766   { "Editor4",          NULL,           "editor4",              "<control>5",   NULL,   CB(layout_menu_edit_cb) },
767   { "Editor5",          NULL,           "editor5",              "<control>6",   NULL,   CB(layout_menu_edit_cb) },
768   { "Editor6",          NULL,           "editor6",              "<control>7",   NULL,   CB(layout_menu_edit_cb) },
769   { "Editor7",          NULL,           "editor7",              "<control>8",   NULL,   CB(layout_menu_edit_cb) },
770   { "Editor8",          NULL,           "editor8",              "<control>9",   NULL,   CB(layout_menu_edit_cb) },
771   { "Editor9",          NULL,           "editor9",              "<control>0",   NULL,   CB(layout_menu_edit_cb) },
772   { "RotateCW",         NULL,   N_("_Rotate clockwise"),        "bracketright", NULL,   CB(layout_menu_alter_90_cb) },
773   { "RotateCCW",        NULL,   N_("Rotate _counterclockwise"), "bracketleft",  NULL,   CB(layout_menu_alter_90cc_cb) },
774   { "Rotate180",        NULL,           N_("Rotate 1_80"),      "<shift>R",     NULL,   CB(layout_menu_alter_180_cb) },
775   { "Mirror",           NULL,           N_("_Mirror"),          "<shift>M",     NULL,   CB(layout_menu_alter_mirror_cb) },
776   { "Flip",             NULL,           N_("_Flip"),            "<shift>F",     NULL,   CB(layout_menu_alter_flip_cb) },
777   { "Grayscale",        NULL,           N_("_Grayscale"),       "<shift>G",     NULL,   CB(layout_menu_alter_desaturate_cb) },
778   { "Properties",GTK_STOCK_PROPERTIES,  N_("_Properties"),      "<control>P",   NULL,   CB(layout_menu_info_cb) },
779   { "SelectAll",        NULL,           N_("Select _all"),      "<control>A",   NULL,   CB(layout_menu_select_all_cb) },
780   { "SelectNone",       NULL,           N_("Select _none"), "<control><shift>A",NULL,   CB(layout_menu_unselect_all_cb) },
781   { "Preferences",GTK_STOCK_PREFERENCES,N_("P_references..."),  "<control>O",   NULL,   CB(layout_menu_config_cb) },
782   { "Maintenance",      NULL,           N_("_Thumbnail maintenance..."),NULL,   NULL,   CB(layout_menu_remove_thumb_cb) },
783   { "Wallpaper",        NULL,           N_("Set as _wallpaper"),NULL,           NULL,   CB(layout_menu_wallpaper_cb) },
784
785   { "ZoomIn",   GTK_STOCK_ZOOM_IN,      N_("Zoom _in"),         "equal",        NULL,   CB(layout_menu_zoom_in_cb) },
786   { "ZoomOut",  GTK_STOCK_ZOOM_OUT,     N_("Zoom _out"),        "minus",        NULL,   CB(layout_menu_zoom_out_cb) },
787   { "Zoom100",  GTK_STOCK_ZOOM_100,     N_("Zoom _1:1"),        "Z",            NULL,   CB(layout_menu_zoom_1_1_cb) },
788   { "ZoomFit",  GTK_STOCK_ZOOM_FIT,     N_("_Zoom to fit"),     "X",            NULL,   CB(layout_menu_zoom_fit_cb) },
789   { "FullScreen",       NULL,           N_("F_ull screen"),     "F",            NULL,   CB(layout_menu_fullscreen_cb) },
790   { "HideTools",        NULL,           N_("_Hide file list"),  "<control>H",   NULL,   CB(layout_menu_hide_cb) },
791   { "SlideShow",        NULL,           N_("Toggle _slideshow"),"S",            NULL,   CB(layout_menu_slideshow_cb) },
792   { "Refresh",  GTK_STOCK_REFRESH,      N_("_Refresh"),         "R",            NULL,   CB(layout_menu_refresh_cb) },
793
794   { "HelpContents",     GTK_STOCK_HELP, N_("_Contents"),        "F1",           NULL,   CB(layout_menu_help_cb) },
795   { "HelpShortcuts",    NULL,           N_("_Keyboard shortcuts"),NULL,         NULL,   CB(layout_menu_help_keys_cb) },
796   { "HelpNotes",        NULL,           N_("_Release notes"),   NULL,           NULL,   CB(layout_menu_notes_cb) },
797   { "About",            NULL,           N_("_About"),           NULL,           NULL,   CB(layout_menu_about_cb) }
798 };
799
800 static GtkToggleActionEntry menu_toggle_entries[] = {
801   { "Thumbnails",       NULL,           N_("_Thumbnails"),      "T",            NULL,   CB(layout_menu_thumb_cb) },
802   { "FolderTree",       NULL,           N_("Tr_ee"),            "<control>T",   NULL,   CB(layout_menu_tree_cb) },
803   { "FloatTools",       NULL,           N_("_Float file list"), "L",            NULL,   CB(layout_menu_float_cb) },
804   { "HideToolbar",      NULL,           N_("Hide tool_bar"),    NULL,           NULL,   CB(layout_menu_toolbar_cb) },
805   { "SBarKeywords",     NULL,           N_("_Keywords"),        "<control>K",   NULL,   CB(layout_menu_bar_info_cb) },
806   { "SBarExif",         NULL,           N_("E_xif data"),       "<control>E",   NULL,   CB(layout_menu_bar_exif_cb) },
807   { "SBarSort",         NULL,           N_("Sort _manager"),    "<control>S",   NULL,   CB(layout_menu_bar_sort_cb) }
808 };
809
810 static GtkRadioActionEntry menu_radio_entries[] = {
811   { "ViewList",         NULL,           N_("_List"),            "<control>L",   NULL,   0 },
812   { "ViewIcons",        NULL,           N_("I_cons"),           "<control>I",   NULL,   1 }
813 };
814
815 #undef CB
816
817 static const char *menu_ui_description =
818 "<ui>"
819 "  <menubar name='MainMenu'>"
820 "    <menu action='FileMenu'>"
821 "      <menuitem action='NewWindow'/>"
822 "      <menuitem action='NewCollection'/>"
823 "      <menuitem action='OpenCollection'/>"
824 "      <menuitem action='OpenRecent'/>"
825 "      <separator/>"
826 "      <menuitem action='Search'/>"
827 "      <menuitem action='FindDupes'/>"
828 "      <menuitem action='PanView'/>"
829 "      <separator/>"
830 "      <menuitem action='Print'/>"
831 "      <menuitem action='NewFolder'/>"
832 "      <separator/>"
833 "      <menuitem action='Copy'/>"
834 "      <menuitem action='Move'/>"
835 "      <menuitem action='Rename'/>"
836 "      <menuitem action='Delete'/>"
837 "      <separator/>"
838 "      <menuitem action='CloseWindow'/>"
839 "      <menuitem action='Quit'/>"
840 "    </menu>"
841 "    <menu action='EditMenu'>"
842 "      <menuitem action='Editor0'/>"
843 "      <menuitem action='Editor1'/>"
844 "      <menuitem action='Editor2'/>"
845 "      <menuitem action='Editor3'/>"
846 "      <menuitem action='Editor4'/>"
847 "      <menuitem action='Editor5'/>"
848 "      <menuitem action='Editor6'/>"
849 "      <menuitem action='Editor7'/>"
850 "      <menuitem action='Editor8'/>"
851 "      <menuitem action='Editor9'/>"
852 "      <separator/>"
853 "      <menu action='AdjustMenu'>"
854 "        <menuitem action='RotateCW'/>"
855 "        <menuitem action='RotateCCW'/>"
856 "        <menuitem action='Rotate180'/>"
857 "        <menuitem action='Mirror'/>"
858 "        <menuitem action='Flip'/>"
859 "        <menuitem action='Grayscale'/>"
860 "      </menu>"
861 "      <menuitem action='Properties'/>"
862 "      <separator/>"
863 "      <menuitem action='SelectAll'/>"
864 "      <menuitem action='SelectNone'/>"
865 "      <separator/>"
866 "      <menuitem action='Preferences'/>"
867 "      <menuitem action='Maintenance'/>"
868 "      <separator/>"
869 "      <menuitem action='Wallpaper'/>"
870 "    </menu>"
871 "    <menu action='ViewMenu'>"
872 "      <separator/>"
873 "      <menuitem action='ZoomIn'/>"
874 "      <menuitem action='ZoomOut'/>"
875 "      <menuitem action='Zoom100'/>"
876 "      <menuitem action='ZoomFit'/>"
877 "      <separator/>"
878 "      <menuitem action='Thumbnails'/>"
879 "      <menuitem action='ViewList'/>"
880 "      <menuitem action='ViewIcons'/>"
881 "      <separator/>"
882 "      <menuitem action='FolderTree'/>"
883 "      <menuitem action='FullScreen'/>"
884 "      <separator/>"
885 "      <menuitem action='FloatTools'/>"
886 "      <menuitem action='HideTools'/>"
887 "      <menuitem action='HideToolbar'/>"
888 "      <separator/>"
889 "      <menuitem action='SBarKeywords'/>"
890 "      <menuitem action='SBarExif'/>"
891 "      <menuitem action='SBarSort'/>"
892 "      <separator/>"
893 "      <menuitem action='SlideShow'/>"
894 "      <menuitem action='Refresh'/>"
895 "    </menu>"
896 "    <menu action='HelpMenu'>"
897 "      <separator/>"
898 "      <menuitem action='HelpContents'/>"
899 "      <menuitem action='HelpShortcuts'/>"
900 "      <menuitem action='HelpNotes'/>"
901 "      <separator/>"
902 "      <menuitem action='About'/>"
903 "    </menu>"
904 "  </menubar>"
905 "</ui>";
906
907
908 static gchar *menu_translate(const gchar *path, gpointer data)
909 {
910         return _(path);
911 }
912
913 void layout_actions_setup(LayoutWindow *lw)
914 {
915         GError *error;
916
917         if (lw->ui_manager) return;
918
919         lw->action_group = gtk_action_group_new ("MenuActions");
920         gtk_action_group_set_translate_func(lw->action_group, menu_translate, NULL, NULL);
921
922         gtk_action_group_add_actions(lw->action_group,
923                                      menu_entries, G_N_ELEMENTS(menu_entries), lw);
924         gtk_action_group_add_toggle_actions(lw->action_group,
925                                             menu_toggle_entries, G_N_ELEMENTS(menu_toggle_entries), lw);
926         gtk_action_group_add_radio_actions(lw->action_group,
927                                            menu_radio_entries, G_N_ELEMENTS(menu_radio_entries),
928                                            0, G_CALLBACK(layout_menu_list_cb), lw);
929
930         lw->ui_manager = gtk_ui_manager_new();
931         gtk_ui_manager_set_add_tearoffs(lw->ui_manager, TRUE);
932         gtk_ui_manager_insert_action_group(lw->ui_manager, lw->action_group, 0);
933
934         error = NULL;
935         if (!gtk_ui_manager_add_ui_from_string(lw->ui_manager, menu_ui_description, -1, &error))
936                 {
937                 g_message ("building menus failed: %s", error->message);
938                 g_error_free (error);
939                 exit (EXIT_FAILURE);
940                 }
941 }
942
943 void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window)
944 {
945         GtkAccelGroup *group;
946
947         if (!lw->ui_manager) return;
948
949         group = gtk_ui_manager_get_accel_group(lw->ui_manager);
950         gtk_window_add_accel_group(GTK_WINDOW(window), group);
951 }
952
953 GtkWidget *layout_actions_menu_bar(LayoutWindow *lw)
954 {
955         return gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu");
956 }
957
958
959 /*
960  *-----------------------------------------------------------------------------
961  * toolbar
962  *-----------------------------------------------------------------------------
963  */ 
964
965 static void layout_button_thumb_cb(GtkWidget *widget, gpointer data)
966 {
967         LayoutWindow *lw = data;
968
969         layout_thumb_set(lw, gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget)));
970 }
971
972 static void layout_button_home_cb(GtkWidget *widget, gpointer data)
973 {
974         LayoutWindow *lw = data;
975         const gchar *path = homedir();
976
977         if (path) layout_set_path(lw, path);
978 }
979
980 static void layout_button_refresh_cb(GtkWidget *widget, gpointer data)
981 {
982         LayoutWindow *lw = data;
983
984         layout_refresh(lw);
985 }
986
987 static void layout_button_zoom_in_cb(GtkWidget *widget, gpointer data)
988 {
989         LayoutWindow *lw = data;
990
991         layout_image_zoom_adjust(lw, get_zoom_increment());
992 }
993
994 static void layout_button_zoom_out_cb(GtkWidget *widget, gpointer data)
995 {
996         LayoutWindow *lw = data;
997
998         layout_image_zoom_adjust(lw, -get_zoom_increment());
999 }
1000
1001 static void layout_button_zoom_fit_cb(GtkWidget *widget, gpointer data)
1002 {
1003         LayoutWindow *lw = data;
1004
1005         layout_image_zoom_set(lw, 0.0);
1006 }
1007
1008 static void layout_button_zoom_1_1_cb(GtkWidget *widget, gpointer data)
1009 {
1010         LayoutWindow *lw = data;
1011
1012         layout_image_zoom_set(lw, 1.0);
1013 }
1014
1015 static void layout_button_config_cb(GtkWidget *widget, gpointer data)
1016 {
1017         show_config_window();
1018 }
1019
1020 static void layout_button_float_cb(GtkWidget *widget, gpointer data)
1021 {
1022         LayoutWindow *lw = data;
1023
1024         layout_tools_float_toggle(lw);
1025 }
1026
1027 static void layout_button_custom_icon(GtkWidget *button, const gchar *key)
1028 {
1029         GtkWidget *icon;
1030         GdkPixbuf *pixbuf;
1031
1032         pixbuf = pixbuf_inline(key);
1033         if (!pixbuf) return;
1034
1035         icon = gtk_image_new_from_pixbuf(pixbuf);
1036         g_object_unref(pixbuf);
1037
1038         pref_toolbar_button_set_icon(button, icon, NULL);
1039         gtk_widget_show(icon);
1040 }
1041
1042 GtkWidget *layout_button_bar(LayoutWindow *lw)
1043 {
1044         GtkWidget *box;
1045         GtkWidget *button;
1046
1047         box =  pref_toolbar_new(NULL, GTK_TOOLBAR_ICONS);
1048
1049         button = pref_toolbar_button(box, NULL, _("_Thumbnails"), TRUE,
1050                                      _("Show thumbnails"), G_CALLBACK(layout_button_thumb_cb), lw);
1051         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_THUMB);
1052         lw->thumb_button = button;
1053
1054         pref_toolbar_button(box, GTK_STOCK_HOME, NULL, FALSE,
1055                             _("Change to home folder"), G_CALLBACK(layout_button_home_cb), lw);
1056         pref_toolbar_button(box, GTK_STOCK_REFRESH, NULL, FALSE,
1057                             _("Refresh file list"), G_CALLBACK(layout_button_refresh_cb), lw);
1058         pref_toolbar_button(box, GTK_STOCK_ZOOM_IN, NULL, FALSE,
1059                             _("Zoom in"), G_CALLBACK(layout_button_zoom_in_cb), lw);
1060         pref_toolbar_button(box, GTK_STOCK_ZOOM_OUT, NULL, FALSE,
1061                             _("Zoom out"), G_CALLBACK(layout_button_zoom_out_cb), lw);
1062         pref_toolbar_button(box, GTK_STOCK_ZOOM_FIT, NULL, FALSE,
1063                             _("Fit image to window"), G_CALLBACK(layout_button_zoom_fit_cb), lw);
1064         pref_toolbar_button(box, GTK_STOCK_ZOOM_100, NULL, FALSE,
1065                             _("Set zoom 1:1"), G_CALLBACK(layout_button_zoom_1_1_cb), lw);
1066         pref_toolbar_button(box, GTK_STOCK_PREFERENCES, NULL, FALSE,
1067                             _("Configure options"), G_CALLBACK(layout_button_config_cb), lw);
1068         button = pref_toolbar_button(box, NULL, _("_Float"), FALSE,
1069                                      _("Float Controls"), G_CALLBACK(layout_button_float_cb), lw);
1070         layout_button_custom_icon(button, PIXBUF_INLINE_ICON_FLOAT);
1071
1072         return box;
1073 }
1074
1075 /*
1076  *-----------------------------------------------------------------------------
1077  * misc
1078  *-----------------------------------------------------------------------------
1079  */
1080
1081 static void layout_util_sync_views(LayoutWindow *lw)
1082 {
1083         GtkAction *action;
1084
1085         if (!lw->action_group) return;
1086
1087         action = gtk_action_group_get_action(lw->action_group, "FolderTree");
1088         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tree_view);
1089
1090         action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
1091         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->icon_view);
1092
1093         action = gtk_action_group_get_action(lw->action_group, "FloatTools");
1094         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tools_float);
1095
1096         action = gtk_action_group_get_action(lw->action_group, "SBarKeywords");
1097         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_info_enabled);
1098
1099         action = gtk_action_group_get_action(lw->action_group, "SBarExif");
1100         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_exif_enabled);
1101
1102         action = gtk_action_group_get_action(lw->action_group, "SBarSort");
1103         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_sort_enabled);
1104
1105         action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
1106         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->toolbar_hidden);
1107 }
1108
1109 void layout_util_sync_thumb(LayoutWindow *lw)
1110 {
1111         GtkAction *action;
1112
1113         if (!lw->action_group) return;
1114
1115         action = gtk_action_group_get_action(lw->action_group, "Thumbnails");
1116         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->thumbs_enabled);
1117         g_object_set(action, "sensitive", !lw->icon_view, NULL);
1118
1119         gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->thumbs_enabled);
1120         gtk_widget_set_sensitive(lw->thumb_button, !lw->icon_view);
1121 }
1122
1123 void layout_util_sync(LayoutWindow *lw)
1124 {
1125         layout_util_sync_views(lw);
1126         layout_util_sync_thumb(lw);
1127         layout_menu_recent_update(lw);
1128         layout_menu_edit_update(lw);
1129 }
1130
1131 /*
1132  *-----------------------------------------------------------------------------
1133  * icons (since all the toolbar icons are included here, best place as any)
1134  *-----------------------------------------------------------------------------
1135  */
1136
1137 PixmapFolders *folder_icons_new(void)
1138 {
1139         PixmapFolders *pf;
1140
1141         pf = g_new0(PixmapFolders, 1);
1142
1143         pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
1144         pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
1145         pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
1146         pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
1147
1148         return pf;
1149 }
1150
1151 void folder_icons_free(PixmapFolders *pf)
1152 {
1153         if (!pf) return;
1154
1155         g_object_unref(pf->close);
1156         g_object_unref(pf->open);
1157         g_object_unref(pf->deny);
1158         g_object_unref(pf->parent);
1159
1160         g_free(pf);
1161 }
1162
1163 /*
1164  *-----------------------------------------------------------------------------
1165  * sidebars
1166  *-----------------------------------------------------------------------------
1167  */
1168
1169 #define SIDEBAR_WIDTH 288
1170
1171 static void layout_bar_info_destroyed(GtkWidget *widget, gpointer data)
1172 {
1173         LayoutWindow *lw = data;
1174
1175         lw->bar_info = NULL;
1176
1177         if (lw->utility_box)
1178                 {
1179                 /* destroyed from within itself */
1180                 lw->bar_info_enabled = FALSE;
1181                 layout_util_sync_views(lw);
1182                 }
1183 }
1184
1185 static GList *layout_bar_info_list_cb(gpointer data)
1186 {
1187         LayoutWindow *lw = data;
1188
1189         return layout_selection_list(lw);
1190 }
1191
1192 static void layout_bar_info_new(LayoutWindow *lw)
1193 {
1194         if (!lw->utility_box) return;
1195                                                                                                                     
1196         lw->bar_info = bar_info_new(layout_image_get_path(lw), FALSE, lw->utility_box);
1197         bar_info_set_selection_func(lw->bar_info, layout_bar_info_list_cb, lw);
1198         bar_info_selection(lw->bar_info, layout_selection_count(lw, NULL) - 1);
1199         bar_info_size_request(lw->bar_info, SIDEBAR_WIDTH * 3 / 4);
1200         g_signal_connect(G_OBJECT(lw->bar_info), "destroy",
1201                          G_CALLBACK(layout_bar_info_destroyed), lw);
1202         lw->bar_info_enabled = TRUE;
1203
1204         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_info, FALSE, FALSE, 0);
1205         gtk_widget_show(lw->bar_info);
1206 }
1207                                                                                                                     
1208 static void layout_bar_info_close(LayoutWindow *lw)
1209 {
1210         if (lw->bar_info)
1211                 {
1212                 bar_info_close(lw->bar_info);
1213                 lw->bar_info = NULL;
1214                 }
1215         lw->bar_info_enabled = FALSE;
1216 }
1217
1218 void layout_bar_info_toggle(LayoutWindow *lw)
1219 {
1220         if (lw->bar_info_enabled)
1221                 {
1222                 layout_bar_info_close(lw);
1223                 }
1224         else
1225                 {
1226                 layout_bar_info_new(lw);
1227                 }
1228 }
1229
1230 static void layout_bar_info_new_image(LayoutWindow *lw)
1231 {
1232         if (!lw->bar_info || !lw->bar_info_enabled) return;
1233
1234         bar_info_set(lw->bar_info, layout_image_get_path(lw));
1235 }
1236
1237 static void layout_bar_info_new_selection(LayoutWindow *lw, gint count)
1238 {
1239         if (!lw->bar_info || !lw->bar_info_enabled) return;
1240
1241         bar_info_selection(lw->bar_info, count - 1);
1242 }
1243
1244 static void layout_bar_info_maint_renamed(LayoutWindow *lw)
1245 {
1246         if (!lw->bar_info || !lw->bar_info_enabled) return;
1247
1248         bar_info_maint_renamed(lw->bar_info, layout_image_get_path(lw));
1249 }
1250
1251 static void layout_bar_exif_destroyed(GtkWidget *widget, gpointer data)
1252 {
1253         LayoutWindow *lw = data;
1254
1255         if (lw->bar_exif)
1256                 {
1257                 lw->bar_exif_advanced = bar_exif_is_advanced(lw->bar_exif);
1258                 }
1259
1260         lw->bar_exif = NULL;
1261         if (lw->utility_box)
1262                 {
1263                 /* destroyed from within itself */
1264                 lw->bar_exif_enabled = FALSE;
1265                 layout_util_sync_views(lw);
1266                 }
1267 }
1268
1269 static void layout_bar_exif_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1270 {
1271         LayoutWindow *lw = data;
1272
1273         if (lw->bar_exif)
1274                 {
1275                 lw->bar_exif_size = allocation->width;
1276                 }
1277 }
1278
1279 static void layout_bar_exif_new(LayoutWindow *lw)
1280 {
1281         if (!lw->utility_box) return;
1282
1283         lw->bar_exif = bar_exif_new(TRUE, layout_image_get_path(lw),
1284                                     lw->bar_exif_advanced, lw->utility_box);
1285         g_signal_connect(G_OBJECT(lw->bar_exif), "destroy",
1286                          G_CALLBACK(layout_bar_exif_destroyed), lw);
1287         g_signal_connect(G_OBJECT(lw->bar_exif), "size_allocate",
1288                          G_CALLBACK(layout_bar_exif_sized), lw);
1289         lw->bar_exif_enabled = TRUE;
1290
1291         if (lw->bar_exif_size < 1) lw->bar_exif_size = SIDEBAR_WIDTH;
1292         gtk_widget_set_size_request(lw->bar_exif, lw->bar_exif_size, -1);
1293         gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar_exif, FALSE, FALSE, 0);
1294         if (lw->bar_info) gtk_box_reorder_child(GTK_BOX(lw->utility_box), lw->bar_exif, 1);
1295         gtk_widget_show(lw->bar_exif);
1296 }
1297
1298 static void layout_bar_exif_close(LayoutWindow *lw)
1299 {
1300         if (lw->bar_exif)
1301                 {
1302                 bar_exif_close(lw->bar_exif);
1303                 lw->bar_exif = NULL;
1304                 }
1305         lw->bar_exif_enabled = FALSE;
1306 }
1307
1308 void layout_bar_exif_toggle(LayoutWindow *lw)
1309 {
1310         if (lw->bar_exif_enabled)
1311                 {
1312                 layout_bar_exif_close(lw);
1313                 }
1314         else
1315                 {
1316                 layout_bar_exif_new(lw);
1317                 }
1318 }
1319
1320 static void layout_bar_exif_new_image(LayoutWindow *lw)
1321 {
1322         if (!lw->bar_exif || !lw->bar_exif_enabled) return;
1323
1324         bar_exif_set(lw->bar_exif, layout_image_get_path(lw));
1325 }
1326
1327 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
1328 {
1329         LayoutWindow *lw = data;
1330
1331         lw->bar_sort = NULL;
1332
1333         if (lw->utility_box)
1334                 {
1335                 /* destroyed from within itself */
1336                 lw->bar_sort_enabled = FALSE;
1337
1338                 layout_util_sync_views(lw);
1339                 }
1340 }
1341
1342 static void layout_bar_sort_new(LayoutWindow *lw)
1343 {
1344         if (!lw->utility_box) return;
1345
1346         lw->bar_sort = bar_sort_new(lw);
1347         g_signal_connect(G_OBJECT(lw->bar_sort), "destroy",
1348                          G_CALLBACK(layout_bar_sort_destroyed), lw);
1349         lw->bar_sort_enabled = TRUE;
1350
1351         gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0);
1352         gtk_widget_show(lw->bar_sort);
1353 }
1354
1355 static void layout_bar_sort_close(LayoutWindow *lw)
1356 {
1357         if (lw->bar_sort)
1358                 {
1359                 bar_sort_close(lw->bar_sort);
1360                 lw->bar_sort = NULL;
1361                 }
1362         lw->bar_sort_enabled = FALSE;
1363 }
1364
1365 void layout_bar_sort_toggle(LayoutWindow *lw)
1366 {
1367         if (lw->bar_sort_enabled)
1368                 {
1369                 layout_bar_sort_close(lw);
1370                 }
1371         else
1372                 {
1373                 layout_bar_sort_new(lw);
1374                 }
1375 }
1376
1377 void layout_bars_new_image(LayoutWindow *lw)
1378 {
1379         layout_bar_info_new_image(lw);
1380         layout_bar_exif_new_image(lw);
1381 }
1382
1383 void layout_bars_new_selection(LayoutWindow *lw, gint count)
1384 {
1385         layout_bar_info_new_selection(lw, count);
1386 }
1387
1388 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
1389 {
1390         lw->utility_box = gtk_hbox_new(FALSE, PREF_PAD_GAP);
1391         gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
1392         gtk_widget_show(image);
1393
1394         if (lw->bar_sort_enabled)
1395                 {
1396                 layout_bar_sort_new(lw);
1397                 }
1398
1399         if (lw->bar_info_enabled)
1400                 {
1401                 layout_bar_info_new(lw);
1402                 }
1403
1404         if (lw->bar_exif_enabled)
1405                 {
1406                 layout_bar_exif_new(lw);
1407                 }
1408
1409         return lw->utility_box;
1410 }
1411
1412 void layout_bars_close(LayoutWindow *lw)
1413 {
1414         layout_bar_sort_close(lw);
1415         layout_bar_exif_close(lw);
1416         layout_bar_info_close(lw);
1417 }
1418
1419 void layout_bars_maint_renamed(LayoutWindow *lw)
1420 {
1421         layout_bar_info_maint_renamed(lw);
1422 }
1423