emailuis/nmailui/src/nmattachmentmanager.cpp
changeset 23 2dc6caa42ec3
child 27 9ba4404ef423
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "nmuiheaders.h"
       
    19 
       
    20 const int NmAttachmentManagerInitialProgressPercent = 5;
       
    21 
       
    22 /*!
       
    23     \class NmAttachmentManager
       
    24     \brief Attachment download manager, shares attachment download between editor and viewer
       
    25 */
       
    26 
       
    27 /*!
       
    28 
       
    29 */
       
    30 NmAttachmentManager::NmAttachmentManager(NmUiEngine &uiEngine) :
       
    31     mUiEngine(uiEngine),
       
    32     mFetchOperation(NULL),
       
    33     mFetchObserver(NULL),
       
    34     mAttaId(0),
       
    35     mProgressValue(0),
       
    36     mIsFetching(false)
       
    37 {
       
    38 
       
    39 }
       
    40 
       
    41 /*!
       
    42 
       
    43 */
       
    44 NmAttachmentManager::~NmAttachmentManager()
       
    45 {
       
    46     // cancel fetch
       
    47     cancelFetch();
       
    48 }
       
    49 
       
    50 /*!
       
    51     Starts attachment fetch. If earlier fetch operation exist it is cancelled.
       
    52     Set observer with setObserver method to get process and complete events
       
    53 */
       
    54 void NmAttachmentManager::fetchAttachment(
       
    55         const NmId &mailboxId, 
       
    56         const NmId &folderId, 
       
    57         const NmId &messageId, 
       
    58         const NmId &messagePartId)
       
    59 {
       
    60     // cancel old fetch operation, Does nothing if fetch not ongoing
       
    61     cancelFetch();
       
    62 
       
    63     mFetchOperation = mUiEngine.fetchMessagePart(
       
    64             mailboxId, folderId, messageId, messagePartId);
       
    65     
       
    66     if (mFetchOperation) {
       
    67         mAttaId = messagePartId;
       
    68         mIsFetching = true;
       
    69         QObject::connect(mFetchOperation, SIGNAL(operationCompleted(int)),
       
    70                 this, SLOT(attachmentFetchCompleted(int)));
       
    71         
       
    72         QObject::connect(mFetchOperation, SIGNAL(operationProgressChanged(int)),
       
    73                 this, SLOT(changeProgress(int)));
       
    74         // set progress to 5 % already in start
       
    75         changeProgress(NmAttachmentManagerInitialProgressPercent);
       
    76     }
       
    77 }
       
    78 
       
    79 /*!
       
    80     Retruns true if fetch operation is ongoing
       
    81 */
       
    82 bool NmAttachmentManager::isFetching() const
       
    83 {
       
    84     return mIsFetching;
       
    85 }
       
    86 
       
    87 /*!
       
    88     Retrunrs part id of attachment if fetch operation is ongoing. Zero id is returned otherwise
       
    89 */
       
    90 NmId NmAttachmentManager::partIdUnderFetch() const
       
    91 {
       
    92     return mAttaId;
       
    93 }
       
    94 
       
    95 /*!
       
    96     Cancels fetch operation. Does nothing if fetch not ongoing
       
    97 */
       
    98 void NmAttachmentManager::cancelFetch()
       
    99 {
       
   100     if (mFetchOperation && mFetchOperation->isRunning()) { 
       
   101         mFetchOperation->cancelOperation();
       
   102     }
       
   103     mIsFetching = false;
       
   104     mAttaId = 0;
       
   105     mProgressValue = 0;
       
   106 }
       
   107 
       
   108 /*!
       
   109     Used by message part fetch operation
       
   110 */
       
   111 void NmAttachmentManager::changeProgress(int value)
       
   112 {
       
   113     if (mFetchObserver && value > mProgressValue) {
       
   114         mProgressValue = value;
       
   115         mFetchObserver->progressChanged(value);
       
   116     }
       
   117 }
       
   118 
       
   119 /*!
       
   120     Used by message part fetch operation
       
   121 */
       
   122 void NmAttachmentManager::attachmentFetchCompleted(int result)
       
   123 {
       
   124     if (mFetchObserver) {
       
   125         mFetchObserver->fetchCompleted(result);
       
   126     }
       
   127     mAttaId = 0;
       
   128     mProgressValue = 0;
       
   129     mIsFetching = false;
       
   130 }
       
   131 
       
   132 /*!
       
   133     Sets fetch observer
       
   134 */
       
   135 void NmAttachmentManager::setObserver(NmAttachmentFetchObserver *observer)
       
   136 {
       
   137     mFetchObserver = observer;
       
   138     // send progress event wheng observer changes if fetch ongoing 
       
   139     // to get progress bar updating
       
   140     if (mIsFetching) {
       
   141         changeProgress(mProgressValue);
       
   142     }
       
   143 }
       
   144 
       
   145 /*!
       
   146     Clear observer
       
   147 */
       
   148 void NmAttachmentManager::clearObserver()
       
   149 {
       
   150     mFetchObserver = NULL;
       
   151 }
       
   152 
       
   153 /*!
       
   154     Returns progress value if fetch ongoing. Otherwise returns 0.
       
   155 */
       
   156 int NmAttachmentManager::progressValue() const
       
   157 {
       
   158     return mProgressValue;
       
   159 }
       
   160