on xenial help sign in
Bindings for SocialPreview.

Approved by PS Jenkins bot, Daniel d'Andrada.

commitc15365873253e4f92919c361f9135d6c01be1319 authorPawel Stolowski <pawel.stolowski@canonical.com> dateTue 9 Jul 2013, 14:01 (13 years ago) parenta2f3eb3490021c
12 files changed+400−59
plugins/Unity/CMakeLists.txt+2 plugins/Unity/genericpreview.cpp+5 plugins/Unity/genericpreview.h+6 plugins/Unity/plugin.cpp+2 plugins/Unity/preview.cpp+4 plugins/Unity/previewaction.h+1−1 plugins/Unity/socialpreview.cpp+83 plugins/Unity/socialpreview.h+63 plugins/Unity/socialpreviewcomment.cpp+63 plugins/Unity/socialpreviewcomment.h+57 tests/plugins/Unity/previewbindingstest.cpp+113−58 tests/plugins/Unity/previewbindingstest.h+1
plugins/Unity/CMakeLists.txt+2
@@ -29,6 +29,8 @@ set(QMLPLUGIN_SRC
2929 preview.cpp
3030 previewaction.cpp
3131 previewinfohint.cpp
32+ socialpreview.cpp
33+ socialpreviewcomment.cpp
3234 variantutils.cpp
3335 )
3436
plugins/Unity/genericpreview.cpp+5
@@ -24,3 +24,8 @@ GenericPreview::GenericPreview(QObject *parent):
2424 Preview(parent)
2525{
2626}
27+
28+void GenericPreview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
29+{
30+ Q_EMIT previewChanged();
31+}
plugins/Unity/genericpreview.h+6
@@ -33,6 +33,12 @@ class GenericPreview : public Preview
3333
3434public:
3535 explicit GenericPreview(QObject *parent = 0);
36+
37+Q_SIGNALS:
38+ void previewChanged();
39+
40+protected:
41+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
3642};
3743
3844Q_DECLARE_METATYPE(GenericPreview *)
plugins/Unity/plugin.cpp+2
@@ -27,6 +27,7 @@
2727#include "preview.h"
2828#include "previewaction.h"
2929#include "previewinfohint.h"
30+#include "socialpreviewcomment.h"
3031#include "scope.h"
3132#include "scopes.h"
3233#include "categories.h"
@@ -46,6 +47,7 @@ void UnityPlugin::registerTypes(const char *uri)
4647 qmlRegisterUncreatableType<Preview>(uri, 0, 1, "Preview", "Can't create Preview object in QML.");
4748 qmlRegisterUncreatableType<PreviewAction>(uri, 0, 1, "PreviewAction", "Can't create PreviewAction object in QML.");
4849 qmlRegisterUncreatableType<PreviewInfoHint>(uri, 0, 1, "PreviewInfoHint", "Can't create PreviewInfoHint object in QML.");
50+ qmlRegisterUncreatableType<SocialPreviewComment>(uri, 0, 1, "SocialPreviewComment", "Can't create SocialPreviewComment object in QML.");
4951 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
5052 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
5153 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
plugins/Unity/preview.cpp+4
@@ -25,6 +25,7 @@
2525#include "applicationpreview.h"
2626#include "moviepreview.h"
2727#include "musicpreview.h"
28+#include "socialpreview.h"
2829#include "variantutils.h"
2930
3031// Qt
@@ -35,6 +36,7 @@
3536#include <UnityCore/ApplicationPreview.h>
3637#include <UnityCore/MoviePreview.h>
3738#include <UnityCore/MusicPreview.h>
39+#include <UnityCore/SocialPreview.h>
3840
3941Preview::Preview(QObject *parent):
4042 QObject(parent),
@@ -124,6 +126,8 @@ Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
124126 preview = new MoviePreview();
125127 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
126128 preview = new ApplicationPreview();
129+ } else if (dynamic_cast<unity::dash::SocialPreview *>(unityPreview.get()) != nullptr) {
130+ preview = new SocialPreview();
127131 } else {
128132 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
129133 preview = new GenericPreview();
plugins/Unity/previewaction.h+1−1
@@ -36,7 +36,7 @@ enum LayoutHint // keep in sync with unty::dash::LayoutHint
3636 Bottom
3737};
3838
39−class PreviewAction : public QObject
39+class Q_DECL_EXPORT PreviewAction : public QObject
4040{
4141 Q_OBJECT
4242
plugins/Unity/socialpreview.cppnew file+83
@@ -0,0 +1,83 @@
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 "socialpreview.h"
21+#include "socialpreviewcomment.h"
22+
23+#include <QDebug>
24+
25+SocialPreview::SocialPreview(QObject *parent):
26+ Preview(parent),
27+ m_unitySocialPreview(nullptr)
28+{
29+}
30+
31+QString SocialPreview::sender() const
32+{
33+ if (m_unitySocialPreview) {
34+ return QString::fromStdString(m_unitySocialPreview->sender());
35+ } else {
36+ qWarning() << "Preview not set";
37+ }
38+ return QString();
39+}
40+
41+QString SocialPreview::content() const
42+{
43+ if (m_unitySocialPreview) {
44+ return QString::fromStdString(m_unitySocialPreview->content());
45+ } else {
46+ qWarning() << "Preview not set";
47+ }
48+ return QString();
49+}
50+
51+QString SocialPreview::avatar() const
52+{
53+ if (m_unitySocialPreview) {
54+ return QString::fromUtf8(g_icon_to_string(m_unitySocialPreview->avatar()));
55+ } else {
56+ qWarning() << "Preview not set";
57+ }
58+ return QString();
59+}
60+
61+QVariant SocialPreview::comments()
62+{
63+ return QVariant::fromValue(m_comments);
64+}
65+
66+void SocialPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
67+{
68+ m_unitySocialPreview = std::dynamic_pointer_cast<unity::dash::SocialPreview>(unityPreview);
69+ qDeleteAll(m_comments);
70+ m_comments.clear();
71+
72+ if (m_unitySocialPreview) {
73+ for (auto unityComment: m_unitySocialPreview->GetComments()) {
74+ auto comment = new SocialPreviewComment(this);
75+ comment->setUnityComment(unityComment);
76+ m_comments.append(comment);
77+
78+ Q_EMIT previewChanged();
79+ }
80+ } else {
81+ qWarning() << "Incorrect preview type";
82+ }
83+}
plugins/Unity/socialpreview.hnew file+63
@@ -0,0 +1,63 @@
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 SOCIALPREVIEW_H
21+#define SOCIALPREVIEW_H
22+
23+// local
24+#include "preview.h"
25+
26+// Qt
27+#include <QObject>
28+#include <QList>
29+#include <QMetaType>
30+
31+// libunity-core
32+#include <UnityCore/SocialPreview.h>
33+
34+class Q_DECL_EXPORT SocialPreview: public Preview
35+{
36+ Q_OBJECT
37+
38+ Q_PROPERTY(QString sender READ sender NOTIFY previewChanged)
39+ Q_PROPERTY(QString content READ content NOTIFY previewChanged)
40+ Q_PROPERTY(QString avatar READ avatar NOTIFY previewChanged)
41+
42+public:
43+ explicit SocialPreview(QObject *parent = 0);
44+
45+ QString sender() const;
46+ QString content() const;
47+ QString avatar() const;
48+ QVariant comments();
49+
50+Q_SIGNALS:
51+ void previewChanged();
52+
53+protected:
54+ void setUnityPreview(unity::dash::Preview::Ptr unityPreview) override;
55+
56+private:
57+ unity::dash::SocialPreview::Ptr m_unitySocialPreview;
58+ QList<QObject *> m_comments;
59+};
60+
61+Q_DECLARE_METATYPE(SocialPreview *)
62+
63+#endif
plugins/Unity/socialpreviewcomment.cppnew file+63
@@ -0,0 +1,63 @@
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 "socialpreviewcomment.h"
22+
23+SocialPreviewComment::SocialPreviewComment(QObject *parent) :
24+ QObject(parent)
25+{
26+}
27+
28+void SocialPreviewComment::setUnityComment(unity::dash::SocialPreview::CommentPtr unityComment)
29+{
30+ m_unityComment = unityComment;
31+}
32+
33+QString SocialPreviewComment::id() const
34+{
35+ if (m_unityComment) {
36+ return QString::fromStdString(m_unityComment->id);
37+ }
38+ return QString();
39+}
40+
41+QString SocialPreviewComment::displayName() const
42+{
43+ if (m_unityComment) {
44+ return QString::fromStdString(m_unityComment->display_name);
45+ }
46+ return QString();
47+}
48+
49+QString SocialPreviewComment::content() const
50+{
51+ if (m_unityComment) {
52+ return QString::fromStdString(m_unityComment->content);
53+ }
54+ return QString();
55+}
56+
57+QString SocialPreviewComment::time() const
58+{
59+ if (m_unityComment) {
60+ return QString::fromStdString(m_unityComment->time);
61+ }
62+ return QString();
63+}
plugins/Unity/socialpreviewcomment.hnew 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+#ifndef SOCIALPREVIEWCOMMENT_H
21+#define SOCIALPREVIEWCOMMENT_H
22+
23+// Qt
24+#include <QObject>
25+#include <QMetaType>
26+
27+// libunity-core
28+#include <UnityCore/SocialPreview.h>
29+
30+class Q_DECL_EXPORT SocialPreviewComment : public QObject
31+{
32+ Q_OBJECT
33+
34+ Q_PROPERTY(QString id READ id NOTIFY socialPreviewCommentChanged)
35+ Q_PROPERTY(QString displayName READ displayName NOTIFY socialPreviewCommentChanged)
36+ Q_PROPERTY(QString content READ content NOTIFY socialPreviewCommentChanged)
37+ Q_PROPERTY(QString time READ time NOTIFY socialPreviewCommentChanged)
38+
39+public:
40+ explicit SocialPreviewComment(QObject *parent = 0);
41+ void setUnityComment(unity::dash::SocialPreview::CommentPtr unityComment);
42+
43+ QString id() const;
44+ QString displayName() const;
45+ QString content() const;
46+ QString time() const;
47+
48+Q_SIGNALS:
49+ void socialPreviewCommentChanged();
50+
51+private:
52+ unity::dash::SocialPreview::CommentPtr m_unityComment;
53+};
54+
55+Q_DECLARE_METATYPE(SocialPreviewComment *)
56+
57+#endif
tests/plugins/Unity/previewbindingstest.cpp+113−58
@@ -25,6 +25,12 @@
2525#include "applicationpreview.h"
2626#include "moviepreview.h"
2727#include "musicpreview.h"
28+#include "socialpreview.h"
29+#include "socialpreviewcomment.h"
30+#include "previewaction.h"
31+
32+#include <glib.h>
33+#include <glib-object.h>
2834
2935void PreviewBindingsTest::initTestCase()
3036{
@@ -32,81 +38,130 @@ void PreviewBindingsTest::initTestCase()
3238
3339void PreviewBindingsTest::testGenericPreview()
3440{
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);
41+ auto rawPreview = (GObject *)unity_protocol_generic_preview_new();
42+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Metallica");
43+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Ride The Lightning");
44+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
45+ GFile *iconFile = g_file_new_for_path("/foo.png");
46+ GIcon *icon = g_file_icon_new(iconFile);
47+ unity_protocol_preview_add_action(UNITY_PROTOCOL_PREVIEW(rawPreview), "1", "Action1", icon,
48+ UNITY_PROTOCOL_LAYOUT_HINT_LEFT);
49+ unity::glib::Object<GObject> genPrv(rawPreview);
50+
51+ auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
52+ auto prv = Preview::newFromUnityPreview(corePrv);
4353
4454 QCOMPARE(prv != nullptr, true);
4555 QCOMPARE(prv->title(), QString("Metallica"));
4656 QCOMPARE(prv->subtitle(), QString("Ride The Lightning"));
4757 QCOMPARE(prv->description(), QString("Lorem ipsum dolor sit amet"));
58+
59+ auto actions = prv->actions().value<QList<QObject *>>();
60+ QCOMPARE(actions.size(), 1);
61+ auto act = dynamic_cast<PreviewAction *>(actions[0]);
62+ QVERIFY(act != nullptr);
63+ QCOMPARE(act->id(), QString("1"));
64+ QCOMPARE(act->displayName(), QString("Action1"));
65+ QCOMPARE(act->iconHint(), QString("/foo.png"));
66+
67+ g_object_unref(icon);
68+ g_object_unref(iconFile);
4869}
4970
5071void PreviewBindingsTest::testApplicationPreview()
5172{
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));
73+ auto rawPreview = (GObject *)unity_protocol_application_preview_new();
74+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Firefox");
75+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Web Browser");
76+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
77+ unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), "GPL");
78+ unity_protocol_application_preview_set_rating(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), 0.5f);
79+ unity_protocol_application_preview_set_num_ratings(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), 4);
80+ unity::glib::Object<GObject> genPrv(rawPreview);
81+
82+ auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
83+ auto prv = Preview::newFromUnityPreview(corePrv);
84+ auto appPrv = dynamic_cast<ApplicationPreview*>(prv);
85+
86+ QCOMPARE(appPrv != nullptr, true);
87+ QCOMPARE(appPrv->title(), QString("Firefox"));
88+ QCOMPARE(appPrv->subtitle(), QString("Web Browser"));
89+ QCOMPARE(appPrv->description(), QString("Lorem ipsum dolor sit amet"));
90+ QCOMPARE(appPrv->license(), QString("GPL"));
91+ QCOMPARE(appPrv->rating(), 0.5f);
92+ QCOMPARE(appPrv->numRatings(), unsigned (4));
7293}
7394
7495void PreviewBindingsTest::testMoviePreview()
7596{
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"));
97+ auto rawPreview = (GObject *)unity_protocol_movie_preview_new();
98+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Blade Runner");
99+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Ridley Scott");
100+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
101+ unity_protocol_movie_preview_set_year(UNITY_PROTOCOL_MOVIE_PREVIEW(rawPreview), "1982");
102+ unity::glib::Object<GObject> genPrv(rawPreview);
103+
104+ auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
105+ auto prv = Preview::newFromUnityPreview(corePrv);
106+ auto moviePrv = dynamic_cast<MoviePreview*>(prv);
107+
108+ QCOMPARE(moviePrv != nullptr, true);
109+ QCOMPARE(moviePrv->title(), QString("Blade Runner"));
110+ QCOMPARE(moviePrv->subtitle(), QString("Ridley Scott"));
111+ QCOMPARE(moviePrv->description(), QString("Lorem ipsum dolor sit amet"));
112+ QCOMPARE(moviePrv->year(), QString("1982"));
92113}
93114
94115void PreviewBindingsTest::testMusicPreview()
95116{
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"));
117+ auto rawPreview = (GObject *)unity_protocol_music_preview_new();
118+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Metallica");
119+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Death Magnetic");
120+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
121+ unity::glib::Object<GObject> genPrv(rawPreview);
122+
123+ auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
124+ auto prv = Preview::newFromUnityPreview(corePrv);
125+ auto musicPrv = dynamic_cast<MusicPreview*>(prv);
126+
127+ QCOMPARE(musicPrv != nullptr, true);
128+ QCOMPARE(musicPrv->title(), QString("Metallica"));
129+ QCOMPARE(musicPrv->subtitle(), QString("Death Magnetic"));
130+ QCOMPARE(musicPrv->description(), QString("Lorem ipsum dolor sit amet"));
131+}
132+
133+void PreviewBindingsTest::testSocialPreview()
134+{
135+ GFile *iconFile = g_file_new_for_path("/foo.png");
136+ GIcon *icon = g_file_icon_new(iconFile);
137+
138+ auto rawPreview = (GObject *)unity_protocol_social_preview_new();
139+ unity_protocol_social_preview_set_sender(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "John");
140+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), icon);
141+ unity_protocol_social_preview_set_content(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
142+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "1", "comment1", "Ubuntu", "2013-07-04 14:10");
143+ unity::glib::Object<GObject> genPrv(rawPreview);
144+
145+ auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
146+ auto prv = Preview::newFromUnityPreview(corePrv);
147+ auto socialPrv = dynamic_cast<SocialPreview*>(prv);
148+
149+ QCOMPARE(socialPrv != nullptr, true);
150+ QCOMPARE(socialPrv->sender(), QString("John"));
151+ QCOMPARE(socialPrv->content(), QString("Lorem ipsum dolor sit amet"));
152+ QCOMPARE(socialPrv->avatar(), QString("/foo.png"));
153+
154+ auto comments = socialPrv->comments().value<QList<QObject *>>();
155+ QCOMPARE(comments.size(), 1);
156+ auto cmt = dynamic_cast<SocialPreviewComment *>(comments[0]);
157+ QVERIFY(cmt != nullptr);
158+ QCOMPARE(cmt->id(), QString("1"));
159+ QCOMPARE(cmt->displayName(), QString("comment1"));
160+ QCOMPARE(cmt->content(), QString("Ubuntu"));
161+ QCOMPARE(cmt->time(), QString("2013-07-04 14:10"));
162+
163+ g_object_unref(icon);
164+ g_object_unref(iconFile);
110165}
111166
112167QTEST_MAIN(PreviewBindingsTest)
tests/plugins/Unity/previewbindingstest.h+1
@@ -29,6 +29,7 @@ class PreviewBindingsTest : public QObject
2929 void testApplicationPreview();
3030 void testMoviePreview();
3131 void testMusicPreview();
32+ void testSocialPreview();
3233};
3334
3435#endif