d362bde0550e78f695d6dd6d0714b910cdf9f68b
[apps/osp/Gallery.git] / src / GlTimerBase.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                GlTimerBase.cpp
19  * @brief               This is the source file for GlTimerBase class.
20  */
21
22 #include <FBase.h>
23 #include <FUi.h>
24
25 #include "GlContentUpdateEventListener.h"
26 #include "GlProgressBar.h"
27 #include "GlTimerBase.h"
28 #include "GlTypes.h"
29
30 using namespace Tizen::Ui;
31 using namespace Tizen::Base::Runtime;
32
33 GlTimerBase::GlTimerBase(IFileOpInvalidateListener* invalidateListener, enum FileActionMode actionId)
34         : _actionId(actionId)
35         , __pContentIdList(null)
36         , __moveToCount(0)
37         , __pMoveProBar(null)
38         , __pInvalidate(invalidateListener)
39         , __isStarted(false)
40 {
41         AppLogDebug("ENTER");
42         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
43 }
44
45 GlTimerBase::~GlTimerBase(void)
46 {
47         AppLogDebug("ENTER");
48         __pInvalidate = null;
49         if (__pContentIdList != null && __pContentIdList->GetCount() > 0 && __isStarted)
50         {
51                 __moveTimer.Cancel();
52                 __isStarted = false;
53         }
54         delete __pContentIdList;
55         if (__pMoveProBar)
56         {
57                 __pMoveProBar->HideFileProgressingPopup();
58                 delete __pMoveProBar;
59         }
60         AppLogDebug("ENTER");
61 }
62
63 bool
64 GlTimerBase::StartTimer(void)
65 {
66         AppLogDebug("ENTER");
67         __pContentIdList = TimerStart();
68         if (__pContentIdList != null && __pContentIdList->GetCount() > 0)
69         {
70                 AppLogDebug("Starting timer");
71                 __pMoveProBar = new (std::nothrow) GlProgressBar(static_cast<IActionEventListener*>(this));
72                 __pMoveProBar->ShowFileProgressingPopup(__pContentIdList->GetCount(), _actionId);
73                 __moveToCount = 0;
74                 __moveTimer.Construct(*this);
75                 __moveTimer.Start(1);
76                 __isStarted = true;
77                 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
78                 pContentListener->RemoveContentListener();
79                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
80                 return E_SUCCESS;
81         }
82         AppLogDebug("EXIT1(%s)", GetErrorMessage(GetLastResult()));
83         return E_FAILURE;
84 }
85
86 void
87 GlTimerBase::CancelTimer(void)
88 {
89         AppLogDebug("ENTER");
90         __moveTimer.Cancel();
91         __isStarted = false;
92         OnOpCancelled(CANCEL_USER);
93         __moveToCount = 0;
94         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
95 }
96
97 void
98 GlTimerBase::OnTimerExpired(Timer& timer)
99 {
100         AppLogDebug("ENTER");
101         if (&timer == &__moveTimer)
102         {
103                 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
104                 if (__moveToCount < __pContentIdList->GetCount())
105                 {
106                         AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
107                         if (__pContentIdList->GetAt(__moveToCount) != null)
108                         {
109                                 result r = TimerExpired(__pContentIdList->GetAt(__moveToCount));
110                                 if (IsFailed(r))
111                                 {
112                                         AppLogDebug("OnTimerExpired EXIT(%s)", GetErrorMessage(r));
113                                         OnOpCancelled(CANCEL_SYS_ERROR);
114                                         return;
115                                 }
116                         }
117                         __moveToCount++;
118                         __pMoveProBar->IncProgress(__moveToCount);
119                         if (__pInvalidate)
120                         {
121                                 __pInvalidate->OnFileOpInvalidate(_actionId);
122                         }
123                         __moveTimer.Start(1);
124                         __isStarted = true;
125                 }
126                 else
127                 {
128                         __moveTimer.Cancel();
129                         __isStarted = false;
130                         OnOpComplete(COMPLETE_SUCCESS);
131                         __moveToCount = 0;
132                 }
133         }
134         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
135 }
136
137 void
138 GlTimerBase::OnActionPerformed(const Control& source, int actionId)
139 {
140         AppLogDebug("ENTER");
141         switch (actionId)
142         {
143         case IDA_PROGRESSBAR_CANCEL:
144         {
145                 CancelTimer();
146         }
147         break;
148
149         default:
150                 break;
151         }
152         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
153 }
154
155 int GlTimerBase::GetMovedCount() const
156 {
157         return __moveToCount;
158 }
159
160 void GlTimerBase::OnOpCancelled(enum FileActionCancelRes res)
161 {
162         AppLogDebug("ENTER");
163         __pMoveProBar->HideFileProgressingPopup();
164         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
165         pContentListener->AddContentListener();
166         if (__pInvalidate)
167         {
168                 __pInvalidate->OnFileOpInvalidate(_actionId);
169         }
170         if (__moveToCount > 0)
171         {
172                 if (__pInvalidate)
173                 {
174                         if (res != CANCEL_USER)
175                         {
176                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_PARTIAL);
177                         }
178                         else
179                         {
180                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
181                         }
182                 }
183         }
184         else
185         {
186                 if (__pInvalidate)
187                 {
188                         if (res != CANCEL_USER)
189                         {
190                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_FAILURE);
191                         }
192                         else
193                         {
194                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
195                         }
196                 }
197         }
198         TimerCancel(__moveToCount, res);
199         AppLogDebug("EXIT");
200 }
201
202 void GlTimerBase::OnOpComplete(enum FileActionCompleteRes res)
203 {
204         AppLogDebug("ENTER");
205         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
206         pContentListener->AddContentListener();
207         __pMoveProBar->HideFileProgressingPopup();
208         if (__pInvalidate)
209         {
210                 __pInvalidate->OnFileOpInvalidate(_actionId);
211                 __pInvalidate->OnFileOpComplete(_actionId, res);
212         }
213         TimerComplete(__moveToCount, res);
214         AppLogDebug("EXIT");
215 }
216
217 void GlTimerBase::SetActionMode(const enum FileActionMode actionId)
218 {
219         _actionId = actionId;
220 }
221
222
223 bool GlTimerBase::IsStarted(void)
224 {
225         return __isStarted;
226 }
227
228 void GlTimerBase::Cancel(void)
229 {
230         if ( __isStarted )
231         {
232                 __pMoveProBar->HideFileProgressingPopup();
233                 __moveTimer.Cancel();
234                 __isStarted = false;
235         }
236
237 }