@@ -19,12 +19,19 @@
21#include "scope.h"
21#include "scope.h"
22#include "categories.h"
24#include "categories.h"
26+#include "variantutils.h"
25#include <QUrl>
29#include <QUrl>
26#include <QDebug>
30#include <QDebug>
27#include <QtGui/QDesktopServices>
31#include <QtGui/QDesktopServices>
34+#include <UnityCore/Variant.h>
29#include <libintl.h>
36#include <libintl.h>
@@ -118,21 +125,80 @@ void Scope::setNoResultsHint(const QString& hint) {
129+unity::dash::LocalResult Scope::createLocalResult(const QVariant &uri, const QVariant &icon_hint,
130+ const QVariant &category, const QVariant &result_type,
131+ const QVariant &mimetype, const QVariant &title,
132+ const QVariant &comment, const QVariant &dnd_uri,
133+ const QVariant &metadata)
135+ unity::dash::LocalResult res;
136+ res.uri = uri.toString().toStdString();
137+ res.icon_hint = icon_hint.toString().toStdString();
138+ res.category_index = category.toUInt();
139+ res.result_type = result_type.toUInt();
140+ res.mimetype = mimetype.toString().toStdString();
141+ res.name = title.toString().toStdString();
142+ res.comment = comment.toString().toStdString();
143+ res.dnd_uri = dnd_uri.toString().toStdString();
144+ res.hints = convertToHintsMap(metadata);
149+// FIXME: Change to use row index.
121−void Scope::activate(const QString& /*uri*/)
150+void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
151+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
152+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
154+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
155+ m_unityScope->Activate(res);
158+// FIXME: Change to use row index.
159+void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
160+ const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
161+ const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
123− // TODO:
163+ auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
124− // we need to create unity::dash::LocalResult (see UnityCore/Result.h) and pass it to Activate;
164+ m_unityScope->Preview(res);
125− // this requires entire row from the model, so we need row index rather than uri.
126− // m_unityScope->Activate(QByteArray::fromPercentEncoding(uri.toUtf8()).constData());
129−void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
167+void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
169+ // note: we will not get called on SHOW_PREVIEW, instead UnityCore will signal preview_ready.
131− if (type == unity::dash::NOT_HANDLED) {
172+ case unity::dash::NOT_HANDLED:
132− fallbackActivate(QString::fromStdString(result.uri));
173+ fallbackActivate(QString::fromStdString(result.uri));
175+ case unity::dash::SHOW_DASH:
178+ case unity::dash::HIDE_DASH:
181+ case unity::dash::GOTO_DASH_URI:
182+ if (hints.find("goto-uri") != hints.end()) {
183+ Q_EMIT gotoUri(QString::fromStdString(g_variant_get_string(hints.at("goto-uri"), nullptr)));
185+ qWarning() << "Missing goto-uri hint for GOTO_DASH_URI activation reply";
189+ qWarning() << "Unhandled activation response:" << type;
193+void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
195+ auto prv = Preview::newFromUnityPreview(preview);
196+ // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
197+ // passing it by value is not possible.
198+ QQmlEngine::setObjectOwnership(prv, QQmlEngine::JavaScriptOwnership);
199+ Q_EMIT previewReady(prv);
136void Scope::fallbackActivate(const QString& uri)
202void Scope::fallbackActivate(const QString& uri)
138 /* FIXME: stripping all content before the first column because for some
204 /* FIXME: stripping all content before the first column because for some
@@ -161,10 +227,10 @@ void Scope::fallbackActivate(const QString& uri)
164− qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
165− qWarning() << "Trying to open" << tweakedUri;
230+ qDebug() << "Trying to open" << uri;
166 /* Try our luck */
232 /* Try our luck */
167− QDesktopServices::openUrl(url);
233+ QDesktopServices::openUrl(uri); //url?
170void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
236void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
@@ -204,6 +270,8 @@ void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
204 /* FIXME: signal should be forwarded instead of calling the handler directly */
270 /* FIXME: signal should be forwarded instead of calling the handler directly */
205 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
271 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
273+ m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
207 /* Synchronize local states with m_unityScope right now and whenever
275 /* Synchronize local states with m_unityScope right now and whenever
208 m_unityScope becomes connected */
276 m_unityScope becomes connected */
209 /* FIXME: should emit change notification signals for all properties */
277 /* FIXME: should emit change notification signals for all properties */