NABI_SE isues resolved
[apps/osp/MyFiles.git] / src / MfTopLevelFolderFileListForm.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: MfTemp.cpp
19  * @brief:
20  */
21
22 #include <FApp.h>
23 #include "MfFolderNavigationPresentationModel.h"
24 #include "MfTopLevelFolderFileListForm.h"
25 #include "MfTypes.h"
26 #include "MfSceneRegister.h"
27
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37
38 TopLevelFolderFileListForm::TopLevelFolderFileListForm(void)
39 : __pPhone(null)
40 , __pMemoryCard(null)
41 #if 0
42 , __pExternalStorage(null)
43 , __pExternalStoragePress(null)
44 #endif
45 , __pPhonePress(null)
46 , __pMemoryCardPress(null)
47 , __pItemContext(null)
48 , __pFolderList(null)
49 , __pCategoryIconPanel(null)
50 {
51         __appControlRequest = false;
52         __checkMem = false;
53         __listItemCount = 0;
54
55 }
56
57 TopLevelFolderFileListForm::~TopLevelFolderFileListForm(void)
58 {
59         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD,*this);
60         if (__pFolderList != null)
61         {
62                 __pFolderList->RemoveAll(true);
63                 delete __pFolderList;
64         }
65 }
66
67 bool
68 TopLevelFolderFileListForm::Initialize(void)
69 {
70         Form::Construct(L"IDL_MAIN_FORM");
71         return true;
72 }
73
74 result
75 TopLevelFolderFileListForm::OnInitializing(void)
76 {
77         result r = E_SUCCESS;
78         int xPos = 0, yPos = 0;
79         Point bitmapLocation(0, 0);
80
81         String headerDisplayText;
82         String buttonSearch;
83         String contextItemText;
84         String deviceSateSdCard;
85         String mounted = sdCardStatusMounted;
86         String unmounted = sdCardStatusUnmounted;
87         String phoneStorage;
88         String sdCardStorage;
89         String externalStorage;
90
91         AppResource* pAppResource = null;
92
93         Header* pHeader = null;
94         Footer* pFormFooter = null;
95         pAppResource = UiApp::App::GetInstance()->GetAppResource();
96
97         if (pAppResource != null)
98         {
99                 pAppResource->GetString(L"IDS_COM_BODY_MY_FILES", headerDisplayText);
100                 pAppResource->GetString(L"IDS_MF_SK3_SEARCH", buttonSearch);
101                 pAppResource->GetString(L"IDS_MF_SK_DETAILS", contextItemText);
102                 pAppResource->GetString(L"IDS_MF_TAB_PHONE", phoneStorage);
103         pAppResource->GetString(L"IDS_MF_OPT_SHOW_FILE_EXTENSION", _showExtension);
104         pAppResource->GetString(L"IDS_MF_OPT_HIDE_FILE_EXTENSION_ABB", _hideExtension);
105
106                 __pPhone = pAppResource->GetBitmapN(IDB_PHONE_ICON);
107                 __pMemoryCard = pAppResource->GetBitmapN(IDB_SDCARD_ICON_TOP_LEVEL);
108 #if 0
109                 __pExternalStorage = pAppResource->GetBitmapN(IDB_EXTERNAL_ICON);
110                 __pExternalStoragePress = pAppResource->GetBitmapN(IDB_EXTERNAL_ICON_PRESSED);
111 #endif
112                 __pPhonePress = pAppResource->GetBitmapN(IDB_PHONE_ICON_PRESSED);
113                 __pMemoryCardPress = pAppResource->GetBitmapN(IDB_SDCARD_ICON_PRESSED);
114         }
115
116         String* phonetext = new (std::nothrow) String(phoneStorage);
117
118         __pFolderList = new (std::nothrow) ArrayList();
119         //TryCatch(__pFolderList != null, , "MfMyFilesApp::Failed to Allocate memory to pTabList!");
120         __pFolderList->Construct();
121
122         __pFolderList->Add(phonetext);
123
124         pHeader = GetHeader();
125         if (pHeader != null)
126         {
127                 pHeader-> SetTitleText(headerDisplayText);
128         }
129
130         pFormFooter = GetFooter();
131         __pCategoryIconPanel = static_cast< Panel* >(GetControl("IDC_CATEGORY_ICON_PANEL", true));
132         _extensionKeyName.Append(L"ExtensionVisibility");
133
134         //Call the InitializeAppRegistry() method to define the keys used throughout the application.
135         InitializeAppRegistry();
136
137         FooterItem footerItemSearch;
138
139
140         __pItemContext = new (std::nothrow) ListContextItem();
141         __pItemContext->Construct();
142         __pItemContext->AddElement(IDA_CONTEXT_ITEM_DETAIL, contextItemText);
143
144         footerItemSearch.Construct(IDA_CONTEXT_MENU_BTN_SEARCH);
145         footerItemSearch.SetText(buttonSearch);
146
147         if (pFormFooter != null)
148         {
149                 pFormFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
150                 pFormFooter->AddItem(footerItemSearch);
151                 pFormFooter->GetPosition(xPos, yPos);
152         }
153
154         _pLabelDisplayPath = static_cast< Label* >(GetControl("IDC_LABEL_DISPLAY_PATH"));
155         if (_pLabelDisplayPath != null)
156         {
157                 _pLabelDisplayPath->SetShowState(false);
158         }
159         CreateCategoryPanel();
160
161
162         //Initialize the itemprovider class for the listview inside the popup
163         if (_pCustomListViewForPopup == null)
164         {
165                 _pCustomListViewForPopup = new (std::nothrow) CustomListViewForPopup();
166         }
167         //TryCatch(_pCustomListViewForPopup != null, , "MfMyFilesApp::ListView For Popup not created!");
168
169         _pCustomListViewForPopup->SetEventListener(this);
170
171         if (pFormFooter != null)
172         {
173                 pFormFooter->AddActionEventListener(*this);
174                 pFormFooter->Invalidate(true);
175                 pFormFooter->SetBackButton();
176                 SetFormBackEventListener(this);
177         }
178
179         _pLongPressGestureDetector = new (std::nothrow) TouchLongPressGestureDetector();
180         _pLongPressGestureDetector->Construct();
181
182         _pIconListView = static_cast< IconListView* >(GetControl("IDC_ICONLISTVIEW_TOP_MOST_FORM"));
183         if (_pIconListView != null)
184         {
185                 _pIconListView->AddIconListViewItemEventListener(*this);
186                 _pIconListView->SetItemProvider(*this);
187                 _pIconListView->AddTouchEventListener(*this);
188                 _pIconListView->SetShowState(false);
189         }
190
191         _pListView = static_cast< ListView* >(GetControl("IDC_LISTVIEW_TEMP_FORM"));
192         if (_pListView != null)
193         {
194                 _pListView->AddListViewItemEventListener(*this);
195                 _pListView->SetShowState(true);
196                 _pListView->SetItemProvider(*this);
197         }
198
199         return r;
200 }
201
202 result
203 TopLevelFolderFileListForm::OnTerminating(void)
204 {
205         result r = E_SUCCESS;
206         delete __pPhone;
207         delete __pMemoryCard;
208 #if 0
209         delete __pExternalStorage;
210         delete __pExternalStoragePress;
211 #endif
212         delete __pPhonePress;
213         delete __pMemoryCardPress;
214         delete __pItemContext;
215         return r;
216 }
217
218 void
219 TopLevelFolderFileListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
220 {
221         AppRegistry* pAppRegistry = null;
222         String viewStyleKeyName(L"ListDisplayType");
223
224         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
225
226         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
227         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
228
229
230         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
231
232         pAppRegistry->Get(viewStyleKeyName, _flagViewAsStatus);
233         //      TryCatch(r == E_SUCCESS, , "Failed To Get Value From AppRegistry");
234
235         __appControlRequest = ((MyFilesApp*) Application::GetInstance())->IsAppControlMode();
236
237         if (__appControlRequest == true) //if (pArgs != null)
238         {
239                 _flagViewAsStatus = VIEW_TYPE_AS_NORMAL_LIST;
240                 _pFooter = GetFooter();
241
242                 _pListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height));
243                 _pIconListView->SetBounds(Rectangle(X_DEFAULT, Y_DEFAULT, GetClientAreaBounds().width, GetClientAreaBounds().height));
244
245                 if (_pLabelDisplayPath != null)
246                 {
247                         _pLabelDisplayPath->SetShowState(false);
248                 }
249
250                 if (_pFooter != null)
251                 {
252                         _pFooter->RemoveAllItems();
253                         _pFooter->RemoveAllButtons();
254                         _pFooter->SetBackButton();
255
256                         __pCategoryIconPanel->SetShowState(false);
257                 }
258         }
259         else
260         {
261                 SetCurrentDirectoryFlag(true);
262
263                 if (_pLabelDisplayPath != null)
264                 {
265                         _pLabelDisplayPath->SetShowState(true);
266                 }
267                 __appControlRequest = false;
268         }
269 }
270
271 void
272 TopLevelFolderFileListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
273 {
274         __appControlRequest = false;
275         DeviceManager::RemoveAllDeviceEventListeners();
276
277         if (_pIconListView != null)
278         {
279                 _pIconListView->RemoveGestureDetector(*_pLongPressGestureDetector);
280         }
281
282         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(null);
283
284 }
285
286 void
287 TopLevelFolderFileListForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
288 {
289         ComponentType currentDeviceType = COMPONENT_TYPE_NONE;
290
291         String mounted = sdCardStatusMounted;
292         String unmounted = sdCardStatusUnmounted;
293         String inserted = usbDeviceStatusInserted;
294         String removed = usbDeviceStatusRemoved;
295
296         String sdCardStorage;
297         String externalStorage;
298
299         String* pSdCard = null;
300         String* pExternalStorage = null;
301
302         AppResource* pAppResource = null;
303
304         pAppResource = UiApp::App::GetInstance()->GetAppResource();
305
306         if (pAppResource != null)
307         {
308                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCardStorage);
309                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
310
311         }
312
313         if (_pIconListViewContextMenu != null)
314         {
315                 _pIconListViewContextMenu->SetShowState(false);
316         }
317
318         switch (deviceType)
319         {
320         case StorageCard:
321         {
322                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
323
324                 if (state == mounted)
325                 {
326                         pSdCard = new (std::nothrow) String(sdCardStorage);
327                         __pFolderList->Add(pSdCard);
328
329                 }
330                 else if (state == unmounted)
331                 {
332                         __pFolderList->RemoveAt(__listItemCount - 1);
333                 }
334
335                 __listItemCount = __pFolderList->GetCount();
336         }
337         break;
338
339         case UsbClient:
340         {
341                 currentDeviceType = COMPONENT_TYPE_USB;
342
343                 if (state == inserted)
344                 {
345                         pExternalStorage = new (std::nothrow) String(externalStorage);
346                         __pFolderList->Add(pExternalStorage);
347                 }
348                 else if (state == removed)
349                 {
350                         __pFolderList->RemoveAt(__listItemCount - 1);
351                 }
352                 __listItemCount = __pFolderList->GetCount();
353
354         }
355         break;
356
357         default:
358         {
359                 //Do Nothing.
360         }
361         break;
362         }
363
364         _pListView->UpdateList();
365         _pIconListView->UpdateList();
366
367         //OnDeviceChange(currentDeviceType, state);
368 }
369
370 void
371 TopLevelFolderFileListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
372 {
373         String viewAs;
374         String sortBy;
375         result r = E_SUCCESS;
376         Integer currentFileType;
377         AppResource* pAppResource = null;
378         ArrayList *pArgs = null;
379         String sounds;
380         String videos;
381         String images;
382         String document;
383         String others;
384         SceneManager* pSceneManager = SceneManager::GetInstance();
385         pAppResource = UiApp::GetInstance()->GetAppResource();
386         if (pAppResource != null)
387         {
388                 pAppResource->GetString(L"IDS_MF_OPT_VIEW_AS", viewAs);
389                 pAppResource->GetString(L"IDS_MF_SK3_SORT_BY", sortBy);
390                 pAppResource->GetString(L"IDS_MF_BODY_SOUNDS", sounds);
391                 pAppResource->GetString(L"IDS_MF_BODY_VIDEOS", videos);
392                 pAppResource->GetString(L"IDS_MF_BODY_IMAGES", images);
393                 pAppResource->GetString(L"IDS_MF_BODY_DOCUMENT", document);
394                 pAppResource->GetString(L"IDS_MF_BODY_OTHERS", others);
395         }
396
397         switch (actionId)
398         {
399
400         case IDA_BUTTON_IMAGE:
401         {
402                 currentFileType = FILE_TYPE_IMAGE_TYPE;
403                 if (pArgs == null)
404                 {
405                         pArgs = new (std::nothrow) ArrayList();
406                         pArgs->Construct();
407                 }
408                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
409                 pArgs->Add(new (std::nothrow) String(images));
410
411                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
412
413         }
414         break;
415
416         case IDA_BUTTON_VIDEO:
417         {
418                 currentFileType = FILE_TYPE_VIDEO_TYPE;
419                 if (pArgs == null)
420                 {
421                         pArgs = new (std::nothrow) ArrayList();
422                         pArgs->Construct();
423                 }
424                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
425                 pArgs->Add(new (std::nothrow) String(videos));
426                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
427         }
428         break;
429
430         case IDA_BUTTON_SOUND:
431         {
432                 currentFileType = FILE_TYPE_AUDIO_TYPE;
433                 if (pArgs == null)
434                 {
435                         pArgs = new (std::nothrow) ArrayList();
436                         pArgs->Construct();
437                 }
438                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
439                 pArgs->Add(new (std::nothrow) String(sounds));
440                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
441         }
442         break;
443
444         case IDA_BUTTON_DOCUMENT:
445         {
446                 currentFileType = FILE_TYPE_DOCUMENT_TYPE;
447                 if (pArgs == null)
448                 {
449                         pArgs = new (std::nothrow) ArrayList();
450                         pArgs->Construct();
451                 }
452                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
453                 pArgs->Add(new (std::nothrow) String(document));
454                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
455         }
456         break;
457
458         case IDA_BUTTON_OTHERS:
459         {
460                 currentFileType = FILE_TYPE_OTHER_TYPE;
461
462                 if (pArgs == null)
463                 {
464                         pArgs = new (std::nothrow) ArrayList();
465                         pArgs->Construct();
466                 }
467
468                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
469                 pArgs->Add(new (std::nothrow) String(others));
470                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
471         }
472         break;
473
474         case IDA_CONTEXT_MENU_BTN_SEARCH:
475         {
476                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_NONE);
477                 LoadSearchForm();
478         }
479         break;
480
481         default:
482                 SubBaseOnActionPerformed(source, actionId);
483                 break;
484         }
485         return;
486 }
487
488 void
489 TopLevelFolderFileListForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
490 {
491         switch (orientationStatus)
492         {
493         case ORIENTATION_STATUS_PORTRAIT:
494         {
495                 if (_pLabelDisplayPath != null)
496                 {
497                         _pLabelDisplayPath->SetShowState(true);
498                 }
499         }
500         break;
501
502         case ORIENTATION_STATUS_LANDSCAPE:
503         {
504                 if (_pLabelDisplayPath != null)
505                 {
506                         _pLabelDisplayPath->SetShowState(false);
507                 }
508         }
509         break;
510
511         default:
512         {
513                 //Do Nothing
514         }
515         break;
516         }
517 }
518
519 void
520 TopLevelFolderFileListForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
521 {
522         String filePath;
523
524         switch (index)
525         {
526         case 0:
527                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
528                 filePath = FolderNavigationPresentationModel::GetMediaPath();
529                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
530                 break;
531         case 1:
532                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
533                 filePath = FolderNavigationPresentationModel::GetSdCardPath();
534                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
535
536                 break;
537         case 2:
538                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
539                 filePath = FolderNavigationPresentationModel::GetUsbPath();
540                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
541                 break;
542         }
543
544         LoadDetailForm(filePath);
545
546 }
547
548 void
549 TopLevelFolderFileListForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
550 {
551         ArrayList* pArgs = null;
552         pArgs = new (std::nothrow) ArrayList();
553         pArgs->Construct();
554
555         String fileName;
556
557         switch (index)
558         {
559         case 0:
560                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
561                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
562                 fileName.Clear();
563                 fileName.Append(defaultPhoneBody);
564                 break;
565         case 1:
566                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
567                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
568                 fileName.Clear();
569                 fileName.Append(defaultSdCardBody);
570                 break;
571         case 2:
572                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
573                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
574                 fileName.Clear();
575                 fileName.Append(defaultExternalStorageBody);
576                 break;
577         default:
578                 break;
579         }
580
581         if (__appControlRequest == false)
582         {
583                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
584         }
585         else
586         {
587                 pArgs->Add(&fileName);
588                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_FOLDER_SELECTION_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
589         }
590 }
591
592 ListItemBase*
593 TopLevelFolderFileListForm::CreateItem(int index, int itemWidth)
594 {
595         String titleText;
596         String memoryCard;
597 #if 0
598         String externalStorage;
599 #endif
600         String* tempStr;
601
602         CustomItem* pItem = new CustomItem();
603         AppResource* pAppResource = null;
604         pAppResource = UiApp::GetInstance()->GetAppResource();
605         if (pAppResource != null)
606         {
607                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", memoryCard);
608 #if 0
609                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
610 #endif
611         }
612
613         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
614
615         pItem->Construct(Dimension(itemWidth, H_ITEM_LISTVIEW), style);
616
617         switch (index)
618         {
619         case 0:
620         {
621                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pPhone, __pPhonePress, null);
622
623         }
624         break;
625         case 1:
626         {
627                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pMemoryCard, __pMemoryCardPress, null);
628
629         }
630         break;
631 #if 0
632         case 2:
633         {
634                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pExternalStorage, __pExternalStoragePress, null);
635         }
636         break;
637 #endif
638         default:
639                 break;
640         }
641
642         tempStr = static_cast<String*>(__pFolderList->GetAt(index));
643
644         titleText.Clear();
645         titleText.Append(*tempStr);
646
647         pItem->AddElement(Rectangle(W_LISTVIEW_ITEM_BITMAP + 2 * X_LISTVIEW, (H_ITEM_LISTVIEW - H_LISTVIEW_ITEM_TITLE) /2, itemWidth - (W_LISTVIEW_ITEM_BITMAP + 3 * X_LISTVIEW), H_LISTVIEW_ITEM_TITLE), IDA_FORMAT_STRING, titleText, true);
648         pItem->SetContextItem(__pItemContext);
649         return pItem;
650 }
651
652 bool
653 TopLevelFolderFileListForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
654 {
655         if (pItem != null)
656         {
657                 delete pItem;
658                 pItem = null;
659         }
660         return true;
661 }
662
663 int
664 TopLevelFolderFileListForm::GetItemCount(void)
665 {
666         return __listItemCount;
667         //return 1;
668 }
669
670 void
671 TopLevelFolderFileListForm::OnFormBackRequested(Form& source)
672 {
673         SceneManager* pSceneManager = SceneManager::GetInstance();
674         if (CheckSearchHistory() == true)
675         {
676                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
677         }
678         else
679         {
680                 MyFilesApp* pApp = (MyFilesApp*) Application::GetInstance();
681
682                 if (__appControlRequest)
683                 {
684                         ((MyFilesApp*) Application::GetInstance())->SetAppControlSelected();
685                         ((MyFilesApp*) Application::GetInstance())->AddAppControlResult(APP_CTRL_RESULT_CANCELED);
686                 }
687
688                 if (pApp != null)
689                 {
690                         pApp->Terminate();
691                 }
692                 return;
693         }
694 }
695
696 void
697 TopLevelFolderFileListForm::InitializeAppRegistry(void)
698 {
699         AppLogDebug("ENTER");
700         // 3 keys: ViewStyle, SortBy, Show/Hide File Extension
701         result r = E_SUCCESS;
702
703         AppRegistry* pAppRegistry = null;
704         String viewStyleKeyName(L"ListDisplayType");
705         ViewType viewStyle = VIEW_TYPE_AS_NORMAL_LIST;
706
707         String sortbyKeyName(L"SortBy");
708         SortByType sortStyle = SORT_BY_TYPE_DATE_RECENT;
709
710         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
711
712         r = pAppRegistry->Add(viewStyleKeyName, viewStyle);
713         if (r == E_SUCCESS)
714         {
715                 r = pAppRegistry->Save();
716         }
717
718         r = pAppRegistry->Add(_extensionKeyName, _showExtension);
719         if (r == E_SUCCESS)
720         {
721                 r = pAppRegistry->Save();
722         }
723
724         r = pAppRegistry->Add(sortbyKeyName, sortStyle);
725         if (r == E_SUCCESS)
726         {
727                 r = pAppRegistry->Save();
728         }
729
730         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
731 }
732
733 void
734 TopLevelFolderFileListForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
735                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
736 {
737         //Empty Implementation.
738 }
739
740 void
741 TopLevelFolderFileListForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
742                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
743 {
744         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
745
746         String deviceSateSdCard;
747         String mounted = sdCardStatusMounted;
748         String unmounted = sdCardStatusUnmounted;
749         AppControlState currentState;
750
751 #if 0
752         String deviceSateUSBStorage;
753         String inserted = usbDeviceStatusInserted;
754         String removed = usbDeviceStatusRemoved;
755         String externalStorage;
756         String* pExternalStorage = null;
757 #endif
758
759         String sdCardStorage;
760
761         String buttonSearch;
762         String* pSDCard = null;
763
764         FooterItem footerItemSearch;
765
766         int footerItemCount = 0;
767         DeviceManager::GetState(StorageCard, deviceSateSdCard);
768 #if 0
769         DeviceManager::GetState(UsbClient, deviceSateUSBStorage);
770 #endif
771
772         AppResource* pAppResource = null;
773
774         pAppResource = UiApp::App::GetInstance()->GetAppResource();
775
776         if (pAppResource != null)
777         {
778                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCardStorage);
779 #if 0
780                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
781 #endif
782                 pAppResource->GetString(L"IDS_MF_SK3_SEARCH", buttonSearch);
783         }
784         FolderNavigationPresentationModel::SetCurrentFilePath(L"");
785         __listItemCount = __pFolderList->GetCount();
786
787         if (deviceSateSdCard == mounted && __listItemCount < 2)
788         {
789                 pSDCard = new (std::nothrow) String(sdCardStorage);
790
791                 __pFolderList->Add(pSDCard);
792         }
793         else if (deviceSateSdCard == unmounted && __listItemCount > 1)
794         {
795                 __pFolderList->RemoveAt(__listItemCount - 1, true);
796         }
797
798 #if 0
799         if (deviceSateUSBStorage == inserted)
800         {
801                 pExternalStorage = new (std::nothrow) String(externalStorage);
802                 __pFolderList->Add(pExternalStorage);
803         }
804         else if (deviceSateUSBStorage == removed && __listItemCount > 1)
805         {
806                 __pFolderList->RemoveAt(__listItemCount - 1);
807         }
808 #endif
809
810         __listItemCount = __pFolderList->GetCount();
811
812
813         _pFooter = GetFooter();
814         currentState = ((MyFilesApp*) Application::GetInstance())->GetCurrentState();
815
816         if (currentState != APPCONTROL_STATE_SELECTED)
817         {
818                 if (CheckSearchHistory())
819                 {
820                         if (_pFooter != null)
821                         {
822                                 _pFooter->RemoveItemAt(0);
823                                 _pFooter->Invalidate(true);
824                         }
825                 }
826                 else
827                 {
828                         if (_pFooter != null)
829                         {
830                                 footerItemCount = _pFooter->GetItemCount();
831
832                                 if (footerItemCount != 1)
833                                 {
834                                         footerItemSearch.Construct(IDA_CONTEXT_MENU_BTN_SEARCH);
835                                         footerItemSearch.SetText(buttonSearch);
836                                         _pFooter->AddItem(footerItemSearch);
837                                         _pFooter->Invalidate(true);
838                                 }
839                         }
840                 }
841         }
842         SwitchViewType();
843
844         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
845         if (_pIconListView != null)
846         {
847                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
848         }
849
850 }
851
852 void
853 TopLevelFolderFileListForm::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& listView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
854 {
855
856         if (__appControlRequest == false)
857         {
858                 switch (index)
859                 {
860                 case 0:
861                         FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
862                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
863                         break;
864                 case 1:
865                         FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
866                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
867
868                         break;
869                 case 2:
870                         FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
871                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
872                         break;
873                 }
874
875                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
876
877         }
878         else
879         {
880                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_TOP_MOST_SELECTION_FORM));
881         }
882 }
883
884 Tizen::Ui::Controls::IconListViewItem*
885 TopLevelFolderFileListForm::CreateItem(int index)
886 {
887         String titleText;
888         String* tempStr;
889
890         IconListViewItem* pItem = null;
891         pItem = new (std::nothrow) IconListViewItem();
892
893         tempStr = static_cast<String*>(__pFolderList->GetAt(index));
894
895         titleText.Clear();
896         titleText.Append(*tempStr);
897
898         switch (index)
899         {
900         case 0:
901         {
902                 pItem->Construct(*__pPhone, &titleText,__pPhonePress, null);
903         }
904         break;
905         case 1:
906         {
907                 pItem->Construct(*__pMemoryCard, &titleText,__pMemoryCardPress, null);
908
909         }
910         break;
911 #if 0
912         case 2:
913         {
914                 pItem->Construct(*__pExternalStorage, &titleText,__pExternalStoragePress, null);
915         }
916         break;
917 #endif
918         default:
919                 break;
920         }
921
922         return pItem;
923 }
924
925 bool
926 TopLevelFolderFileListForm::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem* pItem)
927 {
928         if (pItem != null)
929         {
930                 delete pItem;
931                 pItem = null;
932         }
933         return true;
934 }
935
936 void
937 TopLevelFolderFileListForm::CreateCategoryPanel(void)
938 {
939         Button* pImageButton = null;
940         Button* pVideoButton = null;
941         Button* pSoundButton = null;
942         Button* pDocumentButton = null;
943         Button* pOthersButton = null;
944         Label* pBackgroundLabel = null;
945         Panel* pCategoryPanel = null;
946
947 //      Bitmap* pCategoryImagesBitmap = null;
948 //      Bitmap* pCategorySoundsBitmap = null;
949 //      Bitmap* pCategoryVideosBitmap = null;
950 //      Bitmap* pCategoryDocsBitmap = null;
951 //      Bitmap* pCategoryOthersBitmap = null;
952 //
953 //      Bitmap* pCategoryPressImagesBitmap = null;
954 //      Bitmap* pCategoryPressSoundsBitmap = null;
955 //      Bitmap* pCategoryPressVideosBitmap = null;
956 //      Bitmap* pCategoryPressDocsBitmap = null;
957 //      Bitmap* pCategoryPressOthersBitmap = null;
958
959         Bitmap* pImages = null;
960         Bitmap* pVideos = null;
961         Bitmap* pSounds = null;
962         Bitmap* pDocs = null;
963         Bitmap* pOthers = null;
964         Bitmap* pImagesPressed = null;
965         Bitmap* pVideosPressed = null;
966         Bitmap* pSoundsPressed = null;
967         Bitmap* pDocsPressed = null;
968         Bitmap* pOthersPressed = null;
969
970         Point* startPoint = null;
971
972         startPoint = new (std::nothrow) Point(28, 10);
973
974
975         pImages = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_IMAGE_ICON, 128, 92, startPoint);
976         pVideos = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_VIDEO_ICON, 128, 92, startPoint);
977         pSounds = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_SOUND_ICON, 128, 92, startPoint);
978         pDocs = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_DOCUMENT_ICON, 128, 92, startPoint);
979         pOthers = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_OTHERS_ICON, 128, 92, startPoint);
980
981         pImagesPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_IMAGE_ICON_PRESS, 128, 92, startPoint);
982         pVideosPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_VIDEO_ICON_PRESS, 128, 92, startPoint);
983         pSoundsPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_SOUND_ICON_PRESS, 128, 92, startPoint);
984         pDocsPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_DOCUMENT_ICON_PRESS, 128, 92, startPoint);
985         pOthersPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_OTHERS_ICON_PRESS, 128, 92, startPoint);
986
987         pImageButton = static_cast<Button*>(GetControl("IDC_BUTTON_IMAGES", true));
988         pImageButton->SetActionId(IDA_BUTTON_IMAGE);
989         pImageButton->SetNormalBackgroundBitmap(*pImages);
990         pImageButton->SetPressedBackgroundBitmap(*pImagesPressed);
991         pImageButton->AddActionEventListener(*this);
992
993         pVideoButton = static_cast<Button*>(GetControl("IDC_BUTTON_VIDEOS", true));
994         pVideoButton->SetActionId(IDA_BUTTON_VIDEO);
995         pVideoButton->SetNormalBackgroundBitmap(*pVideos);
996         pVideoButton->SetPressedBackgroundBitmap(*pVideosPressed);
997         pVideoButton->AddActionEventListener(*this);
998
999         pSoundButton = static_cast<Button*>(GetControl("IDC_BUTTON_SOUNDS", true));
1000         pSoundButton->SetNormalBackgroundBitmap(*pSounds);
1001         pSoundButton->SetPressedBackgroundBitmap(*pSoundsPressed);
1002         pSoundButton->SetActionId(IDA_BUTTON_SOUND);
1003         pSoundButton->AddActionEventListener(*this);
1004
1005         pDocumentButton = static_cast<Button*>(GetControl("IDC_BUTTON_DOCUMENTS", true));
1006         pDocumentButton->SetNormalBackgroundBitmap(*pDocs);
1007         pDocumentButton->SetPressedBackgroundBitmap(*pDocsPressed);
1008         pDocumentButton->SetActionId(IDA_BUTTON_DOCUMENT);
1009         pDocumentButton->AddActionEventListener(*this);
1010
1011         pOthersButton = static_cast<Button*>(GetControl("IDC_BUTTON_OTHERS", true));
1012         pOthersButton->SetNormalBackgroundBitmap(*pOthers);
1013         pOthersButton->SetPressedBackgroundBitmap(*pOthersPressed);
1014         pOthersButton->SetActionId(IDA_BUTTON_OTHERS);
1015         pOthersButton->AddActionEventListener(*this);
1016
1017         pCategoryPanel = static_cast<Panel*>(GetControl("IDC_CATEGORY_ICON_PANEL", true));
1018
1019         pBackgroundLabel = static_cast<Label*>(GetControl("IDC_LABEL_BACKGROUND", true));
1020
1021         pCategoryPanel->SetControlAlwaysAtBottom(*pBackgroundLabel, true);
1022
1023         delete startPoint;
1024         delete pImages;
1025         delete pVideos;
1026         delete pSounds;
1027         delete pDocs;
1028         delete pOthers;
1029
1030         delete pImagesPressed;
1031         delete pVideosPressed;
1032         delete pSoundsPressed;
1033         delete pDocsPressed;
1034         delete pOthersPressed;
1035 }