|
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 "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: contact presence |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32debug.h> |
|
23 #include <cbsfactory.h> |
|
24 #include <flogger.h> |
|
25 |
|
26 #include "contactpresence.h" |
|
27 #include <mcontactpresenceobs.h> |
|
28 #include "presenceiconinfo.h" |
|
29 #include "presencebrandedicon.h" |
|
30 |
|
31 #include "presenceiconinfolistener.h" |
|
32 |
|
33 #include <contactpresencebrandids.h> |
|
34 |
|
35 const TInt KDefaultBitmapSize(10); |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 // |
|
39 |
|
40 // ---------------------------------------------------------- |
|
41 // CContactPresence::CContactPresence |
|
42 // ---------------------------------------------------------- |
|
43 // |
|
44 CContactPresence::CContactPresence( MContactPresenceObs& aObs ) |
|
45 : iObs( aObs ), |
|
46 iIconReqList(CPresenceBrandedIcon::LinkOffset() ) |
|
47 { |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------- |
|
51 // CContactPresence::~CContactPresence |
|
52 // ---------------------------------------------------------- |
|
53 // |
|
54 CContactPresence::~CContactPresence() |
|
55 { |
|
56 #ifdef _DEBUG |
|
57 CContactPresence::WriteToLog( _L8( "CContactPresence::~CContactPresence starts this=%d" ),(TInt)this ); |
|
58 #endif |
|
59 DeleteAllRequests(); |
|
60 delete iBrandingFactory; |
|
61 |
|
62 delete iListener; |
|
63 iListener = NULL; |
|
64 |
|
65 #ifdef _DEBUG |
|
66 CContactPresence::WriteToLog( _L8( "CContactPresence::~CContactPresence ends this=%d" ),(TInt)this ); |
|
67 #endif |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CContactPresence::Close |
|
72 // ----------------------------------------------------------------------------- |
|
73 void CContactPresence::Close() |
|
74 { |
|
75 delete this; |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------- |
|
79 // CContactPresence::NewL |
|
80 // ---------------------------------------------------------- |
|
81 // |
|
82 CContactPresence* CContactPresence::NewL( |
|
83 MContactPresenceObs& aObs ) |
|
84 { |
|
85 CContactPresence* self = new (ELeave) CContactPresence(aObs ); |
|
86 CleanupStack::PushL( self ); |
|
87 self->ConstructL( NULL ); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------- |
|
93 // CContactPresence::NewL |
|
94 // ---------------------------------------------------------- |
|
95 // |
|
96 CContactPresence* CContactPresence::NewL( |
|
97 CVPbkContactManager& aContactManager, |
|
98 MContactPresenceObs& aObs ) |
|
99 { |
|
100 CContactPresence* self = new (ELeave) CContactPresence(aObs ); |
|
101 CleanupStack::PushL( self ); |
|
102 self->ConstructL( &aContactManager ); |
|
103 CleanupStack::Pop( self ); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CContactPresence::ConstructL |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CContactPresence::ConstructL( CVPbkContactManager* aManager ) |
|
112 { |
|
113 #ifdef _DEBUG |
|
114 CContactPresence::WriteToLog( _L8( "CContactPresence::ConstructL this=%d" ), (TInt)this ); |
|
115 #endif |
|
116 iBrandingFactory = CBSFactory::NewL(KCPBrandDefaultId, KCPBrandAppId ); |
|
117 iSize.SetSize( KDefaultBitmapSize, KDefaultBitmapSize ); |
|
118 |
|
119 iListener = CPresenceIconInfoListener::NewL( aManager, iObs ); |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------- |
|
123 // CContactPresence::SubscribePresenceInfoL |
|
124 // ---------------------------------------------------------- |
|
125 // |
|
126 void CContactPresence::SubscribePresenceInfoL( |
|
127 const MDesC8Array& aLinkArray ) |
|
128 { |
|
129 #ifdef _DEBUG |
|
130 TInt count = aLinkArray.MdcaCount(); |
|
131 CContactPresence::WriteToLog( _L8( "CContactPresence::SubscribePresenceInfoL array count=%d this=%d" ), count, (TInt)this ); |
|
132 #endif |
|
133 iListener->SubscribePresenceInfoL( aLinkArray ); |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------- |
|
137 // CContactPresence::GetPresenceIconFileL |
|
138 // ---------------------------------------------------------- |
|
139 // |
|
140 TInt CContactPresence::GetPresenceIconFileL( |
|
141 const TDesC8& aBrandId, |
|
142 const TDesC8& aElementId /*AKA aImageId*/ ) |
|
143 { |
|
144 #ifdef _DEBUG |
|
145 CContactPresence::WriteToLog( _L8( "CContactPresence::GetPresenceIconFileL this=%d" ), (TInt)this ); |
|
146 #endif |
|
147 // We always create a new instance, since they delete itself in complication |
|
148 iOpId++; |
|
149 |
|
150 CPresenceBrandedIcon* icon = CPresenceBrandedIcon::NewL(iBrandingFactory, iObs ); |
|
151 iIconReqList.AddLast( *icon ); |
|
152 icon->StartGetIconInfoL( iOpId, aBrandId, aElementId, iSize ); |
|
153 |
|
154 return iOpId; |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------- |
|
158 // |
|
159 TInt CContactPresence::GetPresenceInfoL( const TDesC8& aPackedLink ) |
|
160 { |
|
161 #ifdef _DEBUG |
|
162 CContactPresence::WriteToLog( _L8( "CContactPresence::GetPresenceInfoL this=%d" ), (TInt)this ); |
|
163 #endif |
|
164 iOpId++; |
|
165 |
|
166 CPresenceBrandedIcon* icon = CPresenceBrandedIcon::NewL(iBrandingFactory, iObs ); |
|
167 iIconReqList.AddLast( *icon ); |
|
168 iListener->GetPresenceInfoL( aPackedLink, iOpId ); |
|
169 |
|
170 return iOpId; |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------- |
|
174 // CContactPresence::SetPresenceIconSize |
|
175 // ---------------------------------------------------------- |
|
176 // |
|
177 void CContactPresence::SetPresenceIconSize( |
|
178 const TSize aSize ) |
|
179 { |
|
180 iSize = aSize; |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------- |
|
184 // CContactPresence::CancelSubscribePresenceInfo |
|
185 // ---------------------------------------------------------- |
|
186 // |
|
187 void CContactPresence::CancelSubscribePresenceInfo( const MDesC8Array& aLinkArray ) |
|
188 { |
|
189 #ifdef _DEBUG |
|
190 CContactPresence::WriteToLog( _L8( "CContactPresence::CancelSubscribePresenceInfo this=%d" ), (TInt)this ); |
|
191 #endif |
|
192 |
|
193 iListener->CancelSubscribePresenceInfo( aLinkArray ); |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------- |
|
197 // CContactPresence::CancelAll |
|
198 // ---------------------------------------------------------- |
|
199 // |
|
200 void CContactPresence::CancelAll() |
|
201 { |
|
202 #ifdef _DEBUG |
|
203 CContactPresence::WriteToLog( _L8( "CContactPresence::CancelAll this=%d" ), (TInt)this ); |
|
204 #endif |
|
205 DeleteAllRequests(); |
|
206 } |
|
207 |
|
208 // ---------------------------------------------------------- |
|
209 // CContactPresence::CancelOperation |
|
210 // ---------------------------------------------------------- |
|
211 // |
|
212 void CContactPresence::CancelOperation( TInt aOpId ) |
|
213 { |
|
214 #ifdef _DEBUG |
|
215 CContactPresence::WriteToLog( _L8( "CContactPresence::CancelOperation this=%d" ), (TInt)this ); |
|
216 #endif |
|
217 |
|
218 // synchronous is good enough |
|
219 CPresenceBrandedIcon* iconH = CContactPresence::SearchBrandedIcon( aOpId ); |
|
220 if ( iconH ) |
|
221 { |
|
222 iconH->Cancel(); |
|
223 iconH->Destroy(); |
|
224 } |
|
225 else |
|
226 { |
|
227 iListener->CancelGet( aOpId ); |
|
228 } |
|
229 return; |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------- |
|
233 // |
|
234 void CContactPresence::DeleteAllRequests() |
|
235 { |
|
236 if ( iListener ) |
|
237 { |
|
238 iListener->DeleteAllRequests(); |
|
239 } |
|
240 else |
|
241 { |
|
242 } |
|
243 |
|
244 TDblQueIter<CPresenceBrandedIcon> rIter2( iIconReqList ); |
|
245 rIter2.SetToFirst(); |
|
246 |
|
247 while ( rIter2 ) |
|
248 { |
|
249 CPresenceBrandedIcon* req2 = rIter2; |
|
250 rIter2++; |
|
251 req2->Destroy(); |
|
252 } |
|
253 |
|
254 return; |
|
255 } |
|
256 |
|
257 // ---------------------------------------------------------- |
|
258 // |
|
259 CPresenceBrandedIcon* CContactPresence::SearchBrandedIcon( TInt aOpId ) |
|
260 { |
|
261 TDblQueIter<CPresenceBrandedIcon> rIter( iIconReqList ); |
|
262 rIter.SetToFirst(); |
|
263 |
|
264 while ( rIter ) |
|
265 { |
|
266 CPresenceBrandedIcon* req = rIter; |
|
267 rIter++; |
|
268 if ( req->GetOpId() == aOpId ) |
|
269 { |
|
270 return req; |
|
271 } |
|
272 } |
|
273 return (CPresenceBrandedIcon*)NULL; |
|
274 } |
|
275 |
|
276 #ifdef _DEBUG |
|
277 // ---------------------------------------------------- |
|
278 // CContactPresence::WriteToLog |
|
279 // |
|
280 // ---------------------------------------------------- |
|
281 // |
|
282 void CContactPresence::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) |
|
283 { |
|
284 _LIT( KMyLogDir, "CCA"); |
|
285 _LIT( KMyLogFile, "cp.txt"); |
|
286 const TInt KMyBufferMaxSize = 100; |
|
287 VA_LIST list; |
|
288 VA_START( list, aFmt ); |
|
289 TBuf8<KMyBufferMaxSize> buf; |
|
290 buf.FormatList( aFmt, list ); |
|
291 RFileLogger::Write( KMyLogDir, KMyLogFile, EFileLoggingModeAppend, buf ); |
|
292 RDebug::RawPrint( buf ); |
|
293 } |
|
294 #endif //_DEBUG |
|
295 |