~stolowski/unity8/monitor-network

« back to all changes in this revision

Viewing changes to plugins/Unity/scope.cpp

  • Committer: Michal Hruby
  • Date: 2013-09-19 14:37:02 UTC
  • Revision ID: michal.mhr@gmail.com-20130919143702-x96thxc42v0iz34k
Add new searchInProgress property

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <QQmlEngine>
34
34
 
35
35
#include <UnityCore/Variant.h>
 
36
#include <UnityCore/GLibWrapper.h>
36
37
 
37
38
#include <libintl.h>
38
39
#include <glib.h>
39
40
 
40
41
Scope::Scope(QObject *parent) : QObject(parent)
41
42
    , m_formFactor("phone")
 
43
    , m_searchInProgress(false)
42
44
{
43
45
    m_categories.reset(new Categories(this));
44
46
}
68
70
    return QString::fromStdString(m_unityScope->search_hint());
69
71
}
70
72
 
 
73
bool Scope::searchInProgress() const
 
74
{
 
75
    return m_searchInProgress;
 
76
}
 
77
 
71
78
bool Scope::visible() const
72
79
{
73
80
    return m_unityScope->visible();
115
122
       string ("") and m_searchQuery is the null string,
116
123
       search_query != m_searchQuery is still true.
117
124
    */
 
125
    using namespace std::placeholders;
 
126
 
118
127
    if (m_searchQuery.isNull() || search_query != m_searchQuery) {
119
128
        m_searchQuery = search_query;
120
 
        m_unityScope->Search(search_query.toStdString(), sigc::mem_fun(this, &Scope::searchFinished));
 
129
        m_cancellable.Renew();
 
130
        m_searchInProgress = true;
 
131
        m_unityScope->Search(search_query.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
121
132
        Q_EMIT searchQueryChanged();
 
133
        Q_EMIT searchInProgressChanged();
122
134
    }
123
135
}
124
136
 
275
287
    m_unityScope->visible.changed.connect(sigc::mem_fun(this, &Scope::visibleChanged));
276
288
    m_unityScope->shortcut.changed.connect(sigc::mem_fun(this, &Scope::shortcutChanged));
277
289
    m_unityScope->connected.changed.connect(sigc::mem_fun(this, &Scope::connectedChanged));
278
 
    /* Signals forwarding */
279
 
    connect(this, SIGNAL(searchFinished(const std::string &, unity::glib::HintsMap const &, unity::glib::Error const &)), SLOT(onSearchFinished(const std::string &, unity::glib::HintsMap const &)));
280
290
 
281
291
    /* FIXME: signal should be forwarded instead of calling the handler directly */
282
292
    m_unityScope->activated.connect(sigc::mem_fun(this, &Scope::onActivated));
297
307
 
298
308
void Scope::synchronizeStates()
299
309
{
 
310
    using namespace std::placeholders;
 
311
 
300
312
    if (connected()) {
301
313
        /* Forward local states to m_unityScope */
302
314
        if (!m_searchQuery.isNull()) {
303
 
            m_unityScope->Search(m_searchQuery.toStdString());
 
315
            m_cancellable.Renew();
 
316
            m_searchInProgress = true;
 
317
            m_unityScope->Search(m_searchQuery.toStdString(), std::bind(&Scope::onSearchFinished, this, _1, _2, _3), m_cancellable);
 
318
            Q_EMIT searchInProgressChanged();
304
319
        }
305
320
    }
306
321
}
307
322
 
308
 
void Scope::onSearchFinished(const std::string& /* query */, unity::glib::HintsMap const &hints)
 
323
void Scope::onSearchFinished(std::string const& query, unity::glib::HintsMap const& hints, unity::glib::Error const& err)
309
324
{
310
325
    QString hint;
311
326
 
 
327
    GError* error = const_cast<unity::glib::Error&>(err);
 
328
 
 
329
    if (!err || !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 
330
        m_searchInProgress = false;
 
331
        Q_EMIT searchInProgressChanged();
 
332
        qWarning("search for %s finished", query.c_str());
 
333
    }
 
334
 
312
335
    if (!m_unityScope->results()->count()) {
313
336
        unity::glib::HintsMap::const_iterator it = hints.find("no-results-hint");
314
337
        if (it != hints.end()) {