NABI_SE issues 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                 __listItemCount = __pFolderList->GetCount();
324                 if (state == mounted)
325                 {
326                         pSdCard = new (std::nothrow) String(sdCardStorage);
327                         __pFolderList->Add(pSdCard);
328
329                 }
330                 else if (state == unmounted && __listItemCount > 1)
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 }
368
369 void
370 TopLevelFolderFileListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
371 {
372         String viewAs;
373         String sortBy;
374         result r = E_SUCCESS;
375         Integer currentFileType;
376         AppResource* pAppResource = null;
377         ArrayList *pArgs = null;
378         String sounds;
379         String videos;
380         String images;
381         String document;
382         String others;
383         SceneManager* pSceneManager = SceneManager::GetInstance();
384         pAppResource = UiApp::GetInstance()->GetAppResource();
385         if (pAppResource != null)
386         {
387                 pAppResource->GetString(L"IDS_MF_OPT_VIEW_AS", viewAs);
388                 pAppResource->GetString(L"IDS_MF_SK3_SORT_BY", sortBy);
389                 pAppResource->GetString(L"IDS_MF_BODY_SOUNDS", sounds);
390                 pAppResource->GetString(L"IDS_MF_BODY_VIDEOS", videos);
391                 pAppResource->GetString(L"IDS_MF_BODY_IMAGES", images);
392                 pAppResource->GetString(L"IDS_MF_BODY_DOCUMENT", document);
393                 pAppResource->GetString(L"IDS_MF_BODY_OTHERS", others);
394         }
395
396         switch (actionId)
397         {
398
399         case IDA_BUTTON_IMAGE:
400         {
401                 currentFileType = FILE_TYPE_IMAGE_TYPE;
402                 if (pArgs == null)
403                 {
404                         pArgs = new (std::nothrow) ArrayList();
405                         pArgs->Construct();
406                 }
407                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
408                 pArgs->Add(new (std::nothrow) String(images));
409
410                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
411
412         }
413         break;
414
415         case IDA_BUTTON_VIDEO:
416         {
417                 currentFileType = FILE_TYPE_VIDEO_TYPE;
418                 if (pArgs == null)
419                 {
420                         pArgs = new (std::nothrow) ArrayList();
421                         pArgs->Construct();
422                 }
423                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
424                 pArgs->Add(new (std::nothrow) String(videos));
425                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
426         }
427         break;
428
429         case IDA_BUTTON_SOUND:
430         {
431                 currentFileType = FILE_TYPE_AUDIO_TYPE;
432                 if (pArgs == null)
433                 {
434                         pArgs = new (std::nothrow) ArrayList();
435                         pArgs->Construct();
436                 }
437                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
438                 pArgs->Add(new (std::nothrow) String(sounds));
439                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
440         }
441         break;
442
443         case IDA_BUTTON_DOCUMENT:
444         {
445                 currentFileType = FILE_TYPE_DOCUMENT_TYPE;
446                 if (pArgs == null)
447                 {
448                         pArgs = new (std::nothrow) ArrayList();
449                         pArgs->Construct();
450                 }
451                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
452                 pArgs->Add(new (std::nothrow) String(document));
453                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
454         }
455         break;
456
457         case IDA_BUTTON_OTHERS:
458         {
459                 currentFileType = FILE_TYPE_OTHER_TYPE;
460
461                 if (pArgs == null)
462                 {
463                         pArgs = new (std::nothrow) ArrayList();
464                         pArgs->Construct();
465                 }
466
467                 pArgs->Add(new (std::nothrow) Integer(currentFileType));
468                 pArgs->Add(new (std::nothrow) String(others));
469                 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CATEGORY_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
470         }
471         break;
472
473         case IDA_CONTEXT_MENU_BTN_SEARCH:
474         {
475                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_NONE);
476                 LoadSearchForm();
477         }
478         break;
479
480         default:
481                 SubBaseOnActionPerformed(source, actionId);
482                 break;
483         }
484         return;
485 }
486
487 void
488 TopLevelFolderFileListForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
489 {
490         switch (orientationStatus)
491         {
492         case ORIENTATION_STATUS_PORTRAIT:
493         {
494                 if (_pLabelDisplayPath != null)
495                 {
496                         _pLabelDisplayPath->SetShowState(true);
497                 }
498         }
499         break;
500
501         case ORIENTATION_STATUS_LANDSCAPE:
502         {
503                 if (_pLabelDisplayPath != null)
504                 {
505                         _pLabelDisplayPath->SetShowState(false);
506                 }
507         }
508         break;
509
510         default:
511         {
512                 //Do Nothing
513         }
514         break;
515         }
516 }
517
518 void
519 TopLevelFolderFileListForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
520 {
521         String filePath;
522
523         switch (index)
524         {
525         case 0:
526                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
527                 filePath = FolderNavigationPresentationModel::GetMediaPath();
528                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
529                 break;
530         case 1:
531                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
532                 filePath = FolderNavigationPresentationModel::GetSdCardPath();
533                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
534
535                 break;
536         case 2:
537                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
538                 filePath = FolderNavigationPresentationModel::GetUsbPath();
539                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
540                 break;
541         }
542
543         LoadDetailForm(filePath);
544
545 }
546
547 void
548 TopLevelFolderFileListForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
549 {
550         ArrayList* pArgs = null;
551         pArgs = new (std::nothrow) ArrayList();
552         pArgs->Construct();
553
554         String fileName;
555
556         switch (index)
557         {
558         case 0:
559                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
560                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
561                 fileName.Clear();
562                 fileName.Append(defaultPhoneBody);
563                 break;
564         case 1:
565                 FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
566                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
567                 fileName.Clear();
568                 fileName.Append(defaultSdCardBody);
569                 break;
570         case 2:
571                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
572                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
573                 fileName.Clear();
574                 fileName.Append(defaultExternalStorageBody);
575                 break;
576         default:
577                 break;
578         }
579
580         if (__appControlRequest == false)
581         {
582                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
583         }
584         else
585         {
586                 pArgs->Add(&fileName);
587                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_FOLDER_SELECTION_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
588         }
589 }
590
591 ListItemBase*
592 TopLevelFolderFileListForm::CreateItem(int index, int itemWidth)
593 {
594         String titleText;
595         String memoryCard;
596 #if 0
597         String externalStorage;
598 #endif
599         String* tempStr;
600
601         CustomItem* pItem = new CustomItem();
602         AppResource* pAppResource = null;
603         pAppResource = UiApp::GetInstance()->GetAppResource();
604         if (pAppResource != null)
605         {
606                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", memoryCard);
607 #if 0
608                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
609 #endif
610         }
611
612         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
613
614         pItem->Construct(Dimension(itemWidth, H_ITEM_LISTVIEW), style);
615
616         switch (index)
617         {
618         case 0:
619         {
620                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pPhone, __pPhonePress, null);
621
622         }
623         break;
624         case 1:
625         {
626                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pMemoryCard, __pMemoryCardPress, null);
627
628         }
629         break;
630 #if 0
631         case 2:
632         {
633                 pItem->AddElement(Rectangle(X_LISTVIEW, Y_LISTVIEW, W_LISTVIEW_ITEM_BITMAP, H_LISTVIEW_ITEM_BITMAP), IDA_FORMAT_BITMAP, *__pExternalStorage, __pExternalStoragePress, null);
634         }
635         break;
636 #endif
637         default:
638                 break;
639         }
640
641         tempStr = static_cast<String*>(__pFolderList->GetAt(index));
642
643         titleText.Clear();
644         titleText.Append(*tempStr);
645
646         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);
647         pItem->SetContextItem(__pItemContext);
648         return pItem;
649 }
650
651 bool
652 TopLevelFolderFileListForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
653 {
654         if (pItem != null)
655         {
656                 delete pItem;
657                 pItem = null;
658         }
659         return true;
660 }
661
662 int
663 TopLevelFolderFileListForm::GetItemCount(void)
664 {
665         return __listItemCount;
666         //return 1;
667 }
668
669 void
670 TopLevelFolderFileListForm::OnFormBackRequested(Form& source)
671 {
672         SceneManager* pSceneManager = SceneManager::GetInstance();
673         if (CheckSearchHistory() == true)
674         {
675                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_SEARCH_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
676         }
677         else
678         {
679                 MyFilesApp* pApp = (MyFilesApp*) Application::GetInstance();
680
681                 if (__appControlRequest)
682                 {
683                         ((MyFilesApp*) Application::GetInstance())->SetAppControlSelected();
684                         ((MyFilesApp*) Application::GetInstance())->AddAppControlResult(APP_CTRL_RESULT_CANCELED);
685                 }
686
687                 if (pApp != null)
688                 {
689                         pApp->Terminate();
690                 }
691                 return;
692         }
693 }
694
695 void
696 TopLevelFolderFileListForm::InitializeAppRegistry(void)
697 {
698         AppLogDebug("ENTER");
699         // 3 keys: ViewStyle, SortBy, Show/Hide File Extension
700         result r = E_SUCCESS;
701
702         AppRegistry* pAppRegistry = null;
703         String viewStyleKeyName(L"ListDisplayType");
704         ViewType viewStyle = VIEW_TYPE_AS_NORMAL_LIST;
705
706         String sortbyKeyName(L"SortBy");
707         SortByType sortStyle = SORT_BY_TYPE_DATE_RECENT;
708
709         String timeFormatKeyName(L"TimeFormat");
710         String timeFormatSettingSelected;
711
712         String timeFormatSettingKey = L"http://tizen.org/setting/locale.date_time.format";
713         TimeFormat timeFormatSelected = TIME_FORMAT_NONE;
714
715         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
716
717         SettingInfo::GetValue(timeFormatSettingKey, timeFormatSettingSelected);
718
719         r = pAppRegistry->Add(viewStyleKeyName, viewStyle);
720         if (r == E_SUCCESS)
721         {
722                 r = pAppRegistry->Save();
723         }
724
725         r = pAppRegistry->Add(_extensionKeyName, _showExtension);
726         if (r == E_SUCCESS)
727         {
728                 r = pAppRegistry->Save();
729         }
730
731         r = pAppRegistry->Add(sortbyKeyName, sortStyle);
732         if (r == E_SUCCESS)
733         {
734                 r = pAppRegistry->Save();
735         }
736
737         if (timeFormatSettingSelected.CompareTo(IDB_DATETIME_24HR) == 0)
738         {
739                 timeFormatSelected = TIME_FORMAT_24_HOUR;
740         }
741         else if (timeFormatSettingSelected.CompareTo(IDB_DATETIME_12HR) == 0)
742         {
743                 timeFormatSelected = TIME_FORMAT_12_HOUR;
744         }
745         r = pAppRegistry->Add(timeFormatKeyName, timeFormatSelected);
746
747         if (r == E_SUCCESS)
748         {
749                 r = pAppRegistry->Save();
750         }
751         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
752 }
753
754 void
755 TopLevelFolderFileListForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
756                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
757 {
758         //Empty Implementation.
759 }
760
761 void
762 TopLevelFolderFileListForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
763                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
764 {
765         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
766
767         String deviceSateSdCard;
768         String mounted = sdCardStatusMounted;
769         String unmounted = sdCardStatusUnmounted;
770         AppControlState currentState;
771
772 #if 0
773         String deviceSateUSBStorage;
774         String inserted = usbDeviceStatusInserted;
775         String removed = usbDeviceStatusRemoved;
776         String externalStorage;
777         String* pExternalStorage = null;
778 #endif
779
780         String sdCardStorage;
781
782         String buttonSearch;
783         String* pSDCard = null;
784
785         FooterItem footerItemSearch;
786
787         int footerItemCount = 0;
788         DeviceManager::GetState(StorageCard, deviceSateSdCard);
789 #if 0
790         DeviceManager::GetState(UsbClient, deviceSateUSBStorage);
791 #endif
792
793         AppResource* pAppResource = null;
794
795         pAppResource = UiApp::App::GetInstance()->GetAppResource();
796
797         if (pAppResource != null)
798         {
799                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCardStorage);
800 #if 0
801                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
802 #endif
803                 pAppResource->GetString(L"IDS_MF_SK3_SEARCH", buttonSearch);
804         }
805         FolderNavigationPresentationModel::SetCurrentFilePath(L"");
806         __listItemCount = __pFolderList->GetCount();
807
808         if (deviceSateSdCard == mounted && __listItemCount < 2)
809         {
810                 pSDCard = new (std::nothrow) String(sdCardStorage);
811
812                 __pFolderList->Add(pSDCard);
813         }
814         else if (deviceSateSdCard == unmounted && __listItemCount > 1)
815         {
816                 __pFolderList->RemoveAt(__listItemCount - 1, true);
817         }
818
819 #if 0
820         if (deviceSateUSBStorage == inserted)
821         {
822                 pExternalStorage = new (std::nothrow) String(externalStorage);
823                 __pFolderList->Add(pExternalStorage);
824         }
825         else if (deviceSateUSBStorage == removed && __listItemCount > 1)
826         {
827                 __pFolderList->RemoveAt(__listItemCount - 1);
828         }
829 #endif
830
831         __listItemCount = __pFolderList->GetCount();
832
833
834         _pFooter = GetFooter();
835         currentState = ((MyFilesApp*) Application::GetInstance())->GetCurrentState();
836
837         if (currentState != APPCONTROL_STATE_SELECTED)
838         {
839                 if (CheckSearchHistory())
840                 {
841                         if (_pFooter != null)
842                         {
843                                 _pFooter->RemoveItemAt(0);
844                                 _pFooter->Invalidate(true);
845                         }
846                 }
847                 else
848                 {
849                         if (_pFooter != null)
850                         {
851                                 footerItemCount = _pFooter->GetItemCount();
852
853                                 if (footerItemCount != 1)
854                                 {
855                                         footerItemSearch.Construct(IDA_CONTEXT_MENU_BTN_SEARCH);
856                                         footerItemSearch.SetText(buttonSearch);
857                                         _pFooter->AddItem(footerItemSearch);
858                                         _pFooter->Invalidate(true);
859                                 }
860                         }
861                 }
862         }
863         SwitchViewType();
864
865         _pLongPressGestureDetector->AddLongPressGestureEventListener(*this);
866         if (_pIconListView != null)
867         {
868                 _pIconListView->AddGestureDetector(*_pLongPressGestureDetector);
869         }
870
871 }
872
873 void
874 TopLevelFolderFileListForm::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView& listView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
875 {
876
877         if (__appControlRequest == false)
878         {
879                 switch (index)
880                 {
881                 case 0:
882                         FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetMediaPath());
883                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
884                         break;
885                 case 1:
886                         FolderNavigationPresentationModel::SetCurrentFilePath(FolderNavigationPresentationModel::GetSdCardPath());
887                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
888
889                         break;
890                 case 2:
891                         FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetUsbPath());
892                         FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_EXTERNAL);
893                         break;
894                 }
895
896                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
897
898         }
899         else
900         {
901                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_TOP_MOST_SELECTION_FORM));
902         }
903 }
904
905 Tizen::Ui::Controls::IconListViewItem*
906 TopLevelFolderFileListForm::CreateItem(int index)
907 {
908         String titleText;
909         String* tempStr;
910
911         IconListViewItem* pItem = null;
912         pItem = new (std::nothrow) IconListViewItem();
913
914         tempStr = static_cast<String*>(__pFolderList->GetAt(index));
915
916         titleText.Clear();
917         titleText.Append(*tempStr);
918
919         switch (index)
920         {
921         case 0:
922         {
923                 pItem->Construct(*__pPhone, &titleText,__pPhonePress, null);
924         }
925         break;
926         case 1:
927         {
928                 pItem->Construct(*__pMemoryCard, &titleText,__pMemoryCardPress, null);
929
930         }
931         break;
932 #if 0
933         case 2:
934         {
935                 pItem->Construct(*__pExternalStorage, &titleText,__pExternalStoragePress, null);
936         }
937         break;
938 #endif
939         default:
940                 break;
941         }
942
943         return pItem;
944 }
945
946 bool
947 TopLevelFolderFileListForm::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem* pItem)
948 {
949         if (pItem != null)
950         {
951                 delete pItem;
952                 pItem = null;
953         }
954         return true;
955 }
956
957 void
958 TopLevelFolderFileListForm::CreateCategoryPanel(void)
959 {
960         Button* pImageButton = null;
961         Button* pVideoButton = null;
962         Button* pSoundButton = null;
963         Button* pDocumentButton = null;
964         Button* pOthersButton = null;
965         Label* pBackgroundLabel = null;
966         Panel* pCategoryPanel = null;
967
968 //      Bitmap* pCategoryImagesBitmap = null;
969 //      Bitmap* pCategorySoundsBitmap = null;
970 //      Bitmap* pCategoryVideosBitmap = null;
971 //      Bitmap* pCategoryDocsBitmap = null;
972 //      Bitmap* pCategoryOthersBitmap = null;
973 //
974 //      Bitmap* pCategoryPressImagesBitmap = null;
975 //      Bitmap* pCategoryPressSoundsBitmap = null;
976 //      Bitmap* pCategoryPressVideosBitmap = null;
977 //      Bitmap* pCategoryPressDocsBitmap = null;
978 //      Bitmap* pCategoryPressOthersBitmap = null;
979
980         Bitmap* pImages = null;
981         Bitmap* pVideos = null;
982         Bitmap* pSounds = null;
983         Bitmap* pDocs = null;
984         Bitmap* pOthers = null;
985         Bitmap* pImagesPressed = null;
986         Bitmap* pVideosPressed = null;
987         Bitmap* pSoundsPressed = null;
988         Bitmap* pDocsPressed = null;
989         Bitmap* pOthersPressed = null;
990
991         Point* startPoint = null;
992
993         startPoint = new (std::nothrow) Point(28, 10);
994
995
996         pImages = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_IMAGE_ICON, 128, 92, startPoint);
997         pVideos = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_VIDEO_ICON, 128, 92, startPoint);
998         pSounds = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_SOUND_ICON, 128, 92, startPoint);
999         pDocs = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_DOCUMENT_ICON, 128, 92, startPoint);
1000         pOthers = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_OTHERS_ICON, 128, 92, startPoint);
1001
1002         pImagesPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_IMAGE_ICON_PRESS, 128, 92, startPoint);
1003         pVideosPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_VIDEO_ICON_PRESS, 128, 92, startPoint);
1004         pSoundsPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_SOUND_ICON_PRESS, 128, 92, startPoint);
1005         pDocsPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_DOCUMENT_ICON_PRESS, 128, 92, startPoint);
1006         pOthersPressed = MfUtility::MergeNinePatchedBitmapN(IDB_CATEGORY_BACKGROUND, IDB_CATEGORY_OTHERS_ICON_PRESS, 128, 92, startPoint);
1007
1008         pImageButton = static_cast<Button*>(GetControl("IDC_BUTTON_IMAGES", true));
1009         pImageButton->SetActionId(IDA_BUTTON_IMAGE);
1010         pImageButton->SetNormalBackgroundBitmap(*pImages);
1011         pImageButton->SetPressedBackgroundBitmap(*pImagesPressed);
1012         pImageButton->AddActionEventListener(*this);
1013
1014         pVideoButton = static_cast<Button*>(GetControl("IDC_BUTTON_VIDEOS", true));
1015         pVideoButton->SetActionId(IDA_BUTTON_VIDEO);
1016         pVideoButton->SetNormalBackgroundBitmap(*pVideos);
1017         pVideoButton->SetPressedBackgroundBitmap(*pVideosPressed);
1018         pVideoButton->AddActionEventListener(*this);
1019
1020         pSoundButton = static_cast<Button*>(GetControl("IDC_BUTTON_SOUNDS", true));
1021         pSoundButton->SetNormalBackgroundBitmap(*pSounds);
1022         pSoundButton->SetPressedBackgroundBitmap(*pSoundsPressed);
1023         pSoundButton->SetActionId(IDA_BUTTON_SOUND);
1024         pSoundButton->AddActionEventListener(*this);
1025
1026         pDocumentButton = static_cast<Button*>(GetControl("IDC_BUTTON_DOCUMENTS", true));
1027         pDocumentButton->SetNormalBackgroundBitmap(*pDocs);
1028         pDocumentButton->SetPressedBackgroundBitmap(*pDocsPressed);
1029         pDocumentButton->SetActionId(IDA_BUTTON_DOCUMENT);
1030         pDocumentButton->AddActionEventListener(*this);
1031
1032         pOthersButton = static_cast<Button*>(GetControl("IDC_BUTTON_OTHERS", true));
1033         pOthersButton->SetNormalBackgroundBitmap(*pOthers);
1034         pOthersButton->SetPressedBackgroundBitmap(*pOthersPressed);
1035         pOthersButton->SetActionId(IDA_BUTTON_OTHERS);
1036         pOthersButton->AddActionEventListener(*this);
1037
1038         pCategoryPanel = static_cast<Panel*>(GetControl("IDC_CATEGORY_ICON_PANEL", true));
1039
1040         pBackgroundLabel = static_cast<Label*>(GetControl("IDC_LABEL_BACKGROUND", true));
1041
1042         pCategoryPanel->SetControlAlwaysAtBottom(*pBackgroundLabel, true);
1043
1044         delete startPoint;
1045         delete pImages;
1046         delete pVideos;
1047         delete pSounds;
1048         delete pDocs;
1049         delete pOthers;
1050
1051         delete pImagesPressed;
1052         delete pVideosPressed;
1053         delete pSoundsPressed;
1054         delete pDocsPressed;
1055         delete pOthersPressed;
1056 }
1057
1058 void
1059 TopLevelFolderFileListForm::OnAppControlCompleted(void)
1060 {
1061         AppLogDebug("TopLevelFolderFileListForm::OnAppControlCompleted");
1062         Invalidate(true);
1063 }