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

#include <handy.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>

#define TOOTLE_DIALOGS_TYPE_PREFERENCES (tootle_dialogs_preferences_get_type ())
#define TOOTLE_DIALOGS_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_DIALOGS_TYPE_PREFERENCES, TootleDialogsPreferences))
#define TOOTLE_DIALOGS_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_DIALOGS_TYPE_PREFERENCES, TootleDialogsPreferencesClass))
#define TOOTLE_DIALOGS_IS_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_DIALOGS_TYPE_PREFERENCES))
#define TOOTLE_DIALOGS_IS_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_DIALOGS_TYPE_PREFERENCES))
#define TOOTLE_DIALOGS_PREFERENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_DIALOGS_TYPE_PREFERENCES, TootleDialogsPreferencesClass))

typedef struct _TootleDialogsPreferences TootleDialogsPreferences;
typedef struct _TootleDialogsPreferencesClass TootleDialogsPreferencesClass;
typedef struct _TootleDialogsPreferencesPrivate TootleDialogsPreferencesPrivate;
enum  {
	TOOTLE_DIALOGS_PREFERENCES_0_PROPERTY,
	TOOTLE_DIALOGS_PREFERENCES_NUM_PROPERTIES
};
static GParamSpec* tootle_dialogs_preferences_properties[TOOTLE_DIALOGS_PREFERENCES_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TOOTLE_TYPE_SETTINGS (tootle_settings_get_type ())
#define TOOTLE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_TYPE_SETTINGS, TootleSettings))
#define TOOTLE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_TYPE_SETTINGS, TootleSettingsClass))
#define TOOTLE_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_TYPE_SETTINGS))
#define TOOTLE_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_TYPE_SETTINGS))
#define TOOTLE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_TYPE_SETTINGS, TootleSettingsClass))

typedef struct _TootleSettings TootleSettings;
typedef struct _TootleSettingsClass TootleSettingsClass;
typedef enum  {
	TOOTLE_API_VISIBILITY_PUBLIC,
	TOOTLE_API_VISIBILITY_UNLISTED,
	TOOTLE_API_VISIBILITY_PRIVATE,
	TOOTLE_API_VISIBILITY_DIRECT
} TootleAPIVisibility;

#define TOOTLE_API_TYPE_VISIBILITY (tootle_api_visibility_get_type ())

#define TOOTLE_DIALOGS_TYPE_MAIN_WINDOW (tootle_dialogs_main_window_get_type ())
#define TOOTLE_DIALOGS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindow))
#define TOOTLE_DIALOGS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindowClass))
#define TOOTLE_DIALOGS_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW))
#define TOOTLE_DIALOGS_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW))
#define TOOTLE_DIALOGS_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TOOTLE_DIALOGS_TYPE_MAIN_WINDOW, TootleDialogsMainWindowClass))

typedef struct _TootleDialogsMainWindow TootleDialogsMainWindow;
typedef struct _TootleDialogsMainWindowClass TootleDialogsMainWindowClass;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _TootleDialogsPreferences {
	HdyPreferencesWindow parent_instance;
	TootleDialogsPreferencesPrivate * priv;
};

struct _TootleDialogsPreferencesClass {
	HdyPreferencesWindowClass parent_class;
};

struct _TootleDialogsPreferencesPrivate {
	GtkSwitch* dark_theme;
	GtkSwitch* autostart;
	GtkSwitch* work_in_background;
	HdyComboRow* default_post_visibility;
	GtkSpinButton* timeline_page_size;
	GtkSpinButton* post_text_size;
	GtkSwitch* live_updates;
	GtkSwitch* public_live_updates;
};

static gint TootleDialogsPreferences_private_offset;
static gpointer tootle_dialogs_preferences_parent_class = NULL;
extern TootleSettings* tootle_settings;
extern TootleDialogsMainWindow* tootle_window;

GType tootle_dialogs_preferences_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleDialogsPreferences, g_object_unref)
void tootle_dialogs_preferences_open (void);
TootleDialogsPreferences* tootle_dialogs_preferences_new (void);
TootleDialogsPreferences* tootle_dialogs_preferences_construct (GType object_type);
static void tootle_dialogs_preferences_bind (TootleDialogsPreferences* self);
GType tootle_settings_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleSettings, g_object_unref)
GType tootle_api_visibility_get_type (void) G_GNUC_CONST ;
TootleAPIVisibility tootle_settings_get_default_post_visibility (TootleSettings* self);
static void __lambda125_ (TootleDialogsPreferences* self,
                   GParamSpec* p);
void tootle_settings_set_default_post_visibility (TootleSettings* self,
                                                  TootleAPIVisibility value);
static void ___lambda125__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static GObject * tootle_dialogs_preferences_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
GType tootle_dialogs_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TootleDialogsMainWindow, g_object_unref)
static gchar* _tootle_dialogs_preferences___lambda126_ (TootleDialogsPreferences* self,
                                                 HdyEnumValueObject* e);
TootleAPIVisibility* tootle_api_visibility_all (gint* result_length1);
gchar* tootle_api_visibility_get_desc (TootleAPIVisibility self);
gchar* tootle_api_visibility_get_name (TootleAPIVisibility self);
static gchar* __tootle_dialogs_preferences___lambda126__hdy_combo_row_get_enum_value_name_func (HdyEnumValueObject* value,
                                                                                         gpointer self);
static void tootle_dialogs_preferences_finalize (GObject * obj);
static GType tootle_dialogs_preferences_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
tootle_dialogs_preferences_get_instance_private (TootleDialogsPreferences* self)
{
	return G_STRUCT_MEMBER_P (self, TootleDialogsPreferences_private_offset);
}

void
tootle_dialogs_preferences_open (void)
{
	TootleDialogsPreferences* _tmp0_;
	TootleDialogsPreferences* _tmp1_;
	_tmp0_ = tootle_dialogs_preferences_new ();
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	_g_object_unref0 (_tmp1_);
}

static void
__lambda125_ (TootleDialogsPreferences* self,
              GParamSpec* p)
{
	gint i = 0;
	HdyComboRow* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	TootleSettings* _tmp3_;
	g_return_if_fail (p != NULL);
	_tmp0_ = self->priv->default_post_visibility;
	_tmp1_ = hdy_combo_row_get_selected_index (_tmp0_);
	_tmp2_ = _tmp1_;
	i = _tmp2_;
	_tmp3_ = tootle_settings;
	tootle_settings_set_default_post_visibility (_tmp3_, (TootleAPIVisibility) i);
}

static void
___lambda125__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda125_ ((TootleDialogsPreferences*) self, pspec);
}

static void
tootle_dialogs_preferences_bind (TootleDialogsPreferences* self)
{
	TootleSettings* _tmp0_;
	GtkSwitch* _tmp1_;
	TootleSettings* _tmp2_;
	GtkSwitch* _tmp3_;
	TootleSettings* _tmp4_;
	GtkSwitch* _tmp5_;
	HdyComboRow* _tmp6_;
	TootleSettings* _tmp7_;
	TootleAPIVisibility _tmp8_;
	TootleAPIVisibility _tmp9_;
	HdyComboRow* _tmp10_;
	TootleSettings* _tmp11_;
	GtkSpinButton* _tmp12_;
	GtkAdjustment* _tmp13_;
	GtkAdjustment* _tmp14_;
	TootleSettings* _tmp15_;
	GtkSpinButton* _tmp16_;
	GtkAdjustment* _tmp17_;
	GtkAdjustment* _tmp18_;
	TootleSettings* _tmp19_;
	GtkSwitch* _tmp20_;
	TootleSettings* _tmp21_;
	GtkSwitch* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = tootle_settings;
	_tmp1_ = self->priv->dark_theme;
	g_settings_bind ((GSettings*) _tmp0_, "dark-theme", (GObject*) _tmp1_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp2_ = tootle_settings;
	_tmp3_ = self->priv->autostart;
	g_settings_bind ((GSettings*) _tmp2_, "autostart", (GObject*) _tmp3_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = tootle_settings;
	_tmp5_ = self->priv->work_in_background;
	g_settings_bind ((GSettings*) _tmp4_, "work-in-background", (GObject*) _tmp5_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp6_ = self->priv->default_post_visibility;
	_tmp7_ = tootle_settings;
	_tmp8_ = tootle_settings_get_default_post_visibility (_tmp7_);
	_tmp9_ = _tmp8_;
	hdy_combo_row_set_selected_index (_tmp6_, (gint) _tmp9_);
	_tmp10_ = self->priv->default_post_visibility;
	g_signal_connect_object ((GObject*) _tmp10_, "notify::selected-index", (GCallback) ___lambda125__g_object_notify, self, 0);
	_tmp11_ = tootle_settings;
	_tmp12_ = self->priv->timeline_page_size;
	_tmp13_ = gtk_spin_button_get_adjustment (_tmp12_);
	_tmp14_ = _tmp13_;
	g_settings_bind ((GSettings*) _tmp11_, "timeline-page-size", (GObject*) _tmp14_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp15_ = tootle_settings;
	_tmp16_ = self->priv->post_text_size;
	_tmp17_ = gtk_spin_button_get_adjustment (_tmp16_);
	_tmp18_ = _tmp17_;
	g_settings_bind ((GSettings*) _tmp15_, "post-text-size", (GObject*) _tmp18_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp19_ = tootle_settings;
	_tmp20_ = self->priv->live_updates;
	g_settings_bind ((GSettings*) _tmp19_, "live-updates", (GObject*) _tmp20_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp21_ = tootle_settings;
	_tmp22_ = self->priv->public_live_updates;
	g_settings_bind ((GSettings*) _tmp21_, "public-live-updates", (GObject*) _tmp22_, "active", G_SETTINGS_BIND_DEFAULT);
}

TootleDialogsPreferences*
tootle_dialogs_preferences_construct (GType object_type)
{
	TootleDialogsPreferences * self = NULL;
	self = (TootleDialogsPreferences*) g_object_new (object_type, NULL);
	return self;
}

TootleDialogsPreferences*
tootle_dialogs_preferences_new (void)
{
	return tootle_dialogs_preferences_construct (TOOTLE_DIALOGS_TYPE_PREFERENCES);
}

static gchar*
_tootle_dialogs_preferences___lambda126_ (TootleDialogsPreferences* self,
                                          HdyEnumValueObject* e)
{
	gint i = 0;
	TootleAPIVisibility vis = 0;
	gint _tmp0_ = 0;
	TootleAPIVisibility* _tmp1_;
	TootleAPIVisibility* _tmp2_;
	gint _tmp2__length1;
	TootleAPIVisibility _tmp3_;
	TootleAPIVisibility _tmp4_;
	HdyComboRow* _tmp5_;
	TootleAPIVisibility _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	TootleAPIVisibility _tmp9_;
	gchar* _tmp10_;
	gchar* result = NULL;
	g_return_val_if_fail (e != NULL, NULL);
	i = hdy_enum_value_object_get_value (e);
	_tmp1_ = tootle_api_visibility_all (&_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp0_;
	_tmp3_ = _tmp2_[i];
	_tmp4_ = _tmp3_;
	_tmp2_ = (g_free (_tmp2_), NULL);
	vis = _tmp4_;
	_tmp5_ = self->priv->default_post_visibility;
	_tmp6_ = vis;
	_tmp7_ = tootle_api_visibility_get_desc (_tmp6_);
	_tmp8_ = _tmp7_;
	hdy_action_row_set_subtitle ((HdyActionRow*) _tmp5_, _tmp8_);
	_g_free0 (_tmp8_);
	_tmp9_ = vis;
	_tmp10_ = tootle_api_visibility_get_name (_tmp9_);
	result = _tmp10_;
	return result;
}

static gchar*
__tootle_dialogs_preferences___lambda126__hdy_combo_row_get_enum_value_name_func (HdyEnumValueObject* value,
                                                                                  gpointer self)
{
	gchar* result;
	result = _tootle_dialogs_preferences___lambda126_ ((TootleDialogsPreferences*) self, value);
	return result;
}

static GObject *
tootle_dialogs_preferences_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	TootleDialogsPreferences * self;
	TootleDialogsMainWindow* _tmp0_;
	HdyComboRow* _tmp1_;
	parent_class = G_OBJECT_CLASS (tootle_dialogs_preferences_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_DIALOGS_TYPE_PREFERENCES, TootleDialogsPreferences);
	_tmp0_ = tootle_window;
	gtk_window_set_transient_for ((GtkWindow*) self, (GtkWindow*) _tmp0_);
	_tmp1_ = self->priv->default_post_visibility;
	hdy_combo_row_set_for_enum (_tmp1_, TOOTLE_API_TYPE_VISIBILITY, __tootle_dialogs_preferences___lambda126__hdy_combo_row_get_enum_value_name_func, g_object_ref (self), g_object_unref);
	tootle_dialogs_preferences_bind (self);
	gtk_widget_show ((GtkWidget*) self);
	return obj;
}

static void
tootle_dialogs_preferences_class_init (TootleDialogsPreferencesClass * klass,
                                       gpointer klass_data)
{
	tootle_dialogs_preferences_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &TootleDialogsPreferences_private_offset);
	G_OBJECT_CLASS (klass)->constructor = tootle_dialogs_preferences_constructor;
	G_OBJECT_CLASS (klass)->finalize = tootle_dialogs_preferences_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/github/bleakgrey/tootle/ui/dialogs/preferences.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "dark_theme", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, dark_theme));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "autostart", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, autostart));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "work_in_background", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, work_in_background));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "default_post_visibility", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, default_post_visibility));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "timeline_page_size", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, timeline_page_size));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "post_text_size", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, post_text_size));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "live_updates", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, live_updates));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "public_live_updates", FALSE, TootleDialogsPreferences_private_offset + G_STRUCT_OFFSET (TootleDialogsPreferencesPrivate, public_live_updates));
}

static void
tootle_dialogs_preferences_instance_init (TootleDialogsPreferences * self,
                                          gpointer klass)
{
	self->priv = tootle_dialogs_preferences_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
tootle_dialogs_preferences_finalize (GObject * obj)
{
	TootleDialogsPreferences * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TOOTLE_DIALOGS_TYPE_PREFERENCES, TootleDialogsPreferences);
	G_OBJECT_CLASS (tootle_dialogs_preferences_parent_class)->finalize (obj);
}

static GType
tootle_dialogs_preferences_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (TootleDialogsPreferencesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tootle_dialogs_preferences_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TootleDialogsPreferences), 0, (GInstanceInitFunc) tootle_dialogs_preferences_instance_init, NULL };
	GType tootle_dialogs_preferences_type_id;
	tootle_dialogs_preferences_type_id = g_type_register_static (hdy_preferences_window_get_type (), "TootleDialogsPreferences", &g_define_type_info, 0);
	TootleDialogsPreferences_private_offset = g_type_add_instance_private (tootle_dialogs_preferences_type_id, sizeof (TootleDialogsPreferencesPrivate));
	return tootle_dialogs_preferences_type_id;
}

GType
tootle_dialogs_preferences_get_type (void)
{
	static volatile gsize tootle_dialogs_preferences_type_id__volatile = 0;
	if (g_once_init_enter (&tootle_dialogs_preferences_type_id__volatile)) {
		GType tootle_dialogs_preferences_type_id;
		tootle_dialogs_preferences_type_id = tootle_dialogs_preferences_get_type_once ();
		g_once_init_leave (&tootle_dialogs_preferences_type_id__volatile, tootle_dialogs_preferences_type_id);
	}
	return tootle_dialogs_preferences_type_id__volatile;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

