/* gitg-edit-remote-dialog.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-edit-remote-dialog.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2022 - Adwait Rawat
 *
 * gitg 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 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#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 GITG_TYPE_EDIT_REMOTE_DIALOG (gitg_edit_remote_dialog_get_type ())
#define GITG_EDIT_REMOTE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialog))
#define GITG_EDIT_REMOTE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialogClass))
#define GITG_IS_EDIT_REMOTE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_EDIT_REMOTE_DIALOG))
#define GITG_IS_EDIT_REMOTE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_EDIT_REMOTE_DIALOG))
#define GITG_EDIT_REMOTE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialogClass))

typedef struct _GitgEditRemoteDialog GitgEditRemoteDialog;
typedef struct _GitgEditRemoteDialogClass GitgEditRemoteDialogClass;
typedef struct _GitgEditRemoteDialogPrivate GitgEditRemoteDialogPrivate;
enum  {
	GITG_EDIT_REMOTE_DIALOG_0_PROPERTY,
	GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY,
	GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY,
	GITG_EDIT_REMOTE_DIALOG_NUM_PROPERTIES
};
static GParamSpec* gitg_edit_remote_dialog_properties[GITG_EDIT_REMOTE_DIALOG_NUM_PROPERTIES];
typedef struct _Block53Data Block53Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GitgEditRemoteDialog {
	GtkDialog parent_instance;
	GitgEditRemoteDialogPrivate * priv;
};

struct _GitgEditRemoteDialogClass {
	GtkDialogClass parent_class;
};

struct _GitgEditRemoteDialogPrivate {
	GtkButton* d_button_save;
	GtkEntry* d_entry_remote_name;
	GtkEntry* d_entry_remote_url;
};

struct _Block53Data {
	int _ref_count_;
	GitgEditRemoteDialog* self;
	gboolean is_name_valid;
};

static gint GitgEditRemoteDialog_private_offset;
static gpointer gitg_edit_remote_dialog_parent_class = NULL;

VALA_EXTERN GType gitg_edit_remote_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgEditRemoteDialog, g_object_unref)
VALA_EXTERN GitgEditRemoteDialog* gitg_edit_remote_dialog_new (GtkWindow* parent);
VALA_EXTERN GitgEditRemoteDialog* gitg_edit_remote_dialog_construct (GType object_type,
                                                         GtkWindow* parent);
VALA_EXTERN gchar* gitg_edit_remote_dialog_get_new_remote_name (GitgEditRemoteDialog* self);
VALA_EXTERN void gitg_edit_remote_dialog_set_new_remote_name (GitgEditRemoteDialog* self,
                                                  const gchar* value);
VALA_EXTERN gchar* gitg_edit_remote_dialog_get_new_remote_url (GitgEditRemoteDialog* self);
VALA_EXTERN void gitg_edit_remote_dialog_set_new_remote_url (GitgEditRemoteDialog* self,
                                                 const gchar* value);
static GObject * gitg_edit_remote_dialog_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void _gitg_edit_remote_dialog___lambda99_ (GitgEditRemoteDialog* self);
static Block53Data* block53_data_ref (Block53Data* _data53_);
static void block53_data_unref (void * _userdata_);
static void __lambda100_ (Block53Data* _data53_,
                   GtkEditable* e);
static void ___lambda100__gtk_editable_changed (GtkEditable* _sender,
                                         gpointer self);
static void __gitg_edit_remote_dialog___lambda99__gtk_editable_changed (GtkEditable* _sender,
                                                                 gpointer self);
static void gitg_edit_remote_dialog_finalize (GObject * obj);
static GType gitg_edit_remote_dialog_get_type_once (void);
static void _vala_gitg_edit_remote_dialog_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_gitg_edit_remote_dialog_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);

static inline gpointer
gitg_edit_remote_dialog_get_instance_private (GitgEditRemoteDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GitgEditRemoteDialog_private_offset);
}

GitgEditRemoteDialog*
gitg_edit_remote_dialog_construct (GType object_type,
                                   GtkWindow* parent)
{
	GitgEditRemoteDialog * self = NULL;
	self = (GitgEditRemoteDialog*) g_object_new (object_type, "use-header-bar", 1, NULL);
	if (parent != NULL) {
		gtk_window_set_transient_for ((GtkWindow*) self, parent);
	}
	return self;
}

GitgEditRemoteDialog*
gitg_edit_remote_dialog_new (GtkWindow* parent)
{
	return gitg_edit_remote_dialog_construct (GITG_TYPE_EDIT_REMOTE_DIALOG, parent);
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

gchar*
gitg_edit_remote_dialog_get_new_remote_name (GitgEditRemoteDialog* self)
{
	gchar* result;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->d_entry_remote_name;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	result = _tmp3_;
	return result;
}

void
gitg_edit_remote_dialog_set_new_remote_name (GitgEditRemoteDialog* self,
                                             const gchar* value)
{
	GtkEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->d_entry_remote_name;
	gtk_entry_set_text (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, gitg_edit_remote_dialog_properties[GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY]);
}

gchar*
gitg_edit_remote_dialog_get_new_remote_url (GitgEditRemoteDialog* self)
{
	gchar* result;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->d_entry_remote_url;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	result = _tmp3_;
	return result;
}

void
gitg_edit_remote_dialog_set_new_remote_url (GitgEditRemoteDialog* self,
                                            const gchar* value)
{
	GtkEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->d_entry_remote_url;
	gtk_entry_set_text (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, gitg_edit_remote_dialog_properties[GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY]);
}

static Block53Data*
block53_data_ref (Block53Data* _data53_)
{
	g_atomic_int_inc (&_data53_->_ref_count_);
	return _data53_;
}

static void
block53_data_unref (void * _userdata_)
{
	Block53Data* _data53_;
	_data53_ = (Block53Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data53_->_ref_count_)) {
		GitgEditRemoteDialog* self;
		self = _data53_->self;
		_g_object_unref0 (self);
		g_slice_free (Block53Data, _data53_);
	}
}

static void
__lambda100_ (Block53Data* _data53_,
              GtkEditable* e)
{
	GitgEditRemoteDialog* self;
	gboolean is_url_valid = FALSE;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean _tmp3_ = FALSE;
	self = _data53_->self;
	g_return_if_fail (e != NULL);
	_tmp0_ = self->priv->d_entry_remote_url;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	is_url_valid = g_strcmp0 (_tmp2_, "") != 0;
	if (_data53_->is_name_valid) {
		_tmp3_ = is_url_valid;
	} else {
		_tmp3_ = FALSE;
	}
	gtk_dialog_set_response_sensitive ((GtkDialog*) self, (gint) GTK_RESPONSE_OK, _tmp3_);
}

static void
___lambda100__gtk_editable_changed (GtkEditable* _sender,
                                    gpointer self)
{
	__lambda100_ (self, _sender);
}

static void
_gitg_edit_remote_dialog___lambda99_ (GitgEditRemoteDialog* self)
{
	Block53Data* _data53_;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GtkEntry* _tmp3_;
	_data53_ = g_slice_new0 (Block53Data);
	_data53_->_ref_count_ = 1;
	_data53_->self = g_object_ref (self);
	_tmp0_ = self->priv->d_entry_remote_name;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_data53_->is_name_valid = g_strcmp0 (_tmp2_, "") != 0;
	_tmp3_ = self->priv->d_entry_remote_url;
	g_signal_connect_data ((GtkEditable*) _tmp3_, "changed", (GCallback) ___lambda100__gtk_editable_changed, block53_data_ref (_data53_), (GClosureNotify) block53_data_unref, 0);
	block53_data_unref (_data53_);
	_data53_ = NULL;
}

static void
__gitg_edit_remote_dialog___lambda99__gtk_editable_changed (GtkEditable* _sender,
                                                            gpointer self)
{
	_gitg_edit_remote_dialog___lambda99_ ((GitgEditRemoteDialog*) self);
}

static GObject *
gitg_edit_remote_dialog_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GitgEditRemoteDialog * self;
	GtkEntry* _tmp0_;
	GtkButton* _tmp1_;
	parent_class = G_OBJECT_CLASS (gitg_edit_remote_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialog);
	_tmp0_ = self->priv->d_entry_remote_name;
	g_signal_connect_object ((GtkEditable*) _tmp0_, "changed", (GCallback) __gitg_edit_remote_dialog___lambda99__gtk_editable_changed, self, 0);
	_tmp1_ = self->priv->d_button_save;
	gtk_window_set_default ((GtkWindow*) self, (GtkWidget*) _tmp1_);
	gtk_dialog_set_default_response ((GtkDialog*) self, (gint) GTK_RESPONSE_OK);
	return obj;
}

static void
gitg_edit_remote_dialog_class_init (GitgEditRemoteDialogClass * klass,
                                    gpointer klass_data)
{
	gitg_edit_remote_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgEditRemoteDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gitg_edit_remote_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gitg_edit_remote_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = gitg_edit_remote_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = gitg_edit_remote_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY, gitg_edit_remote_dialog_properties[GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY] = g_param_spec_string ("new-remote-name", "new-remote-name", "new-remote-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY, gitg_edit_remote_dialog_properties[GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY] = g_param_spec_string ("new-remote-url", "new-remote-url", "new-remote-url", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/gitg/ui/gitg-edit-remote-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_button_save", FALSE, GitgEditRemoteDialog_private_offset + G_STRUCT_OFFSET (GitgEditRemoteDialogPrivate, d_button_save));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_entry_remote_name", FALSE, GitgEditRemoteDialog_private_offset + G_STRUCT_OFFSET (GitgEditRemoteDialogPrivate, d_entry_remote_name));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "d_entry_remote_url", FALSE, GitgEditRemoteDialog_private_offset + G_STRUCT_OFFSET (GitgEditRemoteDialogPrivate, d_entry_remote_url));
}

static void
gitg_edit_remote_dialog_instance_init (GitgEditRemoteDialog * self,
                                       gpointer klass)
{
	self->priv = gitg_edit_remote_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
gitg_edit_remote_dialog_finalize (GObject * obj)
{
	GitgEditRemoteDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialog);
	G_OBJECT_CLASS (gitg_edit_remote_dialog_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_edit_remote_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgEditRemoteDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_edit_remote_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgEditRemoteDialog), 0, (GInstanceInitFunc) gitg_edit_remote_dialog_instance_init, NULL };
	GType gitg_edit_remote_dialog_type_id;
	gitg_edit_remote_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "GitgEditRemoteDialog", &g_define_type_info, 0);
	GitgEditRemoteDialog_private_offset = g_type_add_instance_private (gitg_edit_remote_dialog_type_id, sizeof (GitgEditRemoteDialogPrivate));
	return gitg_edit_remote_dialog_type_id;
}

GType
gitg_edit_remote_dialog_get_type (void)
{
	static gsize gitg_edit_remote_dialog_type_id__once = 0;
	if (g_once_init_enter (&gitg_edit_remote_dialog_type_id__once)) {
		GType gitg_edit_remote_dialog_type_id;
		gitg_edit_remote_dialog_type_id = gitg_edit_remote_dialog_get_type_once ();
		g_once_init_leave (&gitg_edit_remote_dialog_type_id__once, gitg_edit_remote_dialog_type_id);
	}
	return gitg_edit_remote_dialog_type_id__once;
}

static void
_vala_gitg_edit_remote_dialog_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	GitgEditRemoteDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialog);
	switch (property_id) {
		case GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY:
		g_value_take_string (value, gitg_edit_remote_dialog_get_new_remote_name (self));
		break;
		case GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY:
		g_value_take_string (value, gitg_edit_remote_dialog_get_new_remote_url (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gitg_edit_remote_dialog_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	GitgEditRemoteDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_EDIT_REMOTE_DIALOG, GitgEditRemoteDialog);
	switch (property_id) {
		case GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_NAME_PROPERTY:
		gitg_edit_remote_dialog_set_new_remote_name (self, g_value_get_string (value));
		break;
		case GITG_EDIT_REMOTE_DIALOG_NEW_REMOTE_URL_PROPERTY:
		gitg_edit_remote_dialog_set_new_remote_url (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

