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

« back to all changes in this revision

Viewing changes to podcast/rb-podcast-manager.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        GAsyncQueue *event_queue;
94
94
};
95
95
 
 
96
#define RB_PODCAST_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_PODCAST_MANAGER, RBPodcastManagerPrivate))
 
97
 
96
98
/* used on event loop */
97
99
typedef struct
98
100
{
261
263
                                G_TYPE_NONE,
262
264
                                1,
263
265
                                G_TYPE_POINTER);
264
 
                                        
 
266
 
 
267
        g_type_class_add_private (klass, sizeof (RBPodcastManagerPrivate));
265
268
}       
266
269
 
267
270
static void
268
271
rb_podcast_manager_init (RBPodcastManager *pd)
269
272
{
270
 
        pd->priv = g_new0 (RBPodcastManagerPrivate, 1);
 
273
        pd->priv = RB_PODCAST_MANAGER_GET_PRIVATE (pd);
 
274
 
271
275
        pd->priv->source_sync = 0;
272
276
        pd->priv->mutex_job = g_mutex_new();
273
277
        pd->priv->download_list_mutex = g_mutex_new();
278
282
 
279
283
static GObject *
280
284
rb_podcast_manager_constructor (GType type, guint n_construct_properties,
281
 
                           GObjectConstructParam *construct_properties)
 
285
                                GObjectConstructParam *construct_properties)
282
286
{
283
287
        RBPodcastManager *pd;
284
288
 
326
330
        g_mutex_free (pd->priv->mutex_job);     
327
331
        g_mutex_free (pd->priv->download_list_mutex);   
328
332
        g_async_queue_unref (pd->priv->event_queue);
329
 
        
330
 
        g_free (pd->priv);
331
 
        
 
333
 
332
334
        G_OBJECT_CLASS (rb_podcast_manager_parent_class)->finalize (object);
333
335
        rb_debug ("Podcast Manager END");
334
336
}
335
337
 
336
338
static void 
337
339
rb_podcast_manager_set_property (GObject *object,
338
 
                                        guint prop_id,
339
 
                                        const GValue *value,
340
 
                                        GParamSpec *pspec)
 
340
                                 guint prop_id,
 
341
                                 const GValue *value,
 
342
                                 GParamSpec *pspec)
341
343
{
342
344
        RBPodcastManager *pd = RB_PODCAST_MANAGER (object);
343
345
 
344
 
        switch (prop_id)
345
 
        {
 
346
        switch (prop_id) {
346
347
        case PROP_DB:
347
348
                if (pd->priv->db) {
348
349
                        g_signal_handlers_disconnect_by_func (G_OBJECT (pd->priv->db),
381
382
{
382
383
        RBPodcastManager *pd = RB_PODCAST_MANAGER (object);
383
384
 
384
 
        switch (prop_id)
385
 
        {
 
385
        switch (prop_id) {
386
386
        case PROP_DB:
387
387
                g_value_set_object (value, pd->priv->db);
388
388
                break;
432
432
        }
433
433
}
434
434
 
 
435
gboolean
 
436
rb_podcast_manager_entry_downloaded (RhythmDBEntry *entry)
 
437
{
 
438
        g_assert (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST);
 
439
 
 
440
        gulong status;
 
441
        const gchar *file_name;
 
442
 
 
443
        status = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_STATUS);
 
444
        file_name = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MOUNTPOINT);
 
445
 
 
446
        return (status != RHYTHMDB_PODCAST_STATUS_ERROR && file_name != NULL);
 
447
}
435
448
 
436
449
void
437
450
rb_podcast_manager_start_sync (RBPodcastManager *pd)
1384
1397
        GValue author_val = { 0, };
1385
1398
        GValue status_val = { 0, };
1386
1399
        GValue last_post_val = { 0, };
 
1400
        GValue last_update_val = { 0, };
1387
1401
        gulong last_post = 0;
1388
1402
        gulong new_last_post;
1389
1403
        gboolean new_feed, updated;
1412
1426
                g_value_set_ulong (&status_val, 1);
1413
1427
                rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_STATUS, &status_val);
1414
1428
                g_value_unset (&status_val);
1415
 
                last_post = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_LAST_SEEN);
 
1429
                last_post = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_POST_TIME);
1416
1430
                new_feed = FALSE;
1417
1431
        } else {
1418
1432
                rb_debug ("Insert new entry");
1492
1506
        for (lst_songs = data->posts; lst_songs != NULL; lst_songs = g_list_next (lst_songs)) {
1493
1507
                RBPodcastItem *item = (RBPodcastItem *) lst_songs->data;
1494
1508
 
1495
 
                if (item->pub_date > last_post) {
 
1509
                if (item->pub_date > last_post || item->pub_date == 0) {
1496
1510
                        gulong status;
1497
1511
                        updated = TRUE;
1498
1512
 
1529
1543
        g_value_set_ulong (&last_post_val, new_last_post);
1530
1544
 
1531
1545
        if (new_feed) 
1532
 
                rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_LAST_SEEN, &last_post_val);
 
1546
                rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_POST_TIME, &last_post_val);
1533
1547
        else
1534
 
                rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_LAST_SEEN, &last_post_val);
 
1548
                rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_POST_TIME, &last_post_val);
1535
1549
        g_value_unset (&last_post_val);
 
1550
 
 
1551
        g_value_init (&last_update_val, G_TYPE_ULONG);
 
1552
        g_value_set_ulong (&last_update_val, time(NULL));
 
1553
 
 
1554
        if (new_feed)
 
1555
                rhythmdb_entry_set_uninserted (db, entry, RHYTHMDB_PROP_LAST_SEEN, &last_update_val);
 
1556
        else
 
1557
                rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_LAST_SEEN, &last_update_val);
 
1558
        g_value_unset (&last_update_val);
1536
1559
        
1537
1560
        rhythmdb_commit (db);
1538
1561
}