Skip to content

Commit 3ae56c0

Browse files
author
Shane Kearns
committed
symbian - search drives for translation files
Qt may be installed on a different drive from the application, particularly the case when Qt is included in ROM (Z:) and the application is on C: With this change, if QTranslator::load() specifies an absolute directory in the filesystem (e.g. "/resource/qt/translations") without a drive letter, then the symbian search paths are used. Note that this example path is the one returned by QLibraryInfo so applications using the example code from http://doc.qt.nokia.com/latest/internationalization.html#produce-translations will work as expected. Task-number: QT-5246 Reviewed-by: mread
1 parent c47cd8f commit 3ae56c0

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/corelib/kernel/qtranslator.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "qcoreapplication.h"
5151
#include "qcoreapplication_p.h"
5252
#include "qdatastream.h"
53+
#include "qdir.h"
5354
#include "qfile.h"
5455
#include "qmap.h"
5556
#include "qalgorithms.h"
@@ -61,6 +62,10 @@
6162
#include "private/qcore_unix_p.h"
6263
#endif
6364

65+
#ifdef Q_OS_SYMBIAN
66+
#include "private/qcore_symbian_p.h"
67+
#endif
68+
6469
// most of the headers below are already included in qplatformdefs.h
6570
// also this lacks Large File support but that's probably irrelevant
6671
#if defined(QT_USE_MMAP)
@@ -402,11 +407,24 @@ bool QTranslator::load(const QString & filename, const QString & directory,
402407

403408
QString prefix;
404409
if (QFileInfo(filename).isRelative()) {
410+
#ifdef Q_OS_SYMBIAN
411+
if(directory.isEmpty())
412+
prefix = QCoreApplication::applicationDirPath();
413+
else
414+
prefix = QFileInfo(directory).absoluteFilePath(); //TFindFile doesn't like dirty paths
415+
if (prefix.length() > 2 && prefix.at(1) == QLatin1Char(':') && prefix.at(0).isLetter())
416+
prefix[0] = QLatin1Char('Y');
417+
#else
405418
prefix = directory;
406-
if (prefix.length() && !prefix.endsWith(QLatin1Char('/')))
407-
prefix += QLatin1Char('/');
419+
#endif
420+
if (prefix.length() && !prefix.endsWith(QLatin1Char('/')))
421+
prefix += QLatin1Char('/');
408422
}
409423

424+
#ifdef Q_OS_SYMBIAN
425+
QString nativePrefix = QDir::toNativeSeparators(prefix);
426+
#endif
427+
410428
QString fname = filename;
411429
QString realname;
412430
QString delims;
@@ -415,6 +433,24 @@ bool QTranslator::load(const QString & filename, const QString & directory,
415433
for (;;) {
416434
QFileInfo fi;
417435

436+
#ifdef Q_OS_SYMBIAN
437+
//search for translations on other drives, e.g. Qt may be in Z, while app is in C
438+
//note this uses symbian search rules, i.e. y:->a:, followed by z:
439+
TFindFile finder(qt_s60GetRFs());
440+
QString fname2 = fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix);
441+
TInt err = finder.FindByDir(
442+
qt_QString2TPtrC(fname2),
443+
qt_QString2TPtrC(nativePrefix));
444+
if (err != KErrNone)
445+
err = finder.FindByDir(qt_QString2TPtrC(fname), qt_QString2TPtrC(nativePrefix));
446+
if (err == KErrNone) {
447+
fi.setFile(qt_TDesC2QString(finder.File()));
448+
realname = fi.canonicalFilePath();
449+
if (fi.isReadable() && fi.isFile())
450+
break;
451+
}
452+
#endif
453+
418454
realname = prefix + fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix);
419455
fi.setFile(realname);
420456
if (fi.isReadable() && fi.isFile())

0 commit comments

Comments
 (0)