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

/*
 * Copyright (C) 2011-2012 Mario Guerriero <mefrio.g@gmail.com> This program
 * is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see <http://www.gnu.org/licenses/>
 */

#include "spell.h"
#include "codecore.h"
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtkspell/gtkspell.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <granite.h>
#include <glib/gi18n-lib.h>
#include <libpeas.h>
#include <gtksourceview/gtksource.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  {
	SCRATCH_PLUGINS_SPELL_0_PROPERTY,
	SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY,
	SCRATCH_PLUGINS_SPELL_NUM_PROPERTIES
};
static GParamSpec* scratch_plugins_spell_properties[SCRATCH_PLUGINS_SPELL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _ScratchPluginsSpellPrivate {
	ScratchServicesInterface* plugins;
	GSettings* settings;
	ScratchMainWindow* window;
	gchar* lang_dict;
	GtkSpellChecker* spell;
	GObject* _object;
};

struct _Block1Data {
	int _ref_count_;
	ScratchPluginsSpell* self;
	ScratchWidgetsSourceView* view;
};

static gint ScratchPluginsSpell_private_offset;
static gpointer scratch_plugins_spell_parent_class = NULL;
static ScratchServicesActivatablePluginIface * scratch_plugins_spell_scratch_services_activatable_plugin_parent_iface = NULL;
static GType scratch_plugins_spell_type_id = 0;

static void scratch_plugins_spell_real_update_state (ScratchServicesActivatablePlugin* base);
static void scratch_plugins_spell_real_activate (ScratchServicesActivatablePlugin* base);
static void _scratch_plugins_spell_settings_changed_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self);
static void __lambda4_ (ScratchPluginsSpell* self,
                 ScratchServicesDocument* d);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
static void ___lambda5_ (ScratchPluginsSpell* self,
                  PeasPluginInfo* info);
static void ____lambda5__scratch_services_plugins_manager_extension_removed (ScratchServicesPluginsManager* _sender,
                                                                      PeasPluginInfo* info,
                                                                      gpointer self);
static void ___lambda6_ (Block1Data* _data1_);
static void scratch_plugins_spell_language_changed_spell (ScratchPluginsSpell* self,
                                                   ScratchWidgetsSourceView* view);
static void ____lambda6__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static void ___lambda7_ (ScratchPluginsSpell* self,
                  const gchar* lang_dict);
static void ____lambda7__gtk_spell_checker_language_changed (GtkSpellChecker* _sender,
                                                      const gchar* new_lang,
                                                      gpointer self);
static void ___lambda4__scratch_services_interface_hook_document (ScratchServicesInterface* _sender,
                                                           ScratchServicesDocument* doc,
                                                           gpointer self);
static void __lambda8_ (ScratchPluginsSpell* self,
                 ScratchMainWindow* w);
static void _scratch_plugins_spell_save_settings_gtk_widget_destroy (GtkWidget* _sender,
                                                              gpointer self);
static void ___lambda8__scratch_services_interface_hook_window (ScratchServicesInterface* _sender,
                                                         ScratchMainWindow* window,
                                                         gpointer self);
static void scratch_plugins_spell_real_deactivate (ScratchServicesActivatablePlugin* base);
static void scratch_plugins_spell_finalize (GObject * obj);
static void _vala_scratch_plugins_spell_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_scratch_plugins_spell_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);

static inline gpointer
scratch_plugins_spell_get_instance_private (ScratchPluginsSpell* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchPluginsSpell_private_offset);
}

static void
scratch_plugins_spell_real_update_state (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsSpell * self;
	self = (ScratchPluginsSpell*) base;
}

static void
_scratch_plugins_spell_settings_changed_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self)
{
	scratch_plugins_spell_settings_changed ((ScratchPluginsSpell*) self);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		ScratchPluginsSpell* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->view);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

static void
___lambda5_ (ScratchPluginsSpell* self,
             PeasPluginInfo* info)
{
	const gchar* _tmp0_;
	g_return_if_fail (info != NULL);
	_tmp0_ = peas_plugin_info_get_module_name (info);
	if (g_strcmp0 (_tmp0_, "spell") == 0) {
		GtkSpellChecker* _tmp1_;
		_tmp1_ = self->priv->spell;
		gtk_spell_checker_detach (_tmp1_);
	}
}

static void
____lambda5__scratch_services_plugins_manager_extension_removed (ScratchServicesPluginsManager* _sender,
                                                                 PeasPluginInfo* info,
                                                                 gpointer self)
{
	___lambda5_ ((ScratchPluginsSpell*) self, info);
}

static void
___lambda6_ (Block1Data* _data1_)
{
	ScratchPluginsSpell* self;
	ScratchWidgetsSourceView* _tmp0_;
	self = _data1_->self;
	_tmp0_ = _data1_->view;
	scratch_plugins_spell_language_changed_spell (self, _tmp0_);
}

static void
____lambda6__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	___lambda6_ (self);
}

static void
___lambda7_ (ScratchPluginsSpell* self,
             const gchar* lang_dict)
{
	gchar* _tmp0_;
	g_return_if_fail (lang_dict != NULL);
	_tmp0_ = g_strdup (lang_dict);
	_g_free0 (self->priv->lang_dict);
	self->priv->lang_dict = _tmp0_;
}

static void
____lambda7__gtk_spell_checker_language_changed (GtkSpellChecker* _sender,
                                                 const gchar* new_lang,
                                                 gpointer self)
{
	___lambda7_ ((ScratchPluginsSpell*) self, new_lang);
}

static void
__lambda4_ (ScratchPluginsSpell* self,
            ScratchServicesDocument* d)
{
	Block1Data* _data1_;
	ScratchWidgetsSourceView* _tmp0_;
	ScratchWidgetsSourceView* _tmp1_;
	ScratchWidgetsSourceView* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	GtkSpellChecker* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (d != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = scratch_services_document_get_source_view (d);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data1_->view = _tmp2_;
	_tmp3_ = _data1_->view;
	_tmp4_ = gtk_spell_checker_get_from_text_view ((GtkTextView*) _tmp3_);
	if (_tmp4_ == NULL) {
		GtkSpellChecker* _tmp5_;
		ScratchServicesInterface* _tmp31_;
		ScratchServicesPluginsManager* _tmp32_;
		ScratchServicesPluginsManager* _tmp33_;
		GtkSourceBuffer* source_buffer = NULL;
		ScratchWidgetsSourceView* _tmp34_;
		ScratchWidgetsSourceView* _tmp35_;
		GtkTextBuffer* _tmp36_;
		GtkTextBuffer* _tmp37_;
		GtkSourceBuffer* _tmp38_;
		GtkSourceLanguage* lang = NULL;
		GtkSourceBuffer* _tmp39_;
		GtkSourceLanguage* _tmp40_;
		GtkSourceLanguage* _tmp41_;
		GtkSourceLanguage* _tmp42_;
		gboolean _tmp43_ = FALSE;
		GtkSourceLanguage* _tmp44_;
		ScratchWidgetsSourceView* _tmp49_;
		GtkSpellChecker* _tmp50_;
		_tmp5_ = gtk_spell_checker_new ();
		g_object_ref_sink (_tmp5_);
		_g_object_unref0 (self->priv->spell);
		self->priv->spell = _tmp5_;
		{
			gboolean exist_language = FALSE;
			GList* language_list = NULL;
			GList* _tmp6_;
			GList* _tmp7_;
			GList* _tmp13_;
			GtkSpellChecker* _tmp27_;
			ScratchWidgetsSourceView* _tmp28_;
			exist_language = FALSE;
			_tmp6_ = gtk_spell_checker_get_language_list ();
			language_list = _tmp6_;
			_tmp7_ = language_list;
			{
				GList* element_collection = NULL;
				GList* element_it = NULL;
				element_collection = _tmp7_;
				for (element_it = element_collection; element_it != NULL; element_it = element_it->next) {
					gchar* _tmp8_;
					gchar* element = NULL;
					_tmp8_ = g_strdup ((const gchar*) element_it->data);
					element = _tmp8_;
					{
						const gchar* _tmp9_;
						const gchar* _tmp10_;
						_tmp9_ = self->priv->lang_dict;
						_tmp10_ = element;
						if (g_strcmp0 (_tmp9_, _tmp10_) == 0) {
							GtkSpellChecker* _tmp11_;
							const gchar* _tmp12_;
							exist_language = TRUE;
							_tmp11_ = self->priv->spell;
							_tmp12_ = self->priv->lang_dict;
							gtk_spell_checker_set_language (_tmp11_, _tmp12_, &_inner_error0_);
							if (G_UNLIKELY (_inner_error0_ != NULL)) {
								_g_free0 (element);
								(language_list == NULL) ? NULL : (language_list = (_g_list_free__g_free0_ (language_list), NULL));
								goto __catch0_g_error;
							}
							_g_free0 (element);
							break;
						}
						_g_free0 (element);
					}
				}
			}
			_tmp13_ = language_list;
			if (g_list_length (_tmp13_) == ((guint) 0)) {
				GraniteMessageDialog* dialog = NULL;
				GThemedIcon* _tmp14_;
				GThemedIcon* _tmp15_;
				GraniteMessageDialog* _tmp16_;
				GraniteMessageDialog* _tmp17_;
				GraniteMessageDialog* _tmp18_;
				GraniteMessageDialog* _tmp19_;
				GtkSpellChecker* _tmp20_;
				_tmp14_ = (GThemedIcon*) g_themed_icon_new ("dialog-warning");
				_tmp15_ = _tmp14_;
				_tmp16_ = granite_message_dialog_new (_ ("No Suitable Dictionaries Were Found"), _ ("Please install at least one [aspell] dictionary."), (GIcon*) _tmp15_, GTK_BUTTONS_CLOSE);
				g_object_ref_sink (_tmp16_);
				_tmp17_ = _tmp16_;
				_g_object_unref0 (_tmp15_);
				dialog = _tmp17_;
				_tmp18_ = dialog;
				gtk_dialog_run ((GtkDialog*) _tmp18_);
				_tmp19_ = dialog;
				gtk_widget_destroy ((GtkWidget*) _tmp19_);
				_tmp20_ = self->priv->spell;
				gtk_spell_checker_set_language (_tmp20_, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (dialog);
					(language_list == NULL) ? NULL : (language_list = (_g_list_free__g_free0_ (language_list), NULL));
					goto __catch0_g_error;
				}
				_g_object_unref0 (dialog);
			} else {
				if (!exist_language) {
					GList* _tmp21_;
					GList* _tmp22_;
					gconstpointer _tmp23_;
					gchar* _tmp24_;
					GtkSpellChecker* _tmp25_;
					const gchar* _tmp26_;
					_tmp21_ = language_list;
					_tmp22_ = g_list_first (_tmp21_);
					_tmp23_ = _tmp22_->data;
					_tmp24_ = g_strdup ((const gchar*) _tmp23_);
					_g_free0 (self->priv->lang_dict);
					self->priv->lang_dict = _tmp24_;
					_tmp25_ = self->priv->spell;
					_tmp26_ = self->priv->lang_dict;
					gtk_spell_checker_set_language (_tmp25_, _tmp26_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						(language_list == NULL) ? NULL : (language_list = (_g_list_free__g_free0_ (language_list), NULL));
						goto __catch0_g_error;
					}
				}
			}
			_tmp27_ = self->priv->spell;
			_tmp28_ = _data1_->view;
			gtk_spell_checker_attach (_tmp27_, (GtkTextView*) _tmp28_);
			(language_list == NULL) ? NULL : (language_list = (_g_list_free__g_free0_ (language_list), NULL));
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp29_;
			const gchar* _tmp30_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp29_ = e;
			_tmp30_ = _tmp29_->message;
			g_warning ("spell.vala:91: %s", _tmp30_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			block1_data_unref (_data1_);
			_data1_ = 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;
		}
		_tmp31_ = self->priv->plugins;
		_tmp32_ = scratch_services_interface_get_manager (_tmp31_);
		_tmp33_ = _tmp32_;
		g_signal_connect_object (_tmp33_, "extension-removed", (GCallback) ____lambda5__scratch_services_plugins_manager_extension_removed, self, 0);
		_tmp34_ = scratch_services_document_get_source_view (d);
		_tmp35_ = _tmp34_;
		_tmp36_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp35_);
		_tmp37_ = _tmp36_;
		_tmp38_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp37_, gtk_source_buffer_get_type (), GtkSourceBuffer));
		source_buffer = _tmp38_;
		_tmp39_ = source_buffer;
		_tmp40_ = gtk_source_buffer_get_language (_tmp39_);
		_tmp41_ = _tmp40_;
		_tmp42_ = _g_object_ref0 (_tmp41_);
		lang = _tmp42_;
		_tmp44_ = lang;
		if (_tmp44_ != NULL) {
			GtkSourceLanguage* _tmp45_;
			const gchar* _tmp46_;
			const gchar* _tmp47_;
			_tmp45_ = lang;
			_tmp46_ = gtk_source_language_get_id (_tmp45_);
			_tmp47_ = _tmp46_;
			_tmp43_ = g_strcmp0 (_tmp47_, "markdown") != 0;
		} else {
			_tmp43_ = FALSE;
		}
		if (_tmp43_) {
			GtkSpellChecker* _tmp48_;
			_tmp48_ = self->priv->spell;
			gtk_spell_checker_detach (_tmp48_);
		}
		_tmp49_ = _data1_->view;
		g_signal_connect_data ((GObject*) _tmp49_, "notify::language", (GCallback) ____lambda6__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
		_tmp50_ = self->priv->spell;
		g_signal_connect_object (_tmp50_, "language-changed", (GCallback) ____lambda7__gtk_spell_checker_language_changed, self, 0);
		_g_object_unref0 (lang);
		_g_object_unref0 (source_buffer);
	}
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
___lambda4__scratch_services_interface_hook_document (ScratchServicesInterface* _sender,
                                                      ScratchServicesDocument* doc,
                                                      gpointer self)
{
	__lambda4_ ((ScratchPluginsSpell*) self, doc);
}

static void
_scratch_plugins_spell_save_settings_gtk_widget_destroy (GtkWidget* _sender,
                                                         gpointer self)
{
	scratch_plugins_spell_save_settings ((ScratchPluginsSpell*) self);
}

static void
__lambda8_ (ScratchPluginsSpell* self,
            ScratchMainWindow* w)
{
	ScratchMainWindow* _tmp0_;
	ScratchMainWindow* _tmp1_;
	ScratchMainWindow* _tmp2_;
	g_return_if_fail (w != NULL);
	_tmp0_ = self->priv->window;
	if (_tmp0_ != NULL) {
		return;
	}
	_tmp1_ = _g_object_ref0 (w);
	_g_object_unref0 (self->priv->window);
	self->priv->window = _tmp1_;
	_tmp2_ = self->priv->window;
	g_signal_connect_object ((GtkWidget*) _tmp2_, "destroy", (GCallback) _scratch_plugins_spell_save_settings_gtk_widget_destroy, self, 0);
}

static void
___lambda8__scratch_services_interface_hook_window (ScratchServicesInterface* _sender,
                                                    ScratchMainWindow* window,
                                                    gpointer self)
{
	__lambda8_ ((ScratchPluginsSpell*) self, window);
}

static void
scratch_plugins_spell_real_activate (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsSpell * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	gchar* _tmp2_;
	GSettings* _tmp3_;
	GObject* _tmp4_;
	GObject* _tmp5_;
	ScratchServicesInterface* _tmp6_;
	ScratchServicesInterface* _tmp7_;
	self = (ScratchPluginsSpell*) base;
	_tmp0_ = g_settings_new (CONSTANTS_PROJECT_NAME ".plugins.spell");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = self->priv->settings;
	_tmp2_ = g_settings_get_string (_tmp1_, "language");
	_g_free0 (self->priv->lang_dict);
	self->priv->lang_dict = _tmp2_;
	_tmp3_ = self->priv->settings;
	g_signal_connect_object (_tmp3_, "changed", (GCallback) _scratch_plugins_spell_settings_changed_g_settings_changed, self, 0);
	_tmp4_ = scratch_services_activatable_plugin_get_object ((ScratchServicesActivatablePlugin*) self);
	_tmp5_ = _tmp4_;
	_g_object_unref0 (self->priv->plugins);
	self->priv->plugins = G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, SCRATCH_SERVICES_TYPE_INTERFACE, ScratchServicesInterface);
	_tmp6_ = self->priv->plugins;
	g_signal_connect_object (_tmp6_, "hook-document", (GCallback) ___lambda4__scratch_services_interface_hook_document, self, 0);
	_tmp7_ = self->priv->plugins;
	g_signal_connect_object (_tmp7_, "hook-window", (GCallback) ___lambda8__scratch_services_interface_hook_window, self, 0);
}

static void
scratch_plugins_spell_language_changed_spell (ScratchPluginsSpell* self,
                                              ScratchWidgetsSourceView* view)
{
	GtkSourceLanguage* _tmp0_;
	GtkSourceLanguage* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (view != NULL);
	_tmp0_ = scratch_widgets_source_view_get_language (view);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		GtkSpellChecker* _tmp2_;
		_tmp2_ = self->priv->spell;
		gtk_spell_checker_detach (_tmp2_);
	}
}

void
scratch_plugins_spell_settings_changed (ScratchPluginsSpell* self)
{
	GtkSpellChecker* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->spell;
	if (_tmp0_ != NULL) {
		{
			GtkSpellChecker* _tmp1_;
			GSettings* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			GSettings* _tmp5_;
			gchar* _tmp6_;
			_tmp1_ = self->priv->spell;
			_tmp2_ = self->priv->settings;
			_tmp3_ = g_settings_get_string (_tmp2_, "language");
			_tmp4_ = _tmp3_;
			gtk_spell_checker_set_language (_tmp1_, _tmp4_, &_inner_error0_);
			_g_free0 (_tmp4_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp5_ = self->priv->settings;
			_tmp6_ = g_settings_get_string (_tmp5_, "language");
			_g_free0 (self->priv->lang_dict);
			self->priv->lang_dict = _tmp6_;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp7_;
			const gchar* _tmp8_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp7_ = e;
			_tmp8_ = _tmp7_->message;
			g_warning ("spell.vala:142: %s", _tmp8_);
			_g_error_free0 (e);
		}
		__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;
		}
	}
}

void
scratch_plugins_spell_save_settings (ScratchPluginsSpell* self)
{
	GSettings* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	_tmp1_ = self->priv->lang_dict;
	g_settings_set_string (_tmp0_, "language", _tmp1_);
}

static void
scratch_plugins_spell_real_deactivate (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsSpell * self;
	ScratchMainWindow* _tmp0_;
	guint _tmp1_;
	self = (ScratchPluginsSpell*) base;
	scratch_plugins_spell_save_settings (self);
	_tmp0_ = self->priv->window;
	g_signal_parse_name ("destroy", gtk_widget_get_type (), &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched ((GtkWidget*) _tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _scratch_plugins_spell_save_settings_gtk_widget_destroy, self);
}

ScratchPluginsSpell*
scratch_plugins_spell_construct (GType object_type)
{
	ScratchPluginsSpell * self = NULL;
	self = (ScratchPluginsSpell*) g_object_new (object_type, NULL);
	return self;
}

ScratchPluginsSpell*
scratch_plugins_spell_new (void)
{
	return scratch_plugins_spell_construct (SCRATCH_PLUGINS_TYPE_SPELL);
}

static GObject*
scratch_plugins_spell_real_get_object (ScratchServicesActivatablePlugin* base)
{
	GObject* result;
	ScratchPluginsSpell* self;
	GObject* _tmp0_;
	GObject* _tmp1_;
	self = (ScratchPluginsSpell*) base;
	_tmp0_ = self->priv->_object;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
scratch_plugins_spell_real_set_object (ScratchServicesActivatablePlugin* base,
                                       GObject* value)
{
	ScratchPluginsSpell* self;
	GObject* old_value;
	self = (ScratchPluginsSpell*) base;
	old_value = scratch_plugins_spell_real_get_object (base);
	if (old_value != value) {
		GObject* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_object);
		self->priv->_object = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_plugins_spell_properties[SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY]);
	}
	_g_object_unref0 (old_value);
}

static void
scratch_plugins_spell_class_init (ScratchPluginsSpellClass * klass,
                                  gpointer klass_data)
{
	scratch_plugins_spell_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchPluginsSpell_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_plugins_spell_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_plugins_spell_set_property;
	G_OBJECT_CLASS (klass)->finalize = scratch_plugins_spell_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY, scratch_plugins_spell_properties[SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY] = g_param_spec_object ("object", "object", "object", G_TYPE_OBJECT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
scratch_plugins_spell_scratch_services_activatable_plugin_interface_init (ScratchServicesActivatablePluginIface * iface,
                                                                          gpointer iface_data)
{
	scratch_plugins_spell_scratch_services_activatable_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->update_state = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_spell_real_update_state;
	iface->activate = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_spell_real_activate;
	iface->deactivate = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_spell_real_deactivate;
	iface->get_object = scratch_plugins_spell_real_get_object;
	iface->set_object = scratch_plugins_spell_real_set_object;
}

static void
scratch_plugins_spell_instance_init (ScratchPluginsSpell * self,
                                     gpointer klass)
{
	self->priv = scratch_plugins_spell_get_instance_private (self);
	self->priv->window = NULL;
	self->priv->spell = NULL;
}

static void
scratch_plugins_spell_finalize (GObject * obj)
{
	ScratchPluginsSpell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_PLUGINS_TYPE_SPELL, ScratchPluginsSpell);
	_g_object_unref0 (self->priv->plugins);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->window);
	_g_free0 (self->priv->lang_dict);
	_g_object_unref0 (self->priv->spell);
	_g_object_unref0 (self->priv->_object);
	G_OBJECT_CLASS (scratch_plugins_spell_parent_class)->finalize (obj);
}

GType
scratch_plugins_spell_get_type (void)
{
	return scratch_plugins_spell_type_id;
}

GType
scratch_plugins_spell_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchPluginsSpellClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_plugins_spell_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchPluginsSpell), 0, (GInstanceInitFunc) scratch_plugins_spell_instance_init, NULL };
	static const GInterfaceInfo scratch_services_activatable_plugin_info = { (GInterfaceInitFunc) scratch_plugins_spell_scratch_services_activatable_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	scratch_plugins_spell_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "ScratchPluginsSpell", &g_define_type_info, G_TYPE_FLAG_NONE);
	g_type_module_add_interface (module, scratch_plugins_spell_type_id, SCRATCH_SERVICES_TYPE_ACTIVATABLE_PLUGIN, &scratch_services_activatable_plugin_info);
	ScratchPluginsSpell_private_offset = sizeof (ScratchPluginsSpellPrivate);
	return scratch_plugins_spell_type_id;
}

static void
_vala_scratch_plugins_spell_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	ScratchPluginsSpell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_PLUGINS_TYPE_SPELL, ScratchPluginsSpell);
	switch (property_id) {
		case SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY:
		g_value_take_object (value, scratch_services_activatable_plugin_get_object ((ScratchServicesActivatablePlugin*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_plugins_spell_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	ScratchPluginsSpell * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_PLUGINS_TYPE_SPELL, ScratchPluginsSpell);
	switch (property_id) {
		case SCRATCH_PLUGINS_SPELL_OBJECT_PROPERTY:
		scratch_services_activatable_plugin_set_object ((ScratchServicesActivatablePlugin*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

void
peas_register_types (GTypeModule* module)
{
	PeasObjectModule* objmodule = NULL;
	PeasObjectModule* _tmp0_;
	g_return_if_fail (module != NULL);
	scratch_plugins_spell_register_type (module);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (module, peas_object_module_get_type ()) ? ((PeasObjectModule*) module) : NULL);
	objmodule = _tmp0_;
	peas_object_module_register_extension_type (objmodule, SCRATCH_SERVICES_TYPE_ACTIVATABLE_PLUGIN, SCRATCH_PLUGINS_TYPE_SPELL);
	_g_object_unref0 (objmodule);
}

