/* world-row.c generated by valac 0.56.3, the Vala compiler
 * generated from world-row.vala, do not modify */

/*
 * Copyright (C) 2013  Paolo Borelli <pborelli@gnome.org>
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <adwaita.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.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 CLOCKS_WORLD_TYPE_ROW (clocks_world_row_get_type ())
#define CLOCKS_WORLD_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_WORLD_TYPE_ROW, ClocksWorldRow))
#define CLOCKS_WORLD_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_WORLD_TYPE_ROW, ClocksWorldRowClass))
#define CLOCKS_WORLD_IS_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_WORLD_TYPE_ROW))
#define CLOCKS_WORLD_IS_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_WORLD_TYPE_ROW))
#define CLOCKS_WORLD_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_WORLD_TYPE_ROW, ClocksWorldRowClass))

typedef struct _ClocksWorldRow ClocksWorldRow;
typedef struct _ClocksWorldRowClass ClocksWorldRowClass;
typedef struct _ClocksWorldRowPrivate ClocksWorldRowPrivate;

#define CLOCKS_WORLD_TYPE_ITEM (clocks_world_item_get_type ())
#define CLOCKS_WORLD_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_WORLD_TYPE_ITEM, ClocksWorldItem))
#define CLOCKS_WORLD_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_WORLD_TYPE_ITEM, ClocksWorldItemClass))
#define CLOCKS_WORLD_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_WORLD_TYPE_ITEM))
#define CLOCKS_WORLD_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_WORLD_TYPE_ITEM))
#define CLOCKS_WORLD_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_WORLD_TYPE_ITEM, ClocksWorldItemClass))

typedef struct _ClocksWorldItem ClocksWorldItem;
typedef struct _ClocksWorldItemClass ClocksWorldItemClass;
enum  {
	CLOCKS_WORLD_ROW_0_PROPERTY,
	CLOCKS_WORLD_ROW_LOCATION_PROPERTY,
	CLOCKS_WORLD_ROW_NUM_PROPERTIES
};
static GParamSpec* clocks_world_row_properties[CLOCKS_WORLD_ROW_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  {
	CLOCKS_WORLD_ROW_REMOVE_CLOCK_SIGNAL,
	CLOCKS_WORLD_ROW_NUM_SIGNALS
};
static guint clocks_world_row_signals[CLOCKS_WORLD_ROW_NUM_SIGNALS] = {0};

struct _ClocksWorldRow {
	AdwActionRow parent_instance;
	ClocksWorldRowPrivate * priv;
};

struct _ClocksWorldRowClass {
	AdwActionRowClass parent_class;
};

struct _ClocksWorldRowPrivate {
	ClocksWorldItem* _location;
	GtkLabel* time_label;
	GtkWidget* delete_button;
};

static gint ClocksWorldRow_private_offset;
static gpointer clocks_world_row_parent_class = NULL;

VALA_EXTERN GType clocks_world_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClocksWorldRow, g_object_unref)
VALA_EXTERN GType clocks_world_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClocksWorldItem, g_object_unref)
VALA_EXTERN ClocksWorldRow* clocks_world_row_new (ClocksWorldItem* location);
VALA_EXTERN ClocksWorldRow* clocks_world_row_construct (GType object_type,
                                            ClocksWorldItem* location);
static void clocks_world_row_update (ClocksWorldRow* self);
static void _clocks_world_row_update_clocks_world_item_tick (ClocksWorldItem* _sender,
                                                      gpointer self);
VALA_EXTERN ClocksWorldItem* clocks_world_row_get_location (ClocksWorldRow* self);
VALA_EXTERN const gchar* clocks_world_item_get_state_class (ClocksWorldItem* self);
VALA_EXTERN gchar* clocks_utils_get_time_difference_message (gdouble offset);
VALA_EXTERN GTimeSpan clocks_world_item_get_local_offset (ClocksWorldItem* self);
VALA_EXTERN const gchar* clocks_world_item_get_day_label (ClocksWorldItem* self);
VALA_EXTERN gboolean clocks_world_item_get_automatic (ClocksWorldItem* self);
VALA_EXTERN gchar* clocks_world_item_get_time_label (ClocksWorldItem* self);
static void clocks_world_row_delete (ClocksWorldRow* self);
static void _clocks_world_row_delete_gtk_button_clicked (GtkButton* _sender,
                                                  gpointer self);
VALA_EXTERN void clocks_world_row_set_location (ClocksWorldRow* self,
                                    ClocksWorldItem* value);
static void clocks_world_row_finalize (GObject * obj);
static GType clocks_world_row_get_type_once (void);
static void _vala_clocks_world_row_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_clocks_world_row_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
clocks_world_row_get_instance_private (ClocksWorldRow* self)
{
	return G_STRUCT_MEMBER_P (self, ClocksWorldRow_private_offset);
}

static void
_clocks_world_row_update_clocks_world_item_tick (ClocksWorldItem* _sender,
                                                 gpointer self)
{
	clocks_world_row_update ((ClocksWorldRow*) self);
}

ClocksWorldRow*
clocks_world_row_construct (GType object_type,
                            ClocksWorldItem* location)
{
	ClocksWorldRow * self = NULL;
	g_return_val_if_fail (location != NULL, NULL);
	self = (ClocksWorldRow*) g_object_new (object_type, "location", location, NULL);
	g_object_bind_property_with_closures ((GObject*) location, "city-name", (GObject*) self, "title", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	g_signal_connect_object (location, "tick", (GCallback) _clocks_world_row_update_clocks_world_item_tick, self, 0);
	clocks_world_row_update (self);
	return self;
}

ClocksWorldRow*
clocks_world_row_new (ClocksWorldItem* location)
{
	return clocks_world_row_construct (CLOCKS_WORLD_TYPE_ROW, location);
}

static void
clocks_world_row_update (ClocksWorldRow* self)
{
	ClocksWorldItem* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* message = NULL;
	ClocksWorldItem* _tmp3_;
	GTimeSpan _tmp4_;
	GTimeSpan _tmp5_;
	gchar* _tmp6_;
	gboolean _tmp7_ = FALSE;
	ClocksWorldItem* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	GtkLabel* _tmp32_;
	ClocksWorldItem* _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	g_return_if_fail (self != NULL);
	gtk_widget_remove_css_class ((GtkWidget*) self, "night");
	gtk_widget_remove_css_class ((GtkWidget*) self, "astro");
	gtk_widget_remove_css_class ((GtkWidget*) self, "naut");
	gtk_widget_remove_css_class ((GtkWidget*) self, "civil");
	gtk_widget_remove_css_class ((GtkWidget*) self, "day");
	_tmp0_ = self->priv->_location;
	_tmp1_ = clocks_world_item_get_state_class (_tmp0_);
	_tmp2_ = _tmp1_;
	gtk_widget_add_css_class ((GtkWidget*) self, _tmp2_);
	_tmp3_ = self->priv->_location;
	_tmp4_ = clocks_world_item_get_local_offset (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = clocks_utils_get_time_difference_message ((gdouble) _tmp5_);
	message = _tmp6_;
	_tmp8_ = self->priv->_location;
	_tmp9_ = clocks_world_item_get_day_label (_tmp8_);
	_tmp10_ = _tmp9_;
	if (_tmp10_ != NULL) {
		ClocksWorldItem* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		_tmp11_ = self->priv->_location;
		_tmp12_ = clocks_world_item_get_day_label (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp7_ = g_strcmp0 (_tmp13_, "") != 0;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		ClocksWorldItem* _tmp14_;
		const gchar* _tmp15_;
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		GtkWidget* _tmp20_;
		GtkWidget* _tmp21_;
		_tmp14_ = self->priv->_location;
		_tmp15_ = clocks_world_item_get_day_label (_tmp14_);
		_tmp16_ = _tmp15_;
		_tmp17_ = message;
		_tmp18_ = g_strdup_printf ("%s • %s", (const gchar*) _tmp16_, _tmp17_);
		_tmp19_ = _tmp18_;
		adw_action_row_set_subtitle ((AdwActionRow*) self, _tmp19_);
		_g_free0 (_tmp19_);
		_tmp20_ = self->priv->delete_button;
		gtk_widget_set_sensitive (_tmp20_, TRUE);
		_tmp21_ = self->priv->delete_button;
		gtk_widget_remove_css_class (_tmp21_, "hidden");
	} else {
		ClocksWorldItem* _tmp22_;
		gboolean _tmp23_;
		gboolean _tmp24_;
		_tmp22_ = self->priv->_location;
		_tmp23_ = clocks_world_item_get_automatic (_tmp22_);
		_tmp24_ = _tmp23_;
		if (_tmp24_) {
			GtkWidget* _tmp25_;
			GtkWidget* _tmp26_;
			adw_action_row_set_subtitle ((AdwActionRow*) self, _ ("Current location"));
			_tmp25_ = self->priv->delete_button;
			gtk_widget_set_sensitive (_tmp25_, FALSE);
			_tmp26_ = self->priv->delete_button;
			gtk_widget_add_css_class (_tmp26_, "hidden");
		} else {
			const gchar* _tmp27_;
			gchar* _tmp28_;
			gchar* _tmp29_;
			GtkWidget* _tmp30_;
			GtkWidget* _tmp31_;
			_tmp27_ = message;
			_tmp28_ = g_strdup_printf ("%s", _tmp27_);
			_tmp29_ = _tmp28_;
			adw_action_row_set_subtitle ((AdwActionRow*) self, _tmp29_);
			_g_free0 (_tmp29_);
			_tmp30_ = self->priv->delete_button;
			gtk_widget_set_sensitive (_tmp30_, TRUE);
			_tmp31_ = self->priv->delete_button;
			gtk_widget_remove_css_class (_tmp31_, "hidden");
		}
	}
	_tmp32_ = self->priv->time_label;
	_tmp33_ = self->priv->_location;
	_tmp34_ = clocks_world_item_get_time_label (_tmp33_);
	_tmp35_ = _tmp34_;
	_tmp36_ = _tmp35_;
	gtk_label_set_label (_tmp32_, _tmp36_);
	_g_free0 (_tmp36_);
	_g_free0 (message);
}

static void
clocks_world_row_delete (ClocksWorldRow* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, clocks_world_row_signals[CLOCKS_WORLD_ROW_REMOVE_CLOCK_SIGNAL], 0);
}

static void
_clocks_world_row_delete_gtk_button_clicked (GtkButton* _sender,
                                             gpointer self)
{
	clocks_world_row_delete ((ClocksWorldRow*) self);
}

ClocksWorldItem*
clocks_world_row_get_location (ClocksWorldRow* self)
{
	ClocksWorldItem* result;
	ClocksWorldItem* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_location;
	result = _tmp0_;
	return result;
}

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

void
clocks_world_row_set_location (ClocksWorldRow* self,
                               ClocksWorldItem* value)
{
	ClocksWorldItem* old_value;
	g_return_if_fail (self != NULL);
	old_value = clocks_world_row_get_location (self);
	if (old_value != value) {
		ClocksWorldItem* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_location);
		self->priv->_location = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, clocks_world_row_properties[CLOCKS_WORLD_ROW_LOCATION_PROPERTY]);
	}
}

static void
clocks_world_row_class_init (ClocksWorldRowClass * klass,
                             gpointer klass_data)
{
	clocks_world_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ClocksWorldRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_clocks_world_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_clocks_world_row_set_property;
	G_OBJECT_CLASS (klass)->finalize = clocks_world_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CLOCKS_WORLD_ROW_LOCATION_PROPERTY, clocks_world_row_properties[CLOCKS_WORLD_ROW_LOCATION_PROPERTY] = g_param_spec_object ("location", "location", "location", CLOCKS_WORLD_TYPE_ITEM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/clocks/ui/world-row.ui");
	clocks_world_row_signals[CLOCKS_WORLD_ROW_REMOVE_CLOCK_SIGNAL] = g_signal_new ("remove-clock", CLOCKS_WORLD_TYPE_ROW, 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), "time_label", FALSE, ClocksWorldRow_private_offset + G_STRUCT_OFFSET (ClocksWorldRowPrivate, time_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "delete_button", FALSE, ClocksWorldRow_private_offset + G_STRUCT_OFFSET (ClocksWorldRowPrivate, delete_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "delete", G_CALLBACK(_clocks_world_row_delete_gtk_button_clicked));
}

static void
clocks_world_row_instance_init (ClocksWorldRow * self,
                                gpointer klass)
{
	self->priv = clocks_world_row_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
clocks_world_row_finalize (GObject * obj)
{
	ClocksWorldRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CLOCKS_WORLD_TYPE_ROW, ClocksWorldRow);
	_g_object_unref0 (self->priv->_location);
	G_OBJECT_CLASS (clocks_world_row_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
clocks_world_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ClocksWorldRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) clocks_world_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ClocksWorldRow), 0, (GInstanceInitFunc) clocks_world_row_instance_init, NULL };
	GType clocks_world_row_type_id;
	clocks_world_row_type_id = g_type_register_static (adw_action_row_get_type (), "ClocksWorldRow", &g_define_type_info, 0);
	ClocksWorldRow_private_offset = g_type_add_instance_private (clocks_world_row_type_id, sizeof (ClocksWorldRowPrivate));
	return clocks_world_row_type_id;
}

GType
clocks_world_row_get_type (void)
{
	static volatile gsize clocks_world_row_type_id__once = 0;
	if (g_once_init_enter (&clocks_world_row_type_id__once)) {
		GType clocks_world_row_type_id;
		clocks_world_row_type_id = clocks_world_row_get_type_once ();
		g_once_init_leave (&clocks_world_row_type_id__once, clocks_world_row_type_id);
	}
	return clocks_world_row_type_id__once;
}

static void
_vala_clocks_world_row_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	ClocksWorldRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CLOCKS_WORLD_TYPE_ROW, ClocksWorldRow);
	switch (property_id) {
		case CLOCKS_WORLD_ROW_LOCATION_PROPERTY:
		g_value_set_object (value, clocks_world_row_get_location (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_clocks_world_row_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	ClocksWorldRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CLOCKS_WORLD_TYPE_ROW, ClocksWorldRow);
	switch (property_id) {
		case CLOCKS_WORLD_ROW_LOCATION_PROPERTY:
		clocks_world_row_set_location (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

