merge with master
[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.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                GlTimerBase.cpp
19  * @brief               This is the source file for GlTimerBase class.
20  */
21
22 #include <FUi.h>
23
24 #include "GlProgressBar.h"
25 #include "GlTimerBase.h"
26 #include "GlTypes.h"
27
28 using namespace Tizen::Ui;
29
30 GlTimerBase::GlTimerBase(IFileOpInvalidateListener* invalidateListener, enum FileActionMode actionId)
31         : __pInvalidate(invalidateListener)
32         , __actionId(actionId)
33 {
34 }
35
36 GlTimerBase::~GlTimerBase(void)
37 {
38         AppLogDebug("ENTER");
39         __pInvalidate = null;
40         __moveTimer.Cancel();
41         delete __pContentIdList;
42         AppLogDebug("ENTER");
43 }
44
45 bool GlTimerBase::StartTimer(void)
46 {
47         AppLogDebug("ENTER");
48         __pContentIdList = TimerStart();
49         if (__pContentIdList != null && __pContentIdList->GetCount() > 0 )
50         {
51                 AppLogDebug("Starting timer");
52                 __pMoveProBar = new GlProgressBar(static_cast<IActionEventListener*>(this));
53                 __pMoveProBar->ShowFileProgressingPopup( __pContentIdList->GetCount(), __actionId );
54                 __moveToCount = 0;
55                 __moveTimer.Construct(*this);
56                 __moveTimer.Start(1);
57                 AppLogDebug("Returned true");
58                 return E_SUCCESS;
59         }
60         AppLogDebug("Returned false");
61         return E_FAILURE;
62 }
63
64 void GlTimerBase::CancelTimer(void)
65 {
66         AppLogDebug("ENTER");
67         __moveTimer.Cancel();
68         OnOpCancelled();
69         __moveToCount = 0;
70         AppLogDebug("EXIT");
71 }
72
73 void GlTimerBase::OnTimerExpired(Timer& timer)
74 {
75         AppLogDebug("ENTER");
76         if (&timer == &__moveTimer)
77         {
78                 AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
79                 if (__moveToCount < __pContentIdList->GetCount())
80                 {
81                         AppLogDebug("__pContentIdList count is %d", __pContentIdList->GetCount());
82                         ContentId* pContentId = static_cast<ContentId*>(__pContentIdList->GetAt(__moveToCount));
83                         if (pContentId != null)
84                         {
85                                 TimerExpired(*pContentId);
86                         }
87                         __moveToCount++;
88                         __pMoveProBar->IncProgress( __moveToCount );
89                         if (__pInvalidate)
90                         {
91                                 __pInvalidate->OnFileOpInvalidate(__actionId);
92                         }
93                         __moveTimer.Start(1);
94                 }
95                 else
96                 {
97                         __moveTimer.Cancel();
98                         OnOpComplete();
99                         __moveToCount = 0;
100                 }
101         }
102         AppLogDebug("EXIT");
103 }
104
105 void
106 GlTimerBase::OnActionPerformed(const Control& source, int actionId)
107 {
108         switch (actionId)
109         {
110         case ACTION_ID_PROGRESSBAR_CANCEL:
111         {
112                 CancelTimer();
113                 break;
114         }
115         default:
116                 break;
117         }
118 }
119
120 void GlTimerBase::OnOpCancelled(void)
121 {
122         AppLogDebug("ENTER");
123         if (__moveToCount > 0)
124         {
125                 OnOpComplete();
126         }
127         else
128         {
129                 __pMoveProBar->HideFileProgressingPopup();
130                 if (__pInvalidate)
131                 {
132                         __pInvalidate->OnFileOpInvalidate(__actionId);
133                         __pInvalidate->OnFileOpComplete(__actionId, true);
134                 }
135         }
136         AppLogDebug("EXIT");
137 }
138
139 void GlTimerBase::OnOpComplete(void)
140 {
141         AppLogDebug("ENTER");
142         __pMoveProBar->HideFileProgressingPopup();
143         if (__pInvalidate)
144         {
145                 __pInvalidate->OnFileOpInvalidate(__actionId);
146                 __pInvalidate->OnFileOpComplete(__actionId, true);
147         }
148         TimerComplete(__moveToCount);
149         AppLogDebug("EXIT");
150 }