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

/*
 * Seahorse
 *
 * Copyright (C) 2003 Jacob Perkins
 * Copyright (C) 2004-2005 Stefan Walter
 * Copyright (C) 2011 Collabora Ltd.
 * Copyright (C) 2020 Niels De Graef
 *
 * 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "seahorse-common.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

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

void
seahorse_util_show_error (GtkWidget* parent,
                          const gchar* heading,
                          const gchar* message)
{
	GtkWindow* window = NULL;
	GtkMessageDialog* dialog = NULL;
	GtkWindow* _tmp2_;
	GtkMessageDialog* _tmp3_;
	GtkMessageDialog* _tmp6_;
	GtkMessageDialog* _tmp7_;
	window = NULL;
	if (message == NULL) {
		message = "";
	}
	if (parent != NULL) {
		if (!G_TYPE_CHECK_INSTANCE_TYPE (parent, gtk_window_get_type ())) {
			GtkWidget* _tmp0_;
			_tmp0_ = gtk_widget_get_toplevel (parent);
			parent = _tmp0_;
		}
		if (G_TYPE_CHECK_INSTANCE_TYPE (parent, gtk_window_get_type ())) {
			GtkWindow* _tmp1_;
			_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (parent, gtk_window_get_type (), GtkWindow));
			_g_object_unref0 (window);
			window = _tmp1_;
		}
	}
	_tmp2_ = window;
	_tmp3_ = (GtkMessageDialog*) gtk_message_dialog_new (_tmp2_, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "");
	g_object_ref_sink (_tmp3_);
	dialog = _tmp3_;
	if (heading == NULL) {
		GtkMessageDialog* _tmp4_;
		_tmp4_ = dialog;
		g_object_set ((GObject*) _tmp4_, "text", message, NULL);
	} else {
		GtkMessageDialog* _tmp5_;
		_tmp5_ = dialog;
		g_object_set ((GObject*) _tmp5_, "text", heading, "secondary-text", message, NULL);
	}
	_tmp6_ = dialog;
	gtk_dialog_run ((GtkDialog*) _tmp6_);
	_tmp7_ = dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp7_);
	_g_object_unref0 (dialog);
	_g_object_unref0 (window);
}

void
seahorse_util_toggle_action (GSimpleAction* action,
                             GVariant* variant,
                             void* user_data)
{
	GVariant* old_state = NULL;
	GVariant* _tmp0_;
	GVariant* new_state = NULL;
	GVariant* _tmp1_;
	g_return_if_fail (action != NULL);
	_tmp0_ = g_action_get_state ((GAction*) action);
	old_state = _tmp0_;
	_tmp1_ = g_variant_new_boolean (!g_variant_get_boolean (old_state));
	g_variant_ref_sink (_tmp1_);
	new_state = _tmp1_;
	g_signal_emit_by_name (action, "change-state", new_state);
	_g_variant_unref0 (new_state);
	_g_variant_unref0 (old_state);
}

