~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to tests/daemon/dbus/xesamlistener.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2011-09-20 08:50:25 UTC
  • mto: (1.1.20 upstream) (5.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110920085025-wszfu6x8rshrjq0e
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Strigi Desktop Search
2
 
 *
3
 
 * Copyright (C) 2008 Jos van den Oever <jos@vandenoever.info>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public License
16
 
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
#include "xesamlistener.h"
21
 
#include "xesam/xesamdbus.h"
22
 
#include <QtCore/QDebug>
23
 
#include <QtCore/QTimer>
24
 
#include <QtCore/QTime>
25
 
 
26
 
XesamListener::XesamListener(OrgFreedesktopXesamSearchInterface* xesam)
27
 
        :eventloop(this) {
28
 
    connect(xesam, SIGNAL(HitsAdded(const QString&, uint)),
29
 
        this, SLOT(slotHitsAdded(const QString&, uint)));
30
 
    connect(xesam, SIGNAL(HitsRemoved(const QString &, const QList<uint> &)),
31
 
        this, SLOT(slotHitsRemoved(const QString &, const QList<uint> &)));
32
 
    connect(xesam, SIGNAL(SearchDone(const QString&)),
33
 
        this, SLOT(slotSearchDone(const QString&)));
34
 
    connect(xesam, SIGNAL(StateChanged(const QStringList&)),
35
 
        this, SLOT(slotStateChanged(const QStringList&)));
36
 
}
37
 
bool
38
 
XesamListener::waitForSearchToFinish(const QString& searchid,
39
 
        int millisecondtimeout) {
40
 
    QTime time;
41
 
    time.start();
42
 
    int left = millisecondtimeout;
43
 
    bool finished = finishedSearches.contains(searchid);
44
 
    while (left > 0 && !finished) {
45
 
        QTimer::singleShot(left, &eventloop, SLOT(quit()));
46
 
        eventloop.exec();
47
 
        left = millisecondtimeout - time.elapsed();
48
 
        finished = finishedSearches.contains(searchid);
49
 
    }
50
 
    return finished;
51
 
}
52
 
 uint
53
 
XesamListener::getNumberOfReportedHits(const QString& searchid) const {
54
 
    return hitsReported.value(searchid);
55
 
}
56
 
void
57
 
XesamListener::slotHitsAdded(const QString &search, uint count) {
58
 
    hitsReported[search] += count;
59
 
    eventloop.quit();
60
 
}
61
 
void
62
 
XesamListener::slotHitsModified(const QString &search,
63
 
        const QList<uint> &hit_ids) {
64
 
    eventloop.quit();
65
 
}
66
 
void
67
 
XesamListener::slotHitsRemoved(const QString &search,
68
 
        const QList<uint> &hit_ids) {
69
 
    eventloop.quit();
70
 
}
71
 
void
72
 
XesamListener::slotSearchDone(const QString &search) {
73
 
    finishedSearches.append(search);
74
 
    eventloop.quit();
75
 
}
76
 
void
77
 
XesamListener::slotStateChanged(const QStringList &state_info) {
78
 
    eventloop.quit();
79
 
}