videocollection/videofiledetailsview/src/videofiledetailsviewplugin.cpp
changeset 30 4f111d64a341
child 34 bbb98528c666
equal deleted inserted replaced
2:dec420019252 30:4f111d64a341
       
     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:   VideoCollectionViewPlugin class implementation
       
    15 * 
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <xqserviceutil.h>
       
    20 #include <xqplugin.h>
       
    21 #include <hbview.h>
       
    22 #include <hbinstance.h>
       
    23 #include <hblabel.h>
       
    24 #include <hbstackedwidget.h>
       
    25 #include <hbmarqueeitem.h>
       
    26 #include <hbpushbutton.h>
       
    27 #include <hbaction.h>
       
    28 #include <hbratingslider.h>
       
    29 #include <hbscrollarea.h>
       
    30 #include <qabstractitemmodel.h>
       
    31 #include <qdebug.h>
       
    32 #include <hbmessagebox.h>
       
    33 #include <cmath>
       
    34 #include <hbframedrawer.h>
       
    35 #include <thumbnailmanager_qt.h>
       
    36 #include "videocollectionclient.h"
       
    37 #include "videofiledetailsviewplugin.h"
       
    38 #include "videocollectioncommon.h"
       
    39 #include "mpxhbvideocommondefs.h"
       
    40 #include "videocollectionwrapper.h"
       
    41 #include "videosortfilterproxymodel.h"
       
    42 #include "videoservices.h"
       
    43 
       
    44 const char* const VIDEO_DETAILS_DOCML = ":/xml/videofiledetails.docml";
       
    45 const char* const VIDEO_DETAILS_GFX_PLAY = ":/gfx/play.png";
       
    46 const char* const VIDEO_DETAILS_GFX_DEFAULT = ":/gfx/pri_large_video.svg";
       
    47 const char* const VIDEO_DETAILS_VIEW = "videofiledetailsview";
       
    48 const char* const VIDEO_DETAILS_TITLE = "mLblTitle";
       
    49 const char* const VIDEO_DETAILS_RATING = "mRatingSlider";
       
    50 const char* const VIDEO_DETAILS_LAYOUT_VIDEO_INFO = "mLayoutVideoInfo";
       
    51 const char* const VIDEO_DETAILS_DETAIL_SCROLL_AREA = "mDetailScrollArea";
       
    52 const char* const VIDEO_DETAILS_ITEM = "mLblDetail";
       
    53 const char* const VIDEO_DETAILS_BUTTON_PLAY = "mBtnPlay";
       
    54 const char* const VIDEO_DETAILS_BUTTON_ATTACH = "mBtnAttach";
       
    55 const char* const VIDEO_DETAILS_MENUACTION_DELETE = "mOptionsDelete";
       
    56 const char* const VIDEO_DETAILS_MENUACTION_SHARE = "mOptionsShare";
       
    57 
       
    58 const int VIDEO_DETAILS_DETAIL_AMOUNT = 6;
       
    59 
       
    60 // Just for testing, remove this 
       
    61 void _DebugNotImplementedYet()
       
    62 {
       
    63     HbMessageBox::information(QObject::tr("Not implemented yet"));
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Constructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 VideoFileDetailsViewPlugin::VideoFileDetailsViewPlugin()
       
    71     : mModel(0),
       
    72       mVideoServices(0),
       
    73       mActivated(false),
       
    74       mIsService(false),
       
    75       mCreated(VideoFileDetailsViewPlugin::ENotCreated),
       
    76       mVideoIndex(-1),
       
    77       mSecSkAction(0),
       
    78       mTitleAnim(0),
       
    79       mThumbnailManager(0)
       
    80 {
       
    81     mCollectionWrapper = VideoCollectionWrapper::instance();
       
    82 }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Destructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 VideoFileDetailsViewPlugin::~VideoFileDetailsViewPlugin()
       
    89 {
       
    90     destroyView();
       
    91 }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Create view
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void VideoFileDetailsViewPlugin::createView()
       
    98 {
       
    99     if (VideoFileDetailsViewPlugin::EPreCreated == mCreated)
       
   100     {
       
   101     	finalizeCreateView();
       
   102     }
       
   103     else if (VideoFileDetailsViewPlugin::ENotCreated == mCreated)
       
   104     {
       
   105     	preCreateView();
       
   106     }
       
   107 }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // preCreateView
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void VideoFileDetailsViewPlugin::preCreateView()
       
   114 {
       
   115 	mActivated = false;
       
   116 	mCreated = VideoFileDetailsViewPlugin::EPreCreated;
       
   117 	
       
   118 	if (!mThumbnailManager)
       
   119 	{
       
   120 		mThumbnailManager = new ThumbnailManager();
       
   121 	}
       
   122 }
       
   123 // ---------------------------------------------------------------------------
       
   124 // finalizeCreateView
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void VideoFileDetailsViewPlugin::finalizeCreateView()
       
   128 {
       
   129 	mView.reset();
       
   130 	mActivated = false;
       
   131 	mCreated = VideoFileDetailsViewPlugin::EFinalized;
       
   132 	bool ok = false;
       
   133 	mView.load(VIDEO_DETAILS_DOCML, &ok);
       
   134 
       
   135 	if(mCollectionWrapper)
       
   136 	{
       
   137 		mModel = mCollectionWrapper->getModel();
       
   138 	}
       
   139 
       
   140 	if (!mModel)
       
   141 		{
       
   142 		qDebug() << "VideoFileDetailsViewPlugin::createView(): Unable to open collection wrapper. Cannot connect slots, aborting...";
       
   143 		// TODO need to throw exception instead?
       
   144 		return;
       
   145 		}
       
   146 
       
   147 	mIsService = XQServiceUtil::isService();
       
   148 
       
   149 	// no deallocation needed for this since
       
   150 	// stackedwidget takes ownership
       
   151 	mTitleAnim = new HbMarqueeItem;
       
   152 	mTitleAnim->setLoopCount(-1);
       
   153 
       
   154 	connect(mModel,
       
   155 			SIGNAL(shortDetailsReady(int)),
       
   156 			this, SLOT(shortDetailsReadySlot(int)));
       
   157 
       
   158 	connect(mModel,
       
   159 			SIGNAL(fullDetailsReady(int)),
       
   160 			this, SLOT(fullDetailsReadySlot(int)));
       
   161 
       
   162 	connect(mModel,
       
   163 			SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
       
   164 			this, SLOT(rowsRemovedSlot(const QModelIndex&, int, int)));
       
   165 
       
   166 	HbPushButton* playBtn = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON_PLAY);
       
   167 	HbStackedWidget* title = findObject<HbStackedWidget>(VIDEO_DETAILS_TITLE);
       
   168 
       
   169 	title->addWidget(mTitleAnim);
       
   170 
       
   171 	HbFrameDrawer* drawer = new HbFrameDrawer("VideoDetailsFrameGraphic", HbFrameDrawer::OnePiece);
       
   172 	drawer->setFillWholeRect(true);
       
   173 	playBtn->setFrameBackground(drawer);
       
   174 
       
   175 	connect(playBtn, SIGNAL(clicked(bool)), this, SLOT(startPlaybackSlot()));
       
   176 
       
   177 	HbAction* deleteAction = findObject<HbAction>(VIDEO_DETAILS_MENUACTION_DELETE);
       
   178 	HbAction* shareAction = findObject<HbAction>(VIDEO_DETAILS_MENUACTION_SHARE);
       
   179 
       
   180 	if (mIsService)
       
   181 	{
       
   182 		deleteAction->setVisible(false);
       
   183 		shareAction->setVisible(false);
       
   184 	}
       
   185 	else
       
   186 	{
       
   187 		connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteVideoSlot()));
       
   188 		connect(shareAction, SIGNAL(triggered(bool)), this, SLOT(sendVideoSlot()));
       
   189 	}
       
   190 	mSecSkAction = new HbAction( Hb::BackAction );
       
   191 	
       
   192 	connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap,void*,int,int)), 
       
   193 			this, SLOT(thumbnailReadySlot(QPixmap,void*,int,int)));
       
   194 }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // Destroy view
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void VideoFileDetailsViewPlugin::destroyView()
       
   201 {
       
   202     if (mActivated)
       
   203     {
       
   204         deactivateView();
       
   205     }
       
   206 
       
   207     if(mVideoServices)
       
   208     {
       
   209     	mVideoServices->decreaseReferenceCount();
       
   210     	mVideoServices = 0;
       
   211     }
       
   212 
       
   213     if(mCollectionWrapper)
       
   214     {
       
   215         mCollectionWrapper->decreaseReferenceCount();
       
   216         mCollectionWrapper = 0;
       
   217     }
       
   218     
       
   219     delete mSecSkAction; mSecSkAction = 0;
       
   220     delete mThumbnailManager; mThumbnailManager = 0;
       
   221     disconnect();
       
   222     mView.reset();
       
   223 }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // Activate view
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void VideoFileDetailsViewPlugin::activateView()
       
   230 {
       
   231 	
       
   232 	if ( !mActivated && (VideoFileDetailsViewPlugin::EFinalized == mCreated))
       
   233     {
       
   234         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   235         mainWnd->addSoftKeyAction( Hb::SecondarySoftKey, mSecSkAction );
       
   236 
       
   237         Qt::Orientation orientation = mainWnd->orientation();
       
   238         if ( orientation == Qt::Vertical )
       
   239         {
       
   240         	if (mIsService)
       
   241         	{
       
   242             	mView.load(VIDEO_DETAILS_DOCML, "portrait_fetch");
       
   243         	}
       
   244         	else
       
   245         	{
       
   246         		mView.load(VIDEO_DETAILS_DOCML, "portrait");
       
   247         	}
       
   248         }
       
   249         else if ( orientation == Qt::Horizontal )
       
   250         {
       
   251         	if (mIsService)
       
   252         	{
       
   253         		mView.load(VIDEO_DETAILS_DOCML, "landscape_fetch");
       
   254         	}
       
   255         	else
       
   256         	{
       
   257         		mView.load(VIDEO_DETAILS_DOCML, "landscape");
       
   258         	}
       
   259         }
       
   260 
       
   261     	if (mIsService && !mVideoServices)
       
   262     	{
       
   263     		mVideoServices = VideoServices::instance();
       
   264 
       
   265 			if (!mVideoServices)
       
   266 			{
       
   267 				return;
       
   268 			}
       
   269 			else
       
   270 			{
       
   271 	    		HbPushButton* attachBtn = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON_ATTACH);
       
   272 	    		connect(attachBtn, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
       
   273 				connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
       
   274 			}
       
   275     	}
       
   276 
       
   277         connect(mainWnd->softKeyAction(Hb::SecondarySoftKey),
       
   278                 SIGNAL(triggered()), this, SLOT(back()));
       
   279         connect(mainWnd,
       
   280                 SIGNAL(orientationChanged(Qt::Orientation)),
       
   281                 this, SLOT(orientationChange(Qt::Orientation)));
       
   282         connect(mCollectionWrapper, 
       
   283                SIGNAL(asyncStatus(int, QVariant&)), 
       
   284                this, SLOT(handleErrorSlot(int, QVariant&)));
       
   285 
       
   286         // scroll the scrollarea back to top.
       
   287         findWidget<HbScrollArea>(VIDEO_DETAILS_DETAIL_SCROLL_AREA)->scrollContentsTo(QPointF(0, 0));
       
   288         
       
   289         // setup title size in order for animation to be enabled if needed
       
   290         mTitleAnim->setPreferredSize(findObject<HbStackedWidget>(VIDEO_DETAILS_TITLE)->preferredSize());
       
   291         mTitleAnim->adjustSize();
       
   292         
       
   293         mActivated = true;
       
   294     }
       
   295 }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // Deactivate view
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void VideoFileDetailsViewPlugin::deactivateView()
       
   302 {
       
   303     if ( mActivated )
       
   304     {
       
   305         mVideoIndex = -1; // set video index as invalid.
       
   306         
       
   307         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   308         
       
   309         disconnect(mainWnd->softKeyAction(Hb::SecondarySoftKey),
       
   310                         SIGNAL(triggered()), this, SLOT(back()));
       
   311 
       
   312         disconnect(mainWnd, SIGNAL( orientationChanged( Qt::Orientation ) ),
       
   313              this, SLOT( orientationChange( Qt::Orientation ) ));
       
   314 
       
   315         disconnect(mCollectionWrapper, 
       
   316                        SIGNAL(asyncStatus(int, QVariant&)), 
       
   317                        this, SLOT(handleErrorSlot(int, QVariant&)));
       
   318 
       
   319         mainWnd->removeSoftKeyAction(Hb::SecondarySoftKey, mSecSkAction);
       
   320         
       
   321         mTitleAnim->stopAnimation();
       
   322         mTitleAnim->setText("");
       
   323         
       
   324         mActivated = false;
       
   325 
       
   326         findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON_PLAY)->setIcon(QIcon());
       
   327 
       
   328     	if (mIsService)
       
   329     	{
       
   330     		HbPushButton* attachBtn = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON_ATTACH);
       
   331 			disconnect(attachBtn, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
       
   332 			disconnect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
       
   333     	}
       
   334 
       
   335     }
       
   336 }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // Get view
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 QGraphicsWidget* VideoFileDetailsViewPlugin::getView()
       
   343 {
       
   344     return mView.findWidget(VIDEO_DETAILS_VIEW);
       
   345 }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // Slot: Orientation change
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void VideoFileDetailsViewPlugin::orientationChange( Qt::Orientation orientation )
       
   352 {    
       
   353     if ( orientation == Qt::Vertical ) 
       
   354     {
       
   355       	if (mIsService)
       
   356        	{
       
   357            	mView.load(VIDEO_DETAILS_DOCML, "portrait_fetch");
       
   358        	}
       
   359        	else
       
   360        	{
       
   361        		mView.load(VIDEO_DETAILS_DOCML, "portrait");
       
   362        	}
       
   363     }
       
   364       		   
       
   365     else if ( orientation == Qt::Horizontal ) 
       
   366     {
       
   367        	if (mIsService)
       
   368        	{
       
   369        		mView.load(VIDEO_DETAILS_DOCML, "landscape_fetch");
       
   370        	}
       
   371        	else
       
   372        	{
       
   373        		mView.load(VIDEO_DETAILS_DOCML, "landscape");
       
   374        	}
       
   375     }
       
   376     mTitleAnim->adjustSize();
       
   377     mTitleAnim->startAnimation();
       
   378 }
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 // Slot: back
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 void VideoFileDetailsViewPlugin::back()
       
   385 {
       
   386     if ( mActivated )
       
   387     {
       
   388         emit command( MpxHbVideoCommon::ActivateCollectionView );
       
   389     }
       
   390 }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Slot: shortDetailsReadySlot
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void VideoFileDetailsViewPlugin::shortDetailsReadySlot(int index)
       
   397 {
       
   398     // first clear all details, so that the view doesn't display the old data.
       
   399     int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int);
       
   400     for(int i = 0; i<detailCount; i++) {
       
   401         HbLabel* detail = findWidget<HbLabel>(VIDEO_DETAILS_ITEM + 
       
   402                 QString::number(i+1));
       
   403         detail->setPlainText(QString());
       
   404     }
       
   405 
       
   406     QModelIndex modelIndex = mModel->index(index, 0);
       
   407 
       
   408     mVideoIndex = index;
       
   409     
       
   410     // index assumed to come from source model, so data will be fetched from there
       
   411     QVariant variant = mModel->sourceModel()->data(modelIndex, Qt::DisplayRole);
       
   412 
       
   413     if (variant.isValid() && mTitleAnim) 
       
   414     {
       
   415         mTitleAnim->setText(variant.toStringList().first());      
       
   416     } 
       
   417     startFetchingThumbnail();
       
   418 }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // Slot: fullDetailsReadySlot
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 void VideoFileDetailsViewPlugin::fullDetailsReadySlot(int index)
       
   425 {
       
   426     using namespace VideoCollectionCommon;
       
   427     
       
   428     int detailCount = sizeof(VideoDetailLabelKeys) / sizeof(int);
       
   429 
       
   430     QModelIndex modelIndex = mModel->index(index, 0);
       
   431     int detailAmount = 1;
       
   432     int heightOfVisibleItems = 0;
       
   433     
       
   434     // index received comes from source model so we need to fetch data
       
   435     // directly from there
       
   436     QVariant variant = mModel->sourceModel()->data(modelIndex, KeyMetaData);
       
   437     QMap<QString, QVariant> metadata = variant.toMap();
       
   438     
       
   439     for(int i = 0; i< detailCount; i++) {
       
   440         if (metadata.contains(VideoDetailLabelKeys[i])) {
       
   441             HbLabel* detail = findWidget<HbLabel>(VIDEO_DETAILS_ITEM + 
       
   442                     QString::number(detailAmount));
       
   443             detail->setTextWrapping(Hb::TextWordWrap);
       
   444             detail->setElideMode(Qt::ElideNone);
       
   445             detail->setPlainText(tr(VideoDetailLabels[i]).arg(
       
   446                     metadata[VideoDetailLabelKeys[i]].toString()));
       
   447 
       
   448             detailAmount++;
       
   449             heightOfVisibleItems += detail->preferredHeight(); 
       
   450         }
       
   451     }
       
   452 
       
   453     for(; detailAmount <= VIDEO_DETAILS_DETAIL_AMOUNT; detailAmount++) {
       
   454         HbLabel* detail = findWidget<HbLabel>(VIDEO_DETAILS_ITEM + 
       
   455                 QString::number(detailAmount));
       
   456         detail->hide();
       
   457     }
       
   458 
       
   459     findWidget<HbWidget>(VIDEO_DETAILS_LAYOUT_VIDEO_INFO)->setPreferredHeight(heightOfVisibleItems);
       
   460     findWidget<HbWidget>(VIDEO_DETAILS_LAYOUT_VIDEO_INFO)->adjustSize();
       
   461  
       
   462     int rating = 0;
       
   463     if (metadata.contains(MetaKeyStarRating)) {
       
   464         rating = metadata[MetaKeyStarRating].toInt();
       
   465     }
       
   466     findWidget<HbRatingSlider>(VIDEO_DETAILS_RATING)->setCurrentRating(rating); 
       
   467 
       
   468     // start title animation
       
   469     mTitleAnim->startAnimation();
       
   470 }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // Slot: getFileUri
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 void VideoFileDetailsViewPlugin::getFileUri()
       
   477 {
       
   478     if (mVideoIndex >= 0)
       
   479     {
       
   480 		QVariant variant = mModel->data(mModel->index(mVideoIndex, 0), VideoCollectionCommon::KeyFilePath);
       
   481 		if ( variant.isValid()  )
       
   482 		{
       
   483 			QString itemPath = variant.value<QString>();
       
   484     		emit(fileUri(itemPath));
       
   485 		}
       
   486     }
       
   487 }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // Slot: startPlaybackSlot
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 void VideoFileDetailsViewPlugin::startPlaybackSlot()
       
   494 {
       
   495     if (mVideoIndex >= 0) {
       
   496         mModel->openItem(mModel->index(mVideoIndex, 0));
       
   497     }
       
   498 }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // Slot: sendVideo
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void VideoFileDetailsViewPlugin::sendVideoSlot()
       
   505 {
       
   506     _DebugNotImplementedYet();
       
   507 }
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 // Slot: deleteVideo
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 void VideoFileDetailsViewPlugin::deleteVideoSlot()
       
   514 {
       
   515     if (mVideoIndex > -1)
       
   516         {
       
   517         QModelIndex modelIndex = mModel->index(mVideoIndex, 0);
       
   518         QVariant variant = mModel->data(modelIndex, Qt::DisplayRole);
       
   519 
       
   520         if (variant.isValid()) {
       
   521             QString text = tr("Do you want to delete \"%1\"?").arg(variant.toStringList().first());
       
   522 
       
   523             if (HbMessageBox::question(text)){
       
   524                 deleteItem(modelIndex);
       
   525             }
       
   526         }
       
   527     }
       
   528 }
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // deleteItem
       
   532 // ---------------------------------------------------------------------------
       
   533 //
       
   534 void VideoFileDetailsViewPlugin::deleteItem(QModelIndex index)
       
   535 {
       
   536     QModelIndexList list;
       
   537     list.append(index);
       
   538     mModel->deleteItems(list);
       
   539 }
       
   540 
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // Slot: rowsRemovedSlot
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void VideoFileDetailsViewPlugin::rowsRemovedSlot(const QModelIndex& /*parent*/,
       
   547                                                  int first, int last)
       
   548 {
       
   549     if(mActivated && mVideoIndex > -1 &&
       
   550        (mVideoIndex >= first && mVideoIndex <= last))
       
   551     {
       
   552         // item is withing the group of removed items, deactivate view
       
   553         emit command(MpxHbVideoCommon::ActivateCollectionView);
       
   554     }
       
   555 }
       
   556 
       
   557 // -------------------------------------------------------------------------------------------------
       
   558 // Slot: handleErrorSlot()
       
   559 // error signal received from collectionwrapper
       
   560 // -------------------------------------------------------------------------------------------------
       
   561 //
       
   562 void VideoFileDetailsViewPlugin::handleErrorSlot(int errorCode, QVariant &additional)
       
   563 {
       
   564     QString msg("");
       
   565     if(errorCode == VideoCollectionCommon::statusSingleDeleteFail)
       
   566     {
       
   567         QString format = tr("Unable to delete item %1. It is currently open.");
       
   568         if(additional.isValid())
       
   569         {
       
   570            msg = format.arg(additional.toString());
       
   571         }
       
   572     }
       
   573     if(msg.count() > 0)
       
   574     {
       
   575         // show msg box if there's something to show
       
   576         HbMessageBox::warning(msg);
       
   577     }  
       
   578 }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // Slot: thumbnailReadySlot
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void VideoFileDetailsViewPlugin::thumbnailReadySlot(QPixmap pixmap, 
       
   585         void * clientData, int id, int errorCode)
       
   586 {
       
   587     Q_UNUSED(clientData);
       
   588     Q_UNUSED(id);
       
   589 
       
   590 	HbPushButton* playBtn = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON_PLAY);
       
   591 	QSize size(playBtn->size().toSize());
       
   592 	QImage play(VIDEO_DETAILS_GFX_PLAY);
       
   593 
       
   594 	if (!errorCode) {
       
   595 
       
   596 		QImage sourceImage = pixmap.toImage();
       
   597 
       
   598 		if ((sourceImage.size().height() > size.height()) || (sourceImage.size().width() > size.width()))
       
   599 		{
       
   600 			// Smooth scaling is very expensive (size^2). Therefore we reduce the size
       
   601 			// to 2x of the destination size and using fast transformation before doing final smooth scaling.
       
   602 			if (sourceImage.size().width() > (4*size.width()) || sourceImage.size().height() > (4*size.height()))
       
   603 			{
       
   604 				QSize intermediate_size = QSize( size.width() * 2, size.height() * 2 );
       
   605 				sourceImage = sourceImage.scaled(intermediate_size, Qt::KeepAspectRatio, Qt::FastTransformation );
       
   606 			}
       
   607 			sourceImage = sourceImage.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
       
   608 		}
       
   609 
       
   610 		QImage resultImage = QImage(sourceImage.size(), QImage::Format_ARGB32_Premultiplied);
       
   611 		QPainter painter(&resultImage);
       
   612 		painter.setCompositionMode(QPainter::CompositionMode_Source);
       
   613 		painter.fillRect(resultImage.rect(), Qt::transparent);
       
   614 		painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
       
   615 		painter.drawImage( (int)(sourceImage.width() - play.width())/2, 
       
   616 				           (int)(sourceImage.height() - play.height())/2, 
       
   617 				            play );
       
   618 		painter.setCompositionMode(QPainter::CompositionMode_Screen);
       
   619 		painter.drawImage(0, 0, sourceImage);
       
   620 		painter.end();
       
   621 
       
   622 		HbIcon compsedIcon(QPixmap::fromImage(resultImage));
       
   623 	    playBtn->setIcon(compsedIcon);
       
   624 	}
       
   625     else {
       
   626 		playBtn->setIcon(HbIcon(VIDEO_DETAILS_GFX_DEFAULT));
       
   627 	}
       
   628 }
       
   629 
       
   630 // ---------------------------------------------------------------------------
       
   631 // startFetchingThumbnail
       
   632 // ---------------------------------------------------------------------------
       
   633 //
       
   634 void VideoFileDetailsViewPlugin::startFetchingThumbnail()
       
   635 {
       
   636     int tnId = -1;
       
   637     
       
   638     if(mModel && mThumbnailManager) {
       
   639         QVariant variant = mModel->data(mModel->index(mVideoIndex, 0), VideoCollectionCommon::KeyFilePath);
       
   640         if(variant.isValid()) {
       
   641             mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
   642             tnId = mThumbnailManager->getThumbnail(variant.toString(), 0, 5000);
       
   643         }
       
   644     } else {
       
   645         qWarning() << "Tried to start fetching thumbnail when either mModel or mThumbnailManager is NULL!";
       
   646     }
       
   647     
       
   648     if(tnId == -1) {
       
   649         // TODO set default thumbnail here
       
   650     }
       
   651 }
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // findWidget
       
   655 // ---------------------------------------------------------------------------
       
   656 //
       
   657 template<class T>
       
   658 T* VideoFileDetailsViewPlugin::findWidget(QString name)
       
   659 {
       
   660     return qobject_cast<T *>(mView.findWidget(name));
       
   661 }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // findObject
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 template<class T>
       
   668 T* VideoFileDetailsViewPlugin::findObject(QString name)
       
   669 {
       
   670     return qobject_cast<T *>(mView.findObject(name));
       
   671 }
       
   672 
       
   673 XQ_EXPORT_PLUGIN2( videofiledetailsview, VideoFileDetailsViewPlugin );
       
   674 
       
   675 // end of file