Fixed Nabi Issues and poppup alignment 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.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://www.tizenopensource.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 void
200 InternetApp::OnBackground(void)
201 {
202
203 }
204
205 void
206 InternetApp::OnLowMemory(void)
207 {
208
209 }
210
211 void
212 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
213 {
214
215 }
216
217 void
218 InternetApp::OnScreenOn(void)
219 {
220
221 }
222
223 void
224 InternetApp::OnScreenOff(void)
225 {
226         // TODO:
227         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
228         // to enter the sleep mode to save the battery.
229         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
230         // callback before the device enters the sleep mode.
231         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
232 }
233
234 void
235 InternetApp::OnSettingChanged(Tizen::Base::String& key)
236 {
237         AppLog("InternetApp::OnSettingChanged: %ls", key.GetPointer());
238         if (key == L"http://tizen.org/setting/locale.language")
239         {
240                 Terminate();
241         }
242 }
243
244 void
245 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
246 {
247         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
248
249         if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
250         {
251                 String urlData;
252                 if (pUriScheme)
253                 {
254                         urlData = *pUriScheme;
255                 }
256                 else
257                 {
258                         int argCount = pArgs->GetCount();
259                         AppLog("argCount == %d", argCount);
260
261                         IList *pValues = pArgs->GetValuesN();
262                         if(pValues == null)
263                         {
264                                 AppLog("pValues == null");
265                                 return;
266                         }
267
268                         String url = L"url";
269                         String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
270                         if(pUrl == null)
271                         {
272                                 delete pValues;
273                                 AppLog("pUrl == null");
274                                 return;
275                         }
276                         urlData = *pUrl;
277                 }
278                 AppLog("URL received %ls", urlData.GetPointer());
279
280                 if (__pNewWindowInfo == null)
281                 {
282                         __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
283                 }
284                 if (__pNewWindowInfo == null)
285                 {
286                         if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
287                         {
288                                 String strTitle = L"Maximum Limit Reached";
289                                 String strText = L"cannot open more than 9 windows";
290                                 ShowPopup(strTitle, strText);
291                         }
292                         return;
293                 }
294                 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
295                 {
296                         //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
297                         //otherwise appcontrol request will be handled by OnAppInitialized method
298                         SceneManager* pSceneManager = SceneManager::GetInstance();
299                         if (pSceneManager == null)
300                         {
301                                 return;
302                         }
303
304                         ArrayList* pArgList = new(std::nothrow) ArrayList();
305                         pArgList->Construct();
306                         pArgList->Add(*__pNewWindowInfo);
307
308                         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
309                         {
310                                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
311                                                 delete pArgList;
312                                 __pNewWindowInfo = null;
313                                 return;
314                         }
315
316                         delete pArgList;
317
318                         __pNewWindowInfo = null;
319                 }
320         }
321         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
322         return;
323 }
324