/* Generated by GOB (v2.0.20)   (do not edit directly) */

/* End world hunger, donate to the World Food Programme, http://www.wfp.org */

#define GOB_VERSION_MAJOR 2
#define GOB_VERSION_MINOR 0
#define GOB_VERSION_PATCHLEVEL 20

#define selfp (self->_priv)

#include <string.h> /* memset() */

#include "gmpc-meta-watcher.h"

#include "gmpc-meta-watcher-private.h"

#ifdef G_LIKELY
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
#else /* ! G_LIKELY */
#define ___GOB_LIKELY(expr) (expr)
#define ___GOB_UNLIKELY(expr) (expr)
#endif /* G_LIKELY */
/* self casting macros */
#define SELF(x) GMPC_META_WATCHER(x)
#define SELF_CONST(x) GMPC_META_WATCHER_CONST(x)
#define IS_SELF(x) GMPC_IS_META_WATCHER(x)
#define TYPE_SELF GMPC_TYPE_META_WATCHER
#define SELF_CLASS(x) GMPC_META_WATCHER_CLASS(x)

#define SELF_GET_CLASS(x) GMPC_META_WATCHER_GET_CLASS(x)

/* self typedefs */
typedef GmpcMetaWatcher Self;
typedef GmpcMetaWatcherClass SelfClass;

/* here are local prototypes */
static void gmpc_meta_watcher_class_init (GmpcMetaWatcherClass * c) G_GNUC_UNUSED;
#line 30 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
static void gmpc_meta_watcher_init (GmpcMetaWatcher * self) G_GNUC_UNUSED;
#line 42 "gmpc-meta-watcher.c"

/*
 * Signal connection wrapper macro shortcuts
 */
#define self_connect__data_changed(object,func,data)	gmpc_meta_watcher_connect__data_changed((object),(func),(data))
#define self_connect_after__data_changed(object,func,data)	gmpc_meta_watcher_connect_after__data_changed((object),(func),(data))
#define self_connect_data__data_changed(object,func,data,destroy_data,flags)	gmpc_meta_watcher_connect_data__data_changed((object),(func),(data),(destroy_data),(flags))
#define self_connect__force_reload(object,func,data)	gmpc_meta_watcher_connect__force_reload((object),(func),(data))
#define self_connect_after__force_reload(object,func,data)	gmpc_meta_watcher_connect_after__force_reload((object),(func),(data))
#define self_connect_data__force_reload(object,func,data,destroy_data,flags)	gmpc_meta_watcher_connect_data__force_reload((object),(func),(data),(destroy_data),(flags))

typedef void  (*___Sig1) (GmpcMetaWatcher *, gpointer , gint , gint , gpointer , gpointer);

static void
___marshal_Sig1 (GClosure *closure,
	GValue *return_value G_GNUC_UNUSED,
	guint n_param_values,
	const GValue *param_values,
	gpointer invocation_hint G_GNUC_UNUSED,
	gpointer marshal_data)
{
	register ___Sig1 callback;
	register GCClosure *cc = (GCClosure*) closure;
	register gpointer data1, data2;

	g_return_if_fail (n_param_values == 5);

	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = g_value_peek_pointer (param_values + 0);
	} else {
		data1 = g_value_peek_pointer (param_values + 0);
		data2 = closure->data;
	}

	callback = (___Sig1) (marshal_data != NULL ? marshal_data : cc->callback);

	callback ((GmpcMetaWatcher *)data1,
		(gpointer ) g_value_get_pointer (param_values + 1),
		(gint ) g_value_get_int (param_values + 2),
		(gint ) g_value_get_int (param_values + 3),
		(gpointer ) g_value_get_pointer (param_values + 4),
		data2);
}


enum {
	DATA_CHANGED_SIGNAL,
	FORCE_RELOAD_SIGNAL,
	LAST_SIGNAL
};

static guint object_signals[LAST_SIGNAL] = {0};

/* pointer to the class of our parent */
static GObjectClass *parent_class = NULL;

/* Short form macros */
#define self_new gmpc_meta_watcher_new
#define self_data_changed gmpc_meta_watcher_data_changed
#define self_force_reload gmpc_meta_watcher_force_reload
#define self_match_data gmpc_meta_watcher_match_data
#define self_get_meta_path_callback gmpc_meta_watcher_get_meta_path_callback
#define self_get_meta_path gmpc_meta_watcher_get_meta_path
GType
gmpc_meta_watcher_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (GmpcMetaWatcherClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) gmpc_meta_watcher_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (GmpcMetaWatcher),
			0 /* n_preallocs */,
			(GInstanceInitFunc) gmpc_meta_watcher_init,
			NULL
		};

		type = g_type_register_static (G_TYPE_OBJECT, "GmpcMetaWatcher", &info, (GTypeFlags)0);
	}

	return type;
}

/* a macro for creating a new object of our type */
#define GET_NEW ((GmpcMetaWatcher *)g_object_new(gmpc_meta_watcher_get_type(), NULL))

/* a function for creating a new object of our type */
#include <stdarg.h>
static GmpcMetaWatcher * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
static GmpcMetaWatcher *
GET_NEW_VARG (const char *first, ...)
{
	GmpcMetaWatcher *ret;
	va_list ap;
	va_start (ap, first);
	ret = (GmpcMetaWatcher *)g_object_new_valist (gmpc_meta_watcher_get_type (), first, ap);
	va_end (ap);
	return ret;
}

static void 
gmpc_meta_watcher_class_init (GmpcMetaWatcherClass * c G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::class_init"
	GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;

	parent_class = g_type_class_ref (G_TYPE_OBJECT);

	object_signals[DATA_CHANGED_SIGNAL] =
		g_signal_new ("data_changed",
			G_TYPE_FROM_CLASS (g_object_class),
			(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
			G_STRUCT_OFFSET (GmpcMetaWatcherClass, data_changed),
			NULL, NULL,
			___marshal_Sig1,
			G_TYPE_NONE, 4,
			G_TYPE_POINTER,
			G_TYPE_INT,
			G_TYPE_INT,
			G_TYPE_POINTER);
	if ___GOB_UNLIKELY(sizeof(mpd_Song * ) != sizeof(gpointer ) || sizeof(MetaDataType ) != sizeof(gint ) || sizeof(MetaDataResult ) != sizeof(gint ) || sizeof(MetaData * ) != sizeof(gpointer ) || parent_class == NULL /* avoid warning */) {
		g_error("/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob line 40: Type mismatch of \"data_changed\" signal signature");
	}
	object_signals[FORCE_RELOAD_SIGNAL] =
		g_signal_new ("force_reload",
			G_TYPE_FROM_CLASS (g_object_class),
			(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
			G_STRUCT_OFFSET (GmpcMetaWatcherClass, force_reload),
			NULL, NULL,
			g_cclosure_marshal_VOID__VOID,
			G_TYPE_NONE, 0);

	c->data_changed = NULL;
	c->force_reload = NULL;
}
#undef __GOB_FUNCTION__
#line 30 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
static void 
gmpc_meta_watcher_init (GmpcMetaWatcher * self G_GNUC_UNUSED)
{
#line 189 "gmpc-meta-watcher.c"
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::init"
}
#undef __GOB_FUNCTION__



#line 34 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
GmpcMetaWatcher * 
gmpc_meta_watcher_new (void)
{
#line 200 "gmpc-meta-watcher.c"
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::new"
{
#line 36 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	
      return GET_NEW;
    }}
#line 207 "gmpc-meta-watcher.c"
#undef __GOB_FUNCTION__

#line 40 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
void 
gmpc_meta_watcher_data_changed (GmpcMetaWatcher * self, mpd_Song * song, MetaDataType type, MetaDataResult result, MetaData * met)
{
#line 214 "gmpc-meta-watcher.c"
	GValue ___param_values[5];
	GValue ___return_val;

memset (&___return_val, 0, sizeof (___return_val));
memset (&___param_values, 0, sizeof (___param_values));

#line 40 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (self != NULL);
#line 40 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (GMPC_IS_META_WATCHER (self));
#line 225 "gmpc-meta-watcher.c"

	___param_values[0].g_type = 0;
	g_value_init (&___param_values[0], G_TYPE_FROM_INSTANCE (self));
	g_value_set_instance (&___param_values[0], (gpointer) self);

	___param_values[1].g_type = 0;
	g_value_init (&___param_values[1], G_TYPE_POINTER);
	g_value_set_pointer (&___param_values[1], (gpointer ) song);

	___param_values[2].g_type = 0;
	g_value_init (&___param_values[2], G_TYPE_INT);
	g_value_set_int (&___param_values[2], (gint ) type);

	___param_values[3].g_type = 0;
	g_value_init (&___param_values[3], G_TYPE_INT);
	g_value_set_int (&___param_values[3], (gint ) result);

	___param_values[4].g_type = 0;
	g_value_init (&___param_values[4], G_TYPE_POINTER);
	g_value_set_pointer (&___param_values[4], (gpointer ) met);

	g_signal_emitv (___param_values,
		object_signals[DATA_CHANGED_SIGNAL],
		0 /* detail */,
		&___return_val);

	g_value_unset (&___param_values[0]);
	g_value_unset (&___param_values[1]);
	g_value_unset (&___param_values[2]);
	g_value_unset (&___param_values[3]);
	g_value_unset (&___param_values[4]);
}

#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
void 
gmpc_meta_watcher_force_reload (GmpcMetaWatcher * self)
{
#line 263 "gmpc-meta-watcher.c"
	GValue ___param_values[1];
	GValue ___return_val;

memset (&___return_val, 0, sizeof (___return_val));
memset (&___param_values, 0, sizeof (___param_values));

#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (self != NULL);
#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (GMPC_IS_META_WATCHER (self));
#line 274 "gmpc-meta-watcher.c"

	___param_values[0].g_type = 0;
	g_value_init (&___param_values[0], G_TYPE_FROM_INSTANCE (self));
	g_value_set_instance (&___param_values[0], (gpointer) self);

	g_signal_emitv (___param_values,
		object_signals[FORCE_RELOAD_SIGNAL],
		0 /* detail */,
		&___return_val);

	g_value_unset (&___param_values[0]);
}

#line 59 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
gboolean 
gmpc_meta_watcher_match_data (MetaDataType type, mpd_Song * song1, mpd_Song * song2)
{
#line 292 "gmpc-meta-watcher.c"
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::match_data"
{
#line 62 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	
		if(song1 == NULL || song2 == NULL)
			return FALSE;
		switch(type)
		{
            case META_GENRE_SIMILAR:
				if(song1->genre && song2->genre && !strcmp(song1->genre, song2->genre))
					return TRUE;
                return FALSE;
			case META_SONG_TXT:
            case META_SONG_GUITAR_TAB:
				if(song1->artist && song2->artist && !strcmp(song1->artist, song2->artist))
                    if(song1->title && song2->title && !strcmp(song1->title, song2->title))
                        return TRUE;
				return FALSE;

			case META_ALBUM_TXT:
			case META_ALBUM_ART:
				if(song1->album == NULL || song2->album == NULL || strcmp(song1->album, song2->album))
				{
					return FALSE;
				}
			case META_ARTIST_SIMILAR:
			case META_ARTIST_TXT:
			case META_ARTIST_ART: 
                if(song1->albumartist && song2->albumartist && !strcmp(song1->albumartist, song2->albumartist))
                {
                    return TRUE;
                }
				if(song1->artist && song2->artist  && !strcmp(song1->artist, song2->artist))
				{
					return TRUE;
				}
                /* if we rewrite the artist, to be various (collection) also "see that" */
                if((song1->artist && !strcmp(song1->artist, "Various Artists")) &&
                        (song2->artist && !strcmp(song2->artist, "Various Artists")))
                {
                    return TRUE;
                }
                break;
            case META_SONG_SIMILAR:
                if(song1->title == NULL || song2->title == NULL || strcmp(song1->title, song2->title))
                {
                    return FALSE;
                }
				if(song1->artist && song2->artist  && !strcmp(song1->artist, song2->artist))
				{

					return TRUE;
				}
                /* if we rewrite the artist, to be various (collection) also "see that" */
                if((song1->artist && !strcmp(song1->artist, "Various Artists")) ||
                        (song2->artist && !strcmp(song2->artist, "Various Artists")))
                {
                    return TRUE;
                }
            case META_QUERY_DATA_TYPES:
            case META_QUERY_NO_CACHE:
            default:
				break;
		}
		return FALSE;
	}}
#line 359 "gmpc-meta-watcher.c"
#undef __GOB_FUNCTION__

#line 126 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
void 
gmpc_meta_watcher_get_meta_path_callback (GmpcMetaWatcher * self, mpd_Song * song, MetaDataType type, MetaDataCallback callback, gpointer data)
{
#line 366 "gmpc-meta-watcher.c"
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::get_meta_path_callback"
#line 126 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (self != NULL);
#line 126 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_if_fail (GMPC_IS_META_WATCHER (self));
#line 372 "gmpc-meta-watcher.c"
{
#line 129 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	
        MetaData *met = NULL;
		MetaDataResult ret;

		if(!self_match_data(type&META_QUERY_DATA_TYPES, song,song))
		{
			callback(song, META_DATA_UNAVAILABLE, NULL, data);			
            g_warning("Query is invalid");
            return;
		}
		ret = meta_data_get_path(song, type, &met,callback,data);
		callback(song,ret,met,data);
		if(met) meta_data_free(met);
	}}
#line 389 "gmpc-meta-watcher.c"
#undef __GOB_FUNCTION__

#line 144 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
MetaDataResult 
gmpc_meta_watcher_get_meta_path (GmpcMetaWatcher * self, mpd_Song * song, MetaDataType type, MetaData ** met)
{
#line 396 "gmpc-meta-watcher.c"
#define __GOB_FUNCTION__ "Gmpc:Meta:Watcher::get_meta_path"
#line 144 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_val_if_fail (self != NULL, (MetaDataResult )0);
#line 144 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	g_return_val_if_fail (GMPC_IS_META_WATCHER (self), (MetaDataResult )0);
#line 402 "gmpc-meta-watcher.c"
{
#line 147 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-meta-watcher.gob"
	
		g_assert(met != NULL);
			
		if(!self_match_data(type&META_QUERY_DATA_TYPES, song,song))
		{
			return META_DATA_UNAVAILABLE;
		}

		return meta_data_get_path(song, type, met,NULL,NULL);
	}}
#line 415 "gmpc-meta-watcher.c"
#undef __GOB_FUNCTION__
