Improvements and fixes to the external (text) subtitle file support:

* Fix printing the loaded subtitle file to the log.
* Fix loading of UTF8 subs: detect if the strings cannot be
  presented as valid UTF8 chars and fall back to Latin1 in
  that case (TODO: add user option to select the fall back
  encoding, as it's not possible to reliably detect the
  8-bit encoding)

Index: mythtv/libs/libmythtv/tv_play.cpp
===================================================================
--- mythtv.orig/libs/libmythtv/tv_play.cpp	2006-08-28 22:38:27.000000000 +0300
+++ mythtv/libs/libmythtv/tv_play.cpp	2006-08-28 22:42:02.000000000 +0300
@@ -7053,17 +7053,19 @@
         baseName + "*.srt; " + baseName + "*.sub; " + baseName + "*.txt;");
 
     bool found = false;
+    QString candidate = "";
     QStringList::const_iterator it = candidates.begin();
     for (; (it != candidates.end()) && !found; ++it)
     {
-        if (nvp->LoadExternalSubtitles(dirName + "/" + *it))
+        candidate = dirName + "/" + *it;
+        if (nvp->LoadExternalSubtitles(candidate));
             found = true;
     }
 
     if (found)
     {
         VERBOSE(VB_PLAYBACK, LOC +
-                QString("Loaded text subtitles from '%1'.").arg(*it));
+                QString("Loaded text subtitles from '%1'.").arg(candidate));
     }
 
     return found;
Index: mythtv/libs/libmythtv/textsubtitleparser.cpp
===================================================================
--- mythtv.orig/libs/libmythtv/textsubtitleparser.cpp	2006-08-28 22:38:27.000000000 +0300
+++ mythtv/libs/libmythtv/textsubtitleparser.cpp	2006-08-29 22:13:53.000000000 +0300
@@ -5,8 +5,9 @@
  */
 
 #include <stdio.h>
-#include <qtextcodec.h>
+#include <cstring>
 #include <algorithm>
+#include <qtextcodec.h>
 
 using std::lower_bound;
 
@@ -115,6 +116,14 @@
 
     target.SetFrameBasedTiming(!sub_data.uses_time);
 
+
+    // assume the text to be in UTF8 compatible format until encountering
+    // a string of which characters cannot be encoded by UTF8
+    QTextCodec* utf8Codec = QTextCodec::codecForName("utf8");
+    assert(utf8Codec);
+
+    bool utf8 = true;
+
     // convert the subtitles to our own format and free the original structures
     for (int sub_i = 0; sub_i < sub_data.num; ++sub_i)
     {
@@ -129,10 +138,28 @@
 
         for (int line = 0; line < sub->lines; ++line)
         {
-            newsub.textLines.push_back(QString(sub->text[line]));
+            const char *subLine = sub->text[line];
+            int lineLength = std::strlen(subLine);
+
+            // check if the string contains unknown chars to UTF8, 
+            // if the encoding has not been detected to be non-UTF8
+            // before (the heuristics method can sometimes return
+            // larger than lineLength for unknown reason, thus the >= )
+            utf8 = utf8 && 
+                (utf8Codec->heuristicContentMatch(subLine, lineLength) >= lineLength);
+
+            // use Latin1 as the fall back encoding in case there was 
+            // non-UTF8 strings detected
+            // TODO: user option for setting the fall back encoding could
+            // be nice (it's impossible to detect the correct 8-bit encoding 
+            // automatically)
+            if (utf8)
+                newsub.textLines.push_back(QString::fromUtf8(subLine));
+            else 
+                newsub.textLines.push_back(QString::fromLatin1(subLine));
+
             free(sub->text[line]);
         }
-
         target.AddSubtitle(newsub);
     }
 
