/* gkr-keyring-add.c generated by valac 0.56.1, the Vala compiler
 * generated from gkr-keyring-add.vala, do not modify */

/*
 * Seahorse
 *
 * Copyright (C) 2008 Stefan Walter
 * Copyright (C) 2011 Collabora Ltd.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "seahorse-gkr.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <libsecret/secret.h>
#include <stdlib.h>
#include <string.h>
#include "seahorse-common.h"
#include <glib/gi18n-lib.h>

enum  {
	SEAHORSE_GKR_KEYRING_ADD_0_PROPERTY,
	SEAHORSE_GKR_KEYRING_ADD_NUM_PROPERTIES
};
static GParamSpec* seahorse_gkr_keyring_add_properties[SEAHORSE_GKR_KEYRING_ADD_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _SeahorseGkrKeyringAddPrivate {
	GtkEntry* name_entry;
};

static gint SeahorseGkrKeyringAdd_private_offset;
static gpointer seahorse_gkr_keyring_add_parent_class = NULL;

static void seahorse_gkr_keyring_add_real_response (GtkDialog* base,
                                             gint resp);
static void __lambda15_ (SeahorseGkrKeyringAdd* self,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda15__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void seahorse_gkr_keyring_add_on_name_entry_changed (SeahorseGkrKeyringAdd* self,
                                                     GtkEditable* editable);
static void _seahorse_gkr_keyring_add_on_name_entry_changed_gtk_editable_changed (GtkEditable* _sender,
                                                                           gpointer self);
static GObject * seahorse_gkr_keyring_add_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static void seahorse_gkr_keyring_add_finalize (GObject * obj);
static GType seahorse_gkr_keyring_add_get_type_once (void);

static inline gpointer
seahorse_gkr_keyring_add_get_instance_private (SeahorseGkrKeyringAdd* self)
{
	return G_STRUCT_MEMBER_P (self, SeahorseGkrKeyringAdd_private_offset);
}

SeahorseGkrKeyringAdd*
seahorse_gkr_keyring_add_construct (GType object_type,
                                    GtkWindow* parent)
{
	SeahorseGkrKeyringAdd * self = NULL;
	self = (SeahorseGkrKeyringAdd*) g_object_new (object_type, "transient-for", parent, "use-header-bar", 1, NULL);
	return self;
}

SeahorseGkrKeyringAdd*
seahorse_gkr_keyring_add_new (GtkWindow* parent)
{
	return seahorse_gkr_keyring_add_construct (SEAHORSE_GKR_TYPE_KEYRING_ADD, parent);
}

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

static void
__lambda15_ (SeahorseGkrKeyringAdd* self,
             GObject* obj,
             GAsyncResult* res)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (res != NULL);
	seahorse_gkr_dialog_complete_request ((GtkWidget*) self, FALSE);
	{
		SecretCollection* _tmp0_;
		SecretCollection* _tmp1_;
		_tmp0_ = secret_collection_create_finish (res, &_inner_error0_);
		_tmp1_ = _tmp0_;
		_g_object_unref0 (_tmp1_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = err;
		_tmp3_ = _tmp2_->message;
		seahorse_util_show_error ((GtkWidget*) self, _ ("Couldn’t add keyring"), _tmp3_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	gtk_widget_destroy ((GtkWidget*) self);
}

static void
___lambda15__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda15_ ((SeahorseGkrKeyringAdd*) self, source_object, res);
	g_object_unref (self);
}

static void
seahorse_gkr_keyring_add_real_response (GtkDialog* base,
                                        gint resp)
{
	SeahorseGkrKeyringAdd * self;
	GCancellable* cancellable = NULL;
	GCancellable* _tmp0_;
	SecretService* service = NULL;
	SeahorseGkrBackend* _tmp1_;
	SeahorseGkrBackend* _tmp2_;
	SecretService* _tmp3_;
	SecretService* _tmp4_;
	SecretService* _tmp5_;
	SecretService* _tmp6_;
	SecretService* _tmp7_;
	GtkEntry* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	GCancellable* _tmp11_;
	self = (SeahorseGkrKeyringAdd*) base;
	if (resp != ((gint) GTK_RESPONSE_ACCEPT)) {
		gtk_widget_destroy ((GtkWidget*) self);
		return;
	}
	_tmp0_ = seahorse_gkr_dialog_begin_request ((GtkWidget*) self);
	cancellable = _tmp0_;
	_tmp1_ = seahorse_gkr_backend_instance ();
	_tmp2_ = _tmp1_;
	_tmp3_ = seahorse_gkr_backend_get_service (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp2_);
	service = _tmp6_;
	_tmp7_ = service;
	_tmp8_ = self->priv->name_entry;
	_tmp9_ = gtk_entry_get_text (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = cancellable;
	secret_collection_create (_tmp7_, _tmp10_, NULL, 0, _tmp11_, ___lambda15__gasync_ready_callback, g_object_ref (self));
	_g_object_unref0 (service);
	_g_object_unref0 (cancellable);
}

static void
seahorse_gkr_keyring_add_on_name_entry_changed (SeahorseGkrKeyringAdd* self,
                                                GtkEditable* editable)
{
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (editable != NULL);
	_tmp0_ = self->priv->name_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	gtk_dialog_set_response_sensitive ((GtkDialog*) self, (gint) GTK_RESPONSE_ACCEPT, g_strcmp0 (_tmp2_, "") != 0);
}

static void
_seahorse_gkr_keyring_add_on_name_entry_changed_gtk_editable_changed (GtkEditable* _sender,
                                                                      gpointer self)
{
	seahorse_gkr_keyring_add_on_name_entry_changed ((SeahorseGkrKeyringAdd*) self, _sender);
}

static GObject *
seahorse_gkr_keyring_add_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SeahorseGkrKeyringAdd * self;
	parent_class = G_OBJECT_CLASS (seahorse_gkr_keyring_add_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_GKR_TYPE_KEYRING_ADD, SeahorseGkrKeyringAdd);
	gtk_dialog_set_response_sensitive ((GtkDialog*) self, (gint) GTK_RESPONSE_ACCEPT, FALSE);
	return obj;
}

static void
seahorse_gkr_keyring_add_class_init (SeahorseGkrKeyringAddClass * klass,
                                     gpointer klass_data)
{
	seahorse_gkr_keyring_add_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SeahorseGkrKeyringAdd_private_offset);
	((GtkDialogClass *) klass)->response = (void (*) (GtkDialog*, gint)) seahorse_gkr_keyring_add_real_response;
	G_OBJECT_CLASS (klass)->constructor = seahorse_gkr_keyring_add_constructor;
	G_OBJECT_CLASS (klass)->finalize = seahorse_gkr_keyring_add_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Seahorse/seahorse-gkr-add-keyring.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "name_entry", FALSE, SeahorseGkrKeyringAdd_private_offset + G_STRUCT_OFFSET (SeahorseGkrKeyringAddPrivate, name_entry));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_name_entry_changed", G_CALLBACK(_seahorse_gkr_keyring_add_on_name_entry_changed_gtk_editable_changed));
}

static void
seahorse_gkr_keyring_add_instance_init (SeahorseGkrKeyringAdd * self,
                                        gpointer klass)
{
	self->priv = seahorse_gkr_keyring_add_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
seahorse_gkr_keyring_add_finalize (GObject * obj)
{
	SeahorseGkrKeyringAdd * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_GKR_TYPE_KEYRING_ADD, SeahorseGkrKeyringAdd);
	G_OBJECT_CLASS (seahorse_gkr_keyring_add_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
seahorse_gkr_keyring_add_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseGkrKeyringAddClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_gkr_keyring_add_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseGkrKeyringAdd), 0, (GInstanceInitFunc) seahorse_gkr_keyring_add_instance_init, NULL };
	GType seahorse_gkr_keyring_add_type_id;
	seahorse_gkr_keyring_add_type_id = g_type_register_static (gtk_dialog_get_type (), "SeahorseGkrKeyringAdd", &g_define_type_info, 0);
	SeahorseGkrKeyringAdd_private_offset = g_type_add_instance_private (seahorse_gkr_keyring_add_type_id, sizeof (SeahorseGkrKeyringAddPrivate));
	return seahorse_gkr_keyring_add_type_id;
}

GType
seahorse_gkr_keyring_add_get_type (void)
{
	static volatile gsize seahorse_gkr_keyring_add_type_id__once = 0;
	if (g_once_init_enter (&seahorse_gkr_keyring_add_type_id__once)) {
		GType seahorse_gkr_keyring_add_type_id;
		seahorse_gkr_keyring_add_type_id = seahorse_gkr_keyring_add_get_type_once ();
		g_once_init_leave (&seahorse_gkr_keyring_add_type_id__once, seahorse_gkr_keyring_add_type_id);
	}
	return seahorse_gkr_keyring_add_type_id__once;
}

