diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 5cde6690..c2affc2c 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -1208,6 +1208,10 @@ Style + + + :/icons/palette.png:/icons/palette.png + @@ -1218,7 +1222,10 @@ Language - + + + :/icons/font.png:/icons/font.png + @@ -1458,6 +1465,10 @@ true + + + :/flags/gb.png:/flags/gb.png + English @@ -1465,113 +1476,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/res/Flags.qrc b/res/Flags.qrc index f78762f1..7bc7babe 100644 --- a/res/Flags.qrc +++ b/res/Flags.qrc @@ -2,6 +2,8 @@ flags/de.png + flags/fr.png flags/gb.png + flags/it.png diff --git a/res/Icons.qrc b/res/Icons.qrc index 4137a380..46b3b288 100644 --- a/res/Icons.qrc +++ b/res/Icons.qrc @@ -44,6 +44,7 @@ icons/folder_go.png icons/folder_image.png icons/folder_page.png + icons/font.png icons/house.png icons/hourglass.png icons/information.png @@ -51,6 +52,7 @@ icons/money_dollar.png icons/monitor.png icons/music.png + icons/palette.png icons/package.png icons/page_white_cplusplus.png icons/page_white_add.png diff --git a/res/Localization.qrc b/res/Localization.qrc index 80bd0f3c..7a48f215 100644 --- a/res/Localization.qrc +++ b/res/Localization.qrc @@ -4,10 +4,10 @@ localization/LameXP_DE.qm localization/LameXP_DE.qm.txt diff --git a/src/Config.h b/src/Config.h index babdd3af..fd4e5be5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 197 +#define VER_LAMEXP_BUILD 200 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 8945ad23..e743ba5d 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -249,24 +249,20 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S //Populate the language menu m_languageActionGroup = new QActionGroup(this); - m_languageActionGroup->addAction(actionLanguageEnglish); - actionLanguageEnglish->setChecked(true); connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*))); QStringList translations = lamexp_query_translations(); - while(translations.count() > 0) + while(!translations.isEmpty()) { + QString langId = translations.takeFirst(); QAction *currentLanguage = new QAction(this); + currentLanguage->setData(langId); + currentLanguage->setText(lamexp_translation_name(langId)); + currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId))); currentLanguage->setCheckable(true); - currentLanguage->setText(translations.takeFirst()); m_languageActionGroup->addAction(currentLanguage); menuLanguage->addAction(currentLanguage); - if(currentLanguage->text().compare(m_settings->currentLanguage(), Qt::CaseInsensitive) == 0) - { - currentLanguage->setChecked(true); - languageActionActivated(currentLanguage); - } } - + //Activate tools menu actions actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled()); actionDisableSounds->setChecked(!m_settings->soundsEnabled()); @@ -311,8 +307,17 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S //Enable Drag & Drop this->setAcceptDrops(true); - //Finally re-translate the UI - retranslateUi(this); + //Load translation & re-translate + QList languageActions = m_languageActionGroup->actions(); + while(!languageActions.isEmpty()) + { + QAction *currentLanguage = languageActions.takeFirst(); + if(currentLanguage->data().toString().compare(m_settings->currentLanguage(), Qt::CaseInsensitive) == 0) + { + currentLanguage->setChecked(true); + languageActionActivated(currentLanguage); + } + } } //////////////////////////////////////////////////////////// @@ -630,9 +635,9 @@ void MainWindow::windowShown(void) if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac()) { QString messageText; - messageText += tr("LameXP detected that your version of the Nero AAC encoder is outdated!
"); - messageText += tr("The current version available is %1 (or later), but you still have version %2 installed.

").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac()), lamexp_version2string("?.?.?.?", lamexp_tool_version("neroAacEnc.exe"))); - messageText += tr("You can download the latest version of the Nero AAC encoder from the Nero website at:
"); + messageText += QString("
%1
").arg(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")); + messageText += QString("%1

").arg(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac()), lamexp_version2string("?.?.?.?", lamexp_tool_version("neroAacEnc.exe")))); + messageText += QString("%1
").arg(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")); messageText += "" + LINK(AboutDialog::neroAacUrl) + "
"; QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText); } @@ -641,11 +646,11 @@ void MainWindow::windowShown(void) { radioButtonEncoderAAC->setEnabled(false); QString messageText; - messageText += tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.
"); - messageText += tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!

"); - messageText += tr("Your LameXP directory is located here:
"); + messageText += QString("
%1
").arg(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")); + messageText += QString("%1

").arg(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")); + messageText += QString("%1
").arg(tr("Your LameXP directory is located here:")); messageText += QString("
%1

").arg(QDir::toNativeSeparators(QCoreApplication::applicationDirPath())); - messageText += tr("You can download the Nero AAC encoder for free from the official Nero website at:
"); + messageText += QString("%1
").arg(tr("You can download the Nero AAC encoder for free from the official Nero website at:")); messageText += "" + LINK(AboutDialog::neroAacUrl) + "
"; QMessageBox::information(this, tr("AAC Support Disabled"), messageText); } @@ -657,8 +662,8 @@ void MainWindow::windowShown(void) if(!lamexp_check_tool("wmawav.exe")) { QString messageText; - messageText += tr("LameXP has detected that the WMA File Decoder component is not currently installed on your system.
"); - messageText += tr("You won't be able to process WMA files as input unless the WMA File Decoder component is installed!
"); + messageText += QString("%1
").arg(tr("LameXP has detected that the WMA File Decoder component is not currently installed on your system.")); + messageText += QString("%1
").arg(tr("You won't be able to process WMA files as input unless the WMA File Decoder component is installed!")); QMessageBox::information(this, tr("WMA Decoder Missing"), messageText); installWMADecoderActionTriggered(rand() % 2); } @@ -962,19 +967,11 @@ void MainWindow::styleActionActivated(QAction *action) */ void MainWindow::languageActionActivated(QAction *action) { - if(action != actionLanguageEnglish) + QString langId = action->data().toString(); + + if(lamexp_install_translator(langId)) { - if(lamexp_install_translator(action->text())) - { - m_settings->currentLanguage(action->text()); - } - } - else - { - if(lamexp_install_translator(QString())) - { - m_settings->currentLanguage(action->text()); - } + m_settings->currentLanguage(langId); } retranslateUi(this); diff --git a/src/Global.cpp b/src/Global.cpp index dc88867b..d0f5fefb 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -121,7 +121,8 @@ static QMap g_lamexp_tool_registry; static QMap g_lamexp_tool_versions; //Languages -static QMap g_lamexp_translations; +static QMap g_lamexp_translation_files; +static QMap g_lamexp_translation_names; static QTranslator *g_lamexp_currentTranslator = NULL; //Shared memory @@ -448,6 +449,44 @@ static bool lamexp_check_elevation(void) return !bIsProcessElevated; } +/* + * Initialize translation files + */ +static void lamexp_init_translations(void) +{ + //Add default translations + g_lamexp_translation_files.insert(LAMEXP_DEFAULT_LANGID, ""); + g_lamexp_translation_names.insert(LAMEXP_DEFAULT_LANGID, "English"); + + //Search for language files + QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name); + + //Add all available translations + while(!qmFiles.isEmpty()) + { + QString langId, langName; + QString qmFile = qmFiles.takeFirst(); + + QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive); + if(langIdExp.indexIn(qmFile) >= 0) + { + langId = langIdExp.cap(1).toLower(); + } + + QResource langNameRes = (QString(":/localization/%1.txt").arg(qmFile)); + if(langNameRes.isValid() && langNameRes.size() > 0) + { + langName = QString::fromUtf8(reinterpret_cast(langNameRes.data()), langNameRes.size()); + } + + if(!langId.isEmpty() && !langName.isEmpty()) + { + g_lamexp_translation_files.insert(langId, qmFile); + g_lamexp_translation_names.insert(langId, langName); + } + } +} + /* * Initialize Qt framework */ @@ -519,17 +558,9 @@ bool lamexp_init_qt(int argc, char* argv[]) return false; } } - - //Init available translations - QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "*.qm", QDir::Files, QDir::Name); - for(int i = 0; i < qmFiles.count(); i++) - { - QResource langName = (QString(":/localization/%1.txt").arg(qmFiles.at(i))); - if(langName.isValid() && langName.size() > 0) - { - g_lamexp_translations.insert(QString::fromUtf8(reinterpret_cast(langName.data()), langName.size()), qmFiles.at(i)); - } - } + + //Init language files + lamexp_init_translations(); //Check for process elevation if(!lamexp_check_elevation()) @@ -867,17 +898,25 @@ const QString lamexp_version2string(const QString &pattern, unsigned int version } /* - * Get list of translations + * Get list of all translations */ QStringList lamexp_query_translations(void) { - return g_lamexp_translations.keys(); + return g_lamexp_translation_files.keys(); +} + +/* + * Get translation name + */ +QString lamexp_translation_name(const QString &langId) +{ + return g_lamexp_translation_names.value(langId.toLower(), QString()); } /* * Install a new translator */ -bool lamexp_install_translator(const QString &language) +bool lamexp_install_translator(const QString &langId) { bool success = false; @@ -886,14 +925,14 @@ bool lamexp_install_translator(const QString &language) g_lamexp_currentTranslator = new QTranslator(); } - if(language.isEmpty()) + if(langId.isEmpty() || langId.toLower().compare(LAMEXP_DEFAULT_LANGID) == 0) { QApplication::removeTranslator(g_lamexp_currentTranslator); success = true; } else { - QString qmFile = g_lamexp_translations.value(language, QString()); + QString qmFile = g_lamexp_translation_files.value(langId.toLower(), QString()); if(!qmFile.isEmpty()) { QApplication::removeTranslator(g_lamexp_currentTranslator); @@ -902,7 +941,7 @@ bool lamexp_install_translator(const QString &language) } else { - qWarning("Translation '%s' not available!", language.toLatin1().constData()); + qWarning("Translation '%s' not available!", langId.toLatin1().constData()); } } @@ -1080,9 +1119,13 @@ void lamexp_finalization(void) } //Clear languages - lamexp_install_translator(QString()); - LAMEXP_DELETE(g_lamexp_currentTranslator); - g_lamexp_translations.clear(); + if(g_lamexp_currentTranslator) + { + QApplication::removeTranslator(g_lamexp_currentTranslator); + LAMEXP_DELETE(g_lamexp_currentTranslator); + } + g_lamexp_translation_files.clear(); + g_lamexp_translation_names.clear(); //Destroy Qt application object QApplication *application = dynamic_cast(QApplication::instance()); diff --git a/src/Global.h b/src/Global.h index 926f2aed..51d61054 100644 --- a/src/Global.h +++ b/src/Global.h @@ -91,8 +91,12 @@ const QString &lamexp_temp_folder(void); void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize); void lamexp_ipc_send(unsigned int command, const char* message); lamexp_cpu_t lamexp_detect_cpu_features(void); + +//Translation support QStringList lamexp_query_translations(void); +QString lamexp_translation_name(const QString &language); bool lamexp_install_translator(const QString &language); +static const char* LAMEXP_DEFAULT_LANGID = "gb"; //Auxiliary functions bool lamexp_clean_folder(const QString folderPath); diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index 17d366eb..bc20e066 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -28,6 +28,7 @@ #include #include #include +#include //Constants static const char *g_settingsId_versionNumber = "VersionNumber"; @@ -96,10 +97,12 @@ void SettingsModel::validate(void) { this->compressionEncoder(SettingsModel::MP3Encoder); } + if(this->compressionRCMode() < SettingsModel::VBRMode || this->compressionRCMode() > SettingsModel::CBRMode) { this->compressionEncoder(SettingsModel::VBRMode); } + if(!(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe"))) { if(this->compressionEncoder() == SettingsModel::AACEncoder) @@ -108,10 +111,17 @@ void SettingsModel::validate(void) this->compressionEncoder(SettingsModel::MP3Encoder); } } + if(this->outputDir().isEmpty() || !QFileInfo(this->outputDir()).isDir()) { this->outputDir(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); } + + if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive)) + { + qWarning("Current language is unknown, reverting to default language!"); + this->currentLanguage(LAMEXP_DEFAULT_LANGID); + } } //////////////////////////////////////////////////////////// @@ -134,4 +144,4 @@ MAKE_OPTION3(soundsEnabled, true) MAKE_OPTION3(neroAacNotificationsEnabled, true) MAKE_OPTION3(wmaDecoderNotificationsEnabled, true) MAKE_OPTION3(dropBoxWidgetEnabled, true) -MAKE_OPTION2(currentLanguage, QString()); \ No newline at end of file +MAKE_OPTION2(currentLanguage, LAMEXP_DEFAULT_LANGID);