Files
federated-calendar/src/gui/event-editor/gcal-summary-section.c
T
davidandClaude Opus 5.5 3c118fbb9d 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>
2026-11-28 07:28:20 -07:00

365 lines
11 KiB
C

/* gcal-summary-section.c
*
* Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* 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 3 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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#define G_LOG_DOMAIN "GcalSummarySection"
#include "gcal-debug.h"
#include "gcal-jitsi.h"
#include "gcal-summary-section.h"
#include "gcal-utils.h"
#include <glib/gi18n.h>
struct _GcalSummarySection
{
GcalEventEditorSection parent;
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)
{
gboolean should_request_validation;
const char *text, *summary;
GtkWidget *dialog;
GcalEvent *event;
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
summary = gcal_event_get_summary (event);
text = gtk_editable_get_text (GTK_EDITABLE (self->summary_entry));
should_request_validation = gcal_util_is_valid_event_name (text) != gcal_util_is_valid_event_name (summary);
if (gcal_util_is_valid_event_name (text))
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
else
gtk_widget_add_css_class (GTK_WIDGET (self->summary_entry), "error");
gcal_event_set_summary (event, text);
dialog = gcal_event_editor_section_get_dialog (GCAL_EVENT_EDITOR_SECTION (self));
if (should_request_validation)
g_signal_emit_by_name (dialog, "validation-requested");
}
static void
on_location_entry_changed_cb (GcalSummarySection *self)
{
const char *text = gtk_editable_get_text (GTK_EDITABLE (self->location_entry));
GcalEvent *event;
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
gcal_event_set_location (event, text);
}
/*
* GcalEventEditorSection overrides
*/
static void
gcal_summary_section_event_set_cb (GcalEventEditorSection *section,
GcalEvent *event)
{
GcalSummarySection *self = GCAL_SUMMARY_SECTION (section);
g_signal_handlers_block_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
g_signal_handlers_block_by_func (self->location_entry, on_location_entry_changed_cb, self);
if (event)
{
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), gcal_event_get_summary (event));
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), gcal_event_get_location (event));
}
else
{
gtk_editable_delete_text (GTK_EDITABLE (self->summary_entry), 0, -1);
gtk_editable_delete_text (GTK_EDITABLE (self->location_entry), 0, -1);
}
g_signal_handlers_unblock_by_func (self->summary_entry, on_summary_entry_text_changed_cb, self);
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);
}
/*
* GtkWidget overrides
*/
static gboolean
gcal_summary_section_grab_focus (GtkWidget *widget)
{
GcalSummarySection *self = GCAL_SUMMARY_SECTION (widget);
return gtk_widget_grab_focus (GTK_WIDGET (self->summary_entry));
}
static void
gcal_summary_section_unmap (GtkWidget *widget)
{
GcalSummarySection *self = GCAL_SUMMARY_SECTION (widget);
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
GTK_WIDGET_CLASS (gcal_summary_section_parent_class)->unmap (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;
section_class->event_set_cb = gcal_summary_section_event_set_cb;
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_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
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);
}