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 StManageApplicationForm.cpp
19 * @brief This is the implementation file for ManageApplicationForm class.
22 #include "StManageApplicationForm.h"
23 #include "StResourceManager.h"
24 #include "StSettingScenesList.h"
27 using namespace Tizen::App;
28 using namespace Tizen::App::Package;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
37 static const int IDA_UNINSTALL_OK = 400;
39 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 160;
40 static const int X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 26;
41 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
42 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
43 static const int W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 690;
44 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 12;
45 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 360;
46 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 620;
47 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
48 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
50 static const int W_ALERT_POPUP_CLIENT_RECT_DEFAULT = 700;
51 static const int H_ALERT_POPUP_CLIENT_RECT_DEFAULT = 550;
53 static const int BYTE_TO_KILOBYTE = 1024;
57 DATA_TYPE_APPLICATION_NAME = 0,
58 DATA_TYPE_APPLICATION_ICON_PATH,
59 DATA_TYPE_APPLICATION_UNINSTALLABLE,
60 DATA_TYPE_APPLICATION_SIZE,
61 DATA_TYPE_APPLICATION_DATA_SIZE,
62 DATA_TYPE_APPLICATION_ID,
63 DATA_TYPE_APPLICATION_PACKAGE_ID,
66 ManageApplicationForm::ManageApplicationForm(void)
67 : __pPackageInfoList(null)
68 , __uninstallResultPopup(null)
72 ManageApplicationForm::~ManageApplicationForm(void)
77 ManageApplicationForm::CreateHeaderStyleTab(void)
79 #ifdef HEADER_HAS_THREE_TAB
80 Header* pHeader = GetHeader();
81 pHeader->SetStyle(HEADER_STYLE_TAB_WITH_TITLE);
82 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS"));
84 HeaderItem headerItemApplication;
85 headerItemApplication.Construct(IDA_HEADER_APPLICATION);
86 headerItemApplication.SetText(ResourceManager::GetString(L"IDS_ST_BODY_APPLICATION"));
88 HeaderItem headerItemRunning;
89 headerItemRunning.Construct(IDA_HEADER_RUNNING);
90 headerItemRunning.SetText(L"Running");
92 HeaderItem headerItemAll;
93 headerItemAll.Construct(IDA_HEADER_ALL);
94 headerItemAll.SetText(ResourceManager::GetString(L"IDS_ST_OPT_ALL"));
96 pHeader->AddItem(headerItemApplication);
97 pHeader->AddItem(headerItemRunning);
98 pHeader->AddItem(headerItemAll);
99 pHeader->AddActionEventListener(*this);
101 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS"));
106 ManageApplicationForm::CreateFooter(void)
108 Footer* pFooter = GetFooter();
111 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
112 pFooter->AddActionEventListener(*this);
114 SetFormBackEventListener(this);
118 ManageApplicationForm::GetPackageInfoItem(int index, int type)
121 PackageInfo* pPackageInfo = static_cast<PackageInfo*>(__pPackageInfoList->GetAt(index));
125 case DATA_TYPE_APPLICATION_NAME:
127 data = pPackageInfo->GetDisplayName();
131 case DATA_TYPE_APPLICATION_ICON_PATH:
133 IList* pPackageAppInfoList = pPackageInfo->GetPackageAppInfoListN();
135 for (int i = 0; i< pPackageAppInfoList->GetCount(); i++)
137 PackageAppInfo* pPackageAppInfo = static_cast<PackageAppInfo*>(pPackageAppInfoList->GetAt(i));
139 data = pPackageAppInfo->GetAppMenuIconPath();
142 delete pPackageAppInfoList;
146 case DATA_TYPE_APPLICATION_UNINSTALLABLE:
148 data = Integer::ToString(pPackageInfo->IsUninstallable());
152 case DATA_TYPE_APPLICATION_SIZE:
154 data = Integer::ToString((pPackageInfo->GetSize() / BYTE_TO_KILOBYTE));
158 case DATA_TYPE_APPLICATION_DATA_SIZE:
160 data = Integer::ToString((pPackageInfo->GetDataSize() / BYTE_TO_KILOBYTE));
164 case DATA_TYPE_APPLICATION_ID:
166 data = pPackageInfo->GetMainAppId();
170 case DATA_TYPE_APPLICATION_PACKAGE_ID:
172 data = pPackageInfo->GetId();
183 ManageApplicationForm::LoadPackageInfoList(void)
185 if (__pPackageInfoList == null)
187 PackageManager* pPackageManager = PackageManager::GetInstance();
188 __pPackageInfoList = pPackageManager->GetPackageInfoListN();
193 ManageApplicationForm::DeletePackageInfoList(void)
195 if (__pPackageInfoList)
197 __pPackageInfoList->RemoveAll(true);
198 delete __pPackageInfoList;
203 ManageApplicationForm::ReLoadPackageInfoList(void)
205 __pPackageInfoList->RemoveAll(true);
206 delete __pPackageInfoList;
207 __pPackageInfoList = null;
208 LoadPackageInfoList();
212 ManageApplicationForm::OnInitializing(void)
214 LoadPackageInfoList();
216 CreateHeaderStyleTab();
219 AppLogDebug("ENTER");
225 ManageApplicationForm::OnTerminating(void)
229 DeletePackageInfoList();
232 SetFormBackEventListener(null);
237 ManageApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
239 if (previousSceneId.Equals(IDSCN_MANAGE_APPLICATION_INFO, false))
243 String* uninstalledApplicationName = (static_cast<String*>(pArgs->GetAt(0)));
244 String uninstallationResult = *(static_cast<String*>(pArgs->GetAt(1)));
246 ReLoadPackageInfoList();
247 CreateAlertPopup(uninstalledApplicationName, uninstallationResult.Equals(L"true", false));
252 __pTableView->UpdateTableView();
256 ManageApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
261 ManageApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
263 SceneManager* pSceneManager = SceneManager::GetInstance();
264 AppAssert(pSceneManager);
266 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
270 ManageApplicationForm::GetGroupCount(void)
272 // Temporary code due to the UI Framework defect
273 if (!__pPackageInfoList)
278 AppLogDebug("ENTER");
283 ManageApplicationForm::GetItemCount(int groupIndex)
285 // Temporary code due to the UI Framework defect
286 if (!__pPackageInfoList)
291 int itemCount = __pPackageInfoList->GetCount();
293 AppLogDebug("GetItemCount %d", itemCount);
299 ManageApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
301 AppLogDebug("ENTER");
303 int itemHeight = Y_GROUP_DEFAULT;
304 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
305 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
306 Rectangle itemMainRectangle;
307 int fontSize = GetFontSize();
309 Label* pLabel = null;
311 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
313 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
314 itemMainRectangle.y = yItemOffset;
315 itemMainRectangle.width = itemWidth;
316 itemMainRectangle.height = itemHeight;
318 RelativeLayout relativeLayout;
319 relativeLayout.Construct();
321 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
322 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
324 pLabel = new (std::nothrow) Label();
325 pLabel->Construct(itemMainRectangle, groupText);
326 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
327 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
328 pLabel->SetTextConfig(fontSize, style);
329 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
331 pItem->AddControl(pLabel);
332 pItem->SetEnabled(false);
333 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
334 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
335 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
341 ManageApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
343 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
345 Rectangle itemIconRectangle;
346 Rectangle itemMainRectangle;
347 Rectangle itemSubRectangle;
348 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
351 String fontReturnValue;
352 Label* pLabel = null;
353 Bitmap* pBitmap = null;
355 int fontSize = GetFontSize();
356 TableViewItem* pItem = new (std::nothrow) TableViewItem();
358 itemMainText = GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_NAME);
359 ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
361 RelativeLayout relativeLayout;
362 relativeLayout.Construct();
364 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
365 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
367 pBitmap = ResourceManager::GetApplicationBitmapN(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ICON_PATH));
371 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
373 pBitmap->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
374 pBitmap->Scale(Dimension(W_ITEM_TYPE_3_ICON, H_ITEM_TYPE_3_ICON));
375 pLabel = new (std::nothrow) Label();
376 pLabel->Construct(itemIconRectangle, L"");
377 pLabel->SetBackgroundBitmap(*pBitmap);
378 pItem->AddControl(pLabel);
380 pLabel = new (std::nothrow) Label();
381 pLabel->Construct(itemMainRectangle, itemMainText);
382 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
384 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
385 pLabel->SetTextColor(COLOR_MAIN_TEXT);
387 pItem->AddControl(pLabel);
389 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
390 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
391 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
397 ManageApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
399 AppLogDebug("ENTER");
408 ManageApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
410 AppLogDebug("ENTER");
419 ManageApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
421 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
423 SceneManager* pSceneManager = SceneManager::GetInstance();
424 AppAssert(pSceneManager);
426 ArrayList* pData = new (std::nothrow) ArrayList(SingleObjectDeleter);
429 String applicationName(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_NAME));
430 String applicationIconPath(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ICON_PATH));
431 String applicationUninstallAble(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_UNINSTALLABLE));
432 String applicationSize(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_SIZE));
433 String applicationDataSize(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_DATA_SIZE));
434 String applicationId(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ID));
435 String applicationPackageId(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_PACKAGE_ID));
437 pData->Add(new (std::nothrow) String(applicationName));
438 pData->Add(new (std::nothrow) String(applicationIconPath));
439 pData->Add(new (std::nothrow) String(applicationUninstallAble));
440 pData->Add(new (std::nothrow) String(applicationSize));
441 pData->Add(new (std::nothrow) String(applicationDataSize));
442 pData->Add(new (std::nothrow) String(applicationId));
443 pData->Add(new (std::nothrow) String(applicationPackageId));
445 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_MANAGE_APPLICATION_INFO, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pData);
449 ManageApplicationForm::GetDefaultGroupItemHeight(void)
451 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
455 ManageApplicationForm::GetDefaultItemHeight(void)
457 return H_GROUP_ITEM_DEFAULT;
461 ManageApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
466 ManageApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
471 ManageApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
476 ManageApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
481 ManageApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
487 ManageApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
489 if (requestId == REFRESH_REQUEST_EVENT)
493 ReLoadPackageInfoList();
494 __pTableView->UpdateTableView();
498 pArgs->RemoveAll(true);
505 ManageApplicationForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
509 case IDA_UNINSTALL_OK:
522 ManageApplicationForm::CreateAlertPopup(Tizen::Base::String* appName, bool uninstallResult)
525 Label* pLabel = null;
526 Button* pOkButton = null;
528 Rectangle clientRect = GetClientAreaBounds();
529 Rectangle itemRectLabel;
530 Rectangle itemRectLhsButton;
531 Rectangle itemRectRhsButton;
534 clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
535 clientRect.width = W_ALERT_POPUP_CLIENT_RECT_DEFAULT;
536 clientRect.height = H_ALERT_POPUP_CLIENT_RECT_DEFAULT;
538 itemRectLabel.x = X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
539 itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
540 itemRectLabel.width = W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
541 itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
543 itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT + itemRectLabel.x;
544 itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
545 itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
546 itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
548 Dimension bounds = Dimension(clientRect.width, clientRect.height);
550 __uninstallResultPopup = new (std::nothrow) Popup();
551 __uninstallResultPopup->Construct(true, bounds);
552 __uninstallResultPopup->SetTitleText(*appName);
554 String descriptionText = L"";
557 descriptionText = ResourceManager::GetString(L"IDS_ST_POP_UNINSTALLED");
561 descriptionText = ResourceManager::GetString(L"IDS_COM_POP_FAILED");
564 pLabel = new (std::nothrow) Label();
565 pLabel->Construct(itemRectLabel, descriptionText);
566 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
567 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
568 pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
570 __uninstallResultPopup->AddControl(pLabel);
572 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
573 pOkButton = new (std::nothrow) Button();
574 pOkButton->Construct(itemRectLhsButton, buttonText);
575 pOkButton->SetActionId(IDA_UNINSTALL_OK);
577 __uninstallResultPopup->AddControl(pOkButton);
579 pOkButton->AddActionEventListener(*this);
585 ManageApplicationForm::ShowAlertPopup(void)
587 __uninstallResultPopup->SetShowState(true);
588 __uninstallResultPopup->Show();
592 ManageApplicationForm::HideAlertPopup(void)
594 __uninstallResultPopup->SetShowState(false);
595 __uninstallResultPopup->Invalidate(true);
599 ManageApplicationForm::DeleteAlertPopup(void)
601 if (__uninstallResultPopup)
603 delete __uninstallResultPopup;
604 __uninstallResultPopup = null;