Merge lp:~stolowski/unity-scopes-shell/single-preview into lp:unity-scopes-shell

Proposed by Paweł Stołowski
Status: Superseded
Proposed branch: lp:~stolowski/unity-scopes-shell/single-preview
Merge into: lp:unity-scopes-shell
Diff against target: 1456 lines (+299/-517)
23 files modified
CMakeLists.txt (+1/-1)
debian/HARNESS_VERSION (+1/-1)
debian/control.in (+2/-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 (+34/-14)
src/Unity/scope.h (+7/-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
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Needs Fixing
Review via email: mp+286360@code.launchpad.net

This proposal has been superseded by a proposal from 2016-02-18.

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://code.launchpad.net/~stolowski/unity-api/single-preview/+merge/286359

To post a comment you must log in.
289. By Paweł Stołowski

Merged trunk

290. By Paweł Stołowski

Require new API

291. By Paweł Stołowski

Updated scope harness symbols file

Revision history for this message
Albert Astals Cid (aacid) wrote :

bring back the top warning to debian/control ?

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good otherwise

292. By Paweł Stołowski

Reverted accidental change to generated debian/control file

Revision history for this message
Paweł Stołowski (stolowski) wrote :

> bring back the top warning to debian/control ?

Ah, right, this file is generated, I shouldn't have commited it. Fixed, thanks for spotting.

293. By Paweł Stołowski

Merged activation-progress

294. By Paweł Stołowski

Debug message when preview model gets destroyed

Unmerged revisions

285. By Launchpad Translations on behalf of unity-team

Launchpad automatic translations update.

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: