changeset 1931:111f30d09ef2 trunk

[svn] audtool improvement: - print playlist titles in current codeset. - justify multi byte characters correctly in playlist-display and playqueue-display.
author yaz
date Sat, 04 Nov 2006 04:56:41 -0800
parents 727807ecf74a
children 532bb9b2bef6
files ChangeLog audtool/audtool.c
diffstat 2 files changed, 59 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 03 18:47:00 2006 -0800
+++ b/ChangeLog	Sat Nov 04 04:56:41 2006 -0800
@@ -1,3 +1,11 @@
+2006-11-04 02:47:00 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [2817]
+  - merge debian's manpage with ours, and improve overall spelling and grammar
+  
+  trunk/audtool.1.in |  279 +++++++++++++++++++++++++++++------------------------
+  1 file changed, 156 insertions(+), 123 deletions(-)
+
+
 2006-11-01 09:31:16 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [2815]
   - libguess update. a bug in JOHAB detecting was fixed.
--- a/audtool/audtool.c	Fri Nov 03 18:47:00 2006 -0800
+++ b/audtool/audtool.c	Sat Nov 04 04:56:41 2006 -0800
@@ -18,6 +18,7 @@
 
 #include <stdlib.h>
 #include <glib.h>
+#include <locale.h>
 #include "libaudacious/beepctrl.h"
 #include "audtool.h"
 
@@ -91,6 +92,8 @@
 	gint i;
 	gchar *remote_uri;
 
+	setlocale(LC_CTYPE, "");
+
 	if (argc < 2)
 	{
 		g_print("%s: usage: %s <command>\n", argv[0], argv[0]);
@@ -464,7 +467,9 @@
 {
 	gint i, ii, frames, length, total;
 	gchar *songname;
-	
+	gchar *fmt = NULL, *p;
+	gint column;
+
 	i = xmms_remote_get_playlist_length(session);
 
 	g_print("%d tracks.\n", i);
@@ -478,8 +483,28 @@
 		length = frames / 1000;
 		total += length;
 
-		g_print("%4d | %-60s | %d:%.2d\n",
-			ii + 1, songname, length / 60, length % 60);
+		/* adjust width for multi byte characters */
+		column = 60;
+		if(songname){
+			p = songname;
+			while(*p){
+				gint stride;
+				stride = g_utf8_next_char(p) - p;
+				if(g_unichar_iswide(g_utf8_get_char(p)) ||
+				   g_unichar_iswide_cjk(g_utf8_get_char(p))){
+					column += (stride - 2);
+				}
+				else {
+					column += (stride - 1);
+				}
+				p = g_utf8_next_char(p);
+			}
+
+		}
+
+		fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d\n", column);
+		g_print(fmt, ii + 1, songname, length / 60, length % 60);
+		g_free(fmt);
 	}
 
 	g_print("Total length: %d:%.2d\n", total / 60, total % 60);
@@ -707,6 +732,8 @@
 {
 	gint i, ii, position, frames, length, total;
 	gchar *songname;
+	gchar *fmt = NULL, *p;
+	gint column;
 	
 	i = xmms_remote_get_playqueue_length(session);
 
@@ -722,8 +749,27 @@
 		length = frames / 1000;
 		total += length;
 
-		g_print("%4d | %4d | %-60s | %d:%.2d\n",
-			ii + 1, position + 1, songname, length / 60, length % 60);
+		/* adjust width for multi byte characters */
+		column = 60;
+		if(songname) {
+			p = songname;
+			while(*p){
+				gint stride;
+				stride = g_utf8_next_char(p) - p;
+				if(g_unichar_iswide(g_utf8_get_char(p)) ||
+				   g_unichar_iswide_cjk(g_utf8_get_char(p))){
+					column += (stride - 2);
+				}
+				else {
+					column += (stride - 1);
+				}
+				p = g_utf8_next_char(p);
+			}
+		}
+
+		fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column);
+		g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60);
+		g_free(fmt);
 	}
 
 	g_print("Total length: %d:%.2d\n", total / 60, total % 60);