If a QM file is used instead of a built-in translation, the QM file will now be remembered. Also the translation system can now be re-initialized by pressing CTRL+F5 in the Main window.

This commit is contained in:
LoRd_MuldeR 2012-10-14 22:21:57 +02:00
parent b653702f46
commit 4ed70b7bea
6 changed files with 110 additions and 49 deletions

View File

@ -1398,7 +1398,7 @@
<x>0</x>
<y>0</y>
<width>607</width>
<height>1677</height>
<height>1668</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_22">
@ -4385,6 +4385,9 @@
</property>
</action>
<action name="actionLoadTranslationFromFile">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../res/Icons.qrc">
<normaloff>:/icons/folder_page.png</normaloff>:/icons/folder_page.png</iconset>

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 2
#define VER_LAMEXP_BUILD 1145
#define VER_LAMEXP_BUILD 1148
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)

View File

@ -503,12 +503,14 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
currentLanguage->setText(lamexp_translation_name(langId));
currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId)));
currentLanguage->setCheckable(true);
currentLanguage->setChecked(false);
m_languageActionGroup->addAction(currentLanguage);
menuLanguage->insertAction(actionLoadTranslationFromFile, currentLanguage);
}
menuLanguage->insertSeparator(actionLoadTranslationFromFile);
connect(actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
actionLoadTranslationFromFile->setChecked(false);
//Activate tools menu actions
actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
@ -577,17 +579,8 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
m_messageHandler->start();
//Load translation file
QList<QAction*> 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);
}
}
//Load translation
initializeTranslation();
//Re-translate (make sure we translate once)
QEvent languageChangeEvent(QEvent::LanguageChange);
@ -657,29 +650,6 @@ void MainWindow::addFiles(const QStringList &files)
tabWidget->setCurrentIndex(0);
//int timeMT = 0, timeST = 0;
//
//--Prepass--
//
//FileAnalyzer_ST *analyzerPre = new FileAnalyzer_ST(files);
//connect(analyzerPre, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
//connect(analyzerPre, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
//connect(analyzerPre, SIGNAL(progressMaxChanged(unsigned int)), m_banner, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
//connect(analyzerPre, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
//connect(m_banner, SIGNAL(userAbort()), analyzerPre, SLOT(abortProcess()), Qt::DirectConnection);
//
//try
//{
// m_fileListModel->setBlockUpdates(true);
// m_banner->show(tr("Adding file(s), please wait..."), analyzerPre);
//}
//catch(...)
//{
// /* ignore any exceptions that may occur */
//}
//
//--MT--
FileAnalyzer *analyzer = new FileAnalyzer(files);
connect(analyzer, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
connect(analyzer, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
@ -724,9 +694,6 @@ void MainWindow::addFiles(const QStringList &files)
}
LAMEXP_DELETE(analyzer);
//LAMEXP_DELETE(analyzerST);
//LAMEXP_DELETE(analyzerPre);
m_banner->close();
}
@ -807,6 +774,9 @@ bool MainWindow::checkForUpdates(void)
return bReadyToInstall;
}
/*
* Refresh list of favorites
*/
void MainWindow::refreshFavorites(void)
{
QList<QAction*> folderList = m_outputFolderFavoritesMenu->actions();
@ -837,6 +807,68 @@ void MainWindow::refreshFavorites(void)
}
}
/*
* Initilaize translation
*/
void MainWindow::initializeTranslation(void)
{
bool translationLoaded = false;
//Try to load "external" translation file
if(!m_settings->currentLanguageFile().isEmpty())
{
const QString qmFilePath = QFileInfo(m_settings->currentLanguageFile()).canonicalFilePath();
if(QFileInfo(qmFilePath).exists() && QFileInfo(qmFilePath).isFile() && (QFileInfo(qmFilePath).suffix().compare("qm", Qt::CaseInsensitive) == 0))
{
if(lamexp_install_translator_from_file(qmFilePath))
{
QList<QAction*> actions = m_languageActionGroup->actions();
while(!actions.isEmpty()) actions.takeFirst()->setChecked(false);
actionLoadTranslationFromFile->setChecked(true);
translationLoaded = true;
}
}
}
//Try to load "built-in" translation file
if(!translationLoaded)
{
QList<QAction*> 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);
translationLoaded = true;
}
}
}
//Fallback to default translation
if(!translationLoaded)
{
QList<QAction*> languageActions = m_languageActionGroup->actions();
while(!languageActions.isEmpty())
{
QAction *currentLanguage = languageActions.takeFirst();
if(currentLanguage->data().toString().compare(LAMEXP_DEFAULT_LANGID, Qt::CaseInsensitive) == 0)
{
currentLanguage->setChecked(true);
languageActionActivated(currentLanguage);
translationLoaded = true;
}
}
}
//Make sure we loaded some translation
if(!translationLoaded)
{
qFatal("Failed to load any translation, this is NOT supposed to happen!");
}
}
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
@ -1044,15 +1076,6 @@ void MainWindow::resizeEvent(QResizeEvent *event)
*/
void MainWindow::keyPressEvent(QKeyEvent *e)
{
if(e->key() == Qt::Key_F5)
{
if(outputFolderView->isVisible())
{
QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
return;
}
}
if(e->key() == Qt::Key_Delete)
{
if(sourceFileView->isVisible())
@ -1062,6 +1085,22 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
}
}
if(e->modifiers().testFlag(Qt::ControlModifier) && (e->key() == Qt::Key_F5))
{
initializeTranslation();
MessageBeep(MB_ICONINFORMATION);
return;
}
if(e->key() == Qt::Key_F5)
{
if(outputFolderView->isVisible())
{
QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
return;
}
}
QMainWindow::keyPressEvent(e);
}
@ -1678,7 +1717,9 @@ void MainWindow::languageActionActivated(QAction *action)
if(lamexp_install_translator(langId))
{
action->setChecked(true);
actionLoadTranslationFromFile->setChecked(false);
m_settings->currentLanguage(langId);
m_settings->currentLanguageFile(QString());
}
}
}
@ -1695,13 +1736,16 @@ void MainWindow::languageFromFileActionActivated(bool checked)
if(dialog.exec())
{
QStringList selectedFiles = dialog.selectedFiles();
if(lamexp_install_translator_from_file(selectedFiles.first()))
const QString qmFile = QFileInfo(selectedFiles.first()).canonicalFilePath();
if(lamexp_install_translator_from_file(qmFile))
{
QList<QAction*> actions = m_languageActionGroup->actions();
while(!actions.isEmpty())
{
actions.takeFirst()->setChecked(false);
}
actionLoadTranslationFromFile->setChecked(true);
m_settings->currentLanguageFile(qmFile);
}
else
{

View File

@ -171,6 +171,7 @@ private:
void addFiles(const QStringList &files);
void addFolder(const QString &path, bool recursive = false, bool delayed = false);
bool checkForUpdates(void);
void initializeTranslation(void);
void refreshFavorites(void);
bool m_accepted;

View File

@ -88,6 +88,7 @@ LAMEXP_MAKE_ID(antivirNotificationsEnabled, "Flags/EnableAntivirusNotifications"
LAMEXP_MAKE_ID(dropBoxWidgetEnabled, "Flags/EnableDropBoxWidget");
LAMEXP_MAKE_ID(shellIntegrationEnabled, "Flags/EnableShellIntegration");
LAMEXP_MAKE_ID(currentLanguage, "Localization/Language");
LAMEXP_MAKE_ID(currentLanguageFile, "Localization/UseQMFile");
LAMEXP_MAKE_ID(lameAlgoQuality, "AdvancedOptions/LAME/AlgorithmQuality");
LAMEXP_MAKE_ID(lameChannelMode, "AdvancedOptions/LAME/ChannelMode");
LAMEXP_MAKE_ID(forceStereoDownmix, "AdvancedOptions/StereoDownmix/Force");
@ -250,6 +251,16 @@ void SettingsModel::validate(void)
this->outputDir(musicLocation.isEmpty() ? QDesktopServices::storageLocation(QDesktopServices::HomeLocation) : musicLocation);
}
if(!this->currentLanguageFile().isEmpty())
{
const QString qmPath = QFileInfo(this->currentLanguageFile()).canonicalFilePath();
if(!(QFileInfo(qmPath).exists() && QFileInfo(qmPath).isFile() && (QFileInfo(qmPath).suffix().compare("qm", Qt::CaseInsensitive) == 0)))
{
qWarning("Current language file \"%s\" missing, reverting to built-in translator!", qmPath.toUtf8().constData());
this->currentLanguageFile(QString());
}
}
if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
{
qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
@ -375,6 +386,7 @@ LAMEXP_MAKE_OPTION_B(antivirNotificationsEnabled, true)
LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled, true)
LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled, !lamexp_portable_mode())
LAMEXP_MAKE_OPTION_S(currentLanguage, defaultLanguage())
LAMEXP_MAKE_OPTION_S(currentLanguageFile, QString())
LAMEXP_MAKE_OPTION_I(lameAlgoQuality, 3)
LAMEXP_MAKE_OPTION_I(lameChannelMode, 0)
LAMEXP_MAKE_OPTION_B(forceStereoDownmix, false)

View File

@ -99,6 +99,7 @@ public:
LAMEXP_MAKE_OPTION_B(dropBoxWidgetEnabled);
LAMEXP_MAKE_OPTION_B(shellIntegrationEnabled);
LAMEXP_MAKE_OPTION_S(currentLanguage);
LAMEXP_MAKE_OPTION_S(currentLanguageFile);
LAMEXP_MAKE_OPTION_I(lameAlgoQuality);
LAMEXP_MAKE_OPTION_I(lameChannelMode);
LAMEXP_MAKE_OPTION_B(forceStereoDownmix);