[devhelp/wip/book-list] Implement DhBookListDirectory
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp/wip/book-list] Implement DhBookListDirectory
- Date: Fri, 27 Apr 2018 13:19:27 +0000 (UTC)
commit 5abf518dedd593ad59ea5e7e6c3046b90b2cd2d9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Apr 27 13:35:40 2018 +0200
Implement DhBookListDirectory
devhelp/devhelp.h | 1 +
devhelp/dh-book-list-directory.c | 200 +++++++++++++++++++++++++++++++++++
devhelp/dh-book-list-directory.h | 61 +++++++++++
devhelp/meson.build | 2 +
docs/reference/devhelp-docs.xml | 1 +
docs/reference/devhelp-sections.txt | 17 +++
po/POTFILES.in | 1 +
7 files changed, 283 insertions(+), 0 deletions(-)
---
diff --git a/devhelp/devhelp.h b/devhelp/devhelp.h
index a90a9f1..302197d 100644
--- a/devhelp/devhelp.h
+++ b/devhelp/devhelp.h
@@ -29,6 +29,7 @@
#include <devhelp/dh-book.h>
#include <devhelp/dh-book-list.h>
#include <devhelp/dh-book-list-builder.h>
+#include <devhelp/dh-book-list-directory.h>
#include <devhelp/dh-book-manager.h>
#include <devhelp/dh-book-tree.h>
#include <devhelp/dh-completion.h>
diff --git a/devhelp/dh-book-list-directory.c b/devhelp/dh-book-list-directory.c
new file mode 100644
index 0000000..03c7b50
--- /dev/null
+++ b/devhelp/dh-book-list-directory.c
@@ -0,0 +1,200 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * This file is part of Devhelp.
+ *
+ * Copyright (C) 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
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Devhelp 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 Devhelp. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "dh-book-list-directory.h"
+
+/**
+ * SECTION:dh-book-list-directory
+ * @Title: DhBookListDirectory
+ * @Short_description: Subclass of #DhBookList containing the #DhBook's in one
+ * directory
+ */
+
+struct _DhBookListDirectoryPrivate {
+ GFile *directory;
+};
+
+enum {
+ PROP_0,
+ PROP_DIRECTORY,
+ N_PROPERTIES
+};
+
+/* List of unowned DhBookListDirectory*. */
+static GList *instances;
+
+static GParamSpec *properties[N_PROPERTIES];
+
+G_DEFINE_TYPE_WITH_PRIVATE (DhBookListDirectory, dh_book_list_directory, DH_TYPE_BOOK_LIST)
+
+static void
+set_directory (DhBookListDirectory *list_directory,
+ GFile *directory)
+{
+ g_assert (list_directory->priv->directory == NULL);
+ g_return_if_fail (G_IS_FILE (directory));
+
+ list_directory->priv->directory = g_object_ref (directory);
+}
+
+static void
+dh_book_list_directory_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DhBookListDirectory *list_directory = DH_BOOK_LIST_DIRECTORY (object);
+
+ switch (prop_id) {
+ case PROP_DIRECTORY:
+ g_value_set_object (value, dh_book_list_directory_get_directory (list_directory));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dh_book_list_directory_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DhBookListDirectory *list_directory = DH_BOOK_LIST_DIRECTORY (object);
+
+ switch (prop_id) {
+ case PROP_DIRECTORY:
+ set_directory (list_directory, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+dh_book_list_directory_dispose (GObject *object)
+{
+ DhBookListDirectory *list_directory = DH_BOOK_LIST_DIRECTORY (object);
+
+ g_clear_object (&list_directory->priv->directory);
+
+ G_OBJECT_CLASS (dh_book_list_directory_parent_class)->dispose (object);
+}
+
+static void
+dh_book_list_directory_finalize (GObject *object)
+{
+ DhBookListDirectory *list_directory = DH_BOOK_LIST_DIRECTORY (object);
+
+ instances = g_list_remove (instances, list_directory);
+
+ G_OBJECT_CLASS (dh_book_list_directory_parent_class)->finalize (object);
+}
+
+static void
+dh_book_list_directory_class_init (DhBookListDirectoryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = dh_book_list_directory_get_property;
+ object_class->set_property = dh_book_list_directory_set_property;
+ object_class->dispose = dh_book_list_directory_dispose;
+ object_class->finalize = dh_book_list_directory_finalize;
+
+ /**
+ * DhBookListDirectory:directory:
+ *
+ * Since: 3.30
+ */
+ properties[PROP_DIRECTORY] =
+ g_param_spec_object ("directory",
+ "Directory",
+ "",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+dh_book_list_directory_init (DhBookListDirectory *list_directory)
+{
+ list_directory->priv = dh_book_list_directory_get_instance_private (list_directory);
+
+ instances = g_list_prepend (instances, list_directory);
+}
+
+/**
+ * dh_book_list_directory_new:
+ * @directory: the #DhBookListDirectory:directory.
+ *
+ * Returns a #DhBookListDirectory for @directory.
+ *
+ * If a #DhBookListDirectory instance is still alive for @directory (according
+ * to g_file_equal()), the same instance is returned with the reference count
+ * increased by one, to avoid data duplication. If no #DhBookListDirectory
+ * instance already exists for @directory, this function returns a new instance
+ * with a reference count of one (so it's the responsibility of the caller to
+ * keep the object alive if wanted, to avoid destroying and re-creating the same
+ * #DhBookListDirectory repeatedly).
+ *
+ * Returns: (transfer full): a #DhBookListDirectory for @directory.
+ * Since: 3.30
+ */
+DhBookListDirectory *
+dh_book_list_directory_new (GFile *directory)
+{
+ GList *l;
+
+ g_return_val_if_fail (G_IS_FILE (directory), NULL);
+
+ for (l = instances; l != NULL; l = l->next) {
+ DhBookListDirectory *cur_list_directory = DH_BOOK_LIST_DIRECTORY (l->data);
+
+ if (cur_list_directory->priv->directory != NULL &&
+ g_file_equal (cur_list_directory->priv->directory, directory))
+ return g_object_ref (cur_list_directory);
+ }
+
+ return g_object_new (DH_TYPE_BOOK_LIST_DIRECTORY,
+ "directory", directory,
+ NULL);
+}
+
+/**
+ * dh_book_list_directory_get_directory:
+ * @list_directory: a #DhBookListDirectory.
+ *
+ * Returns: (transfer none): the #DhBookListDirectory:directory.
+ * Since: 3.30
+ */
+GFile *
+dh_book_list_directory_get_directory (DhBookListDirectory *list_directory)
+{
+ g_return_val_if_fail (DH_IS_BOOK_LIST_DIRECTORY (list_directory), NULL);
+
+ return list_directory->priv->directory;
+}
diff --git a/devhelp/dh-book-list-directory.h b/devhelp/dh-book-list-directory.h
new file mode 100644
index 0000000..1aade54
--- /dev/null
+++ b/devhelp/dh-book-list-directory.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * This file is part of Devhelp.
+ *
+ * Copyright (C) 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
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Devhelp 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 Devhelp. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DH_BOOK_LIST_DIRECTORY_H
+#define DH_BOOK_LIST_DIRECTORY_H
+
+#include <gio/gio.h>
+#include <devhelp/dh-book-list.h>
+
+G_BEGIN_DECLS
+
+#define DH_TYPE_BOOK_LIST_DIRECTORY (dh_book_list_directory_get_type ())
+#define DH_BOOK_LIST_DIRECTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
DH_TYPE_BOOK_LIST_DIRECTORY, DhBookListDirectory))
+#define DH_BOOK_LIST_DIRECTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
DH_TYPE_BOOK_LIST_DIRECTORY, DhBookListDirectoryClass))
+#define DH_IS_BOOK_LIST_DIRECTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
DH_TYPE_BOOK_LIST_DIRECTORY))
+#define DH_IS_BOOK_LIST_DIRECTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
DH_TYPE_BOOK_LIST_DIRECTORY))
+#define DH_BOOK_LIST_DIRECTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
DH_TYPE_BOOK_LIST_DIRECTORY, DhBookListDirectoryClass))
+
+typedef struct _DhBookListDirectory DhBookListDirectory;
+typedef struct _DhBookListDirectoryClass DhBookListDirectoryClass;
+typedef struct _DhBookListDirectoryPrivate DhBookListDirectoryPrivate;
+
+struct _DhBookListDirectory {
+ DhBookList parent;
+
+ DhBookListDirectoryPrivate *priv;
+};
+
+struct _DhBookListDirectoryClass {
+ DhBookListClass parent_class;
+
+ /* Padding for future expansion */
+ gpointer padding[12];
+};
+
+GType dh_book_list_directory_get_type (void);
+
+DhBookListDirectory * dh_book_list_directory_new (GFile *directory);
+
+GFile * dh_book_list_directory_get_directory (DhBookListDirectory *list_directory);
+
+G_END_DECLS
+
+#endif /* DH_BOOK_LIST_DIRECTORY_H */
diff --git a/devhelp/meson.build b/devhelp/meson.build
index d3093e2..57300f5 100644
--- a/devhelp/meson.build
+++ b/devhelp/meson.build
@@ -4,6 +4,7 @@ libdevhelp_public_headers = [
'dh-book.h',
'dh-book-list.h',
'dh-book-list-builder.h',
+ 'dh-book-list-directory.h',
'dh-book-manager.h',
'dh-book-tree.h',
'dh-completion.h',
@@ -22,6 +23,7 @@ libdevhelp_public_c_files = [
'dh-book.c',
'dh-book-list.c',
'dh-book-list-builder.c',
+ 'dh-book-list-directory.c',
'dh-book-manager.c',
'dh-book-tree.c',
'dh-completion.c',
diff --git a/docs/reference/devhelp-docs.xml b/docs/reference/devhelp-docs.xml
index 3e3f4ec..9486f15 100644
--- a/docs/reference/devhelp-docs.xml
+++ b/docs/reference/devhelp-docs.xml
@@ -30,6 +30,7 @@
<title>The Data</title>
<xi:include href="xml/dh-book-manager.xml"/>
<xi:include href="xml/dh-book-list.xml"/>
+ <xi:include href="xml/dh-book-list-directory.xml"/>
<xi:include href="xml/dh-book-list-builder.xml"/>
<xi:include href="xml/dh-book.xml"/>
<xi:include href="xml/dh-link.xml"/>
diff --git a/docs/reference/devhelp-sections.txt b/docs/reference/devhelp-sections.txt
index 0d9905c..7f1d466 100644
--- a/docs/reference/devhelp-sections.txt
+++ b/docs/reference/devhelp-sections.txt
@@ -89,6 +89,23 @@ dh_book_list_builder_get_type
</SECTION>
<SECTION>
+<FILE>dh-book-list-directory</FILE>
+DhBookListDirectory
+dh_book_list_directory_new
+dh_book_list_directory_get_directory
+<SUBSECTION Standard>
+DH_BOOK_LIST_DIRECTORY
+DH_BOOK_LIST_DIRECTORY_CLASS
+DH_BOOK_LIST_DIRECTORY_GET_CLASS
+DH_IS_BOOK_LIST_DIRECTORY
+DH_IS_BOOK_LIST_DIRECTORY_CLASS
+DH_TYPE_BOOK_LIST_DIRECTORY
+DhBookListDirectoryClass
+DhBookListDirectoryPrivate
+dh_book_list_directory_get_type
+</SECTION>
+
+<SECTION>
<FILE>dh-book-manager</FILE>
DhBookManager
dh_book_manager_new
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5649132..ad19b86 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,6 +8,7 @@ devhelp/dh-assistant-view.c
devhelp/dh-book.c
devhelp/dh-book-list-builder.c
devhelp/dh-book-list.c
+devhelp/dh-book-list-directory.c
devhelp/dh-book-list-simple.c
devhelp/dh-book-manager.c
devhelp/dh-book-tree.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]