2 * Copyright (C) 2011 Canonical, Ltd.
5 * Florian Boucault <florian.boucault@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/>.
24#include "categories.h"
26#include "variantutils.h"
31#include <QtGui/QDesktopServices>
34#include <UnityCore/Variant.h>
38Scope::Scope(QObject *parent) :
41 m_results = new DeeListModel(this);
42 m_categories = new Categories(this);
44 m_categories->setResultModel(m_results);
47QString Scope::id() const
49 return QString::fromStdString(m_unityScope->id());
52QString Scope::name() const
54 return QString::fromStdString(m_unityScope->name());
57QString Scope::iconHint() const
59 return QString::fromStdString(m_unityScope->icon_hint());
62QString Scope::description() const
64 return QString::fromStdString(m_unityScope->description());
67QString Scope::searchHint() const
69 return QString::fromStdString(m_unityScope->search_hint());
72bool Scope::visible() const
74 return m_unityScope->visible();
77QString Scope::shortcut() const
79 return QString::fromStdString(m_unityScope->shortcut());
82bool Scope::connected() const
84 return m_unityScope->connected();
87DeeListModel* Scope::results() const
92Categories* Scope::categories() const
97QString Scope::searchQuery() const
102QString Scope::noResultsHint() const
104 return m_noResultsHint;
107void Scope::setSearchQuery(const QString& search_query)
109 /* Checking for m_searchQuery.isNull() which returns true only when the string
110 has never been set is necessary because when search_query is the empty
111 string ("") and m_searchQuery is the null string,
112 search_query != m_searchQuery is still true.
114 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
115 m_searchQuery = search_query;
116 m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
117 Q_EMIT searchQueryChanged();
121void Scope::setNoResultsHint(const QString& hint) {
122 if (hint != m_noResultsHint) {
123 m_noResultsHint = hint;
124 Q_EMIT noResultsHintChanged();
129unity::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.
150void 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.
159void 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)
163 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
164 m_unityScope->Preview(res);
167void 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.
172 case unity::dash::NOT_HANDLED:
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;
193void 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);
202void Scope::fallbackActivate(const QString& uri)
204 /* FIXME: stripping all content before the first column because for some
205 reason the scopes give uri with junk content at their beginning.
207 QString tweakedUri = uri;
208 int firstColumnAt = tweakedUri.indexOf(":");
209 tweakedUri.remove(0, firstColumnAt+1);
211 /* Tries various methods to trigger a sensible action for the given 'uri'.
212 If it has no understanding of the given scheme it falls back on asking
215 QUrl url(tweakedUri);
216 if (url.scheme() == "file") {
217 /* Override the files place's default URI handler: we want the file
218 manager to handle opening folders, not the dash.
220 Ref: https://bugs.launchpad.net/upicek/+bug/689667
222 QDesktopServices::openUrl(url);
225 if (url.scheme() == "application") {
226 // TODO: implement application handling
230 qDebug() << "Trying to open" << uri;
233 QDesktopServices::openUrl(uri); //url?
236void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
238 m_unityScope = scope;
240 if (QString::fromStdString(m_unityScope->results()->swarm_name) == QString(":local")) {
241 m_results->setModel(m_unityScope->results()->model());
243 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
246 if (QString::fromStdString(m_unityScope->categories()->swarm_name) == QString(":local")) {
247 m_categories->setModel(m_unityScope->categories()->model());
249 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
252 /* Property change signals */
253 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
254 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
255 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
256 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
257 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
258 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
259 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
260 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
261 m_unityScope->results.changed.connect(sigc::mem_fun(this, &Scope::onResultsChanged));
262 m_unityScope->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onResultsSwarmNameChanged));
263 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
264 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesModelChanged));
265 m_unityScope->categories.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesChanged));
266 m_unityScope->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesSwarmNameChanged));
267 /* Signals forwarding */
268 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
270 /* FIXME: signal should be forwarded instead of calling the handler directly */
271 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
273 m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
275 /* Synchronize local states with m_unityScope right now and whenever
276 m_unityScope becomes connected */
277 /* FIXME: should emit change notification signals for all properties */
278 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
282unity::dash::Scope::Ptr Scope::unityScope() const
287void Scope::synchronizeStates()
290 /* Forward local states to m_unityScope */
291 if (!m_searchQuery.isNull()) {
292 m_unityScope->Search(m_searchQuery.toStdString());
297void Scope::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
299 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
302void Scope::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
304 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
307void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
309 m_results->setModel(m_unityScope->results()->model());
312void Scope::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
314 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
317void Scope::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
319 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
322void Scope::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
324 m_categories->setModel(model);
327void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
331 if (!m_unityScope->results()->count()) {
332 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
333 if (it != hints.end()) {
334 hint = QString::fromStdString(it->second.GetString());
336 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
340 setNoResultsHint(hint);
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