For NSE_43972
[apps/osp/Gallery.git] / src / GlProgressBar.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                GlProgressBar.cpp
19  * @brief               This is the implementation file for GlProgressBar class.
20  */
21
22 #include <FApp.h>
23 #include <FUi.h>
24
25 #include "GlProgressBar.h"
26 #include "GlResourceManager.h"
27 #include "GlTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35
36 GlProgressBar::GlProgressBar(IActionEventListener* listener)
37         : __totalVal(1)
38         , __curVal(1)
39         , __pFileProgressingPopup(null)
40         , __pFileProgressingProgress(null)
41         , __pFileProgressingHeaderLabel(null)
42         , __pFileProgressingLabel(null)
43         , __pFileCounterLabel(null)
44         , __pFileProgressingCancelButton(null)
45         , __pActionListener(listener)
46 {
47         AppLogDebug("ENTER");
48         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
49 }
50
51 GlProgressBar::~GlProgressBar(void)
52 {
53         AppLogDebug("ENTER");
54         if (__pFileProgressingPopup != null)
55         {
56                 delete __pFileProgressingPopup;
57         }
58         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
59 }
60
61 void
62 GlProgressBar::HideFileProgressingPopup(void)
63 {
64         AppLogDebug("ENTER");
65         if (__pFileProgressingPopup != null && __pFileProgressingPopup->IsVisible())
66         {
67                 __pFileProgressingPopup->SetShowState(false);
68
69                 delete __pFileProgressingPopup;
70                 __pFileProgressingPopup = null;
71         }
72         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
73 }
74
75 result
76 GlProgressBar::CreateFileProgressingPopup(void)
77 {
78         AppLogDebug("ENTER");
79         __pFileProgressingPopup = new (std::nothrow) Popup();
80         result r = __pFileProgressingPopup->Construct(L"IDL_DEL_PROGRESSING_POPUP");
81
82         if (__pFileProgressingPopup != null && r == E_SUCCESS)
83         {
84                 __pFileProgressingCancelButton = static_cast<Button*>(__pFileProgressingPopup->GetControl(L"IDC_CANCEL_BUTTON", true));
85
86                 if (__pFileProgressingCancelButton != null)
87                 {
88                         __pFileProgressingCancelButton->SetActionId(IDA_PROGRESSBAR_CANCEL);
89                         __pFileProgressingCancelButton->AddActionEventListener(*__pActionListener);
90                         __pFileProgressingCancelButton->SetShowState(true);
91                 }
92
93                 __pFileProgressingProgress = static_cast<Progress*>(__pFileProgressingPopup->GetControl(L"IDC_PROGRESS_BAR", true));
94
95                 if (__pFileProgressingProgress != null)
96                 {
97                         __pFileProgressingProgress->SetName(L"IDC_ANIMATION_PROGRESS");
98                         __pFileProgressingProgress->SetValue(0);
99                 }
100
101                 __pFileProgressingHeaderLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_HEADER", true));
102
103                 if (__pFileProgressingHeaderLabel != null)
104                 {
105                         __pFileProgressingHeaderLabel->SetName(L"IDC_ANIMATION_HEADER");
106                         __pFileProgressingHeaderLabel->SetShowState(true);
107                 }
108
109                 __pFileProgressingLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_LABEL", true));
110
111                 if (__pFileProgressingLabel != null)
112                 {
113                         __pFileProgressingLabel->SetName(L"IDC_FILE_COUNT_LABEL");
114                         __pFileProgressingLabel->SetShowState(true);
115                 }
116
117                 __pFileCounterLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_COUNTER_LABEL", true));
118
119                 if (__pFileCounterLabel != null)
120                 {
121                         __pFileCounterLabel->SetText(L"");
122                         __pFileCounterLabel->SetTextColor(CUSTOM_COLOR_GREY);
123                         __pFileCounterLabel->SetShowState(true);
124                 }
125
126         }
127         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128         return r;
129 }
130
131 void
132 GlProgressBar::ShowFileProgressingPopup(const int val, enum FileActionMode action)
133 {
134         AppLogDebug("ENTER");
135         CreateFileProgressingPopup();
136
137         if (val > 0)
138         {
139                 __totalVal = val;
140         }
141         else
142         {
143                 __totalVal = 1;
144         }
145         __pFileProgressingProgress->SetRange(1, val);
146
147         if (__pFileProgressingPopup != null)
148         {
149                 if (__pFileProgressingHeaderLabel != null)
150                 {
151                         switch (action)
152                         {
153                         case FILE_ACTION_MOVE:
154                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_MOVING"));
155                         break;
156
157                         case FILE_ACTION_DELETE:
158                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_DELETING"));
159                         break;
160
161                         case FILE_ACTION_COPY:
162                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_COPYING_ING"));
163                         break;
164
165                         case FILE_ACTION_ROTATE:
166                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_PROCESSING"));
167                         break;
168
169                         default:
170                                 break;
171                         }
172
173                         __pFileProgressingHeaderLabel->Invalidate(true);
174                 }
175
176                 __pFileProgressingPopup->SetShowState(true);
177                 __pFileProgressingPopup->Show();
178         }
179         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
180 }
181
182 void
183 GlProgressBar::IncProgress(const int count)
184 {
185         AppLogDebug("ENTER");
186         String counter;
187         __curVal = count;
188         __pFileProgressingProgress->SetValue(count);
189
190         counter.Append(count);
191         counter.Append(L"/");
192         counter.Append(__totalVal);
193
194         if( __pFileCounterLabel != null )
195         {
196                 __pFileCounterLabel->SetText(counter);
197                 __pFileCounterLabel->Invalidate(true);
198         }
199
200         __pFileProgressingPopup->SetShowState(true);
201         __pFileProgressingPopup->Show();
202         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
203 }