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>
42#include <UnityCore/GLibWrapper.h>
44Preview::Preview(QObject *parent):
46 m_unityPreview(nullptr),
47 m_result(new Result(this))
51QString Preview::rendererName() const
54 return QString::fromStdString(m_unityPreview->renderer_name());
56 qWarning() << "Preview not set";
61QString Preview::title() const
64 return QString::fromStdString(m_unityPreview->title());
66 qWarning() << "Preview not set";
71QString Preview::subtitle () const
74 return QString::fromStdString(m_unityPreview->subtitle());
76 qWarning() << "Preview not set";
81QString Preview::description() const
84 return QString::fromStdString(m_unityPreview->description());
86 qWarning() << "Preview not set";
91QVariant Preview::actions()
93 return QVariant::fromValue(m_actions);
96QVariant Preview::infoHints()
98 return QVariant::fromValue(m_infoHints);
101QVariantMap Preview::infoHintsHash() const
103 return m_infoHintsHash;
106QString Preview::image() const
108 if (m_unityPreview) {
109 if (m_unityPreview->image() != nullptr) {
110 auto giconString = g_icon_to_string(m_unityPreview->image());
111 QString result(gIconToDeclarativeImageProviderString(QString::fromUtf8(giconString)));
115 QString sourceMedia(QString::fromStdString(m_unityPreview->image_source_uri()));
116 QString thumbnailUri(uriToThumbnailerProviderString(sourceMedia));
117 if (!thumbnailUri.isNull()) return thumbnailUri;
120 qWarning() << "Preview not set";
122 return QString::null;
125QVariant Preview::result() const
127 return QVariant::fromValue(m_result);
130Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
132 Preview* preview = nullptr;
134 if (dynamic_cast<unity::dash::GenericPreview *>(unityPreview.get()) != nullptr) {
135 preview = new GenericPreview();
136 } else if (dynamic_cast<unity::dash::MusicPreview *>(unityPreview.get()) != nullptr) {
137 preview = new MusicPreview();
138 } else if (dynamic_cast<unity::dash::MoviePreview *>(unityPreview.get()) != nullptr) {
139 preview = new MoviePreview();
140 } else if (dynamic_cast<unity::dash::ApplicationPreview *>(unityPreview.get()) != nullptr) {
141 preview = new ApplicationPreview();
142 } else if (dynamic_cast<unity::dash::SocialPreview *>(unityPreview.get()) != nullptr) {
143 preview = new SocialPreview();
145 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
146 preview = new GenericPreview();
149 preview->setUnityPreviewBase(unityPreview);
150 preview->setUnityPreview(unityPreview);
155void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
157 m_unityPreview = unityPreview;
158 m_result->setPreview(unityPreview);
160 qDeleteAll(m_infoHints);
162 m_infoHintsHash.clear();
163 qDeleteAll(m_actions);
166 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
167 auto hint = new PreviewInfoHint(this);
168 hint->setUnityInfoHint(unityInfoHint);
169 m_infoHints.append(hint);
170 m_infoHintsHash[hint->id()] = QVariant::fromValue(hint);
173 for (auto unityAction: m_unityPreview->GetActions()) {
174 auto action = new PreviewAction(this);
175 action->setUnityAction(unityAction);
176 m_actions.append(action);
180void Preview::setUnityPreview(unity::dash::Preview::Ptr /* unityPreview */)
182 // default implementation does nothing
185void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
187 if (m_unityPreview) {
188 auto unityHints = convertToHintsMap(hints);
189 m_actionCancellable.Renew();
190 m_unityPreview->PerformAction(actionId.toStdString(), unityHints, nullptr, m_actionCancellable);
192 qWarning() << "Preview not set";
196void Preview::cancelAction()
198 m_actionCancellable.Cancel();
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