[devhelp] Book: new(): take a GFile argument for the index_file, not a path
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Book: new(): take a GFile argument for the index_file, not a path
- Date: Fri, 8 Dec 2017 14:50:48 +0000 (UTC)
commit e78d1139f6209f7d83ddcd32e9ace4912f00eba8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Dec 8 15:43:06 2017 +0100
Book: new(): take a GFile argument for the index_file, not a path
It's OK to break the API, neither gnome-builder nor Anjuta use this
function.
docs/reference/api-breaks.xml | 6 ++++++
src/dh-book-manager.c | 11 +++++++----
src/dh-book.c | 23 ++++++++++++++---------
src/dh-book.h | 2 +-
4 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/api-breaks.xml b/docs/reference/api-breaks.xml
index b268368..35db9ff 100644
--- a/docs/reference/api-breaks.xml
+++ b/docs/reference/api-breaks.xml
@@ -156,6 +156,12 @@
<link linkend="dh-book-get-index-file">dh_book_get_index_file()</link>.
</para>
</listitem>
+ <listitem>
+ <para>
+ The <link linkend="dh-book-new">dh_book_new()</link> constructor now
+ takes a <code>GFile</code> argument instead of a path.
+ </para>
+ </listitem>
</itemizedlist>
</refsect1>
</part>
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index 1d4c939..684e4ec 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -541,16 +541,19 @@ book_manager_add_from_filepath (DhBookManager *book_manager,
const gchar *book_path)
{
DhBookManagerPrivate *priv;
- DhBook *book;
- gboolean book_enabled;
+ GFile *index_file;
+ DhBook *book;
+ gboolean book_enabled;
g_return_if_fail (book_manager);
g_return_if_fail (book_path);
priv = dh_book_manager_get_instance_private (book_manager);
- /* Allocate new book struct */
- book = dh_book_new (book_path);
+ index_file = g_file_new_for_path (book_path);
+ book = dh_book_new (index_file);
+ g_object_unref (index_file);
+
if (book == NULL)
return;
diff --git a/src/dh-book.c b/src/dh-book.c
index 6d80cc5..14a070b 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -270,24 +270,25 @@ book_monitor_event_cb (GFileMonitor *file_monitor,
/**
* dh_book_new:
- * @index_file_path: the path to the index file.
+ * @index_file: the index file.
*
- * Returns: a new #DhBook object.
+ * Returns: (nullable): a new #DhBook object, or %NULL if parsing the index file
+ * failed.
*/
DhBook *
-dh_book_new (const gchar *index_file_path)
+dh_book_new (GFile *index_file)
{
DhBookPrivate *priv;
DhBook *book;
gchar *language = NULL;
GError *error = NULL;
- g_return_val_if_fail (index_file_path, NULL);
+ g_return_val_if_fail (G_IS_FILE (index_file), NULL);
book = g_object_new (DH_TYPE_BOOK, NULL);
priv = dh_book_get_instance_private (book);
- priv->index_file = g_file_new_for_path (index_file_path);
+ priv->index_file = g_object_ref (index_file);
/* Parse file storing contents in the book struct. */
if (!dh_parser_read_file (priv->index_file,
@@ -298,10 +299,14 @@ dh_book_new (const gchar *index_file_path)
&priv->keywords,
&error)) {
if (error != NULL) {
- g_warning ("Failed to read '%s': %s",
- index_file_path,
- error->message);
- g_error_free (error);
+ gchar *path;
+
+ path = g_file_get_path (priv->index_file);
+
+ g_warning ("Failed to read '%s': %s", path, error->message);
+
+ g_free (path);
+ g_clear_error (&error);
}
/* Deallocate the book, as we are not going to add it in the
diff --git a/src/dh-book.h b/src/dh-book.h
index b97f51e..617eafc 100644
--- a/src/dh-book.h
+++ b/src/dh-book.h
@@ -46,7 +46,7 @@ struct _DhBookClass {
GType dh_book_get_type (void) G_GNUC_CONST;
-DhBook * dh_book_new (const gchar *index_file_path);
+DhBook * dh_book_new (GFile *index_file);
GList * dh_book_get_keywords (DhBook *book);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]