|
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 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 |
|
10 * Initial Contributors: |
|
11 * Nokia Corporation - initial contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: Class representing album in My Videos collection. |
|
16 */ |
|
17 |
|
18 #include <mpxlog.h> |
|
19 #include <mpxmedia.h> |
|
20 #include <mpxmediaarray.h> |
|
21 #include <mpxmediacontainerdefs.h> |
|
22 #include <mpxmediageneraldefs.h> |
|
23 #include "vcxmyvideosalbum.h" |
|
24 #include "vcxmyvideoscollectionplugin.h" |
|
25 #include "vcxmyvideosvideocache.h" |
|
26 #include "vcxmyvideoscollectionutil.h" |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // TVcxMyVideosAlbumVideo::TVcxMyVideosAlbumVideo |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 TVcxMyVideosAlbumVideo::TVcxMyVideosAlbumVideo() |
|
34 { |
|
35 Set( 0, 0, 0 ); |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // TVcxMyVideosAlbumVideo::operator= |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 TVcxMyVideosAlbumVideo& TVcxMyVideosAlbumVideo::operator=( const TVcxMyVideosAlbumVideo& aVideo ) |
|
43 { |
|
44 Set( aVideo.iMdsId, aVideo.iRelationMdsId, aVideo.iMedia ); |
|
45 return *this; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // TVcxMyVideosAlbumVideo::Set |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void TVcxMyVideosAlbumVideo::Set( TUint32 aMdsId, TUint32 aRelationMdsId, CMPXMedia* aVideo ) |
|
53 { |
|
54 iMdsId = aMdsId; |
|
55 iRelationMdsId = aRelationMdsId; |
|
56 iMedia = aVideo; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CVcxMyVideosAlbum::CVcxMyVideosAlbum |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CVcxMyVideosAlbum::CVcxMyVideosAlbum( CVcxMyVideosCollectionPlugin& aCollectionPlugin ) |
|
64 : iCollection( aCollectionPlugin ) |
|
65 { |
|
66 // No implementation required |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CVcxMyVideosAlbum::~CVcxMyVideosAlbum |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CVcxMyVideosAlbum::~CVcxMyVideosAlbum() |
|
74 { |
|
75 iVideoList.Close(); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CVcxMyVideosAlbum::NewLC |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CVcxMyVideosAlbum* CVcxMyVideosAlbum::NewLC( CVcxMyVideosCollectionPlugin& aCollectionPlugin ) |
|
83 { |
|
84 CVcxMyVideosAlbum* self = new (ELeave) CVcxMyVideosAlbum( aCollectionPlugin ); |
|
85 CleanupStack::PushL(self); |
|
86 self->ConstructL(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CVcxMyVideosAlbum::NewL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CVcxMyVideosAlbum* CVcxMyVideosAlbum::NewL( CVcxMyVideosCollectionPlugin& aCollectionPlugin ) |
|
95 { |
|
96 CVcxMyVideosAlbum* self = CVcxMyVideosAlbum::NewLC( aCollectionPlugin ); |
|
97 CleanupStack::Pop( self ); |
|
98 return self; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CVcxMyVideosAlbum::ConstructL |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CVcxMyVideosAlbum::ConstructL() |
|
106 { |
|
107 iVideoList.Reset(); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CVcxMyVideosAlbum::Sort |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CVcxMyVideosAlbum::Sort() |
|
115 { |
|
116 const TLinearOrder<TVcxMyVideosAlbumVideo> KOrderByMdsId( |
|
117 CVcxMyVideosAlbum::CompareVideosByMdsId ); |
|
118 |
|
119 iVideoList.Sort( KOrderByMdsId ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CVcxMyVideosAlbum::SetL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CVcxMyVideosAlbum::SetL( /*CMPXMedia& aAlbum*/ ) |
|
127 { |
|
128 //TODO: |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CVcxMyVideosAlbum::BelongsToAlbum |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 TBool CVcxMyVideosAlbum::BelongsToAlbum( TUint32 aMdsId ) |
|
136 { |
|
137 const TLinearOrder<TVcxMyVideosAlbumVideo> KOrderByMdsId( |
|
138 CVcxMyVideosAlbum::CompareVideosByMdsId ); |
|
139 |
|
140 TInt index; |
|
141 TVcxMyVideosAlbumVideo video; |
|
142 video.iMdsId = aMdsId; |
|
143 TInt err = iVideoList.FindInOrder( video, index, KOrderByMdsId ); |
|
144 |
|
145 if ( err != KErrNone ) |
|
146 { |
|
147 return EFalse; |
|
148 } |
|
149 |
|
150 return ETrue; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CVcxMyVideosAlbum::Video |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 TInt CVcxMyVideosAlbum::Video( TUint32 aMdsId, TVcxMyVideosAlbumVideo& aVideo, TInt& aIndex ) |
|
158 { |
|
159 const TLinearOrder<TVcxMyVideosAlbumVideo> KOrderByMdsId( |
|
160 CVcxMyVideosAlbum::CompareVideosByMdsId ); |
|
161 |
|
162 TVcxMyVideosAlbumVideo videoToFind; |
|
163 videoToFind.iMdsId = aMdsId; |
|
164 TInt err = iVideoList.FindInOrder( videoToFind, aIndex, KOrderByMdsId ); |
|
165 |
|
166 if ( err == KErrNone ) |
|
167 { |
|
168 aVideo = iVideoList[aIndex]; |
|
169 } |
|
170 |
|
171 return err; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CVcxMyVideosAlbum::AddL |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CVcxMyVideosAlbum::AddL( TVcxMyVideosAlbumVideo aVideo ) |
|
179 { |
|
180 const TLinearOrder<TVcxMyVideosAlbumVideo> KOrderByMdsId( |
|
181 CVcxMyVideosAlbum::CompareVideosByMdsId ); |
|
182 |
|
183 iVideoList.InsertInOrderAllowRepeatsL( aVideo, KOrderByMdsId ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CVcxMyVideosAlbum::Remove |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CVcxMyVideosAlbum::Remove( RArray<TUint32>& aMdsIds ) |
|
191 { |
|
192 TInt count = aMdsIds.Count(); |
|
193 for ( TInt i = 0; i < count; i++ ) |
|
194 { |
|
195 Remove( aMdsIds[i], EFalse /* don't compress */ ); |
|
196 } |
|
197 iVideoList.Compress(); |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // CVcxMyVideosAlbum::Remove |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CVcxMyVideosAlbum::Remove( TUint32 aMdsId, TBool aCompress ) |
|
205 { |
|
206 const TLinearOrder<TVcxMyVideosAlbumVideo> KOrderByMdsId( |
|
207 CVcxMyVideosAlbum::CompareVideosByMdsId ); |
|
208 |
|
209 TVcxMyVideosAlbumVideo video; |
|
210 video.iMdsId = aMdsId; |
|
211 TInt pos; |
|
212 TInt err = iVideoList.FindInOrder( video, pos, KOrderByMdsId ); |
|
213 if ( err == KErrNone ) |
|
214 { |
|
215 iVideoList.Remove( pos ); |
|
216 } |
|
217 if ( aCompress ) |
|
218 { |
|
219 iVideoList.Compress(); |
|
220 } |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // CVcxMyVideosAlbum::CompareVideosByMdsId |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 TInt CVcxMyVideosAlbum::CompareVideosByMdsId( const TVcxMyVideosAlbumVideo& aVideo1, |
|
228 const TVcxMyVideosAlbumVideo& aVideo2 ) |
|
229 { |
|
230 if ( aVideo1.iMdsId == aVideo2.iMdsId ) |
|
231 { |
|
232 return 0; |
|
233 } |
|
234 |
|
235 if ( aVideo1.iMdsId < aVideo2.iMdsId ) |
|
236 { |
|
237 return -1; |
|
238 } |
|
239 return 1; |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CVcxMyVideosAlbum::CreateVideoListL |
|
244 // Creates album video list from iCollection.iCache->iVideoList. |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 CMPXMedia* CVcxMyVideosAlbum::CreateVideoListL() |
|
248 { |
|
249 CMPXMedia* toVideoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL(); |
|
250 CleanupStack::PushL( toVideoList ); |
|
251 |
|
252 AppendToVideoListL( *iCollection.iCache->iVideoList, *toVideoList, 0 ); |
|
253 |
|
254 CleanupStack::Pop( toVideoList ); |
|
255 |
|
256 return toVideoList; |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CVcxMyVideosAlbum::CreateVideoListL |
|
261 // Appends to video list the items which belong to this album. |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CVcxMyVideosAlbum::AppendToVideoListL( CMPXMedia& aFromVideoList, |
|
265 CMPXMedia& aToVideoList, TInt aNewItemStartIndex ) |
|
266 { |
|
267 if ( aNewItemStartIndex < 0 ) |
|
268 { |
|
269 return; |
|
270 } |
|
271 |
|
272 CMPXMediaArray* fromArray = aFromVideoList.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
273 CMPXMediaArray* toArray = aToVideoList.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
274 TUint32 mdsId; |
|
275 CMPXMedia* fromVideo; |
|
276 TInt count = fromArray->Count(); |
|
277 for ( TInt i = aNewItemStartIndex; i < count; i++ ) |
|
278 { |
|
279 fromVideo = fromArray->AtL( i ); |
|
280 mdsId = TVcxMyVideosCollectionUtil::IdL( *fromVideo ).iId1; |
|
281 if ( BelongsToAlbum( mdsId ) ) |
|
282 { |
|
283 CMPXMedia* toVideo = CMPXMedia::NewL( *fromVideo ); //share underlying memory |
|
284 CleanupStack::PushL( toVideo ); |
|
285 toArray->AppendL( toVideo ); |
|
286 CleanupStack::Pop( toVideo ); |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CVcxMyVideosAlbum::CalculateAttributesL |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CVcxMyVideosAlbum::CalculateAttributesL( TInt aStartIndex ) |
|
296 { |
|
297 TInt videoCount = 0; |
|
298 TUint32 count = iVideoList.Count(); |
|
299 TInt newCount = 0; |
|
300 CMPXMedia* video; |
|
301 CMPXMedia* latestNewVideo = NULL; |
|
302 TInt pos; |
|
303 TUint32 flags; |
|
304 TInt64 currentItemsCreationDate = 0; |
|
305 TInt64 latestCreationDate = TVcxMyVideosCollectionUtil::CreationDateL( *iMedia ); |
|
306 for ( TInt i = aStartIndex; i < count; i++ ) |
|
307 { |
|
308 video = iCollection.iCache->FindVideoByMdsIdL( iVideoList[i].iMdsId, pos ); |
|
309 if ( video ) |
|
310 { |
|
311 videoCount++; |
|
312 flags = TVcxMyVideosCollectionUtil::FlagsL( *video ); |
|
313 if ( flags & EVcxMyVideosVideoNew ) |
|
314 { |
|
315 newCount++; |
|
316 currentItemsCreationDate = TVcxMyVideosCollectionUtil::CreationDateL( *video ); |
|
317 if ( latestCreationDate < currentItemsCreationDate ) |
|
318 { |
|
319 latestCreationDate = currentItemsCreationDate; |
|
320 latestNewVideo = video; |
|
321 } |
|
322 } |
|
323 } |
|
324 } |
|
325 iMedia->SetTObjectValueL<TUint32>( KVcxMediaMyVideosCategoryItemCount, videoCount ); |
|
326 iMedia->SetTObjectValueL<TUint32>( KVcxMediaMyVideosCategoryNewItemCount, newCount ); |
|
327 if ( latestNewVideo ) |
|
328 { |
|
329 iMedia->SetTextValueL( KVcxMediaMyVideosCategoryNewItemName, |
|
330 TVcxMyVideosCollectionUtil::Title( *latestNewVideo ) ); |
|
331 } |
|
332 iMedia->SetTObjectValueL<TInt64>( KMPXMediaGeneralDate, latestCreationDate ); |
|
333 } |
|
334 |