[devhelp/gnome-2-32] Make sure all books are properly ordered by title



commit eae79955d17e6e4cc7cf09c8d952ecccd2afabad
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Jul 6 17:05:16 2010 +0200

    Make sure all books are properly ordered by title

 src/dh-book-manager.c |   15 ++++++++++++---
 src/dh-book.c         |   22 ++++++++++++++++++++--
 src/dh-book.h         |    6 +++++-
 3 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
index 23374c9..9549c5a 100644
--- a/src/dh-book-manager.c
+++ b/src/dh-book-manager.c
@@ -316,10 +316,19 @@ book_manager_add_from_filepath (DhBookManager *book_manager,
         /* Allocate new book struct */
         book = dh_book_new (book_path);
 
-        /* Check if book was already loaded in the manager */
+        /* Check if book with same path was already loaded in the manager */
         if (g_list_find_custom (priv->books,
                                 book,
-                                (GCompareFunc)dh_book_cmp)) {
+                                (GCompareFunc)dh_book_cmp_by_path)) {
+                g_object_unref (book);
+                return;
+        }
+
+        /* Check if book with same bookname was already loaded in the manager
+         * (we need to force unique book names) */
+        if (g_list_find_custom (priv->books,
+                                book,
+                                (GCompareFunc)dh_book_cmp_by_name)) {
                 g_object_unref (book);
                 return;
         }
@@ -327,7 +336,7 @@ book_manager_add_from_filepath (DhBookManager *book_manager,
         /* Add the book to the book list */
         priv->books = g_list_insert_sorted (priv->books,
                                             book,
-                                            (GCompareFunc)dh_book_cmp);
+                                            (GCompareFunc)dh_book_cmp_by_title);
 }
 
 GList *
diff --git a/src/dh-book.c b/src/dh-book.c
index baa45a2..179fdd2 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -219,10 +219,28 @@ dh_book_set_enabled (DhBook *book,
 }
 
 gint
-dh_book_cmp (const DhBook *a,
-             const DhBook *b)
+dh_book_cmp_by_path (const DhBook *a,
+                     const DhBook *b)
 {
         return ((a && b) ?
                 g_strcmp0 (GET_PRIVATE (a)->path, GET_PRIVATE (b)->path) :
                 -1);
 }
+
+gint
+dh_book_cmp_by_name (const DhBook *a,
+                     const DhBook *b)
+{
+        return ((a && b) ?
+                g_ascii_strcasecmp (GET_PRIVATE (a)->name, GET_PRIVATE (b)->name) :
+                -1);
+}
+
+gint
+dh_book_cmp_by_title (const DhBook *a,
+                      const DhBook *b)
+{
+        return ((a && b) ?
+                g_utf8_collate (GET_PRIVATE (a)->title, GET_PRIVATE (b)->title) :
+                -1);
+}
diff --git a/src/dh-book.h b/src/dh-book.h
index 8d3ed3f..198f2b3 100644
--- a/src/dh-book.h
+++ b/src/dh-book.h
@@ -55,7 +55,11 @@ const gchar *dh_book_get_title    (DhBook *book);
 gboolean     dh_book_get_enabled  (DhBook *book);
 void         dh_book_set_enabled  (DhBook *book,
                                    gboolean enabled);
-gint         dh_book_cmp          (const DhBook *a,
+gint         dh_book_cmp_by_path  (const DhBook *a,
+                                   const DhBook *b);
+gint         dh_book_cmp_by_name  (const DhBook *a,
+                                   const DhBook *b);
+gint         dh_book_cmp_by_title (const DhBook *a,
                                    const DhBook *b);
 
 G_END_DECLS



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