[gnome-calendar] events: fix handling of event with no end date



commit e62f48bfeac9992f00476df978e6e5ed2c2cd2aa
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Sun Dec 7 15:23:27 2014 -0500

    events: fix handling of event with no end date
    
    Fix the sigsegv in edit-dialog and event-widgets when there's no
    end-date set.
    Set a guard in Utils::gcal_dup_icaltime function.
    There's still some problems with the events showing the first time but
    not anymore.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=736002

 src/gcal-edit-dialog.c  |   44 ++++++++++++++++++++++----------------------
 src/gcal-event-widget.c |   28 ++++++++++++++++------------
 src/gcal-utils.c        |    3 +++
 3 files changed, 41 insertions(+), 34 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 3903786..a2ad7ff 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -861,40 +861,40 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog,
                             dtstart.value->month,
                             dtstart.value->year);
 
-  /* end date */
-  e_cal_component_get_dtend (priv->component, &dtend);
-
-  gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry),
-                            dtend.value->day,
-                            dtend.value->month,
-                            dtend.value->year);
-
-  /* all_day  */
-  all_day = (dtstart.value->is_date == 1 && dtend.value->is_date == 1);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check), all_day);
-
   /* start time */
   if (all_day)
     {
       dtstart.value->hour = 0;
       dtstart.value->minute = 0;
     }
-  gcal_time_entry_set_time (GCAL_TIME_ENTRY (priv->start_time_entry),
-                            dtstart.value->hour,
-                            dtstart.value->minute);
-  /* end time */
-  if (all_day)
+  gcal_time_entry_set_time (GCAL_TIME_ENTRY (priv->start_time_entry), dtstart.value->hour, 
dtstart.value->minute);
+
+  /* end date */
+  e_cal_component_get_dtend (priv->component, &dtend);
+  if (dtend.value != NULL)
     {
-      dtend.value->hour = 0;
-      dtend.value->minute = 0;
+      gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry),
+                                dtend.value->day, dtend.value->month, dtend.value->year);
+      all_day = (dtstart.value->is_date == 1 && dtend.value->is_date == 1);
+
+      if (!all_day)
+        gcal_time_entry_set_time (GCAL_TIME_ENTRY (priv->end_time_entry), dtend.value->hour, 
dtend.value->minute);
+    }
+  else
+    {
+      gcal_date_entry_set_date (GCAL_DATE_ENTRY (priv->end_date_entry),
+                                dtstart.value->day, dtstart.value->month, dtstart.value->year);
+      gcal_time_entry_set_time (GCAL_TIME_ENTRY (priv->end_time_entry), dtstart.value->hour, 
dtstart.value->minute);
+      all_day = FALSE;
     }
-  gcal_time_entry_set_time (GCAL_TIME_ENTRY (priv->end_time_entry),
-                            dtend.value->hour,
-                            dtend.value->minute);
 
   e_cal_component_free_datetime (&dtstart);
   e_cal_component_free_datetime (&dtend);
 
+  /* all_day  */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check), all_day);
+
+
   /* location */
   e_cal_component_get_location (priv->component, &const_text);
   gtk_entry_set_text (GTK_ENTRY (priv->location_entry),
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index 4f7f1c1..4cae475 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -796,20 +796,23 @@ gcal_event_widget_new_from_data (GcalEventData *data)
 
   /* end date */
   e_cal_component_get_dtend (priv->component, &dt);
-  date = gcal_dup_icaltime (dt.value);
+  if (dt.value != NULL)
+    {
+      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;
+      /* 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);
+      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_all_day */
+      gcal_event_widget_set_all_day (event, start_is_date && end_is_date);
+    }
 
   /* set_has_reminders */
   gcal_event_widget_set_has_reminders (
@@ -900,7 +903,8 @@ gcal_event_widget_set_end_date (GcalEventWidget    *event,
  * gcal_event_widget_get_end_date:
  * @event: a #GcalEventWidget
  *
- * Return the end date of the event
+ * Return the end date of the event. If the event has no end_date
+ * (as Google does on 0 sec events) %NULL will be returned
  *
  * Returns: (transfer full): Release with g_free()
  **/
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index 3bc65fb..b741fbe 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -128,6 +128,9 @@ gcal_dup_icaltime (const icaltimetype *date)
 {
   icaltimetype *new_date;
 
+  if (date == NULL)
+    return NULL;
+
   new_date= g_new (icaltimetype, 1);
   new_date->year = date->year;
   new_date->month = date->month;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]