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



commit 35524dbe7ce877d3bd6a2294b2121a415a3426c0
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon Nov 7 23:29:04 2011 +0100

    GnomeCmdData: move Format options to GnomeCmdData::Options

 src/gnome-cmd-data.cc              |   25 ++++++++++---------------
 src/gnome-cmd-data.h               |   16 +++++++++++++---
 src/gnome-cmd-file-selector.cc     |    2 +-
 src/gnome-cmd-file.cc              |    4 ++--
 src/gnome-cmd-options-dialog.cc    |   24 ++++++++++++------------
 src/gnome-cmd-xfer-progress-win.cc |    4 ++--
 src/utils.cc                       |    4 ++--
 7 files changed, 42 insertions(+), 37 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 37ee927..7bbaa41 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -49,7 +49,6 @@ struct GnomeCmdData::Private
 {
     GnomeCmdConList      *con_list;
     GList                *fav_apps;
-    GnomeCmdDateFormat   date_format;           // NOTE: internally stored as locale (which not always defaults to UTF8), needs converting from/to UTF8 for editing and cfg load/save
     GnomeCmdColorTheme   color_themes[GNOME_CMD_NUM_COLOR_MODES];
     gchar                *list_font;
     gchar                *theme_icon_dir;
@@ -842,8 +841,7 @@ GnomeCmdData::GnomeCmdData(): search_defaults(selections)
     confirm_move_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
     confirm_mouse_dnd = TRUE;
     color_mode = GNOME_CMD_COLOR_DEEP_BLUE;
-    size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_POWERED;
-    perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_TEXT;
+    options.perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_TEXT; //  ???
 
     memset(&filter_settings, 0, sizeof(filter_settings));
     filter_settings.hidden = TRUE;
@@ -920,9 +918,6 @@ void GnomeCmdData::free()
         // free the anonymous password string
         g_free (priv->ftp_anonymous_password);
 
-        // free the date_format string
-        g_free (priv->date_format);
-
         // free the font name strings
         g_free (priv->list_font);
 
@@ -1020,15 +1015,15 @@ void GnomeCmdData::load()
     priv->color_themes[GNOME_CMD_COLOR_NONE].curs_fg = NULL;
     priv->color_themes[GNOME_CMD_COLOR_NONE].curs_bg = NULL;
 
-    size_disp_mode = (GnomeCmdSizeDispMode) gnome_cmd_data_get_int ("/options/size_disp_mode", GNOME_CMD_SIZE_DISP_MODE_POWERED);
-    perm_disp_mode = (GnomeCmdPermDispMode) gnome_cmd_data_get_int ("/options/perm_disp_mode", GNOME_CMD_PERM_DISP_MODE_TEXT);
+    options.size_disp_mode = (GnomeCmdSizeDispMode) gnome_cmd_data_get_int ("/options/size_disp_mode", GNOME_CMD_SIZE_DISP_MODE_POWERED);
+    options.perm_disp_mode = (GnomeCmdPermDispMode) gnome_cmd_data_get_int ("/options/perm_disp_mode", GNOME_CMD_PERM_DISP_MODE_TEXT);
 
 #ifdef HAVE_LOCALE_H
     gchar *utf8_date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%x %R");
 #else
     gchar *utf8_date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%D %R");
 #endif
-    priv->date_format = g_locale_from_utf8 (utf8_date_format, -1, NULL, NULL, NULL);
+    options.date_format = g_locale_from_utf8 (utf8_date_format, -1, NULL, NULL, NULL);
     g_free (utf8_date_format);
 
     layout = (GnomeCmdLayout) gnome_cmd_data_get_int ("/options/layout", GNOME_CMD_LAYOUT_MIME_ICONS);
@@ -1463,12 +1458,12 @@ void GnomeCmdData::load_more()
 
 void GnomeCmdData::save()
 {
-    gnome_cmd_data_set_int    ("/options/size_disp_mode", size_disp_mode);
-    gnome_cmd_data_set_int    ("/options/perm_disp_mode", perm_disp_mode);
+    gnome_cmd_data_set_int    ("/options/size_disp_mode", options.size_disp_mode);
+    gnome_cmd_data_set_int    ("/options/perm_disp_mode", options.perm_disp_mode);
     gnome_cmd_data_set_int    ("/options/layout", layout);
     gnome_cmd_data_set_int    ("/options/list_row_height", list_row_height);
 
-    gchar *utf8_date_format = g_locale_to_utf8 (priv->date_format, -1, NULL, NULL, NULL);
+    gchar *utf8_date_format = g_locale_to_utf8 (options.date_format, -1, NULL, NULL, NULL);
     gnome_cmd_data_set_string ("/options/date_disp_mode", utf8_date_format);
     g_free (utf8_date_format);
 
@@ -1744,15 +1739,15 @@ void gnome_cmd_data_set_fav_apps (GList *apps)
 
 GnomeCmdDateFormat gnome_cmd_data_get_date_format ()
 {
-    return gnome_cmd_data.priv->date_format;
+    return gnome_cmd_data.options.date_format;
 }
 
 
 void gnome_cmd_data_set_date_format (GnomeCmdDateFormat format)
 {
-    g_free (gnome_cmd_data.priv->date_format);
+    g_free (gnome_cmd_data.options.date_format);
 
-    gnome_cmd_data.priv->date_format = g_strdup (format);
+    gnome_cmd_data.options.date_format = g_strdup (format);
 }
 
 
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 477e811..b810855 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -80,6 +80,10 @@ struct GnomeCmdData
         gboolean              save_dirs_on_exit;
         gboolean              save_tabs_on_exit;
         gboolean              save_dir_history_on_exit;
+        // Format
+        GnomeCmdSizeDispMode  size_disp_mode;
+        GnomeCmdPermDispMode  perm_disp_mode;
+        GnomeCmdDateFormat    date_format;           // NOTE: internally stored as locale (which not always defaults to UTF8), needs converting from/to UTF8 for editing and cfg load/save
 
         Options(): left_mouse_button_mode(LEFT_BUTTON_OPENS_WITH_DOUBLE_CLICK),
                    left_mouse_button_unselects(TRUE),
@@ -92,9 +96,17 @@ struct GnomeCmdData
                    allow_multiple_instances(FALSE),
                    save_dirs_on_exit(FALSE),
                    save_tabs_on_exit(TRUE),
-                   save_dir_history_on_exit(TRUE)
+                   save_dir_history_on_exit(TRUE),
+                   size_disp_mode(GNOME_CMD_SIZE_DISP_MODE_POWERED),
+                   perm_disp_mode(GNOME_CMD_PERM_DISP_MODE_TEXT),
+                   date_format(NULL)
         {
         }
+
+        ~Options()
+        {
+            g_free (date_format);
+        }
     };
 
     struct Selection
@@ -234,8 +246,6 @@ struct GnomeCmdData
     GnomeCmdConfirmOverwriteMode confirm_move_overwrite;
     gboolean                     confirm_mouse_dnd;
     GnomeCmdColorMode            color_mode;
-    GnomeCmdSizeDispMode         size_disp_mode;
-    GnomeCmdPermDispMode         perm_disp_mode;
 
     Options                      options;
 
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index f061582..17ee91d 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -123,7 +123,7 @@ inline void GnomeCmdFileSelector::update_selected_files_label()
     gint num_sel_files = 0;
     gint num_sel_dirs = 0;
 
-    GnomeCmdSizeDispMode size_mode = gnome_cmd_data.size_disp_mode;
+    GnomeCmdSizeDispMode size_mode = gnome_cmd_data.options.size_disp_mode;
     if (size_mode==GNOME_CMD_SIZE_DISP_MODE_POWERED)
         size_mode = GNOME_CMD_SIZE_DISP_MODE_GROUPED;
 
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index b456311..c2c7a68 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -525,7 +525,7 @@ const gchar *GnomeCmdFile::get_size()
     if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
         return dir_indicator;
 
-    return size2string (info->size, gnome_cmd_data.size_disp_mode);
+    return size2string (info->size, gnome_cmd_data.options.size_disp_mode);
 }
 
 
@@ -558,7 +558,7 @@ const gchar *GnomeCmdFile::get_tree_size_as_str()
     if (is_dotdot)
         return get_size();
 
-    return size2string (get_tree_size(), gnome_cmd_data.size_disp_mode);
+    return size2string (get_tree_size(), gnome_cmd_data.options.size_disp_mode);
 }
 
 
diff --git a/src/gnome-cmd-options-dialog.cc b/src/gnome-cmd-options-dialog.cc
index a5c879b..25cd79b 100644
--- a/src/gnome-cmd-options-dialog.cc
+++ b/src/gnome-cmd-options-dialog.cc
@@ -260,23 +260,23 @@ inline GtkWidget *create_format_tab (GtkWidget *parent, GnomeCmdData &cfg)
     // Translators: 'Powered' refers to the mode of file size display (here - display using units of data: kB, MB, GB, ...)
     radio = create_radio (parent, NULL, _("Powered"), "size_powered_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_POWERED)
+    if (cfg.options.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_POWERED)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
     // Translators: '<locale>' refers to the mode of file size display (here - use current locale settings)
     radio = create_radio (parent, get_radio_group (radio), _("<locale>"), "size_locale_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_LOCALE)
+    if (cfg.options.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_LOCALE)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
     radio = create_radio (parent, get_radio_group (radio), _("Grouped"), "size_grouped_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_GROUPED)
+    if (cfg.options.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_GROUPED)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
     radio = create_radio (parent, get_radio_group (radio), _("Plain"), "size_plain_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_PLAIN)
+    if (cfg.options.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_PLAIN)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
 
@@ -287,12 +287,12 @@ inline GtkWidget *create_format_tab (GtkWidget *parent, GnomeCmdData &cfg)
 
     radio = create_radio (parent, NULL, _("Text (rw-r--r--)"), "perm_text_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.perm_disp_mode == GNOME_CMD_PERM_DISP_MODE_TEXT)
+    if (cfg.options.perm_disp_mode == GNOME_CMD_PERM_DISP_MODE_TEXT)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
     radio = create_radio (parent, get_radio_group (radio), _("Number (644)"), "perm_num_radio");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
-    if (cfg.perm_disp_mode == GNOME_CMD_PERM_DISP_MODE_NUMBER)
+    if (cfg.options.perm_disp_mode == GNOME_CMD_PERM_DISP_MODE_NUMBER)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
 
@@ -337,18 +337,18 @@ inline void store_format_options (GtkWidget *dialog, GnomeCmdData &cfg)
     const gchar *format = gtk_entry_get_text (GTK_ENTRY (entry));
 
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (size_powered_radio)))
-        cfg.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_POWERED;
+        cfg.options.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_POWERED;
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (size_locale_radio)))
-        cfg.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_LOCALE;
+        cfg.options.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_LOCALE;
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (size_grouped_radio)))
-        cfg.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_GROUPED;
+        cfg.options.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_GROUPED;
     else
-        cfg.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_PLAIN;
+        cfg.options.size_disp_mode = GNOME_CMD_SIZE_DISP_MODE_PLAIN;
 
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (perm_text_radio)))
-        cfg.perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_TEXT;
+        cfg.options.perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_TEXT;
     else
-        cfg.perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_NUMBER;
+        cfg.options.perm_disp_mode = GNOME_CMD_PERM_DISP_MODE_NUMBER;
 
     gnome_cmd_data_set_date_format (g_locale_from_utf8 (format, -1, NULL, NULL, NULL));
 }
diff --git a/src/gnome-cmd-xfer-progress-win.cc b/src/gnome-cmd-xfer-progress-win.cc
index 7ffd515..208db90 100644
--- a/src/gnome-cmd-xfer-progress-win.cc
+++ b/src/gnome-cmd-xfer-progress-win.cc
@@ -170,8 +170,8 @@ void gnome_cmd_xfer_progress_win_set_total_progress (GnomeCmdXferProgressWin *wi
         gtk_progress_set_percentage (GTK_PROGRESS (win->fileprog), file_prog);
     }
 
-    gchar *bytes_total_str = g_strdup (size2string (bytes_total, gnome_cmd_data.size_disp_mode));
-    const gchar *bytes_copied_str = size2string (bytes_copied, gnome_cmd_data.size_disp_mode);
+    gchar *bytes_total_str = g_strdup (size2string (bytes_total, gnome_cmd_data.options.size_disp_mode));
+    const gchar *bytes_copied_str = size2string (bytes_copied, gnome_cmd_data.options.size_disp_mode);
 
     gchar text[128];
 
diff --git a/src/utils.cc b/src/utils.cc
index 6646acb..fc10680 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -287,7 +287,7 @@ const gchar *name2string (gchar *filename, gchar *buf, guint max)
 
 const gchar *perm2string (GnomeVFSFilePermissions p, gchar *buf, guint max)
 {
-    switch (gnome_cmd_data.perm_disp_mode)
+    switch (gnome_cmd_data.options.perm_disp_mode)
     {
         case GNOME_CMD_PERM_DISP_MODE_TEXT:
             return perm2textstring (p, buf, max);
@@ -815,7 +815,7 @@ gchar *create_nice_size_str (GnomeVFSFileSize size)
 {
     GString *s = g_string_sized_new (64);
 
-    if (gnome_cmd_data.size_disp_mode==GNOME_CMD_SIZE_DISP_MODE_POWERED && size>=1000)
+    if (gnome_cmd_data.options.size_disp_mode==GNOME_CMD_SIZE_DISP_MODE_POWERED && size>=1000)
     {
         g_string_printf (s, "%s", size2string (size, GNOME_CMD_SIZE_DISP_MODE_POWERED));
         g_string_append_printf (s, ngettext("(%sbyte)","(%sbytes)",size), size2string (size, GNOME_CMD_SIZE_DISP_MODE_GROUPED));



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