utils: Turn number of weekdays into a macro
While "7" may be obvious in the context of calendaring that it represents the number of week days, it often gives me the impression of it being a magic number when I'm hyperfocused on certain parts of the codebase for several consecutive hours. Turning the number into a macro helps me scan functions much more easily. Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/674>
This commit is contained in:
@@ -199,7 +199,7 @@ gcal_date_chooser_day_set_date (GcalDateChooserDay *self,
|
||||
|
||||
now = g_date_time_new_now (g_date_time_get_timezone (date));
|
||||
today = gcal_date_time_compare_date (date, now) == 0;
|
||||
weekday = g_date_time_get_day_of_week (date) % 7;
|
||||
weekday = g_date_time_get_day_of_week (date) % N_WEEKDAYS;
|
||||
|
||||
if (G_UNLIKELY (today))
|
||||
gtk_widget_add_css_class (widget, "today");
|
||||
|
||||
@@ -34,8 +34,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ROWS 6
|
||||
#define COLS 7
|
||||
#define DAYS 42
|
||||
#define DAYS ROWS * N_WEEKDAYS
|
||||
|
||||
struct _GcalDateChooser
|
||||
{
|
||||
@@ -49,9 +48,9 @@ struct _GcalDateChooser
|
||||
|
||||
GtkWidget *day_grid;
|
||||
GtkWidget *corner;
|
||||
GtkWidget *cols[COLS];
|
||||
GtkWidget *cols[N_WEEKDAYS];
|
||||
GtkWidget *rows[ROWS];
|
||||
GtkWidget *days[ROWS][COLS];
|
||||
GtkWidget *days[ROWS][N_WEEKDAYS];
|
||||
GtkWidget *week[ROWS];
|
||||
|
||||
GDateTime *date;
|
||||
@@ -222,9 +221,9 @@ calendar_compute_days (GcalDateChooser *self)
|
||||
first_day = g_date_time_get_day_of_week (date);
|
||||
g_date_time_unref (date);
|
||||
|
||||
first_day = (first_day + COLS - self->week_start) % COLS;
|
||||
first_day = (first_day + N_WEEKDAYS - self->week_start) % N_WEEKDAYS;
|
||||
if (first_day == 0)
|
||||
first_day = COLS;
|
||||
first_day = N_WEEKDAYS;
|
||||
|
||||
/* Compute days of previous month */
|
||||
if (month > 1)
|
||||
@@ -252,8 +251,8 @@ calendar_compute_days (GcalDateChooser *self)
|
||||
}
|
||||
|
||||
/* Compute days of current month */
|
||||
row = first_day / COLS;
|
||||
col = first_day % COLS;
|
||||
row = first_day / N_WEEKDAYS;
|
||||
col = first_day % N_WEEKDAYS;
|
||||
|
||||
for (day = 1; day <= ndays_in_month; day++)
|
||||
{
|
||||
@@ -264,7 +263,7 @@ calendar_compute_days (GcalDateChooser *self)
|
||||
g_date_time_unref (date);
|
||||
|
||||
col++;
|
||||
if (col == COLS)
|
||||
if (col == N_WEEKDAYS)
|
||||
{
|
||||
row++;
|
||||
col = 0;
|
||||
@@ -284,7 +283,7 @@ calendar_compute_days (GcalDateChooser *self)
|
||||
day = 1;
|
||||
for (; row < ROWS; row++)
|
||||
{
|
||||
for (; col < COLS; col++)
|
||||
for (; col < N_WEEKDAYS; col++)
|
||||
{
|
||||
d = GCAL_DATE_CHOOSER_DAY (self->days[row][col]);
|
||||
date = g_date_time_new_local (other_year, other_month, day, 0, 0, 0);
|
||||
@@ -301,7 +300,7 @@ calendar_compute_days (GcalDateChooser *self)
|
||||
{
|
||||
gchar *text;
|
||||
|
||||
d = GCAL_DATE_CHOOSER_DAY (self->days[row][COLS - 1]);
|
||||
d = GCAL_DATE_CHOOSER_DAY (self->days[row][N_WEEKDAYS - 1]);
|
||||
date = gcal_date_chooser_day_get_date (d);
|
||||
text = g_strdup_printf ("%d", g_date_time_get_week_of_year (date));
|
||||
gtk_label_set_label (GTK_LABEL (self->rows[row]), text);
|
||||
@@ -382,9 +381,9 @@ calendar_get_weekday_name (gint i)
|
||||
static void
|
||||
calendar_init_weekday_display (GcalDateChooser *self)
|
||||
{
|
||||
for (gint i = 0; i < COLS; i++)
|
||||
for (gint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
const char *text = calendar_get_weekday_name ((i + self->week_start) % COLS);
|
||||
const char *text = calendar_get_weekday_name ((i + self->week_start) % N_WEEKDAYS);
|
||||
gtk_label_set_label (GTK_LABEL (self->cols[i]), text);
|
||||
}
|
||||
}
|
||||
@@ -463,7 +462,7 @@ calendar_update_selected_day_display (GcalDateChooser *self)
|
||||
{
|
||||
gboolean row_selected = FALSE;
|
||||
|
||||
for (col = 0; col < COLS; col++)
|
||||
for (col = 0; col < N_WEEKDAYS; col++)
|
||||
{
|
||||
gboolean day_selected;
|
||||
|
||||
@@ -508,7 +507,7 @@ update_event_indicators (GcalDateChooser *self)
|
||||
|
||||
for (row = 0; row < ROWS; row++)
|
||||
{
|
||||
for (col = 0; col < COLS; col++)
|
||||
for (col = 0; col < N_WEEKDAYS; col++)
|
||||
{
|
||||
GDateTime *date;
|
||||
g_autoptr (GcalRange) range = NULL;
|
||||
@@ -1071,7 +1070,7 @@ show_week_number_to_column_span_cb (GBinding *binding,
|
||||
GValue *to_value,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_value_set_int (to_value, g_value_get_boolean (from_value) ? COLS + 1 : COLS);
|
||||
g_value_set_int (to_value, g_value_get_boolean (from_value) ? N_WEEKDAYS + 1 : N_WEEKDAYS);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1102,7 +1101,7 @@ gcal_date_chooser_init (GcalDateChooser *self)
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
for (col = 0; col < COLS; col++)
|
||||
for (col = 0; col < N_WEEKDAYS; col++)
|
||||
{
|
||||
self->cols[col] = gtk_label_new ("");
|
||||
|
||||
@@ -1183,11 +1182,11 @@ gcal_date_chooser_init (GcalDateChooser *self)
|
||||
"column-spacing", 2,
|
||||
"visible", TRUE,
|
||||
NULL);
|
||||
gtk_grid_attach (GTK_GRID (self->grid), self->day_grid, 0, 0, COLS, ROWS);
|
||||
gtk_grid_attach (GTK_GRID (self->grid), self->day_grid, 0, 0, N_WEEKDAYS, ROWS);
|
||||
|
||||
for (row = 0; row < ROWS; row++)
|
||||
{
|
||||
for (col = 0; col < COLS; col++)
|
||||
for (col = 0; col < N_WEEKDAYS; col++)
|
||||
{
|
||||
self->days[row][col] = gcal_date_chooser_day_new ();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "gcal-alarm-row.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
struct _GcalAlarmRow
|
||||
{
|
||||
@@ -63,7 +64,7 @@ format_alarm_duration (ICalDuration *duration)
|
||||
guint hours;
|
||||
guint days;
|
||||
|
||||
days = i_cal_duration_get_weeks (duration) * 7 + i_cal_duration_get_days (duration);
|
||||
days = i_cal_duration_get_weeks (duration) * N_WEEKDAYS + i_cal_duration_get_days (duration);
|
||||
hours = i_cal_duration_get_hours (duration);
|
||||
minutes = i_cal_duration_get_minutes (duration);
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ struct _GcalWindow
|
||||
GtkWidget *quick_add_popover;
|
||||
|
||||
/* day, week, month, year, list */
|
||||
GtkWidget *views [6];
|
||||
GtkWidget *views[N_WEEKDAYS - 1];
|
||||
gboolean subscribed;
|
||||
|
||||
GcalContext *context;
|
||||
|
||||
@@ -111,7 +111,7 @@ add_month_separators (GcalMonthCell *self)
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (self), "separator-side");
|
||||
|
||||
day_of_month = g_date_time_get_day_of_month (self->date);
|
||||
if (day_of_month > 1 && day_of_month <= 7)
|
||||
if (day_of_month > 1 && day_of_month <= N_WEEKDAYS)
|
||||
{
|
||||
gtk_widget_add_css_class (GTK_WIDGET (self), "separator-top");
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ struct _GcalMonthViewRow
|
||||
{
|
||||
GtkWidget parent;
|
||||
|
||||
GtkWidget *day_cells[7];
|
||||
GtkWidget *day_cells[N_WEEKDAYS];
|
||||
|
||||
GcalRange *range;
|
||||
|
||||
@@ -424,7 +424,7 @@ focus_vertical_cell (GcalMonthViewRow *self,
|
||||
if (gtk_widget_is_ancestor (focused_cell, GTK_WIDGET (self)))
|
||||
return FALSE;
|
||||
|
||||
cell_width = (gdouble) gtk_widget_get_width (GTK_WIDGET (self)) / 7.0;
|
||||
cell_width = (gdouble) gtk_widget_get_width (GTK_WIDGET (self)) / (float) N_WEEKDAYS;
|
||||
row = gtk_widget_get_ancestor (focused_cell, GCAL_TYPE_MONTH_VIEW_ROW);
|
||||
|
||||
g_assert (GTK_WIDGET (self) != row);
|
||||
@@ -482,7 +482,7 @@ static void
|
||||
setup_child_widget (GcalMonthViewRow *self,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
gtk_widget_insert_after (widget, GTK_WIDGET (self), self->day_cells[6]);
|
||||
gtk_widget_insert_after (widget, GTK_WIDGET (self), self->day_cells[N_WEEKDAYS - 1]);
|
||||
|
||||
g_signal_connect_object (widget, "activate", G_CALLBACK (on_event_widget_activated_cb), self, 0);
|
||||
}
|
||||
@@ -518,7 +518,7 @@ calculate_event_cells (GcalMonthViewRow *self,
|
||||
{
|
||||
g_autoptr (GDateTime) range_start = NULL;
|
||||
g_autoptr (GDateTime) end_date = NULL;
|
||||
gint last_cell = 6;
|
||||
gint last_cell = N_WEEKDAYS - 1;
|
||||
|
||||
range_start = gcal_range_get_start (self->range);
|
||||
end_date = gcal_event_get_date_end (event);
|
||||
@@ -538,26 +538,26 @@ calculate_event_cells (GcalMonthViewRow *self,
|
||||
if (all_day)
|
||||
last_cell--;
|
||||
|
||||
*out_last_cell = CLAMP (last_cell, first_cell, 6);
|
||||
*out_last_cell = CLAMP (last_cell, first_cell, N_WEEKDAYS - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_layout_blocks (GcalMonthViewRow *self,
|
||||
guint overflows[7])
|
||||
guint overflows[N_WEEKDAYS])
|
||||
{
|
||||
GPtrArray *blocks_per_day[7];
|
||||
gboolean cell_will_overflow[7] = { FALSE, };
|
||||
guint available_height_without_overflow[7] = { 0, };
|
||||
guint available_height_with_overflow[7] = { 0, };
|
||||
guint weekday_heights[7] = { 0, };
|
||||
GPtrArray *blocks_per_day[N_WEEKDAYS];
|
||||
gboolean cell_will_overflow[N_WEEKDAYS] = { FALSE, };
|
||||
guint available_height_without_overflow[N_WEEKDAYS] = { 0, };
|
||||
guint available_height_with_overflow[N_WEEKDAYS] = { 0, };
|
||||
guint weekday_heights[N_WEEKDAYS] = { 0, };
|
||||
guint n_events;
|
||||
|
||||
g_assert (self->layout_blocks_valid);
|
||||
|
||||
n_events = g_list_model_get_n_items (G_LIST_MODEL (self->events));
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
gint overflow_height;
|
||||
gint content_space;
|
||||
@@ -606,7 +606,7 @@ prepare_layout_blocks (GcalMonthViewRow *self,
|
||||
}
|
||||
|
||||
/* Figure out which blocks will be visible */
|
||||
for (guint cell = 0; cell < 7; cell++)
|
||||
for (guint cell = 0; cell < N_WEEKDAYS; cell++)
|
||||
{
|
||||
for (guint block_index = 0;
|
||||
block_index < blocks_per_day[cell]->len;
|
||||
@@ -645,7 +645,7 @@ prepare_layout_blocks (GcalMonthViewRow *self,
|
||||
}
|
||||
}
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
g_clear_pointer (&blocks_per_day[i], g_ptr_array_unref);
|
||||
}
|
||||
|
||||
@@ -653,7 +653,7 @@ static void
|
||||
recalculate_layout_blocks (GcalMonthViewRow *self)
|
||||
{
|
||||
g_autoptr (GDateTime) range_start = NULL;
|
||||
guint events_at_weekday[7] = { 0, };
|
||||
guint events_at_weekday[N_WEEKDAYS] = { 0, };
|
||||
guint n_events;
|
||||
|
||||
GCAL_ENTRY;
|
||||
@@ -944,7 +944,7 @@ gcal_month_view_row_measure (GtkWidget *widget,
|
||||
gint minimum = 0;
|
||||
gint natural = 0;
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
gint child_minimum;
|
||||
gint child_natural;
|
||||
@@ -994,10 +994,10 @@ gcal_month_view_row_size_allocate (GtkWidget *widget,
|
||||
gdouble cell_width;
|
||||
|
||||
is_ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
|
||||
cell_width = width / 7.0;
|
||||
cell_width = width / (float) N_WEEKDAYS;
|
||||
|
||||
/* Month cells */
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *cell;
|
||||
@@ -1007,20 +1007,20 @@ gcal_month_view_row_size_allocate (GtkWidget *widget,
|
||||
allocation.width = round (cell_width * (i + 1)) - allocation.x;
|
||||
allocation.height = height;
|
||||
|
||||
cell = is_ltr ? self->day_cells[i] : self->day_cells[7 - i - 1];
|
||||
cell = is_ltr ? self->day_cells[i] : self->day_cells[N_WEEKDAYS - i - 1];
|
||||
gtk_widget_size_allocate (cell, &allocation, baseline);
|
||||
}
|
||||
|
||||
/* Event widgets */
|
||||
if (self->layout_blocks_valid)
|
||||
{
|
||||
gdouble cell_y[7];
|
||||
guint overflows[7] = { 0, };
|
||||
gdouble cell_y[N_WEEKDAYS];
|
||||
guint overflows[N_WEEKDAYS] = { 0, };
|
||||
guint n_events;
|
||||
|
||||
prepare_layout_blocks (self, overflows);
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
cell_y[i] = gcal_month_cell_get_header_height (GCAL_MONTH_CELL (self->day_cells[i]));
|
||||
|
||||
n_events = g_list_model_get_n_items (G_LIST_MODEL (self->events));
|
||||
@@ -1044,7 +1044,7 @@ gcal_month_view_row_size_allocate (GtkWidget *widget,
|
||||
|
||||
block = g_ptr_array_index (blocks, block_index);
|
||||
|
||||
start_cell = is_ltr ? block->cell : 7 - block->cell - block->length;
|
||||
start_cell = is_ltr ? block->cell : N_WEEKDAYS - block->cell - block->length;
|
||||
end_cell = start_cell + block->length;
|
||||
|
||||
allocation.x = round (start_cell * cell_width - (is_ltr ? 0 : SEPARATOR_OFFSET));
|
||||
@@ -1060,7 +1060,7 @@ gcal_month_view_row_size_allocate (GtkWidget *widget,
|
||||
}
|
||||
}
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
gcal_month_cell_set_overflow (GCAL_MONTH_CELL (self->day_cells[i]), overflows[i]);
|
||||
}
|
||||
}
|
||||
@@ -1075,7 +1075,7 @@ gcal_month_view_row_dispose (GObject *object)
|
||||
{
|
||||
GcalMonthViewRow *self = (GcalMonthViewRow *)object;
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
g_clear_pointer (&self->day_cells[i], gtk_widget_unparent);
|
||||
|
||||
g_clear_pointer (&self->layout_blocks, g_hash_table_destroy);
|
||||
@@ -1190,7 +1190,7 @@ gcal_month_view_row_init (GcalMonthViewRow *self)
|
||||
self->layout_blocks = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) g_ptr_array_unref);
|
||||
self->layout_blocks_valid = TRUE;
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
self->day_cells[i] = gcal_month_cell_new ();
|
||||
gcal_month_cell_set_overflow (GCAL_MONTH_CELL (self->day_cells[i]), 0);
|
||||
@@ -1225,7 +1225,7 @@ gcal_month_view_row_set_context (GcalMonthViewRow *self,
|
||||
|
||||
if (g_set_object (&self->context, context))
|
||||
{
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
gcal_month_cell_set_context (GCAL_MONTH_CELL (self->day_cells[i]), context);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CONTEXT]);
|
||||
@@ -1263,7 +1263,7 @@ gcal_month_view_row_set_range (GcalMonthViewRow *self,
|
||||
invalidate_layout_blocks (self);
|
||||
|
||||
start = gcal_range_get_start (range);
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
g_autoptr (GDateTime) day = g_date_time_add_days (start, i);
|
||||
gcal_month_cell_set_date (GCAL_MONTH_CELL (self->day_cells[i]), day);
|
||||
@@ -1332,12 +1332,12 @@ gcal_month_view_row_get_cell_at_x (GcalMonthViewRow *self,
|
||||
if (x < 0.0 || x > width)
|
||||
return NULL;
|
||||
|
||||
column = floor (7.0 * x / (gdouble) width);
|
||||
column = floor ((float) N_WEEKDAYS * x / (gdouble) width);
|
||||
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL)
|
||||
return self->day_cells[column];
|
||||
else
|
||||
return self->day_cells[7 - column - 1];
|
||||
return self->day_cells[N_WEEKDAYS - column - 1];
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1346,7 +1346,7 @@ gcal_month_view_row_update_selection (GcalMonthViewRow *self,
|
||||
{
|
||||
g_assert (GCAL_IS_MONTH_VIEW_ROW (self));
|
||||
|
||||
for (guint i = 0; i < 7; i++)
|
||||
for (guint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
GcalMonthCell *month_cell;
|
||||
GDateTime *cell_date;
|
||||
|
||||
@@ -51,7 +51,7 @@ struct _GcalMonthView
|
||||
GtkWidget parent;
|
||||
|
||||
GtkWidget *header;
|
||||
GtkWidget *weekday_label[7];
|
||||
GtkWidget *weekday_label[N_WEEKDAYS];
|
||||
|
||||
GtkEventController *motion_controller;
|
||||
|
||||
@@ -193,11 +193,11 @@ update_weekday_labels (GcalMonthView *self)
|
||||
{
|
||||
const gint first_weekday = get_first_weekday ();
|
||||
|
||||
for (gint i = 0; i < 7; i++)
|
||||
for (gint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
g_autofree gchar *weekday_name = NULL;
|
||||
|
||||
weekday_name = g_utf8_strup (gcal_get_weekday ((i + first_weekday) % 7), -1);
|
||||
weekday_name = g_utf8_strup (gcal_get_weekday ((i + first_weekday) % N_WEEKDAYS), -1);
|
||||
|
||||
gtk_label_set_label (GTK_LABEL (self->weekday_label[i]), weekday_name);
|
||||
}
|
||||
@@ -1955,7 +1955,7 @@ gcal_month_view_init (GcalMonthView *self)
|
||||
update_weekday_labels (self);
|
||||
|
||||
gtk_accessible_update_relation (GTK_ACCESSIBLE (self),
|
||||
GTK_ACCESSIBLE_RELATION_COL_COUNT, 7,
|
||||
GTK_ACCESSIBLE_RELATION_COL_COUNT, N_WEEKDAYS,
|
||||
GTK_ACCESSIBLE_RELATION_ROW_COUNT, N_ROWS_PER_PAGE,
|
||||
-1);
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ on_click_gesture_pressed_cb (GtkGestureClick *click_gesture,
|
||||
g_assert (self->selection.end == -1);
|
||||
|
||||
minute_height = (gdouble) gtk_widget_get_height (GTK_WIDGET (self)) / MINUTES_PER_DAY;
|
||||
column_width = floor (gtk_widget_get_width (GTK_WIDGET (self)) / 7);
|
||||
column_width = floor (gtk_widget_get_width (GTK_WIDGET (self)) / N_WEEKDAYS);
|
||||
column = (gint) x / column_width;
|
||||
minute = y / minute_height;
|
||||
minute = minute - (minute % 30);
|
||||
@@ -307,7 +307,7 @@ on_click_gesture_released_cb (GtkGestureClick *click_gesture,
|
||||
guint rtl_start_cell, rtl_end_cell, rtl_column;
|
||||
|
||||
/* Fix the minute */
|
||||
rtl_column = 6 - column;
|
||||
rtl_column = N_WEEKDAYS - 1 - column;
|
||||
rtl_start_cell = start_cell + (rtl_column - column) * 48;
|
||||
rtl_end_cell = (rtl_column * MINUTES_PER_DAY + minute) / 30;
|
||||
|
||||
@@ -315,7 +315,7 @@ on_click_gesture_released_cb (GtkGestureClick *click_gesture,
|
||||
end = gcal_date_time_add_floating_minutes (week_start, (rtl_end_cell + 1) * 30);
|
||||
}
|
||||
|
||||
local_x = round ((column + 0.5) * (gtk_widget_get_width (GTK_WIDGET (self)) / 7.0));
|
||||
local_x = round ((column + 0.5) * (gtk_widget_get_width (GTK_WIDGET (self)) / (float) N_WEEKDAYS));
|
||||
local_y = (minute + 15) * minute_height;
|
||||
|
||||
if (!gtk_widget_compute_point (GTK_WIDGET (self),
|
||||
@@ -338,7 +338,7 @@ get_dnd_cell (GcalWeekGrid *self,
|
||||
gdouble column_width, cell_height;
|
||||
gint column, row;
|
||||
|
||||
column_width = gtk_widget_get_width (GTK_WIDGET (self)) / 7.0;
|
||||
column_width = gtk_widget_get_width (GTK_WIDGET (self)) / (float) N_WEEKDAYS;
|
||||
cell_height = gtk_widget_get_height (GTK_WIDGET (self)) / 48.0;
|
||||
column = floor (x / column_width);
|
||||
row = y / cell_height;
|
||||
@@ -367,7 +367,7 @@ move_event_to_cell (GcalWeekGrid *self,
|
||||
column = cell / (MINUTES_PER_DAY / 30);
|
||||
row = cell - column * 48;
|
||||
|
||||
cell = (6 - column) * 48 + row;
|
||||
cell = (N_WEEKDAYS - 1 - column) * 48 + row;
|
||||
}
|
||||
|
||||
changed_event = gcal_event_new_from_event (event);
|
||||
@@ -557,7 +557,7 @@ get_today_column (GcalWeekGrid *self)
|
||||
days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
|
||||
|
||||
/* Today is out of range */
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > 7)
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > N_WEEKDAYS)
|
||||
return -1;
|
||||
|
||||
return days_diff;
|
||||
@@ -626,7 +626,7 @@ gcal_week_grid_size_allocate (GtkWidget *widget,
|
||||
|
||||
/* Preliminary calculations */
|
||||
minutes_height = (gdouble) height / MINUTES_PER_DAY;
|
||||
column_width = (gdouble) width / 7.0;
|
||||
column_width = (gdouble) width / (float) N_WEEKDAYS;
|
||||
|
||||
/* Selection */
|
||||
if (gtk_widget_should_layout (self->selection.widget))
|
||||
@@ -708,7 +708,7 @@ gcal_week_grid_size_allocate (GtkWidget *widget,
|
||||
* Iterate through weekdays; we don't have to worry about events that
|
||||
* jump between days because they're already handled by GcalWeekHeader.
|
||||
*/
|
||||
for (size_t i = 0; i < 7; i++)
|
||||
for (size_t i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
g_autoptr (GcalRange) day_range = NULL;
|
||||
GPtrArray *widgets_data;
|
||||
|
||||
@@ -85,9 +85,9 @@ struct _GcalWeekHeader
|
||||
* The list will later be iterated after the active date is changed
|
||||
* and the events will be placed
|
||||
*/
|
||||
GList *events[7];
|
||||
GtkWidget *overflow_label[7];
|
||||
WeekdayHeader weekday_header[7];
|
||||
GList *events[N_WEEKDAYS];
|
||||
GtkWidget *overflow_label[N_WEEKDAYS];
|
||||
WeekdayHeader weekday_header[N_WEEKDAYS];
|
||||
|
||||
gint first_weekday;
|
||||
|
||||
@@ -112,7 +112,7 @@ struct _GcalWeekHeader
|
||||
} dnd;
|
||||
|
||||
/* Array of nullable weather infos for each day, starting with Sunday. */
|
||||
WeatherInfoDay weather_infos[7];
|
||||
WeatherInfoDay weather_infos[N_WEEKDAYS];
|
||||
};
|
||||
|
||||
typedef enum
|
||||
@@ -268,8 +268,8 @@ on_button_pressed (GtkGestureClick *click_gesture,
|
||||
|
||||
ltr = gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL;
|
||||
width = gtk_widget_get_width (self->scrolledwindow);
|
||||
column_width = width / 7.0;
|
||||
column = ltr ? (x / column_width) : (7 - x / column_width);
|
||||
column_width = width / (float) N_WEEKDAYS;
|
||||
column = ltr ? (x / column_width) : (N_WEEKDAYS - x / column_width);
|
||||
|
||||
self->selection.start = column;
|
||||
self->selection.end = column;
|
||||
@@ -293,8 +293,8 @@ on_motion_notify (GtkEventControllerMotion *motion_event,
|
||||
|
||||
ltr = gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL;
|
||||
width = gtk_widget_get_width (self->scrolledwindow);
|
||||
column_width = width / 7.0;
|
||||
column = ltr ? (x / column_width) : (7 - x / column_width);
|
||||
column_width = width / (float) N_WEEKDAYS;
|
||||
column = ltr ? (x / column_width) : (N_WEEKDAYS - x / column_width);
|
||||
|
||||
self->selection.end = column;
|
||||
|
||||
@@ -324,8 +324,8 @@ on_button_released (GtkGestureClick *click_gesture,
|
||||
|
||||
ltr = gtk_widget_get_direction (GTK_WIDGET (self)) != GTK_TEXT_DIR_RTL;
|
||||
width = gtk_widget_get_width (self->scrolledwindow);
|
||||
column_width = width / 7.0;
|
||||
column = ltr ? (x / column_width) : (7 - x / column_width);
|
||||
column_width = width / (float) N_WEEKDAYS;
|
||||
column = ltr ? (x / column_width) : (N_WEEKDAYS - x / column_width);
|
||||
|
||||
self->selection.end = column;
|
||||
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
||||
@@ -377,7 +377,7 @@ get_event_by_uuid (GcalWeekHeader *self,
|
||||
{
|
||||
gint weekday;
|
||||
|
||||
for (weekday = 0; weekday < 7; weekday++)
|
||||
for (weekday = 0; weekday < N_WEEKDAYS; weekday++)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
@@ -403,7 +403,7 @@ get_today_column (GcalWeekHeader *self)
|
||||
days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
|
||||
|
||||
/* Today is out of range */
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > 7)
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > N_WEEKDAYS)
|
||||
return -1;
|
||||
|
||||
return days_diff;
|
||||
@@ -460,7 +460,7 @@ update_overflow (GcalWeekHeader *self)
|
||||
|
||||
show_expand = FALSE;
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
GtkWidget *label;
|
||||
gboolean show_label;
|
||||
@@ -542,11 +542,11 @@ merge_events (GcalWeekHeader *self,
|
||||
static void
|
||||
check_mergeable_events (GcalWeekHeader *self)
|
||||
{
|
||||
GList *checked_events[7] = { NULL, };
|
||||
GList *checked_events[N_WEEKDAYS] = { NULL, };
|
||||
gint weekday;
|
||||
|
||||
/* We don't need to check the last column */
|
||||
for (weekday = 0; weekday < 6; weekday++)
|
||||
for (weekday = 0; weekday < N_WEEKDAYS - 1; weekday++)
|
||||
{
|
||||
GList *l;
|
||||
gint index;
|
||||
@@ -575,7 +575,7 @@ check_mergeable_events (GcalWeekHeader *self)
|
||||
* Horizontally check if the next cells have the same event
|
||||
* than the current cell.
|
||||
*/
|
||||
for (i = 1; i < 7 - weekday; i++)
|
||||
for (i = 1; i < N_WEEKDAYS - weekday; i++)
|
||||
{
|
||||
GcalEvent *next_event;
|
||||
|
||||
@@ -652,7 +652,7 @@ split_event_widget_at_column (GcalWeekHeader *self,
|
||||
old_width = gtk_grid_layout_child_get_column_span (GTK_GRID_LAYOUT_CHILD (layout_child));
|
||||
|
||||
create_before = column > 0 && left_attach < column;
|
||||
create_after = column < 6 && old_width > 1 && left_attach + old_width > column + 1;
|
||||
create_after = column < N_WEEKDAYS - 1 && old_width > 1 && left_attach + old_width > column + 1;
|
||||
|
||||
if (create_before)
|
||||
{
|
||||
@@ -915,9 +915,9 @@ update_unchanged_events (GcalWeekHeader *self,
|
||||
g_date_time_get_month (new_week_start),
|
||||
g_date_time_get_day_of_month (new_week_start),
|
||||
0, 0, 0);
|
||||
utc_week_end = g_date_time_add_days (utc_week_start, 7);
|
||||
utc_week_end = g_date_time_add_days (utc_week_start, N_WEEKDAYS);
|
||||
|
||||
for (weekday = 0; weekday < 7; weekday++)
|
||||
for (weekday = 0; weekday < N_WEEKDAYS; weekday++)
|
||||
{
|
||||
GList *events;
|
||||
|
||||
@@ -986,7 +986,7 @@ update_title (GcalWeekHeader *self)
|
||||
week_start = gcal_date_time_get_start_of_week (self->active_date);
|
||||
today_column = get_today_column (self);
|
||||
|
||||
for (gint i = 0; i < 7; i++)
|
||||
for (gint i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
g_autoptr (GDateTime) day = NULL;
|
||||
g_autofree gchar *weekday_date = NULL;
|
||||
@@ -1127,7 +1127,7 @@ get_dnd_cell (GcalWeekHeader *self,
|
||||
{
|
||||
gdouble column_width;
|
||||
|
||||
column_width = gtk_widget_get_width (GTK_WIDGET (self)) / 7.0;
|
||||
column_width = gtk_widget_get_width (GTK_WIDGET (self)) / (float) N_WEEKDAYS;
|
||||
|
||||
return x / column_width;
|
||||
}
|
||||
@@ -1151,7 +1151,7 @@ move_event_to_cell (GcalWeekHeader *self,
|
||||
|
||||
/* RTL languages swap the drop cell column */
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL)
|
||||
cell = 6 - cell;
|
||||
cell = N_WEEKDAYS - 1 - cell;
|
||||
|
||||
changed_event = gcal_event_new_from_event (event);
|
||||
start_date = gcal_event_get_date_start (changed_event);
|
||||
@@ -1334,7 +1334,7 @@ gcal_week_header_size_allocate (GtkWidget *widget,
|
||||
gtk_widget_allocate (self->main_box, width, height, baseline, NULL);
|
||||
|
||||
ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
|
||||
cell_width = width / 7.0;
|
||||
cell_width = width / (float) N_WEEKDAYS;
|
||||
|
||||
if (gtk_widget_should_layout (self->selection.widget))
|
||||
{
|
||||
@@ -1438,7 +1438,7 @@ gcal_week_header_finalize (GObject *object)
|
||||
|
||||
gcal_clear_date_time (&self->active_date);
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < N_WEEKDAYS; i++)
|
||||
g_list_free (self->events[i]);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (self->weather_infos); i++)
|
||||
@@ -1562,7 +1562,7 @@ gcal_week_header_init (GcalWeekHeader *self)
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
WeekdayHeader *header = &self->weekday_header[i];
|
||||
GtkWidget *box;
|
||||
@@ -1586,7 +1586,7 @@ gcal_week_header_init (GcalWeekHeader *self)
|
||||
|
||||
gtk_box_append (self->weekdays_box, box);
|
||||
|
||||
/* Add 7 empty widget to the grid to ensure proper spacing */
|
||||
/* Add N_WEEKDAYS empty widget to the grid to ensure proper spacing */
|
||||
gtk_grid_attach (self->grid, gtk_box_new (GTK_ORIENTATION_VERTICAL, 0), i, 0, 1, 1);
|
||||
}
|
||||
|
||||
@@ -1684,10 +1684,10 @@ gcal_week_header_add_event (GcalWeekHeader *self,
|
||||
if (g_date_time_compare (event_end, week_end) < 0)
|
||||
end = floor (g_date_time_difference (event_end, week_start) / G_TIME_SPAN_DAY) - all_day;
|
||||
else
|
||||
end = 6;
|
||||
end = N_WEEKDAYS - 1;
|
||||
|
||||
/* Sanity checks */
|
||||
if (start > end || start > 6 || end < 0)
|
||||
if (start > end || start > N_WEEKDAYS - 1 || end < 0)
|
||||
{
|
||||
g_warning ("Error adding event '%s' to the week header", gcal_event_get_summary (event));
|
||||
return;
|
||||
@@ -1739,7 +1739,7 @@ gcal_week_header_remove_event (GcalWeekHeader *self,
|
||||
}
|
||||
|
||||
/* Remove from the weekday's GList */
|
||||
for (weekday = 0; weekday < 7; weekday++)
|
||||
for (weekday = 0; weekday < N_WEEKDAYS; weekday++)
|
||||
{
|
||||
GList *l;
|
||||
gint event_position;
|
||||
|
||||
@@ -40,12 +40,12 @@ gcal_week_view_common_snapshot_hour_lines (GtkWidget *widget,
|
||||
color.alpha = 0.15;
|
||||
gtk_snapshot_restore (snapshot);
|
||||
|
||||
column_width = width / 7.0;
|
||||
column_width = width / (float) N_WEEKDAYS;
|
||||
|
||||
switch (orientation)
|
||||
{
|
||||
case GTK_ORIENTATION_HORIZONTAL:
|
||||
for (i = 0; i < 7; i++)
|
||||
for (i = 0; i < N_WEEKDAYS; i++)
|
||||
{
|
||||
gdouble x;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "gcal-search-model.h"
|
||||
#include "gcal-timeline.h"
|
||||
#include "gcal-timeline-subscriber.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
struct _GcalSearchEngine
|
||||
{
|
||||
@@ -225,8 +226,8 @@ gcal_search_engine_search (GcalSearchEngine *self,
|
||||
|
||||
timezone = gcal_context_get_timezone (self->context);
|
||||
now = g_date_time_new_now (timezone);
|
||||
range_start = g_date_time_add_months (now, -6);
|
||||
range_end = g_date_time_add_months (now, 6);
|
||||
range_start = g_date_time_add_months (now, -N_WEEKDAYS - 1);
|
||||
range_end = g_date_time_add_months (now, N_WEEKDAYS - 1);
|
||||
model = gcal_search_model_new (cancellable, range_start, range_end);
|
||||
|
||||
gcal_timeline_set_filter (self->timeline, search_query);
|
||||
|
||||
@@ -84,8 +84,8 @@ gcal_date_time_get_start_of_week (GDateTime *date)
|
||||
g_assert (date != NULL);
|
||||
|
||||
first_weekday = get_first_weekday ();
|
||||
weekday = g_date_time_get_day_of_week (date) % 7;
|
||||
n_days_after_week_start = (7 + weekday - first_weekday) % 7;
|
||||
weekday = g_date_time_get_day_of_week (date) % N_WEEKDAYS;
|
||||
n_days_after_week_start = (N_WEEKDAYS + weekday - first_weekday) % N_WEEKDAYS;
|
||||
|
||||
start_of_week = g_date_time_add_days (date, -n_days_after_week_start);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
*/
|
||||
|
||||
static const gint
|
||||
ab_day[7] =
|
||||
ab_day[N_WEEKDAYS] =
|
||||
{
|
||||
ABDAY_1,
|
||||
ABDAY_2,
|
||||
@@ -402,7 +402,7 @@ get_first_weekday (void)
|
||||
else
|
||||
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
|
||||
|
||||
week_start = (week_1stday + first_weekday - 1) % 7;
|
||||
week_start = (week_1stday + first_weekday - 1) % N_WEEKDAYS;
|
||||
|
||||
#else
|
||||
|
||||
@@ -418,7 +418,7 @@ get_first_weekday (void)
|
||||
else
|
||||
week_start = -1;
|
||||
|
||||
if (week_start < 0 || week_start > 6)
|
||||
if (week_start < 0 || week_start > N_WEEKDAYS - 1)
|
||||
{
|
||||
g_warning ("Whoever translated calendar:week_start:0 for GTK+ "
|
||||
"did so wrongly.\n");
|
||||
@@ -771,7 +771,7 @@ get_alarm_trigger_minutes (GcalEvent *event,
|
||||
alarm_dt = g_date_time_add_full (gcal_event_get_date_start (event),
|
||||
0,
|
||||
0,
|
||||
- (i_cal_duration_get_days (duration) + i_cal_duration_get_weeks (duration) * 7),
|
||||
- (i_cal_duration_get_days (duration) + i_cal_duration_get_weeks (duration) * N_WEEKDAYS),
|
||||
- i_cal_duration_get_hours (duration),
|
||||
- i_cal_duration_get_minutes (duration),
|
||||
- i_cal_duration_get_seconds (duration));
|
||||
@@ -903,7 +903,7 @@ is_workday (guint day)
|
||||
gchar territory[3] = { 0, };
|
||||
guint i;
|
||||
|
||||
if (day > 6)
|
||||
if (day > N_WEEKDAYS - 1)
|
||||
return FALSE;
|
||||
|
||||
no_work_days = GCAL_WEEK_DAY_SATURDAY | GCAL_WEEK_DAY_SUNDAY;
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
#include <libecal/libecal.h>
|
||||
#include <libgweather/gweather.h>
|
||||
|
||||
#define N_WEEKDAYS 7
|
||||
#define ALIGNED(x) (round (x) + 0.5)
|
||||
#define MINUTES_PER_DAY 1440
|
||||
#define MAX_MINUTES (7 * MINUTES_PER_DAY)
|
||||
#define MAX_MINUTES (N_WEEKDAYS * MINUTES_PER_DAY)
|
||||
|
||||
#define gcal_clear_timeout(pp) { if (pp && *pp) { g_source_remove (*pp); *pp = 0; } }
|
||||
#define gcal_clear_signal_handler(pp,instance) { if (pp && *pp > 0) { g_signal_handler_disconnect (instance, *pp); *pp = 0; } }
|
||||
|
||||
Reference in New Issue
Block a user