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 static const wchar_t* APPCONTROL_SELECT_KEY_IMAGE = L"http://tizen.org/appcontrol/data/image/crop_mode";
44 static const wchar_t* APPCONTROL_SELECT_VALUE_IMAGE = L"fit_to_screen";
45 static const wchar_t* APPCONTROL_PROVIDER_ID_IMAGE_VIEWER = L"tizen.imageviewer";
46 static const wchar_t* APPCONTROL_OPERATION_ID_IMAGE_VIEWER = L"http://tizen.org/appcontrol/operation/view";
47 const int MIN_MEMORY_NEEDED = 1048576;
49 InternetApp::InternetApp(void)
50 : __pMultiWindowManager(NULL),__pNewWindowInfo(null),pSceneManagementFrame(null),__value(null),__isShowMsg(false),__pAc(null)
54 InternetApp::~InternetApp(void)
56 if (__pNewWindowInfo != NULL)
58 delete __pNewWindowInfo;
59 __pNewWindowInfo = NULL;
64 InternetApp::CreateInstance(void)
66 // Create the instance through the constructor.
67 return new(std::nothrow) InternetApp();
71 InternetApp::ShowPopup(String& pTitle, String& pText)
73 MessageBox messageBox;
74 messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
77 messageBox.ShowAndWait(modalResult);
80 case MSGBOX_RESULT_OK:
91 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
93 AppLog("ABC::Internet::OnAppInitializing entered");
94 AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
97 result r = pAppMgr->SetAppControlProviderEventListener(this);
98 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
104 InternetApp::OnAppInitialized(void)
106 result r = E_SUCCESS;
108 long long mem = GetAvailableMemory();
109 AppLogDebug("%lld",mem);
110 if(mem < MIN_MEMORY_NEEDED)
112 MessageBox LowMemory;
114 LowMemory.Construct(CommonUtil::GetString(L"IDS_COM_POP_NOT_ENOUGH_MEMORY"), CommonUtil::GetString(L"IDS_COM_POP_NOT_ENOUGH_MEMORY_DELETE_SOME_ITEMS"), MSGBOX_STYLE_NONE,1000);
116 // Calls ShowAndWait() : Draws and Shows itself and processes events
117 LowMemory.ShowAndWait(modalResult);
122 String title1 = L"URL1";
123 String title2 = L"URL2";
124 String folder1 = L"Folder 1";
125 String strSite1 = "Site 1";
127 BookmarkPresentationModel::GetInstance();
128 HistoryPresentationModel::GetInstance();
129 FaviconManager::GetInstance();
130 SettingPresentationModel::GetInstance();
132 // MultipleWindowPresentationModel::GetInstance();
134 SettingInfo::AddSettingEventListener(*this);
135 __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
136 AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
141 pSceneManagementFrame = new(std::nothrow) MainFrame();
142 pSceneManagementFrame->Construct();
143 pSceneManagementFrame->SetName(L"SceneManagement");
144 AddFrame(*pSceneManagementFrame);
145 pSceneManagementFrame->Show();
146 // Goto the first scene.
148 SceneManager* pSceneManager = SceneManager::GetInstance();
149 if (pSceneManager == null)
151 AppLogDebug("pSceneManager is null returning");
155 String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
156 if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
160 else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
162 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
163 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
164 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
167 if (__pNewWindowInfo == null)//if the application is launched normally
169 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
172 if (__pNewWindowInfo == null)
177 if (__operationId.CompareTo(L"http://tizen.org/appcontrol/operation/main") == 0)
182 AppLog("AppControl Stop Result %s",GetErrorMessage(r));
186 __pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_IMAGE_VIEWER,
187 APPCONTROL_OPERATION_ID_IMAGE_VIEWER);
188 if (__pAc && __value && __value->GetLength() > 0)
190 AppLog("17jul __value is %S", __value->GetPointer());
191 if (__pAc->Start(__value, null, null, null) == E_SUCCESS)
200 ArrayList* pArgList = new(std::nothrow) ArrayList();
201 pArgList->Construct();
202 pArgList->Add(*__pNewWindowInfo);
204 * The GoForward call cannot be moved into the MainFrame::OnInitializing
205 * because when the application is launched from the appcontol, the data(URL)
206 * is not available for Mainframe, and we cannot pass the url information to
207 * the Mainframe because logically MainFrame should not know the URL information.
209 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
211 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
213 __pNewWindowInfo = null;
219 __pNewWindowInfo = null;
225 InternetApp::OnAppWillTerminate(void)
232 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
234 AppLogDebug("Internet::OnAppTerminating");
236 SettingInfo::RemoveSettingEventListener(*this);
242 InternetApp::OnForeground(void)
245 pApp = UiApp::GetInstance();
246 if (pApp != null && pSceneManagementFrame != null && pApp->GetFrameAt(0)->GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
248 pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
250 AppLog("InternetApp::OnForeground called");
252 AppLog("InternetApp::OnForeground");
254 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
255 String sliderKey("SliderValue");
257 int sliderValue = 10;
260 result r = pAppRegistry->Get(sliderKey, sliderValue);
261 r = PowerManager::SetScreenBrightness(sliderValue);
262 // r = PowerManager::RestoreScreenBrightness();
264 AppLog("Settingscreenbrightness to %d result %s",sliderValue , GetErrorMessage(r));
266 Form* pCurrentForm = null;
267 if(SceneManager::GetInstance()->GetCurrentScene() != null)
268 pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
271 pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
273 Frame* pCurrentFrame = null;
274 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
276 if (pCurrentFrame != null)
278 pCurrentFrame->SetEnabled(true);
279 pCurrentFrame->Invalidate(true);
282 if ( __isShowMsg == true )
285 SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
290 InternetApp::OnBackground(void)
292 AppLog("InternetApp::OnBackground");
293 Form* pCurrentForm = null;
294 if(SceneManager::GetInstance()->GetCurrentScene() != null)
295 pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
298 pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
303 InternetApp::OnLowMemory(void)
309 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
315 InternetApp::OnScreenOn(void)
321 InternetApp::OnScreenOff(void)
324 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
325 // to enter the sleep mode to save the battery.
326 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
327 // callback before the device enters the sleep mode.
328 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
332 InternetApp::OnSettingChanged(Tizen::Base::String& key)
334 AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
335 if (key == L"http://tizen.org/setting/locale.language" || key == L"http://tizen.org/setting/font.size")
339 else if (key == L"http://tizen.org/setting/screen.brightness" )
341 AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
342 result r = E_SUCCESS;
343 int sliderValue = 10;
344 SettingInfo::GetValue(key,sliderValue);
345 String sliderKey("SliderValue");
347 if( (sliderValue/10) + 1 > 10)
348 r = pAppRegistry->Set(sliderKey, 10);
350 r = pAppRegistry->Set(sliderKey, (sliderValue/10) + 1);
351 pAppRegistry->Save();
353 Form* pCurrentForm = null;
354 if(SceneManager::GetInstance()->GetCurrentScene() != null)
355 pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
358 AppLog("sending userevent for appcontrol");
359 pCurrentForm->SendUserEvent(DEVICE_BRIGHTNESS_CHANGE_EVENT, NULL);
362 if( (sliderValue/10) + 1 > 10)
363 r = PowerManager::SetScreenBrightness(10);
365 r = PowerManager::SetScreenBrightness((sliderValue/10) + 1);
366 // r = PowerManager::RestoreScreenBrightness();
373 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
376 pApp = UiApp::GetInstance();
377 if (pApp != null && pSceneManagementFrame != null)
379 pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
385 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
386 __operationId.Clear();
387 __operationId.Append(operationId);
388 if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
393 urlData = *pUriScheme;
397 int argCount = pArgs->GetCount();
398 AppLog("argCount == %d", argCount);
400 IList *pValues = pArgs->GetValuesN();
403 AppLog("pValues == null");
408 String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
412 AppLog("pUrl == null");
417 AppLog("URL received %ls", urlData.GetPointer());
418 if(pSceneManagementFrame)
419 pSceneManagementFrame->Show();
422 if (__pNewWindowInfo == null)
424 if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
431 if (__pNewWindowInfo == null)
433 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(urlData, true);
436 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
438 //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
439 //otherwise appcontrol request will be handled by OnAppInitialized method
440 SceneManager* pSceneManager = SceneManager::GetInstance();
441 if (pSceneManager == null)
446 ArrayList* pArgList = new(std::nothrow) ArrayList();
447 pArgList->Construct();
448 pArgList->Add(*__pNewWindowInfo);
450 if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
452 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
454 __pNewWindowInfo = null;
460 __pNewWindowInfo = null;
463 else if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/main") == 0)
467 //const String* pVal = (String *) pArgs->GetValue(String(L"http://tizen.org/appcontrol/data/notification"));
468 String *data = (String *) pArgs->GetValue(String(L"http://tizen.org/appcontrol/data/notification"));
470 __value = new String(*data);
471 if (__value && __value->GetLength() > 0)
473 AppLog("17jul rahul __value is %S", __value->GetPointer());
475 if (__value && __value->GetLength() > 0 && pSceneManagementFrame != null)
477 AppLog("17jul OnAppControlRequestReceived notification");
479 extraData.Construct();
480 String typeKey = APPCONTROL_SELECT_KEY_IMAGE;
481 String typeVal = APPCONTROL_SELECT_VALUE_IMAGE;
482 extraData.Add(&typeKey, &typeVal);
486 result r = __pAc->Stop();
487 AppLog("AppControl Stop Result %s",GetErrorMessage(r));
491 __pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_IMAGE_VIEWER,
492 APPCONTROL_OPERATION_ID_IMAGE_VIEWER);
495 AppLog("17jul __value is %S", __value->GetPointer());
496 if (__pAc->Start(__value, null, null, null) == E_SUCCESS)
508 AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
514 InternetApp::GetAvailableMemory(void)
516 result r = E_SUCCESS;
518 String key(L"http://tizen.org/runtime/storage.available.internal");
519 long long allocatedMemory = 0;
521 r = RuntimeInfo::GetValue(key, allocatedMemory);
522 TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
524 return allocatedMemory;
532 InternetApp::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
534 Form* pCurrentForm = null;
535 if(SceneManager::GetInstance()->GetCurrentScene() != null)
536 pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
539 AppLog("sending userevent for appcontrol");
540 pCurrentForm->SendUserEvent(APPCONTROL_LAUNCH_MAX_LIMIT_REACHED, NULL);
543 if(requestId == FORE_GROUND_APP_EVENT)
545 if( MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
547 String strText = CommonUtil::GetString(L"IDS_BR_BODY_COULD_NOT_OPEN_NEW_WINDOW_BECAUSE_YOU_HAVE_ALREADY_OPENED_MAXIMUM_NUMBER");
548 MessageBox messageBox;
549 messageBox.Construct(L"", strText, MSGBOX_STYLE_OK, 3000);
552 messageBox.ShowAndWait(modalResult);