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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * 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, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.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 WIDGETS_TYPE_SYNC_BUTTON (widgets_sync_button_get_type ())
#define WIDGETS_SYNC_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButton))
#define WIDGETS_SYNC_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButtonClass))
#define WIDGETS_IS_SYNC_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_SYNC_BUTTON))
#define WIDGETS_IS_SYNC_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_SYNC_BUTTON))
#define WIDGETS_SYNC_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButtonClass))

typedef struct _WidgetsSyncButton WidgetsSyncButton;
typedef struct _WidgetsSyncButtonClass WidgetsSyncButtonClass;
typedef struct _WidgetsSyncButtonPrivate WidgetsSyncButtonPrivate;
enum  {
	WIDGETS_SYNC_BUTTON_0_PROPERTY,
	WIDGETS_SYNC_BUTTON_REVEAL_CHILD_PROPERTY,
	WIDGETS_SYNC_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_sync_button_properties[WIDGETS_SYNC_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	WIDGETS_SYNC_BUTTON_CLICKED_SIGNAL,
	WIDGETS_SYNC_BUTTON_NUM_SIGNALS
};
static guint widgets_sync_button_signals[WIDGETS_SYNC_BUTTON_NUM_SIGNALS] = {0};

struct _WidgetsSyncButton {
	AdwBin parent_instance;
	WidgetsSyncButtonPrivate * priv;
};

struct _WidgetsSyncButtonClass {
	AdwBinClass parent_class;
};

struct _WidgetsSyncButtonPrivate {
	GtkRevealer* main_revealer;
	GtkStack* stack;
	GtkButton* sync_button;
};

static gint WidgetsSyncButton_private_offset;
static gpointer widgets_sync_button_parent_class = NULL;

VALA_EXTERN GType widgets_sync_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsSyncButton, g_object_unref)
VALA_EXTERN void widgets_sync_button_sync_started (WidgetsSyncButton* self);
VALA_EXTERN void widgets_sync_button_sync_finished (WidgetsSyncButton* self);
VALA_EXTERN void widgets_sync_button_sync_failed (WidgetsSyncButton* self,
                                      const gchar* custom_message);
VALA_EXTERN WidgetsSyncButton* widgets_sync_button_new (void);
VALA_EXTERN WidgetsSyncButton* widgets_sync_button_construct (GType object_type);
VALA_EXTERN void widgets_sync_button_set_reveal_child (WidgetsSyncButton* self,
                                           gboolean value);
static GObject * widgets_sync_button_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static gboolean _widgets_sync_button___lambda266_ (WidgetsSyncButton* self);
static gboolean __widgets_sync_button___lambda266__gsource_func (gpointer self);
static void _widgets_sync_button___lambda267_ (WidgetsSyncButton* self);
static void __widgets_sync_button___lambda267__gtk_button_clicked (GtkButton* _sender,
                                                            gpointer self);
static void _widgets_sync_button___lambda268_ (WidgetsSyncButton* self);
static void __widgets_sync_button___lambda268__gtk_button_clicked (GtkButton* _sender,
                                                            gpointer self);
static void widgets_sync_button_finalize (GObject * obj);
static GType widgets_sync_button_get_type_once (void);
static void _vala_widgets_sync_button_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
widgets_sync_button_get_instance_private (WidgetsSyncButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsSyncButton_private_offset);
}

void
widgets_sync_button_sync_started (WidgetsSyncButton* self)
{
	GtkStack* _tmp0_;
	GtkButton* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp0_, "sync");
	gtk_widget_set_tooltip_markup ((GtkWidget*) self, "");
	_tmp1_ = self->priv->sync_button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "is_loading");
}

void
widgets_sync_button_sync_finished (WidgetsSyncButton* self)
{
	GtkButton* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sync_button;
	gtk_widget_remove_css_class ((GtkWidget*) _tmp0_, "is_loading");
}

void
widgets_sync_button_sync_failed (WidgetsSyncButton* self,
                                 const gchar* custom_message)
{
	GtkButton* _tmp0_;
	GtkStack* _tmp1_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->sync_button;
	gtk_widget_remove_css_class ((GtkWidget*) _tmp0_, "is_loading");
	_tmp1_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp1_, "error");
	if (custom_message != NULL) {
		_tmp2_ = g_strcmp0 (custom_message, "") != 0;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gtk_widget_set_tooltip_markup ((GtkWidget*) self, custom_message);
	} else {
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = g_strdup_printf ("<b>%s</b>\n%s", _ ("Failed to connect to server"), _ ("It looks like the server is unreachable,\n" \
"are you connected to the internet?\n" \
"Any changes you make while disconnected\n" \
"will be synchronized when you reconnect."));
		_tmp4_ = _tmp3_;
		gtk_widget_set_tooltip_markup ((GtkWidget*) self, _tmp4_);
		_g_free0 (_tmp4_);
	}
}

WidgetsSyncButton*
widgets_sync_button_construct (GType object_type)
{
	WidgetsSyncButton * self = NULL;
	self = (WidgetsSyncButton*) g_object_new (object_type, NULL);
	return self;
}

WidgetsSyncButton*
widgets_sync_button_new (void)
{
	return widgets_sync_button_construct (WIDGETS_TYPE_SYNC_BUTTON);
}

void
widgets_sync_button_set_reveal_child (WidgetsSyncButton* self,
                                      gboolean value)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, widgets_sync_button_properties[WIDGETS_SYNC_BUTTON_REVEAL_CHILD_PROPERTY]);
}

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

static gboolean
_widgets_sync_button___lambda266_ (WidgetsSyncButton* self)
{
	gboolean result;
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
__widgets_sync_button___lambda266__gsource_func (gpointer self)
{
	gboolean result;
	result = _widgets_sync_button___lambda266_ ((WidgetsSyncButton*) self);
	return result;
}

static void
_widgets_sync_button___lambda267_ (WidgetsSyncButton* self)
{
	g_signal_emit (self, widgets_sync_button_signals[WIDGETS_SYNC_BUTTON_CLICKED_SIGNAL], 0);
}

static void
__widgets_sync_button___lambda267__gtk_button_clicked (GtkButton* _sender,
                                                       gpointer self)
{
	_widgets_sync_button___lambda267_ ((WidgetsSyncButton*) self);
}

static void
_widgets_sync_button___lambda268_ (WidgetsSyncButton* self)
{
	g_signal_emit (self, widgets_sync_button_signals[WIDGETS_SYNC_BUTTON_CLICKED_SIGNAL], 0);
}

static void
__widgets_sync_button___lambda268__gtk_button_clicked (GtkButton* _sender,
                                                       gpointer self)
{
	_widgets_sync_button___lambda268_ ((WidgetsSyncButton*) self);
}

static GObject *
widgets_sync_button_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsSyncButton * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	GtkButton* _tmp3_ = NULL;
	GtkButton* error_button = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	GtkButton* _tmp7_ = NULL;
	GtkStack* _tmp8_ = NULL;
	GtkStack* _tmp9_;
	GtkButton* _tmp10_;
	GtkStack* _tmp11_;
	GtkButton* _tmp12_;
	GtkStack* _tmp13_;
	GtkWidget* _tmp14_;
	GtkRevealer* _tmp15_ = NULL;
	GtkRevealer* _tmp16_;
	GtkRevealer* _tmp17_;
	guint _tmp18_;
	guint _tmp19_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	parent_class = G_OBJECT_CLASS (widgets_sync_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButton);
	_tmp0_ = g_strdup ("flat");
	_tmp1_ = g_strdup ("header-item-button");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = (GtkButton*) gtk_button_new_from_icon_name ("update-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp3_, GTK_ALIGN_CENTER);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp3_, _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, 2, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->sync_button);
	self->priv->sync_button = _tmp3_;
	_tmp4_ = g_strdup ("flat");
	_tmp5_ = g_strdup ("header-item-button");
	_tmp6_ = g_new0 (gchar*, 2 + 1);
	_tmp6_[0] = _tmp4_;
	_tmp6_[1] = _tmp5_;
	_tmp7_ = (GtkButton*) gtk_button_new_from_icon_name ("dialog-warning-symbolic");
	gtk_widget_set_valign ((GtkWidget*) _tmp7_, GTK_ALIGN_CENTER);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp7_, _tmp6_);
	_tmp6_ = (_vala_array_free (_tmp6_, 2, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp7_);
	error_button = _tmp7_;
	_tmp8_ = (GtkStack*) gtk_stack_new ();
	gtk_stack_set_transition_type (_tmp8_, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp8_;
	_tmp9_ = self->priv->stack;
	_tmp10_ = self->priv->sync_button;
	gtk_stack_add_named (_tmp9_, (GtkWidget*) _tmp10_, "sync");
	_tmp11_ = self->priv->stack;
	_tmp12_ = error_button;
	gtk_stack_add_named (_tmp11_, (GtkWidget*) _tmp12_, "error");
	_tmp13_ = self->priv->stack;
	_tmp14_ = _g_object_ref0 ((GtkWidget*) _tmp13_);
	_tmp15_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp15_, GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
	gtk_revealer_set_child (_tmp15_, _tmp14_);
	_g_object_unref0 (_tmp14_);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->priv->main_revealer);
	self->priv->main_revealer = _tmp15_;
	_tmp16_ = self->priv->main_revealer;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp16_);
	_tmp17_ = self->priv->main_revealer;
	_tmp18_ = gtk_revealer_get_transition_duration (_tmp17_);
	_tmp19_ = _tmp18_;
	g_timeout_add_full (G_PRIORITY_DEFAULT, _tmp19_, __widgets_sync_button___lambda266__gsource_func, g_object_ref (self), g_object_unref);
	_tmp20_ = self->priv->sync_button;
	g_signal_connect_object (_tmp20_, "clicked", (GCallback) __widgets_sync_button___lambda267__gtk_button_clicked, self, 0);
	_tmp21_ = error_button;
	g_signal_connect_object (_tmp21_, "clicked", (GCallback) __widgets_sync_button___lambda268__gtk_button_clicked, self, 0);
	_g_object_unref0 (error_button);
	return obj;
}

static void
widgets_sync_button_class_init (WidgetsSyncButtonClass * klass,
                                gpointer klass_data)
{
	widgets_sync_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsSyncButton_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_sync_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_sync_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_sync_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_SYNC_BUTTON_REVEAL_CHILD_PROPERTY, widgets_sync_button_properties[WIDGETS_SYNC_BUTTON_REVEAL_CHILD_PROPERTY] = g_param_spec_boolean ("reveal-child", "reveal-child", "reveal-child", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	widgets_sync_button_signals[WIDGETS_SYNC_BUTTON_CLICKED_SIGNAL] = g_signal_new ("clicked", WIDGETS_TYPE_SYNC_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_sync_button_instance_init (WidgetsSyncButton * self,
                                   gpointer klass)
{
	self->priv = widgets_sync_button_get_instance_private (self);
}

static void
widgets_sync_button_finalize (GObject * obj)
{
	WidgetsSyncButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButton);
	g_debug ("SyncButton.vala:36: Destroying Widgets.SyncButton\n");
	_g_object_unref0 (self->priv->main_revealer);
	_g_object_unref0 (self->priv->stack);
	_g_object_unref0 (self->priv->sync_button);
	G_OBJECT_CLASS (widgets_sync_button_parent_class)->finalize (obj);
}

static GType
widgets_sync_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsSyncButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_sync_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsSyncButton), 0, (GInstanceInitFunc) widgets_sync_button_instance_init, NULL };
	GType widgets_sync_button_type_id;
	widgets_sync_button_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsSyncButton", &g_define_type_info, 0);
	WidgetsSyncButton_private_offset = g_type_add_instance_private (widgets_sync_button_type_id, sizeof (WidgetsSyncButtonPrivate));
	return widgets_sync_button_type_id;
}

GType
widgets_sync_button_get_type (void)
{
	static volatile gsize widgets_sync_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_sync_button_type_id__once)) {
		GType widgets_sync_button_type_id;
		widgets_sync_button_type_id = widgets_sync_button_get_type_once ();
		g_once_init_leave (&widgets_sync_button_type_id__once, widgets_sync_button_type_id);
	}
	return widgets_sync_button_type_id__once;
}

static void
_vala_widgets_sync_button_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	WidgetsSyncButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_SYNC_BUTTON, WidgetsSyncButton);
	switch (property_id) {
		case WIDGETS_SYNC_BUTTON_REVEAL_CHILD_PROPERTY:
		widgets_sync_button_set_reveal_child (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

