on bc9f5cd help sign in
unity8/plugins/Unity/preview.cpp
174 lines 4.5 kB history raw
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 */
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"
30// Qt
31#include <QDebug>
33#include <UnityCore/GenericPreview.h>
34#include <UnityCore/ApplicationPreview.h>
35#include <UnityCore/MoviePreview.h>
36#include <UnityCore/MusicPreview.h>
38Preview::Preview(QObject *parent):
39 QObject(parent),
40 m_unityPreview(nullptr)
44QString Preview::rendererName() const
46 if (m_unityPreview) {
47 return QString::fromStdString(m_unityPreview->renderer_name());
48 } else {
49 qWarning() << "Preview not set";
50 }
51 return "";
54QString Preview::title() const
56 if (m_unityPreview) {
57 return QString::fromStdString(m_unityPreview->title());
58 } else {
59 qWarning() << "Preview not set";
60 }
61 return "";
64QString Preview::subtitle () const
66 if (m_unityPreview) {
67 return QString::fromStdString(m_unityPreview->subtitle());
68 } else {
69 qWarning() << "Preview not set";
70 }
71 return "";
74QString Preview::description() const
76 if (m_unityPreview) {
77 return QString::fromStdString(m_unityPreview->description());
78 } else {
79 qWarning() << "Preview not set";
80 }
81 return "";
84QVariant Preview::actions()
86 return QVariant::fromValue(m_actions);
89QVariant Preview::infoHints()
91 return QVariant::fromValue(m_infoHints);
94QString Preview::image() const
96 if (m_unityPreview) {
97 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
98 } else {
99 qWarning() << "Preview not set";
100 }
101 return QString::null;
104QString Preview::imageSourceUri() const
106 if (m_unityPreview) {
107 return QString::fromStdString(m_unityPreview->image_source_uri());
108 } else {
109 qWarning() << "Preview not set";
110 }
111 return QString::null;
114Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
116 Preview* preview = nullptr;
118 if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
119 preview = new GenericPreview();
120 }
121 else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
122 preview = new MusicPreview();
123 }
124 else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
125 preview = new MoviePreview();
126 }
127 else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
128 preview = new ApplicationPreview();
129 } else {
130 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
131 preview = new GenericPreview();
132 }
134 preview->Preview::setUnityPreview(unityPreview);
135 preview->setUnityPreview(unityPreview);
137 return preview;
140void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
142 m_unityPreview = unityPreview;
144 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
145 auto hint = new PreviewInfoHint(this);
146 hint->setUnityInfoHint(unityInfoHint);
147 m_infoHints.append(hint);
148 }
150 for (auto unityAction: m_unityPreview->GetActions()) {
151 auto action = new PreviewAction(this);
152 action->setUnityAction(unityAction);
153 m_actions.append(action);
154 }
156 Q_EMIT rendererNameChanged();
157 Q_EMIT titleChanged();
158 Q_EMIT subtitleChanged();
159 Q_EMIT descriptionChanged();
160 Q_EMIT actionsChanged();
161 Q_EMIT infoHintsChanged();
162 Q_EMIT imageChanged();
163 Q_EMIT imageSourceUriChanged();
166void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
168 if (m_unityPreview) {
169 auto unityHints = convertToHintsMap(hints);
170 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
171 } else {
172 qWarning() << "Preview not set";
173 }