Fixed prevent issue
[apps/osp/Gallery.git] / src / GlFileMoveTimer.cpp
index cc6f780..818436f 100644 (file)
@@ -33,6 +33,7 @@ using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Content;
 using namespace Tizen::Io;
+using namespace Tizen::System;
 using namespace Tizen::Ui;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
@@ -47,12 +48,16 @@ FileMoveTimer::FileMoveTimer(String& destDirectory, IList* list, FileListPresent
        , __scanDirMap(SingleObjectDeleter)
        , __pContentManager(null)
 {
+       AppLogDebug("ENTER");
        __scanDirMap.Construct();
+       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+       AppLogDebug("EXIT");
 }
 
 FileMoveTimer::~FileMoveTimer(void)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        ScanDirectories();
        delete __pMoveIndexList;
        delete __pContentManager;
@@ -85,9 +90,15 @@ FileMoveTimer::TimerStart(void)
                }
                if (File::IsFileExist(__moveToDir) == false)
                {
-                       Directory::Create(__moveToDir, true);
+                       result r = Directory::Create(__moveToDir, true);
+                       AppLog("The directory create result is 2(%s)", GetErrorMessage(r));
+
+                       if ( r == E_STORAGE_FULL)
+                       {
+                               return null;
+                       }
+
                }
-               __scanDirMap.Add(new String(__moveToDir), new Integer(0));
                AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
                IList* pCntIdList = __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
                return pCntIdList;
@@ -128,6 +139,10 @@ FileMoveTimer::TimerExpired(const Object* contentId)
                                        __scanDirMap.Add(new String(dirPath), new Integer(0));
                                }
                        }
+                       if (!__scanDirMap.ContainsKey(__moveToDir))
+                       {
+                               __scanDirMap.Add(new String(__moveToDir), new Integer(0));
+                       }
                }
                return r;
        }
@@ -161,6 +176,7 @@ void
 FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        if (res == CANCEL_USER || (res == CANCEL_SYS_ERROR && GetMovedCount() > 0) )
        {
                String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
@@ -192,9 +208,20 @@ FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
 }
 
 int
-FileMoveTimer::GetDirScanCount() const
+FileMoveTimer::GetDirScanCount()
 {
        AppLogDebug("ENTER");
+       IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
+       String* pKey = null;
+       while (pMapEnum->MoveNext() == E_SUCCESS)
+       {
+               pKey = static_cast< String* > (pMapEnum->GetKey());
+               if (File::IsFileExist(*pKey) == false)
+               {
+                       __scanDirMap.Remove(*pKey);
+               }
+       }
+       delete pMapEnum;
        return __scanDirMap.GetCount();
 }
 
@@ -202,6 +229,7 @@ void
 FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
 {
        AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
 
        if (albumName != EMPTY_SPACE)
@@ -229,3 +257,26 @@ FileMoveTimer::ClearCopy(void)
 {
        __isCopyOperation = false;
 }
+
+
+void
+FileMoveTimer::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
+{
+       AppLogDebug("ENTER");
+       if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
+       {
+               String sdcPath = Environment::GetExternalStoragePath();
+               IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
+               String* pKey = null;
+               while (pMapEnum->MoveNext() == E_SUCCESS)
+               {
+                       pKey = static_cast< String* > (pMapEnum->GetKey());
+                       if (pKey->StartsWith(sdcPath, 0))
+                       {
+                               __scanDirMap.Remove(*pKey);
+                       }
+               }
+               delete pMapEnum;
+       }
+       AppLogDebug("EXIT");
+}