OSDN Git Service

First step to internationalization and localization.
authorlordmulder <mulder2@gmx.de>
Tue, 28 Dec 2010 02:57:48 +0000 (03:57 +0100)
committerlordmulder <mulder2@gmx.de>
Tue, 28 Dec 2010 02:57:48 +0000 (03:57 +0100)
14 files changed:
LameXP.vcproj
etc/Translation/update.bat [new file with mode: 0644]
gui/MainWindow.ui
res/Localization.qrc [new file with mode: 0644]
res/localization/LameXP_DE.qm [new file with mode: 0644]
res/localization/LameXP_DE.qm.txt [new file with mode: 0644]
res/localization/LameXP_FR.qm [new file with mode: 0644]
res/localization/LameXP_FR.qm.txt [new file with mode: 0644]
res/localization/LameXP_IT.qm [new file with mode: 0644]
res/localization/LameXP_IT.qm.txt [new file with mode: 0644]
src/Config.h
src/Dialog_MainWindow.cpp
src/Dialog_MainWindow.h
src/Global.cpp

index 329963f..8a277bd 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\tmp\RCC_Localization.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\tmp\RCC_Tools.cpp"
                                >
                        </File>
                                >
                        </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"
                                >
                        </File>
diff --git a/etc/Translation/update.bat b/etc/Translation/update.bat
new file mode 100644 (file)
index 0000000..296d582
--- /dev/null
@@ -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
index 89d8bc5..9d00b93 100644 (file)
            <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>
      <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">
     <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"/>
   <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>
diff --git a/res/Localization.qrc b/res/Localization.qrc
new file mode 100644 (file)
index 0000000..fc2fb2d
--- /dev/null
@@ -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>
diff --git a/res/localization/LameXP_DE.qm b/res/localization/LameXP_DE.qm
new file mode 100644 (file)
index 0000000..4afdc65
Binary files /dev/null and b/res/localization/LameXP_DE.qm differ
diff --git a/res/localization/LameXP_DE.qm.txt b/res/localization/LameXP_DE.qm.txt
new file mode 100644 (file)
index 0000000..176e537
--- /dev/null
@@ -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 (file)
index 0000000..fc3990d
Binary files /dev/null and b/res/localization/LameXP_FR.qm differ
diff --git a/res/localization/LameXP_FR.qm.txt b/res/localization/LameXP_FR.qm.txt
new file mode 100644 (file)
index 0000000..b637125
--- /dev/null
@@ -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 (file)
index 0000000..f7a36ac
Binary files /dev/null and b/res/localization/LameXP_IT.qm differ
diff --git a/res/localization/LameXP_IT.qm.txt b/res/localization/LameXP_IT.qm.txt
new file mode 100644 (file)
index 0000000..c90c673
--- /dev/null
@@ -0,0 +1 @@
+Italiano
\ No newline at end of file
index 3e5bdb0..f9d978f 100644 (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
 
 /*
index eef846e..9edbd97 100644 (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();
                        }
@@ -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<Tag*>(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();
                }
index 2596263..a6cdc6e 100644 (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;
 };
index 0308bd2..2c6bf5b 100644 (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;