[devhelp] Sidebar: add construct-only "profile" property



commit 4950c1bbf8626f2d206271bec2137730e63538b2
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Apr 5 14:54:45 2018 +0200

    Sidebar: add construct-only "profile" property
    
    dh_sidebar_new() is called in Anjuta with a DhBookManager non-NULL
    argument, so do not break the API.

 devhelp/dh-sidebar.c                |  130 +++++++++++++++++++++++++++++++++++
 devhelp/dh-sidebar.h                |    8 ++-
 docs/reference/devhelp-sections.txt |    2 +
 src/dh-window.c                     |    2 +-
 4 files changed, 140 insertions(+), 2 deletions(-)
---
diff --git a/devhelp/dh-sidebar.c b/devhelp/dh-sidebar.c
index 4e626fe..02d5316 100644
--- a/devhelp/dh-sidebar.c
+++ b/devhelp/dh-sidebar.c
@@ -54,6 +54,8 @@
  */
 
 typedef struct {
+        DhProfile *profile;
+
         /* A GtkSearchEntry. */
         GtkEntry *entry;
 
@@ -73,15 +75,86 @@ enum {
         N_SIGNALS
 };
 
+enum {
+        PROP_0,
+        PROP_PROFILE,
+        N_PROPERTIES
+};
+
 static guint signals[N_SIGNALS] = { 0 };
+static GParamSpec *properties[N_PROPERTIES];
 
 G_DEFINE_TYPE_WITH_PRIVATE (DhSidebar, dh_sidebar, GTK_TYPE_GRID)
 
 static void
+set_profile (DhSidebar *sidebar,
+             DhProfile *profile)
+{
+        DhSidebarPrivate *priv = dh_sidebar_get_instance_private (sidebar);
+
+        g_return_if_fail (profile == NULL || DH_IS_PROFILE (profile));
+
+        g_assert (priv->profile == NULL);
+        g_set_object (&priv->profile, profile);
+}
+
+static void
+dh_sidebar_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+        DhSidebar *sidebar = DH_SIDEBAR (object);
+
+        switch (prop_id) {
+                case PROP_PROFILE:
+                        g_value_set_object (value, dh_sidebar_get_profile (sidebar));
+                        break;
+
+                default:
+                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                        break;
+        }
+}
+
+static void
+dh_sidebar_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+        DhSidebar *sidebar = DH_SIDEBAR (object);
+
+        switch (prop_id) {
+                case PROP_PROFILE:
+                        set_profile (sidebar, g_value_get_object (value));
+                        break;
+
+                default:
+                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                        break;
+        }
+}
+
+static void
+dh_sidebar_constructed (GObject *object)
+{
+        DhSidebar *sidebar = DH_SIDEBAR (object);
+        DhSidebarPrivate *priv = dh_sidebar_get_instance_private (sidebar);
+
+        if (G_OBJECT_CLASS (dh_sidebar_parent_class)->constructed != NULL)
+                G_OBJECT_CLASS (dh_sidebar_parent_class)->constructed (object);
+
+        if (priv->profile == NULL)
+                priv->profile = g_object_ref (dh_profile_get_default ());
+}
+
+static void
 dh_sidebar_dispose (GObject *object)
 {
         DhSidebarPrivate *priv = dh_sidebar_get_instance_private (DH_SIDEBAR (object));
 
+        g_clear_object (&priv->profile);
         g_clear_object (&priv->hitlist_model);
 
         if (priv->idle_complete_id != 0) {
@@ -102,6 +175,9 @@ dh_sidebar_class_init (DhSidebarClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+        object_class->get_property = dh_sidebar_get_property;
+        object_class->set_property = dh_sidebar_set_property;
+        object_class->constructed = dh_sidebar_constructed;
         object_class->dispose = dh_sidebar_dispose;
 
         /**
@@ -117,6 +193,24 @@ dh_sidebar_class_init (DhSidebarClass *klass)
                               NULL, NULL, NULL,
                               G_TYPE_NONE,
                               1, DH_TYPE_LINK);
+
+        /**
+         * DhSidebar:profile:
+         *
+         * The #DhProfile.
+         *
+         * Since: 3.30
+         */
+        properties[PROP_PROFILE] =
+                g_param_spec_object ("profile",
+                                     "Profile",
+                                     "",
+                                     DH_TYPE_PROFILE,
+                                     G_PARAM_READWRITE |
+                                     G_PARAM_CONSTRUCT_ONLY |
+                                     G_PARAM_STATIC_STRINGS);
+
+        g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
 /******************************************************************************/
@@ -599,6 +693,7 @@ dh_sidebar_init (DhSidebar *sidebar)
  * you should just pass %NULL.
  *
  * Returns: (transfer floating): a new #DhSidebar widget.
+ * Deprecated: 3.30: Use dh_sidebar_new2() instead.
  */
 GtkWidget *
 dh_sidebar_new (DhBookManager *book_manager)
@@ -607,6 +702,41 @@ dh_sidebar_new (DhBookManager *book_manager)
 }
 
 /**
+ * dh_sidebar_new2:
+ * @profile: (nullable): a #DhProfile, or %NULL for the default profile.
+ *
+ * Returns: (transfer floating): a new #DhSidebar widget.
+ * Since: 3.30
+ */
+DhSidebar *
+dh_sidebar_new2 (DhProfile *profile)
+{
+        g_return_val_if_fail (profile == NULL || DH_IS_PROFILE (profile), NULL);
+
+        return g_object_new (DH_TYPE_SIDEBAR,
+                             "profile", profile,
+                             NULL);
+}
+
+/**
+ * dh_sidebar_get_profile:
+ * @sidebar: a #DhSidebar.
+ *
+ * Returns: (transfer none): the #DhProfile of @sidebar.
+ * Since: 3.30
+ */
+DhProfile *
+dh_sidebar_get_profile (DhSidebar *sidebar)
+{
+        DhSidebarPrivate *priv;
+
+        g_return_val_if_fail (DH_IS_SIDEBAR (sidebar), NULL);
+
+        priv = dh_sidebar_get_instance_private (sidebar);
+        return priv->profile;
+}
+
+/**
  * dh_sidebar_select_uri:
  * @sidebar: a #DhSidebar.
  * @uri: the URI to select.
diff --git a/devhelp/dh-sidebar.h b/devhelp/dh-sidebar.h
index 62c37d4..ce96f82 100644
--- a/devhelp/dh-sidebar.h
+++ b/devhelp/dh-sidebar.h
@@ -5,7 +5,7 @@
  * Copyright (C) 2001-2002 CodeFactory AB
  * Copyright (C) 2001-2002 Mikael Hallendal <micke imendio com>
  * Copyright (C) 2013 Aleksander Morgado <aleksander gnu org>
- * Copyright (C) 2017 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2017, 2018 Sébastien Wilmet <swilmet gnome org>
  *
  * Devhelp is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
@@ -27,6 +27,7 @@
 #include <gtk/gtk.h>
 #include <devhelp/dh-book-manager.h>
 #include <devhelp/dh-link.h>
+#include <devhelp/dh-profile.h>
 
 G_BEGIN_DECLS
 
@@ -56,8 +57,13 @@ struct _DhSidebarClass {
 
 GType           dh_sidebar_get_type             (void);
 
+G_DEPRECATED_FOR (dh_sidebar_new2)
 GtkWidget *     dh_sidebar_new                  (DhBookManager *book_manager);
 
+DhSidebar *     dh_sidebar_new2                 (DhProfile *profile);
+
+DhProfile *     dh_sidebar_get_profile          (DhSidebar *sidebar);
+
 void            dh_sidebar_select_uri           (DhSidebar   *sidebar,
                                                  const gchar *uri);
 
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index e24aad8..8cfd225 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -229,6 +229,8 @@ dh_settings_builder_get_type
 <FILE>dh-sidebar</FILE>
 DhSidebar
 dh_sidebar_new
+dh_sidebar_new2
+dh_sidebar_get_profile
 dh_sidebar_select_uri
 dh_sidebar_set_search_string
 dh_sidebar_set_search_focus
diff --git a/src/dh-window.c b/src/dh-window.c
index 2ebd82e..103f257 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -709,7 +709,7 @@ dh_window_init (DhWindow *window)
                          G_SETTINGS_BIND_NO_SENSITIVITY);
 
         /* Sidebar */
-        priv->sidebar = DH_SIDEBAR (dh_sidebar_new (NULL));
+        priv->sidebar = dh_sidebar_new2 (NULL);
         gtk_widget_show (GTK_WIDGET (priv->sidebar));
         gtk_container_add (GTK_CONTAINER (priv->grid_sidebar),
                            GTK_WIDGET (priv->sidebar));


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