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

/*
 * Copyright 2021 elementary, Inc
 *
 * 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/>.
 */

#include "onlineaccounts.h"
#include <gtk/gtk.h>
#include <switchboard.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <gee.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>
#include <adwaita.h>
#include <granite-7.h>
#include <gmodule.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  {
	ONLINE_ACCOUNTS_PLUG_0_PROPERTY,
	ONLINE_ACCOUNTS_PLUG_NUM_PROPERTIES
};
static GParamSpec* online_accounts_plug_properties[ONLINE_ACCOUNTS_PLUG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _OnlineAccountsPlugSearchData OnlineAccountsPlugSearchData;

struct _OnlineAccountsPlugPrivate {
	GtkBox* box;
};

struct _OnlineAccountsPlugSearchData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	OnlineAccountsPlug* self;
	gchar* search;
	GeeTreeMap* result;
	GeeTreeMap* search_results;
	GCompareFunc _tmp0_;
	GEqualFunc _tmp1_;
	GeeTreeMap* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
};

static gint OnlineAccountsPlug_private_offset;
static gpointer online_accounts_plug_parent_class = NULL;

static GtkWidget* online_accounts_plug_real_get_widget (SwitchboardPlug* base);
static void online_accounts_plug_real_shown (SwitchboardPlug* base);
static void online_accounts_plug_real_hidden (SwitchboardPlug* base);
static void online_accounts_plug_real_search_callback (SwitchboardPlug* base,
                                                const gchar* location);
static void online_accounts_plug_real_search_data_free (gpointer _data);
static void online_accounts_plug_real_search (SwitchboardPlug* base,
                                       const gchar* search,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
static gboolean online_accounts_plug_real_search_co (OnlineAccountsPlugSearchData* _data_);
static void online_accounts_plug_finalize (GObject * obj);
static GType online_accounts_plug_get_type_once (void);

static inline gpointer
online_accounts_plug_get_instance_private (OnlineAccountsPlug* self)
{
	return G_STRUCT_MEMBER_P (self, OnlineAccountsPlug_private_offset);
}

OnlineAccountsPlug*
online_accounts_plug_construct (GType object_type)
{
	OnlineAccountsPlug * self = NULL;
	GeeTreeMap* settings = NULL;
	GeeTreeMap* _tmp0_;
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	_tmp0_ = gee_tree_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL);
	settings = _tmp0_;
	gee_abstract_map_set ((GeeAbstractMap*) settings, "accounts/online", NULL);
	self = (OnlineAccountsPlug*) g_object_new (object_type, "category", SWITCHBOARD_PLUG_CATEGORY_NETWORK, "code-name", "io.elementary.settings.onlineaccounts", "display-name", _ ("Online Accounts"), "description", _ ("Manage online accounts and connected applications"), "icon", "io.elementary.settings.onlineaccounts", "supported-settings", settings, NULL);
	_g_object_unref0 (settings);
	return self;
}

OnlineAccountsPlug*
online_accounts_plug_new (void)
{
	return online_accounts_plug_construct (ONLINE_ACCOUNTS_TYPE_PLUG);
}

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

static GtkWidget*
online_accounts_plug_real_get_widget (SwitchboardPlug* base)
{
	OnlineAccountsPlug * self;
	GtkBox* _tmp0_;
	GtkBox* _tmp13_;
	GtkWidget* _tmp14_;
	GtkWidget* result;
	self = (OnlineAccountsPlug*) base;
	_tmp0_ = self->priv->box;
	if (_tmp0_ == NULL) {
		GtkCssProvider* provider = NULL;
		GtkCssProvider* _tmp1_;
		GtkCssProvider* _tmp2_;
		GdkDisplay* _tmp3_;
		GtkCssProvider* _tmp4_;
		AdwHeaderBar* headerbar = NULL;
		AdwHeaderBar* _tmp5_ = NULL;
		AdwHeaderBar* _tmp6_;
		OnlineAccountsMainView* main_view = NULL;
		OnlineAccountsMainView* _tmp7_ = NULL;
		GtkBox* _tmp8_;
		GtkBox* _tmp9_;
		AdwHeaderBar* _tmp10_;
		GtkBox* _tmp11_;
		OnlineAccountsMainView* _tmp12_;
		_tmp1_ = gtk_css_provider_new ();
		provider = _tmp1_;
		_tmp2_ = provider;
		gtk_css_provider_load_from_resource (_tmp2_, "/io/elementary/settings/onlineaccounts/plug.css");
		_tmp3_ = gdk_display_get_default ();
		_tmp4_ = provider;
		gtk_style_context_add_provider_for_display (_tmp3_, (GtkStyleProvider*) _tmp4_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
		_tmp5_ = (AdwHeaderBar*) adw_header_bar_new ();
		adw_header_bar_set_show_title (_tmp5_, FALSE);
		g_object_ref_sink (_tmp5_);
		headerbar = _tmp5_;
		_tmp6_ = headerbar;
		gtk_widget_add_css_class ((GtkWidget*) _tmp6_, GRANITE_STYLE_CLASS_FLAT);
		_tmp7_ = online_accounts_main_view_new ();
		gtk_widget_set_vexpand ((GtkWidget*) _tmp7_, TRUE);
		g_object_ref_sink (_tmp7_);
		main_view = _tmp7_;
		_tmp8_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
		g_object_ref_sink (_tmp8_);
		_g_object_unref0 (self->priv->box);
		self->priv->box = _tmp8_;
		_tmp9_ = self->priv->box;
		_tmp10_ = headerbar;
		gtk_box_append (_tmp9_, (GtkWidget*) _tmp10_);
		_tmp11_ = self->priv->box;
		_tmp12_ = main_view;
		gtk_box_append (_tmp11_, (GtkWidget*) _tmp12_);
		_g_object_unref0 (main_view);
		_g_object_unref0 (headerbar);
		_g_object_unref0 (provider);
	}
	_tmp13_ = self->priv->box;
	_tmp14_ = _g_object_ref0 ((GtkWidget*) _tmp13_);
	result = _tmp14_;
	return result;
}

static void
online_accounts_plug_real_shown (SwitchboardPlug* base)
{
	OnlineAccountsPlug * self;
	self = (OnlineAccountsPlug*) base;
}

static void
online_accounts_plug_real_hidden (SwitchboardPlug* base)
{
	OnlineAccountsPlug * self;
	self = (OnlineAccountsPlug*) base;
}

static void
online_accounts_plug_real_search_callback (SwitchboardPlug* base,
                                           const gchar* location)
{
	OnlineAccountsPlug * self;
	self = (OnlineAccountsPlug*) base;
	g_return_if_fail (location != NULL);
}

static void
online_accounts_plug_real_search_data_free (gpointer _data)
{
	OnlineAccountsPlugSearchData* _data_;
	_data_ = _data;
	_g_free0 (_data_->search);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (OnlineAccountsPlugSearchData, _data_);
}

static void
online_accounts_plug_real_search (SwitchboardPlug* base,
                                  const gchar* search,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	OnlineAccountsPlug * self;
	OnlineAccountsPlugSearchData* _data_;
	OnlineAccountsPlug* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (search != NULL);
	self = (OnlineAccountsPlug*) base;
	_data_ = g_slice_new0 (OnlineAccountsPlugSearchData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, online_accounts_plug_real_search_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (search);
	_g_free0 (_data_->search);
	_data_->search = _tmp1_;
	online_accounts_plug_real_search_co (_data_);
}

static GeeTreeMap*
online_accounts_plug_search_finish (SwitchboardPlug* base,
                                    GAsyncResult* _res_)
{
	GeeTreeMap* result;
	OnlineAccountsPlugSearchData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static gboolean
online_accounts_plug_real_search_co (OnlineAccountsPlugSearchData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ((GCompareFunc) g_strcmp0);
	_data_->_tmp1_ = g_str_equal;
	_data_->_tmp2_ = gee_tree_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, (GCompareDataFunc) _data_->_tmp0_, NULL, NULL, (GeeEqualDataFunc) _data_->_tmp1_, NULL, NULL);
	_data_->search_results = _data_->_tmp2_;
	_data_->_tmp3_ = switchboard_plug_get_display_name ((SwitchboardPlug*) _data_->self);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = g_strdup_printf ("%s → %s", _data_->_tmp4_, _ ("CalDAV"));
	_data_->_tmp6_ = _data_->_tmp5_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->search_results, _data_->_tmp6_, "");
	_g_free0 (_data_->_tmp6_);
	_data_->_tmp7_ = switchboard_plug_get_display_name ((SwitchboardPlug*) _data_->self);
	_data_->_tmp8_ = _data_->_tmp7_;
	_data_->_tmp9_ = g_strdup_printf ("%s → %s", _data_->_tmp8_, _ ("Calendars"));
	_data_->_tmp10_ = _data_->_tmp9_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->search_results, _data_->_tmp10_, "");
	_g_free0 (_data_->_tmp10_);
	_data_->_tmp11_ = switchboard_plug_get_display_name ((SwitchboardPlug*) _data_->self);
	_data_->_tmp12_ = _data_->_tmp11_;
	_data_->_tmp13_ = g_strdup_printf ("%s → %s", _data_->_tmp12_, _ ("IMAP"));
	_data_->_tmp14_ = _data_->_tmp13_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->search_results, _data_->_tmp14_, "");
	_g_free0 (_data_->_tmp14_);
	_data_->_tmp15_ = switchboard_plug_get_display_name ((SwitchboardPlug*) _data_->self);
	_data_->_tmp16_ = _data_->_tmp15_;
	_data_->_tmp17_ = g_strdup_printf ("%s → %s", _data_->_tmp16_, _ ("Mail"));
	_data_->_tmp18_ = _data_->_tmp17_;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->search_results, _data_->_tmp18_, "");
	_g_free0 (_data_->_tmp18_);
	_data_->result = _data_->search_results;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
online_accounts_plug_class_init (OnlineAccountsPlugClass * klass,
                                 gpointer klass_data)
{
	online_accounts_plug_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &OnlineAccountsPlug_private_offset);
	((SwitchboardPlugClass *) klass)->get_widget = (GtkWidget* (*) (SwitchboardPlug*)) online_accounts_plug_real_get_widget;
	((SwitchboardPlugClass *) klass)->shown = (void (*) (SwitchboardPlug*)) online_accounts_plug_real_shown;
	((SwitchboardPlugClass *) klass)->hidden = (void (*) (SwitchboardPlug*)) online_accounts_plug_real_hidden;
	((SwitchboardPlugClass *) klass)->search_callback = (void (*) (SwitchboardPlug*, const gchar*)) online_accounts_plug_real_search_callback;
	((SwitchboardPlugClass *) klass)->search = (void (*) (SwitchboardPlug*, const gchar*, GAsyncReadyCallback, gpointer)) online_accounts_plug_real_search;
	((SwitchboardPlugClass *) klass)->search_finish = (GeeTreeMap* (*) (SwitchboardPlug*, GAsyncResult*)) online_accounts_plug_search_finish;
	G_OBJECT_CLASS (klass)->finalize = online_accounts_plug_finalize;
}

static void
online_accounts_plug_instance_init (OnlineAccountsPlug * self,
                                    gpointer klass)
{
	self->priv = online_accounts_plug_get_instance_private (self);
}

static void
online_accounts_plug_finalize (GObject * obj)
{
	OnlineAccountsPlug * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ONLINE_ACCOUNTS_TYPE_PLUG, OnlineAccountsPlug);
	_g_object_unref0 (self->priv->box);
	G_OBJECT_CLASS (online_accounts_plug_parent_class)->finalize (obj);
}

static GType
online_accounts_plug_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (OnlineAccountsPlugClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) online_accounts_plug_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (OnlineAccountsPlug), 0, (GInstanceInitFunc) online_accounts_plug_instance_init, NULL };
	GType online_accounts_plug_type_id;
	online_accounts_plug_type_id = g_type_register_static (SWITCHBOARD_TYPE_PLUG, "OnlineAccountsPlug", &g_define_type_info, 0);
	OnlineAccountsPlug_private_offset = g_type_add_instance_private (online_accounts_plug_type_id, sizeof (OnlineAccountsPlugPrivate));
	return online_accounts_plug_type_id;
}

GType
online_accounts_plug_get_type (void)
{
	static volatile gsize online_accounts_plug_type_id__once = 0;
	if (g_once_init_enter (&online_accounts_plug_type_id__once)) {
		GType online_accounts_plug_type_id;
		online_accounts_plug_type_id = online_accounts_plug_get_type_once ();
		g_once_init_leave (&online_accounts_plug_type_id__once, online_accounts_plug_type_id);
	}
	return online_accounts_plug_type_id__once;
}

SwitchboardPlug*
get_plug (GModule* module)
{
	OnlineAccountsPlug* plug = NULL;
	OnlineAccountsPlug* _tmp0_;
	SwitchboardPlug* result;
	g_return_val_if_fail (module != NULL, NULL);
	_tmp0_ = online_accounts_plug_new ();
	plug = _tmp0_;
	result = (SwitchboardPlug*) plug;
	return result;
}

