1/*
2 Copyright (c) 2013 Daniel Vrátil <dvratil@redhat.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "searchresultjob_p.h"
21#include "job_p.h"
22#include "protocolhelper_p.h"
23
24#include <akonadi/private/protocol_p.h>
25
26namespace Akonadi {
27
28class SearchResultJobPrivate : public Akonadi::JobPrivate
29{
30public:
31 SearchResultJobPrivate(SearchResultJob *parent);
32
33 QByteArray searchId;
34 Collection collection;
35 ImapSet uid;
36 QVector<QByteArray> rid;
37};
38
39SearchResultJobPrivate::SearchResultJobPrivate(SearchResultJob *parent)
40 : JobPrivate(parent)
41{
42}
43
44}
45
46using namespace Akonadi;
47
48SearchResultJob::SearchResultJob(const QByteArray &searchId, const Collection &collection, QObject *parent)
49 : Job(new SearchResultJobPrivate(this), parent)
50{
51 Q_D(SearchResultJob);
52 Q_ASSERT(collection.isValid());
53
54 d->searchId = searchId;
55 d->collection = collection;
56}
57
58SearchResultJob::~SearchResultJob()
59{
60}
61
62void SearchResultJob::setSearchId(const QByteArray &searchId)
63{
64 Q_D(SearchResultJob);
65 d->searchId = searchId;
66}
67
68QByteArray SearchResultJob::searchId() const
69{
70 return d_func()->searchId;
71}
72
73void SearchResultJob::setResult(const ImapSet &set)
74{
75 Q_D(SearchResultJob);
76 d->rid.clear();
77 d->uid = set;
78}
79
80void SearchResultJob::setResult(const QVector<qint64> &ids)
81{
82 Q_D(SearchResultJob);
83 d->rid.clear();
84 d->uid = ImapSet();
85 d->uid.add(ids);
86}
87
88void SearchResultJob::setResult(const QVector<QByteArray> &remoteIds)
89{
90 Q_D(SearchResultJob);
91 d->uid = ImapSet();
92 d->rid = remoteIds;
93}
94
95void SearchResultJob::doStart()
96{
97 Q_D(SearchResultJob);
98
99 QByteArray command = d->newTag() + ' ';
100
101 if (!d->rid.isEmpty()) {
102 command += AKONADI_CMD_RID;
103 } else {
104 command += AKONADI_CMD_UID;
105 }
106
107 command += " SEARCH_RESULT " + d->searchId + " " + QByteArray::number(d->collection.id()) + " (";
108
109 if (!d->rid.isEmpty()) {
110 command += ImapParser::join(d->rid.toList(), " ");
111 } else if (!d->uid.isEmpty()) {
112 command += d->uid.toImapSequenceSet();
113 }
114
115 command += ")";
116
117 d->writeData(command);
118}
119