/* main-panel-plugin.c generated by valac 0.19.0, the Vala compiler
 * generated from main-panel-plugin.vala, do not modify */

/*
 *  Notes - panel plugin for Xfce Desktop Environment
 *  Copyright (C) 2009-2010  Mike Massonnet <mmassonnet@xfce.org>
 *
 *  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 St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <glib.h>
#include <glib-object.h>
#include <libxfce4panel/libxfce4panel.h>
#include <gtk/gtk.h>
#include <libnotes.h>
#include <libxfce4util/libxfce4util.h>
#include <config.h>
#include <glib/gi18n-lib.h>
#include <popup.h>
#include <gdk/gdk.h>


#define TYPE_NOTES_PLUGIN (notes_plugin_get_type ())
#define NOTES_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NOTES_PLUGIN, NotesPlugin))
#define NOTES_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NOTES_PLUGIN, NotesPluginClass))
#define IS_NOTES_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NOTES_PLUGIN))
#define IS_NOTES_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NOTES_PLUGIN))
#define NOTES_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NOTES_PLUGIN, NotesPluginClass))

typedef struct _NotesPlugin NotesPlugin;
typedef struct _NotesPluginClass NotesPluginClass;
typedef struct _NotesPluginPrivate NotesPluginPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _NotesPlugin {
	XfcePanelPlugin parent_instance;
	NotesPluginPrivate * priv;
};

struct _NotesPluginClass {
	XfcePanelPluginClass parent_class;
};

struct _NotesPluginPrivate {
	GtkInvisible* invisible;
	GtkButton* button;
	XfcePanelImage* image;
	XnpApplication* application;
};


static gpointer notes_plugin_parent_class = NULL;
static GType notes_plugin_type_id = 0;

GType notes_plugin_get_type (void) G_GNUC_CONST;
GType notes_plugin_register_type (GTypeModule * module);
#define NOTES_PLUGIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_NOTES_PLUGIN, NotesPluginPrivate))
enum  {
	NOTES_PLUGIN_DUMMY_PROPERTY
};
NotesPlugin* notes_plugin_new (void);
NotesPlugin* notes_plugin_construct (GType object_type);
static void notes_plugin_real_construct (XfcePanelPlugin* base);
static void __lambda2_ (NotesPlugin* self);
static void ___lambda2__gtk_button_clicked (GtkButton* _sender, gpointer self);
static gboolean notes_plugin_set_x_selection (NotesPlugin* self);
static gboolean __lambda4_ (NotesPlugin* self, XfcePanelPlugin* p, gint size);
static gboolean ___lambda4__xfce_panel_plugin_size_changed (XfcePanelPlugin* _sender, gint size, gpointer self);
static void __lambda5_ (NotesPlugin* self);
static void ___lambda5__xfce_panel_plugin_save (XfcePanelPlugin* _sender, gpointer self);
static void __lambda6_ (NotesPlugin* self);
static void ___lambda6__xfce_panel_plugin_free_data (XfcePanelPlugin* _sender, gpointer self);
static void __lambda7_ (NotesPlugin* self);
static void ___lambda7__xfce_panel_plugin_configure_plugin (XfcePanelPlugin* _sender, gpointer self);
static void __lambda8_ (NotesPlugin* self);
static void ___lambda8__xfce_panel_plugin_about (XfcePanelPlugin* _sender, gpointer self);
static void __lambda9_ (NotesPlugin* self);
static void ___lambda9__gtk_object_destroy (GtkObject* _sender, gpointer self);
static gboolean __lambda3_ (NotesPlugin* self, GtkWidget* w, GdkEventClient* event);
static gboolean ___lambda3__gtk_widget_client_event (GtkWidget* _sender, GdkEventClient* event, gpointer self);
static void notes_plugin_finalize (GObject* obj);
GType xfce_panel_module_init (GTypeModule* module);


NotesPlugin* notes_plugin_construct (GType object_type) {
	NotesPlugin * self = NULL;
	self = (NotesPlugin*) g_object_new (object_type, NULL);
	return self;
}


NotesPlugin* notes_plugin_new (void) {
	return notes_plugin_construct (TYPE_NOTES_PLUGIN);
}


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


static void __lambda2_ (NotesPlugin* self) {
	XnpApplication* _tmp0_;
	_tmp0_ = self->priv->application;
	xnp_application_show_hide_notes (_tmp0_);
}


static void ___lambda2__gtk_button_clicked (GtkButton* _sender, gpointer self) {
	__lambda2_ (self);
}


static gboolean __lambda4_ (NotesPlugin* self, XfcePanelPlugin* p, gint size) {
	gboolean result = FALSE;
	gint _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	GtkButton* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	g_return_val_if_fail (p != NULL, FALSE);
	_tmp0_ = size;
	_tmp1_ = xfce_panel_plugin_get_nrows ((XfcePanelPlugin*) self);
	_tmp2_ = _tmp1_;
	size = _tmp0_ / ((gint) _tmp2_);
	_tmp3_ = self->priv->button;
	_tmp4_ = size;
	_tmp5_ = size;
	gtk_widget_set_size_request ((GtkWidget*) _tmp3_, _tmp4_, _tmp5_);
	result = TRUE;
	return result;
}


static gboolean ___lambda4__xfce_panel_plugin_size_changed (XfcePanelPlugin* _sender, gint size, gpointer self) {
	gboolean result;
	result = __lambda4_ (self, _sender, size);
	return result;
}


static void __lambda5_ (NotesPlugin* self) {
	XnpApplication* _tmp0_;
	_tmp0_ = self->priv->application;
	xnp_application_save_windows_configuration (_tmp0_);
}


static void ___lambda5__xfce_panel_plugin_save (XfcePanelPlugin* _sender, gpointer self) {
	__lambda5_ (self);
}


static void __lambda6_ (NotesPlugin* self) {
	XnpApplication* _tmp0_;
	XnpApplication* _tmp1_;
	_tmp0_ = self->priv->application;
	xnp_application_save_windows_configuration (_tmp0_);
	_tmp1_ = self->priv->application;
	xnp_application_save_notes (_tmp1_);
}


static void ___lambda6__xfce_panel_plugin_free_data (XfcePanelPlugin* _sender, gpointer self) {
	__lambda6_ (self);
}


static void __lambda7_ (NotesPlugin* self) {
	XnpApplication* _tmp0_;
	_tmp0_ = self->priv->application;
	xnp_application_open_settings_dialog (_tmp0_);
}


static void ___lambda7__xfce_panel_plugin_configure_plugin (XfcePanelPlugin* _sender, gpointer self) {
	__lambda7_ (self);
}


static void __lambda8_ (NotesPlugin* self) {
	XnpApplication* _tmp0_;
	_tmp0_ = self->priv->application;
	xnp_application_open_about_dialog (_tmp0_);
}


static void ___lambda8__xfce_panel_plugin_about (XfcePanelPlugin* _sender, gpointer self) {
	__lambda8_ (self);
}


static void __lambda9_ (NotesPlugin* self) {
	gtk_main_quit ();
}


static void ___lambda9__gtk_object_destroy (GtkObject* _sender, gpointer self) {
	__lambda9_ (self);
}


static void notes_plugin_real_construct (XfcePanelPlugin* base) {
	NotesPlugin * self;
	const gchar* _tmp0_ = NULL;
	XnpApplication* _tmp1_;
	GtkWidget* _tmp2_ = NULL;
	GtkButton* _tmp3_;
	XfcePanelImage* _tmp4_;
	GtkButton* _tmp5_;
	XfcePanelImage* _tmp6_;
	GtkButton* _tmp7_;
	GtkButton* _tmp8_;
	GtkButton* _tmp9_;
	GtkButton* _tmp10_;
	const gchar* _tmp11_ = NULL;
	const gchar* _tmp12_ = NULL;
	GtkMenuItem* _tmp13_;
	GtkMenuItem* mi;
	XnpApplication* _tmp14_;
	GtkMenu* _tmp15_ = NULL;
	GtkMenu* menu;
	self = (NotesPlugin*) base;
	xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, NULL);
	_tmp0_ = xfce_panel_plugin_save_location ((XfcePanelPlugin*) self, TRUE);
	_tmp1_ = xnp_application_new (_tmp0_);
	_g_object_unref0 (self->priv->application);
	self->priv->application = _tmp1_;
	_tmp2_ = xfce_panel_create_button ();
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GTK_TYPE_BUTTON, GtkButton));
	_g_object_unref0 (self->priv->button);
	self->priv->button = _tmp3_;
	_tmp4_ = (XfcePanelImage*) xfce_panel_image_new_from_source ("xfce4-notes-plugin");
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->image);
	self->priv->image = _tmp4_;
	_tmp5_ = self->priv->button;
	_tmp6_ = self->priv->image;
	gtk_container_add ((GtkContainer*) _tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = self->priv->button;
	g_signal_connect_object (_tmp7_, "clicked", (GCallback) ___lambda2__gtk_button_clicked, self, 0);
	_tmp8_ = self->priv->button;
	gtk_widget_show_all ((GtkWidget*) _tmp8_);
	xfce_panel_plugin_set_small ((XfcePanelPlugin*) self, TRUE);
	_tmp9_ = self->priv->button;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp9_);
	_tmp10_ = self->priv->button;
	xfce_panel_plugin_add_action_widget ((XfcePanelPlugin*) self, (GtkWidget*) _tmp10_);
	_tmp11_ = _ ("Notes");
	gtk_widget_set_tooltip_text ((GtkWidget*) self, _tmp11_);
	xfce_panel_plugin_menu_show_configure ((XfcePanelPlugin*) self);
	xfce_panel_plugin_menu_show_about ((XfcePanelPlugin*) self);
	_tmp12_ = _ ("_Groups");
	_tmp13_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic (_tmp12_);
	g_object_ref_sink (_tmp13_);
	mi = _tmp13_;
	_tmp14_ = self->priv->application;
	_tmp15_ = xnp_application_context_menu (_tmp14_);
	menu = _tmp15_;
	gtk_menu_item_set_submenu (mi, (GtkWidget*) menu);
	gtk_widget_show_all ((GtkWidget*) mi);
	xfce_panel_plugin_menu_insert_item ((XfcePanelPlugin*) self, mi);
	notes_plugin_set_x_selection (self);
	g_signal_connect_object ((XfcePanelPlugin*) self, "size-changed", (GCallback) ___lambda4__xfce_panel_plugin_size_changed, self, 0);
	g_signal_connect_object ((XfcePanelPlugin*) self, "save", (GCallback) ___lambda5__xfce_panel_plugin_save, self, 0);
	g_signal_connect_object ((XfcePanelPlugin*) self, "free-data", (GCallback) ___lambda6__xfce_panel_plugin_free_data, self, 0);
	g_signal_connect_object ((XfcePanelPlugin*) self, "configure-plugin", (GCallback) ___lambda7__xfce_panel_plugin_configure_plugin, self, 0);
	g_signal_connect_object ((XfcePanelPlugin*) self, "about", (GCallback) ___lambda8__xfce_panel_plugin_about, self, 0);
	g_signal_connect_object ((GtkObject*) self, "destroy", (GCallback) ___lambda9__gtk_object_destroy, self, 0);
	_g_object_unref0 (menu);
	_g_object_unref0 (mi);
}


/**
 * set_x_selection:
 *
 * Set an X selection to listen to for the popup command.
 */
static gboolean __lambda3_ (NotesPlugin* self, GtkWidget* w, GdkEventClient* event) {
	gboolean result = FALSE;
	GdkEventClient _tmp0_;
	const gchar* _tmp1_ = NULL;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = *event;
	_tmp1_ = popup_get_message_from_event (&_tmp0_);
	if (g_strcmp0 (_tmp1_, "SHOW_HIDE") == 0) {
		XnpApplication* _tmp2_;
		_tmp2_ = self->priv->application;
		xnp_application_show_hide_notes (_tmp2_);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}


static gboolean ___lambda3__gtk_widget_client_event (GtkWidget* _sender, GdkEventClient* event, gpointer self) {
	gboolean result;
	result = __lambda3_ (self, _sender, event);
	return result;
}


static gboolean notes_plugin_set_x_selection (NotesPlugin* self) {
	gboolean result = FALSE;
	GtkInvisible* _tmp0_;
	GtkInvisible* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkInvisible* _tmp3_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = (GtkInvisible*) gtk_invisible_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->invisible);
	self->priv->invisible = _tmp0_;
	_tmp1_ = self->priv->invisible;
	_tmp2_ = popup_set_x_selection ((GtkWidget*) _tmp1_);
	if (!_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp3_ = self->priv->invisible;
	g_signal_connect_object ((GtkWidget*) _tmp3_, "client-event", (GCallback) ___lambda3__gtk_widget_client_event, self, 0);
	result = TRUE;
	return result;
}


static void notes_plugin_class_init (NotesPluginClass * klass) {
	notes_plugin_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (NotesPluginPrivate));
	XFCE_PANEL_PLUGIN_CLASS (klass)->construct = notes_plugin_real_construct;
	G_OBJECT_CLASS (klass)->finalize = notes_plugin_finalize;
}


static void notes_plugin_instance_init (NotesPlugin * self) {
	self->priv = NOTES_PLUGIN_GET_PRIVATE (self);
}


static void notes_plugin_finalize (GObject* obj) {
	NotesPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_NOTES_PLUGIN, NotesPlugin);
	_g_object_unref0 (self->priv->invisible);
	_g_object_unref0 (self->priv->button);
	_g_object_unref0 (self->priv->image);
	_g_object_unref0 (self->priv->application);
	G_OBJECT_CLASS (notes_plugin_parent_class)->finalize (obj);
}


GType notes_plugin_get_type (void) {
	return notes_plugin_type_id;
}


GType notes_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (NotesPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) notes_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NotesPlugin), 0, (GInstanceInitFunc) notes_plugin_instance_init, NULL };
	notes_plugin_type_id = g_type_module_register_type (module, XFCE_TYPE_PANEL_PLUGIN, "NotesPlugin", &g_define_type_info, 0);
	return notes_plugin_type_id;
}


GType xfce_panel_module_init (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	notes_plugin_register_type (module);
	result = TYPE_NOTES_PLUGIN;
	return result;
}



