/* calculator-plugin.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from calculator-plugin.vala, do not modify */

/*
* Copyright (c) 2010 Michal Hruby <michal.mhr@gmail.com>
*               2022 elementary LLC. (https://elementary.io)
*
* 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
*
* Authored by: Michal Hruby <michal.mhr@gmail.com>
*/

#include "slingshot.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <granite.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.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  {
	SYNAPSE_CALCULATOR_PLUGIN_0_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_NUM_PROPERTIES
};
static GParamSpec* synapse_calculator_plugin_properties[SYNAPSE_CALCULATOR_PLUGIN_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT (synapse_calculator_plugin_result_get_type ())
#define SYNAPSE_CALCULATOR_PLUGIN_RESULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResult))
#define SYNAPSE_CALCULATOR_PLUGIN_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResultClass))
#define SYNAPSE_CALCULATOR_PLUGIN_IS_RESULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT))
#define SYNAPSE_CALCULATOR_PLUGIN_IS_RESULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT))
#define SYNAPSE_CALCULATOR_PLUGIN_RESULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResultClass))

typedef struct _SynapseCalculatorPluginResult SynapseCalculatorPluginResult;
typedef struct _SynapseCalculatorPluginResultClass SynapseCalculatorPluginResultClass;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _SynapseCalculatorPluginSearchData SynapseCalculatorPluginSearchData;
typedef struct _SynapseCalculatorPluginResultPrivate SynapseCalculatorPluginResultPrivate;
enum  {
	SYNAPSE_CALCULATOR_PLUGIN_RESULT_0_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY,
	SYNAPSE_CALCULATOR_PLUGIN_RESULT_NUM_PROPERTIES
};
static GParamSpec* synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_NUM_PROPERTIES];

struct _SynapseCalculatorPluginPrivate {
	gboolean _enabled;
};

struct _SynapseCalculatorPluginSearchData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	SynapseCalculatorPlugin* self;
	SynapseQuery query;
	SynapseResultSet* result;
	SynapseResultSet* results;
	gchar* d;
	SynapseCalculatorPluginBackend* _tmp0_;
	SynapseCalculatorPluginBackend* _tmp1_;
	SynapseQuery _tmp2_;
	const gchar* _tmp3_;
	SynapseQuery _tmp4_;
	GCancellable* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	SynapseCalculatorPluginResult* _result_;
	SynapseQuery _tmp8_;
	const gchar* _tmp9_;
	SynapseCalculatorPluginResult* _tmp10_;
	SynapseCalculatorPluginResult* _tmp11_;
	SynapseQuery _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	SynapseResultSet* _tmp20_;
	SynapseResultSet* _tmp21_;
	SynapseCalculatorPluginResult* _tmp22_;
	GError* e;
	GError* _tmp23_;
	SynapseQuery _tmp24_;
	const gchar* _tmp25_;
	GError* _tmp26_;
	const gchar* _tmp27_;
	GError* _inner_error0_;
};

struct _SynapseCalculatorPluginResult {
	SynapseMatch parent_instance;
	SynapseCalculatorPluginResultPrivate * priv;
};

struct _SynapseCalculatorPluginResultClass {
	SynapseMatchClass parent_class;
};

struct _SynapseCalculatorPluginResultPrivate {
	gint _default_relevancy;
	gchar* _text;
	SynapseTextOrigin _text_origin;
};

static gint SynapseCalculatorPlugin_private_offset;
static gpointer synapse_calculator_plugin_parent_class = NULL;
static gint SynapseCalculatorPluginResult_private_offset;
static gpointer synapse_calculator_plugin_result_parent_class = NULL;
static SynapseTextMatchIface * synapse_calculator_plugin_result_synapse_text_match_parent_iface = NULL;
static SynapseActivatableIface * synapse_calculator_plugin_synapse_activatable_parent_iface = NULL;
static SynapseItemProviderIface * synapse_calculator_plugin_synapse_item_provider_parent_iface = NULL;

static void synapse_calculator_plugin_real_activate (SynapseActivatable* base);
static void synapse_calculator_plugin_real_deactivate (SynapseActivatable* base);
static void synapse_calculator_plugin_register_plugin (void);
static void _synapse_calculator_plugin_register_plugin_synapse_plugin_register_func (void);
static gboolean synapse_calculator_plugin_real_handles_query (SynapseItemProvider* base,
                                                       SynapseQuery* query);
static void synapse_calculator_plugin_real_search_data_free (gpointer _data);
static void synapse_calculator_plugin_real_search (SynapseItemProvider* base,
                                            SynapseQuery* query,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
static gboolean synapse_calculator_plugin_real_search_co (SynapseCalculatorPluginSearchData* _data_);
static void synapse_calculator_plugin_search_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static GType synapse_calculator_plugin_result_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static SynapseCalculatorPluginResult* synapse_calculator_plugin_result_new (const gchar* _result_,
                                                                     const gchar* match_string);
static SynapseCalculatorPluginResult* synapse_calculator_plugin_result_construct (GType object_type,
                                                                           const gchar* _result_,
                                                                           const gchar* match_string);
static void synapse_calculator_plugin_result_real_execute (SynapseMatch* base,
                                                    SynapseMatch* match);
static gint synapse_calculator_plugin_result_get_default_relevancy (SynapseCalculatorPluginResult* self);
static void synapse_calculator_plugin_result_set_default_relevancy (SynapseCalculatorPluginResult* self,
                                                             gint value);
static void synapse_calculator_plugin_result_finalize (GObject * obj);
static GType synapse_calculator_plugin_result_get_type_once (void);
static void _vala_synapse_calculator_plugin_result_get_property (GObject * object,
                                                          guint property_id,
                                                          GValue * value,
                                                          GParamSpec * pspec);
static void _vala_synapse_calculator_plugin_result_set_property (GObject * object,
                                                          guint property_id,
                                                          const GValue * value,
                                                          GParamSpec * pspec);
static void synapse_calculator_plugin_finalize (GObject * obj);
static GType synapse_calculator_plugin_get_type_once (void);
static void _vala_synapse_calculator_plugin_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_synapse_calculator_plugin_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
synapse_calculator_plugin_get_instance_private (SynapseCalculatorPlugin* self)
{
	return G_STRUCT_MEMBER_P (self, SynapseCalculatorPlugin_private_offset);
}

static void
synapse_calculator_plugin_real_activate (SynapseActivatable* base)
{
	SynapseCalculatorPlugin * self;
	self = (SynapseCalculatorPlugin*) base;
}

static void
synapse_calculator_plugin_real_deactivate (SynapseActivatable* base)
{
	SynapseCalculatorPlugin * self;
	self = (SynapseCalculatorPlugin*) base;
}

static void
_synapse_calculator_plugin_register_plugin_synapse_plugin_register_func (void)
{
	synapse_calculator_plugin_register_plugin ();
}

static void
synapse_calculator_plugin_register_plugin (void)
{
	SynapseDataSinkPluginRegistry* _tmp0_;
	SynapseDataSinkPluginRegistry* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = synapse_data_sink_plugin_registry_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_find_program_in_path ("bc");
	_tmp3_ = _tmp2_;
	synapse_data_sink_plugin_registry_register_plugin (_tmp1_, SYNAPSE_TYPE_CALCULATOR_PLUGIN, "accessories-calculator", _synapse_calculator_plugin_register_plugin_synapse_plugin_register_func, _tmp3_ != NULL);
	_g_free0 (_tmp3_);
	_g_object_unref0 (_tmp1_);
}

static gboolean
synapse_calculator_plugin_real_handles_query (SynapseItemProvider* base,
                                              SynapseQuery* query)
{
	SynapseCalculatorPlugin * self;
	SynapseQuery _tmp0_;
	gboolean result;
	self = (SynapseCalculatorPlugin*) base;
	g_return_val_if_fail (query != NULL, FALSE);
	_tmp0_ = *query;
	result = (_tmp0_.query_type & SYNAPSE_QUERY_FLAGS_ACTIONS) == SYNAPSE_QUERY_FLAGS_ACTIONS;
	return result;
}

static void
synapse_calculator_plugin_real_search_data_free (gpointer _data)
{
	SynapseCalculatorPluginSearchData* _data_;
	_data_ = _data;
	synapse_query_destroy (&_data_->query);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (SynapseCalculatorPluginSearchData, _data_);
}

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

static void
synapse_calculator_plugin_real_search (SynapseItemProvider* base,
                                       SynapseQuery* query,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_)
{
	SynapseCalculatorPlugin * self;
	SynapseCalculatorPluginSearchData* _data_;
	SynapseCalculatorPlugin* _tmp0_;
	SynapseQuery _tmp1_;
	SynapseQuery _tmp2_;
	SynapseQuery _tmp3_ = {0};
	g_return_if_fail (query != NULL);
	self = (SynapseCalculatorPlugin*) base;
	_data_ = g_slice_new0 (SynapseCalculatorPluginSearchData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, synapse_calculator_plugin_real_search_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = *query;
	_tmp2_ = _tmp1_;
	synapse_query_copy (&_tmp2_, &_tmp3_);
	synapse_query_destroy (&_data_->query);
	_data_->query = _tmp3_;
	synapse_calculator_plugin_real_search_co (_data_);
}

static SynapseResultSet*
synapse_calculator_plugin_search_finish (SynapseItemProvider* base,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	SynapseResultSet* result;
	SynapseCalculatorPluginSearchData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
synapse_calculator_plugin_search_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	SynapseCalculatorPluginSearchData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	synapse_calculator_plugin_real_search_co (_data_);
}

static gboolean
synapse_calculator_plugin_real_search_co (SynapseCalculatorPluginSearchData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->results = NULL;
	{
		_data_->_tmp0_ = synapse_calculator_plugin_backend_get_instance ();
		_data_->_tmp1_ = _data_->_tmp0_;
		_data_->_tmp2_ = _data_->query;
		_data_->_tmp3_ = _data_->_tmp2_.query_string;
		_data_->_tmp4_ = _data_->query;
		_data_->_tmp5_ = _data_->_tmp4_.cancellable;
		_data_->_state_ = 1;
		synapse_calculator_plugin_backend_get_solution (_data_->_tmp1_, _data_->_tmp3_, _data_->_tmp5_, synapse_calculator_plugin_search_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = synapse_calculator_plugin_backend_get_solution_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp7_ = _data_->_tmp6_;
		_g_object_unref0 (_data_->_tmp1_);
		_data_->d = _data_->_tmp7_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp8_ = _data_->query;
		_data_->_tmp9_ = _data_->_tmp8_.query_string;
		_data_->_tmp10_ = synapse_calculator_plugin_result_new (_data_->d, _data_->_tmp9_);
		_data_->_result_ = _data_->_tmp10_;
		_data_->_tmp11_ = _data_->_result_;
		_data_->_tmp12_ = _data_->query;
		_data_->_tmp13_ = _data_->_tmp12_.query_string;
		_data_->_tmp14_ = g_strdup_printf ("%s = %s", _data_->_tmp13_, _data_->d);
		_data_->_tmp15_ = _data_->_tmp14_;
		_data_->_tmp16_ = g_strdup_printf (GRANITE_TOOLTIP_SECONDARY_TEXT_MARKUP, _ ("Click to copy result to clipboard"));
		_data_->_tmp17_ = _data_->_tmp16_;
		_data_->_tmp18_ = g_strdup_printf ("%s\n%s", _data_->_tmp15_, _data_->_tmp17_);
		_data_->_tmp19_ = _data_->_tmp18_;
		synapse_match_set_description ((SynapseMatch*) _data_->_tmp11_, _data_->_tmp19_);
		_g_free0 (_data_->_tmp19_);
		_g_free0 (_data_->_tmp17_);
		_g_free0 (_data_->_tmp15_);
		_data_->_tmp20_ = synapse_result_set_new ();
		_g_object_unref0 (_data_->results);
		_data_->results = _data_->_tmp20_;
		_data_->_tmp21_ = _data_->results;
		_data_->_tmp22_ = _data_->_result_;
		synapse_result_set_add (_data_->_tmp21_, (SynapseMatch*) _data_->_tmp22_, (gint) SYNAPSE_MATCH_SCORE_AVERAGE);
		_g_object_unref0 (_data_->_result_);
		_g_free0 (_data_->d);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp23_ = _data_->e;
		if (!g_error_matches (_data_->_tmp23_, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) {
			_data_->_tmp24_ = _data_->query;
			_data_->_tmp25_ = _data_->_tmp24_.query_string;
			_data_->_tmp26_ = _data_->e;
			_data_->_tmp27_ = _data_->_tmp26_->message;
			g_warning ("calculator-plugin.vala:88: Error processing %s with bc: %s", _data_->_tmp25_, _data_->_tmp27_);
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == SYNAPSE_SEARCH_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->results);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->results);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	synapse_query_check_cancellable (&_data_->query, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		if (_data_->_inner_error0_->domain == SYNAPSE_SEARCH_ERROR) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			_g_object_unref0 (_data_->results);
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->results);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->result = _data_->results;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

SynapseCalculatorPlugin*
synapse_calculator_plugin_construct (GType object_type)
{
	SynapseCalculatorPlugin * self = NULL;
	self = (SynapseCalculatorPlugin*) g_object_new (object_type, NULL);
	return self;
}

SynapseCalculatorPlugin*
synapse_calculator_plugin_new (void)
{
	return synapse_calculator_plugin_construct (SYNAPSE_TYPE_CALCULATOR_PLUGIN);
}

static gboolean
synapse_calculator_plugin_real_get_enabled (SynapseActivatable* base)
{
	gboolean result;
	SynapseCalculatorPlugin* self;
	self = (SynapseCalculatorPlugin*) base;
	result = self->priv->_enabled;
	return result;
}

static void
synapse_calculator_plugin_real_set_enabled (SynapseActivatable* base,
                                            gboolean value)
{
	SynapseCalculatorPlugin* self;
	gboolean old_value;
	self = (SynapseCalculatorPlugin*) base;
	old_value = synapse_calculator_plugin_real_get_enabled (base);
	if (old_value != value) {
		self->priv->_enabled = value;
		g_object_notify_by_pspec ((GObject *) self, synapse_calculator_plugin_properties[SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY]);
	}
}

static inline gpointer
synapse_calculator_plugin_result_get_instance_private (SynapseCalculatorPluginResult* self)
{
	return G_STRUCT_MEMBER_P (self, SynapseCalculatorPluginResult_private_offset);
}

static SynapseCalculatorPluginResult*
synapse_calculator_plugin_result_construct (GType object_type,
                                            const gchar* _result_,
                                            const gchar* match_string)
{
	SynapseCalculatorPluginResult * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (_result_ != NULL, NULL);
	g_return_val_if_fail (match_string != NULL, NULL);
	_tmp0_ = g_strdup_printf ("%s", _result_);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf ("%s", _result_);
	_tmp3_ = _tmp2_;
	self = (SynapseCalculatorPluginResult*) g_object_new (object_type, "match-type", SYNAPSE_MATCH_TYPE_CALCULATION, "text", _tmp1_, "title", _tmp3_, "icon-name", "accessories-calculator", "text-origin", SYNAPSE_TEXT_ORIGIN_UNKNOWN, NULL);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	return self;
}

static SynapseCalculatorPluginResult*
synapse_calculator_plugin_result_new (const gchar* _result_,
                                      const gchar* match_string)
{
	return synapse_calculator_plugin_result_construct (SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, _result_, match_string);
}

static void
synapse_calculator_plugin_result_real_execute (SynapseMatch* base,
                                               SynapseMatch* match)
{
	SynapseCalculatorPluginResult * self;
	GdkDisplay* display = NULL;
	GdkDisplay* _tmp0_;
	GtkClipboard* clipboard = NULL;
	GtkClipboard* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	self = (SynapseCalculatorPluginResult*) base;
	_tmp0_ = gdk_display_get_default ();
	display = _tmp0_;
	_tmp1_ = gtk_clipboard_get_default (display);
	clipboard = _tmp1_;
	_tmp2_ = synapse_text_match_get_text ((SynapseTextMatch*) self);
	_tmp3_ = _tmp2_;
	gtk_clipboard_set_text (clipboard, _tmp3_, -1);
}

static gint
synapse_calculator_plugin_result_get_default_relevancy (SynapseCalculatorPluginResult* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_default_relevancy;
	return result;
}

static void
synapse_calculator_plugin_result_set_default_relevancy (SynapseCalculatorPluginResult* self,
                                                        gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = synapse_calculator_plugin_result_get_default_relevancy (self);
	if (old_value != value) {
		self->priv->_default_relevancy = value;
		g_object_notify_by_pspec ((GObject *) self, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY]);
	}
}

static const gchar*
synapse_calculator_plugin_result_real_get_text (SynapseTextMatch* base)
{
	const gchar* result;
	SynapseCalculatorPluginResult* self;
	const gchar* _tmp0_;
	self = (SynapseCalculatorPluginResult*) base;
	_tmp0_ = self->priv->_text;
	result = _tmp0_;
	return result;
}

static void
synapse_calculator_plugin_result_real_set_text (SynapseTextMatch* base,
                                                const gchar* value)
{
	SynapseCalculatorPluginResult* self;
	gchar* old_value;
	self = (SynapseCalculatorPluginResult*) base;
	old_value = synapse_calculator_plugin_result_real_get_text (base);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_text);
		self->priv->_text = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY]);
	}
}

static SynapseTextOrigin
synapse_calculator_plugin_result_real_get_text_origin (SynapseTextMatch* base)
{
	SynapseTextOrigin result;
	SynapseCalculatorPluginResult* self;
	self = (SynapseCalculatorPluginResult*) base;
	result = self->priv->_text_origin;
	return result;
}

static void
synapse_calculator_plugin_result_real_set_text_origin (SynapseTextMatch* base,
                                                       SynapseTextOrigin value)
{
	SynapseCalculatorPluginResult* self;
	SynapseTextOrigin old_value;
	self = (SynapseCalculatorPluginResult*) base;
	old_value = synapse_calculator_plugin_result_real_get_text_origin (base);
	if (old_value != value) {
		self->priv->_text_origin = value;
		g_object_notify_by_pspec ((GObject *) self, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY]);
	}
}

static void
synapse_calculator_plugin_result_class_init (SynapseCalculatorPluginResultClass * klass,
                                             gpointer klass_data)
{
	synapse_calculator_plugin_result_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SynapseCalculatorPluginResult_private_offset);
	((SynapseMatchClass *) klass)->execute = (void (*) (SynapseMatch*, SynapseMatch*)) synapse_calculator_plugin_result_real_execute;
	G_OBJECT_CLASS (klass)->get_property = _vala_synapse_calculator_plugin_result_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_synapse_calculator_plugin_result_set_property;
	G_OBJECT_CLASS (klass)->finalize = synapse_calculator_plugin_result_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY] = g_param_spec_int ("default-relevancy", "default-relevancy", "default-relevancy", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY] = g_param_spec_string ("text", "text", "text", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY, synapse_calculator_plugin_result_properties[SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY] = g_param_spec_enum ("text-origin", "text-origin", "text-origin", SYNAPSE_TYPE_TEXT_ORIGIN, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
synapse_calculator_plugin_result_synapse_text_match_interface_init (SynapseTextMatchIface * iface,
                                                                    gpointer iface_data)
{
	synapse_calculator_plugin_result_synapse_text_match_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_text = synapse_calculator_plugin_result_real_get_text;
	iface->set_text = synapse_calculator_plugin_result_real_set_text;
	iface->get_text_origin = synapse_calculator_plugin_result_real_get_text_origin;
	iface->set_text_origin = synapse_calculator_plugin_result_real_set_text_origin;
}

static void
synapse_calculator_plugin_result_instance_init (SynapseCalculatorPluginResult * self,
                                                gpointer klass)
{
	gchar* _tmp0_;
	self->priv = synapse_calculator_plugin_result_get_instance_private (self);
	self->priv->_default_relevancy = 0;
	_tmp0_ = g_strdup ("");
	self->priv->_text = _tmp0_;
}

static void
synapse_calculator_plugin_result_finalize (GObject * obj)
{
	SynapseCalculatorPluginResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResult);
	_g_free0 (self->priv->_text);
	G_OBJECT_CLASS (synapse_calculator_plugin_result_parent_class)->finalize (obj);
}

static GType
synapse_calculator_plugin_result_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SynapseCalculatorPluginResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_calculator_plugin_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SynapseCalculatorPluginResult), 0, (GInstanceInitFunc) synapse_calculator_plugin_result_instance_init, NULL };
	static const GInterfaceInfo synapse_text_match_info = { (GInterfaceInitFunc) synapse_calculator_plugin_result_synapse_text_match_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType synapse_calculator_plugin_result_type_id;
	synapse_calculator_plugin_result_type_id = g_type_register_static (SYNAPSE_TYPE_MATCH, "SynapseCalculatorPluginResult", &g_define_type_info, 0);
	g_type_add_interface_static (synapse_calculator_plugin_result_type_id, SYNAPSE_TYPE_TEXT_MATCH, &synapse_text_match_info);
	SynapseCalculatorPluginResult_private_offset = g_type_add_instance_private (synapse_calculator_plugin_result_type_id, sizeof (SynapseCalculatorPluginResultPrivate));
	return synapse_calculator_plugin_result_type_id;
}

static GType
synapse_calculator_plugin_result_get_type (void)
{
	static volatile gsize synapse_calculator_plugin_result_type_id__once = 0;
	if (g_once_init_enter (&synapse_calculator_plugin_result_type_id__once)) {
		GType synapse_calculator_plugin_result_type_id;
		synapse_calculator_plugin_result_type_id = synapse_calculator_plugin_result_get_type_once ();
		g_once_init_leave (&synapse_calculator_plugin_result_type_id__once, synapse_calculator_plugin_result_type_id);
	}
	return synapse_calculator_plugin_result_type_id__once;
}

static void
_vala_synapse_calculator_plugin_result_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec)
{
	SynapseCalculatorPluginResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResult);
	switch (property_id) {
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY:
		g_value_set_int (value, synapse_calculator_plugin_result_get_default_relevancy (self));
		break;
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY:
		g_value_set_string (value, synapse_text_match_get_text ((SynapseTextMatch*) self));
		break;
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY:
		g_value_set_enum (value, synapse_text_match_get_text_origin ((SynapseTextMatch*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_synapse_calculator_plugin_result_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec)
{
	SynapseCalculatorPluginResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SYNAPSE_CALCULATOR_PLUGIN_TYPE_RESULT, SynapseCalculatorPluginResult);
	switch (property_id) {
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_DEFAULT_RELEVANCY_PROPERTY:
		synapse_calculator_plugin_result_set_default_relevancy (self, g_value_get_int (value));
		break;
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_PROPERTY:
		synapse_text_match_set_text ((SynapseTextMatch*) self, g_value_get_string (value));
		break;
		case SYNAPSE_CALCULATOR_PLUGIN_RESULT_TEXT_ORIGIN_PROPERTY:
		synapse_text_match_set_text_origin ((SynapseTextMatch*) self, g_value_get_enum (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
synapse_calculator_plugin_class_init (SynapseCalculatorPluginClass * klass,
                                      gpointer klass_data)
{
	synapse_calculator_plugin_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SynapseCalculatorPlugin_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_synapse_calculator_plugin_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_synapse_calculator_plugin_set_property;
	G_OBJECT_CLASS (klass)->finalize = synapse_calculator_plugin_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY, synapse_calculator_plugin_properties[SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY] = g_param_spec_boolean ("enabled", "enabled", "enabled", TRUE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	synapse_calculator_plugin_register_plugin ();
}

static void
synapse_calculator_plugin_synapse_activatable_interface_init (SynapseActivatableIface * iface,
                                                              gpointer iface_data)
{
	synapse_calculator_plugin_synapse_activatable_parent_iface = g_type_interface_peek_parent (iface);
	iface->activate = (void (*) (SynapseActivatable*)) synapse_calculator_plugin_real_activate;
	iface->deactivate = (void (*) (SynapseActivatable*)) synapse_calculator_plugin_real_deactivate;
	iface->get_enabled = synapse_calculator_plugin_real_get_enabled;
	iface->set_enabled = synapse_calculator_plugin_real_set_enabled;
}

static void
synapse_calculator_plugin_synapse_item_provider_interface_init (SynapseItemProviderIface * iface,
                                                                gpointer iface_data)
{
	synapse_calculator_plugin_synapse_item_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->handles_query = (gboolean (*) (SynapseItemProvider*, SynapseQuery*)) synapse_calculator_plugin_real_handles_query;
	iface->search = (void (*) (SynapseItemProvider*, SynapseQuery*, GAsyncReadyCallback, gpointer)) synapse_calculator_plugin_real_search;
	iface->search_finish = (SynapseResultSet* (*) (SynapseItemProvider*, GAsyncResult*, GError**)) synapse_calculator_plugin_search_finish;
}

static void
synapse_calculator_plugin_instance_init (SynapseCalculatorPlugin * self,
                                         gpointer klass)
{
	self->priv = synapse_calculator_plugin_get_instance_private (self);
	self->priv->_enabled = TRUE;
}

static void
synapse_calculator_plugin_finalize (GObject * obj)
{
	SynapseCalculatorPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SYNAPSE_TYPE_CALCULATOR_PLUGIN, SynapseCalculatorPlugin);
	G_OBJECT_CLASS (synapse_calculator_plugin_parent_class)->finalize (obj);
}

static GType
synapse_calculator_plugin_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SynapseCalculatorPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_calculator_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SynapseCalculatorPlugin), 0, (GInstanceInitFunc) synapse_calculator_plugin_instance_init, NULL };
	static const GInterfaceInfo synapse_activatable_info = { (GInterfaceInitFunc) synapse_calculator_plugin_synapse_activatable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo synapse_item_provider_info = { (GInterfaceInitFunc) synapse_calculator_plugin_synapse_item_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType synapse_calculator_plugin_type_id;
	synapse_calculator_plugin_type_id = g_type_register_static (G_TYPE_OBJECT, "SynapseCalculatorPlugin", &g_define_type_info, 0);
	g_type_add_interface_static (synapse_calculator_plugin_type_id, SYNAPSE_TYPE_ACTIVATABLE, &synapse_activatable_info);
	g_type_add_interface_static (synapse_calculator_plugin_type_id, SYNAPSE_TYPE_ITEM_PROVIDER, &synapse_item_provider_info);
	SynapseCalculatorPlugin_private_offset = g_type_add_instance_private (synapse_calculator_plugin_type_id, sizeof (SynapseCalculatorPluginPrivate));
	return synapse_calculator_plugin_type_id;
}

GType
synapse_calculator_plugin_get_type (void)
{
	static volatile gsize synapse_calculator_plugin_type_id__once = 0;
	if (g_once_init_enter (&synapse_calculator_plugin_type_id__once)) {
		GType synapse_calculator_plugin_type_id;
		synapse_calculator_plugin_type_id = synapse_calculator_plugin_get_type_once ();
		g_once_init_leave (&synapse_calculator_plugin_type_id__once, synapse_calculator_plugin_type_id);
	}
	return synapse_calculator_plugin_type_id__once;
}

static void
_vala_synapse_calculator_plugin_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	SynapseCalculatorPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SYNAPSE_TYPE_CALCULATOR_PLUGIN, SynapseCalculatorPlugin);
	switch (property_id) {
		case SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY:
		g_value_set_boolean (value, synapse_activatable_get_enabled ((SynapseActivatable*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_synapse_calculator_plugin_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	SynapseCalculatorPlugin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SYNAPSE_TYPE_CALCULATOR_PLUGIN, SynapseCalculatorPlugin);
	switch (property_id) {
		case SYNAPSE_CALCULATOR_PLUGIN_ENABLED_PROPERTY:
		synapse_activatable_set_enabled ((SynapseActivatable*) self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

