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 "AppResourceId.h"
19 #include "UpdatePanel.h"
20 #include "FileManagerForm.h"
23 using namespace Tizen::Base;
24 using namespace Tizen::Graphics;
25 using namespace Tizen::Ui;
26 using namespace Tizen::Ui::Controls;
27 using namespace Tizen::Ui::Scenes;
30 UpdatePanel::UpdatePanel(void)
31 : __currentFeaturePath("")
32 , __currentImagePath("")
33 , __prevFeaturesCount(0)
37 UpdatePanel::~UpdatePanel(void)
42 UpdatePanel::Initialize()
44 Panel::Construct(IDC_UPDATE_MODE_PANEL);
49 UpdatePanel::OnInitializing(void)
53 Button *pButton = null;
54 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
55 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
57 Rectangle clienRect = pForm->GetClientAreaBounds();
58 this->SetBounds(clienRect);
60 pButton = static_cast<Button*>(GetControl(IDC_BUTTON_LOAD_FEATURE_SET, true));
63 pButton->SetActionId(ID_BUTTON_LOAD_FEATURE_SET);
64 pButton->AddActionEventListener(*this);
71 UpdatePanel::OnTerminating(void)
78 UpdatePanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
80 SceneManager* pSceneManager = SceneManager::GetInstance();
81 AppAssert(pSceneManager);
85 case ID_BUTTON_LOAD_FEATURE_SET:
87 pSceneManager->GoForward(
88 ForwardSceneTransition("ChooseExistingFeatureSetScene",
89 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
90 SCENE_HISTORY_OPTION_ADD_HISTORY,
91 SCENE_DESTROY_OPTION_KEEP), 0);
99 UpdatePanel::OnSceneActivatedN(
100 const Tizen::Ui::Scenes::SceneId& previousSceneId,
101 const Tizen::Ui::Scenes::SceneId& currentSceneId,
102 Tizen::Base::Collection::IList* pArgs)
105 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
106 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
107 Footer* pFooter = pForm->GetFooter();
109 if ((previousSceneId == "ChooseImageScene") && pArgs)
111 if (pArgs->GetCount() > 0)
113 __currentImagePath = *(dynamic_cast<String*>(pArgs->GetAt(0)));
114 pForm->AppendImageFolder(__currentImagePath, this);
116 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
118 Footer* pFooter = pForm->GetFooter();
119 pFooter->SetItemEnabled(0, true);
123 else if ((previousSceneId == "ChooseExistingFeatureSetScene") && pArgs)
125 if (pArgs->GetCount() > 0)
127 __currentFeaturePath = *(dynamic_cast<String*>(pArgs->GetAt(0)));
129 result res = pForm->GetFeatureManager()->Load(__currentFeaturePath);
130 AppLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
134 __currentFeaturePath = "";
135 SendUserEvent(REQUEST_MESSAGE_LOAD_FAILED, null);
139 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
140 pFooter->SetItemEnabled(0, false);
144 else if (previousSceneId == "GenerationModeScene")
146 result res = pForm->GetFeatureManager()->Load(__currentFeaturePath);
147 AppLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
148 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
149 pFooter->SetItemEnabled(0, false);
152 else if (previousSceneId == "ManageScene")
154 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
156 Footer* pFooter = pForm->GetFooter();
157 pFooter->SetItemEnabled(0, true);
158 SendUserEvent(REQUEST_MESSAGE_AFTER_DELETE, null);
164 pArgs->RemoveAll(true);
169 Label* pLabel = null;
170 pLabel = static_cast<Label*>(GetControl(IDC_FEATURE_SET_PATH_LABEL, true));
173 pLabel->SetText(__currentFeaturePath);
177 if (__currentFeaturePath.IsEmpty())
179 pFooter->SetItemEnabled(0, false);
180 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
184 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
189 UpdatePanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
190 const Tizen::Ui::Scenes::SceneId& nextSceneId)
195 UpdatePanel::OnImageProcessed(int imNo, int total)
197 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
198 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
199 pForm->OnImageProcessed(imNo, total);
204 UpdatePanel::OnFinish(void)
206 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
207 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
209 __currentImagePath = "";
210 Button* pButtonPath = static_cast<Button*>(GetControl(L"IDC_BUTTON_UPDATE_IMAGE_FOLDER", true));
213 pButtonPath->SetText(__currentImagePath);
216 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
218 Footer* pFooter = pForm->GetFooter();
219 pFooter->SetItemEnabled(0, true);
220 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
227 UpdatePanel::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
229 SceneManager* pSceneManager = SceneManager::GetInstance();
230 AppAssert(pSceneManager);
235 case UpdatePanel::REQUEST_MESSAGE_LOAD_FAILED:
240 msgBox.Construct("Error", "Can't load feature set.", MSGBOX_STYLE_OK, 0);
241 msgBox.ShowAndWait(res);
244 case UpdatePanel::REQUEST_MESSAGE_AFTER_DELETE:
246 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
247 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
249 Tizen::Base::String message;
250 message.Format(80, L"Deleted %i features.", __prevFeaturesCount - pForm->GetFeatureManager()->GetTotalNumberOfFeatures());
255 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 0);
256 msgBox.ShowAndWait(res);
258 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
261 case UpdatePanel::REQUEST_ADD:
263 pSceneManager->GoForward(
264 ForwardSceneTransition("ChooseImageScene",
265 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
266 SCENE_HISTORY_OPTION_ADD_HISTORY,
267 SCENE_DESTROY_OPTION_KEEP), /*pList*/null);
270 case UpdatePanel::REQUEST_DELETE:
272 pSceneManager->GoForward(
273 ForwardSceneTransition("ManageScene",
274 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
275 SCENE_HISTORY_OPTION_ADD_HISTORY,
276 SCENE_DESTROY_OPTION_KEEP), null);
279 case UpdatePanel::REQUEST_UPDATE:
281 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
282 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
284 //Disabling update button
285 Footer* pFooter = pForm->GetFooter();
286 pFooter->SetItemEnabled(0, false);
288 result res = pForm->GetFeatureManager()->Flush(0);
289 AppLog("Result:: on Flush %s", GetErrorMessage(res));
293 pForm->GetFeatureManager()->Load(__currentFeaturePath);
299 int currentFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
301 message.Format(80, L"Feature set successfully updated.\nTotal features count: %i", currentFeaturesCount);
303 __prevFeaturesCount = currentFeaturesCount;
305 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 0);
306 msgBox.ShowAndWait(res);
314 msgBox.Construct("Update", "Feature set failed to update.", MSGBOX_STYLE_OK, 0);
315 msgBox.ShowAndWait(res);
317 pForm->GetFeatureManager()->Load(__currentFeaturePath);