120 // --------------------------------------------------------------------------- |
120 // --------------------------------------------------------------------------- |
121 // |
121 // |
122 void CMailCpsSettings::LoadSettingsL() |
122 void CMailCpsSettings::LoadSettingsL() |
123 { |
123 { |
124 FUNC_LOG; |
124 FUNC_LOG; |
125 // Clean up local settings cache |
|
126 iMailboxArray.Reset(); |
|
127 TInt ret( KErrNone ); |
125 TInt ret( KErrNone ); |
128 |
126 |
129 // Load mailbox array |
127 // mailbox keys |
130 RArray<TUint32> keys; |
128 RArray<TUint> cenrepMailboxes; |
|
129 CleanupClosePushL( cenrepMailboxes ); |
|
130 RArray<TBool> cenrepMailboxesExistence; |
|
131 CleanupClosePushL( cenrepMailboxesExistence ); |
|
132 |
|
133 // cenrep keys |
|
134 RArray<TUint32> keys; |
131 CleanupClosePushL( keys ); |
135 CleanupClosePushL( keys ); |
132 GetMailboxNonZeroKeysL( keys ); |
136 GetMailboxNonZeroKeysL( keys ); |
133 const TInt iiMax( keys.Count() ); |
137 TInt dMax( keys.Count() ); |
134 for ( TInt ii = 0; ii < iiMax; ii++ ) |
138 |
135 { |
139 cenrepMailboxes.ReserveL( dMax ); |
136 TInt value( 0 ); |
140 cenrepMailboxesExistence.ReserveL( dMax ); |
137 ret = iCenRep->Get( keys[ii], value ); |
141 |
138 if ( ret ) |
142 // make array of mailbox keys |
139 { |
143 TInt value( 0 ); |
140 User::Leave( ret ); |
144 TInt i; |
141 } |
145 for ( i = 0; i < dMax; i++ ) |
142 else |
146 { |
143 { |
147 User::LeaveIfError( ret = iCenRep->Get( keys[i], value )); |
144 TFSMailMsgId mailbox; |
148 cenrepMailboxes.AppendL( static_cast<TUint>(value) ); |
145 ret = ResolveMailbox( value, mailbox ); |
149 cenrepMailboxesExistence.AppendL( EFalse ); |
146 if ( ret ) |
150 } |
|
151 CleanupStack::PopAndDestroy(&keys); |
|
152 |
|
153 // Sync array of cenrep keys with iMailboxArray |
|
154 // remove from array what is not in cenrep |
|
155 TInt dFound( KErrNotFound ); |
|
156 for ( i = iMailboxArray.Count()-1; i >= 0; i -- ) |
|
157 { |
|
158 dFound = cenrepMailboxes.Find( iMailboxArray[i].Id() ); |
|
159 if ( KErrNotFound != dFound ) |
|
160 { |
|
161 // mailbox is in iMailboxArray and in cenrep => check provider |
|
162 INFO_1("Mailbox both in cenrep and iMailboxArray: i = %d ", i ); |
|
163 ret = CheckMailboxExistence( iMailboxArray[i] ); |
|
164 if ( KErrNotFound == ret) |
147 { |
165 { |
148 INFO("CMailCpsSettings::LoadSettingsL(): Error: ignore this entry"); |
166 // mailbox was removed from provider => remove from cenrep also |
149 // Resolving encountered error, ignore this entry |
167 // cenrepMailboxes indexed the same way as keys => finding key not needed |
150 ret = iCenRep->Reset( KCMailMailboxIdBase+ii ); |
168 ret = iCenRep->Reset( KCMailMailboxIdBase + i ); |
151 ret = iCenRep->Reset( KCMailPluginIdBase+ii ); |
169 ret = iCenRep->Reset( KCMailPluginIdBase + i ); |
152 ret = iCenRep->Reset( KCMailWidgetContentIdBase+ii ); |
170 ret = iCenRep->Reset( KCMailWidgetContentIdBase + i ); |
153 if ( ret ) |
171 INFO_1("Mailbox removed from cenrep: dFound %d ", dFound ); |
154 { |
|
155 } |
|
156 } |
172 } |
157 else |
173 else |
158 { |
174 { |
159 iMailboxArray.AppendL( mailbox ); |
175 User::LeaveIfError(ret); // for instance if no memory |
|
176 INFO_1("Mailbox provider check ok: dFound = %d ", dFound ); |
160 } |
177 } |
161 } |
178 cenrepMailboxesExistence[dFound] = ETrue; // not remove to ensure indexes are the same as in keys |
162 } |
179 } |
163 CleanupStack::PopAndDestroy(); // CleanupClosePushL( keys ) |
180 else |
|
181 { |
|
182 // mailbox was removed from cenrep => remove from array |
|
183 iMailboxArray.Remove(i); |
|
184 INFO_1("Mailbox removed from iMailboxArray: i = %d ", i ); |
|
185 } |
|
186 } |
|
187 // Check order and new mailboxes |
|
188 TInt j(0); |
|
189 for ( i = 0; i < dMax; i++ ) |
|
190 { |
|
191 // new mailboxes in cenrep needs to be added to iMailboxArray |
|
192 if ( ! cenrepMailboxesExistence[i] ) |
|
193 { |
|
194 TFSMailMsgId mailbox; |
|
195 // Find mailbox by this function because cenrep does not hold pluginID |
|
196 if ( KErrNone == ResolveMailbox( cenrepMailboxes[i], mailbox ) ) |
|
197 { |
|
198 iMailboxArray.Insert( mailbox, i ); |
|
199 INFO_1("Mailbox added to iMailboxArray: i = %d ", i ); |
|
200 } |
|
201 } |
|
202 // Check if order is OK |
|
203 if ( iMailboxArray[i].Id() != cenrepMailboxes[i] ) |
|
204 { |
|
205 TInt jMax( iMailboxArray.Count() ); |
|
206 for ( j = i+1; j <= jMax; j++ ) |
|
207 { |
|
208 if ( iMailboxArray[j].Id() == cenrepMailboxes[i]) |
|
209 { |
|
210 iMailboxArray.Insert( iMailboxArray[j], i ); |
|
211 iMailboxArray.Remove( j+1 );// insertion increased indices |
|
212 break; |
|
213 } |
|
214 } |
|
215 if (j == jMax) // arrays not in sync error |
|
216 { |
|
217 User::Leave( KErrNotFound ); |
|
218 } |
|
219 } |
|
220 } |
|
221 CleanupStack::PopAndDestroy(&cenrepMailboxesExistence); |
|
222 CleanupStack::PopAndDestroy(&cenrepMailboxes); |
164 } |
223 } |
165 |
224 |
166 // --------------------------------------------------------------------------- |
225 // --------------------------------------------------------------------------- |
167 // CMailCpsSettings::LoadConfigurationL |
226 // CMailCpsSettings::LoadConfigurationL |
168 // --------------------------------------------------------------------------- |
227 // --------------------------------------------------------------------------- |
236 } |
295 } |
237 mailboxarray.ResetAndDestroy(); |
296 mailboxarray.ResetAndDestroy(); |
238 return err; |
297 return err; |
239 } |
298 } |
240 |
299 |
|
300 TInt CMailCpsSettings::CheckMailboxExistence( TFSMailMsgId& aMsg ) |
|
301 { |
|
302 FUNC_LOG; |
|
303 CFSMailBox *mbox( NULL ); |
|
304 TRAPD(err, mbox = iMailClient.GetMailBoxByUidL(aMsg)); |
|
305 if ( mbox ) // mail box exists |
|
306 { |
|
307 delete mbox; |
|
308 return KErrNone; |
|
309 } |
|
310 if ( ( KErrNotFound == err ) || ( KErrNone == err ) ) |
|
311 { |
|
312 // mail box not exists, chek if it is not in different plugin |
|
313 // very safe, maybe return KErrNotFound would be enough |
|
314 return ResolveMailbox( aMsg.Id(), aMsg ); |
|
315 } |
|
316 return err; |
|
317 } |
|
318 |
|
319 |
|
320 |
|
321 |
241 // --------------------------------------------------------------------------- |
322 // --------------------------------------------------------------------------- |
242 // CMailCpsSettings::StartObservingL |
323 // CMailCpsSettings::StartObservingL |
243 // --------------------------------------------------------------------------- |
324 // --------------------------------------------------------------------------- |
244 // |
325 // |
245 void CMailCpsSettings::StartObservingL( MMailCpsSettingsCallback* aObserver ) |
326 void CMailCpsSettings::StartObservingL( MMailCpsSettingsCallback* aObserver ) |
676 } |
779 } |
677 } |
780 } |
678 } |
781 } |
679 |
782 |
680 // ----------------------------------------------------------------------------- |
783 // ----------------------------------------------------------------------------- |
681 // CMailCpsSettings::GetNewMailState |
784 // CMailCpsSettings::GetNewMailStateL |
682 // ----------------------------------------------------------------------------- |
785 // ----------------------------------------------------------------------------- |
683 TBool CMailCpsSettings::GetNewMailState( const TFSMailMsgId& aMailBox ) |
786 TBool CMailCpsSettings::GetNewMailStateL( const TFSMailMsgId& aMailBox, TInt aUnreadCount ) |
684 { |
787 { |
685 FUNC_LOG; |
788 FUNC_LOG; |
686 TBool ret(EFalse); |
789 TBool ret(EFalse); |
687 TBuf<KMaxDescLen> mailbox; |
790 if ( aUnreadCount ) |
688 mailbox.Num(aMailBox.Id()); |
791 { |
689 |
792 TBuf<KMaxDescLen> mailbox; |
690 TBuf<KMaxDescLen> str; |
793 mailbox.Num(aMailBox.Id()); |
691 str.Copy(KStartSeparator); |
794 |
692 str.Append(mailbox); |
795 TBuf<KMaxDescLen> str; |
693 str.Append(KEndSeparator); |
796 str.Copy(KStartSeparator); |
694 |
797 str.Append(mailbox); |
695 TBuf<KMaxDescLen> stored; |
798 str.Append(KEndSeparator); |
696 TUint32 key(KCMailMailboxesWithNewMail); |
799 |
697 iCenRep->Get( key, stored ); |
800 TBuf<KMaxDescLen> stored; |
|
801 TUint32 key(KCMailMailboxesWithNewMail); |
|
802 iCenRep->Get( key, stored ); |
698 |
803 |
699 TInt result = stored.Find(str); |
804 TInt result = stored.Find(str); |
700 if (result >= 0) |
805 if (result >= 0) |
701 { |
806 { |
702 ret = ETrue; |
807 ret = ETrue; |
|
808 } |
|
809 } |
|
810 else |
|
811 { |
|
812 ToggleWidgetNewMailIconL( EFalse, aMailBox ); |
703 } |
813 } |
704 return ret; |
814 return ret; |
705 } |
815 } |