1. Shuffle Implementation 2. fixed 31419
authorchitta ranjan <chitta.rs@samsung.com>
Thu, 4 Apr 2013 04:26:04 +0000 (13:26 +0900)
committerchitta ranjan <chitta.rs@samsung.com>
Thu, 4 Apr 2013 04:26:04 +0000 (13:26 +0900)
Change-Id: I97d3b46c19acc45a6b2b280c873c549e6d3e5143
Signed-off-by: chitta ranjan <chitta.rs@samsung.com>
inc/IvImageViewerForm.h
src/IvImageViewerForm.cpp

index b8932b3..1036bf9 100644 (file)
@@ -166,7 +166,11 @@ private:
        void SetFooterItemState(bool isEnable);
        Tizen::Graphics::Bitmap* GetQuickThumbnailN(Tizen::Base::String& fileName);
 
+       void CreateShuffledList(int count);
+       void SlideShowStopped(int index);
+
 private:
+       int __shuffelStartIndex;
        AppControlMode __initializeDisplayModeCurrent;
        Tizen::Ui::Controls::Label* __pLabel;
        Tizen::Ui::Controls::Footer* __pFooter;
@@ -180,6 +184,7 @@ private:
        Tizen::Ui::Controls::FooterItem* __pDetailFooterItem;
        Tizen::Ui::Controls::Gallery* __pGallery;
        Tizen::Base::Runtime::Timer* __pTimer;
+       Tizen::Base::Runtime::Timer* __pShuffelTimer;
        Tizen::Ui::Controls::ContextMenu* __pContextMenuMore;
        Tizen::Ui::Controls::ContextMenu* __pContextMenuCopy;
        Tizen::Ui::Controls::ContextMenu* __pContextMenuSetAs;
@@ -188,12 +193,15 @@ private:
        bool __visible;
        bool __detail;
        bool __startSlide;
+       bool __shuffle;
        Tizen::Base::String __downLordFileName;
        RequestId __requestId;
        Tizen::Content::ContentTransfer __contentTransfer;
        SlideShowPopUp* __pPopUp;
+       int* __pShuffledList;
        ImageViewerPresentationModel* __pPresentationModel;
        SettingPresentationModel* __pSettingPresentationModel;
+
 };
 
 #endif /* _IV_IMAGE_VIEWER_FORM_H_ */
index 4018c05..19d2589 100644 (file)
@@ -94,27 +94,31 @@ static const int DETAIL_MAIN_FONT_SIZE = 36;
 static const int DETAIL_COUNT_MAX = 9;
 
 ImageViewerForm::ImageViewerForm(void)
-: __initializeDisplayModeCurrent(APPCONTROL_MODE_NORMAL)
-, __pLabel(null)
-, __pFooter(null)
-, __pScrollPanel(null)
-, __pDetail_Label(null)
-, __pLabelMessage(null)
-, __pPlayButton(null)
-, __pRenameButton(null)
-, __pDetailFooterItem(null)
-, __pGallery(null)
-, __pTimer(null)
-, __pContextMenuMore(null)
-, __pContextMenuCopy(null)
-, __pContextMenuSetAs(null)
-, __pContextMenuShare(null)
-, __pDeletePopup(null)
-, __visible(true)
-, __detail(true)
-, __startSlide(false)
-, __requestId(0)
-, __pPresentationModel(null)
+       : __shuffelStartIndex(0)
+       , __initializeDisplayModeCurrent(APPCONTROL_MODE_NORMAL)
+       , __pLabel(null)
+       , __pFooter(null)
+       , __pScrollPanel(null)
+       , __pDetail_Label(null)
+       , __pLabelMessage(null)
+       , __pPlayButton(null)
+       , __pRenameButton(null)
+       , __pDetailFooterItem(null)
+       , __pGallery(null)
+       , __pTimer(null)
+       , __pShuffelTimer(null)
+       , __pContextMenuMore(null)
+       , __pContextMenuCopy(null)
+       , __pContextMenuSetAs(null)
+       , __pContextMenuShare(null)
+       , __pDeletePopup(null)
+       , __visible(true)
+       , __detail(true)
+       , __startSlide(false)
+       , __shuffle(false)
+       , __requestId(0)
+       , __pShuffledList(null)
+       , __pPresentationModel(null)
 {
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -762,7 +766,7 @@ ImageViewerForm::InitializeContextMenuMore(void)
 
        __pContextMenuMore = new (std::nothrow) ContextMenu();
 
-       __pContextMenuMore->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
+       __pContextMenuMore->Construct(Point(X_MORE,  GetClientAreaBounds().height),
                        CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
 
        if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
@@ -1087,9 +1091,17 @@ ImageViewerForm::CreateItem(int index)
        AppLogDebug("ENTER : index(%d)", index);
        GalleryItem* pGallery = new (std::nothrow) GalleryItem();
 
-       String filePath = __pPresentationModel->GetFilePathAt(index);
-       ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
+       int curIndex = index;
+
+       if(__shuffle == true && __pShuffledList != null)
+       {
+               curIndex = __pShuffledList[index];
+       }
+
+       String filePath = __pPresentationModel->GetFilePathAt(curIndex);
+       ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(curIndex);
        Bitmap* pBitmap = pImageInfo->GetBitmapN();
+
        if (pBitmap == null)
        {
                pBitmap = GetQuickThumbnailN(filePath);
@@ -1110,8 +1122,16 @@ ImageViewerForm::CreateItem(int index)
 bool
 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
 {
-       AppLogDebug("ENTER index(%d)", index);
-       ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
+       AppLogDebug("ImageViewerForm::DeleteItem ENTER index(%d)", index);
+       int curIndex = index;
+
+       if(__shuffle == true && __pShuffledList != null)
+       {
+               curIndex = __pShuffledList[index];
+       }
+
+
+       ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(curIndex);
        pImageInfo->ClearBitmap();
        delete pItem;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -1122,7 +1142,7 @@ ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
 void
 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
 {
-       AppLogDebug("ENTER index(%d)", index);
+       AppLogDebug("ImageViewerForm::OnGalleryCurrentItemChanged index(%d)", index);
 
        String filePath = __pPresentationModel->GetFilePathAt(index);
        AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
@@ -1222,9 +1242,35 @@ ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
 void
 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
 {
-       AppLogDebug("ENTER");
+       AppLogDebug("ImageViewerForm::OnGallerySlideShowStopped");
+
+       int index;
+
+       if(__shuffle == true)
+       {
+
+               if(__pShuffelTimer == null)
+               {
+                       __pShuffelTimer = new (std::nothrow) Timer();
+                       __pShuffelTimer->Construct(*this);
+               }
+               __pShuffelTimer->Start(1);
+       }
+       else
+       {
+               index = __pGallery->GetCurrentItemIndex();
+               SlideShowStopped(index);
+       }
+
+
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
+
+void
+ImageViewerForm::SlideShowStopped(int index)
+{
+       AppLog("ImageViewerForm::SlideShowStopped");
        PowerManager::KeepScreenOnState(false, true);
-       int index = __pGallery->GetCurrentItemIndex();
 
        if (__visible == false)
        {
@@ -1253,7 +1299,6 @@ ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
        __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
 
        Invalidate(true);
-       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
@@ -1273,6 +1318,13 @@ ImageViewerForm::OnTerminating(void)
                __pTimer = null;
        }
 
+       if(__pShuffelTimer)
+       {
+               __pShuffelTimer->Cancel();
+               delete __pShuffelTimer;
+               __pShuffelTimer = null;
+       }
+
        __pPresentationModel->ClearImageRequests();
        __pPresentationModel->RemoveListener(*this);
        __pPresentationModel->RemoveFileUpdateListener(*this);
@@ -1307,6 +1359,12 @@ ImageViewerForm::OnTerminating(void)
                __pContextMenuMore = null;
        }
 
+       if(__pShuffledList != null)
+       {
+               free(__pShuffledList);
+               __pShuffledList = null;
+       }
+
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
@@ -1698,14 +1756,52 @@ ImageViewerForm::InitShowGallery(void)
 void
 ImageViewerForm::OnTimerExpired(Timer &timer)
 {
-       int repeatValue = 0;
-       AppLogDebug("ENTER");
+       AppLog("ImageViewerForm::OnTimerExpired");
+
+       if(timer.Equals(*__pShuffelTimer) == true)
+       {
+               AppLog("OnTimerExpired __pShuffelTimer");
+               int curItemIndex = __pGallery->GetCurrentItemIndex();
+               int index = __pShuffledList[curItemIndex];
+
+               __shuffle = false;
+
+               __pGallery->UpdateGallery();
+
+               AppLog("ImageViewerForm::OnGallerySlideShowStopped index = %d, shuffelIndex = %d", curItemIndex, index);
+
+               __pGallery->SetCurrentItemIndex(index);
+               __pGallery->Draw();
+
+               SlideShowStopped(index);
+               return;
+       }
+
+       int repeatValue  = 0;
+       int shuffleValue = 0;
+
        if (__pPresentationModel->GetFileCount() > 1)
        {
                __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
-                               ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
+                                                       ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
 
-               if (repeatValue == 0)
+                __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
+                                                       ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
+
+               
+               if(shuffleValue != 0)
+               {
+                       __shuffelStartIndex = __pGallery->GetCurrentItemIndex();
+                       CreateShuffledList(__pPresentationModel->GetFileCount());
+                       __shuffle = true;
+               }
+               else
+               {
+                       __shuffelStartIndex = 0;
+                       __shuffle = false;
+               }
+
+               if( repeatValue == 0)
                {
                        __pGallery->StartSlideShow(false);
                }
@@ -1718,6 +1814,34 @@ ImageViewerForm::OnTimerExpired(Timer &timer)
 }
 
 void
+ImageViewerForm::CreateShuffledList(int count)
+{
+       AppLogDebug("ImageViewerForm::CreateShuffledList ENTER");
+       if(__pShuffledList == null)
+       {
+               __pShuffledList = new (std::nothrow) int[count];
+               for(int i = 0; i < count; i++)
+               {
+                       __pShuffledList[i] = i;
+               }
+       }
+       for(int i = count - 1; i > 1; i--)
+       {
+               int randomNum = Math::Rand() % (i+1);
+               int t = __pShuffledList[randomNum];
+               __pShuffledList[randomNum] = __pShuffledList[i];
+               __pShuffledList[i] = t;
+       }
+
+       for(int i = 0; i < count; i++)
+       {
+               AppLogDebug("ShuffeldList i = %d & Val = %d", i, __pShuffledList[i]);
+       }
+
+       AppLogDebug("ImageViewerForm::CreateShuffledList EXIT");
+}
+
+void
 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
 {
        AppLogDebug("ENTER");
@@ -2079,6 +2203,8 @@ ImageViewerForm::OnSlideSettingPopUpItemSelected(int index)
 
                if (__pPresentationModel->GetFileCount() > 1)
                {
+                       int shuffleValue;
+
                        __pGallery->UpdateGallery();
 
                        if (__detail == false)
@@ -2089,6 +2215,21 @@ ImageViewerForm::OnSlideSettingPopUpItemSelected(int index)
                        __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
                                        ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
 
+                       __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
+                                       ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
+
+                       if (shuffleValue != 0)
+                       {
+                               __shuffelStartIndex = __pGallery->GetCurrentItemIndex();
+                               CreateShuffledList(__pPresentationModel->GetFileCount());
+                               __shuffle = true;
+                       }
+                       else
+                       {
+                               __shuffelStartIndex = 0;
+                               __shuffle = false;
+                       }
+
                        if (repeatValue == 0)
                        {
                                __pGallery->StartSlideShow(false);