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

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <glib-object.h>
#include <ibus.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.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 GALA_DAEMON_TYPE_IBUS_SERVICE (gala_daemon_ibus_service_get_type ())
#define GALA_DAEMON_IBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_IBUS_SERVICE, GalaDaemonIBusService))
#define GALA_DAEMON_IBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_IBUS_SERVICE, GalaDaemonIBusServiceClass))
#define GALA_DAEMON_IS_IBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_IBUS_SERVICE))
#define GALA_DAEMON_IS_IBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_IBUS_SERVICE))
#define GALA_DAEMON_IBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_IBUS_SERVICE, GalaDaemonIBusServiceClass))

typedef struct _GalaDaemonIBusService GalaDaemonIBusService;
typedef struct _GalaDaemonIBusServiceClass GalaDaemonIBusServiceClass;
typedef struct _GalaDaemonIBusServicePrivate GalaDaemonIBusServicePrivate;

#define GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW (gala_daemon_ibus_candidate_window_get_type ())
#define GALA_DAEMON_IBUS_CANDIDATE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW, GalaDaemonIBusCandidateWindow))
#define GALA_DAEMON_IBUS_CANDIDATE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW, GalaDaemonIBusCandidateWindowClass))
#define GALA_DAEMON_IS_IBUS_CANDIDATE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW))
#define GALA_DAEMON_IS_IBUS_CANDIDATE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW))
#define GALA_DAEMON_IBUS_CANDIDATE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_IBUS_CANDIDATE_WINDOW, GalaDaemonIBusCandidateWindowClass))

typedef struct _GalaDaemonIBusCandidateWindow GalaDaemonIBusCandidateWindow;
typedef struct _GalaDaemonIBusCandidateWindowClass GalaDaemonIBusCandidateWindowClass;
enum  {
	GALA_DAEMON_IBUS_SERVICE_0_PROPERTY,
	GALA_DAEMON_IBUS_SERVICE_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_ibus_service_properties[GALA_DAEMON_IBUS_SERVICE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GalaDaemonIBusService {
	GObject parent_instance;
	GalaDaemonIBusServicePrivate * priv;
};

struct _GalaDaemonIBusServiceClass {
	GObjectClass parent_class;
};

struct _GalaDaemonIBusServicePrivate {
	IBusBus* bus;
	IBusPanelService* service;
	GalaDaemonIBusCandidateWindow* candidate_window;
};

static gint GalaDaemonIBusService_private_offset;
static gpointer gala_daemon_ibus_service_parent_class = NULL;

VALA_EXTERN GType gala_daemon_ibus_service_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonIBusService, g_object_unref)
VALA_EXTERN GType gala_daemon_ibus_candidate_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonIBusCandidateWindow, g_object_unref)
static void gala_daemon_ibus_service_on_connected (GalaDaemonIBusService* self);
static void gala_daemon_ibus_service_on_name_acquired (GalaDaemonIBusService* self,
                                                GObject* obj,
                                                GAsyncResult* res);
static void _gala_daemon_ibus_service_on_name_acquired_gasync_ready_callback (GObject* source_object,
                                                                       GAsyncResult* res,
                                                                       gpointer self);
VALA_EXTERN GalaDaemonIBusCandidateWindow* gala_daemon_ibus_candidate_window_new (IBusPanelService* service);
VALA_EXTERN GalaDaemonIBusCandidateWindow* gala_daemon_ibus_candidate_window_construct (GType object_type,
                                                                            IBusPanelService* service);
VALA_EXTERN GalaDaemonIBusService* gala_daemon_ibus_service_new (void);
VALA_EXTERN GalaDaemonIBusService* gala_daemon_ibus_service_construct (GType object_type);
static GObject * gala_daemon_ibus_service_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static void _gala_daemon_ibus_service_on_connected_ibus_bus_connected (IBusBus* _sender,
                                                                gpointer self);
static void gala_daemon_ibus_service_finalize (GObject * obj);
static GType gala_daemon_ibus_service_get_type_once (void);

static inline gpointer
gala_daemon_ibus_service_get_instance_private (GalaDaemonIBusService* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonIBusService_private_offset);
}

static void
_gala_daemon_ibus_service_on_name_acquired_gasync_ready_callback (GObject* source_object,
                                                                  GAsyncResult* res,
                                                                  gpointer self)
{
	gala_daemon_ibus_service_on_name_acquired ((GalaDaemonIBusService*) self, source_object, res);
	g_object_unref (self);
}

static void
gala_daemon_ibus_service_on_connected (GalaDaemonIBusService* self)
{
	IBusBus* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->bus;
	ibus_bus_request_name_async (_tmp0_, IBUS_SERVICE_PANEL, (guint) IBUS_BUS_NAME_FLAG_REPLACE_EXISTING, -1, NULL, _gala_daemon_ibus_service_on_name_acquired_gasync_ready_callback, g_object_ref (self));
}

static void
gala_daemon_ibus_service_on_name_acquired (GalaDaemonIBusService* self,
                                           GObject* obj,
                                           GAsyncResult* res)
{
	IBusBus* _tmp3_;
	GDBusConnection* _tmp4_;
	GObject* _tmp5_;
	GObject* _tmp6_;
	IBusPanelService* _tmp7_;
	GalaDaemonIBusCandidateWindow* _tmp8_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (res != NULL);
	{
		IBusBus* _tmp0_;
		_tmp0_ = self->priv->bus;
		ibus_bus_request_name_async_finish (_tmp0_, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp1_ = e;
		_tmp2_ = _tmp1_->message;
		g_warning ("IBusService.vala:29: Failed to acquire bus name: %s", _tmp2_);
		_g_error_free0 (e);
		return;
	}
	__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;
	}
	_tmp3_ = self->priv->bus;
	_tmp4_ = ibus_bus_get_connection (_tmp3_);
	_tmp5_ = g_object_new (ibus_panel_service_get_type (), "connection", _tmp4_, "object-path", IBUS_PATH_PANEL, NULL);
	_tmp6_ = G_IS_INITIALLY_UNOWNED (_tmp5_) ? g_object_ref_sink (_tmp5_) : _tmp5_;
	_g_object_unref0 (self->priv->service);
	self->priv->service = G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, ibus_panel_service_get_type (), IBusPanelService);
	_tmp7_ = self->priv->service;
	_tmp8_ = gala_daemon_ibus_candidate_window_new (_tmp7_);
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->candidate_window);
	self->priv->candidate_window = _tmp8_;
}

GalaDaemonIBusService*
gala_daemon_ibus_service_construct (GType object_type)
{
	GalaDaemonIBusService * self = NULL;
	self = (GalaDaemonIBusService*) g_object_new (object_type, NULL);
	return self;
}

GalaDaemonIBusService*
gala_daemon_ibus_service_new (void)
{
	return gala_daemon_ibus_service_construct (GALA_DAEMON_TYPE_IBUS_SERVICE);
}

static void
_gala_daemon_ibus_service_on_connected_ibus_bus_connected (IBusBus* _sender,
                                                           gpointer self)
{
	gala_daemon_ibus_service_on_connected ((GalaDaemonIBusService*) self);
}

static GObject *
gala_daemon_ibus_service_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonIBusService * self;
	IBusBus* _tmp0_;
	IBusBus* _tmp1_;
	parent_class = G_OBJECT_CLASS (gala_daemon_ibus_service_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_IBUS_SERVICE, GalaDaemonIBusService);
	_tmp0_ = ibus_bus_new_async ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->bus);
	self->priv->bus = _tmp0_;
	_tmp1_ = self->priv->bus;
	g_signal_connect_object (_tmp1_, "connected", (GCallback) _gala_daemon_ibus_service_on_connected_ibus_bus_connected, self, 0);
	return obj;
}

static void
gala_daemon_ibus_service_class_init (GalaDaemonIBusServiceClass * klass,
                                     gpointer klass_data)
{
	gala_daemon_ibus_service_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonIBusService_private_offset);
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_ibus_service_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_ibus_service_finalize;
}

static void
gala_daemon_ibus_service_instance_init (GalaDaemonIBusService * self,
                                        gpointer klass)
{
	self->priv = gala_daemon_ibus_service_get_instance_private (self);
}

static void
gala_daemon_ibus_service_finalize (GObject * obj)
{
	GalaDaemonIBusService * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_IBUS_SERVICE, GalaDaemonIBusService);
	_g_object_unref0 (self->priv->bus);
	_g_object_unref0 (self->priv->service);
	_g_object_unref0 (self->priv->candidate_window);
	G_OBJECT_CLASS (gala_daemon_ibus_service_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_ibus_service_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonIBusServiceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_ibus_service_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonIBusService), 0, (GInstanceInitFunc) gala_daemon_ibus_service_instance_init, NULL };
	GType gala_daemon_ibus_service_type_id;
	gala_daemon_ibus_service_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaDaemonIBusService", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonIBusService_private_offset = g_type_add_instance_private (gala_daemon_ibus_service_type_id, sizeof (GalaDaemonIBusServicePrivate));
	return gala_daemon_ibus_service_type_id;
}

GType
gala_daemon_ibus_service_get_type (void)
{
	static gsize gala_daemon_ibus_service_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_ibus_service_type_id__once)) {
		GType gala_daemon_ibus_service_type_id;
		gala_daemon_ibus_service_type_id = gala_daemon_ibus_service_get_type_once ();
		g_once_init_leave (&gala_daemon_ibus_service_type_id__once, gala_daemon_ibus_service_type_id);
	}
	return gala_daemon_ibus_service_type_id__once;
}

