Esempio n. 1
0
/**
 * Execute query.
 * @param query the query to execute.
 * @param playlist set to TRUE to search only songs in the playlist.
 *
 * @returns the search result in a #MpdData list.
 */
MpdData *advanced_search(const gchar * query, int in_playlist)
{
    MpdData *data_return = NULL;
    gchar **text = g_regex_split(search_regex, query, 0);
    int i = 0;
    gboolean found = FALSE;
    for (i = 0; text && text[i]; i++)
    {
        int type;
        /* Or sign, if hit, a new query is started */
        if (strcmp(text[i], "||") == 0)
        {
            MpdData *data;
            /* Commit the currently in active search and append the results */
            if (in_playlist)
                data = mpd_playlist_search_commit(connection);
            else
                data = mpd_database_search_commit(connection);
            data_return = mpd_data_concatenate(data_return, data);
            found = FALSE;
            continue;
        }
        /* empty element */
        if (text[i][0] == '\0')
            continue;

        /* Parse the tag name. */
        type = mpd_misc_get_tag_by_name(g_strstrip(text[i]));
        if (type != MPD_TAG_NOT_FOUND && text[i + 1])
        {
            gchar **split = tokenize_string(text[i + 1]);
            int j;
            for (j = 0; split && split[j]; j++)
            {
                if (!found)
                {
                    if (in_playlist)
                        mpd_playlist_search_start(connection, FALSE);
                    else
                        mpd_database_search_start(connection, FALSE);
                    found = TRUE;
                }
                if (in_playlist)
                    mpd_playlist_search_add_constraint(connection, type, g_strstrip(split[j]));
                else
                    mpd_database_search_add_constraint(connection, type, g_strstrip(split[j]));
            }
            if (split)
                g_strfreev(split);
            i++;
        } else
        {
            gchar **split = tokenize_string(text[i]);
            int j;
            for (j = 0; split && split[j]; j++)
            {
                if (!found)
                {
                    if (in_playlist)
                        mpd_playlist_search_start(connection, FALSE);
                    else
                        mpd_database_search_start(connection, FALSE);
                    found = TRUE;
                }
                if (in_playlist)
                    mpd_playlist_search_add_constraint(connection, MPD_TAG_ITEM_ANY, split[j]);
                else
                    mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ANY, split[j]);
            }
            if (split)
                g_strfreev(split);
        }
    }
    if (text)
        g_strfreev(text);
    /* Execute the active search and append the results */
    if (found)
    {
        MpdData *data;
        if (in_playlist)
            data = mpd_playlist_search_commit(connection);
        else
            data = mpd_database_search_commit(connection);
        data_return = mpd_data_concatenate(data_return, data);
    }
    /* remove possible duplicates (because of concatenating queries) */
    return misc_mpddata_remove_duplicate_songs(data_return);
}
Esempio n. 2
0
static gboolean gmpc_meta_data_widgets_similar_songs_update_sim_song (GmpcMetaDataWidgetsSimilarSongs* self) {
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->current == NULL) {
		GList* _tmp0_ = NULL;
		GtkProgressBar* _tmp1_ = NULL;
		_tmp0_ = meta_data_get_text_list (self->priv->copy);
		self->priv->current = _tmp0_;
		_tmp1_ = (GtkProgressBar*) gtk_progress_bar_new ();
		_g_object_unref0 (self->priv->pchild);
		self->priv->pchild = (GtkWidget*) g_object_ref_sink (_tmp1_);
		gtk_container_add ((GtkContainer*) self, self->priv->pchild);
		gtk_widget_show_all ((GtkWidget*) self);
	}
	gtk_progress_bar_pulse (GTK_PROGRESS_BAR (self->priv->pchild));
	if (self->priv->current != NULL) {
		gchar* _tmp2_;
		gchar* entry;
		_tmp2_ = g_strdup ((const gchar*) self->priv->current->data);
		entry = _tmp2_;
		if (entry != NULL) {
			gchar** _tmp3_;
			gchar** _tmp4_ = NULL;
			gchar** split;
			gint split_length1;
			gint _split_size_;
			_tmp4_ = _tmp3_ = g_strsplit (entry, "::", 2);
			split = _tmp4_;
			split_length1 = _vala_array_length (_tmp3_);
			_split_size_ = _vala_array_length (_tmp3_);
			if (split_length1 == 2) {
				gchar** _tmp5_;
				gchar** _tmp6_ = NULL;
				gchar** art_split;
				gint art_split_length1;
				gint _art_split_size_;
				MpdData* _tmp8_ = NULL;
				MpdData* data;
				mpd_database_search_start (connection, FALSE);
				_tmp6_ = _tmp5_ = g_strsplit (split[0], " ", 0);
				art_split = _tmp6_;
				art_split_length1 = _vala_array_length (_tmp5_);
				_art_split_size_ = _vala_array_length (_tmp5_);
				{
					gchar** artist_collection;
					int artist_collection_length1;
					int artist_it;
					artist_collection = art_split;
					artist_collection_length1 = art_split_length1;
					for (artist_it = 0; artist_it < art_split_length1; artist_it = artist_it + 1) {
						gchar* _tmp7_;
						gchar* artist;
						_tmp7_ = g_strdup (artist_collection[artist_it]);
						artist = _tmp7_;
						{
							mpd_database_search_add_constraint (connection, MPD_TAG_ITEM_ARTIST, artist);
							_g_free0 (artist);
						}
					}
				}
				mpd_database_search_add_constraint (connection, MPD_TAG_ITEM_TITLE, split[1]);
				_tmp8_ = mpd_database_search_commit (connection);
				data = _tmp8_;
				if (data != NULL) {
					MpdData* _tmp9_;
					_tmp9_ = data;
					data = NULL;
					self->priv->item = mpd_data_concatenate (self->priv->item, _tmp9_);
				}
				_mpd_data_free0 (data);
				art_split = (_vala_array_free (art_split, art_split_length1, (GDestroyNotify) g_free), NULL);
			}
			split = (_vala_array_free (split, split_length1, (GDestroyNotify) g_free), NULL);
		}
		self->priv->current = self->priv->current->next;
		if (self->priv->current != NULL) {
			result = TRUE;
			_g_free0 (entry);
			return result;
		}
		_g_free0 (entry);
	}
	gtk_object_destroy ((GtkObject*) self->priv->pchild);
	if (self->priv->item != NULL) {
		GmpcMpdDataModel* _tmp10_ = NULL;
		GmpcMpdDataModel* model;
		MpdData* _tmp11_;
		GmpcMpdDataTreeview* _tmp12_ = NULL;
		GmpcMpdDataTreeview* tree;
		GtkWidget* _tmp13_;
		_tmp10_ = gmpc_mpddata_model_new ();
		model = _tmp10_;
		self->priv->item = misc_mpddata_remove_duplicate_songs (self->priv->item);
		_tmp11_ = self->priv->item;
		self->priv->item = NULL;
		gmpc_mpddata_model_set_mpd_data (model, _tmp11_);
		_tmp12_ = gmpc_mpddata_treeview_new ("similar-song", TRUE, (GtkTreeModel*) model);
		tree = g_object_ref_sink (_tmp12_);
		gmpc_mpddata_treeview_enable_click_fix (tree);
		g_signal_connect_object ((GtkWidget*) tree, "button-release-event", (GCallback) _gmpc_meta_data_widgets_similar_songs_tree_right_menu_gtk_widget_button_release_event, self, 0);
		g_signal_connect_object ((GtkTreeView*) tree, "row-activated", (GCallback) _gmpc_meta_data_widgets_similar_songs_tree_row_activated_gtk_tree_view_row_activated, self, 0);
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) tree);
		_tmp13_ = _g_object_ref0 ((GtkWidget*) tree);
		_g_object_unref0 (self->priv->pchild);
		self->priv->pchild = _tmp13_;
		_g_object_unref0 (tree);
		_g_object_unref0 (model);
	} else {
		const gchar* _tmp14_ = NULL;
		GtkLabel* _tmp15_ = NULL;
		GtkLabel* label;
		GtkWidget* _tmp16_;
		_tmp14_ = _ ("Unavailable");
		_tmp15_ = (GtkLabel*) gtk_label_new (_tmp14_);
		label = g_object_ref_sink (_tmp15_);
		gtk_misc_set_alignment ((GtkMisc*) label, 0.0f, 0.0f);
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) label);
		_tmp16_ = _g_object_ref0 ((GtkWidget*) label);
		_g_object_unref0 (self->priv->pchild);
		self->priv->pchild = _tmp16_;
		_g_object_unref0 (label);
	}
	_meta_data_free0 (self->priv->copy);
	self->priv->copy = NULL;
	self->priv->idle_add = (guint) 0;
	gtk_widget_show_all ((GtkWidget*) self);
	result = FALSE;
	return result;
}