emailuis/nmailuiengine/src/nmuiengine.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2009 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 
       
    19 #include "nmuiengineheaders.h"
       
    20 
       
    21 /*!
       
    22     \class NmUiEngine
       
    23     \brief NmUiEngine provides a controller-type services for the email UI.
       
    24 
       
    25 */
       
    26 
       
    27 NmUiEngine *NmUiEngine::mInstance;
       
    28 int NmUiEngine::mReferenceCount;
       
    29 
       
    30 /*!
       
    31     Constructor
       
    32 */
       
    33 NmUiEngine::NmUiEngine() 
       
    34 :mMailboxListModel(NULL),
       
    35 mMessageListModel(NULL),
       
    36 mSendOperation(NULL),
       
    37 mSaveOperation(NULL),
       
    38 mMessageToBeSent(false),
       
    39 mMessage(NULL)
       
    40 {
       
    41     mPluginFactory = NmDataPluginFactory::instance();
       
    42     mDataManager = new NmDataManager();
       
    43 }
       
    44 
       
    45 
       
    46 /*!
       
    47     Destructor
       
    48 */
       
    49 NmUiEngine::~NmUiEngine()
       
    50 {
       
    51     if (mMessageListModel) {
       
    52         delete mMessageListModel;
       
    53         mMessageListModel = NULL;
       
    54     }
       
    55     if (mMailboxListModel) {
       
    56         delete mMailboxListModel;
       
    57         mMailboxListModel = NULL;
       
    58     }
       
    59     NmDataPluginFactory::releaseInstance(mPluginFactory);
       
    60     delete mDataManager;
       
    61     
       
    62     while (!mOperations.isEmpty()) {
       
    63         delete mOperations.takeLast();
       
    64     }
       
    65     
       
    66     delete mSendOperation;
       
    67     delete mSaveOperation;
       
    68 }
       
    69 
       
    70 /*!
       
    71 
       
    72 */
       
    73 NmUiEngine *NmUiEngine::instance()
       
    74 {
       
    75     if (!mInstance) {
       
    76     	mInstance = new NmUiEngine();
       
    77     }
       
    78     mReferenceCount++;
       
    79     return mInstance;
       
    80 }
       
    81 
       
    82 /*!
       
    83 
       
    84 */
       
    85 void NmUiEngine::releaseInstance(NmUiEngine *&instance)
       
    86 {
       
    87     //can't have passed out instances if we don't have any
       
    88     if (mInstance) {
       
    89         if(instance == mInstance) {
       
    90             instance = NULL;
       
    91             mReferenceCount--;
       
    92         }
       
    93         if (0 >= mReferenceCount) {
       
    94             delete mInstance;
       
    95             mInstance = NULL;
       
    96         }
       
    97     }
       
    98 }
       
    99 
       
   100 /*!
       
   101     Returns a list model populated with the mailbox and top level folder objects. The model is
       
   102     updated dynamically. The ownership of the model object is not moved to the caller.
       
   103 */
       
   104 NmMailboxListModel &NmUiEngine::mailboxListModel()
       
   105 {
       
   106     if (!mMailboxListModel) {
       
   107         refreshMailboxListModel(); // creates the model too
       
   108     }
       
   109     
       
   110     return *mMailboxListModel;
       
   111 }
       
   112         
       
   113 /*!
       
   114     Populate the list model with the mailbox and top level folder objects. The model is
       
   115     updated dynamically. Creates the model if needed.
       
   116 */
       
   117 void NmUiEngine::refreshMailboxListModel()
       
   118 {
       
   119     if (!mMailboxListModel) {
       
   120         mMailboxListModel = new NmMailboxListModel(*mDataManager);
       
   121         
       
   122         // Connect the model to the plugins to receive change notifications
       
   123         QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
       
   124         for (int i = 0; i < dataPlugins->count(); i++) {
       
   125             QObject *plugin = (*dataPlugins)[i];
       
   126             if (plugin) {
       
   127                 connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)),
       
   128                     mMailboxListModel, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)));
       
   129             }
       
   130         }
       
   131     } else {
       
   132         mMailboxListModel->clear();
       
   133     }
       
   134     
       
   135     QList<NmMailbox*> mailboxList;
       
   136     mDataManager->listMailboxes(mailboxList);
       
   137     mMailboxListModel->refresh(mailboxList);
       
   138     while (!mailboxList.isEmpty()) {
       
   139         delete mailboxList.takeFirst();
       
   140     }
       
   141 }
       
   142 
       
   143 /*!
       
   144     Returns a message list model for a folder identified by \a mailboxId and \a folderId.
       
   145     The model is updated dynamically. The ownership of the model object is not moved to the caller.
       
   146 */
       
   147 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId, const NmId &folderId)
       
   148 {
       
   149     if (!mMessageListModel){
       
   150         mMessageListModel = new NmMessageListModel(*mDataManager);
       
   151     }
       
   152     else{
       
   153         mMessageListModel->clear();
       
   154     }
       
   155     QObject *plugin =
       
   156         mPluginFactory->pluginInstance(mailboxId);
       
   157     if (plugin) {
       
   158         QObject::connect(plugin,
       
   159             SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
       
   160         mMessageListModel,
       
   161             SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &)),
       
   162             Qt::UniqueConnection );
       
   163         
       
   164         QObject::connect(plugin,
       
   165             SIGNAL(syncStateEvent(NmSyncState, const NmId &)),
       
   166             this,
       
   167             SIGNAL(syncStateEvent(NmSyncState, const NmId &)),
       
   168             Qt::UniqueConnection);
       
   169         
       
   170         QObject::connect(plugin,
       
   171             SIGNAL(connectionEvent(NmConnectState, const NmId &)),
       
   172             this,
       
   173             SIGNAL(connectionEvent(NmConnectState, const NmId &)),
       
   174             Qt::UniqueConnection);
       
   175         
       
   176         // Start to listen mailbox events
       
   177         NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(plugin);
       
   178         if (pluginInterface) {
       
   179             pluginInterface->subscribeMailboxEvents(mailboxId);
       
   180         }
       
   181     }
       
   182     QList<NmMessageEnvelope*> messageEnvelopeList;
       
   183     mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
       
   184     mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
       
   185     while (!messageEnvelopeList.isEmpty()) {
       
   186         delete messageEnvelopeList.takeFirst();
       
   187     }
       
   188     return *mMessageListModel;
       
   189 }
       
   190 
       
   191 /*!
       
   192     
       
   193 */
       
   194 void NmUiEngine::releaseMessageListModel(const NmId &mailboxId)
       
   195 {
       
   196     // Stop listening mailbox events
       
   197     NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(mailboxId);
       
   198     if (pluginInterface) {
       
   199         pluginInterface->unsubscribeMailboxEvents(mailboxId);
       
   200     }
       
   201 }
       
   202 
       
   203 /*!
       
   204     Get the identifier of the standard folder of a type \a folderType 
       
   205     from the mailbox \a mailboxId.
       
   206 */
       
   207 NmId NmUiEngine::standardFolderId(
       
   208     const NmId &mailboxId,
       
   209     NmFolderType folderType)
       
   210 {
       
   211     NmId value;
       
   212     if (folderType != NmFolderOther) {
       
   213         NmDataPluginInterface *plugin =
       
   214             mPluginFactory->interfaceInstance(mailboxId);
       
   215         if(plugin) {
       
   216             value = plugin->getStandardFolderId(mailboxId, folderType);
       
   217         }
       
   218     }
       
   219     return value;
       
   220 }
       
   221 
       
   222 /*!
       
   223     Returns a message identified by \a mailboxId,  \a folderId and \amessageId.
       
   224     The ownership of the  object is moved to the caller.
       
   225     Returns null pointer if the message is not found.
       
   226 */
       
   227 NmMessage *NmUiEngine::message(const NmId &mailboxId,
       
   228                       const NmId &folderId,
       
   229                       const NmId &messageId)
       
   230 {
       
   231     NmMessage *message = mDataManager->message(mailboxId, folderId, messageId);
       
   232     return message;
       
   233 }
       
   234 
       
   235 /*!
       
   236 
       
   237 */
       
   238 NmOperation *NmUiEngine::fetchMessage( const NmId &mailboxId,
       
   239     const NmId &folderId,
       
   240     const NmId &messageId )
       
   241 {
       
   242     NmOperation *value(NULL);
       
   243     NmDataPluginInterface *plugin =
       
   244         mPluginFactory->interfaceInstance(mailboxId);
       
   245     if (plugin) {
       
   246         value = plugin->fetchMessage(mailboxId, folderId, messageId);
       
   247     }
       
   248     return value;
       
   249 }
       
   250 
       
   251 /*!
       
   252 
       
   253 */
       
   254 NmOperation *NmUiEngine::fetchMessagePart(
       
   255     const NmId &mailboxId,
       
   256     const NmId &folderId,
       
   257     const NmId &messageId,
       
   258     const NmId& messagePartId)
       
   259 {
       
   260     NmOperation *value(NULL);
       
   261     NmDataPluginInterface *plugin =
       
   262         mPluginFactory->interfaceInstance(mailboxId);
       
   263     if (plugin) {
       
   264         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
       
   265     }
       
   266     return value;
       
   267 }
       
   268 
       
   269 /*!
       
   270     Get content to message part
       
   271 */
       
   272 int NmUiEngine::contentToMessagePart(
       
   273     const NmId &mailboxId,
       
   274     const NmId &folderId,
       
   275     const NmId &messageId,
       
   276     NmMessagePart &messagePart)
       
   277 {
       
   278     return mDataManager->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
       
   279 }
       
   280 
       
   281 /*!
       
   282     Deletes messages from model and routes call to plugin
       
   283 */
       
   284 int NmUiEngine::deleteMessages(
       
   285 	const NmId &mailboxId,
       
   286 	const NmId &folderId,
       
   287 	const QList<NmId> &messageIdList)
       
   288 {
       
   289     int result(NmNotFoundError);
       
   290 	if (mMessageListModel) {
       
   291 	    mMessageListModel->handleMessageEvent(NmMessageDeleted, folderId, messageIdList);
       
   292 	}
       
   293     NmDataPluginInterface *plugin =
       
   294             mPluginFactory->interfaceInstance(mailboxId);
       
   295     if (plugin) {
       
   296           result = plugin->deleteMessages(
       
   297 	            mailboxId, folderId, messageIdList);
       
   298     }
       
   299 	return result;
       
   300 }
       
   301 
       
   302 /*!
       
   303     Sets envelope property given in argument.
       
   304     Ownership of operation object is transferred to the caller.
       
   305 */
       
   306 
       
   307 NmStoreEnvelopesOperation *NmUiEngine::setEnvelopes(
       
   308         const NmId &mailboxId,
       
   309         const NmId &folderId,
       
   310         NmEnvelopeProperties property,
       
   311         const QList<const NmMessageEnvelope*> &envelopeList)
       
   312 {
       
   313     NMLOG("NmUiEngine::setEnvelopes() <---");
       
   314     NmStoreEnvelopesOperation *operation(NULL);
       
   315     if (mMessageListModel && envelopeList.count()) {
       
   316         QList<NmId> messageIdList;
       
   317         
       
   318         for (int i(0); i < envelopeList.count(); i++){
       
   319             messageIdList.append(envelopeList[i]->id());
       
   320         }
       
   321         mMessageListModel->setEnvelopeProperties(
       
   322                            property, messageIdList);
       
   323         // Store new envelopes to plugin
       
   324         NmDataPluginInterface *plugin =
       
   325             mPluginFactory->interfaceInstance(mailboxId);
       
   326         if (plugin) {
       
   327             operation = plugin->storeEnvelopes(
       
   328                     mailboxId, folderId, envelopeList);
       
   329         }
       
   330         messageIdList.clear();
       
   331     }
       
   332     
       
   333     NMLOG("NmUiEngine::setEnvelopes() --->");
       
   334     return operation;
       
   335 }
       
   336 
       
   337 
       
   338 /*!
       
   339     Returns a mailbox meta data object from model with the ID \a mailboxId.
       
   340     Ownership of the return value is not moved to the caller.
       
   341     Returns NULL if the mailbox is not found.
       
   342 */
       
   343 NmMailboxMetaData *NmUiEngine::mailboxById(const NmId &mailboxId)
       
   344 {
       
   345     NmMailboxMetaData *meta(NULL);
       
   346     if (mMailboxListModel) {
       
   347 	    for (int i(0); i < mMailboxListModel->rowCount(); i++) {
       
   348 	        QModelIndex index = mMailboxListModel->index(i,0);
       
   349 	        NmMailboxMetaData *mailbox =
       
   350 	            mMailboxListModel->data(index, Qt::DisplayRole).value<NmMailboxMetaData*>();
       
   351 	        if (mailbox && mailbox->id() == mailboxId) {
       
   352 	            meta = mailbox;
       
   353 	            break;
       
   354 	        }
       
   355 	    }
       
   356     }
       
   357     return meta;
       
   358 }
       
   359 
       
   360 
       
   361 /*!
       
   362     Creates a new message (into Drafts-folder).
       
   363     Ownership of operation object is transferred to the caller.
       
   364 */
       
   365 NmMessageCreationOperation *NmUiEngine::createNewMessage(const NmId &mailboxId)
       
   366 {
       
   367     NmMessageCreationOperation *value(NULL);
       
   368     NmDataPluginInterface *plugin =
       
   369         mPluginFactory->interfaceInstance(mailboxId);
       
   370     if (plugin) {
       
   371         value = plugin->createNewMessage(mailboxId);
       
   372     }
       
   373     return value;
       
   374 }
       
   375 
       
   376 /*!
       
   377     Creates a new forward message (into Drafts-folder).
       
   378     Ownership of operation object is transferred to the caller.
       
   379 */
       
   380 NmMessageCreationOperation *NmUiEngine::createForwardMessage(
       
   381         const NmId &mailboxId,
       
   382         const NmId &originalMessageId)
       
   383 {
       
   384     NmMessageCreationOperation *value(NULL);
       
   385     NmDataPluginInterface *plugin =
       
   386         mPluginFactory->interfaceInstance(mailboxId);
       
   387     if (plugin) {
       
   388         value = plugin->createForwardMessage(mailboxId, originalMessageId);
       
   389     }
       
   390     return value;
       
   391 }
       
   392 
       
   393 /*!
       
   394     Creates a new reply message (into Drafts-folder).
       
   395     Ownership of operation object is transferred to the caller.
       
   396 */
       
   397 NmMessageCreationOperation *NmUiEngine::createReplyMessage(
       
   398         const NmId &mailboxId,
       
   399         const NmId &originalMessageId,
       
   400         bool replyAll)
       
   401 {
       
   402     NmMessageCreationOperation *value(NULL);
       
   403     NmDataPluginInterface *plugin =
       
   404         mPluginFactory->interfaceInstance(mailboxId);
       
   405     if (plugin) {
       
   406         value = plugin->createReplyMessage(mailboxId, originalMessageId, replyAll);
       
   407     }
       
   408     return value;
       
   409 }
       
   410 
       
   411 /*!
       
   412     Saves a message (into message store).
       
   413 */
       
   414 int NmUiEngine::saveMessage(const NmMessage &message)
       
   415 {
       
   416     const NmId &mailboxId = message.mailboxId();
       
   417     int ret(NmNotFoundError);
       
   418     NmDataPluginInterface *plugin =
       
   419         mPluginFactory->interfaceInstance(mailboxId);
       
   420     if (plugin) {
       
   421         ret = plugin->saveMessage(message);
       
   422     }
       
   423     return ret;
       
   424 }
       
   425 
       
   426 /*!
       
   427     Saves a message with its subparts (into message store).
       
   428     Ownership of operation object is transferred to the caller.
       
   429 */
       
   430 NmOperation *NmUiEngine::saveMessageWithSubparts(const NmMessage &message)
       
   431 {
       
   432     NmOperation *value(NULL);
       
   433     const NmId &mailboxId = message.mailboxId();
       
   434     
       
   435     NmDataPluginInterface *plugin =
       
   436         mPluginFactory->interfaceInstance(mailboxId);
       
   437 
       
   438     if (plugin) {
       
   439         value = plugin->saveMessageWithSubparts(message);
       
   440     }
       
   441     return value;
       
   442 }
       
   443 
       
   444 /*!
       
   445     Refreshes mailbox.
       
   446 */
       
   447 int NmUiEngine::refreshMailbox(const NmId &mailboxId )
       
   448 {
       
   449     int ret(NmNotFoundError);
       
   450     NmDataPluginInterface *plugin =
       
   451         mPluginFactory->interfaceInstance(mailboxId);
       
   452     if (plugin) {
       
   453         ret = plugin->refreshMailbox(mailboxId);
       
   454     }
       
   455     return ret;
       
   456 }
       
   457 
       
   458 /*!
       
   459     Removes message from given mailbox and folder
       
   460     - routes call to plugin
       
   461 */
       
   462 int NmUiEngine::removeMessage(
       
   463     const NmId &mailboxId,
       
   464     const NmId &folderId,
       
   465     const NmId &messageId)
       
   466 {
       
   467     int result(NmNotFoundError);
       
   468     NmDataPluginInterface *plugin =
       
   469             mPluginFactory->interfaceInstance(mailboxId);
       
   470     if (plugin) {
       
   471           result = plugin->removeMessage(mailboxId, folderId, messageId);
       
   472     }
       
   473     return result;
       
   474 }
       
   475 
       
   476 /*!
       
   477     Takes ownership of an operation and connects to 
       
   478     it's completion signal
       
   479  */
       
   480 void NmUiEngine::storeOperation(NmOperation *op)
       
   481 {
       
   482     mOperations.append(op);
       
   483     connect(
       
   484             op, 
       
   485             SIGNAL(operationCompleted(int)), 
       
   486             this, 
       
   487             SLOT(handleCompletedOperation()));
       
   488 }
       
   489 
       
   490 /*!
       
   491     Sends the given message.
       
   492  */
       
   493 void NmUiEngine::sendMessage(NmMessage *message)
       
   494 {
       
   495     //First trigger message storing
       
   496     if (message) {
       
   497 
       
   498         if (mMessage) {
       
   499             delete mMessage;
       
   500             mMessage = NULL;
       
   501         }
       
   502         mMessage = message;
       
   503 
       
   504         if (mSaveOperation) {
       
   505             delete mSaveOperation;
       
   506             mSaveOperation = NULL;
       
   507         }
       
   508         mSaveOperation = this->saveMessageWithSubparts(*message);
       
   509 
       
   510         if (mSaveOperation) {
       
   511             connect(mSaveOperation, SIGNAL(operationCompleted(int)), this,
       
   512                 SLOT(handleCompletedSaveOperation(int)));
       
   513         }
       
   514         mMessageToBeSent = true;
       
   515     }
       
   516 }
       
   517 
       
   518 /*!
       
   519     Is sending operation in progress.
       
   520  */
       
   521 bool NmUiEngine::isSendingMessage() const
       
   522 {
       
   523     int ret(false);
       
   524     if (mSendOperation) {
       
   525         ret = true;
       
   526     }
       
   527     return ret;
       
   528 }
       
   529 
       
   530 /*!
       
   531    Returns a pointer to the message that is being sent. Returns NULL if not sending.
       
   532  */
       
   533 const NmMessage *NmUiEngine::messageBeingSent()
       
   534 {
       
   535     const NmMessage *message = NULL;
       
   536     
       
   537     if (mSendOperation != NULL) {
       
   538         message = mSendOperation->getMessage();
       
   539     }
       
   540     
       
   541     return message;
       
   542 }
       
   543 
       
   544 /*!
       
   545     Add file attachment into given message. Return the operation object for
       
   546     observing/cancelling. Ownership of operation object is transferred to the caller.
       
   547  */
       
   548 NmAddAttachmentsOperation *NmUiEngine::addAttachments(
       
   549     const NmMessage &message,
       
   550     const QList<QString> &fileList)
       
   551 {
       
   552     NmDataPluginInterface *plugin =
       
   553         mPluginFactory->interfaceInstance(message.mailboxId());
       
   554     
       
   555     NmAddAttachmentsOperation *ret(NULL);
       
   556     
       
   557     if (plugin) {
       
   558         ret = plugin->addAttachments(message, fileList);
       
   559     }
       
   560 
       
   561     return ret;
       
   562 }
       
   563 
       
   564 /*!
       
   565     Remove attached file from given message. Return the operation object for
       
   566     observing/cancelling. Ownership of operation object is transferred to the caller.
       
   567  */
       
   568 NmOperation *NmUiEngine::removeAttachment(
       
   569     const NmMessage &message,
       
   570     const NmId &attachmentPartId)
       
   571 {
       
   572     NmDataPluginInterface *plugin =
       
   573         mPluginFactory->interfaceInstance(message.mailboxId());
       
   574     
       
   575     NmOperation *ret(NULL);
       
   576     
       
   577     if (plugin) {
       
   578         ret = plugin->removeAttachment(message, attachmentPartId);
       
   579     }
       
   580 
       
   581     return ret;
       
   582 }
       
   583 
       
   584 /*!
       
   585     Ownership of operation object is transferred to the caller.
       
   586  */
       
   587 NmCheckOutboxOperation *NmUiEngine::checkOutbox(const NmId &mailboxId)
       
   588 {
       
   589     NmDataPluginInterface *plugin =
       
   590         mPluginFactory->interfaceInstance(mailboxId);
       
   591 
       
   592     NmCheckOutboxOperation *ret(NULL);
       
   593     
       
   594     if (plugin) {
       
   595         ret = plugin->checkOutbox(mailboxId);
       
   596     }
       
   597     
       
   598     return ret;
       
   599 }
       
   600 
       
   601 /*!
       
   602     Returns the current sync state of the mailbox
       
   603  */
       
   604 NmSyncState NmUiEngine::syncState(const NmId& mailboxId)
       
   605 {
       
   606     NmDataPluginInterface *plugin =
       
   607                 mPluginFactory->interfaceInstance(mailboxId);
       
   608     if (plugin) {
       
   609         return plugin->syncState(mailboxId);
       
   610     }
       
   611     else {
       
   612         return SyncComplete;
       
   613     }
       
   614 }
       
   615 
       
   616 /*!
       
   617     Returns the current connection state of the mailbox
       
   618  */
       
   619 NmConnectState NmUiEngine::connectionState(const NmId& mailboxId)
       
   620 {
       
   621     NmDataPluginInterface *plugin =
       
   622                 mPluginFactory->interfaceInstance(mailboxId);
       
   623     if (plugin) {
       
   624         return plugin->connectionState(mailboxId);
       
   625     }
       
   626     else {
       
   627         return Disconnected;
       
   628     }
       
   629 }
       
   630 
       
   631 /*!
       
   632  * deletes completed operations
       
   633  * 
       
   634  */
       
   635 void NmUiEngine::handleCompletedOperation()
       
   636 {
       
   637     NMLOG("NmUiEngine::handleCompletedOperation() <---");
       
   638     int count = mOperations.count();
       
   639     
       
   640     QObject *sender = this->sender();
       
   641     
       
   642     for(int i(0); i < count; i++){
       
   643         if (mOperations[i] == sender){
       
   644             delete mOperations.takeAt(i);
       
   645             }
       
   646         }
       
   647     NMLOG("NmUiEngine::handleCompletedOperation() --->");
       
   648 }
       
   649     
       
   650 /*!
       
   651     Handle completed send operation
       
   652  */
       
   653 void NmUiEngine::handleCompletedSendOperation()
       
   654 { // let the callback method finish until cleaning the operation
       
   655     QTimer::singleShot(1, this, SLOT(cleanupSendOperation()));
       
   656 }
       
   657 
       
   658 /*!
       
   659     Cleanup the send operation
       
   660  */
       
   661 void NmUiEngine::cleanupSendOperation()
       
   662 {
       
   663     delete mSendOperation;
       
   664     mSendOperation = NULL;
       
   665     // delete the sent messages from the store if necessary
       
   666     // ...
       
   667 }
       
   668  
       
   669 /*!
       
   670     Handle completed store message operation
       
   671  */
       
   672 void NmUiEngine::handleCompletedSaveOperation(int error)
       
   673 {
       
   674 	if (mMessage && mMessageToBeSent && error == NmNoError)
       
   675 	{
       
   676 	    mMessageToBeSent = false;
       
   677 	    
       
   678 	    NmDataPluginInterface *plugin =
       
   679             mPluginFactory->interfaceInstance(mMessage->mailboxId());
       
   680         
       
   681         if (plugin) {
       
   682             // to be on the safer side:
       
   683             // we shouldn't even be here if mSendOperation != NULL
       
   684 			delete mSendOperation;
       
   685             mSendOperation = NULL;
       
   686             // ownership of mMessage changes
       
   687             mSendOperation = plugin->sendMessage(mMessage);
       
   688             mMessage = NULL;
       
   689             // don't put this to mOperations as we need to handle this
       
   690             // operation separately
       
   691 			if (mSendOperation) {
       
   692 			    connect(mSendOperation, 
       
   693 			            SIGNAL(operationCompleted(int)), 
       
   694 			            this, 
       
   695 			            SLOT(handleCompletedSendOperation()));
       
   696 			}
       
   697         }
       
   698 	}
       
   699 }