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 wchar_t* ID_RELATIVE_SETTING_XML_FILE_PATH = L"/setting/setting.xml";
40 static const wchar_t* ID_APPLICATION_DEFAULT_FOLDER_PATH = L"/opt/apps/";
42 static const int ID_GROUP_COUNT = 1;
44 DownloadedApplicationForm::DownloadedApplicationForm(void)
45 : __pDownloadAppIdKeyList(null)
46 , __pAppIdHashMap(null)
47 , __pAppIconPathHashMap(null)
51 DownloadedApplicationForm::~DownloadedApplicationForm(void)
56 DownloadedApplicationForm::CreateFooter(void)
58 Footer* pFooter = GetFooter();
61 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
62 pFooter->AddActionEventListener(*this);
64 SetFormBackEventListener(this);
68 DownloadedApplicationForm::OnInitializing(void)
70 CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DOWNLOADED_APPLICATIONS"));
72 SetAppIdListFromPackageManager();
73 UpdateTableViewAndNoContent();
79 DownloadedApplicationForm::OnTerminating(void)
81 RemoveAllDownLoadAppIdKeyList();
83 int controlCount = GetControlCount();
84 for (int i = 0; i < controlCount; i++)
86 RemoveControl(GetControl(0));
90 SetFormBackEventListener(null);
95 DownloadedApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
101 RemoveAllDownLoadAppIdKeyList();
102 SetAppIdListFromPackageManager();
104 UpdateTableViewAndNoContent();
108 DownloadedApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
113 DownloadedApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
115 SceneManager* pSceneManager = SceneManager::GetInstance();
116 AppAssert(pSceneManager);
118 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
122 DownloadedApplicationForm::GetGroupCount(void)
124 AppLogDebug("ENTER");
126 return ID_GROUP_COUNT;
130 DownloadedApplicationForm::GetItemCount(int groupIndex)
132 int itemCount = GetDownLoadAppCount();
134 AppLogDebug("GetItemCount %d", itemCount);
140 DownloadedApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
142 AppLogDebug("ENTER");
144 int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
145 int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
146 LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
147 Rectangle itemRectangle;
149 Label* pLabel = null;
150 int fontSize = GetFontSize();
152 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
154 yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
155 itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
157 itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
158 itemRectangle.y = yItemOffset;
159 itemRectangle.width = itemWidth;
160 itemRectangle.height = itemHeight;
162 RelativeLayout relativeLayout;
163 relativeLayout.Construct();
165 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
166 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
168 pLabel = new (std::nothrow) Label();
169 pLabel->Construct(itemRectangle, groupText);
170 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
171 pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
172 pLabel->SetTextConfig(fontSize, style);
173 pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
175 pItem->AddControl(pLabel);
176 relativeLayout.SetMargin(*pLabel, itemRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
177 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
178 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
179 pItem->SetEnabled(false);
185 DownloadedApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
187 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
189 Rectangle itemIconRectangle;
190 Rectangle itemMainRectangle;
191 TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
193 String fontReturnValue;
194 Label* pLabel = null;
197 int fontSize = GetFontSize();
198 int itemHeight = H_GROUP_ITEM_DEFAULT_LABEL;
199 ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
201 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
202 String iconPath = GetAppSettingIconPathFromAppIdListAt(appIdKey);
204 itemMainText = GetDownLoadAppNameAt(itemIndex);
206 if (iconPath.IsEmpty() == true)
208 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
212 pBitmap = ResourceManager::GetApplicationBitmapN(iconPath);
214 TableViewItem* pItem = new (std::nothrow) TableViewItem();
216 RelativeLayout relativeLayout;
217 relativeLayout.Construct();
219 pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
220 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
222 pLabel = new (std::nothrow) Label();
223 pLabel->Construct(itemIconRectangle, L"");
224 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
225 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
226 pLabel->SetBackgroundBitmap(*pBitmap);
228 pItem->AddControl(pLabel);
230 pLabel = new (std::nothrow) Label();
231 pLabel->Construct(itemMainRectangle, itemMainText);
232 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
233 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
234 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
235 pLabel->SetTextColor(COLOR_MAIN_TEXT);
237 pItem->AddControl(pLabel);
238 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
239 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
240 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
246 DownloadedApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
248 AppLogDebug("ENTER");
257 DownloadedApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
259 AppLogDebug("ENTER");
268 DownloadedApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
270 AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
272 SceneManager* pSceneManager = SceneManager::GetInstance();
273 AppAssert(pSceneManager);
275 ArrayList* pArgs = null;
277 String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
278 if (appIdKey.IsEmpty() == true)
280 AppLogDebug("GetDownLoadAppIdKeyAt[%d] fail", itemIndex);
283 String appSettingFilepath = GetAppSettingFilePathFromAppIdListAt(appIdKey);
284 if (appSettingFilepath.IsEmpty() == true)
286 AppLogDebug("GetAppSettingFilePathFromAppIdListAt[%ls] fail", appIdKey.GetPointer());
289 pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
292 AppLogDebug("pArgs is null");
295 result r = pArgs->Construct();
298 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
301 pArgs->Add(new (std::nothrow) String(appIdKey));
302 pArgs->Add(new (std::nothrow) String(appSettingFilepath));
304 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_XML_PARSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
308 DownloadedApplicationForm::GetDefaultGroupItemHeight(void)
310 return H_GROUP_INDEX_NO_TITLE_DEFAULT;
314 DownloadedApplicationForm::GetDefaultItemHeight(void)
316 return H_GROUP_ITEM_DEFAULT;
320 DownloadedApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
325 DownloadedApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
331 DownloadedApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
336 DownloadedApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
341 DownloadedApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
343 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
346 Rectangle clientRect = GetClientAreaBounds();
347 Rectangle labelBound = pLabel->GetBounds();
349 int xPos = (clientRect.width / LINE_COUNT_2) - (labelBound.width / LINE_COUNT_2);
350 int yPos = (clientRect.height / LINE_COUNT_2) -(labelBound.height / LINE_COUNT_2);
352 pLabel->SetBounds(Rectangle(xPos, yPos, labelBound.width, labelBound.height));
353 yPos = yPos + pLabel->GetBounds().height;
354 Label* pTextLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS_TEXT, false));
355 if (pTextLabel != null)
357 pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
364 DownloadedApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
366 if (requestId == REFRESH_REQUEST_EVENT)
370 RemoveAllDownLoadAppIdKeyList();
371 SetAppIdListFromPackageManager();
372 __pTableView->UpdateTableView();
376 pArgs->RemoveAll(true);
383 DownloadedApplicationForm::SetDownLoadAppIdKeyList(void)
385 RemoveAllDownLoadAppIdKeyList();
387 if (__pAppIdHashMap == null)
389 AppLogDebug("__pAppIdHashMap is null");
393 __pDownloadAppIdKeyList = __pAppIdHashMap->GetKeysN();
394 if (__pDownloadAppIdKeyList == null)
396 AppLogDebug("__pDownloadAppIdKeyList is null");
404 DownloadedApplicationForm::RemoveAllDownLoadAppIdKeyList(void)
406 if (__pDownloadAppIdKeyList != null)
408 __pDownloadAppIdKeyList->RemoveAll();
409 delete __pDownloadAppIdKeyList;
410 __pDownloadAppIdKeyList = null;
415 DownloadedApplicationForm::SetAppIdListFromPackageManager(void)
417 RemoveAllAppIdList();
419 __pAppIdHashMap = new (std::nothrow) HashMap();
420 if (__pAppIdHashMap == null)
422 AppLogDebug("__pAppIdHashMap is null");
426 result r = __pAppIdHashMap->Construct();
429 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
430 RemoveAllAppIdList();
434 __pAppIconPathHashMap = new (std::nothrow) HashMap();
435 if (__pAppIconPathHashMap == null)
437 AppLogDebug("__pAppIconPathHashMap is null");
440 r = __pAppIconPathHashMap->Construct();
443 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
444 RemoveAllAppIdList();
449 PackageManager* pPackageManager = PackageManager::GetInstance();
450 if (pPackageManager == null)
452 AppLogDebug("pPackageManager is null");
453 RemoveAllAppIdList();
457 HashMap packageFilterMap;
458 r = packageFilterMap.Construct();
461 AppLogDebug("pPackageFilter Construct fail");
464 String* pKey = new (std::nothrow) String("http://tizen.org/package/appsetting");
465 Boolean* pValue = new (std::nothrow) Boolean(true);
467 r = packageFilterMap.Add(pKey, pValue);
470 AppLogDebug("packageFilterMap add Fail");
473 pList = pPackageManager->GetPackageInfoListN(packageFilterMap);
476 AppLogDebug("pList is null");
477 RemoveAllAppIdList();
481 IEnumerator* pEnumerator = pList->GetEnumeratorN();
482 if (pEnumerator == null)
484 AppLogDebug("pEnumerator is null");
487 RemoveAllAppIdList();
491 bool isFindXml = false;
492 UiApp* pApp = UiApp::GetInstance();
495 while (pEnumerator->MoveNext() == E_SUCCESS)
497 PackageInfo* pPackage = static_cast<PackageInfo*>(pEnumerator->GetCurrent());
498 if (pPackage != null && pPackage->GetType() == PACKAGE_TYPE_TPK)
500 String path(ID_APPLICATION_DEFAULT_FOLDER_PATH);
501 path.Append(pPackage->GetId());
503 path.Append(ID_RELATIVE_SETTING_XML_FILE_PATH);
505 if ((File::IsFileExist(path) == true)
506 && (!pApp->GetAppId().Contains(pPackage->GetId())))
508 String key(pPackage->GetDisplayName());
510 key.Append(pPackage->GetId());
512 String currentAppId = pPackage->GetMainAppId();
513 PackageAppInfo* pPackageInfo = static_cast<PackageAppInfo*>(pPackage->GetPackageAppInfoN(currentAppId));
516 IList* pCategoryList = pPackageInfo->GetAppCategoryListN();
519 for (int i=0; i<pCategoryList->GetCount(); ++i)
521 String* pCategory = static_cast<String*>(pCategoryList->GetAt(i));
522 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);