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::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
40 FileMoveTimer::FileMoveTimer(String& destDirectory, IList* list, FileListPresentationModel* presentationModel,
41 IFileOpInvalidateListener* pInvalidate, bool isCopyOperation)
42 : GlTimerBase(pInvalidate, FILE_ACTION_MOVE)
43 , __pMoveIndexList(list)
44 , __moveToDir(destDirectory)
45 , __isCopyOperation(false)
46 , __pPresentationModel(presentationModel)
47 , __scanDirMap(SingleObjectDeleter)
48 , __pContentManager(null)
50 __scanDirMap.Construct();
53 FileMoveTimer::~FileMoveTimer(void)
57 delete __pMoveIndexList;
58 delete __pContentManager;
63 FileMoveTimer::TimerStart(void)
66 if (&__moveToDir == null || __moveToDir.IsEmpty())
68 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
72 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
74 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
78 if (__pMoveIndexList->GetCount() > 0)
80 __pContentManager = new (std::nothrow) ContentManager();
81 __pContentManager->Construct();
82 if (__isCopyOperation == true)
84 SetActionMode(FILE_ACTION_COPY);
86 if (File::IsFileExist(__moveToDir) == false)
88 Directory::Create(__moveToDir, true);
90 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
91 IList* pCntIdList = __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
101 FileMoveTimer::TimerExpired(const Object* contentId)
103 AppLogDebug("ENTER");
104 const ContentId* cntId = static_cast<const ContentId*>(contentId);
109 ContentInfo* cntInfo = __pContentManager->GetContentInfoN(*cntId);
112 String filePath = cntInfo->GetContentPath();
114 result r = __pPresentationModel->MoveToContentFile(filePath, __moveToDir, __isCopyOperation);
117 if (__isCopyOperation == false)
119 //For Move operation, add the directory being moved from for scanning
122 result r = filePath.LastIndexOf(DIRECTORY_SEPARATOR, filePath.GetLength() - 1, index);
123 TryReturn(r == E_SUCCESS, false, "[%s] Unable to get Dirpath", GetErrorMessage(r));
124 filePath.SubString(0, index, dirPath);
125 if(!__scanDirMap.ContainsKey(dirPath))
127 __scanDirMap.Add(new String(dirPath), new Integer(0));
130 if (!__scanDirMap.ContainsKey(__moveToDir))
132 __scanDirMap.Add(new String(__moveToDir), new Integer(0));
141 FileMoveTimer::ScanDirectories(void)
143 AppLogDebug("ENTER");
145 result r = E_FAILURE;
146 if (__scanDirMap.GetCount() > 0)
148 AppLogDebug("Print AlbumScanMoveToDirPath 2(%d)", __scanDirMap.GetCount());
149 IMapEnumerator* pMapEnum = __scanDirMap.GetMapEnumeratorN();
151 while (pMapEnum->MoveNext() == E_SUCCESS)
153 pKey = static_cast< String* > (pMapEnum->GetKey());
154 r = ContentManager::ScanDirectory(*(pKey), true, null, reqId);
156 __scanDirMap.RemoveAll();
159 AppLogDebug("EXIT(%s)", GetErrorMessage(r));
164 FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
166 AppLogDebug("ENTER");
167 if (res == CANCEL_USER || (res == CANCEL_SYS_ERROR && GetMovedCount() > 0) )
169 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
171 if (albumName != EMPTY_SPACE)
173 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
174 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
175 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
176 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
177 delete pDirectoryList;
179 SceneManager* pSceneManager = SceneManager::GetInstance();
180 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
183 else if (res == CANCEL_SYS_ERROR && GetMovedCount() == 0)
185 if (__isCopyOperation == true)
187 MessageBox messageBox;
188 messageBox.Construct(L"", L"Unable to copy files.",
189 MSGBOX_STYLE_NONE, 3000);
191 messageBox.ShowAndWait(modalResult);
198 FileMoveTimer::GetDirScanCount() const
200 AppLogDebug("ENTER");
201 return __scanDirMap.GetCount();
205 FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
207 AppLogDebug("ENTER");
208 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
210 if (albumName != EMPTY_SPACE)
212 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
213 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
214 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
215 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
216 delete pDirectoryList;
218 SceneManager* pSceneManager = SceneManager::GetInstance();
219 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
225 FileMoveTimer::SetCopy(void)
227 __isCopyOperation = true;
231 FileMoveTimer::ClearCopy(void)
233 __isCopyOperation = false;