[devhelp] Unify the treeview and combobox way of sorting the books
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [devhelp] Unify the treeview and combobox way of sorting the books
- Date: Mon, 31 Aug 2009 12:11:11 +0000 (UTC)
commit b9a13309b77a8dac7626ce5b3454fe34fc6c46f7
Author: Frédéric Péters <fpeters 0d be>
Date: Mon Aug 31 14:09:15 2009 +0200
Unify the treeview and combobox way of sorting the books
src/dh-base.c | 21 +--------------------
src/dh-search.c | 14 ++------------
src/dh-util.c | 38 ++++++++++++++++++++++++++++++++++++++
src/dh-util.h | 3 +++
4 files changed, 44 insertions(+), 32 deletions(-)
---
diff --git a/src/dh-base.c b/src/dh-base.c
index 3b340a4..f539a30 100644
--- a/src/dh-base.c
+++ b/src/dh-base.c
@@ -141,30 +141,11 @@ book_sort_func (gconstpointer a,
{
DhLink *link_a;
DhLink *link_b;
- const gchar *name_a;
- const gchar *name_b;
link_a = ((GNode *) a)->data;
link_b = ((GNode *) b)->data;
- name_a = dh_link_get_name (link_a);
- if (!name_a) {
- name_a = "";
- }
-
- name_b = dh_link_get_name (link_b);
- if (!name_b) {
- name_b = "";
- }
-
- if (g_ascii_strncasecmp (name_a, "the ", 4) == 0) {
- name_a += 4;
- }
- if (g_ascii_strncasecmp (name_b, "the ", 4) == 0) {
- name_b += 4;
- }
-
- return g_utf8_collate (name_a, name_b);
+ return dh_util_cmp_book (link_a, link_b);
}
static void
diff --git a/src/dh-search.c b/src/dh-search.c
index 2ddf8be..58be0ee 100644
--- a/src/dh-search.c
+++ b/src/dh-search.c
@@ -30,6 +30,7 @@
#include "dh-search.h"
#include "dh-preferences.h"
#include "dh-base.h"
+#include "dh-util.h"
typedef struct {
DhKeywordModel *model;
@@ -467,18 +468,7 @@ search_cell_data_func (GtkTreeViewColumn *tree_column,
static gint
book_cmp (DhLink **a, DhLink **b)
{
- gchar *name_a, *name_b;
- int r;
-
- name_a = g_utf8_casefold (dh_link_get_name (*a), -1);
- name_b = g_utf8_casefold (dh_link_get_name (*b), -1);
-
- r = strcmp(name_a, name_b);
-
- g_free (name_a);
- g_free (name_b);
-
- return r;
+ return dh_util_cmp_book (*a, *b);
}
static GtkWidget *
diff --git a/src/dh-util.c b/src/dh-util.c
index 3b31d2d..d1f2653 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -746,3 +746,41 @@ dh_util_font_add_web_view (WebKitWebView *view)
view_setup_fonts (view);
}
+
+gint
+dh_util_cmp_book (DhLink *a, DhLink *b)
+{
+ const gchar *name_a;
+ const gchar *name_b;
+ gchar *name_a_casefold;
+ gchar *name_b_casefold;
+ int rc;
+
+ name_a = dh_link_get_name (a);
+ if (!name_a) {
+ name_a = "";
+ }
+
+ name_b = dh_link_get_name (b);
+ if (!name_b) {
+ name_b = "";
+ }
+
+ if (g_ascii_strncasecmp (name_a, "the ", 4) == 0) {
+ name_a += 4;
+ }
+ if (g_ascii_strncasecmp (name_b, "the ", 4) == 0) {
+ name_b += 4;
+ }
+
+ name_a_casefold = g_utf8_casefold (name_a, -1);
+ name_b_casefold = g_utf8_casefold (name_b, -1);
+
+ rc = strcmp (name_a_casefold, name_b_casefold);
+
+ g_free (name_a_casefold);
+ g_free (name_b_casefold);
+
+ return rc;
+}
+
diff --git a/src/dh-util.h b/src/dh-util.h
index 2a81294..a033d99 100644
--- a/src/dh-util.h
+++ b/src/dh-util.h
@@ -24,6 +24,7 @@
#include <gtk/gtk.h>
#include <webkit/webkit.h>
+#include "dh-link.h"
G_BEGIN_DECLS
@@ -56,6 +57,8 @@ void dh_util_font_get_fixed (gchar **name,
gdouble *size,
gboolean use_system_font);
void dh_util_font_add_web_view (WebKitWebView *view);
+gint dh_util_cmp_book (DhLink *a,
+ DhLink *b);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]