From 1bef8f7ea39aa7652ded34fd2baaa3bf6c28e69d Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Mon, 23 Feb 2009 22:13:09 +0000 Subject: [PATCH] simplified config writing --- src/bar.c | 6 ++---- src/bar_comment.c | 6 ++---- src/bar_exif.c | 6 ++---- src/bar_histogram.c | 6 ++---- src/bar_keywords.c | 6 ++---- src/filefilter.c | 12 ++++-------- src/layout.c | 9 +++------ src/rcfile.c | 37 +++++++++++++++---------------------- src/rcfile.h | 2 +- 9 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/bar.c b/src/bar.c index ba7520e1..15f23a0e 100644 --- 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, "\n"); + WRITE_STRING("\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, "\n"); + WRITE_STRING("\n"); } diff --git a/src/bar_comment.c b/src/bar_comment.c index 6ccbbbba..60e44166 100644 --- a/src/bar_comment.c +++ b/src/bar_comment.c @@ -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, "\n"); + WRITE_STRING("/>\n"); } static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data) diff --git a/src/bar_exif.c b/src/bar_exif.c index a9d5aa23..0afa00a5 100644 --- a/src/bar_exif.c +++ b/src/bar_exif.c @@ -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, "\n"); + WRITE_STRING("/>\n"); } diff --git a/src/bar_histogram.c b/src/bar_histogram.c index 9c209fc7..8a8ac328 100644 --- a/src/bar_histogram.c +++ b/src/bar_histogram.c @@ -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, "\n"); + WRITE_STRING("/>\n"); } diff --git a/src/bar_keywords.c b/src/bar_keywords.c index bca93afe..4e95f84b 100644 --- a/src/bar_keywords.c +++ b/src/bar_keywords.c @@ -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, "\n"); + WRITE_STRING("/>\n"); } gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event) diff --git a/src/filefilter.c b/src/filefilter.c index aca7f401..b120e9f7 100644 --- a/src/filefilter.c +++ b/src/filefilter.c @@ -425,8 +425,7 @@ void filter_write_list(GString *outstr, gint indent) { GList *work; - write_indent(outstr, indent); - g_string_append_printf(outstr, "\n"); + WRITE_STRING("\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, "\n"); + WRITE_STRING("/>\n"); } indent--; - write_indent(outstr, indent); - g_string_append_printf(outstr, "\n"); + WRITE_STRING("\n"); } void filter_load_file_type(const gchar **attribute_names, const gchar **attribute_values) diff --git a/src/layout.c b/src/layout.c index d451999f..956ddf7e 100644 --- a/src/layout.c +++ b/src/layout.c @@ -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, "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, "\n"); + WRITE_STRING("\n"); } void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values) diff --git a/src/rcfile.c b/src/rcfile.c index f563fa95..1779ad25 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -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_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, "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, "\n"); + WRITE_STRING("\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, "\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, outstr, indent + 1); - write_indent(outstr, indent); - g_string_append_printf(outstr, "/>\n"); + WRITE_STRING("/>\n"); indent--; - g_string_append_printf(outstr, "\n"); + WRITE_STRING("\n"); WRITE_SEPARATOR(); WRITE_SUBTITLE("Layout Options"); diff --git a/src/rcfile.h b/src/rcfile.h index a46f6caf..7d942db5 100644 --- a/src/rcfile.h +++ b/src/rcfile.h @@ -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\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; -- 2.20.1