Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StPrivacyDetailForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                StPrivacyDetailForm.cpp
19  * @brief               This is the implementation file for PrivacyDetailForm class.
20  */
21
22 #include "StPrivacyDetailForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
25 #include "StTypes.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Security;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int ID_GROUP_COUNT = 1;
37
38 PrivacyDetailForm::PrivacyDetailForm(void)
39         : __pPrivacyManager(null)
40         , __pPrivateDataList(null)
41         , __packageId(L"")
42 {
43 }
44
45 PrivacyDetailForm::~PrivacyDetailForm(void)
46 {
47 }
48
49 void
50 PrivacyDetailForm::CreateFooter(void)
51 {
52         Footer* pFooter = GetFooter();
53         AppAssert(pFooter);
54
55         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
56         pFooter->SetBackButton();
57         pFooter->AddActionEventListener(*this);
58
59         SetFormBackEventListener(this);
60 }
61
62 result
63 PrivacyDetailForm::OnInitializing(void)
64 {
65         AppLogDebug("Enter");
66
67         __pPrivacyManager = PrivacyManager::GetInstance();
68         if (__pPrivacyManager == null)
69         {
70                 AppLogDebug("__pPrivacyManager == null");
71                 return E_FAILURE;
72         }
73
74         return E_SUCCESS;
75 }
76
77 result
78 PrivacyDetailForm::OnTerminating(void)
79 {
80         __pPrivateDataList->RemoveAll(true);
81         __pPrivateDataList = null;
82
83         __pPrivacyManager = null;
84         __pTableView = null;
85
86         SetFormBackEventListener(null);
87         return E_SUCCESS;
88 }
89
90 void
91 PrivacyDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
92 {
93         AppLogDebug("Enter");
94
95         if (pArgs == null)
96         {
97                 AppLogDebug("pArgs is null. Can't make detail form");
98                 return;
99         }
100         __pPrivateDataList = new (std::nothrow) ArrayList(SingleObjectDeleter);
101         __pPrivateDataList->Construct();
102
103         __packageId = *static_cast<String*>(pArgs->GetAt(0));
104         String title = *static_cast<String*>(pArgs->GetAt(1));
105         String data = *static_cast<String*>(pArgs->GetAt(2));
106         String item;
107
108         StringTokenizer token(data, L", ");
109
110         do {
111                 token.GetNextToken(item);
112                 __pPrivateDataList->Add(new (std::nothrow) String(item));
113         }
114         while (token.HasMoreTokens() == true);
115
116         delete pArgs;
117
118         CreateHeader(title);
119         CreateFooter();
120         CreateTableView();
121
122         __pTableView->UpdateTableView();
123         for (int index = 0; index < __pPrivateDataList->GetCount(); index++)
124         {
125                 PrivacyInfo* pPrivacyInfo = GetPrivacyInfo(index);
126                 __pTableView->SetItemChecked(0, index, pPrivacyInfo->IsEnabled());
127         }
128 }
129
130 void
131 PrivacyDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
132 {
133 }
134
135 void
136 PrivacyDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
137 {
138         SceneManager* pSceneManager = SceneManager::GetInstance();
139         AppAssert(pSceneManager);
140         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
141 }
142
143 int
144 PrivacyDetailForm::GetGroupCount(void)
145 {
146         AppLogDebug("ENTER");
147         return ID_GROUP_COUNT;
148 }
149
150 int
151 PrivacyDetailForm::GetItemCount(int groupIndex)
152 {
153         int itemCount = 0;
154
155         if (__pPrivateDataList)
156         {
157                 itemCount = __pPrivateDataList->GetCount();
158         }
159
160         AppLogDebug("GetItemCount %d", itemCount);
161
162         return itemCount;
163 }
164
165 TableViewGroupItem*
166 PrivacyDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
167 {
168         AppLogDebug("ENTER");
169
170         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
171         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
172         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
173         Rectangle itemMainRectangle;
174         String groupText;
175         Label* pLabel = null;
176         int fontSize = GetFontSize();
177
178         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
179
180         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
181         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
182
183         itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
184         itemMainRectangle.y = yItemOffset;
185         itemMainRectangle.width = itemWidth;
186         itemMainRectangle.height = itemHeight;
187
188         RelativeLayout relativeLayout;
189         relativeLayout.Construct();
190
191         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
192         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
193
194         pLabel = new (std::nothrow) Label();
195         pLabel->Construct(itemMainRectangle, groupText);
196         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
197         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
198         pLabel->SetTextConfig(fontSize, style);
199         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
200
201         pItem->AddControl(pLabel);
202         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
203         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
204         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
205         pItem->SetEnabled(false);
206
207         return pItem;
208 }
209
210 TableViewItem*
211 PrivacyDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
212 {
213         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
214
215         Rectangle itemMainRectangle;
216         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
217         String itemMainText;
218         String fontReturnValue;
219         Label* pLabel = null;
220
221         int fontSize = GetFontSize();
222         itemMainText = *static_cast<String*>(__pPrivateDataList->GetAt(itemIndex));
223
224         ItemTypeOneLine(itemMainRectangle);
225
226         TableViewItem* pItem = new (std::nothrow) TableViewItem();
227
228         RelativeLayout relativeLayout;
229         relativeLayout.Construct();
230
231         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
232         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
233
234
235         pLabel = new (std::nothrow) Label();
236         pLabel->Construct(itemMainRectangle, itemMainText);
237         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
238         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
239         pLabel->SetTextColor(COLOR_MAIN_TEXT);
240
241         pItem->AddControl(pLabel);
242         relativeLayout.SetMargin(*pLabel, RELATIVE_LAYOUT_LEFT_MARGIN, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
243         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
244         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
245
246         return pItem;
247 }
248
249 bool
250 PrivacyDetailForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
251 {
252         AppLogDebug("ENTER");
253
254         delete pItem;
255         pItem = null;
256
257         return true;
258 }
259
260 bool
261 PrivacyDetailForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
262 {
263         AppLogDebug("ENTER");
264
265         delete pItem;
266         pItem = null;
267
268         return true;
269 }
270
271 void
272 PrivacyDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
273 {
274         result r = E_FAILURE;
275         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
276
277         r = SetPrivacyInfo(itemIndex, tableView.IsItemChecked(groupIndex, itemIndex));
278         if (IsFailed(r))
279         {
280                 AppLogDebug("SetPrivacyInfo fail[%s]", GetErrorMessage(r));
281         }
282 }
283
284 result
285 PrivacyDetailForm::SetPrivacyInfo(int itemIndex, bool enable)
286 {
287         result r = E_FAILURE;
288
289         PrivacyInfo* pPrivacyInfo = GetPrivacyInfo(itemIndex);
290         pPrivacyInfo->SetEnabled(enable);
291
292         r = __pPrivacyManager->SetAppPackagePrivacy(__packageId, *pPrivacyInfo);
293         if (IsFailed(r))
294         {
295                 AppLogDebug("SetAppPackagePrivacy fail [%s]", GetErrorMessage(r));
296         }
297
298         return r;
299 }
300
301 Tizen::Security::PrivacyInfo*
302 PrivacyDetailForm::GetPrivacyInfo(int itemIndex)
303 {
304         if (__pPrivacyManager == null)
305         {
306                 AppLogDebug("pPrivacyManager is null");
307                 return null;
308         }
309
310         PrivacyInfo* pPrivacyInfo;
311         ArrayList* privacyListInfo = static_cast<ArrayList*>(__pPrivacyManager->GetPrivacyInfoListN(__packageId));
312         if (privacyListInfo == null)
313         {
314                 AppLogDebug("privacyListInfo is null");
315                 return null;
316         }
317
318         pPrivacyInfo = static_cast<PrivacyInfo*>(privacyListInfo->GetAt(itemIndex));
319         if (pPrivacyInfo == null)
320         {
321                 AppLogDebug("pPrivacyInfo is null");
322                 return null;
323         }
324
325         return pPrivacyInfo;
326 }
327
328 int
329 PrivacyDetailForm::GetDefaultGroupItemHeight(void)
330 {
331         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
332 }
333
334 int
335 PrivacyDetailForm::GetDefaultItemHeight(void)
336 {
337         return H_GROUP_ITEM_DEFAULT;
338 }
339
340 void
341 PrivacyDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
342 {
343 }
344
345 void
346 PrivacyDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
347 {
348         Invalidate(true);
349 }
350
351 void
352 PrivacyDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
353 {
354 }
355
356 void
357 PrivacyDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
358 {
359 }