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

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

#include "io.elementary.settings.sound.h"
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <granite-7.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <float.h>
#include <math.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  {
	SOUND_APPLICATIONS_PANEL_0_PROPERTY,
	SOUND_APPLICATIONS_PANEL_NUM_PROPERTIES
};
static GParamSpec* sound_applications_panel_properties[SOUND_APPLICATIONS_PANEL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Block1Data {
	int _ref_count_;
	SoundApplicationsPanel* self;
	SoundPulseAudioManager* pulse_audio_manager;
};

static gpointer sound_applications_panel_parent_class = NULL;

static GtkWidget* sound_applications_panel_widget_create_func (SoundApplicationsPanel* self,
                                                        GObject* item);
static GObject * sound_applications_panel_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static GtkWidget* _sound_applications_panel_widget_create_func_gtk_list_box_create_widget_func (GObject* item,
                                                                                         gpointer self);
static void _sound_applications_panel___lambda21_ (Block1Data* _data1_);
static void __sound_applications_panel___lambda21__gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static GType sound_applications_panel_get_type_once (void);

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

static GtkWidget*
sound_applications_panel_widget_create_func (SoundApplicationsPanel* self,
                                             GObject* item)
{
	SoundApp* app = NULL;
	SoundApp* _tmp0_;
	SoundAppRow* app_row = NULL;
	SoundAppRow* _tmp1_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (item, SOUND_TYPE_APP, SoundApp));
	app = _tmp0_;
	_tmp1_ = sound_app_row_new ();
	g_object_ref_sink (_tmp1_);
	app_row = _tmp1_;
	sound_app_row_bind_app (app_row, app);
	result = (GtkWidget*) app_row;
	_g_object_unref0 (app);
	return result;
}

SoundApplicationsPanel*
sound_applications_panel_construct (GType object_type)
{
	SoundApplicationsPanel * self = NULL;
	self = (SoundApplicationsPanel*) g_object_new (object_type, NULL);
	return self;
}

SoundApplicationsPanel*
sound_applications_panel_new (void)
{
	return sound_applications_panel_construct (SOUND_TYPE_APPLICATIONS_PANEL);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		SoundApplicationsPanel* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->pulse_audio_manager);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static GtkWidget*
_sound_applications_panel_widget_create_func_gtk_list_box_create_widget_func (GObject* item,
                                                                              gpointer self)
{
	GtkWidget* result;
	result = sound_applications_panel_widget_create_func ((SoundApplicationsPanel*) self, item);
	return result;
}

static void
_sound_applications_panel___lambda21_ (Block1Data* _data1_)
{
	SoundApplicationsPanel* self;
	self = _data1_->self;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				SoundPulseAudioManager* _tmp2_;
				GListStore* _tmp3_;
				GListStore* _tmp4_;
				SoundPulseAudioManager* _tmp5_;
				SoundPulseAudioManager* _tmp6_;
				GListStore* _tmp7_;
				GListStore* _tmp8_;
				GObject* _tmp9_;
				SoundApp* _tmp10_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = _data1_->pulse_audio_manager;
				_tmp3_ = sound_pulse_audio_manager_get_apps (_tmp2_);
				_tmp4_ = _tmp3_;
				if (!(((guint) i) < g_list_model_get_n_items ((GListModel*) _tmp4_))) {
					break;
				}
				_tmp5_ = _data1_->pulse_audio_manager;
				_tmp6_ = _data1_->pulse_audio_manager;
				_tmp7_ = sound_pulse_audio_manager_get_apps (_tmp6_);
				_tmp8_ = _tmp7_;
				_tmp9_ = g_list_model_get_item ((GListModel*) _tmp8_, (guint) i);
				_tmp10_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, SOUND_TYPE_APP, SoundApp);
				sound_pulse_audio_manager_change_application_volume (_tmp5_, _tmp10_, (gdouble) 1);
				_g_object_unref0 (_tmp10_);
			}
		}
	}
}

static void
__sound_applications_panel___lambda21__gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	_sound_applications_panel___lambda21_ (self);
}

static GObject *
sound_applications_panel_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SoundApplicationsPanel * self;
	Block1Data* _data1_;
	SoundPulseAudioManager* _tmp0_;
	SoundPulseAudioManager* _tmp1_;
	GranitePlaceholder* placeholder = NULL;
	gchar* _tmp2_;
	GranitePlaceholder* _tmp3_ = NULL;
	GtkListBox* list_box = NULL;
	GtkListBox* _tmp4_ = NULL;
	GtkListBox* _tmp5_;
	SoundPulseAudioManager* _tmp6_;
	GListStore* _tmp7_;
	GListStore* _tmp8_;
	GtkListBox* _tmp9_;
	GranitePlaceholder* _tmp10_;
	GtkListBox* _tmp11_;
	GtkScrolledWindow* scrolled_window = NULL;
	GtkListBox* _tmp12_;
	GtkWidget* _tmp13_;
	GtkScrolledWindow* _tmp14_ = NULL;
	GtkFrame* frame = NULL;
	GtkScrolledWindow* _tmp15_;
	GtkWidget* _tmp16_;
	GtkFrame* _tmp17_ = NULL;
	GtkButton* reset_button = NULL;
	GtkButton* _tmp18_ = NULL;
	GtkFrame* _tmp19_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	parent_class = G_OBJECT_CLASS (sound_applications_panel_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SOUND_TYPE_APPLICATIONS_PANEL, SoundApplicationsPanel);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = sound_pulse_audio_manager_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data1_->pulse_audio_manager = _tmp1_;
	_tmp2_ = g_strdup (_ ("Applications emitting sounds will automatically appear here"));
	_tmp3_ = granite_placeholder_new (_ ("No applications currently emitting sounds"));
	granite_placeholder_set_description (_tmp3_, _tmp2_);
	_g_free0 (_tmp2_);
	g_object_ref_sink (_tmp3_);
	placeholder = _tmp3_;
	_tmp4_ = (GtkListBox*) gtk_list_box_new ();
	gtk_list_box_set_selection_mode (_tmp4_, GTK_SELECTION_NONE);
	g_object_ref_sink (_tmp4_);
	list_box = _tmp4_;
	_tmp5_ = list_box;
	_tmp6_ = _data1_->pulse_audio_manager;
	_tmp7_ = sound_pulse_audio_manager_get_apps (_tmp6_);
	_tmp8_ = _tmp7_;
	gtk_list_box_bind_model (_tmp5_, (GListModel*) _tmp8_, _sound_applications_panel_widget_create_func_gtk_list_box_create_widget_func, g_object_ref (self), g_object_unref);
	_tmp9_ = list_box;
	_tmp10_ = placeholder;
	gtk_list_box_set_placeholder (_tmp9_, (GtkWidget*) _tmp10_);
	_tmp11_ = list_box;
	gtk_widget_add_css_class ((GtkWidget*) _tmp11_, GRANITE_STYLE_CLASS_RICH_LIST);
	_tmp12_ = list_box;
	_tmp13_ = _g_object_ref0 ((GtkWidget*) _tmp12_);
	_tmp14_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	gtk_scrolled_window_set_child (_tmp14_, _tmp13_);
	_g_object_unref0 (_tmp13_);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp14_, TRUE);
	g_object_ref_sink (_tmp14_);
	scrolled_window = _tmp14_;
	_tmp15_ = scrolled_window;
	_tmp16_ = _g_object_ref0 ((GtkWidget*) _tmp15_);
	_tmp17_ = (GtkFrame*) gtk_frame_new (NULL);
	gtk_frame_set_child (_tmp17_, _tmp16_);
	_g_object_unref0 (_tmp16_);
	g_object_ref_sink (_tmp17_);
	frame = _tmp17_;
	_tmp18_ = (GtkButton*) gtk_button_new_with_label (_ ("Reset all apps to default"));
	gtk_widget_set_halign ((GtkWidget*) _tmp18_, GTK_ALIGN_END);
	g_object_ref_sink (_tmp18_);
	reset_button = _tmp18_;
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	gtk_box_set_spacing ((GtkBox*) self, 12);
	_tmp19_ = frame;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp19_);
	_tmp20_ = reset_button;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp20_);
	_tmp21_ = reset_button;
	g_signal_connect_data (_tmp21_, "clicked", (GCallback) __sound_applications_panel___lambda21__gtk_button_clicked, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_g_object_unref0 (reset_button);
	_g_object_unref0 (frame);
	_g_object_unref0 (scrolled_window);
	_g_object_unref0 (list_box);
	_g_object_unref0 (placeholder);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return obj;
}

static void
sound_applications_panel_class_init (SoundApplicationsPanelClass * klass,
                                     gpointer klass_data)
{
	sound_applications_panel_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = sound_applications_panel_constructor;
}

static void
sound_applications_panel_instance_init (SoundApplicationsPanel * self,
                                        gpointer klass)
{
}

static GType
sound_applications_panel_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SoundApplicationsPanelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sound_applications_panel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SoundApplicationsPanel), 0, (GInstanceInitFunc) sound_applications_panel_instance_init, NULL };
	GType sound_applications_panel_type_id;
	sound_applications_panel_type_id = g_type_register_static (gtk_box_get_type (), "SoundApplicationsPanel", &g_define_type_info, 0);
	return sound_applications_panel_type_id;
}

GType
sound_applications_panel_get_type (void)
{
	static volatile gsize sound_applications_panel_type_id__once = 0;
	if (g_once_init_enter (&sound_applications_panel_type_id__once)) {
		GType sound_applications_panel_type_id;
		sound_applications_panel_type_id = sound_applications_panel_get_type_once ();
		g_once_init_leave (&sound_applications_panel_type_id__once, sound_applications_panel_type_id);
	}
	return sound_applications_panel_type_id__once;
}

