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 FileMoveTimer.cpp
19 * @brief This is the source file for FileMoveTimer class.
28 #include "GlFileListPresentationModel.h"
29 #include "GlFileMoveTimer.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Utility;
34 using namespace Tizen::Content;
35 using namespace Tizen::Io;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 FileMoveTimer::FileMoveTimer(String& destDirectory, IList* list, FileListPresentationModel* presentationModel,
42 IFileOpInvalidateListener* pInvalidate, bool isCopyOperation)
43 : GlTimerBase(pInvalidate, FILE_ACTION_MOVE)
44 , __pMoveIndexList(list)
45 , __moveToDir(destDirectory)
46 , __isCopyOperation(false)
47 , __pPresentationModel(presentationModel)
48 , __scanDirMap(SingleObjectDeleter)
49 , __pContentManager(null)
52 __scanDirMap.Construct();
53 DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
57 FileMoveTimer::~FileMoveTimer(void)
60 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
62 delete __pMoveIndexList;
63 delete __pContentManager;
68 FileMoveTimer::TimerStart(void)
71 if (&__moveToDir == null || __moveToDir.IsEmpty())
73 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
77 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
79 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
83 if (__pMoveIndexList->GetCount() > 0)
85 __pContentManager = new (std::nothrow) ContentManager();
86 __pContentManager->Construct();
87 if (__isCopyOperation == true)
89 SetActionMode(FILE_ACTION_COPY);
91 if (File::IsFileExist(__moveToDir) == false)
93 result r = Directory::Create(__moveToDir, true);
94 AppLog("The directory create result is 2(%s)", GetErrorMessage(r));
96 if ( r == E_STORAGE_FULL)
102 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
103 IList* pCntIdList = __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
113 FileMoveTimer::TimerExpired(const Object* contentId)
115 AppLogDebug("ENTER");
116 const ContentId* cntId = static_cast<const ContentId*>(contentId);
121 ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*cntId);
124 String filePath = cntInfo->GetContentPath();
126 result r = __pPresentationModel->MoveToContentFile(filePath, __moveToDir, __isCopyOperation);
129 if (__isCopyOperation == false)
131 //For Move operation, add the directory being moved from for scanning
134 result r = filePath.LastIndexOf(DIRECTORY_SEPARATOR, filePath.GetLength() - 1, index);
135 TryReturn(r == E_SUCCESS, false, "[%s] Unable to get Dirpath", GetErrorMessage(r));
136 filePath.SubString(0, index, dirPath);
137 if(!__scanDirMap.ContainsKey(dirPath))
139 __scanDirMap.Add(new String(dirPath), new Integer(0));
142 if (!__scanDirMap.ContainsKey(__moveToDir))
144 __scanDirMap.Add(new String(__moveToDir), new Integer(0));
153 FileMoveTimer::ScanDirectories(void)
155 AppLogDebug("ENTER");
157 result r = E_FAILURE;
158 if (__scanDirMap.GetCount() > 0)
160 AppLogDebug("Print AlbumScanMoveToDirPath 2(%d)", __scanDirMap.GetCount());
161 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
163 while (pMapEnum->MoveNext() == E_SUCCESS)
165 pKey = static_cast< String* > (pMapEnum->GetKey());
166 r = ContentManager::ScanDirectory(*(pKey), true, null, reqId);
168 __scanDirMap.RemoveAll();
171 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
176 FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
178 AppLogDebug("ENTER");
179 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
180 if (res == CANCEL_USER || (res == CANCEL_SYS_ERROR && GetMovedCount() > 0) )
182 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
184 if (albumName != EMPTY_SPACE)
186 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
187 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
188 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
189 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
190 delete pDirectoryList;
192 SceneManager* pSceneManager = SceneManager::GetInstance();
193 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
196 else if (res == CANCEL_SYS_ERROR && GetMovedCount() == 0)
198 if (__isCopyOperation == true)
200 MessageBox messageBox;
201 messageBox.Construct(L"", L"Unable to copy files.",
202 MSGBOX_STYLE_NONE, 3000);
204 messageBox.ShowAndWait(modalResult);
211 FileMoveTimer::GetDirScanCount()
213 AppLogDebug("ENTER");
214 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
216 while (pMapEnum->MoveNext() == E_SUCCESS)
218 pKey = static_cast< String* > (pMapEnum->GetKey());
219 if (File::IsFileExist(*pKey) == false)
221 __scanDirMap.Remove(*pKey);
225 return __scanDirMap.GetCount();
229 FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
231 AppLogDebug("ENTER");
232 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
233 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
235 if (albumName != EMPTY_SPACE)
237 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
238 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
239 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
240 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
241 delete pDirectoryList;
243 SceneManager* pSceneManager = SceneManager::GetInstance();
244 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
250 FileMoveTimer::SetCopy(void)
252 __isCopyOperation = true;
256 FileMoveTimer::ClearCopy(void)
258 __isCopyOperation = false;
263 FileMoveTimer::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String& state)
265 AppLogDebug("ENTER");
266 if (deviceType == DEVICE_TYPE_STORAGE_CARD && state == DEVICE_STORAGE_CARD_UNMOUNTED)
268 String sdcPath = Environment::GetExternalStoragePath();
269 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
271 while (pMapEnum->MoveNext() == E_SUCCESS)
273 pKey = static_cast< String* > (pMapEnum->GetKey());
274 if (pKey->StartsWith(sdcPath, 0))
276 __scanDirMap.Remove(*pKey);