/* plugin.c generated by valac 0.22.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_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	_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_ = 0;
	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_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	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_ = NULL;
	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_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->message_window_notebook;
	result = G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GTK_TYPE_NOTEBOOK) ? ((GtkNotebook*) _tmp0_) : NULL;
	return result;
}


static GtkNotebook* geany_vala_plugin_main_widgets_get_sidebar_notebook (GeanyMainWidgets* self) {
	GtkNotebook* result;
	GtkWidget* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->sidebar_notebook;
	result = G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GTK_TYPE_NOTEBOOK) ? ((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_ = NULL;
	GeanyData* _tmp1_ = NULL;
	GeanyApp* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	GtkAlignment* _tmp13_ = NULL;
	const gchar* _tmp14_ = NULL;
	MultiTermNotebook* _tmp15_ = NULL;
	GtkAlignment* _tmp16_ = NULL;
	MultiTermNotebook* _tmp17_ = NULL;
	GtkAlignment* _tmp18_ = NULL;
	GtkAlignment* _tmp19_ = NULL;
	GtkWidget* _tmp20_ = NULL;
	GtkLabel* _tmp21_ = NULL;
	MultiTermNotebook* _tmp22_ = NULL;
	GtkLabel* _tmp23_ = NULL;
	GtkLabel* _tmp24_ = NULL;
	MultiTermNotebook* _tmp25_ = NULL;
	GeanyData* _tmp26_ = NULL;
	GeanyMainWidgets* _tmp27_ = NULL;
	GtkNotebook* _tmp28_ = NULL;
	GtkNotebook* _tmp29_ = NULL;
	GtkNotebook* _tmp30_ = NULL;
	MultiTermNotebook* _tmp31_ = NULL;
	GeanyData* _tmp32_ = NULL;
	GeanyMainWidgets* _tmp33_ = NULL;
	GtkNotebook* _tmp34_ = NULL;
	GtkNotebook* _tmp35_ = NULL;
	GtkNotebook* _tmp36_ = NULL;
	MultiTermNotebook* _tmp37_ = NULL;
	MultiTermConfig* _tmp38_ = NULL;
	gchar* _tmp39_ = NULL;
	gchar* _tmp40_ = NULL;
	gchar* _tmp41_ = NULL;
	gboolean _tmp42_ = FALSE;
	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_ = NULL;
		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_ = NULL;
			_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_ = NULL;
		const gchar* _tmp12_ = NULL;
		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);
	g_object_ref_sink (_tmp13_);
	_g_object_unref0 (align);
	align = _tmp13_;
	_tmp14_ = config_file;
	_tmp15_ = multi_term_notebook_new (_tmp14_);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (notebook);
	notebook = _tmp15_;
	_tmp16_ = align;
	_tmp17_ = notebook;
	gtk_container_add ((GtkContainer*) _tmp16_, (GtkWidget*) (G_TYPE_CHECK_INSTANCE_TYPE (_tmp17_, GTK_TYPE_NOTEBOOK) ? ((GtkNotebook*) _tmp17_) : NULL));
	_tmp18_ = align;
	gtk_widget_show_all ((GtkWidget*) _tmp18_);
	_tmp19_ = align;
	_tmp20_ = _g_object_ref0 ((GtkWidget*) _tmp19_);
	toplevel_widgets = g_list_append (toplevel_widgets, _tmp20_);
	_tmp21_ = (GtkLabel*) gtk_label_new ("MultiTerm");
	g_object_ref_sink (_tmp21_);
	_g_object_unref0 (label);
	label = _tmp21_;
	_tmp22_ = notebook;
	_tmp23_ = label;
	_tmp24_ = _g_object_ref0 (_tmp23_);
	g_object_set_data_full ((GObject*) _tmp22_, "label", _tmp24_, g_object_unref);
	_tmp25_ = notebook;
	_tmp26_ = data;
	_tmp27_ = _tmp26_->main_widgets;
	_tmp28_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = _g_object_ref0 (_tmp29_);
	g_object_set_data_full ((GObject*) _tmp25_, "msgwin_notebook", _tmp30_, g_object_unref);
	_tmp31_ = notebook;
	_tmp32_ = data;
	_tmp33_ = _tmp32_->main_widgets;
	_tmp34_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp33_);
	_tmp35_ = _tmp34_;
	_tmp36_ = _g_object_ref0 (_tmp35_);
	g_object_set_data_full ((GObject*) _tmp31_, "sidebar_notebook", _tmp36_, g_object_unref);
	_tmp37_ = notebook;
	_tmp38_ = _tmp37_->cfg;
	_tmp39_ = multi_term_config_get_location (_tmp38_);
	_tmp40_ = _tmp39_;
	_tmp41_ = _tmp40_;
	_tmp42_ = g_strcmp0 (_tmp41_, "msgwin") == 0;
	_g_free0 (_tmp41_);
	if (_tmp42_) {
		GeanyData* _tmp43_ = NULL;
		GeanyMainWidgets* _tmp44_ = NULL;
		GtkNotebook* _tmp45_ = NULL;
		GtkNotebook* _tmp46_ = NULL;
		GtkAlignment* _tmp47_ = NULL;
		GtkLabel* _tmp48_ = NULL;
		GeanyData* _tmp49_ = NULL;
		GeanyMainWidgets* _tmp50_ = NULL;
		GtkNotebook* _tmp51_ = NULL;
		GtkNotebook* _tmp52_ = NULL;
		GeanyData* _tmp53_ = NULL;
		GeanyMainWidgets* _tmp54_ = NULL;
		GtkNotebook* _tmp55_ = NULL;
		GtkNotebook* _tmp56_ = NULL;
		GtkAlignment* _tmp57_ = NULL;
		gint _tmp58_ = 0;
		_tmp43_ = data;
		_tmp44_ = _tmp43_->main_widgets;
		_tmp45_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp44_);
		_tmp46_ = _tmp45_;
		_tmp47_ = align;
		_tmp48_ = label;
		gtk_notebook_append_page (_tmp46_, (GtkWidget*) _tmp47_, (GtkWidget*) _tmp48_);
		_tmp49_ = data;
		_tmp50_ = _tmp49_->main_widgets;
		_tmp51_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp50_);
		_tmp52_ = _tmp51_;
		_tmp53_ = data;
		_tmp54_ = _tmp53_->main_widgets;
		_tmp55_ = geany_vala_plugin_main_widgets_get_message_window_notebook (_tmp54_);
		_tmp56_ = _tmp55_;
		_tmp57_ = align;
		_tmp58_ = gtk_notebook_page_num (_tmp56_, (GtkWidget*) _tmp57_);
		gtk_notebook_set_current_page (_tmp52_, _tmp58_);
	} else {
		GeanyData* _tmp59_ = NULL;
		GeanyMainWidgets* _tmp60_ = NULL;
		GtkNotebook* _tmp61_ = NULL;
		GtkNotebook* _tmp62_ = NULL;
		GtkAlignment* _tmp63_ = NULL;
		GtkLabel* _tmp64_ = NULL;
		GeanyData* _tmp65_ = NULL;
		GeanyMainWidgets* _tmp66_ = NULL;
		GtkNotebook* _tmp67_ = NULL;
		GtkNotebook* _tmp68_ = NULL;
		GeanyData* _tmp69_ = NULL;
		GeanyMainWidgets* _tmp70_ = NULL;
		GtkNotebook* _tmp71_ = NULL;
		GtkNotebook* _tmp72_ = NULL;
		GtkAlignment* _tmp73_ = NULL;
		gint _tmp74_ = 0;
		_tmp59_ = data;
		_tmp60_ = _tmp59_->main_widgets;
		_tmp61_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp60_);
		_tmp62_ = _tmp61_;
		_tmp63_ = align;
		_tmp64_ = label;
		gtk_notebook_append_page (_tmp62_, (GtkWidget*) _tmp63_, (GtkWidget*) _tmp64_);
		_tmp65_ = data;
		_tmp66_ = _tmp65_->main_widgets;
		_tmp67_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp66_);
		_tmp68_ = _tmp67_;
		_tmp69_ = data;
		_tmp70_ = _tmp69_->main_widgets;
		_tmp71_ = geany_vala_plugin_main_widgets_get_sidebar_notebook (_tmp70_);
		_tmp72_ = _tmp71_;
		_tmp73_ = align;
		_tmp74_ = gtk_notebook_page_num (_tmp72_, (GtkWidget*) _tmp73_);
		gtk_notebook_set_current_page (_tmp68_, _tmp74_);
	}
	_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_ = NULL;
	_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_ = NULL;
			GtkWidget* wid = NULL;
			_tmp1_ = _g_object_ref0 ((GtkWidget*) wid_it->data);
			wid = _tmp1_;
			{
				GtkWidget* _tmp2_ = NULL;
				_tmp2_ = wid;
				gtk_object_destroy ((GtkObject*) _tmp2_);
				_g_object_unref0 (wid);
			}
		}
	}
}



