190 // activateSelection |
207 // activateSelection |
191 // --------------------------------------------------------------------------- |
208 // --------------------------------------------------------------------------- |
192 // |
209 // |
193 void VideoListSelectionDialog::activateSelection() |
210 void VideoListSelectionDialog::activateSelection() |
194 { |
211 { |
195 // "add to collection" and "select collection" -selections needs |
212 // "add to collection" and "remove from collection -selections needs |
196 // additional functionality for primary key |
213 // additional functionality for primary key |
197 if(mTypeOfSelection == EAddToCollection || |
214 if(mTypeOfSelection == EAddToCollection || |
198 mTypeOfSelection == ESelectCollection) |
215 mTypeOfSelection == ERemoveFromCollection) |
199 { |
216 { |
200 primaryAction()->disconnect(SIGNAL(triggered())); |
217 primaryAction()->disconnect(SIGNAL(triggered())); |
201 connect(primaryAction(), SIGNAL(triggered()), this, SLOT(primaryActionTriggeredSlot())); |
218 connect(primaryAction(), SIGNAL(triggered()), this, SLOT(primaryActionTriggeredSlot())); |
202 } |
219 } |
203 |
220 QString headingTxt(""); |
204 if(mTypeOfSelection == EDeleteVideos || mTypeOfSelection == EAddToCollection) |
221 QString primaryTxt(""); |
205 { |
222 // create texts |
206 mSelection.clear(); |
223 switch(mTypeOfSelection) |
207 mListWidget->setSelectionMode(HbAbstractItemView::MultiSelection); |
224 { |
|
225 case EDeleteVideos: |
|
226 primaryTxt = hbTrId("txt_common_button_delete"); |
|
227 break; |
|
228 case EAddToCollection: |
|
229 primaryTxt = hbTrId("txt_common_button_add"); |
|
230 break; |
|
231 case ERemoveFromCollection: |
|
232 primaryTxt = hbTrId("txt_common_button_remove"); |
|
233 break; |
|
234 case ESelectCollection: |
|
235 primaryTxt = hbTrId("txt_videos_button_new"); |
|
236 break; |
|
237 default: |
|
238 break; |
|
239 } |
|
240 |
|
241 HbAction *primary = primaryAction(); |
|
242 primary->setText(primaryTxt); |
|
243 |
|
244 if(mTypeOfSelection == ESelectCollection) |
|
245 { |
|
246 headingTxt = hbTrId("txt_videos_title_select_collection"); |
|
247 mCheckboxContainer->setVisible(false); |
|
248 mListWidget->setSelectionMode(-1); |
|
249 mListWidget->activate(VideoCollectionCommon::ELevelCategory); |
|
250 // need to set primaryaction disabled here in order for it |
|
251 // get correctly updated at modelReady(), where it will be enabled |
|
252 // if state would be same, no update will happen |
|
253 primary->setDisabled(true); |
|
254 } |
|
255 else |
|
256 { |
|
257 headingTxt = hbTrId("txt_videos_title_select_videos"); |
|
258 mListWidget->setSelectionMode(HbAbstractItemView::MultiSelection); |
208 mListWidget->activate(VideoCollectionCommon::ELevelVideos); |
259 mListWidget->activate(VideoCollectionCommon::ELevelVideos); |
209 mCheckboxContainer->setVisible(true); |
260 mCheckboxContainer->setVisible(true); |
210 mItemCount->setPlainText(tr("0/%1").arg(mModel->rowCount())); |
261 mItemCount->setPlainText(tr("0/%1").arg(mModel->rowCount())); |
211 mCheckBox->setChecked(false); |
262 mCheckBox->setChecked(false); |
212 QString txt(""); |
263 // need to set primaryaction enabled here in order for it |
213 mTypeOfSelection == EDeleteVideos ? txt = tr("Delete items") : txt = tr("Add to collection"); // localisation missing |
264 // get correctly updated at modelReady(), where it will be disabled |
214 mHeading->setPlainText(txt); |
265 // if state would be same, no update will happen |
215 mTypeOfSelection == EDeleteVideos ? txt = hbTrId("txt_common_menu_delete") : txt = tr("Add"); // localisation missing |
266 primary->setDisabled(false); |
216 primaryAction()->setText(txt); |
267 } |
217 primaryAction()->setDisabled(true); |
268 mHeading->setPlainText(headingTxt); |
218 } |
|
219 else |
|
220 { |
|
221 mListWidget->setSelectionMode(-1); |
|
222 mListWidget->activate(VideoCollectionCommon::ELevelCategory); |
|
223 mCheckboxContainer->setVisible(false); |
|
224 mHeading->setPlainText(tr("Select collection")); // localisation missing |
|
225 primaryAction()->setText(tr("New")); // localisation missing |
|
226 primaryAction()->setDisabled(false); |
|
227 } |
|
228 // sort to make sure dialog has correctly filtered content |
269 // sort to make sure dialog has correctly filtered content |
229 // at the same order as in view |
270 // at the same order as in view |
230 VideoCollectionViewUtils::sortModel(mModel, false); |
271 VideoCollectionViewUtils::sortModel(mModel, false); |
231 } |
272 } |
232 |
273 |
233 // --------------------------------------------------------------------------- |
274 // --------------------------------------------------------------------------- |
234 // exec |
275 // exec |
235 // --------------------------------------------------------------------------- |
276 // --------------------------------------------------------------------------- |
236 // |
277 // |
237 HbAction* VideoListSelectionDialog::exec() |
278 void VideoListSelectionDialog::exec() |
238 { |
279 { |
239 // clear checkbox |
280 // clear checkbox |
240 mCheckBox->setChecked(false); |
281 mCheckBox->setChecked(false); |
241 |
282 |
242 mListWidget->clearSelection(); |
283 mListWidget->clearSelection(); |
243 |
284 |
244 // scroll list back to top |
285 // scroll list back to top |
245 mListWidget->scrollTo(mModel->index(0, 0)); |
286 mListWidget->scrollTo(mModel->index(0, 0)); |
246 |
287 |
247 connectSignals(); |
288 if(mModel->rowCount()) |
248 |
289 { |
249 // Launch popup syncronously |
290 connectSignals(); |
250 bool accepted = false; |
291 |
251 HbDialog::exec() == primaryAction() ? accepted = true : accepted = false; |
292 // show dialog |
252 |
293 HbDialog::open(); |
|
294 } |
|
295 else |
|
296 { |
|
297 // no items, finish right away |
|
298 finishedSlot(primaryAction()); |
|
299 } |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // finishedSlot |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void VideoListSelectionDialog::finishedSlot(HbAction *action) |
|
307 { |
253 disconnectSignals(); |
308 disconnectSignals(); |
254 |
309 if(action == secondaryAction()) |
255 if(accepted) |
310 { |
256 { |
311 return; |
257 // user is adding videos into selected collection |
312 } |
258 // or selecting collection where to add videos |
313 QString albumName(""); |
259 if(mTypeOfSelection == EAddToCollection || |
314 if( mTypeOfSelection == ESelectCollection ) |
260 mTypeOfSelection == ESelectCollection) |
315 { |
261 { |
316 if( mSelectedAlbumId == TMPXItemId::InvalidId()) |
262 if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count()) |
317 { |
|
318 albumName = queryNewAlbumSelected(); |
|
319 if(mSelectedAlbumId == TMPXItemId::InvalidId()) |
263 { |
320 { |
264 if(mModel->addItemsInAlbum(mSelectedAlbumId, mSelectedVideos.toList()) == 0) |
321 // user cancelled new album creation |
|
322 return; |
|
323 } |
|
324 } |
|
325 mTypeOfSelection = EAddToCollection; |
|
326 |
|
327 } |
|
328 |
|
329 if(mTypeOfSelection == EAddToCollection) |
|
330 { |
|
331 if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count()) |
|
332 { |
|
333 if(mModel->addItemsInAlbum(mSelectedAlbumId, mSelectedVideos.toList()) == 0) |
|
334 { |
|
335 if(!albumName.length()) |
265 { |
336 { |
266 QVariant data = getSelectedName(); |
337 albumName = getSelectedName(); |
267 VideoCollectionViewUtils::instance().showStatusMsgSlot( |
|
268 VideoCollectionCommon::statusVideosAddedToCollection, |
|
269 data); |
|
270 } |
338 } |
|
339 QVariant data = albumName; |
|
340 VideoCollectionViewUtils::instance().showStatusMsgSlot( |
|
341 VideoCollectionCommon::statusVideosAddedToCollection, |
|
342 data); |
271 } |
343 } |
272 } |
344 } |
273 // user is deleting videos |
345 } |
274 else if(mTypeOfSelection == EDeleteVideos) |
346 else if(mTypeOfSelection == ERemoveFromCollection) |
275 { |
347 { |
276 QVariant data = mSelection.indexes().count(); |
348 if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count()) |
277 VideoCollectionViewUtils::instance().showStatusMsgSlot( |
349 { |
278 VideoCollectionCommon::statusDeleteInProgress, |
350 if(mModel->removeItemsFromAlbum(mSelectedAlbumId, mSelectedVideos.toList()) == 0) |
279 data); |
351 { |
280 // delete items |
352 QVariant data = getSelectedName(); |
281 mModel->deleteItems(mSelection.indexes()); |
353 VideoCollectionViewUtils::instance().showStatusMsgSlot( |
282 |
354 VideoCollectionCommon::statusVideosRemovedFromCollection, |
283 } |
355 data); |
284 return primaryAction(); |
356 } |
|
357 } |
|
358 } |
|
359 // user is deleting videos |
|
360 else if(mTypeOfSelection == EDeleteVideos) |
|
361 { |
|
362 QVariant data = mSelection.indexes().count(); |
|
363 VideoCollectionViewUtils::instance().showStatusMsgSlot( |
|
364 VideoCollectionCommon::statusDeleteInProgress, |
|
365 data); |
|
366 // delete items |
|
367 mModel->deleteItems(mSelection.indexes()); |
285 } |
368 } |
286 return secondaryAction(); |
|
287 } |
369 } |
288 |
370 |
289 // --------------------------------------------------------------------------- |
371 // --------------------------------------------------------------------------- |
290 // markAllStateChanged |
372 // markAllStateChanged |
291 // --------------------------------------------------------------------------- |
373 // --------------------------------------------------------------------------- |
360 // modelReadySlot |
441 // modelReadySlot |
361 // --------------------------------------------------------------------------- |
442 // --------------------------------------------------------------------------- |
362 // |
443 // |
363 void VideoListSelectionDialog::modelReadySlot() |
444 void VideoListSelectionDialog::modelReadySlot() |
364 { |
445 { |
365 if(!mModel) |
446 |
|
447 if(mTypeOfSelection == ESelectCollection) |
|
448 { |
|
449 primaryAction()->setDisabled(false); |
|
450 if(!mModel->rowCount()) |
|
451 { |
|
452 // in case there are no user defined albums, |
|
453 // start input dialog right away by accepting dialog |
|
454 primaryAction()->trigger(); |
|
455 return; |
|
456 } |
|
457 } |
|
458 if(mTypeOfSelection != ESelectCollection) |
|
459 { |
|
460 primaryAction()->setDisabled(true); |
|
461 } |
|
462 updateCounterSlot(); |
|
463 } |
|
464 |
|
465 // --------------------------------------------------------------------------- |
|
466 // updateCounterSlot |
|
467 // --------------------------------------------------------------------------- |
|
468 // |
|
469 void VideoListSelectionDialog::updateCounterSlot() |
|
470 { |
|
471 if(!mItemCount) |
366 { |
472 { |
367 return; |
473 return; |
368 } |
474 } |
369 |
475 |
370 if(mTypeOfSelection == ESelectCollection && ! mModel->rowCount()) |
476 int rowCount = mModel->rowCount(); |
371 { |
|
372 // in case there are no albums, start input dialog right away |
|
373 mSelectedAlbumId = queryNewAlbum(); |
|
374 if(mSelectedAlbumId != TMPXItemId::InvalidId()) |
|
375 { |
|
376 primaryAction()->trigger(); |
|
377 } |
|
378 else |
|
379 { |
|
380 secondaryAction()->trigger(); |
|
381 } |
|
382 return; |
|
383 } |
|
384 updateCounterSlot(); |
|
385 } |
|
386 |
|
387 // --------------------------------------------------------------------------- |
|
388 // updateCounterSlot |
|
389 // --------------------------------------------------------------------------- |
|
390 // |
|
391 void VideoListSelectionDialog::updateCounterSlot() |
|
392 { |
|
393 if(!mItemCount || !mModel) |
|
394 { |
|
395 return; |
|
396 } |
|
397 // orbit does not update HbLabel read from docml in case it isn't cleared first |
|
398 int rowCount = mModel->rowCount(); |
|
399 |
|
400 |
|
401 int selectionCount = mSelection.indexes().count(); |
477 int selectionCount = mSelection.indexes().count(); |
402 mItemCount->setPlainText(tr("%1/%2").arg(selectionCount).arg(rowCount)); |
478 mItemCount->setPlainText(tr("%1/%2").arg(selectionCount).arg(rowCount)); |
403 |
|
404 mForcedCheck = true; |
479 mForcedCheck = true; |
405 if(selectionCount == rowCount && rowCount > 0) |
480 if(selectionCount == rowCount && rowCount > 0) |
406 { |
481 { |
407 mCheckBox->setChecked(true); |
482 mCheckBox->setChecked(true); |
408 } |
483 } |
476 // --------------------------------------------------------------------------- |
528 // --------------------------------------------------------------------------- |
477 // connectSignals |
529 // connectSignals |
478 // --------------------------------------------------------------------------- |
530 // --------------------------------------------------------------------------- |
479 // |
531 // |
480 void VideoListSelectionDialog::connectSignals() |
532 void VideoListSelectionDialog::connectSignals() |
481 { |
533 { |
|
534 // dialog finished |
|
535 connect(this, SIGNAL(finished(HbAction*)), this, SLOT(finishedSlot(HbAction*))); |
|
536 |
482 // selection changes |
537 // selection changes |
483 connect(mListWidget, SIGNAL(activated(const QModelIndex&)), |
538 connect(mListWidget, SIGNAL(activated(const QModelIndex&)), |
484 this, SLOT(singleItemSelectedSlot(const QModelIndex&))); |
539 this, SLOT(singleItemSelectedSlot(const QModelIndex&))); |
485 |
540 |
486 connect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), |
541 connect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), |
487 this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &))); |
542 this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &))); |
488 |
543 |
489 // model changes signals |
544 // model changes signals |
490 connect(mModel, SIGNAL(modelReady()), this, SLOT(modelReadySlot())); |
545 connect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot())); |
491 connect(mModel, SIGNAL(modelChanged()), this, SLOT(updateCounterSlot())); |
546 connect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot())); |
492 |
547 |
493 // mark all state changes |
548 // mark all state changes |
494 connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int))); |
549 connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int))); |
495 } |
550 } |
496 |
551 |
497 // --------------------------------------------------------------------------- |
552 // --------------------------------------------------------------------------- |
498 // disconnectSignals |
553 // disconnectSignals |
499 // --------------------------------------------------------------------------- |
554 // --------------------------------------------------------------------------- |
500 // |
555 // |
501 void VideoListSelectionDialog::disconnectSignals() |
556 void VideoListSelectionDialog::disconnectSignals() |
502 { |
557 { |
|
558 disconnect(this, SIGNAL(finished(HbAction*)), this, SLOT(finishedSlot(HbAction*))); |
|
559 |
503 disconnect(mListWidget, SIGNAL(activated(const QModelIndex&)), |
560 disconnect(mListWidget, SIGNAL(activated(const QModelIndex&)), |
504 this, SLOT(singleItemSelectedSlot(const QModelIndex&))); |
561 this, SLOT(singleItemSelectedSlot(const QModelIndex&))); |
505 |
562 |
506 disconnect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), |
563 disconnect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), |
507 this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &))); |
564 this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &))); |
508 |
565 |
509 // model changes signals |
566 // model changes signals |
510 disconnect(mModel, SIGNAL(modelReady()), this, SLOT(modelReadySlot())); |
567 disconnect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot())); |
511 disconnect(mModel, SIGNAL(modelChanged()), this, SLOT(updateCounterSlot())); |
568 disconnect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot())); |
512 |
569 |
513 // mark all state changes |
570 // mark all state changes |
514 disconnect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int))); |
571 disconnect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int))); |
515 } |
572 } |
516 |
573 |