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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    For copyright information, see AUTHORS.

    Déjà Dup 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.

    Déjà Dup 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 Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.h>
#include "widgets.h"
#include "deja.h"


#define TYPE_PREFERENCES_APP (preferences_app_get_type ())
#define PREFERENCES_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PREFERENCES_APP, PreferencesApp))
#define PREFERENCES_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PREFERENCES_APP, PreferencesAppClass))
#define IS_PREFERENCES_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PREFERENCES_APP))
#define IS_PREFERENCES_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PREFERENCES_APP))
#define PREFERENCES_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PREFERENCES_APP, PreferencesAppClass))

typedef struct _PreferencesApp PreferencesApp;
typedef struct _PreferencesAppClass PreferencesAppClass;
typedef struct _PreferencesAppPrivate PreferencesAppPrivate;

#define DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH (deja_dup_preferences_periodic_switch_get_type ())
#define DEJA_DUP_PREFERENCES_PERIODIC_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH, DejaDupPreferencesPeriodicSwitch))
#define DEJA_DUP_PREFERENCES_PERIODIC_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH, DejaDupPreferencesPeriodicSwitchClass))
#define DEJA_DUP_IS_PREFERENCES_PERIODIC_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH))
#define DEJA_DUP_IS_PREFERENCES_PERIODIC_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH))
#define DEJA_DUP_PREFERENCES_PERIODIC_SWITCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_PREFERENCES_PERIODIC_SWITCH, DejaDupPreferencesPeriodicSwitchClass))

typedef struct _DejaDupPreferencesPeriodicSwitch DejaDupPreferencesPeriodicSwitch;
typedef struct _DejaDupPreferencesPeriodicSwitchClass DejaDupPreferencesPeriodicSwitchClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define DEJA_DUP_TYPE_PREFERENCES (deja_dup_preferences_get_type ())
#define DEJA_DUP_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_PREFERENCES, DejaDupPreferences))
#define DEJA_DUP_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_PREFERENCES, DejaDupPreferencesClass))
#define DEJA_DUP_IS_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_PREFERENCES))
#define DEJA_DUP_IS_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_PREFERENCES))
#define DEJA_DUP_PREFERENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_PREFERENCES, DejaDupPreferencesClass))

typedef struct _DejaDupPreferences DejaDupPreferences;
typedef struct _DejaDupPreferencesClass DejaDupPreferencesClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))

struct _PreferencesApp {
	GtkApplication parent_instance;
	PreferencesAppPrivate * priv;
};

struct _PreferencesAppClass {
	GtkApplicationClass parent_class;
};


static gpointer preferences_app_parent_class = NULL;
extern PreferencesApp* app;
PreferencesApp* app = NULL;
extern gboolean show_version;
gboolean show_version = FALSE;

GType preferences_app_get_type (void) G_GNUC_CONST;
enum  {
	PREFERENCES_APP_DUMMY_PROPERTY
};
PreferencesApp* preferences_app_new (void);
PreferencesApp* preferences_app_construct (GType object_type);
static void preferences_app_real_activate (GApplication* base);
GType deja_dup_preferences_periodic_switch_get_type (void) G_GNUC_CONST;
DejaDupPreferencesPeriodicSwitch* deja_dup_preferences_periodic_switch_new (void);
DejaDupPreferencesPeriodicSwitch* deja_dup_preferences_periodic_switch_construct (GType object_type);
GType deja_dup_preferences_get_type (void) G_GNUC_CONST;
DejaDupPreferences* deja_dup_preferences_new (DejaDupPreferencesPeriodicSwitch* auto_switch);
DejaDupPreferences* deja_dup_preferences_construct (GType object_type, DejaDupPreferencesPeriodicSwitch* auto_switch);
static void preferences_app_real_startup (GApplication* base);
void handle_help (void);
static void _handle_help_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self);
void handle_quit (void);
static void _handle_quit_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self);
gboolean handle_console_options (gint* status);
gint _vala_main (gchar** args, int args_length1);

const GActionEntry actions[2] = {{"help", _handle_help_gsimple_action_activate_callback}, {"quit", _handle_quit_gsimple_action_activate_callback}};
const GOptionEntry options[2] = {{"version", (gchar) 0, 0, G_OPTION_ARG_NONE, &show_version, "Show version", NULL}, {NULL}};

PreferencesApp* preferences_app_construct (GType object_type) {
	PreferencesApp * self = NULL;
	self = (PreferencesApp*) g_object_new (object_type, "application-id", "org.gnome.DejaDup.Preferences", NULL);
	return self;
}


PreferencesApp* preferences_app_new (void) {
	return preferences_app_construct (TYPE_PREFERENCES_APP);
}


static void preferences_app_real_activate (GApplication* base) {
	PreferencesApp * self;
	GList* list = NULL;
	GList* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	self = (PreferencesApp*) base;
	G_APPLICATION_CLASS (preferences_app_parent_class)->activate ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	_tmp0_ = gtk_application_get_windows ((GtkApplication*) self);
	list = _tmp0_;
	_tmp1_ = list;
	if (_tmp1_ != NULL) {
		GList* _tmp2_ = NULL;
		gconstpointer _tmp3_ = NULL;
		guint32 _tmp4_ = 0U;
		_tmp2_ = list;
		_tmp3_ = _tmp2_->data;
		_tmp4_ = gtk_get_current_event_time ();
		gtk_window_present_with_time ((GtkWindow*) _tmp3_, _tmp4_);
	} else {
		GtkApplicationWindow* dlg = NULL;
		GtkApplicationWindow* _tmp5_ = NULL;
		GtkApplicationWindow* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		GtkApplicationWindow* _tmp8_ = NULL;
		DejaDupPreferencesPeriodicSwitch* auto_switch = NULL;
		GtkHeaderBar* header = NULL;
		GtkHeaderBar* _tmp9_ = NULL;
		GtkHeaderBar* _tmp10_ = NULL;
		GtkApplicationWindow* _tmp11_ = NULL;
		GtkHeaderBar* _tmp12_ = NULL;
		DejaDupPreferencesPeriodicSwitch* _tmp13_ = NULL;
		DejaDupPreferencesPeriodicSwitch* _tmp14_ = NULL;
		GtkHeaderBar* _tmp15_ = NULL;
		DejaDupPreferencesPeriodicSwitch* _tmp16_ = NULL;
		DejaDupPreferences* prefs = NULL;
		DejaDupPreferencesPeriodicSwitch* _tmp17_ = NULL;
		DejaDupPreferences* _tmp18_ = NULL;
		DejaDupPreferences* _tmp19_ = NULL;
		GtkApplicationWindow* _tmp20_ = NULL;
		DejaDupPreferences* _tmp21_ = NULL;
		GtkApplicationWindow* _tmp22_ = NULL;
		GtkApplicationWindow* _tmp23_ = NULL;
		_tmp5_ = (GtkApplicationWindow*) gtk_application_window_new ((GtkApplication*) self);
		g_object_ref_sink (_tmp5_);
		dlg = _tmp5_;
		_tmp6_ = dlg;
		_tmp7_ = _ ("Backups");
		gtk_window_set_title ((GtkWindow*) _tmp6_, _tmp7_);
		_tmp8_ = dlg;
		gtk_window_set_resizable ((GtkWindow*) _tmp8_, FALSE);
		auto_switch = NULL;
		_tmp9_ = (GtkHeaderBar*) gtk_header_bar_new ();
		g_object_ref_sink (_tmp9_);
		header = _tmp9_;
		_tmp10_ = header;
		gtk_header_bar_set_show_close_button (_tmp10_, TRUE);
		_tmp11_ = dlg;
		_tmp12_ = header;
		gtk_window_set_titlebar ((GtkWindow*) _tmp11_, (GtkWidget*) _tmp12_);
		_tmp13_ = deja_dup_preferences_periodic_switch_new ();
		g_object_ref_sink (_tmp13_);
		_g_object_unref0 (auto_switch);
		auto_switch = _tmp13_;
		_tmp14_ = auto_switch;
		gtk_widget_set_valign ((GtkWidget*) _tmp14_, GTK_ALIGN_CENTER);
		_tmp15_ = header;
		_tmp16_ = auto_switch;
		gtk_header_bar_pack_end (_tmp15_, (GtkWidget*) _tmp16_);
		_tmp17_ = auto_switch;
		_tmp18_ = deja_dup_preferences_new (_tmp17_);
		g_object_ref_sink (_tmp18_);
		prefs = _tmp18_;
		_tmp19_ = prefs;
		gtk_container_set_border_width ((GtkContainer*) _tmp19_, (guint) 12);
		_tmp20_ = dlg;
		_tmp21_ = prefs;
		gtk_container_add ((GtkContainer*) _tmp20_, (GtkWidget*) _tmp21_);
		_tmp22_ = dlg;
		gtk_window_set_application ((GtkWindow*) _tmp22_, (GtkApplication*) self);
		_tmp23_ = dlg;
		gtk_widget_show_all ((GtkWidget*) _tmp23_);
		_g_object_unref0 (prefs);
		_g_object_unref0 (header);
		_g_object_unref0 (auto_switch);
		_g_object_unref0 (dlg);
	}
}


static void _handle_help_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self) {
	handle_help ();
}


static void _handle_quit_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self) {
	handle_quit ();
}


static void preferences_app_real_startup (GApplication* base) {
	PreferencesApp * self;
	GMenu* help = NULL;
	GMenu* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GMenu* quit = NULL;
	GMenu* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	GMenu* menu = NULL;
	GMenu* _tmp4_ = NULL;
	self = (PreferencesApp*) base;
	G_APPLICATION_CLASS (preferences_app_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	g_action_map_add_action_entries ((GActionMap*) self, actions, G_N_ELEMENTS (actions), NULL);
	_tmp0_ = g_menu_new ();
	help = _tmp0_;
	_tmp1_ = _ ("_Help");
	g_menu_append (help, _tmp1_, "app.help");
	_tmp2_ = g_menu_new ();
	quit = _tmp2_;
	_tmp3_ = _ ("_Quit");
	g_menu_append (quit, _tmp3_, "app.quit");
	_tmp4_ = g_menu_new ();
	menu = _tmp4_;
	g_menu_append_section (menu, NULL, (GMenuModel*) help);
	g_menu_append_section (menu, NULL, (GMenuModel*) quit);
	gtk_application_set_app_menu ((GtkApplication*) self, (GMenuModel*) menu);
	_g_object_unref0 (menu);
	_g_object_unref0 (quit);
	_g_object_unref0 (help);
}


static void preferences_app_class_init (PreferencesAppClass * klass) {
	preferences_app_parent_class = g_type_class_peek_parent (klass);
	((GApplicationClass *) klass)->activate = preferences_app_real_activate;
	((GApplicationClass *) klass)->startup = preferences_app_real_startup;
}


static void preferences_app_instance_init (PreferencesApp * self) {
}


GType preferences_app_get_type (void) {
	static volatile gsize preferences_app_type_id__volatile = 0;
	if (g_once_init_enter (&preferences_app_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (PreferencesAppClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) preferences_app_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PreferencesApp), 0, (GInstanceInitFunc) preferences_app_instance_init, NULL };
		GType preferences_app_type_id;
		preferences_app_type_id = g_type_register_static (gtk_application_get_type (), "PreferencesApp", &g_define_type_info, 0);
		g_once_init_leave (&preferences_app_type_id__volatile, preferences_app_type_id);
	}
	return preferences_app_type_id__volatile;
}


gboolean handle_console_options (gint* status) {
	gint _vala_status = 0;
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	_vala_status = 0;
	_tmp0_ = show_version;
	if (_tmp0_) {
		g_print ("%s %s\n", "deja-dup-preferences", VERSION);
		result = FALSE;
		if (status) {
			*status = _vala_status;
		}
		return result;
	}
	result = TRUE;
	if (status) {
		*status = _vala_status;
	}
	return result;
}


void handle_help (void) {
	GList* list = NULL;
	PreferencesApp* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	GtkWindow* _tmp2_ = NULL;
	GList* _tmp3_ = NULL;
	_tmp0_ = app;
	_tmp1_ = gtk_application_get_windows ((GtkApplication*) _tmp0_);
	list = _tmp1_;
	_tmp3_ = list;
	if (_tmp3_ == NULL) {
		_tmp2_ = NULL;
	} else {
		GList* _tmp4_ = NULL;
		gconstpointer _tmp5_ = NULL;
		_tmp4_ = list;
		_tmp5_ = _tmp4_->data;
		_tmp2_ = (GtkWindow*) _tmp5_;
	}
	deja_dup_show_uri (_tmp2_, "help:deja-dup");
}


void handle_quit (void) {
	PreferencesApp* _tmp0_ = NULL;
	_tmp0_ = app;
	g_application_quit ((GApplication*) _tmp0_);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	const gchar* _tmp0_ = NULL;
	GOptionContext* context = NULL;
	GOptionContext* _tmp1_ = NULL;
	GOptionContext* _tmp2_ = NULL;
	GOptionContext* _tmp3_ = NULL;
	GOptionGroup* _tmp4_ = NULL;
	gint status = 0;
	gint _tmp11_ = 0;
	gboolean _tmp12_ = FALSE;
	GtkIconTheme* _tmp13_ = NULL;
	gboolean _tmp14_ = FALSE;
	PreferencesApp* _tmp15_ = NULL;
	PreferencesApp* _tmp16_ = NULL;
	gint _tmp17_ = 0;
	GError * _inner_error_ = NULL;
	deja_dup_i18n_setup ();
	_tmp0_ = _ ("Backups");
	g_set_application_name (_tmp0_);
	_tmp1_ = g_option_context_new ("");
	context = _tmp1_;
	_tmp2_ = context;
	g_option_context_add_main_entries (_tmp2_, options, GETTEXT_PACKAGE);
	_tmp3_ = context;
	_tmp4_ = gtk_get_option_group (FALSE);
	g_option_context_add_group (_tmp3_, _tmp4_);
	{
		GOptionContext* _tmp5_ = NULL;
		_tmp5_ = context;
		g_option_context_parse (_tmp5_, &args_length1, &args, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		GOptionContext* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		gchar* _tmp10_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		_tmp8_ = context;
		_tmp9_ = g_option_context_get_help (_tmp8_, TRUE, NULL);
		_tmp10_ = _tmp9_;
		g_printerr ("%s\n\n%s", _tmp7_, _tmp10_);
		_g_free0 (_tmp10_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (context);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_option_context_free0 (context);
		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 0;
	}
	_tmp12_ = handle_console_options (&_tmp11_);
	status = _tmp11_;
	if (!_tmp12_) {
		result = status;
		_g_option_context_free0 (context);
		return result;
	}
	gtk_init (&args_length1, &args);
	_tmp13_ = gtk_icon_theme_get_default ();
	gtk_icon_theme_append_search_path (_tmp13_, THEME_DIR);
	gtk_window_set_default_icon_name (PACKAGE);
	_tmp14_ = deja_dup_gui_initialize (NULL, TRUE);
	if (!_tmp14_) {
		result = 1;
		_g_option_context_free0 (context);
		return result;
	}
	_tmp15_ = preferences_app_new ();
	_g_object_unref0 (app);
	app = _tmp15_;
	_tmp16_ = app;
	_tmp17_ = g_application_run ((GApplication*) _tmp16_, 0, NULL);
	result = _tmp17_;
	_g_option_context_free0 (context);
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return _vala_main (argv, argc);
}



