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_HEADER_APPLICATION = 300;
38 static const int IDA_HEADER_RUNNING = 310;
39 static const int IDA_HEADER_ALL = 320;
40 static const int IDA_UNINSTALL_OK = 400;
42 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 160;
43 static const int X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 26;
44 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
45 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
46 static const int W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 690;
47 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 12;
48 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 360;
49 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 620;
50 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
51 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
53 static const int W_ALERT_POPUP_CLIENT_RECT_DEFAULT = 700;
54 static const int H_ALERT_POPUP_CLIENT_RECT_DEFAULT = 550;
56 static const int BYTE_TO_KILOBYTE = 1024;
60 DATA_TYPE_APPLICATION_NAME = 0,
61 DATA_TYPE_APPLICATION_ICON_PATH,
62 DATA_TYPE_APPLICATION_UNINSTALLABLE,
63 DATA_TYPE_APPLICATION_SIZE,
64 DATA_TYPE_APPLICATION_DATA_SIZE,
65 DATA_TYPE_APPLICATION_ID,
66 DATA_TYPE_APPLICATION_PACKAGE_ID,
69 ManageApplicationForm::ManageApplicationForm(void)
70 : __pPackageInfoList(null)
71 , __uninstallResultPopup(null)
75 ManageApplicationForm::~ManageApplicationForm(void)
80 ManageApplicationForm::CreateHeaderStyleTab(void)
82 #ifdef HEADER_HAS_THREE_TAB
83 Header* pHeader = GetHeader();
84 pHeader->SetStyle(HEADER_STYLE_TAB_WITH_TITLE);
85 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS"));
87 HeaderItem headerItemApplication;
88 headerItemApplication.Construct(IDA_HEADER_APPLICATION);
89 headerItemApplication.SetText(ResourceManager::GetString(L"IDS_ST_BODY_APPLICATION"));
91 HeaderItem headerItemRunning;
92 headerItemRunning.Construct(IDA_HEADER_RUNNING);
93 headerItemRunning.SetText(L"Running");
95 HeaderItem headerItemAll;
96 headerItemAll.Construct(IDA_HEADER_ALL);
97 headerItemAll.SetText(ResourceManager::GetString(L"IDS_ST_OPT_ALL"));
99 pHeader->AddItem(headerItemApplication);
100 pHeader->AddItem(headerItemRunning);
101 pHeader->AddItem(headerItemAll);
102 pHeader->AddActionEventListener(*this);
104 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_MANAGE_APPLICATIONS"));
109 ManageApplicationForm::CreateFooter(void)
111 Footer* pFooter = GetFooter();
114 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
115 pFooter->SetBackButton();
116 pFooter->AddActionEventListener(*this);
118 SetFormBackEventListener(this);
122 ManageApplicationForm::GetPackageInfoItem(int index, int type)
125 PackageInfo* pPackageInfo = static_cast<PackageInfo*>(__pPackageInfoList->GetAt(index));
129 case DATA_TYPE_APPLICATION_NAME:
131 data = pPackageInfo->GetDisplayName();
135 case DATA_TYPE_APPLICATION_ICON_PATH:
137 IList* pPackageAppInfoList = pPackageInfo->GetPackageAppInfoListN();
139 for (int i = 0; i< pPackageAppInfoList->GetCount(); i++)
141 PackageAppInfo* pPackageAppInfo = static_cast<PackageAppInfo*>(pPackageAppInfoList->GetAt(i));
143 data = pPackageAppInfo->GetAppMenuIconPath();
146 delete pPackageAppInfoList;
150 case DATA_TYPE_APPLICATION_UNINSTALLABLE:
152 data = Integer::ToString(pPackageInfo->IsUninstallable());
156 case DATA_TYPE_APPLICATION_SIZE:
158 data = Integer::ToString((pPackageInfo->GetSize() / BYTE_TO_KILOBYTE));
162 case DATA_TYPE_APPLICATION_DATA_SIZE:
164 data = Integer::ToString((pPackageInfo->GetDataSize() / BYTE_TO_KILOBYTE));
168 case DATA_TYPE_APPLICATION_ID:
170 data = pPackageInfo->GetMainAppId();
174 case DATA_TYPE_APPLICATION_PACKAGE_ID:
176 data = pPackageInfo->GetId();
187 ManageApplicationForm::LoadPackageInfoList(void)
189 if (__pPackageInfoList == null)
191 PackageManager* pPackageManager = PackageManager::GetInstance();
192 __pPackageInfoList = pPackageManager->GetPackageInfoListN();
197 ManageApplicationForm::DeletePackageInfoList(void)
199 if (__pPackageInfoList)
201 __pPackageInfoList->RemoveAll(true);
202 delete __pPackageInfoList;
207 ManageApplicationForm::ReLoadPackageInfoList(void)
209 __pPackageInfoList->RemoveAll(true);
210 delete __pPackageInfoList;
211 __pPackageInfoList = null;
212 LoadPackageInfoList();
216 ManageApplicationForm::OnInitializing(void)
218 LoadPackageInfoList();
220 CreateHeaderStyleTab();
224 AppLogDebug("ENTER");
230 ManageApplicationForm::OnTerminating(void)
234 DeletePackageInfoList();
237 SetFormBackEventListener(null);
242 ManageApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
244 if (previousSceneId.Equals(IDSCN_MANAGE_APPLICATION_INFO, false))
248 String* uninstalledApplicationName = (static_cast<String*>(pArgs->GetAt(0)));
249 String uninstallationResult = *(static_cast<String*>(pArgs->GetAt(1)));
251 ReLoadPackageInfoList();
252 CreateAlertPopup(uninstalledApplicationName, uninstallationResult.Equals(L"true", false));
257 __pTableView->UpdateTableView();
261 ManageApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
266 ManageApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
268 SceneManager* pSceneManager = SceneManager::GetInstance();
269 AppAssert(pSceneManager);
271 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
275 ManageApplicationForm::GetGroupCount(void)
277 // Temporary code due to the UI Framework defect
278 if (!__pPackageInfoList)
283 AppLogDebug("ENTER");
288 ManageApplicationForm::GetItemCount(int groupIndex)
290 // Temporary code due to the UI Framework defect
291 if (!__pPackageInfoList)
296 int itemCount = __pPackageInfoList->GetCount();
298 AppLogDebug("GetItemCount %d", itemCount);
304 ManageApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
306 AppLogDebug("ENTER");
308 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
309 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
310 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
311 Rectangle itemMainRectangle;
312 int fontSize = GetFontSize();
314 Label* pLabel = null;
316 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
318 itemMainRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
319 itemMainRectangle.y = yItemOffset;
320 itemMainRectangle.width = itemWidth;
321 itemMainRectangle.height = itemHeight;
323 RelativeLayout relativeLayout;
324 relativeLayout.Construct();
326 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
327 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
329 pLabel = new (std::nothrow) Label();
330 pLabel->Construct(itemMainRectangle, groupText);
331 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
332 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
333 pLabel->SetTextConfig(fontSize, style);
334 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
336 pItem->AddControl(pLabel);
337 pItem->SetEnabled(false);
338 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
339 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
340 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
346 ManageApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
348 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
350 Rectangle itemIconRectangle;
351 Rectangle itemMainRectangle;
352 Rectangle itemSubRectangle;
353 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
356 String fontReturnValue;
357 Label* pLabel = null;
358 Bitmap* pBitmap = null;
360 int fontSize = GetFontSize();
361 TableViewItem* pItem = new (std::nothrow) TableViewItem();
363 itemMainText = GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_NAME);
364 ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
366 RelativeLayout relativeLayout;
367 relativeLayout.Construct();
369 pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
370 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
372 pBitmap = ResourceManager::GetApplicationBitmapN(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ICON_PATH));
376 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
378 pLabel = new (std::nothrow) Label();
379 pLabel->Construct(itemIconRectangle, L"");
380 pLabel->SetBackgroundBitmap(*pBitmap);
381 pItem->AddControl(pLabel);
383 pLabel = new (std::nothrow) Label();
384 pLabel->Construct(itemMainRectangle, itemMainText);
385 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
387 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
388 pLabel->SetTextColor(COLOR_MAIN_TEXT);
390 pItem->AddControl(pLabel);
392 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
393 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
394 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
400 ManageApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
402 AppLogDebug("ENTER");
411 ManageApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
413 AppLogDebug("ENTER");
422 ManageApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
424 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
426 SceneManager* pSceneManager = SceneManager::GetInstance();
427 AppAssert(pSceneManager);
429 ArrayList* pData = new (std::nothrow) ArrayList(SingleObjectDeleter);
432 String applicationName(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_NAME));
433 String applicationIconPath(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ICON_PATH));
434 String applicationUninstallAble(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_UNINSTALLABLE));
435 String applicationSize(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_SIZE));
436 String applicationDataSize(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_DATA_SIZE));
437 String applicationId(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_ID));
438 String applicationPackageId(GetPackageInfoItem(itemIndex, DATA_TYPE_APPLICATION_PACKAGE_ID));
440 pData->Add(new (std::nothrow) String(applicationName));
441 pData->Add(new (std::nothrow) String(applicationIconPath));
442 pData->Add(new (std::nothrow) String(applicationUninstallAble));
443 pData->Add(new (std::nothrow) String(applicationSize));
444 pData->Add(new (std::nothrow) String(applicationDataSize));
445 pData->Add(new (std::nothrow) String(applicationId));
446 pData->Add(new (std::nothrow) String(applicationPackageId));
448 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_MANAGE_APPLICATION_INFO, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pData);
452 ManageApplicationForm::GetDefaultGroupItemHeight(void)
454 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
458 ManageApplicationForm::GetDefaultItemHeight(void)
460 return H_GROUP_ITEM_DEFAULT;
464 ManageApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
469 ManageApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
474 ManageApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
479 ManageApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
484 ManageApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
490 ManageApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
492 if (requestId == FRFRESH_REQUEST_EVENT)
496 ReLoadPackageInfoList();
497 __pTableView->UpdateTableView();
501 pArgs->RemoveAll(true);
508 ManageApplicationForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
512 case IDA_UNINSTALL_OK:
525 ManageApplicationForm::CreateAlertPopup(Tizen::Base::String* appName, bool uninstallResult)
528 Label* pLabel = null;
529 Button* pOkButton = null;
531 Rectangle clientRect = GetClientAreaBounds();
532 Rectangle itemRectLabel;
533 Rectangle itemRectLhsButton;
534 Rectangle itemRectRhsButton;
537 clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
538 clientRect.width = W_ALERT_POPUP_CLIENT_RECT_DEFAULT;
539 clientRect.height = H_ALERT_POPUP_CLIENT_RECT_DEFAULT;
541 itemRectLabel.x = X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
542 itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
543 itemRectLabel.width = W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
544 itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
546 itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT + itemRectLabel.x;
547 itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
548 itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
549 itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
551 Dimension bounds = Dimension(clientRect.width, clientRect.height);
553 __uninstallResultPopup = new (std::nothrow) Popup();
554 __uninstallResultPopup->Construct(true, bounds);
555 __uninstallResultPopup->SetTitleText(*appName);
556 __uninstallResultPopup->SetTitleTextColor(COLOR_SUB_TEXT);
558 String descriptionText = L"";
561 descriptionText = ResourceManager::GetString(L"IDS_ST_POP_UNINSTALLED");
565 descriptionText = ResourceManager::GetString(L"IDS_COM_POP_FAILED");
568 pLabel = new (std::nothrow) Label();
569 pLabel->Construct(itemRectLabel, descriptionText);
570 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
571 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
572 pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
574 __uninstallResultPopup->AddControl(pLabel);
576 buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_OK");
577 pOkButton = new (std::nothrow) Button();
578 pOkButton->Construct(itemRectLhsButton, buttonText);
579 pOkButton->SetActionId(IDA_UNINSTALL_OK);
581 __uninstallResultPopup->AddControl(pOkButton);
583 pOkButton->AddActionEventListener(*this);
589 ManageApplicationForm::ShowAlertPopup(void)
591 __uninstallResultPopup->SetShowState(true);
592 __uninstallResultPopup->Show();
596 ManageApplicationForm::HideAlertPopup(void)
598 __uninstallResultPopup->SetShowState(false);
599 __uninstallResultPopup->Invalidate(true);
603 ManageApplicationForm::DeleteAlertPopup(void)
605 if (__uninstallResultPopup)
607 delete __uninstallResultPopup;
608 __uninstallResultPopup = null;