/* stopwatch.c generated by valac 0.20.1-dirty, the Vala compiler
 * generated from stopwatch.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 <stdlib.h>
#include <string.h>
#include <libgd/gd.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>


#define CLOCKS_TYPE_CLOCK (clocks_clock_get_type ())
#define CLOCKS_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_TYPE_CLOCK, ClocksClock))
#define CLOCKS_IS_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_TYPE_CLOCK))
#define CLOCKS_CLOCK_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CLOCKS_TYPE_CLOCK, ClocksClockIface))

typedef struct _ClocksClock ClocksClock;
typedef struct _ClocksClockIface ClocksClockIface;

#define CLOCKS_TYPE_HEADER_BAR (clocks_header_bar_get_type ())
#define CLOCKS_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_TYPE_HEADER_BAR, ClocksHeaderBar))
#define CLOCKS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_TYPE_HEADER_BAR, ClocksHeaderBarClass))
#define CLOCKS_IS_HEADER_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_TYPE_HEADER_BAR))
#define CLOCKS_IS_HEADER_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_TYPE_HEADER_BAR))
#define CLOCKS_HEADER_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_TYPE_HEADER_BAR, ClocksHeaderBarClass))

typedef struct _ClocksHeaderBar ClocksHeaderBar;
typedef struct _ClocksHeaderBarClass ClocksHeaderBarClass;

#define CLOCKS_STOPWATCH_TYPE_MAIN_PANEL (clocks_stopwatch_main_panel_get_type ())
#define CLOCKS_STOPWATCH_MAIN_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanel))
#define CLOCKS_STOPWATCH_MAIN_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanelClass))
#define CLOCKS_STOPWATCH_IS_MAIN_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL))
#define CLOCKS_STOPWATCH_IS_MAIN_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL))
#define CLOCKS_STOPWATCH_MAIN_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanelClass))

typedef struct _ClocksStopwatchMainPanel ClocksStopwatchMainPanel;
typedef struct _ClocksStopwatchMainPanelClass ClocksStopwatchMainPanelClass;
typedef struct _ClocksStopwatchMainPanelPrivate ClocksStopwatchMainPanelPrivate;

#define CLOCKS_STOPWATCH_MAIN_PANEL_TYPE_STATE (clocks_stopwatch_main_panel_state_get_type ())

#define CLOCKS_STOPWATCH_MAIN_PANEL_TYPE_LAPS_COLUMN (clocks_stopwatch_main_panel_laps_column_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_timer_destroy0(var) ((var == NULL) ? NULL : (var = (g_timer_destroy (var), NULL)))
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))

struct _ClocksClockIface {
	GTypeInterface parent_iface;
	void (*activate_new) (ClocksClock* self);
	void (*activate_select_all) (ClocksClock* self);
	void (*activate_select_none) (ClocksClock* self);
	gboolean (*escape_pressed) (ClocksClock* self);
	void (*update_header_bar) (ClocksClock* self);
	const gchar* (*get_label) (ClocksClock* self);
	void (*set_label) (ClocksClock* self, const gchar* value);
	ClocksHeaderBar* (*get_header_bar) (ClocksClock* self);
	void (*set_header_bar) (ClocksClock* self, ClocksHeaderBar* value);
};

struct _ClocksStopwatchMainPanel {
	GtkBox parent_instance;
	ClocksStopwatchMainPanelPrivate * priv;
};

struct _ClocksStopwatchMainPanelClass {
	GtkBoxClass parent_class;
};

typedef enum  {
	CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET,
	CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING,
	CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED
} ClocksStopwatchMainPanelState;

struct _ClocksStopwatchMainPanelPrivate {
	gchar* _label;
	ClocksHeaderBar* _header_bar;
	ClocksStopwatchMainPanelState state;
	GTimer* timer;
	guint timeout_id;
	gint current_lap;
	gdouble last_lap_time;
	GtkLabel* time_label;
	GtkButton* left_button;
	GtkButton* right_button;
	GtkListStore* laps_model;
	GtkTreeView* laps_view;
};

typedef enum  {
	CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_LAP,
	CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_SPLIT,
	CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_TOTAL
} ClocksStopwatchMainPanelLapsColumn;


static gpointer clocks_stopwatch_main_panel_parent_class = NULL;
static ClocksClockIface* clocks_stopwatch_main_panel_clocks_clock_parent_iface = NULL;

GType clocks_header_bar_get_type (void) G_GNUC_CONST;
GType clocks_clock_get_type (void) G_GNUC_CONST;
GType clocks_stopwatch_main_panel_get_type (void) G_GNUC_CONST;
static GType clocks_stopwatch_main_panel_state_get_type (void) G_GNUC_UNUSED;
#define CLOCKS_STOPWATCH_MAIN_PANEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanelPrivate))
enum  {
	CLOCKS_STOPWATCH_MAIN_PANEL_DUMMY_PROPERTY,
	CLOCKS_STOPWATCH_MAIN_PANEL_LABEL,
	CLOCKS_STOPWATCH_MAIN_PANEL_HEADER_BAR
};
static GType clocks_stopwatch_main_panel_laps_column_get_type (void) G_GNUC_UNUSED;
ClocksStopwatchMainPanel* clocks_stopwatch_main_panel_new (ClocksHeaderBar* header_bar);
ClocksStopwatchMainPanel* clocks_stopwatch_main_panel_construct (GType object_type, ClocksHeaderBar* header_bar);
GtkBuilder* clocks_utils_load_ui (const gchar* ui);
static void clocks_stopwatch_main_panel_on_left_button_clicked (ClocksStopwatchMainPanel* self, GtkButton* button);
static void _clocks_stopwatch_main_panel_on_left_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void clocks_stopwatch_main_panel_on_right_button_clicked (ClocksStopwatchMainPanel* self, GtkButton* button);
static void _clocks_stopwatch_main_panel_on_right_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void __lambda44_ (ClocksStopwatchMainPanel* self, GtkWidget* w);
static gboolean clocks_stopwatch_main_panel_update_time_label (ClocksStopwatchMainPanel* self);
static void clocks_stopwatch_main_panel_add_timeout (ClocksStopwatchMainPanel* self);
static void ___lambda44__gtk_widget_map (GtkWidget* _sender, gpointer self);
static void __lambda45_ (ClocksStopwatchMainPanel* self, GtkWidget* w);
static void clocks_stopwatch_main_panel_remove_timeout (ClocksStopwatchMainPanel* self);
static void ___lambda45__gtk_widget_unmap (GtkWidget* _sender, gpointer self);
static void clocks_stopwatch_main_panel_reset (ClocksStopwatchMainPanel* self);
static void clocks_stopwatch_main_panel_start (ClocksStopwatchMainPanel* self);
static void clocks_stopwatch_main_panel_stop (ClocksStopwatchMainPanel* self);
static void clocks_stopwatch_main_panel_lap (ClocksStopwatchMainPanel* self);
void clocks_utils_time_to_hms (gdouble t, gint* h, gint* m, gint* s, gdouble* remainder);
static gboolean _clocks_stopwatch_main_panel_update_time_label_gsource_func (gpointer self);
static void clocks_stopwatch_main_panel_real_grab_focus (GtkWidget* base);
static void clocks_stopwatch_main_panel_finalize (GObject* obj);
const gchar* clocks_clock_get_label (ClocksClock* self);
ClocksHeaderBar* clocks_clock_get_header_bar (ClocksClock* self);
static void _vala_clocks_stopwatch_main_panel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
void clocks_clock_set_label (ClocksClock* self, const gchar* value);
void clocks_clock_set_header_bar (ClocksClock* self, ClocksHeaderBar* value);
static void _vala_clocks_stopwatch_main_panel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static GType clocks_stopwatch_main_panel_state_get_type (void) {
	static volatile gsize clocks_stopwatch_main_panel_state_type_id__volatile = 0;
	if (g_once_init_enter (&clocks_stopwatch_main_panel_state_type_id__volatile)) {
		static const GEnumValue values[] = {{CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET, "CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET", "reset"}, {CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING, "CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING", "running"}, {CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED, "CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED", "stopped"}, {0, NULL, NULL}};
		GType clocks_stopwatch_main_panel_state_type_id;
		clocks_stopwatch_main_panel_state_type_id = g_enum_register_static ("ClocksStopwatchMainPanelState", values);
		g_once_init_leave (&clocks_stopwatch_main_panel_state_type_id__volatile, clocks_stopwatch_main_panel_state_type_id);
	}
	return clocks_stopwatch_main_panel_state_type_id__volatile;
}


static GType clocks_stopwatch_main_panel_laps_column_get_type (void) {
	static volatile gsize clocks_stopwatch_main_panel_laps_column_type_id__volatile = 0;
	if (g_once_init_enter (&clocks_stopwatch_main_panel_laps_column_type_id__volatile)) {
		static const GEnumValue values[] = {{CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_LAP, "CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_LAP", "lap"}, {CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_SPLIT, "CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_SPLIT", "split"}, {CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_TOTAL, "CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_TOTAL", "total"}, {0, NULL, NULL}};
		GType clocks_stopwatch_main_panel_laps_column_type_id;
		clocks_stopwatch_main_panel_laps_column_type_id = g_enum_register_static ("ClocksStopwatchMainPanelLapsColumn", values);
		g_once_init_leave (&clocks_stopwatch_main_panel_laps_column_type_id__volatile, clocks_stopwatch_main_panel_laps_column_type_id);
	}
	return clocks_stopwatch_main_panel_laps_column_type_id__volatile;
}


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


static void _clocks_stopwatch_main_panel_on_left_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	clocks_stopwatch_main_panel_on_left_button_clicked (self, _sender);
}


static void _clocks_stopwatch_main_panel_on_right_button_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	clocks_stopwatch_main_panel_on_right_button_clicked (self, _sender);
}


static void __lambda44_ (ClocksStopwatchMainPanel* self, GtkWidget* w) {
	ClocksStopwatchMainPanelState _tmp0_;
	g_return_if_fail (w != NULL);
	_tmp0_ = self->priv->state;
	if (_tmp0_ == CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING) {
		clocks_stopwatch_main_panel_update_time_label (self);
		clocks_stopwatch_main_panel_add_timeout (self);
	}
}


static void ___lambda44__gtk_widget_map (GtkWidget* _sender, gpointer self) {
	__lambda44_ (self, _sender);
}


static void __lambda45_ (ClocksStopwatchMainPanel* self, GtkWidget* w) {
	ClocksStopwatchMainPanelState _tmp0_;
	g_return_if_fail (w != NULL);
	_tmp0_ = self->priv->state;
	if (_tmp0_ == CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING) {
		clocks_stopwatch_main_panel_remove_timeout (self);
	}
}


static void ___lambda45__gtk_widget_unmap (GtkWidget* _sender, gpointer self) {
	__lambda45_ (self, _sender);
}


ClocksStopwatchMainPanel* clocks_stopwatch_main_panel_construct (GType object_type, ClocksHeaderBar* header_bar) {
	ClocksStopwatchMainPanel * self = NULL;
	const gchar* _tmp0_ = NULL;
	ClocksHeaderBar* _tmp1_;
	GTimer* _tmp2_;
	GtkBuilder* _tmp3_ = NULL;
	GtkBuilder* builder;
	GObject* _tmp4_ = NULL;
	GtkWidget* _tmp5_;
	GtkWidget* stopwatch_panel;
	GObject* _tmp6_ = NULL;
	GtkLabel* _tmp7_;
	GObject* _tmp8_ = NULL;
	GtkButton* _tmp9_;
	GObject* _tmp10_ = NULL;
	GtkButton* _tmp11_;
	GObject* _tmp12_ = NULL;
	GtkListStore* _tmp13_;
	GObject* _tmp14_ = NULL;
	GtkTreeView* _tmp15_;
	GtkButton* _tmp16_;
	GtkButton* _tmp17_;
	g_return_val_if_fail (header_bar != NULL, NULL);
	_tmp0_ = _ ("Stopwatch");
	_tmp1_ = header_bar;
	self = (ClocksStopwatchMainPanel*) g_object_new (object_type, "label", _tmp0_, "header-bar", _tmp1_, NULL);
	_tmp2_ = g_timer_new ();
	_g_timer_destroy0 (self->priv->timer);
	self->priv->timer = _tmp2_;
	self->priv->timeout_id = (guint) 0;
	_tmp3_ = clocks_utils_load_ui ("stopwatch.ui");
	builder = _tmp3_;
	_tmp4_ = gtk_builder_get_object (builder, "stopwatch_panel");
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, GTK_TYPE_WIDGET) ? ((GtkWidget*) _tmp4_) : NULL);
	stopwatch_panel = _tmp5_;
	_tmp6_ = gtk_builder_get_object (builder, "time_label");
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, GTK_TYPE_LABEL) ? ((GtkLabel*) _tmp6_) : NULL);
	_g_object_unref0 (self->priv->time_label);
	self->priv->time_label = _tmp7_;
	_tmp8_ = gtk_builder_get_object (builder, "left_button");
	_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, GTK_TYPE_BUTTON) ? ((GtkButton*) _tmp8_) : NULL);
	_g_object_unref0 (self->priv->left_button);
	self->priv->left_button = _tmp9_;
	_tmp10_ = gtk_builder_get_object (builder, "right_button");
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp10_, GTK_TYPE_BUTTON) ? ((GtkButton*) _tmp10_) : NULL);
	_g_object_unref0 (self->priv->right_button);
	self->priv->right_button = _tmp11_;
	_tmp12_ = gtk_builder_get_object (builder, "laps_model");
	_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp12_, GTK_TYPE_LIST_STORE) ? ((GtkListStore*) _tmp12_) : NULL);
	_g_object_unref0 (self->priv->laps_model);
	self->priv->laps_model = _tmp13_;
	_tmp14_ = gtk_builder_get_object (builder, "laps_view");
	_tmp15_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp14_, GTK_TYPE_TREE_VIEW) ? ((GtkTreeView*) _tmp14_) : NULL);
	_g_object_unref0 (self->priv->laps_view);
	self->priv->laps_view = _tmp15_;
	_tmp16_ = self->priv->left_button;
	g_signal_connect_object (_tmp16_, "clicked", (GCallback) _clocks_stopwatch_main_panel_on_left_button_clicked_gtk_button_clicked, self, 0);
	_tmp17_ = self->priv->right_button;
	g_signal_connect_object (_tmp17_, "clicked", (GCallback) _clocks_stopwatch_main_panel_on_right_button_clicked_gtk_button_clicked, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "map", (GCallback) ___lambda44__gtk_widget_map, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "unmap", (GCallback) ___lambda45__gtk_widget_unmap, self, 0);
	clocks_stopwatch_main_panel_reset (self);
	gtk_container_add ((GtkContainer*) self, stopwatch_panel);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (stopwatch_panel);
	_g_object_unref0 (builder);
	return self;
}


ClocksStopwatchMainPanel* clocks_stopwatch_main_panel_new (ClocksHeaderBar* header_bar) {
	return clocks_stopwatch_main_panel_construct (CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, header_bar);
}


static void clocks_stopwatch_main_panel_on_left_button_clicked (ClocksStopwatchMainPanel* self, GtkButton* button) {
	ClocksStopwatchMainPanelState _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = self->priv->state;
	switch (_tmp0_) {
		case CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET:
		case CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED:
		{
			clocks_stopwatch_main_panel_start (self);
			break;
		}
		case CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING:
		{
			clocks_stopwatch_main_panel_stop (self);
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}


static void clocks_stopwatch_main_panel_on_right_button_clicked (ClocksStopwatchMainPanel* self, GtkButton* button) {
	ClocksStopwatchMainPanelState _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (button != NULL);
	_tmp0_ = self->priv->state;
	switch (_tmp0_) {
		case CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED:
		{
			clocks_stopwatch_main_panel_reset (self);
			break;
		}
		case CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING:
		{
			clocks_stopwatch_main_panel_lap (self);
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}


static void clocks_stopwatch_main_panel_start (ClocksStopwatchMainPanel* self) {
	ClocksStopwatchMainPanelState _tmp0_;
	GtkButton* _tmp3_;
	const gchar* _tmp4_ = NULL;
	GtkButton* _tmp5_;
	GtkStyleContext* _tmp6_ = NULL;
	GtkButton* _tmp7_;
	GtkButton* _tmp8_;
	const gchar* _tmp9_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->state;
	if (_tmp0_ == CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET) {
		GTimer* _tmp1_;
		_tmp1_ = self->priv->timer;
		g_timer_start (_tmp1_);
	} else {
		GTimer* _tmp2_;
		_tmp2_ = self->priv->timer;
		g_timer_continue (_tmp2_);
	}
	self->priv->state = CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RUNNING;
	clocks_stopwatch_main_panel_add_timeout (self);
	_tmp3_ = self->priv->left_button;
	_tmp4_ = _ ("Stop");
	gtk_button_set_label (_tmp3_, _tmp4_);
	_tmp5_ = self->priv->left_button;
	_tmp6_ = gtk_widget_get_style_context ((GtkWidget*) _tmp5_);
	gtk_style_context_add_class (_tmp6_, "clocks-stop");
	_tmp7_ = self->priv->right_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp7_, TRUE);
	_tmp8_ = self->priv->right_button;
	_tmp9_ = _ ("Lap");
	gtk_button_set_label (_tmp8_, _tmp9_);
}


static void clocks_stopwatch_main_panel_stop (ClocksStopwatchMainPanel* self) {
	GTimer* _tmp0_;
	GtkButton* _tmp1_;
	const gchar* _tmp2_ = NULL;
	GtkButton* _tmp3_;
	GtkStyleContext* _tmp4_ = NULL;
	GtkButton* _tmp5_;
	GtkStyleContext* _tmp6_ = NULL;
	GtkButton* _tmp7_;
	GtkButton* _tmp8_;
	const gchar* _tmp9_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	g_timer_stop (_tmp0_);
	self->priv->state = CLOCKS_STOPWATCH_MAIN_PANEL_STATE_STOPPED;
	clocks_stopwatch_main_panel_remove_timeout (self);
	_tmp1_ = self->priv->left_button;
	_tmp2_ = _ ("Continue");
	gtk_button_set_label (_tmp1_, _tmp2_);
	_tmp3_ = self->priv->left_button;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) _tmp3_);
	gtk_style_context_remove_class (_tmp4_, "clocks-stop");
	_tmp5_ = self->priv->left_button;
	_tmp6_ = gtk_widget_get_style_context ((GtkWidget*) _tmp5_);
	gtk_style_context_add_class (_tmp6_, "clocks-go");
	_tmp7_ = self->priv->right_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp7_, TRUE);
	_tmp8_ = self->priv->right_button;
	_tmp9_ = _ ("Reset");
	gtk_button_set_label (_tmp8_, _tmp9_);
}


static void clocks_stopwatch_main_panel_reset (ClocksStopwatchMainPanel* self) {
	GTimer* _tmp0_;
	GtkButton* _tmp1_;
	const gchar* _tmp2_ = NULL;
	GtkButton* _tmp3_;
	GtkStyleContext* _tmp4_ = NULL;
	GtkButton* _tmp5_;
	GtkListStore* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timer;
	g_timer_reset (_tmp0_);
	self->priv->state = CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET;
	clocks_stopwatch_main_panel_remove_timeout (self);
	clocks_stopwatch_main_panel_update_time_label (self);
	_tmp1_ = self->priv->left_button;
	_tmp2_ = _ ("Start");
	gtk_button_set_label (_tmp1_, _tmp2_);
	_tmp3_ = self->priv->left_button;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) _tmp3_);
	gtk_style_context_add_class (_tmp4_, "clocks-go");
	_tmp5_ = self->priv->right_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp5_, FALSE);
	self->priv->current_lap = 0;
	self->priv->last_lap_time = (gdouble) 0;
	_tmp6_ = self->priv->laps_model;
	gtk_list_store_clear (_tmp6_);
}


static void clocks_stopwatch_main_panel_lap (ClocksStopwatchMainPanel* self) {
	gint _tmp0_;
	GTimer* _tmp1_;
	gdouble _tmp2_ = 0.0;
	gdouble e;
	gdouble _tmp3_;
	gdouble _tmp4_;
	gdouble split;
	gdouble _tmp5_;
	gint h = 0;
	gint m = 0;
	gint s = 0;
	gdouble r = 0.0;
	gdouble _tmp6_;
	gint _tmp7_ = 0;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	gdouble _tmp10_ = 0.0;
	gdouble _tmp11_;
	gint cs;
	gint split_h = 0;
	gint split_m = 0;
	gint split_s = 0;
	gdouble _tmp12_;
	gint _tmp13_ = 0;
	gint _tmp14_ = 0;
	gint _tmp15_ = 0;
	gdouble _tmp16_ = 0.0;
	gdouble _tmp17_;
	gint split_cs;
	gint _tmp18_;
	gchar* _tmp19_ = NULL;
	gchar* n_label;
	gchar* split_label = NULL;
	gint _tmp20_;
	gchar* tot_label = NULL;
	gint _tmp30_;
	GtkTreeIter i = {0};
	GtkListStore* _tmp40_;
	GtkTreeIter _tmp41_ = {0};
	GtkListStore* _tmp42_;
	GtkTreeIter _tmp43_;
	const gchar* _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	GtkListStore* _tmp47_;
	GtkTreeIter _tmp48_;
	GtkTreePath* _tmp49_ = NULL;
	GtkTreePath* p;
	GtkTreeView* _tmp50_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_lap;
	self->priv->current_lap = _tmp0_ + 1;
	_tmp1_ = self->priv->timer;
	_tmp2_ = g_timer_elapsed (_tmp1_, NULL);
	e = _tmp2_;
	_tmp3_ = e;
	_tmp4_ = self->priv->last_lap_time;
	split = _tmp3_ - _tmp4_;
	_tmp5_ = e;
	self->priv->last_lap_time = _tmp5_;
	_tmp6_ = e;
	clocks_utils_time_to_hms (_tmp6_, &_tmp7_, &_tmp8_, &_tmp9_, &_tmp10_);
	h = _tmp7_;
	m = _tmp8_;
	s = _tmp9_;
	r = _tmp10_;
	_tmp11_ = r;
	cs = (gint) (_tmp11_ * 100);
	_tmp12_ = split;
	clocks_utils_time_to_hms (_tmp12_, &_tmp13_, &_tmp14_, &_tmp15_, &_tmp16_);
	split_h = _tmp13_;
	split_m = _tmp14_;
	split_s = _tmp15_;
	r = _tmp16_;
	_tmp17_ = r;
	split_cs = (gint) (_tmp17_ * 100);
	_tmp18_ = self->priv->current_lap;
	_tmp19_ = g_strdup_printf ("<span color='dimgray'> %d </span>", _tmp18_);
	n_label = _tmp19_;
	_tmp20_ = split_h;
	if (_tmp20_ > 0) {
		gint _tmp21_;
		gint _tmp22_;
		gint _tmp23_;
		gint _tmp24_;
		gchar* _tmp25_ = NULL;
		_tmp21_ = split_h;
		_tmp22_ = split_m;
		_tmp23_ = split_s;
		_tmp24_ = split_cs;
		_tmp25_ = g_strdup_printf ("%i∶%02i∶%02i.%02i", _tmp21_, _tmp22_, _tmp23_, _tmp24_);
		_g_free0 (split_label);
		split_label = _tmp25_;
	} else {
		gint _tmp26_;
		gint _tmp27_;
		gint _tmp28_;
		gchar* _tmp29_ = NULL;
		_tmp26_ = split_m;
		_tmp27_ = split_s;
		_tmp28_ = split_cs;
		_tmp29_ = g_strdup_printf ("%02i∶%02i.%02i", _tmp26_, _tmp27_, _tmp28_);
		_g_free0 (split_label);
		split_label = _tmp29_;
	}
	_tmp30_ = h;
	if (_tmp30_ > 0) {
		gint _tmp31_;
		gint _tmp32_;
		gint _tmp33_;
		gint _tmp34_;
		gchar* _tmp35_ = NULL;
		_tmp31_ = h;
		_tmp32_ = m;
		_tmp33_ = s;
		_tmp34_ = cs;
		_tmp35_ = g_strdup_printf ("%i∶%02i∶%02i.%02i", _tmp31_, _tmp32_, _tmp33_, _tmp34_);
		_g_free0 (tot_label);
		tot_label = _tmp35_;
	} else {
		gint _tmp36_;
		gint _tmp37_;
		gint _tmp38_;
		gchar* _tmp39_ = NULL;
		_tmp36_ = m;
		_tmp37_ = s;
		_tmp38_ = cs;
		_tmp39_ = g_strdup_printf ("%02i∶%02i.%02i", _tmp36_, _tmp37_, _tmp38_);
		_g_free0 (tot_label);
		tot_label = _tmp39_;
	}
	_tmp40_ = self->priv->laps_model;
	gtk_list_store_append (_tmp40_, &_tmp41_);
	i = _tmp41_;
	_tmp42_ = self->priv->laps_model;
	_tmp43_ = i;
	_tmp44_ = n_label;
	_tmp45_ = split_label;
	_tmp46_ = tot_label;
	gtk_list_store_set (_tmp42_, &_tmp43_, CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_LAP, _tmp44_, CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_SPLIT, _tmp45_, CLOCKS_STOPWATCH_MAIN_PANEL_LAPS_COLUMN_TOTAL, _tmp46_, -1);
	_tmp47_ = self->priv->laps_model;
	_tmp48_ = i;
	_tmp49_ = gtk_tree_model_get_path ((GtkTreeModel*) _tmp47_, &_tmp48_);
	p = _tmp49_;
	_tmp50_ = self->priv->laps_view;
	gtk_tree_view_scroll_to_cell (_tmp50_, p, NULL, FALSE, (gfloat) 0, (gfloat) 0);
	_gtk_tree_path_free0 (p);
	_g_free0 (tot_label);
	_g_free0 (split_label);
	_g_free0 (n_label);
}


static gboolean _clocks_stopwatch_main_panel_update_time_label_gsource_func (gpointer self) {
	gboolean result;
	result = clocks_stopwatch_main_panel_update_time_label (self);
	return result;
}


static void clocks_stopwatch_main_panel_add_timeout (ClocksStopwatchMainPanel* self) {
	guint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timeout_id;
	if (_tmp0_ == ((guint) 0)) {
		guint _tmp1_ = 0U;
		_tmp1_ = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 100, _clocks_stopwatch_main_panel_update_time_label_gsource_func, g_object_ref (self), g_object_unref);
		self->priv->timeout_id = _tmp1_;
	}
}


static void clocks_stopwatch_main_panel_remove_timeout (ClocksStopwatchMainPanel* self) {
	guint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->timeout_id;
	if (_tmp0_ != ((guint) 0)) {
		guint _tmp1_;
		_tmp1_ = self->priv->timeout_id;
		g_source_remove (_tmp1_);
		self->priv->timeout_id = (guint) 0;
	}
}


static gboolean clocks_stopwatch_main_panel_update_time_label (ClocksStopwatchMainPanel* self) {
	gboolean result = FALSE;
	gint h;
	gint m;
	gint s;
	gdouble r;
	ClocksStopwatchMainPanelState _tmp0_;
	gdouble _tmp7_;
	gint ds;
	gint _tmp8_;
	g_return_val_if_fail (self != NULL, FALSE);
	h = 0;
	m = 0;
	s = 0;
	r = (gdouble) 0;
	_tmp0_ = self->priv->state;
	if (_tmp0_ != CLOCKS_STOPWATCH_MAIN_PANEL_STATE_RESET) {
		GTimer* _tmp1_;
		gdouble _tmp2_ = 0.0;
		gint _tmp3_ = 0;
		gint _tmp4_ = 0;
		gint _tmp5_ = 0;
		gdouble _tmp6_ = 0.0;
		_tmp1_ = self->priv->timer;
		_tmp2_ = g_timer_elapsed (_tmp1_, NULL);
		clocks_utils_time_to_hms (_tmp2_, &_tmp3_, &_tmp4_, &_tmp5_, &_tmp6_);
		h = _tmp3_;
		m = _tmp4_;
		s = _tmp5_;
		r = _tmp6_;
	}
	_tmp7_ = r;
	ds = (gint) (_tmp7_ * 10);
	_tmp8_ = h;
	if (_tmp8_ > 0) {
		GtkLabel* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gchar* _tmp14_ = NULL;
		gchar* _tmp15_;
		_tmp9_ = self->priv->time_label;
		_tmp10_ = h;
		_tmp11_ = m;
		_tmp12_ = s;
		_tmp13_ = ds;
		_tmp14_ = g_strdup_printf ("%i∶%02i∶%02i.%i", _tmp10_, _tmp11_, _tmp12_, _tmp13_);
		_tmp15_ = _tmp14_;
		gtk_label_set_text (_tmp9_, _tmp15_);
		_g_free0 (_tmp15_);
	} else {
		GtkLabel* _tmp16_;
		gint _tmp17_;
		gint _tmp18_;
		gint _tmp19_;
		gchar* _tmp20_ = NULL;
		gchar* _tmp21_;
		_tmp16_ = self->priv->time_label;
		_tmp17_ = m;
		_tmp18_ = s;
		_tmp19_ = ds;
		_tmp20_ = g_strdup_printf ("%02i∶%02i.%i", _tmp17_, _tmp18_, _tmp19_);
		_tmp21_ = _tmp20_;
		gtk_label_set_text (_tmp16_, _tmp21_);
		_g_free0 (_tmp21_);
	}
	result = TRUE;
	return result;
}


static void clocks_stopwatch_main_panel_real_grab_focus (GtkWidget* base) {
	ClocksStopwatchMainPanel * self;
	GtkButton* _tmp0_;
	self = (ClocksStopwatchMainPanel*) base;
	_tmp0_ = self->priv->left_button;
	gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
}


static const gchar* clocks_stopwatch_main_panel_real_get_label (ClocksClock* base) {
	const gchar* result;
	ClocksStopwatchMainPanel* self;
	const gchar* _tmp0_;
	self = (ClocksStopwatchMainPanel*) base;
	_tmp0_ = self->priv->_label;
	result = _tmp0_;
	return result;
}


static void clocks_stopwatch_main_panel_real_set_label (ClocksClock* base, const gchar* value) {
	ClocksStopwatchMainPanel* self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	self = (ClocksStopwatchMainPanel*) base;
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_label);
	self->priv->_label = _tmp1_;
	g_object_notify ((GObject *) self, "label");
}


static ClocksHeaderBar* clocks_stopwatch_main_panel_real_get_header_bar (ClocksClock* base) {
	ClocksHeaderBar* result;
	ClocksStopwatchMainPanel* self;
	ClocksHeaderBar* _tmp0_;
	self = (ClocksStopwatchMainPanel*) base;
	_tmp0_ = self->priv->_header_bar;
	result = _tmp0_;
	return result;
}


static void clocks_stopwatch_main_panel_real_set_header_bar (ClocksClock* base, ClocksHeaderBar* value) {
	ClocksStopwatchMainPanel* self;
	ClocksHeaderBar* _tmp0_;
	ClocksHeaderBar* _tmp1_;
	self = (ClocksStopwatchMainPanel*) base;
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_header_bar);
	self->priv->_header_bar = _tmp1_;
	g_object_notify ((GObject *) self, "header-bar");
}


static void clocks_stopwatch_main_panel_class_init (ClocksStopwatchMainPanelClass * klass) {
	clocks_stopwatch_main_panel_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ClocksStopwatchMainPanelPrivate));
	GTK_WIDGET_CLASS (klass)->grab_focus = clocks_stopwatch_main_panel_real_grab_focus;
	G_OBJECT_CLASS (klass)->get_property = _vala_clocks_stopwatch_main_panel_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_clocks_stopwatch_main_panel_set_property;
	G_OBJECT_CLASS (klass)->finalize = clocks_stopwatch_main_panel_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), CLOCKS_STOPWATCH_MAIN_PANEL_LABEL, g_param_spec_string ("label", "label", "label", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), CLOCKS_STOPWATCH_MAIN_PANEL_HEADER_BAR, g_param_spec_object ("header-bar", "header-bar", "header-bar", CLOCKS_TYPE_HEADER_BAR, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}


static void clocks_stopwatch_main_panel_clocks_clock_interface_init (ClocksClockIface * iface) {
	clocks_stopwatch_main_panel_clocks_clock_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_label = clocks_stopwatch_main_panel_real_get_label;
	iface->set_label = clocks_stopwatch_main_panel_real_set_label;
	iface->get_header_bar = clocks_stopwatch_main_panel_real_get_header_bar;
	iface->set_header_bar = clocks_stopwatch_main_panel_real_set_header_bar;
}


static void clocks_stopwatch_main_panel_instance_init (ClocksStopwatchMainPanel * self) {
	self->priv = CLOCKS_STOPWATCH_MAIN_PANEL_GET_PRIVATE (self);
}


static void clocks_stopwatch_main_panel_finalize (GObject* obj) {
	ClocksStopwatchMainPanel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanel);
	_g_free0 (self->priv->_label);
	_g_object_unref0 (self->priv->_header_bar);
	_g_timer_destroy0 (self->priv->timer);
	_g_object_unref0 (self->priv->time_label);
	_g_object_unref0 (self->priv->left_button);
	_g_object_unref0 (self->priv->right_button);
	_g_object_unref0 (self->priv->laps_model);
	_g_object_unref0 (self->priv->laps_view);
	G_OBJECT_CLASS (clocks_stopwatch_main_panel_parent_class)->finalize (obj);
}


GType clocks_stopwatch_main_panel_get_type (void) {
	static volatile gsize clocks_stopwatch_main_panel_type_id__volatile = 0;
	if (g_once_init_enter (&clocks_stopwatch_main_panel_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ClocksStopwatchMainPanelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) clocks_stopwatch_main_panel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ClocksStopwatchMainPanel), 0, (GInstanceInitFunc) clocks_stopwatch_main_panel_instance_init, NULL };
		static const GInterfaceInfo clocks_clock_info = { (GInterfaceInitFunc) clocks_stopwatch_main_panel_clocks_clock_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType clocks_stopwatch_main_panel_type_id;
		clocks_stopwatch_main_panel_type_id = g_type_register_static (GTK_TYPE_BOX, "ClocksStopwatchMainPanel", &g_define_type_info, 0);
		g_type_add_interface_static (clocks_stopwatch_main_panel_type_id, CLOCKS_TYPE_CLOCK, &clocks_clock_info);
		g_once_init_leave (&clocks_stopwatch_main_panel_type_id__volatile, clocks_stopwatch_main_panel_type_id);
	}
	return clocks_stopwatch_main_panel_type_id__volatile;
}


static void _vala_clocks_stopwatch_main_panel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	ClocksStopwatchMainPanel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanel);
	switch (property_id) {
		case CLOCKS_STOPWATCH_MAIN_PANEL_LABEL:
		g_value_set_string (value, clocks_clock_get_label ((ClocksClock*) self));
		break;
		case CLOCKS_STOPWATCH_MAIN_PANEL_HEADER_BAR:
		g_value_set_object (value, clocks_clock_get_header_bar ((ClocksClock*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_clocks_stopwatch_main_panel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	ClocksStopwatchMainPanel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, CLOCKS_STOPWATCH_TYPE_MAIN_PANEL, ClocksStopwatchMainPanel);
	switch (property_id) {
		case CLOCKS_STOPWATCH_MAIN_PANEL_LABEL:
		clocks_clock_set_label ((ClocksClock*) self, g_value_get_string (value));
		break;
		case CLOCKS_STOPWATCH_MAIN_PANEL_HEADER_BAR:
		clocks_clock_set_header_bar ((ClocksClock*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



