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

/* Copyright 2015 Switchboard Locale Plug Developers
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser 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/.
*/

#include "locale-plug.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <locale.h>
#include "monetary.h"
#include <float.h>
#include <math.h>

enum  {
	SWITCHBOARD_PLUG_LOCALE_WIDGETS_PREVIEW_0_PROPERTY,
	SWITCHBOARD_PLUG_LOCALE_WIDGETS_PREVIEW_NUM_PROPERTIES
};
static GParamSpec* switchboard_plug_locale_widgets_preview_properties[SWITCHBOARD_PLUG_LOCALE_WIDGETS_PREVIEW_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))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

struct _SwitchboardPlugLocaleWidgetsPreviewPrivate {
	GtkLabel* date_time_label;
	GtkLabel* date_label;
	GtkLabel* time_label;
	GtkLabel* currency_label;
	GtkLabel* number_label;
};

static gint SwitchboardPlugLocaleWidgetsPreview_private_offset;
static gpointer switchboard_plug_locale_widgets_preview_parent_class = NULL;

static GObject * switchboard_plug_locale_widgets_preview_constructor (GType type,
                                                               guint n_construct_properties,
                                                               GObjectConstructParam * construct_properties);
static void switchboard_plug_locale_widgets_preview_finalize (GObject * obj);
static GType switchboard_plug_locale_widgets_preview_get_type_once (void);

static inline gpointer
switchboard_plug_locale_widgets_preview_get_instance_private (SwitchboardPlugLocaleWidgetsPreview* self)
{
	return G_STRUCT_MEMBER_P (self, SwitchboardPlugLocaleWidgetsPreview_private_offset);
}

SwitchboardPlugLocaleWidgetsPreview*
switchboard_plug_locale_widgets_preview_construct (GType object_type)
{
	SwitchboardPlugLocaleWidgetsPreview * self = NULL;
	self = (SwitchboardPlugLocaleWidgetsPreview*) g_object_new (object_type, "row-spacing", 12, NULL);
	return self;
}

SwitchboardPlugLocaleWidgetsPreview*
switchboard_plug_locale_widgets_preview_new (void)
{
	return switchboard_plug_locale_widgets_preview_construct (SWITCHBOARD_PLUG_LOCALE_WIDGETS_TYPE_PREVIEW);
}

void
switchboard_plug_locale_widgets_preview_reload_languages (SwitchboardPlugLocaleWidgetsPreview* self,
                                                          const gchar* format)
{
	GDateTime* date = NULL;
	GDateTime* _tmp0_;
	GtkLabel* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar currency[20] = {0};
	GtkLabel* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GtkLabel* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GtkLabel* _tmp12_;
	GtkLabel* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (format != NULL);
	setlocale (LC_ALL, format);
	_tmp0_ = g_date_time_new_now_local ();
	date = _tmp0_;
	_tmp1_ = self->priv->date_time_label;
	_tmp2_ = g_date_time_format (date, "%c");
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf ("%s", _tmp3_);
	_tmp5_ = _tmp4_;
	gtk_label_set_label (_tmp1_, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	strfmon (currency, (gint) 20, "%5.2n", 1234.56);
	_tmp6_ = self->priv->date_label;
	_tmp7_ = g_date_time_format (date, "%x");
	_tmp8_ = _tmp7_;
	gtk_label_set_label (_tmp6_, _tmp8_);
	_g_free0 (_tmp8_);
	_tmp9_ = self->priv->time_label;
	_tmp10_ = g_date_time_format (date, "%X");
	_tmp11_ = _tmp10_;
	gtk_label_set_label (_tmp9_, _tmp11_);
	_g_free0 (_tmp11_);
	_tmp12_ = self->priv->currency_label;
	gtk_label_set_label (_tmp12_, (const gchar*) currency);
	_tmp13_ = self->priv->number_label;
	_tmp14_ = g_strdup_printf ("%'.2f", 1234.56);
	_tmp15_ = _tmp14_;
	gtk_label_set_label (_tmp13_, _tmp15_);
	_g_free0 (_tmp15_);
	_g_date_time_unref0 (date);
}

static GObject *
switchboard_plug_locale_widgets_preview_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SwitchboardPlugLocaleWidgetsPreview * self;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* _tmp11_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp12_;
	GtkGrid* _tmp13_;
	GtkGrid* _tmp14_;
	GtkLabel* _tmp15_;
	GtkGrid* _tmp16_;
	GtkLabel* _tmp17_;
	GtkGrid* _tmp18_;
	GtkLabel* _tmp19_;
	GtkGrid* _tmp20_;
	GtkLabel* _tmp21_;
	GtkLabel* _tmp22_;
	GtkGrid* _tmp23_;
	parent_class = G_OBJECT_CLASS (switchboard_plug_locale_widgets_preview_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_LOCALE_WIDGETS_TYPE_PREVIEW, SwitchboardPlugLocaleWidgetsPreview);
	_tmp0_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->date_time_label);
	self->priv->date_time_label = _tmp0_;
	_tmp1_ = self->priv->date_time_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp1_, TRUE);
	_tmp2_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->date_label);
	self->priv->date_label = _tmp2_;
	_tmp3_ = self->priv->date_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp3_, TRUE);
	_tmp4_ = self->priv->date_label;
	gtk_label_set_xalign (_tmp4_, (gfloat) 0);
	_tmp5_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->time_label);
	self->priv->time_label = _tmp5_;
	_tmp6_ = self->priv->time_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp6_, TRUE);
	_tmp7_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->currency_label);
	self->priv->currency_label = _tmp7_;
	_tmp8_ = self->priv->currency_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp8_, TRUE);
	_tmp9_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->number_label);
	self->priv->number_label = _tmp9_;
	_tmp10_ = self->priv->number_label;
	gtk_widget_set_hexpand ((GtkWidget*) _tmp10_, TRUE);
	_tmp11_ = self->priv->number_label;
	gtk_label_set_xalign (_tmp11_, (gfloat) 1);
	_tmp12_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp12_);
	grid = _tmp12_;
	_tmp13_ = grid;
	gtk_grid_set_column_spacing (_tmp13_, 6);
	_tmp14_ = grid;
	_tmp15_ = self->priv->date_label;
	gtk_container_add ((GtkContainer*) _tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = grid;
	_tmp17_ = self->priv->time_label;
	gtk_container_add ((GtkContainer*) _tmp16_, (GtkWidget*) _tmp17_);
	_tmp18_ = grid;
	_tmp19_ = self->priv->currency_label;
	gtk_container_add ((GtkContainer*) _tmp18_, (GtkWidget*) _tmp19_);
	_tmp20_ = grid;
	_tmp21_ = self->priv->number_label;
	gtk_container_add ((GtkContainer*) _tmp20_, (GtkWidget*) _tmp21_);
	_tmp22_ = self->priv->date_time_label;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp22_, 0, 0, 1, 1);
	_tmp23_ = grid;
	gtk_grid_attach ((GtkGrid*) self, (GtkWidget*) _tmp23_, 0, 1, 1, 1);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (grid);
	return obj;
}

static void
switchboard_plug_locale_widgets_preview_class_init (SwitchboardPlugLocaleWidgetsPreviewClass * klass,
                                                    gpointer klass_data)
{
	switchboard_plug_locale_widgets_preview_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SwitchboardPlugLocaleWidgetsPreview_private_offset);
	G_OBJECT_CLASS (klass)->constructor = switchboard_plug_locale_widgets_preview_constructor;
	G_OBJECT_CLASS (klass)->finalize = switchboard_plug_locale_widgets_preview_finalize;
}

static void
switchboard_plug_locale_widgets_preview_instance_init (SwitchboardPlugLocaleWidgetsPreview * self,
                                                       gpointer klass)
{
	self->priv = switchboard_plug_locale_widgets_preview_get_instance_private (self);
}

static void
switchboard_plug_locale_widgets_preview_finalize (GObject * obj)
{
	SwitchboardPlugLocaleWidgetsPreview * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWITCHBOARD_PLUG_LOCALE_WIDGETS_TYPE_PREVIEW, SwitchboardPlugLocaleWidgetsPreview);
	_g_object_unref0 (self->priv->date_time_label);
	_g_object_unref0 (self->priv->date_label);
	_g_object_unref0 (self->priv->time_label);
	_g_object_unref0 (self->priv->currency_label);
	_g_object_unref0 (self->priv->number_label);
	G_OBJECT_CLASS (switchboard_plug_locale_widgets_preview_parent_class)->finalize (obj);
}

static GType
switchboard_plug_locale_widgets_preview_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SwitchboardPlugLocaleWidgetsPreviewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) switchboard_plug_locale_widgets_preview_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwitchboardPlugLocaleWidgetsPreview), 0, (GInstanceInitFunc) switchboard_plug_locale_widgets_preview_instance_init, NULL };
	GType switchboard_plug_locale_widgets_preview_type_id;
	switchboard_plug_locale_widgets_preview_type_id = g_type_register_static (gtk_grid_get_type (), "SwitchboardPlugLocaleWidgetsPreview", &g_define_type_info, 0);
	SwitchboardPlugLocaleWidgetsPreview_private_offset = g_type_add_instance_private (switchboard_plug_locale_widgets_preview_type_id, sizeof (SwitchboardPlugLocaleWidgetsPreviewPrivate));
	return switchboard_plug_locale_widgets_preview_type_id;
}

GType
switchboard_plug_locale_widgets_preview_get_type (void)
{
	static volatile gsize switchboard_plug_locale_widgets_preview_type_id__once = 0;
	if (g_once_init_enter (&switchboard_plug_locale_widgets_preview_type_id__once)) {
		GType switchboard_plug_locale_widgets_preview_type_id;
		switchboard_plug_locale_widgets_preview_type_id = switchboard_plug_locale_widgets_preview_get_type_once ();
		g_once_init_leave (&switchboard_plug_locale_widgets_preview_type_id__once, switchboard_plug_locale_widgets_preview_type_id);
	}
	return switchboard_plug_locale_widgets_preview_type_id__once;
}

