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
1=== modified file 'src/Unity/scope.cpp'
2--- src/Unity/scope.cpp 2014-04-08 10:06:42 +0000
3+++ src/Unity/scope.cpp 2014-04-30 17:24:07 +0000
4@@ -164,7 +164,7 @@
5 Q_EMIT previewRequested(QVariant::fromValue(result));
6 break;
7 case scopes::ActivationResponse::PerformQuery:
8- processPerformQuery(response, true);
9+ executeCannedQuery(response->query(), true);
10 break;
11 default:
12 break;
13@@ -176,7 +176,13 @@
14 std::shared_ptr<scopes::ActivationResponse> response;
15 response.swap(m_delayedActivation);
16
17- processPerformQuery(response, false);
18+ if (!response) {
19+ return;
20+ }
21+
22+ if (response->status() == scopes::ActivationResponse::PerformQuery) {
23+ executeCannedQuery(response->query(), false);
24+ }
25 }
26
27 void Scope::internetFlagChanged(QString const& key)
28@@ -188,7 +194,7 @@
29 invalidateResults();
30 }
31
32-void Scope::processPerformQuery(std::shared_ptr<scopes::ActivationResponse> const& response, bool allowDelayedActivation)
33+void Scope::executeCannedQuery(unity::scopes::CannedQuery const& query, bool allowDelayedActivation)
34 {
35 scopes_ng::Scopes* scopes = qobject_cast<scopes_ng::Scopes*>(parent());
36 if (scopes == nullptr) {
37@@ -196,37 +202,30 @@
38 return;
39 }
40
41- if (!response) {
42- return;
43- }
44-
45- if (response->status() == scopes::ActivationResponse::PerformQuery) {
46- scopes::CannedQuery q(response->query());
47- QString scopeId(QString::fromStdString(q.scope_id()));
48- QString searchString(QString::fromStdString(q.query_string()));
49- // figure out if this scope is already favourited
50- Scope* scope = scopes->getScopeById(scopeId);
51- if (scope != nullptr) {
52- // TODO: change department, filters, query_string?
53+ QString scopeId(QString::fromStdString(query.scope_id()));
54+ QString searchString(QString::fromStdString(query.query_string()));
55+ // figure out if this scope is already favourited
56+ Scope* scope = scopes->getScopeById(scopeId);
57+ if (scope != nullptr) {
58+ // TODO: change department, filters?
59+ scope->setSearchQuery(searchString);
60+ Q_EMIT gotoScope(scopeId);
61+ } else {
62+ // create temp dash page
63+ auto meta_sptr = scopes->getCachedMetadata(scopeId);
64+ if (meta_sptr) {
65+ scope = new scopes_ng::Scope(this);
66+ scope->setScopeData(*meta_sptr);
67 scope->setSearchQuery(searchString);
68- Q_EMIT gotoScope(scopeId);
69+ m_tempScopes.insert(scope);
70+ Q_EMIT openScope(scope);
71+ } else if (allowDelayedActivation) {
72+ // request registry refresh to get the missing metadata
73+ m_delayedActivation = std::make_shared<scopes::ActivationResponse>(query);
74+ QObject::connect(scopes, &Scopes::metadataRefreshed, this, &Scope::metadataRefreshed);
75+ scopes->refreshScopeMetadata();
76 } else {
77- // create temp dash page
78- auto meta_sptr = scopes->getCachedMetadata(scopeId);
79- if (meta_sptr) {
80- scope = new scopes_ng::Scope(this);
81- scope->setScopeData(*meta_sptr);
82- scope->setSearchQuery(searchString);
83- m_tempScopes.insert(scope);
84- Q_EMIT openScope(scope);
85- } else if (allowDelayedActivation) {
86- // request registry refresh to get the missing metadata
87- m_delayedActivation = response;
88- QObject::connect(scopes, &Scopes::metadataRefreshed, this, &Scope::metadataRefreshed);
89- scopes->refreshScopeMetadata();
90- } else {
91- qWarning("Unable to find scope \"%s\" after metadata refresh", q.scope_id().c_str());
92- }
93+ qWarning("Unable to find scope \"%s\" after metadata refresh", query.scope_id().c_str());
94 }
95 }
96 }
97@@ -572,7 +571,7 @@
98 Qt to open the uri.
99 */
100 QUrl url(uri);
101- if (url.scheme() == "application") {
102+ if (url.scheme() == QLatin1String("application")) {
103 QString path(url.path().isEmpty() ? url.authority() : url.path());
104 if (path.startsWith("/")) {
105 Q_FOREACH(const QString &dir, QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) {
106@@ -585,6 +584,14 @@
107 }
108
109 Q_EMIT activateApplication(QFileInfo(path).completeBaseName());
110+ } else if (url.scheme() == QLatin1String("scope")) {
111+ qDebug() << "Got scope URI" << uri;
112+ try {
113+ scopes::CannedQuery q(scopes::CannedQuery::from_uri(uri.toStdString()));
114+ executeCannedQuery(q, true);
115+ } catch (...) {
116+ qWarning("Unable to parse scope uri!");
117+ }
118 } else {
119 qDebug() << "Trying to open" << uri;
120 /* Try our luck */
121
122=== modified file 'src/Unity/scope.h'
123--- src/Unity/scope.h 2014-04-07 16:55:52 +0000
124+++ src/Unity/scope.h 2014-04-30 17:24:07 +0000
125@@ -134,7 +134,7 @@
126
127 private:
128 void processSearchChunk(PushEvent* pushEvent);
129- void processPerformQuery(std::shared_ptr<unity::scopes::ActivationResponse> const& response, bool allowDelayedActivation);
130+ void executeCannedQuery(unity::scopes::CannedQuery const& query, bool allowDelayedActivation);
131
132 void processResultSet(QList<std::shared_ptr<unity::scopes::CategorisedResult>>& result_set);
133 void dispatchSearch();
134
135=== modified file 'tests/data/mock-scope/mock-scope.cpp'
136--- tests/data/mock-scope/mock-scope.cpp 2014-03-31 11:33:21 +0000
137+++ tests/data/mock-scope/mock-scope.cpp 2014-04-30 17:24:07 +0000
138@@ -156,6 +156,15 @@
139 res.set_intercept_activation();
140 reply->push(res);
141 }
142+ else if (query_ == "scope-uri")
143+ {
144+ CategoryRenderer minimal_rndr(R"({"schema-version": 1, "components": {"title": "title"}})");
145+ auto cat = reply->register_category("cat1", "Category 1", "", minimal_rndr);
146+ CategorisedResult res(cat);
147+ res.set_uri("scope://mock-scope?q=next-scope-uri");
148+ res.set_title("result for: \"" + query_ + "\"");
149+ reply->push(res);
150+ }
151 else if (query_ == "two-categories")
152 {
153 auto cat1 = reply->register_category("cat1", "Category 1", "");
154
155=== modified file 'tests/resultstest-ng.cpp'
156--- tests/resultstest-ng.cpp 2014-04-04 15:07:05 +0000
157+++ tests/resultstest-ng.cpp 2014-04-30 17:24:07 +0000
158@@ -779,7 +779,23 @@
159 QCOMPARE(spy3.count(), 0);
160 }
161
162+ void testScopeResultWithScopeUri()
163+ {
164+ performSearch(m_scope, QString("scope-uri"));
165+
166+ unity::scopes::Result::SPtr result;
167+ QVERIFY(getFirstResult(m_scope, result));
168+
169+ QSignalSpy spy(m_scope, SIGNAL(gotoScope(QString)));
170+ m_scope->activate(QVariant::fromValue(result));
171+ // this is likely to be invoked synchronously
172+ if (spy.count() == 0) {
173+ QVERIFY(spy.wait());
174+ }
175+ QVERIFY(spy.count() > 0);
176+ }
177+
178 };
179
180-QTEST_MAIN(ResultsTestNg)
181+QTEST_GUILESS_MAIN(ResultsTestNg)
182 #include <resultstest-ng.moc>
183
184=== modified file 'tests/utilstest-ng.cpp'
185--- tests/utilstest-ng.cpp 2014-03-25 16:34:26 +0000
186+++ tests/utilstest-ng.cpp 2014-04-30 17:24:07 +0000
187@@ -110,5 +110,5 @@
188 }
189 };
190
191-QTEST_MAIN(UtilsTestNg)
192+QTEST_GUILESS_MAIN(UtilsTestNg)
193 #include <utilstest-ng.moc>

Subscribers

People subscribed via source and target branches

to all changes: