Removed warning
[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                                 static_cast<IPropagatedKeyEventListener*>(this));
73                 __pMoveProBar->ShowFileProgressingPopup(__pContentIdList->GetCount(), _actionId);
74                 __moveToCount = 0;
75                 __moveTimer.Construct(*this);
76                 __moveTimer.Start(1);
77                 __isStarted = true;
78                 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
79                 pContentListener->RemoveContentListener();
80                 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
81                 return E_SUCCESS;
82         }
83         AppLogDebug("EXIT1(%s)", GetErrorMessage(GetLastResult()));
84         return E_FAILURE;
85 }
86
87 void
88 GlTimerBase::CancelTimer(void)
89 {
90         AppLogDebug("ENTER");
91         __moveTimer.Cancel();
92         __isStarted = false;
93         OnOpCancelled(CANCEL_USER);
94         __moveToCount = 0;
95         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
96 }
97
98 void
99 GlTimerBase::OnTimerExpired(Timer& timer)
100 {
101         AppLogDebug("ENTER");
102         if (&timer == &__moveTimer)
103         {
104                 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
105                 if (__moveToCount < __pContentIdList->GetCount())
106                 {
107                         AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
108                         if (__pContentIdList->GetAt(__moveToCount) != null)
109                         {
110                                 TimerExpired(__pContentIdList->GetAt(__moveToCount));
111                         }
112                         ++__moveToCount;
113                         __pMoveProBar->IncProgress(__moveToCount);
114                         if (__pInvalidate)
115                         {
116                                 __pInvalidate->OnFileOpInvalidate(_actionId);
117                         }
118                         __moveTimer.Start(1);
119                         __isStarted = true;
120                 }
121                 else
122                 {
123                         __moveTimer.Cancel();
124                         __isStarted = false;
125                         OnOpComplete(COMPLETE_SUCCESS);
126                         __moveToCount = 0;
127                 }
128         }
129         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
130 }
131
132 void
133 GlTimerBase::OnActionPerformed(const Control& source, int actionId)
134 {
135         AppLogDebug("ENTER");
136         switch (actionId)
137         {
138         case IDA_PROGRESSBAR_CANCEL:
139         {
140                 CancelTimer();
141         }
142         break;
143
144         default:
145                 break;
146         }
147         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
148 }
149
150 int
151 GlTimerBase::GetMovedCount() const
152 {
153         return __moveToCount;
154 }
155
156 void
157 GlTimerBase::OnOpCancelled(enum FileActionCancelRes res)
158 {
159         AppLogDebug("ENTER");
160         __pMoveProBar->HideFileProgressingPopup();
161         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
162         pContentListener->AddContentListener();
163         if (__pInvalidate)
164         {
165                 __pInvalidate->OnFileOpInvalidate(_actionId);
166         }
167         if (__moveToCount > 0)
168         {
169                 if (__pInvalidate)
170                 {
171                         if (res != CANCEL_USER)
172                         {
173                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_PARTIAL);
174                         }
175                         else
176                         {
177                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
178                         }
179                 }
180         }
181         else
182         {
183                 if (__pInvalidate)
184                 {
185                         if (res != CANCEL_USER)
186                         {
187                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SYS_FAILURE);
188                         }
189                         else
190                         {
191                                 __pInvalidate->OnFileOpComplete(_actionId, COMPLETE_SUCCESS);
192                         }
193                 }
194         }
195         TimerCancel(__moveToCount, res);
196         AppLogDebug("EXIT");
197 }
198
199 void
200 GlTimerBase::OnOpComplete(enum FileActionCompleteRes res)
201 {
202         AppLogDebug("ENTER");
203         ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
204         pContentListener->AddContentListener();
205         __pMoveProBar->HideFileProgressingPopup();
206         if (__pInvalidate)
207         {
208                 __pInvalidate->OnFileOpInvalidate(_actionId);
209                 __pInvalidate->OnFileOpComplete(_actionId, res);
210         }
211         TimerComplete(__moveToCount, res);
212         AppLogDebug("EXIT");
213 }
214
215 void
216 GlTimerBase::SetActionMode(const enum FileActionMode actionId)
217 {
218         _actionId = actionId;
219 }
220
221 bool
222 GlTimerBase::IsStarted(void)
223 {
224         return __isStarted;
225 }
226
227 void
228 GlTimerBase::Cancel(void)
229 {
230         if (__isStarted)
231         {
232                 ContentUpdateEventListener* pContentListener = ContentUpdateEventListener::GetInstance();
233                 pContentListener->AddContentListener();
234                 __pMoveProBar->HideFileProgressingPopup();
235                 __moveTimer.Cancel();
236                 __isStarted = false;
237         }
238 }
239
240 bool
241 GlTimerBase::OnKeyReleased(Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
242 {
243         AppLogDebug("ENTER");
244
245         if(keyEventInfo.GetKeyCode() == KEY_BACK)
246         {
247                 CancelTimer();
248         }
249         return true;
250 }