/* collection-view-child.c generated by valac 0.56.3, 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>

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

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

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 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 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 __lambda15_ (ConnectionsCollectionViewChild* self);
VALA_EXTERN GdkPixbuf* connections_connection_get_thumbnail (ConnectionsConnection* self);
static gboolean ___lambda15__gsource_func (gpointer self);
static void connections_collection_view_child_finalize (GObject * obj);
static GType connections_collection_view_child_get_type_once (void);

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_;
	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);
	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
__lambda15_ (ConnectionsCollectionViewChild* self)
{
	ConnectionsConnection* _tmp0_;
	ConnectionsConnection* _tmp2_;
	GdkPixbuf* _tmp3_;
	GdkPixbuf* _tmp4_;
	GdkPixbuf* _tmp5_;
	gboolean _tmp6_;
	GdkPixbuf* pixbuf = NULL;
	ConnectionsConnection* _tmp7_;
	GdkPixbuf* _tmp8_;
	GdkPixbuf* _tmp9_;
	GdkPixbuf* _tmp10_;
	GdkPixbuf* _tmp11_;
	GdkPixbuf* _tmp12_;
	GtkImage* _tmp13_;
	GdkPixbuf* _tmp14_;
	gboolean result;
	self->priv->thumbnail_id = (guint) 0;
	_tmp0_ = self->connection;
	if (!_tmp0_->connected) {
		GtkImage* _tmp1_;
		_tmp1_ = self->thumbnail;
		gtk_image_set_from_icon_name (_tmp1_, "org.gnome.Connections-symbolic", (GtkIconSize) GTK_ICON_SIZE_LARGE_TOOLBAR);
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp2_ = self->connection;
	_tmp3_ = connections_connection_get_thumbnail (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_ == NULL;
	_g_object_unref0 (_tmp5_);
	if (_tmp6_) {
		result = G_SOURCE_REMOVE;
		return result;
	}
	_tmp7_ = self->connection;
	_tmp8_ = connections_connection_get_thumbnail (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp11_ = gdk_pixbuf_scale_simple (_tmp10_, 180, 134, GDK_INTERP_BILINEAR);
	_tmp12_ = _tmp11_;
	_g_object_unref0 (_tmp10_);
	pixbuf = _tmp12_;
	_tmp13_ = self->thumbnail;
	_tmp14_ = pixbuf;
	gtk_image_set_from_pixbuf (_tmp13_, _tmp14_);
	result = G_SOURCE_CONTINUE;
	_g_object_unref0 (pixbuf);
	return result;
}

static gboolean
___lambda15__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda15_ ((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, ___lambda15__gsource_func, g_object_ref (self), g_object_unref);
}

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

