emailuis/nmailui/src/nmattachmentmanager.cpp
author hgs
Thu, 24 Jun 2010 14:32:18 +0300
changeset 47 f83bd4ae1fe3
parent 44 c2d07d913565
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmuiheaders.h"
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
47
hgs
parents: 44
diff changeset
    20
static const int NmAttachmentManagerInitialProgressPercent = 5;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
    \class NmAttachmentManager
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
    \brief Attachment download manager, shares attachment download between editor and viewer
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
NmAttachmentManager::NmAttachmentManager(NmUiEngine &uiEngine) :
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
    mUiEngine(uiEngine),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
    mFetchOperation(NULL),
43
hgs
parents: 40
diff changeset
    33
    mMsgFetchOperation(NULL),
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
    mFetchObserver(NULL),
47
hgs
parents: 44
diff changeset
    35
    mFetchMsg(NULL),
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    mAttaId(0),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    mProgressValue(0),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
    mIsFetching(false)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
{
43
hgs
parents: 40
diff changeset
    40
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
NmAttachmentManager::~NmAttachmentManager()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
{
43
hgs
parents: 40
diff changeset
    48
    NM_FUNCTION;
hgs
parents: 40
diff changeset
    49
    
hgs
parents: 40
diff changeset
    50
    // fetch operation deleted in cancel fetch
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
    cancelFetch();
47
hgs
parents: 44
diff changeset
    52
    
hgs
parents: 44
diff changeset
    53
    delete mFetchMsg;
hgs
parents: 44
diff changeset
    54
    mFetchMsg = NULL;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
    Starts attachment fetch. If earlier fetch operation exist it is cancelled.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
    Set observer with setObserver method to get process and complete events
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
void NmAttachmentManager::fetchAttachment(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
        const NmId &mailboxId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
        const NmId &folderId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
        const NmId &messageId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
        const NmId &messagePartId)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
{
43
hgs
parents: 40
diff changeset
    67
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    // cancel old fetch operation, Does nothing if fetch not ongoing
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    cancelFetch();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    mFetchOperation = mUiEngine.fetchMessagePart(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
            mailboxId, folderId, messageId, messagePartId);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
    
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    if (mFetchOperation) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
        mAttaId = messagePartId;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
        mIsFetching = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
        QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
43
hgs
parents: 40
diff changeset
    78
                this, SLOT(completeAttachmentFetch(int)));
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
        
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
        QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
                this, SLOT(changeProgress(int)));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
        // set progress to 5 % already in start
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
        changeProgress(NmAttachmentManagerInitialProgressPercent);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    84
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
/*!
40
hgs
parents: 23
diff changeset
    88
    Fetch attachments to a message. 
47
hgs
parents: 44
diff changeset
    89
    Set observer with setObserver method to get progress and complete events
43
hgs
parents: 40
diff changeset
    90
    
hgs
parents: 40
diff changeset
    91
    \return bool true if fetch started, otherwise false.
40
hgs
parents: 23
diff changeset
    92
*/
43
hgs
parents: 40
diff changeset
    93
bool NmAttachmentManager::fetchAttachments(
40
hgs
parents: 23
diff changeset
    94
        const NmId &mailboxId, 
hgs
parents: 23
diff changeset
    95
        const NmId &folderId, 
hgs
parents: 23
diff changeset
    96
        const NmId &messageId,
hgs
parents: 23
diff changeset
    97
        QList<NmId> &messagePartIds)
hgs
parents: 23
diff changeset
    98
{
43
hgs
parents: 40
diff changeset
    99
    NM_FUNCTION;
47
hgs
parents: 44
diff changeset
   100
    bool result(false);
40
hgs
parents: 23
diff changeset
   101
    // cancel old fetch operation, Does nothing if fetch not ongoing
43
hgs
parents: 40
diff changeset
   102
    cancelFetch();
40
hgs
parents: 23
diff changeset
   103
    
hgs
parents: 23
diff changeset
   104
    if (messagePartIds.count() > 0) {
hgs
parents: 23
diff changeset
   105
        mFetchOperation = mUiEngine.fetchMessageParts(
hgs
parents: 23
diff changeset
   106
            mailboxId,
hgs
parents: 23
diff changeset
   107
            folderId,
hgs
parents: 23
diff changeset
   108
            messageId,
hgs
parents: 23
diff changeset
   109
            messagePartIds);
43
hgs
parents: 40
diff changeset
   110
        
hgs
parents: 40
diff changeset
   111
        if (mFetchOperation) {
hgs
parents: 40
diff changeset
   112
            mAttaId = 0;
hgs
parents: 40
diff changeset
   113
            mIsFetching = true;
hgs
parents: 40
diff changeset
   114
            QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
hgs
parents: 40
diff changeset
   115
                    this, SLOT(completeAttachmentFetch(int)));
hgs
parents: 40
diff changeset
   116
            
hgs
parents: 40
diff changeset
   117
            QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
hgs
parents: 40
diff changeset
   118
                    this, SLOT(changeProgress(int)));
hgs
parents: 40
diff changeset
   119
        
hgs
parents: 40
diff changeset
   120
            result = true;
hgs
parents: 40
diff changeset
   121
        }
40
hgs
parents: 23
diff changeset
   122
    }
43
hgs
parents: 40
diff changeset
   123
    return result;
40
hgs
parents: 23
diff changeset
   124
}
hgs
parents: 23
diff changeset
   125
hgs
parents: 23
diff changeset
   126
/*!
hgs
parents: 23
diff changeset
   127
    Fetch all message parts to a message. Fetches also message part data structure,
hgs
parents: 23
diff changeset
   128
    if not fetched already.
hgs
parents: 23
diff changeset
   129
      If earlier fetch operation exist it is cancelled and deleted.
47
hgs
parents: 44
diff changeset
   130
    Set observer with setObserver method to get progress and complete events
40
hgs
parents: 23
diff changeset
   131
*/
hgs
parents: 23
diff changeset
   132
void NmAttachmentManager::fetchAllMessageParts(
hgs
parents: 23
diff changeset
   133
        const NmId &mailboxId, 
hgs
parents: 23
diff changeset
   134
        const NmId &folderId, 
hgs
parents: 23
diff changeset
   135
        const NmId &messageId)
hgs
parents: 23
diff changeset
   136
{
43
hgs
parents: 40
diff changeset
   137
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   138
    mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
40
hgs
parents: 23
diff changeset
   139
    
hgs
parents: 23
diff changeset
   140
    // Check if we have part data structure.    
47
hgs
parents: 44
diff changeset
   141
    if (mFetchMsg && mFetchMsg->childParts().count() == 0 &&
43
hgs
parents: 40
diff changeset
   142
        mFetchMsg->fetchedSize() < mFetchMsg->size()) {
40
hgs
parents: 23
diff changeset
   143
hgs
parents: 23
diff changeset
   144
        // cancel old fetch operation, Does nothing if fetch not ongoing
hgs
parents: 23
diff changeset
   145
        cancelFetch();
hgs
parents: 23
diff changeset
   146
        
hgs
parents: 23
diff changeset
   147
        // Fetch the message.
hgs
parents: 23
diff changeset
   148
        mMsgFetchOperation = mUiEngine.fetchMessage(
43
hgs
parents: 40
diff changeset
   149
            mFetchMsg->envelope().mailboxId(),
hgs
parents: 40
diff changeset
   150
            mFetchMsg->envelope().folderId(),
hgs
parents: 40
diff changeset
   151
            mFetchMsg->envelope().messageId());
40
hgs
parents: 23
diff changeset
   152
        
hgs
parents: 23
diff changeset
   153
        mAttaId = 0;
hgs
parents: 23
diff changeset
   154
        mIsFetching = true;
hgs
parents: 23
diff changeset
   155
hgs
parents: 23
diff changeset
   156
        if (mMsgFetchOperation) {
hgs
parents: 23
diff changeset
   157
            QObject::connect(mMsgFetchOperation,
hgs
parents: 23
diff changeset
   158
                    SIGNAL(operationCompleted(int)),
hgs
parents: 23
diff changeset
   159
                    this,
43
hgs
parents: 40
diff changeset
   160
                    SLOT(completeMessageFetch(int)));
40
hgs
parents: 23
diff changeset
   161
        }
44
hgs
parents: 43
diff changeset
   162
        else {
hgs
parents: 43
diff changeset
   163
            completeMessageFetch(NmGeneralError);
hgs
parents: 43
diff changeset
   164
        }
40
hgs
parents: 23
diff changeset
   165
        
hgs
parents: 23
diff changeset
   166
    }
hgs
parents: 23
diff changeset
   167
    else {
43
hgs
parents: 40
diff changeset
   168
        completeMessageFetch(NmNoError);
40
hgs
parents: 23
diff changeset
   169
    }
hgs
parents: 23
diff changeset
   170
}
hgs
parents: 23
diff changeset
   171
hgs
parents: 23
diff changeset
   172
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
    Retruns true if fetch operation is ongoing
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
bool NmAttachmentManager::isFetching() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
{
43
hgs
parents: 40
diff changeset
   177
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   178
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
    return mIsFetching;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
    Retrunrs part id of attachment if fetch operation is ongoing. Zero id is returned otherwise
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
NmId NmAttachmentManager::partIdUnderFetch() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
{
43
hgs
parents: 40
diff changeset
   187
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   188
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    return mAttaId;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
    Cancels fetch operation. Does nothing if fetch not ongoing
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
void NmAttachmentManager::cancelFetch()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
{
43
hgs
parents: 40
diff changeset
   197
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
    if (mFetchOperation && mFetchOperation->isRunning()) { 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
        mFetchOperation->cancelOperation();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
    }
40
hgs
parents: 23
diff changeset
   201
    if (mMsgFetchOperation && mMsgFetchOperation->isRunning()) {
hgs
parents: 23
diff changeset
   202
        mMsgFetchOperation->cancelOperation();
hgs
parents: 23
diff changeset
   203
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
    mIsFetching = false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
    mAttaId = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
    mProgressValue = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    Used by message part fetch operation
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
void NmAttachmentManager::changeProgress(int value)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
{
43
hgs
parents: 40
diff changeset
   214
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   215
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
    if (mFetchObserver && value > mProgressValue) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
        mProgressValue = value;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
        mFetchObserver->progressChanged(value);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   221
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
    Used by message part fetch operation
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   224
*/
43
hgs
parents: 40
diff changeset
   225
void NmAttachmentManager::completeAttachmentFetch(int result)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
{
43
hgs
parents: 40
diff changeset
   227
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   228
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
    if (mFetchObserver) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
        mFetchObserver->fetchCompleted(result);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
    mAttaId = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   233
    mProgressValue = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
    mIsFetching = false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   235
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   236
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
/*!
40
hgs
parents: 23
diff changeset
   238
    Used by message fetch operation
hgs
parents: 23
diff changeset
   239
*/
43
hgs
parents: 40
diff changeset
   240
void NmAttachmentManager::completeMessageFetch(int result)
40
hgs
parents: 23
diff changeset
   241
{
43
hgs
parents: 40
diff changeset
   242
    NM_FUNCTION;
40
hgs
parents: 23
diff changeset
   243
    
hgs
parents: 23
diff changeset
   244
    if (result == NmNoError) {
hgs
parents: 23
diff changeset
   245
        
43
hgs
parents: 40
diff changeset
   246
        if (mFetchMsg) {
47
hgs
parents: 44
diff changeset
   247
            
hgs
parents: 44
diff changeset
   248
            NmId mailboxId = mFetchMsg->envelope().mailboxId();
hgs
parents: 44
diff changeset
   249
            NmId folderId = mFetchMsg->envelope().folderId();
hgs
parents: 44
diff changeset
   250
            NmId messageId = mFetchMsg->envelope().messageId();
hgs
parents: 44
diff changeset
   251
            
hgs
parents: 44
diff changeset
   252
            // Delete object
hgs
parents: 44
diff changeset
   253
            delete mFetchMsg;
hgs
parents: 44
diff changeset
   254
            mFetchMsg = NULL;
hgs
parents: 44
diff changeset
   255
            
hgs
parents: 44
diff changeset
   256
            // Reload message
hgs
parents: 44
diff changeset
   257
            mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
hgs
parents: 44
diff changeset
   258
            
hgs
parents: 44
diff changeset
   259
            if (mFetchMsg) {
hgs
parents: 44
diff changeset
   260
                QList<NmId> partIds;
hgs
parents: 44
diff changeset
   261
                NmMessagePart *part;
hgs
parents: 44
diff changeset
   262
                foreach (part, mFetchMsg->childParts()) {
hgs
parents: 44
diff changeset
   263
                    if (part->size() > part->fetchedSize()) {
hgs
parents: 44
diff changeset
   264
                        partIds.append(part->partId());
hgs
parents: 44
diff changeset
   265
                    }
40
hgs
parents: 23
diff changeset
   266
                }
47
hgs
parents: 44
diff changeset
   267
                if (partIds.count() > 0) {
hgs
parents: 44
diff changeset
   268
                    mMsgFetchOperation = NULL;
hgs
parents: 44
diff changeset
   269
                    fetchAttachments(
hgs
parents: 44
diff changeset
   270
                        mFetchMsg->envelope().mailboxId(),
hgs
parents: 44
diff changeset
   271
                        mFetchMsg->envelope().folderId(),
hgs
parents: 44
diff changeset
   272
                        mFetchMsg->envelope().messageId(),
hgs
parents: 44
diff changeset
   273
                        partIds);
hgs
parents: 44
diff changeset
   274
                }
hgs
parents: 44
diff changeset
   275
                else {
hgs
parents: 44
diff changeset
   276
                    mFetchObserver->fetchCompleted(NmNoError);
hgs
parents: 44
diff changeset
   277
                }
hgs
parents: 44
diff changeset
   278
                // Delete object
hgs
parents: 44
diff changeset
   279
                delete mFetchMsg;
hgs
parents: 44
diff changeset
   280
                mFetchMsg = NULL;
40
hgs
parents: 23
diff changeset
   281
            }
hgs
parents: 23
diff changeset
   282
            else {
47
hgs
parents: 44
diff changeset
   283
                mFetchObserver->fetchCompleted(NmNotFoundError);
40
hgs
parents: 23
diff changeset
   284
            }
hgs
parents: 23
diff changeset
   285
        }
hgs
parents: 23
diff changeset
   286
        else {
hgs
parents: 23
diff changeset
   287
            mFetchObserver->fetchCompleted(NmNotFoundError);
hgs
parents: 23
diff changeset
   288
        }
hgs
parents: 23
diff changeset
   289
    }
hgs
parents: 23
diff changeset
   290
    else {
hgs
parents: 23
diff changeset
   291
        mFetchObserver->fetchCompleted(result);
hgs
parents: 23
diff changeset
   292
    }
hgs
parents: 23
diff changeset
   293
}
hgs
parents: 23
diff changeset
   294
hgs
parents: 23
diff changeset
   295
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
    Sets fetch observer
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   297
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
void NmAttachmentManager::setObserver(NmAttachmentFetchObserver *observer)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
{
43
hgs
parents: 40
diff changeset
   300
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   301
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
    mFetchObserver = observer;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
    // send progress event wheng observer changes if fetch ongoing 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
    // to get progress bar updating
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
    if (mIsFetching) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
        changeProgress(mProgressValue);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   307
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   311
    Clear observer
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   312
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
void NmAttachmentManager::clearObserver()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
{
43
hgs
parents: 40
diff changeset
   315
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   316
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
    mFetchObserver = NULL;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   320
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   321
    Returns progress value if fetch ongoing. Otherwise returns 0.
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   322
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   323
int NmAttachmentManager::progressValue() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   324
{
43
hgs
parents: 40
diff changeset
   325
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   326
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   327
    return mProgressValue;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   328
}