|
1 /* |
|
2 * Copyright (c) 2009 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: Content info container |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "spbcontent.h" |
|
19 #include "spbstatusprovider.h" |
|
20 #include "spbserviceiconprovider.h" |
|
21 #include "spbphonenumberparser.h" |
|
22 |
|
23 // LOCAL METHODS AND CONSTANTS |
|
24 namespace { |
|
25 |
|
26 inline TBool IsFlag( TInt aFlags, TInt aFlag ) |
|
27 { |
|
28 return ( aFlags & aFlag ); |
|
29 } |
|
30 } |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // CSpbContent::NewLC |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 CSpbContent* CSpbContent::NewLC( |
|
37 const CSpbContent::TParameters& aParameters, |
|
38 const MVPbkContactLink& aLink) |
|
39 { |
|
40 CSpbContent* self = new (ELeave) CSpbContent( aParameters ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(aLink); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // CSpbContent::~CSpbContent |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 CSpbContent::~CSpbContent() |
|
51 { |
|
52 delete iBuddyId; |
|
53 delete iLink; |
|
54 delete iText; |
|
55 delete iPhoneNumberParser; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CSpbContent::ConstructL |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 inline void CSpbContent::ConstructL(const MVPbkContactLink& aLink) |
|
63 { |
|
64 iLink = aLink.CloneLC(); |
|
65 CleanupStack::Pop(); // iLink |
|
66 |
|
67 if( IsFlag(iParameters.iFeatures, CSpbContentProvider::EPhoneNumber) ) |
|
68 { |
|
69 iPhoneNumberParser = CSpbPhoneNumberParser::NewL( |
|
70 *(iParameters.iContactManager), *this ); |
|
71 } |
|
72 |
|
73 iAsyncCallBack.CallBack(); |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CSpbContent::CSpbContent |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 inline CSpbContent::CSpbContent( |
|
81 const CSpbContent::TParameters& aParameters ) : |
|
82 iParameters(aParameters), |
|
83 iAsyncCallBack( TCallBack( CSpbContent::StartFetchContentL, this ), |
|
84 CActive::EPriorityStandard ), |
|
85 iType( CSpbContentProvider::ETypeNone ) |
|
86 { |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CSpbContent::RefreshNumber |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 void CSpbContent::RefreshNumberL() |
|
94 { |
|
95 // if no status text |
|
96 if( iType != CSpbContentProvider::ETypeSocialStatus && iPhoneNumberParser ) |
|
97 { |
|
98 // re-fetch phonenumber |
|
99 iPhoneNumberParser->FetchPhoneNumberL( Link() ); |
|
100 } |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CSpbContent::StartFetchContent |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CSpbContent::StartFetchContentL( TAny* aPtr ) |
|
108 { |
|
109 static_cast<CSpbContent*>(aPtr)->DoStartFetchContentL(); |
|
110 return 0; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CSpbContent::PhoneNumberUpdatedL |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 void CSpbContent::DoStartFetchContentL() |
|
118 { |
|
119 TBool fetching = EFalse; |
|
120 if( iParameters.iStatusProvider ) |
|
121 { |
|
122 TRAPD( err, iParameters.iStatusProvider->FetchStatusDataL(*this) ); |
|
123 fetching = ( err == KErrNone ); |
|
124 } |
|
125 |
|
126 if( !fetching && iPhoneNumberParser) |
|
127 { |
|
128 iPhoneNumberParser->FetchPhoneNumberL(Link()); |
|
129 fetching = ETrue; |
|
130 } |
|
131 |
|
132 if( !fetching ) |
|
133 { |
|
134 NotifyObservers( MSpbContentProviderObserver::EContentNotAvailable ); |
|
135 } |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // CSpbContent::PhoneNumberUpdatedL |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CSpbContent::PhoneNumberUpdatedL( const TDesC& aPhoneNumber, |
|
143 CSpbContentProvider::TSpbContentType aType ) |
|
144 { |
|
145 delete iText; |
|
146 iText = NULL; |
|
147 iType = CSpbContentProvider::ETypeNone; |
|
148 iReady = EFalse; |
|
149 |
|
150 if( aPhoneNumber.Length() ) |
|
151 { |
|
152 iText = aPhoneNumber.AllocL(); |
|
153 iReady = ETrue; |
|
154 iType = aType; |
|
155 } |
|
156 NotifyObservers(MSpbContentProviderObserver::EContentChanged); |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------------------------- |
|
160 // CSpbContent::StatusDataUpdatedL |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void CSpbContent::StatusDataUpdatedL( |
|
164 const TDesC& aStatusMessage, |
|
165 const TDesC8& aBrandId, |
|
166 const TDesC8& aIconEntry ) |
|
167 { |
|
168 if(!aStatusMessage.Length() && iPhoneNumberParser ) |
|
169 { |
|
170 iPhoneNumberParser->FetchPhoneNumberL(Link()); |
|
171 return; |
|
172 } |
|
173 |
|
174 delete iText; |
|
175 iText = NULL; |
|
176 if(aStatusMessage.Length()) |
|
177 { |
|
178 if(iParameters.iIconProvider && aBrandId.Length() && aIconEntry.Length() ) |
|
179 { |
|
180 MSpbServiceIcon* icon = |
|
181 iParameters.iIconProvider->GetBrandedIconL( aBrandId, aIconEntry ); |
|
182 iIconId = icon->IconId(); |
|
183 } |
|
184 |
|
185 iText = aStatusMessage.AllocL(); |
|
186 iReady = ETrue; |
|
187 iType = CSpbContentProvider::ETypeSocialStatus; |
|
188 NotifyObservers(MSpbContentProviderObserver::EContentChanged); |
|
189 } |
|
190 else |
|
191 { |
|
192 iReady = EFalse; |
|
193 iType = CSpbContentProvider::ETypeNone; |
|
194 NotifyObservers(MSpbContentProviderObserver::EContentNotAvailable); |
|
195 } |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CSpbContent::NotifyObservers |
|
200 // ---------------------------------------------------------------------------- |
|
201 // |
|
202 void CSpbContent::NotifyObservers( |
|
203 MSpbContentProviderObserver::TSpbContentEvent aEvent) |
|
204 { |
|
205 const TInt count(iParameters.iObservers->Count()); |
|
206 for(TInt i = 0 ; i < count ; ++i) |
|
207 { |
|
208 (*iParameters.iObservers)[i]->ContentUpdated(*iLink,aEvent); |
|
209 } |
|
210 } |
|
211 |
|
212 // end of file |