Fixed issue 51922
[apps/osp/Gallery.git] / src / GlFileMoveTimer.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                FileMoveTimer.cpp
19  * @brief               This is the source file for FileMoveTimer class.
20  */
21
22 #include <FBase.h>
23 #include <FContent.h>
24 #include <FMedia.h>
25 #include <FSystem.h>
26 #include <FUi.h>
27
28 #include "GlFileListPresentationModel.h"
29 #include "GlFileMoveTimer.h"
30
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;
39
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 {
48 }
49
50 FileMoveTimer::~FileMoveTimer(void)
51 {
52         delete __pMoveIndexList;
53 }
54
55 IList * FileMoveTimer::TimerStart(void)
56 {
57         AppLogDebug("ENTER");
58         if (&__moveToDir == null || __moveToDir.IsEmpty())
59         {
60                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
61                 return null;
62         }
63
64         if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
65         {
66                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
67                 return null;
68         }
69         if (__isCopyOperation == true)
70         {
71                 SetActionMode(FILE_ACTION_COPY);
72         }
73         if (__pMoveIndexList->GetCount() > 0)
74         {
75                 if (File::IsFileExist(__moveToDir) == false)
76                 {
77                         result r = Directory::Create(__moveToDir, true);
78                         AppLog(" The Directory create result is %s",GetErrorMessage(r));
79
80                         if ( r != E_SUCCESS )
81                         {
82                                 return null;
83                         }
84                 }
85                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
86                 return __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
87         }
88         else
89         {
90                 return null;
91         }
92 }
93
94 result FileMoveTimer::TimerExpired(const Object* contentId)
95 {
96         AppLogDebug("ENTER");
97         return __pPresentationModel->MoveToContentFile(*static_cast<const ContentId*>(contentId), __moveToDir, __isCopyOperation);
98 }
99
100 void FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
101 {
102         AppLogDebug("ENTER");
103
104         if (res == CANCEL_USER || (res == CANCEL_SYS_ERROR && GetMovedCount() > 0))
105         {
106                 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
107
108                 if (albumName != EMPTY_SPACE)
109                 {
110                         IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
111                         pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
112                         __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
113                         __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
114                         delete pDirectoryList;
115
116                         SceneManager* pSceneManager = SceneManager::GetInstance();
117                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
118                 }
119         }
120         else if (res == CANCEL_SYS_ERROR && GetMovedCount() == 0)
121         {
122                 if (__isCopyOperation == true)
123                 {
124                         MessageBox messageBox;
125                         messageBox.Construct(L"", L"Unable to copy files.",
126                                         MSGBOX_STYLE_NONE, 3000);
127                         int modalResult;
128                         messageBox.ShowAndWait(modalResult);
129                 }
130         }
131         AppLogDebug("EXIt");
132 }
133
134 void FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
135 {
136         AppLogDebug("ENTER");
137         String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
138
139         if (albumName != EMPTY_SPACE)
140         {
141                 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
142                 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
143                 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
144                 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
145                 delete pDirectoryList;
146
147                 SceneManager* pSceneManager = SceneManager::GetInstance();
148                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
149         }
150         AppLogDebug("EXIt");
151 }
152
153 void FileMoveTimer::SetCopy(void)
154 {
155         __isCopyOperation = true;
156 }
157
158 void FileMoveTimer::ClearCopy(void)
159 {
160         __isCopyOperation = false;
161 }