2
* This file is part of the KDE Baloo Project
3
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) version 3, or any
9
* later version accepted by the membership of KDE e.V. (or its
10
* successor approved by the membership of KDE e.V.), which shall
11
* act as a proxy defined in Section 6 of version 3 of the license.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#include "emailindexer.h"
25
#include <QApplication>
29
#include <Akonadi/CollectionFetchJob>
30
#include <Akonadi/Collection>
31
#include <Akonadi/ItemFetchJob>
32
#include <Akonadi/ItemFetchScope>
33
#include <Akonadi/Item>
35
class App : public QApplication {
38
App(int& argc, char** argv, int flags = ApplicationFlags);
43
void slotRootCollectionsFetched(KJob* job);
44
void indexNextCollection();
45
void itemReceived(const Akonadi::Item::List& item);
47
void slotCommitTimerElapsed();
50
Akonadi::Collection::List m_collections;
51
EmailIndexer m_indexer;
60
int main(int argc, char** argv)
66
App::App(int& argc, char** argv, int flags)
67
: QApplication(argc, argv, flags)
68
, m_indexer("/tmp/xap", "/tmp/xapC")
70
QTimer::singleShot(0, this, SLOT(main()));
75
m_commitTimer.setInterval(1000);
76
connect(&m_commitTimer, SIGNAL(timeout()), this, SLOT(slotCommitTimerElapsed()));
77
m_commitTimer.start();
79
Akonadi::CollectionFetchJob* job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(),
80
Akonadi::CollectionFetchJob::Recursive);
81
connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotRootCollectionsFetched(KJob*)));
89
void App::slotRootCollectionsFetched(KJob* kjob)
91
Akonadi::CollectionFetchJob* job = qobject_cast<Akonadi::CollectionFetchJob*>(kjob);
92
m_collections = job->collections();
94
QMutableListIterator<Akonadi::Collection> it(m_collections);
95
while (it.hasNext()) {
96
const Akonadi::Collection& c = it.next();
97
const QStringList mimeTypes = c.contentMimeTypes();
98
if (!c.contentMimeTypes().contains("message/rfc822"))
102
if (m_collections.size()) {
103
indexNextCollection();
106
kDebug() << "No collections to index";
110
void App::indexNextCollection()
112
Akonadi::ItemFetchJob *fetchJob = new Akonadi::ItemFetchJob(m_collections.takeFirst(), this);
113
fetchJob->fetchScope().fetchAllAttributes(true);
114
fetchJob->fetchScope().fetchFullPayload(true);
115
fetchJob->fetchScope().setFetchModificationTime(false);
116
fetchJob->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
117
fetchJob->setDeliveryOption(Akonadi::ItemFetchJob::EmitItemsIndividually);
119
connect(fetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)), this, SLOT(itemReceived(Akonadi::Item::List)));
120
connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(slotIndexed()));
123
void App::itemReceived(const Akonadi::Item::List& itemList)
128
Q_FOREACH (const Akonadi::Item& item, itemList) {
129
m_indexer.index(item);
132
m_indexTime += timer.elapsed();
133
m_numEmails += itemList.size();
136
void App::slotCommitTimerElapsed()
142
m_indexTime += timer.elapsed();
144
kDebug() << "Emails:" << m_numEmails;
145
kDebug() << "Total Time:" << m_totalTime.elapsed()/1000.0 << " seconds";
146
kDebug() << "Index Time:" << m_indexTime/1000.0 << " seconds";
149
void App::slotIndexed()
151
if (!m_collections.isEmpty()) {
152
QTimer::singleShot(0, this, SLOT(indexNextCollection()));
158
kDebug() << "Emails:" << m_numEmails;
159
kDebug() << "Total Time:" << m_totalTime.elapsed()/1000.0 << " seconds";
160
kDebug() << "Index Time:" << m_indexTime/1000.0 << " seconds";
165
#include "emailtest.moc"