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

/* Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2017 Jens Georg <mail@jensge.org>
 *
 * This software is licensed under the GNU LGPL (version 2.1 or later).
 * See the COPYING file in this distribution.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <float.h>
#include <math.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 TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG (set_background_slideshow_dialog_get_type ())
#define SET_BACKGROUND_SLIDESHOW_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG, SetBackgroundSlideshowDialog))
#define SET_BACKGROUND_SLIDESHOW_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG, SetBackgroundSlideshowDialogClass))
#define IS_SET_BACKGROUND_SLIDESHOW_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG))
#define IS_SET_BACKGROUND_SLIDESHOW_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG))
#define SET_BACKGROUND_SLIDESHOW_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG, SetBackgroundSlideshowDialogClass))

typedef struct _SetBackgroundSlideshowDialog SetBackgroundSlideshowDialog;
typedef struct _SetBackgroundSlideshowDialogClass SetBackgroundSlideshowDialogClass;
typedef struct _SetBackgroundSlideshowDialogPrivate SetBackgroundSlideshowDialogPrivate;
enum  {
	SET_BACKGROUND_SLIDESHOW_DIALOG_0_PROPERTY,
	SET_BACKGROUND_SLIDESHOW_DIALOG_NUM_PROPERTIES
};
static GParamSpec* set_background_slideshow_dialog_properties[SET_BACKGROUND_SLIDESHOW_DIALOG_NUM_PROPERTIES];

#define TYPE_PAGE_WINDOW (page_window_get_type ())
#define PAGE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PAGE_WINDOW, PageWindow))
#define PAGE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PAGE_WINDOW, PageWindowClass))
#define IS_PAGE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PAGE_WINDOW))
#define IS_PAGE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PAGE_WINDOW))
#define PAGE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PAGE_WINDOW, PageWindowClass))

typedef struct _PageWindow PageWindow;
typedef struct _PageWindowClass PageWindowClass;

#define TYPE_APP_WINDOW (app_window_get_type ())
#define APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APP_WINDOW, AppWindow))
#define APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APP_WINDOW, AppWindowClass))
#define IS_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APP_WINDOW))
#define IS_APP_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APP_WINDOW))
#define APP_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APP_WINDOW, AppWindowClass))

typedef struct _AppWindow AppWindow;
typedef struct _AppWindowClass AppWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _SetBackgroundSlideshowDialog {
	GtkDialog parent_instance;
	SetBackgroundSlideshowDialogPrivate * priv;
};

struct _SetBackgroundSlideshowDialogClass {
	GtkDialogClass parent_class;
};

struct _SetBackgroundSlideshowDialogPrivate {
	GtkCheckButton* desktop_background_checkbox;
	GtkCheckButton* screensaver_checkbox;
	GtkScale* delay_scale;
	GtkLabel* delay_value_label;
	gint delay_value;
};

static gint SetBackgroundSlideshowDialog_private_offset;
static gpointer set_background_slideshow_dialog_parent_class = NULL;

VALA_EXTERN GType set_background_slideshow_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetBackgroundSlideshowDialog, g_object_unref)
VALA_EXTERN SetBackgroundSlideshowDialog* set_background_slideshow_dialog_new (void);
VALA_EXTERN SetBackgroundSlideshowDialog* set_background_slideshow_dialog_construct (GType object_type);
VALA_EXTERN gint resources_use_header_bar (void);
VALA_EXTERN GType page_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PageWindow, g_object_unref)
VALA_EXTERN GType app_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AppWindow, g_object_unref)
VALA_EXTERN AppWindow* app_window_get_instance (void);
static void set_background_slideshow_dialog_real_constructed (GObject* base);
static void set_background_slideshow_dialog_on_delay_scale_value_changed (SetBackgroundSlideshowDialog* self);
static void set_background_slideshow_dialog_on_checkbox_clicked (SetBackgroundSlideshowDialog* self);
static void _set_background_slideshow_dialog_on_checkbox_clicked_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                     gpointer self);
static void _set_background_slideshow_dialog_on_delay_scale_value_changed_gtk_range_value_changed (GtkRange* _sender,
                                                                                            gpointer self);
VALA_EXTERN gboolean set_background_slideshow_dialog_execute (SetBackgroundSlideshowDialog* self,
                                                  gint* delay_value,
                                                  gboolean* desktop_background,
                                                  gboolean* screensaver);
static void set_background_slideshow_dialog_finalize (GObject * obj);
static GType set_background_slideshow_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
set_background_slideshow_dialog_get_instance_private (SetBackgroundSlideshowDialog* self)
{
	return G_STRUCT_MEMBER_P (self, SetBackgroundSlideshowDialog_private_offset);
}

SetBackgroundSlideshowDialog*
set_background_slideshow_dialog_construct (GType object_type)
{
	SetBackgroundSlideshowDialog * self = NULL;
	AppWindow* _tmp0_;
	AppWindow* _tmp1_;
	self = (SetBackgroundSlideshowDialog*) g_object_new (object_type, "use-header-bar", resources_use_header_bar (), NULL);
	_tmp0_ = app_window_get_instance ();
	_tmp1_ = _tmp0_;
	gtk_window_set_transient_for (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_window_get_type (), GtkWindow));
	_g_object_unref0 (_tmp1_);
	return self;
}

SetBackgroundSlideshowDialog*
set_background_slideshow_dialog_new (void)
{
	return set_background_slideshow_dialog_construct (TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG);
}

static void
set_background_slideshow_dialog_real_constructed (GObject* base)
{
	SetBackgroundSlideshowDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG, SetBackgroundSlideshowDialog);
	set_background_slideshow_dialog_on_delay_scale_value_changed (self);
}

static void
set_background_slideshow_dialog_on_checkbox_clicked (SetBackgroundSlideshowDialog* self)
{
	gboolean _tmp0_ = FALSE;
	GtkCheckButton* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (IS_SET_BACKGROUND_SLIDESHOW_DIALOG (self));
	_tmp1_ = self->priv->desktop_background_checkbox;
	_tmp2_ = gtk_toggle_button_get_active (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_toggle_button_get_type (), GtkToggleButton));
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		GtkCheckButton* _tmp4_;
		gboolean _tmp5_;
		gboolean _tmp6_;
		_tmp4_ = self->priv->screensaver_checkbox;
		_tmp5_ = gtk_toggle_button_get_active (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_toggle_button_get_type (), GtkToggleButton));
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_;
	}
	gtk_dialog_set_response_sensitive (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_dialog_get_type (), GtkDialog), (gint) GTK_RESPONSE_OK, _tmp0_);
}

static void
_set_background_slideshow_dialog_on_checkbox_clicked_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                gpointer self)
{
	set_background_slideshow_dialog_on_checkbox_clicked ((SetBackgroundSlideshowDialog*) self);
}

static void
set_background_slideshow_dialog_on_delay_scale_value_changed (SetBackgroundSlideshowDialog* self)
{
	gdouble value = 0.0;
	GtkScale* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gchar* text = NULL;
	GtkLabel* _tmp9_;
	const gchar* _tmp10_;
	g_return_if_fail (IS_SET_BACKGROUND_SLIDESHOW_DIALOG (self));
	_tmp0_ = self->priv->delay_scale;
	_tmp1_ = gtk_range_get_adjustment (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_range_get_type (), GtkRange));
	_tmp2_ = _tmp1_;
	_tmp3_ = gtk_adjustment_get_value (_tmp2_);
	_tmp4_ = _tmp3_;
	value = _tmp4_;
	self->priv->delay_value = (gint) (((((pow (value, (gdouble) 5) / pow ((gdouble) 90, (gdouble) 5)) * 60) * 60) * 24) + 5);
	if (self->priv->delay_value < 60) {
		gchar* _tmp5_;
		_tmp5_ = g_strdup_printf (ngettext ("%d second", "%d seconds", (gulong) self->priv->delay_value), self->priv->delay_value);
		_g_free0 (text);
		text = _tmp5_;
	} else {
		if (self->priv->delay_value < (60 * 60)) {
			gint minutes = 0;
			gchar* _tmp6_;
			minutes = self->priv->delay_value / 60;
			_tmp6_ = g_strdup_printf (ngettext ("%d minute", "%d minutes", (gulong) minutes), minutes);
			_g_free0 (text);
			text = _tmp6_;
			self->priv->delay_value = minutes * 60;
		} else {
			if (self->priv->delay_value < ((60 * 60) * 24)) {
				gint hours = 0;
				gchar* _tmp7_;
				hours = self->priv->delay_value / (60 * 60);
				_tmp7_ = g_strdup_printf (ngettext ("%d hour", "%d hours", (gulong) hours), hours);
				_g_free0 (text);
				text = _tmp7_;
				self->priv->delay_value = hours * (60 * 60);
			} else {
				gchar* _tmp8_;
				_tmp8_ = g_strdup (_ ("1 day"));
				_g_free0 (text);
				text = _tmp8_;
				self->priv->delay_value = (60 * 60) * 24;
			}
		}
	}
	_tmp9_ = self->priv->delay_value_label;
	_tmp10_ = text;
	gtk_label_set_label (_tmp9_, _tmp10_);
	_g_free0 (text);
}

static void
_set_background_slideshow_dialog_on_delay_scale_value_changed_gtk_range_value_changed (GtkRange* _sender,
                                                                                       gpointer self)
{
	set_background_slideshow_dialog_on_delay_scale_value_changed ((SetBackgroundSlideshowDialog*) self);
}

gboolean
set_background_slideshow_dialog_execute (SetBackgroundSlideshowDialog* self,
                                         gint* delay_value,
                                         gboolean* desktop_background,
                                         gboolean* screensaver)
{
	gint _vala_delay_value = 0;
	gboolean _vala_desktop_background = FALSE;
	gboolean _vala_screensaver = FALSE;
	gboolean _result_ = FALSE;
	GtkCheckButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GtkCheckButton* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean result;
	g_return_val_if_fail (IS_SET_BACKGROUND_SLIDESHOW_DIALOG (self), FALSE);
	gtk_widget_show_all (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	_result_ = gtk_dialog_run (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_dialog_get_type (), GtkDialog)) == ((gint) GTK_RESPONSE_OK);
	gtk_widget_hide (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	_vala_delay_value = self->priv->delay_value;
	_tmp0_ = self->priv->desktop_background_checkbox;
	_tmp1_ = gtk_toggle_button_get_active (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_toggle_button_get_type (), GtkToggleButton));
	_tmp2_ = _tmp1_;
	_vala_desktop_background = _tmp2_;
	_tmp3_ = self->priv->screensaver_checkbox;
	_tmp4_ = gtk_toggle_button_get_active (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_toggle_button_get_type (), GtkToggleButton));
	_tmp5_ = _tmp4_;
	_vala_screensaver = _tmp5_;
	gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	result = _result_;
	if (delay_value) {
		*delay_value = _vala_delay_value;
	}
	if (desktop_background) {
		*desktop_background = _vala_desktop_background;
	}
	if (screensaver) {
		*screensaver = _vala_screensaver;
	}
	return result;
}

static void
set_background_slideshow_dialog_class_init (SetBackgroundSlideshowDialogClass * klass,
                                            gpointer klass_data)
{
	set_background_slideshow_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SetBackgroundSlideshowDialog_private_offset);
	((GObjectClass *) klass)->constructed = (void (*) (GObject*)) set_background_slideshow_dialog_real_constructed;
	G_OBJECT_CLASS (klass)->finalize = set_background_slideshow_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Shotwell/ui/set_background_slideshow_dialog.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "desktop_background_checkbox", FALSE, SetBackgroundSlideshowDialog_private_offset + G_STRUCT_OFFSET (SetBackgroundSlideshowDialogPrivate, desktop_background_checkbox));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "screensaver_checkbox", FALSE, SetBackgroundSlideshowDialog_private_offset + G_STRUCT_OFFSET (SetBackgroundSlideshowDialogPrivate, screensaver_checkbox));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "delay_scale", FALSE, SetBackgroundSlideshowDialog_private_offset + G_STRUCT_OFFSET (SetBackgroundSlideshowDialogPrivate, delay_scale));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "delay_value_label", FALSE, SetBackgroundSlideshowDialog_private_offset + G_STRUCT_OFFSET (SetBackgroundSlideshowDialogPrivate, delay_value_label));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_checkbox_clicked", G_CALLBACK(_set_background_slideshow_dialog_on_checkbox_clicked_gtk_toggle_button_toggled));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_delay_scale_value_changed", G_CALLBACK(_set_background_slideshow_dialog_on_delay_scale_value_changed_gtk_range_value_changed));
}

static void
set_background_slideshow_dialog_instance_init (SetBackgroundSlideshowDialog * self,
                                               gpointer klass)
{
	self->priv = set_background_slideshow_dialog_get_instance_private (self);
	self->priv->delay_value = 0;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
set_background_slideshow_dialog_finalize (GObject * obj)
{
	SetBackgroundSlideshowDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SET_BACKGROUND_SLIDESHOW_DIALOG, SetBackgroundSlideshowDialog);
	G_OBJECT_CLASS (set_background_slideshow_dialog_parent_class)->finalize (obj);
}

static GType
set_background_slideshow_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SetBackgroundSlideshowDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) set_background_slideshow_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SetBackgroundSlideshowDialog), 0, (GInstanceInitFunc) set_background_slideshow_dialog_instance_init, NULL };
	GType set_background_slideshow_dialog_type_id;
	set_background_slideshow_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "SetBackgroundSlideshowDialog", &g_define_type_info, 0);
	SetBackgroundSlideshowDialog_private_offset = g_type_add_instance_private (set_background_slideshow_dialog_type_id, sizeof (SetBackgroundSlideshowDialogPrivate));
	return set_background_slideshow_dialog_type_id;
}

GType
set_background_slideshow_dialog_get_type (void)
{
	static volatile gsize set_background_slideshow_dialog_type_id__once = 0;
	if (g_once_init_enter (&set_background_slideshow_dialog_type_id__once)) {
		GType set_background_slideshow_dialog_type_id;
		set_background_slideshow_dialog_type_id = set_background_slideshow_dialog_get_type_once ();
		g_once_init_leave (&set_background_slideshow_dialog_type_id__once, set_background_slideshow_dialog_type_id);
	}
	return set_background_slideshow_dialog_type_id__once;
}

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;
}

