Commit b9d011ca authored by Clement CHAVANCE's avatar Clement CHAVANCE
Browse files

Language Settings are now included in the application settings widget

parent a62a130f
...@@ -33,4 +33,12 @@ void VLMCSettingsDefault::loadVLMCDefaults( const QString& part ) ...@@ -33,4 +33,12 @@ void VLMCSettingsDefault::loadVLMCDefaults( const QString& part )
void VLMCSettingsDefault::loadlanguageDefaults( const QString& part ) void VLMCSettingsDefault::loadlanguageDefaults( const QString& part )
{ {
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultLang = "fr";
setMan->setValue( part,
"VLMCLang",
defaultLang );
return ;
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team * Copyright (C) 2008-2009 the VLMC team
* *
* Authors: Christophe Courtaut <christophe.courtaut@gmail.com> * Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
* Authors: Clement CHAVANCE <kinder@vlmcorg>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -19,60 +20,49 @@ ...@@ -19,60 +20,49 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <QVariant>
#include "SettingsManager.h"
#include "LanguagePreferences.h" #include "LanguagePreferences.h"
#include "ui_LanguagePreferences.h" #include "ui_LanguagePreferences.h"
QTranslator* Preferences::m_currentLang = NULL; QTranslator* LanguagePreferences::m_currentLang = NULL;
Preferences* Preferences::m_instance = NULL;
Preferences::Preferences( QWidget *parent ) : QDialog( parent ) LanguagePreferences::LanguagePreferences( QWidget *parent )
: PreferenceWidget( parent )
{ {
m_ui.setupUi( this ); m_ui.setupUi( this );
m_ui.comboBoxLanguage->addItem( tr( "English" ), "" ); m_ui.comboBoxLanguage->addItem( tr( "English" ), "en" );
m_ui.comboBoxLanguage->addItem( tr( "French" ), "fr" ); m_ui.comboBoxLanguage->addItem( tr( "French" ), "fr" );
m_ui.comboBoxLanguage->addItem( tr( "Spanish" ), "es" ); m_ui.comboBoxLanguage->addItem( tr( "Spanish" ), "es" );
m_ui.comboBoxLanguage->addItem( tr( "Swedish" ), "sv" ); m_ui.comboBoxLanguage->addItem( tr( "Swedish" ), "sv" );
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( deleteLater() ) );
} }
void Preferences::changeEvent( QEvent *e ) LanguagePreferences::~LanguagePreferences() {}
{
QWidget::changeEvent( e );
switch ( e->type() )
{
case QEvent::LanguageChange:
m_ui.retranslateUi( this );
break;
default:
break;
}
}
Preferences* Preferences::instance() void LanguagePreferences::load()
{ {
if ( m_instance ) const QString& part = m_defaults ? "default" : m_settName;
return m_instance; SettingsManager* setMan = SettingsManager::getInstance();
m_instance = new Preferences(); QVariant lang = setMan->getValue( part, "VLMCLang" );
return m_instance; int idx = m_ui.comboBoxLanguage->findData( lang );
}
void Preferences::on_pushButtonCancel_clicked() if ( idx != -1 )
{ m_ui.comboBoxLanguage->setCurrentIndex( idx );
close(); return ;
} }
void Preferences::on_pushButtonApply_clicked() void LanguagePreferences::save()
{ {
Preferences::changeLang( m_ui.comboBoxLanguage->itemData( m_ui.comboBoxLanguage->currentIndex() ).toString() ); SettingsManager* setMan = SettingsManager::getInstance();
close(); QVariant lang = m_ui.comboBoxLanguage->itemData( m_ui.comboBoxLanguage->currentIndex() );
setMan->setValue( m_settName, "VLMCLang", lang );
changeLang( lang.toString() );
} }
void Preferences::changeLang( QString langValue ) void LanguagePreferences::changeLang( QString langValue )
{ {
QSettings settings;
QString lang = settings.value( "Lang" ).toString();
settings.setValue( "Lang", langValue);
if ( m_currentLang != NULL ) if ( m_currentLang != NULL )
{ {
qApp->removeTranslator( m_currentLang ); qApp->removeTranslator( m_currentLang );
...@@ -86,3 +76,16 @@ void Preferences::changeLang( QString langValue ) ...@@ -86,3 +76,16 @@ void Preferences::changeLang( QString langValue )
qApp->installTranslator( m_currentLang ); qApp->installTranslator( m_currentLang );
} }
} }
void LanguagePreferences::changeEvent( QEvent *e )
{
QWidget::changeEvent( e );
switch ( e->type() )
{
case QEvent::LanguageChange:
m_ui.retranslateUi( this );
break;
default:
break;
}
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team * Copyright (C) 2008-2009 the VLMC team
* *
* Authors: Christophe Courtaut <christophe.courtaut@gmail.com> * Authors: Christophe Courtaut <christophe.courtaut@gmail.com>
* Authors: Clement CHAVANCE <kinder@vlmc.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -23,33 +24,26 @@ ...@@ -23,33 +24,26 @@
#ifndef PREFERENCES_H #ifndef PREFERENCES_H
#define PREFERENCES_H #define PREFERENCES_H
#include <QtGui/QWidget>
#include <QTranslator> #include <QTranslator>
#include <QApplication>
#include <QSettings>
#include <QtDebug> #include <QtDebug>
#include "PreferenceWidget.h"
#include "ui_LanguagePreferences.h" #include "ui_LanguagePreferences.h"
class Preferences : public QDialog class LanguagePreferences : public PreferenceWidget
{ {
Q_OBJECT public:
Q_DISABLE_COPY( Preferences ) LanguagePreferences( QWidget* parent = 0 );
public: ~LanguagePreferences();
static Preferences* instance(); void load();
static void changeLang(QString lang); void save();
void changeLang(QString lang);
protected: protected:
virtual void changeEvent( QEvent *e ); virtual void changeEvent( QEvent *e );
private: private:
explicit Preferences( QWidget *parent = 0 ); Ui::LanguagePreferences m_ui;
Ui::LanguagePreferences m_ui; static QTranslator* m_currentLang;
static QTranslator* m_currentLang;
static Preferences* m_instance;
private slots:
void on_pushButtonCancel_clicked();
void on_pushButtonApply_clicked();
}; };
#endif // PREFERENCES_H #endif // PREFERENCES_H
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "VLMCPreferences.h" #include "VLMCPreferences.h"
#include "Import.h" #include "Import.h"
#include "MediaLibraryWidget.h" #include "MediaLibraryWidget.h"
#include "LanguagePreferences.h"
MainWindow::MainWindow( QWidget *parent ) : MainWindow::MainWindow( QWidget *parent ) :
QMainWindow( parent ), m_renderer( NULL ) QMainWindow( parent ), m_renderer( NULL )
...@@ -315,6 +316,10 @@ void MainWindow::createGlobalPreferences() ...@@ -315,6 +316,10 @@ void MainWindow::createGlobalPreferences()
new VLMCPreferences( m_globalPreferences ), new VLMCPreferences( m_globalPreferences ),
"../images/vlmc.png", "../images/vlmc.png",
"VLMC settings"); "VLMC settings");
m_globalPreferences->addWidget("Language preferences",
new LanguagePreferences( m_globalPreferences ),
"../images/vlmc.png",
"Langage settings");
m_globalPreferences->build(); m_globalPreferences->build();
} }
...@@ -353,7 +358,7 @@ void MainWindow::on_actionQuit_triggered() ...@@ -353,7 +358,7 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionPreferences_triggered() void MainWindow::on_actionPreferences_triggered()
{ {
m_projectPreferences->show(); m_globalPreferences->show();
} }
void MainWindow::on_actionAbout_triggered() void MainWindow::on_actionAbout_triggered()
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>LanguagePreferences</class> <class>LanguagePreferences</class>
<widget class="QDialog" name="LanguagePreferences"> <widget class="QWidget" name="LanguagePreferences">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>444</width> <width>400</width>
<height>388</height> <height>114</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Preferences</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QLabel" name="label">
<property name="tabPosition"> <property name="text">
<enum>QTabWidget::North</enum> <string>Language</string>
</property> </property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="TabGeneral">
<attribute name="title">
<string>General</string>
</attribute>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Language</string>
</property>
</widget>
<widget class="QComboBox" name="comboBoxLanguage">
<property name="geometry">
<rect>
<x>110</x>
<y>10</y>
<width>121</width>
<height>24</height>
</rect>
</property>
</widget>
</widget>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="1">
<spacer name="horizontalSpacer"> <widget class="QComboBox" name="comboBoxLanguage"/>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>293</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>
......
...@@ -50,8 +50,8 @@ int main( int argc, char **argv ) ...@@ -50,8 +50,8 @@ int main( int argc, char **argv )
app.setOrganizationName( "vlmc" ); app.setOrganizationName( "vlmc" );
app.setOrganizationDomain( "vlmc.org" ); app.setOrganizationDomain( "vlmc.org" );
app.setApplicationVersion( STRINGIFY(VLMC_VERSION) ); app.setApplicationVersion( STRINGIFY(VLMC_VERSION) );
QSettings::setDefaultFormat( QSettings::IniFormat ); //QSettings::setDefaultFormat( QSettings::IniFormat );
Preferences::changeLang( QSettings().value( "Lang" ).toString() ); //Preferences::changeLang( QSettings().value( "Lang" ).toString() );
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Ugly workaround // Ugly workaround
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment