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

/*
 * This file is part of budgie-desktop
 * 
 * Copyright (C) 2015-2016 Ikey Doherty <ikey@solus-project.com>
 * 
 * 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.
 */

#include <glib.h>
#include <glib-object.h>
#include <libpeas/peas.h>
#include <plugin.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>


#define TYPE_LOCK_KEYS_PLUGIN (lock_keys_plugin_get_type ())
#define LOCK_KEYS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LOCK_KEYS_PLUGIN, LockKeysPlugin))
#define LOCK_KEYS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LOCK_KEYS_PLUGIN, LockKeysPluginClass))
#define IS_LOCK_KEYS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LOCK_KEYS_PLUGIN))
#define IS_LOCK_KEYS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LOCK_KEYS_PLUGIN))
#define LOCK_KEYS_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LOCK_KEYS_PLUGIN, LockKeysPluginClass))

typedef struct _LockKeysPlugin LockKeysPlugin;
typedef struct _LockKeysPluginClass LockKeysPluginClass;
typedef struct _LockKeysPluginPrivate LockKeysPluginPrivate;

#define TYPE_LOCK_KEYS_APPLET (lock_keys_applet_get_type ())
#define LOCK_KEYS_APPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LOCK_KEYS_APPLET, LockKeysApplet))
#define LOCK_KEYS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LOCK_KEYS_APPLET, LockKeysAppletClass))
#define IS_LOCK_KEYS_APPLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LOCK_KEYS_APPLET))
#define IS_LOCK_KEYS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LOCK_KEYS_APPLET))
#define LOCK_KEYS_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LOCK_KEYS_APPLET, LockKeysAppletClass))

typedef struct _LockKeysApplet LockKeysApplet;
typedef struct _LockKeysAppletClass LockKeysAppletClass;
typedef struct _LockKeysAppletPrivate LockKeysAppletPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _LockKeysPlugin {
	PeasExtensionBase parent_instance;
	LockKeysPluginPrivate * priv;
};

struct _LockKeysPluginClass {
	PeasExtensionBaseClass parent_class;
};

struct _LockKeysApplet {
	BudgieApplet parent_instance;
	LockKeysAppletPrivate * priv;
};

struct _LockKeysAppletClass {
	BudgieAppletClass parent_class;
};

struct _LockKeysAppletPrivate {
	GtkBox* widget;
	GtkImage* caps;
	GtkImage* num;
	GdkKeymap* map;
};


static gpointer lock_keys_plugin_parent_class = NULL;
static BudgiePluginIface* lock_keys_plugin_budgie_plugin_parent_iface = NULL;
static GType lock_keys_plugin_type_id = 0;
static gpointer lock_keys_applet_parent_class = NULL;
static GType lock_keys_applet_type_id = 0;

GType lock_keys_plugin_get_type (void) G_GNUC_CONST;
GType lock_keys_plugin_register_type (GTypeModule * module);
enum  {
	LOCK_KEYS_PLUGIN_DUMMY_PROPERTY
};
static BudgieApplet* lock_keys_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid);
LockKeysApplet* lock_keys_applet_new (void);
LockKeysApplet* lock_keys_applet_construct (GType object_type);
GType lock_keys_applet_get_type (void) G_GNUC_CONST;
GType lock_keys_applet_register_type (GTypeModule * module);
LockKeysPlugin* lock_keys_plugin_new (void);
LockKeysPlugin* lock_keys_plugin_construct (GType object_type);
#define LOCK_KEYS_APPLET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_LOCK_KEYS_APPLET, LockKeysAppletPrivate))
enum  {
	LOCK_KEYS_APPLET_DUMMY_PROPERTY
};
void lock_keys_applet_on_state_changed (LockKeysApplet* self);
static void _lock_keys_applet_on_state_changed_gdk_keymap_state_changed (GdkKeymap* _sender, gpointer self);
void lock_keys_applet_toggle_caps (LockKeysApplet* self);
void lock_keys_applet_toggle_num (LockKeysApplet* self);
static void lock_keys_applet_finalize (GObject* obj);
void peas_register_types (GTypeModule* module);


static BudgieApplet* lock_keys_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid) {
	LockKeysPlugin * self;
	BudgieApplet* result = NULL;
	LockKeysApplet* _tmp0_ = NULL;
	self = (LockKeysPlugin*) base;
	g_return_val_if_fail (uuid != NULL, NULL);
	_tmp0_ = lock_keys_applet_new ();
	g_object_ref_sink (_tmp0_);
	result = (BudgieApplet*) _tmp0_;
	return result;
}


LockKeysPlugin* lock_keys_plugin_construct (GType object_type) {
	LockKeysPlugin * self = NULL;
	self = (LockKeysPlugin*) g_object_new (object_type, NULL);
	return self;
}


LockKeysPlugin* lock_keys_plugin_new (void) {
	return lock_keys_plugin_construct (TYPE_LOCK_KEYS_PLUGIN);
}


static void lock_keys_plugin_class_init (LockKeysPluginClass * klass) {
	lock_keys_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void lock_keys_plugin_budgie_plugin_interface_init (BudgiePluginIface * iface) {
	lock_keys_plugin_budgie_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_panel_widget = (BudgieApplet* (*)(BudgiePlugin*, const gchar*)) lock_keys_plugin_real_get_panel_widget;
}


static void lock_keys_plugin_instance_init (LockKeysPlugin * self) {
}


GType lock_keys_plugin_get_type (void) {
	return lock_keys_plugin_type_id;
}


GType lock_keys_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (LockKeysPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) lock_keys_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LockKeysPlugin), 0, (GInstanceInitFunc) lock_keys_plugin_instance_init, NULL };
	static const GInterfaceInfo budgie_plugin_info = { (GInterfaceInitFunc) lock_keys_plugin_budgie_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	lock_keys_plugin_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "LockKeysPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, lock_keys_plugin_type_id, budgie_plugin_get_type (), &budgie_plugin_info);
	return lock_keys_plugin_type_id;
}


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


static void _lock_keys_applet_on_state_changed_gdk_keymap_state_changed (GdkKeymap* _sender, gpointer self) {
	lock_keys_applet_on_state_changed ((LockKeysApplet*) self);
}


LockKeysApplet* lock_keys_applet_construct (GType object_type) {
	LockKeysApplet * self = NULL;
	GtkBox* _tmp0_ = NULL;
	GtkBox* _tmp1_ = NULL;
	GtkStyleContext* _tmp2_ = NULL;
	GtkImage* _tmp3_ = NULL;
	GtkImage* _tmp4_ = NULL;
	GtkBox* _tmp5_ = NULL;
	GtkImage* _tmp6_ = NULL;
	GtkBox* _tmp7_ = NULL;
	GtkImage* _tmp8_ = NULL;
	GdkKeymap* _tmp9_ = NULL;
	GdkKeymap* _tmp10_ = NULL;
	GdkKeymap* _tmp11_ = NULL;
	self = (LockKeysApplet*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->widget);
	self->priv->widget = _tmp0_;
	_tmp1_ = self->priv->widget;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp1_);
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp2_, "lock-keys");
	_tmp3_ = (GtkImage*) gtk_image_new_from_icon_name ("caps-lock-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->caps);
	self->priv->caps = _tmp3_;
	_tmp4_ = (GtkImage*) gtk_image_new_from_icon_name ("num-lock-symbolic", GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->num);
	self->priv->num = _tmp4_;
	_tmp5_ = self->priv->widget;
	_tmp6_ = self->priv->caps;
	gtk_box_pack_start (_tmp5_, (GtkWidget*) _tmp6_, FALSE, FALSE, (guint) 0);
	_tmp7_ = self->priv->widget;
	_tmp8_ = self->priv->num;
	gtk_box_pack_start (_tmp7_, (GtkWidget*) _tmp8_, FALSE, FALSE, (guint) 0);
	_tmp9_ = gdk_keymap_get_default ();
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_g_object_unref0 (self->priv->map);
	self->priv->map = _tmp10_;
	_tmp11_ = self->priv->map;
	g_signal_connect_object (_tmp11_, "state-changed", (GCallback) _lock_keys_applet_on_state_changed_gdk_keymap_state_changed, self, 0);
	lock_keys_applet_on_state_changed (self);
	gtk_widget_show_all ((GtkWidget*) self);
	return self;
}


LockKeysApplet* lock_keys_applet_new (void) {
	return lock_keys_applet_construct (TYPE_LOCK_KEYS_APPLET);
}


void lock_keys_applet_toggle_caps (LockKeysApplet* self) {
	GtkImage* _tmp0_ = NULL;
	GdkKeymap* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GdkKeymap* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->caps;
	_tmp1_ = self->priv->map;
	_tmp2_ = gdk_keymap_get_caps_lock_state (_tmp1_);
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, _tmp2_);
	_tmp3_ = self->priv->map;
	_tmp4_ = gdk_keymap_get_caps_lock_state (_tmp3_);
	if (_tmp4_) {
		GtkImage* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		GtkImage* _tmp7_ = NULL;
		GtkStyleContext* _tmp8_ = NULL;
		_tmp5_ = self->priv->caps;
		_tmp6_ = _ ("Caps lock is active");
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp5_, _tmp6_);
		_tmp7_ = self->priv->caps;
		_tmp8_ = gtk_widget_get_style_context ((GtkWidget*) _tmp7_);
		gtk_style_context_remove_class (_tmp8_, "dim-label");
	} else {
		GtkImage* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		GtkImage* _tmp11_ = NULL;
		GtkStyleContext* _tmp12_ = NULL;
		_tmp9_ = self->priv->caps;
		_tmp10_ = _ ("Caps lock is not active");
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp9_, _tmp10_);
		_tmp11_ = self->priv->caps;
		_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
		gtk_style_context_add_class (_tmp12_, "dim-label");
	}
}


void lock_keys_applet_toggle_num (LockKeysApplet* self) {
	GtkImage* _tmp0_ = NULL;
	GdkKeymap* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GdkKeymap* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->num;
	_tmp1_ = self->priv->map;
	_tmp2_ = gdk_keymap_get_num_lock_state (_tmp1_);
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, _tmp2_);
	_tmp3_ = self->priv->map;
	_tmp4_ = gdk_keymap_get_num_lock_state (_tmp3_);
	if (_tmp4_) {
		GtkImage* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		GtkImage* _tmp7_ = NULL;
		GtkStyleContext* _tmp8_ = NULL;
		_tmp5_ = self->priv->num;
		_tmp6_ = _ ("Num lock is active");
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp5_, _tmp6_);
		_tmp7_ = self->priv->num;
		_tmp8_ = gtk_widget_get_style_context ((GtkWidget*) _tmp7_);
		gtk_style_context_remove_class (_tmp8_, "dim-label");
	} else {
		GtkImage* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		GtkImage* _tmp11_ = NULL;
		GtkStyleContext* _tmp12_ = NULL;
		_tmp9_ = self->priv->num;
		_tmp10_ = _ ("Num lock is not active");
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp9_, _tmp10_);
		_tmp11_ = self->priv->num;
		_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) _tmp11_);
		gtk_style_context_add_class (_tmp12_, "dim-label");
	}
}


void lock_keys_applet_on_state_changed (LockKeysApplet* self) {
	g_return_if_fail (self != NULL);
	lock_keys_applet_toggle_caps (self);
	lock_keys_applet_toggle_num (self);
}


static void lock_keys_applet_class_init (LockKeysAppletClass * klass) {
	lock_keys_applet_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (LockKeysAppletPrivate));
	G_OBJECT_CLASS (klass)->finalize = lock_keys_applet_finalize;
}


static void lock_keys_applet_instance_init (LockKeysApplet * self) {
	self->priv = LOCK_KEYS_APPLET_GET_PRIVATE (self);
}


static void lock_keys_applet_finalize (GObject* obj) {
	LockKeysApplet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_LOCK_KEYS_APPLET, LockKeysApplet);
	_g_object_unref0 (self->priv->widget);
	_g_object_unref0 (self->priv->caps);
	_g_object_unref0 (self->priv->num);
	_g_object_unref0 (self->priv->map);
	G_OBJECT_CLASS (lock_keys_applet_parent_class)->finalize (obj);
}


GType lock_keys_applet_get_type (void) {
	return lock_keys_applet_type_id;
}


GType lock_keys_applet_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (LockKeysAppletClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) lock_keys_applet_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LockKeysApplet), 0, (GInstanceInitFunc) lock_keys_applet_instance_init, NULL };
	lock_keys_applet_type_id = g_type_module_register_type (module, budgie_applet_get_type (), "LockKeysApplet", &g_define_type_info, 0);
	return lock_keys_applet_type_id;
}


void peas_register_types (GTypeModule* module) {
	PeasObjectModule* objmodule = NULL;
	GTypeModule* _tmp0_ = NULL;
	PeasObjectModule* _tmp1_ = NULL;
	g_return_if_fail (module != NULL);
	lock_keys_plugin_register_type (module);
	lock_keys_applet_register_type (module);
	_tmp0_ = module;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, peas_object_module_get_type ()) ? ((PeasObjectModule*) _tmp0_) : NULL);
	objmodule = _tmp1_;
	peas_object_module_register_extension_type (objmodule, budgie_plugin_get_type (), TYPE_LOCK_KEYS_PLUGIN);
	_g_object_unref0 (objmodule);
}



