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

/*-
* Copyright (c) 2014-2017 elementary LLC. (http://launchpad.net/switchboard-plug-security-privacy)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*
* Authored by: Julien Spautz <spautz.julien@gmail.com>
*              Corentin Noël <corentin@elementaryos.org>
*/

#include "security-privacy.h"
#include <gio/gdesktopappinfo.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <granite-7.h>
#include <float.h>
#include <math.h>
#include <pango/pango.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  {
	APP_ROW_0_PROPERTY,
	APP_ROW_APP_INFO_PROPERTY,
	APP_ROW_NUM_PROPERTIES
};
static GParamSpec* app_row_properties[APP_ROW_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 _AppRowPrivate {
	GDesktopAppInfo* _app_info;
};

static gint AppRow_private_offset;
static gpointer app_row_parent_class = NULL;

static gchar* app_row_get_app_comment (AppRow* self);
static gchar* app_row_get_app_name (AppRow* self);
static gchar* app_row_get_icon_name (AppRow* self);
static GObject * app_row_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties);
static void app_row_finalize (GObject * obj);
static GType app_row_get_type_once (void);
static void _vala_app_row_get_property (GObject * object,
                                 guint property_id,
                                 GValue * value,
                                 GParamSpec * pspec);
static void _vala_app_row_set_property (GObject * object,
                                 guint property_id,
                                 const GValue * value,
                                 GParamSpec * pspec);

static inline gpointer
app_row_get_instance_private (AppRow* self)
{
	return G_STRUCT_MEMBER_P (self, AppRow_private_offset);
}

AppRow*
app_row_construct (GType object_type,
                   GDesktopAppInfo* app_info)
{
	AppRow * self = NULL;
	g_return_val_if_fail (app_info != NULL, NULL);
	self = (AppRow*) g_object_new (object_type, "app-info", app_info, NULL);
	return self;
}

AppRow*
app_row_new (GDesktopAppInfo* app_info)
{
	return app_row_construct (TYPE_APP_ROW, app_info);
}

static gchar*
app_row_get_app_comment (AppRow* self)
{
	gchar* comment = NULL;
	GDesktopAppInfo* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app_info;
	_tmp1_ = g_app_info_get_description ((GAppInfo*) _tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	comment = _tmp2_;
	_tmp3_ = comment;
	if (_tmp3_ == NULL) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("");
		_g_free0 (comment);
		comment = _tmp4_;
	}
	_tmp5_ = comment;
	_tmp6_ = g_markup_escape_text (_tmp5_, (gssize) -1);
	result = _tmp6_;
	_g_free0 (comment);
	return result;
}

static gchar*
app_row_get_app_name (AppRow* self)
{
	gchar* name = NULL;
	GDesktopAppInfo* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app_info;
	_tmp1_ = g_app_info_get_display_name ((GAppInfo*) _tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	name = _tmp2_;
	_tmp3_ = name;
	if (_tmp3_ == NULL) {
		GDesktopAppInfo* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp4_ = self->priv->_app_info;
		_tmp5_ = g_app_info_get_name ((GAppInfo*) _tmp4_);
		_tmp6_ = g_strdup (_tmp5_);
		_g_free0 (name);
		name = _tmp6_;
	}
	_tmp7_ = name;
	_tmp8_ = g_markup_escape_text (_tmp7_, (gssize) -1);
	result = _tmp8_;
	_g_free0 (name);
	return result;
}

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

static gchar*
app_row_get_icon_name (AppRow* self)
{
	GtkIconTheme* icon_theme = NULL;
	GdkDisplay* _tmp0_;
	GtkIconTheme* _tmp1_;
	GtkIconTheme* _tmp2_;
	GtkIconTheme* _tmp3_;
	GDesktopAppInfo* _tmp4_;
	GIcon* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gboolean _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = gtk_icon_theme_get_for_display (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	icon_theme = _tmp2_;
	_tmp3_ = icon_theme;
	_tmp4_ = self->priv->_app_info;
	_tmp5_ = g_app_info_get_icon ((GAppInfo*) _tmp4_);
	_tmp6_ = g_icon_to_string (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gtk_icon_theme_has_icon (_tmp3_, _tmp7_);
	_g_free0 (_tmp7_);
	if (_tmp8_) {
		GDesktopAppInfo* _tmp9_;
		GIcon* _tmp10_;
		gchar* _tmp11_;
		_tmp9_ = self->priv->_app_info;
		_tmp10_ = g_app_info_get_icon ((GAppInfo*) _tmp9_);
		_tmp11_ = g_icon_to_string (_tmp10_);
		result = _tmp11_;
		_g_object_unref0 (icon_theme);
		return result;
	} else {
		gchar* _tmp12_;
		_tmp12_ = g_strdup ("application-default-icon");
		result = _tmp12_;
		_g_object_unref0 (icon_theme);
		return result;
	}
}

GDesktopAppInfo*
app_row_get_app_info (AppRow* self)
{
	GDesktopAppInfo* result;
	GDesktopAppInfo* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app_info;
	result = _tmp0_;
	return result;
}

static void
app_row_set_app_info (AppRow* self,
                      GDesktopAppInfo* value)
{
	GDesktopAppInfo* old_value;
	g_return_if_fail (self != NULL);
	old_value = app_row_get_app_info (self);
	if (old_value != value) {
		GDesktopAppInfo* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_app_info);
		self->priv->_app_info = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, app_row_properties[APP_ROW_APP_INFO_PROPERTY]);
	}
}

static GObject *
app_row_constructor (GType type,
                     guint n_construct_properties,
                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	AppRow * self;
	GtkImage* image = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GtkImage* _tmp2_ = NULL;
	GtkImage* _tmp3_;
	GtkLabel* app_name = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GtkLabel* _tmp6_;
	GtkLabel* _tmp7_;
	GtkLabel* _tmp8_;
	GtkLabel* _tmp9_;
	GtkLabel* _tmp10_;
	GtkLabel* app_comment = NULL;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	GtkLabel* _tmp17_;
	GtkLabel* _tmp18_;
	GtkLabel* _tmp19_;
	GtkLabel* _tmp20_;
	GtkLabel* _tmp21_;
	GtkGrid* _tmp22_ = NULL;
	GtkGrid* _tmp23_;
	GtkGrid* _tmp24_;
	GtkImage* _tmp25_;
	GtkGrid* _tmp26_;
	GtkLabel* _tmp27_;
	GtkGrid* _tmp28_;
	GtkLabel* _tmp29_;
	GtkGrid* _tmp30_;
	parent_class = G_OBJECT_CLASS (app_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_APP_ROW, AppRow);
	_tmp0_ = app_row_get_icon_name (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = (GtkImage*) gtk_image_new_from_icon_name (_tmp1_);
	gtk_image_set_pixel_size (_tmp2_, 32);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	image = _tmp3_;
	_tmp4_ = app_row_get_app_name (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = (GtkLabel*) gtk_label_new (_tmp5_);
	g_object_ref_sink (_tmp6_);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	app_name = _tmp7_;
	_tmp8_ = app_name;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, GRANITE_STYLE_CLASS_H3_LABEL);
	_tmp9_ = app_name;
	gtk_label_set_xalign (_tmp9_, (gfloat) 0);
	_tmp10_ = app_name;
	gtk_label_set_ellipsize (_tmp10_, PANGO_ELLIPSIZE_END);
	_tmp11_ = app_row_get_app_comment (self);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strconcat ("<span font_size='small'>", _tmp12_, NULL);
	_tmp14_ = _tmp13_;
	_tmp15_ = g_strconcat (_tmp14_, "</span>", NULL);
	_tmp16_ = _tmp15_;
	_tmp17_ = (GtkLabel*) gtk_label_new (_tmp16_);
	g_object_ref_sink (_tmp17_);
	_tmp18_ = _tmp17_;
	_g_free0 (_tmp16_);
	_g_free0 (_tmp14_);
	_g_free0 (_tmp12_);
	app_comment = _tmp18_;
	_tmp19_ = app_comment;
	gtk_label_set_xalign (_tmp19_, (gfloat) 0);
	_tmp20_ = app_comment;
	gtk_label_set_use_markup (_tmp20_, TRUE);
	_tmp21_ = app_comment;
	gtk_label_set_ellipsize (_tmp21_, PANGO_ELLIPSIZE_END);
	_tmp22_ = (GtkGrid*) gtk_grid_new ();
	gtk_widget_set_margin_top ((GtkWidget*) _tmp22_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp22_, 12);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp22_, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp22_, 10);
	g_object_ref_sink (_tmp22_);
	_g_object_unref0 (self->main_grid);
	self->main_grid = _tmp22_;
	_tmp23_ = self->main_grid;
	gtk_grid_set_column_spacing (_tmp23_, 12);
	_tmp24_ = self->main_grid;
	_tmp25_ = image;
	gtk_grid_attach (_tmp24_, (GtkWidget*) _tmp25_, 0, 0, 1, 2);
	_tmp26_ = self->main_grid;
	_tmp27_ = app_name;
	gtk_grid_attach (_tmp26_, (GtkWidget*) _tmp27_, 1, 0, 1, 1);
	_tmp28_ = self->main_grid;
	_tmp29_ = app_comment;
	gtk_grid_attach (_tmp28_, (GtkWidget*) _tmp29_, 1, 1, 1, 1);
	_tmp30_ = self->main_grid;
	gtk_list_box_row_set_child ((GtkListBoxRow*) self, (GtkWidget*) _tmp30_);
	_g_object_unref0 (app_comment);
	_g_object_unref0 (app_name);
	_g_object_unref0 (image);
	return obj;
}

static void
app_row_class_init (AppRowClass * klass,
                    gpointer klass_data)
{
	app_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &AppRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_app_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_app_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = app_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = app_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), APP_ROW_APP_INFO_PROPERTY, app_row_properties[APP_ROW_APP_INFO_PROPERTY] = g_param_spec_object ("app-info", "app-info", "app-info", G_TYPE_DESKTOP_APP_INFO, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
app_row_instance_init (AppRow * self,
                       gpointer klass)
{
	self->priv = app_row_get_instance_private (self);
}

static void
app_row_finalize (GObject * obj)
{
	AppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_APP_ROW, AppRow);
	_g_object_unref0 (self->priv->_app_info);
	_g_object_unref0 (self->main_grid);
	G_OBJECT_CLASS (app_row_parent_class)->finalize (obj);
}

static GType
app_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (AppRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) app_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AppRow), 0, (GInstanceInitFunc) app_row_instance_init, NULL };
	GType app_row_type_id;
	app_row_type_id = g_type_register_static (gtk_list_box_row_get_type (), "AppRow", &g_define_type_info, 0);
	AppRow_private_offset = g_type_add_instance_private (app_row_type_id, sizeof (AppRowPrivate));
	return app_row_type_id;
}

GType
app_row_get_type (void)
{
	static volatile gsize app_row_type_id__once = 0;
	if (g_once_init_enter (&app_row_type_id__once)) {
		GType app_row_type_id;
		app_row_type_id = app_row_get_type_once ();
		g_once_init_leave (&app_row_type_id__once, app_row_type_id);
	}
	return app_row_type_id__once;
}

static void
_vala_app_row_get_property (GObject * object,
                            guint property_id,
                            GValue * value,
                            GParamSpec * pspec)
{
	AppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_APP_ROW, AppRow);
	switch (property_id) {
		case APP_ROW_APP_INFO_PROPERTY:
		g_value_set_object (value, app_row_get_app_info (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_app_row_set_property (GObject * object,
                            guint property_id,
                            const GValue * value,
                            GParamSpec * pspec)
{
	AppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_APP_ROW, AppRow);
	switch (property_id) {
		case APP_ROW_APP_INFO_PROPERTY:
		app_row_set_app_info (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

