emailuis/nmailui/src/nmattachmentmanager.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 const int NmAttachmentManagerInitialProgressPercent = 5;
    20 static const int NmAttachmentManagerInitialProgressPercent = 5;
    21 
    21 
    22 /*!
    22 /*!
    23     \class NmAttachmentManager
    23     \class NmAttachmentManager
    24     \brief Attachment download manager, shares attachment download between editor and viewer
    24     \brief Attachment download manager, shares attachment download between editor and viewer
    25 */
    25 */
    30 NmAttachmentManager::NmAttachmentManager(NmUiEngine &uiEngine) :
    30 NmAttachmentManager::NmAttachmentManager(NmUiEngine &uiEngine) :
    31     mUiEngine(uiEngine),
    31     mUiEngine(uiEngine),
    32     mFetchOperation(NULL),
    32     mFetchOperation(NULL),
    33     mMsgFetchOperation(NULL),
    33     mMsgFetchOperation(NULL),
    34     mFetchObserver(NULL),
    34     mFetchObserver(NULL),
       
    35     mFetchMsg(NULL),
    35     mAttaId(0),
    36     mAttaId(0),
    36     mProgressValue(0),
    37     mProgressValue(0),
    37     mIsFetching(false)
    38     mIsFetching(false)
    38 {
    39 {
    39     NM_FUNCTION;
    40     NM_FUNCTION;
    46 {
    47 {
    47     NM_FUNCTION;
    48     NM_FUNCTION;
    48     
    49     
    49     // fetch operation deleted in cancel fetch
    50     // fetch operation deleted in cancel fetch
    50     cancelFetch();
    51     cancelFetch();
       
    52     
       
    53     delete mFetchMsg;
       
    54     mFetchMsg = NULL;
    51 }
    55 }
    52 
    56 
    53 /*!
    57 /*!
    54     Starts attachment fetch. If earlier fetch operation exist it is cancelled.
    58     Starts attachment fetch. If earlier fetch operation exist it is cancelled.
    55     Set observer with setObserver method to get process and complete events
    59     Set observer with setObserver method to get process and complete events
    80     }
    84     }
    81 }
    85 }
    82 
    86 
    83 /*!
    87 /*!
    84     Fetch attachments to a message. 
    88     Fetch attachments to a message. 
    85     Set observer with setObserver method to get process and complete events
    89     Set observer with setObserver method to get progress and complete events
    86     
    90     
    87     \return bool true if fetch started, otherwise false.
    91     \return bool true if fetch started, otherwise false.
    88 */
    92 */
    89 bool NmAttachmentManager::fetchAttachments(
    93 bool NmAttachmentManager::fetchAttachments(
    90         const NmId &mailboxId, 
    94         const NmId &mailboxId, 
    91         const NmId &folderId, 
    95         const NmId &folderId, 
    92         const NmId &messageId,
    96         const NmId &messageId,
    93         QList<NmId> &messagePartIds)
    97         QList<NmId> &messagePartIds)
    94 {
    98 {
    95     NM_FUNCTION;
    99     NM_FUNCTION;
    96     bool result = false;
   100     bool result(false);
    97     // cancel old fetch operation, Does nothing if fetch not ongoing
   101     // cancel old fetch operation, Does nothing if fetch not ongoing
    98     cancelFetch();
   102     cancelFetch();
    99     
   103     
   100     if (messagePartIds.count() > 0) {
   104     if (messagePartIds.count() > 0) {
   101         mFetchOperation = mUiEngine.fetchMessageParts(
   105         mFetchOperation = mUiEngine.fetchMessageParts(
   121 
   125 
   122 /*!
   126 /*!
   123     Fetch all message parts to a message. Fetches also message part data structure,
   127     Fetch all message parts to a message. Fetches also message part data structure,
   124     if not fetched already.
   128     if not fetched already.
   125       If earlier fetch operation exist it is cancelled and deleted.
   129       If earlier fetch operation exist it is cancelled and deleted.
   126     Set observer with setObserver method to get process and complete events
   130     Set observer with setObserver method to get progress and complete events
   127 */
   131 */
   128 void NmAttachmentManager::fetchAllMessageParts(
   132 void NmAttachmentManager::fetchAllMessageParts(
   129         const NmId &mailboxId, 
   133         const NmId &mailboxId, 
   130         const NmId &folderId, 
   134         const NmId &folderId, 
   131         const NmId &messageId)
   135         const NmId &messageId)
   132 {
   136 {
   133     NM_FUNCTION;
   137     NM_FUNCTION;
   134     mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
   138     mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
   135     
   139     
   136     // Check if we have part data structure.    
   140     // Check if we have part data structure.    
   137     if (mFetchMsg->childParts().count() == 0 &&
   141     if (mFetchMsg && mFetchMsg->childParts().count() == 0 &&
   138         mFetchMsg->fetchedSize() < mFetchMsg->size()) {
   142         mFetchMsg->fetchedSize() < mFetchMsg->size()) {
   139 
   143 
   140         // cancel old fetch operation, Does nothing if fetch not ongoing
   144         // cancel old fetch operation, Does nothing if fetch not ongoing
   141         cancelFetch();
   145         cancelFetch();
   142         
   146         
   237 {
   241 {
   238     NM_FUNCTION;
   242     NM_FUNCTION;
   239     
   243     
   240     if (result == NmNoError) {
   244     if (result == NmNoError) {
   241         
   245         
   242         // Reload message
       
   243         mFetchMsg = mUiEngine.message(
       
   244             mFetchMsg->envelope().mailboxId(),
       
   245             mFetchMsg->envelope().folderId(),
       
   246             mFetchMsg->envelope().messageId());
       
   247         
       
   248         if (mFetchMsg) {
   246         if (mFetchMsg) {
   249             QList<NmId> partIds;
   247             
   250             NmMessagePart *part;
   248             NmId mailboxId = mFetchMsg->envelope().mailboxId();
   251             foreach (part, mFetchMsg->childParts()) {
   249             NmId folderId = mFetchMsg->envelope().folderId();
   252                 if (part->size() > part->fetchedSize()) {
   250             NmId messageId = mFetchMsg->envelope().messageId();
   253                     partIds.append(part->partId());
   251             
       
   252             // Delete object
       
   253             delete mFetchMsg;
       
   254             mFetchMsg = NULL;
       
   255             
       
   256             // Reload message
       
   257             mFetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
       
   258             
       
   259             if (mFetchMsg) {
       
   260                 QList<NmId> partIds;
       
   261                 NmMessagePart *part;
       
   262                 foreach (part, mFetchMsg->childParts()) {
       
   263                     if (part->size() > part->fetchedSize()) {
       
   264                         partIds.append(part->partId());
       
   265                     }
   254                 }
   266                 }
   255             }
   267                 if (partIds.count() > 0) {
   256             if (partIds.count() > 0) {
   268                     mMsgFetchOperation = NULL;
   257                 mMsgFetchOperation = NULL;
   269                     fetchAttachments(
   258                 fetchAttachments(
   270                         mFetchMsg->envelope().mailboxId(),
   259                     mFetchMsg->envelope().mailboxId(),
   271                         mFetchMsg->envelope().folderId(),
   260                     mFetchMsg->envelope().folderId(),
   272                         mFetchMsg->envelope().messageId(),
   261                     mFetchMsg->envelope().messageId(),
   273                         partIds);
   262                     partIds);
   274                 }
       
   275                 else {
       
   276                     mFetchObserver->fetchCompleted(NmNoError);
       
   277                 }
       
   278                 // Delete object
       
   279                 delete mFetchMsg;
       
   280                 mFetchMsg = NULL;
   263             }
   281             }
   264             else {
   282             else {
   265                 mFetchObserver->fetchCompleted(NmNoError);
   283                 mFetchObserver->fetchCompleted(NmNotFoundError);
   266             }
   284             }
   267         }
   285         }
   268         else {
   286         else {
   269             mFetchObserver->fetchCompleted(NmNotFoundError);
   287             mFetchObserver->fetchCompleted(NmNotFoundError);
   270         }
   288         }
   306 {
   324 {
   307     NM_FUNCTION;
   325     NM_FUNCTION;
   308     
   326     
   309     return mProgressValue;
   327     return mProgressValue;
   310 }
   328 }
   311