/* gitg-ext-action.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-ext-action.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2014 - Jesse van den Kieboom
 *
 * gitg 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.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgitg-ext.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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

#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 _GitgExtActionFetchData GitgExtActionFetchData;

struct _GitgExtActionFetchData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GitgExtAction* self;
	gboolean result;
};

static void gitg_ext_action_real_populate_menu (GitgExtAction* self,
                                         GtkMenu* menu);
static void ___lambda5_ (GitgExtAction* self);
static void ____lambda5__gtk_menu_item_activate (GtkMenuItem* _sender,
                                          gpointer self);
static void gitg_ext_action_real_fetch_data_free (gpointer _data);
static void gitg_ext_action_real_fetch (GitgExtAction* self,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
static gboolean gitg_ext_action_real_fetch_co (GitgExtActionFetchData* _data_);
static GType gitg_ext_action_get_type_once (void);

static void
___lambda5_ (GitgExtAction* self)
{
	g_signal_emit_by_name ((GitgExtUIElement*) self, "activate");
}

static void
____lambda5__gtk_menu_item_activate (GtkMenuItem* _sender,
                                     gpointer self)
{
	___lambda5_ ((GitgExtAction*) self);
}

static void
gitg_ext_action_real_populate_menu (GitgExtAction* self,
                                    GtkMenu* menu)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	GtkMenuItem* item = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GtkMenuItem* _tmp5_;
	GtkMenuItem* _tmp6_;
	GtkMenuItem* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	GtkMenuItem* _tmp15_;
	GtkMenuItem* _tmp16_;
	g_return_if_fail (menu != NULL);
	_tmp0_ = gitg_ext_ui_element_get_available ((GitgExtUIElement*) self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		return;
	}
	_tmp2_ = gitg_ext_ui_element_get_display_name ((GitgExtUIElement*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp5_ = (GtkMenuItem*) gtk_menu_item_new_with_label (_tmp4_);
	g_object_ref_sink (_tmp5_);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	item = _tmp6_;
	_tmp7_ = item;
	_tmp8_ = gitg_ext_ui_element_get_description ((GitgExtUIElement*) self);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp7_, _tmp10_);
	_g_free0 (_tmp10_);
	_tmp11_ = gitg_ext_ui_element_get_enabled ((GitgExtUIElement*) self);
	_tmp12_ = _tmp11_;
	if (_tmp12_) {
		GtkMenuItem* _tmp13_;
		_tmp13_ = item;
		g_signal_connect_object (_tmp13_, "activate", (GCallback) ____lambda5__gtk_menu_item_activate, self, 0);
	} else {
		GtkMenuItem* _tmp14_;
		_tmp14_ = item;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp14_, FALSE);
	}
	_tmp15_ = item;
	gtk_widget_show ((GtkWidget*) _tmp15_);
	_tmp16_ = item;
	gtk_menu_shell_append ((GtkMenuShell*) menu, _tmp16_);
	_g_object_unref0 (item);
}

void
gitg_ext_action_populate_menu (GitgExtAction* self,
                               GtkMenu* menu)
{
	GitgExtActionIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = GITG_EXT_ACTION_GET_INTERFACE (self);
	if (_iface_->populate_menu) {
		_iface_->populate_menu (self, menu);
	}
}

static void
gitg_ext_action_real_fetch_data_free (gpointer _data)
{
	GitgExtActionFetchData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (GitgExtActionFetchData, _data_);
}

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

static void
gitg_ext_action_real_fetch (GitgExtAction* self,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	GitgExtActionFetchData* _data_;
	GitgExtAction* _tmp0_;
	_data_ = g_slice_new0 (GitgExtActionFetchData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, gitg_ext_action_real_fetch_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	gitg_ext_action_real_fetch_co (_data_);
}

static gboolean
gitg_ext_action_real_fetch_finish (GitgExtAction* self,
                                   GAsyncResult* _res_)
{
	gboolean result;
	GitgExtActionFetchData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static gboolean
gitg_ext_action_real_fetch_co (GitgExtActionFetchData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->result = TRUE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
gitg_ext_action_fetch (GitgExtAction* self,
                       GAsyncReadyCallback _callback_,
                       gpointer _user_data_)
{
	GitgExtActionIface* _iface_;
	_iface_ = GITG_EXT_ACTION_GET_INTERFACE (self);
	if (_iface_->fetch) {
		_iface_->fetch (self, _callback_, _user_data_);
	}
}

gboolean
gitg_ext_action_fetch_finish (GitgExtAction* self,
                              GAsyncResult* _res_)
{
	GitgExtActionIface* _iface_;
	_iface_ = GITG_EXT_ACTION_GET_INTERFACE (self);
	if (_iface_->fetch_finish) {
		return _iface_->fetch_finish (self, _res_);
	}
	return FALSE;
}

static void
gitg_ext_action_default_init (GitgExtActionIface * iface,
                              gpointer iface_data)
{
	iface->populate_menu = gitg_ext_action_real_populate_menu;
	iface->fetch = gitg_ext_action_real_fetch;
	iface->fetch_finish = gitg_ext_action_real_fetch_finish;
}

 G_GNUC_NO_INLINE static GType
gitg_ext_action_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgExtActionIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_ext_action_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType gitg_ext_action_type_id;
	gitg_ext_action_type_id = g_type_register_static (G_TYPE_INTERFACE, "GitgExtAction", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (gitg_ext_action_type_id, GITG_EXT_TYPE_UI_ELEMENT);
	return gitg_ext_action_type_id;
}

GType
gitg_ext_action_get_type (void)
{
	static gsize gitg_ext_action_type_id__once = 0;
	if (g_once_init_enter (&gitg_ext_action_type_id__once)) {
		GType gitg_ext_action_type_id;
		gitg_ext_action_type_id = gitg_ext_action_get_type_once ();
		g_once_init_leave (&gitg_ext_action_type_id__once, gitg_ext_action_type_id);
	}
	return gitg_ext_action_type_id__once;
}

