/* RecordDialog.c generated by valac 0.38.4, the Vala compiler
 * generated from RecordDialog.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_RECORD_DIALOG (moserial_record_dialog_get_type ())
#define MOSERIAL_RECORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialog))
#define MOSERIAL_RECORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialogClass))
#define MOSERIAL_IS_RECORD_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOSERIAL_TYPE_RECORD_DIALOG))
#define MOSERIAL_IS_RECORD_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOSERIAL_TYPE_RECORD_DIALOG))
#define MOSERIAL_RECORD_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialogClass))

typedef struct _moserialRecordDialog moserialRecordDialog;
typedef struct _moserialRecordDialogClass moserialRecordDialogClass;
typedef struct _moserialRecordDialogPrivate moserialRecordDialogPrivate;

#define MOSERIAL_SERIAL_STREAM_RECORDER_TYPE_DIRECTION (moserial_serial_stream_recorder_direction_get_type ())
enum  {
	MOSERIAL_RECORD_DIALOG_0_PROPERTY,
	MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY,
	MOSERIAL_RECORD_DIALOG_NUM_PROPERTIES
};
static GParamSpec* moserial_record_dialog_properties[MOSERIAL_RECORD_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))
enum  {
	MOSERIAL_RECORD_DIALOG_START_RECORDING_SIGNAL,
	MOSERIAL_RECORD_DIALOG_STOP_RECORDING_SIGNAL,
	MOSERIAL_RECORD_DIALOG_NUM_SIGNALS
};
static guint moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_NUM_SIGNALS] = {0};

typedef enum  {
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_INCOMING,
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_OUTGOING,
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_BOTH
} moserialSerialStreamRecorderDirection;

struct _moserialRecordDialog {
	GObject parent_instance;
	moserialRecordDialogPrivate * priv;
	moserialSerialStreamRecorderDirection direction;
};

struct _moserialRecordDialogClass {
	GObjectClass parent_class;
};

struct _moserialRecordDialogPrivate {
	GtkFileChooserDialog* dialog;
	GtkButton* cancelButton;
	GtkComboBox* streamCombo;
	gchar* _fileName;
};


static gpointer moserial_record_dialog_parent_class = NULL;

GType moserial_record_dialog_get_type (void) G_GNUC_CONST;
GType moserial_serial_stream_recorder_direction_get_type (void) G_GNUC_CONST;
#define MOSERIAL_RECORD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialogPrivate))
void moserial_record_dialog_show (moserialRecordDialog* self, const gchar* folder);
gboolean mo_utils_fileExists (const gchar* path);
gboolean moserial_record_dialog_hide (moserialRecordDialog* self);
static void moserial_record_dialog_response (moserialRecordDialog* self, GtkWidget* w, gint r);
static void moserial_record_dialog_set_fileName (moserialRecordDialog* self, const gchar* value);
const gchar* moserial_record_dialog_get_fileName (moserialRecordDialog* self);
moserialRecordDialog* moserial_record_dialog_new (void);
moserialRecordDialog* moserial_record_dialog_construct (GType object_type);
static void g_cclosure_user_marshal_VOID__STRING_ENUM (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static GObject * moserial_record_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_record_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender, GdkEventAny* event, gpointer self);
static void _moserial_record_dialog_response_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self);
static void moserial_record_dialog_finalize (GObject * obj);
static void _vala_moserial_record_dialog_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_moserial_record_dialog_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);

extern const gchar* MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings[3];

void moserial_record_dialog_show (moserialRecordDialog* 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_record_dialog_hide (moserialRecordDialog* 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_record_dialog_response (moserialRecordDialog* 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_record_dialog_set_fileName (self, NULL);
		moserial_record_dialog_hide (self);
		g_signal_emit (self, moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_STOP_RECORDING_SIGNAL], 0);
	} else {
		gint _tmp1_;
		_tmp1_ = r;
		if (_tmp1_ == ((gint) GTK_RESPONSE_ACCEPT)) {
			GtkFileChooserDialog* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			GtkComboBox* _tmp5_;
			gint _tmp6_;
			const gchar* _tmp7_;
			moserialSerialStreamRecorderDirection _tmp8_;
			_tmp2_ = self->priv->dialog;
			_tmp3_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp2_);
			_tmp4_ = _tmp3_;
			moserial_record_dialog_set_fileName (self, _tmp4_);
			_g_free0 (_tmp4_);
			_tmp5_ = self->priv->streamCombo;
			_tmp6_ = gtk_combo_box_get_active (_tmp5_);
			switch (_tmp6_) {
				default:
				case 0:
				{
					self->direction = MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_INCOMING;
					break;
				}
				case 1:
				{
					self->direction = MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_OUTGOING;
					break;
				}
				case 2:
				{
					self->direction = MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_BOTH;
					break;
				}
			}
			moserial_record_dialog_hide (self);
			_tmp7_ = self->priv->_fileName;
			_tmp8_ = self->direction;
			g_signal_emit (self, moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_START_RECORDING_SIGNAL], 0, _tmp7_, _tmp8_);
		} else {
			g_signal_emit (self, moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_STOP_RECORDING_SIGNAL], 0);
		}
	}
}


moserialRecordDialog* moserial_record_dialog_construct (GType object_type) {
	moserialRecordDialog * self = NULL;
	self = (moserialRecordDialog*) g_object_new (object_type, NULL);
	return self;
}


moserialRecordDialog* moserial_record_dialog_new (void) {
	return moserial_record_dialog_construct (MOSERIAL_TYPE_RECORD_DIALOG);
}


const gchar* moserial_record_dialog_get_fileName (moserialRecordDialog* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_fileName;
	result = _tmp0_;
	return result;
}


static void moserial_record_dialog_set_fileName (moserialRecordDialog* self, const gchar* value) {
	g_return_if_fail (self != NULL);
	if (g_strcmp0 (value, moserial_record_dialog_get_fileName (self)) != 0) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = value;
		_tmp1_ = g_strdup (_tmp0_);
		_g_free0 (self->priv->_fileName);
		self->priv->_fileName = _tmp1_;
		g_object_notify_by_pspec ((GObject *) self, moserial_record_dialog_properties[MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY]);
	}
}


static void g_cclosure_user_marshal_VOID__STRING_ENUM (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__STRING_ENUM) (gpointer data1, const char* arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__STRING_ENUM callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__STRING_ENUM) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_string (param_values + 1), g_value_get_enum (param_values + 2), data2);
}


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


static gboolean _moserial_record_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender, GdkEventAny* event, gpointer self) {
	gboolean result;
	result = moserial_record_dialog_hide ((moserialRecordDialog*) self);
	return result;
}


static void _moserial_record_dialog_response_gtk_dialog_response (GtkDialog* _sender, gint response_id, gpointer self) {
	moserial_record_dialog_response ((moserialRecordDialog*) self, _sender, response_id);
}


static GObject * moserial_record_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	moserialRecordDialog * self;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp0_;
	GtkBuilder* _tmp1_;
	GObject* _tmp2_;
	GtkFileChooserDialog* _tmp3_;
	GtkBuilder* _tmp4_;
	GObject* _tmp5_;
	GtkButton* _tmp6_;
	GtkBuilder* _tmp7_;
	GObject* _tmp8_;
	GtkComboBox* _tmp9_;
	GtkComboBox* _tmp10_;
	GtkComboBox* _tmp11_;
	GtkFileChooserDialog* _tmp12_;
	GtkFileChooserDialog* _tmp13_;
	GtkFileChooserDialog* _tmp14_;
	GtkFileChooserDialog* _tmp15_;
	GtkFileChooserDialog* _tmp16_;
	parent_class = G_OBJECT_CLASS (moserial_record_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialog);
	_tmp0_ = gtk_builder_new_from_resource (UIROOT "record_dialog.ui");
	builder = _tmp0_;
	_tmp1_ = builder;
	_tmp2_ = gtk_builder_get_object (_tmp1_, "record_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_, "record_cancel");
	_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_button_get_type (), GtkButton));
	_g_object_unref0 (self->priv->cancelButton);
	self->priv->cancelButton = _tmp6_;
	_tmp7_ = builder;
	_tmp8_ = gtk_builder_get_object (_tmp7_, "record_stream");
	_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, gtk_combo_box_get_type (), GtkComboBox));
	_g_object_unref0 (self->priv->streamCombo);
	self->priv->streamCombo = _tmp9_;
	_tmp10_ = self->priv->streamCombo;
	mo_utils_populateComboBox (_tmp10_, MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings, G_N_ELEMENTS (MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings));
	_tmp11_ = self->priv->streamCombo;
	gtk_combo_box_set_active (_tmp11_, (gint) MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_INCOMING);
	_tmp12_ = self->priv->dialog;
	g_signal_connect_object ((GtkWidget*) _tmp12_, "delete-event", (GCallback) _moserial_record_dialog_hide_gtk_widget_delete_event, self, 0);
	_tmp13_ = self->priv->dialog;
	g_signal_connect_object ((GtkDialog*) _tmp13_, "response", (GCallback) _moserial_record_dialog_response_gtk_dialog_response, self, 0);
	_tmp14_ = self->priv->dialog;
	gtk_dialog_add_buttons ((GtkDialog*) _tmp14_, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL, NULL);
	_tmp15_ = self->priv->dialog;
	gtk_file_chooser_set_do_overwrite_confirmation ((GtkFileChooser*) _tmp15_, TRUE);
	_tmp16_ = self->priv->dialog;
	gtk_file_chooser_set_local_only ((GtkFileChooser*) _tmp16_, FALSE);
	moserial_record_dialog_set_fileName (self, NULL);
	_g_object_unref0 (builder);
	return obj;
}


static void moserial_record_dialog_class_init (moserialRecordDialogClass * klass) {
	moserial_record_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (moserialRecordDialogPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_moserial_record_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_moserial_record_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = moserial_record_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = moserial_record_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY, moserial_record_dialog_properties[MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY] = g_param_spec_string ("fileName", "fileName", "fileName", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_START_RECORDING_SIGNAL] = g_signal_new ("start-recording", MOSERIAL_TYPE_RECORD_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_ENUM, G_TYPE_NONE, 2, G_TYPE_STRING, MOSERIAL_SERIAL_STREAM_RECORDER_TYPE_DIRECTION);
	moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_STOP_RECORDING_SIGNAL] = g_signal_new ("stop-recording", MOSERIAL_TYPE_RECORD_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void moserial_record_dialog_instance_init (moserialRecordDialog * self) {
	self->priv = MOSERIAL_RECORD_DIALOG_GET_PRIVATE (self);
}


static void moserial_record_dialog_finalize (GObject * obj) {
	moserialRecordDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialog);
	_g_object_unref0 (self->priv->dialog);
	_g_object_unref0 (self->priv->cancelButton);
	_g_object_unref0 (self->priv->streamCombo);
	_g_free0 (self->priv->_fileName);
	G_OBJECT_CLASS (moserial_record_dialog_parent_class)->finalize (obj);
}


GType moserial_record_dialog_get_type (void) {
	static volatile gsize moserial_record_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&moserial_record_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (moserialRecordDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) moserial_record_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (moserialRecordDialog), 0, (GInstanceInitFunc) moserial_record_dialog_instance_init, NULL };
		GType moserial_record_dialog_type_id;
		moserial_record_dialog_type_id = g_type_register_static (G_TYPE_OBJECT, "moserialRecordDialog", &g_define_type_info, 0);
		g_once_init_leave (&moserial_record_dialog_type_id__volatile, moserial_record_dialog_type_id);
	}
	return moserial_record_dialog_type_id__volatile;
}


static void _vala_moserial_record_dialog_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	moserialRecordDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialog);
	switch (property_id) {
		case MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY:
		g_value_set_string (value, moserial_record_dialog_get_fileName (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_moserial_record_dialog_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	moserialRecordDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, MOSERIAL_TYPE_RECORD_DIALOG, moserialRecordDialog);
	switch (property_id) {
		case MOSERIAL_RECORD_DIALOG_FILE_NAME_PROPERTY:
		moserial_record_dialog_set_fileName (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



