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->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
236 pLabel->SetTextColor(COLOR_MAIN_TEXT);
238 pItem->AddControl(pLabel);
239 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, MAIN_RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
240 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
241 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
247 DownloadedApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
249 AppLogDebug("ENTER");
258 DownloadedApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
260 AppLogDebug("ENTER");
269 DownloadedApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
271 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
273 SceneManager* pSceneManager = SceneManager::GetInstance();
274 AppAssert(pSceneManager);
276 ArrayList* pArgs = null;
278 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
279 if (appIdKey.IsEmpty() == true)
281 AppLogDebug("GetDownLoadAppIdKeyAt[%d] fail", itemIndex);
284 String appSettingFilepath = GetAppSettingFilePathFromAppIdListAt(appIdKey);
285 if (appSettingFilepath.IsEmpty() == true)
287 AppLogDebug("GetAppSettingFilePathFromAppIdListAt[%ls] fail", appIdKey.GetPointer());
290 pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
293 AppLogDebug("pArgs is null");
296 result r = pArgs->Construct();
299 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
302 pArgs->Add(*(new (std::nothrow) String(appIdKey)));
303 pArgs->Add(*(new (std::nothrow) String(appSettingFilepath)));
305 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_XML_PARSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
309 DownloadedApplicationForm::GetDefaultGroupItemHeight(void)
311 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
315 DownloadedApplicationForm::GetDefaultItemHeight(void)
317 return H_GROUP_ITEM_DEFAULT;
321 DownloadedApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
326 DownloadedApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
332 DownloadedApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
337 DownloadedApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
342 DownloadedApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
344 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
347 Rectangle clientRect = GetClientAreaBounds();
348 Rectangle labelBound = pLabel->GetBounds();
350 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
351 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
353 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
354 yPos = yPos + pLabel->GetBounds().height;
355 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
356 if (pTextLabel != null)
358 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
365 DownloadedApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
367 if (requestId == REFRESH_REQUEST_EVENT)
371 RemoveAllDownLoadAppIdKeyList();
372 SetAppIdListFromPackageManager();
373 __pTableView->UpdateTableView();
377 pArgs->RemoveAll(true);
384 DownloadedApplicationForm::SetDownLoadAppIdKeyList(void)
386 RemoveAllDownLoadAppIdKeyList();
388 if (__pAppIdHashMap == null)
390 AppLogDebug("__pAppIdHashMap is null");
394 __pDownloadAppIdKeyList = __pAppIdHashMap->GetKeysN();
395 if (__pDownloadAppIdKeyList == null)
397 AppLogDebug("__pDownloadAppIdKeyList is null");
405 DownloadedApplicationForm::RemoveAllDownLoadAppIdKeyList(void)
407 if (__pDownloadAppIdKeyList != null)
409 __pDownloadAppIdKeyList->RemoveAll();
410 delete __pDownloadAppIdKeyList;
411 __pDownloadAppIdKeyList = null;
416 DownloadedApplicationForm::SetAppIdListFromPackageManager(void)
418 RemoveAllAppIdList();
420 __pAppIdHashMap = new (std::nothrow) HashMap();
421 if (__pAppIdHashMap == null)
423 AppLogDebug("__pAppIdHashMap is null");
427 result r = __pAppIdHashMap->Construct();
430 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
431 RemoveAllAppIdList();
435 __pAppIconPathHashMap = new (std::nothrow) HashMap();
436 if (__pAppIconPathHashMap == null)
438 AppLogDebug("__pAppIconPathHashMap is null");
441 r = __pAppIconPathHashMap->Construct();
444 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
445 RemoveAllAppIdList();
450 PackageManager* pPackageManager = PackageManager::GetInstance();
451 if (pPackageManager == null)
453 AppLogDebug("pPackageManager is null");
454 RemoveAllAppIdList();
458 HashMap packageFilterMap;
459 r = packageFilterMap.Construct();
462 AppLogDebug("pPackageFilter Construct fail");
465 String* pKey = new (std::nothrow) String("http://tizen.org/package/appsetting");
466 Boolean* pValue = new (std::nothrow) Boolean(true);
468 r = packageFilterMap.Add(pKey, pValue);
471 AppLogDebug("packageFilterMap add Fail");
474 pList = pPackageManager->GetPackageInfoListN(packageFilterMap);
477 AppLogDebug("pList is null");
478 RemoveAllAppIdList();
482 IEnumerator* pEnumerator = pList->GetEnumeratorN();
483 if (pEnumerator == null)
485 AppLogDebug("pEnumerator is null");
488 RemoveAllAppIdList();
492 bool isFindXml = false;
493 UiApp* pApp = UiApp::GetInstance();
496 while (pEnumerator->MoveNext() == E_SUCCESS)
498 PackageInfo* pPackage = static_cast<PackageInfo*>(pEnumerator->GetCurrent());
499 if (pPackage != null && pPackage->GetType() == PACKAGE_TYPE_TPK)
501 String path(ID_APPLICATION_DEFAULT_FOLDER_PATH);
502 path.Append(pPackage->GetId());
504 path.Append(ID_RELATIVE_SETTING_XML_FILE_PATH);
506 if ((File::IsFileExist(path) == true)
507 && (!pApp->GetAppId().Contains(pPackage->GetId())))
509 String key(pPackage->GetDisplayName());
511 key.Append(pPackage->GetId());
513 String currentAppId = pPackage->GetMainAppId();
514 PackageAppInfo* pPackageInfo = static_cast<PackageAppInfo*>(pPackage->GetPackageAppInfoN(currentAppId));
517 IList* pCategoryList = pPackageInfo->GetAppCategoryListN();
520 for (int i=0; i<pCategoryList->GetCount(); ++i)
522 String* pCategory = static_cast<String*>(pCategoryList->GetAt(i));
523 if (pCategory->Equals(L"http://tizen.org/category/ime", false))
536 String iconPath = pPackageInfo->GetAppMenuIconPath();
538 __pAppIdHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(path)));
539 __pAppIconPathHashMap->Add(*(new (std::nothrow) String(key)), *(new (std::nothrow) String(iconPath)));
547 if (isFindXml == false)
549 RemoveAllAppIdList();
553 r = SetDownLoadAppIdKeyList();
556 RemoveAllDownLoadAppIdKeyList();
557 RemoveAllAppIdList();
561 packageFilterMap.RemoveAll(true);
567 DownloadedApplicationForm::RemoveAllAppIdList(void)
569 if (__pAppIdHashMap != null)
571 __pAppIdHashMap->RemoveAll();
572 delete __pAppIdHashMap;
573 __pAppIdHashMap = null;
576 if (__pAppIconPathHashMap != null)
578 __pAppIconPathHashMap->RemoveAll();
579 delete __pAppIconPathHashMap;
580 __pAppIconPathHashMap = null;
585 DownloadedApplicationForm::GetAppSettingFilePathFromAppIdListAt(Tizen::Base::String key)
587 String appSettingFilePath;
588 if (__pAppIdHashMap == null)
590 AppLogDebug("__pAppIdHashMap is null");
591 return appSettingFilePath;
595 result r = __pAppIdHashMap->ContainsKey(key, isFind);
596 if ((isFind == false)
601 AppLogDebug("key[%ls] is not found", key.GetPointer());
605 AppLogDebug("ContainsKey fail [%s]", GetErrorMessage(r));
607 return appSettingFilePath;
610 String* pValue = static_cast<String*>(__pAppIdHashMap->GetValue(key));
613 AppLogDebug("pValue is null");
614 return appSettingFilePath;
617 appSettingFilePath.Append(*pValue);
618 return appSettingFilePath;
622 DownloadedApplicationForm::GetDownLoadAppNameAt(unsigned int index)
625 if (__pDownloadAppIdKeyList == null)
627 AppLogDebug("__pDownloadAppIdKeyList is null");
631 String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
634 AppLogDebug("pAppKey is null");
638 StringTokenizer stringTokenizer(*pAppKey, L":");
639 result r = stringTokenizer.GetNextToken(appName);
642 AppLogDebug("GetNextToken fail[%s]",GetErrorMessage(r));
650 DownloadedApplicationForm::GetDownLoadAppIdKeyAt(unsigned int index)
653 if (__pDownloadAppIdKeyList == null)
655 AppLogDebug("__pDownloadAppIdKeyList is null");
659 String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
662 AppLogDebug("pAppKey is null");
666 appIdKey.Append(*pAppKey);
672 DownloadedApplicationForm::GetDownLoadAppCount(void)
674 unsigned int downLoadAppCount = 0;
675 if (__pDownloadAppIdKeyList == null)
677 AppLogDebug("__pDownloadAppIdKeyList is null");
678 return downLoadAppCount;
681 downLoadAppCount = __pDownloadAppIdKeyList->GetCount();
682 return downLoadAppCount;
686 DownloadedApplicationForm::GetAppSettingIconPathFromAppIdListAt(Tizen::Base::String& id)
690 if (__pAppIconPathHashMap)
692 if (__pAppIconPathHashMap->ContainsKey(id) == true)
694 iconPath = *(static_cast<String*>(__pAppIconPathHashMap->GetValue((id))));
701 DownloadedApplicationForm::UpdateTableViewAndNoContent(void)
703 bool createTableView = false;
704 if (__pTableView != null)
706 if (GetDownLoadAppCount() != 0)
708 __pTableView->UpdateTableView();
714 if (GetDownLoadAppCount() != 0)
716 createTableView = true;
720 if (__pTableView != null)
722 int tableViewControlCount = __pTableView->GetControlCount();
723 for (int i = 0; i < tableViewControlCount; i++)
725 __pTableView->RemoveControl(__pTableView->GetControl(0));
727 // __pTableView->RemoveAllControls();
730 int controlCount = GetControlCount();
731 for (int i = 0; i < controlCount; i++)
733 RemoveControl(GetControl(0));
735 // RemoveAllControls();
740 __pTableView->UpdateTableView();
744 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
747 Rectangle clientRect = GetClientAreaBounds();
748 Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
750 int bitmapWidth = pBitmp->GetWidth();
751 int bitmapHeight = pBitmp->GetHeight();
752 String labelText = ResourceManager::GetString(L"IDS_ST_BODY_NO_CONTENT");
753 Color textColor = COLOR_HELP_TEXT_TYPE_03_NORMAL;
754 int noContentTextHeight = GetHeightForStringArea(labelText, bitmapWidth, 32);
756 int xPos = (clientRect.width / LINE_COUNT_2) - (bitmapWidth / DIVIDE_BY_TWO);
757 int yPos = (clientRect.height / LINE_COUNT_2) - ((bitmapHeight + noContentTextHeight) / DIVIDE_BY_TWO);
759 Label* pLabel = new (std::nothrow) Label();
760 pLabel->Construct(Rectangle(xPos, yPos, bitmapWidth, bitmapHeight), L"");
761 pLabel->SetName(NO_CONTENTS);
762 pLabel->SetBackgroundBitmap(*pBitmp);
764 yPos = yPos + bitmapHeight;
766 Label* pLabelNoContents = new (std::nothrow) Label();
767 pLabelNoContents->Construct(Rectangle(0, yPos, clientRect.width, noContentTextHeight), L"");
768 pLabelNoContents->SetName(NO_CONTENTS_TEXT);
769 pLabelNoContents->SetTextColor(textColor);
770 pLabelNoContents->SetText(labelText);
773 AddControl(pLabelNoContents);