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

View File

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

View File

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

View File

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

View File

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