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

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
/*
    This file is part of Déjà Dup.
    © 2008–2010 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 <config.h>
#include <unique/unique.h>
#include <common.h>
#include <glib/gi18n-lib.h>


#define TYPE_DEJA_DUP_PREFERENCES (deja_dup_preferences_get_type ())
#define DEJA_DUP_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEJA_DUP_PREFERENCES, DejaDupPreferences))
#define DEJA_DUP_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEJA_DUP_PREFERENCES, DejaDupPreferencesClass))
#define IS_DEJA_DUP_PREFERENCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEJA_DUP_PREFERENCES))
#define IS_DEJA_DUP_PREFERENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEJA_DUP_PREFERENCES))
#define DEJA_DUP_PREFERENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEJA_DUP_PREFERENCES, DejaDupPreferencesClass))

typedef struct _DejaDupPreferences DejaDupPreferences;
typedef struct _DejaDupPreferencesClass DejaDupPreferencesClass;
typedef struct _DejaDupPreferencesPrivate DejaDupPreferencesPrivate;

#define TYPE_PREFERENCES_DIALOG (preferences_dialog_get_type ())
#define PREFERENCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PREFERENCES_DIALOG, PreferencesDialog))
#define PREFERENCES_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PREFERENCES_DIALOG, PreferencesDialogClass))
#define IS_PREFERENCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PREFERENCES_DIALOG))
#define IS_PREFERENCES_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PREFERENCES_DIALOG))
#define PREFERENCES_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PREFERENCES_DIALOG, PreferencesDialogClass))

typedef struct _PreferencesDialog PreferencesDialog;
typedef struct _PreferencesDialogClass PreferencesDialogClass;
#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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _DejaDupPreferences {
	GObject parent_instance;
	DejaDupPreferencesPrivate * priv;
};

struct _DejaDupPreferencesClass {
	GObjectClass parent_class;
};


static gpointer deja_dup_preferences_parent_class = NULL;
static gboolean deja_dup_preferences_show_version;
static gboolean deja_dup_preferences_show_version = FALSE;
static PreferencesDialog* deja_dup_preferences_pref_window;
static PreferencesDialog* deja_dup_preferences_pref_window = NULL;

GType deja_dup_preferences_get_type (void) G_GNUC_CONST;
enum  {
	DEJA_DUP_PREFERENCES_DUMMY_PROPERTY
};
GType preferences_dialog_get_type (void) G_GNUC_CONST;
static gboolean deja_dup_preferences_handle_console_options (gint* status);
static UniqueResponse deja_dup_preferences_message_received (UniqueApp* app, gint command, UniqueMessageData* message_data, guint time_);
gint deja_dup_preferences_main (gchar** args, int args_length1);
PreferencesDialog* preferences_dialog_new (GtkWindow* parent);
PreferencesDialog* preferences_dialog_construct (GType object_type, GtkWindow* parent);
static UniqueResponse _deja_dup_preferences_message_received_unique_app_message_received (UniqueApp* _sender, gint command, UniqueMessageData* message_data, guint time_, gpointer self);
DejaDupPreferences* deja_dup_preferences_new (void);
DejaDupPreferences* deja_dup_preferences_construct (GType object_type);
static void deja_dup_preferences_finalize (GObject* obj);

static const GOptionEntry DEJA_DUP_PREFERENCES_options[2] = {{"version", (gchar) 0, 0, G_OPTION_ARG_NONE, &deja_dup_preferences_show_version, "Show version", NULL}, {NULL}};

static gboolean deja_dup_preferences_handle_console_options (gint* status) {
	gint _status = 0;
	gboolean result = FALSE;
	_status = 0;
	if (deja_dup_preferences_show_version) {
		g_print ("%s %s\n", "deja-dup-preferences", VERSION);
		result = FALSE;
		if (status) {
			*status = _status;
		}
		return result;
	}
	result = TRUE;
	if (status) {
		*status = _status;
	}
	return result;
}


static UniqueResponse deja_dup_preferences_message_received (UniqueApp* app, gint command, UniqueMessageData* message_data, guint time_) {
	UniqueResponse result = 0;
	UniqueResponse res;
	g_return_val_if_fail (app != NULL, 0);
	g_return_val_if_fail (message_data != NULL, 0);
	res = UNIQUE_RESPONSE_OK;
	switch (command) {
		case UNIQUE_ACTIVATE:
		{
			gtk_window_present_with_time ((GtkWindow*) deja_dup_preferences_pref_window, (guint32) time_);
			break;
		}
		default:
		break;
	}
	result = res;
	return result;
}


static UniqueResponse _deja_dup_preferences_message_received_unique_app_message_received (UniqueApp* _sender, gint command, UniqueMessageData* message_data, guint time_, gpointer self) {
	UniqueResponse result;
	result = deja_dup_preferences_message_received (_sender, command, message_data, time_);
	return result;
}


gint deja_dup_preferences_main (gchar** args, int args_length1) {
	gint result = 0;
	const gchar* _tmp0_ = NULL;
	GOptionContext* _tmp1_ = NULL;
	GOptionContext* context;
	GOptionGroup* _tmp2_ = NULL;
	gint status = 0;
	gint _tmp5_;
	gboolean _tmp6_;
	UniqueApp* _tmp7_ = NULL;
	UniqueApp* app;
	gboolean _tmp8_;
	GError * _inner_error_ = NULL;
	deja_dup_i18n_setup ();
	_tmp0_ = _ ("Déjà Dup Preferences");
	g_set_application_name (_tmp0_);
	_tmp1_ = g_option_context_new ("");
	context = _tmp1_;
	g_option_context_add_main_entries (context, DEJA_DUP_PREFERENCES_options, GETTEXT_PACKAGE);
	_tmp2_ = gtk_get_option_group (FALSE);
	g_option_context_add_group (context, _tmp2_);
	g_option_context_parse (context, &args_length1, &args, &_inner_error_);
	if (_inner_error_ != NULL) {
		goto __catch0_g_error;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError * e;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = g_option_context_get_help (context, TRUE, NULL);
		_tmp4_ = _tmp3_;
		g_printerr ("%s\n\n%s", e->message, _tmp4_);
		_g_free0 (_tmp4_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (context);
		return result;
	}
	__finally0:
	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;
	}
	_tmp6_ = deja_dup_preferences_handle_console_options (&_tmp5_);
	status = _tmp5_;
	if (!_tmp6_) {
		result = status;
		_g_option_context_free0 (context);
		return result;
	}
	deja_dup_initialize ();
	gtk_init (&args_length1, &args);
	_tmp7_ = unique_app_new ("org.gnome.DejaDup.Preferences", NULL);
	app = _tmp7_;
	if ((g_object_get (app, "is-running", &_tmp8_, NULL), _tmp8_)) {
		unique_app_send_message (app, (gint) UNIQUE_ACTIVATE, NULL);
	} else {
		GtkIconTheme* _tmp9_ = NULL;
		PreferencesDialog* _tmp10_ = NULL;
		PreferencesDialog* _tmp11_;
		_tmp9_ = gtk_icon_theme_get_default ();
		gtk_icon_theme_append_search_path (_tmp9_, THEME_DIR);
		gtk_window_set_default_icon_name (PACKAGE);
		_tmp10_ = preferences_dialog_new (NULL);
		_tmp11_ = g_object_ref_sink (_tmp10_);
		_g_object_unref0 (deja_dup_preferences_pref_window);
		deja_dup_preferences_pref_window = _tmp11_;
		g_signal_connect (app, "message-received", (GCallback) _deja_dup_preferences_message_received_unique_app_message_received, NULL);
		unique_app_watch_window (app, (GtkWindow*) deja_dup_preferences_pref_window);
		gtk_widget_show_all ((GtkWidget*) deja_dup_preferences_pref_window);
		gtk_main ();
	}
	result = 0;
	_g_object_unref0 (app);
	_g_option_context_free0 (context);
	return result;
}


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


DejaDupPreferences* deja_dup_preferences_construct (GType object_type) {
	DejaDupPreferences * self = NULL;
	self = (DejaDupPreferences*) g_object_new (object_type, NULL);
	return self;
}


DejaDupPreferences* deja_dup_preferences_new (void) {
	return deja_dup_preferences_construct (TYPE_DEJA_DUP_PREFERENCES);
}


static void deja_dup_preferences_class_init (DejaDupPreferencesClass * klass) {
	deja_dup_preferences_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = deja_dup_preferences_finalize;
}


static void deja_dup_preferences_instance_init (DejaDupPreferences * self) {
}


static void deja_dup_preferences_finalize (GObject* obj) {
	DejaDupPreferences * self;
	self = DEJA_DUP_PREFERENCES (obj);
	G_OBJECT_CLASS (deja_dup_preferences_parent_class)->finalize (obj);
}


GType deja_dup_preferences_get_type (void) {
	static volatile gsize deja_dup_preferences_type_id__volatile = 0;
	if (g_once_init_enter (&deja_dup_preferences_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DejaDupPreferencesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_preferences_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupPreferences), 0, (GInstanceInitFunc) deja_dup_preferences_instance_init, NULL };
		GType deja_dup_preferences_type_id;
		deja_dup_preferences_type_id = g_type_register_static (G_TYPE_OBJECT, "DejaDupPreferences", &g_define_type_info, 0);
		g_once_init_leave (&deja_dup_preferences_type_id__volatile, deja_dup_preferences_type_id);
	}
	return deja_dup_preferences_type_id__volatile;
}



