Move LayoutOptions to layout
authorArkadiy Illarionov <[email protected]>
Sat, 1 Mar 2025 10:30:50 +0000 (13:30 +0300)
committerColin Clark <[email protected]>
Sat, 1 Mar 2025 16:34:39 +0000 (16:34 +0000)
Simplify related code.

src/command-line-handling.cc
src/layout.cc
src/layout.h
src/main.cc
src/options.cc
src/options.h

index 952ae3982f8aafb7076634c0b9a33ffb63d7b52e..1837f37cb6895c634ea4585c5e973065e700454f 100644 (file)
@@ -41,6 +41,7 @@
 #include "main-defines.h"
 #include "main.h"
 #include "misc.h"
+#include "options.h"
 #include "pixbuf-renderer.h"
 #include "rcfile.h"
 #include "secure-save.h"
index 3567f855fef673fcde22367a6c57e1155e04a926..d70b222c4e11e8d4bf2c40479c497da1b2a46207 100644 (file)
@@ -52,6 +52,7 @@
 #include "menu.h"
 #include "metadata.h"
 #include "misc.h"
+#include "options.h"
 #include "pixbuf-util.h"
 #include "preferences.h"
 #include "rcfile.h"
@@ -114,6 +115,199 @@ LayoutWindow *layout_window_find_by_options_id(const gchar *id)
        return *it;
 }
 
+void layout_load_attributes(LayoutOptions &lop, const gchar **attribute_names, const gchar **attribute_values)
+{
+       g_autofree gchar *id = nullptr;
+
+       while (*attribute_names)
+               {
+               const gchar *option = *attribute_names++;
+               const gchar *value = *attribute_values++;
+
+               /* layout options */
+               if (READ_CHAR_FULL("id", id)) continue;
+
+               if (READ_INT(lop, style)) continue;
+               if (READ_CHAR(lop, order)) continue;
+
+               if (READ_UINT_ENUM(lop, dir_view_type)) continue;
+               if (READ_UINT_ENUM(lop, file_view_type)) continue;
+               if (READ_UINT_ENUM(lop, file_view_list_sort.method)) continue;
+               if (READ_BOOL(lop, file_view_list_sort.ascend)) continue;
+               if (READ_BOOL(lop, file_view_list_sort.case_sensitive)) continue;
+               if (READ_UINT_ENUM(lop, dir_view_list_sort.method)) continue;
+               if (READ_BOOL(lop, dir_view_list_sort.ascend)) continue;
+               if (READ_BOOL(lop, dir_view_list_sort.case_sensitive)) continue;
+               if (READ_BOOL(lop, show_marks)) continue;
+               if (READ_BOOL(lop, show_file_filter)) continue;
+               if (READ_BOOL(lop, show_thumbnails)) continue;
+               if (READ_BOOL(lop, show_directory_date)) continue;
+               if (READ_CHAR(lop, home_path)) continue;
+               if (READ_UINT_ENUM_CLAMP(lop, startup_path, 0, STARTUP_PATH_HOME)) continue;
+
+               /* window positions */
+
+               if (READ_INT_FULL("main_window.x", lop.main_window.rect.x)) continue;
+               if (READ_INT_FULL("main_window.y", lop.main_window.rect.y)) continue;
+               if (READ_INT_FULL("main_window.w", lop.main_window.rect.width)) continue;
+               if (READ_INT_FULL("main_window.h", lop.main_window.rect.height)) continue;
+               if (READ_BOOL(lop, main_window.maximized)) continue;
+               if (READ_INT(lop, main_window.hdivider_pos)) continue;
+               if (READ_INT(lop, main_window.vdivider_pos)) continue;
+
+               if (READ_INT_CLAMP(lop, folder_window.vdivider_pos, 1, 1000)) continue;
+
+               if (READ_INT_FULL("float_window.x", lop.float_window.rect.x)) continue;
+               if (READ_INT_FULL("float_window.y", lop.float_window.rect.y)) continue;
+               if (READ_INT_FULL("float_window.w", lop.float_window.rect.width)) continue;
+               if (READ_INT_FULL("float_window.h", lop.float_window.rect.height)) continue;
+               if (READ_INT(lop, float_window.vdivider_pos)) continue;
+
+               if (READ_BOOL(lop, tools_float)) continue;
+               if (READ_BOOL(lop, tools_hidden)) continue;
+               if (READ_BOOL(lop, show_info_pixel)) continue;
+               if (READ_BOOL(lop, ignore_alpha)) continue;
+
+               if (READ_BOOL(lop, bars_state.info)) continue;
+               if (READ_BOOL(lop, bars_state.sort)) continue;
+               if (READ_BOOL(lop, bars_state.tools_float)) continue;
+               if (READ_BOOL(lop, bars_state.tools_hidden)) continue;
+               if (READ_BOOL(lop, bars_state.hidden)) continue;
+
+               if (READ_UINT(lop, image_overlay.state)) continue;
+               if (READ_INT(lop, image_overlay.histogram_channel)) continue;
+               if (READ_INT(lop, image_overlay.histogram_mode)) continue;
+
+               if (READ_INT(lop, log_window.x)) continue;
+               if (READ_INT(lop, log_window.y)) continue;
+               if (READ_INT(lop, log_window.width)) continue;
+               if (READ_INT(lop, log_window.height)) continue;
+
+               if (READ_INT_FULL("preferences_window.x", lop.preferences_window.rect.x)) continue;
+               if (READ_INT_FULL("preferences_window.y", lop.preferences_window.rect.y)) continue;
+               if (READ_INT_FULL("preferences_window.w", lop.preferences_window.rect.width)) continue;
+               if (READ_INT_FULL("preferences_window.h", lop.preferences_window.rect.height)) continue;
+               if (READ_INT(lop, preferences_window.page_number)) continue;
+
+               if (READ_INT(lop, search_window.x)) continue;
+               if (READ_INT(lop, search_window.y)) continue;
+               if (READ_INT_FULL("search_window.w", lop.search_window.width)) continue;
+               if (READ_INT_FULL("search_window.h", lop.search_window.height)) continue;
+
+               if (READ_INT(lop, dupe_window.x)) continue;
+               if (READ_INT(lop, dupe_window.y)) continue;
+               if (READ_INT_FULL("dupe_window.w", lop.dupe_window.width)) continue;
+               if (READ_INT_FULL("dupe_window.h", lop.dupe_window.height)) continue;
+
+               if (READ_INT(lop, advanced_exif_window.x)) continue;
+               if (READ_INT(lop, advanced_exif_window.y)) continue;
+               if (READ_INT_FULL("advanced_exif_window.w", lop.advanced_exif_window.width)) continue;
+               if (READ_INT_FULL("advanced_exif_window.h", lop.advanced_exif_window.height)) continue;
+
+               if (READ_BOOL(lop, animate)) continue;
+               if (READ_INT(lop, workspace)) continue;
+
+               config_file_error((std::string("Unknown attribute: ") + option + " = " + value).c_str());
+               }
+
+       if (id && !is_current_layout_id(id))
+               {
+               std::swap(lop.id, id);
+               }
+}
+
+LayoutOptions init_layout_options(const gchar **attribute_names, const gchar **attribute_values)
+{
+       LayoutOptions lop;
+       memset(&lop, 0, sizeof(LayoutOptions));
+
+       lop.dir_view_type = DIRVIEW_LIST;
+       lop.dir_view_list_sort.ascend = TRUE;
+       lop.dir_view_list_sort.case_sensitive = TRUE;
+       lop.dir_view_list_sort.method = SORT_NAME;
+       lop.file_view_list_sort.ascend = TRUE;
+       lop.file_view_list_sort.case_sensitive = TRUE;
+       lop.file_view_list_sort.method = SORT_NAME;
+       lop.file_view_type = FILEVIEW_LIST;
+       lop.float_window.rect = {0, 0, 260, 450};
+       lop.float_window.vdivider_pos = -1;
+       lop.home_path = nullptr;
+       lop.id = g_strdup("null");
+       lop.main_window.hdivider_pos = -1;
+       lop.main_window.maximized = FALSE;
+       lop.main_window.rect = {0, 0, 720, 540};
+       lop.main_window.vdivider_pos = 200;
+       lop.search_window = {100, 100, 700, 650};
+       lop.dupe_window = {100, 100, 800, 400};
+       lop.advanced_exif_window = {0, 0, 900, 600};
+       lop.folder_window.vdivider_pos = 100;
+       lop.order = g_strdup("123");
+       lop.show_directory_date = FALSE;
+       lop.show_marks = FALSE;
+       lop.show_file_filter = FALSE;
+       lop.show_thumbnails = FALSE;
+       lop.style = 0;
+       lop.show_info_pixel = FALSE;
+       lop.selectable_toolbars_hidden = FALSE;
+       lop.tools_float = FALSE;
+       lop.tools_hidden = FALSE;
+       lop.image_overlay.histogram_channel = HCHAN_RGB;
+       lop.image_overlay.histogram_mode = 1;
+       lop.image_overlay.state = OSD_SHOW_NOTHING;
+       lop.animate = TRUE;
+       lop.bars_state.hidden = FALSE;
+       lop.log_window = {0, 0, 520, 400};
+       lop.preferences_window.rect = {0, 0, 700, 600};
+       lop.split_pane_sync = FALSE;
+       lop.workspace = -1;
+
+       if (attribute_names) layout_load_attributes(lop, attribute_names, attribute_values);
+
+       return lop;
+}
+
+void free_layout_options_content(LayoutOptions &dest)
+{
+       g_free(dest.id);
+       g_free(dest.order);
+       g_free(dest.home_path);
+       g_free(dest.last_path);
+}
+
+void copy_layout_options(LayoutOptions &dest, const LayoutOptions &src)
+{
+       free_layout_options_content(dest);
+
+       dest = src;
+       dest.id = g_strdup(src.id);
+       dest.order = g_strdup(src.order);
+       dest.home_path = g_strdup(src.home_path);
+       dest.last_path = g_strdup(src.last_path);
+}
+
+void layout_options_set_unique_id(LayoutOptions &options)
+{
+       if (options.id && options.id[0]) return; /* id is already set */
+
+       g_free(options.id);
+       options.id = layout_get_unique_id();
+}
+
+void layout_apply_options(LayoutWindow *lw, const LayoutOptions &lop)
+{
+       if (!layout_valid(&lw)) return;
+
+       /** @FIXME add other options too */
+
+       gboolean refresh_style = (lop.style != lw->options.style || strcmp(lop.order, lw->options.order) != 0);
+       gboolean refresh_lists = (lop.show_directory_date != lw->options.show_directory_date);
+
+       copy_layout_options(lw->options, lop);
+
+       if (refresh_style) layout_style_set(lw, lw->options.style, lw->options.order);
+       if (refresh_lists) layout_refresh(lw);
+}
+
 } // namespace
 
 static void layout_list_scroll_to_subpart(LayoutWindow *lw, const gchar *needle);
@@ -192,14 +386,6 @@ gchar *layout_get_unique_id()
                }
 }
 
-static void layout_set_unique_id(LayoutWindow *lw)
-{
-       if (lw->options.id && lw->options.id[0]) return; /* id is already set */
-
-       g_free(lw->options.id);
-       lw->options.id = layout_get_unique_id();
-}
-
 static gboolean layout_set_current_cb(GtkWidget *, GdkEventFocus *, gpointer data)
 {
        auto lw = static_cast<LayoutWindow *>(data);
@@ -2187,7 +2373,7 @@ static void layout_config_close_cb(GtkWidget *, gpointer data)
        auto lc = static_cast<LayoutConfig *>(data);
 
        gq_gtk_widget_destroy(lc->configwindow);
-       free_layout_options_content(&lc->options);
+       free_layout_options_content(lc->options);
        g_free(lc);
 }
 
@@ -2206,7 +2392,7 @@ static void layout_config_apply_cb(GtkWidget *, gpointer data)
 
        config_entry_to_option(lc->home_path_entry, &lc->options.home_path, remove_trailing_slash);
 
-       layout_apply_options(lc->lw, &lc->options);
+       layout_apply_options(lc->lw, lc->options);
 }
 
 static void layout_config_help_cb(GtkWidget *, gpointer)
@@ -2272,7 +2458,7 @@ void layout_show_config_window(LayoutWindow *lw)
        lc = g_new0(LayoutConfig, 1);
        lc->lw = lw;
        layout_sync_options_with_current_state(lw);
-       copy_layout_options(&lc->options, &lw->options);
+       copy_layout_options(lc->options, lw->options);
 
        lc->configwindow = window_new("Layout", PIXBUF_INLINE_ICON_CONFIG, nullptr, _("Window options and layout"));
        DEBUG_NAME(lc->configwindow);
@@ -2428,23 +2614,6 @@ void layout_sync_options_with_current_state(LayoutWindow *lw)
 #endif
 }
 
-void layout_apply_options(LayoutWindow *lw, LayoutOptions *lop)
-{
-       gboolean refresh_style;
-       gboolean refresh_lists;
-
-       if (!layout_valid(&lw)) return;
-/** @FIXME add other options too */
-
-       refresh_style = (lop->style != lw->options.style || strcmp(lop->order, lw->options.order) != 0);
-       refresh_lists = (lop->show_directory_date != lw->options.show_directory_date);
-
-       copy_layout_options(&lw->options, lop);
-
-       if (refresh_style) layout_style_set(lw, lw->options.style, lw->options.order);
-       if (refresh_lists) layout_refresh(lw);
-}
-
 void save_layout(LayoutWindow *lw)
 {
        if (g_str_has_prefix(lw->options.id, "lw")) return;
@@ -2501,7 +2670,7 @@ void layout_free(LayoutWindow *lw)
                file_data_unref(lw->dir_fd);
                }
 
-       free_layout_options_content(&lw->options);
+       free_layout_options_content(lw->options);
        g_free(lw);
 }
 
@@ -2547,9 +2716,9 @@ static LayoutWindow *layout_new(const LayoutOptions &lop)
        DEBUG_1("%s layout_new: start", get_exec_time());
        lw = g_new0(LayoutWindow, 1);
 
-       copy_layout_options(&lw->options, &lop);
+       copy_layout_options(lw->options, lop);
 
-       layout_set_unique_id(lw);
+       layout_options_set_unique_id(lw->options);
 
        /* default layout */
 
@@ -2662,97 +2831,97 @@ static LayoutWindow *layout_new(const LayoutOptions &lop)
        return lw;
 }
 
-void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent)
+static void layout_write_attributes(const LayoutOptions &lop, GString *outstr, gint indent)
 {
-       WRITE_NL(); WRITE_CHAR(*layout, id);
+       WRITE_NL(); WRITE_CHAR(lop, id);
 
-       WRITE_NL(); WRITE_INT(*layout, style);
-       WRITE_NL(); WRITE_CHAR(*layout, order);
-       WRITE_NL(); WRITE_UINT(*layout, dir_view_type);
-       WRITE_NL(); WRITE_UINT(*layout, file_view_type);
+       WRITE_NL(); WRITE_INT(lop, style);
+       WRITE_NL(); WRITE_CHAR(lop, order);
+       WRITE_NL(); WRITE_UINT(lop, dir_view_type);
+       WRITE_NL(); WRITE_UINT(lop, file_view_type);
 
-       WRITE_NL(); WRITE_UINT(*layout, file_view_list_sort.method);
-       WRITE_NL(); WRITE_BOOL(*layout, file_view_list_sort.ascend);
-       WRITE_NL(); WRITE_BOOL(*layout, file_view_list_sort.case_sensitive);
+       WRITE_NL(); WRITE_UINT(lop, file_view_list_sort.method);
+       WRITE_NL(); WRITE_BOOL(lop, file_view_list_sort.ascend);
+       WRITE_NL(); WRITE_BOOL(lop, file_view_list_sort.case_sensitive);
 
-       WRITE_NL(); WRITE_UINT(*layout, dir_view_list_sort.method);
-       WRITE_NL(); WRITE_BOOL(*layout, dir_view_list_sort.ascend);
-       WRITE_NL(); WRITE_BOOL(*layout, dir_view_list_sort.case_sensitive);
-       WRITE_NL(); WRITE_BOOL(*layout, show_marks);
-       WRITE_NL(); WRITE_BOOL(*layout, show_file_filter);
-       WRITE_NL(); WRITE_BOOL(*layout, show_thumbnails);
-       WRITE_NL(); WRITE_BOOL(*layout, show_directory_date);
-       WRITE_NL(); WRITE_CHAR(*layout, home_path);
-       WRITE_NL(); WRITE_UINT(*layout, startup_path);
+       WRITE_NL(); WRITE_UINT(lop, dir_view_list_sort.method);
+       WRITE_NL(); WRITE_BOOL(lop, dir_view_list_sort.ascend);
+       WRITE_NL(); WRITE_BOOL(lop, dir_view_list_sort.case_sensitive);
+       WRITE_NL(); WRITE_BOOL(lop, show_marks);
+       WRITE_NL(); WRITE_BOOL(lop, show_file_filter);
+       WRITE_NL(); WRITE_BOOL(lop, show_thumbnails);
+       WRITE_NL(); WRITE_BOOL(lop, show_directory_date);
+       WRITE_NL(); WRITE_CHAR(lop, home_path);
+       WRITE_NL(); WRITE_UINT(lop, startup_path);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_INT_FULL("main_window.x", layout->main_window.rect.x);
-       WRITE_NL(); WRITE_INT_FULL("main_window.y", layout->main_window.rect.y);
-       WRITE_NL(); WRITE_INT_FULL("main_window.w", layout->main_window.rect.width);
-       WRITE_NL(); WRITE_INT_FULL("main_window.h", layout->main_window.rect.height);
-       WRITE_NL(); WRITE_BOOL(*layout, main_window.maximized);
-       WRITE_NL(); WRITE_INT(*layout, main_window.hdivider_pos);
-       WRITE_NL(); WRITE_INT(*layout, main_window.vdivider_pos);
-       WRITE_NL(); WRITE_INT(*layout, workspace);
+       WRITE_NL(); WRITE_INT_FULL("main_window.x", lop.main_window.rect.x);
+       WRITE_NL(); WRITE_INT_FULL("main_window.y", lop.main_window.rect.y);
+       WRITE_NL(); WRITE_INT_FULL("main_window.w", lop.main_window.rect.width);
+       WRITE_NL(); WRITE_INT_FULL("main_window.h", lop.main_window.rect.height);
+       WRITE_NL(); WRITE_BOOL(lop, main_window.maximized);
+       WRITE_NL(); WRITE_INT(lop, main_window.hdivider_pos);
+       WRITE_NL(); WRITE_INT(lop, main_window.vdivider_pos);
+       WRITE_NL(); WRITE_INT(lop, workspace);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_INT(*layout, folder_window.vdivider_pos);
+       WRITE_NL(); WRITE_INT(lop, folder_window.vdivider_pos);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_INT_FULL("float_window.x", layout->float_window.rect.x);
-       WRITE_NL(); WRITE_INT_FULL("float_window.y", layout->float_window.rect.y);
-       WRITE_NL(); WRITE_INT_FULL("float_window.w", layout->float_window.rect.width);
-       WRITE_NL(); WRITE_INT_FULL("float_window.h", layout->float_window.rect.height);
-       WRITE_NL(); WRITE_INT(*layout, float_window.vdivider_pos);
+       WRITE_NL(); WRITE_INT_FULL("float_window.x", lop.float_window.rect.x);
+       WRITE_NL(); WRITE_INT_FULL("float_window.y", lop.float_window.rect.y);
+       WRITE_NL(); WRITE_INT_FULL("float_window.w", lop.float_window.rect.width);
+       WRITE_NL(); WRITE_INT_FULL("float_window.h", lop.float_window.rect.height);
+       WRITE_NL(); WRITE_INT(lop, float_window.vdivider_pos);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_BOOL(*layout, tools_float);
-       WRITE_NL(); WRITE_BOOL(*layout, tools_hidden);
+       WRITE_NL(); WRITE_BOOL(lop, tools_float);
+       WRITE_NL(); WRITE_BOOL(lop, tools_hidden);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_BOOL(*layout, show_info_pixel);
-       WRITE_NL(); WRITE_BOOL(*layout, ignore_alpha);
+       WRITE_NL(); WRITE_BOOL(lop, show_info_pixel);
+       WRITE_NL(); WRITE_BOOL(lop, ignore_alpha);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_BOOL(*layout, bars_state.info);
-       WRITE_NL(); WRITE_BOOL(*layout, bars_state.sort);
-       WRITE_NL(); WRITE_BOOL(*layout, bars_state.tools_float);
-       WRITE_NL(); WRITE_BOOL(*layout, bars_state.tools_hidden);
-       WRITE_NL(); WRITE_BOOL(*layout, bars_state.hidden);
+       WRITE_NL(); WRITE_BOOL(lop, bars_state.info);
+       WRITE_NL(); WRITE_BOOL(lop, bars_state.sort);
+       WRITE_NL(); WRITE_BOOL(lop, bars_state.tools_float);
+       WRITE_NL(); WRITE_BOOL(lop, bars_state.tools_hidden);
+       WRITE_NL(); WRITE_BOOL(lop, bars_state.hidden);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_UINT(*layout, image_overlay.state);
-       WRITE_NL(); WRITE_INT(*layout, image_overlay.histogram_channel);
-       WRITE_NL(); WRITE_INT(*layout, image_overlay.histogram_mode);
-
-       WRITE_NL(); WRITE_INT(*layout, log_window.x);
-       WRITE_NL(); WRITE_INT(*layout, log_window.y);
-       WRITE_NL(); WRITE_INT(*layout, log_window.width);
-       WRITE_NL(); WRITE_INT(*layout, log_window.height);
-
-       WRITE_NL(); WRITE_INT_FULL("preferences_window.x", layout->preferences_window.rect.x);
-       WRITE_NL(); WRITE_INT_FULL("preferences_window.y", layout->preferences_window.rect.y);
-       WRITE_NL(); WRITE_INT_FULL("preferences_window.w", layout->preferences_window.rect.width);
-       WRITE_NL(); WRITE_INT_FULL("preferences_window.h", layout->preferences_window.rect.height);
-       WRITE_NL(); WRITE_INT(*layout, preferences_window.page_number);
-
-       WRITE_NL(); WRITE_INT(*layout, search_window.x);
-       WRITE_NL(); WRITE_INT(*layout, search_window.y);
-       WRITE_NL(); WRITE_INT_FULL("search_window.w", layout->search_window.width);
-       WRITE_NL(); WRITE_INT_FULL("search_window.h", layout->search_window.height);
-
-       WRITE_NL(); WRITE_INT(*layout, dupe_window.x);
-       WRITE_NL(); WRITE_INT(*layout, dupe_window.y);
-       WRITE_NL(); WRITE_INT_FULL("dupe_window.w", layout->dupe_window.width);
-       WRITE_NL(); WRITE_INT_FULL("dupe_window.h", layout->dupe_window.height);
-
-       WRITE_NL(); WRITE_INT(*layout, advanced_exif_window.x);
-       WRITE_NL(); WRITE_INT(*layout, advanced_exif_window.y);
-       WRITE_NL(); WRITE_INT_FULL("advanced_exif_window.w", layout->advanced_exif_window.width);
-       WRITE_NL(); WRITE_INT_FULL("advanced_exif_window.h", layout->advanced_exif_window.height);
+       WRITE_NL(); WRITE_UINT(lop, image_overlay.state);
+       WRITE_NL(); WRITE_INT(lop, image_overlay.histogram_channel);
+       WRITE_NL(); WRITE_INT(lop, image_overlay.histogram_mode);
+
+       WRITE_NL(); WRITE_INT(lop, log_window.x);
+       WRITE_NL(); WRITE_INT(lop, log_window.y);
+       WRITE_NL(); WRITE_INT(lop, log_window.width);
+       WRITE_NL(); WRITE_INT(lop, log_window.height);
+
+       WRITE_NL(); WRITE_INT_FULL("preferences_window.x", lop.preferences_window.rect.x);
+       WRITE_NL(); WRITE_INT_FULL("preferences_window.y", lop.preferences_window.rect.y);
+       WRITE_NL(); WRITE_INT_FULL("preferences_window.w", lop.preferences_window.rect.width);
+       WRITE_NL(); WRITE_INT_FULL("preferences_window.h", lop.preferences_window.rect.height);
+       WRITE_NL(); WRITE_INT(lop, preferences_window.page_number);
+
+       WRITE_NL(); WRITE_INT(lop, search_window.x);
+       WRITE_NL(); WRITE_INT(lop, search_window.y);
+       WRITE_NL(); WRITE_INT_FULL("search_window.w", lop.search_window.width);
+       WRITE_NL(); WRITE_INT_FULL("search_window.h", lop.search_window.height);
+
+       WRITE_NL(); WRITE_INT(lop, dupe_window.x);
+       WRITE_NL(); WRITE_INT(lop, dupe_window.y);
+       WRITE_NL(); WRITE_INT_FULL("dupe_window.w", lop.dupe_window.width);
+       WRITE_NL(); WRITE_INT_FULL("dupe_window.h", lop.dupe_window.height);
+
+       WRITE_NL(); WRITE_INT(lop, advanced_exif_window.x);
+       WRITE_NL(); WRITE_INT(lop, advanced_exif_window.y);
+       WRITE_NL(); WRITE_INT_FULL("advanced_exif_window.w", lop.advanced_exif_window.width);
+       WRITE_NL(); WRITE_INT_FULL("advanced_exif_window.h", lop.advanced_exif_window.height);
        WRITE_SEPARATOR();
 
-       WRITE_NL(); WRITE_BOOL(*layout, animate);
+       WRITE_NL(); WRITE_BOOL(lop, animate);
 }
 
 
@@ -2760,7 +2929,7 @@ void layout_write_config(LayoutWindow *lw, GString *outstr, gint indent)
 {
        layout_sync_options_with_current_state(lw);
        WRITE_NL(); WRITE_STRING("<layout");
-       layout_write_attributes(&lw->options, outstr, indent + 1);
+       layout_write_attributes(lw->options, outstr, indent + 1);
        WRITE_STRING(">");
 
        bar_sort_write_config(lw->bar_sort, outstr, indent + 1);
@@ -2776,107 +2945,6 @@ void layout_write_config(LayoutWindow *lw, GString *outstr, gint indent)
        WRITE_NL(); WRITE_STRING("</layout>");
 }
 
-void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values)
-{
-       g_autofree gchar *id = nullptr;
-
-       while (*attribute_names)
-               {
-               const gchar *option = *attribute_names++;
-               const gchar *value = *attribute_values++;
-
-               /* layout options */
-               if (READ_CHAR_FULL("id", id)) continue;
-
-               if (READ_INT(*layout, style)) continue;
-               if (READ_CHAR(*layout, order)) continue;
-
-               if (READ_UINT_ENUM(*layout, dir_view_type)) continue;
-               if (READ_UINT_ENUM(*layout, file_view_type)) continue;
-               if (READ_UINT_ENUM(*layout, file_view_list_sort.method)) continue;
-               if (READ_BOOL(*layout, file_view_list_sort.ascend)) continue;
-               if (READ_BOOL(*layout, file_view_list_sort.case_sensitive)) continue;
-               if (READ_UINT_ENUM(*layout, dir_view_list_sort.method)) continue;
-               if (READ_BOOL(*layout, dir_view_list_sort.ascend)) continue;
-               if (READ_BOOL(*layout, dir_view_list_sort.case_sensitive)) continue;
-               if (READ_BOOL(*layout, show_marks)) continue;
-               if (READ_BOOL(*layout, show_file_filter)) continue;
-               if (READ_BOOL(*layout, show_thumbnails)) continue;
-               if (READ_BOOL(*layout, show_directory_date)) continue;
-               if (READ_CHAR(*layout, home_path)) continue;
-               if (READ_UINT_ENUM_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue;
-
-               /* window positions */
-
-               if (READ_INT_FULL("main_window.x", layout->main_window.rect.x)) continue;
-               if (READ_INT_FULL("main_window.y", layout->main_window.rect.y)) continue;
-               if (READ_INT_FULL("main_window.w", layout->main_window.rect.width)) continue;
-               if (READ_INT_FULL("main_window.h", layout->main_window.rect.height)) continue;
-               if (READ_BOOL(*layout, main_window.maximized)) continue;
-               if (READ_INT(*layout, main_window.hdivider_pos)) continue;
-               if (READ_INT(*layout, main_window.vdivider_pos)) continue;
-
-               if (READ_INT_CLAMP(*layout, folder_window.vdivider_pos, 1, 1000)) continue;
-
-               if (READ_INT_FULL("float_window.x", layout->float_window.rect.x)) continue;
-               if (READ_INT_FULL("float_window.y", layout->float_window.rect.y)) continue;
-               if (READ_INT_FULL("float_window.w", layout->float_window.rect.width)) continue;
-               if (READ_INT_FULL("float_window.h", layout->float_window.rect.height)) continue;
-               if (READ_INT(*layout, float_window.vdivider_pos)) continue;
-
-               if (READ_BOOL(*layout, tools_float)) continue;
-               if (READ_BOOL(*layout, tools_hidden)) continue;
-               if (READ_BOOL(*layout, show_info_pixel)) continue;
-               if (READ_BOOL(*layout, ignore_alpha)) continue;
-
-               if (READ_BOOL(*layout, bars_state.info)) continue;
-               if (READ_BOOL(*layout, bars_state.sort)) continue;
-               if (READ_BOOL(*layout, bars_state.tools_float)) continue;
-               if (READ_BOOL(*layout, bars_state.tools_hidden)) continue;
-               if (READ_BOOL(*layout, bars_state.hidden)) continue;
-
-               if (READ_UINT(*layout, image_overlay.state)) continue;
-               if (READ_INT(*layout, image_overlay.histogram_channel)) continue;
-               if (READ_INT(*layout, image_overlay.histogram_mode)) continue;
-
-               if (READ_INT(*layout, log_window.x)) continue;
-               if (READ_INT(*layout, log_window.y)) continue;
-               if (READ_INT(*layout, log_window.width)) continue;
-               if (READ_INT(*layout, log_window.height)) continue;
-
-               if (READ_INT_FULL("preferences_window.x", layout->preferences_window.rect.x)) continue;
-               if (READ_INT_FULL("preferences_window.y", layout->preferences_window.rect.y)) continue;
-               if (READ_INT_FULL("preferences_window.w", layout->preferences_window.rect.width)) continue;
-               if (READ_INT_FULL("preferences_window.h", layout->preferences_window.rect.height)) continue;
-               if (READ_INT(*layout, preferences_window.page_number)) continue;
-
-               if (READ_INT(*layout, search_window.x)) continue;
-               if (READ_INT(*layout, search_window.y)) continue;
-               if (READ_INT_FULL("search_window.w", layout->search_window.width)) continue;
-               if (READ_INT_FULL("search_window.h", layout->search_window.height)) continue;
-
-               if (READ_INT(*layout, dupe_window.x)) continue;
-               if (READ_INT(*layout, dupe_window.y)) continue;
-               if (READ_INT_FULL("dupe_window.w", layout->dupe_window.width)) continue;
-               if (READ_INT_FULL("dupe_window.h", layout->dupe_window.height)) continue;
-
-               if (READ_INT(*layout, advanced_exif_window.x)) continue;
-               if (READ_INT(*layout, advanced_exif_window.y)) continue;
-               if (READ_INT_FULL("advanced_exif_window.w", layout->advanced_exif_window.width)) continue;
-               if (READ_INT_FULL("advanced_exif_window.h", layout->advanced_exif_window.height)) continue;
-
-               if (READ_BOOL(*layout, animate)) continue;
-               if (READ_INT(*layout, workspace)) continue;
-
-               config_file_error((std::string("Unknown attribute: ") + option + " = " + value).c_str());
-               }
-
-       if (id && !is_current_layout_id(id))
-               {
-               std::swap(layout->id, id);
-               }
-}
-
 static gchar *layout_config_startup_path(const LayoutOptions &lop)
 {
        switch (lop.startup_path)
@@ -2895,10 +2963,7 @@ static gchar *layout_config_startup_path(const LayoutOptions &lop)
 
 LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar **attribute_values, gboolean use_commandline)
 {
-       LayoutOptions lop;
-       init_layout_options(&lop);
-
-       if (attribute_names) layout_load_attributes(&lop, attribute_names, attribute_values);
+       LayoutOptions lop = init_layout_options(attribute_names, attribute_values);
 
        g_autofree gchar *path = layout_config_startup_path(lop);
 
@@ -2925,21 +2990,17 @@ LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar
 
        layout_set_path(lw, path);
 
-       free_layout_options_content(&lop);
+       free_layout_options_content(lop);
        return lw;
 }
 
 void layout_update_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values)
 {
-       LayoutOptions lop;
-
-       init_layout_options(&lop);
-
-       if (attribute_names) layout_load_attributes(&lop, attribute_names, attribute_values);
+       LayoutOptions lop = init_layout_options(attribute_names, attribute_values);
 
-       layout_apply_options(lw, &lop);
+       layout_apply_options(lw, lop);
 
-       free_layout_options_content(&lop);
+       free_layout_options_content(lop);
 }
 
 LayoutWindow *layout_new_from_default()
index 9387147184d6df1c35d5eec95f65dc55eb376f0e..08230e8aef4a57f3c798b1c2a3fbc46b6bd5083e 100644 (file)
@@ -27,7 +27,6 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 
-#include "options.h"
 #include "typedefs.h"
 
 struct AnimationData;
@@ -48,6 +47,119 @@ enum LayoutLocation {
        LAYOUT_BOTTOM = 1 << 3
 };
 
+enum StartUpPath {
+       STARTUP_PATH_CURRENT    = 0,
+       STARTUP_PATH_LAST,
+       STARTUP_PATH_HOME,
+};
+
+enum SortActionType {
+       BAR_SORT_COPY = 0,
+       BAR_SORT_MOVE,
+       BAR_SORT_FILTER,
+       BAR_SORT_ACTION_COUNT
+};
+
+enum SortModeType {
+       BAR_SORT_MODE_FOLDER = 0,
+       BAR_SORT_MODE_COLLECTION,
+       BAR_SORT_MODE_COUNT
+};
+
+enum SortSelectionType {
+       BAR_SORT_SELECTION_IMAGE = 0,
+       BAR_SORT_SELECTION_SELECTED,
+       BAR_SORT_SELECTION_COUNT
+};
+
+struct LayoutOptions
+{
+       gchar *id;
+
+       gchar *order;
+       gint style;
+
+       DirViewType dir_view_type;
+       FileViewType file_view_type;
+
+       struct SortParams
+       {
+               SortType method;
+               gboolean ascend;
+               gboolean case_sensitive;
+       };
+       SortParams dir_view_list_sort;
+       SortParams file_view_list_sort;
+
+       gboolean show_thumbnails;
+       gboolean show_marks;
+       gboolean show_file_filter;
+       gboolean show_directory_date;
+       gboolean show_info_pixel;
+       gboolean split_pane_sync;
+       gboolean ignore_alpha;
+
+       struct {
+               GdkRectangle rect;
+               gboolean maximized;
+               gint hdivider_pos;
+               gint vdivider_pos;
+       } main_window;
+
+       struct {
+               GdkRectangle rect;
+               gint vdivider_pos;
+       } float_window;
+
+       struct {
+               gint vdivider_pos;
+       } folder_window;
+
+       struct {
+               guint state;
+               gint histogram_channel;
+               gint histogram_mode;
+       } image_overlay;
+
+       GdkRectangle log_window;
+
+       struct {
+               GdkRectangle rect;
+               gint page_number;
+       } preferences_window;
+
+       GdkRectangle search_window;
+
+       GdkRectangle dupe_window;
+
+       GdkRectangle advanced_exif_window;
+
+       gboolean tools_float;
+       gboolean tools_hidden;
+       gboolean selectable_toolbars_hidden;
+
+       struct {
+               gboolean info;
+               gboolean sort;
+               gboolean tools_float;
+               gboolean tools_hidden;
+               gboolean hidden;
+       } bars_state;
+
+       gchar *home_path;
+       gchar *last_path;
+
+       StartUpPath startup_path;
+
+       gboolean animate;
+       gint workspace;
+
+       SortActionType action;
+       SortModeType mode;
+       SortSelectionType selection;
+       gchar *filter_key;
+};
+
 struct LayoutWindow
 {
        LayoutOptions options;
@@ -161,11 +273,7 @@ gboolean layout_valid(LayoutWindow **lw);
 
 void layout_show_config_window(LayoutWindow *lw);
 
-void layout_apply_options(LayoutWindow *lw, LayoutOptions *lop);
-
 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);
 
 
index 0e64c7336a987ff763cb487d4770624c4a76f966..99864206b8e692fe9668e60beeeaa1c3eae15182 100644 (file)
@@ -77,6 +77,7 @@
 #include "logwindow.h"
 #include "main-defines.h"
 #include "metadata.h"
+#include "options.h"
 #include "pixbuf-util.h"
 #include "secure-save.h"
 #include "third-party/whereami.h"
index 67d4ea36bdc2dde1aa7ec3f70ce3b7a530c77f4f..e7c895062a1e26d15e61db360476cb80d56d7503 100644 (file)
@@ -23,9 +23,6 @@
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
-#include "histogram.h" /* HCHAN_RGB */
-#include "image-overlay.h" /* OSD_SHOW_NOTHING */
-#include "image.h" /* RECTANGLE_DRAW_ASPECT_RATIO_NONE */
 #include "intl.h"
 #include "layout-image.h"
 #include "layout.h"
@@ -287,71 +284,6 @@ void setup_default_options(ConfOptions *options)
        options->help_search_engine = g_strdup(HELP_SEARCH_ENGINE);
 }
 
-void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src)
-{
-       free_layout_options_content(dest);
-
-       *dest = *src;
-       dest->id = g_strdup(src->id);
-       dest->order = g_strdup(src->order);
-       dest->home_path = g_strdup(src->home_path);
-       dest->last_path = g_strdup(src->last_path);
-}
-
-void free_layout_options_content(LayoutOptions *dest)
-{
-       g_free(dest->id);
-       g_free(dest->order);
-       g_free(dest->home_path);
-       g_free(dest->last_path);
-}
-
-LayoutOptions *init_layout_options(LayoutOptions *options)
-{
-       memset(options, 0, sizeof(LayoutOptions));
-
-       options->dir_view_type = DIRVIEW_LIST;
-       options->dir_view_list_sort.ascend = TRUE;
-       options->dir_view_list_sort.case_sensitive = TRUE;
-       options->dir_view_list_sort.method = SORT_NAME;
-       options->file_view_list_sort.ascend = TRUE;
-       options->file_view_list_sort.case_sensitive = TRUE;
-       options->file_view_list_sort.method = SORT_NAME;
-       options->file_view_type = FILEVIEW_LIST;
-       options->float_window.rect = {0, 0, 260, 450};
-       options->float_window.vdivider_pos = -1;
-       options->home_path = nullptr;
-       options->id = g_strdup("null");
-       options->main_window.hdivider_pos = -1;
-       options->main_window.maximized = FALSE;
-       options->main_window.rect = {0, 0, 720, 540};
-       options->main_window.vdivider_pos = 200;
-       options->search_window = {100, 100, 700, 650};
-       options->dupe_window = {100, 100, 800, 400};
-       options->advanced_exif_window = {0, 0, 900, 600};
-       options->folder_window.vdivider_pos = 100;
-       options->order = g_strdup("123");
-       options->show_directory_date = FALSE;
-       options->show_marks = FALSE;
-       options->show_file_filter = FALSE;
-       options->show_thumbnails = FALSE;
-       options->style = 0;
-       options->show_info_pixel = FALSE;
-       options->selectable_toolbars_hidden = FALSE;
-       options->tools_float = FALSE;
-       options->tools_hidden = FALSE;
-       options->image_overlay.histogram_channel = HCHAN_RGB;
-       options->image_overlay.histogram_mode = 1;
-       options->image_overlay.state = OSD_SHOW_NOTHING;
-       options->animate = TRUE;
-       options->bars_state.hidden = FALSE;
-       options->log_window = {0, 0, 520, 400};
-       options->preferences_window.rect = {0, 0, 700, 600};
-       options->split_pane_sync = FALSE;
-       options->workspace = -1;
-       return options;
-}
-
 static void sync_options_with_current_state(ConfOptions *options)
 {
        LayoutWindow *lw = get_current_layout();
index b1290abcb7b843fc1506bb651c36deba5f29da0d..b2c30ecce50d8ff7e5f837dc1f7b41df41122eab 100644 (file)
@@ -443,123 +443,5 @@ void save_options(ConfOptions *options);
 gboolean load_options(ConfOptions *options);
 void set_default_image_overlay_template_string(ConfOptions *options);
 
-
-enum StartUpPath {
-       STARTUP_PATH_CURRENT    = 0,
-       STARTUP_PATH_LAST,
-       STARTUP_PATH_HOME,
-};
-
-enum SortActionType {
-       BAR_SORT_COPY = 0,
-       BAR_SORT_MOVE,
-       BAR_SORT_FILTER,
-       BAR_SORT_ACTION_COUNT
-};
-
-enum SortModeType {
-       BAR_SORT_MODE_FOLDER = 0,
-       BAR_SORT_MODE_COLLECTION,
-       BAR_SORT_MODE_COUNT
-};
-
-enum SortSelectionType {
-       BAR_SORT_SELECTION_IMAGE = 0,
-       BAR_SORT_SELECTION_SELECTED,
-       BAR_SORT_SELECTION_COUNT
-};
-
-struct LayoutOptions
-{
-       gchar *id;
-
-       gchar *order;
-       gint style;
-
-       DirViewType dir_view_type;
-       FileViewType file_view_type;
-
-       struct SortParams
-       {
-               SortType method;
-               gboolean ascend;
-               gboolean case_sensitive;
-       };
-       SortParams dir_view_list_sort;
-       SortParams file_view_list_sort;
-
-       gboolean show_thumbnails;
-       gboolean show_marks;
-       gboolean show_file_filter;
-       gboolean show_directory_date;
-       gboolean show_info_pixel;
-       gboolean split_pane_sync;
-       gboolean ignore_alpha;
-
-       struct {
-               GdkRectangle rect;
-               gboolean maximized;
-               gint hdivider_pos;
-               gint vdivider_pos;
-       } main_window;
-
-       struct {
-               GdkRectangle rect;
-               gint vdivider_pos;
-       } float_window;
-
-       struct {
-               gint vdivider_pos;
-       } folder_window;
-
-       struct {
-               guint state;
-               gint histogram_channel;
-               gint histogram_mode;
-       } image_overlay;
-
-       GdkRectangle log_window;
-
-       struct {
-               GdkRectangle rect;
-               gint page_number;
-       } preferences_window;
-
-       GdkRectangle search_window;
-
-       GdkRectangle dupe_window;
-
-       GdkRectangle advanced_exif_window;
-
-       gboolean tools_float;
-       gboolean tools_hidden;
-       gboolean selectable_toolbars_hidden;
-
-       struct {
-               gboolean info;
-               gboolean sort;
-               gboolean tools_float;
-               gboolean tools_hidden;
-               gboolean hidden;
-       } bars_state;
-
-       gchar *home_path;
-       gchar *last_path;
-
-       StartUpPath startup_path;
-
-       gboolean animate;
-       gint workspace;
-
-       SortActionType action;
-       SortModeType mode;
-       SortSelectionType selection;
-       gchar *filter_key;
-};
-
-void copy_layout_options(LayoutOptions *dest, const LayoutOptions *src);
-void free_layout_options_content(LayoutOptions *dest);
-LayoutOptions *init_layout_options(LayoutOptions *options);
-
 #endif /* OPTIONS_H */
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */