2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
2012-02-21 14:36:01 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/QSet>
|
2011-12-08 11:38:48 +00:00
|
|
|
#include <QtCore/QFile>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/QTranslator>
|
2012-01-11 15:20:29 +00:00
|
|
|
#include <QtCore/QTemporaryDir>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <private/qthread_p.h>
|
Expose QPA API under qpa/*
The main reasons for doing this are:
1. _qpa.h end up in the master QtGui include file. QtGui is meant for
userland applications. qpa code is neither binary nor source compatible.
Inadvertant use of QPA api makes the user code binary-incompatible.
2. syncqt creates forwarding headers for non-private header files. This
gives people the impression that this is public API.
As discussed on the mailing list, even though QPA api is internal and subject
to change, it needs to treated differently from private headers since they
will be used by in-qtbase and out-of-qtbase plugins.
This commit does the following:
1. The _qpa in QPA header files is dropped.
2. syncqt now treats any file with qplatform prefix as a special file and
moves it to qpa/ directory. The recommended way of using QPA API in plugins
is: #include <qpa/qplatformfoo.h>. This allows the user include QPA API
from multiple modules (for example, qplatformfoo might be in QtPrintSupport)
3. The user needs to explicitly add QT += <module>-private to get access to
the qpa api.
4. Creates compat headers for the olden style qplatformfoo_qpa.h and QPlatformFoo
includes.
This commit does not change the cpp filenames. This requires a more careful
merging of existing non qpa cpp files and existing cpp files on a case by
case basis. This can be done at anytime.
The following files are not renamed as part of this changed but will be fixed
as part of a future change:
src/gui/kernel/qgenericpluginfactory_qpa.h
src/gui/kernel/qgenericplugin_qpa.h
src/gui/kernel/qwindowsysteminterface_qpa.h
files were renamed using
for x in `find . -name "qplatform*_qpa.h"`; do git mv $x "${x/_qpa.h/.h}"; done
for x in `find . -name "qplatform*_qpa_p.h"`; do git mv $x "${x/_qpa_p.h/_p.h}"; done
includes were renamed using script
for file in `find . -name "*.h" -or -name "*.cpp" -or -name "*.mm"`; do
sed -i -e 's,.*#.*include.*<\(Qt.*/\)\?\(QPlatform.*\)>,#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.*"\(Qt.*/\)\?\(QPlatform.*\)",#include <qpa/\L\2.h>,g' \
-e 's,.*#.*include.* "\(qplatform.*\)_qpa.h",#include <qpa/\L\1.h>,g' \
-e 's,.*#.*include.*"\(qplatform.*\)_qpa_p.h",#include <qpa/\L\1_p.h>,g' \
-e 's,.*#.*include.*<\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)>,#include <qpa/\2\3>,g' \
-e 's,.*#.*include.*"\(Qt.*/\|Qt.*/private/\|private/\)\?\(qplatform.*\)_qpa\(.*\)",#include <qpa/\2\3>,g' \
$file
done
Change-Id: I04a350314a45746e3911f54b3b21ad03315afb67
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
2012-04-26 23:33:35 +00:00
|
|
|
#include <qpa/qplatformtheme.h>
|
2011-05-23 14:49:06 +00:00
|
|
|
#include <QtWidgets/QInputDialog>
|
|
|
|
#include <QtWidgets/QColorDialog>
|
2012-02-21 14:36:01 +00:00
|
|
|
#include <QtWidgets/QDialogButtonBox>
|
2011-05-23 14:49:06 +00:00
|
|
|
#include <QtWidgets/QFileDialog>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_languageChange : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_languageChange();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
private slots:
|
|
|
|
void retranslatability_data();
|
|
|
|
void retranslatability();
|
|
|
|
|
2012-02-21 14:36:01 +00:00
|
|
|
private:
|
|
|
|
QDialogButtonBox::ButtonLayout m_layout;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-21 14:36:01 +00:00
|
|
|
tst_languageChange::tst_languageChange() :
|
|
|
|
m_layout(QDialogButtonBox::WinLayout)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-21 14:36:01 +00:00
|
|
|
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
|
|
|
|
m_layout = static_cast<QDialogButtonBox::ButtonLayout>(theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_languageChange::initTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_languageChange::cleanupTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Records all calls to translate()
|
|
|
|
*/
|
|
|
|
class TransformTranslator : public QTranslator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TransformTranslator() : QTranslator() {}
|
|
|
|
TransformTranslator(QObject *parent) : QTranslator(parent) {}
|
2011-12-08 11:38:48 +00:00
|
|
|
QString translate(const char *context, const char *sourceText,
|
|
|
|
const char *disambiguation = 0, int = -1) const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QByteArray total(context);
|
|
|
|
total.append("::");
|
|
|
|
total.append(sourceText);
|
2011-12-08 11:38:48 +00:00
|
|
|
if (disambiguation) {
|
2011-04-27 10:05:43 +00:00
|
|
|
total.append("::");
|
2011-12-08 11:38:48 +00:00
|
|
|
total.append(disambiguation);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
m_translations.insert(total);
|
|
|
|
QString res;
|
|
|
|
for (int i = 0; i < int(qstrlen(sourceText)); ++i) {
|
|
|
|
QChar ch = QLatin1Char(sourceText[i]);
|
|
|
|
if (ch.isLower()) {
|
|
|
|
res.append(ch.toUpper());
|
|
|
|
} else if (ch.isUpper()) {
|
|
|
|
res.append(ch.toLower());
|
|
|
|
} else {
|
|
|
|
res.append(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEmpty() const { return false; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
mutable QSet<QByteArray> m_translations;
|
|
|
|
};
|
|
|
|
|
2012-01-11 15:20:29 +00:00
|
|
|
// Install the translator and close all application windows after a while to
|
|
|
|
// quit the event loop.
|
|
|
|
class LanguageTestStateMachine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
LanguageTestStateMachine(QTranslator *translator);
|
|
|
|
void start() { m_timer.start(); }
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void timeout();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum State { InstallTranslator, CloseDialog };
|
|
|
|
|
|
|
|
QTimer m_timer;
|
|
|
|
QTranslator *m_translator;
|
|
|
|
State m_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
LanguageTestStateMachine::LanguageTestStateMachine(QTranslator *translator) :
|
|
|
|
m_translator(translator), m_state(InstallTranslator)
|
|
|
|
{
|
|
|
|
m_timer.setInterval(500);
|
|
|
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageTestStateMachine::timeout()
|
|
|
|
{
|
|
|
|
switch (m_state) {
|
|
|
|
case InstallTranslator:
|
|
|
|
m_timer.stop();
|
|
|
|
QCoreApplication::installTranslator(m_translator);
|
|
|
|
m_timer.setInterval(2500);
|
|
|
|
m_timer.start();
|
|
|
|
m_state = CloseDialog;
|
|
|
|
break;
|
|
|
|
case CloseDialog: // Close repeatedly in case file dialog is slow.
|
|
|
|
QApplication::closeAllWindows();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
enum DialogType {
|
|
|
|
InputDialog = 1,
|
|
|
|
ColorDialog,
|
|
|
|
FileDialog
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef QSet<QByteArray> TranslationSet;
|
|
|
|
Q_DECLARE_METATYPE(TranslationSet)
|
|
|
|
|
|
|
|
void tst_languageChange::retranslatability_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("dialogType");
|
|
|
|
QTest::addColumn<TranslationSet >("expected");
|
|
|
|
|
|
|
|
//next we fill it with data
|
|
|
|
QTest::newRow( "QInputDialog" )
|
|
|
|
<< int(InputDialog) << (QSet<QByteArray>()
|
2014-01-08 14:12:43 +00:00
|
|
|
<< "QPlatformTheme::Cancel");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTest::newRow( "QColorDialog" )
|
|
|
|
<< int(ColorDialog) << (QSet<QByteArray>()
|
2014-01-08 14:12:43 +00:00
|
|
|
<< "QPlatformTheme::Cancel"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "QColorDialog::&Sat:"
|
|
|
|
<< "QColorDialog::&Add to Custom Colors"
|
|
|
|
<< "QColorDialog::&Green:"
|
|
|
|
<< "QColorDialog::&Red:"
|
|
|
|
<< "QColorDialog::Bl&ue:"
|
|
|
|
<< "QColorDialog::A&lpha channel:"
|
|
|
|
<< "QColorDialog::&Basic colors"
|
|
|
|
<< "QColorDialog::&Custom colors"
|
|
|
|
<< "QColorDialog::&Val:"
|
|
|
|
<< "QColorDialog::Hu&e:");
|
|
|
|
|
|
|
|
QTest::newRow( "QFileDialog" )
|
|
|
|
<< int(FileDialog) << (QSet<QByteArray>()
|
|
|
|
<< "QFileDialog::All Files (*)"
|
|
|
|
<< "QFileDialog::Back"
|
|
|
|
<< "QFileDialog::Create New Folder"
|
|
|
|
<< "QFileDialog::Detail View"
|
|
|
|
<< "QFileDialog::Files of type:"
|
|
|
|
<< "QFileDialog::Forward"
|
|
|
|
<< "QFileDialog::List View"
|
|
|
|
<< "QFileDialog::Look in:"
|
|
|
|
<< "QFileDialog::Open"
|
|
|
|
<< "QFileDialog::Parent Directory"
|
|
|
|
<< "QFileDialog::Show "
|
|
|
|
<< "QFileDialog::Show &hidden files"
|
|
|
|
<< "QFileDialog::&Delete"
|
|
|
|
<< "QFileDialog::&New Folder"
|
|
|
|
<< "QFileDialog::&Rename"
|
|
|
|
<< "QFileSystemModel::Date Modified"
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
<< "QFileSystemModel::My Computer"
|
|
|
|
#else
|
|
|
|
<< "QFileSystemModel::Computer"
|
|
|
|
#endif
|
|
|
|
<< "QFileSystemModel::Size"
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
<< "QFileSystemModel::Kind::Match OS X Finder"
|
|
|
|
#else
|
|
|
|
<< "QFileSystemModel::Type::All other platforms"
|
|
|
|
#endif
|
|
|
|
// << "QFileSystemModel::%1 KB"
|
2014-01-08 14:12:43 +00:00
|
|
|
<< "QPlatformTheme::Cancel"
|
|
|
|
<< "QPlatformTheme::Open"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "QFileDialog::File &name:");
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_languageChange::retranslatability()
|
|
|
|
{
|
|
|
|
QFETCH( int, dialogType);
|
|
|
|
QFETCH( TranslationSet, expected);
|
|
|
|
|
2012-02-21 14:36:01 +00:00
|
|
|
if (m_layout == QDialogButtonBox::GnomeLayout)
|
|
|
|
QSKIP("The input data are not suitable for this layout (QDialogButtonBox::GnomeLayout)");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// This will always be queried for when a language changes
|
2015-02-03 13:54:52 +00:00
|
|
|
expected.insert("QGuiApplication::QT_LAYOUT_DIRECTION::Translate this string to the string 'LTR' in left-to-right "
|
2011-12-08 11:38:48 +00:00
|
|
|
"languages or to 'RTL' in right-to-left languages (such as Hebrew and Arabic) to "
|
|
|
|
"get proper widget layout.");
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
TransformTranslator translator;
|
2012-01-11 15:20:29 +00:00
|
|
|
LanguageTestStateMachine stateMachine(&translator);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
switch (dialogType) {
|
|
|
|
case InputDialog:
|
2012-01-11 15:20:29 +00:00
|
|
|
stateMachine.start();
|
2015-08-24 11:35:22 +00:00
|
|
|
QInputDialog::getInt(0, QLatin1String("title"), QLatin1String("label"));
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ColorDialog:
|
2011-12-08 11:38:48 +00:00
|
|
|
#ifdef Q_OS_MAC
|
2011-10-19 02:53:13 +00:00
|
|
|
QSKIP("The native color dialog is used on Mac OS");
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
2012-01-11 15:20:29 +00:00
|
|
|
stateMachine.start();
|
|
|
|
QColorDialog::getColor();
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case FileDialog: {
|
|
|
|
QFileDialog dlg;
|
|
|
|
dlg.setOption(QFileDialog::DontUseNativeDialog);
|
2012-01-11 15:20:29 +00:00
|
|
|
QString tempDirPattern = QDir::tempPath();
|
|
|
|
if (!tempDirPattern.endsWith(QLatin1Char('/')))
|
|
|
|
tempDirPattern += QLatin1Char('/');
|
|
|
|
tempDirPattern += QStringLiteral("languagechangetestdirXXXXXX");
|
|
|
|
QTemporaryDir temporaryDir(tempDirPattern);
|
|
|
|
temporaryDir.setAutoRemove(true);
|
2015-09-24 13:56:57 +00:00
|
|
|
QVERIFY2(temporaryDir.isValid(), qPrintable(temporaryDir.errorString()));
|
2012-01-11 15:20:29 +00:00
|
|
|
const QString finalDir = temporaryDir.path() + QStringLiteral("/finaldir");
|
|
|
|
const QString fooName = temporaryDir.path() + QStringLiteral("/foo");
|
2011-04-27 10:05:43 +00:00
|
|
|
QDir dir;
|
2012-01-11 15:20:29 +00:00
|
|
|
QVERIFY(dir.mkpath(finalDir));
|
2011-12-08 11:38:48 +00:00
|
|
|
QFile fooFile(fooName);
|
|
|
|
QVERIFY(fooFile.open(QIODevice::WriteOnly|QIODevice::Text));
|
|
|
|
fooFile.write("test");
|
|
|
|
fooFile.close();
|
2012-01-11 15:20:29 +00:00
|
|
|
dlg.setDirectory(temporaryDir.path());
|
2011-04-27 10:05:43 +00:00
|
|
|
dlg.setFileMode(QFileDialog::ExistingFiles);
|
|
|
|
dlg.setViewMode(QFileDialog::Detail);
|
2012-01-11 15:20:29 +00:00
|
|
|
stateMachine.start();
|
2011-04-27 10:05:43 +00:00
|
|
|
dlg.exec();
|
|
|
|
QTest::qWait(3000);
|
|
|
|
break; }
|
|
|
|
}
|
2011-10-28 07:04:19 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// In case we use a Color dialog, we do not want to test for
|
|
|
|
// strings non existing in the dialog and which do not get
|
|
|
|
// translated.
|
2016-03-10 13:38:37 +00:00
|
|
|
const QSize desktopSize = QApplication::desktop()->size();
|
|
|
|
if (dialogType == ColorDialog && (desktopSize.width() < 480 || desktopSize.height() < 350)) {
|
2011-04-27 10:05:43 +00:00
|
|
|
expected.remove("QColorDialog::&Basic colors");
|
|
|
|
expected.remove("QColorDialog::&Custom colors");
|
|
|
|
expected.remove("QColorDialog::&Define Custom Colors >>");
|
|
|
|
expected.remove("QColorDialog::&Add to Custom Colors");
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if all of our *expected* translations was translated.
|
|
|
|
// (There might be more, but thats not that bad)
|
|
|
|
QSet<QByteArray> commonTranslations = expected;
|
|
|
|
commonTranslations.intersect(translator.m_translations);
|
|
|
|
if (!expected.subtract(commonTranslations).isEmpty()) {
|
|
|
|
qDebug() << "Missing:" << expected;
|
|
|
|
if (!translator.m_translations.subtract(commonTranslations).isEmpty())
|
|
|
|
qDebug() << "Unexpected:" << translator.m_translations;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(expected.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_languageChange)
|
|
|
|
#include "tst_languagechange.moc"
|