2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file GlFileUpdateTimer.cpp
19 * @brief This is the source file for FileUpdateTimer class.
24 #include "GlFileUpdateTimer.h"
25 #include "GlFileListPresentationModel.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Content;
31 using namespace Tizen::Io;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 FileUpdateTimer::FileUpdateTimer(Tizen::Base::Collection::IList* pDelList
38 , IContentFileUpdateManager* pFDM
39 , IFileOpInvalidateListener* invalidate
40 , FileActionMode actionId
41 , RotateMode rotateMode)
42 : GlTimerBase(invalidate, actionId)
43 , __pUpdateIndexList(pDelList)
44 , __pFileUpdateManager(pFDM)
45 , __rotateMode(rotateMode)
46 , __scanDirMap(SingleObjectDeleter)
47 , __pContentManager(null)
49 __scanDirMap.Construct();
50 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
53 FileUpdateTimer::~FileUpdateTimer(void)
56 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
58 delete __pUpdateIndexList;
59 delete __pContentManager;
64 FileUpdateTimer::TimerStart(void)
67 __pContentManager = new (std::nothrow) ContentManager();
68 __pContentManager->Construct();
69 IList* pCntIdList = __pFileUpdateManager->GetContentIdListAtIndexN(*__pUpdateIndexList);
75 FileUpdateTimer::TimerExpired(const Object* contentId)
78 if (_actionId == FILE_ACTION_DELETE)
80 const ContentId* cntId = static_cast<const ContentId*>(contentId);
85 ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*cntId);
88 String filePath = cntInfo->GetContentPath();
90 result r = __pFileUpdateManager->DeleteContentFile(filePath);
95 result r = filePath.LastIndexOf(DIRECTORY_SEPARATOR, filePath.GetLength() - 1, index);
96 TryReturn(r == E_SUCCESS, false, "[%s] Unable to get Dirpath", GetErrorMessage(r));
97 filePath.SubString(0, index, dirPath);
98 if(!__scanDirMap.ContainsKey(dirPath))
100 __scanDirMap.Add(new String(dirPath), new Integer(0));
112 result r = E_SUCCESS;
113 const ContentId* cntId = static_cast<const ContentId*>(contentId);
114 if (contentId != null)
116 r = __pFileUpdateManager->RotateImage(*cntId, __rotateMode);
117 if ( r == E_SUCCESS )
119 __pFileUpdateManager->RequestThumbnail(*cntId); // do not request thumbnail for video files
132 FileUpdateTimer::ScanDirectories(void)
134 AppLogDebug("ENTER");
136 result r = E_SUCCESS;
137 if (_actionId == FILE_ACTION_DELETE)
139 int scanCount = __scanDirMap.GetCount();
144 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
146 while (pMapEnum->MoveNext() == E_SUCCESS)
148 pKey = static_cast< String* > (pMapEnum->GetKey());
149 r = ContentManager::ScanDirectory(*(pKey), true, null, reqId);
151 __scanDirMap.RemoveAll();
152 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
157 AppLogDebug("EXIT, nothing to be done");
163 FileUpdateTimer::GetDirScanCount()
165 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
167 while (pMapEnum->MoveNext() == E_SUCCESS)
169 pKey = static_cast< String* > (pMapEnum->GetKey());
170 if (File::IsFileExist(*pKey) == false)
172 __scanDirMap.Remove(*pKey);
176 return __scanDirMap.GetCount();
180 FileUpdateTimer::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
182 AppLogDebug("ENTER");
183 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED &&
184 _actionId == FILE_ACTION_DELETE)
186 String sdcPath = Environment::GetExternalStoragePath();
187 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
189 while (pMapEnum->MoveNext() == E_SUCCESS)
191 pKey = static_cast< String* > (pMapEnum->GetKey());
192 if (pKey->StartsWith(sdcPath, 0))
194 __scanDirMap.Remove(*pKey);
203 FileUpdateTimer::TimerCancel(int, enum FileActionCancelRes res)
205 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
208 FileUpdateTimer::TimerComplete(int, enum FileActionCompleteRes res)
210 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);