3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "UpdatePanel.h"
19 #include "FileManagerForm.h"
22 using namespace Tizen::Base;
23 using namespace Tizen::Graphics;
24 using namespace Tizen::Ui;
25 using namespace Tizen::Ui::Controls;
26 using namespace Tizen::Ui::Scenes;
29 UpdatePanel::UpdatePanel(void)
30 : __currentFeaturePath("")
31 , __currentImagePath("")
32 , __prevFeaturesCount(0)
36 UpdatePanel::~UpdatePanel(void)
41 UpdatePanel::Initialize()
43 Panel::Construct(L"IDC_UPDATE_MODE_PANEL");
48 UpdatePanel::OnInitializing(void)
52 Button *pButton = null;
53 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
54 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
56 Rectangle clienRect = pForm->GetClientAreaBounds();
57 this->SetBounds(clienRect);
59 pButton = static_cast<Button*>(GetControl(L"IDC_BUTTON_LOAD_FEATURE_SET", true));
62 pButton->SetActionId(ID_BUTTON_LOAD_FEATURE_SET);
63 pButton->AddActionEventListener(*this);
70 UpdatePanel::OnTerminating(void)
77 UpdatePanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
79 SceneManager* pSceneManager = SceneManager::GetInstance();
80 AppAssert(pSceneManager);
84 case ID_BUTTON_LOAD_FEATURE_SET:
86 pSceneManager->GoForward(
87 ForwardSceneTransition("ChooseExistingFeatureSetScene",
88 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
89 SCENE_HISTORY_OPTION_ADD_HISTORY,
90 SCENE_DESTROY_OPTION_KEEP), 0);
98 UpdatePanel::OnSceneActivatedN(
99 const Tizen::Ui::Scenes::SceneId& previousSceneId,
100 const Tizen::Ui::Scenes::SceneId& currentSceneId,
101 Tizen::Base::Collection::IList* pArgs)
104 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
105 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
106 Footer* pFooter = pForm->GetFooter();
108 if ((previousSceneId == "ChooseImageScene") && pArgs)
110 if (pArgs->GetCount() > 0)
112 __currentImagePath = *(dynamic_cast<String*>(pArgs->GetAt(0)));
113 pForm->AppendImageFolder(__currentImagePath, this);
115 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
117 Footer* pFooter = pForm->GetFooter();
118 pFooter->SetItemEnabled(0, true);
122 else if ((previousSceneId == "ChooseExistingFeatureSetScene") && pArgs)
124 if (pArgs->GetCount() > 0)
126 __currentFeaturePath = *(dynamic_cast<String*>(pArgs->GetAt(0)));
128 result res = pForm->GetFeatureManager()->Load(__currentFeaturePath);
129 AppLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
133 __currentFeaturePath = "";
134 SendUserEvent(REQUEST_MESSAGE_LOAD_FAILED, null);
138 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
139 pFooter->SetItemEnabled(0, false);
143 else if (previousSceneId == "GenerationModeScene")
145 result res = pForm->GetFeatureManager()->Load(__currentFeaturePath);
146 AppLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
147 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
148 pFooter->SetItemEnabled(0, false);
151 else if (previousSceneId == "ManageScene")
153 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
155 Footer* pFooter = pForm->GetFooter();
156 pFooter->SetItemEnabled(0, true);
157 SendUserEvent(REQUEST_MESSAGE_AFTER_DELETE, null);
163 pArgs->RemoveAll(true);
168 Label* pLabel = null;
169 pLabel = static_cast<Label*>(GetControl(L"IDC_FEATURE_SET_PATH_LABEL", true));
172 pLabel->SetText(__currentFeaturePath);
176 if (__currentFeaturePath.IsEmpty())
178 pFooter->SetItemEnabled(0, false);
179 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
183 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
188 UpdatePanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
189 const Tizen::Ui::Scenes::SceneId& nextSceneId)
194 UpdatePanel::OnImageProcessed(int imNo, int total)
196 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
197 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
198 pForm->OnImageProcessed(imNo, total);
203 UpdatePanel::OnFinish(void)
205 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
206 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
208 __currentImagePath = "";
209 Button* pButtonPath = static_cast<Button*>(GetControl(L"IDC_BUTTON_UPDATE_IMAGE_FOLDER", true));
212 pButtonPath->SetText(__currentImagePath);
215 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
217 Footer* pFooter = pForm->GetFooter();
218 pFooter->SetItemEnabled(0, true);
219 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
226 UpdatePanel::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
228 SceneManager* pSceneManager = SceneManager::GetInstance();
229 AppAssert(pSceneManager);
234 case UpdatePanel::REQUEST_MESSAGE_LOAD_FAILED:
239 msgBox.Construct("Error", "Can't load feature set.", MSGBOX_STYLE_OK, 0);
240 msgBox.ShowAndWait(res);
243 case UpdatePanel::REQUEST_MESSAGE_AFTER_DELETE:
245 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
246 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
248 Tizen::Base::String message;
249 message.Format(80, L"Deleted %i features.", __prevFeaturesCount - pForm->GetFeatureManager()->GetTotalNumberOfFeatures());
254 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 0);
255 msgBox.ShowAndWait(res);
257 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
260 case UpdatePanel::REQUEST_ADD:
262 pSceneManager->GoForward(
263 ForwardSceneTransition("ChooseImageScene",
264 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
265 SCENE_HISTORY_OPTION_ADD_HISTORY,
266 SCENE_DESTROY_OPTION_KEEP), /*pList*/null);
269 case UpdatePanel::REQUEST_DELETE:
271 pSceneManager->GoForward(
272 ForwardSceneTransition("ManageScene",
273 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
274 SCENE_HISTORY_OPTION_ADD_HISTORY,
275 SCENE_DESTROY_OPTION_KEEP), null);
278 case UpdatePanel::REQUEST_UPDATE:
280 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
281 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(L"IDF_FORM", true));
283 //Disabling update button
284 Footer* pFooter = pForm->GetFooter();
285 pFooter->SetItemEnabled(0, false);
287 result res = pForm->GetFeatureManager()->Flush(0);
288 AppLog("Result:: on Flush %s", GetErrorMessage(res));
292 pForm->GetFeatureManager()->Load(__currentFeaturePath);
298 int currentFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
300 message.Format(80, L"Feature set successfully updated.\nTotal features count: %i", currentFeaturesCount);
302 __prevFeaturesCount = currentFeaturesCount;
304 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 0);
305 msgBox.ShowAndWait(res);
313 msgBox.Construct("Update", "Feature set failed to update.", MSGBOX_STYLE_OK, 0);
314 msgBox.ShowAndWait(res);
316 pForm->GetFeatureManager()->Load(__currentFeaturePath);