/* gkr-password-entry.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from gkr-password-entry.vala, do not modify */

/*
 * Seahorse
 *
 * Copyright (C) 2018 Niels De Graef
 *
 * 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 2 of the License, or
 * (at your option) 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 "seahorse-gkr.h"
#include <glib.h>
#include <glib-object.h>
#include <ui/gcr-ui.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.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

enum  {
	SEAHORSE_GKR_PASSWORD_ENTRY_0_PROPERTY,
	SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY,
	SEAHORSE_GKR_PASSWORD_ENTRY_NUM_PROPERTIES
};
static GParamSpec* seahorse_gkr_password_entry_properties[SEAHORSE_GKR_PASSWORD_ENTRY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SeahorseGkrPasswordEntryPrivate {
	gboolean _has_changed;
};

static gint SeahorseGkrPasswordEntry_private_offset;
static gpointer seahorse_gkr_password_entry_parent_class = NULL;

static void __lambda4_ (SeahorseGkrPasswordEntry* self,
                 GtkEntryIconPosition pos,
                 GdkEvent* event);
static void ___lambda4__gtk_entry_icon_press (GtkEntry* _sender,
                                       GtkEntryIconPosition icon_pos,
                                       GdkEvent* event,
                                       gpointer self);
static void __lambda5_ (SeahorseGkrPasswordEntry* self);
static void ___lambda5__gtk_editable_changed (GtkEditable* _sender,
                                       gpointer self);
static void seahorse_gkr_password_entry_finalize (GObject * obj);
static GType seahorse_gkr_password_entry_get_type_once (void);
static void _vala_seahorse_gkr_password_entry_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_seahorse_gkr_password_entry_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);

static inline gpointer
seahorse_gkr_password_entry_get_instance_private (SeahorseGkrPasswordEntry* self)
{
	return G_STRUCT_MEMBER_P (self, SeahorseGkrPasswordEntry_private_offset);
}

static void
__lambda4_ (SeahorseGkrPasswordEntry* self,
            GtkEntryIconPosition pos,
            GdkEvent* event)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (event != NULL);
	_tmp0_ = gtk_entry_get_visibility ((GtkEntry*) self);
	_tmp1_ = _tmp0_;
	gtk_entry_set_visibility ((GtkEntry*) self, !_tmp1_);
}

static void
___lambda4__gtk_entry_icon_press (GtkEntry* _sender,
                                  GtkEntryIconPosition icon_pos,
                                  GdkEvent* event,
                                  gpointer self)
{
	__lambda4_ ((SeahorseGkrPasswordEntry*) self, icon_pos, event);
}

static void
__lambda5_ (SeahorseGkrPasswordEntry* self)
{
	seahorse_gkr_password_entry_set_has_changed (self, TRUE);
}

static void
___lambda5__gtk_editable_changed (GtkEditable* _sender,
                                  gpointer self)
{
	__lambda5_ ((SeahorseGkrPasswordEntry*) self);
}

SeahorseGkrPasswordEntry*
seahorse_gkr_password_entry_construct (GType object_type)
{
	SeahorseGkrPasswordEntry * self = NULL;
	GcrSecureEntryBuffer* _tmp0_;
	GcrSecureEntryBuffer* _tmp1_;
	_tmp0_ = (GcrSecureEntryBuffer*) gcr_secure_entry_buffer_new ();
	_tmp1_ = _tmp0_;
	self = (SeahorseGkrPasswordEntry*) g_object_new (object_type, "buffer", _tmp1_, "visibility", FALSE, "visible", TRUE, "hexpand", TRUE, "secondary-icon-name", "dialog-password-symbolic", "secondary-icon-tooltip-text", _ ("Show/Hide password"), "secondary-icon-sensitive", TRUE, NULL);
	_g_object_unref0 (_tmp1_);
	g_signal_connect_object ((GtkEntry*) self, "icon-press", (GCallback) ___lambda4__gtk_entry_icon_press, self, 0);
	g_signal_connect_object ((GtkEditable*) self, "changed", (GCallback) ___lambda5__gtk_editable_changed, self, 0);
	return self;
}

SeahorseGkrPasswordEntry*
seahorse_gkr_password_entry_new (void)
{
	return seahorse_gkr_password_entry_construct (SEAHORSE_GKR_TYPE_PASSWORD_ENTRY);
}

void
seahorse_gkr_password_entry_set_initial_password (SeahorseGkrPasswordEntry* self,
                                                  const gchar* password)
{
	g_return_if_fail (self != NULL);
	gtk_entry_set_text ((GtkEntry*) self, password);
	seahorse_gkr_password_entry_set_has_changed (self, FALSE);
}

gboolean
seahorse_gkr_password_entry_get_has_changed (SeahorseGkrPasswordEntry* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_has_changed;
	return result;
}

void
seahorse_gkr_password_entry_set_has_changed (SeahorseGkrPasswordEntry* self,
                                             gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = seahorse_gkr_password_entry_get_has_changed (self);
	if (old_value != value) {
		self->priv->_has_changed = value;
		g_object_notify_by_pspec ((GObject *) self, seahorse_gkr_password_entry_properties[SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY]);
	}
}

static void
seahorse_gkr_password_entry_class_init (SeahorseGkrPasswordEntryClass * klass,
                                        gpointer klass_data)
{
	seahorse_gkr_password_entry_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SeahorseGkrPasswordEntry_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_seahorse_gkr_password_entry_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_seahorse_gkr_password_entry_set_property;
	G_OBJECT_CLASS (klass)->finalize = seahorse_gkr_password_entry_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY, seahorse_gkr_password_entry_properties[SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY] = g_param_spec_boolean ("has-changed", "has-changed", "has-changed", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
seahorse_gkr_password_entry_instance_init (SeahorseGkrPasswordEntry * self,
                                           gpointer klass)
{
	self->priv = seahorse_gkr_password_entry_get_instance_private (self);
	self->priv->_has_changed = FALSE;
}

static void
seahorse_gkr_password_entry_finalize (GObject * obj)
{
	SeahorseGkrPasswordEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_GKR_TYPE_PASSWORD_ENTRY, SeahorseGkrPasswordEntry);
	G_OBJECT_CLASS (seahorse_gkr_password_entry_parent_class)->finalize (obj);
}

/**
 * An entry specifically for password: the buffer is saved in a
 * {@link Gcr.SecureEntryBuffer}, a secondary icon allows the user to hide or
 * show the password.
 */
 G_GNUC_NO_INLINE static GType
seahorse_gkr_password_entry_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseGkrPasswordEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_gkr_password_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseGkrPasswordEntry), 0, (GInstanceInitFunc) seahorse_gkr_password_entry_instance_init, NULL };
	GType seahorse_gkr_password_entry_type_id;
	seahorse_gkr_password_entry_type_id = g_type_register_static (gtk_entry_get_type (), "SeahorseGkrPasswordEntry", &g_define_type_info, 0);
	SeahorseGkrPasswordEntry_private_offset = g_type_add_instance_private (seahorse_gkr_password_entry_type_id, sizeof (SeahorseGkrPasswordEntryPrivate));
	return seahorse_gkr_password_entry_type_id;
}

GType
seahorse_gkr_password_entry_get_type (void)
{
	static volatile gsize seahorse_gkr_password_entry_type_id__once = 0;
	if (g_once_init_enter (&seahorse_gkr_password_entry_type_id__once)) {
		GType seahorse_gkr_password_entry_type_id;
		seahorse_gkr_password_entry_type_id = seahorse_gkr_password_entry_get_type_once ();
		g_once_init_leave (&seahorse_gkr_password_entry_type_id__once, seahorse_gkr_password_entry_type_id);
	}
	return seahorse_gkr_password_entry_type_id__once;
}

static void
_vala_seahorse_gkr_password_entry_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	SeahorseGkrPasswordEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SEAHORSE_GKR_TYPE_PASSWORD_ENTRY, SeahorseGkrPasswordEntry);
	switch (property_id) {
		case SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY:
		g_value_set_boolean (value, seahorse_gkr_password_entry_get_has_changed (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_seahorse_gkr_password_entry_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	SeahorseGkrPasswordEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SEAHORSE_GKR_TYPE_PASSWORD_ENTRY, SeahorseGkrPasswordEntry);
	switch (property_id) {
		case SEAHORSE_GKR_PASSWORD_ENTRY_HAS_CHANGED_PROPERTY:
		seahorse_gkr_password_entry_set_has_changed (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

