/* main-status-icon.c generated by valac 0.19.0, the Vala compiler
 * generated from main-status-icon.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 <libnotes.h>
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <xfce-autostart.h>
#include <popup.h>
#include <gdk/gdk.h>
#include <unique/unique.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))


extern XnpApplication* application;
XnpApplication* application = NULL;
extern GtkInvisible* invisible;
GtkInvisible* invisible = NULL;
extern GtkStatusIcon* status_icon;
GtkStatusIcon* status_icon = NULL;
extern GtkMenu* context_menu;
GtkMenu* context_menu = NULL;

void build_plugin (void);
static gboolean __lambda2_ (void);
static gboolean ___lambda2__gsource_func (gpointer self);
static void __lambda3_ (void);
static void ___lambda3__gtk_status_icon_activate (GtkStatusIcon* _sender, gpointer self);
GtkMenu* build_context_menu (void);
static void __lambda7_ (void);
static void _gtk_status_icon_position_menu_gtk_menu_position_func (GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer self);
static void ___lambda7__gtk_status_icon_popup_menu (GtkStatusIcon* _sender, guint button, guint activate_time, gpointer self);
gboolean set_x_selection (void);
static void __lambda4_ (void);
static void ___lambda4__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static void __lambda5_ (void);
static void ___lambda5__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static void __lambda6_ (void);
static void ___lambda6__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
static gboolean __lambda8_ (GtkWidget* w, GdkEventClient* event);
static gboolean ___lambda8__gtk_widget_client_event (GtkWidget* _sender, GdkEventClient* event, gpointer self);
gint _vala_main (gchar** args, int args_length1);
static UniqueResponse __lambda9_ (gint command, UniqueMessageData* message_data, guint time_);
static UniqueResponse ___lambda9__unique_app_message_received (UniqueApp* _sender, gint command, UniqueMessageData* message_data, guint time_, gpointer self);


static gboolean __lambda2_ (void) {
	gboolean result = FALSE;
	GtkStatusIcon* _tmp0_;
	gboolean _tmp1_ = FALSE;
	_tmp0_ = status_icon;
	_tmp1_ = gtk_status_icon_is_embedded (_tmp0_);
	if (!_tmp1_) {
		g_warning ("main-status-icon.vala:37: Status Icon is not embedded");
		gtk_main_quit ();
	}
	result = FALSE;
	return result;
}


static gboolean ___lambda2__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda2_ ();
	return result;
}


static void __lambda3_ (void) {
	XnpApplication* _tmp0_;
	_tmp0_ = application;
	xnp_application_show_hide_notes (_tmp0_);
}


static void ___lambda3__gtk_status_icon_activate (GtkStatusIcon* _sender, gpointer self) {
	__lambda3_ ();
}


static void _gtk_status_icon_position_menu_gtk_menu_position_func (GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer self) {
	gtk_status_icon_position_menu (menu, x, y, push_in, self);
}


static void __lambda7_ (void) {
	GtkMenu* _tmp0_;
	GtkStatusIcon* _tmp1_;
	guint32 _tmp2_ = 0U;
	_tmp0_ = context_menu;
	_tmp1_ = status_icon;
	_tmp2_ = gtk_get_current_event_time ();
	gtk_menu_popup (_tmp0_, NULL, NULL, _gtk_status_icon_position_menu_gtk_menu_position_func, _tmp1_, (guint) 0, _tmp2_);
}


static void ___lambda7__gtk_status_icon_popup_menu (GtkStatusIcon* _sender, guint button, guint activate_time, gpointer self) {
	__lambda7_ ();
}


void build_plugin (void) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	gchar* save_location;
	XnpApplication* _tmp2_;
	GtkStatusIcon* _tmp3_;
	GtkStatusIcon* _tmp4_;
	const gchar* _tmp5_ = NULL;
	GtkStatusIcon* _tmp6_;
	GtkMenu* _tmp7_ = NULL;
	GtkStatusIcon* _tmp8_;
	xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, NULL);
	_tmp0_ = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "xfce4/xfce4-notes.rc", TRUE);
	_tmp1_ = g_strdup (_tmp0_);
	save_location = _tmp1_;
	_tmp2_ = xnp_application_new (save_location);
	_g_object_unref0 (application);
	application = _tmp2_;
	_tmp3_ = gtk_status_icon_new_from_icon_name ("xfce4-notes-plugin");
	_g_object_unref0 (status_icon);
	status_icon = _tmp3_;
	_tmp4_ = status_icon;
	_tmp5_ = _ ("Notes");
	gtk_status_icon_set_tooltip_text (_tmp4_, _tmp5_);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 60, ___lambda2__gsource_func, NULL, NULL);
	_tmp6_ = status_icon;
	g_signal_connect (_tmp6_, "activate", (GCallback) ___lambda3__gtk_status_icon_activate, NULL);
	_tmp7_ = build_context_menu ();
	_g_object_unref0 (context_menu);
	context_menu = _tmp7_;
	_tmp8_ = status_icon;
	g_signal_connect (_tmp8_, "popup-menu", (GCallback) ___lambda7__gtk_status_icon_popup_menu, NULL);
	set_x_selection ();
	_g_free0 (save_location);
}


static void __lambda4_ (void) {
	XnpApplication* _tmp0_;
	_tmp0_ = application;
	xnp_application_open_settings_dialog (_tmp0_);
}


static void ___lambda4__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	__lambda4_ ();
}


static void __lambda5_ (void) {
	XnpApplication* _tmp0_;
	_tmp0_ = application;
	xnp_application_open_about_dialog (_tmp0_);
}


static void ___lambda5__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	__lambda5_ ();
}


static void __lambda6_ (void) {
	XnpApplication* _tmp0_;
	_tmp0_ = application;
	xnp_application_save_notes (_tmp0_);
	xfce_autostart_set ("xfce4-notes-autostart", "xfce4-notes", TRUE);
	gtk_main_quit ();
}


static void ___lambda6__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
	__lambda6_ ();
}


GtkMenu* build_context_menu (void) {
	GtkMenu* result = NULL;
	GtkMenu* _tmp0_;
	GtkMenu* menu;
	const gchar* _tmp1_ = NULL;
	GtkMenuItem* _tmp2_;
	GtkMenuItem* mi;
	XnpApplication* _tmp3_;
	GtkMenu* _tmp4_ = NULL;
	GtkMenu* menu_go;
	GtkMenuItem* _tmp5_;
	GtkMenuItem* _tmp6_;
	GtkSeparatorMenuItem* _tmp7_;
	GtkMenuItem* _tmp8_;
	GtkImageMenuItem* _tmp9_;
	GtkMenuItem* _tmp10_;
	GtkMenuItem* _tmp11_;
	GtkImageMenuItem* _tmp12_;
	GtkMenuItem* _tmp13_;
	GtkMenuItem* _tmp14_;
	GtkSeparatorMenuItem* _tmp15_;
	GtkMenuItem* _tmp16_;
	GtkImageMenuItem* _tmp17_;
	GtkMenuItem* _tmp18_;
	GtkMenuItem* _tmp19_;
	_tmp0_ = (GtkMenu*) gtk_menu_new ();
	g_object_ref_sink (_tmp0_);
	menu = _tmp0_;
	_tmp1_ = _ ("_Groups");
	_tmp2_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic (_tmp1_);
	g_object_ref_sink (_tmp2_);
	mi = _tmp2_;
	_tmp3_ = application;
	_tmp4_ = xnp_application_context_menu (_tmp3_);
	menu_go = _tmp4_;
	_tmp5_ = mi;
	gtk_menu_item_set_submenu (_tmp5_, (GtkWidget*) menu_go);
	_tmp6_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp6_);
	_tmp7_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new ();
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (mi);
	mi = (GtkMenuItem*) _tmp7_;
	_tmp8_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp8_);
	_tmp9_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (mi);
	mi = (GtkMenuItem*) _tmp9_;
	_tmp10_ = mi;
	g_signal_connect (_tmp10_, "activate", (GCallback) ___lambda4__gtk_menu_item_activate, NULL);
	_tmp11_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp11_);
	_tmp12_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
	g_object_ref_sink (_tmp12_);
	_g_object_unref0 (mi);
	mi = (GtkMenuItem*) _tmp12_;
	_tmp13_ = mi;
	g_signal_connect (_tmp13_, "activate", (GCallback) ___lambda5__gtk_menu_item_activate, NULL);
	_tmp14_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp14_);
	_tmp15_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new ();
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (mi);
	mi = (GtkMenuItem*) _tmp15_;
	_tmp16_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp16_);
	_tmp17_ = (GtkImageMenuItem*) gtk_image_menu_item_new_from_stock (GTK_STOCK_REMOVE, NULL);
	g_object_ref_sink (_tmp17_);
	_g_object_unref0 (mi);
	mi = (GtkMenuItem*) _tmp17_;
	_tmp18_ = mi;
	g_signal_connect (_tmp18_, "activate", (GCallback) ___lambda6__gtk_menu_item_activate, NULL);
	_tmp19_ = mi;
	gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) _tmp19_);
	gtk_widget_show_all ((GtkWidget*) menu);
	result = menu;
	_g_object_unref0 (menu_go);
	_g_object_unref0 (mi);
	return result;
}


static gboolean __lambda8_ (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_ = application;
		xnp_application_show_hide_notes (_tmp2_);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}


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


gboolean set_x_selection (void) {
	gboolean result = FALSE;
	GtkInvisible* _tmp0_;
	GtkInvisible* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GtkInvisible* _tmp3_;
	_tmp0_ = (GtkInvisible*) gtk_invisible_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (invisible);
	invisible = _tmp0_;
	_tmp1_ = invisible;
	_tmp2_ = popup_set_x_selection ((GtkWidget*) _tmp1_);
	if (!_tmp2_) {
		result = FALSE;
		return result;
	}
	_tmp3_ = invisible;
	g_signal_connect ((GtkWidget*) _tmp3_, "client-event", (GCallback) ___lambda8__gtk_widget_client_event, NULL);
	result = TRUE;
	return result;
}


static UniqueResponse __lambda9_ (gint command, UniqueMessageData* message_data, guint time_) {
	UniqueResponse result = 0;
	gint _tmp0_;
	g_return_val_if_fail (message_data != NULL, 0);
	_tmp0_ = command;
	if (_tmp0_ != ((gint) UNIQUE_ACTIVATE)) {
		result = UNIQUE_RESPONSE_PASSTHROUGH;
		return result;
	}
	result = UNIQUE_RESPONSE_OK;
	return result;
}


static UniqueResponse ___lambda9__unique_app_message_received (UniqueApp* _sender, gint command, UniqueMessageData* message_data, guint time_, gpointer self) {
	UniqueResponse result;
	result = __lambda9_ (command, message_data, time_);
	return result;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	UniqueApp* _tmp0_;
	UniqueApp* app;
	UniqueApp* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_;
	UniqueApp* _tmp6_;
	const gchar* _tmp7_ = NULL;
	gtk_init (&args_length1, &args);
	_tmp0_ = unique_app_new ("org.xfce.Notes", NULL);
	app = _tmp0_;
	_tmp1_ = app;
	g_object_get (_tmp1_, "is-running", &_tmp2_, NULL);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		UniqueApp* _tmp4_;
		UniqueResponse _tmp5_ = 0;
		_tmp4_ = app;
		_tmp5_ = unique_app_send_message (_tmp4_, (gint) UNIQUE_ACTIVATE, NULL);
		if (_tmp5_ == UNIQUE_RESPONSE_OK) {
			_g_object_unref0 (app);
			app = NULL;
			result = 0;
			_g_object_unref0 (app);
			return result;
		}
	}
	_tmp6_ = app;
	g_signal_connect (_tmp6_, "message-received", (GCallback) ___lambda9__unique_app_message_received, NULL);
	_tmp7_ = _ ("Notes");
	g_set_application_name (_tmp7_);
	build_plugin ();
	xfce_autostart_set ("xfce4-notes-autostart", "xfce4-notes", FALSE);
	gtk_main ();
	_g_object_unref0 (application);
	application = NULL;
	_g_object_unref0 (invisible);
	invisible = NULL;
	_g_object_unref0 (status_icon);
	status_icon = NULL;
	_g_object_unref0 (context_menu);
	context_menu = NULL;
	result = 0;
	_g_object_unref0 (app);
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



