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

/*
 * Copyright 2024 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

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

#define GALA_DAEMON_BACKGROUND_MENU_ACTION_GROUP_PREFIX "background-menu"
#define GALA_DAEMON_BACKGROUND_MENU_ACTION_PREFIX GALA_DAEMON_BACKGROUND_MENU_ACTION_GROUP_PREFIX "."
#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 GALA_DAEMON_TYPE_BACKGROUND_MENU (gala_daemon_background_menu_get_type ())
#define GALA_DAEMON_BACKGROUND_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_BACKGROUND_MENU, GalaDaemonBackgroundMenu))
#define GALA_DAEMON_BACKGROUND_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_BACKGROUND_MENU, GalaDaemonBackgroundMenuClass))
#define GALA_DAEMON_IS_BACKGROUND_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_BACKGROUND_MENU))
#define GALA_DAEMON_IS_BACKGROUND_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_BACKGROUND_MENU))
#define GALA_DAEMON_BACKGROUND_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_BACKGROUND_MENU, GalaDaemonBackgroundMenuClass))

typedef struct _GalaDaemonBackgroundMenu GalaDaemonBackgroundMenu;
typedef struct _GalaDaemonBackgroundMenuClass GalaDaemonBackgroundMenuClass;
typedef struct _GalaDaemonBackgroundMenuPrivate GalaDaemonBackgroundMenuPrivate;
enum  {
	GALA_DAEMON_BACKGROUND_MENU_0_PROPERTY,
	GALA_DAEMON_BACKGROUND_MENU_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_background_menu_properties[GALA_DAEMON_BACKGROUND_MENU_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_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 _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

struct _GalaDaemonBackgroundMenu {
	GtkMenu parent_instance;
	GalaDaemonBackgroundMenuPrivate * priv;
};

struct _GalaDaemonBackgroundMenuClass {
	GtkMenuClass parent_class;
};

static gpointer gala_daemon_background_menu_parent_class = NULL;

VALA_EXTERN GType gala_daemon_background_menu_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonBackgroundMenu, g_object_unref)
static void gala_daemon_background_menu_action_launch (GalaDaemonBackgroundMenu* self,
                                                GSimpleAction* action,
                                                GVariant* variant);
static void _gtk_widget_destroy_gtk_dialog_response (GtkDialog* _sender,
                                              gint response_id,
                                              gpointer self);
VALA_EXTERN GalaDaemonBackgroundMenu* gala_daemon_background_menu_new (void);
VALA_EXTERN GalaDaemonBackgroundMenu* gala_daemon_background_menu_construct (GType object_type);
static GObject * gala_daemon_background_menu_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _gala_daemon_background_menu_action_launch_g_simple_action_activate (GSimpleAction* _sender,
                                                                          GVariant* parameter,
                                                                          gpointer self);
static GType gala_daemon_background_menu_get_type_once (void);

static void
_gtk_widget_destroy_gtk_dialog_response (GtkDialog* _sender,
                                         gint response_id,
                                         gpointer self)
{
	gtk_widget_destroy ((GtkWidget*) self);
}

static void
gala_daemon_background_menu_action_launch (GalaDaemonBackgroundMenu* self,
                                           GSimpleAction* action,
                                           GVariant* variant)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	{
		const gchar* _tmp0_;
		_tmp0_ = g_variant_get_string (variant, NULL);
		g_app_info_launch_default_for_uri (_tmp0_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GraniteMessageDialog* message_dialog = NULL;
		GraniteMessageDialog* _tmp1_;
		GraniteMessageDialog* _tmp2_;
		GError* _tmp3_;
		const gchar* _tmp4_;
		GraniteMessageDialog* _tmp5_;
		GraniteMessageDialog* _tmp6_;
		GraniteMessageDialog* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp1_ = granite_message_dialog_new_with_image_from_icon_name (_ ("Failed to open System Settings"), _ ("A handler for the “settings://” URI scheme must be installed."), "dialog-error", GTK_BUTTONS_CLOSE);
		g_object_ref_sink (_tmp1_);
		message_dialog = _tmp1_;
		_tmp2_ = message_dialog;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		granite_message_dialog_show_error_details (_tmp2_, _tmp4_);
		_tmp5_ = message_dialog;
		gtk_window_present ((GtkWindow*) _tmp5_);
		_tmp6_ = message_dialog;
		_tmp7_ = message_dialog;
		g_signal_connect_object ((GtkDialog*) _tmp6_, "response", (GCallback) _gtk_widget_destroy_gtk_dialog_response, (GtkWidget*) _tmp7_, 0);
		_g_object_unref0 (message_dialog);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

GalaDaemonBackgroundMenu*
gala_daemon_background_menu_construct (GType object_type)
{
	GalaDaemonBackgroundMenu * self = NULL;
	self = (GalaDaemonBackgroundMenu*) g_object_new (object_type, NULL);
	return self;
}

GalaDaemonBackgroundMenu*
gala_daemon_background_menu_new (void)
{
	return gala_daemon_background_menu_construct (GALA_DAEMON_TYPE_BACKGROUND_MENU);
}

static void
_gala_daemon_background_menu_action_launch_g_simple_action_activate (GSimpleAction* _sender,
                                                                     GVariant* parameter,
                                                                     gpointer self)
{
	gala_daemon_background_menu_action_launch ((GalaDaemonBackgroundMenu*) self, _sender, parameter);
}

static GObject *
gala_daemon_background_menu_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonBackgroundMenu * self;
	GtkMenuItem* change_wallpaper = NULL;
	gchar* _tmp0_;
	GVariant* _tmp1_;
	GtkMenuItem* _tmp2_ = NULL;
	GtkMenuItem* display_settings = NULL;
	gchar* _tmp3_;
	GVariant* _tmp4_;
	GtkMenuItem* _tmp5_ = NULL;
	GtkMenuItem* system_settings = NULL;
	gchar* _tmp6_;
	GVariant* _tmp7_;
	GtkMenuItem* _tmp8_ = NULL;
	GtkMenuItem* _tmp9_;
	GtkMenuItem* _tmp10_;
	GtkSeparatorMenuItem* _tmp11_;
	GtkSeparatorMenuItem* _tmp12_;
	GtkMenuItem* _tmp13_;
	GSimpleAction* launch_action = NULL;
	const GVariantType* _tmp14_;
	GSimpleAction* _tmp15_;
	GSimpleAction* _tmp16_;
	GSimpleActionGroup* action_group = NULL;
	GSimpleActionGroup* _tmp17_;
	GSimpleActionGroup* _tmp18_;
	GSimpleAction* _tmp19_;
	GSimpleActionGroup* _tmp20_;
	parent_class = G_OBJECT_CLASS (gala_daemon_background_menu_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_BACKGROUND_MENU, GalaDaemonBackgroundMenu);
	_tmp0_ = g_strdup (GALA_DAEMON_BACKGROUND_MENU_ACTION_PREFIX "launch-uri");
	_tmp1_ = g_variant_new_string ("settings://desktop/appearance/wallpaper");
	g_variant_ref_sink (_tmp1_);
	_tmp2_ = (GtkMenuItem*) gtk_menu_item_new_with_label (_ ("Change Wallpaper…"));
	gtk_actionable_set_action_name ((GtkActionable*) _tmp2_, _tmp0_);
	_g_free0 (_tmp0_);
	g_object_set ((GtkActionable*) _tmp2_, "action-target", _tmp1_, NULL);
	_g_variant_unref0 (_tmp1_);
	g_object_ref_sink (_tmp2_);
	change_wallpaper = _tmp2_;
	_tmp3_ = g_strdup (GALA_DAEMON_BACKGROUND_MENU_ACTION_PREFIX "launch-uri");
	_tmp4_ = g_variant_new_string ("settings://display");
	g_variant_ref_sink (_tmp4_);
	_tmp5_ = (GtkMenuItem*) gtk_menu_item_new_with_label (_ ("Display Settings…"));
	gtk_actionable_set_action_name ((GtkActionable*) _tmp5_, _tmp3_);
	_g_free0 (_tmp3_);
	g_object_set ((GtkActionable*) _tmp5_, "action-target", _tmp4_, NULL);
	_g_variant_unref0 (_tmp4_);
	g_object_ref_sink (_tmp5_);
	display_settings = _tmp5_;
	_tmp6_ = g_strdup (GALA_DAEMON_BACKGROUND_MENU_ACTION_PREFIX "launch-uri");
	_tmp7_ = g_variant_new_string ("settings://");
	g_variant_ref_sink (_tmp7_);
	_tmp8_ = (GtkMenuItem*) gtk_menu_item_new_with_label (_ ("System Settings…"));
	gtk_actionable_set_action_name ((GtkActionable*) _tmp8_, _tmp6_);
	_g_free0 (_tmp6_);
	g_object_set ((GtkActionable*) _tmp8_, "action-target", _tmp7_, NULL);
	_g_variant_unref0 (_tmp7_);
	g_object_ref_sink (_tmp8_);
	system_settings = _tmp8_;
	_tmp9_ = change_wallpaper;
	gtk_menu_shell_append ((GtkMenuShell*) self, _tmp9_);
	_tmp10_ = display_settings;
	gtk_menu_shell_append ((GtkMenuShell*) self, _tmp10_);
	_tmp11_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new ();
	g_object_ref_sink (_tmp11_);
	_tmp12_ = _tmp11_;
	gtk_menu_shell_append ((GtkMenuShell*) self, (GtkMenuItem*) _tmp12_);
	_g_object_unref0 (_tmp12_);
	_tmp13_ = system_settings;
	gtk_menu_shell_append ((GtkMenuShell*) self, _tmp13_);
	gtk_widget_show_all ((GtkWidget*) self);
	_tmp14_ = G_VARIANT_TYPE_STRING;
	_tmp15_ = g_simple_action_new ("launch-uri", _tmp14_);
	launch_action = _tmp15_;
	_tmp16_ = launch_action;
	g_signal_connect_object (_tmp16_, "activate", (GCallback) _gala_daemon_background_menu_action_launch_g_simple_action_activate, self, 0);
	_tmp17_ = g_simple_action_group_new ();
	action_group = _tmp17_;
	_tmp18_ = action_group;
	_tmp19_ = launch_action;
	g_action_map_add_action ((GActionMap*) _tmp18_, (GAction*) _tmp19_);
	_tmp20_ = action_group;
	gtk_widget_insert_action_group ((GtkWidget*) self, GALA_DAEMON_BACKGROUND_MENU_ACTION_GROUP_PREFIX, (GActionGroup*) _tmp20_);
	_g_object_unref0 (action_group);
	_g_object_unref0 (launch_action);
	_g_object_unref0 (system_settings);
	_g_object_unref0 (display_settings);
	_g_object_unref0 (change_wallpaper);
	return obj;
}

static void
gala_daemon_background_menu_class_init (GalaDaemonBackgroundMenuClass * klass,
                                        gpointer klass_data)
{
	gala_daemon_background_menu_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_background_menu_constructor;
}

static void
gala_daemon_background_menu_instance_init (GalaDaemonBackgroundMenu * self,
                                           gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
gala_daemon_background_menu_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonBackgroundMenuClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_background_menu_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonBackgroundMenu), 0, (GInstanceInitFunc) gala_daemon_background_menu_instance_init, NULL };
	GType gala_daemon_background_menu_type_id;
	gala_daemon_background_menu_type_id = g_type_register_static (gtk_menu_get_type (), "GalaDaemonBackgroundMenu", &g_define_type_info, 0);
	return gala_daemon_background_menu_type_id;
}

GType
gala_daemon_background_menu_get_type (void)
{
	static gsize gala_daemon_background_menu_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_background_menu_type_id__once)) {
		GType gala_daemon_background_menu_type_id;
		gala_daemon_background_menu_type_id = gala_daemon_background_menu_get_type_once ();
		g_once_init_leave (&gala_daemon_background_menu_type_id__once, gala_daemon_background_menu_type_id);
	}
	return gala_daemon_background_menu_type_id__once;
}

