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.
20 #include "FileManagerForm.h"
21 #include "GeneratePanel.h"
22 #include "UpdatePanel.h"
24 using namespace Tizen::Base;
25 using namespace Tizen::App;
26 using namespace Tizen::Graphics;
27 using namespace Tizen::Ui;
28 using namespace Tizen::Ui::Controls;
29 using namespace Tizen::Ui::Scenes;
31 static const String SAMPLE_TITLE = L"IMAGE FEATURE MANAGER";
33 MainForm::MainForm(void)
34 : __headerTitle(SAMPLE_TITLE)
35 , __pRadioGroupMode(null)
36 , __pFeatureManager(null)
37 , __pMessagePopup(null)
38 , __pMessageLabel(null)
42 MainForm::~MainForm(void)
44 if (__pFeatureManager)
46 delete __pFeatureManager;
48 delete __pMessagePopup;
52 MainForm::Initialize(void)
54 Construct(L"IDF_FORM");
59 MainForm::OnInitializing(void)
63 SetFormBackEventListener(this);
65 CheckButton* pCheckButton = null;
67 __pRadioGroupMode = new RadioGroup();
68 __pRadioGroupMode->Construct();
70 pCheckButton = static_cast<CheckButton*>(GetControl(L"IDC_UPDATE_MODE_BUTTON", true));
73 pCheckButton->AddActionEventListener(*this);
74 pCheckButton->SetActionId(ID_BUTTON_UPDATE_MODE, 0, 0);
75 __pRadioGroupMode->Add(*pCheckButton);
78 pCheckButton = static_cast<CheckButton*>(GetControl(L"IDC_GENERATION_MODE_BUTTON", true));
82 pCheckButton->SetSelected(true);
83 pCheckButton->AddActionEventListener(*this);
84 pCheckButton->SetActionId(ID_BUTTON_GENERATE_MODE, 0, 0);
85 __pRadioGroupMode->Add(*pCheckButton);
88 Footer* pFooter = GetFooter();
89 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
90 pFooter->SetBackButton();
92 FooterItem pFooterItemSend;
93 pFooterItemSend.Construct(ID_FOOTER_ITEM_GENERATE);
94 pFooterItemSend.SetText(L"Generate");
95 pFooter->AddItem(pFooterItemSend);
96 pFooter->AddActionEventListener(*this);
99 __dbGen.SetListener(this);
101 __pFeatureManager = new Tizen::Uix::Vision::ImageFeatureManager();
102 __pFeatureManager->Construct();
104 __pMessagePopup = new Popup();
105 __pMessagePopup->Construct("IDC_MESSAGE_POPUP");
106 __pMessageLabel = static_cast<Label*>(__pMessagePopup->GetControl("IDC_LABEL_MASSEGE_TEXT", true));
108 __pContextMenu = new ContextMenu();
109 __pContextMenu->Construct(Point(50, 1200), CONTEXT_MENU_STYLE_LIST);
111 __pContextMenu->AddItem(L"Add Features", ID_CONTEXT_MENU_ADD);
112 __pContextMenu->AddItem(L"Delete Features", ID_CONTEXT_MENU_DELETE);
113 __pContextMenu->AddActionEventListener(*this);
115 Button* pButton = static_cast<Button*>(__pMessagePopup->GetControl("IDC_BUTTON_MESSAGE_CLOSE", true));
118 pButton->AddActionEventListener(*this);
119 pButton->SetActionId(ID_BUTTON_CLOSE_RESULTS);
126 MainForm::OnTerminating(void)
128 result r = E_SUCCESS;
133 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
135 SceneManager* pSceneManager = SceneManager::GetInstance();
136 AppAssert(pSceneManager);
140 case ID_BUTTON_GENERATE_MODE:
143 Footer* pFooter = GetFooter();
144 pFooter->RemoveAllItems();
145 pFooter->RemoveAllButtons();
148 FooterItem pFooterItemGenerate;
149 pFooterItemGenerate.Construct(ID_FOOTER_ITEM_GENERATE);
150 pFooterItemGenerate.SetText(L"Generate");
151 pFooter->AddItem(pFooterItemGenerate);
153 pFooter->SetBackButton();
154 pFooter->AddActionEventListener(*this);
156 __pFeatureManager->DeleteAllFeatures();
157 pSceneManager->GoForward(
158 ForwardSceneTransition("GenerationModeScene",
159 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
160 SCENE_HISTORY_OPTION_NO_HISTORY,
161 SCENE_DESTROY_OPTION_KEEP), null);
164 case ID_BUTTON_UPDATE_MODE:
166 Footer* pFooter = GetFooter();
167 pFooter->RemoveAllItems();
168 pFooter->RemoveAllButtons();
170 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
171 Tizen::Graphics::Bitmap* pNormalIcon = pAppResource->GetBitmapN(L"00_more_icon_normal.png");
172 Tizen::Graphics::Bitmap* pPressedIcon = pAppResource->GetBitmapN(L"00_more_icon_pressed.png");
173 Tizen::Graphics::Bitmap* pDisabledIcon = pAppResource->GetBitmapN(L"00_more_icon_disabled.png");
175 ButtonItem buttonItem;
176 buttonItem.Construct(BUTTON_ITEM_STYLE_ICON, ID_FOOTER_ITEM_SHOW_MENU);
177 buttonItem.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pNormalIcon);
178 buttonItem.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pPressedIcon);
179 buttonItem.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pDisabledIcon);
181 pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItem);
183 FooterItem pFooterItemUpdate;
184 pFooterItemUpdate.Construct(ID_FOOTER_ITEM_UPDATE);
185 pFooterItemUpdate.SetText(L"Update");
186 pFooter->AddItem(pFooterItemUpdate);
188 pFooter->SetBackButton();
189 pFooter->AddActionEventListener(*this);
191 __pFeatureManager->DeleteAllFeatures();
192 pSceneManager->GoForward(
193 ForwardSceneTransition("UpdateModeScene",
194 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
195 SCENE_HISTORY_OPTION_NO_HISTORY,
196 SCENE_DESTROY_OPTION_KEEP), null);
199 case ID_BUTTON_CLOSE_RESULTS:
200 __pMessagePopup->SetShowState(false);
203 case ID_FOOTER_ITEM_GENERATE:
205 Panel* pPanel = static_cast<Panel*>(this->GetControl("IDC_GENERATION_MODE_PANEL", true));
208 pPanel->SendUserEvent(GeneratePanel::REQUEST_GENERATE_FEATURE_SET, null);
212 case ID_FOOTER_ITEM_UPDATE:
214 Panel* pPanel = static_cast<Panel*>(this->GetControl("IDC_UPDATE_MODE_PANEL", true));
217 pPanel->SendUserEvent(UpdatePanel::REQUEST_UPDATE, null);
221 case ID_FOOTER_ITEM_SHOW_MENU:
223 __pContextMenu->SetShowState(true);
224 __pContextMenu->Show();
227 case ID_CONTEXT_MENU_ADD:
229 Panel* pPanel = static_cast<Panel*>(this->GetControl("IDC_UPDATE_MODE_PANEL", true));
232 pPanel->SendUserEvent(UpdatePanel::REQUEST_ADD, null);
236 case ID_CONTEXT_MENU_DELETE:
238 Panel* pPanel = static_cast<Panel*>(this->GetControl("IDC_UPDATE_MODE_PANEL", true));
241 pPanel->SendUserEvent(UpdatePanel::REQUEST_DELETE, null);
251 MainForm::AppendImageFolder(const Tizen::Base::String& imPath, IFeatureSetGeneratorListener* listener)
253 if (listener != null)
255 __dbGen.SetListener(listener);
259 __dbGen.SetListener(this);
261 __dbGen.SetImagePath(imPath);
262 __dbGen.SetFeatureManager(__pFeatureManager);
263 this->SetEnabled(false);
268 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
270 UiApp* pApp = UiApp::GetInstance();
276 MainForm::OnSceneActivatedN(
277 const Tizen::Ui::Scenes::SceneId& previousSceneId,
278 const Tizen::Ui::Scenes::SceneId& currentSceneId,
279 Tizen::Base::Collection::IList* pArgs)
284 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
285 const Tizen::Ui::Scenes::SceneId& nextSceneId)
290 MainForm::OnImageProcessed(int imNo, int total)
293 SceneManager* pSceneManager = SceneManager::GetInstance();
294 AppAssert(pSceneManager);
296 if (pSceneManager->GetCurrentSceneId() == "GenerationModeScene")
298 __headerTitle = "Generating... ";
300 else if (pSceneManager->GetCurrentSceneId() == "UpdateModeScene")
302 __headerTitle = "Updating... ";
305 __headerTitle.Append(Integer(imNo).ToString());
306 __headerTitle.Append('/');
307 __headerTitle.Append(Integer(total).ToString());
312 MainForm::OnFinish(void)
314 SendUserEvent(REQUEST_RESULT, 0);
318 MainForm::OnDraw(void)
320 Header* pHeader = GetHeader();
321 pHeader->SetTitleText(__headerTitle);
326 MainForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
332 __dbGen.GetResults(__resInfo);
333 this->SetEnabled(true);
334 this->RequestRedraw(true);
335 __headerTitle = SAMPLE_TITLE;
336 if (__resInfo.appendTime > 0)
338 if (__resInfo.appendedObjectsNumber != 0)
340 __pMessageLabel->SetText(
341 "\nTotal time: " + Integer(__resInfo.appendTime).ToString() + "ms" +
342 "\nAverage time: " + Integer(__resInfo.appendTime / __resInfo.appendedObjectsNumber).ToString() + " ms" +
343 "\nAdded images: " + Integer(__resInfo.appendedObjectsNumber).ToString() +
344 "\nRejected files: " + Integer(__resInfo.rejectedObjectsNumber).ToString() +
345 "\nTotal files count: " + Integer(__resInfo.totalObjectsNumber).ToString()
350 __pMessageLabel->SetText(
351 "\nTotal time: " + Integer(__resInfo.appendTime).ToString() + "ms" +
352 "\nAdded images: " + Integer(__resInfo.appendedObjectsNumber).ToString() +
353 "\nRejected files: " + Integer(__resInfo.rejectedObjectsNumber).ToString() +
354 "\nTotal files count: " + Integer(__resInfo.totalObjectsNumber).ToString()
358 __pMessagePopup->SetShowState(true);
359 __pMessagePopup->Show();
368 Tizen::Uix::Vision::ImageFeatureManager*
369 MainForm::GetFeatureManager(void)
371 return __pFeatureManager;