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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include <adwaita.h>
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "deja.h"
#include <gio/gio.h>
#include <stdlib.h>
#include <string.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
#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 TYPE_SWITCH_ROW (switch_row_get_type ())
#define SWITCH_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SWITCH_ROW, SwitchRow))
#define SWITCH_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SWITCH_ROW, SwitchRowClass))
#define IS_SWITCH_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SWITCH_ROW))
#define IS_SWITCH_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SWITCH_ROW))
#define SWITCH_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SWITCH_ROW, SwitchRowClass))

typedef struct _SwitchRow SwitchRow;
typedef struct _SwitchRowClass SwitchRowClass;
typedef struct _SwitchRowPrivate SwitchRowPrivate;

#define TYPE_SAVE_PASSWORD_ROW (save_password_row_get_type ())
#define SAVE_PASSWORD_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SAVE_PASSWORD_ROW, SavePasswordRow))
#define SAVE_PASSWORD_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SAVE_PASSWORD_ROW, SavePasswordRowClass))
#define IS_SAVE_PASSWORD_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SAVE_PASSWORD_ROW))
#define IS_SAVE_PASSWORD_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SAVE_PASSWORD_ROW))
#define SAVE_PASSWORD_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SAVE_PASSWORD_ROW, SavePasswordRowClass))

typedef struct _SavePasswordRow SavePasswordRow;
typedef struct _SavePasswordRowClass SavePasswordRowClass;
typedef struct _SavePasswordRowPrivate SavePasswordRowPrivate;
enum  {
	SAVE_PASSWORD_ROW_0_PROPERTY,
	SAVE_PASSWORD_ROW_NUM_PROPERTIES
};
static GParamSpec* save_password_row_properties[SAVE_PASSWORD_ROW_NUM_PROPERTIES];
typedef struct _Block12Data Block12Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SwitchRow {
	AdwActionRow parent_instance;
	SwitchRowPrivate * priv;
};

struct _SwitchRowClass {
	AdwActionRowClass parent_class;
};

struct _SavePasswordRow {
	SwitchRow parent_instance;
	SavePasswordRowPrivate * priv;
};

struct _SavePasswordRowClass {
	SwitchRowClass parent_class;
};

struct _Block12Data {
	int _ref_count_;
	SavePasswordRow* self;
	GtkWindow* window;
};

static gpointer save_password_row_parent_class = NULL;

VALA_EXTERN GType switch_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SwitchRow, g_object_unref)
VALA_EXTERN GType save_password_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SavePasswordRow, g_object_unref)
static gboolean save_password_row_on_state_set (SavePasswordRow* self,
                                         gboolean state);
static Block12Data* block12_data_ref (Block12Data* _data12_);
static void block12_data_unref (void * _userdata_);
static void ___lambda29_ (Block12Data* _data12_,
                   GObject* obj,
                   GAsyncResult* res);
VALA_EXTERN void switch_row_set_state (SwitchRow* self,
                           gboolean value);
VALA_EXTERN void switch_row_set_active (SwitchRow* self,
                            gboolean value);
VALA_EXTERN void deja_dup_run_error_dialog (GtkWidget* parent,
                                const gchar* header,
                                const gchar* message,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
VALA_EXTERN void deja_dup_run_error_dialog_finish (GAsyncResult* _res_);
static void ____lambda29__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
VALA_EXTERN SavePasswordRow* save_password_row_new (void);
VALA_EXTERN SavePasswordRow* save_password_row_construct (GType object_type);
VALA_EXTERN SwitchRow* switch_row_new (void);
VALA_EXTERN SwitchRow* switch_row_construct (GType object_type);
static GObject * save_password_row_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static gboolean _save_password_row_on_state_set_switch_row_state_set (SwitchRow* _sender,
                                                               gboolean state,
                                                               gpointer self);
static GType save_password_row_get_type_once (void);

static Block12Data*
block12_data_ref (Block12Data* _data12_)
{
	g_atomic_int_inc (&_data12_->_ref_count_);
	return _data12_;
}

static void
block12_data_unref (void * _userdata_)
{
	Block12Data* _data12_;
	_data12_ = (Block12Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data12_->_ref_count_)) {
		SavePasswordRow* self;
		self = _data12_->self;
		_g_object_unref0 (_data12_->window);
		_g_object_unref0 (self);
		g_slice_free (Block12Data, _data12_);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
___lambda29_ (Block12Data* _data12_,
              GObject* obj,
              GAsyncResult* res)
{
	SavePasswordRow* self;
	self = _data12_->self;
	g_return_if_fail (res != NULL);
	if (deja_dup_is_secret_service_available_finish (res)) {
		switch_row_set_state ((SwitchRow*) self, TRUE);
	} else {
		GtkWindow* _tmp0_;
		switch_row_set_active ((SwitchRow*) self, FALSE);
		_tmp0_ = _data12_->window;
		deja_dup_run_error_dialog ((GtkWidget*) _tmp0_, _ ("Cannot remember password"), _ ("Your desktop session does not support saving passwords."), NULL, NULL);
	}
}

static void
____lambda29__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda29_ (self, source_object, res);
	block12_data_unref (self);
}

static gboolean
save_password_row_on_state_set (SavePasswordRow* self,
                                gboolean state)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (state) {
		Block12Data* _data12_;
		GtkRoot* _tmp0_;
		GtkRoot* _tmp1_;
		GtkWindow* _tmp2_;
		GtkWindow* _tmp3_;
		_data12_ = g_slice_new0 (Block12Data);
		_data12_->_ref_count_ = 1;
		_data12_->self = g_object_ref (self);
		_tmp0_ = gtk_widget_get_root ((GtkWidget*) self);
		_tmp1_ = _tmp0_;
		_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gtk_window_get_type ()) ? ((GtkWindow*) _tmp1_) : NULL);
		_data12_->window = _tmp2_;
		_tmp3_ = _data12_->window;
		if (_tmp3_ == NULL) {
			result = TRUE;
			block12_data_unref (_data12_);
			_data12_ = NULL;
			return result;
		}
		deja_dup_is_secret_service_available (____lambda29__gasync_ready_callback, block12_data_ref (_data12_));
		result = TRUE;
		block12_data_unref (_data12_);
		_data12_ = NULL;
		return result;
	}
	result = FALSE;
	return result;
}

SavePasswordRow*
save_password_row_construct (GType object_type)
{
	SavePasswordRow * self = NULL;
	self = (SavePasswordRow*) switch_row_construct (object_type);
	return self;
}

SavePasswordRow*
save_password_row_new (void)
{
	return save_password_row_construct (TYPE_SAVE_PASSWORD_ROW);
}

static gboolean
_save_password_row_on_state_set_switch_row_state_set (SwitchRow* _sender,
                                                      gboolean state,
                                                      gpointer self)
{
	gboolean result;
	result = save_password_row_on_state_set ((SavePasswordRow*) self, state);
	return result;
}

static GObject *
save_password_row_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SavePasswordRow * self;
	parent_class = G_OBJECT_CLASS (save_password_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SAVE_PASSWORD_ROW, SavePasswordRow);
	adw_preferences_row_set_title ((AdwPreferencesRow*) self, _ ("_Remember password"));
	g_signal_connect_object ((SwitchRow*) self, "state-set", (GCallback) _save_password_row_on_state_set_switch_row_state_set, self, 0);
	return obj;
}

static void
save_password_row_class_init (SavePasswordRowClass * klass,
                              gpointer klass_data)
{
	save_password_row_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = save_password_row_constructor;
}

static void
save_password_row_instance_init (SavePasswordRow * self,
                                 gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
save_password_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SavePasswordRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) save_password_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SavePasswordRow), 0, (GInstanceInitFunc) save_password_row_instance_init, NULL };
	GType save_password_row_type_id;
	save_password_row_type_id = g_type_register_static (TYPE_SWITCH_ROW, "SavePasswordRow", &g_define_type_info, 0);
	return save_password_row_type_id;
}

GType
save_password_row_get_type (void)
{
	static gsize save_password_row_type_id__once = 0;
	if (g_once_init_enter (&save_password_row_type_id__once)) {
		GType save_password_row_type_id;
		save_password_row_type_id = save_password_row_get_type_once ();
		g_once_init_leave (&save_password_row_type_id__once, save_password_row_type_id);
	}
	return save_password_row_type_id__once;
}

