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>
35Scope::Scope(QObject *parent) :
38 m_results = new DeeListModel(this);
39 m_categories = new Categories(this);
41 m_categories->setResultModel(m_results);
44QString Scope::id() const
46 return QString::fromStdString(m_unityScope->id());
49QString Scope::name() const
51 return QString::fromStdString(m_unityScope->name());
54QString Scope::iconHint() const
56 return QString::fromStdString(m_unityScope->icon_hint());
59QString Scope::description() const
61 return QString::fromStdString(m_unityScope->description());
64QString Scope::searchHint() const
66 return QString::fromStdString(m_unityScope->search_hint());
69bool Scope::visible() const
71 return m_unityScope->visible();
74QString Scope::shortcut() const
76 return QString::fromStdString(m_unityScope->shortcut());
79bool Scope::connected() const
81 return m_unityScope->connected();
84DeeListModel* Scope::results() const
89Categories* Scope::categories() const
94QString Scope::searchQuery() const
99QString Scope::noResultsHint() const
101 return m_noResultsHint;
104void Scope::setSearchQuery(const QString& search_query)
106 /* Checking for m_searchQuery.isNull() which returns true only when the string
107 has never been set is necessary because when search_query is the empty
108 string ("") and m_searchQuery is the null string,
109 search_query != m_searchQuery is still true.
111 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
112 m_searchQuery = search_query;
113 m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
114 Q_EMIT searchQueryChanged();
118void Scope::setNoResultsHint(const QString& hint) {
119 if (hint != m_noResultsHint) {
120 m_noResultsHint = hint;
121 Q_EMIT noResultsHintChanged();
126unity::dash::LocalResult Scope::createLocalResult(const QVariant &uri, const QVariant &icon_hint,
127 const QVariant &category, const QVariant &result_type,
128 const QVariant &mimetype, const QVariant &title,
129 const QVariant &comment, const QVariant &dnd_uri,
130 const QVariant &metadata)
132 unity::dash::LocalResult res;
133 res.uri = uri.toString().toStdString();
134 res.icon_hint = icon_hint.toString().toStdString();
135 res.category_index = category.toUInt();
136 res.result_type = result_type.toUInt();
137 res.mimetype = mimetype.toString().toStdString();
138 res.name = title.toString().toStdString();
139 res.comment = comment.toString().toStdString();
140 res.dnd_uri = dnd_uri.toString().toStdString();
141 res.hints = hintsMapFromQVariant(metadata);
146void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
147 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
148 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
150 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
151 m_unityScope->Activate(res);
154void Scope::preview(const QVariant &uri, const QVariant &icon_hint, const QVariant &category,
155 const QVariant &result_type, const QVariant &mimetype, const QVariant &title,
156 const QVariant &comment, const QVariant &dnd_uri, const QVariant &metadata)
158 auto res = createLocalResult(uri, icon_hint, category, result_type, mimetype, title, comment, dnd_uri, metadata);
159 m_unityScope->Preview(res);
162void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
164 if (type == unity::dash::NOT_HANDLED) {
165 fallbackActivate(QString::fromStdString(result.uri));
169void Scope::onPreviewReady(unity::dash::LocalResult const& result, unity::dash::Preview::Ptr const& preview)
173void Scope::fallbackActivate(const QString& uri)
175 /* FIXME: stripping all content before the first column because for some
176 reason the scopes give uri with junk content at their beginning.
178 QString tweakedUri = uri;
179 int firstColumnAt = tweakedUri.indexOf(":");
180 tweakedUri.remove(0, firstColumnAt+1);
182 /* Tries various methods to trigger a sensible action for the given 'uri'.
183 If it has no understanding of the given scheme it falls back on asking
186 QUrl url(tweakedUri);
187 if (url.scheme() == "file") {
188 /* Override the files place's default URI handler: we want the file
189 manager to handle opening folders, not the dash.
191 Ref: https://bugs.launchpad.net/upicek/+bug/689667
193 QDesktopServices::openUrl(url);
196 if (url.scheme() == "application") {
197 // TODO: implement application handling
201 qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
202 qWarning() << "Trying to open" << tweakedUri;
204 QDesktopServices::openUrl(uri); //url?
207void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
209 m_unityScope = scope;
211 if (QString::fromStdString(m_unityScope->results()->swarm_name) == QString(":local")) {
212 m_results->setModel(m_unityScope->results()->model());
214 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
217 if (QString::fromStdString(m_unityScope->categories()->swarm_name) == QString(":local")) {
218 m_categories->setModel(m_unityScope->categories()->model());
220 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
223 /* Property change signals */
224 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
225 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
226 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
227 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
228 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
229 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
230 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
231 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
232 m_unityScope->results.changed.connect(sigc::mem_fun(this, &Scope::onResultsChanged));
233 m_unityScope->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onResultsSwarmNameChanged));
234 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
235 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesModelChanged));
236 m_unityScope->categories.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesChanged));
237 m_unityScope->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesSwarmNameChanged));
238 /* Signals forwarding */
239 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
241 /* FIXME: signal should be forwarded instead of calling the handler directly */
242 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
244 m_unityScope->preview_ready.connect(sigc::mem_fun(this, &Scope::onPreviewReady));
246 /* Synchronize local states with m_unityScope right now and whenever
247 m_unityScope becomes connected */
248 /* FIXME: should emit change notification signals for all properties */
249 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
253unity::dash::Scope::Ptr Scope::unityScope() const
258void Scope::synchronizeStates()
261 /* Forward local states to m_unityScope */
262 if (!m_searchQuery.isNull()) {
263 m_unityScope->Search(m_searchQuery.toStdString());
268void Scope::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
270 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
273void Scope::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
275 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
278void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
280 m_results->setModel(m_unityScope->results()->model());
283void Scope::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
285 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
288void Scope::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
290 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
293void Scope::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
295 m_categories->setModel(model);
298void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
302 if (!m_unityScope->results()->count()) {
303 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
304 if (it != hints.end()) {
305 hint = QString::fromStdString(it->second.GetString());
307 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
311 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