Added a new global function to get a list of all available Text Codecs.

This commit is contained in:
LoRd_MuldeR 2011-12-10 23:12:47 +01:00
parent b633f40e4c
commit 621ddc8179
5 changed files with 46 additions and 20 deletions

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 8 #define VER_LAMEXP_PATCH 8
#define VER_LAMEXP_BUILD 806 #define VER_LAMEXP_BUILD 807
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!) // Tool versions (minimum expected versions!)

View File

@ -130,16 +130,9 @@ int CueImportDialog::exec(void)
{ {
const QString systemDefault = tr("(System Default)"); const QString systemDefault = tr("(System Default)");
QStringList codecList; codecList << systemDefault; QStringList codecList;
QList<QByteArray> availableCodecs = QTextCodec::availableCodecs(); codecList.append(systemDefault);
while(!availableCodecs.isEmpty()) codecList.append(lamexp_available_codepages());
{
QByteArray current = availableCodecs.takeFirst();
if(!(current.startsWith("system") || current.startsWith("System")))
{
codecList << QString::fromLatin1(current.constData(), current.size());
}
}
QInputDialog *input = new QInputDialog(progress); QInputDialog *input = new QInputDialog(progress);
input->setLabelText(EXPAND(tr("Select ANSI Codepage for Cue Sheet file:"))); input->setLabelText(EXPAND(tr("Select ANSI Codepage for Cue Sheet file:")));
@ -148,17 +141,20 @@ int CueImportDialog::exec(void)
input->setTextEchoMode(QLineEdit::Normal); input->setTextEchoMode(QLineEdit::Normal);
input->setComboBoxItems(codecList); input->setComboBoxItems(codecList);
if(input->exec() > 0) if(input->exec() < 1)
{
progress->close();
LAMEXP_DELETE(input);
LAMEXP_DELETE(progress);
return Rejected;
}
if(input->textValue().compare(systemDefault, Qt::CaseInsensitive))
{ {
qDebug("User-selected codec is: %s", input->textValue().toLatin1().constData()); qDebug("User-selected codec is: %s", input->textValue().toLatin1().constData());
if(input->textValue().compare(systemDefault, Qt::CaseInsensitive)) codec = QTextCodec::codecForName(input->textValue().toLatin1().constData());
{
qDebug("Going to use a user-selected codec!");
codec = QTextCodec::codecForName(input->textValue().toLatin1().constData());
}
} }
else
if(!codec)
{ {
qDebug("Going to use the system's default codec!"); qDebug("Going to use the system's default codec!");
codec = QTextCodec::codecForName("System"); codec = QTextCodec::codecForName("System");

View File

@ -1643,6 +1643,35 @@ const QString lamexp_clean_filepath(const QString &str)
return parts.join("/"); return parts.join("/");
} }
/*
* Get a list of all available Qt Text Codecs
*/
QStringList lamexp_available_codepages(bool noAliases)
{
QStringList codecList;
QList<QByteArray> availableCodecs = QTextCodec::availableCodecs();
while(!availableCodecs.isEmpty())
{
QByteArray current = availableCodecs.takeFirst();
if(!(current.startsWith("system") || current.startsWith("System")))
{
codecList << QString::fromLatin1(current.constData(), current.size());
if(noAliases)
{
if(QTextCodec *currentCodec = QTextCodec::codecForName(current.constData()))
{
QList<QByteArray> aliases = currentCodec->aliases();
while(!aliases.isEmpty()) availableCodecs.removeAll(aliases.takeFirst());
}
}
}
}
return codecList;
}
/* /*
* Finalization function (final clean-up) * Finalization function (final clean-up)
*/ */

View File

@ -116,6 +116,7 @@ QString lamexp_translation_name(const QString &language);
unsigned int lamexp_translation_sysid(const QString &langId); unsigned int lamexp_translation_sysid(const QString &langId);
bool lamexp_install_translator_from_file(const QString &qmFile); bool lamexp_install_translator_from_file(const QString &qmFile);
bool lamexp_install_translator(const QString &language); bool lamexp_install_translator(const QString &language);
QStringList lamexp_available_codepages(bool noAliases = true);
static const char* LAMEXP_DEFAULT_LANGID = "en"; static const char* LAMEXP_DEFAULT_LANGID = "en";
//Auxiliary functions //Auxiliary functions

View File

@ -530,7 +530,7 @@ unsigned int CueSheetModel::getAlbumYear(void)
int CueSheetModel::loadCueSheet(const QString &cueFileName, QCoreApplication *application, QTextCodec *forceCodec) int CueSheetModel::loadCueSheet(const QString &cueFileName, QCoreApplication *application, QTextCodec *forceCodec)
{ {
QMutexLocker lock(&m_mutex); QMutexLocker lock(&m_mutex);
const QTextCodec *codec = (forceCodec != NULL) ? forceCodec : QTextCodec::codecForName("System"); const QTextCodec *codec = (forceCodec != NULL) ? forceCodec : QTextCodec::codecForName("System");
QFile cueFile(cueFileName); QFile cueFile(cueFileName);
if(!cueFile.open(QIODevice::ReadOnly)) if(!cueFile.open(QIODevice::ReadOnly))