/* AppContextMenu.c generated by valac 0.56.19, the Vala compiler
 * generated from AppContextMenu.vala, do not modify */

/*
 * Copyright 2019 elementary, Inc. (https://elementary.io)
 * Copyright 2020-2021 Justin Haygood
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

#include "slingshot.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gdesktopappinfo.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <glib/gi18n-lib.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

enum  {
	SLINGSHOT_APP_CONTEXT_MENU_0_PROPERTY,
	SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY,
	SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY,
	SLINGSHOT_APP_CONTEXT_MENU_HAS_ITEMS_PROPERTY,
	SLINGSHOT_APP_CONTEXT_MENU_NUM_PROPERTIES
};
static GParamSpec* slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block6Data Block6Data;
typedef struct _Block7Data Block7Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block8Data Block8Data;
enum  {
	SLINGSHOT_APP_CONTEXT_MENU_APP_LAUNCHED_SIGNAL,
	SLINGSHOT_APP_CONTEXT_MENU_NUM_SIGNALS
};
static guint slingshot_app_context_menu_signals[SLINGSHOT_APP_CONTEXT_MENU_NUM_SIGNALS] = {0};

struct _SlingshotAppContextMenuPrivate {
	gchar* _desktop_id;
	gchar* _desktop_path;
	GDesktopAppInfo* app_info;
	SlingshotBackendSwitcherooControl* switcheroo_control;
	SlingshotBackendFavoritesManager* favorites_manager;
	gboolean _has_items;
};

struct _Block6Data {
	int _ref_count_;
	SlingshotAppContextMenu* self;
	gchar* action;
};

struct _Block7Data {
	int _ref_count_;
	SlingshotAppContextMenu* self;
	gboolean prefers_non_default_gpu;
};

struct _Block8Data {
	int _ref_count_;
	SlingshotAppContextMenu* self;
	gchar* captured_desktop_id;
};

static gint SlingshotAppContextMenu_private_offset;
static gpointer slingshot_app_context_menu_parent_class = NULL;
static GSettings* slingshot_app_context_menu__appmenu_settings;
static GSettings* slingshot_app_context_menu__appmenu_settings = NULL;
static GType slingshot_app_context_menu_type_id = 0;

static GtkModelButton* slingshot_app_context_menu_make_button (const gchar* label);
static GSettings* slingshot_app_context_menu_get_appmenu_settings (void);
static void slingshot_app_context_menu_set_appmenu_settings (GSettings* value);
static GObject * slingshot_app_context_menu_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static Block6Data* block6_data_ref (Block6Data* _data6_);
static void block6_data_unref (void * _userdata_);
static void _slingshot_app_context_menu_____lambda37_ (Block6Data* _data6_);
static void __slingshot_app_context_menu_____lambda37__gtk_button_clicked (GtkButton* _sender,
                                                                    gpointer self);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void _slingshot_app_context_menu____lambda38_ (Block7Data* _data7_);
static void __slingshot_app_context_menu____lambda38__gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void _slingshot_app_context_menu____lambda39_ (Block8Data* _data8_);
static void __slingshot_app_context_menu____lambda39__gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self);
static void slingshot_app_context_menu_finalize (GObject * obj);
static void _vala_slingshot_app_context_menu_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static void _vala_slingshot_app_context_menu_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec);
static gssize _vala_array_length (gpointer array);

static inline gpointer
slingshot_app_context_menu_get_instance_private (SlingshotAppContextMenu* self)
{
	return G_STRUCT_MEMBER_P (self, SlingshotAppContextMenu_private_offset);
}

SlingshotAppContextMenu*
slingshot_app_context_menu_construct (GType object_type,
                                      const gchar* desktop_id,
                                      const gchar* desktop_path,
                                      GtkWidget* relative_to)
{
	SlingshotAppContextMenu * self = NULL;
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (desktop_path != NULL, NULL);
	g_return_val_if_fail (relative_to != NULL, NULL);
	self = (SlingshotAppContextMenu*) g_object_new (object_type, "desktop-id", desktop_id, "desktop-path", desktop_path, "relative-to", relative_to, "position", GTK_POS_BOTTOM, NULL);
	return self;
}

SlingshotAppContextMenu*
slingshot_app_context_menu_new (const gchar* desktop_id,
                                const gchar* desktop_path,
                                GtkWidget* relative_to)
{
	return slingshot_app_context_menu_construct (SLINGSHOT_TYPE_APP_CONTEXT_MENU, desktop_id, desktop_path, relative_to);
}

void
slingshot_app_context_menu_popup_at_pointer_coords (SlingshotAppContextMenu* self,
                                                    gdouble x,
                                                    gdouble y)
{
	GdkRectangle rect = {0};
	GdkRectangle _tmp0_;
	g_return_if_fail (self != NULL);
	memset (&rect, 0, sizeof (GdkRectangle));
	rect.x = (gint) x;
	rect.y = (gint) y;
	rect.width = 1;
	rect.height = 1;
	_tmp0_ = rect;
	gtk_popover_set_pointing_to ((GtkPopover*) self, &_tmp0_);
	gtk_popover_popup ((GtkPopover*) self);
}

static GtkModelButton*
slingshot_app_context_menu_make_button (const gchar* label)
{
	GtkModelButton* btn = NULL;
	GtkModelButton* _tmp0_;
	GtkModelButton* result;
	g_return_val_if_fail (label != NULL, NULL);
	_tmp0_ = (GtkModelButton*) gtk_model_button_new ();
	g_object_ref_sink (_tmp0_);
	btn = _tmp0_;
	g_object_set (btn, "text", label, NULL);
	result = btn;
	return result;
}

const gchar*
slingshot_app_context_menu_get_desktop_id (SlingshotAppContextMenu* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_desktop_id;
	result = _tmp0_;
	return result;
}

static void
slingshot_app_context_menu_set_desktop_id (SlingshotAppContextMenu* self,
                                           const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = slingshot_app_context_menu_get_desktop_id (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_desktop_id);
		self->priv->_desktop_id = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY]);
	}
}

const gchar*
slingshot_app_context_menu_get_desktop_path (SlingshotAppContextMenu* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_desktop_path;
	result = _tmp0_;
	return result;
}

static void
slingshot_app_context_menu_set_desktop_path (SlingshotAppContextMenu* self,
                                             const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = slingshot_app_context_menu_get_desktop_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_desktop_path);
		self->priv->_desktop_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY]);
	}
}

static GSettings*
slingshot_app_context_menu_get_appmenu_settings (void)
{
	GSettings* result;
	GSettings* _tmp0_;
	_tmp0_ = slingshot_app_context_menu__appmenu_settings;
	result = _tmp0_;
	return result;
}

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

static void
slingshot_app_context_menu_set_appmenu_settings (GSettings* value)
{
	GSettings* _tmp0_;
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (slingshot_app_context_menu__appmenu_settings);
	slingshot_app_context_menu__appmenu_settings = _tmp0_;
}

gboolean
slingshot_app_context_menu_get_has_items (SlingshotAppContextMenu* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_has_items;
	return result;
}

static Block6Data*
block6_data_ref (Block6Data* _data6_)
{
	g_atomic_int_inc (&_data6_->_ref_count_);
	return _data6_;
}

static void
block6_data_unref (void * _userdata_)
{
	Block6Data* _data6_;
	_data6_ = (Block6Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data6_->_ref_count_)) {
		SlingshotAppContextMenu* self;
		self = _data6_->self;
		_g_free0 (_data6_->action);
		_g_object_unref0 (self);
		g_slice_free (Block6Data, _data6_);
	}
}

static void
_slingshot_app_context_menu_____lambda37_ (Block6Data* _data6_)
{
	SlingshotAppContextMenu* self;
	GDesktopAppInfo* _tmp0_;
	const gchar* _tmp1_;
	GAppLaunchContext* _tmp2_;
	GAppLaunchContext* _tmp3_;
	self = _data6_->self;
	gtk_popover_popdown ((GtkPopover*) self);
	_tmp0_ = self->priv->app_info;
	_tmp1_ = _data6_->action;
	_tmp2_ = g_app_launch_context_new ();
	_tmp3_ = _tmp2_;
	g_desktop_app_info_launch_action (_tmp0_, _tmp1_, _tmp3_);
	_g_object_unref0 (_tmp3_);
	g_signal_emit (self, slingshot_app_context_menu_signals[SLINGSHOT_APP_CONTEXT_MENU_APP_LAUNCHED_SIGNAL], 0);
}

static void
__slingshot_app_context_menu_____lambda37__gtk_button_clicked (GtkButton* _sender,
                                                               gpointer self)
{
	_slingshot_app_context_menu_____lambda37_ (self);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		SlingshotAppContextMenu* self;
		self = _data7_->self;
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static void
_slingshot_app_context_menu____lambda38_ (Block7Data* _data7_)
{
	SlingshotAppContextMenu* self;
	GError* _inner_error0_ = NULL;
	self = _data7_->self;
	gtk_popover_popdown ((GtkPopover*) self);
	{
		GAppLaunchContext* context = NULL;
		GAppLaunchContext* _tmp0_;
		SlingshotBackendSwitcherooControl* _tmp1_;
		GAppLaunchContext* _tmp2_;
		GDesktopAppInfo* _tmp3_;
		GAppLaunchContext* _tmp4_;
		_tmp0_ = g_app_launch_context_new ();
		context = _tmp0_;
		_tmp1_ = self->priv->switcheroo_control;
		_tmp2_ = context;
		slingshot_backend_switcheroo_control_apply_gpu_environment (_tmp1_, _tmp2_, _data7_->prefers_non_default_gpu);
		_tmp3_ = self->priv->app_info;
		_tmp4_ = context;
		g_app_info_launch ((GAppInfo*) _tmp3_, NULL, _tmp4_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (context);
			goto __catch0_g_error;
		}
		g_signal_emit (self, slingshot_app_context_menu_signals[SLINGSHOT_APP_CONTEXT_MENU_APP_LAUNCHED_SIGNAL], 0);
		_g_object_unref0 (context);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp5_;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = self->priv->_desktop_id;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_warning ("AppContextMenu.vala:99: Failed to launch %s: %s", _tmp5_, _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

static void
__slingshot_app_context_menu____lambda38__gtk_button_clicked (GtkButton* _sender,
                                                              gpointer self)
{
	_slingshot_app_context_menu____lambda38_ (self);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		SlingshotAppContextMenu* self;
		self = _data8_->self;
		_g_free0 (_data8_->captured_desktop_id);
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static void
_slingshot_app_context_menu____lambda39_ (Block8Data* _data8_)
{
	SlingshotAppContextMenu* self;
	SlingshotBackendFavoritesManager* _tmp0_;
	const gchar* _tmp1_;
	self = _data8_->self;
	gtk_popover_popdown ((GtkPopover*) self);
	_tmp0_ = self->priv->favorites_manager;
	_tmp1_ = _data8_->captured_desktop_id;
	if (slingshot_backend_favorites_manager_is_favorite (_tmp0_, _tmp1_)) {
		SlingshotBackendFavoritesManager* _tmp2_;
		const gchar* _tmp3_;
		_tmp2_ = self->priv->favorites_manager;
		_tmp3_ = _data8_->captured_desktop_id;
		slingshot_backend_favorites_manager_remove_favorite (_tmp2_, _tmp3_);
	} else {
		SlingshotBackendFavoritesManager* _tmp4_;
		const gchar* _tmp5_;
		_tmp4_ = self->priv->favorites_manager;
		_tmp5_ = _data8_->captured_desktop_id;
		slingshot_backend_favorites_manager_add_favorite (_tmp4_, _tmp5_);
	}
}

static void
__slingshot_app_context_menu____lambda39__gtk_button_clicked (GtkButton* _sender,
                                                              gpointer self)
{
	_slingshot_app_context_menu____lambda39_ (self);
}

static GObject *
slingshot_app_context_menu_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SlingshotAppContextMenu * self;
	SlingshotBackendSwitcherooControl* _tmp0_;
	const gchar* _tmp1_;
	GDesktopAppInfo* _tmp2_;
	GtkBox* box = NULL;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	GDesktopAppInfo* _tmp5_;
	gchar** _tmp6_;
	gchar** _tmp7_;
	gboolean _tmp19_ = FALSE;
	SlingshotBackendSwitcherooControl* _tmp20_;
	GSettings* _tmp34_;
	GSettings* _tmp35_;
	GtkBox* _tmp51_;
	GtkBox* _tmp52_;
	parent_class = G_OBJECT_CLASS (slingshot_app_context_menu_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_TYPE_APP_CONTEXT_MENU, SlingshotAppContextMenu);
	_tmp0_ = slingshot_backend_switcheroo_control_new ();
	_g_object_unref0 (self->priv->switcheroo_control);
	self->priv->switcheroo_control = _tmp0_;
	_tmp1_ = self->priv->_desktop_id;
	_tmp2_ = g_desktop_app_info_new (_tmp1_);
	_g_object_unref0 (self->priv->app_info);
	self->priv->app_info = _tmp2_;
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp3_);
	box = _tmp3_;
	_tmp4_ = box;
	g_object_set ((GtkWidget*) _tmp4_, "margin", 4, NULL);
	_tmp5_ = self->priv->app_info;
	_tmp7_ = _tmp6_ = g_desktop_app_info_list_actions (_tmp5_);
	{
		gchar** _action_collection = NULL;
		gint _action_collection_length1 = 0;
		gint __action_collection_size_ = 0;
		gint _action_it = 0;
		_action_collection = _tmp7_;
		_action_collection_length1 = _vala_array_length (_tmp6_);
		for (_action_it = 0; _action_it < _action_collection_length1; _action_it = _action_it + 1) {
			const gchar* _action = NULL;
			_action = _action_collection[_action_it];
			{
				Block6Data* _data6_;
				const gchar* _tmp8_;
				gchar* _tmp9_;
				GtkModelButton* btn = NULL;
				GDesktopAppInfo* _tmp10_;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				GtkModelButton* _tmp14_;
				GtkModelButton* _tmp15_;
				GtkModelButton* _tmp16_;
				GtkBox* _tmp17_;
				GtkModelButton* _tmp18_;
				_data6_ = g_slice_new0 (Block6Data);
				_data6_->_ref_count_ = 1;
				_data6_->self = g_object_ref (self);
				_tmp8_ = _action;
				_tmp9_ = g_strdup (_tmp8_);
				_data6_->action = _tmp9_;
				_tmp10_ = self->priv->app_info;
				_tmp11_ = _data6_->action;
				_tmp12_ = g_desktop_app_info_get_action_name (_tmp10_, _tmp11_);
				_tmp13_ = _tmp12_;
				_tmp14_ = slingshot_app_context_menu_make_button (_tmp13_);
				_tmp15_ = _tmp14_;
				_g_free0 (_tmp13_);
				btn = _tmp15_;
				_tmp16_ = btn;
				g_signal_connect_data ((GtkButton*) _tmp16_, "clicked", (GCallback) __slingshot_app_context_menu_____lambda37__gtk_button_clicked, block6_data_ref (_data6_), (GClosureNotify) block6_data_unref, 0);
				_tmp17_ = box;
				_tmp18_ = btn;
				gtk_container_add ((GtkContainer*) _tmp17_, (GtkWidget*) _tmp18_);
				self->priv->_has_items = TRUE;
				_g_object_unref0 (btn);
				block6_data_unref (_data6_);
				_data6_ = NULL;
			}
		}
	}
	_tmp20_ = self->priv->switcheroo_control;
	if (_tmp20_ != NULL) {
		SlingshotBackendSwitcherooControl* _tmp21_;
		gboolean _tmp22_;
		gboolean _tmp23_;
		_tmp21_ = self->priv->switcheroo_control;
		_tmp22_ = slingshot_backend_switcheroo_control_get_has_dual_gpu (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp19_ = _tmp23_;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		Block7Data* _data7_;
		GDesktopAppInfo* _tmp24_;
		gchar* gpu_name = NULL;
		SlingshotBackendSwitcherooControl* _tmp25_;
		gchar* _tmp26_;
		gchar* label = NULL;
		const gchar* _tmp27_;
		gchar* _tmp28_;
		GtkModelButton* btn = NULL;
		const gchar* _tmp29_;
		GtkModelButton* _tmp30_;
		GtkModelButton* _tmp31_;
		GtkBox* _tmp32_;
		GtkModelButton* _tmp33_;
		_data7_ = g_slice_new0 (Block7Data);
		_data7_->_ref_count_ = 1;
		_data7_->self = g_object_ref (self);
		_tmp24_ = self->priv->app_info;
		_data7_->prefers_non_default_gpu = g_desktop_app_info_get_boolean (_tmp24_, "PrefersNonDefaultGPU");
		_tmp25_ = self->priv->switcheroo_control;
		_tmp26_ = slingshot_backend_switcheroo_control_get_gpu_name (_tmp25_, _data7_->prefers_non_default_gpu);
		gpu_name = _tmp26_;
		_tmp27_ = gpu_name;
		_tmp28_ = g_strdup_printf (_ ("Open with %s Graphics"), _tmp27_);
		label = _tmp28_;
		_tmp29_ = label;
		_tmp30_ = slingshot_app_context_menu_make_button (_tmp29_);
		btn = _tmp30_;
		_tmp31_ = btn;
		g_signal_connect_data ((GtkButton*) _tmp31_, "clicked", (GCallback) __slingshot_app_context_menu____lambda38__gtk_button_clicked, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
		_tmp32_ = box;
		_tmp33_ = btn;
		gtk_container_add ((GtkContainer*) _tmp32_, (GtkWidget*) _tmp33_);
		self->priv->_has_items = TRUE;
		_g_object_unref0 (btn);
		_g_free0 (label);
		_g_free0 (gpu_name);
		block7_data_unref (_data7_);
		_data7_ = NULL;
	}
	_tmp34_ = slingshot_app_context_menu_get_appmenu_settings ();
	_tmp35_ = _tmp34_;
	if (g_settings_get_boolean (_tmp35_, "enable-favorites")) {
		Block8Data* _data8_;
		SlingshotBackendFavoritesManager* _tmp36_;
		const gchar* _tmp37_;
		gchar* _tmp38_;
		gboolean is_favorite = FALSE;
		SlingshotBackendFavoritesManager* _tmp42_;
		const gchar* _tmp43_;
		const gchar* _tmp44_ = NULL;
		gchar* fav_label = NULL;
		gchar* _tmp45_;
		GtkModelButton* fav_btn = NULL;
		const gchar* _tmp46_;
		GtkModelButton* _tmp47_;
		GtkModelButton* _tmp48_;
		GtkBox* _tmp49_;
		GtkModelButton* _tmp50_;
		_data8_ = g_slice_new0 (Block8Data);
		_data8_->_ref_count_ = 1;
		_data8_->self = g_object_ref (self);
		_tmp36_ = slingshot_backend_favorites_manager_get_default ();
		_g_object_unref0 (self->priv->favorites_manager);
		self->priv->favorites_manager = _tmp36_;
		_tmp37_ = self->priv->_desktop_id;
		_tmp38_ = g_strdup (_tmp37_);
		_data8_->captured_desktop_id = _tmp38_;
		if (self->priv->_has_items) {
			GtkBox* _tmp39_;
			GtkSeparator* _tmp40_;
			GtkSeparator* _tmp41_;
			_tmp39_ = box;
			_tmp40_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
			g_object_ref_sink (_tmp40_);
			_tmp41_ = _tmp40_;
			gtk_container_add ((GtkContainer*) _tmp39_, (GtkWidget*) _tmp41_);
			_g_object_unref0 (_tmp41_);
		}
		_tmp42_ = self->priv->favorites_manager;
		_tmp43_ = _data8_->captured_desktop_id;
		is_favorite = slingshot_backend_favorites_manager_is_favorite (_tmp42_, _tmp43_);
		if (is_favorite) {
			_tmp44_ = _ ("Remove from Favorites");
		} else {
			_tmp44_ = _ ("Add to Favorites");
		}
		_tmp45_ = g_strdup (_tmp44_);
		fav_label = _tmp45_;
		_tmp46_ = fav_label;
		_tmp47_ = slingshot_app_context_menu_make_button (_tmp46_);
		fav_btn = _tmp47_;
		_tmp48_ = fav_btn;
		g_signal_connect_data ((GtkButton*) _tmp48_, "clicked", (GCallback) __slingshot_app_context_menu____lambda39__gtk_button_clicked, block8_data_ref (_data8_), (GClosureNotify) block8_data_unref, 0);
		_tmp49_ = box;
		_tmp50_ = fav_btn;
		gtk_container_add ((GtkContainer*) _tmp49_, (GtkWidget*) _tmp50_);
		self->priv->_has_items = TRUE;
		_g_object_unref0 (fav_btn);
		_g_free0 (fav_label);
		block8_data_unref (_data8_);
		_data8_ = NULL;
	}
	_tmp51_ = box;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp51_);
	_tmp52_ = box;
	gtk_widget_show_all ((GtkWidget*) _tmp52_);
	_g_object_unref0 (box);
	return obj;
}

static void
slingshot_app_context_menu_class_init (SlingshotAppContextMenuClass * klass,
                                       gpointer klass_data)
{
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	slingshot_app_context_menu_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SlingshotAppContextMenu_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_slingshot_app_context_menu_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_slingshot_app_context_menu_set_property;
	G_OBJECT_CLASS (klass)->constructor = slingshot_app_context_menu_constructor;
	G_OBJECT_CLASS (klass)->finalize = slingshot_app_context_menu_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY, slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY] = g_param_spec_string ("desktop-id", "desktop-id", "desktop-id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY, slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY] = g_param_spec_string ("desktop-path", "desktop-path", "desktop-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SLINGSHOT_APP_CONTEXT_MENU_HAS_ITEMS_PROPERTY, slingshot_app_context_menu_properties[SLINGSHOT_APP_CONTEXT_MENU_HAS_ITEMS_PROPERTY] = g_param_spec_boolean ("has-items", "has-items", "has-items", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	slingshot_app_context_menu_signals[SLINGSHOT_APP_CONTEXT_MENU_APP_LAUNCHED_SIGNAL] = g_signal_new ("app-launched", SLINGSHOT_TYPE_APP_CONTEXT_MENU, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	_tmp0_ = slingshot_app_context_menu_get_appmenu_settings ();
	_tmp1_ = _tmp0_;
	if (_tmp1_ == NULL) {
		GSettings* _tmp2_;
		GSettings* _tmp3_;
		_tmp2_ = g_settings_new ("org.ubuntubudgie.plugins.budgie-appmenu");
		_tmp3_ = _tmp2_;
		slingshot_app_context_menu_set_appmenu_settings (_tmp3_);
		_g_object_unref0 (_tmp3_);
	}
}

static void
slingshot_app_context_menu_instance_init (SlingshotAppContextMenu * self,
                                          gpointer klass)
{
	self->priv = slingshot_app_context_menu_get_instance_private (self);
	self->priv->_has_items = FALSE;
}

static void
slingshot_app_context_menu_finalize (GObject * obj)
{
	SlingshotAppContextMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_TYPE_APP_CONTEXT_MENU, SlingshotAppContextMenu);
	_g_free0 (self->priv->_desktop_id);
	_g_free0 (self->priv->_desktop_path);
	_g_object_unref0 (self->priv->app_info);
	_g_object_unref0 (self->priv->switcheroo_control);
	_g_object_unref0 (self->priv->favorites_manager);
	G_OBJECT_CLASS (slingshot_app_context_menu_parent_class)->finalize (obj);
}

GType
slingshot_app_context_menu_get_type (void)
{
	return slingshot_app_context_menu_type_id;
}

GType
slingshot_app_context_menu_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (SlingshotAppContextMenuClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) slingshot_app_context_menu_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SlingshotAppContextMenu), 0, (GInstanceInitFunc) slingshot_app_context_menu_instance_init, NULL };
	slingshot_app_context_menu_type_id = g_type_module_register_type (module, gtk_popover_get_type (), "SlingshotAppContextMenu", &g_define_type_info, 0);
	SlingshotAppContextMenu_private_offset = sizeof (SlingshotAppContextMenuPrivate);
	return slingshot_app_context_menu_type_id;
}

static void
_vala_slingshot_app_context_menu_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	SlingshotAppContextMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SLINGSHOT_TYPE_APP_CONTEXT_MENU, SlingshotAppContextMenu);
	switch (property_id) {
		case SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY:
		g_value_set_string (value, slingshot_app_context_menu_get_desktop_id (self));
		break;
		case SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY:
		g_value_set_string (value, slingshot_app_context_menu_get_desktop_path (self));
		break;
		case SLINGSHOT_APP_CONTEXT_MENU_HAS_ITEMS_PROPERTY:
		g_value_set_boolean (value, slingshot_app_context_menu_get_has_items (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_slingshot_app_context_menu_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	SlingshotAppContextMenu * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SLINGSHOT_TYPE_APP_CONTEXT_MENU, SlingshotAppContextMenu);
	switch (property_id) {
		case SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_ID_PROPERTY:
		slingshot_app_context_menu_set_desktop_id (self, g_value_get_string (value));
		break;
		case SLINGSHOT_APP_CONTEXT_MENU_DESKTOP_PATH_PROPERTY:
		slingshot_app_context_menu_set_desktop_path (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

