From 621ddc817908fe82a4e95337726febb927f3dd7f Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sat, 10 Dec 2011 23:12:47 +0100 Subject: [PATCH] Added a new global function to get a list of all available Text Codecs. --- src/Config.h | 2 +- src/Dialog_CueImport.cpp | 32 ++++++++++++++------------------ src/Global.cpp | 29 +++++++++++++++++++++++++++++ src/Global.h | 1 + src/Model_CueSheet.cpp | 2 +- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/Config.h b/src/Config.h index 1f111f93..56908381 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 8 -#define VER_LAMEXP_BUILD 806 +#define VER_LAMEXP_BUILD 807 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index 3f205059..87b4ab7f 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -130,16 +130,9 @@ int CueImportDialog::exec(void) { const QString systemDefault = tr("(System Default)"); - QStringList codecList; codecList << systemDefault; - QList availableCodecs = QTextCodec::availableCodecs(); - while(!availableCodecs.isEmpty()) - { - QByteArray current = availableCodecs.takeFirst(); - if(!(current.startsWith("system") || current.startsWith("System"))) - { - codecList << QString::fromLatin1(current.constData(), current.size()); - } - } + QStringList codecList; + codecList.append(systemDefault); + codecList.append(lamexp_available_codepages()); QInputDialog *input = new QInputDialog(progress); input->setLabelText(EXPAND(tr("Select ANSI Codepage for Cue Sheet file:"))); @@ -148,17 +141,20 @@ int CueImportDialog::exec(void) input->setTextEchoMode(QLineEdit::Normal); 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()); - if(input->textValue().compare(systemDefault, Qt::CaseInsensitive)) - { - qDebug("Going to use a user-selected codec!"); - codec = QTextCodec::codecForName(input->textValue().toLatin1().constData()); - } + codec = QTextCodec::codecForName(input->textValue().toLatin1().constData()); } - - if(!codec) + else { qDebug("Going to use the system's default codec!"); codec = QTextCodec::codecForName("System"); diff --git a/src/Global.cpp b/src/Global.cpp index 35b66144..4d0088a7 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -1643,6 +1643,35 @@ const QString lamexp_clean_filepath(const QString &str) return parts.join("/"); } +/* + * Get a list of all available Qt Text Codecs + */ +QStringList lamexp_available_codepages(bool noAliases) +{ + QStringList codecList; + + QList 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 aliases = currentCodec->aliases(); + while(!aliases.isEmpty()) availableCodecs.removeAll(aliases.takeFirst()); + } + } + } + } + + return codecList; +} + /* * Finalization function (final clean-up) */ diff --git a/src/Global.h b/src/Global.h index faaf8576..2fd5d2a3 100644 --- a/src/Global.h +++ b/src/Global.h @@ -116,6 +116,7 @@ QString lamexp_translation_name(const QString &language); unsigned int lamexp_translation_sysid(const QString &langId); bool lamexp_install_translator_from_file(const QString &qmFile); bool lamexp_install_translator(const QString &language); +QStringList lamexp_available_codepages(bool noAliases = true); static const char* LAMEXP_DEFAULT_LANGID = "en"; //Auxiliary functions diff --git a/src/Model_CueSheet.cpp b/src/Model_CueSheet.cpp index b8385b92..3c001264 100644 --- a/src/Model_CueSheet.cpp +++ b/src/Model_CueSheet.cpp @@ -530,7 +530,7 @@ unsigned int CueSheetModel::getAlbumYear(void) int CueSheetModel::loadCueSheet(const QString &cueFileName, QCoreApplication *application, QTextCodec *forceCodec) { 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); if(!cueFile.open(QIODevice::ReadOnly))