Changeset View
Changeset View
Standalone View
Standalone View
src/kioslaves/search/kio_search.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
65 | { | 65 | { | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | 68 | | |||
69 | SearchProtocol::~SearchProtocol() | 69 | SearchProtocol::~SearchProtocol() | ||
70 | { | 70 | { | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | static QString jsonQueryForType(const QString &type) | | |||
74 | { | | |||
75 | const QString jsonQuery(QStringLiteral("{\"dayFilter\": 0,\ | | |||
76 | \"monthFilter\": 0, \ | | |||
77 | \"yearFilter\": 0, \ | | |||
78 | \"type\": [ \"%1\"]}")); | | |||
79 | return jsonQuery.arg(type); | | |||
80 | } | | |||
81 | | ||||
82 | static QString jsonQueryFromUrl(const QUrl &url) | | |||
83 | { | | |||
84 | const QString path = url.path(); | | |||
85 | | ||||
86 | if (path == QLatin1String("/documents")) { | | |||
87 | return jsonQueryForType(QStringLiteral("Document")); | | |||
88 | } else if (path.endsWith(QLatin1String("/images"))) { | | |||
bruns: @broulik - why `endsWith()`? | |||||
should I just change the comparisons to path == ..., just like the /documents one? iasensio: should I just change the comparisons to `path == ...`, just like the `/documents` one? | |||||
89 | return jsonQueryForType(QStringLiteral("Image")); | | |||
90 | } else if (path.endsWith(QLatin1String("/audio"))) { | | |||
91 | return jsonQueryForType(QStringLiteral("Audio")); | | |||
92 | } else if (path.endsWith(QLatin1String("/videos"))) { | | |||
93 | return jsonQueryForType(QStringLiteral("Video")); | | |||
94 | } | | |||
95 | | ||||
96 | return QString(); | | |||
97 | } | | |||
98 | | ||||
99 | void SearchProtocol::listDir(const QUrl& url) | 73 | void SearchProtocol::listDir(const QUrl& url) | ||
100 | { | 74 | { | ||
101 | Query q; | 75 | Query q = Query::fromSearchUrl(url); | ||
102 | | ||||
103 | QUrlQuery urlQuery(url); | | |||
104 | if (urlQuery.hasQueryItem(QStringLiteral("json"))) { | | |||
105 | QString jsonString = urlQuery.queryItemValue(QStringLiteral("json"), QUrl::FullyDecoded); | | |||
106 | q = Query::fromJSON(jsonString.toUtf8()); | | |||
107 | } else if (urlQuery.hasQueryItem(QStringLiteral("query"))) { | | |||
108 | QString queryString = urlQuery.queryItemValue(QStringLiteral("query"), QUrl::FullyDecoded); | | |||
109 | | ||||
110 | q.setSearchString(queryString); | | |||
111 | } else { | | |||
112 | const QString jsonString = jsonQueryFromUrl(url); | | |||
113 | if (!jsonString.isEmpty()) { | | |||
114 | q = Query::fromJSON(jsonString.toUtf8()); | | |||
115 | } | | |||
116 | } | | |||
117 | 76 | | |||
118 | q.setSortingOption(Query::SortNone); | 77 | q.setSortingOption(Query::SortNone); | ||
119 | ResultIterator it = q.exec(); | 78 | ResultIterator it = q.exec(); | ||
120 | 79 | | |||
121 | while (it.next()) { | 80 | while (it.next()) { | ||
122 | KIO::UDSEntry uds; | 81 | KIO::UDSEntry uds; | ||
123 | uds.reserve(10); | 82 | uds.reserve(10); | ||
124 | const QString filePath(it.filePath()); | 83 | const QString filePath(it.filePath()); | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
@broulik - why endsWith()?