diff options
| author | Tannin <devnull@localhost> | 2013-11-27 20:25:24 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-11-27 20:25:24 +0100 |
| commit | f1515193ca82c229a712f067f61f1c26e9b83400 (patch) | |
| tree | c0a50bbfcde4644b7f05e30c90211b69b60a25d0 /src/mainwindow.cpp | |
| parent | db0347212a509b9ceef1cede61a4afd7d2253014 (diff) | |
- plugins can now be localized too
- fixes to the installer script
- extended build scripts to fetch translations from pootle server automatically
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 31ee1ae7..5c487e7a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -144,8 +144,7 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, QWidget m_DirectoryStructure(new DirectoryEntry(L"data", NULL, 0)), m_ModList(this), m_ModListGroupingProxy(NULL), m_ModListSortProxy(NULL), m_PluginList(this), m_OldExecutableIndex(-1), m_GamePath(ToQString(GameInfo::instance().getGameDirectory())), - m_DownloadManager(NexusInterface::instance(), this), - m_InstallationManager(this), m_Translator(NULL), m_TranslatorQt(NULL), + m_DownloadManager(NexusInterface::instance(), this), m_InstallationManager(this), m_Updater(NexusInterface::instance(), this), m_CategoryFactory(CategoryFactory::instance()), m_CurrentProfile(NULL), m_AskForNexusPW(false), m_LoginAttempted(false), m_ArchivesInit(false), m_ContextItem(NULL), m_ContextAction(NULL), m_CurrentSaveView(NULL), @@ -975,7 +974,7 @@ void MainWindow::registerPluginTool(IPluginTool *tool) } -bool MainWindow::registerPlugin(QObject *plugin) +bool MainWindow::registerPlugin(QObject *plugin, const QString &fileName) { { // generic treatment for all plugins IPlugin *pluginObj = qobject_cast<IPlugin*>(plugin); @@ -983,6 +982,7 @@ bool MainWindow::registerPlugin(QObject *plugin) qDebug("not an IPlugin"); return false; } + plugin->setProperty("filename", fileName); m_Settings.registerPlugin(pluginObj); } @@ -1017,7 +1017,7 @@ bool MainWindow::registerPlugin(QObject *plugin) try { QObject *proxiedPlugin = proxy->instantiate(pluginName); if (proxiedPlugin != NULL) { - if (registerPlugin(proxiedPlugin)) { + if (registerPlugin(proxiedPlugin, pluginName)) { qDebug("loaded plugin \"%s\"", QDir::toNativeSeparators(pluginName).toUtf8().constData()); } else { qWarning("plugin \"%s\" failed to load", pluginName.toUtf8().constData()); @@ -1052,7 +1052,7 @@ void MainWindow::loadPlugins() m_Settings.clearPlugins(); foreach (QObject *plugin, QPluginLoader::staticInstances()) { - registerPlugin(plugin); + registerPlugin(plugin, ""); } QFile loadCheck(QCoreApplication::applicationDirPath() + "/plugin_loadcheck.tmp"); @@ -1095,7 +1095,7 @@ void MainWindow::loadPlugins() qCritical("failed to load plugin %s: %s", pluginName.toUtf8().constData(), pluginLoader.errorString().toUtf8().constData()); } else { - if (registerPlugin(pluginLoader.instance())) { + if (registerPlugin(pluginLoader.instance(), pluginName)) { qDebug("loaded plugin \"%s\"", QDir::toNativeSeparators(pluginName).toUtf8().constData()); } else { m_UnloadedPlugins.push_back(pluginName); @@ -3998,35 +3998,40 @@ void MainWindow::downloadRequested(QNetworkReply *reply, int modID, const QStrin } -void MainWindow::languageChange(const QString &newLanguage) +QTranslator *MainWindow::installTranslator(const QString &name) { - if (m_Translator != NULL) { - QCoreApplication::removeTranslator(m_Translator); - delete m_Translator; - m_Translator = NULL; + QTranslator *translator = new QTranslator(this); + QString fileName = name + "_" + m_CurrentLanguage; + if (!translator->load(fileName, qApp->applicationDirPath() + "/translations")) { + qWarning("localization file %s not found", qPrintable(fileName)); } - if (m_TranslatorQt != NULL) { - QCoreApplication::removeTranslator(m_TranslatorQt); - delete m_TranslatorQt; - m_TranslatorQt = NULL; + qApp->installTranslator(translator); + return translator; +} + + +void MainWindow::languageChange(const QString &newLanguage) +{ + foreach (QTranslator *trans, m_Translators) { + qApp->removeTranslator(trans); } + m_Translators.clear(); - if (newLanguage != "en_US") { - // add our own translations - m_Translator = new QTranslator(this); - QString locFile = ToQString(AppConfig::translationPrefix()) + "_" + newLanguage; - if (!m_Translator->load(locFile, QCoreApplication::applicationDirPath() + "/translations")) { - qDebug("localization %s not found", locFile.toUtf8().constData()); - } - QCoreApplication::installTranslator(m_Translator); + m_CurrentLanguage = newLanguage; - // also add the translations for qt default strings - m_TranslatorQt = new QTranslator(this); - locFile = QString("qt_") + newLanguage; - if (!m_TranslatorQt->load(locFile, QCoreApplication::applicationDirPath() + "/translations")) { - qDebug("localization %s not found", locFile.toUtf8().constData()); + if (newLanguage != "en_US") { + installTranslator("qt"); + installTranslator(ToQString(AppConfig::translationPrefix())); + foreach(IPlugin *plugin, m_Settings.plugins()) { + QObject *pluginObj = dynamic_cast<QObject*>(plugin); + if (pluginObj != NULL) { + QVariant fileNameVariant = pluginObj->property("filename"); + if (fileNameVariant.isValid()) { + QString fileName = QFileInfo(fileNameVariant.toString()).baseName(); + m_Translators.push_back(installTranslator(fileName)); + } + } } - QCoreApplication::installTranslator(m_TranslatorQt); } ui->retranslateUi(this); ui->profileBox->setItemText(0, QObject::tr("<Manage...>")); |
