Commit a018b7e4 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

setting character encoding for ID3v1.1 tags

parent 69f937fc
......@@ -60,6 +60,21 @@
#include "commandstable.h"
#include "kid3.h"
enum { TextEncodingV1Latin1Index = 13 };
/**
* Remove aliases in braces from text encoding combo box entry.
*
* @param comboEntry text encoding combo box entry
*
* @return codec name.
*/
static QString getTextEncodingV1CodecName(const QString& comboEntry)
{
int braceIdx = comboEntry.QCM_indexOf(" (");
return braceIdx == -1 ? comboEntry : comboEntry.left(braceIdx);
}
/**
* Constructor.
*
......@@ -96,20 +111,104 @@ ConfigDialog::ConfigDialog(QWidget* parent, QString& caption) :
vlayout->setSpacing(6);
#if QT_VERSION >= 0x040000
QGroupBox* v1GroupBox = new QGroupBox(i18n("ID3v1"), tagsPage);
#else
QGroupBox* v1GroupBox = new QGroupBox(1, Qt::Horizontal, i18n("ID3v1"), tagsPage);
QGridLayout* v1GroupBoxLayout = new QGridLayout(v1GroupBox);
v1GroupBoxLayout->setMargin(2);
v1GroupBoxLayout->setSpacing(4);
if (v1GroupBox) {
m_markTruncationsCheckBox = new QCheckBox(i18n("&Mark truncated fields"), v1GroupBox);
v1GroupBoxLayout->addWidget(m_markTruncationsCheckBox, 0, 0, 1, 2);
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
QLabel* textEncodingV1Label = new QLabel(i18n("Text &encoding:"), v1GroupBox);
m_textEncodingV1ComboBox = new QComboBox(v1GroupBox);
#endif
#else
QGroupBox* v1GroupBox = new QGroupBox(2, Qt::Horizontal, i18n("ID3v1"), tagsPage);
if (v1GroupBox) {
m_markTruncationsCheckBox = new QCheckBox(i18n("&Mark truncated fields"), v1GroupBox);
v1GroupBox->addSpace(0);
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
QLabel* textEncodingV1Label = new QLabel(i18n("Text &encoding:"), v1GroupBox);
m_textEncodingV1ComboBox = new QComboBox(v1GroupBox);
#endif
#endif
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
if (textEncodingV1Label && m_textEncodingV1ComboBox) {
static const char* const codecs[] = {
"Apple Roman (macintosh)",
"Big5",
"big5-0",
"Big5-HKSCS",
"big5hkscs-0",
"EUC-JP",
"EUC-KR",
"GB18030",
"GBK (windows-936)",
"hp-roman8",
"IBM850",
"IBM866",
"ISO-2022-JP (JIS7)",
"ISO-8859-1 (latin1)",
"ISO-8859-2 (latin2)",
"ISO-8859-3 (latin3)",
"ISO-8859-4 (latin4)",
"ISO-8859-5 (cyrillic)",
"ISO-8859-6 (arabic)",
"ISO-8859-7 (greek)",
"ISO-8859-8 (hebrew)",
"ISO-8859-9 (latin5)",
"ISO-8859-10 (latin6)",
"ISO-8859-13 (baltic)",
"ISO-8859-14 (latin8, iso-celtic)",
"ISO-8859-15 (latin9)",
"ISO-8859-16 (latin10)",
"ISO-10646-UCS-2 (UTF-16)",
"Iscii-Bng",
"Iscii-Dev",
"Iscii-Gjr",
"Iscii-Knd",
"Iscii-Mlm",
"Iscii-Ori",
"Iscii-Pnj",
"Iscii-Tlg",
"Iscii-Tml",
"jisx0201*-0",
"KOI8-R",
"KOI8-U",
"ksc5601.1987-0",
"mulelao-1",
"Shift_JIS (SJIS, MS_Kanji)",
"TIS-620 (ISO 8859-11)",
"TSCII",
"UTF-8",
"windows-1250",
"windows-1251",
"windows-1252",
"windows-1253",
"windows-1254",
"windows-1255",
"windows-1256",
"windows-1257",
"windows-1258",
"WINSAMI2 (WS2)",
0
};
Q_ASSERT(std::strcmp(codecs[TextEncodingV1Latin1Index], "ISO-8859-1 (latin1)") == 0);
const char* const* str = codecs;
m_textEncodingV1List.clear();
while (*str) {
m_textEncodingV1List += *str++;
}
m_textEncodingV1ComboBox->QCM_addItems(m_textEncodingV1List);
m_textEncodingV1ComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
textEncodingV1Label->setBuddy(m_textEncodingV1ComboBox);
#if QT_VERSION >= 0x040000
QHBoxLayout* hbox = new QHBoxLayout;
hbox->setMargin(2);
hbox->addWidget(m_markTruncationsCheckBox);
v1GroupBox->setLayout(hbox);
v1GroupBoxLayout->addWidget(textEncodingV1Label, 1, 0);
v1GroupBoxLayout->addWidget(m_textEncodingV1ComboBox, 1, 1);
#endif
}
#endif
vlayout->addWidget(v1GroupBox);
}
#if QT_VERSION >= 0x040000
QGroupBox* v2GroupBox = new QGroupBox(i18n("ID3v2"), tagsPage);
QGridLayout* v2GroupBoxLayout = new QGridLayout(v2GroupBox);
......@@ -458,6 +557,18 @@ void ConfigDialog::setConfig(const FormatConfig* fnCfg,
#endif
#endif
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
int textEncodingV1Index = TextEncodingV1Latin1Index;
int index = 0;
for (QStringList::const_iterator it = m_textEncodingV1List.begin();
it != m_textEncodingV1List.end();
++it) {
if (getTextEncodingV1CodecName(*it) == miscCfg->m_textEncodingV1) {
textEncodingV1Index = index;
break;
}
++index;
}
m_textEncodingV1ComboBox->QCM_setCurrentIndex(textEncodingV1Index);
m_textEncodingComboBox->QCM_setCurrentIndex(miscCfg->m_textEncoding);
#endif
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
......@@ -517,6 +628,8 @@ void ConfigDialog::getConfig(FormatConfig* fnCfg,
miscCfg->m_commentName = m_commentNameComboBox->currentText();
#endif
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
miscCfg->m_textEncodingV1 =
getTextEncodingV1CodecName(m_textEncodingV1ComboBox->currentText());
miscCfg->m_textEncoding = m_textEncodingComboBox->QCM_currentIndex();
#endif
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
......
......@@ -35,6 +35,7 @@
#endif
#endif
#include <qstringlist.h>
#include "qtcompatmac.h"
#ifdef KID3_USE_KCONFIGDIALOG
#include <kconfigdialog.h>
......@@ -132,6 +133,10 @@ private:
QCheckBox* m_preserveTimeCheckBox;
/** Mark truncated fields checkbox */
QCheckBox* m_markTruncationsCheckBox;
/** ID3v1 text encodings */
QStringList m_textEncodingV1List;
/** ID3v1 text encoding combo box */
QComboBox* m_textEncodingV1ComboBox;
/** Use track/total number of tracks format checkbox */
QCheckBox* m_totalNumTracksCheckBox;
/** Comment field name combo box */
......
......@@ -35,6 +35,7 @@
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <qimage.h>
#include <qtextcodec.h>
#include "qtcompatmac.h"
#if QT_VERSION >= 0x040000
#include <QCloseEvent>
......@@ -943,22 +944,35 @@ void Kid3App::saveOptions()
}
/**
* Load application options.
* Set the ID3v1 and ID3v2 text encodings from the configuration.
*/
void Kid3App::readOptions()
static void setTextEncodings()
{
s_miscCfg.readFromConfig(m_config);
if (s_miscCfg.m_nameFilter.isEmpty()) {
createFilterString(&s_miscCfg.m_nameFilter);
}
const QTextCodec* id3v1TextCodec =
Kid3App::s_miscCfg.m_textEncodingV1 != "ISO-8859-1" ?
QTextCodec::codecForName(Kid3App::s_miscCfg.m_textEncodingV1.QCM_latin1()) : 0;
#ifdef HAVE_ID3LIB
Mp3File::setDefaultTextEncoding(
static_cast<MiscConfig::TextEncoding>(s_miscCfg.m_textEncoding));
static_cast<MiscConfig::TextEncoding>(Kid3App::s_miscCfg.m_textEncoding));
Mp3File::setTextCodecV1(id3v1TextCodec);
#endif
#ifdef HAVE_TAGLIB
TagLibFile::setDefaultTextEncoding(
static_cast<MiscConfig::TextEncoding>(s_miscCfg.m_textEncoding));
static_cast<MiscConfig::TextEncoding>(Kid3App::s_miscCfg.m_textEncoding));
TagLibFile::setTextCodecV1(id3v1TextCodec);
#endif
}
/**
* Load application options.
*/
void Kid3App::readOptions()
{
s_miscCfg.readFromConfig(m_config);
if (s_miscCfg.m_nameFilter.isEmpty()) {
createFilterString(&s_miscCfg.m_nameFilter);
}
setTextEncodings();
s_fnFormatCfg.readFromConfig(m_config);
s_id3FormatCfg.readFromConfig(m_config);
s_genCfg.readFromConfig(m_config);
......@@ -2124,14 +2138,7 @@ void Kid3App::slotSettingsConfigure()
if (!s_miscCfg.m_markTruncations) {
m_view->frameTableV1()->markRows(0);
}
#ifdef HAVE_ID3LIB
Mp3File::setDefaultTextEncoding(
static_cast<MiscConfig::TextEncoding>(s_miscCfg.m_textEncoding));
#endif
#ifdef HAVE_TAGLIB
TagLibFile::setDefaultTextEncoding(
static_cast<MiscConfig::TextEncoding>(s_miscCfg.m_textEncoding));
#endif
setTextEncodings();
#if QT_VERSION < 0x040000
m_view->frameTableV1()->triggerUpdateGenres();
m_view->frameTableV2()->triggerUpdateGenres();
......
......@@ -110,6 +110,7 @@ MiscConfig::MiscConfig(const QString& group) :
m_hideV1(false),
m_hideV2(false),
m_id3v2Version(ID3v2_3_0),
m_textEncodingV1(""),
m_textEncoding(TE_ISO8859_1),
m_useProxy(false),
m_onlyCustomGenres(false)
......@@ -155,6 +156,7 @@ void MiscConfig::writeToConfig(
cfg.writeEntry("HideV1", m_hideV1);
cfg.writeEntry("HideV2", m_hideV2);
cfg.writeEntry("ID3v2Version", m_id3v2Version);
cfg.writeEntry("TextEncodingV1", m_textEncodingV1);
cfg.writeEntry("TextEncoding", m_textEncoding);
cfg.writeEntry("UseProxy", m_useProxy);
cfg.writeEntry("Proxy", m_proxy);
......@@ -211,6 +213,7 @@ void MiscConfig::writeToConfig(
config->QCM_writeEntry("/HideV1", m_hideV1);
config->QCM_writeEntry("/HideV2", m_hideV2);
config->QCM_writeEntry("/ID3v2Version", m_id3v2Version);
config->QCM_writeEntry("/TextEncodingV1", m_textEncodingV1);
config->QCM_writeEntry("/TextEncoding", m_textEncoding);
config->QCM_writeEntry("/UseProxy", m_useProxy);
config->QCM_writeEntry("/Proxy", m_proxy);
......@@ -281,6 +284,7 @@ void MiscConfig::readFromConfig(
m_hideV1 = cfg.KCM_readBoolEntry("HideV1", m_hideV1);
m_hideV2 = cfg.KCM_readBoolEntry("HideV2", m_hideV2);
m_id3v2Version = cfg.KCM_readNumEntry("ID3v2Version", static_cast<int>(ID3v2_3_0));
m_textEncodingV1 = cfg.readEntry("TextEncodingV1", "");
m_textEncoding = cfg.KCM_readNumEntry("TextEncoding", static_cast<int>(TE_ISO8859_1));
m_useProxy = cfg.KCM_readBoolEntry("UseProxy", m_useProxy);
m_proxy = cfg.readEntry("Proxy", m_proxy);
......@@ -338,6 +342,7 @@ void MiscConfig::readFromConfig(
m_hideV1 = config->QCM_readBoolEntry("/HideV1", m_hideV1);
m_hideV2 = config->QCM_readBoolEntry("/HideV2", m_hideV2);
m_id3v2Version = config->QCM_readNumEntry("/ID3v2Version", ID3v2_3_0);
m_textEncodingV1 = config->QCM_readEntry("/TextEncodingV1", "");
m_textEncoding = config->QCM_readNumEntry("/TextEncoding", TE_ISO8859_1);
m_useProxy = config->QCM_readBoolEntry("/UseProxy", m_useProxy);
m_proxy = config->QCM_readEntry("/Proxy", m_proxy);
......
......@@ -201,6 +201,8 @@ public:
bool m_hideV2;
/** version used for new ID3v2 tags */
int m_id3v2Version;
/** text encoding used for new ID3v1 tags */
QString m_textEncodingV1;
/** text encoding used for new ID3v2 tags */
int m_textEncoding;
/** true if proxy is used */
......
......@@ -29,6 +29,7 @@
#include <qdir.h>
#include <qstring.h>
#include <qtextcodec.h>
#include "qtcompatmac.h"
#if QT_VERSION >= 0x040000
#include <QByteArray>
......@@ -61,6 +62,9 @@
#define UNICODE_SUPPORT_BUGGY ((((ID3LIB_MAJOR_VERSION) << 16) + ((ID3LIB_MINOR_VERSION) << 8) + (ID3LIB_PATCH_VERSION)) <= 0x030803)
#endif
/** Text codec for ID3v1 tags, 0 to use default (ISO 8859-1) */
const QTextCodec* Mp3File::s_textCodecV1 = 0;
/** Default text encoding */
ID3_TextEnc Mp3File::s_defaultTextEncoding = ID3TE_ISO8859_1;
......@@ -273,11 +277,12 @@ static QString fixUpUnicode(const unicode_t* str, size_t numChars)
* Get string from text field.
*
* @param field field
* @param codec text codec to use, 0 for default
*
* @return string,
* "" if the field does not exist.
*/
static QString getString(ID3_Field* field)
static QString getString(ID3_Field* field, const QTextCodec* codec = 0)
{
QString text("");
if (field != NULL) {
......@@ -301,7 +306,9 @@ static QString getString(ID3_Field* field)
// (enc == ID3TE_ISO8859_1 || enc == ID3TE_UTF8)
size_t numItems = field->GetNumTextItems();
if (numItems <= 1) {
text = QString(field->GetRawText());
text = codec ?
codec->toUnicode(field->GetRawText(), field->Size()) :
QString(field->GetRawText());
} else {
// if there are multiple items, put them into one string
// separated by a special separator.
......@@ -324,11 +331,13 @@ static QString getString(ID3_Field* field)
*
* @param tag ID3 tag
* @param id frame ID
* @param codec text codec to use, 0 for default
* @return string,
* "" if the field does not exist,
* QString::null if the tags do not exist.
*/
static QString getTextField(const ID3_Tag* tag, ID3_FrameID id)
static QString getTextField(const ID3_Tag* tag, ID3_FrameID id,
const QTextCodec* codec = 0)
{
if (!tag) {
return QString::null;
......@@ -337,7 +346,7 @@ static QString getTextField(const ID3_Tag* tag, ID3_FrameID id)
ID3_Field* fld;
ID3_Frame* frame = tag->Find(id);
if (frame && ((fld = frame->GetField(ID3FN_TEXT)) != NULL)) {
str = getString(fld);
str = getString(fld, codec);
}
return str;
}
......@@ -495,8 +504,10 @@ static void setStringList(ID3_Field* field, const QStringList& lst)
*
* @param field field
* @param text text to set
* @param codec text codec to use, 0 for default
*/
static void setString(ID3_Field* field, const QString& text)
static void setString(ID3_Field* field, const QString& text,
const QTextCodec* codec = 0)
{
if (text.QCM_indexOf(Frame::stringListSeparator()) == -1) {
ID3_TextEnc enc = field->GetEncoding();
......@@ -511,7 +522,7 @@ static void setString(ID3_Field* field, const QString& text)
field->Set(text.QCM_toUtf8().data());
} else {
// enc == ID3TE_ISO8859_1
field->Set(text.QCM_latin1());
field->Set(codec ? codec->fromUnicode(text).data() : text.QCM_latin1());
}
} else {
setStringList(field, QCM_split(Frame::stringListSeparator(), text));
......@@ -527,12 +538,13 @@ static void setString(ID3_Field* field, const QString& text)
* @param allowUnicode true to allow setting of Unicode encoding if necessary
* @param replace true to replace an existing field
* @param removeEmpty true to remove a field if text is empty
* @param codec text codec to use, 0 for default
*
* @return true if the field was changed.
*/
static bool setTextField(ID3_Tag* tag, ID3_FrameID id, const QString& text,
bool allowUnicode = false, bool replace = true,
bool removeEmpty = true)
bool removeEmpty = true, const QTextCodec* codec = 0)
{
bool changed = false;
if (tag && !text.isNull()) {
......@@ -571,7 +583,7 @@ static bool setTextField(ID3_Tag* tag, ID3_FrameID id, const QString& text,
encfld->Set(enc);
}
fld->SetEncoding(enc);
setString(fld, text);
setString(fld, text, codec);
tag->AttachFrame(frame);
}
}
......@@ -667,7 +679,7 @@ static bool setGenreNum(ID3_Tag* tag, int num)
*/
QString Mp3File::getTitleV1()
{
return getTextField(m_tagV1, ID3FID_TITLE);
return getTextField(m_tagV1, ID3FID_TITLE, s_textCodecV1);
}
/**
......@@ -679,7 +691,7 @@ QString Mp3File::getTitleV1()
*/
QString Mp3File::getArtistV1()
{
return getTextField(m_tagV1, ID3FID_LEADARTIST);
return getTextField(m_tagV1, ID3FID_LEADARTIST, s_textCodecV1);
}
/**
......@@ -691,7 +703,7 @@ QString Mp3File::getArtistV1()
*/
QString Mp3File::getAlbumV1()
{
return getTextField(m_tagV1, ID3FID_ALBUM);
return getTextField(m_tagV1, ID3FID_ALBUM, s_textCodecV1);
}
/**
......@@ -703,7 +715,7 @@ QString Mp3File::getAlbumV1()
*/
QString Mp3File::getCommentV1()
{
return getTextField(m_tagV1, ID3FID_COMMENT);
return getTextField(m_tagV1, ID3FID_COMMENT, s_textCodecV1);
}
/**
......@@ -845,11 +857,11 @@ QString Mp3File::getGenreV2()
*/
void Mp3File::setTitleV1(const QString& str)
{
if (getTextField(m_tagV1, ID3FID_TITLE) != str &&
setTextField(m_tagV1, ID3FID_TITLE, str)) {
if (getTextField(m_tagV1, ID3FID_TITLE, s_textCodecV1) != str &&
setTextField(m_tagV1, ID3FID_TITLE, str, false, true, true, s_textCodecV1)) {
markTag1Changed();
QString s = checkTruncation(str, 1 << Frame::FT_Title);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_TITLE, s);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_TITLE, s, false, true, true, s_textCodecV1);
}
}
......@@ -860,11 +872,11 @@ void Mp3File::setTitleV1(const QString& str)
*/
void Mp3File::setArtistV1(const QString& str)
{
if (getTextField(m_tagV1, ID3FID_LEADARTIST) != str &&
setTextField(m_tagV1, ID3FID_LEADARTIST, str)) {
if (getTextField(m_tagV1, ID3FID_LEADARTIST, s_textCodecV1) != str &&
setTextField(m_tagV1, ID3FID_LEADARTIST, str, false, true, true, s_textCodecV1)) {
markTag1Changed();
QString s = checkTruncation(str, 1 << Frame::FT_Artist);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_LEADARTIST, s);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_LEADARTIST, s, false, true, true, s_textCodecV1);
}
}
......@@ -875,11 +887,11 @@ void Mp3File::setArtistV1(const QString& str)
*/
void Mp3File::setAlbumV1(const QString& str)
{
if (getTextField(m_tagV1, ID3FID_ALBUM) != str &&
setTextField(m_tagV1, ID3FID_ALBUM, str)) {
if (getTextField(m_tagV1, ID3FID_ALBUM, s_textCodecV1) != str &&
setTextField(m_tagV1, ID3FID_ALBUM, str, false, true, true, s_textCodecV1)) {
markTag1Changed();
QString s = checkTruncation(str, 1 << Frame::FT_Album);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_ALBUM, s);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_ALBUM, s, false, true, true, s_textCodecV1);
}
}
......@@ -890,11 +902,11 @@ void Mp3File::setAlbumV1(const QString& str)
*/
void Mp3File::setCommentV1(const QString& str)
{
if (getTextField(m_tagV1, ID3FID_COMMENT) != str &&
setTextField(m_tagV1, ID3FID_COMMENT, str)) {
if (getTextField(m_tagV1, ID3FID_COMMENT, s_textCodecV1) != str &&
setTextField(m_tagV1, ID3FID_COMMENT, str, false, true, true, s_textCodecV1)) {
markTag1Changed();
QString s = checkTruncation(str, 1 << Frame::FT_Comment, 28);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_COMMENT, s);
if (!s.isNull()) setTextField(m_tagV1, ID3FID_COMMENT, s, false, true, true, s_textCodecV1);
}
}
......@@ -1832,6 +1844,16 @@ QStringList Mp3File::getFrameIds() const
return lst;
}
/**
* Set the text codec to be used for tag 1.
*
* @param codec text codec, 0 to use default (ISO 8859-1)
*/
void Mp3File::setTextCodecV1(const QTextCodec* codec)
{
s_textCodecV1 = codec;
}
/**
* Set the default text encoding.
*
......
......@@ -36,6 +36,7 @@
class ID3_Tag;
class ID3_Field;
class ID3_Frame;
class QTextCodec;
/** List box item containing MP3 file */
class Mp3File : public TaggedFile {
......@@ -443,6 +444,13 @@ public:
*/
virtual QStringList getFrameIds() const;
/**
* Set the text codec to be used for tag 1.
*
* @param codec text codec, 0 to use default (ISO 8859-1)
*/
static void setTextCodecV1(const QTextCodec* codec);
/**
* Set the default text encoding.
*
......@@ -474,6 +482,9 @@ private:
/** ID3v2 tags */
ID3_Tag* m_tagV2;
/** Text codec for ID3v1 tags, 0 to use default (ISO 8859-1) */
static const QTextCodec* s_textCodecV1;
/** Default text encoding */
static ID3_TextEnc s_defaultTextEncoding;
};
......
......@@ -29,6 +29,7 @@
#include <qdir.h>
#include <qstring.h>
#include <qtextcodec.h>
#include "qtcompatmac.h"
#if QT_VERSION >= 0x040000
#include <QByteArray>
......@@ -83,6 +84,76 @@
#include "taglibext/aac/aacfiletyperesolver.h"
#include "taglibext/mp2/mp2filetyperesolver.h"
/**
* Data encoding in ID3v1 tags.
*/
class TextCodecStringHandler : public TagLib::ID3v1::StringHandler {
public:
/**
* Constructor.
*/
TextCodecStringHandler() {}
/**
* Destructor.
*/
virtual ~TextCodecStringHandler() {}
/**
* Decode a string from data.
*
* @param data data to decode
*/
virtual TagLib::String parse(const TagLib::ByteVector& data) const;
/**
* Encode a byte vector with the data from a string.
*
* @param s string to encode
*/
virtual TagLib::ByteVector render(const TagLib::String& s) const;
/**
* Set text codec.
* @param codec text codec, 0 for default behavior (ISO 8859-1)
*/
static void setTextCodec(const QTextCodec* codec) { s_codec = codec; }
private:
static const QTextCodec* s_codec;
};
const QTextCodec* TextCodecStringHandler::s_codec = 0;
/**
* Decode a string from data.
*
* @param data data to decode
*/
TagLib::String TextCodecStringHandler::parse(const TagLib::ByteVector& data) const
{
return s_codec ?
QSTRING_TO_TSTRING(s_codec->toUnicode(data.data(), data.size())).stripWhiteSpace() :
TagLib::String(data, TagLib::String::Latin1).stripWhiteSpace();
}
/**
* Encode a byte vector with the data from a string.
*
* @param s string to encode
*/
TagLib::ByteVector TextCodecStringHandler::render(const TagLib::String& s) const
{
if (s_codec) {
QCM_QCString ba(s_codec->fromUnicode(TStringToQString(s)));
return TagLib::ByteVector(ba.data(), ba.size());