videocollection/videofiledetailsview/src/videofiledetailsviewplugin.cpp
changeset 44 518105d52e45
parent 41 229f037ce963
child 50 21fe8338c6bf
equal deleted inserted replaced
42:17f382c040b1 44:518105d52e45
    13 *
    13 *
    14 * Description:   VideoCollectionViewPlugin class implementation
    14 * Description:   VideoCollectionViewPlugin class implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 76.1.1 %
    18 // Version : %version: 76.1.5 %
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <qcoreapplication.h>
    21 #include <qcoreapplication.h>
    22 #include <xqserviceutil.h>
    22 #include <xqserviceutil.h>
    23 #include <xqplugin.h>
    23 #include <xqplugin.h>
    30 #include <qabstractitemmodel.h>
    30 #include <qabstractitemmodel.h>
    31 #include <hbmessagebox.h>
    31 #include <hbmessagebox.h>
    32 #include <hblistwidget.h>
    32 #include <hblistwidget.h>
    33 #include <hblistwidgetitem.h>
    33 #include <hblistwidgetitem.h>
    34 #include <hblistviewitem.h>
    34 #include <hblistviewitem.h>
       
    35 #include <hbparameterlengthlimiter.h>
    35 #include <cmath>
    36 #include <cmath>
    36 #include <thumbnailmanager_qt.h>
    37 #include <thumbnailmanager_qt.h>
    37 #include <shareui.h>
    38 #include <shareui.h>
    38 
    39 
    39 #include "videocollectionclient.h"
    40 #include "videocollectionclient.h"
   111 	mLoader.reset();
   112 	mLoader.reset();
   112 
   113 
   113 	mActivated = false;
   114 	mActivated = false;
   114 
   115 
   115 	bool ok = false;
   116 	bool ok = false;
   116 	
   117 
   117 	//Load the details view docml first
   118 	//Load the details view docml first
   118 	mLoader.load(VIDEO_DETAILS_DOCML, &ok);
   119 	mLoader.load(VIDEO_DETAILS_DOCML, &ok);
   119 	
   120 
   120 	if(!ok)
   121 	if(!ok)
   121 	{
   122 	{
   122 	    ERROR(-1, "VideoFileDetailsViewPlugin::createView() failed to load docml.");
   123 	    ERROR(-1, "VideoFileDetailsViewPlugin::createView() failed to load docml.");
   123 		return;
   124 		return;
   124 	}
   125 	}
   125 
   126 
   126 	//Load portrait section by default as only vertical orientation is currently supported by videoplayer
   127 	//Load portrait section by default as only vertical orientation is currently supported by videoplayer
   127 	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_PORTRAIT, &ok);
   128 	mLoader.load(VIDEO_DETAILS_DOCML, VIDEO_DETAILS_PORTRAIT, &ok);
   128 	
   129 
   129 	if(!ok)
   130 	if(!ok)
   130 	{
   131 	{
   131 	    ERROR(-1, "VideoFileDetailsViewPlugin::createView() failed to load portrait view.");
   132 	    ERROR(-1, "VideoFileDetailsViewPlugin::createView() failed to load portrait view.");
   132 		return;
   133 		return;
   133 	}
   134 	}
   174 	// no deallocation needed for this since
   175 	// no deallocation needed for this since
   175 	// stackedwidget takes ownership
   176 	// stackedwidget takes ownership
   176 	mThumbLabel = new VideoDetailsLabel;
   177 	mThumbLabel = new VideoDetailsLabel;
   177 	mThumbLabel->setAlignment(Qt::AlignCenter);
   178 	mThumbLabel->setAlignment(Qt::AlignCenter);
   178 	mThumbLabel->setObjectName(VIDEO_DETAILS_OBJECT_NAME_THUMBLABEL);
   179 	mThumbLabel->setObjectName(VIDEO_DETAILS_OBJECT_NAME_THUMBLABEL);
   179 	
   180 
   180 	connect(mThumbLabel, SIGNAL(clicked(bool)), this, SLOT(startPlaybackSlot()));
   181 	connect(mThumbLabel, SIGNAL(clicked(bool)), this, SLOT(startPlaybackSlot()));
   181 
   182 
   182 	thumbWidget->addWidget(mThumbLabel);
   183 	thumbWidget->addWidget(mThumbLabel);
   183 
   184 
   184 	// Load details title.
   185 	// Load details title.
   209 	}
   210 	}
   210 
   211 
   211 	// Create navigation keys.
   212 	// Create navigation keys.
   212 	mNavKeyBackAction = new HbAction(Hb::BackNaviAction);
   213 	mNavKeyBackAction = new HbAction(Hb::BackNaviAction);
   213 	mNavKeyBackAction->setObjectName(VIDEO_DETAILS_OBJECT_NAME_NAVKEY_BACK);
   214 	mNavKeyBackAction->setObjectName(VIDEO_DETAILS_OBJECT_NAME_NAVKEY_BACK);
   214 	
   215 
   215 	if (!mThumbnailManager)
   216 	if (!mThumbnailManager)
   216 	{
   217 	{
   217 		mThumbnailManager = new ThumbnailManager();
   218 		mThumbnailManager = new ThumbnailManager();
   218 	}
   219 	}
   219 
   220 
   220 	connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap,void*,int,int)),
   221 	connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap,void*,int,int)),
   221 			this, SLOT(thumbnailReadySlot(QPixmap,void*,int,int)));
   222 			this, SLOT(thumbnailReadySlot(QPixmap,void*,int,int)));
   222 	
   223 
   223     HbListWidget* list = findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET);
   224     HbListWidget* list = findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET);
   224     if(!list)
   225     if(!list)
   225     {
   226     {
   226         ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details list widget.");
   227         ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details list widget.");
   227         return;
   228         return;
   228     }
   229     }
   229     
   230 
   230     list->setEnabledAnimations(HbAbstractItemView::None);
   231     list->setEnabledAnimations(HbAbstractItemView::None);
   231 }
   232 }
   232 
   233 
   233 // ---------------------------------------------------------------------------
   234 // ---------------------------------------------------------------------------
   234 // Destroy view
   235 // Destroy view
   248     	mVideoServices = 0;
   249     	mVideoServices = 0;
   249     }
   250     }
   250 
   251 
   251     delete mNavKeyBackAction;
   252     delete mNavKeyBackAction;
   252     mNavKeyBackAction = 0;
   253     mNavKeyBackAction = 0;
   253     
   254 
   254     delete mThumbnailManager;
   255     delete mThumbnailManager;
   255     mThumbnailManager = 0;
   256     mThumbnailManager = 0;
   256     
   257 
   257     disconnect();
   258     disconnect();
   258     mLoader.reset();
   259     mLoader.reset();
   259 }
   260 }
   260 
   261 
   261 // ---------------------------------------------------------------------------
   262 // ---------------------------------------------------------------------------
   312 
   313 
   313 		VideoServices::TVideoService service = VideoServices::ENoService;
   314 		VideoServices::TVideoService service = VideoServices::ENoService;
   314 		if (mIsService && mVideoServices)
   315 		if (mIsService && mVideoServices)
   315 		{
   316 		{
   316 		    service = mVideoServices->currentService();
   317 		    service = mVideoServices->currentService();
   317 		    
   318 
   318             HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   319             HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   319             mainWnd->currentView()->setTitle(mVideoServices->contextTitle());
   320             mainWnd->currentView()->setTitle(mVideoServices->contextTitle());
   320 		}
   321 		}
   321 
   322 
   322         HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON);
   323         HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON);
   323 		if(!button)
   324 		if(!button)
   324 		{
   325 		{
   325 		    ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details button.");
   326 		    ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details button.");
   326 		    return;
   327 		    return;
   327 		}
   328 		}
   328 				
   329 
   329 	    // Fix the size of the thumbnail, as that needs to be in 16:9
   330 	    // Fix the size of the thumbnail, as that needs to be in 16:9
   330 	    qreal width = button->size().width();
   331 	    qreal width = button->size().width();
   331 	    qreal height = width * 9 / 16;
   332 	    qreal height = width * 9 / 16;
   332 	    
   333 
   333 	    HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   334 	    HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   334 	    thumbWidget->setPreferredWidth(width);
   335 	    thumbWidget->setPreferredWidth(width);
   335 	    thumbWidget->setPreferredHeight(height);
   336 	    thumbWidget->setPreferredHeight(height);
   336 	    
   337 
   337 		if (service == VideoServices::EUriFetcher)
   338 		if (service == VideoServices::EUriFetcher)
   338 		{
   339 		{
   339             button->setText(hbTrId("txt_videos_button_attach"));
   340 			HbIcon icon = HbIcon("qtg_mono_attach");
       
   341 			button->setIcon(icon);
   340 
   342 
   341             connect(button, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
   343             connect(button, SIGNAL(clicked(bool)), this, SLOT(getFileUri()));
   342             connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
   344             connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
   343 		}
   345 		}
   344 		else
   346 		else
   345 		{
   347 		{
   346 			connect(button, SIGNAL(clicked(bool)), this, SLOT(sendVideoSlot()));
   348 			connect(button, SIGNAL(clicked(bool)), this, SLOT(sendVideoSlot()));
   347 			button->setText(hbTrId("txt_videos_opt_share"));
   349 
       
   350 			HbIcon icon = HbIcon("qtg_mono_share");
       
   351 			button->setIcon(icon);
   348     	}
   352     	}
   349 
   353 
   350         connect(mainWnd,
   354         connect(mainWnd,
   351                 SIGNAL(orientationChanged(Qt::Orientation)),
   355                 SIGNAL(orientationChanged(Qt::Orientation)),
   352                 this, SLOT(orientationChange(Qt::Orientation)));
   356                 this, SLOT(orientationChange(Qt::Orientation)));
   492     using namespace VideoCollectionCommon;
   496     using namespace VideoCollectionCommon;
   493 
   497 
   494     int detailCount = sizeof(VideoDetailLabelKeys) / sizeof(int);
   498     int detailCount = sizeof(VideoDetailLabelKeys) / sizeof(int);
   495 
   499 
   496     QMap<QString, QVariant> metadata = variant.toMap();
   500     QMap<QString, QVariant> metadata = variant.toMap();
   497     
   501 
   498     HbListWidget* list = findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET);
   502     HbListWidget* list = findWidget<HbListWidget>(VIDEO_DETAILS_LISTWIDGET);
   499     if(!list)
   503     if(!list)
   500     {
   504     {
   501         ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details list widget.");
   505         ERROR(-1, "VideoFileDetailsViewPlugin::activateView() failed to load details list widget.");
   502         return;
   506         return;
   503     }
   507     }
   504     
   508 
   505     if(list->count())
   509     if(list->count())
   506     {
   510     {
   507         list->clear();
   511         list->clear();
   508     }
   512     }
   509 
   513 
   563 //
   567 //
   564 void VideoFileDetailsViewPlugin::sendVideoSlot()
   568 void VideoFileDetailsViewPlugin::sendVideoSlot()
   565 {
   569 {
   566 	FUNC_LOG;
   570 	FUNC_LOG;
   567 //	HbMessageBox::information(tr("Not implemented yet"));
   571 //	HbMessageBox::information(tr("Not implemented yet"));
   568 	
   572 
   569     if(mVideoId != TMPXItemId::InvalidId())
   573     if(mVideoId != TMPXItemId::InvalidId())
   570     {
   574     {
   571         ShareUi dialog;
   575         ShareUi dialog;
   572         QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   576         QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   573         QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
   577         QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
   592 		QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   596 		QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   593 		QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyTitle);
   597 		QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyTitle);
   594 
   598 
   595         if (variant.isValid())
   599         if (variant.isValid())
   596         {
   600         {
   597             QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
   601         	QString text = HbParameterLengthLimiter(hbTrId("txt_videos_info_do_you_want_to_delete_1")).
   598 			   variant.toString());
   602         			arg(variant.toString());
   599 
   603 
   600             HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
   604             HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
   601             messageBox->setAttribute(Qt::WA_DeleteOnClose);
   605             messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   606             messageBox->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No);
   602             messageBox->setObjectName(VIDEO_DETAILS_OBJECT_NAME_DELETE_VIDEO);
   607             messageBox->setObjectName(VIDEO_DETAILS_OBJECT_NAME_DELETE_VIDEO);
   603             messageBox->open(this, SLOT(deleteVideoDialogFinished(HbAction *)));
   608             messageBox->open(this, SLOT(deleteVideoDialogFinished(int)));
   604         }
   609         }
   605     }
   610     }
   606 }
   611 }
   607 
   612 
   608 // ---------------------------------------------------------------------------
   613 // ---------------------------------------------------------------------------
   609 // deleteVideoDialogFinished
   614 // deleteVideoDialogFinished
   610 // ---------------------------------------------------------------------------
   615 // ---------------------------------------------------------------------------
   611 //
   616 //
   612 void VideoFileDetailsViewPlugin::deleteVideoDialogFinished(HbAction *action)
   617 void VideoFileDetailsViewPlugin::deleteVideoDialogFinished(int action)
   613 {
   618 {
   614     FUNC_LOG;
   619     FUNC_LOG;
   615     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
       
   616     QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   620     QModelIndex modelIndex = mModel->indexOfId(mVideoId);
   617     if(action == dlg->actions().at(0) && modelIndex.isValid()) 
   621     if(action == HbMessageBox::Yes && modelIndex.isValid())
   618     {
   622     {
   619         deleteItem(modelIndex);
   623         deleteItem(modelIndex);
   620     }
   624     }
   621 }
   625 }
   622 
   626 
   664     if(errorCode == VideoCollectionCommon::statusSingleDeleteFail)
   668     if(errorCode == VideoCollectionCommon::statusSingleDeleteFail)
   665     {
   669     {
   666         QString format = hbTrId("txt_videos_info_unable_to_delete_1_it_is_current");
   670         QString format = hbTrId("txt_videos_info_unable_to_delete_1_it_is_current");
   667         if(additional.isValid())
   671         if(additional.isValid())
   668         {
   672         {
   669            msg = format.arg(additional.toString());
   673            msg = HbParameterLengthLimiter(format).arg(additional.toString());
   670         }
   674         }
   671     }
   675     }
   672     if(msg.count() > 0)
   676     if(msg.count() > 0)
   673     {
   677     {
   674         // show msg box if there's something to show
   678         // show msg box if there's something to show
   688 {
   692 {
   689 	FUNC_LOG;
   693 	FUNC_LOG;
   690     Q_UNUSED(clientData);
   694     Q_UNUSED(clientData);
   691     Q_UNUSED(id);
   695     Q_UNUSED(id);
   692 
   696 
   693 	QSize size(mThumbLabel->size().toSize());
   697 	HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
       
   698 	if(!thumbWidget)
       
   699 	{
       
   700 	    ERROR(-1, "VideoFileDetailsViewPlugin::thumbnailReadySlot() failed to load thumbnail widget.");
       
   701 	    return;
       
   702 	}
       
   703 
       
   704 	QSize size(thumbWidget->size().toSize());
   694 
   705 
   695 	if (!errorCode)
   706 	if (!errorCode)
   696 	{
   707 	{
   697 		QImage sourceImage = pixmap.toImage();
   708 		QImage sourceImage = pixmap.toImage();
   698 
   709 
   707 			}
   718 			}
   708 			sourceImage = sourceImage.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
   719 			sourceImage = sourceImage.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
   709 		}
   720 		}
   710 
   721 
   711 		int difference(0);
   722 		int difference(0);
   712 		QRect rect = mThumbLabel->rect().toRect();
   723 		QRect rect = thumbWidget->rect().toRect();
   713 
   724 
   714 		if(sourceImage.width() > size.width())
   725 		if(sourceImage.width() > size.width())
   715 		{
   726 		{
   716 			difference = sourceImage.width() - size.width();
   727 			difference = sourceImage.width() - size.width();
   717 			difference = (difference/2)+1;
   728 			difference = (difference/2)+1;
   785     // Check if we have already the icon.
   796     // Check if we have already the icon.
   786     if(!mPlayIcon.isNull())
   797     if(!mPlayIcon.isNull())
   787     {
   798     {
   788         return mPlayIcon;
   799         return mPlayIcon;
   789     }
   800     }
   790     
   801 
   791     // Compose the icon.
   802     // Compose the icon.
   792     HbIcon play =        HbIcon("qtg_mono_play");
   803     HbIcon play =        HbIcon("qtg_mono_play");
   793     HbIcon topLeft =     HbIcon("qtg_fr_popup_trans_tl");
   804     HbIcon topLeft =     HbIcon("qtg_fr_popup_trans_tl");
   794     HbIcon top =         HbIcon("qtg_fr_popup_trans_t");
   805     HbIcon top =         HbIcon("qtg_fr_popup_trans_t");
   795     HbIcon topRight =    HbIcon("qtg_fr_popup_trans_tr");
   806     HbIcon topRight =    HbIcon("qtg_fr_popup_trans_tr");
   800     HbIcon bottom =      HbIcon("qtg_fr_popup_trans_b");
   811     HbIcon bottom =      HbIcon("qtg_fr_popup_trans_b");
   801     HbIcon bottomRight = HbIcon("qtg_fr_popup_trans_br");
   812     HbIcon bottomRight = HbIcon("qtg_fr_popup_trans_br");
   802 
   813 
   803     int width = topLeft.width() + top.width() + topRight.width();
   814     int width = topLeft.width() + top.width() + topRight.width();
   804     int height = topLeft.height() + center.height() + bottomLeft.height();
   815     int height = topLeft.height() + center.height() + bottomLeft.height();
   805     
   816 
   806     mPlayIcon = QPixmap(width, height);
   817     mPlayIcon = QPixmap(width, height);
   807     
   818 
   808     QPainter painter(&mPlayIcon);
   819     QPainter painter(&mPlayIcon);
   809     painter.fillRect(mPlayIcon.rect(), Qt::white);
   820     painter.fillRect(mPlayIcon.rect(), Qt::white);
   810     
   821 
   811     painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
   822     painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
   812     
   823 
   813     int x = 0;
   824     int x = 0;
   814     int y = 0;
   825     int y = 0;
   815 
   826 
   816     // Draw top
   827     // Draw top
   817     painter.drawPixmap(QPoint(x, y), topLeft.pixmap());
   828     painter.drawPixmap(QPoint(x, y), topLeft.pixmap());
   818     x += left.width();
   829     x += left.width();
   819     
   830 
   820     painter.drawPixmap(QPoint(x, y), top.pixmap());
   831     painter.drawPixmap(QPoint(x, y), top.pixmap());
   821     x += top.width();
   832     x += top.width();
   822 
   833 
   823     painter.drawPixmap(QPoint(x, y), topRight.pixmap());
   834     painter.drawPixmap(QPoint(x, y), topRight.pixmap());
   824     y += top.height();
   835     y += top.height();
   825     
   836 
   826     // Draw center
   837     // Draw center
   827     x = 0;
   838     x = 0;
   828     painter.drawPixmap(QPoint(x, y), left.pixmap());
   839     painter.drawPixmap(QPoint(x, y), left.pixmap());
   829     x += left.width();
   840     x += left.width();
   830     
   841 
   831     painter.drawPixmap(QPoint(x, y), center.pixmap());
   842     painter.drawPixmap(QPoint(x, y), center.pixmap());
   832     x += center.width();
   843     x += center.width();
   833 
   844 
   834     painter.drawPixmap(QPoint(x, y), right.pixmap());
   845     painter.drawPixmap(QPoint(x, y), right.pixmap());
   835     y += center.height();
   846     y += center.height();
   836     
   847 
   837     // Draw bottom
   848     // Draw bottom
   838     x = 0;
   849     x = 0;
   839     painter.drawPixmap(QPoint(x, y), bottomLeft.pixmap());
   850     painter.drawPixmap(QPoint(x, y), bottomLeft.pixmap());
   840     x += left.width();
   851     x += left.width();
   841     
   852 
   842     painter.drawPixmap(QPoint(x, y), bottom.pixmap());
   853     painter.drawPixmap(QPoint(x, y), bottom.pixmap());
   843     x += top.width();
   854     x += top.width();
   844     
   855 
   845     painter.drawPixmap(QPoint(x, y), bottomRight.pixmap());
   856     painter.drawPixmap(QPoint(x, y), bottomRight.pixmap());
   846     
   857 
   847     // Draw play icon
   858     // Draw play icon
   848     play.setSize(mPlayIcon.size());
   859     play.setSize(mPlayIcon.size());
   849     play.setColor(Qt::white);
   860     play.setColor(Qt::white);
   850     painter.drawPixmap(mPlayIcon.rect(), play.pixmap());
   861     painter.drawPixmap(mPlayIcon.rect(), play.pixmap());
   851     painter.end();
   862     painter.end();
   852     
   863 
   853     return mPlayIcon;
   864     return mPlayIcon;
   854 }
   865 }
   855 
   866 
   856 // ---------------------------------------------------------------------------
   867 // ---------------------------------------------------------------------------
   857 // findWidget
   868 // findWidget