[gnome-calendar] week-view: add first_weekday setting to view
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] week-view: add first_weekday setting to view
- Date: Thu, 4 Dec 2014 22:42:28 +0000 (UTC)
commit 2cecaf9337928b84bc6bddfdd3251cf2466928b5
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Fri Nov 7 16:47:23 2014 -0500
week-view: add first_weekday setting to view
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=703317
src/gcal-week-view.c | 49 +++++++++++++++++++++++++++++++++++++------------
src/gcal-week-view.h | 3 +++
src/gcal-window.c | 3 +++
3 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/src/gcal-week-view.c b/src/gcal-week-view.c
index 24f005a..ffcbca3 100644
--- a/src/gcal-week-view.c
+++ b/src/gcal-week-view.c
@@ -60,6 +60,7 @@ typedef struct
* Every child added to the list placed in the position
* of it corresponding cell number.
* The cell number is calculated in _add method.
+ * day[0] Represents the first_weekday according to locale
*/
GList *days [7];
@@ -68,6 +69,10 @@ typedef struct
GtkWidget *vscrollbar;
+ /* first day of the week according to user locale, being
+ * 0 for Sunday, 1 for Monday and so on */
+ gint first_weekday;
+
/* property */
icaltimetype *date;
GcalManager *manager; /* weak referenced */
@@ -877,9 +882,9 @@ gcal_week_view_add (GtkContainer *container,
/* Check if it's already added for date */
date = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (widget));
- day = icaltime_day_of_week (*date);
+ day = (icaltime_day_of_week (*date) - priv->first_weekday + 6) % 7;
- for (l = priv->days[day - 1]; l != NULL; l = l->next)
+ for (l = priv->days[day]; l != NULL; l = l->next)
{
GtkWidget *event;
@@ -913,7 +918,7 @@ gcal_week_view_add (GtkContainer *container,
gtk_widget_set_parent_window (widget, priv->grid_window);
}
- priv->days[day - 1] = g_list_append (priv->days[day - 1], new_child);
+ priv->days[day] = g_list_append (priv->days[day], new_child);
gtk_widget_set_parent (widget, GTK_WIDGET (container));
g_signal_connect (widget,
@@ -938,16 +943,16 @@ gcal_week_view_remove (GtkContainer *container,
priv = gcal_week_view_get_instance_private (GCAL_WEEK_VIEW (container));
date = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (widget));
- day = icaltime_day_of_week (*date);
+ day = (icaltime_day_of_week (*date) - priv->first_weekday + 6) % 7;
- for (l = priv->days[day - 1]; l != NULL; l = l->next)
+ for (l = priv->days[day]; l != NULL; l = l->next)
{
GcalWeekViewChild *child;
child = (GcalWeekViewChild*) l->data;
if (child->widget == widget)
{
- priv->days[day - 1] = g_list_remove (priv->days[day - 1], child);
+ priv->days[day] = g_list_remove (priv->days[day], child);
g_free (child);
break;
}
@@ -1000,6 +1005,7 @@ gcal_week_view_draw_header (GcalWeekView *view,
GtkAllocation *alloc,
GtkBorder *padding)
{
+ GcalWeekViewPrivate *priv;
GtkWidget *widget;
GtkStyleContext *context;
GtkStateFlags state;
@@ -1018,6 +1024,7 @@ gcal_week_view_draw_header (GcalWeekView *view,
cairo_pattern_t *pattern;
+ priv = gcal_week_view_get_instance_private (view);
widget = GTK_WIDGET (view);
cairo_save (cr);
@@ -1065,8 +1072,8 @@ gcal_week_view_draw_header (GcalWeekView *view,
start_of_week->year);
}
- weekday_abv = gcal_get_weekday (i);
- weekday_header = g_strdup_printf ("%s %d",weekday_abv, n_day);
+ weekday_abv = gcal_get_weekday ((i + priv->first_weekday) % 7);
+ weekday_header = g_strdup_printf ("%s %d", weekday_abv, n_day);
pango_layout_set_text (layout, weekday_header, -1);
pango_cairo_update_layout (cr, layout);
@@ -1283,8 +1290,8 @@ gcal_week_view_get_initial_date (GcalView *view)
priv = gcal_week_view_get_instance_private (GCAL_WEEK_VIEW(view));
new_date = g_new0 (icaltimetype, 1);
*new_date = icaltime_from_day_of_year (
- icaltime_day_of_year (*(priv->date)) - icaltime_day_of_week (*(priv->date)) + 1,
- priv->date->year);
+ icaltime_start_doy_week (*(priv->date), priv->first_weekday + 1),
+ priv->date->year);
new_date->is_date = 0;
new_date->hour = 0;
new_date->minute = 0;
@@ -1310,8 +1317,8 @@ gcal_week_view_get_final_date (GcalView *view)
priv = gcal_week_view_get_instance_private (GCAL_WEEK_VIEW(view));
new_date = g_new0 (icaltimetype, 1);
*new_date = icaltime_from_day_of_year (
- icaltime_day_of_year (*(priv->date)) + 7 - icaltime_day_of_week (*(priv->date)),
- priv->date->year);
+ icaltime_start_doy_week (*(priv->date), priv->first_weekday + 1) + 6,
+ priv->date->year);
new_date->is_date = 0;
new_date->hour = 23;
new_date->minute = 59;
@@ -1407,3 +1414,21 @@ gcal_week_view_new (GcalManager *manager)
{
return g_object_new (GCAL_TYPE_WEEK_VIEW, "manager", manager, NULL);
}
+
+/**
+ * gcal_week_view_set_first_weekday:
+ * @view:
+ * @day_nr:
+ *
+ * Set the first day of the week according to the locale, being
+ * 0 for Sunday, 1 for Monday and so on.
+ **/
+void
+gcal_week_view_set_first_weekday (GcalWeekView *view,
+ gint day_nr)
+{
+ GcalWeekViewPrivate *priv;
+
+ priv = gcal_week_view_get_instance_private (view);
+ priv->first_weekday = day_nr;
+}
diff --git a/src/gcal-week-view.h b/src/gcal-week-view.h
index ef57773..af9cdef 100644
--- a/src/gcal-week-view.h
+++ b/src/gcal-week-view.h
@@ -50,6 +50,9 @@ GType gcal_week_view_get_type (void);
GtkWidget* gcal_week_view_new (GcalManager *manager);
+void gcal_week_view_set_first_weekday (GcalWeekView *view,
+ gint day_nr);
+
G_END_DECLS
#endif /* __GCAL_WEEK_VIEW_H__ */
diff --git a/src/gcal-window.c b/src/gcal-window.c
index a2389fa..68fced3 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1135,6 +1135,9 @@ gcal_window_constructed (GObject *object)
priv->views[GCAL_WINDOW_VIEW_WEEK] =
gcal_week_view_new (priv->manager);
+ gcal_week_view_set_first_weekday (
+ GCAL_WEEK_VIEW (priv->views[GCAL_WINDOW_VIEW_WEEK]),
+ get_first_weekday ());
gtk_stack_add_titled (GTK_STACK (priv->views_stack),
priv->views[GCAL_WINDOW_VIEW_WEEK],
"week", _("Week"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]