From 07f2756b305247bb1c92f81c4013f5515f603708 Mon Sep 17 00:00:00 2001 From: chitta ranjan Date: Fri, 5 Apr 2013 15:01:46 +0900 Subject: [PATCH] ImageViewer Upadte policy changes Change-Id: I4a09913998dba4e3d60672bf3c53aee3b240a96f Signed-off-by: chitta ranjan --- inc/IvImageCropForm.h | 1 + inc/IvImageViewerPresentationModel.h | 17 ++++-- inc/IvTypes.h | 6 ++ src/IvImageNameEditorForm.cpp | 3 +- src/IvImageSetterForm.cpp | 3 +- src/IvImageViewerForm.cpp | 21 +++---- src/IvImageViewerPresentationModel.cpp | 103 +++++++++++++++------------------ 7 files changed, 80 insertions(+), 74 deletions(-) diff --git a/inc/IvImageCropForm.h b/inc/IvImageCropForm.h index 92ca959..036d6fd 100644 --- a/inc/IvImageCropForm.h +++ b/inc/IvImageCropForm.h @@ -52,6 +52,7 @@ class ImageCropForm { public: ImageCropForm(void); + ~ImageCropForm(void); bool Initialize(void); diff --git a/inc/IvImageViewerPresentationModel.h b/inc/IvImageViewerPresentationModel.h index 4af7208..3159505 100644 --- a/inc/IvImageViewerPresentationModel.h +++ b/inc/IvImageViewerPresentationModel.h @@ -42,7 +42,7 @@ class IFileUpdateEventListener; class ImageViewerPresentationModel : public IImageProviderEventListener - , public Tizen::Io::IFileEventListener + , public Tizen::Content::IContentUpdateEventListener { public: static ImageViewerPresentationModel* GetInstance(); @@ -84,7 +84,12 @@ public: virtual void OnImageReceivedN(Tizen::Base::Runtime::IEventArg& eventArg); - virtual void OnFileEventOccured (const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId); + //From IContentUpdateEventListener + virtual void OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r); + virtual void OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r); + virtual void OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r); + virtual void OnContentDirectoryScanCompleted(const Tizen::Base::String& directoryPath, result r); + private: ImageViewerPresentationModel(void); @@ -97,7 +102,7 @@ private: static void DestroyInstance(void); void LoadSettingValue(); - int GetImageCacheIndex(const Tizen::Base::String &path); + int GetImageCacheIndex(const Tizen::Base::String& ); bool GetImageRotateStatus(void) const; private: @@ -113,9 +118,13 @@ private: Tizen::Base::String __type; int __durationOfSlideShow; SlideShowTransitionEffect __transitionEffectOfSlideShow; - Tizen::Io::FileEventManager* __pFileEventManager; + Tizen::Content::ContentManager* __pCntMgr; SettingPresentationModel* __pSettingPresentationModel; bool __isImageRotated; + bool __ivTriggeredEvent; + short __contentFileEventType; + Tizen::Content::ContentId __contentId; + bool __ivTriggeredDeleteEvent; }; #endif /* _IV_VIEWER_PRESENTATION_MODEL_H_ */ diff --git a/inc/IvTypes.h b/inc/IvTypes.h index 7a34f45..90bf4f8 100644 --- a/inc/IvTypes.h +++ b/inc/IvTypes.h @@ -74,6 +74,12 @@ enum SlideShowTransitionEffect SLIDE_SHOW_TRANSITION_EFFECT_ZOOM }; +enum IVFileEventTypes +{ + IV_FILE_DELETE, + IV_FILE_CREATE +}; + extern const wchar_t* IDL_FORM_IMAGE_VIEWER; extern const wchar_t* IDL_FORM_IMAGE_SETTER; extern const wchar_t* IDL_FORM_NAME_EDITOR; diff --git a/src/IvImageNameEditorForm.cpp b/src/IvImageNameEditorForm.cpp index f1a505d..25803bd 100644 --- a/src/IvImageNameEditorForm.cpp +++ b/src/IvImageNameEditorForm.cpp @@ -186,7 +186,8 @@ ImageNameEditorForm::OnActionPerformed(const Control& source, int actionId) || originalFilePath.StartsWith(Environment::GetExternalStoragePath(), 0) == true) { ImageViewerMediaType mediaType = CommonUtil::GetMediaType(originalFilePath); - if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE) + if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE || + mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO) { result r = File::Move(originalFilePath, filePath); if (r != E_SUCCESS) diff --git a/src/IvImageSetterForm.cpp b/src/IvImageSetterForm.cpp index dcec557..5ca85f1 100644 --- a/src/IvImageSetterForm.cpp +++ b/src/IvImageSetterForm.cpp @@ -484,8 +484,7 @@ ImageSetterForm::OnSceneDeactivated(const SceneId& currentSceneId, void ImageSetterForm::OnFormFileEventOccuered(const int index, const unsigned long eventId) { AppLogDebug(" ENTER"); - bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF); - if (__currentImageIndex == index && eventDelete) + if (__currentImageIndex == index && eventId == IV_FILE_DELETE) { SceneManager* pSceneManager = SceneManager::GetInstance(); pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_VIEWER)); diff --git a/src/IvImageViewerForm.cpp b/src/IvImageViewerForm.cpp index e1c0f75..4e8f8c4 100644 --- a/src/IvImageViewerForm.cpp +++ b/src/IvImageViewerForm.cpp @@ -517,6 +517,8 @@ ImageViewerForm::DeleteImageFile() GetLabelText(__pGallery->GetCurrentItemIndex(), strItemIdxText); + __pLabel->SetText(strItemIdxText); + if (__visible == true) { ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath); @@ -2154,35 +2156,30 @@ ImageViewerForm::GetQuickThumbnailN(String& filePath) void ImageViewerForm::OnFormFileEventOccuered(const int index, const unsigned long eventId) { AppLogDebug(" ENTER"); - bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF); - bool eventMove = (eventId & 0x8000);// (eventId & FILE_EVENT_TYPE_MOVE_SELF); int currentIndex = __pGallery->GetCurrentItemIndex(); - int countPath = __pPresentationModel->GetFileCount(); + int fileCount = __pPresentationModel->GetFileCount(); - if (countPath == 0 && eventDelete) + if (fileCount == 0 && eventId == IV_FILE_DELETE) { UiApp* pApp = UiApp::GetInstance(); pApp->Terminate(); AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult())); } - AppLogDebug(" countPath is %d", countPath); - AppLogDebug(" currentIndex is %d", currentIndex); - if (countPath == currentIndex && eventDelete) + if (fileCount <= currentIndex && eventId == IV_FILE_DELETE) { - __pGallery->SetCurrentItemIndex(--currentIndex); + currentIndex = fileCount - 1; } - else if (eventMove) + else if (eventId == IV_FILE_CREATE) { currentIndex = index; - __pGallery->SetCurrentItemIndex(currentIndex); } - String strItemIdxText(EMPTY_SPACE); + String strItemIdxText(EMPTY_SPACE); + __pGallery->SetCurrentItemIndex(currentIndex); __pGallery->UpdateGallery(); - AppLogDebug(" UpdateGallery is %d", currentIndex); String filePath = __pPresentationModel->GetFilePathAt(currentIndex); __pPresentationModel->RequestImage(filePath); diff --git a/src/IvImageViewerPresentationModel.cpp b/src/IvImageViewerPresentationModel.cpp index 896fa10..fc5e1b7 100644 --- a/src/IvImageViewerPresentationModel.cpp +++ b/src/IvImageViewerPresentationModel.cpp @@ -60,9 +60,11 @@ ImageViewerPresentationModel::ImageViewerPresentationModel(void) , __setterIndex(0) , __durationOfSlideShow(0) , __transitionEffectOfSlideShow(SLIDE_SHOW_TRANSITION_EFFECT_SLIDE) - , __pFileEventManager(null) , __pSettingPresentationModel(null) , __isImageRotated(false) + , __ivTriggeredEvent(false) + , __contentFileEventType(-1) + ,__ivTriggeredDeleteEvent(false) { AppLogDebug("ENTER"); AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); @@ -72,8 +74,9 @@ ImageViewerPresentationModel::~ImageViewerPresentationModel(void) { AppLogDebug("ENTER"); delete __pImageCaches; - delete __pFileEventManager; delete __pFileUpdateListener; + __pCntMgr->RemoveContentUpdateEventListener(*this); + delete __pCntMgr; AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); } @@ -99,8 +102,6 @@ ImageViewerPresentationModel::Construct(void) delete __pImageCaches; } - __pFileEventManager = new (std::nothrow) FileEventManager; - __pFileEventManager->Construct(*this); __pImageCaches = new (std::nothrow) ArrayList(SingleObjectDeleter); __pImageCaches->Construct(); @@ -170,7 +171,9 @@ ImageViewerPresentationModel::Construct(void) __pImageEvent->AddListener(*pImageProviderEventListener, true); __pImageProvider = ImageProvider::GetInstance(); - + __pCntMgr = new (std::nothrow) ContentManager; + __pCntMgr->Construct(); + __pCntMgr->AddContentUpdateEventListener(*this); AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); return E_SUCCESS; @@ -262,6 +265,7 @@ void ImageViewerPresentationModel::DeleteFilePathAt(const int index) { AppLogDebug("ENTER"); + __ivTriggeredEvent = true; __pImageCaches->RemoveAt(index, true); AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); } @@ -272,6 +276,7 @@ ImageViewerPresentationModel::UpdateFilePathAt(const int index, const String& fi AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer()); ImageInfo* pImageInfo = static_cast(__pImageCaches->GetAt(index)); pImageInfo->SetFilePath(filePath); + __ivTriggeredEvent = true; AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); } @@ -413,7 +418,6 @@ ImageViewerPresentationModel::GetFileContentId(const String& filePath) const queryString.Append(L"'"); queryString.Append(GetFileName(filePath)); queryString.Append(L"'"); - pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH, totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE); @@ -427,7 +431,6 @@ ImageViewerPresentationModel::GetFileContentId(const String& filePath) const { continue; } - if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0) { contentId = pResultItem->GetContentInfo()->GetContentId(); @@ -539,17 +542,19 @@ ImageViewerPresentationModel::LoadSettingValue() } } -int ImageViewerPresentationModel::GetImageCacheIndex(const String &path) +int ImageViewerPresentationModel::GetImageCacheIndex(const String& afilePath) { int loopCount = __pImageCaches->GetCount(); - String string; + String filePath; ImageInfo* pImageInfo; for (int i = 0; i < loopCount; ++i) { pImageInfo = static_cast(__pImageCaches->GetAt(i)); - string = pImageInfo->GetFilePath(); - if (string.CompareTo(path) == 0) + filePath = pImageInfo->GetFilePath(); + AppLogDebug(" the filePath %ls", filePath.GetPointer()); + if (afilePath == filePath) { + AppLogDebug(" returning the index %d", i); return i; } } @@ -566,60 +571,48 @@ bool ImageViewerPresentationModel::GetImageRotateStatus(void) const return __isImageRotated; } -void ImageViewerPresentationModel::OnFileEventOccured (const unsigned long events, const String &path, const unsigned int eventId) +void ImageViewerPresentationModel::OnContentFileCreated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r) +{ + AppLogDebug(" Enter"); + AppLogDebug(" Exit"); +} +void ImageViewerPresentationModel::OnContentFileUpdated(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r) +{ + AppLogDebug(" Enter"); + AppLogDebug(" Exit"); +} +void ImageViewerPresentationModel::OnContentFileDeleted(Tizen::Content::ContentId contentId, Tizen::Content::ContentType contentType, result r) { AppLogDebug("Enter"); - bool eventDelete = (events & FILE_EVENT_TYPE_DELETE_SELF); - /*bool eventMove = (events & FILE_EVENT_TYPE_MOVE_SELF); - bool eventMoveSelf = (events & 0x8000);*/ - AppLogDebug("event delete is %d", eventDelete); - //AppLogDebug(" event move is %d", eventMoveSelf); - int index = GetImageCacheIndex(path); - if (index != -1 && eventDelete && GetImageRotateStatus() == false) - { - AppLogDebug("event index is %d, removing the index", index); - __pImageCaches->RemoveAt(index, true); - IEnumerator* pEventEnum = __pFileUpdateListener->GetEnumeratorN(); - IFileUpdateEventListener* pEventListener = null; - while (pEventEnum->MoveNext() == E_SUCCESS) - { - pEventListener = static_cast(pEventEnum->GetCurrent()); - pEventListener->OnFormFileEventOccuered(index, events); - } - } - /** TODO This is for rename, however there seems to be some problem with OnFileEventOccured. - * It is returning 0x8000(which is an illegal value) for move, and File::GetAttributes(path, attr); - * returns E_FILE_NOT_FOUND for renamed file - if (eventMoveSelf) + __contentId = contentId; + __ivTriggeredDeleteEvent = true; + AppLogDebug("Exit"); +} +void ImageViewerPresentationModel::OnContentDirectoryScanCompleted(const Tizen::Base::String& filePath, result r) +{ + AppLogDebug(" Enter"); + AppLogDebug(" directory path is %ls", filePath.GetPointer()); + if ( !__ivTriggeredEvent && __ivTriggeredDeleteEvent) { - ImageInfo* pImageInfo = null; - FileAttributes attr; - result r = File::GetAttributes(path, attr); - AppLogDebug(" event index is %d, adding the index", index); - AppLogDebug(" __pFileEventManager AddPath %ls", path.GetPointer()); - AppLogDebug(" GetAttr result is %d", r); - AppLogDebug(" GetAttr result invalid arg %d", E_INVALID_ARG); - AppLogDebug(" GetAttr result illegal arg %d", E_ILLEGAL_ACCESS); - AppLogDebug(" GetAttr result is IO %d", E_IO); - AppLogDebug(" GetAttr result is FILE NOT FOUND %d", E_FILE_NOT_FOUND); - - AppLogDebug(" GetAttr is dir %d", attr.IsDirectory()); - if (r == E_SUCCESS && attr.IsDirectory() != true) + int index = GetImageCacheIndex(filePath); + AppLogDebug("index is %d", index); + if ( -1 != index ) { - pImageInfo = new (std::nothrow) ImageInfo(); - pImageInfo->Construct(path, null); - __pImageCaches->Add(pImageInfo); - AppLogDebug("__pFileEventManager AddPath %ls", path.GetPointer()); - __pFileEventManager->AddPath(path, FILE_EVENTS); - AppLogDebug("__pFileEventManager events %d", FILE_EVENTS); + __pImageCaches->RemoveAt(index, true); + AppLogDebug("removed the index %d", index); IEnumerator* pEventEnum = __pFileUpdateListener->GetEnumeratorN(); IFileUpdateEventListener* pEventListener = null; while (pEventEnum->MoveNext() == E_SUCCESS) { pEventListener = static_cast(pEventEnum->GetCurrent()); - pEventListener->OnFormFileEventOccuered(__pImageCaches->GetCount() - 1, events); + pEventListener->OnFormFileEventOccuered(index, 0); } } - }*/ + } + if (__ivTriggeredDeleteEvent) + { + __ivTriggeredEvent = false; + } AppLogDebug("Exit"); } + -- 2.7.4