on xenial help sign in
Added SocialPreview classes.
690885aPawel Stolowski
plugins/Unity/CMakeLists.txt+2
@@ -27,6 +27,8 @@ set(QMLPLUGIN_SRC
27 preview.cpp
27 preview.cpp
28 previewaction.cpp
28 previewaction.cpp
29 previewinfohint.cpp
29 previewinfohint.cpp
30+ socialpreview.cpp
31+ socialpreviewcomment.cpp
30 variantutils.cpp
32 variantutils.cpp
31 )
33 )
32
34
plugins/Unity/plugin.cpp+2
@@ -27,6 +27,7 @@
27#include "preview.h"
27#include "preview.h"
28#include "previewaction.h"
28#include "previewaction.h"
29#include "previewinfohint.h"
29#include "previewinfohint.h"
30+#include "socialpreviewcomment.h"
30#include "scope.h"
31#include "scope.h"
31#include "scopes.h"
32#include "scopes.h"
32#include "categories.h"
33#include "categories.h"
@@ -46,6 +47,7 @@ void UnityPlugin::registerTypes(const char *uri)
46 qmlRegisterUncreatableType<Preview>(uri, 0, 1, "Preview", "Can't create Preview object in QML.");
47 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<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.");
49 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.");
49 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
51 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
50 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
52 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
51 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
53 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
plugins/Unity/preview.cpp+4
@@ -25,6 +25,7 @@
25#include "applicationpreview.h"
25#include "applicationpreview.h"
26#include "moviepreview.h"
26#include "moviepreview.h"
27#include "musicpreview.h"
27#include "musicpreview.h"
28+#include "socialpreview.h"
28#include "variantutils.h"
29#include "variantutils.h"
29
30
30// Qt
31// Qt
@@ -35,6 +36,7 @@
35#include <UnityCore/ApplicationPreview.h>
36#include <UnityCore/ApplicationPreview.h>
36#include <UnityCore/MoviePreview.h>
37#include <UnityCore/MoviePreview.h>
37#include <UnityCore/MusicPreview.h>
38#include <UnityCore/MusicPreview.h>
39+#include <UnityCore/SocialPreview.h>
38
40
39Preview::Preview(QObject *parent):
41Preview::Preview(QObject *parent):
40 QObject(parent),
42 QObject(parent),
@@ -124,6 +126,8 @@ Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
124 preview = new MoviePreview();
126 preview = new MoviePreview();
125 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
127 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
126 preview = new ApplicationPreview();
128 preview = new ApplicationPreview();
129+ } else if (dynamic_cast<unity::dash::SocialPreview *>(unityPreview.get()) != nullptr) {
130+ preview = new SocialPreview();
127 } else {
131 } else {
128 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
132 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
129 preview = new GenericPreview();
133 preview = new GenericPreview();
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+28
@@ -25,6 +25,8 @@
25#include "applicationpreview.h"
25#include "applicationpreview.h"
26#include "moviepreview.h"
26#include "moviepreview.h"
27#include "musicpreview.h"
27#include "musicpreview.h"
28+#include "socialpreview.h"
29+#include "socialpreviewcomment.h"
28
30
29void PreviewBindingsTest::initTestCase()
31void PreviewBindingsTest::initTestCase()
30{
32{
@@ -109,6 +111,32 @@ void PreviewBindingsTest::testMusicPreview()
109 QCOMPARE(music_prv->description(), QString("Lorem ipsum dolor sit amet"));
111 QCOMPARE(music_prv->description(), QString("Lorem ipsum dolor sit amet"));
110}
112}
111
113
114+void PreviewBindingsTest::testSocialPreview()
115+{
116+ auto raw_preview = (GObject *)unity_protocol_social_preview_new();
117+ unity_protocol_social_preview_set_sender(UNITY_PROTOCOL_SOCIAL_PREVIEW(raw_preview), "John");
118+ unity_protocol_social_preview_set_content(UNITY_PROTOCOL_SOCIAL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
119+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(raw_preview), "1", "comment1", "Ubuntu", "2013-07-04 14:10");
120+ unity::glib::Object<GObject> gen_prv(raw_preview);
121+
122+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
123+ auto prv = Preview::newFromUnityPreview(core_prv);
124+ auto social_prv = dynamic_cast<SocialPreview*>(prv);
125+
126+ QCOMPARE(social_prv != nullptr, true);
127+ QCOMPARE(social_prv->sender(), QString("John"));
128+ QCOMPARE(social_prv->content(), QString("Lorem ipsum dolor sit amet"));
129+
130+ auto comments = social_prv->comments().value<QList<QObject *>>();
131+ QCOMPARE(comments.size(), 1);
132+ auto cmt = dynamic_cast<SocialPreviewComment *>(comments[0]);
133+ QVERIFY(cmt != nullptr);
134+ QCOMPARE(cmt->id(), QString("1"));
135+ QCOMPARE(cmt->displayName(), QString("comment1"));
136+ QCOMPARE(cmt->content(), QString("Ubuntu"));
137+ QCOMPARE(cmt->time(), QString("2013-07-04 14:10"));
138+}
139+
112QTEST_MAIN(PreviewBindingsTest)
140QTEST_MAIN(PreviewBindingsTest)
113
141
114#include "previewbindingstest.moc"
142#include "previewbindingstest.moc"
tests/plugins/Unity/previewbindingstest.h+1
@@ -29,6 +29,7 @@ class PreviewBindingsTest : public QObject
29 void testApplicationPreview();
29 void testApplicationPreview();
30 void testMoviePreview();
30 void testMoviePreview();
31 void testMusicPreview();
31 void testMusicPreview();
32+ void testSocialPreview();
32};
33};
33
34
34#endif
35#endif