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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    © 2008,2009 Michael Terry <mike@mterry.name>

    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 <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <config.h>
#include <common.h>
#include <widgets.h>
#include <gio/gio.h>


#define TYPE_DEJA_DUP_APP (deja_dup_app_get_type ())
#define DEJA_DUP_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEJA_DUP_APP, DejaDupApp))
#define DEJA_DUP_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEJA_DUP_APP, DejaDupAppClass))
#define IS_DEJA_DUP_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEJA_DUP_APP))
#define IS_DEJA_DUP_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEJA_DUP_APP))
#define DEJA_DUP_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEJA_DUP_APP, DejaDupAppClass))

typedef struct _DejaDupApp DejaDupApp;
typedef struct _DejaDupAppClass DejaDupAppClass;
typedef struct _DejaDupAppPrivate DejaDupAppPrivate;
#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)))

#define TYPE_ASSISTANT (assistant_get_type ())
#define ASSISTANT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ASSISTANT, Assistant))
#define ASSISTANT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ASSISTANT, AssistantClass))
#define IS_ASSISTANT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ASSISTANT))
#define IS_ASSISTANT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ASSISTANT))
#define ASSISTANT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ASSISTANT, AssistantClass))

typedef struct _Assistant Assistant;
typedef struct _AssistantClass AssistantClass;

#define TYPE_ASSISTANT_OPERATION (assistant_operation_get_type ())
#define ASSISTANT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ASSISTANT_OPERATION, AssistantOperation))
#define ASSISTANT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ASSISTANT_OPERATION, AssistantOperationClass))
#define IS_ASSISTANT_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ASSISTANT_OPERATION))
#define IS_ASSISTANT_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ASSISTANT_OPERATION))
#define ASSISTANT_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ASSISTANT_OPERATION, AssistantOperationClass))

typedef struct _AssistantOperation AssistantOperation;
typedef struct _AssistantOperationClass AssistantOperationClass;

#define TYPE_ASSISTANT_RESTORE (assistant_restore_get_type ())
#define ASSISTANT_RESTORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ASSISTANT_RESTORE, AssistantRestore))
#define ASSISTANT_RESTORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ASSISTANT_RESTORE, AssistantRestoreClass))
#define IS_ASSISTANT_RESTORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ASSISTANT_RESTORE))
#define IS_ASSISTANT_RESTORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ASSISTANT_RESTORE))
#define ASSISTANT_RESTORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ASSISTANT_RESTORE, AssistantRestoreClass))

typedef struct _AssistantRestore AssistantRestore;
typedef struct _AssistantRestoreClass AssistantRestoreClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __g_list_free_g_object_unref0(var) ((var == NULL) ? NULL : (var = (_g_list_free_g_object_unref (var), NULL)))

#define TYPE_ASSISTANT_BACKUP (assistant_backup_get_type ())
#define ASSISTANT_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ASSISTANT_BACKUP, AssistantBackup))
#define ASSISTANT_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ASSISTANT_BACKUP, AssistantBackupClass))
#define IS_ASSISTANT_BACKUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ASSISTANT_BACKUP))
#define IS_ASSISTANT_BACKUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ASSISTANT_BACKUP))
#define ASSISTANT_BACKUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ASSISTANT_BACKUP, AssistantBackupClass))

typedef struct _AssistantBackup AssistantBackup;
typedef struct _AssistantBackupClass AssistantBackupClass;

#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 _DejaDupApp {
	GObject parent_instance;
	DejaDupAppPrivate * priv;
};

struct _DejaDupAppClass {
	GObjectClass parent_class;
};


extern GtkWindow* toplevel;
GtkWindow* toplevel = NULL;
static gboolean deja_dup_app_valid_duplicity;
static gboolean deja_dup_app_valid_duplicity = FALSE;
static gboolean deja_dup_app_show_version;
static gboolean deja_dup_app_show_version = FALSE;
static gboolean deja_dup_app_restore_mode;
static gboolean deja_dup_app_restore_mode = FALSE;
static gboolean deja_dup_app_backup_mode;
static gboolean deja_dup_app_backup_mode = FALSE;
static char** deja_dup_app_filenames;
static gint deja_dup_app_filenames_length1;
static char** deja_dup_app_filenames = NULL;
static gint deja_dup_app_filenames_length1 = 0;
static gint _deja_dup_app_filenames_size_ = 0;
static gpointer deja_dup_app_parent_class = NULL;

GType deja_dup_app_get_type (void);
enum  {
	DEJA_DUP_APP_DUMMY_PROPERTY
};
static gboolean deja_dup_app_handle_console_options (gint* status);
static gboolean _lambda25_ (void);
static gboolean __lambda25__gsource_func (gpointer self);
AssistantRestore* assistant_restore_new_with_files (GList* files);
AssistantRestore* assistant_restore_construct_with_files (GType object_type, GList* files);
GType assistant_get_type (void);
GType assistant_operation_get_type (void);
GType assistant_restore_get_type (void);
static void _lambda26_ (GtkObject* t);
static void __lambda26__gtk_object_destroy (GtkObject* _sender, gpointer self);
static void _g_list_free_g_object_unref (GList* self);
AssistantBackup* assistant_backup_new (gboolean automatic);
AssistantBackup* assistant_backup_construct (GType object_type, gboolean automatic);
GType assistant_backup_get_type (void);
static void _lambda27_ (GtkObject* t);
static void __lambda27__gtk_object_destroy (GtkObject* _sender, gpointer self);
MainWindow* main_window_new (void);
MainWindow* main_window_construct (GType object_type);
GType main_window_get_type (void);
static void _lambda28_ (GtkObject* w);
static void __lambda28__gtk_object_destroy (GtkObject* _sender, gpointer self);
gint deja_dup_app_main (char** args, int args_length1);
DejaDupApp* deja_dup_app_new (void);
DejaDupApp* deja_dup_app_construct (GType object_type);
static void deja_dup_app_finalize (GObject* obj);

static const GOptionEntry DEJA_DUP_APP_options[5] = {{"version", (gchar) 0, 0, G_OPTION_ARG_NONE, &deja_dup_app_show_version, N_ ("Show version"), NULL}, {"restore", (gchar) 0, 0, G_OPTION_ARG_NONE, &deja_dup_app_restore_mode, N_ ("Restore given files"), NULL}, {"backup", (gchar) 0, 0, G_OPTION_ARG_NONE, &deja_dup_app_backup_mode, N_ ("Immediately start a backup"), NULL}, {"", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &deja_dup_app_filenames, NULL, NULL}, {NULL}};


static gboolean deja_dup_app_handle_console_options (gint* status) {
	gboolean result = FALSE;
	*status = 0;
	if (deja_dup_app_show_version) {
		g_print ("%s %s\n", _ ("Déjà Dup"), VERSION);
		result = FALSE;
		return result;
	}
	if (deja_dup_app_restore_mode) {
		if (deja_dup_app_filenames == NULL) {
			g_printerr ("%s\n", _ ("No filenames provided"));
			*status = 1;
			result = FALSE;
			return result;
		}
	}
	result = TRUE;
	return result;
}


static gboolean _lambda25_ (void) {
	gboolean result = FALSE;
	deja_dup_app_valid_duplicity = deja_dup_init_duplicity (toplevel);
	gtk_main_quit ();
	result = FALSE;
	return result;
}


static gboolean __lambda25__gsource_func (gpointer self) {
	return _lambda25_ ();
}


static void _lambda26_ (GtkObject* t) {
	g_return_if_fail (t != NULL);
	gtk_main_quit ();
}


static void __lambda26__gtk_object_destroy (GtkObject* _sender, gpointer self) {
	_lambda26_ (_sender);
}


static void _g_list_free_g_object_unref (GList* self) {
	g_list_foreach (self, (GFunc) g_object_unref, NULL);
	g_list_free (self);
}


static void _lambda27_ (GtkObject* t) {
	g_return_if_fail (t != NULL);
	gtk_main_quit ();
}


static void __lambda27__gtk_object_destroy (GtkObject* _sender, gpointer self) {
	_lambda27_ (_sender);
}


static void _lambda28_ (GtkObject* w) {
	g_return_if_fail (w != NULL);
	gtk_main_quit ();
}


static void __lambda28__gtk_object_destroy (GtkObject* _sender, gpointer self) {
	_lambda28_ (_sender);
}


gint deja_dup_app_main (char** args, int args_length1) {
	gint result = 0;
	GError * _inner_error_;
	GOptionContext* context;
	gint status = 0;
	_inner_error_ = NULL;
	textdomain (GETTEXT_PACKAGE);
	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	g_set_application_name (_ ("Déjà Dup"));
	context = g_option_context_new ("");
	g_option_context_add_main_entries (context, DEJA_DUP_APP_options, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (FALSE));
	{
		g_option_context_parse (context, &args_length1, &args, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch11_g_error;
		}
	}
	goto __finally11;
	__catch11_g_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		{
			char* _tmp0_;
			g_printerr ("%s\n\n%s", e->message, _tmp0_ = g_option_context_get_help (context, TRUE, NULL));
			_g_free0 (_tmp0_);
			result = 1;
			_g_error_free0 (e);
			_g_option_context_free0 (context);
			return result;
		}
	}
	__finally11:
	if (_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;
	}
	if (!deja_dup_app_handle_console_options (&status)) {
		result = status;
		_g_option_context_free0 (context);
		return result;
	}
	deja_dup_initialize ();
	gtk_init (&args_length1, &args);
	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), THEME_DIR);
	gtk_window_set_default_icon_name (PACKAGE);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, __lambda25__gsource_func, NULL, NULL);
	gtk_main ();
	if (!deja_dup_app_valid_duplicity) {
		result = 1;
		_g_option_context_free0 (context);
		return result;
	}
	if (deja_dup_app_restore_mode) {
		GList* file_list;
		gint i;
		GtkWindow* _tmp1_;
		file_list = NULL;
		i = 0;
		while (TRUE) {
			if (!(deja_dup_app_filenames[i] != NULL)) {
				break;
			}
			file_list = g_list_append (file_list, g_file_new_for_commandline_arg (deja_dup_app_filenames[i++]));
		}
		toplevel = (_tmp1_ = (GtkWindow*) g_object_ref_sink (assistant_restore_new_with_files (file_list)), _g_object_unref0 (toplevel), _tmp1_);
		g_signal_connect ((GtkObject*) toplevel, "destroy", (GCallback) __lambda26__gtk_object_destroy, NULL);
		gtk_widget_show_all ((GtkWidget*) toplevel);
		__g_list_free_g_object_unref0 (file_list);
	} else {
		if (deja_dup_app_backup_mode) {
			GtkWindow* _tmp2_;
			toplevel = (_tmp2_ = (GtkWindow*) g_object_ref_sink (assistant_backup_new (TRUE)), _g_object_unref0 (toplevel), _tmp2_);
			g_signal_connect ((GtkObject*) toplevel, "destroy", (GCallback) __lambda27__gtk_object_destroy, NULL);
		} else {
			GtkWindow* _tmp3_;
			toplevel = (_tmp3_ = (GtkWindow*) g_object_ref_sink (main_window_new ()), _g_object_unref0 (toplevel), _tmp3_);
			gtk_widget_show_all ((GtkWidget*) toplevel);
		}
	}
	g_signal_connect ((GtkObject*) toplevel, "destroy", (GCallback) __lambda28__gtk_object_destroy, NULL);
	gtk_main ();
	result = 0;
	_g_option_context_free0 (context);
	return result;
}


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


DejaDupApp* deja_dup_app_construct (GType object_type) {
	DejaDupApp * self;
	self = (DejaDupApp*) g_object_new (object_type, NULL);
	return self;
}


DejaDupApp* deja_dup_app_new (void) {
	return deja_dup_app_construct (TYPE_DEJA_DUP_APP);
}


static void deja_dup_app_class_init (DejaDupAppClass * klass) {
	deja_dup_app_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = deja_dup_app_finalize;
}


static void deja_dup_app_instance_init (DejaDupApp * self) {
}


static void deja_dup_app_finalize (GObject* obj) {
	DejaDupApp * self;
	self = DEJA_DUP_APP (obj);
	G_OBJECT_CLASS (deja_dup_app_parent_class)->finalize (obj);
}


GType deja_dup_app_get_type (void) {
	static volatile gsize deja_dup_app_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_app_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupAppClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_app_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupApp), 0, (GInstanceInitFunc) deja_dup_app_instance_init, NULL };
		GType deja_dup_app_type_id;
		deja_dup_app_type_id = g_type_register_static (G_TYPE_OBJECT, "DejaDupApp", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_app_type_id__volatile, deja_dup_app_type_id);
	}
	return deja_dup_app_type_id__volatile;
}




