Commit 4f157e8a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Adding a helper to track language changes.

Old language is now restored when vlmc is launched again.
parent d0570b53
......@@ -25,6 +25,7 @@ SET(VLMC_SRCS
Gui/ClipProperty.cpp
Gui/DockWidgetManager.cpp
Gui/FileInfoListModel.cpp
Gui/LanguageHelper.cpp
Gui/LCDTimecode.cpp
Gui/MainWindow.cpp
Gui/PreviewRuler.cpp
......@@ -118,6 +119,7 @@ SET (VLMC_HDRS
Gui/import/ImportController.h
Gui/import/ImportMediaCellView.h
Gui/import/ImportMediaListController.h
Gui/LanguageHelper.h
Gui/LCDTimecode.h
Gui/library/ClipListViewController.h
Gui/library/ListViewController.h
......
/*****************************************************************************
* Languagehelper.cpp: Watch for language changes
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "LanguageHelper.h"
#include <QApplication>
#include <QTranslator>
#include <QVariant>
#define TS_PREFIX "vlmc_"
LanguageHelper::LanguageHelper() : m_translator( NULL )
{
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( deleteLater() ) );
}
LanguageHelper::~LanguageHelper()
{
if ( m_translator )
delete m_translator;
}
void
LanguageHelper::languageChanged( const QVariant &vLang )
{
QString lang = vLang.toString();
if ( !lang.isEmpty() )
{
if ( m_translator != NULL )
{
qApp->removeTranslator( m_translator );
delete m_translator;
m_translator = NULL;
}
m_translator = new QTranslator();
m_translator->load( TS_PREFIX + lang, ":/ts/" );
qApp->installTranslator( m_translator );
}
}
/*****************************************************************************
* Languagehelper.h: Watch for language changes
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef LANGUAGEHELPER_H
#define LANGUAGEHELPER_H
#include "Singleton.hpp"
#include <QObject>
class QTranslator;
class LanguageHelper : public QObject, public Singleton<LanguageHelper>
{
Q_OBJECT
Q_DISABLE_COPY( LanguageHelper );
public slots:
void languageChanged( const QVariant& lang );
private:
LanguageHelper();
~LanguageHelper();
QTranslator *m_translator;
friend class Singleton<LanguageHelper>;
};
#endif // LANGUAGEHELPER_H
......@@ -57,6 +57,7 @@
#include "ProjectWizard.h"
#include "Settings.h"
#include "SettingsManager.h"
#include "LanguageHelper.h"
/* VLCpp */
#include "VLCInstance.h"
......@@ -191,10 +192,16 @@ MainWindow::initVlmcPreferences()
CREATE_MENU_SHORTCUT( "keyboard/renderproject", "Ctrl+R", "Render the project", "Render the project to a file", actionRender );
VLMC_CREATE_PREFERENCE_LANGUAGE( "general/VLMCLang", "en_US", "Langage", "The VLMC's UI language" );
SettingsManager::getInstance()->watchValue( "general/VLMCLang",
LanguageHelper::getInstance(),
SLOT( languageChanged( const QVariant& ) ),
SettingsManager::Vlmc );
//Load saved preferences :
loadVlmcPreferences( "keyboard" );
loadVlmcPreferences( "general" );
}
void
......@@ -585,3 +592,4 @@ void MainWindow::setupCrashTester()
connect( actionCrash, SIGNAL( triggered( bool ) ), this, SLOT( on_actionCrash_triggered() ) );
}
#endif
......@@ -87,17 +87,4 @@ LanguageWidget::save()
{
QString lang = m_list->itemData( m_list->currentIndex() ).toString();
m_setting->set( lang );
if ( !lang.isEmpty() )
{
if ( m_translator != NULL )
{
qApp->removeTranslator( m_translator );
delete m_translator;
m_translator = NULL;
}
m_translator = new QTranslator();
m_translator->load( TS_PREFIX + lang, ":/ts/" );
qApp->installTranslator( m_translator );
}
}
......@@ -29,7 +29,6 @@
class SettingValue;
class QComboBox;
class QTranslator;
class LanguageWidget : public ISettingsCategorieWidget
{
......@@ -41,7 +40,6 @@ class LanguageWidget : public ISettingsCategorieWidget
private:
SettingValue *m_setting;
QComboBox *m_list;
QTranslator *m_translator;
};
#endif // LANGUAGEWIDGET_H
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