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.
20 *@brief: provides basic features necessary to define an UiApp.
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"
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;
43 const int MIN_MEMORY_NEEDED = 1048576;
45 InternetApp::InternetApp(void)
46 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
50 InternetApp::~InternetApp(void)
52 if (__pNewWindowInfo != NULL)
54 delete __pNewWindowInfo;
55 __pNewWindowInfo = NULL;
60 InternetApp::CreateInstance(void)
62 // Create the instance through the constructor.
63 return new(std::nothrow) InternetApp();
67 InternetApp::ShowPopup(String& pTitle, String& pText)
69 MessageBox messageBox;
70 messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
73 messageBox.ShowAndWait(modalResult);
76 case MSGBOX_RESULT_OK:
87 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
89 AppLog("ABC::Internet::OnAppInitializing entered");
90 AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
93 result r = pAppMgr->SetAppControlProviderEventListener(this);
94 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
100 InternetApp::OnAppInitialized(void)
102 result r = E_SUCCESS;
104 long long mem = GetAvailableMemory();
105 AppLogDebug("%lld",mem);
106 if(mem < MIN_MEMORY_NEEDED)
108 MessageBox LowMemory;
110 LowMemory.Construct(CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG_TITLE"), CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG"), MSGBOX_STYLE_NONE,1000);
112 // Calls ShowAndWait() : Draws and Shows itself and processes events
113 LowMemory.ShowAndWait(modalResult);
118 String title1 = L"URL1";
119 String title2 = L"URL2";
120 String folder1 = L"Folder 1";
121 String strSite1 = "Site 1";
123 BookmarkPresentationModel::GetInstance();
124 HistoryPresentationModel::GetInstance();
125 FaviconManager::GetInstance();
126 SettingPresentationModel::GetInstance();
128 // MultipleWindowPresentationModel::GetInstance();
130 SettingInfo::AddSettingEventListener(*this);
131 __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
132 AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
137 MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
138 pSceneManagementFrame->Construct();
139 pSceneManagementFrame->SetName(L"SceneManagement");
140 AddFrame(*pSceneManagementFrame);
141 // Goto the first scene.
143 SceneManager* pSceneManager = SceneManager::GetInstance();
144 if (pSceneManager == null)
146 AppLogDebug("pSceneManager is null returning");
150 String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
151 if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
155 else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
157 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
158 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
159 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
162 if (__pNewWindowInfo == null)//if the application is launched normally
164 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
167 if (__pNewWindowInfo == null)
172 ArrayList* pArgList = new(std::nothrow) ArrayList();
173 pArgList->Construct();
174 pArgList->Add(*__pNewWindowInfo);
176 * The GoForward call cannot be moved into the MainFrame::OnInitializing
177 * because when the application is launched from the appcontol, the data(URL)
178 * is not available for Mainframe, and we cannot pass the url information to
179 * the Mainframe because logically MainFrame should not know the URL information.
181 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
183 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
185 __pNewWindowInfo = null;
189 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
190 String sliderKey("SliderValue");
195 r = pAppRegistry->Get(sliderKey, sliderValue);
196 r = PowerManager::SetScreenBrightness(sliderValue);
198 AppLog("Settingscreenbrightness to %d result %s",sliderValue , GetErrorMessage(r));
202 __pNewWindowInfo = null;
208 InternetApp::OnAppWillTerminate(void)
215 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
217 AppLogDebug("Internet::OnAppTerminating");
219 SettingInfo::RemoveSettingEventListener(*this);
225 InternetApp::OnForeground(void)
227 Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
230 pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
235 InternetApp::OnBackground(void)
237 Form* pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
240 pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
245 InternetApp::OnLowMemory(void)
251 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
257 InternetApp::OnScreenOn(void)
263 InternetApp::OnScreenOff(void)
266 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
267 // to enter the sleep mode to save the battery.
268 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
269 // callback before the device enters the sleep mode.
270 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
274 InternetApp::OnSettingChanged(Tizen::Base::String& key)
276 AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
277 if (key == L"http://tizen.org/setting/locale.language")
284 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
286 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
288 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
293 urlData = *pUriScheme;
297 int argCount = pArgs->GetCount();
298 AppLog("argCount == %d", argCount);
300 IList *pValues = pArgs->GetValuesN();
303 AppLog("pValues == null");
308 String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
312 AppLog("pUrl == null");
317 AppLog("URL received %ls", urlData.GetPointer());
319 if (__pNewWindowInfo == null)
321 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(urlData, true);
323 if (__pNewWindowInfo == null)
325 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
327 String strTitle = CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
328 String strText = CommonUtil::GetString(L"IDS_COM_SK_CREATE_WINDOWS_BNO");
329 ShowPopup(strTitle, strText);
333 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
335 //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
336 //otherwise appcontrol request will be handled by OnAppInitialized method
337 SceneManager* pSceneManager = SceneManager::GetInstance();
338 if (pSceneManager == null)
343 ArrayList* pArgList = new(std::nothrow) ArrayList();
344 pArgList->Construct();
345 pArgList->Add(*__pNewWindowInfo);
347 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
349 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
351 __pNewWindowInfo = null;
357 __pNewWindowInfo = null;
360 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
366 InternetApp::GetAvailableMemory(void)
368 result r = E_SUCCESS;
370 String key(L"http://tizen.org/runtime/storage.available.internal");
371 long long allocatedMemory = 0;
373 r = RuntimeInfo::GetValue(key, allocatedMemory);
374 TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
376 return allocatedMemory;