/* ModifyFilterDialog.c generated by valac 0.26.2, the Vala compiler
 * generated from ModifyFilterDialog.vala, do not modify */

/*  This file is part of corebird, a Gtk+ linux Twitter client.
 *  Copyright (C) 2013 Timm Bäder
 *
 *  corebird 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.
 *
 *  corebird is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with corebird.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gee.h>


#define TYPE_MODIFY_FILTER_DIALOG (modify_filter_dialog_get_type ())
#define MODIFY_FILTER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialog))
#define MODIFY_FILTER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialogClass))
#define IS_MODIFY_FILTER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MODIFY_FILTER_DIALOG))
#define IS_MODIFY_FILTER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MODIFY_FILTER_DIALOG))
#define MODIFY_FILTER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialogClass))

typedef struct _ModifyFilterDialog ModifyFilterDialog;
typedef struct _ModifyFilterDialogClass ModifyFilterDialogClass;
typedef struct _ModifyFilterDialogPrivate ModifyFilterDialogPrivate;

#define TYPE_ACCOUNT (account_get_type ())
#define ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ACCOUNT, Account))
#define ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ACCOUNT, AccountClass))
#define IS_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ACCOUNT))
#define IS_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ACCOUNT))
#define ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ACCOUNT, AccountClass))

typedef struct _Account Account;
typedef struct _AccountClass AccountClass;

#define TYPE_FILTER (filter_get_type ())
#define FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FILTER, Filter))
#define FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FILTER, FilterClass))
#define IS_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FILTER))
#define IS_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FILTER))
#define FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FILTER, FilterClass))

typedef struct _Filter Filter;
typedef struct _FilterClass FilterClass;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define SQL_TYPE_DATABASE (sql_database_get_type ())
#define SQL_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQL_TYPE_DATABASE, SqlDatabase))
#define SQL_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQL_TYPE_DATABASE, SqlDatabaseClass))
#define SQL_IS_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_TYPE_DATABASE))
#define SQL_IS_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQL_TYPE_DATABASE))
#define SQL_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQL_TYPE_DATABASE, SqlDatabaseClass))

typedef struct _SqlDatabase SqlDatabase;
typedef struct _SqlDatabaseClass SqlDatabaseClass;

#define SQL_TYPE_INSERT_STATEMENT (sql_insert_statement_get_type ())
#define SQL_INSERT_STATEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQL_TYPE_INSERT_STATEMENT, SqlInsertStatement))
#define SQL_INSERT_STATEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQL_TYPE_INSERT_STATEMENT, SqlInsertStatementClass))
#define SQL_IS_INSERT_STATEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_TYPE_INSERT_STATEMENT))
#define SQL_IS_INSERT_STATEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQL_TYPE_INSERT_STATEMENT))
#define SQL_INSERT_STATEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQL_TYPE_INSERT_STATEMENT, SqlInsertStatementClass))

typedef struct _SqlInsertStatement SqlInsertStatement;
typedef struct _SqlInsertStatementClass SqlInsertStatementClass;
#define _sql_insert_statement_unref0(var) ((var == NULL) ? NULL : (var = (sql_insert_statement_unref (var), NULL)))

#define SQL_TYPE_UPDATE_STATEMENT (sql_update_statement_get_type ())
#define SQL_UPDATE_STATEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQL_TYPE_UPDATE_STATEMENT, SqlUpdateStatement))
#define SQL_UPDATE_STATEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQL_TYPE_UPDATE_STATEMENT, SqlUpdateStatementClass))
#define SQL_IS_UPDATE_STATEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_TYPE_UPDATE_STATEMENT))
#define SQL_IS_UPDATE_STATEMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQL_TYPE_UPDATE_STATEMENT))
#define SQL_UPDATE_STATEMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQL_TYPE_UPDATE_STATEMENT, SqlUpdateStatementClass))

typedef struct _SqlUpdateStatement SqlUpdateStatement;
typedef struct _SqlUpdateStatementClass SqlUpdateStatementClass;
#define _sql_update_statement_unref0(var) ((var == NULL) ? NULL : (var = (sql_update_statement_unref (var), NULL)))
typedef struct _AccountPrivate AccountPrivate;

struct _ModifyFilterDialog {
	GtkDialog parent_instance;
	ModifyFilterDialogPrivate * priv;
};

struct _ModifyFilterDialogClass {
	GtkDialogClass parent_class;
};

struct _ModifyFilterDialogPrivate {
	GtkEntry* regex_entry;
	GtkLabel* regex_status_label;
	GtkTextView* regex_test_text;
	GtkButton* save_button;
	GRegex* regex;
	Account* account;
	Filter* filter;
	MainWindow* main_window;
};

struct _Account {
	GObject parent_instance;
	AccountPrivate * priv;
	gint64* friends;
	gint friends_length1;
	gint64* blocked;
	gint blocked_length1;
	gint64* muted;
	gint muted_length1;
	gint64* disabled_rts;
	gint disabled_rts_length1;
	GeeArrayList* filters;
};

struct _AccountClass {
	GObjectClass parent_class;
};


static gpointer modify_filter_dialog_parent_class = NULL;

GType modify_filter_dialog_get_type (void) G_GNUC_CONST;
GType account_get_type (void) G_GNUC_CONST;
GType filter_get_type (void) G_GNUC_CONST;
GType main_window_get_type (void) G_GNUC_CONST;
#define MODIFY_FILTER_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialogPrivate))
enum  {
	MODIFY_FILTER_DIALOG_DUMMY_PROPERTY
};
ModifyFilterDialog* modify_filter_dialog_new (MainWindow* parent, Account* account, Filter* filter);
ModifyFilterDialog* modify_filter_dialog_construct (GType object_type, MainWindow* parent, Account* account, Filter* filter);
const gchar* filter_get_content (Filter* self);
static void modify_filter_dialog_real_response (GtkDialog* base, gint response_id);
static void modify_filter_dialog_save_filter (ModifyFilterDialog* self);
static void modify_filter_dialog_regex_entry_changed_cb (ModifyFilterDialog* self);
static void _modify_filter_dialog_regex_entry_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self);
gpointer sql_database_ref (gpointer instance);
void sql_database_unref (gpointer instance);
GParamSpec* sql_param_spec_database (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void sql_value_set_database (GValue* value, gpointer v_object);
void sql_value_take_database (GValue* value, gpointer v_object);
gpointer sql_value_get_database (const GValue* value);
GType sql_database_get_type (void) G_GNUC_CONST;
SqlDatabase* account_get_db (Account* self);
gpointer sql_insert_statement_ref (gpointer instance);
void sql_insert_statement_unref (gpointer instance);
GParamSpec* sql_param_spec_insert_statement (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void sql_value_set_insert_statement (GValue* value, gpointer v_object);
void sql_value_take_insert_statement (GValue* value, gpointer v_object);
gpointer sql_value_get_insert_statement (const GValue* value);
GType sql_insert_statement_get_type (void) G_GNUC_CONST;
SqlInsertStatement* sql_database_insert (SqlDatabase* self, const gchar* table_name);
SqlInsertStatement* sql_insert_statement_val (SqlInsertStatement* self, const gchar* col_name, const gchar* col_value);
gint64 sql_insert_statement_run (SqlInsertStatement* self);
Filter* filter_new (const gchar* expression);
Filter* filter_construct (GType object_type, const gchar* expression);
void filter_set_id (Filter* self, gint value);
void account_add_filter (Account* self, Filter* f);
gpointer sql_update_statement_ref (gpointer instance);
void sql_update_statement_unref (gpointer instance);
GParamSpec* sql_param_spec_update_statement (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void sql_value_set_update_statement (GValue* value, gpointer v_object);
void sql_value_take_update_statement (GValue* value, gpointer v_object);
gpointer sql_value_get_update_statement (const GValue* value);
GType sql_update_statement_get_type (void) G_GNUC_CONST;
SqlUpdateStatement* sql_database_update (SqlDatabase* self, const gchar* table_name);
SqlUpdateStatement* sql_update_statement_val (SqlUpdateStatement* self, const gchar* col_name, const gchar* col_value);
SqlUpdateStatement* sql_update_statement_where_eq (SqlUpdateStatement* self, const gchar* col, const gchar* value);
gint filter_get_id (Filter* self);
gint64 sql_update_statement_run (SqlUpdateStatement* self);
void filter_reset (Filter* self, const gchar* expression);
void main_window_rerun_filters (MainWindow* self);
static void g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static GObject * modify_filter_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void _modify_filter_dialog_regex_entry_changed_cb_gtk_text_buffer_changed (GtkTextBuffer* _sender, gpointer self);
static void modify_filter_dialog_finalize (GObject* obj);


ModifyFilterDialog* modify_filter_dialog_construct (GType object_type, MainWindow* parent, Account* account, Filter* filter) {
	ModifyFilterDialog * self = NULL;
	gint _tmp0_ = 0;
	GtkSettings* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	MainWindow* _tmp4_ = NULL;
	MainWindow* _tmp5_ = NULL;
	GtkApplication* _tmp6_ = NULL;
	Account* _tmp7_ = NULL;
	Filter* _tmp8_ = NULL;
	Filter* _tmp14_ = NULL;
	MainWindow* _tmp15_ = NULL;
	g_return_val_if_fail (IS_MAIN_WINDOW (parent), NULL);
	g_return_val_if_fail (IS_ACCOUNT (account), NULL);
	g_return_val_if_fail ((filter == NULL) || IS_FILTER (filter), NULL);
	_tmp1_ = gtk_settings_get_default ();
	g_object_get (_tmp1_, "gtk-dialogs-use-header", &_tmp2_, NULL);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = 1;
	} else {
		_tmp0_ = 0;
	}
	self = (ModifyFilterDialog*) g_object_new (object_type, "use-header-bar", _tmp0_, NULL);
	_tmp4_ = parent;
	gtk_window_set_transient_for (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_window_get_type (), GtkWindow));
	_tmp5_ = parent;
	_tmp6_ = gtk_window_get_application (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, gtk_window_get_type (), GtkWindow));
	gtk_window_set_application (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), _tmp6_);
	_tmp7_ = account;
	self->priv->account = _tmp7_;
	_tmp8_ = filter;
	if (_tmp8_ != NULL) {
		GtkEntry* _tmp9_ = NULL;
		Filter* _tmp10_ = NULL;
		const gchar* _tmp11_ = NULL;
		const gchar* _tmp12_ = NULL;
		const gchar* _tmp13_ = NULL;
		_tmp9_ = self->priv->regex_entry;
		_tmp10_ = filter;
		_tmp11_ = filter_get_content (_tmp10_);
		_tmp12_ = _tmp11_;
		gtk_entry_set_text (_tmp9_, _tmp12_);
		_tmp13_ = _ ("Modify Filter");
		gtk_window_set_title (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), _tmp13_);
	}
	_tmp14_ = filter;
	self->priv->filter = _tmp14_;
	_tmp15_ = parent;
	self->priv->main_window = _tmp15_;
	return self;
}


ModifyFilterDialog* modify_filter_dialog_new (MainWindow* parent, Account* account, Filter* filter) {
	return modify_filter_dialog_construct (TYPE_MODIFY_FILTER_DIALOG, parent, account, filter);
}


static void modify_filter_dialog_real_response (GtkDialog* base, gint response_id) {
	ModifyFilterDialog * self;
	gint _tmp0_ = 0;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialog);
	_tmp0_ = response_id;
	if (_tmp0_ == ((gint) GTK_RESPONSE_CANCEL)) {
		gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	} else {
		gint _tmp1_ = 0;
		_tmp1_ = response_id;
		if (_tmp1_ == ((gint) GTK_RESPONSE_OK)) {
			modify_filter_dialog_save_filter (self);
			gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
		}
	}
}


static void modify_filter_dialog_regex_entry_changed_cb (ModifyFilterDialog* self) {
	gboolean matches = FALSE;
	GRegex* _tmp10_ = NULL;
	GtkTextView* _tmp11_ = NULL;
	GtkTextBuffer* _tmp12_ = NULL;
	GtkTextBuffer* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	gchar* _tmp16_ = NULL;
	gboolean _tmp17_ = FALSE;
	gboolean _tmp18_ = FALSE;
	gboolean _tmp19_ = FALSE;
	GtkButton* _tmp24_ = NULL;
	GtkEntry* _tmp25_ = NULL;
	const gchar* _tmp26_ = NULL;
	const gchar* _tmp27_ = NULL;
	gint _tmp28_ = 0;
	gint _tmp29_ = 0;
	GError * _inner_error_ = NULL;
	g_return_if_fail (IS_MODIFY_FILTER_DIALOG (self));
	{
		GRegex* _tmp0_ = NULL;
		GtkEntry* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		const gchar* _tmp3_ = NULL;
		GRegex* _tmp4_ = NULL;
		GRegex* _tmp5_ = NULL;
		_tmp1_ = self->priv->regex_entry;
		_tmp2_ = gtk_entry_get_text (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_regex_new (_tmp3_, 0, 0, &_inner_error_);
		_tmp0_ = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch90_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
		_tmp5_ = _tmp0_;
		_tmp0_ = NULL;
		_g_regex_unref0 (self->priv->regex);
		self->priv->regex = _tmp5_;
		_g_regex_unref0 (_tmp0_);
	}
	goto __finally90;
	__catch90_g_regex_error:
	{
		GError* e = NULL;
		GtkLabel* _tmp6_ = NULL;
		GError* _tmp7_ = NULL;
		const gchar* _tmp8_ = NULL;
		GtkButton* _tmp9_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = self->priv->regex_status_label;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		gtk_label_set_label (_tmp6_, _tmp8_);
		_tmp9_ = self->priv->save_button;
		gtk_widget_set_sensitive (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, gtk_widget_get_type (), GtkWidget), FALSE);
		_g_error_free0 (e);
		return;
	}
	__finally90:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_tmp10_ = self->priv->regex;
	_tmp11_ = self->priv->regex_test_text;
	_tmp12_ = gtk_text_view_get_buffer (_tmp11_);
	_tmp13_ = _tmp12_;
	g_object_get (_tmp13_, "text", &_tmp14_, NULL);
	_tmp15_ = _tmp14_;
	_tmp16_ = _tmp15_;
	_tmp17_ = g_regex_match (_tmp10_, _tmp16_, 0, NULL);
	_tmp18_ = _tmp17_;
	_g_free0 (_tmp16_);
	matches = _tmp18_;
	_tmp19_ = matches;
	if (_tmp19_) {
		GtkLabel* _tmp20_ = NULL;
		const gchar* _tmp21_ = NULL;
		_tmp20_ = self->priv->regex_status_label;
		_tmp21_ = _ ("Matches");
		gtk_label_set_label (_tmp20_, _tmp21_);
	} else {
		GtkLabel* _tmp22_ = NULL;
		const gchar* _tmp23_ = NULL;
		_tmp22_ = self->priv->regex_status_label;
		_tmp23_ = _ ("Doesn't match");
		gtk_label_set_label (_tmp22_, _tmp23_);
	}
	_tmp24_ = self->priv->save_button;
	_tmp25_ = self->priv->regex_entry;
	_tmp26_ = gtk_entry_get_text (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = strlen (_tmp27_);
	_tmp29_ = _tmp28_;
	gtk_widget_set_sensitive (G_TYPE_CHECK_INSTANCE_CAST (_tmp24_, gtk_widget_get_type (), GtkWidget), _tmp29_ != 0);
}


static void _modify_filter_dialog_regex_entry_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self) {
	modify_filter_dialog_regex_entry_changed_cb ((ModifyFilterDialog*) self);
}


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


static void modify_filter_dialog_save_filter (ModifyFilterDialog* self) {
	gchar* content = NULL;
	GtkEntry* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	Filter* _tmp4_ = NULL;
	MainWindow* _tmp59_ = NULL;
	g_return_if_fail (IS_MODIFY_FILTER_DIALOG (self));
	_tmp0_ = self->priv->regex_entry;
	_tmp1_ = gtk_entry_get_text (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	content = _tmp3_;
	_tmp4_ = self->priv->filter;
	if (_tmp4_ == NULL) {
		gint id = 0;
		Account* _tmp5_ = NULL;
		SqlDatabase* _tmp6_ = NULL;
		SqlDatabase* _tmp7_ = NULL;
		SqlInsertStatement* _tmp8_ = NULL;
		SqlInsertStatement* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
		SqlInsertStatement* _tmp11_ = NULL;
		SqlInsertStatement* _tmp12_ = NULL;
		gint64 _tmp13_ = 0LL;
		gint _tmp14_ = 0;
		Filter* f = NULL;
		const gchar* _tmp15_ = NULL;
		Filter* _tmp16_ = NULL;
		Filter* _tmp17_ = NULL;
		gint _tmp18_ = 0;
		Account* _tmp19_ = NULL;
		Filter* _tmp20_ = NULL;
		Filter* _tmp21_ = NULL;
		Filter* _tmp22_ = NULL;
		_tmp5_ = self->priv->account;
		_tmp6_ = account_get_db (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = sql_database_insert (_tmp7_, "filters");
		_tmp9_ = _tmp8_;
		_tmp10_ = content;
		_tmp11_ = sql_insert_statement_val (_tmp9_, "content", _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = sql_insert_statement_run (_tmp12_);
		_tmp14_ = (gint) _tmp13_;
		_sql_insert_statement_unref0 (_tmp12_);
		_sql_insert_statement_unref0 (_tmp9_);
		id = _tmp14_;
		_tmp15_ = content;
		_tmp16_ = filter_new (_tmp15_);
		f = _tmp16_;
		_tmp17_ = f;
		_tmp18_ = id;
		filter_set_id (_tmp17_, _tmp18_);
		_tmp19_ = self->priv->account;
		_tmp20_ = f;
		_tmp21_ = _g_object_ref0 (_tmp20_);
		account_add_filter (_tmp19_, _tmp21_);
		_tmp22_ = f;
		g_signal_emit_by_name (self, "filter-added", _tmp22_, TRUE);
		_g_object_unref0 (f);
	} else {
		Account* _tmp23_ = NULL;
		SqlDatabase* _tmp24_ = NULL;
		SqlDatabase* _tmp25_ = NULL;
		SqlUpdateStatement* _tmp26_ = NULL;
		SqlUpdateStatement* _tmp27_ = NULL;
		const gchar* _tmp28_ = NULL;
		SqlUpdateStatement* _tmp29_ = NULL;
		SqlUpdateStatement* _tmp30_ = NULL;
		Filter* _tmp31_ = NULL;
		gint _tmp32_ = 0;
		gint _tmp33_ = 0;
		gchar* _tmp34_ = NULL;
		gchar* _tmp35_ = NULL;
		SqlUpdateStatement* _tmp36_ = NULL;
		SqlUpdateStatement* _tmp37_ = NULL;
		_tmp23_ = self->priv->account;
		_tmp24_ = account_get_db (_tmp23_);
		_tmp25_ = _tmp24_;
		_tmp26_ = sql_database_update (_tmp25_, "filters");
		_tmp27_ = _tmp26_;
		_tmp28_ = content;
		_tmp29_ = sql_update_statement_val (_tmp27_, "content", _tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = self->priv->filter;
		_tmp32_ = filter_get_id (_tmp31_);
		_tmp33_ = _tmp32_;
		_tmp34_ = g_strdup_printf ("%i", _tmp33_);
		_tmp35_ = _tmp34_;
		_tmp36_ = sql_update_statement_where_eq (_tmp30_, "id", _tmp35_);
		_tmp37_ = _tmp36_;
		sql_update_statement_run (_tmp37_);
		_sql_update_statement_unref0 (_tmp37_);
		_g_free0 (_tmp35_);
		_sql_update_statement_unref0 (_tmp30_);
		_sql_update_statement_unref0 (_tmp27_);
		{
			GeeArrayList* _f_list = NULL;
			Account* _tmp38_ = NULL;
			GeeArrayList* _tmp39_ = NULL;
			GeeArrayList* _tmp40_ = NULL;
			gint _f_size = 0;
			GeeArrayList* _tmp41_ = NULL;
			gint _tmp42_ = 0;
			gint _tmp43_ = 0;
			gint _f_index = 0;
			_tmp38_ = self->priv->account;
			_tmp39_ = _tmp38_->filters;
			_tmp40_ = _g_object_ref0 (_tmp39_);
			_f_list = _tmp40_;
			_tmp41_ = _f_list;
			_tmp42_ = gee_abstract_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp41_, GEE_TYPE_COLLECTION, GeeCollection));
			_tmp43_ = _tmp42_;
			_f_size = _tmp43_;
			_f_index = -1;
			while (TRUE) {
				gint _tmp44_ = 0;
				gint _tmp45_ = 0;
				gint _tmp46_ = 0;
				Filter* f = NULL;
				GeeArrayList* _tmp47_ = NULL;
				gint _tmp48_ = 0;
				gpointer _tmp49_ = NULL;
				Filter* _tmp50_ = NULL;
				gint _tmp51_ = 0;
				gint _tmp52_ = 0;
				Filter* _tmp53_ = NULL;
				gint _tmp54_ = 0;
				gint _tmp55_ = 0;
				_tmp44_ = _f_index;
				_f_index = _tmp44_ + 1;
				_tmp45_ = _f_index;
				_tmp46_ = _f_size;
				if (!(_tmp45_ < _tmp46_)) {
					break;
				}
				_tmp47_ = _f_list;
				_tmp48_ = _f_index;
				_tmp49_ = gee_abstract_list_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp47_, GEE_TYPE_ABSTRACT_LIST, GeeAbstractList), _tmp48_);
				f = (Filter*) _tmp49_;
				_tmp50_ = f;
				_tmp51_ = filter_get_id (_tmp50_);
				_tmp52_ = _tmp51_;
				_tmp53_ = self->priv->filter;
				_tmp54_ = filter_get_id (_tmp53_);
				_tmp55_ = _tmp54_;
				if (_tmp52_ == _tmp55_) {
					Filter* _tmp56_ = NULL;
					const gchar* _tmp57_ = NULL;
					Filter* _tmp58_ = NULL;
					_tmp56_ = f;
					_tmp57_ = content;
					filter_reset (_tmp56_, _tmp57_);
					_tmp58_ = f;
					g_signal_emit_by_name (self, "filter-added", _tmp58_, FALSE);
					_g_object_unref0 (f);
					break;
				}
				_g_object_unref0 (f);
			}
			_g_object_unref0 (_f_list);
		}
	}
	_tmp59_ = self->priv->main_window;
	main_window_rerun_filters (_tmp59_);
	_g_free0 (content);
}


static void g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__OBJECT_BOOLEAN) (gpointer data1, gpointer arg_1, gboolean arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOOLEAN callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boolean (param_values + 2), data2);
}


static void _modify_filter_dialog_regex_entry_changed_cb_gtk_text_buffer_changed (GtkTextBuffer* _sender, gpointer self) {
	modify_filter_dialog_regex_entry_changed_cb ((ModifyFilterDialog*) self);
}


static GObject * modify_filter_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	ModifyFilterDialog * self;
	GtkTextView* _tmp0_ = NULL;
	GtkTextBuffer* _tmp1_ = NULL;
	GtkTextBuffer* _tmp2_ = NULL;
	parent_class = G_OBJECT_CLASS (modify_filter_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialog);
	_tmp0_ = self->priv->regex_test_text;
	_tmp1_ = gtk_text_view_get_buffer (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_connect_object (_tmp2_, "changed", (GCallback) _modify_filter_dialog_regex_entry_changed_cb_gtk_text_buffer_changed, self, 0);
	return obj;
}


static void modify_filter_dialog_class_init (ModifyFilterDialogClass * klass) {
	gint ModifyFilterDialog_private_offset;
	modify_filter_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ModifyFilterDialogPrivate));
	((GtkDialogClass *) klass)->response = modify_filter_dialog_real_response;
	G_OBJECT_CLASS (klass)->constructor = modify_filter_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = modify_filter_dialog_finalize;
	ModifyFilterDialog_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/baedert/corebird/ui/modify-filter-dialog.ui");
	/** created will be true if the filter has just been created by the user(i.e. not modified) */
	g_signal_new ("filter_added", TYPE_MODIFY_FILTER_DIALOG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOOLEAN, G_TYPE_NONE, 2, TYPE_FILTER, G_TYPE_BOOLEAN);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "regex_entry", FALSE, ModifyFilterDialog_private_offset + G_STRUCT_OFFSET (ModifyFilterDialogPrivate, regex_entry));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "regex_status_label", FALSE, ModifyFilterDialog_private_offset + G_STRUCT_OFFSET (ModifyFilterDialogPrivate, regex_status_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "regex_test_text", FALSE, ModifyFilterDialog_private_offset + G_STRUCT_OFFSET (ModifyFilterDialogPrivate, regex_test_text));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "save_button", FALSE, ModifyFilterDialog_private_offset + G_STRUCT_OFFSET (ModifyFilterDialogPrivate, save_button));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "regex_entry_changed_cb", G_CALLBACK(_modify_filter_dialog_regex_entry_changed_cb_gtk_editable_changed));
}


static void modify_filter_dialog_instance_init (ModifyFilterDialog * self) {
	self->priv = MODIFY_FILTER_DIALOG_GET_PRIVATE (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void modify_filter_dialog_finalize (GObject* obj) {
	ModifyFilterDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MODIFY_FILTER_DIALOG, ModifyFilterDialog);
	_g_object_unref0 (self->priv->regex_entry);
	_g_object_unref0 (self->priv->regex_status_label);
	_g_object_unref0 (self->priv->regex_test_text);
	_g_object_unref0 (self->priv->save_button);
	_g_regex_unref0 (self->priv->regex);
	G_OBJECT_CLASS (modify_filter_dialog_parent_class)->finalize (obj);
}


GType modify_filter_dialog_get_type (void) {
	static volatile gsize modify_filter_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&modify_filter_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ModifyFilterDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) modify_filter_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ModifyFilterDialog), 0, (GInstanceInitFunc) modify_filter_dialog_instance_init, NULL };
		GType modify_filter_dialog_type_id;
		modify_filter_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "ModifyFilterDialog", &g_define_type_info, 0);
		g_once_init_leave (&modify_filter_dialog_type_id__volatile, modify_filter_dialog_type_id);
	}
	return modify_filter_dialog_type_id__volatile;
}



