Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
QmlViewer: Translate UI
Install translators for the Qt & QmlViewer translations. also
add QT_NO_CAST_FROM_ASCII, QT_NO_CAST_TO_ASCII to check for untranslated
strings.

Reviewed-by: Oswald Buddenhagen
Task-number: QTBUG-14848

(cherry-picked from commit f33b31dcc1b8fd35501ab5b441a4529e2f8570f3)
  • Loading branch information
Kai Koehne committed May 10, 2011
1 parent f9b1989 commit 7b337d4
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 126 deletions.
14 changes: 7 additions & 7 deletions tools/qmlviewer/loggerwidget.cpp
Expand Up @@ -139,10 +139,10 @@ QAction *LoggerWidget::showAction()
void LoggerWidget::readSettings()
{
QSettings settings;
QString warningsPreferences = settings.value("warnings", "hide").toString();
if (warningsPreferences == "show") {
QString warningsPreferences = settings.value(QLatin1String("warnings"), QLatin1String("hide")).toString();
if (warningsPreferences == QLatin1String("show")) {
m_visibility = ShowWarnings;
} else if (warningsPreferences == "hide") {
} else if (warningsPreferences == QLatin1String("hide")) {
m_visibility = HideWarnings;
} else {
m_visibility = AutoShowWarnings;
Expand All @@ -154,15 +154,15 @@ void LoggerWidget::saveSettings()
if (m_visibilityOrigin != SettingsOrigin)
return;

QString value = "autoShow";
QString value = QLatin1String("autoShow");
if (defaultVisibility() == ShowWarnings) {
value = "show";
value = QLatin1String("show");
} else if (defaultVisibility() == HideWarnings) {
value = "hide";
value = QLatin1String("hide");
}

QSettings settings;
settings.setValue("warnings", value);
settings.setValue(QLatin1String("warnings"), value);
}

void LoggerWidget::warningsPreferenceChanged(QAction *action)
Expand Down
91 changes: 52 additions & 39 deletions tools/qmlviewer/main.cpp
Expand Up @@ -50,6 +50,7 @@
#include <QDebug>
#include <QMessageBox>
#include <QAtomicInt>
#include <QLibraryInfo>
#include "qdeclarativetester.h"
#include <private/qdeclarativedebughelper_p.h>

Expand All @@ -67,7 +68,7 @@ void exitApp(int i)
// Debugging output is not visible by default on Windows -
// therefore show modal dialog with errors instead.
if (!warnings.isEmpty()) {
QMessageBox::warning(0, QApplication::tr("Qt QML Viewer"), warnings);
QMessageBox::warning(0, QApplication::translate("QDeclarativeViewer", "Qt QML Viewer"), warnings);
}
#endif
exit(i);
Expand Down Expand Up @@ -123,7 +124,7 @@ void myMessageOutput(QtMsgType type, const char *msg)
static QDeclarativeViewer* globalViewer = 0;

// The qml file that is shown if the user didn't specify a QML file
QString initialFile = "qrc:/startup/startup.qml";
QString initialFile = QLatin1String("qrc:/startup/startup.qml");

void usage()
{
Expand Down Expand Up @@ -199,7 +200,7 @@ struct ViewerOptions
fps(0.0),
autorecord_from(0),
autorecord_to(0),
dither("none"),
dither(QLatin1String("none")),
runScript(false),
devkeys(false),
cache(0),
Expand Down Expand Up @@ -336,54 +337,54 @@ static void parseCommandLineOptions(const QStringList &arguments)
for (int i = 1; i < arguments.count(); ++i) {
bool lastArg = (i == arguments.count() - 1);
QString arg = arguments.at(i);
if (arg == "-frameless") {
if (arg == QLatin1String("-frameless")) {
opts.frameless = true;
} else if (arg == "-maximized") {
} else if (arg == QLatin1String("-maximized")) {
opts.maximized = true;
} else if (arg == "-fullscreen") {
} else if (arg == QLatin1String("-fullscreen")) {
opts.fullScreen = true;
} else if (arg == "-stayontop") {
} else if (arg == QLatin1String("-stayontop")) {
opts.stayOnTop = true;
} else if (arg == "-netcache") {
} else if (arg == QLatin1String("-netcache")) {
if (lastArg) usage();
opts.cache = arguments.at(++i).toInt();
} else if (arg == "-recordrate") {
} else if (arg == QLatin1String("-recordrate")) {
if (lastArg) usage();
opts.fps = arguments.at(++i).toDouble();
} else if (arg == "-recordfile") {
} else if (arg == QLatin1String("-recordfile")) {
if (lastArg) usage();
opts.recordfile = arguments.at(++i);
} else if (arg == "-record") {
} else if (arg == QLatin1String("-record")) {
if (lastArg) usage();
opts.recordargs << arguments.at(++i);
} else if (arg == "-recorddither") {
} else if (arg == QLatin1String("-recorddither")) {
if (lastArg) usage();
opts.dither = arguments.at(++i);
} else if (arg == "-autorecord") {
} else if (arg == QLatin1String("-autorecord")) {
if (lastArg) usage();
QString range = arguments.at(++i);
int dash = range.indexOf('-');
int dash = range.indexOf(QLatin1Char('-'));
if (dash > 0)
opts.autorecord_from = range.left(dash).toInt();
opts.autorecord_to = range.mid(dash+1).toInt();
} else if (arg == "-devicekeys") {
} else if (arg == QLatin1String("-devicekeys")) {
opts.devkeys = true;
} else if (arg == "-dragthreshold") {
} else if (arg == QLatin1String("-dragthreshold")) {
if (lastArg) usage();
qApp->setStartDragDistance(arguments.at(++i).toInt());
} else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) {
qWarning("Qt QML Viewer version %s", QT_VERSION_STR);
exitApp(0);
} else if (arg == "-translation") {
} else if (arg == QLatin1String("-translation")) {
if (lastArg) usage();
opts.translationFile = arguments.at(++i);
} else if (arg == "-no-opengl") {
} else if (arg == QLatin1String("-no-opengl")) {
opts.useGL = false;
} else if (arg == "-opengl") {
} else if (arg == QLatin1String("-opengl")) {
opts.useGL = true;
} else if (arg == "-qmlbrowser") {
} else if (arg == QLatin1String("-qmlbrowser")) {
opts.useNativeFileBrowser = false;
} else if (arg == "-warnings") {
} else if (arg == QLatin1String("-warnings")) {
if (lastArg) usage();
QString warningsStr = arguments.at(++i);
if (warningsStr == QLatin1String("show")) {
Expand All @@ -393,8 +394,8 @@ static void parseCommandLineOptions(const QStringList &arguments)
} else {
usage();
}
} else if (arg == "-I" || arg == "-L") {
if (arg == "-L")
} else if (arg == QLatin1String("-I") || arg == QLatin1String("-L")) {
if (arg == QLatin1String("-L"))
qWarning("-L option provided for compatibility only, use -I instead");
if (lastArg) {
QDeclarativeEngine tmpEngine;
Expand All @@ -403,32 +404,32 @@ static void parseCommandLineOptions(const QStringList &arguments)
exitApp(0);
}
opts.imports << arguments.at(++i);
} else if (arg == "-P") {
} else if (arg == QLatin1String("-P")) {
if (lastArg) usage();
opts.plugins << arguments.at(++i);
} else if (arg == "-script") {
} else if (arg == QLatin1String("-script")) {
if (lastArg) usage();
opts.script = arguments.at(++i);
} else if (arg == "-scriptopts") {
} else if (arg == QLatin1String("-scriptopts")) {
if (lastArg) usage();
opts.scriptopts = arguments.at(++i);
} else if (arg == "-savescript") {
} else if (arg == QLatin1String("-savescript")) {
if (lastArg) usage();
opts.script = arguments.at(++i);
opts.runScript = false;
} else if (arg == "-playscript") {
} else if (arg == QLatin1String("-playscript")) {
if (lastArg) usage();
opts.script = arguments.at(++i);
opts.runScript = true;
} else if (arg == "-sizeviewtorootobject") {
} else if (arg == QLatin1String("-sizeviewtorootobject")) {
opts.sizeToView = false;
} else if (arg == "-sizerootobjecttoview") {
} else if (arg == QLatin1String("-sizerootobjecttoview")) {
opts.sizeToView = true;
} else if (arg == "-experimentalgestures") {
} else if (arg == QLatin1String("-experimentalgestures")) {
opts.experimentalGestures = true;
} else if (!arg.startsWith('-')) {
} else if (!arg.startsWith(QLatin1Char('-'))) {
fileNames.append(arg);
} else if (true || arg == "-help") {
} else if (true || arg == QLatin1String("-help")) {
usage();
}
}
Expand Down Expand Up @@ -529,29 +530,41 @@ int main(int argc, char ** argv)
//### default to using raster graphics backend for now
bool gsSpecified = false;
for (int i = 0; i < argc; ++i) {
QString arg = argv[i];
if (arg == "-graphicssystem") {
QString arg = QString::fromAscii(argv[i]);
if (arg == QLatin1String("-graphicssystem")) {
gsSpecified = true;
break;
}
}

if (!gsSpecified)
QApplication::setGraphicsSystem("raster");
QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif

QDeclarativeDebugHelper::enableDebugging();

Application app(argc, argv);
app.setApplicationName("QtQmlViewer");
app.setOrganizationName("Nokia");
app.setOrganizationDomain("nokia.com");
app.setApplicationName(QLatin1String("QtQmlViewer"));
app.setOrganizationName(QLatin1String("Nokia"));
app.setOrganizationDomain(QLatin1String("nokia.com"));

QDeclarativeViewer::registerTypes();
QDeclarativeTester::registerTypes();

parseCommandLineOptions(app.arguments());

QTranslator translator;
QTranslator qtTranslator;
QString sysLocale = QLocale::system().name();
if (translator.load(QLatin1String("qmlviewer_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
app.installTranslator(&translator);
if (qtTranslator.load(QLatin1String("qt_") + sysLocale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
app.installTranslator(&qtTranslator);
} else {
app.removeTranslator(&translator);
}
}

QTranslator qmlTranslator;
if (!opts.translationFile.isEmpty()) {
if (qmlTranslator.load(opts.translationFile)) {
Expand Down
36 changes: 18 additions & 18 deletions tools/qmlviewer/proxysettings.cpp
Expand Up @@ -54,17 +54,17 @@ ProxySettings::ProxySettings (QWidget * parent)

#if !defined Q_WS_MAEMO_5
// the onscreen keyboard can't cope with masks
proxyServerEdit->setInputMask ("000.000.000.000;_");
proxyServerEdit->setInputMask(QLatin1String("000.000.000.000;_"));
#endif
QIntValidator *validator = new QIntValidator (0, 9999, this);
proxyPortEdit->setValidator (validator);
proxyPortEdit->setValidator(validator);

QSettings settings;
proxyCheckBox->setChecked (settings.value ("http_proxy/use", 0).toBool ());
proxyServerEdit->insert (settings.value ("http_proxy/hostname", "").toString ());
proxyPortEdit->insert (settings.value ("http_proxy/port", "80").toString ());
usernameEdit->insert (settings.value ("http_proxy/username", "").toString ());
passwordEdit->insert (settings.value ("http_proxy/password", "").toString ());
proxyCheckBox->setChecked(settings.value(QLatin1String("http_proxy/use"), 0).toBool());
proxyServerEdit->insert(settings.value(QLatin1String("http_proxy/hostname")).toString());
proxyPortEdit->insert(settings.value(QLatin1String("http_proxy/port"), QLatin1String("80")).toString ());
usernameEdit->insert(settings.value(QLatin1String("http_proxy/username")).toString ());
passwordEdit->insert(settings.value(QLatin1String("http_proxy/password")).toString ());
}

ProxySettings::~ProxySettings()
Expand All @@ -75,11 +75,11 @@ void ProxySettings::accept ()
{
QSettings settings;

settings.setValue ("http_proxy/use", proxyCheckBox->isChecked ());
settings.setValue ("http_proxy/hostname", proxyServerEdit->text ());
settings.setValue ("http_proxy/port", proxyPortEdit->text ());
settings.setValue ("http_proxy/username", usernameEdit->text ());
settings.setValue ("http_proxy/password", passwordEdit->text ());
settings.setValue(QLatin1String("http_proxy/use"), proxyCheckBox->isChecked());
settings.setValue(QLatin1String("http_proxy/hostname"), proxyServerEdit->text());
settings.setValue(QLatin1String("http_proxy/port"), proxyPortEdit->text());
settings.setValue(QLatin1String("http_proxy/username"), usernameEdit->text());
settings.setValue(QLatin1String("http_proxy/password"), passwordEdit->text());

QDialog::accept ();
}
Expand All @@ -89,13 +89,13 @@ QNetworkProxy ProxySettings::httpProxy ()
QSettings settings;
QNetworkProxy proxy;

bool proxyInUse = settings.value ("http_proxy/use", 0).toBool ();
bool proxyInUse = settings.value(QLatin1String("http_proxy/use"), 0).toBool();
if (proxyInUse) {
proxy.setType (QNetworkProxy::HttpProxy);
proxy.setHostName (settings.value ("http_proxy/hostname", "").toString ());// "192.168.220.5"
proxy.setPort (settings.value ("http_proxy/port", 80).toInt ()); // 8080
proxy.setUser (settings.value ("http_proxy/username", "").toString ());
proxy.setPassword (settings.value ("http_proxy/password", "").toString ());
proxy.setHostName (settings.value(QLatin1String("http_proxy/hostname")).toString());// "192.168.220.5"
proxy.setPort (settings.value(QLatin1String("http_proxy/port"), 80).toInt()); // 8080
proxy.setUser (settings.value(QLatin1String("http_proxy/username")).toString());
proxy.setPassword (settings.value(QLatin1String("http_proxy/password")).toString());
//QNetworkProxy::setApplicationProxy (proxy);
}
else {
Expand All @@ -107,7 +107,7 @@ QNetworkProxy ProxySettings::httpProxy ()
bool ProxySettings::httpProxyInUse()
{
QSettings settings;
return settings.value ("http_proxy/use", 0).toBool ();
return settings.value(QLatin1String("http_proxy/use"), 0).toBool();
}

QT_END_NAMESPACE
6 changes: 3 additions & 3 deletions tools/qmlviewer/proxysettings_maemo5.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>164</height>
<width>447</width>
<height>162</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -88,7 +88,7 @@
<item row="1" column="1">
<widget class="QLineEdit" name="proxyPortEdit">
<property name="text">
<string>8080</string>
<string notr="true">8080</string>
</property>
</widget>
</item>
Expand Down
10 changes: 5 additions & 5 deletions tools/qmlviewer/qdeclarativetester.cpp
Expand Up @@ -205,7 +205,7 @@ void QDeclarativeTester::save()
QString filename = m_script + QLatin1String(".qml");
QFileInfo filenameInfo(filename);
QDir saveDir = filenameInfo.absoluteDir();
saveDir.mkpath(".");
saveDir.mkpath(QLatin1String("."));

QFile file(filename);
file.open(QIODevice::WriteOnly);
Expand All @@ -224,8 +224,8 @@ void QDeclarativeTester::save()
if (!fe.hash.isEmpty()) {
ts << " hash: \"" << fe.hash.toHex() << "\"\n";
} else if (!fe.image.isNull()) {
QString filename = filenameInfo.baseName() + "." + QString::number(imgCount) + ".png";
fe.image.save(m_script + "." + QString::number(imgCount) + ".png");
QString filename = filenameInfo.baseName() + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png");
fe.image.save(m_script + QLatin1String(".") + QString::number(imgCount) + QLatin1String(".png"));
imgCount++;
ts << " image: \"" << filename << "\"\n";
}
Expand Down Expand Up @@ -375,7 +375,7 @@ void QDeclarativeTester::updateCurrentTime(int msec)
imagefailure();
}
if (goodImage != img) {
QString reject(frame->image().toLocalFile() + ".reject.png");
QString reject(frame->image().toLocalFile() + QLatin1String(".reject.png"));
qWarning() << "QDeclarativeTester(" << m_script << "): Image mismatch. Reject saved to:"
<< reject;
img.save(reject);
Expand All @@ -393,7 +393,7 @@ void QDeclarativeTester::updateCurrentTime(int msec)
}
}
}
QString diff(frame->image().toLocalFile() + ".diff.png");
QString diff(frame->image().toLocalFile() + QLatin1String(".diff.png"));
diffimg.save(diff);
qWarning().nospace() << " Diff (" << diffCount << " pixels differed) saved to: " << diff;
}
Expand Down

0 comments on commit 7b337d4

Please sign in to comment.