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/>.
22#include "categories.h"
27#include <QtGui/QDesktopServices>
31Scope::Scope(QObject *parent) :
34 m_results = new DeeListModel(this);
35 m_categories = new Categories(this);
37 m_categories->setResultModel(m_results);
40QString Scope::id() const
42 return QString::fromStdString(m_unityScope->id());
45QString Scope::name() const
47 return QString::fromStdString(m_unityScope->name());
50QString Scope::iconHint() const
52 return QString::fromStdString(m_unityScope->icon_hint());
55QString Scope::description() const
57 return QString::fromStdString(m_unityScope->description());
60QString Scope::searchHint() const
62 return QString::fromStdString(m_unityScope->search_hint());
65bool Scope::visible() const
67 return m_unityScope->visible();
70QString Scope::shortcut() const
72 return QString::fromStdString(m_unityScope->shortcut());
75bool Scope::connected() const
77 return m_unityScope->connected();
80DeeListModel* Scope::results() const
85Categories* Scope::categories() const
90QString Scope::searchQuery() const
95QString Scope::noResultsHint() const
97 return m_noResultsHint;
100void Scope::setSearchQuery(const QString& search_query)
102 /* Checking for m_searchQuery.isNull() which returns true only when the string
103 has never been set is necessary because when search_query is the empty
104 string ("") and m_searchQuery is the null string,
105 search_query != m_searchQuery is still true.
107 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
108 m_searchQuery = search_query;
109 m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
110 Q_EMIT searchQueryChanged();
114void Scope::setNoResultsHint(const QString& hint) {
115 if (hint != m_noResultsHint) {
116 m_noResultsHint = hint;
117 Q_EMIT noResultsHintChanged();
121void Scope::activate(const QString& /*uri*/)
124 // we need to create unity::dash::LocalResult (see UnityCore/Result.h) and pass it to Activate;
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());
129void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
131 if (type == unity::dash::NOT_HANDLED) {
132 fallbackActivate(QString::fromStdString(result.uri));
136void Scope::fallbackActivate(const QString& uri)
138 /* FIXME: stripping all content before the first column because for some
139 reason the scopes give uri with junk content at their beginning.
141 QString tweakedUri = uri;
142 int firstColumnAt = tweakedUri.indexOf(":");
143 tweakedUri.remove(0, firstColumnAt+1);
145 /* Tries various methods to trigger a sensible action for the given 'uri'.
146 If it has no understanding of the given scheme it falls back on asking
149 QUrl url(tweakedUri);
150 if (url.scheme() == "file") {
151 /* Override the files place's default URI handler: we want the file
152 manager to handle opening folders, not the dash.
154 Ref: https://bugs.launchpad.net/upicek/+bug/689667
156 QDesktopServices::openUrl(url);
159 if (url.scheme() == "application") {
160 // TODO: implement application handling
164 qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
165 qWarning() << "Trying to open" << tweakedUri;
167 QDesktopServices::openUrl(url);
170void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
172 m_unityScope = scope;
174 if (QString::fromStdString(m_unityScope->results()->swarm_name) == QString(":local")) {
175 m_results->setModel(m_unityScope->results()->model());
177 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
180 if (QString::fromStdString(m_unityScope->categories()->swarm_name) == QString(":local")) {
181 m_categories->setModel(m_unityScope->categories()->model());
183 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
186 /* Property change signals */
187 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
188 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
189 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
190 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
191 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
192 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
193 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
194 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
195 m_unityScope->results.changed.connect(sigc::mem_fun(this, &Scope::onResultsChanged));
196 m_unityScope->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onResultsSwarmNameChanged));
197 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
198 m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesModelChanged));
199 m_unityScope->categories.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesChanged));
200 m_unityScope->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Scope::onCategoriesSwarmNameChanged));
201 /* Signals forwarding */
202 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
204 /* FIXME: signal should be forwarded instead of calling the handler directly */
205 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
207 /* Synchronize local states with m_unityScope right now and whenever
208 m_unityScope becomes connected */
209 /* FIXME: should emit change notification signals for all properties */
210 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
214unity::dash::Scope::Ptr Scope::unityScope() const
219void Scope::synchronizeStates()
222 /* Forward local states to m_unityScope */
223 if (!m_searchQuery.isNull()) {
224 m_unityScope->Search(m_searchQuery.toStdString());
229void Scope::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
231 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
234void Scope::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
236 m_results->setName(QString::fromStdString(m_unityScope->results()->swarm_name));
239void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
241 m_results->setModel(m_unityScope->results()->model());
244void Scope::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
246 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
249void Scope::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
251 m_categories->setName(QString::fromStdString(m_unityScope->categories()->swarm_name));
254void Scope::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
256 m_categories->setModel(model);
259void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
263 if (!m_unityScope->results()->count()) {
264 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
265 if (it != hints.end()) {
266 hint = QString::fromStdString(it->second.GetString());
268 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
272 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