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_categories.reset(new Categories(this));
37QString Scope::id() const
39 return QString::fromStdString(m_unityScope->id());
42QString Scope::name() const
44 return QString::fromStdString(m_unityScope->name());
47QString Scope::iconHint() const
49 return QString::fromStdString(m_unityScope->icon_hint());
52QString Scope::description() const
54 return QString::fromStdString(m_unityScope->description());
57QString Scope::searchHint() const
59 return QString::fromStdString(m_unityScope->search_hint());
62bool Scope::visible() const
64 return m_unityScope->visible();
67QString Scope::shortcut() const
69 return QString::fromStdString(m_unityScope->shortcut());
72bool Scope::connected() const
74 return m_unityScope->connected();
77Categories* Scope::categories() const
79 return m_categories.get();
82QString Scope::searchQuery() const
87QString Scope::noResultsHint() const
89 return m_noResultsHint;
92QString Scope::formFactor() const
97void Scope::setSearchQuery(const QString& search_query)
99 /* Checking for m_searchQuery.isNull() which returns true only when the string
100 has never been set is necessary because when search_query is the empty
101 string ("") and m_searchQuery is the null string,
102 search_query != m_searchQuery is still true.
104 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
105 m_searchQuery = search_query;
106 m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
107 Q_EMIT searchQueryChanged();
111void Scope::setNoResultsHint(const QString& hint) {
112 if (hint != m_noResultsHint) {
113 m_noResultsHint = hint;
114 Q_EMIT noResultsHintChanged();
118void Scope::setFormFactor(const QString& form_factor) {
119 if (form_factor != m_formFactor) {
120 m_formFactor = form_factor;
122 m_unityScope->form_factor = m_formFactor.toStdString();
124 Q_EMIT formFactorChanged();
128void Scope::activate(const QString& /*uri*/)
131 // we need to create unity::dash::LocalResult (see UnityCore/Result.h) and pass it to Activate;
132 // this requires entire row from the model, so we need row index rather than uri.
133 // m_unityScope->Activate(QByteArray::fromPercentEncoding(uri.toUtf8()).constData());
136void Scope::onActivated(unity::dash::LocalResult const& result, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
138 if (type == unity::dash::NOT_HANDLED) {
139 fallbackActivate(QString::fromStdString(result.uri));
143void Scope::fallbackActivate(const QString& uri)
145 /* FIXME: stripping all content before the first column because for some
146 reason the scopes give uri with junk content at their beginning.
148 QString tweakedUri = uri;
149 int firstColumnAt = tweakedUri.indexOf(":");
150 tweakedUri.remove(0, firstColumnAt+1);
152 /* Tries various methods to trigger a sensible action for the given 'uri'.
153 If it has no understanding of the given scheme it falls back on asking
156 QUrl url(tweakedUri);
157 if (url.scheme() == "file") {
158 /* Override the files place's default URI handler: we want the file
159 manager to handle opening folders, not the dash.
161 Ref: https://bugs.launchpad.net/upicek/+bug/689667
163 QDesktopServices::openUrl(url);
166 if (url.scheme() == "application") {
167 // TODO: implement application handling
171 qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
172 qWarning() << "Trying to open" << tweakedUri;
174 QDesktopServices::openUrl(url);
177void Scope::setUnityScope(const unity::dash::Scope::Ptr& scope)
179 m_unityScope = scope;
181 m_categories->setUnityScope(m_unityScope);
183 m_unityScope->form_factor = m_formFactor.toStdString();
184 /* Property change signals */
185 m_unityScope->id.changed.connect(sigc::mem_fun(this, &Scope::idChanged));
186 m_unityScope->name.changed.connect(sigc::mem_fun(this, &Scope::nameChanged));
187 m_unityScope->icon_hint.changed.connect(sigc::mem_fun(this, &Scope::iconHintChanged));
188 m_unityScope->description.changed.connect(sigc::mem_fun(this, &Scope::descriptionChanged));
189 m_unityScope->search_hint.changed.connect(sigc::mem_fun(this, &Scope::searchHintChanged));
190 m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
191 m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
192 m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
193 /* Signals forwarding */
194 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
196 /* FIXME: signal should be forwarded instead of calling the handler directly */
197 m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
199 /* Synchronize local states with m_unityScope right now and whenever
200 m_unityScope becomes connected */
201 /* FIXME: should emit change notification signals for all properties */
202 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
206unity::dash::Scope::Ptr Scope::unityScope() const
211void Scope::synchronizeStates()
214 /* Forward local states to m_unityScope */
215 if (!m_searchQuery.isNull()) {
216 m_unityScope->Search(m_searchQuery.toStdString());
221void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
225 if (!m_unityScope->results()->count()) {
226 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
227 if (it != hints.end()) {
228 hint = QString::fromStdString(it->second.GetString());
230 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
234 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