videocollection/videocollectionview/src/videolistwidget.cpp
changeset 52 e3cecb93e76a
parent 47 45e72b57a2fd
child 59 a76e86df7ccd
--- a/videocollection/videocollectionview/src/videolistwidget.cpp	Tue Jul 06 14:17:50 2010 +0300
+++ b/videocollection/videocollectionview/src/videolistwidget.cpp	Wed Aug 18 09:50:14 2010 +0300
@@ -30,6 +30,7 @@
 #include <hblistviewitem.h>
 #include <hbmessagebox.h>
 #include <hbinputdialog.h>
+#include <hbparameterlengthlimiter.h>
 #include <vcxmyvideosdefs.h>
 
 #include "videocollectionviewutils.h"
@@ -150,6 +151,7 @@
 		connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
 	}
 
+	setItemPixmapCacheEnabled(true);
 	setModel(mModel);
 	
     return 0;
@@ -200,7 +202,7 @@
     // Enable thumbnail background fetching.
     VideoThumbnailData &thumbnailData = VideoThumbnailData::instance();
     thumbnailData.enableBackgroundFetching(true);
-    thumbnailData.startBackgroundFetching(mModel, 0);
+    fetchThumbnailsForVisibleItems();
 
     return 0;
 }
@@ -380,13 +382,14 @@
 
     if (variant.isValid())
     {
-        QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
-                variant.toString());
+        QString text = HbParameterLengthLimiter(
+                hbTrId("txt_videos_info_do_you_want_to_delete_1")).arg(variant.toString()); 
         
         HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
+        messageBox->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No);
         messageBox->setAttribute(Qt::WA_DeleteOnClose);
         messageBox->setObjectName(LIST_WIDGET_OBJECT_NAME_DELETE_VIDEO);
-        messageBox->open(this, SLOT(deleteItemDialogFinished(HbAction *)));
+        messageBox->open(this, SLOT(deleteItemDialogFinished(int)));
     }
 }
 
@@ -394,10 +397,9 @@
 // deleteItemDialogFinished
 // ---------------------------------------------------------------------------
 //
-void VideoListWidget::deleteItemDialogFinished(HbAction *action)
+void VideoListWidget::deleteItemDialogFinished(int action)
 {
-    HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
-    if(action == dlg->actions().at(0)) 
+    if(action == HbMessageBox::Yes)
     {
         QModelIndex index = currentIndex();
         if(index.isValid())
@@ -543,6 +545,7 @@
     	mContextMenuActions[EActionDelete]->setVisible(true);
     	mContextMenuActions[EActionPlay]->setVisible(true);
 		mContextMenuActions[EActionDetails]->setVisible(true);
+		mContextMenuActions[EActionRename]->setVisible(true);
     }
     else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory) 
     {
@@ -560,6 +563,7 @@
         mContextMenuActions[EActionDelete]->setVisible(true);
     	mContextMenuActions[EActionPlay]->setVisible(true);
 		mContextMenuActions[EActionDetails]->setVisible(true);
+		mContextMenuActions[EActionRename]->setVisible(true);
     }
 }
 
@@ -789,9 +793,8 @@
     
     QModelIndex index = currentIndex();
     QVariant variant = mModel->data(index, VideoCollectionCommon::KeyTitle);
-    TMPXItemId itemId = mModel->getMediaIdAtIndex(index);
-
-    if(variant.isValid() && itemId.iId2 == KVcxMvcMediaTypeAlbum)
+     
+    if(variant.isValid())
     {
         QString label(hbTrId("txt_videos_title_enter_name"));
         QString albumName = variant.toString();
@@ -814,26 +817,34 @@
     Q_UNUSED(action);
 
     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
-    
+    if(dialog->actions().first() != action)
+    {
+        return;
+    }
     QModelIndex index = currentIndex();
     TMPXItemId itemId = mModel->getMediaIdAtIndex(index);
     QVariant newNameVariant = dialog->value();
     QVariant oldNameVariant = mModel->data(index, VideoCollectionCommon::KeyTitle);
-    
-    if(dialog->actions().first() == action &&
-       oldNameVariant.isValid() && newNameVariant.isValid() && itemId.iId2 == KVcxMvcMediaTypeAlbum)
+    if(!newNameVariant.isValid() || !oldNameVariant.isValid())
+    {
+        // invalid data at index
+        return;
+    }
+    QString newAlbumName = newNameVariant.toString().trimmed();
+    QString oldAlbumName = oldNameVariant.toString();
+    if(!newAlbumName.length() || newAlbumName == oldAlbumName)
     {
-        QString newAlbumName = newNameVariant.toString();
-        QString oldAlbumName = oldNameVariant.toString();
-        
-        if(newAlbumName.length() && newAlbumName.trimmed() != oldAlbumName)
-        {
-            // Resolve collection true name and rename the album
-            newAlbumName = mModel->resolveAlbumName(newAlbumName);
-            mModel->renameAlbum(itemId, newAlbumName);
-        }
+        // no new name provided or name has not changed
+        return;
     }
+    if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
+    {     
+        // for album, we need to make sure name is unique
+        newAlbumName = mModel->resolveAlbumName(newAlbumName);
+    }
+    mModel->renameItem(itemId, newAlbumName);
 }
+
 // ---------------------------------------------------------------------------
 // addToCollectionSlot
 // ---------------------------------------------------------------------------
@@ -897,12 +908,14 @@
 
     if (variant.isValid())
     {
-        QString text = hbTrId("txt_videos_info_do_you_want_to_remove_collection").arg(
-                variant.toString());
+        QString text = HbParameterLengthLimiter(
+                hbTrId("txt_videos_info_do_you_want_to_remove_collection")).arg(variant.toString()); 
+        
         HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
+        messageBox->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No);
         messageBox->setAttribute(Qt::WA_DeleteOnClose);
-        messageBox->setObjectName(LIST_WIDGET_OBJECT_NAME_REMOVE_COLLECTION);            
-        messageBox->open(this, SLOT(removeCollectionDialogFinished(HbAction *)));
+        messageBox->setObjectName(LIST_WIDGET_OBJECT_NAME_REMOVE_COLLECTION);
+        messageBox->open(this, SLOT(removeCollectionDialogFinished(int)));
     }
 }
 
@@ -910,10 +923,9 @@
 // removeCollectionDialogFinished
 // ---------------------------------------------------------------------------
 //
-void VideoListWidget::removeCollectionDialogFinished(HbAction *action)
+void VideoListWidget::removeCollectionDialogFinished(int action)
 {
-    HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
-    if(action == dlg->actions().at(0)) 
+    if(action == HbMessageBox::Yes)
     {
         QModelIndex index = currentIndex();
         if(index.isValid())
@@ -1007,13 +1019,53 @@
 void VideoListWidget::fetchThumbnailsForVisibleItems()
 {
 	FUNC_LOG_ADDR(this);
+	
+	// No need to do anything if thumbnail fetching is not enabled.
+	if(!VideoThumbnailData::instance().backgroundFetchingEnabled())
+	{
+	    return;
+	}
+	
     const QList<HbAbstractViewItem *> itemsVisible = visibleItems();
-
+    
     if(itemsVisible.count() > 0)
     {
         int row = itemsVisible.value(0)->modelIndex().row();
         VideoThumbnailData::instance().startBackgroundFetching(mModel, row);
     }
+    else
+    {
+        // Nothing visible yet, start from first index.
+        VideoThumbnailData::instance().startBackgroundFetching(mModel, 0);
+    }
+}
+
+// ---------------------------------------------------------------------------
+// rowsInserted
+// ---------------------------------------------------------------------------
+//
+void VideoListWidget::rowsInserted(const QModelIndex &parent, int start, int end)
+{
+    FUNC_LOG_ADDR(this);
+    Q_UNUSED(parent);
+    Q_UNUSED(start);
+    Q_UNUSED(end);
+    fetchThumbnailsForVisibleItems();
+    HbListView::rowsInserted(parent, start, end);
+}
+
+// ---------------------------------------------------------------------------
+// rowsRemoved
+// ---------------------------------------------------------------------------
+//
+void VideoListWidget::rowsRemoved(const QModelIndex &parent, int start, int end)
+{
+    FUNC_LOG_ADDR(this);
+    Q_UNUSED(parent);
+    Q_UNUSED(start);
+    Q_UNUSED(end);
+    fetchThumbnailsForVisibleItems();
+    HbListView::rowsRemoved(parent, start, end);
 }
 
 // end of file