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 "socialpreview.h"
29#include "variantutils.h"
33#include <QtAlgorithms>
35#include <UnityCore/GenericPreview.h>
36#include <UnityCore/ApplicationPreview.h>
37#include <UnityCore/MoviePreview.h>
38#include <UnityCore/MusicPreview.h>
39#include <UnityCore/SocialPreview.h>
41Preview::Preview(QObject *parent):
43 m_unityPreview(nullptr)
47QString Preview::rendererName() const
50 return QString::fromStdString(m_unityPreview->renderer_name());
52 qWarning() << "Preview not set";
57QString Preview::title() const
60 return QString::fromStdString(m_unityPreview->title());
62 qWarning() << "Preview not set";
67QString Preview::subtitle () const
70 return QString::fromStdString(m_unityPreview->subtitle());
72 qWarning() << "Preview not set";
77QString Preview::description() const
80 return QString::fromStdString(m_unityPreview->description());
82 qWarning() << "Preview not set";
87QVariant Preview::actions()
89 return QVariant::fromValue(m_actions);
92QVariant Preview::infoHints()
94 return QVariant::fromValue(m_infoHints);
97QString Preview::image() const
100 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
102 qWarning() << "Preview not set";
104 return QString::null;
107QString Preview::imageSourceUri() const
109 if (m_unityPreview) {
110 return QString::fromStdString(m_unityPreview->image_source_uri());
112 qWarning() << "Preview not set";
114 return QString::null;
117Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
119 Preview* preview = nullptr;
121 if (dynamic_cast<unity::dash::GenericPreview *>(unityPreview.get()) != nullptr) {
122 preview = new GenericPreview();
123 } else if (dynamic_cast<unity::dash::MusicPreview *>(unityPreview.get()) != nullptr) {
124 preview = new MusicPreview();
125 } else if (dynamic_cast<unity::dash::MoviePreview *>(unityPreview.get()) != nullptr) {
126 preview = new MoviePreview();
127 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
128 preview = new ApplicationPreview();
129 } else if (dynamic_cast<unity::dash::SocialPreview *>(unityPreview.get()) != nullptr) {
130 preview = new SocialPreview();
132 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
133 preview = new GenericPreview();
136 preview->setUnityPreviewBase(unityPreview);
137 preview->setUnityPreview(unityPreview);
142void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
144 m_unityPreview = unityPreview;
146 qDeleteAll(m_infoHints);
148 qDeleteAll(m_actions);
151 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
152 auto hint = new PreviewInfoHint(this);
153 hint->setUnityInfoHint(unityInfoHint);
154 m_infoHints.append(hint);
157 for (auto unityAction: m_unityPreview->GetActions()) {
158 auto action = new PreviewAction(this);
159 action->setUnityAction(unityAction);
160 m_actions.append(action);
164void Preview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
166 // default implementation does nothing
169void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
171 if (m_unityPreview) {
172 auto unityHints = convertToHintsMap(hints);
173 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
175 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