Initialize Tizen 2.3
[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, IPropagatedKeyEventListener* propagatedListener)
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         , __pPropagatedListener(propagatedListener)
47 {
48         AppLogDebug("ENTER");
49         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
50 }
51
52 GlProgressBar::~GlProgressBar(void)
53 {
54         AppLogDebug("ENTER");
55         if (__pFileProgressingPopup != null)
56         {
57                 delete __pFileProgressingPopup;
58         }
59         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
60 }
61
62 void
63 GlProgressBar::HideFileProgressingPopup(void)
64 {
65         AppLogDebug("ENTER");
66         if (__pFileProgressingPopup != null && __pFileProgressingPopup->IsVisible())
67         {
68                 __pFileProgressingPopup->SetShowState(false);
69
70                 delete __pFileProgressingPopup;
71                 __pFileProgressingPopup = null;
72         }
73         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
74 }
75
76 result
77 GlProgressBar::CreateFileProgressingPopup(void)
78 {
79         AppLogDebug("ENTER");
80         __pFileProgressingPopup = new (std::nothrow) Popup();
81         result r = __pFileProgressingPopup->Construct(L"IDL_DEL_PROGRESSING_POPUP");
82
83         if (__pFileProgressingPopup != null && r == E_SUCCESS)
84         {
85
86                 __pFileProgressingPopup->SetPropagatedKeyEventListener(__pPropagatedListener);
87
88                 __pFileProgressingCancelButton = static_cast<Button*>(__pFileProgressingPopup->GetControl(L"IDC_CANCEL_BUTTON", true));
89
90                 if (__pFileProgressingCancelButton != null)
91                 {
92                         __pFileProgressingCancelButton->SetActionId(IDA_PROGRESSBAR_CANCEL);
93                         __pFileProgressingCancelButton->AddActionEventListener(*__pActionListener);
94                         __pFileProgressingCancelButton->SetShowState(true);
95                 }
96
97                 __pFileProgressingProgress = static_cast<Progress*>(__pFileProgressingPopup->GetControl(L"IDC_PROGRESS_BAR", true));
98
99                 if (__pFileProgressingProgress != null)
100                 {
101                         __pFileProgressingProgress->SetName(L"IDC_ANIMATION_PROGRESS");
102                         __pFileProgressingProgress->SetValue(0);
103                 }
104
105                 __pFileProgressingHeaderLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_HEADER", true));
106
107                 if (__pFileProgressingHeaderLabel != null)
108                 {
109                         __pFileProgressingHeaderLabel->SetName(L"IDC_ANIMATION_HEADER");
110                         __pFileProgressingHeaderLabel->SetShowState(true);
111                 }
112
113                 __pFileProgressingLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_LABEL", true));
114
115                 if (__pFileProgressingLabel != null)
116                 {
117                         __pFileProgressingLabel->SetName(L"IDC_FILE_COUNT_LABEL");
118                         __pFileProgressingLabel->SetShowState(true);
119                 }
120
121                 __pFileCounterLabel = static_cast<Label*>(__pFileProgressingPopup->GetControl(L"IDC_COUNTER_LABEL", true));
122
123                 if (__pFileCounterLabel != null)
124                 {
125                         __pFileCounterLabel->SetText(L"");
126                         __pFileCounterLabel->SetTextColor(CUSTOM_COLOR_GREY);
127                         __pFileCounterLabel->SetShowState(true);
128                 }
129
130         }
131         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
132         return r;
133 }
134
135 void
136 GlProgressBar::ShowFileProgressingPopup(const int val, enum FileActionMode action)
137 {
138         AppLogDebug("ENTER");
139         CreateFileProgressingPopup();
140
141         if (val > 0)
142         {
143                 __totalVal = val;
144         }
145         else
146         {
147                 __totalVal = 1;
148         }
149         __pFileProgressingProgress->SetRange(1, val);
150
151         if (__pFileProgressingPopup != null)
152         {
153                 if (__pFileProgressingHeaderLabel != null)
154                 {
155                         switch (action)
156                         {
157                         case FILE_ACTION_MOVE:
158                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_MOVING"));
159                         break;
160
161                         case FILE_ACTION_DELETE:
162                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_DELETING"));
163                         break;
164
165                         case FILE_ACTION_COPY:
166                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_COPYING_ING"));
167                         break;
168
169                         case FILE_ACTION_ROTATE:
170                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_PROCESSING"));
171                         break;
172
173                         default:
174                                 break;
175                         }
176
177                         __pFileProgressingHeaderLabel->Invalidate(true);
178                 }
179
180                 __pFileProgressingPopup->SetShowState(true);
181                 __pFileProgressingPopup->Show();
182         }
183         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
184 }
185
186 void
187 GlProgressBar::IncProgress(const int count)
188 {
189         AppLogDebug("ENTER");
190         String counter;
191         __curVal = count;
192         __pFileProgressingProgress->SetValue(count);
193
194         counter.Append(count);
195         counter.Append(L"/");
196         counter.Append(__totalVal);
197
198         if (__pFileCounterLabel != null)
199         {
200                 __pFileCounterLabel->SetText(counter);
201                 __pFileCounterLabel->Invalidate(true);
202         }
203
204         __pFileProgressingPopup->SetShowState(true);
205         __pFileProgressingPopup->Show();
206         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
207 }