/* preferences-access-token-row.c generated by valac 0.56.19, the Vala compiler
 * generated from preferences-access-token-row.vala, do not modify */

#include "protonplus_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.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  {
	PROTON_PLUS_WIDGETS_PREFERENCES_ACCESS_TOKEN_ROW_0_PROPERTY,
	PROTON_PLUS_WIDGETS_PREFERENCES_ACCESS_TOKEN_ROW_NUM_PROPERTIES
};
static GParamSpec* proton_plus_widgets_preferences_access_token_row_properties[PROTON_PLUS_WIDGETS_PREFERENCES_ACCESS_TOKEN_ROW_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ProtonPlusWidgetsPreferencesAccessTokenRowPrivate {
	gchar* _token_url;
};

static gint ProtonPlusWidgetsPreferencesAccessTokenRow_private_offset;
static gpointer proton_plus_widgets_preferences_access_token_row_parent_class = NULL;

static void proton_plus_widgets_preferences_access_token_row_set_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self,
                                                                     const gchar* value);
static const gchar* proton_plus_widgets_preferences_access_token_row_get_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self);
static gchar* proton_plus_widgets_preferences_access_token_row_get_default_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self,
                                                                               const gchar* source);
static void ___lambda352_ (ProtonPlusWidgetsPreferencesAccessTokenRow* self);
static void ____lambda352__gtk_button_clicked (GtkButton* _sender,
                                        gpointer self);
static GObject * proton_plus_widgets_preferences_access_token_row_constructor (GType type,
                                                                        guint n_construct_properties,
                                                                        GObjectConstructParam * construct_properties);
static void proton_plus_widgets_preferences_access_token_row_finalize (GObject * obj);
static GType proton_plus_widgets_preferences_access_token_row_get_type_once (void);
static void _vala_proton_plus_widgets_preferences_access_token_row_get_property (GObject * object,
                                                                          guint property_id,
                                                                          GValue * value,
                                                                          GParamSpec * pspec);
static void _vala_proton_plus_widgets_preferences_access_token_row_set_property (GObject * object,
                                                                          guint property_id,
                                                                          const GValue * value,
                                                                          GParamSpec * pspec);

static inline gpointer
proton_plus_widgets_preferences_access_token_row_get_instance_private (ProtonPlusWidgetsPreferencesAccessTokenRow* self)
{
	return G_STRUCT_MEMBER_P (self, ProtonPlusWidgetsPreferencesAccessTokenRow_private_offset);
}

static void
___lambda352_ (ProtonPlusWidgetsPreferencesAccessTokenRow* self)
{
	const gchar* _tmp0_;
	_tmp0_ = self->priv->_token_url;
	proton_plus_utils_system_open_uri (_tmp0_);
}

static void
____lambda352__gtk_button_clicked (GtkButton* _sender,
                                   gpointer self)
{
	___lambda352_ ((ProtonPlusWidgetsPreferencesAccessTokenRow*) self);
}

ProtonPlusWidgetsPreferencesAccessTokenRow*
proton_plus_widgets_preferences_access_token_row_construct (GType object_type,
                                                            const gchar* source,
                                                            const gchar* icon_name,
                                                            const gchar* token_url)
{
	ProtonPlusWidgetsPreferencesAccessTokenRow * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GtkImage* _tmp2_;
	GtkImage* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp7_;
	g_return_val_if_fail (source != NULL, NULL);
	g_return_val_if_fail (icon_name != NULL, NULL);
	g_return_val_if_fail (token_url != NULL, NULL);
	self = (ProtonPlusWidgetsPreferencesAccessTokenRow*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup_printf (_ ("%s access token"), source);
	_tmp1_ = _tmp0_;
	adw_preferences_row_set_title ((AdwPreferencesRow*) self, _tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name (icon_name);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	adw_entry_row_add_prefix ((AdwEntryRow*) self, (GtkWidget*) _tmp3_);
	_g_object_unref0 (_tmp3_);
	proton_plus_widgets_preferences_access_token_row_set_token_url (self, token_url);
	_tmp4_ = self->priv->_token_url;
	if (g_strcmp0 (_tmp4_, "") == 0) {
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = proton_plus_widgets_preferences_access_token_row_get_default_token_url (self, source);
		_tmp6_ = _tmp5_;
		proton_plus_widgets_preferences_access_token_row_set_token_url (self, _tmp6_);
		_g_free0 (_tmp6_);
	}
	_tmp7_ = self->priv->_token_url;
	if (g_strcmp0 (_tmp7_, "") != 0) {
		GtkButton* open_token_url_button = NULL;
		GtkButton* _tmp8_;
		GtkButton* _tmp9_;
		GtkButton* _tmp10_;
		GtkButton* _tmp11_;
		GtkButton* _tmp12_;
		GtkButton* _tmp13_;
		GtkButton* _tmp14_;
		_tmp8_ = (GtkButton*) gtk_button_new_from_icon_name ("globe-symbolic");
		g_object_ref_sink (_tmp8_);
		open_token_url_button = _tmp8_;
		_tmp9_ = open_token_url_button;
		gtk_widget_add_css_class ((GtkWidget*) _tmp9_, "flat");
		_tmp10_ = open_token_url_button;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp10_, _ ("Open token creation page"));
		_tmp11_ = open_token_url_button;
		gtk_widget_set_size_request ((GtkWidget*) _tmp11_, -1, 25);
		_tmp12_ = open_token_url_button;
		gtk_widget_set_valign ((GtkWidget*) _tmp12_, GTK_ALIGN_CENTER);
		_tmp13_ = open_token_url_button;
		g_signal_connect_object (_tmp13_, "clicked", (GCallback) ____lambda352__gtk_button_clicked, self, 0);
		_tmp14_ = open_token_url_button;
		adw_entry_row_add_suffix ((AdwEntryRow*) self, (GtkWidget*) _tmp14_);
		_g_object_unref0 (open_token_url_button);
	}
	return self;
}

ProtonPlusWidgetsPreferencesAccessTokenRow*
proton_plus_widgets_preferences_access_token_row_new (const gchar* source,
                                                      const gchar* icon_name,
                                                      const gchar* token_url)
{
	return proton_plus_widgets_preferences_access_token_row_construct (PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW, source, icon_name, token_url);
}

static gchar*
proton_plus_widgets_preferences_access_token_row_get_default_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self,
                                                                        const gchar* source)
{
	gchar* normalized_source = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gchar* _tmp7_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (source != NULL, NULL);
	_tmp0_ = g_utf8_strdown (source, (gssize) -1);
	normalized_source = _tmp0_;
	_tmp1_ = normalized_source;
	if (g_strcmp0 (_tmp1_, "github") == 0) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("https://github.com/settings/tokens");
		result = _tmp2_;
		_g_free0 (normalized_source);
		return result;
	}
	_tmp3_ = normalized_source;
	if (g_strcmp0 (_tmp3_, "gitlab") == 0) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("https://gitlab.com/-/user_settings/personal_access_tokens");
		result = _tmp4_;
		_g_free0 (normalized_source);
		return result;
	}
	_tmp5_ = normalized_source;
	if (g_strcmp0 (_tmp5_, "forgejo") == 0) {
		gchar* _tmp6_;
		_tmp6_ = g_strdup ("https://codeberg.org/user/settings/applications");
		result = _tmp6_;
		_g_free0 (normalized_source);
		return result;
	}
	_tmp7_ = g_strdup ("");
	result = _tmp7_;
	_g_free0 (normalized_source);
	return result;
}

static const gchar*
proton_plus_widgets_preferences_access_token_row_get_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_token_url;
	result = _tmp0_;
	return result;
}

static void
proton_plus_widgets_preferences_access_token_row_set_token_url (ProtonPlusWidgetsPreferencesAccessTokenRow* self,
                                                                const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_token_url);
	self->priv->_token_url = _tmp0_;
}

static GObject *
proton_plus_widgets_preferences_access_token_row_constructor (GType type,
                                                              guint n_construct_properties,
                                                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ProtonPlusWidgetsPreferencesAccessTokenRow * self;
	parent_class = G_OBJECT_CLASS (proton_plus_widgets_preferences_access_token_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW, ProtonPlusWidgetsPreferencesAccessTokenRow);
	gtk_widget_set_tooltip_text ((GtkWidget*) self, _ ("Enter an access token to reduce your chances of being rate limited"));
	proton_plus_utils_text_input_metadata_policy_apply ((GtkWidget*) self, PROTON_PLUS_UTILS_TEXT_INPUT_FIELD_KIND_SECRET);
	return obj;
}

static void
proton_plus_widgets_preferences_access_token_row_class_init (ProtonPlusWidgetsPreferencesAccessTokenRowClass * klass,
                                                             gpointer klass_data)
{
	proton_plus_widgets_preferences_access_token_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ProtonPlusWidgetsPreferencesAccessTokenRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_proton_plus_widgets_preferences_access_token_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_proton_plus_widgets_preferences_access_token_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = proton_plus_widgets_preferences_access_token_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_widgets_preferences_access_token_row_finalize;
}

static void
proton_plus_widgets_preferences_access_token_row_instance_init (ProtonPlusWidgetsPreferencesAccessTokenRow * self,
                                                                gpointer klass)
{
	gchar* _tmp0_;
	self->priv = proton_plus_widgets_preferences_access_token_row_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_token_url = _tmp0_;
}

static void
proton_plus_widgets_preferences_access_token_row_finalize (GObject * obj)
{
	ProtonPlusWidgetsPreferencesAccessTokenRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW, ProtonPlusWidgetsPreferencesAccessTokenRow);
	_g_free0 (self->priv->_token_url);
	G_OBJECT_CLASS (proton_plus_widgets_preferences_access_token_row_parent_class)->finalize (obj);
}

static GType
proton_plus_widgets_preferences_access_token_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusWidgetsPreferencesAccessTokenRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_widgets_preferences_access_token_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusWidgetsPreferencesAccessTokenRow), 0, (GInstanceInitFunc) proton_plus_widgets_preferences_access_token_row_instance_init, NULL };
	GType proton_plus_widgets_preferences_access_token_row_type_id;
	proton_plus_widgets_preferences_access_token_row_type_id = g_type_register_static (adw_entry_row_get_type (), "ProtonPlusWidgetsPreferencesAccessTokenRow", &g_define_type_info, 0);
	ProtonPlusWidgetsPreferencesAccessTokenRow_private_offset = g_type_add_instance_private (proton_plus_widgets_preferences_access_token_row_type_id, sizeof (ProtonPlusWidgetsPreferencesAccessTokenRowPrivate));
	return proton_plus_widgets_preferences_access_token_row_type_id;
}

GType
proton_plus_widgets_preferences_access_token_row_get_type (void)
{
	static volatile gsize proton_plus_widgets_preferences_access_token_row_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_widgets_preferences_access_token_row_type_id__once)) {
		GType proton_plus_widgets_preferences_access_token_row_type_id;
		proton_plus_widgets_preferences_access_token_row_type_id = proton_plus_widgets_preferences_access_token_row_get_type_once ();
		g_once_init_leave (&proton_plus_widgets_preferences_access_token_row_type_id__once, proton_plus_widgets_preferences_access_token_row_type_id);
	}
	return proton_plus_widgets_preferences_access_token_row_type_id__once;
}

static void
_vala_proton_plus_widgets_preferences_access_token_row_get_property (GObject * object,
                                                                     guint property_id,
                                                                     GValue * value,
                                                                     GParamSpec * pspec)
{
	ProtonPlusWidgetsPreferencesAccessTokenRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW, ProtonPlusWidgetsPreferencesAccessTokenRow);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_proton_plus_widgets_preferences_access_token_row_set_property (GObject * object,
                                                                     guint property_id,
                                                                     const GValue * value,
                                                                     GParamSpec * pspec)
{
	ProtonPlusWidgetsPreferencesAccessTokenRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW, ProtonPlusWidgetsPreferencesAccessTokenRow);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

