emailuis/nmframeworkadapter/src/nmframeworkadapter.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    27     Symbian code and emailuis which is done using QT. Most functions in the adapter merely do d
    27     Symbian code and emailuis which is done using QT. Most functions in the adapter merely do d
    28     ata type conversions and forward function calls to emailframework implementation.
    28     ata type conversions and forward function calls to emailframework implementation.
    29     Also events coming from emailframework are converted and emitted as signals.
    29     Also events coming from emailframework are converted and emitted as signals.
    30  */
    30  */
    31 
    31 
    32 static const int nmListMessagesBlock = 100;
    32 static const int NmListMessagesBlock = 100;
    33 static const int nmMaxItemsInMessageList = 1000;
    33 
    34 
    34 
    35 
    35 
    36 /*!
    36 /*!
    37     Constructor
    37     Constructor
    38 */
    38 */
    39 NmFrameworkAdapter::NmFrameworkAdapter( ) : mFSfw(NULL)
    39 NmFrameworkAdapter::NmFrameworkAdapter()
       
    40 : mFSfw(NULL),
       
    41   mSearchObserver(NULL)
    40 {
    42 {
    41     NMLOG("NmFrameworkAdapter::NmFrameworkAdapter() <---");
    43     NMLOG("NmFrameworkAdapter::NmFrameworkAdapter() <---");
    42     // get s60email framework
    44 
       
    45     // get s60 email framework
    43     TRAP_IGNORE(mFSfw = CFSMailClient::NewL());
    46     TRAP_IGNORE(mFSfw = CFSMailClient::NewL());
    44     if(mFSfw){
    47 
       
    48     if (mFSfw) {
    45         TRAP_IGNORE(mFSfw->AddObserverL(*this));
    49         TRAP_IGNORE(mFSfw->AddObserverL(*this));
    46         }
    50     }
       
    51 
    47     NMLOG("NmFrameworkAdapter::NmFrameworkAdapter() --->");
    52     NMLOG("NmFrameworkAdapter::NmFrameworkAdapter() --->");
    48 }
    53 }
    49 
    54 
    50 /*!
    55 /*!
    51     Destructor
    56     Destructor
    52 */
    57 */
    53 NmFrameworkAdapter::~NmFrameworkAdapter()
    58 NmFrameworkAdapter::~NmFrameworkAdapter()
    54 {
    59 {
    55     if(mFSfw){
    60     if (mSearchObserver) {
       
    61         delete mSearchObserver;
       
    62         mSearchObserver = NULL;
       
    63     }
       
    64 
       
    65     if (mFSfw) {
    56         mFSfw->RemoveObserver(*this);
    66         mFSfw->RemoveObserver(*this);
    57         mFSfw->Close();
    67         mFSfw->Close();
    58         }
    68     }
    59 
    69 
    60     mFSfw = NULL;
    70     mFSfw = NULL;
    61 }
    71 }
    62 
    72 
    63 /*!
    73 /*!
   279 int NmFrameworkAdapter::listMessages(
   289 int NmFrameworkAdapter::listMessages(
   280 	const NmId &mailboxId,
   290 	const NmId &mailboxId,
   281     const NmId &folderId,
   291     const NmId &folderId,
   282     QList<NmMessageEnvelope*> &messageEnvelopeList)
   292     QList<NmMessageEnvelope*> &messageEnvelopeList)
   283 {
   293 {
   284     TRAPD(err, listMessagesL(mailboxId,folderId,messageEnvelopeList, nmMaxItemsInMessageList));
   294     TRAPD(err, listMessagesL(mailboxId,folderId,messageEnvelopeList, NmMaxItemsInMessageList));
   285     return err;
   295     return err;
   286 }
   296 }
   287 
   297 
   288 int NmFrameworkAdapter::listMessages(
   298 int NmFrameworkAdapter::listMessages(
   289         const NmId& mailboxId,
   299         const NmId& mailboxId,
   312     if( maxAmountOfEnvelopes <= 0)
   322     if( maxAmountOfEnvelopes <= 0)
   313         {
   323         {
   314         return;
   324         return;
   315         }
   325         }
   316 
   326 
   317     int blockSize = nmListMessagesBlock;
   327     int blockSize = NmListMessagesBlock;
   318     int maxLimit = nmMaxItemsInMessageList;
   328     int maxLimit = NmMaxItemsInMessageList;
   319     if( maxAmountOfEnvelopes < nmMaxItemsInMessageList )
   329     if( maxAmountOfEnvelopes < NmMaxItemsInMessageList )
   320         {
   330         {
   321         maxLimit = maxAmountOfEnvelopes;
   331         maxLimit = maxAmountOfEnvelopes;
   322         if(maxAmountOfEnvelopes < nmListMessagesBlock)
   332         if(maxAmountOfEnvelopes < NmListMessagesBlock)
   323             {
   333             {
   324             blockSize = maxAmountOfEnvelopes;
   334             blockSize = maxAmountOfEnvelopes;
   325             }
   335             }
   326         }
   336         }
   327    
   337    
   385         CleanupStack::PopAndDestroy(folder);
   395         CleanupStack::PopAndDestroy(folder);
   386     }
   396     }
   387     CleanupStack::PopAndDestroy(currentMailbox);
   397     CleanupStack::PopAndDestroy(currentMailbox);
   388 }
   398 }
   389 
   399 
       
   400 /*! 
       
   401     Returns list of messages from the backend for specific mailbox and folder.
       
   402 
       
   403     \param mailboxId Id of the mailbox containing the folder.
       
   404     \param folderId Folder id.
       
   405     \param messageMetaDataList Reference to pointer list to receive the envelope objects,
       
   406      ownership is transferred.
       
   407 
       
   408     \return Error code.
       
   409  */
       
   410 int NmFrameworkAdapter::listMessages(
       
   411     const NmId &mailboxId,
       
   412     const NmId &folderId,
       
   413     QList<NmMessage*> &messageList,
       
   414     const int maxAmountOfMessages)
       
   415 {
       
   416     TRAPD(err, listMessagesL(mailboxId,folderId,messageList, maxAmountOfMessages));
       
   417     return err;
       
   418 }
       
   419 
       
   420 /*!
       
   421     Leaving version of list messages with NmMessageList input
       
   422  */
       
   423 void NmFrameworkAdapter::listMessagesL(
       
   424         const NmId &mailboxId,
       
   425         const NmId &folderId,
       
   426         QList<NmMessage*> &messageList,
       
   427         const int maxAmountOfEnvelopes)
       
   428 {
       
   429     CFSMailBox * currentMailbox(NULL);
       
   430     CFSMailFolder* folder(NULL);
       
   431 
       
   432     //If we are requesting 0 or less mails so we can return
       
   433     if( maxAmountOfEnvelopes <= 0)
       
   434         {
       
   435         return;
       
   436         }
       
   437 
       
   438     int blockSize = NmListMessagesBlock;
       
   439     int maxLimit = NmMaxItemsInMessageList;
       
   440     if( maxAmountOfEnvelopes < NmMaxItemsInMessageList )
       
   441         {
       
   442         maxLimit = maxAmountOfEnvelopes;
       
   443         if(maxAmountOfEnvelopes < NmListMessagesBlock)
       
   444             {
       
   445             blockSize = maxAmountOfEnvelopes;
       
   446             }
       
   447         }
       
   448    
       
   449 
       
   450     currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId);
       
   451     if (!currentMailbox) {
       
   452         User::Leave(KErrNotFound);
       
   453     }
       
   454     CleanupStack::PushL(currentMailbox);
       
   455     folder = mFSfw->GetFolderByUidL(currentMailbox->GetId(), TFSMailMsgId(folderId));
       
   456 
       
   457     if (folder) {
       
   458         CleanupStack::PushL(folder);
       
   459         // First prepare all the parameters
       
   460         // select message details to be listed
       
   461         TFSMailDetails details(EFSMsgDataEnvelope);
       
   462 
       
   463         // set sorting criteria
       
   464         TFSMailSortCriteria criteria;
       
   465         criteria.iField = EFSMailSortByDate;
       
   466         criteria.iOrder = EFSMailDescending;
       
   467         RArray<TFSMailSortCriteria> sorting;
       
   468         CleanupClosePushL(sorting);
       
   469         sorting.Append(criteria);
       
   470 
       
   471         TFSMailMsgId currentMessageId; // first call contains NULL id as begin id
       
   472         // get messages list from the backend
       
   473         MFSMailIterator* iterator(NULL);
       
   474 
       
   475         iterator = folder->ListMessagesL(details, sorting);
       
   476         if (iterator) {
       
   477             CleanupStack::PushL(iterator);
       
   478             RPointerArray<CFSMailMessage> messages;
       
   479             CleanupResetAndDestroy<CFSMailMessage>::PushL(messages);
       
   480 
       
   481             //Message list is fetched in blocks to prevent OOM in protocol plugin side
       
   482             bool moreMessagesToFollow(false);
       
   483             moreMessagesToFollow = iterator->NextL(
       
   484                 TFSMailMsgId(), blockSize, messages);
       
   485             for ( int i = blockSize;
       
   486                   i < maxLimit && moreMessagesToFollow ;
       
   487                   i += blockSize ) {
       
   488                 moreMessagesToFollow = iterator->NextL(
       
   489                     messages[i-1]->GetMessageId(), blockSize, messages);
       
   490                 
       
   491             }
       
   492 
       
   493             //Add all found emails to the result list
       
   494             for(TInt i=0; i<messages.Count(); i++) {
       
   495                 NmMessage* newMessage(NULL);
       
   496                 newMessage = messages[i]->GetNmMessage();
       
   497                 if (newMessage) {
       
   498 					//Add content of message
       
   499                     NmMessagePart *plainTextPart = newMessage->plainTextBodyPart();
       
   500                     if (plainTextPart) {
       
   501                         contentToMessagePart(mailboxId, folderId, newMessage->envelope().messageId(),
       
   502                                              *plainTextPart);
       
   503                     }
       
   504                     messageList.append(newMessage);
       
   505                 }
       
   506             }
       
   507             
       
   508             CleanupStack::PopAndDestroy( &messages );
       
   509             CleanupStack::Pop(iterator);
       
   510             delete iterator;
       
   511             iterator = NULL;
       
   512         }
       
   513         CleanupStack::PopAndDestroy(); // sorting
       
   514         CleanupStack::PopAndDestroy(folder);
       
   515     }
       
   516     CleanupStack::PopAndDestroy(currentMailbox);
       
   517 }
       
   518 
       
   519 /*!
       
   520     Starts an asynchronous search for messages with the given search strings.
       
   521     This is part of the public interface.
       
   522 
       
   523     \see NmFrameworkAdapter::searchL().
       
   524 
       
   525     \param mailboxId The mailbox to search from.
       
   526     \param searchStrings The strings to search.
       
   527 
       
   528     \return A possible error code.
       
   529 */
       
   530 int NmFrameworkAdapter::search(const NmId &mailboxId,
       
   531                                const QStringList &searchStrings)
       
   532 {
       
   533     if (!mSearchObserver) {
       
   534         mSearchObserver = new NmMailboxSearchObserver();
       
   535     }
       
   536 
       
   537     // Set connections for forwarding the signals emitted by the search
       
   538     // observer.
       
   539     connect(mSearchObserver, SIGNAL(matchFound(const NmId &)),
       
   540             this, SIGNAL(matchFound(const NmId &)), Qt::UniqueConnection);
       
   541     connect(mSearchObserver, SIGNAL(searchComplete()),
       
   542             this, SIGNAL(searchComplete()), Qt::UniqueConnection);
       
   543 
       
   544     TRAPD(err, searchL(mailboxId, QList<NmId>(), searchStrings, *mSearchObserver));
       
   545     return err;
       
   546 }
       
   547 
       
   548 
       
   549 /*!
       
   550     Cancels the search if one is ongoing.
       
   551 
       
   552     \param mailboxId The ID of the mailbox running the search.
       
   553 
       
   554     \return A possible error code.
       
   555 */
       
   556 int NmFrameworkAdapter::cancelSearch(const NmId &mailboxId)
       
   557 {
       
   558     // Get the mailbox with the given ID.
       
   559     CFSMailBox *mailbox(NULL);
       
   560     TRAPD(err, mailbox = mFSfw->GetMailBoxByUidL(mailboxId));
       
   561 
       
   562     if (err == KErrNone && mailbox) {
       
   563         mailbox->CancelSearch();
       
   564     }
       
   565 
       
   566     return err;
       
   567 }
       
   568 
       
   569 
       
   570 /*!
       
   571     Starts an asynchronous search for messages with the given search strings.
       
   572 
       
   573     \param mailboxId The mailbox to search from.
       
   574     \param folderIds (not used)
       
   575     \param searchStrings The strings to search. 
       
   576     \param searchObserver The observer which gets informed about the progress
       
   577                           of the search (match found, search complete etc.)
       
   578 */
       
   579 void NmFrameworkAdapter::searchL(const NmId &mailboxId,
       
   580                                  const QList<NmId> &folderIds,
       
   581                                  const QStringList &searchStrings,
       
   582                                  NmMailboxSearchObserver &searchObserver)
       
   583 {
       
   584     // CFSMailBox has no support for search using folder IDs.
       
   585     Q_UNUSED(folderIds); 
       
   586 
       
   587     // Get the mailbox with the given ID.
       
   588     CFSMailBox *mailbox(NULL);
       
   589     mailbox = mFSfw->GetMailBoxByUidL(mailboxId);
       
   590 
       
   591     if (mailbox) {
       
   592         RPointerArray<TDesC> strings;
       
   593         CleanupResetAndDestroy<TDesC>::PushL(strings);
       
   594 
       
   595         // Convert the search strings to HBufCs.
       
   596         foreach (QString string, searchStrings) {
       
   597             HBufC *buffer = NmConverter::qstringToHBufCLC(string);
       
   598             strings.AppendL(buffer);
       
   599             CleanupStack::Pop(buffer);
       
   600         }
       
   601 
       
   602         // Show results in ascending date/time order.
       
   603         TFSMailSortCriteria sortCriteria;
       
   604         sortCriteria.iField = EFSMailSortByDate;
       
   605         sortCriteria.iOrder = EFSMailAscending;
       
   606 
       
   607         // Start the search.
       
   608         mailbox->SearchL(strings, sortCriteria, searchObserver);
       
   609 
       
   610         // Clean up.
       
   611         strings.ResetAndDestroy();
       
   612         CleanupStack::Pop(&strings);
       
   613     }
       
   614 }
       
   615 
       
   616 
   390 /*!
   617 /*!
   391     Starts a message fetching operation.
   618     Starts a message fetching operation.
   392 
   619 
   393     \param mailboxId Id of the mailbox containing the folder.
   620     \param mailboxId Id of the mailbox containing the folder.
   394     \param folderId Id of the folder containing the message.
   621     \param folderId Id of the folder containing the message.
   395     \param messageId Id of the message to fetch.
   622     \param messageId Id of the message to fetch.
   396 
   623 
   397     \return An NmOperation object for the operation, ownership is transferred to caller
   624     \return An NmOperation object for the operation, ownership is transferred to caller
   398  */
   625  */
   399 NmOperation *NmFrameworkAdapter::fetchMessage(
   626 QPointer<NmOperation> NmFrameworkAdapter::fetchMessage(
   400     const NmId &mailboxId,
   627     const NmId &mailboxId,
   401     const NmId &folderId,
   628     const NmId &folderId,
   402     const NmId &messageId )
   629     const NmId &messageId )
   403 {
   630 {
   404     NmOperation *oper = new NmFwaMessageFetchingOperation(mailboxId, folderId, messageId, *mFSfw);
   631     NmOperation *oper = new NmFwaMessageFetchingOperation(mailboxId, folderId, messageId, *mFSfw);
   413     \param messageId Id of message containing the message parts
   640     \param messageId Id of message containing the message parts
   414     \param messagePartId id of message part
   641     \param messagePartId id of message part
   415 
   642 
   416     \return An NmOperation object for the operation, ownership is transferred to caller
   643     \return An NmOperation object for the operation, ownership is transferred to caller
   417  */
   644  */
   418 NmOperation *NmFrameworkAdapter::fetchMessagePart( 
   645 QPointer<NmOperation> NmFrameworkAdapter::fetchMessagePart( 
   419     const NmId &mailboxId,
   646     const NmId &mailboxId,
   420     const NmId &folderId,
   647     const NmId &folderId,
   421     const NmId &messageId,
   648     const NmId &messageId,
   422     const NmId &messagePartId)
   649     const NmId &messagePartId)
   423 {
   650 {
   424     NmOperation *oper = new NmFwaMessagePartFetchingOperation(
   651     QPointer<NmOperation> oper = new NmFwaMessagePartFetchingOperation(
   425             mailboxId, folderId, messageId, messagePartId, *mFSfw);
   652             mailboxId, folderId, messageId, messagePartId, *mFSfw);
   426     return oper;
   653     return oper;
   427 }
   654 }
   428 
   655 
   429 /*!
   656 /*!
   623                     charset = rxlen.cap(1);
   850                     charset = rxlen.cap(1);
   624                 }
   851                 }
   625                 QByteArray msgBytes = QByteArray(reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize);
   852                 QByteArray msgBytes = QByteArray(reinterpret_cast<const char*>(dataPtr.Ptr()), fileSize);
   626                 QTextCodec *codec = QTextCodec::codecForName(charset.toAscii());
   853                 QTextCodec *codec = QTextCodec::codecForName(charset.toAscii());
   627                 if (!codec) {
   854                 if (!codec) {
   628                     codec = QTextCodec::codecForName("iso-8859-1");
   855                     codec = QTextCodec::codecForName("UTF-8");
   629                 }
   856                 }
   630                 QString encodedStr = codec->toUnicode(msgBytes); 
   857                 QString encodedStr = codec->toUnicode(msgBytes); 
   631                 messagePart.setTextContent(encodedStr, contentType);           
   858                 messagePart.setTextContent(encodedStr, contentType);           
   632             }
   859             }
   633             else {
   860             else {
   683     \param folderId Unused.
   910     \param folderId Unused.
   684     \param envelopeList List of the envelope objects to store.
   911     \param envelopeList List of the envelope objects to store.
   685 
   912 
   686     \return NmStoreEnvelopesOperation
   913     \return NmStoreEnvelopesOperation
   687  */
   914  */
   688 NmStoreEnvelopesOperation *NmFrameworkAdapter::storeEnvelopes(
   915 QPointer<NmStoreEnvelopesOperation> NmFrameworkAdapter::storeEnvelopes(
   689 	const NmId &mailboxId,
   916 	const NmId &mailboxId,
   690 	const NmId &folderId,
   917 	const NmId &folderId,
   691 	const QList<const NmMessageEnvelope*> &envelopeList)
   918 	const QList<const NmMessageEnvelope*> &envelopeList)
   692 {
   919 {
   693     Q_UNUSED(folderId);
   920     Q_UNUSED(folderId);
   694     NMLOG("NmFrameworkAdapter::storeEnvelopes() <---");
   921     NMLOG("NmFrameworkAdapter::storeEnvelopes() <---");
   695 
   922 
   696     NmStoreEnvelopesOperation* operation(NULL);
   923     QPointer<NmStoreEnvelopesOperation> operation(NULL);
   697     RPointerArray<CFSMailMessage> envelopeMessages;
   924     RPointerArray<CFSMailMessage> envelopeMessages;
   698 
   925 
   699     int count = envelopeList.count();
   926     int count = envelopeList.count();
   700     for(int i=0;i<count;i++) {
   927     for(int i(0); i < count; i++) {
   701         TRAP_IGNORE( envelopeMessages.AppendL(mailMessageFromEnvelopeL( *envelopeList.at(i)) ));
   928         TRAP_IGNORE(envelopeMessages.AppendL(mailMessageFromEnvelopeL(*envelopeList.at(i))));
   702     }
   929     }
   703 
   930 
   704     if ( envelopeMessages.Count() ) {
   931     if (envelopeMessages.Count()) {
   705         operation = new NmFwaStoreEnvelopesOperation(
   932         operation = new NmFwaStoreEnvelopesOperation(
   706                 mailboxId,
   933                 mailboxId,
   707                 envelopeMessages,
   934                 envelopeMessages,
   708                 *mFSfw);
   935                 *mFSfw);
   709         }
   936         }
   717 
   944 
   718     \param mailboxId Id of the mailbox.
   945     \param mailboxId Id of the mailbox.
   719 
   946 
   720     \return NmMessageCreationOperation
   947     \return NmMessageCreationOperation
   721  */
   948  */
   722 NmMessageCreationOperation *NmFrameworkAdapter::createNewMessage(const NmId &mailboxId)
   949 QPointer<NmMessageCreationOperation> NmFrameworkAdapter::createNewMessage(const NmId &mailboxId)
   723 {
   950 {
   724     NmMessageCreationOperation *oper =
   951     QPointer<NmMessageCreationOperation> oper =
   725         new NmFwaMessageCreationOperation(mailboxId, *mFSfw);
   952         new NmFwaMessageCreationOperation(mailboxId, *mFSfw);
   726     return oper;
   953     return oper;
   727 }
   954 }
   728 
   955 
   729 /*!
   956 /*!
   732     \param mailboxId Id of the mailbox.
   959     \param mailboxId Id of the mailbox.
   733     \param originalMessageId Id of the original message. Original message must be in the given mailbox.
   960     \param originalMessageId Id of the original message. Original message must be in the given mailbox.
   734 
   961 
   735     \return NmMessageCreationOperation
   962     \return NmMessageCreationOperation
   736  */
   963  */
   737 NmMessageCreationOperation *NmFrameworkAdapter::createForwardMessage(
   964 QPointer<NmMessageCreationOperation> NmFrameworkAdapter::createForwardMessage(
   738     const NmId &mailboxId,
   965     const NmId &mailboxId,
   739     const NmId &originalMessageId)
   966     const NmId &originalMessageId)
   740 {
   967 {
   741     NmMessageCreationOperation *oper =
   968     QPointer<NmMessageCreationOperation> oper =
   742         new NmFwaForwardMessageCreationOperation(mailboxId, originalMessageId, *mFSfw);
   969         new NmFwaForwardMessageCreationOperation(mailboxId, originalMessageId, *mFSfw);
   743     return oper;
   970     return oper;
   744 }
   971 }
   745 
   972 
   746 /*!
   973 /*!
   750     \param originalMessageId Id of the original message. Original message must be in the given mailbox.
   977     \param originalMessageId Id of the original message. Original message must be in the given mailbox.
   751     \param replyAll Is reply for all recipients?
   978     \param replyAll Is reply for all recipients?
   752 
   979 
   753     \return NmMessageCreationOperation
   980     \return NmMessageCreationOperation
   754  */
   981  */
   755 NmMessageCreationOperation *NmFrameworkAdapter::createReplyMessage(
   982 QPointer<NmMessageCreationOperation> NmFrameworkAdapter::createReplyMessage(
   756     const NmId &mailboxId,
   983     const NmId &mailboxId,
   757     const NmId &originalMessageId,
   984     const NmId &originalMessageId,
   758     const bool replyAll)
   985     const bool replyAll)
   759 {
   986 {
   760     NmMessageCreationOperation *oper =
   987     QPointer<NmMessageCreationOperation> oper =
   761         new NmFwaReplyMessageCreationOperation(mailboxId, originalMessageId, replyAll, *mFSfw);
   988         new NmFwaReplyMessageCreationOperation(mailboxId, originalMessageId, replyAll, *mFSfw);
   762     return oper;
   989     return oper;
   763 }
   990 }
   764 
   991 
   765 /*!
   992 /*!
   772 }
   999 }
   773 
  1000 
   774 /*!
  1001 /*!
   775     Store asynchronously message with its parts.
  1002     Store asynchronously message with its parts.
   776  */
  1003  */
   777 NmOperation* NmFrameworkAdapter::saveMessageWithSubparts(const NmMessage &message)
  1004 QPointer<NmOperation> NmFrameworkAdapter::saveMessageWithSubparts(const NmMessage &message)
   778 {
  1005 {
   779     CFSMailMessage * cfsMessage = NULL;
  1006     CFSMailMessage * cfsMessage = NULL;
   780     NmOperation *oper = NULL;
  1007     QPointer<NmOperation> oper(NULL);
   781 
  1008 
   782     int err = KErrNone;
  1009     int err = KErrNone;
   783     TRAP(err, cfsMessage = CFSMailMessage::NewL(message));
  1010     TRAP(err, cfsMessage = CFSMailMessage::NewL(message));
   784     if (err == KErrNone) {
  1011     if (err == KErrNone) {
   785         //transfers ownership of cfsMessage
  1012         //transfers ownership of cfsMessage
   872             handleSyncstateEvent(param1, mailbox);
  1099             handleSyncstateEvent(param1, mailbox);
   873             break;
  1100             break;
   874 
  1101 
   875         case TFSEventMailboxOnline:{
  1102         case TFSEventMailboxOnline:{
   876             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1103             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
   877             emit connectionEvent(Connected, id);
  1104             emit connectionEvent(Connected, id, NmNoError);
   878             }
  1105             }
   879             break;
  1106             break;
   880         case TFSEventMailboxOffline:{
  1107             
       
  1108         // param1: errorcode
       
  1109         case TFSEventMailboxOffline: {
   881             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1110             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
   882             emit connectionEvent(Disconnected, id);
  1111             TInt error(KErrNone);
   883             }
  1112             // if param1 is set, and it is != KErrNone, an unexpected offline event has occurred
       
  1113             if(param1) {
       
  1114                 error=*(static_cast<TInt*>(param1));
       
  1115             }
       
  1116             if(error) {
       
  1117                 emit connectionEvent(Disconnected, id, NmConnectionError);
       
  1118             }
       
  1119             else {
       
  1120                 emit connectionEvent(Disconnected, id, NmNoError);
       
  1121             }
       
  1122 			}
   884             break;
  1123             break;
   885 
  1124 
   886         default:
  1125         default:
   887             break;
  1126             break;
   888     }
  1127     }
   962 
  1201 
   963 
  1202 
   964 /*!
  1203 /*!
   965    Sends the given message.
  1204    Sends the given message.
   966  */
  1205  */
   967 NmMessageSendingOperation *NmFrameworkAdapter::sendMessage(
  1206 QPointer<NmMessageSendingOperation> NmFrameworkAdapter::sendMessage(
   968     NmMessage *message)
  1207     NmMessage *message)
   969 {
  1208 {
   970     NmMessageSendingOperation *oper = new NmFwaMessageSendingOperation(*this, message, *mFSfw);
  1209     QPointer<NmMessageSendingOperation>oper = new NmFwaMessageSendingOperation(*this, message, *mFSfw);
   971 	return oper;
  1210 	return oper;
   972 }
  1211 }
   973 
  1212 
   974 /*!
  1213 /*!
   975    Add attachment into the given message.
  1214    Add attachment into the given message.
   976  */
  1215  */
   977 NmAddAttachmentsOperation *NmFrameworkAdapter::addAttachments(
  1216 QPointer<NmAddAttachmentsOperation> NmFrameworkAdapter::addAttachments(
   978     const NmMessage &message,
  1217     const NmMessage &message,
   979     const QList<QString> &fileList)
  1218     const QList<QString> &fileList)
   980 {
  1219 {
   981     NmAddAttachmentsOperation *oper = new NmFwaAddAttachmentsOperation(message, fileList, *mFSfw);
  1220     QPointer<NmAddAttachmentsOperation>oper = new NmFwaAddAttachmentsOperation(message, fileList, *mFSfw);
   982     return oper;
  1221     return oper;
   983 }
  1222 }
   984 
  1223 
   985 /*!
  1224 /*!
   986    Remove attachment from the given message.
  1225    Remove attachment from the given message.
   987  */
  1226  */
   988 NmOperation *NmFrameworkAdapter::removeAttachment(
  1227 QPointer<NmOperation> NmFrameworkAdapter::removeAttachment(
   989     const NmMessage &message,
  1228     const NmMessage &message,
   990     const NmId &attachmentPartId)
  1229     const NmId &attachmentPartId)
   991 {
  1230 {
   992     NmOperation *oper = new NmFwaRemoveAttachmentOperation(message, attachmentPartId, *mFSfw);
  1231     QPointer<NmOperation> oper = new NmFwaRemoveAttachmentOperation(message, attachmentPartId, *mFSfw);
   993     return oper;
  1232     return oper;
   994 }
  1233 }
   995 
  1234 
   996 /*!
  1235 /*!
   997    Checks outbox for messages
  1236    Checks outbox for messages
   998  */
  1237  */
   999 NmCheckOutboxOperation *NmFrameworkAdapter::checkOutbox(const NmId& mailboxId)
  1238 QPointer<NmCheckOutboxOperation> NmFrameworkAdapter::checkOutbox(const NmId& mailboxId)
  1000 {
  1239 {
  1001     NmCheckOutboxOperation *oper =
  1240     QPointer<NmCheckOutboxOperation> oper =
  1002         new NmFwaCheckOutboxOperation(mailboxId, *mFSfw);
  1241         new NmFwaCheckOutboxOperation(mailboxId, *mFSfw);
  1003 
  1242 
  1004     return oper;
  1243     return oper;
  1005 }
  1244 }
  1006 
  1245 
  1228 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox)
  1467 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox)
  1229 {
  1468 {
  1230     TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 );
  1469     TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 );
  1231     NmOperationCompletionEvent event;
  1470     NmOperationCompletionEvent event;
  1232     event.mMailboxId = NmConverter::mailMsgIdToNmId(mailbox);
  1471     event.mMailboxId = NmConverter::mailMsgIdToNmId(mailbox);
       
  1472     event.mOperationType = Synch;
  1233 
  1473 
  1234     switch(*state)
  1474     switch(*state)
  1235         {
  1475         {
  1236         case StartingSync:
  1476         case StartingSync:
  1237             {
  1477             {
  1249             {
  1489             {
  1250             event.mCompletionCode = NmAuthenticationError;
  1490             event.mCompletionCode = NmAuthenticationError;
  1251             emit syncStateEvent(SyncComplete, event);
  1491             emit syncStateEvent(SyncComplete, event);
  1252             break;
  1492             break;
  1253             }
  1493             }
  1254         case SyncError:
  1494         case SyncCancelled:
  1255         default:
  1495             {
       
  1496             event.mCompletionCode = NmCancelError;
       
  1497             emit syncStateEvent(SyncComplete, event);
       
  1498             break;
       
  1499             }
       
  1500         case ServerConnectionError:
  1256             {
  1501             {
  1257             event.mCompletionCode = NmServerConnectionError;
  1502             event.mCompletionCode = NmServerConnectionError;
  1258             emit syncStateEvent(SyncComplete, event);
  1503             emit syncStateEvent(SyncComplete, event);
  1259             break;
  1504             break;
  1260             }
  1505             }
       
  1506         case SyncError:
       
  1507             {
       
  1508             event.mCompletionCode = NmConnectionError;
       
  1509             emit syncStateEvent(SyncComplete, event);
       
  1510             break;
       
  1511             }
       
  1512         default:
       
  1513             // ignore other statuses
       
  1514             break;
  1261         };
  1515         };
  1262 }
  1516 }
  1263 Q_EXPORT_PLUGIN(NmFrameworkAdapter)
  1517 Q_EXPORT_PLUGIN(NmFrameworkAdapter)
  1264 
  1518