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();
106 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
108 __pInvalidate->OnScanDirStart();
109 FileListPresentationModel::GetInstance()->ShowAnimation();
110 AlbumListPresentationModel::GetInstance()->ShowAnimation();
114 OnOpCancelled(CANCEL_USER);
118 __timerRes = CANCEL_BY_USER;
119 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
123 GlTimerBase::OnTimerScanDirComplete()
125 AppLogDebug("OnTimerScanDirComplete ENTER");
127 AlbumListPresentationModel::GetInstance()->RemoveTimerScanListener();
128 FileListPresentationModel::GetInstance()->StopAnimation();
129 AlbumListPresentationModel::GetInstance()->StopAnimation();
130 __pInvalidate->OnScanDirComplete();
134 AppLogDebug("CANCEL_SYS");
135 OnOpCancelled(CANCEL_SYS_ERROR);
138 AppLogDebug("CANCEL_BY_USER");
139 OnOpCancelled(CANCEL_USER);
142 AppLogDebug("TIMER_COMPLETE");
143 OnOpComplete(COMPLETE_SUCCESS);
148 AppLogDebug("ENTER");
152 GlTimerBase::OnTimerExpired(Timer& timer)
154 AppLogDebug("ENTER");
155 if (&timer == &__moveTimer)
157 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
158 if (__moveToCount < __pContentIdList->GetCount())
160 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
161 if (__pContentIdList->GetAt(__moveToCount) != null)
163 result r = TimerExpired(__pContentIdList->GetAt(__moveToCount));
166 if (r == E_STORAGE_FULL || r == E_IO)
168 __moveTimer.Cancel();
170 __timerRes = CANCEL_SYS;
171 __pMoveProBar->HideFileProgressingPopup();
172 int scanCount = GetDirScanCount();
175 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
177 __pInvalidate->OnScanDirStart();
178 FileListPresentationModel::GetInstance()->ShowAnimation();
179 AlbumListPresentationModel::GetInstance()->ShowAnimation();
183 MessageBox messageBox;
184 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_BODY_OPERATION_FAILED"),
185 MSGBOX_STYLE_NONE, 3000);
187 messageBox.ShowAndWait(modalResult);
188 OnOpCancelled(CANCEL_SYS_ERROR);
190 AppLogDebug("OnTimerExpired EXIT(%s)", GetErrorMessage(r));
193 //If the errors are file not found etc, skip this file and move to next.
197 __pMoveProBar->IncProgress(__moveToCount);
200 __pInvalidate->OnFileOpInvalidate(_actionId);
202 __moveTimer.Start(1);
207 __moveTimer.Cancel();
208 __pMoveProBar->HideFileProgressingPopup();
209 int scanCount = GetDirScanCount();
214 __timerRes = TIMER_COMPLETE;
215 OnOpComplete(COMPLETE_SUCCESS);
218 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
220 __pInvalidate->OnScanDirStart();
221 FileListPresentationModel::GetInstance()->ShowAnimation();
222 AlbumListPresentationModel::GetInstance()->ShowAnimation();
224 __timerRes = TIMER_COMPLETE;
228 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
232 GlTimerBase::OnActionPerformed(const Control& source, int actionId)
234 AppLogDebug("ENTER");
237 case IDA_PROGRESSBAR_CANCEL:
246 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
250 GlTimerBase::GetMovedCount() const
252 return __moveToCount;
256 GlTimerBase::OnOpCancelled(enum FileActionCancelRes res)
258 AppLogDebug("ENTER");
259 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
260 pContentListener->ReSetTimerActive();
263 __pInvalidate->OnFileOpInvalidate(_actionId);
265 if (__moveToCount > 0)
269 if (res != CANCEL_USER)
271 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_PARTIAL);
275 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
283 if (res != CANCEL_USER)
285 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_FAILURE);
289 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
293 TimerCancel(__moveToCount, res);
298 GlTimerBase::OnOpComplete(enum FileActionCompleteRes res)
300 AppLogDebug("ENTER");
301 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
302 pContentListener->ReSetTimerActive();
305 __pInvalidate->OnFileOpInvalidate(_actionId);
306 __pInvalidate->OnFileOpComplete(_actionId, res);
308 TimerComplete(__moveToCount, res);
313 GlTimerBase::SetActionMode(const enum FileActionMode actionId)
315 AppLogDebug("ENTER");
316 _actionId = actionId;
321 GlTimerBase::IsStarted(void)
323 AppLogDebug("ENTER");
328 GlTimerBase::Cancel(void)
330 AppLogDebug("ENTER");
333 __pMoveProBar->HideFileProgressingPopup();
334 __moveTimer.Cancel();
337 int scanCount = GetDirScanCount();
340 AlbumListPresentationModel::GetInstance()->AddTimerScanListener(this, scanCount);
342 __pInvalidate->OnScanDirStart();
343 FileListPresentationModel::GetInstance()->ShowAnimation();
344 AlbumListPresentationModel::GetInstance()->ShowAnimation();
348 OnOpCancelled(CANCEL_SYS_ERROR);
355 GlTimerBase::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
357 AppLogDebug("ENTER");
359 if(keyEventInfo.GetKeyCode() == KEY_BACK)