30
|
1 |
/*
|
36
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
30
|
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: video collection view plugin's ui utils class
|
36
|
15 |
*
|
30
|
16 |
*/
|
|
17 |
|
44
|
18 |
// Version : %version: 45 %
|
36
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <hbglobal.h>
|
34
|
22 |
#include <hblistview.h>
|
|
23 |
#include <hbscrollbar.h>
|
|
24 |
#include <hblistviewitem.h>
|
30
|
25 |
#include <hbdialog.h>
|
|
26 |
#include <hbmessagebox.h>
|
36
|
27 |
#include <hbnotificationdialog.h>
|
44
|
28 |
#include <hbparameterlengthlimiter.h>
|
|
29 |
#include <xqsettingsmanager.h>
|
30
|
30 |
#include <centralrepository.h>
|
41
|
31 |
#include <vcxmyvideosdefs.h>
|
30
|
32 |
|
|
33 |
#include "videocollectioncommon.h"
|
|
34 |
#include "videocollectionviewutils.h"
|
34
|
35 |
#include "videosortfilterproxymodel.h"
|
40
|
36 |
#include "videoactivitystate.h"
|
41
|
37 |
#include "videocollectioncenrepdefs.h"
|
36
|
38 |
#include "videocollectiontrace.h"
|
30
|
39 |
|
38
|
40 |
// Object names.
|
|
41 |
const char* const VIEW_UTILS_OBJECT_NAME_STATUS_MSG = "vc:ViewUtilsStatusMessage";
|
|
42 |
const char* const VIEW_UTILS_OBJECT_NAME_MESSAGE_BOX_WARNING = "vc:ViewUtilsMessageBoxWarning";
|
|
43 |
|
|
44 |
const int KAddToCollectionDataCount(2);
|
|
45 |
const int KAddToCollectionCountIndex(0);
|
|
46 |
const int KAddToCollectionNameIndex(1);
|
|
47 |
|
41
|
48 |
// type of collectionview plugin's widget level(int):
|
|
49 |
// all videos, collections or collection video list
|
|
50 |
static const QString KEY_WIDGET_LEVEL = "_VideoActivity_widget_level_";
|
|
51 |
|
|
52 |
// id of the collection whose videolist is to be shown (int).
|
|
53 |
static const QString KEY_COLLECTION_ID = "_VideoActivity_collection_id_";
|
|
54 |
|
|
55 |
// name of the collection whose videolist is to be shown (QString)
|
|
56 |
static const QString KEY_COLLECTION_NAME = "_VideoActivity_collection_name_";
|
|
57 |
|
39
|
58 |
|
30
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
// instance
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
VideoCollectionViewUtils& VideoCollectionViewUtils::instance()
|
|
64 |
{
|
38
|
65 |
FUNC_LOG;
|
|
66 |
static VideoCollectionViewUtils _popupInstance;
|
|
67 |
return _popupInstance;
|
30
|
68 |
}
|
|
69 |
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
// VideoCollectionViewUtils
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
//
|
34
|
74 |
VideoCollectionViewUtils::VideoCollectionViewUtils():
|
36
|
75 |
mVideosSortRole(-1),
|
|
76 |
mCollectionsSortRole(-1),
|
|
77 |
mVideosSortOrder(Qt::AscendingOrder),
|
|
78 |
mCollectionsSortOrder(Qt::AscendingOrder)
|
30
|
79 |
{
|
36
|
80 |
FUNC_LOG;
|
30
|
81 |
}
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// ~VideoCollectionViewUtils
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
VideoCollectionViewUtils::~VideoCollectionViewUtils()
|
|
88 |
{
|
36
|
89 |
FUNC_LOG;
|
30
|
90 |
}
|
|
91 |
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
// saveSortingValues
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
36
|
96 |
int VideoCollectionViewUtils::saveSortingValues(int role, Qt::SortOrder order, VideoCollectionCommon::TCollectionLevels target)
|
30
|
97 |
{
|
36
|
98 |
FUNC_LOG;
|
|
99 |
INFO_3("VideoCollectionViewUtils::saveSortingValues() saving: role: %d, order: %d, target: %d", role, order, target);
|
|
100 |
|
30
|
101 |
int status = -1;
|
36
|
102 |
if (target != VideoCollectionCommon::ELevelInvalid)
|
|
103 |
{
|
|
104 |
CRepository *cenRep = 0;
|
|
105 |
TRAP_IGNORE(cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
|
|
106 |
|
|
107 |
int *rolePtr = &mVideosSortRole;
|
|
108 |
Qt::SortOrder *orderPtr = &mVideosSortOrder;
|
|
109 |
|
|
110 |
int roleKey(KVideoCollectionViewCenrepVideoSortingRoleKey);
|
|
111 |
int orderKey(KVideoCollectionViewCenrepVideoSortingOrderKey);
|
|
112 |
|
|
113 |
if(target == VideoCollectionCommon::ELevelCategory)
|
|
114 |
{
|
|
115 |
rolePtr = &mCollectionsSortRole;
|
|
116 |
orderPtr = &mCollectionsSortOrder;
|
|
117 |
|
|
118 |
roleKey = KVideoCollectionViewCenrepCollectionsSortingRoleKey;
|
|
119 |
orderKey = KVideoCollectionViewCenrepCollectionsSortingOrderKey;
|
|
120 |
}
|
|
121 |
|
|
122 |
if(cenRep)
|
|
123 |
{
|
|
124 |
status = cenRep->Set(roleKey, static_cast<TInt>(role));
|
|
125 |
if(status == KErrNone)
|
|
126 |
{
|
|
127 |
status = cenRep->Set(orderKey, static_cast<TInt>(order));
|
|
128 |
}
|
|
129 |
delete cenRep;
|
|
130 |
}
|
|
131 |
|
|
132 |
*rolePtr = role;
|
|
133 |
*orderPtr = order;
|
|
134 |
}
|
35
|
135 |
return status;
|
30
|
136 |
}
|
|
137 |
|
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
// loadSortingValues
|
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
//
|
36
|
142 |
int VideoCollectionViewUtils::loadSortingValues(int &role, Qt::SortOrder &order, VideoCollectionCommon::TCollectionLevels target)
|
30
|
143 |
{
|
36
|
144 |
FUNC_LOG;
|
34
|
145 |
int err(0);
|
36
|
146 |
|
|
147 |
if ((target > VideoCollectionCommon::ELevelCategory) &&
|
|
148 |
(mVideosSortRole != -1))
|
|
149 |
{
|
|
150 |
role = mVideosSortRole;
|
|
151 |
order = mVideosSortOrder;
|
|
152 |
}
|
|
153 |
else if ((target == VideoCollectionCommon::ELevelCategory) &&
|
|
154 |
(mCollectionsSortRole != -1))
|
30
|
155 |
{
|
36
|
156 |
role = mCollectionsSortRole;
|
|
157 |
order = mCollectionsSortOrder;
|
|
158 |
}
|
|
159 |
else if (target != VideoCollectionCommon::ELevelInvalid)
|
|
160 |
{
|
|
161 |
int *rolePtr = &mVideosSortRole;
|
|
162 |
Qt::SortOrder *orderPtr = &mVideosSortOrder;
|
|
163 |
int roleKey(KVideoCollectionViewCenrepVideoSortingRoleKey);
|
|
164 |
int orderKey(KVideoCollectionViewCenrepVideoSortingOrderKey);
|
|
165 |
|
|
166 |
if(target == VideoCollectionCommon::ELevelCategory)
|
30
|
167 |
{
|
36
|
168 |
roleKey = KVideoCollectionViewCenrepCollectionsSortingRoleKey;
|
|
169 |
orderKey = KVideoCollectionViewCenrepCollectionsSortingOrderKey;
|
|
170 |
rolePtr = &mCollectionsSortRole;
|
|
171 |
orderPtr = &mCollectionsSortOrder;
|
30
|
172 |
}
|
36
|
173 |
|
|
174 |
CRepository *cenRep = 0;
|
|
175 |
TRAP(err, cenRep = CRepository::NewL(TUid::Uid(KVideoCollectionViewCenrepUid)));
|
|
176 |
if(cenRep)
|
|
177 |
{
|
|
178 |
int sortRole(-1);
|
|
179 |
int sortOrder(-1);
|
|
180 |
err = cenRep->Get(roleKey, sortRole);
|
|
181 |
if(err == KErrNone)
|
|
182 |
{
|
|
183 |
err = cenRep->Get(orderKey, sortOrder);
|
|
184 |
if(err == KErrNone)
|
|
185 |
{
|
|
186 |
*orderPtr = static_cast<Qt::SortOrder>(sortOrder);
|
|
187 |
*rolePtr = sortRole;
|
|
188 |
}
|
|
189 |
}
|
|
190 |
delete cenRep;
|
|
191 |
}
|
|
192 |
|
|
193 |
role = *rolePtr;
|
|
194 |
order = *orderPtr;
|
30
|
195 |
}
|
36
|
196 |
INFO_3("VideoCollectionViewUtils::loadSortingValues() loaded: role: %d, order: %d, target: %d", role, order, target);
|
|
197 |
return err;
|
30
|
198 |
}
|
|
199 |
|
|
200 |
// ---------------------------------------------------------------------------
|
44
|
201 |
// getCenrepStringValue
|
30
|
202 |
// ---------------------------------------------------------------------------
|
|
203 |
//
|
44
|
204 |
QString VideoCollectionViewUtils::getCenRepStringValue(int key)
|
30
|
205 |
{
|
44
|
206 |
FUNC_LOG;
|
|
207 |
XQCentralRepositorySettingsKey crKey(KVideoCollectionViewCenrepUid, key);
|
|
208 |
XQSettingsManager mgr;
|
|
209 |
QVariant value = mgr.readItemValue(crKey, XQSettingsManager::TypeString);
|
|
210 |
return value.toString();
|
30
|
211 |
}
|
|
212 |
|
|
213 |
// ---------------------------------------------------------------------------
|
44
|
214 |
// getCenRepIntValue
|
30
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
//
|
44
|
217 |
int VideoCollectionViewUtils::getCenRepIntValue(int key)
|
30
|
218 |
{
|
44
|
219 |
FUNC_LOG;
|
|
220 |
XQCentralRepositorySettingsKey crKey(KVideoCollectionViewCenrepUid, key);
|
|
221 |
XQSettingsManager mgr;
|
|
222 |
QVariant value = mgr.readItemValue(crKey, XQSettingsManager::TypeInt);
|
|
223 |
int uid = -1;
|
|
224 |
if(value.isValid())
|
30
|
225 |
{
|
44
|
226 |
uid = value.toInt();
|
30
|
227 |
}
|
44
|
228 |
return uid;
|
30
|
229 |
}
|
|
230 |
|
|
231 |
// ---------------------------------------------------------------------------
|
34
|
232 |
// initListView
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
void VideoCollectionViewUtils::initListView(HbListView *view)
|
|
236 |
{
|
36
|
237 |
FUNC_LOG;
|
34
|
238 |
if (view)
|
|
239 |
{
|
|
240 |
HbListViewItem *prototype = view->listItemPrototype();
|
|
241 |
if(prototype)
|
|
242 |
{
|
|
243 |
//Use image layout in prototype
|
35
|
244 |
prototype->setGraphicsSize(HbListViewItem::WideThumbnail);
|
34
|
245 |
}
|
|
246 |
view->setItemRecycling(true);
|
|
247 |
view->setClampingStyle(HbScrollArea::BounceBackClamping);
|
36
|
248 |
view->setScrollingStyle(HbScrollArea::PanWithFollowOn);
|
34
|
249 |
view->setFrictionEnabled(true);
|
|
250 |
view->setUniformItemSizes(true);
|
|
251 |
view->setSelectionMode(HbAbstractItemView::NoSelection);
|
|
252 |
|
|
253 |
//Use scrollbar
|
|
254 |
HbScrollBar *scrollBar = view->verticalScrollBar();
|
|
255 |
if (scrollBar)
|
|
256 |
{
|
|
257 |
scrollBar->setInteractive(true);
|
|
258 |
}
|
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
// sortModel
|
|
264 |
// ---------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
void VideoCollectionViewUtils::sortModel(
|
|
267 |
VideoSortFilterProxyModel *model,
|
36
|
268 |
bool async,
|
|
269 |
VideoCollectionCommon::TCollectionLevels target)
|
34
|
270 |
{
|
36
|
271 |
FUNC_LOG;
|
34
|
272 |
if (model)
|
|
273 |
{
|
|
274 |
// setup sorting order for model
|
|
275 |
int sortRole(VideoCollectionCommon::KeyDateTime);
|
36
|
276 |
|
|
277 |
// default for categories
|
|
278 |
if(target == VideoCollectionCommon::ELevelCategory)
|
|
279 |
{
|
|
280 |
sortRole = VideoCollectionCommon::KeyTitle;
|
|
281 |
}
|
|
282 |
|
34
|
283 |
Qt::SortOrder sortOrder(Qt::AscendingOrder);
|
36
|
284 |
|
34
|
285 |
// return value ignored, as in case of error the sortRole and sortOrder variables
|
|
286 |
// stay at their predefined values, and in error cases those are the sorting values
|
|
287 |
// that are used.
|
|
288 |
VideoCollectionViewUtils &self = VideoCollectionViewUtils::instance();
|
36
|
289 |
self.loadSortingValues(sortRole, sortOrder, target);
|
|
290 |
|
34
|
291 |
model->doSorting(sortRole, sortOrder, async);
|
|
292 |
}
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------------------------
|
41
|
296 |
// setWidgetActivityLevel
|
39
|
297 |
// ---------------------------------------------------------------------------
|
|
298 |
//
|
41
|
299 |
void VideoCollectionViewUtils::setWidgetActivityLevel(
|
|
300 |
const VideoCollectionCommon::TCollectionLevels &level)
|
39
|
301 |
{
|
40
|
302 |
FUNC_LOG;
|
|
303 |
QVariant data = int(level);
|
41
|
304 |
VideoActivityState::instance().setActivityData(data, KEY_WIDGET_LEVEL);
|
|
305 |
|
|
306 |
if(level != VideoCollectionCommon::ELevelDefaultColl &&
|
|
307 |
level != VideoCollectionCommon::ELevelAlbum)
|
|
308 |
{
|
|
309 |
// no need to save collection related data, clear them
|
|
310 |
data.clear();
|
|
311 |
VideoActivityState::instance().setActivityData(data, KEY_COLLECTION_ID);
|
|
312 |
VideoActivityState::instance().setActivityData(data, KEY_COLLECTION_NAME);
|
|
313 |
}
|
39
|
314 |
}
|
41
|
315 |
|
39
|
316 |
// ---------------------------------------------------------------------------
|
41
|
317 |
// getActivityWidgetLevel
|
39
|
318 |
// ---------------------------------------------------------------------------
|
|
319 |
//
|
41
|
320 |
void VideoCollectionViewUtils::getActivityWidgetLevel(VideoCollectionCommon::TCollectionLevels &level)
|
39
|
321 |
{
|
|
322 |
FUNC_LOG;
|
41
|
323 |
// default value is all videos list level
|
|
324 |
level = VideoCollectionCommon::ELevelVideos;
|
|
325 |
QVariant data = VideoActivityState::instance().getActivityData(KEY_WIDGET_LEVEL);
|
|
326 |
|
|
327 |
int value = data.toInt();
|
|
328 |
if(value == VideoCollectionCommon::ELevelCategory)
|
39
|
329 |
{
|
|
330 |
level = VideoCollectionCommon::ELevelCategory;
|
|
331 |
}
|
41
|
332 |
else if(value == VideoCollectionCommon::ELevelDefaultColl)
|
|
333 |
{
|
|
334 |
level = VideoCollectionCommon::ELevelDefaultColl;
|
|
335 |
}
|
|
336 |
else if(value == VideoCollectionCommon::ELevelAlbum)
|
|
337 |
{
|
|
338 |
level = VideoCollectionCommon::ELevelAlbum;
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
// ---------------------------------------------------------------------------
|
|
343 |
// setCollectionActivityData
|
|
344 |
// ---------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
void VideoCollectionViewUtils::setCollectionActivityData(const TMPXItemId &id, const QString &name)
|
|
347 |
{
|
|
348 |
FUNC_LOG;
|
|
349 |
QVariant data = int(id.iId1);
|
|
350 |
VideoActivityState::instance().setActivityData(data, KEY_COLLECTION_ID);
|
|
351 |
data.clear();
|
|
352 |
data = name;
|
|
353 |
VideoActivityState::instance().setActivityData(data, KEY_COLLECTION_NAME);
|
|
354 |
}
|
39
|
355 |
|
41
|
356 |
// ---------------------------------------------------------------------------
|
|
357 |
// getCollectionActivityData
|
|
358 |
// ---------------------------------------------------------------------------
|
|
359 |
//
|
|
360 |
void VideoCollectionViewUtils::getCollectionActivityData(TMPXItemId &id, QString &name)
|
|
361 |
{
|
|
362 |
FUNC_LOG;
|
|
363 |
id = TMPXItemId::InvalidId();
|
|
364 |
name = "";
|
|
365 |
VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
|
|
366 |
getActivityWidgetLevel(level);
|
|
367 |
|
|
368 |
if(level == VideoCollectionCommon::ELevelDefaultColl)
|
|
369 |
{
|
|
370 |
id.iId2 = KVcxMvcMediaTypeCategory;
|
|
371 |
}
|
|
372 |
else if(level == VideoCollectionCommon::ELevelAlbum)
|
|
373 |
{
|
|
374 |
id.iId2 = KVcxMvcMediaTypeAlbum;
|
|
375 |
}
|
|
376 |
if(id.iId2 != KMaxTUint32)
|
|
377 |
{
|
|
378 |
QVariant data = VideoActivityState::instance().getActivityData(KEY_COLLECTION_ID);
|
|
379 |
id.iId1 = data.toInt();
|
|
380 |
data = VideoActivityState::instance().getActivityData(KEY_COLLECTION_NAME);
|
|
381 |
name = data.toString();
|
|
382 |
}
|
39
|
383 |
}
|
|
384 |
|
|
385 |
// ---------------------------------------------------------------------------
|
30
|
386 |
// showStatusMsgSlot
|
|
387 |
// ---------------------------------------------------------------------------
|
|
388 |
//
|
|
389 |
void VideoCollectionViewUtils::showStatusMsgSlot(int statusCode, QVariant &additional)
|
|
390 |
{
|
36
|
391 |
FUNC_LOG;
|
30
|
392 |
QString msg("");
|
34
|
393 |
QString format("");
|
30
|
394 |
bool error(true);
|
34
|
395 |
switch(statusCode)
|
30
|
396 |
{
|
34
|
397 |
case VideoCollectionCommon::statusSingleDeleteFail:
|
35
|
398 |
format = hbTrId("txt_videos_info_unable_to_delete_1_it_is_current");
|
34
|
399 |
if(additional.isValid())
|
|
400 |
{
|
44
|
401 |
msg = HbParameterLengthLimiter(format).arg(additional.toString());
|
34
|
402 |
}
|
|
403 |
break;
|
|
404 |
case VideoCollectionCommon::statusMultipleDeleteFail:
|
35
|
405 |
msg = hbTrId("txt_videos_info_unable_to_delete_some_items_which");
|
34
|
406 |
break;
|
|
407 |
case VideoCollectionCommon::statusSingleRemoveFail:
|
36
|
408 |
format = hbTrId("txt_videos_info_unable_to_remove_collection_1");
|
34
|
409 |
if(additional.isValid())
|
|
410 |
{
|
|
411 |
msg = format.arg(additional.toString());
|
|
412 |
}
|
|
413 |
break;
|
|
414 |
case VideoCollectionCommon::statusMultiRemoveFail:
|
36
|
415 |
msg = hbTrId("txt_videos_info_unable_to_remove_some_collections");
|
34
|
416 |
break;
|
38
|
417 |
case VideoCollectionCommon::statusVideosAddedToCollection:
|
|
418 |
// videos added to collection - status should containg both count and collection name
|
|
419 |
if(additional.isValid() && additional.toList().count() == KAddToCollectionDataCount)
|
34
|
420 |
{
|
38
|
421 |
int count = additional.toList().at(KAddToCollectionCountIndex).toInt();
|
|
422 |
QString name = additional.toList().at(KAddToCollectionNameIndex).toString();
|
|
423 |
if(count && name.length())
|
|
424 |
{
|
|
425 |
msg = hbTrId("txt_videos_dpopinfo_ln_videos_added_to_1", count).arg(name);
|
|
426 |
}
|
34
|
427 |
}
|
|
428 |
error = false;
|
|
429 |
break;
|
|
430 |
case VideoCollectionCommon::statusAllVideosAlreadyInCollection:
|
36
|
431 |
msg = hbTrId("txt_videos_info_all_videos_already_added_to_this_c");
|
34
|
432 |
break;
|
|
433 |
case VideoCollectionCommon::statusDeleteInProgress:
|
|
434 |
if(additional.isValid())
|
|
435 |
{
|
38
|
436 |
msg = hbTrId("txt_videos_dpopinfo_ln_videos_are_being_deleted", additional.toInt());
|
34
|
437 |
}
|
|
438 |
error = false;
|
|
439 |
break;
|
|
440 |
default: // no msg to show
|
36
|
441 |
return;
|
30
|
442 |
}
|
36
|
443 |
|
30
|
444 |
if(msg.count() > 0)
|
|
445 |
{
|
|
446 |
if(error)
|
|
447 |
{
|
38
|
448 |
HbMessageBox *messageBox = new HbMessageBox(msg, HbMessageBox::MessageTypeWarning);
|
|
449 |
messageBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
450 |
messageBox->setObjectName(VIEW_UTILS_OBJECT_NAME_MESSAGE_BOX_WARNING);
|
|
451 |
messageBox->show();
|
30
|
452 |
}
|
|
453 |
else
|
|
454 |
{
|
36
|
455 |
HbNotificationDialog *infoNote = new HbNotificationDialog();
|
|
456 |
infoNote->setAttribute(Qt::WA_DeleteOnClose);
|
|
457 |
// only title can be two rows for HbNotificationDialog
|
|
458 |
infoNote->setTitleTextWrapping(Hb::TextWordWrap);
|
|
459 |
infoNote->setTitle(msg);
|
38
|
460 |
infoNote->setObjectName(VIEW_UTILS_OBJECT_NAME_STATUS_MSG);
|
36
|
461 |
infoNote->show();
|
30
|
462 |
}
|
36
|
463 |
}
|
30
|
464 |
}
|
|
465 |
|
38
|
466 |
// End of file
|