Merge lp:~stolowski/unity-scopes-shell/single-preview into lp:unity-scopes-shell
- single-preview
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Albert Astals Cid | ||||
Approved revision: | 293 | ||||
Merged at revision: | 293 | ||||
Proposed branch: | lp:~stolowski/unity-scopes-shell/single-preview | ||||
Merge into: | lp:unity-scopes-shell | ||||
Prerequisite: | lp:~stolowski/unity-scopes-shell/activation-progress | ||||
Diff against target: |
1350 lines (+275/-516) 22 files modified
debian/HARNESS_VERSION (+1/-1) debian/control.in (+1/-1) debian/libscope-harness.symbols.in (+1/-2) po/POTFILES.in (+3/-2) src/Unity/CMakeLists.txt (+0/-2) src/Unity/collectors.h (+1/-1) src/Unity/plugin.cpp (+1/-3) src/Unity/previewmodel.cpp (+199/-0) src/Unity/previewmodel.h (+22/-0) src/Unity/previewstack.cpp (+0/-338) src/Unity/previewstack.h (+0/-94) src/Unity/scope.cpp (+15/-14) src/Unity/scope.h (+4/-4) src/scope-harness/internal/preview-widget-arguments.h (+0/-3) src/scope-harness/preview/preview-widget.cpp (+5/-9) src/scope-harness/results/result.cpp (+5/-5) src/scope-harness/test-utils.cpp (+0/-13) src/scope-harness/test-utils.h (+0/-3) src/scope-harness/view/preview-view.cpp (+15/-17) src/scope-harness/view/preview-view.h (+2/-2) tests/overviewtest.cpp (+0/-1) tests/previewtest.cpp (+0/-1) |
||||
To merge this branch: | bzr merge lp:~stolowski/unity-scopes-shell/single-preview | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Albert Astals Cid (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Review via email: mp+286526@code.launchpad.net |
This proposal supersedes a proposal from 2016-02-17.
Commit message
Removed preview stack. Return single preview model from Scope.
Description of the change
Removed preview stack. Return single preview model from Scope.
The corresponding unity api change: https:/
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal | # |
Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal | # |
Looks good otherwise
Paweł Stołowski (stolowski) wrote : Posted in a previous version of this proposal | # |
> bring back the top warning to debian/control ?
Ah, right, this file is generated, I shouldn't have commited it. Fixed, thanks for spotting.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:293
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 294. By Paweł Stołowski
-
Debug message when preview model gets destroyed
Preview Diff
1 | === modified file 'debian/HARNESS_VERSION' |
2 | --- debian/HARNESS_VERSION 2015-09-17 10:10:40 +0000 |
3 | +++ debian/HARNESS_VERSION 2016-02-26 11:51:36 +0000 |
4 | @@ -1,1 +1,1 @@ |
5 | -1.1.0 |
6 | +2.1.0 |
7 | |
8 | === modified file 'debian/control.in' |
9 | --- debian/control.in 2016-02-26 11:51:36 +0000 |
10 | +++ debian/control.in 2016-02-26 11:51:36 +0000 |
11 | @@ -8,7 +8,7 @@ |
12 | dh-python, |
13 | libboost-python-dev, |
14 | libboost-regex-dev, |
15 | - libunity-api-dev (>= 7.106), |
16 | + libunity-api-dev (>= 7.107), |
17 | libunity-scopes-dev (>= 1.0.1~), |
18 | libgsettings-qt-dev (>= 0.1), |
19 | libqtdbustest1-dev (>= 0.2), |
20 | |
21 | === modified file 'debian/libscope-harness.symbols.in' |
22 | --- debian/libscope-harness.symbols.in 2015-11-11 09:31:48 +0000 |
23 | +++ debian/libscope-harness.symbols.in 2016-02-26 11:51:36 +0000 |
24 | @@ -1,4 +1,5 @@ |
25 | libscope-harness.so.@HARNESS_SO_VERSION@ libscope-harness@HARNESS_SO_VERSION@ #MINVER# |
26 | + (c++)"unity::scopeharness::view::PreviewView::preview(std::shared_ptr<unity::shell::scopes::PreviewModelInterface>)@Base" 0replaceme |
27 | (c++)"typeinfo for unity::scopeharness::registry::CustomRegistry@Base" 0.5.4+15.04.20150311.3 |
28 | (c++)"typeinfo for unity::scopeharness::registry::PreExistingRegistry@Base" 0.5.4+15.04.20150311.3 |
29 | (c++)"typeinfo for unity::scopeharness::registry::Registry@Base" 0.5.4+15.04.20150311.3 |
30 | @@ -264,7 +265,6 @@ |
31 | (c++)"unity::scopeharness::TestUtils::getFavoriteScopes()@Base" 0.5.4+15.04.20150311.3 |
32 | (c++)"unity::scopeharness::TestUtils::getFirstResult(unity::shell::scopes::CategoriesInterface*, std::shared_ptr<unity::scopes::Result>&)@Base" 0.5.4+15.04.20150311.3 |
33 | (c++)"unity::scopeharness::TestUtils::performSearch(QSharedPointer<unity::shell::scopes::ScopeInterface>, QString const&)@Base" 0.5.4+15.04.20150311.3 |
34 | - (c++)"unity::scopeharness::TestUtils::previewForFirstResult(QSharedPointer<scopes_ng::Scope>, QString const&, QScopedPointer<scopes_ng::PreviewStack, QScopedPointerDeleter<scopes_ng::PreviewStack> >&)@Base" 0.5.4+15.04.20150311.3 |
35 | (c++)"unity::scopeharness::TestUtils::refreshSearch(QSharedPointer<scopes_ng::Scope>)@Base" 0.5.4+15.04.20150311.3 |
36 | (c++)"unity::scopeharness::TestUtils::setFavouriteScopes(QStringList const&)@Base" 0.5.4+15.04.20150311.3 |
37 | (c++)"unity::scopeharness::TestUtils::throwIf(bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.5.4+15.04.20150311.3 |
38 | @@ -273,7 +273,6 @@ |
39 | (c++)"unity::scopeharness::TestUtils::waitForSearchFinish(QSharedPointer<unity::shell::scopes::ScopeInterface>)@Base" 0.5.4+15.04.20150311.3 |
40 | (c++)"unity::scopeharness::view::AbstractView::~AbstractView()@Base" 0.5.4+15.04.20150311.3 |
41 | (c++)"unity::scopeharness::view::PreviewView::columnCount() const@Base" 0.5.4+15.04.20150311.3 |
42 | - (c++)"unity::scopeharness::view::PreviewView::preview(std::shared_ptr<unity::shell::scopes::PreviewStackInterface>)@Base" 0.5.4+15.04.20150311.3 |
43 | (c++)"unity::scopeharness::view::PreviewView::~PreviewView()@Base" 0.5.4+15.04.20150311.3 |
44 | (c++)"unity::scopeharness::view::PreviewView::PreviewView()@Base" 0.5.4+15.04.20150311.3 |
45 | (c++)"unity::scopeharness::view::PreviewView::refresh()@Base" 0.5.4+15.04.20150311.3 |
46 | |
47 | === modified file 'po/POTFILES.in' |
48 | --- po/POTFILES.in 2015-10-21 10:47:17 +0000 |
49 | +++ po/POTFILES.in 2016-02-26 11:51:36 +0000 |
50 | @@ -14,6 +14,7 @@ |
51 | tests/data/mock-scope-departments-flipflop/mock-scope-departments-flipflop.cpp |
52 | tests/data/mock-scope/mock-scope.cpp |
53 | tests/data/mock-scope-double-nav/mock-scope-double-nav.cpp |
54 | +tests/data/mock-scope-manyresults/mock-scope-manyresults.cpp |
55 | tests/settingstest.cpp |
56 | src/scope-harness/registry/system-registry.cpp |
57 | src/scope-harness/registry/pre-existing-registry.cpp |
58 | @@ -72,11 +73,11 @@ |
59 | src/Unity/scopes.cpp |
60 | src/Unity/settingsmodel.cpp |
61 | src/Unity/utils.cpp |
62 | +src/Unity/resultsmap.cpp |
63 | src/Unity/locationservice.cpp |
64 | src/Unity/ubuntulocationservice.cpp |
65 | src/Unity/iconutils.cpp |
66 | src/Unity/department.cpp |
67 | -src/Unity/previewstack.cpp |
68 | src/Unity/categories.cpp |
69 | src/Unity/overviewresults.cpp |
70 | src/Unity/resultsmodel.cpp |
71 | @@ -125,7 +126,6 @@ |
72 | src/Unity/plugin.h |
73 | src/Unity/department.h |
74 | src/Unity/scope.h |
75 | -src/Unity/previewstack.h |
76 | src/Unity/logintoaccount.h |
77 | src/Unity/overviewcategories.h |
78 | src/Unity/locationservice.h |
79 | @@ -133,6 +133,7 @@ |
80 | src/Unity/settingsmodel.h |
81 | src/Unity/resultsmodel.h |
82 | src/Unity/geoip.h |
83 | +src/Unity/resultsmap.h |
84 | src/Unity/collectors.h |
85 | src/Unity/previewwidgetmodel.h |
86 | src/Unity/categories.h |
87 | |
88 | === modified file 'src/Unity/CMakeLists.txt' |
89 | --- src/Unity/CMakeLists.txt 2015-10-21 10:47:17 +0000 |
90 | +++ src/Unity/CMakeLists.txt 2016-02-26 11:51:36 +0000 |
91 | @@ -27,7 +27,6 @@ |
92 | overviewresults.cpp |
93 | overviewscope.cpp |
94 | previewmodel.cpp |
95 | - previewstack.cpp |
96 | previewwidgetmodel.cpp |
97 | resultsmap.cpp |
98 | resultsmodel.cpp |
99 | @@ -43,7 +42,6 @@ |
100 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h |
101 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/NavigationInterface.h |
102 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h |
103 | - ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h |
104 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h |
105 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ResultsModelInterface.h |
106 | ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h |
107 | |
108 | === modified file 'src/Unity/collectors.h' |
109 | --- src/Unity/collectors.h 2015-10-05 12:29:55 +0000 |
110 | +++ src/Unity/collectors.h 2016-02-26 11:51:36 +0000 |
111 | @@ -71,7 +71,7 @@ |
112 | public: |
113 | static const QEvent::Type eventType; |
114 | |
115 | - enum Type { SEARCH, PREVIEW, ACTIVATION }; |
116 | + enum Type { SEARCH = QEvent::User, PREVIEW, ACTIVATION }; |
117 | |
118 | PushEvent(Type event_type, const std::shared_ptr<CollectorBase>& collector); |
119 | Type type(); |
120 | |
121 | === modified file 'src/Unity/plugin.cpp' |
122 | --- src/Unity/plugin.cpp 2015-10-28 08:41:55 +0000 |
123 | +++ src/Unity/plugin.cpp 2016-02-26 11:51:36 +0000 |
124 | @@ -29,7 +29,6 @@ |
125 | #include "categories.h" |
126 | #include "department.h" |
127 | #include "resultsmodel.h" |
128 | -#include "previewstack.h" |
129 | #include "previewmodel.h" |
130 | #include "previewwidgetmodel.h" |
131 | #include "settingsmodel.h" |
132 | @@ -48,9 +47,8 @@ |
133 | qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", QStringLiteral("Can't create Categories object in QML. Get them from Scope instance.")); |
134 | qmlRegisterUncreatableType<unity::shell::scopes::SettingsModelInterface>(uri, 0, 2, "Settings", QStringLiteral("Can't create Settings object in QML. Get them from Scope instance.")); |
135 | qmlRegisterUncreatableType<scopes_ng::ResultsModel>(uri, 0, 2, "ResultsModel", QStringLiteral("Can't create new ResultsModel in QML. Get them from Categories instance.")); |
136 | - qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", QStringLiteral("Can't create new PreviewModel in QML. Get them from PreviewStack instance.")); |
137 | + qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", QStringLiteral("Can't create new PreviewModel in QML. Get them from Scope instance.")); |
138 | qmlRegisterUncreatableType<scopes_ng::PreviewWidgetModel>(uri, 0, 2, "PreviewWidgetModel", QStringLiteral("Can't create new PreviewWidgetModel in QML. Get them from PreviewModel instance.")); |
139 | - qmlRegisterUncreatableType<unity::shell::scopes::PreviewStackInterface>(uri, 0, 2, "PreviewStack", QStringLiteral("Can't create new PreviewStack in QML. Get them from Scope instance.")); |
140 | } |
141 | |
142 | void UnityPlugin::initializeEngine(QQmlEngine *engine, const char *uri) |
143 | |
144 | === modified file 'src/Unity/previewmodel.cpp' |
145 | --- src/Unity/previewmodel.cpp 2015-09-28 08:41:08 +0000 |
146 | +++ src/Unity/previewmodel.cpp 2016-02-26 11:51:36 +0000 |
147 | @@ -27,12 +27,16 @@ |
148 | #include "previewwidgetmodel.h" |
149 | #include "resultsmodel.h" |
150 | #include "utils.h" |
151 | +#include "logintoaccount.h" |
152 | |
153 | // Qt |
154 | #include <QJsonDocument> |
155 | #include <QJsonObject> |
156 | #include <QJsonValue> |
157 | |
158 | +#include <unity/scopes/Scope.h> |
159 | +#include <unity/scopes/ActionMetadata.h> |
160 | + |
161 | namespace scopes_ng |
162 | { |
163 | |
164 | @@ -45,11 +49,24 @@ |
165 | m_delayedClear(false), |
166 | m_widgetColumnCount(1) |
167 | { |
168 | + connect(this, &PreviewModel::triggered, this, &PreviewModel::widgetTriggered); |
169 | + |
170 | // we have one column by default |
171 | PreviewWidgetModel* columnModel = new PreviewWidgetModel(this); |
172 | m_previewWidgetModels.append(columnModel); |
173 | } |
174 | |
175 | +PreviewModel::~PreviewModel() |
176 | +{ |
177 | + if (m_listener) { |
178 | + m_listener->invalidate(); |
179 | + } |
180 | + |
181 | + if (m_lastActivation) { |
182 | + m_lastActivation->invalidate(); |
183 | + } |
184 | +} |
185 | + |
186 | void PreviewModel::setResult(std::shared_ptr<scopes::Result> const& result) |
187 | { |
188 | m_previewedResult = result; |
189 | @@ -64,6 +81,9 @@ |
190 | case PushEvent::PREVIEW: |
191 | processPreviewChunk(pushEvent); |
192 | return true; |
193 | + case PushEvent::ACTIVATION: |
194 | + processActionResponse(pushEvent); |
195 | + return true; |
196 | default: |
197 | qWarning("PreviewModel: Unhandled PushEvent type"); |
198 | break; |
199 | @@ -73,6 +93,18 @@ |
200 | return unity::shell::scopes::PreviewModelInterface::event(ev); |
201 | } |
202 | |
203 | +void PreviewModel::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id, QString const& userAgent) |
204 | +{ |
205 | + m_associatedScope = scope; |
206 | + m_session_id = session_id; |
207 | + m_userAgent = userAgent; |
208 | +} |
209 | + |
210 | +scopes_ng::Scope* PreviewModel::associatedScope() const |
211 | +{ |
212 | + return m_associatedScope; |
213 | +} |
214 | + |
215 | void PreviewModel::processPreviewChunk(PushEvent* pushEvent) |
216 | { |
217 | CollectorBase::Status status; |
218 | @@ -178,6 +210,26 @@ |
219 | return m_loaded; |
220 | } |
221 | |
222 | +void PreviewModel::loadForResult(scopes::Result::SPtr const& result) |
223 | +{ |
224 | + m_previewedResult = result; |
225 | + if (m_listener) { |
226 | + m_listener->invalidate(); // TODO: is this needed? |
227 | + } |
228 | + |
229 | + dispatchPreview(); |
230 | +} |
231 | + |
232 | +unity::scopes::Result::SPtr PreviewModel::previewedResult() const |
233 | +{ |
234 | + return m_previewedResult; |
235 | +} |
236 | + |
237 | +void PreviewModel::update(unity::scopes::PreviewWidgetList const& widgets) |
238 | +{ |
239 | + updateWidgetDefinitions(widgets); |
240 | +} |
241 | + |
242 | bool PreviewModel::processingAction() const |
243 | { |
244 | return m_processingAction; |
245 | @@ -439,4 +491,151 @@ |
246 | } |
247 | } |
248 | |
249 | +void PreviewModel::dispatchPreview(scopes::Variant const& extra_data) |
250 | +{ |
251 | + // TODO: figure out if the result can produce a preview without sending a request to the scope |
252 | + // if (m_previewedResult->has_early_preview()) { ... } |
253 | + try { |
254 | + auto proxy = m_associatedScope ? m_associatedScope->proxy_for_result(m_previewedResult) : m_previewedResult->target_scope_proxy(); |
255 | + |
256 | + QString formFactor(m_associatedScope ? m_associatedScope->formFactor() : QStringLiteral("phone")); |
257 | + scopes::ActionMetadata metadata(QLocale::system().name().toStdString(), formFactor.toStdString()); |
258 | + if (!extra_data.is_null()) { |
259 | + metadata.set_scope_data(extra_data); |
260 | + } |
261 | + if (!m_session_id.isNull()) { |
262 | + metadata["session-id"] = uuidToString(m_session_id).toStdString(); |
263 | + } |
264 | + if (!m_userAgent.isEmpty()) { |
265 | + metadata["user-agent"] = m_userAgent.toStdString(); |
266 | + } |
267 | + |
268 | + std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(this)); |
269 | + // invalidate previous listener (if any); TODO: is this needed? |
270 | + if (m_listener) { |
271 | + m_listener->invalidate(); |
272 | + } |
273 | + m_listener = listener; |
274 | + |
275 | + m_lastPreviewQuery = proxy->preview(*(m_previewedResult.get()), metadata, listener); |
276 | + } catch (std::exception& e) { |
277 | + qWarning("Caught an error from preview(): %s", e.what()); |
278 | + } catch (...) { |
279 | + qWarning("Caught an error from preview()"); |
280 | + } |
281 | +} |
282 | + |
283 | +void PreviewModel::widgetTriggered(QString const& widgetId, QString const& actionId, QVariantMap const& data) |
284 | +{ |
285 | + auto action = [this, widgetId, actionId, data]() { |
286 | + try { |
287 | + auto proxy = m_associatedScope ? m_associatedScope->proxy_for_result(m_previewedResult) : m_previewedResult->target_scope_proxy(); |
288 | + |
289 | + QString formFactor(m_associatedScope ? m_associatedScope->formFactor() : QStringLiteral("phone")); |
290 | + scopes::ActionMetadata metadata(QLocale::system().name().toStdString(), formFactor.toStdString()); |
291 | + metadata.set_scope_data(qVariantToScopeVariant(data)); |
292 | + |
293 | + if (m_lastActivation) { |
294 | + m_lastActivation->invalidate(); |
295 | + } |
296 | + std::shared_ptr<ActivationReceiver> listener(new ActivationReceiver(this, m_previewedResult)); |
297 | + m_lastActivation = listener; |
298 | + |
299 | + setProcessingAction(true); |
300 | + |
301 | + // FIXME: don't block |
302 | + proxy->perform_action(*(m_previewedResult.get()), metadata, widgetId.toStdString(), actionId.toStdString(), listener); |
303 | + } catch (std::exception& e) { |
304 | + qWarning("Caught an error from perform_action(%s, %s): %s", widgetId.toStdString().c_str(), actionId.toStdString().c_str(), e.what()); |
305 | + } catch (...) { |
306 | + qWarning("Caught an error from perform_action()"); |
307 | + } |
308 | + }; |
309 | + |
310 | + PreviewWidgetData* widgetData = getWidgetData(widgetId); |
311 | + if (widgetData != nullptr) { |
312 | + QString wtype = widgetData->type; |
313 | + auto uriAction = [this, wtype, data, action]() { |
314 | + if ((wtype == QLatin1String("actions") || wtype == QLatin1String("icon-actions")) && data.contains(QStringLiteral("uri"))) { |
315 | + if (m_associatedScope) { |
316 | + m_associatedScope->activateUri(data.value(QStringLiteral("uri")).toString()); |
317 | + return; |
318 | + } |
319 | + } |
320 | + action(); |
321 | + }; |
322 | + |
323 | + if (m_associatedScope && widgetData->data.contains(QStringLiteral("online_account_details"))) |
324 | + { |
325 | + QVariantMap details = widgetData->data.value(QStringLiteral("online_account_details")).toMap(); |
326 | + if (details.contains(QStringLiteral("service_name")) && |
327 | + details.contains(QStringLiteral("service_type")) && |
328 | + details.contains(QStringLiteral("provider_name")) && |
329 | + details.contains(QStringLiteral("login_passed_action")) && |
330 | + details.contains(QStringLiteral("login_failed_action"))) |
331 | + { |
332 | + LoginToAccount *login = new LoginToAccount(details.contains(QStringLiteral("scope_id")) ? details.value(QStringLiteral("scope_id")).toString() : QLatin1String(""), |
333 | + details.value(QStringLiteral("service_name")).toString(), |
334 | + details.value(QStringLiteral("service_type")).toString(), |
335 | + details.value(QStringLiteral("provider_name")).toString(), |
336 | + details.value(QStringLiteral("login_passed_action")).toInt(), |
337 | + details.value(QStringLiteral("login_failed_action")).toInt(), |
338 | + this); |
339 | + connect(login, SIGNAL(searchInProgress(bool)), m_associatedScope, SLOT(setSearchInProgress(bool))); |
340 | + connect(login, &LoginToAccount::finished, [this, login, uriAction](bool, int action_code_index) { |
341 | + if (action_code_index >= 0 && action_code_index <= scopes::OnlineAccountClient::LastActionCode_) |
342 | + { |
343 | + scopes::OnlineAccountClient::PostLoginAction action_code = static_cast<scopes::OnlineAccountClient::PostLoginAction>(action_code_index); |
344 | + switch (action_code) |
345 | + { |
346 | + case scopes::OnlineAccountClient::DoNothing: |
347 | + return; |
348 | + case scopes::OnlineAccountClient::InvalidateResults: |
349 | + m_associatedScope->invalidateResults(); |
350 | + return; |
351 | + default: |
352 | + break; |
353 | + } |
354 | + } |
355 | + uriAction(); |
356 | + login->deleteLater(); |
357 | + }); |
358 | + login->loginToAccount(); |
359 | + return; // main execution ends here |
360 | + } |
361 | + } else { |
362 | + uriAction(); |
363 | + } |
364 | + } else { |
365 | + qWarning("Action triggered for unknown widget \"%s\"", widgetId.toStdString().c_str()); |
366 | + } |
367 | +} |
368 | + |
369 | +void PreviewModel::processActionResponse(PushEvent* pushEvent) |
370 | +{ |
371 | + std::shared_ptr<scopes::ActivationResponse> response; |
372 | + scopes::Result::SPtr result; |
373 | + QString categoryId; |
374 | + pushEvent->collectActivationResponse(response, result, categoryId); |
375 | + if (!response) return; |
376 | + |
377 | + switch (response->status()) { |
378 | + case scopes::ActivationResponse::ShowPreview: |
379 | + // replace current preview |
380 | + setDelayedClear(); |
381 | + // the preview is marked as processing action, leave the flag on until the preview is updated |
382 | + dispatchPreview(scopes::Variant(response->scope_data())); |
383 | + break; |
384 | + // TODO: case to nest preview (once such API is available) |
385 | + default: |
386 | + if (m_associatedScope) { |
387 | + m_associatedScope->handleActivation(response, result); |
388 | + } |
389 | + |
390 | + setProcessingAction(false); |
391 | + break; |
392 | + } |
393 | +} |
394 | + |
395 | + |
396 | } // namespace scopes_ng |
397 | |
398 | === modified file 'src/Unity/previewmodel.h' |
399 | --- src/Unity/previewmodel.h 2015-08-14 12:29:16 +0000 |
400 | +++ src/Unity/previewmodel.h 2016-02-26 11:51:36 +0000 |
401 | @@ -29,11 +29,14 @@ |
402 | #include <QMultiMap> |
403 | #include <QStringList> |
404 | #include <QPointer> |
405 | +#include <QUuid> |
406 | |
407 | #include <unity/scopes/PreviewWidget.h> |
408 | #include <unity/scopes/Result.h> |
409 | #include <unity/scopes/ColumnLayout.h> |
410 | |
411 | +#include "collectors.h" |
412 | + |
413 | namespace scopes_ng |
414 | { |
415 | |
416 | @@ -60,6 +63,7 @@ |
417 | |
418 | public: |
419 | explicit PreviewModel(QObject* parent = 0); |
420 | + ~PreviewModel(); |
421 | |
422 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
423 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
424 | @@ -80,7 +84,18 @@ |
425 | |
426 | void updateWidgetDefinitions(unity::scopes::PreviewWidgetList const&); |
427 | |
428 | + void loadForResult(unity::scopes::Result::SPtr const&); |
429 | + void update(unity::scopes::PreviewWidgetList const&); |
430 | + |
431 | + void setAssociatedScope(scopes_ng::Scope*, QUuid const&, QString const&); |
432 | + scopes_ng::Scope* associatedScope() const; |
433 | + unity::scopes::Result::SPtr previewedResult() const; |
434 | + |
435 | +private Q_SLOTS: |
436 | + void widgetTriggered(QString const&, QString const&, QVariantMap const&); |
437 | + |
438 | private: |
439 | + void processActionResponse(PushEvent* pushEvent); |
440 | void addWidgetDefinitions(unity::scopes::PreviewWidgetList const&); |
441 | void processWidgetDefinitions(unity::scopes::PreviewWidgetList const&, std::function<void(QSharedPointer<PreviewWidgetData>)> const& processFunc); |
442 | void processPreviewChunk(PushEvent* pushEvent); |
443 | @@ -89,6 +104,7 @@ |
444 | PreviewWidgetModel* createExpandableWidgetModel(unity::scopes::PreviewWidget const&, PreviewWidgetData &); |
445 | void addWidgetToColumnModel(QSharedPointer<PreviewWidgetData> const&); |
446 | void processComponents(QHash<QString, QString> const& components, QVariantMap& out_attributes); |
447 | + void dispatchPreview(unity::scopes::Variant const& extra_data = unity::scopes::Variant()); |
448 | |
449 | bool m_loaded; |
450 | bool m_processingAction; |
451 | @@ -100,7 +116,13 @@ |
452 | QList<QSharedPointer<PreviewWidgetData>> m_previewWidgets; |
453 | QMultiMap<QString, PreviewWidgetData*> m_dataToWidgetMap; |
454 | |
455 | + unity::scopes::QueryCtrlProxy m_lastPreviewQuery; |
456 | + QPointer<scopes_ng::Scope> m_associatedScope; |
457 | + QUuid m_session_id; |
458 | + QString m_userAgent; |
459 | std::shared_ptr<unity::scopes::Result> m_previewedResult; |
460 | + std::shared_ptr<ScopeDataReceiverBase> m_listener; |
461 | + std::shared_ptr<ScopeDataReceiverBase> m_lastActivation; |
462 | }; |
463 | |
464 | } // namespace scopes_ng |
465 | |
466 | === removed file 'src/Unity/previewstack.cpp' |
467 | --- src/Unity/previewstack.cpp 2015-10-21 10:47:17 +0000 |
468 | +++ src/Unity/previewstack.cpp 1970-01-01 00:00:00 +0000 |
469 | @@ -1,338 +0,0 @@ |
470 | -/* |
471 | - * Copyright (C) 2014 Canonical, Ltd. |
472 | - * |
473 | - * Authors: |
474 | - * Michał Sawicz <michal.sawicz@canonical.com> |
475 | - * Michal Hruby <michal.hruby@canonical.com> |
476 | - * |
477 | - * This program is free software; you can redistribute it and/or modify |
478 | - * it under the terms of the GNU General Public License as published by |
479 | - * the Free Software Foundation; version 3. |
480 | - * |
481 | - * This program is distributed in the hope that it will be useful, |
482 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
483 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
484 | - * GNU General Public License for more details. |
485 | - * |
486 | - * You should have received a copy of the GNU General Public License |
487 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
488 | - */ |
489 | - |
490 | -// self |
491 | -#include "previewstack.h" |
492 | - |
493 | -// local |
494 | -#include "previewmodel.h" |
495 | -#include "scope.h" |
496 | -#include "utils.h" |
497 | -#include "logintoaccount.h" |
498 | - |
499 | -// Qt |
500 | -#include <QLocale> |
501 | -#include <QJsonDocument> |
502 | -#include <QJsonObject> |
503 | -#include <QJsonValue> |
504 | -#include <QUuid> |
505 | -#include <QPointer> |
506 | - |
507 | -#include <unity/scopes/ActionMetadata.h> |
508 | -#include <unity/scopes/Scope.h> |
509 | - |
510 | -namespace scopes_ng |
511 | -{ |
512 | - |
513 | -using namespace unity; |
514 | - |
515 | -PreviewStack::PreviewStack(QObject* parent) |
516 | - : unity::shell::scopes::PreviewStackInterface(parent) |
517 | - , m_widgetColumnCount(1), m_activePreview(nullptr) |
518 | -{ |
519 | -} |
520 | - |
521 | -PreviewStack::~PreviewStack() |
522 | -{ |
523 | - for (auto it = m_listeners.begin(); it != m_listeners.end(); ++it) { |
524 | - auto listener = it.value().lock(); |
525 | - if (listener) listener->invalidate(); |
526 | - } |
527 | - |
528 | - if (m_lastActivation) { |
529 | - m_lastActivation->invalidate(); |
530 | - } |
531 | -} |
532 | - |
533 | -bool PreviewStack::event(QEvent* ev) |
534 | -{ |
535 | - if (ev->type() == PushEvent::eventType) { |
536 | - PushEvent* pushEvent = static_cast<PushEvent*>(ev); |
537 | - |
538 | - switch (pushEvent->type()) { |
539 | - case PushEvent::ACTIVATION: |
540 | - processActionResponse(pushEvent); |
541 | - return true; |
542 | - default: |
543 | - qWarning("PreviewStack: Unhandled PushEvent type"); |
544 | - break; |
545 | - } |
546 | - } |
547 | - |
548 | - return unity::shell::scopes::PreviewStackInterface::event(ev); |
549 | -} |
550 | - |
551 | -void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id, QString const& userAgent) |
552 | -{ |
553 | - m_associatedScope = scope; |
554 | - m_session_id = session_id; |
555 | - m_userAgent = userAgent; |
556 | -} |
557 | - |
558 | -scopes_ng::Scope* PreviewStack::associatedScope() const |
559 | -{ |
560 | - return m_associatedScope; |
561 | -} |
562 | - |
563 | -void PreviewStack::loadForResult(scopes::Result::SPtr const& result) |
564 | -{ |
565 | - m_previewedResult = result; |
566 | - |
567 | - beginResetModel(); |
568 | - |
569 | - // invalidate all listeners |
570 | - for (auto it = m_listeners.begin(); it != m_listeners.end(); ++it) { |
571 | - auto listener = it.value().lock(); |
572 | - if (listener) listener->invalidate(); |
573 | - } |
574 | - // clear any previews |
575 | - while (!m_previews.empty()) { |
576 | - delete m_previews.takeFirst(); |
577 | - } |
578 | - // create active preview |
579 | - m_activePreview = new PreviewModel(this); |
580 | - m_activePreview->setResult(m_previewedResult); |
581 | - connect(m_activePreview, &PreviewModel::triggered, this, &PreviewStack::widgetTriggered); |
582 | - m_previews.append(m_activePreview); |
583 | - |
584 | - endResetModel(); |
585 | - |
586 | - dispatchPreview(); |
587 | -} |
588 | - |
589 | -void PreviewStack::update(unity::scopes::PreviewWidgetList const& widgets) |
590 | -{ |
591 | - if (m_activePreview == nullptr) { |
592 | - return; |
593 | - } |
594 | - m_activePreview->updateWidgetDefinitions(widgets); |
595 | -} |
596 | - |
597 | -void PreviewStack::dispatchPreview(scopes::Variant const& extra_data) |
598 | -{ |
599 | - // TODO: figure out if the result can produce a preview without sending a request to the scope |
600 | - // if (m_previewedResult->has_early_preview()) { ... } |
601 | - try { |
602 | - auto proxy = m_associatedScope ? m_associatedScope->proxy_for_result(m_previewedResult) : m_previewedResult->target_scope_proxy(); |
603 | - |
604 | - QString formFactor(m_associatedScope ? m_associatedScope->formFactor() : QStringLiteral("phone")); |
605 | - scopes::ActionMetadata metadata(QLocale::system().name().toStdString(), formFactor.toStdString()); |
606 | - if (!extra_data.is_null()) { |
607 | - metadata.set_scope_data(extra_data); |
608 | - } |
609 | - if (!m_session_id.isNull()) { |
610 | - metadata["session-id"] = uuidToString(m_session_id).toStdString(); |
611 | - } |
612 | - if (!m_userAgent.isEmpty()) { |
613 | - metadata["user-agent"] = m_userAgent.toStdString(); |
614 | - } |
615 | - |
616 | - std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview)); |
617 | - std::weak_ptr<ScopeDataReceiverBase> wl(listener); |
618 | - // invalidate previous listener (if any) |
619 | - auto prev_listener = m_listeners.take(m_activePreview).lock(); |
620 | - if (prev_listener) prev_listener->invalidate(); |
621 | - m_listeners[m_activePreview] = wl; |
622 | - |
623 | - m_lastPreviewQuery = proxy->preview(*(m_previewedResult.get()), metadata, listener); |
624 | - } catch (std::exception& e) { |
625 | - qWarning("Caught an error from preview(): %s", e.what()); |
626 | - } catch (...) { |
627 | - qWarning("Caught an error from preview()"); |
628 | - } |
629 | -} |
630 | - |
631 | -void PreviewStack::widgetTriggered(QString const& widgetId, QString const& actionId, QVariantMap const& data) |
632 | -{ |
633 | - auto action = [this, widgetId, actionId, data]() { |
634 | - try { |
635 | - auto proxy = m_associatedScope ? m_associatedScope->proxy_for_result(m_previewedResult) : m_previewedResult->target_scope_proxy(); |
636 | - |
637 | - QString formFactor(m_associatedScope ? m_associatedScope->formFactor() : QStringLiteral("phone")); |
638 | - scopes::ActionMetadata metadata(QLocale::system().name().toStdString(), formFactor.toStdString()); |
639 | - metadata.set_scope_data(qVariantToScopeVariant(data)); |
640 | - |
641 | - if (m_lastActivation) { |
642 | - m_lastActivation->invalidate(); |
643 | - } |
644 | - std::shared_ptr<ActivationReceiver> listener(new ActivationReceiver(this, m_previewedResult)); |
645 | - m_lastActivation = listener; |
646 | - |
647 | - // should be always coming from active preview |
648 | - if (m_activePreview) { |
649 | - m_activePreview->setProcessingAction(true); |
650 | - } |
651 | - |
652 | - // FIXME: don't block |
653 | - proxy->perform_action(*(m_previewedResult.get()), metadata, widgetId.toStdString(), actionId.toStdString(), listener); |
654 | - } catch (std::exception& e) { |
655 | - qWarning("Caught an error from perform_action(%s, %s): %s", widgetId.toStdString().c_str(), actionId.toStdString().c_str(), e.what()); |
656 | - } catch (...) { |
657 | - qWarning("Caught an error from perform_action()"); |
658 | - } |
659 | - }; |
660 | - |
661 | - PreviewModel* previewModel = qobject_cast<scopes_ng::PreviewModel*>(sender()); |
662 | - if (previewModel != nullptr) { |
663 | - PreviewWidgetData* widgetData = previewModel->getWidgetData(widgetId); |
664 | - if (widgetData != nullptr) { |
665 | - QString wtype = widgetData->type; |
666 | - auto uriAction = [this, wtype, data, action]() { |
667 | - if ((wtype == QLatin1String("actions") || wtype == QLatin1String("icon-actions")) && data.contains(QStringLiteral("uri"))) { |
668 | - if (m_associatedScope) { |
669 | - m_associatedScope->activateUri(data.value(QStringLiteral("uri")).toString()); |
670 | - return; |
671 | - } |
672 | - } |
673 | - action(); |
674 | - }; |
675 | - |
676 | - if (m_associatedScope && widgetData->data.contains(QStringLiteral("online_account_details"))) |
677 | - { |
678 | - QVariantMap details = widgetData->data.value(QStringLiteral("online_account_details")).toMap(); |
679 | - if (details.contains(QStringLiteral("service_name")) && |
680 | - details.contains(QStringLiteral("service_type")) && |
681 | - details.contains(QStringLiteral("provider_name")) && |
682 | - details.contains(QStringLiteral("login_passed_action")) && |
683 | - details.contains(QStringLiteral("login_failed_action"))) |
684 | - { |
685 | - LoginToAccount *login = new LoginToAccount(details.contains(QStringLiteral("scope_id")) ? details.value(QStringLiteral("scope_id")).toString() : QLatin1String(""), |
686 | - details.value(QStringLiteral("service_name")).toString(), |
687 | - details.value(QStringLiteral("service_type")).toString(), |
688 | - details.value(QStringLiteral("provider_name")).toString(), |
689 | - details.value(QStringLiteral("login_passed_action")).toInt(), |
690 | - details.value(QStringLiteral("login_failed_action")).toInt(), |
691 | - this); |
692 | - connect(login, SIGNAL(searchInProgress(bool)), m_associatedScope, SLOT(setSearchInProgress(bool))); |
693 | - connect(login, &LoginToAccount::finished, [this, login, uriAction](bool, int action_code_index) { |
694 | - if (action_code_index >= 0 && action_code_index <= scopes::OnlineAccountClient::LastActionCode_) |
695 | - { |
696 | - scopes::OnlineAccountClient::PostLoginAction action_code = static_cast<scopes::OnlineAccountClient::PostLoginAction>(action_code_index); |
697 | - switch (action_code) |
698 | - { |
699 | - case scopes::OnlineAccountClient::DoNothing: |
700 | - return; |
701 | - case scopes::OnlineAccountClient::InvalidateResults: |
702 | - m_associatedScope->invalidateResults(); |
703 | - return; |
704 | - default: |
705 | - break; |
706 | - } |
707 | - } |
708 | - uriAction(); |
709 | - login->deleteLater(); |
710 | - }); |
711 | - login->loginToAccount(); |
712 | - return; // main execution ends here |
713 | - } |
714 | - } else { |
715 | - uriAction(); |
716 | - } |
717 | - } else { |
718 | - qWarning("Action triggered for unknown widget \"%s\"", widgetId.toStdString().c_str()); |
719 | - } |
720 | - } else { |
721 | - action(); |
722 | - } |
723 | -} |
724 | - |
725 | -void PreviewStack::processActionResponse(PushEvent* pushEvent) |
726 | -{ |
727 | - std::shared_ptr<scopes::ActivationResponse> response; |
728 | - scopes::Result::SPtr result; |
729 | - QString categoryId; |
730 | - pushEvent->collectActivationResponse(response, result, categoryId); |
731 | - if (!response) return; |
732 | - |
733 | - switch (response->status()) { |
734 | - case scopes::ActivationResponse::ShowPreview: |
735 | - // replace current preview |
736 | - m_activePreview->setDelayedClear(); |
737 | - // the preview is marked as processing action, leave the flag on until the preview is updated |
738 | - dispatchPreview(scopes::Variant(response->scope_data())); |
739 | - break; |
740 | - // TODO: case to nest preview (once such API is available) |
741 | - default: |
742 | - if (m_associatedScope) { |
743 | - m_associatedScope->handleActivation(response, result); |
744 | - } |
745 | - |
746 | - if (m_activePreview) { |
747 | - m_activePreview->setProcessingAction(false); |
748 | - } |
749 | - break; |
750 | - } |
751 | -} |
752 | - |
753 | -void PreviewStack::setWidgetColumnCount(int columnCount) |
754 | -{ |
755 | - if (m_widgetColumnCount != columnCount) { |
756 | - m_widgetColumnCount = columnCount; |
757 | - // set on all previews |
758 | - for (int i = 0; i < m_previews.size(); i++) { |
759 | - m_previews[i]->setWidgetColumnCount(columnCount); |
760 | - } |
761 | - Q_EMIT widgetColumnCountChanged(); |
762 | - } |
763 | -} |
764 | - |
765 | -int PreviewStack::widgetColumnCount() const |
766 | -{ |
767 | - return m_widgetColumnCount; |
768 | -} |
769 | - |
770 | -int PreviewStack::rowCount(const QModelIndex&) const |
771 | -{ |
772 | - return m_previews.size(); |
773 | -} |
774 | - |
775 | -unity::scopes::Result::SPtr PreviewStack::previewedResult() const |
776 | -{ |
777 | - return m_previewedResult; |
778 | -} |
779 | - |
780 | -unity::shell::scopes::PreviewModelInterface* PreviewStack::getPreviewModel(int index) const |
781 | -{ |
782 | - if (index >= m_previews.size()) { |
783 | - return nullptr; |
784 | - } |
785 | - |
786 | - return m_previews.at(index); |
787 | -} |
788 | - |
789 | -QVariant PreviewStack::data(const QModelIndex& index, int role) const |
790 | -{ |
791 | - int row = index.row(); |
792 | - if (row >= m_previews.size()) |
793 | - { |
794 | - qWarning() << "PreviewStack::data - invalid index" << row << "size" |
795 | - << m_previews.size(); |
796 | - return QVariant(); |
797 | - } |
798 | - |
799 | - switch (role) { |
800 | - case RolePreviewModel: |
801 | - return QVariant::fromValue(m_previews.at(index.row())); |
802 | - default: |
803 | - return QVariant(); |
804 | - } |
805 | -} |
806 | - |
807 | -} // namespace scopes_ng |
808 | |
809 | === removed file 'src/Unity/previewstack.h' |
810 | --- src/Unity/previewstack.h 2015-08-14 12:29:16 +0000 |
811 | +++ src/Unity/previewstack.h 1970-01-01 00:00:00 +0000 |
812 | @@ -1,94 +0,0 @@ |
813 | -/* |
814 | - * Copyright (C) 2014 Canonical, Ltd. |
815 | - * |
816 | - * Authors: |
817 | - * Michał Sawicz <michal.sawicz@canonical.com> |
818 | - * Michal Hruby <michal.hruby@canonical.com> |
819 | - * |
820 | - * This program is free software; you can redistribute it and/or modify |
821 | - * it under the terms of the GNU General Public License as published by |
822 | - * the Free Software Foundation; version 3. |
823 | - * |
824 | - * This program is distributed in the hope that it will be useful, |
825 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
826 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
827 | - * GNU General Public License for more details. |
828 | - * |
829 | - * You should have received a copy of the GNU General Public License |
830 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
831 | - */ |
832 | - |
833 | - |
834 | -#ifndef NG_PREVIEW_STACK_H |
835 | -#define NG_PREVIEW_STACK_H |
836 | - |
837 | -#include <unity/shell/scopes/PreviewStackInterface.h> |
838 | - |
839 | -#include <QSet> |
840 | -#include <QSharedPointer> |
841 | -#include <QMultiMap> |
842 | -#include <QPointer> |
843 | -#include <QUuid> |
844 | - |
845 | -#include <unity/scopes/PreviewWidget.h> |
846 | -#include <unity/scopes/Result.h> |
847 | - |
848 | -#include "collectors.h" |
849 | - |
850 | -namespace scopes_ng |
851 | -{ |
852 | - |
853 | -class PreviewModel; |
854 | -class Scope; |
855 | - |
856 | -class Q_DECL_EXPORT PreviewStack : public unity::shell::scopes::PreviewStackInterface |
857 | -{ |
858 | - Q_OBJECT |
859 | - |
860 | -public: |
861 | - explicit PreviewStack(QObject* parent = 0); |
862 | - virtual ~PreviewStack(); |
863 | - |
864 | - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
865 | - int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
866 | - |
867 | - virtual bool event(QEvent* ev) override; |
868 | - |
869 | - Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* getPreviewModel(int index) const override; |
870 | - |
871 | - void loadForResult(unity::scopes::Result::SPtr const&); |
872 | - void update(unity::scopes::PreviewWidgetList const&); |
873 | - |
874 | - void setWidgetColumnCount(int columnCount) override; |
875 | - int widgetColumnCount() const override; |
876 | - void setAssociatedScope(scopes_ng::Scope*, QUuid const&, QString const&); |
877 | - scopes_ng::Scope* associatedScope() const; |
878 | - unity::scopes::Result::SPtr previewedResult() const; |
879 | - |
880 | -private Q_SLOTS: |
881 | - void widgetTriggered(QString const&, QString const&, QVariantMap const&); |
882 | - |
883 | -private: |
884 | - void processActionResponse(PushEvent* pushEvent); |
885 | - |
886 | - void dispatchPreview(unity::scopes::Variant const& extra_data = unity::scopes::Variant()); |
887 | - |
888 | - int m_widgetColumnCount; |
889 | - QList<PreviewModel*> m_previews; |
890 | - PreviewModel* m_activePreview; |
891 | - QPointer<scopes_ng::Scope> m_associatedScope; |
892 | - |
893 | - unity::scopes::QueryCtrlProxy m_lastPreviewQuery; |
894 | - QMap<PreviewModel*, std::weak_ptr<ScopeDataReceiverBase>> m_listeners; |
895 | - std::shared_ptr<ScopeDataReceiverBase> m_lastActivation; |
896 | - |
897 | - unity::scopes::Result::SPtr m_previewedResult; |
898 | - QUuid m_session_id; |
899 | - QString m_userAgent; |
900 | -}; |
901 | - |
902 | -} // namespace scopes_ng |
903 | - |
904 | -Q_DECLARE_METATYPE(scopes_ng::PreviewStack*) |
905 | - |
906 | -#endif // NG_PREVIEW_STACK_H |
907 | |
908 | === modified file 'src/Unity/scope.cpp' |
909 | --- src/Unity/scope.cpp 2016-02-26 11:51:36 +0000 |
910 | +++ src/Unity/scope.cpp 2016-02-26 11:51:36 +0000 |
911 | @@ -23,7 +23,7 @@ |
912 | // local |
913 | #include "categories.h" |
914 | #include "collectors.h" |
915 | -#include "previewstack.h" |
916 | +#include "previewmodel.h" |
917 | #include "locationservice.h" |
918 | #include "utils.h" |
919 | #include "scopes.h" |
920 | @@ -273,15 +273,15 @@ |
921 | |
922 | void Scope::handlePreviewUpdate(unity::scopes::Result::SPtr const& result, unity::scopes::PreviewWidgetList const& widgets) |
923 | { |
924 | - for (auto stack: m_previewStacks) { |
925 | - auto previewedResult = stack->previewedResult(); |
926 | + for (auto model: m_previewModels) { |
927 | + auto previewedResult = model->previewedResult(); |
928 | |
929 | if (result == nullptr) { |
930 | qWarning() << "handlePreviewUpdate: result is null"; |
931 | return; |
932 | } |
933 | if (previewedResult != nullptr && *result == *previewedResult) { |
934 | - stack->update(widgets); |
935 | + model->update(widgets); |
936 | } |
937 | } |
938 | } |
939 | @@ -1024,12 +1024,13 @@ |
940 | m_inverseDepartments.erase(it); |
941 | } |
942 | |
943 | -void Scope::previewStackDestroyed(QObject *obj) |
944 | +void Scope::previewModelDestroyed(QObject *obj) |
945 | { |
946 | - for (auto it = m_previewStacks.begin(); it != m_previewStacks.end(); it++) |
947 | + for (auto it = m_previewModels.begin(); it != m_previewModels.end(); it++) |
948 | { |
949 | if (*it == obj) { |
950 | - m_previewStacks.erase(it); |
951 | + qDebug() << "PreviewModel destroyed"; |
952 | + m_previewModels.erase(it); |
953 | break; |
954 | } |
955 | } |
956 | @@ -1302,7 +1303,7 @@ |
957 | } |
958 | } |
959 | |
960 | -unity::shell::scopes::PreviewStackInterface* Scope::preview(QVariant const& result_var, QString const& categoryId) |
961 | +unity::shell::scopes::PreviewModelInterface* Scope::preview(QVariant const& result_var, QString const& categoryId) |
962 | { |
963 | if (!result_var.canConvert<std::shared_ptr<scopes::Result>>()) { |
964 | qWarning("Cannot preview, unable to convert %s to Result", result_var.typeName()); |
965 | @@ -1320,12 +1321,12 @@ |
966 | return nullptr; |
967 | } |
968 | |
969 | - PreviewStack* stack = new PreviewStack(nullptr); |
970 | - QObject::connect(stack, &QObject::destroyed, this, &Scope::previewStackDestroyed); |
971 | - m_previewStacks.append(stack); |
972 | - stack->setAssociatedScope(this, m_session_id, m_scopesInstance->userAgentString()); |
973 | - stack->loadForResult(result); |
974 | - return stack; |
975 | + PreviewModel* previewModel = new PreviewModel(nullptr); |
976 | + QObject::connect(previewModel, &QObject::destroyed, this, &Scope::previewModelDestroyed); |
977 | + m_previewModels.append(previewModel); |
978 | + previewModel->setAssociatedScope(this, m_session_id, m_scopesInstance->userAgentString()); |
979 | + previewModel->loadForResult(result); |
980 | + return previewModel; |
981 | } |
982 | |
983 | void Scope::cancelActivation() |
984 | |
985 | === modified file 'src/Unity/scope.h' |
986 | --- src/Unity/scope.h 2016-02-26 11:51:36 +0000 |
987 | +++ src/Unity/scope.h 2016-02-26 11:51:36 +0000 |
988 | @@ -48,7 +48,7 @@ |
989 | |
990 | class Categories; |
991 | class PushEvent; |
992 | -class PreviewStack; |
993 | +class PreviewModel; |
994 | class LocationService; |
995 | class SettingsModel; |
996 | class Scopes; |
997 | @@ -149,7 +149,7 @@ |
998 | void setFavorite(const bool) override; |
999 | |
1000 | Q_INVOKABLE void activate(QVariant const& result, QString const& categoryId) override; |
1001 | - Q_INVOKABLE unity::shell::scopes::PreviewStackInterface* preview(QVariant const& result, QString const& categoryId) override; |
1002 | + Q_INVOKABLE unity::shell::scopes::PreviewModelInterface* preview(QVariant const& result, QString const& categoryId) override; |
1003 | Q_INVOKABLE void cancelActivation() override; |
1004 | Q_INVOKABLE void closeScope(unity::shell::scopes::ScopeInterface* scope) override; |
1005 | Q_INVOKABLE unity::shell::scopes::NavigationInterface* getNavigation(QString const& id) override; |
1006 | @@ -191,7 +191,7 @@ |
1007 | void flushUpdates(bool finalize = false); |
1008 | void metadataRefreshed(); |
1009 | void departmentModelDestroyed(QObject* obj); |
1010 | - void previewStackDestroyed(QObject *obj); |
1011 | + void previewModelDestroyed(QObject *obj); |
1012 | |
1013 | protected: |
1014 | explicit Scope(scopes_ng::Scopes* parent); |
1015 | @@ -267,7 +267,7 @@ |
1016 | QSharedPointer<LocationService> m_locationService; |
1017 | QSharedPointer<LocationService::Token> m_locationToken; |
1018 | QNetworkConfigurationManager m_network_manager; |
1019 | - QList<PreviewStack*> m_previewStacks; |
1020 | + QList<PreviewModel*> m_previewModels; |
1021 | }; |
1022 | |
1023 | } // namespace scopes_ng |
1024 | |
1025 | === modified file 'src/scope-harness/internal/preview-widget-arguments.h' |
1026 | --- src/scope-harness/internal/preview-widget-arguments.h 2015-04-24 13:06:14 +0000 |
1027 | +++ src/scope-harness/internal/preview-widget-arguments.h 2016-02-26 11:51:36 +0000 |
1028 | @@ -31,7 +31,6 @@ |
1029 | { |
1030 | class PreviewWidgetModelInterface; |
1031 | class PreviewModelInterface; |
1032 | - class PreviewStackInterface; |
1033 | } |
1034 | } |
1035 | namespace scopeharness |
1036 | @@ -54,8 +53,6 @@ |
1037 | std::shared_ptr<view::ResultsView> resultsView; |
1038 | |
1039 | std::shared_ptr<view::PreviewView> previewView; |
1040 | - |
1041 | - std::shared_ptr<unity::shell::scopes::PreviewStackInterface> previewStack; |
1042 | }; |
1043 | } |
1044 | } |
1045 | |
1046 | === modified file 'src/scope-harness/preview/preview-widget.cpp' |
1047 | --- src/scope-harness/preview/preview-widget.cpp 2015-08-20 07:32:49 +0000 |
1048 | +++ src/scope-harness/preview/preview-widget.cpp 2016-02-26 11:51:36 +0000 |
1049 | @@ -23,11 +23,12 @@ |
1050 | #include <scope-harness/view/results-view.h> |
1051 | #include <scope-harness/test-utils.h> |
1052 | |
1053 | +#include <Unity/previewmodel.h> |
1054 | + |
1055 | #include <unity/shell/scopes/PreviewModelInterface.h> |
1056 | #include <unity/shell/scopes/PreviewWidgetModelInterface.h> |
1057 | |
1058 | #include <Unity/utils.h> |
1059 | -#include <Unity/previewstack.h> |
1060 | |
1061 | #include <QDebug> |
1062 | #include <QSignalSpy> |
1063 | @@ -57,8 +58,6 @@ |
1064 | weak_ptr<view::ResultsView> m_resultsView; |
1065 | |
1066 | weak_ptr<view::PreviewView> m_previewView; |
1067 | - |
1068 | - std::shared_ptr<unity::shell::scopes::PreviewStackInterface> m_previewStack; |
1069 | }; |
1070 | |
1071 | PreviewWidget::PreviewWidget(const internal::PreviewWidgetArguments& arguments) : |
1072 | @@ -69,7 +68,6 @@ |
1073 | p->m_index = arguments.index; |
1074 | p->m_resultsView = arguments.resultsView; |
1075 | p->m_previewView = arguments.previewView; |
1076 | - p->m_previewStack = arguments.previewStack; |
1077 | } |
1078 | |
1079 | |
1080 | @@ -91,7 +89,6 @@ |
1081 | p->m_index = other.p->m_index; |
1082 | p->m_resultsView = other.p->m_resultsView; |
1083 | p->m_previewView = other.p->m_previewView; |
1084 | - p->m_previewStack = other.p->m_previewStack; |
1085 | return *this; |
1086 | } |
1087 | |
1088 | @@ -127,9 +124,8 @@ |
1089 | |
1090 | view::AbstractView::SPtr PreviewWidget::trigger(const string& name, const sc::Variant& v) |
1091 | { |
1092 | - auto ps = std::dynamic_pointer_cast<ng::PreviewStack>(p->m_previewStack); |
1093 | - TestUtils::throwIfNot(bool(ps), "No preview stack"); |
1094 | - TestUtils::throwIfNot(bool(ps->associatedScope()), "Preview stack has no associated scope"); |
1095 | + auto ps = dynamic_cast<ng::PreviewModel*>(p->m_previewModel); |
1096 | + TestUtils::throwIfNot(bool(ps->associatedScope()), "Preview model has no associated scope"); |
1097 | QSignalSpy showDashSpy(ps->associatedScope(), SIGNAL(showDash())); |
1098 | |
1099 | QVariant widgetData; |
1100 | @@ -153,7 +149,7 @@ |
1101 | widgetData = ng::scopeVariantToQVariant(v); |
1102 | } |
1103 | |
1104 | - Q_EMIT p->m_previewModel->triggered( |
1105 | + Q_EMIT ps->triggered( |
1106 | QString::fromStdString(id()), QString::fromStdString(name), |
1107 | widgetData.toMap()); |
1108 | |
1109 | |
1110 | === modified file 'src/scope-harness/results/result.cpp' |
1111 | --- src/scope-harness/results/result.cpp 2015-11-30 09:23:32 +0000 |
1112 | +++ src/scope-harness/results/result.cpp 2016-02-26 11:51:36 +0000 |
1113 | @@ -23,9 +23,9 @@ |
1114 | #include <scope-harness/view/results-view.h> |
1115 | |
1116 | #include <Unity/resultsmodel.h> |
1117 | -#include <Unity/previewstack.h> |
1118 | #include <Unity/scope.h> |
1119 | #include <Unity/utils.h> |
1120 | +#include <Unity/previewmodel.h> |
1121 | |
1122 | #include <QObject> |
1123 | #include <QSignalSpy> |
1124 | @@ -137,7 +137,7 @@ |
1125 | // TODO set scope inactive? |
1126 | auto result = m_resultsModel->data( |
1127 | m_index, ss::ResultsModelInterface::Roles::RoleResult); |
1128 | - shared_ptr<ss::PreviewStackInterface> preview( |
1129 | + shared_ptr<ss::PreviewModelInterface> preview( |
1130 | m_scope->preview(result, m_resultsModel->categoryId())); |
1131 | previewView->preview(preview); |
1132 | view = previewView; |
1133 | @@ -161,7 +161,7 @@ |
1134 | auto result = m_resultsModel->data( |
1135 | m_index, |
1136 | ss::ResultsModelInterface::Roles::RoleResult); |
1137 | - shared_ptr<ss::PreviewStackInterface> preview( |
1138 | + shared_ptr<ss::PreviewModelInterface> preview( |
1139 | m_scope->preview(result, m_resultsModel->categoryId())); |
1140 | previewView->preview(preview); |
1141 | view = previewView; |
1142 | @@ -379,7 +379,7 @@ |
1143 | } |
1144 | |
1145 | auto previewView = p->m_previewView.lock(); |
1146 | - shared_ptr<ss::PreviewStackInterface> preview(p->m_scope->preview(result_var, p->m_resultsModel->categoryId())); |
1147 | + shared_ptr<ss::PreviewModelInterface> preview(p->m_scope->preview(result_var, p->m_resultsModel->categoryId())); |
1148 | previewView->preview(preview); |
1149 | return previewView; |
1150 | } |
1151 | @@ -418,7 +418,7 @@ |
1152 | return nullptr; // nothing happens for scope:// uris |
1153 | } |
1154 | auto previewView = p->m_previewView.lock(); |
1155 | - shared_ptr<ss::PreviewStackInterface> preview(p->m_scope->preview(result_var, p->m_resultsModel->categoryId())); |
1156 | + shared_ptr<ss::PreviewModelInterface> preview(p->m_scope->preview(result_var, p->m_resultsModel->categoryId())); |
1157 | previewView->preview(preview); |
1158 | return previewView; |
1159 | } |
1160 | |
1161 | === modified file 'src/scope-harness/test-utils.cpp' |
1162 | --- src/scope-harness/test-utils.cpp 2015-10-27 09:14:07 +0000 |
1163 | +++ src/scope-harness/test-utils.cpp 2016-02-26 11:51:36 +0000 |
1164 | @@ -33,7 +33,6 @@ |
1165 | #include <Unity/scope.h> |
1166 | #include <Unity/categories.h> |
1167 | #include <Unity/resultsmodel.h> |
1168 | -#include <Unity/previewstack.h> |
1169 | |
1170 | namespace sc = unity::scopes; |
1171 | namespace ng = scopes_ng; |
1172 | @@ -136,18 +135,6 @@ |
1173 | QCOMPARE(scope->searchInProgress(), false); |
1174 | } |
1175 | |
1176 | -bool TestUtils::previewForFirstResult(ng::Scope::Ptr scope, QString const& searchString, QScopedPointer<ng::PreviewStack>& preview_stack) |
1177 | -{ |
1178 | - performSearch(scope, searchString); |
1179 | - |
1180 | - unity::scopes::Result::SPtr result; |
1181 | - if (!getFirstResult(scope->categories(), result)) |
1182 | - return false; |
1183 | - preview_stack.reset(static_cast<ng::PreviewStack*>(scope->preview(QVariant::fromValue(result), ""))); //FIXME |
1184 | - |
1185 | - return true; |
1186 | -} |
1187 | - |
1188 | void TestUtils::setFavouriteScopes(const QStringList& cannedQueries) |
1189 | { |
1190 | setenv("GSETTINGS_BACKEND", "memory", 1); |
1191 | |
1192 | === modified file 'src/scope-harness/test-utils.h' |
1193 | --- src/scope-harness/test-utils.h 2015-03-10 11:23:01 +0000 |
1194 | +++ src/scope-harness/test-utils.h 2016-02-26 11:51:36 +0000 |
1195 | @@ -57,9 +57,6 @@ |
1196 | static void waitForSearchFinish(QSharedPointer<shell::scopes::ScopeInterface> scope); |
1197 | |
1198 | Q_DECL_EXPORT |
1199 | -static bool previewForFirstResult(scopes_ng::Scope::Ptr scope, QString const& searchString, QScopedPointer<scopes_ng::PreviewStack>& preview_stack); |
1200 | - |
1201 | -Q_DECL_EXPORT |
1202 | static void setFavouriteScopes(const QStringList& cannedQueries); |
1203 | |
1204 | Q_DECL_EXPORT |
1205 | |
1206 | === modified file 'src/scope-harness/view/preview-view.cpp' |
1207 | --- src/scope-harness/view/preview-view.cpp 2015-04-24 13:06:14 +0000 |
1208 | +++ src/scope-harness/view/preview-view.cpp 2016-02-26 11:51:36 +0000 |
1209 | @@ -23,7 +23,6 @@ |
1210 | #include <scope-harness/test-utils.h> |
1211 | |
1212 | #include <unity/shell/scopes/PreviewModelInterface.h> |
1213 | -#include <unity/shell/scopes/PreviewStackInterface.h> |
1214 | #include <unity/shell/scopes/PreviewWidgetModelInterface.h> |
1215 | |
1216 | |
1217 | @@ -53,7 +52,7 @@ |
1218 | { |
1219 | previewWidgets.emplace_back( |
1220 | preview::PreviewWidget(internal::PreviewWidgetArguments |
1221 | - { previewWidgetModel, previewWidgetModel->index(row), previewModel, m_resultsView.lock(), previewView, m_previewStack})); |
1222 | + { previewWidgetModel, previewWidgetModel->index(row), previewModel, m_resultsView.lock(), previewView })); |
1223 | } |
1224 | |
1225 | return preview::PreviewWidgetList(internal::PreviewWidgetListArguments{previewWidgets}); |
1226 | @@ -82,24 +81,23 @@ |
1227 | return previewModels; |
1228 | } |
1229 | |
1230 | - void setPreviewModel(shared_ptr<ss::PreviewStackInterface> previewStack, PreviewView::SPtr previewView) |
1231 | + void setPreviewModel(shared_ptr<ss::PreviewModelInterface> previewModel, PreviewView::SPtr previewView) |
1232 | { |
1233 | - m_previewStack = previewStack; |
1234 | + m_previewModel = previewModel; |
1235 | updateModels(previewView); |
1236 | } |
1237 | |
1238 | void updateModels(PreviewView::SPtr previewView) |
1239 | { |
1240 | - auto previewModel = m_previewStack->getPreviewModel(0); |
1241 | - m_previewModels = iteratePreviewModel(previewModel, previewView); |
1242 | + m_previewModels = iteratePreviewModel(m_previewModel.get(), previewView); |
1243 | } |
1244 | |
1245 | - void checkPreviewStack() |
1246 | + void checkPreviewModel() |
1247 | { |
1248 | - TestUtils::throwIfNot(bool(m_previewStack), ""); |
1249 | + TestUtils::throwIfNot(bool(m_previewModel), ""); |
1250 | } |
1251 | |
1252 | - shared_ptr<ss::PreviewStackInterface> m_previewStack; |
1253 | + shared_ptr<ss::PreviewModelInterface> m_previewModel; |
1254 | |
1255 | vector<preview::PreviewWidgetList> m_previewModels; |
1256 | |
1257 | @@ -116,17 +114,17 @@ |
1258 | p->m_resultsView = resultsView; |
1259 | } |
1260 | |
1261 | -void PreviewView::preview(shared_ptr<ss::PreviewStackInterface> previewStack) |
1262 | +void PreviewView::preview(shared_ptr<ss::PreviewModelInterface> previewModel) |
1263 | { |
1264 | - p->setPreviewModel(previewStack, |
1265 | + p->setPreviewModel(previewModel, |
1266 | dynamic_pointer_cast<PreviewView>(shared_from_this())); |
1267 | } |
1268 | |
1269 | void PreviewView::setColumnCount(unsigned int count) |
1270 | { |
1271 | - p->checkPreviewStack(); |
1272 | + p->checkPreviewModel(); |
1273 | |
1274 | - p->m_previewStack->setWidgetColumnCount(count); |
1275 | + p->m_previewModel->setWidgetColumnCount(count); |
1276 | // TODO Wait? |
1277 | refresh(); |
1278 | } |
1279 | @@ -138,21 +136,21 @@ |
1280 | |
1281 | unsigned int PreviewView::columnCount() const |
1282 | { |
1283 | - p->checkPreviewStack(); |
1284 | + p->checkPreviewModel(); |
1285 | |
1286 | - return p->m_previewStack->widgetColumnCount(); |
1287 | + return p->m_previewModel->widgetColumnCount(); |
1288 | } |
1289 | |
1290 | vector<preview::PreviewWidgetList> PreviewView::widgets() |
1291 | { |
1292 | - p->checkPreviewStack(); |
1293 | + p->checkPreviewModel(); |
1294 | |
1295 | return p->m_previewModels; |
1296 | } |
1297 | |
1298 | preview::PreviewWidgetList PreviewView::widgetsInColumn(size_t column) |
1299 | { |
1300 | - p->checkPreviewStack(); |
1301 | + p->checkPreviewModel(); |
1302 | |
1303 | return p->m_previewModels.at(column); |
1304 | } |
1305 | |
1306 | === modified file 'src/scope-harness/view/preview-view.h' |
1307 | --- src/scope-harness/view/preview-view.h 2015-03-10 11:23:01 +0000 |
1308 | +++ src/scope-harness/view/preview-view.h 2016-02-26 11:51:36 +0000 |
1309 | @@ -27,7 +27,7 @@ |
1310 | { |
1311 | namespace scopes |
1312 | { |
1313 | -class PreviewStackInterface; |
1314 | +class PreviewModelInterface; |
1315 | } |
1316 | } |
1317 | namespace scopeharness |
1318 | @@ -74,7 +74,7 @@ |
1319 | friend ScopeHarness; |
1320 | friend preview::PreviewWidget; |
1321 | |
1322 | - void preview(std::shared_ptr<shell::scopes::PreviewStackInterface> previewStack); |
1323 | + void preview(std::shared_ptr<shell::scopes::PreviewModelInterface> previewModel); |
1324 | |
1325 | void setResultsView(std::shared_ptr<ResultsView> resultsView); |
1326 | |
1327 | |
1328 | === modified file 'tests/overviewtest.cpp' |
1329 | --- tests/overviewtest.cpp 2016-02-04 15:41:08 +0000 |
1330 | +++ tests/overviewtest.cpp 2016-02-26 11:51:36 +0000 |
1331 | @@ -31,7 +31,6 @@ |
1332 | #include <categories.h> |
1333 | #include <overviewresults.h> |
1334 | #include <previewmodel.h> |
1335 | -#include <previewstack.h> |
1336 | #include <previewwidgetmodel.h> |
1337 | |
1338 | #include <scope-harness/registry/pre-existing-registry.h> |
1339 | |
1340 | === modified file 'tests/previewtest.cpp' |
1341 | --- tests/previewtest.cpp 2015-08-14 12:29:16 +0000 |
1342 | +++ tests/previewtest.cpp 2016-02-26 11:51:36 +0000 |
1343 | @@ -29,7 +29,6 @@ |
1344 | #include <categories.h> |
1345 | #include <resultsmodel.h> |
1346 | #include <previewmodel.h> |
1347 | -#include <previewstack.h> |
1348 | #include <previewwidgetmodel.h> |
1349 | |
1350 | #include <scope-harness/matcher/category-matcher.h> |
bring back the top warning to debian/control ?