on xenial help sign in
Make tests pass a bit more
09ed561Albert Astals
qml/Dash/CardCarousel.qml+1−1
@@ -60,7 +60,7 @@ DashRenderer {
60
60
61 itemComponent: Card {
61 itemComponent: Card {
62 id: card
62 id: card
63− objectName: "delegate" + index
63+ objectName: "carouselDelegate" + index
64 headerHeight: carousel.headerHeight
64 headerHeight: carousel.headerHeight
65 cardData: model
65 cardData: model
66 template: cardCarousel.template
66 template: cardCarousel.template
qml/Dash/CardFilterGrid.qml+1
@@ -30,6 +30,7 @@ DashFilterGrid {
30
30
31 template: genericFilterGrid.template
31 template: genericFilterGrid.template
32 components: genericFilterGrid.components
32 components: genericFilterGrid.components
33+ viewWidth: genericFilterGrid.width
33 }
34 }
34
35
35 delegate: Item {
36 delegate: Item {
qml/Dash/PreviewListView.qml+1−1
@@ -39,7 +39,7 @@ Item {
39 top: previewListView.bottom
39 top: previewListView.bottom
40 left: parent.left
40 left: parent.left
41 leftMargin: previewListView.categoryDelegate !== undefined && previewListView.categoryDelegate.currentItem ?
41 leftMargin: previewListView.categoryDelegate !== undefined && previewListView.categoryDelegate.currentItem ?
42− previewListView.categoryDelegate.currentItem.center + (-width + margins) / 2 : 0
42+ previewListView.categoryDelegate.currentItem.x + previewListView.categoryDelegate.currentItem.width / 2 + (-width + margins) / 2 : 0
43
43
44 Behavior on leftMargin {
44 Behavior on leftMargin {
45 SmoothedAnimation {
45 SmoothedAnimation {
tests/mocks/Unity/CMakeLists.txt+2−4
@@ -18,14 +18,12 @@ include_directories(
18add_definitions(-DQT_NO_KEYWORDS)
18add_definitions(-DQT_NO_KEYWORDS)
19
19
20set(UnityQML_SOURCES
20set(UnityQML_SOURCES
21− categoryresults.cpp
22 iconutils.cpp
21 iconutils.cpp
23− fake_applications_scope.cpp
24− fake_preview.cpp
25 fake_scope.cpp
22 fake_scope.cpp
26 fake_scopes.cpp
23 fake_scopes.cpp
27 fake_categories.cpp
24 fake_categories.cpp
25+ fake_resultsmodel.cpp
28− scopes-ng/fake_preview_model.cpp
26+ fake_preview_model.cpp
29 fake_unity_plugin.cpp
27 fake_unity_plugin.cpp
30)
28)
31
29
tests/mocks/Unity/categoryresults.cppdeleted−121
@@ -1,121 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * Authors:
5− * Michal Hruby <michal.hruby@canonical.com>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License as published by
9− * the Free Software Foundation; version 3.
10− *
11− * This program is distributed in the hope that it will be useful,
12− * but WITHOUT ANY WARRANTY; without even the implied warranty of
13− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14− * GNU General Public License for more details.
15− *
16− * You should have received a copy of the GNU General Public License
17− * along with this program. If not, see <http://www.gnu.org/licenses/>.
18− */
19−
20−// self
21−#include "categoryresults.h"
22−#include "iconutils.h"
23−
24−// TODO: use something from libunity once it's public
25−enum ResultsColumn {
26− URI,
27− ICON_HINT,
28− CATEGORY,
29− RESULT_TYPE,
30− MIMETYPE,
31− TITLE,
32− COMMENT,
33− DND_URI,
34− METADATA
35−};
36−
37−CategoryResults::CategoryResults(QObject* parent)
38− : DeeListModel(parent)
39− , m_categoryIndex(-1)
40−{
41− m_roles[CategoryResults::RoleUri] = "uri";
42− m_roles[CategoryResults::RoleIconHint] = "icon";
43− m_roles[CategoryResults::RoleCategory] = "category";
44− m_roles[CategoryResults::RoleMimetype] = "mimetype";
45− m_roles[CategoryResults::RoleTitle] = "title";
46− m_roles[CategoryResults::RoleComment] = "comment";
47− m_roles[CategoryResults::RoleDndUri] = "dndUri";
48− m_roles[CategoryResults::RoleMetadata] = "metadata";
49− m_roles[CategoryResults::RoleRendererHints] = "rendererHints";
50−}
51−
52−int CategoryResults::categoryIndex() const
53−{
54− return m_categoryIndex;
55−}
56−
57−void CategoryResults::setCategoryIndex(int index)
58−{
59− if (m_categoryIndex != index) {
60− m_categoryIndex = index;
61− Q_EMIT categoryIndexChanged(m_categoryIndex);
62− }
63−}
64−
65−QHash<int, QByteArray>
66−CategoryResults::roleNames() const
67−{
68− return m_roles;
69−}
70−
71−QVariant
72−CategoryResults::data(const QModelIndex& index, int role) const
73−{
74− if (!index.isValid()) {
75− return QVariant();
76− }
77−
78− switch (role) {
79− case RoleUri:
80− return DeeListModel::data(index, ResultsColumn::URI);
81− case RoleIconHint: {
82− QString giconString(DeeListModel::data(index, ResultsColumn::ICON_HINT).toString());
83− if (giconString.isEmpty()) {
84− QString mimetype(DeeListModel::data(index, ResultsColumn::MIMETYPE).toString());
85− QString uri(DeeListModel::data(index, ResultsColumn::URI).toString());
86− QString thumbnailerUri(uriToThumbnailerProviderString(uri, mimetype, DeeListModel::data(index, ResultsColumn::METADATA).toHash()));
87− if (!thumbnailerUri.isNull()) {
88− return QVariant::fromValue(thumbnailerUri);
89− }
90− }
91− return QVariant::fromValue(gIconToDeclarativeImageProviderString(giconString));
92− }
93− case RoleCategory:
94− return DeeListModel::data(index, ResultsColumn::CATEGORY);
95− case RoleMimetype:
96− return DeeListModel::data(index, ResultsColumn::MIMETYPE);
97− case RoleTitle:
98− return DeeListModel::data(index, ResultsColumn::TITLE);
99− case RoleComment:
100− return DeeListModel::data(index, ResultsColumn::COMMENT);
101− case RoleDndUri:
102− return DeeListModel::data(index, ResultsColumn::DND_URI);
103− case RoleMetadata:
104− return DeeListModel::data(index, ResultsColumn::METADATA);
105− case RoleRendererHints:
106− {
107− QVariantHash hash(DeeListModel::data(index, ResultsColumn::METADATA).toHash());
108− if (hash.contains("content")) {
109− QVariantMap hints;
110− QVariantHash innerHash(hash["content"].toHash());
111− if (innerHash.contains("scope_disabled")) {
112− hints["scope_disabled"] = innerHash["scope_disabled"];
113− }
114− return hints.empty() ? QVariant() : QVariant::fromValue(hints);
115− }
116− return QVariant();
117− }
118− default:
119− return QVariant();
120− }
121−}
tests/mocks/Unity/categoryresults.hdeleted−68
@@ -1,68 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * Authors:
5− * Michal Hruby <michal.hruby@canonical.com>
6− *
7− * This program is free software; you can redistribute it and/or modify
8− * it under the terms of the GNU General Public License as published by
9− * the Free Software Foundation; version 3.
10− *
11− * This program is distributed in the hope that it will be useful,
12− * but WITHOUT ANY WARRANTY; without even the implied warranty of
13− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14− * GNU General Public License for more details.
15− *
16− * You should have received a copy of the GNU General Public License
17− * along with this program. If not, see <http://www.gnu.org/licenses/>.
18− */
19−
20−
21−#ifndef CATEGORY_RESULTS_H
22−#define CATEGORY_RESULTS_H
23−
24−// dee-qt
25−#include "deelistmodel.h"
26−
27−class Q_DECL_EXPORT CategoryResults : public DeeListModel
28−{
29− Q_OBJECT
30−
31− Q_ENUMS(Roles)
32−
33− Q_PROPERTY(int categoryIndex READ categoryIndex WRITE setCategoryIndex NOTIFY categoryIndexChanged)
34−
35−public:
36− explicit CategoryResults(QObject* parent = 0);
37−
38− enum Roles {
39− RoleUri,
40− RoleIconHint,
41− RoleCategory,
42− RoleMimetype,
43− RoleTitle,
44− RoleComment,
45− RoleDndUri,
46− RoleMetadata,
47− RoleRendererHints
48− };
49−
50− QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
51−
52− QHash<int, QByteArray> roleNames() const;
53−
54− /* getters */
55− int categoryIndex() const;
56−
57− /* setters */
58− void setCategoryIndex(int index);
59−
60−Q_SIGNALS:
61− void categoryIndexChanged(int index);
62−
63−private:
64− QHash<int, QByteArray> m_roles;
65− int m_categoryIndex;
66−};
67−
68−#endif // CATEGORY_RESULTS_H
tests/mocks/Unity/fake_applications_scope.cppdeleted−76
@@ -1,76 +0,0 @@
1−/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "fake_applications_scope.h"
18−
19−static const gchar * categories_model_schema[] = {
20− "s", //ID
21− "s", // DISPLAY_NAME
22− "s", // ICON_HINT
23− "s", // RENDERER_NAME
24− "a{sv}" // HINTS
25−};
26−
27−ApplicationsScope::ApplicationsScope(bool visible, QObject* parent)
28− : Scope(parent)
29−{
30− m_id = "applications.scope";
31− m_name = "Applications";
32− m_visible = visible;
33− m_previewRendererName = "preview-application";
34− m_categories->setModel(createCategoriesModel());
35−}
36−
37−DeeModel* ApplicationsScope::createCategoriesModel()
38−{
39− DeeModel* category_model = dee_sequence_model_new();
40− dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
41− GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
42−
43− GVariant* children[1];
44− children[0] = g_variant_new_dict_entry(g_variant_new_string("content-type"),
45− g_variant_new_variant(g_variant_new_string("apps")));
46− GVariant* recentHints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), children, 1);
47− dee_model_append(category_model,
48− "recent",
49− "Recent",
50− "gtk-apply",
51− "special",
52− recentHints);
53−
54− dee_model_append(category_model,
55− "installed",
56− "Installed",
57− "gtk-apply",
58− "grid",
59− hints);
60−
61− dee_model_append(category_model,
62− "suggested",
63− "Suggested",
64− "gtk-apply",
65− "grid",
66− hints);
67−
68− dee_model_append(category_model,
69− "outdated",
70− "Outdaded",
71− "gtk-apply",
72− "grid",
73− hints);
74−
75− return category_model;
76−}
tests/mocks/Unity/fake_applications_scope.hdeleted−33
@@ -1,33 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef FAKE_APPLICATIONS_SCOPE_H
18−#define FAKE_APPLICATIONS_SCOPE_H
19−
20−#include "fake_scope.h"
21−
22−class ApplicationsScope : public Scope
23−{
24− Q_OBJECT
25−
26−public:
27− ApplicationsScope(bool visible, QObject* parent = 0);
28−
29−private:
30− DeeModel* createCategoriesModel();
31−};
32−
33−#endif // FAKE_APPLICATIONS_SCOPE_H
tests/mocks/Unity/fake_categories.cpp+37−196
@@ -19,100 +19,21 @@
19// self
19// self
20#include "fake_categories.h"
20#include "fake_categories.h"
21
21
22−// local
22+#include "fake_resultsmodel.h"
23−#include "categoryresults.h"
24
23
25−#define CATEGORY_COLUMN 2
26−
27−// TODO: use something from libunity once it's public
28−enum CategoryColumn {
29− ID,
30− DISPLAY_NAME,
31− ICON_HINT,
32− RENDERER_NAME,
33− HINTS
34−};
35−
36−Categories::Categories(QObject* parent)
24+Categories::Categories(int category_count, QObject* parent)
37− : DeeListModel(parent)
25+ : QAbstractListModel(parent)
26+ , m_category_count(category_count)
38{
27{
39− // FIXME: need to clean up unused filters on countChanged
40 m_roles[Categories::RoleCategoryId] = "categoryId";
28 m_roles[Categories::RoleCategoryId] = "categoryId";
41 m_roles[Categories::RoleName] = "name";
29 m_roles[Categories::RoleName] = "name";
42 m_roles[Categories::RoleIcon] = "icon";
30 m_roles[Categories::RoleIcon] = "icon";
31+ m_roles[Categories::RoleRawRendererTemplate] = "rawRendererTemplate";
43 m_roles[Categories::RoleRenderer] = "renderer";
32 m_roles[Categories::RoleRenderer] = "renderer";
44− m_roles[Categories::RoleContentType] = "contentType";
33+ m_roles[Categories::RoleComponents] = "components";
45− m_roles[Categories::RoleRendererHint] = "rendererHint";
46− m_roles[Categories::RoleHints] = "hints";
34+ m_roles[Categories::RoleProgressSource] = "progressSource";
47 m_roles[Categories::RoleResults] = "results";
35 m_roles[Categories::RoleResults] = "results";
48 m_roles[Categories::RoleCount] = "count";
36 m_roles[Categories::RoleCount] = "count";
49−
50− // TODO This should not be needed but accumulatting the count changes
51− // makes the visualization more stable and also makes crashes on fast
52− // change of the search term harder to reproduce
53− m_timer.setSingleShot(true);
54− m_timer.setInterval(50);
55− connect(&m_timer, SIGNAL(timeout()), this, SLOT(onEmitCountChanged()));
56−}
57−
58−DeeListModel*
59−Categories::getFilter(int index) const
60−{
61− if (!m_filters.contains(index)) {
62− auto results = new CategoryResults ();
63− results->setCategoryIndex(index);
64− connect(results, SIGNAL(countChanged()), this, SLOT(onCountChanged()));
65−
66− unsigned cat_index = static_cast<unsigned>(index);
67− auto model = getResultsForCategory(cat_index);
68− results->setModel(model);
69−
70− m_filters.insert(index, results);
71− }
72−
73− return m_filters[index];
74−}
75−
76−void
77−Categories::onCountChanged()
78−{
79− DeeListModel* filter = qobject_cast<DeeListModel*>(sender());
80− if (filter) {
81− m_timerFilters << filter;
82− m_timer.start();
83− }
84−}
85−
86−void Categories::onRowCountChanged()
87−{
88− QAbstractItemModel* model = qobject_cast<QAbstractItemModel*>(sender());
89− // find the corresponding category index
90− for (auto iter = m_overriddenCategories.begin(); iter != m_overriddenCategories.end(); ++iter) {
91− if (iter.value() == model) {
92− for (int i = 0; i < rowCount(); i++) {
93− auto id = data(index(i), RoleCategoryId).toString();
94− if (id != iter.key()) continue;
95− QVector<int> roles;
96− roles.append(RoleCount);
97− QModelIndex changedIndex = index(i);
98− Q_EMIT dataChanged(changedIndex, changedIndex, roles);
99− break;
100− }
101− }
102− }
103−}
104−
105−void
106−Categories::onEmitCountChanged()
107−{
108− QVector<int> roles;
109− roles.append(Categories::RoleCount);
110− Q_FOREACH(DeeListModel* results, m_timerFilters) {
111− auto cat_results = qobject_cast<CategoryResults*>(results);
112− QModelIndex changedIndex = index(cat_results->categoryIndex());
113− Q_EMIT dataChanged(changedIndex, changedIndex, roles);
114− }
115− m_timerFilters.clear();
116}
37}
117
38
118QHash<int, QByteArray>
39QHash<int, QByteArray>
@@ -121,93 +42,11 @@ Categories::roleNames() const
121 return m_roles;
42 return m_roles;
122}
43}
123
44
124−void Categories::onOverrideModelDestroyed()
45+int Categories::rowCount(const QModelIndex& /*parent*/) const
125{
46{
126− QObject* model = sender();
47+ return m_category_count;
127− auto iter = m_overriddenCategories.begin();
128− while (iter != m_overriddenCategories.end()) {
129− if (iter.value() == model) {
130− iter = m_overriddenCategories.erase(iter);
131− continue;
132− }
133− ++iter;
134− }
135}
48}
136
49
137−void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
138−{
139− m_overriddenCategories[categoryId] = model;
140− // watch the model
141− connect(model, &QObject::destroyed, this, &Categories::onOverrideModelDestroyed);
142− connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
143− connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
144− connect(model, &QAbstractItemModel::modelReset, this, &Categories::onRowCountChanged);
145−
146− // emit the dataChanged signal if the category is already in the model
147− for (int i = 0; i < rowCount(); i++) {
148− auto id = data(index(i), RoleCategoryId).toString();
149− if (id != categoryId) continue;
150− QVector<int> roles;
151− roles.append(RoleCount);
152− roles.append(RoleResults);
153− QModelIndex changedIndex = index(i);
154− Q_EMIT dataChanged(changedIndex, changedIndex, roles);
155− break;
156− }
157−}
158−
159−void Categories::setResultModel(DeeModel* model)
160−{
161− // FIXME: should ref it
162− m_dee_results = model;
163−}
164−
165−
166−static void category_filter_map_func (DeeModel* orig_model,
167− DeeFilterModel* filter_model,
168− gpointer user_data)
169−{
170− DeeModelIter* iter;
171− DeeModelIter* end;
172− unsigned index = GPOINTER_TO_UINT(user_data);
173−
174− iter = dee_model_get_first_iter(orig_model);
175− end = dee_model_get_last_iter(orig_model);
176− while (iter != end) {
177− unsigned category_index = dee_model_get_uint32(orig_model, iter, CATEGORY_COLUMN);
178− if (index == category_index) {
179− dee_filter_model_append_iter(filter_model, iter);
180− }
181− iter = dee_model_next(orig_model, iter);
182− }
183−}
184−
185−static gboolean category_filter_notify_func (DeeModel* orig_model,
186− DeeModelIter* orig_iter,
187− DeeFilterModel* filter_model,
188− gpointer user_data)
189−{
190− unsigned index = GPOINTER_TO_UINT(user_data);
191− unsigned category_index = dee_model_get_uint32(orig_model, orig_iter, CATEGORY_COLUMN);
192−
193− if (index != category_index)
194− return FALSE;
195−
196− dee_filter_model_insert_iter_with_original_order(filter_model, orig_iter);
197− return TRUE;
198−}
199−
200−DeeModel* Categories::getResultsForCategory(unsigned cat_index) const
201−{
202− DeeFilter filter;
203− filter.map_func = category_filter_map_func;
204− filter.map_notify = category_filter_notify_func;
205− filter.destroy = nullptr;
206− filter.userdata = GUINT_TO_POINTER(cat_index);
207−
208− DeeModel* filtered_model = dee_filter_model_new(m_dee_results, &filter);
209− return filtered_model;
210−}
211
50
212QVariant
51QVariant
213Categories::data(const QModelIndex& index, int role) const
52Categories::data(const QModelIndex& index, int role) const
@@ -216,44 +55,46 @@ Categories::data(const QModelIndex& index, int role) const
216 return QVariant();
55 return QVariant();
217 }
56 }
218
57
58+ ResultsModel *resultsModel = m_resultsModels[index.row()];
59+ if (!resultsModel) {
60+ resultsModel = new ResultsModel(15, index.row());
61+ m_resultsModels[index.row()] = resultsModel;
62+ }
219 switch (role) {
63 switch (role) {
220 case RoleCategoryId:
64 case RoleCategoryId:
221− return DeeListModel::data(index, CategoryColumn::ID);
65+ return QString("%1").arg(index.row());
222 case RoleName:
66 case RoleName:
223− return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
67+ return QString("Category %1").arg(index.row());
224 case RoleIcon:
68 case RoleIcon:
225− return DeeListModel::data(index, CategoryColumn::ICON_HINT);
69+ return "gtk-apply";
70+ case RoleRawRendererTemplate:
71+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
72+ return QVariant();
226 case RoleRenderer:
73 case RoleRenderer:
227− return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
228− case RoleContentType:
229 {
74 {
230− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
75+ QVariantMap map;
231− return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
76+ map["category-layout"] = index.row() % 2 == 0 ? "grid" : "carousel";
77+ map["card-size"] = "small";
78+ return map;
232 }
79 }
233− case RoleRendererHint:
80+ case RoleComponents:
234 {
81 {
235− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
82+ QVariantMap map, artMap;
236− return hints.contains("renderer-hint") ? hints["renderer-hint"] : QVariant(QString());
83+ artMap["aspect-ratio"] = "1.0";
84+ artMap["field"] = "art";
85+ map["art"] = artMap;
86+ map["title"] = "HOLA";
87+ return map;
237 }
88 }
238− case RoleHints:
89+ case RoleProgressSource:
239− return DeeListModel::data(index, CategoryColumn::HINTS);
90+ qFatal("Using un-implemented RoleProgressSource Categories role");
91+ return QVariant();
240 case RoleResults:
92 case RoleResults:
241− if (m_overriddenCategories.size() > 0)
242− {
243− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
244− if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
245− return QVariant::fromValue(m_overriddenCategories[id]);
93+ return QVariant::fromValue(resultsModel);
246− }
247− return QVariant::fromValue(getFilter(index.row()));
248 case RoleCount:
94 case RoleCount:
249− if (m_overriddenCategories.size() > 0)
95+ return resultsModel->rowCount();
250− {
251− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
252− if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
253− return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
254− }
255− return QVariant::fromValue(getFilter(index.row())->rowCount());
256 default:
96 default:
97+ qFatal("Using un-implemented Categories role");
257 return QVariant();
98 return QVariant();
258 }
99 }
259}
100}
tests/mocks/Unity/fake_categories.h+12−32
@@ -18,58 +18,38 @@
18#define FAKE_CATEGORIES_H
18#define FAKE_CATEGORIES_H
19
19
20// Qt
20// Qt
21−#include <QObject>
21+#include <QAbstractListModel>
22−#include <QSet>
23−#include <QTimer>
24
22
25−#include <dee.h>
23+class ResultsModel;
26−#include <deelistmodel.h>
27
24
28−class Categories : public DeeListModel
25+class Categories : public QAbstractListModel
29{
26{
30 Q_OBJECT
27 Q_OBJECT
31
28
32 Q_ENUMS(Roles)
29 Q_ENUMS(Roles)
33
30
34public:
31public:
35− Categories(QObject* parent = 0);
32+ Categories(int category_count, QObject* parent = 0);
36 enum Roles {
33 enum Roles {
37 RoleCategoryId,
34 RoleCategoryId,
38 RoleName,
35 RoleName,
39 RoleIcon,
36 RoleIcon,
37+ RoleRawRendererTemplate,
40 RoleRenderer,
38 RoleRenderer,
41− RoleContentType,
39+ RoleComponents,
42− RoleRendererHint,
40+ RoleProgressSource, // maybe
43− RoleHints,
44 RoleResults,
41 RoleResults,
45 RoleCount
42 RoleCount
46 };
43 };
47
44
48− Q_INVOKABLE void overrideResults(const QString& categoryId, QAbstractItemModel* model);
49−
50− QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
45+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
51−
52− QHash<int, QByteArray> roleNames() const;
46+ QHash<int, QByteArray> roleNames() const override;
53−
47+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
54− /* setters */
55− void setResultModel(DeeModel* model);
56−
57−private Q_SLOTS:
58− void onCountChanged();
59− void onRowCountChanged();
60− void onEmitCountChanged();
61− void onOverrideModelDestroyed();
62
48
63private:
49private:
64− DeeModel* getResultsForCategory(unsigned index) const;
50+ mutable QHash<int, ResultsModel*> m_resultsModels;
65− DeeListModel* getFilter(int index) const;
66−
67− DeeModel* m_dee_results;
68− QTimer m_timer;
69− QSet<DeeListModel*> m_timerFilters;
70 QHash<int, QByteArray> m_roles;
51 QHash<int, QByteArray> m_roles;
71− QMap<QString, QAbstractItemModel*> m_overriddenCategories;
52+ int m_category_count;
72− mutable QMap<int, DeeListModel*> m_filters;
73};
53};
74
54
75#endif // FAKE_CATEGORIES_H
55#endif // FAKE_CATEGORIES_H
tests/mocks/Unity/fake_preview.cppdeleted−73
@@ -1,73 +0,0 @@
1−/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "fake_preview.h"
18−
19−Preview::Preview(const QString &rendererName, QObject *parent):
20− QObject(parent),
21− m_rendererName(rendererName)
22−{
23−}
24−
25−QString Preview::rendererName() const
26−{
27− return m_rendererName;
28−}
29−
30−QString Preview::title() const
31−{
32− return "Title";
33−}
34−
35−QString Preview::subtitle() const
36−{
37− return "Subtitle";
38−}
39−
40−QString Preview::description() const
41−{
42− return "Description";
43−}
44−
45−QVariant Preview::actions()
46−{
47− return QVariant();
48−}
49−
50−QVariant Preview::infoHints()
51−{
52− return QVariant();
53−}
54−
55−QVariantMap Preview::infoHintsHash() const
56−{
57− return QVariantMap();
58−}
59−
60−QString Preview::image() const
61−{
62− return "";
63−}
64−
65−void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
66−{
67− Q_UNUSED(actionId);
68− Q_UNUSED(hints);
69−}
70−
71−void Preview::cancelAction()
72−{
73−}
tests/mocks/Unity/fake_preview.hdeleted−65
@@ -1,65 +0,0 @@
1−/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef FAKE_PREVIEW_H
18−#define FAKE_PREVIEW_H
19−
20−// Qt
21−#include <QObject>
22−#include <QString>
23−#include <QMetaType>
24−#include <QList>
25−#include <QVariantMap>
26−
27−class Q_DECL_EXPORT Preview : public QObject
28−{
29− Q_OBJECT
30−
31− Q_PROPERTY(QString rendererName READ rendererName NOTIFY previewChanged)
32− Q_PROPERTY(QString title READ title NOTIFY previewChanged)
33− Q_PROPERTY(QString subtitle READ subtitle NOTIFY previewChanged)
34− Q_PROPERTY(QString description READ description NOTIFY previewChanged)
35− Q_PROPERTY(QVariant actions READ actions NOTIFY previewChanged)
36− Q_PROPERTY(QVariant infoHints READ infoHints NOTIFY previewChanged)
37− Q_PROPERTY(QVariantMap infoMap READ infoHintsHash NOTIFY previewChanged)
38− Q_PROPERTY(QString image READ image NOTIFY previewChanged)
39−
40−public:
41− explicit Preview(const QString &rendererName, QObject *parent = 0);
42−
43− QString rendererName() const;
44− QString title() const;
45− QString subtitle() const;
46− QString description() const;
47− QVariant actions();
48− QVariant infoHints();
49− QVariantMap infoHintsHash() const;
50− QString image() const;
51−
52− Q_INVOKABLE void execute(const QString& actionId, const QHash<QString, QVariant>& hints);
53−
54− Q_INVOKABLE void cancelAction();
55−
56−Q_SIGNALS:
57− void previewChanged();
58−
59−private:
60− QString m_rendererName;
61−};
62−
63−Q_DECLARE_METATYPE(Preview *)
64−
65−#endif // FAKE_PREVIEW_H
tests/mocks/Unity/scopes-ng/fake_preview_model.cpp → tests/mocks/Unity/fake_preview_model.cpprenamed−5
@@ -24,9 +24,6 @@
24// Qt
24// Qt
25#include <QVariantMap>
25#include <QVariantMap>
26
26
27−namespace scopes_ng
28−{
29−
30struct PreviewData
27struct PreviewData
31{
28{
32 QString id;
29 QString id;
@@ -92,5 +89,3 @@ QVariant PreviewModel::data(const QModelIndex& index, int role) const
92 return QVariant();
89 return QVariant();
93 }
90 }
94}
91}
95−
96−} // namespace scopes_ng
tests/mocks/Unity/scopes-ng/fake_preview_model.h → tests/mocks/Unity/fake_preview_model.hrenamed+2−8
@@ -22,12 +22,9 @@
22#include <QSharedPointer>
22#include <QSharedPointer>
23#include <QVariantMap>
23#include <QVariantMap>
24
24
25−namespace scopes_ng
26−{
27−
28class PreviewData;
25class PreviewData;
29
26
30−class Q_DECL_EXPORT PreviewModel : public QAbstractListModel
27+class PreviewModel : public QAbstractListModel
31{
28{
32 Q_OBJECT
29 Q_OBJECT
33
30
@@ -60,9 +57,6 @@ private:
60
57
61};
58};
62
59
63−} // namespace scopes_ng
64−
65−
66−Q_DECLARE_METATYPE(scopes_ng::PreviewModel*)
60+Q_DECLARE_METATYPE(PreviewModel*)
67
61
68#endif // NG_FAKE_PREVIW_H
62#endif // NG_FAKE_PREVIW_H
tests/mocks/Unity/fake_scope.cpp+11−105
@@ -15,13 +15,8 @@
15 */
15 */
16
16
17#include "fake_scope.h"
17#include "fake_scope.h"
18−#include "fake_preview.h"
18+#include "fake_resultsmodel.h"
19−#include <paths.h>
19+#include "fake_preview_model.h"
20−
21−#include <dee.h>
22−
23−static DeeModel* create_categories_model(unsigned category_count);
24−static DeeModel* create_results_model(unsigned category_count, unsigned result_count);
25
20
26// TODO: Implement remaining pieces
21// TODO: Implement remaining pieces
27
22
@@ -36,20 +31,13 @@ Scope::Scope(QString const& id, QString const& name, bool visible, QObject* pare
36 , m_visible(visible)
31 , m_visible(visible)
37 , m_searching(false)
32 , m_searching(false)
38 , m_isActive(false)
33 , m_isActive(false)
39− , m_categories(new Categories(this))
40− , m_results(new DeeListModel(this))
41 , m_previewRendererName("preview-generic")
34 , m_previewRendererName("preview-generic")
35+ , m_categories(new Categories(20, this))
42{
36{
43− DeeModel* results_model = create_results_model(20, 300);
44− m_categories->setResultModel(results_model);
45− m_categories->setModel(create_categories_model(20));
46− m_results->setModel(results_model);
47−
48 m_timer.setInterval(1000);
37 m_timer.setInterval(1000);
49 m_timer.setSingleShot(true);
38 m_timer.setSingleShot(true);
50 connect(&m_timer, &QTimer::timeout, [this]() {
39 connect(&m_timer, &QTimer::timeout, [this]() {
51− Preview *p = new Preview(m_previewRendererName, this);
52− Q_EMIT previewReady(p);
40+ Q_EMIT previewReady(m_previewModel);
53 });
41 });
54}
42}
55
43
@@ -133,7 +121,7 @@ void Scope::setFormFactor(const QString &str) {
133void Scope::setActive(const bool active) {
121void Scope::setActive(const bool active) {
134 if (active != m_isActive) {
122 if (active != m_isActive) {
135 m_isActive = active;
123 m_isActive = active;
136− Q_EMIT isActiveChanged();
124+ Q_EMIT isActiveChanged(active);
137 }
125 }
138}
126}
139
127
@@ -151,102 +139,20 @@ void Scope::setNoResultsHint(const QString& str) {
151 }
139 }
152}
140}
153
141
154−void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
142+void Scope::activate(QVariant const& result)
155− const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
156− const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
157{
143{
158− Q_UNUSED(uri);
144+ Q_UNUSED(result);
159− Q_UNUSED(icon_hint);
160− Q_UNUSED(category);
161− Q_UNUSED(result_type);
162− Q_UNUSED(mimetype);
163− Q_UNUSED(title);
164− Q_UNUSED(comment);
165− Q_UNUSED(dnd_uri);
166− Q_UNUSED(metadata);
167
145
168 m_timer.start();
146 m_timer.start();
169}
147}
170
148
171−void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
149+PreviewModel* Scope::preview(QVariant const& result)
172− const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
173− const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
174{
150{
175− Q_UNUSED(uri);
151+ Q_UNUSED(result);
176− Q_UNUSED(icon_hint);
177− Q_UNUSED(category);
178− Q_UNUSED(result_type);
179− Q_UNUSED(mimetype);
180− Q_UNUSED(title);
181− Q_UNUSED(comment);
182− Q_UNUSED(dnd_uri);
183− Q_UNUSED(metadata);
184
152
185 m_timer.start();
153 m_timer.start();
186−}
154+ m_previewModel = new PreviewModel();
187−
155+ return m_previewModel;
188−static const gchar * categories_model_schema[] = {
189− "s", //ID
190− "s", // DISPLAY_NAME
191− "s", // ICON_HINT
192− "s", // RENDERER_NAME
193− "a{sv}" // HINTS
194−};
195−
196−
197−DeeModel* create_categories_model(unsigned category_count) {
198− DeeModel* category_model = dee_sequence_model_new();
199− dee_model_set_schema_full(category_model, categories_model_schema, G_N_ELEMENTS(categories_model_schema));
200− GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
201−
202− for(unsigned i = 0; i < category_count; ++i)
203− {
204− dee_model_append(category_model,
205− std::to_string(i).c_str(),
206− ("Category "+std::to_string(i)).c_str(),
207− "gtk-apply",
208− i % 2 == 0 ? "grid" : "carousel",
209− hints);
210− }
211− return category_model;
212−}
213−
214−
215−/* Schema that is used in the DeeModel representing
216− the results */
217−static const gchar * results_model_schema[] = {
218− "s", // URI
219− "s", // ICON_HINT
220− "u", // CATEGORY
221− "u", // RESULT_TYPE
222− "s", // MIMETYPE
223− "s", // TITLE
224− "s", // COMMENT
225− "s", // DND_URI
226− "a{sv}" // METADATA
227−};
228−
229−DeeModel* create_results_model(unsigned category_count, unsigned result_count) {
230− DeeModel* results_model = dee_sequence_model_new();
231− dee_model_set_schema_full(results_model, results_model_schema, G_N_ELEMENTS(results_model_schema));
232− GVariant* hints = g_variant_new_array(g_variant_type_element(G_VARIANT_TYPE_VARDICT), NULL, 0);
233−
234− for(unsigned i = 0; i < result_count; ++i)
235− {
236− unsigned category = i % category_count;
237−
238− dee_model_append(results_model,
239− ("uri://result."+std::to_string(i)).c_str(),
240− (qmlDirectory() + "graphics/applicationIcons/dash.png").toLatin1().data(),
241− category,
242− 0,
243− "application/x-desktop",
244− ("Title."+std::to_string(i)).c_str(),
245− ("Comment."+std::to_string(i)).c_str(),
246− ("uri://result."+std::to_string(i)).c_str(),
247− hints);
248− }
249− return results_model;
250}
156}
251
157
252void Scope::cancelActivation()
158void Scope::cancelActivation()
tests/mocks/Unity/fake_scope.h+15−16
@@ -18,9 +18,10 @@
18#define FAKE_SCOPE_H
18#define FAKE_SCOPE_H
19
19
20#include "fake_categories.h"
20#include "fake_categories.h"
21+#include "fake_preview_model.h"
21
22
22#include <QObject>
23#include <QObject>
23−#include <QDebug>
24+#include <QTimer>
24
25
25class Preview;
26class Preview;
26
27
@@ -33,12 +34,12 @@ class Scope : public QObject
33 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
34 Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
34 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
35 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
35 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
36 Q_PROPERTY(QString searchHint READ searchHint NOTIFY searchHintChanged)
37+ Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
36 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
38 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
37 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
39 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
38− Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
39 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
40 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
41+ //Q_PROPERTY(Filters* filters READ filters NOTIFY filtersChanged)
40
42
41− Q_PROPERTY(bool searchInProgress READ searchInProgress WRITE setSearchInProgress NOTIFY searchInProgressChanged)
42 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
43 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
43 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
44 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
44 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
45 Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
@@ -72,17 +73,12 @@ public:
72 void setActive(const bool);
73 void setActive(const bool);
73 void setSearchInProgress(const bool inProg);
74 void setSearchInProgress(const bool inProg);
74
75
75− Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
76+ Q_INVOKABLE void activate(QVariant const& result);
76− const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
77− const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
78− Q_INVOKABLE void preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
77+ Q_INVOKABLE PreviewModel* preview(QVariant const& result);
79− const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
80− const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
81−
82 Q_INVOKABLE void cancelActivation();
78 Q_INVOKABLE void cancelActivation();
83
79
84Q_SIGNALS:
80Q_SIGNALS:
85− void idChanged(const QString&);
81+ void idChanged();
86 void nameChanged(const QString&);
82 void nameChanged(const QString&);
87 void iconHintChanged(const QString&);
83 void iconHintChanged(const QString&);
88 void descriptionChanged(const QString&);
84 void descriptionChanged(const QString&);
@@ -90,18 +86,21 @@ Q_SIGNALS:
90 void searchInProgressChanged();
86 void searchInProgressChanged();
91 void visibleChanged(bool);
87 void visibleChanged(bool);
92 void shortcutChanged(const QString&);
88 void shortcutChanged(const QString&);
93− void connectedChanged(bool);
94 void categoriesChanged();
89 void categoriesChanged();
90+ //void filtersChanged();
95 void searchQueryChanged();
91 void searchQueryChanged();
96 void noResultsHintChanged();
92 void noResultsHintChanged();
97 void formFactorChanged();
93 void formFactorChanged();
98− void isActiveChanged();
94+ void isActiveChanged(bool);
99
95
100 // signals triggered by activate(..) or preview(..) requests.
96 // signals triggered by activate(..) or preview(..) requests.
101− void previewReady(Preview *preview);
97+ void previewReady(PreviewModel* preview);
102− void activateApplication(const QString &desktop);
103 void showDash();
98 void showDash();
104 void hideDash();
99 void hideDash();
100+ void gotoUri(const QString &uri);
101+ void activated();
102+
103+ void activateApplication(const QString &desktop);
105
104
106protected:
105protected:
107
106
@@ -119,9 +118,9 @@ protected:
119 QString m_previewRendererName;
118 QString m_previewRendererName;
120
119
121 Categories* m_categories;
120 Categories* m_categories;
122− DeeListModel* m_results;
123
121
124 QTimer m_timer;
122 QTimer m_timer;
123+ PreviewModel *m_previewModel;
125};
124};
126
125
127#endif // FAKE_SCOPE_H
126#endif // FAKE_SCOPE_H
tests/mocks/Unity/fake_scopes.cpp−4
@@ -19,9 +19,6 @@
19// Self
19// Self
20#include "fake_scopes.h"
20#include "fake_scopes.h"
21
21
22−// Local
23−#include "fake_applications_scope.h"
24−
25// TODO: Implement remaining pieces, like Categories (i.e. LensView now gives warnings)
22// TODO: Implement remaining pieces, like Categories (i.e. LensView now gives warnings)
26
23
27// Qt
24// Qt
@@ -57,7 +54,6 @@ void Scopes::updateScopes()
57 addScope(new Scope("MockScope1", "People", true, this));
54 addScope(new Scope("MockScope1", "People", true, this));
58 addScope(new Scope("MockScope2", "Music", false, this));
55 addScope(new Scope("MockScope2", "Music", false, this));
59 addScope(new Scope("home.scope", "Home", true, this));
56 addScope(new Scope("home.scope", "Home", true, this));
60− addScope(new ApplicationsScope(true, this));
61 addScope(new Scope("MockScope5", "Videos", true, this));
57 addScope(new Scope("MockScope5", "Videos", true, this));
62
58
63 if (!m_loaded) {
59 if (!m_loaded) {
tests/mocks/Unity/fake_unity_plugin.cpp+5−18
@@ -22,11 +22,8 @@
22// local
22// local
23#include "fake_scopes.h"
23#include "fake_scopes.h"
24#include "fake_categories.h"
24#include "fake_categories.h"
25−#include "fake_preview.h"
26−#include "categoryresults.h"
27−
28−// scopes-ng
29−#include "scopes-ng/fake_preview_model.h"
25+#include "fake_preview_model.h"
26+#include "fake_resultsmodel.h"
30
27
31// External
28// External
32#include <glib-object.h>
29#include <glib-object.h>
@@ -41,19 +38,9 @@ void FakeUnityPlugin::registerTypes(const char *uri)
41
38
42 Q_ASSERT(uri == QLatin1String("Unity"));
39 Q_ASSERT(uri == QLatin1String("Unity"));
43
40
44− qmlRegisterUncreatableType<Preview>(uri, 0, 1, "Preview", "Can't create Preview object in QML.");
45− qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
46− qmlRegisterType<Scope>(uri, 0, 1, "Scope");
47− qmlRegisterType<Categories>(uri, 0, 1, "Categories");
48− qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create");
49− qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
50−
51− // same for version 0.2
52− qmlRegisterUncreatableType<Preview>(uri, 0, 2, "Preview", "Can't create Preview object in QML.");
53 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
41 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
54 qmlRegisterType<Scope>(uri, 0, 2, "Scope");
42 qmlRegisterType<Scope>(uri, 0, 2, "Scope");
55− qmlRegisterType<Categories>(uri, 0, 2, "Categories");
43+ qmlRegisterUncreatableType<Categories>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
56− qmlRegisterUncreatableType<CategoryResults>(uri, 0, 2, "CategoryResults", "Can't create");
44+ qmlRegisterUncreatableType<ResultsModel>(uri, 0, 2, "ResultsModel", "Can't create ResultsModel object in QML.");
57− qmlRegisterType<DeeListModel>(uri, 0, 2, "DeeListModel");
58− qmlRegisterType<scopes_ng::PreviewModel>(uri, 0, 2, "FakePreviewModel");
45+ qmlRegisterType<PreviewModel>(uri, 0, 2, "FakePreviewModel");
59}
46}
tests/qmltests/Components/tst_PageHeaderLabel.qml+1−1
@@ -19,7 +19,7 @@ import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Components"
20import "../../../qml/Components"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22−import Unity 0.1
22+import Unity 0.2
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
25Item {
25Item {
tests/qmltests/Dash/Previews/tst_Preview.qml+14−6
@@ -87,21 +87,29 @@ Rectangle {
87
87
88 function test_containOnFocus() {
88 function test_containOnFocus() {
89 waitForRendering(preview);
89 waitForRendering(preview);
90+ tryCompareFunction(function () { return findChild(preview, "widget-9") != null }, true);
90− var widget = findChild(preview, "widget-13");
91+ var widget = findChild(preview, "widget-9");
91−
92− widget.forceActiveFocus();
93
92
94 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
93 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
94+ verify(bottomLeft.y > preview.height);
95
95
96+ widget.forceActiveFocus();
97+
98+ tryCompareFunction(function () {
99+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
96− tryCompareFunction(function () { return bottomLeft.y <= preview.height }, true);
100+ return bottomLeft.y <= preview.height
101+ }, true);
97 }
102 }
98
103
99 function test_containOnGrow() {
104 function test_containOnGrow() {
100 waitForRendering(preview);
105 waitForRendering(preview);
106+ tryCompareFunction(function () { return findChild(preview, "widget-13") != null }, true);
101 var widget = findChild(preview, "widget-13");
107 var widget = findChild(preview, "widget-13");
102
108
103− widget.forceActiveFocus();
109+ var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
104− widget.height += 200;
110+ verify(bottomLeft.y > preview.height);
111+
112+ root.height += units.gu(50);
105
113
106 tryCompareFunction(function () {
114 tryCompareFunction(function () {
107 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
115 var bottomLeft = preview.mapFromItem(widget, 0, widget.height);
tests/qmltests/Dash/qml/FakeScopeView.qml+1−1
@@ -15,7 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18−import Unity 0.1
18+import Unity 0.2
19
19
20import "../../../../qml/Dash"
20import "../../../../qml/Dash"
21
21
tests/qmltests/Dash/tst_DashContent.qml+9−17
@@ -19,7 +19,7 @@ import QtTest 1.0
19import "../../../qml/Dash"
19import "../../../qml/Dash"
20import "../../../qml/Components"
20import "../../../qml/Components"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22−import Unity 0.1
22+import Unity 0.2
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24import Utils 0.1
24import Utils 0.1
25
25
@@ -44,7 +44,6 @@ Item {
44 'MockScope1': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
44 'MockScope1': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
45 'MockScope2': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
45 'MockScope2': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
46 'home.scope': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
46 'home.scope': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
47− 'applications.scope': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
48 'MockScope5': { 'movementStarted': 0, 'positionedAtBeginning': 0 }
47 'MockScope5': { 'movementStarted': 0, 'positionedAtBeginning': 0 }
49 }
48 }
50
49
@@ -71,7 +70,6 @@ Item {
71 "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
70 "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
72 "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
71 "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
73 "home.scope": Qt.resolvedUrl("qml/fake_scopeView3.qml"),
72 "home.scope": Qt.resolvedUrl("qml/fake_scopeView3.qml"),
74− "applications.scope": Qt.resolvedUrl("qml/fake_scopeView4.qml")
75 }
73 }
76 genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
74 genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
77 }
75 }
@@ -86,9 +84,6 @@ Item {
86 scopeStatus["home.scope"].movementStarted = 0;
84 scopeStatus["home.scope"].movementStarted = 0;
87 scopeStatus["home.scope"].positionedAtBeginning = 0;
85 scopeStatus["home.scope"].positionedAtBeginning = 0;
88
86
89− scopeStatus["applications.scope"].movementStarted = 0;
90− scopeStatus["applications.scope"].positionedAtBeginning = 0;
91−
92 scopeStatus["MockScope5"].movementStarted = 0;
87 scopeStatus["MockScope5"].movementStarted = 0;
93 scopeStatus["MockScope5"].positionedAtBeginning = 0;
88 scopeStatus["MockScope5"].positionedAtBeginning = 0;
94 }
89 }
@@ -143,7 +138,7 @@ Item {
143 compare(dashContentList.count, 0, "DashContent should have 0 items when it starts");
138 compare(dashContentList.count, 0, "DashContent should have 0 items when it starts");
144 compare(dashContentList.currentIndex, -1, "DashContent's currentIndex should be -1 while there have been no items in the model");
139 compare(dashContentList.currentIndex, -1, "DashContent's currentIndex should be -1 while there have been no items in the model");
145
140
146− tryCompare(scopeLoadedSpy, "count", 5);
141+ tryCompare(scopeLoadedSpy, "count", 4);
147
142
148 verify(dashContentList.currentIndex >= 0);
143 verify(dashContentList.currentIndex >= 0);
149 }
144 }
@@ -156,7 +151,7 @@ Item {
156 // pretend we're running after a model reset
151 // pretend we're running after a model reset
157 dashContentList.currentIndex = 27;
152 dashContentList.currentIndex = 27;
158
153
159− tryCompare(scopeLoadedSpy, "count", 5);
154+ tryCompare(scopeLoadedSpy, "count", 4);
160
155
161 verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
156 verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
162 }
157 }
@@ -167,7 +162,7 @@ Item {
167 var dashContentList = findChild(dashContent, "dashContentList");
162 var dashContentList = findChild(dashContent, "dashContentList");
168 verify(dashContentList != undefined)
163 verify(dashContentList != undefined)
169
164
170− tryCompare(scopeLoadedSpy, "count", 5);
165+ tryCompare(scopeLoadedSpy, "count", 4);
171
166
172 dashContentList.movementStarted();
167 dashContentList.movementStarted();
173
168
@@ -175,32 +170,30 @@ Item {
175 compare(scopeStatus["MockScope1"].movementStarted, 1, "MockScope1 should have emitted movementStarted signal when content list did.");
170 compare(scopeStatus["MockScope1"].movementStarted, 1, "MockScope1 should have emitted movementStarted signal when content list did.");
176 compare(scopeStatus["MockScope2"].movementStarted, 1, "MockScope2 should have emitted movementStarted signal when content list did.");
171 compare(scopeStatus["MockScope2"].movementStarted, 1, "MockScope2 should have emitted movementStarted signal when content list did.");
177 compare(scopeStatus["home.scope"].movementStarted, 1, "home.scope should have emitted movementStarted signal when content list did.");
172 compare(scopeStatus["home.scope"].movementStarted, 1, "home.scope should have emitted movementStarted signal when content list did.");
178− compare(scopeStatus["applications.scope"].movementStarted, 1, "applications.scope should have emitted movementStarted signal when content list did.");
179 compare(scopeStatus["MockScope5"].movementStarted, 1, "MockScope5 should have emitted movementStarted signal when content list did.");
173 compare(scopeStatus["MockScope5"].movementStarted, 1, "MockScope5 should have emitted movementStarted signal when content list did.");
180 }
174 }
181
175
182 function test_positioned_at_beginning_signal() {
176 function test_positioned_at_beginning_signal() {
183 dashContent.setCurrentScopeAtIndex(3, true, false);
177 dashContent.setCurrentScopeAtIndex(3, true, false);
184
178
185− tryCompare(scopeLoadedSpy, "count", 5);
179+ tryCompare(scopeLoadedSpy, "count", 4);
186
180
187 dashContent.positionedAtBeginning();
181 dashContent.positionedAtBeginning();
188 compare(scopeStatus["MockScope1"].positionedAtBeginning, 1, "MockScope1 should have emitted positionedAtBeginning signal when DashContent did.");
182 compare(scopeStatus["MockScope1"].positionedAtBeginning, 1, "MockScope1 should have emitted positionedAtBeginning signal when DashContent did.");
189 compare(scopeStatus["MockScope2"].positionedAtBeginning, 1, "MockScope2 should have emitted positionedAtBeginning signal when DashContent did.");
183 compare(scopeStatus["MockScope2"].positionedAtBeginning, 1, "MockScope2 should have emitted positionedAtBeginning signal when DashContent did.");
190 compare(scopeStatus["home.scope"].positionedAtBeginning, 1, "home.scope should have emitted positionedAtBeginning signal when DashContent did.");
184 compare(scopeStatus["home.scope"].positionedAtBeginning, 1, "home.scope should have emitted positionedAtBeginning signal when DashContent did.");
191− compare(scopeStatus["applications.scope"].positionedAtBeginning, 1, "applications.scope should have emitted positionedAtBeginning signal when DashContent did.");
192 compare(scopeStatus["MockScope5"].positionedAtBeginning, 1, "MockScope5 should have emitted positionedAtBeginning signal when DashContent did.");
185 compare(scopeStatus["MockScope5"].positionedAtBeginning, 1, "MockScope5 should have emitted positionedAtBeginning signal when DashContent did.");
193 }
186 }
194
187
195 function test_scope_loaded() {
188 function test_scope_loaded() {
196− tryCompare(scopeLoadedSpy, "count", 5);
189+ tryCompare(scopeLoadedSpy, "count", 4);
197 }
190 }
198
191
199 function test_content_end_reached() {
192 function test_content_end_reached() {
200 var dashContentList = findChild(dashContent, "dashContentList");
193 var dashContentList = findChild(dashContent, "dashContentList");
201 verify(dashContentList != undefined);
194 verify(dashContentList != undefined);
202
195
203− tryCompare(scopeLoadedSpy, "count", 5);
196+ tryCompare(scopeLoadedSpy, "count", 4);
204 dashContent.setCurrentScopeAtIndex(0, true, false);
197 dashContent.setCurrentScopeAtIndex(0, true, false);
205 dashContentList.currentItem.item.endReached();
198 dashContentList.currentItem.item.endReached();
206
199
@@ -242,8 +235,7 @@ Item {
242 {tag: "index0", index: 0, objectName: "fake_scopeView1"},
235 {tag: "index0", index: 0, objectName: "fake_scopeView1"},
243 {tag: "index1", index: 1, objectName: "fake_scopeView2"},
236 {tag: "index1", index: 1, objectName: "fake_scopeView2"},
244 {tag: "index2", index: 2, objectName: "fake_scopeView3"},
237 {tag: "index2", index: 2, objectName: "fake_scopeView3"},
245− {tag: "index3", index: 3, objectName: "fake_scopeView4"},
238+ {tag: "index3", index: 3, objectName: "fake_generic_scopeView"}
246− {tag: "index4", index: 4, objectName: "fake_generic_scopeView"}
247 ]
239 ]
248 }
240 }
249
241
@@ -263,7 +255,7 @@ Item {
263 function test_is_active(data) {
255 function test_is_active(data) {
264 var dashContentList = findChild(dashContent, "dashContentList");
256 var dashContentList = findChild(dashContent, "dashContentList");
265
257
266− tryCompare(scopeLoadedSpy, "count", 5);
258+ tryCompare(scopeLoadedSpy, "count", 4);
267
259
268 dashContent.setCurrentScopeAtIndex(data.select, true, false);
260 dashContent.setCurrentScopeAtIndex(data.select, true, false);
269 dashContent.visible = data.visible;
261 dashContent.visible = data.visible;
tests/qmltests/Dash/tst_GenericScopeView.qml+12−79
@@ -16,7 +16,7 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19−import Unity 0.1
19+import Unity 0.2
20import ".."
20import ".."
21import "../../../qml/Dash"
21import "../../../qml/Dash"
22import "../../../qml/Components"
22import "../../../qml/Components"
@@ -26,7 +26,7 @@ import Unity.Test 0.1 as UT
26Item {
26Item {
27 id: shell
27 id: shell
28 width: units.gu(120)
28 width: units.gu(120)
29− height: units.gu(80)
29+ height: units.gu(100)
30
30
31 Scopes {
31 Scopes {
32 id: scopes
32 id: scopes
@@ -41,14 +41,6 @@ Item {
41 signal mainStageFocusedApplicationChanged()
41 signal mainStageFocusedApplicationChanged()
42 }
42 }
43
43
44− PreviewListView {
45− id: previewListView
46− anchors.fill: parent
47− openEffect: openEffect
48− categoryView: genericScopeView.categoryView
49− scope: genericScopeView.scope
50− }
51−
52 DashContentOpenEffect {
44 DashContentOpenEffect {
53 id: openEffect
45 id: openEffect
54 previewListView: previewListView
46 previewListView: previewListView
@@ -158,20 +150,6 @@ Item {
158 openPreview();
150 openPreview();
159
151
160 // check for it opening successfully
152 // check for it opening successfully
161− var currentPreviewItem = findChild(previewListView, "previewLoader0");
162− tryCompareFunction(function() {
163− var parts = currentPreviewItem.source.toString().split("/");
164− var name = parts[parts.length - 1];
165− return name == "DashPreviewPlaceholder.qml";
166− },
167− true);
168− tryCompareFunction(function() {
169− var parts = currentPreviewItem.source.toString().split("/");
170− var name = parts[parts.length - 1];
171− return name == "GenericPreview.qml";
172− },
173− true);
174− tryCompare(currentPreviewItem, "progress", 1);
175 tryCompare(previewListView, "open", true);
153 tryCompare(previewListView, "open", true);
176
154
177 closePreview();
155 closePreview();
@@ -197,21 +175,9 @@ Item {
197
175
198 openPreview();
176 openPreview();
199
177
200− // wait for it to be loaded
201− var currentPreviewItem = findChild(previewListView, "previewLoader0");
202− tryCompareFunction(function() {
203− var parts = currentPreviewItem.source.toString().split("/");
204− var name = parts[parts.length - 1];
205− return name == "GenericPreview.qml";
206− },
207− true);
208− tryCompare(currentPreviewItem, "progress", 1);
209− waitForRendering(currentPreviewItem);
210−
211 checkArrowPosition(0);
178 checkArrowPosition(0);
212
179
213 // flick to the next previews
180 // flick to the next previews
214−
215 for (var i = 1; i < previewListView.count; ++i) {
181 for (var i = 1; i < previewListView.count; ++i) {
216
182
217 mouseFlick(previewListView, previewListView.width - units.gu(1),
183 mouseFlick(previewListView, previewListView.width - units.gu(1),
@@ -219,18 +185,6 @@ Item {
219 units.gu(2),
185 units.gu(2),
220 previewListView.height / 2);
186 previewListView.height / 2);
221
187
222− // wait for it to be loaded
223− var nextPreviewItem = findChild(previewListView, "previewLoader" + i);
224− tryCompareFunction(function() {
225− var parts = nextPreviewItem.source.toString().split("/");
226− var name = parts[parts.length - 1];
227− return name == "GenericPreview.qml";
228− },
229− true);
230− tryCompare(nextPreviewItem, "progress", 1);
231− waitForRendering(nextPreviewItem);
232− tryCompareFunction(function() {return nextPreviewItem.item !== null}, true);
233−
234 checkArrowPosition(i);
188 checkArrowPosition(i);
235
189
236 // Make sure only the new one has isCurrent set to true
190 // Make sure only the new one has isCurrent set to true
@@ -245,21 +199,6 @@ Item {
245 closePreview();
199 closePreview();
246 }
200 }
247
201
248− function test_show_spinner() {
249− openPreview();
250− var previewLoader = findChild(previewListView, "previewLoader0");
251− tryCompare(previewLoader, "progress", 1.0);
252− tryCompareFunction(function() { return previewLoader.item != undefined; }, true);
253−
254− previewLoader.item.showProcessingAction = true;
255− var waitingForAction = findChild(previewListView, "waitingForActionMouseArea");
256− tryCompare(waitingForAction, "enabled", true);
257− previewLoader.closePreviewSpinner();
258− tryCompare(waitingForAction, "enabled", false);
259−
260− closePreview();
261− }
262−
263 function test_changeScope() {
202 function test_changeScope() {
264 genericScopeView.scope.searchQuery = "test"
203 genericScopeView.scope.searchQuery = "test"
265 genericScopeView.scope = scopes.get(1)
204 genericScopeView.scope = scopes.get(1)
@@ -306,26 +245,12 @@ Item {
306 }
245 }
307
246
308 function test_showPreviewCarousel() {
247 function test_showPreviewCarousel() {
309− tryCompareFunction(function() { return findChild(genericScopeView, "carouselDelegate") != undefined; }, true);
248+ tryCompareFunction(function() { return findChild(genericScopeView, "carouselDelegate1") != undefined; }, true);
310− var tile = findChild(genericScopeView, "carouselDelegate");
249+ var tile = findChild(genericScopeView, "carouselDelegate1");
311 mouseClick(tile, tile.width / 2, tile.height / 2);
250 mouseClick(tile, tile.width / 2, tile.height / 2);
312 tryCompare(openEffect, "gap", 1);
251 tryCompare(openEffect, "gap", 1);
313
252
314 // check for it opening successfully
253 // check for it opening successfully
315− var currentPreviewItem = findChild(previewListView, "previewLoader0");
316− tryCompareFunction(function() {
317− var parts = currentPreviewItem.source.toString().split("/");
318− var name = parts[parts.length - 1];
319− return name == "DashPreviewPlaceholder.qml";
320− },
321− true);
322− tryCompareFunction(function() {
323− var parts = currentPreviewItem.source.toString().split("/");
324− var name = parts[parts.length - 1];
325− return name == "GenericPreview.qml";
326− },
327− true);
328− tryCompare(currentPreviewItem, "progress", 1);
329 tryCompare(previewListView, "open", true);
254 tryCompare(previewListView, "open", true);
330
255
331 closePreview();
256 closePreview();
@@ -386,4 +311,12 @@ Item {
386 }
311 }
387 }
312 }
388 }
313 }
314+
315+ PreviewListView {
316+ id: previewListView
317+ anchors.fill: parent
318+ openEffect: openEffect
319+ categoryView: genericScopeView.categoryView
320+ scope: genericScopeView.scope
321+ }
389}
322}