~renatofilho/qtorganizer5-eds/fix-1240505

« back to all changes in this revision

Viewing changes to qorganizer/qorganizer-eds-fetchrequestdata.cpp

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2013-08-14 21:23:01 UTC
  • Revision ID: renato.filho@canonical.com-20130814212301-cmqs3nv48cvzy9qq
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This file is part of ubuntu-pim-service.
 
5
 *
 
6
 * contact-service-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * contact-service-app 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
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "qorganizer-eds-fetchrequestdata.h"
 
20
 
 
21
#include <QtOrganizer/QOrganizerItemFetchRequest>
 
22
 
 
23
using namespace QtOrganizer;
 
24
 
 
25
FetchRequestData::FetchRequestData(QOrganizerEDSEngine *engine, QOrganizerAbstractRequest *req)
 
26
    : RequestData(engine, req),
 
27
      m_collections(engine->m_collectionsMap.values())
 
28
{
 
29
}
 
30
 
 
31
FetchRequestData::~FetchRequestData()
 
32
{
 
33
    m_parent->m_pendingFetchRequest.removeOne(this);
 
34
}
 
35
 
 
36
QOrganizerEDSCollectionEngineId* FetchRequestData::nextCollection()
 
37
{
 
38
    m_current = 0;
 
39
    if (m_collections.size()) {
 
40
        m_current = m_collections.takeFirst();
 
41
        return m_current;
 
42
    } else {
 
43
        return 0;
 
44
    }
 
45
}
 
46
 
 
47
QOrganizerEDSCollectionEngineId* FetchRequestData::collection() const
 
48
{
 
49
    return m_current;
 
50
}
 
51
 
 
52
void FetchRequestData::finish(QOrganizerManager::Error error)
 
53
{
 
54
    QOrganizerManagerEngine::updateItemFetchRequest(request<QOrganizerItemFetchRequest>(),
 
55
                                                    m_results,
 
56
                                                    error,
 
57
                                                    QOrganizerAbstractRequest::FinishedState);
 
58
    // TODO: emit changeset???
 
59
}
 
60
 
 
61
void FetchRequestData::appendResults(QList<QOrganizerItem> results)
 
62
{
 
63
    m_results += results;
 
64
}
 
65
 
 
66
QString FetchRequestData::dateFilter()
 
67
{
 
68
    QString query = QString("(occur-in-time-range? "
 
69
                            "(make-time \"%1\") (make-time \"%2\"))")
 
70
            .arg(isodate_from_time_t(request<QOrganizerItemFetchRequest>()->startDate().toTime_t()))
 
71
            .arg(isodate_from_time_t(request<QOrganizerItemFetchRequest>()->endDate().toTime_t()));
 
72
    return query;
 
73
}