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

/*
 * plugin.vala - This file is part of the Geany MultiTerm plugin
 *
 * Copyright (c) 2012 Matthew Brush <matt@geany.org>.
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include "multiterm.h"
#include <gtk/gtk.h>
#include <geanyplugin.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#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)))


GeanyPlugin* geany_plugin = NULL;
GeanyData* geany_data = NULL;
GeanyFunctions* geany_functions = NULL;
extern GList* toplevel_widgets;
GList* toplevel_widgets = NULL;



static gint geany_vala_plugin_VERSION_CHECK (gint abi_version, gint api_required) {
	gint result = 0;
	gint _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	_tmp0_ = abi_version;
	_tmp1_ = GEANY_ABI_VERSION;
	if (_tmp0_ != _tmp1_) {
		result = -1;
		return result;
	}
	_tmp2_ = api_required;
	result = _tmp2_;
	return result;
}


gint plugin_version_check (gint abi_version) {
	gint result = 0;
	gint _tmp0_;
	gint _tmp1_ = 0;
	_tmp0_ = abi_version;
	_tmp1_ = geany_vala_plugin_VERSION_CHECK (_tmp0_, 185);
	result = _tmp1_;
	return result;
}


static void geany_vala_plugin_SET_INFO (PluginInfo* self, const gchar* name, const gchar* description, const gchar* version, const gchar* author) {
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = name;
	self->name = _tmp0_;
	_tmp1_ = description;
	self->description = _tmp1_;
	_tmp2_ = version;
	self->version = _tmp2_;
	_tmp3_ = author;
	self->author = _tmp3_;
}


void plugin_set_info (PluginInfo* info) {
	PluginInfo* _tmp0_;
	g_return_if_fail (info != NULL);
	_tmp0_ = info;
	geany_vala_plugin_SET_INFO (_tmp0_, "MultiTerm", "Multi-tabbed virtual terminal emulator.", "0.1", "Matthew Brush <matt@geany.org>");
}


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


static GtkNotebook* geany_vala_plugin_main_widgets_get_message_window_notebook (GeanyMainWidgets* self) {
	GtkNotebook* result;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->message_window_notebook;
	result = GTK_IS_NOTEBOOK (_tmp0_) ? ((GtkNotebook*) _tmp0_) : NULL;
	return result;
}


static GtkNotebook* geany_vala_plugin_main_widgets_get_sidebar_notebook (GeanyMainWidgets* self) {
	GtkNotebook* result;
	GtkWidget* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->sidebar_notebook;
	result = GTK_IS_NOTEBOOK (_tmp0_) ? ((GtkNotebook*) _tmp0_) : NULL;
	return result;
}


void plugin_init (GeanyData* data) {
	gchar* config_file = NULL;
	gchar* config_dir = NULL;
	GtkLabel* label = NULL;
	GtkAlignment* align = NULL;
	MultiTermNotebook* notebook = NULL;
	GeanyPlugin* _tmp0_;
	GeanyData* _tmp1_;
	GeanyApp* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_ = NULL;
	const gchar* _tmp5_;
	gchar* _tmp6_ = NULL;
	const gchar* _tmp7_;
	GtkAlignment* _tmp13_;
	GtkAlignment* _tmp14_;
	const gchar* _tmp15_;
	MultiTermNotebook* _tmp16_;
	MultiTermNotebook* _tmp17_;
	GtkAlignment* _tmp18_;
	MultiTermNotebook* _tmp19_;
	GtkAlignment* _tmp20_;
	GtkAlignment* _tmp21_;
	GtkWidget* _tmp22_;
	GtkLabel* _tmp23_;
	GtkLabel* _tmp24_;
	MultiTermNotebook* _tmp25_;
	GtkLabel* _tmp26_;
	GtkLabel* _tmp27_;
	MultiTermNotebook* _tmp28_;
	GeanyData* _tmp29_;
	GeanyMainWidgets* _tmp30_;
	GtkNotebook* _tmp31_;
	GtkNotebook* _tmp32_;
	GtkNotebook* _tmp33_;
	MultiTermNotebook* _tmp34_;
	GeanyData* _tmp35_;
	GeanyMainWidgets* _tmp36_;
	GtkNotebook* _tmp37_;
	GtkNotebook* _tmp38_;
	GtkNotebook* _tmp39_;
	MultiTermNotebook* _tmp40_;
	MultiTermConfig* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	gboolean _tmp45_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (data != NULL);
	_tmp0_ = geany_plugin;
	plugin_module_make_resident (_tmp0_);
	_tmp1_ = geany_data;
	_tmp2_ = _tmp1_->app;
	_tmp3_ = _tmp2_->configdir;
	_tmp4_ = g_build_filename (_tmp3_, "plugins", "multiterm", NULL);
	_g_free0 (config_dir);
	config_dir = _tmp4_;
	_tmp5_ = config_dir;
	_tmp6_ = g_build_filename (_tmp5_, "multiterm.conf", NULL);
	_g_free0 (config_file);
	config_file = _tmp6_;
	_tmp7_ = config_dir;
	g_mkdir_with_parents (_tmp7_, 0755);
	{
		const gchar* _tmp8_;
		gboolean _tmp9_ = FALSE;
		_tmp8_ = config_file;
		_tmp9_ = g_file_test (_tmp8_, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR);
		if (!_tmp9_) {
			const gchar* _tmp10_;
			_tmp10_ = config_file;
			g_file_set_contents (_tmp10_, MULTI_TERM_default_config, (gssize) (-1), &_inner_error_);
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == G_FILE_ERROR) {
					goto __catch6_g_file_error;
				}
				_g_object_unref0 (notebook);
				_g_object_unref0 (align);
				_g_object_unref0 (label);
				_g_free0 (config_dir);
				_g_free0 (config_file);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
	goto __finally6;
	__catch6_g_file_error:
	{
		GError* err = NULL;
		GError* _tmp11_;
		const gchar* _tmp12_;
		err = _inner_error_;
		_inner_error_ = NULL;
		_tmp11_ = err;
		_tmp12_ = _tmp11_->message;
		g_warning ("plugin.vala:72: Unable to write default config file: %s", _tmp12_);
		_g_error_free0 (err);
	}
	__finally6:
	if (_inner_error_ != NULL) {
		_g_object_unref0 (notebook);
		_g_object_unref0 (align);
		_g_object_unref0 (label);
		_g_free0 (config_dir);
		_g_free0 (config_file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp13_ = (GtkAlignment*) gtk_alignment_new (0.5f, 0.5f, 1.0f, 1.0f);
	_tmp14_ = g_object_ref_sink (_tmp13_);
	_g_object_unref0 (align);
	align = _tmp14_;
	_tmp15_ = config_file;
	_tmp16_ = multi_term_notebook_new (_tmp15_);
	_tmp17_ = g_object_ref_sink (_tmp16_);
	_g_object_unref0 (notebook);
	notebook = _tmp17_;
	_tmp18_ = align;
	_tmp19_ = notebook;
	gtk_container_add ((GtkContainer*) _tmp18_, (GtkWidget*) (GTK_IS_NOTEBOOK (_tmp19_) ? ((GtkNotebook*) _tmp19_) : NULL));
	_tmp20_ = align;
	gtk_widget_show_all ((GtkWidget*) _tmp20_);
	_tmp21_ = align;
	_tmp22_ = _g_object_ref0 ((GtkWidget*) _tmp21_);
	toplevel_widgets = g_list_append (toplevel_widgets, _tmp22_);
	_tmp23_ = (GtkLabel*) gtk_label_new ("MultiTerm");
	_tmp24_ = g_object_ref_sink (_tmp23_);
	_g_object_unref0 (label);
	label = _tmp24_;
	_tmp25_ = notebook;
	_tmp26_ = label;
	_tmp27_ = _g_object_ref0 (_tmp26_);
	g_object_set_data_full ((GObject*) _tmp25_, "label", _tmp27_, g_object_unref);
	_tmp28_ = notebook;
	_tmp29_ = data;
	_tmp30_ = _tmp29_->main_widgets;
	_tmp31_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp30_);
	_tmp32_ = _tmp31_;
	_tmp33_ = _g_object_ref0 (_tmp32_);
	g_object_set_data_full ((GObject*) _tmp28_, "msgwin_notebook", _tmp33_, g_object_unref);
	_tmp34_ = notebook;
	_tmp35_ = data;
	_tmp36_ = _tmp35_->main_widgets;
	_tmp37_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp36_);
	_tmp38_ = _tmp37_;
	_tmp39_ = _g_object_ref0 (_tmp38_);
	g_object_set_data_full ((GObject*) _tmp34_, "sidebar_notebook", _tmp39_, g_object_unref);
	_tmp40_ = notebook;
	_tmp41_ = _tmp40_->cfg;
	_tmp42_ = multi_term_config_get_location (_tmp41_);
	_tmp43_ = _tmp42_;
	_tmp44_ = _tmp43_;
	_tmp45_ = g_strcmp0 (_tmp44_, "msgwin") == 0;
	_g_free0 (_tmp44_);
	if (_tmp45_) {
		GeanyData* _tmp46_;
		GeanyMainWidgets* _tmp47_;
		GtkNotebook* _tmp48_;
		GtkNotebook* _tmp49_;
		GtkAlignment* _tmp50_;
		GtkLabel* _tmp51_;
		GeanyData* _tmp52_;
		GeanyMainWidgets* _tmp53_;
		GtkNotebook* _tmp54_;
		GtkNotebook* _tmp55_;
		GeanyData* _tmp56_;
		GeanyMainWidgets* _tmp57_;
		GtkNotebook* _tmp58_;
		GtkNotebook* _tmp59_;
		GtkAlignment* _tmp60_;
		gint _tmp61_ = 0;
		_tmp46_ = data;
		_tmp47_ = _tmp46_->main_widgets;
		_tmp48_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp47_);
		_tmp49_ = _tmp48_;
		_tmp50_ = align;
		_tmp51_ = label;
		gtk_notebook_append_page (_tmp49_, (GtkWidget*) _tmp50_, (GtkWidget*) _tmp51_);
		_tmp52_ = data;
		_tmp53_ = _tmp52_->main_widgets;
		_tmp54_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp53_);
		_tmp55_ = _tmp54_;
		_tmp56_ = data;
		_tmp57_ = _tmp56_->main_widgets;
		_tmp58_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp57_);
		_tmp59_ = _tmp58_;
		_tmp60_ = align;
		_tmp61_ = gtk_notebook_page_num (_tmp59_, (GtkWidget*) _tmp60_);
		gtk_notebook_set_current_page (_tmp55_, _tmp61_);
	} else {
		GeanyData* _tmp62_;
		GeanyMainWidgets* _tmp63_;
		GtkNotebook* _tmp64_;
		GtkNotebook* _tmp65_;
		GtkAlignment* _tmp66_;
		GtkLabel* _tmp67_;
		GeanyData* _tmp68_;
		GeanyMainWidgets* _tmp69_;
		GtkNotebook* _tmp70_;
		GtkNotebook* _tmp71_;
		GeanyData* _tmp72_;
		GeanyMainWidgets* _tmp73_;
		GtkNotebook* _tmp74_;
		GtkNotebook* _tmp75_;
		GtkAlignment* _tmp76_;
		gint _tmp77_ = 0;
		_tmp62_ = data;
		_tmp63_ = _tmp62_->main_widgets;
		_tmp64_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp63_);
		_tmp65_ = _tmp64_;
		_tmp66_ = align;
		_tmp67_ = label;
		gtk_notebook_append_page (_tmp65_, (GtkWidget*) _tmp66_, (GtkWidget*) _tmp67_);
		_tmp68_ = data;
		_tmp69_ = _tmp68_->main_widgets;
		_tmp70_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp69_);
		_tmp71_ = _tmp70_;
		_tmp72_ = data;
		_tmp73_ = _tmp72_->main_widgets;
		_tmp74_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp73_);
		_tmp75_ = _tmp74_;
		_tmp76_ = align;
		_tmp77_ = gtk_notebook_page_num (_tmp75_, (GtkWidget*) _tmp76_);
		gtk_notebook_set_current_page (_tmp71_, _tmp77_);
	}
	_g_object_unref0 (notebook);
	_g_object_unref0 (align);
	_g_object_unref0 (label);
	_g_free0 (config_dir);
	_g_free0 (config_file);
}


void plugin_cleanup (void) {
	GList* _tmp0_;
	_tmp0_ = toplevel_widgets;
	{
		GList* wid_collection = NULL;
		GList* wid_it = NULL;
		wid_collection = _tmp0_;
		for (wid_it = wid_collection; wid_it != NULL; wid_it = wid_it->next) {
			GtkWidget* _tmp1_;
			GtkWidget* wid = NULL;
			_tmp1_ = _g_object_ref0 ((GtkWidget*) wid_it->data);
			wid = _tmp1_;
			{
				GtkWidget* _tmp2_;
				_tmp2_ = wid;
				gtk_object_destroy ((GtkObject*) _tmp2_);
				_g_object_unref0 (wid);
			}
		}
	}
}



