/* preferences-dialog.c generated by valac 0.56.17, the Vala compiler
 * generated from preferences-dialog.vala, do not modify */

/*
Peek Copyright (c) 2015-2018 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <gdk/gdk.h>
#include <glib.h>
#include "../../application.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define PEEK_UI_TYPE_PREFERENCES_DIALOG (peek_ui_preferences_dialog_get_type ())
#define PEEK_UI_PREFERENCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEEK_UI_TYPE_PREFERENCES_DIALOG, PeekUiPreferencesDialog))
#define PEEK_UI_PREFERENCES_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PEEK_UI_TYPE_PREFERENCES_DIALOG, PeekUiPreferencesDialogClass))
#define PEEK_UI_IS_PREFERENCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEEK_UI_TYPE_PREFERENCES_DIALOG))
#define PEEK_UI_IS_PREFERENCES_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEEK_UI_TYPE_PREFERENCES_DIALOG))
#define PEEK_UI_PREFERENCES_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PEEK_UI_TYPE_PREFERENCES_DIALOG, PeekUiPreferencesDialogClass))

typedef struct _PeekUiPreferencesDialog PeekUiPreferencesDialog;
typedef struct _PeekUiPreferencesDialogClass PeekUiPreferencesDialogClass;
typedef struct _PeekUiPreferencesDialogPrivate PeekUiPreferencesDialogPrivate;
enum  {
	PEEK_UI_PREFERENCES_DIALOG_0_PROPERTY,
	PEEK_UI_PREFERENCES_DIALOG_NUM_PROPERTIES
};
static GParamSpec* peek_ui_preferences_dialog_properties[PEEK_UI_PREFERENCES_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block7Data Block7Data;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _PeekUiPreferencesDialog {
	GtkWindow parent_instance;
	PeekUiPreferencesDialogPrivate * priv;
};

struct _PeekUiPreferencesDialogClass {
	GtkWindowClass parent_class;
};

struct _PeekUiPreferencesDialogPrivate {
	GSettings* settings;
	GtkCheckButton* interface_open_file_manager;
	GtkCheckButton* interface_show_notification;
	GtkBox* keybinding_toggle_recording_box;
	GtkShortcutLabel* keybinding_toggle_recording_accelerator;
	GtkBox* keybinding_toggle_recording_editor;
	GtkToggleButton* keybinding_toggle_recording_button;
	GtkComboBoxText* recording_output_format_combo_box;
	GtkBox* recording_gifski_settings;
	GtkCheckButton* recording_gifski_enabled;
	GtkBox* recording_gifski_quality_box;
	GtkAdjustment* recording_gifski_quality;
	GtkScale* recording_gifski_quality_scale;
	GtkAdjustment* recording_start_delay;
	GtkAdjustment* recording_framerate;
	GtkAdjustment* recording_downsample;
	GtkCheckButton* recording_capture_mouse;
};

struct _Block7Data {
	int _ref_count_;
	GtkWindow* main_window;
};

static gint PeekUiPreferencesDialog_private_offset;
static gpointer peek_ui_preferences_dialog_parent_class = NULL;
static GtkWindow* peek_ui_preferences_dialog_instance;
static GtkWindow* peek_ui_preferences_dialog_instance = NULL;

VALA_EXTERN GType peek_ui_preferences_dialog_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GtkWindow* peek_ui_preferences_dialog_present_single_instance (GtkWindow* main_window);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
VALA_EXTERN PeekUiPreferencesDialog* peek_ui_preferences_dialog_new (void);
VALA_EXTERN PeekUiPreferencesDialog* peek_ui_preferences_dialog_construct (GType object_type);
static gboolean ___lambda20_ (Block7Data* _data7_,
                       GdkEventAny* event);
static gboolean ____lambda20__gtk_widget_delete_event (GtkWidget* _sender,
                                                GdkEventAny* event,
                                                gpointer self);
static void peek_ui_preferences_dialog_on_interface_open_file_manager_toggled (PeekUiPreferencesDialog* self,
                                                                        GtkToggleButton* source);
static void peek_ui_preferences_dialog_on_gifski_toggled (PeekUiPreferencesDialog* self,
                                                   GtkToggleButton* source);
static void peek_ui_preferences_dialog_init_keybinding_editor (PeekUiPreferencesDialog* self);
static void _peek_ui_preferences_dialog_on_interface_open_file_manager_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                                   gpointer self);
static void peek_ui_preferences_dialog_on_output_format_changed (PeekUiPreferencesDialog* self);
static void _peek_ui_preferences_dialog_on_output_format_changed_gtk_combo_box_changed (GtkComboBox* _sender,
                                                                                 gpointer self);
static void _peek_ui_preferences_dialog_on_gifski_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                              gpointer self);
static gboolean peek_ui_preferences_dialog_real_delete_event (GtkWidget* base,
                                                       GdkEventAny* event);
static void peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled (PeekUiPreferencesDialog* self,
                                                                               GtkButton* source);
static void _peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                                          gpointer self);
static gboolean peek_ui_preferences_dialog_on_key_release (PeekUiPreferencesDialog* self,
                                                    GdkEventKey* event);
static gboolean _peek_ui_preferences_dialog_on_key_release_gtk_widget_key_release_event (GtkWidget* _sender,
                                                                                  GdkEventKey* event,
                                                                                  gpointer self);
static gboolean peek_ui_preferences_dialog_no_modifier_set (GdkModifierType mods);
static void peek_ui_preferences_dialog_finalize (GObject * obj);
static GType peek_ui_preferences_dialog_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
peek_ui_preferences_dialog_get_instance_private (PeekUiPreferencesDialog* self)
{
	return G_STRUCT_MEMBER_P (self, PeekUiPreferencesDialog_private_offset);
}

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

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		_g_object_unref0 (_data7_->main_window);
		g_slice_free (Block7Data, _data7_);
	}
}

static gboolean
___lambda20_ (Block7Data* _data7_,
              GdkEventAny* event)
{
	gboolean result;
	g_return_val_if_fail (event != NULL, FALSE);
	_g_object_unref0 (peek_ui_preferences_dialog_instance);
	peek_ui_preferences_dialog_instance = NULL;
	gtk_window_set_keep_above (_data7_->main_window, TRUE);
	result = FALSE;
	return result;
}

static gboolean
____lambda20__gtk_widget_delete_event (GtkWidget* _sender,
                                       GdkEventAny* event,
                                       gpointer self)
{
	gboolean result;
	result = ___lambda20_ (self, event);
	return result;
}

GtkWindow*
peek_ui_preferences_dialog_present_single_instance (GtkWindow* main_window)
{
	Block7Data* _data7_;
	GtkWindow* _tmp0_;
	GtkWindow* _tmp1_;
	GtkWindow* _tmp4_;
	GtkWindow* _tmp5_;
	GtkWindow* _tmp6_;
	GtkWindow* _tmp7_;
	GtkWindow* result;
	g_return_val_if_fail (main_window != NULL, NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (main_window);
	_g_object_unref0 (_data7_->main_window);
	_data7_->main_window = _tmp0_;
	_tmp1_ = peek_ui_preferences_dialog_instance;
	if (_tmp1_ == NULL) {
		PeekUiPreferencesDialog* _tmp2_;
		GtkWindow* _tmp3_;
		_tmp2_ = peek_ui_preferences_dialog_new ();
		g_object_ref_sink (_tmp2_);
		_g_object_unref0 (peek_ui_preferences_dialog_instance);
		peek_ui_preferences_dialog_instance = (GtkWindow*) _tmp2_;
		_tmp3_ = peek_ui_preferences_dialog_instance;
		g_signal_connect_data ((GtkWidget*) _tmp3_, "delete-event", (GCallback) ____lambda20__gtk_widget_delete_event, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
	}
	_tmp4_ = peek_ui_preferences_dialog_instance;
	gtk_window_set_transient_for (_tmp4_, _data7_->main_window);
	gtk_window_set_keep_above (_data7_->main_window, FALSE);
	_tmp5_ = peek_ui_preferences_dialog_instance;
	gtk_window_present (_tmp5_);
	_tmp6_ = peek_ui_preferences_dialog_instance;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	result = _tmp7_;
	block7_data_unref (_data7_);
	_data7_ = NULL;
	return result;
}

PeekUiPreferencesDialog*
peek_ui_preferences_dialog_construct (GType object_type)
{
	PeekUiPreferencesDialog * self = NULL;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	GtkCheckButton* _tmp2_;
	GSettings* _tmp3_;
	GtkCheckButton* _tmp4_;
	GSettings* _tmp5_;
	GtkComboBoxText* _tmp6_;
	GSettings* _tmp7_;
	GtkCheckButton* _tmp8_;
	GSettings* _tmp9_;
	GtkAdjustment* _tmp10_;
	GSettings* _tmp11_;
	GtkAdjustment* _tmp12_;
	GSettings* _tmp13_;
	GtkAdjustment* _tmp14_;
	GSettings* _tmp15_;
	GtkAdjustment* _tmp16_;
	GSettings* _tmp17_;
	GtkCheckButton* _tmp18_;
	GtkCheckButton* _tmp19_;
	GtkCheckButton* _tmp20_;
	self = (PeekUiPreferencesDialog*) g_object_new (object_type, NULL);
	_tmp0_ = peek_application_get_app_settings ();
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = self->priv->settings;
	_tmp2_ = self->priv->interface_open_file_manager;
	g_settings_bind (_tmp1_, "interface-open-file-manager", (GObject*) _tmp2_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp3_ = self->priv->settings;
	_tmp4_ = self->priv->interface_show_notification;
	g_settings_bind (_tmp3_, "interface-show-notification", (GObject*) _tmp4_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp5_ = self->priv->settings;
	_tmp6_ = self->priv->recording_output_format_combo_box;
	g_settings_bind (_tmp5_, "recording-output-format", (GObject*) _tmp6_, "active_id", G_SETTINGS_BIND_DEFAULT);
	_tmp7_ = self->priv->settings;
	_tmp8_ = self->priv->recording_gifski_enabled;
	g_settings_bind (_tmp7_, "recording-gifski-enabled", (GObject*) _tmp8_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp9_ = self->priv->settings;
	_tmp10_ = self->priv->recording_gifski_quality;
	g_settings_bind (_tmp9_, "recording-gifski-quality", (GObject*) _tmp10_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp11_ = self->priv->settings;
	_tmp12_ = self->priv->recording_start_delay;
	g_settings_bind (_tmp11_, "recording-start-delay", (GObject*) _tmp12_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp13_ = self->priv->settings;
	_tmp14_ = self->priv->recording_framerate;
	g_settings_bind (_tmp13_, "recording-framerate", (GObject*) _tmp14_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp15_ = self->priv->settings;
	_tmp16_ = self->priv->recording_downsample;
	g_settings_bind (_tmp15_, "recording-downsample", (GObject*) _tmp16_, "value", G_SETTINGS_BIND_DEFAULT);
	_tmp17_ = self->priv->settings;
	_tmp18_ = self->priv->recording_capture_mouse;
	g_settings_bind (_tmp17_, "recording-capture-mouse", (GObject*) _tmp18_, "active", G_SETTINGS_BIND_DEFAULT);
	_tmp19_ = self->priv->interface_open_file_manager;
	peek_ui_preferences_dialog_on_interface_open_file_manager_toggled (self, (GtkToggleButton*) _tmp19_);
	_tmp20_ = self->priv->recording_gifski_enabled;
	peek_ui_preferences_dialog_on_gifski_toggled (self, (GtkToggleButton*) _tmp20_);
	{
		gint i = 0;
		i = 20;
		{
			gboolean _tmp21_ = FALSE;
			_tmp21_ = TRUE;
			while (TRUE) {
				GtkScale* _tmp22_;
				if (!_tmp21_) {
					i += 20;
				}
				_tmp21_ = FALSE;
				if (!(i <= 100)) {
					break;
				}
				_tmp22_ = self->priv->recording_gifski_quality_scale;
				gtk_scale_add_mark (_tmp22_, (gdouble) i, GTK_POS_BOTTOM, NULL);
			}
		}
	}
	if (!peek_post_processing_gifski_post_processor_is_available ()) {
		GtkBox* _tmp23_;
		_tmp23_ = self->priv->recording_gifski_settings;
		gtk_widget_hide ((GtkWidget*) _tmp23_);
	}
	if (peek_desktop_integration_is_x11_backend ()) {
		peek_ui_preferences_dialog_init_keybinding_editor (self);
	} else {
		GtkBox* _tmp24_;
		_tmp24_ = self->priv->keybinding_toggle_recording_box;
		gtk_widget_hide ((GtkWidget*) _tmp24_);
	}
	return self;
}

PeekUiPreferencesDialog*
peek_ui_preferences_dialog_new (void)
{
	return peek_ui_preferences_dialog_construct (PEEK_UI_TYPE_PREFERENCES_DIALOG);
}

static void
peek_ui_preferences_dialog_on_interface_open_file_manager_toggled (PeekUiPreferencesDialog* self,
                                                                   GtkToggleButton* source)
{
	GtkCheckButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = self->priv->interface_show_notification;
	_tmp1_ = gtk_toggle_button_get_active (source);
	_tmp2_ = _tmp1_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, !_tmp2_);
}

static void
_peek_ui_preferences_dialog_on_interface_open_file_manager_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                              gpointer self)
{
	peek_ui_preferences_dialog_on_interface_open_file_manager_toggled ((PeekUiPreferencesDialog*) self, _sender);
}

static void
peek_ui_preferences_dialog_on_output_format_changed (PeekUiPreferencesDialog* self)
{
	GtkBox* _tmp0_;
	GtkComboBoxText* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->recording_gifski_settings;
	_tmp1_ = self->priv->recording_output_format_combo_box;
	_tmp2_ = gtk_combo_box_get_active_id ((GtkComboBox*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = peek_output_format_to_string (PEEK_OUTPUT_FORMAT_GIF);
	_tmp5_ = _tmp4_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, g_strcmp0 (_tmp3_, _tmp5_) == 0);
	_g_free0 (_tmp5_);
}

static void
_peek_ui_preferences_dialog_on_output_format_changed_gtk_combo_box_changed (GtkComboBox* _sender,
                                                                            gpointer self)
{
	peek_ui_preferences_dialog_on_output_format_changed ((PeekUiPreferencesDialog*) self);
}

static void
peek_ui_preferences_dialog_on_gifski_toggled (PeekUiPreferencesDialog* self,
                                              GtkToggleButton* source)
{
	GtkBox* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = self->priv->recording_gifski_quality_box;
	_tmp1_ = gtk_toggle_button_get_active (source);
	_tmp2_ = _tmp1_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, _tmp2_);
}

static void
_peek_ui_preferences_dialog_on_gifski_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                         gpointer self)
{
	peek_ui_preferences_dialog_on_gifski_toggled ((PeekUiPreferencesDialog*) self, _sender);
}

static gboolean
peek_ui_preferences_dialog_real_delete_event (GtkWidget* base,
                                              GdkEventAny* event)
{
	PeekUiPreferencesDialog * self;
	gboolean result;
	self = (PeekUiPreferencesDialog*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	peek_application_set_keybindings_paused (FALSE);
	result = FALSE;
	return result;
}

static void
_peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                                     gpointer self)
{
	peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled ((PeekUiPreferencesDialog*) self, _sender);
}

static gboolean
_peek_ui_preferences_dialog_on_key_release_gtk_widget_key_release_event (GtkWidget* _sender,
                                                                         GdkEventKey* event,
                                                                         gpointer self)
{
	gboolean result;
	result = peek_ui_preferences_dialog_on_key_release ((PeekUiPreferencesDialog*) self, event);
	return result;
}

static void
peek_ui_preferences_dialog_init_keybinding_editor (PeekUiPreferencesDialog* self)
{
	GtkBox* editor_box = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkShortcutLabel* _tmp2_;
	GtkShortcutLabel* _tmp3_;
	GtkShortcutLabel* _tmp4_;
	GSettings* _tmp5_;
	GtkShortcutLabel* _tmp6_;
	GtkShortcutLabel* _tmp7_;
	GtkToggleButton* _tmp8_;
	GtkToggleButton* _tmp9_;
	GtkToggleButton* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->keybinding_toggle_recording_editor;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	editor_box = _tmp1_;
	_tmp2_ = (GtkShortcutLabel*) gtk_shortcut_label_new ("");
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->keybinding_toggle_recording_accelerator);
	self->priv->keybinding_toggle_recording_accelerator = _tmp2_;
	_tmp3_ = self->priv->keybinding_toggle_recording_accelerator;
	gtk_shortcut_label_set_disabled_text (_tmp3_, _ ("deactivated"));
	_tmp4_ = self->priv->keybinding_toggle_recording_accelerator;
	gtk_box_pack_start (editor_box, (GtkWidget*) _tmp4_, FALSE, TRUE, (guint) 0);
	_tmp5_ = self->priv->settings;
	_tmp6_ = self->priv->keybinding_toggle_recording_accelerator;
	g_settings_bind (_tmp5_, "keybinding-toggle-recording", (GObject*) _tmp6_, "accelerator", G_SETTINGS_BIND_DEFAULT);
	_tmp7_ = self->priv->keybinding_toggle_recording_accelerator;
	g_object_set ((GtkWidget*) _tmp7_, "width-request", 175, NULL);
	_tmp8_ = (GtkToggleButton*) gtk_toggle_button_new_with_label (_ ("Change"));
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->keybinding_toggle_recording_button);
	self->priv->keybinding_toggle_recording_button = _tmp8_;
	_tmp9_ = self->priv->keybinding_toggle_recording_button;
	g_signal_connect_object (_tmp9_, "toggled", (GCallback) _peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled_gtk_toggle_button_toggled, self, 0);
	_tmp10_ = self->priv->keybinding_toggle_recording_button;
	gtk_box_pack_start (editor_box, (GtkWidget*) _tmp10_, FALSE, TRUE, (guint) 0);
	g_signal_connect_object ((GtkWidget*) self, "key-release-event", (GCallback) _peek_ui_preferences_dialog_on_key_release_gtk_widget_key_release_event, self, 0);
	gtk_widget_show_all ((GtkWidget*) editor_box);
	_g_object_unref0 (editor_box);
}

static void
peek_ui_preferences_dialog_on_keybinding_toggle_recording_button_toggled (PeekUiPreferencesDialog* self,
                                                                          GtkButton* source)
{
	GtkToggleButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (source != NULL);
	_tmp0_ = self->priv->keybinding_toggle_recording_button;
	_tmp1_ = gtk_toggle_button_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkToggleButton* _tmp3_;
		_tmp3_ = self->priv->keybinding_toggle_recording_button;
		gtk_button_set_label ((GtkButton*) _tmp3_, _ ("Press keys…"));
		peek_application_set_keybindings_paused (TRUE);
	} else {
		GtkToggleButton* _tmp4_;
		_tmp4_ = self->priv->keybinding_toggle_recording_button;
		gtk_button_set_label ((GtkButton*) _tmp4_, _ ("Change"));
		peek_application_set_keybindings_paused (FALSE);
	}
}

static gboolean
peek_ui_preferences_dialog_on_key_release (PeekUiPreferencesDialog* self,
                                           GdkEventKey* event)
{
	GtkToggleButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = self->priv->keybinding_toggle_recording_button;
	_tmp1_ = gtk_toggle_button_get_active (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GtkToggleButton* _tmp3_;
		gboolean _tmp4_ = FALSE;
		_tmp3_ = self->priv->keybinding_toggle_recording_button;
		gtk_toggle_button_set_active (_tmp3_, FALSE);
		if (event->keyval == GDK_KEY_Escape) {
			_tmp4_ = peek_ui_preferences_dialog_no_modifier_set (event->state);
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			result = TRUE;
			return result;
		} else {
			gboolean _tmp5_ = FALSE;
			if (event->keyval == GDK_KEY_BackSpace) {
				_tmp5_ = peek_ui_preferences_dialog_no_modifier_set (event->state);
			} else {
				_tmp5_ = FALSE;
			}
			if (_tmp5_) {
				GSettings* _tmp6_;
				_tmp6_ = self->priv->settings;
				g_settings_set_string (_tmp6_, "keybinding-toggle-recording", "");
			} else {
				if (event->is_modifier == ((guint) 0)) {
					GdkModifierType mods = 0U;
					gchar* accelerator = NULL;
					gchar* _tmp7_;
					GSettings* _tmp8_;
					const gchar* _tmp9_;
					mods = event->state & gtk_accelerator_get_default_mod_mask ();
					_tmp7_ = gtk_accelerator_name (event->keyval, mods);
					accelerator = _tmp7_;
					_tmp8_ = self->priv->settings;
					_tmp9_ = accelerator;
					g_settings_set_string (_tmp8_, "keybinding-toggle-recording", _tmp9_);
					_g_free0 (accelerator);
				}
			}
		}
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
peek_ui_preferences_dialog_no_modifier_set (GdkModifierType mods)
{
	gboolean result;
	result = (mods & gtk_accelerator_get_default_mod_mask ()) == 0;
	return result;
}

static void
peek_ui_preferences_dialog_class_init (PeekUiPreferencesDialogClass * klass,
                                       gpointer klass_data)
{
	peek_ui_preferences_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &PeekUiPreferencesDialog_private_offset);
	((GtkWidgetClass *) klass)->delete_event = (gboolean (*) (GtkWidget*, GdkEventAny*)) peek_ui_preferences_dialog_real_delete_event;
	G_OBJECT_CLASS (klass)->finalize = peek_ui_preferences_dialog_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/uploadedlobster/peek/preferences.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "interface_open_file_manager", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, interface_open_file_manager));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "interface_show_notification", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, interface_show_notification));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "keybinding_toggle_recording_box", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, keybinding_toggle_recording_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "keybinding_toggle_recording_editor", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, keybinding_toggle_recording_editor));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_output_format_combo_box", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_output_format_combo_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_gifski_settings", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_gifski_settings));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_gifski_enabled", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_gifski_enabled));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_gifski_quality_box", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_gifski_quality_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_gifski_quality", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_gifski_quality));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_gifski_quality_scale", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_gifski_quality_scale));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_start_delay", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_start_delay));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_framerate", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_framerate));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_downsample", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_downsample));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "recording_capture_mouse", FALSE, PeekUiPreferencesDialog_private_offset + G_STRUCT_OFFSET (PeekUiPreferencesDialogPrivate, recording_capture_mouse));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_interface_open_file_manager_toggled", G_CALLBACK(_peek_ui_preferences_dialog_on_interface_open_file_manager_toggled_gtk_toggle_button_toggled));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_output_format_changed", G_CALLBACK(_peek_ui_preferences_dialog_on_output_format_changed_gtk_combo_box_changed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_gifski_toggled", G_CALLBACK(_peek_ui_preferences_dialog_on_gifski_toggled_gtk_toggle_button_toggled));
}

static void
peek_ui_preferences_dialog_instance_init (PeekUiPreferencesDialog * self,
                                          gpointer klass)
{
	self->priv = peek_ui_preferences_dialog_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
peek_ui_preferences_dialog_finalize (GObject * obj)
{
	PeekUiPreferencesDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PEEK_UI_TYPE_PREFERENCES_DIALOG, PeekUiPreferencesDialog);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->keybinding_toggle_recording_accelerator);
	_g_object_unref0 (self->priv->keybinding_toggle_recording_button);
	G_OBJECT_CLASS (peek_ui_preferences_dialog_parent_class)->finalize (obj);
}

static GType
peek_ui_preferences_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (PeekUiPreferencesDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) peek_ui_preferences_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PeekUiPreferencesDialog), 0, (GInstanceInitFunc) peek_ui_preferences_dialog_instance_init, NULL };
	GType peek_ui_preferences_dialog_type_id;
	peek_ui_preferences_dialog_type_id = g_type_register_static (gtk_window_get_type (), "PeekUiPreferencesDialog", &g_define_type_info, 0);
	PeekUiPreferencesDialog_private_offset = g_type_add_instance_private (peek_ui_preferences_dialog_type_id, sizeof (PeekUiPreferencesDialogPrivate));
	return peek_ui_preferences_dialog_type_id;
}

GType
peek_ui_preferences_dialog_get_type (void)
{
	static volatile gsize peek_ui_preferences_dialog_type_id__once = 0;
	if (g_once_init_enter (&peek_ui_preferences_dialog_type_id__once)) {
		GType peek_ui_preferences_dialog_type_id;
		peek_ui_preferences_dialog_type_id = peek_ui_preferences_dialog_get_type_once ();
		g_once_init_leave (&peek_ui_preferences_dialog_type_id__once, peek_ui_preferences_dialog_type_id);
	}
	return peek_ui_preferences_dialog_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

