emailuis/nmailuiengine/src/nmuiengine.cpp
changeset 40 2c62ef3caffd
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
39:b0b89ca206b5 40:2c62ef3caffd
   180     while (!mailboxList.isEmpty()) {
   180     while (!mailboxList.isEmpty()) {
   181         delete mailboxList.takeFirst();
   181         delete mailboxList.takeFirst();
   182     }
   182     }
   183 }
   183 }
   184 
   184 
   185 /*!
   185 
   186     Returns a message list model for a folder identified by \a mailboxId and \a folderId.
   186 /*!
   187     The model is updated dynamically. The ownership of the model object is not moved to the caller.
   187     Returns a message list model for a folder identified by \a mailboxId and 
   188 */
   188     \a folderId. The model is updated dynamically. The ownership of the model
   189 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId, const NmId &folderId)
   189     object is not moved to the caller.
   190 {
   190 */
   191     if (!mMessageListModel){
   191 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId,
       
   192                                                  const NmId &folderId)
       
   193 {
       
   194     if (!mMessageListModel) {
   192         mMessageListModel = new NmMessageListModel(*mDataManager);
   195         mMessageListModel = new NmMessageListModel(*mDataManager);
   193     }
   196     }
   194     else{
   197     else {
   195         mMessageListModel->clear();
   198         mMessageListModel->clear();
   196     }
   199     }
   197     QObject *plugin =
   200 
   198         mPluginFactory->pluginInstance(mailboxId);
   201     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
       
   202 
   199     if (plugin) {
   203     if (plugin) {
   200         QObject::connect(plugin,
   204         QObject::connect(plugin,
   201             SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
   205             SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
   202         mMessageListModel,
   206             mMessageListModel,
   203             SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &)),
   207             SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &)),
   204             Qt::UniqueConnection );
   208             Qt::UniqueConnection );
   205 
   209 
   206         QObject::connect(
   210         QObject::connect(
   207             plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   211             plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   208             this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   212             this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   209             Qt::UniqueConnection);        
   213             Qt::UniqueConnection);
   210         // no need for mailbox event subscription here, already done in constructor
   214 
   211     }
   215         // No need for mailbox event subscription here, already done in
       
   216         // constructor.
       
   217     }
       
   218 
   212     QList<NmMessageEnvelope*> messageEnvelopeList;
   219     QList<NmMessageEnvelope*> messageEnvelopeList;
   213     mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   220     mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   214     mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
   221     mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
       
   222 
   215     while (!messageEnvelopeList.isEmpty()) {
   223     while (!messageEnvelopeList.isEmpty()) {
   216         delete messageEnvelopeList.takeFirst();
   224         delete messageEnvelopeList.takeFirst();
   217     }
   225     }
       
   226 
   218     return *mMessageListModel;
   227     return *mMessageListModel;
   219 }
   228 }
   220 
   229 
   221 
   230 
   222 /*!
   231 /*!
   223     Returns a reference of the message search list model. If the model does not
   232     Returns a message list model used in the search view.
   224     exist yet, one is constructed.
   233 
   225 
   234     \param mailboxId The ID of the mailbox to search messages from.
   226     \param sourceModel The source model for the search list model.
   235 
   227 
   236     \return A message list model.
   228     \return The message search list model.
   237 */
   229 */
   238 NmMessageListModel &NmUiEngine::messageListModelForSearch(const NmId &mailboxId)
   230 NmMessageSearchListModel &NmUiEngine::messageSearchListModel(
   239 {
   231     QAbstractItemModel *sourceModel)
   240     Q_UNUSED(mailboxId);
   232 {
   241 
   233     if (!mMessageSearchListModel) {
   242     if (!mMessageSearchListModel) {
   234         mMessageSearchListModel = new NmMessageSearchListModel();
   243         mMessageSearchListModel = new NmMessageListModel(*mDataManager);
   235     }
   244         mMessageSearchListModel->setIgnoreFolderIds(true);
   236 
   245     }
   237     mMessageSearchListModel->setSourceModel(sourceModel);
   246     else {
       
   247         mMessageSearchListModel->clear();
       
   248     }
       
   249 
       
   250     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
       
   251 
       
   252     if (plugin) {
       
   253         QObject::connect(plugin,
       
   254             SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
       
   255             mMessageSearchListModel,
       
   256             SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &)),
       
   257             Qt::UniqueConnection);
       
   258     }
       
   259 
       
   260     // Refresh to set the mailbox ID.
       
   261     QList<NmMessageEnvelope*> messageEnvelopeList;
       
   262     mMessageSearchListModel->refresh(mailboxId, 0, messageEnvelopeList);
       
   263 
   238     return *mMessageSearchListModel;
   264     return *mMessageSearchListModel;
   239 }
   265 }
   240 
   266 
   241 
   267 
   242 /*!
   268 /*!
   301     QPointer<NmOperation> value(NULL);
   327     QPointer<NmOperation> value(NULL);
   302     NmDataPluginInterface *plugin =
   328     NmDataPluginInterface *plugin =
   303         mPluginFactory->interfaceInstance(mailboxId);
   329         mPluginFactory->interfaceInstance(mailboxId);
   304     if (plugin) {
   330     if (plugin) {
   305         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
   331         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
       
   332     }
       
   333     return value;
       
   334 }
       
   335 
       
   336 /*!
       
   337 
       
   338 */
       
   339 QPointer<NmOperation> NmUiEngine::fetchMessageParts(
       
   340     const NmId &mailboxId,
       
   341     const NmId &folderId,
       
   342     const NmId &messageId,
       
   343     const QList<NmId> &messagePartIds)
       
   344 {
       
   345     NMLOG("NmUiEngine::fetchMessageParts() <---");
       
   346     QPointer<NmOperation> value(NULL);
       
   347     NmDataPluginInterface *plugin =
       
   348         mPluginFactory->interfaceInstance(mailboxId);
       
   349     if (plugin) {
       
   350         value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds);
   306     }
   351     }
   307     return value;
   352     return value;
   308 }
   353 }
   309 
   354 
   310 /*!
   355 /*!
   705     // Get the plugin instance.
   750     // Get the plugin instance.
   706     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
   751     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
   707 
   752 
   708     if (pluginInstance) {
   753     if (pluginInstance) {
   709         // Make sure the required signals are connected.
   754         // Make sure the required signals are connected.
   710         connect(pluginInstance, SIGNAL(matchFound(const NmId &)),
   755         connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)),
   711                 this, SIGNAL(matchFound(const NmId &)), Qt::UniqueConnection);    
   756                 this, SIGNAL(matchFound(const NmId &, const NmId &)),
   712         connect(pluginInstance, SIGNAL(matchFound(const NmId &)),
   757                 Qt::UniqueConnection);
   713                 mMessageSearchListModel, SLOT(addSearchResult(const NmId &)),
   758 
       
   759         connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)),
       
   760                 this, SLOT(handleMatchFound(const NmId &, const NmId &)),
       
   761                 Qt::UniqueConnection); 
       
   762 
       
   763         connect(pluginInstance, SIGNAL(searchComplete()),
       
   764                 this, SIGNAL(searchComplete()),
   714                 Qt::UniqueConnection);    
   765                 Qt::UniqueConnection);    
   715         connect(pluginInstance, SIGNAL(searchComplete()),
       
   716                 this, SIGNAL(searchComplete()), Qt::UniqueConnection);    
       
   717     }
   766     }
   718 
   767 
   719     int retVal(NmNoError);
   768     int retVal(NmNoError);
   720 
   769 
   721     // Get the plugin interface.
   770     // Get the plugin interface.
   752     }  
   801     }  
   753     return retVal;    
   802     return retVal;    
   754 }
   803 }
   755 
   804 
   756 /*!
   805 /*!
   757     Cancels the search operation if one is ongoing.
       
   758 
       
   759     \param mailboxId The ID of the mailbox containing the folder
       
   760 
       
   761     \param folderId The ID of the folder 
       
   762 
       
   763     \return Folder type
   806     \return Folder type
   764 */
   807 */
   765 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
   808 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
   766 {
   809 {   
   767     NmFolderType folderType(NmFolderOther);
   810     NmFolderType ret(NmFolderInbox);
   768     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   811     if (mDataManager){
   769         folderType=NmFolderInbox;
   812         ret = mDataManager->folderTypeById(mailboxId,folderId);    
   770     }
   813     }
   771     else if (standardFolderId(mailboxId,NmFolderOutbox)==folderId){
   814     return ret;
   772         folderType=NmFolderOutbox; 
   815 }
   773     }
   816 
   774     else if (standardFolderId(mailboxId,NmFolderDrafts)==folderId){
   817 /*!
   775         folderType=NmFolderDrafts;
   818     Indicates application state information to protocol plugin
   776     }
   819     \param mailboxId Id of active mailbox, 0 if application is closed.
   777     else if (standardFolderId(mailboxId,NmFolderSent)==folderId){
   820     \param folderId Id of active folder, 0 if application is closed.
   778         folderType=NmFolderSent; 
   821 */
   779     }    
   822 void NmUiEngine::updateActiveFolder(const NmId &mailboxId, const NmId &folderId)
   780     else if (standardFolderId(mailboxId,NmFolderDeleted)==folderId){
   823 {
   781         folderType=NmFolderDeleted;  
   824     NmApplicationStateInterface *interface = 
   782     }    
   825         mPluginFactory->applicationStateInterfaceInstance(mailboxId);
   783     return folderType;
   826     if (interface) {
   784 }
   827         interface->updateActiveFolder(mailboxId, folderId);
       
   828     }
       
   829 }
       
   830 
   785 /*!
   831 /*!
   786     Handle completed send operation.
   832     Handle completed send operation.
   787 */
   833 */
   788 void NmUiEngine::handleCompletedSendOperation()
   834 void NmUiEngine::handleCompletedSendOperation()
   789 {
   835 {
   847         default:
   893         default:
   848         break;
   894         break;
   849     }
   895     }
   850 }
   896 }
   851 
   897 
       
   898 
       
   899 /*!
       
   900     Adds the found message into the search model.
       
   901 
       
   902     \param messageId The ID of the found message.
       
   903     \param folderId The ID of the folder where the message is located.
       
   904 */
       
   905 void NmUiEngine::handleMatchFound(const NmId &messageId, const NmId &folderId)
       
   906 {
       
   907     if (!mMessageSearchListModel) {
       
   908         // No search list model!
       
   909         return;
       
   910     }
       
   911 
       
   912     // Add the found message into the search model.
       
   913     QList<NmId> messageIdList;
       
   914     messageIdList.append(messageId);
       
   915 
       
   916     mMessageSearchListModel->handleMessageEvent(NmMessageFound,
       
   917                                                 folderId,
       
   918                                                 messageIdList);
       
   919 }
       
   920 
       
   921 
   852 /*!
   922 /*!
   853     receives events when going online, and offline.
   923     receives events when going online, and offline.
   854 */
   924 */
   855 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
   925 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
   856 {
   926 {