on xenial help sign in
Added some basic classes and code for previews bindings.
commitea9229536254ab477d157dec4c8ca7c34117ec95 authorPawel Stolowski <pawel.stolowski@canonical.com> dateMon 24 Jun 2013, 16:58 (13 years ago) parent6161205
13 files changed+527−4
plugins/Unity/CMakeLists.txt+5 plugins/Unity/applicationpreview.cpp+57 plugins/Unity/applicationpreview.h+60 plugins/Unity/genericpreview.cpp+26 plugins/Unity/genericpreview.h+38 plugins/Unity/moviepreview.cpp+49 plugins/Unity/moviepreview.h+56 plugins/Unity/musicpreview.cpp+25 plugins/Unity/musicpreview.h+40 plugins/Unity/preview.cpp+77 plugins/Unity/preview.h+54 plugins/Unity/scope.cpp+29−3 plugins/Unity/scope.h+11−1
plugins/Unity/CMakeLists.txt+5
@@ -20,6 +20,11 @@ set(QMLPLUGIN_SRC
2020 plugin.cpp
2121 bottombarvisibilitycommunicatorshell.cpp
2222 launchermodel.cpp
23+ applicationpreview.cpp
24+ genericpreview.cpp
25+ moviepreview.cpp
26+ musicpreview.cpp
27+ preview.cpp
2328 variantutils.cpp
2429 )
2530
plugins/Unity/applicationpreview.cppnew file+57
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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+// local
21+#include "applicationpreview.h"
22+
23+ApplicationPreview::ApplicationPreview(QObject *parent):
24+ Preview(parent)
25+{
26+}
27+
28+QString ApplicationPreview::lastUpdate() const
29+{
30+ return QString::fromStdString(m_unityAppPreview->last_update());
31+}
32+
33+QString ApplicationPreview::copyright() const
34+{
35+ return QString::fromStdString(m_unityAppPreview->copyright());
36+}
37+
38+QString ApplicationPreview::license() const
39+{
40+ return QString::fromStdString(m_unityAppPreview->license());
41+}
42+
43+QString ApplicationPreview::appIcon() const
44+{
45+ return QString::fromUtf8(g_icon_to_string(m_unityAppPreview->app_icon()));
46+}
47+
48+float ApplicationPreview::rating() const
49+{
50+ return m_unityAppPreview->rating();
51+}
52+
53+unsigned int ApplicationPreview::numRatings() const
54+{
55+ return m_unityAppPreview->num_ratings();
56+}
57+
plugins/Unity/applicationpreview.hnew file+60
@@ -0,0 +1,60 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 APPLICATIONPREVIEW_H
21+#define APPLICATIONPREVIEW_H
22+
23+// local
24+#include "preview.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QMetaType>
29+
30+// libunity-core
31+#include <UnityCore/ApplicationPreview.h>
32+
33+class ApplicationPreview: public Preview
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(QString lastUpdate READ lastUpdate)
38+ Q_PROPERTY(QString copyright READ copyright)
39+ Q_PROPERTY(QString license READ license)
40+ Q_PROPERTY(QString appIcon READ appIcon)
41+ Q_PROPERTY(float rating READ rating)
42+ Q_PROPERTY(unsigned int numRatings READ numRatings)
43+
44+public:
45+ explicit ApplicationPreview(QObject *parent = 0);
46+
47+ QString lastUpdate() const;
48+ QString copyright() const;
49+ QString license() const;
50+ QString appIcon() const;
51+ float rating() const;
52+ unsigned int numRatings() const;
53+
54+private:
55+ unity::dash::ApplicationPreview::Ptr m_unityAppPreview;
56+};
57+
58+Q_DECLARE_METATYPE(ApplicationPreview *)
59+
60+#endif
plugins/Unity/genericpreview.cppnew file+26
@@ -0,0 +1,26 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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+// local
21+#include "genericpreview.h"
22+
23+GenericPreview::GenericPreview(QObject *parent):
24+ Preview(parent)
25+{
26+}
plugins/Unity/genericpreview.hnew file+38
@@ -0,0 +1,38 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 GENERICPREVIEW_H
21+#define GENERICPREVIEW_H
22+
23+// local
24+#include "preview.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QMetaType>
29+
30+class GenericPreview : public Preview
31+{
32+ Q_OBJECT
33+
34+public:
35+ explicit GenericPreview(QObject *parent = 0);
36+};
37+
38+#endif
plugins/Unity/moviepreview.cppnew file+49
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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+// local
21+#include "moviepreview.h"
22+
23+MoviePreview::MoviePreview(QObject *parent):
24+ Preview(parent)
25+{
26+}
27+
28+QString MoviePreview::year() const
29+{
30+ return QString::fromStdString(m_unityMoviePreview->year());
31+}
32+
33+float MoviePreview::rating() const
34+{
35+ return m_unityMoviePreview->rating();
36+}
37+
38+unsigned int MoviePreview::numRatings() const
39+{
40+ return m_unityMoviePreview->num_ratings();
41+}
42+
43+
44+void MoviePreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
45+{
46+ Preview::setUnityPreview(unityPreview);
47+
48+ m_unityMoviePreview = std::dynamic_pointer_cast<unity::dash::MoviePreview>(unityPreview);
49+}
plugins/Unity/moviepreview.hnew file+56
@@ -0,0 +1,56 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 MOVIEPREVIEW_H
21+#define MOVIEPREVIEW_H
22+
23+// local
24+#include "preview.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QMetaType>
29+
30+// libunity-core
31+#include <UnityCore/MoviePreview.h>
32+
33+class MoviePreview: public Preview
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(QString year READ year)
38+ Q_PROPERTY(float rating READ rating)
39+ Q_PROPERTY(unsigned int numRatings READ numRatings)
40+
41+public:
42+ explicit MoviePreview(QObject *parent = 0);
43+
44+ QString year() const;
45+ float rating() const;
46+ unsigned int numRatings() const;
47+
48+private:
49+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
50+
51+ unity::dash::MoviePreview::Ptr m_unityMoviePreview;
52+};
53+
54+Q_DECLARE_METATYPE(MoviePreview *)
55+
56+#endif
plugins/Unity/musicpreview.cppnew file+25
@@ -0,0 +1,25 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 "musicpreview.h"
21+
22+MusicPreview::MusicPreview(QObject *parent):
23+ Preview(parent)
24+{
25+}
plugins/Unity/musicpreview.hnew file+40
@@ -0,0 +1,40 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 MUSICPREVIEW_H
21+#define MUSICPREVIEW_H
22+
23+// local
24+#include "preview.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QMetaType>
29+
30+class MusicPreview: public Preview
31+{
32+ Q_OBJECT
33+
34+public:
35+ explicit MusicPreview(QObject *parent = 0);
36+};
37+
38+Q_DECLARE_METATYPE(MusicPreview *)
39+
40+#endif
plugins/Unity/preview.cppnew file+77
@@ -0,0 +1,77 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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+// local
21+#include "preview.h"
22+#include "genericpreview.h"
23+#include "applicationpreview.h"
24+#include "moviepreview.h"
25+#include "musicpreview.h"
26+
27+// Qt
28+#include <QDebug>
29+
30+#include <UnityCore/GenericPreview.h>
31+#include <UnityCore/ApplicationPreview.h>
32+#include <UnityCore/MoviePreview.h>
33+#include <UnityCore/MusicPreview.h>
34+
35+Preview::Preview(QObject *parent):
36+ QObject(parent)
37+{
38+}
39+
40+void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
41+{
42+ m_unityPreview = unityPreview;
43+}
44+
45+QString Preview::title() const
46+{
47+ return QString::fromStdString(m_unityPreview->title());
48+}
49+
50+QString Preview::subtitle () const
51+{
52+ return QString::fromStdString(m_unityPreview->subtitle());
53+}
54+
55+Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
56+{
57+ Preview* preview = nullptr;
58+
59+ if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
60+ preview = new GenericPreview();
61+ }
62+ else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
63+ preview = new GenericPreview();
64+ }
65+ else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
66+ preview = new MoviePreview();
67+ }
68+ else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
69+ preview = new ApplicationPreview();
70+ } else {
71+ qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
72+ preview = new GenericPreview();
73+ }
74+ preview->setUnityPreview(unityPreview);
75+
76+ return preview;
77+}
plugins/Unity/preview.hnew file+54
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@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 PREVIEW_H
21+#define PREVIEW_H
22+
23+// Qt
24+#include <QObject>
25+#include <QString>
26+#include <QMetaType>
27+
28+// libunity-core
29+#include <UnityCore/Preview.h>
30+
31+class Preview : public QObject
32+{
33+ Q_OBJECT
34+
35+ Q_PROPERTY(QString title READ title)
36+ Q_PROPERTY(QString subtitle READ subtitle)
37+
38+public:
39+ explicit Preview(QObject *parent = 0);
40+ static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
41+
42+ QString title() const;
43+ QString subtitle () const;
44+
45+protected:
46+ virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
47+
48+ unity::dash::Preview::Ptr m_unityPreview;
49+
50+};
51+
52+Q_DECLARE_METATYPE(Preview *)
53+
54+#endif
plugins/Unity/scope.cpp+29−3
@@ -22,6 +22,7 @@
2222
2323// local
2424#include "categories.h"
25+#include "preview.h"
2526#include "variantutils.h"
2627
2728// Qt
@@ -121,9 +122,12 @@ void Scope::setNoResultsHint(const QString& hint) {
121122 }
122123}
123124
124−void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
125− const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
126− const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
125+
126+unity::dash::LocalResult Scope::createLocalResult(const QVariant &uri, const QVariant &icon_hint,
127+ const QVariant &category, const QVariant &result_type,
128+ const QVariant &mimetype, const QVariant &title,
129+ const QVariant &comment, const QVariant &dnd_uri,
130+ const QVariant &metadata)
127131{
128132 unity::dash::LocalResult res;
129133 res.uri = uri.toString().toStdString();
@@ -136,9 +140,25 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
136140 res.dnd_uri = dnd_uri.toString().toStdString();
137141 res.hints = hintsMapFromQVariant(metadata);
138142
143+ return res;
144+}
145+
146+void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
147+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
148+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
149+{
150+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
139151 m_unityScope->Activate(res);
140152}
141153
154+void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
155+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
156+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
157+{
158+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
159+ m_unityScope->Preview(res);
160+}
161+
142162void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
143163{
144164 if (type == unity::dash::NOT_HANDLED) {
@@ -146,6 +166,10 @@ void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::Sco
146166 }
147167}
148168
169+void Scope::onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview)
170+{
171+}
172+
149173void Scope::fallbackActivate(const QString& uri)
150174{
151175 /* FIXME: stripping all content before the first column because for some
@@ -217,6 +241,8 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
217241 /* FIXME: signal should be forwarded instead of calling the handler directly */
218242 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
219243
244+ m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
245+
220246 /* Synchronize local states with m_unityScope right now and whenever
221247 m_unityScope becomes connected */
222248 /* FIXME: should emit change notification signals for all properties */
plugins/Unity/scope.h+11−1
@@ -33,6 +33,7 @@
3333#include "deelistmodel.h"
3434
3535class Categories;
36+class Preview;
3637
3738class Scope : public QObject
3839{
@@ -76,6 +77,9 @@ public:
7677 Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
7778 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
7879 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
80+ Q_INVOKABLE void preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
81+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
82+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata);
7983 void setUnityScope(const unity::dash::Scope::Ptr& scope);
8084 unity::dash::Scope::Ptr unityScope() const;
8185
@@ -95,6 +99,7 @@ Q_SIGNALS:
9599 void searchFinished(const std::string&, unity::glib::HintsMap const&, unity::glib::Error const&);
96100 void searchQueryChanged();
97101 void noResultsHintChanged();
102+ void previewReady(const Preview &preview);
98103
99104private Q_SLOTS:
100105 void synchronizeStates();
@@ -107,8 +112,13 @@ private:
107112 void onCategoriesSwarmNameChanged(const std::string&);
108113 void onCategoriesModelChanged(unity::glib::Object<DeeModel>);
109114 void onCategoriesChanged(const unity::dash::Categories::Ptr&);
110−
115+ unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
116+ const QVariant &category, const QVariant &result_type,
117+ const QVariant &mimetype, const QVariant &title,
118+ const QVariant &comment, const QVariant &dnd_uri,
119+ const QVariant &metadata);
111120 void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&);
121+ void onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview);
112122 void fallbackActivate(const QString& uri);
113123
114124 unity::dash::Scope::Ptr m_unityScope;