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

/*
* Copyright (c) 2010 Michal Hruby <michal.mhr@gmail.com>
*               2017 elementary LLC.
*
* 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-object.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <stdlib.h>
#include <string.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

#define SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION (synapse_clipboard_copy_action_get_type ())
#define SYNAPSE_CLIPBOARD_COPY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION, SynapseClipboardCopyAction))
#define SYNAPSE_CLIPBOARD_COPY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION, SynapseClipboardCopyActionClass))
#define SYNAPSE_IS_CLIPBOARD_COPY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION))
#define SYNAPSE_IS_CLIPBOARD_COPY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION))
#define SYNAPSE_CLIPBOARD_COPY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION, SynapseClipboardCopyActionClass))

typedef struct _SynapseClipboardCopyAction SynapseClipboardCopyAction;
typedef struct _SynapseClipboardCopyActionClass SynapseClipboardCopyActionClass;
typedef struct _SynapseClipboardCopyActionPrivate SynapseClipboardCopyActionPrivate;
enum  {
	SYNAPSE_CLIPBOARD_COPY_ACTION_0_PROPERTY,
	SYNAPSE_CLIPBOARD_COPY_ACTION_NUM_PROPERTIES
};
static GParamSpec* synapse_clipboard_copy_action_properties[SYNAPSE_CLIPBOARD_COPY_ACTION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _SynapseClipboardCopyAction {
	SynapseBaseAction parent_instance;
	SynapseClipboardCopyActionPrivate * priv;
};

struct _SynapseClipboardCopyActionClass {
	SynapseBaseActionClass parent_class;
};

static gpointer synapse_clipboard_copy_action_parent_class = NULL;
static GType synapse_clipboard_copy_action_type_id = 0;

GType synapse_clipboard_copy_action_register_type (GTypeModule * module);
VALA_EXTERN GType synapse_clipboard_copy_action_get_type (void) G_GNUC_CONST ;
VALA_EXTERN SynapseClipboardCopyAction* synapse_clipboard_copy_action_new (void);
VALA_EXTERN SynapseClipboardCopyAction* synapse_clipboard_copy_action_construct (GType object_type);
static void synapse_clipboard_copy_action_real_do_execute (SynapseBaseAction* base,
                                                    SynapseMatch* match,
                                                    SynapseMatch* target);
static gboolean synapse_clipboard_copy_action_real_valid_for_match (SynapseBaseAction* base,
                                                             SynapseMatch* match);
static gint synapse_clipboard_copy_action_real_get_relevancy_for_match (SynapseBaseAction* base,
                                                                 SynapseMatch* match);

SynapseClipboardCopyAction*
synapse_clipboard_copy_action_construct (GType object_type)
{
	SynapseClipboardCopyAction * self = NULL;
	self = (SynapseClipboardCopyAction*) g_object_new (object_type, "title", _ ("Copy to Clipboard"), "description", _ ("Copy selection to clipboard"), "icon-name", "gtk-copy", "has-thumbnail", FALSE, "match-type", SYNAPSE_MATCH_TYPE_ACTION, "default-relevancy", SYNAPSE_MATCH_SCORE_AVERAGE, NULL);
	return self;
}

SynapseClipboardCopyAction*
synapse_clipboard_copy_action_new (void)
{
	return synapse_clipboard_copy_action_construct (SYNAPSE_TYPE_CLIPBOARD_COPY_ACTION);
}

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

static void
synapse_clipboard_copy_action_real_do_execute (SynapseBaseAction* base,
                                               SynapseMatch* match,
                                               SynapseMatch* target)
{
	SynapseClipboardCopyAction * self;
	GtkClipboard* cb = NULL;
	GtkClipboard* _tmp0_;
	GtkClipboard* _tmp1_;
	SynapseMatchType _tmp2_;
	SynapseMatchType _tmp3_;
	self = (SynapseClipboardCopyAction*) base;
	_tmp0_ = gtk_clipboard_get (GDK_NONE);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	cb = _tmp1_;
	_tmp2_ = synapse_match_get_match_type (match);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == SYNAPSE_MATCH_TYPE_GENERIC_URI) {
		SynapseUriMatch* uri_match = NULL;
		SynapseUriMatch* _tmp4_;
		SynapseUriMatch* _tmp5_;
		GtkClipboard* _tmp6_;
		SynapseUriMatch* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		_tmp4_ = _g_object_ref0 (SYNAPSE_IS_URI_MATCH (match) ? ((SynapseUriMatch*) match) : NULL);
		uri_match = _tmp4_;
		_tmp5_ = uri_match;
		g_return_if_fail (_tmp5_ != NULL);
		_tmp6_ = cb;
		_tmp7_ = uri_match;
		_tmp8_ = synapse_uri_match_get_uri (_tmp7_);
		_tmp9_ = _tmp8_;
		gtk_clipboard_set_text (_tmp6_, _tmp9_, -1);
		_g_object_unref0 (uri_match);
	} else {
		SynapseMatchType _tmp10_;
		SynapseMatchType _tmp11_;
		_tmp10_ = synapse_match_get_match_type (match);
		_tmp11_ = _tmp10_;
		if (_tmp11_ == SYNAPSE_MATCH_TYPE_TEXT) {
			SynapseTextMatch* text_match = NULL;
			SynapseTextMatch* _tmp12_;
			const gchar* _tmp13_ = NULL;
			SynapseTextMatch* _tmp14_;
			const gchar* content = NULL;
			GtkClipboard* _tmp20_;
			const gchar* _tmp21_;
			_tmp12_ = _g_object_ref0 (SYNAPSE_IS_TEXT_MATCH (match) ? ((SynapseTextMatch*) match) : NULL);
			text_match = _tmp12_;
			_tmp14_ = text_match;
			if (_tmp14_ != NULL) {
				SynapseTextMatch* _tmp15_;
				const gchar* _tmp16_;
				const gchar* _tmp17_;
				_tmp15_ = text_match;
				_tmp16_ = synapse_text_match_get_text (_tmp15_);
				_tmp17_ = _tmp16_;
				_tmp13_ = _tmp17_;
			} else {
				const gchar* _tmp18_;
				const gchar* _tmp19_;
				_tmp18_ = synapse_match_get_title (match);
				_tmp19_ = _tmp18_;
				_tmp13_ = _tmp19_;
			}
			content = _tmp13_;
			_tmp20_ = cb;
			_tmp21_ = content;
			gtk_clipboard_set_text (_tmp20_, _tmp21_, -1);
			_g_object_unref0 (text_match);
		}
	}
	_g_object_unref0 (cb);
}

static gboolean
synapse_clipboard_copy_action_real_valid_for_match (SynapseBaseAction* base,
                                                    SynapseMatch* match)
{
	SynapseClipboardCopyAction * self;
	SynapseMatchType _tmp0_;
	SynapseMatchType _tmp1_;
	gboolean result;
	self = (SynapseClipboardCopyAction*) base;
	g_return_val_if_fail (match != NULL, FALSE);
	_tmp0_ = synapse_match_get_match_type (match);
	_tmp1_ = _tmp0_;
	switch (_tmp1_) {
		case SYNAPSE_MATCH_TYPE_GENERIC_URI:
		{
			result = TRUE;
			return result;
		}
		case SYNAPSE_MATCH_TYPE_TEXT:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}

static gint
synapse_clipboard_copy_action_real_get_relevancy_for_match (SynapseBaseAction* base,
                                                            SynapseMatch* match)
{
	SynapseClipboardCopyAction * self;
	SynapseTextMatch* text_match = NULL;
	gboolean _tmp0_ = FALSE;
	SynapseTextMatch* _tmp1_;
	gint _tmp5_;
	gint _tmp6_;
	gint result;
	self = (SynapseClipboardCopyAction*) base;
	g_return_val_if_fail (match != NULL, -1);
	text_match = SYNAPSE_IS_TEXT_MATCH (match) ? ((SynapseTextMatch*) match) : NULL;
	_tmp1_ = text_match;
	if (_tmp1_ != NULL) {
		SynapseTextMatch* _tmp2_;
		SynapseTextOrigin _tmp3_;
		SynapseTextOrigin _tmp4_;
		_tmp2_ = text_match;
		_tmp3_ = synapse_text_match_get_text_origin (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ == SYNAPSE_TEXT_ORIGIN_CLIPBOARD;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = 0;
		return result;
	}
	_tmp5_ = synapse_base_action_get_default_relevancy ((SynapseBaseAction*) self);
	_tmp6_ = _tmp5_;
	result = _tmp6_;
	return result;
}

static void
synapse_clipboard_copy_action_class_init (SynapseClipboardCopyActionClass * klass,
                                          gpointer klass_data)
{
	synapse_clipboard_copy_action_parent_class = g_type_class_peek_parent (klass);
	((SynapseBaseActionClass *) klass)->do_execute = (void (*) (SynapseBaseAction*, SynapseMatch*, SynapseMatch*)) synapse_clipboard_copy_action_real_do_execute;
	((SynapseBaseActionClass *) klass)->valid_for_match = (gboolean (*) (SynapseBaseAction*, SynapseMatch*)) synapse_clipboard_copy_action_real_valid_for_match;
	((SynapseBaseActionClass *) klass)->get_relevancy_for_match = (gint (*) (SynapseBaseAction*, SynapseMatch*)) synapse_clipboard_copy_action_real_get_relevancy_for_match;
}

static void
synapse_clipboard_copy_action_instance_init (SynapseClipboardCopyAction * self,
                                             gpointer klass)
{
}

GType
synapse_clipboard_copy_action_get_type (void)
{
	return synapse_clipboard_copy_action_type_id;
}

GType
synapse_clipboard_copy_action_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (SynapseClipboardCopyActionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_clipboard_copy_action_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SynapseClipboardCopyAction), 0, (GInstanceInitFunc) synapse_clipboard_copy_action_instance_init, NULL };
	synapse_clipboard_copy_action_type_id = g_type_module_register_type (module, SYNAPSE_TYPE_BASE_ACTION, "SynapseClipboardCopyAction", &g_define_type_info, 0);
	return synapse_clipboard_copy_action_type_id;
}

