[devhelp/wip/book-list] BookListBuilder: add add_default_sub_book_lists()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-list] BookListBuilder: add add_default_sub_book_lists()
- Date: Sat, 28 Apr 2018 09:15:58 +0000 (UTC)
commit 03d5f2b7155c529688fb454ed1e6fcd1244edcd9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 28 10:50:47 2018 +0200
BookListBuilder: add add_default_sub_book_lists()
devhelp/dh-book-list-builder.c | 100 +++++++++++++++++++++++++++++++++++
devhelp/dh-book-list-builder.h | 18 ++++---
docs/reference/devhelp-sections.txt | 1 +
3 files changed, 111 insertions(+), 8 deletions(-)
---
diff --git a/devhelp/dh-book-list-builder.c b/devhelp/dh-book-list-builder.c
index 75a3e0c..14dbf4e 100644
--- a/devhelp/dh-book-list-builder.c
+++ b/devhelp/dh-book-list-builder.c
@@ -18,7 +18,9 @@
* along with Devhelp. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
#include "dh-book-list-builder.h"
+#include "dh-book-list-directory.h"
#include "dh-book-list-simple.h"
/**
@@ -111,6 +113,104 @@ dh_book_list_builder_add_sub_book_list (DhBookListBuilder *builder,
g_object_ref (sub_book_list));
}
+static void
+add_book_list_directory (DhBookListBuilder *builder,
+ const gchar *directory_path)
+{
+ GFile *directory;
+ DhBookListDirectory *sub_book_list;
+
+ directory = g_file_new_for_path (directory_path);
+ sub_book_list = dh_book_list_directory_new (directory);
+ g_object_unref (directory);
+
+ dh_book_list_builder_add_sub_book_list (builder, DH_BOOK_LIST (sub_book_list));
+ g_object_unref (sub_book_list);
+}
+
+static void
+add_default_sub_book_lists_in_data_dir (DhBookListBuilder *builder,
+ const gchar *data_dir)
+{
+ gchar *dir;
+
+ g_return_if_fail (data_dir != NULL);
+
+ dir = g_build_filename (data_dir, "gtk-doc", "html", NULL);
+ add_book_list_directory (builder, dir);
+ g_free (dir);
+
+ dir = g_build_filename (data_dir, "devhelp", "books", NULL);
+ add_book_list_directory (builder, dir);
+ g_free (dir);
+}
+
+/**
+ * dh_book_list_builder_add_default_sub_book_lists:
+ * @builder: a #DhBookListBuilder.
+ *
+ * Creates the default #DhBookListDirectory's and adds them to @builder with
+ * dh_book_list_builder_add_sub_book_list().
+ *
+ * It creates and adds a #DhBookListDirectory for the following directories (in
+ * that order):
+ * - `$XDG_DATA_HOME/gtk-doc/html/`
+ * - `$XDG_DATA_HOME/devhelp/books/`
+ * - For each directory in `$XDG_DATA_DIRS`:
+ * - `$xdg_data_dir/gtk-doc/html/`
+ * - `$xdg_data_dir/devhelp/books/`
+ *
+ * See g_get_user_data_dir() and g_get_system_data_dirs().
+ *
+ * Additionally, if the libdevhelp has been compiled with the `flatpak_build`
+ * option, it creates and adds a #DhBookListDirectory for the following
+ * directories (in that order, after the above ones):
+ * - `/run/host/usr/share/gtk-doc/html/`
+ * - `/run/host/usr/share/devhelp/books/`
+ *
+ * The exact list of directories is subject to change, it is not part of the
+ * API.
+ *
+ * Since: 3.30
+ */
+void
+dh_book_list_builder_add_default_sub_book_lists (DhBookListBuilder *builder)
+{
+ const gchar * const *system_dirs;
+ gint i;
+
+ g_return_if_fail (DH_IS_BOOK_LIST_BUILDER (builder));
+
+ add_default_sub_book_lists_in_data_dir (builder, g_get_user_data_dir ());
+
+ system_dirs = g_get_system_data_dirs ();
+ g_return_if_fail (system_dirs != NULL);
+
+ for (i = 0; system_dirs[i] != NULL; i++)
+ add_default_sub_book_lists_in_data_dir (builder, system_dirs[i]);
+
+ /* For Flatpak, to see the books installed on the host by traditional
+ * Linux distro packages.
+ *
+ * It is not a good idea to add the directory to XDG_DATA_DIRS, see:
+ * https://github.com/flatpak/flatpak/issues/1299
+ * "all sorts of things will break if we add all host config to each
+ * app, which is totally opposite to the entire point of flatpak."
+ * "i don't think XDG_DATA_DIRS is the right thing, because all sorts of
+ * libraries will start reading files from there, like dconf, dbus,
+ * service files, mimetypes, etc. It would be preferable to have
+ * something that targeted just gtk-doc files."
+ *
+ * So instead of adapting XDG_DATA_DIRS, add the directory here, with
+ * the path hard-coded.
+ *
+ * https://bugzilla.gnome.org/show_bug.cgi?id=792068
+ */
+#ifdef FLATPAK_BUILD
+ add_default_sub_book_lists_in_data_dir (builder, "/run/host/usr/share");
+#endif
+}
+
/**
* dh_book_list_builder_read_books_disabled_setting:
* @builder: a #DhBookListBuilder.
diff --git a/devhelp/dh-book-list-builder.h b/devhelp/dh-book-list-builder.h
index 7acd816..395149e 100644
--- a/devhelp/dh-book-list-builder.h
+++ b/devhelp/dh-book-list-builder.h
@@ -51,18 +51,20 @@ struct _DhBookListBuilderClass {
gpointer padding[12];
};
-GType dh_book_list_builder_get_type (void);
+GType dh_book_list_builder_get_type (void);
-DhBookListBuilder * dh_book_list_builder_new (void);
+DhBookListBuilder *
+ dh_book_list_builder_new (void);
-void dh_book_list_builder_add_sub_book_list (DhBookListBuilder *builder,
- DhBookList *sub_book_list);
+void dh_book_list_builder_add_sub_book_list (DhBookListBuilder *builder,
+ DhBookList *sub_book_list);
-void dh_book_list_builder_read_books_disabled_setting
- (DhBookListBuilder *builder,
- DhSettings *settings);
+void dh_book_list_builder_add_default_sub_book_lists (DhBookListBuilder *builder);
-DhBookList * dh_book_list_builder_create_object (DhBookListBuilder *builder);
+void dh_book_list_builder_read_books_disabled_setting (DhBookListBuilder *builder,
+ DhSettings *settings);
+
+DhBookList * dh_book_list_builder_create_object (DhBookListBuilder *builder);
G_END_DECLS
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 7f1d466..898c0d9 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -74,6 +74,7 @@ dh_book_list_get_type
DhBookListBuilder
dh_book_list_builder_new
dh_book_list_builder_add_sub_book_list
+dh_book_list_builder_add_default_sub_book_lists
dh_book_list_builder_read_books_disabled_setting
dh_book_list_builder_create_object
<SUBSECTION Standard>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]