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