37
37
destroy (GtkObject *obj)
39
GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
41
g_hash_table_destroy (collection->priv->map);
42
g_list_free (collection->priv->list);
43
g_free (collection->priv);
45
if (GTK_OBJECT_CLASS (parent_class)->destroy)
46
(*GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
39
GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
41
g_hash_table_destroy (collection->priv->map);
42
g_list_free (collection->priv->list);
43
g_free (collection->priv);
45
if (GTK_OBJECT_CLASS (parent_class)->destroy)
46
(*GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
51
51
class_init (GnomeCmdFileCollectionClass *class)
53
GtkObjectClass *object_class;
55
object_class = GTK_OBJECT_CLASS (class);
56
parent_class = gtk_type_class (gtk_object_get_type ());
58
object_class->destroy = destroy;
53
GtkObjectClass *object_class;
55
object_class = GTK_OBJECT_CLASS (class);
56
parent_class = gtk_type_class (gtk_object_get_type ());
58
object_class->destroy = destroy;
63
63
init (GnomeCmdFileCollection *collection)
65
collection->priv = g_new (GnomeCmdFileCollectionPrivate, 1);
66
collection->priv->map = g_hash_table_new_full (
67
g_str_hash, g_str_equal, g_free, (GDestroyNotify)gnome_cmd_file_unref);
68
collection->priv->list = NULL;
65
collection->priv = g_new (GnomeCmdFileCollectionPrivate, 1);
66
collection->priv->map = g_hash_table_new_full (
67
g_str_hash, g_str_equal, g_free, (GDestroyNotify)gnome_cmd_file_unref);
68
collection->priv->list = NULL;
78
78
gnome_cmd_file_collection_get_type (void)
80
static GtkType type = 0;
86
"GnomeCmdFileCollection",
87
sizeof (GnomeCmdFileCollection),
88
sizeof (GnomeCmdFileCollectionClass),
89
(GtkClassInitFunc) class_init,
90
(GtkObjectInitFunc) init,
91
/* reserved_1 */ NULL,
92
/* reserved_2 */ NULL,
93
(GtkClassInitFunc) NULL
96
type = gtk_type_unique (gtk_object_get_type (), &info);
80
static GtkType type = 0;
86
"GnomeCmdFileCollection",
87
sizeof (GnomeCmdFileCollection),
88
sizeof (GnomeCmdFileCollectionClass),
89
(GtkClassInitFunc) class_init,
90
(GtkObjectInitFunc) init,
91
/* reserved_1 */ NULL,
92
/* reserved_2 */ NULL,
93
(GtkClassInitFunc) NULL
96
type = gtk_type_unique (gtk_object_get_type (), &info);
102
102
GnomeCmdFileCollection *
103
103
gnome_cmd_file_collection_new (void)
105
GnomeCmdFileCollection *collection;
107
collection = gtk_type_new (gnome_cmd_file_collection_get_type ());
105
GnomeCmdFileCollection *collection;
107
collection = gtk_type_new (gnome_cmd_file_collection_get_type ());
114
114
gnome_cmd_file_collection_add (GnomeCmdFileCollection *collection,
119
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
120
g_return_if_fail (GNOME_CMD_IS_FILE (file));
122
collection->priv->list = g_list_append (
123
collection->priv->list, file);
125
uri_str = gnome_cmd_file_get_uri_str (file);
126
g_hash_table_insert (collection->priv->map, uri_str, file);
127
gnome_cmd_file_ref (file);
119
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
120
g_return_if_fail (GNOME_CMD_IS_FILE (file));
122
collection->priv->list = g_list_append (
123
collection->priv->list, file);
125
uri_str = gnome_cmd_file_get_uri_str (file);
126
g_hash_table_insert (collection->priv->map, uri_str, file);
127
gnome_cmd_file_ref (file);
132
132
gnome_cmd_file_collection_add_list (GnomeCmdFileCollection *collection,
136
gnome_cmd_file_collection_add (
137
collection, GNOME_CMD_FILE (files->data));
136
gnome_cmd_file_collection_add (
137
collection, GNOME_CMD_FILE (files->data));
144
144
gnome_cmd_file_collection_remove (GnomeCmdFileCollection *collection,
149
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
150
g_return_if_fail (GNOME_CMD_IS_FILE (file));
152
collection->priv->list = g_list_remove (
153
collection->priv->list, file);
155
uri_str = gnome_cmd_file_get_uri_str (file);
156
g_hash_table_remove (collection->priv->map, uri_str);
149
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
150
g_return_if_fail (GNOME_CMD_IS_FILE (file));
152
collection->priv->list = g_list_remove (
153
collection->priv->list, file);
155
uri_str = gnome_cmd_file_get_uri_str (file);
156
g_hash_table_remove (collection->priv->map, uri_str);
162
162
gnome_cmd_file_collection_remove_by_uri (GnomeCmdFileCollection *collection,
163
const gchar *uri_str)
163
const gchar *uri_str)
167
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
168
g_return_if_fail (uri_str != NULL);
170
file = gnome_cmd_file_collection_lookup (collection, uri_str);
171
collection->priv->list = g_list_remove (
172
collection->priv->list, file);
174
g_hash_table_remove (collection->priv->map, uri_str);
167
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
168
g_return_if_fail (uri_str != NULL);
170
file = gnome_cmd_file_collection_lookup (collection, uri_str);
171
collection->priv->list = g_list_remove (
172
collection->priv->list, file);
174
g_hash_table_remove (collection->priv->map, uri_str);
179
179
gnome_cmd_file_collection_lookup (GnomeCmdFileCollection *collection,
180
const gchar *uri_str)
180
const gchar *uri_str)
182
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
183
g_return_val_if_fail (uri_str != NULL, NULL);
185
return GNOME_CMD_FILE (g_hash_table_lookup (collection->priv->map, uri_str));
182
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
183
g_return_val_if_fail (uri_str != NULL, NULL);
185
return GNOME_CMD_FILE (g_hash_table_lookup (collection->priv->map, uri_str));
190
190
gnome_cmd_file_collection_get_size (GnomeCmdFileCollection *collection)
192
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), 0);
192
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), 0);
194
return g_list_length (collection->priv->list);
194
return g_list_length (collection->priv->list);
199
199
gnome_cmd_file_collection_clear (GnomeCmdFileCollection *collection)
201
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
201
g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
203
g_list_free (collection->priv->list);
204
collection->priv->list = NULL;
205
g_hash_table_destroy (collection->priv->map);
206
collection->priv->map = g_hash_table_new_full (
207
g_str_hash, g_str_equal, g_free, (GDestroyNotify)gnome_cmd_file_unref);
203
g_list_free (collection->priv->list);
204
collection->priv->list = NULL;
205
g_hash_table_destroy (collection->priv->map);
206
collection->priv->map = g_hash_table_new_full (
207
g_str_hash, g_str_equal, g_free, (GDestroyNotify)gnome_cmd_file_unref);
212
212
gnome_cmd_file_collection_get_list (GnomeCmdFileCollection *collection)
214
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
214
g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
216
return collection->priv->list;
216
return collection->priv->list;