/* 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 <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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];
typedef struct _Block5Data Block5Data;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _Block5Data {
	int _ref_count_;
	gchar* resolved_token_url;
};

static gpointer proton_plus_widgets_preferences_access_token_row_parent_class = NULL;

static ProtonPlusWidgetsPreferencesAccessTokenRow* proton_plus_widgets_preferences_access_token_row_new (void);
static ProtonPlusWidgetsPreferencesAccessTokenRow* proton_plus_widgets_preferences_access_token_row_construct (GType object_type);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
static gchar* proton_plus_widgets_preferences_access_token_row_get_default_token_url (const gchar* source);
static void ___lambda399_ (Block5Data* _data5_);
static void ____lambda399__gtk_button_clicked (GtkButton* _sender,
                                        gpointer self);
static GType proton_plus_widgets_preferences_access_token_row_get_type_once (void);

static ProtonPlusWidgetsPreferencesAccessTokenRow*
proton_plus_widgets_preferences_access_token_row_construct (GType object_type)
{
	ProtonPlusWidgetsPreferencesAccessTokenRow * self = NULL;
	self = (ProtonPlusWidgetsPreferencesAccessTokenRow*) g_object_new (object_type, NULL);
	return self;
}

static ProtonPlusWidgetsPreferencesAccessTokenRow*
proton_plus_widgets_preferences_access_token_row_new (void)
{
	return proton_plus_widgets_preferences_access_token_row_construct (PROTON_PLUS_WIDGETS_PREFERENCES_TYPE_ACCESS_TOKEN_ROW);
}

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		_g_free0 (_data5_->resolved_token_url);
		g_slice_free (Block5Data, _data5_);
	}
}

static void
___lambda399_ (Block5Data* _data5_)
{
	const gchar* _tmp0_;
	_tmp0_ = _data5_->resolved_token_url;
	proton_plus_utils_system_open_uri (_tmp0_);
}

static void
____lambda399__gtk_button_clicked (GtkButton* _sender,
                                   gpointer self)
{
	___lambda399_ (self);
}

AdwPasswordEntryRow*
proton_plus_widgets_preferences_access_token_row_create (const gchar* source,
                                                         const gchar* icon_name,
                                                         const gchar* token_url)
{
	Block5Data* _data5_;
	AdwPasswordEntryRow* row = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	AdwPasswordEntryRow* _tmp2_ = NULL;
	AdwPasswordEntryRow* _tmp3_;
	GtkImage* _tmp4_;
	GtkImage* _tmp5_;
	AdwPasswordEntryRow* _tmp6_;
	gchar* _tmp7_ = NULL;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	AdwPasswordEntryRow* result;
	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);
	_data5_ = g_slice_new0 (Block5Data);
	_data5_->_ref_count_ = 1;
	_tmp0_ = g_strdup_printf (_ ("%s access token"), source);
	_tmp1_ = g_strdup (_ ("Enter an access token to reduce your chances of being rate limited"));
	_tmp2_ = (AdwPasswordEntryRow*) adw_password_entry_row_new ();
	adw_preferences_row_set_title ((AdwPreferencesRow*) _tmp2_, _tmp0_);
	_g_free0 (_tmp0_);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp2_, _tmp1_);
	_g_free0 (_tmp1_);
	g_object_ref_sink (_tmp2_);
	row = _tmp2_;
	_tmp3_ = row;
	_tmp4_ = (GtkImage*) gtk_image_new_from_icon_name (icon_name);
	g_object_ref_sink (_tmp4_);
	_tmp5_ = _tmp4_;
	adw_entry_row_add_prefix ((AdwEntryRow*) _tmp3_, (GtkWidget*) _tmp5_);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = row;
	proton_plus_utils_text_input_metadata_policy_apply ((GtkWidget*) _tmp6_, PROTON_PLUS_UTILS_TEXT_INPUT_FIELD_KIND_SECRET);
	if (g_strcmp0 (token_url, "") != 0) {
		gchar* _tmp8_;
		_tmp8_ = g_strdup (token_url);
		_g_free0 (_tmp7_);
		_tmp7_ = _tmp8_;
	} else {
		gchar* _tmp9_;
		_tmp9_ = proton_plus_widgets_preferences_access_token_row_get_default_token_url (source);
		_g_free0 (_tmp7_);
		_tmp7_ = _tmp9_;
	}
	_tmp10_ = _tmp7_;
	_tmp7_ = NULL;
	_data5_->resolved_token_url = _tmp10_;
	_tmp11_ = _data5_->resolved_token_url;
	if (g_strcmp0 (_tmp11_, "") != 0) {
		GtkButton* open_token_url_button = NULL;
		GtkButton* _tmp12_;
		GtkButton* _tmp13_;
		gchar* open_token_page_label = NULL;
		gchar* _tmp14_;
		GtkButton* _tmp15_;
		const gchar* _tmp16_;
		GtkButton* _tmp17_;
		const gchar* _tmp18_;
		GtkButton* _tmp19_;
		GtkButton* _tmp20_;
		AdwPasswordEntryRow* _tmp21_;
		GtkButton* _tmp22_;
		_tmp12_ = (GtkButton*) gtk_button_new_from_icon_name ("external-link-symbolic");
		g_object_ref_sink (_tmp12_);
		open_token_url_button = _tmp12_;
		_tmp13_ = open_token_url_button;
		gtk_widget_add_css_class ((GtkWidget*) _tmp13_, "flat");
		_tmp14_ = g_strdup_printf (_ ("Open %s Token Page"), source);
		open_token_page_label = _tmp14_;
		_tmp15_ = open_token_url_button;
		_tmp16_ = open_token_page_label;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp15_, _tmp16_);
		_tmp17_ = open_token_url_button;
		_tmp18_ = open_token_page_label;
		gtk_accessible_update_property ((GtkAccessible*) _tmp17_, GTK_ACCESSIBLE_PROPERTY_LABEL, _tmp18_, -1, -1);
		_tmp19_ = open_token_url_button;
		gtk_widget_set_valign ((GtkWidget*) _tmp19_, GTK_ALIGN_CENTER);
		_tmp20_ = open_token_url_button;
		g_signal_connect_data (_tmp20_, "clicked", (GCallback) ____lambda399__gtk_button_clicked, block5_data_ref (_data5_), (GClosureNotify) block5_data_unref, 0);
		_tmp21_ = row;
		_tmp22_ = open_token_url_button;
		adw_entry_row_add_suffix ((AdwEntryRow*) _tmp21_, (GtkWidget*) _tmp22_);
		_g_free0 (open_token_page_label);
		_g_object_unref0 (open_token_url_button);
	}
	result = row;
	_g_free0 (_tmp7_);
	block5_data_unref (_data5_);
	_data5_ = NULL;
	return result;
}

static gchar*
proton_plus_widgets_preferences_access_token_row_get_default_token_url (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 (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 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);
}

static void
proton_plus_widgets_preferences_access_token_row_instance_init (ProtonPlusWidgetsPreferencesAccessTokenRow * self,
                                                                gpointer klass)
{
}

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 (G_TYPE_OBJECT, "ProtonPlusWidgetsPreferencesAccessTokenRow", &g_define_type_info, 0);
	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;
}

