|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cmmcalllist.h" |
|
20 #include "cmmcalltsy.h" |
|
21 #include "cmmphonetsy.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 CMmCallList::CMmCallList() |
|
26 { |
|
27 } |
|
28 |
|
29 CMmCallList* CMmCallList::NewL( |
|
30 CMmPhoneTsy* aMmPhone ) |
|
31 { |
|
32 |
|
33 CMmCallList* aCallList = NULL; |
|
34 |
|
35 if ( aMmPhone ) |
|
36 { |
|
37 aCallList = new (ELeave) CMmCallList(); |
|
38 CleanupStack::PushL( aCallList ); |
|
39 aCallList->iMmPhone = aMmPhone; |
|
40 aCallList->ConstructL(); |
|
41 CleanupStack::Pop(); |
|
42 } |
|
43 |
|
44 return aCallList; |
|
45 } |
|
46 |
|
47 void CMmCallList::ConstructL() |
|
48 { |
|
49 //Create call container |
|
50 CreateContainerL(); |
|
51 } |
|
52 |
|
53 CMmCallList::~CMmCallList() |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CMmCallList::GetMmCallByIndex |
|
59 // Returns call object by index. The indexing begins from 0. |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CMmCallTsy* CMmCallList::GetMmCallByIndex( |
|
63 TInt aIndex ) |
|
64 { |
|
65 CMmCallTsy* mmCall = NULL; |
|
66 |
|
67 if ( iObjectContainer ) |
|
68 { |
|
69 if ( aIndex >= 0 && aIndex < iObjectContainer->Count() ) |
|
70 { |
|
71 mmCall = reinterpret_cast<CMmCallTsy*>( |
|
72 iObjectContainer->At( aIndex ) ); |
|
73 } |
|
74 } |
|
75 |
|
76 return mmCall; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CMmCallList::GetMmCallByIndexAndLine |
|
81 // Returns call object by index and line. |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 CMmCallTsy* CMmCallList::GetMmCallByIndexAndLine( |
|
85 TInt aIndex, |
|
86 const TName* aLineName ) |
|
87 { |
|
88 |
|
89 CMmCallTsy* mmCall = NULL; |
|
90 CMmCallTsy* mmCallSeek = NULL; |
|
91 |
|
92 TInt callCount = iObjectContainer->Count(); |
|
93 TInt index( 0 ); |
|
94 |
|
95 //search through call list |
|
96 for ( TInt i = 0; i < callCount; i++ ) |
|
97 { |
|
98 //get current call |
|
99 mmCallSeek = reinterpret_cast<CMmCallTsy*>( |
|
100 iObjectContainer->At( i ) ); |
|
101 |
|
102 //get the name of the line from which this call has been opened. |
|
103 //see class CMmLineTsy to see how the call object naming works. |
|
104 TName curLineName = mmCallSeek-> |
|
105 CallName().Left( aLineName->Length() ); |
|
106 |
|
107 //if the name is the same as the line name given as input parameter |
|
108 if ( curLineName.Compare( *aLineName ) == 0 ) |
|
109 { |
|
110 if ( index == aIndex ) |
|
111 { |
|
112 //Break out |
|
113 mmCall = mmCallSeek; |
|
114 i = callCount; |
|
115 } |
|
116 else |
|
117 { |
|
118 index++; |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 return mmCall; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMmCallList::GetMmCallById |
|
128 // Returns call object by call id. Call ID has to differ from 0 because |
|
129 // call list may contain multiple call objects with call ID 0! |
|
130 // In that case the method will return NULL. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 CMmCallTsy* CMmCallList::GetMmCallById( |
|
134 const TInt aCallId ) |
|
135 { |
|
136 CMmCallTsy* mmCall = NULL; |
|
137 CMmCallTsy* mmCallSeek = NULL; |
|
138 |
|
139 if ( ( 0 < aCallId ) && iObjectContainer ) |
|
140 { |
|
141 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
142 { |
|
143 mmCallSeek = reinterpret_cast<CMmCallTsy*>( |
|
144 iObjectContainer->At( i ) ); |
|
145 |
|
146 if ( aCallId == mmCallSeek->CallId() ) |
|
147 { |
|
148 mmCall = mmCallSeek; |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 return mmCall; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CMmCallList::GetMmCallByName |
|
159 // Returns call object by name. |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 CMmCallTsy* CMmCallList::GetMmCallByName( |
|
163 const TName* aName ) |
|
164 { |
|
165 CMmCallTsy* mmCall = NULL; |
|
166 CMmCallTsy* mmCallSeek = NULL; |
|
167 |
|
168 if ( iObjectContainer ) |
|
169 { |
|
170 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
171 { |
|
172 mmCallSeek = reinterpret_cast<CMmCallTsy*>( |
|
173 iObjectContainer->At( i ) ); |
|
174 |
|
175 TName aCurrCallName = mmCallSeek->CallName(); |
|
176 if ( aCurrCallName.Compare( *aName ) == KErrNone ) |
|
177 { |
|
178 mmCall = mmCallSeek; |
|
179 break; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 return mmCall; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CMmCallList::GetMmCallByMode |
|
189 // Returns call object by mode. |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 CMmCallTsy* CMmCallList::GetMmCallByMode( |
|
193 RMobilePhone::TMobileService aCallMode ) |
|
194 { |
|
195 CMmCallTsy* mmCall = NULL; |
|
196 CMmCallTsy* mmCallSeek = NULL; |
|
197 |
|
198 if ( iObjectContainer ) |
|
199 { |
|
200 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
201 { |
|
202 mmCallSeek = reinterpret_cast<CMmCallTsy*>( |
|
203 iObjectContainer->At( i ) ); |
|
204 if ( mmCallSeek->CallMode() == aCallMode ) |
|
205 { |
|
206 mmCall = mmCallSeek; |
|
207 break; |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 return mmCall; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CMmCallList::RemoveMmCallById |
|
217 // Removes a call by id from the list of calls. |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 TInt CMmCallList::RemoveMmCallById( |
|
221 TInt aMmCallId ) |
|
222 { |
|
223 TInt ret( KErrNotFound ); |
|
224 |
|
225 if ( iObjectContainer ) |
|
226 { |
|
227 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
228 { |
|
229 CMmCallTsy* mmCall = |
|
230 reinterpret_cast<CMmCallTsy*>( iObjectContainer->At( i ) ); |
|
231 |
|
232 if ( aMmCallId == mmCall->CallId() ) |
|
233 { |
|
234 iObjectContainer->Delete( i ); |
|
235 if ( iObjectContainer->Count() > 1 ) |
|
236 { |
|
237 iObjectContainer->Compress(); |
|
238 } |
|
239 ret = KErrNone; |
|
240 break; |
|
241 } |
|
242 } |
|
243 } |
|
244 |
|
245 return ret; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CMmCallList::GetMmCallByStatus |
|
250 // Returns a call by status from the list of calls. |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 CMmCallTsy* CMmCallList::GetMmCallByStatus( |
|
254 RMobileCall::TMobileCallStatus aStatus ) |
|
255 { |
|
256 CMmCallTsy* mmCall = NULL; |
|
257 CMmCallTsy* mmCallSeek = NULL; |
|
258 |
|
259 if ( iObjectContainer ) |
|
260 { |
|
261 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
262 { |
|
263 mmCallSeek = reinterpret_cast<CMmCallTsy*>( |
|
264 iObjectContainer->At( i ) ); |
|
265 if ( mmCallSeek->MobileCallStatus() == aStatus ) |
|
266 { |
|
267 mmCall = mmCallSeek; |
|
268 break; |
|
269 } |
|
270 } |
|
271 } |
|
272 |
|
273 return mmCall; |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // CMmCallList::RemoveCallsByLine |
|
278 // Removes Call objects from Call list that has been opened |
|
279 // from the Line (which name is given as a input parameter). |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 void CMmCallList::RemoveCallsByLine( |
|
283 const TName* aLineName ) |
|
284 { |
|
285 //if call list exists |
|
286 if ( iObjectContainer ) |
|
287 { |
|
288 TInt callCount = iObjectContainer->Count(); |
|
289 TInt index( 0 ); |
|
290 //search through call list |
|
291 for ( TInt i = 0; i < callCount; i++ ) |
|
292 { |
|
293 //get current call |
|
294 CMmCallTsy* mmCall = |
|
295 reinterpret_cast<CMmCallTsy*>( iObjectContainer->At( index ) ); |
|
296 |
|
297 //get the name of the line from which this call has been opened. |
|
298 //see class CMmLineTsy to see how the call object naming works. |
|
299 TName curLineName = mmCall-> |
|
300 CallName().Left( aLineName->Length() ); |
|
301 |
|
302 //if the name is the same as the line name given as input param. |
|
303 if ( curLineName.Compare( *aLineName ) == 0 ) |
|
304 { |
|
305 //close this call |
|
306 mmCall->Close(); |
|
307 index--; |
|
308 } |
|
309 index++; |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CMmCallList::AddObject |
|
316 // Adds a call object to the array and remove unused call objects. |
|
317 // from the Line (which name is given as a input parameter). |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 TInt CMmCallList::AddObject( |
|
321 CTelObject* aTsyObject ) |
|
322 { |
|
323 TInt ret( KErrGeneral ); |
|
324 |
|
325 if ( iObjectContainer ) |
|
326 { |
|
327 for ( TInt i = 0; i < iObjectContainer->Count(); i++ ) |
|
328 { |
|
329 CMmCallTsy* mmCall = reinterpret_cast<CMmCallTsy*>( |
|
330 iObjectContainer->At( i ) ); |
|
331 |
|
332 //Remove object for incoming call or ghost call that is on idle |
|
333 //state and don't have a owner (client) |
|
334 if ( ( RCall::EStatusIdle == mmCall->Status() ) && |
|
335 ( mmCall->IsUnownedCallObject() ) ) |
|
336 { |
|
337 iObjectContainer->Delete( i ); |
|
338 mmCall->Close(); |
|
339 } |
|
340 } |
|
341 |
|
342 if ( iObjectContainer->Count() > 1 ) |
|
343 { |
|
344 iObjectContainer->Compress(); |
|
345 } |
|
346 |
|
347 TInt trapError( KErrNone ); |
|
348 |
|
349 //Append the object to the container |
|
350 TRAP( trapError, iObjectContainer->AppendL( aTsyObject ) ); |
|
351 |
|
352 if ( KErrNone != trapError ) |
|
353 { |
|
354 //change return value to indicate out of memory error |
|
355 ret = KErrNoMemory; |
|
356 } |
|
357 else |
|
358 { |
|
359 //success return value |
|
360 ret = KErrNone; |
|
361 } |
|
362 } |
|
363 |
|
364 return ret; |
|
365 } |
|
366 |
|
367 // End of File |