3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.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 AppSecureLog("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);
141 pForm->SetMenuVisibility(true);
145 else if (previousSceneId == "GenerationModeScene")
147 result res = pForm->GetFeatureManager()->Load(__currentFeaturePath);
148 AppSecureLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
149 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
150 pFooter->SetItemEnabled(0, false);
154 pForm->SetMenuVisibility(true);
158 else if (previousSceneId == "ManageScene")
160 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
162 Footer* pFooter = pForm->GetFooter();
163 pFooter->SetItemEnabled(0, true);
164 SendUserEvent(REQUEST_MESSAGE_AFTER_DELETE, null);
170 pArgs->RemoveAll(true);
175 Label* pLabel = null;
176 pLabel = static_cast<Label*>(GetControl(IDC_FEATURE_SET_PATH_LABEL, true));
179 pLabel->SetText(__currentFeaturePath);
183 if (__currentFeaturePath.IsEmpty())
185 pFooter->SetItemEnabled(0, false);
186 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
190 pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
195 UpdatePanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
196 const Tizen::Ui::Scenes::SceneId& nextSceneId)
201 UpdatePanel::OnImageProcessed(int imNo, int total)
203 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
204 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
205 pForm->OnImageProcessed(imNo, total);
210 UpdatePanel::OnFinish(void)
212 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
213 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
215 __currentImagePath = "";
216 Button* pButtonPath = static_cast<Button*>(GetControl(L"IDC_BUTTON_UPDATE_IMAGE_FOLDER", true));
219 pButtonPath->SetText(__currentImagePath);
222 if (pForm->GetFeatureManager()->GetTotalNumberOfFeatures() != __prevFeaturesCount)
224 Footer* pFooter = pForm->GetFooter();
225 pFooter->SetItemEnabled(0, true);
226 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
233 UpdatePanel::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
235 SceneManager* pSceneManager = SceneManager::GetInstance();
236 AppAssert(pSceneManager);
241 case UpdatePanel::REQUEST_MESSAGE_LOAD_FAILED:
246 msgBox.Construct("Error", "Can't load feature set.", MSGBOX_STYLE_OK, 5000);
247 msgBox.ShowAndWait(res);
250 case UpdatePanel::REQUEST_MESSAGE_AFTER_DELETE:
252 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
253 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
255 Tizen::Base::String message;
256 message.Format(80, L"Deleted %i features.", __prevFeaturesCount - pForm->GetFeatureManager()->GetTotalNumberOfFeatures());
261 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 5000);
262 msgBox.ShowAndWait(res);
264 __prevFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
267 case UpdatePanel::REQUEST_ADD:
269 pSceneManager->GoForward(
270 ForwardSceneTransition("ChooseImageScene",
271 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
272 SCENE_HISTORY_OPTION_ADD_HISTORY,
273 SCENE_DESTROY_OPTION_KEEP), /*pList*/null);
276 case UpdatePanel::REQUEST_DELETE:
278 pSceneManager->GoForward(
279 ForwardSceneTransition("ManageScene",
280 SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
281 SCENE_HISTORY_OPTION_ADD_HISTORY,
282 SCENE_DESTROY_OPTION_KEEP), null);
285 case UpdatePanel::REQUEST_UPDATE:
287 Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
288 MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
290 //Disabling update button
291 Footer* pFooter = pForm->GetFooter();
292 pFooter->SetItemEnabled(0, false);
297 result res = pForm->GetFeatureManager()->Flush(0);
298 AppSecureLog("Result:: on Flush %s", GetErrorMessage(res));
302 pForm->GetFeatureManager()->Load(__currentFeaturePath);
308 int currentFeaturesCount = pForm->GetFeatureManager()->GetTotalNumberOfFeatures();
310 message.Format(80, L"Feature set successfully updated.\nTotal features count: %i", currentFeaturesCount);
312 __prevFeaturesCount = currentFeaturesCount;
314 msgBox.Construct("Update", message, MSGBOX_STYLE_OK, 5000);
315 msgBox.ShowAndWait(res);
323 msgBox.Construct("Update", "Feature set failed to update.", MSGBOX_STYLE_OK, 5000);
324 msgBox.ShowAndWait(res);
326 pForm->GetFeatureManager()->Load(__currentFeaturePath);