totem-pl-parser r66 - in trunk: . plparse



Author: hadess
Date: Mon Mar  3 17:11:15 2008
New Revision: 66
URL: http://svn.gnome.org/viewvc/totem-pl-parser?rev=66&view=rev

Log:
2008-03-03  Bastien Nocera  <hadess hadess net>

	* plparse/totem-pl-parser-media.c (totem_pl_parser_iso_get_title),
	(totem_pl_parser_dir_compare): Patch from Sebastian PÃlsterl
	<marduk k-d-w org> to sort filenames the same way nautilus does
	(Closes: #518116)



Modified:
   trunk/ChangeLog
   trunk/plparse/totem-pl-parser-media.c

Modified: trunk/plparse/totem-pl-parser-media.c
==============================================================================
--- trunk/plparse/totem-pl-parser-media.c	(original)
+++ trunk/plparse/totem-pl-parser-media.c	Mon Mar  3 17:11:15 2008
@@ -36,6 +36,10 @@
 #include "totem-pl-parser-media.h"
 #include "totem-pl-parser-private.h"
 
+/* Files that start with these characters sort after files that don't. */
+#define SORT_LAST_CHAR1 '.'
+#define SORT_LAST_CHAR2 '#'
+
 #ifndef TOTEM_PL_PARSER_MINI
 /* Returns NULL if we don't have an ISO image,
  * or an empty string if it's non-UTF-8 data */
@@ -168,17 +172,37 @@
 static int
 totem_pl_parser_dir_compare (GnomeVFSFileInfo *a, GnomeVFSFileInfo *b)
 {
+	const char *name_1, *name_2;
+	const char *key_1, *key_2;
+	gboolean sort_last_1, sort_last_2;
+	int compare;
+	
 	if (a->name == NULL) {
 		if (b->name == NULL)
-			return 0;
-		else
-			return -1;
-	} else {
-		if (b->name == NULL)
-			return 1;
+			compare = 0;
 		else
-			return strcmp (a->name, b->name);
+			compare = -1;
+	} else {	
+		name_1 = a->name;
+		name_2 = b->name;
+		
+		sort_last_1 = name_1[0] == SORT_LAST_CHAR1 || name_1[0] == SORT_LAST_CHAR2;
+		sort_last_2 = name_2[0] == SORT_LAST_CHAR1 || name_2[0] == SORT_LAST_CHAR2;
+		
+		if (sort_last_1 && !sort_last_2) {
+			compare = +1;
+		} else if (!sort_last_1 && sort_last_2) {
+			compare = -1;
+		} else {
+			key_1 = g_utf8_collate_key_for_filename (name_1, -1);
+			key_2 = g_utf8_collate_key_for_filename (name_2, -1);
+			compare = strcmp (key_1, key_2);
+			g_free (key_1);
+			g_free (key_2);
+		}
 	}
+
+	return compare;
 }
 
 TotemPlParserResult



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