/* composer-headerbar.c generated by valac 0.56.3, the Vala compiler
 * generated from composer-headerbar.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 <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <handy.h>

enum  {
	COMPOSER_HEADERBAR_0_PROPERTY,
	COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY,
	COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY,
	COMPOSER_HEADERBAR_NUM_PROPERTIES
};
static GParamSpec* composer_headerbar_properties[COMPOSER_HEADERBAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	COMPOSER_HEADERBAR_EXPAND_COMPOSER_SIGNAL,
	COMPOSER_HEADERBAR_NUM_SIGNALS
};
static guint composer_headerbar_signals[COMPOSER_HEADERBAR_NUM_SIGNALS] = {0};

struct _ComposerHeaderbarPrivate {
	ApplicationConfiguration* config;
	gboolean is_attached;
	GtkBox* detach_start;
	GtkBox* detach_end;
	GtkButton* recipients_button;
	GtkLabel* recipients_label;
	GtkButton* save_and_close_button;
	GtkButton* send_button;
};

static gint ComposerHeaderbar_private_offset;
static gpointer composer_headerbar_parent_class = NULL;

static void composer_headerbar_on_gtk_decoration_layout_changed (ComposerHeaderbar* self);
static void _composer_headerbar_on_gtk_decoration_layout_changed_g_object_notify (GObject* _sender,
                                                                           GParamSpec* pspec,
                                                                           gpointer self);
static void composer_headerbar_real_destroy (GtkWidget* base);
VALA_EXTERN void composer_headerbar_set_mode (ComposerHeaderbar* self,
                                  ComposerWidgetPresentationMode mode);
static void composer_headerbar_set_attached (ComposerHeaderbar* self,
                                      gboolean is_attached);
static void composer_headerbar_set_detach_button_side (ComposerHeaderbar* self);
VALA_EXTERN gboolean util_gtk_close_button_at_end (void);
static void composer_headerbar_on_recipients_button_clicked (ComposerHeaderbar* self);
static void _composer_headerbar_on_recipients_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                          gpointer self);
static void composer_headerbar_finalize (GObject * obj);
static GType composer_headerbar_get_type_once (void);
static void _vala_composer_headerbar_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_composer_headerbar_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);

static inline gpointer
composer_headerbar_get_instance_private (ComposerHeaderbar* self)
{
	return G_STRUCT_MEMBER_P (self, ComposerHeaderbar_private_offset);
}

gboolean
composer_headerbar_get_show_save_and_close (ComposerHeaderbar* self)
{
	gboolean result;
	GtkButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (COMPOSER_IS_HEADERBAR (self), FALSE);
	_tmp0_ = self->priv->save_and_close_button;
	_tmp1_ = gtk_widget_get_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget));
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
composer_headerbar_set_show_save_and_close (ComposerHeaderbar* self,
                                            gboolean value)
{
	GtkButton* _tmp0_;
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	_tmp0_ = self->priv->save_and_close_button;
	gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget), value);
	g_object_notify_by_pspec ((GObject *) self, composer_headerbar_properties[COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY]);
}

gboolean
composer_headerbar_get_show_send (ComposerHeaderbar* self)
{
	gboolean result;
	GtkButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (COMPOSER_IS_HEADERBAR (self), FALSE);
	_tmp0_ = self->priv->send_button;
	_tmp1_ = gtk_widget_get_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget));
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
composer_headerbar_set_show_send (ComposerHeaderbar* self,
                                  gboolean value)
{
	GtkButton* _tmp0_;
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	_tmp0_ = self->priv->send_button;
	gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget), value);
	g_object_notify_by_pspec ((GObject *) self, composer_headerbar_properties[COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY]);
}

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

static void
_composer_headerbar_on_gtk_decoration_layout_changed_g_object_notify (GObject* _sender,
                                                                      GParamSpec* pspec,
                                                                      gpointer self)
{
	composer_headerbar_on_gtk_decoration_layout_changed ((ComposerHeaderbar*) self);
}

ComposerHeaderbar*
composer_headerbar_construct (GType object_type,
                              ApplicationConfiguration* config)
{
	ComposerHeaderbar * self = NULL;
	ApplicationConfiguration* _tmp0_;
	GtkSettings* _tmp1_;
	g_return_val_if_fail (APPLICATION_IS_CONFIGURATION (config), NULL);
	self = (ComposerHeaderbar*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (config);
	_g_object_unref0 (self->priv->config);
	self->priv->config = _tmp0_;
	_tmp1_ = gtk_settings_get_default ();
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, G_TYPE_OBJECT, GObject), "notify::gtk-decoration-layout", (GCallback) _composer_headerbar_on_gtk_decoration_layout_changed_g_object_notify, self, 0);
	return self;
}

ComposerHeaderbar*
composer_headerbar_new (ApplicationConfiguration* config)
{
	return composer_headerbar_construct (COMPOSER_TYPE_HEADERBAR, config);
}

static void
composer_headerbar_real_destroy (GtkWidget* base)
{
	ComposerHeaderbar * self;
	GtkSettings* _tmp0_;
	guint _tmp1_;
	GQuark _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_HEADERBAR, ComposerHeaderbar);
	_tmp0_ = gtk_settings_get_default ();
	g_signal_parse_name ("notify::gtk-decoration-layout", G_TYPE_OBJECT, &_tmp1_, &_tmp2_, TRUE);
	g_signal_handlers_disconnect_matched (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, G_TYPE_OBJECT, GObject), G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, _tmp2_, NULL, (GCallback) _composer_headerbar_on_gtk_decoration_layout_changed_g_object_notify, self);
	GTK_WIDGET_CLASS (composer_headerbar_parent_class)->destroy (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, hdy_header_bar_get_type (), HdyHeaderBar), gtk_widget_get_type (), GtkWidget));
}

void
composer_headerbar_set_recipients (ComposerHeaderbar* self,
                                   const gchar* label,
                                   const gchar* tooltip)
{
	GtkLabel* _tmp0_;
	GtkButton* _tmp1_;
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	g_return_if_fail (label != NULL);
	g_return_if_fail (tooltip != NULL);
	_tmp0_ = self->priv->recipients_label;
	gtk_label_set_label (_tmp0_, label);
	_tmp1_ = self->priv->recipients_button;
	gtk_widget_set_tooltip_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget), tooltip);
}

void
composer_headerbar_set_mode (ComposerHeaderbar* self,
                             ComposerWidgetPresentationMode mode)
{
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	switch (mode) {
		case COMPOSER_WIDGET_PRESENTATION_MODE_DETACHED:
		{
			GtkButton* _tmp0_;
			_tmp0_ = self->priv->recipients_button;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget), FALSE);
			composer_headerbar_set_attached (self, FALSE);
			break;
		}
		case COMPOSER_WIDGET_PRESENTATION_MODE_PANED:
		case COMPOSER_WIDGET_PRESENTATION_MODE_INLINE:
		{
			GtkButton* _tmp1_;
			_tmp1_ = self->priv->recipients_button;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget), FALSE);
			composer_headerbar_set_attached (self, TRUE);
			break;
		}
		case COMPOSER_WIDGET_PRESENTATION_MODE_INLINE_COMPACT:
		{
			GtkButton* _tmp2_;
			_tmp2_ = self->priv->recipients_button;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_widget_get_type (), GtkWidget), TRUE);
			composer_headerbar_set_attached (self, TRUE);
			break;
		}
		case COMPOSER_WIDGET_PRESENTATION_MODE_CLOSED:
		case COMPOSER_WIDGET_PRESENTATION_MODE_NONE:
		{
			break;
		}
		default:
		break;
	}
	if (mode == COMPOSER_WIDGET_PRESENTATION_MODE_PANED) {
		ApplicationConfiguration* _tmp4_;
		ApplicationConfigurationDesktopEnvironment _tmp5_;
		ApplicationConfigurationDesktopEnvironment _tmp6_;
		_tmp4_ = self->priv->config;
		_tmp5_ = application_configuration_get_desktop_environment (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp3_ = _tmp6_ != APPLICATION_CONFIGURATION_DESKTOP_ENVIRONMENT_UNITY;
	} else {
		_tmp3_ = FALSE;
	}
	hdy_header_bar_set_show_close_button (G_TYPE_CHECK_INSTANCE_CAST (self, hdy_header_bar_get_type (), HdyHeaderBar), _tmp3_);
}

static void
composer_headerbar_set_attached (ComposerHeaderbar* self,
                                 gboolean is_attached)
{
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	self->priv->is_attached = is_attached;
	if (is_attached) {
		composer_headerbar_set_detach_button_side (self);
	} else {
		GtkBox* _tmp0_;
		GtkBox* _tmp1_;
		_tmp0_ = self->priv->detach_start;
		_tmp1_ = self->priv->detach_end;
		gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_widget_get_type (), GtkWidget), FALSE);
		gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_widget_get_type (), GtkWidget), FALSE);
	}
}

static void
composer_headerbar_set_detach_button_side (ComposerHeaderbar* self)
{
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	if (self->priv->is_attached) {
		ApplicationConfiguration* _tmp0_;
		ApplicationConfigurationDesktopEnvironment _tmp1_;
		ApplicationConfigurationDesktopEnvironment _tmp2_;
		_tmp0_ = self->priv->config;
		_tmp1_ = application_configuration_get_desktop_environment (_tmp0_);
		_tmp2_ = _tmp1_;
		if (_tmp2_ == APPLICATION_CONFIGURATION_DESKTOP_ENVIRONMENT_UNITY) {
			GtkBox* _tmp3_;
			GtkBox* _tmp4_;
			_tmp3_ = self->priv->detach_start;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_widget_get_type (), GtkWidget), FALSE);
			_tmp4_ = self->priv->detach_end;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_widget_get_type (), GtkWidget), TRUE);
		} else {
			gboolean at_end = FALSE;
			GtkBox* _tmp5_;
			GtkBox* _tmp6_;
			at_end = util_gtk_close_button_at_end ();
			_tmp5_ = self->priv->detach_start;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_widget_get_type (), GtkWidget), !at_end);
			_tmp6_ = self->priv->detach_end;
			gtk_widget_set_visible (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gtk_widget_get_type (), GtkWidget), at_end);
		}
	}
}

static void
composer_headerbar_on_recipients_button_clicked (ComposerHeaderbar* self)
{
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	g_signal_emit (self, composer_headerbar_signals[COMPOSER_HEADERBAR_EXPAND_COMPOSER_SIGNAL], 0);
}

static void
_composer_headerbar_on_recipients_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self)
{
	composer_headerbar_on_recipients_button_clicked ((ComposerHeaderbar*) self);
}

static void
composer_headerbar_on_gtk_decoration_layout_changed (ComposerHeaderbar* self)
{
	g_return_if_fail (COMPOSER_IS_HEADERBAR (self));
	composer_headerbar_set_detach_button_side (self);
}

static void
composer_headerbar_class_init (ComposerHeaderbarClass * klass,
                               gpointer klass_data)
{
	composer_headerbar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ComposerHeaderbar_private_offset);
	((GtkWidgetClass *) klass)->destroy = (void (*) (GtkWidget*)) composer_headerbar_real_destroy;
	G_OBJECT_CLASS (klass)->get_property = _vala_composer_headerbar_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_composer_headerbar_set_property;
	G_OBJECT_CLASS (klass)->finalize = composer_headerbar_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY, composer_headerbar_properties[COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY] = g_param_spec_boolean ("show-save-and-close", "show-save-and-close", "show-save-and-close", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY, composer_headerbar_properties[COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY] = g_param_spec_boolean ("show-send", "show-send", "show-send", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Geary/composer-headerbar.ui");
	/** Fired when the user wants to expand a compact composer. */
	composer_headerbar_signals[COMPOSER_HEADERBAR_EXPAND_COMPOSER_SIGNAL] = g_signal_new ("expand-composer", COMPOSER_TYPE_HEADERBAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "detach_start", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, detach_start));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "detach_end", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, detach_end));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recipients_button", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, recipients_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recipients_label", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, recipients_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "save_and_close_button", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, save_and_close_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "send_button", FALSE, ComposerHeaderbar_private_offset + G_STRUCT_OFFSET (ComposerHeaderbarPrivate, send_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_recipients_button_clicked", G_CALLBACK(_composer_headerbar_on_recipients_button_clicked_gtk_button_clicked));
}

static void
composer_headerbar_instance_init (ComposerHeaderbar * self,
                                  gpointer klass)
{
	self->priv = composer_headerbar_get_instance_private (self);
	self->priv->is_attached = TRUE;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
composer_headerbar_finalize (GObject * obj)
{
	ComposerHeaderbar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, COMPOSER_TYPE_HEADERBAR, ComposerHeaderbar);
	_g_object_unref0 (self->priv->config);
	G_OBJECT_CLASS (composer_headerbar_parent_class)->finalize (obj);
}

static GType
composer_headerbar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ComposerHeaderbarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) composer_headerbar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ComposerHeaderbar), 0, (GInstanceInitFunc) composer_headerbar_instance_init, NULL };
	GType composer_headerbar_type_id;
	composer_headerbar_type_id = g_type_register_static (hdy_header_bar_get_type (), "ComposerHeaderbar", &g_define_type_info, 0);
	ComposerHeaderbar_private_offset = g_type_add_instance_private (composer_headerbar_type_id, sizeof (ComposerHeaderbarPrivate));
	return composer_headerbar_type_id;
}

GType
composer_headerbar_get_type (void)
{
	static volatile gsize composer_headerbar_type_id__once = 0;
	if (g_once_init_enter (&composer_headerbar_type_id__once)) {
		GType composer_headerbar_type_id;
		composer_headerbar_type_id = composer_headerbar_get_type_once ();
		g_once_init_leave (&composer_headerbar_type_id__once, composer_headerbar_type_id);
	}
	return composer_headerbar_type_id__once;
}

static void
_vala_composer_headerbar_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	ComposerHeaderbar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPOSER_TYPE_HEADERBAR, ComposerHeaderbar);
	switch (property_id) {
		case COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY:
		g_value_set_boolean (value, composer_headerbar_get_show_save_and_close (self));
		break;
		case COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY:
		g_value_set_boolean (value, composer_headerbar_get_show_send (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_composer_headerbar_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	ComposerHeaderbar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPOSER_TYPE_HEADERBAR, ComposerHeaderbar);
	switch (property_id) {
		case COMPOSER_HEADERBAR_SHOW_SAVE_AND_CLOSE_PROPERTY:
		composer_headerbar_set_show_save_and_close (self, g_value_get_boolean (value));
		break;
		case COMPOSER_HEADERBAR_SHOW_SEND_PROPERTY:
		composer_headerbar_set_show_send (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

