Merge lp:~mhr3/unity-scopes-shell/fix-1305147 into lp:unity-scopes-shell

Proposed by Michal Hruby
Status: Merged
Merged at revision: 86
Proposed branch: lp:~mhr3/unity-scopes-shell/fix-1305147
Merge into: lp:unity-scopes-shell
Diff against target: 193 lines (+68/-36)
5 files modified
src/Unity/scope.cpp (+40/-33)
src/Unity/scope.h (+1/-1)
tests/data/mock-scope/mock-scope.cpp (+9/-0)
tests/resultstest-ng.cpp (+17/-1)
tests/utilstest-ng.cpp (+1/-1)
To merge this branch: bzr merge lp:~mhr3/unity-scopes-shell/fix-1305147
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+217796@code.launchpad.net

Commit message

Handle scope uris.

Description of the change

Handle scope uris.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) wrote :

LGTM

review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

Sigh, the CI job wasn't updated to build against U. :(

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Unity/scope.cpp'
--- src/Unity/scope.cpp 2014-04-08 10:06:42 +0000
+++ src/Unity/scope.cpp 2014-04-30 17:24:07 +0000
@@ -164,7 +164,7 @@
164 Q_EMIT previewRequested(QVariant::fromValue(result));164 Q_EMIT previewRequested(QVariant::fromValue(result));
165 break;165 break;
166 case scopes::ActivationResponse::PerformQuery:166 case scopes::ActivationResponse::PerformQuery:
167 processPerformQuery(response, true);167 executeCannedQuery(response->query(), true);
168 break;168 break;
169 default:169 default:
170 break;170 break;
@@ -176,7 +176,13 @@
176 std::shared_ptr<scopes::ActivationResponse> response;176 std::shared_ptr<scopes::ActivationResponse> response;
177 response.swap(m_delayedActivation);177 response.swap(m_delayedActivation);
178178
179 processPerformQuery(response, false);179 if (!response) {
180 return;
181 }
182
183 if (response->status() == scopes::ActivationResponse::PerformQuery) {
184 executeCannedQuery(response->query(), false);
185 }
180}186}
181187
182void Scope::internetFlagChanged(QString const& key)188void Scope::internetFlagChanged(QString const& key)
@@ -188,7 +194,7 @@
188 invalidateResults();194 invalidateResults();
189}195}
190196
191void Scope::processPerformQuery(std::shared_ptr<scopes::ActivationResponse> const& response, bool allowDelayedActivation)197void Scope::executeCannedQuery(unity::scopes::CannedQuery const& query, bool allowDelayedActivation)
192{198{
193 scopes_ng::Scopes* scopes = qobject_cast<scopes_ng::Scopes*>(parent());199 scopes_ng::Scopes* scopes = qobject_cast<scopes_ng::Scopes*>(parent());
194 if (scopes == nullptr) {200 if (scopes == nullptr) {
@@ -196,37 +202,30 @@
196 return;202 return;
197 }203 }
198204
199 if (!response) {205 QString scopeId(QString::fromStdString(query.scope_id()));
200 return;206 QString searchString(QString::fromStdString(query.query_string()));
201 }207 // figure out if this scope is already favourited
202208 Scope* scope = scopes->getScopeById(scopeId);
203 if (response->status() == scopes::ActivationResponse::PerformQuery) {209 if (scope != nullptr) {
204 scopes::CannedQuery q(response->query());210 // TODO: change department, filters?
205 QString scopeId(QString::fromStdString(q.scope_id()));211 scope->setSearchQuery(searchString);
206 QString searchString(QString::fromStdString(q.query_string()));212 Q_EMIT gotoScope(scopeId);
207 // figure out if this scope is already favourited213 } else {
208 Scope* scope = scopes->getScopeById(scopeId);214 // create temp dash page
209 if (scope != nullptr) {215 auto meta_sptr = scopes->getCachedMetadata(scopeId);
210 // TODO: change department, filters, query_string?216 if (meta_sptr) {
217 scope = new scopes_ng::Scope(this);
218 scope->setScopeData(*meta_sptr);
211 scope->setSearchQuery(searchString);219 scope->setSearchQuery(searchString);
212 Q_EMIT gotoScope(scopeId);220 m_tempScopes.insert(scope);
221 Q_EMIT openScope(scope);
222 } else if (allowDelayedActivation) {
223 // request registry refresh to get the missing metadata
224 m_delayedActivation = std::make_shared<scopes::ActivationResponse>(query);
225 QObject::connect(scopes, &Scopes::metadataRefreshed, this, &Scope::metadataRefreshed);
226 scopes->refreshScopeMetadata();
213 } else {227 } else {
214 // create temp dash page228 qWarning("Unable to find scope \"%s\" after metadata refresh", query.scope_id().c_str());
215 auto meta_sptr = scopes->getCachedMetadata(scopeId);
216 if (meta_sptr) {
217 scope = new scopes_ng::Scope(this);
218 scope->setScopeData(*meta_sptr);
219 scope->setSearchQuery(searchString);
220 m_tempScopes.insert(scope);
221 Q_EMIT openScope(scope);
222 } else if (allowDelayedActivation) {
223 // request registry refresh to get the missing metadata
224 m_delayedActivation = response;
225 QObject::connect(scopes, &Scopes::metadataRefreshed, this, &Scope::metadataRefreshed);
226 scopes->refreshScopeMetadata();
227 } else {
228 qWarning("Unable to find scope \"%s\" after metadata refresh", q.scope_id().c_str());
229 }
230 }229 }
231 }230 }
232}231}
@@ -572,7 +571,7 @@
572 Qt to open the uri.571 Qt to open the uri.
573 */572 */
574 QUrl url(uri);573 QUrl url(uri);
575 if (url.scheme() == "application") {574 if (url.scheme() == QLatin1String("application")) {
576 QString path(url.path().isEmpty() ? url.authority() : url.path());575 QString path(url.path().isEmpty() ? url.authority() : url.path());
577 if (path.startsWith("/")) {576 if (path.startsWith("/")) {
578 Q_FOREACH(const QString &dir, QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) {577 Q_FOREACH(const QString &dir, QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) {
@@ -585,6 +584,14 @@
585 }584 }
586585
587 Q_EMIT activateApplication(QFileInfo(path).completeBaseName());586 Q_EMIT activateApplication(QFileInfo(path).completeBaseName());
587 } else if (url.scheme() == QLatin1String("scope")) {
588 qDebug() << "Got scope URI" << uri;
589 try {
590 scopes::CannedQuery q(scopes::CannedQuery::from_uri(uri.toStdString()));
591 executeCannedQuery(q, true);
592 } catch (...) {
593 qWarning("Unable to parse scope uri!");
594 }
588 } else {595 } else {
589 qDebug() << "Trying to open" << uri;596 qDebug() << "Trying to open" << uri;
590 /* Try our luck */597 /* Try our luck */
591598
=== modified file 'src/Unity/scope.h'
--- src/Unity/scope.h 2014-04-07 16:55:52 +0000
+++ src/Unity/scope.h 2014-04-30 17:24:07 +0000
@@ -134,7 +134,7 @@
134134
135private:135private:
136 void processSearchChunk(PushEvent* pushEvent);136 void processSearchChunk(PushEvent* pushEvent);
137 void processPerformQuery(std::shared_ptr<unity::scopes::ActivationResponse> const& response, bool allowDelayedActivation);137 void executeCannedQuery(unity::scopes::CannedQuery const& query, bool allowDelayedActivation);
138138
139 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);139 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);
140 void dispatchSearch();140 void dispatchSearch();
141141
=== modified file 'tests/data/mock-scope/mock-scope.cpp'
--- tests/data/mock-scope/mock-scope.cpp 2014-03-31 11:33:21 +0000
+++ tests/data/mock-scope/mock-scope.cpp 2014-04-30 17:24:07 +0000
@@ -156,6 +156,15 @@
156 res.set_intercept_activation();156 res.set_intercept_activation();
157 reply->push(res);157 reply->push(res);
158 }158 }
159 else if (query_ == "scope-uri")
160 {
161 CategoryRenderer minimal_rndr(R"({"schema-version": 1, "components": {"title": "title"}})");
162 auto cat = reply->register_category("cat1", "Category 1", "", minimal_rndr);
163 CategorisedResult res(cat);
164 res.set_uri("scope://mock-scope?q=next-scope-uri");
165 res.set_title("result for: \"" + query_ + "\"");
166 reply->push(res);
167 }
159 else if (query_ == "two-categories")168 else if (query_ == "two-categories")
160 {169 {
161 auto cat1 = reply->register_category("cat1", "Category 1", "");170 auto cat1 = reply->register_category("cat1", "Category 1", "");
162171
=== modified file 'tests/resultstest-ng.cpp'
--- tests/resultstest-ng.cpp 2014-04-04 15:07:05 +0000
+++ tests/resultstest-ng.cpp 2014-04-30 17:24:07 +0000
@@ -779,7 +779,23 @@
779 QCOMPARE(spy3.count(), 0);779 QCOMPARE(spy3.count(), 0);
780 }780 }
781781
782 void testScopeResultWithScopeUri()
783 {
784 performSearch(m_scope, QString("scope-uri"));
785
786 unity::scopes::Result::SPtr result;
787 QVERIFY(getFirstResult(m_scope, result));
788
789 QSignalSpy spy(m_scope, SIGNAL(gotoScope(QString)));
790 m_scope->activate(QVariant::fromValue(result));
791 // this is likely to be invoked synchronously
792 if (spy.count() == 0) {
793 QVERIFY(spy.wait());
794 }
795 QVERIFY(spy.count() > 0);
796 }
797
782};798};
783799
784QTEST_MAIN(ResultsTestNg)800QTEST_GUILESS_MAIN(ResultsTestNg)
785#include <resultstest-ng.moc>801#include <resultstest-ng.moc>
786802
=== modified file 'tests/utilstest-ng.cpp'
--- tests/utilstest-ng.cpp 2014-03-25 16:34:26 +0000
+++ tests/utilstest-ng.cpp 2014-04-30 17:24:07 +0000
@@ -110,5 +110,5 @@
110 }110 }
111};111};
112112
113QTEST_MAIN(UtilsTestNg)113QTEST_GUILESS_MAIN(UtilsTestNg)
114#include <utilstest-ng.moc>114#include <utilstest-ng.moc>

Subscribers

People subscribed via source and target branches

to all changes: