/* gitg-theme.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-theme.vala, do not modify */

/*
 *
 * Copyright (C) 2018 - Jente Hidskes <hjdskes@gmail.com>
 *
 * gitg 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 2 of the License, or
 * (at your option) any later version.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgitg.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <glib-object.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  {
	GITG_THEME_0_PROPERTY,
	GITG_THEME_NUM_PROPERTIES
};
static GParamSpec* gitg_theme_properties[GITG_THEME_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))

static gpointer gitg_theme_parent_class = NULL;
static GOnce gitg_theme__instance;
static GOnce gitg_theme__instance = G_ONCE_INIT;

static GitgTheme* __lambda44_ (void);
static gpointer ___lambda44__gthread_func (gpointer self);
static void gitg_theme_finalize (GObject * obj);
static GType gitg_theme_get_type_once (void);

static GitgTheme*
__lambda44_ (void)
{
	GitgTheme* _tmp0_;
	GitgTheme* result;
	_tmp0_ = gitg_theme_new ();
	g_object_ref_sink (_tmp0_);
	result = _tmp0_;
	return result;
}

static gpointer
___lambda44__gthread_func (gpointer self)
{
	gpointer result;
	result = __lambda44_ ();
	return result;
}

GitgTheme*
gitg_theme_instance (void)
{
	gconstpointer _tmp0_;
	GitgTheme* result;
	_tmp0_ = g_once (&gitg_theme__instance, ___lambda44__gthread_func, NULL);
	result = (GitgTheme*) _tmp0_;
	return result;
}

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

gboolean
gitg_theme_is_theme_dark (GitgTheme* self)
{
	GtkSettings* settings = NULL;
	GtkSettings* _tmp0_;
	GtkSettings* _tmp1_;
	gchar* theme = NULL;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GtkSettings* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean dark = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = gtk_settings_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	settings = _tmp1_;
	_tmp2_ = g_getenv ("GTK_THEME");
	_tmp3_ = g_strdup (_tmp2_);
	theme = _tmp3_;
	_tmp5_ = settings;
	g_object_get (_tmp5_, "gtk-application-prefer-dark-theme", &_tmp6_, NULL);
	_tmp7_ = _tmp6_;
	if (_tmp7_) {
		_tmp4_ = TRUE;
	} else {
		gboolean _tmp8_ = FALSE;
		const gchar* _tmp9_;
		_tmp9_ = theme;
		if (_tmp9_ != NULL) {
			const gchar* _tmp10_;
			_tmp10_ = theme;
			_tmp8_ = g_str_has_suffix (_tmp10_, ":dark");
		} else {
			_tmp8_ = FALSE;
		}
		_tmp4_ = _tmp8_;
	}
	dark = _tmp4_;
	if (!dark) {
		GtkStyleContext* stylecontext = NULL;
		GtkStyleContext* _tmp11_;
		GtkStyleContext* _tmp12_;
		GdkRGBA rgba = {0};
		gboolean background_set = FALSE;
		GtkStyleContext* _tmp13_;
		GdkRGBA _tmp14_ = {0};
		gboolean _tmp15_;
		gboolean _tmp16_ = FALSE;
		_tmp11_ = gtk_widget_get_style_context ((GtkWidget*) self);
		_tmp12_ = _g_object_ref0 (_tmp11_);
		stylecontext = _tmp12_;
		_tmp13_ = stylecontext;
		_tmp15_ = gtk_style_context_lookup_color (_tmp13_, "theme_bg_color", &_tmp14_);
		rgba = _tmp14_;
		background_set = _tmp15_;
		if (background_set) {
			GdkRGBA _tmp17_;
			GdkRGBA _tmp18_;
			GdkRGBA _tmp19_;
			_tmp17_ = rgba;
			_tmp18_ = rgba;
			_tmp19_ = rgba;
			_tmp16_ = ((_tmp17_.red + _tmp18_.green) + _tmp19_.blue) < 1.0;
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			dark = TRUE;
		}
		_g_object_unref0 (stylecontext);
	}
	result = dark;
	_g_free0 (theme);
	_g_object_unref0 (settings);
	return result;
}

GitgTheme*
gitg_theme_construct (GType object_type)
{
	GitgTheme * self = NULL;
	self = (GitgTheme*) gtk_widget_new (object_type, NULL);
	return self;
}

GitgTheme*
gitg_theme_new (void)
{
	return gitg_theme_construct (GITG_TYPE_THEME);
}

static void
gitg_theme_class_init (GitgThemeClass * klass,
                       gpointer klass_data)
{
	gitg_theme_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = gitg_theme_finalize;
}

static void
gitg_theme_instance_init (GitgTheme * self,
                          gpointer klass)
{
}

static void
gitg_theme_finalize (GObject * obj)
{
	GitgTheme * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_THEME, GitgTheme);
	G_OBJECT_CLASS (gitg_theme_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_theme_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgThemeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_theme_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgTheme), 0, (GInstanceInitFunc) gitg_theme_instance_init, NULL };
	GType gitg_theme_type_id;
	gitg_theme_type_id = g_type_register_static (gtk_widget_get_type (), "GitgTheme", &g_define_type_info, 0);
	return gitg_theme_type_id;
}

GType
gitg_theme_get_type (void)
{
	static gsize gitg_theme_type_id__once = 0;
	if (g_once_init_enter (&gitg_theme_type_id__once)) {
		GType gitg_theme_type_id;
		gitg_theme_type_id = gitg_theme_get_type_once ();
		g_once_init_leave (&gitg_theme_type_id__once, gitg_theme_type_id);
	}
	return gitg_theme_type_id__once;
}

