emailuis/nmframeworkadapter/src/nmframeworkadapter.cpp
changeset 68 83cc6bae1de8
parent 66 084b5b1f02a7
child 74 6c59112cfd31
equal deleted inserted replaced
67:459da34cdb45 68:83cc6bae1de8
    41   mSearchObserver(NULL),
    41   mSearchObserver(NULL),
    42   mCurrentMailBox(NULL),
    42   mCurrentMailBox(NULL),
    43   mStateExtension(NULL)
    43   mStateExtension(NULL)
    44 {
    44 {
    45     NM_FUNCTION;
    45     NM_FUNCTION;
    46     
    46 
    47     // get s60 email framework
    47     // get s60 email framework
    48     TRAP_IGNORE(mFSfw = CFSMailClient::NewL());
    48     TRAP_IGNORE(mFSfw = CFSMailClient::NewL());
    49 
    49 
    50     if (mFSfw) {
    50     if (mFSfw) {
    51         TRAP_IGNORE(mFSfw->AddObserverL(*this));
    51         TRAP_IGNORE(mFSfw->AddObserverL(*this));
    56     Destructor
    56     Destructor
    57 */
    57 */
    58 NmFrameworkAdapter::~NmFrameworkAdapter()
    58 NmFrameworkAdapter::~NmFrameworkAdapter()
    59 {
    59 {
    60     NM_FUNCTION;
    60     NM_FUNCTION;
    61     
    61 
    62     delete mCurrentMailBox;
    62     delete mCurrentMailBox;
    63     mCurrentMailBox = NULL;
    63     mCurrentMailBox = NULL;
    64     
    64 
    65     mStateExtension = NULL;    
    65     mStateExtension = NULL;
    66     
    66 
    67     if (mSearchObserver) {
    67     if (mSearchObserver) {
    68         delete mSearchObserver;
    68         delete mSearchObserver;
    69         mSearchObserver = NULL;
    69         mSearchObserver = NULL;
    70     }
    70     }
    71 
    71 
    85     \return Error code.
    85     \return Error code.
    86  */
    86  */
    87 int NmFrameworkAdapter::listMailboxIds(QList<NmId>& mailboxIdList)
    87 int NmFrameworkAdapter::listMailboxIds(QList<NmId>& mailboxIdList)
    88 {
    88 {
    89     NM_FUNCTION;
    89     NM_FUNCTION;
    90     
    90 
    91     QList<NmMailbox*> mailboxList;
    91     QList<NmMailbox*> mailboxList;
    92     int ret = listMailboxes(mailboxList);
    92     int ret = listMailboxes(mailboxList);
    93 
    93 
    94     if (ret == NmNoError) {
    94     if (ret == NmNoError) {
    95         QListIterator<NmMailbox*> iterator(mailboxList);
    95         QListIterator<NmMailbox*> iterator(mailboxList);
   149     \return Error code.
   149     \return Error code.
   150  */
   150  */
   151 int NmFrameworkAdapter::getMailboxById(const NmId& id, NmMailbox*& mailbox)
   151 int NmFrameworkAdapter::getMailboxById(const NmId& id, NmMailbox*& mailbox)
   152 {
   152 {
   153     NM_FUNCTION;
   153     NM_FUNCTION;
   154     
   154 
   155     const TFSMailMsgId mailMsgId(id.pluginId32(), id.id32());
   155     const TFSMailMsgId mailMsgId(id.pluginId32(), id.id32());
   156     CFSMailBox *box(NULL);
   156     CFSMailBox *box(NULL);
   157     TRAPD(err, box = mFSfw->GetMailBoxByUidL(mailMsgId));
   157     TRAPD(err, box = mFSfw->GetMailBoxByUidL(mailMsgId));
   158     if (err == KErrNone && box) {
   158     if (err == KErrNone && box) {
   159         mailbox = box->GetNmMailbox();
   159         mailbox = box->GetNmMailbox();
   171     \return Error code.
   171     \return Error code.
   172  */
   172  */
   173 QPointer<NmOperation> NmFrameworkAdapter::deleteMailboxById(const NmId& mailboxId)
   173 QPointer<NmOperation> NmFrameworkAdapter::deleteMailboxById(const NmId& mailboxId)
   174 {
   174 {
   175     NM_FUNCTION;
   175     NM_FUNCTION;
       
   176 
       
   177     resetCache(mailboxId);
       
   178 
   176     QPointer<NmOperation> oper = new NmFwaDeleteMailboxOperation(mailboxId, *mFSfw);
   179     QPointer<NmOperation> oper = new NmFwaDeleteMailboxOperation(mailboxId, *mFSfw);
   177     return oper;
   180     return oper;
   178 }
   181 }
   179 
   182 
   180 /*!
   183 /*!
   281     const NmId& mailboxId,
   284     const NmId& mailboxId,
   282     QList<NmFolder*>& folderList)
   285     QList<NmFolder*>& folderList)
   283 {
   286 {
   284     NM_FUNCTION;
   287     NM_FUNCTION;
   285     int err(NmNoError);
   288     int err(NmNoError);
   286     CFSMailBox* currentMailbox(NULL); 
   289     CFSMailBox* currentMailbox(NULL);
   287     TRAP(err, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId));
   290     TRAP(err, currentMailbox = mFSfw->GetMailBoxByUidL(mailboxId));
   288     if (KErrNone == err && currentMailbox) {
   291     if (KErrNone == err && currentMailbox) {
   289         RPointerArray<CFSMailFolder> folders = currentMailbox->ListFolders();
   292         RPointerArray<CFSMailFolder> folders = currentMailbox->ListFolders();
   290         for (int i = 0; i < folders.Count(); i++) {
   293         for (int i = 0; i < folders.Count(); i++) {
   291             folderList.append(folders[i]->GetNmFolder());
   294             folderList.append(folders[i]->GetNmFolder());
   662    Removes draft message asynchronously
   665    Removes draft message asynchronously
   663  */
   666  */
   664 QPointer<NmOperation> NmFrameworkAdapter::removeDraftMessage(NmMessage *message)
   667 QPointer<NmOperation> NmFrameworkAdapter::removeDraftMessage(NmMessage *message)
   665 {
   668 {
   666     NM_FUNCTION;
   669     NM_FUNCTION;
   667     
   670 
   668     QPointer<NmOperation> oper = new NmFwaRemoveDraftMessageOperation(*this, message, *mFSfw);
   671     QPointer<NmOperation> oper = new NmFwaRemoveDraftMessageOperation(*this, message, *mFSfw);
   669     return oper;
   672     return oper;
   670 }
   673 }
   671 
   674 
   672 /*!
   675 /*!
   875 NmId NmFrameworkAdapter::getStandardFolderId(
   878 NmId NmFrameworkAdapter::getStandardFolderId(
   876     const NmId& mailboxId,
   879     const NmId& mailboxId,
   877     NmFolderType folderType )
   880     NmFolderType folderType )
   878 {
   881 {
   879     NM_FUNCTION;
   882     NM_FUNCTION;
       
   883 
       
   884 	// Use cached inbox ID when available
       
   885     if (folderType==NmFolderInbox &&
       
   886         mailboxId==mCachedMailboxId &&
       
   887         mCachedInboxId!=0) {
       
   888         return mCachedInboxId;
       
   889     }
   880 
   890 
   881     TFSMailMsgId folderId;
   891     TFSMailMsgId folderId;
   882     NmId resultId(0);
   892     NmId resultId(0);
   883     CFSMailBox* currentMailbox(NULL);
   893     CFSMailBox* currentMailbox(NULL);
   884 
   894 
   914     currentMailbox = NULL;
   924     currentMailbox = NULL;
   915 
   925 
   916     resultId.setPluginId32(static_cast<quint32>(folderId.PluginId().iUid));
   926     resultId.setPluginId32(static_cast<quint32>(folderId.PluginId().iUid));
   917     resultId.setId32(folderId.Id());
   927     resultId.setId32(folderId.Id());
   918 
   928 
       
   929     // Store cached inbox ID
       
   930     if (folderType==NmFolderInbox) {
       
   931         mCachedMailboxId = mailboxId;
       
   932         mCachedInboxId = resultId;
       
   933     }
       
   934 
   919     return resultId;
   935     return resultId;
       
   936 }
       
   937 
       
   938 /*!
       
   939     Reset cache for the specific mailbox
       
   940 
       
   941     \param mailboxId id of the mailbox that cache will be reseted
       
   942 */
       
   943 void NmFrameworkAdapter::resetCache(const NmId &mailboxId)
       
   944 {
       
   945 	if (mailboxId==mCachedMailboxId) {
       
   946         mCachedMailboxId=0;
       
   947         mCachedInboxId=0;
       
   948 	}
   920 }
   949 }
   921 
   950 
   922 /*!
   951 /*!
   923     Connect to mailbox if not already connected and refresh.
   952     Connect to mailbox if not already connected and refresh.
   924 
   953 
   926     \return Async request id or error code.
   955     \return Async request id or error code.
   927  */
   956  */
   928 int NmFrameworkAdapter::refreshMailbox(NmId mailboxId)
   957 int NmFrameworkAdapter::refreshMailbox(NmId mailboxId)
   929 {
   958 {
   930     NM_FUNCTION;
   959     NM_FUNCTION;
   931     
   960 
       
   961     resetCache(mailboxId);
       
   962 
   932     TRAPD(err, RefreshMailboxL(mailboxId)); // return value not used
   963     TRAPD(err, RefreshMailboxL(mailboxId)); // return value not used
   933     return (err == KErrNone) ? NmNoError : NmGeneralError;
   964     return (err == KErrNone) ? NmNoError : NmGeneralError;
   934 }
   965 }
   935 
   966 
   936 /*!
   967 /*!
   940     \return Async request id or error code.
   971     \return Async request id or error code.
   941  */
   972  */
   942 int NmFrameworkAdapter::goOnline(const NmId& mailboxId)
   973 int NmFrameworkAdapter::goOnline(const NmId& mailboxId)
   943 {
   974 {
   944     NM_FUNCTION;
   975     NM_FUNCTION;
   945     
   976 
   946     TRAPD(err, GoOnlineL(mailboxId)); // return value not used
   977     TRAPD(err, GoOnlineL(mailboxId)); // return value not used
   947     return (err == KErrNone) ? NmNoError : NmGeneralError;
   978     return (err == KErrNone) ? NmNoError : NmGeneralError;
   948 }
   979 }
   949 
   980 
   950 /*!
   981 /*!
   954     \return Async request id or error code.
   985     \return Async request id or error code.
   955  */
   986  */
   956 int NmFrameworkAdapter::goOffline(const NmId& mailboxId)
   987 int NmFrameworkAdapter::goOffline(const NmId& mailboxId)
   957 {
   988 {
   958     NM_FUNCTION;
   989     NM_FUNCTION;
   959     
   990 
   960     TRAPD(err, GoOfflineL(mailboxId)); // return value not used
   991     TRAPD(err, GoOfflineL(mailboxId)); // return value not used
   961     return (err == KErrNone) ? NmNoError : NmGeneralError;
   992     return (err == KErrNone) ? NmNoError : NmGeneralError;
   962 }
   993 }
   963 
   994 
   964 /*!
   995 /*!
  1220     switch (aEvent) {
  1251     switch (aEvent) {
  1221         case TFSEventMailboxSettingsChanged:
  1252         case TFSEventMailboxSettingsChanged:
  1222             break;
  1253             break;
  1223 
  1254 
  1224         // Folder related events:
  1255         // Folder related events:
  1225         case TFSEventFoldersDeleted:                 
  1256         case TFSEventFoldersDeleted:
  1226             handleFoldersEvent(param1, param2, NmFolderIsDeleted, mailbox);
  1257             handleFoldersEvent(param1, param2, NmFolderIsDeleted, mailbox);
  1227             break;
  1258             break;
  1228         case TFSEventNewFolder:
  1259         case TFSEventNewFolder:
  1229             handleFoldersEvent(param1, param2, NmFolderIsCreated, mailbox);            
  1260             handleFoldersEvent(param1, param2, NmFolderIsCreated, mailbox);
  1230             break;
  1261             break;
  1231 
  1262 
  1232         // Mailbox related events:
  1263         // Mailbox related events:
  1233         case TFSEventNewMailbox:
  1264         case TFSEventNewMailbox:
  1234             handleMailboxEvent(mailbox, NmMailboxCreated);
  1265             handleMailboxEvent(mailbox, NmMailboxCreated);
  1303         case TFSEventMailboxOnline:{
  1334         case TFSEventMailboxOnline:{
  1304             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1335             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1305             emit connectionEvent(Connected, id, NmNoError);
  1336             emit connectionEvent(Connected, id, NmNoError);
  1306             }
  1337             }
  1307             break;
  1338             break;
  1308             
  1339 
  1309         // param1: errorcode
  1340         // param1: errorcode
  1310         case TFSEventMailboxOffline: {
  1341         case TFSEventMailboxOffline: {
  1311             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1342             NmId id = NmConverter::mailMsgIdToNmId(mailbox);
  1312             TInt error(KErrNone);
  1343             TInt error(KErrNone);
  1313             // if param1 is set, and it is != KErrNone, an unexpected offline event has occurred
  1344             // if param1 is set, and it is != KErrNone, an unexpected offline event has occurred
  1375 */
  1406 */
  1376 int NmFrameworkAdapter::getSignature(const NmId &mailboxId, QString *&signature)
  1407 int NmFrameworkAdapter::getSignature(const NmId &mailboxId, QString *&signature)
  1377 {
  1408 {
  1378     NM_FUNCTION;
  1409     NM_FUNCTION;
  1379     TRAPD(error, getSignatureL(mailboxId, signature));
  1410     TRAPD(error, getSignatureL(mailboxId, signature));
  1380     
  1411 
  1381     return error;
  1412     return error;
  1382 }
  1413 }
  1383 
  1414 
  1384 /*!
  1415 /*!
  1385     Subscribe to events from a mailbox.
  1416     Subscribe to events from a mailbox.
  1387     \param mailboxId Id of the mailbox.
  1418     \param mailboxId Id of the mailbox.
  1388 */
  1419 */
  1389 void NmFrameworkAdapter::subscribeMailboxEvents(const NmId& mailboxId)
  1420 void NmFrameworkAdapter::subscribeMailboxEvents(const NmId& mailboxId)
  1390 {
  1421 {
  1391     NM_FUNCTION;
  1422     NM_FUNCTION;
  1392     
  1423 
  1393     TRAP_IGNORE(mFSfw->SubscribeMailboxEventsL(mailboxId, *this));
  1424     TRAP_IGNORE(mFSfw->SubscribeMailboxEventsL(mailboxId, *this));
  1394 }
  1425 }
  1395 
  1426 
  1396 /*!
  1427 /*!
  1397     Unsubscribe to events from a mailbox.
  1428     Unsubscribe to events from a mailbox.
  1399     \param mailboxId Id of the mailbox.
  1430     \param mailboxId Id of the mailbox.
  1400 */
  1431 */
  1401 void NmFrameworkAdapter::unsubscribeMailboxEvents(const NmId& mailboxId)
  1432 void NmFrameworkAdapter::unsubscribeMailboxEvents(const NmId& mailboxId)
  1402 {
  1433 {
  1403     NM_FUNCTION;
  1434     NM_FUNCTION;
  1404     
  1435 
  1405     mFSfw->UnsubscribeMailboxEvents(mailboxId, *this);
  1436     mFSfw->UnsubscribeMailboxEvents(mailboxId, *this);
  1406 }
  1437 }
  1407 
  1438 
  1408 
  1439 
  1409 /*!
  1440 /*!
  1467     Leaving version of getSignature
  1498     Leaving version of getSignature
  1468 */
  1499 */
  1469 void NmFrameworkAdapter::getSignatureL(const NmId &mailboxId, QString *&signature)
  1500 void NmFrameworkAdapter::getSignatureL(const NmId &mailboxId, QString *&signature)
  1470 {
  1501 {
  1471     NM_FUNCTION;
  1502     NM_FUNCTION;
  1472     
  1503 
  1473     HBufC *sig = mFSfw->GetSignatureL(TFSMailMsgId(mailboxId));
  1504     HBufC *sig = mFSfw->GetSignatureL(TFSMailMsgId(mailboxId));
  1474 
  1505 
  1475     if (sig) {
  1506     if (sig) {
  1476         signature = new QString(NmConverter::toQString(*sig));
  1507         signature = new QString(NmConverter::toQString(*sig));
  1477     }
  1508     }
  1754 }
  1785 }
  1755 
  1786 
  1756 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox)
  1787 void NmFrameworkAdapter::handleSyncstateEvent(TAny* param1, TFSMailMsgId mailbox)
  1757 {
  1788 {
  1758     NM_FUNCTION;
  1789     NM_FUNCTION;
  1759     
  1790 
  1760     TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 );
  1791     TSSMailSyncState* state = static_cast<TSSMailSyncState*>( param1 );
  1761     NmOperationCompletionEvent event;
  1792     NmOperationCompletionEvent event;
  1762     event.mMailboxId = NmConverter::mailMsgIdToNmId(mailbox);
  1793     event.mMailboxId = NmConverter::mailMsgIdToNmId(mailbox);
  1763     event.mOperationType = Synch;
  1794     event.mOperationType = Synch;
  1764 
  1795 
  1765     switch(*state)
  1796     switch(*state)
  1766         {
  1797         {
  1767         case StartingSync:
  1798         case StartingSync:
  1768             {
  1799             {
       
  1800             NM_TIMESTAMP("Sync started.");
  1769             event.mCompletionCode = NmNoError;
  1801             event.mCompletionCode = NmNoError;
  1770             emit syncStateEvent(Synchronizing, event);
  1802             emit syncStateEvent(Synchronizing, event);
  1771             break;
  1803             break;
  1772             }
  1804             }
  1773         case FinishedSuccessfully:
  1805         case FinishedSuccessfully:
  1774             {
  1806             {
       
  1807             NM_TIMESTAMP("Sync completed successfully.");
  1775             event.mCompletionCode = NmNoError;
  1808             event.mCompletionCode = NmNoError;
  1776             emit syncStateEvent(SyncComplete, event);
  1809             emit syncStateEvent(SyncComplete, event);
  1777             break;
  1810             break;
  1778             }
  1811             }
  1779         case PasswordNotVerified:
  1812         case PasswordNotVerified:
  1811  */
  1844  */
  1812 void NmFrameworkAdapter::handleFoldersEvent(
  1845 void NmFrameworkAdapter::handleFoldersEvent(
  1813     TAny* param1, TAny* param2, NmFolderEvent event, TFSMailMsgId mailbox)
  1846     TAny* param1, TAny* param2, NmFolderEvent event, TFSMailMsgId mailbox)
  1814 {
  1847 {
  1815     NM_FUNCTION;
  1848     NM_FUNCTION;
       
  1849     
       
  1850     Q_UNUSED(param2);
  1816 
  1851 
  1817     // aParam1: RArray<TFSMailMsgId>* aEntries
  1852     // aParam1: RArray<TFSMailMsgId>* aEntries
  1818     // aParam2: TFSMailMsgId* aParentFolder
  1853     // aParam2: TFSMailMsgId* aParentFolder
  1819     // aParam3: NULL      
  1854     // aParam3: NULL
  1820 
  1855 
  1821     NmId mailboxId(0);
  1856     NmId mailboxId(0);
  1822     mailboxId = mailbox.GetNmId();
  1857     mailboxId = mailbox.GetNmId();
  1823 
  1858 
  1824     NmId nmMsgId(0);
  1859     NmId nmMsgId(0);
  1825     QList<NmId> folderIds;    
  1860     QList<NmId> folderIds;
  1826 
  1861 
       
  1862     resetCache(mailboxId);
       
  1863     
  1827     RArray<TFSMailMsgId>* fsEntries = reinterpret_cast<RArray<TFSMailMsgId>*> (param1);
  1864     RArray<TFSMailMsgId>* fsEntries = reinterpret_cast<RArray<TFSMailMsgId>*> (param1);
  1828     TFSMailMsgId* fsFolderId = reinterpret_cast<TFSMailMsgId*> (param2);
  1865     NmId folderId(0);
  1829     NmId folderId = fsFolderId->GetNmId();
       
  1830     NmId inputFolderId = NmFrameworkAdapter::getStandardFolderId(mailboxId, NmFolderInbox);
       
  1831 
  1866 
  1832     TFSMailMsgId fsMsgId;
  1867     TFSMailMsgId fsMsgId;
  1833     for(TInt i = 0; i < fsEntries->Count(); i++){
  1868     for(TInt i = 0; i < fsEntries->Count(); i++){
  1834         fsMsgId = (*fsEntries)[i];
  1869         fsMsgId = (*fsEntries)[i];
  1835         folderId = fsMsgId.GetNmId();
  1870         folderId = fsMsgId.GetNmId();