Migrated GcalMonthView to icaltimetype instead of GDate
This commit is contained in:
+44
-46
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "gcal-month-view.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
|
||||
#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_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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define __GCAL_UTILS_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libical/icaltime.h>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
+4
-2
@@ -29,6 +29,8 @@
|
||||
|
||||
#include <libedataserverui/e-cell-renderer-color.h>
|
||||
|
||||
#include <libical/icaltime.h>
|
||||
|
||||
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]);
|
||||
|
||||
Reference in New Issue
Block a user