/* score-dialog.c generated by valac 0.36.3, 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_;
	History* _tmp1_;
	History* _tmp2_;
	HistoryEntry* _tmp3_;
	HistoryEntry* _tmp4_;
	gboolean _tmp5_;
	GtkBox* vbox = NULL;
	GtkBox* _tmp6_;
	GtkBox* _tmp7_;
	GtkBox* _tmp8_;
	GtkBox* _tmp9_;
	GtkBox* _tmp10_;
	GtkBox* hbox = NULL;
	GtkBox* _tmp11_;
	GtkBox* _tmp12_;
	GtkBox* _tmp13_;
	GtkBox* _tmp14_;
	GtkLabel* label = NULL;
	GtkLabel* _tmp15_;
	GtkLabel* _tmp16_;
	GtkBox* _tmp17_;
	GtkLabel* _tmp18_;
	GtkListStore* _tmp19_;
	GtkComboBox* _tmp20_;
	GtkComboBox* _tmp21_;
	GtkComboBox* _tmp22_;
	GtkListStore* _tmp23_;
	GtkCellRendererText* renderer = NULL;
	GtkCellRendererText* _tmp24_;
	GtkComboBox* _tmp25_;
	GtkCellRendererText* _tmp26_;
	GtkComboBox* _tmp27_;
	GtkCellRendererText* _tmp28_;
	GtkComboBox* _tmp29_;
	GtkBox* _tmp30_;
	GtkComboBox* _tmp31_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp32_;
	GtkScrolledWindow* _tmp33_;
	GtkScrolledWindow* _tmp34_;
	GtkScrolledWindow* _tmp35_;
	GtkBox* _tmp36_;
	GtkScrolledWindow* _tmp37_;
	GtkListStore* _tmp38_;
	GtkTreeView* _tmp39_;
	GtkCellRendererText* _tmp40_;
	GtkTreeView* _tmp41_;
	GtkCellRendererText* _tmp42_;
	GtkCellRendererText* _tmp43_;
	GtkCellRendererText* _tmp44_;
	GtkTreeView* _tmp45_;
	GtkCellRendererText* _tmp46_;
	GtkTreeView* _tmp47_;
	GtkListStore* _tmp48_;
	GtkTreeView* _tmp49_;
	GtkScrolledWindow* _tmp50_;
	GtkTreeView* _tmp51_;
	History* _tmp52_;
	GList* _tmp53_;
	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_) {
		gtk_dialog_add_button ((GtkDialog*) self, _ ("_Quit"), (gint) GTK_RESPONSE_CLOSE);
		gtk_dialog_add_button ((GtkDialog*) self, _ ("New Game"), (gint) GTK_RESPONSE_OK);
	} else {
		gtk_dialog_add_button ((GtkDialog*) self, _ ("_OK"), (gint) GTK_RESPONSE_DELETE_EVENT);
	}
	gtk_widget_set_size_request ((GtkWidget*) self, 200, 300);
	_tmp6_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
	g_object_ref_sink (_tmp6_);
	vbox = _tmp6_;
	_tmp7_ = vbox;
	gtk_container_set_border_width ((GtkContainer*) _tmp7_, (guint) 6);
	_tmp8_ = vbox;
	gtk_widget_show ((GtkWidget*) _tmp8_);
	_tmp9_ = (GtkBox*) gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp10_ = vbox;
	gtk_box_pack_start (_tmp9_, (GtkWidget*) _tmp10_, TRUE, TRUE, (guint) 0);
	_tmp11_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp11_);
	hbox = _tmp11_;
	_tmp12_ = hbox;
	gtk_widget_show ((GtkWidget*) _tmp12_);
	_tmp13_ = vbox;
	_tmp14_ = hbox;
	gtk_box_pack_start (_tmp13_, (GtkWidget*) _tmp14_, FALSE, FALSE, (guint) 0);
	_tmp15_ = (GtkLabel*) gtk_label_new (_ ("Size:"));
	g_object_ref_sink (_tmp15_);
	label = _tmp15_;
	_tmp16_ = label;
	gtk_widget_show ((GtkWidget*) _tmp16_);
	_tmp17_ = hbox;
	_tmp18_ = label;
	gtk_box_pack_start (_tmp17_, (GtkWidget*) _tmp18_, FALSE, FALSE, (guint) 0);
	_tmp19_ = 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 = _tmp19_;
	_tmp20_ = (GtkComboBox*) gtk_combo_box_new ();
	g_object_ref_sink (_tmp20_);
	_g_object_unref0 (self->priv->size_combo);
	self->priv->size_combo = _tmp20_;
	_tmp21_ = self->priv->size_combo;
	g_signal_connect_object (_tmp21_, "changed", (GCallback) _score_dialog_size_changed_cb_gtk_combo_box_changed, self, 0);
	_tmp22_ = self->priv->size_combo;
	_tmp23_ = self->priv->size_model;
	gtk_combo_box_set_model (_tmp22_, (GtkTreeModel*) _tmp23_);
	_tmp24_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp24_);
	renderer = _tmp24_;
	_tmp25_ = self->priv->size_combo;
	_tmp26_ = renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp25_, (GtkCellRenderer*) _tmp26_, TRUE);
	_tmp27_ = self->priv->size_combo;
	_tmp28_ = renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp27_, (GtkCellRenderer*) _tmp28_, "text", 0);
	_tmp29_ = self->priv->size_combo;
	gtk_widget_show ((GtkWidget*) _tmp29_);
	_tmp30_ = hbox;
	_tmp31_ = self->priv->size_combo;
	gtk_box_pack_start (_tmp30_, (GtkWidget*) _tmp31_, TRUE, TRUE, (guint) 0);
	_tmp32_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp32_);
	scroll = _tmp32_;
	_tmp33_ = scroll;
	gtk_scrolled_window_set_shadow_type (_tmp33_, GTK_SHADOW_ETCHED_IN);
	_tmp34_ = scroll;
	gtk_scrolled_window_set_policy (_tmp34_, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	_tmp35_ = scroll;
	gtk_widget_show ((GtkWidget*) _tmp35_);
	_tmp36_ = vbox;
	_tmp37_ = scroll;
	gtk_box_pack_start (_tmp36_, (GtkWidget*) _tmp37_, TRUE, TRUE, (guint) 0);
	_tmp38_ = 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 = _tmp38_;
	_tmp39_ = (GtkTreeView*) gtk_tree_view_new ();
	g_object_ref_sink (_tmp39_);
	_g_object_unref0 (self->priv->scores);
	self->priv->scores = _tmp39_;
	_tmp40_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp40_);
	_g_object_unref0 (renderer);
	renderer = _tmp40_;
	_tmp41_ = self->priv->scores;
	_tmp42_ = renderer;
	gtk_tree_view_insert_column_with_attributes (_tmp41_, -1, _ ("Date"), (GtkCellRenderer*) _tmp42_, "text", 0, "weight", 2, NULL);
	_tmp43_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp43_);
	_g_object_unref0 (renderer);
	renderer = _tmp43_;
	_tmp44_ = renderer;
	g_object_set ((GtkCellRenderer*) _tmp44_, "xalign", 1.0f, NULL);
	_tmp45_ = self->priv->scores;
	_tmp46_ = renderer;
	gtk_tree_view_insert_column_with_attributes (_tmp45_, -1, _ ("Score"), (GtkCellRenderer*) _tmp46_, "text", 1, "weight", 2, NULL);
	_tmp47_ = self->priv->scores;
	_tmp48_ = self->priv->score_model;
	gtk_tree_view_set_model (_tmp47_, (GtkTreeModel*) _tmp48_);
	_tmp49_ = self->priv->scores;
	gtk_widget_show ((GtkWidget*) _tmp49_);
	_tmp50_ = scroll;
	_tmp51_ = self->priv->scores;
	gtk_container_add ((GtkContainer*) _tmp50_, (GtkWidget*) _tmp51_);
	_tmp52_ = history;
	_tmp53_ = _tmp52_->entries;
	{
		GList* entry_collection = NULL;
		GList* entry_it = NULL;
		entry_collection = _tmp53_;
		for (entry_it = entry_collection; entry_it != NULL; entry_it = entry_it->next) {
			HistoryEntry* _tmp54_;
			HistoryEntry* entry = NULL;
			_tmp54_ = _g_object_ref0 ((HistoryEntry*) entry_it->data);
			entry = _tmp54_;
			{
				HistoryEntry* _tmp55_;
				_tmp55_ = entry;
				score_dialog_entry_added_cb (self, _tmp55_);
				_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_;
	GList* entries = NULL;
	History* _tmp1_;
	GList* _tmp2_;
	GList* _tmp3_;
	GList* _tmp4_;
	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_;
				guint _tmp8_;
				guint _tmp9_;
				gchar* date_label = NULL;
				HistoryEntry* _tmp16_;
				GDateTime* _tmp17_;
				gchar* _tmp18_;
				gchar* score_label = NULL;
				HistoryEntry* _tmp19_;
				guint _tmp20_;
				gchar* _tmp21_;
				gint weight = 0;
				HistoryEntry* _tmp22_;
				HistoryEntry* _tmp23_;
				GtkTreeIter iter = {0};
				GtkListStore* _tmp24_;
				GtkTreeIter _tmp25_ = {0};
				GtkListStore* _tmp26_;
				GtkTreeIter _tmp27_;
				const gchar* _tmp28_;
				const gchar* _tmp29_;
				gint _tmp30_;
				HistoryEntry* _tmp31_;
				HistoryEntry* _tmp32_;
				_tmp7_ = entry;
				_tmp8_ = _tmp7_->width;
				_tmp9_ = width;
				if (_tmp8_ != _tmp9_) {
					_tmp6_ = TRUE;
				} else {
					HistoryEntry* _tmp10_;
					guint _tmp11_;
					guint _tmp12_;
					_tmp10_ = entry;
					_tmp11_ = _tmp10_->height;
					_tmp12_ = height;
					_tmp6_ = _tmp11_ != _tmp12_;
				}
				if (_tmp6_) {
					_tmp5_ = TRUE;
				} else {
					HistoryEntry* _tmp13_;
					guint _tmp14_;
					guint _tmp15_;
					_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_;
					GtkListStore* _tmp34_;
					gboolean _tmp35_;
					GtkTreeView* _tmp41_;
					GtkListStore* _tmp42_;
					GtkTreeIter _tmp43_;
					GtkTreePath* _tmp44_;
					GtkTreePath* _tmp45_;
					_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_;
						GtkListStore* _tmp37_;
						gboolean _tmp38_;
						_tmp36_ = piter;
						ppiter = _tmp36_;
						_tmp37_ = self->priv->score_model;
						_tmp38_ = gtk_tree_model_iter_previous ((GtkTreeModel*) _tmp37_, &ppiter);
						if (_tmp38_) {
							GtkTreeIter _tmp39_;
							_tmp39_ = ppiter;
							piter = _tmp39_;
						}
					} else {
						GtkTreeIter _tmp40_;
						_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_;
	guint _tmp1_;
	HistoryEntry* _tmp2_;
	guint _tmp3_;
	HistoryEntry* _tmp8_;
	guint _tmp9_;
	HistoryEntry* _tmp10_;
	guint _tmp11_;
	HistoryEntry* _tmp16_;
	guint _tmp17_;
	HistoryEntry* _tmp18_;
	guint _tmp19_;
	HistoryEntry* _tmp24_;
	guint _tmp25_;
	HistoryEntry* _tmp26_;
	guint _tmp27_;
	HistoryEntry* _tmp32_;
	GDateTime* _tmp33_;
	HistoryEntry* _tmp34_;
	GDateTime* _tmp35_;
	gint _tmp36_;
	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_;
		guint _tmp5_;
		HistoryEntry* _tmp6_;
		guint _tmp7_;
		_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_;
		guint _tmp13_;
		HistoryEntry* _tmp14_;
		guint _tmp15_;
		_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_;
		guint _tmp21_;
		HistoryEntry* _tmp22_;
		guint _tmp23_;
		_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_;
		guint _tmp29_;
		HistoryEntry* _tmp30_;
		guint _tmp31_;
		_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_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	gint width = 0;
	gint height = 0;
	gint n_colors = 0;
	GtkComboBox* _tmp3_;
	GtkTreeModel* _tmp4_;
	GtkTreeModel* _tmp5_;
	GtkTreeIter _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	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_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	gboolean _tmp19_;
	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_;
				GtkTreeIter _tmp7_;
				gboolean _tmp8_ = FALSE;
				gboolean _tmp9_ = FALSE;
				gint _tmp10_;
				HistoryEntry* _tmp11_;
				guint _tmp12_;
				if (!_tmp3_) {
					GtkListStore* _tmp4_;
					gboolean _tmp5_;
					_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_;
					HistoryEntry* _tmp14_;
					guint _tmp15_;
					_tmp13_ = height;
					_tmp14_ = entry;
					_tmp15_ = _tmp14_->height;
					_tmp9_ = ((guint) _tmp13_) == _tmp15_;
				} else {
					_tmp9_ = FALSE;
				}
				if (_tmp9_) {
					gint _tmp16_;
					HistoryEntry* _tmp17_;
					guint _tmp18_;
					_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_;
		guint _tmp21_;
		HistoryEntry* _tmp22_;
		guint _tmp23_;
		HistoryEntry* _tmp24_;
		guint _tmp25_;
		HistoryEntry* _tmp26_;
		guint _tmp27_;
		gchar* _tmp28_;
		GtkListStore* _tmp29_;
		GtkTreeIter _tmp30_ = {0};
		GtkListStore* _tmp31_;
		GtkTreeIter _tmp32_;
		const gchar* _tmp33_;
		HistoryEntry* _tmp34_;
		guint _tmp35_;
		HistoryEntry* _tmp36_;
		guint _tmp37_;
		HistoryEntry* _tmp38_;
		guint _tmp39_;
		GtkComboBox* _tmp40_;
		gint _tmp41_;
		gboolean _tmp44_ = FALSE;
		gboolean _tmp45_ = FALSE;
		gboolean _tmp46_ = FALSE;
		HistoryEntry* _tmp47_;
		_tmp20_ = entry;
		_tmp21_ = _tmp20_->n_colors;
		_tmp22_ = entry;
		_tmp23_ = _tmp22_->width;
		_tmp24_ = entry;
		_tmp25_ = _tmp24_->height;
		_tmp26_ = entry;
		_tmp27_ = _tmp26_->n_colors;
		_tmp28_ = g_strdup_printf (ngettext ("%u × %u, %u color", "%u × %u, %u colors", (gulong) _tmp21_), _tmp23_, _tmp25_, _tmp27_);
		label = _tmp28_;
		_tmp29_ = self->priv->size_model;
		gtk_list_store_append (_tmp29_, &_tmp30_);
		iter = _tmp30_;
		_tmp31_ = self->priv->size_model;
		_tmp32_ = iter;
		_tmp33_ = label;
		_tmp34_ = entry;
		_tmp35_ = _tmp34_->width;
		_tmp36_ = entry;
		_tmp37_ = _tmp36_->height;
		_tmp38_ = entry;
		_tmp39_ = _tmp38_->n_colors;
		gtk_list_store_set (_tmp31_, &_tmp32_, 0, _tmp33_, 1, _tmp35_, 2, _tmp37_, 3, _tmp39_, -1);
		_tmp40_ = self->priv->size_combo;
		_tmp41_ = gtk_combo_box_get_active (_tmp40_);
		if (_tmp41_ == -1) {
			GtkComboBox* _tmp42_;
			GtkTreeIter _tmp43_;
			_tmp42_ = self->priv->size_combo;
			_tmp43_ = iter;
			gtk_combo_box_set_active_iter (_tmp42_, &_tmp43_);
		}
		_tmp47_ = self->priv->selected_entry;
		if (_tmp47_ != NULL) {
			HistoryEntry* _tmp48_;
			guint _tmp49_;
			HistoryEntry* _tmp50_;
			guint _tmp51_;
			_tmp48_ = entry;
			_tmp49_ = _tmp48_->width;
			_tmp50_ = self->priv->selected_entry;
			_tmp51_ = _tmp50_->width;
			_tmp46_ = _tmp49_ == _tmp51_;
		} else {
			_tmp46_ = FALSE;
		}
		if (_tmp46_) {
			HistoryEntry* _tmp52_;
			guint _tmp53_;
			HistoryEntry* _tmp54_;
			guint _tmp55_;
			_tmp52_ = entry;
			_tmp53_ = _tmp52_->height;
			_tmp54_ = self->priv->selected_entry;
			_tmp55_ = _tmp54_->height;
			_tmp45_ = _tmp53_ == _tmp55_;
		} else {
			_tmp45_ = FALSE;
		}
		if (_tmp45_) {
			HistoryEntry* _tmp56_;
			guint _tmp57_;
			HistoryEntry* _tmp58_;
			guint _tmp59_;
			_tmp56_ = entry;
			_tmp57_ = _tmp56_->n_colors;
			_tmp58_ = self->priv->selected_entry;
			_tmp59_ = _tmp58_->n_colors;
			_tmp44_ = _tmp57_ == _tmp59_;
		} else {
			_tmp44_ = FALSE;
		}
		if (_tmp44_) {
			GtkComboBox* _tmp60_;
			GtkTreeIter _tmp61_;
			_tmp60_ = self->priv->size_combo;
			_tmp61_ = iter;
			gtk_combo_box_set_active_iter (_tmp60_, &_tmp61_);
		}
		_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;
}



