emailuis/nmailuiengine/src/nmuiengine.cpp
changeset 51 d845db10c0d4
parent 47 f83bd4ae1fe3
child 62 a8c646b56683
equal deleted inserted replaced
49:00c7ae862740 51:d845db10c0d4
    30 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0";
    30 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0";
    31 
    31 
    32 /*!
    32 /*!
    33     Constructor
    33     Constructor
    34 */
    34 */
    35 NmUiEngine::NmUiEngine() 
    35 NmUiEngine::NmUiEngine()
    36 : mMailboxListModel(NULL),
    36 : mMailboxListModel(NULL),
    37   mInboxListModel(NULL),
    37   mInboxListModel(NULL),
    38   mMessageListModel(NULL),
    38   mMessageListModel(NULL),
    39   mMessageSearchListModel(NULL),
    39   mMessageSearchListModel(NULL),
    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;
    45     NM_FUNCTION;
    46     
    46 
    47     mPluginFactory = NmDataPluginFactory::instance();
    47     mPluginFactory = NmDataPluginFactory::instance();
    48     mDataManager = new NmDataManager();
    48     mDataManager = new NmDataManager();
    49     // Connect to the plugins to receive change notifications
    49     // Connect to the plugins to receive change notifications
    50     QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
    50     QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
    51     for (int i(0); i < dataPlugins->count(); i++) {
    51     for (int i(0); i < dataPlugins->count(); i++) {
    54             // connet mailbox events
    54             // connet mailbox events
    55             QObject::connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)),
    55             QObject::connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)),
    56                  this, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)),
    56                  this, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)),
    57                  Qt::UniqueConnection);
    57                  Qt::UniqueConnection);
    58             // connect message events
    58             // connect message events
    59             QObject::connect(plugin, 
    59             QObject::connect(plugin,
    60                 SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
    60                 SIGNAL(messageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId&)),
    61                 this, SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)),
    61                 this, SLOT(handleMessageEvent(NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)),
    62                 Qt::UniqueConnection);
    62                 Qt::UniqueConnection);
    63             // connect connection events
    63             // connect connection events
    64             QObject::connect(plugin,
    64             QObject::connect(plugin,
    65                 SIGNAL(connectionEvent(NmConnectState, const NmId &, const int)),
    65                 SIGNAL(connectionEvent(NmConnectState, const NmId &, const int)),
    66                 this,
    66                 this,
    67                 SLOT(handleConnectEvent(NmConnectState, const NmId &, const int)),
    67                 SLOT(handleConnectEvent(NmConnectState, const NmId &, const int)),
    68                 Qt::UniqueConnection);       
    68                 Qt::UniqueConnection);
    69             // do the subscriptions also
    69             // do the subscriptions also
    70             NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(plugin);
    70             NmDataPluginInterface *pluginInterface = mPluginFactory->interfaceInstance(plugin);
    71             if (pluginInterface) {
    71             if (pluginInterface) {
    72                 QList<NmId> mailboxIdList;
    72                 QList<NmId> mailboxIdList;
    73                 pluginInterface->listMailboxIds(mailboxIdList);
    73                 pluginInterface->listMailboxIds(mailboxIdList);
    85     Class destructor.
    85     Class destructor.
    86 */
    86 */
    87 NmUiEngine::~NmUiEngine()
    87 NmUiEngine::~NmUiEngine()
    88 {
    88 {
    89     NM_FUNCTION;
    89     NM_FUNCTION;
    90     
    90 
    91     HbIndicator indicator;
    91     enableSyncIndicator(false);
    92     indicator.deactivate(syncIndicatorName, QVariant());
    92 
    93     
       
    94     if (mMessageSearchListModel) {
    93     if (mMessageSearchListModel) {
    95         delete mMessageSearchListModel;
    94         delete mMessageSearchListModel;
    96         mMessageSearchListModel = NULL;
    95         mMessageSearchListModel = NULL;
    97     }
    96     }
    98 
    97 
   135     if (mSendOperation && mSendOperation->isRunning()) {
   134     if (mSendOperation && mSendOperation->isRunning()) {
   136         mSendOperation->cancelOperation();
   135         mSendOperation->cancelOperation();
   137     }
   136     }
   138 
   137 
   139     if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) {
   138     if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) {
   140         mRemoveDraftOperation->cancelOperation();        
   139         mRemoveDraftOperation->cancelOperation();
   141     }
   140     }
   142 
   141 
   143     if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) {
   142     if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) {
   144         mSaveDraftOperation->cancelOperation();
   143         mSaveDraftOperation->cancelOperation();
   145     }
   144     }
   159 
   158 
   160 */
   159 */
   161 NmUiEngine *NmUiEngine::instance()
   160 NmUiEngine *NmUiEngine::instance()
   162 {
   161 {
   163     NM_FUNCTION;
   162     NM_FUNCTION;
   164     
   163 
   165     if (!mInstance) {
   164     if (!mInstance) {
   166     	mInstance = new NmUiEngine();
   165     	mInstance = new NmUiEngine();
   167     }
   166     }
   168     mReferenceCount++;
   167     mReferenceCount++;
   169     return mInstance;
   168     return mInstance;
   173 
   172 
   174 */
   173 */
   175 void NmUiEngine::releaseInstance(NmUiEngine *&instance)
   174 void NmUiEngine::releaseInstance(NmUiEngine *&instance)
   176 {
   175 {
   177     NM_FUNCTION;
   176     NM_FUNCTION;
   178     
   177 
   179     //can't have passed out instances if we don't have any
   178     //can't have passed out instances if we don't have any
   180     if (mInstance) {
   179     if (mInstance) {
   181         if(instance == mInstance) {
   180         if(instance == mInstance) {
   182             instance = NULL;
   181             instance = NULL;
   183             mReferenceCount--;
   182             mReferenceCount--;
   194     updated dynamically. The ownership of the model object is not moved to the caller.
   193     updated dynamically. The ownership of the model object is not moved to the caller.
   195 */
   194 */
   196 NmMailboxListModel &NmUiEngine::mailboxListModel()
   195 NmMailboxListModel &NmUiEngine::mailboxListModel()
   197 {
   196 {
   198     NM_FUNCTION;
   197     NM_FUNCTION;
   199     
   198 
   200     if (!mMailboxListModel) {
   199     if (!mMailboxListModel) {
   201         refreshMailboxListModel(); // creates the model too
   200         refreshMailboxListModel(); // creates the model too
   202     }
   201     }
   203     
   202 
   204     return *mMailboxListModel;
   203     return *mMailboxListModel;
   205 }
   204 }
   206         
   205 
   207 /*!
   206 /*!
   208     Populate the list model with the mailbox and top level folder objects. The model is
   207     Populate the list model with the mailbox and top level folder objects. The model is
   209     updated dynamically. Creates the model if needed.
   208     updated dynamically. Creates the model if needed.
   210 */
   209 */
   211 void NmUiEngine::refreshMailboxListModel()
   210 void NmUiEngine::refreshMailboxListModel()
   212 {
   211 {
   213     NM_FUNCTION;
   212     NM_FUNCTION;
   214     
   213 
   215     if (!mMailboxListModel) {
   214     if (!mMailboxListModel) {
   216         mMailboxListModel = new NmMailboxListModel(*mDataManager);
   215         mMailboxListModel = new NmMailboxListModel(*mDataManager);
   217         
   216 
   218         // Connect the model to the plugins to receive change notifications
   217         // Connect the model to the plugins to receive change notifications
   219         QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
   218         QList<QObject*> *dataPlugins = mPluginFactory->pluginInstances();
   220         for (int i = 0; i < dataPlugins->count(); i++) {
   219         for (int i = 0; i < dataPlugins->count(); i++) {
   221             QObject *plugin = (*dataPlugins)[i];
   220             QObject *plugin = (*dataPlugins)[i];
   222             if (plugin) {
   221             if (plugin) {
   225             }
   224             }
   226         }
   225         }
   227     } else {
   226     } else {
   228         mMailboxListModel->clear();
   227         mMailboxListModel->clear();
   229     }
   228     }
   230     
   229 
   231     QList<NmMailbox*> mailboxList;
   230     QList<NmMailbox*> mailboxList;
   232     mDataManager->listMailboxes(mailboxList);
   231     mDataManager->listMailboxes(mailboxList);
   233     mMailboxListModel->refresh(mailboxList);
   232     mMailboxListModel->refresh(mailboxList);
   234     while (!mailboxList.isEmpty()) {
   233     while (!mailboxList.isEmpty()) {
   235         delete mailboxList.takeFirst();
   234         delete mailboxList.takeFirst();
   236     }
   235     }
   237 }
   236 }
   238 
   237 
   239 
   238 
   240 /*!
   239 /*!
   241     Returns a message list model for a folder identified by \a mailboxId and 
   240     Returns a message list model for a folder identified by \a mailboxId and
   242     \a folderId. The model is updated dynamically. The ownership of the model
   241     \a folderId. The model is updated dynamically. The ownership of the model
   243     object is not moved to the caller.
   242     object is not moved to the caller.
   244 */
   243 */
   245 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId,
   244 NmMessageListModel &NmUiEngine::messageListModel(const NmId &mailboxId,
   246                                                  const NmId &folderId)
   245                                                  const NmId &folderId)
   250     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
   249     QObject *plugin = mPluginFactory->pluginInstance(mailboxId);
   251     bool isInbox(false);
   250     bool isInbox(false);
   252     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   251     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   253         isInbox=true;
   252         isInbox=true;
   254     }
   253     }
   255     if (plugin) { 
   254     if (plugin) {
   256         // Connect plugin message events to handler slot messageEventForListModel
   255         // Connect plugin message events to handler slot messageEventForListModel
   257         QObject::connect(plugin, SIGNAL(messageEvent(NmMessageEvent, const NmId &, 
   256         QObject::connect(plugin, SIGNAL(messageEvent(NmMessageEvent, const NmId &,
   258                                 const QList<NmId> &, const NmId&)),
   257                                 const QList<NmId> &, const NmId&)),
   259                                 this, SLOT(messageEventForListModel(NmMessageEvent, 
   258                                 this, SLOT(messageEventForListModel(NmMessageEvent,
   260                                 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection );
   259                                 const NmId &, const QList<NmId> &, const NmId&)), Qt::UniqueConnection );
   261         // Create inbox list model only once when entering to inbox for the first time
   260         // Create inbox list model only once when entering to inbox for the first time
   262         // or re-create inbox list model when mailbox has changed    
   261         // or re-create inbox list model when mailbox has changed
   263         if ((!mInboxListModel&&isInbox)||
   262         if ((!mInboxListModel&&isInbox)||
   264             (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){
   263             (mInboxListModel&&isInbox&&mailboxId!=mInboxListModel->currentMailboxId())){
   265             // Delete previous model and set to NULL. Deleting model will also
   264             // Delete previous model and set to NULL. Deleting model will also
   266             // delete all items in model. 
   265             // delete all items in model.
   267             if (mInboxListModel){
   266             if (mInboxListModel){
   268                 delete mInboxListModel;
   267                 delete mInboxListModel;
   269                 mInboxListModel=NULL;
   268                 mInboxListModel=NULL;
   270             }
   269             }
   271             // Create new inbox model 
   270             // Create new inbox model
   272             mInboxListModel = new NmMessageListModel(*mDataManager);
   271             mInboxListModel = new NmMessageListModel(*mDataManager);
   273             // Initial fill up of inbox list model, otherwise updated in the background
   272             // Initial fill up of inbox list model, otherwise updated in the background
   274             QList<NmMessageEnvelope*> messageEnvelopeList;
   273             QList<NmMessageEnvelope*> messageEnvelopeList;
   275             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   274             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   276             mInboxListModel->refresh(mailboxId, folderId, messageEnvelopeList);
   275             mInboxListModel->refresh(mailboxId, folderId, messageEnvelopeList);
   286             if (mMessageListModel){
   285             if (mMessageListModel){
   287                 delete mMessageListModel;
   286                 delete mMessageListModel;
   288                 mMessageListModel=NULL;
   287                 mMessageListModel=NULL;
   289             }
   288             }
   290             mMessageListModel = new NmMessageListModel(*mDataManager);
   289             mMessageListModel = new NmMessageListModel(*mDataManager);
   291     
   290 
   292             // Fill up other model 
   291             // Fill up other model
   293             QList<NmMessageEnvelope*> messageEnvelopeList;
   292             QList<NmMessageEnvelope*> messageEnvelopeList;
   294             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   293             mDataManager->listMessages(mailboxId, folderId, messageEnvelopeList);
   295             mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
   294             mMessageListModel->refresh(mailboxId, folderId, messageEnvelopeList);
   296 
   295 
   297             while (!messageEnvelopeList.isEmpty()) {
   296             while (!messageEnvelopeList.isEmpty()) {
   298                 delete messageEnvelopeList.takeFirst(); 
   297                 delete messageEnvelopeList.takeFirst();
   299             }             
   298             }
   300         }    
   299         }
   301     }
   300     }
   302      
   301 
   303     // Connect sync state changed
   302     // Connect sync state changed
   304     if (plugin){
   303     if (plugin){
   305         QObject::connect(
   304         QObject::connect(
   306             plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   305             plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   307             this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   306             this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
   308             Qt::UniqueConnection);
   307             Qt::UniqueConnection);
   309     }
   308     }
   310     NmMessageListModel* ret(NULL);
   309     NmMessageListModel* ret(NULL);
   311     if (isInbox){
   310     if (isInbox){
   312         ret = mInboxListModel;    
   311         ret = mInboxListModel;
   313         // Inbox list model is queried, other model is not
   312         // Inbox list model is queried, other model is not
   314         // needed anymore and memory should be freeded
   313         // needed anymore and memory should be freeded
   315         if (mMessageListModel){
   314         if (mMessageListModel){
   316             delete mMessageListModel;
   315             delete mMessageListModel;
   317             mMessageListModel=NULL;
   316             mMessageListModel=NULL;
   318         }
   317         }
   319     }
   318     }
   320     else {
   319     else {
   321         ret = mMessageListModel;    
   320         ret = mMessageListModel;
   322     }
   321     }
   323     return *ret;
   322     return *ret;
   324 }
   323 }
   325 
   324 
   326 
   325 
   332     \return A message list model.
   331     \return A message list model.
   333 */
   332 */
   334 NmMessageListModel &NmUiEngine::messageListModelForSearch(const NmId &mailboxId)
   333 NmMessageListModel &NmUiEngine::messageListModelForSearch(const NmId &mailboxId)
   335 {
   334 {
   336     NM_FUNCTION;
   335     NM_FUNCTION;
   337     
   336 
   338     Q_UNUSED(mailboxId);
   337     Q_UNUSED(mailboxId);
   339 
   338 
   340     if (!mMessageSearchListModel) {
   339     if (!mMessageSearchListModel) {
   341         mMessageSearchListModel = new NmMessageListModel(*mDataManager);
   340         mMessageSearchListModel = new NmMessageListModel(*mDataManager);
   342         mMessageSearchListModel->setIgnoreFolderIds(true);
   341         mMessageSearchListModel->setIgnoreFolderIds(true);
   362     return *mMessageSearchListModel;
   361     return *mMessageSearchListModel;
   363 }
   362 }
   364 
   363 
   365 
   364 
   366 /*!
   365 /*!
   367     Get the identifier of the standard folder of a type \a folderType 
   366     Get the identifier of the standard folder of a type \a folderType
   368     from the mailbox \a mailboxId.
   367     from the mailbox \a mailboxId.
   369 */
   368 */
   370 NmId NmUiEngine::standardFolderId(
   369 NmId NmUiEngine::standardFolderId(
   371     const NmId &mailboxId,
   370     const NmId &mailboxId,
   372     NmFolderType folderType)
   371     NmFolderType folderType)
   373 {
   372 {
   374     NM_FUNCTION;
   373     NM_FUNCTION;
   375     
   374 
   376     NmId value;
   375     NmId value;
   377     if (folderType != NmFolderOther) {
   376     if (folderType != NmFolderOther) {
   378         NmDataPluginInterface *plugin =
   377         NmDataPluginInterface *plugin =
   379             mPluginFactory->interfaceInstance(mailboxId);
   378             mPluginFactory->interfaceInstance(mailboxId);
   380         if(plugin) {
   379         if(plugin) {
   392 NmMessage *NmUiEngine::message(const NmId &mailboxId,
   391 NmMessage *NmUiEngine::message(const NmId &mailboxId,
   393                       const NmId &folderId,
   392                       const NmId &folderId,
   394                       const NmId &messageId)
   393                       const NmId &messageId)
   395 {
   394 {
   396     NM_FUNCTION;
   395     NM_FUNCTION;
   397     
   396 
   398     NmMessage *message = mDataManager->message(mailboxId, folderId, messageId);
   397     NmMessage *message = mDataManager->message(mailboxId, folderId, messageId);
   399     return message;
   398     return message;
   400 }
   399 }
   401 
   400 
   402 /*!
   401 /*!
   405 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId,
   404 QPointer<NmOperation> NmUiEngine::fetchMessage( const NmId &mailboxId,
   406     const NmId &folderId,
   405     const NmId &folderId,
   407     const NmId &messageId )
   406     const NmId &messageId )
   408 {
   407 {
   409     NM_FUNCTION;
   408     NM_FUNCTION;
   410     
   409 
   411     QPointer<NmOperation> value(NULL);
   410     QPointer<NmOperation> value(NULL);
   412     NmDataPluginInterface *plugin =
   411     NmDataPluginInterface *plugin =
   413         mPluginFactory->interfaceInstance(mailboxId);
   412         mPluginFactory->interfaceInstance(mailboxId);
   414     if (plugin) {
   413     if (plugin) {
   415         value = plugin->fetchMessage(mailboxId, folderId, messageId);
   414         value = plugin->fetchMessage(mailboxId, folderId, messageId);
   425     const NmId &folderId,
   424     const NmId &folderId,
   426     const NmId &messageId,
   425     const NmId &messageId,
   427     const NmId &messagePartId)
   426     const NmId &messagePartId)
   428 {
   427 {
   429     NM_FUNCTION;
   428     NM_FUNCTION;
   430     
   429 
   431     QPointer<NmOperation> value(NULL);
   430     QPointer<NmOperation> value(NULL);
   432     NmDataPluginInterface *plugin =
   431     NmDataPluginInterface *plugin =
   433         mPluginFactory->interfaceInstance(mailboxId);
   432         mPluginFactory->interfaceInstance(mailboxId);
   434     if (plugin) {
   433     if (plugin) {
   435         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
   434         value = plugin->fetchMessagePart(mailboxId, folderId, messageId, messagePartId);
   445     const NmId &folderId,
   444     const NmId &folderId,
   446     const NmId &messageId,
   445     const NmId &messageId,
   447     const QList<NmId> &messagePartIds)
   446     const QList<NmId> &messagePartIds)
   448 {
   447 {
   449     NM_FUNCTION;
   448     NM_FUNCTION;
   450     
   449 
   451     QPointer<NmOperation> value(NULL);
   450     QPointer<NmOperation> value(NULL);
   452     NmDataPluginInterface *plugin =
   451     NmDataPluginInterface *plugin =
   453         mPluginFactory->interfaceInstance(mailboxId);
   452         mPluginFactory->interfaceInstance(mailboxId);
   454     if (plugin) {
   453     if (plugin) {
   455         value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds);
   454         value = plugin->fetchMessageParts(mailboxId, folderId, messageId, messagePartIds);
   465         const NmId &folderId,
   464         const NmId &folderId,
   466         const NmId &messageId,
   465         const NmId &messageId,
   467         const NmId &messagePartId)
   466         const NmId &messagePartId)
   468 {
   467 {
   469     NM_FUNCTION;
   468     NM_FUNCTION;
   470     
   469 
   471     NmDataPluginInterface *plugin =
   470     NmDataPluginInterface *plugin =
   472         mPluginFactory->interfaceInstance(mailboxId);
   471         mPluginFactory->interfaceInstance(mailboxId);
   473     if (plugin) {
   472     if (plugin) {
   474         return plugin->messagePartFile(mailboxId, folderId, messageId, messagePartId);
   473         return plugin->messagePartFile(mailboxId, folderId, messageId, messagePartId);
   475     }
   474     }
   486     const NmId &folderId,
   485     const NmId &folderId,
   487     const NmId &messageId,
   486     const NmId &messageId,
   488     NmMessagePart &messagePart)
   487     NmMessagePart &messagePart)
   489 {
   488 {
   490     NM_FUNCTION;
   489     NM_FUNCTION;
   491     
   490 
   492     return mDataManager->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   491     return mDataManager->contentToMessagePart(mailboxId, folderId, messageId, messagePart);
   493 }
   492 }
   494 
   493 
   495 
   494 
   496 /*!
   495 /*!
   505 int NmUiEngine::deleteMessages(const NmId &mailboxId,
   504 int NmUiEngine::deleteMessages(const NmId &mailboxId,
   506                                const NmId &folderId,
   505                                const NmId &folderId,
   507                                const QList<NmId> &messageIdList)
   506                                const QList<NmId> &messageIdList)
   508 {
   507 {
   509     NM_FUNCTION;
   508     NM_FUNCTION;
   510     
   509 
   511     int result(NmNotFoundError);
   510     int result(NmNotFoundError);
   512     
   511 
   513     bool isInbox(false);
   512     bool isInbox(false);
   514     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   513     if (standardFolderId(mailboxId,NmFolderInbox)==folderId){
   515         isInbox=true;
   514         isInbox=true;
   516     } 
   515     }
   517     if (isInbox&&mInboxListModel){
   516     if (isInbox&&mInboxListModel){
   518         mInboxListModel->handleMessageEvent(NmMessageDeleted, folderId,
   517         mInboxListModel->handleMessageEvent(NmMessageDeleted, folderId,
   519                                                messageIdList, mailboxId);   
   518                                                messageIdList, mailboxId);
   520     }   
   519     }
   521     else if (mMessageListModel) {
   520     else if (mMessageListModel) {
   522 	    mMessageListModel->handleMessageEvent(NmMessageDeleted, folderId,
   521 	    mMessageListModel->handleMessageEvent(NmMessageDeleted, folderId,
   523                                               messageIdList, mailboxId);
   522                                               messageIdList, mailboxId);
   524 	}
   523 	}
   525 
   524 
   557         const NmId &folderId,
   556         const NmId &folderId,
   558         NmEnvelopeProperties property,
   557         NmEnvelopeProperties property,
   559         const QList<const NmMessageEnvelope*> &envelopeList)
   558         const QList<const NmMessageEnvelope*> &envelopeList)
   560 {
   559 {
   561     NM_FUNCTION;
   560     NM_FUNCTION;
   562     
   561 
   563     QPointer<NmStoreEnvelopesOperation> operation(NULL);
   562     QPointer<NmStoreEnvelopesOperation> operation(NULL);
   564     NmMessageListModel *theMessageListModel = mMessageListModel;
   563     NmMessageListModel *theMessageListModel = mMessageListModel;
   565 
   564 
   566     if (!theMessageListModel) {
   565     if (!theMessageListModel) {
   567         theMessageListModel = &messageListModel(mailboxId, folderId);
   566         theMessageListModel = &messageListModel(mailboxId, folderId);
   568     }
   567     }
   569 
   568 
   570     if (theMessageListModel && envelopeList.count()) {
   569     if (theMessageListModel && envelopeList.count()) {
   571         QList<NmId> messageIdList;
   570         QList<NmId> messageIdList;
   572         
   571 
   573         for (int i(0); i < envelopeList.count(); i++){
   572         for (int i(0); i < envelopeList.count(); i++){
   574             messageIdList.append(envelopeList[i]->messageId());
   573             messageIdList.append(envelopeList[i]->messageId());
   575         }
   574         }
   576 
   575 
   577         theMessageListModel->setEnvelopeProperties(property, messageIdList);
   576         theMessageListModel->setEnvelopeProperties(property, messageIdList);
   626     Operation is automatically deleted after completion or cancelling.
   625     Operation is automatically deleted after completion or cancelling.
   627 */
   626 */
   628 QPointer<NmMessageCreationOperation> NmUiEngine::createNewMessage(const NmId &mailboxId)
   627 QPointer<NmMessageCreationOperation> NmUiEngine::createNewMessage(const NmId &mailboxId)
   629 {
   628 {
   630     NM_FUNCTION;
   629     NM_FUNCTION;
   631     
   630 
   632     QPointer<NmMessageCreationOperation> value(NULL);
   631     QPointer<NmMessageCreationOperation> value(NULL);
   633     NmDataPluginInterface *plugin =
   632     NmDataPluginInterface *plugin =
   634         mPluginFactory->interfaceInstance(mailboxId);
   633         mPluginFactory->interfaceInstance(mailboxId);
   635     if (plugin) {
   634     if (plugin) {
   636         value = plugin->createNewMessage(mailboxId);
   635         value = plugin->createNewMessage(mailboxId);
   645 QPointer<NmMessageCreationOperation> NmUiEngine::createForwardMessage(
   644 QPointer<NmMessageCreationOperation> NmUiEngine::createForwardMessage(
   646         const NmId &mailboxId,
   645         const NmId &mailboxId,
   647         const NmId &originalMessageId)
   646         const NmId &originalMessageId)
   648 {
   647 {
   649     NM_FUNCTION;
   648     NM_FUNCTION;
   650     
   649 
   651     QPointer<NmMessageCreationOperation> value(NULL);
   650     QPointer<NmMessageCreationOperation> value(NULL);
   652     NmDataPluginInterface *plugin =
   651     NmDataPluginInterface *plugin =
   653         mPluginFactory->interfaceInstance(mailboxId);
   652         mPluginFactory->interfaceInstance(mailboxId);
   654     if (plugin) {
   653     if (plugin) {
   655         value = plugin->createForwardMessage(mailboxId, originalMessageId);
   654         value = plugin->createForwardMessage(mailboxId, originalMessageId);
   665         const NmId &mailboxId,
   664         const NmId &mailboxId,
   666         const NmId &originalMessageId,
   665         const NmId &originalMessageId,
   667         bool replyAll)
   666         bool replyAll)
   668 {
   667 {
   669     NM_FUNCTION;
   668     NM_FUNCTION;
   670     
   669 
   671     QPointer<NmMessageCreationOperation> value(NULL);
   670     QPointer<NmMessageCreationOperation> value(NULL);
   672     NmDataPluginInterface *plugin =
   671     NmDataPluginInterface *plugin =
   673         mPluginFactory->interfaceInstance(mailboxId);
   672         mPluginFactory->interfaceInstance(mailboxId);
   674     if (plugin) {
   673     if (plugin) {
   675         value = plugin->createReplyMessage(mailboxId, originalMessageId, replyAll);
   674         value = plugin->createReplyMessage(mailboxId, originalMessageId, replyAll);
   681     Saves a message (into message store).
   680     Saves a message (into message store).
   682 */
   681 */
   683 int NmUiEngine::saveMessage(const NmMessage &message)
   682 int NmUiEngine::saveMessage(const NmMessage &message)
   684 {
   683 {
   685     NM_FUNCTION;
   684     NM_FUNCTION;
   686     
   685 
   687     const NmId &mailboxId = message.envelope().mailboxId();
   686     const NmId &mailboxId = message.envelope().mailboxId();
   688     int ret(NmNotFoundError);
   687     int ret(NmNotFoundError);
   689     NmDataPluginInterface *plugin =
   688     NmDataPluginInterface *plugin =
   690         mPluginFactory->interfaceInstance(mailboxId);
   689         mPluginFactory->interfaceInstance(mailboxId);
   691     if (plugin) {
   690     if (plugin) {
   698     Refreshes mailbox.
   697     Refreshes mailbox.
   699 */
   698 */
   700 int NmUiEngine::refreshMailbox(const NmId &mailboxId )
   699 int NmUiEngine::refreshMailbox(const NmId &mailboxId )
   701 {
   700 {
   702     NM_FUNCTION;
   701     NM_FUNCTION;
   703     
   702 
   704     int ret(NmNotFoundError);
   703     int ret(NmNotFoundError);
   705     NmDataPluginInterface *plugin =
   704     NmDataPluginInterface *plugin =
   706         mPluginFactory->interfaceInstance(mailboxId);
   705         mPluginFactory->interfaceInstance(mailboxId);
   707     if (plugin) {
   706     if (plugin) {
   708         ret = plugin->refreshMailbox(mailboxId);
   707         ret = plugin->refreshMailbox(mailboxId);
   709         if (NmNoError == ret) {
   708         if (NmNoError == ret) {
   710             HbIndicator indicator;
   709             enableSyncIndicator(true);
   711             indicator.activate(syncIndicatorName, QVariant());
       
   712         }
   710         }
   713     }
   711     }
   714     return ret;
   712     return ret;
   715 }
   713 }
   716 
   714 
   718     Online mailbox.
   716     Online mailbox.
   719 */
   717 */
   720 int NmUiEngine::goOnline(const NmId &mailboxId )
   718 int NmUiEngine::goOnline(const NmId &mailboxId )
   721 {
   719 {
   722     NM_FUNCTION;
   720     NM_FUNCTION;
   723     
   721 
   724     int ret(NmNotFoundError);
   722     int ret(NmNotFoundError);
   725     NmDataPluginInterface *plugin =
   723     NmDataPluginInterface *plugin =
   726         mPluginFactory->interfaceInstance(mailboxId);
   724         mPluginFactory->interfaceInstance(mailboxId);
   727     if (plugin) {
   725     if (plugin) {
   728         ret = plugin->goOnline(mailboxId);
   726         ret = plugin->goOnline(mailboxId);
   734     Offline mailbox.
   732     Offline mailbox.
   735 */
   733 */
   736 int NmUiEngine::goOffline(const NmId &mailboxId )
   734 int NmUiEngine::goOffline(const NmId &mailboxId )
   737 {
   735 {
   738     NM_FUNCTION;
   736     NM_FUNCTION;
   739     
   737 
   740     int ret(NmNotFoundError);
   738     int ret(NmNotFoundError);
   741     NmDataPluginInterface *plugin =
   739     NmDataPluginInterface *plugin =
   742         mPluginFactory->interfaceInstance(mailboxId);
   740         mPluginFactory->interfaceInstance(mailboxId);
   743     if (plugin) {
   741     if (plugin) {
   744         ret = plugin->goOffline(mailboxId);
   742         ret = plugin->goOffline(mailboxId);
   754     const NmId &mailboxId,
   752     const NmId &mailboxId,
   755     const NmId &folderId,
   753     const NmId &folderId,
   756     const NmId &messageId)
   754     const NmId &messageId)
   757 {
   755 {
   758     NM_FUNCTION;
   756     NM_FUNCTION;
   759     
   757 
   760     int result(NmNotFoundError);
   758     int result(NmNotFoundError);
   761     NmDataPluginInterface *plugin =
   759     NmDataPluginInterface *plugin =
   762             mPluginFactory->interfaceInstance(mailboxId);
   760             mPluginFactory->interfaceInstance(mailboxId);
   763     if (plugin) {
   761     if (plugin) {
   764           result = plugin->removeMessage(mailboxId, folderId, messageId);
   762           result = plugin->removeMessage(mailboxId, folderId, messageId);
   766     return result;
   764     return result;
   767 }
   765 }
   768 
   766 
   769 
   767 
   770 /*!
   768 /*!
   771   Handles draft message deletion after editor has closed, takes ownership of message. 
   769   Handles draft message deletion after editor has closed, takes ownership of message.
   772  */
   770  */
   773 void NmUiEngine::removeDraftMessage(NmMessage *message)
   771 void NmUiEngine::removeDraftMessage(NmMessage *message)
   774 {
   772 {
   775     NM_FUNCTION;
   773     NM_FUNCTION;
   776 
   774 
   777     if (message) {
   775     if (message) {
   778         NmDataPluginInterface *plugin =
   776         NmDataPluginInterface *plugin =
   779             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   777             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   780         
   778 
   781         if (plugin) {
   779         if (plugin) {
   782             // to be on the safer side:
   780             // to be on the safer side:
   783             // we shouldn't even be here if mRemoveDraftOperation != NULL
   781             // we shouldn't even be here if mRemoveDraftOperation != NULL
   784             if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) {
   782             if (mRemoveDraftOperation && mRemoveDraftOperation->isRunning()) {
   785                 mRemoveDraftOperation->cancelOperation();
   783                 mRemoveDraftOperation->cancelOperation();
   786             }
   784             }
   787             // ownership of message changes
   785             // ownership of message changes
   788             mRemoveDraftOperation = plugin->removeDraftMessage(message);
   786             mRemoveDraftOperation = plugin->removeDraftMessage(message);
   789             
   787 
   790             if (mRemoveDraftOperation) {
   788             if (mRemoveDraftOperation) {
   791                 connect(mRemoveDraftOperation, 
   789                 connect(mRemoveDraftOperation,
   792                         SIGNAL(operationCompleted(int)), 
   790                         SIGNAL(operationCompleted(int)),
   793                         this, 
   791                         this,
   794                         SLOT(handleCompletedRemoveDraftOperation()));
   792                         SLOT(handleCompletedRemoveDraftOperation()));
   795             }
   793             }
   796         }
   794         }
   797     }    
   795     }
   798 }
   796 }
   799 
   797 
   800 /*!
   798 /*!
   801     Handles draft message saving after editor has closed, takes ownership of message.
   799     Handles draft message saving after editor has closed, takes ownership of message.
   802  */
   800  */
   803 void NmUiEngine::saveDraftMessage(NmMessage *message,
   801 void NmUiEngine::saveDraftMessage(NmMessage *message,
   804                                   const QList<NmOperation*> &preliminaryOperations)
   802                                   const QList<NmOperation*> &preliminaryOperations)
   805 {
   803 {
   806     NM_FUNCTION;
   804     NM_FUNCTION;
   807     
   805 
   808     if (message) {
   806     if (message) {
   809         NmDataPluginInterface *plugin =
   807         NmDataPluginInterface *plugin =
   810             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   808             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   811         
   809 
   812         if (plugin) {
   810         if (plugin) {
   813             // to be on the safer side:
   811             // to be on the safer side:
   814             // we shouldn't even be here if mSaveDraftOperation != NULL
   812             // we shouldn't even be here if mSaveDraftOperation != NULL
   815             if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) {
   813             if (mSaveDraftOperation && mSaveDraftOperation->isRunning()) {
   816                 mSaveDraftOperation->cancelOperation();
   814                 mSaveDraftOperation->cancelOperation();
   817             }
   815             }
   818             
   816 
   819             mSaveDraftOperation = plugin->saveMessageWithSubparts(*message);
   817             mSaveDraftOperation = plugin->saveMessageWithSubparts(*message);
   820             
   818 
   821             if (mSaveDraftOperation) {
   819             if (mSaveDraftOperation) {
   822                 // Ownership of message changes but saveMessageWithSubparts operation only makes a 
   820                 // Ownership of message changes but saveMessageWithSubparts operation only makes a
   823                 // copy so we handle the msg object deletion in engine. mDraftMessage is deleted
   821                 // copy so we handle the msg object deletion in engine. mDraftMessage is deleted
   824                 // in handleCompletedSaveDraftOperation once operation finishes. 
   822                 // in handleCompletedSaveDraftOperation once operation finishes.
   825                 if(mDraftMessage) {
   823                 if(mDraftMessage) {
   826                     delete mDraftMessage;
   824                     delete mDraftMessage;
   827                     mDraftMessage = NULL;
   825                     mDraftMessage = NULL;
   828                 }
   826                 }
   829                 mDraftMessage = message;
   827                 mDraftMessage = message;
   830                 message = NULL;
   828                 message = NULL;
   831                 
   829 
   832                 for (int i(0); i < preliminaryOperations.count(); i++ ) {
   830                 for (int i(0); i < preliminaryOperations.count(); i++ ) {
   833                     QPointer<NmOperation> op = preliminaryOperations[i];
   831                     QPointer<NmOperation> op = preliminaryOperations[i];
   834                     mSaveDraftOperation->addPreliminaryOperation(op);
   832                     mSaveDraftOperation->addPreliminaryOperation(op);
   835                 }
   833                 }
   836                 
   834 
   837                 connect(mSaveDraftOperation, 
   835                 connect(mSaveDraftOperation,
   838                         SIGNAL(operationCompleted(int)), 
   836                         SIGNAL(operationCompleted(int)),
   839                         this, 
   837                         this,
   840                         SLOT(handleCompletedSaveDraftOperation()));
   838                         SLOT(handleCompletedSaveDraftOperation()));
   841                 
   839 
   842             }
   840             }
   843         }
   841         }
   844     }
   842     }
   845 }
   843 }
   846 
   844 
   848     Sends the given message.
   846     Sends the given message.
   849  */
   847  */
   850 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations)
   848 void NmUiEngine::sendMessage(NmMessage *message, const QList<NmOperation *> &preliminaryOperations)
   851 {
   849 {
   852     NM_FUNCTION;
   850     NM_FUNCTION;
   853     
   851 
   854     //First trigger message storing
   852     //First trigger message storing
   855     if (message) {
   853     if (message) {
   856         NmDataPluginInterface *plugin =
   854         NmDataPluginInterface *plugin =
   857             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   855             mPluginFactory->interfaceInstance(message->envelope().mailboxId());
   858         
   856 
   859         if (plugin) {
   857         if (plugin) {
   860             // to be on the safer side:
   858             // to be on the safer side:
   861             // we shouldn't even be here if mSendOperation != NULL
   859             // we shouldn't even be here if mSendOperation != NULL
   862             if (mSendOperation && mSendOperation->isRunning()) {
   860             if (mSendOperation && mSendOperation->isRunning()) {
   863                 mSendOperation->cancelOperation();
   861                 mSendOperation->cancelOperation();
   869             if (mSendOperation) {
   867             if (mSendOperation) {
   870                 for (int i(0); i < preliminaryOperations.count(); i++ ) {
   868                 for (int i(0); i < preliminaryOperations.count(); i++ ) {
   871                     QPointer<NmOperation> op = preliminaryOperations[i];
   869                     QPointer<NmOperation> op = preliminaryOperations[i];
   872                     mSendOperation->addPreliminaryOperation(op);
   870                     mSendOperation->addPreliminaryOperation(op);
   873                 }
   871                 }
   874                 
   872 
   875                 connect(mSendOperation, 
   873                 connect(mSendOperation,
   876                         SIGNAL(operationCompleted(int)), 
   874                         SIGNAL(operationCompleted(int)),
   877                         this, 
   875                         this,
   878                         SLOT(handleCompletedSendOperation()));
   876                         SLOT(handleCompletedSendOperation()));
   879             }
   877             }
   880         }
   878         }
   881     }
   879     }
   882 }
   880 }
   885     Is sending operation in progress.
   883     Is sending operation in progress.
   886  */
   884  */
   887 bool NmUiEngine::isSendingMessage() const
   885 bool NmUiEngine::isSendingMessage() const
   888 {
   886 {
   889     NM_FUNCTION;
   887     NM_FUNCTION;
   890     
   888 
   891     int ret(false);
   889     int ret(false);
   892     if (mSendOperation && mSendOperation->isRunning()) {
   890     if (mSendOperation && mSendOperation->isRunning()) {
   893         ret = true;
   891         ret = true;
   894     }
   892     }
   895     return ret;
   893     return ret;
   899    Returns a pointer to the message that is being sent. Returns NULL if not sending.
   897    Returns a pointer to the message that is being sent. Returns NULL if not sending.
   900  */
   898  */
   901 const NmMessage *NmUiEngine::messageBeingSent() const
   899 const NmMessage *NmUiEngine::messageBeingSent() const
   902 {
   900 {
   903     NM_FUNCTION;
   901     NM_FUNCTION;
   904     
   902 
   905     const NmMessage *message = NULL;
   903     const NmMessage *message = NULL;
   906     
   904 
   907     if (mSendOperation != NULL) {
   905     if (mSendOperation != NULL) {
   908         message = mSendOperation->getMessage();
   906         message = mSendOperation->getMessage();
   909     }
   907     }
   910     
   908 
   911     return message;
   909     return message;
   912 }
   910 }
   913 
   911 
   914 /*!
   912 /*!
   915     Add file attachment into given message. Return the operation object for
   913     Add file attachment into given message. Return the operation object for
   918 QPointer<NmAddAttachmentsOperation> NmUiEngine::addAttachments(
   916 QPointer<NmAddAttachmentsOperation> NmUiEngine::addAttachments(
   919     const NmMessage &message,
   917     const NmMessage &message,
   920     const QList<QString> &fileList)
   918     const QList<QString> &fileList)
   921 {
   919 {
   922     NM_FUNCTION;
   920     NM_FUNCTION;
   923     
   921 
   924     NmDataPluginInterface *plugin =
   922     NmDataPluginInterface *plugin =
   925         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   923         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   926     
   924 
   927     QPointer<NmAddAttachmentsOperation> ret(NULL);    
   925     QPointer<NmAddAttachmentsOperation> ret(NULL);
   928     if (plugin) {
   926     if (plugin) {
   929         ret = plugin->addAttachments(message, fileList);
   927         ret = plugin->addAttachments(message, fileList);
   930     }
   928     }
   931     return ret;
   929     return ret;
   932 }
   930 }
   938 QPointer<NmOperation> NmUiEngine::removeAttachment(
   936 QPointer<NmOperation> NmUiEngine::removeAttachment(
   939     const NmMessage &message,
   937     const NmMessage &message,
   940     const NmId &attachmentPartId)
   938     const NmId &attachmentPartId)
   941 {
   939 {
   942     NM_FUNCTION;
   940     NM_FUNCTION;
   943     
   941 
   944     NmDataPluginInterface *plugin =
   942     NmDataPluginInterface *plugin =
   945         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   943         mPluginFactory->interfaceInstance(message.envelope().mailboxId());
   946     
   944 
   947     QPointer<NmOperation> ret(NULL);   
   945     QPointer<NmOperation> ret(NULL);
   948     if (plugin) {
   946     if (plugin) {
   949         ret = plugin->removeAttachment(message, attachmentPartId);
   947         ret = plugin->removeAttachment(message, attachmentPartId);
   950     }
   948     }
   951     return ret;
   949     return ret;
   952 }
   950 }
   955     Returns the current sync state of the mailbox
   953     Returns the current sync state of the mailbox
   956  */
   954  */
   957 NmSyncState NmUiEngine::syncState(const NmId& mailboxId)
   955 NmSyncState NmUiEngine::syncState(const NmId& mailboxId)
   958 {
   956 {
   959     NM_FUNCTION;
   957     NM_FUNCTION;
   960     
   958 
   961     NmDataPluginInterface *plugin =
   959     NmDataPluginInterface *plugin =
   962                 mPluginFactory->interfaceInstance(mailboxId);
   960                 mPluginFactory->interfaceInstance(mailboxId);
   963     if (plugin) {
   961     if (plugin) {
   964         return plugin->syncState(mailboxId);
   962         return plugin->syncState(mailboxId);
   965     }
   963     }
   972     Returns the current connection state of the mailbox
   970     Returns the current connection state of the mailbox
   973  */
   971  */
   974 NmConnectState NmUiEngine::connectionState(const NmId& mailboxId)
   972 NmConnectState NmUiEngine::connectionState(const NmId& mailboxId)
   975 {
   973 {
   976     NM_FUNCTION;
   974     NM_FUNCTION;
   977     
   975 
   978     NmDataPluginInterface *plugin =
   976     NmDataPluginInterface *plugin =
   979                 mPluginFactory->interfaceInstance(mailboxId);
   977                 mPluginFactory->interfaceInstance(mailboxId);
   980     if (plugin) {
   978     if (plugin) {
   981         return plugin->connectionState(mailboxId);
   979         return plugin->connectionState(mailboxId);
   982     }
   980     }
   996 */
   994 */
   997 int NmUiEngine::search(const NmId &mailboxId,
   995 int NmUiEngine::search(const NmId &mailboxId,
   998                        const QStringList &searchStrings)
   996                        const QStringList &searchStrings)
   999 {
   997 {
  1000     NM_FUNCTION;
   998     NM_FUNCTION;
  1001     
   999 
  1002     // Get the plugin instance.
  1000     // Get the plugin instance.
  1003     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
  1001     QObject *pluginInstance = mPluginFactory->pluginInstance(mailboxId);
  1004 
  1002 
  1005     if (pluginInstance) {
  1003     if (pluginInstance) {
  1006         // Make sure the required signals are connected.
  1004         // Make sure the required signals are connected.
  1008                 this, SIGNAL(matchFound(const NmId &, const NmId &)),
  1006                 this, SIGNAL(matchFound(const NmId &, const NmId &)),
  1009                 Qt::UniqueConnection);
  1007                 Qt::UniqueConnection);
  1010 
  1008 
  1011         connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)),
  1009         connect(pluginInstance, SIGNAL(matchFound(const NmId &, const NmId &)),
  1012                 this, SLOT(handleMatchFound(const NmId &, const NmId &)),
  1010                 this, SLOT(handleMatchFound(const NmId &, const NmId &)),
  1013                 Qt::UniqueConnection); 
  1011                 Qt::UniqueConnection);
  1014 
  1012 
  1015         connect(pluginInstance, SIGNAL(searchComplete()),
  1013         connect(pluginInstance, SIGNAL(searchComplete()),
  1016                 this, SIGNAL(searchComplete()),
  1014                 this, SIGNAL(searchComplete()),
  1017                 Qt::UniqueConnection);    
  1015                 Qt::UniqueConnection);
  1018     }
  1016     }
  1019 
  1017 
  1020     int retVal(NmNoError);
  1018     int retVal(NmNoError);
  1021 
  1019 
  1022     // Get the plugin interface.
  1020     // Get the plugin interface.
  1025 
  1023 
  1026     if (pluginInterface) {
  1024     if (pluginInterface) {
  1027         // Start the search.
  1025         // Start the search.
  1028         retVal = pluginInterface->search(mailboxId, searchStrings);
  1026         retVal = pluginInterface->search(mailboxId, searchStrings);
  1029     }
  1027     }
  1030     
  1028 
  1031     return retVal;
  1029     return retVal;
  1032 }
  1030 }
  1033 
  1031 
  1034 
  1032 
  1035 /*!
  1033 /*!
  1040     \return A possible error code.
  1038     \return A possible error code.
  1041 */
  1039 */
  1042 int NmUiEngine::cancelSearch(const NmId &mailboxId)
  1040 int NmUiEngine::cancelSearch(const NmId &mailboxId)
  1043 {
  1041 {
  1044     NM_FUNCTION;
  1042     NM_FUNCTION;
  1045     
  1043 
  1046     int retVal(NmNoError);
  1044     int retVal(NmNoError);
  1047 
  1045 
  1048     // Get the plugin interface.
  1046     // Get the plugin interface.
  1049     NmDataPluginInterface *pluginInterface =
  1047     NmDataPluginInterface *pluginInterface =
  1050         mPluginFactory->interfaceInstance(mailboxId);
  1048         mPluginFactory->interfaceInstance(mailboxId);
  1051 
  1049 
  1052     if (pluginInterface) {
  1050     if (pluginInterface) {
  1053         // Cancel the search.
  1051         // Cancel the search.
  1054         retVal = pluginInterface->cancelSearch(mailboxId);
  1052         retVal = pluginInterface->cancelSearch(mailboxId);
  1055     }  
  1053     }
  1056     return retVal;    
  1054     return retVal;
  1057 }
  1055 }
  1058 
  1056 
  1059 /*!
  1057 /*!
       
  1058     Get mailbox folder type by folder id
       
  1059     \param mailboxId id of the mailbox
       
  1060     \param folderId id of the folder
  1060     \return Folder type
  1061     \return Folder type
  1061 */
  1062 */
  1062 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
  1063 NmFolderType NmUiEngine::folderTypeById(NmId mailboxId, NmId folderId)
  1063 {
  1064 {
  1064     NM_FUNCTION;
  1065     NM_FUNCTION;
  1065     
  1066 
  1066     NmFolderType ret(NmFolderInbox);
  1067     NmFolderType ret(NmFolderInbox);
  1067     if (mDataManager){
  1068     if (mDataManager){
  1068         ret = mDataManager->folderTypeById(mailboxId,folderId);    
  1069         ret = mDataManager->folderTypeById(mailboxId,folderId);
  1069     }
  1070     }
  1070     return ret;
  1071     return ret;
  1071 }
  1072 }
  1072 
  1073 
  1073 /*!
  1074 /*!
  1076     \param folderId Id of active folder, 0 if application is closed.
  1077     \param folderId Id of active folder, 0 if application is closed.
  1077 */
  1078 */
  1078 void NmUiEngine::updateActiveFolder(const NmId &mailboxId, const NmId &folderId)
  1079 void NmUiEngine::updateActiveFolder(const NmId &mailboxId, const NmId &folderId)
  1079 {
  1080 {
  1080     NM_FUNCTION;
  1081     NM_FUNCTION;
  1081     
  1082 
  1082     NmApplicationStateInterface *interface = 
  1083     NmApplicationStateInterface *interface =
  1083         mPluginFactory->applicationStateInterfaceInstance(mailboxId);
  1084         mPluginFactory->applicationStateInterfaceInstance(mailboxId);
  1084     if (interface) {
  1085     if (interface) {
  1085         interface->updateActiveFolder(mailboxId, folderId);
  1086         interface->updateActiveFolder(mailboxId, folderId);
  1086     }
  1087     }
  1087 }
  1088 }
  1090     Handle completed send operation.
  1091     Handle completed send operation.
  1091 */
  1092 */
  1092 void NmUiEngine::handleCompletedSendOperation()
  1093 void NmUiEngine::handleCompletedSendOperation()
  1093 {
  1094 {
  1094     NM_FUNCTION;
  1095     NM_FUNCTION;
  1095     
  1096 
  1096     emit sendOperationCompleted();
  1097     emit sendOperationCompleted();
  1097 }
  1098 }
  1098 
  1099 
  1099 /*!
  1100 /*!
  1100     Handle completed remove draft operation.
  1101     Handle completed remove draft operation.
  1101 */
  1102 */
  1102 void NmUiEngine::handleCompletedRemoveDraftOperation()
  1103 void NmUiEngine::handleCompletedRemoveDraftOperation()
  1103 {
  1104 {
  1104     NM_FUNCTION;
  1105     NM_FUNCTION;
  1105     
  1106 
  1106     // draft message deletion observing not yet implemented...
  1107     // draft message deletion observing not yet implemented...
  1107 }
  1108 }
  1108 
  1109 
  1109 /*!
  1110 /*!
  1110     Handle completed save draft operation.
  1111     Handle completed save draft operation.
  1111 */
  1112 */
  1112 void NmUiEngine::handleCompletedSaveDraftOperation()
  1113 void NmUiEngine::handleCompletedSaveDraftOperation()
  1113 {
  1114 {
  1114     NM_FUNCTION;
  1115     NM_FUNCTION;
  1115     
  1116 
  1116     // delete message object since it's not needed anymore
  1117     // delete message object since it's not needed anymore
  1117     if(mDraftMessage) {
  1118     if(mDraftMessage) {
  1118         delete mDraftMessage;
  1119         delete mDraftMessage;
  1119         mDraftMessage = NULL;
  1120         mDraftMessage = NULL;
  1120     }
  1121     }
  1124     Handles synch operation related events
  1125     Handles synch operation related events
  1125  */
  1126  */
  1126 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event)
  1127 void NmUiEngine::handleSyncStateEvent(NmSyncState syncState, const NmOperationCompletionEvent &event)
  1127 {
  1128 {
  1128     NM_FUNCTION;
  1129     NM_FUNCTION;
  1129     
  1130 
  1130     if ( syncState == SyncComplete ) {
  1131     if ( syncState == SyncComplete ) {
  1131         // signal for reporting about (sync) operation completion status
  1132         // signal for reporting about (sync) operation completion status
  1132         emit operationCompleted(event);
  1133         emit operationCompleted(event);
  1133         HbIndicator indicator;
  1134 
  1134         indicator.deactivate(syncIndicatorName, QVariant());
  1135         enableSyncIndicator(false);
  1135     }
  1136     }
  1136 
  1137 
  1137     // signal for handling sync state icons
  1138     // signal for handling sync state icons
  1138     emit syncStateEvent(syncState, event.mMailboxId);
  1139     emit syncStateEvent(syncState, event.mMailboxId);
  1139 }
  1140 }
  1140 
  1141 
  1141 /*!
  1142 /*!
  1142     Emits signals based on message events coming from plugins. 
  1143     Enable or disable sync indicator
       
  1144 
       
  1145     \param enabled true if indicator is enabled, false if disabled
       
  1146 */
       
  1147 void NmUiEngine::enableSyncIndicator(bool enabled)
       
  1148 {
       
  1149 	NM_FUNCTION;
       
  1150 
       
  1151     HbIndicator indicator;
       
  1152     if (enabled) {
       
  1153         indicator.activate(syncIndicatorName, QVariant());
       
  1154 	}
       
  1155     else {
       
  1156         indicator.deactivate(syncIndicatorName, QVariant());
       
  1157 	}
       
  1158 }
       
  1159 
       
  1160 
       
  1161 /*!
       
  1162     Emits signals based on message events coming from plugins.
  1143     Currently only NmMessageDeleted is handled.
  1163     Currently only NmMessageDeleted is handled.
  1144 */
  1164 */
  1145 void NmUiEngine::handleMessageEvent(NmMessageEvent event,
  1165 void NmUiEngine::handleMessageEvent(NmMessageEvent event,
  1146                                     const NmId &folderId,
  1166                                     const NmId &folderId,
  1147                                     const QList<NmId> &messageIds, 
  1167                                     const QList<NmId> &messageIds,
  1148                                     const NmId& mailboxId)
  1168                                     const NmId& mailboxId)
  1149 {
  1169 {
  1150     NM_FUNCTION;
  1170     NM_FUNCTION;
  1151     
  1171 
  1152     switch (event) {
  1172     switch (event) {
  1153         case NmMessageDeleted:
  1173         case NmMessageDeleted:
  1154         {
  1174         {
  1155             for (int i(0); i < messageIds.count(); i++) {
  1175             for (int i(0); i < messageIds.count(); i++) {
  1156                 emit messageDeleted(mailboxId, folderId, messageIds[i]);
  1176                 emit messageDeleted(mailboxId, folderId, messageIds[i]);
  1157             }
  1177             }
  1158            break; 
  1178            break;
  1159         }
  1179         }
  1160         default:
  1180         default:
  1161         break;
  1181         break;
  1162     }
  1182     }
  1163 }
  1183 }
  1164 
  1184 
  1165 /*!
  1185 /*!
  1166     Emits signals based on mailbox events coming from plugins. 
  1186     Emits signals based on mailbox events coming from plugins.
  1167     Currently only NmMailboxDeleted is handled.
  1187     Currently only NmMailboxDeleted is handled.
  1168 */
  1188 */
  1169 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event,
  1189 void NmUiEngine::handleMailboxEvent(NmMailboxEvent event,
  1170                                     const QList<NmId> &mailboxIds)
  1190                                     const QList<NmId> &mailboxIds)
  1171 {
  1191 {
  1172     NM_FUNCTION;
  1192     NM_FUNCTION;
  1173     
  1193 
  1174     switch (event) {
  1194     switch (event) {
  1175         case NmMailboxDeleted:
  1195         case NmMailboxDeleted:
  1176         {
  1196         {
  1177             for (int i(0); i < mailboxIds.count(); i++) {
  1197             for (int i(0); i < mailboxIds.count(); i++) {
  1178                 emit mailboxDeleted(mailboxIds[i]);
  1198                 emit mailboxDeleted(mailboxIds[i]);
  1179             }
  1199             }
  1180            break; 
  1200            break;
  1181         }
  1201         }
  1182         default:
  1202         default:
  1183         break;
  1203         break;
  1184     }
  1204     }
  1185 }
  1205 }
  1192     \param folderId The ID of the folder where the message is located.
  1212     \param folderId The ID of the folder where the message is located.
  1193 */
  1213 */
  1194 void NmUiEngine::handleMatchFound(const NmId &messageId, const NmId &folderId)
  1214 void NmUiEngine::handleMatchFound(const NmId &messageId, const NmId &folderId)
  1195 {
  1215 {
  1196     NM_FUNCTION;
  1216     NM_FUNCTION;
  1197     
  1217 
  1198     if (!mMessageSearchListModel) {
  1218     if (!mMessageSearchListModel) {
  1199         // No search list model!
  1219         // No search list model!
  1200         return;
  1220         return;
  1201     }
  1221     }
  1202 
  1222 
  1220     active mailbox is always alove whereas mMessageListModel can represent
  1240     active mailbox is always alove whereas mMessageListModel can represent
  1221     other folder in the device (sent, outbox, drafts, etc.)
  1241     other folder in the device (sent, outbox, drafts, etc.)
  1222 */
  1242 */
  1223 void NmUiEngine::messageEventForListModel(NmMessageEvent event,
  1243 void NmUiEngine::messageEventForListModel(NmMessageEvent event,
  1224                         const NmId &folderId,
  1244                         const NmId &folderId,
  1225                         const QList<NmId> &messageIds, 
  1245                         const QList<NmId> &messageIds,
  1226                         const NmId& mailboxId)
  1246                         const NmId& mailboxId)
  1227 {
  1247 {
  1228     NM_FUNCTION;
  1248     NM_FUNCTION;
  1229     
  1249 
  1230     // Forward event to both list models. Models will take care of checking
  1250     // Forward event to both list models. Models will take care of checking
  1231     // whether event really belongs to current mailbox & folder
  1251     // whether event really belongs to current mailbox & folder
  1232     if (mInboxListModel){
  1252     if (mInboxListModel){
  1233         mInboxListModel->handleMessageEvent(event, folderId,
  1253         mInboxListModel->handleMessageEvent(event, folderId,
  1234                                             messageIds, mailboxId);   
  1254                                             messageIds, mailboxId);
  1235     }
  1255     }
  1236     if (mMessageListModel){
  1256     if (mMessageListModel){
  1237         mMessageListModel->handleMessageEvent(event, folderId,
  1257         mMessageListModel->handleMessageEvent(event, folderId,
  1238                                               messageIds, mailboxId);    
  1258                                               messageIds, mailboxId);
  1239     }  
  1259     }
  1240 }
  1260 }
  1241 
  1261 
  1242 /*!
  1262 /*!
  1243     receives events when going online, and offline.
  1263     receives events when going online, and offline.
  1244 */
  1264 */
  1245 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
  1265 void NmUiEngine::handleConnectEvent(NmConnectState connectState, const NmId &mailboxId, const int errorCode)
  1246 {
  1266 {
  1247     NM_FUNCTION;
  1267     NM_FUNCTION;
  1248     
  1268 
  1249     // signal for connection state icon handling
  1269     // signal for connection state icon handling
  1250     emit connectionEvent(connectState, mailboxId);
  1270     emit connectionEvent(connectState, mailboxId);
  1251 
  1271 
  1252     // in case going offline w/ error, emit signal to UI
  1272     // in case going offline w/ error, emit signal to UI
  1253     if ( connectState == Disconnected && errorCode!= NmNoError ) {
  1273     if ( connectState == Disconnected && errorCode!= NmNoError ) {
  1254         NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0}; 
  1274         NmOperationCompletionEvent event={NoOp, errorCode, mailboxId, 0, 0};
  1255         emit operationCompleted(event);
  1275         emit operationCompleted(event);
  1256     }
  1276     }
  1257 }
  1277 }
  1258 
  1278 
  1259 /*!
  1279 /*!
  1260     returns full mailbox id from plain account id
  1280     returns full mailbox id from plain account id
  1261 */
  1281 */
  1262 NmId NmUiEngine::getPluginIdByMailboxId(quint32 accountId)
  1282 NmId NmUiEngine::getPluginIdByMailboxId(quint32 accountId)
  1263 {
  1283 {
  1264     NM_FUNCTION;
  1284     NM_FUNCTION;
  1265     
  1285 
  1266     NmId fullId = NULL;
  1286     NmId fullId = NULL;
  1267     fullId.setId32(accountId);
  1287     fullId.setId32(accountId);
  1268     QList<NmId> mailboxList;
  1288     QList<NmId> mailboxList;
  1269     if(mDataManager){
  1289     if(mDataManager){
  1270         mDataManager->listMailboxIds(mailboxList);
  1290         mDataManager->listMailboxIds(mailboxList);