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