/* gitg-commit-list-view.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-commit-list-view.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2012 - 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.h"
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <libgit2-glib/ggit.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  {
	GITG_COMMIT_LIST_VIEW_0_PROPERTY,
	GITG_COMMIT_LIST_VIEW_NUM_PROPERTIES
};
static GParamSpec* gitg_commit_list_view_properties[GITG_COMMIT_LIST_VIEW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GgitOId_free0(var) ((var == NULL) ? NULL : (var = (_vala_GgitOId_free (var), NULL)))

static gpointer gitg_commit_list_view_parent_class = NULL;
static GtkBuildableIface * gitg_commit_list_view_gtk_buildable_parent_iface = NULL;

static void gitg_commit_list_view_lanes_data_func (GitgCommitListView* self,
                                            GtkCellLayout* layout,
                                            GtkCellRenderer* cell,
                                            GtkTreeModel* model,
                                            GtkTreeIter* iter);
static void _vala_GgitOId_free (GgitOId* self);
static void gitg_commit_list_view_real_parser_finished (GtkBuildable* base,
                                                 GtkBuilder* builder);
static void _gitg_commit_list_view_lanes_data_func_gtk_cell_layout_data_func (GtkCellLayout* cell_layout,
                                                                       GtkCellRenderer* cell,
                                                                       GtkTreeModel* tree_model,
                                                                       GtkTreeIter* iter,
                                                                       gpointer self);
static GType gitg_commit_list_view_get_type_once (void);

GitgCommitListView*
gitg_commit_list_view_construct (GType object_type,
                                 GitgCommitModel* model)
{
	GitgCommitListView * self = NULL;
	g_return_val_if_fail (model != NULL, NULL);
	self = (GitgCommitListView*) g_object_new (object_type, "model", model, NULL);
	return self;
}

GitgCommitListView*
gitg_commit_list_view_new (GitgCommitModel* model)
{
	return gitg_commit_list_view_construct (GITG_TYPE_COMMIT_LIST_VIEW, model);
}

GitgCommitListView*
gitg_commit_list_view_construct_for_repository (GType object_type,
                                                GitgRepository* repository)
{
	GitgCommitListView * self = NULL;
	GitgCommitModel* _tmp0_;
	GitgCommitModel* _tmp1_;
	g_return_val_if_fail (repository != NULL, NULL);
	_tmp0_ = gitg_commit_model_new (repository);
	_tmp1_ = _tmp0_;
	self = (GitgCommitListView*) gitg_commit_list_view_construct (object_type, _tmp1_);
	_g_object_unref0 (_tmp1_);
	return self;
}

GitgCommitListView*
gitg_commit_list_view_new_for_repository (GitgRepository* repository)
{
	return gitg_commit_list_view_construct_for_repository (GITG_TYPE_COMMIT_LIST_VIEW, repository);
}

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

GtkCellRenderer*
gitg_commit_list_view_find_cell_at_pos (GitgCommitListView* self,
                                        GtkTreeViewColumn* column,
                                        GtkTreePath* path,
                                        gint x,
                                        gint* width)
{
	gint _vala_width = 0;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp0_;
	GtkTreeModel* _tmp1_;
	GtkTreeIter _tmp2_ = {0};
	GtkTreeModel* _tmp3_;
	GtkTreeModel* _tmp4_;
	GtkTreeIter _tmp5_;
	GList* cells = NULL;
	GList* _tmp6_;
	GList* _tmp7_;
	GtkCellRenderer* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = gtk_tree_view_get_model ((GtkTreeView*) self);
	_tmp1_ = _tmp0_;
	gtk_tree_model_get_iter (_tmp1_, &_tmp2_, path);
	iter = _tmp2_;
	_tmp3_ = gtk_tree_view_get_model ((GtkTreeView*) self);
	_tmp4_ = _tmp3_;
	_tmp5_ = iter;
	gtk_tree_view_column_cell_set_cell_data (column, _tmp4_, &_tmp5_, FALSE, FALSE);
	_tmp6_ = gtk_cell_layout_get_cells ((GtkCellLayout*) column);
	cells = _tmp6_;
	_tmp7_ = cells;
	{
		GList* cell_collection = NULL;
		GList* cell_it = NULL;
		cell_collection = _tmp7_;
		for (cell_it = cell_collection; cell_it != NULL; cell_it = cell_it->next) {
			GtkCellRenderer* cell = NULL;
			cell = (GtkCellRenderer*) cell_it->data;
			{
				gint start = 0;
				gint cellw = 0;
				GtkCellRenderer* _tmp8_;
				gint _tmp9_ = 0;
				gint _tmp10_ = 0;
				gboolean _tmp11_;
				gboolean _tmp12_ = FALSE;
				_tmp8_ = cell;
				_tmp11_ = gtk_tree_view_column_cell_get_position (column, _tmp8_, &_tmp9_, &_tmp10_);
				start = _tmp9_;
				cellw = _tmp10_;
				if (!_tmp11_) {
					continue;
				}
				if (x >= start) {
					_tmp12_ = x <= (start + cellw);
				} else {
					_tmp12_ = FALSE;
				}
				if (_tmp12_) {
					GtkCellRenderer* _tmp13_;
					GtkCellRenderer* _tmp14_;
					_vala_width = cellw;
					_tmp13_ = cell;
					_tmp14_ = _g_object_ref0 (_tmp13_);
					result = _tmp14_;
					(cells == NULL) ? NULL : (cells = (g_list_free (cells), NULL));
					if (width) {
						*width = _vala_width;
					}
					return result;
				}
			}
		}
	}
	_vala_width = 0;
	result = NULL;
	(cells == NULL) ? NULL : (cells = (g_list_free (cells), NULL));
	if (width) {
		*width = _vala_width;
	}
	return result;
}

static void
_vala_GgitOId_free (GgitOId* self)
{
	g_boxed_free (ggit_oid_get_type (), self);
}

static void
gitg_commit_list_view_lanes_data_func (GitgCommitListView* self,
                                       GtkCellLayout* layout,
                                       GtkCellRenderer* cell,
                                       GtkTreeModel* model,
                                       GtkTreeIter* iter)
{
	GitgCommitModel* m = NULL;
	GitgCommitModel* _tmp0_;
	GitgCommitModel* _tmp1_;
	GitgCellRendererLanes* lanes = NULL;
	GitgCellRendererLanes* _tmp2_;
	GitgCommit* commit = NULL;
	GitgCommitModel* _tmp3_;
	GtkTreeIter _tmp4_;
	GitgCommit* _tmp5_;
	GitgCommit* _tmp6_;
	GtkTreeIter cp = {0};
	GtkTreeIter _tmp7_;
	GitgCommit* next_commit = NULL;
	GitgCommitModel* _tmp8_;
	gboolean _tmp9_;
	GSList* labels = NULL;
	GitgCommitModel* _tmp13_;
	GitgRepository* _tmp14_;
	GitgRepository* _tmp15_;
	GitgCommit* _tmp16_;
	GgitOId* _tmp17_;
	GgitOId* _tmp18_;
	GSList* _tmp19_;
	GSList* _tmp20_;
	GitgCellRendererLanes* _tmp21_;
	GitgCommit* _tmp22_;
	GitgCellRendererLanes* _tmp23_;
	GitgCommit* _tmp24_;
	GitgCellRendererLanes* _tmp25_;
	GSList* _tmp26_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (layout != NULL);
	g_return_if_fail (cell != NULL);
	g_return_if_fail (model != NULL);
	g_return_if_fail (iter != NULL);
	_tmp0_ = _g_object_ref0 (GITG_IS_COMMIT_MODEL (model) ? ((GitgCommitModel*) model) : NULL);
	m = _tmp0_;
	_tmp1_ = m;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (m);
		return;
	}
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (cell, GITG_TYPE_CELL_RENDERER_LANES, GitgCellRendererLanes));
	lanes = _tmp2_;
	_tmp3_ = m;
	_tmp4_ = *iter;
	_tmp5_ = gitg_commit_model_commit_from_iter (_tmp3_, &_tmp4_);
	commit = _tmp5_;
	_tmp6_ = commit;
	if (_tmp6_ == NULL) {
		_g_object_unref0 (commit);
		_g_object_unref0 (lanes);
		_g_object_unref0 (m);
		return;
	}
	_tmp7_ = *iter;
	cp = _tmp7_;
	next_commit = NULL;
	_tmp8_ = m;
	_tmp9_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp8_, &cp);
	if (_tmp9_) {
		GitgCommitModel* _tmp10_;
		GtkTreeIter _tmp11_;
		GitgCommit* _tmp12_;
		_tmp10_ = m;
		_tmp11_ = cp;
		_tmp12_ = gitg_commit_model_commit_from_iter (_tmp10_, &_tmp11_);
		_g_object_unref0 (next_commit);
		next_commit = _tmp12_;
	}
	_tmp13_ = m;
	_tmp14_ = gitg_commit_model_get_repository (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = commit;
	_tmp17_ = ggit_object_get_id ((GgitObject*) _tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = gitg_repository_refs_for_id (_tmp15_, _tmp18_);
	_tmp20_ = _tmp19_;
	__vala_GgitOId_free0 (_tmp18_);
	labels = _tmp20_;
	_tmp21_ = lanes;
	_tmp22_ = commit;
	gitg_cell_renderer_lanes_set_commit (_tmp21_, _tmp22_);
	_tmp23_ = lanes;
	_tmp24_ = next_commit;
	gitg_cell_renderer_lanes_set_next_commit (_tmp23_, _tmp24_);
	_tmp25_ = lanes;
	_tmp26_ = labels;
	gitg_cell_renderer_lanes_set_labels (_tmp25_, _tmp26_);
	_g_object_unref0 (next_commit);
	_g_object_unref0 (commit);
	_g_object_unref0 (lanes);
	_g_object_unref0 (m);
}

static void
_gitg_commit_list_view_lanes_data_func_gtk_cell_layout_data_func (GtkCellLayout* cell_layout,
                                                                  GtkCellRenderer* cell,
                                                                  GtkTreeModel* tree_model,
                                                                  GtkTreeIter* iter,
                                                                  gpointer self)
{
	gitg_commit_list_view_lanes_data_func ((GitgCommitListView*) self, cell_layout, cell, tree_model, iter);
}

static void
gitg_commit_list_view_real_parser_finished (GtkBuildable* base,
                                            GtkBuilder* builder)
{
	GitgCommitListView * self;
	GList* _tmp0_;
	self = (GitgCommitListView*) base;
	g_return_if_fail (builder != NULL);
	gitg_commit_list_view_gtk_buildable_parent_iface->parser_finished ((GtkBuildable*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_tree_view_get_type (), GtkTreeView), builder);
	_tmp0_ = gtk_tree_view_get_columns ((GtkTreeView*) self);
	{
		GList* column_collection = NULL;
		GList* column_it = NULL;
		column_collection = _tmp0_;
		for (column_it = column_collection; column_it != NULL; column_it = column_it->next) {
			GtkTreeViewColumn* column = NULL;
			column = (GtkTreeViewColumn*) column_it->data;
			{
				GtkTreeViewColumn* _tmp1_;
				GList* _tmp2_;
				_tmp1_ = column;
				_tmp2_ = gtk_cell_layout_get_cells ((GtkCellLayout*) _tmp1_);
				{
					GList* cell_collection = NULL;
					GList* cell_it = NULL;
					cell_collection = _tmp2_;
					for (cell_it = cell_collection; cell_it != NULL; cell_it = cell_it->next) {
						GtkCellRenderer* cell = NULL;
						cell = (GtkCellRenderer*) cell_it->data;
						{
							GitgCellRendererLanes* lanes = NULL;
							GtkCellRenderer* _tmp3_;
							GitgCellRendererLanes* _tmp4_;
							GitgCellRendererLanes* _tmp5_;
							GtkTreeViewColumn* _tmp6_;
							GitgCellRendererLanes* _tmp7_;
							_tmp3_ = cell;
							_tmp4_ = _g_object_ref0 (GITG_IS_CELL_RENDERER_LANES (_tmp3_) ? ((GitgCellRendererLanes*) _tmp3_) : NULL);
							lanes = _tmp4_;
							_tmp5_ = lanes;
							if (_tmp5_ == NULL) {
								_g_object_unref0 (lanes);
								continue;
							}
							_tmp6_ = column;
							_tmp7_ = lanes;
							gtk_cell_layout_set_cell_data_func ((GtkCellLayout*) _tmp6_, (GtkCellRenderer*) _tmp7_, _gitg_commit_list_view_lanes_data_func_gtk_cell_layout_data_func, g_object_ref (self), g_object_unref);
							_g_object_unref0 (lanes);
						}
					}
					(cell_collection == NULL) ? NULL : (cell_collection = (g_list_free (cell_collection), NULL));
				}
			}
		}
		(column_collection == NULL) ? NULL : (column_collection = (g_list_free (column_collection), NULL));
	}
}

static void
gitg_commit_list_view_class_init (GitgCommitListViewClass * klass,
                                  gpointer klass_data)
{
	gitg_commit_list_view_parent_class = g_type_class_peek_parent (klass);
}

static void
gitg_commit_list_view_gtk_buildable_interface_init (GtkBuildableIface * iface,
                                                    gpointer iface_data)
{
	gitg_commit_list_view_gtk_buildable_parent_iface = g_type_interface_peek_parent (iface);
	iface->parser_finished = (void (*) (GtkBuildable*, GtkBuilder*)) gitg_commit_list_view_real_parser_finished;
}

static void
gitg_commit_list_view_instance_init (GitgCommitListView * self,
                                     gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
gitg_commit_list_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgCommitListViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_commit_list_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgCommitListView), 0, (GInstanceInitFunc) gitg_commit_list_view_instance_init, NULL };
	static const GInterfaceInfo gtk_buildable_info = { (GInterfaceInitFunc) gitg_commit_list_view_gtk_buildable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gitg_commit_list_view_type_id;
	gitg_commit_list_view_type_id = g_type_register_static (gtk_tree_view_get_type (), "GitgCommitListView", &g_define_type_info, 0);
	g_type_add_interface_static (gitg_commit_list_view_type_id, gtk_buildable_get_type (), &gtk_buildable_info);
	return gitg_commit_list_view_type_id;
}

GType
gitg_commit_list_view_get_type (void)
{
	static gsize gitg_commit_list_view_type_id__once = 0;
	if (g_once_init_enter (&gitg_commit_list_view_type_id__once)) {
		GType gitg_commit_list_view_type_id;
		gitg_commit_list_view_type_id = gitg_commit_list_view_get_type_once ();
		g_once_init_leave (&gitg_commit_list_view_type_id__once, gitg_commit_list_view_type_id);
	}
	return gitg_commit_list_view_type_id__once;
}

