@@ -39,6 +39,8 @@
39#include <UnityCore/MusicPreview.h>
39#include <UnityCore/MusicPreview.h>
40#include <UnityCore/SocialPreview.h>
40#include <UnityCore/SocialPreview.h>
42+#include <UnityCore/GLibWrapper.h>
42Preview::Preview(QObject *parent):
44Preview::Preview(QObject *parent):
43 QObject(parent),
45 QObject(parent),
44 m_unityPreview(nullptr),
46 m_unityPreview(nullptr),
@@ -46,6 +48,13 @@ Preview::Preview(QObject *parent):
53+ if (m_actionCancellable) {
54+ g_object_unref(m_actionCancellable);
49QString Preview::rendererName() const
58QString Preview::rendererName() const
51 if (m_unityPreview) {
60 if (m_unityPreview) {
@@ -188,8 +197,29 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
189 if (m_unityPreview) {
198 if (m_unityPreview) {
190 auto unityHints = convertToHintsMap(hints);
199 auto unityHints = convertToHintsMap(hints);
201+ // cancel previous action
204+ m_actionCancellable = g_cancellable_new();
191− m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
205+ m_unityPreview->PerformAction(actionId.toStdString(),
207+ [this](unity::dash::LocalResult const&, unity::dash::ScopeHandledType, unity::glib::Error const&) {
208+ if (m_actionCancellable) {
209+ g_object_unref(m_actionCancellable);
210+ m_actionCancellable = nullptr;
212+ }, m_actionCancellable);
193 qWarning() << "Preview not set";
214 qWarning() << "Preview not set";
218+void Preview::cancelAction()
220+ if (m_actionCancellable) {
221+ g_cancellable_cancel(m_actionCancellable);
222+ g_object_unref(m_actionCancellable);
223+ m_actionCancellable = nullptr;