00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CMessageSummaryEngine.h"
00018 #include <miutset.h>
00019 #include "summaryscreenlog.h"
00020
00021 const CMessageSummaryGenerator& CMessageSummaryEngine::SmsSummary()
00022 {
00023 return *iSmsInboxSummary;
00024 }
00025
00026 const CMessageSummaryGenerator* CMessageSummaryEngine::EmailSummary()
00027 {
00028 return iEmailInboxSummary;
00029 }
00030
00031
00032 CMessageSummaryEngine* CMessageSummaryEngine::NewL(MSummaryEngineObserver& aObserver)
00033 {
00034 CMessageSummaryEngine* self = new (ELeave) CMessageSummaryEngine(aObserver);
00035 CleanupStack::PushL(self);
00036 self->ConstructL();
00037 CleanupStack::Pop(self);
00038 CActiveScheduler::Add(self);
00039 return self;
00040 }
00041
00042
00043 void CMessageSummaryEngine::StartL()
00044 {
00045 LOG(">> CMessageSummaryEngine::StartL()");
00046
00047 iState = EConnectingToMessageServer;
00048 iMessagingSession = CMsvSession::OpenAsyncL(*this);
00049
00050
00051 LOG("<< CMessageSummaryEngine::StartL()");
00052 }
00053
00054
00055 void CMessageSummaryEngine::DoCancel()
00056 {
00057
00058 }
00059
00060
00061 TBool CMessageSummaryEngine::UpdateNextSummary()
00062 {
00063 LOG(">> CMessageSummaryEngine::UpdateNextSummary()");
00064 TBool moreSummaries = ETrue;
00065
00066 switch (iState)
00067 {
00068 case EConnectingToMessageServer:
00069 iState = ERefreshing;
00070 iStatus = KRequestPending;
00071
00072 case ERefreshing:
00073
00074 if (iRefreshSms)
00075 {
00076 iSmsInboxSummary->StartL(iStatus);
00077 iRefreshSms = EFalse;
00078 }
00079 else if (iRefreshEmail)
00080 {
00081
00082 if (iEmailInboxSummary != NULL)
00083
00084 {
00085 iEmailInboxSummary->StartL(iStatus);
00086 }
00087 else
00088 {
00089 moreSummaries = EFalse;
00090 }
00091
00092 iRefreshEmail = EFalse;
00093 }
00094 else
00095 {
00096 moreSummaries = EFalse;
00097 }
00098 break;
00099
00100 default:
00101 break;
00102 }
00103
00104 if (moreSummaries)
00105 SetActive();
00106
00107 LOG("<< CMessageSummaryEngine::UpdateNextSummary()");
00108
00109 return moreSummaries;
00110 }
00111
00112
00113 void CMessageSummaryEngine::RunL()
00114 {
00115 LOG(">> CMessageSummaryEngine::RunL()");
00116
00117
00118 if (!UpdateNextSummary())
00119 {
00120
00121
00122 iObserver.Refresh();
00123 }
00124
00125 LOG("<< CMessageSummaryEngine::RunL()");
00126 }
00127
00128
00129 CMessageSummaryEngine::CMessageSummaryEngine(MSummaryEngineObserver& aObserver) : CActive(EPriorityStandard),
00130 iObserver(aObserver),
00131 iRefreshSms(ETrue),
00132 iRefreshEmail(ETrue)
00133 {
00134 }
00135
00136 void CMessageSummaryEngine::ConstructL()
00137 {
00138 }
00139
00140 void CMessageSummaryEngine::CreateSummaryGeneratorsL()
00141 {
00142 LOG(">> CMessageSummaryEngine::CreateSummaryGeneratorsL()");
00143
00144
00145
00146 TMsvSelectionOrdering ordering(KMsvNoGrouping, EMsvSortByDateReverse);
00147
00148
00149
00150
00151 iMessagingEntry = CMsvEntry::NewL(*iMessagingSession, KMsvGlobalInBoxIndexEntryId, ordering);
00152 iSmsInboxSummary = new (ELeave) CMessageSummaryGenerator(KMsvGlobalInBoxIndexEntryId, KUidMsgTypeSMS, *iMessagingEntry);
00153 iEmailInboxSummary = NULL;
00154
00155
00156 TMsvId pop3MailboxId;
00157 if (FindPop3ServiceEntryL(pop3MailboxId))
00158 {
00159 iEmailInboxSummary = new (ELeave) CMessageSummaryGenerator(pop3MailboxId, KUidMsgTypePOP3, *iMessagingEntry);
00160 }
00161
00162 LOG("<< CMessageSummaryEngine::CreateSummaryGeneratorsL()");
00163 }
00164
00165 TBool CMessageSummaryEngine::FindPop3ServiceEntryL(TMsvId& aPop3MailboxId)
00166 {
00167
00168 TBool pop3MailboxFound = EFalse;
00169
00170
00171 iMessagingEntry->SetEntryL(KMsvRootIndexEntryIdValue);
00172 CMsvEntrySelection* serviceEntryList = iMessagingEntry->ChildrenWithMtmL(KUidMsgTypePOP3);
00173 CleanupStack::PushL(serviceEntryList);
00174
00175
00176 if (serviceEntryList->Count() > 0)
00177 {
00178 aPop3MailboxId = (*serviceEntryList)[0];
00179 pop3MailboxFound = ETrue;
00180 }
00181
00182 CleanupStack::PopAndDestroy(serviceEntryList);
00183
00184 return pop3MailboxFound;
00185 }
00186
00187 void CMessageSummaryEngine::HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1, TAny *aArg2, TAny* )
00188
00189
00190 {
00191 LOG(">> CMessageSummaryEngine::HandleSessionEventL");
00192
00193 switch (aEvent)
00194 {
00195 case MMsvSessionObserver::EMsvServerReady:
00196
00197 LOG(">> MMsvSessionObserver::EMsvServerReady:");
00198 if (iState == EConnectingToMessageServer)
00199 {
00200
00201 CreateSummaryGeneratorsL();
00202
00203
00204
00205 UpdateNextSummary();
00206 }
00207 LOG("<< MMsvSessionObserver::EMsvServerReady:");
00208 break;
00209
00210 case MMsvSessionObserver::EMsvEntriesChanged:
00211 LOG(">> MMsvSessionObserver::EMsvEntriesChanged:");
00212
00213 CMsvEntrySelection* newMessages = static_cast<CMsvEntrySelection*> (aArg1);
00214
00215
00216 TMsvId* parentMsvId = static_cast<TMsvId*> (aArg2);
00217
00218
00219 iMessagingEntry->SetEntryL(*parentMsvId);
00220
00221
00222 TInt index = newMessages->Count() - 1;
00223 while (index >= 0)
00224 {
00225
00226 TMsvEntry tempMessageEntry = iMessagingEntry->ChildDataL(newMessages->At(index));
00227
00228 if (tempMessageEntry.Complete())
00229 {
00230 if (iSmsInboxSummary->MessageOfCorrectType(tempMessageEntry))
00231 {
00232 iRefreshSms = ETrue;
00233 }
00234 else if ((iEmailInboxSummary != NULL)
00235 && (iEmailInboxSummary->MessageOfCorrectType(tempMessageEntry)))
00236 {
00237
00238 iRefreshEmail = ETrue;
00239 }
00240 }
00241
00242 index--;
00243 }
00244
00245 if ((iRefreshSms) || (iRefreshEmail))
00246
00247
00248 {
00249 iState = ERefreshing;
00250
00251
00252
00253
00254 if (!IsActive())
00255 UpdateNextSummary();
00256 }
00257
00258 LOG("<< MMsvSessionObserver::EMsvEntriesChanged:");
00259
00260 break;
00261
00262 default:
00263
00264
00265 LOG("default:");
00266 break;
00267 }
00268
00269 LOG("<< CMessageSummaryEngine::HandleSessionEventL");
00270
00271 }
00272
00273
00274 CMessageSummaryEngine::~CMessageSummaryEngine()
00275 {
00276 delete iEmailInboxSummary;
00277 delete iSmsInboxSummary;
00278 delete iMessagingEntry;
00279 delete iMessagingSession;
00280 }