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

/*
 * Copyright (c) 2011-2015 elementary LLC. (https://elementary.io)
 *
 * 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 "datetime.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <granite.h>
#include <glib-object.h>
#include <gio/gio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	DATE_TIME_WIDGETS_PANEL_LABEL_0_PROPERTY,
	DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY,
	DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY,
	DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY,
	DATE_TIME_WIDGETS_PANEL_LABEL_NUM_PROPERTIES
};
static GParamSpec* date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_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))

struct _DateTimeWidgetsPanelLabelPrivate {
	GtkLabel* date_label;
	GtkLabel* time_label;
	DateTimeServicesTimeManager* time_manager;
	gchar* _clock_format;
	gboolean _clock_show_seconds;
	gboolean _clock_show_weekday;
};

static gint DateTimeWidgetsPanelLabel_private_offset;
static gpointer date_time_widgets_panel_label_parent_class = NULL;

static void date_time_widgets_panel_label_update_labels (DateTimeWidgetsPanelLabel* self);
static GObject * date_time_widgets_panel_label_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static void _date_time_widgets_panel_label___lambda9_ (DateTimeWidgetsPanelLabel* self);
static void __date_time_widgets_panel_label___lambda9__g_object_notify (GObject* _sender,
                                                                 GParamSpec* pspec,
                                                                 gpointer self);
static void _date_time_widgets_panel_label_update_labels_date_time_services_time_manager_minute_changed (DateTimeServicesTimeManager* _sender,
                                                                                                  gpointer self);
static void _date_time_widgets_panel_label_update_labels_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void date_time_widgets_panel_label_finalize (GObject * obj);
static GType date_time_widgets_panel_label_get_type_once (void);
static void _vala_date_time_widgets_panel_label_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_date_time_widgets_panel_label_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec);

static inline gpointer
date_time_widgets_panel_label_get_instance_private (DateTimeWidgetsPanelLabel* self)
{
	return G_STRUCT_MEMBER_P (self, DateTimeWidgetsPanelLabel_private_offset);
}

static void
date_time_widgets_panel_label_update_labels (DateTimeWidgetsPanelLabel* self)
{
	gchar* date_format = NULL;
	const gchar* _tmp0_;
	GtkLabel* _tmp4_;
	DateTimeServicesTimeManager* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* time_format = NULL;
	DateTimeServicesTimeManager* _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	gchar* _tmp13_;
	GtkLabel* _tmp14_;
	DateTimeServicesTimeManager* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_clock_format;
	if (g_strcmp0 (_tmp0_, "ISO8601") == 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("%F");
		_g_free0 (date_format);
		date_format = _tmp1_;
	} else {
		gboolean _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->_clock_show_weekday;
		_tmp3_ = granite_date_time_get_default_date_format (_tmp2_, TRUE, FALSE);
		_g_free0 (date_format);
		date_format = _tmp3_;
	}
	_tmp4_ = self->priv->date_label;
	_tmp5_ = self->priv->time_manager;
	_tmp6_ = date_format;
	_tmp7_ = date_time_services_time_manager_format (_tmp5_, _tmp6_);
	_tmp8_ = _tmp7_;
	gtk_label_set_label (_tmp4_, _tmp8_);
	_g_free0 (_tmp8_);
	_tmp9_ = self->priv->time_manager;
	_tmp10_ = date_time_services_time_manager_get_is_12h (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->_clock_show_seconds;
	_tmp13_ = granite_date_time_get_default_time_format (_tmp11_, _tmp12_);
	time_format = _tmp13_;
	_tmp14_ = self->priv->time_label;
	_tmp15_ = self->priv->time_manager;
	_tmp16_ = date_time_services_time_manager_format (_tmp15_, time_format);
	_tmp17_ = _tmp16_;
	_tmp18_ = g_markup_printf_escaped ("<span font_features='tnum'>%s</span>", _tmp17_);
	_tmp19_ = _tmp18_;
	gtk_label_set_label (_tmp14_, _tmp19_);
	_g_free0 (_tmp19_);
	_g_free0 (_tmp17_);
	_g_free0 (time_format);
	_g_free0 (date_format);
}

DateTimeWidgetsPanelLabel*
date_time_widgets_panel_label_construct (GType object_type)
{
	DateTimeWidgetsPanelLabel * self = NULL;
	self = (DateTimeWidgetsPanelLabel*) g_object_new (object_type, NULL);
	return self;
}

DateTimeWidgetsPanelLabel*
date_time_widgets_panel_label_new (void)
{
	return date_time_widgets_panel_label_construct (DATE_TIME_WIDGETS_TYPE_PANEL_LABEL);
}

const gchar*
date_time_widgets_panel_label_get_clock_format (DateTimeWidgetsPanelLabel* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_clock_format;
	result = _tmp0_;
	return result;
}

void
date_time_widgets_panel_label_set_clock_format (DateTimeWidgetsPanelLabel* self,
                                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = date_time_widgets_panel_label_get_clock_format (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_clock_format);
		self->priv->_clock_format = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY]);
	}
}

gboolean
date_time_widgets_panel_label_get_clock_show_seconds (DateTimeWidgetsPanelLabel* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_clock_show_seconds;
	return result;
}

void
date_time_widgets_panel_label_set_clock_show_seconds (DateTimeWidgetsPanelLabel* self,
                                                      gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = date_time_widgets_panel_label_get_clock_show_seconds (self);
	if (old_value != value) {
		self->priv->_clock_show_seconds = value;
		g_object_notify_by_pspec ((GObject *) self, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY]);
	}
}

gboolean
date_time_widgets_panel_label_get_clock_show_weekday (DateTimeWidgetsPanelLabel* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_clock_show_weekday;
	return result;
}

void
date_time_widgets_panel_label_set_clock_show_weekday (DateTimeWidgetsPanelLabel* self,
                                                      gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = date_time_widgets_panel_label_get_clock_show_weekday (self);
	if (old_value != value) {
		self->priv->_clock_show_weekday = value;
		g_object_notify_by_pspec ((GObject *) self, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY]);
	}
}

static void
_date_time_widgets_panel_label___lambda9_ (DateTimeWidgetsPanelLabel* self)
{
	date_time_widgets_panel_label_update_labels (self);
}

static void
__date_time_widgets_panel_label___lambda9__g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self)
{
	_date_time_widgets_panel_label___lambda9_ ((DateTimeWidgetsPanelLabel*) self);
}

static void
_date_time_widgets_panel_label_update_labels_date_time_services_time_manager_minute_changed (DateTimeServicesTimeManager* _sender,
                                                                                             gpointer self)
{
	date_time_widgets_panel_label_update_labels ((DateTimeWidgetsPanelLabel*) self);
}

static void
_date_time_widgets_panel_label_update_labels_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	date_time_widgets_panel_label_update_labels ((DateTimeWidgetsPanelLabel*) self);
}

static GObject *
date_time_widgets_panel_label_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DateTimeWidgetsPanelLabel * self;
	GtkLabel* _tmp0_ = NULL;
	GtkRevealer* date_revealer = NULL;
	GtkRevealer* _tmp1_ = NULL;
	GtkRevealer* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_ = NULL;
	GtkRevealer* _tmp5_;
	GtkLabel* _tmp6_;
	GSettings* clock_settings = NULL;
	GSettings* _tmp7_;
	GSettings* _tmp8_;
	GSettings* _tmp9_;
	GSettings* _tmp10_;
	GtkRevealer* _tmp11_;
	GSettings* _tmp12_;
	DateTimeServicesTimeManager* _tmp13_;
	DateTimeServicesTimeManager* _tmp14_;
	DateTimeServicesTimeManager* _tmp15_;
	parent_class = G_OBJECT_CLASS (date_time_widgets_panel_label_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DATE_TIME_WIDGETS_TYPE_PANEL_LABEL, DateTimeWidgetsPanelLabel);
	_tmp0_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp0_, 12);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->date_label);
	self->priv->date_label = _tmp0_;
	_tmp1_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp1_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
	g_object_ref_sink (_tmp1_);
	date_revealer = _tmp1_;
	_tmp2_ = date_revealer;
	_tmp3_ = self->priv->date_label;
	gtk_container_add ((GtkContainer*) _tmp2_, (GtkWidget*) _tmp3_);
	_tmp4_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_label_set_use_markup (_tmp4_, TRUE);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->time_label);
	self->priv->time_label = _tmp4_;
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	_tmp5_ = date_revealer;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->time_label;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp6_);
	_tmp7_ = g_settings_new ("io.elementary.desktop.wingpanel.datetime");
	clock_settings = _tmp7_;
	_tmp8_ = clock_settings;
	g_settings_bind (_tmp8_, "clock-format", (GObject*) self, "clock-format", G_SETTINGS_BIND_DEFAULT);
	_tmp9_ = clock_settings;
	g_settings_bind (_tmp9_, "clock-show-seconds", (GObject*) self, "clock-show-seconds", G_SETTINGS_BIND_DEFAULT);
	_tmp10_ = clock_settings;
	_tmp11_ = date_revealer;
	g_settings_bind (_tmp10_, "clock-show-date", (GObject*) _tmp11_, "reveal_child", G_SETTINGS_BIND_DEFAULT);
	_tmp12_ = clock_settings;
	g_settings_bind (_tmp12_, "clock-show-weekday", (GObject*) self, "clock-show-weekday", G_SETTINGS_BIND_DEFAULT);
	g_signal_connect_object ((GObject*) self, "notify", (GCallback) __date_time_widgets_panel_label___lambda9__g_object_notify, self, 0);
	_tmp13_ = date_time_services_time_manager_get_default ();
	_g_object_unref0 (self->priv->time_manager);
	self->priv->time_manager = _tmp13_;
	_tmp14_ = self->priv->time_manager;
	g_signal_connect_object (_tmp14_, "minute-changed", (GCallback) _date_time_widgets_panel_label_update_labels_date_time_services_time_manager_minute_changed, self, 0);
	_tmp15_ = self->priv->time_manager;
	g_signal_connect_object ((GObject*) _tmp15_, "notify::is-12h", (GCallback) _date_time_widgets_panel_label_update_labels_g_object_notify, self, 0);
	_g_object_unref0 (clock_settings);
	_g_object_unref0 (date_revealer);
	return obj;
}

static void
date_time_widgets_panel_label_class_init (DateTimeWidgetsPanelLabelClass * klass,
                                          gpointer klass_data)
{
	date_time_widgets_panel_label_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DateTimeWidgetsPanelLabel_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_date_time_widgets_panel_label_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_date_time_widgets_panel_label_set_property;
	G_OBJECT_CLASS (klass)->constructor = date_time_widgets_panel_label_constructor;
	G_OBJECT_CLASS (klass)->finalize = date_time_widgets_panel_label_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY] = g_param_spec_string ("clock-format", "clock-format", "clock-format", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY] = g_param_spec_boolean ("clock-show-seconds", "clock-show-seconds", "clock-show-seconds", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY, date_time_widgets_panel_label_properties[DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY] = g_param_spec_boolean ("clock-show-weekday", "clock-show-weekday", "clock-show-weekday", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
date_time_widgets_panel_label_instance_init (DateTimeWidgetsPanelLabel * self,
                                             gpointer klass)
{
	self->priv = date_time_widgets_panel_label_get_instance_private (self);
}

static void
date_time_widgets_panel_label_finalize (GObject * obj)
{
	DateTimeWidgetsPanelLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DATE_TIME_WIDGETS_TYPE_PANEL_LABEL, DateTimeWidgetsPanelLabel);
	_g_object_unref0 (self->priv->date_label);
	_g_object_unref0 (self->priv->time_label);
	_g_object_unref0 (self->priv->time_manager);
	_g_free0 (self->priv->_clock_format);
	G_OBJECT_CLASS (date_time_widgets_panel_label_parent_class)->finalize (obj);
}

static GType
date_time_widgets_panel_label_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DateTimeWidgetsPanelLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) date_time_widgets_panel_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DateTimeWidgetsPanelLabel), 0, (GInstanceInitFunc) date_time_widgets_panel_label_instance_init, NULL };
	GType date_time_widgets_panel_label_type_id;
	date_time_widgets_panel_label_type_id = g_type_register_static (gtk_box_get_type (), "DateTimeWidgetsPanelLabel", &g_define_type_info, 0);
	DateTimeWidgetsPanelLabel_private_offset = g_type_add_instance_private (date_time_widgets_panel_label_type_id, sizeof (DateTimeWidgetsPanelLabelPrivate));
	return date_time_widgets_panel_label_type_id;
}

GType
date_time_widgets_panel_label_get_type (void)
{
	static volatile gsize date_time_widgets_panel_label_type_id__once = 0;
	if (g_once_init_enter (&date_time_widgets_panel_label_type_id__once)) {
		GType date_time_widgets_panel_label_type_id;
		date_time_widgets_panel_label_type_id = date_time_widgets_panel_label_get_type_once ();
		g_once_init_leave (&date_time_widgets_panel_label_type_id__once, date_time_widgets_panel_label_type_id);
	}
	return date_time_widgets_panel_label_type_id__once;
}

static void
_vala_date_time_widgets_panel_label_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	DateTimeWidgetsPanelLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DATE_TIME_WIDGETS_TYPE_PANEL_LABEL, DateTimeWidgetsPanelLabel);
	switch (property_id) {
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY:
		g_value_set_string (value, date_time_widgets_panel_label_get_clock_format (self));
		break;
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY:
		g_value_set_boolean (value, date_time_widgets_panel_label_get_clock_show_seconds (self));
		break;
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY:
		g_value_set_boolean (value, date_time_widgets_panel_label_get_clock_show_weekday (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_date_time_widgets_panel_label_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec)
{
	DateTimeWidgetsPanelLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DATE_TIME_WIDGETS_TYPE_PANEL_LABEL, DateTimeWidgetsPanelLabel);
	switch (property_id) {
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_FORMAT_PROPERTY:
		date_time_widgets_panel_label_set_clock_format (self, g_value_get_string (value));
		break;
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_SECONDS_PROPERTY:
		date_time_widgets_panel_label_set_clock_show_seconds (self, g_value_get_boolean (value));
		break;
		case DATE_TIME_WIDGETS_PANEL_LABEL_CLOCK_SHOW_WEEKDAY_PROPERTY:
		date_time_widgets_panel_label_set_clock_show_weekday (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

