2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 PackageInfoListRetrieveThread.h
19 * @brief The file contains declaration of PackageInfoListRetrieveThread,
20 * which is a worker thread and being used to retrieve the list PackageInfos, for the Applications installed on device.
24 #include "HmHomeItemInfo.h"
25 #include "HmPackageInfoListRetrieveThread.h"
28 using namespace Tizen::App;
29 using namespace Tizen::App::Package;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
33 PackageInfoListRetrieveThread::PackageInfoListRetrieveThread(IPackageInfoListListener* pPackageListener)
34 : __pPackageListener(pPackageListener)
36 // No implementation required
40 PackageInfoListRetrieveThread::~PackageInfoListRetrieveThread(void)
42 // No implementation required
46 PackageInfoListRetrieveThread::SetPackageType(void)
52 PackageInfoListRetrieveThread::Run(void)
55 PackageManager* pPackMgr = PackageManager::GetInstance();
56 String currentAppName = UiApp::GetInstance()->GetAppName();
58 int currentPosition = 0;
61 HashMap* pAppHashMap = null;
62 IList* pPackList = null;
63 IEnumerator* pEnum = null;
65 if (pAppHashMap == null)
67 ArrayList* pArrayList = null;
69 // constructs hashmap to maintain key(page number) value(list of icons associated to the page) pairs of all pages
70 pAppHashMap = new (std::nothrow) HashMap();
71 r = pAppHashMap->Construct();
72 pArrayList = new (std::nothrow) ArrayList();
73 r = pArrayList->Construct();
74 pKey = new (std::nothrow) Integer(currentPage);
75 r = pAppHashMap->Add(pKey, pArrayList); //transfers ownership to the hashmap
76 TryCatch(r == E_SUCCESS, delete pKey;
79 pArrayList = null, "pAppHashMap->Add(*pKey, *pArrayList) failed with error = %s", GetErrorMessage(r));
85 pPackList = pPackMgr->GetPackageInfoListN();
87 if (pPackList == null)
89 __pPackageListener->OnPackageInfoRetrievedN(pAppHashMap, totalApps, totalPages);
93 pEnum = pPackList->GetEnumeratorN();
95 while (pEnum != null && pEnum->MoveNext() == E_SUCCESS)
97 // PackageType type = PACKAGE_TYPE_TPK;
98 HomeItemInfo* pItemInfo = null;
99 ArrayList* pAppsList = null;
100 IList* pPackAppInfoList = null;
101 IEnumerator* pAppInfoEnumerator = null;
102 PackageInfo* pInfo = static_cast<PackageInfo*>(pEnum->GetCurrent());
103 TryCatch(pInfo != null, r = GetLastResult(), "pInfo is null error %s", GetErrorMessage(GetLastResult()));
104 pPackAppInfoList = pInfo->GetPackageAppInfoListN();
106 if (pPackAppInfoList != null)
108 pAppInfoEnumerator = pPackAppInfoList->GetEnumeratorN();
110 while (pAppInfoEnumerator != null && pAppInfoEnumerator->MoveNext() == E_SUCCESS)
112 PackageAppInfo* pPackAppInfo = static_cast<PackageAppInfo*>(pAppInfoEnumerator->GetCurrent());
113 pAppsList = static_cast<ArrayList*>(pAppHashMap->GetValue(Integer(currentPage)));
114 TryCatch(pAppsList != null, r = GetLastResult(), "pInfo is null error %s", GetErrorMessage(GetLastResult()));
115 // creates an instance of HomeItemInfo for each application to store the details of the application.
116 pItemInfo = new (std::nothrow) HomeItemInfo();
117 r = pItemInfo->Initialize(pPackAppInfo, pInfo);
119 if (!pItemInfo->IsVisibleInMainMenu() || pItemInfo->GetIconPath().IsEmpty())
126 pItemInfo->SetPositionInHomeScreen(currentPage, currentPosition);
128 // adds to the list if not service application
129 // if (!pItemInfo->GetAppName().Contains(L"service")
130 // && !pItemInfo->GetAppName().Equals(currentAppName, true))
133 r = pAppsList->Add(pItemInfo);
137 AppLogException("Failed to pAppsList->Add(pItemInfo) error %s", GetErrorMessage(r));
143 if (currentPosition >= MAX_ICONS_PER_PAGE)
147 ArrayList* pArrayList = new (std::nothrow) ArrayList();
148 pArrayList->Construct();
149 Integer* pKey = new (std::nothrow) Integer(currentPage);
150 pAppHashMap->Add(pKey, pArrayList); //transfers ownership to the hashmap
159 if (pAppInfoEnumerator != null)
161 delete pAppInfoEnumerator;
162 pAppInfoEnumerator = null;
166 pPackAppInfoList->RemoveAll();
167 delete pPackAppInfoList;
168 pPackAppInfoList = null;
171 if (currentPosition == 0 && currentPage > 1)
173 pAppHashMap->Remove(Integer(currentPage), true);
174 totalPages = currentPage - 1;
178 totalPages = currentPage;
181 __pPackageListener->OnPackageInfoRetrievedN(pAppHashMap, totalApps, totalPages);
182 pAppHashMap = null; //ownership transferred to the caller
190 if (pPackList != null)
192 pPackList->RemoveAll(true);
208 if (pPackList != null)
210 pPackList->RemoveAll(true);
215 if (pAppHashMap != null)
217 if (pAppHashMap->GetCount() > 0)
219 IList* pKeysList = pAppHashMap->GetKeysN();
221 for (int keyCount = 0; keyCount < pKeysList->GetCount(); keyCount++)
223 ArrayList* pAppList = static_cast<ArrayList*>(pAppHashMap->GetValue(*static_cast<Integer*>(pKeysList->GetAt(keyCount))));
225 if (pAppList != null)
227 pAppList->RemoveAll(true);
231 pKeysList->RemoveAll();
235 pAppHashMap->RemoveAll(true);