63
|
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: VideoListToolbar class source code
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
66
|
18 |
// Version : %version: 1.1.3 %
|
63
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <qactiongroup.h>
|
|
22 |
#include <hbaction.h>
|
|
23 |
#include <hbtoolbarextension.h>
|
|
24 |
#include <vcxmyvideosdefs.h>
|
|
25 |
|
|
26 |
#include "videolisttoolbar.h"
|
|
27 |
#include "videoservices.h"
|
|
28 |
#include "videooperatorservice.h"
|
|
29 |
#include "videocollectioncenrepdefs.h"
|
|
30 |
#include "videocollectiontrace.h"
|
|
31 |
#include "videolistview.h"
|
|
32 |
#include "videocollectionuiloader.h"
|
|
33 |
#include "videolistwidget.h"
|
|
34 |
#include "videoproxymodelgeneric.h"
|
|
35 |
#include "videolistselectiondialog.h"
|
|
36 |
|
|
37 |
// Object names.
|
|
38 |
const char* const LIST_VIEW_OBJECT_NAME_TOOLBAR_EXTENSION = "vc::ListViewToolbarExtension";
|
|
39 |
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
// Constructor
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
VideoListToolbar::VideoListToolbar(VideoCollectionUiLoader* uiLoader, VideoListView* parent)
|
|
45 |
: QObject(parent)
|
|
46 |
, mCurrentLevel(VideoCollectionCommon::ELevelInvalid)
|
|
47 |
, mUiUtils(VideoCollectionViewUtils::instance())
|
|
48 |
, mUiLoader(uiLoader)
|
|
49 |
, mListView(parent)
|
|
50 |
, mVideoServices(0)
|
|
51 |
, mToolbarViewsActionGroup(0)
|
|
52 |
, mToolbarCollectionActionGroup(0)
|
|
53 |
, mToolbarServiceExtension(0)
|
|
54 |
{
|
|
55 |
FUNC_LOG;
|
|
56 |
}
|
|
57 |
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
// Destructor
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
VideoListToolbar::~VideoListToolbar()
|
|
63 |
{
|
|
64 |
FUNC_LOG;
|
|
65 |
|
|
66 |
emit actionsChanged(mViewStateActions[VideoCollectionCommon::ELevelInvalid]);
|
|
67 |
|
|
68 |
mToolbarActions.clear();
|
|
69 |
|
|
70 |
delete mToolbarServiceExtension;
|
|
71 |
mToolbarServiceExtension = 0;
|
|
72 |
|
|
73 |
if(mVideoServices)
|
|
74 |
{
|
|
75 |
mVideoServices->decreaseReferenceCount();
|
|
76 |
mVideoServices = 0;
|
|
77 |
}
|
|
78 |
|
|
79 |
QList<VideoOperatorService *>::const_iterator iter = mVideoOperatorServices.constBegin();
|
|
80 |
while(iter != mVideoOperatorServices.constEnd())
|
|
81 |
{
|
|
82 |
delete *iter;
|
|
83 |
iter++;
|
|
84 |
}
|
|
85 |
mVideoOperatorServices.clear();
|
|
86 |
}
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// initialize()
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
void VideoListToolbar::initialize()
|
|
93 |
{
|
|
94 |
if (mUiUtils.isService())
|
|
95 |
{
|
|
96 |
INFO("VideoListToolbar::initialize() initializing service.");
|
|
97 |
if (!mVideoServices)
|
|
98 |
{
|
|
99 |
mVideoServices = VideoServices::instance();
|
|
100 |
}
|
|
101 |
|
|
102 |
}
|
|
103 |
else if(mVideoServices)
|
|
104 |
{
|
|
105 |
mVideoServices->decreaseReferenceCount();
|
|
106 |
mVideoServices = 0;
|
|
107 |
}
|
|
108 |
|
|
109 |
createToolbarActions();
|
|
110 |
}
|
|
111 |
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
// viewStateChanged()
|
|
114 |
// ---------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void VideoListToolbar::viewStateChanged(
|
|
117 |
VideoCollectionCommon::TCollectionLevels currentLevel,
|
|
118 |
bool noVideos, bool modelReady)
|
|
119 |
{
|
|
120 |
if(!mToolbarViewsActionGroup || !mToolbarCollectionActionGroup)
|
|
121 |
{
|
|
122 |
// not initialized yet.
|
|
123 |
return;
|
|
124 |
}
|
|
125 |
|
|
126 |
if(currentLevel != mCurrentLevel)
|
|
127 |
{
|
|
128 |
QList<QAction*> newActions = mViewStateActions[currentLevel];
|
|
129 |
QList<QAction*> oldActions = mViewStateActions[mCurrentLevel];
|
|
130 |
|
|
131 |
mCurrentLevel = currentLevel;
|
|
132 |
|
|
133 |
if(newActions != oldActions)
|
|
134 |
{
|
|
135 |
emit actionsChanged(newActions);
|
|
136 |
|
|
137 |
if(mToolbarServiceExtension &&
|
|
138 |
(mCurrentLevel == VideoCollectionCommon::ELevelCategory ||
|
|
139 |
mCurrentLevel == VideoCollectionCommon::ELevelVideos))
|
|
140 |
{
|
|
141 |
emit toolbarExtensionChanged(mToolbarServiceExtension);
|
|
142 |
}
|
|
143 |
// note don't need to clear the toolbar extension actions, as the
|
|
144 |
// actionsChanged signal should clear all previous actions.
|
|
145 |
}
|
|
146 |
|
|
147 |
if(mCurrentLevel == VideoCollectionCommon::ELevelVideos &&
|
|
148 |
!mToolbarActions[ETBActionAllVideos]->isChecked())
|
|
149 |
{
|
|
150 |
mToolbarActions[ETBActionAllVideos]->setChecked(true);
|
|
151 |
}
|
|
152 |
else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory &&
|
|
153 |
!mToolbarActions[ETBActionCollections]->isChecked())
|
|
154 |
{
|
|
155 |
mToolbarActions[ETBActionCollections]->setChecked(true);
|
|
156 |
}
|
|
157 |
}
|
|
158 |
if(!mVideoServices)
|
|
159 |
{
|
|
160 |
if(modelReady)
|
|
161 |
{
|
|
162 |
|
|
163 |
mToolbarActions[ETBActionAddVideos]->setVisible(true);
|
|
164 |
mToolbarActions[ETBActionRemoveVideos]->setVisible(!noVideos);
|
|
165 |
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
mToolbarActions[ETBActionAddVideos]->setVisible(false);
|
|
170 |
mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
|
|
171 |
}
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
// createToolbarActions()
|
|
177 |
// Creates toolbar actions and toolbar icons
|
|
178 |
// ---------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
void VideoListToolbar::createToolbarActions()
|
|
181 |
{
|
|
182 |
FUNC_LOG;
|
|
183 |
|
|
184 |
// Create actiongroup and add all actions to it. This ensures that only one is
|
|
185 |
// active at certain moment.
|
|
186 |
if(!mToolbarViewsActionGroup && !mToolbarCollectionActionGroup)
|
|
187 |
{
|
|
188 |
mToolbarViewsActionGroup = new QActionGroup(this);
|
|
189 |
mToolbarCollectionActionGroup = new QActionGroup(this);
|
|
190 |
|
|
191 |
// create toolbar item actions
|
|
192 |
|
|
193 |
// All Videos tab
|
|
194 |
mToolbarActions[ETBActionAllVideos] = createAction("qtg_mono_video",
|
|
195 |
mToolbarViewsActionGroup, SIGNAL(allVideosActionTriggered()));
|
|
196 |
|
|
197 |
// Collections tab
|
|
198 |
mToolbarActions[ETBActionCollections] = createAction("qtg_mono_video_collection",
|
|
199 |
mToolbarViewsActionGroup, SIGNAL(collectionViewActionTriggered()));
|
|
200 |
|
|
201 |
if (!mVideoServices)
|
|
202 |
{
|
|
203 |
// Create services button or toolbar extension depending how many operator
|
|
204 |
// services are configured.
|
|
205 |
createOperatorServicesToolbarActions();
|
|
206 |
|
|
207 |
// Add Videos tab
|
|
208 |
mToolbarActions[ETBActionAddVideos] =
|
|
209 |
createAction("qtg_mono_add_to_video_collection",
|
|
210 |
mToolbarCollectionActionGroup, SLOT(addVideosToCollectionSlot()));
|
|
211 |
|
|
212 |
// Remove Videos tab
|
|
213 |
mToolbarActions[ETBActionRemoveVideos] =
|
|
214 |
createAction("qtg_mono_remove_from_video_collection",
|
|
215 |
mToolbarCollectionActionGroup, SLOT(removeVideosFromCollectionSlot()));
|
|
216 |
}
|
|
217 |
|
|
218 |
// Collection view actions are not checkable
|
|
219 |
mToolbarActions[ETBActionAllVideos]->setCheckable(true);
|
|
220 |
mToolbarActions[ETBActionCollections]->setCheckable(true);
|
|
221 |
|
|
222 |
if(!mVideoServices && mToolbarActions[ETBActionServices])
|
|
223 |
{
|
|
224 |
mToolbarActions[ETBActionServices]->setCheckable(false);
|
|
225 |
}
|
|
226 |
|
|
227 |
mViewStateActions[VideoCollectionCommon::ELevelCategory] = mToolbarViewsActionGroup->actions();
|
|
228 |
mViewStateActions[VideoCollectionCommon::ELevelVideos] = mToolbarViewsActionGroup->actions();
|
|
229 |
if(!mVideoServices)
|
|
230 |
{
|
|
231 |
mViewStateActions[VideoCollectionCommon::ELevelAlbum] = mToolbarCollectionActionGroup->actions();
|
|
232 |
}
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
// createOperatorServicesToolbar()
|
|
238 |
// ---------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
void VideoListToolbar::createOperatorServicesToolbarActions()
|
|
241 |
{
|
|
242 |
FUNC_LOG;
|
|
243 |
if(mVideoOperatorServices.count() > 0)
|
|
244 |
{
|
|
245 |
return;
|
|
246 |
}
|
|
247 |
|
|
248 |
// Load services.
|
|
249 |
|
|
250 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem1Title, KVideoCollectionViewCenrepServiceItem1ToolbarIconPath,
|
|
251 |
KVideoCollectionViewCenrepServiceItem1Url, KVideoCollectionViewCenrepServiceItem1Uid);
|
|
252 |
|
|
253 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem2Title, KVideoCollectionViewCenrepServiceItem2ToolbarIconPath,
|
|
254 |
KVideoCollectionViewCenrepServiceItem2Url, KVideoCollectionViewCenrepServiceItem2Uid);
|
|
255 |
|
|
256 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem3Title, KVideoCollectionViewCenrepServiceItem3ToolbarIconPath,
|
|
257 |
KVideoCollectionViewCenrepServiceItem3Url, KVideoCollectionViewCenrepServiceItem3Uid);
|
|
258 |
|
|
259 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem4Title, KVideoCollectionViewCenrepServiceItem4ToolbarIconPath,
|
|
260 |
KVideoCollectionViewCenrepServiceItem4Url, KVideoCollectionViewCenrepServiceItem4Uid);
|
|
261 |
|
|
262 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem5Title, KVideoCollectionViewCenrepServiceItem5ToolbarIconPath,
|
|
263 |
KVideoCollectionViewCenrepServiceItem5Url, KVideoCollectionViewCenrepServiceItem5Uid);
|
|
264 |
|
|
265 |
loadOperatorService(KVideoCollectionViewCenrepServiceItem6Title, KVideoCollectionViewCenrepServiceItem6ToolbarIconPath,
|
|
266 |
KVideoCollectionViewCenrepServiceItem6Url, KVideoCollectionViewCenrepServiceItem6Uid);
|
|
267 |
|
|
268 |
// Create toolbar extension when there's multiple services.
|
|
269 |
if(mVideoOperatorServices.count() > 1 && !mToolbarServiceExtension)
|
|
270 |
{
|
|
271 |
mToolbarServiceExtension = new HbToolBarExtension();
|
|
272 |
mToolbarServiceExtension->setObjectName(LIST_VIEW_OBJECT_NAME_TOOLBAR_EXTENSION);
|
|
273 |
|
|
274 |
QList<VideoOperatorService *>::const_iterator iter = mVideoOperatorServices.constBegin();
|
|
275 |
while(iter != mVideoOperatorServices.constEnd())
|
|
276 |
{
|
|
277 |
HbIcon icon((*iter)->iconResource());
|
|
278 |
HbAction *action = mToolbarServiceExtension->addAction(icon, (*iter)->title(),
|
|
279 |
(*iter), SLOT(launchService()));
|
|
280 |
action->setObjectName((*iter)->title());
|
|
281 |
iter++;
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
// Add toolbar button when there's only one service.
|
|
286 |
if(mVideoOperatorServices.count() == 1)
|
|
287 |
{
|
|
288 |
VideoOperatorService *service = mVideoOperatorServices[0];
|
|
289 |
mToolbarActions[ETBActionServices] = createAction(service->iconResource(),
|
|
290 |
mToolbarViewsActionGroup, 0 /*do not connect to any slot*/);
|
|
291 |
connect(mToolbarActions[ETBActionServices], SIGNAL(triggered()), service, SLOT(launchService()));
|
|
292 |
}
|
|
293 |
}
|
|
294 |
|
|
295 |
// ---------------------------------------------------------------------------
|
|
296 |
// loadOperatorService()
|
|
297 |
// ---------------------------------------------------------------------------
|
|
298 |
//
|
|
299 |
void VideoListToolbar::loadOperatorService(int titleKey, int iconKey, int uriKey, int uidKey)
|
|
300 |
{
|
|
301 |
FUNC_LOG;
|
|
302 |
VideoOperatorService *service = new VideoOperatorService();
|
|
303 |
if(service->load(titleKey, iconKey, uriKey, uidKey))
|
|
304 |
{
|
|
305 |
mVideoOperatorServices.append(service);
|
|
306 |
}
|
|
307 |
else
|
|
308 |
{
|
|
309 |
// Load failed, delete service data.
|
|
310 |
delete service;
|
|
311 |
}
|
|
312 |
}
|
|
313 |
|
|
314 |
// -------------------------------------------------------------------------------------------------
|
|
315 |
// addVideosToCollectionSlot()
|
|
316 |
// -------------------------------------------------------------------------------------------------
|
|
317 |
//
|
|
318 |
void VideoListToolbar::addVideosToCollectionSlot()
|
|
319 |
{
|
|
320 |
FUNC_LOG;
|
|
321 |
|
|
322 |
VideoListWidget* currentList = mListView->getCurrentList();
|
|
323 |
|
|
324 |
if(!currentList || !currentList->getModel())
|
|
325 |
{
|
|
326 |
return;
|
|
327 |
}
|
|
328 |
|
|
329 |
VideoListSelectionDialog *dialog =
|
|
330 |
mUiLoader->findWidget<VideoListSelectionDialog>(
|
|
331 |
DOCML_NAME_DIALOG);
|
|
332 |
if (!dialog)
|
|
333 |
{
|
|
334 |
// fatal: no selection dialog
|
|
335 |
return;
|
|
336 |
}
|
|
337 |
|
|
338 |
// do not proceed in case it already have same amount
|
|
339 |
// of videos than all videos view.
|
|
340 |
VideoListWidget *allVideos = mUiLoader->findWidget<VideoListWidget>(
|
|
341 |
DOCML_NAME_VC_VIDEOLISTWIDGET);
|
|
342 |
if(allVideos && allVideos->getModel())
|
|
343 |
{
|
|
344 |
int count = allVideos->getModel()->rowCount();
|
|
345 |
if(count == currentList->getModel()->rowCount())
|
|
346 |
{
|
|
347 |
if(count)
|
|
348 |
{
|
|
349 |
QVariant emptyAdditional;
|
|
350 |
mUiUtils.showStatusMsgSlot(
|
|
351 |
VideoCollectionCommon::statusAllVideosAlreadyInCollection,
|
|
352 |
emptyAdditional);
|
|
353 |
}
|
|
354 |
return;
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
TMPXItemId collectionId = currentList->getModel()->getOpenItem();
|
|
359 |
dialog->setupContent(VideoListSelectionDialog::EAddToCollection, collectionId);
|
|
360 |
dialog->exec();
|
|
361 |
}
|
|
362 |
|
|
363 |
// -------------------------------------------------------------------------------------------------
|
|
364 |
// removeVideosFromCollectionSlot()
|
|
365 |
// -------------------------------------------------------------------------------------------------
|
|
366 |
//
|
|
367 |
void VideoListToolbar::removeVideosFromCollectionSlot()
|
|
368 |
{
|
|
369 |
FUNC_LOG;
|
|
370 |
|
|
371 |
VideoListWidget* currentList = mListView->getCurrentList();
|
|
372 |
|
|
373 |
if(!currentList || !currentList->getModel())
|
|
374 |
{
|
|
375 |
return;
|
|
376 |
}
|
|
377 |
|
|
378 |
// not allowed if for some reason current widget
|
|
379 |
// is all videos or collection or there are no items
|
|
380 |
if(currentList->getLevel() != VideoCollectionCommon::ELevelAlbum ||
|
|
381 |
!currentList->getModel()->rowCount())
|
|
382 |
{
|
|
383 |
return;
|
|
384 |
}
|
|
385 |
|
|
386 |
VideoListSelectionDialog *dialog =
|
|
387 |
mUiLoader->findWidget<VideoListSelectionDialog>(
|
|
388 |
DOCML_NAME_DIALOG);
|
|
389 |
if (!dialog)
|
|
390 |
{
|
|
391 |
ERROR(-1, "VideoListView::removeVideosFromCollectionSlot() failed to load selection dialog.");
|
|
392 |
return;
|
|
393 |
}
|
|
394 |
|
|
395 |
TMPXItemId collectionId = currentList->getModel()->getOpenItem();
|
|
396 |
if(collectionId != TMPXItemId::InvalidId() && collectionId.iId2 == KVcxMvcMediaTypeAlbum)
|
|
397 |
{
|
|
398 |
dialog->setupContent(VideoListSelectionDialog::ERemoveFromCollection, collectionId);
|
|
399 |
dialog->exec();
|
|
400 |
}
|
|
401 |
}
|
|
402 |
|
|
403 |
// ---------------------------------------------------------------------------
|
|
404 |
// createAction()
|
|
405 |
// ---------------------------------------------------------------------------
|
|
406 |
//
|
|
407 |
HbAction* VideoListToolbar::createAction(QString icon,
|
|
408 |
QActionGroup* actionGroup, const char *slot)
|
|
409 |
{
|
|
410 |
FUNC_LOG;
|
|
411 |
HbAction* action = new HbAction(actionGroup);
|
|
412 |
|
|
413 |
HbIcon hbIcon(icon);
|
|
414 |
action->setIcon(hbIcon);
|
|
415 |
|
|
416 |
if(slot)
|
|
417 |
{
|
|
418 |
if(!connect(action, SIGNAL(triggered()), this, slot)) {
|
|
419 |
// actiongroup deletion deletes this also.
|
|
420 |
// return 0 tells that there was a problem in creation to caller.
|
|
421 |
delete action;
|
|
422 |
return 0;
|
|
423 |
}
|
|
424 |
}
|
|
425 |
|
|
426 |
return action;
|
|
427 |
}
|
|
428 |
|
|
429 |
// End of file
|