Fixed Nabi Issues 49466,55718,55225,52332
[apps/osp/Internet.git] / src / IntInternetApp.cpp
index ecf5023..33e694c 100644 (file)
@@ -2,11 +2,11 @@
 
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.tizenopensource.org/license
+//     http://floralicense.org/license
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an AS IS BASIS,
@@ -40,10 +40,15 @@ using namespace Tizen::Ui;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
 
+static const wchar_t* APPCONTROL_SELECT_KEY_IMAGE = L"http://tizen.org/appcontrol/data/image/crop_mode";
+static const wchar_t* APPCONTROL_SELECT_VALUE_IMAGE = L"fit_to_screen";
+static const wchar_t* APPCONTROL_PROVIDER_ID_IMAGE_VIEWER = L"tizen.imageviewer";
+static const wchar_t* APPCONTROL_OPERATION_ID_IMAGE_VIEWER = L"http://tizen.org/appcontrol/operation/view";
+const int MIN_MEMORY_NEEDED = 1048576;
+
 InternetApp::InternetApp(void)
-: __pMultiWindowManager(NULL),__pNewWindowInfo(null)
+: __pMultiWindowManager(NULL),__pNewWindowInfo(null),pSceneManagementFrame(null),__value(null),__isShowMsg(false),__pAc(null)
 {
-
 }
 
 InternetApp::~InternetApp(void)
@@ -100,6 +105,20 @@ InternetApp::OnAppInitialized(void)
 {
        result r = E_SUCCESS;
 
+       long long mem = GetAvailableMemory();
+       AppLogDebug("%lld",mem);
+       if(mem < MIN_MEMORY_NEEDED)
+       {
+               MessageBox LowMemory;
+               String msg = L"";
+               LowMemory.Construct(CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG_TITLE"), CommonUtil::GetString(L"IDS_LOW_MEMORY_MSG"), MSGBOX_STYLE_NONE,1000);
+               int modalResult = 0;
+               // Calls ShowAndWait() : Draws and Shows itself and processes events
+               LowMemory.ShowAndWait(modalResult);
+
+               return false;
+
+       }
        String title1 = L"URL1";
        String title2 = L"URL2";
        String folder1 = L"Folder 1";
@@ -112,21 +131,26 @@ InternetApp::OnAppInitialized(void)
 
 //     MultipleWindowPresentationModel::GetInstance();
 
+       SettingInfo::AddSettingEventListener(*this);
        __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
        AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
 
+
+
+       // Create a Frame
+       pSceneManagementFrame = new(std::nothrow) MainFrame();
+       pSceneManagementFrame->Construct();
+       pSceneManagementFrame->SetName(L"SceneManagement");
+       AddFrame(*pSceneManagementFrame);
+       pSceneManagementFrame->Show();
        // Goto the first scene.
+
        SceneManager* pSceneManager = SceneManager::GetInstance();
        if (pSceneManager == null)
        {
                AppLogDebug("pSceneManager is null returning");
                return false;
        }
-       // Create a Frame
-       MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
-       pSceneManagementFrame->Construct();
-       pSceneManagementFrame->SetName(L"SceneManagement");
-       AddFrame(*pSceneManagementFrame);
 
        String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
        if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
@@ -142,7 +166,7 @@ InternetApp::OnAppInitialized(void)
 
        if (__pNewWindowInfo == null)//if the application is launched normally
        {
-               __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(homePage);
+               __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(homePage);
        }
 
        if (__pNewWindowInfo == null)
@@ -150,6 +174,29 @@ InternetApp::OnAppInitialized(void)
                return false;
        }
 
+       if (__operationId.CompareTo(L"http://tizen.org/appcontrol/operation/main") == 0)
+       {
+               if(__pAc)
+               {
+                       r =__pAc->Stop();
+                       AppLog("AppControl Stop Result %s",GetErrorMessage(r));
+                       delete __pAc;
+                       __pAc = null;
+               }
+               __pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_IMAGE_VIEWER,
+                               APPCONTROL_OPERATION_ID_IMAGE_VIEWER);
+               if (__pAc && __value && __value->GetLength() > 0)
+               {
+                       AppLog("17jul __value is %S", __value->GetPointer());
+                       if (__pAc->Start(__value, null, null, null) == E_SUCCESS)
+                       {
+//                             delete pAc;
+                       }
+                       delete __value;
+                       __value = null;
+               }
+       }
+
        ArrayList* pArgList = new(std::nothrow) ArrayList();
        pArgList->Construct();
        pArgList->Add(*__pNewWindowInfo);
@@ -186,19 +233,70 @@ InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
 {
        AppLogDebug("Internet::OnAppTerminating");
 
+       SettingInfo::RemoveSettingEventListener(*this);
+
        return true;
 }
 
 void
 InternetApp::OnForeground(void)
 {
+       UiApp* pApp = null;
+       pApp = UiApp::GetInstance();
+       if (pApp != null && pSceneManagementFrame != null && pApp->GetFrameAt(0)->GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
+       {
+               pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
+       }
+       AppLog("InternetApp::OnForeground called");
+
+       AppLog("InternetApp::OnForeground");
+
+       AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
+       String sliderKey("SliderValue");
+
+       int sliderValue = 10;
+
 
+       result r = pAppRegistry->Get(sliderKey, sliderValue);
+       r = PowerManager::SetScreenBrightness(sliderValue);
+//     r = PowerManager::RestoreScreenBrightness();
+
+       AppLog("Settingscreenbrightness to %d result %s",sliderValue , GetErrorMessage(r));
+
+       Form* pCurrentForm = null;
+       if(SceneManager::GetInstance()->GetCurrentScene() != null)
+               pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
+       if (pCurrentForm)
+       {
+               pCurrentForm->SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
+       }
+       Frame* pCurrentFrame = null;
+       pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
+
+       if (pCurrentFrame != null)
+       {
+               pCurrentFrame->SetEnabled(true);
+               pCurrentFrame->Invalidate(true);
+       }
+
+       if ( __isShowMsg == true )
+       {
+               __isShowMsg = false;
+               SendUserEvent(FORE_GROUND_APP_EVENT, NULL);
+       }
 }
 
 void
 InternetApp::OnBackground(void)
 {
-
+       AppLog("InternetApp::OnBackground");
+       Form* pCurrentForm = null;
+       if(SceneManager::GetInstance()->GetCurrentScene() != null)
+               pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
+       if(pCurrentForm)
+       {
+               pCurrentForm->SendUserEvent(BACK_GROUND_APP_EVENT, NULL);
+       }
 }
 
 void
@@ -229,11 +327,47 @@ InternetApp::OnScreenOff(void)
        // callback before the device enters the sleep mode.
        // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
 }
+
+void
+InternetApp::OnSettingChanged(Tizen::Base::String& key)
+{
+       AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
+       if (key == L"http://tizen.org/setting/locale.language" || key == L"http://tizen.org/setting/font.size")
+       {
+               Terminate();
+       }
+       else if (key == L"http://tizen.org/setting/screen.brightness" )
+       {
+               AppRegistry* pAppRegistry = App::GetInstance()->GetAppRegistry();
+               String sliderKey("SliderValue");
+
+               int sliderValue = 10;
+
+
+               result r = pAppRegistry->Get(sliderKey, sliderValue);
+               r = PowerManager::SetScreenBrightness(sliderValue);
+               //      r = PowerManager::RestoreScreenBrightness();
+
+       }
+
+}
+
 void
 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
 {
-       AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
+       UiApp* pApp = null;
+       pApp = UiApp::GetInstance();
+       if (pApp != null &&  pSceneManagementFrame != null)
+       {
+               pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
+
+       }
 
+       __isShowMsg = false;
+
+       AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
+       __operationId.Clear();
+       __operationId.Append(operationId);
        if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
        {
                String urlData;
@@ -264,21 +398,24 @@ InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operatio
                        urlData = *pUrl;
                }
                AppLog("URL received %ls", urlData.GetPointer());
+               if(pSceneManagementFrame)
+                       pSceneManagementFrame->Show();
+
 
-               if (__pNewWindowInfo == null)
-               {
-                       __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
-               }
                if (__pNewWindowInfo == null)
                {
                        if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
                        {
-                               String strTitle = L"Maximum Limit Reached";
-                               String strText = L"cannot open more than 9 windows";
-                               ShowPopup(strTitle, strText);
+                               __isShowMsg = true;
+                               return;
                        }
-                       return;
                }
+
+               if (__pNewWindowInfo == null)
+               {
+                       __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(urlData, true);
+               }
+
                if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
                {
                        //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
@@ -306,7 +443,99 @@ InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operatio
                        __pNewWindowInfo = null;
                }
        }
+       else if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/main") == 0)
+       {
+               if (pArgs)
+               {
+                       //const String* pVal = (String *) pArgs->GetValue(String(L"http://tizen.org/appcontrol/data/notification"));
+                       String *data = (String *) pArgs->GetValue(String(L"http://tizen.org/appcontrol/data/notification"));
+                       if(data != NULL)
+                               __value = new String(*data);
+                       if (__value && __value->GetLength() > 0)
+                       {
+                               AppLog("17jul rahul __value is %S", __value->GetPointer());
+                       }
+                       if (__value && __value->GetLength() > 0 && pSceneManagementFrame != null)
+                       {
+                               AppLog("17jul OnAppControlRequestReceived notification");
+                               HashMap extraData;
+                               extraData.Construct();
+                               String typeKey = APPCONTROL_SELECT_KEY_IMAGE;
+                               String typeVal = APPCONTROL_SELECT_VALUE_IMAGE;
+                               extraData.Add(&typeKey, &typeVal);
+
+                               if(__pAc)
+                               {
+                                       result r = __pAc->Stop();
+                                       AppLog("AppControl Stop Result %s",GetErrorMessage(r));
+                                       delete __pAc;
+                                       __pAc = null;
+                               }
+                               __pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_IMAGE_VIEWER,
+                                               APPCONTROL_OPERATION_ID_IMAGE_VIEWER);
+                               if (__pAc)
+                               {
+                                       AppLog("17jul __value is %S", __value->GetPointer());
+                                       if (__pAc->Start(__value, null, null, null) == E_SUCCESS)
+                                       {
+//                                             delete pAc;
+                                       }
+                               }
+                               delete __value;
+                               __value = null;
+
+                       }
+               }
+       }
+
        AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
        return;
 }
 
+
+long long
+InternetApp::GetAvailableMemory(void)
+{
+    result r = E_SUCCESS;
+
+    String key(L"http://tizen.org/runtime/storage.available.internal");
+    long long allocatedMemory = 0;
+
+    r = RuntimeInfo::GetValue(key, allocatedMemory);
+    TryCatch(r == E_SUCCESS, , "MyRuntimeInfo: Failed to get value");
+
+    return allocatedMemory;
+
+   CATCH:
+    return 0;
+}
+
+
+void
+InternetApp::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
+{
+       Form* pCurrentForm = null;
+       if(SceneManager::GetInstance()->GetCurrentScene() != null)
+               pCurrentForm = (SceneManager::GetInstance()->GetCurrentScene()->GetForm());
+       if (pCurrentForm)
+       {
+               AppLog("sending userevent for appcontrol");
+               pCurrentForm->SendUserEvent(APPCONTROL_LAUNCH_MAX_LIMIT_REACHED, NULL);
+       }
+
+       if(requestId == FORE_GROUND_APP_EVENT)
+       {
+               if( MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
+                {
+                        String strText = CommonUtil::GetString(L"IDS_BR_BODY_COULD_NOT_OPEN_NEW_WINDOW_BECAUSE_YOU_HAVE_ALREADY_OPENED_MAXIMUM_NUMBER");
+                        MessageBox messageBox;
+                        messageBox.Construct(L"", strText, MSGBOX_STYLE_OK, 3000);
+                        int modalResult = 0;
+
+                        messageBox.ShowAndWait(modalResult);
+                }
+       }
+
+}
+
+