Invite people to events on Federated Core calendars
This commit is contained in:
@@ -2023,3 +2023,250 @@ gcal_event_get_organizer (GcalEvent *self)
|
||||
|
||||
return self->organizer;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
mailto_equal (const gchar *uri1,
|
||||
const gchar *uri2)
|
||||
{
|
||||
if (!uri1 || !uri2)
|
||||
return FALSE;
|
||||
|
||||
if (g_ascii_strncasecmp (uri1, "mailto:", 7) == 0)
|
||||
uri1 += 7;
|
||||
|
||||
if (g_ascii_strncasecmp (uri2, "mailto:", 7) == 0)
|
||||
uri2 += 7;
|
||||
|
||||
return g_ascii_strcasecmp (uri1, uri2) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
set_component_attendees (GcalEvent *self,
|
||||
GSList *ecal_attendees)
|
||||
{
|
||||
e_cal_component_set_attendees (self->component, ecal_attendees);
|
||||
e_cal_component_commit_sequence (self->component);
|
||||
|
||||
g_list_store_remove_all (self->attendees);
|
||||
load_attendees (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_set_organizer:
|
||||
* @self: a #GcalEvent
|
||||
* @email: (nullable): the email address of the organizer
|
||||
* @name: (nullable): the common name of the organizer
|
||||
*
|
||||
* Sets the organizer of @self. Passing %NULL as @email removes the
|
||||
* organizer.
|
||||
*/
|
||||
void
|
||||
gcal_event_set_organizer (GcalEvent *self,
|
||||
const gchar *email,
|
||||
const gchar *name)
|
||||
{
|
||||
ECalComponentOrganizer *organizer = NULL;
|
||||
|
||||
g_return_if_fail (GCAL_IS_EVENT (self));
|
||||
|
||||
g_clear_object (&self->organizer);
|
||||
|
||||
if (email && *email)
|
||||
{
|
||||
g_autofree gchar *uri = g_strdup_printf ("mailto:%s", email);
|
||||
|
||||
organizer = e_cal_component_organizer_new_full (uri, NULL, (name && *name) ? name : NULL, NULL);
|
||||
self->organizer = gcal_event_organizer_new (organizer);
|
||||
}
|
||||
|
||||
e_cal_component_set_organizer (self->component, organizer);
|
||||
e_cal_component_commit_sequence (self->component);
|
||||
|
||||
e_cal_component_organizer_free (organizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_has_attendee:
|
||||
* @self: a #GcalEvent
|
||||
* @email: an email address, with or without the "mailto:" prefix
|
||||
*
|
||||
* Returns: %TRUE if @email is one of the attendees of @self
|
||||
*/
|
||||
gboolean
|
||||
gcal_event_has_attendee (GcalEvent *self,
|
||||
const gchar *email)
|
||||
{
|
||||
guint n_items;
|
||||
|
||||
g_return_val_if_fail (GCAL_IS_EVENT (self), FALSE);
|
||||
|
||||
n_items = g_list_model_get_n_items (G_LIST_MODEL (self->attendees));
|
||||
|
||||
for (guint i = 0; i < n_items; i++)
|
||||
{
|
||||
g_autoptr (GcalEventAttendee) attendee = g_list_model_get_item (G_LIST_MODEL (self->attendees), i);
|
||||
|
||||
if (mailto_equal (gcal_event_attendee_get_uri (attendee), email))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_add_attendee:
|
||||
* @self: a #GcalEvent
|
||||
* @email: the email address of the attendee
|
||||
* @name: (nullable): the common name of the attendee
|
||||
*
|
||||
* Adds a person to the attendees of @self, who is asked to respond.
|
||||
*
|
||||
* Returns: %FALSE if @email already was an attendee
|
||||
*/
|
||||
gboolean
|
||||
gcal_event_add_attendee (GcalEvent *self,
|
||||
const gchar *email,
|
||||
const gchar *name)
|
||||
{
|
||||
g_autofree gchar *uri = NULL;
|
||||
GSList *ecal_attendees;
|
||||
|
||||
g_return_val_if_fail (GCAL_IS_EVENT (self), FALSE);
|
||||
g_return_val_if_fail (email && *email, FALSE);
|
||||
|
||||
if (gcal_event_has_attendee (self, email))
|
||||
return FALSE;
|
||||
|
||||
uri = g_strdup_printf ("mailto:%s", email);
|
||||
|
||||
ecal_attendees = e_cal_component_get_attendees (self->component);
|
||||
ecal_attendees = g_slist_append (ecal_attendees,
|
||||
e_cal_component_attendee_new_full (uri,
|
||||
NULL,
|
||||
I_CAL_CUTYPE_INDIVIDUAL,
|
||||
I_CAL_ROLE_REQPARTICIPANT,
|
||||
I_CAL_PARTSTAT_NEEDSACTION,
|
||||
TRUE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(name && *name) ? name : NULL,
|
||||
NULL));
|
||||
|
||||
set_component_attendees (self, ecal_attendees);
|
||||
|
||||
g_slist_free_full (ecal_attendees, e_cal_component_attendee_free);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_remove_attendee:
|
||||
* @self: a #GcalEvent
|
||||
* @email: an email address, with or without the "mailto:" prefix
|
||||
*
|
||||
* Removes @email from the attendees of @self.
|
||||
*/
|
||||
void
|
||||
gcal_event_remove_attendee (GcalEvent *self,
|
||||
const gchar *email)
|
||||
{
|
||||
GSList *ecal_attendees;
|
||||
GSList *l;
|
||||
|
||||
g_return_if_fail (GCAL_IS_EVENT (self));
|
||||
|
||||
ecal_attendees = e_cal_component_get_attendees (self->component);
|
||||
|
||||
for (l = ecal_attendees; l != NULL; l = l->next)
|
||||
{
|
||||
if (mailto_equal (e_cal_component_attendee_get_value (l->data), email))
|
||||
break;
|
||||
}
|
||||
|
||||
if (l)
|
||||
{
|
||||
e_cal_component_attendee_free (l->data);
|
||||
ecal_attendees = g_slist_delete_link (ecal_attendees, l);
|
||||
|
||||
set_component_attendees (self, ecal_attendees);
|
||||
}
|
||||
|
||||
g_slist_free_full (ecal_attendees, e_cal_component_attendee_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_copy_attendees:
|
||||
* @self: a #GcalEvent
|
||||
* @event: the #GcalEvent to copy from
|
||||
*
|
||||
* Replaces the organizer and attendees of @self with those of @event.
|
||||
*/
|
||||
void
|
||||
gcal_event_copy_attendees (GcalEvent *self,
|
||||
GcalEvent *event)
|
||||
{
|
||||
ECalComponentOrganizer *organizer;
|
||||
GSList *ecal_attendees;
|
||||
|
||||
g_return_if_fail (GCAL_IS_EVENT (self));
|
||||
g_return_if_fail (GCAL_IS_EVENT (event));
|
||||
|
||||
organizer = e_cal_component_get_organizer (event->component);
|
||||
|
||||
g_clear_object (&self->organizer);
|
||||
if (organizer)
|
||||
self->organizer = gcal_event_organizer_new (organizer);
|
||||
|
||||
e_cal_component_set_organizer (self->component, organizer);
|
||||
|
||||
ecal_attendees = e_cal_component_get_attendees (event->component);
|
||||
set_component_attendees (self, ecal_attendees);
|
||||
|
||||
g_slist_free_full (ecal_attendees, e_cal_component_attendee_free);
|
||||
e_cal_component_organizer_free (organizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_event_attendees_equal:
|
||||
* @event1: a #GcalEvent
|
||||
* @event2: a #GcalEvent
|
||||
*
|
||||
* Checks if @event1 and @event2 have the same organizer and attendees.
|
||||
* Only the email addresses are compared.
|
||||
*
|
||||
* Returns: %TRUE if the events' organizer and attendees are identical
|
||||
*/
|
||||
gboolean
|
||||
gcal_event_attendees_equal (GcalEvent *event1,
|
||||
GcalEvent *event2)
|
||||
{
|
||||
const gchar *organizer1 = NULL;
|
||||
const gchar *organizer2 = NULL;
|
||||
guint n_items;
|
||||
|
||||
g_assert (GCAL_IS_EVENT (event1) && GCAL_IS_EVENT (event2));
|
||||
|
||||
if (event1->organizer)
|
||||
organizer1 = gcal_event_organizer_get_uri (event1->organizer);
|
||||
if (event2->organizer)
|
||||
organizer2 = gcal_event_organizer_get_uri (event2->organizer);
|
||||
|
||||
if ((organizer1 || organizer2) && !mailto_equal (organizer1, organizer2))
|
||||
return FALSE;
|
||||
|
||||
n_items = g_list_model_get_n_items (G_LIST_MODEL (event1->attendees));
|
||||
|
||||
if (n_items != g_list_model_get_n_items (G_LIST_MODEL (event2->attendees)))
|
||||
return FALSE;
|
||||
|
||||
for (guint i = 0; i < n_items; i++)
|
||||
{
|
||||
g_autoptr (GcalEventAttendee) attendee = g_list_model_get_item (G_LIST_MODEL (event1->attendees), i);
|
||||
|
||||
if (!gcal_event_has_attendee (event2, gcal_event_attendee_get_uri (attendee)))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -142,6 +142,26 @@ GListModel * gcal_event_get_attendees (GcalEvent
|
||||
|
||||
GcalEventOrganizer * gcal_event_get_organizer (GcalEvent *self);
|
||||
|
||||
void gcal_event_set_organizer (GcalEvent *self,
|
||||
const gchar *email,
|
||||
const gchar *name);
|
||||
|
||||
gboolean gcal_event_has_attendee (GcalEvent *self,
|
||||
const gchar *email);
|
||||
|
||||
gboolean gcal_event_add_attendee (GcalEvent *self,
|
||||
const gchar *email,
|
||||
const gchar *name);
|
||||
|
||||
void gcal_event_remove_attendee (GcalEvent *self,
|
||||
const gchar *email);
|
||||
|
||||
void gcal_event_copy_attendees (GcalEvent *self,
|
||||
GcalEvent *event);
|
||||
|
||||
gboolean gcal_event_attendees_equal (GcalEvent *event1,
|
||||
GcalEvent *event2);
|
||||
|
||||
gboolean gcal_event_alarms_equal (GcalEvent *event1,
|
||||
GcalEvent *event2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user