/* MessageRevealer.c generated by valac 0.32.1, the Vala compiler
 * generated from MessageRevealer.vala, do not modify */

/*
 * This file is part of budgie-desktop
 *
 * Copyright (C) 2015-2016 Solus Project
 *
 * 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.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_MESSAGE_REVEALER (message_revealer_get_type ())
#define MESSAGE_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MESSAGE_REVEALER, MessageRevealer))
#define MESSAGE_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MESSAGE_REVEALER, MessageRevealerClass))
#define IS_MESSAGE_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MESSAGE_REVEALER))
#define IS_MESSAGE_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MESSAGE_REVEALER))
#define MESSAGE_REVEALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MESSAGE_REVEALER, MessageRevealerClass))

typedef struct _MessageRevealer MessageRevealer;
typedef struct _MessageRevealerClass MessageRevealerClass;
typedef struct _MessageRevealerPrivate MessageRevealerPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;

struct _MessageRevealer {
	GtkRevealer parent_instance;
	MessageRevealerPrivate * priv;
};

struct _MessageRevealerClass {
	GtkRevealerClass parent_class;
};

struct _MessageRevealerPrivate {
	GtkInfoBar* info_bar;
	GtkLabel* message_label;
	guint expire_id;
};

struct _Block1Data {
	int _ref_count_;
	MessageRevealer* self;
	gulong connection;
};


static gpointer message_revealer_parent_class = NULL;
static GType message_revealer_type_id = 0;

GType message_revealer_get_type (void) G_GNUC_CONST;
GType message_revealer_register_type (GTypeModule * module);
#define MESSAGE_REVEALER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MESSAGE_REVEALER, MessageRevealerPrivate))
enum  {
	MESSAGE_REVEALER_DUMMY_PROPERTY
};
MessageRevealer* message_revealer_new (void);
MessageRevealer* message_revealer_construct (GType object_type);
static void message_revealer_show_it (MessageRevealer* self);
static gboolean message_revealer_hide_it (MessageRevealer* self);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda4_ (MessageRevealer* self);
static void ___lambda4__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static gboolean __lambda5_ (Block1Data* _data1_);
static gboolean ___lambda5__gsource_func (gpointer self);
void message_revealer_set_content (MessageRevealer* self, const gchar* message, GtkMessageType message_type);
static gboolean _message_revealer_hide_it_gsource_func (gpointer self);
static void message_revealer_finalize (GObject* obj);


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


MessageRevealer* message_revealer_construct (GType object_type) {
	MessageRevealer * self = NULL;
	GtkInfoBar* _tmp0_ = NULL;
	GtkInfoBar* _tmp1_ = NULL;
	GtkStyleContext* _tmp2_ = NULL;
	GtkInfoBar* _tmp3_ = NULL;
	GtkLabel* _tmp4_ = NULL;
	GtkLabel* _tmp5_ = NULL;
	GtkLabel* _tmp6_ = NULL;
	GtkLabel* _tmp7_ = NULL;
	GtkContainer* info_bar_container = NULL;
	GtkInfoBar* _tmp8_ = NULL;
	GtkContainer* _tmp9_ = NULL;
	GtkContainer* _tmp10_ = NULL;
	GtkLabel* _tmp11_ = NULL;
	self = (MessageRevealer*) g_object_new (object_type, "visible", FALSE, NULL);
	_tmp0_ = (GtkInfoBar*) gtk_info_bar_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->info_bar);
	self->priv->info_bar = _tmp0_;
	_tmp1_ = self->priv->info_bar;
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) _tmp1_);
	gtk_style_context_add_class (_tmp2_, "message-bar");
	_tmp3_ = self->priv->info_bar;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp3_);
	_tmp4_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->message_label);
	self->priv->message_label = _tmp4_;
	_tmp5_ = self->priv->message_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_START);
	_tmp6_ = self->priv->message_label;
	gtk_label_set_line_wrap (_tmp6_, TRUE);
	_tmp7_ = self->priv->message_label;
	gtk_label_set_max_width_chars (_tmp7_, 35);
	_tmp8_ = self->priv->info_bar;
	_tmp9_ = gtk_info_bar_get_content_area (_tmp8_);
	_tmp10_ = _g_object_ref0 (_tmp9_);
	info_bar_container = _tmp10_;
	_tmp11_ = self->priv->message_label;
	gtk_container_add (info_bar_container, (GtkWidget*) _tmp11_);
	_g_object_unref0 (info_bar_container);
	return self;
}


MessageRevealer* message_revealer_new (void) {
	return message_revealer_construct (TYPE_MESSAGE_REVEALER);
}


static void message_revealer_show_it (MessageRevealer* self) {
	g_return_if_fail (self != NULL);
	gtk_widget_set_no_show_all ((GtkWidget*) self, FALSE);
	gtk_widget_show_all ((GtkWidget*) self);
	gtk_revealer_set_reveal_child ((GtkRevealer*) self, TRUE);
}


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		MessageRevealer* self;
		self = _data1_->self;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}


static void __lambda4_ (MessageRevealer* self) {
	gtk_widget_set_no_show_all ((GtkWidget*) self, TRUE);
	gtk_widget_hide ((GtkWidget*) self);
}


static void ___lambda4__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	__lambda4_ ((MessageRevealer*) self);
}


static gboolean __lambda5_ (Block1Data* _data1_) {
	MessageRevealer* self;
	gboolean result = FALSE;
	self = _data1_->self;
	g_signal_handler_disconnect ((GObject*) self, _data1_->connection);
	result = FALSE;
	return result;
}


static gboolean ___lambda5__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda5_ (self);
	return result;
}


static gboolean message_revealer_hide_it (MessageRevealer* self) {
	gboolean result = FALSE;
	Block1Data* _data1_;
	gulong _tmp0_ = 0UL;
	g_return_val_if_fail (self != NULL, FALSE);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	self->priv->expire_id = (guint) 0;
	_tmp0_ = g_signal_connect_object ((GObject*) self, "notify::child-revealed", (GCallback) ___lambda4__g_object_notify, self, G_CONNECT_AFTER);
	_data1_->connection = _tmp0_;
	gtk_revealer_set_reveal_child ((GtkRevealer*) self, FALSE);
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, ___lambda5__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	result = FALSE;
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}


static gboolean _message_revealer_hide_it_gsource_func (gpointer self) {
	gboolean result;
	result = message_revealer_hide_it ((MessageRevealer*) self);
	return result;
}


void message_revealer_set_content (MessageRevealer* self, const gchar* message, GtkMessageType message_type) {
	GtkLabel* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GtkInfoBar* _tmp2_ = NULL;
	GtkMessageType _tmp3_ = 0;
	guint _tmp4_ = 0U;
	guint _tmp6_ = 0U;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = self->priv->message_label;
	_tmp1_ = message;
	gtk_label_set_text (_tmp0_, _tmp1_);
	_tmp2_ = self->priv->info_bar;
	_tmp3_ = message_type;
	gtk_info_bar_set_message_type (_tmp2_, _tmp3_);
	message_revealer_show_it (self);
	_tmp4_ = self->priv->expire_id;
	if (_tmp4_ != ((guint) 0)) {
		guint _tmp5_ = 0U;
		_tmp5_ = self->priv->expire_id;
		g_source_remove (_tmp5_);
	}
	_tmp6_ = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 5000, _message_revealer_hide_it_gsource_func, g_object_ref (self), g_object_unref);
	self->priv->expire_id = _tmp6_;
}


static void message_revealer_class_init (MessageRevealerClass * klass) {
	message_revealer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MessageRevealerPrivate));
	G_OBJECT_CLASS (klass)->finalize = message_revealer_finalize;
}


static void message_revealer_instance_init (MessageRevealer * self) {
	self->priv = MESSAGE_REVEALER_GET_PRIVATE (self);
	self->priv->expire_id = (guint) 0;
}


static void message_revealer_finalize (GObject* obj) {
	MessageRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MESSAGE_REVEALER, MessageRevealer);
	_g_object_unref0 (self->priv->info_bar);
	_g_object_unref0 (self->priv->message_label);
	G_OBJECT_CLASS (message_revealer_parent_class)->finalize (obj);
}


GType message_revealer_get_type (void) {
	return message_revealer_type_id;
}


GType message_revealer_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (MessageRevealerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) message_revealer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MessageRevealer), 0, (GInstanceInitFunc) message_revealer_instance_init, NULL };
	message_revealer_type_id = g_type_module_register_type (module, gtk_revealer_get_type (), "MessageRevealer", &g_define_type_info, 0);
	return message_revealer_type_id;
}



