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