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"
32#include <QtAlgorithms>
34#include <UnityCore/GenericPreview.h>
35#include <UnityCore/ApplicationPreview.h>
36#include <UnityCore/MoviePreview.h>
37#include <UnityCore/MusicPreview.h>
39Preview::Preview(QObject *parent):
41 m_unityPreview(nullptr)
45QString Preview::rendererName() const
48 return QString::fromStdString(m_unityPreview->renderer_name());
50 qWarning() << "Preview not set";
55QString Preview::title() const
58 return QString::fromStdString(m_unityPreview->title());
60 qWarning() << "Preview not set";
65QString Preview::subtitle () const
68 return QString::fromStdString(m_unityPreview->subtitle());
70 qWarning() << "Preview not set";
75QString Preview::description() const
78 return QString::fromStdString(m_unityPreview->description());
80 qWarning() << "Preview not set";
85QVariant Preview::actions()
87 return QVariant::fromValue(m_actions);
90QVariant Preview::infoHints()
92 return QVariant::fromValue(m_infoHints);
95QString Preview::image() const
98 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
100 qWarning() << "Preview not set";
102 return QString::null;
105QString Preview::imageSourceUri() const
107 if (m_unityPreview) {
108 return QString::fromStdString(m_unityPreview->image_source_uri());
110 qWarning() << "Preview not set";
112 return QString::null;
115Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
117 Preview* preview = nullptr;
119 if (dynamic_cast<unity::dash::GenericPreview *>(unityPreview.get()) != nullptr) {
120 preview = new GenericPreview();
121 } else if (dynamic_cast<unity::dash::MusicPreview *>(unityPreview.get()) != nullptr) {
122 preview = new MusicPreview();
123 } else if (dynamic_cast<unity::dash::MoviePreview *>(unityPreview.get()) != nullptr) {
124 preview = new MoviePreview();
125 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
126 preview = new ApplicationPreview();
128 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
129 preview = new GenericPreview();
132 preview->setUnityPreviewBase(unityPreview);
133 preview->setUnityPreview(unityPreview);
138void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
140 m_unityPreview = unityPreview;
142 qDeleteAll(m_infoHints);
144 qDeleteAll(m_actions);
147 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
148 auto hint = new PreviewInfoHint(this);
149 hint->setUnityInfoHint(unityInfoHint);
150 m_infoHints.append(hint);
153 for (auto unityAction: m_unityPreview->GetActions()) {
154 auto action = new PreviewAction(this);
155 action->setUnityAction(unityAction);
156 m_actions.append(action);
160void Preview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
162 // default implementation does nothing
165void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
167 if (m_unityPreview) {
168 auto unityHints = convertToHintsMap(hints);
169 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
171 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