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(); |
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()); |
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 /*! |
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 |
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(); |