[gnome-calendar/gbsneto/range: 5/15] event: Add helper API to return a GcalRange
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/range: 5/15] event: Add helper API to return a GcalRange
- Date: Tue, 14 Apr 2020 19:08:27 +0000 (UTC)
commit 0935a675581d26f55c074a9fc197bf4fbb874804
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Apr 12 21:08:21 2020 -0300
event: Add helper API to return a GcalRange
src/core/gcal-event.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/core/gcal-event.h | 5 ++++-
2 files changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index 8f28a89f..f415b74f 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -89,6 +89,7 @@ struct _GcalEvent
GDateTime *dt_start;
GDateTime *dt_end;
+ GcalRange *range;
GdkRGBA *color;
GBinding *color_binding;
@@ -124,6 +125,7 @@ enum {
PROP_DATE_START,
PROP_LOCATION,
PROP_CALENDAR,
+ PROP_RANGE,
PROP_SUMMARY,
PROP_TIMEZONE,
PROP_UID,
@@ -138,6 +140,13 @@ static GParamSpec* properties[N_PROPS] = { NULL, };
* Auxiliary methods
*/
+static void
+clear_range (GcalEvent *self)
+{
+ g_clear_pointer (&self->range, gcal_range_unref);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RANGE]);
+}
+
static GTimeZone*
get_timezone_from_ical (ECalComponentDateTime *comp)
{
@@ -447,6 +456,7 @@ gcal_event_finalize (GObject *object)
g_clear_pointer (&self->dt_start, g_date_time_unref);
g_clear_pointer (&self->dt_end, g_date_time_unref);
+ g_clear_pointer (&self->range, gcal_range_unref);
g_clear_pointer (&self->summary, g_free);
g_clear_pointer (&self->location, g_free);
g_clear_pointer (&self->description, g_free);
@@ -502,6 +512,10 @@ gcal_event_get_property (GObject *object,
g_value_set_string (value, gcal_event_get_location (self));
break;
+ case PROP_RANGE:
+ g_value_take_boxed (value, gcal_event_get_range (self));
+ break;
+
case PROP_SUMMARY:
g_value_set_string (value, gcal_event_get_summary (self));
break;
@@ -676,6 +690,17 @@ gcal_event_class_init (GcalEventClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
+ /**
+ * GcalEvent::range:
+ *
+ * The range of the event, as a combination of the start and end dates.
+ */
+ properties[PROP_RANGE] = g_param_spec_boxed ("range",
+ "Range of the event",
+ "The time range of the event",
+ GCAL_TYPE_RANGE,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
+
/**
* GcalEvent::recurrence:
*
@@ -863,6 +888,8 @@ gcal_event_set_all_day (GcalEvent *self,
self->all_day = all_day;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALL_DAY]);
+
+ clear_range (self);
}
}
@@ -910,6 +937,7 @@ gcal_event_set_date_end (GcalEvent *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_END]);
+ clear_range (self);
e_cal_component_datetime_free (component_dt);
}
}
@@ -955,10 +983,35 @@ gcal_event_set_date_start (GcalEvent *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_START]);
+ clear_range (self);
e_cal_component_datetime_free (component_dt);
}
}
+/**
+ * gcal_event_get_range:
+ * @self: a #GcalEvent
+ *
+ * Retrieves the range of @self. This is a simple combination of
+ * the start and end dates.
+ *
+ * Returns: (transfer none): a #GcalRange
+ */
+GcalRange*
+gcal_event_get_range (GcalEvent *self)
+{
+ g_return_val_if_fail (GCAL_IS_EVENT (self), NULL);
+
+ if (!self->range)
+ {
+ self->range = gcal_range_new (gcal_event_get_date_start (self),
+ gcal_event_get_date_end (self),
+ self->all_day ? GCAL_RANGE_DATE_ONLY : GCAL_RANGE_DEFAULT);
+ }
+
+ return self->range;
+}
+
/**
* gcal_event_get_description:
* @self a #GcalEvent
diff --git a/src/core/gcal-event.h b/src/core/gcal-event.h
index be6e6c0c..bd036d5e 100644
--- a/src/core/gcal-event.h
+++ b/src/core/gcal-event.h
@@ -1,6 +1,6 @@
/* gcal-event.h
*
- * Copyright (C) 2016 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ * Copyright (C) 2016-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
@@ -20,6 +20,7 @@
#define GCAL_EVENT_H
#include "gcal-calendar.h"
+#include "gcal-range.h"
#include "gcal-recurrence.h"
#include <glib-object.h>
@@ -74,6 +75,8 @@ GDateTime* gcal_event_get_date_start (GcalEvent
void gcal_event_set_date_start (GcalEvent *self,
GDateTime *dt);
+GcalRange* gcal_event_get_range (GcalEvent *self);
+
const gchar* gcal_event_get_description (GcalEvent *self);
void gcal_event_set_description (GcalEvent *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]