Fixed Nabi Issues
[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         faviconFilePath = "";
55         faviconUrl = "";
56         pageUrl = L"";
57         pageTitle = "";
58         pFavicon = FaviconManager::GetInstance()->GetDefaultFaviconN();
59         pCurrentWeb = null;
60         pWebCanvasBitmap = null;
61         pFormCanvasBitmap = null;
62 }
63
64 WindowInfo::~WindowInfo(void)
65 {
66 //      if ( pFavicon != NULL)
67 //      {
68 //              delete pFavicon;
69 //              pFavicon = null;
70 //      }
71 }
72
73 MultipleWindowPresentationModel::MultipleWindowPresentationModel(void)
74 {
75
76 }
77
78 MultipleWindowPresentationModel::~MultipleWindowPresentationModel(void)
79 {
80         if (__pAllWindowList)
81         {
82                 delete __pAllWindowList;
83                 __pAllWindowList = NULL;
84         }
85         __keyAndValues.RemoveAll();
86 }
87
88 void
89 MultipleWindowPresentationModel::CreateInstance(void)
90 {
91         if (__pMultiWindowManager == NULL)
92         {
93                 __pMultiWindowManager = new(std::nothrow) MultipleWindowPresentationModel();
94                 result r = __pMultiWindowManager->Construct();
95                 if(IsFailed(r))
96                 {
97                         delete __pMultiWindowManager;
98                         __pMultiWindowManager = null;
99                 }
100         }
101 }
102
103 MultipleWindowPresentationModel*
104 MultipleWindowPresentationModel::GetInstance(void)
105 {
106         if (__pMultiWindowManager == NULL)
107         {
108                 CreateInstance();
109         }
110         return __pMultiWindowManager;
111 }
112
113
114 void
115 MultipleWindowPresentationModel::DestroyInstance(void)
116 {
117         if (__pMultiWindowManager)
118         {
119                 delete __pMultiWindowManager;
120                 __pMultiWindowManager = null;
121         }
122 }
123
124 result
125 MultipleWindowPresentationModel::Construct(void)
126 {
127         result r = E_SUCCESS;
128         __pAllWindowList = new(std::nothrow) ArrayList();
129          r = __pAllWindowList->Construct();
130          if(IsFailed(r))
131          {
132                  return r;
133          }
134         r = __keyAndValues.Construct();
135         if(IsFailed(r))
136         {
137                 return r;
138         }
139         return E_SUCCESS;
140 }
141
142 void
143 MultipleWindowPresentationModel::UnInitialize(void)
144 {
145         AppLogDebug(" MultiWindowManager::Denitialize");
146         return;
147 }
148
149 result
150 MultipleWindowPresentationModel::AddWindoInfo(WindowInfo* pWindowInfo)
151 {
152         result r = E_FAILURE;
153
154         if (pWindowInfo != NULL)
155         {
156                 r = __pAllWindowList->Add(*pWindowInfo);
157         }
158
159         return r;
160 }
161
162 ArrayList*
163 MultipleWindowPresentationModel::GetAllWindowArrayList(void)
164 {
165         return __pAllWindowList;
166 }
167
168 result
169 MultipleWindowPresentationModel::GetValue(Key key, Object** value)
170 {
171         result r = E_FAILURE;
172         bool containKey = false;
173
174         AppLogDebug("Workspace::GetValue");
175         r = __keyAndValues.ContainsKey(key, containKey);
176         TryCatch(!IsFailed(r),,"ContainsKey failed %s",GetErrorMessage(r));
177
178         if (containKey == true)
179                 r = __keyAndValues.GetValue(key, *value);
180
181         CATCH:
182         return r;
183 }
184
185 result
186 MultipleWindowPresentationModel::SetValue(Key key, Object* value)
187 {
188         result r = E_FAILURE;
189         bool containKey = false;
190
191         r = __keyAndValues.ContainsKey(key, containKey);
192         TryCatch(!IsFailed(r),,"ContainsKey failed %s",GetErrorMessage(r));
193
194         if (containKey == false)
195                 r = __keyAndValues.Add(key, value);
196         else
197                 r = __keyAndValues.SetValue(key, value);
198
199         CATCH:
200         return r;
201 }
202
203 WindowInfo*
204 MultipleWindowPresentationModel::CreateNewMainViewSceneN(const String& Url, bool isAppControlTriggered)
205 {
206
207         if (GetInstance()->GetAllWindowArrayList()->GetCount() >= 9)
208         {
209                 AppLog("9 windows already opened");
210
211                 String strTitle = L"";//CommonUtil::GetString(L"IDS_COM_SK_MAX_LIMIT_REACHED");
212                 String strText = CommonUtil::GetString(L"IDS_BR_BODY_COULD_NOT_OPEN_NEW_WINDOW_BECAUSE_YOU_HAVE_ALREADY_OPENED_MAXIMUM_NUMBER");
213                 ShowPopup(strTitle, strText);
214
215                 return null;
216         }
217         WindowInfo* pWindowInfo = new(std::nothrow) WindowInfo();
218         if (pWindowInfo == NULL)
219         {
220                 return null;
221         }
222         pWindowInfo->pageTitle = CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK");
223         pWindowInfo->pageUrl = Url;
224         pWindowInfo->isAppcontrolTriggered = isAppControlTriggered;
225         MultipleWindowPresentationModel::GetInstance()->AddWindoInfo(pWindowInfo);
226         SceneRegister::RegisterNewMainView(pWindowInfo->sceneID, pWindowInfo->formID);
227
228         return pWindowInfo;
229 }
230
231
232 void
233 MultipleWindowPresentationModel::SetCurrentSceneID(const String& currentSceneId)
234 {
235
236         __currentSceneId.Clear();
237         __currentSceneId.Append(currentSceneId);
238         for (int index = 0; index < GetInstance()->GetAllWindowArrayList()->GetCount(); index ++)
239         {
240                 WindowInfo* pWindowInfo = static_cast< WindowInfo* >(GetInstance()->GetAllWindowArrayList()->GetAt(index));
241
242                 if ( pWindowInfo == NULL )
243                 {
244                         return;
245                 }
246
247                 if (pWindowInfo->sceneID.CompareTo(__currentSceneId) == 0)
248                 {
249                         __pCurWindowInfo = pWindowInfo;
250                 }
251         }
252
253         return ;
254 }
255
256 void
257 MultipleWindowPresentationModel::GetCurrentSceneId(String& currentSceneId)
258 {
259         currentSceneId = __currentSceneId;
260         return ;
261 }
262
263 WindowInfo*
264 MultipleWindowPresentationModel::GetActiveWindowInfo()
265 {
266         return __pCurWindowInfo;
267 }
268
269
270 void
271 MultipleWindowPresentationModel::ShowPopup(String& pTitle, String& pText)
272 {
273         MessageBox messageBox;
274         messageBox.Construct(pTitle, pText,MSGBOX_STYLE_OK,3000);
275         int modalResult = 0;
276
277         messageBox.ShowAndWait(modalResult);
278         switch (modalResult)
279         {
280         case MSGBOX_RESULT_OK:
281         {
282
283         }
284         break;
285         default:
286                 break;
287         }
288 }