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



Author: epiotr
Date: Mon Aug 25 22:04:34 2008
New Revision: 2004
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2004&view=rev

Log:
Convert GnomeCmdFileCollection struct into C++ class

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-dir.cc
   branches/gcmd-1-3/src/gnome-cmd-file-collection.cc
   branches/gcmd-1-3/src/gnome-cmd-file-collection.h
   branches/gcmd-1-3/src/gnome-cmd-file-list.cc

Modified: branches/gcmd-1-3/src/gnome-cmd-dir.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-dir.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-dir.cc	Mon Aug 25 22:04:34 2008
@@ -112,7 +112,7 @@
 
     gnome_cmd_con_remove_from_cache (dir->priv->con, dir);
 
-    gtk_object_destroy (GTK_OBJECT (dir->priv->file_collection));
+    gtk_object_destroy (*dir->priv->file_collection);
 
     if (dir->priv->path)
         gtk_object_unref (GTK_OBJECT (dir->priv->path));
@@ -484,11 +484,11 @@
     {
         DEBUG('l', "File listing succeded\n");
 
-        if (gnome_cmd_file_collection_get_size (dir->priv->file_collection))
-            gnome_cmd_file_collection_clear (dir->priv->file_collection);
+        if (!dir->priv->file_collection->empty())
+            dir->priv->file_collection->clear();
 
         dir->priv->files = create_file_list (dir, infolist);
-        gnome_cmd_file_collection_add_list (dir->priv->file_collection, dir->priv->files);
+        dir->priv->file_collection->add(dir->priv->files);
         dir->state = DIR_STATE_LISTED;
         g_list_free (infolist);
 
@@ -726,7 +726,7 @@
     g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), TRUE);
     g_return_val_if_fail (uri_str != NULL, TRUE);
 
-    GnomeCmdFile *finfo = gnome_cmd_file_collection_lookup (dir->priv->file_collection, uri_str);
+    GnomeCmdFile *finfo = dir->priv->file_collection->find(uri_str);
 
     return finfo != NULL;
 }
@@ -755,8 +755,8 @@
     else
         finfo = gnome_cmd_file_new (info, dir);
 
-    gnome_cmd_file_collection_add (dir->priv->file_collection, finfo);
-    dir->priv->files = gnome_cmd_file_collection_get_list (dir->priv->file_collection);
+    dir->priv->file_collection->add(finfo);
+    dir->priv->files = dir->priv->file_collection->get_list();
 
     gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_CREATED], finfo);
 }
@@ -769,15 +769,15 @@
     g_return_if_fail (GNOME_CMD_IS_DIR (dir));
     g_return_if_fail (uri_str != NULL);
 
-    GnomeCmdFile *finfo = gnome_cmd_file_collection_lookup (dir->priv->file_collection, uri_str);
+    GnomeCmdFile *finfo = dir->priv->file_collection->find(uri_str);
 
     if (!GNOME_CMD_IS_FILE (finfo))
         return;
 
     gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_DELETED], finfo);
 
-    gnome_cmd_file_collection_remove_by_uri (dir->priv->file_collection, uri_str);
-    dir->priv->files = gnome_cmd_file_collection_get_list (dir->priv->file_collection);
+    dir->priv->file_collection->remove(uri_str);
+    dir->priv->files = dir->priv->file_collection->get_list();
 }
 
 
@@ -790,7 +790,7 @@
     g_return_if_fail (uri_str != NULL);
 
     GnomeVFSFileInfoOptions infoOpts = GNOME_VFS_FILE_INFO_GET_MIME_TYPE;
-    GnomeCmdFile *finfo = gnome_cmd_file_collection_lookup (dir->priv->file_collection, uri_str);
+    GnomeCmdFile *finfo = dir->priv->file_collection->find(uri_str);
 
     g_return_if_fail (GNOME_CMD_IS_FILE (finfo));
 
@@ -813,8 +813,8 @@
     if (GNOME_CMD_IS_DIR (finfo))
         gnome_cmd_con_remove_from_cache (dir->priv->con, old_uri_str);
 
-    gnome_cmd_file_collection_remove_by_uri (dir->priv->file_collection, old_uri_str);
-    gnome_cmd_file_collection_add (dir->priv->file_collection, finfo);
+    dir->priv->file_collection->remove(old_uri_str);
+    dir->priv->file_collection->add(finfo);
     gtk_signal_emit (GTK_OBJECT (dir), dir_signals[FILE_RENAMED], finfo);
 }
 

Modified: branches/gcmd-1-3/src/gnome-cmd-file-collection.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-collection.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-collection.cc	Mon Aug 25 22:04:34 2008
@@ -24,20 +24,26 @@
 using namespace std;
 
 
-struct _GnomeCmdFileCollectionPrivate
+struct GnomeCmdFileCollectionClass
+{
+    GtkObjectClass parent_class;
+};
+
+
+struct GnomeCmdFileCollection::Private
 {
     GHashTable *map;
     GList *list;
 };
 
-static GtkObjectClass *parent_class = NULL;
+static GtkObjectClass *gnome_cmd_file_collection_parent_class = NULL;
 
 
 /*******************************
  * Gtk class implementation
  *******************************/
 
-static void destroy (GtkObject *obj)
+static void gnome_cmd_file_collection_destroy (GtkObject *obj)
 {
     GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
 
@@ -45,24 +51,24 @@
     g_list_free (collection->priv->list);
     g_free (collection->priv);
 
-    if (GTK_OBJECT_CLASS (parent_class)->destroy)
-        (*GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
+    if (GTK_OBJECT_CLASS (gnome_cmd_file_collection_parent_class)->destroy)
+        (*GTK_OBJECT_CLASS (gnome_cmd_file_collection_parent_class)->destroy) (obj);
 }
 
 
-static void class_init (GnomeCmdFileCollectionClass *klass)
+static void gnome_cmd_file_collection_class_init (GnomeCmdFileCollectionClass *klass)
 {
     GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
 
-    parent_class = (GtkObjectClass *) gtk_type_class (gtk_object_get_type ());
+    gnome_cmd_file_collection_parent_class = (GtkObjectClass *) gtk_type_class (gtk_object_get_type ());
 
-    object_class->destroy = destroy;
+    object_class->destroy = gnome_cmd_file_collection_destroy;
 }
 
 
-static void init (GnomeCmdFileCollection *collection)
+static void gnome_cmd_file_collection_init (GnomeCmdFileCollection *collection)
 {
-    collection->priv = g_new0 (GnomeCmdFileCollectionPrivate, 1);
+    collection->priv = g_new0 (GnomeCmdFileCollection::Private, 1);
     collection->priv->map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_cmd_file_unref);
     collection->priv->list = NULL;
 }
@@ -73,7 +79,7 @@
  * Public functions
  ***********************************/
 
-GtkType gnome_cmd_file_collection_get_type (void)
+GtkType gnome_cmd_file_collection_get_type ()
 {
     static GtkType type = 0;
 
@@ -84,8 +90,8 @@
             "GnomeCmdFileCollection",
             sizeof (GnomeCmdFileCollection),
             sizeof (GnomeCmdFileCollectionClass),
-            (GtkClassInitFunc) class_init,
-            (GtkObjectInitFunc) init,
+            (GtkClassInitFunc) gnome_cmd_file_collection_class_init,
+            (GtkObjectInitFunc) gnome_cmd_file_collection_init,
             /* reserved_1 */ NULL,
             /* reserved_2 */ NULL,
             (GtkClassInitFunc) NULL
@@ -97,98 +103,67 @@
 }
 
 
-GnomeCmdFileCollection *gnome_cmd_file_collection_new (void)
-{
-    return (GnomeCmdFileCollection *) gtk_type_new (gnome_cmd_file_collection_get_type ());
-}
-
-
-void gnome_cmd_file_collection_add (GnomeCmdFileCollection *collection, GnomeCmdFile *file)
+void GnomeCmdFileCollection::add(GnomeCmdFile *file)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
     g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
-    collection->priv->list = g_list_append (collection->priv->list, file);
+    priv->list = g_list_append (priv->list, file);
 
     gchar *uri_str = gnome_cmd_file_get_uri_str (file);
-    g_hash_table_insert (collection->priv->map, uri_str, file);
+    g_hash_table_insert (priv->map, uri_str, file);
     gnome_cmd_file_ref (file);
 }
 
 
-void gnome_cmd_file_collection_add_list (GnomeCmdFileCollection *collection, GList *files)
-{
-    for (; files; files = files->next)
-        gnome_cmd_file_collection_add (collection, GNOME_CMD_FILE (files->data));
-}
-
-
-void gnome_cmd_file_collection_remove (GnomeCmdFileCollection *collection, GnomeCmdFile *file)
+void GnomeCmdFileCollection::remove(GnomeCmdFile *file)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
     g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
-    collection->priv->list = g_list_remove (collection->priv->list, file);
+    priv->list = g_list_remove (priv->list, file);
 
     gchar *uri_str = gnome_cmd_file_get_uri_str (file);
-    g_hash_table_remove (collection->priv->map, uri_str);
+    g_hash_table_remove (priv->map, uri_str);
     g_free (uri_str);
 }
 
 
-void gnome_cmd_file_collection_remove_by_uri (GnomeCmdFileCollection *collection, const gchar *uri_str)
+void GnomeCmdFileCollection::remove(const gchar *uri_str)
 {
-    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
     g_return_if_fail (uri_str != NULL);
 
-    GnomeCmdFile *file = gnome_cmd_file_collection_lookup (collection, uri_str);
-    collection->priv->list = g_list_remove (collection->priv->list, file);
+    GnomeCmdFile *file = find(uri_str);
+    priv->list = g_list_remove (priv->list, file);
 
-    g_hash_table_remove (collection->priv->map, uri_str);
+    g_hash_table_remove (priv->map, uri_str);
 }
 
 
-GnomeCmdFile *gnome_cmd_file_collection_lookup (GnomeCmdFileCollection *collection, const gchar *uri_str)
+GnomeCmdFile *GnomeCmdFileCollection::find(const gchar *uri_str)
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
     g_return_val_if_fail (uri_str != NULL, NULL);
 
-    return GNOME_CMD_FILE (g_hash_table_lookup (collection->priv->map, uri_str));
+    return GNOME_CMD_FILE (g_hash_table_lookup (priv->map, uri_str));
 }
 
 
-gint gnome_cmd_file_collection_get_size (GnomeCmdFileCollection *collection)
+void GnomeCmdFileCollection::clear()
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), 0);
-
-    return g_list_length (collection->priv->list);
-}
-
-
-void gnome_cmd_file_collection_clear (GnomeCmdFileCollection *collection)
-{
-    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
-
-    g_list_free (collection->priv->list);
-    collection->priv->list = NULL;
-    g_hash_table_destroy (collection->priv->map);
-    collection->priv->map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_cmd_file_unref);
+    g_list_free (priv->list);
+    priv->list = NULL;
+    g_hash_table_destroy (priv->map);
+    priv->map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_cmd_file_unref);
 }
 
 
-GList *gnome_cmd_file_collection_get_list (GnomeCmdFileCollection *collection)
+GList *GnomeCmdFileCollection::get_list()
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
-
-    return collection->priv->list;
+    return priv->list;
 }
 
 
-GList *gnome_cmd_file_collection_sort (GnomeCmdFileCollection *collection, GCompareDataFunc compare_func, gpointer user_data)
+GList *GnomeCmdFileCollection::sort(GCompareDataFunc compare_func, gpointer user_data)
 {
-    g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
-
-    collection->priv->list = g_list_sort_with_data (collection->priv->list, compare_func, user_data);
+    priv->list = g_list_sort_with_data (priv->list, compare_func, user_data);
 
-    return collection->priv->list;
+    return priv->list;
 }

Modified: branches/gcmd-1-3/src/gnome-cmd-file-collection.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-collection.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-collection.h	Mon Aug 25 22:04:34 2008
@@ -20,55 +20,54 @@
 #ifndef __GNOME_CMD_FILE_COLLECTION_H__
 #define __GNOME_CMD_FILE_COLLECTION_H__
 
+
 #include "gnome-cmd-file.h"
 
-#define GNOME_CMD_FILE_COLLECTION(obj) \
-    GTK_CHECK_CAST (obj, gnome_cmd_file_collection_get_type (), GnomeCmdFileCollection)
-#define GNOME_CMD_FILE_COLLECTION_CLASS(klass) \
-    GTK_CHECK_CLASS_CAST (klass, gnome_cmd_file_collection_get_type (), GnomeCmdFileCollectionClass)
-#define GNOME_CMD_IS_FILE_COLLECTION(obj) \
-    GTK_CHECK_TYPE (obj, gnome_cmd_file_collection_get_type ())
-#define GNOME_CMD_FILE_COLLECTION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_CMD_FILE_COLLECTION, GnomeCmdFileCollectionClass))
+#define GNOME_CMD_TYPE_FILE_COLLECTION      (gnome_cmd_file_collection_get_type ())
+#define GNOME_CMD_FILE_COLLECTION(obj)      GTK_CHECK_CAST (obj, GNOME_CMD_TYPE_FILE_COLLECTION, GnomeCmdFileCollection)
+#define GNOME_CMD_IS_FILE_COLLECTION(obj)   GTK_CHECK_TYPE (obj, GNOME_CMD_TYPE_FILE_COLLECTION)
 
 
-typedef struct _GnomeCmdFileCollection GnomeCmdFileCollection;
-typedef struct _GnomeCmdFileCollectionClass GnomeCmdFileCollectionClass;
-typedef struct _GnomeCmdFileCollectionPrivate GnomeCmdFileCollectionPrivate;
+GtkType gnome_cmd_file_collection_get_type ();
 
 
-struct _GnomeCmdFileCollection
+struct GnomeCmdFileCollection
 {
     GtkObject parent;
 
-    GnomeCmdFileCollectionPrivate *priv;
-};
-
-struct _GnomeCmdFileCollectionClass
-{
-    GtkObjectClass parent_class;
-};
+    class Private;
 
+    Private *priv;
 
-GtkType gnome_cmd_file_collection_get_type (void);
+    operator GtkObject * ()             {  return GTK_OBJECT (this);    }
 
-GnomeCmdFileCollection *gnome_cmd_file_collection_new (void);
+    GList *get_list();
 
-void gnome_cmd_file_collection_add (GnomeCmdFileCollection *collection, GnomeCmdFile *file);
+    guint size()        {  return g_list_length (get_list());  }
+    gboolean empty()    {  return get_list()==NULL;            }
+    void clear();
 
-void gnome_cmd_file_collection_add_list (GnomeCmdFileCollection *collection, GList *files);
+    void add(GnomeCmdFile *file);
+    void add(GList *files);
+    void remove(GnomeCmdFile *file);
+    void remove(const gchar *uri_str);
 
-void gnome_cmd_file_collection_remove (GnomeCmdFileCollection *collection, GnomeCmdFile *file);
+    GnomeCmdFile *find(const gchar *uri_str);
 
-void gnome_cmd_file_collection_remove_by_uri (GnomeCmdFileCollection *collection, const gchar *uri_str);
-
-GnomeCmdFile *gnome_cmd_file_collection_lookup (GnomeCmdFileCollection *collection, const gchar *uri_str);
+    GList *sort(GCompareDataFunc compare_func, gpointer user_data);
+};
 
-gint gnome_cmd_file_collection_get_size (GnomeCmdFileCollection *collection);
 
-void gnome_cmd_file_collection_clear (GnomeCmdFileCollection *collection);
+inline void GnomeCmdFileCollection::add(GList *files)
+{
+    for (; files; files = files->next)
+        add(GNOME_CMD_FILE (files->data));
+}
 
-GList *gnome_cmd_file_collection_get_list (GnomeCmdFileCollection *collection);
 
-GList *gnome_cmd_file_collection_sort (GnomeCmdFileCollection *collection, GCompareDataFunc compare_func, gpointer user_data);
+inline GnomeCmdFileCollection *gnome_cmd_file_collection_new ()
+{
+    return (GnomeCmdFileCollection *) gtk_type_new (GNOME_CMD_TYPE_FILE_COLLECTION);
+}
 
 #endif // __GNOME_CMD_FILE_COLLECTION_H__

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	Mon Aug 25 22:04:34 2008
@@ -376,7 +376,7 @@
     if (row == -1)
         return;
 
-    if (row < gnome_cmd_file_collection_get_size (fl->priv->shown_files))
+    if (row < fl->priv->shown_files->size())
         if (g_list_index (fl->priv->selected_files, finfo) == -1)
             select_file (fl, finfo);
         else
@@ -1220,7 +1220,7 @@
 {
     GnomeCmdFileList *fl = GNOME_CMD_FILE_LIST (object);
 
-    gtk_object_destroy (GTK_OBJECT (fl->priv->shown_files));
+    gtk_object_destroy (*fl->priv->shown_files);
     gnome_cmd_file_list_free (fl->priv->selected_files);
 
     g_free (fl->priv);
@@ -1441,8 +1441,7 @@
 ******************************************************************************/
 void GnomeCmdFileList::append_file (GnomeCmdFile *f)
 {
-    gnome_cmd_file_collection_add (priv->shown_files, f);
-
+    priv->shown_files->add(f);
     add_file_to_clist (this, f, -1);
 }
 
@@ -1498,7 +1497,7 @@
         GnomeCmdFile *f2 = get_file_at_row (this, i);
         if (priv->sort_func (f2, f, this) == 1)
         {
-            gnome_cmd_file_collection_add (priv->shown_files, f);
+            priv->shown_files->add(f);
             add_file_to_clist (this, f, i);
 
             if (i<=priv->cur_file)
@@ -1556,7 +1555,7 @@
         gtk_clist_remove (GTK_CLIST (this), row);
 
         priv->selected_files = g_list_remove (priv->selected_files, f);
-        gnome_cmd_file_collection_remove (priv->shown_files, f);
+        priv->shown_files->remove(f);
 
         focus_file_at_row (this, MIN (row, GTK_CLIST (this)->focus_row));
     }
@@ -1567,7 +1566,7 @@
 {
     g_return_if_fail (uri_str != NULL);
 
-    GnomeCmdFile *f = gnome_cmd_file_collection_lookup (priv->shown_files, uri_str);
+    GnomeCmdFile *f = priv->shown_files->find(uri_str);
     g_return_if_fail (GNOME_CMD_IS_FILE (f));
 
     remove_file (f);
@@ -1577,7 +1576,7 @@
 void GnomeCmdFileList::clear()
 {
     gtk_clist_clear (GTK_CLIST (this));
-    gnome_cmd_file_collection_clear (priv->shown_files);
+    priv->shown_files->clear();
     gnome_cmd_file_list_free (priv->selected_files);
     priv->selected_files = NULL;
 }
@@ -1658,7 +1657,7 @@
 {
     g_return_val_if_fail (GNOME_CMD_IS_FILE_LIST (fl), NULL);
 
-    return gnome_cmd_file_collection_get_list (fl->priv->shown_files);
+    return fl->priv->shown_files->get_list();
 }
 
 
@@ -1934,7 +1933,7 @@
     gtk_clist_clear (GTK_CLIST (this));
 
     // Resort the files and readd them to the list
-    for (GList *list = gnome_cmd_file_collection_sort (priv->shown_files, priv->sort_func, this); list; list = list->next)
+    for (GList *list = priv->shown_files->sort(priv->sort_func, this); list; list = list->next)
         add_file_to_clist (this, GNOME_CMD_FILE (list->data), -1);
 
     // refocus the previously selected file if this file-list has the focus



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