~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/item_loader.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file item_loader.c   Asynchronously loading items
 
3
 *
 
4
 * Copyright (C) 2011 Lars Lindner <lars.lindner@gmail.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include "item_loader.h"
 
22
 
 
23
#define ITEM_LOADER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), ITEM_LOADER_TYPE, ItemLoaderPrivate))
 
24
 
 
25
struct ItemLoaderPrivate {
 
26
        fetchCallbackPtr        fetchCallback;          /**< the function to call after each item fetch */
 
27
        gpointer                fetchCallbackData;      /**< user data for the fetch callback */
 
28
 
 
29
        nodePtr         node;                   /**< the node we are loading items for */
 
30
 
 
31
        guint           idleId;                 /**< fetch callback source id */
 
32
};
 
33
 
 
34
enum {
 
35
        ITEM_BATCH_FETCHED,
 
36
        FINISHED,
 
37
        LAST_SIGNAL
 
38
};
 
39
 
 
40
static guint item_loader_signals[LAST_SIGNAL] = { 0 };
 
41
 
 
42
static GObjectClass *parent_class = NULL;
 
43
 
 
44
G_DEFINE_TYPE (ItemLoader, item_loader, G_TYPE_OBJECT);
 
45
 
 
46
static void
 
47
item_loader_finalize (GObject *object)
 
48
{
 
49
        ItemLoader *il = ITEM_LOADER (object);
 
50
 
 
51
        if (il->priv->idleId)
 
52
                g_source_remove (il->priv->idleId);
 
53
 
 
54
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
55
}
 
56
 
 
57
static void
 
58
item_loader_class_init (ItemLoaderClass *klass)
 
59
{
 
60
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
61
 
 
62
        parent_class = g_type_class_peek_parent (klass);
 
63
 
 
64
        object_class->finalize = item_loader_finalize;
 
65
 
 
66
        item_loader_signals[ITEM_BATCH_FETCHED] = 
 
67
                g_signal_new ("item-batch-fetched",
 
68
                G_OBJECT_CLASS_TYPE (object_class),
 
69
                (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
 
70
                0, 
 
71
                NULL,
 
72
                NULL,
 
73
                g_cclosure_marshal_VOID__POINTER,
 
74
                G_TYPE_NONE,
 
75
                1,
 
76
                G_TYPE_POINTER);
 
77
 
 
78
        item_loader_signals[FINISHED] = 
 
79
                g_signal_new ("finished",
 
80
                G_OBJECT_CLASS_TYPE (object_class),
 
81
                (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
 
82
                0, 
 
83
                NULL,
 
84
                NULL,
 
85
                g_cclosure_marshal_VOID__VOID,
 
86
                G_TYPE_NONE,
 
87
                0);
 
88
 
 
89
        g_type_class_add_private (object_class, sizeof(ItemLoaderPrivate));
 
90
}
 
91
 
 
92
static void
 
93
item_loader_init (ItemLoader *il)
 
94
{
 
95
        il->priv = ITEM_LOADER_GET_PRIVATE (il);
 
96
}
 
97
 
 
98
nodePtr
 
99
item_loader_get_node (ItemLoader *il)
 
100
{
 
101
        return il->priv->node;
 
102
}
 
103
 
 
104
gboolean
 
105
item_loader_fetch (gpointer user_data)
 
106
{
 
107
        ItemLoader      *il = ITEM_LOADER (user_data);
 
108
        GSList          *resultItems = NULL;
 
109
        gboolean        result;
 
110
 
 
111
        result = (*il->priv->fetchCallback)(il->priv->fetchCallbackData, &resultItems);
 
112
        if (result)
 
113
                g_signal_emit_by_name (il, "item-batch-fetched", resultItems);
 
114
        else
 
115
                g_signal_emit_by_name (il, "finished");
 
116
 
 
117
        return result;
 
118
}
 
119
 
 
120
void
 
121
item_loader_start (ItemLoader *il) 
 
122
{
 
123
        il->priv->idleId = g_idle_add (item_loader_fetch, il);
 
124
}
 
125
 
 
126
ItemLoader *
 
127
item_loader_new (fetchCallbackPtr fetchCallback, nodePtr node, gpointer fetchCallbackData)
 
128
{
 
129
        ItemLoader *il;
 
130
 
 
131
        il = ITEM_LOADER (g_object_new (ITEM_LOADER_TYPE, NULL));
 
132
        il->priv->node = node;
 
133
        il->priv->fetchCallback = fetchCallback;
 
134
        il->priv->fetchCallbackData = fetchCallbackData;
 
135
 
 
136
        return il;
 
137
}