NABI_SE issues resolved
[apps/osp/MyFiles.git] / src / MfSubFolderMoveCopy.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: MfSubFolderMoveCopy.cpp
19  * @brief: This file contains the implementation SubFolderMoveCopy class, which loads the form which implements the Copy
20  * and Move Functionalities on the SubDirectoryForm.
21  */
22
23 #include "MfSubFolderMoveCopy.h"
24 #include "MfTypes.h"
25
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Base::Utility;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Io;
32 using namespace Tizen::Locales;
33 using namespace Tizen::Media;
34 using namespace Tizen::System;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39
40 SubFolderMoveCopy::SubFolderMoveCopy(void)
41 : _pBaseItemProvider(null)
42 , _pFolderEntryPM(null)
43 , _pFileManager(null)
44 , _pThumbnailItemProvider(null)
45 , _pThumbnailManager(null)
46 , _pFileNames(null)
47 , _pFileProgressingCancelButton(null)
48 , __pHomeButton(null)
49 , __pUpButton(null)
50 , _pMoreContextMenu(null)
51 , _pFooter(null)
52 , _pCopy(null)
53 , _pCreateFolder(null)
54 , _pMove(null)
55 , _pPaste(null)
56 , __pHeader(null)
57 , _pIconListView(null)
58 , _pDisplayPathLabel(null)
59 , _pFileProgressingHeaderLabel(null)
60 , _pFileProgressingLabel(null)
61 , _pListView(null)
62 , _pFileProgressingPopup(null)
63 , _pFileProgressingProgress(null)
64 {
65         __updateFooterCheck = false;
66         __fileManagedCount = 0;
67         __storageType = MEMORY_TYPE_NONE;
68         __viewType = 0;
69         setMediaPath = false;
70 }
71
72 SubFolderMoveCopy::~SubFolderMoveCopy(void)
73 {
74         if (__pHomeButton != null)
75         {
76                 delete __pHomeButton;
77         }
78
79         if (__pUpButton != null)
80         {
81                 delete __pUpButton;
82         }
83 }
84
85 bool
86 SubFolderMoveCopy::Initialize(void)
87 {
88         Form::Construct(L"IDL_SUB_FOLDER_MOVE_COPY");
89         return true;
90 }
91
92 result
93 SubFolderMoveCopy::OnInitializing(void)
94 {
95         AppLogDebug("ENTER");
96         result r = E_SUCCESS;
97         String btnHome;
98         String btnUp;
99         Color formBgColor = GetBackgroundColor();
100
101         AppResource* pAppResource = null;
102         Bitmap* pBitmapHomeButton = null;
103         Bitmap* pBitmapUpButton = null;
104         Bitmap* pBitmapHomeButtonPress = null;
105         Bitmap* pBitmapUpButtonPress = null;
106
107         __fileManagedCount = 0;
108         __updateFooterCheck = false;
109
110         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
111
112         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_SUB_MOVE_COPY_FORM;
113         CreateItemSource createitemsource = CREATE_ITEM_SOURCE_SUB_BASE_MOVE_COPY;
114
115         pAppResource = UiApp::GetInstance()->GetAppResource();
116         TryCatch(pAppResource != null, , "Resource manager not found!");
117
118         pBitmapHomeButton = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
119         pBitmapUpButton = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
120         pBitmapHomeButtonPress = pAppResource->GetBitmapN(IDB_HOME_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
121         pBitmapUpButtonPress = pAppResource->GetBitmapN(IDB_UP_BUTTON_ICON_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
122
123         pAppResource->GetString(L"IDS_MF_BUTTON_HOME", btnHome);
124         pAppResource->GetString(L"IDS_MF_TAB_UP", btnUp);
125         __pHeader = GetHeader();
126         if (__pHeader != null)
127         {
128                 __pHomeButton = new (std::nothrow) ButtonItem();
129                 __pHomeButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_HOME);
130                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapHomeButton);
131                 __pHomeButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapHomeButtonPress);
132
133                 __pUpButton = new (std::nothrow) ButtonItem();
134                 __pUpButton->Construct(BUTTON_ITEM_STYLE_TEXT, IDA_BTN_UP);
135                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL, pBitmapUpButton);
136                 __pUpButton->SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED, pBitmapUpButtonPress);
137
138                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pHomeButton);
139                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pUpButton);
140                 __pHeader->AddActionEventListener(*this);
141         }
142
143         _pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
144         TryCatch(_pFolderEntryPM != null, , "__pContentManager not found!");
145         _pFolderEntryPM->Construct();
146         _pFolderEntryPM->SetSourceForm(createitemsource);
147
148         _pFileManager = FolderEntryEditorPresentationModel::GetInstance();
149         TryCatch(_pFileManager != null, , "File Manager not found!");
150
151         if (_pThumbnailItemProvider == null)
152         {
153                 _pThumbnailItemProvider = new (std::nothrow) ThumbnailItemProviderAndListener(_rootPath, sourceForm);
154                 TryCatch(_pThumbnailItemProvider != null, , "Failed to allocate memory to thumbnail provider");
155                 _pThumbnailItemProvider->SetFolderEntryProvider(this);
156                 _pThumbnailItemProvider->SetFooterItemStateChangeListener(this);
157
158         }
159
160         _pDisplayPathLabel = static_cast< Label* >(GetControl("IDC_LABEL_DISPLAY_PATH"));
161         TryCatch(_pDisplayPathLabel != null, , "__pDisplayPathLabel is null");
162
163         _pBaseItemProvider = new (std::nothrow) BaseItemProvider();
164         TryCatch(_pBaseItemProvider != null, , "Failed to allocate base itemprovider");
165         _pBaseItemProvider->Construct();
166         _pBaseItemProvider->SetSourceForm(createitemsource);
167         _pBaseItemProvider->SetFolderEntryProvider(this);
168
169         _pListView = static_cast< ListView* >(GetControl("IDC_LISTVIEW1"));
170         TryCatch(_pListView != null, , "list view is null");
171         _pListView->AddListViewItemEventListener(*this);
172         _pListView->SetItemProvider(*_pBaseItemProvider);
173
174         _pIconListView = static_cast< IconListView* >(GetControl(L"IDC_ICONLISTVIEW_SUB_THUMBNAILS"));
175         if (_pIconListView != null)
176         {
177                 _pIconListView->SetShowState(false);
178                 r = _pIconListView->SetItemProvider(*_pThumbnailItemProvider);
179                 _pIconListView->AddIconListViewItemEventListener(*_pThumbnailItemProvider);
180         }
181
182 #if 0
183         DataBindingContext* pContext = null;
184
185         pContext = GetDataBindingContextN();
186         pContext->Bind(L"ID_DISPLAY_PATH", L"IDC_LABEL_DISPLAY_PATH", L"text", __displayPath, DATA_BINDING_DATA_TYPE_STRING, DATA_BINDING_FLOW_ONE_WAY, DATA_BINDING_TRIGGER_EXPLICIT, this, null, null);
187         delete pContext;
188
189 #endif
190
191         delete pBitmapHomeButton;
192         delete pBitmapUpButton;
193         delete pBitmapHomeButtonPress;
194         delete pBitmapUpButtonPress;
195         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
196
197         return r;
198 CATCH:
199
200         if (__pHomeButton != null)
201         {
202                 delete __pHomeButton;
203                 __pHomeButton = null;
204         }
205
206         if (__pUpButton != null)
207         {
208                 delete __pUpButton;
209                 __pUpButton = null;
210         }
211
212         if (_pDisplayPathLabel != null)
213         {
214                 delete _pDisplayPathLabel;
215                 _pDisplayPathLabel = null;
216         }
217
218         if (_pListView != null)
219         {
220                 delete _pListView;
221                 _pListView = null;
222         }
223
224         if (pBitmapHomeButton != null)
225         {
226                 delete pBitmapHomeButton;
227                 pBitmapHomeButton = null;
228         }
229
230         if (pBitmapUpButton != null)
231         {
232                 delete pBitmapUpButton;
233                 pBitmapUpButton = null;
234         }
235         if (pBitmapHomeButtonPress != null)
236         {
237                 delete pBitmapHomeButtonPress;
238                 pBitmapHomeButtonPress = null;
239         }
240         if (pBitmapUpButtonPress != null)
241         {
242                 delete pBitmapUpButtonPress;
243                 pBitmapUpButtonPress = null;
244         }
245         return r;
246 }
247
248 void
249 SubFolderMoveCopy::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
250 {
251         AppLogDebug("ENTER");
252         Bitmap* pBitmapCreateFolderContextItem = null;
253         String btnCreateFoler;
254         AppResource* pAppResource = null;
255         pAppResource = UiApp::GetInstance()->GetAppResource();
256
257         if (pAppResource != null)
258         {
259                 pAppResource->GetString(L"IDS_COM_BODY_CREATE_FOLDER", btnCreateFoler);
260                 pBitmapCreateFolderContextItem = pAppResource->GetBitmapN(IDB_POPUP_CREATE_FOLDER_ICON, BITMAP_PIXEL_FORMAT_ARGB8888);
261         }
262
263         switch (actionId)
264         {
265         case IDA_BTN_HOME:
266         {
267                 ShowHomeView();
268         }
269         break;
270
271         case IDA_BTN_UP:
272         {
273                 LoadParentForm();
274         }
275         break;
276         case IDA_BTN_PASTE:
277         {
278                 ((MyFilesApp*) Application::GetInstance())->SetNotifyListener(this);
279                 _rootPath = FolderNavigationPresentationModel::GetCurrentPath();
280                 _pFileManager->CopyFolderEntries(FILE_EXISTING_OPERATIONID_NONE);
281         }
282         break;
283
284         case IDA_BTN_MOVE:
285         {
286                 ((MyFilesApp*) Application::GetInstance())->SetNotifyListener(this);
287                 _rootPath = FolderNavigationPresentationModel::GetCurrentPath();
288                 _pFileManager->MoveFolderEntries(FILE_EXISTING_OPERATIONID_NONE);
289         }
290         break;
291         case IDA_BTN_CREATE_FOLDER:
292         {
293                 LoadCreateFolderForm();
294         }
295         break;
296         case IDA_BTN_MORE:
297         {
298                 _pMoreContextMenu->RemoveAllItems();
299                 _pMoreContextMenu->SetItemTextColor(CONTEXT_MENU_ITEM_STATUS_NORMAL, Color::GetColor(COLOR_ID_WHITE));
300                 _pMoreContextMenu->SetItemTextColor(CONTEXT_MENU_ITEM_STATUS_PRESSED, Color::GetColor(COLOR_ID_WHITE));
301                 _pMoreContextMenu->AddItem(btnCreateFoler, IDA_BTN_CREATE_FOLDER, *pBitmapCreateFolderContextItem, null, null);
302                 _pMoreContextMenu->SetShowState(true);
303                 _pMoreContextMenu->Show();
304         }
305         break;
306         case IDA_BTN_ANIMATION_POPUP_CANCEL:
307         {
308                 //HideFileProgressingPopup();
309                 _pFileManager->ForceStopWorkerThread();
310         }
311         break;
312         default:
313         {
314                 //SubBaseOnActionPerformed(source, actionId);
315         }
316         break;
317         }
318         AppLogDebug("EXIT");
319 }
320
321 void
322 SubFolderMoveCopy::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
323 {
324         AppLogDebug("ENTER");
325         DirectoryEntry* pDirStr = null;
326         String fileName;
327         SceneManager* pSceneManager = SceneManager::GetInstance();
328         result r = E_SUCCESS;
329         String backupRootPath = FolderNavigationPresentationModel::GetCurrentPath();
330         if (_pFileNames != null)
331         {
332                 pDirStr = static_cast< DirectoryEntry* >(_pFileNames->GetAt(index));
333                 TryCatch(pDirStr != null, , " Failed to retrieve pDirStr");
334
335                 _rootPath.Clear();
336                 _rootPath.Append(pDirStr->GetFullFilePath());
337                 if (pDirStr->IsDirectory())
338                 {
339                         FolderNavigationPresentationModel::SetCurrentFilePath(_rootPath);
340
341                         String oldLabelText = _pDisplayPathLabel->GetText();
342
343                         String newLabelText;
344                         newLabelText.Append(oldLabelText);
345                         newLabelText.Append(pDirStr->GetFileName());
346                         newLabelText.Append(L"/");
347
348                         __displayPath = newLabelText;
349
350                         //Get the header and set the title to the current Directory Name.
351                         __pHeader = GetHeader();
352                         if (__pHeader != null)
353                         {
354                                 if (!fileName.IsEmpty())
355                                 {
356                                         __pHeader->SetTitleText(fileName);
357                                         __pHeader->Invalidate(true);
358                                 }
359                         }
360
361                         ArrayList* pArg = null;
362                         pArg = new (std::nothrow) ArrayList();
363                         pArg->Construct();
364                         pArg->Add(new (std::nothrow) Integer(sourceFormOption));
365                         pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArg);
366                         TryCatch(r == E_SUCCESS, , "scene transition failed");
367                 }
368         }
369
370         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
371         return;
372
373 CATCH:
374         FolderNavigationPresentationModel::SetCurrentFilePath(backupRootPath);
375         if (_pFolderEntryPM != null)
376         {
377                 delete _pFolderEntryPM;
378         }
379
380         return;
381 }
382
383 void
384 SubFolderMoveCopy::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
385                                                                          const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
386 {
387         AppLogDebug("ENTER");
388         result r = E_SUCCESS;
389
390         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
391
392         AppResource* pAppResource = null;
393         AppRegistry* pAppRegistry = null;
394         String viewStyleKeyName(L"ListDisplayType");
395         String phone;
396         String sdCard;
397         String externalStorage;
398         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
399         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
400         int sourceForm = THUMBNAIL_PROVIDER_SOURCEID_SUB_MOVE_COPY_FORM;
401
402         r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
403         AppLogDebug("AppRegistry Get Result: %s", GetErrorMessage(r));
404
405         __viewType = listViewDisplayType;
406
407         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
408         DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD,deviceState);
409 #if 0
410         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
411 #endif
412
413         pAppResource = UiApp::GetInstance()->GetAppResource();
414         TryCatch(pAppResource != null, , "Failed to fetch AppResource");
415         pAppResource->GetString(L"IDS_MF_TAB_PHONE", phone);
416         pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCard);
417         pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
418         phone.Append(L"/");
419         sdCard.Append(L"/");
420         externalStorage.Append(L"/");
421
422         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
423
424         if (_pThumbnailItemProvider != null)
425         {
426                 _pThumbnailItemProvider->SetCreateItemSource(sourceForm);
427         }
428
429         if (pArgs != null)
430         {
431                 sourceFormOption = *(static_cast< Integer* >(pArgs->GetAt(0)));
432
433                 pArgs->RemoveAll(true);
434                 delete pArgs;
435                 pArgs = null;
436
437                 _rootPath.Clear();
438                 _rootPath = FolderNavigationPresentationModel::GetCurrentPath();
439                 __receivedStorageType = FolderNavigationPresentationModel::GetStorageType();
440
441                 SetHeaderTitleText(_rootPath);
442
443                 switch (__receivedStorageType.ToInt())
444                 {
445                 case MEMORY_TYPE_PHONE:
446                 {
447                         __storageType = MEMORY_TYPE_PHONE;
448                         __displayPath = phone;
449                 }
450                 break;
451
452                 case MEMORY_TYPE_SD_CARD:
453                 {
454                         __storageType = MEMORY_TYPE_SD_CARD;
455
456                         __displayPath = sdCard;
457                 }
458                 break;
459
460                 case MEMORY_TYPE_EXTERNAL:
461                 {
462                         __storageType = MEMORY_TYPE_EXTERNAL;
463                         __displayPath = externalStorage;
464                 }
465                 break;
466
467                 default:
468                 {
469                         //Do Nothing.
470                 }
471                 break;
472                 }
473
474         }
475         //Call SetNextDisplayPath to Append the right path to the label.
476         SetNextDisplayPath();
477
478         _pFileManager->SetFileManagingListener(this);
479
480         if (_pFolderEntryPM != null)
481         {
482                 _pFolderEntryPM->SetFolderEntryPath(_rootPath);
483                 //__pFileListPM->SetFileEventListener(this);
484                 _pFileNames = _pFolderEntryPM->GetFolderEntryList();
485                 TryCatch(_pFileNames != null, , "Failed to allocate Memory to Filenames ArrayList");
486         }
487
488
489         AppLogDebug("Filenames Count %d", _pFileNames->GetCount());
490
491         _pThumbnailItemProvider->SetSourceFromOption(sourceFormOption.ToInt());
492
493         _pFooter = GetFooter();
494         if (_pFooter != null)
495         {
496                 _pFooter->RemoveAllButtons();
497                 _pFooter->RemoveAllItems();
498         }
499         CreateFooterItems();
500
501         _pFolderEntryPM->InitThumbnailManager();
502         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
503         return;
504 CATCH:
505         return;
506 }
507
508 void
509 SubFolderMoveCopy::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
510                                                                           const Tizen::Ui::Scenes::SceneId& nextSceneId)
511 {
512         ((MyFilesApp*)Application::GetInstance())->SetCurrentView(null);
513         DeviceManager::RemoveAllDeviceEventListeners();
514         _pFolderEntryPM->StopThumbnailManager(true);
515 }
516
517 result
518 SubFolderMoveCopy::LoadParentForm(void)
519 {
520         AppLogDebug("ENTER");
521         SceneManager* pSceneManager = SceneManager::GetInstance();
522         result r = E_SUCCESS;
523         _rootPath = FolderNavigationPresentationModel::GetCurrentPath();
524         String previousParentPath = GetParentDirectoryName();
525
526         //FolderNavigationPresentationModel::SetCurrentFilePath(previousParentPath);
527
528         if (_rootPath == BasePresentationModel::GetMediaPath() || _rootPath == BasePresentationModel::GetSdCardPath() || _rootPath == BasePresentationModel::GetUsbPath())
529         {
530                 String __rootPath;
531                 __rootPath.Append(previousParentPath);
532                 ArrayList* pArgs = new (std::nothrow) ArrayList();
533                 r = pArgs->Construct();
534                 Integer* pSourceFromOption = new (std::nothrow) Integer(sourceFormOption);
535                 pArgs->Add(pSourceFromOption);
536                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_COPY_MOVE_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pArgs);
537         }
538         else
539         {
540                 FolderNavigationPresentationModel::SetCurrentFilePath(previousParentPath);
541                 _rootPath.Clear();
542                 _rootPath.Append(previousParentPath);
543
544                 SetParentDisplayPath();
545                 SetHeaderTitleText(_rootPath);
546
547                 if (_pFolderEntryPM != null)
548                 {
549                         //__pContentManager->ClearList();
550                         _pFolderEntryPM->SetFolderEntryPath(_rootPath);
551                         _pFileNames = _pFolderEntryPM->GetFolderEntryList();
552
553                         _pFolderEntryPM->InitThumbnailManager();
554                         TryCatch(_pFileNames != null, , "Failed to allocate Memory to __pFilenames");
555                 }
556
557
558
559                 if (_pListView != null && _pListView->IsVisible())
560                 {
561                         //Call UpdateList on __pListView
562                         r = _pListView->UpdateList();
563                 }
564
565                 if (_pIconListView != null && _pIconListView->IsVisible())
566                 {
567                         _pIconListView->UpdateList();
568                 }
569
570                 AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
571         }
572         return r;
573 CATCH:
574         return r;
575 }
576
577 String
578 SubFolderMoveCopy::GetParentDirectoryName(void)
579 {
580         String pPreviousParentPath;
581         pPreviousParentPath = FolderNavigationPresentationModel::GetParentPath();
582         return pPreviousParentPath;
583 }
584
585 void
586 SubFolderMoveCopy::SetNextDisplayPath(void)
587 {
588         AppLogDebug("ENTER");
589         String dislayPath;
590         String delim(L"/");
591         String token;
592         String newDisplayPath;
593         String testPath;
594
595         String phone;
596         String sdCard;
597         String externalStorage;
598         AppResource* pAppResource = null;
599         pAppResource = UiApp::GetInstance()->GetAppResource();
600         if (pAppResource != null)
601         {
602                 pAppResource->GetString(L"IDS_MF_TAB_PHONE", phone);
603                 pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", sdCard);
604                 pAppResource->GetString(L"IDS_MF_TAB_EXTERNAL_STORAGE", externalStorage);
605                 phone.Append(L"/");
606                 sdCard.Append(L"/");
607                 externalStorage.Append(L"/");
608         }
609         _rootPath = FolderNavigationPresentationModel::GetCurrentPath();
610         StringTokenizer StrTok(_rootPath, delim);
611         int tokenCount = 0;
612
613         switch (__storageType)
614         {
615         case MEMORY_TYPE_PHONE:
616         {
617                 tokenCount = 3;
618                 __displayPath = phone;
619         }
620         break;
621
622         case MEMORY_TYPE_SD_CARD:
623         {
624                 tokenCount = 3;
625                 __displayPath = sdCard;
626         }
627         break;
628
629         case MEMORY_TYPE_EXTERNAL:
630         {
631                 tokenCount = 3;
632                 __displayPath = externalStorage;
633         }
634         break;
635
636         default:
637                 //Do Nothing.
638                 break;
639         }
640
641         //Use a string tokenizer to get the filepath until it's the last token, break the loop when
642         //it is the last token
643         while (StrTok.HasMoreTokens())
644         {
645                 if (tokenCount > 0)
646                 {
647                         tokenCount--;
648                         StrTok.GetNextToken(token);
649                 }
650                 else
651                 {
652                         StrTok.GetNextToken(token);
653                         dislayPath.Append(token);
654                         dislayPath.Append(L"/");
655                 }
656         }
657
658         newDisplayPath = __displayPath;
659         newDisplayPath.Append(dislayPath);
660         __displayPath = newDisplayPath;
661
662 #if 0
663         DataBindingContext* pContext = GetDataBindingContextN();
664         if (pContext != null)
665         {
666                 pContext->UpdateBinding(L"ID_DISPLAY_PATH", DATA_BINDING_DESTINATION_TYPE_TARGET);
667                 delete pContext;
668                 pContext = null;
669         }
670 #endif
671
672         if (_pDisplayPathLabel != null)
673         {
674                 _pDisplayPathLabel->SetText(__displayPath);
675                 _pDisplayPathLabel->Invalidate(true);
676         }
677         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
678 }
679
680 void
681 SubFolderMoveCopy::SetParentDisplayPath(void)
682 {
683         AppLogDebug("ENTER");
684         String dislayPath;
685         String delim(L"/");
686         String parentDisplayPath;
687         String token;
688
689         if (_pDisplayPathLabel != null)
690         {
691                 dislayPath = _pDisplayPathLabel->GetText();
692         }
693
694         StringTokenizer StrTok(dislayPath, delim);
695
696         //Use a string tokenizer to get the filepath until it's the last token, break the loop when
697         //it is the last token
698         while (StrTok.HasMoreTokens())
699         {
700                 int tokenCount = StrTok.GetTokenCount();
701
702                 if (tokenCount != 1)
703                 {
704                         StrTok.GetNextToken(token);
705                         parentDisplayPath.Append(token);
706                         parentDisplayPath.Append(L"/");
707                 }
708                 else
709                 {
710                         break;
711                 }
712         }
713
714         __displayPath = parentDisplayPath;
715
716 #if 0
717         DataBindingContext* pContext = GetDataBindingContextN();
718         pContext->UpdateBinding(L"ID_DISPLAY_PATH", DATA_BINDING_DESTINATION_TYPE_TARGET);
719         delete pContext;
720         pContext = null;
721 #endif
722         if (_pDisplayPathLabel != null)
723         {
724                 _pDisplayPathLabel->SetText(__displayPath);
725                 _pDisplayPathLabel->Invalidate(true);
726         }
727
728         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
729 }
730
731 void
732 SubFolderMoveCopy::OnDataBindingSourceUpdated(const String& bindingId, const String& controlName, const Tizen::Base::String& propertyName)
733 {
734         //Empty Implementation.
735 }
736
737 void
738 SubFolderMoveCopy::OnDataBindingTargetUpdated(const String& bindingId, const String& controlName, const Tizen::Base::String& propertyName)
739 {
740         //Empty Implementation.
741 }
742 void
743 SubFolderMoveCopy::OnDataBindingValidationFailed(const Tizen::Base::String& bindingId, const Tizen::Base::String& controlName, const Tizen::Base::String& propertyName, Tizen::Ui::DataBindingDestinationType destType)
744 {
745         //Empty Implementation.
746 }
747
748 void
749 SubFolderMoveCopy::ShowHomeView(void)
750 {
751         
752         AppLogDebug("Entry");
753         Integer* pSourceForm = null;
754         SceneManager* pSceneManager = SceneManager::GetInstance();
755         ArrayList* pArgs = null;
756
757         pArgs = new (std::nothrow) ArrayList();
758         //TryCatch(pArgs != null, , "pArgs is null.");
759         pSourceForm = new (std::nothrow) Integer(sourceFormOption);
760
761         //__pFolderEntryPM->SetFileEventListener(null);
762
763         pArgs->Construct();
764
765         pArgs->Add(pSourceForm);
766
767         //TryCatch(pSceneManager != null, , "SceneManager is null.");
768
769         /*if (__rootPath == BasePresentationModel::GetMediaPath() || __rootPath == BasePresentationModel::GetSdCardPath())
770                 {
771                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ROOT_DIRECTORY_MOVE_COPY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
772                 }
773                 else
774                 {
775                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_MOVE_COPY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
776                 }
777          */
778         //pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_MOVE_COPY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArgs);
779         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_COPY_MOVE_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_DESTROY),pArgs);
780         return;
781 }
782
783 void
784 SubFolderMoveCopy::SetHeaderTitleText(Tizen::Base::String& filePath)
785 {
786         String token;
787         String parentFileName;
788         String delimiter(L"/");
789         StringTokenizer tokenizer(filePath, delimiter);
790         AppResource* pAppResource = null;
791
792         pAppResource = UiApp::App::GetInstance()->GetAppResource();
793
794         if (filePath == BasePresentationModel::GetMediaPath())
795         {
796                 if (pAppResource != null)
797                 {
798                         pAppResource->GetString(L"IDS_MF_TAB_PHONE", parentFileName);
799                 }
800         }
801         else if (filePath == BasePresentationModel::GetSdCardPath())
802         {
803                 if (pAppResource != null)
804                 {
805                         pAppResource->GetString(L"IDS_MF_TAB_MEMORY_CARD", parentFileName);
806                 }
807         }
808         else
809         {
810                 while (tokenizer.HasMoreTokens())
811                 {
812                         int tokenCount = tokenizer.GetTokenCount();
813
814                         if (tokenCount == 1)
815                         {
816                                 tokenizer.GetNextToken(parentFileName);
817                         }
818                         else
819                         {
820                                 tokenizer.GetNextToken(token);
821                         }
822                 }
823         }
824         __pHeader = GetHeader();
825
826         if (__pHeader != null)
827         {
828                 if (!parentFileName.IsEmpty())
829                 {
830                         __pHeader->SetTitleText(parentFileName);
831                         __pHeader->Invalidate(true);
832                         __pHeader->Invalidate(true);
833                 }
834         }
835 }
836
837 void
838 SubFolderMoveCopy::OnDeviceChange(ComponentType deviceType, const Tizen::Base::String& state)
839 {
840         bool setMediaPath = false;
841         MemoryType currentMemoryType = MEMORY_TYPE_PHONE;
842         String unmounted = sdCardStatusUnmounted;
843         String removed = usbDeviceStatusRemoved;
844         String currentPath;
845
846         if (state == unmounted || state == removed)
847         {
848                 currentPath = FolderNavigationPresentationModel::GetCurrentPath();
849                 if (state == unmounted)
850                 {
851                         if (currentPath.Contains(BasePresentationModel::GetSdCardPath()))
852                         {
853                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
854                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
855                                 setMediaPath = true;
856                         }
857                 }
858
859                 if (state == removed)
860                 {
861                         if (currentPath.Contains(BasePresentationModel::GetUsbPath()))
862                         {
863                                 FolderNavigationPresentationModel::SetCurrentFilePath(BasePresentationModel::GetMediaPath());
864                                 FolderNavigationPresentationModel::SetStorageType(currentMemoryType);
865                                 setMediaPath = true;
866                         }
867                 }
868
869                 if (setMediaPath)
870                 {
871                         SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_COPY_MOVE_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_DESTROY_OPTION_DESTROY), null);
872                 }
873         }
874 }
875 void
876 SubFolderMoveCopy::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
877 {
878
879         ComponentType currentDeviceType;
880         switch (deviceType)
881         {
882         case StorageCard:
883         {
884                 currentDeviceType = COMPONENT_TYPE_STORAGE_CARD;
885         }
886         break;
887
888         case UsbClient:
889         {
890                 currentDeviceType = COMPONENT_TYPE_USB;
891         }
892         break;
893
894         default:
895         {
896                 //Do Nothing.
897         }
898         break;
899         }
900         OnDeviceChange(currentDeviceType, state);
901 }
902
903 void
904 SubFolderMoveCopy::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
905                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
906 {
907         AppLogDebug("Enter");
908
909         result r = E_SUCCESS;
910
911         int listViewDisplayType = VIEW_TYPE_AS_NORMAL_LIST;
912         String viewStyleKeyName(L"ListDisplayType");
913
914         AppRegistry* pAppRegistry = null;
915         pAppRegistry = UiApp::App::GetInstance()->GetAppRegistry();
916
917         r = pAppRegistry->Get(viewStyleKeyName, listViewDisplayType);
918         AppLogDebug("AppRegistry Get Result: %s", GetErrorMessage(r));
919
920         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
921
922         switch (listViewDisplayType)
923         {
924         case VIEW_TYPE_AS_DETAILED_LIST:
925         {
926                 if (_pIconListView != null && _pIconListView->IsVisible())
927                 {
928                         _pIconListView->SetShowState(false);
929                 }
930
931                 if (_pListView != null)
932                 {
933                         _pListView->ScrollToItem(0);
934                         _pListView->UpdateList();
935                         _pListView->SetShowState(true);
936                 }
937
938         }
939         break;
940
941         case VIEW_TYPE_AS_NORMAL_LIST:
942         {
943                 if (_pIconListView != null && _pIconListView->IsVisible())
944                 {
945                         _pIconListView->SetShowState(false);
946                 }
947
948                 if (_pListView != null)
949                 {
950                         _pListView->ScrollToItem(0);
951                         _pListView->UpdateList();
952                         _pListView->SetShowState(true);
953                 }
954
955         }
956         break;
957
958         case VIEW_TYPE_AS_THUMBNAILS:
959         {
960                 if (_pListView != null && _pListView->IsVisible())
961                 {
962                         _pListView->SetShowState(false);
963                 }
964
965                 if (_pIconListView != null)
966                 {
967                         _pIconListView->ScrollToItem(0);
968                         _pIconListView->UpdateList();
969                         _pIconListView->SetShowState(true);
970                 }
971
972         }
973         break;
974
975         default:
976         {
977                 __viewType = VIEW_TYPE_AS_NORMAL_LIST;
978                 if (_pListView != null)
979                 {
980                         _pListView->ScrollToItem(0);
981                         _pListView->UpdateList();
982                 }
983         }
984         break;
985         }
986
987 }
988
989 void
990 SubFolderMoveCopy::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
991                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
992 {
993         //Empty Implementation.
994 }
995
996 void
997 SubFolderMoveCopy::CreateFooterItems(void)
998 {
999         AppLogDebug("ENTER");
1000         result r = E_SUCCESS;
1001         _pFooter = GetFooter();
1002         int xPos = 0, yPos = 0;
1003
1004         String btnMove;
1005         String btnMoveHere;
1006         String btnPaste;
1007         String btnPasteHere;
1008         //String btnCreateFolder;
1009
1010         ButtonItem footerItemMenu;
1011
1012         Bitmap* pBitmap = null;
1013         Bitmap* pBitmapPress = null;
1014         Bitmap* pBitmapDisabled = null;
1015
1016         AppResource* pAppResource = null;
1017         pAppResource = Application::GetInstance()->GetAppResource();
1018         TryCatch(pAppResource != null, , "Resource manager not found!");
1019
1020         pAppResource->GetString(L"IDS_MF_SK3_MOVE_HERE", btnMoveHere);
1021         pAppResource->GetString(L"IDS_MF_SK3_PASTE_HERE", btnPasteHere);
1022         //pAppResource->GetString(L"IDS_MF_OPT_CREATE_FOLDER", btnCreateFolder);
1023
1024         footerItemMenu.Construct(BUTTON_ITEM_STYLE_ICON, IDA_BTN_MORE);
1025         _pFooter = GetFooter();
1026
1027         pBitmap = pAppResource->GetBitmapN(IDB_MORE, BITMAP_PIXEL_FORMAT_ARGB8888);
1028         pBitmapDisabled = pAppResource->GetBitmapN(IDB_MORE_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888);
1029         pBitmapPress = pAppResource->GetBitmapN(IDB_MORE_PRESS, BITMAP_PIXEL_FORMAT_ARGB8888);
1030
1031         if (pBitmap != null)
1032         {
1033                 pBitmap->Scale(Dimension(H_FOOTER_BUTTON_MORE, W_FOOTER_BUTTON_MORE));
1034                 footerItemMenu.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmap);
1035         }
1036         if (pBitmapPress != null)
1037         {
1038                 pBitmapPress->Scale(Dimension(H_FOOTER_BUTTON_MORE, W_FOOTER_BUTTON_MORE));
1039                 footerItemMenu.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pBitmapPress);
1040         }
1041         if (pBitmapDisabled != null)
1042         {
1043                 pBitmapDisabled->Scale(Dimension(H_FOOTER_BUTTON_MORE, W_FOOTER_BUTTON_MORE));
1044                 footerItemMenu.SetIcon(BUTTON_ITEM_STATUS_DISABLED, pBitmapDisabled);
1045         }
1046         if (_pFooter != null)
1047         {
1048                 _pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
1049         }
1050
1051         if (sourceFormOption.ToInt() == SELECT_MOVE_BUTTON)
1052         {
1053                 if (_pMove == null)
1054                 {
1055                         _pMove = new (std::nothrow) FooterItem();
1056                         r = _pMove->Construct(IDA_BTN_MOVE);
1057                         _pMove->SetText(btnMoveHere);
1058                 }
1059                 if (_pFooter != null)
1060                 {
1061                         r = _pFooter->AddItem(*_pMove);
1062                 }
1063         }
1064         else
1065         {
1066                 if (_pPaste == null)
1067                 {
1068                         _pPaste = new (std::nothrow) FooterItem();
1069                         r = _pPaste->Construct(IDA_BTN_PASTE);
1070                         _pPaste->SetText(btnPasteHere);
1071                 }
1072                 if (_pFooter != null)
1073                 {
1074                         r = _pFooter->AddItem(*_pPaste);
1075                 }
1076         }
1077
1078 /*      if (_pCreateFolder == null)
1079         {
1080                 _pCreateFolder = new (std::nothrow) FooterItem();
1081                 r = _pCreateFolder->Construct(IDA_BTN_CREATE_FOLDER);
1082                 _pCreateFolder->SetText(btnCreateFolder);
1083         }*/
1084 /*      if (_pFooter != null)
1085         {
1086                 r = _pFooter->AddItem(*_pCreateFolder);
1087         }*/
1088
1089         if (_pFooter != null)
1090         {
1091                 _pFooter->AddActionEventListener(*this);
1092                 _pFooter->SetBackButton();
1093                 _pFooter->SetBackButtonEnabled(true);
1094                 _pFooter->SetShowState(true);
1095                 _pFooter->Invalidate(true);
1096                 SetFormBackEventListener(this);
1097                 _pFooter->SetButton(BUTTON_POSITION_LEFT, footerItemMenu);
1098                 _pFooter->GetPosition(xPos, yPos);
1099         }
1100         _pMoreContextMenu = new (std::nothrow) ContextMenu();
1101         _pMoreContextMenu->Construct(Point(0, yPos), CONTEXT_MENU_STYLE_LIST);
1102         _pMoreContextMenu->AddActionEventListener(*this);
1103
1104         delete pBitmap;
1105         delete pBitmapPress;
1106         delete pBitmapDisabled;
1107         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1108         return;
1109 CATCH:
1110         if (_pFooter != null)
1111         {
1112                 _pFooter->RemoveAllItems();
1113         }
1114
1115         AppLogDebug("CreateFooterCustomControls--");
1116 }
1117
1118 FolderEntryPresentationModel*
1119 SubFolderMoveCopy::GetFolderEntryPresentationModel(void)
1120 {
1121         return _pFolderEntryPM;
1122 }
1123
1124 void
1125 SubFolderMoveCopy::OnNotificationReceived(ArrayList* pArgs)
1126 {
1127         AppLogDebug("ENTER");
1128
1129         int fileProcessingResult = 0;
1130         Integer* pfileProcessingResult = null;
1131
1132         TryCatch(pArgs != null, , "Argument list received is invalid");
1133
1134         pfileProcessingResult = (Integer*) pArgs->GetAt(0);
1135         if (pfileProcessingResult != null)
1136         {
1137                 //TryCatch(pArgs!=null ,,"Argument list received is invalid");
1138                 fileProcessingResult = pfileProcessingResult->ToInt();
1139
1140                 delete pfileProcessingResult;
1141         }
1142         switch (fileProcessingResult)
1143         {
1144         case FILE_MANAGING_RESULT_COPYING_SUCCESS:
1145         {
1146                 HideFileProgressingPopup();
1147                 LoadDirectoryForm();
1148         }
1149         break;
1150
1151         case FILE_MANAGING_RESULT_MOVING_SUCCESS:
1152         {
1153                 HideFileProgressingPopup();
1154                 LoadDirectoryForm();
1155         }
1156         break;
1157
1158         case FILE_MANAGING_RESULT_DUPLICITY:
1159         {
1160                 HideFileProgressingPopup();
1161                 //ShowFileExistingPopup();
1162         }
1163         break;
1164
1165         case FILE_MANAGING_RESULT_SOURCE_SAME_AS_DESTINATION:
1166         {
1167                 HideFileProgressingPopup();
1168                 MessageBox messageBox;
1169                 String moveFailedErrorMessage;
1170                 String copyFailedErrorMessage;
1171
1172                 AppResource::GetInstance()->GetString(L"IDS_MF_POP_UNABLE_TO_MOVE_DESTINATION_FOLDER_SAME_AS_SOURCE_FOLDER", moveFailedErrorMessage);
1173                 AppResource::GetInstance()->GetString(L"IDS_MF_POP_UNABLE_TO_COPY_DESTINATION_FOLDER_SAME_AS_SOURCE_FOLDER", copyFailedErrorMessage);
1174
1175                 if (sourceFormOption.ToInt() == SELECT_MOVE_BUTTON)
1176                 {
1177                         messageBox.Construct(L"", moveFailedErrorMessage, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
1178                 }
1179                 else
1180                 {
1181                         messageBox.Construct(L"", copyFailedErrorMessage, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
1182                 }
1183
1184                 // Call ShowAndWait - draw, show itself and process events
1185                 int modalResult = 0;
1186                 messageBox.ShowAndWait(modalResult);
1187         }
1188         break;
1189
1190         case FILE_MANAGING_RESULT_CURRENT_STATUS:
1191         {
1192                 String movingLabelText;
1193                 String copyingLabelText;
1194                 Integer* percentage = null;
1195
1196                 AppResource* pAppResource = null;
1197                 pAppResource = Application::GetInstance()->GetAppResource();
1198
1199                 pAppResource->GetString("IDS_COM_POP_MOVING", movingLabelText);
1200                 pAppResource->GetString("IDS_MF_POP_COPYING", copyingLabelText);
1201                 int value = 0;
1202                 String strFileProcessCount(L"");
1203                 if (pArgs->GetCount() > 1)
1204                 {
1205                         Integer* pCurrentStatus = (Integer*) pArgs->GetAt(1);
1206                         Integer* pTotalFileCount = (Integer*) pArgs->GetAt(2);
1207                         HashMap* pCacheList = null;
1208                         const HashMap* pSelectedItemsList = null;
1209                         int deleteItemcount = 0;
1210                         int filesCount = 0;
1211                         DirectoryEntry* pCurrentEntry = null;
1212                         bool cacheKeyStatus = false;
1213                         String cachePath;
1214
1215                         AppLogDebug("items deleted %d",pCurrentStatus->ToInt());
1216                         deleteItemcount = pCurrentStatus->ToInt();
1217                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1218                         pSelectedItemsList = FolderEntryEditorPresentationModel::GetInstance()->GetCheckedList();
1219
1220                         if (pCacheList != null && pSelectedItemsList != null)
1221                         {
1222                                 for (filesCount=0;filesCount<deleteItemcount;filesCount++)
1223                                 {
1224                                         Integer currentKeyIndex = filesCount;
1225                                         pCurrentEntry = const_cast< DirectoryEntry* >(static_cast< const DirectoryEntry* >(pSelectedItemsList->GetValue(currentKeyIndex)));
1226
1227                                         if (pCurrentEntry != null)
1228                                         {
1229                                                 cachePath = pCurrentEntry->GetFullFilePath();
1230                                         }
1231
1232                                         cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1233
1234                                         if (cacheKeyStatus)
1235                                         {
1236                                                 CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1237                                         }
1238                                 }
1239                         }
1240
1241                         percentage = (Integer *)pArgs->GetAt(3);
1242                         value = percentage->ToInt();
1243                         AppLogDebug("precentage vlaue is %d",value);
1244                         if (pTotalFileCount != null)
1245                         {
1246                                 //value = (__fileManagedCount * 100) / (pTotalFileCount->ToInt());
1247
1248                                 __fileManagedCount = pCurrentStatus->ToInt();
1249                                 strFileProcessCount.Append(__fileManagedCount);
1250                                 strFileProcessCount.Append(L"/");
1251                                 strFileProcessCount.Append(pTotalFileCount->ToInt());
1252                                 delete pCurrentStatus;
1253                                 delete pTotalFileCount;
1254                         }
1255                 }
1256                 if (_pFileProgressingPopup != null)
1257                 {
1258                         if (_pFileProgressingHeaderLabel != null)
1259                         {
1260                                 if (sourceFormOption.ToInt() == SELECT_MOVE_BUTTON)
1261                                 {
1262                                         _pFileProgressingHeaderLabel->SetText(movingLabelText);
1263                                         _pFileProgressingHeaderLabel->Invalidate(true);
1264                                 }
1265
1266                                 if (sourceFormOption.ToInt() == SELECT_COPY_BUTTON)
1267                                 {
1268                                         _pFileProgressingHeaderLabel->SetText(copyingLabelText);
1269                                         _pFileProgressingHeaderLabel->Invalidate(true);
1270                                 }
1271                         }
1272                         if (_pFileProgressingProgress != null)
1273                         {
1274                                 _pFileProgressingProgress->SetValue(value);
1275                                 _pFileProgressingProgress->Invalidate(true);
1276                         }
1277
1278                         if (_pFileProgressingLabel != null)
1279                         {
1280                                 _pFileProgressingLabel->SetText(strFileProcessCount);
1281                                 _pFileProgressingLabel->Invalidate(true);
1282                         }
1283
1284                 }
1285
1286         }
1287         break;
1288
1289         case FILE_MANAGING_RESULT_COPYING_FAILED:
1290         {
1291                 String copyingFailed;
1292                 AppResource* pAppResource = null;
1293                 pAppResource = Application::GetInstance()->GetAppResource();
1294                 pAppResource->GetString("IDS_COPY_FAILED_MESSAGE", copyingFailed);
1295
1296                 HideFileProgressingPopup();
1297
1298                 MessageBox messageBox;
1299                 //messageBox.Construct(L"", L"Not enough memory.\n Delete some items and try again", MSGBOX_STYLE_NONE, 1000);
1300                 messageBox.Construct(L"", copyingFailed, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
1301                 // Call ShowAndWait - draw, show itself and process events
1302                 int modalResult = 0;
1303                 messageBox.ShowAndWait(modalResult);
1304
1305                 String tempDeviceState;
1306
1307                 DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD,tempDeviceState);
1308                 if(tempDeviceState == sdCardStatusUnmounted && deviceState == sdCardStatusMounted)
1309                 {
1310                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
1311                 }
1312                 else
1313                 {
1314                         LoadDirectoryForm();
1315                 }
1316
1317         }
1318         break;
1319
1320         case FILE_MANAGING_RESULT_MOVING_FAILED:
1321         {
1322                 String movingFailed;
1323                 AppResource* pAppResource = null;
1324                 pAppResource = Application::GetInstance()->GetAppResource();
1325                 pAppResource->GetString("IDS_COM_POP_MOVING_FAILED", movingFailed);
1326
1327                 HideFileProgressingPopup();
1328
1329                 MessageBox messageBox;
1330                 //messageBox.Construct(L"", L"Not enough memory.\n Delete some items and try again", MSGBOX_STYLE_NONE, 1000);
1331                 messageBox.Construct(L"", movingFailed, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
1332                 // Call ShowAndWait - draw, show itself and process events
1333                 int modalResult = 0;
1334                 messageBox.ShowAndWait(modalResult);
1335
1336                 String tempDeviceState;
1337                 DeviceManager::GetState(DEVICE_TYPE_STORAGE_CARD,tempDeviceState);
1338                 AppLogDebug("cureent %ls",tempDeviceState.GetPointer());
1339                 AppLogDebug("old device %ls",deviceState.GetPointer());
1340                 if(tempDeviceState == sdCardStatusUnmounted && deviceState == sdCardStatusMounted)
1341                 {
1342                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
1343                 }
1344                 else
1345                 {
1346                         LoadDirectoryForm();
1347                 }
1348         }
1349         break;
1350
1351         case FILE_MANAGING_RESULT_STORAGE_FULL:
1352         {
1353                 String storageFull;
1354                 AppResource* pAppResource = null;
1355                 pAppResource = Application::GetInstance()->GetAppResource();
1356                 pAppResource->GetString("IDS_STORAGE_FULL", storageFull);
1357
1358                 HideFileProgressingPopup();
1359                 MessageBox messageBox;
1360                 //messageBox.Construct(L"", L"Not enough memory.\n Delete some items and try again", MSGBOX_STYLE_NONE, 1000);
1361                 messageBox.Construct(L"", storageFull, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
1362                 // Call ShowAndWait - draw, show itself and process events
1363                 int modalResult = 0;
1364                 messageBox.ShowAndWait(modalResult);
1365
1366                 LoadDirectoryForm();
1367         }
1368         break;
1369
1370         default:
1371                 break;
1372         }
1373
1374 CATCH:
1375         if (pArgs != null)
1376         {
1377                 pArgs->RemoveAll(false);
1378                 delete pArgs;
1379                 pArgs = null;
1380         }
1381
1382         AppLogDebug("EXIT");
1383 }
1384
1385 result
1386 SubFolderMoveCopy::CreateFileProgressingPopup(void)
1387 {
1388         AppLogDebug("Entry");
1389         result r = E_SUCCESS;
1390         _pFileProgressingPopup = new (std::nothrow) Popup();
1391         _pFileProgressingPopup->Construct(L"IDL_FILE_PROGRESSING_POPUP");
1392         if (_pFileProgressingPopup != null)
1393         {
1394                 //_pFileProgressingPopup->SetTitleText(L"FileProcessing");
1395
1396                 _pFileProgressingCancelButton = static_cast< Button* >(_pFileProgressingPopup->GetControl(L"IDC_CANCEL_BUTTON", true));
1397                 if (_pFileProgressingCancelButton != null)
1398                 {
1399                         _pFileProgressingCancelButton->SetActionId(IDA_BTN_ANIMATION_POPUP_CANCEL);
1400                         _pFileProgressingCancelButton->AddActionEventListener(*this);
1401                         _pFileProgressingCancelButton->SetShowState(true);
1402                 }
1403
1404                 _pFileProgressingProgress = static_cast< Progress* >(_pFileProgressingPopup->GetControl(L"IDC_PROGRESS_BAR", true));
1405                 if (_pFileProgressingProgress != null)
1406                 {
1407                         _pFileProgressingProgress->SetValue(0);
1408                 }
1409
1410                 _pFileProgressingHeaderLabel = static_cast< Label* >(_pFileProgressingPopup->GetControl(L"IDC_ANIMATION_HEADER", true));
1411                 if (_pFileProgressingHeaderLabel != null)
1412                 {
1413                         _pFileProgressingHeaderLabel->SetShowState(true);
1414                 }
1415
1416                 _pFileProgressingLabel = static_cast< Label* >(_pFileProgressingPopup->GetControl(L"IDC_ANIMATION_LABEL", true));
1417                 if (_pFileProgressingLabel != null)
1418                 {
1419                         _pFileProgressingLabel->SetShowState(true);
1420                 }
1421         }
1422         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1423         return r;
1424 }
1425
1426 void
1427 SubFolderMoveCopy::ShowFileProgressingPopup(void)
1428 {
1429         String movingLabelText;
1430         String copyingLabelText;
1431         AppResource* pAppResource = null;
1432         pAppResource = Application::GetInstance()->GetAppResource();
1433
1434         pAppResource->GetString("IDS_COM_POP_MOVING", movingLabelText);
1435         pAppResource->GetString("IDS_MF_POP_COPYING", copyingLabelText);
1436
1437         CreateFileProgressingPopup();
1438
1439         if (_pFileProgressingPopup != null)
1440         {
1441
1442                 if (_pFileProgressingHeaderLabel != null)
1443                 {
1444                         if (sourceFormOption.ToInt() == SELECT_MOVE_BUTTON)
1445                         {
1446                                 _pFileProgressingHeaderLabel->SetText(movingLabelText);
1447                                 _pFileProgressingHeaderLabel->Invalidate(true);
1448                         }
1449
1450                         if (sourceFormOption.ToInt() == SELECT_COPY_BUTTON)
1451                         {
1452                                 _pFileProgressingHeaderLabel->SetText(copyingLabelText);
1453                                 _pFileProgressingHeaderLabel->Invalidate(true);
1454                         }
1455                 }
1456
1457                 _pFileProgressingPopup->SetShowState(true);
1458                 _pFileProgressingPopup->Show();
1459         }
1460 }
1461
1462 void
1463 SubFolderMoveCopy::HideFileProgressingPopup(void)
1464 {
1465         if (_pFileProgressingPopup != null && _pFileProgressingPopup->IsVisible())
1466         {
1467                 _pFileProgressingPopup->SetShowState(false);
1468
1469                 delete _pFileProgressingPopup;
1470                 _pFileProgressingPopup = null;
1471         }
1472 }
1473
1474 result
1475 SubFolderMoveCopy::LoadDirectoryForm(void)
1476 {
1477         AppLogDebug("ENTER");
1478         result r = E_SUCCESS;
1479         ArrayList* pArg = null;
1480         String fileName;
1481         SceneManager* pSceneManager = null;
1482         pSceneManager = SceneManager::GetInstance();
1483
1484         FolderNavigationPresentationModel::SetCurrentFilePath(_rootPath);
1485         //if (_moveCopySource == MOVE_COPY_SOURCE_SUB_FOLDER)
1486         //{
1487                 String delim(L"/");
1488                 String token;
1489                 StringTokenizer strTok(_rootPath, delim);
1490                 while (strTok.HasMoreTokens())
1491                 {
1492                         strTok.GetNextToken(token);
1493                 }
1494                 fileName.Append(token);
1495                 pArg = new (std::nothrow) ArrayList();
1496                 r = pArg->Construct();
1497                 pArg->Add(&fileName);
1498         //}
1499
1500         r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pArg);
1501         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1502         return r;
1503 }
1504
1505 void
1506 SubFolderMoveCopy::OnFileManagingStart(void)
1507 {
1508         ShowFileProgressingPopup();
1509 }
1510
1511 void
1512 SubFolderMoveCopy::OnFileManagingStop(FileManagingResult fileProcessingResult)
1513 {
1514
1515 }
1516
1517 void
1518 SubFolderMoveCopy::OnFormBackRequested(Form& source)
1519 {
1520         SceneManager* pSceneManager = SceneManager::GetInstance();
1521         ArrayList* pArgs = null;
1522
1523         pArgs = new (std::nothrow) ArrayList();
1524         pArgs->Construct();
1525
1526         pArgs->Add(* new (std::nothrow) Integer(FILE_MANAGE_EDIT));
1527
1528         if (pSceneManager != null)
1529         {
1530                 pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_EDIT_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_DESTROY_OPTION_DESTROY), pArgs);
1531         }
1532         return;
1533 }
1534
1535 void
1536 SubFolderMoveCopy::LoadCreateFolderForm(void)
1537 {
1538         //Load the CreateFolder view in the current directory.
1539         AppLogDebug("ENTER");
1540         result r = E_SUCCESS;
1541         ArrayList* pArg = null;
1542         Integer* pSourceSelected = null;
1543         SceneManager* pSceneManager = null;
1544
1545         pSceneManager = SceneManager::GetInstance();
1546         //TryCatch(pSceneManager != null, , "failed to Get SceneManager instance");
1547
1548         pArg = new (std::nothrow) ArrayList();
1549         r = pArg->Construct();
1550
1551         pSourceSelected = new (std::nothrow) Integer(SELECT_CREATE_FOLDER);
1552         pArg->Add(pSourceSelected);
1553
1554         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_FOLDER_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArg);
1555         AppLogDebug("EXIT: r = %s", GetErrorMessage(r));
1556
1557         return;
1558 }
1559
1560 void
1561 SubFolderMoveCopy::OnThumbnailReceived(ThumbRequest* pThumbReq)
1562 {
1563         result res = E_SUCCESS;
1564         ArrayList*              pFileList  = null;
1565         AppLogDebug("Enter");
1566
1567
1568
1569
1570         if (_pFolderEntryPM)
1571         {
1572                 pFileList = _pFolderEntryPM->GetFolderEntryList();
1573                 if (pThumbReq != null)
1574                 {
1575                         if (pThumbReq->GetCurrentSourceForm() != _pFolderEntryPM->GetSourceForm())
1576                         {
1577                                 if (pThumbReq->pBitmap != null)
1578                                 {
1579                                         AppLogDebug("This Bitmap is not requested from same form");
1580                                         delete pThumbReq->pBitmap;
1581                                 }
1582                                 return;
1583                         }
1584                 }
1585
1586                 if (pThumbReq)
1587                 {
1588                         if (pThumbReq->iRquestId < pFileList->GetCount())
1589                         {
1590
1591                                 _pFolderEntryPM->OnThumbnailResponseReceived(pThumbReq->pBitmap, pThumbReq->iRquestId);
1592
1593                                 if (_pListView && _pListView->IsVisible())
1594                                 {
1595                                         res = _pListView->RefreshList(pThumbReq->iRquestId, LIST_REFRESH_TYPE_ITEM_MODIFY);
1596                                 }
1597                                 else if (_pIconListView && _pIconListView->IsVisible())
1598                                 {
1599                                         res = _pIconListView->RefreshList(pThumbReq->iRquestId, LIST_REFRESH_TYPE_ITEM_MODIFY);
1600                                 }
1601                         }
1602                 }
1603                 else
1604                 {
1605                         _pFolderEntryPM->OnThumbnailResponseFailed();
1606                 }
1607         }
1608         AppLogDebug("Exit %s", GetErrorMessage(res));
1609         return;
1610 }
1611