Fixed Nabi Issues
[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.0 (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 InternetApp::InternetApp(void)
44 : __pMultiWindowManager(NULL),__pNewWindowInfo(null)
45 {
46
47 }
48
49 InternetApp::~InternetApp(void)
50 {
51         if (__pNewWindowInfo != NULL)
52         {
53                 delete __pNewWindowInfo;
54                 __pNewWindowInfo = NULL;
55         }
56 }
57
58 UiApp*
59 InternetApp::CreateInstance(void)
60 {
61         // Create the instance through the constructor.
62         return new(std::nothrow) InternetApp();
63 }
64
65 void
66 InternetApp::ShowPopup(String& pTitle, String& pText)
67 {
68         MessageBox messageBox;
69         messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
70         int modalResult = 0;
71
72         messageBox.ShowAndWait(modalResult);
73         switch (modalResult)
74         {
75         case MSGBOX_RESULT_OK:
76         {
77
78         }
79         break;
80         default:
81                 break;
82         }
83 }
84
85 bool
86 InternetApp::OnAppInitializing(AppRegistry& appRegistry)
87 {
88         AppLog("ABC::Internet::OnAppInitializing entered");
89         AppControlProviderManager* pAppMgr = AppControlProviderManager::GetInstance();
90         if (pAppMgr != null)
91         {
92                 result r = pAppMgr->SetAppControlProviderEventListener(this);
93                 AppLogDebug("SetAppControlProviderEventListener result %s",GetErrorMessage(r));
94         }
95         return true;
96 }
97
98 bool
99 InternetApp::OnAppInitialized(void)
100 {
101         result r = E_SUCCESS;
102
103         String title1 = L"URL1";
104         String title2 = L"URL2";
105         String folder1 = L"Folder 1";
106         String strSite1 = "Site 1";
107
108         BookmarkPresentationModel::GetInstance();
109         HistoryPresentationModel::GetInstance();
110         FaviconManager::GetInstance();
111         SettingPresentationModel::GetInstance();
112
113 //      MultipleWindowPresentationModel::GetInstance();
114
115         SettingInfo::AddSettingEventListener(*this);
116         __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
117         AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
118
119         // Goto the first scene.
120         SceneManager* pSceneManager = SceneManager::GetInstance();
121         if (pSceneManager == null)
122         {
123                 AppLogDebug("pSceneManager is null returning");
124                 return false;
125         }
126         // Create a Frame
127         MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
128         pSceneManagementFrame->Construct();
129         pSceneManagementFrame->SetName(L"SceneManagement");
130         AddFrame(*pSceneManagementFrame);
131
132         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
133         if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
134         {
135                 homePage = L"";
136         }
137         else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
138         {
139                 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
140                 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
141                 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
142         }
143
144         if (__pNewWindowInfo == null)//if the application is launched normally
145         {
146                 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(homePage);
147         }
148
149         if (__pNewWindowInfo == null)
150         {
151                 return false;
152         }
153
154         ArrayList* pArgList = new(std::nothrow) ArrayList();
155         pArgList->Construct();
156         pArgList->Add(*__pNewWindowInfo);
157         /*
158          * The GoForward call cannot be moved into the MainFrame::OnInitializing
159          * because when the application is launched from the appcontol, the data(URL)
160          * is not available for Mainframe, and we cannot pass the url information to
161          * the Mainframe because logically MainFrame should not know the URL information.
162          */
163         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
164         {
165                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
166                 delete pArgList;
167                 __pNewWindowInfo = null;
168                 return false;
169         }
170
171         delete pArgList;
172         pArgList = null;
173         __pNewWindowInfo = null;
174
175         return true;
176 }
177
178 bool
179 InternetApp::OnAppWillTerminate(void)
180 {
181         return true;
182 }
183
184
185 bool
186 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
187 {
188         AppLogDebug("Internet::OnAppTerminating");
189
190         return true;
191 }
192
193 void
194 InternetApp::OnForeground(void)
195 {
196
197
198 }
199
200 void
201 InternetApp::OnBackground(void)
202 {
203
204 }
205
206 void
207 InternetApp::OnLowMemory(void)
208 {
209
210 }
211
212 void
213 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
214 {
215
216 }
217
218 void
219 InternetApp::OnScreenOn(void)
220 {
221
222 }
223
224 void
225 InternetApp::OnScreenOff(void)
226 {
227         // TODO:
228         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
229         // to enter the sleep mode to save the battery.
230         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
231         // callback before the device enters the sleep mode.
232         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
233 }
234
235 void
236 InternetApp::OnSettingChanged(Tizen::Base::String& key)
237 {
238         AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
239         if (key == L"http://tizen.org/setting/locale.language")
240         {
241                 Terminate();
242         }
243 }
244
245 void
246 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
247 {
248         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
249
250         if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
251         {
252                 String urlData;
253                 if (pUriScheme)
254                 {
255                         urlData = *pUriScheme;
256                 }
257                 else
258                 {
259                         int argCount = pArgs->GetCount();
260                         AppLog("argCount == %d", argCount);
261
262                         IList *pValues = pArgs->GetValuesN();
263                         if(pValues == null)
264                         {
265                                 AppLog("pValues == null");
266                                 return;
267                         }
268
269                         String url = L"url";
270                         String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
271                         if(pUrl == null)
272                         {
273                                 delete pValues;
274                                 AppLog("pUrl == null");
275                                 return;
276                         }
277                         urlData = *pUrl;
278                 }
279                 AppLog("URL received %ls", urlData.GetPointer());
280
281                 if (__pNewWindowInfo == null)
282                 {
283                         __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
284                 }
285                 if (__pNewWindowInfo == null)
286                 {
287                         if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
288                         {
289                                 String strTitle = L"Maximum Limit Reached";
290                                 String strText = L"cannot open more than 9 windows";
291                                 ShowPopup(strTitle, strText);
292                         }
293                         return;
294                 }
295                 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
296                 {
297                         //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
298                         //otherwise appcontrol request will be handled by OnAppInitialized method
299                         SceneManager* pSceneManager = SceneManager::GetInstance();
300                         if (pSceneManager == null)
301                         {
302                                 return;
303                         }
304
305                         ArrayList* pArgList = new(std::nothrow) ArrayList();
306                         pArgList->Construct();
307                         pArgList->Add(*__pNewWindowInfo);
308
309                         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
310                         {
311                                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
312                                                 delete pArgList;
313                                 __pNewWindowInfo = null;
314                                 return;
315                         }
316
317                         delete pArgList;
318
319                         __pNewWindowInfo = null;
320                 }
321         }
322         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
323         return;
324 }
325