|
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: . |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "spbcontentproviderprivate.h" |
|
20 #include "spbcontentprovider.h" |
|
21 #include "spbstatusprovider.h" |
|
22 #include "spbcontent.h" |
|
23 #include "spbcontactstorelistener.h" |
|
24 |
|
25 // CONSTANTS |
|
26 namespace{ |
|
27 |
|
28 /// Status info cache size |
|
29 const TInt KSpbStatusInfoCacheSize = 20; |
|
30 } |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // CSpbContentProviderPrivate::NewL |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 CSpbContentProviderPrivate* CSpbContentProviderPrivate::NewL( |
|
37 CVPbkContactManager& aContactManager, |
|
38 CPbk2StoreManager& aStoreManager, |
|
39 TInt32 aFeatures ) |
|
40 { |
|
41 CSpbContentProviderPrivate* self = new (ELeave) CSpbContentProviderPrivate( |
|
42 aContactManager, aStoreManager, aFeatures ); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CSpbContentProviderPrivate::CSpbContentProviderPrivate |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 inline CSpbContentProviderPrivate::CSpbContentProviderPrivate( |
|
54 CVPbkContactManager& aContactManager, |
|
55 CPbk2StoreManager& aStoreManager, |
|
56 TInt32 aFeatures) : |
|
57 iContactManager(aContactManager), |
|
58 iStoreManager( aStoreManager ), |
|
59 iFeatures(aFeatures), |
|
60 iContentCache( KSpbStatusInfoCacheSize ) |
|
61 { |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CSpbContentProviderPrivate::ConstructL |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 inline void CSpbContentProviderPrivate::ConstructL() |
|
69 { |
|
70 if( IsFeature( CSpbContentProvider::EStatusMessage ) ) |
|
71 { |
|
72 iStatusProvider = CSpbStatusProvider::NewL( iContentCache ); |
|
73 |
|
74 // icon service can only exist with status service |
|
75 if( IsFeature( CSpbContentProvider::EServiceIcon ) ) |
|
76 { |
|
77 iIconProvider = CSpbServiceIconProvider::NewL(); |
|
78 } |
|
79 } |
|
80 if( IsFeature( CSpbContentProvider::EPhoneNumber ) ) |
|
81 { |
|
82 // create contact store listener |
|
83 iStoreListener = CSpbContactStoreListener::NewL( |
|
84 iStoreManager, iContentCache ); |
|
85 } |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CSpbContentProviderPrivate::~CSpbContentProviderPrivate |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 CSpbContentProviderPrivate::~CSpbContentProviderPrivate() |
|
93 { |
|
94 delete iIconProvider; |
|
95 delete iStatusProvider; |
|
96 delete iStoreListener; |
|
97 iObservers.Close(); |
|
98 iContentCache.ResetAndDestroy(); |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CSpbContentProviderPrivate::ContentByLinkL |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 CSpbContent* CSpbContentProviderPrivate::ContentByLinkL( |
|
106 const MVPbkContactLink& aLink ) |
|
107 { |
|
108 const TInt count( iContentCache.Count() ); |
|
109 for( TInt i = 0 ; i < count ; ++i ) |
|
110 { |
|
111 CSpbContent* content = iContentCache[i]; |
|
112 if( content->Match( aLink ) ) |
|
113 { |
|
114 iContentCache.Remove( i ); |
|
115 iContentCache.InsertL( content, 0 ); |
|
116 return content; |
|
117 } |
|
118 } |
|
119 return NULL; |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CSpbContentProviderPrivate::GetContentL |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void CSpbContentProviderPrivate::GetContentL( |
|
127 MVPbkContactLink& aLink, |
|
128 HBufC*& aText, |
|
129 TPbk2IconId& aIconId, |
|
130 CSpbContentProvider::TSpbContentType& aType ) |
|
131 { |
|
132 aType = CSpbContentProvider::ETypeNone; |
|
133 CSpbContent* content = ContentByLinkL(aLink); |
|
134 if( !content ) |
|
135 { |
|
136 // new contact -> fetch and cache |
|
137 CSpbContent::TParameters parameters; |
|
138 parameters.iContactManager = &iContactManager; |
|
139 parameters.iFeatures = iFeatures; |
|
140 parameters.iObservers = &iObservers; |
|
141 parameters.iIconProvider = iIconProvider; |
|
142 parameters.iStatusProvider = iStatusProvider; |
|
143 |
|
144 CSpbContent* content = CSpbContent::NewLC(parameters, aLink); |
|
145 iContentCache.InsertL(content, 0); |
|
146 CleanupStack::Pop(content); |
|
147 |
|
148 // limit cache size |
|
149 const TInt contentCount = iContentCache.Count(); |
|
150 if(contentCount > KSpbStatusInfoCacheSize) |
|
151 { |
|
152 delete iContentCache[contentCount-1]; |
|
153 iContentCache.Remove(contentCount-1); |
|
154 } |
|
155 } |
|
156 else if( content->IsReady() ) |
|
157 { |
|
158 // cached value ready |
|
159 const TDesC& txt = content->Text(); |
|
160 if( txt.Length() ) |
|
161 { |
|
162 aText = txt.AllocL(); |
|
163 aIconId = content->IconId(); |
|
164 aType = content->Type(); |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 // end of file |