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

/*
 * Copyright 2018 elementary, Inc. (https://elementary.io)
 *
 * 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 2 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.
 *
 * Authors: Corentin Noël <corentin@elementary.io>
 */

#include <glib-object.h>
#include <meta/meta-background-actor.h>
#include <clutter/clutter.h>
#include <glib.h>
#include <meta/meta-background.h>
#include <meta/display.h>
#include <gio/gio.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>
#include <meta/meta-background-content.h>

#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 GREETER_TYPE_SYSTEM_BACKGROUND (greeter_system_background_get_type ())
#define GREETER_SYSTEM_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackground))
#define GREETER_SYSTEM_BACKGROUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackgroundClass))
#define GREETER_IS_SYSTEM_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_TYPE_SYSTEM_BACKGROUND))
#define GREETER_IS_SYSTEM_BACKGROUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_TYPE_SYSTEM_BACKGROUND))
#define GREETER_SYSTEM_BACKGROUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackgroundClass))

typedef struct _GreeterSystemBackground GreeterSystemBackground;
typedef struct _GreeterSystemBackgroundClass GreeterSystemBackgroundClass;
typedef struct _GreeterSystemBackgroundPrivate GreeterSystemBackgroundPrivate;
enum  {
	GREETER_SYSTEM_BACKGROUND_0_PROPERTY,
	GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY,
	GREETER_SYSTEM_BACKGROUND_NUM_PROPERTIES
};
static GParamSpec* greeter_system_background_properties[GREETER_SYSTEM_BACKGROUND_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GREETER_SYSTEM_BACKGROUND_LOADED_SIGNAL,
	GREETER_SYSTEM_BACKGROUND_NUM_SIGNALS
};
static guint greeter_system_background_signals[GREETER_SYSTEM_BACKGROUND_NUM_SIGNALS] = {0};

struct _GreeterSystemBackground {
	GObject parent_instance;
	GreeterSystemBackgroundPrivate * priv;
};

struct _GreeterSystemBackgroundClass {
	GObjectClass parent_class;
};

struct _GreeterSystemBackgroundPrivate {
	MetaBackgroundActor* _background_actor;
};

static gint GreeterSystemBackground_private_offset;
static gpointer greeter_system_background_parent_class = NULL;
static MetaBackground* greeter_system_background_system_background;
static MetaBackground* greeter_system_background_system_background = NULL;

VALA_EXTERN GType greeter_system_background_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterSystemBackground, g_object_unref)
VALA_EXTERN GreeterSystemBackground* greeter_system_background_new (MetaDisplay* display);
VALA_EXTERN GreeterSystemBackground* greeter_system_background_construct (GType object_type,
                                                              MetaDisplay* display);
VALA_EXTERN void greeter_system_background_refresh (GreeterSystemBackground* self);
VALA_EXTERN MetaBackgroundActor* greeter_system_background_get_background_actor (GreeterSystemBackground* self);
static void greeter_system_background_set_background_actor (GreeterSystemBackground* self,
                                                     MetaBackgroundActor* value);
static GObject * greeter_system_background_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void greeter_system_background_finalize (GObject * obj);
static GType greeter_system_background_get_type_once (void);
static void _vala_greeter_system_background_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_greeter_system_background_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static const ClutterColor GREETER_SYSTEM_BACKGROUND_DEFAULT_BACKGROUND_COLOR = {(guint8) 0x2e, (guint8) 0x34, (guint8) 0x36, (guint8) 0xff};

static inline gpointer
greeter_system_background_get_instance_private (GreeterSystemBackground* self)
{
	return G_STRUCT_MEMBER_P (self, GreeterSystemBackground_private_offset);
}

GreeterSystemBackground*
greeter_system_background_construct (GType object_type,
                                     MetaDisplay* display)
{
	GreeterSystemBackground * self = NULL;
	MetaBackgroundActor* _tmp0_;
	MetaBackgroundActor* _tmp1_;
	g_return_val_if_fail (display != NULL, NULL);
	_tmp0_ = (MetaBackgroundActor*) meta_background_actor_new (display, 0);
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	self = (GreeterSystemBackground*) g_object_new (object_type, "background-actor", _tmp1_, NULL);
	_g_object_unref0 (_tmp1_);
	return self;
}

GreeterSystemBackground*
greeter_system_background_new (MetaDisplay* display)
{
	return greeter_system_background_construct (GREETER_TYPE_SYSTEM_BACKGROUND, display);
}

void
greeter_system_background_refresh (GreeterSystemBackground* self)
{
	MetaBackground* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = greeter_system_background_system_background;
	if (_tmp0_ != NULL) {
		MetaBackground* _tmp1_;
		_tmp1_ = greeter_system_background_system_background;
		meta_background_set_color (_tmp1_, &GREETER_SYSTEM_BACKGROUND_DEFAULT_BACKGROUND_COLOR);
	}
}

MetaBackgroundActor*
greeter_system_background_get_background_actor (GreeterSystemBackground* self)
{
	MetaBackgroundActor* result;
	MetaBackgroundActor* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_background_actor;
	result = _tmp0_;
	return result;
}

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

static void
greeter_system_background_set_background_actor (GreeterSystemBackground* self,
                                                MetaBackgroundActor* value)
{
	MetaBackgroundActor* old_value;
	g_return_if_fail (self != NULL);
	old_value = greeter_system_background_get_background_actor (self);
	if (old_value != value) {
		MetaBackgroundActor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_background_actor);
		self->priv->_background_actor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, greeter_system_background_properties[GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY]);
	}
}

static GObject *
greeter_system_background_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GreeterSystemBackground * self;
	MetaBackground* _tmp0_;
	MetaBackgroundActor* _tmp10_;
	ClutterContent* _tmp11_;
	ClutterContent* _tmp12_;
	MetaBackground* _tmp13_;
	parent_class = G_OBJECT_CLASS (greeter_system_background_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackground);
	_tmp0_ = greeter_system_background_system_background;
	if (_tmp0_ == NULL) {
		MetaBackgroundActor* _tmp1_;
		MetaDisplay* _tmp2_;
		MetaDisplay* _tmp3_;
		MetaDisplay* _tmp4_;
		MetaBackground* _tmp5_;
		GFile* texture_file = NULL;
		GFile* _tmp6_;
		MetaBackground* _tmp7_;
		MetaBackground* _tmp8_;
		GFile* _tmp9_;
		_tmp1_ = self->priv->_background_actor;
		g_object_get (_tmp1_, "meta-display", &_tmp2_, NULL);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = meta_background_new (_tmp4_);
		_g_object_unref0 (greeter_system_background_system_background);
		greeter_system_background_system_background = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_tmp6_ = g_file_new_for_uri ("resource:///io/elementary/desktop/gala/texture.png");
		texture_file = _tmp6_;
		_tmp7_ = greeter_system_background_system_background;
		meta_background_set_color (_tmp7_, &GREETER_SYSTEM_BACKGROUND_DEFAULT_BACKGROUND_COLOR);
		_tmp8_ = greeter_system_background_system_background;
		_tmp9_ = texture_file;
		meta_background_set_file (_tmp8_, _tmp9_, G_DESKTOP_BACKGROUND_STYLE_WALLPAPER);
		_g_object_unref0 (texture_file);
	}
	_tmp10_ = self->priv->_background_actor;
	_tmp11_ = clutter_actor_get_content ((ClutterActor*) _tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = greeter_system_background_system_background;
	g_object_set (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, meta_background_content_get_type (), MetaBackgroundContent), "background", _tmp13_, NULL);
	return obj;
}

static void
greeter_system_background_class_init (GreeterSystemBackgroundClass * klass,
                                      gpointer klass_data)
{
	greeter_system_background_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GreeterSystemBackground_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_greeter_system_background_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_greeter_system_background_set_property;
	G_OBJECT_CLASS (klass)->constructor = greeter_system_background_constructor;
	G_OBJECT_CLASS (klass)->finalize = greeter_system_background_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY, greeter_system_background_properties[GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY] = g_param_spec_object ("background-actor", "background-actor", "background-actor", meta_background_actor_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	greeter_system_background_signals[GREETER_SYSTEM_BACKGROUND_LOADED_SIGNAL] = g_signal_new ("loaded", GREETER_TYPE_SYSTEM_BACKGROUND, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
greeter_system_background_instance_init (GreeterSystemBackground * self,
                                         gpointer klass)
{
	self->priv = greeter_system_background_get_instance_private (self);
}

static void
greeter_system_background_finalize (GObject * obj)
{
	GreeterSystemBackground * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackground);
	_g_object_unref0 (self->priv->_background_actor);
	G_OBJECT_CLASS (greeter_system_background_parent_class)->finalize (obj);
}

static GType
greeter_system_background_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GreeterSystemBackgroundClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) greeter_system_background_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GreeterSystemBackground), 0, (GInstanceInitFunc) greeter_system_background_instance_init, NULL };
	GType greeter_system_background_type_id;
	greeter_system_background_type_id = g_type_register_static (G_TYPE_OBJECT, "GreeterSystemBackground", &g_define_type_info, 0);
	GreeterSystemBackground_private_offset = g_type_add_instance_private (greeter_system_background_type_id, sizeof (GreeterSystemBackgroundPrivate));
	return greeter_system_background_type_id;
}

GType
greeter_system_background_get_type (void)
{
	static volatile gsize greeter_system_background_type_id__once = 0;
	if (g_once_init_enter (&greeter_system_background_type_id__once)) {
		GType greeter_system_background_type_id;
		greeter_system_background_type_id = greeter_system_background_get_type_once ();
		g_once_init_leave (&greeter_system_background_type_id__once, greeter_system_background_type_id);
	}
	return greeter_system_background_type_id__once;
}

static void
_vala_greeter_system_background_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GreeterSystemBackground * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackground);
	switch (property_id) {
		case GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY:
		g_value_set_object (value, greeter_system_background_get_background_actor (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_greeter_system_background_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GreeterSystemBackground * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GREETER_TYPE_SYSTEM_BACKGROUND, GreeterSystemBackground);
	switch (property_id) {
		case GREETER_SYSTEM_BACKGROUND_BACKGROUND_ACTOR_PROPERTY:
		greeter_system_background_set_background_actor (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

