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 GlTimerBase.cpp
19 * @brief This is the source file for GlTimerBase class.
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlContentUpdateEventListener.h"
27 #include "GlFileListPresentationModel.h"
28 #include "GlProgressBar.h"
29 #include "GlTimerBase.h"
32 using namespace Tizen::Ui;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Ui::Controls;
36 GlTimerBase::GlTimerBase(IFileOpInvalidateListener* invalidateListener, enum FileActionMode actionId)
38 , __pContentIdList(null)
41 , __pInvalidate(invalidateListener)
43 , __timerRes(CANCEL_BY_USER)
46 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
49 GlTimerBase::~GlTimerBase(void)
53 AlbumListPresentationModel::GetInstance()->RemoveTimerScanListener();
54 FileListPresentationModel::GetInstance()->StopAnimation();
55 AlbumListPresentationModel::GetInstance()->StopAnimation();
56 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
57 pContentListener->ReSetTimerActive();
59 if (__pContentIdList != null && __pContentIdList->GetCount() > 0 && __isStarted)
64 delete __pContentIdList;
67 __pMoveProBar->HideFileProgressingPopup();
74 GlTimerBase::StartTimer(void)
77 __pContentIdList = TimerStart();
78 if (__pContentIdList != null && __pContentIdList->GetCount() > 0)
80 AppLogDebug("Starting timer");
81 __pMoveProBar = new (std::nothrow) GlProgressBar(static_cast<IActionEventListener*>(this),
82 static_cast<IPropagatedKeyEventListener*>(this));
83 __pMoveProBar->ShowFileProgressingPopup(__pContentIdList->GetCount(), _actionId);
85 __moveTimer.Construct(*this);
86 __moveTimer.Start(60);
88 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
89 pContentListener->SetTimerActive();
90 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
93 AppLogDebug("EXIT1(%s)", GetErrorMessage(GetLastResult()));
98 GlTimerBase::CancelTimer(void)
100 AppLogDebug("ENTER");
101 __moveTimer.Cancel();
102 __pMoveProBar->HideFileProgressingPopup();
103 int scanCount = GetDirScanCount();
104 if ( (scanCount > 0 && _actionId != FILE_ACTION_MOVE ) ||
105 (scanCount > 1 && _actionId == FILE_ACTION_MOVE ))
107 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
109 __pInvalidate->OnScanDirStart();
110 FileListPresentationModel::GetInstance()->ShowAnimation();
111 AlbumListPresentationModel::GetInstance()->ShowAnimation();
115 OnOpCancelled(CANCEL_USER);
119 __timerRes = CANCEL_BY_USER;
120 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
124 GlTimerBase::OnTimerScanDirComplete()
126 AppLogDebug("OnTimerScanDirComplete ENTER");
128 AlbumListPresentationModel::GetInstance()->RemoveTimerScanListener();
129 FileListPresentationModel::GetInstance()->StopAnimation();
130 AlbumListPresentationModel::GetInstance()->StopAnimation();
131 __pInvalidate->OnScanDirComplete();
135 AppLogDebug("CANCEL_SYS");
136 OnOpCancelled(CANCEL_SYS_ERROR);
139 AppLogDebug("CANCEL_BY_USER");
140 OnOpCancelled(CANCEL_USER);
143 AppLogDebug("TIMER_COMPLETE");
144 OnOpComplete(COMPLETE_SUCCESS);
149 AppLogDebug("ENTER");
153 GlTimerBase::OnTimerExpired(Timer& timer)
155 AppLogDebug("ENTER");
156 if (&timer == &__moveTimer)
158 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
159 if (__moveToCount < __pContentIdList->GetCount())
161 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
162 if (__pContentIdList->GetAt(__moveToCount) != null)
164 result r = TimerExpired(__pContentIdList->GetAt(__moveToCount));
167 if (r == E_STORAGE_FULL || r == E_IO)
169 __moveTimer.Cancel();
171 __timerRes = CANCEL_SYS;
172 __pMoveProBar->HideFileProgressingPopup();
173 int scanCount = GetDirScanCount();
174 if ( (scanCount > 0 && _actionId != FILE_ACTION_MOVE ) ||
175 (scanCount > 1 && _actionId == FILE_ACTION_MOVE ))
177 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
179 __pInvalidate->OnScanDirStart();
180 FileListPresentationModel::GetInstance()->ShowAnimation();
181 AlbumListPresentationModel::GetInstance()->ShowAnimation();
185 MessageBox messageBox;
186 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED"),
187 MSGBOX_STYLE_NONE, 3000);
189 messageBox.ShowAndWait(modalResult);
190 OnOpCancelled(CANCEL_SYS_ERROR);
192 AppLogDebug("OnTimerExpired EXIT(%s)", GetErrorMessage(r));
195 //If the errors are file not found etc, skip this file and move to next.
199 __pMoveProBar->IncProgress(__moveToCount);
202 __pInvalidate->OnFileOpInvalidate(_actionId);
204 __moveTimer.Start(1);
209 __moveTimer.Cancel();
210 __pMoveProBar->HideFileProgressingPopup();
211 int scanCount = GetDirScanCount();
212 if (scanCount == 0 && _actionId == FILE_ACTION_ROTATE)
216 __timerRes = TIMER_COMPLETE;
217 OnOpComplete(COMPLETE_SUCCESS);
220 if ((scanCount > 0 && _actionId != FILE_ACTION_MOVE ) ||
221 (scanCount > 1 && _actionId == FILE_ACTION_MOVE ))
223 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
225 __pInvalidate->OnScanDirStart();
226 FileListPresentationModel::GetInstance()->ShowAnimation();
227 AlbumListPresentationModel::GetInstance()->ShowAnimation();
230 __timerRes = TIMER_COMPLETE;
234 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
238 GlTimerBase::OnActionPerformed(const Control& source, int actionId)
240 AppLogDebug("ENTER");
243 case IDA_PROGRESSBAR_CANCEL:
252 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
256 GlTimerBase::GetMovedCount() const
258 return __moveToCount;
262 GlTimerBase::OnOpCancelled(enum FileActionCancelRes res)
264 AppLogDebug("ENTER");
265 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
266 pContentListener->ReSetTimerActive();
269 __pInvalidate->OnFileOpInvalidate(_actionId);
271 if (__moveToCount > 0)
275 if (res != CANCEL_USER)
277 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_PARTIAL);
281 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
289 if (res != CANCEL_USER)
291 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_FAILURE);
295 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
299 TimerCancel(__moveToCount, res);
304 GlTimerBase::OnOpComplete(enum FileActionCompleteRes res)
306 AppLogDebug("ENTER");
307 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
308 pContentListener->ReSetTimerActive();
311 __pInvalidate->OnFileOpInvalidate(_actionId);
312 __pInvalidate->OnFileOpComplete(_actionId, res);
314 TimerComplete(__moveToCount, res);
319 GlTimerBase::SetActionMode(const enum FileActionMode actionId)
321 AppLogDebug("ENTER");
322 _actionId = actionId;
327 GlTimerBase::IsStarted(void)
329 AppLogDebug("ENTER");
334 GlTimerBase::Cancel(void)
336 AppLogDebug("ENTER");
339 __pMoveProBar->HideFileProgressingPopup();
340 __moveTimer.Cancel();
343 int scanCount = GetDirScanCount();
344 if ((scanCount > 0 && _actionId != FILE_ACTION_MOVE ) ||
345 (scanCount > 1 && _actionId == FILE_ACTION_MOVE ))
347 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
349 __pInvalidate->OnScanDirStart();
350 FileListPresentationModel::GetInstance()->ShowAnimation();
351 AlbumListPresentationModel::GetInstance()->ShowAnimation();
355 OnOpCancelled(CANCEL_SYS_ERROR);
362 GlTimerBase::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
364 AppLogDebug("ENTER");
366 if(keyEventInfo.GetKeyCode() == KEY_BACK)