coding guidelines update
[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.0 (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         , __pPresentationModel(presentationModel)
46 {
47 }
48
49 FileMoveTimer::~FileMoveTimer(void)
50 {
51         delete __pMoveIndexList;
52 }
53
54 IList * FileMoveTimer::TimerStart(void)
55 {
56         AppLogDebug("ENTER");
57         if (&__moveToDir == null || __moveToDir.IsEmpty())
58         {
59                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
60                 return null;
61         }
62
63         if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
64         {
65                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
66                 return null;
67         }
68         if (__isCopyOperation == true)
69         {
70                 SetActionMode(FILE_ACTION_COPY);
71         }
72         if (__pMoveIndexList->GetCount() > 0)
73         {
74                 if (File::IsFileExist(__moveToDir) == false)
75                 {
76                         Directory::Create(__moveToDir, true);
77                 }
78                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
79                 return __pPresentationModel->GetContentIdListAtIndexN(*__pMoveIndexList);
80         }
81         else
82         {
83                 return null;
84         }
85 }
86
87 result FileMoveTimer::TimerExpired(const Object* contentId)
88 {
89         AppLogDebug("ENTER");
90         return __pPresentationModel->MoveToContentFile(*static_cast<const ContentId*>(contentId), __moveToDir, __isCopyOperation);
91 }
92
93 void FileMoveTimer::TimerCancel(int, enum FileActionCancelRes res)
94 {
95         AppLogDebug("ENTER");
96         if (res == CANCEL_USER)
97         {
98                 String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
99
100                 if (albumName != EMPTY_SPACE)
101                 {
102                         IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
103                         pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
104                         __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
105                         __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
106                         delete pDirectoryList;
107
108                         SceneManager* pSceneManager = SceneManager::GetInstance();
109                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
110                 }
111         }
112         AppLogDebug("EXIt");
113 }
114
115 void FileMoveTimer::TimerComplete(int, enum FileActionCompleteRes res)
116 {
117         AppLogDebug("ENTER");
118         String albumName = __pPresentationModel->ConvertToAlbumName(__moveToDir);
119
120         if (albumName != EMPTY_SPACE)
121         {
122                 IList* pDirectoryList = new (std::nothrow) ArrayList(SingleObjectDeleter);
123                 pDirectoryList->Add(new (std::nothrow) String(__moveToDir));
124                 __pPresentationModel->SetCurrentAlbumInfo(albumName, *pDirectoryList);
125                 __pPresentationModel->SetCurrentAlbumContentType(CONTENT_TYPE_ALL);
126                 delete pDirectoryList;
127
128                 SceneManager* pSceneManager = SceneManager::GetInstance();
129                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALL_LIST));
130         }
131         AppLogDebug("EXIt");
132 }
133
134 void FileMoveTimer::SetCopy(void)
135 {
136         __isCopyOperation = true;
137 }
138
139 void FileMoveTimer::ClearCopy(void)
140 {
141         __isCopyOperation = false;
142 }