/* monitored-spinner.c generated by valac 0.56.3, the Vala compiler
 * generated from monitored-spinner.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-43.0.h"
#include "geary-engine.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>

enum  {
	MONITORED_SPINNER_0_PROPERTY,
	MONITORED_SPINNER_NUM_PROPERTIES
};
static GParamSpec* monitored_spinner_properties[MONITORED_SPINNER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _MonitoredSpinnerPrivate {
	GearyProgressMonitor* monitor;
};

static gint MonitoredSpinner_private_offset;
static gpointer monitored_spinner_parent_class = NULL;

static void monitored_spinner_on_start (MonitoredSpinner* self);
static void _monitored_spinner_on_start_geary_progress_monitor_start (GearyProgressMonitor* _sender,
                                                               gpointer self);
static void monitored_spinner_on_stop (MonitoredSpinner* self);
static void _monitored_spinner_on_stop_geary_progress_monitor_finish (GearyProgressMonitor* _sender,
                                                               gpointer self);
static void monitored_spinner_real_show (GtkWidget* base);
static void monitored_spinner_finalize (GObject * obj);
static GType monitored_spinner_get_type_once (void);

static inline gpointer
monitored_spinner_get_instance_private (MonitoredSpinner* self)
{
	return G_STRUCT_MEMBER_P (self, MonitoredSpinner_private_offset);
}

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

static void
_monitored_spinner_on_start_geary_progress_monitor_start (GearyProgressMonitor* _sender,
                                                          gpointer self)
{
	monitored_spinner_on_start ((MonitoredSpinner*) self);
}

static void
_monitored_spinner_on_stop_geary_progress_monitor_finish (GearyProgressMonitor* _sender,
                                                          gpointer self)
{
	monitored_spinner_on_stop ((MonitoredSpinner*) self);
}

void
monitored_spinner_set_progress_monitor (MonitoredSpinner* self,
                                        GearyProgressMonitor* monitor)
{
	g_return_if_fail (IS_MONITORED_SPINNER (self));
	g_return_if_fail ((monitor == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (monitor, GEARY_TYPE_PROGRESS_MONITOR));
	if (monitor != NULL) {
		GearyProgressMonitor* _tmp0_;
		_tmp0_ = _g_object_ref0 (monitor);
		_g_object_unref0 (self->priv->monitor);
		self->priv->monitor = _tmp0_;
		g_signal_connect_object (monitor, "start", (GCallback) _monitored_spinner_on_start_geary_progress_monitor_start, self, 0);
		g_signal_connect_object (monitor, "finish", (GCallback) _monitored_spinner_on_stop_geary_progress_monitor_finish, self, 0);
	} else {
		_g_object_unref0 (self->priv->monitor);
		self->priv->monitor = NULL;
		gtk_spinner_stop (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_spinner_get_type (), GtkSpinner));
		gtk_widget_hide (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	}
}

static void
monitored_spinner_real_show (GtkWidget* base)
{
	MonitoredSpinner * self;
	gboolean _tmp0_ = FALSE;
	GearyProgressMonitor* _tmp1_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_MONITORED_SPINNER, MonitoredSpinner);
	_tmp1_ = self->priv->monitor;
	if (_tmp1_ != NULL) {
		GearyProgressMonitor* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->monitor;
		_tmp3_ = geary_progress_monitor_get_is_in_progress (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GTK_WIDGET_CLASS (monitored_spinner_parent_class)->show (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_spinner_get_type (), GtkSpinner), gtk_widget_get_type (), GtkWidget));
	}
}

static void
monitored_spinner_on_start (MonitoredSpinner* self)
{
	g_return_if_fail (IS_MONITORED_SPINNER (self));
	gtk_spinner_start (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_spinner_get_type (), GtkSpinner));
	gtk_widget_show (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

static void
monitored_spinner_on_stop (MonitoredSpinner* self)
{
	g_return_if_fail (IS_MONITORED_SPINNER (self));
	gtk_spinner_stop (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_spinner_get_type (), GtkSpinner));
	gtk_widget_hide (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

MonitoredSpinner*
monitored_spinner_construct (GType object_type)
{
	MonitoredSpinner * self = NULL;
	self = (MonitoredSpinner*) g_object_new (object_type, NULL);
	return self;
}

MonitoredSpinner*
monitored_spinner_new (void)
{
	return monitored_spinner_construct (TYPE_MONITORED_SPINNER);
}

static void
monitored_spinner_class_init (MonitoredSpinnerClass * klass,
                              gpointer klass_data)
{
	monitored_spinner_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MonitoredSpinner_private_offset);
	((GtkWidgetClass *) klass)->show = (void (*) (GtkWidget*)) monitored_spinner_real_show;
	G_OBJECT_CLASS (klass)->finalize = monitored_spinner_finalize;
}

static void
monitored_spinner_instance_init (MonitoredSpinner * self,
                                 gpointer klass)
{
	self->priv = monitored_spinner_get_instance_private (self);
	self->priv->monitor = NULL;
}

static void
monitored_spinner_finalize (GObject * obj)
{
	MonitoredSpinner * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MONITORED_SPINNER, MonitoredSpinner);
	_g_object_unref0 (self->priv->monitor);
	G_OBJECT_CLASS (monitored_spinner_parent_class)->finalize (obj);
}

/**
 * Adapts a progress spinner to automatically display progress of a Geary.ProgressMonitor.
 */
static GType
monitored_spinner_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MonitoredSpinnerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) monitored_spinner_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MonitoredSpinner), 0, (GInstanceInitFunc) monitored_spinner_instance_init, NULL };
	GType monitored_spinner_type_id;
	monitored_spinner_type_id = g_type_register_static (gtk_spinner_get_type (), "MonitoredSpinner", &g_define_type_info, 0);
	MonitoredSpinner_private_offset = g_type_add_instance_private (monitored_spinner_type_id, sizeof (MonitoredSpinnerPrivate));
	return monitored_spinner_type_id;
}

GType
monitored_spinner_get_type (void)
{
	static volatile gsize monitored_spinner_type_id__once = 0;
	if (g_once_init_enter (&monitored_spinner_type_id__once)) {
		GType monitored_spinner_type_id;
		monitored_spinner_type_id = monitored_spinner_get_type_once ();
		g_once_init_leave (&monitored_spinner_type_id__once, monitored_spinner_type_id);
	}
	return monitored_spinner_type_id__once;
}

