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