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