34
|
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: VideoListDataModel class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
// INCLUDE FILES
|
|
18 |
|
|
19 |
#include <hbglobal.h>
|
|
20 |
#include <vcxmyvideosdefs.h>
|
|
21 |
#include "videolistdatamodel.h"
|
|
22 |
#include "videolistdatamodel_p.h"
|
|
23 |
#include "videocollectionclient.h"
|
|
24 |
#include "videocollectioncommon.h"
|
|
25 |
#include "videocollectionutils.h"
|
|
26 |
#include "videodeleteworker.h"
|
|
27 |
#include "videocollectionwrapper.h"
|
|
28 |
|
|
29 |
|
|
30 |
// ================= MEMBER FUNCTIONS =======================
|
|
31 |
//
|
|
32 |
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
// VideoListDataModel()
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
//
|
|
37 |
VideoListDataModel::VideoListDataModel(QObject *parent) :
|
|
38 |
QAbstractItemModel(parent),
|
|
39 |
d_ptr( new VideoListDataModelPrivate(this)),
|
|
40 |
mCollectionClient(0),
|
|
41 |
mDeleteWorker(0),
|
|
42 |
mInitialized(false)
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
// ~VideoListDataModel()
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
VideoListDataModel::~VideoListDataModel()
|
|
51 |
{
|
|
52 |
delete mDeleteWorker;
|
|
53 |
delete d_ptr;
|
|
54 |
delete mCollectionClient;
|
|
55 |
}
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// initialize()
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
int VideoListDataModel::initialize()
|
|
62 |
{
|
|
63 |
if(mInitialized)
|
|
64 |
{
|
|
65 |
return 0;
|
|
66 |
}
|
|
67 |
if(!mCollectionClient)
|
|
68 |
{
|
|
69 |
mCollectionClient = new VideoCollectionClient();
|
|
70 |
if(!mCollectionClient || mCollectionClient->initialize(d_ptr) < 0)
|
|
71 |
{
|
|
72 |
delete mCollectionClient;
|
|
73 |
mCollectionClient = 0;
|
|
74 |
return -1;
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
if(!mDeleteWorker)
|
|
79 |
{
|
|
80 |
mDeleteWorker = new VideoDeleteWorker(*mCollectionClient);
|
|
81 |
if(!mDeleteWorker)
|
|
82 |
{
|
|
83 |
delete mCollectionClient;
|
|
84 |
mCollectionClient = 0;
|
|
85 |
return -1;
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
if( d_ptr->initialize() == -1)
|
|
90 |
{
|
|
91 |
return -1;
|
|
92 |
}
|
|
93 |
|
|
94 |
if(connectSignals() == -1)
|
|
95 |
{
|
|
96 |
disconnectSignals();
|
|
97 |
return -1;
|
|
98 |
}
|
|
99 |
|
|
100 |
mInitialized = true;
|
|
101 |
return 0;
|
|
102 |
}
|
|
103 |
|
|
104 |
// -----------------------------------------------------------------------------
|
|
105 |
// getCollectionClient()
|
|
106 |
// -----------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
VideoCollectionClient* VideoListDataModel::getCollectionClient()
|
|
109 |
{
|
|
110 |
return mCollectionClient;
|
|
111 |
}
|
|
112 |
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
// connectSignals()
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
int VideoListDataModel::connectSignals()
|
|
118 |
{
|
|
119 |
if(!connect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
120 |
this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))))
|
|
121 |
{
|
|
122 |
return -1;
|
|
123 |
}
|
|
124 |
if(!connect(d_ptr, SIGNAL(videoDetailsReady(TMPXItemId)),
|
|
125 |
this, SIGNAL(fullVideoDetailsReady(TMPXItemId))))
|
|
126 |
{
|
|
127 |
return -1;
|
|
128 |
}
|
|
129 |
if(!connect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot())))
|
|
130 |
{
|
|
131 |
return -1;
|
|
132 |
}
|
|
133 |
if(!connect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot())))
|
|
134 |
{
|
|
135 |
return -1;
|
|
136 |
}
|
|
137 |
if(!connect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)),
|
|
138 |
this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>))))
|
|
139 |
{
|
|
140 |
return -1;
|
|
141 |
}
|
|
142 |
|
|
143 |
return 0;
|
|
144 |
}
|
|
145 |
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
// disconnectSignals()
|
|
148 |
// -----------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
void VideoListDataModel::disconnectSignals()
|
|
151 |
{
|
|
152 |
disconnect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
153 |
this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
|
|
154 |
disconnect(d_ptr, SIGNAL(videoDetailsReady(TMPXItemId)),
|
|
155 |
this, SIGNAL(fullVideoDetailsReady(TMPXItemId)));
|
|
156 |
disconnect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()));
|
|
157 |
disconnect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot()));
|
|
158 |
disconnect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)),
|
|
159 |
this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>)));
|
|
160 |
}
|
|
161 |
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
// mediaIdAtIndex()
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
//
|
|
166 |
TMPXItemId VideoListDataModel::mediaIdAtIndex(int index) const
|
|
167 |
{
|
|
168 |
TMPXItemId mpxId =TMPXItemId::InvalidId();
|
|
169 |
|
|
170 |
if(index >= 0 && index < d_ptr->getVideoCount())
|
|
171 |
{
|
|
172 |
mpxId = d_ptr->getMediaIdFromIndex(index);
|
|
173 |
}
|
|
174 |
|
|
175 |
return mpxId;
|
|
176 |
}
|
|
177 |
|
|
178 |
// -----------------------------------------------------------------------------
|
|
179 |
// indexOfId()
|
|
180 |
// -----------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
QModelIndex VideoListDataModel::indexOfId(TMPXItemId id)
|
|
183 |
{
|
|
184 |
int rowIndex = d_ptr->mMediaData.indexOfId(id);
|
|
185 |
return index(rowIndex, 0, QModelIndex());
|
|
186 |
}
|
|
187 |
|
|
188 |
// -----------------------------------------------------------------------------
|
|
189 |
// mediaFilePathForId()
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
QString VideoListDataModel::mediaFilePathForId(TMPXItemId mediaId) const
|
|
193 |
{
|
|
194 |
QString filePath;
|
|
195 |
filePath = d_ptr->getFilePathForId(mediaId);
|
|
196 |
|
|
197 |
return filePath;
|
|
198 |
}
|
|
199 |
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
// rowCount()
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
int VideoListDataModel::rowCount(const QModelIndex &parent ) const
|
|
205 |
{
|
|
206 |
// according to Qt documentation if parent is valid this should return 0 if
|
|
207 |
// implementing a table based implementation like this.
|
|
208 |
if (parent.isValid())
|
|
209 |
{
|
|
210 |
return 0;
|
|
211 |
}
|
|
212 |
|
|
213 |
return d_ptr->getVideoCount();
|
|
214 |
}
|
|
215 |
|
|
216 |
// -----------------------------------------------------------------------------
|
|
217 |
// itemData()
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
QMap<int, QVariant> VideoListDataModel::itemData(const QModelIndex &index) const
|
|
221 |
{
|
|
222 |
QMap<int, QVariant> itemData;
|
|
223 |
|
|
224 |
if (index.isValid())
|
|
225 |
{
|
|
226 |
// returns only basic data of the item
|
|
227 |
itemData.insert(Qt::DisplayRole, data(index, Qt::DisplayRole));
|
|
228 |
itemData.insert(Qt::DecorationRole, data(index, Qt::DecorationRole));
|
|
229 |
itemData.insert(Qt::BackgroundRole, data(index, Qt::BackgroundRole));
|
|
230 |
}
|
|
231 |
return itemData;
|
|
232 |
|
|
233 |
}
|
|
234 |
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
// prepareDetailRow()
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
QString VideoListDataModel::prepareDetailRow( int index ) const
|
|
240 |
{
|
|
241 |
// TODO: download -status?
|
|
242 |
|
|
243 |
QString retString;
|
|
244 |
|
|
245 |
TMPXItemId itemId = mediaIdAtIndex(index);
|
|
246 |
|
|
247 |
if(itemId.iId2 != KVcxMvcMediaTypeVideo) //category || album
|
|
248 |
{
|
|
249 |
//TODO: get real items and total length
|
|
250 |
int items = 99;
|
|
251 |
QString minutesStr = "10";
|
|
252 |
QString secondsStr = "01";
|
|
253 |
retString = hbTrId("txt_videos_dblist_val_ln_videos_l1l2", items).arg(minutesStr).arg(secondsStr);
|
|
254 |
}
|
|
255 |
else //video
|
|
256 |
{
|
|
257 |
const QString sizeStr = prepareSizeString(index);
|
|
258 |
const QStringList list = prepareLengthStrings( index );
|
|
259 |
retString = hbTrId("txt_videos_dblist_captured_val_1_l1l2").arg(sizeStr).arg(list.at(0)).arg(list.at(1));
|
|
260 |
}
|
|
261 |
return retString;
|
|
262 |
}
|
|
263 |
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
// prepareSizeString()
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
//
|
|
268 |
QString VideoListDataModel::prepareSizeString( int index ) const
|
|
269 |
{
|
|
270 |
QString sizeStr("");
|
|
271 |
|
|
272 |
quint32 size = d_ptr->getVideoSizeFromIndex(index);
|
|
273 |
sizeStr = VideoCollectionUtils::instance().prepareSizeString(size);
|
|
274 |
|
|
275 |
return sizeStr;
|
|
276 |
}
|
|
277 |
|
|
278 |
// -----------------------------------------------------------------------------
|
|
279 |
// VideoListDataModel::prepareLengthStrings()
|
|
280 |
// -----------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
QStringList VideoListDataModel::prepareLengthStrings( int index ) const
|
|
283 |
{
|
|
284 |
quint32 total = d_ptr->getVideodurationFromIndex(index);
|
|
285 |
return VideoCollectionUtils::instance().prepareLengthStrings(total);
|
|
286 |
}
|
|
287 |
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
// data()
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
QVariant VideoListDataModel::data(const QModelIndex & index, int role) const
|
|
293 |
{
|
|
294 |
QVariant returnValue = QVariant();
|
|
295 |
|
|
296 |
|
|
297 |
if (index.isValid())
|
|
298 |
{
|
|
299 |
int rowIndex = index.row();
|
|
300 |
|
|
301 |
if (role == Qt::DisplayRole)
|
|
302 |
{
|
|
303 |
QStringList itemTxt;
|
|
304 |
itemTxt.append(d_ptr->getVideoNameFromIndex(rowIndex));
|
|
305 |
|
|
306 |
// Item's 2nd row: details
|
|
307 |
itemTxt.append(prepareDetailRow(rowIndex));
|
|
308 |
returnValue = itemTxt;
|
|
309 |
}
|
|
310 |
else if (role == Qt::DecorationRole)
|
|
311 |
{
|
|
312 |
const QIcon *thumbnail = d_ptr->getVideoThumbnailFromIndex(rowIndex);
|
|
313 |
QVariant tnVariant(QVariant::Icon, thumbnail);
|
|
314 |
returnValue = tnVariant;
|
|
315 |
}
|
|
316 |
else if (role == VideoCollectionCommon::KeyDateTime)
|
|
317 |
{
|
|
318 |
QDateTime date = d_ptr->getVideoDateFromIndex(rowIndex);
|
|
319 |
returnValue = date;
|
|
320 |
}
|
|
321 |
else if(role == VideoCollectionCommon::KeySizeValue)
|
|
322 |
{
|
|
323 |
quint32 size = d_ptr->getVideoSizeFromIndex(rowIndex);
|
|
324 |
returnValue = size;
|
|
325 |
|
|
326 |
}
|
|
327 |
else if(role == VideoCollectionCommon::KeyMetaData)
|
|
328 |
{
|
|
329 |
returnValue = d_ptr->getMetaDataFromIndex(rowIndex);
|
|
330 |
}
|
|
331 |
else if(role == VideoCollectionCommon::KeyFilePath)
|
|
332 |
{
|
|
333 |
QString path = d_ptr->getFilePathFromIndex(rowIndex);
|
|
334 |
if(!(path.isNull()) && !(path.isEmpty())) {
|
|
335 |
returnValue = path;
|
|
336 |
}
|
|
337 |
}
|
|
338 |
}
|
|
339 |
|
|
340 |
return returnValue;
|
|
341 |
}
|
|
342 |
|
|
343 |
// -----------------------------------------------------------------------------
|
|
344 |
// columnCount()
|
|
345 |
// -----------------------------------------------------------------------------
|
|
346 |
//
|
|
347 |
int VideoListDataModel::columnCount(const QModelIndex & parent) const
|
|
348 |
{
|
|
349 |
// according to Qt documentation if parent is valid this should return 0 if
|
|
350 |
// implementing a table based implementation like this.
|
|
351 |
if (parent.isValid())
|
|
352 |
{
|
|
353 |
return 0;
|
|
354 |
}
|
|
355 |
else
|
|
356 |
{
|
|
357 |
return 1;
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
// -----------------------------------------------------------------------------
|
|
362 |
// index()
|
|
363 |
// -----------------------------------------------------------------------------
|
|
364 |
//
|
|
365 |
QModelIndex VideoListDataModel::index(int row, int column, const QModelIndex & /*parent*/) const
|
|
366 |
{
|
|
367 |
|
|
368 |
if(row >= 0 && row < d_ptr->getVideoCount())
|
|
369 |
{
|
|
370 |
return createIndex(row, column);
|
|
371 |
}
|
|
372 |
|
|
373 |
return QModelIndex();
|
|
374 |
}
|
|
375 |
|
|
376 |
// -----------------------------------------------------------------------------
|
|
377 |
// parent()
|
|
378 |
// -----------------------------------------------------------------------------
|
|
379 |
//
|
|
380 |
QModelIndex VideoListDataModel::parent(const QModelIndex & /*index*/) const
|
|
381 |
{
|
|
382 |
return QModelIndex();
|
|
383 |
}
|
|
384 |
|
|
385 |
// -----------------------------------------------------------------------------
|
|
386 |
// removeRows()
|
|
387 |
// -----------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
bool VideoListDataModel::removeRows(const QModelIndexList &indexList)
|
|
390 |
{
|
|
391 |
if(!mCollectionClient || !mDeleteWorker)
|
|
392 |
{
|
|
393 |
return false;
|
|
394 |
}
|
|
395 |
// generate list of deletable item ids
|
|
396 |
TMPXItemId id = TMPXItemId::InvalidId();
|
|
397 |
QList<TMPXItemId> removedIds;
|
|
398 |
QModelIndexList sortable(indexList);
|
|
399 |
qSort(sortable);
|
|
400 |
|
|
401 |
// since items are removed from actual container when being marked
|
|
402 |
// causing total item count to be decreased,
|
|
403 |
// we need to mark items starting from biggest index, otherwise we might
|
|
404 |
// end up to mark invalid items or we are referring into null item
|
|
405 |
QModelIndexList::const_iterator iter = sortable.constEnd();
|
|
406 |
while(iter != sortable.constBegin())
|
|
407 |
{
|
|
408 |
iter--;
|
|
409 |
beginRemoveRows(QModelIndex(), (*iter).row(), (*iter).row());
|
|
410 |
// marking might fail if either because
|
|
411 |
// item does no exist or index is incorrect.
|
|
412 |
// Both reasons mean that item is incorrect and should be removed
|
|
413 |
// from the view. No need to restain them
|
|
414 |
id = d_ptr->markVideoRemoved((*iter));
|
|
415 |
endRemoveRows();
|
|
416 |
if(id != TMPXItemId::InvalidId())
|
|
417 |
{
|
|
418 |
removedIds.append(id);
|
|
419 |
}
|
|
420 |
}
|
|
421 |
emit modelChanged();
|
|
422 |
if(removedIds.count() > 0 )
|
|
423 |
{
|
|
424 |
mDeleteWorker->requestDelete(removedIds);
|
|
425 |
return true;
|
|
426 |
}
|
|
427 |
return false;
|
|
428 |
}
|
|
429 |
|
|
430 |
// -----------------------------------------------------------------------------
|
|
431 |
// belongsToAlbum()
|
|
432 |
// -----------------------------------------------------------------------------
|
|
433 |
//
|
|
434 |
bool VideoListDataModel::belongsToAlbum(const TMPXItemId &itemId,
|
|
435 |
TMPXItemId albumId ) const
|
|
436 |
{
|
|
437 |
return d_ptr->belongsToAlbum(itemId, albumId);
|
|
438 |
}
|
|
439 |
|
|
440 |
// -----------------------------------------------------------------------------
|
|
441 |
// setAlbumInUse()
|
|
442 |
// -----------------------------------------------------------------------------
|
|
443 |
//
|
|
444 |
void VideoListDataModel::setAlbumInUse(TMPXItemId albumId)
|
|
445 |
{
|
|
446 |
d_ptr->setAlbumInUse(albumId);
|
|
447 |
}
|
|
448 |
|
|
449 |
// -----------------------------------------------------------------------------
|
|
450 |
// albumInUse()
|
|
451 |
// -----------------------------------------------------------------------------
|
|
452 |
//
|
|
453 |
|
|
454 |
TMPXItemId VideoListDataModel::albumInUse()
|
|
455 |
{
|
|
456 |
return d_ptr->mCurrentAlbum;
|
|
457 |
}
|
|
458 |
|
|
459 |
// -----------------------------------------------------------------------------
|
|
460 |
// deleteStartingFailsSlot()
|
|
461 |
// -----------------------------------------------------------------------------
|
|
462 |
//
|
|
463 |
void VideoListDataModel::deleteStartingFailsSlot(QList<TMPXItemId> ids)
|
|
464 |
{
|
|
465 |
if(ids.count())
|
|
466 |
{
|
|
467 |
d_ptr->restoreRemoved(&ids);
|
|
468 |
QVariant data = ids.count();
|
|
469 |
reportAsyncStatus(VideoCollectionCommon::statusMultipleDeleteFail, data);
|
|
470 |
}
|
|
471 |
// signal for worker to proceed
|
|
472 |
emit modelChanged();
|
|
473 |
}
|
|
474 |
|
|
475 |
// -----------------------------------------------------------------------------
|
|
476 |
// reportAsyncStatus()
|
|
477 |
// -----------------------------------------------------------------------------
|
|
478 |
//
|
|
479 |
void VideoListDataModel::reportAsyncStatus(int statusCode, QVariant &additional)
|
|
480 |
{
|
|
481 |
bool report = true;
|
|
482 |
if(statusCode == VideoCollectionCommon::statusSingleDeleteFail ||
|
|
483 |
statusCode == VideoCollectionCommon::statusMultipleDeleteFail ||
|
|
484 |
statusCode == VideoCollectionCommon::statusDeleteSucceed)
|
|
485 |
{
|
|
486 |
report = false;
|
|
487 |
if(!mDeleteWorker)
|
|
488 |
{
|
|
489 |
return;
|
|
490 |
}
|
|
491 |
mDeleteWorker->updateStatus(statusCode, additional);
|
|
492 |
statusCode = mDeleteWorker->getLastStatus(additional);
|
|
493 |
if(!mDeleteWorker->isDeleting())
|
|
494 |
{
|
|
495 |
report = true;
|
|
496 |
// delete procedure ends, reset statuses
|
|
497 |
mDeleteWorker->clearStatus();
|
|
498 |
}
|
|
499 |
}
|
|
500 |
if(report)
|
|
501 |
{
|
|
502 |
VideoCollectionWrapper::instance().sendAsyncStatus(statusCode, additional);
|
|
503 |
}
|
|
504 |
}
|
|
505 |
|
|
506 |
// End of file
|