19
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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 the License "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: Implementation of class CMessagingAccessFolder
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <badesca.h>
|
|
22 |
#include <msvapi.h>
|
|
23 |
#include <MsvUids.h>
|
|
24 |
#include <senduiconsts.h>
|
|
25 |
|
|
26 |
#include "messageheader.h"
|
|
27 |
#include "accessfolder.h"
|
|
28 |
|
|
29 |
// ---------------------------------------------------------------------------
|
|
30 |
// Two-phased constructor.
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
CMessagingAccessFolder* CMessagingAccessFolder::NewL( CMsvSession& aServerSession )
|
|
34 |
{
|
|
35 |
CMessagingAccessFolder* self = new (ELeave) CMessagingAccessFolder( aServerSession );
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// Destructor.
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CMessagingAccessFolder::~CMessagingAccessFolder()
|
|
44 |
{
|
|
45 |
if ( iEntrySelection )
|
|
46 |
{
|
|
47 |
iEntrySelection->Reset();
|
|
48 |
}
|
|
49 |
|
|
50 |
iMtmArrayId.Reset();
|
|
51 |
|
|
52 |
delete iEntrySelection;
|
|
53 |
delete iFilter;
|
|
54 |
}
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
// Constructor.
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
CMessagingAccessFolder::CMessagingAccessFolder( CMsvSession& aServerSession ):
|
|
61 |
iServerSession(aServerSession)
|
|
62 |
{
|
|
63 |
}
|
|
64 |
|
|
65 |
void CMessagingAccessFolder::GetIdListL(TMsvId aFolderId ,
|
|
66 |
CFilterParamInfo* aFilter,
|
|
67 |
CMsvEntrySelection*& aEntrySelection )
|
|
68 |
{
|
|
69 |
if ( !iFilter )
|
|
70 |
iFilter = CFilterParamInfo::NewL();
|
|
71 |
|
|
72 |
if( aFilter ) //added this check to do the copy only if aFilter is not NULL
|
|
73 |
*iFilter = *aFilter;
|
|
74 |
iFolderId = aFolderId;
|
|
75 |
|
|
76 |
GetListL();
|
|
77 |
|
|
78 |
aEntrySelection = iEntrySelection;
|
|
79 |
iEntrySelection = NULL;
|
|
80 |
}
|
|
81 |
|
|
82 |
void CMessagingAccessFolder::GetNextHeaderL( CFilterParamInfo* aFilter,
|
|
83 |
CMsvEntrySelection* aEntrySelection,
|
|
84 |
TInt& aIndex,
|
|
85 |
CMessageHeader*& aHeader )
|
|
86 |
{
|
|
87 |
if(!aEntrySelection || ( aEntrySelection->Count() <= aIndex ))
|
|
88 |
return;
|
|
89 |
|
|
90 |
if ( !iFilter )
|
|
91 |
iFilter = CFilterParamInfo::NewL();
|
|
92 |
|
|
93 |
if( aFilter ) //added this check to do the copy only if aFilter is not NULL
|
|
94 |
*iFilter = *aFilter;
|
|
95 |
|
|
96 |
GetNextFilteredHeaderL( aEntrySelection, aIndex, aHeader );
|
|
97 |
|
|
98 |
}
|
|
99 |
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
// Gives the list of message headers ,sets the sorting order and
|
|
102 |
// call function for filtering the message headers.
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
void CMessagingAccessFolder::GetListL()
|
|
106 |
{
|
|
107 |
TInt groupingKey = KMsvNoGrouping;
|
|
108 |
TMsvSelectionOrdering order( groupingKey, iFilter->SortType() );
|
|
109 |
CMsvEntry* entry = iServerSession.GetEntryL( iFolderId );
|
|
110 |
CleanupStack::PushL( entry );
|
|
111 |
|
|
112 |
// Getlist can be performed on Folders entries only
|
|
113 |
if ( entry->Entry().iType != KUidMsvFolderEntry )
|
|
114 |
{
|
|
115 |
User::Leave( KErrArgument );
|
|
116 |
}
|
|
117 |
|
|
118 |
entry->SetSortTypeL( order );
|
|
119 |
|
|
120 |
InitializeMtmArray();
|
|
121 |
|
|
122 |
if ( iEntrySelection )
|
|
123 |
{
|
|
124 |
iEntrySelection->Reset();
|
|
125 |
delete iEntrySelection;
|
|
126 |
iEntrySelection = NULL;
|
|
127 |
}
|
|
128 |
|
|
129 |
if ( iMtmArrayId.Count() == 1 )
|
|
130 |
{
|
|
131 |
iEntrySelection = entry->ChildrenWithMtmL( iMtmArrayId[0] );
|
|
132 |
}
|
|
133 |
else
|
|
134 |
{
|
|
135 |
iEntrySelection = entry->ChildrenL();
|
|
136 |
}
|
|
137 |
|
|
138 |
CleanupStack::PopAndDestroy( entry );
|
|
139 |
}
|
|
140 |
|
|
141 |
// ---------------------------------------------------------------------------
|
|
142 |
// Initializes the MtmID array by the Mtm string passed
|
|
143 |
// by user.
|
|
144 |
// ---------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CMessagingAccessFolder::InitializeMtmArray()
|
|
147 |
{
|
|
148 |
const CDesCArray* mtmArray = iFilter->Mtm();
|
|
149 |
|
|
150 |
iMtmArrayId.Reset();
|
|
151 |
|
|
152 |
if ( mtmArray )
|
|
153 |
{
|
|
154 |
for ( int i= 0; i< mtmArray->Count(); i++ )
|
|
155 |
{
|
|
156 |
if ( (*mtmArray)[i].CompareF( KMessageTypeSMS ) == KErrNone )
|
|
157 |
{
|
|
158 |
iMtmArrayId.Append( KSenduiMtmSmsUid );
|
|
159 |
}
|
|
160 |
else if ( (*mtmArray)[i].CompareF( KMessageTypeMMS ) == KErrNone )
|
|
161 |
{
|
|
162 |
iMtmArrayId.Append( KSenduiMtmMmsUid );
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
// Fetches next header based on input parameters
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
void CMessagingAccessFolder::GetNextFilteredHeaderL( CMsvEntrySelection* aEntrySelection,
|
|
173 |
TInt& aIndex,
|
|
174 |
CMessageHeader*& aHeader )
|
|
175 |
{
|
|
176 |
TInt count = aEntrySelection->Count();
|
|
177 |
|
|
178 |
InitializeMtmArray();
|
|
179 |
|
|
180 |
for ( ;aIndex < count; )
|
|
181 |
{
|
|
182 |
TMsvId id = (*aEntrySelection)[aIndex];
|
|
183 |
TMsvEntry tentry;
|
|
184 |
TMsvId serviceId;
|
|
185 |
iServerSession.GetEntry( id, serviceId, tentry ); // Getting TMsvEntry
|
|
186 |
|
|
187 |
aIndex++;
|
|
188 |
|
|
189 |
if ( iFilter->Filter() & EFilterId )
|
|
190 |
{
|
|
191 |
if ( !FilterId( id ) )
|
|
192 |
continue;
|
|
193 |
}
|
|
194 |
|
|
195 |
if ( iFilter->Filter() & EFilterMtm )
|
|
196 |
{
|
|
197 |
if ( !FilterMtm( tentry ) )
|
|
198 |
continue;
|
|
199 |
}
|
|
200 |
|
|
201 |
if ( iFilter->Filter() & EFilterFrom )
|
|
202 |
{
|
|
203 |
if ( !FilterFrom( tentry ) )
|
|
204 |
continue;
|
|
205 |
}
|
|
206 |
|
|
207 |
if ( iFilter->Filter() & EFilterSubject )
|
|
208 |
{
|
|
209 |
if ( !FilterSubject( tentry ) )
|
|
210 |
continue;
|
|
211 |
}
|
|
212 |
|
|
213 |
if ( iFilter->Filter() & EFilterStartDate ||
|
|
214 |
iFilter->Filter() & EFilterEndDate )
|
|
215 |
{
|
|
216 |
if ( !FilterDate( tentry ) )
|
|
217 |
continue;
|
|
218 |
}
|
|
219 |
|
|
220 |
CMessageHeader * header = CMessageHeader::NewL();
|
|
221 |
CleanupStack::PushL( header );
|
|
222 |
header->SetMessageId( id );
|
|
223 |
header->SetFromL( tentry.iDetails );
|
|
224 |
header->SetMtmId( tentry.iMtm );
|
|
225 |
header->SetAttachFlag( tentry.Attachment() );
|
|
226 |
header->SetPriorityFlag( tentry.Priority() );
|
|
227 |
header->SetUnreadFlag( tentry.Unread() );
|
|
228 |
header->SetSubjectL( tentry.iDescription );
|
|
229 |
header->SetTime( tentry.iDate );
|
|
230 |
CleanupStack::Pop( header );
|
|
231 |
aHeader = header;
|
|
232 |
break;
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
// Filters out with message id
|
|
238 |
// ---------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
TBool CMessagingAccessFolder::FilterId(const TMsvId aMessageId) const
|
|
241 |
{
|
|
242 |
if ( aMessageId == iFilter->MessageId() )
|
|
243 |
{
|
|
244 |
return ETrue;
|
|
245 |
}
|
|
246 |
return EFalse;
|
|
247 |
}
|
|
248 |
|
|
249 |
// ---------------------------------------------------------------------------
|
|
250 |
// Filters out with mtm type
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
TBool CMessagingAccessFolder::FilterMtm( const TMsvEntry& aEntry) const
|
|
254 |
{
|
|
255 |
for ( int i= 0; i< iMtmArrayId.Count(); i++ )
|
|
256 |
{
|
|
257 |
if( iMtmArrayId[i] == aEntry.iMtm )
|
|
258 |
{
|
|
259 |
return ETrue;
|
|
260 |
}
|
|
261 |
}
|
|
262 |
return EFalse;
|
|
263 |
}
|
|
264 |
|
|
265 |
// ---------------------------------------------------------------------------
|
|
266 |
// Filters out with sender address
|
|
267 |
// ---------------------------------------------------------------------------
|
|
268 |
//
|
|
269 |
TBool CMessagingAccessFolder::FilterFrom( const TMsvEntry& aEntry) const
|
|
270 |
{
|
|
271 |
const CDesCArray* fromArray = iFilter->From();
|
|
272 |
for ( int i= 0; i < fromArray->Count(); i++ )
|
|
273 |
{
|
|
274 |
if ( aEntry.iDetails.FindF( (*fromArray)[i] ) != KErrNotFound )
|
|
275 |
{
|
|
276 |
return ETrue ;
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
return EFalse ;
|
|
281 |
}
|
|
282 |
|
|
283 |
// ---------------------------------------------------------------------------
|
|
284 |
// Filters out with subject
|
|
285 |
// ---------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
TBool CMessagingAccessFolder::FilterSubject( const TMsvEntry& aEntry) const
|
|
288 |
{
|
|
289 |
if ( aEntry.iDescription.FindF( iFilter->Subject() ) != KErrNotFound )
|
|
290 |
{
|
|
291 |
return ETrue ;
|
|
292 |
}
|
|
293 |
|
|
294 |
return EFalse;
|
|
295 |
}
|
|
296 |
|
|
297 |
// ---------------------------------------------------------------------------
|
|
298 |
// Filters out with Date
|
|
299 |
// ---------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
TBool CMessagingAccessFolder::FilterDate( const TMsvEntry& aEntry) const
|
|
302 |
{
|
|
303 |
TDateTime startDateTime( iFilter->StartDate().DateTime().Year(),
|
|
304 |
iFilter->StartDate().DateTime().Month(),
|
|
305 |
iFilter->StartDate().DateTime().Day(),
|
|
306 |
0, 0, 0, 0 );
|
|
307 |
|
|
308 |
TDateTime endDateTime( iFilter->EndDate().DateTime().Year(),
|
|
309 |
iFilter->EndDate().DateTime().Month(),
|
|
310 |
iFilter->EndDate().DateTime().Day(),
|
|
311 |
0, 0, 0, 0 );
|
|
312 |
|
|
313 |
TDateTime checkDateTime( aEntry.iDate.DateTime().Year(),
|
|
314 |
aEntry.iDate.DateTime().Month(),
|
|
315 |
aEntry.iDate.DateTime().Day(),
|
|
316 |
0, 0, 0, 0 );
|
|
317 |
|
|
318 |
TTime startTime( startDateTime );
|
|
319 |
TTime endTime( endDateTime );
|
|
320 |
TTime checkTime( checkDateTime );
|
|
321 |
|
|
322 |
if ( ( iFilter->Filter() & EFilterStartDate ) &&
|
|
323 |
( iFilter->Filter() & EFilterEndDate ) )
|
|
324 |
{
|
|
325 |
if ( checkTime >= startTime && checkTime <= endTime )
|
|
326 |
{
|
|
327 |
return ETrue;
|
|
328 |
}
|
|
329 |
}
|
|
330 |
else if ( iFilter->Filter() & EFilterStartDate )
|
|
331 |
{
|
|
332 |
if( checkTime >= startTime )
|
|
333 |
{
|
|
334 |
return ETrue;
|
|
335 |
}
|
|
336 |
}
|
|
337 |
else if ( iFilter->Filter() & EFilterEndDate )
|
|
338 |
{
|
|
339 |
if( checkTime <= endTime )
|
|
340 |
{
|
|
341 |
return ETrue;
|
|
342 |
}
|
|
343 |
}
|
|
344 |
return EFalse;
|
|
345 |
}
|
|
346 |
|
|
347 |
|