Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /cbrpager-maemo/branches/MAEMO_0_9_20/src/garchivereaderunzip.c [r19] .. [r20] Maximize Restore

  Switch to side-by-side view

--- a/cbrpager-maemo/branches/MAEMO_0_9_20/src/garchivereaderunzip.c
+++ b/cbrpager-maemo/branches/MAEMO_0_9_20/src/garchivereaderunzip.c
@@ -28,12 +28,6 @@
 #include "garchivereaderunzip.h"
 
 extern int debug;
-
-static gint
-compare_pages(gconstpointer s1, gconstpointer s2)
-{
-    return strcmp(*(const char**)s1, *(const char**)s2);
-}
 
 static gboolean extension_handled(const char* filename)
 {
@@ -142,7 +136,8 @@
     }
     else
     {
-	g_array_sort(reader->page_list, compare_pages);
+	g_array_sort(reader->page_list, 
+		     g_archive_reader_translate_strategy(reader->strategy));
     }
     return reader->page_list;
 }
@@ -159,18 +154,19 @@
     unz_file_info file_info;
     GdkPixbufLoader* loader = NULL;
     int num_bytes = 0;
+    GArray* file_list = get_file_list(reader_iface);
 
     if(w)
 	*w = 0;
     if(h)
 	*h = 0;
-    if(page_number < 0 || page_number >= get_file_list(reader_iface)->len)
+    if(page_number < 0 || !file_list || page_number >= file_list->len)
     {
 	set_last_error(reader, g_strdup_printf(_("Page number %d out of range"), page_number));
 	return NULL;
     }
 	
-    filename = (const gchar*)g_array_index(get_file_list(reader_iface), gchar*, page_number);
+    filename = (const gchar*)g_array_index(file_list, gchar*, page_number);
     
     if(unzLocateFile(reader->current_file, (const char*)filename, 1) != UNZ_OK)
     {
@@ -222,6 +218,16 @@
     return last_error;
 }
 
+static void
+set_sort_strategy(GArchiveReader* reader_iface, SortStrategy strategy)
+{
+    GArchiveReaderUnzip* reader = G_ARCHIVE_READER_UNZIP(reader_iface);
+    SortStrategy old_strategy = reader->strategy;
+    reader->strategy = strategy;
+    if(strategy != old_strategy && reader->page_list && reader->page_list->len > 0)
+	g_array_sort(reader->page_list, g_archive_reader_translate_strategy(strategy));
+}
+
 /* class instance housekeeping stuff */
 
 static void
@@ -233,6 +239,7 @@
     klass->get_file_list = get_file_list;
     klass->get_page = get_page;
     klass->get_last_error = get_last_error;
+    klass->set_sort_strategy = set_sort_strategy;
 }
 
 static void
@@ -247,6 +254,7 @@
     reader->current_file = NULL;
     reader->last_error = NULL;
     reader->page_list = NULL;
+    reader->strategy = SORT_ASCII;
 }
 
 G_DEFINE_TYPE_EXTENDED(GArchiveReaderUnzip,
@@ -293,6 +301,7 @@
     reader->current_file = NULL;
     reader->last_error = NULL;
     reader->page_list = NULL;
+    reader->strategy = SORT_ASCII;
 
     reader->buf = buf;
     reader->buf_size = buf_size;