2 * Copyright (C) 2013 Canonical, Ltd.
5 * Pawel Stolowski <pawel.stolowski@canonical.com>
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.
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.
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/>.
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"
33#include <UnityCore/GenericPreview.h>
34#include <UnityCore/ApplicationPreview.h>
35#include <UnityCore/MoviePreview.h>
36#include <UnityCore/MusicPreview.h>
38Preview::Preview(QObject *parent):
40 m_unityPreview(nullptr)
44QString Preview::rendererName() const
47 return QString::fromStdString(m_unityPreview->renderer_name());
49 qWarning() << "Preview not set";
54QString Preview::title() const
57 return QString::fromStdString(m_unityPreview->title());
59 qWarning() << "Preview not set";
64QString Preview::subtitle () const
67 return QString::fromStdString(m_unityPreview->subtitle());
69 qWarning() << "Preview not set";
74QString Preview::description() const
77 return QString::fromStdString(m_unityPreview->description());
79 qWarning() << "Preview not set";
84QVariant Preview::actions()
86 QList<QObject *> alist;
88 for (auto unityAction: m_unityPreview->GetActions()) {
89 auto action = new PreviewAction(this); // preview is the owner of actions
90 action->setUnityAction(unityAction);
94 qWarning() << "Preview not set";
97 return QVariant::fromValue(alist);
100QVariant Preview::infoHints()
102 QList<QObject *> hints;
103 if (m_unityPreview) {
104 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
105 auto hint = new PreviewInfoHint(this); // preview is the owner of hints
106 hint->setUnityInfoHint(unityInfoHint);
110 qWarning() << "Preview not set";
113 return QVariant::fromValue(hints);
116QString Preview::image() const
118 if (m_unityPreview) {
119 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
121 qWarning() << "Preview not set";
123 return QString::null;
126QString Preview::imageSourceUri() const
128 if (m_unityPreview) {
129 return QString::fromStdString(m_unityPreview->image_source_uri());
131 qWarning() << "Preview not set";
133 return QString::null;
136Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
138 Preview* preview = nullptr;
140 if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
141 preview = new GenericPreview();
143 else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
144 preview = new MusicPreview();
146 else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
147 preview = new MoviePreview();
149 else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
150 preview = new ApplicationPreview();
152 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
153 preview = new GenericPreview();
156 preview->Preview::setUnityPreview(unityPreview);
157 preview->setUnityPreview(unityPreview);
162void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
164 m_unityPreview = unityPreview;
166 Q_EMIT rendererNameChanged();
167 Q_EMIT titleChanged();
168 Q_EMIT subtitleChanged();
169 Q_EMIT descriptionChanged();
170 Q_EMIT actionsChanged();
171 Q_EMIT infoHintsChanged();
172 Q_EMIT imageChanged();
173 Q_EMIT imageSourceUriChanged();
176void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
178 if (m_unityPreview) {
179 auto unityHints = convertToHintsMap(hints);
180 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
182 qWarning() << "Preview not set";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list