Index: libmadplugin.cpp
===================================================================
RCS file: /var/cvsroot/yamaken/devel/zaurus/libmad-ja/libmadplugin.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- libmadplugin.cpp	7 Aug 2002 15:26:17 -0000	1.1.1.1
+++ libmadplugin.cpp	10 Aug 2002 04:48:16 -0000	1.3
@@ -32,6 +32,7 @@
 #include <math.h>
 #include <assert.h>
 #include <qapplication.h>
+#include <qtextcodec.h>
 
 
 //#define HAVE_MMAP
@@ -51,6 +52,7 @@
 //#define debugMsg(a)	    qDebug(a)
 #define debugMsg(a)
 
+static QTextCodec *codec_for_str(const char *str);
 
 class Input {
 public:
@@ -111,6 +113,29 @@
     return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" );
 }
 
+static QTextCodec *
+codec_for_str(const char *str) {
+  static const char *encodings[] = {"SJIS", "eucJP", "ISO 8859-1", ""};
+  QTextCodec *codec = NULL, *candidate = NULL;
+  int i, score = 0, hiscore = 0;
+
+  for (i = 0; *encodings[i]; i++) {
+    candidate = QTextCodec::codecForName(encodings[i]);
+    if (candidate) {
+      score = candidate->heuristicContentMatch(str, strlen(str));
+    }
+    if (hiscore < score) {
+      hiscore = score;
+      codec = candidate;
+    }
+  }
+  if (!codec) {
+    codec = QTextCodec::codecForName("ISO 8859-1");
+  }
+
+  return codec;
+}
+
 
 class LibMadPluginData {
 public:
@@ -288,14 +313,18 @@
 
 
 int LibMadPlugin::audioSamples( int ) {
+    long seconds;
+    unsigned int sample_rate;
+
     debugMsg( "LibMadPlugin::audioSamples" );
-/*
     long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
     mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
-    qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate );
-    return d->frame.header.duration.seconds * d->frame.header.samplerate;
-*/
-    return 10000000;
+
+    sample_rate = d->frame.header.samplerate;
+    seconds = (99 * 60/*min*/ + 59/*sec*/) * sample_rate;
+    qDebug( "LibMadPlugin::audioSamples: %i*%i", seconds, sample_rate );
+
+    return seconds;
 }
 
 
@@ -579,8 +608,14 @@
 	    char *ptr3 = ptr2;
 	    while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--;
 	    char push2 = *ptr3; *ptr3 = '\0';
-	    if ( strcmp( ptr, "" ) )
-		info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr;
+	    if ( strcmp( ptr, "" ) ) {
+              QTextCodec *codec;
+              QString unicode_str;
+
+              codec = codec_for_str(ptr);
+              unicode_str = codec->toUnicode(ptr);
+              info += ( i != 0 ? ", " : "" ) + label[i] + ": " + unicode_str;
+            }
 	    //qDebug( info.latin1() );
 	    *ptr3 = push2;
 	    *ptr2 = push;