on 1e71a8a help sign in
unity8/plugins/Unity/preview.cpp
184 lines 4.8 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)
43QString Preview::rendererName() const
45 if (m_unityPreview) {
46 return QString::fromStdString(m_unityPreview->renderer_name());
47 } else {
48 qWarning() << "Preview not set";
49 }
50 return "";
53QString Preview::title() const
55 if (m_unityPreview) {
56 return QString::fromStdString(m_unityPreview->title());
57 } else {
58 qWarning() << "Preview not set";
59 }
60 return "";
63QString Preview::subtitle () const
65 if (m_unityPreview) {
66 return QString::fromStdString(m_unityPreview->subtitle());
67 } else {
68 qWarning() << "Preview not set";
69 }
70 return "";
73QString Preview::description() const
75 if (m_unityPreview) {
76 return QString::fromStdString(m_unityPreview->description());
77 } else {
78 qWarning() << "Preview not set";
79 }
80 return "";
83QVariant Preview::actions()
85 QList<QObject *> alist;
86 if (m_unityPreview) {
87 for (auto unityAction: m_unityPreview->GetActions()) {
88 auto action = new PreviewAction(this); // preview is the owner of actions
89 action->setUnityAction(unityAction);
90 alist.append(action);
91 }
92 } else {
93 qWarning() << "Preview not set";
94 }
96 return QVariant::fromValue(alist);
99QVariant Preview::infoHints()
101 QList<QObject *> hints;
102 if (m_unityPreview) {
103 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
104 auto hint = new PreviewInfoHint(this); // preview is the owner of hints
105 hint->setUnityInfoHint(unityInfoHint);
106 hints.append(hint);
107 }
108 } else {
109 qWarning() << "Preview not set";
110 }
112 return QVariant::fromValue(hints);
115QString Preview::image() const
117 if (m_unityPreview) {
118 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
119 } else {
120 qWarning() << "Preview not set";
121 }
122 return QString::null;
125QString Preview::imageSourceUri() const
127 if (m_unityPreview) {
128 return QString::fromStdString(m_unityPreview->image_source_uri());
129 } else {
130 qWarning() << "Preview not set";
131 }
132 return QString::null;
135Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
137 Preview* preview = nullptr;
139 if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
140 preview = new GenericPreview();
141 }
142 else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
143 preview = new MusicPreview();
144 }
145 else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
146 preview = new MoviePreview();
147 }
148 else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
149 preview = new ApplicationPreview();
150 } else {
151 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
152 preview = new GenericPreview();
153 }
155 preview->Preview::setUnityPreview(unityPreview);
156 preview->setUnityPreview(unityPreview);
158 return preview;
161void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
163 m_unityPreview = unityPreview;
165 Q_EMIT rendererNameChanged();
166 Q_EMIT titleChanged();
167 Q_EMIT subtitleChanged();
168 Q_EMIT descriptionChanged();
169 Q_EMIT actionsChanged();
170 Q_EMIT infoHintsChanged();
171 Q_EMIT imageChanged();
172 Q_EMIT imageSourceUriChanged();
175void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
177 if (m_unityPreview) {
178 auto unityHints = convertToHintsMap(hints);
179 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
180 } else {
181 qWarning() << "Preview not set";
182 }