/* gmpc-metadata-similarsongs.c generated by valac 0.12.0, the Vala compiler
 * generated from gmpc-metadata-similarsongs.vala, do not modify */

/* Gnome Music Player Client (GMPC)
 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
 * Project homepage: http://gmpclient.org/
 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gtktransition.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>
#include "gmpc-extras.h"
#include <libmpd/libmpdclient.h>
#include <libmpd/libmpd.h>
#include <misc.h>
#include <metadata.h>
#include <plugin.h>
#include <mpdinteraction.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
#include <gmpc-mpddata-treeview.h>
#include <gmpc-mpddata-model.h>
#include <gmpc-meta-watcher.h>
#include <main.h>

#define _mpd_freeSong0(var) ((var == NULL) ? NULL : (var = (mpd_freeSong (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _meta_data_free0(var) ((var == NULL) ? NULL : (var = (meta_data_free (var), NULL)))
#define _mpd_data_free0(var) ((var == NULL) ? NULL : (var = (mpd_data_free (var), NULL)))
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))
#define __g_list_free__gtk_tree_path_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__gtk_tree_path_free0_ (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GmpcMetaDataWidgetsSimilarSongsPrivate {
	mpd_Song* song;
	GtkWidget* pchild;
	guint idle_add;
	MetaData* copy;
	MpdData* item;
	GList* current;
};


static gpointer gmpc_meta_data_widgets_similar_songs_parent_class = NULL;

#define use_transition_mdss TRUE
#define some_unique_name_mdss VERSION
#define GMPC_META_DATA_WIDGETS_SIMILAR_SONGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMPC_META_DATA_WIDGETS_TYPE_SIMILAR_SONGS, GmpcMetaDataWidgetsSimilarSongsPrivate))
enum  {
	GMPC_META_DATA_WIDGETS_SIMILAR_SONGS_DUMMY_PROPERTY
};
static void gmpc_meta_data_widgets_similar_songs_add_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item);
static void _gtk_tree_path_free0_ (gpointer var);
static void _g_list_free__gtk_tree_path_free0_ (GList* self);
static void gmpc_meta_data_widgets_similar_songs_play_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item);
static void gmpc_meta_data_widgets_similar_songs_replace_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item);
static void gmpc_meta_data_widgets_similar_songs_tree_row_activated (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* tree, GtkTreePath* path, GtkTreeViewColumn* column);
static gboolean gmpc_meta_data_widgets_similar_songs_tree_right_menu (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* tree, GdkEventButton* event);
static void _gmpc_meta_data_widgets_similar_songs_play_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static void _gmpc_meta_data_widgets_similar_songs_add_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static void _gmpc_meta_data_widgets_similar_songs_replace_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static gboolean gmpc_meta_data_widgets_similar_songs_update_sim_song (GmpcMetaDataWidgetsSimilarSongs* self);
static gboolean _gmpc_meta_data_widgets_similar_songs_tree_right_menu_gtk_widget_button_release_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
static void _gmpc_meta_data_widgets_similar_songs_tree_row_activated_gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self);
static void gmpc_meta_data_widgets_similar_songs_metadata_changed (GmpcMetaDataWidgetsSimilarSongs* self, GmpcMetaWatcher* gmw2, const mpd_Song* song, MetaDataType type, MetaDataResult _result_, const MetaData* met);
static gboolean _gmpc_meta_data_widgets_similar_songs_update_sim_song_gsource_func (gpointer self);
static void _gmpc_meta_data_widgets_similar_songs_metadata_changed_gmpc_meta_watcher_data_changed (GmpcMetaWatcher* _sender, const mpd_Song* song, MetaDataType type, MetaDataResult _result_, const MetaData* met, gpointer self);
static void gmpc_meta_data_widgets_similar_songs_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


static gpointer _mpd_songDup0 (gpointer self) {
	return self ? mpd_songDup (self) : NULL;
}


GmpcMetaDataWidgetsSimilarSongs* gmpc_meta_data_widgets_similar_songs_construct (GType object_type, const mpd_Song* song) {
	GmpcMetaDataWidgetsSimilarSongs * self = NULL;
	mpd_Song* _tmp0_;
	g_return_val_if_fail (song != NULL, NULL);
	self = (GmpcMetaDataWidgetsSimilarSongs*) g_object_new (object_type, NULL);
	_tmp0_ = _mpd_songDup0 (song);
	_mpd_freeSong0 (self->priv->song);
	self->priv->song = _tmp0_;
	gtk_alignment_set ((GtkAlignment*) self, 0.0f, 0.0f, 1.0f, 0.0f);
	return self;
}


GmpcMetaDataWidgetsSimilarSongs* gmpc_meta_data_widgets_similar_songs_new (const mpd_Song* song) {
	return gmpc_meta_data_widgets_similar_songs_construct (GMPC_META_DATA_WIDGETS_TYPE_SIMILAR_SONGS, song);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static gpointer _gtk_tree_path_copy0 (gpointer self) {
	return self ? gtk_tree_path_copy (self) : NULL;
}


static void _gtk_tree_path_free0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL));
}


static void _g_list_free__gtk_tree_path_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _gtk_tree_path_free0_, NULL);
	g_list_free (self);
}


static void gmpc_meta_data_widgets_similar_songs_add_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item) {
	GtkTreeView* _tmp0_;
	GtkTreeView* tree;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_;
	GtkTreeSelection* sel;
	GtkTreeModel* model;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_;
	GList* list;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = _g_object_ref0 (GTK_TREE_VIEW (self->priv->pchild));
	tree = _tmp0_;
	_tmp1_ = gtk_tree_view_get_selection (tree);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	sel = _tmp2_;
	model = NULL;
	_tmp4_ = gtk_tree_selection_get_selected_rows (sel, &_tmp3_);
	_g_object_unref0 (model);
	_tmp5_ = _g_object_ref0 (_tmp3_);
	model = _tmp5_;
	list = _tmp4_;
	{
		GList* path_collection;
		GList* path_it;
		path_collection = list;
		for (path_it = path_collection; path_it != NULL; path_it = path_it->next) {
			GtkTreePath* _tmp6_;
			GtkTreePath* path;
			_tmp6_ = _gtk_tree_path_copy0 ((GtkTreePath*) path_it->data);
			path = _tmp6_;
			{
				GtkTreeIter _tmp7_ = {0};
				gboolean _tmp8_;
				_tmp8_ = gtk_tree_model_get_iter (model, &_tmp7_, path);
				iter = _tmp7_;
				if (_tmp8_) {
					const mpd_Song* song;
					song = NULL;
					gtk_tree_model_get (model, &iter, 0, &song, -1, -1);
					if (song != NULL) {
						mpd_playlist_queue_add (connection, song->file);
					}
				}
				_gtk_tree_path_free0 (path);
			}
		}
	}
	mpd_playlist_queue_commit (connection);
	__g_list_free__gtk_tree_path_free0_0 (list);
	_g_object_unref0 (model);
	_g_object_unref0 (sel);
	_g_object_unref0 (tree);
}


static void gmpc_meta_data_widgets_similar_songs_play_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item) {
	GtkTreeView* _tmp0_;
	GtkTreeView* tree;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_;
	GtkTreeSelection* sel;
	GtkTreeModel* model;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_;
	GList* list;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = _g_object_ref0 (GTK_TREE_VIEW (self->priv->pchild));
	tree = _tmp0_;
	_tmp1_ = gtk_tree_view_get_selection (tree);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	sel = _tmp2_;
	model = NULL;
	_tmp4_ = gtk_tree_selection_get_selected_rows (sel, &_tmp3_);
	_g_object_unref0 (model);
	_tmp5_ = _g_object_ref0 (_tmp3_);
	model = _tmp5_;
	list = _tmp4_;
	if (list != NULL) {
		GtkTreePath* _tmp6_;
		GtkTreePath* path;
		GtkTreeIter _tmp7_ = {0};
		gboolean _tmp8_;
		_tmp6_ = _gtk_tree_path_copy0 ((GtkTreePath*) list->data);
		path = _tmp6_;
		_tmp8_ = gtk_tree_model_get_iter (model, &_tmp7_, path);
		iter = _tmp7_;
		if (_tmp8_) {
			const mpd_Song* song;
			song = NULL;
			gtk_tree_model_get (model, &iter, 0, &song, -1, -1);
			if (song != NULL) {
				play_path (song->file);
			}
		}
		_gtk_tree_path_free0 (path);
	}
	__g_list_free__gtk_tree_path_free0_0 (list);
	_g_object_unref0 (model);
	_g_object_unref0 (sel);
	_g_object_unref0 (tree);
}


static void gmpc_meta_data_widgets_similar_songs_replace_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item) {
	gboolean found;
	GtkTreeView* _tmp0_;
	GtkTreeView* tree;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_;
	GtkTreeSelection* sel;
	GtkTreeModel* model;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_;
	GList* list;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	found = FALSE;
	_tmp0_ = _g_object_ref0 (GTK_TREE_VIEW (self->priv->pchild));
	tree = _tmp0_;
	_tmp1_ = gtk_tree_view_get_selection (tree);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	sel = _tmp2_;
	model = NULL;
	_tmp4_ = gtk_tree_selection_get_selected_rows (sel, &_tmp3_);
	_g_object_unref0 (model);
	_tmp5_ = _g_object_ref0 (_tmp3_);
	model = _tmp5_;
	list = _tmp4_;
	{
		GList* path_collection;
		GList* path_it;
		path_collection = list;
		for (path_it = path_collection; path_it != NULL; path_it = path_it->next) {
			GtkTreePath* _tmp6_;
			GtkTreePath* path;
			_tmp6_ = _gtk_tree_path_copy0 ((GtkTreePath*) path_it->data);
			path = _tmp6_;
			{
				GtkTreeIter _tmp7_ = {0};
				gboolean _tmp8_;
				_tmp8_ = gtk_tree_model_get_iter (model, &_tmp7_, path);
				iter = _tmp7_;
				if (_tmp8_) {
					const mpd_Song* song;
					song = NULL;
					gtk_tree_model_get (model, &iter, 0, &song, -1, -1);
					if (song != NULL) {
						mpd_playlist_queue_add (connection, song->file);
						found = TRUE;
					}
				}
				_gtk_tree_path_free0 (path);
			}
		}
	}
	if (found) {
		mpd_playlist_clear (connection);
		mpd_playlist_queue_commit (connection);
		mpd_player_play (connection);
	}
	gmpc_meta_data_widgets_similar_songs_play_clicked (self, item);
	__g_list_free__gtk_tree_path_free0_0 (list);
	_g_object_unref0 (model);
	_g_object_unref0 (sel);
	_g_object_unref0 (tree);
}


static void gmpc_meta_data_widgets_similar_songs_tree_row_activated (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* tree, GtkTreePath* path, GtkTreeViewColumn* column) {
	GtkWidget* _tmp0_;
	GtkTreeModel* _tmp1_ = NULL;
	GtkTreeModel* _tmp2_;
	GtkTreeModel* model;
	GtkTreeIter iter = {0};
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (tree != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (column != NULL);
	_tmp0_ = tree;
	_tmp1_ = gtk_tree_view_get_model (GTK_IS_TREE_VIEW (_tmp0_) ? ((GtkTreeView*) _tmp0_) : NULL);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	model = _tmp2_;
	_tmp4_ = gtk_tree_model_get_iter (model, &_tmp3_, path);
	iter = _tmp3_;
	if (_tmp4_) {
		const mpd_Song* song;
		song = NULL;
		gtk_tree_model_get (model, &iter, 0, &song, -1, -1);
		if (song != NULL) {
			play_path (song->file);
		}
	}
	_g_object_unref0 (model);
}


static void _gmpc_meta_data_widgets_similar_songs_play_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	gmpc_meta_data_widgets_similar_songs_play_clicked (self, _sender);
}


static void _gmpc_meta_data_widgets_similar_songs_add_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	gmpc_meta_data_widgets_similar_songs_add_clicked (self, _sender);
}


static void _gmpc_meta_data_widgets_similar_songs_replace_clicked_gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	gmpc_meta_data_widgets_similar_songs_replace_clicked (self, _sender);
}


static gboolean gmpc_meta_data_widgets_similar_songs_tree_right_menu (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* tree, GdkEventButton* event) {
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (tree != NULL, FALSE);
	if ((*event).button == 3) {
		GtkMenu* _tmp0_ = NULL;
		GtkMenu* menu;
		GtkImageMenuItem* _tmp1_ = NULL;
		GtkImageMenuItem* item;
		GtkImageMenuItem* _tmp2_ = NULL;
		const gchar* _tmp3_ = NULL;
		GtkImageMenuItem* _tmp4_ = NULL;
		GtkImage* _tmp5_ = NULL;
		GtkImage* _tmp6_;
		GtkWidget* _tmp7_;
		_tmp0_ = (GtkMenu*) gtk_menu_new ();
		menu = g_object_ref_sink (_tmp0_);
		_tmp1_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-media-play", NULL);
		item = g_object_ref_sink (_tmp1_);
		g_signal_connect_object ((GtkMenuItem*) item, "activate", (GCallback) _gmpc_meta_data_widgets_similar_songs_play_clicked_gtk_menu_item_activate, self, 0);
		gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) ((GtkMenuItem*) item));
		_tmp2_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock ("gtk-add", NULL);
		_g_object_unref0 (item);
		item = g_object_ref_sink (_tmp2_);
		g_signal_connect_object ((GtkMenuItem*) item, "activate", (GCallback) _gmpc_meta_data_widgets_similar_songs_add_clicked_gtk_menu_item_activate, self, 0);
		gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) ((GtkMenuItem*) item));
		_tmp3_ = _ ("_Replace");
		_tmp4_ = (GtkImageMenuItem*) gtk_image_menu_item_new_with_mnemonic (_tmp3_);
		_g_object_unref0 (item);
		item = g_object_ref_sink (_tmp4_);
		_tmp5_ = (GtkImage*) gtk_image_new_from_stock ("gtk-redo", GTK_ICON_SIZE_MENU);
		_tmp6_ = g_object_ref_sink (_tmp5_);
		gtk_image_menu_item_set_image (item, (GtkWidget*) _tmp6_);
		_g_object_unref0 (_tmp6_);
		g_signal_connect_object ((GtkMenuItem*) item, "activate", (GCallback) _gmpc_meta_data_widgets_similar_songs_replace_clicked_gtk_menu_item_activate, self, 0);
		gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) ((GtkMenuItem*) item));
		_tmp7_ = tree;
		gmpc_mpddata_treeview_right_mouse_intergration (GMPC_IS_MPDDATA_TREEVIEW (_tmp7_) ? ((GmpcMpdDataTreeview*) _tmp7_) : NULL, menu);
		gtk_menu_popup (menu, NULL, NULL, NULL, NULL, (*event).button, (*event).time);
		gtk_widget_show_all ((GtkWidget*) menu);
		result = TRUE;
		_g_object_unref0 (item);
		_g_object_unref0 (menu);
		return result;
	}
	result = FALSE;
	return result;
}


static gboolean _gmpc_meta_data_widgets_similar_songs_tree_right_menu_gtk_widget_button_release_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
	gboolean result;
	result = gmpc_meta_data_widgets_similar_songs_tree_right_menu (self, _sender, event);
	return result;
}


static void _gmpc_meta_data_widgets_similar_songs_tree_row_activated_gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self) {
	gmpc_meta_data_widgets_similar_songs_tree_row_activated (self, _sender, path, column);
}


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;
}


static gboolean _gmpc_meta_data_widgets_similar_songs_update_sim_song_gsource_func (gpointer self) {
	gboolean result;
	result = gmpc_meta_data_widgets_similar_songs_update_sim_song (self);
	return result;
}


static void gmpc_meta_data_widgets_similar_songs_metadata_changed (GmpcMetaDataWidgetsSimilarSongs* self, GmpcMetaWatcher* gmw2, const mpd_Song* song, MetaDataType type, MetaDataResult _result_, const MetaData* met) {
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gmw2 != NULL);
	g_return_if_fail (song != NULL);
	_tmp0_ = g_utf8_collate (self->priv->song->artist, song->artist);
	if (_tmp0_ != 0) {
		return;
	}
	if (type != META_SONG_SIMILAR) {
		return;
	}
	if (self->priv->pchild != NULL) {
		gtk_object_destroy ((GtkObject*) self->priv->pchild);
	}
	if (_result_ == META_DATA_FETCHING) {
		const gchar* _tmp1_ = NULL;
		GtkLabel* _tmp2_ = NULL;
		GtkLabel* label;
		GtkWidget* _tmp3_;
		_tmp1_ = _ ("Fetching .. ");
		_tmp2_ = (GtkLabel*) gtk_label_new (_tmp1_);
		label = g_object_ref_sink (_tmp2_);
		gtk_misc_set_alignment ((GtkMisc*) label, 0.0f, 0.0f);
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) label);
		_tmp3_ = _g_object_ref0 ((GtkWidget*) label);
		_g_object_unref0 (self->priv->pchild);
		self->priv->pchild = _tmp3_;
		_g_object_unref0 (label);
	} else {
		if (_result_ == META_DATA_UNAVAILABLE) {
			const gchar* _tmp4_ = NULL;
			GtkLabel* _tmp5_ = NULL;
			GtkLabel* label;
			GtkWidget* _tmp6_;
			_tmp4_ = _ ("Unavailable");
			_tmp5_ = (GtkLabel*) gtk_label_new (_tmp4_);
			label = g_object_ref_sink (_tmp5_);
			gtk_misc_set_alignment ((GtkMisc*) label, 0.0f, 0.0f);
			gtk_container_add ((GtkContainer*) self, (GtkWidget*) label);
			_tmp6_ = _g_object_ref0 ((GtkWidget*) label);
			_g_object_unref0 (self->priv->pchild);
			self->priv->pchild = _tmp6_;
			_g_object_unref0 (label);
		} else {
			gboolean _tmp7_;
			_tmp7_ = meta_data_is_text_list (met);
			if (_tmp7_) {
				MetaData* _tmp8_ = NULL;
				guint _tmp9_;
				_tmp8_ = meta_data_dup_steal (met);
				_meta_data_free0 (self->priv->copy);
				self->priv->copy = _tmp8_;
				_tmp9_ = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _gmpc_meta_data_widgets_similar_songs_update_sim_song_gsource_func, g_object_ref (self), g_object_unref);
				self->priv->idle_add = _tmp9_;
				return;
			} else {
				const gchar* _tmp10_ = NULL;
				GtkLabel* _tmp11_ = NULL;
				GtkLabel* label;
				GtkWidget* _tmp12_;
				_tmp10_ = _ ("Unavailable");
				_tmp11_ = (GtkLabel*) gtk_label_new (_tmp10_);
				label = g_object_ref_sink (_tmp11_);
				gtk_misc_set_alignment ((GtkMisc*) label, 0.0f, 0.0f);
				gtk_container_add ((GtkContainer*) self, (GtkWidget*) label);
				_tmp12_ = _g_object_ref0 ((GtkWidget*) label);
				_g_object_unref0 (self->priv->pchild);
				self->priv->pchild = _tmp12_;
				_g_object_unref0 (label);
			}
		}
	}
	gtk_widget_show_all ((GtkWidget*) self);
}


static void _gmpc_meta_data_widgets_similar_songs_metadata_changed_gmpc_meta_watcher_data_changed (GmpcMetaWatcher* _sender, const mpd_Song* song, MetaDataType type, MetaDataResult _result_, const MetaData* met, gpointer self) {
	gmpc_meta_data_widgets_similar_songs_metadata_changed (self, _sender, song, type, _result_, met);
}


void gmpc_meta_data_widgets_similar_songs_update (GmpcMetaDataWidgetsSimilarSongs* self) {
	MetaData* item;
	MetaData* _tmp0_ = NULL;
	MetaDataResult _tmp1_;
	MetaDataResult gm_result;
	g_return_if_fail (self != NULL);
	item = NULL;
	g_signal_connect_object (gmw, "data-changed", (GCallback) _gmpc_meta_data_widgets_similar_songs_metadata_changed_gmpc_meta_watcher_data_changed, self, 0);
	_tmp1_ = gmpc_meta_watcher_get_meta_path (gmw, self->priv->song, META_SONG_SIMILAR, &_tmp0_);
	_meta_data_free0 (item);
	item = _tmp0_;
	gm_result = _tmp1_;
	gmpc_meta_data_widgets_similar_songs_metadata_changed (self, gmw, self->priv->song, META_SONG_SIMILAR, gm_result, item);
	_meta_data_free0 (item);
}


static void gmpc_meta_data_widgets_similar_songs_class_init (GmpcMetaDataWidgetsSimilarSongsClass * klass) {
	gmpc_meta_data_widgets_similar_songs_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GmpcMetaDataWidgetsSimilarSongsPrivate));
	G_OBJECT_CLASS (klass)->finalize = gmpc_meta_data_widgets_similar_songs_finalize;
}


static void gmpc_meta_data_widgets_similar_songs_instance_init (GmpcMetaDataWidgetsSimilarSongs * self) {
	self->priv = GMPC_META_DATA_WIDGETS_SIMILAR_SONGS_GET_PRIVATE (self);
	self->priv->song = NULL;
	self->priv->pchild = NULL;
	self->priv->idle_add = (guint) 0;
	self->priv->copy = NULL;
	self->priv->item = NULL;
	self->priv->current = NULL;
}


static void gmpc_meta_data_widgets_similar_songs_finalize (GObject* obj) {
	GmpcMetaDataWidgetsSimilarSongs * self;
	self = GMPC_META_DATA_WIDGETS_SIMILAR_SONGS (obj);
	if (self->priv->idle_add > 0) {
		g_source_remove (self->priv->idle_add);
		self->priv->idle_add = (guint) 0;
	}
	_mpd_freeSong0 (self->priv->song);
	_g_object_unref0 (self->priv->pchild);
	_meta_data_free0 (self->priv->copy);
	_mpd_data_free0 (self->priv->item);
	G_OBJECT_CLASS (gmpc_meta_data_widgets_similar_songs_parent_class)->finalize (obj);
}


GType gmpc_meta_data_widgets_similar_songs_get_type (void) {
	static volatile gsize gmpc_meta_data_widgets_similar_songs_type_id__volatile = 0;
	if (g_once_init_enter (&gmpc_meta_data_widgets_similar_songs_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GmpcMetaDataWidgetsSimilarSongsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gmpc_meta_data_widgets_similar_songs_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GmpcMetaDataWidgetsSimilarSongs), 0, (GInstanceInitFunc) gmpc_meta_data_widgets_similar_songs_instance_init, NULL };
		GType gmpc_meta_data_widgets_similar_songs_type_id;
		gmpc_meta_data_widgets_similar_songs_type_id = g_type_register_static (GTK_TYPE_ALIGNMENT, "GmpcMetaDataWidgetsSimilarSongs", &g_define_type_info, 0);
		g_once_init_leave (&gmpc_meta_data_widgets_similar_songs_type_id__volatile, gmpc_meta_data_widgets_similar_songs_type_id);
	}
	return gmpc_meta_data_widgets_similar_songs_type_id__volatile;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



