[devhelp] Book: remove the "enabled" property



commit efe9c5fe3eb003561651e435ff71da3d282f10fb
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Apr 30 17:06:39 2018 +0200

    Book: remove the "enabled" property
    
    It was not really a property, but it's simpler to describe it this way.
    
    Whether a DhBook is enabled is now decoupled from DhBook. For a book to
    be enabled, it needs to be part of a DhBookList now. It's more flexible,
    because there can be several different DhBookList's at the same time,
    for example to create different profiles.
    
    The DhCompletion objects are created lazily when calling
    dh_book_get_completion(), to avoid creating them unnecessarily. But they
    need to be created for the relevant DhBooks before the first completion
    in the GtkSearchEntry. So do that in DhSidebar now (where the
    GtkSearchEntry completion is implemented).

 devhelp/dh-book.c                   |  109 +++--------------------------------
 devhelp/dh-book.h                   |    5 --
 devhelp/dh-sidebar.c                |   49 ++++++++++++++--
 docs/reference/api-breaks.xml       |   13 ++++
 docs/reference/devhelp-sections.txt |    2 -
 5 files changed, 64 insertions(+), 114 deletions(-)
---
diff --git a/devhelp/dh-book.c b/devhelp/dh-book.c
index dad84dd..f3ee64f 100644
--- a/devhelp/dh-book.c
+++ b/devhelp/dh-book.c
@@ -41,9 +41,9 @@
  *
  * #DhBook creates a #GFileMonitor on the index file, and emits the
  * #DhBook::updated or #DhBook::deleted signal in case the index file has
- * changed on the filesystem. #DhBookManager listens to those #DhBook signals,
- * and emits in turn the #DhBookManager::book-deleted and
- * #DhBookManager::book-created signals.
+ * changed on the filesystem. #DhBookListDirectory listens to those #DhBook
+ * signals, and emits in turn the #DhBookList #DhBookList::remove-book and
+ * #DhBookList::add-book signals.
  */
 
 /* Timeout to wait for new events on the index file so that they are merged and
@@ -52,14 +52,6 @@
 #define EVENT_MERGE_TIMEOUT_SECS (2)
 
 enum {
-        /* FIXME: a boolean property would be a better API instead of the
-         * ::enabled and ::disabled signals. Or this whole concept can be
-         * removed from DhBook, by introducing DhBookSelection, see:
-         * https://bugzilla.gnome.org/show_bug.cgi?id=784491#c3
-         */
-        SIGNAL_ENABLED,
-        SIGNAL_DISABLED,
-
         SIGNAL_UPDATED,
         SIGNAL_DELETED,
         N_SIGNALS
@@ -89,8 +81,6 @@ typedef struct {
         GFileMonitor *index_file_monitor;
         BookMonitorEvent last_monitor_event;
         guint monitor_event_timeout_id;
-
-        guint enabled : 1;
 } DhBookPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (DhBook, dh_book, G_TYPE_OBJECT);
@@ -141,32 +131,6 @@ dh_book_class_init (DhBookClass *klass)
         object_class->finalize = dh_book_finalize;
 
         /**
-         * DhBook::enabled:
-         * @book: the #DhBook emitting the signal.
-         */
-        signals[SIGNAL_ENABLED] =
-                g_signal_new ("enabled",
-                              G_TYPE_FROM_CLASS (klass),
-                              G_SIGNAL_RUN_LAST,
-                              0,
-                              NULL, NULL, NULL,
-                              G_TYPE_NONE,
-                              0);
-
-        /**
-         * DhBook::disabled:
-         * @book: the #DhBook emitting the signal.
-         */
-        signals[SIGNAL_DISABLED] =
-                g_signal_new ("disabled",
-                              G_TYPE_FROM_CLASS (klass),
-                              G_SIGNAL_RUN_LAST,
-                              0,
-                              NULL, NULL, NULL,
-                              G_TYPE_NONE,
-                              0);
-
-        /**
          * DhBook::updated:
          * @book: the #DhBook emitting the signal.
          *
@@ -204,7 +168,6 @@ dh_book_init (DhBook *book)
 {
         DhBookPrivate *priv = dh_book_get_instance_private (book);
 
-        priv->enabled = TRUE;
         priv->last_monitor_event = BOOK_MONITOR_EVENT_NONE;
 }
 
@@ -462,9 +425,8 @@ dh_book_get_language (DhBook *book)
  * dh_book_get_links:
  * @book: a #DhBook.
  *
- * Returns: (element-type DhLink) (transfer none) (nullable): the list of
- * <emphasis>all</emphasis> #DhLink's part of @book, or %NULL if the book is
- * disabled.
+ * Returns: (element-type DhLink) (transfer none): the list of
+ * <emphasis>all</emphasis> #DhLink's part of @book.
  */
 GList *
 dh_book_get_links (DhBook *book)
@@ -475,7 +437,7 @@ dh_book_get_links (DhBook *book)
 
         priv = dh_book_get_instance_private (book);
 
-        return priv->enabled ? priv->links : NULL;
+        return priv->links;
 }
 
 /**
@@ -488,8 +450,7 @@ dh_book_get_links (DhBook *book)
  * <emphasis>all</emphasis> #DhLink's part of the book, you need to call
  * dh_book_get_links().
  *
- * Returns: (transfer none) (nullable): the tree of #DhLink's part of the @book,
- * or %NULL if the book is disabled.
+ * Returns: (transfer none): the tree of #DhLink's part of @book.
  */
 GNode *
 dh_book_get_tree (DhBook *book)
@@ -500,7 +461,7 @@ dh_book_get_tree (DhBook *book)
 
         priv = dh_book_get_instance_private (book);
 
-        return priv->enabled ? priv->tree : NULL;
+        return priv->tree;
 }
 
 /**
@@ -546,60 +507,6 @@ dh_book_get_completion (DhBook *book)
 }
 
 /**
- * dh_book_get_enabled:
- * @book: a #DhBook.
- *
- * Returns: whether the book is enabled.
- */
-gboolean
-dh_book_get_enabled (DhBook *book)
-{
-        DhBookPrivate *priv;
-
-        g_return_val_if_fail (DH_IS_BOOK (book), FALSE);
-
-        priv = dh_book_get_instance_private (book);
-
-        return priv->enabled;
-}
-
-/**
- * dh_book_set_enabled:
- * @book: a #DhBook.
- * @enabled: the new value.
- *
- * Enables or disables the book.
- */
-void
-dh_book_set_enabled (DhBook   *book,
-                     gboolean  enabled)
-{
-        DhBookPrivate *priv;
-
-        g_return_if_fail (DH_IS_BOOK (book));
-
-        priv = dh_book_get_instance_private (book);
-
-        enabled = enabled != FALSE;
-
-        /* Create DhCompletion, because if all the DhCompletion objects need to
-         * be created (synchronously) at the time of the first completion, it
-         * can make the GUI not responsive (measured time was for example 40ms
-         * to create the DhCompletion's for 17 books, which is not a lot of
-         * books). On application startup it is less a problem.
-         */
-        if (enabled)
-                dh_book_get_completion (book);
-
-        if (priv->enabled != enabled) {
-                priv->enabled = enabled;
-                g_signal_emit (book,
-                               enabled ? signals[SIGNAL_ENABLED] : signals[SIGNAL_DISABLED],
-                               0);
-        }
-}
-
-/**
  * dh_book_cmp_by_id:
  * @a: a #DhBook.
  * @b: a #DhBook.
diff --git a/devhelp/dh-book.h b/devhelp/dh-book.h
index 3f66dbc..94143b6 100644
--- a/devhelp/dh-book.h
+++ b/devhelp/dh-book.h
@@ -69,11 +69,6 @@ GNode *      dh_book_get_tree        (DhBook *book);
 
 DhCompletion *dh_book_get_completion (DhBook *book);
 
-gboolean     dh_book_get_enabled     (DhBook *book);
-
-void         dh_book_set_enabled     (DhBook   *book,
-                                      gboolean  enabled);
-
 gint         dh_book_cmp_by_id       (DhBook *a,
                                       DhBook *b);
 
diff --git a/devhelp/dh-sidebar.c b/devhelp/dh-sidebar.c
index d470cdd..735eab3 100644
--- a/devhelp/dh-sidebar.c
+++ b/devhelp/dh-sidebar.c
@@ -184,8 +184,44 @@ setup_search_idle (DhSidebar *sidebar)
                 priv->idle_search_id = g_idle_add (search_idle_cb, sidebar);
 }
 
+/******************************************************************************/
+
+/* Create DhCompletion objects, because if all the DhCompletion objects need to
+ * be created (synchronously) at the time of the first completion, it can make
+ * the GUI not responsive (measured time was for example 40ms to create the
+ * DhCompletion's for 17 books, which is not a lot of books). On application
+ * startup it is less a problem.
+ */
+static void
+create_completion_objects (DhBookList *book_list)
+{
+        GList *books;
+        GList *l;
+
+        books = dh_book_list_get_books (book_list);
+
+        for (l = books; l != NULL; l = l->next) {
+                DhBook *cur_book = DH_BOOK (l->data);
+                dh_book_get_completion (cur_book);
+        }
+}
+
+static void
+add_book_cb (DhBookList *book_list,
+             DhBook     *book,
+             DhSidebar  *sidebar)
+{
+        /* See comment of create_completion_objects(). */
+        dh_book_get_completion (book);
+
+        /* Update current search if any. */
+        setup_search_idle (sidebar);
+}
+
 static void
-book_list_changed_cb (DhSidebar *sidebar)
+remove_book_cb (DhBookList *book_list,
+                DhBook     *book,
+                DhSidebar  *sidebar)
 {
         /* Update current search if any. */
         setup_search_idle (sidebar);
@@ -557,20 +593,21 @@ dh_sidebar_constructed (GObject *object)
         gtk_widget_set_vexpand (GTK_WIDGET (priv->sw_hitlist), TRUE);
         gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (priv->sw_hitlist));
 
-        /* DhBookList changes */
+        /* DhBookList */
         book_list = dh_profile_get_book_list (priv->profile);
+        create_completion_objects (book_list);
 
         g_signal_connect_object (book_list,
                                  "add-book",
-                                 G_CALLBACK (book_list_changed_cb),
+                                 G_CALLBACK (add_book_cb),
                                  sidebar,
-                                 G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+                                 G_CONNECT_AFTER);
 
         g_signal_connect_object (book_list,
                                  "remove-book",
-                                 G_CALLBACK (book_list_changed_cb),
+                                 G_CALLBACK (remove_book_cb),
                                  sidebar,
-                                 G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+                                 G_CONNECT_AFTER);
 
         /* Setup the book tree */
         priv->sw_book_tree = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index ac51d4f..eac40f2 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -273,6 +273,19 @@
       </listitem>
       <listitem>
         <para>
+          Whether a <link linkend="DhBook">DhBook</link> is enabled is now
+          decoupled from <link linkend="DhBook">DhBook</link>:
+          <code>dh_book_get_enabled()</code> and
+          <code>dh_book_set_enabled()</code> have been removed, as well as the
+          <code>DhBook::enabled</code> and <code>DhBook::disabled</code>
+          signals. For a book to be enabled it now needs to be part
+          of a <link linkend="DhBookList">DhBookList</link>, which is more
+          flexible because there can be several different
+          <link linkend="DhBookList">DhBookList</link>'s in parallel.
+        </para>
+      </listitem>
+      <listitem>
+        <para>
           The last parameter of
           <link linkend="dh-keyword-model-filter">dh_keyword_model_filter()</link>
           has been changed, it is no longer the language (a string, that
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 98b46b7..6f175c2 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -35,8 +35,6 @@ dh_book_get_language
 dh_book_get_links
 dh_book_get_tree
 dh_book_get_completion
-dh_book_get_enabled
-dh_book_set_enabled
 dh_book_cmp_by_id
 dh_book_cmp_by_title
 <SUBSECTION Standard>


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