/* score-dialog.c generated by valac 0.26.0.19-b2255, the Vala compiler
 * generated from score-dialog.vala, do not modify */

/*
 * Copyright (C) 2010-2013 Robert Ancell
 *
 * 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. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pango.h>
#include <float.h>
#include <math.h>


#define TYPE_SCORE_DIALOG (score_dialog_get_type ())
#define SCORE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SCORE_DIALOG, ScoreDialog))
#define SCORE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SCORE_DIALOG, ScoreDialogClass))
#define IS_SCORE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SCORE_DIALOG))
#define IS_SCORE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SCORE_DIALOG))
#define SCORE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SCORE_DIALOG, ScoreDialogClass))

typedef struct _ScoreDialog ScoreDialog;
typedef struct _ScoreDialogClass ScoreDialogClass;
typedef struct _ScoreDialogPrivate ScoreDialogPrivate;

#define TYPE_HISTORY (history_get_type ())
#define HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HISTORY, History))
#define HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HISTORY, HistoryClass))
#define IS_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HISTORY))
#define IS_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HISTORY))
#define HISTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HISTORY, HistoryClass))

typedef struct _History History;
typedef struct _HistoryClass HistoryClass;

#define TYPE_HISTORY_ENTRY (history_entry_get_type ())
#define HISTORY_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HISTORY_ENTRY, HistoryEntry))
#define HISTORY_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HISTORY_ENTRY, HistoryEntryClass))
#define IS_HISTORY_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HISTORY_ENTRY))
#define IS_HISTORY_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HISTORY_ENTRY))
#define HISTORY_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HISTORY_ENTRY, HistoryEntryClass))

typedef struct _HistoryEntry HistoryEntry;
typedef struct _HistoryEntryClass HistoryEntryClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _HistoryPrivate HistoryPrivate;
typedef struct _HistoryEntryPrivate HistoryEntryPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_free (var), NULL)))

struct _ScoreDialog {
	GtkDialog parent_instance;
	ScoreDialogPrivate * priv;
};

struct _ScoreDialogClass {
	GtkDialogClass parent_class;
};

struct _ScoreDialogPrivate {
	History* history;
	HistoryEntry* selected_entry;
	GtkListStore* size_model;
	GtkListStore* score_model;
	GtkComboBox* size_combo;
	GtkTreeView* scores;
};

struct _History {
	GObject parent_instance;
	HistoryPrivate * priv;
	gchar* filename;
	GList* entries;
};

struct _HistoryClass {
	GObjectClass parent_class;
};

struct _HistoryEntry {
	GObject parent_instance;
	HistoryEntryPrivate * priv;
	GDateTime* date;
	gchar* name;
	guint duration;
};

struct _HistoryEntryClass {
	GObjectClass parent_class;
};


static gpointer score_dialog_parent_class = NULL;

GType score_dialog_get_type (void) G_GNUC_CONST;
GType history_get_type (void) G_GNUC_CONST;
GType history_entry_get_type (void) G_GNUC_CONST;
#define SCORE_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_SCORE_DIALOG, ScoreDialogPrivate))
enum  {
	SCORE_DIALOG_DUMMY_PROPERTY
};
ScoreDialog* score_dialog_new (History* history, HistoryEntry* selected_entry, gboolean show_quit);
ScoreDialog* score_dialog_construct (GType object_type, History* history, HistoryEntry* selected_entry, gboolean show_quit);
static void score_dialog_entry_added_cb (ScoreDialog* self, HistoryEntry* entry);
static void _score_dialog_entry_added_cb_history_entry_added (History* _sender, HistoryEntry* entry, gpointer self);
static void score_dialog_size_changed_cb (ScoreDialog* self, GtkComboBox* combo);
static void _score_dialog_size_changed_cb_gtk_combo_box_changed (GtkComboBox* _sender, gpointer self);
void score_dialog_set_map (ScoreDialog* self, const gchar* name);
static gint score_dialog_compare_entries (HistoryEntry* a, HistoryEntry* b);
static gint _score_dialog_compare_entries_gcompare_func (gconstpointer a, gconstpointer b);
static void score_dialog_finalize (GObject* obj);


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


static void _score_dialog_entry_added_cb_history_entry_added (History* _sender, HistoryEntry* entry, gpointer self) {
	score_dialog_entry_added_cb ((ScoreDialog*) self, entry);
}


static void _score_dialog_size_changed_cb_gtk_combo_box_changed (GtkComboBox* _sender, gpointer self) {
	score_dialog_size_changed_cb ((ScoreDialog*) self, _sender);
}


ScoreDialog* score_dialog_construct (GType object_type, History* history, HistoryEntry* selected_entry, gboolean show_quit) {
	ScoreDialog * self = NULL;
	History* _tmp0_ = NULL;
	History* _tmp1_ = NULL;
	History* _tmp2_ = NULL;
	HistoryEntry* _tmp3_ = NULL;
	HistoryEntry* _tmp4_ = NULL;
	gboolean _tmp5_ = FALSE;
	GtkBox* vbox = NULL;
	GtkBox* _tmp9_ = NULL;
	GtkBox* _tmp10_ = NULL;
	GtkBox* _tmp11_ = NULL;
	GtkBox* _tmp12_ = NULL;
	GtkBox* _tmp13_ = NULL;
	GtkBox* hbox = NULL;
	GtkBox* _tmp14_ = NULL;
	GtkBox* _tmp15_ = NULL;
	GtkBox* _tmp16_ = NULL;
	GtkBox* _tmp17_ = NULL;
	GtkLabel* label = NULL;
	const gchar* _tmp18_ = NULL;
	GtkLabel* _tmp19_ = NULL;
	GtkLabel* _tmp20_ = NULL;
	GtkBox* _tmp21_ = NULL;
	GtkLabel* _tmp22_ = NULL;
	GtkListStore* _tmp23_ = NULL;
	GtkComboBox* _tmp24_ = NULL;
	GtkComboBox* _tmp25_ = NULL;
	GtkComboBox* _tmp26_ = NULL;
	GtkListStore* _tmp27_ = NULL;
	GtkCellRendererText* renderer = NULL;
	GtkCellRendererText* _tmp28_ = NULL;
	GtkComboBox* _tmp29_ = NULL;
	GtkCellRendererText* _tmp30_ = NULL;
	GtkComboBox* _tmp31_ = NULL;
	GtkCellRendererText* _tmp32_ = NULL;
	GtkComboBox* _tmp33_ = NULL;
	GtkBox* _tmp34_ = NULL;
	GtkComboBox* _tmp35_ = NULL;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp36_ = NULL;
	GtkScrolledWindow* _tmp37_ = NULL;
	GtkScrolledWindow* _tmp38_ = NULL;
	GtkScrolledWindow* _tmp39_ = NULL;
	GtkBox* _tmp40_ = NULL;
	GtkScrolledWindow* _tmp41_ = NULL;
	GtkListStore* _tmp42_ = NULL;
	GtkTreeView* _tmp43_ = NULL;
	GtkCellRendererText* _tmp44_ = NULL;
	GtkTreeView* _tmp45_ = NULL;
	const gchar* _tmp46_ = NULL;
	GtkCellRendererText* _tmp47_ = NULL;
	GtkCellRendererText* _tmp48_ = NULL;
	GtkCellRendererText* _tmp49_ = NULL;
	GtkTreeView* _tmp50_ = NULL;
	const gchar* _tmp51_ = NULL;
	GtkCellRendererText* _tmp52_ = NULL;
	GtkTreeView* _tmp53_ = NULL;
	GtkListStore* _tmp54_ = NULL;
	GtkTreeView* _tmp55_ = NULL;
	GtkScrolledWindow* _tmp56_ = NULL;
	GtkTreeView* _tmp57_ = NULL;
	History* _tmp58_ = NULL;
	GList* _tmp59_ = NULL;
	g_return_val_if_fail (history != NULL, NULL);
	self = (ScoreDialog*) g_object_new (object_type, NULL);
	_tmp0_ = history;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->history);
	self->priv->history = _tmp1_;
	_tmp2_ = history;
	g_signal_connect_object (_tmp2_, "entry-added", (GCallback) _score_dialog_entry_added_cb_history_entry_added, self, 0);
	_tmp3_ = selected_entry;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (self->priv->selected_entry);
	self->priv->selected_entry = _tmp4_;
	_tmp5_ = show_quit;
	if (_tmp5_) {
		const gchar* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		_tmp6_ = _ ("_Quit");
		gtk_dialog_add_button ((GtkDialog*) self, _tmp6_, (gint) GTK_RESPONSE_CLOSE);
		_tmp7_ = _ ("New Game");
		gtk_dialog_add_button ((GtkDialog*) self, _tmp7_, (gint) GTK_RESPONSE_OK);
	} else {
		const gchar* _tmp8_ = NULL;
		_tmp8_ = _ ("OK");
		gtk_dialog_add_button ((GtkDialog*) self, _tmp8_, (gint) GTK_RESPONSE_DELETE_EVENT);
	}
	gtk_widget_set_size_request ((GtkWidget*) self, 200, 300);
	_tmp9_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
	g_object_ref_sink (_tmp9_);
	vbox = _tmp9_;
	_tmp10_ = vbox;
	gtk_container_set_border_width ((GtkContainer*) _tmp10_, (guint) 6);
	_tmp11_ = vbox;
	gtk_widget_show ((GtkWidget*) _tmp11_);
	_tmp12_ = (GtkBox*) gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp13_ = vbox;
	gtk_box_pack_start (_tmp12_, (GtkWidget*) _tmp13_, TRUE, TRUE, (guint) 0);
	_tmp14_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp14_);
	hbox = _tmp14_;
	_tmp15_ = hbox;
	gtk_widget_show ((GtkWidget*) _tmp15_);
	_tmp16_ = vbox;
	_tmp17_ = hbox;
	gtk_box_pack_start (_tmp16_, (GtkWidget*) _tmp17_, FALSE, FALSE, (guint) 0);
	_tmp18_ = _ ("Layout:");
	_tmp19_ = (GtkLabel*) gtk_label_new (_tmp18_);
	g_object_ref_sink (_tmp19_);
	label = _tmp19_;
	_tmp20_ = label;
	gtk_widget_show ((GtkWidget*) _tmp20_);
	_tmp21_ = hbox;
	_tmp22_ = label;
	gtk_box_pack_start (_tmp21_, (GtkWidget*) _tmp22_, FALSE, FALSE, (guint) 0);
	_tmp23_ = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING, -1);
	_g_object_unref0 (self->priv->size_model);
	self->priv->size_model = _tmp23_;
	_tmp24_ = (GtkComboBox*) gtk_combo_box_new ();
	g_object_ref_sink (_tmp24_);
	_g_object_unref0 (self->priv->size_combo);
	self->priv->size_combo = _tmp24_;
	_tmp25_ = self->priv->size_combo;
	g_signal_connect_object (_tmp25_, "changed", (GCallback) _score_dialog_size_changed_cb_gtk_combo_box_changed, self, 0);
	_tmp26_ = self->priv->size_combo;
	_tmp27_ = self->priv->size_model;
	gtk_combo_box_set_model (_tmp26_, (GtkTreeModel*) _tmp27_);
	_tmp28_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp28_);
	renderer = _tmp28_;
	_tmp29_ = self->priv->size_combo;
	_tmp30_ = renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp29_, (GtkCellRenderer*) _tmp30_, TRUE);
	_tmp31_ = self->priv->size_combo;
	_tmp32_ = renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp31_, (GtkCellRenderer*) _tmp32_, "text", 0);
	_tmp33_ = self->priv->size_combo;
	gtk_widget_show ((GtkWidget*) _tmp33_);
	_tmp34_ = hbox;
	_tmp35_ = self->priv->size_combo;
	gtk_box_pack_start (_tmp34_, (GtkWidget*) _tmp35_, TRUE, TRUE, (guint) 0);
	_tmp36_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp36_);
	scroll = _tmp36_;
	_tmp37_ = scroll;
	gtk_scrolled_window_set_shadow_type (_tmp37_, GTK_SHADOW_ETCHED_IN);
	_tmp38_ = scroll;
	gtk_scrolled_window_set_policy (_tmp38_, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	_tmp39_ = scroll;
	gtk_widget_show ((GtkWidget*) _tmp39_);
	_tmp40_ = vbox;
	_tmp41_ = scroll;
	gtk_box_pack_start (_tmp40_, (GtkWidget*) _tmp41_, TRUE, TRUE, (guint) 0);
	_tmp42_ = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, -1);
	_g_object_unref0 (self->priv->score_model);
	self->priv->score_model = _tmp42_;
	_tmp43_ = (GtkTreeView*) gtk_tree_view_new ();
	g_object_ref_sink (_tmp43_);
	_g_object_unref0 (self->priv->scores);
	self->priv->scores = _tmp43_;
	_tmp44_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp44_);
	_g_object_unref0 (renderer);
	renderer = _tmp44_;
	_tmp45_ = self->priv->scores;
	_tmp46_ = _ ("Date");
	_tmp47_ = renderer;
	gtk_tree_view_insert_column_with_attributes (_tmp45_, -1, _tmp46_, (GtkCellRenderer*) _tmp47_, "text", 0, "weight", 2, NULL);
	_tmp48_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp48_);
	_g_object_unref0 (renderer);
	renderer = _tmp48_;
	_tmp49_ = renderer;
	g_object_set ((GtkCellRenderer*) _tmp49_, "xalign", 1.0f, NULL);
	_tmp50_ = self->priv->scores;
	_tmp51_ = _ ("Time");
	_tmp52_ = renderer;
	gtk_tree_view_insert_column_with_attributes (_tmp50_, -1, _tmp51_, (GtkCellRenderer*) _tmp52_, "text", 1, "weight", 2, NULL);
	_tmp53_ = self->priv->scores;
	_tmp54_ = self->priv->score_model;
	gtk_tree_view_set_model (_tmp53_, (GtkTreeModel*) _tmp54_);
	_tmp55_ = self->priv->scores;
	gtk_widget_show ((GtkWidget*) _tmp55_);
	_tmp56_ = scroll;
	_tmp57_ = self->priv->scores;
	gtk_container_add ((GtkContainer*) _tmp56_, (GtkWidget*) _tmp57_);
	_tmp58_ = history;
	_tmp59_ = _tmp58_->entries;
	{
		GList* entry_collection = NULL;
		GList* entry_it = NULL;
		entry_collection = _tmp59_;
		for (entry_it = entry_collection; entry_it != NULL; entry_it = entry_it->next) {
			HistoryEntry* _tmp60_ = NULL;
			HistoryEntry* entry = NULL;
			_tmp60_ = _g_object_ref0 ((HistoryEntry*) entry_it->data);
			entry = _tmp60_;
			{
				HistoryEntry* _tmp61_ = NULL;
				_tmp61_ = entry;
				score_dialog_entry_added_cb (self, _tmp61_);
				_g_object_unref0 (entry);
			}
		}
	}
	_g_object_unref0 (scroll);
	_g_object_unref0 (renderer);
	_g_object_unref0 (label);
	_g_object_unref0 (hbox);
	_g_object_unref0 (vbox);
	return self;
}


ScoreDialog* score_dialog_new (History* history, HistoryEntry* selected_entry, gboolean show_quit) {
	return score_dialog_construct (TYPE_SCORE_DIALOG, history, selected_entry, show_quit);
}


static gint _score_dialog_compare_entries_gcompare_func (gconstpointer a, gconstpointer b) {
	gint result;
	result = score_dialog_compare_entries ((HistoryEntry*) a, (HistoryEntry*) b);
	return result;
}


void score_dialog_set_map (ScoreDialog* self, const gchar* name) {
	GtkListStore* _tmp0_ = NULL;
	GList* entries = NULL;
	History* _tmp1_ = NULL;
	GList* _tmp2_ = NULL;
	GList* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = self->priv->score_model;
	gtk_list_store_clear (_tmp0_);
	_tmp1_ = self->priv->history;
	_tmp2_ = _tmp1_->entries;
	_tmp3_ = g_list_copy (_tmp2_);
	entries = _tmp3_;
	entries = g_list_sort (entries, _score_dialog_compare_entries_gcompare_func);
	_tmp4_ = entries;
	{
		GList* entry_collection = NULL;
		GList* entry_it = NULL;
		entry_collection = _tmp4_;
		for (entry_it = entry_collection; entry_it != NULL; entry_it = entry_it->next) {
			HistoryEntry* entry = NULL;
			entry = (HistoryEntry*) entry_it->data;
			{
				HistoryEntry* _tmp5_ = NULL;
				const gchar* _tmp6_ = NULL;
				const gchar* _tmp7_ = NULL;
				gchar* date_label = NULL;
				HistoryEntry* _tmp8_ = NULL;
				GDateTime* _tmp9_ = NULL;
				gchar* _tmp10_ = NULL;
				gchar* time_label = NULL;
				HistoryEntry* _tmp11_ = NULL;
				guint _tmp12_ = 0U;
				gchar* _tmp13_ = NULL;
				HistoryEntry* _tmp14_ = NULL;
				guint _tmp15_ = 0U;
				gint weight = 0;
				HistoryEntry* _tmp21_ = NULL;
				HistoryEntry* _tmp22_ = NULL;
				GtkTreeIter iter = {0};
				GtkListStore* _tmp23_ = NULL;
				GtkTreeIter _tmp24_ = {0};
				GtkListStore* _tmp25_ = NULL;
				GtkTreeIter _tmp26_ = {0};
				const gchar* _tmp27_ = NULL;
				const gchar* _tmp28_ = NULL;
				gint _tmp29_ = 0;
				HistoryEntry* _tmp30_ = NULL;
				HistoryEntry* _tmp31_ = NULL;
				_tmp5_ = entry;
				_tmp6_ = _tmp5_->name;
				_tmp7_ = name;
				if (g_strcmp0 (_tmp6_, _tmp7_) != 0) {
					continue;
				}
				_tmp8_ = entry;
				_tmp9_ = _tmp8_->date;
				_tmp10_ = g_date_time_format (_tmp9_, "%d/%m/%Y");
				date_label = _tmp10_;
				_tmp11_ = entry;
				_tmp12_ = _tmp11_->duration;
				_tmp13_ = g_strdup_printf ("%us", _tmp12_);
				time_label = _tmp13_;
				_tmp14_ = entry;
				_tmp15_ = _tmp14_->duration;
				if (_tmp15_ >= ((guint) 60)) {
					HistoryEntry* _tmp16_ = NULL;
					guint _tmp17_ = 0U;
					HistoryEntry* _tmp18_ = NULL;
					guint _tmp19_ = 0U;
					gchar* _tmp20_ = NULL;
					_tmp16_ = entry;
					_tmp17_ = _tmp16_->duration;
					_tmp18_ = entry;
					_tmp19_ = _tmp18_->duration;
					_tmp20_ = g_strdup_printf ("%um %us", _tmp17_ / 60, _tmp19_ % 60);
					_g_free0 (time_label);
					time_label = _tmp20_;
				}
				weight = (gint) PANGO_WEIGHT_NORMAL;
				_tmp21_ = entry;
				_tmp22_ = self->priv->selected_entry;
				if (_tmp21_ == _tmp22_) {
					weight = (gint) PANGO_WEIGHT_BOLD;
				}
				_tmp23_ = self->priv->score_model;
				gtk_list_store_append (_tmp23_, &_tmp24_);
				iter = _tmp24_;
				_tmp25_ = self->priv->score_model;
				_tmp26_ = iter;
				_tmp27_ = date_label;
				_tmp28_ = time_label;
				_tmp29_ = weight;
				gtk_list_store_set (_tmp25_, &_tmp26_, 0, _tmp27_, 1, _tmp28_, 2, _tmp29_, -1);
				_tmp30_ = entry;
				_tmp31_ = self->priv->selected_entry;
				if (_tmp30_ == _tmp31_) {
					GtkTreeIter piter = {0};
					GtkTreeIter _tmp32_ = {0};
					GtkListStore* _tmp33_ = NULL;
					gboolean _tmp34_ = FALSE;
					GtkTreeView* _tmp40_ = NULL;
					GtkListStore* _tmp41_ = NULL;
					GtkTreeIter _tmp42_ = {0};
					GtkTreePath* _tmp43_ = NULL;
					GtkTreePath* _tmp44_ = NULL;
					_tmp32_ = iter;
					piter = _tmp32_;
					_tmp33_ = self->priv->score_model;
					_tmp34_ = gtk_tree_model_iter_previous ((GtkTreeModel*) _tmp33_, &piter);
					if (_tmp34_) {
						GtkTreeIter ppiter = {0};
						GtkTreeIter _tmp35_ = {0};
						GtkListStore* _tmp36_ = NULL;
						gboolean _tmp37_ = FALSE;
						_tmp35_ = piter;
						ppiter = _tmp35_;
						_tmp36_ = self->priv->score_model;
						_tmp37_ = gtk_tree_model_iter_previous ((GtkTreeModel*) _tmp36_, &ppiter);
						if (_tmp37_) {
							GtkTreeIter _tmp38_ = {0};
							_tmp38_ = ppiter;
							piter = _tmp38_;
						}
					} else {
						GtkTreeIter _tmp39_ = {0};
						_tmp39_ = iter;
						piter = _tmp39_;
					}
					_tmp40_ = self->priv->scores;
					_tmp41_ = self->priv->score_model;
					_tmp42_ = piter;
					_tmp43_ = gtk_tree_model_get_path ((GtkTreeModel*) _tmp41_, &_tmp42_);
					_tmp44_ = _tmp43_;
					gtk_tree_view_scroll_to_cell (_tmp40_, _tmp44_, NULL, FALSE, (gfloat) 0, (gfloat) 0);
					_gtk_tree_path_free0 (_tmp44_);
				}
				_g_free0 (time_label);
				_g_free0 (date_label);
			}
		}
	}
	_g_list_free0 (entries);
}


static gint score_dialog_compare_entries (HistoryEntry* a, HistoryEntry* b) {
	gint result = 0;
	gint d = 0;
	GCompareFunc _tmp0_ = NULL;
	HistoryEntry* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	HistoryEntry* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gint _tmp5_ = 0;
	gint _tmp6_ = 0;
	HistoryEntry* _tmp7_ = NULL;
	guint _tmp8_ = 0U;
	HistoryEntry* _tmp9_ = NULL;
	guint _tmp10_ = 0U;
	HistoryEntry* _tmp15_ = NULL;
	GDateTime* _tmp16_ = NULL;
	HistoryEntry* _tmp17_ = NULL;
	GDateTime* _tmp18_ = NULL;
	gint _tmp19_ = 0;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = g_strcmp0;
	_tmp1_ = a;
	_tmp2_ = _tmp1_->name;
	_tmp3_ = b;
	_tmp4_ = _tmp3_->name;
	_tmp5_ = _tmp0_ (_tmp2_, _tmp4_);
	d = _tmp5_;
	_tmp6_ = d;
	if (_tmp6_ != 0) {
		result = d;
		return result;
	}
	_tmp7_ = a;
	_tmp8_ = _tmp7_->duration;
	_tmp9_ = b;
	_tmp10_ = _tmp9_->duration;
	if (_tmp8_ != _tmp10_) {
		HistoryEntry* _tmp11_ = NULL;
		guint _tmp12_ = 0U;
		HistoryEntry* _tmp13_ = NULL;
		guint _tmp14_ = 0U;
		_tmp11_ = a;
		_tmp12_ = _tmp11_->duration;
		_tmp13_ = b;
		_tmp14_ = _tmp13_->duration;
		result = ((gint) _tmp12_) - ((gint) _tmp14_);
		return result;
	}
	_tmp15_ = a;
	_tmp16_ = _tmp15_->date;
	_tmp17_ = b;
	_tmp18_ = _tmp17_->date;
	_tmp19_ = g_date_time_compare (_tmp16_, _tmp18_);
	result = _tmp19_;
	return result;
}


static void score_dialog_size_changed_cb (ScoreDialog* self, GtkComboBox* combo) {
	GtkTreeIter iter = {0};
	GtkComboBox* _tmp0_ = NULL;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_ = FALSE;
	gchar* name = NULL;
	GtkComboBox* _tmp3_ = NULL;
	GtkTreeModel* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_ = NULL;
	GtkTreeIter _tmp6_ = {0};
	const gchar* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (combo != NULL);
	_tmp0_ = combo;
	_tmp2_ = gtk_combo_box_get_active_iter (_tmp0_, &_tmp1_);
	iter = _tmp1_;
	if (!_tmp2_) {
		return;
	}
	_tmp3_ = combo;
	_tmp4_ = gtk_combo_box_get_model (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = iter;
	gtk_tree_model_get (_tmp5_, &_tmp6_, 1, &name, -1);
	_tmp7_ = name;
	score_dialog_set_map (self, _tmp7_);
	_g_free0 (name);
}


static void score_dialog_entry_added_cb (ScoreDialog* self, HistoryEntry* entry) {
	GtkTreeIter iter = {0};
	gboolean have_size_entry = FALSE;
	GtkListStore* _tmp0_ = NULL;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_ = FALSE;
	gboolean _tmp11_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	have_size_entry = FALSE;
	_tmp0_ = self->priv->size_model;
	_tmp2_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp0_, &_tmp1_);
	iter = _tmp1_;
	if (_tmp2_) {
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				gchar* name = NULL;
				GtkListStore* _tmp6_ = NULL;
				GtkTreeIter _tmp7_ = {0};
				const gchar* _tmp8_ = NULL;
				HistoryEntry* _tmp9_ = NULL;
				const gchar* _tmp10_ = NULL;
				if (!_tmp3_) {
					GtkListStore* _tmp4_ = NULL;
					gboolean _tmp5_ = FALSE;
					_tmp4_ = self->priv->size_model;
					_tmp5_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp4_, &iter);
					if (!_tmp5_) {
						break;
					}
				}
				_tmp3_ = FALSE;
				_tmp6_ = self->priv->size_model;
				_tmp7_ = iter;
				gtk_tree_model_get ((GtkTreeModel*) _tmp6_, &_tmp7_, 1, &name, -1);
				_tmp8_ = name;
				_tmp9_ = entry;
				_tmp10_ = _tmp9_->name;
				if (g_strcmp0 (_tmp8_, _tmp10_) == 0) {
					have_size_entry = TRUE;
					_g_free0 (name);
					break;
				}
				_g_free0 (name);
			}
		}
	}
	_tmp11_ = have_size_entry;
	if (!_tmp11_) {
		gchar* label = NULL;
		HistoryEntry* _tmp12_ = NULL;
		const gchar* _tmp13_ = NULL;
		gchar* _tmp14_ = NULL;
		GtkListStore* _tmp15_ = NULL;
		GtkTreeIter _tmp16_ = {0};
		GtkListStore* _tmp17_ = NULL;
		GtkTreeIter _tmp18_ = {0};
		const gchar* _tmp19_ = NULL;
		HistoryEntry* _tmp20_ = NULL;
		const gchar* _tmp21_ = NULL;
		GtkComboBox* _tmp22_ = NULL;
		gint _tmp23_ = 0;
		gboolean _tmp26_ = FALSE;
		HistoryEntry* _tmp27_ = NULL;
		_tmp12_ = entry;
		_tmp13_ = _tmp12_->name;
		_tmp14_ = g_strdup_printf ("%s", _tmp13_);
		label = _tmp14_;
		_tmp15_ = self->priv->size_model;
		gtk_list_store_append (_tmp15_, &_tmp16_);
		iter = _tmp16_;
		_tmp17_ = self->priv->size_model;
		_tmp18_ = iter;
		_tmp19_ = label;
		_tmp20_ = entry;
		_tmp21_ = _tmp20_->name;
		gtk_list_store_set (_tmp17_, &_tmp18_, 0, _tmp19_, 1, _tmp21_, -1);
		_tmp22_ = self->priv->size_combo;
		_tmp23_ = gtk_combo_box_get_active (_tmp22_);
		if (_tmp23_ == (-1)) {
			GtkComboBox* _tmp24_ = NULL;
			GtkTreeIter _tmp25_ = {0};
			_tmp24_ = self->priv->size_combo;
			_tmp25_ = iter;
			gtk_combo_box_set_active_iter (_tmp24_, &_tmp25_);
		}
		_tmp27_ = self->priv->selected_entry;
		if (_tmp27_ != NULL) {
			HistoryEntry* _tmp28_ = NULL;
			const gchar* _tmp29_ = NULL;
			HistoryEntry* _tmp30_ = NULL;
			const gchar* _tmp31_ = NULL;
			_tmp28_ = entry;
			_tmp29_ = _tmp28_->name;
			_tmp30_ = self->priv->selected_entry;
			_tmp31_ = _tmp30_->name;
			_tmp26_ = g_strcmp0 (_tmp29_, _tmp31_) == 0;
		} else {
			_tmp26_ = FALSE;
		}
		if (_tmp26_) {
			GtkComboBox* _tmp32_ = NULL;
			GtkTreeIter _tmp33_ = {0};
			_tmp32_ = self->priv->size_combo;
			_tmp33_ = iter;
			gtk_combo_box_set_active_iter (_tmp32_, &_tmp33_);
		}
		_g_free0 (label);
	}
}


static void score_dialog_class_init (ScoreDialogClass * klass) {
	score_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ScoreDialogPrivate));
	G_OBJECT_CLASS (klass)->finalize = score_dialog_finalize;
}


static void score_dialog_instance_init (ScoreDialog * self) {
	self->priv = SCORE_DIALOG_GET_PRIVATE (self);
	self->priv->selected_entry = NULL;
}


static void score_dialog_finalize (GObject* obj) {
	ScoreDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SCORE_DIALOG, ScoreDialog);
	_g_object_unref0 (self->priv->history);
	_g_object_unref0 (self->priv->selected_entry);
	_g_object_unref0 (self->priv->size_model);
	_g_object_unref0 (self->priv->score_model);
	_g_object_unref0 (self->priv->size_combo);
	_g_object_unref0 (self->priv->scores);
	G_OBJECT_CLASS (score_dialog_parent_class)->finalize (obj);
}


GType score_dialog_get_type (void) {
	static volatile gsize score_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&score_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ScoreDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) score_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScoreDialog), 0, (GInstanceInitFunc) score_dialog_instance_init, NULL };
		GType score_dialog_type_id;
		score_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "ScoreDialog", &g_define_type_info, 0);
		g_once_init_leave (&score_dialog_type_id__volatile, score_dialog_type_id);
	}
	return score_dialog_type_id__volatile;
}



