|
42
|
1 |
|
|
|
2 |
/*
|
|
|
3 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
4 |
* All rights reserved.
|
|
|
5 |
* This component and the accompanying materials are made available
|
|
|
6 |
* under the terms of "Eclipse Public License v1.0"
|
|
|
7 |
* which accompanies this distribution, and is available
|
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
9 |
*
|
|
|
10 |
* Initial Contributors:
|
|
|
11 |
* Nokia Corporation - initial contribution.
|
|
|
12 |
*
|
|
|
13 |
* Contributors:
|
|
|
14 |
*
|
|
|
15 |
* Description: Helper class for creating mediaobjects for testing CVideoListDataModel class methods*
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
// INCLUDES
|
|
|
19 |
|
|
|
20 |
#include <mpxmediageneraldefs.h>
|
|
|
21 |
#include <mpxmediaarray.h>
|
|
|
22 |
#include <mpxmedia.h>
|
|
|
23 |
#include <qdatetime.h>
|
|
|
24 |
#include "vcxmyvideosdefs.h"
|
|
|
25 |
#include "mediaobjectfactory.h"
|
|
|
26 |
|
|
|
27 |
// -----------------------------------------------------------------------------
|
|
|
28 |
// MediaObjectFactory
|
|
|
29 |
// -----------------------------------------------------------------------------
|
|
|
30 |
//
|
|
|
31 |
MediaObjectFactory::MediaObjectFactory() :
|
|
|
32 |
mArray(0)
|
|
|
33 |
{
|
|
|
34 |
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
// -----------------------------------------------------------------------------
|
|
|
38 |
// ~MediaObjectFactory
|
|
|
39 |
// -----------------------------------------------------------------------------
|
|
|
40 |
//
|
|
|
41 |
MediaObjectFactory::~MediaObjectFactory()
|
|
|
42 |
{
|
|
|
43 |
removeArray();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// -----------------------------------------------------------------------------
|
|
|
47 |
// mediaArray
|
|
|
48 |
// -----------------------------------------------------------------------------
|
|
|
49 |
//
|
|
|
50 |
CMPXMediaArray* MediaObjectFactory::mediaArray()
|
|
|
51 |
{
|
|
|
52 |
return mArray;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// -----------------------------------------------------------------------------
|
|
|
56 |
// copyOfMediaArray
|
|
|
57 |
// -----------------------------------------------------------------------------
|
|
|
58 |
//
|
|
|
59 |
CMPXMediaArray* MediaObjectFactory::copyOfMediaArray()
|
|
|
60 |
{
|
|
|
61 |
CMPXMediaArray *copyArray = 0;
|
|
|
62 |
if(mArray)
|
|
|
63 |
{
|
|
|
64 |
TRAP_IGNORE(copyArray = CMPXMediaArray::NewL(*mArray));
|
|
|
65 |
}
|
|
|
66 |
return copyArray;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
// -----------------------------------------------------------------------------
|
|
|
70 |
// createMediaItems
|
|
|
71 |
// -----------------------------------------------------------------------------
|
|
|
72 |
//
|
|
|
73 |
void MediaObjectFactory::createMediaItems(int count, int flags)
|
|
|
74 |
{
|
|
|
75 |
if(!mArray)
|
|
|
76 |
{
|
|
|
77 |
TRAPD(error, mArray = CMPXMediaArray::NewL() )
|
|
|
78 |
if(!mArray)
|
|
|
79 |
{
|
|
|
80 |
return;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
int nextPossibleIndex = mArray->Count();
|
|
|
84 |
|
|
|
85 |
// - create 10 media objects and add them into array
|
|
|
86 |
CMPXMedia *media;
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
for(int i = 0; i < count; ++i)
|
|
|
90 |
{
|
|
|
91 |
media = getMedia(i, flags);
|
|
|
92 |
if(!media)
|
|
|
93 |
{
|
|
|
94 |
delete mArray;
|
|
|
95 |
mArray = 0;
|
|
|
96 |
return;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
TRAPD(error, mArray->AppendL(media));
|
|
|
101 |
if(error != KErrNone)
|
|
|
102 |
{
|
|
|
103 |
delete mArray;
|
|
|
104 |
mArray = 0;
|
|
|
105 |
return;
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
// -----------------------------------------------------------------------------
|
|
|
112 |
// createCollectionItems
|
|
|
113 |
// -----------------------------------------------------------------------------
|
|
|
114 |
//
|
|
|
115 |
void MediaObjectFactory::createCollectionItems()
|
|
|
116 |
{
|
|
|
117 |
if(!mArray)
|
|
|
118 |
{
|
|
|
119 |
TRAPD(error, mArray = CMPXMediaArray::NewL() )
|
|
|
120 |
if(!mArray)
|
|
|
121 |
{
|
|
|
122 |
return;
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
int nextPossibleIndex = mArray->Count();
|
|
|
126 |
|
|
|
127 |
for(int i = 0; i <= KVcxMvcCategoryIdOther; ++i)
|
|
|
128 |
{
|
|
|
129 |
CMPXMedia *media = NULL;
|
|
|
130 |
TRAP_IGNORE(media = CMPXMedia::NewL());
|
|
|
131 |
if(!media)
|
|
|
132 |
{
|
|
|
133 |
return;
|
|
|
134 |
}
|
|
|
135 |
TMPXItemId itemId;
|
|
|
136 |
|
|
|
137 |
// set media id
|
|
|
138 |
/**
|
|
|
139 |
* My Videos Collection category IDs.
|
|
|
140 |
* MPX ID has this as iId1 member and 1 as iId2.
|
|
|
141 |
* These are same as indexes in path.
|
|
|
142 |
*/
|
|
|
143 |
itemId.iId1 = i;
|
|
|
144 |
itemId.iId2 = 1;
|
|
|
145 |
TRAPD(error, media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, itemId));
|
|
|
146 |
if(error != KErrNone)
|
|
|
147 |
{
|
|
|
148 |
delete media;
|
|
|
149 |
return;
|
|
|
150 |
}
|
|
|
151 |
if(!media)
|
|
|
152 |
{
|
|
|
153 |
delete mArray;
|
|
|
154 |
mArray = 0;
|
|
|
155 |
return;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
TRAP(error, mArray->AppendL(media));
|
|
|
159 |
if(error != KErrNone)
|
|
|
160 |
{
|
|
|
161 |
delete mArray;
|
|
|
162 |
mArray = 0;
|
|
|
163 |
return;
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
// -----------------------------------------------------------------------------
|
|
|
169 |
// getMedia
|
|
|
170 |
// -----------------------------------------------------------------------------
|
|
|
171 |
//
|
|
|
172 |
CMPXMedia* MediaObjectFactory::getMedia(int index, int dataSelectionFlags)
|
|
|
173 |
{
|
|
|
174 |
CMPXMedia *media = NULL;
|
|
|
175 |
TRAP_IGNORE(media = CMPXMedia::NewL());
|
|
|
176 |
if(!media)
|
|
|
177 |
{
|
|
|
178 |
return 0;
|
|
|
179 |
}
|
|
|
180 |
TBuf<65> videoname;
|
|
|
181 |
TMPXItemId itemId;
|
|
|
182 |
|
|
|
183 |
// set media id
|
|
|
184 |
if(dataSelectionFlags & MediaDataId)
|
|
|
185 |
{
|
|
|
186 |
itemId.iId1 = index;//category all
|
|
|
187 |
itemId.iId2 = 0;//iId2 = 1 for category item
|
|
|
188 |
TRAPD(error, media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, itemId));
|
|
|
189 |
if(error != KErrNone)
|
|
|
190 |
{
|
|
|
191 |
delete media;
|
|
|
192 |
return 0;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
// set media name
|
|
|
196 |
if(dataSelectionFlags & MediaDataName)
|
|
|
197 |
{
|
|
|
198 |
videoname.Format(KMediaTestNamePrefix, index);
|
|
|
199 |
TRAPD(error, media->SetTextValueL( KMPXMediaGeneralTitle, videoname));
|
|
|
200 |
if(error != KErrNone)
|
|
|
201 |
{
|
|
|
202 |
delete media;
|
|
|
203 |
return 0;
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
// set media rating
|
|
|
208 |
if(dataSelectionFlags & MediaDataRatingFlag)
|
|
|
209 |
{
|
|
|
210 |
// index: 0 1 2 3 4 5 6 7 8 9 ...
|
|
|
211 |
// value: 1 2 3 4 5 1 2 3 ...
|
|
|
212 |
int rating = (index%5) + 1;
|
|
|
213 |
TRAPD(error, media->SetTObjectValueL<TInt>(KVcxMediaMyVideosRating, rating));
|
|
|
214 |
if(error != KErrNone)
|
|
|
215 |
{
|
|
|
216 |
delete media;
|
|
|
217 |
return 0;
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
// set media date
|
|
|
222 |
if(dataSelectionFlags & MediaDataDateFlag)
|
|
|
223 |
{
|
|
|
224 |
TDateTime dateTime;
|
|
|
225 |
dateTime.Set(2009, TMonth(index), index, index+1, index+1, index+1, index+1);
|
|
|
226 |
TTime ttimeDate(dateTime);
|
|
|
227 |
TInt64 temp= ttimeDate.Int64();
|
|
|
228 |
TRAPD(error, media->SetTObjectValueL<TInt64>(KMPXMediaGeneralDate, ttimeDate.Int64()));
|
|
|
229 |
if(error != KErrNone)
|
|
|
230 |
{
|
|
|
231 |
delete media;
|
|
|
232 |
return 0;
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
// set duration
|
|
|
237 |
if(dataSelectionFlags & MediaDataDurationFlag)
|
|
|
238 |
{
|
|
|
239 |
float duration = 1.0 + index;
|
|
|
240 |
TRAPD(error, media->SetTObjectValueL<float>(KVcxMediaMyVideosDuration, duration));
|
|
|
241 |
if(error != KErrNone)
|
|
|
242 |
{
|
|
|
243 |
delete media;
|
|
|
244 |
return 0;
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
// set size
|
|
|
249 |
if(dataSelectionFlags & MediaDataSizeFlag)
|
|
|
250 |
{
|
|
|
251 |
quint32 size = 1.0 + index;
|
|
|
252 |
TRAPD(error, media->SetTObjectValueL<quint32>(KMPXMediaGeneralSize, size));
|
|
|
253 |
if(error != KErrNone)
|
|
|
254 |
{
|
|
|
255 |
delete media;
|
|
|
256 |
return 0;
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
// set age profile
|
|
|
261 |
if(dataSelectionFlags & MediaDataAgeProfile)
|
|
|
262 |
{
|
|
|
263 |
// index: 0 1 2 3 4 5 6 7 8 9 ...
|
|
|
264 |
// value: 1 2 3 4 5 1 2 3 ...
|
|
|
265 |
quint32 profile = (index%5) + 1;
|
|
|
266 |
TRAPD(error, media->SetTObjectValueL<quint32>(KVcxMediaMyVideosAgeProfile, profile));
|
|
|
267 |
if(error != KErrNone)
|
|
|
268 |
{
|
|
|
269 |
delete media;
|
|
|
270 |
return 0;
|
|
|
271 |
}
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
// set "filepath"
|
|
|
275 |
if(dataSelectionFlags & MediaDataFilePath)
|
|
|
276 |
{
|
|
|
277 |
videoname.Format(KMediaTestPathPrefix, index);
|
|
|
278 |
TRAPD(error, media->SetTextValueL( KMPXMediaGeneralUri, videoname));
|
|
|
279 |
if(error != KErrNone)
|
|
|
280 |
{
|
|
|
281 |
delete media;
|
|
|
282 |
return 0;
|
|
|
283 |
}
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
// set description
|
|
|
287 |
if(dataSelectionFlags & MediaDataDesc)
|
|
|
288 |
{
|
|
|
289 |
videoname.Format(KMediaTestDescPrefix, index);
|
|
|
290 |
TRAPD(error, media->SetTextValueL( KMPXMediaGeneralComment, videoname));
|
|
|
291 |
if(error != KErrNone)
|
|
|
292 |
{
|
|
|
293 |
delete media;
|
|
|
294 |
return 0;
|
|
|
295 |
}
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
// set author
|
|
|
299 |
if(dataSelectionFlags & MediaDataAuthor)
|
|
|
300 |
{
|
|
|
301 |
videoname.Format(KMediaTestAuthorPrefix, index);
|
|
|
302 |
TRAPD(error, media->SetTextValueL( KVcxMediaMyVideosAuthor, videoname));
|
|
|
303 |
if(error != KErrNone)
|
|
|
304 |
{
|
|
|
305 |
delete media;
|
|
|
306 |
return 0;
|
|
|
307 |
}
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
// set copyright
|
|
|
311 |
if(dataSelectionFlags & MediaDataCopyright)
|
|
|
312 |
{
|
|
|
313 |
videoname.Format(KMediaTestCopyrightPrefix, index);
|
|
|
314 |
TRAPD(error, media->SetTextValueL( KMPXMediaGeneralCopyright, videoname));
|
|
|
315 |
if(error != KErrNone)
|
|
|
316 |
{
|
|
|
317 |
delete media;
|
|
|
318 |
return 0;
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
// set language
|
|
|
323 |
if(dataSelectionFlags & MediaDataLanguage)
|
|
|
324 |
{
|
|
|
325 |
videoname.Format(KMediaTestLanguagePrefix, index);
|
|
|
326 |
TRAPD(error, media->SetTextValueL( KVcxMediaMyVideosAudioLanguage, videoname));
|
|
|
327 |
if(error != KErrNone)
|
|
|
328 |
{
|
|
|
329 |
delete media;
|
|
|
330 |
return 0;
|
|
|
331 |
}
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
// set format
|
|
|
335 |
if(dataSelectionFlags & MediaDataFormat)
|
|
|
336 |
{
|
|
|
337 |
videoname.Format(KMediaTestFormatPrefix, index);
|
|
|
338 |
TRAPD(error, media->SetTextValueL( KMPXMediaGeneralMimeType, videoname));
|
|
|
339 |
if(error != KErrNone)
|
|
|
340 |
{
|
|
|
341 |
delete media;
|
|
|
342 |
return 0;
|
|
|
343 |
}
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
// set media modified date
|
|
|
347 |
if(dataSelectionFlags & MediaDataModified)
|
|
|
348 |
{
|
|
|
349 |
QDateTime date = QDateTime::currentDateTime();
|
|
|
350 |
date = date.addDays((index+1)*2);
|
|
|
351 |
|
|
|
352 |
TDateTime dateTime;
|
|
|
353 |
|
|
|
354 |
dateTime.Set(date.date().year(), TMonth(date.date().month() - 1), date.date().day(),
|
|
|
355 |
date.time().hour(), date.time().minute(),
|
|
|
356 |
date.time().second(), date.time().msec());
|
|
|
357 |
TTime ttimeDate(dateTime);
|
|
|
358 |
TInt64 temp= ttimeDate.Int64();
|
|
|
359 |
TRAPD(error, media->SetTObjectValueL<TInt64>(KVcxMediaMyVideosModifiedDate, ttimeDate.Int64()));
|
|
|
360 |
if(error != KErrNone)
|
|
|
361 |
{
|
|
|
362 |
delete media;
|
|
|
363 |
return 0;
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
return media;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
// -----------------------------------------------------------------------------
|
|
|
371 |
// removeArray
|
|
|
372 |
// -----------------------------------------------------------------------------
|
|
|
373 |
//
|
|
|
374 |
void MediaObjectFactory::removeArray()
|
|
|
375 |
{
|
|
|
376 |
delete mArray;
|
|
|
377 |
mArray = 0;
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
// End of file
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|