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"
30#include "variantutils.h"
34#include <QtAlgorithms>
36#include <UnityCore/GenericPreview.h>
37#include <UnityCore/ApplicationPreview.h>
38#include <UnityCore/MoviePreview.h>
39#include <UnityCore/MusicPreview.h>
40#include <UnityCore/SocialPreview.h>
42Preview::Preview(QObject *parent):
44 m_unityPreview(nullptr)
48QString Preview::rendererName() const
51 return QString::fromStdString(m_unityPreview->renderer_name());
53 qWarning() << "Preview not set";
58QString Preview::title() const
61 return QString::fromStdString(m_unityPreview->title());
63 qWarning() << "Preview not set";
68QString Preview::subtitle () const
71 return QString::fromStdString(m_unityPreview->subtitle());
73 qWarning() << "Preview not set";
78QString Preview::description() const
81 return QString::fromStdString(m_unityPreview->description());
83 qWarning() << "Preview not set";
88QVariant Preview::actions()
90 return QVariant::fromValue(m_actions);
93QVariant Preview::infoHints()
95 return QVariant::fromValue(m_infoHints);
98QVariantMap Preview::infoHintsHash() const
100 return m_infoHintsHash;
103QString Preview::image() const
105 if (m_unityPreview) {
106 auto giconString = g_icon_to_string(m_unityPreview->image());
107 QString result(gIconToDeclarativeImageProviderString(QString::fromUtf8(giconString)));
111 qWarning() << "Preview not set";
113 return QString::null;
116QString Preview::imageSourceUri() const
118 if (m_unityPreview) {
119 return QString::fromStdString(m_unityPreview->image_source_uri());
121 qWarning() << "Preview not set";
123 return QString::null;
126Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
128 Preview* preview = nullptr;
130 if (dynamic_cast<unity::dash::GenericPreview *>(unityPreview.get()) != nullptr) {
131 preview = new GenericPreview();
132 } else if (dynamic_cast<unity::dash::MusicPreview *>(unityPreview.get()) != nullptr) {
133 preview = new MusicPreview();
134 } else if (dynamic_cast<unity::dash::MoviePreview *>(unityPreview.get()) != nullptr) {
135 preview = new MoviePreview();
136 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
137 preview = new ApplicationPreview();
138 } else if (dynamic_cast<unity::dash::SocialPreview *>(unityPreview.get()) != nullptr) {
139 preview = new SocialPreview();
141 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
142 preview = new GenericPreview();
145 preview->setUnityPreviewBase(unityPreview);
146 preview->setUnityPreview(unityPreview);
151void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
153 m_unityPreview = unityPreview;
155 qDeleteAll(m_infoHints);
157 m_infoHintsHash.clear();
158 qDeleteAll(m_actions);
161 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
162 auto hint = new PreviewInfoHint(this);
163 hint->setUnityInfoHint(unityInfoHint);
164 m_infoHints.append(hint);
165 m_infoHintsHash[hint->id()] = QVariant::fromValue(hint);
168 for (auto unityAction: m_unityPreview->GetActions()) {
169 auto action = new PreviewAction(this);
170 action->setUnityAction(unityAction);
171 m_actions.append(action);
175void Preview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
177 // default implementation does nothing
180void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
182 if (m_unityPreview) {
183 auto unityHints = convertToHintsMap(hints);
184 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
186 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