qmlpreview: fix init locale issue

The init language was never found, because the
findValidI18nDirectoryAsUrl() uses the m_lastLoadedUrl
to find the translation file path.

Change-Id: I6e9b62f3d846795d68ddef5e3a4caf3e3d953c7c
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Tim Jenssen
2020-07-21 13:57:29 +02:00
parent b1fc2cdbb4
commit ce926844d0
5 changed files with 25 additions and 13 deletions

View File

@@ -119,9 +119,14 @@ void QmlPreviewConnectionManager::createDebugTranslationClient()
QObject::connect(this, &QmlPreviewConnectionManager::language,
m_qmlDebugTranslationClient.data(), [this](const QString &locale) {
if (m_lastLoadedUrl.isEmpty()) {
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
m_initLocale = locale;
} else {
// service expects a context URL.
// Search the parent directories of the last loaded URL for i18n files.
m_qmlDebugTranslationClient->changeLanguage(findValidI18nDirectoryAsUrl(locale), locale);
}
});
QObject::connect(m_qmlDebugTranslationClient.data(), &QmlDebugTranslationClient::debugServiceUnavailable,
this, []() {
@@ -152,6 +157,10 @@ void QmlPreviewConnectionManager::createPreviewClient()
m_lastLoadedUrl = m_targetFileFinder.findUrl(filename);
m_qmlPreviewClient->loadUrl(m_lastLoadedUrl);
if (!m_initLocale.isEmpty()) {
emit language(m_initLocale);
m_initLocale.clear();
}
});
QObject::connect(this, &QmlPreviewConnectionManager::rerun,
@@ -163,9 +172,14 @@ void QmlPreviewConnectionManager::createPreviewClient()
QObject::connect(this, &QmlPreviewConnectionManager::language,
m_qmlPreviewClient.data(), [this](const QString &locale) {
if (m_lastLoadedUrl.isEmpty()) {
// findValidI18nDirectoryAsUrl does not work if we didn't load any file
m_initLocale = locale;
} else {
// service expects a context URL.
// Search the parent directories of the last loaded URL for i18n files.
m_qmlPreviewClient->language(findValidI18nDirectoryAsUrl(locale), locale);
}
});
QObject::connect(m_qmlPreviewClient.data(), &QmlPreviewClient::pathRequested,

View File

@@ -78,6 +78,7 @@ private:
QmlPreviewFileLoader m_fileLoader = nullptr;
QmlPreviewFileClassifier m_fileClassifier = nullptr;
QmlPreviewFpsHandler m_fpsHandler = nullptr;
QString m_initLocale;
};
} // namespace Internal

View File

@@ -154,7 +154,7 @@ public:
RunWorkerFactory runWorkerFactory{
[this](RunControl *runControl) {
QmlPreviewRunner *runner = new QmlPreviewRunner(runControl, m_fileLoader, m_fileClassifer,
m_fpsHandler, m_zoomFactor, m_locale);
m_fpsHandler, m_zoomFactor);
connect(q, &QmlPreviewPlugin::updatePreviews,
runner, &QmlPreviewRunner::loadFile);
connect(q, &QmlPreviewPlugin::rerunPreviews,

View File

@@ -49,8 +49,7 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
QmlPreviewFileLoader fileLoader,
QmlPreviewFileClassifier fileClassifier,
QmlPreviewFpsHandler fpsHandler,
float initialZoom,
const QString &initialLocale)
float initialZoom)
: RunWorker(runControl)
{
setId("QmlPreviewRunner");
@@ -68,11 +67,9 @@ QmlPreviewRunner::QmlPreviewRunner(ProjectExplorer::RunControl *runControl,
connect(this, &QmlPreviewRunner::language,
&m_connectionManager, &Internal::QmlPreviewConnectionManager::language);
connect(&m_connectionManager, &Internal::QmlPreviewConnectionManager::connectionOpened,
this, [this, initialZoom, initialLocale]() {
this, [this, initialZoom]() {
if (initialZoom > 0)
emit zoom(initialZoom);
if (!initialLocale.isEmpty())
emit language(initialLocale);
emit ready();
});

View File

@@ -39,7 +39,7 @@ class QmlPreviewRunner : public ProjectExplorer::RunWorker
public:
QmlPreviewRunner(ProjectExplorer::RunControl *runControl, QmlPreviewFileLoader fileLoader,
QmlPreviewFileClassifier fileClassifier, QmlPreviewFpsHandler fpsHandler,
float initialZoom, const QString &initialLocale);
float initialZoom);
void setServerUrl(const QUrl &serverUrl);
QUrl serverUrl() const;