Fixed prevent issue
[apps/osp/Gallery.git] / src / GlFileUpdateTimer.cpp
index 6261555..1ef83cc 100644 (file)
@@ -19,6 +19,8 @@
  * @brief              This is the source file for FileUpdateTimer class.
  */
 
+#include <FIo.h>
+
 #include "GlFileUpdateTimer.h"
 #include "GlFileListPresentationModel.h"
 
@@ -27,6 +29,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;
@@ -44,28 +47,34 @@ FileUpdateTimer::FileUpdateTimer(Tizen::Base::Collection::IList* pDelList
        , __pContentManager(null)
 {
        __scanDirMap.Construct();
+       DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
 }
 
 FileUpdateTimer::~FileUpdateTimer(void)
 {
+       AppLogDebug("ENTER");
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
        ScanDirectories();
        delete __pUpdateIndexList;
        delete __pContentManager;
+       AppLogDebug("EXIT");
 }
 
 IList *
 FileUpdateTimer::TimerStart(void)
 {
+       AppLogDebug("ENTER");
        __pContentManager = new (std::nothrow) ContentManager();
        __pContentManager->Construct();
        IList* pCntIdList = __pFileUpdateManager->GetContentIdListAtIndexN(*__pUpdateIndexList);
+       AppLogDebug("EXIT");
        return pCntIdList;
 }
 
 result
 FileUpdateTimer::TimerExpired(const Object* contentId)
 {
-
+       AppLogDebug("ENTER");
        if (_actionId == FILE_ACTION_DELETE)
        {
                const ContentId* cntId = static_cast<const ContentId*>(contentId);
@@ -116,6 +125,7 @@ FileUpdateTimer::TimerExpired(const Object* contentId)
                }
                return r;
        }
+       AppLogDebug("EXIT");
 }
 
 result
@@ -150,8 +160,52 @@ FileUpdateTimer::ScanDirectories(void)
 }
 
 int
-FileUpdateTimer::GetDirScanCount() const
+FileUpdateTimer::GetDirScanCount()
 {
+       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();
 }
 
+void
+FileUpdateTimer::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
+{
+       AppLogDebug("ENTER");
+       if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED &&
+                       _actionId == FILE_ACTION_DELETE)
+       {
+               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");
+}
+
+void
+FileUpdateTimer::TimerCancel(int, enum FileActionCancelRes res)
+{
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+}
+void
+FileUpdateTimer::TimerComplete(int, enum FileActionCompleteRes res)
+{
+       DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
+}