emailuis/nmailui/src/nmattachmentmanager.cpp
changeset 27 9ba4404ef423
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
23:2dc6caa42ec3 27:9ba4404ef423
    75         changeProgress(NmAttachmentManagerInitialProgressPercent);
    75         changeProgress(NmAttachmentManagerInitialProgressPercent);
    76     }
    76     }
    77 }
    77 }
    78 
    78 
    79 /*!
    79 /*!
       
    80     Fetch attachments to a message. 
       
    81     Set observer with setObserver method to get process and complete events
       
    82 */
       
    83 void NmAttachmentManager::fetchAttachments(
       
    84         const NmId &mailboxId, 
       
    85         const NmId &folderId, 
       
    86         const NmId &messageId,
       
    87         QList<NmId> &messagePartIds)
       
    88 {
       
    89     // cancel old fetch operation, Does nothing if fetch not ongoing
       
    90     // We don't wan't to cancel message fetching operation, because
       
    91     // it might still be finishing.
       
    92     if (!mMsgFetchOperation) {
       
    93         cancelFetch();
       
    94     }
       
    95     
       
    96     if (messagePartIds.count() > 0) {
       
    97         mFetchOperation = mUiEngine.fetchMessageParts(
       
    98             mailboxId,
       
    99             folderId,
       
   100             messageId,
       
   101             messagePartIds);
       
   102     }
       
   103     
       
   104     if (mFetchOperation) {
       
   105         mAttaId = 0;
       
   106         mIsFetching = true;
       
   107         QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
       
   108                 this, SLOT(attachmentFetchCompleted(int)));
       
   109         
       
   110         QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
       
   111                 this, SLOT(changeProgress(int)));
       
   112         
       
   113     }
       
   114 }
       
   115 
       
   116 /*!
       
   117     Fetch all message parts to a message. Fetches also message part data structure,
       
   118     if not fetched already.
       
   119       If earlier fetch operation exist it is cancelled and deleted.
       
   120     Set observer with setObserver method to get process and complete events
       
   121 */
       
   122 void NmAttachmentManager::fetchAllMessageParts(
       
   123         const NmId &mailboxId, 
       
   124         const NmId &folderId, 
       
   125         const NmId &messageId)
       
   126 {
       
   127     fetchMsg = mUiEngine.message(mailboxId,folderId,messageId);
       
   128     
       
   129     // Check if we have part data structure.    
       
   130     if (fetchMsg->childParts().count() == 0 &&
       
   131         fetchMsg->fetchedSize() < fetchMsg->size()) {
       
   132 
       
   133         // cancel old fetch operation, Does nothing if fetch not ongoing
       
   134         cancelFetch();
       
   135         
       
   136         // Fetch the message.
       
   137         mMsgFetchOperation = mUiEngine.fetchMessage(
       
   138             fetchMsg->envelope().mailboxId(),
       
   139             fetchMsg->envelope().folderId(),
       
   140             fetchMsg->envelope().messageId());
       
   141         
       
   142         mAttaId = 0;
       
   143         mIsFetching = true;
       
   144 
       
   145         if (mMsgFetchOperation) {
       
   146             QObject::connect(mMsgFetchOperation,
       
   147                     SIGNAL(operationCompleted(int)),
       
   148                     this,
       
   149                     SLOT(messageFetched(int)));
       
   150         }
       
   151         
       
   152     }
       
   153     else {
       
   154         messageFetched(NmNoError);
       
   155     }
       
   156 }
       
   157 
       
   158 /*!
    80     Retruns true if fetch operation is ongoing
   159     Retruns true if fetch operation is ongoing
    81 */
   160 */
    82 bool NmAttachmentManager::isFetching() const
   161 bool NmAttachmentManager::isFetching() const
    83 {
   162 {
    84     return mIsFetching;
   163     return mIsFetching;
    97 */
   176 */
    98 void NmAttachmentManager::cancelFetch()
   177 void NmAttachmentManager::cancelFetch()
    99 {
   178 {
   100     if (mFetchOperation && mFetchOperation->isRunning()) { 
   179     if (mFetchOperation && mFetchOperation->isRunning()) { 
   101         mFetchOperation->cancelOperation();
   180         mFetchOperation->cancelOperation();
       
   181     }
       
   182     if (mMsgFetchOperation && mMsgFetchOperation->isRunning()) {
       
   183         mMsgFetchOperation->cancelOperation();
   102     }
   184     }
   103     mIsFetching = false;
   185     mIsFetching = false;
   104     mAttaId = 0;
   186     mAttaId = 0;
   105     mProgressValue = 0;
   187     mProgressValue = 0;
   106 }
   188 }
   125         mFetchObserver->fetchCompleted(result);
   207         mFetchObserver->fetchCompleted(result);
   126     }
   208     }
   127     mAttaId = 0;
   209     mAttaId = 0;
   128     mProgressValue = 0;
   210     mProgressValue = 0;
   129     mIsFetching = false;
   211     mIsFetching = false;
       
   212 }
       
   213 
       
   214 /*!
       
   215     Used by message fetch operation
       
   216 */
       
   217 void NmAttachmentManager::messageFetched(int result)
       
   218 {
       
   219     QObject::disconnect(mFetchOperation,
       
   220                 SIGNAL(operationCompleted(int)),
       
   221                 this,
       
   222                 SLOT(messageFetched(int)));
       
   223     
       
   224     if (result == NmNoError) {
       
   225         
       
   226         // Reload message
       
   227         fetchMsg = mUiEngine.message(
       
   228             fetchMsg->envelope().mailboxId(),
       
   229             fetchMsg->envelope().folderId(),
       
   230             fetchMsg->envelope().messageId());
       
   231         
       
   232         if (fetchMsg) {
       
   233             QList<NmId> partIds;
       
   234             NmMessagePart *part;
       
   235             foreach (part, fetchMsg->childParts()) {
       
   236                 if (part->size() > part->fetchedSize()) {
       
   237                     partIds.append(part->partId());
       
   238                 }
       
   239             }
       
   240             if (partIds.count() > 0) {
       
   241                 fetchAttachments(
       
   242                     fetchMsg->envelope().mailboxId(),
       
   243                     fetchMsg->envelope().folderId(),
       
   244                     fetchMsg->envelope().messageId(),
       
   245                     partIds);
       
   246             }
       
   247             else {
       
   248                 mFetchObserver->fetchCompleted(result);
       
   249             }
       
   250         }
       
   251         else {
       
   252             mFetchObserver->fetchCompleted(NmNotFoundError);
       
   253         }
       
   254     }
       
   255     else {
       
   256         mFetchObserver->fetchCompleted(result);
       
   257     }
   130 }
   258 }
   131 
   259 
   132 /*!
   260 /*!
   133     Sets fetch observer
   261     Sets fetch observer
   134 */
   262 */