gnome-commander r1969 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Tue Aug 12 21:40:26 2008
New Revision: 1969
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1969&view=rev

Log:
Convert GnomeCmdFileList struct into C++ class, part 1

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-file-list.cc
   branches/gcmd-1-3/src/gnome-cmd-file-list.h
   branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
   branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-xfer.cc

Modified: branches/gcmd-1-3/src/gnome-cmd-file-list.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-list.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-list.cc	Tue Aug 12 21:40:26 2008
@@ -76,7 +76,7 @@
 static guint file_list_signals[LAST_SIGNAL] = { 0 };
 
 
-typedef struct
+struct GnomeCmdFileListColumn
 {
     guint id;
     const gchar *title;
@@ -84,7 +84,7 @@
     GtkJustification justification;
     GtkSortType default_sort_direction;
     GCompareDataFunc sort_func;
-} GnomeCmdFileListColumn;
+};
 
 
 static gint sort_by_name (GnomeCmdFile *f1, GnomeCmdFile *f2, GnomeCmdFileList *fl);
@@ -109,18 +109,22 @@
  {FILE_LIST_COLUMN_GROUP, N_("gid"), 50, GTK_JUSTIFY_LEFT, GTK_SORT_ASCENDING, (GCompareDataFunc) sort_by_group}};
 
 
-struct _GnomeCmdFileListPrivate
+class GnomeCmdFileList::Private
 {
+  public:
+
     GtkWidget *column_pixmaps[FILE_LIST_NUM_COLUMNS];
     GtkWidget *column_labels[FILE_LIST_NUM_COLUMNS];
     GtkWidget *popup_menu;
 
+    gint cur_file;
+    GList *selected_files;                         // contains GnomeCmdFile pointers
+    GnomeCmdFileCollection *shown_files;
+
     GCompareDataFunc sort_func;
     gint current_col;
     gboolean sort_raising[FILE_LIST_NUM_COLUMNS];
-    GnomeCmdFileCollection *shown_files;
-    GList *selected_files;                         // contains GnomeCmdFile pointers
-    gint cur_file;
+
     gboolean shift_down;
     gint shift_down_row;
     GnomeCmdFile *right_mb_down_file;
@@ -132,14 +136,79 @@
 };
 
 
-typedef struct
+inline gchar *strip_extension (const gchar *fname)
+{
+    gchar *s = g_strdup (fname);
+    gchar *p = g_strrstr (s, ".");
+    if (p && p != s)
+        *p = '\0';
+    return s;
+}
+
+
+struct FileFormatData
 {
     gchar *text[FILE_LIST_NUM_COLUMNS];
 
     gchar *dpath;
     gchar *fname;
     gchar *fext;
-} FileFormatData;
+
+    FileFormatData(GnomeCmdFile *f, gboolean tree_size);
+    ~FileFormatData();
+};
+
+
+inline FileFormatData::FileFormatData(GnomeCmdFile *f, gboolean tree_size)
+{
+    // If the user wants a character instead of icon for filetype set it now
+    if (gnome_cmd_data_get_layout () == GNOME_CMD_LAYOUT_TEXT)
+        text[FILE_LIST_COLUMN_ICON] = (gchar *) gnome_cmd_file_get_type_string (f);
+    else
+        text[FILE_LIST_COLUMN_ICON] = NULL;
+
+    // Prepare the strings to show
+    gchar *t1 = gnome_cmd_file_get_path (f);
+    gchar *t2 = g_path_get_dirname (t1);
+    dpath = get_utf8 (t2);
+    g_free (t1);
+    g_free (t2);
+
+    if (gnome_cmd_data_get_ext_disp_mode () == GNOME_CMD_EXT_DISP_STRIPPED
+        && f->info->type == GNOME_VFS_FILE_TYPE_REGULAR)
+    {
+        gchar *t = strip_extension (gnome_cmd_file_get_name (f));
+        fname = get_utf8 (t);
+        g_free (t);
+    }
+    else
+        fname = get_utf8 (gnome_cmd_file_get_name (f));
+
+    if (gnome_cmd_data_get_ext_disp_mode () != GNOME_CMD_EXT_DISP_WITH_FNAME)
+        fext = get_utf8 (gnome_cmd_file_get_extension (f));
+    else
+        fext = NULL;
+
+    //Set other file information
+    text[FILE_LIST_COLUMN_NAME]  = fname;
+    text[FILE_LIST_COLUMN_EXT]   = fext;
+    text[FILE_LIST_COLUMN_DIR]   = dpath;
+    text[FILE_LIST_COLUMN_SIZE]  = tree_size ? (gchar *) gnome_cmd_file_get_tree_size_as_str (f) :
+                                               (gchar *) gnome_cmd_file_get_size (f);
+    text[FILE_LIST_COLUMN_DATE]  = (gchar *) gnome_cmd_file_get_mdate (f, FALSE);
+    text[FILE_LIST_COLUMN_PERM]  = (gchar *) gnome_cmd_file_get_perm (f);
+    text[FILE_LIST_COLUMN_OWNER] = (gchar *) gnome_cmd_file_get_owner (f);
+    text[FILE_LIST_COLUMN_GROUP] = (gchar *) gnome_cmd_file_get_group (f);
+    text[FILE_LIST_NUM_COLUMNS]  = NULL;
+}
+
+
+inline FileFormatData::~FileFormatData()
+{
+    g_free (dpath);
+    g_free (fname);
+    g_free (fext);
+}
 
 
 inline char *gnome_cmd_get_collation_fname (GnomeCmdFile *f)
@@ -1165,8 +1234,7 @@
     gtk_object_destroy (GTK_OBJECT (fl->priv->shown_files));
     gnome_cmd_file_list_free (fl->priv->selected_files);
 
-    if (fl->priv)
-        g_free (fl->priv);
+    g_free (fl->priv);
 
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
         (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
@@ -1233,7 +1301,7 @@
 
 static void init (GnomeCmdFileList *fl)
 {
-    fl->priv = g_new0 (GnomeCmdFileListPrivate, 1);
+    fl->priv = g_new0 (GnomeCmdFileList::Private, 1);
     fl->priv->shown_files = gnome_cmd_file_collection_new ();
     // fl->priv->selected_files = NULL;
     // fl->priv->shift_down = FALSE;
@@ -1331,79 +1399,14 @@
 }
 
 
-inline gchar *strip_extension (const gchar *fname)
-{
-    gchar *s = g_strdup (fname);
-    gchar *p = g_strrstr (s, ".");
-    if (p && p != s)
-        *p = '\0';
-    return s;
-}
-
-
-inline void format_file_for_display (GnomeCmdFile *finfo, FileFormatData &data, gboolean tree_size)
-{
-    // If the user wants a character instead of icon for filetype set it now
-    if (gnome_cmd_data_get_layout () == GNOME_CMD_LAYOUT_TEXT)
-        data.text[FILE_LIST_COLUMN_ICON] = (gchar *) gnome_cmd_file_get_type_string (finfo);
-    else
-        data.text[FILE_LIST_COLUMN_ICON] = NULL;
-
-    // Prepare the strings to show
-    gchar *t1 = gnome_cmd_file_get_path (finfo);
-    gchar *t2 = g_path_get_dirname (t1);
-    data.dpath = get_utf8 (t2);
-    g_free (t1);
-    g_free (t2);
-
-    if (gnome_cmd_data_get_ext_disp_mode () == GNOME_CMD_EXT_DISP_STRIPPED
-        && finfo->info->type == GNOME_VFS_FILE_TYPE_REGULAR)
-    {
-        gchar *t = strip_extension (gnome_cmd_file_get_name (finfo));
-        data.fname = get_utf8 (t);
-        g_free (t);
-    }
-    else
-        data.fname = get_utf8 (gnome_cmd_file_get_name (finfo));
-
-    if (gnome_cmd_data_get_ext_disp_mode () != GNOME_CMD_EXT_DISP_WITH_FNAME)
-        data.fext = get_utf8 (gnome_cmd_file_get_extension (finfo));
-    else
-        data.fext = NULL;
-
-    //Set other file information
-    data.text[FILE_LIST_COLUMN_NAME]  = data.fname;
-    data.text[FILE_LIST_COLUMN_EXT]   = data.fext;
-    data.text[FILE_LIST_COLUMN_DIR]   = data.dpath;
-    data.text[FILE_LIST_COLUMN_SIZE]  = tree_size ? (gchar *) gnome_cmd_file_get_tree_size_as_str (finfo) :
-                                                    (gchar *) gnome_cmd_file_get_size (finfo);
-    data.text[FILE_LIST_COLUMN_DATE]  = (gchar *) gnome_cmd_file_get_mdate (finfo, FALSE);
-    data.text[FILE_LIST_COLUMN_PERM]  = (gchar *) gnome_cmd_file_get_perm (finfo);
-    data.text[FILE_LIST_COLUMN_OWNER] = (gchar *) gnome_cmd_file_get_owner (finfo);
-    data.text[FILE_LIST_COLUMN_GROUP] = (gchar *) gnome_cmd_file_get_group (finfo);
-    data.text[FILE_LIST_NUM_COLUMNS]  = NULL;
-}
-
-
-inline void cleanup_file_format (FileFormatData &data)
-{
-    g_free (data.dpath);
-    g_free (data.fname);
-    g_free (data.fext);
-}
-
-
 inline void add_file_to_clist (GnomeCmdFileList *fl, GnomeCmdFile *finfo, gint in_row)
 {
     GtkCList *clist = GTK_CLIST (fl);
-    FileFormatData data;
 
-    format_file_for_display (finfo, data, FALSE);
+    FileFormatData data(finfo,FALSE);
 
     gint row = in_row == -1 ? gtk_clist_append (clist, data.text) : gtk_clist_insert (clist, in_row, data.text);
 
-    cleanup_file_format (data);
-
     // Setup row data and color
     if (!gnome_cmd_data_get_use_ls_colors ())
         gtk_clist_set_row_style (clist, row, list_style);
@@ -1438,23 +1441,22 @@
 
 /******************************************************************************
 *
-*   Function: gnome_cmd_file_list_append_file
+*   Function: GnomeCmdFileList::append_file
 *
 *   Purpose:  Add a file to the list
 *
-*   Params:   @fl: The FileList to add the file to
-*             @finfo: The file to add
+*   Params:   @f: The file to add
 *
 *   Returns:
 *
 *   Statuses:
 *
 ******************************************************************************/
-void gnome_cmd_file_list_append_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo)
+void GnomeCmdFileList::append_file (GnomeCmdFile *f)
 {
-    gnome_cmd_file_collection_add (fl->priv->shown_files, finfo);
+    gnome_cmd_file_collection_add (priv->shown_files, f);
 
-    add_file_to_clist (fl, finfo, -1);
+    add_file_to_clist (this, f, -1);
 }
 
 
@@ -1492,7 +1494,7 @@
 
     gtk_clist_freeze (GTK_CLIST (fl));
     for (; tmp; tmp = tmp->next)
-        gnome_cmd_file_list_append_file (fl, GNOME_CMD_FILE (tmp->data));
+        fl->append_file(GNOME_CMD_FILE (tmp->data));
     gtk_clist_thaw (GTK_CLIST (fl));
 
     if (list)
@@ -1520,7 +1522,7 @@
     }
 
     // Insert the file at the end of the list
-    gnome_cmd_file_list_append_file (fl, finfo);
+    fl->append_file(finfo);
 }
 
 
@@ -1533,13 +1535,10 @@
     if (row == -1)
         return;
 
-    FileFormatData data;
-    format_file_for_display (finfo, data, FALSE);
+    FileFormatData data(finfo, FALSE);
 
     for (gint i=1; i<FILE_LIST_NUM_COLUMNS; i++)
         gtk_clist_set_text (GTK_CLIST (fl), row, i, data.text[i]);
-
-    cleanup_file_format (data);
 }
 
 
@@ -1552,45 +1551,39 @@
     if (row == -1)
         return;
 
-    FileFormatData data;
-
-    format_file_for_display (finfo, data, TRUE);
+    FileFormatData data(finfo,TRUE);
 
     for (gint i=1; i<FILE_LIST_NUM_COLUMNS; i++)
         gtk_clist_set_text (GTK_CLIST (fl), row, i, data.text[i]);
-
-    cleanup_file_format (data);
 }
 
 
-void gnome_cmd_file_list_remove_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo)
+void GnomeCmdFileList::remove_file (GnomeCmdFile *f)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
-    g_return_if_fail (finfo != NULL);
+    g_return_if_fail (f != NULL);
 
-    gint row = get_row_from_file (fl, finfo);
+    gint row = get_row_from_file (this, f);
 
     if (row >= 0)
     {
-        gtk_clist_remove (GTK_CLIST (fl), row);
+        gtk_clist_remove (GTK_CLIST (this), row);
 
-        fl->priv->selected_files = g_list_remove (fl->priv->selected_files, finfo);
-        gnome_cmd_file_collection_remove (fl->priv->shown_files, finfo);
+        priv->selected_files = g_list_remove (priv->selected_files, f);
+        gnome_cmd_file_collection_remove (priv->shown_files, f);
 
-        focus_file_at_row (fl, MIN (row, GTK_CLIST (fl)->focus_row));
+        focus_file_at_row (this, MIN (row, GTK_CLIST (this)->focus_row));
     }
 }
 
 
-void gnome_cmd_file_list_remove_file_by_uri (GnomeCmdFileList *fl, const gchar *uri_str)
+void GnomeCmdFileList::remove_file (const gchar *uri_str)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
     g_return_if_fail (uri_str != NULL);
 
-    GnomeCmdFile *file = gnome_cmd_file_collection_lookup (fl->priv->shown_files, uri_str);
-    g_return_if_fail (GNOME_CMD_IS_FILE (file));
+    GnomeCmdFile *f = gnome_cmd_file_collection_lookup (priv->shown_files, uri_str);
+    g_return_if_fail (GNOME_CMD_IS_FILE (f));
 
-    gnome_cmd_file_list_remove_file (fl, file);
+    remove_file (f);
 }
 
 

Modified: branches/gcmd-1-3/src/gnome-cmd-file-list.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-list.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-list.h	Tue Aug 12 21:40:26 2008
@@ -21,21 +21,14 @@
 #define __GNOME_CMD_FILE_LIST_H__
 
 
-#define GNOME_CMD_FILE_LIST(obj) \
-    GTK_CHECK_CAST (obj, gnome_cmd_file_list_get_type (), GnomeCmdFileList)
-#define GNOME_CMD_FILE_LIST_CLASS(klass) \
-    GTK_CHECK_CLASS_CAST (klass, gnome_cmd_file_list_get_type (), GnomeCmdFileListClass)
-#define GNOME_CMD_IS_FILE_LIST(obj) \
-    GTK_CHECK_TYPE (obj, gnome_cmd_file_list_get_type ())
-
-typedef struct _GnomeCmdFileList GnomeCmdFileList;
-typedef struct _GnomeCmdFileListPrivate GnomeCmdFileListPrivate;
-typedef struct _GnomeCmdFileListClass GnomeCmdFileListClass;
+#define GNOME_CMD_FILE_LIST(obj)          GTK_CHECK_CAST (obj, gnome_cmd_file_list_get_type (), GnomeCmdFileList)
+#define GNOME_CMD_FILE_LIST_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gnome_cmd_file_list_get_type (), GnomeCmdFileListClass)
+#define GNOME_CMD_IS_FILE_LIST(obj)       GTK_CHECK_TYPE (obj, gnome_cmd_file_list_get_type ())
 
 #include "gnome-cmd-file.h"
 #include "gnome-cmd-clist.h"
 
-typedef enum
+enum GnomeCmdFileListColumnID
 {
     FILE_LIST_COLUMN_ICON,
     FILE_LIST_COLUMN_NAME,
@@ -47,7 +40,7 @@
     FILE_LIST_COLUMN_OWNER,
     FILE_LIST_COLUMN_GROUP,
     FILE_LIST_NUM_COLUMNS
-} GnomeCmdFileListColumnID;
+};
 
 
 /* DnD target names */
@@ -57,25 +50,34 @@
 #define TARGET_URL_TYPE                 "_NETSCAPE_URL"
 
 /* Standard DnD types */
-typedef enum
+enum TargetType
 {
         TARGET_MC_DESKTOP_ICON,
         TARGET_URI_LIST,
         TARGET_TEXT_PLAIN,
         TARGET_URL,
         TARGET_NTARGETS
-} TargetType;
+};
 
 
-struct _GnomeCmdFileList
+struct GnomeCmdFileList
 {
     GnomeCmdCList parent;
 
-    GnomeCmdFileListPrivate *priv;
+    struct Private;
+
+    Private *priv;
+
+    void show_column (GnomeCmdFileListColumnID col, gboolean value)     {  gtk_clist_set_column_visibility (GTK_CLIST (this), col, value); }
+
+    void append_file (GnomeCmdFile *f);
+    void remove_file (GnomeCmdFile *f);
+    void remove_file (const gchar *uri_str);
+
 };
 
 
-struct _GnomeCmdFileListClass
+struct GnomeCmdFileListClass
 {
     GnomeCmdCListClass parent_class;
 
@@ -91,33 +93,21 @@
 
 
 GtkType gnome_cmd_file_list_get_type (void);
-
 GtkWidget *gnome_cmd_file_list_new (void);
 
-inline void gnome_cmd_file_list_show_column (GnomeCmdFileList *fl, GnomeCmdFileListColumnID col, gboolean value)
-{
-    g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
-
-    gtk_clist_set_column_visibility (GTK_CLIST (fl), col, value);
-}
-
 GnomeCmdFileListColumnID gnome_cmd_file_list_get_sort_column (GnomeCmdFileList *fl);
 guint gnome_cmd_file_list_get_column_default_width (GnomeCmdFileListColumnID col);
 
 void gnome_cmd_file_list_update_style (GnomeCmdFileList *fl);
 
-void gnome_cmd_file_list_append_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo);
-void gnome_cmd_file_list_show_files (GnomeCmdFileList *fl, GList *files, gboolean sort);
 void gnome_cmd_file_list_insert_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo);
+void gnome_cmd_file_list_show_files (GnomeCmdFileList *fl, GList *files, gboolean sort);
 void gnome_cmd_file_list_update_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo);
 
-void gnome_cmd_file_list_remove_file (GnomeCmdFileList *fl, GnomeCmdFile *finfo);
-void gnome_cmd_file_list_remove_file_by_uri (GnomeCmdFileList *fl, const gchar *uri_str);
-
 inline void gnome_cmd_file_list_remove_files (GnomeCmdFileList *fl, GList *files)
 {
     for (; files; files = files->next)
-        gnome_cmd_file_list_remove_file (fl, (GnomeCmdFile *) files->data);
+        fl->remove_file((GnomeCmdFile *) files->data);
 }
 
 void gnome_cmd_file_list_remove_all_files (GnomeCmdFileList *fl);

Modified: branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	Tue Aug 12 21:40:26 2008
@@ -845,7 +845,7 @@
 
     if (fs->priv->cwd == dir && file_is_in_list (fs, f))
     {
-        gnome_cmd_file_list_remove_file (fs->list, f);
+        fs->list->remove_file(f);
         update_selected_files_label (fs);
     }
 }
@@ -1280,7 +1280,7 @@
     gtk_object_set_data_full (GTK_OBJECT (fs), "list_widget", fs->list_widget,
                               (GtkDestroyNotify) gtk_widget_unref);
     fs->list = GNOME_CMD_FILE_LIST (fs->list_widget);
-    gnome_cmd_file_list_show_column (fs->list, FILE_LIST_COLUMN_DIR, FALSE);
+    fs->list->show_column(FILE_LIST_COLUMN_DIR, FALSE);
 
     // create the connection combo
     fs->con_combo = gnome_cmd_combo_new (2, 1, NULL);

Modified: branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-search-dialog.cc	Tue Aug 12 21:40:26 2008
@@ -385,8 +385,8 @@
 
     // Add all files found since last update to the list
     for (GList *files = data->pdata.files; files; files = files->next)
-        gnome_cmd_file_list_append_file (GNOME_CMD_FILE_LIST (data->dialog->priv->result_list),
-                                      GNOME_CMD_FILE (files->data));
+        GNOME_CMD_FILE_LIST (data->dialog->priv->result_list)->append_file(GNOME_CMD_FILE (files->data));
+
     if (data->pdata.files)
     {
         g_list_free (data->pdata.files);

Modified: branches/gcmd-1-3/src/gnome-cmd-xfer.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-xfer.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-xfer.cc	Tue Aug 12 21:40:26 2008
@@ -279,7 +279,7 @@
                 {
                     GnomeVFSURI *src_uri = gnome_cmd_file_get_uri ((GnomeCmdFile *) data->src_files->data);
                     if (!gnome_vfs_uri_exists (src_uri))
-                        gnome_cmd_file_list_remove_file (data->src_fl, (GnomeCmdFile *) data->src_files->data);
+                        data->src_fl->remove_file((GnomeCmdFile *) data->src_files->data);
                     g_free (src_uri);
                 }
             }



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