/* RecordDialog.c generated by valac 0.54.3, 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-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_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;
typedef enum  {
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_INCOMING,
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_OUTGOING,
	MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_BOTH
} moserialSerialStreamRecorderDirection;

#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};

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 gint moserialRecordDialog_private_offset;
static gpointer moserial_record_dialog_parent_class = NULL;

VALA_EXTERN GType moserial_record_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (moserialRecordDialog, g_object_unref)
VALA_EXTERN GType moserial_serial_stream_recorder_direction_get_type (void) G_GNUC_CONST ;
VALA_EXTERN moserialRecordDialog* moserial_record_dialog_new (GtkWindow* parent);
VALA_EXTERN moserialRecordDialog* moserial_record_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_record_dialog_hide (moserialRecordDialog* self);
static gboolean _moserial_record_dialog_hide_gtk_widget_delete_event (GtkWidget* _sender,
                                                               GdkEventAny* event,
                                                               gpointer self);
static void moserial_record_dialog_response (moserialRecordDialog* self,
                                      GtkWidget* w,
                                      gint r);
static void _moserial_record_dialog_response_gtk_dialog_response (GtkDialog* _sender,
                                                           gint response_id,
                                                           gpointer self);
static void moserial_record_dialog_set_fileName (moserialRecordDialog* self,
                                          const gchar* value);
VALA_EXTERN void moserial_record_dialog_show (moserialRecordDialog* self,
                                  const gchar* folder);
VALA_EXTERN gboolean mo_utils_fileExists (const gchar* path);
VALA_EXTERN const gchar* moserial_record_dialog_get_fileName (moserialRecordDialog* self);
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 void moserial_record_dialog_finalize (GObject * obj);
static GType moserial_record_dialog_get_type_once (void);
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);

VALA_EXTERN const gchar* MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings[3];

static inline gpointer
moserial_record_dialog_get_instance_private (moserialRecordDialog* self)
{
	return G_STRUCT_MEMBER_P (self, moserialRecordDialog_private_offset);
}

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);
}

moserialRecordDialog*
moserial_record_dialog_construct (GType object_type,
                                  GtkWindow* parent)
{
	moserialRecordDialog * self = NULL;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp0_;
	GObject* _tmp1_;
	GtkFileChooserDialog* _tmp2_;
	GtkFileChooserDialog* _tmp3_;
	GObject* _tmp4_;
	GtkButton* _tmp5_;
	GObject* _tmp6_;
	GtkComboBox* _tmp7_;
	GtkComboBox* _tmp8_;
	GtkComboBox* _tmp9_;
	GtkFileChooserDialog* _tmp10_;
	GtkFileChooserDialog* _tmp11_;
	GtkFileChooserDialog* _tmp12_;
	GtkFileChooserDialog* _tmp13_;
	GtkFileChooserDialog* _tmp14_;
	g_return_val_if_fail (parent != NULL, NULL);
	self = (moserialRecordDialog*) g_object_new (object_type, NULL);
	_tmp0_ = gtk_builder_new_from_resource (UIROOT "record_dialog.ui");
	builder = _tmp0_;
	_tmp1_ = gtk_builder_get_object (builder, "record_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, "record_cancel");
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_button_get_type (), GtkButton));
	_g_object_unref0 (self->priv->cancelButton);
	self->priv->cancelButton = _tmp5_;
	_tmp6_ = gtk_builder_get_object (builder, "record_stream");
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_combo_box_get_type (), GtkComboBox));
	_g_object_unref0 (self->priv->streamCombo);
	self->priv->streamCombo = _tmp7_;
	_tmp8_ = self->priv->streamCombo;
	mo_utils_populateComboBox (_tmp8_, MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings, (gint) G_N_ELEMENTS (MOSERIAL_SERIAL_STREAM_RECORDER_DirectionStrings), TRUE);
	_tmp9_ = self->priv->streamCombo;
	gtk_combo_box_set_active (_tmp9_, (gint) MOSERIAL_SERIAL_STREAM_RECORDER_DIRECTION_INCOMING);
	_tmp10_ = self->priv->dialog;
	g_signal_connect_object ((GtkWidget*) _tmp10_, "delete-event", (GCallback) _moserial_record_dialog_hide_gtk_widget_delete_event, self, 0);
	_tmp11_ = self->priv->dialog;
	g_signal_connect_object ((GtkDialog*) _tmp11_, "response", (GCallback) _moserial_record_dialog_response_gtk_dialog_response, self, 0);
	_tmp12_ = self->priv->dialog;
	gtk_dialog_add_buttons ((GtkDialog*) _tmp12_, "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-save", GTK_RESPONSE_ACCEPT, NULL, NULL);
	_tmp13_ = self->priv->dialog;
	gtk_file_chooser_set_do_overwrite_confirmation ((GtkFileChooser*) _tmp13_, TRUE);
	_tmp14_ = self->priv->dialog;
	gtk_file_chooser_set_local_only ((GtkFileChooser*) _tmp14_, FALSE);
	moserial_record_dialog_set_fileName (self, NULL);
	_g_object_unref0 (builder);
	return self;
}

moserialRecordDialog*
moserial_record_dialog_new (GtkWindow* parent)
{
	return moserial_record_dialog_construct (MOSERIAL_TYPE_RECORD_DIALOG, parent);
}

void
moserial_record_dialog_show (moserialRecordDialog* 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_record_dialog_hide (moserialRecordDialog* 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_record_dialog_response (moserialRecordDialog* self,
                                 GtkWidget* w,
                                 gint r)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (w != NULL);
	if (r == ((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 {
		if (r == ((gint) GTK_RESPONSE_ACCEPT)) {
			GtkFileChooserDialog* _tmp0_;
			gchar* _tmp1_;
			gchar* _tmp2_;
			GtkComboBox* _tmp3_;
			const gchar* _tmp4_;
			moserialSerialStreamRecorderDirection _tmp5_;
			_tmp0_ = self->priv->dialog;
			_tmp1_ = gtk_file_chooser_get_filename ((GtkFileChooser*) _tmp0_);
			_tmp2_ = _tmp1_;
			moserial_record_dialog_set_fileName (self, _tmp2_);
			_g_free0 (_tmp2_);
			_tmp3_ = self->priv->streamCombo;
			switch (gtk_combo_box_get_active (_tmp3_)) {
				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);
			_tmp4_ = self->priv->_fileName;
			_tmp5_ = self->direction;
			g_signal_emit (self, moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_START_RECORDING_SIGNAL], 0, _tmp4_, _tmp5_);
		} else {
			g_signal_emit (self, moserial_record_dialog_signals[MOSERIAL_RECORD_DIALOG_STOP_RECORDING_SIGNAL], 0);
		}
	}
}

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)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = moserial_record_dialog_get_fileName (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_fileName);
		self->priv->_fileName = _tmp0_;
		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 void
moserial_record_dialog_class_init (moserialRecordDialogClass * klass,
                                   gpointer klass_data)
{
	moserial_record_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &moserialRecordDialog_private_offset);
	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)->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_STRINGS | 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,
                                      gpointer klass)
{
	self->priv = moserial_record_dialog_get_instance_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);
}

static GType
moserial_record_dialog_get_type_once (void)
{
	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);
	moserialRecordDialog_private_offset = g_type_add_instance_private (moserial_record_dialog_type_id, sizeof (moserialRecordDialogPrivate));
	return moserial_record_dialog_type_id;
}

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)) {
		GType moserial_record_dialog_type_id;
		moserial_record_dialog_type_id = moserial_record_dialog_get_type_once ();
		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;
	}
}

