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

/*
* Copyright 2019-2025 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <granite-7.h>
#include <canberra.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 NOTIFICATIONS_TYPE_APPLICATION (notifications_application_get_type ())
#define NOTIFICATIONS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFICATIONS_TYPE_APPLICATION, NotificationsApplication))
#define NOTIFICATIONS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFICATIONS_TYPE_APPLICATION, NotificationsApplicationClass))
#define NOTIFICATIONS_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFICATIONS_TYPE_APPLICATION))
#define NOTIFICATIONS_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFICATIONS_TYPE_APPLICATION))
#define NOTIFICATIONS_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NOTIFICATIONS_TYPE_APPLICATION, NotificationsApplicationClass))

typedef struct _NotificationsApplication NotificationsApplication;
typedef struct _NotificationsApplicationClass NotificationsApplicationClass;
typedef struct _NotificationsApplicationPrivate NotificationsApplicationPrivate;
enum  {
	NOTIFICATIONS_APPLICATION_0_PROPERTY,
	NOTIFICATIONS_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* notifications_application_properties[NOTIFICATIONS_APPLICATION_NUM_PROPERTIES];

#define NOTIFICATIONS_TYPE_SERVER (notifications_server_get_type ())
#define NOTIFICATIONS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFICATIONS_TYPE_SERVER, NotificationsServer))
#define NOTIFICATIONS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFICATIONS_TYPE_SERVER, NotificationsServerClass))
#define NOTIFICATIONS_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFICATIONS_TYPE_SERVER))
#define NOTIFICATIONS_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFICATIONS_TYPE_SERVER))
#define NOTIFICATIONS_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NOTIFICATIONS_TYPE_SERVER, NotificationsServerClass))

typedef struct _NotificationsServer NotificationsServer;
typedef struct _NotificationsServerClass NotificationsServerClass;
#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)))
#define _ca_proplist_destroy0(var) ((var == NULL) ? NULL : (var = (ca_proplist_destroy (var), NULL)))

struct _NotificationsApplication {
	GtkApplication parent_instance;
	NotificationsApplicationPrivate * priv;
};

struct _NotificationsApplicationClass {
	GtkApplicationClass parent_class;
};

static gpointer notifications_application_parent_class = NULL;
VALA_EXTERN GSettings* notifications_application_settings;
GSettings* notifications_application_settings = NULL;

VALA_EXTERN GType notifications_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (NotificationsApplication, g_object_unref)
VALA_EXTERN NotificationsApplication* notifications_application_new (void);
VALA_EXTERN NotificationsApplication* notifications_application_construct (GType object_type);
static gboolean notifications_application_real_dbus_register (GApplication* base,
                                                       GDBusConnection* connection,
                                                       const gchar* object_path,
                                                       GError** error);
VALA_EXTERN NotificationsServer* notifications_server_new (GDBusConnection* connection,
                                               GError** error);
VALA_EXTERN NotificationsServer* notifications_server_construct (GType object_type,
                                                     GDBusConnection* connection,
                                                     GError** error);
VALA_EXTERN GType notifications_server_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (NotificationsServer, g_object_unref)
VALA_EXTERN guint notifications_server_register_object (void* object,
                                            GDBusConnection* connection,
                                            const gchar* path,
                                            GError** error);
static void notifications_application_real_startup (GApplication* base);
VALA_EXTERN ca_context* canberra_gtk4_context_get (void);
static void __lambda14_ (NotificationsApplication* self);
static void ___lambda14__gbus_name_acquired_callback (GDBusConnection* connection,
                                               const gchar* name,
                                               gpointer self);
static void __lambda15_ (NotificationsApplication* self,
                  GDBusConnection* conn,
                  const gchar* name);
static void ___lambda15__gbus_name_lost_callback (GDBusConnection* connection,
                                           const gchar* name,
                                           gpointer self);
VALA_EXTERN void notifications_application_play_sound (const gchar* sound_name);
static gint notifications_application_main (gchar** args,
                                     gint args_length1);
static void notifications_application_finalize (GObject * obj);
static GType notifications_application_get_type_once (void);

NotificationsApplication*
notifications_application_construct (GType object_type)
{
	NotificationsApplication * self = NULL;
	self = (NotificationsApplication*) g_object_new (object_type, "application-id", "io.elementary.notifications", "flags", G_APPLICATION_IS_SERVICE | G_APPLICATION_ALLOW_REPLACEMENT, NULL);
	return self;
}

NotificationsApplication*
notifications_application_new (void)
{
	return notifications_application_construct (NOTIFICATIONS_TYPE_APPLICATION);
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static gboolean
notifications_application_real_dbus_register (GApplication* base,
                                              GDBusConnection* connection,
                                              const gchar* object_path,
                                              GError** error)
{
	NotificationsApplication * self;
	gboolean _tmp6_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (NotificationsApplication*) base;
	g_return_val_if_fail (connection != NULL, FALSE);
	g_return_val_if_fail (object_path != NULL, FALSE);
	{
		NotificationsServer* _tmp0_;
		NotificationsServer* _tmp1_;
		_tmp0_ = notifications_server_new (connection, &_inner_error0_);
		_tmp1_ = _tmp0_;
		_g_object_unref0 (_tmp1_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp2_ = NULL;
		GError* _tmp3_;
		GError* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		g_prefix_error_literal (&_tmp2_, "Registering notification server failed: ");
		_g_error_free0 (e);
		e = _tmp2_;
		_tmp3_ = e;
		_tmp4_ = _g_error_copy0 (_tmp3_);
		_inner_error0_ = _tmp4_;
		_g_error_free0 (e);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp5_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp5_;
	}
	_tmp6_ = G_APPLICATION_CLASS (notifications_application_parent_class)->dbus_register ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication), connection, object_path, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp7_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp7_;
	}
	result = _tmp6_;
	return result;
}

static void
__lambda14_ (NotificationsApplication* self)
{
	g_application_hold ((GApplication*) self);
}

static void
___lambda14__gbus_name_acquired_callback (GDBusConnection* connection,
                                          const gchar* name,
                                          gpointer self)
{
	__lambda14_ ((NotificationsApplication*) self);
}

static void
__lambda15_ (NotificationsApplication* self,
             GDBusConnection* conn,
             const gchar* name)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (conn != NULL);
	g_return_if_fail (name != NULL);
	g_critical ("Application.vala:67: Could not acquire bus: %s", name);
	g_signal_emit_by_name ((GApplication*) self, "name-lost", &_tmp0_);
}

static void
___lambda15__gbus_name_lost_callback (GDBusConnection* connection,
                                      const gchar* name,
                                      gpointer self)
{
	__lambda15_ ((NotificationsApplication*) self, connection, name);
}

static void
notifications_application_real_startup (GApplication* base)
{
	NotificationsApplication * self;
	ca_context* context = NULL;
	ca_context* _tmp0_;
	ca_context* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	ca_context* _tmp4_;
	GBusNameOwnerFlags dbus_flags = 0U;
	GApplicationFlags _tmp5_;
	GApplicationFlags _tmp6_;
	GDBusConnection* _tmp7_;
	self = (NotificationsApplication*) base;
	G_APPLICATION_CLASS (notifications_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	granite_init ();
	_tmp0_ = canberra_gtk4_context_get ();
	context = _tmp0_;
	_tmp1_ = context;
	_tmp2_ = g_application_get_application_id ((GApplication*) self);
	_tmp3_ = _tmp2_;
	ca_context_change_props (_tmp1_, CA_PROP_APPLICATION_NAME, "Notifications", CA_PROP_APPLICATION_ID, _tmp3_, NULL, NULL);
	_tmp4_ = context;
	ca_context_open (_tmp4_);
	dbus_flags = G_BUS_NAME_OWNER_FLAGS_DO_NOT_QUEUE | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
	_tmp5_ = g_application_get_flags ((GApplication*) self);
	_tmp6_ = _tmp5_;
	if ((_tmp6_ & G_APPLICATION_REPLACE) == G_APPLICATION_REPLACE) {
		dbus_flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
	}
	_tmp7_ = g_application_get_dbus_connection ((GApplication*) self);
	g_bus_own_name_on_connection_with_closures (_tmp7_, "org.freedesktop.Notifications", dbus_flags, (GClosure*) ((___lambda14__gbus_name_acquired_callback == NULL) ? NULL : g_cclosure_new ((GCallback) ___lambda14__gbus_name_acquired_callback, g_object_ref (self), (GClosureNotify) g_object_unref)), (GClosure*) ((___lambda15__gbus_name_lost_callback == NULL) ? NULL : g_cclosure_new ((GCallback) ___lambda15__gbus_name_lost_callback, g_object_ref (self), (GClosureNotify) g_object_unref)));
}

void
notifications_application_play_sound (const gchar* sound_name)
{
	ca_proplist* props = NULL;
	ca_proplist* _tmp0_ = NULL;
	ca_context* _tmp1_;
	g_return_if_fail (sound_name != NULL);
	ca_proplist_create (&_tmp0_);
	_ca_proplist_destroy0 (props);
	props = _tmp0_;
	ca_proplist_sets (props, CA_PROP_CANBERRA_CACHE_CONTROL, "volatile");
	ca_proplist_sets (props, CA_PROP_EVENT_ID, sound_name);
	_tmp1_ = canberra_gtk4_context_get ();
	ca_context_play_full (_tmp1_, (guint32) 0, props, NULL, NULL);
	_ca_proplist_destroy0 (props);
}

static gint
notifications_application_main (gchar** args,
                                gint args_length1)
{
	NotificationsApplication* app = NULL;
	NotificationsApplication* _tmp0_;
	gint result;
	_tmp0_ = notifications_application_new ();
	app = _tmp0_;
	result = g_application_run ((GApplication*) app, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return notifications_application_main (argv, argc);
}

static void
notifications_application_class_init (NotificationsApplicationClass * klass,
                                      gpointer klass_data)
{
	GSettings* _tmp0_;
	notifications_application_parent_class = g_type_class_peek_parent (klass);
	((GApplicationClass *) klass)->dbus_register = (gboolean (*) (GApplication*, GDBusConnection*, const gchar*, GError**)) notifications_application_real_dbus_register;
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) notifications_application_real_startup;
	G_OBJECT_CLASS (klass)->finalize = notifications_application_finalize;
	_tmp0_ = g_settings_new ("io.elementary.notifications");
	notifications_application_settings = _tmp0_;
}

static void
notifications_application_instance_init (NotificationsApplication * self,
                                         gpointer klass)
{
}

static void
notifications_application_finalize (GObject * obj)
{
	NotificationsApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, NOTIFICATIONS_TYPE_APPLICATION, NotificationsApplication);
	G_OBJECT_CLASS (notifications_application_parent_class)->finalize (obj);
}

static GType
notifications_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (NotificationsApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) notifications_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NotificationsApplication), 0, (GInstanceInitFunc) notifications_application_instance_init, NULL };
	GType notifications_application_type_id;
	notifications_application_type_id = g_type_register_static (gtk_application_get_type (), "NotificationsApplication", &g_define_type_info, 0);
	return notifications_application_type_id;
}

GType
notifications_application_get_type (void)
{
	static volatile gsize notifications_application_type_id__once = 0;
	if (g_once_init_enter (&notifications_application_type_id__once)) {
		GType notifications_application_type_id;
		notifications_application_type_id = notifications_application_get_type_once ();
		g_once_init_leave (&notifications_application_type_id__once, notifications_application_type_id);
	}
	return notifications_application_type_id__once;
}

