views: get rid of current date
We can easily track the current date with GDateTime API, so we don't actually need the current date field.
This commit is contained in:
@@ -82,8 +82,6 @@ struct _GcalMonthView
|
||||
/* text direction factors */
|
||||
gboolean k;
|
||||
|
||||
icaltimetype *current_date;
|
||||
|
||||
/* The cell hovered during Drag and Drop */
|
||||
gint dnd_cell;
|
||||
|
||||
@@ -1496,6 +1494,8 @@ gcal_month_view_draw (GtkWidget *widget,
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *font_desc, *sfont_desc;
|
||||
|
||||
g_autoptr (GDateTime) today;
|
||||
|
||||
gint font_width, font_height, pos_x, pos_y, shown_rows;
|
||||
gint i, j, sw, lower_mark = 43, upper_mark = -2;
|
||||
gint cell_width, cell_height;
|
||||
@@ -1505,6 +1505,8 @@ gcal_month_view_draw (GtkWidget *widget,
|
||||
self = GCAL_MONTH_VIEW (widget);
|
||||
ppriv = GCAL_SUBSCRIBER_VIEW (widget)->priv;
|
||||
|
||||
today = g_date_time_new_now_local ();
|
||||
|
||||
/* fonts and colors selection */
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_style_context_get_state (context);
|
||||
@@ -1705,8 +1707,9 @@ gcal_month_view_draw (GtkWidget *widget,
|
||||
g_object_unref (overflow_layout);
|
||||
}
|
||||
|
||||
if (self->date->year == self->current_date->year && self->date->month == self->current_date->month &&
|
||||
j == self->current_date->day)
|
||||
if (self->date->year == g_date_time_get_year (today) &&
|
||||
self->date->month == g_date_time_get_month (today) &&
|
||||
j == g_date_time_get_day_of_month (today))
|
||||
{
|
||||
PangoFontDescription *cfont_desc;
|
||||
PangoLayout *clayout;
|
||||
@@ -2286,15 +2289,6 @@ gcal_month_view_init (GcalMonthView *self)
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
void
|
||||
gcal_month_view_set_current_date (GcalMonthView *self,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_MONTH_VIEW (self));
|
||||
|
||||
self->current_date = current_date;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_month_view_set_first_weekday:
|
||||
|
||||
@@ -29,10 +29,6 @@ G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GcalMonthView, gcal_month_view, GCAL, MONTH_VIEW, GcalSubscriberView)
|
||||
|
||||
|
||||
void gcal_month_view_set_current_date (GcalMonthView *self,
|
||||
icaltimetype *current_date);
|
||||
|
||||
void gcal_month_view_set_first_weekday (GcalMonthView *self,
|
||||
gint day_nr);
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@ struct _GcalWeekGrid
|
||||
gboolean use_24h_format : 1;
|
||||
|
||||
icaltimetype *active_date;
|
||||
icaltimetype *current_date;
|
||||
|
||||
GcalRangeTree *events;
|
||||
|
||||
@@ -257,7 +256,6 @@ gcal_week_grid_finalize (GObject *object)
|
||||
|
||||
g_clear_pointer (&self->events, gcal_range_tree_unref);
|
||||
g_clear_pointer (&self->active_date, g_free);
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
|
||||
if (self->redraw_timeout_id > 0)
|
||||
{
|
||||
@@ -1179,18 +1177,6 @@ gcal_week_grid_set_use_24h_format (GcalWeekGrid *self,
|
||||
self->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_grid_set_current_date (GcalWeekGrid *self,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_GRID (self));
|
||||
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
self->current_date = gcal_dup_icaltime (current_date);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
GcalEvent *event)
|
||||
|
||||
@@ -40,9 +40,6 @@ void gcal_week_grid_set_first_weekday (GcalWeekGrid
|
||||
void gcal_week_grid_set_use_24h_format (GcalWeekGrid *week_grid,
|
||||
gboolean use_24h_format);
|
||||
|
||||
void gcal_week_grid_set_current_date (GcalWeekGrid *week_grid,
|
||||
icaltimetype *current_date);
|
||||
|
||||
void gcal_week_grid_add_event (GcalWeekGrid *self,
|
||||
GcalEvent *event);
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ struct _GcalWeekHeader
|
||||
gint redraw_timeout_id;
|
||||
|
||||
icaltimetype *active_date;
|
||||
icaltimetype *current_date;
|
||||
|
||||
gint selection_start;
|
||||
gint selection_end;
|
||||
@@ -1025,7 +1024,6 @@ gcal_week_header_finalize (GObject *object)
|
||||
gint i;
|
||||
|
||||
g_clear_pointer (&self->active_date, g_free);
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
|
||||
if (self->redraw_timeout_id > 0)
|
||||
{
|
||||
@@ -1744,20 +1742,6 @@ gcal_week_header_get_children_by_uuid (GcalWeekHeader *self,
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_header_set_current_date (GcalWeekHeader *self,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
|
||||
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
self->current_date = gcal_dup_icaltime (current_date);
|
||||
|
||||
update_title (self);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
GtkSizeGroup*
|
||||
gcal_week_header_get_sidebar_size_group (GcalWeekHeader *self)
|
||||
{
|
||||
|
||||
@@ -40,9 +40,6 @@ void gcal_week_header_set_first_weekday (GcalWeekHeader
|
||||
void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
|
||||
gboolean use_24h_format);
|
||||
|
||||
void gcal_week_header_set_current_date (GcalWeekHeader *self,
|
||||
icaltimetype *current_date);
|
||||
|
||||
void gcal_week_header_add_event (GcalWeekHeader *self,
|
||||
GcalEvent *event);
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ struct _GcalWeekView
|
||||
|
||||
/* property */
|
||||
icaltimetype *date;
|
||||
icaltimetype *current_date;
|
||||
GcalManager *manager; /* weak referenced */
|
||||
|
||||
guint scroll_grid_timeout_id;
|
||||
@@ -655,16 +654,3 @@ gcal_week_view_set_use_24h_format (GcalWeekView *self,
|
||||
|
||||
self->use_24h_format = use_24h;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_week_view_set_current_date (GcalWeekView *self,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_WEEK_VIEW (self));
|
||||
|
||||
g_clear_pointer (&self->current_date, g_free);
|
||||
self->current_date = current_date;
|
||||
|
||||
gcal_week_header_set_current_date (GCAL_WEEK_HEADER (self->header), current_date);
|
||||
gcal_week_grid_set_current_date (GCAL_WEEK_GRID (self->week_grid), current_date);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,6 @@ void gcal_week_view_set_first_weekday (GcalWeekView
|
||||
void gcal_week_view_set_use_24h_format (GcalWeekView *self,
|
||||
gboolean use_24h);
|
||||
|
||||
void gcal_week_view_set_current_date (GcalWeekView *self,
|
||||
icaltimetype *current_date);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_WEEK_VIEW_H__ */
|
||||
|
||||
+31
-24
@@ -105,9 +105,6 @@ struct _GcalYearView
|
||||
/* text direction factors */
|
||||
gint k;
|
||||
|
||||
/* weak ref to current date */
|
||||
icaltimetype *current_date;
|
||||
|
||||
/* date property */
|
||||
icaltimetype *date;
|
||||
};
|
||||
@@ -218,7 +215,17 @@ update_selected_dates_from_button_data (GcalYearView *year_view)
|
||||
}
|
||||
else
|
||||
{
|
||||
*(year_view->start_selected_date) = year_view->date ? *(year_view->date) : *(year_view->current_date);
|
||||
g_autofree icaltimetype *current_date;
|
||||
g_autoptr (GDateTime) now;
|
||||
|
||||
now = g_date_time_new_now_local ();
|
||||
current_date = datetime_to_icaltime (now);
|
||||
|
||||
if (year_view->date)
|
||||
*(year_view->start_selected_date) = *year_view->date;
|
||||
else
|
||||
*(year_view->start_selected_date) = *current_date;
|
||||
|
||||
year_view->start_selected_date->hour = 0;
|
||||
year_view->start_selected_date->minute = 0;
|
||||
year_view->start_selected_date->second = 0;
|
||||
@@ -245,13 +252,17 @@ update_selected_dates_from_button_data (GcalYearView *year_view)
|
||||
static void
|
||||
update_no_events_page (GcalYearView *year_view)
|
||||
{
|
||||
gchar *title;
|
||||
g_autoptr (GDateTime) start_selected_date, now;
|
||||
gboolean has_range;
|
||||
gchar *title;
|
||||
|
||||
now = g_date_time_new_now_local ();
|
||||
start_selected_date = icaltime_to_datetime (year_view->start_selected_date);
|
||||
|
||||
has_range = (year_view->start_selected_date->day != year_view->end_selected_date->day ||
|
||||
year_view->start_selected_date->month != year_view->end_selected_date->month);
|
||||
|
||||
if (icaltime_compare_date (year_view->current_date, year_view->start_selected_date) == 0)
|
||||
if (datetime_compare_date (now, start_selected_date) == 0)
|
||||
{
|
||||
title = g_strdup_printf ("%s%s", _("Today"), has_range ? "…" : "");
|
||||
}
|
||||
@@ -465,14 +476,19 @@ update_sidebar_headers (GtkListBoxRow *row,
|
||||
|
||||
if (before_shift == -1 || before_shift != row_shift)
|
||||
{
|
||||
g_autoptr (GDateTime) now, dt;
|
||||
GtkWidget *label;
|
||||
gchar *label_str;
|
||||
|
||||
row_header = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
now = g_date_time_new_now_local ();
|
||||
|
||||
date = *(year_view->start_selected_date);
|
||||
icaltime_adjust (&date, row_shift, 0, 0, 0);
|
||||
|
||||
if (icaltime_compare_date (&date, year_view->current_date) == 0)
|
||||
dt = icaltime_to_datetime (&date);
|
||||
|
||||
if (datetime_compare_date (dt, now) == 0)
|
||||
label_str = g_strdup (_("Today"));
|
||||
else
|
||||
label_str = g_strdup_printf ("%s %d", gcal_get_month_name (date.month - 1), date.day);
|
||||
@@ -674,6 +690,8 @@ draw_month_grid (GcalYearView *year_view,
|
||||
PangoLayout *layout, *slayout;
|
||||
PangoFontDescription *font_desc, *sfont_desc;
|
||||
|
||||
g_autoptr (GDateTime) now;
|
||||
|
||||
GdkRGBA color;
|
||||
gint layout_width, layout_height, i, j, sw;
|
||||
gint column, row;
|
||||
@@ -684,6 +702,8 @@ draw_month_grid (GcalYearView *year_view,
|
||||
GList *events;
|
||||
icaltimetype start_date, end_date;
|
||||
|
||||
now = g_date_time_new_now_local ();
|
||||
|
||||
cairo_save (cr);
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state_flags = gtk_style_context_get_state (context);
|
||||
@@ -845,8 +865,9 @@ draw_month_grid (GcalYearView *year_view,
|
||||
}
|
||||
}
|
||||
|
||||
if (year_view->date->year == year_view->current_date->year && month_nr + 1 == year_view->current_date->month &&
|
||||
j == year_view->current_date->day)
|
||||
if (year_view->date->year == g_date_time_get_year (now) &&
|
||||
month_nr + 1 == g_date_time_get_month (now) &&
|
||||
j == g_date_time_get_day_of_month (now))
|
||||
{
|
||||
PangoLayout *clayout;
|
||||
PangoFontDescription *cfont_desc;
|
||||
@@ -1237,10 +1258,7 @@ add_event_clicked_cb (GcalYearView *year_view,
|
||||
|
||||
if (year_view->start_selected_date->day == 0)
|
||||
{
|
||||
start_date = g_date_time_new_local (year_view->current_date->year,
|
||||
year_view->current_date->month,
|
||||
year_view->current_date->day,
|
||||
0, 0, 0);
|
||||
start_date = g_date_time_new_now_local ();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1978,14 +1996,3 @@ gcal_year_view_set_use_24h_format (GcalYearView *year_view,
|
||||
{
|
||||
year_view->use_24h_format = use_24h_format;
|
||||
}
|
||||
|
||||
void
|
||||
gcal_year_view_set_current_date (GcalYearView *year_view,
|
||||
icaltimetype *current_date)
|
||||
{
|
||||
year_view->current_date = current_date;
|
||||
|
||||
/* Launches update */
|
||||
gtk_widget_queue_draw (GTK_WIDGET (year_view));
|
||||
update_sidebar (year_view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user