/* collection-view-child.c generated by valac 0.56.19, the Vala compiler
 * generated from collection-view-child.vala, do not modify */

/* collection-view-child.vala
 *
 * Copyright (C) Red Hat, Inc
 *
 * 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 3 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: Felipe Borges <felipeborges@gnome.org>
 *
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD (connections_collection_view_child_get_type ())
#define CONNECTIONS_COLLECTION_VIEW_CHILD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, ConnectionsCollectionViewChild))
#define CONNECTIONS_COLLECTION_VIEW_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, ConnectionsCollectionViewChildClass))
#define CONNECTIONS_IS_COLLECTION_VIEW_CHILD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD))
#define CONNECTIONS_IS_COLLECTION_VIEW_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD))
#define CONNECTIONS_COLLECTION_VIEW_CHILD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, ConnectionsCollectionViewChildClass))

typedef struct _ConnectionsCollectionViewChild ConnectionsCollectionViewChild;
typedef struct _ConnectionsCollectionViewChildClass ConnectionsCollectionViewChildClass;
typedef struct _ConnectionsCollectionViewChildPrivate ConnectionsCollectionViewChildPrivate;

#define CONNECTIONS_TYPE_CONNECTION (connections_connection_get_type ())
#define CONNECTIONS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_CONNECTION, ConnectionsConnection))
#define CONNECTIONS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_CONNECTION, ConnectionsConnectionClass))
#define CONNECTIONS_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_CONNECTION))
#define CONNECTIONS_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_CONNECTION))
#define CONNECTIONS_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_CONNECTION, ConnectionsConnectionClass))

typedef struct _ConnectionsConnection ConnectionsConnection;
typedef struct _ConnectionsConnectionClass ConnectionsConnectionClass;
enum  {
	CONNECTIONS_COLLECTION_VIEW_CHILD_0_PROPERTY,
	CONNECTIONS_COLLECTION_VIEW_CHILD_NUM_PROPERTIES
};
static GParamSpec* connections_collection_view_child_properties[CONNECTIONS_COLLECTION_VIEW_CHILD_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ConnectionsConnectionPrivate ConnectionsConnectionPrivate;

#define CONNECTIONS_TYPE_APPLICATION (connections_application_get_type ())
#define CONNECTIONS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONNECTIONS_TYPE_APPLICATION, ConnectionsApplication))
#define CONNECTIONS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONNECTIONS_TYPE_APPLICATION, ConnectionsApplicationClass))
#define CONNECTIONS_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONNECTIONS_TYPE_APPLICATION))
#define CONNECTIONS_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONNECTIONS_TYPE_APPLICATION))
#define CONNECTIONS_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONNECTIONS_TYPE_APPLICATION, ConnectionsApplicationClass))

typedef struct _ConnectionsApplication ConnectionsApplication;
typedef struct _ConnectionsApplicationClass ConnectionsApplicationClass;

struct _ConnectionsCollectionViewChild {
	GtkBox parent_instance;
	ConnectionsCollectionViewChildPrivate * priv;
	ConnectionsConnection* connection;
	GtkImage* thumbnail;
};

struct _ConnectionsCollectionViewChildClass {
	GtkBoxClass parent_class;
};

struct _ConnectionsCollectionViewChildPrivate {
	GtkLabel* connection_name;
	guint thumbnail_id;
};

struct _ConnectionsConnection {
	GObject parent_instance;
	ConnectionsConnectionPrivate * priv;
	gchar* uuid;
	gboolean connected;
	gboolean need_password;
	gboolean need_username;
	gboolean need_domain;
};

struct _ConnectionsConnectionClass {
	GObjectClass parent_class;
	void (*send_keys) (ConnectionsConnection* self, guint* keys, gint keys_length1);
	void (*connect_it) (ConnectionsConnection* self);
	void (*disconnect_it) (ConnectionsConnection* self);
	void (*dispose_display) (ConnectionsConnection* self);
	GtkWidget* (*get_widget) (ConnectionsConnection* self);
	void (*set_widget) (ConnectionsConnection* self, GtkWidget* value);
	gboolean (*get_scaling) (ConnectionsConnection* self);
	void (*set_scaling) (ConnectionsConnection* self, gboolean value);
	gint (*get_port) (ConnectionsConnection* self);
	void (*set_port) (ConnectionsConnection* self, gint value);
	GdkPixbuf* (*get_thumbnail) (ConnectionsConnection* self);
	void (*set_thumbnail) (ConnectionsConnection* self, GdkPixbuf* value);
};

static gint ConnectionsCollectionViewChild_private_offset;
static gpointer connections_collection_view_child_parent_class = NULL;
VALA_EXTERN ConnectionsApplication* connections_application_application;

VALA_EXTERN GType connections_collection_view_child_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsCollectionViewChild, g_object_unref)
VALA_EXTERN GType connections_connection_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsConnection, g_object_unref)
VALA_EXTERN ConnectionsCollectionViewChild* connections_collection_view_child_new (ConnectionsConnection* connection);
VALA_EXTERN ConnectionsCollectionViewChild* connections_collection_view_child_construct (GType object_type,
                                                                             ConnectionsConnection* connection);
static void connections_collection_view_child_update_display_name (ConnectionsCollectionViewChild* self);
static void _connections_collection_view_child_update_display_name_g_object_notify (GObject* _sender,
                                                                             GParamSpec* pspec,
                                                                             gpointer self);
static gchar* connections_collection_view_child_get_default_thumbnail_icon (ConnectionsCollectionViewChild* self);
static void connections_collection_view_child_update_thumbnail (ConnectionsCollectionViewChild* self);
static void _connections_collection_view_child_update_thumbnail_connections_connection_show (ConnectionsConnection* _sender,
                                                                                      gpointer self);
VALA_EXTERN gchar* connections_connection_get_visible_name (ConnectionsConnection* self);
static gboolean __lambda18_ (ConnectionsCollectionViewChild* self);
VALA_EXTERN GdkPixbuf* connections_connection_get_thumbnail (ConnectionsConnection* self);
static gboolean ___lambda18__gsource_func (gpointer self);
VALA_EXTERN GType connections_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ConnectionsApplication, g_object_unref)
static void connections_collection_view_child_finalize (GObject * obj);
static GType connections_collection_view_child_get_type_once (void);
static void _vala_connections_collection_view_child_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec);

static inline gpointer
connections_collection_view_child_get_instance_private (ConnectionsCollectionViewChild* self)
{
	return G_STRUCT_MEMBER_P (self, ConnectionsCollectionViewChild_private_offset);
}

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

static void
_connections_collection_view_child_update_display_name_g_object_notify (GObject* _sender,
                                                                        GParamSpec* pspec,
                                                                        gpointer self)
{
	connections_collection_view_child_update_display_name ((ConnectionsCollectionViewChild*) self);
}

static void
_connections_collection_view_child_update_thumbnail_connections_connection_show (ConnectionsConnection* _sender,
                                                                                 gpointer self)
{
	connections_collection_view_child_update_thumbnail ((ConnectionsCollectionViewChild*) self);
}

ConnectionsCollectionViewChild*
connections_collection_view_child_construct (GType object_type,
                                             ConnectionsConnection* connection)
{
	ConnectionsCollectionViewChild * self = NULL;
	ConnectionsConnection* _tmp0_;
	GtkImage* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_val_if_fail (connection != NULL, NULL);
	self = (ConnectionsCollectionViewChild*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (connection);
	_g_object_unref0 (self->connection);
	self->connection = _tmp0_;
	connections_collection_view_child_update_display_name (self);
	g_signal_connect_object ((GObject*) connection, "notify::display-name", (GCallback) _connections_collection_view_child_update_display_name_g_object_notify, self, 0);
	_tmp1_ = self->thumbnail;
	_tmp2_ = connections_collection_view_child_get_default_thumbnail_icon (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = _tmp3_;
	g_object_set (_tmp1_, "icon-name", _tmp4_, NULL);
	_g_free0 (_tmp4_);
	g_signal_connect_object (connection, "show", (GCallback) _connections_collection_view_child_update_thumbnail_connections_connection_show, self, 0);
	return self;
}

ConnectionsCollectionViewChild*
connections_collection_view_child_new (ConnectionsConnection* connection)
{
	return connections_collection_view_child_construct (CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, connection);
}

static void
connections_collection_view_child_update_display_name (ConnectionsCollectionViewChild* self)
{
	GtkLabel* _tmp0_;
	ConnectionsConnection* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->connection_name;
	_tmp1_ = self->connection;
	_tmp2_ = connections_connection_get_visible_name (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_label_set_text (_tmp0_, _tmp3_);
	_g_free0 (_tmp3_);
}

static gboolean
__lambda18_ (ConnectionsCollectionViewChild* self)
{
	ConnectionsConnection* _tmp0_;
	ConnectionsConnection* _tmp5_;
	GdkPixbuf* _tmp6_;
	GdkPixbuf* _tmp7_;
	GdkPixbuf* _tmp8_;
	gboolean _tmp9_;
	GdkPixbuf* pixbuf = NULL;
	ConnectionsConnection* _tmp10_;
	GdkPixbuf* _tmp11_;
	GdkPixbuf* _tmp12_;
	GdkPixbuf* _tmp13_;
	GdkPixbuf* _tmp14_;
	GdkPixbuf* _tmp15_;
	GtkImage* _tmp16_;
	GdkPixbuf* _tmp17_;
	gboolean result;
	self->priv->thumbnail_id = (guint) 0;
	_tmp0_ = self->connection;
	if (!_tmp0_->connected) {
		GtkImage* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp1_ = self->thumbnail;
		_tmp2_ = connections_collection_view_child_get_default_thumbnail_icon (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		gtk_image_set_from_icon_name (_tmp1_, _tmp4_, (GtkIconSize) GTK_ICON_SIZE_LARGE_TOOLBAR);
		_g_free0 (_tmp4_);
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp5_ = self->connection;
	_tmp6_ = connections_connection_get_thumbnail (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp9_ = _tmp8_ == NULL;
	_g_object_unref0 (_tmp8_);
	if (_tmp9_) {
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp10_ = self->connection;
	_tmp11_ = connections_connection_get_thumbnail (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp14_ = gdk_pixbuf_scale_simple (_tmp13_, 180, 134, GDK_INTERP_BILINEAR);
	_tmp15_ = _tmp14_;
	_g_object_unref0 (_tmp13_);
	pixbuf = _tmp15_;
	_tmp16_ = self->thumbnail;
	_tmp17_ = pixbuf;
	gtk_image_set_from_pixbuf (_tmp16_, _tmp17_);
	result = G_SOURCE_CONTINUE;
	_g_object_unref0 (pixbuf);
	return result;
}

static gboolean
___lambda18__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda18_ ((ConnectionsCollectionViewChild*) self);
	return result;
}

static void
connections_collection_view_child_update_thumbnail (ConnectionsCollectionViewChild* self)
{
	g_return_if_fail (self != NULL);
	self->priv->thumbnail_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 3, ___lambda18__gsource_func, g_object_ref (self), g_object_unref);
}

static gchar*
connections_collection_view_child_get_default_thumbnail_icon (ConnectionsCollectionViewChild* self)
{
	gchar* result;
	ConnectionsApplication* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = connections_application_application;
	_tmp1_ = g_application_get_application_id ((GApplication*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf ("%s-symbolic", _tmp2_);
	result = _tmp3_;
	return result;
}

static void
connections_collection_view_child_class_init (ConnectionsCollectionViewChildClass * klass,
                                              gpointer klass_data)
{
	connections_collection_view_child_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ConnectionsCollectionViewChild_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_connections_collection_view_child_get_property;
	G_OBJECT_CLASS (klass)->finalize = connections_collection_view_child_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Connections/ui/collection-view-child.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "connection_name", FALSE, ConnectionsCollectionViewChild_private_offset + G_STRUCT_OFFSET (ConnectionsCollectionViewChildPrivate, connection_name));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "thumbnail", FALSE, G_STRUCT_OFFSET (ConnectionsCollectionViewChild, thumbnail));
}

static void
connections_collection_view_child_instance_init (ConnectionsCollectionViewChild * self,
                                                 gpointer klass)
{
	self->priv = connections_collection_view_child_get_instance_private (self);
	self->priv->thumbnail_id = (guint) 0;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
connections_collection_view_child_finalize (GObject * obj)
{
	ConnectionsCollectionViewChild * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, ConnectionsCollectionViewChild);
	if (self->priv->thumbnail_id != ((guint) 0)) {
		g_source_remove (self->priv->thumbnail_id);
	}
	self->priv->thumbnail_id = (guint) 0;
	_g_object_unref0 (self->connection);
	G_OBJECT_CLASS (connections_collection_view_child_parent_class)->finalize (obj);
}

static GType
connections_collection_view_child_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ConnectionsCollectionViewChildClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) connections_collection_view_child_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ConnectionsCollectionViewChild), 0, (GInstanceInitFunc) connections_collection_view_child_instance_init, NULL };
	GType connections_collection_view_child_type_id;
	connections_collection_view_child_type_id = g_type_register_static (gtk_box_get_type (), "ConnectionsCollectionViewChild", &g_define_type_info, 0);
	ConnectionsCollectionViewChild_private_offset = g_type_add_instance_private (connections_collection_view_child_type_id, sizeof (ConnectionsCollectionViewChildPrivate));
	return connections_collection_view_child_type_id;
}

GType
connections_collection_view_child_get_type (void)
{
	static volatile gsize connections_collection_view_child_type_id__once = 0;
	if (g_once_init_enter (&connections_collection_view_child_type_id__once)) {
		GType connections_collection_view_child_type_id;
		connections_collection_view_child_type_id = connections_collection_view_child_get_type_once ();
		g_once_init_leave (&connections_collection_view_child_type_id__once, connections_collection_view_child_type_id);
	}
	return connections_collection_view_child_type_id__once;
}

static void
_vala_connections_collection_view_child_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec)
{
	ConnectionsCollectionViewChild * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONNECTIONS_TYPE_COLLECTION_VIEW_CHILD, ConnectionsCollectionViewChild);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

