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->SetBackButton();
65 pFooter->AddActionEventListener(*this);
67 SetFormBackEventListener(this);
71 DownloadedApplicationForm::OnInitializing(void)
73 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DOWNLOADED_APPLICATIONS"));
76 SetAppIdListFromPackageManager();
77 UpdateTableViewAndNoContent();
83 DownloadedApplicationForm::OnTerminating(void)
85 RemoveAllDownLoadAppIdKeyList();
87 int controlCount = GetControlCount();
88 for (int i = 0; i < controlCount; i++)
90 RemoveControl(GetControl(0));
94 SetFormBackEventListener(null);
99 DownloadedApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
105 RemoveAllDownLoadAppIdKeyList();
106 SetAppIdListFromPackageManager();
108 UpdateTableViewAndNoContent();
112 DownloadedApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
117 DownloadedApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
119 SceneManager* pSceneManager = SceneManager::GetInstance();
120 AppAssert(pSceneManager);
122 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
126 DownloadedApplicationForm::GetGroupCount(void)
128 AppLogDebug("ENTER");
130 return ID_GROUP_COUNT;
134 DownloadedApplicationForm::GetItemCount(int groupIndex)
136 int itemCount = GetDownLoadAppCount();
138 AppLogDebug("GetItemCount %d", itemCount);
144 DownloadedApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
146 AppLogDebug("ENTER");
148 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
149 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
150 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
151 Rectangle itemRectangle;
153 Label* pLabel = null;
154 int fontSize = GetFontSize();
156 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
158 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
159 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
161 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
162 itemRectangle.y = yItemOffset;
163 itemRectangle.width = itemWidth;
164 itemRectangle.height = itemHeight;
166 RelativeLayout relativeLayout;
167 relativeLayout.Construct();
169 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
170 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
172 pLabel = new (std::nothrow) Label();
173 pLabel->Construct(itemRectangle, groupText);
174 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
175 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
176 pLabel->SetTextConfig(fontSize, style);
177 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
179 pItem->AddControl(pLabel);
180 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
181 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
182 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
183 pItem->SetEnabled(false);
189 DownloadedApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
191 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
193 Rectangle itemIconRectangle;
194 Rectangle itemMainRectangle;
195 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
197 String fontReturnValue;
198 Label* pLabel = null;
201 int fontSize = GetFontSize();
202 int itemHeight = H_GROUP_ITEM_DEFAULT_LABEL;
203 ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
205 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
206 String iconPath = GetAppSettingIconPathFromAppIdListAt(appIdKey);
208 itemMainText = GetDownLoadAppNameAt(itemIndex);
210 if (iconPath.IsEmpty() == true)
212 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
216 pBitmap = ResourceManager::GetApplicationBitmapN(iconPath);
218 TableViewItem* pItem = new (std::nothrow) TableViewItem();
220 RelativeLayout relativeLayout;
221 relativeLayout.Construct();
223 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
224 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
226 pLabel = new (std::nothrow) Label();
227 pLabel->Construct(itemIconRectangle, L"");
228 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
229 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
230 pLabel->SetBackgroundBitmap(*pBitmap);
232 pItem->AddControl(pLabel);
234 pLabel = new (std::nothrow) Label();
235 pLabel->Construct(itemMainRectangle, itemMainText);
236 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
237 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
238 pLabel->SetTextColor(COLOR_MAIN_TEXT);
240 pItem->AddControl(pLabel);
241 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, MAIN_RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
242 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
243 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
249 DownloadedApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
251 AppLogDebug("ENTER");
260 DownloadedApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
262 AppLogDebug("ENTER");
271 DownloadedApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
273 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
275 SceneManager* pSceneManager = SceneManager::GetInstance();
276 AppAssert(pSceneManager);
278 ArrayList* pArgs = null;
280 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
281 if (appIdKey.IsEmpty() == true)
283 AppLogDebug("GetDownLoadAppIdKeyAt[%d] fail", itemIndex);
286 String appSettingFilepath = GetAppSettingFilePathFromAppIdListAt(appIdKey);
287 if (appSettingFilepath.IsEmpty() == true)
289 AppLogDebug("GetAppSettingFilePathFromAppIdListAt[%ls] fail", appIdKey.GetPointer());
292 pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
295 AppLogDebug("pArgs is null");
298 result r = pArgs->Construct();
301 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
304 pArgs->Add(*(new (std::nothrow) String(appIdKey)));
305 pArgs->Add(*(new (std::nothrow) String(appSettingFilepath)));
307 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_XML_PARSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
311 DownloadedApplicationForm::GetDefaultGroupItemHeight(void)
313 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
317 DownloadedApplicationForm::GetDefaultItemHeight(void)
319 return H_GROUP_ITEM_DEFAULT;
323 DownloadedApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
328 DownloadedApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
334 DownloadedApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
339 DownloadedApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
344 DownloadedApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
346 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
349 Rectangle clientRect = GetClientAreaBounds();
350 Rectangle labelBound = pLabel->GetBounds();
352 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
353 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
355 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
356 yPos = yPos + pLabel->GetBounds().height;
357 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
358 if (pTextLabel != null)
360 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
367 DownloadedApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
369 if (requestId == FRFRESH_REQUEST_EVENT)
373 RemoveAllDownLoadAppIdKeyList();
374 SetAppIdListFromPackageManager();
375 __pTableView->UpdateTableView();
379 pArgs->RemoveAll(true);
386 DownloadedApplicationForm::SetDownLoadAppIdKeyList(void)
388 RemoveAllDownLoadAppIdKeyList();
390 if (__pAppIdHashMap == null)
392 AppLogDebug("__pAppIdHashMap is null");
396 __pDownloadAppIdKeyList = __pAppIdHashMap->GetKeysN();
397 if (__pDownloadAppIdKeyList == null)
399 AppLogDebug("__pDownloadAppIdKeyList is null");
407 DownloadedApplicationForm::RemoveAllDownLoadAppIdKeyList(void)
409 if (__pDownloadAppIdKeyList != null)
411 __pDownloadAppIdKeyList->RemoveAll();
412 delete __pDownloadAppIdKeyList;
413 __pDownloadAppIdKeyList = null;
418 DownloadedApplicationForm::SetAppIdListFromPackageManager(void)
420 RemoveAllAppIdList();
422 __pAppIdHashMap = new (std::nothrow) HashMap();
423 if (__pAppIdHashMap == null)
425 AppLogDebug("__pAppIdHashMap is null");
429 result r = __pAppIdHashMap->Construct();
432 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
433 RemoveAllAppIdList();
437 __pAppIconPathHashMap = new (std::nothrow) HashMap();
438 if (__pAppIconPathHashMap == null)
440 AppLogDebug("__pAppIconPathHashMap is null");
443 r = __pAppIconPathHashMap->Construct();
446 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
447 RemoveAllAppIdList();
452 PackageManager* pPackageManager = PackageManager::GetInstance();
453 if (pPackageManager == null)
455 AppLogDebug("pPackageManager is null");
456 RemoveAllAppIdList();
460 HashMap packageFilterMap;
461 r = packageFilterMap.Construct();
464 AppLogDebug("pPackageFilter Construct fail");
467 String* pKey = new (std::nothrow) String("http://tizen.org/package/appsetting");
468 Boolean* pValue = new (std::nothrow) Boolean(true);
470 r = packageFilterMap.Add(pKey, pValue);
473 AppLogDebug("packageFilterMap add Fail");
476 pList = pPackageManager->GetPackageInfoListN(packageFilterMap);
479 AppLogDebug("pList is null");
480 RemoveAllAppIdList();
484 IEnumerator* pEnumerator = pList->GetEnumeratorN();
485 if (pEnumerator == null)
487 AppLogDebug("pEnumerator is null");
490 RemoveAllAppIdList();
494 bool isFindXml = false;
495 UiApp* pApp = UiApp::GetInstance();
498 while (pEnumerator->MoveNext() == E_SUCCESS)
500 PackageInfo* pPackage = static_cast<PackageInfo*>(pEnumerator->GetCurrent());
501 if (pPackage != null && pPackage->GetType() == PACKAGE_TYPE_TPK)
503 String path(ID_APPLICATION_DEFAULT_FOLDER_PATH);
504 path.Append(pPackage->GetId());
506 path.Append(ID_RELATIVE_SETTING_XML_FILE_PATH);
508 if ((File::IsFileExist(path) == true)
509 && (!pApp->GetAppId().Contains(pPackage->GetId())))
511 String key(pPackage->GetDisplayName());
513 key.Append(pPackage->GetId());
515 String currentAppId = pPackage->GetMainAppId();
516 PackageAppInfo* pPackageInfo = static_cast<PackageAppInfo*>(pPackage->GetPackageAppInfoN(currentAppId));
519 IList* pCategoryList = pPackageInfo->GetAppCategoryListN();
522 for (int i=0; i<pCategoryList->GetCount(); ++i)
524 String* pCategory = static_cast<String*>(pCategoryList->GetAt(i));
525 if (pCategory->Equals(L"http://tizen.org/category/ime", false))
538 String iconPath = pPackageInfo->GetAppMenuIconPath();
540 __pAppIdHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(path)));
541 __pAppIconPathHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(iconPath)));
549 if (isFindXml == false)
551 RemoveAllAppIdList();
555 r = SetDownLoadAppIdKeyList();
558 RemoveAllDownLoadAppIdKeyList();
559 RemoveAllAppIdList();
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);