on xenial help sign in
Initial cut at preview action handling.
commitd6066086427dcbd03ba6ed55cd41ba2a91c910ad authorPawel Stolowski <pawel.stolowski@canonical.com> dateTue 25 Jun 2013, 12:47 (13 years ago) parentdc8f17e
6 files changed+152−4
plugins/Unity/CMakeLists.txt+1 plugins/Unity/preview.cpp+22−3 plugins/Unity/preview.h+5 plugins/Unity/previewaction.cpp+65 plugins/Unity/previewaction.h+58 plugins/Unity/scope.cpp+1−1
plugins/Unity/CMakeLists.txt+1
@@ -25,6 +25,7 @@ set(QMLPLUGIN_SRC
2525 moviepreview.cpp
2626 musicpreview.cpp
2727 preview.cpp
28+ previewaction.cpp
2829 variantutils.cpp
2930 )
3031
plugins/Unity/preview.cpp+22−3
@@ -39,17 +39,36 @@ Preview::Preview(QObject *parent):
3939
4040QString Preview::rendererName() const
4141{
42− return QString::fromStdString(m_unityPreview->renderer_name());
42+ if (m_unityPreview)
43+ return QString::fromStdString(m_unityPreview->renderer_name());
44+ return "";
4345}
4446
4547QString Preview::title() const
4648{
47− return QString::fromStdString(m_unityPreview->title());
49+ if (m_unityPreview)
50+ return QString::fromStdString(m_unityPreview->title());
51+ return "";
4852}
4953
5054QString Preview::subtitle () const
5155{
52− return QString::fromStdString(m_unityPreview->subtitle());
56+ if (m_unityPreview)
57+ return QString::fromStdString(m_unityPreview->subtitle());
58+ return "";
59+}
60+
61+PreviewActionList Preview::actions()
62+{
63+ PreviewActionList alist;
64+ if (m_unityPreview) {
65+ for (auto unityAction: m_unityPreview->GetActions()) {
66+ auto action = new PreviewAction(this);
67+ action->setUnityAction(unityAction);
68+ alist.append(action);
69+ }
70+ }
71+ return alist;
5372}
5473
5574Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
plugins/Unity/preview.h+5
@@ -28,6 +28,9 @@
2828// libunity-core
2929#include <UnityCore/Preview.h>
3030
31+// local
32+#include "previewaction.h"
33+
3134class Preview : public QObject
3235{
3336 Q_OBJECT
@@ -35,6 +38,7 @@ class Preview : public QObject
3538 Q_PROPERTY(QString rendererName READ rendererName)
3639 Q_PROPERTY(QString title READ title)
3740 Q_PROPERTY(QString subtitle READ subtitle)
41+ Q_PROPERTY(PreviewActionList actions READ actions)
3842
3943public:
4044 explicit Preview(QObject *parent = 0);
@@ -43,6 +47,7 @@ public:
4347 QString rendererName() const;
4448 QString title() const;
4549 QString subtitle () const;
50+ PreviewActionList actions();
4651
4752protected:
4853 virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
plugins/Unity/previewaction.cppnew file+65
@@ -0,0 +1,65 @@
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+{
25+}
26+
27+void PreviewAction::setUnityAction(unity::dash::Preview::ActionPtr unityAction)
28+{
29+ m_unityAction = unityAction;
30+}
31+
32+QString PreviewAction::id() const
33+{
34+ if (m_unityAction)
35+ return QString::fromStdString(m_unityAction->id);
36+ return "";
37+}
38+
39+QString PreviewAction::displayName() const
40+{
41+ if (m_unityAction)
42+ return QString::fromStdString(m_unityAction->display_name);
43+ return "";
44+}
45+
46+QString PreviewAction::iconHint() const
47+{
48+ if (m_unityAction)
49+ return QString::fromStdString(m_unityAction->icon_hint);
50+ return "";
51+}
52+
53+QString PreviewAction::extraText() const
54+{
55+ if (m_unityAction)
56+ return QString::fromStdString(m_unityAction->extra_text);
57+ return "";
58+}
59+
60+QString PreviewAction::activationUri() const
61+{
62+ if (m_unityAction)
63+ return QString::fromStdString(m_unityAction->activation_uri);
64+ return "";
65+}
plugins/Unity/previewaction.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 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+class PreviewAction : public QObject
31+{
32+ Q_OBJECT
33+
34+ Q_PROPERTY(QString id READ id)
35+ Q_PROPERTY(QString displayName READ displayName)
36+ Q_PROPERTY(QString iconHint READ iconHint)
37+ Q_PROPERTY(QString extraText READ extraText)
38+ Q_PROPERTY(QString activationUri READ activationUri)
39+
40+public:
41+ explicit PreviewAction(QObject *parent = 0);
42+ void setUnityAction(unity::dash::Preview::ActionPtr unityAction);
43+
44+ QString id() const;
45+ QString displayName() const;
46+ QString iconHint() const;
47+ QString extraText() const;
48+ QString activationUri() const;
49+
50+private:
51+ unity::dash::Preview::ActionPtr m_unityAction;
52+};
53+
54+typedef QList<PreviewAction *> PreviewActionList;
55+Q_DECLARE_METATYPE(PreviewAction*)
56+Q_DECLARE_METATYPE(PreviewActionList)
57+
58+#endif
plugins/Unity/scope.cpp+1−1
@@ -187,7 +187,7 @@ void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::Sco
187187 }
188188}
189189
190−void Scope::onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview)
190+void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
191191{
192192 auto prv = Preview::newFromUnityPreview(preview);
193193 Q_EMIT previewReady(*prv);