/* 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-stats-label.h"

#include "gmpc-stats-label-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_STATS_LABEL(x)
#define SELF_CONST(x) GMPC_STATS_LABEL_CONST(x)
#define IS_SELF(x) GMPC_IS_STATS_LABEL(x)
#define TYPE_SELF GMPC_TYPE_STATS_LABEL
#define SELF_CLASS(x) GMPC_STATS_LABEL_CLASS(x)

#define SELF_GET_CLASS(x) GMPC_STATS_LABEL_GET_CLASS(x)

/* self typedefs */
typedef GmpcStatsLabel Self;
typedef GmpcStatsLabelClass SelfClass;

/* here are local prototypes */
static void gmpc_stats_label_init (GmpcStatsLabel * o) G_GNUC_UNUSED;
static void gmpc_stats_label_class_init (GmpcStatsLabelClass * c) G_GNUC_UNUSED;
#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
static gboolean gmpc_stats_label_idle_handler (GmpcStatsLabel * self) G_GNUC_UNUSED;
#line 43 "gmpc-stats-label.c"
#line 137 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
static gboolean gmpc_stats_label_expose_event (GmpcStatsLabel * self, GdkEventExpose * event, gpointer data) G_GNUC_UNUSED;
#line 46 "gmpc-stats-label.c"

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

/* Short form macros */
#define self_idle_handler gmpc_stats_label_idle_handler
#define self_expose_event gmpc_stats_label_expose_event
#define self_new gmpc_stats_label_new
GType
gmpc_stats_label_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (GmpcStatsLabelClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) gmpc_stats_label_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (GmpcStatsLabel),
			0 /* n_preallocs */,
			(GInstanceInitFunc) gmpc_stats_label_init,
			NULL
		};

		type = g_type_register_static (GTK_TYPE_LABEL, "GmpcStatsLabel", &info, (GTypeFlags)0);
	}

	return type;
}

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

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


static void
___finalize(GObject *obj_self)
{
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::finalize"
	GmpcStatsLabel *self G_GNUC_UNUSED = GMPC_STATS_LABEL (obj_self);
	gpointer priv G_GNUC_UNUSED = self->_priv;
#line 47 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	if(self->_priv->song) { mpd_freeSong ((gpointer) self->_priv->song); self->_priv->song = NULL; }
#line 106 "gmpc-stats-label.c"
	if(G_OBJECT_CLASS(parent_class)->finalize) \
		(* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
}
#undef __GOB_FUNCTION__

static void 
gmpc_stats_label_init (GmpcStatsLabel * o G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::init"
	o->_priv = G_TYPE_INSTANCE_GET_PRIVATE(o,GMPC_TYPE_STATS_LABEL,GmpcStatsLabelPrivate);
#line 39 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	o->_priv->ltype = ARTIST_NUM_SONGS;
#line 119 "gmpc-stats-label.c"
#line 47 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	o->_priv->song = NULL;
#line 122 "gmpc-stats-label.c"
#line 47 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	o->_priv->ll_signal = 0;
#line 125 "gmpc-stats-label.c"
}
#undef __GOB_FUNCTION__
static void 
gmpc_stats_label_class_init (GmpcStatsLabelClass * c G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::class_init"
	GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;

	g_type_class_add_private(c,sizeof(GmpcStatsLabelPrivate));

	parent_class = g_type_class_ref (GTK_TYPE_LABEL);

	g_object_class->finalize = ___finalize;
}
#undef __GOB_FUNCTION__



#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
static gboolean 
gmpc_stats_label_idle_handler (GmpcStatsLabel * self)
{
#line 148 "gmpc-stats-label.c"
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::idle_handler"
#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	g_return_val_if_fail (self != NULL, (gboolean )0);
#line 50 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	g_return_val_if_fail (GMPC_IS_STATS_LABEL (self), (gboolean )0);
#line 154 "gmpc-stats-label.c"
{
#line 53 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	
        if(self->_priv->ltype == ARTIST_NUM_SONGS || self->_priv->ltype == ALBUM_NUM_SONGS)
        {
            MpdDBStats *stats = NULL;
            mpd_database_search_stats_start(connection);
            mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ARTIST, self->_priv->song->artist);
            if(self->_priv->ltype == ALBUM_NUM_SONGS) {
                mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ALBUM, self->_priv->song->album);
            }
            stats = mpd_database_search_stats_commit(connection);
            if(stats) {
                char *buffer = g_strdup_printf("%i", stats->numberOfSongs);
                gtk_label_set_text(GTK_LABEL(self), buffer); 
                q_free(buffer); 
                mpd_database_search_free_stats(stats);
            } else {
                gtk_label_set_text(GTK_LABEL(self), ""); 
            }
        }else if (self->_priv->ltype == ARTIST_PLAYTIME_SONGS || self->_priv->ltype == ALBUM_PLAYTIME_SONGS )
        {
            MpdDBStats *stats = NULL;
            mpd_database_search_stats_start(connection);
            mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ARTIST, self->_priv->song->artist);
            if(self->_priv->ltype == ALBUM_PLAYTIME_SONGS) {
                mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ALBUM, self->_priv->song->album);
            }
            stats = mpd_database_search_stats_commit(connection);
            if(stats) {
                char *buffer = format_time_real(stats->playTime,"");
                gtk_label_set_text(GTK_LABEL(self), buffer); 
                q_free(buffer); 
                mpd_database_search_free_stats(stats);
            } else {
                gtk_label_set_text(GTK_LABEL(self), ""); 
            }
        }else if (self->_priv->ltype == ARTIST_GENRES_SONGS|| self->_priv->ltype == ALBUM_GENRES_SONGS)
        {
            GString *string = NULL;
            MpdData *data = NULL;
            mpd_database_search_field_start(connection, MPD_TAG_ITEM_GENRE);
            mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ARTIST, self->_priv->song->artist);
            if(self->_priv->ltype == ALBUM_GENRES_SONGS) {
                mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ALBUM, self->_priv->song->album);
            }
            string = g_string_new("");
            for(data = mpd_database_search_commit(connection);data != NULL ;data= mpd_data_get_next(data))
            {
                if(strlen(data->tag) > 0)
                    g_string_append_printf(string, "%s%s",data->tag, (mpd_data_is_last(data))?"":", "); 
            }
            if(string->len >0) {
                gtk_label_set_text(GTK_LABEL(self), string->str); 
            } else {
                gtk_label_set_text(GTK_LABEL(self),_("n/a")); 
            }
            g_string_free(string, TRUE);
        }
        else if (self->_priv->ltype == ARTIST_DATES_SONGS || self->_priv->ltype == ALBUM_DATES_SONGS)
        {
            GString *string = NULL;
            MpdData *data = NULL;
            mpd_database_search_field_start(connection, MPD_TAG_ITEM_DATE);
            mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ARTIST, self->_priv->song->artist);
            if(self->_priv->ltype == ALBUM_DATES_SONGS) {
                mpd_database_search_add_constraint(connection, MPD_TAG_ITEM_ALBUM, self->_priv->song->album);
            }
            string = g_string_new("");
            for(data = mpd_database_search_commit(connection);data != NULL ;data= mpd_data_get_next(data))
            {
                if(strlen(data->tag) > 0)
                    g_string_append_printf(string, "%s%s",data->tag, (mpd_data_is_last(data))?"":", "); 
            }
            if(string->len >0) {
                gtk_label_set_text(GTK_LABEL(self), string->str); 
            } else {
                gtk_label_set_text(GTK_LABEL(self), _("n/a")); 
            }
            g_string_free(string, TRUE);
        }

        return FALSE;
    }}
#line 239 "gmpc-stats-label.c"
#undef __GOB_FUNCTION__

#line 137 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
static gboolean 
gmpc_stats_label_expose_event (GmpcStatsLabel * self, GdkEventExpose * event, gpointer data)
{
#line 246 "gmpc-stats-label.c"
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::expose_event"
#line 137 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	g_return_val_if_fail (self != NULL, (gboolean )0);
#line 137 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	g_return_val_if_fail (GMPC_IS_STATS_LABEL (self), (gboolean )0);
#line 252 "gmpc-stats-label.c"
{
#line 140 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	
        gchar *string = g_markup_printf_escaped("<i>%s</i>", _("Loading"));
        gtk_label_set_markup(GTK_LABEL(self),string);
        g_free(string);
        self_idle_handler(self);
        if(self->_priv->ll_signal) {
            g_signal_handler_disconnect(self, self->_priv->ll_signal);
            self->_priv->ll_signal = 0;
        }
        return FALSE;
    }}
#line 266 "gmpc-stats-label.c"
#undef __GOB_FUNCTION__

#line 152 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
GtkWidget * 
gmpc_stats_label_new (LabelType ltype, mpd_Song * song)
{
#line 273 "gmpc-stats-label.c"
#define __GOB_FUNCTION__ "Gmpc:Stats:Label::new"
{
#line 155 "/usr/src/extras/gmpc/gmpc-11.8.16-2.x86_64/src/gmpc-11.8.16/src/gmpc-stats-label.gob"
	
        Self *self = GET_NEW;
        self->_priv->song = mpd_songDup(song);
        self->_priv->ltype = ltype;
        /* Set expose signal, so I know when it is visible for the first time */
        self->_priv->ll_signal = g_signal_connect(G_OBJECT(self), "expose-event", G_CALLBACK(self_expose_event), NULL);
        return (GtkWidget *)self;
    }}
#line 285 "gmpc-stats-label.c"
#undef __GOB_FUNCTION__
