/* NotifyManager.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from NotifyManager.vala, do not modify */

/*
 * Copyright 2011-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 2 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 "notifications.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.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  {
	BACKEND_NOTIFY_MANAGER_0_PROPERTY,
	BACKEND_NOTIFY_MANAGER_APPS_PROPERTY,
	BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY,
	BACKEND_NOTIFY_MANAGER_NUM_PROPERTIES
};
static GParamSpec* backend_notify_manager_properties[BACKEND_NOTIFY_MANAGER_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))

struct _BackendNotifyManagerPrivate {
	GeeHashMap* _apps;
	gchar* _selected_app_id;
};

static gint BackendNotifyManager_private_offset;
static gpointer backend_notify_manager_parent_class = NULL;
BackendNotifyManager* backend_notify_manager_instance = NULL;

static GObject * backend_notify_manager_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void backend_notify_manager_finalize (GObject * obj);
static GType backend_notify_manager_get_type_once (void);
static void _vala_backend_notify_manager_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_backend_notify_manager_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
backend_notify_manager_get_instance_private (BackendNotifyManager* self)
{
	return G_STRUCT_MEMBER_P (self, BackendNotifyManager_private_offset);
}

BackendNotifyManager*
backend_notify_manager_get_default (void)
{
	BackendNotifyManager* _tmp0_;
	BackendNotifyManager* _tmp2_;
	BackendNotifyManager* result;
	_tmp0_ = backend_notify_manager_instance;
	if (_tmp0_ == NULL) {
		BackendNotifyManager* _tmp1_;
		_tmp1_ = backend_notify_manager_new ();
		_g_object_unref0 (backend_notify_manager_instance);
		backend_notify_manager_instance = _tmp1_;
	}
	_tmp2_ = backend_notify_manager_instance;
	result = _tmp2_;
	return result;
}

BackendNotifyManager*
backend_notify_manager_construct (GType object_type)
{
	BackendNotifyManager * self = NULL;
	self = (BackendNotifyManager*) g_object_new (object_type, NULL);
	return self;
}

BackendNotifyManager*
backend_notify_manager_new (void)
{
	return backend_notify_manager_construct (BACKEND_TYPE_NOTIFY_MANAGER);
}

GeeHashMap*
backend_notify_manager_get_apps (BackendNotifyManager* self)
{
	GeeHashMap* result;
	GeeHashMap* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_apps;
	result = _tmp0_;
	return result;
}

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

static void
backend_notify_manager_set_apps (BackendNotifyManager* self,
                                 GeeHashMap* value)
{
	GeeHashMap* old_value;
	g_return_if_fail (self != NULL);
	old_value = backend_notify_manager_get_apps (self);
	if (old_value != value) {
		GeeHashMap* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_apps);
		self->priv->_apps = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, backend_notify_manager_properties[BACKEND_NOTIFY_MANAGER_APPS_PROPERTY]);
	}
}

const gchar*
backend_notify_manager_get_selected_app_id (BackendNotifyManager* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_selected_app_id;
	result = _tmp0_;
	return result;
}

void
backend_notify_manager_set_selected_app_id (BackendNotifyManager* self,
                                            const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = backend_notify_manager_get_selected_app_id (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_selected_app_id);
		self->priv->_selected_app_id = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, backend_notify_manager_properties[BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY]);
	}
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static GObject *
backend_notify_manager_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	BackendNotifyManager * self;
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GList* installed_apps = NULL;
	GList* _tmp2_;
	GList* _tmp3_;
	parent_class = G_OBJECT_CLASS (backend_notify_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BACKEND_TYPE_NOTIFY_MANAGER, BackendNotifyManager);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, BACKEND_TYPE_APP, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_tmp1_ = _tmp0_;
	backend_notify_manager_set_apps (self, _tmp1_);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = g_app_info_get_all ();
	installed_apps = _tmp2_;
	_tmp3_ = installed_apps;
	{
		GList* app_info_collection = NULL;
		GList* app_info_it = NULL;
		app_info_collection = _tmp3_;
		for (app_info_it = app_info_collection; app_info_it != NULL; app_info_it = app_info_it->next) {
			GAppInfo* _tmp4_;
			GAppInfo* app_info = NULL;
			_tmp4_ = _g_object_ref0 ((GAppInfo*) app_info_it->data);
			app_info = _tmp4_;
			{
				GDesktopAppInfo* desktop_app_info = NULL;
				GAppInfo* _tmp5_;
				GDesktopAppInfo* _tmp6_;
				gboolean _tmp7_ = FALSE;
				GDesktopAppInfo* _tmp8_;
				_tmp5_ = app_info;
				_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, G_TYPE_DESKTOP_APP_INFO) ? ((GDesktopAppInfo*) _tmp5_) : NULL);
				desktop_app_info = _tmp6_;
				_tmp8_ = desktop_app_info;
				if (_tmp8_ != NULL) {
					GDesktopAppInfo* _tmp9_;
					_tmp9_ = desktop_app_info;
					_tmp7_ = g_desktop_app_info_get_boolean (_tmp9_, "X-GNOME-UsesNotifications");
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					BackendApp* app = NULL;
					GDesktopAppInfo* _tmp10_;
					BackendApp* _tmp11_;
					GeeHashMap* _tmp12_;
					BackendApp* _tmp13_;
					const gchar* _tmp14_;
					const gchar* _tmp15_;
					BackendApp* _tmp16_;
					_tmp10_ = desktop_app_info;
					_tmp11_ = backend_app_new (_tmp10_);
					app = _tmp11_;
					_tmp12_ = self->priv->_apps;
					_tmp13_ = app;
					_tmp14_ = backend_app_get_app_id (_tmp13_);
					_tmp15_ = _tmp14_;
					_tmp16_ = app;
					gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, _tmp15_, _tmp16_);
					_g_object_unref0 (app);
				}
				_g_object_unref0 (desktop_app_info);
				_g_object_unref0 (app_info);
			}
		}
	}
	(installed_apps == NULL) ? NULL : (installed_apps = (_g_list_free__g_object_unref0_ (installed_apps), NULL));
	return obj;
}

static void
backend_notify_manager_class_init (BackendNotifyManagerClass * klass,
                                   gpointer klass_data)
{
	backend_notify_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BackendNotifyManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_backend_notify_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_backend_notify_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = backend_notify_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = backend_notify_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BACKEND_NOTIFY_MANAGER_APPS_PROPERTY, backend_notify_manager_properties[BACKEND_NOTIFY_MANAGER_APPS_PROPERTY] = g_param_spec_object ("apps", "apps", "apps", GEE_TYPE_HASH_MAP, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY, backend_notify_manager_properties[BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY] = g_param_spec_string ("selected-app-id", "selected-app-id", "selected-app-id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
backend_notify_manager_instance_init (BackendNotifyManager * self,
                                      gpointer klass)
{
	self->priv = backend_notify_manager_get_instance_private (self);
}

static void
backend_notify_manager_finalize (GObject * obj)
{
	BackendNotifyManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BACKEND_TYPE_NOTIFY_MANAGER, BackendNotifyManager);
	_g_object_unref0 (self->priv->_apps);
	_g_free0 (self->priv->_selected_app_id);
	G_OBJECT_CLASS (backend_notify_manager_parent_class)->finalize (obj);
}

static GType
backend_notify_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BackendNotifyManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) backend_notify_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BackendNotifyManager), 0, (GInstanceInitFunc) backend_notify_manager_instance_init, NULL };
	GType backend_notify_manager_type_id;
	backend_notify_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "BackendNotifyManager", &g_define_type_info, 0);
	BackendNotifyManager_private_offset = g_type_add_instance_private (backend_notify_manager_type_id, sizeof (BackendNotifyManagerPrivate));
	return backend_notify_manager_type_id;
}

GType
backend_notify_manager_get_type (void)
{
	static volatile gsize backend_notify_manager_type_id__once = 0;
	if (g_once_init_enter (&backend_notify_manager_type_id__once)) {
		GType backend_notify_manager_type_id;
		backend_notify_manager_type_id = backend_notify_manager_get_type_once ();
		g_once_init_leave (&backend_notify_manager_type_id__once, backend_notify_manager_type_id);
	}
	return backend_notify_manager_type_id__once;
}

static void
_vala_backend_notify_manager_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	BackendNotifyManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BACKEND_TYPE_NOTIFY_MANAGER, BackendNotifyManager);
	switch (property_id) {
		case BACKEND_NOTIFY_MANAGER_APPS_PROPERTY:
		g_value_set_object (value, backend_notify_manager_get_apps (self));
		break;
		case BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY:
		g_value_set_string (value, backend_notify_manager_get_selected_app_id (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_backend_notify_manager_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	BackendNotifyManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BACKEND_TYPE_NOTIFY_MANAGER, BackendNotifyManager);
	switch (property_id) {
		case BACKEND_NOTIFY_MANAGER_APPS_PROPERTY:
		backend_notify_manager_set_apps (self, g_value_get_object (value));
		break;
		case BACKEND_NOTIFY_MANAGER_SELECTED_APP_ID_PROPERTY:
		backend_notify_manager_set_selected_app_id (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

