startup path options simplified and moved to layout options
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 4 Apr 2009 21:14:34 +0000 (21:14 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sat, 4 Apr 2009 21:14:34 +0000 (21:14 +0000)
src/layout.c
src/options.c
src/options.h
src/preferences.c
src/rcfile.c
src/typedefs.h

index bd8a879..34a3246 100644 (file)
@@ -2032,6 +2032,25 @@ static void home_path_set_current_cb(GtkWidget *widget, gpointer data)
        gtk_entry_set_text(GTK_ENTRY(lc->home_path_entry), layout_get_path(lc->lw));
 }
 
+static void startup_path_set_current_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutConfig *lc = data;
+       lc->options.startup_path = STARTUP_PATH_CURRENT;
+}
+
+static void startup_path_set_last_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutConfig *lc = data;
+       lc->options.startup_path = STARTUP_PATH_LAST;
+}
+
+static void startup_path_set_home_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutConfig *lc = data;
+       lc->options.startup_path = STARTUP_PATH_HOME;
+}
+
+
 /*
 static void layout_config_save_cb(GtkWidget *widget, gpointer data)
 {
@@ -2115,9 +2134,10 @@ void layout_show_config_window(LayoutWindow *lw)
        gtk_container_add(GTK_CONTAINER(frame), vbox);
        gtk_widget_show(vbox);
 
+
        group = pref_group_new(vbox, FALSE, _("General options"), GTK_ORIENTATION_VERTICAL);
 
-       pref_label_new(group, _("Home button path (empty to use your home directory)"));
+       pref_label_new(group, _("Home path (empty to use your home directory)"));
        hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
 
        tabcomp = tab_completion_new(&lc->home_path_entry, lc->options.home_path, NULL, NULL);
@@ -2128,11 +2148,21 @@ void layout_show_config_window(LayoutWindow *lw)
        button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
                                 G_CALLBACK(home_path_set_current_cb), lc);
 
-       group = pref_group_new(vbox, FALSE, _("Behavior"), GTK_ORIENTATION_VERTICAL);
-
        pref_checkbox_new_int(group, _("Show date in directories list view"),
                              lc->options.show_directory_date, &lc->options.show_directory_date);
 
+       group = pref_group_new(vbox, FALSE, _("Start-up directory:"), GTK_ORIENTATION_VERTICAL);
+
+       button = pref_radiobutton_new(group, NULL, _("No change"),
+                                     (lc->options.startup_path == STARTUP_PATH_CURRENT),
+                                     G_CALLBACK(startup_path_set_current_cb), lc);
+       button = pref_radiobutton_new(group, button, _("Restore last path"),
+                                     (lc->options.startup_path == STARTUP_PATH_LAST),
+                                     G_CALLBACK(startup_path_set_last_cb), lc);
+       button = pref_radiobutton_new(group, button, _("Home path"),
+                                     (lc->options.startup_path == STARTUP_PATH_HOME),
+                                     G_CALLBACK(startup_path_set_home_cb), lc);
+
        group = pref_group_new(vbox, FALSE, _("Layout"), GTK_ORIENTATION_VERTICAL);
 
        lc->layout_widget = layout_config_new();
@@ -2174,11 +2204,8 @@ void layout_sync_options_with_current_state(LayoutWindow *lw)
        lw->options.image_overlay.histogram_channel = histogram->histogram_channel;
        lw->options.image_overlay.histogram_mode = histogram->histogram_mode;
 
-//     if (options->startup.restore_path && options->startup.use_last_path)
-//             {
-//             g_free(options->startup.path);
-//             options->startup.path = g_strdup(layout_get_path(NULL));
-//             }
+       g_free(lw->options.last_path);
+       lw->options.last_path = g_strdup(layout_get_path(lw));
 }
 
 void layout_apply_options(LayoutWindow *lw, LayoutOptions *lop)
@@ -2406,6 +2433,8 @@ void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent
        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_CHAR(*layout, last_path);
+       WRITE_NL(); WRITE_UINT(*layout, startup_path);
        WRITE_SEPARATOR();
 
        WRITE_NL(); WRITE_INT(*layout, main_window.x);
@@ -2477,6 +2506,8 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names
                if (READ_BOOL(*layout, show_thumbnails)) continue;
                if (READ_BOOL(*layout, show_directory_date)) continue;
                if (READ_CHAR(*layout, home_path)) continue;
+               if (READ_CHAR(*layout, last_path)) continue;
+               if (READ_UINT_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue;
 
                /* window positions */
 
@@ -2519,6 +2550,23 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names
                }
 }
 
+static void layout_config_startup_path(LayoutOptions *lop, gchar **path)
+{
+       switch (lop->startup_path)
+               {
+               case STARTUP_PATH_LAST:
+                       *path = (lop->last_path && isdir(lop->last_path)) ? g_strdup(lop->last_path) : get_current_dir();
+                       break;
+               case STARTUP_PATH_HOME:
+                       *path = (lop->home_path && isdir(lop->home_path)) ? g_strdup(lop->home_path) : g_strdup(homedir());
+                       break;
+               default:
+                       *path = get_current_dir();
+                       break;
+               }
+}      
+
+
 static void layout_config_commandline(LayoutOptions *lop, gchar **path)
 {
        if (command_line->startup_blank)
@@ -2533,14 +2581,7 @@ static void layout_config_commandline(LayoutOptions *lop, gchar **path)
                {
                *path = g_strdup(command_line->path);
                }
-       else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path))
-               {
-               *path = g_strdup(options->startup.path);
-               }
-       else
-               {
-               *path = get_current_dir();
-               }
+       else layout_config_startup_path(lop, path);
        
        if (command_line->tools_show)
                {
@@ -2567,13 +2608,9 @@ LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar
                {
                layout_config_commandline(&lop, &path);
                }
-       else if (options->startup.restore_path && options->startup.path && isdir(options->startup.path))
-               {
-               path = g_strdup(options->startup.path);
-               }
-       else
+       else 
                {
-               path = get_current_dir();
+               layout_config_startup_path(&lop, &path);
                }
 
        lw = layout_new_with_geometry(NULL, &lop, use_commandline ? command_line->geometry : NULL);
index 992d689..92654ae 100644 (file)
@@ -113,10 +113,6 @@ ConfOptions *init_options(ConfOptions *options)
        options->slideshow.random = FALSE;
        options->slideshow.repeat = FALSE;
 
-       options->startup.path = NULL;
-       options->startup.restore_path = FALSE;
-       options->startup.use_last_path = FALSE;
-
        options->thumbnails.cache_into_dirs = FALSE;
        options->thumbnails.enable_caching = TRUE;
        options->thumbnails.fast = TRUE;
@@ -173,6 +169,7 @@ void copy_layout_options(LayoutOptions *dest, const LayoutOptions *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)
@@ -180,6 +177,7 @@ 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)
@@ -230,12 +228,6 @@ static void sync_options_with_current_state(ConfOptions *options)
                                               &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(lw));
-                       }
                }
 
 }
index f49554f..168ae12 100644 (file)
@@ -37,13 +37,6 @@ struct _ConfOptions
        gboolean save_window_positions;
        gboolean tools_restore_state;
 
-       /* start up */
-       struct {
-               gboolean restore_path;
-               gboolean use_last_path;
-               gchar *path;
-       } startup;
-
        /* file ops */
        struct {
                gboolean enable_in_place_rename;
index 5753305..99ecdb5 100644 (file)
@@ -96,7 +96,6 @@ static gint debug_c;
 #endif
 
 static GtkWidget *configwindow = NULL;
-static GtkWidget *startup_path_entry;
 static GtkListStore *filter_store = NULL;
 
 static GtkWidget *safe_delete_path_entry;
@@ -117,11 +116,6 @@ static GtkWidget *sidecar_ext_entry;
  *-----------------------------------------------------------------------------
  */
 
-static void startup_path_set_current(GtkWidget *widget, gpointer data)
-{
-       gtk_entry_set_text(GTK_ENTRY(startup_path_entry), layout_get_path(NULL));
-}
-
 static void zoom_mode_cb(GtkWidget *widget, gpointer data)
 {
        if (GTK_TOGGLE_BUTTON (widget)->active)
@@ -231,10 +225,6 @@ static void config_window_apply(void)
        if (options->file_sort.case_sensitive != c_options->file_sort.case_sensitive) refresh = TRUE;
        if (options->file_filter.disable != c_options->file_filter.disable) refresh = TRUE;
 
-       options->startup.restore_path = c_options->startup.restore_path;
-       options->startup.use_last_path = c_options->startup.use_last_path;
-       config_entry_to_option(startup_path_entry, &options->startup.path, remove_trailing_slash);
-
        options->file_ops.confirm_delete = c_options->file_ops.confirm_delete;
        options->file_ops.enable_delete_key = c_options->file_ops.enable_delete_key;
        options->file_ops.safe_delete_enable = c_options->file_ops.safe_delete_enable;
@@ -913,42 +903,16 @@ static GtkWidget *scrolled_notebook_page(GtkWidget *notebook, const gchar *title
 /* general options tab */
 static void config_tab_general(GtkWidget *notebook)
 {
-       GtkWidget *hbox;
        GtkWidget *vbox;
-       GtkWidget *subvbox;
        GtkWidget *group;
        GtkWidget *subgroup;
        GtkWidget *button;
-       GtkWidget *tabcomp;
        GtkWidget *ct_button;
        GtkWidget *table;
        GtkWidget *spin;
 
        vbox = scrolled_notebook_page(notebook, _("General"));
 
-       group = pref_group_new(vbox, FALSE, _("Startup"), GTK_ORIENTATION_VERTICAL);
-
-       button = pref_checkbox_new_int(group, _("Restore folder on startup"),
-                                      options->startup.restore_path, &c_options->startup.restore_path);
-
-       subvbox = pref_box_new(group, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
-       pref_checkbox_link_sensitivity(button, subvbox);
-
-       hbox = pref_box_new(subvbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
-
-       tabcomp = tab_completion_new(&startup_path_entry, options->startup.path, NULL, NULL);
-       tab_completion_add_select_button(startup_path_entry, NULL, TRUE);
-       gtk_box_pack_start(GTK_BOX(hbox), tabcomp, TRUE, TRUE, 0);
-       gtk_widget_show(tabcomp);
-
-       button = pref_button_new(hbox, NULL, _("Use current"), FALSE,
-                                G_CALLBACK(startup_path_set_current), NULL);
-
-       button = pref_checkbox_new_int(subvbox, _("Use last path"),
-                                      options->startup.use_last_path, &c_options->startup.use_last_path);
-       pref_checkbox_link_sensitivity_swap(button, hbox);
-
-
        group = pref_group_new(vbox, FALSE, _("Thumbnails"), GTK_ORIENTATION_VERTICAL);
 
        table = pref_table_new(group, 2, 2, FALSE, FALSE);
index 32c55e0..ce95a70 100644 (file)
@@ -283,13 +283,6 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_BOOL(*options, save_window_positions);
        WRITE_NL(); WRITE_BOOL(*options, tools_restore_state);
 
-//     WRITE_SUBTITLE("Startup Options");
-
-       WRITE_NL(); WRITE_BOOL(*options, startup.restore_path);
-       WRITE_NL(); WRITE_BOOL(*options, startup.use_last_path);
-       WRITE_NL(); WRITE_CHAR(*options, startup.path);
-
-
 //     WRITE_SUBTITLE("File operations Options");
 
        WRITE_NL(); WRITE_BOOL(*options, file_ops.enable_in_place_rename);
@@ -601,15 +594,6 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, save_window_positions)) continue;
                if (READ_BOOL(*options, tools_restore_state)) continue;
 
-               /* startup options */
-               
-               if (READ_BOOL(*options, startup.restore_path)) continue;
-
-               if (READ_BOOL(*options, startup.use_last_path)) continue;
-
-               if (READ_CHAR(*options, startup.path)) continue;
-       
-
                /* properties dialog options */
                if (READ_CHAR(*options, properties.tabs_order)) continue;
 
index 2b551d4..6adfd7b 100644 (file)
@@ -174,6 +174,11 @@ typedef enum {
        METADATA_FORMATTED      = 1  /* for display only */
 } MetadataFormat;
 
+typedef enum {
+       STARTUP_PATH_CURRENT    = 0,
+       STARTUP_PATH_LAST,
+       STARTUP_PATH_HOME,
+} StartUpPath;
 
 #define MAX_SPLIT_IMAGES 4
 
@@ -530,6 +535,9 @@ struct _LayoutOptions
        gboolean info_pixel_hidden;
 
        gchar *home_path;
+       gchar *last_path;
+
+       StartUpPath startup_path;
 };
 
 struct _LayoutWindow