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

/*
 * AptikGtk.vala
 *
 * Copyright 2012-2018 Tony George <teejeetech@gmail.com>
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <locale.h>
#include <glib/gi18n-lib.h>

#define AppName "Timeshift-gtk"
#define AppShortName "timeshift"
#define CONSTANTS_VERSION "25.12.4"
#define AppVersion CONSTANTS_VERSION
#define AppAuthor "Tony George"
#define AppAuthorEmail "teejeetech@gmail.com"
#define GETTEXT_PACKAGE ""
#define LOCALE_DIR "/usr/share/locale"
#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 TYPE_MAIN (main_get_type ())
#define MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN, Main))
#define MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN, MainClass))
#define IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN))
#define IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN))
#define MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN, MainClass))

typedef struct _Main Main;
typedef struct _MainClass MainClass;

#define TYPE_APP_GTK (app_gtk_get_type ())
#define APP_GTK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_APP_GTK, AppGtk))
#define APP_GTK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APP_GTK, AppGtkClass))
#define IS_APP_GTK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_APP_GTK))
#define IS_APP_GTK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APP_GTK))
#define APP_GTK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APP_GTK, AppGtkClass))

typedef struct _AppGtk AppGtk;
typedef struct _AppGtkClass AppGtkClass;
typedef struct _AppGtkPrivate AppGtkPrivate;
enum  {
	APP_GTK_0_PROPERTY,
	APP_GTK_NUM_PROPERTIES
};
static GParamSpec* app_gtk_properties[APP_GTK_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;

struct _AppGtk {
	GObject parent_instance;
	AppGtkPrivate * priv;
};

struct _AppGtkClass {
	GObjectClass parent_class;
};

VALA_EXTERN Main* App;
Main* App = NULL;
static gpointer app_gtk_parent_class = NULL;
VALA_EXTERN gboolean GTK_INITIALIZED;
VALA_EXTERN gboolean tee_jee_logging_LOG_DEBUG;

VALA_EXTERN GType main_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Main, g_object_unref)
void exit (gint exit_code);
VALA_EXTERN GType app_gtk_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AppGtk, g_object_unref)
static gint app_gtk_main (gchar** args,
                   gint args_length1);
static void app_gtk_set_locale (void);
VALA_EXTERN gchar* app_gtk_help_message (void);
static gchar* app_gtk_version_message (void);
VALA_EXTERN void main_setup_env (void);
VALA_EXTERN void tee_jee_process_helper_init_tmp (void);
VALA_EXTERN void app_gtk_check_if_admin (void);
VALA_EXTERN Main* main_new (gchar** args,
                gint args_length1,
                gboolean gui_mode);
VALA_EXTERN Main* main_construct (GType object_type,
                      gchar** args,
                      gint args_length1,
                      gboolean gui_mode);
VALA_EXTERN gboolean app_gtk_parse_arguments (gchar** args,
                                  gint args_length1);
VALA_EXTERN void main_initialize (Main* self);
VALA_EXTERN void app_gtk_start_application (void);
VALA_EXTERN void main_exit_app (Main* self,
                    gint exit_code);
VALA_EXTERN void tee_jee_logging_log_debug (const gchar* message);
VALA_EXTERN void tee_jee_logging_log_error (const gchar* message,
                                gboolean highlight,
                                gboolean is_warning);
VALA_EXTERN void tee_jee_logging_log_msg (const gchar* message,
                              gboolean highlight);
VALA_EXTERN gboolean tee_jee_system_user_is_admin (void);
VALA_EXTERN void tee_jee_gtk_helper_gtk_messagebox (const gchar* title,
                                        const gchar* message,
                                        GtkWindow* parent_win,
                                        gboolean is_error);
VALA_EXTERN GType main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MainWindow, g_object_unref)
VALA_EXTERN MainWindow* main_window_new (void);
VALA_EXTERN MainWindow* main_window_construct (GType object_type);
static void _gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender,
                                        gpointer self);
VALA_EXTERN AppGtk* app_gtk_new (void);
VALA_EXTERN AppGtk* app_gtk_construct (GType object_type);
static GType app_gtk_get_type_once (void);

static gint
app_gtk_main (gchar** args,
              gint args_length1)
{
	Main* _tmp11_;
	Main* _tmp12_;
	Main* _tmp13_;
	gint result;
	app_gtk_set_locale ();
	if (args_length1 > 1) {
		const gchar* _tmp0_;
		gchar* _tmp1_;
		gchar* _tmp2_;
		GQuark _tmp4_ = 0U;
		static GQuark _tmp3_label0 = 0;
		static GQuark _tmp3_label1 = 0;
		static GQuark _tmp3_label2 = 0;
		static GQuark _tmp3_label3 = 0;
		_tmp0_ = args[1];
		_tmp1_ = g_utf8_strdown (_tmp0_, (gssize) -1);
		_tmp2_ = _tmp1_;
		_tmp4_ = (NULL == _tmp2_) ? 0 : g_quark_from_string (_tmp2_);
		g_free (_tmp2_);
		if (((_tmp4_ == ((0 != _tmp3_label0) ? _tmp3_label0 : (_tmp3_label0 = g_quark_from_static_string ("--help")))) || (_tmp4_ == ((0 != _tmp3_label1) ? _tmp3_label1 : (_tmp3_label1 = g_quark_from_static_string ("--h"))))) || (_tmp4_ == ((0 != _tmp3_label2) ? _tmp3_label2 : (_tmp3_label2 = g_quark_from_static_string ("-h"))))) {
			switch (0) {
				default:
				{
					FILE* _tmp5_;
					gchar* _tmp6_;
					gchar* _tmp7_;
					_tmp5_ = stdout;
					_tmp6_ = app_gtk_help_message ();
					_tmp7_ = _tmp6_;
					fprintf (_tmp5_, "%s", _tmp7_);
					_g_free0 (_tmp7_);
					result = 0;
					return result;
				}
			}
		} else if (_tmp4_ == ((0 != _tmp3_label3) ? _tmp3_label3 : (_tmp3_label3 = g_quark_from_static_string ("--version")))) {
			switch (0) {
				default:
				{
					FILE* _tmp8_;
					gchar* _tmp9_;
					gchar* _tmp10_;
					_tmp8_ = stdout;
					_tmp9_ = app_gtk_version_message ();
					_tmp10_ = _tmp9_;
					fprintf (_tmp8_, "%s", _tmp10_);
					_g_free0 (_tmp10_);
					result = 0;
					return result;
				}
			}
		}
	}
	main_setup_env ();
	gtk_init ((gint*) (&args_length1), &args);
	GTK_INITIALIZED = TRUE;
	tee_jee_process_helper_init_tmp ();
	app_gtk_check_if_admin ();
	_tmp11_ = main_new (args, args_length1, TRUE);
	_g_object_unref0 (App);
	App = _tmp11_;
	app_gtk_parse_arguments (args, (gint) args_length1);
	_tmp12_ = App;
	main_initialize (_tmp12_);
	app_gtk_start_application ();
	_tmp13_ = App;
	main_exit_app (_tmp13_, 0);
	result = 0;
	return result;
}

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

static void
app_gtk_set_locale (void)
{
	tee_jee_logging_log_debug ("setting locale...");
	setlocale (LC_MESSAGES, "timeshift");
	textdomain (GETTEXT_PACKAGE);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "utf-8");
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
}

gboolean
app_gtk_parse_arguments (gchar** args,
                         gint args_length1)
{
	gboolean result;
	{
		gint k = 0;
		k = 1;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				const gchar* _tmp2_;
				gchar* _tmp3_;
				gchar* _tmp4_;
				GQuark _tmp6_ = 0U;
				static GQuark _tmp5_label0 = 0;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = k;
					k = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(k < args_length1)) {
					break;
				}
				_tmp2_ = args[k];
				_tmp3_ = g_utf8_strdown (_tmp2_, (gssize) -1);
				_tmp4_ = _tmp3_;
				_tmp6_ = (NULL == _tmp4_) ? 0 : g_quark_from_string (_tmp4_);
				g_free (_tmp4_);
				if (_tmp6_ == ((0 != _tmp5_label0) ? _tmp5_label0 : (_tmp5_label0 = g_quark_from_static_string ("--debug")))) {
					switch (0) {
						default:
						{
							tee_jee_logging_LOG_DEBUG = TRUE;
							break;
						}
					}
				} else {
					switch (0) {
						default:
						{
							const gchar* _tmp7_;
							gchar* _tmp8_;
							gchar* _tmp9_;
							gchar* _tmp10_;
							gchar* _tmp11_;
							gchar* _tmp12_;
							gchar* _tmp13_;
							Main* _tmp14_;
							_tmp7_ = args[k];
							_tmp8_ = g_strdup_printf (": %s", _tmp7_);
							_tmp9_ = _tmp8_;
							_tmp10_ = g_strconcat (_ ("Unknown option"), _tmp9_, NULL);
							_tmp11_ = _tmp10_;
							tee_jee_logging_log_error (_tmp11_, FALSE, FALSE);
							_g_free0 (_tmp11_);
							_g_free0 (_tmp9_);
							_tmp12_ = app_gtk_help_message ();
							_tmp13_ = _tmp12_;
							tee_jee_logging_log_msg (_tmp13_, FALSE);
							_g_free0 (_tmp13_);
							_tmp14_ = App;
							main_exit_app (_tmp14_, 1);
							result = FALSE;
							return result;
						}
					}
				}
			}
		}
	}
	result = TRUE;
	return result;
}

static gchar*
app_gtk_version_message (void)
{
	gchar* msg = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup_printf ("%s %s\n", AppName, AppVersion);
	msg = _tmp0_;
	result = msg;
	return result;
}

gchar*
app_gtk_help_message (void)
{
	gchar* msg = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	const gchar* _tmp33_;
	gchar* _tmp34_;
	const gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	gchar* result;
	_tmp0_ = g_strdup_printf ("\n%s v%s by Tony George (%s)\n", AppName, AppVersion, AppAuthorEmail);
	msg = _tmp0_;
	_tmp1_ = msg;
	_tmp2_ = g_strconcat (_tmp1_, "\n", NULL);
	_g_free0 (msg);
	msg = _tmp2_;
	_tmp3_ = msg;
	_tmp4_ = g_strconcat (_ ("Syntax"), ": timeshift-gtk [options]\n", NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp3_, _tmp5_, NULL);
	_g_free0 (msg);
	msg = _tmp6_;
	_g_free0 (_tmp5_);
	_tmp7_ = msg;
	_tmp8_ = g_strconcat (_tmp7_, "\n", NULL);
	_g_free0 (msg);
	msg = _tmp8_;
	_tmp9_ = msg;
	_tmp10_ = g_strconcat (_ ("Options"), ":\n", NULL);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp9_, _tmp11_, NULL);
	_g_free0 (msg);
	msg = _tmp12_;
	_g_free0 (_tmp11_);
	_tmp13_ = msg;
	_tmp14_ = g_strconcat (_tmp13_, "\n", NULL);
	_g_free0 (msg);
	msg = _tmp14_;
	_tmp15_ = msg;
	_tmp16_ = g_strconcat ("  --debug      ", _ ("Print debug information"), NULL);
	_tmp17_ = _tmp16_;
	_tmp18_ = g_strconcat (_tmp17_, "\n", NULL);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strconcat (_tmp15_, _tmp19_, NULL);
	_g_free0 (msg);
	msg = _tmp20_;
	_g_free0 (_tmp19_);
	_g_free0 (_tmp17_);
	_tmp21_ = msg;
	_tmp22_ = g_strconcat ("  --h[elp]     ", _ ("Show all options"), NULL);
	_tmp23_ = _tmp22_;
	_tmp24_ = g_strconcat (_tmp23_, "\n", NULL);
	_tmp25_ = _tmp24_;
	_tmp26_ = g_strconcat (_tmp21_, _tmp25_, NULL);
	_g_free0 (msg);
	msg = _tmp26_;
	_g_free0 (_tmp25_);
	_g_free0 (_tmp23_);
	_tmp27_ = msg;
	_tmp28_ = g_strconcat ("  --version    ", _ ("Print version number"), NULL);
	_tmp29_ = _tmp28_;
	_tmp30_ = g_strconcat (_tmp29_, "\n", NULL);
	_tmp31_ = _tmp30_;
	_tmp32_ = g_strconcat (_tmp27_, _tmp31_, NULL);
	_g_free0 (msg);
	msg = _tmp32_;
	_g_free0 (_tmp31_);
	_g_free0 (_tmp29_);
	_tmp33_ = msg;
	_tmp34_ = g_strconcat (_tmp33_, "\n\n", NULL);
	_g_free0 (msg);
	msg = _tmp34_;
	_tmp35_ = msg;
	_tmp36_ = g_strdup_printf ("\n%s\n", _ ("Run 'timeshift' for the command-line version of this tool"));
	_tmp37_ = _tmp36_;
	_tmp38_ = g_strconcat (_tmp35_, _tmp37_, NULL);
	_g_free0 (msg);
	msg = _tmp38_;
	_g_free0 (_tmp37_);
	result = msg;
	return result;
}

void
app_gtk_check_if_admin (void)
{
	if (!tee_jee_system_user_is_admin ()) {
		gchar* msg = NULL;
		gchar* _tmp0_;
		const gchar* _tmp1_;
		gchar* _tmp2_;
		const gchar* _tmp3_;
		gchar* title = NULL;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		_tmp0_ = g_strconcat (_ ("Admin access is required to backup and restore system files."), "\n", NULL);
		msg = _tmp0_;
		_tmp1_ = msg;
		_tmp2_ = g_strconcat (_tmp1_, _ ("Please re-run the application as admin (using 'sudo' or 'su')"), NULL);
		_g_free0 (msg);
		msg = _tmp2_;
		_tmp3_ = msg;
		tee_jee_logging_log_error (_tmp3_, FALSE, FALSE);
		_tmp4_ = g_strdup (_ ("Admin Access Required"));
		title = _tmp4_;
		_tmp5_ = title;
		_tmp6_ = msg;
		tee_jee_gtk_helper_gtk_messagebox (_tmp5_, _tmp6_, NULL, TRUE);
		exit (1);
		_g_free0 (title);
		_g_free0 (msg);
	}
}

static void
_gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender,
                                   gpointer self)
{
	gtk_main_quit ();
}

void
app_gtk_start_application (void)
{
	MainWindow* window = NULL;
	MainWindow* _tmp0_;
	_tmp0_ = main_window_new ();
	g_object_ref_sink (_tmp0_);
	window = _tmp0_;
	g_signal_connect ((GtkWidget*) window, "destroy", (GCallback) _gtk_main_quit_gtk_widget_destroy, NULL);
	gtk_widget_show_all ((GtkWidget*) window);
	gtk_main ();
	_g_object_unref0 (window);
}

AppGtk*
app_gtk_construct (GType object_type)
{
	AppGtk * self = NULL;
	self = (AppGtk*) g_object_new (object_type, NULL);
	return self;
}

AppGtk*
app_gtk_new (void)
{
	return app_gtk_construct (TYPE_APP_GTK);
}

static void
app_gtk_class_init (AppGtkClass * klass,
                    gpointer klass_data)
{
	app_gtk_parent_class = g_type_class_peek_parent (klass);
}

static void
app_gtk_instance_init (AppGtk * self,
                       gpointer klass)
{
}

static GType
app_gtk_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (AppGtkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) app_gtk_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AppGtk), 0, (GInstanceInitFunc) app_gtk_instance_init, NULL };
	GType app_gtk_type_id;
	app_gtk_type_id = g_type_register_static (G_TYPE_OBJECT, "AppGtk", &g_define_type_info, 0);
	return app_gtk_type_id;
}

GType
app_gtk_get_type (void)
{
	static volatile gsize app_gtk_type_id__once = 0;
	if (g_once_init_enter (&app_gtk_type_id__once)) {
		GType app_gtk_type_id;
		app_gtk_type_id = app_gtk_get_type_once ();
		g_once_init_leave (&app_gtk_type_id__once, app_gtk_type_id);
	}
	return app_gtk_type_id__once;
}

