aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/nntp/MCNNTPFetchOverviewOperation.cpp
blob: b05b29e641f4fff656455df472a63d0949b69feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
//  NNTPFetchOverviewOperation.cpp
//  mailcore2
//
//  Created by Robert Widmann on 10/21/14.
//  Copyright (c) 2014 MailCore. All rights reserved.
//

#include "MCNNTPFetchOverviewOperation.h"

#include "MCNNTPAsyncSession.h"
#include "MCNNTPSession.h"

using namespace mailcore;

NNTPFetchOverviewOperation::NNTPFetchOverviewOperation()
{
    mArticles = NULL;
    mIndexes = NULL;
    mGroupName = NULL;
}

NNTPFetchOverviewOperation::~NNTPFetchOverviewOperation()
{
    MC_SAFE_RELEASE(mIndexes);
    MC_SAFE_RELEASE(mGroupName);
}

void NNTPFetchOverviewOperation::setIndexes(IndexSet * indexes)
{
    MC_SAFE_REPLACE_RETAIN(IndexSet, mIndexes, indexes);
}

IndexSet * NNTPFetchOverviewOperation::indexes()
{
    return mIndexes;
}

void NNTPFetchOverviewOperation::setGroupName(String * groupname)
{
    MC_SAFE_REPLACE_COPY(String, mGroupName, groupname);
}

String * NNTPFetchOverviewOperation::groupName()
{
    return mGroupName;
}

Array * NNTPFetchOverviewOperation::articles() {
    return mArticles;
}

void NNTPFetchOverviewOperation::main()
{
    ErrorCode error;
    mArticles = Array::array();
    for(unsigned int i = 0 ; i < mIndexes->rangesCount() ; i ++) {
        Range range = mIndexes->allRanges()[i];
        Array * articles = session()->session()->fetchOverArticlesInRange(range, mGroupName, &error);
        if (error != ErrorNone) {
            setError(error);
            return;
        }
        mArticles->addObjectsFromArray(articles);
    }
    
    setError(error);
}