2
* @file item_loader.h Interface for asynchronous item loading
4
* Copyright (C) 2011 Lars Lindner <lars.lindner@gmail.com>
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.
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.
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
21
#ifndef _ITEM_LOADER_H
22
#define _ITEM_LOADER_H
24
#include <glib-object.h>
28
/* ItemLoader concept: an ItemLoader instance runs a fetch callback
29
repeatedly collecting the items the fetch callback provides. One
30
each fetch when there were items the loader emits a callback with
31
the itemset as parameter for an item view to present. */
33
typedef struct ItemLoaderPrivate ItemLoaderPrivate;
35
typedef struct ItemLoader {
39
ItemLoaderPrivate *priv;
42
typedef struct ItemLoaderClass {
46
GType item_loader_get_type();
48
#define ITEM_LOADER_TYPE (item_loader_get_type ())
49
#define ITEM_LOADER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ITEM_LOADER_TYPE, ItemLoader))
50
#define ITEM_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ITEM_LOADER_TYPE, ItemLoaderClass))
51
#define IS_ITEM_LOADER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), ITEM_LOADER_TYPE))
52
#define IS_ITEM_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ITEM_LOADER_TYPE))
53
#define ITEM_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ITEM_LOADER_TYPE, ItemLoaderClass))
56
* Definition of item loader fetch callback to be
57
* implemented by specific item loaders. This callback
58
* is called multiple times to fetch item batches. The
59
* batch size is determined by the specific implementation.
61
* @param user_data ItemLoader type specific data
62
* @param items Result items (to be free'd by caller)
64
* @returns FALSE if loading has finished
66
typedef gboolean (*fetchCallbackPtr)(gpointer user_data, GSList **items);
69
* Set up a new item loader with a specific fetch function.
71
* @param fetchCallback the item fetching function
72
* @param node the node we are loading items for
73
* @param user_data ItemLoader type specific data
75
* @returns the new ItemLoader instance
77
ItemLoader * item_loader_new (fetchCallbackPtr fetchCallback, nodePtr node, gpointer user_data);
80
* Returns the node an item loader is loading items for.
82
* @param il the item loader
86
nodePtr item_loader_get_node (ItemLoader *il);
89
* Starts the item loader to load items with idle priority.
91
* @param il the item loader
93
void item_loader_start (ItemLoader *il);