/* actions.c generated by valac 0.56.1, 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>

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)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

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 GVariant* _variant_new1 (const gchar* value);
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 GVariant*
_variant_new1 (const gchar* value)
{
	return g_variant_ref_sink (g_variant_new_string (value));
}

static void
seahorse_ssh_actions_on_ssh_generate_key (SeahorseSshActions* self,
                                          GSimpleAction* action,
                                          GVariant* param)
{
	SeahorseSshGenerate* generate_dialog = NULL;
	SeahorseSshBackend* _tmp0_;
	SeahorseSshBackend* _tmp1_;
	SeahorseSshSource* _tmp2_;
	SeahorseSshSource* _tmp3_;
	SeahorseCatalog* _tmp4_;
	SeahorseCatalog* _tmp5_;
	SeahorseCatalog* _tmp6_;
	SeahorseSshGenerate* _tmp7_;
	SeahorseSshGenerate* _tmp8_;
	gint response = 0;
	SeahorseSshGenerate* _tmp9_;
	SeahorseSshGenerate* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_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_);
	generate_dialog = _tmp8_;
	_tmp9_ = generate_dialog;
	response = gtk_dialog_run ((GtkDialog*) _tmp9_);
	if (response == ((gint) GTK_RESPONSE_ACCEPT)) {
		SeahorseCatalog* _tmp10_;
		SeahorseCatalog* _tmp11_;
		SeahorseCatalog* _tmp12_;
		GVariant* _tmp13_;
		_tmp10_ = seahorse_action_group_get_catalog ((SeahorseActionGroup*) self);
		_tmp11_ = _tmp10_;
		_tmp12_ = _tmp11_;
		_tmp13_ = _variant_new1 ("openssh");
		g_action_group_activate_action ((GActionGroup*) _tmp12_, "focus-place", _tmp13_);
		_g_variant_unref0 (_tmp13_);
		_g_object_unref0 (_tmp12_);
	}
	_tmp14_ = generate_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp14_);
	_g_object_unref0 (generate_dialog);
}

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;
}

