/* score-dialog.c generated by valac 0.34.2, 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 _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))
#define _g_free0(var) (var = (g_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;
	guint width;
	guint height;
	guint n_colors;
	guint score;
};

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_size (ScoreDialog* self, guint width, guint height, guint n_colors);
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_ = _ ("Size:");
	_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 (4, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, -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_ = _ ("Score");
	_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_size (ScoreDialog* self, guint width, guint height, guint n_colors) {
	GtkListStore* _tmp0_ = NULL;
	GList* entries = NULL;
	History* _tmp1_ = NULL;
	GList* _tmp2_ = NULL;
	GList* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	g_return_if_fail (self != 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;
			{
				gboolean _tmp5_ = FALSE;
				gboolean _tmp6_ = FALSE;
				HistoryEntry* _tmp7_ = NULL;
				guint _tmp8_ = 0U;
				guint _tmp9_ = 0U;
				gchar* date_label = NULL;
				HistoryEntry* _tmp16_ = NULL;
				GDateTime* _tmp17_ = NULL;
				gchar* _tmp18_ = NULL;
				gchar* score_label = NULL;
				HistoryEntry* _tmp19_ = NULL;
				guint _tmp20_ = 0U;
				gchar* _tmp21_ = NULL;
				gint weight = 0;
				HistoryEntry* _tmp22_ = NULL;
				HistoryEntry* _tmp23_ = NULL;
				GtkTreeIter iter = {0};
				GtkListStore* _tmp24_ = NULL;
				GtkTreeIter _tmp25_ = {0};
				GtkListStore* _tmp26_ = NULL;
				GtkTreeIter _tmp27_ = {0};
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_ = NULL;
				gint _tmp30_ = 0;
				HistoryEntry* _tmp31_ = NULL;
				HistoryEntry* _tmp32_ = NULL;
				_tmp7_ = entry;
				_tmp8_ = _tmp7_->width;
				_tmp9_ = width;
				if (_tmp8_ != _tmp9_) {
					_tmp6_ = TRUE;
				} else {
					HistoryEntry* _tmp10_ = NULL;
					guint _tmp11_ = 0U;
					guint _tmp12_ = 0U;
					_tmp10_ = entry;
					_tmp11_ = _tmp10_->height;
					_tmp12_ = height;
					_tmp6_ = _tmp11_ != _tmp12_;
				}
				if (_tmp6_) {
					_tmp5_ = TRUE;
				} else {
					HistoryEntry* _tmp13_ = NULL;
					guint _tmp14_ = 0U;
					guint _tmp15_ = 0U;
					_tmp13_ = entry;
					_tmp14_ = _tmp13_->n_colors;
					_tmp15_ = n_colors;
					_tmp5_ = _tmp14_ != _tmp15_;
				}
				if (_tmp5_) {
					continue;
				}
				_tmp16_ = entry;
				_tmp17_ = _tmp16_->date;
				_tmp18_ = g_date_time_format (_tmp17_, "%d/%m/%Y");
				date_label = _tmp18_;
				_tmp19_ = entry;
				_tmp20_ = _tmp19_->score;
				_tmp21_ = g_strdup_printf ("%u", _tmp20_);
				score_label = _tmp21_;
				weight = (gint) PANGO_WEIGHT_NORMAL;
				_tmp22_ = entry;
				_tmp23_ = self->priv->selected_entry;
				if (_tmp22_ == _tmp23_) {
					weight = (gint) PANGO_WEIGHT_BOLD;
				}
				_tmp24_ = self->priv->score_model;
				gtk_list_store_append (_tmp24_, &_tmp25_);
				iter = _tmp25_;
				_tmp26_ = self->priv->score_model;
				_tmp27_ = iter;
				_tmp28_ = date_label;
				_tmp29_ = score_label;
				_tmp30_ = weight;
				gtk_list_store_set (_tmp26_, &_tmp27_, 0, _tmp28_, 1, _tmp29_, 2, _tmp30_, -1);
				_tmp31_ = entry;
				_tmp32_ = self->priv->selected_entry;
				if (_tmp31_ == _tmp32_) {
					GtkTreeIter piter = {0};
					GtkTreeIter _tmp33_ = {0};
					GtkListStore* _tmp34_ = NULL;
					gboolean _tmp35_ = FALSE;
					GtkTreeView* _tmp41_ = NULL;
					GtkListStore* _tmp42_ = NULL;
					GtkTreeIter _tmp43_ = {0};
					GtkTreePath* _tmp44_ = NULL;
					GtkTreePath* _tmp45_ = NULL;
					_tmp33_ = iter;
					piter = _tmp33_;
					_tmp34_ = self->priv->score_model;
					_tmp35_ = gtk_tree_model_iter_previous ((GtkTreeModel*) _tmp34_, &piter);
					if (_tmp35_) {
						GtkTreeIter ppiter = {0};
						GtkTreeIter _tmp36_ = {0};
						GtkListStore* _tmp37_ = NULL;
						gboolean _tmp38_ = FALSE;
						_tmp36_ = piter;
						ppiter = _tmp36_;
						_tmp37_ = self->priv->score_model;
						_tmp38_ = gtk_tree_model_iter_previous ((GtkTreeModel*) _tmp37_, &ppiter);
						if (_tmp38_) {
							GtkTreeIter _tmp39_ = {0};
							_tmp39_ = ppiter;
							piter = _tmp39_;
						}
					} else {
						GtkTreeIter _tmp40_ = {0};
						_tmp40_ = iter;
						piter = _tmp40_;
					}
					_tmp41_ = self->priv->scores;
					_tmp42_ = self->priv->score_model;
					_tmp43_ = piter;
					_tmp44_ = gtk_tree_model_get_path ((GtkTreeModel*) _tmp42_, &_tmp43_);
					_tmp45_ = _tmp44_;
					gtk_tree_view_scroll_to_cell (_tmp41_, _tmp45_, NULL, FALSE, (gfloat) 0, (gfloat) 0);
					_gtk_tree_path_free0 (_tmp45_);
				}
				_g_free0 (score_label);
				_g_free0 (date_label);
			}
		}
	}
	_g_list_free0 (entries);
}


static gint score_dialog_compare_entries (HistoryEntry* a, HistoryEntry* b) {
	gint result = 0;
	HistoryEntry* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	HistoryEntry* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	HistoryEntry* _tmp8_ = NULL;
	guint _tmp9_ = 0U;
	HistoryEntry* _tmp10_ = NULL;
	guint _tmp11_ = 0U;
	HistoryEntry* _tmp16_ = NULL;
	guint _tmp17_ = 0U;
	HistoryEntry* _tmp18_ = NULL;
	guint _tmp19_ = 0U;
	HistoryEntry* _tmp24_ = NULL;
	guint _tmp25_ = 0U;
	HistoryEntry* _tmp26_ = NULL;
	guint _tmp27_ = 0U;
	HistoryEntry* _tmp32_ = NULL;
	GDateTime* _tmp33_ = NULL;
	HistoryEntry* _tmp34_ = NULL;
	GDateTime* _tmp35_ = NULL;
	gint _tmp36_ = 0;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = a;
	_tmp1_ = _tmp0_->width;
	_tmp2_ = b;
	_tmp3_ = _tmp2_->width;
	if (_tmp1_ != _tmp3_) {
		HistoryEntry* _tmp4_ = NULL;
		guint _tmp5_ = 0U;
		HistoryEntry* _tmp6_ = NULL;
		guint _tmp7_ = 0U;
		_tmp4_ = a;
		_tmp5_ = _tmp4_->width;
		_tmp6_ = b;
		_tmp7_ = _tmp6_->width;
		result = ((gint) _tmp5_) - ((gint) _tmp7_);
		return result;
	}
	_tmp8_ = a;
	_tmp9_ = _tmp8_->height;
	_tmp10_ = b;
	_tmp11_ = _tmp10_->height;
	if (_tmp9_ != _tmp11_) {
		HistoryEntry* _tmp12_ = NULL;
		guint _tmp13_ = 0U;
		HistoryEntry* _tmp14_ = NULL;
		guint _tmp15_ = 0U;
		_tmp12_ = a;
		_tmp13_ = _tmp12_->height;
		_tmp14_ = b;
		_tmp15_ = _tmp14_->height;
		result = ((gint) _tmp13_) - ((gint) _tmp15_);
		return result;
	}
	_tmp16_ = a;
	_tmp17_ = _tmp16_->n_colors;
	_tmp18_ = b;
	_tmp19_ = _tmp18_->n_colors;
	if (_tmp17_ != _tmp19_) {
		HistoryEntry* _tmp20_ = NULL;
		guint _tmp21_ = 0U;
		HistoryEntry* _tmp22_ = NULL;
		guint _tmp23_ = 0U;
		_tmp20_ = a;
		_tmp21_ = _tmp20_->n_colors;
		_tmp22_ = b;
		_tmp23_ = _tmp22_->n_colors;
		result = ((gint) _tmp21_) - ((gint) _tmp23_);
		return result;
	}
	_tmp24_ = a;
	_tmp25_ = _tmp24_->score;
	_tmp26_ = b;
	_tmp27_ = _tmp26_->score;
	if (_tmp25_ != _tmp27_) {
		HistoryEntry* _tmp28_ = NULL;
		guint _tmp29_ = 0U;
		HistoryEntry* _tmp30_ = NULL;
		guint _tmp31_ = 0U;
		_tmp28_ = a;
		_tmp29_ = _tmp28_->score;
		_tmp30_ = b;
		_tmp31_ = _tmp30_->score;
		result = ((gint) _tmp29_) - ((gint) _tmp31_);
		return result;
	}
	_tmp32_ = a;
	_tmp33_ = _tmp32_->date;
	_tmp34_ = b;
	_tmp35_ = _tmp34_->date;
	_tmp36_ = g_date_time_compare (_tmp33_, _tmp35_);
	result = _tmp36_;
	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;
	gint width = 0;
	gint height = 0;
	gint n_colors = 0;
	GtkComboBox* _tmp3_ = NULL;
	GtkTreeModel* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_ = NULL;
	GtkTreeIter _tmp6_ = {0};
	gint _tmp7_ = 0;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	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, &width, 2, &height, 3, &n_colors, -1);
	_tmp7_ = width;
	_tmp8_ = height;
	_tmp9_ = n_colors;
	score_dialog_set_size (self, (guint) _tmp7_, (guint) _tmp8_, (guint) _tmp9_);
}


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 _tmp19_ = 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) {
				gint width = 0;
				gint height = 0;
				gint n_colors = 0;
				GtkListStore* _tmp6_ = NULL;
				GtkTreeIter _tmp7_ = {0};
				gboolean _tmp8_ = FALSE;
				gboolean _tmp9_ = FALSE;
				gint _tmp10_ = 0;
				HistoryEntry* _tmp11_ = NULL;
				guint _tmp12_ = 0U;
				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, &width, 2, &height, 3, &n_colors, -1);
				_tmp10_ = width;
				_tmp11_ = entry;
				_tmp12_ = _tmp11_->width;
				if (((guint) _tmp10_) == _tmp12_) {
					gint _tmp13_ = 0;
					HistoryEntry* _tmp14_ = NULL;
					guint _tmp15_ = 0U;
					_tmp13_ = height;
					_tmp14_ = entry;
					_tmp15_ = _tmp14_->height;
					_tmp9_ = ((guint) _tmp13_) == _tmp15_;
				} else {
					_tmp9_ = FALSE;
				}
				if (_tmp9_) {
					gint _tmp16_ = 0;
					HistoryEntry* _tmp17_ = NULL;
					guint _tmp18_ = 0U;
					_tmp16_ = n_colors;
					_tmp17_ = entry;
					_tmp18_ = _tmp17_->n_colors;
					_tmp8_ = ((guint) _tmp16_) == _tmp18_;
				} else {
					_tmp8_ = FALSE;
				}
				if (_tmp8_) {
					have_size_entry = TRUE;
					break;
				}
			}
		}
	}
	_tmp19_ = have_size_entry;
	if (!_tmp19_) {
		gchar* label = NULL;
		HistoryEntry* _tmp20_ = NULL;
		guint _tmp21_ = 0U;
		const gchar* _tmp22_ = NULL;
		HistoryEntry* _tmp23_ = NULL;
		guint _tmp24_ = 0U;
		HistoryEntry* _tmp25_ = NULL;
		guint _tmp26_ = 0U;
		HistoryEntry* _tmp27_ = NULL;
		guint _tmp28_ = 0U;
		gchar* _tmp29_ = NULL;
		GtkListStore* _tmp30_ = NULL;
		GtkTreeIter _tmp31_ = {0};
		GtkListStore* _tmp32_ = NULL;
		GtkTreeIter _tmp33_ = {0};
		const gchar* _tmp34_ = NULL;
		HistoryEntry* _tmp35_ = NULL;
		guint _tmp36_ = 0U;
		HistoryEntry* _tmp37_ = NULL;
		guint _tmp38_ = 0U;
		HistoryEntry* _tmp39_ = NULL;
		guint _tmp40_ = 0U;
		GtkComboBox* _tmp41_ = NULL;
		gint _tmp42_ = 0;
		gboolean _tmp45_ = FALSE;
		gboolean _tmp46_ = FALSE;
		gboolean _tmp47_ = FALSE;
		HistoryEntry* _tmp48_ = NULL;
		_tmp20_ = entry;
		_tmp21_ = _tmp20_->n_colors;
		_tmp22_ = ngettext ("%u × %u, %u color", "%u × %u, %u colors", (gulong) _tmp21_);
		_tmp23_ = entry;
		_tmp24_ = _tmp23_->width;
		_tmp25_ = entry;
		_tmp26_ = _tmp25_->height;
		_tmp27_ = entry;
		_tmp28_ = _tmp27_->n_colors;
		_tmp29_ = g_strdup_printf (_tmp22_, _tmp24_, _tmp26_, _tmp28_);
		label = _tmp29_;
		_tmp30_ = self->priv->size_model;
		gtk_list_store_append (_tmp30_, &_tmp31_);
		iter = _tmp31_;
		_tmp32_ = self->priv->size_model;
		_tmp33_ = iter;
		_tmp34_ = label;
		_tmp35_ = entry;
		_tmp36_ = _tmp35_->width;
		_tmp37_ = entry;
		_tmp38_ = _tmp37_->height;
		_tmp39_ = entry;
		_tmp40_ = _tmp39_->n_colors;
		gtk_list_store_set (_tmp32_, &_tmp33_, 0, _tmp34_, 1, _tmp36_, 2, _tmp38_, 3, _tmp40_, -1);
		_tmp41_ = self->priv->size_combo;
		_tmp42_ = gtk_combo_box_get_active (_tmp41_);
		if (_tmp42_ == -1) {
			GtkComboBox* _tmp43_ = NULL;
			GtkTreeIter _tmp44_ = {0};
			_tmp43_ = self->priv->size_combo;
			_tmp44_ = iter;
			gtk_combo_box_set_active_iter (_tmp43_, &_tmp44_);
		}
		_tmp48_ = self->priv->selected_entry;
		if (_tmp48_ != NULL) {
			HistoryEntry* _tmp49_ = NULL;
			guint _tmp50_ = 0U;
			HistoryEntry* _tmp51_ = NULL;
			guint _tmp52_ = 0U;
			_tmp49_ = entry;
			_tmp50_ = _tmp49_->width;
			_tmp51_ = self->priv->selected_entry;
			_tmp52_ = _tmp51_->width;
			_tmp47_ = _tmp50_ == _tmp52_;
		} else {
			_tmp47_ = FALSE;
		}
		if (_tmp47_) {
			HistoryEntry* _tmp53_ = NULL;
			guint _tmp54_ = 0U;
			HistoryEntry* _tmp55_ = NULL;
			guint _tmp56_ = 0U;
			_tmp53_ = entry;
			_tmp54_ = _tmp53_->height;
			_tmp55_ = self->priv->selected_entry;
			_tmp56_ = _tmp55_->height;
			_tmp46_ = _tmp54_ == _tmp56_;
		} else {
			_tmp46_ = FALSE;
		}
		if (_tmp46_) {
			HistoryEntry* _tmp57_ = NULL;
			guint _tmp58_ = 0U;
			HistoryEntry* _tmp59_ = NULL;
			guint _tmp60_ = 0U;
			_tmp57_ = entry;
			_tmp58_ = _tmp57_->n_colors;
			_tmp59_ = self->priv->selected_entry;
			_tmp60_ = _tmp59_->n_colors;
			_tmp45_ = _tmp58_ == _tmp60_;
		} else {
			_tmp45_ = FALSE;
		}
		if (_tmp45_) {
			GtkComboBox* _tmp61_ = NULL;
			GtkTreeIter _tmp62_ = {0};
			_tmp61_ = self->priv->size_combo;
			_tmp62_ = iter;
			gtk_combo_box_set_active_iter (_tmp61_, &_tmp62_);
		}
		_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;
}



