hythmbox-2.98/sources/rb-source-search-basic.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2008  Jonathan Matthew  <jonathan@d14n.org>
  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 /**
 30  * SECTION:rb-source-search-basic
 31  * @short_description: Simple implementation of #RBSourceSearch
 32  *
 33  * This implementation of #RBSourceSearch constructs queries that
 34  * search on a single #RhythmDBEntry property.  It's useful for
 35  * providing basic searches.
 36  */
 37 
 38 #include "config.h"
 39 
 40 #include "rb-source-search-basic.h"
 41 
 42 static void	rb_source_search_basic_class_init (RBSourceSearchBasicClass *klass);
 43 static void	rb_source_search_basic_init (RBSourceSearchBasic *search);
 44 
 45 G_DEFINE_TYPE (RBSourceSearchBasic, rb_source_search_basic, RB_TYPE_SOURCE_SEARCH)
 46 
 47 enum
 48 {
 49 	PROP_0,
 50 	PROP_SEARCH_PROP,
 51 };
 52 
 53 static RhythmDBQuery *
 54 impl_create_query (RBSourceSearch *bsearch, RhythmDB *db, const char *search_text)
 55 {
 56 	RBSourceSearchBasic *search = RB_SOURCE_SEARCH_BASIC (bsearch);
 57 
 58 	return _rb_source_search_create_simple_query (bsearch, db, search_text, search->search_prop);
 59 }
 60 
 61 static void
 62 impl_set_property (GObject *object,
 63 		   guint prop_id,
 64 		   const GValue *value,
 65 		   GParamSpec *pspec)
 66 {
 67 	RBSourceSearchBasic *search = RB_SOURCE_SEARCH_BASIC (object);
 68 
 69 	switch (prop_id) {
 70 	case PROP_SEARCH_PROP:
 71 		search->search_prop = g_value_get_int (value);
 72 		break;
 73 	default:
 74 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 75 		break;
 76 	}
 77 }
 78 
 79 static void
 80 impl_get_property (GObject *object,
 81 		   guint prop_id,
 82 		   GValue *value,
 83 		   GParamSpec *pspec)
 84 {
 85 	RBSourceSearchBasic *search = RB_SOURCE_SEARCH_BASIC (object);
 86 
 87 	switch (prop_id) {
 88 	case PROP_SEARCH_PROP:
 89 		g_value_set_int (value, search->search_prop);
 90 		break;
 91 	default:
 92 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 93 		break;
 94 	}
 95 }
 96 
 97 static void
 98 rb_source_search_basic_class_init (RBSourceSearchBasicClass *klass)
 99 {
100 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
101 	RBSourceSearchClass *search_class = RB_SOURCE_SEARCH_CLASS (klass);
102 
103 	object_class->set_property = impl_set_property;
104 	object_class->get_property = impl_get_property;
105 
106 	search_class->create_query = impl_create_query;
107 
108 	g_object_class_install_property (object_class,
109 					 PROP_SEARCH_PROP,
110 					 g_param_spec_int ("prop",
111 							   "propid",
112 							   "Property id",
113 							   0, RHYTHMDB_NUM_PROPERTIES,
114 							   RHYTHMDB_PROP_TYPE,
115 							   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
116 }
117 
118 static void
119 rb_source_search_basic_init (RBSourceSearchBasic *search)
120 {
121 	/* nothing */
122 }
123 
124 
125 /**
126  * rb_source_search_basic_new:
127  * @prop:	the #RhythmDBPropType to search
128  *
129  * Creates a new #RBSourceSearchBasic instance.
130  * This performs simple string matching on a specified
131  * property.
132  *
133  * Return value: newly created #RBSourceSearchBasic
134  */
135 RBSourceSearch *
136 rb_source_search_basic_new (RhythmDBPropType prop)
137 {
138 	return g_object_new (RB_TYPE_SOURCE_SEARCH_BASIC, "prop", prop, NULL);
139 }
140 
141 /**
142  * rb_source_search_basic_create_for_actions:
143  * @action_group:	the GtkActionGroup containing the actions
144  * @actions:		the GtkRadioActionEntries for the actions
145  * @n_actions:		the number of actions
146  *
147  * Creates #RBSourceSearchBasic instances for a set of
148  * search actions and associates them with the actions.
149  * The property to match on is taken from the action
150  * value in the GtkRadioActionEntry structure.
151  */
152 void
153 rb_source_search_basic_create_for_actions (GtkActionGroup *action_group,
154 					   GtkRadioActionEntry *actions,
155 					   int n_actions)
156 {
157 	int i;
158 	for (i = 0; i < n_actions; i++) {
159 		GtkAction *action;
160 		RBSourceSearch *search;
161 
162 		if (actions[i].value != RHYTHMDB_NUM_PROPERTIES) {
163 			action = gtk_action_group_get_action (action_group, actions[i].name);
164 			g_assert (action != NULL);
165 
166 			search = rb_source_search_basic_new (actions[i].value);
167 			rb_source_search_action_attach (search, G_OBJECT (action));
168 			g_object_unref (search);
169 		}
170 	}
171 }