/* Generated by GOB (v2.0.15)   (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 15

#define selfp (self->_priv)

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

#include "mn-sound-file-chooser-dialog.h"

#include "mn-sound-file-chooser-dialog-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 */

#line 28 "src/mn-sound-file-chooser-dialog.gob"

#include <glib/gi18n.h>

enum
{
  RESPONSE_PLAY = 1,
  RESPONSE_STOP
};

#line 36 "mn-sound-file-chooser-dialog.c"
/* self casting macros */
#define SELF(x) MN_SOUND_FILE_CHOOSER_DIALOG(x)
#define SELF_CONST(x) MN_SOUND_FILE_CHOOSER_DIALOG_CONST(x)
#define IS_SELF(x) MN_IS_SOUND_FILE_CHOOSER_DIALOG(x)
#define TYPE_SELF MN_TYPE_SOUND_FILE_CHOOSER_DIALOG
#define SELF_CLASS(x) MN_SOUND_FILE_CHOOSER_DIALOG_CLASS(x)

#define SELF_GET_CLASS(x) MN_SOUND_FILE_CHOOSER_DIALOG_GET_CLASS(x)

/* self typedefs */
typedef MNSoundFileChooserDialog Self;
typedef MNSoundFileChooserDialogClass SelfClass;

/* here are local prototypes */
#line 0 "src/mn-sound-file-chooser-dialog.gob"
static void mn_sound_file_chooser_dialog_init (MNSoundFileChooserDialog * o);
#line 53 "mn-sound-file-chooser-dialog.c"
#line 0 "src/mn-sound-file-chooser-dialog.gob"
static void mn_sound_file_chooser_dialog_class_init (MNSoundFileChooserDialogClass * c);
#line 56 "mn-sound-file-chooser-dialog.c"
#line 42 "src/mn-sound-file-chooser-dialog.gob"
static void mn_sound_file_chooser_dialog_constructor (MNSoundFileChooserDialog * self);
#line 59 "mn-sound-file-chooser-dialog.c"
#line 81 "src/mn-sound-file-chooser-dialog.gob"
static void mn_sound_file_chooser_dialog_response_h (GtkDialog * dialog, int response, gpointer user_data);
#line 62 "mn-sound-file-chooser-dialog.c"
#line 109 "src/mn-sound-file-chooser-dialog.gob"
static void mn_sound_file_chooser_dialog_update_sensitivity (MNSoundFileChooserDialog * self);
#line 65 "mn-sound-file-chooser-dialog.c"
#line 116 "src/mn-sound-file-chooser-dialog.gob"
static gboolean mn_sound_file_chooser_dialog_has_selected_file (MNSoundFileChooserDialog * self);
#line 68 "mn-sound-file-chooser-dialog.c"

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

/* Short form macros */
#define self_response_h mn_sound_file_chooser_dialog_response_h
#define self_update_sensitivity mn_sound_file_chooser_dialog_update_sensitivity
#define self_has_selected_file mn_sound_file_chooser_dialog_has_selected_file
#define self_new mn_sound_file_chooser_dialog_new
GType
mn_sound_file_chooser_dialog_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (MNSoundFileChooserDialogClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) mn_sound_file_chooser_dialog_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (MNSoundFileChooserDialog),
			0 /* n_preallocs */,
			(GInstanceInitFunc) mn_sound_file_chooser_dialog_init,
			NULL
		};

		type = g_type_register_static (GTK_TYPE_FILE_CHOOSER_DIALOG, "MNSoundFileChooserDialog", &info, (GTypeFlags)0);
	}

	return type;
}

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

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


static GObject *
___constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
{
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::constructor"
	GObject *obj_self;
	MNSoundFileChooserDialog *self;
	obj_self = G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_properties, construct_properties);
	self = MN_SOUND_FILE_CHOOSER_DIALOG (obj_self);
#line 42 "src/mn-sound-file-chooser-dialog.gob"
	mn_sound_file_chooser_dialog_constructor (self);
#line 131 "mn-sound-file-chooser-dialog.c"
	return obj_self;
}
#undef __GOB_FUNCTION__


static void
___dispose (GObject *obj_self)
{
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::dispose"
	MNSoundFileChooserDialog *self G_GNUC_UNUSED = MN_SOUND_FILE_CHOOSER_DIALOG (obj_self);
	if (G_OBJECT_CLASS (parent_class)->dispose) \
		(* G_OBJECT_CLASS (parent_class)->dispose) (obj_self);
#line 40 "src/mn-sound-file-chooser-dialog.gob"
	if(self->_priv->sound_player) { g_object_unref ((gpointer) self->_priv->sound_player); self->_priv->sound_player = NULL; }
#line 146 "mn-sound-file-chooser-dialog.c"
}
#undef __GOB_FUNCTION__


static void
___finalize(GObject *obj_self)
{
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::finalize"
	MNSoundFileChooserDialog *self G_GNUC_UNUSED = MN_SOUND_FILE_CHOOSER_DIALOG (obj_self);
	gpointer priv G_GNUC_UNUSED = self->_priv;
	if(G_OBJECT_CLASS(parent_class)->finalize) \
		(* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
}
#undef __GOB_FUNCTION__

static void 
mn_sound_file_chooser_dialog_init (MNSoundFileChooserDialog * o G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::init"
	o->_priv = G_TYPE_INSTANCE_GET_PRIVATE(o,MN_TYPE_SOUND_FILE_CHOOSER_DIALOG,MNSoundFileChooserDialogPrivate);
}
#undef __GOB_FUNCTION__
static void 
mn_sound_file_chooser_dialog_class_init (MNSoundFileChooserDialogClass * c G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::class_init"
	GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;

	g_type_class_add_private(c,sizeof(MNSoundFileChooserDialogPrivate));

	parent_class = g_type_class_ref (GTK_TYPE_FILE_CHOOSER_DIALOG);

	g_object_class->constructor = ___constructor;
	g_object_class->dispose = ___dispose;
	g_object_class->finalize = ___finalize;
}
#undef __GOB_FUNCTION__



#line 42 "src/mn-sound-file-chooser-dialog.gob"
static void 
mn_sound_file_chooser_dialog_constructor (MNSoundFileChooserDialog * self)
{
#line 191 "mn-sound-file-chooser-dialog.c"
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::constructor"
{
#line 43 "src/mn-sound-file-chooser-dialog.gob"
	
    GtkFileFilter *filter;

    selfp->sound_player = mn_sound_player_new();

    gtk_window_set_title(GTK_WINDOW(self), _("Select a File"));

    gtk_dialog_add_buttons(GTK_DIALOG(self),
			   GTK_STOCK_MEDIA_PLAY, RESPONSE_PLAY,
			   GTK_STOCK_MEDIA_STOP, RESPONSE_STOP,
			   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
			   NULL);

    filter = gtk_file_filter_new();
    gtk_file_filter_set_name(filter, _("All files"));
    gtk_file_filter_add_pattern(filter, "*");
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(self), filter);

    filter = gtk_file_filter_new();
    gtk_file_filter_set_name(filter, _("Audio files"));
    gtk_file_filter_add_mime_type(filter, "audio/*");
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(self), filter);
    gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(self), filter);

    g_object_connect(self,
		     "signal::response", self_response_h, NULL,
		     "signal::selection-changed", self_update_sensitivity, NULL,
		     NULL);

    g_object_connect(selfp->sound_player,
		     "swapped-signal::notify::can-play", self_update_sensitivity, self,
		     "swapped-signal::notify::can-stop", self_update_sensitivity, self,
		     NULL);

    self_update_sensitivity(self);
  }}
#line 232 "mn-sound-file-chooser-dialog.c"
#undef __GOB_FUNCTION__

#line 81 "src/mn-sound-file-chooser-dialog.gob"
static void 
mn_sound_file_chooser_dialog_response_h (GtkDialog * dialog, int response, gpointer user_data)
{
#line 239 "mn-sound-file-chooser-dialog.c"
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::response_h"
{
#line 83 "src/mn-sound-file-chooser-dialog.gob"
	
    Self *self = SELF(dialog);

    if (response == RESPONSE_PLAY)
      {
	char *filename;

	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	if (filename)
	  {
	    mn_sound_player_play(selfp->sound_player, filename, GTK_WINDOW(dialog));
	    g_free(filename);
	  }
      }
    else if (response == RESPONSE_STOP)
      mn_sound_player_stop(selfp->sound_player);
    else
      return;

    /*
     * Do not pass our internal responses to client code and do not
     * let the dialog be destroyed.
     */
    g_signal_stop_emission_by_name(dialog, "response");
  }}
#line 268 "mn-sound-file-chooser-dialog.c"
#undef __GOB_FUNCTION__

#line 109 "src/mn-sound-file-chooser-dialog.gob"
static void 
mn_sound_file_chooser_dialog_update_sensitivity (MNSoundFileChooserDialog * self)
{
#line 275 "mn-sound-file-chooser-dialog.c"
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::update_sensitivity"
#line 109 "src/mn-sound-file-chooser-dialog.gob"
	g_return_if_fail (self != NULL);
#line 109 "src/mn-sound-file-chooser-dialog.gob"
	g_return_if_fail (MN_IS_SOUND_FILE_CHOOSER_DIALOG (self));
#line 281 "mn-sound-file-chooser-dialog.c"
{
#line 111 "src/mn-sound-file-chooser-dialog.gob"
	
    gtk_dialog_set_response_sensitive(GTK_DIALOG(self), RESPONSE_PLAY, self_has_selected_file(self) && mn_sound_player_get_can_play(selfp->sound_player));
    gtk_dialog_set_response_sensitive(GTK_DIALOG(self), RESPONSE_STOP, mn_sound_player_get_can_stop(selfp->sound_player));
  }}
#line 288 "mn-sound-file-chooser-dialog.c"
#undef __GOB_FUNCTION__

#line 116 "src/mn-sound-file-chooser-dialog.gob"
static gboolean 
mn_sound_file_chooser_dialog_has_selected_file (MNSoundFileChooserDialog * self)
{
#line 295 "mn-sound-file-chooser-dialog.c"
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::has_selected_file"
#line 116 "src/mn-sound-file-chooser-dialog.gob"
	g_return_val_if_fail (self != NULL, (gboolean )0);
#line 116 "src/mn-sound-file-chooser-dialog.gob"
	g_return_val_if_fail (MN_IS_SOUND_FILE_CHOOSER_DIALOG (self), (gboolean )0);
#line 301 "mn-sound-file-chooser-dialog.c"
{
#line 118 "src/mn-sound-file-chooser-dialog.gob"
	
    char *filename;
    gboolean has;

    filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(self));
    has = filename && ! g_file_test(filename, G_FILE_TEST_IS_DIR);
    g_free(filename);

    return has;
  }}
#line 314 "mn-sound-file-chooser-dialog.c"
#undef __GOB_FUNCTION__

#line 129 "src/mn-sound-file-chooser-dialog.gob"
GtkWidget * 
mn_sound_file_chooser_dialog_new (void)
{
#line 321 "mn-sound-file-chooser-dialog.c"
#define __GOB_FUNCTION__ "MN:Sound:File:Chooser:Dialog::new"
{
#line 131 "src/mn-sound-file-chooser-dialog.gob"
	
    return GTK_WIDGET(GET_NEW);
  }}
#line 328 "mn-sound-file-chooser-dialog.c"
#undef __GOB_FUNCTION__
