Restore Qt4 compat in QDesktopServices::DataLocation
"/data/" was appended to the base directory. Change-Id: I220f2ce74c36b795bc49c7c84106feb0709d1547 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
ad81f75429
commit
518a4cb5ab
|
|
@ -54,6 +54,7 @@
|
|||
#include <qmutex.h>
|
||||
#include <qplatformservices_qpa.h>
|
||||
#include <qplatformintegration_qpa.h>
|
||||
#include <qdir.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -283,6 +284,23 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme)
|
|||
Use QStandardPaths::displayName()
|
||||
*/
|
||||
|
||||
|
||||
QString QDesktopServices::storageLocationImpl(StandardLocation type)
|
||||
{
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||
if (type == DataLocation) {
|
||||
QString xdgDataHome = QLatin1String(qgetenv("XDG_DATA_HOME"));
|
||||
if (xdgDataHome.isEmpty())
|
||||
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
|
||||
xdgDataHome += QLatin1String("/data/")
|
||||
+ QCoreApplication::organizationName() + QLatin1Char('/')
|
||||
+ QCoreApplication::applicationName();
|
||||
return xdgDataHome;
|
||||
}
|
||||
#endif
|
||||
return QStandardPaths::writableLocation(static_cast<QStandardPaths::StandardLocation>(type));
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "qdesktopservices.moc"
|
||||
|
|
|
|||
|
|
@ -79,12 +79,14 @@ public:
|
|||
};
|
||||
|
||||
QT_DEPRECATED static QString storageLocation(StandardLocation type) {
|
||||
return QStandardPaths::writableLocation(static_cast<QStandardPaths::StandardLocation>(type));
|
||||
return storageLocationImpl(type);
|
||||
}
|
||||
QT_DEPRECATED static QString displayName(StandardLocation type) {
|
||||
return QStandardPaths::displayName(static_cast<QStandardPaths::StandardLocation>(type));
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
static QString storageLocationImpl(StandardLocation type);
|
||||
};
|
||||
|
||||
#endif // QT_NO_DESKTOPSERVICES
|
||||
|
|
|
|||
|
|
@ -57,12 +57,11 @@ private slots:
|
|||
void cleanup();
|
||||
void openUrl();
|
||||
void handlers();
|
||||
void testDataLocation();
|
||||
};
|
||||
|
||||
tst_qdesktopservices::tst_qdesktopservices()
|
||||
{
|
||||
QCoreApplication::setOrganizationName("Nokia");
|
||||
QCoreApplication::setApplicationName("tst_qdesktopservices");
|
||||
}
|
||||
|
||||
tst_qdesktopservices::~tst_qdesktopservices()
|
||||
|
|
@ -117,5 +116,37 @@ void tst_qdesktopservices::handlers()
|
|||
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||
#define Q_XDG_PLATFORM
|
||||
#endif
|
||||
|
||||
void tst_qdesktopservices::testDataLocation()
|
||||
{
|
||||
// This is the one point where QDesktopServices and QStandardPaths differ.
|
||||
// QDesktopServices on unix returns "data"/orgname/appname for DataLocation, for Qt4 compat.
|
||||
// And the appname in qt4 defaulted to empty, not to argv[0].
|
||||
{
|
||||
const QString base = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
||||
const QString app = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#ifdef Q_XDG_PLATFORM
|
||||
QCOMPARE(app, base + "/data//"); // as ugly as in Qt4
|
||||
#else
|
||||
QCOMPARE(app, base);
|
||||
#endif
|
||||
}
|
||||
QCoreApplication::instance()->setOrganizationName("Qt");
|
||||
QCoreApplication::instance()->setApplicationName("QtTest");
|
||||
{
|
||||
const QString base = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
||||
const QString app = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#ifdef Q_XDG_PLATFORM
|
||||
QCOMPARE(app, base + "/data/Qt/QtTest");
|
||||
#else
|
||||
QCOMPARE(app, base + "/Qt/QtTest");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qdesktopservices)
|
||||
|
||||
#include "tst_qdesktopservices.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue