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

/*
 *  pamac-vala
 *
 *  Copyright (C) 2020-2023 Guillaume Benoit <guillaume@manjaro.org>
 *
 *  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 get of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gio/gio.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_SOFTWARE (software_get_type ())
#define SOFTWARE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SOFTWARE, Software))
#define SOFTWARE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SOFTWARE, SoftwareClass))
#define IS_SOFTWARE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SOFTWARE))
#define IS_SOFTWARE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SOFTWARE))
#define SOFTWARE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SOFTWARE, SoftwareClass))

typedef struct _Software Software;
typedef struct _SoftwareClass SoftwareClass;
typedef struct _SoftwarePrivate SoftwarePrivate;
enum  {
	SOFTWARE_0_PROPERTY,
	SOFTWARE_NUM_PROPERTIES
};
static GParamSpec* software_properties[SOFTWARE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _Software {
	GApplication parent_instance;
	SoftwarePrivate * priv;
};

struct _SoftwareClass {
	GApplicationClass parent_class;
};

struct _SoftwarePrivate {
	gchar* details;
	GOptionEntry* options;
	gint options_length1;
	gint _options_size_;
};

static gint Software_private_offset;
static gpointer software_parent_class = NULL;

VALA_EXTERN GType software_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Software, g_object_unref)
VALA_EXTERN Software* software_new (void);
VALA_EXTERN Software* software_construct (GType object_type);
static void software_real_startup (GApplication* base);
static void __lambda4_ (Software* self,
                 GVariant* parameter);
static void ___lambda4__g_simple_action_activate (GSimpleAction* _sender,
                                           GVariant* parameter,
                                           gpointer self);
static void software_real_activate (GApplication* base);
static gint software_real_handle_local_options (GApplication* base,
                                         GVariantDict* options);
static void software_finalize (GObject * obj);
static GType software_get_type_once (void);
static gint _vala_main (gchar** args,
                 gint args_length1);

static inline gpointer
software_get_instance_private (Software* self)
{
	return G_STRUCT_MEMBER_P (self, Software_private_offset);
}

Software*
software_construct (GType object_type)
{
	Software * self = NULL;
	GOptionEntry* _tmp0_;
	GOptionEntry* _tmp1_;
	gint _tmp1__length1;
	GOptionEntry _tmp2_ = {0};
	GOptionEntry* _tmp3_;
	gint _tmp3__length1;
	self = (Software*) g_object_new (object_type, "application-id", "org.gnome.Software", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	_g_free0 (self->priv->details);
	self->priv->details = NULL;
	_tmp0_ = g_new0 (GOptionEntry, 1);
	self->priv->options = (g_free (self->priv->options), NULL);
	self->priv->options = _tmp0_;
	self->priv->options_length1 = 1;
	self->priv->_options_size_ = self->priv->options_length1;
	_tmp1_ = self->priv->options;
	_tmp1__length1 = self->priv->options_length1;
	_tmp2_.long_name = "details";
	_tmp2_.short_name = (gchar) 0;
	_tmp2_.flags = (gint) 0;
	_tmp2_.arg = G_OPTION_ARG_STRING;
	_tmp2_.arg_data = &self->priv->details;
	_tmp2_.description = "Display package details";
	_tmp2_.arg_description = "ID";
	_tmp1_[0] = _tmp2_;
	_tmp3_ = self->priv->options;
	_tmp3__length1 = self->priv->options_length1;
	g_application_add_main_option_entries ((GApplication*) self, _tmp3_);
	return self;
}

Software*
software_new (void)
{
	return software_construct (TYPE_SOFTWARE);
}

static void
__lambda4_ (Software* self,
            GVariant* parameter)
{
	const gchar* details = NULL;
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	_tmp0_ = g_variant_get_child_value (parameter, (gsize) 0);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_variant_get_string (_tmp1_, NULL);
	_tmp3_ = _tmp2_;
	_g_variant_unref0 (_tmp1_);
	details = _tmp3_;
	{
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = g_strdup_printf ("pamac-manager --details-id=%s", details);
		_tmp5_ = _tmp4_;
		g_spawn_command_line_async (_tmp5_, &_inner_error0_);
		_g_free0 (_tmp5_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_warning ("fake_gnome_software.vala:40: %s", _tmp7_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
___lambda4__g_simple_action_activate (GSimpleAction* _sender,
                                      GVariant* parameter,
                                      gpointer self)
{
	__lambda4_ ((Software*) self, parameter);
}

static void
software_real_startup (GApplication* base)
{
	Software * self;
	GSimpleAction* action = NULL;
	GVariantType* _tmp0_;
	GVariantType* _tmp1_;
	GSimpleAction* _tmp2_;
	GSimpleAction* _tmp3_;
	self = (Software*) base;
	G_APPLICATION_CLASS (software_parent_class)->startup (G_TYPE_CHECK_INSTANCE_CAST (self, g_application_get_type (), GApplication));
	_tmp0_ = g_variant_type_new ("(ss)");
	_tmp1_ = _tmp0_;
	_tmp2_ = g_simple_action_new ("details", _tmp1_);
	_tmp3_ = _tmp2_;
	_g_variant_type_free0 (_tmp1_);
	action = _tmp3_;
	g_signal_connect_object (action, "activate", (GCallback) ___lambda4__g_simple_action_activate, self, 0);
	g_action_map_add_action ((GActionMap*) self, (GAction*) action);
	_g_object_unref0 (action);
}

static void
software_real_activate (GApplication* base)
{
	Software * self;
	self = (Software*) base;
	G_APPLICATION_CLASS (software_parent_class)->activate (G_TYPE_CHECK_INSTANCE_CAST (self, g_application_get_type (), GApplication));
}

static gint
software_real_handle_local_options (GApplication* base,
                                    GVariantDict* options)
{
	Software * self;
	const gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	gint result;
	self = (Software*) base;
	g_return_val_if_fail (options != NULL, 0);
	_tmp0_ = self->priv->details;
	if (_tmp0_ != NULL) {
		const gchar* _tmp4_;
		GVariant* _tmp5_;
		GVariant* _tmp6_;
		{
			g_application_register ((GApplication*) self, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp1_;
			const gchar* _tmp2_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp1_ = e;
			_tmp2_ = _tmp1_->message;
			g_warning ("fake_gnome_software.vala:55: %s", _tmp2_);
			result = 0;
			_g_error_free0 (e);
			return result;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gint _tmp3_ = -1;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp3_;
		}
		_tmp4_ = self->priv->details;
		_tmp5_ = g_variant_new ("(ss)", _tmp4_, "", NULL);
		g_variant_ref_sink (_tmp5_);
		_tmp6_ = _tmp5_;
		g_action_group_activate_action ((GActionGroup*) self, "details", _tmp6_);
		_g_variant_unref0 (_tmp6_);
	}
	result = -1;
	return result;
}

static void
software_class_init (SoftwareClass * klass,
                     gpointer klass_data)
{
	software_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &Software_private_offset);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) software_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) software_real_activate;
	((GApplicationClass *) klass)->handle_local_options = (gint (*) (GApplication*, GVariantDict*)) software_real_handle_local_options;
	G_OBJECT_CLASS (klass)->finalize = software_finalize;
}

static void
software_instance_init (Software * self,
                        gpointer klass)
{
	self->priv = software_get_instance_private (self);
}

static void
software_finalize (GObject * obj)
{
	Software * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SOFTWARE, Software);
	_g_free0 (self->priv->details);
	self->priv->options = (g_free (self->priv->options), NULL);
	G_OBJECT_CLASS (software_parent_class)->finalize (obj);
}

static GType
software_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SoftwareClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) software_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Software), 0, (GInstanceInitFunc) software_instance_init, NULL };
	GType software_type_id;
	software_type_id = g_type_register_static (g_application_get_type (), "Software", &g_define_type_info, 0);
	Software_private_offset = g_type_add_instance_private (software_type_id, sizeof (SoftwarePrivate));
	return software_type_id;
}

GType
software_get_type (void)
{
	static volatile gsize software_type_id__once = 0;
	if (g_once_init_enter (&software_type_id__once)) {
		GType software_type_id;
		software_type_id = software_get_type_once ();
		g_once_init_leave (&software_type_id__once, software_type_id);
	}
	return software_type_id__once;
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	Software* software = NULL;
	Software* _tmp0_;
	gint result;
	_tmp0_ = software_new ();
	software = _tmp0_;
	result = g_application_run ((GApplication*) software, (gint) args_length1, args);
	_g_object_unref0 (software);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return _vala_main (argv, argc);
}

