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

/*
 * This file is part of gitg
 *
 * Copyright (C) 2022 - Adwait Rawat
 *
 * 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 <glib-object.h>
#include "libgitg-ext.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "libgitg.h"
#include "config.h"
#include <libgit2-glib/ggit.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>

#define GITG_REF_ACTION_CREATE_BRANCH_version VERSION
#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 GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH (gitg_commit_action_create_branch_get_type ())
#define GITG_COMMIT_ACTION_CREATE_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH, GitgCommitActionCreateBranch))
#define GITG_COMMIT_ACTION_CREATE_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH, GitgCommitActionCreateBranchClass))
#define GITG_IS_COMMIT_ACTION_CREATE_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH))
#define GITG_IS_COMMIT_ACTION_CREATE_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH))
#define GITG_COMMIT_ACTION_CREATE_BRANCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH, GitgCommitActionCreateBranchClass))

typedef struct _GitgCommitActionCreateBranch GitgCommitActionCreateBranch;
typedef struct _GitgCommitActionCreateBranchClass GitgCommitActionCreateBranchClass;
typedef struct _GitgCommitActionCreateBranchPrivate GitgCommitActionCreateBranchPrivate;

#define GITG_TYPE_REF_ACTION_CREATE_BRANCH (gitg_ref_action_create_branch_get_type ())
#define GITG_REF_ACTION_CREATE_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranch))
#define GITG_REF_ACTION_CREATE_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranchClass))
#define GITG_IS_REF_ACTION_CREATE_BRANCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GITG_TYPE_REF_ACTION_CREATE_BRANCH))
#define GITG_IS_REF_ACTION_CREATE_BRANCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GITG_TYPE_REF_ACTION_CREATE_BRANCH))
#define GITG_REF_ACTION_CREATE_BRANCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranchClass))

typedef struct _GitgRefActionCreateBranch GitgRefActionCreateBranch;
typedef struct _GitgRefActionCreateBranchClass GitgRefActionCreateBranchClass;
typedef struct _GitgRefActionCreateBranchPrivate GitgRefActionCreateBranchPrivate;
enum  {
	GITG_REF_ACTION_CREATE_BRANCH_0_PROPERTY,
	GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY,
	GITG_REF_ACTION_CREATE_BRANCH_ID_PROPERTY,
	GITG_REF_ACTION_CREATE_BRANCH_DESCRIPTION_PROPERTY,
	GITG_REF_ACTION_CREATE_BRANCH_NUM_PROPERTIES
};
static GParamSpec* gitg_ref_action_create_branch_properties[GITG_REF_ACTION_CREATE_BRANCH_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GitgCommitActionCreateBranch {
	GObject parent_instance;
	GitgCommitActionCreateBranchPrivate * priv;
};

struct _GitgCommitActionCreateBranchClass {
	GObjectClass parent_class;
	void (*activate) (GitgCommitActionCreateBranch* self);
	gchar* (*get_id) (GitgCommitActionCreateBranch* self);
	gchar* (*get_description) (GitgCommitActionCreateBranch* self);
};

struct _GitgRefActionCreateBranch {
	GitgCommitActionCreateBranch parent_instance;
	GitgRefActionCreateBranchPrivate * priv;
};

struct _GitgRefActionCreateBranchClass {
	GitgCommitActionCreateBranchClass parent_class;
};

struct _GitgRefActionCreateBranchPrivate {
	GitgRef* _reference;
};

static gint GitgRefActionCreateBranch_private_offset;
static gpointer gitg_ref_action_create_branch_parent_class = NULL;
static GitgExtRefActionIface * gitg_ref_action_create_branch_gitg_ext_ref_action_parent_iface = NULL;

VALA_EXTERN GType gitg_commit_action_create_branch_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgCommitActionCreateBranch, g_object_unref)
VALA_EXTERN GType gitg_ref_action_create_branch_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GitgRefActionCreateBranch, g_object_unref)
VALA_EXTERN void gitg_commit_action_create_branch_activate (GitgCommitActionCreateBranch* self);
VALA_EXTERN gchar* gitg_commit_action_create_branch_get_id (GitgCommitActionCreateBranch* self);
VALA_EXTERN gchar* gitg_commit_action_create_branch_get_description (GitgCommitActionCreateBranch* self);
VALA_EXTERN GitgRefActionCreateBranch* gitg_ref_action_create_branch_new (GitgExtApplication* application,
                                                              GitgExtRefActionInterface* action_interface,
                                                              GitgRef* reference);
VALA_EXTERN GitgRefActionCreateBranch* gitg_ref_action_create_branch_construct (GType object_type,
                                                                    GitgExtApplication* application,
                                                                    GitgExtRefActionInterface* action_interface,
                                                                    GitgRef* reference);
static void gitg_ref_action_create_branch_real_activate (GitgCommitActionCreateBranch* base);
static void gitg_ref_action_create_branch_finalize (GObject * obj);
static GType gitg_ref_action_create_branch_get_type_once (void);
static void _vala_gitg_ref_action_create_branch_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_gitg_ref_action_create_branch_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec);

static inline gpointer
gitg_ref_action_create_branch_get_instance_private (GitgRefActionCreateBranch* self)
{
	return G_STRUCT_MEMBER_P (self, GitgRefActionCreateBranch_private_offset);
}

GitgRefActionCreateBranch*
gitg_ref_action_create_branch_construct (GType object_type,
                                         GitgExtApplication* application,
                                         GitgExtRefActionInterface* action_interface,
                                         GitgRef* reference)
{
	GitgRefActionCreateBranch * self = NULL;
	g_return_val_if_fail (application != NULL, NULL);
	g_return_val_if_fail (action_interface != NULL, NULL);
	g_return_val_if_fail (reference != NULL, NULL);
	self = (GitgRefActionCreateBranch*) g_object_new (object_type, "application", application, "action-interface", action_interface, "reference", reference, NULL);
	return self;
}

GitgRefActionCreateBranch*
gitg_ref_action_create_branch_new (GitgExtApplication* application,
                                   GitgExtRefActionInterface* action_interface,
                                   GitgRef* reference)
{
	return gitg_ref_action_create_branch_construct (GITG_TYPE_REF_ACTION_CREATE_BRANCH, application, action_interface, reference);
}

static void
gitg_ref_action_create_branch_real_activate (GitgCommitActionCreateBranch* base)
{
	GitgRefActionCreateBranch * self;
	GError* _inner_error0_ = NULL;
	self = (GitgRefActionCreateBranch*) base;
	{
		GgitRef* _tmp0_ = NULL;
		GitgRef* _tmp1_;
		GitgRef* _tmp2_;
		GgitRef* _tmp3_;
		GgitObject* _tmp4_ = NULL;
		GgitObject* _tmp5_;
		_tmp1_ = gitg_ext_ref_action_get_reference ((GitgExtRefAction*) self);
		_tmp2_ = _tmp1_;
		_tmp3_ = ggit_ref_resolve ((GgitRef*) _tmp2_, &_inner_error0_);
		_tmp0_ = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp5_ = ggit_ref_lookup (_tmp0_, &_inner_error0_);
		_tmp4_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (_tmp0_);
			goto __catch0_g_error;
		}
		gitg_ext_commit_action_set_commit ((GitgExtCommitAction*) self, G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, GITG_TYPE_COMMIT) ? ((GitgCommit*) _tmp4_) : NULL);
		GITG_COMMIT_ACTION_CREATE_BRANCH_CLASS (gitg_ref_action_create_branch_parent_class)->activate (G_TYPE_CHECK_INSTANCE_CAST (self, GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH, GitgCommitActionCreateBranch));
		_g_object_unref0 (_tmp4_);
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GitgExtApplication* _tmp6_;
		GitgExtApplication* _tmp7_;
		GitgExtApplication* _tmp8_;
		GError* _tmp9_;
		const gchar* _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = gitg_ext_ui_element_get_application ((GitgExtUIElement*) self);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp9_ = e;
		_tmp10_ = _tmp9_->message;
		gitg_ext_application_show_infobar (_tmp8_, _ ("Failed to lookup reference"), _tmp10_, GTK_MESSAGE_ERROR);
		_g_object_unref0 (_tmp8_);
		_g_error_free0 (e);
		return;
	}
	__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 GitgRef*
gitg_ref_action_create_branch_real_get_reference (GitgExtRefAction* base)
{
	GitgRef* result;
	GitgRefActionCreateBranch* self;
	GitgRef* _tmp0_;
	self = (GitgRefActionCreateBranch*) base;
	_tmp0_ = self->priv->_reference;
	result = _tmp0_;
	return result;
}

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

static void
gitg_ref_action_create_branch_real_set_reference (GitgExtRefAction* base,
                                                  GitgRef* value)
{
	GitgRefActionCreateBranch* self;
	GitgRef* old_value;
	self = (GitgRefActionCreateBranch*) base;
	old_value = gitg_ref_action_create_branch_real_get_reference (base);
	if (old_value != value) {
		GitgRef* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_reference);
		self->priv->_reference = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gitg_ref_action_create_branch_properties[GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY]);
	}
}

static gchar*
gitg_ref_action_create_branch_real_get_id (GitgCommitActionCreateBranch* base)
{
	gchar* result;
	GitgRefActionCreateBranch* self;
	gchar* _tmp0_;
	self = (GitgRefActionCreateBranch*) base;
	_tmp0_ = g_strdup ("/org/gnome/gitg/ref-actions/create-branch");
	result = _tmp0_;
	return result;
}

static gchar*
gitg_ref_action_create_branch_real_get_description (GitgCommitActionCreateBranch* base)
{
	gchar* result;
	GitgRefActionCreateBranch* self;
	gchar* _tmp0_;
	self = (GitgRefActionCreateBranch*) base;
	_tmp0_ = g_strdup (_ ("Create a new branch at the selected reference"));
	result = _tmp0_;
	return result;
}

static void
gitg_ref_action_create_branch_class_init (GitgRefActionCreateBranchClass * klass,
                                          gpointer klass_data)
{
	gitg_ref_action_create_branch_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgRefActionCreateBranch_private_offset);
	((GitgCommitActionCreateBranchClass *) klass)->activate = (void (*) (GitgCommitActionCreateBranch*)) gitg_ref_action_create_branch_real_activate;
	GITG_COMMIT_ACTION_CREATE_BRANCH_CLASS (klass)->get_id = (gchar* (*) (GitgCommitActionCreateBranch*)) gitg_ref_action_create_branch_real_get_id;
	GITG_COMMIT_ACTION_CREATE_BRANCH_CLASS (klass)->get_description = (gchar* (*) (GitgCommitActionCreateBranch*)) gitg_ref_action_create_branch_real_get_description;
	G_OBJECT_CLASS (klass)->get_property = _vala_gitg_ref_action_create_branch_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gitg_ref_action_create_branch_set_property;
	G_OBJECT_CLASS (klass)->finalize = gitg_ref_action_create_branch_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY, gitg_ref_action_create_branch_properties[GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY] = g_param_spec_object ("reference", "reference", "reference", GITG_TYPE_REF, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_REF_ACTION_CREATE_BRANCH_ID_PROPERTY, gitg_ref_action_create_branch_properties[GITG_REF_ACTION_CREATE_BRANCH_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GITG_REF_ACTION_CREATE_BRANCH_DESCRIPTION_PROPERTY, gitg_ref_action_create_branch_properties[GITG_REF_ACTION_CREATE_BRANCH_DESCRIPTION_PROPERTY] = g_param_spec_string ("description", "description", "description", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gitg_ref_action_create_branch_gitg_ext_ref_action_interface_init (GitgExtRefActionIface * iface,
                                                                  gpointer iface_data)
{
	gitg_ref_action_create_branch_gitg_ext_ref_action_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_reference = gitg_ref_action_create_branch_real_get_reference;
	iface->set_reference = gitg_ref_action_create_branch_real_set_reference;
	iface->get_action_interface = (GitgExtRefActionInterface* (*) (GitgExtCommitAction*)) gitg_ext_commit_action_get_action_interface;
	iface->set_action_interface = (void (*) (GitgExtCommitAction*, GitgExtRefActionInterface*)) gitg_ext_commit_action_set_action_interface;
}

static void
gitg_ref_action_create_branch_instance_init (GitgRefActionCreateBranch * self,
                                             gpointer klass)
{
	self->priv = gitg_ref_action_create_branch_get_instance_private (self);
}

static void
gitg_ref_action_create_branch_finalize (GObject * obj)
{
	GitgRefActionCreateBranch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranch);
	_g_object_unref0 (self->priv->_reference);
	G_OBJECT_CLASS (gitg_ref_action_create_branch_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_ref_action_create_branch_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgRefActionCreateBranchClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_ref_action_create_branch_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgRefActionCreateBranch), 0, (GInstanceInitFunc) gitg_ref_action_create_branch_instance_init, NULL };
	static const GInterfaceInfo gitg_ext_ref_action_info = { (GInterfaceInitFunc) gitg_ref_action_create_branch_gitg_ext_ref_action_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gitg_ref_action_create_branch_type_id;
	gitg_ref_action_create_branch_type_id = g_type_register_static (GITG_TYPE_COMMIT_ACTION_CREATE_BRANCH, "GitgRefActionCreateBranch", &g_define_type_info, 0);
	g_type_add_interface_static (gitg_ref_action_create_branch_type_id, GITG_EXT_TYPE_REF_ACTION, &gitg_ext_ref_action_info);
	GitgRefActionCreateBranch_private_offset = g_type_add_instance_private (gitg_ref_action_create_branch_type_id, sizeof (GitgRefActionCreateBranchPrivate));
	return gitg_ref_action_create_branch_type_id;
}

GType
gitg_ref_action_create_branch_get_type (void)
{
	static gsize gitg_ref_action_create_branch_type_id__once = 0;
	if (g_once_init_enter (&gitg_ref_action_create_branch_type_id__once)) {
		GType gitg_ref_action_create_branch_type_id;
		gitg_ref_action_create_branch_type_id = gitg_ref_action_create_branch_get_type_once ();
		g_once_init_leave (&gitg_ref_action_create_branch_type_id__once, gitg_ref_action_create_branch_type_id);
	}
	return gitg_ref_action_create_branch_type_id__once;
}

static void
_vala_gitg_ref_action_create_branch_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	GitgRefActionCreateBranch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranch);
	switch (property_id) {
		case GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY:
		g_value_set_object (value, gitg_ext_ref_action_get_reference ((GitgExtRefAction*) self));
		break;
		case GITG_REF_ACTION_CREATE_BRANCH_ID_PROPERTY:
		g_value_take_string (value, gitg_commit_action_create_branch_get_id ((GitgCommitActionCreateBranch*) self));
		break;
		case GITG_REF_ACTION_CREATE_BRANCH_DESCRIPTION_PROPERTY:
		g_value_take_string (value, gitg_commit_action_create_branch_get_description ((GitgCommitActionCreateBranch*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gitg_ref_action_create_branch_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec)
{
	GitgRefActionCreateBranch * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GITG_TYPE_REF_ACTION_CREATE_BRANCH, GitgRefActionCreateBranch);
	switch (property_id) {
		case GITG_REF_ACTION_CREATE_BRANCH_REFERENCE_PROPERTY:
		gitg_ext_ref_action_set_reference ((GitgExtRefAction*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

