/* ConnectivityInfoBar.c generated by valac 0.56.19, the Vala compiler
 * generated from ConnectivityInfoBar.vala, do not modify */

/*
 * Copyright 2020 elementary, Inc. (https://elementary.io)
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Fabio Zaramella
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR (calendar_widgets_connectivity_info_bar_get_type ())
#define CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR, CalendarWidgetsConnectivityInfoBar))
#define CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR, CalendarWidgetsConnectivityInfoBarClass))
#define CALENDAR_WIDGETS_IS_CONNECTIVITY_INFO_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR))
#define CALENDAR_WIDGETS_IS_CONNECTIVITY_INFO_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR))
#define CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR, CalendarWidgetsConnectivityInfoBarClass))

typedef struct _CalendarWidgetsConnectivityInfoBar CalendarWidgetsConnectivityInfoBar;
typedef struct _CalendarWidgetsConnectivityInfoBarClass CalendarWidgetsConnectivityInfoBarClass;
typedef struct _CalendarWidgetsConnectivityInfoBarPrivate CalendarWidgetsConnectivityInfoBarPrivate;
enum  {
	CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR_0_PROPERTY,
	CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR_NUM_PROPERTIES
};
static GParamSpec* calendar_widgets_connectivity_info_bar_properties[CALENDAR_WIDGETS_CONNECTIVITY_INFO_BAR_NUM_PROPERTIES];
typedef struct _Block34Data Block34Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _CalendarWidgetsConnectivityInfoBar {
	GtkInfoBar parent_instance;
	CalendarWidgetsConnectivityInfoBarPrivate * priv;
};

struct _CalendarWidgetsConnectivityInfoBarClass {
	GtkInfoBarClass parent_class;
};

struct _Block34Data {
	int _ref_count_;
	CalendarWidgetsConnectivityInfoBar* self;
	GNetworkMonitor* network_monitor;
};

static gpointer calendar_widgets_connectivity_info_bar_parent_class = NULL;

VALA_EXTERN GType calendar_widgets_connectivity_info_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CalendarWidgetsConnectivityInfoBar, g_object_unref)
VALA_EXTERN CalendarWidgetsConnectivityInfoBar* calendar_widgets_connectivity_info_bar_new (void);
VALA_EXTERN CalendarWidgetsConnectivityInfoBar* calendar_widgets_connectivity_info_bar_construct (GType object_type);
static GObject * calendar_widgets_connectivity_info_bar_constructor (GType type,
                                                              guint n_construct_properties,
                                                              GObjectConstructParam * construct_properties);
static Block34Data* block34_data_ref (Block34Data* _data34_);
static void block34_data_unref (void * _userdata_);
static void _calendar_widgets_connectivity_info_bar___lambda139_ (Block34Data* _data34_);
static void __calendar_widgets_connectivity_info_bar___lambda139__g_network_monitor_network_changed (GNetworkMonitor* _sender,
                                                                                              gboolean network_available,
                                                                                              gpointer self);
static void _calendar_widgets_connectivity_info_bar___lambda140_ (CalendarWidgetsConnectivityInfoBar* self,
                                                           gint response_id);
static void __calendar_widgets_connectivity_info_bar___lambda140__gtk_info_bar_response (GtkInfoBar* _sender,
                                                                                  gint response_id,
                                                                                  gpointer self);
static GType calendar_widgets_connectivity_info_bar_get_type_once (void);

CalendarWidgetsConnectivityInfoBar*
calendar_widgets_connectivity_info_bar_construct (GType object_type)
{
	CalendarWidgetsConnectivityInfoBar * self = NULL;
	self = (CalendarWidgetsConnectivityInfoBar*) g_object_new (object_type, "message-type", GTK_MESSAGE_WARNING, "revealed", FALSE, "show-close-button", FALSE, NULL);
	return self;
}

CalendarWidgetsConnectivityInfoBar*
calendar_widgets_connectivity_info_bar_new (void)
{
	return calendar_widgets_connectivity_info_bar_construct (CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR);
}

static Block34Data*
block34_data_ref (Block34Data* _data34_)
{
	g_atomic_int_inc (&_data34_->_ref_count_);
	return _data34_;
}

static void
block34_data_unref (void * _userdata_)
{
	Block34Data* _data34_;
	_data34_ = (Block34Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data34_->_ref_count_)) {
		CalendarWidgetsConnectivityInfoBar* self;
		self = _data34_->self;
		_g_object_unref0 (_data34_->network_monitor);
		_g_object_unref0 (self);
		g_slice_free (Block34Data, _data34_);
	}
}

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

static void
_calendar_widgets_connectivity_info_bar___lambda139_ (Block34Data* _data34_)
{
	CalendarWidgetsConnectivityInfoBar* self;
	gboolean available = FALSE;
	GNetworkMonitor* _tmp0_;
	gboolean _tmp1_ = FALSE;
	self = _data34_->self;
	_tmp0_ = _data34_->network_monitor;
	available = g_network_monitor_get_network_available (_tmp0_);
	if (available) {
		GNetworkMonitor* _tmp2_;
		_tmp2_ = _data34_->network_monitor;
		_tmp1_ = g_network_monitor_get_connectivity (_tmp2_) == G_NETWORK_CONNECTIVITY_FULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		gtk_info_bar_set_revealed ((GtkInfoBar*) self, FALSE);
	} else {
		gtk_info_bar_set_revealed ((GtkInfoBar*) self, TRUE);
	}
}

static void
__calendar_widgets_connectivity_info_bar___lambda139__g_network_monitor_network_changed (GNetworkMonitor* _sender,
                                                                                         gboolean network_available,
                                                                                         gpointer self)
{
	_calendar_widgets_connectivity_info_bar___lambda139_ (self);
}

static void
_calendar_widgets_connectivity_info_bar___lambda140_ (CalendarWidgetsConnectivityInfoBar* self,
                                                      gint response_id)
{
	GError* _inner_error0_ = NULL;
	{
		g_app_info_launch_default_for_uri ("settings://network", NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = e;
		_tmp1_ = _tmp0_->message;
		g_critical ("ConnectivityInfoBar.vala:56: %s", _tmp1_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
__calendar_widgets_connectivity_info_bar___lambda140__gtk_info_bar_response (GtkInfoBar* _sender,
                                                                             gint response_id,
                                                                             gpointer self)
{
	_calendar_widgets_connectivity_info_bar___lambda140_ ((CalendarWidgetsConnectivityInfoBar*) self, response_id);
}

static GObject *
calendar_widgets_connectivity_info_bar_constructor (GType type,
                                                    guint n_construct_properties,
                                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	CalendarWidgetsConnectivityInfoBar * self;
	Block34Data* _data34_;
	const gchar* title = NULL;
	const gchar* details = NULL;
	GtkLabel* info_label = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GtkLabel* _tmp4_ = NULL;
	GtkLabel* _tmp5_;
	GtkContainer* _tmp6_;
	GtkLabel* _tmp7_;
	GNetworkMonitor* _tmp8_;
	GNetworkMonitor* _tmp9_;
	GNetworkMonitor* _tmp10_;
	parent_class = G_OBJECT_CLASS (calendar_widgets_connectivity_info_bar_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CALENDAR_WIDGETS_TYPE_CONNECTIVITY_INFO_BAR, CalendarWidgetsConnectivityInfoBar);
	_data34_ = g_slice_new0 (Block34Data);
	_data34_->_ref_count_ = 1;
	_data34_->self = g_object_ref (self);
	title = _ ("Network Not Available.");
	details = _ ("Connect to the Internet to see additional details and new events from " \
"online calendars.");
	_tmp0_ = title;
	_tmp1_ = details;
	_tmp2_ = g_strdup_printf ("<b>%s</b> %s", _tmp0_, _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	gtk_label_set_use_markup (_tmp4_, TRUE);
	g_object_set (_tmp4_, "wrap", TRUE, NULL);
	g_object_ref_sink (_tmp4_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	info_label = _tmp5_;
	_tmp6_ = gtk_info_bar_get_content_area ((GtkInfoBar*) self);
	_tmp7_ = info_label;
	gtk_container_add (_tmp6_, (GtkWidget*) _tmp7_);
	gtk_info_bar_add_button ((GtkInfoBar*) self, _ ("Network Settings…"), (gint) GTK_RESPONSE_ACCEPT);
	_tmp8_ = g_network_monitor_get_default ();
	_tmp9_ = _g_object_ref0 (_tmp8_);
	_data34_->network_monitor = _tmp9_;
	_tmp10_ = _data34_->network_monitor;
	g_signal_connect_data (_tmp10_, "network-changed", (GCallback) __calendar_widgets_connectivity_info_bar___lambda139__g_network_monitor_network_changed, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	g_signal_connect_object ((GtkInfoBar*) self, "response", (GCallback) __calendar_widgets_connectivity_info_bar___lambda140__gtk_info_bar_response, self, 0);
	_g_object_unref0 (info_label);
	block34_data_unref (_data34_);
	_data34_ = NULL;
	return obj;
}

static void
calendar_widgets_connectivity_info_bar_class_init (CalendarWidgetsConnectivityInfoBarClass * klass,
                                                   gpointer klass_data)
{
	calendar_widgets_connectivity_info_bar_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = calendar_widgets_connectivity_info_bar_constructor;
}

static void
calendar_widgets_connectivity_info_bar_instance_init (CalendarWidgetsConnectivityInfoBar * self,
                                                      gpointer klass)
{
}

static GType
calendar_widgets_connectivity_info_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CalendarWidgetsConnectivityInfoBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) calendar_widgets_connectivity_info_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CalendarWidgetsConnectivityInfoBar), 0, (GInstanceInitFunc) calendar_widgets_connectivity_info_bar_instance_init, NULL };
	GType calendar_widgets_connectivity_info_bar_type_id;
	calendar_widgets_connectivity_info_bar_type_id = g_type_register_static (gtk_info_bar_get_type (), "CalendarWidgetsConnectivityInfoBar", &g_define_type_info, 0);
	return calendar_widgets_connectivity_info_bar_type_id;
}

GType
calendar_widgets_connectivity_info_bar_get_type (void)
{
	static volatile gsize calendar_widgets_connectivity_info_bar_type_id__once = 0;
	if (g_once_init_enter (&calendar_widgets_connectivity_info_bar_type_id__once)) {
		GType calendar_widgets_connectivity_info_bar_type_id;
		calendar_widgets_connectivity_info_bar_type_id = calendar_widgets_connectivity_info_bar_get_type_once ();
		g_once_init_leave (&calendar_widgets_connectivity_info_bar_type_id__once, calendar_widgets_connectivity_info_bar_type_id);
	}
	return calendar_widgets_connectivity_info_bar_type_id__once;
}

