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

/*
 * Seahorse
 *
 * Copyright (C) 2008 Stefan Walter
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2016 Niels De Graef
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "seahorse-ssh.h"
#include "seahorse-common.h"
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.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  {
	SEAHORSE_SSH_ACTIONS_0_PROPERTY,
	SEAHORSE_SSH_ACTIONS_NUM_PROPERTIES
};
static GParamSpec* seahorse_ssh_actions_properties[SEAHORSE_SSH_ACTIONS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _Block1Data {
	int _ref_count_;
	SeahorseSshActions* self;
	SeahorseSshGenerate* dialog;
};

static gpointer seahorse_ssh_actions_parent_class = NULL;
static SeahorseSshActions* seahorse_ssh_actions__instance;
static SeahorseSshActions* seahorse_ssh_actions__instance = NULL;

static void seahorse_ssh_actions_on_ssh_generate_key (SeahorseSshActions* self,
                                               GSimpleAction* action,
                                               GVariant* param);
static void _seahorse_ssh_actions_on_ssh_generate_key_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void seahorse_ssh_actions_on_ssh_upload (SeahorseSshActions* self,
                                         GSimpleAction* action,
                                         GVariant* param);
static void _seahorse_ssh_actions_on_ssh_upload_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self);
static SeahorseSshActions* seahorse_ssh_actions_new (void);
static SeahorseSshActions* seahorse_ssh_actions_construct (GType object_type);
static void seahorse_ssh_actions_real_set_actions_for_selected_objects (SeahorseActionGroup* base,
                                                                 GList* objects);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda13_ (Block1Data* _data1_,
                  GObject* obj,
                  GAsyncResult* res);
static GVariant* _variant_new1 (const gchar* value);
static void ___lambda13__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static GObject * seahorse_ssh_actions_constructor (GType type,
                                            guint n_construct_properties,
                                            GObjectConstructParam * construct_properties);
static void seahorse_ssh_actions_finalize (GObject * obj);
static GType seahorse_ssh_actions_get_type_once (void);

static const GActionEntry SEAHORSE_SSH_ACTIONS_KEYS_ACTIONS[2] = {{"generate-key", _seahorse_ssh_actions_on_ssh_generate_key_gsimple_action_activate_callback}, {"remote-upload", _seahorse_ssh_actions_on_ssh_upload_gsimple_action_activate_callback}};

static void
_seahorse_ssh_actions_on_ssh_generate_key_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	seahorse_ssh_actions_on_ssh_generate_key ((SeahorseSshActions*) self, action, parameter);
}

static void
_seahorse_ssh_actions_on_ssh_upload_gsimple_action_activate_callback (GSimpleAction* action,
                                                                      GVariant* parameter,
                                                                      gpointer self)
{
	seahorse_ssh_actions_on_ssh_upload ((SeahorseSshActions*) self, action, parameter);
}

static SeahorseSshActions*
seahorse_ssh_actions_construct (GType object_type)
{
	SeahorseSshActions * self = NULL;
	self = (SeahorseSshActions*) g_object_new (object_type, "prefix", "ssh", NULL);
	return self;
}

static SeahorseSshActions*
seahorse_ssh_actions_new (void)
{
	return seahorse_ssh_actions_construct (SEAHORSE_SSH_TYPE_ACTIONS);
}

SeahorseSshActions*
seahorse_ssh_actions_instance (void)
{
	SeahorseSshActions* _tmp0_;
	SeahorseSshActions* _tmp2_;
	SeahorseSshActions* result;
	_tmp0_ = seahorse_ssh_actions__instance;
	if (_tmp0_ == NULL) {
		SeahorseSshActions* _tmp1_;
		_tmp1_ = seahorse_ssh_actions_new ();
		_g_object_unref0 (seahorse_ssh_actions__instance);
		seahorse_ssh_actions__instance = _tmp1_;
	}
	_tmp2_ = seahorse_ssh_actions__instance;
	result = _tmp2_;
	return result;
}

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

static void
seahorse_ssh_actions_real_set_actions_for_selected_objects (SeahorseActionGroup* base,
                                                            GList* objects)
{
	SeahorseSshActions * self;
	gboolean is_ssh_key = FALSE;
	GAction* _tmp2_;
	self = (SeahorseSshActions*) base;
	is_ssh_key = FALSE;
	{
		GList* object_collection = NULL;
		GList* object_it = NULL;
		object_collection = objects;
		for (object_it = object_collection; object_it != NULL; object_it = object_it->next) {
			GObject* _tmp0_;
			GObject* object = NULL;
			_tmp0_ = _g_object_ref0 ((GObject*) object_it->data);
			object = _tmp0_;
			{
				GObject* _tmp1_;
				_tmp1_ = object;
				if (SEAHORSE_SSH_IS_KEY (_tmp1_)) {
					is_ssh_key = TRUE;
					_g_object_unref0 (object);
					break;
				}
				_g_object_unref0 (object);
			}
		}
	}
	_tmp2_ = g_action_map_lookup_action ((GActionMap*) self, "remote-upload");
	g_simple_action_set_enabled (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, g_simple_action_get_type (), GSimpleAction), is_ssh_key);
}

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_)) {
		SeahorseSshActions* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->dialog);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static GVariant*
_variant_new1 (const gchar* value)
{
	return g_variant_ref_sink (g_variant_new_string (value));
}

static void
__lambda13_ (Block1Data* _data1_,
             GObject* obj,
             GAsyncResult* res)
{
	SeahorseSshActions* self;
	SeahorseSshGenerate* _tmp0_;
	SeahorseSshGenerate* _tmp1_;
	SeahorseCatalog* _tmp2_;
	SeahorseCatalog* _tmp3_;
	SeahorseCatalog* _tmp4_;
	GVariant* _tmp5_;
	self = _data1_->self;
	g_return_if_fail (res != NULL);
	_tmp0_ = _data1_->dialog;
	seahorse_ssh_generate_generate_key_finish (_tmp0_, res);
	_tmp1_ = _data1_->dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp1_);
	_tmp2_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp5_ = _variant_new1 ("openssh");
	g_action_group_activate_action ((GActionGroup*) _tmp4_, "focus-place", _tmp5_);
	_g_variant_unref0 (_tmp5_);
	_g_object_unref0 (_tmp4_);
}

static void
___lambda13__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda13_ (self, source_object, res);
	block1_data_unref (self);
}

static void
seahorse_ssh_actions_on_ssh_generate_key (SeahorseSshActions* self,
                                          GSimpleAction* action,
                                          GVariant* param)
{
	Block1Data* _data1_;
	SeahorseSshBackend* _tmp0_;
	SeahorseSshBackend* _tmp1_;
	SeahorseSshSource* _tmp2_;
	SeahorseSshSource* _tmp3_;
	SeahorseCatalog* _tmp4_;
	SeahorseCatalog* _tmp5_;
	SeahorseCatalog* _tmp6_;
	SeahorseSshGenerate* _tmp7_;
	SeahorseSshGenerate* _tmp8_;
	SeahorseSshGenerate* _tmp9_;
	SeahorseSshGenerate* _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = seahorse_ssh_backend_get_instance ();
	_tmp1_ = _tmp0_;
	_tmp2_ = seahorse_ssh_backend_get_dot_ssh (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp7_ = seahorse_ssh_generate_new (_tmp3_, (GtkWindow*) _tmp6_);
	g_object_ref_sink (_tmp7_);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp6_);
	_g_object_unref0 (_tmp3_);
	_data1_->dialog = _tmp8_;
	_tmp9_ = _data1_->dialog;
	if (gtk_dialog_run ((GtkDialog*) _tmp9_) != ((gint) GTK_RESPONSE_ACCEPT)) {
		SeahorseSshGenerate* _tmp10_;
		_tmp10_ = _data1_->dialog;
		gtk_widget_destroy ((GtkWidget*) _tmp10_);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		return;
	}
	_tmp11_ = _data1_->dialog;
	seahorse_ssh_generate_generate_key (_tmp11_, ___lambda13__gasync_ready_callback, block1_data_ref (_data1_));
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static void
seahorse_ssh_actions_on_ssh_upload (SeahorseSshActions* self,
                                    GSimpleAction* action,
                                    GVariant* param)
{
	GList* keys = NULL;
	SeahorseCatalog* _tmp0_;
	SeahorseCatalog* _tmp1_;
	SeahorseCatalog* _tmp2_;
	gboolean _tmp3_;
	GList* _tmp15_;
	SeahorseCatalog* _tmp16_;
	SeahorseCatalog* _tmp17_;
	SeahorseCatalog* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	keys = NULL;
	_tmp0_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		SeahorseCatalog* _tmp4_;
		SeahorseCatalog* _tmp5_;
		SeahorseCatalog* _tmp6_;
		GList* _tmp7_;
		GList* _tmp8_;
		_tmp4_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		_tmp7_ = seahorse_catalog_get_selected_objects (_tmp6_);
		_tmp8_ = _tmp7_;
		_g_object_unref0 (_tmp6_);
		{
			GList* el_collection = NULL;
			GList* el_it = NULL;
			el_collection = _tmp8_;
			for (el_it = el_collection; el_it != NULL; el_it = el_it->next) {
				GObject* _tmp9_;
				GObject* el = NULL;
				_tmp9_ = _g_object_ref0 ((GObject*) el_it->data);
				el = _tmp9_;
				{
					SeahorseSshKey* key = NULL;
					GObject* _tmp10_;
					SeahorseSshKey* _tmp11_;
					SeahorseSshKey* _tmp12_;
					_tmp10_ = el;
					_tmp11_ = _g_object_ref0 (SEAHORSE_SSH_IS_KEY (_tmp10_) ? ((SeahorseSshKey*) _tmp10_) : NULL);
					key = _tmp11_;
					_tmp12_ = key;
					if (_tmp12_ != NULL) {
						SeahorseSshKey* _tmp13_;
						SeahorseSshKey* _tmp14_;
						_tmp13_ = key;
						_tmp14_ = _g_object_ref0 (_tmp13_);
						keys = g_list_prepend (keys, _tmp14_);
					}
					_g_object_unref0 (key);
					_g_object_unref0 (el);
				}
			}
			(el_collection == NULL) ? NULL : (el_collection = (_g_list_free__g_object_unref0_ (el_collection), NULL));
		}
	}
	_tmp15_ = keys;
	_tmp16_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
	_tmp17_ = _tmp16_;
	_tmp18_ = _tmp17_;
	seahorse_ssh_upload_prompt (_tmp15_, (GtkWindow*) _tmp18_);
	_g_object_unref0 (_tmp18_);
	(keys == NULL) ? NULL : (keys = (_g_list_free__g_object_unref0_ (keys), NULL));
}

static GObject *
seahorse_ssh_actions_constructor (GType type,
                                  guint n_construct_properties,
                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SeahorseSshActions * self;
	parent_class = G_OBJECT_CLASS (seahorse_ssh_actions_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_SSH_TYPE_ACTIONS, SeahorseSshActions);
	g_action_map_add_action_entries ((GActionMap*) self, SEAHORSE_SSH_ACTIONS_KEYS_ACTIONS, (gint) G_N_ELEMENTS (SEAHORSE_SSH_ACTIONS_KEYS_ACTIONS), self);
	return obj;
}

static void
seahorse_ssh_actions_class_init (SeahorseSshActionsClass * klass,
                                 gpointer klass_data)
{
	seahorse_ssh_actions_parent_class = g_type_class_peek_parent (klass);
	((SeahorseActionGroupClass *) klass)->set_actions_for_selected_objects = (void (*) (SeahorseActionGroup*, GList*)) seahorse_ssh_actions_real_set_actions_for_selected_objects;
	G_OBJECT_CLASS (klass)->constructor = seahorse_ssh_actions_constructor;
	G_OBJECT_CLASS (klass)->finalize = seahorse_ssh_actions_finalize;
}

static void
seahorse_ssh_actions_instance_init (SeahorseSshActions * self,
                                    gpointer klass)
{
}

static void
seahorse_ssh_actions_finalize (GObject * obj)
{
	SeahorseSshActions * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_SSH_TYPE_ACTIONS, SeahorseSshActions);
	G_OBJECT_CLASS (seahorse_ssh_actions_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
seahorse_ssh_actions_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseSshActionsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_ssh_actions_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseSshActions), 0, (GInstanceInitFunc) seahorse_ssh_actions_instance_init, NULL };
	GType seahorse_ssh_actions_type_id;
	seahorse_ssh_actions_type_id = g_type_register_static (SEAHORSE_TYPE_ACTION_GROUP, "SeahorseSshActions", &g_define_type_info, 0);
	return seahorse_ssh_actions_type_id;
}

GType
seahorse_ssh_actions_get_type (void)
{
	static volatile gsize seahorse_ssh_actions_type_id__once = 0;
	if (g_once_init_enter (&seahorse_ssh_actions_type_id__once)) {
		GType seahorse_ssh_actions_type_id;
		seahorse_ssh_actions_type_id = seahorse_ssh_actions_get_type_once ();
		g_once_init_leave (&seahorse_ssh_actions_type_id__once, seahorse_ssh_actions_type_id);
	}
	return seahorse_ssh_actions_type_id__once;
}

