/* TrayApplet.c generated by valac 0.32.1, the Vala compiler
 * generated from TrayApplet.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 <na-tray.h>
#include <gtk/gtk.h>
#include <cairo.h>
#include <gdk/gdk.h>


#define TYPE_TRAY_PLUGIN (tray_plugin_get_type ())
#define TRAY_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TRAY_PLUGIN, TrayPlugin))
#define TRAY_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TRAY_PLUGIN, TrayPluginClass))
#define IS_TRAY_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TRAY_PLUGIN))
#define IS_TRAY_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TRAY_PLUGIN))
#define TRAY_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TRAY_PLUGIN, TrayPluginClass))

typedef struct _TrayPlugin TrayPlugin;
typedef struct _TrayPluginClass TrayPluginClass;
typedef struct _TrayPluginPrivate TrayPluginPrivate;

#define TYPE_TRAY_APPLET (tray_applet_get_type ())
#define TRAY_APPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TRAY_APPLET, TrayApplet))
#define TRAY_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TRAY_APPLET, TrayAppletClass))
#define IS_TRAY_APPLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TRAY_APPLET))
#define IS_TRAY_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TRAY_APPLET))
#define TRAY_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TRAY_APPLET, TrayAppletClass))

typedef struct _TrayApplet TrayApplet;
typedef struct _TrayAppletClass TrayAppletClass;
typedef struct _TrayAppletPrivate TrayAppletPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _TrayPlugin {
	PeasExtensionBase parent_instance;
	TrayPluginPrivate * priv;
};

struct _TrayPluginClass {
	PeasExtensionBaseClass parent_class;
};

struct _TrayApplet {
	BudgieApplet parent_instance;
	TrayAppletPrivate * priv;
	NaTray* tray;
	gint icon_size;
};

struct _TrayAppletClass {
	BudgieAppletClass parent_class;
};

struct _TrayAppletPrivate {
	GtkEventBox* box;
	gint width;
	gint height;
};


static gpointer tray_plugin_parent_class = NULL;
static BudgiePluginIface* tray_plugin_budgie_plugin_parent_iface = NULL;
static GType tray_plugin_type_id = 0;
static gpointer tray_applet_parent_class = NULL;
static GType tray_applet_type_id = 0;

GType tray_plugin_get_type (void) G_GNUC_CONST;
GType tray_plugin_register_type (GTypeModule * module);
enum  {
	TRAY_PLUGIN_DUMMY_PROPERTY
};
static BudgieApplet* tray_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid);
TrayApplet* tray_applet_new (void);
TrayApplet* tray_applet_construct (GType object_type);
GType tray_applet_get_type (void) G_GNUC_CONST;
GType tray_applet_register_type (GTypeModule * module);
TrayPlugin* tray_plugin_new (void);
TrayPlugin* tray_plugin_construct (GType object_type);
#define TRAY_APPLET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_TRAY_APPLET, TrayAppletPrivate))
enum  {
	TRAY_APPLET_DUMMY_PROPERTY
};
static void __lambda4_ (TrayApplet* self);
void tray_applet_maybe_integrate_tray (TrayApplet* self);
static void ___lambda4__gtk_widget_map (GtkWidget* _sender, gpointer self);
static void __lambda5_ (TrayApplet* self, gint p, gint i, gint s);
static void ___lambda5__budgie_applet_panel_size_changed (BudgieApplet* _sender, gint panel_size, gint icon_size, gint small_icon_size, gpointer self);
static void tray_applet_on_size_allocate (TrayApplet* self, GtkAllocation* alloc);
static void _tray_applet_on_size_allocate_gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self);
static void tray_applet_real_get_preferred_height (GtkWidget* base, gint* m, gint* n);
static void tray_applet_real_get_preferred_height_for_width (GtkWidget* base, gint w, gint* m, gint* n);
static void tray_applet_finalize (GObject* obj);
void peas_register_types (GTypeModule* module);


static BudgieApplet* tray_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid) {
	TrayPlugin * self;
	BudgieApplet* result = NULL;
	TrayApplet* _tmp0_ = NULL;
	self = (TrayPlugin*) base;
	g_return_val_if_fail (uuid != NULL, NULL);
	_tmp0_ = tray_applet_new ();
	g_object_ref_sink (_tmp0_);
	result = (BudgieApplet*) _tmp0_;
	return result;
}


TrayPlugin* tray_plugin_construct (GType object_type) {
	TrayPlugin * self = NULL;
	self = (TrayPlugin*) g_object_new (object_type, NULL);
	return self;
}


TrayPlugin* tray_plugin_new (void) {
	return tray_plugin_construct (TYPE_TRAY_PLUGIN);
}


static void tray_plugin_class_init (TrayPluginClass * klass) {
	tray_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void tray_plugin_budgie_plugin_interface_init (BudgiePluginIface * iface) {
	tray_plugin_budgie_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_panel_widget = (BudgieApplet* (*)(BudgiePlugin*, const gchar*)) tray_plugin_real_get_panel_widget;
}


static void tray_plugin_instance_init (TrayPlugin * self) {
}


GType tray_plugin_get_type (void) {
	return tray_plugin_type_id;
}


GType tray_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (TrayPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tray_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TrayPlugin), 0, (GInstanceInitFunc) tray_plugin_instance_init, NULL };
	static const GInterfaceInfo budgie_plugin_info = { (GInterfaceInitFunc) tray_plugin_budgie_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	tray_plugin_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "TrayPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, tray_plugin_type_id, budgie_plugin_get_type (), &budgie_plugin_info);
	return tray_plugin_type_id;
}


static void __lambda4_ (TrayApplet* self) {
	tray_applet_maybe_integrate_tray (self);
}


static void ___lambda4__gtk_widget_map (GtkWidget* _sender, gpointer self) {
	__lambda4_ ((TrayApplet*) self);
}


static void __lambda5_ (TrayApplet* self, gint p, gint i, gint s) {
	gint _tmp0_ = 0;
	NaTray* _tmp1_ = NULL;
	_tmp0_ = s;
	self->icon_size = _tmp0_;
	_tmp1_ = self->tray;
	if (_tmp1_ != NULL) {
		NaTray* _tmp2_ = NULL;
		gint _tmp3_ = 0;
		NaTray* _tmp4_ = NULL;
		NaTray* _tmp5_ = NULL;
		_tmp2_ = self->tray;
		_tmp3_ = self->icon_size;
		na_tray_set_icon_size (_tmp2_, _tmp3_);
		gtk_widget_queue_resize ((GtkWidget*) self);
		_tmp4_ = self->tray;
		gtk_widget_queue_resize ((GtkWidget*) _tmp4_);
		_tmp5_ = self->tray;
		na_tray_force_redraw (_tmp5_);
	}
}


static void ___lambda5__budgie_applet_panel_size_changed (BudgieApplet* _sender, gint panel_size, gint icon_size, gint small_icon_size, gpointer self) {
	__lambda5_ ((TrayApplet*) self, panel_size, icon_size, small_icon_size);
}


static void _tray_applet_on_size_allocate_gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self) {
	tray_applet_on_size_allocate ((TrayApplet*) self, allocation);
}


TrayApplet* tray_applet_construct (GType object_type) {
	TrayApplet * self = NULL;
	GtkEventBox* _tmp0_ = NULL;
	GtkEventBox* _tmp1_ = NULL;
	GtkEventBox* _tmp2_ = NULL;
	GtkEventBox* _tmp3_ = NULL;
	self = (TrayApplet*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkEventBox*) gtk_event_box_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->box);
	self->priv->box = _tmp0_;
	_tmp1_ = self->priv->box;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp1_);
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	_tmp2_ = self->priv->box;
	gtk_widget_set_valign ((GtkWidget*) _tmp2_, GTK_ALIGN_CENTER);
	_tmp3_ = self->priv->box;
	gtk_widget_set_vexpand ((GtkWidget*) _tmp3_, FALSE);
	gtk_widget_set_vexpand ((GtkWidget*) self, FALSE);
	g_signal_connect_object ((GtkWidget*) self, "map", (GCallback) ___lambda4__gtk_widget_map, self, G_CONNECT_AFTER);
	gtk_widget_show_all ((GtkWidget*) self);
	g_signal_connect_object ((BudgieApplet*) self, "panel-size-changed", (GCallback) ___lambda5__budgie_applet_panel_size_changed, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "size-allocate", (GCallback) _tray_applet_on_size_allocate_gtk_widget_size_allocate, self, 0);
	return self;
}


TrayApplet* tray_applet_new (void) {
	return tray_applet_construct (TYPE_TRAY_APPLET);
}


static void tray_applet_on_size_allocate (TrayApplet* self, GtkAllocation* alloc) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gint _tmp4_ = 0;
	GtkAllocation _tmp5_ = {0};
	gint _tmp6_ = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (alloc != NULL);
	_tmp1_ = gtk_widget_get_realized ((GtkWidget*) self);
	if (!_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		GtkContainer* _tmp2_ = NULL;
		_tmp2_ = (GtkContainer*) gtk_widget_get_parent ((GtkWidget*) self);
		_tmp0_ = _tmp2_ == NULL;
	}
	if (_tmp0_) {
		return;
	}
	_tmp4_ = self->priv->width;
	_tmp5_ = *alloc;
	_tmp6_ = _tmp5_.width;
	if (_tmp4_ != _tmp6_) {
		_tmp3_ = TRUE;
	} else {
		gint _tmp7_ = 0;
		GtkAllocation _tmp8_ = {0};
		gint _tmp9_ = 0;
		_tmp7_ = self->priv->height;
		_tmp8_ = *alloc;
		_tmp9_ = _tmp8_.height;
		_tmp3_ = _tmp7_ != _tmp9_;
	}
	if (_tmp3_) {
		GtkAllocation _tmp10_ = {0};
		gint _tmp11_ = 0;
		GtkAllocation _tmp12_ = {0};
		gint _tmp13_ = 0;
		GtkContainer* _tmp14_ = NULL;
		GtkWidget* _tmp15_ = NULL;
		_tmp10_ = *alloc;
		_tmp11_ = _tmp10_.width;
		self->priv->width = _tmp11_;
		_tmp12_ = *alloc;
		_tmp13_ = _tmp12_.height;
		self->priv->height = _tmp13_;
		_tmp14_ = (GtkContainer*) gtk_widget_get_parent ((GtkWidget*) self);
		gtk_widget_queue_resize ((GtkWidget*) _tmp14_);
		_tmp15_ = gtk_widget_get_toplevel ((GtkWidget*) self);
		gtk_widget_queue_resize (_tmp15_);
	}
}


static void tray_applet_real_get_preferred_height (GtkWidget* base, gint* m, gint* n) {
	TrayApplet * self;
	gint _vala_m = 0;
	gint _vala_n = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	self = (TrayApplet*) base;
	_tmp0_ = self->icon_size;
	_vala_m = _tmp0_;
	_tmp1_ = self->icon_size;
	_vala_n = _tmp1_;
	if (m) {
		*m = _vala_m;
	}
	if (n) {
		*n = _vala_n;
	}
}


static void tray_applet_real_get_preferred_height_for_width (GtkWidget* base, gint w, gint* m, gint* n) {
	TrayApplet * self;
	gint _vala_m = 0;
	gint _vala_n = 0;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	self = (TrayApplet*) base;
	_tmp0_ = self->icon_size;
	_vala_m = _tmp0_;
	_tmp1_ = self->icon_size;
	_vala_n = _tmp1_;
	if (m) {
		*m = _vala_m;
	}
	if (n) {
		*n = _vala_n;
	}
}


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


void tray_applet_maybe_integrate_tray (TrayApplet* self) {
	NaTray* _tmp0_ = NULL;
	GdkScreen* _tmp1_ = NULL;
	NaTray* _tmp2_ = NULL;
	NaTray* _tmp3_ = NULL;
	NaTray* _tmp7_ = NULL;
	gint _tmp8_ = 0;
	GdkColor fg = {0};
	GdkColor warning = {0};
	GdkColor _error_ = {0};
	GdkColor success = {0};
	GdkColor _tmp9_ = {0};
	GdkColor _tmp10_ = {0};
	GdkColor _tmp11_ = {0};
	GdkColor _tmp12_ = {0};
	NaTray* _tmp13_ = NULL;
	GdkColor _tmp14_ = {0};
	GdkColor _tmp15_ = {0};
	GdkColor _tmp16_ = {0};
	GdkColor _tmp17_ = {0};
	GtkEventBox* _tmp18_ = NULL;
	NaTray* _tmp19_ = NULL;
	GtkWidget* win = NULL;
	GtkWidget* _tmp20_ = NULL;
	GtkWidget* _tmp21_ = NULL;
	GtkWidget* _tmp22_ = NULL;
	GtkWidget* _tmp23_ = NULL;
	NaTray* _tmp24_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->tray;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp1_ = gtk_widget_get_screen ((GtkWidget*) self);
	_tmp2_ = (NaTray*) na_tray_new_for_screen (_tmp1_, GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->tray);
	self->tray = _tmp2_;
	_tmp3_ = self->tray;
	if (_tmp3_ == NULL) {
		GtkLabel* label = NULL;
		GtkLabel* _tmp4_ = NULL;
		GtkLabel* _tmp5_ = NULL;
		GtkLabel* _tmp6_ = NULL;
		_tmp4_ = (GtkLabel*) gtk_label_new ("Tray unavailable");
		g_object_ref_sink (_tmp4_);
		label = _tmp4_;
		_tmp5_ = label;
		gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp5_);
		_tmp6_ = label;
		gtk_widget_show_all ((GtkWidget*) _tmp6_);
		_g_object_unref0 (label);
		return;
	}
	_tmp7_ = self->tray;
	_tmp8_ = self->icon_size;
	na_tray_set_icon_size (_tmp7_, _tmp8_);
	gdk_color_parse ("white", &_tmp9_);
	fg = _tmp9_;
	gdk_color_parse ("red", &_tmp10_);
	_error_ = _tmp10_;
	gdk_color_parse ("orange", &_tmp11_);
	warning = _tmp11_;
	gdk_color_parse ("white", &_tmp12_);
	success = _tmp12_;
	_tmp13_ = self->tray;
	_tmp14_ = fg;
	_tmp15_ = _error_;
	_tmp16_ = warning;
	_tmp17_ = success;
	na_tray_set_colors (_tmp13_, &_tmp14_, &_tmp15_, &_tmp16_, &_tmp17_);
	_tmp18_ = self->priv->box;
	_tmp19_ = self->tray;
	gtk_container_add ((GtkContainer*) _tmp18_, (GtkWidget*) _tmp19_);
	gtk_widget_show_all ((GtkWidget*) self);
	_tmp20_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp21_ = _g_object_ref0 (_tmp20_);
	win = _tmp21_;
	_tmp22_ = win;
	if (_tmp22_ == NULL) {
		_g_object_unref0 (win);
		return;
	}
	_tmp23_ = win;
	gtk_widget_queue_draw (_tmp23_);
	_tmp24_ = self->tray;
	na_tray_force_redraw (_tmp24_);
	gtk_widget_queue_resize ((GtkWidget*) self);
	_g_object_unref0 (win);
}


static void tray_applet_class_init (TrayAppletClass * klass) {
	tray_applet_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TrayAppletPrivate));
	((GtkWidgetClass *) klass)->get_preferred_height = tray_applet_real_get_preferred_height;
	((GtkWidgetClass *) klass)->get_preferred_height_for_width = tray_applet_real_get_preferred_height_for_width;
	G_OBJECT_CLASS (klass)->finalize = tray_applet_finalize;
}


static void tray_applet_instance_init (TrayApplet * self) {
	self->priv = TRAY_APPLET_GET_PRIVATE (self);
	self->tray = NULL;
	self->icon_size = 22;
}


static void tray_applet_finalize (GObject* obj) {
	TrayApplet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TRAY_APPLET, TrayApplet);
	_g_object_unref0 (self->tray);
	_g_object_unref0 (self->priv->box);
	G_OBJECT_CLASS (tray_applet_parent_class)->finalize (obj);
}


GType tray_applet_get_type (void) {
	return tray_applet_type_id;
}


GType tray_applet_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (TrayAppletClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tray_applet_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TrayApplet), 0, (GInstanceInitFunc) tray_applet_instance_init, NULL };
	tray_applet_type_id = g_type_module_register_type (module, budgie_applet_get_type (), "TrayApplet", &g_define_type_info, 0);
	return tray_applet_type_id;
}


void peas_register_types (GTypeModule* module) {
	PeasObjectModule* objmodule = NULL;
	GTypeModule* _tmp0_ = NULL;
	PeasObjectModule* _tmp1_ = NULL;
	g_return_if_fail (module != NULL);
	tray_plugin_register_type (module);
	tray_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_TRAY_PLUGIN);
	_g_object_unref0 (objmodule);
}



