Blob Blame History Raw
/* math-variable-popover.c generated by valac 0.40.6, the Vala compiler
 * generated from math-variable-popover.vala, do not modify */

/*
 * Copyright (C) 2008-2012 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 3 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 "libcalculator.h"
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>


#define TYPE_MATH_VARIABLE_POPOVER (math_variable_popover_get_type ())
#define MATH_VARIABLE_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopover))
#define MATH_VARIABLE_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopoverClass))
#define IS_MATH_VARIABLE_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_VARIABLE_POPOVER))
#define IS_MATH_VARIABLE_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_VARIABLE_POPOVER))
#define MATH_VARIABLE_POPOVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopoverClass))

typedef struct _MathVariablePopover MathVariablePopover;
typedef struct _MathVariablePopoverClass MathVariablePopoverClass;
typedef struct _MathVariablePopoverPrivate MathVariablePopoverPrivate;
enum  {
	MATH_VARIABLE_POPOVER_0_PROPERTY,
	MATH_VARIABLE_POPOVER_NUM_PROPERTIES
};
static GParamSpec* math_variable_popover_properties[MATH_VARIABLE_POPOVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;

struct _MathVariablePopover {
	GtkPopover parent_instance;
	MathVariablePopoverPrivate * priv;
};

struct _MathVariablePopoverClass {
	GtkPopoverClass parent_class;
};

struct _MathVariablePopoverPrivate {
	MathEquation* equation;
	GtkListBox* variable_list;
	GtkEntry* variable_name_entry;
	GtkButton* store_variable_button;
};

struct _Block2Data {
	int _ref_count_;
	MathVariablePopover* self;
	GtkListBoxRow* row;
	gchar* name;
};


static gpointer math_variable_popover_parent_class = NULL;
static gchar** math_variable_popover_RESERVED_VARIABLE_NAMES;
static gint math_variable_popover_RESERVED_VARIABLE_NAMES_length1;
static gchar** math_variable_popover_RESERVED_VARIABLE_NAMES = NULL;
static gint math_variable_popover_RESERVED_VARIABLE_NAMES_length1 = 0;
static gint _math_variable_popover_RESERVED_VARIABLE_NAMES_size_ = 0;

GType math_variable_popover_get_type (void) G_GNUC_CONST;
#define MATH_VARIABLE_POPOVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopoverPrivate))
MathVariablePopover* math_variable_popover_new (MathEquation* equation);
MathVariablePopover* math_variable_popover_construct (GType object_type,
                                                      MathEquation* equation);
static void math_variable_popover_handler (MathVariablePopover* self,
                                    const gchar* answer,
                                    Number* number,
                                    gint number_base,
                                    guint representation_base);
static void _math_variable_popover_handler_math_equation_history_signal (MathEquation* _sender,
                                                                  const gchar* answer,
                                                                  Number* number,
                                                                  gint number_base,
                                                                  guint representation_base,
                                                                  gpointer self);
static GtkListBoxRow* math_variable_popover_make_variable_row (MathVariablePopover* self,
                                                        const gchar* name,
                                                        Number* value);
static gint math_variable_popover_variable_list_sort (MathVariablePopover* self,
                                               GtkListBoxRow* row1,
                                               GtkListBoxRow* row2);
static gint _math_variable_popover_variable_list_sort_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                       GtkListBoxRow* row2,
                                                                       gpointer self);
static void __lambda14_ (MathVariablePopover* self,
                  const gchar* name,
                  Number* value);
static void ___lambda14__math_variables_variable_added (MathVariables* _sender,
                                                 const gchar* name,
                                                 Number* value,
                                                 gpointer self);
static void __lambda15_ (MathVariablePopover* self,
                  const gchar* name,
                  Number* value);
static GtkListBoxRow* math_variable_popover_find_row_for_variable (MathVariablePopover* self,
                                                            const gchar* name);
static void ___lambda15__math_variables_variable_edited (MathVariables* _sender,
                                                  const gchar* name,
                                                  Number* new_value,
                                                  gpointer self);
static void __lambda16_ (MathVariablePopover* self,
                  const gchar* name);
static void ___lambda16__math_variables_variable_deleted (MathVariables* _sender,
                                                   const gchar* name,
                                                   gpointer self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda13_ (Block2Data* _data2_,
                  GtkWidget* child);
static void ___lambda13__gtk_callback (GtkWidget* widget,
                                gpointer self);
static void math_variable_popover_insert_variable_cb (MathVariablePopover* self,
                                               GtkListBoxRow* row);
static void _math_variable_popover_insert_variable_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                           GtkListBoxRow* row,
                                                                           gpointer self);
static gboolean math_variable_popover_variable_name_key_press_cb (MathVariablePopover* self,
                                                           GtkWidget* widget,
                                                           GdkEventKey* event);
static gboolean _math_variable_popover_variable_name_key_press_cb_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                                       GdkEventKey* event,
                                                                                       gpointer self);
static void math_variable_popover_variable_name_changed_cb (MathVariablePopover* self);
static void _math_variable_popover_variable_name_changed_cb_gtk_editable_changed (GtkEditable* _sender,
                                                                           gpointer self);
static void math_variable_popover_store_variable_cb (MathVariablePopover* self,
                                              GtkWidget* widget);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      int stack_length,
                                      gchar* needle);
static void _math_variable_popover_store_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static void math_variable_popover_delete_variable_cb (MathVariablePopover* self,
                                               GtkWidget* widget);
static void _math_variable_popover_delete_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self);
static void math_variable_popover_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array,
                          gint array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gint array_length,
                       GDestroyNotify destroy_func);


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


static void
_math_variable_popover_handler_math_equation_history_signal (MathEquation* _sender,
                                                             const gchar* answer,
                                                             Number* number,
                                                             gint number_base,
                                                             guint representation_base,
                                                             gpointer self)
{
	math_variable_popover_handler ((MathVariablePopover*) self, answer, number, number_base, representation_base);
}


static gint
_math_variable_popover_variable_list_sort_gtk_list_box_sort_func (GtkListBoxRow* row1,
                                                                  GtkListBoxRow* row2,
                                                                  gpointer self)
{
	gint result;
	result = math_variable_popover_variable_list_sort ((MathVariablePopover*) self, row1, row2);
	return result;
}


static void
__lambda14_ (MathVariablePopover* self,
             const gchar* name,
             Number* value)
{
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = self->priv->variable_list;
	_tmp1_ = math_variable_popover_make_variable_row (self, name, value);
	_tmp2_ = _tmp1_;
	gtk_container_add ((GtkContainer*) _tmp0_, (GtkWidget*) _tmp2_);
	_g_object_unref0 (_tmp2_);
}


static void
___lambda14__math_variables_variable_added (MathVariables* _sender,
                                            const gchar* name,
                                            Number* value,
                                            gpointer self)
{
	__lambda14_ ((MathVariablePopover*) self, name, value);
}


static void
__lambda15_ (MathVariablePopover* self,
             const gchar* name,
             Number* value)
{
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	GtkListBox* _tmp3_;
	GtkListBoxRow* _tmp4_;
	GtkListBoxRow* _tmp5_;
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = self->priv->variable_list;
	_tmp1_ = math_variable_popover_find_row_for_variable (self, name);
	_tmp2_ = _tmp1_;
	gtk_container_remove ((GtkContainer*) _tmp0_, (GtkWidget*) _tmp2_);
	_g_object_unref0 (_tmp2_);
	_tmp3_ = self->priv->variable_list;
	_tmp4_ = math_variable_popover_make_variable_row (self, name, value);
	_tmp5_ = _tmp4_;
	gtk_container_add ((GtkContainer*) _tmp3_, (GtkWidget*) _tmp5_);
	_g_object_unref0 (_tmp5_);
}


static void
___lambda15__math_variables_variable_edited (MathVariables* _sender,
                                             const gchar* name,
                                             Number* new_value,
                                             gpointer self)
{
	__lambda15_ ((MathVariablePopover*) self, name, new_value);
}


static void
__lambda16_ (MathVariablePopover* self,
             const gchar* name)
{
	GtkListBox* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBoxRow* _tmp2_;
	g_return_if_fail (name != NULL);
	_tmp0_ = self->priv->variable_list;
	_tmp1_ = math_variable_popover_find_row_for_variable (self, name);
	_tmp2_ = _tmp1_;
	gtk_container_remove ((GtkContainer*) _tmp0_, (GtkWidget*) _tmp2_);
	_g_object_unref0 (_tmp2_);
}


static void
___lambda16__math_variables_variable_deleted (MathVariables* _sender,
                                              const gchar* name,
                                              gpointer self)
{
	__lambda16_ ((MathVariablePopover*) self, name);
}


MathVariablePopover*
math_variable_popover_construct (GType object_type,
                                 MathEquation* equation)
{
	MathVariablePopover * self = NULL;
	MathEquation* _tmp0_;
	gchar** names = NULL;
	MathVariables* _tmp1_;
	MathVariables* _tmp2_;
	gint _tmp3_;
	gchar** _tmp4_;
	gint names_length1;
	gint _names_size_;
	GtkListBox* _tmp23_;
	GtkListBoxRow* _tmp24_;
	GtkListBoxRow* _tmp25_;
	GtkListBox* _tmp26_;
	MathVariables* _tmp27_;
	MathVariables* _tmp28_;
	MathVariables* _tmp29_;
	MathVariables* _tmp30_;
	MathVariables* _tmp31_;
	MathVariables* _tmp32_;
	g_return_val_if_fail (equation != NULL, NULL);
	self = (MathVariablePopover*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (equation);
	_g_object_unref0 (self->priv->equation);
	self->priv->equation = _tmp0_;
	g_signal_connect_object (equation, "history-signal", (GCallback) _math_variable_popover_handler_math_equation_history_signal, self, 0);
	_tmp1_ = math_equation_get_variables (equation);
	_tmp2_ = _tmp1_;
	_tmp4_ = math_variables_get_names (_tmp2_, &_tmp3_);
	names = _tmp4_;
	names_length1 = _tmp3_;
	_names_size_ = names_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				gchar** _tmp7_;
				gint _tmp7__length1;
				gint _tmp8_;
				const gchar* _tmp9_;
				Number* value = NULL;
				MathVariables* _tmp10_;
				MathVariables* _tmp11_;
				gchar** _tmp12_;
				gint _tmp12__length1;
				gint _tmp13_;
				const gchar* _tmp14_;
				Number* _tmp15_;
				GtkListBox* _tmp16_;
				gchar** _tmp17_;
				gint _tmp17__length1;
				gint _tmp18_;
				const gchar* _tmp19_;
				Number* _tmp20_;
				GtkListBoxRow* _tmp21_;
				GtkListBoxRow* _tmp22_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = names;
				_tmp7__length1 = names_length1;
				_tmp8_ = i;
				_tmp9_ = _tmp7_[_tmp8_];
				if (!(_tmp9_ != NULL)) {
					break;
				}
				_tmp10_ = math_equation_get_variables (equation);
				_tmp11_ = _tmp10_;
				_tmp12_ = names;
				_tmp12__length1 = names_length1;
				_tmp13_ = i;
				_tmp14_ = _tmp12_[_tmp13_];
				_tmp15_ = math_variables_get (_tmp11_, _tmp14_);
				value = _tmp15_;
				_tmp16_ = self->priv->variable_list;
				_tmp17_ = names;
				_tmp17__length1 = names_length1;
				_tmp18_ = i;
				_tmp19_ = _tmp17_[_tmp18_];
				_tmp20_ = value;
				_tmp21_ = math_variable_popover_make_variable_row (self, _tmp19_, _tmp20_);
				_tmp22_ = _tmp21_;
				gtk_container_add ((GtkContainer*) _tmp16_, (GtkWidget*) _tmp22_);
				_g_object_unref0 (_tmp22_);
				_g_object_unref0 (value);
			}
		}
	}
	_tmp23_ = self->priv->variable_list;
	_tmp24_ = math_variable_popover_make_variable_row (self, "rand", NULL);
	_tmp25_ = _tmp24_;
	gtk_container_add ((GtkContainer*) _tmp23_, (GtkWidget*) _tmp25_);
	_g_object_unref0 (_tmp25_);
	_tmp26_ = self->priv->variable_list;
	gtk_list_box_set_sort_func (_tmp26_, _math_variable_popover_variable_list_sort_gtk_list_box_sort_func, g_object_ref (self), g_object_unref);
	_tmp27_ = math_equation_get_variables (equation);
	_tmp28_ = _tmp27_;
	g_signal_connect_object (_tmp28_, "variable-added", (GCallback) ___lambda14__math_variables_variable_added, self, 0);
	_tmp29_ = math_equation_get_variables (equation);
	_tmp30_ = _tmp29_;
	g_signal_connect_object (_tmp30_, "variable-edited", (GCallback) ___lambda15__math_variables_variable_edited, self, 0);
	_tmp31_ = math_equation_get_variables (equation);
	_tmp32_ = _tmp31_;
	g_signal_connect_object (_tmp32_, "variable-deleted", (GCallback) ___lambda16__math_variables_variable_deleted, self, 0);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
	return self;
}


MathVariablePopover*
math_variable_popover_new (MathEquation* equation)
{
	return math_variable_popover_construct (TYPE_MATH_VARIABLE_POPOVER, equation);
}


static void
math_variable_popover_handler (MathVariablePopover* self,
                               const gchar* answer,
                               Number* number,
                               gint number_base,
                               guint representation_base)
{
	GtkListBoxRow* row = NULL;
	GtkListBoxRow* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkListBox* _tmp4_;
	GtkListBoxRow* _tmp5_;
	GtkListBoxRow* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (answer != NULL);
	g_return_if_fail (number != NULL);
	_tmp0_ = math_variable_popover_find_row_for_variable (self, "_");
	row = _tmp0_;
	_tmp1_ = row;
	if (_tmp1_ != NULL) {
		GtkListBox* _tmp2_;
		GtkListBoxRow* _tmp3_;
		_tmp2_ = self->priv->variable_list;
		_tmp3_ = row;
		gtk_container_remove ((GtkContainer*) _tmp2_, (GtkWidget*) _tmp3_);
	}
	_tmp4_ = self->priv->variable_list;
	_tmp5_ = math_variable_popover_make_variable_row (self, "_", number);
	_tmp6_ = _tmp5_;
	gtk_container_add ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp6_);
	_g_object_unref0 (_tmp6_);
	_g_object_unref0 (row);
}


static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		MathVariablePopover* self;
		self = _data2_->self;
		_g_free0 (_data2_->name);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static void
__lambda13_ (Block2Data* _data2_,
             GtkWidget* child)
{
	MathVariablePopover* self;
	gconstpointer _tmp0_;
	self = _data2_->self;
	g_return_if_fail (child != NULL);
	_tmp0_ = g_object_get_data ((GObject*) child, "variable_name");
	if (g_strcmp0 (_data2_->name, (const gchar*) _tmp0_) == 0) {
		_data2_->row = G_TYPE_CHECK_INSTANCE_TYPE (child, gtk_list_box_row_get_type ()) ? ((GtkListBoxRow*) child) : NULL;
	}
}


static void
___lambda13__gtk_callback (GtkWidget* widget,
                           gpointer self)
{
	__lambda13_ (self, widget);
}


static GtkListBoxRow*
math_variable_popover_find_row_for_variable (MathVariablePopover* self,
                                             const gchar* name)
{
	GtkListBoxRow* result = NULL;
	Block2Data* _data2_;
	gchar* _tmp0_;
	GtkListBox* _tmp1_;
	GtkListBoxRow* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = g_strdup (name);
	_g_free0 (_data2_->name);
	_data2_->name = _tmp0_;
	_data2_->row = NULL;
	_tmp1_ = self->priv->variable_list;
	gtk_container_foreach ((GtkContainer*) _tmp1_, ___lambda13__gtk_callback, _data2_);
	_tmp2_ = _g_object_ref0 (_data2_->row);
	result = _tmp2_;
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return result;
}


static void
math_variable_popover_insert_variable_cb (MathVariablePopover* self,
                                          GtkListBoxRow* row)
{
	gchar* name = NULL;
	gconstpointer _tmp0_;
	gchar* _tmp1_;
	MathEquation* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = g_object_get_data ((GObject*) row, "variable_name");
	_tmp1_ = g_strdup ((const gchar*) _tmp0_);
	name = _tmp1_;
	_tmp2_ = self->priv->equation;
	math_equation_insert (_tmp2_, name);
	_g_free0 (name);
}


static void
_math_variable_popover_insert_variable_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                      GtkListBoxRow* row,
                                                                      gpointer self)
{
	math_variable_popover_insert_variable_cb ((MathVariablePopover*) self, row);
}


static gboolean
math_variable_popover_variable_name_key_press_cb (MathVariablePopover* self,
                                                  GtkWidget* widget,
                                                  GdkEventKey* event)
{
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	guint _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp1_ = event->keyval;
	if (_tmp1_ == ((guint) GDK_KEY_space)) {
		_tmp0_ = TRUE;
	} else {
		guint _tmp2_;
		_tmp2_ = event->keyval;
		_tmp0_ = _tmp2_ == ((guint) GDK_KEY_KP_Space);
	}
	if (_tmp0_) {
		event->keyval = (guint) GDK_KEY_underscore;
	}
	result = FALSE;
	return result;
}


static gboolean
_math_variable_popover_variable_name_key_press_cb_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                              GdkEventKey* event,
                                                                              gpointer self)
{
	gboolean result;
	result = math_variable_popover_variable_name_key_press_cb ((MathVariablePopover*) self, _sender, event);
	return result;
}


static void
math_variable_popover_variable_name_changed_cb (MathVariablePopover* self)
{
	GtkButton* _tmp0_;
	GtkEntry* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->store_variable_button;
	_tmp1_ = self->priv->variable_name_entry;
	_tmp2_ = gtk_entry_get_text (_tmp1_);
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, g_strcmp0 (_tmp2_, "") != 0);
}


static void
_math_variable_popover_variable_name_changed_cb_gtk_editable_changed (GtkEditable* _sender,
                                                                      gpointer self)
{
	math_variable_popover_variable_name_changed_cb ((MathVariablePopover*) self);
}


static gboolean
_vala_string_array_contains (gchar* * stack,
                             int stack_length,
                             gchar* needle)
{
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


static void
math_variable_popover_store_variable_cb (MathVariablePopover* self,
                                         GtkWidget* widget)
{
	gchar* name = NULL;
	GtkEntry* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gboolean _tmp3_ = FALSE;
	const gchar* _tmp4_;
	Number* z = NULL;
	MathEquation* _tmp7_;
	Number* _tmp8_;
	Number* _tmp9_;
	Number* _tmp10_;
	GtkEntry* _tmp27_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = self->priv->variable_name_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	name = _tmp2_;
	_tmp4_ = name;
	if (g_strcmp0 (_tmp4_, "") == 0) {
		_tmp3_ = TRUE;
	} else {
		const gchar* _tmp5_;
		gchar** _tmp6_;
		gint _tmp6__length1;
		_tmp5_ = name;
		_tmp6_ = math_variable_popover_RESERVED_VARIABLE_NAMES;
		_tmp6__length1 = math_variable_popover_RESERVED_VARIABLE_NAMES_length1;
		_tmp3_ = _vala_string_array_contains (_tmp6_, _tmp6__length1, _tmp5_);
	}
	if (_tmp3_) {
		_g_free0 (name);
		return;
	}
	_tmp7_ = self->priv->equation;
	_tmp8_ = math_equation_get_number (_tmp7_);
	_tmp9_ = _tmp8_;
	z = _tmp9_;
	_tmp10_ = z;
	if (_tmp10_ != NULL) {
		MathEquation* _tmp11_;
		MathVariables* _tmp12_;
		MathVariables* _tmp13_;
		const gchar* _tmp14_;
		Number* _tmp15_;
		_tmp11_ = self->priv->equation;
		_tmp12_ = math_equation_get_variables (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = name;
		_tmp15_ = z;
		math_variables_set (_tmp13_, _tmp14_, _tmp15_);
	} else {
		MathEquation* _tmp16_;
		gboolean _tmp17_;
		gboolean _tmp18_;
		_tmp16_ = self->priv->equation;
		_tmp17_ = math_equation_get_is_result (_tmp16_);
		_tmp18_ = _tmp17_;
		if (_tmp18_) {
			MathEquation* _tmp19_;
			MathVariables* _tmp20_;
			MathVariables* _tmp21_;
			const gchar* _tmp22_;
			MathEquation* _tmp23_;
			Number* _tmp24_;
			Number* _tmp25_;
			_tmp19_ = self->priv->equation;
			_tmp20_ = math_equation_get_variables (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp22_ = name;
			_tmp23_ = self->priv->equation;
			_tmp24_ = math_equation_get_answer (_tmp23_);
			_tmp25_ = _tmp24_;
			math_variables_set (_tmp21_, _tmp22_, _tmp25_);
		} else {
			const gchar* _tmp26_;
			_tmp26_ = name;
			g_warning ("math-variable-popover.vala:110: Can't add variable %s, the display is " \
"not a number", _tmp26_);
		}
	}
	_tmp27_ = self->priv->variable_name_entry;
	gtk_entry_set_text (_tmp27_, "");
	_g_object_unref0 (z);
	_g_free0 (name);
}


static void
_math_variable_popover_store_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	math_variable_popover_store_variable_cb ((MathVariablePopover*) self, _sender);
}


static void
math_variable_popover_delete_variable_cb (MathVariablePopover* self,
                                          GtkWidget* widget)
{
	gchar* name = NULL;
	gconstpointer _tmp0_;
	gchar* _tmp1_;
	MathEquation* _tmp2_;
	MathVariables* _tmp3_;
	MathVariables* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = g_object_get_data ((GObject*) widget, "variable_name");
	_tmp1_ = g_strdup ((const gchar*) _tmp0_);
	name = _tmp1_;
	_tmp2_ = self->priv->equation;
	_tmp3_ = math_equation_get_variables (_tmp2_);
	_tmp4_ = _tmp3_;
	math_variables_delete (_tmp4_, name);
	_g_free0 (name);
}


static void
_math_variable_popover_delete_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                              gpointer self)
{
	math_variable_popover_delete_variable_cb ((MathVariablePopover*) self, _sender);
}


static GtkListBoxRow*
math_variable_popover_make_variable_row (MathVariablePopover* self,
                                         const gchar* name,
                                         Number* value)
{
	GtkListBoxRow* result = NULL;
	GtkListBoxRow* row = NULL;
	GtkListBoxRow* _tmp0_;
	GtkListBoxRow* _tmp1_;
	GtkStyleContext* _tmp2_;
	GtkListBoxRow* _tmp3_;
	gchar* _tmp4_;
	GtkBox* hbox = NULL;
	GtkBox* _tmp5_;
	gchar* text = NULL;
	GtkLabel* label = NULL;
	const gchar* _tmp13_;
	GtkLabel* _tmp14_;
	GtkLabel* _tmp15_;
	GtkLabel* _tmp16_;
	GtkBox* _tmp17_;
	GtkLabel* _tmp18_;
	gchar** _tmp19_;
	gint _tmp19__length1;
	GtkListBoxRow* _tmp28_;
	GtkBox* _tmp29_;
	GtkListBoxRow* _tmp30_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = (GtkListBoxRow*) gtk_list_box_row_new ();
	g_object_ref_sink (_tmp0_);
	row = _tmp0_;
	_tmp1_ = row;
	_tmp2_ = gtk_widget_get_style_context ((GtkWidget*) _tmp1_);
	gtk_style_context_add_class (_tmp2_, "popover-row");
	_tmp3_ = row;
	_tmp4_ = g_strdup (name);
	g_object_set_data_full ((GObject*) _tmp3_, "variable_name", _tmp4_, g_free);
	_tmp5_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp5_);
	hbox = _tmp5_;
	if (value != NULL) {
		gchar* value_text = NULL;
		MathEquation* _tmp6_;
		Serializer* _tmp7_;
		Serializer* _tmp8_;
		gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp6_ = self->priv->equation;
		_tmp7_ = math_equation_get_serializer (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = serializer_to_string (_tmp8_, value);
		value_text = _tmp9_;
		_tmp10_ = value_text;
		_tmp11_ = g_strdup_printf ("<b>%s</b> = %s", name, _tmp10_);
		_g_free0 (text);
		text = _tmp11_;
		_g_free0 (value_text);
	} else {
		gchar* _tmp12_;
		_tmp12_ = g_strdup_printf ("<b>%s</b>", name);
		_g_free0 (text);
		text = _tmp12_;
	}
	_tmp13_ = text;
	_tmp14_ = (GtkLabel*) gtk_label_new (_tmp13_);
	g_object_ref_sink (_tmp14_);
	label = _tmp14_;
	_tmp15_ = label;
	gtk_label_set_use_markup (_tmp15_, TRUE);
	_tmp16_ = label;
	gtk_widget_set_halign ((GtkWidget*) _tmp16_, GTK_ALIGN_START);
	_tmp17_ = hbox;
	_tmp18_ = label;
	gtk_box_pack_start (_tmp17_, (GtkWidget*) _tmp18_, TRUE, TRUE, (guint) 0);
	_tmp19_ = math_variable_popover_RESERVED_VARIABLE_NAMES;
	_tmp19__length1 = math_variable_popover_RESERVED_VARIABLE_NAMES_length1;
	if (!_vala_string_array_contains (_tmp19_, _tmp19__length1, name)) {
		GtkButton* button = NULL;
		GtkButton* _tmp20_;
		GtkButton* _tmp21_;
		GtkStyleContext* _tmp22_;
		GtkButton* _tmp23_;
		gchar* _tmp24_;
		GtkButton* _tmp25_;
		GtkBox* _tmp26_;
		GtkButton* _tmp27_;
		_tmp20_ = (GtkButton*) gtk_button_new_from_icon_name ("list-remove-symbolic", (GtkIconSize) GTK_ICON_SIZE_BUTTON);
		g_object_ref_sink (_tmp20_);
		button = _tmp20_;
		_tmp21_ = button;
		_tmp22_ = gtk_widget_get_style_context ((GtkWidget*) _tmp21_);
		gtk_style_context_add_class (_tmp22_, "flat");
		_tmp23_ = button;
		_tmp24_ = g_strdup (name);
		g_object_set_data_full ((GObject*) _tmp23_, "variable_name", _tmp24_, g_free);
		_tmp25_ = button;
		g_signal_connect_object (_tmp25_, "clicked", (GCallback) _math_variable_popover_delete_variable_cb_gtk_button_clicked, self, 0);
		_tmp26_ = hbox;
		_tmp27_ = button;
		gtk_box_pack_start (_tmp26_, (GtkWidget*) _tmp27_, FALSE, TRUE, (guint) 0);
		_g_object_unref0 (button);
	}
	_tmp28_ = row;
	_tmp29_ = hbox;
	gtk_container_add ((GtkContainer*) _tmp28_, (GtkWidget*) _tmp29_);
	_tmp30_ = row;
	gtk_widget_show_all ((GtkWidget*) _tmp30_);
	result = row;
	_g_object_unref0 (label);
	_g_free0 (text);
	_g_object_unref0 (hbox);
	return result;
}


static gint
math_variable_popover_variable_list_sort (MathVariablePopover* self,
                                          GtkListBoxRow* row1,
                                          GtkListBoxRow* row2)
{
	gint result = 0;
	gchar* name1 = NULL;
	gconstpointer _tmp0_;
	gchar* _tmp1_;
	gchar* name2 = NULL;
	gconstpointer _tmp2_;
	gchar* _tmp3_;
	GCompareFunc _tmp4_;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (row1 != NULL, 0);
	g_return_val_if_fail (row2 != NULL, 0);
	_tmp0_ = g_object_get_data ((GObject*) row1, "variable_name");
	_tmp1_ = g_strdup ((const gchar*) _tmp0_);
	name1 = _tmp1_;
	_tmp2_ = g_object_get_data ((GObject*) row2, "variable_name");
	_tmp3_ = g_strdup ((const gchar*) _tmp2_);
	name2 = _tmp3_;
	_tmp4_ = g_strcmp0;
	result = _tmp4_ (name1, name2);
	_g_free0 (name2);
	_g_free0 (name1);
	return result;
}


static void
math_variable_popover_class_init (MathVariablePopoverClass * klass)
{
	gint MathVariablePopover_private_offset;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	math_variable_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MathVariablePopoverPrivate));
	G_OBJECT_CLASS (klass)->finalize = math_variable_popover_finalize;
	MathVariablePopover_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/calculator/math-variable-popover.ui");
	_tmp0_ = g_strdup ("_");
	_tmp1_ = g_strdup ("rand");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	math_variable_popover_RESERVED_VARIABLE_NAMES = _tmp2_;
	math_variable_popover_RESERVED_VARIABLE_NAMES_length1 = 2;
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variable_list", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, variable_list));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variable_name_entry", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, variable_name_entry));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "store_variable_button", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, store_variable_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "insert_variable_cb", G_CALLBACK(_math_variable_popover_insert_variable_cb_gtk_list_box_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "variable_name_key_press_cb", G_CALLBACK(_math_variable_popover_variable_name_key_press_cb_gtk_widget_key_press_event));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "variable_name_changed_cb", G_CALLBACK(_math_variable_popover_variable_name_changed_cb_gtk_editable_changed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "store_variable_cb", G_CALLBACK(_math_variable_popover_store_variable_cb_gtk_button_clicked));
}


static void
math_variable_popover_instance_init (MathVariablePopover * self)
{
	self->priv = MATH_VARIABLE_POPOVER_GET_PRIVATE (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void
math_variable_popover_finalize (GObject * obj)
{
	MathVariablePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MATH_VARIABLE_POPOVER, MathVariablePopover);
	_g_object_unref0 (self->priv->equation);
	_g_object_unref0 (self->priv->variable_list);
	_g_object_unref0 (self->priv->variable_name_entry);
	_g_object_unref0 (self->priv->store_variable_button);
	G_OBJECT_CLASS (math_variable_popover_parent_class)->finalize (obj);
}


GType
math_variable_popover_get_type (void)
{
	static volatile gsize math_variable_popover_type_id__volatile = 0;
	if (g_once_init_enter (&math_variable_popover_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MathVariablePopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) math_variable_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MathVariablePopover), 0, (GInstanceInitFunc) math_variable_popover_instance_init, NULL };
		GType math_variable_popover_type_id;
		math_variable_popover_type_id = g_type_register_static (gtk_popover_get_type (), "MathVariablePopover", &g_define_type_info, 0);
		g_once_init_leave (&math_variable_popover_type_id__volatile, math_variable_popover_type_id);
	}
	return math_variable_popover_type_id__volatile;
}


static void
_vala_array_destroy (gpointer array,
                     gint array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void
_vala_array_free (gpointer array,
                  gint array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}