[gnome-calendar] event-widget: show tooltip with event details
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] event-widget: show tooltip with event details
- Date: Tue, 11 Apr 2017 12:56:00 +0000 (UTC)
commit 21eba8ea0a89fd15b7a571754a617dfad83d8ca9
Author: Novi-Novi <chinhanglun gmail com>
Date: Tue Jan 31 13:42:43 2017 +0000
event-widget: show tooltip with event details
In month view and year view, when the mouse is hovering over
an event, nothing is shown. A tooltip with the event information
would be much more useful in this scenario.
Fix that by showing a tooltip displaying the event's title, time
and date, and, if present, the location and notes of the event. Long
notes are truncated and ellipsized.
https://bugzilla.gnome.org/show_bug.cgi?id=774952
src/gcal-event-widget.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 141 insertions(+), 2 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index 0e316b0..4879bf4 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -20,12 +20,14 @@
#define G_LOG_DOMAIN "GcalEventWidget"
#include <string.h>
+#include <glib/gi18n.h>
#include "gcal-event-widget.h"
#include "gcal-utils.h"
-#define INTENSITY(c) ((c->red) * 0.30 + (c->green) * 0.59 + (c->blue) * 0.11)
-#define ICON_SIZE 16
+#define DESC_MAX_CHAR 200
+#define INTENSITY(c) ((c->red) * 0.30 + (c->green) * 0.59 + (c->blue) * 0.11)
+#define ICON_SIZE 16
struct _GcalEventWidget
{
@@ -241,6 +243,141 @@ update_color (GcalEventWidget *self)
}
static void
+gcal_event_widget_set_event_tooltip (GcalEventWidget *self,
+ GcalEvent *event)
+{
+ g_autoptr (GDateTime) tooltip_start, tooltip_end;
+ g_autofree gchar *start, *end;
+ gboolean allday, multiday, is_ltr;
+ GString *tooltip_desc, *tooltip_mesg;
+
+ tooltip_mesg = g_string_new (NULL);
+ g_string_append_printf (tooltip_mesg, "<b>%s</b>", gcal_event_get_summary (event));
+
+ tooltip_start = g_date_time_to_local (gcal_event_get_date_start (event));
+ tooltip_end = g_date_time_to_local (gcal_event_get_date_end (event));
+
+ allday = gcal_event_get_all_day (event);
+ multiday = gcal_event_is_multiday (event);
+
+ is_ltr = gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL;
+
+ if (allday)
+ {
+ if (multiday)
+ {
+ start = g_date_time_format (tooltip_start, "%x");
+ end = g_date_time_format (tooltip_end, "%x");
+ }
+ else
+ {
+ start = g_date_time_format (tooltip_start, "%x");
+ end = NULL;
+ }
+ }
+ else
+ {
+ if (multiday)
+ {
+ if (self->clock_format_24h)
+ {
+ if (is_ltr)
+ {
+ start = g_date_time_format (tooltip_start, "%x %R");
+ end = g_date_time_format (tooltip_end, "%x %R");
+ }
+ else
+ {
+ start = g_date_time_format (tooltip_start, "%R %x");
+ end = g_date_time_format (tooltip_end, "%R %x");
+ }
+ }
+ else
+ {
+ if (is_ltr)
+ {
+ start = g_date_time_format (tooltip_start, "%x I:%M %P");
+ end = g_date_time_format (tooltip_end, "%x I:%M %P");
+ }
+ else
+ {
+ start = g_date_time_format (tooltip_start, "%P %M:%I %x");
+ end = g_date_time_format (tooltip_end, "%P %M:%I %x");
+ }
+ }
+ }
+ else
+ {
+ if (self->clock_format_24h)
+ {
+ if (is_ltr)
+ {
+ start = g_date_time_format (tooltip_start, "%x, %R");
+ end = g_date_time_format (tooltip_end, "%R");
+ }
+ else
+ {
+ start = g_date_time_format (tooltip_start, "%R ,%x");
+ end = g_date_time_format (tooltip_end, "%R");
+ }
+ }
+ else
+ {
+ if (is_ltr)
+ {
+ start = g_date_time_format (tooltip_start, "%x, I:%M %P");
+ end = g_date_time_format (tooltip_end, "I:%M %P");
+ }
+ else
+ {
+ start = g_date_time_format (tooltip_start, "%P %M:%I ,%x");
+ end = g_date_time_format (tooltip_end, "%P %M:%I");
+ }
+ }
+ }
+ }
+
+ if (allday && !multiday)
+ {
+ g_string_append_printf (tooltip_mesg,
+ "\n%s",
+ start);
+ }
+ else
+ {
+ g_string_append_printf (tooltip_mesg,
+ "\n%s - %s",
+ is_ltr ? start : end,
+ is_ltr ? end : start);
+ }
+
+ /* Append event location */
+ if (g_utf8_strlen (gcal_event_get_location (event), -1) > 0)
+ {
+ g_string_append (tooltip_mesg, "\n");
+ g_string_append_printf (tooltip_mesg,
+ _("At %s"),
+ gcal_event_get_location (event));
+ }
+
+ tooltip_desc = g_string_new (gcal_event_get_description (event));
+
+ /* Truncate long descriptions at a white space and ellipsize */
+ if (tooltip_desc->len > 0)
+ {
+ g_string_truncate (tooltip_desc, DESC_MAX_CHAR - 1);
+ g_string_append (tooltip_desc, "…");
+
+ g_string_append_printf (tooltip_mesg, "\n%s", tooltip_desc->str);
+ }
+
+ gtk_widget_set_tooltip_markup (GTK_WIDGET (self), tooltip_mesg->str);
+
+ g_string_free (tooltip_desc, TRUE);
+ g_string_free (tooltip_mesg, TRUE);
+}
+
+static void
gcal_event_widget_set_event_internal (GcalEventWidget *self,
GcalEvent *event)
{
@@ -275,6 +412,8 @@ gcal_event_widget_set_event_internal (GcalEventWidget *self,
"notify::summary",
G_CALLBACK (gtk_widget_queue_draw),
self);
+
+ gcal_event_widget_set_event_tooltip (self, event);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]