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

/* UIFragment.vala
 *
 * Copyright 2020 Dylan McCall <dylan@dylanmccall.ca>
 *
 * 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/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "daemon.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.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  {
	BREAK_TIMER_DAEMON_UI_FRAGMENT_0_PROPERTY,
	BREAK_TIMER_DAEMON_UI_FRAGMENT_FOCUS_PRIORITY_PROPERTY,
	BREAK_TIMER_DAEMON_UI_FRAGMENT_NOTIFICATION_IDS_PROPERTY,
	BREAK_TIMER_DAEMON_UI_FRAGMENT_NUM_PROPERTIES
};
static GParamSpec* break_timer_daemon_ui_fragment_properties[BREAK_TIMER_DAEMON_UI_FRAGMENT_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 _BreakTimerDaemonUIFragmentPrivate {
	BreakTimerDaemonUtilFocusPriority _focus_priority;
	gchar** _notification_ids;
	gint _notification_ids_length1;
	gint __notification_ids_size_;
};

static gint BreakTimerDaemonUIFragment_private_offset;
static gpointer break_timer_daemon_ui_fragment_parent_class = NULL;
static BreakTimerDaemonUtilIFocusableIface * break_timer_daemon_ui_fragment_break_timer_daemon_util_ifocusable_parent_iface = NULL;

static void break_timer_daemon_ui_fragment_hide_all_notifications (BreakTimerDaemonUIFragment* self);
static void break_timer_daemon_ui_fragment_real_focus_started (BreakTimerDaemonUIFragment* self);
static void break_timer_daemon_ui_fragment_real_focus_stopped (BreakTimerDaemonUIFragment* self);
static void break_timer_daemon_ui_fragment_finalize (GObject * obj);
static GType break_timer_daemon_ui_fragment_get_type_once (void);
static void _vala_break_timer_daemon_ui_fragment_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
break_timer_daemon_ui_fragment_get_instance_private (BreakTimerDaemonUIFragment* self)
{
	return G_STRUCT_MEMBER_P (self, BreakTimerDaemonUIFragment_private_offset);
}

gboolean
break_timer_daemon_ui_fragment_has_ui_focus (BreakTimerDaemonUIFragment* self)
{
	BreakTimerDaemonUIManager* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->ui_manager;
	result = break_timer_daemon_util_simple_focus_manager_is_focusing ((BreakTimerDaemonUtilSimpleFocusManager*) _tmp0_, (BreakTimerDaemonUtilIFocusable*) self);
	return result;
}

gboolean
break_timer_daemon_ui_fragment_has_higher_focus_priority (BreakTimerDaemonUIFragment* self,
                                                          BreakTimerDaemonUIFragment* other)
{
	BreakTimerDaemonUtilFocusPriority _tmp0_;
	BreakTimerDaemonUtilFocusPriority _tmp1_;
	BreakTimerDaemonUtilFocusPriority _tmp2_;
	BreakTimerDaemonUtilFocusPriority _tmp3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (other != NULL, FALSE);
	_tmp0_ = break_timer_daemon_ui_fragment_get_focus_priority (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = break_timer_daemon_ui_fragment_get_focus_priority (other);
	_tmp3_ = _tmp2_;
	result = _tmp1_ > _tmp3_;
	return result;
}

void
break_timer_daemon_ui_fragment_reset_ui (BreakTimerDaemonUIFragment* self)
{
	g_return_if_fail (self != NULL);
	break_timer_daemon_ui_fragment_hide_all_notifications (self);
}

void
break_timer_daemon_ui_fragment_request_ui_focus (BreakTimerDaemonUIFragment* self)
{
	g_return_if_fail (self != NULL);
	if (break_timer_daemon_ui_fragment_has_ui_focus (self)) {
		break_timer_daemon_ui_fragment_focus_started (self);
	} else {
		BreakTimerDaemonUIManager* _tmp0_;
		BreakTimerDaemonUtilFocusPriority _tmp1_;
		BreakTimerDaemonUtilFocusPriority _tmp2_;
		_tmp0_ = self->ui_manager;
		_tmp1_ = break_timer_daemon_ui_fragment_get_focus_priority (self);
		_tmp2_ = _tmp1_;
		break_timer_daemon_util_simple_focus_manager_request_focus ((BreakTimerDaemonUtilSimpleFocusManager*) _tmp0_, (BreakTimerDaemonUtilIFocusable*) self, _tmp2_);
	}
}

void
break_timer_daemon_ui_fragment_release_ui_focus (BreakTimerDaemonUIFragment* self)
{
	BreakTimerDaemonUIManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->ui_manager;
	break_timer_daemon_util_simple_focus_manager_release_focus ((BreakTimerDaemonUtilSimpleFocusManager*) _tmp0_, (BreakTimerDaemonUtilIFocusable*) self);
}

void
break_timer_daemon_ui_fragment_play_sound_from_id (BreakTimerDaemonUIFragment* self,
                                                   const gchar* event_id)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (event_id != NULL);
	if (break_timer_daemon_ui_fragment_has_ui_focus (self)) {
		BreakTimerDaemonUIManager* _tmp0_;
		_tmp0_ = self->ui_manager;
		break_timer_daemon_ui_manager_play_sound_from_id (_tmp0_, event_id);
	}
}

void
break_timer_daemon_ui_fragment_lock_screen (BreakTimerDaemonUIFragment* self)
{
	g_return_if_fail (self != NULL);
	if (break_timer_daemon_ui_fragment_has_ui_focus (self)) {
		BreakTimerDaemonUIManager* _tmp0_;
		_tmp0_ = self->ui_manager;
		break_timer_daemon_ui_manager_lock_screen (_tmp0_);
	}
}

static void
break_timer_daemon_ui_fragment_hide_all_notifications (BreakTimerDaemonUIFragment* self)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	gint _tmp1_ = 0;
	gchar** _tmp2_;
	gint _tmp2__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = break_timer_daemon_ui_fragment_get_notification_ids (self, &_tmp1_);
	_tmp0__length1 = _tmp1_;
	_tmp2_ = _tmp0_;
	_tmp2__length1 = _tmp0__length1;
	{
		gchar** id_collection = NULL;
		gint id_collection_length1 = 0;
		gint _id_collection_size_ = 0;
		gint id_it = 0;
		id_collection = _tmp2_;
		id_collection_length1 = _tmp2__length1;
		for (id_it = 0; id_it < id_collection_length1; id_it = id_it + 1) {
			gchar* _tmp3_;
			gchar* id = NULL;
			_tmp3_ = g_strdup (id_collection[id_it]);
			id = _tmp3_;
			{
				const gchar* _tmp4_;
				_tmp4_ = id;
				break_timer_daemon_ui_fragment_hide_notification (self, _tmp4_);
				_g_free0 (id);
			}
		}
	}
}

void
break_timer_daemon_ui_fragment_show_notification (BreakTimerDaemonUIFragment* self,
                                                  const gchar* id,
                                                  GNotification* notification)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	g_return_if_fail (notification != NULL);
	if (break_timer_daemon_ui_fragment_has_ui_focus (self)) {
		BreakTimerDaemonUIManager* _tmp0_;
		_tmp0_ = self->ui_manager;
		break_timer_daemon_ui_manager_show_notification (_tmp0_, id, notification);
	}
}

void
break_timer_daemon_ui_fragment_show_transient_notification (BreakTimerDaemonUIFragment* self,
                                                            const gchar* id,
                                                            GNotification* notification)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	g_return_if_fail (notification != NULL);
	if (break_timer_daemon_ui_fragment_has_ui_focus (self)) {
		BreakTimerDaemonUIManager* _tmp0_;
		_tmp0_ = self->ui_manager;
		break_timer_daemon_ui_manager_show_transient_notification (_tmp0_, id, notification);
	}
}

void
break_timer_daemon_ui_fragment_hide_notification (BreakTimerDaemonUIFragment* self,
                                                  const gchar* id)
{
	BreakTimerDaemonUIManager* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (id != NULL);
	_tmp0_ = self->ui_manager;
	break_timer_daemon_ui_manager_hide_notification (_tmp0_, id);
}

static void
break_timer_daemon_ui_fragment_real_focus_started (BreakTimerDaemonUIFragment* self)
{
	g_critical ("Type `%s' does not implement abstract method `break_timer_daemon_ui_fragment_focus_started'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
break_timer_daemon_ui_fragment_focus_started (BreakTimerDaemonUIFragment* self)
{
	BreakTimerDaemonUIFragmentClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = BREAK_TIMER_DAEMON_UI_FRAGMENT_GET_CLASS (self);
	if (_klass_->focus_started) {
		_klass_->focus_started (self);
	}
}

static void
break_timer_daemon_ui_fragment_real_focus_stopped (BreakTimerDaemonUIFragment* self)
{
	g_critical ("Type `%s' does not implement abstract method `break_timer_daemon_ui_fragment_focus_stopped'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
break_timer_daemon_ui_fragment_focus_stopped (BreakTimerDaemonUIFragment* self)
{
	BreakTimerDaemonUIFragmentClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = BREAK_TIMER_DAEMON_UI_FRAGMENT_GET_CLASS (self);
	if (_klass_->focus_stopped) {
		_klass_->focus_stopped (self);
	}
}

BreakTimerDaemonUIFragment*
break_timer_daemon_ui_fragment_construct (GType object_type)
{
	BreakTimerDaemonUIFragment * self = NULL;
	self = (BreakTimerDaemonUIFragment*) g_object_new (object_type, NULL);
	return self;
}

BreakTimerDaemonUtilFocusPriority
break_timer_daemon_ui_fragment_get_focus_priority (BreakTimerDaemonUIFragment* self)
{
	BreakTimerDaemonUIFragmentClass* _klass_;
	g_return_val_if_fail (self != NULL, 0);
	_klass_ = BREAK_TIMER_DAEMON_UI_FRAGMENT_GET_CLASS (self);
	if (_klass_->get_focus_priority) {
		return _klass_->get_focus_priority (self);
	}
	return 0;
}

static BreakTimerDaemonUtilFocusPriority
break_timer_daemon_ui_fragment_real_get_focus_priority (BreakTimerDaemonUIFragment* base)
{
	BreakTimerDaemonUtilFocusPriority result;
	BreakTimerDaemonUIFragment* self;
	self = base;
	result = self->priv->_focus_priority;
	return result;
}

gchar**
break_timer_daemon_ui_fragment_get_notification_ids (BreakTimerDaemonUIFragment* self,
                                                     gint* result_length1)
{
	BreakTimerDaemonUIFragmentClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = BREAK_TIMER_DAEMON_UI_FRAGMENT_GET_CLASS (self);
	if (_klass_->get_notification_ids) {
		return _klass_->get_notification_ids (self, result_length1);
	}
	return NULL;
}

static gchar**
break_timer_daemon_ui_fragment_real_get_notification_ids (BreakTimerDaemonUIFragment* base,
                                                          gint* result_length1)
{
	gchar** result;
	BreakTimerDaemonUIFragment* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = base;
	_tmp0_ = self->priv->_notification_ids;
	_tmp0__length1 = self->priv->_notification_ids_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
break_timer_daemon_ui_fragment_class_init (BreakTimerDaemonUIFragmentClass * klass,
                                           gpointer klass_data)
{
	break_timer_daemon_ui_fragment_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BreakTimerDaemonUIFragment_private_offset);
	((BreakTimerDaemonUIFragmentClass *) klass)->focus_started = (void (*) (BreakTimerDaemonUIFragment*)) break_timer_daemon_ui_fragment_real_focus_started;
	((BreakTimerDaemonUIFragmentClass *) klass)->focus_stopped = (void (*) (BreakTimerDaemonUIFragment*)) break_timer_daemon_ui_fragment_real_focus_stopped;
	BREAK_TIMER_DAEMON_UI_FRAGMENT_CLASS (klass)->get_focus_priority = (BreakTimerDaemonUtilFocusPriority (*) (BreakTimerDaemonUIFragment*)) break_timer_daemon_ui_fragment_real_get_focus_priority;
	BREAK_TIMER_DAEMON_UI_FRAGMENT_CLASS (klass)->get_notification_ids = (gchar** (*) (BreakTimerDaemonUIFragment*, gint*)) break_timer_daemon_ui_fragment_real_get_notification_ids;
	G_OBJECT_CLASS (klass)->get_property = _vala_break_timer_daemon_ui_fragment_get_property;
	G_OBJECT_CLASS (klass)->finalize = break_timer_daemon_ui_fragment_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), BREAK_TIMER_DAEMON_UI_FRAGMENT_FOCUS_PRIORITY_PROPERTY, break_timer_daemon_ui_fragment_properties[BREAK_TIMER_DAEMON_UI_FRAGMENT_FOCUS_PRIORITY_PROPERTY] = g_param_spec_enum ("focus-priority", "focus-priority", "focus-priority", BREAK_TIMER_DAEMON_UTIL_TYPE_FOCUS_PRIORITY, BREAK_TIMER_DAEMON_UTIL_FOCUS_PRIORITY_LOW, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), BREAK_TIMER_DAEMON_UI_FRAGMENT_NOTIFICATION_IDS_PROPERTY, break_timer_daemon_ui_fragment_properties[BREAK_TIMER_DAEMON_UI_FRAGMENT_NOTIFICATION_IDS_PROPERTY] = g_param_spec_boxed ("notification-ids", "notification-ids", "notification-ids", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
break_timer_daemon_ui_fragment_break_timer_daemon_util_ifocusable_interface_init (BreakTimerDaemonUtilIFocusableIface * iface,
                                                                                  gpointer iface_data)
{
	break_timer_daemon_ui_fragment_break_timer_daemon_util_ifocusable_parent_iface = g_type_interface_peek_parent (iface);
	iface->focus_started = (void (*) (BreakTimerDaemonUtilIFocusable*)) break_timer_daemon_ui_fragment_focus_started;
	iface->focus_stopped = (void (*) (BreakTimerDaemonUtilIFocusable*)) break_timer_daemon_ui_fragment_focus_stopped;
}

static void
break_timer_daemon_ui_fragment_instance_init (BreakTimerDaemonUIFragment * self,
                                              gpointer klass)
{
	gchar** _tmp0_;
	self->priv = break_timer_daemon_ui_fragment_get_instance_private (self);
	self->priv->_focus_priority = BREAK_TIMER_DAEMON_UTIL_FOCUS_PRIORITY_LOW;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->priv->_notification_ids = _tmp0_;
	self->priv->_notification_ids_length1 = 0;
	self->priv->__notification_ids_size_ = self->priv->_notification_ids_length1;
}

static void
break_timer_daemon_ui_fragment_finalize (GObject * obj)
{
	BreakTimerDaemonUIFragment * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BREAK_TIMER_DAEMON_TYPE_UI_FRAGMENT, BreakTimerDaemonUIFragment);
	_g_object_unref0 (self->ui_manager);
	self->priv->_notification_ids = (_vala_array_free (self->priv->_notification_ids, self->priv->_notification_ids_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (break_timer_daemon_ui_fragment_parent_class)->finalize (obj);
}

/**
 * Provides a simple interface for UIManager to create notifications and
 * overlays.
 */
static GType
break_timer_daemon_ui_fragment_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BreakTimerDaemonUIFragmentClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) break_timer_daemon_ui_fragment_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BreakTimerDaemonUIFragment), 0, (GInstanceInitFunc) break_timer_daemon_ui_fragment_instance_init, NULL };
	static const GInterfaceInfo break_timer_daemon_util_ifocusable_info = { (GInterfaceInitFunc) break_timer_daemon_ui_fragment_break_timer_daemon_util_ifocusable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType break_timer_daemon_ui_fragment_type_id;
	break_timer_daemon_ui_fragment_type_id = g_type_register_static (G_TYPE_OBJECT, "BreakTimerDaemonUIFragment", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	g_type_add_interface_static (break_timer_daemon_ui_fragment_type_id, BREAK_TIMER_DAEMON_UTIL_TYPE_IFOCUSABLE, &break_timer_daemon_util_ifocusable_info);
	BreakTimerDaemonUIFragment_private_offset = g_type_add_instance_private (break_timer_daemon_ui_fragment_type_id, sizeof (BreakTimerDaemonUIFragmentPrivate));
	return break_timer_daemon_ui_fragment_type_id;
}

GType
break_timer_daemon_ui_fragment_get_type (void)
{
	static volatile gsize break_timer_daemon_ui_fragment_type_id__once = 0;
	if (g_once_init_enter (&break_timer_daemon_ui_fragment_type_id__once)) {
		GType break_timer_daemon_ui_fragment_type_id;
		break_timer_daemon_ui_fragment_type_id = break_timer_daemon_ui_fragment_get_type_once ();
		g_once_init_leave (&break_timer_daemon_ui_fragment_type_id__once, break_timer_daemon_ui_fragment_type_id);
	}
	return break_timer_daemon_ui_fragment_type_id__once;
}

static void
_vala_break_timer_daemon_ui_fragment_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	BreakTimerDaemonUIFragment * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BREAK_TIMER_DAEMON_TYPE_UI_FRAGMENT, BreakTimerDaemonUIFragment);
	switch (property_id) {
		case BREAK_TIMER_DAEMON_UI_FRAGMENT_FOCUS_PRIORITY_PROPERTY:
		g_value_set_enum (value, break_timer_daemon_ui_fragment_get_focus_priority (self));
		break;
		case BREAK_TIMER_DAEMON_UI_FRAGMENT_NOTIFICATION_IDS_PROPERTY:
		{
			int length;
			g_value_set_boxed (value, break_timer_daemon_ui_fragment_get_notification_ids (self, &length));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

