add to resume event
[apps/osp/Internet.git] / src / IntSettingClearPrivateDataForm.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 SettingsClearPrivateDataForm class
19 /*@file: IntSettingsClearPrivateDataForm.cpp
20  *@brief:        The SettingsClearPrivateDataForm used to create private data scene
21  *
22  */
23
24 #include <FAppUiApp.h>
25 #include <FUi.h>
26 #include "IntSettingClearPrivateDataForm.h"
27 #include "IntSceneRegister.h"
28 #include "IntHistoryPresentationModel.h"
29 #include "IntSettingPresentationModel.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 const int SettingsClearPrivateDataForm::IDA_FORMAT_TITLE_STRING = 101;
40 const int SettingsClearPrivateDataForm::IDA_BUTTON_DELETE = 102;
41 const int SettingsClearPrivateDataForm::IDA_BUTTON_CANCEL = 103;
42
43 SettingsClearPrivateDataForm::SettingsClearPrivateDataForm()
44         : __pList(null)
45         , __clearItem(5)
46 {
47 }
48
49 SettingsClearPrivateDataForm::~SettingsClearPrivateDataForm()
50 {
51 }
52
53 bool
54 SettingsClearPrivateDataForm::Initialize(void)
55 {
56         Construct(L"IDL_SETTINGS_CLEAR_PRIVATE_DATA");
57         //SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
58         return true;
59 }
60
61 result
62 SettingsClearPrivateDataForm::OnInitializing(void)
63 {
64         result r = E_SUCCESS;
65         SceneManager* pSceneManager = SceneManager::GetInstance();
66         if (pSceneManager == null)
67         {
68                 return E_FAILURE;
69         }
70
71         Footer* pFooter = GetFooter();
72
73         if ( pFooter == null)
74         {
75                 return E_FAILURE;
76         }
77         FooterItem deleteButton;
78         FooterItem cancelButton;
79
80         SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
81
82         r = pSceneManager->AddSceneEventListener(IDSCN_SETTINGS_CLEAR_PRIVATE_DATA, *this);
83
84         // Setup back event listener
85         SetFormBackEventListener(this);
86         pFooter->AddActionEventListener(*this);
87
88         __pList = static_cast< ListView* >(GetControl(L"IDC_CLEAR_LISTVIEW"));
89         if (__pList != null)
90         {
91                 __pList->SetItemProvider(*this);
92                 __pList->AddListViewItemEventListener(*this);
93         }
94
95         AddOrientationEventListener(*this);
96
97         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
98         deleteButton.Construct(IDA_BUTTON_DELETE);
99         deleteButton.SetText(L"Delete");
100
101         pFooter->AddItem(deleteButton);
102         cancelButton.Construct(IDA_BUTTON_CANCEL);
103         cancelButton.SetText(L"Cancel");
104
105         pFooter->AddItem(cancelButton);
106         pFooter->SetItemEnabled(0, false);
107         return r;
108 }
109
110 result
111 SettingsClearPrivateDataForm::OnTerminating(void)
112 {
113         result r = E_SUCCESS;
114         return r;
115 }
116
117 void
118 SettingsClearPrivateDataForm::OnActionPerformed(const Control& source, int actionId)
119 {
120         Footer* pFooter = GetFooter();
121         if ( pFooter == NULL )
122         {
123                 return;
124         }
125
126         SceneManager* pSceneManager = SceneManager::GetInstance();
127         if (pSceneManager == null)
128         {
129                 return;
130         }
131         switch (actionId)
132         {
133         case IDA_BUTTON_DELETE:
134         {
135                 AppLog("Delete button is called");
136                 if (__pList)
137                 {
138                         if (__pList->IsItemChecked(0) || __pList->IsItemChecked(1) || __pList->IsItemChecked(2) || __pList->IsItemChecked(3) || __pList->IsItemChecked(4))
139                         {
140                                 pFooter->SetItemEnabled(0, true);
141                                 pFooter->Invalidate(true);
142
143                                 // Delete the specific index setting
144                                 if (__pList->IsItemChecked(0) == true)
145                                 {
146                                         // clear all private data
147                                         AppLog("Clear all private data");
148                                         HistoryPresentationModel::GetInstance()->ClearHistory();
149                                         SettingPresentationModel::GetInstance()->ClearCache();
150                                         SettingPresentationModel::GetInstance()->ClearCookie();
151                                 }
152                                 if (__pList->IsItemChecked(1) == true)
153                                 {
154                                         // clear History
155                                         AppLog("Clear all History data");
156                                 HistoryPresentationModel::GetInstance()->ClearHistory();
157                                 }
158                                 if (__pList->IsItemChecked(2) == true)
159                                 {
160                                         // clear cache
161                                         AppLog("Clear all cache data");
162                                         SettingPresentationModel::GetInstance()->ClearCache();
163                                 }
164                                 if (__pList->IsItemChecked(3) == true)
165                                 {
166                                         // clear cookie
167                                         AppLog("Clear all cookie data");
168                                         SettingPresentationModel::GetInstance()->ClearCookie();
169                                 }
170                                 else if (__pList->IsItemChecked(4) == true)
171                                 {
172                                         // clear saved ID and password
173                                         AppLog("Clear saved ID and password");
174                                 }
175                         }
176                         else
177                         {
178                                 pFooter->SetItemEnabled(0, false);
179                                 pFooter->Invalidate(true);
180                         }
181                 }
182                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
183         }
184         break;
185
186         case IDA_BUTTON_CANCEL:
187         {
188                 AppLog("cancel button is called");
189                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
190         }
191         break;
192
193         default:
194                 break;
195         }
196 }
197
198 void
199 SettingsClearPrivateDataForm::OnFormBackRequested(Form& source)
200 {
201         SceneManager* pSceneManager = SceneManager::GetInstance();
202         if (pSceneManager == null)
203         {
204                 return;
205         }
206         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SETTINGS,  SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
207 }
208
209 void
210 SettingsClearPrivateDataForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
211 {
212         if (__pList)
213         {
214                 __pList->UpdateList();
215         }
216         return;
217 }
218
219 void
220 SettingsClearPrivateDataForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
221 {
222         return;
223 }
224
225 void
226 SettingsClearPrivateDataForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
227 {
228         return;
229 }
230
231 void
232 SettingsClearPrivateDataForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
233 {
234
235         bool checkstatus = __pList->IsItemChecked(index);
236
237         if (index == 0)
238         {
239                 if (!checkstatus)
240                 {
241                         __pList->SetItemChecked(0, false);
242                         __pList->SetItemChecked(1, false);
243                         __pList->SetItemChecked(2, false);
244                         __pList->SetItemChecked(3, false);
245                         __pList->SetItemChecked(4, false);
246                 }
247                 else
248                 {
249                         __pList->SetItemChecked(0, true);
250                         __pList->SetItemChecked(1, true);
251                         __pList->SetItemChecked(2, true);
252                         __pList->SetItemChecked(3, true);
253                         __pList->SetItemChecked(4, true);
254                 }
255         }
256         if (__pList->IsItemChecked(0) || __pList->IsItemChecked(1) || __pList->IsItemChecked(2) || __pList->IsItemChecked(3) || __pList->IsItemChecked(4))
257         {
258                 GetFooter()->SetItemEnabled(0, true);
259                 GetFooter()->Invalidate(true);
260         }
261         else
262         {
263                 GetFooter()->SetItemEnabled(0, false);
264                 GetFooter()->Invalidate(true);
265         }
266         return;
267 }
268
269 void
270 SettingsClearPrivateDataForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
271 {
272         return;
273 }
274
275 void
276 SettingsClearPrivateDataForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
277 {
278         return;
279 }
280
281 ListItemBase*
282 SettingsClearPrivateDataForm::CreateItem(int index, int itemWidth)
283 {
284         Rectangle pagetTitleRect;
285         CustomItem* pItem = new(std::nothrow) CustomItem();
286         ListAnnexStyle style = LIST_ANNEX_STYLE_MARK;
287         pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 112), style);
288         Rectangle screenBounds = GetBounds();
289
290         pagetTitleRect.SetBounds(screenBounds.x + 15, 38, screenBounds.width - 10, 40);
291
292         if (index == 0)
293         {
294                 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, L"Select all", 38, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
295         }
296         else if (index == 1)
297         {
298                 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, L"History", 38, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
299         }
300         else if (index == 2)
301         {
302                 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, L"Cache", 38, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
303         }
304         else if (index == 3)
305         {
306                 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, L"Cookie", 38, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
307         }
308         else if (index == 4)
309         {
310                 pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, L"Saved ID and password", 38, Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), Color::GetColor(COLOR_ID_BLACK), true);
311         }
312
313         return pItem;
314 }
315
316 bool
317 SettingsClearPrivateDataForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
318 {
319         delete pItem;
320         pItem = null;
321         return true;
322 }
323
324 int
325 SettingsClearPrivateDataForm::GetItemCount(void)
326 {
327         return __clearItem;
328 }
329
330 void
331 SettingsClearPrivateDataForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
332 {
333         if (__pList)
334         {
335                 __pList->UpdateList();
336         }
337         return;
338 }