[devhelp] BookManager: small code refactoring to add books in data dirs
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] BookManager: small code refactoring to add books in data dirs
- Date: Sat, 23 Dec 2017 10:50:27 +0000 (UTC)
commit 4778c4f7e089ee691d861ed1080e1cc62a324508
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Dec 23 11:24:27 2017 +0100
BookManager: small code refactoring to add books in data dirs
- Have shorter and more consistent function names.
- Have safer code by catching problems earlier.
- No need to check DH_IS_BOOK_MANAGER in an internal function.
src/dh-book-manager.c | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index 009e9bd..e937704 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -730,13 +730,12 @@ book_manager_monitor_path (DhBookManager *book_manager,
}
static void
-book_manager_add_from_dir (DhBookManager *book_manager,
- const gchar *dir_path)
+add_books_in_dir (DhBookManager *book_manager,
+ const gchar *dir_path)
{
GDir *dir;
const gchar *name;
- g_return_if_fail (DH_IS_BOOK_MANAGER (book_manager));
g_return_if_fail (dir_path != NULL);
/* Open directory */
@@ -773,17 +772,19 @@ book_manager_add_from_dir (DhBookManager *book_manager,
}
static void
-book_manager_add_books_in_data_dir (DhBookManager *book_manager,
- const gchar *data_dir)
+add_books_in_data_dir (DhBookManager *book_manager,
+ const gchar *data_dir)
{
gchar *dir;
+ g_return_if_fail (data_dir != NULL);
+
dir = g_build_filename (data_dir, "gtk-doc", "html", NULL);
- book_manager_add_from_dir (book_manager, dir);
+ add_books_in_dir (book_manager, dir);
g_free (dir);
dir = g_build_filename (data_dir, "devhelp", "books", NULL);
- book_manager_add_from_dir (book_manager, dir);
+ add_books_in_dir (book_manager, dir);
g_free (dir);
}
@@ -791,15 +792,15 @@ static void
populate (DhBookManager *book_manager)
{
const gchar * const *system_dirs;
+ gint i;
- book_manager_add_books_in_data_dir (book_manager,
- g_get_user_data_dir ());
+ add_books_in_data_dir (book_manager, g_get_user_data_dir ());
system_dirs = g_get_system_data_dirs ();
- while (*system_dirs) {
- book_manager_add_books_in_data_dir (book_manager,
- *system_dirs);
- system_dirs++;
+ g_return_if_fail (system_dirs != NULL);
+
+ for (i = 0; system_dirs[i] != NULL; i++) {
+ add_books_in_data_dir (book_manager, system_dirs[i]);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]