Rename feature added
[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.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                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         , __pFileProgressingCancelButton(null)
44         , __pActionListener(listener)
45 {
46         AppLogDebug("ENTER");
47         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
48 }
49
50 GlProgressBar::~GlProgressBar(void)
51 {
52         AppLogDebug("ENTER");
53         if (__pFileProgressingPopup != null)
54         {
55                 delete __pFileProgressingPopup;
56         }
57         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
58 }
59
60 void
61 GlProgressBar::HideFileProgressingPopup(void)
62 {
63         AppLogDebug("ENTER");
64         if (__pFileProgressingPopup != null && __pFileProgressingPopup->IsVisible())
65         {
66                 __pFileProgressingPopup->SetShowState(false);
67
68                 delete __pFileProgressingPopup;
69                 __pFileProgressingPopup = null;
70         }
71         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72 }
73
74 result
75 GlProgressBar::CreateFileProgressingPopup(void)
76 {
77         AppLogDebug("ENTER");
78         __pFileProgressingPopup = new (std::nothrow) Popup();
79         result r = __pFileProgressingPopup->Construct(L"IDL_DEL_PROGRESSING_POPUP");
80
81         if (__pFileProgressingPopup != null && r == E_SUCCESS)
82         {
83                 __pFileProgressingCancelButton = static_cast< Button* >(__pFileProgressingPopup->GetControl(L"IDC_CANCEL_BUTTON", true));
84
85                 if (__pFileProgressingCancelButton != null)
86                 {
87                         __pFileProgressingCancelButton->SetActionId(ACTION_ID_PROGRESSBAR_CANCEL);
88                         __pFileProgressingCancelButton->AddActionEventListener(*__pActionListener);
89                         __pFileProgressingCancelButton->SetShowState(true);
90                 }
91
92                 __pFileProgressingProgress = static_cast< Progress* >(__pFileProgressingPopup->GetControl(L"IDC_PROGRESS_BAR", true));
93
94                 if (__pFileProgressingProgress != null)
95                 {
96                         __pFileProgressingProgress->SetName(L"IDC_ANIMATION_PROGRESS");
97                         __pFileProgressingProgress->SetValue(0);
98                 }
99
100                 __pFileProgressingHeaderLabel = static_cast< Label* >(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_HEADER", true));
101
102                 if (__pFileProgressingHeaderLabel != null)
103                 {
104                         __pFileProgressingHeaderLabel->SetName(L"IDC_ANIMATION_HEADER");
105                         __pFileProgressingHeaderLabel->SetShowState(true);
106                 }
107
108                 __pFileProgressingLabel = static_cast< Label* >(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_LABEL", true));
109
110                 if (__pFileProgressingLabel != null)
111                 {
112                         __pFileProgressingLabel->SetName(L"IDC_FILE_COUNT_LABEL");
113                         __pFileProgressingLabel->SetShowState(true);
114                 }
115
116         }
117         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
118         return r;
119 }
120
121 void
122 GlProgressBar::ShowFileProgressingPopup(int val, enum FileActionMode action)
123 {
124         AppLogDebug("ENTER");
125         CreateFileProgressingPopup();
126
127         if (val > 0)
128         {
129                 __totalVal = val;
130         }
131         else
132         {
133                 __totalVal = 1;
134         }
135         __pFileProgressingProgress->SetRange(1, val);
136
137         if (__pFileProgressingPopup != null)
138         {
139                 if (__pFileProgressingHeaderLabel != null)
140                 {
141                         switch (action)
142                         {
143                         case FILE_MOVE_ACTION:
144                                 __pFileProgressingHeaderLabel->SetText(ResourceManager::GetString(L"IDS_COM_POP_MOVING"));
145                                 break;
146                         case FILE_DELETE_ACTION:
147                                 __pFileProgressingHeaderLabel->SetText(L"Deleting...");
148                                 break;
149                         default:
150                                 break;
151                         }
152
153                         __pFileProgressingHeaderLabel->Invalidate(true);
154                 }
155
156                 __pFileProgressingPopup->SetShowState(true);
157                 __pFileProgressingPopup->Show();
158         }
159         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
160 }
161
162 void
163 GlProgressBar::IncProgress(int count)
164 {
165         AppLogDebug("ENTER");
166         __curVal = count;
167         __pFileProgressingProgress->SetValue( count );
168         __pFileProgressingPopup->SetShowState(true);
169         __pFileProgressingPopup->Show();
170         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
171 }