13 * |
13 * |
14 * Description: VideoListDataModel class implementation |
14 * Description: VideoListDataModel class implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 // Version : %version: 51 % |
|
19 |
18 // INCLUDE FILES |
20 // INCLUDE FILES |
19 |
|
20 #include <hbglobal.h> |
21 #include <hbglobal.h> |
21 #include <vcxmyvideosdefs.h> |
22 #include <vcxmyvideosdefs.h> |
|
23 |
22 #include "videolistdatamodel.h" |
24 #include "videolistdatamodel.h" |
23 #include "videolistdatamodel_p.h" |
25 #include "videolistdatamodel_p.h" |
24 #include "videocollectionclient.h" |
26 #include "videocollectionclient.h" |
25 #include "videocollectioncommon.h" |
27 #include "videocollectioncommon.h" |
26 #include "videocollectionutils.h" |
28 #include "videocollectionutils.h" |
27 #include "videodeleteworker.h" |
29 #include "videodeleteworker.h" |
28 #include "videocollectionwrapper.h" |
30 #include "videocollectionwrapper.h" |
|
31 #include "videocollectiontrace.h" |
29 |
32 |
30 // ================= MEMBER FUNCTIONS ======================= |
33 // ================= MEMBER FUNCTIONS ======================= |
31 // |
34 // |
32 |
35 |
33 // ----------------------------------------------------------------------------- |
36 // ----------------------------------------------------------------------------- |
34 // VideoListDataModel() |
37 // VideoListDataModel() |
35 // ----------------------------------------------------------------------------- |
38 // ----------------------------------------------------------------------------- |
36 // |
39 // |
37 VideoListDataModel::VideoListDataModel(QObject *parent) : |
40 VideoListDataModel::VideoListDataModel( QObject *parent ) |
38 QAbstractItemModel(parent), |
41 : QAbstractItemModel( parent ) |
39 d_ptr( new VideoListDataModelPrivate(this)), |
42 , d_ptr( new VideoListDataModelPrivate( this ) ) |
40 mCollectionClient(0), |
43 , mCollectionClient( 0 ) |
41 mDeleteWorker(0), |
44 , mDeleteWorker( 0 ) |
42 mInitialized(false) |
45 , mInitialized( false ) |
43 { |
46 { |
|
47 FUNC_LOG; |
44 } |
48 } |
45 |
49 |
46 // ----------------------------------------------------------------------------- |
50 // ----------------------------------------------------------------------------- |
47 // ~VideoListDataModel() |
51 // ~VideoListDataModel() |
48 // ----------------------------------------------------------------------------- |
52 // ----------------------------------------------------------------------------- |
49 // |
53 // |
50 VideoListDataModel::~VideoListDataModel() |
54 VideoListDataModel::~VideoListDataModel() |
51 { |
55 { |
|
56 FUNC_LOG; |
52 delete mDeleteWorker; |
57 delete mDeleteWorker; |
53 delete d_ptr; |
58 delete d_ptr; |
54 delete mCollectionClient; |
59 delete mCollectionClient; |
55 } |
60 } |
56 |
61 |
58 // initialize() |
63 // initialize() |
59 // ----------------------------------------------------------------------------- |
64 // ----------------------------------------------------------------------------- |
60 // |
65 // |
61 int VideoListDataModel::initialize() |
66 int VideoListDataModel::initialize() |
62 { |
67 { |
|
68 FUNC_LOG; |
63 if(mInitialized) |
69 if(mInitialized) |
64 { |
70 { |
65 return 0; |
71 return 0; |
66 } |
72 } |
67 if(!mCollectionClient) |
73 if(!mCollectionClient) |
68 { |
74 { |
69 mCollectionClient = new VideoCollectionClient(); |
75 mCollectionClient = new VideoCollectionClient(); |
70 if(!mCollectionClient || mCollectionClient->initialize(d_ptr) < 0) |
76 if(!mCollectionClient || mCollectionClient->initialize(d_ptr) < 0) |
71 { |
77 { |
|
78 ERROR(-1, "VideoListDataModel::initialize() collection client setup failed."); |
72 delete mCollectionClient; |
79 delete mCollectionClient; |
73 mCollectionClient = 0; |
80 mCollectionClient = 0; |
74 return -1; |
81 return -1; |
75 } |
82 } |
76 } |
83 } |
105 // getCollectionClient() |
114 // getCollectionClient() |
106 // ----------------------------------------------------------------------------- |
115 // ----------------------------------------------------------------------------- |
107 // |
116 // |
108 VideoCollectionClient* VideoListDataModel::getCollectionClient() |
117 VideoCollectionClient* VideoListDataModel::getCollectionClient() |
109 { |
118 { |
|
119 FUNC_LOG; |
110 return mCollectionClient; |
120 return mCollectionClient; |
111 } |
121 } |
112 |
122 |
113 // ----------------------------------------------------------------------------- |
123 // ----------------------------------------------------------------------------- |
114 // connectSignals() |
124 // connectSignals() |
115 // ----------------------------------------------------------------------------- |
125 // ----------------------------------------------------------------------------- |
116 // |
126 // |
117 int VideoListDataModel::connectSignals() |
127 int VideoListDataModel::connectSignals() |
118 { |
128 { |
|
129 FUNC_LOG; |
119 if(!connect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
130 if(!connect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
120 this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)))) |
131 this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)))) |
121 { |
132 { |
122 return -1; |
133 return -1; |
123 } |
134 } |
124 if(!connect(d_ptr, SIGNAL(videoDetailsReady(TMPXItemId)), |
135 if(!connect(d_ptr, SIGNAL(videoDetailsReady(QVariant&)), |
125 this, SIGNAL(fullVideoDetailsReady(TMPXItemId)))) |
136 this, SIGNAL(fullVideoDetailsReady(QVariant&)))) |
126 { |
137 { |
127 return -1; |
138 return -1; |
128 } |
139 } |
129 if(!connect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()))) |
140 if(!connect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()))) |
130 { |
141 { |
147 // disconnectSignals() |
158 // disconnectSignals() |
148 // ----------------------------------------------------------------------------- |
159 // ----------------------------------------------------------------------------- |
149 // |
160 // |
150 void VideoListDataModel::disconnectSignals() |
161 void VideoListDataModel::disconnectSignals() |
151 { |
162 { |
|
163 FUNC_LOG; |
152 disconnect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
164 disconnect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
153 this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))); |
165 this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))); |
154 disconnect(d_ptr, SIGNAL(videoDetailsReady(TMPXItemId)), |
166 disconnect(d_ptr, SIGNAL(videoDetailsReady(QVariant&)), |
155 this, SIGNAL(fullVideoDetailsReady(TMPXItemId))); |
167 this, SIGNAL(fullVideoDetailsReady(QVariant&))); |
156 disconnect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot())); |
168 disconnect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot())); |
157 disconnect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot())); |
169 disconnect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot())); |
158 disconnect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)), |
170 disconnect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)), |
159 this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>))); |
171 this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>))); |
160 } |
172 } |
248 { |
260 { |
249 retString = prepareVideoCountString(index); |
261 retString = prepareVideoCountString(index); |
250 } |
262 } |
251 else //video |
263 else //video |
252 { |
264 { |
253 const QString sizeStr = prepareSizeString(index); |
265 const QString duration = prepareShortLengthString( index ); |
254 const QStringList list = prepareLengthStrings( index ); |
266 |
255 QString duration; |
267 retString = doDetailRow(index, duration); |
256 duration.append(list.at(0)); |
|
257 duration.append(":"); |
|
258 duration.append(list.at(1)); |
|
259 duration.append(":"); |
|
260 duration.append(list.at(2)); |
|
261 retString = hbTrId("txt_videos_dblist_captured_val_1_l1").arg(duration).arg(sizeStr); |
|
262 } |
268 } |
263 return retString; |
269 return retString; |
264 } |
270 } |
265 |
271 |
266 // ----------------------------------------------------------------------------- |
272 // ----------------------------------------------------------------------------- |
297 |
303 |
298 return sizeStr; |
304 return sizeStr; |
299 } |
305 } |
300 |
306 |
301 // ----------------------------------------------------------------------------- |
307 // ----------------------------------------------------------------------------- |
302 // VideoListDataModel::prepareLengthStrings() |
308 // VideoListDataModel::prepareShortLengthString() |
303 // ----------------------------------------------------------------------------- |
309 // ----------------------------------------------------------------------------- |
304 // |
310 // |
305 QStringList VideoListDataModel::prepareLengthStrings(int index) const |
311 QString VideoListDataModel::prepareShortLengthString(int index) const |
306 { |
312 { |
307 quint32 total = d_ptr->getVideodurationFromIndex(index); |
313 quint32 total = d_ptr->getVideodurationFromIndex(index); |
308 return VideoCollectionUtils::instance().prepareLengthStrings(total); |
314 return VideoCollectionUtils::instance().prepareShortLengthString(total); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // VideoListDataModel::doDetailRow() |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 QString VideoListDataModel::doDetailRow(int index, const QString duration) const |
|
322 { |
|
323 QString detailStr(""); |
|
324 |
|
325 quint32 size = d_ptr->getVideoSizeFromIndex(index); |
|
326 |
|
327 const int videoSizeGB( 0x40000000 ); |
|
328 const int videoSizeHalfGB( 0x20000000 ); |
|
329 const int videoSizeMB( 0x100000 ); |
|
330 const int videoSizeHalfMB( 0x80000 ); |
|
331 const int videoSizeKB( 0x400 ); |
|
332 |
|
333 quint32 dispSize = 0; |
|
334 |
|
335 if ( size >= videoSizeGB ) |
|
336 { |
|
337 dispSize = size + videoSizeHalfGB; |
|
338 dispSize /= videoSizeGB; |
|
339 detailStr = hbTrId("txt_videos_dblist_captured_val_l1_l2_gb").arg(duration).arg(QString::number(dispSize)); |
|
340 } |
|
341 else if ( size >= videoSizeMB ) |
|
342 { |
|
343 dispSize = size + videoSizeHalfMB; |
|
344 dispSize /= videoSizeMB; |
|
345 detailStr = hbTrId("txt_videos_dblist_captured_val_l1_l2_mb").arg(duration).arg(QString::number(dispSize)); |
|
346 } |
|
347 else |
|
348 { |
|
349 dispSize = size + videoSizeKB; |
|
350 dispSize /= videoSizeKB; |
|
351 detailStr = hbTrId("txt_videos_dblist_captured_val_l1_l2_kb").arg(duration).arg(QString::number(dispSize)); |
|
352 } |
|
353 |
|
354 return detailStr; |
309 } |
355 } |
310 |
356 |
311 // ----------------------------------------------------------------------------- |
357 // ----------------------------------------------------------------------------- |
312 // data() |
358 // data() |
313 // ----------------------------------------------------------------------------- |
359 // ----------------------------------------------------------------------------- |
314 // |
360 // |
315 QVariant VideoListDataModel::data(const QModelIndex & index, int role) const |
361 QVariant VideoListDataModel::data(const QModelIndex & index, int role) const |
316 { |
362 { |
317 QVariant returnValue = QVariant(); |
363 QVariant returnValue = QVariant(); |
318 |
364 |
319 |
|
320 if (index.isValid()) |
365 if (index.isValid()) |
321 { |
366 { |
322 int rowIndex = index.row(); |
367 int rowIndex = index.row(); |
323 |
368 |
324 if (role == Qt::DisplayRole) |
369 if (role == Qt::DisplayRole) |
343 } |
388 } |
344 else if(role == VideoCollectionCommon::KeySizeValue) |
389 else if(role == VideoCollectionCommon::KeySizeValue) |
345 { |
390 { |
346 quint32 size = d_ptr->getVideoSizeFromIndex(rowIndex); |
391 quint32 size = d_ptr->getVideoSizeFromIndex(rowIndex); |
347 returnValue = size; |
392 returnValue = size; |
348 |
393 } |
349 } |
394 else if (role == VideoCollectionCommon::KeyFilePath) |
350 else if(role == VideoCollectionCommon::KeyMetaData) |
|
351 { |
|
352 returnValue = d_ptr->getMetaDataFromIndex(rowIndex); |
|
353 } |
|
354 else if(role == VideoCollectionCommon::KeyFilePath) |
|
355 { |
395 { |
356 QString path = d_ptr->getFilePathFromIndex(rowIndex); |
396 QString path = d_ptr->getFilePathFromIndex(rowIndex); |
357 if(!(path.isNull()) && !(path.isEmpty())) { |
397 if(!(path.isNull()) && !(path.isEmpty())) { |
358 returnValue = path; |
398 returnValue = path; |
359 } |
399 } |
360 } |
400 } |
|
401 else if (role == VideoCollectionCommon::KeyNumberOfItems) |
|
402 { |
|
403 quint32 numberOfItems = d_ptr->getCategoryVideoCountFromIndex(rowIndex); |
|
404 returnValue = numberOfItems; |
|
405 } |
|
406 else if (role == VideoCollectionCommon::KeyTitle) |
|
407 { |
|
408 QString title = d_ptr->getVideoNameFromIndex(rowIndex); |
|
409 returnValue = title; |
|
410 } |
361 } |
411 } |
362 |
412 |
363 return returnValue; |
413 return returnValue; |
364 } |
414 } |
365 |
415 |
385 // index() |
435 // index() |
386 // ----------------------------------------------------------------------------- |
436 // ----------------------------------------------------------------------------- |
387 // |
437 // |
388 QModelIndex VideoListDataModel::index(int row, int column, const QModelIndex & /*parent*/) const |
438 QModelIndex VideoListDataModel::index(int row, int column, const QModelIndex & /*parent*/) const |
389 { |
439 { |
390 |
|
391 if(row >= 0 && row < d_ptr->getVideoCount()) |
440 if(row >= 0 && row < d_ptr->getVideoCount()) |
392 { |
441 { |
393 return createIndex(row, column); |
442 return createIndex(row, column); |
394 } |
443 } |
395 |
444 |
464 // setAlbumInUse() |
514 // setAlbumInUse() |
465 // ----------------------------------------------------------------------------- |
515 // ----------------------------------------------------------------------------- |
466 // |
516 // |
467 void VideoListDataModel::setAlbumInUse(TMPXItemId albumId) |
517 void VideoListDataModel::setAlbumInUse(TMPXItemId albumId) |
468 { |
518 { |
|
519 FUNC_LOG; |
469 d_ptr->setAlbumInUse(albumId); |
520 d_ptr->setAlbumInUse(albumId); |
470 } |
521 } |
471 |
522 |
472 // ----------------------------------------------------------------------------- |
523 // ----------------------------------------------------------------------------- |
473 // albumInUse() |
524 // albumInUse() |
474 // ----------------------------------------------------------------------------- |
525 // ----------------------------------------------------------------------------- |
475 // |
526 // |
476 TMPXItemId VideoListDataModel::albumInUse() |
527 TMPXItemId VideoListDataModel::albumInUse() |
477 { |
528 { |
|
529 FUNC_LOG; |
478 return d_ptr->mCurrentAlbum; |
530 return d_ptr->mCurrentAlbum; |
479 } |
531 } |
480 |
532 |
481 // ----------------------------------------------------------------------------- |
533 // ----------------------------------------------------------------------------- |
482 // removeItemsFromAlbum() |
534 // removeItemsFromAlbum() |
483 // ----------------------------------------------------------------------------- |
535 // ----------------------------------------------------------------------------- |
484 // |
536 // |
485 int VideoListDataModel::removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &items) |
537 int VideoListDataModel::removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &items) |
486 { |
538 { |
|
539 FUNC_LOG; |
487 int removeCount = d_ptr->removeItemsFromAlbum(albumId, items); |
540 int removeCount = d_ptr->removeItemsFromAlbum(albumId, items); |
488 if(removeCount) |
541 if(removeCount) |
489 { |
542 { |
490 if(mCollectionClient->removeItemsFromAlbum(albumId, items) < 0) |
543 if(mCollectionClient->removeItemsFromAlbum(albumId, items) < 0) |
491 { |
544 { |
|
545 ERROR(-1, "VideoListDataModel::removeItemsFromAlbum() remove failed."); |
492 return -1; |
546 return -1; |
493 } |
547 } |
494 emit albumChanged(); |
548 emit albumChanged(); |
495 } |
549 } |
496 return removeCount; |
550 return removeCount; |
500 // deleteStartingFailsSlot() |
554 // deleteStartingFailsSlot() |
501 // ----------------------------------------------------------------------------- |
555 // ----------------------------------------------------------------------------- |
502 // |
556 // |
503 void VideoListDataModel::deleteStartingFailsSlot(QList<TMPXItemId> ids) |
557 void VideoListDataModel::deleteStartingFailsSlot(QList<TMPXItemId> ids) |
504 { |
558 { |
|
559 FUNC_LOG; |
505 if(ids.count()) |
560 if(ids.count()) |
506 { |
561 { |
507 d_ptr->restoreRemoved(&ids); |
562 d_ptr->restoreRemoved(&ids); |
508 QVariant data = ids.count(); |
563 QVariant data = ids.count(); |
509 reportAsyncStatus(VideoCollectionCommon::statusMultipleDeleteFail, data); |
564 reportAsyncStatus(VideoCollectionCommon::statusMultipleDeleteFail, data); |
516 // reportAsyncStatus() |
571 // reportAsyncStatus() |
517 // ----------------------------------------------------------------------------- |
572 // ----------------------------------------------------------------------------- |
518 // |
573 // |
519 void VideoListDataModel::reportAsyncStatus(int statusCode, QVariant &additional) |
574 void VideoListDataModel::reportAsyncStatus(int statusCode, QVariant &additional) |
520 { |
575 { |
|
576 FUNC_LOG; |
521 bool report = true; |
577 bool report = true; |
522 if(statusCode == VideoCollectionCommon::statusSingleDeleteFail || |
578 if(statusCode == VideoCollectionCommon::statusSingleDeleteFail || |
523 statusCode == VideoCollectionCommon::statusMultipleDeleteFail || |
579 statusCode == VideoCollectionCommon::statusMultipleDeleteFail || |
524 statusCode == VideoCollectionCommon::statusDeleteSucceed) |
580 statusCode == VideoCollectionCommon::statusDeleteSucceed) |
525 { |
581 { |