[gnome-calendar] search-button: Add a context property



commit dfbd7fca26dc28ccd9aa8ff453e10f074dafd4d0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Apr 26 20:05:03 2019 -0300

    search-button: Add a context property
    
    We will use it later when GcalContext has a search
    engine.

 src/gcal-window.c               |  1 +
 src/search/gcal-search-button.c | 87 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 87 insertions(+), 1 deletion(-)
---
diff --git a/src/gcal-window.c b/src/gcal-window.c
index f3560eb5..7bd94482 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1161,6 +1161,7 @@ gcal_window_constructed (GObject *object)
   g_object_bind_property (self, "context", self->edit_dialog, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
   g_object_bind_property (self, "context", self->search_popover, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
   g_object_bind_property (self, "context", self->quick_add_popover, "context", G_BINDING_DEFAULT | 
G_BINDING_SYNC_CREATE);
+  g_object_bind_property (self, "context", self->search_button, "context", G_BINDING_DEFAULT);
 
   GCAL_EXIT;
 }
diff --git a/src/search/gcal-search-button.c b/src/search/gcal-search-button.c
index bf0d2ad3..669b3508 100644
--- a/src/search/gcal-search-button.c
+++ b/src/search/gcal-search-button.c
@@ -20,15 +20,27 @@
 
 #define G_LOG_DOMAIN "GcalSearchButton"
 
+#include "gcal-context.h"
 #include "gcal-search-button.h"
 
 struct _GcalSearchButton
 {
-  DzlSuggestionButton parent;
+  DzlSuggestionButton  parent;
+
+  GcalContext         *context;
 };
 
 G_DEFINE_TYPE (GcalSearchButton, gcal_search_button, DZL_TYPE_SUGGESTION_BUTTON)
 
+enum
+{
+  PROP_0,
+  PROP_CONTEXT,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
 
 /*
  * Callbacks
@@ -67,9 +79,82 @@ on_shortcut_grab_focus_cb (GtkWidget *widget,
 }
 
 
+/*
+ * GObject overrides
+ */
+
+
+static void
+gcal_search_button_finalize (GObject *object)
+{
+  GcalSearchButton *self = (GcalSearchButton *)object;
+
+  g_clear_object (&self->context);
+
+  G_OBJECT_CLASS (gcal_search_button_parent_class)->finalize (object);
+}
+
+static void
+gcal_search_button_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GcalSearchButton *self = GCAL_SEARCH_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      g_value_set_object (value, self->context);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gcal_search_button_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GcalSearchButton *self = GCAL_SEARCH_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      g_assert (self->context == NULL);
+      self->context = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+
 static void
 gcal_search_button_class_init (GcalSearchButtonClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gcal_search_button_finalize;
+  object_class->get_property = gcal_search_button_get_property;
+  object_class->set_property = gcal_search_button_set_property;
+
+  /**
+   * GcalSearchButton::context:
+   *
+   * The #GcalContext of the application.
+   */
+  properties[PROP_CONTEXT] = g_param_spec_object ("context",
+                                                  "Context of the application",
+                                                  "The context of the application",
+                                                  GCAL_TYPE_CONTEXT,
+                                                  G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | 
G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
 static void


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