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

/*
* Copyright 2013-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 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, 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>
*/

#include "applications.h"
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <pango/pango.h>
#include <granite-7.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.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  {
	STARTUP_WIDGETS_APP_ROW_0_PROPERTY,
	STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY,
	STARTUP_WIDGETS_APP_ROW_NUM_PROPERTIES
};
static GParamSpec* startup_widgets_app_row_properties[STARTUP_WIDGETS_APP_ROW_NUM_PROPERTIES];
typedef struct _Block3Data Block3Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	STARTUP_WIDGETS_APP_ROW_ACTIVE_CHANGED_SIGNAL,
	STARTUP_WIDGETS_APP_ROW_NUM_SIGNALS
};
static guint startup_widgets_app_row_signals[STARTUP_WIDGETS_APP_ROW_NUM_SIGNALS] = {0};

struct _StartupWidgetsAppRowPrivate {
	StartupEntityAppInfo _app_info;
};

struct _Block3Data {
	int _ref_count_;
	StartupWidgetsAppRow* self;
	GtkSwitch* active_switch;
};

static gint StartupWidgetsAppRow_private_offset;
static gpointer startup_widgets_app_row_parent_class = NULL;

static gboolean _startup_entity_app_info_equal (const StartupEntityAppInfo * s1,
                                         const StartupEntityAppInfo * s2);
static GObject * startup_widgets_app_row_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void _startup_widgets_app_row___lambda26_ (Block3Data* _data3_);
static void __startup_widgets_app_row___lambda26__g_object_notify (GObject* _sender,
                                                            GParamSpec* pspec,
                                                            gpointer self);
static void _startup_widgets_app_row___lambda27_ (StartupWidgetsAppRow* self);
static void __startup_widgets_app_row___lambda27__gtk_button_clicked (GtkButton* _sender,
                                                               gpointer self);
static void startup_widgets_app_row_finalize (GObject * obj);
static GType startup_widgets_app_row_get_type_once (void);
static void _vala_startup_widgets_app_row_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_startup_widgets_app_row_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);

static inline gpointer
startup_widgets_app_row_get_instance_private (StartupWidgetsAppRow* self)
{
	return G_STRUCT_MEMBER_P (self, StartupWidgetsAppRow_private_offset);
}

StartupWidgetsAppRow*
startup_widgets_app_row_construct (GType object_type,
                                   StartupEntityAppInfo* app_info)
{
	StartupWidgetsAppRow * self = NULL;
	StartupEntityAppInfo _tmp0_;
	g_return_val_if_fail (app_info != NULL, NULL);
	_tmp0_ = *app_info;
	self = (StartupWidgetsAppRow*) g_object_new (object_type, "app-info", &_tmp0_, NULL);
	return self;
}

StartupWidgetsAppRow*
startup_widgets_app_row_new (StartupEntityAppInfo* app_info)
{
	return startup_widgets_app_row_construct (STARTUP_WIDGETS_TYPE_APP_ROW, app_info);
}

void
startup_widgets_app_row_get_app_info (StartupWidgetsAppRow* self,
                                      StartupEntityAppInfo * result)
{
	StartupEntityAppInfo _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app_info;
	*result = _tmp0_;
	return;
}

static gboolean
_startup_entity_app_info_equal (const StartupEntityAppInfo * s1,
                                const StartupEntityAppInfo * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	if (g_strcmp0 (s1->name, s2->name)) {
		return FALSE;
	}
	if (g_strcmp0 (s1->comment, s2->comment)) {
		return FALSE;
	}
	if (g_strcmp0 (s1->icon, s2->icon)) {
		return FALSE;
	}
	if (s1->active != s2->active) {
		return FALSE;
	}
	if (g_strcmp0 (s1->path, s2->path)) {
		return FALSE;
	}
	return TRUE;
}

static void
startup_widgets_app_row_set_app_info (StartupWidgetsAppRow* self,
                                      StartupEntityAppInfo * value)
{
	StartupEntityAppInfo old_value;
	g_return_if_fail (self != NULL);
	startup_widgets_app_row_get_app_info (self, &old_value);
	if (_startup_entity_app_info_equal (value, &old_value) != TRUE) {
		StartupEntityAppInfo _tmp0_;
		StartupEntityAppInfo _tmp1_;
		StartupEntityAppInfo _tmp2_ = {0};
		_tmp0_ = *value;
		_tmp1_ = _tmp0_;
		startup_entity_app_info_copy (&_tmp1_, &_tmp2_);
		startup_entity_app_info_destroy (&self->priv->_app_info);
		self->priv->_app_info = _tmp2_;
		g_object_notify_by_pspec ((GObject *) self, startup_widgets_app_row_properties[STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY]);
	}
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		StartupWidgetsAppRow* self;
		self = _data3_->self;
		_g_object_unref0 (_data3_->active_switch);
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static void
_startup_widgets_app_row___lambda26_ (Block3Data* _data3_)
{
	StartupWidgetsAppRow* self;
	GtkSwitch* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	self = _data3_->self;
	_tmp0_ = _data3_->active_switch;
	_tmp1_ = gtk_switch_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_emit (self, startup_widgets_app_row_signals[STARTUP_WIDGETS_APP_ROW_ACTIVE_CHANGED_SIGNAL], 0, _tmp2_);
}

static void
__startup_widgets_app_row___lambda26__g_object_notify (GObject* _sender,
                                                       GParamSpec* pspec,
                                                       gpointer self)
{
	_startup_widgets_app_row___lambda26_ (self);
}

static void
_startup_widgets_app_row___lambda27_ (StartupWidgetsAppRow* self)
{
	StartupEntityAppInfo _tmp0_;
	const gchar* _tmp1_;
	GtkWidget* _tmp2_;
	GtkWidget* _tmp3_;
	_tmp0_ = self->priv->_app_info;
	_tmp1_ = _tmp0_.path;
	g_remove (_tmp1_);
	_tmp2_ = gtk_widget_get_parent ((GtkWidget*) self);
	_tmp3_ = _tmp2_;
	gtk_list_box_remove (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_list_box_get_type (), GtkListBox), (GtkWidget*) self);
}

static void
__startup_widgets_app_row___lambda27__gtk_button_clicked (GtkButton* _sender,
                                                          gpointer self)
{
	_startup_widgets_app_row___lambda27_ ((StartupWidgetsAppRow*) self);
}

static GObject *
startup_widgets_app_row_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	StartupWidgetsAppRow * self;
	Block3Data* _data3_;
	GtkImage* image = NULL;
	StartupEntityAppInfo _tmp0_;
	GtkImage* _tmp1_;
	GtkLabel* app_name = NULL;
	StartupEntityAppInfo _tmp2_;
	const gchar* _tmp3_;
	GtkLabel* _tmp4_ = NULL;
	GtkLabel* app_comment = NULL;
	StartupEntityAppInfo _tmp5_;
	const gchar* _tmp6_;
	GtkLabel* _tmp7_ = NULL;
	GtkLabel* _tmp8_;
	GtkButton* remove_button = NULL;
	gchar* _tmp9_;
	GtkButton* _tmp10_ = NULL;
	StartupEntityAppInfo _tmp11_;
	StartupEntityAppInfo _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	GtkSwitch* _tmp15_ = NULL;
	GtkGrid* main_grid = NULL;
	GtkGrid* _tmp16_ = NULL;
	GtkGrid* _tmp17_;
	GtkImage* _tmp18_;
	GtkGrid* _tmp19_;
	GtkLabel* _tmp20_;
	GtkGrid* _tmp21_;
	GtkLabel* _tmp22_;
	GtkGrid* _tmp23_;
	GtkButton* _tmp24_;
	GtkGrid* _tmp25_;
	GtkSwitch* _tmp26_;
	GtkGrid* _tmp27_;
	GtkSwitch* _tmp28_;
	GtkButton* _tmp29_;
	parent_class = G_OBJECT_CLASS (startup_widgets_app_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, STARTUP_WIDGETS_TYPE_APP_ROW, StartupWidgetsAppRow);
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_tmp0_ = self->priv->_app_info;
	_tmp1_ = startup_utils_create_icon (&_tmp0_);
	image = _tmp1_;
	_tmp2_ = self->priv->_app_info;
	_tmp3_ = _tmp2_.name;
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	gtk_label_set_xalign (_tmp4_, (gfloat) 0);
	g_object_ref_sink (_tmp4_);
	app_name = _tmp4_;
	_tmp5_ = self->priv->_app_info;
	_tmp6_ = _tmp5_.comment;
	_tmp7_ = (GtkLabel*) gtk_label_new (_tmp6_);
	gtk_label_set_ellipsize (_tmp7_, PANGO_ELLIPSIZE_END);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp7_, TRUE);
	gtk_label_set_xalign (_tmp7_, (gfloat) 0);
	g_object_ref_sink (_tmp7_);
	app_comment = _tmp7_;
	_tmp8_ = app_comment;
	gtk_widget_add_css_class ((GtkWidget*) _tmp8_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	_tmp9_ = g_strdup (_ ("Remove this app from startup"));
	_tmp10_ = (GtkButton*) gtk_button_new_from_icon_name ("edit-delete-symbolic");
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp10_, _tmp9_);
	_g_free0 (_tmp9_);
	g_object_ref_sink (_tmp10_);
	remove_button = _tmp10_;
	_tmp11_ = self->priv->_app_info;
	_tmp12_ = self->priv->_app_info;
	_tmp13_ = _tmp12_.name;
	_tmp14_ = g_strdup_printf (_ ("Launch %s on startup"), _tmp13_);
	_tmp15_ = (GtkSwitch*) gtk_switch_new ();
	gtk_switch_set_active (_tmp15_, _tmp11_.active);
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp15_, _tmp14_);
	_g_free0 (_tmp14_);
	gtk_widget_set_valign ((GtkWidget*) _tmp15_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp15_);
	_data3_->active_switch = _tmp15_;
	_tmp16_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp16_, 6);
	g_object_ref_sink (_tmp16_);
	main_grid = _tmp16_;
	_tmp17_ = main_grid;
	_tmp18_ = image;
	gtk_grid_attach (_tmp17_, (GtkWidget*) _tmp18_, 0, 0, 1, 2);
	_tmp19_ = main_grid;
	_tmp20_ = app_name;
	gtk_grid_attach (_tmp19_, (GtkWidget*) _tmp20_, 1, 0, 1, 1);
	_tmp21_ = main_grid;
	_tmp22_ = app_comment;
	gtk_grid_attach (_tmp21_, (GtkWidget*) _tmp22_, 1, 1, 1, 1);
	_tmp23_ = main_grid;
	_tmp24_ = remove_button;
	gtk_grid_attach (_tmp23_, (GtkWidget*) _tmp24_, 2, 0, 1, 2);
	_tmp25_ = main_grid;
	_tmp26_ = _data3_->active_switch;
	gtk_grid_attach (_tmp25_, (GtkWidget*) _tmp26_, 3, 0, 1, 2);
	_tmp27_ = main_grid;
	gtk_list_box_row_set_child ((GtkListBoxRow*) self, (GtkWidget*) _tmp27_);
	_tmp28_ = _data3_->active_switch;
	g_signal_connect_data ((GObject*) _tmp28_, "notify::active", (GCallback) __startup_widgets_app_row___lambda26__g_object_notify, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_tmp29_ = remove_button;
	g_signal_connect_object (_tmp29_, "clicked", (GCallback) __startup_widgets_app_row___lambda27__gtk_button_clicked, self, 0);
	_g_object_unref0 (main_grid);
	_g_object_unref0 (remove_button);
	_g_object_unref0 (app_comment);
	_g_object_unref0 (app_name);
	_g_object_unref0 (image);
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return obj;
}

static void
startup_widgets_app_row_class_init (StartupWidgetsAppRowClass * klass,
                                    gpointer klass_data)
{
	startup_widgets_app_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &StartupWidgetsAppRow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_startup_widgets_app_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_startup_widgets_app_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = startup_widgets_app_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = startup_widgets_app_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY, startup_widgets_app_row_properties[STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY] = g_param_spec_boxed ("app-info", "app-info", "app-info", STARTUP_ENTITY_TYPE_APP_INFO, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	startup_widgets_app_row_signals[STARTUP_WIDGETS_APP_ROW_ACTIVE_CHANGED_SIGNAL] = g_signal_new ("active-changed", STARTUP_WIDGETS_TYPE_APP_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

static void
startup_widgets_app_row_instance_init (StartupWidgetsAppRow * self,
                                       gpointer klass)
{
	self->priv = startup_widgets_app_row_get_instance_private (self);
}

static void
startup_widgets_app_row_finalize (GObject * obj)
{
	StartupWidgetsAppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, STARTUP_WIDGETS_TYPE_APP_ROW, StartupWidgetsAppRow);
	startup_entity_app_info_destroy (&self->priv->_app_info);
	G_OBJECT_CLASS (startup_widgets_app_row_parent_class)->finalize (obj);
}

static GType
startup_widgets_app_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (StartupWidgetsAppRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) startup_widgets_app_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (StartupWidgetsAppRow), 0, (GInstanceInitFunc) startup_widgets_app_row_instance_init, NULL };
	GType startup_widgets_app_row_type_id;
	startup_widgets_app_row_type_id = g_type_register_static (gtk_list_box_row_get_type (), "StartupWidgetsAppRow", &g_define_type_info, 0);
	StartupWidgetsAppRow_private_offset = g_type_add_instance_private (startup_widgets_app_row_type_id, sizeof (StartupWidgetsAppRowPrivate));
	return startup_widgets_app_row_type_id;
}

GType
startup_widgets_app_row_get_type (void)
{
	static volatile gsize startup_widgets_app_row_type_id__once = 0;
	if (g_once_init_enter (&startup_widgets_app_row_type_id__once)) {
		GType startup_widgets_app_row_type_id;
		startup_widgets_app_row_type_id = startup_widgets_app_row_get_type_once ();
		g_once_init_leave (&startup_widgets_app_row_type_id__once, startup_widgets_app_row_type_id);
	}
	return startup_widgets_app_row_type_id__once;
}

static void
_vala_startup_widgets_app_row_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	StartupWidgetsAppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, STARTUP_WIDGETS_TYPE_APP_ROW, StartupWidgetsAppRow);
	switch (property_id) {
		case STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY:
		{
			StartupEntityAppInfo boxed;
			startup_widgets_app_row_get_app_info (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_startup_widgets_app_row_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	StartupWidgetsAppRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, STARTUP_WIDGETS_TYPE_APP_ROW, StartupWidgetsAppRow);
	switch (property_id) {
		case STARTUP_WIDGETS_APP_ROW_APP_INFO_PROPERTY:
		startup_widgets_app_row_set_app_info (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

