[gnome-commander] GnomeCmdData: move Programs options to GnomeCmdData::Options



commit ef2606753375d6738105476078d5b5d94877e9c6
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Sat Nov 12 14:57:35 2011 +0100

    GnomeCmdData: move Programs options to GnomeCmdData::Options

 src/gnome-cmd-data.cc           |   56 +++++++++----------------
 src/gnome-cmd-data.h            |   86 ++++++++++++++++++++-------------------
 src/gnome-cmd-file-selector.cc  |    2 +-
 src/gnome-cmd-file.cc           |    6 +-
 src/gnome-cmd-options-dialog.cc |   24 +++++-----
 src/gnome-cmd-user-actions.cc   |    4 +-
 src/utils.cc                    |    6 +-
 7 files changed, 86 insertions(+), 98 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index c67eebe..47291f9 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -48,7 +48,6 @@ GnomeVFSVolumeMonitor *monitor = NULL;
 struct GnomeCmdData::Private
 {
     GnomeCmdConList      *con_list;
-    GList                *fav_apps;
     GnomeCmdColorTheme   color_themes[GNOME_CMD_NUM_COLOR_MODES];
     GList                *auto_load_plugins;
     gint                 sort_column[2];
@@ -179,9 +178,9 @@ inline void save_fav_apps (const gchar *fname)
 
     if (fd)
     {
-        for (GList *tmp = gnome_cmd_data.priv->fav_apps; tmp; tmp = tmp->next)
+        for (GList *i = gnome_cmd_data.options.fav_apps; i; i = i->next)
         {
-            GnomeCmdApp *app = (GnomeCmdApp *) tmp->data;
+            GnomeCmdApp *app = (GnomeCmdApp *) i->data;
             if (app)
             {
                 gchar *name = gnome_vfs_escape_string (gnome_cmd_app_get_name (app));
@@ -602,7 +601,7 @@ inline void load_devices (const gchar *fname)
 
 inline void load_fav_apps (const gchar *fname)
 {
-    gnome_cmd_data.priv->fav_apps = NULL;
+    gnome_cmd_data.options.fav_apps = NULL;
     gchar *path = config_dir ? g_build_filename (config_dir, fname, NULL) : g_build_filename (g_get_home_dir (), "." PACKAGE, fname, NULL);
 
     ifstream f(path);
@@ -626,8 +625,8 @@ inline void load_fav_apps (const gchar *fname)
                 gchar *icon_path = gnome_vfs_unescape_string (a[2], NULL);
                 gchar *pattern   = gnome_vfs_unescape_string (a[4], NULL);
 
-                gnome_cmd_data.priv->fav_apps = g_list_append (
-                    gnome_cmd_data.priv->fav_apps,
+                gnome_cmd_data.options.fav_apps = g_list_append (
+                    gnome_cmd_data.options.fav_apps,
                     gnome_cmd_app_new_with_values (
                         name, cmd, icon_path, (AppTarget) target, pattern, handles_uris, handles_multiple, requires_terminal));
 
@@ -845,10 +844,8 @@ GnomeCmdData::GnomeCmdData(): search_defaults(selections)
     cmdline_history = NULL;
     cmdline_history_length = 0;
 
-    use_internal_viewer = TRUE;
     use_gcmd_block = FALSE;
 
-    honor_expect_uris = FALSE;
     skip_mounting = FALSE;
 
     main_win_width = 600;
@@ -856,11 +853,6 @@ GnomeCmdData::GnomeCmdData(): search_defaults(selections)
 
     main_win_state = GDK_WINDOW_STATE_MAXIMIZED;
 
-    viewer = NULL;
-    editor = NULL;
-    differ = NULL;
-    term = NULL;
-
     umask = ::umask(0);
     ::umask(umask);
 }
@@ -868,12 +860,6 @@ GnomeCmdData::GnomeCmdData(): search_defaults(selections)
 
 void GnomeCmdData::free()
 {
-    // free the external programs strings
-    g_free (viewer);
-    g_free (editor);
-    g_free (differ);
-    g_free (term);
-
     if (priv)
     {
         // free the connections
@@ -1089,9 +1075,9 @@ void GnomeCmdData::load()
     if (gui_update_rate > MAX_GUI_UPDATE_RATE)
         gui_update_rate = MAX_GUI_UPDATE_RATE;
 
-    honor_expect_uris = gnome_cmd_data_get_bool ("/programs/honor_expect_uris", FALSE);
+    options.honor_expect_uris = gnome_cmd_data_get_bool ("/programs/honor_expect_uris", FALSE);
     options.allow_multiple_instances = gnome_cmd_data_get_bool ("/programs/allow_multiple_instances", FALSE);
-    use_internal_viewer = gnome_cmd_data_get_bool ("/programs/use_internal_viewer", TRUE);
+    options.use_internal_viewer = gnome_cmd_data_get_bool ("/programs/use_internal_viewer", TRUE);
     options.alt_quick_search = gnome_cmd_data_get_bool ("/programs/alt_quick_search", FALSE);
     options.quick_search_exact_match_begin = gnome_cmd_data_get_bool ("/programs/quick_search_exact_match_begin", TRUE);
     options.quick_search_exact_match_end = gnome_cmd_data_get_bool ("/programs/quick_search_exact_match_end", FALSE);
@@ -1104,10 +1090,10 @@ void GnomeCmdData::load()
         priv->symlink_prefix = NULL;
     }
 
-    viewer = gnome_cmd_data_get_string ("/programs/viewer", "gedit %s");
-    editor = gnome_cmd_data_get_string ("/programs/editor", "gedit %s");
-    differ = gnome_cmd_data_get_string ("/programs/differ", "meld %s");
-    term   = gnome_cmd_data_get_string ("/programs/terminal", "xterm -hold -e %s");
+    options.viewer = gnome_cmd_data_get_string ("/programs/viewer", "gedit %s");
+    options.editor = gnome_cmd_data_get_string ("/programs/editor", "gedit %s");
+    options.differ = gnome_cmd_data_get_string ("/programs/differ", "meld %s");
+    options.term   = gnome_cmd_data_get_string ("/programs/terminal", "xterm -hold -e %s");
 
     use_gcmd_block = gnome_cmd_data_get_bool ("/programs/use_gcmd_block", FALSE);
 
@@ -1500,9 +1486,9 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_bool   ("/options/list_orientation", list_orientation);
     gnome_cmd_data_set_int    ("/options/gui_update_rate", gui_update_rate);
 
-    gnome_cmd_data_set_bool   ("/programs/honor_expect_uris", honor_expect_uris);
+    gnome_cmd_data_set_bool   ("/programs/honor_expect_uris", options.honor_expect_uris);
     gnome_cmd_data_set_bool   ("/programs/allow_multiple_instances", options.allow_multiple_instances);
-    gnome_cmd_data_set_bool   ("/programs/use_internal_viewer", use_internal_viewer);
+    gnome_cmd_data_set_bool   ("/programs/use_internal_viewer", options.use_internal_viewer);
     gnome_cmd_data_set_bool   ("/programs/alt_quick_search", options.alt_quick_search);
     gnome_cmd_data_set_bool   ("/programs/quick_search_exact_match_begin", options.quick_search_exact_match_begin);
     gnome_cmd_data_set_bool   ("/programs/quick_search_exact_match_end", options.quick_search_exact_match_end);
@@ -1522,10 +1508,10 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_int    ("/options/main_win_pos_x", priv->main_win_pos[0]);
     gnome_cmd_data_set_int    ("/options/main_win_pos_y", priv->main_win_pos[1]);
 
-    gnome_cmd_data_set_string ("/programs/viewer", viewer);
-    gnome_cmd_data_set_string ("/programs/editor", editor);
-    gnome_cmd_data_set_string ("/programs/differ", differ);
-    gnome_cmd_data_set_string ("/programs/terminal", term);
+    gnome_cmd_data_set_string ("/programs/viewer", options.viewer);
+    gnome_cmd_data_set_string ("/programs/editor", options.editor);
+    gnome_cmd_data_set_string ("/programs/differ", options.differ);
+    gnome_cmd_data_set_string ("/programs/terminal", options.term);
 
     gnome_cmd_data_set_bool   ("/programs/use_gcmd_block", use_gcmd_block);
 
@@ -1679,7 +1665,7 @@ void gnome_cmd_data_add_fav_app (GnomeCmdApp *app)
 {
     g_return_if_fail (app != NULL);
 
-    gnome_cmd_data.priv->fav_apps = g_list_append (gnome_cmd_data.priv->fav_apps, app);
+    gnome_cmd_data.options.fav_apps = g_list_append (gnome_cmd_data.options.fav_apps, app);
 }
 
 
@@ -1687,19 +1673,19 @@ void gnome_cmd_data_remove_fav_app (GnomeCmdApp *app)
 {
     g_return_if_fail (app != NULL);
 
-    gnome_cmd_data.priv->fav_apps = g_list_remove (gnome_cmd_data.priv->fav_apps, app);
+    gnome_cmd_data.options.fav_apps = g_list_remove (gnome_cmd_data.options.fav_apps, app);
 }
 
 
 GList *gnome_cmd_data_get_fav_apps ()
 {
-    return gnome_cmd_data.priv->fav_apps;
+    return gnome_cmd_data.options.fav_apps;
 }
 
 
 void gnome_cmd_data_set_fav_apps (GList *apps)
 {
-    gnome_cmd_data.priv->fav_apps = apps;
+    gnome_cmd_data.options.fav_apps = apps;
 }
 
 
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index b3321ce..4c644cb 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -123,6 +123,14 @@ struct GnomeCmdData
         FilterSettings               filter;
         gchar                       *backup_pattern;
         GList                       *backup_pattern_list;
+        //  Programs
+        gboolean                     honor_expect_uris;
+        gchar                       *viewer;
+        gboolean                     use_internal_viewer;
+        gchar                       *editor;
+        gchar                       *differ;
+        gchar                       *term;
+        GList                       *fav_apps;
 
         Options(): left_mouse_button_mode(LEFT_BUTTON_OPENS_WITH_DOUBLE_CLICK),
                    left_mouse_button_unselects(TRUE),
@@ -156,7 +164,14 @@ struct GnomeCmdData
                    confirm_move_overwrite(GNOME_CMD_CONFIRM_OVERWRITE_QUERY),
                    confirm_mouse_dnd(TRUE),
                    backup_pattern(NULL),
-                   backup_pattern_list(NULL)
+                   backup_pattern_list(NULL),
+                   honor_expect_uris(FALSE),
+                   viewer(NULL),
+                   use_internal_viewer(TRUE),
+                   editor(NULL),
+                   differ(NULL),
+                   term(NULL),
+                   fav_apps(NULL)
         {
             memset(&ls_colors_palette, 0, sizeof(ls_colors_palette));
         }
@@ -167,6 +182,10 @@ struct GnomeCmdData
             g_free (list_font);
             g_free (backup_pattern);
             patlist_free (backup_pattern_list);
+            g_free (viewer);
+            g_free (editor);
+            g_free (differ);
+            g_free (term);
         }
 
         void set_date_format(const GnomeCmdDateFormat format)
@@ -201,6 +220,30 @@ struct GnomeCmdData
             backup_pattern = g_strdup (value);
             backup_pattern_list = patlist_new (backup_pattern);
         }
+
+        void set_viewer(const gchar *command)
+        {
+            g_free (viewer);
+            viewer = g_strdup (command);
+        }
+
+        void set_editor(const gchar *command)
+        {
+            g_free (editor);
+            editor = g_strdup (command);
+        }
+
+        void set_differ(const gchar *command)
+        {
+            g_free (differ);
+            differ = g_strdup (command);
+        }
+
+        void set_term(const gchar *command)
+        {
+            g_free (term);
+            term = g_strdup (command);
+        }
     };
 
     struct Selection
@@ -304,11 +347,6 @@ struct GnomeCmdData
 
     GnomeCmdConRemote           *quick_connect;
 
-    gchar *viewer;
-    gchar *editor;
-    gchar *differ;
-    gchar *term;
-
     void load_auto_load_plugins();
     void load_cmdline_history();
     void load_local_bookmarks();
@@ -351,10 +389,8 @@ struct GnomeCmdData
     GList                       *cmdline_history;
     gint                         cmdline_history_length;
 
-    gboolean                     use_internal_viewer;
     gboolean                     use_gcmd_block;
 
-    gboolean                     honor_expect_uris;
     gboolean                     skip_mounting;
 
     gint                         main_win_width;
@@ -378,16 +414,6 @@ struct GnomeCmdData
 
     GnomeCmdFileList::ColumnID get_sort_col(FileSelectorID id) const;
     GtkSortType get_sort_direction(FileSelectorID id) const;
-
-    const gchar *get_viewer() const                 {  return viewer;                            }
-    const gchar *get_editor() const                 {  return editor;                            }
-    const gchar *get_differ() const                 {  return differ;                            }
-    const gchar *get_term() const                   {  return term;                              }
-
-    void set_viewer(const gchar *command);
-    void set_editor(const gchar *command);
-    void set_differ(const gchar *command);
-    void set_term(const gchar *command);
 };
 
 gpointer gnome_cmd_data_get_con_list ();
@@ -403,30 +429,6 @@ void gnome_cmd_data_set_ftp_anonymous_password (const gchar *pw);
 GnomeCmdColorTheme *gnome_cmd_data_get_custom_color_theme ();
 GnomeCmdColorTheme *gnome_cmd_data_get_current_color_theme ();
 
-inline void GnomeCmdData::set_viewer(const gchar *command)
-{
-    g_free (viewer);
-    viewer = g_strdup (command);
-}
-
-inline void GnomeCmdData::set_editor(const gchar *command)
-{
-    g_free (editor);
-    editor = g_strdup (command);
-}
-
-inline void GnomeCmdData::set_differ(const gchar *command)
-{
-    g_free (differ);
-    differ = g_strdup (command);
-}
-
-inline void GnomeCmdData::set_term(const gchar *command)
-{
-    g_free (term);
-    term = g_strdup (command);
-}
-
 GList *gnome_cmd_data_get_auto_load_plugins ();
 void gnome_cmd_data_set_auto_load_plugins (GList *plugins);
 
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index 02aaf34..3c6c33a 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -1071,7 +1071,7 @@ static gboolean on_new_textfile_ok (GnomeCmdStringDialog *string_dialog, const g
     g_return_val_if_fail (filepath, TRUE);
 
     gchar *escaped_filepath = g_strdup_printf ("\"%s\"", filepath);
-    gchar *cmd = g_strdup_printf (gnome_cmd_data.get_editor(), escaped_filepath);
+    gchar *cmd = g_strdup_printf (gnome_cmd_data.options.editor, escaped_filepath);
     g_free (filepath);
     g_free (escaped_filepath);
 
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index ff78ae3..a1d46a2 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -647,7 +647,7 @@ void gnome_cmd_file_show_properties (GnomeCmdFile *f)
 inline void do_view_file (GnomeCmdFile *f, gint internal_viewer=-1)
 {
     if (internal_viewer==-1)
-        internal_viewer = gnome_cmd_data.use_internal_viewer;
+        internal_viewer = gnome_cmd_data.options.use_internal_viewer;
 
     switch (internal_viewer)
     {
@@ -662,7 +662,7 @@ inline void do_view_file (GnomeCmdFile *f, gint internal_viewer=-1)
 
         case FALSE: {
                         gchar *filename = f->get_quoted_real_path();
-                        gchar *command = g_strdup_printf (gnome_cmd_data.get_viewer(), filename);
+                        gchar *command = g_strdup_printf (gnome_cmd_data.options.viewer, filename);
                         run_command (command);
                         g_free (filename);
                     }
@@ -726,7 +726,7 @@ void gnome_cmd_file_edit (GnomeCmdFile *f)
 
     gchar *fpath = f->get_quoted_real_path();
     gchar *dpath = f->get_unescaped_dirname();
-    gchar *command = g_strdup_printf (gnome_cmd_data.get_editor(), fpath);
+    gchar *command = g_strdup_printf (gnome_cmd_data.options.editor, fpath);
 
     run_command_indir (command, dpath, FALSE);
 
diff --git a/src/gnome-cmd-options-dialog.cc b/src/gnome-cmd-options-dialog.cc
index 901277c..6069726 100644
--- a/src/gnome-cmd-options-dialog.cc
+++ b/src/gnome-cmd-options-dialog.cc
@@ -1491,7 +1491,7 @@ inline GtkWidget *create_programs_tab (GtkWidget *parent, GnomeCmdData &cfg)
 
 
     check = create_check (parent, _("Always download remote files before opening in external programs"), "honor_expect_uris");
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), !cfg.honor_expect_uris);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), !cfg.options.honor_expect_uris);
     cat = create_category (parent, check, _("MIME applications"));
     gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, FALSE, 0);
 
@@ -1508,17 +1508,17 @@ inline GtkWidget *create_programs_tab (GtkWidget *parent, GnomeCmdData &cfg)
     label = create_label (parent, _("Terminal:"));
     table_add (table, label, 0, 4, GTK_FILL);
 
-    entry = create_entry (parent, "viewer", cfg.get_viewer());
+    entry = create_entry (parent, "viewer", cfg.options.viewer);
     table_add (table, entry, 1, 0, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
 
     check = create_check (parent, _("Use Internal Viewer"), "use_internal_viewer");
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), cfg.use_internal_viewer);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), cfg.options.use_internal_viewer);
     table_add (table, check, 1, 1, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
-    entry = create_entry (parent, "editor", cfg.get_editor());
+    entry = create_entry (parent, "editor", cfg.options.editor);
     table_add (table, entry, 1, 2, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
-    entry = create_entry (parent, "differ", cfg.get_differ());
+    entry = create_entry (parent, "differ", cfg.options.differ);
     table_add (table, entry, 1, 3, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
-    entry = create_entry (parent, "term", cfg.get_term());
+    entry = create_entry (parent, "term", cfg.options.term);
     table_add (table, entry, 1, 4, (GtkAttachOptions) (GTK_EXPAND|GTK_FILL));
 
 
@@ -1580,13 +1580,13 @@ inline void store_programs_options (GtkWidget *dialog, GnomeCmdData &cfg)
     GtkWidget *check_uris = lookup_widget (dialog, "honor_expect_uris");
     GtkWidget *check_iv = lookup_widget (dialog, "use_internal_viewer");
 
-    cfg.set_viewer(gtk_entry_get_text (GTK_ENTRY (entry1)));
-    cfg.set_editor(gtk_entry_get_text (GTK_ENTRY (entry2)));
-    cfg.set_differ(gtk_entry_get_text (GTK_ENTRY (entry3)));
-    cfg.set_term(gtk_entry_get_text (GTK_ENTRY (entry5)));
+    cfg.options.set_viewer(gtk_entry_get_text (GTK_ENTRY (entry1)));
+    cfg.options.set_editor(gtk_entry_get_text (GTK_ENTRY (entry2)));
+    cfg.options.set_differ(gtk_entry_get_text (GTK_ENTRY (entry3)));
+    cfg.options.set_term(gtk_entry_get_text (GTK_ENTRY (entry5)));
 
-    cfg.honor_expect_uris = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_uris));
-    cfg.use_internal_viewer = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_iv));
+    cfg.options.honor_expect_uris = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_uris));
+    cfg.options.use_internal_viewer = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_iv));
 }
 
 
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index c488544..16149aa 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -944,7 +944,7 @@ void file_diff (GtkMenuItem *menuitem, gpointer not_used)
 
     if (!s.empty())
     {
-        gchar *cmd = g_strdup_printf (gnome_cmd_data.get_differ(), s.c_str(), "");
+        gchar *cmd = g_strdup_printf (gnome_cmd_data.options.differ, s.c_str(), "");
 
         run_command (cmd);
 
@@ -969,7 +969,7 @@ void file_sync_dirs (GtkMenuItem *menuitem, gpointer not_used)
     append_real_path (s, GNOME_CMD_FILE (active_fs->get_directory()));
     append_real_path (s, GNOME_CMD_FILE (inactive_fs->get_directory()));
 
-    gchar *cmd = g_strdup_printf (gnome_cmd_data.get_differ(), s.c_str(), "");
+    gchar *cmd = g_strdup_printf (gnome_cmd_data.options.differ, s.c_str(), "");
 
     run_command (cmd);
 
diff --git a/src/utils.cc b/src/utils.cc
index 4f34aae..f7a0eef 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -111,7 +111,7 @@ void run_command_indir (const gchar *in_command, const gchar *dir, gboolean term
         else
             arg = g_shell_quote (in_command);
 
-        command = g_strdup_printf (gnome_cmd_data.get_term(), arg);
+        command = g_strdup_printf (gnome_cmd_data.options.term, arg);
 
         g_free (arg);
     }
@@ -565,7 +565,7 @@ void mime_exec_single (GnomeCmdFile *f)
     }
     else
     {
-        if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.honor_expect_uris)
+        if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
         {
             args[0] = (gpointer) app;
             args[1] = (gpointer) f->get_uri_str();
@@ -647,7 +647,7 @@ void mime_exec_multiple (GList *files, GnomeCmdApp *app)
         else
         {
             ++no_of_remote_files;
-            if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.honor_expect_uris)
+            if (gnome_cmd_app_get_handles_uris (app) && gnome_cmd_data.options.honor_expect_uris)
             {
                 local_files = g_list_append (local_files,  f->get_uri_str());
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]