/* main-status-icon.c generated by valac 0.56.18, 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 "libnotes.h"
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
#include <xfce-revision.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <libc/xfce-autostart.h>
#include <gio/gio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef void (*Callback) (gpointer user_data);
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _Block1Data {
	int _ref_count_;
	Callback callback;
	gpointer callback_target;
};

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

VALA_EXTERN void build_plugin (void);
static gboolean __lambda4_ (void);
static gboolean ___lambda4__gsource_func (gpointer self);
static void __lambda5_ (void);
static void ___lambda5__gtk_status_icon_activate (GtkStatusIcon* _sender,
                                           gpointer self);
VALA_EXTERN GtkMenu* build_context_menu (void);
static void __lambda10_ (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 ___lambda10__gtk_status_icon_popup_menu (GtkStatusIcon* _sender,
                                              guint button,
                                              guint activate_time,
                                              gpointer self);
VALA_EXTERN void menu_add_icon_item (GtkMenu* menu,
                         const gchar* text,
                         const gchar* icon,
                         Callback callback,
                         gpointer callback_target);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda6_ (Block1Data* _data1_);
static void ___lambda6__gtk_menu_item_activate (GtkMenuItem* _sender,
                                         gpointer self);
VALA_EXTERN void menu_add_separator (GtkMenu* menu);
static void __lambda7_ (void);
static void ___lambda7__callback (gpointer self);
static void __lambda8_ (void);
static void ___lambda8__callback (gpointer self);
static void __lambda9_ (void);
static void ___lambda9__callback (gpointer self);
static gint _vala_main (gchar** args,
                 gint args_length1);
static void __lambda11_ (void);
static void ___lambda11__g_application_activate (GApplication* _sender,
                                          gpointer self);

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

static gboolean
___lambda4__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda4_ ();
	return result;
}

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

static void
___lambda5__gtk_status_icon_activate (GtkStatusIcon* _sender,
                                      gpointer self)
{
	__lambda5_ ();
}

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, (GtkStatusIcon*) self);
}

static void
__lambda10_ (void)
{
	GtkMenu* _tmp0_;
	GtkStatusIcon* _tmp1_;
	_tmp0_ = context_menu;
	_tmp1_ = status_icon;
	gtk_menu_popup (_tmp0_, NULL, NULL, _gtk_status_icon_position_menu_gtk_menu_position_func, g_object_ref (_tmp1_), (guint) 0, gtk_get_current_event_time ());
}

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

void
build_plugin (void)
{
	gchar* save_location = NULL;
	gchar* _tmp0_;
	XnpApplication* _tmp1_;
	GtkStatusIcon* _tmp2_;
	GtkStatusIcon* _tmp3_;
	GtkStatusIcon* _tmp4_;
	GtkMenu* _tmp5_;
	GtkStatusIcon* _tmp6_;
	XnpApplication* _tmp7_;
	xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
	_tmp0_ = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "xfce4/notes/xfce4-notes.rc", TRUE);
	save_location = _tmp0_;
	_tmp1_ = xnp_application_new (save_location);
	_g_object_unref0 (application);
	application = _tmp1_;
	_tmp2_ = gtk_status_icon_new_from_icon_name ("org.xfce.notes.tray");
	_g_object_unref0 (status_icon);
	status_icon = _tmp2_;
	_tmp3_ = status_icon;
	gtk_status_icon_set_tooltip_text (_tmp3_, _ ("Notes"));
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 60, ___lambda4__gsource_func, NULL, NULL);
	_tmp4_ = status_icon;
	g_signal_connect (_tmp4_, "activate", (GCallback) ___lambda5__gtk_status_icon_activate, NULL);
	_tmp5_ = build_context_menu ();
	_g_object_unref0 (context_menu);
	context_menu = _tmp5_;
	_tmp6_ = status_icon;
	g_signal_connect (_tmp6_, "popup-menu", (GCallback) ___lambda10__gtk_status_icon_popup_menu, NULL);
	_tmp7_ = application;
	_tmp7_->system_tray_mode = TRUE;
	_g_free0 (save_location);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		g_slice_free (Block1Data, _data1_);
	}
}

static void
__lambda6_ (Block1Data* _data1_)
{
	_data1_->callback (_data1_->callback_target);
}

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

void
menu_add_icon_item (GtkMenu* menu,
                    const gchar* text,
                    const gchar* icon,
                    Callback callback,
                    gpointer callback_target)
{
	Block1Data* _data1_;
	GtkImageMenuItem* mi = NULL;
	GtkImageMenuItem* _tmp0_;
	GtkImage* image = NULL;
	GtkImage* _tmp1_;
	g_return_if_fail (menu != NULL);
	g_return_if_fail (text != NULL);
	g_return_if_fail (icon != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->callback = callback;
	_data1_->callback_target = callback_target;
	_tmp0_ = (GtkImageMenuItem*) gtk_image_menu_item_new_with_mnemonic (text);
	g_object_ref_sink (_tmp0_);
	mi = _tmp0_;
	_tmp1_ = (GtkImage*) gtk_image_new_from_icon_name (icon, (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp1_);
	image = _tmp1_;
	gtk_image_menu_item_set_image (mi, (GtkWidget*) image);
	g_signal_connect_data ((GtkMenuItem*) mi, "activate", (GCallback) ___lambda6__gtk_menu_item_activate, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	gtk_menu_shell_insert ((GtkMenuShell*) menu, G_TYPE_CHECK_INSTANCE_TYPE (mi, gtk_widget_get_type ()) ? ((GtkWidget*) mi) : NULL, -1);
	_g_object_unref0 (image);
	_g_object_unref0 (mi);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

void
menu_add_separator (GtkMenu* menu)
{
	GtkSeparatorMenuItem* mi = NULL;
	GtkSeparatorMenuItem* _tmp0_;
	g_return_if_fail (menu != NULL);
	_tmp0_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new ();
	g_object_ref_sink (_tmp0_);
	mi = _tmp0_;
	gtk_menu_shell_insert ((GtkMenuShell*) menu, G_TYPE_CHECK_INSTANCE_TYPE (mi, gtk_widget_get_type ()) ? ((GtkWidget*) mi) : NULL, -1);
	_g_object_unref0 (mi);
}

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

static void
___lambda7__callback (gpointer self)
{
	__lambda7_ ();
}

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

static void
___lambda8__callback (gpointer self)
{
	__lambda8_ ();
}

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

static void
___lambda9__callback (gpointer self)
{
	__lambda9_ ();
}

GtkMenu*
build_context_menu (void)
{
	GtkMenu* menu = NULL;
	GtkMenu* _tmp0_;
	GtkMenuItem* mi = NULL;
	GtkMenuItem* _tmp1_;
	GtkMenu* menu_go = NULL;
	XnpApplication* _tmp2_;
	GtkMenu* _tmp3_;
	GtkMenu* result;
	_tmp0_ = (GtkMenu*) gtk_menu_new ();
	g_object_ref_sink (_tmp0_);
	menu = _tmp0_;
	_tmp1_ = (GtkMenuItem*) gtk_menu_item_new_with_mnemonic (_ ("_Groups"));
	g_object_ref_sink (_tmp1_);
	mi = _tmp1_;
	_tmp2_ = application;
	_tmp3_ = xnp_application_context_menu (_tmp2_);
	menu_go = _tmp3_;
	gtk_menu_item_set_submenu (mi, menu_go);
	gtk_menu_shell_insert ((GtkMenuShell*) menu, G_TYPE_CHECK_INSTANCE_TYPE (mi, gtk_widget_get_type ()) ? ((GtkWidget*) mi) : NULL, -1);
	menu_add_separator (menu);
	menu_add_icon_item (menu, _ ("_Properties"), "gtk-properties", ___lambda7__callback, NULL);
	menu_add_icon_item (menu, _ ("_About"), "gtk-about", ___lambda8__callback, NULL);
	menu_add_separator (menu);
	menu_add_icon_item (menu, _ ("_Quit"), "gtk-quit", ___lambda9__callback, NULL);
	gtk_widget_show_all ((GtkWidget*) menu);
	result = menu;
	_g_object_unref0 (menu_go);
	_g_object_unref0 (mi);
	return result;
}

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

static void
___lambda11__g_application_activate (GApplication* _sender,
                                     gpointer self)
{
	__lambda11_ ();
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GtkApplication* app = NULL;
	GtkApplication* _tmp0_;
	GError* _inner_error0_ = NULL;
	gint result;
	gtk_init ((gint*) (&args_length1), &args);
	_tmp0_ = gtk_application_new ("org.xfce.Notes", 0);
	app = _tmp0_;
	{
		g_application_register ((GApplication*) app, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp1_ = e;
		_tmp2_ = _tmp1_->message;
		g_warning ("main-status-icon.vala:95: Application cannot be registered: %s", _tmp2_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp3_ = -1;
		_g_object_unref0 (app);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp3_;
	}
	if (g_application_get_is_remote ((GApplication*) app)) {
		g_application_activate ((GApplication*) app);
		result = 0;
		_g_object_unref0 (app);
		return result;
	}
	g_signal_connect ((GApplication*) app, "activate", (GCallback) ___lambda11__g_application_activate, NULL);
	g_set_application_name (_ ("Notes"));
	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)
{
	return _vala_main (argv, argc);
}

