utils: use GDateTime to build component

As part of our epic journey to GDateTime, and to
prepare ground for the future work, use GDateTime
as arguments for building the ECalComponent.
This commit is contained in:
Georges Basile Stavracas Neto
2016-02-16 11:54:35 -02:00
parent 6a64384971
commit 3c0c3646f4
5 changed files with 73 additions and 60 deletions
+16 -23
View File
@@ -239,9 +239,6 @@ show_popover_for_position (GcalMonthView *view,
gint start_day, end_day;
icaltimetype *start_date;
icaltimetype *end_date = NULL;
widget = GTK_WIDGET (view);
priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (widget));
ppriv = GCAL_SUBSCRIBER_VIEW (widget)->priv;
@@ -268,26 +265,23 @@ show_popover_for_position (GcalMonthView *view,
}
else
{
start_date = gcal_dup_icaltime (priv->date);
start_date->day = start_day;
start_date->is_date = 1;
GDateTime *start_dt, *end_dt;
end_date = gcal_dup_icaltime (priv->date);
end_date->day = end_day;
end_date->is_date = 1;
if (start_date->day > end_date->day)
start_dt = g_date_time_new_local (priv->date->year, priv->date->month, start_day, 0, 0, 0);
end_dt = g_date_time_new_local (priv->date->year, priv->date->month, end_day + 1, 0, 0, 0);
/* Swap dates if start > end */
if (start_day > end_day)
{
gint day = start_date->day;
start_date->day = end_date->day;
end_date->day = day;
GDateTime *aux = start_dt;
start_dt = end_dt;
end_dt = aux;
}
end_date->day += 1;
g_signal_emit_by_name (GCAL_VIEW (widget), "create-event", start_dt, end_dt, x, y);
g_signal_emit_by_name (GCAL_VIEW (widget), "create-event", start_date, end_date, x, y);
g_free (start_date);
g_free (end_date);
g_date_time_unref (start_dt);
g_date_time_unref (end_dt);
}
gtk_widget_queue_draw (widget);
@@ -747,19 +741,18 @@ add_new_event_button_cb (GtkWidget *button,
{
GcalMonthViewPrivate *priv;
gint day;
icaltimetype *start_date;
GDateTime *start_date;
priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (user_data));
gtk_widget_hide (priv->overflow_popover);
day = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (priv->overflow_popover), "selected-day"));
start_date = gcal_dup_icaltime (priv->date);
start_date->day = day;
start_date->is_date = 1;
start_date = g_date_time_new_local (priv->date->year, priv->date->month, day, 0, 0, 0);
g_signal_emit_by_name (GCAL_VIEW (user_data), "create-event-detailed", start_date, NULL);
g_free (start_date);
g_date_time_unref (start_date);
}
static void
+33 -17
View File
@@ -416,33 +416,49 @@ get_first_weekday (void)
* Returns: (Transfer full): an {@link ECalComponent} object
**/
ECalComponent*
build_component_from_details (const gchar *summary,
const icaltimetype *initial_date,
const icaltimetype *final_date)
build_component_from_details (const gchar *summary,
GDateTime *initial_date,
GDateTime *final_date)
{
ECalComponent *event;
ECalComponentDateTime dt;
ECalComponentText summ;
GDateTime *utc_start, *utc_end;
gboolean all_day;
event = e_cal_component_new ();
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
dt.value = (icaltimetype*) initial_date;
/*
* Check if the event is all day. Notice that it can be all day even
* without the final date.
*/
all_day = datetime_is_date (initial_date) && (final_date ? datetime_is_date (final_date) : TRUE);
/* Start date */
utc_start = g_date_time_to_utc (initial_date);
dt.value = datetime_to_icaltime (utc_start);
dt.value->is_date = all_day;
dt.tzid = format_utc_offset (g_date_time_get_utc_offset (initial_date));
e_cal_component_set_dtstart (event, &dt);
if (final_date != NULL)
{
dt.value = (icaltimetype*) final_date;
e_cal_component_set_dtend (event, &dt);
}
else
{
icaltimetype *dt_end = gcal_dup_icaltime (initial_date);
icaltime_adjust (dt_end, 1, 0, 0, 0);
dt.value = dt_end;
e_cal_component_set_dtend (event, &dt);
g_free (dt_end);
}
e_cal_component_free_datetime (&dt);
g_date_time_unref (utc_start);
/* End date */
if (!final_date)
final_date = g_date_time_add_days (initial_date, 1);
utc_end = g_date_time_to_utc (final_date);
dt.value = datetime_to_icaltime (utc_end);
dt.value->is_date = all_day;
dt.tzid = format_utc_offset (g_date_time_get_utc_offset (final_date));
e_cal_component_set_dtend (event, &dt);
e_cal_component_free_datetime (&dt);
g_date_time_unref (utc_end);
summ.altrep = NULL;
summ.value = summary;
+2 -2
View File
@@ -88,8 +88,8 @@ gchar* get_uuid_from_component (ESource
gint get_first_weekday (void);
ECalComponent* build_component_from_details (const gchar *summary,
const icaltimetype *initial_date,
const icaltimetype *final_date);
GDateTime *initial_date,
GDateTime *final_date);
gint icaltime_compare_date (const icaltimetype *date1,
const icaltimetype *date2);
+7 -7
View File
@@ -40,8 +40,8 @@ typedef struct
{
gint x;
gint y;
icaltimetype *start_date;
icaltimetype *end_date;
GDateTime *start_date;
GDateTime *end_date;
} NewEventData;
typedef struct
@@ -694,17 +694,17 @@ show_new_event_widget (GcalView *view,
if (window->event_creation_data != NULL)
{
g_free (window->event_creation_data->start_date);
g_free (window->event_creation_data->end_date);
g_date_time_unref (window->event_creation_data->start_date);
g_date_time_unref (window->event_creation_data->end_date);
g_free (window->event_creation_data);
}
window->event_creation_data = g_new0 (NewEventData, 1);
window->event_creation_data->x = x;
window->event_creation_data->y = y;
window->event_creation_data->start_date = gcal_dup_icaltime (start_span);
window->event_creation_data->start_date = g_date_time_ref (start_span);
if (end_span != NULL)
window->event_creation_data->end_date = gcal_dup_icaltime (end_span);
window->event_creation_data->end_date = g_date_time_ref (end_span);
g_debug ("[show_new_event] position (%f, %f)", x, y);
/* Setup new event widget data */
@@ -1111,7 +1111,7 @@ create_event_detailed_cb (GcalView *view,
ECalComponent *comp;
GcalEvent *event;
comp = build_component_from_details ("", (icaltimetype*) start_span, (icaltimetype*) end_span);
comp = build_component_from_details ("", start_span, end_span);
event = gcal_event_new (gcal_manager_get_default_source (window->manager), comp);
gcal_edit_dialog_set_event_is_new (GCAL_EDIT_DIALOG (window->edit_dialog), TRUE);
+15 -11
View File
@@ -1031,29 +1031,33 @@ static void
add_event_clicked_cb (GcalYearView *year_view,
GtkButton *button)
{
icaltimetype *start_date, *end_date = NULL;
GDateTime *start_date, *end_date = NULL;
if (year_view->start_selected_date->day == 0)
{
start_date = gcal_dup_icaltime (year_view->current_date);
start_date = g_date_time_new_local (year_view->current_date->year,
year_view->current_date->month,
year_view->current_date->day,
0, 0, 0);
}
else
{
start_date = gcal_dup_icaltime (year_view->start_selected_date);
end_date = gcal_dup_icaltime (year_view->end_selected_date);
end_date->day += 1;
*end_date = icaltime_normalize (*end_date);
end_date->is_date = 1;
icaltimetype *dtstart, *dtend;
dtstart = year_view->start_selected_date;
dtend = year_view->end_selected_date;
start_date = g_date_time_new_local (dtstart->year, dtstart->month, dtstart->day, 0, 0, 0);
end_date = g_date_time_new_local (dtend->year, dtend->month, dtend->day + 1, 0, 0, 0);
}
if (year_view->popover_mode)
gtk_widget_hide (year_view->popover);
start_date->is_date = 1;
g_signal_emit_by_name (GCAL_VIEW (year_view), "create-event-detailed", start_date, end_date);
g_free (start_date);
if (end_date != NULL)
g_free (end_date);
g_clear_pointer (&start_date, g_date_time_unref);
g_clear_pointer (&end_date, g_date_time_unref);
}
static void