Add a Jitsi video conference to events on Core calendars
The event editor offers "Add Video Conference" on the calendars of a Federated Computer Core. It makes a room with an unguessable name, like BraveOttersSing-k3f9x2m7, on the Core's Jitsi at jitsi.<CORE_DOMAIN>, and shows its link with Copy and Remove buttons. The link goes at the end of the event's notes, which reach everyone invited whatever their mail app, and in an RFC 7986 CONFERENCE property. Saving puts the link back in the notes if it was taken out, and "All events" copies the conference to the whole series. Existing conferences are found in CONFERENCE, or as Jitsi links in the notes or location, so the editor doesn't offer a second one and the popover shows a Join button. The popover now keeps showing a place in the location alongside a meeting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#define G_LOG_DOMAIN "GcalSummarySection"
|
||||
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-jitsi.h"
|
||||
#include "gcal-summary-section.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
@@ -32,15 +33,155 @@ struct _GcalSummarySection
|
||||
|
||||
AdwEntryRow *summary_entry;
|
||||
AdwEntryRow *location_entry;
|
||||
AdwButtonRow *add_conference_row;
|
||||
AdwActionRow *conference_row;
|
||||
GtkButton *copy_conference_button;
|
||||
GtkButton *remove_conference_button;
|
||||
|
||||
/* The Jitsi server of the event's Core, if a conference can be added */
|
||||
gchar *conference_server;
|
||||
|
||||
/* The event's conference */
|
||||
gchar *conference_url;
|
||||
|
||||
guint copied_timeout_id;
|
||||
};
|
||||
|
||||
|
||||
G_DEFINE_FINAL_TYPE (GcalSummarySection, gcal_summary_section, GCAL_TYPE_EVENT_EDITOR_SECTION)
|
||||
|
||||
/*
|
||||
* Auxiliary methods
|
||||
*/
|
||||
|
||||
static void
|
||||
update_conference_rows (GcalSummarySection *self)
|
||||
{
|
||||
gboolean has_conference = self->conference_url != NULL;
|
||||
|
||||
adw_action_row_set_subtitle (self->conference_row, has_conference ? self->conference_url : "");
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->conference_row), has_conference);
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->add_conference_row), !has_conference && self->conference_server);
|
||||
}
|
||||
|
||||
static void
|
||||
announce (GcalSummarySection *self,
|
||||
const gchar *message)
|
||||
{
|
||||
gtk_accessible_announce (GTK_ACCESSIBLE (self), message, GTK_ACCESSIBLE_ANNOUNCEMENT_PRIORITY_MEDIUM);
|
||||
}
|
||||
|
||||
static void
|
||||
reset_copy_button (GcalSummarySection *self)
|
||||
{
|
||||
g_clear_handle_id (&self->copied_timeout_id, g_source_remove);
|
||||
|
||||
gtk_button_set_icon_name (self->copy_conference_button, "edit-copy-symbolic");
|
||||
gtk_widget_set_tooltip_text (GTK_WIDGET (self->copy_conference_button), _("Copy Link"));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Callbacks
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
on_copied_timeout_cb (gpointer user_data)
|
||||
{
|
||||
GcalSummarySection *self = GCAL_SUMMARY_SECTION (user_data);
|
||||
|
||||
self->copied_timeout_id = 0;
|
||||
reset_copy_button (self);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_add_conference_row_activated_cb (GcalSummarySection *self)
|
||||
{
|
||||
g_autofree gchar *room_name = NULL;
|
||||
GcalEvent *event;
|
||||
|
||||
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||
|
||||
if (!event || !self->conference_server || self->conference_url)
|
||||
return;
|
||||
|
||||
room_name = gcal_jitsi_generate_room_name ();
|
||||
if (!room_name)
|
||||
return;
|
||||
|
||||
self->conference_url = gcal_jitsi_build_room_url (self->conference_server, room_name);
|
||||
|
||||
gcal_jitsi_add_conference (event, self->conference_url);
|
||||
|
||||
update_conference_rows (self);
|
||||
|
||||
/* The button that had the focus is gone */
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self->copy_conference_button));
|
||||
announce (self, _("Video conference added"));
|
||||
}
|
||||
|
||||
static void
|
||||
on_copy_conference_button_clicked_cb (GcalSummarySection *self)
|
||||
{
|
||||
if (!self->conference_url)
|
||||
return;
|
||||
|
||||
gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (self)), self->conference_url);
|
||||
|
||||
gtk_button_set_icon_name (self->copy_conference_button, "object-select-symbolic");
|
||||
gtk_widget_set_tooltip_text (GTK_WIDGET (self->copy_conference_button), _("Copied"));
|
||||
|
||||
g_clear_handle_id (&self->copied_timeout_id, g_source_remove);
|
||||
self->copied_timeout_id = g_timeout_add_seconds (2, on_copied_timeout_cb, self);
|
||||
|
||||
announce (self, _("Link copied"));
|
||||
}
|
||||
|
||||
static void
|
||||
on_remove_conference_button_clicked_cb (GcalSummarySection *self)
|
||||
{
|
||||
g_autofree gchar *other_url = NULL;
|
||||
g_autofree gchar *location = NULL;
|
||||
GcalEvent *event;
|
||||
|
||||
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||
|
||||
if (!event || !self->conference_url)
|
||||
return;
|
||||
|
||||
gcal_jitsi_remove_conference (event, self->conference_url);
|
||||
|
||||
/* The conference could have been in the location */
|
||||
location = g_strdup (gcal_event_get_location (event));
|
||||
if (location && g_str_equal (g_strstrip (location), self->conference_url))
|
||||
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), "");
|
||||
|
||||
/* There could be another one, e.g. a different room in the location */
|
||||
other_url = gcal_jitsi_find_event_conference (event);
|
||||
|
||||
/* A link amid other words in the location is the person's to edit */
|
||||
if (g_strcmp0 (other_url, self->conference_url) == 0)
|
||||
g_clear_pointer (&other_url, g_free);
|
||||
|
||||
g_free (self->conference_url);
|
||||
self->conference_url = g_steal_pointer (&other_url);
|
||||
|
||||
reset_copy_button (self);
|
||||
update_conference_rows (self);
|
||||
|
||||
if (gtk_widget_get_visible (GTK_WIDGET (self->add_conference_row)))
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self->add_conference_row));
|
||||
else if (self->conference_url)
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self->copy_conference_button));
|
||||
else
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self->location_entry));
|
||||
|
||||
announce (self, _("Video conference removed"));
|
||||
}
|
||||
|
||||
static void
|
||||
on_summary_entry_text_changed_cb (GcalSummarySection *self)
|
||||
{
|
||||
@@ -107,6 +248,13 @@ gcal_summary_section_event_set_cb (GcalEventEditorSection *section,
|
||||
g_signal_handlers_unblock_by_func (self->location_entry, on_location_entry_changed_cb, self);
|
||||
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||
|
||||
g_clear_pointer (&self->conference_url, g_free);
|
||||
if (event)
|
||||
self->conference_url = gcal_jitsi_find_event_conference (event);
|
||||
|
||||
reset_copy_button (self);
|
||||
update_conference_rows (self);
|
||||
}
|
||||
|
||||
|
||||
@@ -137,12 +285,37 @@ gcal_summary_section_unmap (GtkWidget *widget)
|
||||
* GObject overrides
|
||||
*/
|
||||
|
||||
static void
|
||||
gcal_summary_section_dispose (GObject *object)
|
||||
{
|
||||
GcalSummarySection *self = GCAL_SUMMARY_SECTION (object);
|
||||
|
||||
g_clear_handle_id (&self->copied_timeout_id, g_source_remove);
|
||||
|
||||
G_OBJECT_CLASS (gcal_summary_section_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_summary_section_finalize (GObject *object)
|
||||
{
|
||||
GcalSummarySection *self = GCAL_SUMMARY_SECTION (object);
|
||||
|
||||
g_clear_pointer (&self->conference_server, g_free);
|
||||
g_clear_pointer (&self->conference_url, g_free);
|
||||
|
||||
G_OBJECT_CLASS (gcal_summary_section_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_summary_section_class_init (GcalSummarySectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GcalEventEditorSectionClass *section_class = GCAL_EVENT_EDITOR_SECTION_CLASS (klass);
|
||||
|
||||
object_class->dispose = gcal_summary_section_dispose;
|
||||
object_class->finalize = gcal_summary_section_finalize;
|
||||
|
||||
widget_class->grab_focus = gcal_summary_section_grab_focus;
|
||||
widget_class->unmap = gcal_summary_section_unmap;
|
||||
|
||||
@@ -150,11 +323,18 @@ gcal_summary_section_class_init (GcalSummarySectionClass *klass)
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-summary-section.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, add_conference_row);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, conference_row);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, copy_conference_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, location_entry);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, remove_conference_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, summary_entry);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_text_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_add_conference_row_activated_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_copy_conference_button_clicked_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_location_entry_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_remove_conference_button_clicked_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_text_changed_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -162,3 +342,23 @@ gcal_summary_section_init (GcalSummarySection *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_summary_section_set_conference_server:
|
||||
* @self: a #GcalSummarySection
|
||||
* @server: (nullable): the address of a Jitsi server
|
||||
*
|
||||
* Offers to add a video conference on @server to the event, unless it has
|
||||
* one already. %NULL hides the offer, e.g. for calendars that aren't on a
|
||||
* Federated Computer Core.
|
||||
*/
|
||||
void
|
||||
gcal_summary_section_set_conference_server (GcalSummarySection *self,
|
||||
const gchar *server)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_SUMMARY_SECTION (self));
|
||||
|
||||
g_set_str (&self->conference_server, server);
|
||||
|
||||
update_conference_rows (self);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user