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

/*
 * This file is part of gitg
 *
 * Copyright (C) 2014 - Jesse van den Kieboom
 *
 * 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 "libgitg.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.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

enum  {
	GITG_AUTHENTICATION_DIALOG_0_PROPERTY,
	GITG_AUTHENTICATION_DIALOG_USERNAME_PROPERTY,
	GITG_AUTHENTICATION_DIALOG_PASSWORD_PROPERTY,
	GITG_AUTHENTICATION_DIALOG_LIFE_TIME_PROPERTY,
	GITG_AUTHENTICATION_DIALOG_NUM_PROPERTIES
};
static GParamSpec* gitg_authentication_dialog_properties[GITG_AUTHENTICATION_DIALOG_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GitgAuthenticationDialogPrivate {
	GtkLabel* d_label_title;
	GtkLabel* d_label_failed;
	GtkEntry* d_entry_username;
	GtkEntry* d_entry_password;
	GtkRadioButton* d_radio_button_forget;
	GtkRadioButton* d_radio_button_session;
	GtkRadioButton* d_radio_button_forever;
};

static gint GitgAuthenticationDialog_private_offset;
static gpointer gitg_authentication_dialog_parent_class = NULL;
static GitgAuthenticationLifeTime gitg_authentication_dialog_s_last_lifetime;
static GitgAuthenticationLifeTime gitg_authentication_dialog_s_last_lifetime = 0;

static void gitg_authentication_dialog_finalize (GObject * obj);
static GType gitg_authentication_dialog_get_type_once (void);
static void _vala_gitg_authentication_dialog_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);

 G_GNUC_NO_INLINE static GType
gitg_authentication_life_time_get_type_once (void)
{
	static const GEnumValue values[] = {{GITG_AUTHENTICATION_LIFE_TIME_FORGET, "GITG_AUTHENTICATION_LIFE_TIME_FORGET", "forget"}, {GITG_AUTHENTICATION_LIFE_TIME_SESSION, "GITG_AUTHENTICATION_LIFE_TIME_SESSION", "session"}, {GITG_AUTHENTICATION_LIFE_TIME_FOREVER, "GITG_AUTHENTICATION_LIFE_TIME_FOREVER", "forever"}, {0, NULL, NULL}};
	GType gitg_authentication_life_time_type_id;
	gitg_authentication_life_time_type_id = g_enum_register_static ("GitgAuthenticationLifeTime", values);
	return gitg_authentication_life_time_type_id;
}

GType
gitg_authentication_life_time_get_type (void)
{
	static gsize gitg_authentication_life_time_type_id__once = 0;
	if (g_once_init_enter (&gitg_authentication_life_time_type_id__once)) {
		GType gitg_authentication_life_time_type_id;
		gitg_authentication_life_time_type_id = gitg_authentication_life_time_get_type_once ();
		g_once_init_leave (&gitg_authentication_life_time_type_id__once, gitg_authentication_life_time_type_id);
	}
	return gitg_authentication_life_time_type_id__once;
}

static inline gpointer
gitg_authentication_dialog_get_instance_private (GitgAuthenticationDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GitgAuthenticationDialog_private_offset);
}

GitgAuthenticationDialog*
gitg_authentication_dialog_construct (GType object_type,
                                      const gchar* url,
                                      const gchar* username,
                                      gboolean failed)
{
	GitgAuthenticationDialog * self = NULL;
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GtkLabel* _tmp3_;
	g_return_val_if_fail (url != NULL, NULL);
	self = (GitgAuthenticationDialog*) g_object_new (object_type, "use-header-bar", 1, NULL);
	gtk_dialog_set_default_response ((GtkDialog*) self, (gint) GTK_RESPONSE_OK);
	_tmp0_ = self->priv->d_label_title;
	_tmp1_ = g_strdup_printf (_ ("Password required for %s"), url);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	_tmp3_ = self->priv->d_label_failed;
	gtk_widget_set_visible ((GtkWidget*) _tmp3_, failed);
	if (username != NULL) {
		GtkEntry* _tmp4_;
		GtkEntry* _tmp5_;
		_tmp4_ = self->priv->d_entry_username;
		gtk_entry_set_text (_tmp4_, username);
		_tmp5_ = self->priv->d_entry_password;
		gtk_widget_grab_focus ((GtkWidget*) _tmp5_);
	}
	switch (gitg_authentication_dialog_s_last_lifetime) {
		case GITG_AUTHENTICATION_LIFE_TIME_FORGET:
		{
			GtkRadioButton* _tmp6_;
			_tmp6_ = self->priv->d_radio_button_forget;
			gtk_toggle_button_set_active ((GtkToggleButton*) _tmp6_, TRUE);
			break;
		}
		case GITG_AUTHENTICATION_LIFE_TIME_SESSION:
		{
			GtkRadioButton* _tmp7_;
			_tmp7_ = self->priv->d_radio_button_session;
			gtk_toggle_button_set_active ((GtkToggleButton*) _tmp7_, TRUE);
			break;
		}
		case GITG_AUTHENTICATION_LIFE_TIME_FOREVER:
		{
			GtkRadioButton* _tmp8_;
			_tmp8_ = self->priv->d_radio_button_forever;
			gtk_toggle_button_set_active ((GtkToggleButton*) _tmp8_, TRUE);
			break;
		}
		default:
		break;
	}
	return self;
}

GitgAuthenticationDialog*
gitg_authentication_dialog_new (const gchar* url,
                                const gchar* username,
                                gboolean failed)
{
	return gitg_authentication_dialog_construct (GITG_TYPE_AUTHENTICATION_DIALOG, url, username, failed);
}

const gchar*
gitg_authentication_dialog_get_username (GitgAuthenticationDialog* self)
{
	const gchar* result;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->d_entry_username;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

const gchar*
gitg_authentication_dialog_get_password (GitgAuthenticationDialog* self)
{
	const gchar* result;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->d_entry_password;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

GitgAuthenticationLifeTime
gitg_authentication_dialog_get_life_time (GitgAuthenticationDialog* self)
{
	GitgAuthenticationLifeTime result;
	GtkRadioButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->d_radio_button_forget;
	_tmp1_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		result = GITG_AUTHENTICATION_LIFE_TIME_FORGET;
		return result;
	} else {
		GtkRadioButton* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp3_ = self->priv->d_radio_button_session;
		_tmp4_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp3_);
		_tmp5_ = _tmp4_;
		if (_tmp5_) {
			result = GITG_AUTHENTICATION_LIFE_TIME_SESSION;
			return result;
		} else {
			result = GITG_AUTHENTICATION_LIFE_TIME_FOREVER;
			return result;
		}
	}
}

static void
gitg_authentication_dialog_class_init (GitgAuthenticationDialogClass * klass,
                                       gpointer klass_data)
{
	gitg_authentication_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgAuthenticationDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gitg_authentication_dialog_get_property;
	G_OBJECT_CLASS (klass)->finalize = gitg_authentication_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_AUTHENTICATION_DIALOG_USERNAME_PROPERTY, gitg_authentication_dialog_properties[GITG_AUTHENTICATION_DIALOG_USERNAME_PROPERTY] = g_param_spec_string ("username", "username", "username", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_AUTHENTICATION_DIALOG_PASSWORD_PROPERTY, gitg_authentication_dialog_properties[GITG_AUTHENTICATION_DIALOG_PASSWORD_PROPERTY] = g_param_spec_string ("password", "password", "password", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_AUTHENTICATION_DIALOG_LIFE_TIME_PROPERTY, gitg_authentication_dialog_properties[GITG_AUTHENTICATION_DIALOG_LIFE_TIME_PROPERTY] = g_param_spec_enum ("life-time", "life-time", "life-time", GITG_TYPE_AUTHENTICATION_LIFE_TIME, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/gitg/ui/gitg-authentication-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label_title", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_label_title));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label_failed", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_label_failed));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "entry_username", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_entry_username));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "entry_password", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_entry_password));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "radio_button_forget", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_radio_button_forget));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "radio_button_session", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_radio_button_session));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "radio_button_forever", FALSE, GitgAuthenticationDialog_private_offset + G_STRUCT_OFFSET (GitgAuthenticationDialogPrivate, d_radio_button_forever));
	gitg_authentication_dialog_s_last_lifetime = GITG_AUTHENTICATION_LIFE_TIME_SESSION;
}

static void
gitg_authentication_dialog_instance_init (GitgAuthenticationDialog * self,
                                          gpointer klass)
{
	self->priv = gitg_authentication_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
gitg_authentication_dialog_finalize (GObject * obj)
{
	GitgAuthenticationDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_AUTHENTICATION_DIALOG, GitgAuthenticationDialog);
	G_OBJECT_CLASS (gitg_authentication_dialog_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_authentication_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgAuthenticationDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_authentication_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgAuthenticationDialog), 0, (GInstanceInitFunc) gitg_authentication_dialog_instance_init, NULL };
	GType gitg_authentication_dialog_type_id;
	gitg_authentication_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "GitgAuthenticationDialog", &g_define_type_info, 0);
	GitgAuthenticationDialog_private_offset = g_type_add_instance_private (gitg_authentication_dialog_type_id, sizeof (GitgAuthenticationDialogPrivate));
	return gitg_authentication_dialog_type_id;
}

GType
gitg_authentication_dialog_get_type (void)
{
	static gsize gitg_authentication_dialog_type_id__once = 0;
	if (g_once_init_enter (&gitg_authentication_dialog_type_id__once)) {
		GType gitg_authentication_dialog_type_id;
		gitg_authentication_dialog_type_id = gitg_authentication_dialog_get_type_once ();
		g_once_init_leave (&gitg_authentication_dialog_type_id__once, gitg_authentication_dialog_type_id);
	}
	return gitg_authentication_dialog_type_id__once;
}

static void
_vala_gitg_authentication_dialog_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	GitgAuthenticationDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_AUTHENTICATION_DIALOG, GitgAuthenticationDialog);
	switch (property_id) {
		case GITG_AUTHENTICATION_DIALOG_USERNAME_PROPERTY:
		g_value_set_string (value, gitg_authentication_dialog_get_username (self));
		break;
		case GITG_AUTHENTICATION_DIALOG_PASSWORD_PROPERTY:
		g_value_set_string (value, gitg_authentication_dialog_get_password (self));
		break;
		case GITG_AUTHENTICATION_DIALOG_LIFE_TIME_PROPERTY:
		g_value_set_enum (value, gitg_authentication_dialog_get_life_time (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

