~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to rhythmdb/rhythmdb-tree.c

Tags: upstream-0.9.2cvs20060102
ImportĀ upstreamĀ versionĀ 0.9.2cvs20060102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 * 
2
3
 *  arch-tag: Implementation of RhythmDB tree-structured database
3
4
 *
4
5
 *  Copyright (C) 2003, 2004 Colin Walters <walters@verbum.org>
33
34
#include <string.h>
34
35
#include <glib/gprintf.h>
35
36
#include <glib/gatomic.h>
36
 
#include <libgnome/gnome-i18n.h>
 
37
#include <glib/gi18n.h>
37
38
#include <gtk/gtkliststore.h>
38
39
#include <libxml/entities.h>
39
40
#include <libxml/SAX.h>
111
112
 
112
113
struct RhythmDBTreePrivate
113
114
{
114
 
        GMemChunk *property_memchunk;
115
 
 
116
115
        GHashTable *entries;
117
116
        GHashTable *genres;
118
117
        GMutex *genres_lock;
121
120
        guint idle_load_id;
122
121
};
123
122
 
 
123
#define RHYTHMDB_TREE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RHYTHMDB_TYPE_TREE, RhythmDBTreePrivate))
 
124
 
124
125
enum
125
126
{
126
127
        PROP_0,
147
148
        rhythmdb_class->impl_entry_foreach = rhythmdb_tree_entry_foreach;
148
149
        rhythmdb_class->impl_evaluate_query = rhythmdb_tree_evaluate_query;
149
150
        rhythmdb_class->impl_do_full_query = rhythmdb_tree_do_full_query;
 
151
 
 
152
        g_type_class_add_private (klass, sizeof (RhythmDBTreePrivate));
150
153
}
151
154
 
152
155
static void
153
156
rhythmdb_tree_init (RhythmDBTree *db)
154
157
{
155
 
        db->priv = g_new0 (RhythmDBTreePrivate, 1);
 
158
        db->priv = RHYTHMDB_TREE_GET_PRIVATE (db);
156
159
 
157
160
        db->priv->entries = g_hash_table_new (g_str_hash, g_str_equal);
158
161
 
159
 
        db->priv->property_memchunk = g_mem_chunk_new ("RhythmDBTree property memchunk",
160
 
                                                       sizeof (RhythmDBTreeProperty),
161
 
                                                       1024, G_ALLOC_AND_FREE);
162
162
        db->priv->genres = g_hash_table_new_full (g_direct_hash, g_direct_equal,
163
163
                                                  NULL, (GDestroyNotify)g_hash_table_destroy);
164
164
}
187
187
 
188
188
        g_hash_table_destroy (db->priv->entries);
189
189
 
190
 
        g_mem_chunk_destroy (db->priv->property_memchunk);
191
 
 
192
190
        g_hash_table_destroy (db->priv->genres);
193
191
 
194
 
        g_free (db->priv);
195
 
 
196
192
        G_OBJECT_CLASS (rhythmdb_tree_parent_class)->finalize (object);
197
193
}
198
194
 
326
322
                        rb_debug ("pre-Date entry found, causing re-read");
327
323
                        ctx->entry->mtime = 0;
328
324
                }
329
 
                rhythmdb_tree_entry_new (RHYTHMDB (ctx->db), ctx->entry);
330
 
                rhythmdb_entry_insert (RHYTHMDB (ctx->db), ctx->entry);
331
 
                rhythmdb_commit (RHYTHMDB (ctx->db));
 
325
                if (ctx->entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED && ctx->entry->podcast->post_time == 0) {
 
326
                        /* Handle upgrades from 0.9.2.
 
327
                         * Previously, last-seen for podcast feeds was the time of the last post,
 
328
                         * and post-time was unused.  Now, we want last-seen to be the time we
 
329
                         * last updated the feed, and post-time to be the time of the last post.
 
330
                         */
 
331
                        ctx->entry->podcast->post_time = ctx->entry->last_seen;
 
332
                }
 
333
                
 
334
                if (ctx->entry->location != NULL) {
 
335
                        rhythmdb_tree_entry_new (RHYTHMDB (ctx->db), ctx->entry);
 
336
                        rhythmdb_entry_insert (RHYTHMDB (ctx->db), ctx->entry);
 
337
                        rhythmdb_commit (RHYTHMDB (ctx->db));
 
338
                } else {
 
339
                        rb_debug ("found entry without location");
 
340
                        rhythmdb_entry_unref (RHYTHMDB (ctx->db), ctx->entry);
 
341
                }
332
342
                ctx->state = RHYTHMDB_TREE_PARSER_STATE_RHYTHMDB;
333
343
                break;
334
344
        }
956
966
static RhythmDBTreeProperty *
957
967
rhythmdb_tree_property_new (RhythmDBTree *db)
958
968
{
959
 
        RhythmDBTreeProperty *ret = g_mem_chunk_alloc0 (db->priv->property_memchunk);
 
969
        RhythmDBTreeProperty *ret = g_new0 (RhythmDBTreeProperty, 1);
960
970
#ifndef G_DISABLE_ASSERT
961
971
        ret->magic = 0xf00dbeef;
962
972
#endif  
1278
1288
        prop->magic = 0xf33df33d;
1279
1289
#endif
1280
1290
        g_hash_table_destroy (prop->children);
 
1291
        g_free (prop);
1281
1292
}
1282
1293
 
1283
1294
typedef void (*RhythmDBTreeTraversalFunc) (RhythmDBTree *db, RhythmDBEntry *entry, gpointer data);