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>
31Lens::Lens(QObject *parent) :
34 m_results = new DeeListModel(this);
35 //m_globalResults = new DeeListModel(this);
36 m_categories = new Categories(this);
38 m_categories->setResultModel(m_results);
39// m_categories->setGlobalResultModel(m_globalResults);
42QString Lens::id() const
44 return QString::fromStdString(m_unityLens->id());
47/*QString Lens::dbusName() const
49 return QString::fromStdString(m_unityLens->dbus_name());
52QString Lens::dbusPath() const
54 return QString::fromStdString(m_unityLens->dbus_path());
57QString Lens::name() const
59 return QString::fromStdString(m_unityLens->name());
62QString Lens::iconHint() const
64 return QString::fromStdString(m_unityLens->icon_hint());
67QString Lens::description() const
69 return QString::fromStdString(m_unityLens->description());
72QString Lens::searchHint() const
74 return QString::fromStdString(m_unityLens->search_hint());
77bool Lens::visible() const
79 return m_unityLens->visible();
82/*bool Lens::searchInGlobal() const
84 return m_unityLens->search_in_global();
87QString Lens::shortcut() const
89 return QString::fromStdString(m_unityLens->shortcut());
92bool Lens::connected() const
94 return m_unityLens->connected();
97DeeListModel* Lens::results() const
102/*DeeListModel* Lens::globalResults() const
104 return m_globalResults;
107Categories* Lens::categories() const
112Lens::ViewType Lens::viewType() const
114 return (Lens::ViewType) m_unityLens->view_type();
117QString Lens::searchQuery() const
119 return m_searchQuery;
122/*QString Lens::globalSearchQuery() const
124 return m_globalSearchQuery;
127QString Lens::noResultsHint() const
129 return m_noResultsHint;
132void Lens::setViewType(const Lens::ViewType& viewType)
134 m_unityLens->view_type = (unity::dash::ScopeViewType) viewType;
137void Lens::setSearchQuery(const QString& search_query)
139 /* Checking for m_searchQuery.isNull() which returns true only when the string
140 has never been set is necessary because when search_query is the empty
141 string ("") and m_searchQuery is the null string,
142 search_query != m_searchQuery is still true.
144 if (m_searchQuery.isNull() || search_query != m_searchQuery) {
145 m_searchQuery = search_query;
146 m_unityLens->Search(search_query.toStdString(), sigc::mem_fun(this, &Lens::searchFinished));
147 Q_EMIT searchQueryChanged();
151//void Lens::setGlobalSearchQuery(const QString& search_query)
153 /* Checking for m_globalSearchQuery.isNull() which returns true only when the string
154 has never been set is necessary because when search_query is the empty
155 string ("") and m_globalSearchQuery is the null string,
156 search_query != m_globalSearchQuery is still true.
158/* if (m_globalSearchQuery.isNull() || search_query != m_globalSearchQuery) {
159 m_globalSearchQuery = search_query;
160 m_unityLens->GlobalSearch(search_query.toStdString(), sigc::mem_fun(this, &Lens::globalSearchFinished));
161 Q_EMIT globalSearchQueryChanged();
165void Lens::setNoResultsHint(const QString& hint) {
166 if (hint != m_noResultsHint) {
167 m_noResultsHint = hint;
168 Q_EMIT noResultsHintChanged();
172void Lens::activate(const QString& uri)
174 // m_unityLens->Activate(QByteArray::fromPercentEncoding(uri.toUtf8()).constData()); FIXME pawel
177void Lens::onActivated(std::string const& uri, unity::dash::ScopeHandledType type, unity::glib::HintsMap const&)
179 if (type == unity::dash::NOT_HANDLED) {
180 fallbackActivate(QString::fromStdString(uri));
184void Lens::fallbackActivate(const QString& uri)
186 /* FIXME: stripping all content before the first column because for some
187 reason the lenses give uri with junk content at their beginning.
189 QString tweakedUri = uri;
190 int firstColumnAt = tweakedUri.indexOf(":");
191 tweakedUri.remove(0, firstColumnAt+1);
193 /* Tries various methods to trigger a sensible action for the given 'uri'.
194 If it has no understanding of the given scheme it falls back on asking
197 QUrl url(tweakedUri);
198 if (url.scheme() == "file") {
199 /* Override the files place's default URI handler: we want the file
200 manager to handle opening folders, not the dash.
202 Ref: https://bugs.launchpad.net/upicek/+bug/689667
204 QDesktopServices::openUrl(url);
207 if (url.scheme() == "application") {
208 // TODO: implement application handling
212 qWarning() << "FIXME: Possibly no handler for scheme: " << url.scheme();
213 qWarning() << "Trying to open" << tweakedUri;
215 QDesktopServices::openUrl(url);
218void Lens::setUnityLens(const unity::dash::Scope::Ptr& lens)
221// m_results->setModel(m_unityLens->results()->model());
223 if (QString::fromStdString(m_unityLens->results()->swarm_name) == QString(":local")) {
224 m_results->setModel(m_unityLens->results()->model());
226 m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
228/* if (QString::fromStdString(m_unityLens->global_results()->swarm_name) == QString(":local")) {
229 m_globalResults->setModel(m_unityLens->global_results()->model());
231 m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
234 if (QString::fromStdString(m_unityLens->categories()->swarm_name) == QString(":local")) {
235 m_categories->setModel(m_unityLens->categories()->model());
237 m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
240 /* Property change signals */
241 m_unityLens->id.changed.connect(sigc::mem_fun(this, &Lens::idChanged));
242// m_unityLens->dbus_name.changed.connect(sigc::mem_fun(this, &Lens::dbusNameChanged));
243// m_unityLens->dbus_path.changed.connect(sigc::mem_fun(this, &Lens::dbusPathChanged));
244 m_unityLens->name.changed.connect(sigc::mem_fun(this, &Lens::nameChanged));
245 m_unityLens->icon_hint.changed.connect(sigc::mem_fun(this, &Lens::iconHintChanged));
246 m_unityLens->description.changed.connect(sigc::mem_fun(this, &Lens::descriptionChanged));
247 m_unityLens->search_hint.changed.connect(sigc::mem_fun(this, &Lens::searchHintChanged));
248 m_unityLens->visible.changed.connect(sigc::mem_fun(this, &Lens::visibleChanged));
249// m_unityLens->search_in_global.changed.connect(sigc::mem_fun(this, &Lens::searchInGlobalChanged));
250 m_unityLens->shortcut.changed.connect(sigc::mem_fun(this, &Lens::shortcutChanged));
251 m_unityLens->connected.changed.connect(sigc::mem_fun(this, &Lens::connectedChanged));
252 m_unityLens->results.changed.connect(sigc::mem_fun(this, &Lens::onResultsChanged));
253 m_unityLens->results()->swarm_name.changed.connect(sigc::mem_fun(this, &Lens::onResultsSwarmNameChanged));
254 m_unityLens->results()->model.changed.connect(sigc::mem_fun(this, &Lens::onResultsModelChanged));
255// m_unityLens->global_results.changed.connect(sigc::mem_fun(this, &Lens::onGlobalResultsChanged));
256// m_unityLens->global_results()->swarm_name.changed.connect(sigc::mem_fun(this, &Lens::onGlobalResultsSwarmNameChanged));
257 m_unityLens->categories()->model.changed.connect(sigc::mem_fun(this, &Lens::onCategoriesModelChanged));
258 m_unityLens->categories.changed.connect(sigc::mem_fun(this, &Lens::onCategoriesChanged));
259 m_unityLens->categories()->swarm_name.changed.connect(sigc::mem_fun(this, &Lens::onCategoriesSwarmNameChanged));
260 m_unityLens->view_type.changed.connect(sigc::mem_fun(this, &Lens::onViewTypeChanged));
262 /* Signals forwarding */
263 connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
265 /* FIXME: signal should be forwarded instead of calling the handler directly */
266 //unityLens->activated.connect(sigc::mem_fun(this, &Lens::onActivated)); //FIXME pawel
268 /* Synchronize local states with m_unityLens right now and whenever
269 m_unityLens becomes connected */
270 /* FIXME: should emit change notification signals for all properties */
271 connect(this, SIGNAL(connectedChanged(bool)), SLOT(synchronizeStates()));
275unity::dash::Scope::Ptr Lens::unityLens() const
280void Lens::synchronizeStates()
283 /* Forward local states to m_unityLens */
284 if (!m_searchQuery.isNull()) {
285 m_unityLens->Search(m_searchQuery.toStdString());
287 /*if (!m_globalSearchQuery.isNull()) {
288 m_unityLens->GlobalSearch(m_globalSearchQuery.toStdString());
293void Lens::onResultsSwarmNameChanged(const std::string& /* swarm_name */)
295 m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
298void Lens::onResultsChanged(const unity::dash::Results::Ptr& /* results */)
300 m_results->setName(QString::fromStdString(m_unityLens->results()->swarm_name));
303void Lens::onResultsModelChanged(unity::glib::Object<DeeModel> model)
305 m_results->setModel(m_unityLens->results()->model());
308//void Lens::onGlobalResultsSwarmNameChanged(const std::string& /* swarm_name */)
310// m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
313//id Lens::onGlobalResultsChanged(const unity::dash::Results::Ptr& /* global_results */)
315// m_globalResults->setName(QString::fromStdString(m_unityLens->global_results()->swarm_name));
318void Lens::onCategoriesSwarmNameChanged(const std::string& /* swarm_name */)
320 m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
323void Lens::onCategoriesChanged(const unity::dash::Categories::Ptr& /* categories */)
325 qWarning() << "categories changed!";
326 m_categories->setName(QString::fromStdString(m_unityLens->categories()->swarm_name));
329void Lens::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
331 qWarning() << "categories model changed!";
332 m_categories->setModel(model);
335void Lens::onViewTypeChanged(unity::dash::ScopeViewType viewType)
337 Q_EMIT viewTypeChanged( (Lens::ViewType) viewType);
340void Lens::onSearchFinished(const std::string &query, unity::glib::HintsMap const &hints)
344 qWarning() << "Result count:" << id() << m_unityLens->results()->count() << QString::fromStdString(m_unityLens->results()->swarm_name) << m_categories->rowCount();
345 if (!m_unityLens->results()->count()) {
346 unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
347 if (it != hints.end()) {
348 hint = QString::fromStdString(it->second.GetString());
350 hint = QString::fromUtf8(dgettext("unity", "Sorry, there is nothing that matches your search."));
354 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