/* components-problem-report-info-bar.c generated by valac 0.56.3, the Vala compiler
 * generated from components-problem-report-info-bar.vala, do not modify */

/*
 * Copyright © 2017,2020 Michael Gratton <mike@vee.net>
 *
 * 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 <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

enum  {
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_0_PROPERTY,
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY,
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_NUM_PROPERTIES
};
static GParamSpec* components_problem_report_info_bar_properties[COMPONENTS_PROBLEM_REPORT_INFO_BAR_NUM_PROPERTIES];
typedef enum  {
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_DETAILS,
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_RETRY
} ComponentsProblemReportInfoBarResponseType;

#define COMPONENTS_PROBLEM_REPORT_INFO_BAR_TYPE_RESPONSE_TYPE (components_problem_report_info_bar_response_type_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_RETRY_SIGNAL,
	COMPONENTS_PROBLEM_REPORT_INFO_BAR_NUM_SIGNALS
};
static guint components_problem_report_info_bar_signals[COMPONENTS_PROBLEM_REPORT_INFO_BAR_NUM_SIGNALS] = {0};

struct _ComponentsProblemReportInfoBarPrivate {
	GearyProblemReport* _report;
};

static gint ComponentsProblemReportInfoBar_private_offset;
static gpointer components_problem_report_info_bar_parent_class = NULL;

static GType components_problem_report_info_bar_response_type_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void components_problem_report_info_bar_set_report (ComponentsProblemReportInfoBar* self,
                                                    GearyProblemReport* value);
static void components_problem_report_info_bar_on_info_bar_response (ComponentsProblemReportInfoBar* self,
                                                              gint response);
static void _components_problem_report_info_bar_on_info_bar_response_components_info_bar_response (ComponentsInfoBar* _sender,
                                                                                            gint response_id,
                                                                                            gpointer self);
static void components_problem_report_info_bar_show_details (ComponentsProblemReportInfoBar* self);
static void components_problem_report_info_bar_finalize (GObject * obj);
static GType components_problem_report_info_bar_get_type_once (void);
static void _vala_components_problem_report_info_bar_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec);
static void _vala_components_problem_report_info_bar_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec);

static inline gpointer
components_problem_report_info_bar_get_instance_private (ComponentsProblemReportInfoBar* self)
{
	return G_STRUCT_MEMBER_P (self, ComponentsProblemReportInfoBar_private_offset);
}

static GType
components_problem_report_info_bar_response_type_get_type_once (void)
{
	static const GEnumValue values[] = {{COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_DETAILS, "COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_DETAILS", "details"}, {COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_RETRY, "COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_RETRY", "retry"}, {0, NULL, NULL}};
	GType components_problem_report_info_bar_response_type_type_id;
	components_problem_report_info_bar_response_type_type_id = g_enum_register_static ("ComponentsProblemReportInfoBarResponseType", values);
	return components_problem_report_info_bar_response_type_type_id;
}

static GType
components_problem_report_info_bar_response_type_get_type (void)
{
	static volatile gsize components_problem_report_info_bar_response_type_type_id__once = 0;
	if (g_once_init_enter (&components_problem_report_info_bar_response_type_type_id__once)) {
		GType components_problem_report_info_bar_response_type_type_id;
		components_problem_report_info_bar_response_type_type_id = components_problem_report_info_bar_response_type_get_type_once ();
		g_once_init_leave (&components_problem_report_info_bar_response_type_type_id__once, components_problem_report_info_bar_response_type_type_id);
	}
	return components_problem_report_info_bar_response_type_type_id__once;
}

GearyProblemReport*
components_problem_report_info_bar_get_report (ComponentsProblemReportInfoBar* self)
{
	GearyProblemReport* result;
	GearyProblemReport* _tmp0_;
	g_return_val_if_fail (COMPONENTS_IS_PROBLEM_REPORT_INFO_BAR (self), NULL);
	_tmp0_ = self->priv->_report;
	result = _tmp0_;
	return result;
}

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

static void
components_problem_report_info_bar_set_report (ComponentsProblemReportInfoBar* self,
                                               GearyProblemReport* value)
{
	GearyProblemReport* old_value;
	g_return_if_fail (COMPONENTS_IS_PROBLEM_REPORT_INFO_BAR (self));
	old_value = components_problem_report_info_bar_get_report (self);
	if (old_value != value) {
		GearyProblemReport* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_report);
		self->priv->_report = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, components_problem_report_info_bar_properties[COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY]);
	}
}

static void
_components_problem_report_info_bar_on_info_bar_response_components_info_bar_response (ComponentsInfoBar* _sender,
                                                                                       gint response_id,
                                                                                       gpointer self)
{
	components_problem_report_info_bar_on_info_bar_response ((ComponentsProblemReportInfoBar*) self, response_id);
}

ComponentsProblemReportInfoBar*
components_problem_report_info_bar_construct (GType object_type,
                                              GearyProblemReport* report)
{
	ComponentsProblemReportInfoBar * self = NULL;
	GtkMessageType type = 0;
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* descr = NULL;
	gchar* _tmp1_;
	gchar* retry = NULL;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	GearyProblemReport* _tmp29_;
	GearyErrorContext* _tmp30_;
	GearyErrorContext* _tmp31_;
	const gchar* _tmp34_;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (report, GEARY_TYPE_PROBLEM_REPORT), NULL);
	type = GTK_MESSAGE_WARNING;
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = g_strdup ("");
	descr = _tmp1_;
	retry = NULL;
	if (G_TYPE_CHECK_INSTANCE_TYPE (report, GEARY_TYPE_ACCOUNT_PROBLEM_REPORT)) {
		GearyAccountProblemReport* account_report = NULL;
		GearyAccountProblemReport* _tmp2_;
		gchar* account_name = NULL;
		GearyAccountProblemReport* _tmp3_;
		GearyAccountInformation* _tmp4_;
		GearyAccountInformation* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (report, GEARY_TYPE_ACCOUNT_PROBLEM_REPORT, GearyAccountProblemReport));
		account_report = _tmp2_;
		_tmp3_ = account_report;
		_tmp4_ = geary_account_problem_report_get_account (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = geary_account_information_get_display_name (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strdup (_tmp7_);
		account_name = _tmp8_;
		_tmp9_ = g_strdup (_ ("Account problem"));
		_g_free0 (title);
		title = _tmp9_;
		_tmp10_ = account_name;
		_tmp11_ = g_strdup_printf (_ ("Geary has encountered a problem with %s."), _tmp10_);
		_g_free0 (descr);
		descr = _tmp11_;
		if (G_TYPE_CHECK_INSTANCE_TYPE (report, GEARY_TYPE_SERVICE_PROBLEM_REPORT)) {
			GearyServiceProblemReport* service_report = NULL;
			GearyServiceProblemReport* _tmp12_;
			GearyServiceProblemReport* _tmp13_;
			GearyServiceInformation* _tmp14_;
			GearyServiceInformation* _tmp15_;
			GearyProtocol _tmp16_;
			GearyProtocol _tmp17_;
			_tmp12_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (report, GEARY_TYPE_SERVICE_PROBLEM_REPORT, GearyServiceProblemReport));
			service_report = _tmp12_;
			_tmp13_ = service_report;
			_tmp14_ = geary_service_problem_report_get_service (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = geary_service_information_get_protocol (_tmp15_);
			_tmp17_ = _tmp16_;
			switch (_tmp17_) {
				case GEARY_PROTOCOL_IMAP:
				{
					const gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					_tmp18_ = account_name;
					_tmp19_ = g_strdup_printf (_ ("Geary encountered a problem checking mail for %s."), _tmp18_);
					_g_free0 (descr);
					descr = _tmp19_;
					_tmp20_ = g_strdup (_ ("Try reconnecting"));
					_g_free0 (retry);
					retry = _tmp20_;
					break;
				}
				case GEARY_PROTOCOL_SMTP:
				{
					const gchar* _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					_tmp21_ = account_name;
					_tmp22_ = g_strdup_printf (_ ("Geary encountered a problem sending email for %s."), _tmp21_);
					_g_free0 (descr);
					descr = _tmp22_;
					_tmp23_ = g_strdup (_ ("Retry sending queued messages"));
					_g_free0 (retry);
					retry = _tmp23_;
					break;
				}
				default:
				break;
			}
			_g_object_unref0 (service_report);
		}
		_g_free0 (account_name);
		_g_object_unref0 (account_report);
	} else {
		gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp24_ = g_strdup (_ ("Geary has encountered a problem"));
		_g_free0 (title);
		title = _tmp24_;
		_tmp25_ = g_strdup (_ ("Please report the details if it persists."));
		_g_free0 (descr);
		descr = _tmp25_;
	}
	_tmp26_ = title;
	_tmp27_ = descr;
	self = (ComponentsProblemReportInfoBar*) components_info_bar_construct (object_type, _tmp26_, _tmp27_);
	components_info_bar_set_message_type (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), type);
	components_problem_report_info_bar_set_report (self, report);
	_tmp28_ = retry;
	components_info_bar_set_show_close_button (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), _tmp28_ == NULL);
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), "response", (GCallback) _components_problem_report_info_bar_on_info_bar_response_components_info_bar_response, self, 0);
	_tmp29_ = self->priv->_report;
	_tmp30_ = geary_problem_report_get_error (_tmp29_);
	_tmp31_ = _tmp30_;
	if (_tmp31_ != NULL) {
		GtkButton* details = NULL;
		GtkButton* _tmp32_;
		GtkButton* _tmp33_;
		_tmp32_ = components_info_bar_add_button (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), _ ("_Details"), (gint) COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_DETAILS);
		details = _tmp32_;
		_tmp33_ = details;
		gtk_widget_set_tooltip_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp33_, gtk_widget_get_type (), GtkWidget), _ ("View technical details about the error"));
		_g_object_unref0 (details);
	}
	_tmp34_ = retry;
	if (_tmp34_ != NULL) {
		GtkButton* retry_btn = NULL;
		GtkButton* _tmp35_;
		GtkButton* _tmp36_;
		const gchar* _tmp37_;
		_tmp35_ = components_info_bar_add_button (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), _ ("_Retry"), (gint) COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_RETRY);
		retry_btn = _tmp35_;
		_tmp36_ = retry_btn;
		_tmp37_ = retry;
		gtk_widget_set_tooltip_text (G_TYPE_CHECK_INSTANCE_CAST (_tmp36_, gtk_widget_get_type (), GtkWidget), _tmp37_);
		_g_object_unref0 (retry_btn);
	}
	_g_free0 (retry);
	_g_free0 (descr);
	_g_free0 (title);
	return self;
}

ComponentsProblemReportInfoBar*
components_problem_report_info_bar_new (GearyProblemReport* report)
{
	return components_problem_report_info_bar_construct (COMPONENTS_TYPE_PROBLEM_REPORT_INFO_BAR, report);
}

static void
components_problem_report_info_bar_show_details (ComponentsProblemReportInfoBar* self)
{
	ApplicationMainWindow* main = NULL;
	GtkWidget* _tmp0_;
	ApplicationMainWindow* _tmp1_;
	ApplicationMainWindow* _tmp2_;
	g_return_if_fail (COMPONENTS_IS_PROBLEM_REPORT_INFO_BAR (self));
	_tmp0_ = gtk_widget_get_toplevel (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	_tmp1_ = _g_object_ref0 (APPLICATION_IS_MAIN_WINDOW (_tmp0_) ? ((ApplicationMainWindow*) _tmp0_) : NULL);
	main = _tmp1_;
	_tmp2_ = main;
	if (_tmp2_ != NULL) {
		DialogsProblemDetailsDialog* dialog = NULL;
		ApplicationMainWindow* _tmp3_;
		ApplicationMainWindow* _tmp4_;
		ApplicationClient* _tmp5_;
		ApplicationClient* _tmp6_;
		GearyProblemReport* _tmp7_;
		DialogsProblemDetailsDialog* _tmp8_;
		DialogsProblemDetailsDialog* _tmp9_;
		_tmp3_ = main;
		_tmp4_ = main;
		_tmp5_ = application_main_window_get_application (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = self->priv->_report;
		_tmp8_ = dialogs_problem_details_dialog_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_window_get_type (), GtkWindow), _tmp6_, _tmp7_);
		g_object_ref_sink (_tmp8_);
		dialog = _tmp8_;
		_tmp9_ = dialog;
		gtk_widget_show (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, gtk_widget_get_type (), GtkWidget));
		_g_object_unref0 (dialog);
	}
	_g_object_unref0 (main);
}

static void
components_problem_report_info_bar_on_info_bar_response (ComponentsProblemReportInfoBar* self,
                                                         gint response)
{
	g_return_if_fail (COMPONENTS_IS_PROBLEM_REPORT_INFO_BAR (self));
	switch (response) {
		case COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_DETAILS:
		{
			components_problem_report_info_bar_show_details (self);
			break;
		}
		case COMPONENTS_PROBLEM_REPORT_INFO_BAR_RESPONSE_TYPE_RETRY:
		{
			g_signal_emit (self, components_problem_report_info_bar_signals[COMPONENTS_PROBLEM_REPORT_INFO_BAR_RETRY_SIGNAL], 0);
			components_info_bar_set_revealed (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), FALSE);
			break;
		}
		default:
		{
			components_info_bar_set_revealed (G_TYPE_CHECK_INSTANCE_CAST (self, COMPONENTS_TYPE_INFO_BAR, ComponentsInfoBar), FALSE);
			break;
		}
	}
}

static void
components_problem_report_info_bar_class_init (ComponentsProblemReportInfoBarClass * klass,
                                               gpointer klass_data)
{
	components_problem_report_info_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ComponentsProblemReportInfoBar_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_components_problem_report_info_bar_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_components_problem_report_info_bar_set_property;
	G_OBJECT_CLASS (klass)->finalize = components_problem_report_info_bar_finalize;
	/** If reporting a problem, returns the problem report else null. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY, components_problem_report_info_bar_properties[COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY] = g_param_spec_object ("report", "report", "report", GEARY_TYPE_PROBLEM_REPORT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Emitted when the user clicks the Retry button, if any. */
	components_problem_report_info_bar_signals[COMPONENTS_PROBLEM_REPORT_INFO_BAR_RETRY_SIGNAL] = g_signal_new ("retry", COMPONENTS_TYPE_PROBLEM_REPORT_INFO_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
components_problem_report_info_bar_instance_init (ComponentsProblemReportInfoBar * self,
                                                  gpointer klass)
{
	self->priv = components_problem_report_info_bar_get_instance_private (self);
}

static void
components_problem_report_info_bar_finalize (GObject * obj)
{
	ComponentsProblemReportInfoBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, COMPONENTS_TYPE_PROBLEM_REPORT_INFO_BAR, ComponentsProblemReportInfoBar);
	_g_object_unref0 (self->priv->_report);
	G_OBJECT_CLASS (components_problem_report_info_bar_parent_class)->finalize (obj);
}

/**
 * Displays a Geary problem report as an info bar.
 */
static GType
components_problem_report_info_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ComponentsProblemReportInfoBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) components_problem_report_info_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ComponentsProblemReportInfoBar), 0, (GInstanceInitFunc) components_problem_report_info_bar_instance_init, NULL };
	GType components_problem_report_info_bar_type_id;
	components_problem_report_info_bar_type_id = g_type_register_static (COMPONENTS_TYPE_INFO_BAR, "ComponentsProblemReportInfoBar", &g_define_type_info, 0);
	ComponentsProblemReportInfoBar_private_offset = g_type_add_instance_private (components_problem_report_info_bar_type_id, sizeof (ComponentsProblemReportInfoBarPrivate));
	return components_problem_report_info_bar_type_id;
}

GType
components_problem_report_info_bar_get_type (void)
{
	static volatile gsize components_problem_report_info_bar_type_id__once = 0;
	if (g_once_init_enter (&components_problem_report_info_bar_type_id__once)) {
		GType components_problem_report_info_bar_type_id;
		components_problem_report_info_bar_type_id = components_problem_report_info_bar_get_type_once ();
		g_once_init_leave (&components_problem_report_info_bar_type_id__once, components_problem_report_info_bar_type_id);
	}
	return components_problem_report_info_bar_type_id__once;
}

static void
_vala_components_problem_report_info_bar_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec)
{
	ComponentsProblemReportInfoBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPONENTS_TYPE_PROBLEM_REPORT_INFO_BAR, ComponentsProblemReportInfoBar);
	switch (property_id) {
		case COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY:
		g_value_set_object (value, components_problem_report_info_bar_get_report (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_components_problem_report_info_bar_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec)
{
	ComponentsProblemReportInfoBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPONENTS_TYPE_PROBLEM_REPORT_INFO_BAR, ComponentsProblemReportInfoBar);
	switch (property_id) {
		case COMPONENTS_PROBLEM_REPORT_INFO_BAR_REPORT_PROPERTY:
		components_problem_report_info_bar_set_report (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

