ImageViewer Update Policy
authorchitta ranjan <chitta.rs@samsung.com>
Wed, 27 Mar 2013 10:43:58 +0000 (19:43 +0900)
committerchitta ranjan <chitta.rs@samsung.com>
Wed, 27 Mar 2013 10:43:58 +0000 (19:43 +0900)
Change-Id: I76eeb52dcc931132a99bb9fba646b6297fba89bc
Signed-off-by: chitta ranjan <chitta.rs@samsung.com>
inc/IvFileUpdateEventListener.h [new file with mode: 0644]
inc/IvImageInfo.h
inc/IvImageSetterForm.h
inc/IvImageViewerForm.h
inc/IvImageViewerPresentationModel.h
src/IvImageInfo.cpp
src/IvImageNameEditorForm.cpp
src/IvImageSetterForm.cpp
src/IvImageViewerForm.cpp
src/IvImageViewerPresentationModel.cpp

diff --git a/inc/IvFileUpdateEventListener.h b/inc/IvFileUpdateEventListener.h
new file mode 100644 (file)
index 0000000..bf6b9d3
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file               IvFileUpdateEventListener.h
+ * @brief              This is the header file for IvFileUpdateEventListener class.
+ */
+
+#ifndef _IV_FILE_UPDATE_EVENT_LISTENER_H_
+#define _IV_FILE_UPDATE_EVENT_LISTENER_H_
+
+#include <FBase.h>
+
+class ImageInfo;
+
+class IFileUpdateEventListener
+       : public Tizen::Base::Object
+{
+public:
+       virtual ~IFileUpdateEventListener(void) {};
+       virtual void OnFormFileEventOccuered(const int index, const unsigned long eventId) = 0;
+};
+
+#endif /* _IV_FILE_UPDATE_EVENT_LISTENER_H_ */
index a9ca0c8..6322bbf 100644 (file)
@@ -32,7 +32,7 @@ public:
        ImageInfo(void);
        virtual ~ImageInfo(void);
 
-       void Construct(Tizen::Base::String& pFilePath, Tizen::Graphics::Bitmap* pBitmap);
+       void Construct(const Tizen::Base::String& pFilePath, Tizen::Graphics::Bitmap* pBitmap);
 
        Tizen::Base::String GetFilePath(void) const;
        void SetFilePath(const Tizen::Base::String& filePath);
index cc3a9fe..54c9f79 100644 (file)
@@ -29,6 +29,8 @@
 #include <FIo.h>
 #include <FUi.h>
 
+#include "IvFileUpdateEventListener.h"
+
 class ImageViewerPresentationModel;
 
 class ImageSetterForm
@@ -39,6 +41,7 @@ class ImageSetterForm
        , public Tizen::Ui::Controls::IGalleryEventListener
        , public Tizen::Ui::Controls::IGalleryItemProvider
        , public Tizen::Ui::Scenes::ISceneEventListener
+       , public IFileUpdateEventListener
 {
 public:
        ImageSetterForm();
@@ -70,6 +73,9 @@ public:
        virtual void OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
                        const Tizen::Ui::Scenes::SceneId& nextSceneId);
 
+       //From IFileUpdateEventListener
+       void OnFormFileEventOccuered(const int index, const unsigned long eventId);
+
 private:
        result InitializeButton(void);
        void CreateGallery(void);
index 059d97f..d42dc5c 100644 (file)
 #include <FUi.h>
 
 #include "IvBaseForm.h"
+#include "IvFileUpdateEventListener.h"
 #include "IvImageProvider.h"
-#include "IvTypes.h"
 #include "IvImageViewerEventListener.h"
+#include "IvTypes.h"
 
 class ImageInfo;
 class ImageViewerForm;
@@ -54,6 +55,7 @@ class ImageViewerForm
        , public Tizen::Ui::Controls::IGalleryItemProvider
        , public Tizen::Ui::Scenes::ISceneEventListener
        , public IImageViewerEventListener
+       , public IFileUpdateEventListener
 {
 public:
        ImageViewerForm(void);
@@ -113,6 +115,9 @@ public:
 
        virtual void OnImageDecodedN(const int index);
 
+       //From IFileUpdateEventListener
+       virtual void OnFormFileEventOccuered(const int index, const unsigned long eventId);
+
 private:
        enum AppControlMode
        {
index 62ed8c1..ed0e54e 100644 (file)
@@ -28,6 +28,7 @@
 #include <FBaseColArrayList.h>
 #include <FContent.h>
 #include <FGraphics.h>
+#include <FIo.h>
 #include <FUi.h>
 #include "IvImageProviderEventListener.h"
 #include "IvTypes.h"
@@ -37,9 +38,11 @@ class ImageInfo;
 class ImageProvider;
 class IImageViewerEventListener;
 class SettingPresentationModel;
+class IFileUpdateEventListener;
 
 class ImageViewerPresentationModel
        : public IImageProviderEventListener
+         , public Tizen::Io::IFileEventListener
 {
 public:
        static ImageViewerPresentationModel* GetInstance();
@@ -48,6 +51,9 @@ public:
        result AddListener(IImageViewerEventListener* listener);
        result RemoveListener(IImageViewerEventListener& listner);
 
+       result AddFileUpdateListener(IFileUpdateEventListener* listener);
+       result RemoveFileUpdateListener(IFileUpdateEventListener& listner);
+
        void ClearImageRequests(bool appTerminating = false);
        void DeleteFilePathAt(const int index);
        void UpdateFilePathAt(const int index, const Tizen::Base::String& filePath);
@@ -75,6 +81,9 @@ public:
 
        virtual void OnImageReceivedN(Tizen::Base::Runtime::IEventArg& eventArg);
 
+       //From IFileEventListener
+       virtual void OnFileEventOccured (const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId);
+
 private:
        ImageViewerPresentationModel(void);
        ImageViewerPresentationModel(const ImageViewerPresentationModel&);
@@ -86,12 +95,14 @@ private:
        static void DestroyInstance(void);
 
        void LoadSettingValue();
+       int GetImageCacheIndex(const Tizen::Base::String &path);
 
 private:
        static ImageViewerPresentationModel* __pPresentationModelInstance;
        static ImageProvider* __pImageProvider;
        static ImageEvent* __pImageEvent;
        static Tizen::Base::Collection::ArrayList* __pImageViewerListener;
+       Tizen::Base::Collection::ArrayList* __pFileUpdateListener;
        Tizen::Base::Collection::ArrayList* __pImageCaches;
        long long __contactId;
        int __startIndex;
@@ -99,6 +110,7 @@ private:
        Tizen::Base::String __type;
        int __durationOfSlideShow;
        SlideShowTransitionEffect __transitionEffectOfSlideShow;
+       Tizen::Io::FileEventManager* __pFileEventManager;
        SettingPresentationModel* __pSettingPresentationModel;
 };
 
index 8bb480d..cadc1a2 100644 (file)
@@ -39,7 +39,7 @@ ImageInfo::~ImageInfo(void)
 }
 
 void
-ImageInfo::Construct(String& pFilePath, Bitmap* pBitmap)
+ImageInfo::Construct(const String& pFilePath, Bitmap* pBitmap)
 {
        AppLogDebug("Enter");
        __pFilePath = pFilePath;
index c979930..9b8d4db 100644 (file)
@@ -369,7 +369,6 @@ ImageNameEditorForm::OnTextValueChanged (const Control &source)
 
        String filePath = __pPresentationModel->GetFilePathAt(__currentIndex);
        String inputString = __pNameEditField->GetText();
-       int modalResult = 0;
 
        if (inputString.Contains(DIRECTORY_SEPARATOR) == true)
        {
index 305cbf6..6e98702 100644 (file)
@@ -91,6 +91,7 @@ ImageSetterForm::OnInitializing(void)
 
        __pPresentationModel = ImageViewerPresentationModel::GetInstance();
        __currentImageIndex = __pPresentationModel->GetSetterIndex();
+       __pPresentationModel->AddFileUpdateListener(this);
        CreateGallery();
        InitializeButton();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
@@ -272,6 +273,7 @@ ImageSetterForm::OnTerminating(void)
        {
                delete __pCurrentBitmap;
        }
+       __pPresentationModel->RemoveFileUpdateListener(*this);
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 
        return E_SUCCESS;
@@ -442,3 +444,15 @@ ImageSetterForm::OnSceneDeactivated(const SceneId& currentSceneId,
        AppLogDebug("ENTER");
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
+
+void ImageSetterForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
+{
+       AppLogDebug(" ENTER");
+       bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF );
+       if ( __currentImageIndex == index && eventDelete )
+       {
+               SceneManager* pSceneManager = SceneManager::GetInstance();
+               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_VIEWER));
+       }
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+}
index 75b2f46..4f47f0e 100644 (file)
@@ -138,6 +138,8 @@ ImageViewerForm::Initialize()
                }
        }
 
+       __pPresentationModel->AddFileUpdateListener(this);
+
        __pSettingPresentationModel = SettingPresentationModel::GetInstance();
 
        int startIndex = __pPresentationModel->GetStartIndex();
@@ -1259,6 +1261,7 @@ ImageViewerForm::OnTerminating(void)
 
        __pPresentationModel->ClearImageRequests();
        __pPresentationModel->RemoveListener(*this);
+       __pPresentationModel->RemoveFileUpdateListener(*this);
 
        if (__pContextMenuCopy != null)
        {
@@ -1932,3 +1935,68 @@ ImageViewerForm::GetQuickThumbnailN(String& filePath)
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        return pBitmap;
 }
+
+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();
+
+       if (countPath == 0 && eventDelete)
+       {
+               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)
+       {
+               __pGallery->SetCurrentItemIndex(--currentIndex);
+       }
+       else if ( eventMove )
+       {
+               currentIndex = index;
+               __pGallery->SetCurrentItemIndex(currentIndex);
+       }
+
+       String strItemText(EMPTY_SPACE);
+       String strItemIdxText(EMPTY_SPACE);
+
+       __pGallery->UpdateGallery();
+       AppLogDebug(" UpdateGallery is %d", currentIndex);
+       String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
+       __pPresentationModel->RequestImage(filePath);
+
+       GetHeaderString(currentIndex, strItemText, strItemIdxText);
+       __pHeader->SetTitleText(strItemText);
+       __pHeader->SetDescriptionText(strItemIdxText);
+
+       if (__visible == true)
+       {
+               ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
+
+               if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
+               {
+                       __pPlayButton->SetShowState(false);
+               }
+               else
+               {
+                       __pPlayButton->SetShowState(true);
+               }
+       }
+       if ( __detail == false)
+       {
+               __pScrollPanel->SetShowState(false);
+               __detail = true;
+       }
+
+
+       Invalidate(true);
+       AppLogDebug("EXIT");
+}
index cf7c028..b625ae7 100644 (file)
@@ -24,6 +24,7 @@
 #include <FIo.h>
 #include <FMedia.h>
 #include <FGraphics.h>
+#include "IvFileUpdateEventListener.h"
 #include "IvImageEvent.h"
 #include "IvImageEventArg.h"
 #include "IvImageInfo.h"
@@ -46,6 +47,10 @@ using namespace Tizen::Media;
 
 static const int PAGE_NO_CONTENT_SEARCH = 1;
 static const int COUNT_PER_PAGE_CONTENT_SEARCH = 10;
+static const int FILE_EVENTS = FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF
+               | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF | FILE_EVENT_TYPE_CREATE;
+
+
 
 ImageViewerPresentationModel* ImageViewerPresentationModel::__pPresentationModelInstance = null;
 ImageProvider* ImageViewerPresentationModel::__pImageProvider = null;
@@ -59,6 +64,7 @@ ImageViewerPresentationModel::ImageViewerPresentationModel(void)
        , __setterIndex(0)
        , __durationOfSlideShow(0)
        , __transitionEffectOfSlideShow(SLIDE_SHOW_TRANSITION_EFFECT_SLIDE)
+       , __pFileEventManager(null)
        , __pSettingPresentationModel(null)
 {
        AppLogDebug("ENTER");
@@ -69,6 +75,8 @@ ImageViewerPresentationModel::~ImageViewerPresentationModel(void)
 {
        AppLogDebug("ENTER");
        delete __pImageCaches;
+       delete __pFileEventManager;
+       delete __pFileUpdateListener;
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -93,6 +101,9 @@ ImageViewerPresentationModel::Construct(void)
        {
                delete __pImageCaches;
        }
+
+       __pFileEventManager = new (std::nothrow) FileEventManager;
+       __pFileEventManager->Construct(*this);
        __pImageCaches = new (std::nothrow) ArrayList(SingleObjectDeleter);
        __pImageCaches->Construct();
 
@@ -148,6 +159,7 @@ ImageViewerPresentationModel::Construct(void)
                                                        pImageInfo = new (std::nothrow) ImageInfo();
                                                        pImageInfo->Construct(tempPath, null);
                                                        __pImageCaches->Add(pImageInfo);
+                                                       __pFileEventManager->AddPath(tempPath, FILE_EVENTS);
                                                        tempPath.Clear();
                                                        continue;
                                                }
@@ -161,6 +173,8 @@ ImageViewerPresentationModel::Construct(void)
                                        pImageInfo = new (std::nothrow) ImageInfo();
                                        pImageInfo->Construct(tempPath, null);
                                        __pImageCaches->Add(pImageInfo);
+                                       __pFileEventManager->AddPath(tempPath, FILE_EVENTS);
+
                                }
                        }
                }
@@ -177,6 +191,9 @@ ImageViewerPresentationModel::Construct(void)
        __pSettingPresentationModel = SettingPresentationModel::GetInstance();
        LoadSettingValue();
 
+       __pFileUpdateListener = new (std::nothrow) ArrayList();
+       __pFileUpdateListener->Construct();
+
        __pImageViewerListener = new (std::nothrow) ArrayList();
        __pImageViewerListener->Construct();
 
@@ -239,6 +256,25 @@ ImageViewerPresentationModel::RemoveListener(IImageViewerEventListener& listner)
        return r;
 }
 
+result
+ImageViewerPresentationModel::AddFileUpdateListener(IFileUpdateEventListener* listener)
+{
+       AppLogDebug("ENTER");
+       result r = __pFileUpdateListener->Add(listener);
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+       return r;
+}
+
+result
+ImageViewerPresentationModel::RemoveFileUpdateListener(IFileUpdateEventListener& listner)
+{
+       AppLogDebug("ENTER");
+       result r = __pFileUpdateListener->Remove(listner);
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
+
+       return r;
+}
 int
 ImageViewerPresentationModel::GetStartIndex(void) const
 {
@@ -536,3 +572,78 @@ ImageViewerPresentationModel::LoadSettingValue()
                break;
        }
 }
+
+int ImageViewerPresentationModel::GetImageCacheIndex(const String &path)
+{
+       int loopCount = __pImageCaches->GetCount();
+       String string;
+       ImageInfo* pImageInfo;
+       for (int i = 0; i < loopCount; ++i)
+       {
+               pImageInfo = static_cast<ImageInfo*>(__pImageCaches->GetAt(i));
+               string = pImageInfo->GetFilePath();
+               if ( string.CompareTo(path) == 0 )
+               {
+                       return i;
+               }
+       }
+       return -1;
+}
+
+void ImageViewerPresentationModel::OnFileEventOccured (const unsigned long events, const String &path, const unsigned int eventId)
+{
+       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 )
+       {
+               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<IFileUpdateEventListener*>(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)
+       {
+               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)
+               {
+                       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);
+                       IEnumerator* pEventEnum = __pFileUpdateListener->GetEnumeratorN();
+                       IFileUpdateEventListener* pEventListener = null;
+                       while (pEventEnum->MoveNext() == E_SUCCESS)
+                       {
+                               pEventListener = static_cast<IFileUpdateEventListener*>(pEventEnum->GetCurrent());
+                               pEventListener->OnFormFileEventOccuered(__pImageCaches->GetCount() - 1, events);
+                       }
+               }
+       }*/
+       AppLogDebug("Exit");
+}