Re: [Musicpd-dev-team] Patch to sort lsplaylists by name

2011-01-16 Thread Max Kellermann
On 2011/01/16 14:55, Justifiably  wrote:
> Dear MPD devs,
> 
> I found it surprising and confusing that several clients would display
> my list of playlists in a seemingly random order that would also change
> from time to time.  Doesn't it make most sense to sort the names on the
> server side?

No.  That adds overhead to the server, for something which may not be
useful for all clients in all situations.  Clients which wish to show
a sorted list shall sort it, and for the rest, the order is undefined.

--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
___
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team


[Musicpd-dev-team] Patch to sort lsplaylists by name

2011-01-16 Thread Justifiably
Dear MPD devs,

I found it surprising and confusing that several clients would display
my list of playlists in a seemingly random order that would also change
from time to time.  Doesn't it make most sense to sort the names on the
server side?

Here's a tiny patch to sort the output of listplaylists which fixes this
by sorting after using readdir().

g_utf8_collate seems to be the right ordering to choose, although the
Glib docs warn it isn't the best way if there are lot of items to be
sorted.

  - J.
commit e957be4cd0ab5d44fcd697e26c5e346329e6339e
Author: Justifiably 
Date:   Sun Jan 16 13:20:23 2011 +

spl_list(): return playlist names in sorted order

diff --git a/src/stored_playlist.c b/src/stored_playlist.c
index c75c007..aff8fd3 100644
--- a/src/stored_playlist.c
+++ b/src/stored_playlist.c
@@ -105,6 +105,13 @@ load_playlist_info(const char *parent_path_fs, const char *name_fs)
 	return playlist;
 }
 
+static gint
+compare_playlist_names(struct stored_playlist_info **playlist1, 
+  struct stored_playlist_info **playlist2) 
+{
+  return g_utf8_collate((*playlist1)->name,(*playlist2)->name);
+}
+
 GPtrArray *
 spl_list(void)
 {
@@ -130,6 +137,7 @@ spl_list(void)
 	}
 
 	closedir(dir);
+	g_ptr_array_sort(list, (GCompareFunc)&compare_playlist_names);
 	return list;
 }
 
--
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl___
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team