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"))) { | ||||
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 | | ||||
73 | void SearchProtocol::listDir(const QUrl& url) | 99 | void SearchProtocol::listDir(const QUrl& url) | ||
74 | { | 100 | { | ||
75 | Query q; | 101 | Query q; | ||
76 | 102 | | |||
77 | QUrlQuery urlQuery(url); | 103 | QUrlQuery urlQuery(url); | ||
78 | if (urlQuery.hasQueryItem(QStringLiteral("json"))) { | 104 | if (urlQuery.hasQueryItem(QStringLiteral("json"))) { | ||
79 | QString jsonString = urlQuery.queryItemValue(QStringLiteral("json"), QUrl::FullyDecoded); | 105 | QString jsonString = urlQuery.queryItemValue(QStringLiteral("json"), QUrl::FullyDecoded); | ||
80 | q = Query::fromJSON(jsonString.toUtf8()); | 106 | q = Query::fromJSON(jsonString.toUtf8()); | ||
81 | } else if (urlQuery.hasQueryItem(QStringLiteral("query"))) { | 107 | } else if (urlQuery.hasQueryItem(QStringLiteral("query"))) { | ||
82 | QString queryString = urlQuery.queryItemValue(QStringLiteral("query"), QUrl::FullyDecoded); | 108 | QString queryString = urlQuery.queryItemValue(QStringLiteral("query"), QUrl::FullyDecoded); | ||
83 | 109 | | |||
84 | q.setSearchString(queryString); | 110 | q.setSearchString(queryString); | ||
111 | } else { | ||||
112 | const QString jsonString = jsonQueryFromUrl(url); | ||||
113 | if (!jsonString.isEmpty()) { | ||||
114 | q = Query::fromJSON(jsonString.toUtf8()); | ||||
115 | } | ||||
85 | } | 116 | } | ||
86 | 117 | | |||
87 | q.setSortingOption(Query::SortNone); | 118 | q.setSortingOption(Query::SortNone); | ||
88 | ResultIterator it = q.exec(); | 119 | ResultIterator it = q.exec(); | ||
89 | 120 | | |||
90 | while (it.next()) { | 121 | while (it.next()) { | ||
91 | KIO::UDSEntry uds; | 122 | KIO::UDSEntry uds; | ||
92 | const QString filePath(it.filePath()); | 123 | const QString filePath(it.filePath()); | ||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |