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);
149void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
150 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
151 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
153 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
154 m_unityScope->Activate(res);
157void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
158 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
159 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
161 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
162 m_unityScope->Preview(res);
165void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const& hints)
167 // note: we will not get called on SHOW_PREVIEW, instead UnityCore will signal preview_ready.
170 case unity::dash::NOT_HANDLED:
171 fallbackActivate(QString::fromStdString(result.uri));
173 case unity::dash::SHOW_DASH:
176 case unity::dash::HIDE_DASH:
179 case unity::dash::GOTO_DASH_URI:
180 if (hints.find("goto-uri") != hints.end()) {
181 Q_EMIT gotoUri(QString::fromStdString(g_variant_get_string(hints.at("goto-uri"), nullptr)));
183 qWarning() << "Missing goto-uri hint for GOTO_DASH_URI activation reply";
187 qWarning() << "Unhandled activation response:" << type;
191void Scope::onPreviewReady(unity::dash::LocalResult const& /* result */, unity::dash::Preview::Ptr const& preview)
193 auto prv = Preview::newFromUnityPreview(preview);
194 // is this the best solution? QML may need to keep more than one preview instance around, so we can't own it.
195 // passing it by value is not possible.
196 QQmlEngine::setObjectOwnership(prv, QQmlEngine::JavaScriptOwnership);
197 Q_EMIT previewReady(prv);
200void Scope::fallbackActivate(const QString& uri)
202 /* FIXME: stripping all content before the first column because for some
203 reason the scopes give uri with junk content at their beginning.
205 QString tweakedUri = uri;
206 int firstColumnAt = tweakedUri.indexOf(":");
207 tweakedUri.remove(0, firstColumnAt+1);
209 /* Tries various methods to trigger a sensible action for the given 'uri'.
210 If it has no understanding of the given scheme it falls back on asking
213 QUrl url(tweakedUri);
214 if (url.scheme() == "file") {
215 /* Override the files place's default URI handler: we want the file
216 manager to handle opening folders, not the dash.
218 Ref: https://bugs.launchpad.net/upicek/+bug/689667
220 QDesktopServices::openUrl(url);
223 if (url.scheme() == "application") {
224 // TODO: implement application handling
228 qDebug() << "Trying to open" << uri;
231 QDesktopServices::openUrl(uri); //url?
234void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
236 m_unityScope = scope;
238 if (QString::fromStdString(m_unityScope->results()->swarm_name) == QString(":local")) {
239 m_results->setModel(m_unityScope->results()->model());
241 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
244 if (QString::fromStdString(m_unityScope->categories()->swarm_name) == QString(":local")) {
245 m_categories->setModel(m_unityScope->categories()->model());
247 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
250 /* Property change signals */
251 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
252 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
253 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
254 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
255 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
256 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
257 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
258 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
259 m_unityScope->results.changed.connect(sigc::mem_fun(this, &Scope::onResultsChanged));
260 m_unityScope->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onResultsSwarmNameChanged));
261 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
262 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesModelChanged));
263 m_unityScope->categories.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesChanged));
264 m_unityScope->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesSwarmNameChanged));
265 /* Signals forwarding */
266 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
268 /* FIXME: signal should be forwarded instead of calling the handler directly */
269 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
271 m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
273 /* Synchronize local states with m_unityScope right now and whenever
274 m_unityScope becomes connected */
275 /* FIXME: should emit change notification signals for all properties */
276 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
280unity::dash::Scope::Ptr Scope::unityScope() const
285void Scope::synchronizeStates()
288 /* Forward local states to m_unityScope */
289 if (!m_searchQuery.isNull()) {
290 m_unityScope->Search(m_searchQuery.toStdString());
295void Scope::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
297 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
300void Scope::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
302 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
305void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
307 m_results->setModel(m_unityScope->results()->model());
310void Scope::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
312 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
315void Scope::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
317 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
320void Scope::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
322 m_categories->setModel(model);
325void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
329 if (!m_unityScope->results()->count()) {
330 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
331 if (it != hints.end()) {
332 hint = QString::fromStdString(it->second.GetString());
334 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
338 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