Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StDownloadedApplicationForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                StDownloadedApplicationForm.cpp
19  * @brief               This is the implementation file for DownloadedApplicationForm class.
20  */
21
22 #include <FIo.h>
23 #include "StDownloadedApplicationForm.h"
24 #include "StResourceManager.h"
25 #include "StSettingScenesList.h"
26 #include "StTypes.h"
27
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;
38
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/";
42
43 static const int ID_GROUP_COUNT = 1;
44 static const int ID_GROUP_MAX_ITEM_COUNT = 3;
45
46 DownloadedApplicationForm::DownloadedApplicationForm(void)
47         : __pDownloadAppIdKeyList(null)
48         , __pAppIdHashMap(null)
49         , __pAppIconPathHashMap(null)
50 {
51 }
52
53 DownloadedApplicationForm::~DownloadedApplicationForm(void)
54 {
55 }
56
57 void
58 DownloadedApplicationForm::CreateFooter(void)
59 {
60         Footer* pFooter = GetFooter();
61         AppAssert(pFooter);
62
63         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
64         pFooter->SetBackButton();
65         pFooter->AddActionEventListener(*this);
66
67         SetFormBackEventListener(this);
68 }
69
70 result
71 DownloadedApplicationForm::OnInitializing(void)
72 {
73         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_DOWNLOADED_APPLICATIONS"));
74         CreateFooter();
75         CreateTableView();
76         SetAppIdListFromPackageManager();
77         UpdateTableViewAndNoContent();
78
79         return E_SUCCESS;
80 }
81
82 result
83 DownloadedApplicationForm::OnTerminating(void)
84 {
85         RemoveAllDownLoadAppIdKeyList();
86         RemoveAllAppIdList();
87         int controlCount = GetControlCount();
88         for (int i = 0; i < controlCount; i++)
89         {
90                 RemoveControl(GetControl(0));
91         }
92         __pTableView = null;
93
94         SetFormBackEventListener(null);
95         return E_SUCCESS;
96 }
97
98 void
99 DownloadedApplicationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
100 {
101         if (pArgs != null)
102         {
103                 delete pArgs;
104         }
105         RemoveAllDownLoadAppIdKeyList();
106         SetAppIdListFromPackageManager();
107
108         UpdateTableViewAndNoContent();
109 }
110
111 void
112 DownloadedApplicationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
113 {
114 }
115
116 void
117 DownloadedApplicationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
118 {
119         SceneManager* pSceneManager = SceneManager::GetInstance();
120         AppAssert(pSceneManager);
121
122         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
123 }
124
125 int
126 DownloadedApplicationForm::GetGroupCount(void)
127 {
128         AppLogDebug("ENTER");
129
130         return ID_GROUP_COUNT;
131 }
132
133 int
134 DownloadedApplicationForm::GetItemCount(int groupIndex)
135 {
136         int itemCount = GetDownLoadAppCount();
137
138         AppLogDebug("GetItemCount %d", itemCount);
139
140         return itemCount;
141 }
142
143 TableViewGroupItem*
144 DownloadedApplicationForm::CreateGroupItem(int groupIndex, int itemWidth)
145 {
146         AppLogDebug("ENTER");
147
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;
152         String groupText;
153         Label* pLabel = null;
154         int fontSize = GetFontSize();
155
156         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
157
158         yItemOffset = H_GROUP_INDEX_NO_HELP_TEXT_GAP;
159         itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
160
161         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
162         itemRectangle.y = yItemOffset;
163         itemRectangle.width = itemWidth;
164         itemRectangle.height = itemHeight;
165
166         RelativeLayout relativeLayout;
167         relativeLayout.Construct();
168
169         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
170         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
171
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);
178
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);
184
185         return pItem;
186 }
187
188 TableViewItem*
189 DownloadedApplicationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
190 {
191         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
192
193         Rectangle itemIconRectangle;
194         Rectangle itemMainRectangle;
195         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
196         String itemMainText;
197         String fontReturnValue;
198         Label* pLabel = null;
199         Bitmap* pBitmap;
200
201         int fontSize = GetFontSize();
202         int itemHeight = H_GROUP_ITEM_DEFAULT_LABEL;
203         ItemTypeIconAndOneLine(itemIconRectangle, itemMainRectangle);
204
205         String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
206         String iconPath = GetAppSettingIconPathFromAppIdListAt(appIdKey);
207
208         itemMainText = GetDownLoadAppNameAt(itemIndex);
209
210         if (iconPath.IsEmpty() == true)
211         {
212                 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
213         }
214         else
215         {
216                 pBitmap = ResourceManager::GetApplicationBitmapN(iconPath);
217         }
218         TableViewItem* pItem = new (std::nothrow) TableViewItem();
219
220         RelativeLayout relativeLayout;
221         relativeLayout.Construct();
222
223         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight), style);
224         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
225
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);
231
232         pItem->AddControl(pLabel);
233
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);
239
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);
244
245         return pItem;
246 }
247
248 bool
249 DownloadedApplicationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
250 {
251         AppLogDebug("ENTER");
252
253         delete pItem;
254         pItem = null;
255
256         return true;
257 }
258
259 bool
260 DownloadedApplicationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
261 {
262         AppLogDebug("ENTER");
263
264         delete pItem;
265         pItem = null;
266
267         return true;
268 }
269
270 void
271 DownloadedApplicationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
272 {
273         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
274
275         SceneManager* pSceneManager = SceneManager::GetInstance();
276         AppAssert(pSceneManager);
277
278         ArrayList* pArgs = null;
279
280         String appIdKey = GetDownLoadAppIdKeyAt(itemIndex);
281         if (appIdKey.IsEmpty() == true)
282         {
283                 AppLogDebug("GetDownLoadAppIdKeyAt[%d] fail", itemIndex);
284         }
285
286         String appSettingFilepath = GetAppSettingFilePathFromAppIdListAt(appIdKey);
287         if (appSettingFilepath.IsEmpty() == true)
288         {
289                 AppLogDebug("GetAppSettingFilePathFromAppIdListAt[%ls] fail", appIdKey.GetPointer());
290         }
291
292         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
293         if (pArgs == null)
294         {
295                 AppLogDebug("pArgs is null");
296         }
297
298         result r = pArgs->Construct();
299         if (IsFailed(r))
300         {
301                 AppLogDebug("Construct fail [%s]", GetErrorMessage(r));
302         }
303
304         pArgs->Add(*(new (std::nothrow) String(appIdKey)));
305         pArgs->Add(*(new (std::nothrow) String(appSettingFilepath)));
306
307         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_XML_PARSER, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
308 }
309
310 int
311 DownloadedApplicationForm::GetDefaultGroupItemHeight(void)
312 {
313         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
314 }
315
316 int
317 DownloadedApplicationForm::GetDefaultItemHeight(void)
318 {
319         return H_GROUP_ITEM_DEFAULT;
320 }
321
322 void
323 DownloadedApplicationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
324 {
325 }
326
327 void
328 DownloadedApplicationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
329 {
330         Invalidate(true);
331 }
332
333 void
334 DownloadedApplicationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
335 {
336 }
337
338 void
339 DownloadedApplicationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
340 {
341 }
342
343 void
344 DownloadedApplicationForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
345 {
346         Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
347         if (pLabel != null)
348         {
349                 Rectangle clientRect = GetClientAreaBounds();
350                 Rectangle labelBound = pLabel->GetBounds();
351
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);
354
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)
359                 {
360                         pTextLabel->SetBounds(Rectangle(0, yPos, clientRect.width, pTextLabel->GetBounds().height));
361                 }
362         }
363         Invalidate(true);
364 }
365
366 void
367 DownloadedApplicationForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
368 {
369         if (requestId == FRFRESH_REQUEST_EVENT)
370         {
371                 if (__pTableView)
372                 {
373                         RemoveAllDownLoadAppIdKeyList();
374                         SetAppIdListFromPackageManager();
375                         __pTableView->UpdateTableView();
376                 }
377                 if (pArgs)
378                 {
379                         pArgs->RemoveAll(true);
380                         delete pArgs;
381                 }
382         }
383 }
384
385 result
386 DownloadedApplicationForm::SetDownLoadAppIdKeyList(void)
387 {
388         RemoveAllDownLoadAppIdKeyList();
389
390         if (__pAppIdHashMap == null)
391         {
392                 AppLogDebug("__pAppIdHashMap is null");
393                 return E_FAILURE;
394         }
395
396         __pDownloadAppIdKeyList = __pAppIdHashMap->GetKeysN();
397         if (__pDownloadAppIdKeyList == null)
398         {
399                 AppLogDebug("__pDownloadAppIdKeyList is null");
400                 return E_FAILURE;
401         }
402
403         return E_SUCCESS;
404 }
405
406 void
407 DownloadedApplicationForm::RemoveAllDownLoadAppIdKeyList(void)
408 {
409         if (__pDownloadAppIdKeyList != null)
410         {
411                 __pDownloadAppIdKeyList->RemoveAll();
412                 delete __pDownloadAppIdKeyList;
413                 __pDownloadAppIdKeyList = null;
414         }
415 }
416
417 result
418 DownloadedApplicationForm::SetAppIdListFromPackageManager(void)
419 {
420         RemoveAllAppIdList();
421
422         __pAppIdHashMap = new (std::nothrow) HashMap();
423         if (__pAppIdHashMap == null)
424         {
425                 AppLogDebug("__pAppIdHashMap is null");
426                 return E_FAILURE;
427         }
428
429         result r = __pAppIdHashMap->Construct();
430         if (IsFailed(r))
431         {
432                 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
433                 RemoveAllAppIdList();
434                 return E_FAILURE;
435         }
436
437         __pAppIconPathHashMap = new (std::nothrow) HashMap();
438         if (__pAppIconPathHashMap == null)
439         {
440                 AppLogDebug("__pAppIconPathHashMap is null");
441                 return E_FAILURE;
442         }
443         r = __pAppIconPathHashMap->Construct();
444         if (IsFailed(r))
445         {
446                 AppLogDebug("Construct fail [%s]", GetErrorMessage(GetLastResult()));
447                 RemoveAllAppIdList();
448                 return E_FAILURE;
449         }
450
451         IList* pList = null;
452         PackageManager* pPackageManager = PackageManager::GetInstance();
453         if (pPackageManager == null)
454         {
455                 AppLogDebug("pPackageManager is null");
456                 RemoveAllAppIdList();
457                 return E_FAILURE;
458         }
459
460         HashMap packageFilterMap;
461         r = packageFilterMap.Construct();
462         if (IsFailed(r))
463         {
464                 AppLogDebug("pPackageFilter Construct fail");
465         }
466
467         String* pKey = new (std::nothrow) String("http://tizen.org/package/appsetting");
468         Boolean* pValue = new (std::nothrow) Boolean(true);
469
470         r = packageFilterMap.Add(pKey, pValue);
471         if (IsFailed(r))
472         {
473                 AppLogDebug("packageFilterMap add Fail");
474         }
475
476         pList = pPackageManager->GetPackageInfoListN(packageFilterMap);
477         if (pList == null)
478         {
479                 AppLogDebug("pList is null");
480                 RemoveAllAppIdList();
481                 return E_FAILURE;
482         }
483
484         IEnumerator* pEnumerator = pList->GetEnumeratorN();
485         if (pEnumerator == null)
486         {
487                 AppLogDebug("pEnumerator is null");
488                 pList->RemoveAll();
489                 delete pList;
490                 RemoveAllAppIdList();
491                 return E_FAILURE;
492         }
493
494         bool isFindXml = false;
495         UiApp* pApp = UiApp::GetInstance();
496         AppAssert(pApp);
497
498         while (pEnumerator->MoveNext() == E_SUCCESS)
499         {
500                 PackageInfo* pPackage = static_cast<PackageInfo*>(pEnumerator->GetCurrent());
501                 if (pPackage != null && pPackage->GetType() == PACKAGE_TYPE_TPK)
502                 {
503                         String path(ID_APPLICATION_DEFAULT_FOLDER_PATH);
504                         path.Append(pPackage->GetId());
505
506                         path.Append(ID_RELATIVE_SETTING_XML_FILE_PATH);
507
508                         if ((File::IsFileExist(path) == true)
509                                 && (!pApp->GetAppId().Contains(pPackage->GetId())))
510                         {
511                                 String key(pPackage->GetDisplayName());
512                                 key.Append(L":");
513                                 key.Append(pPackage->GetId());
514
515                                 String currentAppId = pPackage->GetMainAppId();
516                                 PackageAppInfo* pPackageInfo = static_cast<PackageAppInfo*>(pPackage->GetPackageAppInfoN(currentAppId));
517
518                                 bool isIME = false;
519                                 IList* pCategoryList = pPackageInfo->GetAppCategoryListN();
520                                 if (pCategoryList)
521                                 {
522                                         for (int i=0; i<pCategoryList->GetCount(); ++i)
523                                         {
524                                                 String* pCategory = static_cast<String*>(pCategoryList->GetAt(i));
525                                                 if (pCategory->Equals(L"http://tizen.org/category/ime", false))
526                                                 {
527                                                         isIME = true;
528                                                         break;
529                                                 }
530                                         }
531                                 }
532
533                                 if (isIME)
534                                 {
535                                         continue;
536                                 }
537
538                                 String iconPath = pPackageInfo->GetAppMenuIconPath();
539
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)));
542                                 isFindXml = true;
543                         }
544                 }
545         }
546         delete pEnumerator;
547         delete pList;
548
549         if (isFindXml == false)
550         {
551                 RemoveAllAppIdList();
552                 return E_FAILURE;
553         }
554
555         r = SetDownLoadAppIdKeyList();
556         if (IsFailed(r))
557         {
558                 RemoveAllDownLoadAppIdKeyList();
559                 RemoveAllAppIdList();
560                 return E_FAILURE;
561         }
562
563         return E_SUCCESS;
564 }
565
566
567 void
568 DownloadedApplicationForm::RemoveAllAppIdList(void)
569 {
570         if (__pAppIdHashMap != null)
571         {
572                 __pAppIdHashMap->RemoveAll();
573                 delete __pAppIdHashMap;
574                 __pAppIdHashMap = null;
575         }
576
577         if (__pAppIconPathHashMap != null)
578         {
579                 __pAppIconPathHashMap->RemoveAll();
580                 delete __pAppIconPathHashMap;
581                 __pAppIconPathHashMap = null;
582         }
583 }
584
585 Tizen::Base::String
586 DownloadedApplicationForm::GetAppSettingFilePathFromAppIdListAt(Tizen::Base::String key)
587 {
588         String appSettingFilePath;
589         if (__pAppIdHashMap == null)
590         {
591                 AppLogDebug("__pAppIdHashMap is null");
592                 return appSettingFilePath;
593         }
594
595         bool isFind = false;
596         result r = __pAppIdHashMap->ContainsKey(key, isFind);
597         if ((isFind == false)
598                 || (IsFailed(r)))
599         {
600                 if (isFind == false)
601                 {
602                         AppLogDebug("key[%ls] is not found", key.GetPointer());
603                 }
604                 else
605                 {
606                         AppLogDebug("ContainsKey fail [%s]", GetErrorMessage(r));
607                 }
608                 return appSettingFilePath;
609         }
610
611         String* pValue = static_cast<String*>(__pAppIdHashMap->GetValue(key));
612         if (pValue == null)
613         {
614                 AppLogDebug("pValue is null");
615                 return appSettingFilePath;
616         }
617
618         appSettingFilePath.Append(*pValue);
619         return appSettingFilePath;
620 }
621
622 Tizen::Base::String
623 DownloadedApplicationForm::GetDownLoadAppNameAt(unsigned int index)
624 {
625         String appName;
626         if (__pDownloadAppIdKeyList == null)
627         {
628                 AppLogDebug("__pDownloadAppIdKeyList is null");
629                 return appName;
630         }
631
632         String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
633         if (pAppKey == null)
634         {
635                 AppLogDebug("pAppKey is null");
636                 return appName;
637         }
638
639         StringTokenizer stringTokenizer(*pAppKey, L":");
640         result r = stringTokenizer.GetNextToken(appName);
641         if (IsFailed(r))
642         {
643                 AppLogDebug("GetNextToken fail[%s]",GetErrorMessage(r));
644                 return appName;
645         }
646
647         return appName;
648 }
649
650 Tizen::Base::String
651 DownloadedApplicationForm::GetDownLoadAppIdKeyAt(unsigned int index)
652 {
653         String appIdKey;
654         if (__pDownloadAppIdKeyList == null)
655         {
656                 AppLogDebug("__pDownloadAppIdKeyList is null");
657                 return appIdKey;
658         }
659
660         String* pAppKey = static_cast<String*>(__pDownloadAppIdKeyList->GetAt(index));
661         if (pAppKey == null)
662         {
663                 AppLogDebug("pAppKey is null");
664                 return appIdKey;
665         }
666
667         appIdKey.Append(*pAppKey);
668
669         return appIdKey;
670 }
671
672 unsigned int
673 DownloadedApplicationForm::GetDownLoadAppCount(void)
674 {
675         unsigned int downLoadAppCount = 0;
676         if (__pDownloadAppIdKeyList == null)
677         {
678                 AppLogDebug("__pDownloadAppIdKeyList is null");
679                 return downLoadAppCount;
680         }
681
682         downLoadAppCount = __pDownloadAppIdKeyList->GetCount();
683         return downLoadAppCount;
684 }
685
686 Tizen::Base::String
687 DownloadedApplicationForm::GetAppSettingIconPathFromAppIdListAt(Tizen::Base::String& id)
688 {
689         String iconPath;
690
691         if (__pAppIconPathHashMap)
692         {
693                 if (__pAppIconPathHashMap->ContainsKey(id) == true)
694                 {
695                         iconPath = *(static_cast<String*>(__pAppIconPathHashMap->GetValue((id))));
696                 }
697         }
698         return iconPath;
699 }
700
701 void
702 DownloadedApplicationForm::UpdateTableViewAndNoContent(void)
703 {
704         bool createTableView = false;
705         if (__pTableView != null)
706         {
707                 if (GetDownLoadAppCount() != 0)
708                 {
709                         __pTableView->UpdateTableView();
710                         return;
711                 }
712         }
713         else
714         {
715                 if (GetDownLoadAppCount() != 0)
716                 {
717                         createTableView = true;
718                 }
719         }
720
721         if (__pTableView != null)
722         {
723                 int tableViewControlCount = __pTableView->GetControlCount();
724                 for (int i = 0; i < tableViewControlCount; i++)
725                 {
726                         __pTableView->RemoveControl(__pTableView->GetControl(0));
727                 }
728 //                      __pTableView->RemoveAllControls();
729                 __pTableView = null;
730         }
731         int controlCount = GetControlCount();
732         for (int i = 0; i < controlCount; i++)
733         {
734                 RemoveControl(GetControl(0));
735         }
736 //      RemoveAllControls();
737
738         if (createTableView)
739         {
740                 CreateTableView();
741                 __pTableView->UpdateTableView();
742         }
743         else
744         {
745                 Label* pLabel = static_cast<Label*>(this->GetControl(NO_CONTENTS, false));
746                 if (pLabel == null)
747                 {
748                         Rectangle clientRect = GetClientAreaBounds();
749                         Bitmap* pBitmp = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
750
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);
756
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);
759
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);
764
765                         yPos = yPos + bitmapHeight;
766
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);
772
773                         AddControl(pLabel);
774                         AddControl(pLabelNoContents);
775                 }
776         }
777 }