/* ShowDesktopApplet.c generated by valac 0.32.1, the Vala compiler
 * generated from ShowDesktopApplet.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 <libwnck/libwnck.h>
#include <glib/gi18n-lib.h>


#define TYPE_SHOW_DESKTOP_PLUGIN (show_desktop_plugin_get_type ())
#define SHOW_DESKTOP_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SHOW_DESKTOP_PLUGIN, ShowDesktopPlugin))
#define SHOW_DESKTOP_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SHOW_DESKTOP_PLUGIN, ShowDesktopPluginClass))
#define IS_SHOW_DESKTOP_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SHOW_DESKTOP_PLUGIN))
#define IS_SHOW_DESKTOP_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SHOW_DESKTOP_PLUGIN))
#define SHOW_DESKTOP_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SHOW_DESKTOP_PLUGIN, ShowDesktopPluginClass))

typedef struct _ShowDesktopPlugin ShowDesktopPlugin;
typedef struct _ShowDesktopPluginClass ShowDesktopPluginClass;
typedef struct _ShowDesktopPluginPrivate ShowDesktopPluginPrivate;

#define TYPE_SHOW_DESKTOP_APPLET (show_desktop_applet_get_type ())
#define SHOW_DESKTOP_APPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SHOW_DESKTOP_APPLET, ShowDesktopApplet))
#define SHOW_DESKTOP_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SHOW_DESKTOP_APPLET, ShowDesktopAppletClass))
#define IS_SHOW_DESKTOP_APPLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SHOW_DESKTOP_APPLET))
#define IS_SHOW_DESKTOP_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SHOW_DESKTOP_APPLET))
#define SHOW_DESKTOP_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SHOW_DESKTOP_APPLET, ShowDesktopAppletClass))

typedef struct _ShowDesktopApplet ShowDesktopApplet;
typedef struct _ShowDesktopAppletClass ShowDesktopAppletClass;
typedef struct _ShowDesktopAppletPrivate ShowDesktopAppletPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ShowDesktopPlugin {
	PeasExtensionBase parent_instance;
	ShowDesktopPluginPrivate * priv;
};

struct _ShowDesktopPluginClass {
	PeasExtensionBaseClass parent_class;
};

struct _ShowDesktopApplet {
	BudgieApplet parent_instance;
	ShowDesktopAppletPrivate * priv;
	GtkToggleButton* widget;
	GtkImage* img;
};

struct _ShowDesktopAppletClass {
	BudgieAppletClass parent_class;
};

struct _ShowDesktopAppletPrivate {
	WnckScreen* wscreen;
};


static gpointer show_desktop_plugin_parent_class = NULL;
static BudgiePluginIface* show_desktop_plugin_budgie_plugin_parent_iface = NULL;
static GType show_desktop_plugin_type_id = 0;
static gpointer show_desktop_applet_parent_class = NULL;
static GType show_desktop_applet_type_id = 0;

GType show_desktop_plugin_get_type (void) G_GNUC_CONST;
GType show_desktop_plugin_register_type (GTypeModule * module);
enum  {
	SHOW_DESKTOP_PLUGIN_DUMMY_PROPERTY
};
static BudgieApplet* show_desktop_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid);
ShowDesktopApplet* show_desktop_applet_new (void);
ShowDesktopApplet* show_desktop_applet_construct (GType object_type);
GType show_desktop_applet_get_type (void) G_GNUC_CONST;
GType show_desktop_applet_register_type (GTypeModule * module);
ShowDesktopPlugin* show_desktop_plugin_new (void);
ShowDesktopPlugin* show_desktop_plugin_construct (GType object_type);
#define SHOW_DESKTOP_APPLET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_SHOW_DESKTOP_APPLET, ShowDesktopAppletPrivate))
enum  {
	SHOW_DESKTOP_APPLET_DUMMY_PROPERTY
};
static void __lambda4_ (ShowDesktopApplet* self);
static void ___lambda4__wnck_screen_showing_desktop_changed (WnckScreen* _sender, gpointer self);
static void __lambda5_ (ShowDesktopApplet* self);
static void ___lambda5__gtk_button_clicked (GtkButton* _sender, gpointer self);
static void show_desktop_applet_finalize (GObject* obj);
void peas_register_types (GTypeModule* module);


static BudgieApplet* show_desktop_plugin_real_get_panel_widget (BudgiePlugin* base, const gchar* uuid) {
	ShowDesktopPlugin * self;
	BudgieApplet* result = NULL;
	ShowDesktopApplet* _tmp0_ = NULL;
	self = (ShowDesktopPlugin*) base;
	g_return_val_if_fail (uuid != NULL, NULL);
	_tmp0_ = show_desktop_applet_new ();
	g_object_ref_sink (_tmp0_);
	result = (BudgieApplet*) _tmp0_;
	return result;
}


ShowDesktopPlugin* show_desktop_plugin_construct (GType object_type) {
	ShowDesktopPlugin * self = NULL;
	self = (ShowDesktopPlugin*) g_object_new (object_type, NULL);
	return self;
}


ShowDesktopPlugin* show_desktop_plugin_new (void) {
	return show_desktop_plugin_construct (TYPE_SHOW_DESKTOP_PLUGIN);
}


static void show_desktop_plugin_class_init (ShowDesktopPluginClass * klass) {
	show_desktop_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void show_desktop_plugin_budgie_plugin_interface_init (BudgiePluginIface * iface) {
	show_desktop_plugin_budgie_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_panel_widget = (BudgieApplet* (*)(BudgiePlugin*, const gchar*)) show_desktop_plugin_real_get_panel_widget;
}


static void show_desktop_plugin_instance_init (ShowDesktopPlugin * self) {
}


GType show_desktop_plugin_get_type (void) {
	return show_desktop_plugin_type_id;
}


GType show_desktop_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (ShowDesktopPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) show_desktop_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ShowDesktopPlugin), 0, (GInstanceInitFunc) show_desktop_plugin_instance_init, NULL };
	static const GInterfaceInfo budgie_plugin_info = { (GInterfaceInitFunc) show_desktop_plugin_budgie_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	show_desktop_plugin_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "ShowDesktopPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, show_desktop_plugin_type_id, budgie_plugin_get_type (), &budgie_plugin_info);
	return show_desktop_plugin_type_id;
}


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


static void __lambda4_ (ShowDesktopApplet* self) {
	gboolean showing = FALSE;
	WnckScreen* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GtkToggleButton* _tmp2_ = NULL;
	_tmp0_ = self->priv->wscreen;
	_tmp1_ = wnck_screen_get_showing_desktop (_tmp0_);
	showing = _tmp1_;
	_tmp2_ = self->widget;
	gtk_toggle_button_set_active (_tmp2_, showing);
}


static void ___lambda4__wnck_screen_showing_desktop_changed (WnckScreen* _sender, gpointer self) {
	__lambda4_ ((ShowDesktopApplet*) self);
}


static void __lambda5_ (ShowDesktopApplet* self) {
	WnckScreen* _tmp0_ = NULL;
	GtkToggleButton* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	_tmp0_ = self->priv->wscreen;
	_tmp1_ = self->widget;
	_tmp2_ = gtk_toggle_button_get_active (_tmp1_);
	wnck_screen_toggle_showing_desktop (_tmp0_, _tmp2_);
}


static void ___lambda5__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda5_ ((ShowDesktopApplet*) self);
}


ShowDesktopApplet* show_desktop_applet_construct (GType object_type) {
	ShowDesktopApplet * self = NULL;
	GtkToggleButton* _tmp0_ = NULL;
	GtkToggleButton* _tmp1_ = NULL;
	GtkToggleButton* _tmp2_ = NULL;
	GtkImage* _tmp3_ = NULL;
	GtkToggleButton* _tmp4_ = NULL;
	GtkImage* _tmp5_ = NULL;
	GtkToggleButton* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	WnckScreen* _tmp8_ = NULL;
	WnckScreen* _tmp9_ = NULL;
	WnckScreen* _tmp10_ = NULL;
	GtkToggleButton* _tmp11_ = NULL;
	GtkToggleButton* _tmp12_ = NULL;
	self = (ShowDesktopApplet*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkToggleButton*) gtk_toggle_button_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->widget);
	self->widget = _tmp0_;
	_tmp1_ = self->widget;
	gtk_button_set_relief ((GtkButton*) _tmp1_, GTK_RELIEF_NONE);
	_tmp2_ = self->widget;
	gtk_toggle_button_set_active (_tmp2_, FALSE);
	_tmp3_ = (GtkImage*) gtk_image_new_from_icon_name ("user-desktop-symbolic", GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->img);
	self->img = _tmp3_;
	_tmp4_ = self->widget;
	_tmp5_ = self->img;
	gtk_container_add ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->widget;
	_tmp7_ = _ ("Toggle the desktop");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp6_, _tmp7_);
	_tmp8_ = wnck_screen_get_default ();
	_tmp9_ = _g_object_ref0 (_tmp8_);
	_g_object_unref0 (self->priv->wscreen);
	self->priv->wscreen = _tmp9_;
	_tmp10_ = self->priv->wscreen;
	g_signal_connect_object (_tmp10_, "showing-desktop-changed", (GCallback) ___lambda4__wnck_screen_showing_desktop_changed, self, 0);
	_tmp11_ = self->widget;
	g_signal_connect_object ((GtkButton*) _tmp11_, "clicked", (GCallback) ___lambda5__gtk_button_clicked, self, 0);
	_tmp12_ = self->widget;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp12_);
	gtk_widget_show_all ((GtkWidget*) self);
	return self;
}


ShowDesktopApplet* show_desktop_applet_new (void) {
	return show_desktop_applet_construct (TYPE_SHOW_DESKTOP_APPLET);
}


static void show_desktop_applet_class_init (ShowDesktopAppletClass * klass) {
	show_desktop_applet_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ShowDesktopAppletPrivate));
	G_OBJECT_CLASS (klass)->finalize = show_desktop_applet_finalize;
}


static void show_desktop_applet_instance_init (ShowDesktopApplet * self) {
	self->priv = SHOW_DESKTOP_APPLET_GET_PRIVATE (self);
}


static void show_desktop_applet_finalize (GObject* obj) {
	ShowDesktopApplet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SHOW_DESKTOP_APPLET, ShowDesktopApplet);
	_g_object_unref0 (self->widget);
	_g_object_unref0 (self->img);
	_g_object_unref0 (self->priv->wscreen);
	G_OBJECT_CLASS (show_desktop_applet_parent_class)->finalize (obj);
}


GType show_desktop_applet_get_type (void) {
	return show_desktop_applet_type_id;
}


GType show_desktop_applet_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (ShowDesktopAppletClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) show_desktop_applet_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ShowDesktopApplet), 0, (GInstanceInitFunc) show_desktop_applet_instance_init, NULL };
	show_desktop_applet_type_id = g_type_module_register_type (module, budgie_applet_get_type (), "ShowDesktopApplet", &g_define_type_info, 0);
	return show_desktop_applet_type_id;
}


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



