simplified and improved bar configuration
authorVladimir Nadvornik <nadvornik@suse.cz>
Tue, 24 Feb 2009 20:34:39 +0000 (20:34 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Tue, 24 Feb 2009 20:34:39 +0000 (20:34 +0000)
src/bar.c
src/bar.h
src/layout.c
src/layout_image.c
src/layout_util.c
src/layout_util.h
src/options.c
src/rcfile.c
src/typedefs.h

index 15f23a0..9d45e09 100644 (file)
--- a/src/bar.c
+++ b/src/bar.c
@@ -43,6 +43,7 @@ struct _BarData
 
        GList *(*list_func)(gpointer);
        gpointer list_data;
+       gint width;
 };
 
 static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up)
@@ -156,7 +157,12 @@ void bar_write_config(GtkWidget *bar, GString *outstr, gint indent)
        bd = g_object_get_data(G_OBJECT(bar), "bar_data");
        if (!bd) return;
 
-       WRITE_STRING("<bar>\n");
+       WRITE_STRING("<bar\n");
+       indent++;
+       write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar));
+       write_uint_option(outstr, indent, "width", bd->width);
+       indent--;
+       WRITE_STRING(">\n");
 
        list = gtk_container_get_children(GTK_CONTAINER(bd->vbox));     
        work = list;
@@ -250,7 +256,7 @@ void bar_add(GtkWidget *bar, GtkWidget *pane)
 
 }
 
-void bar_populate_default(GtkWidget *bar)
+static void bar_populate_default(GtkWidget *bar)
 {
        GtkWidget *widget;
        widget = bar_pane_histogram_new(_("Histogram"), 80, TRUE);
@@ -269,6 +275,13 @@ void bar_populate_default(GtkWidget *bar)
        bar_add(bar, widget);
 }
 
+static void bar_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+{
+       BarData *bd = data;
+       bd->width = allocation->width;
+}
+
+
 static void bar_width(BarData *bd, gint val)
 {
        gint size;
@@ -277,7 +290,6 @@ static void bar_width(BarData *bd, gint val)
        size = CLAMP(size + val, BAR_SIZE_INCREMENT * 2, BAR_SIZE_INCREMENT * 16);
 
        gtk_widget_set_size_request(bd->widget, size, -1);
-       options->layout.panels.info.width = bd->widget->allocation.width;
 }
 
 static void bar_larger(GtkWidget *widget, gpointer data)
@@ -329,6 +341,12 @@ GtkWidget *bar_new(GtkWidget *bounding_widget)
        g_signal_connect(G_OBJECT(bd->widget), "destroy",
                         G_CALLBACK(bar_destroy), bd);
 
+       g_signal_connect(G_OBJECT(bd->widget), "size_allocate",
+                        G_CALLBACK(bar_sized), bd);
+
+       bd->width = PANEL_DEFAULT_WIDTH;
+       gtk_widget_set_size_request(bd->widget, bd->width, -1);
+
        box = gtk_hbox_new(FALSE, 0);
 
        sizer = sizer_new(bd->widget, bounding_widget, SIZER_POS_LEFT);
@@ -388,5 +406,40 @@ GtkWidget *bar_new(GtkWidget *bounding_widget)
        return bd->widget;
 }
 
+GtkWidget *bar_new_default(GtkWidget *bounding_widget)
+{
+       GtkWidget *bar = bar_new(bounding_widget);
+       
+       bar_populate_default(bar);
+       
+       gtk_widget_show(bar);
+       
+       return bar;
+}
+
+GtkWidget *bar_new_from_config(GtkWidget *bounding_widget, const gchar **attribute_names, const gchar **attribute_values)
+{
+       GtkWidget *bar = bar_new(bounding_widget);
+       
+       gboolean enabled = TRUE;
+       gint width = PANEL_DEFAULT_WIDTH;
+
+       while (*attribute_names)
+               {
+               const gchar *option = *attribute_names++;
+               const gchar *value = *attribute_values++;
+
+               if (READ_BOOL_FULL("enabled", enabled)) continue;
+               if (READ_INT_FULL("width", width)) continue;
+               
+
+               DEBUG_1("unknown attribute %s = %s", option, value);
+               }
+       
+       gtk_widget_set_size_request(bar, width, -1);
+       if (enabled) gtk_widget_show(bar);
+       return bar;
+}
+
 
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 35b4674..1764d7f 100644 (file)
--- a/src/bar.h
+++ b/src/bar.h
@@ -31,8 +31,8 @@ struct _PaneData {
 
 
 GtkWidget *bar_new(GtkWidget *bounding_widget);
-
-void bar_populate_default(GtkWidget *bar);
+GtkWidget *bar_new_default(GtkWidget *bounding_widget);
+GtkWidget *bar_new_from_config(GtkWidget *bounding_widget, const gchar **attribute_names, const gchar **attribute_values);
 
 void bar_close(GtkWidget *bar);
 
index 2493774..43c58db 100644 (file)
@@ -2023,7 +2023,6 @@ LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop,
                lw->options.main_window.hdivider_pos = MAIN_WINDOW_DIV_HPOS;
                lw->options.main_window.vdivider_pos = MAIN_WINDOW_DIV_VPOS;
                lw->options.float_window.vdivider_pos = MAIN_WINDOW_DIV_VPOS;
-               lw->options.panels.info.width = PANEL_DEFAULT_WIDTH;
                }
 
        /* window */
@@ -2159,10 +2158,6 @@ void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent
 
        WRITE_BOOL(*layout, toolbar_hidden);
 
-       WRITE_BOOL(*layout, panels.exif.enabled);
-       WRITE_INT(*layout, panels.exif.width);
-       WRITE_BOOL(*layout, panels.info.enabled);
-       WRITE_INT(*layout, panels.info.width);
        WRITE_BOOL(*layout, panels.sort.enabled);
        WRITE_INT(*layout, panels.sort.action_state);
        WRITE_INT(*layout, panels.sort.mode_state);
@@ -2230,10 +2225,6 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names
                if (READ_BOOL(*layout, toolbar_hidden)) continue;
 
                /* panels */
-               if (READ_BOOL(*layout, panels.exif.enabled)) continue;
-               if (READ_INT_CLAMP(*layout, panels.exif.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH)) continue;
-               if (READ_BOOL(*layout, panels.info.enabled)) continue;
-               if (READ_INT_CLAMP(*layout, panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH)) continue;
                if (READ_BOOL(*layout, panels.sort.enabled)) continue;
                if (READ_INT(*layout, panels.sort.action_state)) continue;
                if (READ_INT(*layout, panels.sort.mode_state)) continue;
index 93fa860..280ef1c 100644 (file)
@@ -1759,7 +1759,6 @@ static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
        if (fd == layout_image_get_fd(lw))
                {
                image_set_fd(lw->image, fd);
-               layout_bars_maint_renamed(lw);
                }
 }
 
index 270e26b..874dfd9 100644 (file)
@@ -49,6 +49,7 @@
 
 #define MENU_EDIT_ACTION_OFFSET 16
 
+static gboolean layout_bar_enabled(LayoutWindow *lw);
 
 /*
  *-----------------------------------------------------------------------------
@@ -669,7 +670,7 @@ static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
 
        layout_exit_fullscreen(lw);
 
-       if (lw->options.panels.info.enabled == gtk_toggle_action_get_active(action)) return;
+       if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return;
        layout_bar_toggle(lw);
 }
 
@@ -1862,7 +1863,7 @@ static void layout_util_sync_views(LayoutWindow *lw)
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
 
        action = gtk_action_group_get_action(lw->action_group, "SBar");
-       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.info.enabled);
+       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw));
 
        action = gtk_action_group_get_action(lw->action_group, "SBarSort");
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.sort.enabled);
@@ -1941,18 +1942,22 @@ void folder_icons_free(PixmapFolders *pf)
  *-----------------------------------------------------------------------------
  */
 
+static gboolean layout_bar_enabled(LayoutWindow *lw)
+{
+       return lw->bar && GTK_WIDGET_VISIBLE(lw->bar);
+}
+
 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
 
        lw->bar = NULL;
+/* 
+    do not call layout_util_sync_views(lw) here
+    this is called either when whole layout is destroyed - no need for update
+    or when the bar is replaced - sync is called by upper function at the end of whole operation
 
-       if (lw->utility_box)
-               {
-               /* destroyed from within itself */
-               lw->options.panels.info.enabled = FALSE;
-               layout_util_sync_views(lw);
-               }
+*/
 }
 
 static GList *layout_bar_list_cb(gpointer data)
@@ -1962,96 +1967,78 @@ static GList *layout_bar_list_cb(gpointer data)
        return layout_selection_list(lw);
 }
 
-static void layout_bar_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+static void layout_bar_set_default(LayoutWindow *lw)
 {
-       LayoutWindow *lw = data;
-
-       if (!lw->bar) return;
+       GtkWidget *bar;
        
-       lw->options.panels.info.width = allocation->width;
-}
-
-void layout_bar_new(LayoutWindow *lw, gboolean populate)
-{
        if (!lw->utility_box) return;
 
-       if (!lw->bar)
-               {
-               lw->bar = bar_new(lw->utility_box);
-
-               if (populate)
-                       {
-                       bar_populate_default(lw->bar);
-                       }
-
-               bar_set_selection_func(lw->bar, layout_bar_list_cb, lw);
-               g_signal_connect(G_OBJECT(lw->bar), "destroy",
-                                G_CALLBACK(layout_bar_destroyed), lw);
-               g_signal_connect(G_OBJECT(lw->bar), "size_allocate",
-                                G_CALLBACK(layout_bar_sized), lw);
-
-
-               gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
-               }
-
-       lw->options.panels.info.enabled  = TRUE;
-       gtk_widget_set_size_request(lw->bar, lw->options.panels.info.width, -1);
-       bar_set_fd(lw->bar, layout_image_get_fd(lw));
-       gtk_widget_show(lw->bar);
+       bar = bar_new_default(lw->utility_box);
+       
+       layout_bar_set(lw, bar);
 }
 
-void layout_bar_close(LayoutWindow *lw)
+static void layout_bar_close(LayoutWindow *lw)
 {
        if (lw->bar)
                {
                bar_close(lw->bar);
                lw->bar = NULL;
                }
-       lw->options.panels.info.enabled = FALSE;
 }
 
-static void layout_bar_hide(LayoutWindow *lw)
+
+void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
 {
-       if (lw->bar)
-               {
-               gtk_widget_hide(lw->bar);
-               }
-       lw->options.panels.info.enabled = FALSE;
+       if (!lw->utility_box) return;
+
+       layout_bar_close(lw); /* if any */
+
+       if (!bar) return;
+       lw->bar = bar;
+
+       bar_set_selection_func(lw->bar, layout_bar_list_cb, lw);
+       g_signal_connect(G_OBJECT(lw->bar), "destroy",
+                        G_CALLBACK(layout_bar_destroyed), lw);
+
+
+       gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
+
+       bar_set_fd(lw->bar, layout_image_get_fd(lw));
 }
 
+
 void layout_bar_toggle(LayoutWindow *lw)
 {
-       if (lw->options.panels.info.enabled)
+       if (layout_bar_enabled(lw))
                {
-               layout_bar_hide(lw);
+               gtk_widget_hide(lw->bar);
                }
        else
                {
-               layout_bar_new(lw, TRUE);
+               if (!lw->bar)
+                       {
+                       layout_bar_set_default(lw);
+                       }
+               gtk_widget_show(lw->bar);
                }
+       layout_util_sync_views(lw);
 }
 
 static void layout_bar_new_image(LayoutWindow *lw)
 {
-       if (!lw->bar || !lw->options.panels.info.enabled) return;
+       if (!layout_bar_enabled(lw)) return;
 
        bar_set_fd(lw->bar, layout_image_get_fd(lw));
 }
 
 static void layout_bar_new_selection(LayoutWindow *lw, gint count)
 {
-       if (!lw->bar || !lw->options.panels.info.enabled) return;
+       if (!layout_bar_enabled(lw)) return;
 
 //     bar_info_selection(lw->bar_info, count - 1);
 }
 
-static void layout_bar_maint_renamed(LayoutWindow *lw)
-{
-       if (!lw->bar || !lw->options.panels.info.enabled) return;
-
-//     bar_maint_renamed(lw->bar_info, layout_image_get_fd(lw));
-}
-
 static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
@@ -2129,11 +2116,6 @@ GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
                layout_bar_sort_new(lw);
                }
 
-       if (lw->options.panels.info.enabled)
-               {
-               layout_bar_new(lw, TRUE);
-               }
-
        return lw->utility_box;
 }
 
@@ -2143,11 +2125,6 @@ void layout_bars_close(LayoutWindow *lw)
        layout_bar_close(lw);
 }
 
-void layout_bars_maint_renamed(LayoutWindow *lw)
-{
-       layout_bar_maint_renamed(lw);
-}
-
 static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
 {
        LayoutWindow *lw = data;
index 3bea967..a118cd2 100644 (file)
@@ -45,8 +45,7 @@ void folder_icons_free(PixmapFolders *pf);
 
 
 void layout_bar_toggle(LayoutWindow *lw);
-void layout_bar_new(LayoutWindow *lw, gboolean populate);
-void layout_bar_close(LayoutWindow *lw);
+void layout_bar_set(LayoutWindow *lw, GtkWidget *bar);
 
 void layout_bar_exif_toggle(LayoutWindow *lw);
 void layout_bar_sort_toggle(LayoutWindow *lw);
@@ -57,8 +56,6 @@ void layout_bars_new_selection(LayoutWindow *lw, gint count);
 GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image);
 void layout_bars_close(LayoutWindow *lw);
 
-void layout_bars_maint_renamed(LayoutWindow *lw);
-
 void layout_exif_window_new(LayoutWindow *lw);
 
 #endif
index 38175de..871229d 100644 (file)
@@ -120,10 +120,6 @@ ConfOptions *init_options(ConfOptions *options)
        options->open_recent_list_maxsize = 10;
        options->place_dialogs_under_mouse = FALSE;
 
-       options->layout.panels.exif.enabled = FALSE;
-       options->layout.panels.exif.width = PANEL_DEFAULT_WIDTH;
-       options->layout.panels.info.enabled = FALSE;
-       options->layout.panels.info.width = PANEL_DEFAULT_WIDTH;
        options->layout.panels.sort.action_state = 0;
        options->layout.panels.sort.enabled = FALSE;
        options->layout.panels.sort.mode_state = 0;
index 2212dbe..f8b480b 100644 (file)
@@ -877,9 +877,8 @@ static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext
        LayoutWindow *lw = data;
        if (g_ascii_strcasecmp(element_name, "bar") == 0)
                {
-               if (lw->bar) 
-                       layout_bar_close(lw);
-               layout_bar_new(lw, FALSE);
+               GtkWidget *bar = bar_new_from_config(lw->utility_box, attribute_names, attribute_values);
+               layout_bar_set(lw, bar);
                options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar);
                }
        else
@@ -889,6 +888,12 @@ static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext
                }
 }
 
+static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error)
+{
+       LayoutWindow *lw = data;
+       layout_util_sync(lw);
+}
+
 static void options_parse_toplevel(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error)
 {
        if (g_ascii_strcasecmp(element_name, "global") == 0)
@@ -909,7 +914,7 @@ static void options_parse_toplevel(GQParserData *parser_data, GMarkupParseContex
                {
                LayoutWindow *lw;
                lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup);
-               options_parse_func_push(parser_data, options_parse_layout, NULL, lw);
+               options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw);
                }
        else
                {
index 100db05..57a5e11 100644 (file)
@@ -516,16 +516,6 @@ struct _LayoutOptions
 
        /* panels */
        struct {
-               struct {
-                       gboolean enabled;
-                       gint width;
-               } info;
-
-               struct {
-                       gboolean enabled;
-                       gint width;
-               } exif;
-
                struct {
                        gboolean enabled;
                        gint mode_state;