year-view: Read show-weekdate from GNOME Shell
Year view always shows week numbers and by design team the default show not display them. This patch adds support to read "show week numbers" setting from GNOME Shell (org.gnome.shell.calendar::show-weekdate) and to change year-view accordingly. https://bugzilla.gnome.org/show_bug.cgi?id=763251
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
465d786ae8
commit
32c5c824e3
+52
-15
@@ -87,6 +87,10 @@ struct _GcalYearView
|
||||
*/
|
||||
gboolean use_24h_format;
|
||||
|
||||
/* show week numbers from GNOME Shell settings */
|
||||
GSettings *shell_settings;
|
||||
gboolean show_week_numbers;
|
||||
|
||||
/* text direction factors */
|
||||
gint k;
|
||||
|
||||
@@ -100,6 +104,7 @@ struct _GcalYearView
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DATE,
|
||||
PROP_SHOW_WEEK_NUMBERS,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
@@ -836,24 +841,27 @@ draw_month_grid (GcalYearView *year_view,
|
||||
else
|
||||
*weeks_counter = *weeks_counter + 1;
|
||||
|
||||
nr_week = g_strdup_printf ("%d", *weeks_counter);
|
||||
if (year_view->show_week_numbers)
|
||||
{
|
||||
nr_week = g_strdup_printf ("%d", *weeks_counter);
|
||||
|
||||
pango_layout_set_text (layout, nr_week, -1);
|
||||
pango_layout_get_pixel_size (layout, &layout_width, &layout_height);
|
||||
box_padding_top = (box_side - layout_height) / 2.0 > 0 ? (box_side - layout_height) / 2.0 : 0;
|
||||
box_padding_start = (box_side - layout_width) / 2.0 > 0 ? (box_side - layout_width) / 2.0 : 0;
|
||||
pango_layout_set_text (layout, nr_week, -1);
|
||||
pango_layout_get_pixel_size (layout, &layout_width, &layout_height);
|
||||
box_padding_top = (box_side - layout_height) / 2.0 > 0 ? (box_side - layout_height) / 2.0 : 0;
|
||||
box_padding_start = (box_side - layout_width) / 2.0 > 0 ? (box_side - layout_width) / 2.0 : 0;
|
||||
|
||||
gtk_render_background (context, cr,
|
||||
x + sw * box_padding_top + year_view->k * (8 * box_side - layout_height) - WEEK_NUMBER_MARGIN,
|
||||
box_side * (i + 1) + y + box_padding_top - WEEK_NUMBER_MARGIN,
|
||||
layout_height + WEEK_NUMBER_MARGIN * 2, layout_height + WEEK_NUMBER_MARGIN * 2);
|
||||
gtk_render_background (context, cr,
|
||||
x + sw * box_padding_top + year_view->k * (8 * box_side - layout_height) - WEEK_NUMBER_MARGIN,
|
||||
box_side * (i + 1) + y + box_padding_top - WEEK_NUMBER_MARGIN,
|
||||
layout_height + WEEK_NUMBER_MARGIN * 2, layout_height + WEEK_NUMBER_MARGIN * 2);
|
||||
|
||||
gtk_render_layout (context, cr,
|
||||
x + sw * box_padding_start + year_view->k * (8 * box_side - layout_width),
|
||||
box_side * (i + 1) + y + box_padding_top,
|
||||
layout);
|
||||
gtk_render_layout (context, cr,
|
||||
x + sw * box_padding_start + year_view->k * (8 * box_side - layout_width),
|
||||
box_side * (i + 1) + y + box_padding_top,
|
||||
layout);
|
||||
|
||||
g_free (nr_week);
|
||||
g_free (nr_week);
|
||||
}
|
||||
}
|
||||
gtk_style_context_restore (context);
|
||||
|
||||
@@ -1091,6 +1099,8 @@ gcal_year_view_finalize (GObject *object)
|
||||
|
||||
g_clear_pointer (&year_view->date, g_free);
|
||||
|
||||
g_clear_object (&year_view->shell_settings);
|
||||
|
||||
G_OBJECT_CLASS (gcal_year_view_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
@@ -1108,6 +1118,10 @@ gcal_year_view_get_property (GObject *object,
|
||||
g_value_set_boxed (value, self->date);
|
||||
break;
|
||||
|
||||
case PROP_SHOW_WEEK_NUMBERS:
|
||||
g_value_set_boolean (value, self->show_week_numbers);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
@@ -1119,10 +1133,20 @@ gcal_year_view_set_property (GObject *object,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalYearView *self = GCAL_YEAR_VIEW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DATE:
|
||||
update_date (GCAL_YEAR_VIEW (object), g_value_dup_boxed (value));
|
||||
update_date (self, g_value_dup_boxed (value));
|
||||
break;
|
||||
|
||||
case PROP_SHOW_WEEK_NUMBERS:
|
||||
if (self->show_week_numbers != g_value_get_boolean (value))
|
||||
{
|
||||
self->show_week_numbers = g_value_get_boolean (value);
|
||||
g_object_notify (object, "show-week-numbers");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1425,6 +1449,14 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
|
||||
|
||||
g_object_class_override_property (object_class, PROP_DATE, "active-date");
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SHOW_WEEK_NUMBERS,
|
||||
g_param_spec_boolean ("show-week-numbers",
|
||||
"Show Week Numbers",
|
||||
"Show Week Numbers Column",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
/* FIXME: it will problably go back to GcalView */
|
||||
signals[EVENT_ACTIVATED] = g_signal_new ("event-activated", GCAL_TYPE_YEAR_VIEW, G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
@@ -1469,6 +1501,11 @@ gcal_year_view_init (GcalYearView *self)
|
||||
self->end_selected_date = g_new0 (icaltimetype, 1);
|
||||
self->end_selected_date->zone = e_cal_util_get_system_timezone ();
|
||||
|
||||
/* bind GNOME Shell' show week numbers property to GNOME Calendar's one */
|
||||
self->shell_settings = g_settings_new ("org.gnome.shell.calendar");
|
||||
g_settings_bind (self->shell_settings, "show-weekdate", self, "show-week-numbers", G_SETTINGS_BIND_DEFAULT);
|
||||
g_signal_connect_swapped (self->shell_settings, "changed::show-weekdate", G_CALLBACK (gtk_widget_queue_draw), self);
|
||||
|
||||
gtk_list_box_set_header_func (GTK_LIST_BOX (self->events_sidebar), update_sidebar_headers, self, NULL);
|
||||
gtk_list_box_set_sort_func (GTK_LIST_BOX (self->events_sidebar), sidebar_sort_func, NULL, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user