on xenial help sign in
Bindings for preview and activation requests.

Approved by PS Jenkins bot, Ying-Chun Liu, Albert Astals Cid.

commitc3c1984f79d7853739d56ebca3f134f3c703d69f authorPawel Stolowski <pawel.stolowski@canonical.com> dateWed 3 Jul 2013, 15:18 (13 years ago) parentf9e9a80115060e
25 files changed+1488−14
debian/control+1 plugins/Unity/CMakeLists.txt+8 plugins/Unity/applicationpreview.cpp+96 plugins/Unity/applicationpreview.h+66 plugins/Unity/genericpreview.cpp+26 plugins/Unity/genericpreview.h+40 plugins/Unity/moviepreview.cpp+67 plugins/Unity/moviepreview.h+60 plugins/Unity/musicpreview.cpp+54 plugins/Unity/musicpreview.h+62 plugins/Unity/plugin.cpp+6 plugins/Unity/preview.cpp+173 plugins/Unity/preview.h+80 plugins/Unity/previewaction.cpp+75 plugins/Unity/previewaction.h+71 plugins/Unity/previewinfohint.cpp+67 plugins/Unity/previewinfohint.h+58 plugins/Unity/scope.cpp+79−11 plugins/Unity/scope.h+20−3 plugins/Unity/variantutils.cpp+158 plugins/Unity/variantutils.h+34 tests/plugins/CMakeLists.txt+1 tests/plugins/Unity/CMakeLists.txt+38 tests/plugins/Unity/previewbindingstest.cpp+114 tests/plugins/Unity/previewbindingstest.h+34
debian/control+1
@@ -13,6 +13,7 @@ Build-Depends: cmake,
1313 libpulse-dev,
1414 libqt5v8-5-private-dev,
1515 libunity-core-6.0-dev (<< 7.80),
16+ libunity-dev (>= 7.0.3),
1617 libusermetricsoutput1-dev,
1718 libxcb1-dev,
1819 pkg-config,
plugins/Unity/CMakeLists.txt+8
@@ -20,6 +20,14 @@ 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
28+ previewaction.cpp
29+ previewinfohint.cpp
30+ variantutils.cpp
2331 )
2432
2533add_library(Unity-qml MODULE
plugins/Unity/applicationpreview.cppnew file+96
@@ -0,0 +1,96 @@
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+#include <QDebug>
24+
25+ApplicationPreview::ApplicationPreview(QObject *parent):
26+ Preview(parent),
27+ m_unityAppPreview(nullptr)
28+{
29+}
30+
31+QString ApplicationPreview::lastUpdate() const
32+{
33+ if (m_unityAppPreview) {
34+ return QString::fromStdString(m_unityAppPreview->last_update());
35+ } else {
36+ qWarning() << "Preview not set";
37+ }
38+ return QString();
39+}
40+
41+QString ApplicationPreview::copyright() const
42+{
43+ if (m_unityAppPreview) {
44+ return QString::fromStdString(m_unityAppPreview->copyright());
45+ } else {
46+ qWarning() << "Preview not set";
47+ }
48+ return QString();
49+}
50+
51+QString ApplicationPreview::license() const
52+{
53+ if (m_unityAppPreview) {
54+ return QString::fromStdString(m_unityAppPreview->license());
55+ } else {
56+ qWarning() << "Preview not set";
57+ }
58+ return QString();
59+}
60+
61+QString ApplicationPreview::appIcon() const
62+{
63+ if (m_unityAppPreview) {
64+ return QString::fromUtf8(g_icon_to_string(m_unityAppPreview->app_icon()));
65+ } else {
66+ qWarning() << "Preview not set";
67+ }
68+ return QString();
69+}
70+
71+float ApplicationPreview::rating() const
72+{
73+ if (m_unityAppPreview) {
74+ return m_unityAppPreview->rating();
75+ } else {
76+ qWarning() << "Preview not set";
77+ }
78+ return 0.0f;
79+}
80+
81+unsigned int ApplicationPreview::numRatings() const
82+{
83+ if (m_unityAppPreview) {
84+ return m_unityAppPreview->num_ratings();
85+ } else {
86+ qWarning() << "Preview not set";
87+ }
88+ return 0;
89+}
90+
91+void ApplicationPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
92+{
93+ m_unityAppPreview = std::dynamic_pointer_cast<unity::dash::ApplicationPreview>(unityPreview);
94+
95+ Q_EMIT previewChanged();
96+}
plugins/Unity/applicationpreview.hnew file+66
@@ -0,0 +1,66 @@
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 Q_DECL_EXPORT ApplicationPreview: public Preview
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(QString lastUpdate READ lastUpdate NOTIFY previewChanged)
38+ Q_PROPERTY(QString copyright READ copyright NOTIFY previewChanged)
39+ Q_PROPERTY(QString license READ license NOTIFY previewChanged)
40+ Q_PROPERTY(QString appIcon READ appIcon NOTIFY previewChanged)
41+ Q_PROPERTY(float rating READ rating NOTIFY previewChanged)
42+ Q_PROPERTY(unsigned int numRatings READ numRatings NOTIFY previewChanged)
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+Q_SIGNALS:
55+ void previewChanged();
56+
57+protected:
58+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
59+
60+private:
61+ unity::dash::ApplicationPreview::Ptr m_unityAppPreview;
62+};
63+
64+Q_DECLARE_METATYPE(ApplicationPreview *)
65+
66+#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+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 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+Q_DECLARE_METATYPE(GenericPreview *)
39+
40+#endif
plugins/Unity/moviepreview.cppnew file+67
@@ -0,0 +1,67 @@
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+// Qt
24+#include <QDebug>
25+
26+MoviePreview::MoviePreview(QObject *parent):
27+ Preview(parent),
28+ m_unityMoviePreview(nullptr)
29+{
30+}
31+
32+QString MoviePreview::year() const
33+{
34+ if (m_unityMoviePreview) {
35+ return QString::fromStdString(m_unityMoviePreview->year());
36+ } else {
37+ qWarning() << "Preview not set";
38+ }
39+ return QString();
40+}
41+
42+float MoviePreview::rating() const
43+{
44+ if (m_unityMoviePreview) {
45+ return m_unityMoviePreview->rating();
46+ } else {
47+ qWarning() << "Preview not set";
48+ }
49+ return 0.0f;
50+}
51+
52+unsigned int MoviePreview::numRatings() const
53+{
54+ if (m_unityMoviePreview) {
55+ return m_unityMoviePreview->num_ratings();
56+ } else {
57+ qWarning() << "Preview not set";
58+ }
59+ return 0;
60+}
61+
62+void MoviePreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
63+{
64+ m_unityMoviePreview = std::dynamic_pointer_cast<unity::dash::MoviePreview>(unityPreview);
65+
66+ Q_EMIT previewChanged();
67+}
plugins/Unity/moviepreview.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 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 Q_DECL_EXPORT MoviePreview: public Preview
34+{
35+ Q_OBJECT
36+
37+ Q_PROPERTY(QString year READ year NOTIFY previewChanged)
38+ Q_PROPERTY(float rating READ rating NOTIFY previewChanged)
39+ Q_PROPERTY(unsigned int numRatings READ numRatings NOTIFY previewChanged)
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+Q_SIGNALS:
49+ void previewChanged();
50+
51+protected:
52+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
53+
54+private:
55+ unity::dash::MoviePreview::Ptr m_unityMoviePreview;
56+};
57+
58+Q_DECLARE_METATYPE(MoviePreview *)
59+
60+#endif
plugins/Unity/musicpreview.cppnew 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+#include "musicpreview.h"
21+#include <QDebug>
22+
23+// dee-qt
24+#include "deelistmodel.h"
25+
26+MusicPreview::MusicPreview(QObject *parent):
27+ Preview(parent),
28+ m_unityMusicPreview(nullptr)
29+{
30+ m_tracks = new DeeListModel(this);
31+}
32+
33+void MusicPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
34+{
35+ m_unityMusicPreview = std::dynamic_pointer_cast<unity::dash::MusicPreview>(unityPreview);
36+ m_tracks->setModel(m_unityMusicPreview->GetTracksModel()->model());
37+ m_unityMusicPreview->GetTracksModel()->model.changed.connect(sigc::mem_fun(this, &MusicPreview::onTracksModelChanged));
38+
39+ Q_EMIT previewChanged();
40+ Q_EMIT tracksChanged();
41+}
42+
43+DeeListModel* MusicPreview::tracks() const
44+{
45+ if (m_unityMusicPreview == nullptr) {
46+ qWarning() << "Preview not set";
47+ }
48+ return m_tracks;
49+}
50+
51+void MusicPreview::onTracksModelChanged(unity::glib::Object<DeeModel> /* model */)
52+{
53+ m_tracks->setModel(m_unityMusicPreview->GetTracksModel()->model());
54+}
plugins/Unity/musicpreview.hnew file+62
@@ -0,0 +1,62 @@
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+// libunity-core
31+#include <UnityCore/MusicPreview.h>
32+
33+class DeeListModel;
34+
35+class Q_DECL_EXPORT MusicPreview: public Preview
36+{
37+ Q_OBJECT
38+
39+ Q_PROPERTY(DeeListModel* tracks READ tracks NOTIFY tracksChanged)
40+
41+public:
42+ explicit MusicPreview(QObject *parent = 0);
43+
44+ DeeListModel* tracks() const;
45+
46+Q_SIGNALS:
47+ void tracksChanged();
48+
49+protected:
50+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
51+
52+private Q_SLOTS:
53+ void onTracksModelChanged(unity::glib::Object<DeeModel> model);
54+
55+private:
56+ unity::dash::MusicPreview::Ptr m_unityMusicPreview;
57+ DeeListModel *m_tracks;
58+};
59+
60+Q_DECLARE_METATYPE(MusicPreview *)
61+
62+#endif
plugins/Unity/plugin.cpp+6
@@ -24,6 +24,9 @@
2424#include "plugin.h"
2525
2626// local
27+#include "preview.h"
28+#include "previewaction.h"
29+#include "previewinfohint.h"
2730#include "scope.h"
2831#include "scopes.h"
2932#include "categories.h"
@@ -40,6 +43,9 @@ static const char* DBUS_SERVICE = "com.canonical.Shell.BottomBarVisibilityCommun
4043void UnityPlugin::registerTypes(const char *uri)
4144{
4245 Q_ASSERT(uri == QLatin1String("Unity"));
46+ qmlRegisterUncreatableType<Preview>(uri, 0, 1, "Preview", "Can't create Preview object in QML.");
47+ qmlRegisterUncreatableType<PreviewAction>(uri, 0, 1, "PreviewAction", "Can't create PreviewAction object in QML.");
48+ qmlRegisterUncreatableType<PreviewInfoHint>(uri, 0, 1, "PreviewInfoHint", "Can't create PreviewInfoHint object in QML.");
4349 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
4450 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
4551 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
plugins/Unity/preview.cppnew file+173
@@ -0,0 +1,173 @@
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 "previewaction.h"
23+#include "previewinfohint.h"
24+#include "genericpreview.h"
25+#include "applicationpreview.h"
26+#include "moviepreview.h"
27+#include "musicpreview.h"
28+#include "variantutils.h"
29+
30+// Qt
31+#include <QDebug>
32+#include <QtAlgorithms>
33+
34+#include <UnityCore/GenericPreview.h>
35+#include <UnityCore/ApplicationPreview.h>
36+#include <UnityCore/MoviePreview.h>
37+#include <UnityCore/MusicPreview.h>
38+
39+Preview::Preview(QObject *parent):
40+ QObject(parent),
41+ m_unityPreview(nullptr)
42+{
43+}
44+
45+QString Preview::rendererName() const
46+{
47+ if (m_unityPreview) {
48+ return QString::fromStdString(m_unityPreview->renderer_name());
49+ } else {
50+ qWarning() << "Preview not set";
51+ }
52+ return QString();
53+}
54+
55+QString Preview::title() const
56+{
57+ if (m_unityPreview) {
58+ return QString::fromStdString(m_unityPreview->title());
59+ } else {
60+ qWarning() << "Preview not set";
61+ }
62+ return QString();
63+}
64+
65+QString Preview::subtitle () const
66+{
67+ if (m_unityPreview) {
68+ return QString::fromStdString(m_unityPreview->subtitle());
69+ } else {
70+ qWarning() << "Preview not set";
71+ }
72+ return QString();
73+}
74+
75+QString Preview::description() const
76+{
77+ if (m_unityPreview) {
78+ return QString::fromStdString(m_unityPreview->description());
79+ } else {
80+ qWarning() << "Preview not set";
81+ }
82+ return QString();
83+}
84+
85+QVariant Preview::actions()
86+{
87+ return QVariant::fromValue(m_actions);
88+}
89+
90+QVariant Preview::infoHints()
91+{
92+ return QVariant::fromValue(m_infoHints);
93+}
94+
95+QString Preview::image() const
96+{
97+ if (m_unityPreview) {
98+ return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
99+ } else {
100+ qWarning() << "Preview not set";
101+ }
102+ return QString::null;
103+}
104+
105+QString Preview::imageSourceUri() const
106+{
107+ if (m_unityPreview) {
108+ return QString::fromStdString(m_unityPreview->image_source_uri());
109+ } else {
110+ qWarning() << "Preview not set";
111+ }
112+ return QString::null;
113+}
114+
115+Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
116+{
117+ Preview* preview = nullptr;
118+
119+ if (dynamic_cast<unity::dash::GenericPreview *>(unityPreview.get()) != nullptr) {
120+ preview = new GenericPreview();
121+ } else if (dynamic_cast<unity::dash::MusicPreview *>(unityPreview.get()) != nullptr) {
122+ preview = new MusicPreview();
123+ } else if (dynamic_cast<unity::dash::MoviePreview *>(unityPreview.get()) != nullptr) {
124+ preview = new MoviePreview();
125+ } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
126+ preview = new ApplicationPreview();
127+ } else {
128+ qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
129+ preview = new GenericPreview();
130+ }
131+
132+ preview->setUnityPreviewBase(unityPreview);
133+ preview->setUnityPreview(unityPreview);
134+
135+ return preview;
136+}
137+
138+void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
139+{
140+ m_unityPreview = unityPreview;
141+
142+ qDeleteAll(m_infoHints);
143+ m_infoHints.clear();
144+ qDeleteAll(m_actions);
145+ m_actions.clear();
146+
147+ for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
148+ auto hint = new PreviewInfoHint(this);
149+ hint->setUnityInfoHint(unityInfoHint);
150+ m_infoHints.append(hint);
151+ }
152+
153+ for (auto unityAction: m_unityPreview->GetActions()) {
154+ auto action = new PreviewAction(this);
155+ action->setUnityAction(unityAction);
156+ m_actions.append(action);
157+ }
158+}
159+
160+void Preview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
161+{
162+ // default implementation does nothing
163+}
164+
165+void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
166+{
167+ if (m_unityPreview) {
168+ auto unityHints = convertToHintsMap(hints);
169+ m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
170+ } else {
171+ qWarning() << "Preview not set";
172+ }
173+}
plugins/Unity/preview.hnew file+80
@@ -0,0 +1,80 @@
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+#include <QList>
28+
29+// libunity-core
30+#include <UnityCore/Preview.h>
31+
32+// local
33+#include "previewaction.h"
34+
35+class Q_DECL_EXPORT Preview : public QObject
36+{
37+ Q_OBJECT
38+
39+ Q_PROPERTY(QString rendererName READ rendererName NOTIFY previewChanged)
40+ Q_PROPERTY(QString title READ title NOTIFY previewChanged)
41+ Q_PROPERTY(QString subtitle READ subtitle NOTIFY previewChanged)
42+ Q_PROPERTY(QString description READ description NOTIFY previewChanged)
43+ Q_PROPERTY(QVariant actions READ actions NOTIFY previewChanged)
44+ Q_PROPERTY(QVariant infoHints READ infoHints NOTIFY previewChanged)
45+ Q_PROPERTY(QString image READ image NOTIFY previewChanged)
46+ Q_PROPERTY(QString imageSourceUri READ imageSourceUri NOTIFY previewChanged)
47+
48+public:
49+ explicit Preview(QObject *parent = 0);
50+ static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
51+
52+ QString rendererName() const;
53+ QString title() const;
54+ QString subtitle() const;
55+ QString description() const;
56+ QVariant actions();
57+ QVariant infoHints();
58+ QString image() const;
59+ QString imageSourceUri() const;
60+
61+ Q_INVOKABLE void execute(const QString& actionId, const QHash<QString, QVariant>& hints);
62+
63+Q_SIGNALS:
64+ void previewChanged();
65+
66+protected:
67+ virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
68+
69+ unity::dash::Preview::Ptr m_unityPreview;
70+
71+private:
72+ void setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview);
73+
74+ QList<QObject *> m_actions;
75+ QList<QObject *> m_infoHints;
76+};
77+
78+Q_DECLARE_METATYPE(Preview *)
79+
80+#endif
plugins/Unity/previewaction.cppnew file+75
@@ -0,0 +1,75 @@
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 "previewaction.h"
21+
22+PreviewAction::PreviewAction(QObject *parent)
23+ : QObject(parent),
24+ m_unityAction(nullptr)
25+{
26+}
27+
28+void PreviewAction::setUnityAction(unity::dash::Preview::ActionPtr unityAction)
29+{
30+ m_unityAction = unityAction;
31+
32+ Q_EMIT previewActionChanged();
33+}
34+
35+QString PreviewAction::id() const
36+{
37+ if (m_unityAction)
38+ return QString::fromStdString(m_unityAction->id);
39+ return QString();
40+}
41+
42+QString PreviewAction::displayName() const
43+{
44+ if (m_unityAction)
45+ return QString::fromStdString(m_unityAction->display_name);
46+ return QString();
47+}
48+
49+QString PreviewAction::iconHint() const
50+{
51+ if (m_unityAction)
52+ return QString::fromStdString(m_unityAction->icon_hint);
53+ return QString();
54+}
55+
56+QString PreviewAction::extraText() const
57+{
58+ if (m_unityAction)
59+ return QString::fromStdString(m_unityAction->extra_text);
60+ return QString();
61+}
62+
63+QString PreviewAction::activationUri() const
64+{
65+ if (m_unityAction)
66+ return QString::fromStdString(m_unityAction->activation_uri);
67+ return QString();
68+}
69+
70+LayoutHint PreviewAction::layoutHint() const
71+{
72+ if (m_unityAction)
73+ return static_cast<LayoutHint>(m_unityAction->layout_hint);
74+ return LayoutHint::None;
75+}
plugins/Unity/previewaction.hnew file+71
@@ -0,0 +1,71 @@
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 PREVIEWACTION_H
21+#define PREVIEWACTION_H
22+
23+// Qt
24+#include <QObject>
25+#include <QList>
26+
27+// libuinity-core
28+#include <UnityCore/Preview.h>
29+
30+enum LayoutHint // keep in sync with unty::dash::LayoutHint
31+{
32+ None,
33+ Left,
34+ Right,
35+ Top,
36+ Bottom
37+};
38+
39+class PreviewAction : public QObject
40+{
41+ Q_OBJECT
42+
43+ Q_PROPERTY(QString id READ id NOTIFY previewActionChanged)
44+ Q_PROPERTY(QString displayName READ displayName NOTIFY previewActionChanged)
45+ Q_PROPERTY(QString iconHint READ iconHint NOTIFY previewActionChanged)
46+ Q_PROPERTY(QString extraText READ extraText NOTIFY previewActionChanged)
47+ Q_PROPERTY(QString activationUri READ activationUri NOTIFY previewActionChanged)
48+ Q_PROPERTY(LayoutHint layoutHint READ layoutHint NOTIFY previewActionChanged)
49+
50+public:
51+ explicit PreviewAction(QObject *parent = 0);
52+ void setUnityAction(unity::dash::Preview::ActionPtr unityAction);
53+
54+ QString id() const;
55+ QString displayName() const;
56+ QString iconHint() const;
57+ QString extraText() const;
58+ QString activationUri() const;
59+ LayoutHint layoutHint() const;
60+
61+Q_SIGNALS:
62+ void previewActionChanged();
63+
64+private:
65+ unity::dash::Preview::ActionPtr m_unityAction;
66+};
67+
68+Q_DECLARE_METATYPE(PreviewAction *)
69+Q_DECLARE_METATYPE(LayoutHint)
70+
71+#endif
plugins/Unity/previewinfohint.cppnew file+67
@@ -0,0 +1,67 @@
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 "previewinfohint.h"
22+#include "variantutils.h"
23+
24+PreviewInfoHint::PreviewInfoHint(QObject *parent):
25+ QObject(parent),
26+ m_unityInfoHint(nullptr)
27+{
28+}
29+
30+void PreviewInfoHint::setUnityInfoHint(unity::dash::Preview::InfoHintPtr unityInfoHint)
31+{
32+ m_unityInfoHint = unityInfoHint;
33+
34+ Q_EMIT previewInfoHintChanged();
35+}
36+
37+QString PreviewInfoHint::id() const
38+{
39+ if (m_unityInfoHint) {
40+ return QString::fromStdString(m_unityInfoHint->id);
41+ }
42+ return QString();
43+}
44+
45+QString PreviewInfoHint::displayName() const
46+{
47+ if (m_unityInfoHint) {
48+ return QString::fromStdString(m_unityInfoHint->display_name);
49+ }
50+ return QString();
51+}
52+
53+QString PreviewInfoHint::iconHint() const
54+{
55+ if (m_unityInfoHint) {
56+ return QString::fromStdString(m_unityInfoHint->icon_hint);
57+ }
58+ return QString();
59+}
60+
61+QVariant PreviewInfoHint::value() const
62+{
63+ if (m_unityInfoHint) {
64+ return QVariantFromGVariant(m_unityInfoHint->value);
65+ }
66+ return QVariant();
67+}
plugins/Unity/previewinfohint.hnew file+58
@@ -0,0 +1,58 @@
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 PREVIEWINFOHINT_H
21+#define PREVIEWINFOHINT_H
22+
23+// Qt
24+#include <QObject>
25+#include <QString>
26+#include <QVariant>
27+
28+// libunity-core
29+#include <UnityCore/Preview.h>
30+
31+class PreviewInfoHint : public QObject
32+{
33+ Q_OBJECT
34+
35+ Q_PROPERTY(QString id READ id NOTIFY previewInfoHintChanged)
36+ Q_PROPERTY(QString displayName READ displayName NOTIFY previewInfoHintChanged)
37+ Q_PROPERTY(QString iconHint READ iconHint NOTIFY previewInfoHintChanged)
38+ Q_PROPERTY(QVariant value READ value NOTIFY previewInfoHintChanged)
39+
40+public:
41+ explicit PreviewInfoHint(QObject *parent = 0);
42+ void setUnityInfoHint(unity::dash::Preview::InfoHintPtr unityInfoHint);
43+
44+ QString id() const;
45+ QString displayName() const;
46+ QString iconHint() const;
47+ QVariant value() const;
48+
49+Q_SIGNALS:
50+ void previewInfoHintChanged();
51+
52+private:
53+ unity::dash::Preview::InfoHintPtr m_unityInfoHint;
54+};
55+
56+Q_DECLARE_METATYPE(PreviewInfoHint *)
57+
58+#endif
plugins/Unity/scope.cpp+79−11
@@ -19,12 +19,19 @@
1919
2020// Self
2121#include "scope.h"
22+
23+// local
2224#include "categories.h"
25+#include "preview.h"
26+#include "variantutils.h"
2327
2428// Qt
2529#include <QUrl>
2630#include <QDebug>
2731#include <QtGui/QDesktopServices>
32+#include <QQmlEngine>
33+
34+#include <UnityCore/Variant.h>
2835
2936#include <libintl.h>
3037
@@ -118,21 +125,80 @@ void Scope::setNoResultsHint(const QString& hint) {
118125 }
119126}
120127
121−void Scope::activate(const QString& /*uri*/)
128+
129+unity::dash::LocalResult Scope::createLocalResult(const QVariant &uri, const QVariant &icon_hint,
130+ const QVariant &category, const QVariant &result_type,
131+ const QVariant &mimetype, const QVariant &title,
132+ const QVariant &comment, const QVariant &dnd_uri,
133+ const QVariant &metadata)
134+{
135+ unity::dash::LocalResult res;
136+ res.uri = uri.toString().toStdString();
137+ res.icon_hint = icon_hint.toString().toStdString();
138+ res.category_index = category.toUInt();
139+ res.result_type = result_type.toUInt();
140+ res.mimetype = mimetype.toString().toStdString();
141+ res.name = title.toString().toStdString();
142+ res.comment = comment.toString().toStdString();
143+ res.dnd_uri = dnd_uri.toString().toStdString();
144+ res.hints = convertToHintsMap(metadata);
145+
146+ return res;
147+}
148+
149+// FIXME: Change to use row index.
150+void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
151+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
152+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
153+{
154+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
155+ m_unityScope->Activate(res);
156+}
157+
158+// FIXME: Change to use row index.
159+void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
160+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
161+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
122162{
123− // TODO:
124− // we need to create unity::dash::LocalResult (see UnityCore/Result.h) and pass it to Activate;
125− // this requires entire row from the model, so we need row index rather than uri.
126− // m_unityScope->Activate(QByteArray::fromPercentEncoding(uri.toUtf8()).constData());
163+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
164+ m_unityScope->Preview(res);
127165}
128166
129−void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
167+void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
130168{
131− if (type == unity::dash::NOT_HANDLED) {
132− fallbackActivate(QString::fromStdString(result.uri));
169+ // note: we will not get called on SHOW_PREVIEW, instead UnityCore will signal preview_ready.
170+ switch (type)
171+ {
172+ case unity::dash::NOT_HANDLED:
173+ fallbackActivate(QString::fromStdString(result.uri));
174+ break;
175+ case unity::dash::SHOW_DASH:
176+ Q_EMIT showDash();
177+ break;
178+ case unity::dash::HIDE_DASH:
179+ Q_EMIT hideDash();
180+ break;
181+ case unity::dash::GOTO_DASH_URI:
182+ if (hints.find("goto-uri") != hints.end()) {
183+ Q_EMIT gotoUri(QString::fromStdString(g_variant_get_string(hints.at("goto-uri"), nullptr)));
184+ } else {
185+ qWarning() << "Missing goto-uri hint for GOTO_DASH_URI activation reply";
186+ }
187+ break;
188+ default:
189+ qWarning() << "Unhandled activation response:" << type;
133190 }
134191}
135192
193+void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
194+{
195+ auto prv = Preview::newFromUnityPreview(preview);
196+ // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
197+ // passing it by value is not possible.
198+ QQmlEngine::setObjectOwnership(prv, QQmlEngine::JavaScriptOwnership);
199+ Q_EMIT previewReady(prv);
200+}
201+
136202void Scope::fallbackActivate(const QString& uri)
137203{
138204 /* FIXME: stripping all content before the first column because for some
@@ -161,10 +227,10 @@ void Scope::fallbackActivate(const QString& uri)
161227 return;
162228 }
163229
164− qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
165− qWarning() << "Trying to open" << tweakedUri;
230+ qDebug() << "Trying to open" << uri;
231+
166232 /* Try our luck */
167− QDesktopServices::openUrl(url);
233+ QDesktopServices::openUrl(uri); //url?
168234}
169235
170236void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
@@ -204,6 +270,8 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
204270 /* FIXME: signal should be forwarded instead of calling the handler directly */
205271 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
206272
273+ m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
274+
207275 /* Synchronize local states with m_unityScope right now and whenever
208276 m_unityScope becomes connected */
209277 /* FIXME: should emit change notification signals for all properties */
plugins/Unity/scope.h+20−3
@@ -33,6 +33,7 @@
3333#include "deelistmodel.h"
3434
3535class Categories;
36+class Preview;
3637
3738class Scope : public QObject
3839{
@@ -73,7 +74,12 @@ public:
7374 void setSearchQuery(const QString& search_query);
7475 void setNoResultsHint(const QString& hint);
7576
76− Q_INVOKABLE void activate(const QString& uri);
77+ Q_INVOKABLE void activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
78+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
79+ 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);
7783 void setUnityScope(const unity::dash::Scope::Ptr& scope);
7884 unity::dash::Scope::Ptr unityScope() const;
7985
@@ -94,6 +100,12 @@ Q_SIGNALS:
94100 void searchQueryChanged();
95101 void noResultsHintChanged();
96102
103+ // signals triggered by activate(..) or preview(..) requests.
104+ void previewReady(Preview *preview);
105+ void showDash();
106+ void hideDash();
107+ void gotoUri(const QString &uri);
108+
97109private Q_SLOTS:
98110 void synchronizeStates();
99111 void onSearchFinished(const std::string &, unity::glib::HintsMap const &);
@@ -105,8 +117,13 @@ private:
105117 void onCategoriesSwarmNameChanged(const std::string&);
106118 void onCategoriesModelChanged(unity::glib::Object<DeeModel>);
107119 void onCategoriesChanged(const unity::dash::Categories::Ptr&);
108−
109− void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&);
120+ unity::dash::LocalResult createLocalResult(const QVariant &uri, const QVariant &icon_hint,
121+ const QVariant &category, const QVariant &result_type,
122+ const QVariant &mimetype, const QVariant &title,
123+ const QVariant &comment, const QVariant &dnd_uri,
124+ const QVariant &metadata);
125+ void onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints);
126+ void onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview);
110127 void fallbackActivate(const QString& uri);
111128
112129 unity::dash::Scope::Ptr m_unityScope;
plugins/Unity/variantutils.cppnew file+158
@@ -0,0 +1,158 @@
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 "variantutils.h"
21+
22+/* Returns floating ref */
23+GVariant* GVariantFromQVariant(const QVariant &var)
24+{
25+ GVariant *gv = nullptr;
26+
27+ switch (var.type()) {
28+ case QVariant::String:
29+ gv = g_variant_new_string(var.toString().toUtf8());
30+ break;
31+ case QVariant::UInt:
32+ gv = g_variant_new_uint32(var.toUInt());
33+ break;
34+ case QVariant::Int:
35+ gv = g_variant_new_int32(var.toInt());
36+ break;
37+ case QVariant::LongLong:
38+ gv = g_variant_new_int64(var.toLongLong());
39+ break;
40+ case QVariant::ULongLong:
41+ gv = g_variant_new_uint64(var.toULongLong());
42+ break;
43+ case QVariant::Double:
44+ gv = g_variant_new_double(var.toDouble());
45+ break;
46+ case QVariant::Bool:
47+ gv = g_variant_new_boolean(var.toBool());
48+ break;
49+ case QVariant::Hash: {
50+ const auto hash = var.toHash();
51+ GVariant **children = new GVariant*[hash.size()];
52+ int cnt = 0;
53+ QHash<QString, QVariant>::const_iterator it = hash.constBegin();
54+ while (it != hash.constEnd()) {
55+ GVariant *key = g_variant_new_string(it.key().toUtf8());
56+ children[cnt++] = g_variant_new_dict_entry(key, g_variant_new_variant(GVariantFromQVariant(it.value())));
57+ ++it;
58+ }
59+ gv = g_variant_new_array(G_VARIANT_TYPE("{sv}"), children, hash.size());
60+ delete [] children;
61+ break;
62+ }
63+ default:
64+ break;
65+ }
66+ return gv;
67+}
68+
69+// implementation of this conversion taken from libdee-qt private utility function.
70+QVariant QVariantFromGVariant(GVariant *value)
71+{
72+ /* We need to special-case a{sv} here as G_VARIANT_CLASS_ARRAY handles simple arrays;
73+ we need to create QVariantHash, not a list */
74+ if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARDICT)) {
75+ const gsize nChildren = g_variant_n_children(value);
76+ QVariantHash hash;
77+ for (gsize i = 0; i < nChildren; ++i)
78+ {
79+ GVariant* dict_entry = g_variant_get_child_value(value, i);
80+
81+ gchar* dict_key;
82+ GVariant *dict_var;
83+ g_variant_get(dict_entry, "{&sv}", &dict_key, &dict_var);
84+ hash.insert(QString::fromUtf8(dict_key), QVariantFromGVariant(dict_var));
85+ g_variant_unref(dict_var);
86+ g_variant_unref(dict_entry);
87+ }
88+ return hash;
89+ }
90+
91+ switch (g_variant_classify(value)) {
92+ case G_VARIANT_CLASS_BOOLEAN:
93+ return QVariant((bool) g_variant_get_boolean(value));
94+ case G_VARIANT_CLASS_BYTE:
95+ return QVariant((uchar) g_variant_get_byte(value));
96+ case G_VARIANT_CLASS_INT16:
97+ return QVariant((qint16) g_variant_get_int16(value));
98+ case G_VARIANT_CLASS_UINT16:
99+ return QVariant((quint16) g_variant_get_uint16(value));
100+ case G_VARIANT_CLASS_INT32:
101+ return QVariant((qint32) g_variant_get_int32(value));
102+ case G_VARIANT_CLASS_UINT32:
103+ return QVariant((quint32) g_variant_get_uint32(value));
104+ case G_VARIANT_CLASS_INT64:
105+ return QVariant((qint64) g_variant_get_int64(value));
106+ case G_VARIANT_CLASS_UINT64:
107+ return QVariant((quint64) g_variant_get_uint64(value));
108+ case G_VARIANT_CLASS_DOUBLE:
109+ return QVariant(g_variant_get_double(value));
110+ case G_VARIANT_CLASS_STRING:
111+ return QVariant(QString::fromUtf8(g_variant_get_string(value, NULL)));
112+ case G_VARIANT_CLASS_ARRAY:
113+ case G_VARIANT_CLASS_TUPLE:
114+ {
115+ const gsize nChildren = g_variant_n_children(value);
116+ QList<QVariant> array;
117+ for (gsize i = 0; i < nChildren; ++i)
118+ {
119+ GVariant* gvariant = g_variant_get_child_value(value, i);
120+ array << QVariantFromGVariant(gvariant);
121+ g_variant_unref(gvariant);
122+ }
123+ return array;
124+ }
125+ default:
126+ /* Fallback on an empty QVariant.
127+ FIXME: Missing conversion of following GVariant types:
128+ - G_VARIANT_CLASS_HANDLE
129+ - G_VARIANT_CLASS_OBJECT_PATH
130+ - G_VARIANT_CLASS_SIGNATURE
131+ - G_VARIANT_CLASS_VARIANT
132+ - G_VARIANT_CLASS_MAYBE
133+ - G_VARIANT_CLASS_DICT_ENTRY
134+ */
135+ return QVariant();
136+ }
137+}
138+
139+unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val)
140+{
141+ unity::glib::HintsMap hintsMap;
142+ QHash<QString, QVariant>::const_iterator it = val.constBegin();
143+ while (it != val.constEnd()) {
144+ hintsMap[it.key().toStdString()] = GVariantFromQVariant(it.value());
145+ ++it;
146+ }
147+ return hintsMap;
148+}
149+
150+unity::glib::HintsMap convertToHintsMap(const QVariant &var)
151+{
152+ if (var.type() == QVariant::Hash) {
153+ unity::glib::HintsMap hintsMap;
154+ const auto hash = var.toHash();
155+ return convertToHintsMap(hash);
156+ }
157+ return unity::glib::HintsMap();
158+}
plugins/Unity/variantutils.hnew file+34
@@ -0,0 +1,34 @@
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 VARIANTUTILS_H
21+#define VARIANTUTILS_H
22+
23+#include <glib.h>
24+#include <QVariant>
25+
26+// libunity-core
27+#include <UnityCore/Variant.h>
28+
29+GVariant* GVariantFromQVariant(const QVariant &value);
30+QVariant QVariantFromGVariant(GVariant *value);
31+unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val);
32+unity::glib::HintsMap convertToHintsMap(const QVariant &var);
33+
34+#endif
tests/plugins/CMakeLists.txt+1
@@ -1,3 +1,4 @@
11add_subdirectory(Utils)
22add_subdirectory(Ubuntu)
3+add_subdirectory(Unity)
34add_subdirectory(ListViewWithPageHeader)
tests/plugins/Unity/CMakeLists.txtnew file+38
@@ -0,0 +1,38 @@
1+pkg_check_modules(UNITYCORE REQUIRED unity-core-6.0)
2+pkg_check_modules(LIBUNITYPROTO REQUIRED unity-protocol-private)
3+
4+include_directories(
5+ ${Unity-qml_SOURCE_DIR}
6+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../plugins/Unity
7+ ${CMAKE_CURRENT_BINARY_DIR}
8+ ${LIBUNITYPROTO_INCLUDE_DIRS}
9+ ${UNITYCORE_INCLUDE_DIRS}
10+ )
11+
12+macro(run_tests)
13+ set(_test_list "")
14+ foreach(_test ${ARGN})
15+ set(testCommand
16+ ${CMAKE_CURRENT_BINARY_DIR}/${_test}Exec
17+ -o ${CMAKE_BINARY_DIR}/${_test}.xml,xunitxml
18+ -o -,txt)
19+ add_test(NAME test${CLASSNAME}${_test} COMMAND ${testCommand})
20+ add_custom_target(${_test} ${testCommand})
21+ add_executable(${_test}Exec ${_test}.cpp previewbindingstest.cpp)
22+ qt5_use_modules(${_test}Exec Test Core Qml)
23+ set_tests_properties(test${CLASSNAME}${_test}
24+ PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Unity:${LIBUNITYPROTO_LIBRARY_DIRS})
25+
26+ target_link_libraries(${_test}Exec
27+ Unity-qml
28+ ${UNITYCORE_LDFLAGS}
29+ ${LIBUNITYPROTO_LDFLAGS}
30+ )
31+
32+ set(_test_list "${_test_list};${_test}")
33+ endforeach()
34+endmacro(run_tests)
35+
36+run_tests(
37+ previewbindingstest
38+ )
tests/plugins/Unity/previewbindingstest.cppnew file+114
@@ -0,0 +1,114 @@
1+/*
2+ * Copyright (C) 2011, 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+#include "previewbindingstest.h"
18+#include <QTest>
19+
20+#include <UnityCore/Preview.h>
21+#include <UnityCore/GLibWrapper.h>
22+#include <unity-protocol.h>
23+
24+#include "genericpreview.h"
25+#include "applicationpreview.h"
26+#include "moviepreview.h"
27+#include "musicpreview.h"
28+
29+void PreviewBindingsTest::initTestCase()
30+{
31+}
32+
33+void PreviewBindingsTest::testGenericPreview()
34+{
35+ auto raw_preview = (GObject *)unity_protocol_generic_preview_new();
36+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Metallica");
37+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Ride The Lightning");
38+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
39+ unity::glib::Object<GObject> gen_prv(raw_preview);
40+
41+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
42+ auto prv = Preview::newFromUnityPreview(core_prv);
43+
44+ QCOMPARE(prv != nullptr, true);
45+ QCOMPARE(prv->title(), QString("Metallica"));
46+ QCOMPARE(prv->subtitle(), QString("Ride The Lightning"));
47+ QCOMPARE(prv->description(), QString("Lorem ipsum dolor sit amet"));
48+}
49+
50+void PreviewBindingsTest::testApplicationPreview()
51+{
52+ auto raw_preview = (GObject *)unity_protocol_application_preview_new();
53+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Firefox");
54+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Web Browser");
55+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
56+ unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(raw_preview), "GPL");
57+ unity_protocol_application_preview_set_rating(UNITY_PROTOCOL_APPLICATION_PREVIEW(raw_preview), 0.5f);
58+ unity_protocol_application_preview_set_num_ratings(UNITY_PROTOCOL_APPLICATION_PREVIEW(raw_preview), 4);
59+ unity::glib::Object<GObject> gen_prv(raw_preview);
60+
61+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
62+ auto prv = Preview::newFromUnityPreview(core_prv);
63+ auto app_prv = dynamic_cast<ApplicationPreview*>(prv);
64+
65+ QCOMPARE(app_prv != nullptr, true);
66+ QCOMPARE(app_prv->title(), QString("Firefox"));
67+ QCOMPARE(app_prv->subtitle(), QString("Web Browser"));
68+ QCOMPARE(app_prv->description(), QString("Lorem ipsum dolor sit amet"));
69+ QCOMPARE(app_prv->license(), QString("GPL"));
70+ QCOMPARE(app_prv->rating(), 0.5f);
71+ QCOMPARE(app_prv->numRatings(), unsigned (4));
72+}
73+
74+void PreviewBindingsTest::testMoviePreview()
75+{
76+ auto raw_preview = (GObject *)unity_protocol_movie_preview_new();
77+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Blade Runner");
78+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Ridley Scott");
79+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
80+ unity_protocol_movie_preview_set_year(UNITY_PROTOCOL_MOVIE_PREVIEW(raw_preview), "1982");
81+ unity::glib::Object<GObject> gen_prv(raw_preview);
82+
83+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
84+ auto prv = Preview::newFromUnityPreview(core_prv);
85+ auto movie_prv = dynamic_cast<MoviePreview*>(prv);
86+
87+ QCOMPARE(movie_prv != nullptr, true);
88+ QCOMPARE(movie_prv->title(), QString("Blade Runner"));
89+ QCOMPARE(movie_prv->subtitle(), QString("Ridley Scott"));
90+ QCOMPARE(movie_prv->description(), QString("Lorem ipsum dolor sit amet"));
91+ QCOMPARE(movie_prv->year(), QString("1982"));
92+}
93+
94+void PreviewBindingsTest::testMusicPreview()
95+{
96+ auto raw_preview = (GObject *)unity_protocol_music_preview_new();
97+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Metallica");
98+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Death Magnetic");
99+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
100+ unity::glib::Object<GObject> gen_prv(raw_preview);
101+
102+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
103+ auto prv = Preview::newFromUnityPreview(core_prv);
104+ auto music_prv = dynamic_cast<MusicPreview*>(prv);
105+
106+ QCOMPARE(music_prv != nullptr, true);
107+ QCOMPARE(music_prv->title(), QString("Metallica"));
108+ QCOMPARE(music_prv->subtitle(), QString("Death Magnetic"));
109+ QCOMPARE(music_prv->description(), QString("Lorem ipsum dolor sit amet"));
110+}
111+
112+QTEST_MAIN(PreviewBindingsTest)
113+
114+#include "previewbindingstest.moc"
tests/plugins/Unity/previewbindingstest.hnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2011, 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 PREVIEWBINDINGSTEST_H
18+#define PREVIEWBINDINGSTEST_H
19+
20+#include <QObject>
21+
22+class PreviewBindingsTest : public QObject
23+{
24+ Q_OBJECT
25+
26+ private Q_SLOTS:
27+ void initTestCase();
28+ void testGenericPreview();
29+ void testApplicationPreview();
30+ void testMoviePreview();
31+ void testMusicPreview();
32+};
33+
34+#endif