changeset 1601:be8babbd772c

Convert strings to UTF-8 using str_to_utf8(). This solution is not "Correct(tm)", but since the encoding used in module files cannot be known, it's the best bet.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2007 11:54:05 +0300
parents 49fe2225d236
children b0550943c696
files src/modplug/gui/main.cxx src/modplug/modplugbmp.cxx
diffstat 2 files changed, 28 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/modplug/gui/main.cxx	Wed Sep 05 07:38:21 2007 +0300
+++ b/src/modplug/gui/main.cxx	Wed Sep 05 11:54:05 2007 +0300
@@ -9,7 +9,10 @@
 
 #include <gtk/gtk.h>
 #include <libintl.h>
+extern "C" {
 #include "audacious/util.h"
+#include "audacious/strings.h"
+}
 
 #include "interface.h"
 #include "support.h"
@@ -152,7 +155,7 @@
 
 	uint32 lSongTime, lNumSamples, lNumInstruments, i;
 	string lInfo;
-	char lBuffer[33];
+	gchar lBuffer[33];
 	stringstream lStrStream(ios::out);   //C++ replacement for sprintf()
 
 	CSoundFile* lSoundFile;
@@ -160,6 +163,7 @@
 	Archive* lArchive;
 	string lShortFN;
 	uint32 lPos;
+	gchar *tmps;
 
 	lPos = aFilename.find_last_of('/') + 1;
 	lShortFN = aFilename.substr(lPos);
@@ -177,7 +181,9 @@
 
 	lInfo = lShortFN;
 	lInfo += '\n';
-	lInfo += lSoundFile->GetTitle();
+	tmps = str_to_utf8(lSoundFile->GetTitle());
+	lInfo += tmps;
+	g_free(tmps);
 	lInfo += '\n';
 
 	switch(lSoundFile->GetType())
@@ -275,7 +281,9 @@
 	for(i = 0; i < lNumSamples; i++)
 	{
 		lSoundFile->GetSampleName(i, lBuffer);
-		lInfo += lBuffer;
+		tmps = str_to_utf8(lBuffer);
+		lInfo += tmps;
+		g_free(tmps);
 		lInfo += '\n';
 	}
 	gtk_label_set_text((GtkLabel*)lookup_widget(InfoWin, "info_samples"), lInfo.c_str());
@@ -284,7 +292,9 @@
 	for(i = 0; i < lNumInstruments; i++)
 	{
 		lSoundFile->GetInstrumentName(i, lBuffer);
-		lInfo += lBuffer;
+		tmps = str_to_utf8(lBuffer);
+		lInfo += tmps;
+		g_free(tmps);
 		lInfo += '\n';
 	}
 	gtk_label_set_text((GtkLabel*)lookup_widget(InfoWin, "info_instruments"), lInfo.c_str());
@@ -296,7 +306,9 @@
 	//gtk_text_backward_delete(textbox, length);
 	length = lSoundFile->GetSongComments(message, MAX_MESSAGE_LENGTH, 80);
 	if (length != 0) {
-		gtk_label_set_text((GtkLabel*)lookup_widget(InfoWin, "info_message"), message);
+		tmps = str_to_utf8(message);
+		gtk_label_set_text((GtkLabel*)lookup_widget(InfoWin, "info_message"), tmps);
+		g_free(tmps);
 	}
 	
 	//unload the file
--- a/src/modplug/modplugbmp.cxx	Wed Sep 05 07:38:21 2007 +0300
+++ b/src/modplug/modplugbmp.cxx	Wed Sep 05 11:54:05 2007 +0300
@@ -19,6 +19,7 @@
 #include "audacious/tuple.h"
 #include "audacious/tuple_formatter.h"
 #include "audacious/vfs.h"
+#include "audacious/strings.h"
 }
 
 static char* format_and_free_ti( Tuple* ti, int* length )
@@ -505,7 +506,7 @@
 {
 	CSoundFile* lSoundFile;
 	Archive* lArchive;
-	char* tmps;
+	gchar* tmps;
 	
 	//open and mmap the file
         lArchive = OpenArchive(aFilename);
@@ -546,8 +547,16 @@
 	}
 	tuple_associate_string(ti, "codec", tmps);
 	tuple_associate_string(ti, "quality", "sequenced");
-	tuple_associate_string(ti, "title", lSoundFile->GetTitle());
 	tuple_associate_int(ti, "length", lSoundFile->GetSongTime() * 1000);
+
+	/* NOTICE! FIXME? This is actually incorrect. We _cannot_ know what charset
+	 * an arbitrary module file uses .. typically it is some DOS CP-variant,
+	 * except for true Amiga modules.
+	 */
+	tmps = str_to_utf8(lSoundFile->GetTitle());
+	tuple_associate_string(ti, "title", tmps);
+	g_free(tmps);
+	
 	
 	//unload the file
 	lSoundFile->Destroy();