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