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

/*  This file is part of corebird, a Gtk+ linux Twitter client.
 *  Copyright (C) 2013 Timm Bäder
 *
 *  corebird 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.
 *
 *  corebird 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 corebird.  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 TYPE_NEW_LIST_ENTRY (new_list_entry_get_type ())
#define NEW_LIST_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NEW_LIST_ENTRY, NewListEntry))
#define NEW_LIST_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NEW_LIST_ENTRY, NewListEntryClass))
#define IS_NEW_LIST_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NEW_LIST_ENTRY))
#define IS_NEW_LIST_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NEW_LIST_ENTRY))
#define NEW_LIST_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NEW_LIST_ENTRY, NewListEntryClass))

typedef struct _NewListEntry NewListEntry;
typedef struct _NewListEntryClass NewListEntryClass;
typedef struct _NewListEntryPrivate NewListEntryPrivate;
enum  {
	NEW_LIST_ENTRY_0_PROPERTY,
	NEW_LIST_ENTRY_NUM_PROPERTIES
};
static GParamSpec* new_list_entry_properties[NEW_LIST_ENTRY_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))
enum  {
	NEW_LIST_ENTRY_CREATE_ACTIVATED_SIGNAL,
	NEW_LIST_ENTRY_NUM_SIGNALS
};
static guint new_list_entry_signals[NEW_LIST_ENTRY_NUM_SIGNALS] = {0};

struct _NewListEntry {
	GtkListBoxRow parent_instance;
	NewListEntryPrivate * priv;
};

struct _NewListEntryClass {
	GtkListBoxRowClass parent_class;
};

struct _NewListEntryPrivate {
	GtkEntry* list_name_entry;
	GtkRevealer* revealer;
	GtkButton* create_list_button;
};


static gpointer new_list_entry_parent_class = NULL;

GType new_list_entry_get_type (void) G_GNUC_CONST;
#define NEW_LIST_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_NEW_LIST_ENTRY, NewListEntryPrivate))
void new_list_entry_reveal (NewListEntry* self);
void new_list_entry_unreveal (NewListEntry* self);
static void new_list_entry_create_list_button_clicked_cb (NewListEntry* self);
static void _new_list_entry_create_list_button_clicked_cb_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void new_list_entry_name_text_changed_cb (NewListEntry* self);
NewListEntry* new_list_entry_new (void);
NewListEntry* new_list_entry_construct (GType object_type);
static GObject * new_list_entry_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void _new_list_entry_name_text_changed_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void new_list_entry_finalize (GObject * obj);


void new_list_entry_reveal (NewListEntry* self) {
	GtkRevealer* _tmp0_;
	GtkEntry* _tmp1_;
	g_return_if_fail (IS_NEW_LIST_ENTRY (self));
	_tmp0_ = self->priv->revealer;
	gtk_revealer_set_reveal_child (_tmp0_, TRUE);
	gtk_list_box_row_set_activatable (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_list_box_row_get_type (), GtkListBoxRow), FALSE);
	_tmp1_ = self->priv->list_name_entry;
	gtk_widget_grab_focus (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget));
}


void new_list_entry_unreveal (NewListEntry* self) {
	GtkRevealer* _tmp0_;
	GtkEntry* _tmp1_;
	g_return_if_fail (IS_NEW_LIST_ENTRY (self));
	_tmp0_ = self->priv->revealer;
	gtk_revealer_set_reveal_child (_tmp0_, FALSE);
	gtk_list_box_row_set_activatable (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_list_box_row_get_type (), GtkListBoxRow), TRUE);
	_tmp1_ = self->priv->list_name_entry;
	gtk_entry_set_text (_tmp1_, "");
}


static void new_list_entry_create_list_button_clicked_cb (NewListEntry* self) {
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (IS_NEW_LIST_ENTRY (self));
	_tmp0_ = self->priv->list_name_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_emit (self, new_list_entry_signals[NEW_LIST_ENTRY_CREATE_ACTIVATED_SIGNAL], 0, _tmp2_);
}


static void _new_list_entry_create_list_button_clicked_cb_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	new_list_entry_create_list_button_clicked_cb ((NewListEntry*) self);
}


static gunichar string_get_char (const gchar* self, glong index) {
	gunichar result = 0U;
	glong _tmp0_;
	gunichar _tmp1_;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = index;
	_tmp1_ = g_utf8_get_char (((gchar*) self) + _tmp0_);
	result = _tmp1_;
	return result;
}


static void new_list_entry_name_text_changed_cb (NewListEntry* self) {
	gchar* name = NULL;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	GtkButton* _tmp4_;
	gboolean _tmp5_ = FALSE;
	const gchar* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	const gchar* _tmp11_;
	gunichar _tmp12_;
	gboolean _tmp13_;
	GtkButton* _tmp14_;
	g_return_if_fail (IS_NEW_LIST_ENTRY (self));
	_tmp0_ = self->priv->list_name_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	name = _tmp3_;
	_tmp4_ = self->priv->create_list_button;
	gtk_widget_set_sensitive (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_widget_get_type (), GtkWidget), FALSE);
	_tmp6_ = name;
	_tmp7_ = strlen (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_ == 0) {
		_tmp5_ = TRUE;
	} else {
		const gchar* _tmp9_;
		gint _tmp10_;
		_tmp9_ = name;
		_tmp10_ = g_utf8_strlen (_tmp9_, (gssize) -1);
		_tmp5_ = _tmp10_ > 25;
	}
	if (_tmp5_) {
		_g_free0 (name);
		return;
	}
	_tmp11_ = name;
	_tmp12_ = string_get_char (_tmp11_, (glong) 0);
	_tmp13_ = g_unichar_isdigit (_tmp12_);
	if (_tmp13_) {
		_g_free0 (name);
		return;
	}
	_tmp14_ = self->priv->create_list_button;
	gtk_widget_set_sensitive (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, gtk_widget_get_type (), GtkWidget), TRUE);
	_g_free0 (name);
}


NewListEntry* new_list_entry_construct (GType object_type) {
	NewListEntry * self = NULL;
	self = (NewListEntry*) g_object_new (object_type, NULL);
	return self;
}


NewListEntry* new_list_entry_new (void) {
	return new_list_entry_construct (TYPE_NEW_LIST_ENTRY);
}


static void _new_list_entry_name_text_changed_cb_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	new_list_entry_name_text_changed_cb ((NewListEntry*) self);
}


static GObject * new_list_entry_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	NewListEntry * self;
	GtkEntry* _tmp0_;
	GtkEntryBuffer* _tmp1_;
	GtkEntryBuffer* _tmp2_;
	parent_class = G_OBJECT_CLASS (new_list_entry_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_NEW_LIST_ENTRY, NewListEntry);
	_tmp0_ = self->priv->list_name_entry;
	_tmp1_ = gtk_entry_get_buffer (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, G_TYPE_OBJECT, GObject), "notify::text", (GCallback) _new_list_entry_name_text_changed_cb_g_object_notify, self, 0);
	return obj;
}


static void new_list_entry_class_init (NewListEntryClass * klass) {
	gint NewListEntry_private_offset;
	new_list_entry_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (NewListEntryPrivate));
	G_OBJECT_CLASS (klass)->constructor = new_list_entry_constructor;
	G_OBJECT_CLASS (klass)->finalize = new_list_entry_finalize;
	NewListEntry_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/baedert/corebird/ui/new-list-entry.ui");
	new_list_entry_signals[NEW_LIST_ENTRY_CREATE_ACTIVATED_SIGNAL] = g_signal_new ("create-activated", TYPE_NEW_LIST_ENTRY, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "list_name_entry", FALSE, NewListEntry_private_offset + G_STRUCT_OFFSET (NewListEntryPrivate, list_name_entry));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "revealer", FALSE, NewListEntry_private_offset + G_STRUCT_OFFSET (NewListEntryPrivate, revealer));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "create_list_button", FALSE, NewListEntry_private_offset + G_STRUCT_OFFSET (NewListEntryPrivate, create_list_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "create_list_button_clicked_cb", G_CALLBACK(_new_list_entry_create_list_button_clicked_cb_gtk_button_clicked));
}


static void new_list_entry_instance_init (NewListEntry * self) {
	self->priv = NEW_LIST_ENTRY_GET_PRIVATE (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void new_list_entry_finalize (GObject * obj) {
	NewListEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_NEW_LIST_ENTRY, NewListEntry);
	_g_object_unref0 (self->priv->list_name_entry);
	_g_object_unref0 (self->priv->revealer);
	_g_object_unref0 (self->priv->create_list_button);
	G_OBJECT_CLASS (new_list_entry_parent_class)->finalize (obj);
}


GType new_list_entry_get_type (void) {
	static volatile gsize new_list_entry_type_id__volatile = 0;
	if (g_once_init_enter (&new_list_entry_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (NewListEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) new_list_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NewListEntry), 0, (GInstanceInitFunc) new_list_entry_instance_init, NULL };
		GType new_list_entry_type_id;
		new_list_entry_type_id = g_type_register_static (gtk_list_box_row_get_type (), "NewListEntry", &g_define_type_info, 0);
		g_once_init_leave (&new_list_entry_type_id__volatile, new_list_entry_type_id);
	}
	return new_list_entry_type_id__volatile;
}



