aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/imap/MCOIMAPFetchContentToFileOperation.mm
blob: 4f2bbfcfc9407679ed424f6ba2c94bace1ac6b29 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
//  MCOIMAPFetchContentToFileOperation.mm
//  mailcore2
//
//  Created by Dmitry Isaikin on 2/08/16.
//  Copyright (c) 2016 MailCore. All rights reserved.
//

#import "MCOIMAPFetchContentToFileOperation.h"

#include "MCAsyncIMAP.h"

#import "MCOOperation+Private.h"
#import "MCOUtils.h"

typedef void (^CompletionType)(NSError *error);

@implementation MCOIMAPFetchContentToFileOperation {
    CompletionType _completionBlock;
    MCOIMAPBaseOperationProgressBlock _progress;
}

@synthesize progress = _progress;

#define nativeType mailcore::IMAPFetchContentToFileOperation

+ (void) load
{
    MCORegisterClass(self, &typeid(nativeType));
}

+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
    nativeType * op = (nativeType *) object;
    return [[[self alloc] initWithMCOperation:op] autorelease];
}

- (void)setLoadingByChunksEnabled:(BOOL)loadingByChunksEnabled {
    MCO_NATIVE_INSTANCE->setLoadingByChunksEnabled(loadingByChunksEnabled);
}

- (BOOL)isLoadingByChunksEnabled {
    return MCO_NATIVE_INSTANCE->isLoadingByChunksEnabled();
}

- (void)setChunksSize:(uint32_t)chunksSize {
    MCO_NATIVE_INSTANCE->setChunksSize(chunksSize);
}

- (uint32_t)chunksSize {
    return MCO_NATIVE_INSTANCE->chunksSize();
}

- (void)setEstimatedSize:(uint32_t)estimatedSize {
    MCO_NATIVE_INSTANCE->setEstimatedSize(estimatedSize);
}

- (uint32_t)estimatedSize {
    return MCO_NATIVE_INSTANCE->estimatedSize();
}

- (void) dealloc
{
    [_progress release];
    [_completionBlock release];
    [super dealloc];
}

- (void) start:(void (^)(NSError *error))completionBlock {
    _completionBlock = [completionBlock copy];
    [self start];
}

- (void) cancel
{
    [_completionBlock release];
    _completionBlock = nil;
    [super cancel];
}

- (void) operationCompleted
{
    if (_completionBlock == NULL)
        return;

    nativeType *op = MCO_NATIVE_INSTANCE;
    if (op->error() == mailcore::ErrorNone) {
        _completionBlock(nil);
    } else {
        _completionBlock([NSError mco_errorWithErrorCode:op->error()]);
    }
    [_completionBlock release];
    _completionBlock = nil;
}

- (void) bodyProgress:(unsigned int)current maximum:(unsigned int)maximum
{
    if (_progress != NULL) {
        _progress(current, maximum);
    }
}

@end