/* FolderChooserButton.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from FolderChooserButton.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include "deja.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_FOLDER_CHOOSER_BUTTON (folder_chooser_button_get_type ())
#define FOLDER_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButton))
#define FOLDER_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButtonClass))
#define IS_FOLDER_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOLDER_CHOOSER_BUTTON))
#define IS_FOLDER_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOLDER_CHOOSER_BUTTON))
#define FOLDER_CHOOSER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButtonClass))

typedef struct _FolderChooserButton FolderChooserButton;
typedef struct _FolderChooserButtonClass FolderChooserButtonClass;
typedef struct _FolderChooserButtonPrivate FolderChooserButtonPrivate;
enum  {
	FOLDER_CHOOSER_BUTTON_0_PROPERTY,
	FOLDER_CHOOSER_BUTTON_PATH_PROPERTY,
	FOLDER_CHOOSER_BUTTON_FILE_PROPERTY,
	FOLDER_CHOOSER_BUTTON_NUM_PROPERTIES
};
static GParamSpec* folder_chooser_button_properties[FOLDER_CHOOSER_BUTTON_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _FolderChooserButtonOnClickedAsyncData FolderChooserButtonOnClickedAsyncData;
enum  {
	FOLDER_CHOOSER_BUTTON_FILE_SELECTED_SIGNAL,
	FOLDER_CHOOSER_BUTTON_NUM_SIGNALS
};
static guint folder_chooser_button_signals[FOLDER_CHOOSER_BUTTON_NUM_SIGNALS] = {0};

struct _FolderChooserButton {
	GtkButton parent_instance;
	FolderChooserButtonPrivate * priv;
};

struct _FolderChooserButtonClass {
	GtkButtonClass parent_class;
};

struct _FolderChooserButtonPrivate {
	gchar* _path;
	GFile* _file;
};

struct _FolderChooserButtonOnClickedAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FolderChooserButton* self;
	GtkFileDialog* dlg;
	GtkFileDialog* _tmp0_;
	GFile* folder;
	GtkRoot* _tmp1_;
	GtkRoot* _tmp2_;
	GFile* _tmp3_;
	GError* _inner_error0_;
};

static gint FolderChooserButton_private_offset;
static gpointer folder_chooser_button_parent_class = NULL;

VALA_EXTERN GType folder_chooser_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FolderChooserButton, g_object_unref)
static void folder_chooser_button_on_clicked (FolderChooserButton* self);
static void folder_chooser_button_on_clicked_async (FolderChooserButton* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void folder_chooser_button_on_clicked_finish (FolderChooserButton* self,
                                              GAsyncResult* _res_);
static void folder_chooser_button_on_clicked_async_data_free (gpointer _data);
static gboolean folder_chooser_button_on_clicked_async_co (FolderChooserButtonOnClickedAsyncData* _data_);
static void folder_chooser_button_on_clicked_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void folder_chooser_button_on_dialog_response (FolderChooserButton* self,
                                               GFile* folder);
static void folder_chooser_button_set_path (FolderChooserButton* self,
                                     const gchar* value);
static void folder_chooser_button_set_file (FolderChooserButton* self,
                                     GFile* value);
VALA_EXTERN FolderChooserButton* folder_chooser_button_new (void);
VALA_EXTERN FolderChooserButton* folder_chooser_button_construct (GType object_type);
VALA_EXTERN const gchar* folder_chooser_button_get_path (FolderChooserButton* self);
VALA_EXTERN GFile* folder_chooser_button_get_file (FolderChooserButton* self);
static GObject * folder_chooser_button_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static void _folder_chooser_button_on_clicked_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self);
static void folder_chooser_button_finalize (GObject * obj);
static GType folder_chooser_button_get_type_once (void);
static void _vala_folder_chooser_button_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_folder_chooser_button_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);

static inline gpointer
folder_chooser_button_get_instance_private (FolderChooserButton* self)
{
	return G_STRUCT_MEMBER_P (self, FolderChooserButton_private_offset);
}

static void
folder_chooser_button_on_clicked (FolderChooserButton* self)
{
	g_return_if_fail (self != NULL);
	folder_chooser_button_on_clicked_async (self, NULL, NULL);
}

static void
folder_chooser_button_on_clicked_async_data_free (gpointer _data)
{
	FolderChooserButtonOnClickedAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FolderChooserButtonOnClickedAsyncData, _data_);
}

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

static void
folder_chooser_button_on_clicked_async (FolderChooserButton* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	FolderChooserButtonOnClickedAsyncData* _data_;
	FolderChooserButton* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FolderChooserButtonOnClickedAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, folder_chooser_button_on_clicked_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	folder_chooser_button_on_clicked_async_co (_data_);
}

static void
folder_chooser_button_on_clicked_finish (FolderChooserButton* self,
                                         GAsyncResult* _res_)
{
	FolderChooserButtonOnClickedAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
folder_chooser_button_on_clicked_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	FolderChooserButtonOnClickedAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	folder_chooser_button_on_clicked_async_co (_data_);
}

static gboolean
folder_chooser_button_on_clicked_async_co (FolderChooserButtonOnClickedAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gtk_file_dialog_new ();
	_data_->dlg = _data_->_tmp0_;
	gtk_file_dialog_set_modal (_data_->dlg, TRUE);
	{
		_data_->_tmp1_ = gtk_widget_get_root ((GtkWidget*) _data_->self);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_state_ = 1;
		gtk_file_dialog_select_folder (_data_->dlg, G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp2_, gtk_window_get_type ()) ? ((GtkWindow*) _data_->_tmp2_) : NULL, NULL, folder_chooser_button_on_clicked_async_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp3_ = gtk_file_dialog_select_folder_finish (_data_->dlg, _data_->_res_, &_data_->_inner_error0_);
		_data_->folder = _data_->_tmp3_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		folder_chooser_button_on_dialog_response (_data_->self, _data_->folder);
		_g_object_unref0 (_data_->folder);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->dlg);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_g_object_unref0 (_data_->dlg);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
folder_chooser_button_on_dialog_response (FolderChooserButton* self,
                                          GFile* folder)
{
	gchar* dlg_path = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (folder != NULL);
	_tmp0_ = deja_dup_backend_local_get_path_from_file (folder);
	dlg_path = _tmp0_;
	_tmp1_ = dlg_path;
	if (_tmp1_ != NULL) {
		const gchar* _tmp2_;
		_tmp2_ = dlg_path;
		folder_chooser_button_set_path (self, _tmp2_);
		folder_chooser_button_set_file (self, folder);
		g_signal_emit (self, folder_chooser_button_signals[FOLDER_CHOOSER_BUTTON_FILE_SELECTED_SIGNAL], 0);
	}
	_g_free0 (dlg_path);
}

FolderChooserButton*
folder_chooser_button_construct (GType object_type)
{
	FolderChooserButton * self = NULL;
	self = (FolderChooserButton*) g_object_new (object_type, NULL);
	return self;
}

FolderChooserButton*
folder_chooser_button_new (void)
{
	return folder_chooser_button_construct (TYPE_FOLDER_CHOOSER_BUTTON);
}

const gchar*
folder_chooser_button_get_path (FolderChooserButton* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}

static void
folder_chooser_button_set_path (FolderChooserButton* self,
                                const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = folder_chooser_button_get_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_path);
		self->priv->_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, folder_chooser_button_properties[FOLDER_CHOOSER_BUTTON_PATH_PROPERTY]);
	}
}

GFile*
folder_chooser_button_get_file (FolderChooserButton* self)
{
	GFile* result;
	GFile* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_file;
	result = _tmp0_;
	return result;
}

static void
folder_chooser_button_set_file (FolderChooserButton* self,
                                GFile* value)
{
	GFile* old_value;
	g_return_if_fail (self != NULL);
	old_value = folder_chooser_button_get_file (self);
	if (old_value != value) {
		GFile* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_file);
		self->priv->_file = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, folder_chooser_button_properties[FOLDER_CHOOSER_BUTTON_FILE_PROPERTY]);
	}
}

static void
_folder_chooser_button_on_clicked_gtk_button_clicked (GtkButton* _sender,
                                                      gpointer self)
{
	folder_chooser_button_on_clicked ((FolderChooserButton*) self);
}

static GObject *
folder_chooser_button_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FolderChooserButton * self;
	parent_class = G_OBJECT_CLASS (folder_chooser_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButton);
	gtk_button_set_icon_name ((GtkButton*) self, "document-open-symbolic");
	gtk_widget_set_receives_default ((GtkWidget*) self, TRUE);
	gtk_button_set_use_underline ((GtkButton*) self, TRUE);
	gtk_accessible_update_property ((GtkAccessible*) self, GTK_ACCESSIBLE_PROPERTY_LABEL, _ ("Choose Folder"), -1);
	g_signal_connect_object ((GtkButton*) self, "clicked", (GCallback) _folder_chooser_button_on_clicked_gtk_button_clicked, self, 0);
	return obj;
}

static void
folder_chooser_button_class_init (FolderChooserButtonClass * klass,
                                  gpointer klass_data)
{
	folder_chooser_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FolderChooserButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_folder_chooser_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_folder_chooser_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = folder_chooser_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = folder_chooser_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLDER_CHOOSER_BUTTON_PATH_PROPERTY, folder_chooser_button_properties[FOLDER_CHOOSER_BUTTON_PATH_PROPERTY] = g_param_spec_string ("path", "path", "path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLDER_CHOOSER_BUTTON_FILE_PROPERTY, folder_chooser_button_properties[FOLDER_CHOOSER_BUTTON_FILE_PROPERTY] = g_param_spec_object ("file", "file", "file", g_file_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	folder_chooser_button_signals[FOLDER_CHOOSER_BUTTON_FILE_SELECTED_SIGNAL] = g_signal_new ("file-selected", TYPE_FOLDER_CHOOSER_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
folder_chooser_button_instance_init (FolderChooserButton * self,
                                     gpointer klass)
{
	self->priv = folder_chooser_button_get_instance_private (self);
}

static void
folder_chooser_button_finalize (GObject * obj)
{
	FolderChooserButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButton);
	_g_free0 (self->priv->_path);
	_g_object_unref0 (self->priv->_file);
	G_OBJECT_CLASS (folder_chooser_button_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
folder_chooser_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FolderChooserButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folder_chooser_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolderChooserButton), 0, (GInstanceInitFunc) folder_chooser_button_instance_init, NULL };
	GType folder_chooser_button_type_id;
	folder_chooser_button_type_id = g_type_register_static (gtk_button_get_type (), "FolderChooserButton", &g_define_type_info, 0);
	FolderChooserButton_private_offset = g_type_add_instance_private (folder_chooser_button_type_id, sizeof (FolderChooserButtonPrivate));
	return folder_chooser_button_type_id;
}

GType
folder_chooser_button_get_type (void)
{
	static gsize folder_chooser_button_type_id__once = 0;
	if (g_once_init_enter (&folder_chooser_button_type_id__once)) {
		GType folder_chooser_button_type_id;
		folder_chooser_button_type_id = folder_chooser_button_get_type_once ();
		g_once_init_leave (&folder_chooser_button_type_id__once, folder_chooser_button_type_id);
	}
	return folder_chooser_button_type_id__once;
}

static void
_vala_folder_chooser_button_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	FolderChooserButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButton);
	switch (property_id) {
		case FOLDER_CHOOSER_BUTTON_PATH_PROPERTY:
		g_value_set_string (value, folder_chooser_button_get_path (self));
		break;
		case FOLDER_CHOOSER_BUTTON_FILE_PROPERTY:
		g_value_set_object (value, folder_chooser_button_get_file (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_folder_chooser_button_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	FolderChooserButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOLDER_CHOOSER_BUTTON, FolderChooserButton);
	switch (property_id) {
		case FOLDER_CHOOSER_BUTTON_PATH_PROPERTY:
		folder_chooser_button_set_path (self, g_value_get_string (value));
		break;
		case FOLDER_CHOOSER_BUTTON_FILE_PROPERTY:
		folder_chooser_button_set_file (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

