month-view: fix another allocation cycle
This commit is contained in:
@@ -48,6 +48,8 @@ struct _GcalMonthCell
|
|||||||
gboolean pressed : 1;
|
gboolean pressed : 1;
|
||||||
|
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
|
|
||||||
|
GcalWeatherInfo *weather_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX)
|
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX)
|
||||||
@@ -505,9 +507,14 @@ gcal_month_cell_set_weather (GcalMonthCell *self,
|
|||||||
GcalWeatherInfo *info)
|
GcalWeatherInfo *info)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
|
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
|
||||||
g_return_if_fail (info == NULL || GCAL_IS_WEATHER_INFO (info));
|
g_return_if_fail (!info || GCAL_IS_WEATHER_INFO (info));
|
||||||
|
|
||||||
if (info == NULL)
|
if (self->weather_info == info)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->weather_info = info;
|
||||||
|
|
||||||
|
if (!info)
|
||||||
{
|
{
|
||||||
gtk_image_clear (self->weather_icon);
|
gtk_image_clear (self->weather_icon);
|
||||||
gtk_label_set_text (self->temp_label, "");
|
gtk_label_set_text (self->temp_label, "");
|
||||||
|
|||||||
+34
-34
@@ -914,6 +914,12 @@ static void
|
|||||||
update_weather (GcalMonthView *self,
|
update_weather (GcalMonthView *self,
|
||||||
gboolean clear_old)
|
gboolean clear_old)
|
||||||
{
|
{
|
||||||
|
GcalMonthCell *first_cell;
|
||||||
|
GDateTime *first_dt;
|
||||||
|
GSList *weather_infos;
|
||||||
|
GSList *l;
|
||||||
|
GDate first;
|
||||||
|
|
||||||
g_return_if_fail (GCAL_IS_MONTH_VIEW (self));
|
g_return_if_fail (GCAL_IS_MONTH_VIEW (self));
|
||||||
|
|
||||||
/* Drop old weather information */
|
/* Drop old weather information */
|
||||||
@@ -936,48 +942,43 @@ update_weather (GcalMonthView *self,
|
|||||||
|
|
||||||
|
|
||||||
/* Set new one */
|
/* Set new one */
|
||||||
if (self->weather_service != NULL)
|
if (!self->weather_service)
|
||||||
|
return;
|
||||||
|
|
||||||
|
first_cell = GCAL_MONTH_CELL (self->month_cell[0][0]);
|
||||||
|
first_dt = gcal_month_cell_get_date (first_cell);
|
||||||
|
|
||||||
|
g_date_set_dmy (&first,
|
||||||
|
g_date_time_get_day_of_month (first_dt),
|
||||||
|
g_date_time_get_month (first_dt),
|
||||||
|
g_date_time_get_year (first_dt));
|
||||||
|
|
||||||
|
weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
|
||||||
|
|
||||||
|
for (l = weather_infos; l; l = l->next)
|
||||||
{
|
{
|
||||||
GcalMonthCell *fstcell;
|
GcalWeatherInfo *info;
|
||||||
GDateTime *firstdt;
|
GDate weather_date;
|
||||||
GSList *weather_infos;
|
gint day_difference;
|
||||||
GSList *witer;
|
|
||||||
GDate first;
|
|
||||||
|
|
||||||
fstcell = GCAL_MONTH_CELL (self->month_cell[0][0]);
|
info = GCAL_WEATHER_INFO (l->data);
|
||||||
firstdt = gcal_month_cell_get_date (fstcell);
|
|
||||||
|
|
||||||
g_date_set_dmy (&first,
|
gcal_weather_info_get_date (info, &weather_date);
|
||||||
g_date_time_get_day_of_month (firstdt),
|
day_difference = g_date_days_between (&first, &weather_date);
|
||||||
g_date_time_get_month (firstdt),
|
|
||||||
g_date_time_get_year (firstdt));
|
|
||||||
|
|
||||||
weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
|
if (day_difference >= 0 && day_difference < 6 * 7)
|
||||||
for (witer = weather_infos; witer; witer = witer->next)
|
|
||||||
{
|
{
|
||||||
GcalWeatherInfo *info;
|
GcalMonthCell *wcell;
|
||||||
GDate weather_date;
|
guint row;
|
||||||
gint day_difference;
|
guint column;
|
||||||
|
|
||||||
info = GCAL_WEATHER_INFO (witer->data);
|
row = day_difference / 7;
|
||||||
gcal_weather_info_get_date (info, &weather_date);
|
column = day_difference % 7;
|
||||||
day_difference = g_date_days_between (&first, &weather_date);
|
wcell = GCAL_MONTH_CELL (self->month_cell[row][column]);
|
||||||
|
|
||||||
if (day_difference >= 0 && day_difference < 6 * 7)
|
gcal_month_cell_set_weather (wcell, info);
|
||||||
{
|
|
||||||
GcalMonthCell *wcell;
|
|
||||||
guint row;
|
|
||||||
guint column;
|
|
||||||
|
|
||||||
row = day_difference / 7;
|
|
||||||
column = day_difference % 7;
|
|
||||||
wcell = GCAL_MONTH_CELL (self->month_cell[row][column]);
|
|
||||||
|
|
||||||
gcal_month_cell_set_weather (wcell, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -1012,7 +1013,6 @@ update_month_cells (GcalMonthView *self)
|
|||||||
cell_date = g_date_time_add_days (dt, row * 7 + col - self->days_delay);
|
cell_date = g_date_time_add_days (dt, row * 7 + col - self->days_delay);
|
||||||
|
|
||||||
gcal_month_cell_set_date (cell, cell_date);
|
gcal_month_cell_set_date (cell, cell_date);
|
||||||
gcal_month_cell_set_weather (cell, NULL);
|
|
||||||
|
|
||||||
/* Different month */
|
/* Different month */
|
||||||
different_month = day < self->days_delay ||
|
different_month = day < self->days_delay ||
|
||||||
|
|||||||
Reference in New Issue
Block a user