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.reset(new DeeListModel(this));
35 m_categories.reset(new Categories(this));
38QString Scope::id() const
40 return QString::fromStdString(m_unityScope->id());
43QString Scope::name() const
45 return QString::fromStdString(m_unityScope->name());
48QString Scope::iconHint() const
50 return QString::fromStdString(m_unityScope->icon_hint());
53QString Scope::description() const
55 return QString::fromStdString(m_unityScope->description());
58QString Scope::searchHint() const
60 return QString::fromStdString(m_unityScope->search_hint());
63bool Scope::visible() const
65 return m_unityScope->visible();
68QString Scope::shortcut() const
70 return QString::fromStdString(m_unityScope->shortcut());
73bool Scope::connected() const
75 return m_unityScope->connected();
78Categories* Scope::categories() const
80 return m_categories.get();
83QString Scope::searchQuery() const
88QString Scope::noResultsHint() const
90 return m_noResultsHint;
93QString Scope::formFactor() const
98void Scope::setSearchQuery(const QString& search_query)
100 /* Checking for m_searchQuery.isNull() which returns true only when the string
101 has never been set is necessary because when search_query is the empty
102 string ("") and m_searchQuery is the null string,
103 search_query != m_searchQuery is still true.
105 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
106 m_searchQuery = search_query;
107 m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
108 Q_EMIT searchQueryChanged();
112void Scope::setNoResultsHint(const QString& hint) {
113 if (hint != m_noResultsHint) {
114 m_noResultsHint = hint;
115 Q_EMIT noResultsHintChanged();
119void Scope::setFormFactor(const QString& form_factor) {
120 if (form_factor != m_formFactor) {
121 m_formFactor = form_factor;
123 m_unityScope->form_factor = m_formFactor.toStdString();
125 Q_EMIT formFactorChanged();
129void Scope::activate(const QString& /*uri*/)
132 // we need to create unity::dash::LocalResult (see UnityCore/Result.h) and pass it to Activate;
133 // this requires entire row from the model, so we need row index rather than uri.
134 // m_unityScope->Activate(QByteArray::fromPercentEncoding(uri.toUtf8()).constData());
137void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
139 if (type == unity::dash::NOT_HANDLED) {
140 fallbackActivate(QString::fromStdString(result.uri));
144void Scope::fallbackActivate(const QString& uri)
146 /* FIXME: stripping all content before the first column because for some
147 reason the scopes give uri with junk content at their beginning.
149 QString tweakedUri = uri;
150 int firstColumnAt = tweakedUri.indexOf(":");
151 tweakedUri.remove(0, firstColumnAt+1);
153 /* Tries various methods to trigger a sensible action for the given 'uri'.
154 If it has no understanding of the given scheme it falls back on asking
157 QUrl url(tweakedUri);
158 if (url.scheme() == "file") {
159 /* Override the files place's default URI handler: we want the file
160 manager to handle opening folders, not the dash.
162 Ref: https://bugs.launchpad.net/upicek/+bug/689667
164 QDesktopServices::openUrl(url);
167 if (url.scheme() == "application") {
168 // TODO: implement application handling
172 qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
173 qWarning() << "Trying to open" << tweakedUri;
175 QDesktopServices::openUrl(url);
178void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
180 m_unityScope = scope;
182 // TODO: do we even need this?
183 m_results->setModel(m_unityScope->results()->model());
184 m_categories->setUnityScope(m_unityScope);
186 m_unityScope->form_factor = m_formFactor.toStdString();
187 /* Property change signals */
188 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
189 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
190 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
191 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
192 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
193 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
194 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
195 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
196 m_unityScope->results()->model.changed.connect(sigc::mem_fun(this, &Scope::onResultsModelChanged));
197 /* Signals forwarding */
198 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
200 /* FIXME: signal should be forwarded instead of calling the handler directly */
201 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
203 /* Synchronize local states with m_unityScope right now and whenever
204 m_unityScope becomes connected */
205 /* FIXME: should emit change notification signals for all properties */
206 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
210unity::dash::Scope::Ptr Scope::unityScope() const
215void Scope::synchronizeStates()
218 /* Forward local states to m_unityScope */
219 if (!m_searchQuery.isNull()) {
220 m_unityScope->Search(m_searchQuery.toStdString());
225void Scope::onResultsModelChanged(unity::glib::Object<DeeModel> /* model */)
227 m_results->setModel(m_unityScope->results()->model());
230void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
234 if (!m_unityScope->results()->count()) {
235 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
236 if (it != hints.end()) {
237 hint = QString::fromStdString(it->second.GetString());
239 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
243 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