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

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib-object.h>
#include "gnome-games.h"
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "games-steam-plugin.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

#define GAMES_TYPE_STEAM_ICON (games_steam_icon_get_type ())
#define GAMES_STEAM_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_STEAM_ICON, GamesSteamIcon))
#define GAMES_STEAM_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_STEAM_ICON, GamesSteamIconClass))
#define GAMES_IS_STEAM_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_STEAM_ICON))
#define GAMES_IS_STEAM_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_STEAM_ICON))
#define GAMES_STEAM_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_STEAM_ICON, GamesSteamIconClass))

typedef struct _GamesSteamIcon GamesSteamIcon;
typedef struct _GamesSteamIconClass GamesSteamIconClass;
typedef struct _GamesSteamIconPrivate GamesSteamIconPrivate;
enum  {
	GAMES_STEAM_ICON_0_PROPERTY,
	GAMES_STEAM_ICON_NUM_PROPERTIES
};
static GParamSpec* games_steam_icon_properties[GAMES_STEAM_ICON_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))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GamesSteamIcon {
	GObject parent_instance;
	GamesSteamIconPrivate * priv;
};

struct _GamesSteamIconClass {
	GObjectClass parent_class;
};

struct _GamesSteamIconPrivate {
	GIcon* steam_icon;
	gchar* game_id;
	GIcon* icon;
	gboolean searched;
};

static gint GamesSteamIcon_private_offset;
static gpointer games_steam_icon_parent_class = NULL;
static GamesIconIface * games_steam_icon_games_icon_parent_iface = NULL;
static GType games_steam_icon_type_id = 0;

GType games_steam_icon_register_type (GTypeModule * module);
VALA_EXTERN GType games_steam_icon_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesSteamIcon* games_steam_icon_new (const gchar* app_id,
                                      const gchar* game_id);
VALA_EXTERN GamesSteamIcon* games_steam_icon_construct (GType object_type,
                                            const gchar* app_id,
                                            const gchar* game_id);
static GIcon* games_steam_icon_real_get_icon (GamesIcon* base);
static void games_steam_icon_finalize (GObject * obj);

static inline gpointer
games_steam_icon_get_instance_private (GamesSteamIcon* self)
{
	return G_STRUCT_MEMBER_P (self, GamesSteamIcon_private_offset);
}

GamesSteamIcon*
games_steam_icon_construct (GType object_type,
                            const gchar* app_id,
                            const gchar* game_id)
{
	GamesSteamIcon * self = NULL;
	gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (app_id != NULL, NULL);
	g_return_val_if_fail (game_id != NULL, NULL);
	self = (GamesSteamIcon*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (game_id);
	_g_free0 (self->priv->game_id);
	self->priv->game_id = _tmp0_;
	self->priv->searched = FALSE;
	{
		GIcon* _tmp1_ = NULL;
		GIcon* _tmp2_;
		GIcon* _tmp3_;
		_tmp2_ = g_icon_new_for_string (app_id, &_inner_error0_);
		_tmp1_ = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = _tmp1_;
		_tmp1_ = NULL;
		_g_object_unref0 (self->priv->steam_icon);
		self->priv->steam_icon = _tmp3_;
		_g_object_unref0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		g_warning ("steam-icon.vala:19: %s\n", _tmp5_);
		_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 NULL;
	}
	return self;
}

GamesSteamIcon*
games_steam_icon_new (const gchar* app_id,
                      const gchar* game_id)
{
	return games_steam_icon_construct (GAMES_TYPE_STEAM_ICON, app_id, game_id);
}

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

static GIcon*
games_steam_icon_real_get_icon (GamesIcon* base)
{
	GamesSteamIcon * self;
	GIcon* _tmp16_ = NULL;
	GIcon* _tmp17_;
	GIcon* _tmp19_;
	GError* _inner_error0_ = NULL;
	GIcon* result;
	self = (GamesSteamIcon*) base;
	if (self->priv->searched) {
		GIcon* _tmp0_ = NULL;
		GIcon* _tmp1_;
		GIcon* _tmp3_;
		_tmp1_ = self->priv->icon;
		_tmp0_ = _tmp1_;
		if (_tmp0_ == NULL) {
			GIcon* _tmp2_;
			_tmp2_ = self->priv->steam_icon;
			_tmp0_ = _tmp2_;
		}
		_tmp3_ = _g_object_ref0 (_tmp0_);
		result = _tmp3_;
		return result;
	}
	self->priv->searched = TRUE;
	{
		gchar* icon_name = NULL;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		GtkIconTheme* theme = NULL;
		GtkIconTheme* _tmp6_;
		GtkIconTheme* _tmp7_;
		GtkIconTheme* _tmp8_;
		const gchar* _tmp9_;
		_tmp4_ = self->priv->game_id;
		_tmp5_ = g_strconcat ("steam_icon_", _tmp4_, NULL);
		icon_name = _tmp5_;
		_tmp6_ = gtk_icon_theme_get_default ();
		_tmp7_ = _g_object_ref0 (_tmp6_);
		theme = _tmp7_;
		_tmp8_ = theme;
		_tmp9_ = icon_name;
		if (gtk_icon_theme_has_icon (_tmp8_, _tmp9_)) {
			GIcon* _tmp10_ = NULL;
			const gchar* _tmp11_;
			GIcon* _tmp12_;
			GIcon* _tmp13_;
			_tmp11_ = icon_name;
			_tmp12_ = g_icon_new_for_string (_tmp11_, &_inner_error0_);
			_tmp10_ = _tmp12_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (theme);
				_g_free0 (icon_name);
				goto __catch0_g_error;
			}
			_tmp13_ = _tmp10_;
			_tmp10_ = NULL;
			_g_object_unref0 (self->priv->icon);
			self->priv->icon = _tmp13_;
			_g_object_unref0 (_tmp10_);
		}
		_g_object_unref0 (theme);
		_g_free0 (icon_name);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp14_;
		const gchar* _tmp15_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp14_ = e;
		_tmp15_ = _tmp14_->message;
		g_warning ("steam-icon.vala:36: %s\n", _tmp15_);
		_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 NULL;
	}
	_tmp17_ = self->priv->icon;
	_tmp16_ = _tmp17_;
	if (_tmp16_ == NULL) {
		GIcon* _tmp18_;
		_tmp18_ = self->priv->steam_icon;
		_tmp16_ = _tmp18_;
	}
	_tmp19_ = _g_object_ref0 (_tmp16_);
	result = _tmp19_;
	return result;
}

static void
games_steam_icon_class_init (GamesSteamIconClass * klass,
                             gpointer klass_data)
{
	games_steam_icon_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesSteamIcon_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_steam_icon_finalize;
}

static void
games_steam_icon_games_icon_interface_init (GamesIconIface * iface,
                                            gpointer iface_data)
{
	games_steam_icon_games_icon_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_icon = (GIcon* (*) (GamesIcon*)) games_steam_icon_real_get_icon;
}

static void
games_steam_icon_instance_init (GamesSteamIcon * self,
                                gpointer klass)
{
	self->priv = games_steam_icon_get_instance_private (self);
}

static void
games_steam_icon_finalize (GObject * obj)
{
	GamesSteamIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_STEAM_ICON, GamesSteamIcon);
	_g_object_unref0 (self->priv->steam_icon);
	_g_free0 (self->priv->game_id);
	_g_object_unref0 (self->priv->icon);
	G_OBJECT_CLASS (games_steam_icon_parent_class)->finalize (obj);
}

GType
games_steam_icon_get_type (void)
{
	return games_steam_icon_type_id;
}

GType
games_steam_icon_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesSteamIconClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_steam_icon_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesSteamIcon), 0, (GInstanceInitFunc) games_steam_icon_instance_init, NULL };
	static const GInterfaceInfo games_icon_info = { (GInterfaceInitFunc) games_steam_icon_games_icon_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_steam_icon_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesSteamIcon", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_steam_icon_type_id, GAMES_TYPE_ICON, &games_icon_info);
	GamesSteamIcon_private_offset = sizeof (GamesSteamIconPrivate);
	return games_steam_icon_type_id;
}

