/* SendChooserDialog.c generated by valac 0.54.3, the Vala compiler
 * generated from SendChooserDialog.vala, do not modify */

/*
 *  Copyright (C) 2009-2010 Michael J. Chudobiak.
 *
 *  This file is part of moserial.
 *
 *  moserial 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  moserial 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 moserial.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define MOSERIAL_TYPE_SEND_CHOOSER_DIALOG (moserial_send_chooser_dialog_get_type ())
#define MOSERIAL_SEND_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, moserialSendChooserDialog))
#define MOSERIAL_SEND_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, moserialSendChooserDialogClass))
#define MOSERIAL_IS_SEND_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_SEND_CHOOSER_DIALOG))
#define MOSERIAL_IS_SEND_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_SEND_CHOOSER_DIALOG))
#define MOSERIAL_SEND_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, moserialSendChooserDialogClass))

typedef struct _moserialSendChooserDialog moserialSendChooserDialog;
typedef struct _moserialSendChooserDialogClass moserialSendChooserDialogClass;
typedef struct _moserialSendChooserDialogPrivate moserialSendChooserDialogPrivate;
enum  {
	MOSERIAL_SEND_CHOOSER_DIALOG_0_PROPERTY,
	MOSERIAL_SEND_CHOOSER_DIALOG_NUM_PROPERTIES
};
static GParamSpec* moserial_send_chooser_dialog_properties[MOSERIAL_SEND_CHOOSER_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef enum  {
	MOSERIAL_SZWRAPPER_PROTOCOL_XMODEM,
	MOSERIAL_SZWRAPPER_PROTOCOL_YMODEM,
	MOSERIAL_SZWRAPPER_PROTOCOL_ZMODEM,
	MOSERIAL_SZWRAPPER_PROTOCOL_RAW,
	MOSERIAL_SZWRAPPER_PROTOCOL_NULL
} moserialSzwrapperProtocol;

#define MOSERIAL_SZWRAPPER_TYPE_PROTOCOL (moserial_szwrapper_protocol_get_type ())
enum  {
	MOSERIAL_SEND_CHOOSER_DIALOG_START_TRANSFER_SIGNAL,
	MOSERIAL_SEND_CHOOSER_DIALOG_NUM_SIGNALS
};
static guint moserial_send_chooser_dialog_signals[MOSERIAL_SEND_CHOOSER_DIALOG_NUM_SIGNALS] = {0};

struct _moserialSendChooserDialog {
	GObject parent_instance;
	moserialSendChooserDialogPrivate * priv;
	GtkComboBox* protocolCombo;
	gchar* filename;
};

struct _moserialSendChooserDialogClass {
	GObjectClass parent_class;
};

struct _moserialSendChooserDialogPrivate {
	GtkFileChooserDialog* dialog;
};

static gint moserialSendChooserDialog_private_offset;
static gpointer moserial_send_chooser_dialog_parent_class = NULL;

VALA_EXTERN GType moserial_send_chooser_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (moserialSendChooserDialog, g_object_unref)
VALA_EXTERN moserialSendChooserDialog* moserial_send_chooser_dialog_new (GtkWindow* parent);
VALA_EXTERN moserialSendChooserDialog* moserial_send_chooser_dialog_construct (GType object_type,
                                                                   GtkWindow* parent);
VALA_EXTERN void mo_utils_populateComboBox (GtkComboBox* Combo,
                                gchar** val_array,
                                gint val_array_length1,
                                gboolean render_cell);
VALA_EXTERN gboolean moserial_send_chooser_dialog_hide (moserialSendChooserDialog* self);
static gboolean _moserial_send_chooser_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender,
                                                                     GdkEventAny* event,
                                                                     gpointer self);
VALA_EXTERN GType moserial_szwrapper_protocol_get_type (void) G_GNUC_CONST ;
static void moserial_send_chooser_dialog_response (moserialSendChooserDialog* self,
                                            GtkWidget* w,
                                            gint r);
static void _moserial_send_chooser_dialog_response_gtk_dialog_response (GtkDialog* _sender,
                                                                 gint response_id,
                                                                 gpointer self);
VALA_EXTERN void moserial_send_chooser_dialog_show (moserialSendChooserDialog* self,
                                        const gchar* folder);
VALA_EXTERN gboolean mo_utils_fileExists (const gchar* path);
static void moserial_send_chooser_dialog_finalize (GObject * obj);
static GType moserial_send_chooser_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

VALA_EXTERN const gchar* MOSERIAL_SZWRAPPER_ProtocolStrings[4];

static inline gpointer
moserial_send_chooser_dialog_get_instance_private (moserialSendChooserDialog* self)
{
	return G_STRUCT_MEMBER_P (self, moserialSendChooserDialog_private_offset);
}

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

static gboolean
_moserial_send_chooser_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender,
                                                            GdkEventAny* event,
                                                            gpointer self)
{
	gboolean result;
	result = moserial_send_chooser_dialog_hide ((moserialSendChooserDialog*) self);
	return result;
}

static void
_moserial_send_chooser_dialog_response_gtk_dialog_response (GtkDialog* _sender,
                                                            gint response_id,
                                                            gpointer self)
{
	moserial_send_chooser_dialog_response ((moserialSendChooserDialog*) self, _sender, response_id);
}

moserialSendChooserDialog*
moserial_send_chooser_dialog_construct (GType object_type,
                                        GtkWindow* parent)
{
	moserialSendChooserDialog * self = NULL;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp0_;
	GObject* _tmp1_;
	GtkFileChooserDialog* _tmp2_;
	GtkFileChooserDialog* _tmp3_;
	GObject* _tmp4_;
	GtkComboBox* _tmp5_;
	GtkComboBox* _tmp6_;
	GtkFileChooserDialog* _tmp7_;
	GtkFileChooserDialog* _tmp8_;
	GtkComboBox* _tmp9_;
	GtkFileChooserDialog* _tmp10_;
	g_return_val_if_fail (parent != NULL, NULL);
	self = (moserialSendChooserDialog*) g_object_new (object_type, NULL);
	_tmp0_ = gtk_builder_new_from_resource (UIROOT "send_chooser_dialog.ui");
	builder = _tmp0_;
	_tmp1_ = gtk_builder_get_object (builder, "send_chooser_dialog");
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_file_chooser_dialog_get_type (), GtkFileChooserDialog));
	_g_object_unref0 (self->priv->dialog);
	self->priv->dialog = _tmp2_;
	_tmp3_ = self->priv->dialog;
	gtk_window_set_transient_for ((GtkWindow*) _tmp3_, parent);
	_tmp4_ = gtk_builder_get_object (builder, "send_chooser_protocol");
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_combo_box_get_type (), GtkComboBox));
	_g_object_unref0 (self->protocolCombo);
	self->protocolCombo = _tmp5_;
	_tmp6_ = self->protocolCombo;
	mo_utils_populateComboBox (_tmp6_, MOSERIAL_SZWRAPPER_ProtocolStrings, (gint) G_N_ELEMENTS (MOSERIAL_SZWRAPPER_ProtocolStrings), TRUE);
	_tmp7_ = self->priv->dialog;
	g_signal_connect_object ((GtkWidget*) _tmp7_, "delete-event", (GCallback) _moserial_send_chooser_dialog_hide_gtk_widget_delete_event, self, 0);
	_tmp8_ = self->priv->dialog;
	gtk_dialog_add_buttons ((GtkDialog*) _tmp8_, "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-ok", GTK_RESPONSE_ACCEPT, NULL, NULL);
	_tmp9_ = self->protocolCombo;
	gtk_combo_box_set_active (_tmp9_, (gint) MOSERIAL_SZWRAPPER_PROTOCOL_ZMODEM);
	_tmp10_ = self->priv->dialog;
	g_signal_connect_object ((GtkDialog*) _tmp10_, "response", (GCallback) _moserial_send_chooser_dialog_response_gtk_dialog_response, self, 0);
	_g_object_unref0 (builder);
	return self;
}

moserialSendChooserDialog*
moserial_send_chooser_dialog_new (GtkWindow* parent)
{
	return moserial_send_chooser_dialog_construct (MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, parent);
}

void
moserial_send_chooser_dialog_show (moserialSendChooserDialog* self,
                                   const gchar* folder)
{
	gboolean _tmp0_ = FALSE;
	GtkFileChooserDialog* _tmp2_;
	g_return_if_fail (self != NULL);
	if (folder != NULL) {
		_tmp0_ = mo_utils_fileExists (folder);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GtkFileChooserDialog* _tmp1_;
		_tmp1_ = self->priv->dialog;
		gtk_file_chooser_set_current_folder ((GtkFileChooser*) _tmp1_, folder);
	}
	_tmp2_ = self->priv->dialog;
	gtk_dialog_run ((GtkDialog*) _tmp2_);
}

gboolean
moserial_send_chooser_dialog_hide (moserialSendChooserDialog* self)
{
	GtkFileChooserDialog* _tmp0_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->dialog;
	gtk_widget_hide ((GtkWidget*) _tmp0_);
	result = TRUE;
	return result;
}

static void
moserial_send_chooser_dialog_response (moserialSendChooserDialog* self,
                                       GtkWidget* w,
                                       gint r)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	if (r == ((gint) GTK_RESPONSE_CANCEL)) {
		moserial_send_chooser_dialog_hide (self);
	} else {
		if (r == ((gint) GTK_RESPONSE_ACCEPT)) {
			GtkFileChooserDialog* _tmp0_;
			gchar* _tmp1_;
			moserial_send_chooser_dialog_hide (self);
			_tmp0_ = self->priv->dialog;
			_tmp1_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp0_);
			_g_free0 (self->filename);
			self->filename = _tmp1_;
			g_signal_emit (self, moserial_send_chooser_dialog_signals[MOSERIAL_SEND_CHOOSER_DIALOG_START_TRANSFER_SIGNAL], 0);
		} else {
		}
	}
}

static void
moserial_send_chooser_dialog_class_init (moserialSendChooserDialogClass * klass,
                                         gpointer klass_data)
{
	moserial_send_chooser_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &moserialSendChooserDialog_private_offset);
	G_OBJECT_CLASS (klass)->finalize = moserial_send_chooser_dialog_finalize;
	moserial_send_chooser_dialog_signals[MOSERIAL_SEND_CHOOSER_DIALOG_START_TRANSFER_SIGNAL] = g_signal_new ("start-transfer", MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
moserial_send_chooser_dialog_instance_init (moserialSendChooserDialog * self,
                                            gpointer klass)
{
	self->priv = moserial_send_chooser_dialog_get_instance_private (self);
}

static void
moserial_send_chooser_dialog_finalize (GObject * obj)
{
	moserialSendChooserDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_SEND_CHOOSER_DIALOG, moserialSendChooserDialog);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->protocolCombo);
	_g_free0 (self->filename);
	G_OBJECT_CLASS (moserial_send_chooser_dialog_parent_class)->finalize (obj);
}

static GType
moserial_send_chooser_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (moserialSendChooserDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) moserial_send_chooser_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (moserialSendChooserDialog), 0, (GInstanceInitFunc) moserial_send_chooser_dialog_instance_init, NULL };
	GType moserial_send_chooser_dialog_type_id;
	moserial_send_chooser_dialog_type_id = g_type_register_static (G_TYPE_OBJECT, "moserialSendChooserDialog", &g_define_type_info, 0);
	moserialSendChooserDialog_private_offset = g_type_add_instance_private (moserial_send_chooser_dialog_type_id, sizeof (moserialSendChooserDialogPrivate));
	return moserial_send_chooser_dialog_type_id;
}

GType
moserial_send_chooser_dialog_get_type (void)
{
	static volatile gsize moserial_send_chooser_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&moserial_send_chooser_dialog_type_id__volatile)) {
		GType moserial_send_chooser_dialog_type_id;
		moserial_send_chooser_dialog_type_id = moserial_send_chooser_dialog_get_type_once ();
		g_once_init_leave (&moserial_send_chooser_dialog_type_id__volatile, moserial_send_chooser_dialog_type_id);
	}
	return moserial_send_chooser_dialog_type_id__volatile;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

