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

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2011-2026 elementary, Inc. (https://elementary.io)
 *
 * Authored by: Maxwell Barvian
 *              Corentin Noël <corentin@elementaryos.org>
 */

#include <libecal/libecal.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <handy.h>
#include <glib/gi18n-lib.h>
#include <libedataserver/libedataserver.h>
#include "elementary-calendar.h"
#include <granite.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)))
typedef struct _Block31Data Block31Data;

#define MAYA_TYPE_APPLICATION (maya_application_get_type ())
#define MAYA_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAYA_TYPE_APPLICATION, MayaApplication))
#define MAYA_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAYA_TYPE_APPLICATION, MayaApplicationClass))
#define MAYA_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAYA_TYPE_APPLICATION))
#define MAYA_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAYA_TYPE_APPLICATION))
#define MAYA_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAYA_TYPE_APPLICATION, MayaApplicationClass))

typedef struct _MayaApplication MayaApplication;
typedef struct _MayaApplicationClass MayaApplicationClass;
typedef struct _MayaApplicationPrivate MayaApplicationPrivate;

#define MAYA_TYPE_MAIN_WINDOW (maya_main_window_get_type ())
#define MAYA_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAYA_TYPE_MAIN_WINDOW, MayaMainWindow))
#define MAYA_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MAYA_TYPE_MAIN_WINDOW, MayaMainWindowClass))
#define MAYA_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MAYA_TYPE_MAIN_WINDOW))
#define MAYA_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MAYA_TYPE_MAIN_WINDOW))
#define MAYA_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MAYA_TYPE_MAIN_WINDOW, MayaMainWindowClass))

typedef struct _MayaMainWindow MayaMainWindow;
typedef struct _MayaMainWindowClass MayaMainWindowClass;

#define CALENDAR_TYPE_DELETE_EVENT_DIALOG (calendar_delete_event_dialog_get_type ())
#define CALENDAR_DELETE_EVENT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALENDAR_TYPE_DELETE_EVENT_DIALOG, CalendarDeleteEventDialog))
#define CALENDAR_DELETE_EVENT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALENDAR_TYPE_DELETE_EVENT_DIALOG, CalendarDeleteEventDialogClass))
#define CALENDAR_IS_DELETE_EVENT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALENDAR_TYPE_DELETE_EVENT_DIALOG))
#define CALENDAR_IS_DELETE_EVENT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALENDAR_TYPE_DELETE_EVENT_DIALOG))
#define CALENDAR_DELETE_EVENT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CALENDAR_TYPE_DELETE_EVENT_DIALOG, CalendarDeleteEventDialogClass))

typedef struct _CalendarDeleteEventDialog CalendarDeleteEventDialog;
typedef struct _CalendarDeleteEventDialogClass CalendarDeleteEventDialogClass;

struct _Block31Data {
	int _ref_count_;
	ECalComponent* comp;
};

struct _MayaApplication {
	GtkApplication parent_instance;
	MayaApplicationPrivate * priv;
	MayaMainWindow* window;
};

struct _MayaApplicationClass {
	GtkApplicationClass parent_class;
};

VALA_EXTERN GtkMenu* maya_event_menu_build (ECalComponent* comp);
static Block31Data* block31_data_ref (Block31Data* _data31_);
static void block31_data_unref (void * _userdata_);
static void __lambda4_ (Block31Data* _data31_);
VALA_EXTERN GType maya_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MayaApplication, g_object_unref)
VALA_EXTERN GType maya_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MayaMainWindow, g_object_unref)
VALA_EXTERN void maya_main_window_on_modified (MayaMainWindow* self,
                                   ECalComponent* comp);
static void ___lambda4__g_simple_action_activate (GSimpleAction* _sender,
                                           GVariant* parameter,
                                           gpointer self);
static void __lambda192_ (Block31Data* _data31_);
VALA_EXTERN void maya_main_window_on_duplicated (MayaMainWindow* self,
                                     ECalComponent* comp);
static void ___lambda192__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda193_ (Block31Data* _data31_);
VALA_EXTERN void maya_event_menu_remove_event (ECalComponent* comp);
static void ___lambda193__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
static void __lambda194_ (Block31Data* _data31_);
VALA_EXTERN void maya_event_menu_add_exception (ECalComponent* comp);
static void ___lambda194__g_simple_action_activate (GSimpleAction* _sender,
                                             GVariant* parameter,
                                             gpointer self);
VALA_EXTERN GType calendar_delete_event_dialog_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CalendarDeleteEventDialog, g_object_unref)
VALA_EXTERN CalendarDeleteEventDialog* calendar_delete_event_dialog_new (ESource* source,
                                                             ECalComponent* ecal_event,
                                                             ECalObjModType mod_type_prop);
VALA_EXTERN CalendarDeleteEventDialog* calendar_delete_event_dialog_construct (GType object_type,
                                                                   ESource* source,
                                                                   ECalComponent* ecal_event,
                                                                   ECalObjModType mod_type_prop);

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

static Block31Data*
block31_data_ref (Block31Data* _data31_)
{
	g_atomic_int_inc (&_data31_->_ref_count_);
	return _data31_;
}

static void
block31_data_unref (void * _userdata_)
{
	Block31Data* _data31_;
	_data31_ = (Block31Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data31_->_ref_count_)) {
		_g_object_unref0 (_data31_->comp);
		g_slice_free (Block31Data, _data31_);
	}
}

static void
__lambda4_ (Block31Data* _data31_)
{
	GApplication* _tmp0_;
	MayaMainWindow* _tmp1_;
	_tmp0_ = g_application_get_default ();
	_tmp1_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, MAYA_TYPE_APPLICATION, MayaApplication)->window;
	maya_main_window_on_modified (_tmp1_, _data31_->comp);
}

static void
___lambda4__g_simple_action_activate (GSimpleAction* _sender,
                                      GVariant* parameter,
                                      gpointer self)
{
	__lambda4_ (self);
}

static void
__lambda192_ (Block31Data* _data31_)
{
	GApplication* _tmp0_;
	MayaMainWindow* _tmp1_;
	_tmp0_ = g_application_get_default ();
	_tmp1_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, MAYA_TYPE_APPLICATION, MayaApplication)->window;
	maya_main_window_on_duplicated (_tmp1_, _data31_->comp);
}

static void
___lambda192__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda192_ (self);
}

static void
__lambda193_ (Block31Data* _data31_)
{
	maya_event_menu_remove_event (_data31_->comp);
}

static void
___lambda193__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda193_ (self);
}

static void
__lambda194_ (Block31Data* _data31_)
{
	maya_event_menu_add_exception (_data31_->comp);
}

static void
___lambda194__g_simple_action_activate (GSimpleAction* _sender,
                                        GVariant* parameter,
                                        gpointer self)
{
	__lambda194_ (self);
}

GtkMenu*
maya_event_menu_build (ECalComponent* comp)
{
	Block31Data* _data31_;
	ECalComponent* _tmp0_;
	GSimpleAction* action_edit = NULL;
	GSimpleAction* _tmp1_;
	GSimpleAction* _tmp2_;
	GSimpleAction* action_duplicate = NULL;
	GSimpleAction* _tmp3_;
	GSimpleAction* _tmp4_;
	GSimpleAction* action_remove = NULL;
	GSimpleAction* _tmp5_;
	GSimpleAction* _tmp6_;
	GSimpleAction* action_add_exception = NULL;
	GSimpleAction* _tmp7_;
	GSimpleAction* _tmp8_;
	GSimpleActionGroup* action_group = NULL;
	GSimpleActionGroup* _tmp9_;
	GSimpleActionGroup* _tmp10_;
	GSimpleAction* _tmp11_;
	GSimpleActionGroup* _tmp12_;
	GSimpleAction* _tmp13_;
	GSimpleActionGroup* _tmp14_;
	GSimpleAction* _tmp15_;
	GSimpleActionGroup* _tmp16_;
	GSimpleAction* _tmp17_;
	GMenu* menu_model = NULL;
	GMenu* _tmp18_;
	GMenu* _tmp19_;
	GMenu* _tmp20_;
	GtkMenu* menu = NULL;
	GMenu* _tmp24_;
	GtkMenu* _tmp25_;
	GtkMenu* _tmp26_;
	GSimpleActionGroup* _tmp27_;
	ESource* src = NULL;
	gconstpointer _tmp28_;
	ESource* _tmp29_;
	gboolean _tmp30_ = FALSE;
	ESource* _tmp31_;
	gboolean _tmp32_;
	gboolean _tmp33_;
	gboolean sensitive = FALSE;
	GSimpleAction* _tmp37_;
	GSimpleAction* _tmp38_;
	GSimpleAction* _tmp39_;
	GSimpleAction* _tmp40_;
	GtkMenu* result;
	g_return_val_if_fail (comp != NULL, NULL);
	_data31_ = g_slice_new0 (Block31Data);
	_data31_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (comp);
	_g_object_unref0 (_data31_->comp);
	_data31_->comp = _tmp0_;
	_tmp1_ = g_simple_action_new ("edit", NULL);
	action_edit = _tmp1_;
	_tmp2_ = action_edit;
	g_signal_connect_data (_tmp2_, "activate", (GCallback) ___lambda4__g_simple_action_activate, block31_data_ref (_data31_), (GClosureNotify) block31_data_unref, 0);
	_tmp3_ = g_simple_action_new ("duplicate", NULL);
	action_duplicate = _tmp3_;
	_tmp4_ = action_duplicate;
	g_signal_connect_data (_tmp4_, "activate", (GCallback) ___lambda192__g_simple_action_activate, block31_data_ref (_data31_), (GClosureNotify) block31_data_unref, 0);
	_tmp5_ = g_simple_action_new ("remove", NULL);
	action_remove = _tmp5_;
	_tmp6_ = action_remove;
	g_signal_connect_data (_tmp6_, "activate", (GCallback) ___lambda193__g_simple_action_activate, block31_data_ref (_data31_), (GClosureNotify) block31_data_unref, 0);
	_tmp7_ = g_simple_action_new ("add-exception", NULL);
	action_add_exception = _tmp7_;
	_tmp8_ = action_add_exception;
	g_signal_connect_data (_tmp8_, "activate", (GCallback) ___lambda194__g_simple_action_activate, block31_data_ref (_data31_), (GClosureNotify) block31_data_unref, 0);
	_tmp9_ = g_simple_action_group_new ();
	action_group = _tmp9_;
	_tmp10_ = action_group;
	_tmp11_ = action_edit;
	g_action_map_add_action ((GActionMap*) _tmp10_, (GAction*) _tmp11_);
	_tmp12_ = action_group;
	_tmp13_ = action_duplicate;
	g_action_map_add_action ((GActionMap*) _tmp12_, (GAction*) _tmp13_);
	_tmp14_ = action_group;
	_tmp15_ = action_remove;
	g_action_map_add_action ((GActionMap*) _tmp14_, (GAction*) _tmp15_);
	_tmp16_ = action_group;
	_tmp17_ = action_add_exception;
	g_action_map_add_action ((GActionMap*) _tmp16_, (GAction*) _tmp17_);
	_tmp18_ = g_menu_new ();
	menu_model = _tmp18_;
	_tmp19_ = menu_model;
	g_menu_append (_tmp19_, _ ("Edit…"), "event.edit");
	_tmp20_ = menu_model;
	g_menu_append (_tmp20_, _ ("Duplicate…"), "event.duplicate");
	if (e_cal_component_has_recurrences (_data31_->comp)) {
		GMenu* _tmp21_;
		GMenu* _tmp22_;
		_tmp21_ = menu_model;
		g_menu_prepend (_tmp21_, _ ("Remove Event"), "event.remove");
		_tmp22_ = menu_model;
		g_menu_insert (_tmp22_, 1, _ ("Remove Occurrence"), "event.add-exception");
	} else {
		GMenu* _tmp23_;
		_tmp23_ = menu_model;
		g_menu_prepend (_tmp23_, _ ("Remove"), "event.remove");
	}
	_tmp24_ = menu_model;
	_tmp25_ = (GtkMenu*) gtk_menu_new_from_model ((GMenuModel*) _tmp24_);
	g_object_ref_sink (_tmp25_);
	menu = _tmp25_;
	_tmp26_ = menu;
	_tmp27_ = action_group;
	gtk_widget_insert_action_group ((GtkWidget*) _tmp26_, "event", (GActionGroup*) _tmp27_);
	_tmp28_ = g_object_get_data ((GObject*) _data31_->comp, "source");
	_tmp29_ = _g_object_ref0 ((ESource*) _tmp28_);
	src = _tmp29_;
	_tmp31_ = src;
	_tmp32_ = e_source_get_writable (_tmp31_);
	_tmp33_ = _tmp32_;
	if (_tmp33_) {
		CalendarEventStore* _tmp34_;
		CalendarEventStore* _tmp35_;
		ESource* _tmp36_;
		_tmp34_ = calendar_event_store_get_default ();
		_tmp35_ = _tmp34_;
		_tmp36_ = src;
		_tmp30_ = !calendar_event_store_calclient_is_readonly (_tmp35_, _tmp36_);
		_g_object_unref0 (_tmp35_);
	} else {
		_tmp30_ = FALSE;
	}
	sensitive = _tmp30_;
	_tmp37_ = action_edit;
	g_simple_action_set_enabled (_tmp37_, sensitive);
	_tmp38_ = action_duplicate;
	g_simple_action_set_enabled (_tmp38_, sensitive);
	_tmp39_ = action_remove;
	g_simple_action_set_enabled (_tmp39_, sensitive);
	_tmp40_ = action_add_exception;
	g_simple_action_set_enabled (_tmp40_, sensitive);
	result = menu;
	_g_object_unref0 (src);
	_g_object_unref0 (menu_model);
	_g_object_unref0 (action_group);
	_g_object_unref0 (action_add_exception);
	_g_object_unref0 (action_remove);
	_g_object_unref0 (action_duplicate);
	_g_object_unref0 (action_edit);
	block31_data_unref (_data31_);
	_data31_ = NULL;
	return result;
}

void
maya_event_menu_remove_event (ECalComponent* comp)
{
	GtkApplication* application = NULL;
	GApplication* _tmp0_;
	GtkApplication* _tmp1_;
	ESource* source = NULL;
	gconstpointer _tmp2_;
	ESource* _tmp3_;
	CalendarDeleteEventDialog* delete_dialog = NULL;
	GtkWindow* _tmp4_;
	GtkWindow* _tmp5_;
	GtkWindow* _tmp6_;
	CalendarDeleteEventDialog* _tmp7_ = NULL;
	g_return_if_fail (comp != NULL);
	_tmp0_ = g_application_get_default ();
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_application_get_type (), GtkApplication));
	application = _tmp1_;
	_tmp2_ = g_object_get_data ((GObject*) comp, "source");
	_tmp3_ = _g_object_ref0 ((ESource*) _tmp2_);
	source = _tmp3_;
	_tmp4_ = gtk_application_get_active_window (application);
	_tmp5_ = _tmp4_;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_tmp7_ = calendar_delete_event_dialog_new (source, comp, E_CAL_OBJ_MOD_ALL);
	gtk_window_set_transient_for ((GtkWindow*) _tmp7_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	delete_dialog = _tmp7_;
	gtk_window_present ((GtkWindow*) delete_dialog);
	_g_object_unref0 (delete_dialog);
	_g_object_unref0 (source);
	_g_object_unref0 (application);
}

void
maya_event_menu_add_exception (ECalComponent* comp)
{
	GtkApplication* application = NULL;
	GApplication* _tmp0_;
	GtkApplication* _tmp1_;
	ESource* source = NULL;
	gconstpointer _tmp2_;
	ESource* _tmp3_;
	CalendarDeleteEventDialog* delete_dialog = NULL;
	GtkWindow* _tmp4_;
	GtkWindow* _tmp5_;
	GtkWindow* _tmp6_;
	CalendarDeleteEventDialog* _tmp7_ = NULL;
	g_return_if_fail (comp != NULL);
	_tmp0_ = g_application_get_default ();
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_application_get_type (), GtkApplication));
	application = _tmp1_;
	_tmp2_ = g_object_get_data ((GObject*) comp, "source");
	_tmp3_ = _g_object_ref0 ((ESource*) _tmp2_);
	source = _tmp3_;
	_tmp4_ = gtk_application_get_active_window (application);
	_tmp5_ = _tmp4_;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_tmp7_ = calendar_delete_event_dialog_new (source, comp, E_CAL_OBJ_MOD_THIS);
	gtk_window_set_transient_for ((GtkWindow*) _tmp7_, _tmp6_);
	_g_object_unref0 (_tmp6_);
	g_object_ref_sink (_tmp7_);
	delete_dialog = _tmp7_;
	gtk_window_present ((GtkWindow*) delete_dialog);
	_g_object_unref0 (delete_dialog);
	_g_object_unref0 (source);
	_g_object_unref0 (application);
}

