[gnome-calendar] event-widget: add internal #ECalComponent object
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] event-widget: add internal #ECalComponent object
- Date: Thu, 4 Dec 2014 22:34:03 +0000 (UTC)
commit bc4663f8c8616a9fcfb82213d239d3295e5786d4
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Sun Oct 5 19:10:18 2014 -0400
event-widget: add internal #ECalComponent object
The changes made here are minimal to get this building. GcalEventWidget
needs a new rethink and rework to accommodate to those new internal
attributes, which replaces some of the old ones.
src/gcal-event-widget.c | 125 +++++++++++++++++++++++++++++++++++++++++++----
src/gcal-event-widget.h | 4 ++
2 files changed, 119 insertions(+), 10 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index e23db78..1ad09c3 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -23,16 +23,21 @@
typedef struct
{
/* properties */
- gchar *uuid;
- gchar *summary;
- GdkRGBA *color;
- icaltimetype *dt_start;
- icaltimetype *dt_end;
- gboolean all_day;
- gboolean has_reminders;
-
- GdkWindow *event_window;
- gboolean button_pressed;
+ gchar *uuid;
+ gchar *summary;
+ GdkRGBA *color;
+ icaltimetype *dt_start;
+ icaltimetype *dt_end;
+ gboolean all_day;
+ gboolean has_reminders;
+
+ /* weak ESource reference */
+ ESource *source;
+ /* ECalComponent data */
+ ECalComponent *component;
+
+ GdkWindow *event_window;
+ gboolean button_pressed;
} GcalEventWidgetPrivate;
enum
@@ -67,6 +72,8 @@ static void gcal_event_widget_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
+static void gcal_event_widget_finalize (GObject *object);
+
static void gcal_event_widget_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural);
@@ -107,6 +114,7 @@ gcal_event_widget_class_init(GcalEventWidgetClass *klass)
object_class->constructed = gcal_event_widget_constructed;
object_class->set_property = gcal_event_widget_set_property;
object_class->get_property = gcal_event_widget_get_property;
+ object_class->finalize = gcal_event_widget_finalize;
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->get_preferred_width = gcal_event_widget_get_preferred_width;
@@ -319,6 +327,20 @@ gcal_event_widget_get_property (GObject *object,
}
static void
+gcal_event_widget_finalize (GObject *object)
+{
+ GcalEventWidgetPrivate *priv;
+
+ priv =
+ gcal_event_widget_get_instance_private (GCAL_EVENT_WIDGET (object));
+
+ if (priv->component != NULL)
+ g_object_unref (priv->component);
+
+ G_OBJECT_CLASS (gcal_event_widget_parent_class)->finalize (object);
+}
+
+static void
gcal_event_widget_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
@@ -616,6 +638,89 @@ gcal_event_widget_new (gchar *uuid)
return g_object_new (GCAL_TYPE_EVENT_WIDGET, "uuid", uuid, NULL);
}
+/**
+ * gcal_event_widget_new_from_data:
+ * @data: a #GcalEventData instance
+ *
+ * Create an event widget by passing its #ECalComponent and #ESource
+ *
+ * Returns: a #GcalEventWidget as #GtkWidget
+ **/
+GtkWidget*
+gcal_event_widget_new_from_data (GcalEventData *data)
+{
+ GtkWidget *widget;
+ GcalEventWidget *event;
+ GcalEventWidgetPrivate *priv;
+
+ ECalComponentText e_summary;
+ ESourceSelectable *extension;
+ GdkRGBA *color;
+ ECalComponentDateTime dt;
+ icaltimetype *date;
+ gboolean start_is_date, end_is_date;
+
+ widget = g_object_new (GCAL_TYPE_EVENT_WIDGET, NULL);
+
+ event = GCAL_EVENT_WIDGET (widget);
+
+ priv = gcal_event_widget_get_instance_private (event);
+ priv->component = data->event_component;
+ priv->source = data->source;
+
+ /* summary */
+ e_cal_component_get_summary (priv->component, &e_summary);
+ gcal_event_widget_set_summary (event, e_summary.value);
+
+ /* color */
+ color = g_new0 (GdkRGBA, 1);
+
+ extension = E_SOURCE_SELECTABLE (
+ e_source_get_extension (priv->source,
+ E_SOURCE_EXTENSION_CALENDAR));
+ gdk_rgba_parse (color, e_source_selectable_get_color (extension));
+ gcal_event_widget_set_color (event, color);
+ gdk_rgba_free (color);
+
+ /* start date */
+ e_cal_component_get_dtstart (priv->component, &dt);
+ date = gcal_dup_icaltime (dt.value);
+
+ /* FIXME: fix the timezone issue */
+ /* if (date->is_date != 1) */
+ /* *date = icaltime_convert_to_zone (*(dt.value), */
+ /* priv->system_timezone); */
+ start_is_date = date->is_date == 1;
+
+ gcal_event_widget_set_date (event, date);
+ e_cal_component_free_datetime (&dt);
+ g_free (date);
+
+ /* end date */
+ e_cal_component_get_dtend (priv->component, &dt);
+ date = gcal_dup_icaltime (dt.value);
+
+ /* FIXME: fix the timezone issue */
+ /* if (date->is_date != 1) */
+ /* *date = icaltime_convert_to_zone (*(dt.value), */
+ /* priv->system_timezone); */
+ end_is_date = date->is_date == 1;
+
+ gcal_event_widget_set_end_date (event, date);
+ e_cal_component_free_datetime (&dt);
+ g_free (date);
+
+ /* set_all_day */
+ gcal_event_widget_set_all_day (event, start_is_date && end_is_date);
+
+ /* set_has_reminders */
+ gcal_event_widget_set_has_reminders (
+ event,
+ e_cal_component_has_alarms (priv->component));
+
+ return widget;
+}
+
GtkWidget*
gcal_event_widget_new_with_summary_and_color (const gchar *summary,
const GdkRGBA *color)
diff --git a/src/gcal-event-widget.h b/src/gcal-event-widget.h
index 328741c..65fcb94 100644
--- a/src/gcal-event-widget.h
+++ b/src/gcal-event-widget.h
@@ -20,6 +20,8 @@
#ifndef __GCAL_EVENT_WIDGET_H__
#define __GCAL_EVENT_WIDGET_H__
+#include "gcal-manager.h"
+
#include <gtk/gtk.h>
#include <libical/icaltime.h>
@@ -54,6 +56,8 @@ GType gcal_event_widget_get_type (void);
GtkWidget* gcal_event_widget_new (gchar *uuid);
+GtkWidget* gcal_event_widget_new_from_data (GcalEventData *data);
+
GtkWidget* gcal_event_widget_new_with_summary_and_color (const gchar *summary,
const GdkRGBA *color);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]