/* CapsLockRevealer.c generated by valac 0.56.3, the Vala compiler
 * generated from CapsLockRevealer.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.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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_CAPS_LOCK_REVEALER (greeter_caps_lock_revealer_get_type ())
#define GREETER_CAPS_LOCK_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer))
#define GREETER_CAPS_LOCK_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealerClass))
#define GREETER_IS_CAPS_LOCK_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER))
#define GREETER_IS_CAPS_LOCK_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_TYPE_CAPS_LOCK_REVEALER))
#define GREETER_CAPS_LOCK_REVEALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealerClass))

typedef struct _GreeterCapsLockRevealer GreeterCapsLockRevealer;
typedef struct _GreeterCapsLockRevealerClass GreeterCapsLockRevealerClass;
typedef struct _GreeterCapsLockRevealerPrivate GreeterCapsLockRevealerPrivate;
enum  {
	GREETER_CAPS_LOCK_REVEALER_0_PROPERTY,
	GREETER_CAPS_LOCK_REVEALER_NUM_PROPERTIES
};
static GParamSpec* greeter_caps_lock_revealer_properties[GREETER_CAPS_LOCK_REVEALER_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))

struct _GreeterCapsLockRevealer {
	GtkRevealer parent_instance;
	GreeterCapsLockRevealerPrivate * priv;
};

struct _GreeterCapsLockRevealerClass {
	GtkRevealerClass parent_class;
};

struct _GreeterCapsLockRevealerPrivate {
	GdkKeymap* keymap;
	GtkImage* caps_lock_image;
	GtkImage* num_lock_image;
	GtkLabel* lock_label;
};

static gint GreeterCapsLockRevealer_private_offset;
static gpointer greeter_caps_lock_revealer_parent_class = NULL;

VALA_EXTERN GType greeter_caps_lock_revealer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterCapsLockRevealer, g_object_unref)
static void greeter_caps_lock_revealer_update_visibility (GreeterCapsLockRevealer* self);
VALA_EXTERN GreeterCapsLockRevealer* greeter_caps_lock_revealer_new (void);
VALA_EXTERN GreeterCapsLockRevealer* greeter_caps_lock_revealer_construct (GType object_type);
static GObject * greeter_caps_lock_revealer_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed (GdkKeymap* _sender,
                                                                             gpointer self);
static void greeter_caps_lock_revealer_finalize (GObject * obj);
static GType greeter_caps_lock_revealer_get_type_once (void);

static inline gpointer
greeter_caps_lock_revealer_get_instance_private (GreeterCapsLockRevealer* self)
{
	return G_STRUCT_MEMBER_P (self, GreeterCapsLockRevealer_private_offset);
}

static void
greeter_caps_lock_revealer_update_visibility (GreeterCapsLockRevealer* self)
{
	const gchar* label = NULL;
	gboolean caps_lock = FALSE;
	GdkKeymap* _tmp0_;
	gboolean num_lock = FALSE;
	GdkKeymap* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkImage* _tmp3_;
	GtkImage* _tmp4_;
	GtkImage* _tmp5_;
	GtkImage* _tmp6_;
	gboolean _tmp7_ = FALSE;
	const gchar* _tmp8_;
	g_return_if_fail (self != NULL);
	label = NULL;
	_tmp0_ = self->priv->keymap;
	caps_lock = gdk_keymap_get_caps_lock_state (_tmp0_);
	_tmp1_ = self->priv->keymap;
	num_lock = gdk_keymap_get_num_lock_state (_tmp1_);
	if (caps_lock) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = num_lock;
	}
	gtk_revealer_set_reveal_child ((GtkRevealer*) self, _tmp2_);
	_tmp3_ = self->priv->caps_lock_image;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp3_, !caps_lock);
	_tmp4_ = self->priv->num_lock_image;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp4_, !num_lock);
	_tmp5_ = self->priv->caps_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp5_, caps_lock);
	_tmp6_ = self->priv->num_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp6_, num_lock);
	if (caps_lock) {
		_tmp7_ = num_lock;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		label = _ ("Caps Lock & Num Lock are on");
	} else {
		if (caps_lock) {
			label = _ ("Caps Lock is on");
		} else {
			if (num_lock) {
				label = _ ("Num Lock is on");
			}
		}
	}
	_tmp8_ = label;
	if (_tmp8_ == NULL) {
		GtkLabel* _tmp9_;
		_tmp9_ = self->priv->lock_label;
		gtk_label_set_label (_tmp9_, NULL);
	} else {
		GtkLabel* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp10_ = self->priv->lock_label;
		_tmp11_ = label;
		_tmp12_ = g_markup_escape_text (_tmp11_, (gssize) -1);
		_tmp13_ = _tmp12_;
		_tmp14_ = g_strdup_printf ("<small>%s</small>", _tmp13_);
		_tmp15_ = _tmp14_;
		gtk_label_set_label (_tmp10_, _tmp15_);
		_g_free0 (_tmp15_);
		_g_free0 (_tmp13_);
	}
}

GreeterCapsLockRevealer*
greeter_caps_lock_revealer_construct (GType object_type)
{
	GreeterCapsLockRevealer * self = NULL;
	self = (GreeterCapsLockRevealer*) g_object_new (object_type, NULL);
	return self;
}

GreeterCapsLockRevealer*
greeter_caps_lock_revealer_new (void)
{
	return greeter_caps_lock_revealer_construct (GREETER_TYPE_CAPS_LOCK_REVEALER);
}

static void
_greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed (GdkKeymap* _sender,
                                                                        gpointer self)
{
	greeter_caps_lock_revealer_update_visibility ((GreeterCapsLockRevealer*) self);
}

static GObject *
greeter_caps_lock_revealer_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GreeterCapsLockRevealer * self;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	GtkImage* _tmp2_;
	GtkImage* _tmp3_;
	GtkImage* _tmp4_;
	GtkImage* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkGrid* caps_lock_grid = NULL;
	GtkGrid* _tmp8_;
	GtkGrid* _tmp9_;
	GtkGrid* _tmp10_;
	GtkGrid* _tmp11_;
	GtkStyleContext* _tmp12_;
	GtkGrid* _tmp13_;
	GtkImage* _tmp14_;
	GtkGrid* _tmp15_;
	GtkImage* _tmp16_;
	GtkGrid* _tmp17_;
	GtkLabel* _tmp18_;
	GtkGrid* _tmp19_;
	GdkDisplay* _tmp20_;
	GdkKeymap* _tmp21_;
	GdkKeymap* _tmp22_;
	parent_class = G_OBJECT_CLASS (greeter_caps_lock_revealer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer);
	gtk_revealer_set_transition_type ((GtkRevealer*) self, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("input-keyboard-capslock-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->caps_lock_image);
	self->priv->caps_lock_image = _tmp0_;
	_tmp1_ = self->priv->caps_lock_image;
	g_object_set (_tmp1_, "use-fallback", TRUE, NULL);
	_tmp2_ = self->priv->caps_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp2_, FALSE);
	_tmp3_ = (GtkImage*) gtk_image_new_from_icon_name ("input-keyboard-numlock-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->num_lock_image);
	self->priv->num_lock_image = _tmp3_;
	_tmp4_ = self->priv->num_lock_image;
	g_object_set (_tmp4_, "use-fallback", TRUE, NULL);
	_tmp5_ = self->priv->num_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp5_, FALSE);
	_tmp6_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->lock_label);
	self->priv->lock_label = _tmp6_;
	_tmp7_ = self->priv->lock_label;
	gtk_label_set_use_markup (_tmp7_, TRUE);
	_tmp8_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp8_);
	caps_lock_grid = _tmp8_;
	_tmp9_ = caps_lock_grid;
	gtk_grid_set_column_spacing (_tmp9_, 3);
	_tmp10_ = caps_lock_grid;
	gtk_widget_set_halign ((GtkWidget*) _tmp10_, GTK_ALIGN_CENTER);
	_tmp11_ = caps_lock_grid;
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
	gtk_style_context_add_class (_tmp12_, GTK_STYLE_CLASS_DIM_LABEL);
	_tmp13_ = caps_lock_grid;
	_tmp14_ = self->priv->caps_lock_image;
	gtk_container_add ((GtkContainer*) _tmp13_, (GtkWidget*) _tmp14_);
	_tmp15_ = caps_lock_grid;
	_tmp16_ = self->priv->num_lock_image;
	gtk_container_add ((GtkContainer*) _tmp15_, (GtkWidget*) _tmp16_);
	_tmp17_ = caps_lock_grid;
	_tmp18_ = self->priv->lock_label;
	gtk_container_add ((GtkContainer*) _tmp17_, (GtkWidget*) _tmp18_);
	_tmp19_ = caps_lock_grid;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp19_);
	_tmp20_ = gdk_display_get_default ();
	_tmp21_ = gdk_keymap_get_for_display (_tmp20_);
	self->priv->keymap = _tmp21_;
	_tmp22_ = self->priv->keymap;
	g_signal_connect_object (_tmp22_, "state-changed", (GCallback) _greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed, self, 0);
	greeter_caps_lock_revealer_update_visibility (self);
	_g_object_unref0 (caps_lock_grid);
	return obj;
}

static void
greeter_caps_lock_revealer_class_init (GreeterCapsLockRevealerClass * klass,
                                       gpointer klass_data)
{
	greeter_caps_lock_revealer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GreeterCapsLockRevealer_private_offset);
	G_OBJECT_CLASS (klass)->constructor = greeter_caps_lock_revealer_constructor;
	G_OBJECT_CLASS (klass)->finalize = greeter_caps_lock_revealer_finalize;
}

static void
greeter_caps_lock_revealer_instance_init (GreeterCapsLockRevealer * self,
                                          gpointer klass)
{
	self->priv = greeter_caps_lock_revealer_get_instance_private (self);
}

static void
greeter_caps_lock_revealer_finalize (GObject * obj)
{
	GreeterCapsLockRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer);
	_g_object_unref0 (self->priv->caps_lock_image);
	_g_object_unref0 (self->priv->num_lock_image);
	_g_object_unref0 (self->priv->lock_label);
	G_OBJECT_CLASS (greeter_caps_lock_revealer_parent_class)->finalize (obj);
}

static GType
greeter_caps_lock_revealer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GreeterCapsLockRevealerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) greeter_caps_lock_revealer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GreeterCapsLockRevealer), 0, (GInstanceInitFunc) greeter_caps_lock_revealer_instance_init, NULL };
	GType greeter_caps_lock_revealer_type_id;
	greeter_caps_lock_revealer_type_id = g_type_register_static (gtk_revealer_get_type (), "GreeterCapsLockRevealer", &g_define_type_info, 0);
	GreeterCapsLockRevealer_private_offset = g_type_add_instance_private (greeter_caps_lock_revealer_type_id, sizeof (GreeterCapsLockRevealerPrivate));
	return greeter_caps_lock_revealer_type_id;
}

GType
greeter_caps_lock_revealer_get_type (void)
{
	static volatile gsize greeter_caps_lock_revealer_type_id__once = 0;
	if (g_once_init_enter (&greeter_caps_lock_revealer_type_id__once)) {
		GType greeter_caps_lock_revealer_type_id;
		greeter_caps_lock_revealer_type_id = greeter_caps_lock_revealer_get_type_once ();
		g_once_init_leave (&greeter_caps_lock_revealer_type_id__once, greeter_caps_lock_revealer_type_id);
	}
	return greeter_caps_lock_revealer_type_id__once;
}

