Mercurial > geeqie
changeset 1309:55ea4962887a
config file format changed to XML
save and restore all layout windows
save and restore sidebar configuration
author | nadvornik |
---|---|
date | Sun, 22 Feb 2009 15:35:37 +0000 |
parents | 2320339ca8be |
children | ef05743535e3 |
files | src/bar.c src/bar.h src/bar_comment.c src/bar_comment.h src/bar_exif.c src/bar_exif.h src/bar_histogram.c src/bar_histogram.h src/bar_keywords.c src/bar_keywords.h src/bar_sort.c src/filefilter.c src/filefilter.h src/img-view.c src/layout.c src/layout.h src/layout_image.c src/layout_util.c src/layout_util.h src/main.c src/main.h src/options.c src/options.h src/rcfile.c src/rcfile.h src/typedefs.h src/view_file.c |
diffstat | 27 files changed, 1685 insertions(+), 1053 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar.c Sun Feb 22 15:35:37 2009 +0000 @@ -27,6 +27,7 @@ #include "bar_keywords.h" #include "bar_exif.h" #include "bar_histogram.h" +#include "rcfile.h" #define BAR_SIZE_INCREMENT 48 #define BAR_ARROW_SIZE 7 @@ -147,6 +148,40 @@ return ret; } +void bar_write_config(GtkWidget *bar, GString *outstr, gint indent) +{ + BarData *bd; + GList *list, *work; + if (!bar) return; + bd = g_object_get_data(G_OBJECT(bar), "bar_data"); + if (!bd) return; + + write_indent(outstr, indent); + g_string_append_printf(outstr, "<bar>\n"); + + list = gtk_container_get_children(GTK_CONTAINER(bd->vbox)); + work = list; + while (work) + { + GtkWidget *expander = work->data; + GtkWidget *widget = gtk_bin_get_child(GTK_BIN(expander)); + PaneData *pd = g_object_get_data(G_OBJECT(widget), "pane_data"); + if (!pd) continue; + + pd->expanded = gtk_expander_get_expanded(GTK_EXPANDER(expander)); + + if (pd->pane_write_config) + pd->pane_write_config(widget, outstr, indent + 1); + + work = work->next; + } + g_list_free(list); + + write_indent(outstr, indent); + g_string_append_printf(outstr, "</bar>\n"); +} + + void bar_pane_set_selection_func(GtkWidget *pane, GList *(*list_func)(gpointer data), gpointer data) { PaneData *pd; @@ -187,7 +222,7 @@ -static void bar_add(GtkWidget *bar, GtkWidget *pane) +void bar_add(GtkWidget *bar, GtkWidget *pane) { GtkWidget *expander; GtkWidget *label; @@ -208,7 +243,7 @@ gtk_container_add(GTK_CONTAINER(expander), pane); - gtk_expander_set_expanded(GTK_EXPANDER(expander), TRUE); + gtk_expander_set_expanded(GTK_EXPANDER(expander), pd->expanded); gtk_widget_show(expander); @@ -217,6 +252,25 @@ } +void bar_populate_default(GtkWidget *bar) +{ + GtkWidget *widget; + widget = bar_pane_histogram_new(_("Histogram"), 80, TRUE); + bar_add(bar, widget); + + widget = bar_pane_comment_new(_("Title"), "Xmp.dc.title", TRUE, 40); + bar_add(bar, widget); + + widget = bar_pane_keywords_new(_("Keywords"), KEYWORD_KEY, TRUE); + bar_add(bar, widget); + + widget = bar_pane_comment_new(_("Comment"), "Xmp.dc.description", TRUE, 150); + bar_add(bar, widget); + + widget = bar_pane_exif_new(_("Exif"), TRUE); + bar_add(bar, widget); +} + static void bar_width(BarData *bd, gint val) { gint size; @@ -225,7 +279,7 @@ size = CLAMP(size + val, BAR_SIZE_INCREMENT * 2, BAR_SIZE_INCREMENT * 16); gtk_widget_set_size_request(bd->widget, size, -1); - options->panels.info.width = bd->widget->allocation.width; + options->layout.panels.info.width = bd->widget->allocation.width; } static void bar_larger(GtkWidget *widget, gpointer data) @@ -269,7 +323,6 @@ GtkWidget *button; GtkWidget *arrow; GtkWidget *scrolled; - GtkWidget *widget; bd = g_new0(BarData, 1); @@ -334,25 +387,8 @@ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_NONE); gtk_widget_show(bd->vbox); - - widget = bar_pane_histogram_new(_("Histogram"), 80); - bar_add(bd->widget, widget); - - widget = bar_pane_comment_new(_("Title"), "Xmp.dc.title", 40); - bar_add(bd->widget, widget); - - widget = bar_pane_keywords_new(_("Keywords"), KEYWORD_KEY); - bar_add(bd->widget, widget); - - widget = bar_pane_comment_new(_("Comment"), "Xmp.dc.description", 150); - bar_add(bd->widget, widget); - - widget = bar_pane_exif_new(_("Exif")); - bar_add(bd->widget, widget); - return bd->widget; } - /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar.h Sun Feb 22 15:35:37 2009 +0000 @@ -19,7 +19,9 @@ struct _PaneData { void (*pane_set_fd)(GtkWidget *pane, FileData *fd); gint (*pane_event)(GtkWidget *pane, GdkEvent *event); + void (*pane_write_config)(GtkWidget *pane, GString *outstr, gint indent); gchar *title; + gboolean expanded; GList *(*list_func)(gpointer); gpointer list_data; @@ -29,8 +31,16 @@ GtkWidget *bar_new(GtkWidget *bounding_widget); + +void bar_populate_default(GtkWidget *bar); + void bar_close(GtkWidget *bar); +void bar_write_config(GtkWidget *bar, GString *outstr, gint indent); + +void bar_add(GtkWidget *bar, GtkWidget *pane); + + void bar_set_fd(GtkWidget *bar, FileData *fd); gint bar_event(GtkWidget *bar, GdkEvent *event);
--- a/src/bar_comment.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_comment.c Sun Feb 22 15:35:37 2009 +0000 @@ -19,6 +19,7 @@ #include "filedata.h" #include "ui_menu.h" #include "ui_misc.h" +#include "rcfile.h" static void bar_pane_comment_changed(GtkTextBuffer *buffer, gpointer data); @@ -38,6 +39,7 @@ GtkWidget *comment_view; FileData *fd; gchar *key; + gint height; }; @@ -130,7 +132,7 @@ bar_pane_comment_update(pcd); } -gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event) +static gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event) { PaneCommentData *pcd; @@ -142,6 +144,25 @@ return FALSE; } +static void bar_pane_comment_write_config(GtkWidget *pane, GString *outstr, gint indent) +{ + PaneCommentData *pcd; + + 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"); + 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"); +} + static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data) { PaneCommentData *pcd = data; @@ -193,7 +214,7 @@ } -GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gint height) +GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gboolean expanded, gint height) { PaneCommentData *pcd; GtkWidget *scrolled; @@ -203,9 +224,12 @@ pcd->pane.pane_set_fd = bar_pane_comment_set_fd; pcd->pane.pane_event = bar_pane_comment_event; + pcd->pane.pane_write_config = bar_pane_comment_write_config; pcd->pane.title = g_strdup(title); + pcd->pane.expanded = expanded; pcd->key = g_strdup(key); + pcd->height = height; scrolled = gtk_scrolled_window_new(NULL, NULL); @@ -237,4 +261,28 @@ return pcd->widget; } +GtkWidget *bar_pane_comment_new_from_config(const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *title = g_strdup(_("NoName")); + gchar *key = g_strdup(COMMENT_KEY); + gboolean expanded = TRUE; + gint height = 50; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + READ_CHAR_FULL("pane.title", title); + READ_CHAR_FULL("key", key); + READ_BOOL_FULL("pane.expanded", expanded); + READ_INT_FULL("height", height); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + return bar_pane_comment_new(title, key, expanded, height); +} + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_comment.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_comment.h Sun Feb 22 15:35:37 2009 +0000 @@ -14,7 +14,8 @@ #ifndef BAR_COMMENT_H #define BAR_COMMENT_H -GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gint height); +GtkWidget *bar_pane_comment_new(const gchar *title, const gchar *key, gboolean expanded, gint height); +GtkWidget *bar_pane_comment_new_from_config(const gchar **attribute_names, const gchar **attribute_values); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_exif.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_exif.c Sun Feb 22 15:35:37 2009 +0000 @@ -21,6 +21,7 @@ #include "misc.h" #include "ui_misc.h" #include "bar.h" +#include "rcfile.h" #include <math.h> @@ -281,6 +282,24 @@ bar_pane_exif_update(ped); } +static void bar_pane_exif_write_config(GtkWidget *pane, GString *outstr, gint indent) +{ + PaneExifData *ped; + + 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"); + indent++; + WRITE_CHAR(*ped, pane.title); + WRITE_BOOL(*ped, pane.expanded); + indent--; + write_indent(outstr, indent); + g_string_append_printf(outstr, "/>\n"); +} + + static void bar_pane_exif_remove_advanced_cb(GtkWidget *widget, gpointer data) { PaneExifData *ped = data; @@ -317,7 +336,7 @@ g_free(ped); } -GtkWidget *bar_pane_exif_new(const gchar *title) +GtkWidget *bar_pane_exif_new(const gchar *title, gboolean expanded) { PaneExifData *ped; GtkWidget *table; @@ -332,7 +351,9 @@ ped = g_new0(PaneExifData, 1); ped->pane.pane_set_fd = bar_pane_exif_set_fd; + ped->pane.pane_write_config = bar_pane_exif_write_config; ped->pane.title = g_strdup(title); + ped->pane.expanded = expanded; ped->keys = g_new0(GtkWidget *, exif_len); ped->labels = g_new0(GtkWidget *, exif_len); @@ -395,4 +416,26 @@ return ped->vbox; } + +GtkWidget *bar_pane_exif_new_from_config(const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *title = g_strdup(_("NoName")); + gboolean expanded = TRUE; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + READ_CHAR_FULL("pane.title", title); + READ_BOOL_FULL("pane.expanded", expanded); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + return bar_pane_exif_new(title, expanded); +} + + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_exif.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_exif.h Sun Feb 22 15:35:37 2009 +0000 @@ -30,8 +30,8 @@ #define EXIF_BAR_CUSTOM_COUNT 20 -GtkWidget *bar_pane_exif_new(const gchar *title); - +GtkWidget *bar_pane_exif_new(const gchar *title, gboolean expanded); +GtkWidget *bar_pane_exif_new_from_config(const gchar **attribute_names, const gchar **attribute_values); /* these are exposed for when duplication of the exif bar's text is needed */
--- a/src/bar_histogram.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_histogram.c Sun Feb 22 15:35:37 2009 +0000 @@ -20,6 +20,7 @@ #include "ui_menu.h" #include "ui_misc.h" #include "histogram.h" +#include "rcfile.h" /* *------------------------------------------------------------------- @@ -76,6 +77,24 @@ bar_pane_histogram_update(phd); } +static void bar_pane_histogram_write_config(GtkWidget *pane, GString *outstr, gint indent) +{ + PaneHistogramData *phd; + + 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"); + indent++; + WRITE_CHAR(*phd, pane.title); + WRITE_BOOL(*phd, pane.expanded); + indent--; + write_indent(outstr, indent); + g_string_append_printf(outstr, "/>\n"); +} + + static void bar_pane_histogram_notify_cb(FileData *fd, NotifyType type, gpointer data) { PaneHistogramData *phd = data; @@ -131,14 +150,16 @@ } -GtkWidget *bar_pane_histogram_new(const gchar *title, gint height) +GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded) { PaneHistogramData *phd; phd = g_new0(PaneHistogramData, 1); phd->pane.pane_set_fd = bar_pane_histogram_set_fd; + phd->pane.pane_write_config = bar_pane_histogram_write_config; phd->pane.title = g_strdup(title); + phd->pane.expanded = expanded; phd->histogram = histogram_new(); @@ -169,4 +190,26 @@ return phd->widget; } +GtkWidget *bar_pane_histogram_new_from_config(const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *title = g_strdup(_("NoName")); + gboolean expanded = TRUE; + gint height = 80; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + READ_CHAR_FULL("pane.title", title); + READ_BOOL_FULL("pane.expanded", expanded); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + return bar_pane_histogram_new(title, height, expanded); +} + + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_histogram.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_histogram.h Sun Feb 22 15:35:37 2009 +0000 @@ -14,7 +14,8 @@ #ifndef BAR_HISTOGRAM_H #define BAR_HISTOGRAM_H -GtkWidget *bar_pane_histogram_new(const gchar *title, gint height); +GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gboolean expanded); +GtkWidget *bar_pane_histogram_new_from_config(const gchar **attribute_names, const gchar **attribute_values); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_keywords.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_keywords.c Sun Feb 22 15:35:37 2009 +0000 @@ -25,6 +25,7 @@ #include "utilops.h" #include "bar.h" #include "ui_menu.h" +#include "rcfile.h" static const gchar *keyword_favorite_defaults[] = { N_("Favorite"), @@ -474,6 +475,24 @@ bar_pane_keywords_update(pkd); } +static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gint indent) +{ + PaneKeywordsData *pkd; + + 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"); + 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"); +} + gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event) { PaneKeywordsData *pkd; @@ -707,7 +726,7 @@ return GTK_TREE_MODEL(model); } -GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key) +GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key, gboolean expanded) { PaneKeywordsData *pkd; GtkWidget *hbox; @@ -721,7 +740,9 @@ pkd->pane.pane_set_fd = bar_pane_keywords_set_fd; pkd->pane.pane_event = bar_pane_keywords_event; + pkd->pane.pane_write_config = bar_pane_keywords_write_config; pkd->pane.title = g_strdup(title); + pkd->pane.expanded = expanded; pkd->key = g_strdup(key); @@ -807,4 +828,27 @@ return pkd->widget; } + +GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *title = g_strdup(_("NoName")); + gchar *key = g_strdup(COMMENT_KEY); + gboolean expanded = TRUE; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + READ_CHAR_FULL("pane.title", title); + READ_CHAR_FULL("key", key); + READ_BOOL_FULL("pane.expanded", expanded); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + return bar_pane_keywords_new(title, key, expanded); +} + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_keywords.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_keywords.h Sun Feb 22 15:35:37 2009 +0000 @@ -14,8 +14,8 @@ #ifndef BAR_KEYWORDS_H #define BAR_KEYWORDS_H -GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key); - +GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key, gboolean expanded); +GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values); /* used in search.c */ GList *keyword_list_pull(GtkWidget *text_widget);
--- a/src/bar_sort.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/bar_sort.c Sun Feb 22 15:35:37 2009 +0000 @@ -171,7 +171,7 @@ { bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION); } - options->panels.sort.mode_state = sd->mode; + options->layout.panels.sort.mode_state = sd->mode; } /* this takes control of src_list */ @@ -351,19 +351,19 @@ static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key) { - options->panels.sort.action_state = sd->action = action; + options->layout.panels.sort.action_state = sd->action = action; if (action == BAR_SORT_FILTER) { if (!filter_key) filter_key = ""; sd->filter_key = filter_key; - g_free(options->panels.sort.action_filter); - options->panels.sort.action_filter = g_strdup(filter_key); + g_free(options->layout.panels.sort.action_filter); + options->layout.panels.sort.action_filter = g_strdup(filter_key); } else { sd->filter_key = NULL; - g_free(options->panels.sort.action_filter); - options->panels.sort.action_filter = g_strdup(""); + g_free(options->layout.panels.sort.action_filter); + options->layout.panels.sort.action_filter = g_strdup(""); } } @@ -393,7 +393,7 @@ static void bar_sort_set_selection(SortData *sd, SortSelectionType selection) { - options->panels.sort.selection_state = sd->selection = selection; + options->layout.panels.sort.selection_state = sd->selection = selection; } static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data) @@ -572,14 +572,14 @@ sd->lw = lw; - mode = CLAMP(options->panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1); - sd->action = CLAMP(options->panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1); + mode = CLAMP(options->layout.panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1); + sd->action = CLAMP(options->layout.panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1); if (sd->action == BAR_SORT_FILTER && - (!options->panels.sort.action_filter || !options->panels.sort.action_filter[0])) + (!options->layout.panels.sort.action_filter || !options->layout.panels.sort.action_filter[0])) sd->action = BAR_SORT_COPY; - sd->selection = CLAMP(options->panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1); + sd->selection = CLAMP(options->layout.panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1); sd->undo_src = NULL; sd->undo_dest = NULL; @@ -625,7 +625,7 @@ if (!editor_is_filter(editor->key)) continue; - if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, options->panels.sort.action_filter) == 0) + if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, options->layout.panels.sort.action_filter) == 0) { bar_sort_set_action(sd, sd->action, editor->key); select = TRUE;
--- a/src/filefilter.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/filefilter.c Sun Feb 22 15:35:37 2009 +0000 @@ -19,6 +19,7 @@ #include "secure_save.h" #include "thumb_standard.h" #include "ui_fileops.h" +#include "rcfile.h" /* *----------------------------------------------------------------------------- @@ -420,72 +421,73 @@ return filter_name_find(file_sidecar_list, name); } -void filter_write_list(SecureSaveInfo *ssi) +void filter_write_list(GString *outstr, gint indent) { GList *work; + write_indent(outstr, indent); + g_string_append_printf(outstr, "<filter>\n"); + indent++; + work = filter_list; while (work) { FilterEntry *fe = work->data; work = work->next; - gchar *extensions = escquote_value(fe->extensions); - gchar *description = escquote_value(fe->description); - - secure_fprintf(ssi, "file_filter.ext: \"%s%s\" %s %s %d %d %d\n", - (fe->enabled) ? "" : "#", - fe->key, extensions, description, fe->file_class, fe->writable, fe->allow_sidecar); - g_free(extensions); - g_free(description); + write_indent(outstr, indent); + g_string_append_printf(outstr, "<file_type\n"); + indent++; + WRITE_CHAR(*fe, key); + WRITE_BOOL(*fe, enabled); + WRITE_CHAR(*fe, extensions); + WRITE_CHAR(*fe, description); + WRITE_UINT(*fe, file_class); + WRITE_BOOL(*fe, writable); + WRITE_BOOL(*fe, allow_sidecar); + indent--; + write_indent(outstr, indent); + g_string_append_printf(outstr, "/>\n"); } + indent--; + write_indent(outstr, indent); + g_string_append_printf(outstr, "</filter>\n"); } -void filter_parse(const gchar *text) +void filter_load_file_type(const gchar **attribute_names, const gchar **attribute_values) { - const gchar *p; - gchar *key; - gchar *ext; - gchar *desc; - gint enabled = TRUE; - guint file_class = FORMAT_CLASS_UNKNOWN; - gboolean writable = TRUE; - gboolean allow_sidecar = TRUE; - - if (!text || text[0] != '"') return; - - key = quoted_value(text, &p); - if (!key) return; - - ext = quoted_value(p, &p); - desc = quoted_value(p, &p); - - sscanf(p, "%u %d %d", &file_class, &writable, &allow_sidecar); - - if (file_class >= FILE_FORMAT_CLASSES) file_class = FORMAT_CLASS_UNKNOWN; + FilterEntry fe; + FilterEntry *old_fe; + memset(&fe, 0, sizeof(fe)); + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; - if (key && key[0] == '#') - { - gchar *tmp; - tmp = g_strdup(key + 1); - g_free(key); - key = tmp; - - enabled = FALSE; - } + READ_CHAR(fe, key); + READ_BOOL(fe, enabled); + READ_CHAR(fe, extensions); + READ_CHAR(fe, description); + READ_UINT(fe, file_class); + READ_BOOL(fe, writable); + READ_BOOL(fe, allow_sidecar); - if (key && strlen(key) > 0 && ext) + printf("unknown attribute %s = %s\n", option, value); + } + if (fe.file_class >= FILE_FORMAT_CLASSES) fe.file_class = FORMAT_CLASS_UNKNOWN; + + if (fe.key && fe.key[0] != 0) { - FilterEntry *fe = filter_get_by_key(key); + old_fe = filter_get_by_key(fe.key); - if (fe != NULL) filter_remove_entry(fe); - filter_add(key, desc, ext, file_class, writable, allow_sidecar, enabled); + if (old_fe != NULL) filter_remove_entry(old_fe); + filter_add(fe.key, fe.description, fe.extensions, fe.file_class, fe.writable, fe.allow_sidecar, fe.enabled); } + g_free(fe.key); + g_free(fe.extensions); + g_free(fe.description); +} - g_free(key); - g_free(ext); - g_free(desc); -} /* *-----------------------------------------------------------------------------
--- a/src/filefilter.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/filefilter.h Sun Feb 22 15:35:37 2009 +0000 @@ -42,8 +42,9 @@ gboolean filter_name_is_writable(const gchar *name); gboolean filter_name_allow_sidecar(const gchar *name); -void filter_write_list(SecureSaveInfo *ssi); -void filter_parse(const gchar *text); +void filter_write_list(GString *outstr, gint indent); +void filter_load_file_type(const gchar **attribute_names, const gchar **attribute_values); + void sidecar_ext_parse(const gchar *text, gboolean quoted); gchar *sidecar_ext_to_string(void);
--- a/src/img-view.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/img-view.c Sun Feb 22 15:35:37 2009 +0000 @@ -1219,7 +1219,7 @@ { LayoutWindow *nw; - nw = layout_new(NULL, FALSE, FALSE); + nw = layout_new(NULL, NULL); layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending); layout_set_fd(nw, fd); return nw;
--- a/src/layout.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/layout.c Sun Feb 22 15:35:37 2009 +0000 @@ -33,6 +33,8 @@ #include "ui_tabcomp.h" #include "window.h" #include "metadata.h" +#include "rcfile.h" +#include "bar.h" #ifdef HAVE_LIRC #include "lirc.h" @@ -217,7 +219,7 @@ lw->toolbar = layout_button_bar(lw); gtk_box_pack_start(GTK_BOX(box), lw->toolbar, FALSE, FALSE, 0); - if (!lw->toolbar_hidden) gtk_widget_show(lw->toolbar); + if (!lw->options.toolbar_hidden) gtk_widget_show(lw->toolbar); tabcomp = tab_completion_new_with_history(&lw->path_entry, NULL, "path_list", -1, layout_path_entry_cb, lw); @@ -229,7 +231,7 @@ g_signal_connect(G_OBJECT(lw->path_entry->parent), "changed", G_CALLBACK(layout_path_entry_changed_cb), lw); - lw->vd = vd_new(lw->dir_view_type, lw->dir_fd); + lw->vd = vd_new(lw->options.dir_view_type, lw->dir_fd); vd_set_layout(lw->vd, lw); vd_set_select_func(lw->vd, layout_vd_select_cb, lw); @@ -845,14 +847,14 @@ vf_set_status_func(lw->vf, layout_list_status_cb, lw); vf_set_thumb_status_func(lw->vf, layout_list_thumb_cb, lw); - vf_marks_set(lw->vf, lw->marks_enabled); + vf_marks_set(lw->vf, lw->options.show_marks); switch (lw->file_view_type) { case FILEVIEW_ICON: break; case FILEVIEW_LIST: - vf_thumb_set(lw->vf, lw->thumbs_enabled); + vf_thumb_set(lw->vf, lw->options.show_thumbnails); break; } @@ -861,12 +863,12 @@ static void layout_list_sync_thumb(LayoutWindow *lw) { - if (lw->vf) vf_thumb_set(lw->vf, lw->thumbs_enabled); + if (lw->vf) vf_thumb_set(lw->vf, lw->options.show_thumbnails); } static void layout_list_sync_marks(LayoutWindow *lw) { - if (lw->vf) vf_marks_set(lw->vf, lw->marks_enabled); + if (lw->vf) vf_marks_set(lw->vf, lw->options.show_marks); } static void layout_list_scroll_to_subpart(LayoutWindow *lw, const gchar *needle) @@ -1134,9 +1136,9 @@ { if (!layout_valid(&lw)) return; - if (lw->thumbs_enabled == enable) return; - - lw->thumbs_enabled = enable; + if (lw->options.show_thumbnails == enable) return; + + lw->options.show_thumbnails = enable; layout_util_sync_thumb(lw); layout_list_sync_thumb(lw); @@ -1146,9 +1148,9 @@ { if (!layout_valid(&lw)) return; - if (lw->marks_enabled == enable) return; - - lw->marks_enabled = enable; + if (lw->options.show_marks == enable) return; + + lw->options.show_marks = enable; // layout_util_sync_marks(lw); layout_list_sync_marks(lw); @@ -1158,14 +1160,14 @@ { if (!layout_valid(&lw)) return FALSE; - return lw->thumbs_enabled; + return lw->options.show_thumbnails; } gint layout_marks_get(LayoutWindow *lw) { if (!layout_valid(&lw)) return FALSE; - return lw->marks_enabled; + return lw->options.show_marks; } void layout_sort_set(LayoutWindow *lw, SortType type, gint ascend) @@ -1209,18 +1211,18 @@ { *h = GTK_PANED(lw->h_pane)->child1->allocation.width; } - else if (h != &lw->div_h) + else if (h != &lw->options.main_window.hdivider_pos) { - *h = lw->div_h; + *h = lw->options.main_window.hdivider_pos; } if (lw->v_pane && GTK_PANED(lw->v_pane)->child1->allocation.x >= 0) { *v = GTK_PANED(lw->v_pane)->child1->allocation.height; } - else if (v != &lw->div_v) + else if (v != &lw->options.main_window.vdivider_pos) { - *v = lw->div_v; + *v = lw->options.main_window.vdivider_pos; } return TRUE; @@ -1230,9 +1232,9 @@ { if (!layout_valid(&lw)) return; - if (lw->dir_view_type == dir_view_type && lw->file_view_type == file_view_type) return; - - lw->dir_view_type = dir_view_type; + if (lw->options.dir_view_type == dir_view_type && lw->file_view_type == file_view_type) return; + + lw->options.dir_view_type = dir_view_type; lw->file_view_type = file_view_type; layout_style_set(lw, -1, NULL); @@ -1242,7 +1244,7 @@ { if (!layout_valid(&lw)) return FALSE; - *dir_view_type = lw->dir_view_type; + *dir_view_type = lw->options.dir_view_type; *file_view_type = lw->file_view_type; return TRUE; @@ -1316,7 +1318,7 @@ { /* use the stored values (sort of breaks success return value) */ - *divider_pos = lw->div_float; + *divider_pos = lw->options.float_window.vdivider_pos; return FALSE; } @@ -1339,7 +1341,7 @@ static void layout_tools_geometry_sync(LayoutWindow *lw) { layout_geometry_get_tools(lw, &options->layout.float_window.x, &options->layout.float_window.x, - &options->layout.float_window.w, &options->layout.float_window.h, &lw->div_float); + &options->layout.float_window.w, &options->layout.float_window.h, &lw->options.float_window.vdivider_pos); } static void layout_tools_hide(LayoutWindow *lw, gint hide) @@ -1363,7 +1365,7 @@ } } - lw->tools_hidden = hide; + lw->options.tools_hidden = hide; } static gint layout_tools_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) @@ -1482,15 +1484,15 @@ { if (vertical) { - lw->div_float = MAIN_WINDOW_DIV_VPOS; + lw->options.float_window.vdivider_pos = MAIN_WINDOW_DIV_VPOS; } else { - lw->div_float = MAIN_WINDOW_DIV_HPOS; + lw->options.float_window.vdivider_pos = MAIN_WINDOW_DIV_HPOS; } } - gtk_paned_set_position(GTK_PANED(lw->tools_pane), lw->div_float); + gtk_paned_set_position(GTK_PANED(lw->tools_pane), lw->options.float_window.vdivider_pos); } /* @@ -1597,7 +1599,7 @@ image = layout_bars_prepare(lw, image); - if (lw->tools_float || lw->tools_hidden) + if (lw->options.tools_float || lw->options.tools_hidden) { gtk_box_pack_start(GTK_BOX(lw->group_box), image, TRUE, TRUE, 0); gtk_widget_show(image); @@ -1660,7 +1662,7 @@ gtk_widget_show(h); /* fix to have image pane visible when it is left and priority widget */ - if (lw->div_h == -1 && + if (lw->options.main_window.hdivider_pos == -1 && w1 == image && !layout_location_vertical(priority_location) && layout_location_first(priority_location)) @@ -1668,8 +1670,8 @@ gtk_widget_set_size_request(image, 200, -1); } - gtk_paned_set_position(GTK_PANED(lw->h_pane), lw->div_h); - gtk_paned_set_position(GTK_PANED(lw->v_pane), lw->div_v); + gtk_paned_set_position(GTK_PANED(lw->h_pane), lw->options.main_window.hdivider_pos); + gtk_paned_set_position(GTK_PANED(lw->v_pane), lw->options.main_window.vdivider_pos); gtk_widget_grab_focus(lw->image->widget); } @@ -1707,7 +1709,7 @@ lw->image = NULL; lw->utility_box = NULL; - layout_geometry_get_dividers(lw, &lw->div_h, &lw->div_v); + layout_geometry_get_dividers(lw, &lw->options.main_window.hdivider_pos, &lw->options.main_window.vdivider_pos); /* clear it all */ @@ -1751,7 +1753,7 @@ /* re-fill */ layout_grid_setup(lw); - layout_tools_hide(lw, lw->tools_hidden); + layout_tools_hide(lw, lw->options.tools_hidden); layout_util_sync(lw); layout_status_update_all(lw); @@ -1766,7 +1768,7 @@ { layout_set_fd(lw, dir_fd); } - image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden)); + image_top_window_set_sync(lw->image, (lw->options.tools_float || lw->options.tools_hidden)); /* clean up */ @@ -1808,25 +1810,25 @@ if (!lw) return; - if (!lw->tools_hidden) + if (!lw->options.tools_hidden) { - popped = !lw->tools_float; + popped = !lw->options.tools_float; } else { popped = TRUE; } - if (lw->tools_float == popped) + if (lw->options.tools_float == popped) { - if (popped && lw->tools_hidden) + if (popped && lw->options.tools_hidden) { layout_tools_float_set(lw, popped, FALSE); } } else { - if (lw->tools_float) + if (lw->options.tools_float) { layout_tools_float_set(lw, FALSE, FALSE); } @@ -1841,23 +1843,23 @@ { if (!lw) return; - layout_tools_float_set(lw, lw->tools_float, !lw->tools_hidden); + layout_tools_float_set(lw, lw->options.tools_float, !lw->options.tools_hidden); } void layout_tools_float_set(LayoutWindow *lw, gint popped, gint hidden) { if (!layout_valid(&lw)) return; - if (lw->tools_float == popped && lw->tools_hidden == hidden) return; - - if (lw->tools_float == popped && lw->tools_float && lw->tools) + if (lw->options.tools_float == popped && lw->options.tools_hidden == hidden) return; + + if (lw->options.tools_float == popped && lw->options.tools_float && lw->tools) { layout_tools_hide(lw, hidden); return; } - lw->tools_float = popped; - lw->tools_hidden = hidden; + lw->options.tools_float = popped; + lw->options.tools_hidden = hidden; layout_style_set(lw, -1, NULL); } @@ -1866,8 +1868,8 @@ { if (!layout_valid(&lw)) return FALSE; - *popped = lw->tools_float; - *hidden = lw->tools_hidden; + *popped = lw->options.tools_float; + *hidden = lw->options.tools_hidden; return TRUE; } @@ -1877,9 +1879,9 @@ if (!layout_valid(&lw)) return; if (!lw->toolbar) return; - lw->toolbar_hidden = !lw->toolbar_hidden; - - if (lw->toolbar_hidden) + lw->options.toolbar_hidden = !lw->options.toolbar_hidden; + + if (lw->options.toolbar_hidden) { if (GTK_WIDGET_VISIBLE(lw->toolbar)) gtk_widget_hide(lw->toolbar); } @@ -1893,7 +1895,7 @@ { if (!layout_valid(&lw)) return TRUE; - return lw->toolbar_hidden; + return lw->options.toolbar_hidden; } /* @@ -1902,6 +1904,32 @@ *----------------------------------------------------------------------------- */ +void layout_sync_options_with_current_state(LayoutWindow *lw) +{ + if (!layout_valid(&lw)) return; + + lw->options.main_window.maximized = window_maximized(lw->window); + if (!lw->options.main_window.maximized) + { + layout_geometry_get(lw, &lw->options.main_window.x, &lw->options.main_window.y, + &lw->options.main_window.w, &lw->options.main_window.h); + } + + layout_geometry_get_dividers(lw, &lw->options.main_window.hdivider_pos, &lw->options.main_window.vdivider_pos); + +// layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending); + + layout_geometry_get_tools(lw, &lw->options.float_window.x, &lw->options.float_window.y, + &lw->options.float_window.w, &lw->options.float_window.h, &lw->options.float_window.vdivider_pos); + +// if (options->startup.restore_path && options->startup.use_last_path) +// { +// g_free(options->startup.path); +// options->startup.path = g_strdup(layout_get_path(NULL)); +// } +} + + void layout_close(LayoutWindow *lw) { if (layout_window_list && layout_window_list->next) @@ -1936,6 +1964,7 @@ file_data_unref(lw->dir_fd); } + free_layout_options_content(&lw->options); g_free(lw); } @@ -1947,12 +1976,12 @@ return TRUE; } -LayoutWindow *layout_new(FileData *dir_fd, gint popped, gint hidden) +LayoutWindow *layout_new(FileData *dir_fd, LayoutOptions *lop) { - return layout_new_with_geometry(dir_fd, popped, hidden, NULL); + return layout_new_with_geometry(dir_fd, lop, NULL); } -LayoutWindow *layout_new_with_geometry(FileData *dir_fd, gint popped, gint hidden, +LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop, const gchar *geometry) { LayoutWindow *lw; @@ -1961,48 +1990,40 @@ lw = g_new0(LayoutWindow, 1); - lw->thumbs_enabled = options->layout.show_thumbnails; - lw->marks_enabled = options->layout.show_marks; + if (lop) + copy_layout_options(&lw->options, lop); + else + copy_layout_options(&lw->options, &options->layout); + lw->sort_method = SORT_NAME; lw->sort_ascend = TRUE; - lw->tools_float = popped; - lw->tools_hidden = hidden; - - lw->toolbar_hidden = options->layout.toolbar_hidden; +// lw->options.tools_float = popped; +// lw->options.tools_hidden = hidden; lw->utility_box = NULL; lw->bar_sort = NULL; - lw->bar_sort_enabled = options->panels.sort.enabled; +// lw->bar_sort_enabled = options->panels.sort.enabled; lw->bar = NULL; - lw->bar_enabled = options->panels.info.enabled; +// lw->bar_enabled = options->panels.info.enabled; lw->exif_window = NULL; /* default layout */ - layout_config_parse(options->layout.style, options->layout.order, + layout_config_parse(lw->options.style, lw->options.order, &lw->dir_location, &lw->file_location, &lw->image_location); - lw->dir_view_type = options->layout.dir_view_type; - if (lw->dir_view_type >= VIEW_DIR_TYPES_COUNT) lw->dir_view_type = 0; - lw->file_view_type = options->layout.file_view_type; - if (lw->file_view_type >= VIEW_FILE_TYPES_COUNT) lw->file_view_type = 0; + if (lw->options.dir_view_type >= VIEW_DIR_TYPES_COUNT) lw->options.dir_view_type = 0; + if (lw->options.file_view_type >= VIEW_FILE_TYPES_COUNT) lw->options.file_view_type = 0; /* divider positions */ - if (options->layout.save_window_positions) + if (!lw->options.save_window_positions) { - lw->div_h = options->layout.main_window.hdivider_pos; - lw->div_v = options->layout.main_window.vdivider_pos; - lw->div_float = options->layout.float_window.vdivider_pos; - lw->bar_width = options->panels.info.width; - } - else - { - lw->div_h = MAIN_WINDOW_DIV_HPOS; - lw->div_v = MAIN_WINDOW_DIV_VPOS; - lw->div_float = MAIN_WINDOW_DIV_VPOS; - lw->bar_width = PANEL_DEFAULT_WIDTH; + 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 */ @@ -2011,7 +2032,7 @@ gtk_window_set_resizable(GTK_WINDOW(lw->window), TRUE); gtk_container_set_border_width(GTK_CONTAINER(lw->window), 0); - if (options->layout.save_window_positions) + if (lw->options.save_window_positions) { hint_mask = GDK_HINT_USER_POS; } @@ -2027,14 +2048,14 @@ gtk_window_set_geometry_hints(GTK_WINDOW(lw->window), NULL, &hint, GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE | hint_mask); - if (options->layout.save_window_positions) + if (lw->options.save_window_positions) { - gtk_window_set_default_size(GTK_WINDOW(lw->window), options->layout.main_window.w, options->layout.main_window.h); - if (!layout_window_list) - { - gtk_window_move(GTK_WINDOW(lw->window), options->layout.main_window.x, options->layout.main_window.y); - if (options->layout.main_window.maximized) gtk_window_maximize(GTK_WINDOW(lw->window)); - } + gtk_window_set_default_size(GTK_WINDOW(lw->window), lw->options.main_window.w, lw->options.main_window.h); +// if (!layout_window_list) +// { + gtk_window_move(GTK_WINDOW(lw->window), lw->options.main_window.x, lw->options.main_window.y); + if (lw->options.main_window.maximized) gtk_window_maximize(GTK_WINDOW(lw->window)); +// } } else { @@ -2055,7 +2076,7 @@ gtk_widget_show(lw->main_box); layout_grid_setup(lw); - image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden)); + image_top_window_set_sync(lw->image, (lw->options.tools_float || lw->options.tools_hidden)); layout_util_sync(lw); layout_status_update_all(lw); @@ -2085,7 +2106,7 @@ } gtk_widget_show(lw->window); - layout_tools_hide(lw, lw->tools_hidden); + layout_tools_hide(lw, lw->options.tools_hidden); layout_window_list = g_list_append(layout_window_list, lw); @@ -2094,4 +2115,154 @@ return lw; } +void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent) +{ + WRITE_INT(*layout, style); + WRITE_CHAR(*layout, order); + WRITE_UINT(*layout, dir_view_type); + WRITE_UINT(*layout, file_view_type); + WRITE_BOOL(*layout, show_marks); + WRITE_BOOL(*layout, show_thumbnails); + WRITE_BOOL(*layout, show_directory_date); + WRITE_CHAR(*layout, home_path); + WRITE_SEPARATOR(); + + WRITE_BOOL(*layout, save_window_positions); + WRITE_SEPARATOR(); + + WRITE_INT(*layout, main_window.x); + WRITE_INT(*layout, main_window.y); + WRITE_INT(*layout, main_window.w); + WRITE_INT(*layout, main_window.h); + WRITE_BOOL(*layout, main_window.maximized); + WRITE_INT(*layout, main_window.hdivider_pos); + WRITE_INT(*layout, main_window.vdivider_pos); + WRITE_SEPARATOR(); + + WRITE_INT(*layout, float_window.x); + WRITE_INT(*layout, float_window.y); + WRITE_INT(*layout, float_window.w); + WRITE_INT(*layout, float_window.h); + WRITE_INT(*layout, float_window.vdivider_pos); + WRITE_SEPARATOR(); + + WRITE_INT(*layout, properties_window.w); + WRITE_INT(*layout, properties_window.h); + WRITE_SEPARATOR(); + + WRITE_BOOL(*layout, tools_float); + WRITE_BOOL(*layout, tools_hidden); + WRITE_BOOL(*layout, tools_restore_state); + WRITE_SEPARATOR(); + + 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); + WRITE_INT(*layout, panels.sort.selection_state); + WRITE_CHAR(*layout, panels.sort.action_filter); +} + + +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"); + layout_write_attributes(&lw->options, outstr, indent + 1); + write_indent(outstr, indent); + g_string_append_printf(outstr, ">\n"); + + bar_write_config(lw->bar, outstr, indent + 1); + + write_indent(outstr, indent); + g_string_append_printf(outstr, "</layout>\n"); +} + +void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values) +{ + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + /* layout options */ + + READ_INT(*layout, style); + READ_CHAR(*layout, order); + + READ_UINT(*layout, dir_view_type); + READ_UINT(*layout, file_view_type); + READ_BOOL(*layout, show_marks); + READ_BOOL(*layout, show_thumbnails); + READ_BOOL(*layout, show_directory_date); + READ_CHAR(*layout, home_path); + + /* window positions */ + + READ_BOOL(*layout, save_window_positions); + + READ_INT(*layout, main_window.x); + READ_INT(*layout, main_window.y); + READ_INT(*layout, main_window.w); + READ_INT(*layout, main_window.h); + READ_BOOL(*layout, main_window.maximized); + READ_INT(*layout, main_window.hdivider_pos); + READ_INT(*layout, main_window.vdivider_pos); + + READ_INT(*layout, float_window.x); + READ_INT(*layout, float_window.y); + READ_INT(*layout, float_window.w); + READ_INT(*layout, float_window.h); + READ_INT(*layout, float_window.vdivider_pos); + + READ_INT(*layout, properties_window.w); + READ_INT(*layout, properties_window.h); + + READ_BOOL(*layout, tools_float); + READ_BOOL(*layout, tools_hidden); + READ_BOOL(*layout, tools_restore_state); + READ_BOOL(*layout, toolbar_hidden); + + /* panels */ + READ_BOOL(*layout, panels.exif.enabled); + READ_INT_CLAMP(*layout, panels.exif.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); + READ_BOOL(*layout, panels.info.enabled); + READ_INT_CLAMP(*layout, panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); + READ_BOOL(*layout, panels.sort.enabled); + READ_INT(*layout, panels.sort.action_state); + READ_INT(*layout, panels.sort.mode_state); + READ_INT(*layout, panels.sort.selection_state); + READ_CHAR(*layout, panels.sort.action_filter); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + +} + + +LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar **attribute_values) +{ + LayoutOptions lop; + LayoutWindow *lw; + memset(&lop, 0, sizeof(LayoutOptions)); + copy_layout_options(&lop, &options->layout); + + layout_load_attributes(&lop, attribute_names, attribute_values); + lw = layout_new(NULL, &lop); + layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending); + layout_set_path(lw, get_current_dir()); // FIXME: use options / cmdline + + free_layout_options_content(&lop); + return lw; +} + + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/layout.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/layout.h Sun Feb 22 15:35:37 2009 +0000 @@ -17,15 +17,22 @@ extern GList *layout_window_list; -LayoutWindow *layout_new(FileData *dir_fd, gint popped, gint hidden); -LayoutWindow *layout_new_with_geometry(FileData *dir_fd, gint popped, gint hidden, +LayoutWindow *layout_new(FileData *dir_fd, LayoutOptions *lop); +LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop, const gchar *geometry); +LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar **attribute_values); void layout_close(LayoutWindow *lw); void layout_free(LayoutWindow *lw); gint layout_valid(LayoutWindow **lw); +void layout_sync_options_with_current_state(LayoutWindow *lw); +void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values); +void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent); +void layout_write_config(LayoutWindow *lw, GString *outstr, gint indent); + + LayoutWindow *layout_find_by_image(ImageWindow *imd); LayoutWindow *layout_find_by_image_fd(ImageWindow *imd);
--- a/src/layout_image.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/layout_image.c Sun Feb 22 15:35:37 2009 +0000 @@ -543,7 +543,7 @@ menu_item_add_divider(menu); - item = menu_item_add_check(menu, _("Hide file _list"), lw->tools_hidden, + item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden, G_CALLBACK(li_pop_menu_hide_cb), lw); if (fullscreen) gtk_widget_set_sensitive(item, FALSE); @@ -1580,7 +1580,7 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n) { - gboolean frame = (n == 1) ? (!lw->tools_float && !lw->tools_hidden) : 1; + gboolean frame = (n == 1) ? (!lw->options.tools_float && !lw->options.tools_hidden) : 1; gint i; for (i = 0; i < n; i++)
--- a/src/layout_util.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/layout_util.c Sun Feb 22 15:35:37 2009 +0000 @@ -97,7 +97,7 @@ return TRUE; } } - if (lw->vd && lw->dir_view_type == DIRVIEW_TREE && GTK_WIDGET_HAS_FOCUS(lw->vd->view) && + if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && GTK_WIDGET_HAS_FOCUS(lw->vd->view) && !layout_key_match(event->keyval) && gtk_widget_event(lw->vd->view, (GdkEvent *)event)) { @@ -194,7 +194,7 @@ layout_exit_fullscreen(lw); - nw = layout_new(NULL, FALSE, FALSE); + nw = layout_new(NULL, NULL); layout_sort_set(nw, options->file_sort.method, options->file_sort.ascending); layout_set_fd(nw, lw->dir_fd); } @@ -569,7 +569,7 @@ LayoutWindow *lw = data; layout_exit_fullscreen(lw); - layout_views_set(lw, lw->dir_view_type, (gtk_radio_action_get_current_value(action) == 1) ? FILEVIEW_ICON : FILEVIEW_LIST); + layout_views_set(lw, lw->options.dir_view_type, (gtk_radio_action_get_current_value(action) == 1) ? FILEVIEW_ICON : FILEVIEW_LIST); } static void layout_menu_view_dir_as_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data) @@ -641,7 +641,7 @@ layout_exit_fullscreen(lw); - if (lw->tools_float == gtk_toggle_action_get_active(action)) return; + if (lw->options.tools_float == gtk_toggle_action_get_active(action)) return; layout_tools_float_toggle(lw); } @@ -659,7 +659,7 @@ layout_exit_fullscreen(lw); - if (lw->toolbar_hidden == gtk_toggle_action_get_active(action)) return; + if (lw->options.toolbar_hidden == gtk_toggle_action_get_active(action)) return; layout_toolbar_toggle(lw); } @@ -669,7 +669,7 @@ layout_exit_fullscreen(lw); - if (lw->bar_enabled == gtk_toggle_action_get_active(action)) return; + if (lw->options.panels.info.enabled == gtk_toggle_action_get_active(action)) return; layout_bar_toggle(lw); } @@ -688,7 +688,7 @@ layout_exit_fullscreen(lw); - if (lw->bar_sort_enabled == gtk_toggle_action_get_active(action)) return; + if (lw->options.panels.sort.enabled == gtk_toggle_action_get_active(action)) return; layout_bar_sort_toggle(lw); } @@ -1853,25 +1853,25 @@ if (!lw->action_group) return; action = gtk_action_group_get_action(lw->action_group, "FolderTree"); - radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->dir_view_type); + radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type); action = gtk_action_group_get_action(lw->action_group, "ViewIcons"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->file_view_type); action = gtk_action_group_get_action(lw->action_group, "FloatTools"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->tools_float); + 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->bar_enabled); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.info.enabled); action = gtk_action_group_get_action(lw->action_group, "SBarSort"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->bar_sort_enabled); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.sort.enabled); action = gtk_action_group_get_action(lw->action_group, "HideToolbar"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->toolbar_hidden); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden); action = gtk_action_group_get_action(lw->action_group, "ShowMarks"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->marks_enabled); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks); action = gtk_action_group_get_action(lw->action_group, "SlideShow"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_image_slideshow_active(lw)); @@ -1888,10 +1888,10 @@ if (!lw->action_group) return; action = gtk_action_group_get_action(lw->action_group, "Thumbnails"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->thumbs_enabled); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_thumbnails); g_object_set(action, "sensitive", (lw->file_view_type == FILEVIEW_LIST), NULL); - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->thumbs_enabled); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(lw->thumb_button), lw->options.show_thumbnails); gtk_widget_set_sensitive(lw->thumb_button, (lw->file_view_type == FILEVIEW_LIST)); } @@ -1950,7 +1950,7 @@ if (lw->utility_box) { /* destroyed from within itself */ - lw->bar_enabled = FALSE; + lw->options.panels.info.enabled = FALSE; layout_util_sync_views(lw); } } @@ -1968,68 +1968,86 @@ if (!lw->bar) return; - options->panels.info.width = lw->bar_width = allocation->width; + lw->options.panels.info.width = allocation->width; } -static void layout_bar_new(LayoutWindow *lw) +void layout_bar_new(LayoutWindow *lw, gboolean populate) { if (!lw->utility_box) return; - lw->bar = bar_new(lw->utility_box); - 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); + if (!lw->bar) + { + lw->bar = bar_new(lw->utility_box); + + if (populate) + { + bar_populate_default(lw->bar); + } - options->panels.info.enabled = lw->bar_enabled = TRUE; - gtk_widget_set_size_request(lw->bar, lw->bar_width, -1); + 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); - + + 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); } -static void layout_bar_close(LayoutWindow *lw) +void layout_bar_close(LayoutWindow *lw) { if (lw->bar) { bar_close(lw->bar); lw->bar = NULL; } - options->panels.info.enabled = lw->bar_enabled = FALSE; + lw->options.panels.info.enabled = FALSE; +} + +static void layout_bar_hide(LayoutWindow *lw) +{ + if (lw->bar) + { + gtk_widget_hide(lw->bar); + } + lw->options.panels.info.enabled = FALSE; } void layout_bar_toggle(LayoutWindow *lw) { - if (lw->bar_enabled) + if (lw->options.panels.info.enabled) { - layout_bar_close(lw); + layout_bar_hide(lw); } else { - layout_bar_new(lw); + layout_bar_new(lw, TRUE); } } static void layout_bar_new_image(LayoutWindow *lw) { - if (!lw->bar || !lw->bar_enabled) return; + if (!lw->bar || !lw->options.panels.info.enabled) 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->bar_enabled) return; + if (!lw->bar || !lw->options.panels.info.enabled) return; // bar_info_selection(lw->bar_info, count - 1); } static void layout_bar_maint_renamed(LayoutWindow *lw) { - if (!lw->bar || !lw->bar_enabled) return; + if (!lw->bar || !lw->options.panels.info.enabled) return; // bar_maint_renamed(lw->bar_info, layout_image_get_fd(lw)); } @@ -2043,7 +2061,7 @@ if (lw->utility_box) { /* destroyed from within itself */ - lw->bar_sort_enabled = FALSE; + lw->options.panels.sort.enabled = FALSE; layout_util_sync_views(lw); } @@ -2056,7 +2074,7 @@ lw->bar_sort = bar_sort_new(lw); g_signal_connect(G_OBJECT(lw->bar_sort), "destroy", G_CALLBACK(layout_bar_sort_destroyed), lw); - options->panels.sort.enabled = lw->bar_sort_enabled = TRUE; + lw->options.panels.sort.enabled = TRUE; gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0); gtk_widget_show(lw->bar_sort); @@ -2069,12 +2087,12 @@ bar_sort_close(lw->bar_sort); lw->bar_sort = NULL; } - options->panels.sort.enabled = lw->bar_sort_enabled = FALSE; + lw->options.panels.sort.enabled = FALSE; } void layout_bar_sort_toggle(LayoutWindow *lw) { - if (lw->bar_sort_enabled) + if (lw->options.panels.sort.enabled) { layout_bar_sort_close(lw); } @@ -2106,14 +2124,14 @@ gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0); gtk_widget_show(image); - if (lw->bar_sort_enabled) + if (lw->options.panels.sort.enabled) { layout_bar_sort_new(lw); } - if (lw->bar_enabled) + if (lw->options.panels.info.enabled) { - layout_bar_new(lw); + layout_bar_new(lw, TRUE); } return lw->utility_box;
--- a/src/layout_util.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/layout_util.h Sun Feb 22 15:35:37 2009 +0000 @@ -45,6 +45,9 @@ void layout_bar_toggle(LayoutWindow *lw); +void layout_bar_new(LayoutWindow *lw, gboolean populate); +void layout_bar_close(LayoutWindow *lw); + void layout_bar_exif_toggle(LayoutWindow *lw); void layout_bar_sort_toggle(LayoutWindow *lw);
--- a/src/main.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/main.c Sun Feb 22 15:35:37 2009 +0000 @@ -666,6 +666,30 @@ exit_program_final(); } +void init_after_global_options(void) +{ + + if (gtk_major_version < GTK_MAJOR_VERSION || + (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) + { + log_printf("!!! This is a friendly warning.\n"); + log_printf("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); + log_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); + log_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); + log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); + } + + mkdir_if_not_exists(get_rc_dir()); + mkdir_if_not_exists(get_collections_dir()); + mkdir_if_not_exists(get_thumbnails_cache_dir()); + mkdir_if_not_exists(get_metadata_cache_dir()); + + keys_load(); + + editor_load_descriptions(); + + accel_map_load(); +} /* This code is supposed to handle situation when a file mmaped by image_loader @@ -751,35 +775,19 @@ options = init_options(NULL); setup_default_options(options); - load_options(options); - gtkrc_load(); + gtkrc_load(); //FIXME: move to init_after_global_options() gtk_init(&argc, &argv); - parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry); - if (gtk_major_version < GTK_MAJOR_VERSION || - (gtk_major_version == GTK_MAJOR_VERSION && gtk_minor_version < GTK_MINOR_VERSION) ) - { - log_printf("!!! This is a friendly warning.\n"); - log_printf("!!! The version of GTK+ in use now is older than when %s was compiled.\n", GQ_APPNAME); - log_printf("!!! compiled with GTK+-%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION); - log_printf("!!! running with GTK+-%d.%d\n", gtk_major_version, gtk_minor_version); - log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); - } + load_options(options); + /* ^^^ this calls init_after_global_options(); at the right moment*/ - mkdir_if_not_exists(get_rc_dir()); - mkdir_if_not_exists(get_collections_dir()); - mkdir_if_not_exists(get_thumbnails_cache_dir()); - mkdir_if_not_exists(get_metadata_cache_dir()); - - keys_load(); - filter_add_defaults(); - filter_rebuild(); - - editor_load_descriptions(); - - accel_map_load(); + if (!layout_window_list) + { // FIXME: commandline handling does not work at all, this is a quick workaround for missing rc file + + init_after_global_options(); + parse_command_line(argc, argv, &cmd_path, &cmd_file, &cmd_list, &collection_list, &geometry); if (startup_blank) { @@ -807,7 +815,7 @@ path = get_current_dir(); } - lw = layout_new_with_geometry(NULL, options->layout.tools_float, options->layout.tools_hidden, geometry); + lw = layout_new_with_geometry(NULL, NULL, geometry); layout_sort_set(lw, options->file_sort.method, options->file_sort.ascending); if (collection_list && !startup_command_line_collection) @@ -894,6 +902,8 @@ image_osd_set(lw->image, options->image_overlay.common.state | (options->image_overlay.common.show_at_startup ? OSD_SHOW_INFO : OSD_SHOW_NOTHING)); + } + g_free(geometry); g_free(cmd_path); g_free(cmd_file);
--- a/src/main.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/main.h Sun Feb 22 15:35:37 2009 +0000 @@ -77,7 +77,7 @@ #define GQ_SYSTEM_WIDE_DIR "/etc/" GQ_APPNAME_LC -#define RC_FILE_NAME GQ_APPNAME_LC "rc" +#define RC_FILE_NAME GQ_APPNAME_LC "rc.xml" #define GQ_COLLECTION_EXT ".gqv" @@ -136,6 +136,8 @@ void exit_program(void); +void init_after_global_options(void); + #define CASE_SORT(a, b) ( (options->file_sort.case_sensitive) ? strcmp((a), (b)) : strcasecmp((a), (b)) )
--- a/src/options.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/options.c Sun Feb 22 15:35:37 2009 +0000 @@ -120,15 +120,15 @@ options->open_recent_list_maxsize = 10; options->place_dialogs_under_mouse = FALSE; - options->panels.exif.enabled = FALSE; - options->panels.exif.width = PANEL_DEFAULT_WIDTH; - options->panels.info.enabled = FALSE; - options->panels.info.width = PANEL_DEFAULT_WIDTH; - options->panels.sort.action_state = 0; - options->panels.sort.enabled = FALSE; - options->panels.sort.mode_state = 0; - options->panels.sort.selection_state = 0; - options->panels.sort.action_filter = NULL; + 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; + options->layout.panels.sort.selection_state = 0; + options->layout.panels.sort.action_filter = NULL; options->progressive_key_scrolling = TRUE; @@ -202,47 +202,49 @@ ExifUIList[i].current = ExifUIList[i].default_value; } +void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src) +{ + free_layout_options_content(dest); + + *dest = *src; + dest->order = g_strdup(src->order); + dest->home_path = g_strdup(src->home_path); + dest->panels.sort.action_filter = g_strdup(src->panels.sort.action_filter); +} + +void free_layout_options_content(LayoutOptions *dest) +{ + if (dest->order) g_free(dest->order); + if (dest->home_path) g_free(dest->home_path); + if (dest->panels.sort.action_filter) g_free(dest->panels.sort.action_filter); +} + static void sync_options_with_current_state(ConfOptions *options) { LayoutWindow *lw = NULL; if (layout_valid(&lw)) { - options->layout.main_window.maximized = window_maximized(lw->window); - if (!options->layout.main_window.maximized) + layout_sync_options_with_current_state(lw); + copy_layout_options(&options->layout, &lw->options); + options->image_overlay.common.state = image_osd_get(lw->image); + layout_sort_get(lw, &options->file_sort.method, &options->file_sort.ascending); + + + + options->color_profile.enabled = layout_image_color_profile_get_use(lw); + layout_image_color_profile_get(lw, + &options->color_profile.input_type, + &options->color_profile.screen_type, + &options->color_profile.use_image); + + if (options->startup.restore_path && options->startup.use_last_path) { - layout_geometry_get(NULL, &options->layout.main_window.x, &options->layout.main_window.y, - &options->layout.main_window.w, &options->layout.main_window.h); + g_free(options->startup.path); + options->startup.path = g_strdup(layout_get_path(lw)); } - - options->image_overlay.common.state = image_osd_get(lw->image); } - layout_geometry_get_dividers(NULL, &options->layout.main_window.hdivider_pos, &options->layout.main_window.vdivider_pos); - - layout_views_get(NULL, &options->layout.dir_view_type, &options->layout.file_view_type); - - options->layout.show_thumbnails = layout_thumb_get(NULL); - options->layout.show_marks = layout_marks_get(NULL); - - layout_sort_get(NULL, &options->file_sort.method, &options->file_sort.ascending); - - layout_geometry_get_tools(NULL, &options->layout.float_window.x, &options->layout.float_window.y, - &options->layout.float_window.w, &options->layout.float_window.h, &options->layout.float_window.vdivider_pos); - layout_tools_float_get(NULL, &options->layout.tools_float, &options->layout.tools_hidden); - options->layout.toolbar_hidden = layout_toolbar_hidden(NULL); - - options->color_profile.enabled = layout_image_color_profile_get_use(NULL); - layout_image_color_profile_get(NULL, - &options->color_profile.input_type, - &options->color_profile.screen_type, - &options->color_profile.use_image); - - if (options->startup.restore_path && options->startup.use_last_path) - { - g_free(options->startup.path); - options->startup.path = g_strdup(layout_get_path(NULL)); - } } void save_options(ConfOptions *options)
--- a/src/options.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/options.h Sun Feb 22 15:35:37 2009 +0000 @@ -156,71 +156,11 @@ } image_overlay; /* layout */ - struct { - gchar *order; - gint style; - - DirViewType dir_view_type; - FileViewType file_view_type; - - gboolean show_thumbnails; - gboolean show_marks; - gboolean show_directory_date; - - struct { - gint w; - gint h; - gint x; - gint y; - gboolean maximized; - gint hdivider_pos; - gint vdivider_pos; - } main_window; - - struct { - gint w; - gint h; - gint x; - gint y; - gint vdivider_pos; - } float_window; - - struct { - gint w; - gint h; - } properties_window; - - gboolean save_window_positions; - - gboolean tools_float; - gboolean tools_hidden; - gboolean tools_restore_state; - - gboolean toolbar_hidden; - - gchar *home_path; - } layout; - - /* panels */ - struct { - struct { - gboolean enabled; - gint width; - } info; - - struct { - gboolean enabled; - gint width; - } exif; - - struct { - gboolean enabled; - gint mode_state; - gint action_state; - gint selection_state; - gchar *action_filter; - } sort; - } panels; + /* FIXME: this is here for 2 reasons: + - I don't want to break preferences dialog now + - it might be useful as defaults for new windows (I am not sure about this) + */ + LayoutOptions layout; /* properties dialog */ struct { @@ -275,6 +215,9 @@ void save_options(ConfOptions *options); void load_options(ConfOptions *options); +void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src); +void free_layout_options_content(LayoutOptions *dest); + #endif /* OPTIONS_H */ /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/rcfile.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/rcfile.c Sun Feb 22 15:35:37 2009 +0000 @@ -16,7 +16,11 @@ #include "main.h" #include "rcfile.h" +#include "bar.h" +#include "bar_comment.h" #include "bar_exif.h" +#include "bar_histogram.h" +#include "bar_keywords.h" #include "editors.h" #include "filefilter.h" #include "misc.h" @@ -24,29 +28,37 @@ #include "secure_save.h" #include "slideshow.h" #include "ui_fileops.h" +#include "layout.h" +#include "layout_util.h" +#include "bar.h" + /* *----------------------------------------------------------------------------- - * line write/parse routines (private) + * line write/parse routines (public) *----------------------------------------------------------------------------- */ - -static void write_char_option(SecureSaveInfo *ssi, gchar *label, gchar *text) +void write_indent(GString *str, gint indent) { - gchar *escval = escquote_value(text); + g_string_append_printf(str, "%*s", indent * 4, ""); +} - secure_fprintf(ssi, "%s: %s\n", label, escval); +void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text) +{ + gchar *escval = g_markup_escape_text(text ? text : "", -1); + write_indent(str, indent); + g_string_append_printf(str, "%s = \"%s\"\n", label, escval); g_free(escval); } -static gboolean read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar **text) +gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!text) return FALSE; g_free(*text); - *text = quoted_value(value, NULL); + *text = g_strdup(value); return TRUE; } @@ -57,39 +69,36 @@ return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue); } -static void write_color_option(SecureSaveInfo *ssi, gchar *label, GdkColor *color) +void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color) { if (color) { gchar *colorstring = color_to_string(color); - write_char_option(ssi, label, colorstring); + write_char_option(str, indent, label, colorstring); g_free(colorstring); } else - secure_fprintf(ssi, "%s: \n", label); + write_char_option(str, indent, label, ""); } -static gboolean read_color_option(FILE *f, gchar *option, gchar *label, gchar *value, GdkColor *color) +gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color) { - gchar *colorstr; - if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!color) return FALSE; - colorstr = quoted_value(value, NULL); - if (!colorstr) return FALSE; - gdk_color_parse(colorstr, color); - g_free(colorstr); + if (!*value) return FALSE; + gdk_color_parse(value, color); return TRUE; } -static void write_int_option(SecureSaveInfo *ssi, gchar *label, gint n) +void write_int_option(GString *str, gint indent, const gchar *label, gint n) { - secure_fprintf(ssi, "%s: %d\n", label, n); + write_indent(str, indent); + g_string_append_printf(str, "%s = \"%d\"\n", label, n); } -static gboolean read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n) +gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -109,12 +118,13 @@ return TRUE; } -static void write_uint_option(SecureSaveInfo *ssi, gchar *label, guint n) +void write_uint_option(GString *str, gint indent, const gchar *label, guint n) { - secure_fprintf(ssi, "%s: %u\n", label, n); + write_indent(str, indent); + g_string_append_printf(str, "%s = \"%u\"\n", label, n); } -static gboolean read_uint_option(FILE *f, gchar *option, gchar *label, gchar *value, guint *n) +gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -134,28 +144,28 @@ return TRUE; } -static gboolean read_uint_option_clamp(FILE *f, gchar *option, gchar *label, gchar *value, guint *n, guint min, guint max) +gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max) { gboolean ret; - ret = read_uint_option(f, option, label, value, n); + ret = read_uint_option(option, label, value, n); if (ret) *n = CLAMP(*n, min, max); return ret; } -static gboolean read_int_option_clamp(FILE *f, gchar *option, gchar *label, gchar *value, gint *n, gint min, gint max) +gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max) { gboolean ret; - ret = read_int_option(f, option, label, value, n); + ret = read_int_option(option, label, value, n); if (ret) *n = CLAMP(*n, min, max); return ret; } -static void write_int_unit_option(SecureSaveInfo *ssi, gchar *label, gint n, gint subunits) +void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits) { gint l, r; @@ -170,18 +180,20 @@ r = 0; } - secure_fprintf(ssi, "%s: %d.%d\n", label, l, r); + write_indent(str, indent); + g_string_append_printf(str, "%s = \"%d.%d\"\n", label, l, r); } -static gboolean read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n, gint subunits) +gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits) { gint l, r; - gchar *ptr; + gchar *ptr, *buf; if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; - ptr = value; + buf = g_strdup(value); + ptr = buf; while (*ptr != '\0' && *ptr != '.') ptr++; if (*ptr == '.') { @@ -198,17 +210,18 @@ } *n = l * subunits + r; - + g_free(buf); + return TRUE; } -static void write_bool_option(SecureSaveInfo *ssi, gchar *label, gint n) +void write_bool_option(GString *str, gint indent, gchar *label, gint n) { - secure_fprintf(ssi, "%s: ", label); - if (n) secure_fprintf(ssi, "true\n"); else secure_fprintf(ssi, "false\n"); + write_indent(str, indent); + g_string_append_printf(str, "%s = \"%s\"\n", label, n ? "true" : "false"); } -static gboolean read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint *n) +gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n) { if (g_ascii_strcasecmp(option, label) != 0) return FALSE; if (!n) return FALSE; @@ -221,6 +234,248 @@ return TRUE; } +/* + *----------------------------------------------------------------------------- + * write fuctions for elements (private) + *----------------------------------------------------------------------------- + */ + +static void write_global_attributes(GString *outstr, gint indent) +{ +// WRITE_SUBTITLE("General Options"); + + WRITE_BOOL(*options, show_icon_names); + WRITE_BOOL(*options, show_copy_path); + WRITE_SEPARATOR(); + + WRITE_BOOL(*options, tree_descend_subdirs); + WRITE_BOOL(*options, lazy_image_sync); + WRITE_BOOL(*options, update_on_time_change); + WRITE_SEPARATOR(); + + WRITE_BOOL(*options, progressive_key_scrolling); + + WRITE_UINT(*options, duplicates_similarity_threshold); + WRITE_SEPARATOR(); + + WRITE_BOOL(*options, mousewheel_scrolls); + WRITE_INT(*options, open_recent_list_maxsize); + WRITE_INT(*options, dnd_icon_size); + WRITE_BOOL(*options, place_dialogs_under_mouse); + + +// WRITE_SUBTITLE("Startup Options"); + + WRITE_BOOL(*options, startup.restore_path); + WRITE_BOOL(*options, startup.use_last_path); + WRITE_CHAR(*options, startup.path); + + +// WRITE_SUBTITLE("File operations Options"); + + WRITE_BOOL(*options, file_ops.enable_in_place_rename); + WRITE_BOOL(*options, file_ops.confirm_delete); + WRITE_BOOL(*options, file_ops.enable_delete_key); + WRITE_BOOL(*options, file_ops.safe_delete_enable); + WRITE_CHAR(*options, file_ops.safe_delete_path); + WRITE_INT(*options, file_ops.safe_delete_folder_maxsize); + + + + +// WRITE_SUBTITLE("Properties dialog Options"); + WRITE_CHAR(*options, properties.tabs_order); + +// WRITE_SUBTITLE("Image Options"); + + WRITE_UINT(*options, image.zoom_mode); + +// g_string_append_printf(outstr, "# image.zoom_mode possible values are:\n" +// "# original\n" +// "# fit\n" +// "# dont_change\n"); +// g_string_append_printf(outstr, "image.zoom_mode: "); +// switch (options->image.zoom_mode) +// { +// case ZOOM_RESET_ORIGINAL: g_string_append_printf(outstr, "original\n"); break; +// case ZOOM_RESET_FIT_WINDOW: g_string_append_printf(outstr, "fit\n"); break; +// case ZOOM_RESET_NONE: g_string_append_printf(outstr, "dont_change\n"); break; +// } + WRITE_SEPARATOR(); + WRITE_BOOL(*options, image.zoom_2pass); + WRITE_BOOL(*options, image.zoom_to_fit_allow_expand); + WRITE_UINT(*options, image.zoom_quality); + WRITE_INT(*options, image.zoom_increment); + WRITE_BOOL(*options, image.fit_window_to_image); + WRITE_BOOL(*options, image.limit_window_size); + WRITE_INT(*options, image.max_window_size); + WRITE_BOOL(*options, image.limit_autofit_size); + WRITE_INT(*options, image.max_autofit_size); + WRITE_UINT(*options, image.scroll_reset_method); + WRITE_INT(*options, image.tile_cache_max); + WRITE_INT(*options, image.image_cache_max); + WRITE_UINT(*options, image.dither_quality); + WRITE_BOOL(*options, image.enable_read_ahead); + WRITE_BOOL(*options, image.exif_rotate_enable); + WRITE_BOOL(*options, image.use_custom_border_color); + WRITE_COLOR(*options, image.border_color); + WRITE_INT(*options, image.read_buffer_size); + WRITE_INT(*options, image.idle_read_loop_count); + +// WRITE_SUBTITLE("Thumbnails Options"); + + WRITE_INT(*options, thumbnails.max_width); + WRITE_INT(*options, thumbnails.max_height); + WRITE_BOOL(*options, thumbnails.enable_caching); + WRITE_BOOL(*options, thumbnails.cache_into_dirs); + WRITE_BOOL(*options, thumbnails.fast); + WRITE_BOOL(*options, thumbnails.use_xvpics); + WRITE_BOOL(*options, thumbnails.spec_standard); + WRITE_UINT(*options, thumbnails.quality); + WRITE_BOOL(*options, thumbnails.use_exif); + + +// WRITE_SUBTITLE("File sorting Options"); + + WRITE_INT(*options, file_sort.method); + WRITE_BOOL(*options, file_sort.ascending); + WRITE_BOOL(*options, file_sort.case_sensitive); + + +// WRITE_SUBTITLE("Fullscreen Options"); + + WRITE_INT(*options, fullscreen.screen); + WRITE_BOOL(*options, fullscreen.clean_flip); + WRITE_BOOL(*options, fullscreen.disable_saver); + WRITE_BOOL(*options, fullscreen.above); + + +// WRITE_SUBTITLE("Histogram Options"); + WRITE_UINT(*options, histogram.last_channel_mode); + WRITE_UINT(*options, histogram.last_log_mode); + + +// WRITE_SUBTITLE("Image Overlay Options"); + WRITE_UINT(*options, image_overlay.common.state); + WRITE_BOOL(*options, image_overlay.common.show_at_startup); + WRITE_CHAR(*options, image_overlay.common.template_string); + WRITE_SEPARATOR(); + +// g_string_append_printf(outstr, "# these are relative positions:\n"); +// g_string_append_printf(outstr, "# x >= 0: |x| pixels from left border\n"); +// g_string_append_printf(outstr, "# x < 0 : |x| pixels from right border\n"); +// g_string_append_printf(outstr, "# y >= 0: |y| pixels from top border\n"); +// g_string_append_printf(outstr, "# y < 0 : |y| pixels from bottom border\n"); + WRITE_INT(*options, image_overlay.common.x); + WRITE_INT(*options, image_overlay.common.y); + + +// WRITE_SUBTITLE("Slideshow Options"); + + WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); + WRITE_BOOL(*options, slideshow.random); + WRITE_BOOL(*options, slideshow.repeat); + + +// WRITE_SUBTITLE("Collection Options"); + + WRITE_BOOL(*options, collections.rectangular_selection); + + +// WRITE_SUBTITLE("Filtering Options"); + + WRITE_BOOL(*options, file_filter.show_hidden_files); + WRITE_BOOL(*options, file_filter.show_dot_directory); + WRITE_BOOL(*options, file_filter.disable); + WRITE_SEPARATOR(); + + +// WRITE_SUBTITLE("Sidecars Options"); + + WRITE_CHAR(*options, sidecar.ext); + + + +// WRITE_SUBTITLE("Shell command"); + WRITE_CHAR(*options, shell.path); + WRITE_CHAR(*options, shell.options); + + +// WRITE_SUBTITLE("Helpers"); +// g_string_append_printf(outstr, "# Html browser\n"); +// g_string_append_printf(outstr, "# command_name is: the binary's name to look for in the path\n"); +// g_string_append_printf(outstr, "# If command_name is empty, the program will try various common html browsers\n"); +// g_string_append_printf(outstr, "# command_line is:\n"); +// g_string_append_printf(outstr, "# \"\" (empty string) = execute binary with html file path as command line\n"); +// g_string_append_printf(outstr, "# \"string\" = execute string and use results for command line\n"); +// g_string_append_printf(outstr, "# \"!string\" = use text following ! as command line, replacing optional %%s with html file path\n"); + WRITE_CHAR(*options, helpers.html_browser.command_name); + WRITE_CHAR(*options, helpers.html_browser.command_line); + +/* FIXME: + WRITE_SUBTITLE("Exif Options"); + g_string_append_printf(outstr, "# Display: 0: never\n" + "# 1: if set\n" + "# 2: always\n\n"); + for (i = 0; ExifUIList[i].key; i++) + { + g_string_append_printf(outstr, "exif.display."); + write_int_option(outstr, 2, (gchar *)ExifUIList[i].key, ExifUIList[i].current); + } +*/ + +// WRITE_SUBTITLE("Metadata Options"); + WRITE_BOOL(*options, metadata.enable_metadata_dirs); + WRITE_BOOL(*options, metadata.save_in_image_file); + WRITE_BOOL(*options, metadata.save_legacy_IPTC); + WRITE_BOOL(*options, metadata.warn_on_write_problems); + WRITE_BOOL(*options, metadata.save_legacy_format); + WRITE_BOOL(*options, metadata.sync_grouped_files); + WRITE_BOOL(*options, metadata.confirm_write); + WRITE_INT(*options, metadata.confirm_timeout); + WRITE_BOOL(*options, metadata.confirm_after_timeout); + WRITE_BOOL(*options, metadata.confirm_on_image_change); + WRITE_BOOL(*options, metadata.confirm_on_dir_change); + +} + +static void write_color_profile(GString *outstr, gint indent) +{ + gint i; +#ifndef HAVE_LCMS + g_string_append_printf(outstr, "<!-- NOTICE: %s was not built with support for color profiles,\n" + " color profile options will have no effect.\n-->\n", GQ_APPNAME); +#endif + + write_indent(outstr, indent); + g_string_append_printf(outstr, "<color_profiles\n"); + indent++; + WRITE_INT(options->color_profile, screen_type); + WRITE_CHAR(options->color_profile, screen_file); + WRITE_BOOL(options->color_profile, enabled); + 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"); + + indent++; + for (i = 0; i < COLOR_PROFILE_INPUTS; i++) + { + write_indent(outstr, indent); + g_string_append_printf(outstr, "<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"); + } + indent--; + write_indent(outstr, indent); + g_string_append_printf(outstr, "</color_profiles>\n"); +} + /* *----------------------------------------------------------------------------- @@ -232,8 +487,10 @@ { SecureSaveInfo *ssi; gchar *rc_pathl; - gint i; - + GString *outstr; + gint indent = 0; + GList *work; + rc_pathl = path_from_utf8(utf8_path); ssi = secure_open(rc_pathl); g_free(rc_pathl); @@ -243,322 +500,56 @@ return FALSE; } -#define WRITE_BOOL(_name_) write_bool_option(ssi, #_name_, options->_name_) -#define WRITE_INT(_name_) write_int_option(ssi, #_name_, options->_name_) -#define WRITE_UINT(_name_) write_uint_option(ssi, #_name_, options->_name_) -#define WRITE_INT_UNIT(_name_, _unit_) write_int_unit_option(ssi, #_name_, options->_name_, _unit_) -#define WRITE_CHAR(_name_) write_char_option(ssi, #_name_, options->_name_) -#define WRITE_COLOR(_name_) write_color_option(ssi, #_name_, &options->_name_) - -#define WRITE_SEPARATOR() secure_fputc(ssi, '\n') -#define WRITE_SUBTITLE(_title_) secure_fprintf(ssi, "\n\n##### "_title_" #####\n\n") - - secure_fprintf(ssi, "######################################################################\n"); - secure_fprintf(ssi, "# %30s config file version %-10s #\n", GQ_APPNAME, VERSION); - secure_fprintf(ssi, "######################################################################\n"); - WRITE_SEPARATOR(); - - secure_fprintf(ssi, "# Note: This file is autogenerated. Options can be changed here,\n"); - secure_fprintf(ssi, "# but user comments and formatting will be lost.\n"); - WRITE_SEPARATOR(); - - WRITE_SUBTITLE("General Options"); - - WRITE_BOOL(show_icon_names); - WRITE_BOOL(show_copy_path); - WRITE_SEPARATOR(); - - WRITE_BOOL(tree_descend_subdirs); - WRITE_BOOL(lazy_image_sync); - WRITE_BOOL(update_on_time_change); - WRITE_SEPARATOR(); - - WRITE_BOOL(progressive_key_scrolling); - - WRITE_UINT(duplicates_similarity_threshold); - WRITE_SEPARATOR(); - - WRITE_BOOL(mousewheel_scrolls); - WRITE_INT(open_recent_list_maxsize); - WRITE_INT(dnd_icon_size); - WRITE_BOOL(place_dialogs_under_mouse); - - - WRITE_SUBTITLE("Startup Options"); - - WRITE_BOOL(startup.restore_path); - WRITE_BOOL(startup.use_last_path); - WRITE_CHAR(startup.path); - - - WRITE_SUBTITLE("File operations Options"); - - WRITE_BOOL(file_ops.enable_in_place_rename); - WRITE_BOOL(file_ops.confirm_delete); - WRITE_BOOL(file_ops.enable_delete_key); - WRITE_BOOL(file_ops.safe_delete_enable); - WRITE_CHAR(file_ops.safe_delete_path); - WRITE_INT(file_ops.safe_delete_folder_maxsize); - - - WRITE_SUBTITLE("Layout Options"); - - WRITE_INT(layout.style); - WRITE_CHAR(layout.order); - WRITE_UINT(layout.dir_view_type); - WRITE_UINT(layout.file_view_type); - WRITE_BOOL(layout.show_marks); - WRITE_BOOL(layout.show_thumbnails); - WRITE_BOOL(layout.show_directory_date); - WRITE_CHAR(layout.home_path); - WRITE_SEPARATOR(); - - WRITE_BOOL(layout.save_window_positions); - WRITE_SEPARATOR(); - - WRITE_INT(layout.main_window.x); - WRITE_INT(layout.main_window.y); - WRITE_INT(layout.main_window.w); - WRITE_INT(layout.main_window.h); - WRITE_BOOL(layout.main_window.maximized); - WRITE_INT(layout.main_window.hdivider_pos); - WRITE_INT(layout.main_window.vdivider_pos); - WRITE_SEPARATOR(); - - WRITE_INT(layout.float_window.x); - WRITE_INT(layout.float_window.y); - WRITE_INT(layout.float_window.w); - WRITE_INT(layout.float_window.h); - WRITE_INT(layout.float_window.vdivider_pos); - WRITE_SEPARATOR(); - - WRITE_INT(layout.properties_window.w); - WRITE_INT(layout.properties_window.h); - WRITE_SEPARATOR(); - - WRITE_BOOL(layout.tools_float); - WRITE_BOOL(layout.tools_hidden); - WRITE_BOOL(layout.tools_restore_state); + outstr = g_string_new(""); + g_string_append_printf(outstr, "<!--\n"); + g_string_append_printf(outstr, "######################################################################\n"); + g_string_append_printf(outstr, "# %30s config file version %-10s #\n", GQ_APPNAME, VERSION); + g_string_append_printf(outstr, "######################################################################\n"); WRITE_SEPARATOR(); - WRITE_BOOL(layout.toolbar_hidden); - - WRITE_SUBTITLE("Panels Options"); - - WRITE_BOOL(panels.exif.enabled); - WRITE_INT(panels.exif.width); - WRITE_BOOL(panels.info.enabled); - WRITE_INT(panels.info.width); - WRITE_BOOL(panels.sort.enabled); - WRITE_INT(panels.sort.action_state); - WRITE_INT(panels.sort.mode_state); - WRITE_INT(panels.sort.selection_state); - WRITE_CHAR(panels.sort.action_filter); - - WRITE_SUBTITLE("Properties dialog Options"); - WRITE_CHAR(properties.tabs_order); - - WRITE_SUBTITLE("Image Options"); + 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_SEPARATOR(); + g_string_append_printf(outstr, "-->\n"); + WRITE_SEPARATOR(); + g_string_append_printf(outstr, "<global\n"); + indent++; + write_global_attributes(outstr, indent); + write_indent(outstr, indent); + g_string_append_printf(outstr, ">\n"); - secure_fprintf(ssi, "# image.zoom_mode possible values are:\n" - "# original\n" - "# fit\n" - "# dont_change\n"); - secure_fprintf(ssi, "image.zoom_mode: "); - switch (options->image.zoom_mode) - { - case ZOOM_RESET_ORIGINAL: secure_fprintf(ssi, "original\n"); break; - case ZOOM_RESET_FIT_WINDOW: secure_fprintf(ssi, "fit\n"); break; - case ZOOM_RESET_NONE: secure_fprintf(ssi, "dont_change\n"); break; - } + write_color_profile(outstr, indent); + WRITE_SEPARATOR(); - WRITE_BOOL(image.zoom_2pass); - WRITE_BOOL(image.zoom_to_fit_allow_expand); - WRITE_UINT(image.zoom_quality); - WRITE_INT(image.zoom_increment); - WRITE_BOOL(image.fit_window_to_image); - WRITE_BOOL(image.limit_window_size); - WRITE_INT(image.max_window_size); - WRITE_BOOL(image.limit_autofit_size); - WRITE_INT(image.max_autofit_size); - WRITE_UINT(image.scroll_reset_method); - WRITE_INT(image.tile_cache_max); - WRITE_INT(image.image_cache_max); - WRITE_UINT(image.dither_quality); - WRITE_BOOL(image.enable_read_ahead); - WRITE_BOOL(image.exif_rotate_enable); - WRITE_BOOL(image.use_custom_border_color); - WRITE_COLOR(image.border_color); - WRITE_INT(image.read_buffer_size); - WRITE_INT(image.idle_read_loop_count); + filter_write_list(outstr, indent); - WRITE_SUBTITLE("Thumbnails Options"); - - WRITE_INT(thumbnails.max_width); - WRITE_INT(thumbnails.max_height); - WRITE_BOOL(thumbnails.enable_caching); - WRITE_BOOL(thumbnails.cache_into_dirs); - WRITE_BOOL(thumbnails.fast); - WRITE_BOOL(thumbnails.use_xvpics); - WRITE_BOOL(thumbnails.spec_standard); - WRITE_UINT(thumbnails.quality); - WRITE_BOOL(thumbnails.use_exif); - + WRITE_SEPARATOR(); + WRITE_SUBTITLE("Layout Options - defaults"); + write_indent(outstr, indent); + g_string_append_printf(outstr, "<layout\n"); + layout_write_attributes(&options->layout, outstr, indent + 1); + write_indent(outstr, indent); + g_string_append_printf(outstr, "/>\n"); - WRITE_SUBTITLE("File sorting Options"); - - WRITE_INT(file_sort.method); - WRITE_BOOL(file_sort.ascending); - WRITE_BOOL(file_sort.case_sensitive); - - - WRITE_SUBTITLE("Fullscreen Options"); - - WRITE_INT(fullscreen.screen); - WRITE_BOOL(fullscreen.clean_flip); - WRITE_BOOL(fullscreen.disable_saver); - WRITE_BOOL(fullscreen.above); + indent--; + g_string_append_printf(outstr, "</global>\n"); - - WRITE_SUBTITLE("Histogram Options"); - WRITE_UINT(histogram.last_channel_mode); - WRITE_UINT(histogram.last_log_mode); - - - WRITE_SUBTITLE("Image Overlay Options"); - WRITE_UINT(image_overlay.common.state); - WRITE_BOOL(image_overlay.common.show_at_startup); - WRITE_CHAR(image_overlay.common.template_string); WRITE_SEPARATOR(); + WRITE_SUBTITLE("Layout Options"); - secure_fprintf(ssi, "# these are relative positions:\n"); - secure_fprintf(ssi, "# x >= 0: |x| pixels from left border\n"); - secure_fprintf(ssi, "# x < 0 : |x| pixels from right border\n"); - secure_fprintf(ssi, "# y >= 0: |y| pixels from top border\n"); - secure_fprintf(ssi, "# y < 0 : |y| pixels from bottom border\n"); - WRITE_INT(image_overlay.common.x); - WRITE_INT(image_overlay.common.y); + work = layout_window_list; + while (work) + { + LayoutWindow *lw = work->data; + layout_write_config(lw, outstr, indent); + work = work->next; - - WRITE_SUBTITLE("Slideshow Options"); - - WRITE_INT_UNIT(slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); - WRITE_BOOL(slideshow.random); - WRITE_BOOL(slideshow.repeat); + } - WRITE_SUBTITLE("Collection Options"); - WRITE_BOOL(collections.rectangular_selection); - - - WRITE_SUBTITLE("Filtering Options"); - - WRITE_BOOL(file_filter.show_hidden_files); - WRITE_BOOL(file_filter.show_dot_directory); - WRITE_BOOL(file_filter.disable); - WRITE_SEPARATOR(); - - filter_write_list(ssi); - - - WRITE_SUBTITLE("Sidecars Options"); - - WRITE_CHAR(sidecar.ext); - - WRITE_SUBTITLE("Color Profiles"); - -#ifndef HAVE_LCMS - secure_fprintf(ssi, "# NOTICE: %s was not built with support for color profiles,\n" - "# color profile options will have no effect.\n\n", GQ_APPNAME); -#endif - - WRITE_BOOL(color_profile.enabled); - WRITE_BOOL(color_profile.use_image); - WRITE_INT(color_profile.input_type); - WRITE_SEPARATOR(); - - for (i = 0; i < COLOR_PROFILE_INPUTS; i++) - { - gchar *buf; - - buf = g_strdup_printf("color_profile.input_file_%d", i + 1); - write_char_option(ssi, buf, options->color_profile.input_file[i]); - g_free(buf); - - buf = g_strdup_printf("color_profile.input_name_%d", i + 1); - write_char_option(ssi, buf, options->color_profile.input_name[i]); - g_free(buf); - } - - WRITE_SEPARATOR(); - WRITE_INT(color_profile.screen_type); - WRITE_CHAR(color_profile.screen_file); - - - WRITE_SUBTITLE("Shell command"); - WRITE_CHAR(shell.path); - WRITE_CHAR(shell.options); - - - WRITE_SUBTITLE("Helpers"); - secure_fprintf(ssi, "# Html browser\n"); - secure_fprintf(ssi, "# command_name is: the binary's name to look for in the path\n"); - secure_fprintf(ssi, "# If command_name is empty, the program will try various common html browsers\n"); - secure_fprintf(ssi, "# command_line is:\n"); - secure_fprintf(ssi, "# \"\" (empty string) = execute binary with html file path as command line\n"); - secure_fprintf(ssi, "# \"string\" = execute string and use results for command line\n"); - secure_fprintf(ssi, "# \"!string\" = use text following ! as command line, replacing optional %%s with html file path\n"); - WRITE_CHAR(helpers.html_browser.command_name); - WRITE_CHAR(helpers.html_browser.command_line); - -#if 0 - WRITE_SUBTITLE("External Programs"); - secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS); - secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS); - secure_fprintf(ssi, "# format: external_n: \"menu name\" \"command line\"\n\n"); - - for (i = 0; i < GQ_EDITOR_SLOTS; i++) - { - if (i == GQ_EDITOR_GENERIC_SLOTS) secure_fputc(ssi, '\n'); - gchar *qname = escquote_value(options->editor[i].name); - gchar *qcommand = escquote_value(options->editor[i].command); - secure_fprintf(ssi, "external_%d: %s %s\n", i+1, qname, qcommand); - g_free(qname); - g_free(qcommand); - } -#endif - - WRITE_SUBTITLE("Exif Options"); - secure_fprintf(ssi, "# Display: 0: never\n" - "# 1: if set\n" - "# 2: always\n\n"); - for (i = 0; ExifUIList[i].key; i++) - { - secure_fprintf(ssi, "exif.display."); - write_int_option(ssi, (gchar *)ExifUIList[i].key, ExifUIList[i].current); - } - - WRITE_SUBTITLE("Metadata Options"); - WRITE_BOOL(metadata.enable_metadata_dirs); - WRITE_BOOL(metadata.save_in_image_file); - WRITE_BOOL(metadata.save_legacy_IPTC); - WRITE_BOOL(metadata.warn_on_write_problems); - WRITE_BOOL(metadata.save_legacy_format); - WRITE_BOOL(metadata.sync_grouped_files); - WRITE_BOOL(metadata.confirm_write); - WRITE_INT(metadata.confirm_timeout); - WRITE_BOOL(metadata.confirm_after_timeout); - WRITE_BOOL(metadata.confirm_on_image_change); - WRITE_BOOL(metadata.confirm_on_dir_change); - - WRITE_SEPARATOR(); - WRITE_SEPARATOR(); - - secure_fprintf(ssi, "######################################################################\n"); - secure_fprintf(ssi, "# end of config file #\n"); - secure_fprintf(ssi, "######################################################################\n"); - + secure_fputs(ssi, outstr->str); + g_string_free(outstr, TRUE); if (secure_close(ssi)) { @@ -570,8 +561,445 @@ return TRUE; } +/* + *----------------------------------------------------------------------------- + * loading attributes for elements (private) + *----------------------------------------------------------------------------- + */ + + +static gboolean load_global_params(const gchar **attribute_names, const gchar **attribute_values) +{ + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + + /* general options */ + READ_BOOL(*options, show_icon_names); + READ_BOOL(*options, show_copy_path); + + READ_BOOL(*options, tree_descend_subdirs); + READ_BOOL(*options, lazy_image_sync); + READ_BOOL(*options, update_on_time_change); + + READ_UINT_CLAMP(*options, duplicates_similarity_threshold, 0, 100); + + READ_BOOL(*options, progressive_key_scrolling); + + READ_BOOL(*options, mousewheel_scrolls); + + READ_INT(*options, open_recent_list_maxsize); + READ_INT(*options, dnd_icon_size); + READ_BOOL(*options, place_dialogs_under_mouse); + + /* startup options */ + + READ_BOOL(*options, startup.restore_path); + + READ_BOOL(*options, startup.use_last_path); + + READ_CHAR(*options, startup.path); + + + /* properties dialog options */ + READ_CHAR(*options, properties.tabs_order); + + /* image options */ + READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE); + READ_BOOL(*options, image.zoom_2pass); + READ_BOOL(*options, image.zoom_to_fit_allow_expand); + READ_BOOL(*options, image.fit_window_to_image); + READ_BOOL(*options, image.limit_window_size); + READ_INT(*options, image.max_window_size); + READ_BOOL(*options, image.limit_autofit_size); + READ_INT(*options, image.max_autofit_size); + READ_UINT_CLAMP(*options, image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1); + READ_INT(*options, image.tile_cache_max); + READ_INT(*options, image.image_cache_max); + READ_UINT_CLAMP(*options, image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); + READ_UINT_CLAMP(*options, image.dither_quality, GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX); + READ_INT(*options, image.zoom_increment); + READ_BOOL(*options, image.enable_read_ahead); + READ_BOOL(*options, image.exif_rotate_enable); + READ_BOOL(*options, image.use_custom_border_color); + READ_COLOR(*options, image.border_color); + READ_INT_CLAMP(*options, image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX); + READ_INT_CLAMP(*options, image.idle_read_loop_count, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MIN, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MAX); + + + /* thumbnails options */ + READ_INT_CLAMP(*options, thumbnails.max_width, 16, 512); + READ_INT_CLAMP(*options, thumbnails.max_height, 16, 512); + + READ_BOOL(*options, thumbnails.enable_caching); + READ_BOOL(*options, thumbnails.cache_into_dirs); + READ_BOOL(*options, thumbnails.fast); + READ_BOOL(*options, thumbnails.use_xvpics); + READ_BOOL(*options, thumbnails.spec_standard); + READ_UINT_CLAMP(*options, thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); + READ_BOOL(*options, thumbnails.use_exif); + + /* file sorting options */ + READ_UINT(*options, file_sort.method); + READ_BOOL(*options, file_sort.ascending); + READ_BOOL(*options, file_sort.case_sensitive); + + /* file operations *options */ + READ_BOOL(*options, file_ops.enable_in_place_rename); + READ_BOOL(*options, file_ops.confirm_delete); + READ_BOOL(*options, file_ops.enable_delete_key); + READ_BOOL(*options, file_ops.safe_delete_enable); + READ_CHAR(*options, file_ops.safe_delete_path); + READ_INT(*options, file_ops.safe_delete_folder_maxsize); + + /* fullscreen options */ + READ_INT(*options, fullscreen.screen); + READ_BOOL(*options, fullscreen.clean_flip); + READ_BOOL(*options, fullscreen.disable_saver); + READ_BOOL(*options, fullscreen.above); + + /* histogram */ + READ_UINT(*options, histogram.last_channel_mode); + READ_UINT(*options, histogram.last_log_mode); + + /* image overlay */ + READ_UINT(*options, image_overlay.common.state); + READ_BOOL(*options, image_overlay.common.show_at_startup); + READ_CHAR(*options, image_overlay.common.template_string); + + READ_INT(*options, image_overlay.common.x); + READ_INT(*options, image_overlay.common.y); + + + /* slideshow options */ + READ_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); + READ_BOOL(*options, slideshow.random); + READ_BOOL(*options, slideshow.repeat); + + /* collection options */ + + READ_BOOL(*options, collections.rectangular_selection); + + /* filtering options */ + + READ_BOOL(*options, file_filter.show_hidden_files); + READ_BOOL(*options, file_filter.show_dot_directory); + READ_BOOL(*options, file_filter.disable); + READ_CHAR(*options, sidecar.ext); + + /* Color Profiles */ + + /* Shell command */ + READ_CHAR(*options, shell.path); + READ_CHAR(*options, shell.options); + + /* Helpers */ + READ_CHAR(*options, helpers.html_browser.command_name); + READ_CHAR(*options, helpers.html_browser.command_line); + /* Exif */ +/* + if (0 == g_ascii_strncasecmp(option, "exif.display.", 13)) + { + for (i = 0; ExifUIList[i].key; i++) + if (0 == g_ascii_strcasecmp(option + 13, ExifUIList[i].key)) + ExifUIList[i].current = strtol(value, NULL, 10); + continue; + } +*/ + /* metadata */ + READ_BOOL(*options, metadata.enable_metadata_dirs); + READ_BOOL(*options, metadata.save_in_image_file); + READ_BOOL(*options, metadata.save_legacy_IPTC); + READ_BOOL(*options, metadata.warn_on_write_problems); + READ_BOOL(*options, metadata.save_legacy_format); + READ_BOOL(*options, metadata.sync_grouped_files); + READ_BOOL(*options, metadata.confirm_write); + READ_BOOL(*options, metadata.confirm_after_timeout); + READ_INT(*options, metadata.confirm_timeout); + READ_BOOL(*options, metadata.confirm_on_image_change); + READ_BOOL(*options, metadata.confirm_on_dir_change); + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + return TRUE; +} + +static void options_load_color_profiles(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + + READ_BOOL(options->color_profile, enabled); + READ_BOOL(options->color_profile, use_image); + READ_INT(options->color_profile, input_type); + READ_INT(options->color_profile, screen_type); + READ_CHAR(options->color_profile, screen_file); + + DEBUG_1("unknown attribute %s = %s", option, value); + } + +} + +static void options_load_profile(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + gint i = GPOINTER_TO_INT(data); + if (i < 0 || i >= COLOR_PROFILE_INPUTS) return; + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + READ_CHAR_FULL("input_file", options->color_profile.input_file[i]); + READ_CHAR_FULL("input_name", options->color_profile.input_name[i]); + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + i++; + options_parse_func_set_data(parser_data, GINT_TO_POINTER(i)); + +} + + + +/* + *----------------------------------------------------------------------------- + * xml file structure (private) + *----------------------------------------------------------------------------- + */ +void options_parse_leaf(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + DEBUG_1("unexpected: %s", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); +} + +static void options_parse_color_profiles(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, "profile") == 0) + { + options_load_profile(parser_data, context, element_name, attribute_names, attribute_values, data, error); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + DEBUG_1("unexpected profile: %s", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + +static void options_parse_filter(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, "file_type") == 0) + { + filter_load_file_type(attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + DEBUG_1("unexpected filter: %s", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + +static void options_parse_filter_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + DEBUG_1(" filter end"); + filter_add_defaults(); + filter_rebuild(); +} + +static void options_parse_global(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, "color_profiles") == 0) + { + options_load_color_profiles(parser_data, context, element_name, attribute_names, attribute_values, data, error); + options_parse_func_push(parser_data, options_parse_color_profiles, NULL, GINT_TO_POINTER(0)); + } + else if (g_ascii_strcasecmp(element_name, "filter") == 0) + { + options_parse_func_push(parser_data, options_parse_filter, options_parse_filter_end, NULL); + } + else if (g_ascii_strcasecmp(element_name, "layout") == 0) + { + layout_load_attributes(&options->layout, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + DEBUG_1("unexpected global: %s", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + +static void options_parse_global_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + DEBUG_1(" global end"); + init_after_global_options(); +} + +static void options_parse_bar(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + GtkWidget *bar = data; + if (g_ascii_strcasecmp(element_name, "pane_comment") == 0) + { + GtkWidget *pane = bar_pane_comment_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else if (g_ascii_strcasecmp(element_name, "pane_exif") == 0) + { + GtkWidget *pane = bar_pane_exif_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else if (g_ascii_strcasecmp(element_name, "pane_histogram") == 0) + { + GtkWidget *pane = bar_pane_histogram_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else if (g_ascii_strcasecmp(element_name, "pane_keywords") == 0) + { + GtkWidget *pane = bar_pane_keywords_new_from_config(attribute_names, attribute_values); + bar_add(bar, pane); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + DEBUG_1("unexpected in <bar>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + +static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + LayoutWindow *lw = data; + if (g_ascii_strcasecmp(element_name, "bar") == 0) + { + if (lw->bar) + layout_bar_close(lw); + layout_bar_new(lw, FALSE); + options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar); + } + else + { + DEBUG_1("unexpected in <layout>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + +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) + { + load_global_params(attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_global, options_parse_global_end, NULL); + } + else if (g_ascii_strcasecmp(element_name, "layout") == 0) + { + LayoutWindow *lw; + lw = layout_new_from_config(attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_layout, NULL, lw); + } + else + { + DEBUG_1("unexpected in <toplevel>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + + + + + +/* + *----------------------------------------------------------------------------- + * parser + *----------------------------------------------------------------------------- + */ + + +struct _GQParserFuncData +{ + GQParserStartFunc start_func; + GQParserEndFunc end_func; +// GQParserTextFunc text_func; + gpointer data; +}; + +struct _GQParserData +{ + GList *parse_func_stack; +}; + +void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data) +{ + GQParserFuncData *func_data = g_new0(GQParserFuncData, 1); + func_data->start_func = start_func; + func_data->end_func = end_func; + func_data->data = data; + + parser_data->parse_func_stack = g_list_prepend(parser_data->parse_func_stack, func_data); +} + +void options_parse_func_pop(GQParserData *parser_data) +{ + g_free(parser_data->parse_func_stack->data); + parser_data->parse_func_stack = g_list_delete_link(parser_data->parse_func_stack, parser_data->parse_func_stack); +} + +void options_parse_func_set_data(GQParserData *parser_data, gpointer data) +{ + GQParserFuncData *func = parser_data->parse_func_stack->data; + func->data = data; +} + + +static void start_element(GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + GQParserData *parser_data = user_data; + GQParserFuncData *func = parser_data->parse_func_stack->data; + DEBUG_1("start %s", element_name); + + if (func->start_func) + func->start_func(parser_data, context, element_name, attribute_names, attribute_values, func->data, error); +} + +static void end_element(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + GQParserData *parser_data = user_data; + GQParserFuncData *func = parser_data->parse_func_stack->data; + DEBUG_1("end %s", element_name); + + if (func->end_func) + func->end_func(parser_data, context, element_name, func->data, error); + + options_parse_func_pop(parser_data); +} + +static GMarkupParser parser = { + start_element, + end_element, + NULL, + NULL, + NULL +}; /* *----------------------------------------------------------------------------- @@ -579,348 +1007,37 @@ *----------------------------------------------------------------------------- */ -static gboolean is_numbered_option(const gchar *option, const gchar *prefix, gint *number) -{ - gsize n; - gsize option_len = strlen(option); - gsize prefix_len = strlen(prefix); - - if (option_len <= prefix_len) return FALSE; - if (g_ascii_strncasecmp(option, prefix, prefix_len) != 0) return FALSE; - - n = prefix_len; - while (g_ascii_isdigit(option[n])) n++; - if (n < option_len) return FALSE; - - if (number) *number = atoi(option + prefix_len); - return TRUE; -} - -#define OPTION_READ_BUFFER_SIZE 1024 - gboolean load_options_from(const gchar *utf8_path, ConfOptions *options) { - FILE *f; - gchar *rc_pathl; - gchar s_buf[OPTION_READ_BUFFER_SIZE]; - gchar value_all[OPTION_READ_BUFFER_SIZE]; - gchar *option; - gchar *value; - gint i; - - rc_pathl = path_from_utf8(utf8_path); - f = fopen(rc_pathl,"r"); - g_free(rc_pathl); - if (!f) return FALSE; - - while (fgets(s_buf, sizeof(s_buf), f)) - { - gchar *value_end; - gchar *p = s_buf; - - /* skip empty lines and comments */ - while (g_ascii_isspace(*p)) p++; - if (!*p || *p == '\n' || *p == '#') continue; - - /* parse option name */ - option = p; - while (g_ascii_isalnum(*p) || *p == '_' || *p == '.') p++; - if (!*p) continue; - *p = '\0'; - p++; - - /* search for value start, name and value are normally separated by ': ' - * but we allow relaxed syntax here, so '=', ':=' or just a tab will work too */ - while (*p == ':' || g_ascii_isspace(*p) || *p == '=') p++; - value = p; - - while (*p && !g_ascii_isspace(*p) && *p != '\n') p++; - value_end = p; /* value part up to the first whitespace or end of line */ - while (*p != '\0') p++; - memcpy(value_all, value, 1 + p - value); - - *value_end = '\0'; - -#define READ_BOOL(_name_) if (read_bool_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_INT(_name_) if (read_int_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_UINT(_name_) if (read_uint_option(f, option, #_name_, value, &options->_name_)) continue; -#define READ_INT_CLAMP(_name_, _min_, _max_) if (read_int_option_clamp(f, option, #_name_, value, &options->_name_, _min_, _max_)) continue; -#define READ_UINT_CLAMP(_name_, _min_, _max_) if (read_uint_option_clamp(f, option, #_name_, value, &options->_name_, _min_, _max_)) continue; -#define READ_INT_UNIT(_name_, _unit_) if (read_int_unit_option(f, option, #_name_, value, &options->_name_, _unit_)) continue; -#define READ_CHAR(_name_) if (read_char_option(f, option, #_name_, value_all, &options->_name_)) continue; -#define READ_COLOR(_name_) if (read_color_option(f, option, #_name_, value, &options->_name_)) continue; - -#define COMPAT_READ_BOOL(_oldname_, _name_) if (read_bool_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_INT(_oldname_, _name_) if (read_int_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_UINT(_oldname_, _name_) if (read_uint_option(f, option, #_oldname_, value, &options->_name_)) continue; -#define COMPAT_READ_INT_CLAMP(_oldname_, _name_, _min_, _max_) if (read_int_option_clamp(f, option, #_oldname_, value, &options->_name_, _min_, _max_)) continue; -#define COMPAT_READ_INT_UNIT(_oldname_, _name_, _unit_) if (read_int_unit_option(f, option, #_oldname_, value, &options->_name_, _unit_)) continue; -#define COMPAT_READ_CHAR(_oldname_, _name_) if (read_char_option(f, option, #_oldname_, value_all, &options->_name_)) continue; -#define COMPAT_READ_COLOR(_oldname_, _name_) if (read_color_option(f, option, #_oldname_, value, &options->_name_)) continue; - - /* general options */ - READ_BOOL(show_icon_names); - READ_BOOL(show_copy_path); - - READ_BOOL(tree_descend_subdirs); - READ_BOOL(lazy_image_sync); - READ_BOOL(update_on_time_change); - - READ_UINT_CLAMP(duplicates_similarity_threshold, 0, 100); - - READ_BOOL(progressive_key_scrolling); - - READ_BOOL(mousewheel_scrolls); - - READ_INT(open_recent_list_maxsize); - READ_INT(dnd_icon_size); - READ_BOOL(place_dialogs_under_mouse); - - /* startup options */ - - COMPAT_READ_BOOL(startup_path_enable, startup.restore_path); /* 2008/05/11 */ - READ_BOOL(startup.restore_path); - - READ_BOOL(startup.use_last_path); + gsize size; + gchar *buf; + GMarkupParseContext *context; + gboolean ret = TRUE; + GQParserData *parser_data; - COMPAT_READ_CHAR(startup_path, startup.path); /* 2008/05/11 */ - READ_CHAR(startup.path); + if (g_file_get_contents (utf8_path, &buf, &size, NULL) == FALSE) + { + return FALSE; + } - /* layout options */ - - READ_INT(layout.style); - READ_CHAR(layout.order); - - COMPAT_READ_UINT(layout.view_as_icons, layout.file_view_type); /* 2008/05/03 */ - - READ_UINT(layout.dir_view_type); - READ_UINT(layout.file_view_type); - READ_BOOL(layout.show_marks); - READ_BOOL(layout.show_thumbnails); - READ_BOOL(layout.show_directory_date); - READ_CHAR(layout.home_path); - - /* window positions */ - - READ_BOOL(layout.save_window_positions); - - READ_INT(layout.main_window.x); - READ_INT(layout.main_window.y); - READ_INT(layout.main_window.w); - READ_INT(layout.main_window.h); - READ_BOOL(layout.main_window.maximized); - READ_INT(layout.main_window.hdivider_pos); - READ_INT(layout.main_window.vdivider_pos); - - READ_INT(layout.float_window.x); - READ_INT(layout.float_window.y); - READ_INT(layout.float_window.w); - READ_INT(layout.float_window.h); - READ_INT(layout.float_window.vdivider_pos); + parser_data = g_new0(GQParserData, 1); + options_parse_func_push(parser_data, options_parse_toplevel, NULL, NULL); - READ_INT(layout.properties_window.w); - READ_INT(layout.properties_window.h); - - READ_BOOL(layout.tools_float); - READ_BOOL(layout.tools_hidden); - READ_BOOL(layout.tools_restore_state); - READ_BOOL(layout.toolbar_hidden); + context = g_markup_parse_context_new(&parser, 0, parser_data, NULL); - /* panels */ - READ_BOOL(panels.exif.enabled); - READ_INT_CLAMP(panels.exif.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); - READ_BOOL(panels.info.enabled); - READ_INT_CLAMP(panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH); - READ_BOOL(panels.sort.enabled); - READ_INT(panels.sort.action_state); - READ_INT(panels.sort.mode_state); - READ_INT(panels.sort.selection_state); - READ_CHAR(panels.sort.action_filter); - - /* properties dialog options */ - READ_CHAR(properties.tabs_order); + if (g_markup_parse_context_parse (context, buf, size, NULL) == FALSE) + { + ret = FALSE; + DEBUG_1("Parse failed"); + } + + g_free(parser_data); - /* image options */ - if (g_ascii_strcasecmp(option, "image.zoom_mode") == 0) - { - if (g_ascii_strcasecmp(value, "original") == 0) - options->image.zoom_mode = ZOOM_RESET_ORIGINAL; - else if (g_ascii_strcasecmp(value, "fit") == 0) - options->image.zoom_mode = ZOOM_RESET_FIT_WINDOW; - else if (g_ascii_strcasecmp(value, "dont_change") == 0) - options->image.zoom_mode = ZOOM_RESET_NONE; - continue; - } - READ_BOOL(image.zoom_2pass); - READ_BOOL(image.zoom_to_fit_allow_expand); - READ_BOOL(image.fit_window_to_image); - READ_BOOL(image.limit_window_size); - READ_INT(image.max_window_size); - READ_BOOL(image.limit_autofit_size); - READ_INT(image.max_autofit_size); - READ_UINT_CLAMP(image.scroll_reset_method, 0, PR_SCROLL_RESET_COUNT - 1); - READ_INT(image.tile_cache_max); - READ_INT(image.image_cache_max); - READ_UINT_CLAMP(image.zoom_quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); - READ_UINT_CLAMP(image.dither_quality, GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX); - READ_INT(image.zoom_increment); - READ_BOOL(image.enable_read_ahead); - READ_BOOL(image.exif_rotate_enable); - READ_BOOL(image.use_custom_border_color); - READ_COLOR(image.border_color); - READ_INT_CLAMP(image.read_buffer_size, IMAGE_LOADER_READ_BUFFER_SIZE_MIN, IMAGE_LOADER_READ_BUFFER_SIZE_MAX); - READ_INT_CLAMP(image.idle_read_loop_count, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MIN, IMAGE_LOADER_IDLE_READ_LOOP_COUNT_MAX); + g_free(buf); + g_markup_parse_context_free (context); + return ret; +} + - /* thumbnails options */ - READ_INT_CLAMP(thumbnails.max_width, 16, 512); - READ_INT_CLAMP(thumbnails.max_height, 16, 512); - - READ_BOOL(thumbnails.enable_caching); - READ_BOOL(thumbnails.cache_into_dirs); - READ_BOOL(thumbnails.fast); - READ_BOOL(thumbnails.use_xvpics); - READ_BOOL(thumbnails.spec_standard); - READ_UINT_CLAMP(thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER); - READ_BOOL(thumbnails.use_exif); - - /* file sorting options */ - READ_UINT(file_sort.method); - READ_BOOL(file_sort.ascending); - READ_BOOL(file_sort.case_sensitive); - - /* file operations options */ - READ_BOOL(file_ops.enable_in_place_rename); - READ_BOOL(file_ops.confirm_delete); - READ_BOOL(file_ops.enable_delete_key); - READ_BOOL(file_ops.safe_delete_enable); - READ_CHAR(file_ops.safe_delete_path); - READ_INT(file_ops.safe_delete_folder_maxsize); - - /* fullscreen options */ - READ_INT(fullscreen.screen); - READ_BOOL(fullscreen.clean_flip); - READ_BOOL(fullscreen.disable_saver); - READ_BOOL(fullscreen.above); - - /* histogram */ - READ_UINT(histogram.last_channel_mode); - READ_UINT(histogram.last_log_mode); - - /* image overlay */ - COMPAT_READ_UINT(image_overlay.common.enabled, image_overlay.common.state); /* 2008-05-12 */ - READ_UINT(image_overlay.common.state); - COMPAT_READ_BOOL(fullscreen.show_info, image_overlay.common.show_at_startup); /* 2008-04-21 */ - READ_BOOL(image_overlay.common.show_at_startup); - COMPAT_READ_CHAR(fullscreen.info, image_overlay.common.template_string); /* 2008-04-21 */ - READ_CHAR(image_overlay.common.template_string); - - READ_INT(image_overlay.common.x); - READ_INT(image_overlay.common.y); - - - /* slideshow options */ - READ_INT_UNIT(slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); - READ_BOOL(slideshow.random); - READ_BOOL(slideshow.repeat); - - /* collection options */ - - READ_BOOL(collections.rectangular_selection); - - /* filtering options */ - - READ_BOOL(file_filter.show_hidden_files); - READ_BOOL(file_filter.show_dot_directory); - READ_BOOL(file_filter.disable); - - if (g_ascii_strcasecmp(option, "file_filter.ext") == 0) - { - filter_parse(value_all); - continue; - } - - READ_CHAR(sidecar.ext); - - /* Color Profiles */ - - READ_BOOL(color_profile.enabled); - READ_BOOL(color_profile.use_image); - READ_INT(color_profile.input_type); - - if (is_numbered_option(option, "color_profile.input_file_", &i)) - { - if (i > 0 && i <= COLOR_PROFILE_INPUTS) - { - i--; - read_char_option(f, option, option, value, &options->color_profile.input_file[i]); - } - continue; - } - - if (is_numbered_option(option, "color_profile.input_name_", &i)) - { - if (i > 0 && i <= COLOR_PROFILE_INPUTS) - { - i--; - read_char_option(f, option, option, value, &options->color_profile.input_name[i]); - } - continue; - } - - READ_INT(color_profile.screen_type); - READ_CHAR(color_profile.screen_file); - - /* Shell command */ - READ_CHAR(shell.path); - READ_CHAR(shell.options); - - /* Helpers */ - READ_CHAR(helpers.html_browser.command_name); - READ_CHAR(helpers.html_browser.command_line); - - /* External Programs */ -#if 0 - if (is_numbered_option(option, "external_", &i)) - { - if (i > 0 && i <= GQ_EDITOR_SLOTS) - { - const gchar *ptr; - - i--; - editor_set_name(i, quoted_value(value_all, &ptr)); - editor_set_command(i, quoted_value(ptr, NULL)); - } - continue; - } -#endif - /* Exif */ - if (0 == g_ascii_strncasecmp(option, "exif.display.", 13)) - { - for (i = 0; ExifUIList[i].key; i++) - if (0 == g_ascii_strcasecmp(option + 13, ExifUIList[i].key)) - ExifUIList[i].current = strtol(value, NULL, 10); - continue; - } - - /* metadata */ - COMPAT_READ_BOOL(enable_metadata_dirs, metadata.enable_metadata_dirs); /* 2008/12/20 */ - READ_BOOL(metadata.enable_metadata_dirs); - COMPAT_READ_BOOL(save_metadata_in_image_file, metadata.save_in_image_file); /* 2008/12/20 */ - READ_BOOL(metadata.save_in_image_file); - READ_BOOL(metadata.save_legacy_IPTC); - READ_BOOL(metadata.warn_on_write_problems); - READ_BOOL(metadata.save_legacy_format); - READ_BOOL(metadata.sync_grouped_files); - READ_BOOL(metadata.confirm_write); - READ_BOOL(metadata.confirm_after_timeout); - READ_INT(metadata.confirm_timeout); - READ_BOOL(metadata.confirm_on_image_change); - READ_BOOL(metadata.confirm_on_dir_change); - - } - - fclose(f); - return TRUE; -} /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/rcfile.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/rcfile.h Sun Feb 22 15:35:37 2009 +0000 @@ -14,8 +14,67 @@ #ifndef RCFILE_H #define RCFILE_H + +void write_indent(GString *str, gint indent); +void write_char_option(GString *str, gint indent, const gchar *label, const gchar *text); +gboolean read_char_option(const gchar *option, const gchar *label, const gchar *value, gchar **text); +void write_color_option(GString *str, gint indent, gchar *label, GdkColor *color); +gboolean read_color_option(const gchar *option, const gchar *label, const gchar *value, GdkColor *color); +void write_int_option(GString *str, gint indent, const gchar *label, gint n); +gboolean read_int_option(const gchar *option, const gchar *label, const gchar *value, gint *n); +void write_uint_option(GString *str, gint indent, const gchar *label, guint n); +gboolean read_uint_option(const gchar *option, const gchar *label, const gchar *value, guint *n); +gboolean read_uint_option_clamp(const gchar *option, const gchar *label, const gchar *value, guint *n, guint min, guint max); +gboolean read_int_option_clamp(const gchar *option, const gchar *label, const gchar *value, gint *n, gint min, gint max); +void write_int_unit_option(GString *str, gint indent, gchar *label, gint n, gint subunits); +gboolean read_int_unit_option(const gchar *option, const gchar *label, const gchar *value, gint *n, gint subunits); +void write_bool_option(GString *str, gint indent, gchar *label, gint n); +gboolean read_bool_option(const gchar *option, const gchar *label, const gchar *value, gint *n); + +#define WRITE_BOOL(source, _name_) write_bool_option(outstr, indent, #_name_, (source)._name_) +#define WRITE_INT(source, _name_) write_int_option(outstr, indent, #_name_, (source)._name_) +#define WRITE_UINT(source, _name_) write_uint_option(outstr, indent, #_name_, (source)._name_) +#define WRITE_INT_UNIT(source, _name_, _unit_) write_int_unit_option(outstr, indent, #_name_, (source)._name_, _unit_) +#define WRITE_CHAR(source, _name_) write_char_option(outstr, indent, #_name_, (source)._name_) +#define WRITE_COLOR(source, _name_) write_color_option(outstr, indent, #_name_, &(source)._name_) + +#define WRITE_SEPARATOR() g_string_append(outstr, "\n") +#define WRITE_SUBTITLE(_title_) g_string_append_printf(outstr, "\n\n<!-- "_title_" -->\n\n") + + +#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; +#define READ_UINT(target, _name_) if (read_uint_option(option, #_name_, value, &(target)._name_)) continue; +#define READ_INT_CLAMP(target, _name_, _min_, _max_) if (read_int_option_clamp(option, #_name_, value, &(target)._name_, _min_, _max_)) continue; +#define READ_UINT_CLAMP(target, _name_, _min_, _max_) if (read_uint_option_clamp(option, #_name_, value, &(target)._name_, _min_, _max_)) continue; +#define READ_INT_UNIT(target, _name_, _unit_) if (read_int_unit_option(option, #_name_, value, &(target)._name_, _unit_)) continue; +#define READ_CHAR(target, _name_) if (read_char_option(option, #_name_, value, &(target)._name_)) continue; +#define READ_COLOR(target, _name_) if (read_color_option(option, #_name_, value, &(target)._name_)) continue; + +#define READ_BOOL_FULL(name, target) if (read_bool_option(option, name, value, &(target))) continue; +#define READ_INT_FULL(name, target) if (read_int_option(option, name, value, &(target))) continue; +#define READ_UINT_FULL(name, target) if (read_uint_option(option, name, value, &(target))) continue; +#define READ_INT_CLAMP_FULL(name, target, _min_, _max_) if (read_int_option_clamp(option, name, value, &(target), _min_, _max_)) continue; +#define READ_INT_UNIT_FULL(name, target, _unit_) if (read_int_unit_option(option, name, value, &(target), _unit_)) continue; +#define READ_CHAR_FULL(name, target) if (read_char_option(option, name, value, &(target))) continue; +#define READ_COLOR_FULL(name, target) if (read_color_option(option, name, value, &(target))) continue; + + + + +typedef struct _GQParserFuncData GQParserFuncData; +typedef struct _GQParserData GQParserData; +typedef void (* GQParserStartFunc)(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error); +typedef void (* GQParserEndFunc)(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error); + +void options_parse_func_push(GQParserData *parser_data, GQParserStartFunc start_func, GQParserEndFunc end_func, gpointer data); +void options_parse_func_pop(GQParserData *parser_data); +void options_parse_func_set_data(GQParserData *parser_data, gpointer data); + + gboolean save_options_to(const gchar *utf8_path, ConfOptions *options); gboolean load_options_from(const gchar *utf8_path, ConfOptions *options); + #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/typedefs.h Sun Feb 22 13:29:49 2009 +0000 +++ b/src/typedefs.h Sun Feb 22 15:35:37 2009 +0000 @@ -186,6 +186,7 @@ typedef struct _FileDataChangeInfo FileDataChangeInfo; typedef struct _LayoutWindow LayoutWindow; +typedef struct _LayoutOptions LayoutOptions; typedef struct _ViewDir ViewDir; typedef struct _ViewDirInfoList ViewDirInfoList; @@ -466,8 +467,78 @@ GHashTable *modified_xmp; // hash table which contains unwritten xmp metadata in format: key->list of string values }; +struct _LayoutOptions +{ + gchar *order; + gint style; + + DirViewType dir_view_type; + FileViewType file_view_type; + + gboolean show_thumbnails; + gboolean show_marks; + gboolean show_directory_date; + + struct { + gint w; + gint h; + gint x; + gint y; + gboolean maximized; + gint hdivider_pos; + gint vdivider_pos; + } main_window; + + struct { + gint w; + gint h; + gint x; + gint y; + gint vdivider_pos; + } float_window; + + struct { + gint w; + gint h; + } properties_window; + + gboolean save_window_positions; + + gboolean tools_float; + gboolean tools_hidden; + gboolean tools_restore_state; + + gboolean toolbar_hidden; + + gchar *home_path; + + /* panels */ + struct { + struct { + gboolean enabled; + gint width; + } info; + + struct { + gboolean enabled; + gint width; + } exif; + + struct { + gboolean enabled; + gint mode_state; + gint action_state; + gint selection_state; + gchar *action_filter; + } sort; + } panels; + +}; + struct _LayoutWindow { + LayoutOptions options; + FileData *dir_fd; /* base */ @@ -506,17 +577,17 @@ GtkWidget *tools; GtkWidget *tools_pane; - gint tools_float; - gint tools_hidden; +// gint tools_float; +// gint tools_hidden; /* toolbar */ GtkWidget *toolbar; - gint toolbar_hidden; +// gint toolbar_hidden; GtkWidget *thumb_button; - gint thumbs_enabled; - gint marks_enabled; +// gint thumbs_enabled; +// gint marks_enabled; GtkWidget *back_button; @@ -527,7 +598,7 @@ ViewDir *vd; GtkWidget *dir_view; - DirViewType dir_view_type; +// DirViewType dir_view_type; /* file view */ @@ -562,9 +633,9 @@ /* dividers */ - gint div_h; - gint div_v; - gint div_float; +// gint div_h; +// gint div_v; +// gint div_float; /* misc */ @@ -572,10 +643,10 @@ GtkWidget *bar_sort; GtkWidget *bar; - gint bar_sort_enabled; - gint bar_enabled; +// gint bar_sort_enabled; +// gint bar_enabled; - gint bar_width; +// gint bar_width; GtkWidget *exif_window; };
--- a/src/view_file.c Sun Feb 22 13:29:49 2009 +0000 +++ b/src/view_file.c Sun Feb 22 15:35:37 2009 +0000 @@ -447,10 +447,10 @@ switch(vf->layout->file_view_type) { case FILEVIEW_LIST: - layout_views_set(vf->layout, vf->layout->dir_view_type, FILEVIEW_ICON); + layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_ICON); break; case FILEVIEW_ICON: - layout_views_set(vf->layout, vf->layout->dir_view_type, FILEVIEW_LIST); + layout_views_set(vf->layout, vf->layout->options.dir_view_type, FILEVIEW_LIST); break; } }