Fixed Nabi Issues N_SE-56606,N_SE-56568
[apps/osp/Internet.git] / src / IntMultipleWindowPresentationModel.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 MultipleWindowScene class
19 /*@file:        IntMultipleWindowScene.cpp
20  *@brief:       The MultipleWindowScene provides multiple instance of mainscenes and displays them in a Listview
21  *
22  */
23 #include <FUi.h>
24
25 #include "IntCommonLib.h"
26 #include "IntMultipleWindowPresentationModel.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Ui::Scenes;
33
34 MultipleWindowPresentationModel* MultipleWindowPresentationModel::__pMultiWindowManager = NULL;
35 ArrayList* MultipleWindowPresentationModel::__pAllWindowList = NULL;
36 HashMapT< Key, Object* > MultipleWindowPresentationModel::__keyAndValues;
37 int WindowInfo::__windowId = 0;
38 String  MultipleWindowPresentationModel::__currentSceneId = L"" ;
39 WindowInfo* MultipleWindowPresentationModel::__pCurWindowInfo = null;
40 Bitmap* WindowInfo::pFormCanvasBitmap = null;
41
42 WindowInfo::WindowInfo(void)
43 {
44         __windowId++;
45         ID = __windowId;
46         sceneID.Clear();
47         sceneID.Append(IDSCN_MAIN_VIEW);
48         sceneID.Append(ID);
49         formID.Clear();
50         formID.Append(IDL_FORM_MAIN_VIEW_SCENE);
51         formID.Append(ID);
52         isAppcontrolTriggered = false;
53         isJavascriptInitiated = false;
54         isFirstLaunch = true;
55         faviconFilePath = "";
56         faviconUrl = "";
57         pageUrl = L"";
58         pageTitle = "";
59         pFavicon = FaviconManager::GetInstance()->GetDefaultFaviconN();
60         pCurrentWeb = null;
61         pWebCanvasBitmap = null;
62         pFormCanvasBitmap = null;
63
64 }
65
66 WindowInfo::~WindowInfo(void)
67 {
68 //      if ( pFavicon != NULL)
69 //      {
70 //              delete pFavicon;
71 //              pFavicon = null;
72 //      }
73 }
74
75 MultipleWindowPresentationModel::MultipleWindowPresentationModel(void)
76 {
77         __isShowInProcess = false;
78 }
79
80 MultipleWindowPresentationModel::~MultipleWindowPresentationModel(void)
81 {
82         if (__pAllWindowList)
83         {
84                 delete __pAllWindowList;
85                 __pAllWindowList = NULL;
86         }
87         __keyAndValues.RemoveAll();
88 }
89
90 void
91 MultipleWindowPresentationModel::CreateInstance(void)
92 {
93         if (__pMultiWindowManager == NULL)
94         {
95                 __pMultiWindowManager = new(std::nothrow) MultipleWindowPresentationModel();
96                 result r = __pMultiWindowManager->Construct();
97                 if(IsFailed(r))
98                 {
99                         delete __pMultiWindowManager;
100                         __pMultiWindowManager = null;
101                 }
102         }
103 }
104
105 MultipleWindowPresentationModel*
106 MultipleWindowPresentationModel::GetInstance(void)
107 {
108         if (__pMultiWindowManager == NULL)
109         {
110                 CreateInstance();
111         }
112         return __pMultiWindowManager;
113 }
114
115
116 void
117 MultipleWindowPresentationModel::DestroyInstance(void)
118 {
119         if (__pMultiWindowManager)
120         {
121                 delete __pMultiWindowManager;
122                 __pMultiWindowManager = null;
123         }
124 }
125
126 result
127 MultipleWindowPresentationModel::Construct(void)
128 {
129         result r = E_SUCCESS;
130         __pAllWindowList = new(std::nothrow) ArrayList();
131          r = __pAllWindowList->Construct();
132          if(IsFailed(r))
133          {
134                  return r;
135          }
136         r = __keyAndValues.Construct();
137         if(IsFailed(r))
138         {
139                 return r;
140         }
141         return E_SUCCESS;
142 }
143
144 void
145 MultipleWindowPresentationModel::UnInitialize(void)
146 {
147         AppLogDebug(" MultiWindowManager::Denitialize");
148         return;
149 }
150
151 result
152 MultipleWindowPresentationModel::AddWindoInfo(WindowInfo* pWindowInfo)
153 {
154         result r = E_FAILURE;
155
156         if (pWindowInfo != NULL)
157         {
158                 r = __pAllWindowList->Add(*pWindowInfo);
159         }
160
161         return r;
162 }
163
164 ArrayList*
165 MultipleWindowPresentationModel::GetAllWindowArrayList(void)
166 {
167         return __pAllWindowList;
168 }
169
170 result
171 MultipleWindowPresentationModel::GetValue(Key key, Object** value)
172 {
173         result r = E_FAILURE;
174         bool containKey = false;
175
176         AppLogDebug("Workspace::GetValue");
177         r = __keyAndValues.ContainsKey(key, containKey);
178         TryCatch(!IsFailed(r),,"ContainsKey failed %s",GetErrorMessage(r));
179
180         if (containKey == true)
181                 r = __keyAndValues.GetValue(key, *value);
182
183         CATCH:
184         return r;
185 }
186
187 result
188 MultipleWindowPresentationModel::SetValue(Key key, Object* value)
189 {
190         result r = E_FAILURE;
191         bool containKey = false;
192
193         r = __keyAndValues.ContainsKey(key, containKey);
194         TryCatch(!IsFailed(r),,"ContainsKey failed %s",GetErrorMessage(r));
195
196         if (containKey == false)
197                 r = __keyAndValues.Add(key, value);
198         else
199                 r = __keyAndValues.SetValue(key, value);
200
201         CATCH:
202         return r;
203 }
204
205 WindowInfo*
206 MultipleWindowPresentationModel::CreateNewMainViewSceneN(const String& Url, bool isAppControlTriggered)
207 {
208
209         if (GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
210         {
211                 AppLog("9 windows already opened");
212
213                 String strTitle = L"";//CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
214                 String strText = CommonUtil::GetString(L"IDS_BR_BODY_COULD_NOT_OPEN_NEW_WINDOW_BECAUSE_YOU_HAVE_ALREADY_OPENED_MAXIMUM_NUMBER");
215                 ShowPopup(strTitle, strText);
216 //              ShowPopup(strTitle, strText);
217 //              ShowPopup(strTitle, strText);
218
219                 return null;
220         }
221         WindowInfo* pWindowInfo = new(std::nothrow) WindowInfo();
222         if (pWindowInfo == NULL)
223         {
224                 return null;
225         }
226         pWindowInfo->pageTitle = CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE");
227         pWindowInfo->pageUrl = Url;
228         pWindowInfo->isAppcontrolTriggered = isAppControlTriggered;
229         MultipleWindowPresentationModel::GetInstance()->AddWindoInfo(pWindowInfo);
230         SceneRegister::RegisterNewMainView(pWindowInfo->sceneID, pWindowInfo->formID);
231
232         return pWindowInfo;
233 }
234
235
236 void
237 MultipleWindowPresentationModel::SetCurrentSceneID(const String& currentSceneId)
238 {
239
240         __currentSceneId.Clear();
241         __currentSceneId.Append(currentSceneId);
242         for (int index = 0; index < GetInstance()->GetAllWindowArrayList()->GetCount(); index ++)
243         {
244                 WindowInfo* pWindowInfo = static_cast< WindowInfo* >(GetInstance()->GetAllWindowArrayList()->GetAt(index));
245
246                 if ( pWindowInfo == NULL )
247                 {
248                         return;
249                 }
250
251                 if (pWindowInfo->sceneID.CompareTo(__currentSceneId) == 0)
252                 {
253                         __pCurWindowInfo = pWindowInfo;
254                 }
255         }
256
257         return ;
258 }
259
260 void
261 MultipleWindowPresentationModel::GetCurrentSceneId(String& currentSceneId)
262 {
263         currentSceneId = __currentSceneId;
264         return ;
265 }
266
267 WindowInfo*
268 MultipleWindowPresentationModel::GetActiveWindowInfo()
269 {
270         return __pCurWindowInfo;
271 }
272
273
274 void
275 MultipleWindowPresentationModel::ShowPopup(String& pTitle, String& pText)
276 {
277         if(__isShowInProcess)
278                 return;
279
280         MessageBox* pMessageBox = new(std::nothrow) MessageBox();
281         pMessageBox->Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
282         int modalResult = 0;
283         __isShowInProcess = true;
284         pMessageBox->ShowAndWait(modalResult);
285         __isShowInProcess = false;
286
287         delete pMessageBox;
288 }