diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-02-03 21:00:34 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-02-03 21:00:34 +0000 |
| commit | 0c969362a32a2990c5b77e2720bc0f343957469d (patch) | |
| tree | 1bcee268dfa149bd05cd4d57d5d98b046273e3cb /src/plugins/Input/cue/cueparser.cpp | |
| parent | 72f0f5c74aa64a60d6c39f8490d7dd876bdf2885 (diff) | |
| download | qmmp-0c969362a32a2990c5b77e2720bc0f343957469d.tar.gz qmmp-0c969362a32a2990c5b77e2720bc0f343957469d.tar.bz2 qmmp-0c969362a32a2990c5b77e2720bc0f343957469d.zip | |
cue plugin: added automatic charset detection (Closes issue 50)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1542 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input/cue/cueparser.cpp')
| -rw-r--r-- | src/plugins/Input/cue/cueparser.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp index 6343bf647..63c55c83d 100644 --- a/src/plugins/Input/cue/cueparser.cpp +++ b/src/plugins/Input/cue/cueparser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Ilya Kotov * + * Copyright (C) 2008-2010 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -23,10 +23,11 @@ #include <QSettings> #include <QTextStream> #include <QTextCodec> - #include <qmmp/decoder.h> #include <qmmp/metadatamanager.h> - +#ifdef WITH_ENCA +#include <enca.h> +#endif #include "cueparser.h" CUEParser::CUEParser(const QString &fileName) @@ -39,7 +40,32 @@ CUEParser::CUEParser(const QString &fileName) } QTextStream textStream (&file); QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - QTextCodec *codec = QTextCodec::codecForName(settings.value("CUE/encoding","ISO-8859-1").toByteArray ()); + settings.beginGroup("CUE"); + QTextCodec *codec = QTextCodec::codecForName(settings.value("encoding","ISO-8859-1").toByteArray ()); + if(!codec) + codec = QTextCodec::codecForName("UTF-8"); +#ifdef WITH_ENCA + EncaAnalyser analyser = 0; + if(settings.value("use_enca", FALSE).toBool()) + { + analyser = enca_analyser_alloc(settings.value("enca_lang").toByteArray ().constData()); + if(analyser) + { + EncaEncoding encoding = enca_analyse(analyser, + (uchar *)file.readAll().constData(), + file.size()); + file.reset(); + if(encoding.charset != ENCA_CS_UNKNOWN) + { + codec = QTextCodec::codecForName(enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA)); + //qDebug("CUEParser: detected charset: %s", + // enca_charset_name(encoding.charset,ENCA_NAME_STYLE_ENCA)); + } + } + } +#endif + settings.endGroup(); + //qDebug("CUEParser: using %s encoding", codec->name().constData()); textStream.setCodec(codec); QString album, genre, date, comment, artist, file_path; bool new_file = FALSE; @@ -120,6 +146,10 @@ CUEParser::CUEParser(const QString &fileName) } } file.close(); +#ifdef WITH_ENCA + if(analyser) + enca_analyser_free(analyser); +#endif if(m_infoList.isEmpty()) { qWarning("CUEParser: invalid cue file"); |
