1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include <glib-object.h>
24 #include "mm-hit-collection.h"
26 #define MM_HIT_COLLECTION_GET_PRIVATE(o) \
27 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_HIT_COLLECTION, MMHitCollectionPrivate))
29 G_DEFINE_TYPE (MMHitCollection
, mm_hit_collection
, G_TYPE_OBJECT
);
31 struct _MMHitCollectionPrivate
{
37 unref_hit (gpointer hit
,
44 mm_hit_collection_finalize (GObject
*o
)
46 MMHitCollection
*c
= MM_HIT_COLLECTION (o
);
48 /* unref all the hits first */
49 g_ptr_array_foreach (c
->details
->hits
, unref_hit
, NULL
);
50 g_ptr_array_free (c
->details
->hits
, FALSE
);
52 G_OBJECT_CLASS (mm_hit_collection_parent_class
)->finalize (o
);
56 mm_hit_collection_class_init (MMHitCollectionClass
*klass
)
58 G_OBJECT_CLASS (klass
)->finalize
= mm_hit_collection_finalize
;
60 g_type_class_add_private (klass
, sizeof (MMHitCollectionPrivate
));
64 mm_hit_collection_init (MMHitCollection
*c
)
66 MMHitCollectionPrivate
*details
= c
->details
= MM_HIT_COLLECTION_GET_PRIVATE (c
);
68 details
->hits
= g_ptr_array_new ();
69 details
->current_offset
= 0;
75 * mm_hit_collection_new:
77 * Builds an empty #MMHitCollection.
79 * Return value: an empty #MMHitCollection.
83 mm_hit_collection_new (void)
87 c
= g_object_new (MM_TYPE_HIT_COLLECTION
, NULL
);
93 * mm_hit_collection_add_hit:
94 * @collection: a #MMHitCollection.
97 * Adds @hit to @collection. The collection will own a reference to the
102 mm_hit_collection_add_hit (MMHitCollection
*collection
,
105 MMHitCollectionPrivate
*details
= collection
->details
;
107 g_ptr_array_add (details
->hits
, g_object_ref (hit
));
111 * mm_hit_collection_get_next_hit:
112 * @collection: a #MMHitCollection.
114 * Gets a reference to the next hit inside @collection, or %NULL if there are no hits
117 * Return value: a #MMHit or %NULL. Use #g_object_unref when done with the hit.
121 mm_hit_collection_get_next_hit (MMHitCollection
*collection
)
123 MMHitCollectionPrivate
*details
= collection
->details
;
126 if (details
->hits
->len
== 0 ||
127 details
->current_offset
>= details
->hits
->len
) {
128 /* no hits in this collection or we already got all results */
131 hit
= g_ptr_array_index (details
->hits
, details
->current_offset
);
132 details
->current_offset
++;
135 return g_object_ref (hit
);