Flora license update
[apps/osp/Home.git] / src / HmHomeApp.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        HmHomeApp.cpp
19  * @brief       Keeps implementation of UiApp derived class.
20  */
21
22 #include <FBase.h>
23 #include <FUi.h>
24 #include "HmHomeApp.h"
25 #include "HmHomeForm.h"
26 #include "HmMainFrame.h"
27 #include "HmHomePresentationModel.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35
36
37 HomeApp::HomeApp(void)
38         : __presentationModelInitialized(false)
39         , __pHomeForm(null)
40         , __pPresentationModel(null)
41 {
42         //No implementation needed
43 }
44
45 HomeApp::~HomeApp(void)
46 {
47         //No implementation needed
48 }
49
50 UiApp*
51 HomeApp::CreateInstance(void)
52 {
53         // Create the instance through the constructor.
54         return new (std::nothrow) HomeApp();
55 }
56
57 bool
58 HomeApp::OnAppInitialized(void)
59 {
60         __pHomeForm = null;
61         MainFrame* pMainFrame = null;
62         bool retVal = true;
63         result r = E_SUCCESS;
64         // Create a Frame
65         pMainFrame = new (std::nothrow) MainFrame();
66         r = pMainFrame->Construct();
67         TryCatch(r == E_SUCCESS, retVal = false, " pHmMainFrame.>Construct() failed with error %s", GetErrorMessage(r));
68         r = AddFrame(*pMainFrame);
69         TryCatch(r == E_SUCCESS, retVal = false;
70                          delete pMainFrame;
71                          pMainFrame = null, "AddFrame(*pHmMainFrame. failed with error %s", GetErrorMessage(r));
72         // Create a form
73         __pHomeForm = new (std::nothrow) HomeForm();
74         __pHomeForm->Initialize();
75         // Add the form to the frame
76         r = pMainFrame->AddControl(__pHomeForm);
77         TryCatch(r == E_SUCCESS, retVal = false, "pHmMainFrame.>AddControl(__pHomeForm) failed with error %s", GetErrorMessage(r));
78         // Set the current form
79         pMainFrame->SetCurrentForm(__pHomeForm);
80
81         // Draw the form
82         __pHomeForm->Draw();
83
84         if (__presentationModelInitialized)
85         {
86                 __pHomeForm->InitializePageControls(__pPresentationModel);
87         }
88
89         return retVal;
90
91 CATCH:
92
93         if (__pHomeForm != null)
94         {
95                 delete __pHomeForm;
96                 __pHomeForm = null;
97         }
98
99         if (pMainFrame != null)
100         {
101                 delete pMainFrame;
102                 pMainFrame = null;
103         }
104         return retVal;
105
106 }
107
108
109 bool
110 HomeApp::OnAppInitializing(AppRegistry& appRegistry)
111 {
112         __pPresentationModel = new (std::nothrow) HomePresentationModel();
113         __pPresentationModel->Construct();
114         return true;
115 }
116
117 bool
118 HomeApp::OnAppWillTerminate(void)
119 {
120         // Comment.
121         return true;
122 }
123
124
125 bool
126 HomeApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
127 {
128         // Deallocate resources allocated by this App for termination.
129         // The App's permanent data and context can be saved via appRegistry.
130         return true;
131 }
132
133 void
134 HomeApp::OnForeground(void)
135 {
136         if (__pHomeForm != null)
137         {
138                 __pHomeForm->UpdateAllPages();
139         }
140
141         return;
142 }
143
144 void
145 HomeApp::OnBackground(void)
146 {
147         // TODO:
148         // Stop drawing when the application is moved to the background.
149         return;
150 }
151
152 void
153 HomeApp::OnLowMemory(void)
154 {
155         // TODO:
156         // Free unused resources or close the application.
157         return;
158 }
159
160 void
161 HomeApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
162 {
163         // TODO:
164         // Handle any changes in battery level here.
165         // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
166         return;
167 }
168
169 void
170 HomeApp::OnScreenOn(void)
171 {
172         // TODO:
173         // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
174         return;
175 }
176
177 void
178 HomeApp::OnScreenOff(void)
179 {
180         // TODO:
181         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
182         // to enter the sleep mode to save the battery.
183         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
184         // callback before the device enters the sleep mode.
185         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
186         return;
187 }
188
189 void
190 HomeApp::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
191 {
192         switch (requestId)
193         {
194         case MODEL_REQUEST_INITIALIZE:
195         {
196                 __presentationModelInitialized = true;
197
198                 if (__pHomeForm != null)
199                 {
200                         __pHomeForm->InitializePageControls(__pPresentationModel);
201                 }
202         }
203         break;
204
205         default:
206         {
207                 //no implementation required
208         }
209         break;
210
211         }
212
213         if (pArgs != null)
214         {
215                 pArgs->RemoveAll(true);
216                 delete pArgs;
217                 pArgs = null;
218         }
219 }