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 StDownloadedApplicationForm.cpp
19 * @brief This is the implementation file for DownloadedApplicationForm class.
23 #include "StDownloadedApplicationForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
28 using namespace Tizen::App;
29 using namespace Tizen::App::Package;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Utility;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Io;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 static const int MAIN_RELATIVE_LAYOUT_RIGHT_MARGIN = 60;
40 static const wchar_t* ID_RELATIVE_SETTING_XML_FILE_PATH = L"/setting/setting.xml";
41 static const wchar_t* ID_APPLICATION_DEFAULT_FOLDER_PATH = L"/opt/apps/";
43 static const int ID_GROUP_COUNT = 1;
44 static const int ID_GROUP_MAX_ITEM_COUNT = 3;
46 DownloadedApplicationForm::DownloadedApplicationForm(void)
47 : __pDownloadAppIdKeyList(null)
48 , __pAppIdHashMap(null)
49 , __pAppIconPathHashMap(null)
53 DownloadedApplicationForm::~DownloadedApplicationForm(void)
58 DownloadedApplicationForm::CreateFooter(void)
60 Footer* pFooter = GetFooter();
63 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
64 pFooter->AddActionEventListener(*this);
66 SetFormBackEventListener(this);
70 DownloadedApplicationForm::OnInitializing(void)
72 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DOWNLOADED_APPLICATIONS"));
74 SetAppIdListFromPackageManager();
75 UpdateTableViewAndNoContent();
81 DownloadedApplicationForm::OnTerminating(void)
83 RemoveAllDownLoadAppIdKeyList();
85 int controlCount = GetControlCount();
86 for (int i = 0; i < controlCount; i++)
88 RemoveControl(GetControl(0));
92 SetFormBackEventListener(null);
97 DownloadedApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
103 RemoveAllDownLoadAppIdKeyList();
104 SetAppIdListFromPackageManager();
106 UpdateTableViewAndNoContent();
110 DownloadedApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
115 DownloadedApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
117 SceneManager* pSceneManager = SceneManager::GetInstance();
118 AppAssert(pSceneManager);
120 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
124 DownloadedApplicationForm::GetGroupCount(void)
126 AppLogDebug("ENTER");
128 return ID_GROUP_COUNT;
132 DownloadedApplicationForm::GetItemCount(int groupIndex)
134 int itemCount = GetDownLoadAppCount();
136 AppLogDebug("GetItemCount %d", itemCount);
142 DownloadedApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
144 AppLogDebug("ENTER");
146 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
147 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
148 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
149 Rectangle itemRectangle;
151 Label* pLabel = null;
152 int fontSize = GetFontSize();
154 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
156 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
157 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
159 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
160 itemRectangle.y = yItemOffset;
161 itemRectangle.width = itemWidth;
162 itemRectangle.height = itemHeight;
164 RelativeLayout relativeLayout;
165 relativeLayout.Construct();
167 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
168 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
170 pLabel = new (std::nothrow) Label();
171 pLabel->Construct(itemRectangle, groupText);
172 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
173 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
174 pLabel->SetTextConfig(fontSize, style);
175 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
177 pItem->AddControl(pLabel);
178 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
179 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
180 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
181 pItem->SetEnabled(false);
187 DownloadedApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
189 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
191 Rectangle itemIconRectangle;
192 Rectangle itemMainRectangle;
193 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
195 String fontReturnValue;
196 Label* pLabel = null;
199 int fontSize = GetFontSize();
200 int itemHeight = H_GROUP_ITEM_DEFAULT_LABEL;
201 ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
203 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
204 String iconPath = GetAppSettingIconPathFromAppIdListAt(appIdKey);
206 itemMainText = GetDownLoadAppNameAt(itemIndex);
208 if (iconPath.IsEmpty() == true)
210 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
214 pBitmap = ResourceManager::GetApplicationBitmapN(iconPath);
216 TableViewItem* pItem = new (std::nothrow) TableViewItem();
218 RelativeLayout relativeLayout;
219 relativeLayout.Construct();
221 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
222 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
224 pLabel = new (std::nothrow) Label();
225 pLabel->Construct(itemIconRectangle, L"");
226 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
227 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
228 pLabel->SetBackgroundBitmap(*pBitmap);
230 pItem->AddControl(pLabel);
232 pLabel = new (std::nothrow) Label();
233 pLabel->Construct(itemMainRectangle, itemMainText);
234 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
235 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
236 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
237 pLabel->SetTextColor(COLOR_MAIN_TEXT);
239 pItem->AddControl(pLabel);
240 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
241 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
242 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
248 DownloadedApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
250 AppLogDebug("ENTER");
259 DownloadedApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
261 AppLogDebug("ENTER");
270 DownloadedApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
272 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
274 SceneManager* pSceneManager = SceneManager::GetInstance();
275 AppAssert(pSceneManager);
277 ArrayList* pArgs = null;
279 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
280 if (appIdKey.IsEmpty() == true)
282 AppLogDebug("GetDownLoadAppIdKeyAt[%d] fail", itemIndex);
285 String appSettingFilepath = GetAppSettingFilePathFromAppIdListAt(appIdKey);
286 if (appSettingFilepath.IsEmpty() == true)
288 AppLogDebug("GetAppSettingFilePathFromAppIdListAt[%ls] fail", appIdKey.GetPointer());
291 pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
294 AppLogDebug("pArgs is null");
297 result r = pArgs->Construct();
300 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
303 pArgs->Add(*(new (std::nothrow) String(appIdKey)));
304 pArgs->Add(*(new (std::nothrow) String(appSettingFilepath)));
306 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_XML_PARSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
310 DownloadedApplicationForm::GetDefaultGroupItemHeight(void)
312 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
316 DownloadedApplicationForm::GetDefaultItemHeight(void)
318 return H_GROUP_ITEM_DEFAULT;
322 DownloadedApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
327 DownloadedApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
333 DownloadedApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
338 DownloadedApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
343 DownloadedApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
345 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
348 Rectangle clientRect = GetClientAreaBounds();
349 Rectangle labelBound = pLabel->GetBounds();
351 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
352 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
354 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
355 yPos = yPos + pLabel->GetBounds().height;
356 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
357 if (pTextLabel != null)
359 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
366 DownloadedApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
368 if (requestId == REFRESH_REQUEST_EVENT)
372 RemoveAllDownLoadAppIdKeyList();
373 SetAppIdListFromPackageManager();
374 __pTableView->UpdateTableView();
378 pArgs->RemoveAll(true);
385 DownloadedApplicationForm::SetDownLoadAppIdKeyList(void)
387 RemoveAllDownLoadAppIdKeyList();
389 if (__pAppIdHashMap == null)
391 AppLogDebug("__pAppIdHashMap is null");
395 __pDownloadAppIdKeyList = __pAppIdHashMap->GetKeysN();
396 if (__pDownloadAppIdKeyList == null)
398 AppLogDebug("__pDownloadAppIdKeyList is null");
406 DownloadedApplicationForm::RemoveAllDownLoadAppIdKeyList(void)
408 if (__pDownloadAppIdKeyList != null)
410 __pDownloadAppIdKeyList->RemoveAll();
411 delete __pDownloadAppIdKeyList;
412 __pDownloadAppIdKeyList = null;
417 DownloadedApplicationForm::SetAppIdListFromPackageManager(void)
419 RemoveAllAppIdList();
421 __pAppIdHashMap = new (std::nothrow) HashMap();
422 if (__pAppIdHashMap == null)
424 AppLogDebug("__pAppIdHashMap is null");
428 result r = __pAppIdHashMap->Construct();
431 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
432 RemoveAllAppIdList();
436 __pAppIconPathHashMap = new (std::nothrow) HashMap();
437 if (__pAppIconPathHashMap == null)
439 AppLogDebug("__pAppIconPathHashMap is null");
442 r = __pAppIconPathHashMap->Construct();
445 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
446 RemoveAllAppIdList();
451 PackageManager* pPackageManager = PackageManager::GetInstance();
452 if (pPackageManager == null)
454 AppLogDebug("pPackageManager is null");
455 RemoveAllAppIdList();
459 HashMap packageFilterMap;
460 r = packageFilterMap.Construct();
463 AppLogDebug("pPackageFilter Construct fail");
466 String* pKey = new (std::nothrow) String("http://tizen.org/package/appsetting");
467 Boolean* pValue = new (std::nothrow) Boolean(true);
469 r = packageFilterMap.Add(pKey, pValue);
472 AppLogDebug("packageFilterMap add Fail");
475 pList = pPackageManager->GetPackageInfoListN(packageFilterMap);
478 AppLogDebug("pList is null");
479 RemoveAllAppIdList();
483 IEnumerator* pEnumerator = pList->GetEnumeratorN();
484 if (pEnumerator == null)
486 AppLogDebug("pEnumerator is null");
489 RemoveAllAppIdList();
493 bool isFindXml = false;
494 UiApp* pApp = UiApp::GetInstance();
497 while (pEnumerator->MoveNext() == E_SUCCESS)
499 PackageInfo* pPackage = static_cast<PackageInfo*>(pEnumerator->GetCurrent());
500 if (pPackage != null && pPackage->GetType() == PACKAGE_TYPE_TPK)
502 String path(ID_APPLICATION_DEFAULT_FOLDER_PATH);
503 path.Append(pPackage->GetId());
505 path.Append(ID_RELATIVE_SETTING_XML_FILE_PATH);
507 if ((File::IsFileExist(path) == true)
508 && (!pApp->GetAppId().Contains(pPackage->GetId())))
510 String key(pPackage->GetDisplayName());
512 key.Append(pPackage->GetId());
514 String currentAppId = pPackage->GetMainAppId();
515 PackageAppInfo* pPackageInfo = static_cast<PackageAppInfo*>(pPackage->GetPackageAppInfoN(currentAppId));
518 IList* pCategoryList = pPackageInfo->GetAppCategoryListN();
521 for (int i=0; i<pCategoryList->GetCount(); ++i)
523 String* pCategory = static_cast<String*>(pCategoryList->GetAt(i));
524 if (pCategory->Equals(L"http://tizen.org/category/ime", false))
537 String iconPath = pPackageInfo->GetAppMenuIconPath();
539 __pAppIdHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(path)));
540 __pAppIconPathHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(iconPath)));
548 if (isFindXml == false)
550 RemoveAllAppIdList();
554 r = SetDownLoadAppIdKeyList();
557 RemoveAllDownLoadAppIdKeyList();
558 RemoveAllAppIdList();
562 packageFilterMap.RemoveAll(true);
568 DownloadedApplicationForm::RemoveAllAppIdList(void)
570 if (__pAppIdHashMap != null)
572 __pAppIdHashMap->RemoveAll();
573 delete __pAppIdHashMap;
574 __pAppIdHashMap = null;
577 if (__pAppIconPathHashMap != null)
579 __pAppIconPathHashMap->RemoveAll();
580 delete __pAppIconPathHashMap;
581 __pAppIconPathHashMap = null;
586 DownloadedApplicationForm::GetAppSettingFilePathFromAppIdListAt(Tizen::Base::String key)
588 String appSettingFilePath;
589 if (__pAppIdHashMap == null)
591 AppLogDebug("__pAppIdHashMap is null");
592 return appSettingFilePath;
596 result r = __pAppIdHashMap->ContainsKey(key, isFind);
597 if ((isFind == false)
602 AppLogDebug("key[%ls] is not found", key.GetPointer());
606 AppLogDebug("ContainsKey fail [%s]", GetErrorMessage(r));
608 return appSettingFilePath;
611 String* pValue = static_cast<String*>(__pAppIdHashMap->GetValue(key));
614 AppLogDebug("pValue is null");
615 return appSettingFilePath;
618 appSettingFilePath.Append(*pValue);
619 return appSettingFilePath;
623 DownloadedApplicationForm::GetDownLoadAppNameAt(unsigned int index)
626 if (__pDownloadAppIdKeyList == null)
628 AppLogDebug("__pDownloadAppIdKeyList is null");
632 String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
635 AppLogDebug("pAppKey is null");
639 StringTokenizer stringTokenizer(*pAppKey, L":");
640 result r = stringTokenizer.GetNextToken(appName);
643 AppLogDebug("GetNextToken fail[%s]",GetErrorMessage(r));
651 DownloadedApplicationForm::GetDownLoadAppIdKeyAt(unsigned int index)
654 if (__pDownloadAppIdKeyList == null)
656 AppLogDebug("__pDownloadAppIdKeyList is null");
660 String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
663 AppLogDebug("pAppKey is null");
667 appIdKey.Append(*pAppKey);
673 DownloadedApplicationForm::GetDownLoadAppCount(void)
675 unsigned int downLoadAppCount = 0;
676 if (__pDownloadAppIdKeyList == null)
678 AppLogDebug("__pDownloadAppIdKeyList is null");
679 return downLoadAppCount;
682 downLoadAppCount = __pDownloadAppIdKeyList->GetCount();
683 return downLoadAppCount;
687 DownloadedApplicationForm::GetAppSettingIconPathFromAppIdListAt(Tizen::Base::String& id)
691 if (__pAppIconPathHashMap)
693 if (__pAppIconPathHashMap->ContainsKey(id) == true)
695 iconPath = *(static_cast<String*>(__pAppIconPathHashMap->GetValue((id))));
702 DownloadedApplicationForm::UpdateTableViewAndNoContent(void)
704 bool createTableView = false;
705 if (__pTableView != null)
707 if (GetDownLoadAppCount() != 0)
709 __pTableView->UpdateTableView();
715 if (GetDownLoadAppCount() != 0)
717 createTableView = true;
721 if (__pTableView != null)
723 int tableViewControlCount = __pTableView->GetControlCount();
724 for (int i = 0; i < tableViewControlCount; i++)
726 __pTableView->RemoveControl(__pTableView->GetControl(0));
728 // __pTableView->RemoveAllControls();
731 int controlCount = GetControlCount();
732 for (int i = 0; i < controlCount; i++)
734 RemoveControl(GetControl(0));
736 // RemoveAllControls();
741 __pTableView->UpdateTableView();
745 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
748 Rectangle clientRect = GetClientAreaBounds();
749 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
751 int bitmapWidth = pBitmp->GetWidth();
752 int bitmapHeight = pBitmp->GetHeight();
753 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
754 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
755 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
757 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
758 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
760 Label* pLabel = new (std::nothrow) Label();
761 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
762 pLabel->SetName(NO_CONTENTS);
763 pLabel->SetBackgroundBitmap(*pBitmp);
765 yPos = yPos + bitmapHeight;
767 Label* pLabelNoContents = new (std::nothrow) Label();
768 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
769 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
770 pLabelNoContents->SetTextColor(textColor);
771 pLabelNoContents->SetText(labelText);
774 AddControl(pLabelNoContents);