/* progress-bar.c generated by valac 0.56.18, the Vala compiler
 * generated from progress-bar.vala, do not modify */

/*
 *  Copyright (c) 2019 Johannes Marbach <n0-0ne+xfce@mailbox.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 "xfmpc.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.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  {
	XFMPC_PROGRESS_BAR_0_PROPERTY,
	XFMPC_PROGRESS_BAR_NUM_PROPERTIES
};
static GParamSpec* xfmpc_progress_bar_properties[XFMPC_PROGRESS_BAR_NUM_PROPERTIES];
typedef enum  {
	XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_PERCENTAGE,
	XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_TEXT,
	XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_BACKGROUND,
	XFMPC_PROGRESS_BAR_COLUMNS_N_COLUMNS
} XfmpcProgressBarColumns;

#define XFMPC_PROGRESS_BAR_TYPE_COLUMNS (xfmpc_progress_bar_columns_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _XfmpcProgressBarPrivate {
	GtkTreeView* treeview;
	GtkListStore* store;
	GtkTreeIter iter;
};

static gint XfmpcProgressBar_private_offset;
static gpointer xfmpc_progress_bar_parent_class = NULL;

static GType xfmpc_progress_bar_columns_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void xfmpc_progress_bar_cb_hierarchy_changed (XfmpcProgressBar* self,
                                              GtkWidget* widget,
                                              GtkWidget* previous_toplevel);
static void xfmpc_progress_bar_update_background_color (XfmpcProgressBar* self);
static void xfmpc_progress_bar_cb_style_updated (XfmpcProgressBar* self,
                                          GtkWidget* widget);
static GObject * xfmpc_progress_bar_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties);
static void _xfmpc_progress_bar_cb_hierarchy_changed_gtk_widget_hierarchy_changed (GtkWidget* _sender,
                                                                            GtkWidget* previous_toplevel,
                                                                            gpointer self);
static void _xfmpc_progress_bar_cb_style_updated_gtk_widget_style_updated (GtkWidget* _sender,
                                                                    gpointer self);
static void xfmpc_progress_bar_finalize (GObject * obj);
static GType xfmpc_progress_bar_get_type_once (void);

static inline gpointer
xfmpc_progress_bar_get_instance_private (XfmpcProgressBar* self)
{
	return G_STRUCT_MEMBER_P (self, XfmpcProgressBar_private_offset);
}

 G_GNUC_NO_INLINE static GType
xfmpc_progress_bar_columns_get_type_once (void)
{
	static const GEnumValue values[] = {{XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_PERCENTAGE, "XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_PERCENTAGE", "column-percentage"}, {XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_TEXT, "XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_TEXT", "column-text"}, {XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_BACKGROUND, "XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_BACKGROUND", "column-background"}, {XFMPC_PROGRESS_BAR_COLUMNS_N_COLUMNS, "XFMPC_PROGRESS_BAR_COLUMNS_N_COLUMNS", "n-columns"}, {0, NULL, NULL}};
	GType xfmpc_progress_bar_columns_type_id;
	xfmpc_progress_bar_columns_type_id = g_enum_register_static ("XfmpcProgressBarColumns", values);
	return xfmpc_progress_bar_columns_type_id;
}

static GType
xfmpc_progress_bar_columns_get_type (void)
{
	static volatile gsize xfmpc_progress_bar_columns_type_id__once = 0;
	if (g_once_init_enter (&xfmpc_progress_bar_columns_type_id__once)) {
		GType xfmpc_progress_bar_columns_type_id;
		xfmpc_progress_bar_columns_type_id = xfmpc_progress_bar_columns_get_type_once ();
		g_once_init_leave (&xfmpc_progress_bar_columns_type_id__once, xfmpc_progress_bar_columns_type_id);
	}
	return xfmpc_progress_bar_columns_type_id__once;
}

void
xfmpc_progress_bar_set_text (XfmpcProgressBar* self,
                             const gchar* text)
{
	GtkListStore* _tmp0_;
	GtkTreeIter _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (text != NULL);
	_tmp0_ = self->priv->store;
	_tmp1_ = self->priv->iter;
	gtk_list_store_set (_tmp0_, &_tmp1_, XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_TEXT, text, -1, -1);
}

void
xfmpc_progress_bar_set_fraction (XfmpcProgressBar* self,
                                 gdouble fraction)
{
	GtkListStore* _tmp0_;
	GtkTreeIter _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->store;
	_tmp1_ = self->priv->iter;
	gtk_list_store_set (_tmp0_, &_tmp1_, XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_PERCENTAGE, fraction * 100.0, -1, -1);
}

static void
xfmpc_progress_bar_cb_hierarchy_changed (XfmpcProgressBar* self,
                                         GtkWidget* widget,
                                         GtkWidget* previous_toplevel)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	xfmpc_progress_bar_update_background_color (self);
}

static void
xfmpc_progress_bar_cb_style_updated (XfmpcProgressBar* self,
                                     GtkWidget* widget)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	xfmpc_progress_bar_update_background_color (self);
}

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

static void
xfmpc_progress_bar_update_background_color (XfmpcProgressBar* self)
{
	GtkWidget* toplevel = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	GtkStyleContext* context = NULL;
	GtkWidget* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkStyleContext* _tmp5_;
	GValue value = {0};
	GtkStyleContext* _tmp6_;
	GValue _tmp7_ = {0};
	GtkListStore* _tmp8_;
	GtkTreeIter _tmp9_;
	void* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	toplevel = _tmp1_;
	_tmp2_ = toplevel;
	if (!g_type_is_a (G_TYPE_FROM_INSTANCE ((GObject*) _tmp2_), gtk_window_get_type ())) {
		_g_object_unref0 (toplevel);
		return;
	}
	_tmp3_ = toplevel;
	_tmp4_ = gtk_widget_get_style_context (_tmp3_);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	context = _tmp5_;
	_tmp6_ = context;
	gtk_style_context_get_property (_tmp6_, GTK_STYLE_PROPERTY_BACKGROUND_COLOR, GTK_STATE_FLAG_NORMAL, &_tmp7_);
	value = _tmp7_;
	if (!G_VALUE_HOLDS (&value, gdk_rgba_get_type ())) {
		G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
		_g_object_unref0 (context);
		_g_object_unref0 (toplevel);
		return;
	}
	_tmp8_ = self->priv->store;
	_tmp9_ = self->priv->iter;
	_tmp10_ = g_value_get_boxed (&value);
	gtk_list_store_set (_tmp8_, &_tmp9_, XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_BACKGROUND, (GdkRGBA*) _tmp10_, -1, -1);
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	_g_object_unref0 (context);
	_g_object_unref0 (toplevel);
}

XfmpcProgressBar*
xfmpc_progress_bar_construct (GType object_type)
{
	XfmpcProgressBar * self = NULL;
	self = (XfmpcProgressBar*) g_object_new (object_type, NULL);
	return self;
}

XfmpcProgressBar*
xfmpc_progress_bar_new (void)
{
	return xfmpc_progress_bar_construct (XFMPC_TYPE_PROGRESS_BAR);
}

static void
_xfmpc_progress_bar_cb_hierarchy_changed_gtk_widget_hierarchy_changed (GtkWidget* _sender,
                                                                       GtkWidget* previous_toplevel,
                                                                       gpointer self)
{
	xfmpc_progress_bar_cb_hierarchy_changed ((XfmpcProgressBar*) self, _sender, previous_toplevel);
}

static void
_xfmpc_progress_bar_cb_style_updated_gtk_widget_style_updated (GtkWidget* _sender,
                                                               gpointer self)
{
	xfmpc_progress_bar_cb_style_updated ((XfmpcProgressBar*) self, _sender);
}

static GObject *
xfmpc_progress_bar_constructor (GType type,
                                guint n_construct_properties,
                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	XfmpcProgressBar * self;
	GtkListStore* _tmp0_;
	GtkListStore* _tmp1_;
	GtkTreeIter _tmp2_ = {0};
	GtkTreeView* _tmp3_;
	GtkTreeView* _tmp4_;
	GtkTreeView* _tmp5_;
	GtkListStore* _tmp6_;
	GtkTreeView* _tmp7_;
	GtkTreeSelection* _tmp8_;
	GtkTreeView* _tmp9_;
	GtkTreeView* _tmp10_;
	GtkCellRendererProgress* renderer = NULL;
	GtkCellRendererProgress* _tmp11_;
	GtkCellRendererProgress* _tmp12_;
	GtkTreeView* _tmp13_;
	GtkCellRendererProgress* _tmp14_;
	GtkTreeView* _tmp15_;
	parent_class = G_OBJECT_CLASS (xfmpc_progress_bar_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XFMPC_TYPE_PROGRESS_BAR, XfmpcProgressBar);
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	_tmp0_ = gtk_list_store_new ((gint) XFMPC_PROGRESS_BAR_COLUMNS_N_COLUMNS, G_TYPE_DOUBLE, G_TYPE_STRING, gdk_rgba_get_type (), -1);
	_g_object_unref0 (self->priv->store);
	self->priv->store = _tmp0_;
	_tmp1_ = self->priv->store;
	gtk_list_store_append (_tmp1_, &_tmp2_);
	self->priv->iter = _tmp2_;
	_tmp3_ = (GtkTreeView*) gtk_tree_view_new ();
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->treeview);
	self->priv->treeview = _tmp3_;
	_tmp4_ = self->priv->treeview;
	gtk_tree_view_set_headers_visible (_tmp4_, FALSE);
	_tmp5_ = self->priv->treeview;
	_tmp6_ = self->priv->store;
	gtk_tree_view_set_model (_tmp5_, (GtkTreeModel*) _tmp6_);
	_tmp7_ = self->priv->treeview;
	_tmp8_ = gtk_tree_view_get_selection (_tmp7_);
	gtk_tree_selection_set_mode (_tmp8_, GTK_SELECTION_NONE);
	_tmp9_ = self->priv->treeview;
	g_signal_connect_object ((GtkWidget*) _tmp9_, "hierarchy-changed", (GCallback) _xfmpc_progress_bar_cb_hierarchy_changed_gtk_widget_hierarchy_changed, self, 0);
	_tmp10_ = self->priv->treeview;
	g_signal_connect_object ((GtkWidget*) _tmp10_, "style-updated", (GCallback) _xfmpc_progress_bar_cb_style_updated_gtk_widget_style_updated, self, 0);
	_tmp11_ = (GtkCellRendererProgress*) gtk_cell_renderer_progress_new ();
	g_object_ref_sink (_tmp11_);
	renderer = _tmp11_;
	_tmp12_ = renderer;
	g_object_set ((GtkCellRenderer*) _tmp12_, "height", 32, NULL);
	_tmp13_ = self->priv->treeview;
	_tmp14_ = renderer;
	gtk_tree_view_insert_column_with_attributes (_tmp13_, -1, NULL, (GtkCellRenderer*) _tmp14_, "value", XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_PERCENTAGE, "text", XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_TEXT, "cell-background-rgba", XFMPC_PROGRESS_BAR_COLUMNS_COLUMN_BACKGROUND, NULL, NULL);
	_tmp15_ = self->priv->treeview;
	gtk_box_pack_start ((GtkBox*) self, (GtkWidget*) _tmp15_, TRUE, TRUE, (guint) 0);
	_g_object_unref0 (renderer);
	return obj;
}

static void
xfmpc_progress_bar_class_init (XfmpcProgressBarClass * klass,
                               gpointer klass_data)
{
	xfmpc_progress_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XfmpcProgressBar_private_offset);
	G_OBJECT_CLASS (klass)->constructor = xfmpc_progress_bar_constructor;
	G_OBJECT_CLASS (klass)->finalize = xfmpc_progress_bar_finalize;
}

static void
xfmpc_progress_bar_instance_init (XfmpcProgressBar * self,
                                  gpointer klass)
{
	self->priv = xfmpc_progress_bar_get_instance_private (self);
}

static void
xfmpc_progress_bar_finalize (GObject * obj)
{
	XfmpcProgressBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XFMPC_TYPE_PROGRESS_BAR, XfmpcProgressBar);
	_g_object_unref0 (self->priv->treeview);
	_g_object_unref0 (self->priv->store);
	G_OBJECT_CLASS (xfmpc_progress_bar_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
xfmpc_progress_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XfmpcProgressBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xfmpc_progress_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XfmpcProgressBar), 0, (GInstanceInitFunc) xfmpc_progress_bar_instance_init, NULL };
	GType xfmpc_progress_bar_type_id;
	xfmpc_progress_bar_type_id = g_type_register_static (gtk_box_get_type (), "XfmpcProgressBar", &g_define_type_info, 0);
	XfmpcProgressBar_private_offset = g_type_add_instance_private (xfmpc_progress_bar_type_id, sizeof (XfmpcProgressBarPrivate));
	return xfmpc_progress_bar_type_id;
}

GType
xfmpc_progress_bar_get_type (void)
{
	static volatile gsize xfmpc_progress_bar_type_id__once = 0;
	if (g_once_init_enter (&xfmpc_progress_bar_type_id__once)) {
		GType xfmpc_progress_bar_type_id;
		xfmpc_progress_bar_type_id = xfmpc_progress_bar_get_type_once ();
		g_once_init_leave (&xfmpc_progress_bar_type_id__once, xfmpc_progress_bar_type_id);
	}
	return xfmpc_progress_bar_type_id__once;
}

