From efc0765dea4b2e0b6b4fed5105ea33dcb054a6ac Mon Sep 17 00:00:00 2001 From: lordmulder Date: Tue, 4 Jan 2011 19:58:18 +0100 Subject: [PATCH] Move language file initialization to InitializationThread. --- src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 2 + src/Global.cpp | 72 ++++++++++++----------------------- src/Global.h | 3 +- src/Thread_Initialization.cpp | 57 ++++++++++++++++++++++++++- src/Thread_Initialization.h | 1 + 6 files changed, 85 insertions(+), 52 deletions(-) diff --git a/src/Config.h b/src/Config.h index 6e7b1b46..2ed971e2 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 215 +#define VER_LAMEXP_BUILD 217 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 08d29f51..527aee6a 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -446,6 +446,8 @@ void MainWindow::changeEvent(QEvent *e) m_previewContextAction->setText(tr("Open File in External Application")); m_findFileContextAction->setText(tr("Browse File Location")); m_showFolderContextAction->setText(tr("Browse Selected Folder")); + + m_metaInfoModel->clearData(); } } diff --git a/src/Global.cpp b/src/Global.cpp index 4c8ad3c9..2f2c2de5 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -123,7 +123,7 @@ static QMap g_lamexp_tool_versions; //Languages static QMap g_lamexp_translation_files; static QMap g_lamexp_translation_names; -static QMap g_lamexp_translation_sysid; +static QMap g_lamexp_translation_sysid; static QTranslator *g_lamexp_currentTranslator = NULL; //Shared memory @@ -461,51 +461,6 @@ 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; - WORD systemId = 0; - QString qmFile = qmFiles.takeFirst(); - - QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive); - if(langIdExp.indexIn(qmFile) >= 0) - { - langId = langIdExp.cap(1).toLower(); - } - - QResource langRes = (QString(":/localization/%1.txt").arg(qmFile)); - if(langRes.isValid() && langRes.size() > 0) - { - QStringList langInfo = QString::fromUtf8(reinterpret_cast(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts); - if(langInfo.count() == 2) - { - systemId = langInfo.at(0).toUInt(); - langName = langInfo.at(1); - } - } - - if(!langId.isEmpty() && systemId > 0 && !langName.isEmpty()) - { - g_lamexp_translation_files.insert(langId, qmFile); - g_lamexp_translation_names.insert(langId, langName); - g_lamexp_translation_sysid.insert(langId, systemId); - } - } -} - /* * Initialize Qt framework */ @@ -578,8 +533,12 @@ bool lamexp_init_qt(int argc, char* argv[]) } } + //Add default translations + g_lamexp_translation_files.insert(LAMEXP_DEFAULT_LANGID, ""); + g_lamexp_translation_names.insert(LAMEXP_DEFAULT_LANGID, "English"); + //Init language files - lamexp_init_translations(); + //lamexp_init_translations(); //Check for process elevation if(!lamexp_check_elevation()) @@ -910,6 +869,23 @@ const QString lamexp_version2string(const QString &pattern, unsigned int version return result; } +/* + * Register a new translation + */ +bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId) +{ + if(qmFile.isEmpty() || langName.isEmpty() || systemId < 1) + { + return false; + } + + g_lamexp_translation_files.insert(langId, qmFile); + g_lamexp_translation_names.insert(langId, langName); + g_lamexp_translation_sysid.insert(langId, systemId); + + return true; +} + /* * Get list of all translations */ @@ -929,7 +905,7 @@ QString lamexp_translation_name(const QString &langId) /* * Get translation system id */ -WORD lamexp_translation_sysid(const QString &langId) +unsigned int lamexp_translation_sysid(const QString &langId) { return g_lamexp_translation_sysid.value(langId.toLower(), 0); } diff --git a/src/Global.h b/src/Global.h index 926f9bf9..0379fbc6 100644 --- a/src/Global.h +++ b/src/Global.h @@ -94,8 +94,9 @@ lamexp_cpu_t lamexp_detect_cpu_features(void); //Translation support QStringList lamexp_query_translations(void); +bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId); QString lamexp_translation_name(const QString &language); -WORD lamexp_translation_sysid(const QString &langId); +unsigned int lamexp_translation_sysid(const QString &langId); bool lamexp_install_translator(const QString &language); static const char* LAMEXP_DEFAULT_LANGID = "en"; diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index e2a673e9..644abae6 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -54,8 +55,8 @@ static const struct lamexp_tool_t g_lamexp_tools[] = {"d837bf6ee4dab557d8b02d46c75a24e58980fffa", "gpgv.gpg", UINT_MAX}, {"143fc001a2f6c56fe1b9e6f8a2eb2b53b9e1e504", "lame.exe", 39910}, {"775b260b3f64101beaeb317b74746f9bccdab842", "MAC.exe", UINT_MAX}, - {"7ea28a2ff8aa6ec2f0a8d59600519b696e915946", "mediainfo_i386.exe", 739}, - {"91d3247fa75be2efb532a0711966057684532235", "mediainfo_x64.exe", 739}, + {"61d584ffaf428e9afb0ed9bd32706a954af492b0", "mediainfo_i386.exe", 739}, + {"81fb728cbc6057906fa1b637738e6aefe5dccf54", "mediainfo_x64.exe", 739}, {"55c293a80475f7aeccf449ac9487a4626e5139cb", "mpcdec.exe", UINT_MAX}, {"8bbf4a3fffe2ff143eb5ba2cf82ca16d676e865d", "mpg123.exe", UINT_MAX}, {"8dd7138714c3bcb39f5a3213413addba13d06f1e", "oggdec.exe", UINT_MAX}, @@ -150,6 +151,9 @@ void InitializationThread::run() qDebug("All extracted.\n"); + //Register all translations + initTranslations(); + //Look for Nero encoder initNeroAac(); @@ -178,6 +182,55 @@ void InitializationThread::delay(void) printf("Done\n\n"); } +void InitializationThread::initTranslations(void) +{ + //Search for language files + QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name); + + //Make sure we found at least one translation + if(qmFiles.count() < 1) + { + qFatal("Could not find any translation files!"); + return; + } + + //Add all available translations + while(!qmFiles.isEmpty()) + { + QString langId, langName; + unsigned int systemId = 0; + QString qmFile = qmFiles.takeFirst(); + + QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive); + if(langIdExp.indexIn(qmFile) >= 0) + { + langId = langIdExp.cap(1).toLower(); + } + + QResource langRes = (QString(":/localization/%1.txt").arg(qmFile)); + if(langRes.isValid() && langRes.size() > 0) + { + QStringList langInfo = QString::fromUtf8(reinterpret_cast(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts); + if(langInfo.count() == 2) + { + systemId = langInfo.at(0).toUInt(); + langName = langInfo.at(1); + } + } + + if(lamexp_translation_register(langId, qmFile, langName, systemId)) + { + qDebug("Registering translation: %s = %s (%u)", qmFile.toLatin1().constData(), langName.toLatin1().constData(), systemId); + } + else + { + qWarning("Failed to register: %s", qmFile.toLatin1().constData()); + } + } + + qDebug("All registered.\n"); +} + void InitializationThread::initNeroAac(void) { QFileInfo neroFileInfo[3]; diff --git a/src/Thread_Initialization.h b/src/Thread_Initialization.h index c66a840b..b109774e 100644 --- a/src/Thread_Initialization.h +++ b/src/Thread_Initialization.h @@ -38,6 +38,7 @@ public: private: void delay(void); + void initTranslations(void); void initNeroAac(void); void initWmaDec(void);