/* contacts-in-app-notification.c generated by valac 0.38.7, the Vala compiler
 * generated from contacts-in-app-notification.vala, do not modify */

/*
 * Copyright (C) 2017 Niels De Graef <nielsdegraef@gmail.com>
 *
 * 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 <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>


#define CONTACTS_TYPE_IN_APP_NOTIFICATION (contacts_in_app_notification_get_type ())
#define CONTACTS_IN_APP_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotification))
#define CONTACTS_IN_APP_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotificationClass))
#define CONTACTS_IS_IN_APP_NOTIFICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_IN_APP_NOTIFICATION))
#define CONTACTS_IS_IN_APP_NOTIFICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_IN_APP_NOTIFICATION))
#define CONTACTS_IN_APP_NOTIFICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotificationClass))

typedef struct _ContactsInAppNotification ContactsInAppNotification;
typedef struct _ContactsInAppNotificationClass ContactsInAppNotificationClass;
typedef struct _ContactsInAppNotificationPrivate ContactsInAppNotificationPrivate;
enum  {
	CONTACTS_IN_APP_NOTIFICATION_0_PROPERTY,
	CONTACTS_IN_APP_NOTIFICATION_MESSAGE_LABEL_PROPERTY,
	CONTACTS_IN_APP_NOTIFICATION_NUM_PROPERTIES
};
static GParamSpec* contacts_in_app_notification_properties[CONTACTS_IN_APP_NOTIFICATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	CONTACTS_IN_APP_NOTIFICATION_DISMISSED_SIGNAL,
	CONTACTS_IN_APP_NOTIFICATION_NUM_SIGNALS
};
static guint contacts_in_app_notification_signals[CONTACTS_IN_APP_NOTIFICATION_NUM_SIGNALS] = {0};

struct _ContactsInAppNotification {
	GtkRevealer parent_instance;
	ContactsInAppNotificationPrivate * priv;
};

struct _ContactsInAppNotificationClass {
	GtkRevealerClass parent_class;
};

struct _ContactsInAppNotificationPrivate {
	GtkGrid* grid;
	GtkLabel* label;
};


static gpointer contacts_in_app_notification_parent_class = NULL;

GType contacts_in_app_notification_get_type (void) G_GNUC_CONST;
#define CONTACTS_IN_APP_NOTIFICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotificationPrivate))
#define CONTACTS_IN_APP_NOTIFICATION_DEFAULT_KEEPALIVE ((guint) 5)
ContactsInAppNotification* contacts_in_app_notification_new (const gchar* message, GtkButton* button);
ContactsInAppNotification* contacts_in_app_notification_construct (GType object_type, const gchar* message, GtkButton* button);
static void contacts_in_app_notification_on_child_revealed_changed (ContactsInAppNotification* self, GObject* o, GParamSpec* p);
static void _contacts_in_app_notification_on_child_revealed_changed_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
void contacts_in_app_notification_show (ContactsInAppNotification* self);
static gboolean __lambda71_ (ContactsInAppNotification* self);
void contacts_in_app_notification_dismiss (ContactsInAppNotification* self);
static gboolean ___lambda71__gsource_func (gpointer self);
static void contacts_in_app_notification_on_close_button_clicked (ContactsInAppNotification* self, GtkButton* close_button);
static void _contacts_in_app_notification_on_close_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self);
GtkLabel* contacts_in_app_notification_get_message_label (ContactsInAppNotification* self);
static void contacts_in_app_notification_finalize (GObject * obj);
static void _vala_contacts_in_app_notification_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);


/**
   * Creates an in-app notification with the given message, and an accompanying button if not null.
   */
static void _contacts_in_app_notification_on_child_revealed_changed_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	contacts_in_app_notification_on_child_revealed_changed ((ContactsInAppNotification*) self, _sender, pspec);
}


ContactsInAppNotification* contacts_in_app_notification_construct (GType object_type, const gchar* message, GtkButton* button) {
	ContactsInAppNotification * self = NULL;
	GtkLabel* _tmp0_;
	const gchar* _tmp1_;
	GtkButton* _tmp2_;
	g_return_val_if_fail (message != NULL, NULL);
	self = (ContactsInAppNotification*) g_object_new (object_type, NULL);
	_tmp0_ = self->priv->label;
	_tmp1_ = message;
	gtk_label_set_label (_tmp0_, _tmp1_);
	_tmp2_ = button;
	if (_tmp2_ != NULL) {
		GtkGrid* _tmp3_;
		GtkButton* _tmp4_;
		GtkButton* _tmp5_;
		_tmp3_ = self->priv->grid;
		_tmp4_ = button;
		gtk_grid_attach (_tmp3_, (GtkWidget*) _tmp4_, 1, 0, 1, 1);
		_tmp5_ = button;
		gtk_widget_show ((GtkWidget*) _tmp5_);
	}
	g_signal_connect_object ((GObject*) self, "notify::child-revealed", (GCallback) _contacts_in_app_notification_on_child_revealed_changed_g_object_notify, self, 0);
	return self;
}


ContactsInAppNotification* contacts_in_app_notification_new (const gchar* message, GtkButton* button) {
	return contacts_in_app_notification_construct (CONTACTS_TYPE_IN_APP_NOTIFICATION, message, button);
}


static gboolean __lambda71_ (ContactsInAppNotification* self) {
	gboolean result = FALSE;
	contacts_in_app_notification_dismiss (self);
	result = FALSE;
	return result;
}


static gboolean ___lambda71__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda71_ ((ContactsInAppNotification*) self);
	return result;
}


void contacts_in_app_notification_show (ContactsInAppNotification* self) {
	g_return_if_fail (self != NULL);
	GTK_WIDGET_CLASS (contacts_in_app_notification_parent_class)->show ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_revealer_get_type (), GtkRevealer));
	gtk_revealer_set_reveal_child ((GtkRevealer*) self, TRUE);
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, CONTACTS_IN_APP_NOTIFICATION_DEFAULT_KEEPALIVE, ___lambda71__gsource_func, g_object_ref (self), g_object_unref);
}


void contacts_in_app_notification_dismiss (ContactsInAppNotification* self) {
	g_return_if_fail (self != NULL);
	gtk_revealer_set_reveal_child ((GtkRevealer*) self, FALSE);
}


static void contacts_in_app_notification_on_child_revealed_changed (ContactsInAppNotification* self, GObject* o, GParamSpec* p) {
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (o != NULL);
	g_return_if_fail (p != NULL);
	_tmp0_ = gtk_revealer_get_child_revealed ((GtkRevealer*) self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		g_signal_emit (self, contacts_in_app_notification_signals[CONTACTS_IN_APP_NOTIFICATION_DISMISSED_SIGNAL], 0);
		gtk_widget_destroy ((GtkWidget*) self);
	}
}


static void contacts_in_app_notification_on_close_button_clicked (ContactsInAppNotification* self, GtkButton* close_button) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (close_button != NULL);
	contacts_in_app_notification_dismiss (self);
}


static void _contacts_in_app_notification_on_close_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	contacts_in_app_notification_on_close_button_clicked ((ContactsInAppNotification*) self, _sender);
}


GtkLabel* contacts_in_app_notification_get_message_label (ContactsInAppNotification* self) {
	GtkLabel* result;
	GtkLabel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->label;
	result = _tmp0_;
	return result;
}


static void contacts_in_app_notification_class_init (ContactsInAppNotificationClass * klass) {
	gint ContactsInAppNotification_private_offset;
	contacts_in_app_notification_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ContactsInAppNotificationPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_contacts_in_app_notification_get_property;
	G_OBJECT_CLASS (klass)->finalize = contacts_in_app_notification_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CONTACTS_IN_APP_NOTIFICATION_MESSAGE_LABEL_PROPERTY, contacts_in_app_notification_properties[CONTACTS_IN_APP_NOTIFICATION_MESSAGE_LABEL_PROPERTY] = g_param_spec_object ("message-label", "message-label", "message-label", gtk_label_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	ContactsInAppNotification_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/contacts/ui/contacts-in-app-notification.ui");
	/**
	   * Fired when the notification is completely dismissed (i.e. gone).
	   */
	contacts_in_app_notification_signals[CONTACTS_IN_APP_NOTIFICATION_DISMISSED_SIGNAL] = g_signal_new ("dismissed", CONTACTS_TYPE_IN_APP_NOTIFICATION, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "grid", FALSE, ContactsInAppNotification_private_offset + G_STRUCT_OFFSET (ContactsInAppNotificationPrivate, grid));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label", FALSE, ContactsInAppNotification_private_offset + G_STRUCT_OFFSET (ContactsInAppNotificationPrivate, label));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_close_button_clicked", G_CALLBACK(_contacts_in_app_notification_on_close_button_clicked_gtk_button_clicked));
}


static void contacts_in_app_notification_instance_init (ContactsInAppNotification * self) {
	self->priv = CONTACTS_IN_APP_NOTIFICATION_GET_PRIVATE (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void contacts_in_app_notification_finalize (GObject * obj) {
	ContactsInAppNotification * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotification);
	_g_object_unref0 (self->priv->grid);
	_g_object_unref0 (self->priv->label);
	G_OBJECT_CLASS (contacts_in_app_notification_parent_class)->finalize (obj);
}


GType contacts_in_app_notification_get_type (void) {
	static volatile gsize contacts_in_app_notification_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_in_app_notification_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsInAppNotificationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_in_app_notification_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsInAppNotification), 0, (GInstanceInitFunc) contacts_in_app_notification_instance_init, NULL };
		GType contacts_in_app_notification_type_id;
		contacts_in_app_notification_type_id = g_type_register_static (gtk_revealer_get_type (), "ContactsInAppNotification", &g_define_type_info, 0);
		g_once_init_leave (&contacts_in_app_notification_type_id__volatile, contacts_in_app_notification_type_id);
	}
	return contacts_in_app_notification_type_id__volatile;
}


static void _vala_contacts_in_app_notification_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	ContactsInAppNotification * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CONTACTS_TYPE_IN_APP_NOTIFICATION, ContactsInAppNotification);
	switch (property_id) {
		case CONTACTS_IN_APP_NOTIFICATION_MESSAGE_LABEL_PROPERTY:
		g_value_set_object (value, contacts_in_app_notification_get_message_label (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



