Introduce GcalEventPopover

GcalEventPopover gives a preview of the event, and handy access
to the event description and information. It also allows easily
joining meetings if any one if available.

The list of supported meeting URLs is small now, but I hope
more people will contribute as we go.

It is also possible to edit the event through an edit button.
This commit is contained in:
Georges Basile Stavracas Neto
2021-06-27 18:45:12 -03:00
parent 01ee4a2b49
commit 68160348dc
12 changed files with 1337 additions and 7 deletions
+77
View File
@@ -25,6 +25,8 @@
#include "gcal-application.h"
#include "gcal-context.h"
#include "gcal-clock.h"
#include "gcal-debug.h"
#include "gcal-event-popover.h"
#include "gcal-event-widget.h"
#include "gcal-utils.h"
@@ -32,6 +34,13 @@
#define INTENSITY(c) ((c->red) * 0.30 + (c->green) * 0.59 + (c->blue) * 0.11)
#define ICON_SIZE 16
typedef struct
{
GcalEventWidget *event_widget;
GcalEventPreviewCallback callback;
gpointer user_data;
} PreviewData;
struct _GcalEventWidget
{
GtkBin parent;
@@ -527,6 +536,40 @@ gcal_event_widget_set_event_internal (GcalEventWidget *self,
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
}
static void
reply_preview_callback (GtkWidget *event_popover,
PreviewData *data,
GcalEventPreviewAction action)
{
if (data->callback)
data->callback (data->event_widget, action, data->user_data);
g_signal_handlers_disconnect_by_data (event_popover, data);
gtk_widget_destroy (event_popover);
g_clear_pointer (&data, g_free);
}
/*
* Callbacks
*/
static void
on_event_popover_closed_cb (GtkWidget *event_popover,
PreviewData *data)
{
reply_preview_callback (event_popover, data, GCAL_EVENT_PREVIEW_ACTION_NONE);
}
static void
on_event_popover_edit_cb (GtkWidget *event_popover,
PreviewData *data)
{
reply_preview_callback (event_popover, data, GCAL_EVENT_PREVIEW_ACTION_EDIT);
}
/*
* GtkWidget overrides
@@ -1134,6 +1177,40 @@ gcal_event_widget_set_date_start (GcalEventWidget *self,
}
}
/**
* gcal_event_widget_show_preview:
* @self: a #GcalEventWidget
* @callback: (nullable): callback for the event preview
* @user_data: (nullable): user data for @callback
*
* Shows an event preview popover for this event widget, and
* calls @callback when the popover is either dismissed, or
* the edit button is clicked.
*/
void
gcal_event_widget_show_preview (GcalEventWidget *self,
GcalEventPreviewCallback callback,
gpointer user_data)
{
PreviewData *data;
GtkWidget *event_popover;
GCAL_ENTRY;
data = g_new0 (PreviewData, 1);
data->event_widget = self;
data->callback = callback;
data->user_data = user_data;
event_popover = gcal_event_popover_new (self->context, self->event);
gtk_popover_set_relative_to (GTK_POPOVER (event_popover), GTK_WIDGET (self));
g_signal_connect (event_popover, "closed", G_CALLBACK (on_event_popover_closed_cb), data);
g_signal_connect (event_popover, "edit", G_CALLBACK (on_event_popover_edit_cb), data);
gtk_popover_popup (GTK_POPOVER (event_popover));
GCAL_EXIT;
}
/**
* gcal_event_widget_get_event:
* @self: a #GcalEventWidget