[gnome-calendar/wip/flb/weather-forecast: 101/135] weather: Pin weather services to applications.



commit 950a2cda8fdc2b53c07fffba8e59d82d4a5c6d0d
Author: Florian Brosch <flo brosch gmail com>
Date:   Thu Oct 12 23:51:57 2017 +0200

    weather: Pin weather services to applications.

 src/gcal-application.c | 30 +++++++++++++++++++++++++++++-
 src/gcal-application.h |  3 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 470f416d..63d27c63 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -35,6 +35,9 @@
 #include <gio/gio.h>
 #include <glib/gi18n.h>
 
+#define WEATHER_CHECK_INTERVAL 7200 /* seconds */
+#define FORECAST_MAX_DAYS      3
+
 struct _GcalApplication
 {
   GtkApplication      parent;
@@ -49,6 +52,12 @@ struct _GcalApplication
   gchar              *uuid;
   icaltimetype       *initial_date;
 
+  /* Weather service exists as long as #GcalApplication.
+   * However, it only runs if #GcalApplicatoin->window
+   * is available.
+   */
+  GcalWeatherService *weather_service; /* owned */
+
   GcalShellSearchProvider *search_provider;
 };
 
@@ -198,6 +207,7 @@ gcal_application_finalize (GObject *object)
   g_clear_object (&self->colors_provider);
 
   g_clear_object (&self->manager);
+  g_clear_object (&self->weather_service);
   g_clear_object (&self->search_provider);
 
   G_OBJECT_CLASS (gcal_application_parent_class)->finalize (object);
@@ -412,7 +422,9 @@ gcal_application_init (GcalApplication *self)
   self->manager = gcal_manager_new ();
   g_signal_connect_swapped (self->manager, "source-added", G_CALLBACK (process_sources), self);
   g_signal_connect_swapped (self->manager, "source-changed", G_CALLBACK (process_sources), self);
-
+  self->weather_service = gcal_weather_service_new (NULL, /* in prep. for configurable time zones */
+                                                    FORECAST_MAX_DAYS,
+                                                    WEATHER_CHECK_INTERVAL);
   self->search_provider = gcal_shell_search_provider_new ();
   gcal_shell_search_provider_connect (self->search_provider, self->manager);
 }
@@ -537,6 +549,22 @@ gcal_application_get_manager (GcalApplication *self)
   return self->manager;
 }
 
+/**
+ * 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 9dc369da..224f1929 100644
--- a/src/gcal-application.h
+++ b/src/gcal-application.h
@@ -20,6 +20,7 @@
 #ifndef _GCAL_APPLICATION_H_
 #define _GCAL_APPLICATION_H_
 
+#include "gcal-weather-service.h"
 #include "gcal-manager.h"
 
 #include <gtk/gtk.h>
@@ -34,6 +35,8 @@ GcalApplication*     gcal_application_new                        (void);
 
 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);
 


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