hythmbox-2.98/rhythmdb/rhythmdb-query-results.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2006  Jonathan Matthew  <jonathan@kaolin.wh9.net>
  4  *
  5  *  This program is free software; you can redistribute it and/or modify
  6  *  it under the terms of the GNU General Public License as published by
  7  *  the Free Software Foundation; either version 2 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 #include <config.h>
 30 
 31 #include "rhythmdb-query-results.h"
 32 
 33 /**
 34  * SECTION:rhythmdb-query-results
 35  * @short_description: interface for receiving query results from RhythmDB
 36  *
 37  * This is the interface that #RhythmDB uses to report results of database
 38  * queries.  When running a query, it first calls rhythmdb_query_results_set_query,
 39  * then passes entries matching the query to rhythmdb_query_results_add_results
 40  * in batches, and finally calls rhythmdb_query_results_query_complete.
 41  * There are no guarantees as to which threads the calls are made from.
 42  */
 43 
 44 GType
 45 rhythmdb_query_results_get_type (void)
 46 {
 47 	static GType our_type = 0;
 48 
 49 	if (!our_type) {
 50 		static const GTypeInfo our_info = {
 51 			sizeof (RhythmDBQueryResultsIface),
 52 			NULL,	/* base_init */
 53 			NULL,	/* base_finalize */
 54 			NULL,
 55 			NULL,	/* class_finalize */
 56 			NULL,	/* class_data */
 57 			0,
 58 			0,
 59 			NULL
 60 		};
 61 
 62 		our_type = g_type_register_static (G_TYPE_INTERFACE, "RhythmDBQueryResults", &our_info, 0);
 63 	}
 64 
 65 	return our_type;
 66 }
 67 
 68 /**
 69  * rhythmdb_query_results_set_query:
 70  * @results: the #RhythmDBQueryResults implementation
 71  * @query: the new query
 72  *
 73  * When a new query is run, this method is invoked to give the
 74  * object implementing this interface a chance to take a copy of the
 75  * query criteria, so that it can evaluate the query for newly added
 76  * or changed entries once the query is complete.
 77  */
 78 void
 79 rhythmdb_query_results_set_query (RhythmDBQueryResults *results,
 80 				  GPtrArray *query)
 81 {
 82 	RhythmDBQueryResultsIface *iface = RHYTHMDB_QUERY_RESULTS_GET_IFACE (results);
 83 	if (iface->set_query)
 84 		iface->set_query (results, query);
 85 }
 86 
 87 /**
 88  * rhythmdb_query_results_add_results:
 89  * @results: the #RhythmDBQueryResults implementation
 90  * @entries: #GPtrArray containing #RhythmDBEntry results
 91  *
 92  * Provides a new set of query results.  References must be taken on the
 93  * entries.
 94  */
 95 void
 96 rhythmdb_query_results_add_results (RhythmDBQueryResults *results,
 97 				    GPtrArray *entries)
 98 {
 99 	RhythmDBQueryResultsIface *iface = RHYTHMDB_QUERY_RESULTS_GET_IFACE (results);
100 	if (iface->add_results)
101 		iface->add_results (results, entries);
102 }
103 
104 /**
105  * rhythmdb_query_results_query_complete:
106  * @results: the #RhythmDBQueryResults
107  *
108  * Called when the query is complete and all entries that match the query
109  * have been supplied to rhythmdb_query_results_add_results.  If the object
110  * implementing this interface needs to identify newly added or changed entries
111  * that match the query, it needs to use the entry-added, entry-deleted and
112  * entry-changed signals from #RhythmDB.
113  */
114 void
115 rhythmdb_query_results_query_complete (RhythmDBQueryResults *results)
116 {
117 	RhythmDBQueryResultsIface *iface = RHYTHMDB_QUERY_RESULTS_GET_IFACE (results);
118 	if (iface->query_complete)
119 		iface->query_complete (results);
120 }