|
1 /* |
|
2 * Copyright (c) 2008 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 the License "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: CVcxNsChPublisher class definition* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 #include <LiwServiceHandler.h> |
|
21 #include <LiwVariant.h> |
|
22 #include <LiwGenericParam.h> |
|
23 |
|
24 #include "videochpublishabledata.h" |
|
25 #include "videochpublisher.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 ////// |
|
30 // names used as keys in maps to be passed to service api: |
|
31 |
|
32 // key name for item data |
|
33 _LIT8( KVcxNsSAKeyItem, "item" ); |
|
34 |
|
35 // key name for type data |
|
36 _LIT8( KVcxNsSAKeyType, "type" ); |
|
37 |
|
38 // key name for "add" command -data |
|
39 _LIT8( KVcxNsSAKeyCmdAdd, "Add" ); |
|
40 |
|
41 // key name for "delete" command -data |
|
42 _LIT8( KVcxNsSAKeyCmdDelete, "Delete" ); |
|
43 |
|
44 // key name for Get list command -data |
|
45 _LIT8 ( KVcxNsSAKeyCmdGetList, "GetList" ); |
|
46 |
|
47 // key name for publisher name data |
|
48 _LIT8( KVcxNsSAKeyPublisher, "publisher" ); |
|
49 |
|
50 // key name for content_type data |
|
51 _LIT8( KVcxNsSAKeyContentType, "content_type" ); |
|
52 |
|
53 // key name for content id data |
|
54 _LIT8( KVcxNsSAKeyContentId, "content_id" ); |
|
55 |
|
56 // key name for actual data |
|
57 _LIT8( KVcxNsSAKeyDataMap, "data_map" ); |
|
58 |
|
59 // value key name for results when reading |
|
60 // from CP database |
|
61 _LIT8( KVcxNsSAKeyResults, "results" ); |
|
62 |
|
63 ///////////////// |
|
64 // common values used in result map: |
|
65 |
|
66 // value name used to identify data |
|
67 // from the result liw map in homescreen's |
|
68 // contentpublishing -plugin |
|
69 _LIT ( KVcxNsSapiCPData, "cp_data" ); |
|
70 |
|
71 // publisher value name used for tvvideosuite |
|
72 // related data |
|
73 _LIT( KTvVideoPublisher, "tvvideopublisher" ); |
|
74 |
|
75 // content id's |
|
76 // "normal" id for content used in the matrix menu |
|
77 _LIT( KContentMenuId, "menucontentid" ); |
|
78 // this id can be used to maintain data in CP, but |
|
79 // not show it in the matrix menu |
|
80 _LIT( KContentBackupId, "backupcontentid" ); |
|
81 |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CVcxNsChPublisher::CVcxNsChPublisher |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CVcxNsChPublisher::CVcxNsChPublisher( MLiwInterface* iCPSInterface, |
|
89 CVcxNsChPublishableData* aData ) : |
|
90 iCPSInterface( iCPSInterface ), |
|
91 iPublishableData( aData ), |
|
92 iContentId( 0, 0 ) |
|
93 { |
|
94 // No implementation required |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CVcxNsChPublisher::~CVcxNsChPublisher |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CVcxNsChPublisher::~CVcxNsChPublisher() |
|
102 { |
|
103 // No implementation required |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CVcxNsChPublisher::NewLC |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CVcxNsChPublisher* CVcxNsChPublisher::NewLC( MLiwInterface* aCPInterface, |
|
111 CVcxNsChPublishableData* aData ) |
|
112 { |
|
113 if( !aCPInterface || !aData ) |
|
114 { |
|
115 User::Leave( KErrNotFound ); |
|
116 } |
|
117 |
|
118 CVcxNsChPublisher* self = new (ELeave)CVcxNsChPublisher( aCPInterface, aData ); |
|
119 CleanupStack::PushL(self); |
|
120 self->ConstructL(); |
|
121 return self; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CVcxNsChPublisher::NewL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 CVcxNsChPublisher* CVcxNsChPublisher::NewL( MLiwInterface* aCPInterface, |
|
129 CVcxNsChPublishableData* aData ) |
|
130 { |
|
131 CVcxNsChPublisher* self = CVcxNsChPublisher::NewLC( aCPInterface, aData ); |
|
132 CleanupStack::Pop( self ); // self; |
|
133 return self; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CVcxNsChPublisher::ConstructL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CVcxNsChPublisher::ConstructL() |
|
141 { |
|
142 iContentId.Set( KContentMenuId ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CVcxNsChPublisher::PublishAllL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CVcxNsChPublisher::PublishAllL() |
|
150 { |
|
151 PublishContentL( EVCxNsCPContentLastWatched ); |
|
152 PublishContentL( EVCxNsCPContentLiveTV ); |
|
153 PublishContentL( EVCxNsCPContentIPTV ); |
|
154 PublishContentL( EVCxNsCPContentMyVideos ); |
|
155 PublishContentL( EVCxNsCPContentFeeds ); |
|
156 PublishContentL( EVCxNsCPContentPreloaded ); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CVcxNsChPublisher::PublishContentL |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CVcxNsChPublisher::PublishContentL( TVCxNsCPContentType aContentType ) |
|
164 { |
|
165 CLiwGenericParamList* inParam = CLiwGenericParamList::NewLC(); |
|
166 CLiwGenericParamList* outParam = CLiwGenericParamList::NewLC(); |
|
167 ExecCPCommandL( aContentType, KVcxNsSAKeyCmdAdd, |
|
168 inParam, outParam); |
|
169 CleanupStack::PopAndDestroy( outParam ); |
|
170 CleanupStack::PopAndDestroy( inParam ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CVcxNsChPublisher::DeleteContentL |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CVcxNsChPublisher::DeleteContentL( TVCxNsCPContentType aContentType ) |
|
178 { |
|
179 CLiwGenericParamList* inParam = CLiwGenericParamList::NewLC(); |
|
180 CLiwGenericParamList* outParam = CLiwGenericParamList::NewLC(); |
|
181 ExecCPCommandL( aContentType, KVcxNsSAKeyCmdDelete, |
|
182 inParam, outParam ); |
|
183 CleanupStack::PopAndDestroy( outParam ); |
|
184 CleanupStack::PopAndDestroy( inParam ); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CVcxNsChPublisher::ReadContentL |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CVcxNsChPublisher::ReadContentL( TVCxNsCPContentType aContentType ) |
|
192 { |
|
193 TInt pos( 0 ); |
|
194 CLiwGenericParamList* inParam = CLiwGenericParamList::NewLC(); |
|
195 CLiwGenericParamList* outParam = CLiwGenericParamList::NewLC(); |
|
196 |
|
197 ExecCPCommandL( aContentType, KVcxNsSAKeyCmdGetList, inParam, outParam ); |
|
198 |
|
199 TLiwVariant variant; |
|
200 variant.PushL(); |
|
201 |
|
202 outParam->FindFirst( pos, KVcxNsSAKeyResults ); |
|
203 if( pos != KErrNotFound ) |
|
204 { |
|
205 variant = ( *outParam )[pos].Value(); |
|
206 // get the first iterator data. In tvvideo suite context |
|
207 // we have only one level of data |
|
208 CLiwIterable* iterable = variant.AsIterable(); |
|
209 iterable->Reset(); |
|
210 iterable->NextL( variant ); |
|
211 |
|
212 CLiwDefaultMap* cpDataRootMap = CLiwDefaultMap::NewLC(); |
|
213 if( variant.Get( *cpDataRootMap ) ) |
|
214 { |
|
215 ReadCPResultDataRootL( aContentType, cpDataRootMap ); |
|
216 } |
|
217 |
|
218 CleanupStack::PopAndDestroy( cpDataRootMap ); |
|
219 } |
|
220 CleanupStack::PopAndDestroy( &variant ); |
|
221 CleanupStack::PopAndDestroy(outParam); |
|
222 CleanupStack::PopAndDestroy(inParam); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CVcxNsChPublisher::BackupContentL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CVcxNsChPublisher::BackupContentL( TVCxNsCPContentType aContentType, TBool aRefreshFrDB ) |
|
230 { |
|
231 if( aRefreshFrDB ) |
|
232 { |
|
233 // read content data from default to backup |
|
234 iContentId.Set( KContentMenuId ); |
|
235 ReadContentL( aContentType ); |
|
236 } |
|
237 iContentId.Set( KContentBackupId ); |
|
238 // trap to make sure the default id is switched back |
|
239 // delete old backup |
|
240 TRAPD( err, DeleteContentL( aContentType ) ); |
|
241 if( err == KErrNone ) |
|
242 { |
|
243 TRAP( err, PublishContentL( aContentType ) ); |
|
244 } |
|
245 iContentId.Set( KContentMenuId ); |
|
246 User::LeaveIfError( err ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CVcxNsChPublisher::RestoreBackupL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CVcxNsChPublisher::RestoreBackupL( TVCxNsCPContentType aContentType ) |
|
254 { |
|
255 // read content data from backup to default |
|
256 iContentId.Set( KContentBackupId ); |
|
257 // trap to make sure the default id is swithced back |
|
258 TRAPD( err, ReadContentL( aContentType ) ); |
|
259 if( err == KErrNone ) |
|
260 { |
|
261 // delete old backup |
|
262 TRAP( err, DeleteContentL( aContentType ) ); |
|
263 } |
|
264 iContentId.Set( KContentMenuId ); |
|
265 User::LeaveIfError( err ); |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CVcxNsChPublisher::ReadCPResultDataRootL |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CVcxNsChPublisher::ReadCPResultDataRootL( TVCxNsCPContentType& aContentType, |
|
273 CLiwDefaultMap* aDataRootMap ) |
|
274 { |
|
275 TLiwVariant variant; |
|
276 variant.PushL(); |
|
277 if( aDataRootMap->FindL( KVcxNsSAKeyDataMap, variant ) ) |
|
278 { |
|
279 CLiwDefaultMap* cpDataMap = CLiwDefaultMap::NewLC(); |
|
280 if( variant.Get( *cpDataMap ) ) |
|
281 { |
|
282 iPublishableData->ReadCPDataMapL( aContentType, *cpDataMap ); |
|
283 } |
|
284 CleanupStack::PopAndDestroy( cpDataMap ); |
|
285 } |
|
286 CleanupStack::PopAndDestroy( &variant ); |
|
287 |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CVcxNsChPublisher::ExecCPCommandL |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 void CVcxNsChPublisher::ExecCPCommandL( TVCxNsCPContentType& aContentType, |
|
295 const TDesC8& aCmd, |
|
296 CLiwGenericParamList* aInParam, |
|
297 CLiwGenericParamList* aOutParam ) |
|
298 { |
|
299 // inParammlist -map organisation: |
|
300 // results |
|
301 // |- KVcxNsSAKeyType, KVcxNsSapiCPData |
|
302 // |- KVcxNsSAKeyItem, cpDataRootMap |
|
303 // |- KVcxNsSAKeyPublisher, KTvVideoPublisher |
|
304 // |- KVcxNsSAKeyContentType, < resolved content name > |
|
305 // |- KVcxNsSAKeyContentId, KContentMenuId (for visible content) OR |
|
306 // KContentBackupId (for backed up content) |
|
307 // |- KVcxNsSAKeyDataMap, cpDataMap |
|
308 // |- contains data map generated |
|
309 // in CVcxNsChPublishableData |
|
310 |
|
311 |
|
312 |
|
313 // setup basic data type value |
|
314 TLiwGenericParam cptype( KVcxNsSAKeyType, TLiwVariant( KVcxNsSapiCPData )); |
|
315 aInParam->AppendL( cptype ); |
|
316 |
|
317 CLiwDefaultMap* cpDataRootMap = CLiwDefaultMap::NewLC(); |
|
318 |
|
319 // set up publisher |
|
320 cpDataRootMap->InsertL( KVcxNsSAKeyPublisher, |
|
321 TLiwVariant( KTvVideoPublisher )); |
|
322 // set up content_type |
|
323 TPtrC cType = iPublishableData->ItemContentTypeNameL( aContentType ); |
|
324 cpDataRootMap->InsertL( KVcxNsSAKeyContentType, |
|
325 TLiwVariant( cType ) ); |
|
326 |
|
327 // content_id, just use default value |
|
328 cpDataRootMap->InsertL( KVcxNsSAKeyContentId, |
|
329 TLiwVariant( iContentId )); |
|
330 |
|
331 CLiwDefaultMap* cpDataMap = CLiwDefaultMap::NewLC(); |
|
332 |
|
333 // set the actual data from our data container |
|
334 iPublishableData->FillCPDataMapL( aContentType, *cpDataMap ); |
|
335 |
|
336 // save it to root |
|
337 cpDataRootMap->InsertL( KVcxNsSAKeyDataMap, TLiwVariant( cpDataMap ) ); |
|
338 |
|
339 // data ready, fill item and save it to input param |
|
340 TLiwGenericParam item( KVcxNsSAKeyItem, TLiwVariant( cpDataRootMap )); |
|
341 aInParam->AppendL( item ); |
|
342 |
|
343 CleanupStack::PopAndDestroy( cpDataMap ); |
|
344 CleanupStack::PopAndDestroy( cpDataRootMap ); |
|
345 item.Reset(); |
|
346 cptype.Reset(); |
|
347 |
|
348 iCPSInterface->ExecuteCmdL( aCmd, *aInParam, *aOutParam ); |
|
349 |
|
350 } |
|
351 |