First step to internationalization and localization.

This commit is contained in:
LoRd_MuldeR 2010-12-28 03:57:48 +01:00
parent 6f47dc260a
commit 705e4ba7e4
14 changed files with 278 additions and 14 deletions

View File

@ -1550,6 +1550,10 @@
RelativePath=".\tmp\RCC_Images.cpp"
>
</File>
<File
RelativePath=".\tmp\RCC_Localization.cpp"
>
</File>
<File
RelativePath=".\tmp\RCC_Tools.cpp"
>
@ -1664,6 +1668,40 @@
RelativePath=".\LameXP.rc"
>
</File>
<File
RelativePath=".\res\Localization.qrc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(QTDIR)\bin\rcc.exe&quot; -o &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot; -name &quot;$(SafeInputName)&quot; &quot;$(InputPath)&quot;"
AdditionalDependencies="RCC &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
Outputs="&quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(QTDIR)\bin\rcc.exe&quot; -o &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot; -name &quot;$(SafeInputName)&quot; &quot;$(InputPath)&quot;"
AdditionalDependencies="RCC &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
Outputs="&quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Static|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="&quot;$(QTDIR)\bin\rcc.exe&quot; -o &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot; -name &quot;$(SafeInputName)&quot; &quot;$(InputPath)&quot;"
AdditionalDependencies="RCC &quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
Outputs="&quot;$(SolutionDir)tmp\RCC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\res\MainIcon.ico"
>

View File

@ -0,0 +1,25 @@
@echo off
REM ---------------------------
set "QTVARS=E:\Qt\MSVC\4.7.1\bin\qtvars.bat"
REM ---------------------------
call "%QTVARS%"
del update.lst > NUL
REM ---------------------------
if exist update.lst (
echo "Failed to delete old 'update.lst' file!"
pause
exit
)
REM ---------------------------
for %%f in (..\..\gui\*.ui) do (
echo %%f >> update.lst
)
for %%f in (..\..\src\*.cpp) do (
echo %%f >> update.lst
)
REM ---------------------------
for %%f in (*.ts) do (
lupdate.exe @update.lst -ts %%f
)
REM ---------------------------
pause

View File

@ -239,6 +239,46 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="outputFolderLabel">
<property name="palette">
<palette>
<active>
<colorrole role="Link">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>200</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Link">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>200</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Link">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>200</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@ -1174,12 +1214,19 @@
<addaction name="actionStyleWindowsXP"/>
<addaction name="actionStyleWindowsClassic"/>
</widget>
<widget class="QMenu" name="menuLanguage">
<property name="title">
<string>Language</string>
</property>
<addaction name="actionLanguageEnglish"/>
</widget>
<addaction name="actionSourceFiles"/>
<addaction name="actionOutputDirectory"/>
<addaction name="actionMetaData"/>
<addaction name="actionCompression"/>
<addaction name="actionAdvancedOptions"/>
<addaction name="separator"/>
<addaction name="menuLanguage"/>
<addaction name="menuStyle"/>
</widget>
<widget class="QMenu" name="menuTools">
@ -1407,6 +1454,14 @@
<string>Show DropBox</string>
</property>
</action>
<action name="actionLanguageEnglish">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>English</string>
</property>
</action>
</widget>
<resources>
<include location="../res/Icons.qrc"/>
@ -1512,6 +1567,10 @@
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
<include location="../res/Icons.qrc"/>
<include location="../res/Images.qrc"/>
</resources>
<connections>
<connection>

11
res/Localization.qrc Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>localization/LameXP_DE.qm</file>
<file>localization/LameXP_DE.qm.txt</file>
<file>localization/LameXP_FR.qm</file>
<file>localization/LameXP_FR.qm.txt</file>
<file>localization/LameXP_IT.qm</file>
<file>localization/LameXP_IT.qm.txt</file>
</qresource>
</RCC>

Binary file not shown.

View File

@ -0,0 +1 @@
Deutsch

Binary file not shown.

View File

@ -0,0 +1 @@
Française

Binary file not shown.

View File

@ -0,0 +1 @@
Italiano

View File

@ -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 189
#define VER_LAMEXP_BUILD 193
#define VER_LAMEXP_SUFFIX TechPreview
/*

View File

@ -59,6 +59,8 @@
#include <QUuid>
#include <QProcessEnvironment>
#include <QCryptographicHash>
#include <QTranslator>
#include <QResource>
//Win32 includes
#include <Windows.h>
@ -80,6 +82,16 @@ private:
int m_index;
};
//Helper class
class Tag: public QObjectUserData
{
public:
Tag(const QString &text) : m_text(text) {}
QString text(void) { return m_text; }
private:
const QString m_text;
};
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
@ -88,6 +100,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
:
QMainWindow(parent),
m_fileListModel(fileListModel),
m_currentTranslator(new QTranslator),
m_metaData(metaInfo),
m_settings(settingsModel),
m_accepted(false),
@ -175,6 +188,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
QAction *showFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/zoom.png"), "Browse Selected Folder");
connect(outputFolderView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(outputFolderContextMenu(QPoint)));
connect(showFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
outputFolderLabel->installEventFilter(this);
//Setup "Meta Data" tab
m_metaInfoModel = new MetaInfoModel(m_metaData, 6);
@ -251,6 +265,22 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S
connect(m_styleActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(styleActionActivated(QAction*)));
styleActionActivated(NULL);
//Populate the language menu
m_languageActionGroup = new QActionGroup(this);
m_languageActionGroup->addAction(actionLanguageEnglish);
QStringList translations = QDir(":/localization").entryList(QStringList() << "*.qm", QDir::Files, QDir::Name);
for(int i = 0; i < translations.count(); i++)
{
QAction *currentLanguage = new QAction(this);
currentLanguage->setCheckable(true);
currentLanguage->setText(QString::fromUtf8(reinterpret_cast<const char*>(QResource(QString(":/localization/%1.txt").arg(translations.at(i))).data())));
currentLanguage->setUserData(0, new Tag(translations.at(i)));
m_languageActionGroup->addAction(currentLanguage);
menuLanguage->addAction(currentLanguage);
}
connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
actionLanguageEnglish->setChecked(true);
//Activate tools menu actions
actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
actionDisableSounds->setChecked(!m_settings->soundsEnabled());
@ -317,9 +347,13 @@ MainWindow::~MainWindow(void)
sourceFileView->setModel(NULL);
metaDataView->setModel(NULL);
//Uninstall translator
QApplication::removeTranslator(m_currentTranslator);
//Free memory
LAMEXP_DELETE(m_tabActionGroup);
LAMEXP_DELETE(m_styleActionGroup);
LAMEXP_DELETE(m_languageActionGroup);
LAMEXP_DELETE(m_banner);
LAMEXP_DELETE(m_fileSystemModel);
LAMEXP_DELETE(m_messageHandler);
@ -330,12 +364,16 @@ MainWindow::~MainWindow(void)
LAMEXP_DELETE(m_encoderButtonGroup);
LAMEXP_DELETE(m_sourceFilesContextMenu);
LAMEXP_DELETE(m_dropBox);
LAMEXP_DELETE(m_currentTranslator);
}
////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS
////////////////////////////////////////////////////////////
/*
* Add file to source list
*/
void MainWindow::addFiles(const QStringList &files)
{
if(files.isEmpty())
@ -369,6 +407,9 @@ void MainWindow::addFiles(const QStringList &files)
// EVENTS
////////////////////////////////////////////////////////////
/*
* Window is about to be shown
*/
void MainWindow::showEvent(QShowEvent *event)
{
m_accepted = false;
@ -390,6 +431,9 @@ void MainWindow::showEvent(QShowEvent *event)
}
}
/*
* File dragged over window
*/
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
QStringList formats = event->mimeData()->formats();
@ -400,6 +444,9 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
}
}
/*
* File dropped onto window
*/
void MainWindow::dropEvent(QDropEvent *event)
{
ABORT_IF_BUSY;
@ -432,6 +479,9 @@ void MainWindow::dropEvent(QDropEvent *event)
addFiles(droppedFiles);
}
/*
* Window tries to close
*/
void MainWindow::closeEvent(QCloseEvent *event)
{
if(m_banner->isVisible() || m_delayedFileTimer->isActive())
@ -446,12 +496,18 @@ void MainWindow::closeEvent(QCloseEvent *event)
}
}
/*
* Window was resized
*/
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
}
/*
* Event filter
*/
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_fileSystemModel && QApplication::overrideCursor() == NULL)
@ -459,6 +515,26 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QTimer::singleShot(250, this, SLOT(restoreCursor()));
}
else if(obj == outputFolderLabel)
{
switch(event->type())
{
case QEvent::MouseButtonPress:
if(dynamic_cast<QMouseEvent*>(event)->button() == Qt::LeftButton)
{
QDesktopServices::openUrl(QString("file:///%1").arg(outputFolderLabel->text()));
}
break;
case QEvent::Enter:
qDebug("QEvent::HoverEnter");
outputFolderLabel->setForegroundRole(QPalette::Link);
break;
case QEvent::Leave:
qDebug("QEvent::HoverLeave");
outputFolderLabel->setForegroundRole(QPalette::WindowText);
break;
}
}
return false;
}
@ -536,7 +612,7 @@ void MainWindow::windowShown(void)
QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
if(!lastUpdateCheck.isValid() || QDate::currentDate() >= lastUpdateCheck.addDays(14))
{
if(QMessageBox::information(this, "Update Reminer", (lastUpdateCheck.isValid() ? "Your last update check was more than 14 days ago. Check for updates now?" : "Your did not check for LameXP updates yet. Check for updates now?"), "Check for Updates", "Defer") == 0)
if(QMessageBox::information(this, "Update Reminer", (lastUpdateCheck.isValid() ? "Your last update check was more than 14 days ago. Check for updates now?" : "Your did not check for LameXP updates yet. Check for updates now?"), "Check for Updates", "Postpone") == 0)
{
checkUpdatesActionActivated();
}
@ -878,6 +954,22 @@ void MainWindow::styleActionActivated(QAction *action)
}
}
/*
* Language action triggered
*/
void MainWindow::languageActionActivated(QAction *action)
{
QApplication::removeTranslator(m_currentTranslator);
if(action->userData(0))
{
if(m_currentTranslator->load(QString(":/localization/%1").arg(dynamic_cast<Tag*>(action->userData(0))->text())))
{
QApplication::installTranslator(m_currentTranslator);
}
}
retranslateUi(this);
}
/*
* Output folder changed (mouse clicked)
*/
@ -889,7 +981,7 @@ void MainWindow::outputFolderViewClicked(const QModelIndex &index)
}
QString selectedDir = m_fileSystemModel->filePath(index);
if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
outputFolderLabel->setText(selectedDir);
outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
m_settings->outputDir(selectedDir);
}
@ -909,30 +1001,57 @@ void MainWindow::outputFolderViewMoved(const QModelIndex &index)
*/
void MainWindow::gotoDesktopButtonClicked(void)
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)));
QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
outputFolderViewClicked(outputFolderView->currentIndex());
outputFolderView->setFocus();
}
else
{
buttonGotoDesktop->setEnabled(false);
}
}
/*
* Goto home folder button
*/
void MainWindow::gotoHomeFolderButtonClicked(void)
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)));
QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
if(!homePath.isEmpty() && QDir(homePath).exists())
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
outputFolderViewClicked(outputFolderView->currentIndex());
outputFolderView->setFocus();
}
else
{
buttonGotoHome->setEnabled(false);
}
}
/*
* Goto music folder button
*/
void MainWindow::gotoMusicFolderButtonClicked(void)
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)));
QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
if(!musicPath.isEmpty() && QDir(musicPath).exists())
{
outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
outputFolderViewClicked(outputFolderView->currentIndex());
outputFolderView->setFocus();
}
else
{
buttonGotoMusic->setEnabled(false);
}
}
/*
* Make folder button
@ -1645,7 +1764,7 @@ void MainWindow::installWMADecoderActionTriggered(bool checked)
QFile::remove(setupFile);
QApplication::restoreOverrideCursor();
if(QMessageBox::information(this, "WMA Decoder", "The WMA File Decoder has been installed. Please restart LameXP now!", "Quit LameXP", "Ignore") == 0)
if(QMessageBox::information(this, "WMA Decoder", "The WMA File Decoder has been installed. Please restart LameXP now!", "Quit LameXP", "Postpone") == 0)
{
QApplication::quit();
}

View File

@ -35,6 +35,7 @@ class FileListModel;
class AbstractEncoder;
class QMenu;
class DropBox;
class QTranslator;
class MainWindow: public QMainWindow, private Ui::MainWindow
{
@ -60,6 +61,7 @@ private slots:
void tabPageChanged(int idx);
void tabActionActivated(QAction *action);
void styleActionActivated(QAction *action);
void languageActionActivated(QAction *action);
void outputFolderViewClicked(const QModelIndex &index);
void outputFolderViewMoved(const QModelIndex &index);
void makeFolderButtonClicked(void);
@ -112,6 +114,7 @@ private:
QFileSystemModelEx *m_fileSystemModel;
QActionGroup *m_tabActionGroup;
QActionGroup *m_styleActionGroup;
QActionGroup *m_languageActionGroup;
QButtonGroup *m_encoderButtonGroup;
QButtonGroup *m_modeButtonGroup;
WorkingBanner *m_banner;
@ -125,4 +128,5 @@ private:
QMenu *m_sourceFilesContextMenu;
QMenu *m_outputFolderContextMenu;
DropBox *m_dropBox;
QTranslator *m_currentTranslator;
};

View File

@ -523,6 +523,11 @@ bool lamexp_init_qt(int argc, char* argv[])
}
}
//Load translation
//QTranslator *translator = new QTranslator();
//translator->load(":/localization/LameXP_DE.qm");
//application->installTranslator(translator);
//Done
qt_initialized = true;
return true;