/* application.c generated by valac 0.24.0.146-7a48b, 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)))

struct _ClocksApplication {
	GtkApplication parent_instance;
	ClocksApplicationPrivate * priv;
};

struct _ClocksApplicationClass {
	GtkApplicationClass parent_class;
};

struct _ClocksApplicationPrivate {
	ClocksWindow* window;
};


static gpointer clocks_application_parent_class = NULL;

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 gint clocks_application_real_handle_local_options (GApplication* base, GVariantDict* options);
static void clocks_application_finalize (GObject* obj);

static const GOptionEntry CLOCKS_APPLICATION_option_entries[2] = {{"version", 'v', 0, G_OPTION_ARG_NONE, NULL, "Print version information and exit", NULL}, {NULL}};
static const GActionEntry CLOCKS_APPLICATION_action_entries[3] = {{"stop-alarm", NULL, "s"}, {"snooze-alarm", NULL, "s"}, {"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 ((ClocksApplication*) 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_application_add_main_option_entries ((GApplication*) self, CLOCKS_APPLICATION_option_entries);
	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>n", "win.new", NULL);
	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 gint clocks_application_real_handle_local_options (GApplication* base, GVariantDict* options) {
	ClocksApplication * self;
	gint result = 0;
	GVariantDict* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	self = (ClocksApplication*) base;
	g_return_val_if_fail (options != NULL, 0);
	_tmp0_ = options;
	_tmp1_ = g_variant_dict_contains (_tmp0_, "version");
	if (_tmp1_) {
		const gchar* _tmp2_ = NULL;
		_tmp2_ = g_get_application_name ();
		g_print ("%s %s\n", _tmp2_, VERSION);
		result = 0;
		return result;
	}
	result = -1;
	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));
	((GApplicationClass *) klass)->activate = clocks_application_real_activate;
	((GApplicationClass *) klass)->startup = clocks_application_real_startup;
	((GApplicationClass *) klass)->handle_local_options = clocks_application_real_handle_local_options;
	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;
}



