|
From: <tiz...@us...> - 2012-09-04 15:16:51
|
Revision: 326
http://sepiola.svn.sourceforge.net/sepiola/?rev=326&view=rev
Author: tizianomueller
Date: 2012-09-04 15:16:42 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
Translation system update
- rename translation files to app_*.ts/qm for automated loading
- dynamically search for translation files
- store language code instead of QComboBox index
- convert old index value to new language code
- add entry in UI combo box to get translation of the language name
Modified Paths:
--------------
trunk/src/gui/settings_form.cc
trunk/src/main.cc
trunk/src/settings/settings.cc
trunk/src/settings/settings.hh
Modified: trunk/src/gui/settings_form.cc
===================================================================
--- trunk/src/gui/settings_form.cc 2012-09-04 15:16:20 UTC (rev 325)
+++ trunk/src/gui/settings_form.cc 2012-09-04 15:16:42 UTC (rev 326)
@@ -76,11 +76,10 @@
this->checkBoxKeepDeletedFiles->setChecked( !settings->getDeleteExtraneousItems() );
this->comboBoxLanguage->clear();
- foreach( QString language, settings->getSupportedLanguages() )
- {
- this->comboBoxLanguage->addItem( language );
- }
- this->comboBoxLanguage->setCurrentIndex( settings->getLanguageIndex() );
+ for ( auto language: settings->getAvailableLanguages() )
+ this->comboBoxLanguage->addItem( language.first, language.second );
+
+ this->comboBoxLanguage->setCurrentIndex( this->comboBoxLanguage->findData(settings->getLanguage()) );
formChanged = false;
}
@@ -91,7 +90,7 @@
Settings* settings = Settings::getInstance();
settings->saveServerUserName( this->lineEditUsername->text() );
settings->saveBackupPrefix( this->lineEditBackupPrefix->text() );
- settings->saveLanguageIndex( this->comboBoxLanguage->currentIndex() );
+ settings->saveLanguage( this->comboBoxLanguage->itemData(this->comboBoxLanguage->currentIndex()).toString() );
settings->saveNOfLastBackups( this->spinBoxNOfShownLastBackups->value() );
settings->saveShowHiddenFilesAndFolders( this->checkBoxShowHiddenFiles->isChecked() );
settings->saveDeleteExtraneousItems( !this->checkBoxKeepDeletedFiles->isChecked() );
@@ -153,7 +152,7 @@
void SettingsForm::on_comboBoxLanguage_currentIndexChanged( int languageIndex )
{
- formChanged = ( languageIndex != Settings::getInstance()->getLanguageIndex() );
+ formChanged = ( this->comboBoxLanguage->itemData(languageIndex).toString() != Settings::getInstance()->getLanguage() );
}
void SettingsForm::on_lineEditBackupPrefix_textEdited( QString backupPrefix )
Modified: trunk/src/main.cc
===================================================================
--- trunk/src/main.cc 2012-09-04 15:16:20 UTC (rev 325)
+++ trunk/src/main.cc 2012-09-04 15:16:42 UTC (rev 326)
@@ -54,7 +54,6 @@
static const QString CONFIG_FILE_NAME = "config";
static const QString VERSION_ARGUMENT = "-version";
static const char* DEPENDENCY_MISSING = "Dependent files are missing. Please reinstall the application.\n";
-static const char* TRANSLATION_MISSING = "Translation files are missing, using default language. Please reinstall the application.\n";
static const char* SINGLE_APPLICATION_ERROR =
"The application is already running. Only one instance of this application can be run concurrently.\n";
}
@@ -138,24 +137,6 @@
return true;
}
-bool loadTranslations()
-{
- QTranslator translator;
- Settings* settings = Settings::getInstance();
- QStringList supportedLanguages = settings->getSupportedLanguages();
-
- // skip the default langauge, because there is no translation file for it
- for (int i=1; i<supportedLanguages.size(); i++)
- {
- if (!translator.load(supportedLanguages.at(i), settings->getApplicationBinDir() ) )
- {
- qDebug() << "translation for" << supportedLanguages.at(i) << "could not be found";
- return false;
- }
- }
- return true;
-}
-
bool isProcessRunning(const int& processId)
{
#ifdef Q_OS_UNIX
@@ -337,10 +318,6 @@
QMessageBox::critical( 0, "Dependency missing", DEPENDENCY_MISSING);
return -1;
}
- if (!loadTranslations())
- {
- QMessageBox::critical( 0, "Translations missing", TRANSLATION_MISSING);
- }
if ( !assertSingleApplication() )
{
QMessageBox::critical( 0, "Application is already running", SINGLE_APPLICATION_ERROR);
@@ -350,11 +327,14 @@
LogFileUtils::getInstance()->open(Settings::getInstance()->getLogFileAbsolutePath(), Settings::getInstance()->getMaxLogLines());
MainModel model;
- QTranslator translator;
Settings* settings = Settings::getInstance();
- translator.load(settings->getSupportedLanguages().at(settings->getLanguageIndex() ), settings->getApplicationBinDir() );
- app.installTranslator( &translator);
+ QTranslator appTranslator, qtTranslator;
+ appTranslator.load("app_" + settings->getLanguage(), settings->getApplicationBinDir());
+ qtTranslator.load("qt_" + settings->getLanguage(), settings->getApplicationBinDir());
+ app.installTranslator(&appTranslator);
+ app.installTranslator(&qtTranslator);
+
MainWindow mainWindow( &model);
QObject::connect( &mainWindow, SIGNAL( writeLog( const QString& ) ), LogFileUtils::getInstance(), SLOT( writeLog( const QString& ) ));
Modified: trunk/src/settings/settings.cc
===================================================================
--- trunk/src/settings/settings.cc 2012-09-04 15:16:20 UTC (rev 325)
+++ trunk/src/settings/settings.cc 2012-09-04 15:16:42 UTC (rev 326)
@@ -23,7 +23,8 @@
#include <QDebug>
#include <QCoreApplication>
#include <QLocale>
-#include <stdio.h>
+#include <cstdio>
+#include <QtCore/QTranslator>
#include "settings/settings.hh"
#include "utils/file_system_utils.hh"
@@ -275,8 +276,18 @@
serverName = userSettings->value( SETTINGS_HOST, serverName ).toString();
serverUserName = userSettings->value( SETTINGS_USERNAME ).toString();
- languageIndex = userSettings->value( SETTINGS_LANGUAGE ).toInt();
+
+ language = userSettings->value( SETTINGS_LANGUAGE ).toString();
+ // Convert old index values to new language codes
+ bool languageIsIndex(false);
+ int languageIndex = language.toInt(&languageIsIndex);
+ if ( languageIsIndex )
+ {
+ qDebug() << "converting deprecated language index to new language code";
+ saveLanguage((languageIndex == 1) ? "de" : "en");
+ }
+
backupPrefix = userSettings->value( SETTINGS_BACKUP_PREFIX ).toString();
if ( backupPrefix == "" )
{
@@ -516,12 +527,12 @@
}
}
-void Settings::saveLanguageIndex( const int& languageIndex )
+void Settings::saveLanguage( const QString& language )
{
- if ( this->languageIndex != languageIndex )
+ if ( this->language != language )
{
- this->languageIndex = languageIndex;
- userSettings->setValue( SETTINGS_LANGUAGE, languageIndex );
+ this->language = language;
+ userSettings->setValue( SETTINGS_LANGUAGE, language );
}
}
@@ -703,9 +714,23 @@
return false;
}
-QStringList Settings::getSupportedLanguages()
+QList<std::pair<QString, QString>> Settings::getAvailableLanguages()
{
- return supportedLanguages;
+ QList<std::pair<QString, QString>> languages;
+ languages << std::make_pair("English", "en"); // the native language
+
+ QDir translationDir(getApplicationBinDir());
+
+ QRegExp regex("^app_(.*)\\.qm$");
+ QStringList translationFiles(translationDir.entryList(QStringList("app_*.qm"), QDir::Files, QDir::Name));
+ for ( auto l: translationFiles )
+ {
+ QTranslator translator;
+ translator.load(translationDir.filePath(l));
+ regex.indexIn(l);
+ languages << std::make_pair(translator.translate("SettingsForm", "English"), regex.cap(1));
+ }
+ return languages;
}
bool Settings::isLogDebugMessageEnabled()
@@ -748,7 +773,6 @@
return applicationDataDir;
}
-
QString Settings::getSetAclName()
{
return getApplicationBinDir() + setacl;
@@ -864,9 +888,9 @@
return getApplicationBinDir() + ssh;
}
-int Settings::getLanguageIndex()
+QString Settings::getLanguage() const
{
- return languageIndex;
+ return language;
}
QString Settings::getBackupContentFileName()
Modified: trunk/src/settings/settings.hh
===================================================================
--- trunk/src/settings/settings.hh 2012-09-04 15:16:20 UTC (rev 325)
+++ trunk/src/settings/settings.hh 2012-09-04 15:16:42 UTC (rev 326)
@@ -19,16 +19,15 @@
#ifndef SETTINGS_HH
#define SETTINGS_HH
-#include <stdlib.h>
#include <QObject>
#include <QFileInfo>
#include <QSettings>
#include <QString>
#include <QStringList>
+#include <QList>
#include <QDateTime>
#include <QSize>
#include <QPoint>
-#include <QHash>
#include "model/backup_task.hh"
#include "model/scheduled_task.hh"
@@ -78,10 +77,10 @@
const char* getEOLCharacter();
/**
- * Gets a list of supported application languages
+ * Gets a list of available application languages
* @return list of languages
*/
- QStringList getSupportedLanguages();
+ QList<std::pair<QString, QString>> getAvailableLanguages();
/**
* Creates a file containing the private putty key
@@ -226,11 +225,11 @@
QString getClientPassword();
QString getServerUserName();
QString getServerPassword();
- int getLanguageIndex();
+ QString getLanguage() const;
void saveServerUserName( const QString& userName );
void setServerPassword( const QString& password );
void setClientPassword( const QString& password );
- void saveLanguageIndex( const int& languageIndex );
+ void saveLanguage( const QString& language );
QString getBackupPrefix();
void saveBackupPrefix( const QString& backupPrefix );
QString getServerKey();
@@ -404,7 +403,7 @@
// writable
QString serverName;
QString serverUserName;
- int languageIndex;
+ QString language;
QString serverKey;
QString privatePuttyKey;
QString privateOpenSshKey;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|