Migrated GcalMonthView to icaltimetype instead of GDate

This commit is contained in:
Erick Pérez Castellanos
2012-05-04 00:10:57 -04:00
parent 04be11a32c
commit 4454e83f9f
5 changed files with 77 additions and 53 deletions
+44 -46
View File
@@ -19,6 +19,7 @@
*/ */
#include "gcal-month-view.h" #include "gcal-month-view.h"
#include "gcal-utils.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
@@ -30,12 +31,12 @@ enum
struct _GcalMonthViewPrivate struct _GcalMonthViewPrivate
{ {
GDate *date; icaltimetype *date;
gint header_font_size; gint header_font_size;
gdouble vertical_step; gdouble vertical_step;
gdouble horizontal_step; gdouble horizontal_step;
}; };
/* this will need translation */ /* this will need translation */
@@ -88,15 +89,14 @@ static void gcal_month_view_class_init (GcalMonthViewClass *klass)
object_class->finalize = gcal_month_view_finalize; object_class->finalize = gcal_month_view_finalize;
g_object_class_install_property (object_class, PROP_DATE, g_object_class_install_property (object_class, PROP_DATE,
g_param_spec_boxed ("date", g_param_spec_pointer ("date",
"date", "date",
_("Date"), _("Date"),
G_TYPE_DATE, G_PARAM_CONSTRUCT |
G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_NICK));
G_PARAM_STATIC_BLURB));
g_type_class_add_private ((gpointer)klass, sizeof (GcalMonthViewPrivate)); g_type_class_add_private ((gpointer)klass, sizeof (GcalMonthViewPrivate));
} }
@@ -123,10 +123,10 @@ gcal_month_view_set_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_DATE: case PROP_DATE:
if (priv->date) if (priv->date != NULL)
g_date_free (priv->date); g_free (priv->date);
priv->date = g_value_dup_boxed (value); priv->date = g_value_get_pointer (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -145,7 +145,7 @@ gcal_month_view_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_DATE: case PROP_DATE:
g_value_set_boxed (value, priv->date); g_value_set_pointer (value, priv->date);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 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; GcalMonthViewPrivate *priv = GCAL_MONTH_VIEW (object)->priv;
if (priv->date) if (priv->date != NULL)
g_date_free (priv->date); g_free (priv->date);
/* Chain up to parent's finalize() method. */ /* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (gcal_month_view_parent_class)->finalize (object); 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; gint font_height;
guint8 n_days_in_month; guint8 n_days_in_month;
GDate *first_of_month; icaltimetype *first_of_month;
GDateWeekday lapse;
gint space; gint space;
PangoLayout *layout; PangoLayout *layout;
@@ -246,16 +245,14 @@ _gcal_month_view_draw_month_grid (GcalMonthView *month_view,
priv->vertical_step = (gdouble) height / 5; priv->vertical_step = (gdouble) height / 5;
priv->horizontal_step= (gdouble) width / 7; priv->horizontal_step= (gdouble) width / 7;
n_days_in_month = g_date_get_days_in_month (g_date_get_month (priv->date), n_days_in_month = icaltime_days_in_month (priv->date->month,
g_date_get_year (priv->date)); priv->date->year);
first_of_month = g_date_new_dmy (1, first_of_month = gcal_dup_icaltime (priv->date);
g_date_get_month (priv->date), first_of_month->day = 1;
g_date_get_year (priv->date));
lapse = g_date_get_weekday (first_of_month); space = - icaltime_day_of_week (*first_of_month) + 2;
space = (lapse == 7 ? 1 : 1 - lapse); g_free (first_of_month);
g_date_free (first_of_month);
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
{ {
@@ -311,10 +308,8 @@ _gcal_month_view_draw_month_grid (GcalMonthView *month_view,
* Returns: (transfer full): * Returns: (transfer full):
**/ **/
GtkWidget* 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); 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 * Return value: the first day of the month
* Returns: (transfer full): * Returns: (transfer full):
**/ **/
GDate* icaltimetype*
gcal_month_view_get_initial_date (GcalMonthView *view) gcal_month_view_get_initial_date (GcalMonthView *view)
{ {
GcalMonthViewPrivate *priv = view->priv; GcalMonthViewPrivate *priv;
GDate *initial = g_date_new_dmy (1, icaltimetype *new_date;
g_date_get_month (priv->date),
g_date_get_year (priv->date)); priv = view->priv;
return initial; 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 * Return value: the last day of the month
* Returns: (transfer full): * Returns: (transfer full):
**/ **/
GDate* icaltimetype*
gcal_month_view_get_final_date (GcalMonthView *view) gcal_month_view_get_final_date (GcalMonthView *view)
{ {
GcalMonthViewPrivate *priv = view->priv; GcalMonthViewPrivate *priv;
GDate *last = g_date_new_dmy (g_date_get_days_in_month ( icaltimetype *new_date;
g_date_get_month (priv->date),
g_date_get_year (priv->date)), priv = view->priv;
g_date_get_month (priv->date), new_date = gcal_dup_icaltime (priv->date);
g_date_get_year (priv->date)); new_date->day = icaltime_days_in_month (priv->date->month, priv->date->year);
return last; return new_date;
} }
+6 -5
View File
@@ -22,8 +22,9 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
G_BEGIN_DECLS #include <libical/icaltime.h>
G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_VIEW (gcal_month_view_get_type ()) #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)) #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; 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); icaltimetype* gcal_month_view_get_initial_date (GcalMonthView *view);
GDate* gcal_month_view_get_final_date (GcalMonthView *view); icaltimetype* gcal_month_view_get_final_date (GcalMonthView *view);
G_END_DECLS G_END_DECLS
+20
View File
@@ -84,6 +84,26 @@ gcal_get_group_name (const gchar *base_uri)
return "External"; 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 void
gcal_print_date (gchar *str, gcal_print_date (gchar *str,
GDate *date) GDate *date)
+3
View File
@@ -21,6 +21,7 @@
#define __GCAL_UTILS_H__ #define __GCAL_UTILS_H__
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libical/icaltime.h>
typedef enum 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); const gchar* gcal_get_group_name (const gchar *base_uri);
icaltimetype* gcal_dup_icaltime (icaltimetype *date);
void gcal_print_date (gchar *str, void gcal_print_date (gchar *str,
GDate *date); GDate *date);
+4 -2
View File
@@ -29,6 +29,8 @@
#include <libedataserverui/e-cell-renderer-color.h> #include <libedataserverui/e-cell-renderer-color.h>
#include <libical/icaltime.h>
struct _GcalWindowPrivate struct _GcalWindowPrivate
{ {
ClutterActor *main_toolbar; ClutterActor *main_toolbar;
@@ -162,8 +164,8 @@ gcal_window_constructed (GObject *object)
CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL,
CLUTTER_BIN_ALIGNMENT_FILL); CLUTTER_BIN_ALIGNMENT_FILL);
GDate *date = g_date_new (); icaltimetype *date = g_new (icaltimetype, 1);
g_date_set_time_t (date, time (NULL)); *date = icaltime_today ();
priv->views[GCAL_VIEW_TYPE_MONTHLY] = gcal_month_view_new (date); priv->views[GCAL_VIEW_TYPE_MONTHLY] = gcal_month_view_new (date);
context = gtk_widget_get_style_context (priv->views[GCAL_VIEW_TYPE_MONTHLY]); context = gtk_widget_get_style_context (priv->views[GCAL_VIEW_TYPE_MONTHLY]);