[gnome-calendar] Use weather service from GcalContext
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] Use weather service from GcalContext
- Date: Thu, 25 Apr 2019 19:58:03 +0000 (UTC)
commit 01fdf79e6ab05341b4ae51adb96793c583f24f2c
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Apr 24 16:34:41 2019 -0300
Use weather service from GcalContext
All those properties were a waste compared to storing it
into the context.
src/gcal-application.c | 45 ++----
src/gcal-application.h | 3 -
src/gcal-context.c | 2 +
src/gcal-window.c | 31 +---
src/views/gcal-month-view.c | 32 ++--
src/views/gcal-view.c | 88 -----------
src/views/gcal-view.h | 14 --
src/views/gcal-week-header.c | 296 ++++++++++--------------------------
src/views/gcal-week-header.h | 7 -
src/views/gcal-week-view.c | 18 ---
src/views/gcal-year-view.c | 32 ++--
src/weather/gcal-weather-service.c | 25 +++
src/weather/gcal-weather-service.h | 7 +-
src/weather/gcal-weather-settings.c | 57 +------
src/weather/gcal-weather-settings.h | 5 -
15 files changed, 158 insertions(+), 504 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index c20c9adb..91967850 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -27,7 +27,6 @@
#include "gcal-enums.h"
#include "gcal-log.h"
#include "gcal-shell-search-provider.h"
-#include "gcal-weather-service.h"
#include "gcal-window.h"
#include <glib.h>
@@ -50,7 +49,6 @@ struct _GcalApplication
GSettings *desktop_settings;
GcalTimeFormat time_format;
- GcalWeatherService *weather_service;
GcalShellSearchProvider *search_provider;
GcalContext *context;
@@ -118,7 +116,6 @@ enum
PROP_CONTEXT,
PROP_MANAGER,
PROP_TIME_FORMAT,
- PROP_WEATHER_SERVICE,
N_PROPS
};
@@ -229,7 +226,6 @@ gcal_application_finalize (GObject *object)
g_clear_object (&self->desktop_settings);
g_clear_object (&self->provider);
g_clear_object (&self->search_provider);
- g_clear_object (&self->weather_service);
G_OBJECT_CLASS (gcal_application_parent_class)->finalize (object);
@@ -258,10 +254,6 @@ gcal_application_get_property (GObject *object,
g_value_set_enum (value, self->time_format);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_object (value, self->weather_service);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -309,7 +301,6 @@ gcal_application_activate (GApplication *application)
"application", self,
"context", self->context,
"active-date", self->initial_date,
- "weather-service", self->weather_service,
"time-format", self->time_format,
NULL);
@@ -355,7 +346,6 @@ gcal_application_startup (GApplication *app)
G_APPLICATION_CLASS (gcal_application_parent_class)->startup (app);
self->colors_provider = gtk_css_provider_new ();
- self->weather_service = gcal_weather_service_new ();
/* Time format */
self->desktop_settings = g_settings_new ("org.gnome.desktop.interface");
@@ -530,12 +520,6 @@ gcal_application_class_init (GcalApplicationClass *klass)
GCAL_TIME_FORMAT_24H,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
- properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
- "The weather service object",
- "The weather service object",
- GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, N_PROPS, properties);
}
@@ -560,9 +544,14 @@ gcal_application_sync (GSimpleAction *sync,
GVariant *parameter,
gpointer app)
{
- GcalApplication *self = GCAL_APPLICATION (app);
+ GcalWeatherService *weather_service;
+ GcalApplication *self;
+
+ self = GCAL_APPLICATION (app);
+ weather_service = gcal_context_get_weather_service (self->context);
+
gcal_manager_refresh (gcal_context_get_manager (self->context));
- gcal_weather_service_update (self->weather_service);
+ gcal_weather_service_update (weather_service);
}
static void
@@ -590,6 +579,7 @@ static gchar*
build_about_copyright (GcalApplication *self)
{
g_autoptr (GDateTime) dt = NULL;
+ GcalWeatherService *weather_service;
const gchar *attribution;
GString *builder;
@@ -601,7 +591,8 @@ build_about_copyright (GcalApplication *self)
_("Copyright \xC2\xA9 2012\xE2\x80\x93%d " "The Calendar authors"),
g_date_time_get_year (dt));
- attribution = gcal_weather_service_get_attribution (self->weather_service);
+ weather_service = gcal_context_get_weather_service (self->context);
+ attribution = gcal_weather_service_get_attribution (weather_service);
if (attribution)
{
g_string_append_c (builder, '\n');
@@ -716,22 +707,6 @@ gcal_application_get_manager (GcalApplication *self)
return gcal_context_get_manager (self->context);
}
-/**
- * gcal_application_get_weather_service:
- * @self: A #GcalApplication
- *
- * Provides the #GcalWeatherService used by this application.
- *
- * Returns: (transfer none): A #GcalWeatehrService
- */
-GcalWeatherService*
-gcal_application_get_weather_service (GcalApplication *self)
-{
- g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
-
- return self->weather_service;
-}
-
void
gcal_application_set_uuid (GcalApplication *self,
const gchar *app_uuid)
diff --git a/src/gcal-application.h b/src/gcal-application.h
index 93d3392c..ab124d38 100644
--- a/src/gcal-application.h
+++ b/src/gcal-application.h
@@ -22,7 +22,6 @@
#include "gcal-clock.h"
#include "gcal-context.h"
-#include "gcal-weather-service.h"
#include "gcal-manager.h"
#include <gtk/gtk.h>
@@ -39,8 +38,6 @@ GcalContext* gcal_application_get_context (GcalApplicatio
GcalManager* gcal_application_get_manager (GcalApplication *self);
-GcalWeatherService* gcal_application_get_weather_service (GcalApplication *self);
-
void gcal_application_set_uuid (GcalApplication *self,
const gchar *app_uuid);
diff --git a/src/gcal-context.c b/src/gcal-context.c
index 87e31ccc..2129d2f2 100644
--- a/src/gcal-context.c
+++ b/src/gcal-context.c
@@ -61,6 +61,8 @@ gcal_context_finalize (GObject *object)
{
GcalContext *self = (GcalContext *)object;
+ gcal_weather_service_stop (self->weather_service);
+
g_clear_object (&self->clock);
g_clear_object (&self->goa_client);
g_clear_object (&self->manager);
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 69d9c34e..b072b02d 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -33,10 +33,8 @@
#include "gcal-week-view.h"
#include "gcal-window.h"
#include "gcal-year-view.h"
-#include "gcal-weather-service.h"
#include <glib/gi18n.h>
-#include <libgweather/gweather.h>
#include <libecal/libecal.h>
#include <libical/icaltime.h>
@@ -162,7 +160,6 @@ struct _GcalWindow
GcalTimeFormat time_format;
/* weather management */
- GcalWeatherService *weather_service;
GcalWeatherSettings *weather_settings;
/* temp to keep event_creation */
@@ -187,7 +184,6 @@ enum
PROP_CONTEXT,
PROP_NEW_EVENT_MODE,
PROP_TIME_FORMAT,
- PROP_WEATHER_SERVICE,
N_PROPS
};
@@ -1231,10 +1227,8 @@ gcal_window_finalize (GObject *object)
g_clear_object (&window->views_switcher);
g_clear_pointer (&window->active_date, g_free);
- G_OBJECT_CLASS (gcal_window_parent_class)->finalize (object);
- gcal_weather_service_stop (window->weather_service);
- g_clear_object (&window->weather_service);
+ G_OBJECT_CLASS (gcal_window_parent_class)->finalize (object);
GCAL_EXIT;
}
@@ -1267,10 +1261,6 @@ gcal_window_constructed (GObject *object)
g_object_bind_property (self, "time-format", self->edit_dialog, "time-format", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
g_object_bind_property (self, "time-format", self->search_popover, "time-format", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
g_object_bind_property (self, "time-format", self->week_view, "time-format", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->weather_settings, "weather-service",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->month_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->week_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->year_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
GCAL_EXIT;
}
@@ -1343,11 +1333,6 @@ gcal_window_set_property (GObject *object,
}
break;
- case PROP_WEATHER_SERVICE:
- if (g_set_object (&self->weather_service, g_value_get_object (value)))
- g_object_notify_by_pspec (object, properties[PROP_WEATHER_SERVICE]);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -1385,10 +1370,6 @@ gcal_window_get_property (GObject *object,
g_value_set_enum (value, self->time_format);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_object (value, self->weather_service);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -1428,7 +1409,6 @@ gcal_window_class_init (GcalWindowClass *klass)
g_type_ensure (GCAL_TYPE_QUICK_ADD_POPOVER);
g_type_ensure (GCAL_TYPE_SEARCH_POPOVER);
g_type_ensure (GCAL_TYPE_SOURCE_DIALOG);
- g_type_ensure (GCAL_TYPE_WEATHER_SERVICE);
g_type_ensure (GCAL_TYPE_WEATHER_SETTINGS);
g_type_ensure (GCAL_TYPE_WEEK_VIEW);
g_type_ensure (GCAL_TYPE_YEAR_VIEW);
@@ -1475,12 +1455,6 @@ gcal_window_class_init (GcalWindowClass *klass)
GCAL_TIME_FORMAT_24H,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
- "The weather service object",
- "The weather service object",
- GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/window.ui");
@@ -1556,8 +1530,6 @@ gcal_window_init (GcalWindow *self)
G_N_ELEMENTS (actions),
self);
- app = g_application_get_default ();
- self->weather_service = gcal_application_get_weather_service (GCAL_APPLICATION (app));
self->time_format = GCAL_TIME_FORMAT_24H;
gtk_widget_init_template (GTK_WIDGET (self));
@@ -1576,6 +1548,7 @@ gcal_window_init (GcalWindow *self)
self->rtl = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL;
/* setup accels */
+ app = g_application_get_default ();
gcal_window_add_accelerator (app, "win.change-view(-1)", "<Ctrl>Page_Down");
gcal_window_add_accelerator (app, "win.change-view(-2)", "<Ctrl>Page_Up");
gcal_window_add_accelerator (app, "win.change-view(1)", "<Ctrl>1")
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 7b4291c2..706e0881 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -122,8 +122,6 @@ struct _GcalMonthView
icaltimetype *date;
GcalContext *context;
- GcalWeatherService *weather_service;
-
gboolean pending_event_allocation;
};
@@ -158,7 +156,6 @@ enum
PROP_0,
PROP_DATE,
PROP_CONTEXT,
- PROP_WEATHER_SERVICE,
N_PROPS
};
@@ -872,16 +869,15 @@ static GcalWeatherInfo*
get_weather_info_for_cell (GcalMonthView *self,
guint cell)
{
+ GcalWeatherService *weather_service;
GcalMonthCell *first_cell;
GPtrArray *weather_infos;
GDateTime *first_dt;
GDate first;
guint i;
- if (!self->weather_service)
- return NULL;
-
- weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
+ weather_service = gcal_context_get_weather_service (self->context);
+ weather_infos = gcal_weather_service_get_weather_infos (weather_service);
first_cell = GCAL_MONTH_CELL (self->month_cell[0][0]);
first_dt = gcal_month_cell_get_date (first_cell);
@@ -2100,15 +2096,14 @@ gcal_month_view_set_property (GObject *object,
self,
G_CONNECT_SWAPPED);
- g_object_notify (object, "context");
- break;
+ g_signal_connect_object (gcal_context_get_weather_service (self->context),
+ "weather-changed",
+ G_CALLBACK (on_weather_service_weather_changed_cb),
+ self,
+ 0);
+ update_weather (self, TRUE);
- case PROP_WEATHER_SERVICE:
- gcal_view_set_weather_service_impl_helper (&self->weather_service,
- g_value_get_object (value),
- (GcalWeatherUpdateFunc) update_weather,
- G_CALLBACK (on_weather_service_weather_changed_cb),
- GTK_WIDGET (self));
+ g_object_notify (object, "context");
break;
default:
@@ -2135,10 +2130,6 @@ gcal_month_view_get_property (GObject *object,
g_value_set_object (value, self->context);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_boxed (value, self->weather_service);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -2157,7 +2148,6 @@ gcal_month_view_finalize (GObject *object)
g_clear_pointer (&self->multi_cell_children, g_list_free);
g_clear_object (&self->context);
- g_clear_object (&self->weather_service);
if (self->update_grid_id > 0)
{
@@ -2201,7 +2191,6 @@ gcal_month_view_class_init (GcalMonthViewClass *klass)
g_object_class_override_property (object_class, PROP_DATE, "active-date");
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
- g_object_class_override_property (object_class, PROP_WEATHER_SERVICE, "weather-service");
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/month-view.ui");
@@ -2229,7 +2218,6 @@ gcal_month_view_init (GcalMonthView *self)
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
- self->weather_service = NULL;
self->children = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_list_free);
self->single_cell_children = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)
g_list_free);
self->overflow_cells = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)
g_list_free);
diff --git a/src/views/gcal-view.c b/src/views/gcal-view.c
index 50064531..7d50240c 100644
--- a/src/views/gcal-view.c
+++ b/src/views/gcal-view.c
@@ -55,18 +55,6 @@ gcal_view_default_init (GcalViewInterface *iface)
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
- /**
- * GcalView::weather-service:
- *
- * The #GcalWeatherService of the view.
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("weather-service",
- "The weather service",
- "The weather service of the view",
- GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
/**
* GcalView::create-event:
*
@@ -149,82 +137,6 @@ gcal_view_get_context (GcalView *self)
return context;
}
-/**
- * gcal_view_get_weather_service:
- * @self: The #GcalView instance.
- * @service: (nullable): The weather service to query.
- *
- * Sets the service to query for weather reports.
- */
-GcalWeatherService*
-gcal_view_get_weather_service (GcalView *self)
-{
- GcalWeatherService *service; /* unowned */
-
- g_return_val_if_fail (GCAL_IS_VIEW (self), NULL);
-
- g_object_get (self, "weather-service", &service, NULL);
- g_object_unref (service);
-
- return service;
-}
-
-/**
- * gcal_view_set_weather_service:
- * @self: The #GcalView instance.
- *
- * Returns: (transfer none): The internal weather service object.
- */
-void
-gcal_view_set_weather_service (GcalView *self,
- GcalWeatherService *service)
-{
- g_return_if_fail (GCAL_IS_VIEW (self));
- g_return_if_fail (service == NULL || GCAL_IS_WEATHER_SERVICE (service));
-
- g_object_set (self, "weather-service", service, NULL);
-}
-
-/**
- * gcal_view_set_weather_service_impl_helper:
- * @old_service: The views weather service field.
- * @new_service: (nullable): The new weather service to use.
- * @update_func: The function to call after updating weather.
- * @weather_changed_cb: The views "weather-changed" handler
- * @data: The data to pass to @update_func and @weather_changed_cb
- *
- * Internal implementation helper for
- * gcal_view_set_weather_service().
- */
-void
-gcal_view_set_weather_service_impl_helper (GcalWeatherService **old_service,
- GcalWeatherService *new_service,
- GcalWeatherUpdateFunc update_func,
- GCallback weather_changed_cb,
- GtkWidget *data)
-{
- g_return_if_fail (old_service != NULL);
- g_return_if_fail (*old_service == NULL || GCAL_IS_WEATHER_SERVICE (*old_service));
- g_return_if_fail (new_service == NULL || GCAL_IS_WEATHER_SERVICE (new_service));
- g_return_if_fail (update_func != NULL);
- g_return_if_fail (weather_changed_cb != NULL);
- g_return_if_fail (GTK_IS_WIDGET (data));
-
- if (*old_service != new_service)
- {
- if (*old_service)
- g_signal_handlers_disconnect_by_func (*old_service, weather_changed_cb, data);
-
- g_set_object (old_service, new_service);
-
- if (*old_service)
- g_signal_connect_object (*old_service, "weather-changed", weather_changed_cb, data, 0);
-
- update_func (data);
- g_object_notify (G_OBJECT (data), "weather-service");
- }
-}
-
/**
* gcal_view_get_date:
* @view: a #GcalView
diff --git a/src/views/gcal-view.h b/src/views/gcal-view.h
index caad5eee..c8dc0d60 100644
--- a/src/views/gcal-view.h
+++ b/src/views/gcal-view.h
@@ -21,7 +21,6 @@
#include "gcal-context.h"
#include "gcal-event-widget.h"
-#include "gcal-weather-service.h"
G_BEGIN_DECLS
@@ -29,8 +28,6 @@ G_BEGIN_DECLS
G_DECLARE_INTERFACE (GcalView, gcal_view, GCAL, VIEW, GtkWidget)
-typedef void (*GcalWeatherUpdateFunc) (GtkWidget *widget);
-
struct _GcalViewInterface
{
GTypeInterface parent;
@@ -66,17 +63,6 @@ icaltimetype* gcal_view_get_date (GcalView
GcalContext* gcal_view_get_context (GcalView *self);
-GcalWeatherService* gcal_view_get_weather_service (GcalView *view);
-
-void gcal_view_set_weather_service (GcalView *view,
- GcalWeatherService *service);
-
-void gcal_view_set_weather_service_impl_helper (GcalWeatherService **old_service,
- GcalWeatherService *new_service,
- GcalWeatherUpdateFunc update_func,
- GCallback weather_changed_cb,
- GtkWidget *data);
-
void gcal_view_clear_marks (GcalView *view);
GList* gcal_view_get_children_by_uuid (GcalView *view,
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index 70b568a5..6b41e703 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -108,13 +108,6 @@ typedef enum
DOWN
} MoveDirection;
-enum
-{
- PROP_0,
- PROP_WEATHER_SERVICE,
- NUM_PROPS
-};
-
enum
{
EVENT_ACTIVATED,
@@ -145,6 +138,77 @@ wid_clear (WeatherInfoDay *wid)
g_clear_object (&wid->icon_buf);
}
+static gint
+add_weather_infos (GcalWeekHeader *self,
+ GPtrArray *weather_infos)
+{
+ g_autoptr (GDateTime) week_start_dt = NULL;
+ GDate week_start;
+ gint consumed = 0;
+ guint i;
+
+ if (!self->active_date)
+ return 0;
+
+ week_start_dt = get_start_of_week (self->active_date);
+ g_date_set_dmy (&week_start,
+ g_date_time_get_day_of_month (week_start_dt),
+ g_date_time_get_month (week_start_dt),
+ g_date_time_get_year (week_start_dt));
+
+ for (i = 0; weather_infos && i < weather_infos->len; i++)
+ {
+ GcalWeatherInfo *gwi; /* unowned */
+ GDate gwi_date;
+ gint day_diff;
+
+ gwi = g_ptr_array_index (weather_infos, i);
+
+ gcal_weather_info_get_date (gwi, &gwi_date);
+
+ day_diff = g_date_days_between (&week_start, &gwi_date);
+ if (day_diff >= 0 && day_diff < G_N_ELEMENTS (self->weather_infos))
+ {
+ wid_clear (&self->weather_infos[day_diff]);
+ self->weather_infos[day_diff].winfo = g_object_ref (gwi);
+ consumed++;
+ }
+ }
+
+ if (consumed > 0)
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+
+ return consumed;
+}
+
+static void
+clear_weather_infos (GcalWeekHeader *self)
+{
+ g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
+
+ for (gint i = 0; i < G_N_ELEMENTS (self->weather_infos); i++)
+ wid_clear (&self->weather_infos[i]);
+
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+update_weather_infos (GcalWeekHeader *self)
+{
+ GPtrArray* weather_infos;
+
+ g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
+
+ clear_weather_infos (self);
+
+ if (!self->weather_service)
+ return;
+
+ weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
+ add_weather_infos (self, weather_infos);
+}
+
+
/* Event activation methods */
static void
on_event_widget_activated (GcalEventWidget *widget,
@@ -287,11 +351,11 @@ static void
on_weather_update (GcalWeatherService *weather_service,
GcalWeekHeader *self)
{
- g_return_if_fail (GCAL_IS_WEATHER_SERVICE (weather_service));
- g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
- g_return_if_fail (self->weather_service == weather_service);
+ g_assert (GCAL_IS_WEATHER_SERVICE (weather_service));
+ g_assert (GCAL_IS_WEEK_HEADER (self));
+ g_assert (self->weather_service == weather_service);
- gcal_week_header_update_weather_infos (self);
+ update_weather_infos (self);
}
static GcalEvent*
@@ -1104,46 +1168,6 @@ gcal_week_header_finalize (GObject *object)
wid_clear (&self->weather_infos[i]);
}
-static void
-gcal_week_header_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
-
- switch (property_id)
- {
- case PROP_WEATHER_SERVICE:
- g_value_set_boxed (value, self->weather_service);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
-static void
-gcal_week_header_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
-
- switch (property_id)
- {
- case PROP_WEATHER_SERVICE:
- gcal_week_header_set_weather_service (self, GCAL_WEATHER_SERVICE (g_value_get_object (value)));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
-}
-
static void
gcal_week_header_size_allocate (GtkWidget *widget,
GtkAllocation *alloc)
@@ -1615,8 +1639,6 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (kclass);
object_class->finalize = gcal_week_header_finalize;
- object_class->get_property = gcal_week_header_get_property;
- object_class->set_property = gcal_week_header_set_property;
widget_class->draw = gcal_week_header_draw;
widget_class->size_allocate = gcal_week_header_size_allocate;
@@ -1624,19 +1646,6 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
widget_class->drag_leave = gcal_week_header_drag_leave;
widget_class->drag_drop = gcal_week_header_drag_drop;
- /**
- * GcalWeekHeader::weather-service:
- *
- * The #GcalWeatherService of the view.
- */
- g_object_class_install_property (G_OBJECT_CLASS (kclass),
- PROP_WEATHER_SERVICE,
- g_param_spec_object ("weather-service",
- "The weather service",
- "The weather service of the view",
- GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
signals[EVENT_ACTIVATED] = g_signal_new ("event-activated",
GCAL_TYPE_WEEK_HEADER,
G_SIGNAL_RUN_FIRST,
@@ -1690,127 +1699,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
GDK_ACTION_MOVE);
}
-/* Private API */
-
-/* gcal_week_header_add_weather_infos:
- * @self: (not nullable): The #GcalWeekHeader instance.
- * @winfo: List of #GcalWeatherInfos to add to @self.
- *
- * Adds weather information to this header. @self
- * only adds weather information that can be
- * displayed with current settings.
- *
- * Return: Number of consumed weather information
- * objects.
- */
-static gint
-gcal_week_header_add_weather_infos (GcalWeekHeader *self,
- GPtrArray *weather_infos)
-{
- g_autoptr (GDateTime) week_start_dt = NULL;
- GDate week_start;
- gint consumed = 0;
- guint i;
-
- if (!self->active_date)
- return 0;
-
- week_start_dt = get_start_of_week (self->active_date);
- g_date_set_dmy (&week_start,
- g_date_time_get_day_of_month (week_start_dt),
- g_date_time_get_month (week_start_dt),
- g_date_time_get_year (week_start_dt));
-
- for (i = 0; weather_infos && i < weather_infos->len; i++)
- {
- GcalWeatherInfo *gwi; /* unowned */
- GDate gwi_date;
- gint day_diff;
-
- gwi = g_ptr_array_index (weather_infos, i);
-
- gcal_weather_info_get_date (gwi, &gwi_date);
-
- day_diff = g_date_days_between (&week_start, &gwi_date);
- if (day_diff >= 0 && day_diff < G_N_ELEMENTS (self->weather_infos))
- {
- wid_clear (&self->weather_infos[day_diff]);
- self->weather_infos[day_diff].winfo = g_object_ref (gwi);
- consumed++;
- }
- }
-
- if (consumed > 0)
- gtk_widget_queue_draw (GTK_WIDGET (self));
-
- return consumed;
-}
-
-/* gcal_week_header_clear_weather_infos:
- * @self: The #GcalWeekHeader instance.
- *
- * Removes all registered weather information objects from
- * this widget.
- */
-static void
-gcal_week_header_clear_weather_infos (GcalWeekHeader *self)
-{
- g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
-
- for (gint i = 0; i < G_N_ELEMENTS (self->weather_infos); i++)
- wid_clear (&self->weather_infos[i]);
-
- gtk_widget_queue_draw (GTK_WIDGET (self));
-}
-
-
-/* Public API */
-
-/**
- * gcal_week_header_set_weather_service:
- * @self: The #GcalWeekHeader instance.
- * @service: (nullable): The weather service to query.
- *
- * Note that #GcalWeekHeader does not hold a strong reference
- * to its weather service.
- */
-void
-gcal_week_header_set_weather_service (GcalWeekHeader *self,
- GcalWeatherService *service)
-{
- g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
- g_return_if_fail (service == NULL || GCAL_IS_WEATHER_SERVICE (service));
-
- gcal_view_set_weather_service_impl_helper (&self->weather_service,
- service,
- (GcalWeatherUpdateFunc) gcal_week_header_update_weather_infos,
- (GCallback) on_weather_update,
- GTK_WIDGET (self));
-}
-
-/**
- * gcal_week_header_update_weather_infos:
- * @self: The #GcalWeekHeader instance.
- *
- * Retrieves latest weather information from registered
- * weather service and displays it.
- */
-void
-gcal_week_header_update_weather_infos (GcalWeekHeader *self)
-{
- GPtrArray* weather_infos;
-
- g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
-
- gcal_week_header_clear_weather_infos (self);
-
- if (!self->weather_service)
- return;
-
- weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
- gcal_week_header_add_weather_infos (self, weather_infos);
-}
-
void
gcal_week_header_set_context (GcalWeekHeader *self,
GcalContext *context)
@@ -1824,6 +1712,14 @@ gcal_week_header_set_context (GcalWeekHeader *self,
G_CALLBACK (gtk_widget_queue_draw),
self,
G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (gcal_context_get_weather_service (self->context),
+ "weather-changed",
+ G_CALLBACK (on_weather_update),
+ self,
+ 0);
+
+ update_weather_infos (self);
}
void
@@ -2034,32 +1930,8 @@ gcal_week_header_set_date (GcalWeekHeader *self,
if (old_date)
update_unchanged_events (self, self->active_date);
- gcal_week_header_update_weather_infos (self);
+ update_weather_infos (self);
g_clear_pointer (&old_date, g_free);
}
-/**
- * gcal_week_header_get_weather_infos:
- * @self: The #GcalWeekHeader instance.
- *
- * Returns a list of shown weather informations.
- *
- * @Returns: (transfer container):
- * A GSList. The callee is responsible for freeing it.
- * Elements are owned by the widget. Do not modify.
- */
-GSList*
-gcal_week_header_get_shown_weather_infos (GcalWeekHeader *self)
-{
- g_return_val_if_fail (GCAL_IS_WEEK_HEADER (self), NULL);
- GSList* lst = NULL; /* owned[unowned] */
-
- for (int i = 0; i < G_N_ELEMENTS (self->weather_infos); i++)
- {
- if (self->weather_infos[i].winfo != NULL)
- lst = g_slist_prepend (lst, self->weather_infos[i].winfo);
- }
-
- return lst;
-}
diff --git a/src/views/gcal-week-header.h b/src/views/gcal-week-header.h
index c57a1bf3..df86a526 100644
--- a/src/views/gcal-week-header.h
+++ b/src/views/gcal-week-header.h
@@ -52,13 +52,6 @@ void gcal_week_header_clear_marks (GcalWeekHeader
void gcal_week_header_set_date (GcalWeekHeader *self,
icaltimetype *date);
-void gcal_week_header_set_weather_service (GcalWeekHeader *self,
- GcalWeatherService *service);
-
-void gcal_week_header_update_weather_infos (GcalWeekHeader *self);
-
-GSList* gcal_week_header_get_shown_weather_infos (GcalWeekHeader *self);
-
G_END_DECLS
#endif /* GCAL_WEEK_HEADER_H */
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 5a65ae23..b21ebcf2 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -26,7 +26,6 @@
#include "gcal-week-header.h"
#include "gcal-week-grid.h"
#include "gcal-week-view.h"
-#include "gcal-weather-service.h"
#include <glib/gi18n.h>
@@ -54,7 +53,6 @@ struct _GcalWeekView
/* property */
icaltimetype *date;
GcalContext *context;
- GcalWeatherService *weather_service; /* owned */
guint scroll_grid_timeout_id;
@@ -73,7 +71,6 @@ enum
PROP_DATE,
PROP_CONTEXT,
PROP_TIME_FORMAT,
- PROP_WEATHER_SERVICE,
NUM_PROPS
};
@@ -507,7 +504,6 @@ gcal_week_view_finalize (GObject *object)
g_clear_pointer (&self->date, g_free);
g_clear_object (&self->context);
- g_clear_object (&self->weather_service);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (gcal_week_view_parent_class)->finalize (object);
@@ -540,11 +536,6 @@ gcal_week_view_set_property (GObject *object,
gtk_widget_queue_draw (self->hours_bar);
break;
- case PROP_WEATHER_SERVICE:
- if (g_set_object (&self->weather_service, g_value_get_object (value)))
- g_object_notify (object, "weather-service");
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -576,10 +567,6 @@ gcal_week_view_get_property (GObject *object,
g_value_set_enum (value, self->time_format);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_object (value, self->weather_service);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -601,7 +588,6 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
g_object_class_override_property (object_class, PROP_DATE, "active-date");
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
- g_object_class_override_property (object_class, PROP_WEATHER_SERVICE, "weather-service");
g_object_class_install_property (object_class,
PROP_TIME_FORMAT,
@@ -631,9 +617,5 @@ gcal_week_view_init (GcalWeekView *self)
gtk_widget_init_template (GTK_WIDGET (self));
update_hours_sidebar_size (self);
-
- self->weather_service = NULL;
-
- g_object_bind_property (self, "weather-service", self->header, "weather-service", G_BINDING_DEFAULT);
}
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 8f44c1de..2edff1cd 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -68,7 +68,6 @@ struct _GcalYearView
/* manager singleton */
GcalContext *context;
- GcalWeatherService *weather_service; /* owned, nullable */
/* range shown on the sidebar */
icaltimetype *start_selected_date;
@@ -122,7 +121,6 @@ enum {
PROP_0,
PROP_DATE,
PROP_CONTEXT,
- PROP_WEATHER_SERVICE,
PROP_SHOW_WEEK_NUMBERS,
LAST_PROP
};
@@ -1614,7 +1612,6 @@ gcal_year_view_finalize (GObject *object)
g_clear_pointer (&year_view->date, g_free);
g_clear_object (&year_view->calendar_settings);
- g_clear_object (&year_view->weather_service);
for (i = 0; i < 12; i++)
g_clear_pointer (&year_view->events[i], g_ptr_array_unref);
@@ -1640,10 +1637,6 @@ gcal_year_view_get_property (GObject *object,
g_value_set_object (value, self->context);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_object (value, self->weather_service);
- break;
-
case PROP_SHOW_WEEK_NUMBERS:
g_value_set_boolean (value, self->show_week_numbers);
break;
@@ -1676,15 +1669,14 @@ gcal_year_view_set_property (GObject *object,
self,
G_CONNECT_SWAPPED);
- g_object_notify (object, "context");
- break;
+ g_signal_connect_object (gcal_context_get_weather_service (self->context),
+ "weather-changed",
+ G_CALLBACK (weather_changed),
+ self,
+ 0);
+ update_weather (self);
- case PROP_WEATHER_SERVICE:
- gcal_view_set_weather_service_impl_helper (&self->weather_service,
- g_value_get_object (value),
- (GcalWeatherUpdateFunc) update_weather,
- (GCallback) weather_changed,
- GTK_WIDGET (self));
+ g_object_notify (object, "context");
break;
case PROP_SHOW_WEEK_NUMBERS:
@@ -1978,7 +1970,6 @@ gcal_year_view_class_init (GcalYearViewClass *klass)
g_object_class_override_property (object_class, PROP_DATE, "active-date");
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
- g_object_class_override_property (object_class, PROP_WEATHER_SERVICE, "weather-service");
g_object_class_install_property (object_class,
PROP_SHOW_WEEK_NUMBERS,
@@ -2021,8 +2012,6 @@ gcal_year_view_init (GcalYearView *self)
{
guint i;
- self->weather_service = NULL;
-
for (i = 0; i < 12; i++)
self->events[i] = g_ptr_array_new_with_free_func (g_object_unref);
@@ -2076,11 +2065,14 @@ gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *ifa
static void
update_weather (GcalYearView *self)
{
+ GcalWeatherService *weather_service;
gboolean updated = FALSE;
g_return_if_fail (GCAL_IS_YEAR_VIEW (self));
- if (self->weather_service && self->date)
+ weather_service = gcal_context_get_weather_service (self->context);
+
+ if (self->date)
{
GPtrArray *weather_infos;
GDate date;
@@ -2088,7 +2080,7 @@ update_weather (GcalYearView *self)
g_date_set_dmy (&date, self->date->day, self->date->month, self->date->year);
- weather_infos = gcal_weather_service_get_weather_infos (self->weather_service);
+ weather_infos = gcal_weather_service_get_weather_infos (weather_service);
for (i = 0; weather_infos && i < weather_infos->len; i++)
{
diff --git a/src/weather/gcal-weather-service.c b/src/weather/gcal-weather-service.c
index 53e2ce9a..5ca08a27 100644
--- a/src/weather/gcal-weather-service.c
+++ b/src/weather/gcal-weather-service.c
@@ -1191,3 +1191,28 @@ gcal_weather_service_stop (GcalWeatherService *self)
GCAL_EXIT;
}
+
+/**
+ * gcal_weather_service_connect_widget:
+ * @old_service: The views weather service field.
+ * @new_service: (nullable): The new weather service to use.
+ * @update_func: The function to call after updating weather.
+ * @weather_changed_cb: The views "weather-changed" handler
+ * @data: The data to pass to @update_func and @weather_changed_cb
+ *
+ * Internal implementation helper for widgets.
+ */
+void
+gcal_weather_service_connect_widget (GcalWeatherService *self,
+ GcalWeatherUpdateFunc update_func,
+ GCallback weather_changed_cb,
+ GtkWidget *data)
+{
+ g_return_if_fail (GCAL_IS_WEATHER_SERVICE (self));
+ g_return_if_fail (update_func != NULL);
+ g_return_if_fail (weather_changed_cb != NULL);
+ g_return_if_fail (GTK_IS_WIDGET (data));
+
+ g_signal_connect_object (self, "weather-changed", weather_changed_cb, data, 0);
+ update_func (data);
+}
diff --git a/src/weather/gcal-weather-service.h b/src/weather/gcal-weather-service.h
index 06f1aaf4..7485a913 100644
--- a/src/weather/gcal-weather-service.h
+++ b/src/weather/gcal-weather-service.h
@@ -28,9 +28,9 @@
G_BEGIN_DECLS
#define GCAL_TYPE_WEATHER_SERVICE (gcal_weather_service_get_type())
-
G_DECLARE_FINAL_TYPE (GcalWeatherService, gcal_weather_service, GCAL, WEATHER_SERVICE, GObject)
+typedef void (*GcalWeatherUpdateFunc) (GtkWidget *widget);
GcalWeatherService* gcal_weather_service_new (void);
@@ -50,6 +50,11 @@ void gcal_weather_service_run (GcalWeatherSer
void gcal_weather_service_stop (GcalWeatherService *self);
+void gcal_weather_service_connect_widget (GcalWeatherService *self,
+ GcalWeatherUpdateFunc update_func,
+ GCallback weather_changed_cb,
+ GtkWidget *data);
+
G_END_DECLS
#endif /* GCAL_WEATHER_SERVICE_H */
diff --git a/src/weather/gcal-weather-settings.c b/src/weather/gcal-weather-settings.c
index fd0a6b78..dd17df7d 100644
--- a/src/weather/gcal-weather-settings.c
+++ b/src/weather/gcal-weather-settings.c
@@ -34,8 +34,6 @@ struct _GcalWeatherSettings
GtkWidget *weather_location_entry;
GcalContext *context;
-
- GcalWeatherService *weather_service;
};
@@ -56,7 +54,6 @@ enum
{
PROP_0,
PROP_CONTEXT,
- PROP_WEATHER_SERVICE,
N_PROPS
};
@@ -191,8 +188,12 @@ get_checked_fixed_location (GcalWeatherSettings *self)
static void
manage_weather_service (GcalWeatherSettings *self)
{
+ GcalWeatherService *weather_service;
+
GCAL_ENTRY;
+ weather_service = gcal_context_get_weather_service (self->context);
+
if (gtk_switch_get_active (self->show_weather_switch))
{
g_autoptr (GWeatherLocation) location = NULL;
@@ -205,11 +206,11 @@ manage_weather_service (GcalWeatherSettings *self)
g_warning ("Unknown location '%s' selected", gtk_entry_get_text (GTK_ENTRY
(self->weather_location_entry)));
}
- gcal_weather_service_run (self->weather_service, location);
+ gcal_weather_service_run (weather_service, location);
}
else
{
- gcal_weather_service_stop (self->weather_service);
+ gcal_weather_service_stop (weather_service);
}
GCAL_EXIT;
@@ -268,7 +269,6 @@ on_weather_location_searchbox_changed_cb (GWeatherLocationEntry *entry,
}
-
/*
* GObject overrides
*/
@@ -278,7 +278,7 @@ gcal_weather_settings_finalize (GObject *object)
{
GcalWeatherSettings *self = (GcalWeatherSettings *)object;
- g_clear_object (&self->weather_service);
+ g_clear_object (&self->context);
G_OBJECT_CLASS (gcal_weather_settings_parent_class)->finalize (object);
}
@@ -297,10 +297,6 @@ gcal_weather_settings_get_property (GObject *object,
g_value_set_object (value, self->context);
break;
- case PROP_WEATHER_SERVICE:
- g_value_set_object (value, self->weather_service);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -327,10 +323,6 @@ gcal_weather_settings_set_property (GObject *object,
}
break;
- case PROP_WEATHER_SERVICE:
- gcal_weather_settings_set_weather_service (self, g_value_get_object (value));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -352,12 +344,6 @@ gcal_weather_settings_class_init (GcalWeatherSettingsClass *klass)
GCAL_TYPE_CONTEXT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
- "The weather service object",
- "The weather service object",
- GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/weather-settings.ui");
@@ -376,32 +362,3 @@ gcal_weather_settings_init (GcalWeatherSettings *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
-
-GcalWeatherService*
-gcal_weather_settings_get_weather_service (GcalWeatherSettings *self)
-{
- g_return_val_if_fail (GCAL_IS_WEATHER_SETTINGS (self), NULL);
-
- return self->weather_service;
-}
-
-void
-gcal_weather_settings_set_weather_service (GcalWeatherSettings *self,
- GcalWeatherService *service)
-{
- g_return_if_fail (GCAL_IS_WEATHER_SETTINGS (self));
-
- GCAL_ENTRY;
-
- if (!g_set_object (&self->weather_service, service))
- GCAL_RETURN ();
-
- /* Recover weather settings */
- load_weather_settings (self);
- update_menu_weather_sensitivity (self);
- manage_weather_service (self);
-
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WEATHER_SERVICE]);
-
- GCAL_EXIT;
-}
diff --git a/src/weather/gcal-weather-settings.h b/src/weather/gcal-weather-settings.h
index 7c4138d9..3365dd31 100644
--- a/src/weather/gcal-weather-settings.h
+++ b/src/weather/gcal-weather-settings.h
@@ -25,12 +25,7 @@
G_BEGIN_DECLS
#define GCAL_TYPE_WEATHER_SETTINGS (gcal_weather_settings_get_type())
-
G_DECLARE_FINAL_TYPE (GcalWeatherSettings, gcal_weather_settings, GCAL, WEATHER_SETTINGS, GtkBox)
-GcalWeatherService* gcal_weather_settings_get_weather_service (GcalWeatherSettings *self);
-
-void gcal_weather_settings_set_weather_service (GcalWeatherSettings *self,
- GcalWeatherService *service);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]