emailuis/nmailuiengine/src/nmuiengine.cpp
changeset 75 47d84de1c893
parent 72 64e38f08e49c
child 74 6c59112cfd31
equal deleted inserted replaced
72:64e38f08e49c 75:47d84de1c893
    40   mSendOperation(NULL),
    40   mSendOperation(NULL),
    41   mRemoveDraftOperation(NULL),
    41   mRemoveDraftOperation(NULL),
    42   mSaveDraftOperation(NULL),
    42   mSaveDraftOperation(NULL),
    43   mDraftMessage(NULL)
    43   mDraftMessage(NULL)
    44 {
    44 {
    45     NM_FUNCTION;
       
    46 
       
    47     mPluginFactory = NmDataPluginFactory::instance();
    45     mPluginFactory = NmDataPluginFactory::instance();
    48     mDataManager = new NmDataManager();
    46     mDataManager = new NmDataManager();
    49     // Connect to the plugins to receive change notifications
    47     // Connect to the plugins to receive change notifications
    50     QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
    48     QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
    51     for (int i(0); i < dataPlugins->count(); i++) {
    49     for (int i(0); i < dataPlugins->count(); i++) {
    90 /*!
    88 /*!
    91     Class destructor.
    89     Class destructor.
    92 */
    90 */
    93 NmUiEngine::~NmUiEngine()
    91 NmUiEngine::~NmUiEngine()
    94 {
    92 {
    95     NM_FUNCTION;
       
    96 
       
    97     enableSyncIndicator(false);
    93     enableSyncIndicator(false);
    98 
    94 
    99     if (mMessageSearchListModel) {
    95     if (mMessageSearchListModel) {
   100         delete mMessageSearchListModel;
    96         delete mMessageSearchListModel;
   101         mMessageSearchListModel = NULL;
    97         mMessageSearchListModel = NULL;
   163 /*!
   159 /*!
   164 
   160 
   165 */
   161 */
   166 NmUiEngine *NmUiEngine::instance()
   162 NmUiEngine *NmUiEngine::instance()
   167 {
   163 {
   168     NM_FUNCTION;
       
   169 
       
   170     if (!mInstance) {
   164     if (!mInstance) {
   171     	mInstance = new NmUiEngine();
   165     	mInstance = new NmUiEngine();
   172     }
   166     }
   173     mReferenceCount++;
   167     mReferenceCount++;
   174     return mInstance;
   168     return mInstance;
   177 /*!
   171 /*!
   178 
   172 
   179 */
   173 */
   180 void NmUiEngine::releaseInstance(NmUiEngine *&instance)
   174 void NmUiEngine::releaseInstance(NmUiEngine *&instance)
   181 {
   175 {
   182     NM_FUNCTION;
       
   183 
       
   184     //can't have passed out instances if we don't have any
   176     //can't have passed out instances if we don't have any
   185     if (mInstance) {
   177     if (mInstance) {
   186         if(instance == mInstance) {
   178         if(instance == mInstance) {
   187             instance = NULL;
   179             instance = NULL;
   188             mReferenceCount--;
   180             mReferenceCount--;
   198     Returns a list model populated with the mailbox and top level folder objects. The model is
   190     Returns a list model populated with the mailbox and top level folder objects. The model is
   199     updated dynamically. The ownership of the model object is not moved to the caller.
   191     updated dynamically. The ownership of the model object is not moved to the caller.
   200 */
   192 */
   201 NmMailboxListModel &NmUiEngine::mailboxListModel()
   193 NmMailboxListModel &NmUiEngine::mailboxListModel()
   202 {
   194 {
   203     NM_FUNCTION;
       
   204 
       
   205     if (!mMailboxListModel) {
   195     if (!mMailboxListModel) {
   206         refreshMailboxListModel(); // creates the model too
   196         refreshMailboxListModel(); // creates the model too
   207     }
   197     }
   208 
   198 
   209     return *mMailboxListModel;
   199     return *mMailboxListModel;
   213     Populate the list model with the mailbox and top level folder objects. The model is
   203     Populate the list model with the mailbox and top level folder objects. The model is
   214     updated dynamically. Creates the model if needed.
   204     updated dynamically. Creates the model if needed.
   215 */
   205 */
   216 void NmUiEngine::refreshMailboxListModel()
   206 void NmUiEngine::refreshMailboxListModel()
   217 {
   207 {
   218     NM_FUNCTION;
       
   219 
       
   220     if (!mMailboxListModel) {
   208     if (!mMailboxListModel) {
   221         mMailboxListModel = new NmMailboxListModel(*mDataManager);
   209         mMailboxListModel = new NmMailboxListModel(*mDataManager);
   222 
   210 
   223         // Connect the model to the plugins to receive change notifications
   211         // Connect the model to the plugins to receive change notifications
   224         QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
   212         QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
   248     object is not moved to the caller.
   236     object is not moved to the caller.
   249 */
   237 */
   250 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId,
   238 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId,
   251                                                  const NmId &folderId)
   239                                                  const NmId &folderId)
   252 {
   240 {
   253     NM_FUNCTION;
       
   254 
       
   255     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
   241     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
   256     bool isInbox(false);
   242     bool isInbox(false);
   257     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   243     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   258         isInbox=true;
   244         isInbox=true;
   259     }
   245     }
   265                                 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection );
   251                                 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection );
   266         // Create inbox list model only once when entering to inbox for the first time
   252         // Create inbox list model only once when entering to inbox for the first time
   267         // or re-create inbox list model when mailbox has changed
   253         // or re-create inbox list model when mailbox has changed
   268         if ((!mInboxListModel&&isInbox)||
   254         if ((!mInboxListModel&&isInbox)||
   269             (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){
   255             (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){
   270             // Delete previous model and set to NULL. Deleting model will also
   256             createMessageListModel(&mInboxListModel, mailboxId, folderId);
   271             // delete all items in model.
       
   272             if (mInboxListModel){
       
   273                 delete mInboxListModel;
       
   274                 mInboxListModel=NULL;
       
   275             }
       
   276             // Create new inbox model
       
   277             mInboxListModel = new NmMessageListModel(*mDataManager);
       
   278             // Initial fill up of inbox list model, otherwise updated in the background
       
   279             QList<NmMessageEnvelope*> messageEnvelopeList;
       
   280             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
       
   281             mInboxListModel->refresh(mailboxId, folderId, messageEnvelopeList);
       
   282 
       
   283             while (!messageEnvelopeList.isEmpty()) {
       
   284                 delete messageEnvelopeList.takeFirst();
       
   285             }
       
   286         }
   257         }
   287         // Selected folder is not inbox folder for the mailbox
   258         // Selected folder is not inbox folder for the mailbox
   288         else if (!isInbox){
   259         else if (!isInbox){
   289             // Recreate model for other folders when needed, previous model
   260             // Recreate model for other folders when needed, previous model
   290             // items are deleted from the memory with the old model
   261             // items are deleted from the memory with the old model
   291             if (mMessageListModel){
   262             createMessageListModel(&mMessageListModel, mailboxId, folderId);
   292                 delete mMessageListModel;
       
   293                 mMessageListModel=NULL;
       
   294             }
       
   295             mMessageListModel = new NmMessageListModel(*mDataManager);
       
   296 
       
   297             // Fill up other model
       
   298             QList<NmMessageEnvelope*> messageEnvelopeList;
       
   299             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
       
   300             mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
       
   301 
       
   302             while (!messageEnvelopeList.isEmpty()) {
       
   303                 delete messageEnvelopeList.takeFirst();
       
   304             }
       
   305         }
   263         }
   306     }
   264     }
   307 
   265 
   308     // Connect sync state changed
   266     // Connect sync state changed
   309     if (plugin){
   267     if (plugin){
   336 
   294 
   337     \return A message list model.
   295     \return A message list model.
   338 */
   296 */
   339 NmMessageListModel &NmUiEngine::messageListModelForSearch(const NmId &mailboxId)
   297 NmMessageListModel &NmUiEngine::messageListModelForSearch(const NmId &mailboxId)
   340 {
   298 {
   341     NM_FUNCTION;
       
   342 
       
   343     Q_UNUSED(mailboxId);
   299     Q_UNUSED(mailboxId);
   344 
   300 
   345     if (!mMessageSearchListModel) {
   301     if (!mMessageSearchListModel) {
   346         mMessageSearchListModel = new NmMessageListModel(*mDataManager);
   302         mMessageSearchListModel = new NmMessageListModel(*mDataManager);
   347         mMessageSearchListModel->setIgnoreFolderIds(true);
   303         mMessageSearchListModel->setIgnoreFolderIds(true);
   374 */
   330 */
   375 NmId NmUiEngine::standardFolderId(
   331 NmId NmUiEngine::standardFolderId(
   376     const NmId &mailboxId,
   332     const NmId &mailboxId,
   377     NmFolderType folderType)
   333     NmFolderType folderType)
   378 {
   334 {
   379     NM_FUNCTION;
       
   380 
       
   381     NmId value;
   335     NmId value;
   382     if (folderType != NmFolderOther) {
   336     if (folderType != NmFolderOther) {
   383         NmDataPluginInterface *plugin =
   337         NmDataPluginInterface *plugin =
   384             mPluginFactory->interfaceInstance(mailboxId);
   338             mPluginFactory->interfaceInstance(mailboxId);
   385         if(plugin) {
   339         if(plugin) {
   396 */
   350 */
   397 NmMessage *NmUiEngine::message(const NmId &mailboxId,
   351 NmMessage *NmUiEngine::message(const NmId &mailboxId,
   398                       const NmId &folderId,
   352                       const NmId &folderId,
   399                       const NmId &messageId)
   353                       const NmId &messageId)
   400 {
   354 {
   401     NM_FUNCTION;
       
   402 
       
   403     NmMessage *message = mDataManager->message(mailboxId, folderId, messageId);
   355     NmMessage *message = mDataManager->message(mailboxId, folderId, messageId);
   404     return message;
   356     return message;
   405 }
   357 }
   406 
   358 
   407 /*!
   359 /*!
   409 */
   361 */
   410 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId,
   362 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId,
   411     const NmId &folderId,
   363     const NmId &folderId,
   412     const NmId &messageId )
   364     const NmId &messageId )
   413 {
   365 {
   414     NM_FUNCTION;
       
   415 
       
   416     QPointer<NmOperation> value(NULL);
   366     QPointer<NmOperation> value(NULL);
   417     NmDataPluginInterface *plugin =
   367     NmDataPluginInterface *plugin =
   418         mPluginFactory->interfaceInstance(mailboxId);
   368         mPluginFactory->interfaceInstance(mailboxId);
   419     if (plugin) {
   369     if (plugin) {
   420         value = plugin->fetchMessage(mailboxId, folderId, messageId);
   370         value = plugin->fetchMessage(mailboxId, folderId, messageId);
   429     const NmId &mailboxId,
   379     const NmId &mailboxId,
   430     const NmId &folderId,
   380     const NmId &folderId,
   431     const NmId &messageId,
   381     const NmId &messageId,
   432     const NmId &messagePartId)
   382     const NmId &messagePartId)
   433 {
   383 {
   434     NM_FUNCTION;
       
   435 
       
   436     QPointer<NmOperation> value(NULL);
   384     QPointer<NmOperation> value(NULL);
   437     NmDataPluginInterface *plugin =
   385     NmDataPluginInterface *plugin =
   438         mPluginFactory->interfaceInstance(mailboxId);
   386         mPluginFactory->interfaceInstance(mailboxId);
   439     if (plugin) {
   387     if (plugin) {
   440         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
   388         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
   449     const NmId &mailboxId,
   397     const NmId &mailboxId,
   450     const NmId &folderId,
   398     const NmId &folderId,
   451     const NmId &messageId,
   399     const NmId &messageId,
   452     const QList<NmId> &messagePartIds)
   400     const QList<NmId> &messagePartIds)
   453 {
   401 {
   454     NM_FUNCTION;
       
   455 
       
   456     QPointer<NmOperation> value(NULL);
   402     QPointer<NmOperation> value(NULL);
   457     NmDataPluginInterface *plugin =
   403     NmDataPluginInterface *plugin =
   458         mPluginFactory->interfaceInstance(mailboxId);
   404         mPluginFactory->interfaceInstance(mailboxId);
   459     if (plugin) {
   405     if (plugin) {
   460         value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds);
   406         value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds);
   469         const NmId &mailboxId,
   415         const NmId &mailboxId,
   470         const NmId &folderId,
   416         const NmId &folderId,
   471         const NmId &messageId,
   417         const NmId &messageId,
   472         const NmId &messagePartId)
   418         const NmId &messagePartId)
   473 {
   419 {
   474     NM_FUNCTION;
       
   475 
       
   476     NmDataPluginInterface *plugin =
   420     NmDataPluginInterface *plugin =
   477         mPluginFactory->interfaceInstance(mailboxId);
   421         mPluginFactory->interfaceInstance(mailboxId);
   478     if (plugin) {
   422     if (plugin) {
   479         return plugin->messagePartFile(mailboxId, folderId, messageId, messagePartId);
   423         return plugin->messagePartFile(mailboxId, folderId, messageId, messagePartId);
   480     }
   424     }
   490     const NmId &mailboxId,
   434     const NmId &mailboxId,
   491     const NmId &folderId,
   435     const NmId &folderId,
   492     const NmId &messageId,
   436     const NmId &messageId,
   493     NmMessagePart &messagePart)
   437     NmMessagePart &messagePart)
   494 {
   438 {
   495     NM_FUNCTION;
       
   496 
       
   497     return mDataManager->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   439     return mDataManager->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   498 }
   440 }
   499 
   441 
   500 
   442 
   501 /*!
   443 /*!
   510 int NmUiEngine::deleteMessages(const NmId &mailboxId,
   452 int NmUiEngine::deleteMessages(const NmId &mailboxId,
   511                                const NmId &folderId,
   453                                const NmId &folderId,
   512                                const QList<NmId> &messageIdList)
   454                                const QList<NmId> &messageIdList)
   513 {
   455 {
   514     NM_FUNCTION;
   456     NM_FUNCTION;
   515 
   457     
   516     int result(NmNotFoundError);
   458     int result(NmNotFoundError);
   517 
   459 
   518     bool isInbox(false);
   460     bool isInbox(false);
   519     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   461     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   520         isInbox=true;
   462         isInbox=true;
   539         mPluginFactory->interfaceInstance(mailboxId);
   481         mPluginFactory->interfaceInstance(mailboxId);
   540 
   482 
   541     if (plugin) {
   483     if (plugin) {
   542           result = plugin->deleteMessages(mailboxId, folderId, messageIdList);
   484           result = plugin->deleteMessages(mailboxId, folderId, messageIdList);
   543     }
   485     }
   544 
   486     
   545 	return result;
   487     // Because the asynchronous delete operation may take some time to
       
   488     // finish, we will not wait for the NmMessageDeleted events from the
       
   489     // protocol plugin. Instead, handleMessageEvent() is invoked directly.
       
   490     // This causes the viewer to exit even though the asychronous delete
       
   491     // operation would take a bit longer to finish.
       
   492     handleMessageEvent(NmMessageDeleted,folderId,messageIdList,mailboxId);
       
   493     
       
   494     return result;
   546 }
   495 }
   547 
   496 
   548 
   497 
   549 /*!
   498 /*!
   550     Sets the envelope property for the given envelopes.
   499     Sets the envelope property for the given envelopes.
   561         const NmId &mailboxId,
   510         const NmId &mailboxId,
   562         const NmId &folderId,
   511         const NmId &folderId,
   563         NmEnvelopeProperties property,
   512         NmEnvelopeProperties property,
   564         const QList<const NmMessageEnvelope*> &envelopeList)
   513         const QList<const NmMessageEnvelope*> &envelopeList)
   565 {
   514 {
   566     NM_FUNCTION;
       
   567 
       
   568     QPointer<NmStoreEnvelopesOperation> operation(NULL);
   515     QPointer<NmStoreEnvelopesOperation> operation(NULL);
   569     NmMessageListModel *theMessageListModel = mMessageListModel;
   516     NmMessageListModel *theMessageListModel = mMessageListModel;
   570 
   517 
   571     if (!theMessageListModel) {
   518     if (!theMessageListModel) {
   572         theMessageListModel = &messageListModel(mailboxId, folderId);
   519         theMessageListModel = &messageListModel(mailboxId, folderId);
   630     Creates a new message (into Drafts-folder).
   577     Creates a new message (into Drafts-folder).
   631     Operation is automatically deleted after completion or cancelling.
   578     Operation is automatically deleted after completion or cancelling.
   632 */
   579 */
   633 QPointer<NmMessageCreationOperation> NmUiEngine::createNewMessage(const NmId &mailboxId)
   580 QPointer<NmMessageCreationOperation> NmUiEngine::createNewMessage(const NmId &mailboxId)
   634 {
   581 {
   635     NM_FUNCTION;
       
   636 
       
   637     QPointer<NmMessageCreationOperation> value(NULL);
   582     QPointer<NmMessageCreationOperation> value(NULL);
   638     NmDataPluginInterface *plugin =
   583     NmDataPluginInterface *plugin =
   639         mPluginFactory->interfaceInstance(mailboxId);
   584         mPluginFactory->interfaceInstance(mailboxId);
   640     if (plugin) {
   585     if (plugin) {
   641         value = plugin->createNewMessage(mailboxId);
   586         value = plugin->createNewMessage(mailboxId);
   649 */
   594 */
   650 QPointer<NmMessageCreationOperation> NmUiEngine::createForwardMessage(
   595 QPointer<NmMessageCreationOperation> NmUiEngine::createForwardMessage(
   651         const NmId &mailboxId,
   596         const NmId &mailboxId,
   652         const NmId &originalMessageId)
   597         const NmId &originalMessageId)
   653 {
   598 {
   654     NM_FUNCTION;
       
   655 
       
   656     QPointer<NmMessageCreationOperation> value(NULL);
   599     QPointer<NmMessageCreationOperation> value(NULL);
   657     NmDataPluginInterface *plugin =
   600     NmDataPluginInterface *plugin =
   658         mPluginFactory->interfaceInstance(mailboxId);
   601         mPluginFactory->interfaceInstance(mailboxId);
   659     if (plugin) {
   602     if (plugin) {
   660         value = plugin->createForwardMessage(mailboxId, originalMessageId);
   603         value = plugin->createForwardMessage(mailboxId, originalMessageId);
   669 QPointer<NmMessageCreationOperation> NmUiEngine::createReplyMessage(
   612 QPointer<NmMessageCreationOperation> NmUiEngine::createReplyMessage(
   670         const NmId &mailboxId,
   613         const NmId &mailboxId,
   671         const NmId &originalMessageId,
   614         const NmId &originalMessageId,
   672         bool replyAll)
   615         bool replyAll)
   673 {
   616 {
       
   617     QPointer<NmMessageCreationOperation> value(NULL);
       
   618     NmDataPluginInterface *plugin =
       
   619         mPluginFactory->interfaceInstance(mailboxId);
       
   620     if (plugin) {
       
   621         value = plugin->createReplyMessage(mailboxId, originalMessageId, replyAll);
       
   622     }
       
   623     return value;
       
   624 }
       
   625 
       
   626 /*!
       
   627     Saves a message (into message store).
       
   628 */
       
   629 int NmUiEngine::saveMessage(const NmMessage &message)
       
   630 {
   674     NM_FUNCTION;
   631     NM_FUNCTION;
   675 
   632     
   676     QPointer<NmMessageCreationOperation> value(NULL);
       
   677     NmDataPluginInterface *plugin =
       
   678         mPluginFactory->interfaceInstance(mailboxId);
       
   679     if (plugin) {
       
   680         value = plugin->createReplyMessage(mailboxId, originalMessageId, replyAll);
       
   681     }
       
   682     return value;
       
   683 }
       
   684 
       
   685 /*!
       
   686     Saves a message (into message store).
       
   687 */
       
   688 int NmUiEngine::saveMessage(const NmMessage &message)
       
   689 {
       
   690     NM_FUNCTION;
       
   691 
       
   692     const NmId &mailboxId = message.envelope().mailboxId();
   633     const NmId &mailboxId = message.envelope().mailboxId();
   693     int ret(NmNotFoundError);
   634     int ret(NmNotFoundError);
   694     NmDataPluginInterface *plugin =
   635     NmDataPluginInterface *plugin =
   695         mPluginFactory->interfaceInstance(mailboxId);
   636         mPluginFactory->interfaceInstance(mailboxId);
   696     if (plugin) {
   637     if (plugin) {
   702 /*!
   643 /*!
   703     Refreshes mailbox.
   644     Refreshes mailbox.
   704 */
   645 */
   705 int NmUiEngine::refreshMailbox(const NmId &mailboxId )
   646 int NmUiEngine::refreshMailbox(const NmId &mailboxId )
   706 {
   647 {
   707     NM_FUNCTION;
       
   708 
       
   709     int ret(NmNotFoundError);
   648     int ret(NmNotFoundError);
   710     NmDataPluginInterface *plugin =
   649     NmDataPluginInterface *plugin =
   711         mPluginFactory->interfaceInstance(mailboxId);
   650         mPluginFactory->interfaceInstance(mailboxId);
   712     if (plugin) {
   651     if (plugin) {
   713         ret = plugin->refreshMailbox(mailboxId);
   652         ret = plugin->refreshMailbox(mailboxId);
   721 /*!
   660 /*!
   722     Online mailbox.
   661     Online mailbox.
   723 */
   662 */
   724 int NmUiEngine::goOnline(const NmId &mailboxId )
   663 int NmUiEngine::goOnline(const NmId &mailboxId )
   725 {
   664 {
   726     NM_FUNCTION;
       
   727 
       
   728     int ret(NmNotFoundError);
   665     int ret(NmNotFoundError);
   729     NmDataPluginInterface *plugin =
   666     NmDataPluginInterface *plugin =
   730         mPluginFactory->interfaceInstance(mailboxId);
   667         mPluginFactory->interfaceInstance(mailboxId);
   731     if (plugin) {
   668     if (plugin) {
   732         ret = plugin->goOnline(mailboxId);
   669         ret = plugin->goOnline(mailboxId);
   737 /*!
   674 /*!
   738     Offline mailbox.
   675     Offline mailbox.
   739 */
   676 */
   740 int NmUiEngine::goOffline(const NmId &mailboxId )
   677 int NmUiEngine::goOffline(const NmId &mailboxId )
   741 {
   678 {
   742     NM_FUNCTION;
       
   743 
       
   744     int ret(NmNotFoundError);
   679     int ret(NmNotFoundError);
   745     NmDataPluginInterface *plugin =
   680     NmDataPluginInterface *plugin =
   746         mPluginFactory->interfaceInstance(mailboxId);
   681         mPluginFactory->interfaceInstance(mailboxId);
   747     if (plugin) {
   682     if (plugin) {
   748         ret = plugin->goOffline(mailboxId);
   683         ret = plugin->goOffline(mailboxId);
   758     const NmId &mailboxId,
   693     const NmId &mailboxId,
   759     const NmId &folderId,
   694     const NmId &folderId,
   760     const NmId &messageId)
   695     const NmId &messageId)
   761 {
   696 {
   762     NM_FUNCTION;
   697     NM_FUNCTION;
   763 
   698     
   764     int result(NmNotFoundError);
   699     int result(NmNotFoundError);
   765     NmDataPluginInterface *plugin =
   700     NmDataPluginInterface *plugin =
   766             mPluginFactory->interfaceInstance(mailboxId);
   701             mPluginFactory->interfaceInstance(mailboxId);
   767     if (plugin) {
   702     if (plugin) {
   768           result = plugin->removeMessage(mailboxId, folderId, messageId);
   703           result = plugin->removeMessage(mailboxId, folderId, messageId);
   775   Handles draft message deletion after editor has closed, takes ownership of message.
   710   Handles draft message deletion after editor has closed, takes ownership of message.
   776  */
   711  */
   777 void NmUiEngine::removeDraftMessage(NmMessage *message)
   712 void NmUiEngine::removeDraftMessage(NmMessage *message)
   778 {
   713 {
   779     NM_FUNCTION;
   714     NM_FUNCTION;
   780 
   715     
   781     if (message) {
   716     if (message) {
   782         NmDataPluginInterface *plugin =
   717         NmDataPluginInterface *plugin =
   783             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   718             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   784 
   719 
   785         if (plugin) {
   720         if (plugin) {
   806  */
   741  */
   807 void NmUiEngine::saveDraftMessage(NmMessage *message,
   742 void NmUiEngine::saveDraftMessage(NmMessage *message,
   808                                   const QList<NmOperation*> &preliminaryOperations)
   743                                   const QList<NmOperation*> &preliminaryOperations)
   809 {
   744 {
   810     NM_FUNCTION;
   745     NM_FUNCTION;
   811 
   746     
   812     if (message) {
   747     if (message) {
   813         NmDataPluginInterface *plugin =
   748         NmDataPluginInterface *plugin =
   814             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   749             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   815 
   750 
   816         if (plugin) {
   751         if (plugin) {
   852     Sends the given message.
   787     Sends the given message.
   853  */
   788  */
   854 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations)
   789 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations)
   855 {
   790 {
   856     NM_FUNCTION;
   791     NM_FUNCTION;
   857 
   792     
   858     //First trigger message storing
   793     //First trigger message storing
   859     if (message) {
   794     if (message) {
   860         NmDataPluginInterface *plugin =
   795         NmDataPluginInterface *plugin =
   861             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   796             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   862 
   797 
   888 /*!
   823 /*!
   889     Is sending operation in progress.
   824     Is sending operation in progress.
   890  */
   825  */
   891 bool NmUiEngine::isSendingMessage() const
   826 bool NmUiEngine::isSendingMessage() const
   892 {
   827 {
   893     NM_FUNCTION;
       
   894 
       
   895     int ret(false);
   828     int ret(false);
   896     if (mSendOperation && mSendOperation->isRunning()) {
   829     if (mSendOperation && mSendOperation->isRunning()) {
   897         ret = true;
   830         ret = true;
   898     }
   831     }
   899     return ret;
   832     return ret;
   902 /*!
   835 /*!
   903    Returns a pointer to the message that is being sent. Returns NULL if not sending.
   836    Returns a pointer to the message that is being sent. Returns NULL if not sending.
   904  */
   837  */
   905 const NmMessage *NmUiEngine::messageBeingSent() const
   838 const NmMessage *NmUiEngine::messageBeingSent() const
   906 {
   839 {
   907     NM_FUNCTION;
       
   908 
       
   909     const NmMessage *message = NULL;
   840     const NmMessage *message = NULL;
   910 
   841 
   911     if (mSendOperation) {
   842     if (mSendOperation) {
   912         message = mSendOperation->getMessage();
   843         message = mSendOperation->getMessage();
   913     }
   844     }
   921  */
   852  */
   922 QPointer<NmAddAttachmentsOperation> NmUiEngine::addAttachments(
   853 QPointer<NmAddAttachmentsOperation> NmUiEngine::addAttachments(
   923     const NmMessage &message,
   854     const NmMessage &message,
   924     const QList<QString> &fileList)
   855     const QList<QString> &fileList)
   925 {
   856 {
   926     NM_FUNCTION;
       
   927 
       
   928     NmDataPluginInterface *plugin =
   857     NmDataPluginInterface *plugin =
   929         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   858         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   930 
   859 
   931     QPointer<NmAddAttachmentsOperation> ret(NULL);
   860     QPointer<NmAddAttachmentsOperation> ret(NULL);
   932     if (plugin) {
   861     if (plugin) {
   941  */
   870  */
   942 QPointer<NmOperation> NmUiEngine::removeAttachment(
   871 QPointer<NmOperation> NmUiEngine::removeAttachment(
   943     const NmMessage &message,
   872     const NmMessage &message,
   944     const NmId &attachmentPartId)
   873     const NmId &attachmentPartId)
   945 {
   874 {
   946     NM_FUNCTION;
       
   947 
       
   948     NmDataPluginInterface *plugin =
   875     NmDataPluginInterface *plugin =
   949         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   876         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   950 
   877 
   951     QPointer<NmOperation> ret(NULL);
   878     QPointer<NmOperation> ret(NULL);
   952     if (plugin) {
   879     if (plugin) {
   958 /*!
   885 /*!
   959     Returns the current sync state of the mailbox
   886     Returns the current sync state of the mailbox
   960  */
   887  */
   961 NmSyncState NmUiEngine::syncState(const NmId& mailboxId)
   888 NmSyncState NmUiEngine::syncState(const NmId& mailboxId)
   962 {
   889 {
   963     NM_FUNCTION;
       
   964 
       
   965     NmDataPluginInterface *plugin =
   890     NmDataPluginInterface *plugin =
   966                 mPluginFactory->interfaceInstance(mailboxId);
   891                 mPluginFactory->interfaceInstance(mailboxId);
   967     if (plugin) {
   892     if (plugin) {
   968         return plugin->syncState(mailboxId);
   893         return plugin->syncState(mailboxId);
   969     }
   894     }
   975 /*!
   900 /*!
   976     Returns the current connection state of the mailbox
   901     Returns the current connection state of the mailbox
   977  */
   902  */
   978 NmConnectState NmUiEngine::connectionState(const NmId& mailboxId)
   903 NmConnectState NmUiEngine::connectionState(const NmId& mailboxId)
   979 {
   904 {
   980     NM_FUNCTION;
       
   981 
       
   982     NmDataPluginInterface *plugin =
   905     NmDataPluginInterface *plugin =
   983                 mPluginFactory->interfaceInstance(mailboxId);
   906                 mPluginFactory->interfaceInstance(mailboxId);
   984     if (plugin) {
   907     if (plugin) {
   985         return plugin->connectionState(mailboxId);
   908         return plugin->connectionState(mailboxId);
   986     }
   909     }
  1000 */
   923 */
  1001 int NmUiEngine::search(const NmId &mailboxId,
   924 int NmUiEngine::search(const NmId &mailboxId,
  1002                        const QStringList &searchStrings)
   925                        const QStringList &searchStrings)
  1003 {
   926 {
  1004     NM_FUNCTION;
   927     NM_FUNCTION;
  1005 
   928     
  1006     // Get the plugin instance.
   929     // Get the plugin instance.
  1007     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
   930     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
  1008 
   931 
  1009     if (pluginInstance) {
   932     if (pluginInstance) {
  1010         // Make sure the required signals are connected.
   933         // Make sure the required signals are connected.
  1043 
   966 
  1044     \return A possible error code.
   967     \return A possible error code.
  1045 */
   968 */
  1046 int NmUiEngine::cancelSearch(const NmId &mailboxId)
   969 int NmUiEngine::cancelSearch(const NmId &mailboxId)
  1047 {
   970 {
  1048     NM_FUNCTION;
       
  1049 
       
  1050     int retVal(NmNoError);
   971     int retVal(NmNoError);
  1051 
   972 
  1052     // Get the plugin interface.
   973     // Get the plugin interface.
  1053     NmDataPluginInterface *pluginInterface =
   974     NmDataPluginInterface *pluginInterface =
  1054         mPluginFactory->interfaceInstance(mailboxId);
   975         mPluginFactory->interfaceInstance(mailboxId);
  1066     \param folderId id of the folder
   987     \param folderId id of the folder
  1067     \return Folder type
   988     \return Folder type
  1068 */
   989 */
  1069 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
   990 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
  1070 {
   991 {
  1071     NM_FUNCTION;
       
  1072 
       
  1073     NmFolderType ret(NmFolderInbox);
   992     NmFolderType ret(NmFolderInbox);
  1074     if (mDataManager){
   993     if (mDataManager){
  1075         ret = mDataManager->folderTypeById(mailboxId,folderId);
   994         ret = mDataManager->folderTypeById(mailboxId,folderId);
  1076     }
   995     }
  1077     return ret;
   996     return ret;
  1082     \param mailboxId Id of active mailbox, 0 if application is closed.
  1001     \param mailboxId Id of active mailbox, 0 if application is closed.
  1083     \param folderId Id of active folder, 0 if application is closed.
  1002     \param folderId Id of active folder, 0 if application is closed.
  1084 */
  1003 */
  1085 void NmUiEngine::updateActiveFolder(const NmId &mailboxId, const NmId &folderId)
  1004 void NmUiEngine::updateActiveFolder(const NmId &mailboxId, const NmId &folderId)
  1086 {
  1005 {
  1087     NM_FUNCTION;
       
  1088 
       
  1089     NmApplicationStateInterface *interface =
  1006     NmApplicationStateInterface *interface =
  1090         mPluginFactory->applicationStateInterfaceInstance(mailboxId);
  1007         mPluginFactory->applicationStateInterfaceInstance(mailboxId);
  1091     if (interface) {
  1008     if (interface) {
  1092         interface->updateActiveFolder(mailboxId, folderId);
  1009         interface->updateActiveFolder(mailboxId, folderId);
  1093     }
  1010     }
  1096 /*!
  1013 /*!
  1097     Handle completed send operation.
  1014     Handle completed send operation.
  1098 */
  1015 */
  1099 void NmUiEngine::handleCompletedSendOperation()
  1016 void NmUiEngine::handleCompletedSendOperation()
  1100 {
  1017 {
  1101     NM_FUNCTION;
       
  1102 
       
  1103     emit sendOperationCompleted();
  1018     emit sendOperationCompleted();
  1104 }
  1019 }
  1105 
  1020 
  1106 /*!
  1021 /*!
  1107     Handle completed remove draft operation.
  1022     Handle completed remove draft operation.
  1108 */
  1023 */
  1109 void NmUiEngine::handleCompletedRemoveDraftOperation()
  1024 void NmUiEngine::handleCompletedRemoveDraftOperation()
  1110 {
  1025 {
  1111     NM_FUNCTION;
       
  1112 
       
  1113     // draft message deletion observing not yet implemented...
  1026     // draft message deletion observing not yet implemented...
  1114 }
  1027 }
  1115 
  1028 
  1116 /*!
  1029 /*!
  1117     Handle completed save draft operation.
  1030     Handle completed save draft operation.
  1118 */
  1031 */
  1119 void NmUiEngine::handleCompletedSaveDraftOperation()
  1032 void NmUiEngine::handleCompletedSaveDraftOperation()
  1120 {
  1033 {
  1121     NM_FUNCTION;
       
  1122 
       
  1123     // delete message object since it's not needed anymore
  1034     // delete message object since it's not needed anymore
  1124     if(mDraftMessage) {
  1035     if(mDraftMessage) {
  1125         delete mDraftMessage;
  1036         delete mDraftMessage;
  1126         mDraftMessage = NULL;
  1037         mDraftMessage = NULL;
  1127     }
  1038     }
  1130 /*!
  1041 /*!
  1131     Handles synch operation related events
  1042     Handles synch operation related events
  1132  */
  1043  */
  1133 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event)
  1044 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event)
  1134 {
  1045 {
  1135     NM_FUNCTION;
       
  1136 
       
  1137     if ( syncState == SyncComplete ) {
  1046     if ( syncState == SyncComplete ) {
  1138         // signal for reporting about (sync) operation completion status
  1047         // signal for reporting about (sync) operation completion status
  1139         emit operationCompleted(event);
  1048         emit operationCompleted(event);
  1140 
  1049 
  1141         enableSyncIndicator(false);
  1050         enableSyncIndicator(false);
  1150 
  1059 
  1151     \param enabled true if indicator is enabled, false if disabled
  1060     \param enabled true if indicator is enabled, false if disabled
  1152 */
  1061 */
  1153 void NmUiEngine::enableSyncIndicator(bool enabled)
  1062 void NmUiEngine::enableSyncIndicator(bool enabled)
  1154 {
  1063 {
  1155 	NM_FUNCTION;
       
  1156 
       
  1157     HbIndicator indicator;
  1064     HbIndicator indicator;
  1158     if (enabled) {
  1065     if (enabled) {
  1159         indicator.activate(syncIndicatorName, QVariant());
  1066         indicator.activate(syncIndicatorName, QVariant());
  1160 	}
  1067 	}
  1161     else {
  1068     else {
  1169     \param mailboxId The mailbox id whose signature is asked.
  1076     \param mailboxId The mailbox id whose signature is asked.
  1170 	\param signature The reference to the signature string pointer. NULL if no signature.
  1077 	\param signature The reference to the signature string pointer. NULL if no signature.
  1171 */
  1078 */
  1172 int NmUiEngine::getSignature(const NmId &mailboxId, QString *&signature)
  1079 int NmUiEngine::getSignature(const NmId &mailboxId, QString *&signature)
  1173 {
  1080 {
  1174     NM_FUNCTION;
       
  1175     
       
  1176     int retVal(NmNoError);
  1081     int retVal(NmNoError);
  1177     
  1082     
  1178     // Get the plugin interface.
  1083     // Get the plugin interface.
  1179     NmDataPluginInterface *pluginInterface =
  1084     NmDataPluginInterface *pluginInterface =
  1180         mPluginFactory->interfaceInstance(mailboxId);
  1085         mPluginFactory->interfaceInstance(mailboxId);
  1193 void NmUiEngine::handleMessageEvent(NmMessageEvent event,
  1098 void NmUiEngine::handleMessageEvent(NmMessageEvent event,
  1194                                     const NmId &folderId,
  1099                                     const NmId &folderId,
  1195                                     const QList<NmId> &messageIds,
  1100                                     const QList<NmId> &messageIds,
  1196                                     const NmId& mailboxId)
  1101                                     const NmId& mailboxId)
  1197 {
  1102 {
  1198     NM_FUNCTION;
       
  1199 
       
  1200     switch (event) {
  1103     switch (event) {
  1201         case NmMessageDeleted:
  1104         case NmMessageDeleted:
  1202         {
  1105         {
  1203             for (int i(0); i < messageIds.count(); i++) {
  1106             for (int i(0); i < messageIds.count(); i++) {
  1204                 emit messageDeleted(mailboxId, folderId, messageIds[i]);
  1107                 emit messageDeleted(mailboxId, folderId, messageIds[i]);
  1215     Currently only NmMailboxDeleted is handled.
  1118     Currently only NmMailboxDeleted is handled.
  1216 */
  1119 */
  1217 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event,
  1120 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event,
  1218                                     const QList<NmId> &mailboxIds)
  1121                                     const QList<NmId> &mailboxIds)
  1219 {
  1122 {
  1220     NM_FUNCTION;
       
  1221 
       
  1222     switch (event) {
  1123     switch (event) {
  1223         case NmMailboxDeleted:
  1124         case NmMailboxDeleted:
  1224         {
  1125         {
  1225             for (int i(0); i < mailboxIds.count(); i++) {
  1126             for (int i(0); i < mailboxIds.count(); i++) {
  1226                 emit mailboxDeleted(mailboxIds[i]);
  1127                 emit mailboxDeleted(mailboxIds[i]);
  1239     \param mailboxId Id of active mailbox, 0 if application is closed.
  1140     \param mailboxId Id of active mailbox, 0 if application is closed.
  1240 */
  1141 */
  1241 void NmUiEngine::handleFolderEvent(NmFolderEvent event, 
  1142 void NmUiEngine::handleFolderEvent(NmFolderEvent event, 
  1242         const QList<NmId> &folderIds, const NmId &mailboxId)
  1143         const QList<NmId> &folderIds, const NmId &mailboxId)
  1243 {
  1144 {
  1244     NM_FUNCTION;
       
  1245 
       
  1246     switch (event) {
  1145     switch (event) {
  1247         case NmFolderIsDeleted:
  1146         case NmFolderIsDeleted:
  1248             handleFolderDeletedEvent(folderIds, mailboxId);
  1147             handleFolderDeletedEvent(folderIds, mailboxId);
  1249             break;
  1148             break;
  1250         case NmFolderIsCreated:
  1149         case NmFolderIsCreated:
  1258     Handles folder deletion from plugins.
  1157     Handles folder deletion from plugins.
  1259 */
  1158 */
  1260 void NmUiEngine::handleFolderDeletedEvent(const QList<NmId> &folderIds,
  1159 void NmUiEngine::handleFolderDeletedEvent(const QList<NmId> &folderIds,
  1261                                           const NmId &mailboxId)
  1160                                           const NmId &mailboxId)
  1262 {
  1161 {
  1263     NM_FUNCTION;
       
  1264 
       
  1265     NmId folderId(0); 
  1162     NmId folderId(0); 
  1266 
  1163 
  1267     for (int i(0); i < folderIds.count(); i++) {
  1164     for (int i(0); i < folderIds.count(); i++) {
  1268         folderId = folderIds[i];
  1165         folderId = folderIds[i];
  1269         if (mInboxListModel){
  1166         if (mInboxListModel){
  1279     Emits signals based on folder creation from plugins.
  1176     Emits signals based on folder creation from plugins.
  1280 */
  1177 */
  1281 void NmUiEngine::handleFolderCreatedEvent(const QList<NmId> &folderIds,
  1178 void NmUiEngine::handleFolderCreatedEvent(const QList<NmId> &folderIds,
  1282                                           const NmId &mailboxId)
  1179                                           const NmId &mailboxId)
  1283 {
  1180 {
  1284     NM_FUNCTION;
       
  1285     Q_UNUSED(folderIds);
  1181     Q_UNUSED(folderIds);
  1286     Q_UNUSED(mailboxId);
  1182     Q_UNUSED(mailboxId);
  1287 }
  1183 }
  1288 
  1184 
  1289 
  1185 
  1293     \param messageId The ID of the found message.
  1189     \param messageId The ID of the found message.
  1294     \param folderId The ID of the folder where the message is located.
  1190     \param folderId The ID of the folder where the message is located.
  1295 */
  1191 */
  1296 void NmUiEngine::handleMatchFound(const NmId &messageId, const NmId &folderId)
  1192 void NmUiEngine::handleMatchFound(const NmId &messageId, const NmId &folderId)
  1297 {
  1193 {
  1298     NM_FUNCTION;
       
  1299 
       
  1300     if (!mMessageSearchListModel) {
  1194     if (!mMessageSearchListModel) {
  1301         // No search list model!
  1195         // No search list model!
  1302         return;
  1196         return;
  1303     }
  1197     }
  1304 
  1198 
  1325 void NmUiEngine::messageEventForListModel(NmMessageEvent event,
  1219 void NmUiEngine::messageEventForListModel(NmMessageEvent event,
  1326                         const NmId &folderId,
  1220                         const NmId &folderId,
  1327                         const QList<NmId> &messageIds,
  1221                         const QList<NmId> &messageIds,
  1328                         const NmId& mailboxId)
  1222                         const NmId& mailboxId)
  1329 {
  1223 {
  1330     NM_FUNCTION;
       
  1331 
       
  1332     // Forward event to both list models. Models will take care of checking
  1224     // Forward event to both list models. Models will take care of checking
  1333     // whether event really belongs to current mailbox & folder
  1225     // whether event really belongs to current mailbox & folder
  1334     if (mInboxListModel){
  1226     if (mInboxListModel){
  1335         mInboxListModel->handleMessageEvent(event, folderId,
  1227         mInboxListModel->handleMessageEvent(event, folderId,
  1336                                             messageIds, mailboxId);
  1228                                             messageIds, mailboxId);
  1344 /*!
  1236 /*!
  1345     receives events when going online, and offline.
  1237     receives events when going online, and offline.
  1346 */
  1238 */
  1347 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
  1239 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
  1348 {
  1240 {
  1349     NM_FUNCTION;
       
  1350 
       
  1351     // signal for connection state icon handling
  1241     // signal for connection state icon handling
  1352     emit connectionEvent(connectState, mailboxId);
  1242     emit connectionEvent(connectState, mailboxId);
  1353 
  1243 
  1354     // in case going offline w/ error, emit signal to UI
  1244     // in case going offline w/ error, emit signal to UI
  1355     if ( connectState == Disconnected && errorCode!= NmNoError ) {
  1245     if ( connectState == Disconnected && errorCode!= NmNoError ) {
  1356         NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0};
  1246         NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0};
  1357         emit operationCompleted(event);
  1247         emit operationCompleted(event);
  1358     }
  1248     }
  1359 }
  1249 }
       
  1250 
       
  1251 /*!
       
  1252      Create message list mode
       
  1253  */
       
  1254 void NmUiEngine::createMessageListModel(
       
  1255         NmMessageListModel **model,        
       
  1256         const NmId &mailboxId,
       
  1257         const NmId &folderId)
       
  1258 {
       
  1259     // Delete previous model and set to NULL. Deleting model will also
       
  1260     // delete all items in model.
       
  1261     if (*model){
       
  1262         delete *model;
       
  1263         *model=NULL;
       
  1264     }
       
  1265     // Create new list model
       
  1266     *model = new NmMessageListModel(*mDataManager);
       
  1267     // Initial fill up of the list model, otherwise updated in the background
       
  1268     QList<NmMessageEnvelope*> messageEnvelopeList;
       
  1269     mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
       
  1270     (*model)->refresh(mailboxId, folderId, messageEnvelopeList);
       
  1271 
       
  1272     while (!messageEnvelopeList.isEmpty()) {
       
  1273         delete messageEnvelopeList.takeFirst();
       
  1274     }    
       
  1275 }