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

/* 
 * Copyright 2022 Nanling
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "config.h"
#include <adwaita.h>
#include <glib-object.h>
#include <gio/gio.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
#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 G4_TYPE_APPLICATION (g4_application_get_type ())
#define G4_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G4_TYPE_APPLICATION, G4Application))
#define G4_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), G4_TYPE_APPLICATION, G4ApplicationClass))
#define G4_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G4_TYPE_APPLICATION))
#define G4_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), G4_TYPE_APPLICATION))
#define G4_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G4_TYPE_APPLICATION, G4ApplicationClass))

typedef struct _G4Application G4Application;
typedef struct _G4ApplicationClass G4ApplicationClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gint _vala_main (gchar** args,
                 gint args_length1);
VALA_EXTERN void fix_gst_tag_encoding (void);
VALA_EXTERN void g4_gst_player_init (gchar*** args,
                         gint* args_length1);
VALA_EXTERN GType g4_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (G4Application, g_object_unref)
VALA_EXTERN G4Application* g4_application_new (void);
VALA_EXTERN G4Application* g4_application_construct (GType object_type);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	G4Application* app = NULL;
	G4Application* _tmp0_;
	gint result;
	bindtextdomain (CODE_NAME, LOCALEDIR);
	bind_textdomain_codeset (CODE_NAME, "UTF-8");
	textdomain (CODE_NAME);
	g_set_prgname (APP_ID);
	g_set_application_name (_ ("Gapless"));
	fix_gst_tag_encoding ();
	g_random_set_seed ((guint32) g_get_monotonic_time ());
	g4_gst_player_init (&args, (gint*) (&args_length1));
	_tmp0_ = g4_application_new ();
	app = _tmp0_;
	result = g_application_run ((GApplication*) app, (gint) args_length1, args);
	_g_object_unref0 (app);
	return result;
}

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

void
fix_gst_tag_encoding (void)
{
	const gchar* encoding = NULL;
	const gchar* _tmp0_;
	const gchar* lang = NULL;
	const gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	_tmp0_ = g_getenv ("GST_TAG_ENCODING");
	encoding = _tmp0_;
	_tmp1_ = g_getenv ("LANG");
	lang = _tmp1_;
	_tmp3_ = encoding;
	if (_tmp3_ == NULL) {
		const gchar* _tmp4_;
		_tmp4_ = lang;
		_tmp2_ = _tmp4_ != NULL;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gchar** lang_encodings = NULL;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar** _tmp17_;
		gint lang_encodings_length1;
		gint _lang_encodings_size_;
		_tmp5_ = g_strdup ("ja");
		_tmp6_ = g_strdup ("Shift_JIS");
		_tmp7_ = g_strdup ("ko");
		_tmp8_ = g_strdup ("EUC-KR");
		_tmp9_ = g_strdup ("zh_CN");
		_tmp10_ = g_strdup ("GB18030");
		_tmp11_ = g_strdup ("zh_HK");
		_tmp12_ = g_strdup ("BIG5HKSCS");
		_tmp13_ = g_strdup ("zh_SG");
		_tmp14_ = g_strdup ("GB2312");
		_tmp15_ = g_strdup ("zh_TW");
		_tmp16_ = g_strdup ("BIG5");
		_tmp17_ = g_new0 (gchar*, 12 + 1);
		_tmp17_[0] = _tmp5_;
		_tmp17_[1] = _tmp6_;
		_tmp17_[2] = _tmp7_;
		_tmp17_[3] = _tmp8_;
		_tmp17_[4] = _tmp9_;
		_tmp17_[5] = _tmp10_;
		_tmp17_[6] = _tmp11_;
		_tmp17_[7] = _tmp12_;
		_tmp17_[8] = _tmp13_;
		_tmp17_[9] = _tmp14_;
		_tmp17_[10] = _tmp15_;
		_tmp17_[11] = _tmp16_;
		lang_encodings = _tmp17_;
		lang_encodings_length1 = 12;
		_lang_encodings_size_ = lang_encodings_length1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp18_ = FALSE;
				_tmp18_ = TRUE;
				while (TRUE) {
					gchar** _tmp19_;
					gint _tmp19__length1;
					const gchar* _tmp20_;
					gchar** _tmp21_;
					gint _tmp21__length1;
					const gchar* _tmp22_;
					if (!_tmp18_) {
						i += 2;
					}
					_tmp18_ = FALSE;
					_tmp19_ = lang_encodings;
					_tmp19__length1 = lang_encodings_length1;
					if (!(i < _tmp19__length1)) {
						break;
					}
					_tmp20_ = lang;
					_tmp21_ = lang_encodings;
					_tmp21__length1 = lang_encodings_length1;
					_tmp22_ = _tmp21_[i];
					if (g_str_has_prefix ((const gchar*) _tmp20_, _tmp22_)) {
						gchar** _tmp23_;
						gint _tmp23__length1;
						const gchar* _tmp24_;
						gchar** _tmp25_;
						gint _tmp25__length1;
						const gchar* _tmp26_;
						_tmp23_ = lang_encodings;
						_tmp23__length1 = lang_encodings_length1;
						_tmp24_ = _tmp23_[i + 1];
						g_setenv ("GST_TAG_ENCODING", _tmp24_, TRUE);
						_tmp25_ = lang_encodings;
						_tmp25__length1 = lang_encodings_length1;
						_tmp26_ = _tmp25_[i + 1];
						g_print ("Fix tag encoding: %s\n", _tmp26_);
						break;
					}
				}
			}
		}
		lang_encodings = (_vala_array_free (lang_encodings, lang_encodings_length1, (GDestroyNotify) g_free), NULL);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

