ecf5023e288d2f90da520d0b79c96473797b982e
[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         __pMultiWindowManager = MultipleWindowPresentationModel::GetInstance();
116         AppLogDebug("window count %d",__pMultiWindowManager->GetAllWindowArrayList()->GetCount());
117
118         // Goto the first scene.
119         SceneManager* pSceneManager = SceneManager::GetInstance();
120         if (pSceneManager == null)
121         {
122                 AppLogDebug("pSceneManager is null returning");
123                 return false;
124         }
125         // Create a Frame
126         MainFrame* pSceneManagementFrame = new(std::nothrow) MainFrame();
127         pSceneManagementFrame->Construct();
128         pSceneManagementFrame->SetName(L"SceneManagement");
129         AddFrame(*pSceneManagementFrame);
130
131         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
132         if (homePage == (L"IDS_BR_BODY_MOST_VISITED_SITES") || homePage == (L"IDS_BR_BODY_BLANK_PAGE"))
133         {
134                 homePage = L"";
135         }
136         else if (homePage == CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"))
137         {
138                 AppLog("InternetApp::OnAppInitialized homaepage = userhomepage");
139                 homePage = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
140                 AppLog("InternetApp::OnAppInitialized fav URL = %ls ",homePage.GetPointer());
141         }
142
143         if (__pNewWindowInfo == null)//if the application is launched normally
144         {
145                 __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(homePage);
146         }
147
148         if (__pNewWindowInfo == null)
149         {
150                 return false;
151         }
152
153         ArrayList* pArgList = new(std::nothrow) ArrayList();
154         pArgList->Construct();
155         pArgList->Add(*__pNewWindowInfo);
156         /*
157          * The GoForward call cannot be moved into the MainFrame::OnInitializing
158          * because when the application is launched from the appcontol, the data(URL)
159          * is not available for Mainframe, and we cannot pass the url information to
160          * the Mainframe because logically MainFrame should not know the URL information.
161          */
162         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
163         {
164                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
165                 delete pArgList;
166                 __pNewWindowInfo = null;
167                 return false;
168         }
169
170         delete pArgList;
171         pArgList = null;
172         __pNewWindowInfo = null;
173
174         return true;
175 }
176
177 bool
178 InternetApp::OnAppWillTerminate(void)
179 {
180         return true;
181 }
182
183
184 bool
185 InternetApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
186 {
187         AppLogDebug("Internet::OnAppTerminating");
188
189         return true;
190 }
191
192 void
193 InternetApp::OnForeground(void)
194 {
195
196 }
197
198 void
199 InternetApp::OnBackground(void)
200 {
201
202 }
203
204 void
205 InternetApp::OnLowMemory(void)
206 {
207
208 }
209
210 void
211 InternetApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
212 {
213
214 }
215
216 void
217 InternetApp::OnScreenOn(void)
218 {
219
220 }
221
222 void
223 InternetApp::OnScreenOff(void)
224 {
225         // TODO:
226         // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
227         // to enter the sleep mode to save the battery.
228         // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
229         // callback before the device enters the sleep mode.
230         // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
231 }
232 void
233 InternetApp::OnAppControlRequestReceived(RequestId reqId, const String &operationId, const String* pUriScheme, const String *pDataType, const IMap *pArgs)
234 {
235         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN entered %ls",operationId.GetPointer());
236
237         if (operationId.CompareTo(L"http://tizen.org/appcontrol/operation/view") == 0)
238         {
239                 String urlData;
240                 if (pUriScheme)
241                 {
242                         urlData = *pUriScheme;
243                 }
244                 else
245                 {
246                         int argCount = pArgs->GetCount();
247                         AppLog("argCount == %d", argCount);
248
249                         IList *pValues = pArgs->GetValuesN();
250                         if(pValues == null)
251                         {
252                                 AppLog("pValues == null");
253                                 return;
254                         }
255
256                         String url = L"url";
257                         String* pUrl = dynamic_cast<String*>(const_cast<Object*>(pArgs->GetValue(url)));
258                         if(pUrl == null)
259                         {
260                                 delete pValues;
261                                 AppLog("pUrl == null");
262                                 return;
263                         }
264                         urlData = *pUrl;
265                 }
266                 AppLog("URL received %ls", urlData.GetPointer());
267
268                 if (__pNewWindowInfo == null)
269                 {
270                         __pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(urlData, true);
271                 }
272                 if (__pNewWindowInfo == null)
273                 {
274                         if (MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
275                         {
276                                 String strTitle = L"Maximum Limit Reached";
277                                 String strText = L"cannot open more than 9 windows";
278                                 ShowPopup(strTitle, strText);
279                         }
280                         return;
281                 }
282                 if (__pMultiWindowManager != null && __pMultiWindowManager->GetAllWindowArrayList()->GetCount() != 0)
283                 {
284                         //if the application is running in background and it receives an appcontrol request it will launch a new(std::nothrow) window here,
285                         //otherwise appcontrol request will be handled by OnAppInitialized method
286                         SceneManager* pSceneManager = SceneManager::GetInstance();
287                         if (pSceneManager == null)
288                         {
289                                 return;
290                         }
291
292                         ArrayList* pArgList = new(std::nothrow) ArrayList();
293                         pArgList->Construct();
294                         pArgList->Add(*__pNewWindowInfo);
295
296                         if (E_SUCCESS != pSceneManager->GoForward(ForwardSceneTransition(__pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList))
297                         {
298                                 AppLogDebug("CustomAppControl::OnAppInitializing Result = %s", GetLastResult());
299                                                 delete pArgList;
300                                 __pNewWindowInfo = null;
301                                 return;
302                         }
303
304                         delete pArgList;
305
306                         __pNewWindowInfo = null;
307                 }
308         }
309         AppLogDebug("ABC::Internet::OnAppControlRequestReceivedN Exit");
310         return;
311 }
312