@@ -39,6 +39,8 @@
3939#include <UnityCore/MusicPreview.h>
4040#include <UnityCore/SocialPreview.h>
4141
42+#include <UnityCore/GLibWrapper.h>
43+
4244Preview::Preview(QObject *parent):
4345 QObject(parent),
4446 m_unityPreview(nullptr),
@@ -46,6 +48,13 @@ Preview::Preview(QObject *parent):
4648{
4749}
4850
51+Preview::~Preview()
52+{
53+ if (m_actionCancellable) {
54+ g_object_unref(m_actionCancellable);
55+ }
56+}
57+
4958QString Preview::rendererName() const
5059{
5160 if (m_unityPreview) {
@@ -188,8 +197,29 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
188197{
189198 if (m_unityPreview) {
190199 auto unityHints = convertToHintsMap(hints);
191− m_unityPreview->PerformAction(actionId.toStdString(), unityHints);
200+
201+ // cancel previous action
202+ cancelAction();
203+
204+ m_actionCancellable = g_cancellable_new();
205+ m_unityPreview->PerformAction(actionId.toStdString(),
206+ unityHints,
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;
211+ }
212+ }, m_actionCancellable);
192213 } else {
193214 qWarning() << "Preview not set";
194215 }
195216}
217+
218+void Preview::cancelAction()
219+{
220+ if (m_actionCancellable) {
221+ g_cancellable_cancel(m_actionCancellable);
222+ g_object_unref(m_actionCancellable);
223+ m_actionCancellable = nullptr;
224+ }
225+}