emailuis/nmailui/src/nmattachmentmanager.cpp
author hgs
Thu, 10 Jun 2010 16:14:05 +0300
changeset 44 c2d07d913565
parent 43 99bcbff212ad
child 47 f83bd4ae1fe3
permissions -rw-r--r--
201023
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
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
const int NmAttachmentManagerInitialProgressPercent = 5;
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),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
    mAttaId(0),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    mProgressValue(0),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    mIsFetching(false)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
{
43
hgs
parents: 40
diff changeset
    39
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
}
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
NmAttachmentManager::~NmAttachmentManager()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
{
43
hgs
parents: 40
diff changeset
    47
    NM_FUNCTION;
hgs
parents: 40
diff changeset
    48
    
hgs
parents: 40
diff changeset
    49
    // fetch operation deleted in cancel fetch
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
    cancelFetch();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
    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
    55
    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
    56
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
void NmAttachmentManager::fetchAttachment(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
        const NmId &mailboxId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
        const NmId &folderId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
        const NmId &messageId, 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
        const NmId &messagePartId)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
{
43
hgs
parents: 40
diff changeset
    63
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
    // 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
    65
    cancelFetch();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
    mFetchOperation = mUiEngine.fetchMessagePart(
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
            mailboxId, folderId, messageId, messagePartId);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
    if (mFetchOperation) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
        mAttaId = messagePartId;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
        mIsFetching = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
        QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
43
hgs
parents: 40
diff changeset
    74
                this, SLOT(completeAttachmentFetch(int)));
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
        
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
        QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
                this, SLOT(changeProgress(int)));
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
        // set progress to 5 % already in start
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
        changeProgress(NmAttachmentManagerInitialProgressPercent);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
/*!
40
hgs
parents: 23
diff changeset
    84
    Fetch attachments to a message. 
hgs
parents: 23
diff changeset
    85
    Set observer with setObserver method to get process and complete events
43
hgs
parents: 40
diff changeset
    86
    
hgs
parents: 40
diff changeset
    87
    \return bool true if fetch started, otherwise false.
40
hgs
parents: 23
diff changeset
    88
*/
43
hgs
parents: 40
diff changeset
    89
bool NmAttachmentManager::fetchAttachments(
40
hgs
parents: 23
diff changeset
    90
        const NmId &mailboxId, 
hgs
parents: 23
diff changeset
    91
        const NmId &folderId, 
hgs
parents: 23
diff changeset
    92
        const NmId &messageId,
hgs
parents: 23
diff changeset
    93
        QList<NmId> &messagePartIds)
hgs
parents: 23
diff changeset
    94
{
43
hgs
parents: 40
diff changeset
    95
    NM_FUNCTION;
hgs
parents: 40
diff changeset
    96
    bool result = false;
40
hgs
parents: 23
diff changeset
    97
    // cancel old fetch operation, Does nothing if fetch not ongoing
43
hgs
parents: 40
diff changeset
    98
    cancelFetch();
40
hgs
parents: 23
diff changeset
    99
    
hgs
parents: 23
diff changeset
   100
    if (messagePartIds.count() > 0) {
hgs
parents: 23
diff changeset
   101
        mFetchOperation = mUiEngine.fetchMessageParts(
hgs
parents: 23
diff changeset
   102
            mailboxId,
hgs
parents: 23
diff changeset
   103
            folderId,
hgs
parents: 23
diff changeset
   104
            messageId,
hgs
parents: 23
diff changeset
   105
            messagePartIds);
43
hgs
parents: 40
diff changeset
   106
        
hgs
parents: 40
diff changeset
   107
        if (mFetchOperation) {
hgs
parents: 40
diff changeset
   108
            mAttaId = 0;
hgs
parents: 40
diff changeset
   109
            mIsFetching = true;
hgs
parents: 40
diff changeset
   110
            QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
hgs
parents: 40
diff changeset
   111
                    this, SLOT(completeAttachmentFetch(int)));
hgs
parents: 40
diff changeset
   112
            
hgs
parents: 40
diff changeset
   113
            QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
hgs
parents: 40
diff changeset
   114
                    this, SLOT(changeProgress(int)));
hgs
parents: 40
diff changeset
   115
        
hgs
parents: 40
diff changeset
   116
            result = true;
hgs
parents: 40
diff changeset
   117
        }
40
hgs
parents: 23
diff changeset
   118
    }
43
hgs
parents: 40
diff changeset
   119
    return result;
40
hgs
parents: 23
diff changeset
   120
}
hgs
parents: 23
diff changeset
   121
hgs
parents: 23
diff changeset
   122
/*!
hgs
parents: 23
diff changeset
   123
    Fetch all message parts to a message. Fetches also message part data structure,
hgs
parents: 23
diff changeset
   124
    if not fetched already.
hgs
parents: 23
diff changeset
   125
      If earlier fetch operation exist it is cancelled and deleted.
hgs
parents: 23
diff changeset
   126
    Set observer with setObserver method to get process and complete events
hgs
parents: 23
diff changeset
   127
*/
hgs
parents: 23
diff changeset
   128
void NmAttachmentManager::fetchAllMessageParts(
hgs
parents: 23
diff changeset
   129
        const NmId &mailboxId, 
hgs
parents: 23
diff changeset
   130
        const NmId &folderId, 
hgs
parents: 23
diff changeset
   131
        const NmId &messageId)
hgs
parents: 23
diff changeset
   132
{
43
hgs
parents: 40
diff changeset
   133
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   134
    mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
40
hgs
parents: 23
diff changeset
   135
    
hgs
parents: 23
diff changeset
   136
    // Check if we have part data structure.    
43
hgs
parents: 40
diff changeset
   137
    if (mFetchMsg->childParts().count() == 0 &&
hgs
parents: 40
diff changeset
   138
        mFetchMsg->fetchedSize() < mFetchMsg->size()) {
40
hgs
parents: 23
diff changeset
   139
hgs
parents: 23
diff changeset
   140
        // cancel old fetch operation, Does nothing if fetch not ongoing
hgs
parents: 23
diff changeset
   141
        cancelFetch();
hgs
parents: 23
diff changeset
   142
        
hgs
parents: 23
diff changeset
   143
        // Fetch the message.
hgs
parents: 23
diff changeset
   144
        mMsgFetchOperation = mUiEngine.fetchMessage(
43
hgs
parents: 40
diff changeset
   145
            mFetchMsg->envelope().mailboxId(),
hgs
parents: 40
diff changeset
   146
            mFetchMsg->envelope().folderId(),
hgs
parents: 40
diff changeset
   147
            mFetchMsg->envelope().messageId());
40
hgs
parents: 23
diff changeset
   148
        
hgs
parents: 23
diff changeset
   149
        mAttaId = 0;
hgs
parents: 23
diff changeset
   150
        mIsFetching = true;
hgs
parents: 23
diff changeset
   151
hgs
parents: 23
diff changeset
   152
        if (mMsgFetchOperation) {
hgs
parents: 23
diff changeset
   153
            QObject::connect(mMsgFetchOperation,
hgs
parents: 23
diff changeset
   154
                    SIGNAL(operationCompleted(int)),
hgs
parents: 23
diff changeset
   155
                    this,
43
hgs
parents: 40
diff changeset
   156
                    SLOT(completeMessageFetch(int)));
40
hgs
parents: 23
diff changeset
   157
        }
44
hgs
parents: 43
diff changeset
   158
        else {
hgs
parents: 43
diff changeset
   159
            completeMessageFetch(NmGeneralError);
hgs
parents: 43
diff changeset
   160
        }
40
hgs
parents: 23
diff changeset
   161
        
hgs
parents: 23
diff changeset
   162
    }
hgs
parents: 23
diff changeset
   163
    else {
43
hgs
parents: 40
diff changeset
   164
        completeMessageFetch(NmNoError);
40
hgs
parents: 23
diff changeset
   165
    }
hgs
parents: 23
diff changeset
   166
}
hgs
parents: 23
diff changeset
   167
hgs
parents: 23
diff changeset
   168
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
    Retruns true if fetch operation is ongoing
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
bool NmAttachmentManager::isFetching() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
{
43
hgs
parents: 40
diff changeset
   173
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   174
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
    return mIsFetching;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
    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
   180
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
NmId NmAttachmentManager::partIdUnderFetch() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
{
43
hgs
parents: 40
diff changeset
   183
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   184
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
    return mAttaId;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    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
   190
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
void NmAttachmentManager::cancelFetch()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
{
43
hgs
parents: 40
diff changeset
   193
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
    if (mFetchOperation && mFetchOperation->isRunning()) { 
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
        mFetchOperation->cancelOperation();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
    }
40
hgs
parents: 23
diff changeset
   197
    if (mMsgFetchOperation && mMsgFetchOperation->isRunning()) {
hgs
parents: 23
diff changeset
   198
        mMsgFetchOperation->cancelOperation();
hgs
parents: 23
diff changeset
   199
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
    mIsFetching = false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
    mAttaId = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
    mProgressValue = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
    Used by message part fetch operation
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
void NmAttachmentManager::changeProgress(int value)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
{
43
hgs
parents: 40
diff changeset
   210
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   211
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
    if (mFetchObserver && value > mProgressValue) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
        mProgressValue = value;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
        mFetchObserver->progressChanged(value);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
    Used by message part fetch operation
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
*/
43
hgs
parents: 40
diff changeset
   221
void NmAttachmentManager::completeAttachmentFetch(int result)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
{
43
hgs
parents: 40
diff changeset
   223
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   224
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
    if (mFetchObserver) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
        mFetchObserver->fetchCompleted(result);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
    mAttaId = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
    mProgressValue = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
    mIsFetching = false;
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
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   233
/*!
40
hgs
parents: 23
diff changeset
   234
    Used by message fetch operation
hgs
parents: 23
diff changeset
   235
*/
43
hgs
parents: 40
diff changeset
   236
void NmAttachmentManager::completeMessageFetch(int result)
40
hgs
parents: 23
diff changeset
   237
{
43
hgs
parents: 40
diff changeset
   238
    NM_FUNCTION;
40
hgs
parents: 23
diff changeset
   239
    
hgs
parents: 23
diff changeset
   240
    if (result == NmNoError) {
hgs
parents: 23
diff changeset
   241
        
hgs
parents: 23
diff changeset
   242
        // Reload message
43
hgs
parents: 40
diff changeset
   243
        mFetchMsg = mUiEngine.message(
hgs
parents: 40
diff changeset
   244
            mFetchMsg->envelope().mailboxId(),
hgs
parents: 40
diff changeset
   245
            mFetchMsg->envelope().folderId(),
hgs
parents: 40
diff changeset
   246
            mFetchMsg->envelope().messageId());
40
hgs
parents: 23
diff changeset
   247
        
43
hgs
parents: 40
diff changeset
   248
        if (mFetchMsg) {
40
hgs
parents: 23
diff changeset
   249
            QList<NmId> partIds;
hgs
parents: 23
diff changeset
   250
            NmMessagePart *part;
43
hgs
parents: 40
diff changeset
   251
            foreach (part, mFetchMsg->childParts()) {
40
hgs
parents: 23
diff changeset
   252
                if (part->size() > part->fetchedSize()) {
hgs
parents: 23
diff changeset
   253
                    partIds.append(part->partId());
hgs
parents: 23
diff changeset
   254
                }
hgs
parents: 23
diff changeset
   255
            }
hgs
parents: 23
diff changeset
   256
            if (partIds.count() > 0) {
43
hgs
parents: 40
diff changeset
   257
                mMsgFetchOperation = NULL;
40
hgs
parents: 23
diff changeset
   258
                fetchAttachments(
43
hgs
parents: 40
diff changeset
   259
                    mFetchMsg->envelope().mailboxId(),
hgs
parents: 40
diff changeset
   260
                    mFetchMsg->envelope().folderId(),
hgs
parents: 40
diff changeset
   261
                    mFetchMsg->envelope().messageId(),
40
hgs
parents: 23
diff changeset
   262
                    partIds);
hgs
parents: 23
diff changeset
   263
            }
hgs
parents: 23
diff changeset
   264
            else {
43
hgs
parents: 40
diff changeset
   265
                mFetchObserver->fetchCompleted(NmNoError);
40
hgs
parents: 23
diff changeset
   266
            }
hgs
parents: 23
diff changeset
   267
        }
hgs
parents: 23
diff changeset
   268
        else {
hgs
parents: 23
diff changeset
   269
            mFetchObserver->fetchCompleted(NmNotFoundError);
hgs
parents: 23
diff changeset
   270
        }
hgs
parents: 23
diff changeset
   271
    }
hgs
parents: 23
diff changeset
   272
    else {
hgs
parents: 23
diff changeset
   273
        mFetchObserver->fetchCompleted(result);
hgs
parents: 23
diff changeset
   274
    }
hgs
parents: 23
diff changeset
   275
}
hgs
parents: 23
diff changeset
   276
hgs
parents: 23
diff changeset
   277
/*!
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   278
    Sets fetch observer
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   280
void NmAttachmentManager::setObserver(NmAttachmentFetchObserver *observer)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   281
{
43
hgs
parents: 40
diff changeset
   282
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   283
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
    mFetchObserver = observer;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   285
    // 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
   286
    // to get progress bar updating
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   287
    if (mIsFetching) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   288
        changeProgress(mProgressValue);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   290
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   291
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   292
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
    Clear observer
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
void NmAttachmentManager::clearObserver()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
{
43
hgs
parents: 40
diff changeset
   297
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   298
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
    mFetchObserver = NULL;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   300
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   301
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
    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
   304
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
int NmAttachmentManager::progressValue() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
{
43
hgs
parents: 40
diff changeset
   307
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   308
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
    return mProgressValue;
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