/* WidgetUtils.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from WidgetUtils.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 <gio/gio.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include "deja.h"
#include <glib-object.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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _DejaDupRunErrorDialogData DejaDupRunErrorDialogData;

struct _DejaDupRunErrorDialogData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GtkWidget* parent;
	gchar* header;
	gchar* message;
	AdwAlertDialog* dlg;
	AdwAlertDialog* _tmp0_;
};

static void deja_dup_run_error_dialog_data_free (gpointer _data);
VALA_EXTERN void deja_dup_run_error_dialog (GtkWidget* parent,
                                const gchar* header,
                                const gchar* message,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_);
VALA_EXTERN void deja_dup_run_error_dialog_finish (GAsyncResult* _res_);
static gboolean deja_dup_run_error_dialog_co (DejaDupRunErrorDialogData* _data_);
static void deja_dup_run_error_dialog_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_);
VALA_EXTERN void deja_dup_set_margins (GtkWidget* w,
                           gint margin);
VALA_EXTERN gboolean deja_dup_start_monitor_if_needed (DejaDupFilteredSettings* settings);
VALA_EXTERN void deja_dup_gui_initialize (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static void
deja_dup_run_error_dialog_data_free (gpointer _data)
{
	DejaDupRunErrorDialogData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->parent);
	_g_free0 (_data_->header);
	_g_free0 (_data_->message);
	g_slice_free (DejaDupRunErrorDialogData, _data_);
}

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

void
deja_dup_run_error_dialog (GtkWidget* parent,
                           const gchar* header,
                           const gchar* message,
                           GAsyncReadyCallback _callback_,
                           gpointer _user_data_)
{
	DejaDupRunErrorDialogData* _data_;
	GtkWidget* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (parent != NULL);
	g_return_if_fail (header != NULL);
	g_return_if_fail (message != NULL);
	_data_ = g_slice_new0 (DejaDupRunErrorDialogData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_run_error_dialog_data_free);
	_tmp0_ = _g_object_ref0 (parent);
	_g_object_unref0 (_data_->parent);
	_data_->parent = _tmp0_;
	_tmp1_ = g_strdup (header);
	_g_free0 (_data_->header);
	_data_->header = _tmp1_;
	_tmp2_ = g_strdup (message);
	_g_free0 (_data_->message);
	_data_->message = _tmp2_;
	deja_dup_run_error_dialog_co (_data_);
}

void
deja_dup_run_error_dialog_finish (GAsyncResult* _res_)
{
	DejaDupRunErrorDialogData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
deja_dup_run_error_dialog_ready (GObject* source_object,
                                 GAsyncResult* _res_,
                                 gpointer _user_data_)
{
	DejaDupRunErrorDialogData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_run_error_dialog_co (_data_);
}

static gboolean
deja_dup_run_error_dialog_co (DejaDupRunErrorDialogData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = (AdwAlertDialog*) adw_alert_dialog_new (_data_->header, _data_->message);
	g_object_ref_sink (_data_->_tmp0_);
	_data_->dlg = _data_->_tmp0_;
	adw_alert_dialog_add_response (_data_->dlg, "accept", _ ("_OK"));
	adw_alert_dialog_set_default_response (_data_->dlg, "accept");
	_data_->_state_ = 1;
	adw_alert_dialog_choose (_data_->dlg, _data_->parent, NULL, deja_dup_run_error_dialog_ready, _data_);
	return FALSE;
	_state_1:
	adw_alert_dialog_choose_finish (_data_->dlg, _data_->_res_);
	_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;
}

void
deja_dup_set_margins (GtkWidget* w,
                      gint margin)
{
	g_return_if_fail (w != NULL);
	gtk_widget_set_margin_start (w, margin);
	gtk_widget_set_margin_end (w, margin);
	gtk_widget_set_margin_top (w, margin);
	gtk_widget_set_margin_bottom (w, margin);
}

gboolean
deja_dup_start_monitor_if_needed (DejaDupFilteredSettings* settings)
{
	gboolean result;
	g_return_val_if_fail (settings != NULL, FALSE);
	if (g_settings_get_boolean ((GSettings*) settings, DEJA_DUP_PERIODIC_KEY)) {
		gchar* _tmp0_;
		gchar** _tmp1_;
		gchar** _tmp2_;
		gint _tmp2__length1;
		_tmp0_ = deja_dup_get_monitor_exec ();
		_tmp1_ = g_new0 (gchar*, 1 + 1);
		_tmp1_[0] = _tmp0_;
		_tmp2_ = _tmp1_;
		_tmp2__length1 = 1;
		deja_dup_run_command (_tmp2_, (gint) 1);
		_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	}
	result = G_SOURCE_CONTINUE;
	return result;
}

void
deja_dup_gui_initialize (void)
{
	DejaDupFilteredSettings* settings = NULL;
	DejaDupFilteredSettings* _tmp0_;
	deja_dup_initialize ();
	_tmp0_ = deja_dup_get_settings (NULL);
	settings = _tmp0_;
	g_signal_connect (settings, "changed::" DEJA_DUP_PERIODIC_KEY, (GCallback) deja_dup_start_monitor_if_needed, NULL);
	deja_dup_start_monitor_if_needed (settings);
	g_object_ref ((GObject*) settings);
	_g_object_unref0 (settings);
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

