Moved translation support into MUtilities library + make clean-up of temporary files work again + various minor fixes.

This commit is contained in:
LoRd_MuldeR 2014-12-20 23:44:43 +01:00
parent feb7e8e03c
commit c435e4e1c1
49 changed files with 323 additions and 540 deletions

View File

@ -81,7 +81,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)\tmp\$(ProjectName);$(SolutionDir)\..\MUtilities\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\VisualLeakDetector\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONFIG_NAME=$(ConfigurationName);WIN32;_DEBUG;_CONSOLE;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
@ -89,6 +89,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<OpenMPSupport>false</OpenMPSupport>
<TreatWarningAsError>true</TreatWarningAsError>
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
</ClCompile>
<Link>
<AdditionalOptions>"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)</AdditionalOptions>

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_HI 1
#define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 9
#define VER_LAMEXP_BUILD 1639
#define VER_LAMEXP_PATCH 10
#define VER_LAMEXP_BUILD 1646
#define VER_LAMEXP_CONFG 1558
///////////////////////////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@
AACDecoder::AACDecoder(void)
:
m_binary(lamexp_tool_lookup("faad.exe"))
m_binary(lamexp_tools_lookup("faad.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
AC3Decoder::AC3Decoder(void)
:
m_binary(lamexp_tool_lookup("valdec.exe"))
m_binary(lamexp_tools_lookup("valdec.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
ADPCMDecoder::ADPCMDecoder(void)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
ALACDecoder::ALACDecoder(void)
:
m_binary(lamexp_tool_lookup("refalac.exe"))
m_binary(lamexp_tools_lookup("refalac.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
AvisynthDecoder::AvisynthDecoder(void)
:
m_binary(lamexp_tool_lookup("avs2wav.exe"))
m_binary(lamexp_tools_lookup("avs2wav.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
FLACDecoder::FLACDecoder(void)
:
m_binary(lamexp_tool_lookup("flac.exe"))
m_binary(lamexp_tools_lookup("flac.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
MACDecoder::MACDecoder(void)
:
m_binary(lamexp_tool_lookup("mac.exe"))
m_binary(lamexp_tools_lookup("mac.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
MP3Decoder::MP3Decoder(void)
:
m_binary(lamexp_tool_lookup("mpg123.exe"))
m_binary(lamexp_tools_lookup("mpg123.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
MusepackDecoder::MusepackDecoder(void)
:
m_binary(lamexp_tool_lookup("mpcdec.exe"))
m_binary(lamexp_tools_lookup("mpcdec.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -38,7 +38,7 @@ bool OpusDecoder::m_disableResampling = false;
OpusDecoder::OpusDecoder(void)
:
m_binary(lamexp_tool_lookup("opusdec.exe"))
m_binary(lamexp_tools_lookup("opusdec.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
ShortenDecoder::ShortenDecoder(void)
:
m_binary(lamexp_tool_lookup("shorten.exe"))
m_binary(lamexp_tools_lookup("shorten.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
SpeexDecoder::SpeexDecoder(void)
:
m_binary(lamexp_tool_lookup("speexdec.exe"))
m_binary(lamexp_tools_lookup("speexdec.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
TTADecoder::TTADecoder(void)
:
m_binary(lamexp_tool_lookup("tta.exe"))
m_binary(lamexp_tools_lookup("tta.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
VorbisDecoder::VorbisDecoder(void)
:
m_binary(lamexp_tool_lookup("oggdec.exe"))
m_binary(lamexp_tools_lookup("oggdec.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -37,7 +37,7 @@
WMADecoder::WMADecoder(void)
:
m_binary(lamexp_tool_lookup("wma2wav.exe"))
m_binary(lamexp_tools_lookup("wma2wav.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
WavPackDecoder::WavPackDecoder(void)
:
m_binary(lamexp_tool_lookup("wvunpack.exe"))
m_binary(lamexp_tools_lookup("wvunpack.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -915,8 +915,8 @@ QString AboutDialog::makeToolText(const QString &toolName, const QString &toolBi
if(!toolBin.isEmpty())
{
const unsigned int version = lamexp_tool_version(toolBin, &toolTag);
verStr = lamexp_version2string(toolVerFmt, version, tr("n/a"), &toolTag);
const unsigned int version = lamexp_tools_version(toolBin, &toolTag);
verStr = lamexp_version2string(toolVerFmt, version, tr("n/a"), toolTag);
}
toolText += QString("<li>%1<br>").arg(NOBR(QString("<b>%1 (%2)</b>").arg(toolName, verStr)));

View File

@ -52,6 +52,7 @@
#include <MUtils/GUI.h>
#include <MUtils/Exception.h>
#include <MUtils/Sound.h>
#include <MUtils/Translation.h>
#include <MUtils/Version.h>
//Qt includes
@ -601,19 +602,21 @@ MainWindow::MainWindow(MUtils::IPCChannel *const ipcChannel, FileListModel *cons
//Populate the language menu
m_languageActionGroup = new QActionGroup(this);
QStringList translations = lamexp_query_translations();
while(!translations.isEmpty())
QStringList translations;
if(MUtils::Translation::enumerate(translations) > 0)
{
for(QStringList::ConstIterator iter = translations.constBegin(); iter != translations.constEnd(); iter++)
{
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->setData(*iter);
currentLanguage->setText(MUtils::Translation::get_name(*iter));
currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(*iter)));
currentLanguage->setCheckable(true);
currentLanguage->setChecked(false);
m_languageActionGroup->addAction(currentLanguage);
ui->menuLanguage->insertAction(ui->actionLoadTranslationFromFile, currentLanguage);
}
}
ui->menuLanguage->insertSeparator(ui->actionLoadTranslationFromFile);
connect(ui->actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
@ -942,7 +945,7 @@ void MainWindow::initializeTranslation(void)
const QString qmFilePath = QFileInfo(m_settings->currentLanguageFile()).canonicalFilePath();
if((!qmFilePath.isEmpty()) && QFileInfo(qmFilePath).exists() && QFileInfo(qmFilePath).isFile() && (QFileInfo(qmFilePath).suffix().compare("qm", Qt::CaseInsensitive) == 0))
{
if(lamexp_install_translator_from_file(qmFilePath))
if(MUtils::Translation::install_translator_from_file(qmFilePath))
{
QList<QAction*> actions = m_languageActionGroup->actions();
while(!actions.isEmpty()) actions.takeFirst()->setChecked(false);
@ -975,7 +978,7 @@ void MainWindow::initializeTranslation(void)
while(!languageActions.isEmpty())
{
QAction *currentLanguage = languageActions.takeFirst();
if(currentLanguage->data().toString().compare(LAMEXP_DEFAULT_LANGID, Qt::CaseInsensitive) == 0)
if(currentLanguage->data().toString().compare(MUtils::Translation::DEFAULT_LANGID, Qt::CaseInsensitive) == 0)
{
currentLanguage->setChecked(true);
languageActionActivated(currentLanguage);
@ -1417,11 +1420,11 @@ void MainWindow::windowShown(void)
{
if(m_settings->neroAacNotificationsEnabled())
{
if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
if(lamexp_tools_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
{
QString messageText;
messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
messageText += NOBR(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac(), tr("n/a")), lamexp_version2string("?.?.?.?", lamexp_tool_version("neroAacEnc.exe"), tr("n/a")))).append("<br><br>");
messageText += NOBR(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac(), tr("n/a")), lamexp_version2string("?.?.?.?", lamexp_tools_version("neroAacEnc.exe"), tr("n/a")))).append("<br><br>");
messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br><br>";
messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
@ -1870,7 +1873,7 @@ void MainWindow::languageActionActivated(QAction *action)
{
QString langId = action->data().toString();
if(lamexp_install_translator(langId))
if(MUtils::Translation::install_translator(langId))
{
action->setChecked(true);
ui->actionLoadTranslationFromFile->setChecked(false);
@ -1893,7 +1896,7 @@ void MainWindow::languageFromFileActionActivated(bool checked)
{
QStringList selectedFiles = dialog.selectedFiles();
const QString qmFile = QFileInfo(selectedFiles.first()).canonicalFilePath();
if(lamexp_install_translator_from_file(qmFile))
if(MUtils::Translation::install_translator_from_file(qmFile))
{
QList<QAction*> actions = m_languageActionGroup->actions();
while(!actions.isEmpty())
@ -4012,7 +4015,7 @@ void MainWindow::customParamsHelpRequested(QWidget *obj, QEvent *event)
*/
void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QString &command)
{
const QString binary = lamexp_tool_lookup(toolName);
const QString binary = lamexp_tools_lookup(toolName);
if(binary.isEmpty())
{
MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);

View File

@ -82,10 +82,10 @@ UpdateDialog::UpdateDialog(const SettingsModel *const settings, QWidget *parent)
m_firstShow(true),
m_updateReadyToInstall(false),
m_updaterProcess(NULL),
m_binaryUpdater(lamexp_tool_lookup("wupdate.exe")),
m_binaryWGet(lamexp_tool_lookup("wget.exe")),
m_binaryGnuPG(lamexp_tool_lookup("gpgv.exe")),
m_binaryKeys(lamexp_tool_lookup("gpgv.gpg"))
m_binaryUpdater(lamexp_tools_lookup("wupdate.exe")),
m_binaryWGet(lamexp_tools_lookup("wget.exe")),
m_binaryGnuPG(lamexp_tools_lookup("gpgv.exe")),
m_binaryKeys(lamexp_tools_lookup("gpgv.gpg"))
{
if(m_binaryUpdater.isEmpty())
{

View File

@ -117,9 +117,9 @@ static const g_aacEncoderInfo;
AACEncoder::AACEncoder(void)
:
m_binary_enc(lamexp_tool_lookup("neroAacEnc.exe")),
m_binary_tag(lamexp_tool_lookup("neroAacTag.exe")),
m_binary_sox(lamexp_tool_lookup("sox.exe"))
m_binary_enc(lamexp_tools_lookup("neroAacEnc.exe")),
m_binary_tag(lamexp_tools_lookup("neroAacTag.exe")),
m_binary_sox(lamexp_tools_lookup("sox.exe"))
{
if(m_binary_enc.isEmpty() || m_binary_tag.isEmpty() || m_binary_sox.isEmpty())
{

View File

@ -120,8 +120,8 @@ static const g_fhgAacEncoderInfo;
FHGAACEncoder::FHGAACEncoder(void)
:
m_binary_enc(lamexp_tool_lookup("fhgaacenc.exe")),
m_binary_dll(lamexp_tool_lookup("enc_fhgaac.dll"))
m_binary_enc(lamexp_tools_lookup("fhgaacenc.exe")),
m_binary_dll(lamexp_tools_lookup("enc_fhgaac.dll"))
{
if(m_binary_enc.isEmpty() || m_binary_dll.isEmpty())
{

View File

@ -128,9 +128,9 @@ static const g_qaacEncoderInfo;
QAACEncoder::QAACEncoder(void)
:
m_binary_qaac(lamexp_tool_lookup("qaac.exe")),
m_binary_soxr(lamexp_tool_lookup("libsoxr.dll")),
m_binary_soxc(lamexp_tool_lookup("libsoxconvolver.dll"))
m_binary_qaac(lamexp_tools_lookup("qaac.exe")),
m_binary_soxr(lamexp_tools_lookup("libsoxr.dll")),
m_binary_soxc(lamexp_tools_lookup("libsoxconvolver.dll"))
{
if(m_binary_qaac.isEmpty() || m_binary_soxr.isEmpty() || m_binary_soxc.isEmpty())
{

View File

@ -116,7 +116,7 @@ static const g_aftenEncoderInfo;
AC3Encoder::AC3Encoder(void)
:
m_binary(lamexp_tool_lookup("aften.exe"))
m_binary(lamexp_tools_lookup("aften.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -118,7 +118,7 @@ static const g_dcaEncoderInfo;
DCAEncoder::DCAEncoder(void)
:
m_binary(lamexp_tool_lookup("dcaenc.exe"))
m_binary(lamexp_tools_lookup("dcaenc.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -112,7 +112,7 @@ static const g_flacEncoderInfo;
FLACEncoder::FLACEncoder(void)
:
m_binary(lamexp_tool_lookup("flac.exe"))
m_binary(lamexp_tools_lookup("flac.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -112,8 +112,8 @@ static const g_macEncoderInfo;
MACEncoder::MACEncoder(void)
:
m_binary_enc(lamexp_tool_lookup("mac.exe")),
m_binary_tag(lamexp_tool_lookup("tag.exe"))
m_binary_enc(lamexp_tools_lookup("mac.exe")),
m_binary_tag(lamexp_tools_lookup("tag.exe"))
{
if(m_binary_enc.isEmpty() || m_binary_tag.isEmpty())
{

View File

@ -117,7 +117,7 @@ static const g_mp3EncoderInfo;
MP3Encoder::MP3Encoder(void)
:
m_binary(lamexp_tool_lookup("lame.exe"))
m_binary(lamexp_tools_lookup("lame.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -107,7 +107,7 @@ static const g_opusEncoderInfo;
OpusEncoder::OpusEncoder(void)
:
m_binary(lamexp_tool_lookup("opusenc.exe"))
m_binary(lamexp_tools_lookup("opusenc.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -114,7 +114,7 @@ static const g_vorbisEncoderInfo;
VorbisEncoder::VorbisEncoder(void)
:
m_binary(lamexp_tool_lookup("oggenc2.exe"))
m_binary(lamexp_tools_lookup("oggenc2.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -37,7 +37,7 @@
DownmixFilter::DownmixFilter(void)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -35,7 +35,7 @@
NormalizeFilter::NormalizeFilter(int peakVolume, int equalizationMode)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -41,7 +41,7 @@ static __inline int multipleOf(int value, int base)
ResampleFilter::ResampleFilter(int samplingRate, int bitDepth)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -36,7 +36,7 @@
ToneAdjustFilter::ToneAdjustFilter(int bass, int treble)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -28,6 +28,7 @@
#include <cstdlib>
#include <QtGlobal>
#include <QString>
//Forward declarations
class QDate;
@ -35,36 +36,17 @@ class QStringList;
class QIcon;
class LockedFile;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL CONSTANTS
///////////////////////////////////////////////////////////////////////////////
extern const char* LAMEXP_DEFAULT_LANGID;
extern const char* LAMEXP_DEFAULT_TRANSLATION;
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
/*
* Translation Support
*/
QStringList lamexp_query_translations(void);
unsigned int lamexp_translation_country(const QString &langId);
bool lamexp_translation_init(void);
QString lamexp_translation_name(const QString &language);
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country);
unsigned int lamexp_translation_sysid(const QString &langId);
bool lamexp_install_translator(const QString &language);
bool lamexp_install_translator_from_file(const QString &qmFile);
/*
* Tools Support
*/
bool lamexp_tool_check (const QString &toolName);
const QString& lamexp_tool_lookup (const QString &toolName);
void lamexp_tool_register(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL);
unsigned int lamexp_tool_version (const QString &toolName, QString *tag = NULL);
void lamexp_tools_register(const QString &toolName, LockedFile *const file, const quint32 &version, const QString &tag = QString());
bool lamexp_tools_check (const QString &toolName);
const QString& lamexp_tools_lookup (const QString &toolName);
const quint32& lamexp_tools_version (const QString &toolName, QString *const tagOut = NULL);
/*
* Version getters
@ -76,13 +58,12 @@ unsigned int lamexp_version_confg (void);
const char* lamexp_version_release (void);
bool lamexp_version_portable (void);
bool lamexp_version_demo (void);
QDate& lamexp_version_expires (void);
const QDate& lamexp_version_expires (void);
unsigned int lamexp_toolver_neroaac (void);
unsigned int lamexp_toolver_fhgaacenc(void);
unsigned int lamexp_toolver_qaacenc (void);
unsigned int lamexp_toolver_coreaudio(void);
/*
* URL getters
*/
@ -95,12 +76,7 @@ const char *lamexp_tracker_url(void);
* Misc Functions
*/
const QIcon& lamexp_app_icon(void);
const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag = NULL);
/*
* Finalization
*/
void lamexp_finalization(void);
const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString &tag = QString());
///////////////////////////////////////////////////////////////////////////////
// HELPER MACROS

View File

@ -27,372 +27,147 @@
//Qt includes
#include <QApplication>
#include <QMap>
#include <QHash>
#include <QReadWriteLock>
#include <QReadLocker>
#include <QWriteLocker>
#include <QString>
#include <QStringList>
#include <QTranslator>
#include <QFileInfo>
#include <QPair>
//MUtils
#include <MUtils/Global.h>
#include <MUtils/Exception.h>
//CRT
#include <stdint.h>
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARS
///////////////////////////////////////////////////////////////////////////////
//Tools
static struct
{
QMap<QString, LockedFile*> *registry;
QMap<QString, unsigned int> *versions;
QMap<QString, QString> *tags;
QReadWriteLock lock;
}
g_lamexp_tools;
//Typedef
typedef QPair<quint32,QString> tool_info_t;
typedef QPair<LockedFile*, tool_info_t> tool_data_t;
typedef QHash<QString, tool_data_t> tool_hash_t;
//Supported languages
static struct
{
QMap<QString, QString> *files;
QMap<QString, QString> *names;
QMap<QString, unsigned int> *sysid;
QMap<QString, unsigned int> *cntry;
QReadWriteLock lock;
}
g_lamexp_translation;
//Translator
static struct
{
QTranslator *instance;
QReadWriteLock lock;
}
g_lamexp_currentTranslator;
//Tool registry
static QScopedPointer<tool_hash_t> g_lamexp_tools_data;
static QReadWriteLock g_lamexp_tools_lock;
//Null String
static const QString g_null;
static const QString g_null_string;
//UINT_MAX
static const quint32 g_max_uint32 = UINT32_MAX;
//Helper Macro
#define MAKE_ENTRY(LOCK_FILE,VER,TAG) \
qMakePair((LOCK_FILE),qMakePair((VER),(TAG)))
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
/*
* Clean-up *all* registered tools
*/
static void lamexp_tools_clean_up(void)
{
QWriteLocker writeLock(&g_lamexp_tools_lock);
if(!g_lamexp_tools_data.isNull())
{
const QStringList keys = g_lamexp_tools_data->keys();
for(QStringList::ConstIterator iter = keys.constBegin(); iter != keys.constEnd(); iter++)
{
tool_data_t currentTool = (*g_lamexp_tools_data)[*iter];
MUTILS_DELETE(currentTool.first);
}
g_lamexp_tools_data->clear();
}
}
/*
* Register tool
*/
void lamexp_tool_register(const QString &toolName, LockedFile *file, unsigned int version, const QString *tag)
void lamexp_tools_register(const QString &toolName, LockedFile *const file, const quint32 &version, const QString &tag)
{
QWriteLocker writeLock(&g_lamexp_tools.lock);
QWriteLocker writeLock(&g_lamexp_tools_lock);
if(!g_lamexp_tools.registry) g_lamexp_tools.registry = new QMap<QString, LockedFile*>();
if(!g_lamexp_tools.versions) g_lamexp_tools.versions = new QMap<QString, unsigned int>();
if(!g_lamexp_tools.tags) g_lamexp_tools.tags = new QMap<QString, QString>();
if(g_lamexp_tools_data.isNull())
{
g_lamexp_tools_data.reset(new tool_hash_t());
atexit(lamexp_tools_clean_up);
}
if(g_lamexp_tools.registry->contains(toolName.toLower()))
const QString key = toolName.simplified().toLower();
if(g_lamexp_tools_data->contains(key))
{
MUTILS_THROW("lamexp_register_tool: Tool is already registered!");
}
g_lamexp_tools.registry->insert(toolName.toLower(), file);
g_lamexp_tools.versions->insert(toolName.toLower(), version);
g_lamexp_tools.tags->insert(toolName.toLower(), (tag) ? (*tag) : QString());
g_lamexp_tools_data->insert(key, MAKE_ENTRY(file, version, tag));
}
/*
* Check for tool
*/
bool lamexp_tool_check(const QString &toolName)
bool lamexp_tools_check(const QString &toolName)
{
QReadLocker readLock(&g_lamexp_tools.lock);
return (g_lamexp_tools.registry) ? g_lamexp_tools.registry->contains(toolName.toLower()) : false;
QReadLocker readLock(&g_lamexp_tools_lock);
if(!g_lamexp_tools_data.isNull())
{
const QString key = toolName.simplified().toLower();
return g_lamexp_tools_data->contains(key);
}
return false;
}
/*
* Lookup tool path
*/
const QString &lamexp_tool_lookup(const QString &toolName)
const QString &lamexp_tools_lookup(const QString &toolName)
{
QReadLocker readLock(&g_lamexp_tools.lock);
QReadLocker readLock(&g_lamexp_tools_lock);
if(g_lamexp_tools.registry)
if(!g_lamexp_tools_data.isNull())
{
if(g_lamexp_tools.registry->contains(toolName.toLower()))
const QString key = toolName.simplified().toLower();
if(g_lamexp_tools_data->contains(key))
{
return g_lamexp_tools.registry->value(toolName.toLower())->filePath();
}
else
{
return g_null;
return (*g_lamexp_tools_data)[key].first->filePath();
}
}
else
{
return g_null;
}
return g_null_string;
}
/*
* Lookup tool version
*/
unsigned int lamexp_tool_version(const QString &toolName, QString *tag)
const quint32 &lamexp_tools_version(const QString &toolName, QString *const tagOut)
{
QReadLocker readLock(&g_lamexp_tools.lock);
if(tag) tag->clear();
QReadLocker readLock(&g_lamexp_tools_lock);
if(g_lamexp_tools.versions)
if(!g_lamexp_tools_data.isNull())
{
if(g_lamexp_tools.versions->contains(toolName.toLower()))
const QString key = toolName.simplified().toLower();
if(g_lamexp_tools_data->contains(key))
{
if(tag)
const tool_info_t &info = (*g_lamexp_tools_data)[key].second;
if(tagOut)
{
if(g_lamexp_tools.tags->contains(toolName.toLower())) *tag = g_lamexp_tools.tags->value(toolName.toLower());
*tagOut = info.second;
}
return g_lamexp_tools.versions->value(toolName.toLower());
}
else
{
return UINT_MAX;
}
}
else
{
return UINT_MAX;
return info.first;
}
}
/*
* Version number to human-readable string
*/
const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag)
if(tagOut)
{
if(version == UINT_MAX)
{
return defaultText;
tagOut->clear();
}
QString result = pattern;
const int digits = result.count(QChar(L'?'), Qt::CaseInsensitive);
if(digits < 1)
{
return result;
}
int pos = 0, index = -1;
const QString versionStr = QString().sprintf("%0*u", digits, version);
Q_ASSERT(versionStr.length() == digits);
while((index = result.indexOf(QChar(L'?'), Qt::CaseInsensitive)) >= 0)
{
result[index] = versionStr[pos++];
}
if(tag)
{
if((index = result.indexOf(QChar(L'#'), Qt::CaseInsensitive)) >= 0)
{
result.remove(index, 1).insert(index, (*tag));
}
}
return result;
}
/*
* Initialize translations and add default language
*/
bool lamexp_translation_init(void)
{
QWriteLocker writeLockTranslations(&g_lamexp_translation.lock);
if((!g_lamexp_translation.files) && (!g_lamexp_translation.names))
{
g_lamexp_translation.files = new QMap<QString, QString>();
g_lamexp_translation.names = new QMap<QString, QString>();
g_lamexp_translation.files->insert(LAMEXP_DEFAULT_LANGID, "");
g_lamexp_translation.names->insert(LAMEXP_DEFAULT_LANGID, "English");
return true;
}
else
{
qWarning("[lamexp_translation_init] Error: Already initialized!");
return false;
}
}
/*
* Register a new translation
*/
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country)
{
QWriteLocker writeLockTranslations(&g_lamexp_translation.lock);
if(qmFile.isEmpty() || langName.isEmpty() || systemId < 1)
{
return false;
}
if(!g_lamexp_translation.files) g_lamexp_translation.files = new QMap<QString, QString>();
if(!g_lamexp_translation.names) g_lamexp_translation.names = new QMap<QString, QString>();
if(!g_lamexp_translation.sysid) g_lamexp_translation.sysid = new QMap<QString, unsigned int>();
if(!g_lamexp_translation.cntry) g_lamexp_translation.cntry = new QMap<QString, unsigned int>();
g_lamexp_translation.files->insert(langId, qmFile);
g_lamexp_translation.names->insert(langId, langName);
g_lamexp_translation.sysid->insert(langId, systemId);
g_lamexp_translation.cntry->insert(langId, country);
return true;
}
/*
* Get list of all translations
*/
QStringList lamexp_query_translations(void)
{
QReadLocker readLockTranslations(&g_lamexp_translation.lock);
return (g_lamexp_translation.files) ? g_lamexp_translation.files->keys() : QStringList();
}
/*
* Get translation name
*/
QString lamexp_translation_name(const QString &langId)
{
QReadLocker readLockTranslations(&g_lamexp_translation.lock);
return (g_lamexp_translation.names) ? g_lamexp_translation.names->value(langId.toLower(), QString()) : QString();
}
/*
* Get translation system id
*/
unsigned int lamexp_translation_sysid(const QString &langId)
{
QReadLocker readLockTranslations(&g_lamexp_translation.lock);
return (g_lamexp_translation.sysid) ? g_lamexp_translation.sysid->value(langId.toLower(), 0) : 0;
}
/*
* Get translation script id
*/
unsigned int lamexp_translation_country(const QString &langId)
{
QReadLocker readLockTranslations(&g_lamexp_translation.lock);
return (g_lamexp_translation.cntry) ? g_lamexp_translation.cntry->value(langId.toLower(), 0) : 0;
}
/*
* Install a new translator
*/
bool lamexp_install_translator(const QString &langId)
{
bool success = false;
const QString qmFileToPath(":/localization/%1");
if(langId.isEmpty() || langId.toLower().compare(LAMEXP_DEFAULT_LANGID) == 0)
{
success = lamexp_install_translator_from_file(qmFileToPath.arg(LAMEXP_DEFAULT_TRANSLATION));
}
else
{
QReadLocker readLock(&g_lamexp_translation.lock);
QString qmFile = (g_lamexp_translation.files) ? g_lamexp_translation.files->value(langId.toLower(), QString()) : QString();
readLock.unlock();
if(!qmFile.isEmpty())
{
success = lamexp_install_translator_from_file(qmFileToPath.arg(qmFile));
}
else
{
qWarning("Translation '%s' not available!", langId.toLatin1().constData());
}
}
return success;
}
/*
* Install a new translator from file
*/
bool lamexp_install_translator_from_file(const QString &qmFile)
{
QWriteLocker writeLock(&g_lamexp_currentTranslator.lock);
bool success = false;
if(!g_lamexp_currentTranslator.instance)
{
g_lamexp_currentTranslator.instance = new QTranslator();
}
if(!qmFile.isEmpty())
{
QString qmPath = QFileInfo(qmFile).canonicalFilePath();
QApplication::removeTranslator(g_lamexp_currentTranslator.instance);
if(success = g_lamexp_currentTranslator.instance->load(qmPath))
{
QApplication::installTranslator(g_lamexp_currentTranslator.instance);
}
else
{
qWarning("Failed to load translation:\n\"%s\"", qmPath.toLatin1().constData());
}
}
else
{
QApplication::removeTranslator(g_lamexp_currentTranslator.instance);
success = true;
}
return success;
}
///////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
///////////////////////////////////////////////////////////////////////////////
extern "C" void _lamexp_global_init_tools(void)
{
MUTILS_ZERO_MEMORY(g_lamexp_tools);
MUTILS_ZERO_MEMORY(g_lamexp_currentTranslator);
MUTILS_ZERO_MEMORY(g_lamexp_translation);
}
///////////////////////////////////////////////////////////////////////////////
// FINALIZATION
///////////////////////////////////////////////////////////////////////////////
extern "C" void _lamexp_global_free_tools(void)
{
//Free *all* registered translations
if(g_lamexp_currentTranslator.instance)
{
QApplication::removeTranslator(g_lamexp_currentTranslator.instance);
MUTILS_DELETE(g_lamexp_currentTranslator.instance);
}
MUTILS_DELETE(g_lamexp_translation.files);
MUTILS_DELETE(g_lamexp_translation.names);
MUTILS_DELETE(g_lamexp_translation.cntry);
MUTILS_DELETE(g_lamexp_translation.sysid);
//Free *all* registered tools
if(g_lamexp_tools.registry)
{
QStringList keys = g_lamexp_tools.registry->keys();
for(int i = 0; i < keys.count(); i++)
{
LockedFile *lf = g_lamexp_tools.registry->take(keys.at(i));
MUTILS_DELETE(lf);
}
g_lamexp_tools.registry->clear();
g_lamexp_tools.versions->clear();
g_lamexp_tools.tags->clear();
}
MUTILS_DELETE(g_lamexp_tools.registry);
MUTILS_DELETE(g_lamexp_tools.versions);
MUTILS_DELETE(g_lamexp_tools.tags);
return g_max_uint32;
}

View File

@ -151,3 +151,41 @@ const QIcon &lamexp_app_icon(void)
return *g_lamexp_icon_data;
}
/*
* Version number to human-readable string
*/
const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString &tag)
{
if(version == UINT_MAX)
{
return defaultText;
}
QString result = pattern;
const int digits = result.count(QChar(L'?'), Qt::CaseInsensitive);
if(digits < 1)
{
return result;
}
int pos = 0, index = -1;
const QString versionStr = QString().sprintf("%0*u", digits, version);
Q_ASSERT(versionStr.length() == digits);
while((index = result.indexOf(QChar(L'?'), Qt::CaseInsensitive)) >= 0)
{
result[index] = versionStr[pos++];
}
if(!tag.isEmpty())
{
if((index = result.indexOf(QChar(L'#'), Qt::CaseInsensitive)) >= 0)
{
result.remove(index, 1).insert(index, tag);
}
}
return result;
}

View File

@ -23,7 +23,7 @@
#include "Global.h"
//LameXP includes
#define LAMEXP_INC_CONFIG
#define LAMEXP_INC_CONFIG 1
#include "Resource.h"
#include "Config.h"
@ -121,7 +121,7 @@ bool lamexp_version_demo(void)
/*
* Calculate expiration date
*/
QDate &lamexp_version_expires(void)
const QDate &lamexp_version_expires(void)
{
QReadLocker readLock(&g_lamexp_version_lock);

View File

@ -39,10 +39,6 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#endif
#endif
//Localization
const char* LAMEXP_DEFAULT_LANGID = "en";
const char* LAMEXP_DEFAULT_TRANSLATION = "LameXP_EN.qm";
///////////////////////////////////////////////////////////////////////////////
// GLOBAL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
@ -70,14 +66,11 @@ static size_t lamexp_entry_check(void)
extern "C"
{
int mainCRTStartup(void);
void _lamexp_global_init_tools(void);
void _lamexp_global_free_tools(void);
}
/*
* Application entry point (runs before static initializers)
*/
extern "C" int lamexp_entry_point(void)
{
if(g_lamexp_entry_check_flag != 0x789E09B2)
@ -85,23 +78,9 @@ extern "C" int lamexp_entry_point(void)
MUtils::OS::fatal_exit(L"Application initialization has failed, take care!");
}
//Call global initialization functions
_lamexp_global_init_tools();
//Make sure we will pass the check
g_lamexp_entry_check_flag = (~g_lamexp_entry_check_flag);
//Now initialize the C Runtime library!
return mainCRTStartup();
}
/*
* Application finalization function
*/
void lamexp_finalization(void)
{
qDebug("lamexp_finalization()");
//Call global finalization functions, in proper order
_lamexp_global_free_tools();
}

View File

@ -48,6 +48,11 @@
#include <QMutex>
#include <QDir>
//VLD
#ifdef _MSC_VER
#include <vld.h>
#endif
///////////////////////////////////////////////////////////////////////////////
// Helper functions
///////////////////////////////////////////////////////////////////////////////
@ -114,13 +119,24 @@ static void lamexp_show_splash(const MUtils::CPUFetaures::cpu_info_t &cpuFeature
settingsModel->slowStartup(poInitializationThread->getSlowIndicator());
}
static int lamexp_main_loop_helper(MUtils::IPCChannel *const ipcChannel, FileListModel *const fileListModel, AudioFileModel_MetaInfo *const metaInfo, SettingsModel *const settingsModel, int &iShutdown)
static int lamexp_main_loop(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures, MUtils::IPCChannel *const ipcChannel, int &iShutdown)
{
int iResult = -1;
bool bAccepted = true;
//Create models
QScopedPointer<FileListModel> fileListModel(new FileListModel() );
QScopedPointer<AudioFileModel_MetaInfo> metaInfo (new AudioFileModel_MetaInfo());
QScopedPointer<SettingsModel> settingsModel(new SettingsModel() );
//Show splash screen
lamexp_show_splash(cpuFeatures, settingsModel.data());
//Validate settings
settingsModel->validate();
//Create main window
QScopedPointer<MainWindow> poMainWindow(new MainWindow(ipcChannel, fileListModel, metaInfo, settingsModel));
QScopedPointer<MainWindow> poMainWindow(new MainWindow(ipcChannel, fileListModel.data(), metaInfo.data(), settingsModel.data()));
//Main application loop
while(bAccepted && (iShutdown <= SHUTDOWN_FLAG_NONE))
@ -136,7 +152,7 @@ static int lamexp_main_loop_helper(MUtils::IPCChannel *const ipcChannel, FileLis
//Show processing dialog
if(bAccepted && (fileListModel->rowCount() > 0))
{
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel.data(), metaInfo.data(), settingsModel.data());
processingDialog->exec();
iShutdown = processingDialog->getShutdownFlag();
MUTILS_DELETE(processingDialog);
@ -146,23 +162,6 @@ static int lamexp_main_loop_helper(MUtils::IPCChannel *const ipcChannel, FileLis
return iResult;
}
static int lamexp_main_loop(const MUtils::CPUFetaures::cpu_info_t &cpuFeatures, MUtils::IPCChannel *const ipcChannel, int &iShutdown)
{
//Create models
QScopedPointer<FileListModel> fileListModel(new FileListModel() );
QScopedPointer<AudioFileModel_MetaInfo> metaInfo (new AudioFileModel_MetaInfo());
QScopedPointer<SettingsModel> settingsModel(new SettingsModel() );
//Show splash screen
lamexp_show_splash(cpuFeatures, settingsModel.data());
//Validate settings
settingsModel->validate();
//Main processing loop
return lamexp_main_loop_helper(ipcChannel, fileListModel.data(), metaInfo.data(), settingsModel.data(), iShutdown);
}
///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////
@ -195,18 +194,15 @@ static int lamexp_main(int &argc, char **argv)
qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
//Initialize Qt
if(!MUtils::Startup::init_qt(argc, argv, QLatin1String("LameXP - Audio Encoder Front-End")))
QScopedPointer<QApplication> application(MUtils::Startup::create_qt(argc, argv, QLatin1String("LameXP - Audio Encoder Front-End")));
if(application.isNull())
{
lamexp_finalization();
return EXIT_FAILURE;
}
//Initialize application
qApp->setWindowIcon(lamexp_app_icon());
qApp->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
//Add the default translations
lamexp_translation_init();
application->setWindowIcon(lamexp_app_icon());
application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
//Check for expiration
if(lamexp_version_demo())
@ -231,7 +227,6 @@ static int lamexp_main(int &argc, char **argv)
{
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
{
lamexp_finalization();
return EXIT_SUCCESS;
}
}
@ -258,7 +253,6 @@ static int lamexp_main(int &argc, char **argv)
}
//Terminate
lamexp_finalization();
return iResult;
}

View File

@ -28,6 +28,7 @@
//MUtils
#include <MUtils/Global.h>
#include <MUtils/Translation.h>
#include <MUtils/OSSupport.h>
//Qt
@ -54,26 +55,22 @@
class SettingsCache
{
public:
SettingsCache(QSettings *configFile) : m_configFile(configFile)
SettingsCache(QSettings *configFile)
:
m_configFile(configFile),
m_cache(new cache_data_t()),
m_cacheDirty(new string_set_t())
{
m_cache = new QHash<QString, QVariant>();
m_cacheLock = new QMutex();
m_cacheDirty = new QSet<QString>();
}
~SettingsCache(void)
{
flushValues();
MUTILS_DELETE(m_cache);
MUTILS_DELETE(m_cacheDirty);
MUTILS_DELETE(m_cacheLock);
MUTILS_DELETE(m_configFile);
}
inline void storeValue(const QString &key, const QVariant &value)
{
QMutexLocker lock(m_cacheLock);
QWriteLocker writeLock(&m_cacheLock);
if(!m_cache->contains(key))
{
@ -92,7 +89,15 @@ public:
inline QVariant loadValue(const QString &key, const QVariant &defaultValue) const
{
QMutexLocker lock(m_cacheLock);
QReadLocker readLock(&m_cacheLock);
if(m_cache->contains(key))
{
return m_cache->value(key, defaultValue);
}
readLock.unlock();
QWriteLocker writeLock(&m_cacheLock);
if(!m_cache->contains(key))
{
@ -105,7 +110,7 @@ public:
inline void flushValues(void)
{
QMutexLocker lock(m_cacheLock);
QWriteLocker writeLock(&m_cacheLock);
if(!m_cacheDirty->isEmpty())
{
@ -127,10 +132,14 @@ public:
}
private:
QSettings *m_configFile;
QHash<QString, QVariant> *m_cache;
QSet<QString> *m_cacheDirty;
QMutex *m_cacheLock;
typedef QSet<QString> string_set_t;
typedef QHash<QString, QVariant> cache_data_t;
QScopedPointer<QSettings> m_configFile;
QScopedPointer<cache_data_t> m_cache;
QScopedPointer<string_set_t> m_cacheDirty;
mutable QReadWriteLock m_cacheLock;
};
////////////////////////////////////////////////////////////
@ -277,13 +286,13 @@ LAMEXP_MAKE_ID(writeMetaTags, "Flags/WriteMetaTags");
//LUT
const int SettingsModel::samplingRates[8] = {0, 16000, 22050, 24000, 32000, 44100, 48000, -1};
static QReadWriteLock s_lock;
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
SettingsModel::SettingsModel(void)
:
m_configCache(NULL)
{
QString configPath = "LameXP.ini";
@ -357,7 +366,6 @@ SettingsModel::SettingsModel(void)
SettingsModel::~SettingsModel(void)
{
MUTILS_DELETE(m_configCache);
MUTILS_DELETE(m_defaultLanguage);
}
////////////////////////////////////////////////////////////
@ -417,11 +425,15 @@ void SettingsModel::validate(void)
}
}
if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
QStringList translations;
if(MUtils::Translation::enumerate(translations) > 0)
{
if(!translations.contains(this->currentLanguage(), Qt::CaseInsensitive))
{
qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
this->currentLanguage(defaultLanguage());
}
}
if(this->hibernateComputer())
{
@ -435,7 +447,6 @@ void SettingsModel::validate(void)
{
this->overwriteMode(SettingsModel::Overwrite_KeepBoth);
}
}
void SettingsModel::syncNow(void)
@ -447,24 +458,12 @@ void SettingsModel::syncNow(void)
// Private Functions
////////////////////////////////////////////////////////////
QString *SettingsModel::m_defaultLanguage = NULL;
QString SettingsModel::defaultLanguage(void) const
{
QReadLocker readLock(&s_lock);
QMutexLocker lock(&m_defaultLangLock);
//Default already initialized?
if(m_defaultLanguage)
{
return *m_defaultLanguage;
}
//Acquire write lock now
readLock.unlock();
QWriteLocker writeLock(&s_lock);
//Default still not initialized?
if(m_defaultLanguage)
if(!m_defaultLanguage.isNull())
{
return *m_defaultLanguage;
}
@ -479,40 +478,40 @@ QString SettingsModel::defaultLanguage(void) const
//Check if we can use the default translation
if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/)
{
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
return LAMEXP_DEFAULT_LANGID;
m_defaultLanguage.reset(new QString(MUtils::Translation::DEFAULT_LANGID));
return MUtils::Translation::DEFAULT_LANGID;
}
QStringList languages;
if(MUtils::Translation::enumerate(languages) > 0)
{
//Try to find a suitable translation for the user's system language *and* country
QStringList languages = lamexp_query_translations();
while(!languages.isEmpty())
for(QStringList::ConstIterator iter = languages.constBegin(); iter != languages.constEnd(); iter++)
{
QString currentLangId = languages.takeFirst();
if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
if(MUtils::Translation::get_sysid(*iter) == systemLanguage.language())
{
if(lamexp_translation_country(currentLangId) == systemLanguage.country())
if(MUtils::Translation::get_country(*iter) == systemLanguage.country())
{
m_defaultLanguage = new QString(currentLangId);
return currentLangId;
m_defaultLanguage.reset(new QString(*iter));
return (*iter);
}
}
}
//Try to find a suitable translation for the user's system language
languages = lamexp_query_translations();
while(!languages.isEmpty())
for(QStringList::ConstIterator iter = languages.constBegin(); iter != languages.constEnd(); iter++)
{
QString currentLangId = languages.takeFirst();
if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
if(MUtils::Translation::get_sysid(*iter) == systemLanguage.language())
{
m_defaultLanguage = new QString(currentLangId);
return currentLangId;
m_defaultLanguage.reset(new QString(*iter));
return (*iter);
}
}
}
//Fall back to the default translation
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
return LAMEXP_DEFAULT_LANGID;
m_defaultLanguage.reset(new QString(MUtils::Translation::DEFAULT_LANGID));
return MUtils::Translation::DEFAULT_LANGID;
}
QString SettingsModel::defaultDirectory(void) const

View File

@ -22,6 +22,9 @@
#pragma once
#include <QMutex>
#include <QScopedPointer>
class QString;
class SettingsCache;
@ -201,13 +204,17 @@ public:
void syncNow(void);
private:
SettingsCache *m_configCache;
SettingsModel(const SettingsModel &other) {}
SettingsModel &operator=(const SettingsModel &other) { return *this; }
QString initDirectory(const QString &path) const;
QString defaultLanguage(void) const;
QString defaultDirectory(void) const;
static QString *m_defaultLanguage;
SettingsCache *m_configCache;
mutable QMutex m_defaultLangLock;
mutable QScopedPointer<QString> m_defaultLanguage;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -476,15 +476,15 @@ void EncoderRegistry::resetAllEncoders(SettingsModel *settings)
int EncoderRegistry::getAacEncoder(void)
{
if(lamexp_tool_check("qaac.exe") && lamexp_tool_check("libsoxr.dll") && lamexp_tool_check("libsoxconvolver.dll"))
if(lamexp_tools_check("qaac.exe") && lamexp_tools_check("libsoxr.dll") && lamexp_tools_check("libsoxconvolver.dll"))
{
return SettingsModel::AAC_ENCODER_QAAC;
}
else if(lamexp_tool_check("fhgaacenc.exe") && lamexp_tool_check("enc_fhgaac.dll") && lamexp_tool_check("nsutil.dll") && lamexp_tool_check("libmp4v2.dll"))
else if(lamexp_tools_check("fhgaacenc.exe") && lamexp_tools_check("enc_fhgaac.dll") && lamexp_tools_check("nsutil.dll") && lamexp_tools_check("libmp4v2.dll"))
{
return SettingsModel::AAC_ENCODER_FHG;
}
else if(lamexp_tool_check("neroAacEnc.exe") && lamexp_tool_check("neroAacDec.exe") && lamexp_tool_check("neroAacTag.exe"))
else if(lamexp_tools_check("neroAacEnc.exe") && lamexp_tools_check("neroAacDec.exe") && lamexp_tools_check("neroAacTag.exe"))
{
return SettingsModel::AAC_ENCODER_NERO;
}

View File

@ -56,7 +56,7 @@ CueSplitter::CueSplitter(const QString &outputDir, const QString &baseName, CueS
m_model(model),
m_outputDir(outputDir),
m_baseName(baseName),
m_soxBin(lamexp_tool_lookup("sox.exe"))
m_soxBin(lamexp_tools_lookup("sox.exe"))
{
if(m_soxBin.isEmpty())
{

View File

@ -63,8 +63,8 @@ AnalyzeTask::AnalyzeTask(const int taskId, const QString &inputFile, const QStri
m_taskId(taskId),
m_inputFile(inputFile),
m_templateFile(templateFile),
m_mediaInfoBin(lamexp_tool_lookup("mediainfo.exe")),
m_avs2wavBin(lamexp_tool_lookup("avs2wav.exe")),
m_mediaInfoBin(lamexp_tools_lookup("mediainfo.exe")),
m_avs2wavBin(lamexp_tools_lookup("avs2wav.exe")),
m_abortFlag(abortFlag)
{
if(m_mediaInfoBin.isEmpty() || m_avs2wavBin.isEmpty())

View File

@ -23,13 +23,15 @@
#include "Thread_Initialization.h"
//Internal
#include "LockedFile.h"
#define LAMEXP_INC_TOOLS 1
#include "Tools.h"
#include "LockedFile.h"
#include "Tool_Abstract.h"
//MUtils
#include <MUtils/Global.h>
#include <MUtils/OSSupport.h>
#include <MUtils/Translation.h>
#include <MUtils/Exception.h>
//Qt
@ -183,7 +185,7 @@ protected:
if(lockedFile)
{
lamexp_tool_register(toolShortName, lockedFile, version, &m_toolTag);
lamexp_tools_register(toolShortName, lockedFile, version, m_toolTag);
}
}
@ -483,7 +485,8 @@ void InitializationThread::delay(void)
void InitializationThread::initTranslations(void)
{
//Search for language files
QStringList qmFiles = QDir(":/localization").entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
const QDir qmDirectory(":/localization");
const QStringList qmFiles = qmDirectory.entryList(QStringList() << "LameXP_??.qm", QDir::Files, QDir::Name);
//Make sure we found at least one translation
if(qmFiles.count() < 1)
@ -492,27 +495,31 @@ void InitializationThread::initTranslations(void)
return;
}
//Initialize variables
const QString langResTemplate(":/localization/%1.txt");
QRegExp langIdExp("^LameXP_(\\w\\w)\\.qm$", Qt::CaseInsensitive);
//Add all available translations
while(!qmFiles.isEmpty())
for(QStringList::ConstIterator iter = qmFiles.constBegin(); iter != qmFiles.constEnd(); iter++)
{
const QString langFile = qmDirectory.absoluteFilePath(*iter);
QString langId, langName;
unsigned int systemId = 0, country = 0;
QString qmFile = qmFiles.takeFirst();
QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive);
if(langIdExp.indexIn(qmFile) >= 0)
if(QFileInfo(langFile).isFile() && (langIdExp.indexIn(*iter) >= 0))
{
langId = langIdExp.cap(1).toLower();
QResource langRes = QResource(QString(":/localization/%1.txt").arg(qmFile));
QResource langRes = QResource(langResTemplate.arg(*iter));
if(langRes.isValid() && langRes.size() > 0)
{
QByteArray data = QByteArray::fromRawData(reinterpret_cast<const char*>(langRes.data()), langRes.size());
QTextStream stream(&data, QIODevice::ReadOnly);
stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8");
while(!stream.atEnd())
while(!(stream.atEnd() || (stream.status() != QTextStream::Ok)))
{
QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts);
if(langInfo.count() == 3)
if(langInfo.count() >= 3)
{
systemId = langInfo.at(0).trimmed().toUInt();
country = langInfo.at(1).trimmed().toUInt();
@ -523,15 +530,15 @@ void InitializationThread::initTranslations(void)
}
}
if(!(langId.isEmpty() || langName.isEmpty() || systemId == 0))
if(!(langId.isEmpty() || langName.isEmpty() || (systemId == 0)))
{
if(lamexp_translation_register(langId, qmFile, langName, systemId, country))
if(MUtils::Translation::insert(langId, langFile, langName, systemId, country))
{
qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(qmFile), MUTILS_UTF8(langName), systemId, country);
qDebug("Registering translation: %s = %s (%u) [%u]", MUTILS_UTF8(*iter), MUTILS_UTF8(langName), systemId, country);
}
else
{
qWarning("Failed to register: %s", qmFile.toLatin1().constData());
qWarning("Failed to register: %s", langFile.toLatin1().constData());
}
}
}
@ -647,7 +654,7 @@ void InitializationThread::initNeroAac(void)
for(int i = 0; i < 3; i++)
{
lamexp_tool_register(neroFileInfo[i].fileName(), neroBin[i], neroVersion);
lamexp_tools_register(neroFileInfo[i].fileName(), neroBin[i], neroVersion);
}
}
@ -755,7 +762,7 @@ void InitializationThread::initFhgAac(void)
for(int i = 0; i < 5; i++)
{
lamexp_tool_register(fhgFileInfo[i].fileName(), fhgBin[i], fhgVersion);
lamexp_tools_register(fhgFileInfo[i].fileName(), fhgBin[i], fhgVersion);
}
}
@ -909,10 +916,10 @@ void InitializationThread::initQAac(void)
return;
}
lamexp_tool_register(qaacFileInfo[0].fileName(), qaacBin[0], qaacVersion);
lamexp_tool_register(qaacFileInfo[1].fileName(), qaacBin[1], qaacVersion);
lamexp_tool_register(qaacFileInfo[2].fileName(), qaacBin[2], qaacVersion);
lamexp_tool_register(qaacFileInfo[3].fileName(), qaacBin[3], qaacVersion);
lamexp_tools_register(qaacFileInfo[0].fileName(), qaacBin[0], qaacVersion);
lamexp_tools_register(qaacFileInfo[1].fileName(), qaacBin[1], qaacVersion);
lamexp_tools_register(qaacFileInfo[2].fileName(), qaacBin[2], qaacVersion);
lamexp_tools_register(qaacFileInfo[3].fileName(), qaacBin[3], qaacVersion);
}
void InitializationThread::selfTest(void)

View File

@ -35,7 +35,7 @@
WaveProperties::WaveProperties(void)
:
m_binary(lamexp_tool_lookup("sox.exe"))
m_binary(lamexp_tools_lookup("sox.exe"))
{
if(m_binary.isEmpty())
{

View File

@ -22,6 +22,10 @@
#include <stdlib.h>
#ifndef LAMEXP_INC_TOOLS
#error Please do *not* include TOOLS.H directly!
#endif
////////////////////////////////////////////////////////////
// CPU FLags
////////////////////////////////////////////////////////////