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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2011 ~ 2018 Deepin, Inc.
 *               2011 ~ 2018 Wang Yong
 *
 * Author:     Wang Yong <wangyong@deepin.com>
 * Maintainer: Wang Yong <wangyong@deepin.com>
 *
 * This program 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
 * any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

#define GETTEXT_PACKAGE "deepin-terminal-gtk"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#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 WIDGETS_TYPE_FILE_BUTTON (widgets_file_button_get_type ())
#define WIDGETS_FILE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_FILE_BUTTON, WidgetsFileButton))
#define WIDGETS_FILE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_FILE_BUTTON, WidgetsFileButtonClass))
#define WIDGETS_IS_FILE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_FILE_BUTTON))
#define WIDGETS_IS_FILE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_FILE_BUTTON))
#define WIDGETS_FILE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_FILE_BUTTON, WidgetsFileButtonClass))

typedef struct _WidgetsFileButton WidgetsFileButton;
typedef struct _WidgetsFileButtonClass WidgetsFileButtonClass;
typedef struct _WidgetsFileButtonPrivate WidgetsFileButtonPrivate;

#define WIDGETS_TYPE_CLICK_EVENT_BOX (widgets_click_event_box_get_type ())
#define WIDGETS_CLICK_EVENT_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBox))
#define WIDGETS_CLICK_EVENT_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBoxClass))
#define WIDGETS_IS_CLICK_EVENT_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX))
#define WIDGETS_IS_CLICK_EVENT_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_CLICK_EVENT_BOX))
#define WIDGETS_CLICK_EVENT_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_CLICK_EVENT_BOX, WidgetsClickEventBoxClass))

typedef struct _WidgetsClickEventBox WidgetsClickEventBox;
typedef struct _WidgetsClickEventBoxClass WidgetsClickEventBoxClass;

#define WIDGETS_TYPE_IMAGE_BUTTON (widgets_image_button_get_type ())
#define WIDGETS_IMAGE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_IMAGE_BUTTON, WidgetsImageButton))
#define WIDGETS_IMAGE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_IMAGE_BUTTON, WidgetsImageButtonClass))
#define WIDGETS_IS_IMAGE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_IMAGE_BUTTON))
#define WIDGETS_IS_IMAGE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_IMAGE_BUTTON))
#define WIDGETS_IMAGE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_IMAGE_BUTTON, WidgetsImageButtonClass))

typedef struct _WidgetsImageButton WidgetsImageButton;
typedef struct _WidgetsImageButtonClass WidgetsImageButtonClass;

#define WIDGETS_TYPE_ENTRY (widgets_entry_get_type ())
#define WIDGETS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_ENTRY, WidgetsEntry))
#define WIDGETS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_ENTRY, WidgetsEntryClass))
#define WIDGETS_IS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_ENTRY))
#define WIDGETS_IS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_ENTRY))
#define WIDGETS_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_ENTRY, WidgetsEntryClass))

typedef struct _WidgetsEntry WidgetsEntry;
typedef struct _WidgetsEntryClass WidgetsEntryClass;
enum  {
	WIDGETS_FILE_BUTTON_0_PROPERTY,
	WIDGETS_FILE_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_file_button_properties[WIDGETS_FILE_BUTTON_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))

struct _WidgetsFileButton {
	GtkEventBox parent_instance;
	WidgetsFileButtonPrivate * priv;
	GtkBox* box;
	GtkBox* button_box;
	WidgetsImageButton* file_add_button;
	WidgetsEntry* entry;
	gint height;
};

struct _WidgetsFileButtonClass {
	GtkEventBoxClass parent_class;
};

static gpointer widgets_file_button_parent_class = NULL;

VALA_EXTERN GType widgets_file_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsFileButton, g_object_unref)
VALA_EXTERN GType widgets_click_event_box_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsClickEventBox, g_object_unref)
VALA_EXTERN GType widgets_image_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsImageButton, g_object_unref)
VALA_EXTERN GType widgets_entry_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsEntry, g_object_unref)
VALA_EXTERN WidgetsFileButton* widgets_file_button_new (void);
VALA_EXTERN WidgetsFileButton* widgets_file_button_construct (GType object_type);
VALA_EXTERN WidgetsEntry* widgets_entry_new (void);
VALA_EXTERN WidgetsEntry* widgets_entry_construct (GType object_type);
VALA_EXTERN WidgetsImageButton* widgets_image_button_new (const gchar* image_path,
                                              gboolean theme_button,
                                              const gchar* text,
                                              gint text_size);
VALA_EXTERN WidgetsImageButton* widgets_image_button_construct (GType object_type,
                                                    const gchar* image_path,
                                                    gboolean theme_button,
                                                    const gchar* text,
                                                    gint text_size);
static void __lambda43_ (WidgetsFileButton* self,
                  WidgetsClickEventBox* w,
                  GdkEventButton* e);
VALA_EXTERN void widgets_file_button_select_private_key_file (WidgetsFileButton* self);
static void ___lambda43__widgets_click_event_box_clicked (WidgetsClickEventBox* _sender,
                                                   GdkEventButton* event,
                                                   gpointer self);
static void widgets_file_button_finalize (GObject * obj);
static GType widgets_file_button_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
__lambda43_ (WidgetsFileButton* self,
             WidgetsClickEventBox* w,
             GdkEventButton* e)
{
	g_return_if_fail (w != NULL);
	g_return_if_fail (e != NULL);
	widgets_file_button_select_private_key_file (self);
}

static void
___lambda43__widgets_click_event_box_clicked (WidgetsClickEventBox* _sender,
                                              GdkEventButton* event,
                                              gpointer self)
{
	__lambda43_ ((WidgetsFileButton*) self, _sender, event);
}

WidgetsFileButton*
widgets_file_button_construct (GType object_type)
{
	WidgetsFileButton * self = NULL;
	GtkBox* _tmp0_;
	WidgetsEntry* _tmp1_;
	WidgetsEntry* _tmp2_;
	WidgetsEntry* _tmp3_;
	WidgetsImageButton* _tmp4_;
	GtkBox* _tmp5_;
	GtkBox* _tmp6_;
	WidgetsEntry* _tmp7_;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	WidgetsEntry* _tmp10_;
	GtkStyleContext* _tmp11_;
	GtkBox* _tmp12_;
	WidgetsImageButton* _tmp13_;
	WidgetsImageButton* _tmp14_;
	GtkBox* _tmp15_;
	self = (WidgetsFileButton*) g_object_new (object_type, NULL);
	bindtextdomain (GETTEXT_PACKAGE, "/usr/share/locale");
	gtk_event_box_set_visible_window ((GtkEventBox*) self, FALSE);
	gtk_widget_set_size_request ((GtkWidget*) self, -1, self->height);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->box);
	self->box = _tmp0_;
	_tmp1_ = widgets_entry_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->entry);
	self->entry = _tmp1_;
	_tmp2_ = self->entry;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp2_, 1);
	_tmp3_ = self->entry;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp3_, 1);
	_tmp4_ = widgets_image_button_new ("file_add", FALSE, NULL, 12);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->file_add_button);
	self->file_add_button = _tmp4_;
	_tmp5_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->button_box);
	self->button_box = _tmp5_;
	_tmp6_ = self->box;
	_tmp7_ = self->entry;
	gtk_box_pack_start (_tmp6_, (GtkWidget*) _tmp7_, TRUE, TRUE, (guint) 0);
	_tmp8_ = self->box;
	_tmp9_ = self->button_box;
	gtk_box_pack_start (_tmp8_, (GtkWidget*) _tmp9_, FALSE, FALSE, (guint) 0);
	_tmp10_ = self->entry;
	_tmp11_ = gtk_widget_get_style_context ((GtkWidget*) _tmp10_);
	gtk_style_context_add_class (_tmp11_, "file_add_entry");
	_tmp12_ = self->button_box;
	_tmp13_ = self->file_add_button;
	gtk_box_pack_start (_tmp12_, (GtkWidget*) _tmp13_, FALSE, FALSE, (guint) 0);
	_tmp14_ = self->file_add_button;
	g_signal_connect_object ((WidgetsClickEventBox*) _tmp14_, "clicked", (GCallback) ___lambda43__widgets_click_event_box_clicked, self, 0);
	_tmp15_ = self->box;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp15_);
	return self;
}

WidgetsFileButton*
widgets_file_button_new (void)
{
	return widgets_file_button_construct (WIDGETS_TYPE_FILE_BUTTON);
}

void
widgets_file_button_select_private_key_file (WidgetsFileButton* self)
{
	GtkFileChooserAction action = 0;
	GtkFileChooserDialog* chooser = NULL;
	GtkWidget* _tmp0_;
	GtkFileChooserDialog* _tmp1_;
	GtkFileChooserDialog* _tmp2_;
	GtkFileChooserDialog* _tmp3_;
	GtkFileChooserDialog* _tmp4_;
	GtkFileChooserDialog* _tmp5_;
	GtkFileChooserDialog* _tmp12_;
	g_return_if_fail (self != NULL);
	action = GTK_FILE_CHOOSER_ACTION_OPEN;
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp1_ = (GtkFileChooserDialog*) gtk_file_chooser_dialog_new (_ ("Select the private key file"), G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp0_) : NULL, action, NULL);
	g_object_ref_sink (_tmp1_);
	chooser = _tmp1_;
	_tmp2_ = chooser;
	gtk_dialog_add_button ((GtkDialog*) _tmp2_, _ ("Cancel"), (gint) GTK_RESPONSE_CANCEL);
	_tmp3_ = chooser;
	gtk_file_chooser_set_select_multiple ((GtkFileChooser*) _tmp3_, TRUE);
	_tmp4_ = chooser;
	gtk_dialog_add_button ((GtkDialog*) _tmp4_, _ ("Select"), (gint) GTK_RESPONSE_ACCEPT);
	_tmp5_ = chooser;
	if (gtk_dialog_run ((GtkDialog*) _tmp5_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		WidgetsEntry* _tmp6_;
		GtkFileChooserDialog* _tmp7_;
		GFile* _tmp8_;
		GFile* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp6_ = self->entry;
		_tmp7_ = chooser;
		_tmp8_ = gtk_file_chooser_get_file ((GtkFileChooser*) _tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_file_get_path (_tmp9_);
		_tmp11_ = _tmp10_;
		gtk_entry_set_text ((GtkEntry*) _tmp6_, _tmp11_);
		_g_free0 (_tmp11_);
		_g_object_unref0 (_tmp9_);
	}
	_tmp12_ = chooser;
	gtk_widget_destroy ((GtkWidget*) _tmp12_);
	_g_object_unref0 (chooser);
}

static void
widgets_file_button_class_init (WidgetsFileButtonClass * klass,
                                gpointer klass_data)
{
	widgets_file_button_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = widgets_file_button_finalize;
}

static void
widgets_file_button_instance_init (WidgetsFileButton * self,
                                   gpointer klass)
{
	self->height = 26;
}

static void
widgets_file_button_finalize (GObject * obj)
{
	WidgetsFileButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_FILE_BUTTON, WidgetsFileButton);
	_g_object_unref0 (self->box);
	_g_object_unref0 (self->button_box);
	_g_object_unref0 (self->file_add_button);
	_g_object_unref0 (self->entry);
	G_OBJECT_CLASS (widgets_file_button_parent_class)->finalize (obj);
}

static GType
widgets_file_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsFileButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_file_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsFileButton), 0, (GInstanceInitFunc) widgets_file_button_instance_init, NULL };
	GType widgets_file_button_type_id;
	widgets_file_button_type_id = g_type_register_static (gtk_event_box_get_type (), "WidgetsFileButton", &g_define_type_info, 0);
	return widgets_file_button_type_id;
}

GType
widgets_file_button_get_type (void)
{
	static volatile gsize widgets_file_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_file_button_type_id__once)) {
		GType widgets_file_button_type_id;
		widgets_file_button_type_id = widgets_file_button_get_type_once ();
		g_once_init_leave (&widgets_file_button_type_id__once, widgets_file_button_type_id);
	}
	return widgets_file_button_type_id__once;
}

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

