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

/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-*/

#include "pastebin.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libsoup/soup.h>
#include <glib-object.h>
#include <gio/gio.h>
#include "codecore.h"
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <libpeas.h>

#define SCRATCH_PLUGINS_PASTEBIN_ACTION_GROUP "pastebin"
#define SCRATCH_PLUGINS_PASTEBIN_ACTION_PREFIX SCRATCH_PLUGINS_PASTEBIN_ACTION_GROUP "."
#define SCRATCH_PLUGINS_PASTEBIN_ACTION_SHOW "action-show"
#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_SERVICES_PASTE_BIN_0_PROPERTY,
	SCRATCH_SERVICES_PASTE_BIN_NUM_PROPERTIES
};
static GParamSpec* scratch_services_paste_bin_properties[SCRATCH_SERVICES_PASTE_BIN_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	SCRATCH_PLUGINS_PASTEBIN_0_PROPERTY,
	SCRATCH_PLUGINS_PASTEBIN_OBJECT_PROPERTY,
	SCRATCH_PLUGINS_PASTEBIN_NUM_PROPERTIES
};
static GParamSpec* scratch_plugins_pastebin_properties[SCRATCH_PLUGINS_PASTEBIN_NUM_PROPERTIES];
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _ScratchPluginsPastebinPrivate {
	GMenuItem* menuitem;
	GMenu* share_menu;
	GObject* _object;
	ScratchDialogsPasteBinDialog* pastebin_dialog;
	ScratchServicesDocument* doc;
	ScratchServicesInterface* plugins;
	GSimpleActionGroup* actions;
};

static gpointer scratch_services_paste_bin_parent_class = NULL;
static GType scratch_services_paste_bin_type_id = 0;
static gint ScratchPluginsPastebin_private_offset;
static gpointer scratch_plugins_pastebin_parent_class = NULL;
static ScratchServicesActivatablePluginIface * scratch_plugins_pastebin_scratch_services_activatable_plugin_parent_iface = NULL;
static GType scratch_plugins_pastebin_type_id = 0;

static void scratch_plugins_pastebin_show_paste_bin_upload_dialog (ScratchPluginsPastebin* self);
static void _scratch_plugins_pastebin_show_paste_bin_upload_dialog_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                              GVariant* parameter,
                                                                                              gpointer self);
static void scratch_plugins_pastebin_real_update_state (ScratchServicesActivatablePlugin* base);
static void scratch_plugins_pastebin_real_activate (ScratchServicesActivatablePlugin* base);
static void __lambda9_ (ScratchPluginsPastebin* self,
                 ScratchServicesDocument* doc);
static void ___lambda9__scratch_services_interface_hook_document (ScratchServicesInterface* _sender,
                                                           ScratchServicesDocument* doc,
                                                           gpointer self);
static void scratch_plugins_pastebin_on_hook_share_menu (ScratchPluginsPastebin* self,
                                                  GMenuModel* menu);
static void _scratch_plugins_pastebin_on_hook_share_menu_scratch_services_interface_hook_share_menu (ScratchServicesInterface* _sender,
                                                                                              GMenuModel* menu,
                                                                                              gpointer self);
static void scratch_plugins_pastebin_add_actions (ScratchPluginsPastebin* self,
                                           GMenuModel* menu);
static void scratch_plugins_pastebin_remove_actions (ScratchPluginsPastebin* self);
static void ___lambda8_ (ScratchPluginsPastebin* self);
static void ____lambda8__gtk_widget_destroy (GtkWidget* _sender,
                                      gpointer self);
static void scratch_plugins_pastebin_real_deactivate (ScratchServicesActivatablePlugin* base);
static void scratch_plugins_pastebin_finalize (GObject * obj);
static void _vala_scratch_plugins_pastebin_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_scratch_plugins_pastebin_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec);
GType scratch_dialogs_paste_bin_dialog_register_type (GTypeModule * module);

static const GActionEntry SCRATCH_PLUGINS_PASTEBIN_ACTION_ENTRIES[1] = {{SCRATCH_PLUGINS_PASTEBIN_ACTION_SHOW, _scratch_plugins_pastebin_show_paste_bin_upload_dialog_gsimple_action_activate_callback}};

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

gboolean
scratch_services_paste_bin_submit (gchar** link,
                                   const gchar* paste_code,
                                   const gchar* paste_name,
                                   const gchar* paste_private,
                                   const gchar* paste_expire_date,
                                   const gchar* paste_format)
{
	gchar* _vala_link = NULL;
	gint _tmp0_;
	gint _tmp1_;
	gchar* api_url = NULL;
	gchar* _tmp3_;
	SoupSession* session = NULL;
	SoupSession* _tmp4_;
	SoupMessage* message = NULL;
	const gchar* _tmp5_;
	SoupMessage* _tmp6_;
	gchar* request = NULL;
	gchar* _tmp7_;
	SoupMessage* _tmp8_;
	const gchar* _tmp9_;
	guint8* _tmp10_;
	gint _tmp10__length1;
	gint _tmp11_ = 0;
	guint8* _tmp12_;
	gint _tmp12__length1;
	GBytes* _tmp13_;
	GBytes* _tmp14_;
	SoupMessage* _tmp15_;
	GBytes* output = NULL;
	gchar* output_s = NULL;
	GBytes* _tmp22_;
	gsize _tmp23_ = 0;
	guint8* _tmp24_;
	gchar* _tmp25_;
	const gchar* _tmp26_;
	gchar* _tmp27_;
	gboolean _tmp28_ = FALSE;
	const gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gboolean _tmp32_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (paste_code != NULL, FALSE);
	g_return_val_if_fail (paste_name != NULL, FALSE);
	g_return_val_if_fail (paste_private != NULL, FALSE);
	g_return_val_if_fail (paste_expire_date != NULL, FALSE);
	g_return_val_if_fail (paste_format != NULL, FALSE);
	_g_free0 (_vala_link);
	_vala_link = NULL;
	_tmp0_ = strlen (paste_code);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == 0) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("No text to paste");
		_g_free0 (_vala_link);
		_vala_link = _tmp2_;
		result = FALSE;
		if (link) {
			*link = _vala_link;
		} else {
			_g_free0 (_vala_link);
		}
		return result;
	}
	_tmp3_ = g_strdup ("https://pastebin.com/api/api_post.php");
	api_url = _tmp3_;
	_tmp4_ = soup_session_new ();
	session = _tmp4_;
	_tmp5_ = api_url;
	_tmp6_ = soup_message_new ("POST", _tmp5_);
	message = _tmp6_;
	_tmp7_ = soup_form_encode ("api_option", "paste", "api_dev_key", "67480801fa55fc0977f7561cf650a339", "api_paste_code", paste_code, "api_paste_name", paste_name, "api_paste_private", paste_private, "api_paste_expire_date", paste_expire_date, "api_paste_format", paste_format, NULL);
	request = _tmp7_;
	_tmp8_ = message;
	_tmp9_ = request;
	_tmp10_ = string_get_data (_tmp9_, &_tmp11_);
	_tmp10__length1 = _tmp11_;
	_tmp12_ = _tmp10_;
	_tmp12__length1 = _tmp10__length1;
	_tmp13_ = g_bytes_new (_tmp12_, _tmp12__length1);
	_tmp14_ = _tmp13_;
	soup_message_set_request_body_from_bytes (_tmp8_, "application/x-www-form-urlencoded", _tmp14_);
	_g_bytes_unref0 (_tmp14_);
	_tmp15_ = message;
	soup_message_set_flags (_tmp15_, SOUP_MESSAGE_NO_REDIRECT);
	{
		GBytes* _tmp16_ = NULL;
		SoupSession* _tmp17_;
		SoupMessage* _tmp18_;
		GBytes* _tmp19_;
		GBytes* _tmp20_;
		_tmp17_ = session;
		_tmp18_ = message;
		_tmp19_ = soup_session_send_and_read (_tmp17_, _tmp18_, NULL, &_inner_error0_);
		_tmp16_ = _tmp19_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp20_ = _tmp16_;
		_tmp16_ = NULL;
		_g_bytes_unref0 (output);
		output = _tmp20_;
		_g_bytes_unref0 (_tmp16_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		result = FALSE;
		_g_bytes_unref0 (output);
		_g_free0 (request);
		_g_object_unref0 (message);
		_g_object_unref0 (session);
		_g_free0 (api_url);
		if (link) {
			*link = _vala_link;
		} else {
			_g_free0 (_vala_link);
		}
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp21_ = FALSE;
		_g_bytes_unref0 (output);
		_g_free0 (request);
		_g_object_unref0 (message);
		_g_object_unref0 (session);
		_g_free0 (api_url);
		_g_free0 (_vala_link);
		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 _tmp21_;
	}
	_tmp22_ = output;
	_tmp24_ = g_bytes_get_data (_tmp22_, &_tmp23_);
	_tmp25_ = g_strdup ((const gchar*) _tmp24_);
	output_s = _tmp25_;
	_tmp26_ = output_s;
	_tmp27_ = g_strdup (_tmp26_);
	_g_free0 (_vala_link);
	_vala_link = _tmp27_;
	_tmp29_ = output_s;
	_tmp30_ = g_uri_parse_scheme (_tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = _tmp31_ == NULL;
	_g_free0 (_tmp31_);
	if (_tmp32_) {
		_tmp28_ = TRUE;
	} else {
		SoupMessage* _tmp33_;
		guint _tmp34_;
		guint _tmp35_;
		_tmp33_ = message;
		g_object_get (_tmp33_, "status-code", &_tmp34_, NULL);
		_tmp35_ = _tmp34_;
		_tmp28_ = _tmp35_ != ((guint) 200);
	}
	if (_tmp28_) {
		result = FALSE;
		_g_free0 (output_s);
		_g_bytes_unref0 (output);
		_g_free0 (request);
		_g_object_unref0 (message);
		_g_object_unref0 (session);
		_g_free0 (api_url);
		if (link) {
			*link = _vala_link;
		} else {
			_g_free0 (_vala_link);
		}
		return result;
	}
	result = TRUE;
	_g_free0 (output_s);
	_g_bytes_unref0 (output);
	_g_free0 (request);
	_g_object_unref0 (message);
	_g_object_unref0 (session);
	_g_free0 (api_url);
	if (link) {
		*link = _vala_link;
	} else {
		_g_free0 (_vala_link);
	}
	return result;
}

ScratchServicesPasteBin*
scratch_services_paste_bin_construct (GType object_type)
{
	ScratchServicesPasteBin * self = NULL;
	self = (ScratchServicesPasteBin*) g_object_new (object_type, NULL);
	return self;
}

ScratchServicesPasteBin*
scratch_services_paste_bin_new (void)
{
	return scratch_services_paste_bin_construct (SCRATCH_SERVICES_TYPE_PASTE_BIN);
}

static void
scratch_services_paste_bin_class_init (ScratchServicesPasteBinClass * klass,
                                       gpointer klass_data)
{
	scratch_services_paste_bin_parent_class = g_type_class_peek_parent (klass);
}

static void
scratch_services_paste_bin_instance_init (ScratchServicesPasteBin * self,
                                          gpointer klass)
{
}

GType
scratch_services_paste_bin_get_type (void)
{
	return scratch_services_paste_bin_type_id;
}

GType
scratch_services_paste_bin_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchServicesPasteBinClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_services_paste_bin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchServicesPasteBin), 0, (GInstanceInitFunc) scratch_services_paste_bin_instance_init, NULL };
	scratch_services_paste_bin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "ScratchServicesPasteBin", &g_define_type_info, G_TYPE_FLAG_NONE);
	return scratch_services_paste_bin_type_id;
}

static inline gpointer
scratch_plugins_pastebin_get_instance_private (ScratchPluginsPastebin* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchPluginsPastebin_private_offset);
}

static void
_scratch_plugins_pastebin_show_paste_bin_upload_dialog_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                         GVariant* parameter,
                                                                                         gpointer self)
{
	scratch_plugins_pastebin_show_paste_bin_upload_dialog ((ScratchPluginsPastebin*) self);
}

static void
scratch_plugins_pastebin_real_update_state (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsPastebin * self;
	self = (ScratchPluginsPastebin*) base;
}

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

static void
__lambda9_ (ScratchPluginsPastebin* self,
            ScratchServicesDocument* doc)
{
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (doc != NULL);
	_tmp0_ = _g_object_ref0 (doc);
	_g_object_unref0 (self->priv->doc);
	self->priv->doc = _tmp0_;
}

static void
___lambda9__scratch_services_interface_hook_document (ScratchServicesInterface* _sender,
                                                      ScratchServicesDocument* doc,
                                                      gpointer self)
{
	__lambda9_ ((ScratchPluginsPastebin*) self, doc);
}

static void
_scratch_plugins_pastebin_on_hook_share_menu_scratch_services_interface_hook_share_menu (ScratchServicesInterface* _sender,
                                                                                         GMenuModel* menu,
                                                                                         gpointer self)
{
	scratch_plugins_pastebin_on_hook_share_menu ((ScratchPluginsPastebin*) self, menu);
}

static void
scratch_plugins_pastebin_real_activate (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsPastebin * self;
	GObject* _tmp0_;
	GObject* _tmp1_;
	ScratchServicesInterface* _tmp2_;
	ScratchServicesInterface* _tmp3_;
	self = (ScratchPluginsPastebin*) base;
	_tmp0_ = scratch_services_activatable_plugin_get_object ((ScratchServicesActivatablePlugin*) self);
	_tmp1_ = _tmp0_;
	_g_object_unref0 (self->priv->plugins);
	self->priv->plugins = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, SCRATCH_SERVICES_TYPE_INTERFACE, ScratchServicesInterface);
	_tmp2_ = self->priv->plugins;
	g_signal_connect_object (_tmp2_, "hook-document", (GCallback) ___lambda9__scratch_services_interface_hook_document, self, 0);
	_tmp3_ = self->priv->plugins;
	g_signal_connect_object (_tmp3_, "hook-share-menu", (GCallback) _scratch_plugins_pastebin_on_hook_share_menu_scratch_services_interface_hook_share_menu, self, 0);
}

static void
scratch_plugins_pastebin_on_hook_share_menu (ScratchPluginsPastebin* self,
                                             GMenuModel* menu)
{
	GMenuItem* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
	_tmp0_ = self->priv->menuitem;
	if (_tmp0_ != NULL) {
		return;
	}
	scratch_plugins_pastebin_add_actions (self, menu);
}

static void
scratch_plugins_pastebin_add_actions (ScratchPluginsPastebin* self,
                                      GMenuModel* menu)
{
	GSimpleActionGroup* _tmp0_;
	ScratchServicesInterface* _tmp3_;
	ScratchServicesPluginsManager* _tmp4_;
	ScratchServicesPluginsManager* _tmp5_;
	ScratchMainWindow* _tmp6_;
	ScratchMainWindow* _tmp7_;
	GSimpleActionGroup* _tmp8_;
	GMenu* _tmp9_;
	GMenuItem* _tmp10_;
	GMenu* _tmp11_;
	GMenuItem* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
	_tmp0_ = self->priv->actions;
	if (_tmp0_ == NULL) {
		GSimpleActionGroup* _tmp1_;
		GSimpleActionGroup* _tmp2_;
		_tmp1_ = g_simple_action_group_new ();
		_g_object_unref0 (self->priv->actions);
		self->priv->actions = _tmp1_;
		_tmp2_ = self->priv->actions;
		g_action_map_add_action_entries ((GActionMap*) _tmp2_, SCRATCH_PLUGINS_PASTEBIN_ACTION_ENTRIES, (gint) G_N_ELEMENTS (SCRATCH_PLUGINS_PASTEBIN_ACTION_ENTRIES), self);
	}
	_tmp3_ = self->priv->plugins;
	_tmp4_ = scratch_services_interface_get_manager (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = scratch_services_plugins_manager_get_window (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->actions;
	gtk_widget_insert_action_group ((GtkWidget*) _tmp7_, SCRATCH_PLUGINS_PASTEBIN_ACTION_GROUP, (GActionGroup*) _tmp8_);
	_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (menu, g_menu_get_type (), GMenu));
	_g_object_unref0 (self->priv->share_menu);
	self->priv->share_menu = _tmp9_;
	_tmp10_ = g_menu_item_new (_ ("Upload to Pastebin"), SCRATCH_PLUGINS_PASTEBIN_ACTION_PREFIX SCRATCH_PLUGINS_PASTEBIN_ACTION_SHOW);
	_g_object_unref0 (self->priv->menuitem);
	self->priv->menuitem = _tmp10_;
	_tmp11_ = self->priv->share_menu;
	_tmp12_ = self->priv->menuitem;
	g_menu_append_item (_tmp11_, _tmp12_);
}

static void
scratch_plugins_pastebin_remove_actions (ScratchPluginsPastebin* self)
{
	gint length = 0;
	GMenu* _tmp0_;
	ScratchServicesInterface* _tmp12_;
	ScratchServicesPluginsManager* _tmp13_;
	ScratchServicesPluginsManager* _tmp14_;
	ScratchMainWindow* _tmp15_;
	ScratchMainWindow* _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->share_menu;
	length = g_menu_model_get_n_items ((GMenuModel*) _tmp0_);
	{
		gint i = 0;
		i = length - 1;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gchar* action_name = NULL;
				GMenu* _tmp3_;
				const GVariantType* _tmp4_;
				GVariant* _tmp5_;
				GVariant* _tmp6_;
				const gchar* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				const gchar* _tmp10_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ - 1;
				}
				_tmp1_ = FALSE;
				if (!(i >= 0)) {
					break;
				}
				_tmp3_ = self->priv->share_menu;
				_tmp4_ = G_VARIANT_TYPE_STRING;
				_tmp5_ = g_menu_model_get_item_attribute_value ((GMenuModel*) _tmp3_, i, G_MENU_ATTRIBUTE_ACTION, _tmp4_);
				_tmp6_ = _tmp5_;
				_tmp7_ = g_variant_get_string (_tmp6_, NULL);
				_tmp8_ = g_strdup (_tmp7_);
				_tmp9_ = _tmp8_;
				_g_variant_unref0 (_tmp6_);
				action_name = _tmp9_;
				_tmp10_ = action_name;
				if (g_str_has_prefix (_tmp10_, SCRATCH_PLUGINS_PASTEBIN_ACTION_PREFIX)) {
					GMenu* _tmp11_;
					_tmp11_ = self->priv->share_menu;
					g_menu_remove (_tmp11_, i);
				}
				_g_free0 (action_name);
			}
		}
	}
	_tmp12_ = self->priv->plugins;
	_tmp13_ = scratch_services_interface_get_manager (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = scratch_services_plugins_manager_get_window (_tmp14_);
	_tmp16_ = _tmp15_;
	gtk_widget_insert_action_group ((GtkWidget*) _tmp16_, SCRATCH_PLUGINS_PASTEBIN_ACTION_GROUP, NULL);
}

static void
___lambda8_ (ScratchPluginsPastebin* self)
{
	_g_object_unref0 (self->priv->pastebin_dialog);
	self->priv->pastebin_dialog = NULL;
}

static void
____lambda8__gtk_widget_destroy (GtkWidget* _sender,
                                 gpointer self)
{
	___lambda8_ ((ScratchPluginsPastebin*) self);
}

static void
scratch_plugins_pastebin_show_paste_bin_upload_dialog (ScratchPluginsPastebin* self)
{
	ScratchDialogsPasteBinDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->pastebin_dialog;
	if (_tmp0_ != NULL) {
		ScratchDialogsPasteBinDialog* _tmp1_;
		_tmp1_ = self->priv->pastebin_dialog;
		gtk_window_present ((GtkWindow*) _tmp1_);
	} else {
		ScratchMainWindow* window = NULL;
		ScratchServicesInterface* _tmp2_;
		ScratchServicesPluginsManager* _tmp3_;
		ScratchServicesPluginsManager* _tmp4_;
		ScratchMainWindow* _tmp5_;
		ScratchMainWindow* _tmp6_;
		ScratchMainWindow* _tmp7_;
		ScratchMainWindow* _tmp8_;
		ScratchServicesDocument* _tmp9_;
		ScratchDialogsPasteBinDialog* _tmp10_;
		ScratchDialogsPasteBinDialog* _tmp11_;
		_tmp2_ = self->priv->plugins;
		_tmp3_ = scratch_services_interface_get_manager (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = scratch_services_plugins_manager_get_window (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = _g_object_ref0 (_tmp6_);
		window = _tmp7_;
		_tmp8_ = window;
		_tmp9_ = self->priv->doc;
		_tmp10_ = scratch_dialogs_paste_bin_dialog_new ((GtkWindow*) _tmp8_, _tmp9_);
		g_object_ref_sink (_tmp10_);
		_g_object_unref0 (self->priv->pastebin_dialog);
		self->priv->pastebin_dialog = _tmp10_;
		_tmp11_ = self->priv->pastebin_dialog;
		g_signal_connect_object ((GtkWidget*) _tmp11_, "destroy", (GCallback) ____lambda8__gtk_widget_destroy, self, 0);
		_g_object_unref0 (window);
	}
}

static void
scratch_plugins_pastebin_real_deactivate (ScratchServicesActivatablePlugin* base)
{
	ScratchPluginsPastebin * self;
	self = (ScratchPluginsPastebin*) base;
	scratch_plugins_pastebin_remove_actions (self);
}

ScratchPluginsPastebin*
scratch_plugins_pastebin_construct (GType object_type)
{
	ScratchPluginsPastebin * self = NULL;
	self = (ScratchPluginsPastebin*) g_object_new (object_type, NULL);
	return self;
}

ScratchPluginsPastebin*
scratch_plugins_pastebin_new (void)
{
	return scratch_plugins_pastebin_construct (SCRATCH_PLUGINS_TYPE_PASTEBIN);
}

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

static void
scratch_plugins_pastebin_real_set_object (ScratchServicesActivatablePlugin* base,
                                          GObject* value)
{
	ScratchPluginsPastebin* self;
	GObject* old_value;
	self = (ScratchPluginsPastebin*) base;
	old_value = scratch_plugins_pastebin_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_pastebin_properties[SCRATCH_PLUGINS_PASTEBIN_OBJECT_PROPERTY]);
	}
	_g_object_unref0 (old_value);
}

static void
scratch_plugins_pastebin_class_init (ScratchPluginsPastebinClass * klass,
                                     gpointer klass_data)
{
	scratch_plugins_pastebin_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchPluginsPastebin_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_plugins_pastebin_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_plugins_pastebin_set_property;
	G_OBJECT_CLASS (klass)->finalize = scratch_plugins_pastebin_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_PLUGINS_PASTEBIN_OBJECT_PROPERTY, scratch_plugins_pastebin_properties[SCRATCH_PLUGINS_PASTEBIN_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_pastebin_scratch_services_activatable_plugin_interface_init (ScratchServicesActivatablePluginIface * iface,
                                                                             gpointer iface_data)
{
	scratch_plugins_pastebin_scratch_services_activatable_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->update_state = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_pastebin_real_update_state;
	iface->activate = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_pastebin_real_activate;
	iface->deactivate = (void (*) (ScratchServicesActivatablePlugin*)) scratch_plugins_pastebin_real_deactivate;
	iface->get_object = scratch_plugins_pastebin_real_get_object;
	iface->set_object = scratch_plugins_pastebin_real_set_object;
}

static void
scratch_plugins_pastebin_instance_init (ScratchPluginsPastebin * self,
                                        gpointer klass)
{
	self->priv = scratch_plugins_pastebin_get_instance_private (self);
	self->priv->menuitem = NULL;
	self->priv->share_menu = NULL;
	self->priv->pastebin_dialog = NULL;
	self->priv->doc = NULL;
}

static void
scratch_plugins_pastebin_finalize (GObject * obj)
{
	ScratchPluginsPastebin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_PLUGINS_TYPE_PASTEBIN, ScratchPluginsPastebin);
	_g_object_unref0 (self->priv->menuitem);
	_g_object_unref0 (self->priv->share_menu);
	_g_object_unref0 (self->priv->_object);
	_g_object_unref0 (self->priv->pastebin_dialog);
	_g_object_unref0 (self->priv->doc);
	_g_object_unref0 (self->priv->plugins);
	_g_object_unref0 (self->priv->actions);
	G_OBJECT_CLASS (scratch_plugins_pastebin_parent_class)->finalize (obj);
}

GType
scratch_plugins_pastebin_get_type (void)
{
	return scratch_plugins_pastebin_type_id;
}

GType
scratch_plugins_pastebin_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchPluginsPastebinClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_plugins_pastebin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchPluginsPastebin), 0, (GInstanceInitFunc) scratch_plugins_pastebin_instance_init, NULL };
	static const GInterfaceInfo scratch_services_activatable_plugin_info = { (GInterfaceInitFunc) scratch_plugins_pastebin_scratch_services_activatable_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	scratch_plugins_pastebin_type_id = g_type_module_register_type (module, peas_extension_base_get_type (), "ScratchPluginsPastebin", &g_define_type_info, G_TYPE_FLAG_NONE);
	g_type_module_add_interface (module, scratch_plugins_pastebin_type_id, SCRATCH_SERVICES_TYPE_ACTIVATABLE_PLUGIN, &scratch_services_activatable_plugin_info);
	ScratchPluginsPastebin_private_offset = sizeof (ScratchPluginsPastebinPrivate);
	return scratch_plugins_pastebin_type_id;
}

static void
_vala_scratch_plugins_pastebin_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	ScratchPluginsPastebin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_PLUGINS_TYPE_PASTEBIN, ScratchPluginsPastebin);
	switch (property_id) {
		case SCRATCH_PLUGINS_PASTEBIN_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_pastebin_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	ScratchPluginsPastebin * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_PLUGINS_TYPE_PASTEBIN, ScratchPluginsPastebin);
	switch (property_id) {
		case SCRATCH_PLUGINS_PASTEBIN_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_dialogs_paste_bin_dialog_register_type (module);
	scratch_services_paste_bin_register_type (module);
	scratch_plugins_pastebin_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_PASTEBIN);
	_g_object_unref0 (objmodule);
}

