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

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

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


#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;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (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 {
	gchar* game_id;
	GIcon* icon;
	gboolean searched;
};


static gpointer games_steam_icon_parent_class = NULL;
static GIcon* games_steam_icon_steam_icon;
static GIcon* games_steam_icon_steam_icon = NULL;
static GamesIconIface * games_steam_icon_games_icon_parent_iface = NULL;
static GType games_steam_icon_type_id = 0;

GType games_steam_icon_get_type (void) G_GNUC_CONST;
#define GAMES_STEAM_ICON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_STEAM_ICON, GamesSteamIconPrivate))
enum  {
	GAMES_STEAM_ICON_0_PROPERTY
};
GamesSteamIcon* games_steam_icon_new (const gchar* game_id);
GamesSteamIcon* games_steam_icon_construct (GType object_type, const gchar* game_id);
static GIcon* games_steam_icon_real_get_icon (GamesIcon* base);
static void games_steam_icon_finalize (GObject * obj);


GamesSteamIcon* games_steam_icon_construct (GType object_type, const gchar* game_id) {
	GamesSteamIcon * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (game_id != NULL, NULL);
	self = (GamesSteamIcon*) g_object_new (object_type, NULL);
	_tmp0_ = game_id;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->game_id);
	self->priv->game_id = _tmp1_;
	self->priv->searched = FALSE;
	return self;
}


GamesSteamIcon* games_steam_icon_new (const gchar* game_id) {
	return games_steam_icon_construct (GAMES_TYPE_STEAM_ICON, 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* result = NULL;
	gboolean _tmp0_;
	GIcon* _tmp18_ = NULL;
	GIcon* _tmp19_;
	GIcon* _tmp21_;
	GError * _inner_error_ = NULL;
	self = (GamesSteamIcon*) base;
	_tmp0_ = self->priv->searched;
	if (_tmp0_) {
		GIcon* _tmp1_ = NULL;
		GIcon* _tmp2_;
		GIcon* _tmp4_;
		_tmp2_ = self->priv->icon;
		_tmp1_ = _tmp2_;
		if (_tmp1_ == NULL) {
			GIcon* _tmp3_;
			_tmp3_ = games_steam_icon_steam_icon;
			_tmp1_ = _tmp3_;
		}
		_tmp4_ = _g_object_ref0 (_tmp1_);
		result = _tmp4_;
		return result;
	}
	self->priv->searched = TRUE;
	{
		gchar* icon_name = NULL;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		GtkIconTheme* theme = NULL;
		GtkIconTheme* _tmp7_;
		GtkIconTheme* _tmp8_;
		GtkIconTheme* _tmp9_;
		const gchar* _tmp10_;
		gboolean _tmp11_;
		_tmp5_ = self->priv->game_id;
		_tmp6_ = g_strconcat ("steam_icon_", _tmp5_, NULL);
		icon_name = _tmp6_;
		_tmp7_ = gtk_icon_theme_get_default ();
		_tmp8_ = _g_object_ref0 (_tmp7_);
		theme = _tmp8_;
		_tmp9_ = theme;
		_tmp10_ = icon_name;
		_tmp11_ = gtk_icon_theme_has_icon (_tmp9_, _tmp10_);
		if (_tmp11_) {
			GIcon* _tmp12_ = NULL;
			const gchar* _tmp13_;
			GIcon* _tmp14_;
			GIcon* _tmp15_;
			_tmp13_ = icon_name;
			_tmp14_ = g_icon_new_for_string (_tmp13_, &_inner_error_);
			_tmp12_ = _tmp14_;
			if (G_UNLIKELY (_inner_error_ != NULL)) {
				_g_object_unref0 (theme);
				_g_free0 (icon_name);
				goto __catch1_g_error;
			}
			_tmp15_ = _tmp12_;
			_tmp12_ = NULL;
			_g_object_unref0 (self->priv->icon);
			self->priv->icon = _tmp15_;
			_g_object_unref0 (_tmp12_);
		}
		_g_object_unref0 (theme);
		_g_free0 (icon_name);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp16_;
		const gchar* _tmp17_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp16_ = e;
		_tmp17_ = _tmp16_->message;
		g_warning ("steam-icon.vala:38: %s\n", _tmp17_);
		_g_error_free0 (e);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp19_ = self->priv->icon;
	_tmp18_ = _tmp19_;
	if (_tmp18_ == NULL) {
		GIcon* _tmp20_;
		_tmp20_ = games_steam_icon_steam_icon;
		_tmp18_ = _tmp20_;
	}
	_tmp21_ = _g_object_ref0 (_tmp18_);
	result = _tmp21_;
	return result;
}


static void games_steam_icon_class_init (GamesSteamIconClass * klass) {
	GError * _inner_error_ = NULL;
	games_steam_icon_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesSteamIconPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_steam_icon_finalize;
	{
		GIcon* _tmp0_ = NULL;
		GIcon* _tmp1_;
		GIcon* _tmp2_;
		_tmp1_ = g_icon_new_for_string ("steam", &_inner_error_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch2_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_g_object_unref0 (games_steam_icon_steam_icon);
		games_steam_icon_steam_icon = _tmp2_;
		_g_object_unref0 (_tmp0_);
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("steam-icon.vala:15: %s\n", _tmp4_);
		_g_error_free0 (e);
	}
	__finally2:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
	}
}


static void games_steam_icon_games_icon_interface_init (GamesIconIface * iface) {
	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) {
	self->priv = GAMES_STEAM_ICON_GET_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_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);
	return games_steam_icon_type_id;
}



