/* application.c generated by valac 0.21.1.1-0d6f, the Vala compiler
 * generated from application.vala, do not modify */

/*
 * Copyright (C) 2013  Paolo Borelli <pborelli@gnome.org>
 *
 * 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.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include "config.h"


#define CLOCKS_TYPE_APPLICATION (clocks_application_get_type ())
#define CLOCKS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_TYPE_APPLICATION, ClocksApplication))
#define CLOCKS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_TYPE_APPLICATION, ClocksApplicationClass))
#define CLOCKS_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_TYPE_APPLICATION))
#define CLOCKS_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_TYPE_APPLICATION))
#define CLOCKS_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_TYPE_APPLICATION, ClocksApplicationClass))

typedef struct _ClocksApplication ClocksApplication;
typedef struct _ClocksApplicationClass ClocksApplicationClass;
typedef struct _ClocksApplicationPrivate ClocksApplicationPrivate;

#define CLOCKS_TYPE_WINDOW (clocks_window_get_type ())
#define CLOCKS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_TYPE_WINDOW, ClocksWindow))
#define CLOCKS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_TYPE_WINDOW, ClocksWindowClass))
#define CLOCKS_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_TYPE_WINDOW))
#define CLOCKS_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_TYPE_WINDOW))
#define CLOCKS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_TYPE_WINDOW, ClocksWindowClass))

typedef struct _ClocksWindow ClocksWindow;
typedef struct _ClocksWindowClass ClocksWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (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 _ClocksApplication {
	GtkApplication parent_instance;
	ClocksApplicationPrivate * priv;
};

struct _ClocksApplicationClass {
	GtkApplicationClass parent_class;
};

struct _ClocksApplicationPrivate {
	ClocksWindow* window;
};


static gpointer clocks_application_parent_class = NULL;
static gboolean clocks_application_print_version;
static gboolean clocks_application_print_version = FALSE;

GType clocks_application_get_type (void) G_GNUC_CONST;
GType clocks_window_get_type (void) G_GNUC_CONST;
#define CLOCKS_APPLICATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCKS_TYPE_APPLICATION, ClocksApplicationPrivate))
enum  {
	CLOCKS_APPLICATION_DUMMY_PROPERTY
};
static void clocks_application_on_quit_activate (ClocksApplication* self);
static void _clocks_application_on_quit_activate_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self);
ClocksApplication* clocks_application_new (void);
ClocksApplication* clocks_application_construct (GType object_type);
static void clocks_application_real_activate (GApplication* base);
ClocksWindow* clocks_window_new (ClocksApplication* app);
ClocksWindow* clocks_window_construct (GType object_type, ClocksApplication* app);
static void clocks_application_real_startup (GApplication* base);
GtkCssProvider* clocks_utils_load_css (const gchar* css);
GtkBuilder* clocks_utils_load_ui (const gchar* ui);
static gboolean clocks_application_real_local_command_line (GApplication* base, gchar*** arguments, gint* exit_status);
static void clocks_application_finalize (GObject* obj);
static gint _vala_array_length (gpointer array);

static const GOptionEntry CLOCKS_APPLICATION_option_entries[2] = {{"version", 'v', 0, G_OPTION_ARG_NONE, &clocks_application_print_version, "Print version information and exit", NULL}, {NULL}};
static const GActionEntry CLOCKS_APPLICATION_action_entries[1] = {{"quit", _clocks_application_on_quit_activate_gsimple_action_activate_callback}};

static void _clocks_application_on_quit_activate_gsimple_action_activate_callback (GSimpleAction* action, GVariant* parameter, gpointer self) {
	clocks_application_on_quit_activate (self);
}


ClocksApplication* clocks_application_construct (GType object_type) {
	ClocksApplication * self = NULL;
	self = (ClocksApplication*) g_object_new (object_type, "application-id", "org.gnome.clocks", NULL);
	g_action_map_add_action_entries ((GActionMap*) self, CLOCKS_APPLICATION_action_entries, G_N_ELEMENTS (CLOCKS_APPLICATION_action_entries), self);
	return self;
}


ClocksApplication* clocks_application_new (void) {
	return clocks_application_construct (CLOCKS_TYPE_APPLICATION);
}


static void clocks_application_real_activate (GApplication* base) {
	ClocksApplication * self;
	ClocksWindow* _tmp0_ = NULL;
	ClocksWindow* _tmp2_ = NULL;
	self = (ClocksApplication*) base;
	_tmp0_ = self->priv->window;
	if (_tmp0_ == NULL) {
		ClocksWindow* _tmp1_ = NULL;
		_tmp1_ = clocks_window_new (self);
		g_object_ref_sink (_tmp1_);
		_g_object_unref0 (self->priv->window);
		self->priv->window = _tmp1_;
	}
	_tmp2_ = self->priv->window;
	gtk_window_present ((GtkWindow*) _tmp2_);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void clocks_application_real_startup (GApplication* base) {
	ClocksApplication * self;
	GtkCssProvider* css_provider = NULL;
	GtkCssProvider* _tmp0_ = NULL;
	GdkScreen* _tmp1_ = NULL;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp2_ = NULL;
	GMenuModel* app_menu = NULL;
	GObject* _tmp3_ = NULL;
	GMenuModel* _tmp4_ = NULL;
	self = (ClocksApplication*) base;
	G_APPLICATION_CLASS (clocks_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_APPLICATION, GtkApplication));
	_tmp0_ = clocks_utils_load_css ("gnome-clocks.css");
	css_provider = _tmp0_;
	_tmp1_ = gdk_screen_get_default ();
	gtk_style_context_add_provider_for_screen (_tmp1_, (GtkStyleProvider*) css_provider, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_tmp2_ = clocks_utils_load_ui ("menu.ui");
	builder = _tmp2_;
	_tmp3_ = gtk_builder_get_object (builder, "appmenu");
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, g_menu_model_get_type ()) ? ((GMenuModel*) _tmp3_) : NULL);
	app_menu = _tmp4_;
	gtk_application_set_app_menu ((GtkApplication*) self, app_menu);
	gtk_application_add_accelerator ((GtkApplication*) self, "<Primary>a", "win.select-all", NULL);
	_g_object_unref0 (app_menu);
	_g_object_unref0 (builder);
	_g_object_unref0 (css_provider);
}


static gboolean clocks_application_real_local_command_line (GApplication* base, gchar*** arguments, gint* exit_status) {
	ClocksApplication * self;
	gint _vala_exit_status = 0;
	gboolean result = FALSE;
	GOptionContext* ctx = NULL;
	GOptionContext* _tmp0_ = NULL;
	GOptionContext* _tmp1_ = NULL;
	GOptionContext* _tmp2_ = NULL;
	GOptionGroup* _tmp3_ = NULL;
	gchar** argv = NULL;
	gchar** _tmp4_ = NULL;
	gint _tmp4__length1 = 0;
	gint argv_length1 = 0;
	gint _argv_size_ = 0;
	gboolean _tmp6_ = FALSE;
	gint _tmp8_ = 0;
	gboolean _tmp9_ = FALSE;
	GError * _inner_error_ = NULL;
	self = (ClocksApplication*) base;
	_tmp0_ = g_option_context_new ("");
	ctx = _tmp0_;
	_tmp1_ = ctx;
	g_option_context_add_main_entries (_tmp1_, CLOCKS_APPLICATION_option_entries, GETTEXT_PACKAGE);
	_tmp2_ = ctx;
	_tmp3_ = gtk_get_option_group (TRUE);
	g_option_context_add_group (_tmp2_, _tmp3_);
	_tmp4_ = *arguments;
	_tmp4__length1 = _vala_array_length (*arguments);
	argv = _tmp4_;
	argv_length1 = _tmp4__length1;
	_argv_size_ = argv_length1;
	{
		GOptionContext* _tmp5_ = NULL;
		_tmp5_ = ctx;
		g_option_context_parse (_tmp5_, &argv_length1, &argv, &_inner_error_);
		if (_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_vala_exit_status = 1;
		result = TRUE;
		_g_error_free0 (e);
		_g_option_context_free0 (ctx);
		if (exit_status) {
			*exit_status = _vala_exit_status;
		}
		return result;
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (ctx);
		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 FALSE;
	}
	_tmp6_ = clocks_application_print_version;
	if (_tmp6_) {
		const gchar* _tmp7_ = NULL;
		_tmp7_ = g_get_application_name ();
		g_print ("%s %s\n", _tmp7_, VERSION);
		_vala_exit_status = 0;
		result = TRUE;
		_g_option_context_free0 (ctx);
		if (exit_status) {
			*exit_status = _vala_exit_status;
		}
		return result;
	}
	_tmp9_ = G_APPLICATION_CLASS (clocks_application_parent_class)->local_command_line ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_APPLICATION, GtkApplication), arguments, &_tmp8_);
	_vala_exit_status = _tmp8_;
	result = _tmp9_;
	_g_option_context_free0 (ctx);
	if (exit_status) {
		*exit_status = _vala_exit_status;
	}
	return result;
}


static void clocks_application_on_quit_activate (ClocksApplication* self) {
	g_return_if_fail (self != NULL);
	g_application_quit ((GApplication*) self);
}


static void clocks_application_class_init (ClocksApplicationClass * klass) {
	clocks_application_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ClocksApplicationPrivate));
	G_APPLICATION_CLASS (klass)->activate = clocks_application_real_activate;
	G_APPLICATION_CLASS (klass)->startup = clocks_application_real_startup;
	G_APPLICATION_CLASS (klass)->local_command_line = clocks_application_real_local_command_line;
	G_OBJECT_CLASS (klass)->finalize = clocks_application_finalize;
}


static void clocks_application_instance_init (ClocksApplication * self) {
	self->priv = CLOCKS_APPLICATION_GET_PRIVATE (self);
}


static void clocks_application_finalize (GObject* obj) {
	ClocksApplication * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CLOCKS_TYPE_APPLICATION, ClocksApplication);
	_g_object_unref0 (self->priv->window);
	G_OBJECT_CLASS (clocks_application_parent_class)->finalize (obj);
}


GType clocks_application_get_type (void) {
	static volatile gsize clocks_application_type_id__volatile = 0;
	if (g_once_init_enter (&clocks_application_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ClocksApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) clocks_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ClocksApplication), 0, (GInstanceInitFunc) clocks_application_instance_init, NULL };
		GType clocks_application_type_id;
		clocks_application_type_id = g_type_register_static (GTK_TYPE_APPLICATION, "ClocksApplication", &g_define_type_info, 0);
		g_once_init_leave (&clocks_application_type_id__volatile, clocks_application_type_id);
	}
	return clocks_application_type_id__volatile;
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



