From c64f02c9bf053aa8572357dc6575e52909bd7b24 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 25 Sep 2010 12:42:19 +0000 Subject: [PATCH] Fix locale change from the Web UI --- src/eventmanager.cpp | 17 +++++++++++++++-- src/json.h | 1 + src/options_imp.cpp | 15 ++++++++++++++- src/webui/preferences_content.html | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 7a2a649a4..858f3b4e2 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -38,6 +38,7 @@ //#include "proplistdelegate.h" #include "torrentpersistentdata.h" #include +#include EventManager::EventManager(QObject *parent, Bittorrent *BTSession) : QObject(parent), BTSession(BTSession) @@ -124,8 +125,20 @@ QList EventManager::getPropFilesInfo(QString hash) const { void EventManager::setGlobalPreferences(QVariantMap m) const { // UI - if(m.contains("locale")) - Preferences::setLocale(m["locale"].toString()); + if(m.contains("locale")) { + QString locale = m["locale"].toString(); + if(Preferences::getLocale() != locale) { + QTranslator *translator = new QTranslator; + if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){ + qDebug("%s locale recognized, using translation.", qPrintable(locale)); + }else{ + qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale)); + } + qApp->installTranslator(translator); + } + + Preferences::setLocale(locale); + } // Downloads if(m.contains("save_path")) Preferences::setSavePath(m["save_path"].toString()); diff --git a/src/json.h b/src/json.h index dd0e19b34..8eb27cc4b 100644 --- a/src/json.h +++ b/src/json.h @@ -132,6 +132,7 @@ namespace json { tmp += c; } } + if(!tmp.isEmpty()) couples << tmp; foreach(QString couple, couples) { QStringList parts = couple.split(":"); if(parts.size() != 2) continue; diff --git a/src/options_imp.cpp b/src/options_imp.cpp index ea19c1186..e6d639cfc 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -353,10 +354,22 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ QIniSettings settings("qBittorrent", "qBittorrent"); // Apply style useStyle(); + // Load the translation + QString locale = getLocale(); + if(Preferences::getLocale() != locale) { + QTranslator *translator = new QTranslator; + if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){ + qDebug("%s locale recognized, using translation.", qPrintable(locale)); + }else{ + qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale)); + } + qApp->installTranslator(translator); + } + settings.beginGroup("Preferences"); // General preferences settings.beginGroup("General"); - settings.setValue(QString::fromUtf8("Locale"), getLocale()); + settings.setValue(QString::fromUtf8("Locale"), locale); settings.setValue(QString::fromUtf8("Style"), getStyle()); settings.setValue(QString::fromUtf8("AlternatingRowColors"), checkAltRowColors->isChecked()); settings.setValue(QString::fromUtf8("SystrayEnabled"), systrayIntegration()); diff --git a/src/webui/preferences_content.html b/src/webui/preferences_content.html index 444fedf64..03b86672a 100644 --- a/src/webui/preferences_content.html +++ b/src/webui/preferences_content.html @@ -539,6 +539,7 @@ }, onSuccess: function() { // Close window + window.parent.location.reload(); window.parent.closeWindows(); } }).send();