summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@jollamobile.com>2013-12-03 11:23:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-03 12:46:21 +0100
commitc8f86040f6163710aff986446766acb69d1cb92a (patch)
tree5d5d45249a7cf2b10619dfd0c6da1a708f2e7b4d
parentf93c49b9a7d1e6e48a4ebe3cb0a5ee2c6aec1727 (diff)
Fix DocumentGallery returning encoded urls.
Tracker stores url properties in encoded form, these need to be decoded before they are returned and encoded when used in queries. Cherry pick of c4a36f94bd50d0236aaa7bddbe72bc7e0fbdac4f from qt-mobility. Change-Id: I8075490d6079311b94fe1234857a69af88218dc6 Reviewed-by: Marko Mattila <marko.mattila@jollamobile.com> Reviewed-by: Christopher Adams <chris.adams@jollamobile.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/gallery/tracker/qgallerytrackerlistcolumn.cpp13
-rw-r--r--src/gallery/tracker/qgallerytrackerlistcolumn_p.h6
-rw-r--r--src/gallery/tracker/qgallerytrackerschema.cpp82
-rw-r--r--tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp95
4 files changed, 152 insertions, 44 deletions
diff --git a/src/gallery/tracker/qgallerytrackerlistcolumn.cpp b/src/gallery/tracker/qgallerytrackerlistcolumn.cpp
index 145a278..c93d4f9 100644
--- a/src/gallery/tracker/qgallerytrackerlistcolumn.cpp
+++ b/src/gallery/tracker/qgallerytrackerlistcolumn.cpp
@@ -60,6 +60,11 @@ QVariant QGalleryTrackerStringListColumn::toVariant(const QString &string) const
return string.split(m_separatorChar, QString::SkipEmptyParts);
}
+QVariant QGalleryTrackerUrlColumn::toVariant(const QString &string) const
+{
+ return QUrl::fromEncoded(string.toUtf8(), QUrl::StrictMode);
+}
+
QString QGalleryTrackerStringListColumn::toString(const QVariant &variant) const
{
return variant.type() == QVariant::StringList
@@ -117,7 +122,7 @@ QVariant QGalleryTrackerCompositeIdColumn::value(QVector<QVariant>::const_iterat
QVariant QGalleryTrackerFileUrlColumn::value(QVector<QVariant>::const_iterator row) const
{
- return QUrl( (row + m_column )->toString());
+ return *(row + m_column);
}
QGalleryTrackerCompositeColumn *QGalleryTrackerFileUrlColumn::create(const QVector<int> &)
@@ -127,7 +132,7 @@ QGalleryTrackerCompositeColumn *QGalleryTrackerFileUrlColumn::create(const QVect
QVariant QGalleryTrackerFilePathColumn::value(QVector<QVariant>::const_iterator row) const
{
- return QUrl( (row + QGALLERYTRACKERFILEURLCOLUMN_DEFAULT_COL)->toString() ).path();
+ return (row + QGALLERYTRACKERFILEURLCOLUMN_DEFAULT_COL)->toUrl().path();
}
QGalleryTrackerCompositeColumn *QGalleryTrackerFilePathColumn::create(const QVector<int> &)
@@ -137,7 +142,7 @@ QGalleryTrackerCompositeColumn *QGalleryTrackerFilePathColumn::create(const QVec
QVariant QGalleryTrackerPathColumn::value(QVector<QVariant>::const_iterator row) const
{
- QString filePath = QUrl((row + QGALLERYTRACKERFILEURLCOLUMN_DEFAULT_COL)->toString()).path();
+ QString filePath = (row + QGALLERYTRACKERFILEURLCOLUMN_DEFAULT_COL)->toUrl().path();
return filePath.section(QLatin1Char('/'), 0, -2);
}
@@ -148,7 +153,7 @@ QGalleryTrackerCompositeColumn *QGalleryTrackerPathColumn::create(const QVector<
QVariant QGalleryTrackerFileExtensionColumn::value(QVector<QVariant>::const_iterator row) const
{
- QString fileName = (row + m_column)->toString();
+ QString fileName = (row + m_column)->toUrl().path();
const int index = fileName.lastIndexOf(QLatin1Char('.'));
return index > fileName.lastIndexOf(QLatin1Char('/'))
? QVariant(fileName.mid(index + 1))
diff --git a/src/gallery/tracker/qgallerytrackerlistcolumn_p.h b/src/gallery/tracker/qgallerytrackerlistcolumn_p.h
index 27b0ed7..90cb9b9 100644
--- a/src/gallery/tracker/qgallerytrackerlistcolumn_p.h
+++ b/src/gallery/tracker/qgallerytrackerlistcolumn_p.h
@@ -85,6 +85,12 @@ public:
QVariant toVariant(const QString &string) const;
};
+class QGalleryTrackerUrlColumn : public QGalleryTrackerValueColumn
+{
+public:
+ QVariant toVariant(const QString &string) const;
+};
+
class QGalleryTrackerStringListColumn : public QGalleryTrackerValueColumn
{
public:
diff --git a/src/gallery/tracker/qgallerytrackerschema.cpp b/src/gallery/tracker/qgallerytrackerschema.cpp
index d4e369e..ae40560 100644
--- a/src/gallery/tracker/qgallerytrackerschema.cpp
+++ b/src/gallery/tracker/qgallerytrackerschema.cpp
@@ -401,20 +401,28 @@ static bool qt_write_comparison(
const QLatin1String &field,
const QVariant &value,
const char *op,
- QString *query)
+ QString *query,
+ QVariant::Type type = QVariant::String)
{
- if (value.canConvert(QVariant::String)) {
- *query += QLatin1String("(")
- + field
- + QLatin1String(op)
- + QLatin1String("'")
- + value.toString()
- + QLatin1String("')");
- return true;
+ QString stringValue;
+ if (type == QVariant::Url && value.canConvert(QVariant::Url)) {
+ QByteArray encodedUrl = value.toUrl().toEncoded();
+ stringValue = QString::fromUtf8(encodedUrl.data(), encodedUrl.length());
+ } else if (value.canConvert(QVariant::String)) {
+ stringValue = value.toString();
} else {
*error = QDocumentGallery::FilterError;
return false;
}
+
+ *query += QLatin1String("(")
+ + field
+ + QLatin1String(op)
+ + QLatin1String("'")
+ + stringValue
+ + QLatin1String("')");
+
+ return true;
}
static bool qt_write_function(
@@ -438,20 +446,28 @@ static bool qt_write_function(
const char *function,
const QString &field,
const QVariant &value,
- QString *query)
+ QString *query,
+ QVariant::Type type = QVariant::String)
{
- if (value.canConvert(QVariant::String)) {
- *query += QLatin1String(function)
- + QLatin1String("(")
- + field
- + QLatin1String(",'")
- + value.toString()
- + QLatin1String("')");
- return true;
+ QString stringValue;
+ if (type == QVariant::Url && value.canConvert(QVariant::Url)) {
+ QByteArray encodedUrl = value.toUrl().toEncoded();
+ stringValue = QString::fromUtf8(encodedUrl.data(), encodedUrl.length());
+ } else if (value.canConvert(QVariant::String)) {
+ stringValue = value.toString();
} else {
*error = QDocumentGallery::FilterError;
return false;
}
+
+ *query += QLatin1String(function)
+ + QLatin1String("(")
+ + field
+ + QLatin1String(",'")
+ + stringValue
+ + QLatin1String("')");
+
+ return true;
}
static bool qt_writeCondition(
@@ -470,32 +486,33 @@ static bool qt_writeCondition(
if ((index = properties.indexOfProperty(propertyName)) != -1) {
const QVariant value = filter.value();
+ const QGalleryItemProperty &property = properties[index];
switch (filter.comparator()) {
case QGalleryFilter::Equals:
return value.type() != QVariant::RegExp
- ? qt_write_comparison(error, properties[index].field, value, "=", query)
+ ? qt_write_comparison(error, property.field, value, "=", query, property.type)
: qt_write_function(error, "REGEX", properties[index].field, value.toRegExp(), query);
case QGalleryFilter::LessThan:
- return qt_write_comparison(error, properties[index].field, value, "<", query);
+ return qt_write_comparison(error, property.field, value, "<", query, property.type);
case QGalleryFilter::GreaterThan:
- return qt_write_comparison(error, properties[index].field, value, ">", query);
+ return qt_write_comparison(error, property.field, value, ">", query, property.type);
case QGalleryFilter::LessThanEquals:
- return qt_write_comparison(error, properties[index].field, value, "<=", query);
+ return qt_write_comparison(error, property.field, value, "<=", query, property.type);
case QGalleryFilter::GreaterThanEquals:
- return qt_write_comparison(error, properties[index].field, value, ">=", query);
+ return qt_write_comparison(error, property.field, value, ">=", query, property.type);
case QGalleryFilter::Contains:
- return qt_write_function(error, "fn:contains", properties[index].field, value, query);
+ return qt_write_function(error, "fn:contains", property.field, value, query, property.type);
case QGalleryFilter::StartsWith:
- return qt_write_function(error, "fn:starts-with", properties[index].field, value, query);
+ return qt_write_function(error, "fn:starts-with", property.field, value, query, property.type);
case QGalleryFilter::EndsWith:
- return qt_write_function(error, "fn:ends-with", properties[index].field, value, query);
+ return qt_write_function(error, "fn:ends-with", property.field, value, query, property.type);
case QGalleryFilter::Wildcard:
- return qt_write_function(error, "fn:contains", properties[index].field, value, query);
+ return qt_write_function(error, "fn:contains", property.field, value, query, property.type);
case QGalleryFilter::RegExp:
return value.type() != QVariant::RegExp
- ? qt_write_function(error, "REGEX", properties[index].field, value, query)
- : qt_write_function(error, "REGEX", properties[index].field, value.toRegExp(), query);
+ ? qt_write_function(error, "REGEX", property.field, value, query, property.type)
+ : qt_write_function(error, "REGEX", property.field, value.toRegExp(), query);
default:
*error = QDocumentGallery::FilterError;
@@ -666,7 +683,7 @@ static bool qt_writeOrientationCondition(
// nie:url nie:isPartOf, nie:created, nie:lastRefreshed, nie:interpretedAs, nie:dataSource,
// nie:byteSize
#define QT_GALLERY_NIE_DATAOBJECT_PROPERTIES \
- QT_GALLERY_ITEM_PROPERTY("url", "nie:url(?x)", String, CanRead | CanSort | CanFilter | IsResource)
+ QT_GALLERY_ITEM_PROPERTY("url", "nie:url(?x)", Url, CanRead | CanSort | CanFilter | IsResource)
//nie:InformationElement
// nie:usageCounter, nie:rootElementOf, nie:contentSize, nie:isLogicalPartOf, nie:characterSet,
@@ -1382,6 +1399,9 @@ static QVector<QGalleryTrackerValueColumn *> qt_createValueColumns(
case QVariant::DateTime:
columns.append(new QGalleryTrackerDateTimeColumn);
break;
+ case QVariant::Url:
+ columns.append(new QGalleryTrackerUrlColumn);
+ break;
default:
Q_ASSERT(false);
break;
@@ -1528,7 +1548,7 @@ void QGalleryTrackerSchema::populateItemArguments(
arguments->typeColumn.reset(new QGalleryTrackerServiceTypeColumn);
arguments->valueColumns = QVector<QGalleryTrackerValueColumn *>()
<< new QGalleryTrackerStringColumn
- << new QGalleryTrackerStringColumn
+ << new QGalleryTrackerUrlColumn
<< new QGalleryTrackerServiceIndexColumn
<< qt_createValueColumns(valueTypes + extendedValueTypes);
} else {
diff --git a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp
index 1c937ee..7d9c14e 100644
--- a/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp
+++ b/tests/auto/qgallerytrackerschema_tracker/tst_qgallerytrackerschema.cpp
@@ -101,6 +101,8 @@ private Q_SLOTS:
void queryResponseRootItem();
void queryResponseFilter_data();
void queryResponseFilter();
+ void queryResponseItemUrl_data();
+ void queryResponseItemUrl();
void queryResponseValueColumnToVariant_data();
void queryResponseValueColumnToVariant();
void queryResponseValueColumnToString_data();
@@ -495,7 +497,7 @@ void tst_QGalleryTrackerSchema::prepareValidItemResponse_data()
<< QStringList()
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/file.ext")
+ << QUrl(QLatin1String("file:///path/to/file.ext"))
<< 0)
<< QVariant(QUrl(QLatin1String("file:///path/to/file.ext")))
<< QVariant(QLatin1String("File"))
@@ -620,7 +622,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data()
<< 1
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/file.ext")
+ << QUrl(QLatin1String("file:///path/to/file.ext"))
<< 0)
<< "file::uuid:ff172362-d959-99e0-a792-0ddafdd2c559"
<< QVariant(QUrl(QLatin1String("file:///path/to/file.ext")))
@@ -635,7 +637,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data()
<< 1
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/image.png")
+ << QUrl(QLatin1String("file:///path/to/image.png"))
<< 4)
<< "image::uuid:ff172362-d959-99e0-a792-0ddafdd2c559"
<< QVariant(QUrl(QLatin1String("file:///path/to/image.png")))
@@ -650,7 +652,7 @@ void tst_QGalleryTrackerSchema::queryResponseRootType_data()
<< 1
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/text.txt")
+ << QUrl(QLatin1String("file:///path/to/text.txt"))
<< 7)
<< "text::uuid:ff172362-d959-99e0-a792-0ddafdd2c559"
<< QVariant(QUrl(QLatin1String("file:///path/to/text.txt")))
@@ -1729,6 +1731,21 @@ void tst_QGalleryTrackerSchema::queryResponseFilter_data()
"} "
"GROUP BY ?x";
} {
+ QGalleryFilter filter
+ = QDocumentGallery::url == QUrl::fromLocalFile(QString::fromUtf8("/path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg"));
+
+ QTest::newRow("File.url == file:///path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg")
+ << "File"
+ << QString()
+ << QGalleryQueryRequest::AllDescendants
+ << filter
+ << "SELECT ?x nie:url(?x) rdf:type(?x) "
+ "WHERE {"
+ "{?x rdf:type nfo:FileDataObject}"
+ "FILTER((nie:url(?x)='file:///path/to/K%C3%A4rp%C3%A4ssieni.jpg'))"
+ "} "
+ "GROUP BY ?x";
+ } {
QGalleryFilter filter = QDocumentGallery::filePath == QLatin1String("/path/to/file.ext");
QTest::newRow("File.filePath == /path/to/file.ext")
@@ -1743,6 +1760,21 @@ void tst_QGalleryTrackerSchema::queryResponseFilter_data()
"} "
"GROUP BY ?x";
} {
+ QGalleryFilter filter
+ = QDocumentGallery::filePath == QString::fromUtf8("/path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg");
+
+ QTest::newRow("File.filePath == /path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg")
+ << "File"
+ << QString()
+ << QGalleryQueryRequest::AllDescendants
+ << filter
+ << "SELECT ?x nie:url(?x) rdf:type(?x) "
+ "WHERE {"
+ "{?x rdf:type nfo:FileDataObject}"
+ "FILTER((nie:url(?x)='file:///path/to/K%C3%A4rp%C3%A4ssieni.jpg'))"
+ "} "
+ "GROUP BY ?x";
+ } {
QGalleryFilter filter = QDocumentGallery::filePath > QLatin1String("/path/to/file.ext");
QTest::newRow("File.filePath > /path/to/file.ext")
@@ -2290,6 +2322,51 @@ void tst_QGalleryTrackerSchema::queryResponseFilter()
QCOMPARE(arguments.sparql, sparql);
}
+
+void tst_QGalleryTrackerSchema::queryResponseItemUrl_data()
+{
+ QTest::addColumn<QString>("rootType");
+ QTest::addColumn<QByteArray>("encodedUrl");
+ QTest::addColumn<QUrl>("url");
+
+ QTest::newRow("File ascii")
+ << "File"
+ << QByteArray("file://path/to/file.ext")
+ << QUrl(QLatin1String("file://path/to/file.ext"));
+
+ QTest::newRow("Image encoded")
+ << "Image"
+ << QByteArray("file://path/to/K%C3%A4rp%C3%A4ssieni.jpg")
+ << QUrl(QString::fromUtf8("file://path/to/K\xc3\xa4rp\xc3\xa4ssieni.jpg"));
+}
+
+void tst_QGalleryTrackerSchema::queryResponseItemUrl()
+{
+ QFETCH(QString, rootType);
+ QFETCH(QByteArray, encodedUrl);
+ QFETCH(QUrl, url);
+
+ QGalleryTrackerResultSetArguments arguments;
+
+ QGalleryTrackerSchema schema(rootType);
+
+ QCOMPARE(
+ schema.prepareQueryResponse(
+ &arguments,
+ this,
+ QGalleryQueryRequest::AllDescendants,
+ QString(),
+ QGalleryFilter(),
+ QStringList(),
+ QStringList(),
+ 0,
+ 0),
+ QDocumentGallery::NoError);
+
+ QCOMPARE(arguments.valueColumns.count(), 3);
+ QCOMPARE(arguments.valueColumns.at(1)->toVariant(encodedUrl).toUrl(), url);
+}
+
void tst_QGalleryTrackerSchema::queryResponseValueColumnToVariant_data()
{
QTest::addColumn<QString>("rootType");
@@ -2566,7 +2643,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data()
<< QString::fromLatin1("filePath")
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/file.ext")
+ << QUrl(QLatin1String("file:///path/to/file.ext"))
<< QLatin1String("Files"))
<< QVariant(QLatin1String("/path/to/file.ext"));
@@ -2575,7 +2652,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data()
<< QString::fromLatin1("path")
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/file.ext")
+ << QUrl(QLatin1String("file:///path/to/file.ext"))
<< QLatin1String("Files"))
<< QVariant(QLatin1String("/path/to"));
@@ -2584,7 +2661,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data()
<< QString::fromLatin1("path")
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/")
+ << QUrl(QLatin1String("file:///path/to/"))
<< QLatin1String("Files"))
<< QVariant(QLatin1String("/path/to"));
@@ -2593,7 +2670,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data()
<< QString::fromLatin1("fileExtension")
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to/file.ext")
+ << QUrl(QLatin1String("file:///path/to/file.ext"))
<< QLatin1String("Files"))
<< QVariant(QLatin1String("ext"));
@@ -2603,7 +2680,7 @@ void tst_QGalleryTrackerSchema::queryResponseCompositeColumn_data()
<< QString::fromLatin1("fileExtension")
<< (QVector<QVariant>()
<< QLatin1String("uuid:ff172362-d959-99e0-a792-0ddafdd2c559")
- << QLatin1String("file:///path/to")
+ << QUrl(QLatin1String("file:///path/to"))
<< QLatin1String("Files"))
<< QVariant();
}