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

/*
 * Seahorse
 *
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2012 Stefan Walter
 *
 * 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/>.
 *
 * Author: Stef Walter <stefw@collabora.co.uk>
 */

#include "seahorse-common.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block7Data Block7Data;

struct _Block7Data {
	int _ref_count_;
	GObject* object;
};

static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void ___lambda9_ (Block7Data* _data7_);
static void ____lambda9__gtk_widget_destroy (GtkWidget* _sender,
                                      gpointer self);
static GType seahorse_viewable_get_type_once (void);

GtkWindow*
seahorse_viewable_create_viewer (SeahorseViewable* self,
                                 GtkWindow* parent)
{
	SeahorseViewableIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = SEAHORSE_VIEWABLE_GET_INTERFACE (self);
	if (_iface_->create_viewer) {
		return _iface_->create_viewer (self, parent);
	}
	return NULL;
}

gboolean
seahorse_viewable_can_view (GObject* object)
{
	gboolean result;
	g_return_val_if_fail (object != NULL, FALSE);
	result = SEAHORSE_IS_VIEWABLE (object);
	return result;
}

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

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		_g_object_unref0 (_data7_->object);
		g_slice_free (Block7Data, _data7_);
	}
}

static void
___lambda9_ (Block7Data* _data7_)
{
	g_object_set_data_full (_data7_->object, "viewable-window", NULL, NULL);
}

static void
____lambda9__gtk_widget_destroy (GtkWidget* _sender,
                                 gpointer self)
{
	___lambda9_ (self);
}

gboolean
seahorse_viewable_view (GObject* object,
                        GtkWindow* parent)
{
	Block7Data* _data7_;
	GObject* _tmp0_;
	GtkWindow* window = NULL;
	gconstpointer _tmp1_;
	GtkWindow* _tmp2_;
	GtkWindow* _tmp3_;
	GtkWindow* _tmp11_;
	GtkWindow* _tmp12_;
	gboolean result;
	g_return_val_if_fail (object != NULL, FALSE);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (object);
	_g_object_unref0 (_data7_->object);
	_data7_->object = _tmp0_;
	if (!seahorse_viewable_can_view (_data7_->object)) {
		result = FALSE;
		block7_data_unref (_data7_);
		_data7_ = NULL;
		return result;
	}
	window = NULL;
	_tmp1_ = g_object_get_data (_data7_->object, "viewable-window");
	_tmp2_ = _g_object_ref0 ((GtkWindow*) _tmp1_);
	_g_object_unref0 (window);
	window = _tmp2_;
	_tmp3_ = window;
	if (_tmp3_ == NULL) {
		SeahorseViewable* viewable = NULL;
		SeahorseViewable* _tmp4_;
		SeahorseViewable* _tmp5_;
		GtkWindow* _tmp6_;
		GtkWindow* _tmp7_;
		GtkWindow* _tmp8_;
		GtkWindow* _tmp9_;
		GtkWindow* _tmp10_;
		_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data7_->object, SEAHORSE_TYPE_VIEWABLE, SeahorseViewable));
		viewable = _tmp4_;
		_tmp5_ = viewable;
		_tmp6_ = seahorse_viewable_create_viewer (_tmp5_, parent);
		_g_object_unref0 (window);
		window = _tmp6_;
		_tmp7_ = window;
		if (_tmp7_ == NULL) {
			result = FALSE;
			_g_object_unref0 (viewable);
			_g_object_unref0 (window);
			block7_data_unref (_data7_);
			_data7_ = NULL;
			return result;
		}
		_tmp8_ = window;
		_tmp9_ = _g_object_ref0 (_tmp8_);
		g_object_set_data_full (_data7_->object, "viewable-window", _tmp9_, g_object_unref);
		_tmp10_ = window;
		g_signal_connect_data ((GtkWidget*) _tmp10_, "destroy", (GCallback) ____lambda9__gtk_widget_destroy, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
		_g_object_unref0 (viewable);
	}
	_tmp11_ = window;
	gtk_window_present (_tmp11_);
	_tmp12_ = window;
	gtk_widget_show ((GtkWidget*) _tmp12_);
	result = TRUE;
	_g_object_unref0 (window);
	block7_data_unref (_data7_);
	_data7_ = NULL;
	return result;
}

static void
seahorse_viewable_default_init (SeahorseViewableIface * iface,
                                gpointer iface_data)
{
}

 G_GNUC_NO_INLINE static GType
seahorse_viewable_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseViewableIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_viewable_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType seahorse_viewable_type_id;
	seahorse_viewable_type_id = g_type_register_static (G_TYPE_INTERFACE, "SeahorseViewable", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (seahorse_viewable_type_id, G_TYPE_OBJECT);
	return seahorse_viewable_type_id;
}

GType
seahorse_viewable_get_type (void)
{
	static volatile gsize seahorse_viewable_type_id__once = 0;
	if (g_once_init_enter (&seahorse_viewable_type_id__once)) {
		GType seahorse_viewable_type_id;
		seahorse_viewable_type_id = seahorse_viewable_get_type_once ();
		g_once_init_leave (&seahorse_viewable_type_id__once, seahorse_viewable_type_id);
	}
	return seahorse_viewable_type_id__once;
}

