From 4454e83f9f41531677b0b54dbab10e03c102fd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Fri, 4 May 2012 00:10:57 -0400 Subject: [PATCH] Migrated GcalMonthView to icaltimetype instead of GDate --- src/gcal-month-view.c | 90 +++++++++++++++++++++---------------------- src/gcal-month-view.h | 11 +++--- src/gcal-utils.c | 20 ++++++++++ src/gcal-utils.h | 3 ++ src/gcal-window.c | 6 ++- 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c index 34504c81..267a99a1 100644 --- a/src/gcal-month-view.c +++ b/src/gcal-month-view.c @@ -19,6 +19,7 @@ */ #include "gcal-month-view.h" +#include "gcal-utils.h" #include @@ -30,12 +31,12 @@ enum struct _GcalMonthViewPrivate { - GDate *date; + icaltimetype *date; - gint header_font_size; + gint header_font_size; - gdouble vertical_step; - gdouble horizontal_step; + gdouble vertical_step; + gdouble horizontal_step; }; /* this will need translation */ @@ -88,15 +89,14 @@ static void gcal_month_view_class_init (GcalMonthViewClass *klass) object_class->finalize = gcal_month_view_finalize; g_object_class_install_property (object_class, PROP_DATE, - g_param_spec_boxed ("date", - "date", - _("Date"), - G_TYPE_DATE, - G_PARAM_CONSTRUCT | - G_PARAM_READWRITE | - G_PARAM_STATIC_NAME | - G_PARAM_STATIC_NICK | - G_PARAM_STATIC_BLURB)); + g_param_spec_pointer ("date", + "date", + _("Date"), + G_PARAM_CONSTRUCT | + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_BLURB | + G_PARAM_STATIC_NICK)); g_type_class_add_private ((gpointer)klass, sizeof (GcalMonthViewPrivate)); } @@ -123,10 +123,10 @@ gcal_month_view_set_property (GObject *object, switch (property_id) { case PROP_DATE: - if (priv->date) - g_date_free (priv->date); + if (priv->date != NULL) + g_free (priv->date); - priv->date = g_value_dup_boxed (value); + priv->date = g_value_get_pointer (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -145,7 +145,7 @@ gcal_month_view_get_property (GObject *object, switch (property_id) { case PROP_DATE: - g_value_set_boxed (value, priv->date); + g_value_set_pointer (value, priv->date); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -196,8 +196,8 @@ gcal_month_view_finalize (GObject *object) { GcalMonthViewPrivate *priv = GCAL_MONTH_VIEW (object)->priv; - if (priv->date) - g_date_free (priv->date); + if (priv->date != NULL) + g_free (priv->date); /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (gcal_month_view_parent_class)->finalize (object); @@ -223,8 +223,7 @@ _gcal_month_view_draw_month_grid (GcalMonthView *month_view, gint font_height; guint8 n_days_in_month; - GDate *first_of_month; - GDateWeekday lapse; + icaltimetype *first_of_month; gint space; PangoLayout *layout; @@ -246,16 +245,14 @@ _gcal_month_view_draw_month_grid (GcalMonthView *month_view, priv->vertical_step = (gdouble) height / 5; priv->horizontal_step= (gdouble) width / 7; - n_days_in_month = g_date_get_days_in_month (g_date_get_month (priv->date), - g_date_get_year (priv->date)); + n_days_in_month = icaltime_days_in_month (priv->date->month, + priv->date->year); - first_of_month = g_date_new_dmy (1, - g_date_get_month (priv->date), - g_date_get_year (priv->date)); + first_of_month = gcal_dup_icaltime (priv->date); + first_of_month->day = 1; - lapse = g_date_get_weekday (first_of_month); - space = (lapse == 7 ? 1 : 1 - lapse); - g_date_free (first_of_month); + space = - icaltime_day_of_week (*first_of_month) + 2; + g_free (first_of_month); for (i = 0; i < 7; i++) { @@ -311,10 +308,8 @@ _gcal_month_view_draw_month_grid (GcalMonthView *month_view, * Returns: (transfer full): **/ GtkWidget* -gcal_month_view_new (GDate *date) +gcal_month_view_new (icaltimetype *date) { - g_return_val_if_fail (g_date_valid (date), NULL); - return g_object_new (GCAL_TYPE_MONTH_VIEW, "date", date, NULL); } @@ -325,14 +320,17 @@ gcal_month_view_new (GDate *date) * Return value: the first day of the month * Returns: (transfer full): **/ -GDate* +icaltimetype* gcal_month_view_get_initial_date (GcalMonthView *view) { - GcalMonthViewPrivate *priv = view->priv; - GDate *initial = g_date_new_dmy (1, - g_date_get_month (priv->date), - g_date_get_year (priv->date)); - return initial; + GcalMonthViewPrivate *priv; + icaltimetype *new_date; + + priv = view->priv; + new_date = gcal_dup_icaltime (priv->date); + new_date->day = 1; + + return new_date; } /** @@ -342,14 +340,14 @@ gcal_month_view_get_initial_date (GcalMonthView *view) * Return value: the last day of the month * Returns: (transfer full): **/ -GDate* +icaltimetype* gcal_month_view_get_final_date (GcalMonthView *view) { - GcalMonthViewPrivate *priv = view->priv; - GDate *last = g_date_new_dmy (g_date_get_days_in_month ( - g_date_get_month (priv->date), - g_date_get_year (priv->date)), - g_date_get_month (priv->date), - g_date_get_year (priv->date)); - return last; + GcalMonthViewPrivate *priv; + icaltimetype *new_date; + + priv = view->priv; + new_date = gcal_dup_icaltime (priv->date); + new_date->day = icaltime_days_in_month (priv->date->month, priv->date->year); + return new_date; } diff --git a/src/gcal-month-view.h b/src/gcal-month-view.h index d02e0d00..01f789ad 100644 --- a/src/gcal-month-view.h +++ b/src/gcal-month-view.h @@ -22,8 +22,9 @@ #include -G_BEGIN_DECLS +#include +G_BEGIN_DECLS #define GCAL_TYPE_MONTH_VIEW (gcal_month_view_get_type ()) #define GCAL_MONTH_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_MONTH_VIEW, GcalMonthView)) @@ -49,12 +50,12 @@ struct _GcalMonthViewClass GtkWidgetClass parent_class; }; -GType gcal_month_view_get_type (void); +GType gcal_month_view_get_type (void); -GtkWidget* gcal_month_view_new (GDate *date); +GtkWidget* gcal_month_view_new (icaltimetype *date); -GDate* gcal_month_view_get_initial_date (GcalMonthView *view); -GDate* gcal_month_view_get_final_date (GcalMonthView *view); +icaltimetype* gcal_month_view_get_initial_date (GcalMonthView *view); +icaltimetype* gcal_month_view_get_final_date (GcalMonthView *view); G_END_DECLS diff --git a/src/gcal-utils.c b/src/gcal-utils.c index 251ebf8a..bab24fc8 100644 --- a/src/gcal-utils.c +++ b/src/gcal-utils.c @@ -84,6 +84,26 @@ gcal_get_group_name (const gchar *base_uri) return "External"; } +icaltimetype* +gcal_dup_icaltime (icaltimetype *date) +{ + icaltimetype *new_date; + + new_date= g_new (icaltimetype, 1); + new_date->year = date->year; + new_date->month = date->month; + new_date->day = date->day; + new_date->hour = date->hour; + new_date->minute = date->minute; + new_date->second = date->second; + new_date->is_utc = date->is_utc; + new_date->is_date = date->is_date; + new_date->is_daylight = date->is_daylight; + new_date->zone = date->zone; + + return new_date; +} + void gcal_print_date (gchar *str, GDate *date) diff --git a/src/gcal-utils.h b/src/gcal-utils.h index 4a1db428..baa34c04 100644 --- a/src/gcal-utils.h +++ b/src/gcal-utils.h @@ -21,6 +21,7 @@ #define __GCAL_UTILS_H__ #include +#include typedef enum { @@ -37,6 +38,8 @@ void gcal_gtk_tree_view_set_activate_on_single_click (GtkTreeView const gchar* gcal_get_group_name (const gchar *base_uri); +icaltimetype* gcal_dup_icaltime (icaltimetype *date); + void gcal_print_date (gchar *str, GDate *date); diff --git a/src/gcal-window.c b/src/gcal-window.c index 674e932a..d0088a56 100644 --- a/src/gcal-window.c +++ b/src/gcal-window.c @@ -29,6 +29,8 @@ #include +#include + struct _GcalWindowPrivate { ClutterActor *main_toolbar; @@ -162,8 +164,8 @@ gcal_window_constructed (GObject *object) CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL); - GDate *date = g_date_new (); - g_date_set_time_t (date, time (NULL)); + icaltimetype *date = g_new (icaltimetype, 1); + *date = icaltime_today (); priv->views[GCAL_VIEW_TYPE_MONTHLY] = gcal_month_view_new (date); context = gtk_widget_get_style_context (priv->views[GCAL_VIEW_TYPE_MONTHLY]);