/* AppSettingsView.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from AppSettingsView.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 <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <switchboard.h>
#include <gio/gdesktopappinfo.h>
#include <granite-7.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.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  {
	WIDGETS_APP_SETTINGS_VIEW_0_PROPERTY,
	WIDGETS_APP_SETTINGS_VIEW_NUM_PROPERTIES
};
static GParamSpec* widgets_app_settings_view_properties[WIDGETS_APP_SETTINGS_VIEW_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 _WidgetsAppSettingsViewPrivate {
	WidgetsSettingsOption* bubbles_option;
	WidgetsSettingsOption* sound_option;
	WidgetsSettingsOption* remember_option;
};

static gint WidgetsAppSettingsView_private_offset;
static gpointer widgets_app_settings_view_parent_class = NULL;

static void widgets_app_settings_view_remove_bindings (WidgetsAppSettingsView* self);
static void widgets_app_settings_view_update_selected_app (WidgetsAppSettingsView* self);
static GObject * widgets_app_settings_view_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _widgets_app_settings_view___lambda9_ (WidgetsAppSettingsView* self);
static void __widgets_app_settings_view___lambda9__g_object_notify (GObject* _sender,
                                                             GParamSpec* pspec,
                                                             gpointer self);
static void widgets_app_settings_view_finalize (GObject * obj);
static GType widgets_app_settings_view_get_type_once (void);

static inline gpointer
widgets_app_settings_view_get_instance_private (WidgetsAppSettingsView* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsAppSettingsView_private_offset);
}

static void
widgets_app_settings_view_remove_bindings (WidgetsAppSettingsView* self)
{
	WidgetsSettingsOption* _tmp0_;
	WidgetsSettingsOption* _tmp1_;
	WidgetsSettingsOption* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->bubbles_option;
	g_settings_unbind ((GObject*) _tmp0_, "active");
	_tmp1_ = self->priv->sound_option;
	g_settings_unbind ((GObject*) _tmp1_, "active");
	_tmp2_ = self->priv->remember_option;
	g_settings_unbind ((GObject*) _tmp2_, "active");
}

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

static void
widgets_app_settings_view_update_selected_app (WidgetsAppSettingsView* self)
{
	BackendNotifyManager* notify_manager = NULL;
	BackendNotifyManager* _tmp0_;
	BackendNotifyManager* _tmp1_;
	gchar* app_id = NULL;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	BackendApp* selected_app = NULL;
	GeeHashMap* _tmp5_;
	GeeHashMap* _tmp6_;
	gpointer _tmp7_;
	GSettings* _tmp8_;
	GSettings* _tmp9_;
	WidgetsSettingsOption* _tmp10_;
	GSettings* _tmp11_;
	GSettings* _tmp12_;
	WidgetsSettingsOption* _tmp13_;
	GSettings* _tmp14_;
	GSettings* _tmp15_;
	WidgetsSettingsOption* _tmp16_;
	GDesktopAppInfo* _tmp17_;
	GDesktopAppInfo* _tmp18_;
	const gchar* _tmp19_;
	GDesktopAppInfo* _tmp20_;
	GDesktopAppInfo* _tmp21_;
	GIcon* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = backend_notify_manager_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	notify_manager = _tmp1_;
	_tmp2_ = backend_notify_manager_get_selected_app_id (notify_manager);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup (_tmp3_);
	app_id = _tmp4_;
	_tmp5_ = backend_notify_manager_get_apps (notify_manager);
	_tmp6_ = _tmp5_;
	_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, app_id);
	selected_app = (BackendApp*) _tmp7_;
	_tmp8_ = backend_app_get_settings (selected_app);
	_tmp9_ = _tmp8_;
	_tmp10_ = self->priv->bubbles_option;
	g_settings_bind (_tmp9_, "bubbles", (GObject*) _tmp10_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp11_ = backend_app_get_settings (selected_app);
	_tmp12_ = _tmp11_;
	_tmp13_ = self->priv->sound_option;
	g_settings_bind (_tmp12_, "sounds", (GObject*) _tmp13_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp14_ = backend_app_get_settings (selected_app);
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->remember_option;
	g_settings_bind (_tmp15_, "remember", (GObject*) _tmp16_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp17_ = backend_app_get_app_info (selected_app);
	_tmp18_ = _tmp17_;
	_tmp19_ = g_app_info_get_display_name ((GAppInfo*) _tmp18_);
	switchboard_settings_page_set_title ((SwitchboardSettingsPage*) self, _tmp19_);
	_tmp20_ = backend_app_get_app_info (selected_app);
	_tmp21_ = _tmp20_;
	_tmp22_ = g_app_info_get_icon ((GAppInfo*) _tmp21_);
	switchboard_settings_page_set_icon ((SwitchboardSettingsPage*) self, _tmp22_);
	_g_object_unref0 (selected_app);
	_g_free0 (app_id);
	_g_object_unref0 (notify_manager);
}

WidgetsAppSettingsView*
widgets_app_settings_view_construct (GType object_type)
{
	WidgetsAppSettingsView * self = NULL;
	self = (WidgetsAppSettingsView*) switchboard_settings_page_construct (object_type);
	return self;
}

WidgetsAppSettingsView*
widgets_app_settings_view_new (void)
{
	return widgets_app_settings_view_construct (WIDGETS_TYPE_APP_SETTINGS_VIEW);
}

static void
_widgets_app_settings_view___lambda9_ (WidgetsAppSettingsView* self)
{
	widgets_app_settings_view_remove_bindings (self);
	widgets_app_settings_view_update_selected_app (self);
}

static void
__widgets_app_settings_view___lambda9__g_object_notify (GObject* _sender,
                                                        GParamSpec* pspec,
                                                        gpointer self)
{
	_widgets_app_settings_view___lambda9_ ((WidgetsAppSettingsView*) self);
}

static GObject *
widgets_app_settings_view_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsAppSettingsView * self;
	GraniteHeaderLabel* dnd_header = NULL;
	gchar* _tmp0_;
	GraniteHeaderLabel* _tmp1_ = NULL;
	GtkInfoBar* dnd_infobar = NULL;
	GtkInfoBar* _tmp2_ = NULL;
	GtkInfoBar* _tmp3_;
	GraniteHeaderLabel* _tmp4_;
	GtkInfoBar* _tmp5_;
	WidgetsSettingsOption* _tmp6_;
	WidgetsSettingsOption* _tmp7_;
	WidgetsSettingsOption* _tmp8_;
	GtkBox* box = NULL;
	GtkBox* _tmp9_;
	GtkBox* _tmp10_;
	GtkInfoBar* _tmp11_;
	GtkBox* _tmp12_;
	WidgetsSettingsOption* _tmp13_;
	GtkBox* _tmp14_;
	WidgetsSettingsOption* _tmp15_;
	GtkBox* _tmp16_;
	WidgetsSettingsOption* _tmp17_;
	GtkBox* _tmp18_;
	BackendNotifyManager* _tmp19_;
	GSettings* _tmp20_;
	GtkInfoBar* _tmp21_;
	parent_class = G_OBJECT_CLASS (widgets_app_settings_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_APP_SETTINGS_VIEW, WidgetsAppSettingsView);
	_tmp0_ = g_strdup (_ ("Bubbles will be hidden and sounds will be silenced. System notificatio" \
"ns, such as volume and display brightness, will be unaffected."));
	_tmp1_ = granite_header_label_new (_ ("Do Not Disturb is active"));
	gtk_widget_set_halign ((GtkWidget*) _tmp1_, GTK_ALIGN_FILL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp1_, TRUE);
	granite_header_label_set_secondary_text (_tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_ref_sink (_tmp1_);
	dnd_header = _tmp1_;
	_tmp2_ = (GtkInfoBar*) gtk_info_bar_new ();
	gtk_info_bar_set_message_type (_tmp2_, GTK_MESSAGE_INFO);
	g_object_ref_sink (_tmp2_);
	dnd_infobar = _tmp2_;
	_tmp3_ = dnd_infobar;
	_tmp4_ = dnd_header;
	gtk_info_bar_add_child (_tmp3_, (GtkWidget*) _tmp4_);
	_tmp5_ = dnd_infobar;
	gtk_widget_add_css_class ((GtkWidget*) _tmp5_, GRANITE_STYLE_CLASS_FRAME);
	_tmp6_ = widgets_settings_option_new ("bubbles", _ ("Bubbles"), _ ("Bubbles appear in the top right corner of the display and disappear au" \
"tomatically."));
	g_object_ref_sink (_tmp6_);
	_g_object_unref0 (self->priv->bubbles_option);
	self->priv->bubbles_option = _tmp6_;
	_tmp7_ = widgets_settings_option_new ("sounds", _ ("Sounds"), _ ("Sounds play once when a new notification arrives."));
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->sound_option);
	self->priv->sound_option = _tmp7_;
	_tmp8_ = widgets_settings_option_new ("notify-center", _ ("Notification Center"), _ ("Show missed notifications in Notification Center."));
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->remember_option);
	self->priv->remember_option = _tmp8_;
	_tmp9_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp9_);
	box = _tmp9_;
	_tmp10_ = box;
	_tmp11_ = dnd_infobar;
	gtk_box_append (_tmp10_, (GtkWidget*) _tmp11_);
	_tmp12_ = box;
	_tmp13_ = self->priv->bubbles_option;
	gtk_box_append (_tmp12_, (GtkWidget*) _tmp13_);
	_tmp14_ = box;
	_tmp15_ = self->priv->sound_option;
	gtk_box_append (_tmp14_, (GtkWidget*) _tmp15_);
	_tmp16_ = box;
	_tmp17_ = self->priv->remember_option;
	gtk_box_append (_tmp16_, (GtkWidget*) _tmp17_);
	gtk_widget_add_css_class ((GtkWidget*) self, "notifications");
	_tmp18_ = box;
	switchboard_settings_page_set_child ((SwitchboardSettingsPage*) self, (GtkWidget*) _tmp18_);
	switchboard_settings_page_set_show_end_title_buttons ((SwitchboardSettingsPage*) self, TRUE);
	widgets_app_settings_view_update_selected_app (self);
	_tmp19_ = backend_notify_manager_get_default ();
	g_signal_connect_object ((GObject*) _tmp19_, "notify::selected-app-id", (GCallback) __widgets_app_settings_view___lambda9__g_object_notify, self, 0);
	_tmp20_ = notifications_plug_notify_settings;
	_tmp21_ = dnd_infobar;
	g_settings_bind (_tmp20_, "do-not-disturb", (GObject*) _tmp21_, "revealed", G_SETTINGS_BIND_GET);
	_g_object_unref0 (box);
	_g_object_unref0 (dnd_infobar);
	_g_object_unref0 (dnd_header);
	return obj;
}

static void
widgets_app_settings_view_class_init (WidgetsAppSettingsViewClass * klass,
                                      gpointer klass_data)
{
	GtkCssProvider* css_provider = NULL;
	GtkCssProvider* _tmp0_;
	GtkCssProvider* _tmp1_;
	GdkDisplay* _tmp2_;
	GtkCssProvider* _tmp3_;
	widgets_app_settings_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsAppSettingsView_private_offset);
	G_OBJECT_CLASS (klass)->constructor = widgets_app_settings_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_app_settings_view_finalize;
	_tmp0_ = gtk_css_provider_new ();
	css_provider = _tmp0_;
	_tmp1_ = css_provider;
	gtk_css_provider_load_from_resource (_tmp1_, "/io/elementary/settings/notifications/SettingsOption.css");
	_tmp2_ = gdk_display_get_default ();
	_tmp3_ = css_provider;
	gtk_style_context_add_provider_for_display (_tmp2_, (GtkStyleProvider*) _tmp3_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_g_object_unref0 (css_provider);
}

static void
widgets_app_settings_view_instance_init (WidgetsAppSettingsView * self,
                                         gpointer klass)
{
	self->priv = widgets_app_settings_view_get_instance_private (self);
}

static void
widgets_app_settings_view_finalize (GObject * obj)
{
	WidgetsAppSettingsView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_APP_SETTINGS_VIEW, WidgetsAppSettingsView);
	_g_object_unref0 (self->priv->bubbles_option);
	_g_object_unref0 (self->priv->sound_option);
	_g_object_unref0 (self->priv->remember_option);
	G_OBJECT_CLASS (widgets_app_settings_view_parent_class)->finalize (obj);
}

static GType
widgets_app_settings_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsAppSettingsViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_app_settings_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsAppSettingsView), 0, (GInstanceInitFunc) widgets_app_settings_view_instance_init, NULL };
	GType widgets_app_settings_view_type_id;
	widgets_app_settings_view_type_id = g_type_register_static (SWITCHBOARD_TYPE_SETTINGS_PAGE, "WidgetsAppSettingsView", &g_define_type_info, 0);
	WidgetsAppSettingsView_private_offset = g_type_add_instance_private (widgets_app_settings_view_type_id, sizeof (WidgetsAppSettingsViewPrivate));
	return widgets_app_settings_view_type_id;
}

GType
widgets_app_settings_view_get_type (void)
{
	static volatile gsize widgets_app_settings_view_type_id__once = 0;
	if (g_once_init_enter (&widgets_app_settings_view_type_id__once)) {
		GType widgets_app_settings_view_type_id;
		widgets_app_settings_view_type_id = widgets_app_settings_view_get_type_once ();
		g_once_init_leave (&widgets_app_settings_view_type_id__once, widgets_app_settings_view_type_id);
	}
	return widgets_app_settings_view_type_id__once;
}

