--- a/cbrpager-maemo/branches/MAEMO_0_9_20/src/garchivereader.c
+++ b/cbrpager-maemo/branches/MAEMO_0_9_20/src/garchivereader.c
@@ -20,6 +20,8 @@
  */
 
 #include <string.h>
+#include <ctype.h>
+#include <strings.h> /* for strcasecmp */
 
 #include "garchivereader.h"
 
@@ -81,6 +83,14 @@
 							h);
 }
 
+void
+g_archive_reader_set_sort_strategy(GArchiveReader* reader,
+				   SortStrategy strategy)
+{
+  return G_ARCHIVE_READER_GET_CLASS(reader)->set_sort_strategy(reader, 
+							       strategy);
+}
+
 gchar*
 g_archive_reader_get_last_error(GArchiveReader* reader)
 {
@@ -116,3 +126,69 @@
     fclose(f);
     return 0;
 }
+
+static gint 
+compare_ascii(gconstpointer first, gconstpointer second)
+{
+    return strcmp(*((const char**)first), *((const char**)second));
+}
+
+static gint 
+compare_insensitive(gconstpointer first, gconstpointer second)
+{
+    return strcasecmp(*((const char**)first), *((const char**)second));
+}
+
+static gint 
+compare_natural(gconstpointer first, gconstpointer second)
+{
+    const gchar* lhs = *(const gchar**)first;
+    const gchar* rhs = *(const gchar**)second;
+    int current_lhs_number = 0;
+    int current_rhs_number = 0;
+    while(*lhs || *rhs) {
+	char lhs_char = isalpha(*lhs) ? tolower(*lhs) : *lhs;
+	char rhs_char = isalpha(*rhs) ? tolower(*rhs) : *rhs;
+	int lhs_digit = isdigit(lhs_char);
+	int rhs_digit = isdigit(rhs_char);
+    
+	if(!lhs_digit && !rhs_digit) {
+	    if(lhs_char < rhs_char)
+		return -1;
+	    else if(lhs_char > rhs_char)
+		return 1;
+	    else {
+		if(lhs_char)
+		    ++lhs;
+		if(rhs_char)
+		    ++rhs;
+	    }
+	} else {
+	    if(lhs_digit) {
+		current_lhs_number = current_lhs_number * 10 + (lhs_char - '0');
+		++lhs;
+	    }
+	    if(rhs_digit) {
+		current_rhs_number = current_rhs_number * 10 + (rhs_char - '0');
+		++rhs;
+	    }
+	}
+    }
+    /* if we are here, need to compare numbers */
+    return current_lhs_number - current_rhs_number;
+}
+
+GCompareFunc
+g_archive_reader_translate_strategy(SortStrategy strategy)
+{
+    static GCompareFunc functions[] = {
+	compare_ascii,
+	compare_insensitive,
+	compare_natural
+    };
+
+    g_return_val_if_fail(strategy >= 0, NULL);
+    g_return_val_if_fail(strategy < 3, NULL);
+  
+    return functions[strategy];
+}