[gnome-calendar] month-view: fix another allocation cycle



commit b70f3fa0b606395b51d80dbf752a1acd2b099d07
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Dec 12 11:06:46 2017 -0200

    month-view: fix another allocation cycle

 src/views/gcal-month-cell.c | 11 +++++--
 src/views/gcal-month-view.c | 72 ++++++++++++++++++++++-----------------------
 2 files changed, 45 insertions(+), 38 deletions(-)
---
diff --git a/src/views/gcal-month-cell.c b/src/views/gcal-month-cell.c
index f6541991..cf6d7140 100644
--- a/src/views/gcal-month-cell.c
+++ b/src/views/gcal-month-cell.c
@@ -48,6 +48,8 @@ struct _GcalMonthCell
   gboolean            pressed : 1;
 
   GcalManager        *manager;
+
+  GcalWeatherInfo    *weather_info;
 };
 
 G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX)
@@ -505,9 +507,14 @@ gcal_month_cell_set_weather (GcalMonthCell   *self,
                              GcalWeatherInfo *info)
 {
   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 (self->weather_info == info)
+    return;
+
+  self->weather_info = info;
 
-  if (info == NULL)
+  if (!info)
     {
       gtk_image_clear (self->weather_icon);
       gtk_label_set_text (self->temp_label, "");
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 8d66ffc2..bc3116f6 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -914,6 +914,12 @@ static void
 update_weather (GcalMonthView *self,
                 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));
 
   /* Drop old weather information */
@@ -936,48 +942,43 @@ update_weather (GcalMonthView *self,
 
 
   /* 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;
-      GDateTime *firstdt;
-      GSList *weather_infos;
-      GSList *witer;
-      GDate first;
-
-      fstcell = GCAL_MONTH_CELL (self->month_cell[0][0]);
-      firstdt = gcal_month_cell_get_date (fstcell);
-
-      g_date_set_dmy (&first,
-                      g_date_time_get_day_of_month (firstdt),
-                      g_date_time_get_month (firstdt),
-                      g_date_time_get_year (firstdt));
-
-      weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
-      for (witer = weather_infos; witer; witer = witer->next)
-        {
-          GcalWeatherInfo *info;
-          GDate weather_date;
-          gint day_difference;
+      GcalWeatherInfo *info;
+      GDate weather_date;
+      gint day_difference;
 
-          info = GCAL_WEATHER_INFO (witer->data);
-          gcal_weather_info_get_date (info, &weather_date);
-          day_difference = g_date_days_between (&first, &weather_date);
+      info = GCAL_WEATHER_INFO (l->data);
 
-          if (day_difference >= 0 && day_difference < 6 * 7)
-            {
-              GcalMonthCell *wcell;
-              guint row;
-              guint column;
+      gcal_weather_info_get_date (info, &weather_date);
+      day_difference = g_date_days_between (&first, &weather_date);
 
-              row = day_difference / 7;
-              column = day_difference % 7;
-              wcell = GCAL_MONTH_CELL (self->month_cell[row][column]);
+      if (day_difference >= 0 && day_difference < 6 * 7)
+        {
+          GcalMonthCell *wcell;
+          guint row;
+          guint column;
 
-              gcal_month_cell_set_weather (wcell, info);
-            }
+          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
@@ -1012,7 +1013,6 @@ update_month_cells (GcalMonthView *self)
           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_weather (cell, NULL);
 
           /* Different month */
           different_month = day < self->days_delay ||


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]