2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file StPrivacyDetailForm.cpp
19 * @brief This is the implementation file for PrivacyDetailForm class.
22 #include "StPrivacyDetailForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
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;
36 static const int ID_GROUP_COUNT = 1;
38 PrivacyDetailForm::PrivacyDetailForm(void)
39 : __pPrivacyManager(null)
40 , __pPrivateDataList(null)
45 PrivacyDetailForm::~PrivacyDetailForm(void)
50 PrivacyDetailForm::CreateFooter(void)
52 Footer* pFooter = GetFooter();
55 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
56 pFooter->SetBackButton();
57 pFooter->AddActionEventListener(*this);
59 SetFormBackEventListener(this);
63 PrivacyDetailForm::OnInitializing(void)
67 __pPrivacyManager = PrivacyManager::GetInstance();
68 if (__pPrivacyManager == null)
70 AppLogDebug("__pPrivacyManager == null");
78 PrivacyDetailForm::OnTerminating(void)
80 __pPrivateDataList->RemoveAll(true);
81 __pPrivateDataList = null;
83 __pPrivacyManager = null;
86 SetFormBackEventListener(null);
91 PrivacyDetailForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
97 AppLogDebug("pArgs is null. Can't make detail form");
100 __pPrivateDataList = new (std::nothrow) ArrayList(SingleObjectDeleter);
101 __pPrivateDataList->Construct();
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));
108 StringTokenizer token(data, L", ");
111 token.GetNextToken(item);
112 __pPrivateDataList->Add(new (std::nothrow) String(item));
114 while (token.HasMoreTokens() == true);
122 __pTableView->UpdateTableView();
123 for (int index = 0; index < __pPrivateDataList->GetCount(); index++)
125 PrivacyInfo* pPrivacyInfo = GetPrivacyInfo(index);
126 __pTableView->SetItemChecked(0, index, pPrivacyInfo->IsEnabled());
131 PrivacyDetailForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
136 PrivacyDetailForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
138 SceneManager* pSceneManager = SceneManager::GetInstance();
139 AppAssert(pSceneManager);
140 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
144 PrivacyDetailForm::GetGroupCount(void)
146 AppLogDebug("ENTER");
147 return ID_GROUP_COUNT;
151 PrivacyDetailForm::GetItemCount(int groupIndex)
155 if (__pPrivateDataList)
157 itemCount = __pPrivateDataList->GetCount();
160 AppLogDebug("GetItemCount %d", itemCount);
166 PrivacyDetailForm::CreateGroupItem(int groupIndex, int itemWidth)
168 AppLogDebug("ENTER");
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;
175 Label* pLabel = null;
176 int fontSize = GetFontSize();
178 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
180 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
181 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
183 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
184 itemMainRectangle.y = yItemOffset;
185 itemMainRectangle.width = itemWidth;
186 itemMainRectangle.height = itemHeight;
188 RelativeLayout relativeLayout;
189 relativeLayout.Construct();
191 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
192 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
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);
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);
211 PrivacyDetailForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
213 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
215 Rectangle itemMainRectangle;
216 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_MARK;
218 String fontReturnValue;
219 Label* pLabel = null;
221 int fontSize = GetFontSize();
222 itemMainText = *static_cast<String*>(__pPrivateDataList->GetAt(itemIndex));
224 ItemTypeOneLine(itemMainRectangle);
226 TableViewItem* pItem = new (std::nothrow) TableViewItem();
228 RelativeLayout relativeLayout;
229 relativeLayout.Construct();
231 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
232 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
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);
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);
250 PrivacyDetailForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
252 AppLogDebug("ENTER");
261 PrivacyDetailForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
263 AppLogDebug("ENTER");
272 PrivacyDetailForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
274 result r = E_FAILURE;
275 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
277 r = SetPrivacyInfo(itemIndex, tableView.IsItemChecked(groupIndex, itemIndex));
280 AppLogDebug("SetPrivacyInfo fail[%s]", GetErrorMessage(r));
285 PrivacyDetailForm::SetPrivacyInfo(int itemIndex, bool enable)
287 result r = E_FAILURE;
289 PrivacyInfo* pPrivacyInfo = GetPrivacyInfo(itemIndex);
290 pPrivacyInfo->SetEnabled(enable);
292 r = __pPrivacyManager->SetAppPackagePrivacy(__packageId, *pPrivacyInfo);
295 AppLogDebug("SetAppPackagePrivacy fail [%s]", GetErrorMessage(r));
301 Tizen::Security::PrivacyInfo*
302 PrivacyDetailForm::GetPrivacyInfo(int itemIndex)
304 if (__pPrivacyManager == null)
306 AppLogDebug("pPrivacyManager is null");
310 PrivacyInfo* pPrivacyInfo;
311 ArrayList* privacyListInfo = static_cast<ArrayList*>(__pPrivacyManager->GetPrivacyInfoListN(__packageId));
312 if (privacyListInfo == null)
314 AppLogDebug("privacyListInfo is null");
318 pPrivacyInfo = static_cast<PrivacyInfo*>(privacyListInfo->GetAt(itemIndex));
319 if (pPrivacyInfo == null)
321 AppLogDebug("pPrivacyInfo is null");
329 PrivacyDetailForm::GetDefaultGroupItemHeight(void)
331 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
335 PrivacyDetailForm::GetDefaultItemHeight(void)
337 return H_GROUP_ITEM_DEFAULT;
341 PrivacyDetailForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
346 PrivacyDetailForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
352 PrivacyDetailForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
357 PrivacyDetailForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)