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



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

Log:
DeGTK+ization of GnomeCmdFileCollection

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:12:18 2008
@@ -112,7 +112,7 @@
 
     gnome_cmd_con_remove_from_cache (dir->priv->con, dir);
 
-    gtk_object_destroy (*dir->priv->file_collection);
+    delete dir->priv->file_collection;
 
     if (dir->priv->path)
         gtk_object_unref (GTK_OBJECT (dir->priv->path));
@@ -221,7 +221,7 @@
     dir->priv->monitor_handle = NULL;
     dir->priv->monitor_users = 0;
     dir->priv->files = NULL;
-    dir->priv->file_collection = gnome_cmd_file_collection_new ();
+    dir->priv->file_collection = new GnomeCmdFileCollection;
 }
 
 

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:12:18 2008
@@ -24,93 +24,14 @@
 using namespace std;
 
 
-struct GnomeCmdFileCollectionClass
-{
-    GtkObjectClass parent_class;
-};
-
-
-struct GnomeCmdFileCollection::Private
-{
-    GHashTable *map;
-    GList *list;
-};
-
-static GtkObjectClass *gnome_cmd_file_collection_parent_class = NULL;
-
-
-/*******************************
- * Gtk class implementation
- *******************************/
-
-static void gnome_cmd_file_collection_destroy (GtkObject *obj)
-{
-    GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
-
-    g_hash_table_destroy (collection->priv->map);
-    g_list_free (collection->priv->list);
-    g_free (collection->priv);
-
-    if (GTK_OBJECT_CLASS (gnome_cmd_file_collection_parent_class)->destroy)
-        (*GTK_OBJECT_CLASS (gnome_cmd_file_collection_parent_class)->destroy) (obj);
-}
-
-
-static void gnome_cmd_file_collection_class_init (GnomeCmdFileCollectionClass *klass)
-{
-    GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
-
-    gnome_cmd_file_collection_parent_class = (GtkObjectClass *) gtk_type_class (gtk_object_get_type ());
-
-    object_class->destroy = gnome_cmd_file_collection_destroy;
-}
-
-
-static void gnome_cmd_file_collection_init (GnomeCmdFileCollection *collection)
-{
-    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;
-}
-
-
-
-/***********************************
- * Public functions
- ***********************************/
-
-GtkType gnome_cmd_file_collection_get_type ()
-{
-    static GtkType type = 0;
-
-    if (type == 0)
-    {
-        GtkTypeInfo info =
-        {
-            "GnomeCmdFileCollection",
-            sizeof (GnomeCmdFileCollection),
-            sizeof (GnomeCmdFileCollectionClass),
-            (GtkClassInitFunc) gnome_cmd_file_collection_class_init,
-            (GtkObjectInitFunc) gnome_cmd_file_collection_init,
-            /* reserved_1 */ NULL,
-            /* reserved_2 */ NULL,
-            (GtkClassInitFunc) NULL
-        };
-
-        type = gtk_type_unique (gtk_object_get_type (), &info);
-    }
-    return type;
-}
-
-
 void GnomeCmdFileCollection::add(GnomeCmdFile *file)
 {
     g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
-    priv->list = g_list_append (priv->list, file);
+    list = g_list_append (list, file);
 
     gchar *uri_str = gnome_cmd_file_get_uri_str (file);
-    g_hash_table_insert (priv->map, uri_str, file);
+    g_hash_table_insert (map, uri_str, file);
     gnome_cmd_file_ref (file);
 }
 
@@ -119,10 +40,10 @@
 {
     g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
-    priv->list = g_list_remove (priv->list, file);
+    list = g_list_remove (list, file);
 
     gchar *uri_str = gnome_cmd_file_get_uri_str (file);
-    g_hash_table_remove (priv->map, uri_str);
+    g_hash_table_remove (map, uri_str);
     g_free (uri_str);
 }
 
@@ -132,9 +53,9 @@
     g_return_if_fail (uri_str != NULL);
 
     GnomeCmdFile *file = find(uri_str);
-    priv->list = g_list_remove (priv->list, file);
 
-    g_hash_table_remove (priv->map, uri_str);
+    list = g_list_remove (list, file);
+    g_hash_table_remove (map, uri_str);
 }
 
 
@@ -142,28 +63,22 @@
 {
     g_return_val_if_fail (uri_str != NULL, NULL);
 
-    return GNOME_CMD_FILE (g_hash_table_lookup (priv->map, uri_str));
+    return GNOME_CMD_FILE (g_hash_table_lookup (map, uri_str));
 }
 
 
 void GnomeCmdFileCollection::clear()
 {
-    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 *GnomeCmdFileCollection::get_list()
-{
-    return priv->list;
+    g_list_free (list);
+    list = NULL;
+    g_hash_table_destroy (map);
+    map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_cmd_file_unref);
 }
 
 
 GList *GnomeCmdFileCollection::sort(GCompareDataFunc compare_func, gpointer user_data)
 {
-    priv->list = g_list_sort_with_data (priv->list, compare_func, user_data);
+    list = g_list_sort_with_data (list, compare_func, user_data);
 
-    return priv->list;
+    return 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:12:18 2008
@@ -23,28 +23,19 @@
 
 #include "gnome-cmd-file.h"
 
-#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)
 
-
-GtkType gnome_cmd_file_collection_get_type ();
-
-
-struct GnomeCmdFileCollection
+class GnomeCmdFileCollection
 {
-    GtkObject parent;
-
-    class Private;
+    GHashTable *map;
+    GList *list;
 
-    Private *priv;
+  public:
 
-    operator GtkObject * ()             {  return GTK_OBJECT (this);    }
+    GnomeCmdFileCollection();
+    ~GnomeCmdFileCollection();
 
-    GList *get_list();
-
-    guint size()        {  return g_list_length (get_list());  }
-    gboolean empty()    {  return get_list()==NULL;            }
+    guint size()        {  return g_list_length (list);  }
+    gboolean empty()    {  return list==NULL;            }
     void clear();
 
     void add(GnomeCmdFile *file);
@@ -52,22 +43,32 @@
     void remove(GnomeCmdFile *file);
     void remove(const gchar *uri_str);
 
+    GList *get_list()   {  return list;  }
+
     GnomeCmdFile *find(const gchar *uri_str);
 
     GList *sort(GCompareDataFunc compare_func, gpointer user_data);
 };
 
 
-inline void GnomeCmdFileCollection::add(GList *files)
+inline GnomeCmdFileCollection::GnomeCmdFileCollection()
 {
-    for (; files; files = files->next)
-        add(GNOME_CMD_FILE (files->data));
+    map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_cmd_file_unref);
+    list = NULL;
+}
+
+
+inline GnomeCmdFileCollection::~GnomeCmdFileCollection()
+{
+    g_hash_table_destroy (map);
+    g_list_free (list);
 }
 
 
-inline GnomeCmdFileCollection *gnome_cmd_file_collection_new ()
+inline void GnomeCmdFileCollection::add(GList *files)
 {
-    return (GnomeCmdFileCollection *) gtk_type_new (GNOME_CMD_TYPE_FILE_COLLECTION);
+    for (; files; files = files->next)
+        add(GNOME_CMD_FILE (files->data));
 }
 
 #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:12:18 2008
@@ -1220,7 +1220,7 @@
 {
     GnomeCmdFileList *fl = GNOME_CMD_FILE_LIST (object);
 
-    gtk_object_destroy (*fl->priv->shown_files);
+    delete fl->priv->shown_files;
     gnome_cmd_file_list_free (fl->priv->selected_files);
 
     g_free (fl->priv);
@@ -1291,7 +1291,7 @@
 static void init (GnomeCmdFileList *fl)
 {
     fl->priv = g_new0 (GnomeCmdFileList::Private, 1);
-    fl->priv->shown_files = gnome_cmd_file_collection_new ();
+    fl->priv->shown_files = new GnomeCmdFileCollection;
     // fl->priv->selected_files = NULL;
     // fl->priv->shift_down = FALSE;
     // fl->priv->selpat_dialog = NULL;



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