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

/* onboarding-dialog.vala
 *
 * Copyright (C) Red Hat, Inc
 *
 * 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 3 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/>.
 *
 * Author: Felipe Borges <felipeborges@gnome.org>
 *
 */

#include <handy.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <math.h>
#include <float.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 CONNECTIONS_TYPE_ONBOARDING_DIALOG (connections_onboarding_dialog_get_type ())
#define CONNECTIONS_ONBOARDING_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG, ConnectionsOnboardingDialog))
#define CONNECTIONS_ONBOARDING_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_ONBOARDING_DIALOG, ConnectionsOnboardingDialogClass))
#define CONNECTIONS_IS_ONBOARDING_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG))
#define CONNECTIONS_IS_ONBOARDING_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_ONBOARDING_DIALOG))
#define CONNECTIONS_ONBOARDING_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG, ConnectionsOnboardingDialogClass))

typedef struct _ConnectionsOnboardingDialog ConnectionsOnboardingDialog;
typedef struct _ConnectionsOnboardingDialogClass ConnectionsOnboardingDialogClass;
typedef struct _ConnectionsOnboardingDialogPrivate ConnectionsOnboardingDialogPrivate;

#define CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE (connections_onboarding_dialog_page_get_type ())
#define CONNECTIONS_ONBOARDING_DIALOG_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE, ConnectionsOnboardingDialogPage))
#define CONNECTIONS_ONBOARDING_DIALOG_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE, ConnectionsOnboardingDialogPageClass))
#define CONNECTIONS_IS_ONBOARDING_DIALOG_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE))
#define CONNECTIONS_IS_ONBOARDING_DIALOG_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE))
#define CONNECTIONS_ONBOARDING_DIALOG_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_ONBOARDING_DIALOG_PAGE, ConnectionsOnboardingDialogPageClass))

typedef struct _ConnectionsOnboardingDialogPage ConnectionsOnboardingDialogPage;
typedef struct _ConnectionsOnboardingDialogPageClass ConnectionsOnboardingDialogPageClass;
enum  {
	CONNECTIONS_ONBOARDING_DIALOG_0_PROPERTY,
	CONNECTIONS_ONBOARDING_DIALOG_NUM_PROPERTIES
};
static GParamSpec* connections_onboarding_dialog_properties[CONNECTIONS_ONBOARDING_DIALOG_NUM_PROPERTIES];

#define CONNECTIONS_TYPE_WINDOW (connections_window_get_type ())
#define CONNECTIONS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_WINDOW, ConnectionsWindow))
#define CONNECTIONS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_WINDOW, ConnectionsWindowClass))
#define CONNECTIONS_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_WINDOW))
#define CONNECTIONS_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_WINDOW))
#define CONNECTIONS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_WINDOW, ConnectionsWindowClass))

typedef struct _ConnectionsWindow ConnectionsWindow;
typedef struct _ConnectionsWindowClass ConnectionsWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ConnectionsOnboardingDialog {
	HdyWindow parent_instance;
	ConnectionsOnboardingDialogPrivate * priv;
};

struct _ConnectionsOnboardingDialogClass {
	HdyWindowClass parent_class;
};

struct _ConnectionsOnboardingDialogPrivate {
	HdyCarousel* paginator;
	GtkButton* go_back_button;
	GtkButton* go_next_button;
	GtkButton* close_button;
	GList* pages;
};

static gint ConnectionsOnboardingDialog_private_offset;
static gpointer connections_onboarding_dialog_parent_class = NULL;

VALA_EXTERN GType connections_onboarding_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsOnboardingDialog, g_object_unref)
VALA_EXTERN GType connections_onboarding_dialog_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsOnboardingDialogPage, g_object_unref)
VALA_EXTERN GType connections_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsWindow, g_object_unref)
VALA_EXTERN ConnectionsOnboardingDialog* connections_onboarding_dialog_new (ConnectionsWindow* window);
VALA_EXTERN ConnectionsOnboardingDialog* connections_onboarding_dialog_construct (GType object_type,
                                                                      ConnectionsWindow* window);
static gboolean connections_onboarding_dialog_on_key_pressed (ConnectionsOnboardingDialog* self,
                                                       GtkWidget* widget,
                                                       GdkEventKey* event);
static gboolean _connections_onboarding_dialog_on_key_pressed_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                                   GdkEventKey* event,
                                                                                   gpointer self);
static void connections_onboarding_dialog_on_next_button_clicked (ConnectionsOnboardingDialog* self);
static void _connections_onboarding_dialog_on_next_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                               gpointer self);
static void connections_onboarding_dialog_on_back_button_clicked (ConnectionsOnboardingDialog* self);
static void _connections_onboarding_dialog_on_back_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                               gpointer self);
static void connections_onboarding_dialog_on_position_changed (ConnectionsOnboardingDialog* self);
static void _connections_onboarding_dialog_on_position_changed_g_object_notify (GObject* _sender,
                                                                         GParamSpec* pspec,
                                                                         gpointer self);
static GObject * connections_onboarding_dialog_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static void connections_onboarding_dialog_finalize (GObject * obj);
static GType connections_onboarding_dialog_get_type_once (void);

static inline gpointer
connections_onboarding_dialog_get_instance_private (ConnectionsOnboardingDialog* self)
{
	return G_STRUCT_MEMBER_P (self, ConnectionsOnboardingDialog_private_offset);
}

ConnectionsOnboardingDialog*
connections_onboarding_dialog_construct (GType object_type,
                                         ConnectionsWindow* window)
{
	ConnectionsOnboardingDialog * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (ConnectionsOnboardingDialog*) g_object_new (object_type, NULL);
	gtk_window_set_transient_for ((GtkWindow*) self, (GtkWindow*) window);
	return self;
}

ConnectionsOnboardingDialog*
connections_onboarding_dialog_new (ConnectionsWindow* window)
{
	return connections_onboarding_dialog_construct (CONNECTIONS_TYPE_ONBOARDING_DIALOG, window);
}

static gboolean
connections_onboarding_dialog_on_key_pressed (ConnectionsOnboardingDialog* self,
                                              GtkWidget* widget,
                                              GdkEventKey* event)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	if (event->keyval == GDK_KEY_Escape) {
		gtk_window_close ((GtkWindow*) self);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
_connections_onboarding_dialog_on_key_pressed_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                          GdkEventKey* event,
                                                                          gpointer self)
{
	gboolean result;
	result = connections_onboarding_dialog_on_key_pressed ((ConnectionsOnboardingDialog*) self, _sender, event);
	return result;
}

static void
connections_onboarding_dialog_on_next_button_clicked (ConnectionsOnboardingDialog* self)
{
	gint index = 0;
	HdyCarousel* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	GList* _tmp3_;
	HdyCarousel* _tmp4_;
	GList* _tmp5_;
	gconstpointer _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->paginator;
	_tmp1_ = hdy_carousel_get_position (_tmp0_);
	_tmp2_ = _tmp1_;
	index = ((gint) round (_tmp2_)) + 1;
	_tmp3_ = self->priv->pages;
	if (((guint) index) >= g_list_length (_tmp3_)) {
		return;
	}
	_tmp4_ = self->priv->paginator;
	_tmp5_ = self->priv->pages;
	_tmp6_ = g_list_nth_data (_tmp5_, (guint) index);
	hdy_carousel_scroll_to (_tmp4_, (GtkWidget*) ((ConnectionsOnboardingDialogPage*) _tmp6_));
}

static void
_connections_onboarding_dialog_on_next_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self)
{
	connections_onboarding_dialog_on_next_button_clicked ((ConnectionsOnboardingDialog*) self);
}

static void
connections_onboarding_dialog_on_back_button_clicked (ConnectionsOnboardingDialog* self)
{
	gint index = 0;
	HdyCarousel* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	HdyCarousel* _tmp3_;
	GList* _tmp4_;
	gconstpointer _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->paginator;
	_tmp1_ = hdy_carousel_get_position (_tmp0_);
	_tmp2_ = _tmp1_;
	index = ((gint) round (_tmp2_)) - 1;
	if (index < 0) {
		return;
	}
	_tmp3_ = self->priv->paginator;
	_tmp4_ = self->priv->pages;
	_tmp5_ = g_list_nth_data (_tmp4_, (guint) index);
	hdy_carousel_scroll_to (_tmp3_, (GtkWidget*) ((ConnectionsOnboardingDialogPage*) _tmp5_));
}

static void
_connections_onboarding_dialog_on_back_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self)
{
	connections_onboarding_dialog_on_back_button_clicked ((ConnectionsOnboardingDialog*) self);
}

static void
connections_onboarding_dialog_on_position_changed (ConnectionsOnboardingDialog* self)
{
	gint position = 0;
	HdyCarousel* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gboolean is_first_page = FALSE;
	gboolean is_last_page = FALSE;
	GList* _tmp3_;
	GtkButton* _tmp4_;
	GtkButton* _tmp5_;
	gboolean _tmp6_ = FALSE;
	GtkButton* _tmp7_;
	const gchar* _tmp8_ = NULL;
	GtkButton* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->paginator;
	_tmp1_ = hdy_carousel_get_position (_tmp0_);
	_tmp2_ = _tmp1_;
	position = (gint) _tmp2_;
	is_first_page = position == 0;
	_tmp3_ = self->priv->pages;
	is_last_page = ((guint) position) == (g_list_length (_tmp3_) - 1);
	_tmp4_ = self->priv->go_back_button;
	gtk_widget_set_visible ((GtkWidget*) _tmp4_, !is_first_page);
	_tmp5_ = self->priv->go_next_button;
	gtk_widget_set_visible ((GtkWidget*) _tmp5_, !is_last_page);
	if (is_first_page) {
		_tmp6_ = TRUE;
	} else {
		_tmp6_ = is_last_page;
	}
	_tmp7_ = self->priv->close_button;
	gtk_widget_set_visible ((GtkWidget*) _tmp7_, _tmp6_);
	if (is_first_page) {
		_tmp8_ = _ ("_No Thanks");
	} else {
		_tmp8_ = _ ("_Close");
	}
	_tmp9_ = self->priv->close_button;
	gtk_button_set_label (_tmp9_, _tmp8_);
}

static void
_connections_onboarding_dialog_on_position_changed_g_object_notify (GObject* _sender,
                                                                    GParamSpec* pspec,
                                                                    gpointer self)
{
	connections_onboarding_dialog_on_position_changed ((ConnectionsOnboardingDialog*) self);
}

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

static GObject *
connections_onboarding_dialog_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ConnectionsOnboardingDialog * self;
	ConnectionsOnboardingDialogPage* onboarding_page = NULL;
	HdyCarousel* _tmp0_;
	GList* _tmp1_;
	parent_class = G_OBJECT_CLASS (connections_onboarding_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONNECTIONS_TYPE_ONBOARDING_DIALOG, ConnectionsOnboardingDialog);
	(self->priv->pages == NULL) ? NULL : (self->priv->pages = (g_list_free (self->priv->pages), NULL));
	self->priv->pages = NULL;
	onboarding_page = NULL;
	_tmp0_ = self->priv->paginator;
	_tmp1_ = gtk_container_get_children ((GtkContainer*) _tmp0_);
	{
		GList* page_collection = NULL;
		GList* page_it = NULL;
		page_collection = _tmp1_;
		for (page_it = page_collection; page_it != NULL; page_it = page_it->next) {
			GtkWidget* page = NULL;
			page = (GtkWidget*) page_it->data;
			{
				GtkWidget* _tmp2_;
				GtkWidget* _tmp3_;
				ConnectionsOnboardingDialogPage* _tmp4_;
				ConnectionsOnboardingDialogPage* _tmp5_;
				_tmp2_ = page;
				_vala_assert (CONNECTIONS_IS_ONBOARDING_DIALOG_PAGE (_tmp2_), "page is OnboardingDialogPage");
				_tmp3_ = page;
				_tmp4_ = _g_object_ref0 (CONNECTIONS_IS_ONBOARDING_DIALOG_PAGE (_tmp3_) ? ((ConnectionsOnboardingDialogPage*) _tmp3_) : NULL);
				_g_object_unref0 (onboarding_page);
				onboarding_page = _tmp4_;
				_tmp5_ = onboarding_page;
				self->priv->pages = g_list_append (self->priv->pages, _tmp5_);
			}
		}
		(page_collection == NULL) ? NULL : (page_collection = (g_list_free (page_collection), NULL));
	}
	connections_onboarding_dialog_on_position_changed (self);
	_g_object_unref0 (onboarding_page);
	return obj;
}

static void
connections_onboarding_dialog_class_init (ConnectionsOnboardingDialogClass * klass,
                                          gpointer klass_data)
{
	connections_onboarding_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ConnectionsOnboardingDialog_private_offset);
	G_OBJECT_CLASS (klass)->constructor = connections_onboarding_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = connections_onboarding_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Connections/ui/onboarding-dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "paginator", FALSE, ConnectionsOnboardingDialog_private_offset + G_STRUCT_OFFSET (ConnectionsOnboardingDialogPrivate, paginator));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "go_back_button", FALSE, ConnectionsOnboardingDialog_private_offset + G_STRUCT_OFFSET (ConnectionsOnboardingDialogPrivate, go_back_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "go_next_button", FALSE, ConnectionsOnboardingDialog_private_offset + G_STRUCT_OFFSET (ConnectionsOnboardingDialogPrivate, go_next_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "close_button", FALSE, ConnectionsOnboardingDialog_private_offset + G_STRUCT_OFFSET (ConnectionsOnboardingDialogPrivate, close_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_key_pressed", G_CALLBACK(_connections_onboarding_dialog_on_key_pressed_gtk_widget_key_press_event));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_next_button_clicked", G_CALLBACK(_connections_onboarding_dialog_on_next_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_back_button_clicked", G_CALLBACK(_connections_onboarding_dialog_on_back_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_position_changed", G_CALLBACK(_connections_onboarding_dialog_on_position_changed_g_object_notify));
}

static void
connections_onboarding_dialog_instance_init (ConnectionsOnboardingDialog * self,
                                             gpointer klass)
{
	self->priv = connections_onboarding_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
connections_onboarding_dialog_finalize (GObject * obj)
{
	ConnectionsOnboardingDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONNECTIONS_TYPE_ONBOARDING_DIALOG, ConnectionsOnboardingDialog);
	(self->priv->pages == NULL) ? NULL : (self->priv->pages = (g_list_free (self->priv->pages), NULL));
	G_OBJECT_CLASS (connections_onboarding_dialog_parent_class)->finalize (obj);
}

static GType
connections_onboarding_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ConnectionsOnboardingDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) connections_onboarding_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ConnectionsOnboardingDialog), 0, (GInstanceInitFunc) connections_onboarding_dialog_instance_init, NULL };
	GType connections_onboarding_dialog_type_id;
	connections_onboarding_dialog_type_id = g_type_register_static (hdy_window_get_type (), "ConnectionsOnboardingDialog", &g_define_type_info, 0);
	ConnectionsOnboardingDialog_private_offset = g_type_add_instance_private (connections_onboarding_dialog_type_id, sizeof (ConnectionsOnboardingDialogPrivate));
	return connections_onboarding_dialog_type_id;
}

GType
connections_onboarding_dialog_get_type (void)
{
	static volatile gsize connections_onboarding_dialog_type_id__once = 0;
	if (g_once_init_enter (&connections_onboarding_dialog_type_id__once)) {
		GType connections_onboarding_dialog_type_id;
		connections_onboarding_dialog_type_id = connections_onboarding_dialog_get_type_once ();
		g_once_init_leave (&connections_onboarding_dialog_type_id__once, connections_onboarding_dialog_type_id);
	}
	return connections_onboarding_dialog_type_id__once;
}

