on xenial help sign in
Implement CategoryResults based on DeeFilterModel
0a01feeMichal Hruby
Dash/GenericScopeView.qml+2−2
@@ -72,10 +72,10 @@ ScopeView {
72 delegate: Tile {
72 delegate: Tile {
73 width: filtergrid.cellWidth
73 width: filtergrid.cellWidth
74 height: filtergrid.cellHeight
74 height: filtergrid.cellHeight
75− text: column_5 ? column_5 : "" // FIXME: this shouldn't be necessary
75+ text: title ? title : "" // FIXME: this shouldn't be necessary
76 imageWidth: units.gu(11)
76 imageWidth: units.gu(11)
77 imageHeight: units.gu(16)
77 imageHeight: units.gu(16)
78− source: column_1 ? IconUtil.from_gicon(column_1) : "" // FIXME: ditto
78+ source: icon ? IconUtil.from_gicon(icon) : "" // FIXME: ditto
79 }
79 }
80 }
80 }
81 }
81 }
plugins/Unity/CMakeLists.txt+1−2
@@ -12,11 +12,10 @@ include_directories(
12)
12)
13
13
14set(QMLPLUGIN_SRC
14set(QMLPLUGIN_SRC
15− ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
16 scope.cpp
15 scope.cpp
17 scopes.cpp
16 scopes.cpp
18 categories.cpp
17 categories.cpp
19− categoryfilter.cpp
18+ categoryresults.cpp
20 plugin.cpp
19 plugin.cpp
21 bottombarvisibilitycommunicatorshell.cpp
20 bottombarvisibilitycommunicatorshell.cpp
22 launchermodel.cpp
21 launchermodel.cpp
plugins/Unity/categories.cpp+39−27
@@ -19,11 +19,10 @@
19
19
20// self
20// self
21#include "categories.h"
21#include "categories.h"
22−#include "categoryfilter.h"
22+#include "categoryresults.h"
23
23
24Categories::Categories(QObject* parent)
24Categories::Categories(QObject* parent)
25 : DeeListModel(parent)
25 : DeeListModel(parent)
26− , m_resultModel(0)
27{
26{
28 // FIXME: need to clean up unused filters on countChanged
27 // FIXME: need to clean up unused filters on countChanged
29 m_roles[Categories::RoleId] = "id";
28 m_roles[Categories::RoleId] = "id";
@@ -45,42 +44,57 @@ Categories::Categories(QObject* parent)
45
44
46Categories::~Categories()
45Categories::~Categories()
47{
46{
48− qDeleteAll(m_filters);
49}
47}
50
48
51−CategoryFilter*
49+DeeListModel*
52Categories::getFilter(int index) const
50Categories::getFilter(int index) const
53{
51{
54 if (!m_filters.contains(index)) {
52 if (!m_filters.contains(index)) {
55− CategoryFilter* filter = new CategoryFilter();
53+ auto results = std::make_shared<CategoryResults> ();
54+ results->setCategoryIndex(index);
56− connect(filter, SIGNAL(countChanged()), this, SLOT(onCountChanged()));
55+ connect(results.get(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
57− filter->setModel(m_resultModel);
58− filter->setIndex(index);
59
56
57+ unsigned cat_index = static_cast<unsigned>(index);
58+ auto unity_results = m_unityScope->GetResultsForCategory(cat_index);
59+ results->setModel(unity_results->model());
60+
60− m_filters.insert(index, filter);
61+ m_filters.insert(index, results);
61 }
62 }
62
63
63− return m_filters[index];
64+ return m_filters[index].get();
65+}
66+
67+void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
68+{
69+ m_timerFilters.clear();
70+ m_filters.clear();
71+
72+ setModel(model);
64}
73}
65
74
66void
75void
67−Categories::setResultModel(DeeListModel* model)
76+Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
68{
77{
69− if (model != m_resultModel) {
78+ m_unityScope = scope;
70− m_resultModel = model;
71
79
80+ // no need to call this, we'll get notified
81+ //setModel(m_unityScope->categories()->model());
82+
83+ m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
84+
85+ /*
86+ if (model != m_resultModel) {
72 Q_FOREACH(CategoryFilter* filter, m_filters) {
87 Q_FOREACH(CategoryFilter* filter, m_filters) {
73 filter->setModel(m_resultModel);
88 filter->setModel(m_resultModel);
74 }
89 }
75−
76− Q_EMIT resultModelChanged(m_resultModel);
77 }
90 }
91+ */
78}
92}
79
93
80void
94void
81Categories::onCountChanged()
95Categories::onCountChanged()
82{
96{
83− CategoryFilter* filter = qobject_cast<CategoryFilter*>(sender());
97+ DeeListModel* filter = qobject_cast<DeeListModel*>(sender());
84 if (filter) {
98 if (filter) {
85 m_timerFilters << filter;
99 m_timerFilters << filter;
86 m_timer.start();
100 m_timer.start();
@@ -92,8 +106,9 @@ Categories::onEmitCountChanged()
92{
106{
93 QVector<int> roles;
107 QVector<int> roles;
94 roles.append(Categories::RoleCount);
108 roles.append(Categories::RoleCount);
95− Q_FOREACH(CategoryFilter* filter, m_timerFilters) {
109+ Q_FOREACH(DeeListModel* results, m_timerFilters) {
110+ auto cat_results = qobject_cast<CategoryResults*>(results);
96− QModelIndex changedIndex = index(filter->index());
111+ QModelIndex changedIndex = index(cat_results->categoryIndex());
97 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
112 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
98 }
113 }
99 m_timerFilters.clear();
114 m_timerFilters.clear();
@@ -116,25 +131,22 @@ Categories::data(const QModelIndex& index, int role) const
116 case RoleId:
131 case RoleId:
117 return QVariant::fromValue(index.row());
132 return QVariant::fromValue(index.row());
118 case RoleName:
133 case RoleName:
119− return QVariant::fromValue(DeeListModel::data(index, 1)); //DISPLAY_NAME
134+ return DeeListModel::data(index, 1); //DISPLAY_NAME
120 case RoleIcon:
135 case RoleIcon:
121− return QVariant::fromValue(DeeListModel::data(index, 2)); //ICON_HINT
136+ return DeeListModel::data(index, 2); //ICON_HINT
122 case RoleRenderer:
137 case RoleRenderer:
123− return QVariant::fromValue(DeeListModel::data(index, 3)); //RENDERER_NAME
138+ return DeeListModel::data(index, 3); //RENDERER_NAME
124 case RoleContentType:
139 case RoleContentType:
125 {
140 {
126− auto hints = QVariant::fromValue(DeeListModel::data(index, 4)).toHash();
141+ auto hints = DeeListModel::data(index, 4).toHash();
127 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
142 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
128 }
143 }
129 case RoleHints:
144 case RoleHints:
130− return QVariant::fromValue(DeeListModel::data(index, 4)); //HINTS
145+ return DeeListModel::data(index, 4); //HINTS
131 case RoleResults:
146 case RoleResults:
132 return QVariant::fromValue(getFilter(index.row()));
147 return QVariant::fromValue(getFilter(index.row()));
133 case RoleCount:
148 case RoleCount:
134− {
135− CategoryFilter* filter = getFilter(index.row());
149+ return QVariant::fromValue(getFilter(index.row())->rowCount());
136− return QVariant::fromValue(filter->rowCount());
137− }
138 default:
150 default:
139 return QVariant();
151 return QVariant();
140 }
152 }
plugins/Unity/categories.h+10−15
@@ -21,22 +21,21 @@
21#ifndef CATEGORIES_H
21#ifndef CATEGORIES_H
22#define CATEGORIES_H
22#define CATEGORIES_H
23
23
24+// unity-core
25+#include <UnityCore/Scope.h>
26+
24// dee-qt
27// dee-qt
25#include "deelistmodel.h"
28#include "deelistmodel.h"
26
29
27#include <QSet>
30#include <QSet>
28#include <QTimer>
31#include <QTimer>
29
32
30−class CategoryFilter;
31−
32class Categories : public DeeListModel
33class Categories : public DeeListModel
33{
34{
34 Q_OBJECT
35 Q_OBJECT
35
36
36 Q_ENUMS(Roles)
37 Q_ENUMS(Roles)
37
38
38− Q_PROPERTY(DeeListModel* resultModel READ resultModel WRITE setResultModel NOTIFY resultModelChanged)
39−
40public:
39public:
41 explicit Categories(QObject* parent = 0);
40 explicit Categories(QObject* parent = 0);
42 ~Categories();
41 ~Categories();
@@ -56,27 +55,23 @@ public:
56
55
57 QHash<int, QByteArray> roleNames() const;
56 QHash<int, QByteArray> roleNames() const;
58
57
59− /* getters */
60− DeeListModel* resultModel() { return m_resultModel; }
61−
62 /* setters */
58 /* setters */
63− void setResultModel(DeeListModel*);
59+ void setUnityScope(const unity::dash::Scope::Ptr& scope);
64−
65−Q_SIGNALS:
66− void resultModelChanged(DeeListModel*);
67
60
68private Q_SLOTS:
61private Q_SLOTS:
69 void onCountChanged();
62 void onCountChanged();
70 void onEmitCountChanged();
63 void onEmitCountChanged();
71
64
72private:
65private:
66+ void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
67+
73− CategoryFilter* getFilter(int index) const;
68+ DeeListModel* getFilter(int index) const;
74
69
70+ unity::dash::Scope::Ptr m_unityScope;
75 QTimer m_timer;
71 QTimer m_timer;
76− QSet<CategoryFilter*> m_timerFilters;
72+ QSet<DeeListModel*> m_timerFilters;
77 QHash<int, QByteArray> m_roles;
73 QHash<int, QByteArray> m_roles;
78− DeeListModel* m_resultModel;
79− mutable QMap<int, CategoryFilter*> m_filters;
74+ mutable QMap<int, std::shared_ptr<DeeListModel>> m_filters;
80};
75};
81
76
82#endif // CATEGORIES_H
77#endif // CATEGORIES_H
plugins/Unity/categoryfilter.cppdeleted−45
@@ -1,45 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * Authors:
5− * Michał Sawicz <michal.sawicz@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−#include "categoryfilter.h"
21−
22−int const CATEGORY_COLUMN = 2;
23−
24−CategoryFilter::CategoryFilter(QObject* parent)
25− : QSortFilterProxyModelQML(parent)
26− , m_index(-1)
27−{
28− setDynamicSortFilter(true);
29− setFilterRole(CATEGORY_COLUMN);
30− setFilterRegExp(QString("^%1$").arg(m_index));
31−}
32−
33−int CategoryFilter::index() const
34−{
35− return m_index;
36−}
37−
38−void CategoryFilter::setIndex(int index)
39−{
40− if (index != m_index) {
41− m_index = index;
42− setFilterRegExp(QString("^%1$").arg(m_index));
43− Q_EMIT indexChanged(m_index);
44− }
45−}
plugins/Unity/categoryfilter.hdeleted−48
@@ -1,48 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * Authors:
5− * Michał Sawicz <michal.sawicz@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−#ifndef CATEGORY_FILTER_H
21−#define CATEGORY_FILTER_H
22−
23−// Utils
24−#include "plugins/Utils/qsortfilterproxymodelqml.h"
25−
26−class CategoryFilter : public QSortFilterProxyModelQML
27−{
28− Q_OBJECT
29−
30− Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
31−
32−public:
33− explicit CategoryFilter(QObject* parent = 0);
34−
35− /* getters */
36− int index() const;
37−
38− /* setters */
39− void setIndex(int index);
40−
41−Q_SIGNALS:
42− void indexChanged(int index);
43−
44−private:
45− int m_index;
46−};
47−
48−#endif // CATEGORY_FILTER_H
plugins/Unity/categoryresults.cppnew file+81
@@ -0,0 +1,81 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Michał Sawicz <michal.sawicz@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+
23+CategoryResults::CategoryResults(QObject* parent)
24+ : DeeListModel(parent)
25+ , m_category_index(-1)
26+{
27+ m_roles[CategoryResults::RoleUri] = "uri";
28+ m_roles[CategoryResults::RoleIconHint] = "icon";
29+ m_roles[CategoryResults::RoleMimetype] = "mimetype";
30+ m_roles[CategoryResults::RoleTitle] = "title";
31+ m_roles[CategoryResults::RoleComment] = "comment";
32+ m_roles[CategoryResults::RoleDndUri] = "dnd_uri";
33+}
34+
35+CategoryResults::~CategoryResults()
36+{
37+}
38+
39+int CategoryResults::categoryIndex() const
40+{
41+ return m_category_index;
42+}
43+
44+void CategoryResults::setCategoryIndex(int index)
45+{
46+ if (m_category_index != index) {
47+ m_category_index = index;
48+ Q_EMIT categoryIndexChanged(m_category_index);
49+ }
50+}
51+
52+QHash<int, QByteArray>
53+CategoryResults::roleNames() const
54+{
55+ return m_roles;
56+}
57+
58+QVariant
59+CategoryResults::data(const QModelIndex& index, int role) const
60+{
61+ if (!index.isValid()) {
62+ return QVariant();
63+ }
64+
65+ switch (role) {
66+ case RoleUri:
67+ return DeeListModel::data(index, 0);
68+ case RoleIconHint:
69+ return DeeListModel::data(index, 1);
70+ case RoleMimetype:
71+ return DeeListModel::data(index, 4);
72+ case RoleTitle:
73+ return DeeListModel::data(index, 5);
74+ case RoleComment:
75+ return DeeListModel::data(index, 6);
76+ case RoleDndUri:
77+ return DeeListModel::data(index, 7);
78+ default:
79+ return QVariant();
80+ }
81+}
plugins/Unity/categoryresults.hnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Michał Sawicz <michal.sawicz@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 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+ ~CategoryResults();
38+
39+ enum Roles {
40+ RoleUri,
41+ RoleIconHint,
42+ //RoleCategory, // not needed
43+ //RoleResultType, // not needed
44+ RoleMimetype,
45+ RoleTitle,
46+ RoleComment,
47+ RoleDndUri
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_category_index;
66+};
67+
68+#endif // CATEGORY_RESULTS_H
plugins/Unity/plugin.cpp+2−2
@@ -27,7 +27,7 @@
27#include "scope.h"
27#include "scope.h"
28#include "scopes.h"
28#include "scopes.h"
29#include "categories.h"
29#include "categories.h"
30−#include "categoryfilter.h"
30+#include "categoryresults.h"
31#include "bottombarvisibilitycommunicatorshell.h"
31#include "bottombarvisibilitycommunicatorshell.h"
32#include "launchermodel.h"
32#include "launchermodel.h"
33
33
@@ -43,7 +43,7 @@ void UnityPlugin::registerTypes(const char *uri)
43 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
43 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
44 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
44 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
45 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
45 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
46− qmlRegisterType<CategoryFilter>(uri, 0, 1, "CategoryFilter");
46+ qmlRegisterType<CategoryResults>(uri, 0, 1, "CategoryResults");
47 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
47 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
48 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
48 qmlRegisterType<LauncherModel>(uri, 0, 1, "LauncherModel");
49 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
49 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
plugins/Unity/scope.cpp+22−51
@@ -31,10 +31,8 @@
31Scope::Scope(QObject *parent) :
31Scope::Scope(QObject *parent) :
32 QObject(parent)
32 QObject(parent)
33{
33{
34− m_results = new DeeListModel(this);
34+ m_results.reset(new DeeListModel(this));
35− m_categories = new Categories(this);
35+ m_categories.reset(new Categories(this));
36−
37− m_categories->setResultModel(m_results);
38}
36}
39
37
40QString Scope::id() const
38QString Scope::id() const
@@ -77,14 +75,9 @@ bool Scope::connected() const
77 return m_unityScope->connected();
75 return m_unityScope->connected();
78}
76}
79
77
80−DeeListModel* Scope::results() const
81−{
82− return m_results;
83−}
84−
85Categories* Scope::categories() const
78Categories* Scope::categories() const
86{
79{
87− return m_categories;
80+ return m_categories.get();
88}
81}
89
82
90QString Scope::searchQuery() const
83QString Scope::searchQuery() const
@@ -97,6 +90,11 @@ QString Scope::noResultsHint() const
97 return m_noResultsHint;
90 return m_noResultsHint;
98}
91}
99
92
93+QString Scope::formFactor() const
94+{
95+ return m_formFactor;
96+}
97+
100void Scope::setSearchQuery(const QString& search_query)
98void Scope::setSearchQuery(const QString& search_query)
101{
99{
102 /* Checking for m_searchQuery.isNull() which returns true only when the string
100 /* Checking for m_searchQuery.isNull() which returns true only when the string
@@ -118,6 +116,16 @@ void Scope::setNoResultsHint(const QString& hint) {
118 }
116 }
119}
117}
120
118
119+void Scope::setFormFactor(const QString& form_factor) {
120+ if (form_factor != m_formFactor) {
121+ m_formFactor = form_factor;
122+ if (m_unityScope) {
123+ m_unityScope->form_factor = m_formFactor.toStdString();
124+ }
125+ Q_EMIT formFactorChanged();
126+ }
127+}
128+
121void Scope::activate(const QString& /*uri*/)
129void Scope::activate(const QString& /*uri*/)
122{
130{
123 // TODO:
131 // TODO:
@@ -171,18 +179,11 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
171{
179{
172 m_unityScope = scope;
180 m_unityScope = scope;
173
181
174− if (QString::fromStdString(m_unityScope->results()->swarm_name) == QString(":local")) {
182+ // TODO: do we even need this?
175− m_results->setModel(m_unityScope->results()->model());
176− } else {
177− m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
183+ m_results->setModel(m_unityScope->results()->model());
178− }
179−
180− if (QString::fromStdString(m_unityScope->categories()->swarm_name) == QString(":local")) {
181− m_categories->setModel(m_unityScope->categories()->model());
182− } else {
183− m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
184+ m_categories->setUnityScope(m_unityScope);
184− }
185
185
186+ m_unityScope->form_factor = m_formFactor.toStdString();
186 /* Property change signals */
187 /* Property change signals */
187 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
188 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
188 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
189 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
@@ -192,12 +193,7 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
192 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
193 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
193 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
194 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
194 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
195 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
195− m_unityScope->results.changed.connect(sigc::mem_fun(this, &Scope::onResultsChanged));
196− m_unityScope->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onResultsSwarmNameChanged));
197 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
196 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
198− m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesModelChanged));
199− m_unityScope->categories.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesChanged));
200− m_unityScope->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesSwarmNameChanged));
201 /* Signals forwarding */
197 /* Signals forwarding */
202 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
198 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
203
199
@@ -226,36 +222,11 @@ void Scope::synchronizeStates()
226 }
222 }
227}
223}
228
224
229−void Scope::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
230−{
231− m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
232−}
233−
234−void Scope::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
235−{
236− m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
237−}
238−
239void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
225void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
240{
226{
241 m_results->setModel(m_unityScope->results()->model());
227 m_results->setModel(m_unityScope->results()->model());
242}
228}
243
229
244−void Scope::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
245−{
246− m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
247−}
248−
249−void Scope::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
250−{
251− m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
252−}
253−
254−void Scope::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
255−{
256− m_categories->setModel(model);
257−}
258−
259void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
230void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
260{
231{
261 QString hint;
232 QString hint;
plugins/Unity/scope.h+8−10
@@ -32,7 +32,7 @@
32// dee-qt
32// dee-qt
33#include "deelistmodel.h"
33#include "deelistmodel.h"
34
34
35−class Categories;
35+#include "categories.h"
36
36
37class Scope : public QObject
37class Scope : public QObject
38{
38{
@@ -46,11 +46,11 @@ class Scope : public QObject
46 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
46 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
47 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
47 Q_PROPERTY(QString shortcut READ shortcut NOTIFY shortcutChanged)
48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
48 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
49− Q_PROPERTY(DeeListModel* results READ results NOTIFY resultsChanged)
50 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
49 Q_PROPERTY(Categories* categories READ categories NOTIFY categoriesChanged)
51
50
52 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
51 Q_PROPERTY(QString searchQuery READ searchQuery WRITE setSearchQuery NOTIFY searchQueryChanged)
53 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
52 Q_PROPERTY(QString noResultsHint READ noResultsHint WRITE setNoResultsHint NOTIFY noResultsHintChanged)
53+ Q_PROPERTY(QString formFactor READ formFactor WRITE setFormFactor NOTIFY formFactorChanged)
54
54
55public:
55public:
56 explicit Scope(QObject *parent = 0);
56 explicit Scope(QObject *parent = 0);
@@ -64,14 +64,15 @@ public:
64 bool visible() const;
64 bool visible() const;
65 QString shortcut() const;
65 QString shortcut() const;
66 bool connected() const;
66 bool connected() const;
67− DeeListModel* results() const;
68 Categories* categories() const;
67 Categories* categories() const;
69 QString searchQuery() const;
68 QString searchQuery() const;
70 QString noResultsHint() const;
69 QString noResultsHint() const;
70+ QString formFactor() const;
71
71
72 /* setters */
72 /* setters */
73 void setSearchQuery(const QString& search_query);
73 void setSearchQuery(const QString& search_query);
74 void setNoResultsHint(const QString& hint);
74 void setNoResultsHint(const QString& hint);
75+ void setFormFactor(const QString& form_factor);
75
76
76 Q_INVOKABLE void activate(const QString& uri);
77 Q_INVOKABLE void activate(const QString& uri);
77 void setUnityScope(const unity::dash::Scope::Ptr& scope);
78 void setUnityScope(const unity::dash::Scope::Ptr& scope);
@@ -88,32 +89,29 @@ Q_SIGNALS:
88 void visibleChanged(bool);
89 void visibleChanged(bool);
89 void shortcutChanged(const std::string&);
90 void shortcutChanged(const std::string&);
90 void connectedChanged(bool);
91 void connectedChanged(bool);
91− void resultsChanged();
92 void categoriesChanged();
92 void categoriesChanged();
93 void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
93 void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
94 void searchQueryChanged();
94 void searchQueryChanged();
95 void noResultsHintChanged();
95 void noResultsHintChanged();
96+ void formFactorChanged();
96
97
97private Q_SLOTS:
98private Q_SLOTS:
98 void synchronizeStates();
99 void synchronizeStates();
99 void onSearchFinished(const std::string &, unity::glib::HintsMap const &);
100 void onSearchFinished(const std::string &, unity::glib::HintsMap const &);
100
101
101private:
102private:
102− void onResultsSwarmNameChanged(const std::string&);
103− void onResultsChanged(const unity::dash::Results::Ptr&);
104 void onResultsModelChanged(unity::glib::Object<DeeModel>);
103 void onResultsModelChanged(unity::glib::Object<DeeModel>);
105− void onCategoriesSwarmNameChanged(const std::string&);
106 void onCategoriesModelChanged(unity::glib::Object<DeeModel>);
104 void onCategoriesModelChanged(unity::glib::Object<DeeModel>);
107− void onCategoriesChanged(const unity::dash::Categories::Ptr&);
108
105
109 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&);
106 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&);
110 void fallbackActivate(const QString& uri);
107 void fallbackActivate(const QString& uri);
111
108
112 unity::dash::Scope::Ptr m_unityScope;
109 unity::dash::Scope::Ptr m_unityScope;
113− DeeListModel* m_results;
110+ std::unique_ptr<DeeListModel> m_results;
114− Categories* m_categories;
111+ std::unique_ptr<Categories> m_categories;
115 QString m_searchQuery;
112 QString m_searchQuery;
116 QString m_noResultsHint;
113 QString m_noResultsHint;
114+ QString m_formFactor;
117};
115};
118
116
119Q_DECLARE_METATYPE(Scope*)
117Q_DECLARE_METATYPE(Scope*)