From 705e4ba7e45c3b10532e4a371a37f803edde55ae Mon Sep 17 00:00:00 2001 From: lordmulder Date: Tue, 28 Dec 2010 03:57:48 +0100 Subject: [PATCH] First step to internationalization and localization. --- LameXP.vcproj | 38 ++++++++++ etc/Translation/update.bat | 25 +++++++ gui/MainWindow.ui | 59 ++++++++++++++++ res/Localization.qrc | 11 +++ res/localization/LameXP_DE.qm | Bin 0 -> 144 bytes res/localization/LameXP_DE.qm.txt | 1 + res/localization/LameXP_FR.qm | Bin 0 -> 114 bytes res/localization/LameXP_FR.qm.txt | 1 + res/localization/LameXP_IT.qm | Bin 0 -> 120 bytes res/localization/LameXP_IT.qm.txt | 1 + src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 145 ++++++++++++++++++++++++++++++++++---- src/Dialog_MainWindow.h | 4 ++ src/Global.cpp | 5 ++ 14 files changed, 278 insertions(+), 14 deletions(-) create mode 100644 etc/Translation/update.bat create mode 100644 res/Localization.qrc create mode 100644 res/localization/LameXP_DE.qm create mode 100644 res/localization/LameXP_DE.qm.txt create mode 100644 res/localization/LameXP_FR.qm create mode 100644 res/localization/LameXP_FR.qm.txt create mode 100644 res/localization/LameXP_IT.qm create mode 100644 res/localization/LameXP_IT.qm.txt diff --git a/LameXP.vcproj b/LameXP.vcproj index 329963f9..8a277bd2 100644 --- a/LameXP.vcproj +++ b/LameXP.vcproj @@ -1551,6 +1551,10 @@ > + + @@ -1665,6 +1669,40 @@ > + + + + + + + + + + + diff --git a/etc/Translation/update.bat b/etc/Translation/update.bat new file mode 100644 index 00000000..296d582f --- /dev/null +++ b/etc/Translation/update.bat @@ -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 diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 89d8bc5d..9d00b934 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -239,6 +239,46 @@ + + + + + + + 200 + 0 + 0 + + + + + + + + + 200 + 0 + 0 + + + + + + + + + 200 + 0 + 0 + + + + + + + + PointingHandCursor + QFrame::StyledPanel @@ -1174,12 +1214,19 @@ + + + Language + + + + @@ -1407,6 +1454,14 @@ Show DropBox + + + true + + + English + + @@ -1512,6 +1567,10 @@ + + + + diff --git a/res/Localization.qrc b/res/Localization.qrc new file mode 100644 index 00000000..fc2fb2d6 --- /dev/null +++ b/res/Localization.qrc @@ -0,0 +1,11 @@ + + + + localization/LameXP_DE.qm + localization/LameXP_DE.qm.txt + localization/LameXP_FR.qm + localization/LameXP_FR.qm.txt + localization/LameXP_IT.qm + localization/LameXP_IT.qm.txt + + diff --git a/res/localization/LameXP_DE.qm b/res/localization/LameXP_DE.qm new file mode 100644 index 0000000000000000000000000000000000000000..4afdc6570d8cdfc98d0710a75fecd1dcd7db2a8a GIT binary patch literal 144 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgKK5{5+Kcx3B>8lKthATpCOx}gdv|Hi6NDt zh#?I~76bVT45bWt3@Jd`38)w-!vWI92E+iJ5ufnRzMs<%}IbJ`*D&0DOug2LJ#7 literal 0 HcmV?d00001 diff --git a/res/localization/LameXP_DE.qm.txt b/res/localization/LameXP_DE.qm.txt new file mode 100644 index 00000000..176e5370 --- /dev/null +++ b/res/localization/LameXP_DE.qm.txt @@ -0,0 +1 @@ +Deutsch \ No newline at end of file diff --git a/res/localization/LameXP_FR.qm b/res/localization/LameXP_FR.qm new file mode 100644 index 0000000000000000000000000000000000000000..fc3990d741142f3d062395daedf506ec4a2e0e6a GIT binary patch literal 114 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgKK5{5+Kcx3B;bvK!S_GnW2c`6+;0-DhEh{ z4Tu$d5_3}{0u*!=97|I&^A%k4lJiqiixk|7^7Be`Q}a^TK^lD%GxNeT^HTE589RV{ HCT2zeE(IO1 literal 0 HcmV?d00001 diff --git a/res/localization/LameXP_FR.qm.txt b/res/localization/LameXP_FR.qm.txt new file mode 100644 index 00000000..b6371257 --- /dev/null +++ b/res/localization/LameXP_FR.qm.txt @@ -0,0 +1 @@ +Française \ No newline at end of file diff --git a/res/localization/LameXP_IT.qm b/res/localization/LameXP_IT.qm new file mode 100644 index 0000000000000000000000000000000000000000..f7a36ac24baa614688c0ca76483600fe76cde5b6 GIT binary patch literal 120 zcmcE7ks@*G{hX<16=n7(EZlq7iGhKEgKK5{5+Kcx3B>-)Kth1Qhar(cfgu1WR0V{I z93W{nAXe~6%uS65P|#IyEKSMGS8&Zs&QD1#QgAEE&nwYQ%}ZeiD&q1@%*+eV%uC5H LXY2s-nHU)Xne!eY literal 0 HcmV?d00001 diff --git a/res/localization/LameXP_IT.qm.txt b/res/localization/LameXP_IT.qm.txt new file mode 100644 index 00000000..c90c6734 --- /dev/null +++ b/res/localization/LameXP_IT.qm.txt @@ -0,0 +1 @@ +Italiano \ No newline at end of file diff --git a/src/Config.h b/src/Config.h index 3e5bdb0f..f9d978ff 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 189 +#define VER_LAMEXP_BUILD 193 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index eef846e3..9edbd97e 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -59,6 +59,8 @@ #include #include #include +#include +#include //Win32 includes #include @@ -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(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(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(); } @@ -631,7 +707,7 @@ void MainWindow::encodeButtonClicked(void) static const __int64 minimumFreeDiskspaceMultiplier = 2; ABORT_IF_BUSY; - + if(m_fileListModel->rowCount() < 1) { QMessageBox::warning(this, "LameXP", "You must add at least one file to the list before proceeding!"); @@ -879,6 +955,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(action->userData(0))->text()))) + { + QApplication::installTranslator(m_currentTranslator); + } + } + retranslateUi(this); +} + +/* * Output folder changed (mouse clicked) */ void MainWindow::outputFolderViewClicked(const QModelIndex &index) @@ -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,9 +1001,18 @@ void MainWindow::outputFolderViewMoved(const QModelIndex &index) */ void MainWindow::gotoDesktopButtonClicked(void) { - outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation))); - outputFolderViewClicked(outputFolderView->currentIndex()); - outputFolderView->setFocus(); + 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); + } } /* @@ -919,9 +1020,18 @@ void MainWindow::gotoDesktopButtonClicked(void) */ void MainWindow::gotoHomeFolderButtonClicked(void) { - outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); - outputFolderViewClicked(outputFolderView->currentIndex()); - outputFolderView->setFocus(); + 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); + } } /* @@ -929,9 +1039,18 @@ void MainWindow::gotoHomeFolderButtonClicked(void) */ void MainWindow::gotoMusicFolderButtonClicked(void) { - outputFolderView->setCurrentIndex(m_fileSystemModel->index(QDesktopServices::storageLocation(QDesktopServices::MusicLocation))); - outputFolderViewClicked(outputFolderView->currentIndex()); - outputFolderView->setFocus(); + 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); + } } /* @@ -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(); } diff --git a/src/Dialog_MainWindow.h b/src/Dialog_MainWindow.h index 2596263b..a6cdc6ec 100644 --- a/src/Dialog_MainWindow.h +++ b/src/Dialog_MainWindow.h @@ -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; }; diff --git a/src/Global.cpp b/src/Global.cpp index 0308bd21..2c6bf5b5 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -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; -- 2.11.0