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 return QVariant::fromValue(m_actions);
89QVariant Preview::infoHints()
91 return QVariant::fromValue(m_infoHints);
94QString Preview::image() const
97 return QString::fromUtf8(g_icon_to_string(m_unityPreview->image()));
99 qWarning() << "Preview not set";
101 return QString::null;
104QString Preview::imageSourceUri() const
106 if (m_unityPreview) {
107 return QString::fromStdString(m_unityPreview->image_source_uri());
109 qWarning() << "Preview not set";
111 return QString::null;
114Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
116 Preview* preview = nullptr;
118 if (typeid(*unityPreview) == typeid(unity::dash::GenericPreview)) {
119 preview = new GenericPreview();
121 else if (typeid(*unityPreview) == typeid(unity::dash::MusicPreview)) {
122 preview = new MusicPreview();
124 else if (typeid(*unityPreview) == typeid(unity::dash::MoviePreview)) {
125 preview = new MoviePreview();
127 else if (typeid(*unityPreview) == typeid(unity::dash::ApplicationPreview)) {
128 preview = new ApplicationPreview();
130 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
131 preview = new GenericPreview();
134 preview->Preview::setUnityPreview(unityPreview);
135 preview->setUnityPreview(unityPreview);
140void Preview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
142 m_unityPreview = unityPreview;
144 for (auto unityInfoHint: m_unityPreview->GetInfoHints()) {
145 auto hint = new PreviewInfoHint(this);
146 hint->setUnityInfoHint(unityInfoHint);
147 m_infoHints.append(hint);
150 for (auto unityAction: m_unityPreview->GetActions()) {
151 auto action = new PreviewAction(this);
152 action->setUnityAction(unityAction);
153 m_actions.append(action);
156 Q_EMIT rendererNameChanged();
157 Q_EMIT titleChanged();
158 Q_EMIT subtitleChanged();
159 Q_EMIT descriptionChanged();
160 Q_EMIT actionsChanged();
161 Q_EMIT infoHintsChanged();
162 Q_EMIT imageChanged();
163 Q_EMIT imageSourceUriChanged();
166void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& hints)
168 if (m_unityPreview) {
169 auto unityHints = convertToHintsMap(hints);
170 m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
172 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