/* ReceiveChooserDialog.c generated by valac 0.38.4, the Vala compiler
 * generated from ReceiveChooserDialog.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.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>


#define MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG (moserial_receive_chooser_dialog_get_type ())
#define MOSERIAL_RECEIVE_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialog))
#define MOSERIAL_RECEIVE_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialogClass))
#define MOSERIAL_IS_RECEIVE_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG))
#define MOSERIAL_IS_RECEIVE_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG))
#define MOSERIAL_RECEIVE_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialogClass))

typedef struct _moserialReceiveChooserDialog moserialReceiveChooserDialog;
typedef struct _moserialReceiveChooserDialogClass moserialReceiveChooserDialogClass;
typedef struct _moserialReceiveChooserDialogPrivate moserialReceiveChooserDialogPrivate;
enum  {
	MOSERIAL_RECEIVE_CHOOSER_DIALOG_0_PROPERTY,
	MOSERIAL_RECEIVE_CHOOSER_DIALOG_NUM_PROPERTIES
};
static GParamSpec* moserial_receive_chooser_dialog_properties[MOSERIAL_RECEIVE_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))

#define MOSERIAL_RZWRAPPER_TYPE_PROTOCOL (moserial_rzwrapper_protocol_get_type ())
enum  {
	MOSERIAL_RECEIVE_CHOOSER_DIALOG_START_TRANSFER_SIGNAL,
	MOSERIAL_RECEIVE_CHOOSER_DIALOG_NUM_SIGNALS
};
static guint moserial_receive_chooser_dialog_signals[MOSERIAL_RECEIVE_CHOOSER_DIALOG_NUM_SIGNALS] = {0};

struct _moserialReceiveChooserDialog {
	GObject parent_instance;
	moserialReceiveChooserDialogPrivate * priv;
	GtkComboBox* protocolCombo;
	gchar* path;
};

struct _moserialReceiveChooserDialogClass {
	GObjectClass parent_class;
};

struct _moserialReceiveChooserDialogPrivate {
	GtkFileChooserDialog* dialog;
};

typedef enum  {
	MOSERIAL_RZWRAPPER_PROTOCOL_XMODEM,
	MOSERIAL_RZWRAPPER_PROTOCOL_YMODEM,
	MOSERIAL_RZWRAPPER_PROTOCOL_ZMODEM,
	MOSERIAL_RZWRAPPER_PROTOCOL_NULL
} moserialRzwrapperProtocol;


static gpointer moserial_receive_chooser_dialog_parent_class = NULL;

GType moserial_receive_chooser_dialog_get_type (void) G_GNUC_CONST;
#define MOSERIAL_RECEIVE_CHOOSER_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialogPrivate))
void moserial_receive_chooser_dialog_show (moserialReceiveChooserDialog* self, const gchar* folder);
gboolean mo_utils_fileExists (const gchar* path);
gboolean moserial_receive_chooser_dialog_hide (moserialReceiveChooserDialog* self);
static void moserial_receive_chooser_dialog_response (moserialReceiveChooserDialog* self, GtkWidget* w, gint r);
moserialReceiveChooserDialog* moserial_receive_chooser_dialog_new (void);
moserialReceiveChooserDialog* moserial_receive_chooser_dialog_construct (GType object_type);
static GObject * moserial_receive_chooser_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void mo_utils_populateComboBox (GtkComboBox* Combo, gchar** val_array, int val_array_length1);
static gboolean _moserial_receive_chooser_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender, GdkEventAny* event, gpointer self);
GType moserial_rzwrapper_protocol_get_type (void) G_GNUC_CONST;
static void _moserial_receive_chooser_dialog_response_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self);
static void moserial_receive_chooser_dialog_finalize (GObject * obj);

extern const gchar* MOSERIAL_RZWRAPPER_ProtocolStrings[3];

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


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


static void moserial_receive_chooser_dialog_response (moserialReceiveChooserDialog* self, GtkWidget* w, gint r) {
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	_tmp0_ = r;
	if (_tmp0_ == ((gint) GTK_RESPONSE_CANCEL)) {
		moserial_receive_chooser_dialog_hide (self);
	} else {
		gint _tmp1_;
		_tmp1_ = r;
		if (_tmp1_ == ((gint) GTK_RESPONSE_ACCEPT)) {
			GtkFileChooserDialog* _tmp2_;
			gchar* _tmp3_;
			moserial_receive_chooser_dialog_hide (self);
			_tmp2_ = self->priv->dialog;
			_tmp3_ = gtk_file_chooser_get_current_folder ((GtkFileChooser*) _tmp2_);
			_g_free0 (self->path);
			self->path = _tmp3_;
			g_signal_emit (self, moserial_receive_chooser_dialog_signals[MOSERIAL_RECEIVE_CHOOSER_DIALOG_START_TRANSFER_SIGNAL], 0);
		} else {
		}
	}
}


moserialReceiveChooserDialog* moserial_receive_chooser_dialog_construct (GType object_type) {
	moserialReceiveChooserDialog * self = NULL;
	self = (moserialReceiveChooserDialog*) g_object_new (object_type, NULL);
	return self;
}


moserialReceiveChooserDialog* moserial_receive_chooser_dialog_new (void) {
	return moserial_receive_chooser_dialog_construct (MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG);
}


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


static gboolean _moserial_receive_chooser_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender, GdkEventAny* event, gpointer self) {
	gboolean result;
	result = moserial_receive_chooser_dialog_hide ((moserialReceiveChooserDialog*) self);
	return result;
}


static void _moserial_receive_chooser_dialog_response_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) {
	moserial_receive_chooser_dialog_response ((moserialReceiveChooserDialog*) self, _sender, response_id);
}


static GObject * moserial_receive_chooser_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	moserialReceiveChooserDialog * self;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp0_;
	GtkBuilder* _tmp1_;
	GObject* _tmp2_;
	GtkFileChooserDialog* _tmp3_;
	GtkBuilder* _tmp4_;
	GObject* _tmp5_;
	GtkComboBox* _tmp6_;
	GtkComboBox* _tmp7_;
	GtkFileChooserDialog* _tmp8_;
	GtkFileChooserDialog* _tmp9_;
	GtkComboBox* _tmp10_;
	GtkFileChooserDialog* _tmp11_;
	parent_class = G_OBJECT_CLASS (moserial_receive_chooser_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialog);
	_tmp0_ = gtk_builder_new_from_resource (UIROOT "receive_chooser.ui");
	builder = _tmp0_;
	_tmp1_ = builder;
	_tmp2_ = gtk_builder_get_object (_tmp1_, "receive_chooser_dialog");
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_file_chooser_dialog_get_type (), GtkFileChooserDialog));
	_g_object_unref0 (self->priv->dialog);
	self->priv->dialog = _tmp3_;
	_tmp4_ = builder;
	_tmp5_ = gtk_builder_get_object (_tmp4_, "receive_chooser_protocol");
	_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_combo_box_get_type (), GtkComboBox));
	_g_object_unref0 (self->protocolCombo);
	self->protocolCombo = _tmp6_;
	_tmp7_ = self->protocolCombo;
	mo_utils_populateComboBox (_tmp7_, MOSERIAL_RZWRAPPER_ProtocolStrings, G_N_ELEMENTS (MOSERIAL_RZWRAPPER_ProtocolStrings));
	_tmp8_ = self->priv->dialog;
	g_signal_connect_object ((GtkWidget*) _tmp8_, "delete-event", (GCallback) _moserial_receive_chooser_dialog_hide_gtk_widget_delete_event, self, 0);
	_tmp9_ = self->priv->dialog;
	gtk_dialog_add_buttons ((GtkDialog*) _tmp9_, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL, NULL);
	_tmp10_ = self->protocolCombo;
	gtk_combo_box_set_active (_tmp10_, (gint) MOSERIAL_RZWRAPPER_PROTOCOL_ZMODEM);
	_tmp11_ = self->priv->dialog;
	g_signal_connect_object ((GtkDialog*) _tmp11_, "response", (GCallback) _moserial_receive_chooser_dialog_response_gtk_dialog_response, self, 0);
	_g_object_unref0 (builder);
	return obj;
}


static void moserial_receive_chooser_dialog_class_init (moserialReceiveChooserDialogClass * klass) {
	moserial_receive_chooser_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (moserialReceiveChooserDialogPrivate));
	G_OBJECT_CLASS (klass)->constructor = moserial_receive_chooser_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = moserial_receive_chooser_dialog_finalize;
	moserial_receive_chooser_dialog_signals[MOSERIAL_RECEIVE_CHOOSER_DIALOG_START_TRANSFER_SIGNAL] = g_signal_new ("start-transfer", MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void moserial_receive_chooser_dialog_instance_init (moserialReceiveChooserDialog * self) {
	self->priv = MOSERIAL_RECEIVE_CHOOSER_DIALOG_GET_PRIVATE (self);
}


static void moserial_receive_chooser_dialog_finalize (GObject * obj) {
	moserialReceiveChooserDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_RECEIVE_CHOOSER_DIALOG, moserialReceiveChooserDialog);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->protocolCombo);
	_g_free0 (self->path);
	G_OBJECT_CLASS (moserial_receive_chooser_dialog_parent_class)->finalize (obj);
}


GType moserial_receive_chooser_dialog_get_type (void) {
	static volatile gsize moserial_receive_chooser_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&moserial_receive_chooser_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (moserialReceiveChooserDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) moserial_receive_chooser_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (moserialReceiveChooserDialog), 0, (GInstanceInitFunc) moserial_receive_chooser_dialog_instance_init, NULL };
		GType moserial_receive_chooser_dialog_type_id;
		moserial_receive_chooser_dialog_type_id = g_type_register_static (G_TYPE_OBJECT, "moserialReceiveChooserDialog", &g_define_type_info, 0);
		g_once_init_leave (&moserial_receive_chooser_dialog_type_id__volatile, moserial_receive_chooser_dialog_type_id);
	}
	return moserial_receive_chooser_dialog_type_id__volatile;
}



