resource id addition
[apps/native/sample/ImageFeatureManager.git] / project / src / GeneratePanel.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.tizenopensource.org/license
10 //
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.
16 //
17
18 #include "AppResourceId.h"
19 #include "GeneratePanel.h"
20 #include "MainForm.h"
21 #include "FileManagerForm.h"
22 #include <FSysEnvironment.h>
23
24 using namespace Tizen::Base;
25 using namespace Tizen::Graphics;
26 using namespace Tizen::Ui;
27 using namespace Tizen::Ui::Controls;
28 using namespace Tizen::Ui::Scenes;
29
30
31 GeneratePanel::GeneratePanel(void)
32     : __currentFeaturePath(Tizen::System::Environment::GetMediaPath() + "default.xdb")
33     , __currentImagePath(Tizen::System::Environment::GetMediaPath())
34 {
35 }
36
37 GeneratePanel::~GeneratePanel(void)
38 {
39 }
40
41 bool
42 GeneratePanel::Initialize()
43 {
44     Panel::Construct(IDC_GENERATION_MODE_PANEL);
45     return true;
46 }
47
48 result
49 GeneratePanel::OnInitializing(void)
50 {
51     result r = E_SUCCESS;
52
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));
56
57     Rectangle clienRect = pForm->GetClientAreaBounds();
58     this->SetBounds(clienRect);
59
60     pButton = static_cast<Button*>(GetControl(IDC_BUTTON_CHOOSE_IMAGE_FOLDER, true));
61     if (pButton)
62     {
63         pButton->SetActionId(ID_BUTTON_CHOOSE_IMAGE_FOLDER_PATH);
64         pButton->AddActionEventListener(*this);
65     }
66
67     pButton = static_cast<Button*>(GetControl(IDC_BUTTON_CHOOSE_FEATURE_SET_PATH, true));
68     if (pButton)
69     {
70         pButton->SetActionId(ID_BUTTON_CHOOSE_FEATURE_SET_PATH);
71         pButton->AddActionEventListener(*this);
72     }
73
74     return r;
75 }
76
77 result
78 GeneratePanel::OnTerminating(void)
79 {
80     result r = E_SUCCESS;
81     return r;
82 }
83
84
85 void
86 GeneratePanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
87 {
88     SceneManager* pSceneManager = SceneManager::GetInstance();
89     AppAssert(pSceneManager);
90
91     switch (actionId)
92     {
93     case ID_BUTTON_CHOOSE_FEATURE_SET_PATH:
94     {
95         pSceneManager->GoForward(
96                 ForwardSceneTransition("ChooseNewFeatureSetScene",
97                         SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
98                         SCENE_HISTORY_OPTION_ADD_HISTORY,
99                         SCENE_DESTROY_OPTION_KEEP),0);
100     }
101     break;
102
103     case ID_BUTTON_CHOOSE_IMAGE_FOLDER_PATH:
104     {
105         pSceneManager->GoForward(
106                 ForwardSceneTransition("ChooseImageScene",
107                         SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_IN,
108                         SCENE_HISTORY_OPTION_ADD_HISTORY,
109                         SCENE_DESTROY_OPTION_KEEP), 0);
110     }
111     break;
112     }
113 }
114
115
116 void
117 GeneratePanel::OnSceneActivatedN(
118         const Tizen::Ui::Scenes::SceneId& previousSceneId,
119         const Tizen::Ui::Scenes::SceneId& currentSceneId,
120         Tizen::Base::Collection::IList* pArgs)
121 {
122     if ((previousSceneId == "ChooseImageScene") && pArgs)
123     {
124         if (pArgs->GetCount() > 0)
125         {
126             __currentImagePath   = *(dynamic_cast<String*>(pArgs->GetAt(0)));
127         }
128     }
129     else if ((previousSceneId == "ChooseNewFeatureSetScene") && pArgs)
130     {
131         if (pArgs->GetCount() > 0)
132         {
133             __currentFeaturePath   = *(dynamic_cast<String*>(pArgs->GetAt(0)));
134         }
135     }
136
137     if (pArgs)
138     {
139         pArgs->RemoveAll(true);
140         delete pArgs;
141     }
142
143     Label* pLabel = null;
144     pLabel = static_cast<Label*>(GetControl(IDC_CREATE_FEATRUE_SET_LABEL, true));
145     if (pLabel)
146     {
147         pLabel->SetText(__currentFeaturePath);
148     }
149
150     pLabel = static_cast<Label*>(GetControl(IDC_CHOOSE_IMAGE_FOLDER_LABEL, true));
151     if (pLabel)
152     {
153         pLabel->SetText(__currentImagePath);
154     }
155
156 }
157
158 void
159 GeneratePanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
160         const Tizen::Ui::Scenes::SceneId& nextSceneId)
161 {
162 }
163
164 void
165 GeneratePanel::OnImageProcessed(int imNo, int total)
166 {
167     Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
168     MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
169
170     pForm->OnImageProcessed(imNo, total);
171 }
172
173 void
174 GeneratePanel::OnFinish(void)
175 {
176     Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
177     MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
178
179
180     result res = pForm->GetFeatureManager()->Flush(&__currentFeaturePath);
181
182     AppLog("Result:: %s %ls", GetErrorMessage(res), __currentFeaturePath.GetPointer());
183     pForm->OnFinish();
184 }
185
186 void
187 GeneratePanel::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
188 {
189         switch (requestId)
190         {
191     case GeneratePanel::REQUEST_GENERATE_FEATURE_SET:
192     {
193         Tizen::Ui::Controls::Frame *pFrame = Tizen::App::Application::GetInstance()->GetAppFrame()->GetFrame();
194         MainForm* pForm = static_cast<MainForm*>(pFrame->GetControl(IDF_FORM, true));
195         pForm->GetFeatureManager()->DeleteAllFeatures();
196         pForm->AppendImageFolder(__currentImagePath, this);
197         break;
198     }
199     default:
200         break;
201         }
202 }