/** * rb_query_creator_get_query: * @creator: #RBQueryCreator instance * * Constructs a database query that represents the criteria in the query creator. * * Return value: (transfer full): database query array */ GPtrArray * rb_query_creator_get_query (RBQueryCreator *creator) { RBQueryCreatorPrivate *priv; GPtrArray *query; GPtrArray *sub_query; GList *rows, *row; gboolean disjunction; g_return_val_if_fail (RB_IS_QUERY_CREATOR (creator), NULL); priv = QUERY_CREATOR_GET_PRIVATE (creator); disjunction = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->disjunction_check)); sub_query = g_ptr_array_new (); rows = priv->rows; for (row = rows; row; row = row->next) { GtkComboBox *propmenu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (row->data), 0)); GtkComboBox *criteria_menu = GTK_COMBO_BOX (get_box_widget_at_pos (GTK_BOX (row->data), 1)); guint prop_position = gtk_combo_box_get_active (propmenu); const RBQueryCreatorPropertyOption *prop_option = &property_options[prop_position]; const RBQueryCreatorCriteriaOption *criteria_options = prop_option->property_type->criteria_options; const RBQueryCreatorCriteriaOption *criteria_option = &criteria_options[gtk_combo_box_get_active (criteria_menu)]; g_assert (prop_option->property_type->criteria_get_widget_data != NULL); { RhythmDBQueryData *data = g_new0 (RhythmDBQueryData, 1); GValue *val = g_new0 (GValue, 1); data->type = criteria_option->val; data->propid = criteria_option->strict ? prop_option->strict_val : prop_option->fuzzy_val; prop_option->property_type->criteria_get_widget_data (get_box_widget_at_pos (GTK_BOX (row->data), 2), val); data->val = val; g_ptr_array_add (sub_query, data); } if (disjunction && row->next) rhythmdb_query_append (priv->db, sub_query, RHYTHMDB_QUERY_DISJUNCTION, RHYTHMDB_QUERY_END); } query = rhythmdb_query_parse (priv->db, /* type=songs */ RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG, /* the constructed query */ RHYTHMDB_QUERY_SUBQUERY, sub_query, RHYTHMDB_QUERY_END); return query; }
static GPtrArray * construct_query_from_selection (RBStaticPlaylistSource *source) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source); RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (psource)); GPtrArray *query = NULL; query = g_ptr_array_new(); if (priv->search_query != NULL) { rhythmdb_query_append (db, query, RHYTHMDB_QUERY_SUBQUERY, priv->search_query, RHYTHMDB_QUERY_END); } return query; }
static void rb_iradio_source_do_query (RBIRadioSource *source) { RhythmDBQueryModel *genre_query_model = NULL; RhythmDBQueryModel *station_query_model = NULL; RhythmDBPropertyModel *genre_model; GPtrArray *query; RhythmDBEntryType *entry_type; /* don't update the selection while we're rebuilding the query */ source->priv->setting_new_query = TRUE; /* construct and run the query for the search box. * this is used as the model for the genre view. */ g_object_get (source, "entry-type", &entry_type, NULL); query = rhythmdb_query_parse (source->priv->db, RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, entry_type, RHYTHMDB_QUERY_END); g_object_unref (entry_type); if (source->priv->search_query != NULL) { rhythmdb_query_append (source->priv->db, query, RHYTHMDB_QUERY_SUBQUERY, source->priv->search_query, RHYTHMDB_QUERY_END); } genre_model = rb_property_view_get_model (source->priv->genres); genre_query_model = rhythmdb_query_model_new_empty (source->priv->db); g_object_set (genre_model, "query-model", genre_query_model, NULL); rhythmdb_do_full_query_parsed (source->priv->db, RHYTHMDB_QUERY_RESULTS (genre_query_model), query); rhythmdb_query_free (query); query = NULL; /* check the selected genre is still available, and if not, select 'all' */ if (source->priv->selected_genre != NULL) { GList *sel = NULL; if (!rhythmdb_property_model_iter_from_string (genre_model, source->priv->selected_genre, NULL)) { g_free (source->priv->selected_genre); source->priv->selected_genre = NULL; } sel = g_list_prepend (sel, source->priv->selected_genre); rb_property_view_set_selection (source->priv->genres, sel); g_list_free (sel); } /* if a genre is selected, construct a new query for it, and create * a new model based on the search box query model. otherwise, just * reuse the search box query model. */ if (source->priv->selected_genre != NULL) { rb_debug ("matching on genre \"%s\"", source->priv->selected_genre); station_query_model = rhythmdb_query_model_new_empty (source->priv->db); query = rhythmdb_query_parse (source->priv->db, RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_GENRE, source->priv->selected_genre, RHYTHMDB_QUERY_END); g_object_set (station_query_model, "query", query, "base-model", genre_query_model, NULL); rhythmdb_query_free (query); query = NULL; } else { station_query_model = g_object_ref (genre_query_model); } rb_entry_view_set_model (source->priv->stations, station_query_model); g_object_set (source, "query-model", station_query_model, NULL); g_object_unref (genre_query_model); g_object_unref (station_query_model); source->priv->setting_new_query = FALSE; }