~ubuntu-branches/ubuntu/hardy/gnome-commander/hardy

« back to all changes in this revision

Viewing changes to src/gnome-cmd-file-collection.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-06-13 15:39:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060613153948-gvrt3mb2ddk5u62o
Tags: 1.2.0-3
added --disable-scrollkeeper on build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    GNOME Commander - A GNOME based file manager 
 
2
    GNOME Commander - A GNOME based file manager
3
3
    Copyright (C) 2001-2006 Marcus Bjurman
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
15
15
    You should have received a copy of the GNU General Public License
16
16
    along with this program; if not, write to the Free Software
17
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
*/ 
 
18
*/
19
19
 
20
20
#include "gnome-cmd-includes.h"
21
21
#include "gnome-cmd-file-collection.h"
22
22
 
23
23
struct _GnomeCmdFileCollectionPrivate
24
24
{
25
 
        GHashTable *map;
26
 
        GList *list;
 
25
    GHashTable *map;
 
26
    GList *list;
27
27
};
28
28
 
29
29
static GtkObjectClass *parent_class = NULL;
36
36
static void
37
37
destroy (GtkObject *obj)
38
38
{
39
 
        GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
40
 
        
41
 
        g_hash_table_destroy (collection->priv->map);
42
 
        g_list_free (collection->priv->list);
43
 
        g_free (collection->priv);
44
 
        
45
 
        if (GTK_OBJECT_CLASS (parent_class)->destroy)
46
 
                (*GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
 
39
    GnomeCmdFileCollection *collection = GNOME_CMD_FILE_COLLECTION (obj);
 
40
 
 
41
    g_hash_table_destroy (collection->priv->map);
 
42
    g_list_free (collection->priv->list);
 
43
    g_free (collection->priv);
 
44
 
 
45
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
 
46
        (*GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
47
47
}
48
48
 
49
49
 
50
50
static void
51
51
class_init (GnomeCmdFileCollectionClass *class)
52
52
{
53
 
        GtkObjectClass *object_class;
54
 
 
55
 
        object_class = GTK_OBJECT_CLASS (class);
56
 
        parent_class = gtk_type_class (gtk_object_get_type ());
57
 
 
58
 
        object_class->destroy = destroy;
 
53
    GtkObjectClass *object_class;
 
54
 
 
55
    object_class = GTK_OBJECT_CLASS (class);
 
56
    parent_class = gtk_type_class (gtk_object_get_type ());
 
57
 
 
58
    object_class->destroy = destroy;
59
59
}
60
60
 
61
61
 
62
62
static void
63
63
init (GnomeCmdFileCollection *collection)
64
64
{
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;
69
69
}
70
70
 
71
71
 
77
77
GtkType
78
78
gnome_cmd_file_collection_get_type         (void)
79
79
{
80
 
        static GtkType type = 0;
81
 
 
82
 
        if (type == 0)
83
 
        {
84
 
                GtkTypeInfo info =
85
 
                {
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
94
 
                };
95
 
 
96
 
                type = gtk_type_unique (gtk_object_get_type (), &info);
97
 
        }
98
 
        return type;
 
80
    static GtkType type = 0;
 
81
 
 
82
    if (type == 0)
 
83
    {
 
84
        GtkTypeInfo info =
 
85
        {
 
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
 
94
        };
 
95
 
 
96
        type = gtk_type_unique (gtk_object_get_type (), &info);
 
97
    }
 
98
    return type;
99
99
}
100
100
 
101
101
 
102
102
GnomeCmdFileCollection *
103
103
gnome_cmd_file_collection_new (void)
104
104
{
105
 
        GnomeCmdFileCollection *collection;
106
 
 
107
 
        collection = gtk_type_new (gnome_cmd_file_collection_get_type ());
108
 
 
109
 
        return collection;
 
105
    GnomeCmdFileCollection *collection;
 
106
 
 
107
    collection = gtk_type_new (gnome_cmd_file_collection_get_type ());
 
108
 
 
109
    return collection;
110
110
}
111
111
 
112
112
 
113
113
void
114
114
gnome_cmd_file_collection_add (GnomeCmdFileCollection *collection,
115
 
                                                           GnomeCmdFile *file)
 
115
                               GnomeCmdFile *file)
116
116
{
117
 
        gchar *uri_str;
118
 
        
119
 
        g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
120
 
        g_return_if_fail (GNOME_CMD_IS_FILE (file));
121
 
 
122
 
        collection->priv->list = g_list_append (
123
 
                collection->priv->list, file);
124
 
        
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);
 
117
    gchar *uri_str;
 
118
 
 
119
    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
 
120
    g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
121
 
 
122
    collection->priv->list = g_list_append (
 
123
        collection->priv->list, file);
 
124
 
 
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);
128
128
}
129
129
 
130
130
 
131
131
void
132
132
gnome_cmd_file_collection_add_list (GnomeCmdFileCollection *collection,
133
 
                                                                        GList *files)
 
133
                                    GList *files)
134
134
{
135
 
        while (files) { 
136
 
                gnome_cmd_file_collection_add (
137
 
                        collection, GNOME_CMD_FILE (files->data));
138
 
                files = files->next;
139
 
        }
 
135
    while (files) {
 
136
        gnome_cmd_file_collection_add (
 
137
            collection, GNOME_CMD_FILE (files->data));
 
138
        files = files->next;
 
139
    }
140
140
}
141
141
 
142
142
 
143
143
void
144
144
gnome_cmd_file_collection_remove (GnomeCmdFileCollection *collection,
145
 
                                                                  GnomeCmdFile *file)
 
145
                                  GnomeCmdFile *file)
146
146
{
147
 
        gchar *uri_str;
148
 
        
149
 
        g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
150
 
        g_return_if_fail (GNOME_CMD_IS_FILE (file));
151
 
 
152
 
        collection->priv->list = g_list_remove (
153
 
                collection->priv->list, file);
154
 
        
155
 
        uri_str = gnome_cmd_file_get_uri_str (file);
156
 
        g_hash_table_remove (collection->priv->map, uri_str);
157
 
        g_free (uri_str);
 
147
    gchar *uri_str;
 
148
 
 
149
    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
 
150
    g_return_if_fail (GNOME_CMD_IS_FILE (file));
 
151
 
 
152
    collection->priv->list = g_list_remove (
 
153
        collection->priv->list, file);
 
154
 
 
155
    uri_str = gnome_cmd_file_get_uri_str (file);
 
156
    g_hash_table_remove (collection->priv->map, uri_str);
 
157
    g_free (uri_str);
158
158
}
159
159
 
160
160
 
161
161
void
162
162
gnome_cmd_file_collection_remove_by_uri (GnomeCmdFileCollection *collection,
163
 
                                                                                 const gchar *uri_str)
 
163
                                         const gchar *uri_str)
164
164
{
165
 
        GnomeCmdFile *file;
166
 
        
167
 
        g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
168
 
        g_return_if_fail (uri_str != NULL);
169
 
 
170
 
        file = gnome_cmd_file_collection_lookup (collection, uri_str);
171
 
        collection->priv->list = g_list_remove (
172
 
                collection->priv->list, file);
173
 
        
174
 
        g_hash_table_remove (collection->priv->map, uri_str);
 
165
    GnomeCmdFile *file;
 
166
 
 
167
    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
 
168
    g_return_if_fail (uri_str != NULL);
 
169
 
 
170
    file = gnome_cmd_file_collection_lookup (collection, uri_str);
 
171
    collection->priv->list = g_list_remove (
 
172
        collection->priv->list, file);
 
173
 
 
174
    g_hash_table_remove (collection->priv->map, uri_str);
175
175
}
176
176
 
177
177
 
178
178
GnomeCmdFile *
179
179
gnome_cmd_file_collection_lookup (GnomeCmdFileCollection *collection,
180
 
                                                                  const gchar *uri_str)
 
180
                                  const gchar *uri_str)
181
181
{
182
 
        g_return_val_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection), NULL);
183
 
        g_return_val_if_fail (uri_str != NULL, NULL);
184
 
        
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);
 
184
 
 
185
    return GNOME_CMD_FILE (g_hash_table_lookup (collection->priv->map, uri_str));
186
186
}
187
187
 
188
188
 
189
189
gint
190
190
gnome_cmd_file_collection_get_size (GnomeCmdFileCollection *collection)
191
191
{
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);
193
193
 
194
 
        return g_list_length (collection->priv->list);
 
194
    return g_list_length (collection->priv->list);
195
195
}
196
196
 
197
197
 
198
198
void
199
199
gnome_cmd_file_collection_clear (GnomeCmdFileCollection *collection)
200
200
{
201
 
        g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
 
201
    g_return_if_fail (GNOME_CMD_IS_FILE_COLLECTION (collection));
202
202
 
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);
208
208
}
209
209
 
210
210
 
211
211
GList *
212
212
gnome_cmd_file_collection_get_list (GnomeCmdFileCollection *collection)
213
213
{
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);
215
215
 
216
 
        return collection->priv->list;
 
216
    return collection->priv->list;
217
217
}
218
218