[gnome-calendar] context: Introduce GcalContext



commit 9a13fb5c2a3d15b1bd463679955de8bdd60af9d7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Apr 24 00:34:50 2019 -0300

    context: Introduce GcalContext
    
    This is just the bare minimum of what will become
    the main context class of GNOME Calendar. As of
    now, nothing creates or uses it.

 src/gcal-context.c | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcal-context.h |  42 +++++++++++
 src/meson.build    |   1 +
 3 files changed, 245 insertions(+)
---
diff --git a/src/gcal-context.c b/src/gcal-context.c
new file mode 100644
index 00000000..9d4888dc
--- /dev/null
+++ b/src/gcal-context.c
@@ -0,0 +1,202 @@
+/* gcal-context.c
+ *
+ * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "GcalContext"
+
+#include "gcal-context.h"
+
+struct _GcalContext
+{
+  GObject             parent;
+
+  GcalClock          *clock;
+  GcalManager        *manager;
+  GcalWeatherService *weather_service;
+};
+
+G_DEFINE_TYPE (GcalContext, gcal_context, G_TYPE_OBJECT)
+
+enum
+{
+  PROP_0,
+  PROP_CLOCK,
+  PROP_MANAGER,
+  PROP_WEATHER_SERVICE,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+
+/*
+ * GObject overrides
+ */
+
+static void
+gcal_context_finalize (GObject *object)
+{
+  GcalContext *self = (GcalContext *)object;
+
+  g_clear_object (&self->clock);
+  g_clear_object (&self->manager);
+  g_clear_object (&self->weather_service);
+
+  G_OBJECT_CLASS (gcal_context_parent_class)->finalize (object);
+}
+
+static void
+gcal_context_get_property (GObject    *object,
+                           guint       prop_id,
+                           GValue     *value,
+                           GParamSpec *pspec)
+{
+  GcalContext *self = GCAL_CONTEXT (object);
+
+  switch (prop_id)
+    {
+    case PROP_CLOCK:
+      g_value_set_object (value, self->clock);
+      break;
+
+    case PROP_MANAGER:
+      g_value_set_object (value, self->manager);
+      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);
+    }
+}
+
+static void
+gcal_context_set_property (GObject      *object,
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
+{
+  switch (prop_id)
+    {
+    case PROP_CLOCK:
+    case PROP_MANAGER:
+    case PROP_WEATHER_SERVICE:
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gcal_context_class_init (GcalContextClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gcal_context_finalize;
+  object_class->get_property = gcal_context_get_property;
+  object_class->set_property = gcal_context_set_property;
+
+  properties[PROP_CLOCK] = g_param_spec_object ("clock",
+                                                "Wall clock",
+                                                "Main clock driving the calendar timeline",
+                                                GCAL_TYPE_CLOCK,
+                                                G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | 
G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_MANAGER] = g_param_spec_object ("manager",
+                                                  "Data manager",
+                                                  "Data manager of the application",
+                                                  GCAL_TYPE_MANAGER,
+                                                  G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | 
G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
+                                                          "Weather service",
+                                                          "Weather service",
+                                                          GCAL_TYPE_WEATHER_SERVICE,
+                                                          G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | 
G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gcal_context_init (GcalContext *self)
+{
+  self->clock = gcal_clock_new ();
+  self->manager = gcal_manager_new ();
+  self->weather_service = gcal_weather_service_new ();
+}
+
+/**
+ * gcal_context_new: (skip)
+ *
+ * Create a new GcalContext. Only one context must be
+ * available during the application lifetime.
+ *
+ * Returns: (transfer full): a #GcalContext
+ */
+GcalContext*
+gcal_context_new (void)
+{
+  return g_object_new (GCAL_TYPE_CONTEXT, NULL);
+}
+
+/**
+ * gcal_context_get_clock:
+ *
+ * Retrieves the #GcalClock from @self.
+ *
+ * Returns: (transfer none): a #GcalClock
+ */
+GcalClock*
+gcal_context_get_clock (GcalContext *self)
+{
+  g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
+
+  return self->clock;
+}
+
+/**
+ * gcal_context_get_manager:
+ *
+ * Retrieves the #GcalManager from @self.
+ *
+ * Returns: (transfer none): a #GcalManager
+ */
+GcalManager*
+gcal_context_get_manager (GcalContext *self)
+{
+  g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
+
+  return self->manager;
+}
+
+/**
+ * gcal_context_get_weather_service:
+ *
+ * Retrieves the #GcalWeatherService from @self.
+ *
+ * Returns: (transfer none): a #GcalWeatherService
+ */
+GcalWeatherService*
+gcal_context_get_weather_service (GcalContext *self)
+{
+  g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
+
+  return self->weather_service;
+}
diff --git a/src/gcal-context.h b/src/gcal-context.h
new file mode 100644
index 00000000..34f2e86c
--- /dev/null
+++ b/src/gcal-context.h
@@ -0,0 +1,42 @@
+/* gcal-context.h
+ *
+ * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "gcal-clock.h"
+#include "gcal-manager.h"
+#include "weather/gcal-weather-service.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_CONTEXT (gcal_context_get_type())
+G_DECLARE_FINAL_TYPE (GcalContext, gcal_context, GCAL, CONTEXT, GObject)
+
+GcalContext*         gcal_context_new                            (void);
+
+GcalClock*           gcal_context_get_clock                      (GcalContext        *self);
+
+GcalManager*         gcal_context_get_manager                    (GcalContext        *self);
+
+GcalWeatherService*  gcal_context_get_weather_service            (GcalContext        *self);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 724ff425..ce5685a7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -34,6 +34,7 @@ sources = files(
   'weather/gcal-weather-settings.c',
   'gcal-application.c',
   'gcal-clock.c',
+  'gcal-context.c',
   'gcal-date-chooser-day.c',
   'gcal-date-chooser.c',
   'gcal-date-selector.c',


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