/* tab_label.c generated by valac 0.40.0.227-717ea, the Vala compiler
 * generated from tab_label.vala, do not modify */

/*
 * This file is part of GNOME LaTeX.
 *
 * Copyright © 2017 Sébastien Wilmet
 *
 * GNOME LaTeX 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.
 *
 * GNOME LaTeX 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 GNOME LaTeX.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <glib.h>
#include <glib-object.h>
#include <tepl/tepl.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>


#define TYPE_TAB_LABEL (tab_label_get_type ())
#define TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TAB_LABEL, TabLabel))
#define TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TAB_LABEL, TabLabelClass))
#define IS_TAB_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TAB_LABEL))
#define IS_TAB_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TAB_LABEL))
#define TAB_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TAB_LABEL, TabLabelClass))

typedef struct _TabLabel TabLabel;
typedef struct _TabLabelClass TabLabelClass;
typedef struct _TabLabelPrivate TabLabelPrivate;
enum  {
	TAB_LABEL_0_PROPERTY,
	TAB_LABEL_NUM_PROPERTIES
};
static GParamSpec* tab_label_properties[TAB_LABEL_NUM_PROPERTIES];

#define TYPE_DOCUMENT_TAB (document_tab_get_type ())
#define DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT_TAB, DocumentTab))
#define DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_TAB, DocumentTabClass))
#define IS_DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT_TAB))
#define IS_DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_TAB))
#define DOCUMENT_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_TAB, DocumentTabClass))

typedef struct _DocumentTab DocumentTab;
typedef struct _DocumentTabClass DocumentTabClass;

#define TYPE_DOCUMENT (document_get_type ())
#define DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT, Document))
#define DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT, DocumentClass))
#define IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT))
#define IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT))
#define DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT, DocumentClass))

typedef struct _Document Document;
typedef struct _DocumentClass DocumentClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_PROJECT (project_get_type ())
typedef struct _Project Project;
#define _project_free0(var) ((var == NULL) ? NULL : (var = (project_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _TabLabel {
	TeplTabLabel parent_instance;
	TabLabelPrivate * priv;
};

struct _TabLabelClass {
	TeplTabLabelClass parent_class;
};

struct _Project {
	GFile* directory;
	GFile* main_file;
};


static gpointer tab_label_parent_class = NULL;

GType tab_label_get_type (void) G_GNUC_CONST;
GType document_tab_get_type (void) G_GNUC_CONST;
TabLabel* tab_label_new (DocumentTab* tab);
TabLabel* tab_label_construct (GType object_type,
                               DocumentTab* tab);
GType document_get_type (void) G_GNUC_CONST;
static void _tepl_tab_label_update_tooltip_g_object_notify (GObject* _sender,
                                                     GParamSpec* pspec,
                                                     gpointer self);
static gchar* tab_label_real_get_tooltip_markup (TeplTabLabel* base);
TeplTab* tepl_tab_label_get_tab (TeplTabLabel* self);
GType project_get_type (void) G_GNUC_CONST;
Project* project_dup (const Project* self);
void project_free (Project* self);
void project_copy (const Project* self,
                   Project* dest);
void project_destroy (Project* self);
Project* document_get_project (Document* self);
static gchar* tab_label_get_main_file_relative_path (TabLabel* self);
gchar* utils_get_relative_path (GFile* origin,
                                GFile* target,
                                GFile* common_dir);


static gpointer
_g_object_ref0 (gpointer self)
{
#line 26 "tab_label.vala"
	return self ? g_object_ref (self) : NULL;
#line 122 "tab_label.c"
}


static void
_tepl_tab_label_update_tooltip_g_object_notify (GObject* _sender,
                                                GParamSpec* pspec,
                                                gpointer self)
{
#line 27 "tab_label.vala"
	tepl_tab_label_update_tooltip ((TeplTabLabel*) self);
#line 133 "tab_label.c"
}


TabLabel*
tab_label_construct (GType object_type,
                     DocumentTab* tab)
{
	TabLabel * self = NULL;
	Document* doc = NULL;
	TeplBuffer* _tmp0_;
	Document* _tmp1_;
#line 22 "tab_label.vala"
	g_return_val_if_fail (tab != NULL, NULL);
#line 24 "tab_label.vala"
	self = (TabLabel*) g_object_new (object_type, "tab", tab, NULL);
#line 26 "tab_label.vala"
	_tmp0_ = tepl_tab_get_buffer ((TeplTab*) tab);
#line 26 "tab_label.vala"
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, TYPE_DOCUMENT) ? ((Document*) _tmp0_) : NULL);
#line 26 "tab_label.vala"
	doc = _tmp1_;
#line 27 "tab_label.vala"
	g_signal_connect_object ((GObject*) doc, "notify::project-id", (GCallback) _tepl_tab_label_update_tooltip_g_object_notify, (TeplTabLabel*) self, 0);
#line 22 "tab_label.vala"
	_g_object_unref0 (doc);
#line 22 "tab_label.vala"
	return self;
#line 161 "tab_label.c"
}


TabLabel*
tab_label_new (DocumentTab* tab)
{
#line 22 "tab_label.vala"
	return tab_label_construct (TYPE_TAB_LABEL, tab);
#line 170 "tab_label.c"
}


static gchar*
tab_label_real_get_tooltip_markup (TeplTabLabel* base)
{
	TabLabel * self;
	gchar* result = NULL;
	gchar* base_tooltip = NULL;
	gchar* _tmp0_;
	Document* doc = NULL;
	TeplTab* _tmp1_;
	TeplTab* _tmp2_;
	TeplBuffer* _tmp3_;
	Document* _tmp4_;
	GFile* location = NULL;
	Document* _tmp5_;
	TeplFile* _tmp6_;
	GFile* _tmp7_;
	GFile* _tmp8_;
	GFile* _tmp9_;
	Project* project = NULL;
	Document* _tmp10_;
	Project* _tmp11_;
	Project* _tmp12_;
	const gchar* _tmp13_;
	Project* _tmp15_;
	GFile* _tmp16_;
	GFile* _tmp17_;
	const gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
#line 30 "tab_label.vala"
	self = (TabLabel*) base;
#line 32 "tab_label.vala"
	_tmp0_ = TEPL_TAB_LABEL_CLASS (tab_label_parent_class)->get_tooltip_markup (G_TYPE_CHECK_INSTANCE_CAST (self, tepl_tab_label_get_type (), TeplTabLabel));
#line 32 "tab_label.vala"
	base_tooltip = _tmp0_;
#line 34 "tab_label.vala"
	_tmp1_ = tepl_tab_label_get_tab ((TeplTabLabel*) self);
#line 34 "tab_label.vala"
	_tmp2_ = _tmp1_;
#line 34 "tab_label.vala"
	_tmp3_ = tepl_tab_get_buffer (_tmp2_);
#line 34 "tab_label.vala"
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, TYPE_DOCUMENT) ? ((Document*) _tmp3_) : NULL);
#line 34 "tab_label.vala"
	doc = _tmp4_;
#line 35 "tab_label.vala"
	_tmp5_ = doc;
#line 35 "tab_label.vala"
	_tmp6_ = tepl_buffer_get_file ((TeplBuffer*) _tmp5_);
#line 35 "tab_label.vala"
	_tmp7_ = tepl_file_get_location (_tmp6_);
#line 35 "tab_label.vala"
	_tmp8_ = _g_object_ref0 (_tmp7_);
#line 35 "tab_label.vala"
	location = _tmp8_;
#line 36 "tab_label.vala"
	_tmp9_ = location;
#line 36 "tab_label.vala"
	if (_tmp9_ == NULL) {
#line 37 "tab_label.vala"
		result = base_tooltip;
#line 37 "tab_label.vala"
		_g_object_unref0 (location);
#line 37 "tab_label.vala"
		_g_object_unref0 (doc);
#line 37 "tab_label.vala"
		return result;
#line 245 "tab_label.c"
	}
#line 39 "tab_label.vala"
	_tmp10_ = doc;
#line 39 "tab_label.vala"
	_tmp11_ = document_get_project (_tmp10_);
#line 39 "tab_label.vala"
	project = _tmp11_;
#line 40 "tab_label.vala"
	_tmp12_ = project;
#line 40 "tab_label.vala"
	if (_tmp12_ == NULL) {
#line 41 "tab_label.vala"
		result = base_tooltip;
#line 41 "tab_label.vala"
		_project_free0 (project);
#line 41 "tab_label.vala"
		_g_object_unref0 (location);
#line 41 "tab_label.vala"
		_g_object_unref0 (doc);
#line 41 "tab_label.vala"
		return result;
#line 267 "tab_label.c"
	}
#line 43 "tab_label.vala"
	_tmp13_ = base_tooltip;
#line 43 "tab_label.vala"
	if (_tmp13_ == NULL) {
#line 273 "tab_label.c"
		gchar* _tmp14_;
#line 44 "tab_label.vala"
		_tmp14_ = g_strdup ("");
#line 44 "tab_label.vala"
		_g_free0 (base_tooltip);
#line 44 "tab_label.vala"
		base_tooltip = _tmp14_;
#line 281 "tab_label.c"
	}
#line 46 "tab_label.vala"
	_tmp15_ = project;
#line 46 "tab_label.vala"
	_tmp16_ = (*_tmp15_).main_file;
#line 46 "tab_label.vala"
	_tmp17_ = location;
#line 46 "tab_label.vala"
	if (g_file_equal (_tmp16_, _tmp17_)) {
#line 291 "tab_label.c"
		const gchar* _tmp18_;
		gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
#line 47 "tab_label.vala"
		_tmp18_ = base_tooltip;
#line 47 "tab_label.vala"
		_tmp19_ = g_markup_printf_escaped ("\n<b>%s</b>", _ ("Project main file"));
#line 47 "tab_label.vala"
		_tmp20_ = _tmp19_;
#line 47 "tab_label.vala"
		_tmp21_ = g_strconcat (_tmp18_, _tmp20_, NULL);
#line 47 "tab_label.vala"
		_tmp22_ = _tmp21_;
#line 47 "tab_label.vala"
		_g_free0 (_tmp20_);
#line 47 "tab_label.vala"
		result = _tmp22_;
#line 47 "tab_label.vala"
		_project_free0 (project);
#line 47 "tab_label.vala"
		_g_object_unref0 (location);
#line 47 "tab_label.vala"
		_g_object_unref0 (doc);
#line 47 "tab_label.vala"
		_g_free0 (base_tooltip);
#line 47 "tab_label.vala"
		return result;
#line 321 "tab_label.c"
	}
#line 50 "tab_label.vala"
	_tmp23_ = base_tooltip;
#line 50 "tab_label.vala"
	_tmp24_ = tab_label_get_main_file_relative_path (self);
#line 50 "tab_label.vala"
	_tmp25_ = _tmp24_;
#line 50 "tab_label.vala"
	_tmp26_ = g_markup_printf_escaped ("\n<b>%s</b> %s", _ ("Project main file:"), _tmp25_);
#line 50 "tab_label.vala"
	_tmp27_ = _tmp26_;
#line 50 "tab_label.vala"
	_tmp28_ = g_strconcat (_tmp23_, _tmp27_, NULL);
#line 50 "tab_label.vala"
	_tmp29_ = _tmp28_;
#line 50 "tab_label.vala"
	_g_free0 (_tmp27_);
#line 50 "tab_label.vala"
	_g_free0 (_tmp25_);
#line 50 "tab_label.vala"
	result = _tmp29_;
#line 50 "tab_label.vala"
	_project_free0 (project);
#line 50 "tab_label.vala"
	_g_object_unref0 (location);
#line 50 "tab_label.vala"
	_g_object_unref0 (doc);
#line 50 "tab_label.vala"
	_g_free0 (base_tooltip);
#line 50 "tab_label.vala"
	return result;
#line 353 "tab_label.c"
}


static gchar*
tab_label_get_main_file_relative_path (TabLabel* self)
{
	gchar* result = NULL;
	Document* doc = NULL;
	TeplTab* _tmp0_;
	TeplTab* _tmp1_;
	TeplBuffer* _tmp2_;
	Document* _tmp3_;
	Project* project = NULL;
	Document* _tmp4_;
	Project* _tmp5_;
	Project* _tmp6_;
	GFile* origin = NULL;
	Document* _tmp8_;
	TeplFile* _tmp9_;
	GFile* _tmp10_;
	GFile* _tmp11_;
	GFile* target = NULL;
	Project* _tmp12_;
	GFile* _tmp13_;
	GFile* _tmp14_;
	GFile* common_dir = NULL;
	Project* _tmp15_;
	GFile* _tmp16_;
	GFile* _tmp17_;
	GFile* _tmp18_;
	GFile* _tmp19_;
	GFile* _tmp20_;
	gchar* _tmp21_;
#line 54 "tab_label.vala"
	g_return_val_if_fail (self != NULL, NULL);
#line 56 "tab_label.vala"
	_tmp0_ = tepl_tab_label_get_tab ((TeplTabLabel*) self);
#line 56 "tab_label.vala"
	_tmp1_ = _tmp0_;
#line 56 "tab_label.vala"
	_tmp2_ = tepl_tab_get_buffer (_tmp1_);
#line 56 "tab_label.vala"
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, TYPE_DOCUMENT) ? ((Document*) _tmp2_) : NULL);
#line 56 "tab_label.vala"
	doc = _tmp3_;
#line 57 "tab_label.vala"
	_tmp4_ = doc;
#line 57 "tab_label.vala"
	_tmp5_ = document_get_project (_tmp4_);
#line 57 "tab_label.vala"
	project = _tmp5_;
#line 58 "tab_label.vala"
	_tmp6_ = project;
#line 58 "tab_label.vala"
	if (_tmp6_ == NULL) {
#line 409 "tab_label.c"
		gchar* _tmp7_;
#line 59 "tab_label.vala"
		_tmp7_ = g_strdup ("");
#line 59 "tab_label.vala"
		result = _tmp7_;
#line 59 "tab_label.vala"
		_project_free0 (project);
#line 59 "tab_label.vala"
		_g_object_unref0 (doc);
#line 59 "tab_label.vala"
		return result;
#line 421 "tab_label.c"
	}
#line 61 "tab_label.vala"
	_tmp8_ = doc;
#line 61 "tab_label.vala"
	_tmp9_ = tepl_buffer_get_file ((TeplBuffer*) _tmp8_);
#line 61 "tab_label.vala"
	_tmp10_ = tepl_file_get_location (_tmp9_);
#line 61 "tab_label.vala"
	_tmp11_ = _g_object_ref0 (_tmp10_);
#line 61 "tab_label.vala"
	origin = _tmp11_;
#line 62 "tab_label.vala"
	_tmp12_ = project;
#line 62 "tab_label.vala"
	_tmp13_ = (*_tmp12_).main_file;
#line 62 "tab_label.vala"
	_tmp14_ = _g_object_ref0 (_tmp13_);
#line 62 "tab_label.vala"
	target = _tmp14_;
#line 63 "tab_label.vala"
	_tmp15_ = project;
#line 63 "tab_label.vala"
	_tmp16_ = (*_tmp15_).directory;
#line 63 "tab_label.vala"
	_tmp17_ = _g_object_ref0 (_tmp16_);
#line 63 "tab_label.vala"
	common_dir = _tmp17_;
#line 65 "tab_label.vala"
	_tmp18_ = origin;
#line 65 "tab_label.vala"
	_tmp19_ = target;
#line 65 "tab_label.vala"
	_tmp20_ = common_dir;
#line 65 "tab_label.vala"
	_tmp21_ = utils_get_relative_path (_tmp18_, _tmp19_, _tmp20_);
#line 65 "tab_label.vala"
	result = _tmp21_;
#line 65 "tab_label.vala"
	_g_object_unref0 (common_dir);
#line 65 "tab_label.vala"
	_g_object_unref0 (target);
#line 65 "tab_label.vala"
	_g_object_unref0 (origin);
#line 65 "tab_label.vala"
	_project_free0 (project);
#line 65 "tab_label.vala"
	_g_object_unref0 (doc);
#line 65 "tab_label.vala"
	return result;
#line 471 "tab_label.c"
}


static void
tab_label_class_init (TabLabelClass * klass)
{
#line 20 "tab_label.vala"
	tab_label_parent_class = g_type_class_peek_parent (klass);
#line 20 "tab_label.vala"
	((TeplTabLabelClass *) klass)->get_tooltip_markup = (gchar* (*) (TeplTabLabel *)) tab_label_real_get_tooltip_markup;
#line 482 "tab_label.c"
}


static void
tab_label_instance_init (TabLabel * self)
{
}


GType
tab_label_get_type (void)
{
	static volatile gsize tab_label_type_id__volatile = 0;
	if (g_once_init_enter (&tab_label_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TabLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tab_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TabLabel), 0, (GInstanceInitFunc) tab_label_instance_init, NULL };
		GType tab_label_type_id;
		tab_label_type_id = g_type_register_static (tepl_tab_label_get_type (), "TabLabel", &g_define_type_info, 0);
		g_once_init_leave (&tab_label_type_id__volatile, tab_label_type_id);
	}
	return tab_label_type_id__volatile;
}



