videocollection/videofiledetailsview/src/videofiledetailsviewplugin.cpp
changeset 15 cf5481c2bc0b
child 17 69946d1824c4
equal deleted inserted replaced
2:dec420019252 15:cf5481c2bc0b
       
     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 <qcoreapplication.h>
       
    20 #include <xqserviceutil.h>
       
    21 #include <xqplugin.h>
       
    22 #include <hbview.h>
       
    23 #include <hbinstance.h>
       
    24 #include <hbstackedwidget.h>
       
    25 #include <hbmarqueeitem.h>
       
    26 #include <hbpushbutton.h>
       
    27 #include <hbaction.h>
       
    28 #include <qabstractitemmodel.h>
       
    29 #include <qdebug.h>
       
    30 #include <hbmessagebox.h>
       
    31 #include <hblistwidget.h>
       
    32 #include <hblistwidgetitem.h>
       
    33 #include <hblistviewitem.h>
       
    34 #include <cmath>
       
    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 #include "videodetailslabel.h"
       
    44 
       
    45 const char* const VIDEO_DETAILS_DOCML = ":/xml/videofiledetails.docml";
       
    46 const char* const VIDEO_DETAILS_PORTRAIT = "portrait";
       
    47 const char* const VIDEO_DETAILS_LANDSCAPE = "landscape";
       
    48 const char* const VIDEO_DETAILS_GFX_DEFAULT = ":/gfx/pri_large_video.svg";
       
    49 const char* const VIDEO_DETAILS_VIEW = "videofiledetailsview";
       
    50 const char* const VIDEO_DETAILS_TITLE = "mLblTitle";
       
    51 const char* const VIDEO_DETAILS_THUMBNAIL = "mDetailsLabel";
       
    52 const char* const VIDEO_DETAILS_BUTTON = "mButton";
       
    53 const char* const VIDEO_DETAILS_MENUACTION_DELETE = "mOptionsDelete";
       
    54 const char* const VIDEO_DETAILS_LISTWIDGET ="mDetailsList";
       
    55 
       
    56 // Just for testing, remove this
       
    57 void _DebugNotImplementedYet()
       
    58 {
       
    59     HbMessageBox::information(QObject::tr("Not implemented yet"));
       
    60 }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // Constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 VideoFileDetailsViewPlugin::VideoFileDetailsViewPlugin()
       
    67     : mModel(0),
       
    68       mVideoServices(0),
       
    69       mActivated(false),
       
    70       mIsService(false),
       
    71       mVideoId(TMPXItemId::InvalidId()),
       
    72       mDeletedIndex(-1),
       
    73       mPreviousOrietation(Qt::Vertical),
       
    74       mNavKeyBackAction(0),
       
    75       mTitleAnim(0),
       
    76       mThumbLabel(0),
       
    77       mThumbnailManager(0),
       
    78       mCollectionWrapper(VideoCollectionWrapper::instance())
       
    79 {
       
    80 
       
    81 }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Destructor
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 VideoFileDetailsViewPlugin::~VideoFileDetailsViewPlugin()
       
    88 {
       
    89 	destroyView();
       
    90 }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Create view
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void VideoFileDetailsViewPlugin::createView()
       
    97 {
       
    98 	mLoader.reset();
       
    99 
       
   100 	mActivated = false;
       
   101 
       
   102 	bool ok = false;
       
   103 	
       
   104 	//Load the details view docml first
       
   105 	mLoader.load(VIDEO_DETAILS_DOCML, &ok);
       
   106 	
       
   107 	if(!ok)
       
   108 	{
       
   109 		return;
       
   110 	}
       
   111 
       
   112 	//Load portrait section by default as only vertical orientation is currently supported by videoplayer
       
   113 	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_PORTRAIT, &ok);
       
   114 	
       
   115 	if(!ok)
       
   116 	{
       
   117 		return;
       
   118 	}
       
   119 
       
   120 	mModel = mCollectionWrapper.getModel(VideoCollectionWrapper::EAllVideos);
       
   121 
       
   122 	if (!mModel)
       
   123 		{
       
   124 		qDebug() << "VideoFileDetailsViewPlugin::createView(): Unable to open collection wrapper. Cannot connect slots, aborting...";
       
   125 		// TODO need to throw exception instead?
       
   126 		return;
       
   127 		}
       
   128 
       
   129 	mIsService = XQServiceUtil::isService();
       
   130 
       
   131 	// no deallocation needed for this since
       
   132 	// stackedwidget takes ownership
       
   133 	mTitleAnim = new HbMarqueeItem;
       
   134 	HbFontSpec spec = mTitleAnim->fontSpec();
       
   135     spec.setRole( HbFontSpec::Primary );
       
   136     mTitleAnim->setFontSpec( spec );
       
   137     mTitleAnim->setLoopCount(-1);
       
   138 
       
   139 	connect(mModel->sourceModel(),
       
   140 			SIGNAL(shortDetailsReady(TMPXItemId)),
       
   141 			this, SLOT(shortDetailsReadySlot(TMPXItemId)));
       
   142 
       
   143 	connect(mModel->sourceModel(),
       
   144 			SIGNAL(fullVideoDetailsReady(TMPXItemId)),
       
   145 			this, SLOT(fullDetailsReadySlot(TMPXItemId)));
       
   146 
       
   147 	connect(mModel,
       
   148 			SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
       
   149 			this, SLOT(rowsRemovedSlot(const QModelIndex&, int, int)));
       
   150 
       
   151 	HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
       
   152 
       
   153 	// no deallocation needed for this since
       
   154 	// stackedwidget takes ownership
       
   155 	mThumbLabel = new VideoDetailsLabel;
       
   156 
       
   157 	mThumbLabel->setAlignment(Qt::AlignCenter);
       
   158 
       
   159 	connect(mThumbLabel, SIGNAL(clicked(bool)), this, SLOT(startPlaybackSlot()));
       
   160 
       
   161 	thumbWidget->addWidget(mThumbLabel);
       
   162 
       
   163 	HbStackedWidget* title = findObject<HbStackedWidget>(VIDEO_DETAILS_TITLE);
       
   164 	title->addWidget(mTitleAnim);
       
   165 
       
   166 	HbAction* deleteAction = findObject<HbAction>(VIDEO_DETAILS_MENUACTION_DELETE);
       
   167 
       
   168 	if (mIsService)
       
   169 	{
       
   170 		deleteAction->setVisible(false);
       
   171 	}
       
   172 	else
       
   173 	{
       
   174 		connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteVideoSlot()));
       
   175 	}
       
   176 
       
   177 	// Create navigation keys.
       
   178 	mNavKeyBackAction = new HbAction(Hb::BackNaviAction);
       
   179 
       
   180 	if (!mThumbnailManager)
       
   181 	{
       
   182 		mThumbnailManager = new ThumbnailManager();
       
   183 	}
       
   184 
       
   185 	connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap,void*,int,int)),
       
   186 			this, SLOT(thumbnailReadySlot(QPixmap,void*,int,int)));
       
   187 }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Destroy view
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void VideoFileDetailsViewPlugin::destroyView()
       
   194 {
       
   195     if (mActivated)
       
   196     {
       
   197         deactivateView();
       
   198     }
       
   199 
       
   200     if(mVideoServices)
       
   201     {
       
   202     	mVideoServices->decreaseReferenceCount();
       
   203     	mVideoServices = 0;
       
   204     }
       
   205 
       
   206     delete mNavKeyBackAction; mNavKeyBackAction = 0;
       
   207     delete mThumbnailManager; mThumbnailManager = 0;
       
   208     disconnect();
       
   209     mLoader.reset();
       
   210 }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Activate view
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void VideoFileDetailsViewPlugin::activateView()
       
   217 {
       
   218 	if (!mActivated)
       
   219     {
       
   220         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   221 
       
   222         HbView *currentView = mainWnd->currentView();
       
   223         if(currentView && mNavKeyBackAction)
       
   224         {
       
   225         	if (connect(mNavKeyBackAction, SIGNAL(triggered()), this, SLOT(back())))
       
   226         	{
       
   227         		currentView->setNavigationAction(mNavKeyBackAction);
       
   228         	}
       
   229         	else
       
   230         	{
       
   231         		return;
       
   232         	}
       
   233         }
       
   234 
       
   235         mainWnd->setOrientation(Qt::Vertical, false);
       
   236 
       
   237         // following if is for the future implementations where we should support
       
   238         // also landscape configuration.
       
   239         Qt::Orientation orientation = mainWnd->orientation();
       
   240         if ( (orientation == Qt::Vertical) && (orientation != mPreviousOrietation) )
       
   241         {
       
   242     		mPreviousOrietation = orientation;
       
   243         	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_PORTRAIT);
       
   244         }
       
   245         else if ( (orientation == Qt::Horizontal) && (orientation != mPreviousOrietation) )
       
   246         {
       
   247     		mPreviousOrietation = orientation;
       
   248     		mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_LANDSCAPE);
       
   249         }
       
   250 
       
   251     	if (mIsService && !mVideoServices)
       
   252     	{
       
   253     		mVideoServices = VideoServices::instance();
       
   254 
       
   255 			if (!mVideoServices)
       
   256 			{
       
   257 				return;
       
   258 			}
       
   259     	}
       
   260 
       
   261 		HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON);
       
   262 
       
   263 		if (mIsService && mVideoServices)
       
   264 		{
       
   265 			button->setText(tr("Attach")); //localisation
       
   266 
       
   267 			connect(button, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
       
   268 			connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
       
   269 
       
   270             HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   271 
       
   272             mainWnd->currentView()->setTitle(mVideoServices->contextTitle());
       
   273 		}
       
   274     	else if(!mIsService)
       
   275     	{
       
   276 			connect(button, SIGNAL(clicked(bool)), this, SLOT(sendVideoSlot()));
       
   277 			button->setText(hbTrId("txt_videos_opt_share"));
       
   278     	}
       
   279 
       
   280         connect(mainWnd,
       
   281                 SIGNAL(orientationChanged(Qt::Orientation)),
       
   282                 this, SLOT(orientationChange(Qt::Orientation)));
       
   283 
       
   284         connect(&mCollectionWrapper,
       
   285                SIGNAL(asyncStatus(int, QVariant&)),
       
   286                this, SLOT(handleErrorSlot(int, QVariant&)));
       
   287 
       
   288         // setup title size in order for animation to be enabled if needed
       
   289         mTitleAnim->setMinimumWidth(hbInstance->allMainWindows().value(0)->width()-50);
       
   290         mTitleAnim->adjustSize();
       
   291 
       
   292         mActivated = true;
       
   293     }
       
   294 }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // Deactivate view
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 void VideoFileDetailsViewPlugin::deactivateView()
       
   301 {
       
   302     if ( mActivated )
       
   303     {
       
   304         mVideoId = TMPXItemId::InvalidId();
       
   305 
       
   306         mDeletedIndex = -1;  // set index as invalid.
       
   307 
       
   308         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
       
   309 
       
   310         mainWnd->unsetOrientation();
       
   311 
       
   312         HbView *currentView = mainWnd->currentView();
       
   313         if(currentView)
       
   314         {
       
   315        		currentView->setNavigationAction(0);
       
   316         }
       
   317 
       
   318         disconnect(mNavKeyBackAction, SIGNAL(triggered()), this, SLOT(back()));
       
   319 
       
   320         disconnect(mainWnd, SIGNAL( orientationChanged( Qt::Orientation ) ),
       
   321              this, SLOT( orientationChange( Qt::Orientation ) ));
       
   322 
       
   323         disconnect(&mCollectionWrapper,
       
   324                        SIGNAL(asyncStatus(int, QVariant&)),
       
   325                        this, SLOT(handleErrorSlot(int, QVariant&)));
       
   326 
       
   327         mTitleAnim->stopAnimation();
       
   328         mTitleAnim->setText("");
       
   329 
       
   330         mActivated = false;
       
   331 
       
   332     	mThumbLabel->setIcon(HbIcon());
       
   333 
       
   334    		HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON);
       
   335 
       
   336     	if (mIsService)
       
   337     	{
       
   338 			disconnect(button, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
       
   339 			disconnect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
       
   340     	}
       
   341 		else
       
   342 		{
       
   343 			disconnect(button, SIGNAL(clicked(bool)), this, SLOT(sendVideoSlot()));
       
   344 		}
       
   345 
       
   346     }
       
   347 }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // Get view
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 QGraphicsWidget* VideoFileDetailsViewPlugin::getView()
       
   354 {
       
   355     return mLoader.findWidget(VIDEO_DETAILS_VIEW);
       
   356 }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // Slot: Orientation change
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void VideoFileDetailsViewPlugin::orientationChange( Qt::Orientation orientation )
       
   363 {
       
   364     if ( orientation == Qt::Vertical )
       
   365     {
       
   366     	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_PORTRAIT);
       
   367     }
       
   368 
       
   369     else if ( orientation == Qt::Horizontal )
       
   370     {
       
   371        	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_LANDSCAPE);
       
   372     }
       
   373     mTitleAnim->adjustSize();
       
   374     mTitleAnim->startAnimation();
       
   375 }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // Slot: back
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 void VideoFileDetailsViewPlugin::back()
       
   382 {
       
   383     if ( mActivated )
       
   384     {
       
   385         emit command( MpxHbVideoCommon::ActivateCollectionView );
       
   386     }
       
   387 }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // Slot: shortDetailsReadySlot
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void VideoFileDetailsViewPlugin::shortDetailsReadySlot(TMPXItemId id)
       
   394 {
       
   395     // first clear all details, so that the view doesn't display the old data.
       
   396     findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET)->clear();
       
   397 
       
   398     QModelIndex modelIndex = mModel->indexOfId(id);
       
   399 
       
   400     mVideoId = id;
       
   401 
       
   402     QVariant variant = mModel->data(modelIndex, Qt::DisplayRole);
       
   403 
       
   404     if (variant.isValid() && mTitleAnim)
       
   405     {
       
   406         mTitleAnim->setText(variant.toStringList().first());
       
   407     }
       
   408     startFetchingThumbnail();
       
   409 }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // Slot: fullDetailsReadySlot
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void VideoFileDetailsViewPlugin::fullDetailsReadySlot(TMPXItemId id)
       
   416 {
       
   417     using namespace VideoCollectionCommon;
       
   418 
       
   419     int detailCount = sizeof(VideoDetailLabelKeys) / sizeof(int);
       
   420 
       
   421     QModelIndex modelIndex = mModel->indexOfId(id);
       
   422 
       
   423     QVariant variant = mModel->data(modelIndex, KeyMetaData);
       
   424 
       
   425     QMap<QString, QVariant> metadata = variant.toMap();
       
   426 
       
   427     HbListWidget* list = findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET);
       
   428 
       
   429     if(list->count())
       
   430     {
       
   431         list->clear();
       
   432     }
       
   433 
       
   434     //TODO: define maximum line count once >3 supported
       
   435     HbListViewItem *prototype = list->listItemPrototype();
       
   436     prototype->setSecondaryTextRowCount(1, 3);
       
   437 
       
   438     for(int i = 0; i< detailCount; i++) {
       
   439         if (metadata.contains(VideoDetailLabelKeys[i]))
       
   440         {
       
   441             HbListWidgetItem* listWidgetItem = new HbListWidgetItem();
       
   442             listWidgetItem->setEnabled(false);
       
   443 
       
   444             listWidgetItem->setText( hbTrId(VideoDetailLabels[i]) );
       
   445             listWidgetItem->setSecondaryText( metadata[VideoDetailLabelKeys[i]].toString() );
       
   446             list->addItem( listWidgetItem );
       
   447         }
       
   448     }
       
   449 
       
   450     // start title animation
       
   451     mTitleAnim->startAnimation();
       
   452 }
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 // Slot: getFileUri
       
   456 // ---------------------------------------------------------------------------
       
   457 //
       
   458 void VideoFileDetailsViewPlugin::getFileUri()
       
   459 {
       
   460 	if (mVideoId != TMPXItemId::InvalidId())
       
   461     {
       
   462         QModelIndex modelIndex = mModel->indexOfId(mVideoId);
       
   463 		QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
       
   464 		if ( variant.isValid()  )
       
   465 		{
       
   466 			QString itemPath = variant.value<QString>();
       
   467     		emit(fileUri(itemPath));
       
   468 		}
       
   469     }
       
   470 }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // Slot: startPlaybackSlot
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 void VideoFileDetailsViewPlugin::startPlaybackSlot()
       
   477 {
       
   478 	if (mVideoId != TMPXItemId::InvalidId())
       
   479 	{
       
   480     	mModel->openItem(mVideoId);
       
   481 	}
       
   482 }
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // Slot: sendVideo
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 void VideoFileDetailsViewPlugin::sendVideoSlot()
       
   489 {
       
   490     _DebugNotImplementedYet();
       
   491 }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // Slot: deleteVideo
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void VideoFileDetailsViewPlugin::deleteVideoSlot()
       
   498 {
       
   499 	if (mVideoId != TMPXItemId::InvalidId())
       
   500         {
       
   501 		QModelIndex modelIndex = mModel->indexOfId(mVideoId);
       
   502 		QVariant variant = mModel->data(modelIndex, Qt::DisplayRole);
       
   503 
       
   504         if (variant.isValid())
       
   505         {
       
   506             QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
       
   507 			   variant.toStringList().first());
       
   508 
       
   509             if (HbMessageBox::question(text))
       
   510             {
       
   511                 deleteItem(modelIndex);
       
   512             }
       
   513         }
       
   514     }
       
   515 }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // deleteItem
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void VideoFileDetailsViewPlugin::deleteItem(QModelIndex index)
       
   522 {
       
   523     mDeletedIndex = index.row();
       
   524 
       
   525     QModelIndexList list;
       
   526     list.append(index);
       
   527     mModel->deleteItems(list);
       
   528 }
       
   529 
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // Slot: rowsRemovedSlot
       
   533 // ---------------------------------------------------------------------------
       
   534 //
       
   535 void VideoFileDetailsViewPlugin::rowsRemovedSlot(const QModelIndex& parent,
       
   536                                                  int first, int last)
       
   537 {
       
   538 	Q_UNUSED(parent);
       
   539 
       
   540 	if(mActivated && mDeletedIndex > -1 &&
       
   541        (mDeletedIndex >= first && mDeletedIndex <= last))
       
   542     {
       
   543         // item is withing the group of removed items, deactivate view
       
   544         emit command(MpxHbVideoCommon::ActivateCollectionView);
       
   545     }
       
   546 }
       
   547 
       
   548 // -------------------------------------------------------------------------------------------------
       
   549 // Slot: handleErrorSlot()
       
   550 // error signal received from collectionwrapper
       
   551 // -------------------------------------------------------------------------------------------------
       
   552 //
       
   553 void VideoFileDetailsViewPlugin::handleErrorSlot(int errorCode, QVariant &additional)
       
   554 {
       
   555     QString msg("");
       
   556     if(errorCode == VideoCollectionCommon::statusSingleDeleteFail)
       
   557     {
       
   558         QString format = hbTrId("txt_videos_info_unable_to_delete_1_it_is_current"); 
       
   559         if(additional.isValid())
       
   560         {
       
   561            msg = format.arg(additional.toString());
       
   562         }
       
   563     }
       
   564     if(msg.count() > 0)
       
   565     {
       
   566         // show msg box if there's something to show
       
   567         HbMessageBox::warning(msg);
       
   568     }
       
   569 }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // Slot: thumbnailReadySlot
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 void VideoFileDetailsViewPlugin::thumbnailReadySlot(QPixmap pixmap,
       
   576         void * clientData, int id, int errorCode)
       
   577 {
       
   578     Q_UNUSED(clientData);
       
   579     Q_UNUSED(id);
       
   580 
       
   581 	QSize size(mThumbLabel->size().toSize());
       
   582 
       
   583 	if (!errorCode)
       
   584 	{
       
   585 		QImage sourceImage = pixmap.toImage();
       
   586 
       
   587 		if ((sourceImage.size().height() != size.height()) || (sourceImage.size().width() != size.width()))
       
   588 		{
       
   589 			// Smooth scaling is very expensive (size^2). Therefore we reduce the size
       
   590 			// to 2x of the destination size and using fast transformation before doing final smooth scaling.
       
   591 			if (sourceImage.size().width() > (4*size.width()) || sourceImage.size().height() > (4*size.height()))
       
   592 			{
       
   593 				QSize intermediate_size = QSize( size.width() * 2, size.height() * 2 );
       
   594 				sourceImage = sourceImage.scaled(intermediate_size, Qt::KeepAspectRatioByExpanding, Qt::FastTransformation );
       
   595 			}
       
   596 			sourceImage = sourceImage.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
       
   597 		}
       
   598 
       
   599 		int difference(0);
       
   600 		QRect rect = mThumbLabel->rect().toRect();
       
   601 
       
   602 		if(sourceImage.width() > size.width())
       
   603 		{
       
   604 			difference = sourceImage.width() - size.width();
       
   605 			difference = (difference/2)+1;
       
   606 			rect.moveLeft(rect.left()+difference);
       
   607 		}
       
   608 		else if(sourceImage.height() > size.height())
       
   609 		{
       
   610 			difference = sourceImage.height() - size.height();
       
   611 			difference = (difference/2)+1;
       
   612 			rect.moveBottom(rect.bottom()+difference);
       
   613 		}
       
   614 
       
   615 		sourceImage = sourceImage.copy(rect);
       
   616 		QImage resultImage = QImage(sourceImage.size(), QImage::Format_ARGB32_Premultiplied);
       
   617 
       
   618 		QPainter painter(&resultImage);
       
   619         painter.setCompositionMode(QPainter::CompositionMode_Source);
       
   620 		painter.fillRect(resultImage.rect(), Qt::transparent);
       
   621 		painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
       
   622 		painter.drawPixmap( (int)(sourceImage.width() - playIcon().width())/2,
       
   623 				           (int)(sourceImage.height() - playIcon().height())/2,
       
   624 				            playIcon() );
       
   625 		painter.setCompositionMode(QPainter::CompositionMode_Screen);
       
   626         painter.drawImage(0, 0, sourceImage);
       
   627 		painter.end();
       
   628 
       
   629 		HbIcon compsedIcon(QPixmap::fromImage(resultImage));
       
   630 	    mThumbLabel->setIcon(compsedIcon);
       
   631 	}
       
   632     else
       
   633     {
       
   634 		mThumbLabel->setIcon(HbIcon(VIDEO_DETAILS_GFX_DEFAULT));
       
   635 	}
       
   636 }
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 // startFetchingThumbnail
       
   640 // ---------------------------------------------------------------------------
       
   641 //
       
   642 void VideoFileDetailsViewPlugin::startFetchingThumbnail()
       
   643 {
       
   644     int tnId = -1;
       
   645 
       
   646     if(mModel && mThumbnailManager)
       
   647     {
       
   648     	QModelIndex modelIndex = mModel->indexOfId(mVideoId);
       
   649 		QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
       
   650         if(variant.isValid())
       
   651         {
       
   652             mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
   653             tnId = mThumbnailManager->getThumbnail(variant.toString(), 0, 5000);
       
   654         }
       
   655     }
       
   656     else
       
   657     {
       
   658         qWarning() << "Tried to start fetching thumbnail when either mModel or mThumbnailManager is NULL!";
       
   659     }
       
   660 
       
   661     if(tnId == -1)
       
   662     {
       
   663     	mThumbLabel->setIcon(HbIcon(VIDEO_DETAILS_GFX_DEFAULT));
       
   664     }
       
   665 }
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // playIcon
       
   669 // ---------------------------------------------------------------------------
       
   670 //
       
   671 const QPixmap &VideoFileDetailsViewPlugin::playIcon()
       
   672 {
       
   673     // Check if we have already the icon.
       
   674     if(!mPlayIcon.isNull())
       
   675     {
       
   676         return mPlayIcon;
       
   677     }
       
   678     
       
   679     // Compose the icon.
       
   680     HbIcon play =        HbIcon("qtg_mono_play");
       
   681     HbIcon topLeft =     HbIcon("qtg_fr_popup_trans_tl");
       
   682     HbIcon top =         HbIcon("qtg_fr_popup_trans_t");
       
   683     HbIcon topRight =    HbIcon("qtg_fr_popup_trans_tr");
       
   684     HbIcon left =        HbIcon("qtg_fr_popup_trans_l");
       
   685     HbIcon center =      HbIcon("qtg_fr_popup_trans_c");
       
   686     HbIcon right =       HbIcon("qtg_fr_popup_trans_r");
       
   687     HbIcon bottomLeft =  HbIcon("qtg_fr_popup_trans_bl");
       
   688     HbIcon bottom =      HbIcon("qtg_fr_popup_trans_b");
       
   689     HbIcon bottomRight = HbIcon("qtg_fr_popup_trans_br");
       
   690 
       
   691     int width = topLeft.width() + top.width() + topRight.width();
       
   692     int height = topLeft.height() + center.height() + bottomLeft.height();
       
   693     
       
   694     mPlayIcon = QPixmap(width, height);
       
   695     
       
   696     QPainter painter(&mPlayIcon);
       
   697     painter.fillRect(mPlayIcon.rect(), Qt::white);
       
   698     
       
   699     painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
       
   700     
       
   701     int x = 0;
       
   702     int y = 0;
       
   703 
       
   704     // Draw top
       
   705     painter.drawPixmap(QPoint(x, y), topLeft.pixmap());
       
   706     x += left.width();
       
   707     
       
   708     painter.drawPixmap(QPoint(x, y), top.pixmap());
       
   709     x += top.width();
       
   710 
       
   711     painter.drawPixmap(QPoint(x, y), topRight.pixmap());
       
   712     y += top.height();
       
   713     
       
   714     // Draw center
       
   715     x = 0;
       
   716     painter.drawPixmap(QPoint(x, y), left.pixmap());
       
   717     x += left.width();
       
   718     
       
   719     painter.drawPixmap(QPoint(x, y), center.pixmap());
       
   720     x += center.width();
       
   721 
       
   722     painter.drawPixmap(QPoint(x, y), right.pixmap());
       
   723     y += center.height();
       
   724     
       
   725     // Draw bottom
       
   726     x = 0;
       
   727     painter.drawPixmap(QPoint(x, y), bottomLeft.pixmap());
       
   728     x += left.width();
       
   729     
       
   730     painter.drawPixmap(QPoint(x, y), bottom.pixmap());
       
   731     x += top.width();
       
   732     
       
   733     painter.drawPixmap(QPoint(x, y), bottomRight.pixmap());
       
   734     
       
   735     // Draw play icon
       
   736     play.setSize(mPlayIcon.size());
       
   737     play.setColor(Qt::white);
       
   738     painter.drawPixmap(mPlayIcon.rect(), play.pixmap());
       
   739     painter.end();
       
   740     
       
   741     return mPlayIcon;
       
   742 }
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // findWidget
       
   746 // ---------------------------------------------------------------------------
       
   747 //
       
   748 template<class T>
       
   749 T* VideoFileDetailsViewPlugin::findWidget(QString name)
       
   750 {
       
   751     return qobject_cast<T *>(mLoader.findWidget(name));
       
   752 }
       
   753 
       
   754 // ---------------------------------------------------------------------------
       
   755 // findObject
       
   756 // ---------------------------------------------------------------------------
       
   757 //
       
   758 template<class T>
       
   759 T* VideoFileDetailsViewPlugin::findObject(QString name)
       
   760 {
       
   761     return qobject_cast<T *>(mLoader.findObject(name));
       
   762 }
       
   763 
       
   764 XQ_EXPORT_PLUGIN2( videofiledetailsview, VideoFileDetailsViewPlugin );
       
   765 
       
   766 // end of file