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)
50 FileMoveTimer::~FileMoveTimer(void)
52 delete __pMoveIndexList;
55 IList * FileMoveTimer::TimerStart(void)
58 if (&__moveToDir == null || __moveToDir.IsEmpty())
60 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
64 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
66 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
69 if (__isCopyOperation == true)
71 SetActionMode(FILE_ACTION_COPY);
73 if (__pMoveIndexList->GetCount() > 0)
75 if (File::IsFileExist(__moveToDir) == false)
77 Directory::Create(__moveToDir, true);
79 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
80 return __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
88 result FileMoveTimer::TimerExpired(const Object* contentId)
91 return __pPresentationModel->MoveToContentFile(*static_cast<const ContentId*>(contentId), __moveToDir, __isCopyOperation);
94 void FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
98 if (res == CANCEL_USER || (res == CANCEL_SYS_ERROR && GetMovedCount() > 0) )
100 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
102 if (albumName != EMPTY_SPACE)
104 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
105 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
106 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
107 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
108 delete pDirectoryList;
110 SceneManager* pSceneManager = SceneManager::GetInstance();
111 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
114 else if (res == CANCEL_SYS_ERROR && GetMovedCount() == 0)
116 if ( __isCopyOperation == true )
118 MessageBox messageBox;
119 messageBox.Construct(L"", L"Unable to copy files.",
120 MSGBOX_STYLE_NONE, 3000);
122 messageBox.ShowAndWait(modalResult);
128 void FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
130 AppLogDebug("ENTER");
131 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
133 if (albumName != EMPTY_SPACE)
135 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
136 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
137 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
138 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
139 delete pDirectoryList;
141 SceneManager* pSceneManager = SceneManager::GetInstance();
142 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
147 void FileMoveTimer::SetCopy(void)
149 __isCopyOperation = true;
152 void FileMoveTimer::ClearCopy(void)
154 __isCopyOperation = false;