30
|
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: Videosortfilterproxymodel implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <qstringlist.h>
|
34
|
19 |
#include <qset.h>
|
30
|
20 |
#include <qtimer.h>
|
|
21 |
#include <qdatetime.h>
|
34
|
22 |
#include <vcxmyvideosdefs.h>
|
30
|
23 |
|
|
24 |
#include "videothumbnaildata.h"
|
|
25 |
#include "videocollectioncommon.h"
|
|
26 |
#include "videosortfilterproxymodel.h"
|
|
27 |
#include "videolistdatamodel.h"
|
|
28 |
#include "videocollectionclient.h"
|
34
|
29 |
#include "videocollectionwrapper.h"
|
30
|
30 |
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
// VideoSortFilterProxyModel::VideoSortFilterProxyModel
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
//
|
34
|
35 |
VideoSortFilterProxyModel::VideoSortFilterProxyModel(int type, QObject *parent) :
|
35
|
36 |
QSortFilterProxyModel(parent),
|
|
37 |
mModel(0),
|
|
38 |
mCollectionClient(0),
|
|
39 |
mType(type),
|
|
40 |
mLevel(-1),
|
|
41 |
mGenericFilterId(TMPXItemId::InvalidId()),
|
34
|
42 |
mGenericFilterValue(false),
|
35
|
43 |
mIdleSortTimer(0),
|
|
44 |
mWantedSortRole(VideoCollectionCommon::KeyDateTime)
|
30
|
45 |
{
|
|
46 |
// NOP
|
|
47 |
}
|
|
48 |
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
// VideoSortFilterProxyModel::~VideoSortFilterProxyModel
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
VideoSortFilterProxyModel::~VideoSortFilterProxyModel()
|
|
54 |
{
|
34
|
55 |
// NOP
|
30
|
56 |
}
|
|
57 |
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
// VideoSortFilterProxyModel::initialize
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
int VideoSortFilterProxyModel::initialize(VideoListDataModel *sourceModel)
|
|
63 |
{
|
34
|
64 |
if(!sourceModel)
|
|
65 |
{
|
|
66 |
return -1;
|
|
67 |
}
|
|
68 |
|
|
69 |
if(!mModel)
|
|
70 |
{
|
|
71 |
mModel = sourceModel;
|
|
72 |
if(!connectSignals())
|
|
73 |
{
|
|
74 |
disconnectSignals();
|
|
75 |
mModel = 0;
|
30
|
76 |
return -1;
|
|
77 |
}
|
34
|
78 |
mCollectionClient = mModel->getCollectionClient();
|
|
79 |
setSourceModel(sourceModel);
|
|
80 |
}
|
|
81 |
return 0;
|
|
82 |
}
|
30
|
83 |
|
34
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// VideoSortFilterProxyModel::connectSignals
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
bool VideoSortFilterProxyModel::connectSignals()
|
|
89 |
{
|
|
90 |
if(!connect(mModel, SIGNAL(modelReady()),
|
|
91 |
this, SIGNAL(modelReady())))
|
|
92 |
{
|
|
93 |
return false;
|
30
|
94 |
}
|
34
|
95 |
if(!connect(mModel, SIGNAL(modelChanged()),
|
|
96 |
this, SIGNAL(modelChanged())))
|
|
97 |
{
|
|
98 |
return false;
|
|
99 |
}
|
35
|
100 |
if(mType == VideoCollectionWrapper::ECollectionContent)
|
34
|
101 |
{
|
35
|
102 |
if(!connect(mModel, SIGNAL(albumChanged()),
|
|
103 |
this, SLOT(albumChangedSlot())))
|
|
104 |
{
|
|
105 |
return false;
|
|
106 |
}
|
34
|
107 |
}
|
|
108 |
return true;
|
|
109 |
}
|
|
110 |
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
// VideoSortFilterProxyModel::disconnectSignals
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
void VideoSortFilterProxyModel::disconnectSignals()
|
|
116 |
{
|
35
|
117 |
disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
|
34
|
118 |
disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
|
35
|
119 |
if(mType == VideoCollectionWrapper::ECollectionContent)
|
|
120 |
{
|
|
121 |
disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot()));
|
|
122 |
}
|
|
123 |
|
30
|
124 |
}
|
|
125 |
|
|
126 |
// -----------------------------------------------------------------------------
|
|
127 |
// VideoSortFilterProxyModel::open
|
|
128 |
// -----------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
int VideoSortFilterProxyModel::open(int level)
|
|
131 |
{
|
34
|
132 |
if(!mCollectionClient)
|
|
133 |
{
|
|
134 |
return -1;
|
30
|
135 |
}
|
34
|
136 |
|
|
137 |
if(mLevel != level)
|
|
138 |
{
|
35
|
139 |
mLevel = level;
|
34
|
140 |
invalidateFilter();
|
|
141 |
}
|
|
142 |
// need to call open every time to make sure all items are
|
|
143 |
// inserted to UI ( recent open might have been cancelled)
|
|
144 |
return mCollectionClient->startOpenCollection(level);
|
30
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// VideoSortFilterProxyModel::doSorting
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void VideoSortFilterProxyModel::doSorting(int sortingRole, Qt::SortOrder order,
|
|
152 |
bool async)
|
|
153 |
{
|
|
154 |
if((sortingRole != Qt::DisplayRole) &&
|
|
155 |
(sortingRole != VideoCollectionCommon::KeySizeValue) &&
|
|
156 |
(sortingRole != VideoCollectionCommon::KeyDateTime))
|
|
157 |
{
|
|
158 |
// default sorting order is by date
|
|
159 |
mWantedSortRole = VideoCollectionCommon::KeyDateTime;
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
mWantedSortRole = sortingRole;
|
|
164 |
}
|
|
165 |
|
|
166 |
mWantedSortOrder = order;
|
|
167 |
|
|
168 |
if(async)
|
|
169 |
{
|
|
170 |
if(mIdleSortTimer)
|
|
171 |
{
|
|
172 |
if(mIdleSortTimer->isActive())
|
|
173 |
{
|
|
174 |
mIdleSortTimer->stop();
|
|
175 |
}
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
mIdleSortTimer = new QTimer(this);
|
|
180 |
connect(mIdleSortTimer, SIGNAL(timeout()), this, SLOT(processSorting()));
|
|
181 |
}
|
|
182 |
mIdleSortTimer->start(0);
|
|
183 |
} else {
|
|
184 |
processSorting();
|
|
185 |
}
|
|
186 |
}
|
34
|
187 |
// -----------------------------------------------------------------------------
|
|
188 |
// VideoSortFilterProxyModel::getSorting
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
void VideoSortFilterProxyModel::getSorting(int &sortingRole, Qt::SortOrder &order)
|
|
192 |
{
|
|
193 |
sortingRole = mWantedSortRole;
|
|
194 |
order = mWantedSortOrder;
|
|
195 |
}
|
30
|
196 |
|
|
197 |
// -----------------------------------------------------------------------------
|
|
198 |
// VideoSortFilterProxyModel::deleteItems
|
|
199 |
// -----------------------------------------------------------------------------
|
|
200 |
//
|
|
201 |
int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList)
|
|
202 |
{
|
|
203 |
if(mModel)
|
|
204 |
{
|
|
205 |
QModelIndexList mappedList;
|
|
206 |
for(int i = 0; i < indexList.count(); ++i)
|
|
207 |
{
|
|
208 |
mappedList.append(mapToSource(indexList.at(i)));
|
|
209 |
}
|
|
210 |
|
|
211 |
if(mModel->removeRows(mappedList))
|
|
212 |
{
|
|
213 |
// Start fetching thumbnails at start of the model.
|
34
|
214 |
VideoThumbnailData::instance().startBackgroundFetching(0, 0);
|
30
|
215 |
return 0;
|
|
216 |
}
|
|
217 |
}
|
|
218 |
return -1;
|
|
219 |
}
|
|
220 |
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
// VideoSortFilterProxyModel::openItem
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
//
|
34
|
225 |
int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId)
|
30
|
226 |
{
|
34
|
227 |
if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
|
30
|
228 |
{
|
34
|
229 |
if(mCollectionClient->openItem(mediaId) == 0)
|
|
230 |
{
|
|
231 |
if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
|
|
232 |
{
|
|
233 |
mLevel = VideoCollectionCommon::ELevelAlbum;
|
|
234 |
mModel->setAlbumInUse(mediaId);
|
|
235 |
invalidateFilter();
|
|
236 |
}
|
|
237 |
return 0;
|
|
238 |
}
|
30
|
239 |
}
|
|
240 |
return -1;
|
|
241 |
}
|
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
// VideoSortFilterProxyModel::back
|
|
245 |
// -----------------------------------------------------------------------------
|
|
246 |
//
|
|
247 |
int VideoSortFilterProxyModel::back()
|
|
248 |
{
|
34
|
249 |
if(mCollectionClient && mCollectionClient->back() == 0)
|
30
|
250 |
{
|
34
|
251 |
if(mLevel == VideoCollectionCommon::ELevelAlbum)
|
|
252 |
{
|
|
253 |
mLevel = VideoCollectionCommon::ELevelCategory;
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
mLevel = VideoCollectionCommon::ELevelVideos;
|
|
258 |
}
|
|
259 |
return 0;
|
30
|
260 |
}
|
|
261 |
return -1;
|
|
262 |
}
|
|
263 |
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
// VideoSortFilterProxyModel::fetchItemDetails
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
//
|
|
268 |
int VideoSortFilterProxyModel::fetchItemDetails(const QModelIndex &index)
|
|
269 |
{
|
|
270 |
// no need to map index beforehand, because
|
|
271 |
// getMediaIdAtIndex maps it
|
|
272 |
TMPXItemId mpxId1 = getMediaIdAtIndex(index);
|
|
273 |
if(mpxId1 != TMPXItemId::InvalidId() && mCollectionClient)
|
|
274 |
{
|
|
275 |
if(mCollectionClient->getVideoDetails(mpxId1) == 0)
|
|
276 |
{
|
34
|
277 |
|
|
278 |
emit shortDetailsReady(mpxId1);
|
30
|
279 |
return 0;
|
|
280 |
}
|
|
281 |
}
|
|
282 |
return -1;
|
|
283 |
}
|
|
284 |
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
// VideoSortFilterProxyModel::processSorting
|
|
287 |
// -----------------------------------------------------------------------------
|
|
288 |
//
|
|
289 |
void VideoSortFilterProxyModel::processSorting()
|
|
290 |
{
|
|
291 |
if(mIdleSortTimer)
|
|
292 |
{
|
|
293 |
mIdleSortTimer->stop();
|
|
294 |
}
|
|
295 |
|
|
296 |
if(sortRole() != mWantedSortRole)
|
|
297 |
{
|
|
298 |
setSortRole(mWantedSortRole);
|
|
299 |
}
|
|
300 |
|
|
301 |
if(sortColumn() == -1 || sortOrder() != mWantedSortOrder)
|
|
302 |
{
|
|
303 |
// if sorting column is not yet setted, it indicates
|
|
304 |
// that we've setted the sorting order for the first time
|
|
305 |
// and sorting has not yet been done. After we have called sort once,
|
|
306 |
// the sort columnt gets updated and following sorts gets executed
|
|
307 |
// by setSortRole -call as long as role changes.
|
|
308 |
|
|
309 |
// Another case is when we need to change the sort order, as there is
|
|
310 |
// no other way of setting the sort order than calling sort().
|
|
311 |
sort(0, mWantedSortOrder);
|
|
312 |
}
|
|
313 |
|
|
314 |
// Start fetching thumbnails at start of the model.
|
34
|
315 |
VideoThumbnailData::instance().startBackgroundFetching(0, 0);
|
30
|
316 |
}
|
|
317 |
|
|
318 |
// -----------------------------------------------------------------------------
|
|
319 |
// VideoSortFilterProxyModel::lessThan
|
|
320 |
// -----------------------------------------------------------------------------
|
|
321 |
//
|
34
|
322 |
bool VideoSortFilterProxyModel::lessThan(const QModelIndex &left,
|
|
323 |
const QModelIndex &right) const
|
30
|
324 |
{
|
34
|
325 |
if (!mModel)
|
|
326 |
{
|
|
327 |
return false;
|
|
328 |
}
|
|
329 |
TMPXItemId leftId = mModel->mediaIdAtIndex(left.row());
|
|
330 |
TMPXItemId rightId = mModel->mediaIdAtIndex(right.row());
|
|
331 |
|
|
332 |
// Default categories are always first in the following order:
|
|
333 |
// Recently played (missing currently
|
|
334 |
// Captured
|
|
335 |
// Downloaded
|
|
336 |
// Podcasts (missing currently)
|
|
337 |
bool lessThan(false);
|
|
338 |
bool proceedDataSorting(false);
|
|
339 |
if(leftId.iId2 == KVcxMvcMediaTypeCategory &&
|
|
340 |
rightId.iId2 == KVcxMvcMediaTypeCategory)
|
|
341 |
{
|
|
342 |
if(leftId.iId1 == KVcxMvcCategoryIdCaptured)
|
|
343 |
{
|
|
344 |
lessThan = true;
|
|
345 |
}
|
|
346 |
|
|
347 |
else if(leftId.iId1 == KVcxMvcCategoryIdDownloads)
|
|
348 |
{
|
|
349 |
if(rightId.iId1 != KVcxMvcCategoryIdCaptured)
|
|
350 |
{
|
|
351 |
lessThan = true;
|
|
352 |
}
|
|
353 |
}
|
|
354 |
}
|
|
355 |
else if(leftId.iId2 == KVcxMvcMediaTypeCategory ||
|
|
356 |
rightId.iId2 == KVcxMvcMediaTypeCategory)
|
|
357 |
{
|
|
358 |
lessThan = (leftId.iId2 == KVcxMvcMediaTypeCategory);
|
|
359 |
}
|
|
360 |
else
|
|
361 |
{
|
|
362 |
proceedDataSorting = true;
|
|
363 |
}
|
30
|
364 |
|
34
|
365 |
if(!proceedDataSorting)
|
|
366 |
{
|
|
367 |
return mWantedSortOrder == Qt::AscendingOrder ? lessThan : !lessThan;
|
|
368 |
}
|
|
369 |
|
|
370 |
// Do comparisation based on the role:
|
|
371 |
// Qt::DisplayRole,
|
|
372 |
// VideoCollectionCommon::KeySizeValue,
|
|
373 |
// VideoCollectionCommon::KeyDateValue
|
|
374 |
//
|
|
375 |
// If role does not match, do not sort
|
30
|
376 |
int sRole = sortRole();
|
|
377 |
QVariant leftData = sourceModel()->data(left, sRole);
|
|
378 |
QVariant rightData = sourceModel()->data(right, sRole);
|
|
379 |
|
|
380 |
if(!leftData.isValid() || !rightData.isValid())
|
|
381 |
{
|
|
382 |
return false;
|
|
383 |
}
|
|
384 |
if(sRole == Qt::DisplayRole)
|
|
385 |
{
|
|
386 |
QString leftString = leftData.toStringList().first().toUpper();
|
|
387 |
QString rightString = rightData.toStringList().first().toUpper();
|
|
388 |
return QString::localeAwareCompare(leftString, rightString) < 0;
|
|
389 |
}
|
|
390 |
else if(sRole == VideoCollectionCommon::KeySizeValue)
|
|
391 |
{
|
|
392 |
quint32 leftSize = leftData.toUInt();
|
|
393 |
quint32 rightSize = rightData.toUInt();
|
|
394 |
return leftSize < rightSize;
|
|
395 |
}
|
|
396 |
else if(sRole == VideoCollectionCommon::KeyDateTime)
|
|
397 |
{
|
|
398 |
QDateTime leftDateTime = leftData.toDateTime();
|
|
399 |
QDateTime rightDateTime = rightData.toDateTime();
|
|
400 |
// datetime sorting role has inverted sorting order compared to other roles
|
|
401 |
return rightDateTime < leftDateTime;
|
|
402 |
}
|
|
403 |
return false;
|
|
404 |
}
|
|
405 |
|
|
406 |
// -----------------------------------------------------------------------------
|
|
407 |
// VideoSortFilterProxyModel::filterAcceptsRow
|
|
408 |
// -----------------------------------------------------------------------------
|
|
409 |
//
|
35
|
410 |
bool VideoSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
30
|
411 |
{
|
34
|
412 |
Q_UNUSED(source_parent);
|
35
|
413 |
|
30
|
414 |
if(!sourceModel())
|
|
415 |
return false;
|
|
416 |
|
34
|
417 |
if(source_row < 0 || source_row >= sourceModel()->rowCount())
|
|
418 |
{
|
|
419 |
return false;
|
|
420 |
}
|
|
421 |
TMPXItemId id = mModel->mediaIdAtIndex(source_row);
|
|
422 |
if(id == TMPXItemId::InvalidId())
|
|
423 |
{
|
|
424 |
return false;
|
|
425 |
}
|
|
426 |
|
|
427 |
if (mType == VideoCollectionWrapper::EAllVideos)
|
|
428 |
{
|
|
429 |
if(id.iId2 == KVcxMvcMediaTypeVideo)
|
|
430 |
{
|
|
431 |
return true;
|
|
432 |
}
|
|
433 |
}
|
|
434 |
else if(mType == VideoCollectionWrapper::ECollections)
|
|
435 |
{
|
|
436 |
if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 != KVcxMvcMediaTypeVideo)
|
|
437 |
{
|
|
438 |
return true;
|
|
439 |
}
|
|
440 |
}
|
|
441 |
else if (mType == VideoCollectionWrapper::ECollectionContent)
|
30
|
442 |
{
|
34
|
443 |
// if item belongs to the open album, accept it
|
|
444 |
if (mModel->belongsToAlbum(id))
|
|
445 |
{
|
|
446 |
return true;
|
|
447 |
}
|
|
448 |
}
|
|
449 |
else if(mType == VideoCollectionWrapper::EGeneric)
|
|
450 |
{
|
|
451 |
if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
|
30
|
452 |
{
|
34
|
453 |
// filter items that belong to that album setted as filter id
|
|
454 |
// if there's no filter or setted filter is "all videos", we accept everything
|
|
455 |
if(mGenericFilterId == TMPXItemId::InvalidId() ||
|
|
456 |
(mGenericFilterId.iId1 == KVcxMvcCategoryIdAll &&
|
|
457 |
mGenericFilterId.iId2 == KVcxMvcMediaTypeCategory) ||
|
|
458 |
mGenericFilterValue == mModel->belongsToAlbum(id, mGenericFilterId))
|
|
459 |
{
|
|
460 |
return true;
|
|
461 |
}
|
|
462 |
|
30
|
463 |
}
|
34
|
464 |
else if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 == KVcxMvcMediaTypeAlbum)
|
|
465 |
{
|
|
466 |
// we do not filter albums yet
|
|
467 |
return true;
|
|
468 |
}
|
30
|
469 |
}
|
34
|
470 |
|
30
|
471 |
return false;
|
|
472 |
}
|
|
473 |
|
|
474 |
// -----------------------------------------------------------------------------
|
|
475 |
// VideoSortFilterProxyModel::getMediaIdAtIndex()
|
|
476 |
// -----------------------------------------------------------------------------
|
|
477 |
//
|
34
|
478 |
TMPXItemId VideoSortFilterProxyModel::getMediaIdAtIndex(const QModelIndex &index) const
|
30
|
479 |
{
|
|
480 |
QModelIndex sourceIndex = mapToSource(index);
|
|
481 |
TMPXItemId mpxId = TMPXItemId::InvalidId();
|
|
482 |
if(mModel && sourceIndex.isValid())
|
|
483 |
{
|
|
484 |
mpxId = mModel->mediaIdAtIndex(sourceIndex.row());
|
|
485 |
}
|
|
486 |
return mpxId;
|
|
487 |
}
|
|
488 |
|
|
489 |
// -----------------------------------------------------------------------------
|
34
|
490 |
// VideoSortFilterProxyModel::indexOfId()
|
|
491 |
// -----------------------------------------------------------------------------
|
|
492 |
//
|
|
493 |
QModelIndex VideoSortFilterProxyModel::indexOfId(TMPXItemId id)
|
|
494 |
{
|
|
495 |
QModelIndex sourceIndex;
|
|
496 |
if(!mModel || id == TMPXItemId::InvalidId())
|
|
497 |
{
|
|
498 |
return sourceIndex;
|
|
499 |
}
|
|
500 |
sourceIndex = mModel->indexOfId(id);
|
|
501 |
return mapFromSource(sourceIndex);
|
|
502 |
}
|
|
503 |
|
|
504 |
// -----------------------------------------------------------------------------
|
30
|
505 |
// VideoSortFilterProxyModel::getMediaFilePathForId()
|
|
506 |
// -----------------------------------------------------------------------------
|
|
507 |
//
|
|
508 |
QString VideoSortFilterProxyModel::getMediaFilePathForId(TMPXItemId mediaId)
|
|
509 |
{
|
|
510 |
QString filePath;
|
|
511 |
if(mModel)
|
|
512 |
{
|
|
513 |
filePath = mModel->mediaFilePathForId(mediaId);
|
|
514 |
}
|
|
515 |
return filePath;
|
|
516 |
}
|
|
517 |
|
|
518 |
// -----------------------------------------------------------------------------
|
34
|
519 |
// VideoSortFilterProxyModel::addNewAlbum()
|
|
520 |
// -----------------------------------------------------------------------------
|
|
521 |
//
|
|
522 |
TMPXItemId VideoSortFilterProxyModel::addNewAlbum(const QString &title)
|
|
523 |
{
|
|
524 |
TMPXItemId id = TMPXItemId::InvalidId();
|
|
525 |
|
|
526 |
if (mCollectionClient)
|
|
527 |
{
|
|
528 |
id = mCollectionClient->addNewAlbum(title);
|
|
529 |
}
|
|
530 |
|
|
531 |
return id;
|
|
532 |
}
|
|
533 |
|
|
534 |
// -----------------------------------------------------------------------------
|
|
535 |
// VideoSortFilterProxyModel::removeAlbums()
|
|
536 |
// -----------------------------------------------------------------------------
|
|
537 |
//
|
|
538 |
int VideoSortFilterProxyModel::removeAlbums(const QModelIndexList &indexList)
|
|
539 |
{
|
|
540 |
int err(-1);
|
|
541 |
|
|
542 |
if (mCollectionClient)
|
|
543 |
{
|
|
544 |
TMPXItemId mpxId;
|
|
545 |
QList<TMPXItemId> ids;
|
|
546 |
|
|
547 |
for(int i = 0; i < indexList.count(); ++i)
|
|
548 |
{
|
|
549 |
mpxId = getMediaIdAtIndex(indexList.at(i));
|
|
550 |
if((mpxId != TMPXItemId::InvalidId()) && (mpxId.iId2 == KVcxMvcMediaTypeAlbum))
|
|
551 |
{
|
|
552 |
ids.append(getMediaIdAtIndex(indexList.at(i)));
|
|
553 |
}
|
|
554 |
}
|
|
555 |
|
|
556 |
if (ids.count())
|
|
557 |
{
|
|
558 |
err = mCollectionClient->removeAlbums(ids);
|
|
559 |
}
|
|
560 |
}
|
|
561 |
|
|
562 |
return err;
|
|
563 |
}
|
|
564 |
|
|
565 |
// -----------------------------------------------------------------------------
|
|
566 |
// VideoSortFilterProxyModel::resolveAlbumName()
|
30
|
567 |
// -----------------------------------------------------------------------------
|
|
568 |
//
|
34
|
569 |
QString VideoSortFilterProxyModel::resolveAlbumName(
|
|
570 |
const QString& albumName) const
|
|
571 |
{
|
|
572 |
QString resolvedName = albumName.trimmed();
|
|
573 |
|
|
574 |
// for checking names, we need to use collection list proxy model
|
|
575 |
// to get all existing album names including default ones
|
|
576 |
VideoSortFilterProxyModel *collectionModel =
|
|
577 |
VideoCollectionWrapper::instance().getModel(
|
|
578 |
VideoCollectionWrapper::ECollections);
|
|
579 |
if(!collectionModel || !mModel)
|
|
580 |
{
|
|
581 |
return resolvedName;
|
|
582 |
}
|
|
583 |
|
|
584 |
int i(0);
|
|
585 |
QModelIndex proxyIndex = collectionModel->index(i, 0);
|
|
586 |
QSet<QString> names;
|
|
587 |
QVariant data;
|
|
588 |
// create set of existing names
|
|
589 |
while (proxyIndex.isValid())
|
|
590 |
{
|
|
591 |
data = mModel->data(collectionModel->mapToSource(proxyIndex), Qt::DisplayRole);
|
|
592 |
if (data.isValid())
|
|
593 |
{
|
|
594 |
QStringList stringList = data.toStringList();
|
|
595 |
names.insert(stringList.at(0));
|
|
596 |
}
|
|
597 |
proxyIndex = collectionModel->index(++i, 0, QModelIndex());
|
|
598 |
}
|
|
599 |
i = 0;
|
|
600 |
QString firstMatch("");
|
|
601 |
// find a name that does not yet exists
|
|
602 |
while(names.contains(resolvedName))
|
|
603 |
{
|
|
604 |
if (!firstMatch.length())
|
|
605 |
{
|
|
606 |
firstMatch = resolvedName;
|
|
607 |
}
|
|
608 |
++i;
|
|
609 |
resolvedName = tr("%1 (%2)").arg(firstMatch).arg(i);
|
|
610 |
}
|
|
611 |
return resolvedName;
|
|
612 |
}
|
|
613 |
|
|
614 |
// -----------------------------------------------------------------------------
|
|
615 |
// VideoSortFilterProxyModel::addItemsInAlbum()
|
|
616 |
// -----------------------------------------------------------------------------
|
|
617 |
//
|
35
|
618 |
int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId &albumId,
|
34
|
619 |
const QList<TMPXItemId> &mediaIds)
|
30
|
620 |
{
|
34
|
621 |
int err(-1);
|
|
622 |
|
|
623 |
if (mCollectionClient)
|
|
624 |
{
|
|
625 |
// add items in album
|
|
626 |
err = mCollectionClient->addItemsInAlbum(albumId, mediaIds);
|
30
|
627 |
}
|
34
|
628 |
|
|
629 |
return err;
|
|
630 |
}
|
|
631 |
|
|
632 |
// -----------------------------------------------------------------------------
|
35
|
633 |
// VideoSortFilterProxyModel::removeItemsFromAlbum()
|
|
634 |
// -----------------------------------------------------------------------------
|
|
635 |
//
|
|
636 |
int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId,
|
|
637 |
const QList<TMPXItemId> &mediaIds)
|
|
638 |
{
|
|
639 |
int err(-1);
|
|
640 |
|
|
641 |
if (mModel)
|
|
642 |
{
|
|
643 |
// remove items in album
|
|
644 |
err = mModel->removeItemsFromAlbum(albumId, mediaIds);
|
|
645 |
if(err > 0)
|
|
646 |
{
|
|
647 |
// if there really were items to be removed, invalid filter
|
|
648 |
invalidateFilter();
|
|
649 |
err = 0;
|
|
650 |
}
|
|
651 |
}
|
|
652 |
return err;
|
|
653 |
}
|
|
654 |
|
|
655 |
// -----------------------------------------------------------------------------
|
34
|
656 |
// VideoSortFilterProxyModel::getOpenItem()
|
|
657 |
// -----------------------------------------------------------------------------
|
|
658 |
//
|
|
659 |
TMPXItemId VideoSortFilterProxyModel::getOpenItem() const
|
|
660 |
{
|
|
661 |
TMPXItemId itemId = TMPXItemId::InvalidId();
|
|
662 |
|
|
663 |
if(mModel && mCollectionClient)
|
|
664 |
{
|
|
665 |
if(mType == VideoCollectionWrapper::EAllVideos)
|
|
666 |
{
|
|
667 |
itemId.iId1 = KVcxMvcCategoryIdAll;
|
|
668 |
itemId.iId2 = KVcxMvcMediaTypeCategory;
|
|
669 |
}
|
|
670 |
else if(mType == VideoCollectionWrapper::ECollectionContent)
|
|
671 |
{
|
|
672 |
itemId = mModel->albumInUse();
|
|
673 |
}
|
|
674 |
}
|
|
675 |
|
|
676 |
return itemId;
|
|
677 |
}
|
|
678 |
|
|
679 |
// -----------------------------------------------------------------------------
|
|
680 |
// VideoSortFilterProxyModel::setGenericIdFilter()
|
|
681 |
// -----------------------------------------------------------------------------
|
|
682 |
//
|
|
683 |
void VideoSortFilterProxyModel::setGenericIdFilter(TMPXItemId itemId, bool filterValue)
|
|
684 |
{
|
|
685 |
if(mType == VideoCollectionWrapper::EGeneric)
|
|
686 |
{
|
|
687 |
mGenericFilterId = itemId;
|
|
688 |
mGenericFilterValue = filterValue;
|
|
689 |
invalidateFilter();
|
|
690 |
}
|
|
691 |
}
|
|
692 |
|
|
693 |
// -----------------------------------------------------------------------------
|
35
|
694 |
// VideoSortFilterProxyModel::setAlbumInUse()
|
|
695 |
// -----------------------------------------------------------------------------
|
|
696 |
//
|
|
697 |
void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId)
|
|
698 |
{
|
|
699 |
mModel->setAlbumInUse(albumId);
|
|
700 |
invalidateFilter();
|
|
701 |
}
|
|
702 |
|
|
703 |
// -----------------------------------------------------------------------------
|
34
|
704 |
// VideoSortFilterProxyModel::albumChangedSlot()
|
|
705 |
// -----------------------------------------------------------------------------
|
|
706 |
//
|
|
707 |
void VideoSortFilterProxyModel::albumChangedSlot()
|
|
708 |
{
|
|
709 |
// ignore if not collection content model
|
|
710 |
if (mType == VideoCollectionWrapper::ECollectionContent)
|
|
711 |
{
|
|
712 |
invalidateFilter();
|
|
713 |
}
|
30
|
714 |
}
|
|
715 |
|
|
716 |
// end of file
|
|
717 |
|