on f649207 help sign in
unity8/plugins/Unity/preview.cpp
130 lines 3.6 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 "genericpreview.h"
24#include "applicationpreview.h"
25#include "moviepreview.h"
26#include "musicpreview.h"
27#include "variantutils.h"
29// Qt
30#include <QDebug>
32#include <UnityCore/GenericPreview.h>
33#include <UnityCore/ApplicationPreview.h>
34#include <UnityCore/MoviePreview.h>
35#include <UnityCore/MusicPreview.h>
37Preview::Preview(QObject *parent):
38 QObject(parent)
42QString Preview::rendererName() const
44 if (m_unityPreview) {
45 return QString::fromStdString(m_unityPreview->renderer_name());
46 } else {
47 qWarning() << "Preview not set";
48 }
49 return "";
52QString Preview::title() const
54 if (m_unityPreview) {
55 return QString::fromStdString(m_unityPreview->title());
56 } else {
57 qWarning() << "Preview not set";
58 }
59 return "";
62QString Preview::subtitle () const
64 if (m_unityPreview) {
65 return QString::fromStdString(m_unityPreview->subtitle());
66 } else {
67 qWarning() << "Preview not set";
68 }
69 return "";
72QVariant Preview::actions()
74 QList<QObject *> alist;
75 if (m_unityPreview) {
76 for (auto unityAction: m_unityPreview->GetActions()) {
77 auto action = new PreviewAction(this); // preview is the owner of actions
78 action->setUnityAction(unityAction);
79 alist.append(action);
80 }
81 } else {
82 qWarning() << "Preview not set";
83 }
85 return QVariant::fromValue(alist);
88Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
90 Preview* preview = nullptr;
92 if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
93 preview = new GenericPreview();
94 }
95 else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
96 preview = new MusicPreview();
97 }
98 else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
99 preview = new MoviePreview();
100 }
101 else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
102 preview = new ApplicationPreview();
103 } else {
104 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
105 preview = new GenericPreview();
106 }
107 preview->Preview::setUnityPreview(unityPreview);
108 preview->setUnityPreview(unityPreview);
110 return preview;
113void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
115 m_unityPreview = unityPreview;
116 Q_EMIT rendererNameChanged();
117 Q_EMIT titleChanged();
118 Q_EMIT subtitleChanged();
119 Q_EMIT actionsChanged();
122void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
124 if (m_unityPreview) {
125 auto unityHints = convertToHintsMap(hints);
126 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
127 } else {
128 qWarning() << "Preview not set";
129 }