[vlmc-devel] commit: Support translation for the category name (preferences). ( Ludovic Fauvet )

git at videolan.org git at videolan.org
Wed Apr 14 00:52:45 CEST 2010


vlmc | branch: master | Ludovic Fauvet <etix at l0cal.com> | Wed Apr 14 00:50:56 2010 +0200| [5e6dc330c0355e2a743c2d6baa08ac8ee34740c6] | committer: Ludovic Fauvet 

Support translation for the category name (preferences).

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=5e6dc330c0355e2a743c2d6baa08ac8ee34740c6
---

 src/Gui/MainWindow.cpp                |   10 +++---
 src/Gui/settings/PreferenceWidget.cpp |    7 ++---
 src/Gui/settings/PreferenceWidget.h   |    6 ++--
 src/Gui/settings/Settings.cpp         |   44 ++++++++++++++++++++++++++------
 src/Gui/settings/Settings.h           |   12 ++++++---
 5 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index cb518cd..58d98f4 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -419,10 +419,10 @@ void MainWindow::initializeDockWidgets( void )
 void        MainWindow::createGlobalPreferences()
 {
     m_globalPreferences = new Settings( SettingsManager::Vlmc, this );
-    m_globalPreferences->addCategory( "general", SettingsManager::Vlmc,
+    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Vlmc,
                                    QIcon( ":/images/images/vlmc.png" ),
                                    tr ( "VLMC settings" ) );
-    m_globalPreferences->addCategory( "keyboard", SettingsManager::Vlmc,
+    m_globalPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "keyboard" ), SettingsManager::Vlmc,
                                      QIcon( ":/images/keyboard" ),
                                      tr( "Keyboard Settings" ) );
 }
@@ -430,13 +430,13 @@ void        MainWindow::createGlobalPreferences()
 void    MainWindow::createProjectPreferences()
 {
     m_projectPreferences = new Settings( SettingsManager::Project, this );
-    m_projectPreferences->addCategory( "general", SettingsManager::Project,
+    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "general" ), SettingsManager::Project,
                                    QIcon( ":/images/images/vlmc.png" ),
                                    tr ( "Project settings" ) );
-    m_projectPreferences->addCategory( "video", SettingsManager::Project,
+    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "video" ), SettingsManager::Project,
                                    QIcon( ":/images/images/video.png" ),
                                    tr ( "Video settings" ) );
-    m_projectPreferences->addCategory( "audio", SettingsManager::Project,
+    m_projectPreferences->addCategory( QT_TRANSLATE_NOOP( "Settings", "audio" ), SettingsManager::Project,
                                    QIcon( ":/images/images/audio.png" ),
                                    tr ( "Audio settings" ) );
 }
diff --git a/src/Gui/settings/PreferenceWidget.cpp b/src/Gui/settings/PreferenceWidget.cpp
index 65f1bf2..5d50103 100644
--- a/src/Gui/settings/PreferenceWidget.cpp
+++ b/src/Gui/settings/PreferenceWidget.cpp
@@ -41,14 +41,14 @@
 #include <QHashIterator>
 #include <QEvent>
 
-PreferenceWidget::PreferenceWidget( const QString &category, SettingsManager::Type type,
+PreferenceWidget::PreferenceWidget( const char *category, SettingsManager::Type type,
                                     QWidget *parent ) :
     QScrollArea( parent ),
     m_category( category )
 {
     QWidget     *container = new QWidget( this );
     SettingsManager::SettingHash    settings =
-            SettingsManager::getInstance()->group( category, type );
+            SettingsManager::getInstance()->group( QString( category ), type );
     QFormLayout *layout = new QFormLayout( container );
     layout->setFieldGrowthPolicy( QFormLayout::AllNonFixedFieldsGrow );
 
@@ -66,7 +66,6 @@ PreferenceWidget::PreferenceWidget( const QString &category, SettingsManager::Ty
     setWidget( container );
     setWidgetResizable( true );
     setFrameStyle( QFrame::NoFrame );
-    m_category[0] = m_category[0].toUpper();
 }
 
 ISettingsCategoryWidget*
@@ -96,7 +95,7 @@ PreferenceWidget::save()
         w->save();
 }
 
-const QString&
+const char*
 PreferenceWidget::category() const
 {
     return m_category;
diff --git a/src/Gui/settings/PreferenceWidget.h b/src/Gui/settings/PreferenceWidget.h
index 330b109..39f9263 100644
--- a/src/Gui/settings/PreferenceWidget.h
+++ b/src/Gui/settings/PreferenceWidget.h
@@ -40,12 +40,12 @@ class   PreferenceWidget : public QScrollArea
     Q_OBJECT
     public:
         typedef QList<ISettingsCategoryWidget*>    SettingsList;
-        PreferenceWidget( const QString& category, SettingsManager::Type type,
+        PreferenceWidget( const char* category, SettingsManager::Type type,
                           QWidget* parent = 0 );
         virtual ~PreferenceWidget() {}
 
         virtual void    save();
-        const QString   &category() const;
+        const char      *category() const;
     protected:
         void            changeEvent( QEvent *e );
 
@@ -54,7 +54,7 @@ class   PreferenceWidget : public QScrollArea
         void            retranslateUi();
 
     private:
-        QString                     m_category;
+        const char                  *m_category;
         SettingsList                m_settings;
         QHash<SettingValue*, QLabel*>  m_labels;
 };
diff --git a/src/Gui/settings/Settings.cpp b/src/Gui/settings/Settings.cpp
index 1c57cf9..fca706f 100644
--- a/src/Gui/settings/Settings.cpp
+++ b/src/Gui/settings/Settings.cpp
@@ -60,16 +60,19 @@ Settings::Settings( SettingsManager::Type type, QWidget* parent, Qt::WindowFlags
              this, SLOT( switchWidget( int ) ) );
 }
 
-void        Settings::addCategory( const QString& name,
-                                    SettingsManager::Type type,
-                                 const QIcon& icon,
-                                 const QString& label )
+void        Settings::addCategory( const char* name,
+                                   SettingsManager::Type type,
+                                   const QIcon& icon,
+                                   const QString& label )
 {
     PreferenceWidget    *pWidget = new PreferenceWidget( name, type, this );
 
     m_stackedLayout->addWidget( pWidget );
+
     // Create a button linked to the widget using its index
     m_panel->addButton( label, icon, m_stackedLayout->count() - 1 );
+
+    switchWidget( 0 );
 }
 
 void
@@ -132,11 +135,34 @@ void    Settings::buttonClicked( QAbstractButton* button )
 
 void    Settings::switchWidget( int index )
 {
-    PreferenceWidget* pWidget =
-            qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( index ) );
-
-    Q_ASSERT( pWidget != NULL );
-    m_title->setText( pWidget->category() );
     m_stackedLayout->setCurrentIndex( index );
+
+    // Reload the translated title
+    retranslateUi();
 }
 
+void    Settings::changeEvent( QEvent *e )
+{
+    switch ( e->type() )
+    {
+    case QEvent::LanguageChange:
+        retranslateUi();
+        break;
+    default:
+        break;
+    }
+}
+
+void    Settings::retranslateUi()
+{
+    PreferenceWidget* pWidget =
+            qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( m_stackedLayout->currentIndex() ) );
+    Q_ASSERT( pWidget != NULL );
+
+    // Translate the category name using the current locale
+    QString text = tr( pWidget->category() );
+
+    if ( text.length() >= 1 )
+        text[0] = text[0].toUpper();
+    m_title->setText( text );
+}
diff --git a/src/Gui/settings/Settings.h b/src/Gui/settings/Settings.h
index 840bbe0..c995fea 100644
--- a/src/Gui/settings/Settings.h
+++ b/src/Gui/settings/Settings.h
@@ -47,12 +47,16 @@ class   Settings : public QDialog
     public:
         Settings( SettingsManager::Type type, QWidget* parent = 0, Qt::WindowFlags f = 0 );
 
-        void                        addCategory( const QString& name,
-                                                    SettingsManager::Type type,
-                                                    const QIcon& icon,
-                                                    const QString& label );
+        void                        addCategory( const char* name,
+                                                 SettingsManager::Type type,
+                                                 const QIcon& icon,
+                                                 const QString& label );
+
+    protected:
+        void                        changeEvent( QEvent *e );
     private:
         void                        buildLayout();
+        void                        retranslateUi();
 
     private:
         QDialogButtonBox*           m_buttons;



More information about the Vlmc-devel mailing list