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

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-client-46.0.h"
#include "geary-engine.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gtk/gtk.h>
#include <glib-object.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  {
	MONITORED_PROGRESS_BAR_0_PROPERTY,
	MONITORED_PROGRESS_BAR_NUM_PROPERTIES
};
static GParamSpec* monitored_progress_bar_properties[MONITORED_PROGRESS_BAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _MonitoredProgressBarPrivate {
	GearyProgressMonitor* monitor;
};

static gint MonitoredProgressBar_private_offset;
static gpointer monitored_progress_bar_parent_class = NULL;

static void monitored_progress_bar_on_start (MonitoredProgressBar* self);
static void _monitored_progress_bar_on_start_geary_progress_monitor_start (GearyProgressMonitor* _sender,
                                                                    gpointer self);
static void monitored_progress_bar_on_finish (MonitoredProgressBar* self);
static void _monitored_progress_bar_on_finish_geary_progress_monitor_finish (GearyProgressMonitor* _sender,
                                                                      gpointer self);
static void monitored_progress_bar_on_update (MonitoredProgressBar* self,
                                       gdouble total_progress,
                                       gdouble change,
                                       GearyProgressMonitor* monitor);
static void _monitored_progress_bar_on_update_geary_progress_monitor_update (GearyProgressMonitor* _sender,
                                                                      gdouble total_progress,
                                                                      gdouble change,
                                                                      GearyProgressMonitor* monitor,
                                                                      gpointer self);
static void monitored_progress_bar_finalize (GObject * obj);
static GType monitored_progress_bar_get_type_once (void);

static inline gpointer
monitored_progress_bar_get_instance_private (MonitoredProgressBar* self)
{
	return G_STRUCT_MEMBER_P (self, MonitoredProgressBar_private_offset);
}

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

static void
_monitored_progress_bar_on_start_geary_progress_monitor_start (GearyProgressMonitor* _sender,
                                                               gpointer self)
{
	monitored_progress_bar_on_start ((MonitoredProgressBar*) self);
}

static void
_monitored_progress_bar_on_finish_geary_progress_monitor_finish (GearyProgressMonitor* _sender,
                                                                 gpointer self)
{
	monitored_progress_bar_on_finish ((MonitoredProgressBar*) self);
}

static void
_monitored_progress_bar_on_update_geary_progress_monitor_update (GearyProgressMonitor* _sender,
                                                                 gdouble total_progress,
                                                                 gdouble change,
                                                                 GearyProgressMonitor* monitor,
                                                                 gpointer self)
{
	monitored_progress_bar_on_update ((MonitoredProgressBar*) self, total_progress, change, monitor);
}

void
monitored_progress_bar_set_progress_monitor (MonitoredProgressBar* self,
                                             GearyProgressMonitor* monitor)
{
	GearyProgressMonitor* _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	g_return_if_fail (IS_MONITORED_PROGRESS_BAR (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (monitor, GEARY_TYPE_PROGRESS_MONITOR));
	_tmp0_ = _g_object_ref0 (monitor);
	_g_object_unref0 (self->priv->monitor);
	self->priv->monitor = _tmp0_;
	g_signal_connect_object (monitor, "start", (GCallback) _monitored_progress_bar_on_start_geary_progress_monitor_start, self, 0);
	g_signal_connect_object (monitor, "finish", (GCallback) _monitored_progress_bar_on_finish_geary_progress_monitor_finish, self, 0);
	g_signal_connect_object (monitor, "update", (GCallback) _monitored_progress_bar_on_update_geary_progress_monitor_update, self, 0);
	_tmp1_ = geary_progress_monitor_get_progress (monitor);
	_tmp2_ = _tmp1_;
	gtk_progress_bar_set_fraction (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_progress_bar_get_type (), GtkProgressBar), _tmp2_);
}

static void
monitored_progress_bar_on_start (MonitoredProgressBar* self)
{
	g_return_if_fail (IS_MONITORED_PROGRESS_BAR (self));
	gtk_progress_bar_set_fraction (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_progress_bar_get_type (), GtkProgressBar), 0.0);
}

static void
monitored_progress_bar_on_update (MonitoredProgressBar* self,
                                  gdouble total_progress,
                                  gdouble change,
                                  GearyProgressMonitor* monitor)
{
	g_return_if_fail (IS_MONITORED_PROGRESS_BAR (self));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (monitor, GEARY_TYPE_PROGRESS_MONITOR));
	gtk_progress_bar_set_fraction (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_progress_bar_get_type (), GtkProgressBar), total_progress);
}

static void
monitored_progress_bar_on_finish (MonitoredProgressBar* self)
{
	g_return_if_fail (IS_MONITORED_PROGRESS_BAR (self));
	gtk_progress_bar_set_fraction (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_progress_bar_get_type (), GtkProgressBar), 1.0);
}

MonitoredProgressBar*
monitored_progress_bar_construct (GType object_type)
{
	MonitoredProgressBar * self = NULL;
	self = (MonitoredProgressBar*) g_object_new (object_type, NULL);
	return self;
}

MonitoredProgressBar*
monitored_progress_bar_new (void)
{
	return monitored_progress_bar_construct (TYPE_MONITORED_PROGRESS_BAR);
}

static void
monitored_progress_bar_class_init (MonitoredProgressBarClass * klass,
                                   gpointer klass_data)
{
	monitored_progress_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MonitoredProgressBar_private_offset);
	G_OBJECT_CLASS (klass)->finalize = monitored_progress_bar_finalize;
}

static void
monitored_progress_bar_instance_init (MonitoredProgressBar * self,
                                      gpointer klass)
{
	self->priv = monitored_progress_bar_get_instance_private (self);
	self->priv->monitor = NULL;
}

static void
monitored_progress_bar_finalize (GObject * obj)
{
	MonitoredProgressBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MONITORED_PROGRESS_BAR, MonitoredProgressBar);
	_g_object_unref0 (self->priv->monitor);
	G_OBJECT_CLASS (monitored_progress_bar_parent_class)->finalize (obj);
}

/**
 * Adapts a progress bar to automatically display progress of a Geary.ProgressMonitor.
 */
static GType
monitored_progress_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MonitoredProgressBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) monitored_progress_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MonitoredProgressBar), 0, (GInstanceInitFunc) monitored_progress_bar_instance_init, NULL };
	GType monitored_progress_bar_type_id;
	monitored_progress_bar_type_id = g_type_register_static (gtk_progress_bar_get_type (), "MonitoredProgressBar", &g_define_type_info, 0);
	MonitoredProgressBar_private_offset = g_type_add_instance_private (monitored_progress_bar_type_id, sizeof (MonitoredProgressBarPrivate));
	return monitored_progress_bar_type_id;
}

GType
monitored_progress_bar_get_type (void)
{
	static volatile gsize monitored_progress_bar_type_id__once = 0;
	if (g_once_init_enter (&monitored_progress_bar_type_id__once)) {
		GType monitored_progress_bar_type_id;
		monitored_progress_bar_type_id = monitored_progress_bar_get_type_once ();
		g_once_init_leave (&monitored_progress_bar_type_id__once, monitored_progress_bar_type_id);
	}
	return monitored_progress_bar_type_id__once;
}

