on xenial help sign in
First cut at filters support - added filter classes from Unity-2d.
ffba04dPawel Stolowski
plugins/Unity/CMakeLists.txt+7
@@ -17,7 +17,14 @@ set(QMLPLUGIN_SRC
17 scopes.cpp
17 scopes.cpp
18 categories.cpp
18 categories.cpp
19 categoryfilter.cpp
19 categoryfilter.cpp
20+ checkoptionfilter.cpp
21+ filter.cpp
22+ filteroption.cpp
23+ filter.cpp
20 plugin.cpp
24 plugin.cpp
25+ multirangefilter.cpp
26+ radiooptionfilter.cpp
27+ ratingsfilter.cpp
21 bottombarvisibilitycommunicatorshell.cpp
28 bottombarvisibilitycommunicatorshell.cpp
22 launchermodel.cpp
29 launchermodel.cpp
23 )
30 )
plugins/Unity/checkoptionfilter.cppnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "checkoptionfilter.h"
22+
23+CheckOptionFilter::CheckOptionFilter(QObject *parent) :
24+ Filter(parent), m_unityCheckOptionFilter(NULL), m_options(NULL)
25+{
26+}
27+
28+FilterOptions* CheckOptionFilter::options() const
29+{
30+ return m_options;
31+}
32+
33+void CheckOptionFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
34+{
35+ Filter::setUnityFilter(filter);
36+ m_unityCheckOptionFilter = std::dynamic_pointer_cast<unity::dash::CheckOptionFilter>(m_unityFilter);
37+
38+ onOptionsChanged(m_unityCheckOptionFilter->options);
39+}
40+
41+void CheckOptionFilter::onOptionsChanged(unity::dash::CheckOptionFilter::CheckOptions options)
42+{
43+ if (m_options != NULL) {
44+ // FIXME: should disconnect from m_unityFilter's signals
45+ delete m_options;
46+ m_options = NULL;
47+ }
48+ m_options = new FilterOptions(m_unityCheckOptionFilter->options,
49+ m_unityCheckOptionFilter->option_added,
50+ m_unityCheckOptionFilter->option_removed);
51+ /* Property change signals */
52+ m_unityCheckOptionFilter->options.changed.connect(sigc::mem_fun(this, &CheckOptionFilter::onOptionsChanged));
53+
54+ Q_EMIT optionsChanged();
55+}
56+
57+#include "checkoptionfilter.moc"
plugins/Unity/checkoptionfilter.hnew file+61
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 CHECKOPTIONFILTER_H
21+#define CHECKOPTIONFILTER_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/CheckOptionFilter.h>
29+
30+// Local
31+#include "filter.h"
32+#include "filteroption.h"
33+
34+class CheckOptionFilter : public Filter
35+{
36+ Q_OBJECT
37+
38+ Q_PROPERTY(FilterOptions* options READ options NOTIFY optionsChanged)
39+
40+public:
41+ explicit CheckOptionFilter(QObject *parent = 0);
42+
43+ /* getters */
44+ FilterOptions* options() const;
45+
46+Q_SIGNALS:
47+ void optionsChanged();
48+
49+protected:
50+ virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
51+
52+private:
53+ unity::dash::CheckOptionFilter::Ptr m_unityCheckOptionFilter;
54+ FilterOptions* m_options;
55+
56+ void onOptionsChanged(unity::dash::CheckOptionFilter::CheckOptions);
57+};
58+
59+Q_DECLARE_METATYPE(CheckOptionFilter*)
60+
61+#endif // CHECKOPTIONFILTER_H
plugins/Unity/filter.cppnew file+133
@@ -0,0 +1,133 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "filter.h"
22+
23+// local
24+#include "ratingsfilter.h"
25+#include "radiooptionfilter.h"
26+#include "checkoptionfilter.h"
27+#include "multirangefilter.h"
28+
29+// libunity-core
30+#include <UnityCore/Filter.h>
31+#include <UnityCore/RatingsFilter.h>
32+#include <UnityCore/RadioOptionFilter.h>
33+#include <UnityCore/CheckOptionFilter.h>
34+#include <UnityCore/MultiRangeFilter.h>
35+
36+// Qt
37+#include <QDebug>
38+
39+Filter::Filter(QObject *parent) :
40+ QObject(parent)
41+{
42+}
43+
44+
45+QString Filter::id() const
46+{
47+ return QString::fromStdString(m_unityFilter->id());
48+}
49+
50+QString Filter::name() const
51+{
52+ return QString::fromStdString(m_unityFilter->name());
53+}
54+
55+QString Filter::iconHint() const
56+{
57+ return QString::fromStdString(m_unityFilter->icon_hint());
58+}
59+
60+QString Filter::rendererName() const
61+{
62+ return QString::fromStdString(m_unityFilter->renderer_name());
63+}
64+
65+bool Filter::visible() const
66+{
67+ return m_unityFilter->visible();
68+}
69+
70+bool Filter::collapsed() const
71+{
72+ return m_unityFilter->collapsed();
73+}
74+
75+bool Filter::filtering() const
76+{
77+ return m_unityFilter->filtering();
78+}
79+
80+void Filter::clear()
81+{
82+ m_unityFilter->Clear();
83+}
84+
85+
86+void Filter::setUnityFilter(unity::dash::Filter::Ptr unityFilter)
87+{
88+ if (m_unityFilter != NULL) {
89+ // FIXME: should disconnect from m_unityFilter's signals
90+ }
91+
92+ m_unityFilter = unityFilter;
93+
94+ /* Property change signals */
95+ m_unityFilter->id.changed.connect(sigc::mem_fun(this, &Filter::idChanged));
96+ m_unityFilter->name.changed.connect(sigc::mem_fun(this, &Filter::nameChanged));
97+ m_unityFilter->icon_hint.changed.connect(sigc::mem_fun(this, &Filter::iconHintChanged));
98+ m_unityFilter->renderer_name.changed.connect(sigc::mem_fun(this, &Filter::rendererNameChanged));
99+ m_unityFilter->visible.changed.connect(sigc::mem_fun(this, &Filter::visibleChanged));
100+ m_unityFilter->collapsed.changed.connect(sigc::mem_fun(this, &Filter::collapsedChanged));
101+ m_unityFilter->filtering.changed.connect(sigc::mem_fun(this, &Filter::filteringChanged));
102+
103+ /* Signals forwarding */
104+ m_unityFilter->removed.connect(sigc::mem_fun(this, &Filter::removed));
105+}
106+
107+Filter* Filter::newFromUnityFilter(unity::dash::Filter::Ptr unityFilter)
108+{
109+ Filter* filter;
110+
111+ if (typeid(*unityFilter) == typeid(unity::dash::RatingsFilter)) {
112+ filter = new RatingsFilter;
113+ } else if (typeid(*unityFilter) == typeid(unity::dash::CheckOptionFilter)) {
114+ filter = new CheckOptionFilter;
115+ } else if (typeid(*unityFilter) == typeid(unity::dash::RadioOptionFilter)) {
116+ filter = new RadioOptionFilter;
117+ } else if (typeid(*unityFilter) == typeid(unity::dash::MultiRangeFilter)) {
118+ filter = new MultiRangeFilter;
119+ } else {
120+ qWarning() << "Filter of unknown type: " << typeid(*unityFilter).name();
121+ filter = new Filter;
122+ }
123+
124+ filter->setUnityFilter(unityFilter);
125+ return filter;
126+}
127+
128+bool Filter::hasUnityFilter(unity::dash::Filter::Ptr unityFilter) const
129+{
130+ return m_unityFilter == unityFilter;
131+}
132+
133+#include "filter.moc"
plugins/Unity/filter.hnew file+77
@@ -0,0 +1,77 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 FILTER_H
21+#define FILTER_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/Filter.h>
29+
30+class Filter : public QObject
31+{
32+ Q_OBJECT
33+
34+ Q_PROPERTY(QString id READ id NOTIFY idChanged)
35+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
36+ Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
37+ Q_PROPERTY(QString rendererName READ rendererName NOTIFY rendererNameChanged)
38+ Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
39+ Q_PROPERTY(bool collapsed READ collapsed NOTIFY collapsedChanged)
40+ Q_PROPERTY(bool filtering READ filtering NOTIFY filteringChanged)
41+
42+public:
43+ explicit Filter(QObject *parent = 0);
44+
45+ /* getters */
46+ QString id() const;
47+ QString name() const;
48+ QString iconHint() const;
49+ QString rendererName() const;
50+ bool visible() const;
51+ bool collapsed() const;
52+ bool filtering() const;
53+
54+ Q_INVOKABLE void clear();
55+
56+ static Filter* newFromUnityFilter(unity::dash::Filter::Ptr unityFilter);
57+ bool hasUnityFilter(unity::dash::Filter::Ptr unityFilter) const;
58+
59+Q_SIGNALS:
60+ void idChanged(std::string);
61+ void nameChanged(std::string);
62+ void iconHintChanged(std::string);
63+ void rendererNameChanged(std::string);
64+ void visibleChanged(bool);
65+ void collapsedChanged(bool);
66+ void filteringChanged(bool);
67+
68+ void removed();
69+
70+protected:
71+ unity::dash::Filter::Ptr m_unityFilter;
72+ virtual void setUnityFilter(unity::dash::Filter::Ptr unityFilter);
73+};
74+
75+Q_DECLARE_METATYPE(Filter*)
76+
77+#endif // FILTER_H
plugins/Unity/filteroption.cppnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "filteroption.h"
22+
23+// libunity-core
24+#include <UnityCore/Filter.h>
25+
26+FilterOption::FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent) :
27+ QObject(parent), m_unityFilterOption(NULL)
28+{
29+ setUnityFilterOption(unityFilterOption);
30+}
31+
32+QString FilterOption::id() const
33+{
34+ return QString::fromStdString(m_unityFilterOption->id());
35+}
36+
37+QString FilterOption::name() const
38+{
39+ return QString::fromStdString(m_unityFilterOption->name());
40+}
41+
42+QString FilterOption::iconHint() const
43+{
44+ return QString::fromStdString(m_unityFilterOption->icon_hint());
45+}
46+
47+bool FilterOption::active() const
48+{
49+ return m_unityFilterOption->active();
50+}
51+
52+void FilterOption::setActive(bool active)
53+{
54+ m_unityFilterOption->active = active;
55+}
56+
57+void FilterOption::setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption)
58+{
59+ if (m_unityFilterOption != NULL) {
60+ // FIXME: should disconnect from m_unityFilterOption's signals
61+ }
62+
63+ m_unityFilterOption = unityFilterOption;
64+
65+ /* Property change signals */
66+ m_unityFilterOption->id.changed.connect(sigc::mem_fun(this, &FilterOption::idChanged));
67+ m_unityFilterOption->name.changed.connect(sigc::mem_fun(this, &FilterOption::nameChanged));
68+ m_unityFilterOption->icon_hint.changed.connect(sigc::mem_fun(this, &FilterOption::iconHintChanged));
69+ m_unityFilterOption->active.changed.connect(sigc::mem_fun(this, &FilterOption::activeChanged));
70+}
71+
72+#include "filteroption.moc"
plugins/Unity/filteroption.hnew file+71
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 FILTEROPTION_H
21+#define FILTEROPTION_H
22+
23+// Local
24+#include "listmodelwrapper.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QMetaType>
29+
30+// libunity-core
31+#include <UnityCore/Filter.h>
32+
33+class FilterOption : public QObject
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(QString id READ id NOTIFY idChanged)
38+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
39+ Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
40+ Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
41+
42+public:
43+ explicit FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent = 0);
44+
45+ /* getters */
46+ QString id() const;
47+ QString name() const;
48+ QString iconHint() const;
49+ bool active() const;
50+
51+ /* setters */
52+ void setActive(bool active);
53+
54+Q_SIGNALS:
55+ void idChanged(std::string);
56+ void nameChanged(std::string);
57+ void iconHintChanged(std::string);
58+ void activeChanged(bool);
59+
60+private:
61+ void setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption);
62+
63+ unity::dash::FilterOption::Ptr m_unityFilterOption;
64+};
65+
66+Q_DECLARE_METATYPE(FilterOption*)
67+
68+typedef ListModelWrapper<FilterOption, unity::dash::FilterOption::Ptr> FilterOptions;
69+Q_DECLARE_METATYPE(FilterOptions*)
70+
71+#endif // FILTEROPTION_H
plugins/Unity/filters.cppnew file+144
@@ -0,0 +1,144 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "filters.h"
22+
23+// Local
24+#include "filter.h"
25+
26+// Qt
27+#include <QDebug>
28+
29+// libunity-core
30+#include <UnityCore/Filters.h>
31+
32+Filters::Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent) :
33+ QAbstractListModel(parent), m_unityFilters(unityFilters)
34+{
35+ QHash<int, QByteArray> roles;
36+ roles[Filters::RoleFilter] = "filter";
37+ setRoleNames(roles);
38+
39+ for (unsigned int i=0; i<m_unityFilters->count(); i++) {
40+ unity::dash::Filter::Ptr unityFilter = m_unityFilters->FilterAtIndex(i);
41+ addFilter(unityFilter, i);
42+ }
43+ m_unityFilters->filter_added.connect(sigc::mem_fun(this, &Filters::onFilterAdded));
44+ m_unityFilters->filter_changed.connect(sigc::mem_fun(this, &Filters::onFilterChanged));
45+ m_unityFilters->filter_removed.connect(sigc::mem_fun(this, &Filters::onFilterRemoved));
46+}
47+
48+Filters::~Filters()
49+{
50+ while (!m_filters.isEmpty()) {
51+ delete m_filters.takeFirst();
52+ }
53+}
54+
55+int Filters::rowCount(const QModelIndex& parent) const
56+{
57+ Q_UNUSED(parent)
58+
59+ return m_unityFilters->count();
60+}
61+
62+QVariant Filters::data(const QModelIndex& index, int role) const
63+{
64+ Q_UNUSED(role)
65+
66+ if (!index.isValid()) {
67+ return QVariant();
68+ }
69+
70+ Filter* filter = m_filters.at(index.row());
71+
72+ if (role == Filters::RoleFilter) {
73+ return QVariant::fromValue(filter);
74+ } else {
75+ return QVariant();
76+ }
77+}
78+
79+Filter* Filters::getFilter(const QString& id) const
80+{
81+ Q_FOREACH (Filter* filter, m_filters) {
82+ if (filter->id() == id) {
83+ return filter;
84+ }
85+ }
86+ return NULL;
87+}
88+
89+void Filters::onFilterAdded(unity::dash::Filter::Ptr unityFilter)
90+{
91+ if (unityFilter == NULL) {
92+ return;
93+ }
94+
95+ /* FIXME: figure out actual index of unityFilter; for now filters are appended */
96+ int index = m_filters.count();
97+ addFilter(unityFilter, index);
98+}
99+
100+void Filters::onFilterChanged(unity::dash::Filter::Ptr unityFilter)
101+{
102+ if (unityFilter == NULL) {
103+ return;
104+ }
105+
106+ QModelIndex filterIndex = index(indexForFilter(unityFilter));
107+ Q_EMIT dataChanged(filterIndex, filterIndex);
108+}
109+
110+void Filters::onFilterRemoved(unity::dash::Filter::Ptr unityFilter)
111+{
112+ removeFilter(indexForFilter(unityFilter));
113+}
114+
115+void Filters::addFilter(unity::dash::Filter::Ptr unityFilter, int index)
116+{
117+ beginInsertRows(QModelIndex(), index, index);
118+ Filter* filter = Filter::newFromUnityFilter(unityFilter);
119+ m_filters.insert(index, filter);
120+ endInsertRows();
121+}
122+
123+void Filters::removeFilter(int index)
124+{
125+ beginRemoveRows(QModelIndex(), index, index);
126+ Filter* filter = m_filters.takeAt(index);
127+ delete filter;
128+ endRemoveRows();
129+}
130+
131+int Filters::indexForFilter(unity::dash::Filter::Ptr unityFilter)
132+{
133+ int index;
134+ for (index=0; index<m_filters.count(); index++) {
135+ if (m_filters[index]->hasUnityFilter(unityFilter)) {
136+ return index;
137+ }
138+ }
139+ qWarning() << "Filter" << QString::fromStdString(unityFilter->name()) << "not found in local cache.";
140+ return -1;
141+}
142+
143+
144+#include "filters.moc"
plugins/Unity/filters.hnew file+69
@@ -0,0 +1,69 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 FILTERS_H
21+#define FILTERS_H
22+
23+// Qt
24+#include <QAbstractListModel>
25+#include <QList>
26+
27+// libunity-core
28+#include <UnityCore/Filters.h>
29+#include <UnityCore/Filter.h>
30+
31+
32+class Filter;
33+
34+class Filters : public QAbstractListModel
35+{
36+ Q_OBJECT
37+
38+ Q_ENUMS(Roles)
39+
40+public:
41+ explicit Filters(unity::dash::Filters::Ptr unityFilters, QObject *parent = 0);
42+ ~Filters();
43+
44+ enum Roles {
45+ RoleFilter
46+ };
47+
48+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
49+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
50+
51+ Q_INVOKABLE Filter* getFilter(const QString& id) const;
52+
53+private:
54+ unity::dash::Filters::Ptr m_unityFilters;
55+ QList<Filter*> m_filters;
56+
57+ void onFilterAdded(unity::dash::Filter::Ptr unityFilter);
58+ void onFilterChanged(unity::dash::Filter::Ptr unityFilter);
59+ void onFilterRemoved(unity::dash::Filter::Ptr unityFilter);
60+
61+ void addFilter(unity::dash::Filter::Ptr unityFilter, int index);
62+ void removeFilter(int index);
63+
64+ int indexForFilter(unity::dash::Filter::Ptr unityFilter);
65+};
66+
67+Q_DECLARE_METATYPE(Filters*)
68+
69+#endif // FILTERS_H
plugins/Unity/listmodelwrapper.hnew file+161
@@ -0,0 +1,161 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 LISTMODELWRAPPER_H
21+#define LISTMODELWRAPPER_H
22+
23+// Qt
24+#include <QAbstractListModel>
25+#include <QList>
26+
27+#include <sigc++/signal.h>
28+#include <vector>
29+
30+template <class WrapperItem, class ItemClass>
31+class ListModelWrapper : public QAbstractListModel
32+{
33+// Q_ENUMS(Roles)
34+
35+public:
36+ explicit ListModelWrapper(const std::vector<ItemClass>& list,
37+ sigc::signal<void, ItemClass> itemAddedSignal,
38+ sigc::signal<void, ItemClass> itemRemovedSignal,
39+ QObject *parent = 0);
40+ ~ListModelWrapper();
41+
42+// enum Roles {
43+ // RoleItem
44+// };/
45+
46+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
47+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
48+
49+ const QList<WrapperItem*>& rawList() const;
50+
51+private:
52+ void onItemAdded(ItemClass item);
53+ void onItemRemoved(ItemClass item);
54+ void onItemChanged(ItemClass item);
55+
56+ QList<WrapperItem*> m_list;
57+ QMap<ItemClass, int> m_indexes;
58+
59+ void addItem(ItemClass item, int index);
60+ void removeItem(ItemClass item, int index);
61+};
62+
63+
64+template <class WrapperItem, class ItemClass>
65+ListModelWrapper<WrapperItem, ItemClass>::ListModelWrapper(const std::vector<ItemClass>& list,
66+ sigc::signal<void, ItemClass> itemAddedSignal,
67+ sigc::signal<void, ItemClass> itemRemovedSignal,
68+ QObject *parent) :
69+ QAbstractListModel(parent)
70+{
71+// QHash<int, QByteArray> roles;
72+// roles[ListModelWrapper::RoleItem] = "item";
73+// setRoleNames(roles);
74+
75+ for (unsigned int i=0; i<list.size(); i++) {
76+ addItem(list[i], i);
77+ }
78+ itemAddedSignal.connect(sigc::mem_fun(this, &ListModelWrapper::onItemAdded));
79+ itemRemovedSignal.connect(sigc::mem_fun(this, &ListModelWrapper::onItemRemoved));
80+}
81+
82+template <class WrapperItem, class ItemClass>
83+ListModelWrapper<WrapperItem, ItemClass>::~ListModelWrapper()
84+{
85+ m_indexes.clear();
86+ while (!m_list.isEmpty()) {
87+ delete m_list.takeFirst();
88+ }
89+}
90+
91+template <class WrapperItem, class ItemClass>
92+int ListModelWrapper<WrapperItem, ItemClass>::rowCount(const QModelIndex& parent) const
93+{
94+ Q_UNUSED(parent)
95+
96+ return m_list.count();
97+}
98+
99+template <class WrapperItem, class ItemClass>
100+const QList<WrapperItem*>& ListModelWrapper<WrapperItem, ItemClass>::rawList() const
101+{
102+ return m_list;
103+}
104+
105+template <class WrapperItem, class ItemClass>
106+QVariant ListModelWrapper<WrapperItem, ItemClass>::data(const QModelIndex& index, int) const
107+{
108+ if (!index.isValid()) {
109+ return QVariant();
110+ }
111+
112+ WrapperItem* item = m_list.at(index.row());
113+
114+// if (role == ListModelWrapper::RoleItem) {
115+ return QVariant::fromValue(item);
116+// } else {
117+// return QVariant();
118+// }
119+}
120+
121+template <class WrapperItem, class ItemClass>
122+void ListModelWrapper<WrapperItem, ItemClass>::onItemAdded(ItemClass item)
123+{
124+ /* FIXME: figure out actual index of item; for now items are appended */
125+ int index = m_list.count();
126+ beginInsertRows(QModelIndex(), index, index);
127+ addItem(item, index);
128+ endInsertRows();
129+}
130+
131+template <class WrapperItem, class ItemClass>
132+void ListModelWrapper<WrapperItem, ItemClass>::onItemRemoved(ItemClass item)
133+{
134+ int index = m_indexes[item];
135+ beginInsertRows(QModelIndex(), index, index);
136+ removeItem(item, index);
137+ endInsertRows();
138+}
139+
140+template <class WrapperItem, class ItemClass>
141+void ListModelWrapper<WrapperItem, ItemClass>::onItemChanged(ItemClass item)
142+{
143+ QModelIndex itemIndex = index(m_indexes[item]);
144+ Q_EMIT dataChanged(itemIndex, itemIndex);
145+}
146+
147+template <class WrapperItem, class ItemClass>
148+void ListModelWrapper<WrapperItem, ItemClass>::addItem(ItemClass item, int index)
149+{
150+ m_indexes.insert(item, index);
151+ m_list.insert(index, new WrapperItem(item));
152+}
153+
154+template <class WrapperItem, class ItemClass>
155+void ListModelWrapper<WrapperItem, ItemClass>::removeItem(ItemClass item, int index)
156+{
157+ m_indexes.remove(item);
158+ delete m_list.takeAt(index);
159+}
160+
161+#endif // LISTMODELWRAPPER_H
plugins/Unity/multirangefilter.cppnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "multirangefilter.h"
22+
23+MultiRangeFilter::MultiRangeFilter(QObject *parent) :
24+ Filter(parent), m_unityMultiRangeFilter(NULL), m_options(NULL)
25+{
26+}
27+
28+FilterOptions* MultiRangeFilter::options() const
29+{
30+ return m_options;
31+}
32+
33+void MultiRangeFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
34+{
35+ Filter::setUnityFilter(filter);
36+ m_unityMultiRangeFilter = std::dynamic_pointer_cast<unity::dash::MultiRangeFilter>(m_unityFilter);
37+
38+ onOptionsChanged(m_unityMultiRangeFilter->options);
39+}
40+
41+void MultiRangeFilter::onOptionsChanged(unity::dash::MultiRangeFilter::Options options)
42+{
43+ if (m_options != NULL) {
44+ // FIXME: should disconnect from m_unityFilter's signals
45+ delete m_options;
46+ m_options = NULL;
47+ }
48+ m_options = new FilterOptions(m_unityMultiRangeFilter->options,
49+ m_unityMultiRangeFilter->option_added,
50+ m_unityMultiRangeFilter->option_removed);
51+ /* Property change signals */
52+ m_unityMultiRangeFilter->options.changed.connect(sigc::mem_fun(this, &MultiRangeFilter::onOptionsChanged));
53+
54+ Q_EMIT optionsChanged();
55+}
56+
57+#include "multirangefilter.moc"
plugins/Unity/multirangefilter.hnew file+61
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 MULTIRANGEFILTER_H
21+#define MULTIRANGEFILTER_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/MultiRangeFilter.h>
29+
30+// Local
31+#include "filter.h"
32+#include "filteroption.h"
33+
34+class MultiRangeFilter : public Filter
35+{
36+ Q_OBJECT
37+
38+ Q_PROPERTY(FilterOptions* options READ options NOTIFY optionsChanged)
39+
40+public:
41+ explicit MultiRangeFilter(QObject *parent = 0);
42+
43+ /* getters */
44+ FilterOptions* options() const;
45+
46+Q_SIGNALS:
47+ void optionsChanged();
48+
49+protected:
50+ virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
51+
52+private:
53+ unity::dash::MultiRangeFilter::Ptr m_unityMultiRangeFilter;
54+ FilterOptions* m_options;
55+
56+ void onOptionsChanged(unity::dash::MultiRangeFilter::Options);
57+};
58+
59+Q_DECLARE_METATYPE(MultiRangeFilter*)
60+
61+#endif // MULTIRANGEFILTER_H
plugins/Unity/radiooptionfilter.cppnew file+67
@@ -0,0 +1,67 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "radiooptionfilter.h"
22+
23+RadioOptionFilter::RadioOptionFilter(QObject *parent) :
24+ Filter(parent), m_unityRadioOptionFilter(NULL), m_options(NULL)
25+{
26+}
27+
28+FilterOptions* RadioOptionFilter::options() const
29+{
30+ return m_options;
31+}
32+
33+FilterOption* RadioOptionFilter::getOption(const QString& id) const
34+{
35+ Q_FOREACH (FilterOption* option, m_options->rawList()) {
36+ if (option->id() == id) {
37+ return option;
38+ }
39+ }
40+ return NULL;
41+}
42+
43+void RadioOptionFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
44+{
45+ Filter::setUnityFilter(filter);
46+ m_unityRadioOptionFilter = std::dynamic_pointer_cast<unity::dash::RadioOptionFilter>(m_unityFilter);
47+
48+ onOptionsChanged(m_unityRadioOptionFilter->options);
49+}
50+
51+void RadioOptionFilter::onOptionsChanged(unity::dash::RadioOptionFilter::RadioOptions)
52+{
53+ if (m_options != NULL) {
54+ // FIXME: should disconnect from m_unityFilter's signals
55+ delete m_options;
56+ m_options = NULL;
57+ }
58+ m_options = new FilterOptions(m_unityRadioOptionFilter->options,
59+ m_unityRadioOptionFilter->option_added,
60+ m_unityRadioOptionFilter->option_removed);
61+ /* Property change signals */
62+ m_unityRadioOptionFilter->options.changed.connect(sigc::mem_fun(this, &RadioOptionFilter::onOptionsChanged));
63+
64+ Q_EMIT optionsChanged();
65+}
66+
67+#include "radiooptionfilter.moc"
plugins/Unity/radiooptionfilter.hnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 RADIOOPTIONFILTER_H
21+#define RADIOOPTIONFILTER_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/RadioOptionFilter.h>
29+
30+// Local
31+#include "filter.h"
32+#include "filteroption.h"
33+
34+class RadioOptionFilter : public Filter
35+{
36+ Q_OBJECT
37+
38+ Q_PROPERTY(FilterOptions* options READ options NOTIFY optionsChanged)
39+
40+public:
41+ explicit RadioOptionFilter(QObject *parent = 0);
42+
43+ /* getters */
44+ FilterOptions* options() const;
45+
46+ Q_INVOKABLE FilterOption* getOption(const QString& id) const;
47+
48+Q_SIGNALS:
49+ void optionsChanged();
50+
51+protected:
52+ virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
53+
54+private:
55+ unity::dash::RadioOptionFilter::Ptr m_unityRadioOptionFilter;
56+ FilterOptions* m_options;
57+
58+ void onOptionsChanged(unity::dash::RadioOptionFilter::RadioOptions);
59+};
60+
61+Q_DECLARE_METATYPE(RadioOptionFilter*)
62+
63+#endif // RADIOOPTIONFILTER_H
plugins/Unity/ratingsfilter.cppnew file+51
@@ -0,0 +1,51 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 "ratingsfilter.h"
22+
23+RatingsFilter::RatingsFilter(QObject *parent) :
24+ Filter(parent), m_unityRatingsFilter(NULL)
25+{
26+}
27+
28+float RatingsFilter::rating() const
29+{
30+ return m_unityRatingsFilter->rating();
31+}
32+
33+void RatingsFilter::setRating(float rating)
34+{
35+ m_unityRatingsFilter->rating = rating;
36+}
37+
38+void RatingsFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
39+{
40+ if (m_unityFilter != NULL) {
41+ // FIXME: should disconnect from m_unityFilter's signals
42+ }
43+
44+ Filter::setUnityFilter(filter);
45+ m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
46+
47+ /* Property change signals */
48+ m_unityRatingsFilter->rating.changed.connect(sigc::mem_fun(this, &RatingsFilter::ratingChanged));
49+}
50+
51+#include "ratingsfilter.moc"
plugins/Unity/ratingsfilter.hnew file+60
@@ -0,0 +1,60 @@
1+/*
2+ * Copyright (C) 2011 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Florian Boucault <florian.boucault@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 RATINGSFILTER_H
21+#define RATINGSFILTER_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/RatingsFilter.h>
29+
30+// Local
31+#include "filter.h"
32+
33+class RatingsFilter : public Filter
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(float rating READ rating WRITE setRating NOTIFY ratingChanged)
38+
39+public:
40+ explicit RatingsFilter(QObject *parent = 0);
41+
42+ /* getters */
43+ float rating() const;
44+
45+ /* setters */
46+ void setRating(float rating);
47+
48+Q_SIGNALS:
49+ void ratingChanged(float);
50+
51+protected:
52+ virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
53+
54+private:
55+ unity::dash::RatingsFilter::Ptr m_unityRatingsFilter;
56+};
57+
58+Q_DECLARE_METATYPE(RatingsFilter*)
59+
60+#endif // RATINGSFILTER_H