Applied latest source code
[apps/native/preloaded/Settings.git] / src / StManageApplicationInfoForm.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                StManageApplicationInfoForm.cpp
19  * @brief               This is the implementation file for ManageApplicationInfoForm class.
20  */
21
22 #include "StManageApplicationInfoForm.h"
23 #include "StResourceManager.h"
24 #include "StTypes.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::App::Package;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::System;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int ID_GROUP_APPLICATION_NAME = 0;
37 static const int ID_GROUP_APPLICATION_NAME_ITEM_COUNT = 2;
38 static const int ID_ITEM_APPLICATION_NAME = 0;
39 static const int ID_ITEM_APPLICATION_COMMAND_BUTTON = 1;
40
41 static const int ID_GROUP_APPLICATION_SIZE = 1;
42 static const int ID_GROUP_APPLICATION_SIZE_ITEM_COUNT = 3;
43 static const int ID_ITEM_APPLICATION_SIZE = 1;
44 static const int ID_ITEM_APPLICATION_DATA_SIZE = 2;
45
46 static const int ID_GROUP_APPLICATION_CLEAR_DEFAULT = 2;
47 static const int ID_GROUP_APPLICATION_CLEAR_DEFAULT_ITEM_COUNT = 1;
48
49 static const int ID_GROUP_APPLICATION_CLEAR_DEFAULT_HELP = 3;
50
51 static const int ID_GROUP_APPLICATION_DETAIL = 4;
52
53 static const int ID_TOTAL_GROUP_COUNT = 2;
54
55 static const int IDA_FORCE_STOP = 300;
56 static const int IDA_UNINSTALL = 310;
57 static const int IDA_UNINSTALL_CONFIRM_OK = 320;
58 static const int IDA_UNINSTALL_CONFIRM_CANCEL = 330;
59
60 static const int Y_ALERT_POPUP_CLIENT_RECT_DEFAULT = 160;
61 static const int X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
62 static const int Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 20;
63 static const int H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 340;
64 static const int W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT = 690;
65 static const int X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 12;
66 static const int Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 360;
67 static const int W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 310;
68 static const int H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT = 80;
69 static const int X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE = 20;
70 static const int ALERT_POPUP_LABEL_FONT_SIZE = 40;
71
72 static const int W_ALERT_POPUP_CLIENT_RECT_DEFAULT = 700;
73 static const int H_ALERT_POPUP_CLIENT_RECT_DEFAULT = 550;
74
75 static const int COMMAND_BUTTON_GAP = 20;
76 static const int APPLICATION_NAME_MARGIN_GAP = 100;
77 static const int APPLICATION_NAME_SECOND_CONTROL = 1;
78
79 static const int KILOBYTE_TO_MEGABYTE = 1024;
80 static const int MEGABYTE_TO_GIGABYTE = 1024;
81
82 enum _dataType
83 {
84         DATA_TYPE_APPLICATION_NAME = 0,
85         DATA_TYPE_APPLICATION_ICON_PATH,
86         DATA_TYPE_APPLICATION_UNINSTALLABLE,
87         DATA_TYPE_APPLICATION_SIZE,
88         DATA_TYPE_APPLICATION_DATA_SIZE,
89         DATA_TYPE_APPLICATION_ID,
90         DATA_TYPE_APPLICATION_PACKAGE_ID,
91 };
92
93 enum _uninstallPopup
94 {
95         UNINSTALL_POPUP_OKCANCEL = 0,
96         UNINSTALL_POPUP_PROGRESS,
97 };
98
99 ManageApplicationInfoForm::ManageApplicationInfoForm(void)
100         : __applicationData(null)
101         , __pPackageManager(null)
102         , __uninstallConfirmPopup(null)
103         , __pProgressPopup(null)
104 {
105 }
106
107 ManageApplicationInfoForm::~ManageApplicationInfoForm(void)
108 {
109 }
110
111 void
112 ManageApplicationInfoForm::CreateFooter(void)
113 {
114         Footer* pFooter = GetFooter();
115         AppAssert(pFooter);
116
117         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
118         pFooter->AddActionEventListener(*this);
119
120         SetFormBackEventListener(this);
121 }
122
123 result
124 ManageApplicationInfoForm::OnInitializing(void)
125 {
126         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_APPLICATION_INFO"));
127         CreateTableView();
128
129         __pPackageManager = PackageManager::GetInstance();
130
131         if (__pPackageManager)
132         {
133                 __pPackageManager->AddPackageInstallationEventListener(*this);
134         }
135
136         AppLogDebug("ENTER");
137
138         return E_SUCCESS;
139 }
140
141 result
142 ManageApplicationInfoForm::OnTerminating(void)
143 {
144         if (__pPackageManager)
145         {
146                 __pPackageManager->RemovePackageInstallationEventListener(*this);
147         }
148         delete __applicationData;
149
150         DeleteUninstallPopup();
151
152         __pTableView = null;
153         SetFormBackEventListener(null);
154         RemoveOrientationEventListener(*this);
155         return E_SUCCESS;
156 }
157
158 void
159 ManageApplicationInfoForm::GroupItemEnable(int groupIndex, bool setEnableStatus)
160 {
161         int itemCount = __pTableView->GetItemCountAt(groupIndex);
162
163         for (int i = 0; i< itemCount; i++)
164         {
165                 __pTableView->SetItemEnabled(groupIndex, i, setEnableStatus);
166         }
167 }
168
169 void
170 ManageApplicationInfoForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
171 {
172         if (pArgs)
173         {
174                 __applicationData = static_cast<ArrayList*>(pArgs->GetItemsN(0, pArgs->GetCount()));
175
176                 __pTableView->UpdateTableView();
177
178                 GroupItemEnable(ID_GROUP_APPLICATION_SIZE, false);
179                 GroupItemEnable(ID_GROUP_APPLICATION_CLEAR_DEFAULT, false);
180                 GroupItemEnable(ID_GROUP_APPLICATION_DETAIL, false);
181         }
182 }
183
184 void
185 ManageApplicationInfoForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
186 {
187 }
188
189 void
190 ManageApplicationInfoForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
191 {
192         SceneManager* pSceneManager = SceneManager::GetInstance();
193         AppAssert(pSceneManager);
194
195         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
196 }
197
198 int
199 ManageApplicationInfoForm::GetGroupCount(void)
200 {
201         // Temporary code due to the UI Framework defect
202         if (!__applicationData)
203         {
204                 return 0;
205         }
206
207         AppLogDebug("ENTER");
208         return ID_TOTAL_GROUP_COUNT;
209 }
210
211 int
212 ManageApplicationInfoForm::GetItemCount(int groupIndex)
213 {
214         // Temporary code due to the UI Framework defect
215         if (!__applicationData)
216         {
217                 return 0;
218         }
219
220         int itemCount = 0;
221
222         switch (groupIndex)
223         {
224         case ID_GROUP_APPLICATION_NAME:
225                 {
226                         itemCount = ID_GROUP_APPLICATION_NAME_ITEM_COUNT;
227                 }
228                 break;
229
230         case ID_GROUP_APPLICATION_SIZE:
231                 {
232                         itemCount = ID_GROUP_APPLICATION_SIZE_ITEM_COUNT;
233                 }
234                 break;
235
236         case ID_GROUP_APPLICATION_CLEAR_DEFAULT:
237                 // fall through
238         case ID_GROUP_APPLICATION_DETAIL:
239                 {
240                         itemCount = ID_GROUP_APPLICATION_CLEAR_DEFAULT_ITEM_COUNT;
241                 }
242                 break;
243
244         default:
245                 break;
246         }
247
248         AppLogDebug("GetItemCount %d", itemCount);
249
250         return itemCount;
251 }
252
253 TableViewGroupItem*
254 ManageApplicationInfoForm::CreateGroupItem(int groupIndex, int itemWidth)
255 {
256         AppLogDebug("ENTER");
257
258         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
259         int yItemOffset = H_GROUP_INDEX_HELP_TEXT_TOP_GAP;
260         LabelTextStyle style = LABEL_TEXT_STYLE_NORMAL;
261         Rectangle itemRectangle;
262         String groupText;
263         Label* pLabel = null;
264
265         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
266
267         itemRectangle.x = X_GROUP_ITEM_DEFAULT_LABEL;
268         itemRectangle.y = yItemOffset;
269         itemRectangle.width = itemWidth;
270         itemRectangle.height = itemHeight;
271
272         if (groupIndex == ID_GROUP_APPLICATION_CLEAR_DEFAULT_HELP)
273         {
274                 itemRectangle.y = 0;
275                 itemRectangle.height = itemHeight = H_GROUP_ITEM_DEFAULT;
276                 groupText = ResourceManager::GetString(L"IDS_ST_BODY_YOU_HAVE_SELECTED_TO_LAUNCH_THIS_APPLICATION_BY_DEFAULT_FOR_SOME_ACTIONS");
277         }
278
279         RelativeLayout relativeLayout;
280         relativeLayout.Construct();
281
282         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
283         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
284
285         pLabel = new (std::nothrow) Label();
286         pLabel->Construct(itemRectangle, groupText);
287         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
288         pLabel->SetTextVerticalAlignment(ALIGNMENT_TOP);
289         pLabel->SetTextConfig(FONT_MAIN_TEXT_SIZE_SMALL, style);
290         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
291
292         pItem->AddControl(pLabel);
293         pItem->SetEnabled(false);
294         relativeLayout.SetMargin(*pLabel, itemRectangle.x, 0, 0, 0);
295         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
296         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
297
298         return pItem;
299 }
300
301 TableViewItem*
302 ManageApplicationInfoForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
303 {
304         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
305
306         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
307
308         bool isItemSubText = false;
309         bool isBitmapSet = false;
310         bool isCommandButton = false;
311         Rectangle itemIconRectangle;
312         Rectangle itemMainRectangle;
313         Rectangle itemSubRectangle;
314
315         int itemHeight = H_ITEM_TYPE_1_LABEL;
316
317         Bitmap* pBitmap = null;
318         Button* pStopButton = null;
319         Button* pUninstallButton = null;
320         Label* pLabel = null;
321         Label* pBitmapLabel = null;
322
323         String itemMainText;
324         String itemSubText;
325
326         int fontSize = GetFontSize();
327         TableViewItem* pItem = new (std::nothrow) TableViewItem();
328
329         ItemTypeOneLine(itemMainRectangle);
330         itemHeight = itemMainRectangle.height;
331
332         switch (groupIndex)
333         {
334         case ID_GROUP_APPLICATION_NAME:
335                 {
336                         switch (itemIndex)
337                         {
338                         case ID_ITEM_APPLICATION_NAME:
339                                 {
340                                         isItemSubText = true;
341                                         isBitmapSet = true;
342                                         double appSize = 0;
343                                         double dataSize = 0;
344
345                                         String bitmapPath = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_ICON_PATH)));
346                                         pBitmap = ResourceManager::GetApplicationBitmapN(bitmapPath);
347
348                                         if (pBitmap == null)
349                                         {
350                                                 pBitmap = ResourceManager::GetBitmapN(IDB_DEFAULT_ICON);
351                                         }
352
353                                         String sizeData;
354                                         ItemTypeIconAndTwoLine(itemIconRectangle, itemMainRectangle, itemSubRectangle, fontSize);
355                                         itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
356                                         itemMainText = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_NAME)));
357                                         sizeData = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_SIZE)));
358                                         Double::Parse(sizeData, appSize);
359                                         sizeData = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_DATA_SIZE)));
360                                         Double::Parse(sizeData, dataSize);
361
362                                         if (((appSize+dataSize) / KILOBYTE_TO_MEGABYTE) >= 1)
363                                         {
364                                                 itemSubText = Double::ToString(((appSize+dataSize) / KILOBYTE_TO_MEGABYTE));
365                                                 itemSubText.Append(L" MB");
366                                         }
367                                         else
368                                         {
369                                                 itemSubText = Double::ToString(((appSize+dataSize)));
370                                                 itemSubText.Append(L" KB");
371                                         }
372                                 }
373                                 break;
374
375                         default:
376                                 {
377                                         isCommandButton = true;
378                                 }
379                                 break;
380                         }
381                 }
382                 break;
383
384         case ID_GROUP_APPLICATION_SIZE:
385                 {
386                         double appSize = 0;
387                         double dataSize = 0;
388                         double totalSize = 0;
389                         String tmpDataSize;
390
391                         isItemSubText = true;
392
393                         ItemTypeTwoLine(itemMainRectangle, itemSubRectangle, fontSize);
394                         itemHeight = (itemMainRectangle.height + itemSubRectangle.height);
395
396                         switch (itemIndex)
397                         {
398                         case ID_ITEM_APPLICATION_SIZE:
399                                 {
400                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_APPLICATION");
401                                         tmpDataSize = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_SIZE)));
402
403                                         Double::Parse(tmpDataSize, appSize);
404                                         totalSize = appSize;
405                                 }
406                                 break;
407
408                         case ID_ITEM_APPLICATION_DATA_SIZE:
409                                 {
410                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_DATA");
411                                         tmpDataSize = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_DATA_SIZE)));
412
413                                         Double::Parse(tmpDataSize, dataSize);
414                                         totalSize = dataSize;
415                                 }
416                                 break;
417
418                         default:
419                                 {
420                                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_TOTAL");
421                                         tmpDataSize = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_SIZE)));
422                                         Double::Parse(tmpDataSize, appSize);
423                                         tmpDataSize = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_DATA_SIZE)));
424                                         Double::Parse(tmpDataSize, dataSize);
425
426                                         totalSize = (appSize + dataSize);
427                                 }
428                                 break;
429                         }
430
431                         if ((totalSize / KILOBYTE_TO_MEGABYTE) >= 1)
432                         {
433                                 itemSubText = Double::ToString((totalSize / KILOBYTE_TO_MEGABYTE));
434                                 itemSubText.Append(L" MB");
435                         }
436                         else
437                         {
438                                 itemSubText = Double::ToString((totalSize));
439                                 itemSubText.Append(L" KB");
440                         }
441                 }
442                 break;
443
444         case ID_GROUP_APPLICATION_CLEAR_DEFAULT:
445                 {
446                         ItemTypeOneLine(itemMainRectangle);
447                         itemHeight = itemMainRectangle.height;
448
449                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_CLEAR_DEFAULTS");
450                 }
451                 break;
452
453         case ID_GROUP_APPLICATION_DETAIL:
454                 {
455                         ItemTypeOneLine(itemMainRectangle);
456                         itemHeight = itemMainRectangle.height;
457
458                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_MORE_DETAILS");
459                 }
460                 break;
461
462         default:
463                 break;
464         }
465
466         RelativeLayout relativeLayout;
467         relativeLayout.Construct();
468
469         if (isCommandButton == true)
470         {
471                 String homeAppId;
472                 String lockAppId;
473                 String appId;
474                 bool isMenuIconVisible = false;
475                 itemMainRectangle.height -= (H_ITEM_TYPE_1_LABEL / DIVIDE_BY_TWO);
476
477                 pItem->Construct(Dimension(itemWidth, itemMainRectangle.height), style);
478                 pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
479
480                 Rectangle stopButtonRect;
481                 Rectangle uninstallButtonRect;
482
483                 stopButtonRect = itemMainRectangle;
484                 stopButtonRect.x = stopButtonRect.x + COMMAND_BUTTON_GAP;
485                 stopButtonRect.width = (itemWidth / DIVIDE_BY_TWO) - 2 * COMMAND_BUTTON_GAP;
486
487                 uninstallButtonRect = itemMainRectangle;
488                 uninstallButtonRect.x = (itemWidth / DIVIDE_BY_TWO) + COMMAND_BUTTON_GAP;
489                 uninstallButtonRect.width = (itemWidth / DIVIDE_BY_TWO) - 2 * COMMAND_BUTTON_GAP;
490
491                 pStopButton = new (std::nothrow) Button();
492                 pStopButton->Construct(stopButtonRect, ResourceManager::GetString(L"IDS_ST_BUTTON_FORCE_STOP"));
493                 pStopButton->SetActionId(IDA_FORCE_STOP);
494
495                 SettingInfo::GetValue(SETTING_INFO_KEY_SCREEN_TYPE_HOME, homeAppId);
496                 SettingInfo::GetValue(SETTING_INFO_KEY_SCREEN_TYPE_LOCK, lockAppId);
497
498                 appId = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_ID)));
499                 AppManager* pAppManager = AppManager::GetInstance();
500
501                 if(__pPackageManager)
502                 {
503                          PackageAppInfo* pPackageAppInfo = __pPackageManager->GetPackageAppInfoN(appId);
504                          if(pPackageAppInfo)
505                          {
506                                  isMenuIconVisible = pPackageAppInfo->IsMenuIconVisible();
507                                  delete pPackageAppInfo;
508                          }
509                 }
510
511                 if (pAppManager->IsRunning(appId) == false || appId == homeAppId || appId == lockAppId || !isMenuIconVisible)
512                 {
513                         pStopButton->SetEnabled(false);
514                 }
515
516                 pStopButton->AddActionEventListener(*this);
517
518                 String uninstallable = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_UNINSTALLABLE)));
519
520                 pUninstallButton = new (std::nothrow) Button();
521                 pUninstallButton->Construct(uninstallButtonRect, ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL"));
522
523                 if (uninstallable.Equals(L"0", true) || appId == homeAppId || appId == lockAppId)
524                 {
525                         pUninstallButton->SetEnabled(false);
526                         pItem->SetEnabled(false);
527                 }
528                 pUninstallButton->SetActionId(IDA_UNINSTALL);
529                 pUninstallButton->AddActionEventListener(*this);
530
531                 pItem->AddControl(pStopButton);
532                 pItem->AddControl(pUninstallButton);
533                 pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
534                 pItem->SetIndividualSelectionEnabled(pStopButton, true);
535                 pItem->SetIndividualSelectionEnabled(pUninstallButton, true);
536         }
537         else
538         {
539                 pItem->Construct(Dimension(itemWidth, itemHeight), style);
540                 pItem->SetBackgroundColor(COLOR_ID_WHITE, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
541
542                 if (isBitmapSet == true)
543                 {
544                         pBitmapLabel = new (std::nothrow) Label();
545                         pBitmapLabel->Construct(itemIconRectangle, L"");
546                         pBitmapLabel->SetBackgroundBitmap(*pBitmap);
547                         pItem->AddControl(pBitmapLabel);
548                 }
549
550                 pLabel = new (std::nothrow) Label();
551                 pLabel->Construct(itemMainRectangle, itemMainText);
552                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
553                 pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
554                 pLabel->SetTextColor(COLOR_MAIN_TEXT);
555
556                 pItem->AddControl(pLabel);
557                 relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, 0, 0, 0);
558
559                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
560                 relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
561
562                 if (isItemSubText == true)
563                 {
564                         pLabel = new (std::nothrow) Label();
565                         pLabel->Construct(itemSubRectangle, itemSubText);
566                         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
567                         pLabel->SetTextConfig(FONT_SIZE_SUB_TEXT, LABEL_TEXT_STYLE_NORMAL);
568                         pLabel->SetTextColor(COLOR_SUB_TEXT);
569
570                         pItem->AddControl(pLabel);
571
572                         relativeLayout.SetMargin(*pLabel, itemSubRectangle.x, 0, 0, 0);
573                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
574                         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
575                 }
576         }
577         return pItem;
578 }
579
580 bool
581 ManageApplicationInfoForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
582 {
583         AppLogDebug("ENTER");
584
585         delete pItem;
586         pItem = null;
587
588         return true;
589 }
590
591 bool
592 ManageApplicationInfoForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
593 {
594         AppLogDebug("ENTER");
595
596         delete pItem;
597         pItem = null;
598
599         return true;
600 }
601
602 void
603 ManageApplicationInfoForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
604 {
605         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
606 }
607
608 int
609 ManageApplicationInfoForm::GetDefaultGroupItemHeight(void)
610 {
611         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
612 }
613
614 int
615 ManageApplicationInfoForm::GetDefaultItemHeight(void)
616 {
617         return H_GROUP_ITEM_DEFAULT;
618 }
619
620 void
621 ManageApplicationInfoForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
622 {
623 }
624
625 void
626 ManageApplicationInfoForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
627 {
628         switch (groupIndex)
629         {
630         case ID_GROUP_APPLICATION_NAME:
631                 {
632                         if (itemIndex == ID_ITEM_APPLICATION_NAME)
633                         {
634                                 Label* pLabel = static_cast<Label*>(pItem->GetControl(APPLICATION_NAME_SECOND_CONTROL));
635                                 Rectangle rect = pLabel->GetBounds();
636                                 Rectangle clientRect = GetClientAreaBounds();
637                                 rect.width = clientRect.width - APPLICATION_NAME_MARGIN_GAP;
638                                 pLabel->SetBounds(rect);
639
640                                 pItem->Invalidate(false);
641                         }
642                         else if (itemIndex == ID_ITEM_APPLICATION_COMMAND_BUTTON)
643                         {
644                                 String homeAppId;
645                                 bool isMenuIconVisible = false;
646                                 Rectangle pItemRect = pItem->GetBounds();
647                                 Rectangle clientRect = GetClientAreaBounds();
648
649                                 Button* pStopButton = static_cast<Button*>(pItem->GetControl(0));
650                                 Button* pUninstallButton = static_cast<Button*>(pItem->GetControl(1));
651
652                                 pStopButton->SetBounds(COMMAND_BUTTON_GAP, 0, (clientRect.width / DIVIDE_BY_TWO - 2 * COMMAND_BUTTON_GAP), pItemRect.height);
653                                 pUninstallButton->SetBounds((clientRect.width / DIVIDE_BY_TWO) + COMMAND_BUTTON_GAP, 0, (clientRect.width / DIVIDE_BY_TWO - 2 * COMMAND_BUTTON_GAP), pItemRect.height);
654
655                                 SettingInfo::GetValue(SETTING_INFO_KEY_SCREEN_TYPE_HOME, homeAppId);
656
657                                 String appId = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_ID)));
658                                 AppManager* pAppManager = AppManager::GetInstance();
659
660                                 if(__pPackageManager)
661                                 {
662                                          PackageAppInfo* pPackageAppInfo = __pPackageManager->GetPackageAppInfoN(appId);
663                                          if(pPackageAppInfo)
664                                          {
665                                                  isMenuIconVisible = pPackageAppInfo->IsMenuIconVisible();
666                                                  delete pPackageAppInfo;
667                                          }
668                                 }
669
670                                 if (pAppManager->IsRunning(appId) == false || appId == homeAppId || !isMenuIconVisible)
671                                 {
672                                         pStopButton->SetEnabled(false);
673                                 }
674                                 else
675                                 {
676                                         pStopButton->SetEnabled(true);
677                                 }
678
679                                 pStopButton->Invalidate(false);
680                                 pUninstallButton->Invalidate(false);
681                         }
682                 }
683                 break;
684
685         default:
686                 break;
687         }
688 }
689
690 void
691 ManageApplicationInfoForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
692 {
693 }
694
695 void
696 ManageApplicationInfoForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
697 {
698 }
699
700 void
701 ManageApplicationInfoForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
702 {
703         if (__pTableView == null)
704         {
705                 AppLogDebug("__pTableView is null");
706                 return;
707         }
708         __pTableView->RefreshItem(ID_GROUP_APPLICATION_NAME, ID_ITEM_APPLICATION_NAME, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
709         __pTableView->RefreshItem(ID_GROUP_APPLICATION_NAME, ID_ITEM_APPLICATION_COMMAND_BUTTON, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
710         Invalidate(true);
711 }
712
713 void
714 ManageApplicationInfoForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
715 {
716         switch (actionId)
717         {
718         case IDA_FORCE_STOP:
719                 {
720                         String appId = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_ID)));
721                         AppManager* pAppManager = AppManager::GetInstance();
722
723                         if (pAppManager->IsRunning(appId) == true)
724                         {
725                                 if (pAppManager->TerminateApplication(appId) == E_SUCCESS)
726                                 {
727                                         Button* pStopButton = static_cast<Button*>(&const_cast<Control&>(source));
728                                         pStopButton->SetEnabled(false);
729                                 }
730                                 AppLogDebug("TerminateApplication Result [%s]", GetErrorMessage(GetLastResult()));
731                         }
732                         else
733                         {
734                                 AppLogDebug("[%ls] is not running", appId.GetPointer());
735                         }
736                 }
737                 break;
738
739         case IDA_UNINSTALL:
740                 {
741                         CreateUninstallPopup();
742                         ShowUninstallPopup(UNINSTALL_POPUP_OKCANCEL);
743                 }
744                 break;
745
746         case IDA_UNINSTALL_CONFIRM_OK:
747                 {
748                         String packageId = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_PACKAGE_ID)));
749                         __pPackageManager->UninstallPackage (packageId, null);
750
751                         HideUninstallPopup(UNINSTALL_POPUP_OKCANCEL);
752                         ShowUninstallPopup(UNINSTALL_POPUP_PROGRESS);
753                 }
754                 break;
755
756         case IDA_UNINSTALL_CONFIRM_CANCEL:
757                 {
758                         HideUninstallPopup(UNINSTALL_POPUP_OKCANCEL);
759                 }
760                 break;
761
762         default:
763                 break;
764         }
765 }
766
767 void
768 ManageApplicationInfoForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
769 {
770         if (__pTableView)
771         {
772                 __pTableView->RefreshItem(ID_GROUP_APPLICATION_NAME, ID_ITEM_APPLICATION_COMMAND_BUTTON, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
773         }
774 }
775
776 void
777 ManageApplicationInfoForm::OnPackageUninstallationCompleted(const Tizen::App::PackageId& packageId, bool uninstallationResult)
778 {
779         HideUninstallPopup(UNINSTALL_POPUP_PROGRESS);
780
781         SceneManager* pSceneManager = SceneManager::GetInstance();
782         AppAssert(pSceneManager);
783
784         ArrayList* pUninstallationResult = new (std::nothrow) ArrayList(SingleObjectDeleter);
785         pUninstallationResult->Construct();
786         String *pApplicationName = static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_NAME));
787         if (pApplicationName)
788         {
789                 pUninstallationResult->Add(new (std::nothrow) String(*pApplicationName));
790         }
791         pUninstallationResult->Add(new (std::nothrow) String(Boolean::ToString(uninstallationResult)));
792
793         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pUninstallationResult);
794 }
795
796 result
797 ManageApplicationInfoForm::CreateUninstallPopup(void)
798 {
799         String buttonText;
800         Label* pLabel = null;
801         Button* pOkButton = null;
802         Button* pCancelButton = null;
803         String applicationName = *(static_cast<String*>(__applicationData->GetAt(DATA_TYPE_APPLICATION_NAME)));
804
805         Rectangle clientRect = GetClientAreaBounds();
806         Rectangle itemRectLabel;
807         Rectangle itemRectLhsButton;
808         Rectangle itemRectRhsButton;
809
810         clientRect.x = 0;
811         clientRect.y = Y_ALERT_POPUP_CLIENT_RECT_DEFAULT;
812         clientRect.width = W_ALERT_POPUP_CLIENT_RECT_DEFAULT;
813         clientRect.height = H_ALERT_POPUP_CLIENT_RECT_DEFAULT;
814
815         itemRectLabel.x = X_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
816         itemRectLabel.y = Y_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
817         itemRectLabel.width = W_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
818         itemRectLabel.height = H_ALERT_POPUP_ITEM_RECT_LABEL_DEFAULT;
819
820         itemRectLhsButton.x = X_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT + itemRectLabel.x;
821         itemRectLhsButton.y = Y_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
822         itemRectLhsButton.width = W_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
823         itemRectLhsButton.height = H_ALERT_POPUP_ITEM_RECT_LHS_BUTTON_DEFAULT;
824
825         itemRectRhsButton = itemRectLhsButton;
826         itemRectRhsButton.x = itemRectLhsButton.x + itemRectLhsButton.width + X_ALERT_POPUP_ITEM_RECT_RHS_BUTTON_RESIZE;
827
828         Dimension bounds = Dimension(clientRect.width, clientRect.height);
829
830         __uninstallConfirmPopup = new (std::nothrow) Popup();
831         __uninstallConfirmPopup->Construct(true, bounds);
832         __uninstallConfirmPopup->SetTitleText(applicationName);
833         __uninstallConfirmPopup->SetPropagatedKeyEventListener(this);
834
835         String descriptionText = ResourceManager::GetString(L"IDS_SAPPS_POP_ARE_YOU_SURE_Q");
836
837         pLabel = new (std::nothrow) Label();
838         pLabel->Construct(itemRectLabel, descriptionText);
839         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
840         pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
841         pLabel->SetTextConfig(ALERT_POPUP_LABEL_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
842
843         __uninstallConfirmPopup->AddControl(pLabel);
844
845         buttonText = ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL");
846         pOkButton = new (std::nothrow) Button();
847         pOkButton->Construct(itemRectRhsButton, buttonText);
848         pOkButton->SetActionId(IDA_UNINSTALL_CONFIRM_OK);
849
850         __uninstallConfirmPopup->AddControl(pOkButton);
851
852         buttonText = ResourceManager::GetString(L"IDS_COM_SK_NO");
853
854         pCancelButton = new (std::nothrow) Button();
855         pCancelButton->Construct(itemRectLhsButton, buttonText);
856         pCancelButton->SetActionId(IDA_UNINSTALL_CONFIRM_CANCEL);
857
858         __uninstallConfirmPopup->AddControl(pCancelButton);
859
860         pOkButton->AddActionEventListener(*this);
861         pCancelButton->AddActionEventListener(*this);
862
863         __pProgressPopup = new (std::nothrow) ProgressPopup();
864         __pProgressPopup->Construct(false, false);
865         __pProgressPopup->SetTitleText(applicationName);
866         __pProgressPopup->SetBounds(clientRect);
867
868         descriptionText = ResourceManager::GetString(L"IDS_ST_BUTTON_UNINSTALL");
869         descriptionText.Append(L"....");
870         __pProgressPopup->SetText(descriptionText);
871
872         return E_SUCCESS;
873 }
874
875 void
876 ManageApplicationInfoForm::ShowUninstallPopup(int popupType)
877 {
878         switch (popupType)
879         {
880         case UNINSTALL_POPUP_OKCANCEL:
881                 {
882                         __uninstallConfirmPopup->SetShowState(true);
883                         __uninstallConfirmPopup->Show();
884                 }
885                 break;
886
887         case UNINSTALL_POPUP_PROGRESS:
888                 {
889                         __pProgressPopup->SetShowState(true);
890                         __pProgressPopup->Show();
891                 }
892                 break;
893
894         default:
895                 break;
896         }
897 }
898
899 void
900 ManageApplicationInfoForm::HideUninstallPopup(int popupType)
901 {
902         switch (popupType)
903         {
904         case UNINSTALL_POPUP_OKCANCEL:
905                 {
906                         if (__uninstallConfirmPopup)
907                         {
908                                 __uninstallConfirmPopup->SetShowState(false);
909                                 __uninstallConfirmPopup->Invalidate(true);
910                         }
911                 }
912                 break;
913
914         case UNINSTALL_POPUP_PROGRESS:
915                 {
916                         if (__pProgressPopup)
917                         {
918                                 __pProgressPopup->SetShowState(false);
919                                 __pProgressPopup->Invalidate(true);
920                         }
921                 }
922                 break;
923
924         default:
925                 break;
926         }
927 }
928
929 void
930 ManageApplicationInfoForm::DeleteUninstallPopup(void)
931 {
932         if (__uninstallConfirmPopup)
933         {
934                 delete __uninstallConfirmPopup;
935                 __uninstallConfirmPopup = null;
936         }
937
938         if (__pProgressPopup)
939         {
940                 delete __pProgressPopup;
941                 __pProgressPopup = null;
942         }
943 }
944
945 bool
946 ManageApplicationInfoForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
947 {
948         return false;
949 }
950
951 bool
952 ManageApplicationInfoForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
953 {
954         if (__uninstallConfirmPopup && __uninstallConfirmPopup->GetShowState() == true && (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC))
955         {
956                 HideUninstallPopup(UNINSTALL_POPUP_OKCANCEL);
957                 return true;
958         }
959         return false;
960 }
961
962 bool
963 ManageApplicationInfoForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
964 {
965         return false;
966 }
967
968 bool
969 ManageApplicationInfoForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
970 {
971         return false;
972 }