simplified config writing
authorVladimir Nadvornik <nadvornik@suse.cz>
Mon, 23 Feb 2009 22:13:09 +0000 (22:13 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Mon, 23 Feb 2009 22:13:09 +0000 (22:13 +0000)
src/bar.c
src/bar_comment.c
src/bar_exif.c
src/bar_histogram.c
src/bar_keywords.c
src/filefilter.c
src/layout.c
src/rcfile.c
src/rcfile.h

index ba7520e..15f23a0 100644 (file)
--- a/src/bar.c
+++ b/src/bar.c
@@ -156,8 +156,7 @@ void bar_write_config(GtkWidget *bar, GString *outstr, gint indent)
        bd = g_object_get_data(G_OBJECT(bar), "bar_data");
        if (!bd) return;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<bar>\n");
+       WRITE_STRING("<bar>\n");
 
        list = gtk_container_get_children(GTK_CONTAINER(bd->vbox));     
        work = list;
@@ -177,8 +176,7 @@ void bar_write_config(GtkWidget *bar, GString *outstr, gint indent)
                }
        g_list_free(list);
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "</bar>\n");
+       WRITE_STRING("</bar>\n");
 }
 
 
index 6ccbbbb..60e4416 100644 (file)
@@ -151,16 +151,14 @@ static void bar_pane_comment_write_config(GtkWidget *pane, GString *outstr, gint
        pcd = g_object_get_data(G_OBJECT(pane), "pane_data");
        if (!pcd) return;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<pane_comment\n");
+       WRITE_STRING("<pane_comment\n");
        indent++;
        WRITE_CHAR(*pcd, pane.title);
        WRITE_BOOL(*pcd, pane.expanded);
        WRITE_CHAR(*pcd, key);
        WRITE_INT(*pcd, height); 
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "/>\n");
+       WRITE_STRING("/>\n");
 }
 
 static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data)
index a9d5aa2..0afa00a 100644 (file)
@@ -289,14 +289,12 @@ static void bar_pane_exif_write_config(GtkWidget *pane, GString *outstr, gint in
        ped = g_object_get_data(G_OBJECT(pane), "pane_data");
        if (!ped) return;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<pane_exif\n");
+       WRITE_STRING("<pane_exif\n");
        indent++;
        WRITE_CHAR(*ped, pane.title);
        WRITE_BOOL(*ped, pane.expanded);
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "/>\n");
+       WRITE_STRING("/>\n");
 }
 
 
index 9c209fc..8a8ac32 100644 (file)
@@ -84,14 +84,12 @@ static void bar_pane_histogram_write_config(GtkWidget *pane, GString *outstr, gi
        phd = g_object_get_data(G_OBJECT(pane), "pane_data");
        if (!phd) return;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<pane_histogram\n");
+       WRITE_STRING("<pane_histogram\n");
        indent++;
        WRITE_CHAR(*phd, pane.title);
        WRITE_BOOL(*phd, pane.expanded);
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "/>\n");
+       WRITE_STRING("/>\n");
 }
 
 
index bca93af..4e95f84 100644 (file)
@@ -482,15 +482,13 @@ static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gin
        pkd = g_object_get_data(G_OBJECT(pane), "pane_data");
        if (!pkd) return;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<pane_keywords\n");
+       WRITE_STRING("<pane_keywords\n");
        indent++;
        WRITE_CHAR(*pkd, pane.title);
        WRITE_BOOL(*pkd, pane.expanded);
        WRITE_CHAR(*pkd, key);
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "/>\n");
+       WRITE_STRING("/>\n");
 }
 
 gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event)
index aca7f40..b120e9f 100644 (file)
@@ -425,8 +425,7 @@ void filter_write_list(GString *outstr, gint indent)
 {
        GList *work;
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<filter>\n");
+       WRITE_STRING("<filter>\n");
        indent++;
 
        work = filter_list;
@@ -435,8 +434,7 @@ void filter_write_list(GString *outstr, gint indent)
                FilterEntry *fe = work->data;
                work = work->next;
 
-               write_indent(outstr, indent);
-               g_string_append_printf(outstr, "<file_type\n");
+               WRITE_STRING("<file_type\n");
                indent++;
                WRITE_CHAR(*fe, key);
                WRITE_BOOL(*fe, enabled);
@@ -446,12 +444,10 @@ void filter_write_list(GString *outstr, gint indent)
                WRITE_BOOL(*fe, writable);
                WRITE_BOOL(*fe, allow_sidecar);
                indent--;
-               write_indent(outstr, indent);
-               g_string_append_printf(outstr, "/>\n");
+               WRITE_STRING("/>\n");
                }
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "</filter>\n");
+       WRITE_STRING("</filter>\n");
 }
 
 void filter_load_file_type(const gchar **attribute_names, const gchar **attribute_values)
index d451999..956ddf7 100644 (file)
@@ -2174,16 +2174,13 @@ void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent
 void layout_write_config(LayoutWindow *lw, GString *outstr, gint indent)
 {
        layout_sync_options_with_current_state(lw);
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<layout\n");
+       WRITE_STRING("<layout\n");
        layout_write_attributes(&lw->options, outstr, indent + 1);
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, ">\n");
+       WRITE_STRING(">\n");
 
        bar_write_config(lw->bar, outstr, indent + 1);
        
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "</layout>\n");
+       WRITE_STRING("</layout>\n");
 }
 
 void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values)
index f563fa9..1779ad2 100644 (file)
@@ -447,8 +447,7 @@ static void write_color_profile(GString *outstr, gint indent)
                            "         color profile options will have no effect.\n-->\n", GQ_APPNAME);
 #endif
 
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<color_profiles\n");
+       WRITE_STRING("<color_profiles\n");
        indent++;
        WRITE_INT(options->color_profile, screen_type);
        WRITE_CHAR(options->color_profile, screen_file);
@@ -456,24 +455,20 @@ static void write_color_profile(GString *outstr, gint indent)
        WRITE_BOOL(options->color_profile, use_image);
        WRITE_INT(options->color_profile, input_type);
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, ">\n");
+       WRITE_STRING(">\n");
 
        indent++;
        for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
                {
-               write_indent(outstr, indent);
-               g_string_append_printf(outstr, "<profile\n");
+               WRITE_STRING("<profile\n");
                indent++;
                write_char_option(outstr, indent, "input_file", options->color_profile.input_file[i]);
                write_char_option(outstr, indent, "input_name", options->color_profile.input_name[i]);
                indent--;
-               write_indent(outstr, indent);
-               g_string_append_printf(outstr, "/>\n");
+               WRITE_STRING("/>\n");
                }
        indent--;
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "</color_profiles>\n");
+       WRITE_STRING("</color_profiles>\n");
 }
 
 
@@ -507,16 +502,16 @@ gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
        g_string_append_printf(outstr, "######################################################################\n");
        WRITE_SEPARATOR();
 
-       g_string_append_printf(outstr, "# Note: This file is autogenerated. Options can be changed here,\n");
-       g_string_append_printf(outstr, "#       but user comments and formatting will be lost.\n");
+       WRITE_STRING("# Note: This file is autogenerated. Options can be changed here,\n");
+       WRITE_STRING("#       but user comments and formatting will be lost.\n");
        WRITE_SEPARATOR();
-       g_string_append_printf(outstr, "-->\n");
+       WRITE_STRING("-->\n");
        WRITE_SEPARATOR();
-       g_string_append_printf(outstr, "<global\n");
+       WRITE_STRING("<global\n");
+       write_global_attributes(outstr, indent + 1);
+       WRITE_STRING(">\n");
+
        indent++;
-       write_global_attributes(outstr, indent);
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, ">\n");
 
        write_color_profile(outstr, indent);
 
@@ -525,14 +520,12 @@ gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
 
        WRITE_SEPARATOR();
        WRITE_SUBTITLE("Layout Options - defaults");
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "<layout\n");
+       WRITE_STRING("<layout\n");
        layout_write_attributes(&options->layout, outstr, indent + 1);
-       write_indent(outstr, indent);
-       g_string_append_printf(outstr, "/>\n");
+       WRITE_STRING("/>\n");
 
        indent--;
-       g_string_append_printf(outstr, "</global>\n");
+       WRITE_STRING("</global>\n");
 
        WRITE_SEPARATOR();
        WRITE_SUBTITLE("Layout Options");
index a46f6ca..7d942db 100644 (file)
@@ -40,7 +40,7 @@ gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *
 
 #define WRITE_SEPARATOR() g_string_append(outstr, "\n")
 #define WRITE_SUBTITLE(_title_) g_string_append_printf(outstr, "\n\n<!-- "_title_" -->\n\n")
-
+#define WRITE_STRING(_str_) {write_indent(outstr, indent);g_string_append_printf(outstr, _str_);}
 
 #define READ_BOOL(target, _name_) if (read_bool_option(option, #_name_, value, &(target)._name_)) continue;
 #define READ_INT(target, _name_) if (read_int_option(option, #_name_, value, &(target)._name_)) continue;