Fixed Nabi Issues, Fone Changes
[apps/osp/Internet.git] / src / IntInternetApp.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.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 //!Internet
19 /*@file:        Internet.cpp
20  *@brief:       provides basic features necessary to define an UiApp.
21  */
22
23 #include "IntBookmarkData.h"
24 #include "IntBookmarkPresentationModel.h"
25 #include "IntCommonLib.h"
26 #include "IntFaviconManager.h"
27 #include "IntHistoryPresentationModel.h"
28 #include "IntInternetApp.h"
29 #include "IntMainFrame.h"
30 #include "IntMainForm.h"
31 #include "IntMultipleWindowPresentationModel.h"
32 #include "IntSceneRegister.h"
33 #include "IntSettingPresentationModel.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::System;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42
43 const int MIN_MEMORY_NEEDED = 1048576;
44
45 InternetApp::InternetApp(void)
46 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
47 {
48         __isHwBackButtonExists = false;
49 }
50
51 InternetApp::~InternetApp(void)
52 {
53         if (__pNewWindowInfo != NULL)
54         {
55                 delete __pNewWindowInfo;
56                 __pNewWindowInfo = NULL;
57         }
58 }
59
60 bool
61 InternetApp::IsHwBackKeyExists(void)
62 {
63         return __isHwBackButtonExists;
64 }
65
66 UiApp*
67 InternetApp::CreateInstance(void)
68 {
69         // Create the instance through the constructor.
70         return new(std::nothrow) InternetApp();
71 }
72
73 void
74 InternetApp::ShowPopup(String& pTitle, String& pText)
75 {
76         MessageBox messageBox;
77         messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
78         int modalResult = 0;
79
80         messageBox.ShowAndWait(modalResult);
81         switch (modalResult)
82         {
83         case MSGBOX_RESULT_OK:
84         {
85
86         }
87         break;
88         default:
89                 break;
90         }
91 }
92
93 bool
94 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
95 {
96         AppLog("ABC::Internet::OnAppInitializing entered");
97         AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
98         if (pAppMgr != null)
99         {
100                 result r = pAppMgr->SetAppControlProviderEventListener(this);
101                 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
102         }
103         Tizen::System::SystemInfo::GetValue(L"http://tizen.org/feature/input.keys.back",__isHwBackButtonExists);
104         return true;
105 }
106
107 bool
108 InternetApp::OnAppInitialized(void)
109 {
110         result r = E_SUCCESS;
111
112         long long mem = GetAvailableMemory();
113         AppLogDebug("%lld",mem);
114         if(mem < MIN_MEMORY_NEEDED)
115         {
116                 MessageBox LowMemory;
117                 String msg = L"";
118                 LowMemory.Construct(CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG_TITLE"), CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG"), MSGBOX_STYLE_NONE,1000);
119                 int modalResult = 0;
120                 // Calls ShowAndWait() : Draws and Shows itself and processes events
121                 LowMemory.ShowAndWait(modalResult);
122
123                 return false;
124
125         }
126         String title1 = L"URL1";
127         String title2 = L"URL2";
128         String folder1 = L"Folder 1";
129         String strSite1 = "Site 1";
130
131         BookmarkPresentationModel::GetInstance();
132         HistoryPresentationModel::GetInstance();
133         FaviconManager::GetInstance();
134         SettingPresentationModel::GetInstance();
135
136 //      MultipleWindowPresentationModel::GetInstance();
137
138         SettingInfo::AddSettingEventListener(*this);
139         __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
140         AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
141
142
143
144         // Create a Frame
145         MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
146         pSceneManagementFrame->Construct();
147         pSceneManagementFrame->SetName(L"SceneManagement");
148         AddFrame(*pSceneManagementFrame);
149         // Goto the first scene.
150
151         SceneManager* pSceneManager = SceneManager::GetInstance();
152         if (pSceneManager == null)
153         {
154                 AppLogDebug("pSceneManager is null returning");
155                 return false;
156         }
157
158         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
159         if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
160         {
161                 homePage = L"";
162         }
163         else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
164         {
165                 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
166                 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
167                 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
168         }
169
170         if (__pNewWindowInfo == null)//if the application is launched normally
171         {
172                 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
173         }
174
175         if (__pNewWindowInfo == null)
176         {
177                 return false;
178         }
179
180         ArrayList* pArgList = new(std::nothrow) ArrayList();
181         pArgList->Construct();
182         pArgList->Add(*__pNewWindowInfo);
183         /*
184          * The GoForward call cannot be moved into the MainFrame::OnInitializing
185          * because when the application is launched from the appcontol, the data(URL)
186          * is not available for Mainframe, and we cannot pass the url information to
187          * the Mainframe because logically MainFrame should not know the URL information.
188          */
189         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
190         {
191                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
192                 delete pArgList;
193                 __pNewWindowInfo = null;
194                 return false;
195         }
196
197         delete pArgList;
198         pArgList = null;
199         __pNewWindowInfo = null;
200
201         return true;
202 }
203
204 bool
205 InternetApp::OnAppWillTerminate(void)
206 {
207         return true;
208 }
209
210
211 bool
212 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
213 {
214         AppLogDebug("Internet::OnAppTerminating");
215
216         SettingInfo::RemoveSettingEventListener(*this);
217
218         return true;
219 }
220
221 void
222 InternetApp::OnForeground(void)
223 {
224         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
225         if (pCurrentForm)
226         {
227                 pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
228         }
229 }
230
231 void
232 InternetApp::OnBackground(void)
233 {
234         Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
235         if(pCurrentForm)
236         {
237                 pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
238         }
239 }
240
241 void
242 InternetApp::OnLowMemory(void)
243 {
244
245 }
246
247 void
248 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
249 {
250
251 }
252
253 void
254 InternetApp::OnScreenOn(void)
255 {
256
257 }
258
259 void
260 InternetApp::OnScreenOff(void)
261 {
262         // TODO:
263         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
264         // to enter the sleep mode to save the battery.
265         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
266         // callback before the device enters the sleep mode.
267         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
268 }
269
270 void
271 InternetApp::OnSettingChanged(Tizen::Base::String& key)
272 {
273         AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
274         if (key == L"http://tizen.org/setting/locale.language")
275         {
276                 Terminate();
277         }
278 }
279
280 void
281 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
282 {
283         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
284
285         if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
286         {
287                 String urlData;
288                 if (pUriScheme)
289                 {
290                         urlData = *pUriScheme;
291                 }
292                 else
293                 {
294                         int argCount = pArgs->GetCount();
295                         AppLog("argCount == %d", argCount);
296
297                         IList *pValues = pArgs->GetValuesN();
298                         if(pValues == null)
299                         {
300                                 AppLog("pValues == null");
301                                 return;
302                         }
303
304                         String url = L"url";
305                         String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
306                         if(pUrl == null)
307                         {
308                                 delete pValues;
309                                 AppLog("pUrl == null");
310                                 return;
311                         }
312                         urlData = *pUrl;
313                 }
314                 AppLog("URL received %ls", urlData.GetPointer());
315
316                 if (__pNewWindowInfo == null)
317                 {
318                         __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(urlData, true);
319                 }
320                 if (__pNewWindowInfo == null)
321                 {
322                         if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
323                         {
324                                 String strTitle = CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
325                                 String strText = CommonUtil::GetString(L"IDS_COM_SK_CREATE_WINDOWS_BNO");
326                                 ShowPopup(strTitle, strText);
327                         }
328                         return;
329                 }
330                 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
331                 {
332                         //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
333                         //otherwise appcontrol request will be handled by OnAppInitialized method
334                         SceneManager* pSceneManager = SceneManager::GetInstance();
335                         if (pSceneManager == null)
336                         {
337                                 return;
338                         }
339
340                         ArrayList* pArgList = new(std::nothrow) ArrayList();
341                         pArgList->Construct();
342                         pArgList->Add(*__pNewWindowInfo);
343
344                         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
345                         {
346                                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
347                                                 delete pArgList;
348                                 __pNewWindowInfo = null;
349                                 return;
350                         }
351
352                         delete pArgList;
353
354                         __pNewWindowInfo = null;
355                 }
356         }
357         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
358         return;
359 }
360
361
362 long long
363 InternetApp::GetAvailableMemory(void)
364 {
365     result r = E_SUCCESS;
366
367     String key(L"http://tizen.org/runtime/storage.available.internal");
368     long long allocatedMemory = 0;
369
370     r = RuntimeInfo::GetValue(key, allocatedMemory);
371     TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
372
373     return allocatedMemory;
374
375    CATCH:
376     return 0;
377 }