|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Observer of the given folder. If new messages are created to the folder, |
|
16 * calls HandleFolderEntryL. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "AlwaysOnlineEmailPluginLogging.h" |
|
22 #include "AlwaysOnlineImap4FolderObserver.h" |
|
23 #include "AlwaysOnlineEmailLoggingTools.h" |
|
24 |
|
25 const TInt KAlwaysOnlineImap4FolderObserverTimeout = 2000000; // 2 seconds |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // CAlwaysOnlineImap4FolderObserver() |
|
29 // ---------------------------------------------------------------------------- |
|
30 CAlwaysOnlineImap4FolderObserver::CAlwaysOnlineImap4FolderObserver( |
|
31 CMsvSession& aMsvSession, |
|
32 MAlwaysOnlineImap4FolderObserver& aObserver ) |
|
33 : |
|
34 CActive( EPriorityStandard ), |
|
35 iMsvSession( aMsvSession ), |
|
36 iObserver( aObserver ) |
|
37 { |
|
38 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::CAlwaysOnlineImap4FolderObserver" ); |
|
39 CActiveScheduler::Add( this ); |
|
40 } |
|
41 |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // NewL() |
|
45 // ---------------------------------------------------------------------------- |
|
46 CAlwaysOnlineImap4FolderObserver* CAlwaysOnlineImap4FolderObserver::NewL( |
|
47 CMsvSession& aMsvSession, |
|
48 MAlwaysOnlineImap4FolderObserver& aObserver ) |
|
49 { |
|
50 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::NewL" ); |
|
51 return CAlwaysOnlineImap4FolderObserver::NewL( aMsvSession, NULL, aObserver ); |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // NewL() |
|
56 // ---------------------------------------------------------------------------- |
|
57 CAlwaysOnlineImap4FolderObserver* CAlwaysOnlineImap4FolderObserver::NewL( |
|
58 CMsvSession& aMsvSession, |
|
59 CMsvEntrySelection* aFoldersToWatch, |
|
60 MAlwaysOnlineImap4FolderObserver& aObserver ) |
|
61 { |
|
62 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::NewL" ); |
|
63 CAlwaysOnlineImap4FolderObserver* self = |
|
64 new (ELeave) CAlwaysOnlineImap4FolderObserver( |
|
65 aMsvSession, aObserver ); |
|
66 |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL( aFoldersToWatch ); |
|
69 CleanupStack::Pop( self ); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // ConstructL() |
|
77 // ---------------------------------------------------------------------------- |
|
78 void CAlwaysOnlineImap4FolderObserver::ConstructL( |
|
79 CMsvEntrySelection* aFoldersToWatch ) |
|
80 { |
|
81 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::ConstructL" ); |
|
82 User::LeaveIfError( iTimer.CreateLocal() ); |
|
83 iRunning = EFalse; |
|
84 iSendNotification = EFalse; |
|
85 iMsvSession.AddObserverL( *this ); |
|
86 |
|
87 if ( aFoldersToWatch ) |
|
88 { |
|
89 iFolders = aFoldersToWatch->CopyL(); |
|
90 } |
|
91 else |
|
92 { |
|
93 iFolders = new (ELeave) CMsvEntrySelection; |
|
94 } |
|
95 iChangedFolders = new (ELeave) CMsvEntrySelection; |
|
96 |
|
97 |
|
98 } |
|
99 |
|
100 // ---------------------------------------------------------------------------- |
|
101 // ~CAlwaysOnlineImap4Agent() |
|
102 // ---------------------------------------------------------------------------- |
|
103 CAlwaysOnlineImap4FolderObserver::~CAlwaysOnlineImap4FolderObserver() |
|
104 { |
|
105 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::~CAlwaysOnlineImap4FolderObserver" ); |
|
106 iMsvSession.RemoveObserver( *this ); |
|
107 delete iFolders; |
|
108 delete iChangedFolders; |
|
109 Cancel(); |
|
110 iTimer.Close(); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // Start() |
|
115 // ---------------------------------------------------------------------------- |
|
116 void CAlwaysOnlineImap4FolderObserver::Start() |
|
117 { |
|
118 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::Start" ); |
|
119 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineImap4FolderObserver::Start"); |
|
120 iRunning = ETrue; |
|
121 iSendNotification = EFalse; |
|
122 } |
|
123 |
|
124 void CAlwaysOnlineImap4FolderObserver::Stop() |
|
125 { |
|
126 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineImap4FolderObserver::Stop"); |
|
127 Cancel(); |
|
128 iRunning = EFalse; |
|
129 iSendNotification = EFalse; |
|
130 } |
|
131 |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // DoCancel() |
|
135 // ---------------------------------------------------------------------------- |
|
136 void CAlwaysOnlineImap4FolderObserver::DoCancel() |
|
137 { |
|
138 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::DoCancel" ); |
|
139 iTimer.Cancel(); |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // RunL() |
|
144 // ---------------------------------------------------------------------------- |
|
145 void CAlwaysOnlineImap4FolderObserver::RunL() |
|
146 { |
|
147 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::RunL" ); |
|
148 KAOEMAIL_LOGGER_FN1("CAlwaysOnlineImap4FolderObserver::RunL"); |
|
149 iRunning = EFalse; |
|
150 if ( iSendNotification ) |
|
151 { |
|
152 iObserver.HandleFolderEntryL( *iChangedFolders ); |
|
153 iChangedFolders->Reset(); |
|
154 } |
|
155 KAOEMAIL_LOGGER_FN2("CAlwaysOnlineImap4FolderObserver::RunL"); |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // HandleSessionEventL() |
|
160 // ---------------------------------------------------------------------------- |
|
161 void CAlwaysOnlineImap4FolderObserver::HandleSessionEventL( |
|
162 TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) |
|
163 { |
|
164 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::HandleSessionEventL" ); |
|
165 KAOEMAIL_LOGGER_WRITE_FORMAT("CAlwaysOnlineImap4FolderObserver::HandleSessionEventL aEvent %d", aEvent); |
|
166 if ( !iRunning ) |
|
167 { |
|
168 // just ignore everything, we are not running |
|
169 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineImap4FolderObserver::HandleSessionEventL: ignore everything"); |
|
170 return; |
|
171 } |
|
172 const TTimeIntervalMicroSeconds32 timeInterval = KAlwaysOnlineImap4FolderObserverTimeout; |
|
173 |
|
174 switch ( aEvent ) |
|
175 { |
|
176 case EMsvEntriesCreated: |
|
177 case EMsvEntriesChanged: // Handle this somehow |
|
178 case EMsvEntriesDeleted: |
|
179 { |
|
180 TMsvId parentId = (*(TMsvId*) (aArg2)); |
|
181 if ( iFolders->Find( parentId ) != KErrNotFound ) |
|
182 { |
|
183 KAOEMAIL_LOGGER_WRITE_FORMAT("parent 0x%x found", parentId); |
|
184 iSendNotification = ETrue; |
|
185 if ( iChangedFolders->Find( parentId ) == KErrNotFound ) |
|
186 { |
|
187 iChangedFolders->AppendL( parentId ); |
|
188 } |
|
189 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineImap4FolderObserver::HandleSessionEventL: restart timer case 2"); |
|
190 Cancel(); |
|
191 // cancel called right before, no need to check if still active |
|
192 iTimer.After( iStatus, timeInterval ); // CSI: 10 # see comment above |
|
193 SetActive(); |
|
194 } |
|
195 else |
|
196 { |
|
197 const CMsvEntrySelection* selection = static_cast<CMsvEntrySelection*>(aArg1); |
|
198 if ( iMailboxId > 0 && |
|
199 selection->Find( iMailboxId ) > KErrNotFound ) |
|
200 { |
|
201 iSendNotification = ETrue; |
|
202 iChangedFolders->AppendL( iMailboxId ); |
|
203 KAOEMAIL_LOGGER_WRITE("CAlwaysOnlineImap4FolderObserver::HandleSessionEventL: restart timer case 3"); |
|
204 Cancel(); |
|
205 // cancel called right before, no need to check if still active |
|
206 iTimer.After( iStatus, timeInterval ); // CSI: 10 # see comment above |
|
207 SetActive(); |
|
208 } |
|
209 } |
|
210 } |
|
211 break; |
|
212 default: |
|
213 break; |
|
214 } |
|
215 |
|
216 } |
|
217 |
|
218 // ---------------------------------------------------------------------------- |
|
219 // AppendFolderL() |
|
220 // ---------------------------------------------------------------------------- |
|
221 void CAlwaysOnlineImap4FolderObserver::AppendFolderL( TMsvId aFolderId ) |
|
222 { |
|
223 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::AppendFolderL" ); |
|
224 if ( iFolders->Find( aFolderId ) == KErrNotFound ) |
|
225 { |
|
226 iFolders->AppendL( aFolderId ); |
|
227 } |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // RemoveFolder() |
|
232 // ---------------------------------------------------------------------------- |
|
233 void CAlwaysOnlineImap4FolderObserver::RemoveFolder( TMsvId aFolderId ) |
|
234 { |
|
235 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::RemoveFolder" ); |
|
236 TInt index = iFolders->Find( aFolderId ); |
|
237 if ( index != KErrNotFound ) |
|
238 { |
|
239 iFolders->Delete( index ); |
|
240 } |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // ResetFoldersL() |
|
245 // ---------------------------------------------------------------------------- |
|
246 void CAlwaysOnlineImap4FolderObserver::ResetFoldersL( CMsvEntrySelection* aFoldersToWatch ) |
|
247 { |
|
248 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::ResetFoldersL" ); |
|
249 delete iFolders; |
|
250 iFolders = NULL; |
|
251 iFolders = aFoldersToWatch->CopyL(); |
|
252 } |
|
253 |
|
254 // ---------------------------------------------------------------------------- |
|
255 // SetMailbox() |
|
256 // ---------------------------------------------------------------------------- |
|
257 void CAlwaysOnlineImap4FolderObserver::SetMailbox( const TMsvId aMailboxId ) |
|
258 { |
|
259 AOLOG_IN( "CAlwaysOnlineImap4FolderObserver::SetMailbox" ); |
|
260 iMailboxId = aMailboxId; |
|
261 } |
|
262 //EOF |