NABI_Se issues resolved
[apps/osp/MyFiles.git] / src / MfSearchForm.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: SearchForm.cpp
19  * @brief: This file contains implementation of SearchForm.
20  */
21
22 #include "MfSearchForm.h"
23
24 using namespace Tizen::App;
25 using namespace Tizen::App::Package;
26 using namespace Tizen::Base;
27 using namespace Tizen::Base::Collection;
28 using namespace Tizen::Base::Utility;
29 using namespace Tizen::Content;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Io;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
35 using namespace Tizen::Ui::Scenes;
36
37 int SearchForm::searchBackSelected = 0;
38 SearchForm::SearchForm(void)
39 {
40         __pContentListFromLastView = null;
41         __pSearchedContentList = null;
42
43         __pListView = null;
44         __pSearchBar = null;
45         __pSearchPopup = null;
46         __pLabelSearching = null;
47         __pCancelSearch = null;
48         __pFolderLabel = null;
49
50         __pThumbnailManager = null;
51         __pSearchModel = null;
52
53         __searchText = L"";
54         __currentSearchDirectoryPath = L"";
55         __bIsResultList = false;
56
57         __searchedAllFolders = false;
58         __isSearchCompleted = false;
59         __isCancelClicked = false;
60         __isSearchStarted = false;
61         __bCheckArgsNull = false;
62         __isCurrentDirectoryRenamed = false;
63         __backFromAppControl = false;
64
65         __itemCount = -1;
66         __searchItemIndex = INVALID_LIST_INDEX;
67
68         __pFolderBitmap = null;
69         __pDummyImage = null;
70
71         __pDeleteConfirmationPopUp = null;
72
73         __selectedItemIndexForRename = 0;
74         __selectedItemIndexForDelete = 0;
75
76         __previouFormTab = MEMORY_TYPE_NONE;
77
78         __pCancelDeletion = null;
79         __pDelete = null;
80         __pFileProgressingCancelButton = null;
81         __pFileProgressingHeaderLabel = null;
82         __pItemContext = null;
83         __pFileProgressingPopup = null;
84         __pFileProgressingProgress = null;
85         __pFileEventManager = null;
86 }
87
88 SearchForm::~SearchForm(void)
89 {
90         AppLogDebug("Entry");
91
92         if (__pSearchedContentList != null)
93         {
94                 __pSearchedContentList->RemoveAll(true);
95                 delete __pSearchedContentList;
96         }
97
98         if (__pSearchModel != null)
99         {
100                 delete __pSearchModel;
101         }
102
103         if (__pItemContext != null)
104         {
105                 delete __pItemContext;
106         }
107
108         if (__pDeleteConfirmationPopUp != null)
109         {
110                 delete __pDeleteConfirmationPopUp;
111         }
112         if(__pFolderEntryPM != null)
113         {
114                 delete __pFolderEntryPM;
115         }
116         if (__pFileEventManager != null)
117         {
118                 delete __pFileEventManager;
119         }
120
121 }
122
123 SearchForm&
124 SearchForm::operator =(const SearchForm& pSearchForm)
125 {
126         return *this;
127 }
128
129 SearchForm::SearchForm(const SearchForm& pSearchForm)
130 {
131         __pContentListFromLastView = pSearchForm.__pContentListFromLastView;
132         __selectedItemIndexForRename = pSearchForm.__selectedItemIndexForRename;
133 }
134
135
136 bool
137 SearchForm::Initialize(void)
138 {
139         result r = Form::Construct(L"IDL_SEARCH");
140         if (r != E_SUCCESS)
141         {
142                 AppLogDebug("Form construct failed with %s", GetErrorMessage(r));
143                 return false;
144         }
145         return true;
146 }
147
148 result
149 SearchForm::OnInitializing(void)
150 {
151         AppLogDebug("ENTER::SearchForm::OnInitializing");
152         result r = E_SUCCESS;
153         String cancelButton(L"");
154
155         Bitmap* pDeleteNormalBmp = null;
156         Bitmap* pDeletePressBmp = null;
157         String renameButtonText;
158         String detailButtonText;
159         String deleteButtonText;
160         String strSearching ;
161         IListT< SceneId >* pSceneList = null;
162
163         __SelectedTab = MEMORY_TYPE_NONE;
164
165         __pFolderBitmap = AppResource::GetInstance()->GetBitmapN(IDB_FOLDER, BITMAP_PIXEL_FORMAT_ARGB8888);
166         __pDummyImage = AppResource::GetInstance()->GetBitmapN(IDB_DUMMY_IMG, BITMAP_PIXEL_FORMAT_ARGB8888);
167         AppResource::GetInstance()->GetString(L"IDS_MF_BODY_RENAME_ABB", renameButtonText);
168         AppResource::GetInstance()->GetString(L"IDS_MF_SK3_DELETE", deleteButtonText);
169         AppResource::GetInstance()->GetString(L"IDS_MF_SK_DETAILS", detailButtonText);
170
171         pDeleteNormalBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_NORMAL, 150, 72);
172         pDeletePressBmp = MfUtility::GetNinepatchedBitmapN(IDB_CONTEXT_DELETE_PRESS, 150, 72);
173
174         Footer* pFooter = GetFooter();
175         pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT);
176         pFooter->SetBackButton();
177
178         SetFormBackEventListener(this);
179         __pThumbnailManager = ThumbnailManager::GetInstance();
180         TryCatch(__pThumbnailManager != null, , "ThumbnailManager::GetInstance() failed:%s", GetErrorMessage(GetLastResult()));
181
182         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
183
184         __searchBarMode = SEARCH_BAR_MODE_INPUT;
185
186         __pSearchBar = static_cast< SearchBar* >(GetControl("IDC_SEARCHFORM_SEARCHBAR"));
187         TryCatch(__pSearchBar != null, , "__pSearchBar is Null");
188
189         __pSearchBar->AddSearchBarEventListener(*this);
190         __pSearchBar->AddTextEventListener(*this);
191         __pSearchBar->AddKeypadEventListener(*this);
192         __pSearchBar->SetShowState(true);
193
194         __pFolderEntryPM = new (std::nothrow) FolderEntryPresentationModel();
195         TryCatch(__pFolderEntryPM != null, , "Content Manager not found!");
196         __pFolderEntryPM->Construct();
197
198         __pSearchPopup = new (std::nothrow) Popup();
199         TryCatch(__pSearchPopup != null, , "Failed to allocate memory to __pSearchPopup");
200
201         r = __pSearchPopup->Construct(L"IDL_SEARCH_POPUP");
202         TryCatch(r == E_SUCCESS, , "failed to construct __pPopUpPanel");
203
204         __pLabelSearching = static_cast<Label*> (__pSearchPopup->GetControl(L"IDC_LABEL_SEARCHING"));
205         TryCatch(__pLabelSearching != null, , "Failed to get __pLabelSearching");
206
207         __pFolderLabel = static_cast<Label*> (__pSearchPopup->GetControl(L"IDC_LABEL_FOLDER"));
208         TryCatch(__pFolderLabel != null, r = GetLastResult(), "Failed to get __pFolderLabel");
209
210         __pCancelSearch = static_cast<Button*> (__pSearchPopup->GetControl(L"IDC_BUTTON_CANCEL"));
211         TryCatch(__pCancelSearch != null, , "Failed to get __pCancelSearch");
212
213         __pCancelSearch->SetActionId(IDA_BTN_POPUP_SEARCH_CANCEL);
214         __pCancelSearch->AddActionEventListener(*this);
215
216         __pSearchPopup->SetShowState(false);
217
218
219         __listViewRectangle.SetBounds(X_DEFAULT, H_SEARCH_BAR, GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR);
220
221         __pListView = static_cast< ListView* >(GetControl("IDC_SEARCHFORM_LISTVIEW"));
222         TryCatch(__pListView != null, r = GetLastResult(), "__pListView is Null");
223
224         __pListView->SetItemProvider(*this);
225         __pListView->AddListViewItemEventListener(*this);
226
227         __pSearchModel = new (std::nothrow) SearchPresentationModel();
228         TryCatch(__pSearchModel != null, r = GetLastResult(), "SearchForm::OnInitializing::Failed to allocate memory to __PSearchModel");
229
230         r = __pSearchModel->Initialize();
231         TryCatch(r == E_SUCCESS, , "SearchPresentationModel:Init()failed with %s", GetErrorMessage(GetLastResult()));
232
233         __pSearchedContentList = new (std::nothrow) ArrayList();
234         TryCatch(__pSearchedContentList != null, , "SearchForm::GetCurrentFileControl::Failed to allocate Memory to __pSearchedContentList");
235
236         r = __pSearchedContentList->Construct();
237         TryCatch(r == E_SUCCESS, , "SearchForm::GetCurrentFileControl::Failed to construct __pSearchedContentList");
238
239         __pItemContext = new (std::nothrow) ListContextItem();
240
241         r = __pItemContext->Construct();
242         TryCatch(r == E_SUCCESS, r = GetLastResult(), "Failed to construct pitemcontext");
243
244         __pItemContext->AddElement(IDA_CONTEXT_RENAME, renameButtonText);
245         __pItemContext->AddElement(IDA_CONTEXT_DETAIL, detailButtonText);
246
247         __pItemContext->AddElement(IDA_CONTEXT_DELETE,
248                         deleteButtonText,
249                         *pDeleteNormalBmp,
250                         *pDeletePressBmp,
251                         null,
252                         true);
253
254         __previousFormPath = FolderNavigationPresentationModel::GetCurrentPath();
255         __previouFormTab = FolderNavigationPresentationModel::GetStorageType();
256         pSceneList = SceneManager::GetInstance()->GetSceneHistoryN();
257         if (pSceneList != null)
258         {
259                 __previousSceneId = SceneManager::GetInstance()->GetCurrentSceneId();
260         }
261
262         GetFolderName();
263
264         if (pDeleteNormalBmp != null)
265         {
266                 delete pDeleteNormalBmp;
267                 pDeleteNormalBmp = null;
268         }
269         if (pDeletePressBmp != null)
270         {
271                 delete pDeletePressBmp;
272                 pDeletePressBmp = null;
273         }
274         AppLogDebug("Exit");
275         return r;
276
277 CATCH:
278
279         if (__pSearchBar != null)
280         {
281                 delete __pSearchBar;
282         }
283         if (__pListView != null)
284         {
285                 delete __pListView;
286         }
287         if (__pSearchModel != null)
288         {
289                 delete __pSearchModel;
290         }
291
292         delete pDeleteNormalBmp;
293
294         delete pDeletePressBmp;
295
296         AppLogDebug("EXIT::SearchForm::OnInitializing");
297         return r;
298 }
299
300 result
301 SearchForm::OnTerminating(void)
302 {
303         result r = E_SUCCESS;
304         //((MfMyFilesApp*)Application::GetInstance())->SetCurrentView(null);
305
306         if (__pFolderBitmap)
307                 delete __pFolderBitmap;
308
309         if (__pDummyImage)
310                 delete __pDummyImage;
311         return r;
312 }
313
314
315 ////////////////////////////////////////////////////////////////////////
316 // Call-back functions
317 ////////////////////////////////////////////////////////////////////////
318
319 void
320 SearchForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
321                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
322 {
323         AppLogDebug("ENTER:SearchForm::OnSceneActivatedN:%s", GetErrorMessage(GetLastResult()));
324
325         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
326
327         FolderNavigationPresentationModel::SetCurrentFilePath(__previousFormPath);
328         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
329
330 #if 0
331         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
332 #endif
333
334         SceneManager::GetInstance()->AddSceneManagerEventListener(*this);
335
336         if (pArgs != null)
337         {
338                 __bCheckArgsNull = true;
339
340                 __currentSearchDirectoryPath = FolderNavigationPresentationModel::GetCurrentPath();
341                 __SelectedTab = FolderNavigationPresentationModel::GetStorageType();
342
343                 if (__pFolderEntryPM != null)
344                 {
345                         __pFolderEntryPM->SetSourceForm(CREATE_ITEM_SOURCE_SEARCH_FORM);
346                         if (__currentSearchDirectoryPath.IsEmpty() == false)
347                         {
348                                 __pFolderEntryPM->SetFolderEntryPath(__currentSearchDirectoryPath);
349                                 __pContentListFromLastView = __pFolderEntryPM->GetFolderEntryList();
350                                 TryCatch(__pContentListFromLastView != null, , "Failed to allocate Memory to __pContentListFromLastView");
351                         }
352                 }
353                 __isSearchCompleted = false;
354                 __isSearchStarted = false;
355
356                 String topLevelPath = L"";
357
358
359                 if (__SelectedTab == MEMORY_TYPE_PHONE)
360                 {
361                         topLevelPath = __pFolderEntryPM->GetMediaPath();
362                 }
363                 else if (__SelectedTab == MEMORY_TYPE_SD_CARD)
364                 {
365                         topLevelPath = __pFolderEntryPM->GetSdCardPath();
366                 }
367
368                 if (__currentSearchDirectoryPath.GetLength() > 0 && __currentSearchDirectoryPath != topLevelPath)
369                 {
370                         AppLogDebug("SearchForm::OnSceneActivatedN:%S:%S", __currentSearchDirectoryPath.GetPointer(), topLevelPath.GetPointer());
371                         __pFolderLabel->SetText(__currentSearchDirectoryPath);
372                 }
373
374                 pArgs->RemoveAll(false);
375                 delete pArgs;
376                 pArgs = null;
377
378         }
379         else
380         {
381                 __bCheckArgsNull = false;
382         }
383
384         AppLogDebug("EXIT:SearchForm::OnSceneActivatedN");
385         return;
386
387         CATCH:
388         AppLogDebug("EXIT:SearchForm::OnSceneActivatedN");
389         return;
390
391 }
392
393 void
394 SearchForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
395                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
396 {
397         DeviceManager::RemoveAllDeviceEventListeners();
398         __pSearchBar->RemoveKeypadEventListener(*this);
399 }
400
401 void
402 SearchForm::OnFormBackRequested(Form& source)
403 {
404         TransitionScene();
405 }
406
407 void
408 SearchForm::TransitionScene(void)
409 {
410         //String rootMediaPath = BasePresentationModel::GetHomePath();
411         String rootMediaPath = BasePresentationModel::GetMediaPath();
412         SceneManager* pSceneManager = null;
413         pSceneManager = SceneManager::GetInstance();
414
415         if (__isSearchStarted == true && __isSearchCompleted == false)
416         {
417                 __pSearchModel->StopSearch();
418         }
419
420         if (__previousFormPath.CompareTo("") != 0)
421         {
422                 if (__isCurrentDirectoryRenamed == false)
423                         FolderNavigationPresentationModel::SetCurrentFilePath(__previousFormPath);
424                 FolderNavigationPresentationModel::SetStorageType(__previouFormTab);
425                 AppLogDebug("__previouspath is %S", __previousFormPath.GetPointer());
426         }
427
428         if(__pFileEventManager != null)
429                 __pFileEventManager->RemovePath(__currentSearchDirectoryPath);
430
431 //      pSceneManager->GoBackward(BackwardSceneTransition(__previousSceneId, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
432
433         if (__previousSceneId == IDSCN_SPLIT_PANEL_FORM && GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
434         {
435                 if (__previousFormPath == BasePresentationModel::GetMediaPath() || __previousFormPath == BasePresentationModel::GetSdCardPath())
436                 {
437                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ROOT_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
438                 }
439                 else
440                 {
441                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
442                 }
443         }
444         else if ((__previousSceneId == IDSCN_ROOT_DIRECTORY_FORM ||  __previousSceneId == IDSCN_SUB_DIRECTORY_FORM) && GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
445         {
446                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SPLIT_PANEL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
447         }
448         else
449         {
450                 pSceneManager->GoBackward(BackwardSceneTransition(__previousSceneId, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
451         }
452 }
453
454 void
455 SearchForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
456 {
457         int modalResult = 0;
458         CustomAppControl* pCustomAppControl = null;
459         String topLevelPath;
460         String emptySearchString;
461
462         DirectoryEntry* pFileDetails = null;
463         MessageBox messageEmptyString;
464
465         AppResource* pAppResource = null;
466
467
468         pAppResource = UiApp::GetInstance()->GetAppResource();
469         TryReturn(pAppResource != null, , "Failed to fetch AppResource");
470
471         pAppResource->GetString(L"IDS_SEARCH_STRING_CANNOT_BE_EMPTY", emptySearchString);
472
473         __pathOfSelectedFile = L"";
474
475         if (__isCancelClicked == true)
476         {
477                 return;
478         }
479         if (index == __itemCount && __searchedAllFolders == false)
480         {
481                 AppLogDebug("SearchPresentationModel::Search:%d", index);
482                 messageEmptyString.Construct(L"", emptySearchString , MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
483
484                 if (__pSearchBar->GetText().IsEmpty())
485                 {
486                         messageEmptyString.ShowAndWait(modalResult);
487                         return;
488                 }
489
490                 //Set CurrentSearchDirectory to topLevelPath and StartSearch
491                 if (__SelectedTab == MEMORY_TYPE_PHONE)
492                 {
493                         topLevelPath = __pFolderEntryPM->GetMediaPath();
494                 }
495                 else if (__SelectedTab == MEMORY_TYPE_SD_CARD)
496                 {
497                         topLevelPath = __pFolderEntryPM->GetSdCardPath();
498                 }
499                 __currentSearchDirectoryPath = topLevelPath;
500                 StartSearch();
501         }
502         else
503         {
504
505                 if (__isSearchCompleted == false && __isSearchStarted == false)
506                 {
507                         pFileDetails = static_cast< DirectoryEntry* >(__pContentListFromLastView->GetAt(index));
508                 }
509                 else
510                 {
511                         pFileDetails = static_cast< DirectoryEntry* >(__pSearchedContentList->GetAt(index));
512                 }
513                 TryCatch(pFileDetails != null, , "pFileDetails is Null")
514
515
516                 __pathOfSelectedFile = pFileDetails->GetFullFilePath();
517
518                 if (pFileDetails->IsDirectory() == true)
519                 {
520                         String fileName = pFileDetails->GetFileName();
521                         String filePath = pFileDetails->GetFullFilePath();
522                         LoadSubDirectoryForm(filePath, fileName);
523                 }
524                 else
525                 {
526                         //Else launch the corresponding AppControl.
527                         if (__pathOfSelectedFile.EndsWith(L".tpk") || __pathOfSelectedFile.EndsWith(L".wgt"))
528                         {
529                                 String* pFileUriScheme = new (std::nothrow) String(L"file://");
530                                 pFileUriScheme->Append(__pathOfSelectedFile);
531
532                                 AppControl::FindAndStart(L"http://tizen.org/appcontrol/operation/view", pFileUriScheme, null, null, null, null);
533                                 delete pFileUriScheme;
534                         }
535                         else
536                         {
537                                 String FileName = pFileDetails->GetFileName() + "." + pFileDetails->GetFileExtension();
538                                 String parentDirectoryOfSelectedFile = L"";
539                                 __pathOfSelectedFile.SubString(0, __pathOfSelectedFile.GetLength() - FileName.GetLength() , parentDirectoryOfSelectedFile);
540
541                                 pCustomAppControl = CustomAppControl::GetInstance();
542                                 if (pCustomAppControl != null)
543                                 {
544                                         pCustomAppControl->SetAppControlListener(this);
545                                         __pFileEventManager->AddPath(parentDirectoryOfSelectedFile, FILE_EVENT_TYPE_CREATE | FILE_EVENT_TYPE_MOVED_FROM | FILE_EVENT_TYPE_MOVED_TO | FILE_EVENT_TYPE_DELETE );
546                                         AppControl* pAppControlInUse = pCustomAppControl->LaunchAppControl(__pathOfSelectedFile);
547                                         if (pAppControlInUse != null)
548                                                 CustomAppControl::SetAppControlInUse(pAppControlInUse);
549                                 }
550                         }
551                 }
552         }
553
554         __selectedItemIndex = index;
555         return;
556
557         CATCH:
558         return;
559 }
560
561 void
562 SearchForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
563 {
564         //Empty Implementation.
565 }
566
567 void
568 SearchForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
569 {
570         AppLogDebug("Enter");
571         AppLogDebug("ENTER: SearchForm::OnListViewContextItemStateChanged:%d, %d, %d, %d", index, elementId, __isSearchCompleted, __isSearchStarted);
572
573         String filePath = L"";
574         DirectoryEntry* pFileDetails = null;
575
576         if (__isSearchCompleted == false)
577         {
578                 if (__isSearchStarted == true)
579                 {
580                         pFileDetails = static_cast< DirectoryEntry* >(__pSearchedContentList->GetAt(index));
581                 }
582                 else
583                 {
584                         pFileDetails = static_cast< DirectoryEntry* >(__pContentListFromLastView->GetAt(index));
585                 }
586         }
587         else
588         {
589                 pFileDetails = static_cast< DirectoryEntry* >(__pSearchedContentList->GetAt(index));
590         }
591         TryCatch(pFileDetails != null, , "SearchForm::CreateItem::pFileDetails is null");
592
593         filePath.Append(pFileDetails->GetFullFilePath());
594
595         switch (elementId)
596         {
597         case IDA_CONTEXT_DETAIL:
598         {
599                 LoadDetailForm(filePath);
600         }
601         break;
602
603         case IDA_CONTEXT_RENAME:
604         {
605                 LoadRenameForm(index, pFileDetails);
606         }
607         break;
608
609         case IDA_CONTEXT_DELETE:
610         {
611                 __selectedItemIndexForDelete = index;
612                 __fileToDelete = pFileDetails->GetFullFilePath();
613
614                 ShowDeleteConfirmationPopup();
615
616         }
617         break;
618
619         default:
620         {
621                 //Do nothing
622         }
623         break;
624         }
625
626         CATCH:
627
628         AppLogDebug("EXIT: SearchForm::OnListViewContextItemStateChanged");
629 }
630
631 int
632 SearchForm::GetItemCount(void)
633 {
634         AppLogDebug("ENTER::SearchForm::GetItemCount:%d", __isSearchCompleted);
635         int count = 0;
636
637         TryCatch(__pSearchedContentList != null, , "__pContentListFromLastView is null!")
638
639         if (__isSearchCompleted == false)
640         {
641                 if (__isSearchStarted == true)
642                         count = __pSearchedContentList->GetCount();
643                 else
644                 {
645                         if (__pContentListFromLastView != null)
646                                 count = __pContentListFromLastView->GetCount();
647                 }
648         }
649         else
650         {
651                 count = __pSearchedContentList->GetCount();
652                 String topLevelPath = L"";
653
654                 if (__SelectedTab == MEMORY_TYPE_PHONE)
655                 {
656                         topLevelPath = defaultPhoneBody;
657                         topLevelPath.Append("/");
658                 }
659                 else if (__SelectedTab == MEMORY_TYPE_SD_CARD)
660                 {
661                         topLevelPath = defaultSdCardBody;
662                         topLevelPath.Append("/");
663                 }
664
665                 if (__currentSearchDirectoryPath != topLevelPath && __searchedAllFolders == false)
666                 {
667                         __itemCount = count++;
668                 }
669         }
670         AppLogDebug("EXIT::SearchForm::GetItemCount:%d", count);
671         return count;
672
673         CATCH:
674         AppLogDebug("EXIT::SearchForm::GetItemCount:%d", count);
675         return count;
676 }
677
678 ListItemBase*
679 SearchForm::CreateItem(int index, int itemWidth)
680 {
681         AppLogDebug("ENTER::SearchForm::CreateItem");
682         result r = E_SUCCESS;
683         String filename;
684         String imageIconPath;
685         String strHightlightedText;
686         String filepath;
687         String cacheImagePath;
688
689         Bitmap* pFetchedCacheImage = null;
690         Bitmap* pThumbnailImage = null;
691         HashMap* pCacheList = null;
692         ContentType contentType = CONTENT_TYPE_UNKNOWN;
693
694         Dimension thumbnailDimension(H_LISTVIEW_ITEM_BITMAP, W_LISTVIEW_ITEM_BITMAP);
695         Dimension textDimension(itemWidth - H_LISTVIEW_ITEM_BITMAP, H_ITEM_LISTVIEW);
696
697         AppResource* pAppResource = null;
698         DirectoryEntry* pFileDetails = null;
699         ContentListItem* pCustomItem = null;
700         ThumbRequest* pThumbReq = null;
701
702         ArrayList* pList = null;
703
704         if (index == __itemCount && __searchedAllFolders == false)
705         {
706                 CustomItem* pItem = null;
707                 String searchAllFolder = L"";
708                 AppResource::GetInstance()->GetString(L"IDS_MF_BUTTON_SEARCH_ALL_FOLDERS", searchAllFolder);
709                 pItem = new (std::nothrow) SearchAllFoldersItem(itemWidth, H_ITEM_LISTVIEW, searchAllFolder);
710                 return pItem;
711         }
712
713         pAppResource = Application::GetInstance()->GetAppResource();
714         TryCatch(pAppResource != null, , "Resource manager not found!");
715
716         if (__isSearchCompleted == false)
717         {
718                 if (__isSearchStarted == true)
719                 {
720                         pFileDetails = static_cast< DirectoryEntry* >(__pSearchedContentList->GetAt(index));
721                 }
722                 else
723                 {
724                         if (__pContentListFromLastView != null && __pContentListFromLastView->GetCount() != 0)
725                                 pFileDetails = static_cast< DirectoryEntry* >(__pContentListFromLastView->GetAt(index));
726                 }
727         }
728         else
729         {
730                 pFileDetails = static_cast< DirectoryEntry* >(__pSearchedContentList->GetAt(index));
731         }
732         TryCatch(pFileDetails != null, , "SearchForm::Failed to get pFileDetails");
733
734         pCustomItem = new (std::nothrow) ContentListItem(itemWidth, H_ITEM_LISTVIEW, true);
735         TryCatch(pCustomItem != null, , "SearchForm::Failed to create pCustomItem");
736
737         filename.Clear();
738         filename.Append(pFileDetails->GetFileName());
739
740         filepath.Clear();
741         filepath.Append(pFileDetails->GetFullFilePath());
742
743         if (pFileDetails->IsDirectory() == false)
744         {
745                 filename.Append(".");
746                 filename.Append(pFileDetails->GetFileExtension());
747         }
748
749         if (__searchText.GetLength() > 0)
750                 strHightlightedText.Append(__searchText);
751
752         pCustomItem->SetTitle(filename, strHightlightedText);
753
754 #if 0
755         if (__pThumbnailManager != null)
756         {
757                 if (pFileDetails->IsDirectory() == true)
758                 {
759                         pListBitmap = pAppResource->GetBitmapN(L"U01_icon_folder_Cropped.png", BITMAP_PIXEL_FORMAT_ARGB8888); //pFolderImage->DecodeN(folderIconPath, BITMAP_PIXEL_FORMAT_ARGB8888);
760                         AppLogDebug("MfMyFilesApp::Decode Folder Result: %s", GetErrorMessage(GetLastResult()));
761                 }
762                 else
763                 {
764                         imageIconPath = pFileDetails->GetFullFilePath();
765                         pListBitmap = __pThumbnailManager->InitThumbnailManagerN(imageIconPath, thumbnailDimension);
766                 }
767                 TryCatch(pListBitmap != null, , "SearchForm::CreateItem::pListBitmap is null");
768         }
769 #else
770
771         contentType = ContentManagerUtil::CheckContentType(pFileDetails->GetFullFilePath());
772         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
773
774         if (pFileDetails->IsDirectory() == true)
775         {
776                 pCustomItem->SetThumbnail(__pFolderBitmap);
777         }
778         else
779         {
780                 if (pFileDetails->GetBitmap() == null)
781                 {
782                         if (pCacheList != null && (contentType == CONTENT_TYPE_IMAGE || contentType == CONTENT_TYPE_VIDEO))
783                         {
784                                 if (pFileDetails != null)
785                                 {
786                                         cacheImagePath = pFileDetails->GetFullFilePath();
787                                         AppLogDebug("cache path is %S",cacheImagePath.GetPointer());
788                                 }
789
790                                 if ((pCacheList->GetValue(cacheImagePath)) != null)
791                                 {
792                                         pFetchedCacheImage = static_cast< Bitmap* >(pCacheList->GetValue(cacheImagePath));
793                                 }
794                         }
795
796                         if (pFetchedCacheImage != null)
797                         {
798                                 AppLogDebug("image taken from cachemanager");
799                                 pThumbnailImage = CacheManager::GetInstance()->GetCacheBitmapN(cacheImagePath);
800                                 pCustomItem->SetThumbnail(pThumbnailImage);
801                         }
802                         else
803                         {
804                         pCustomItem->SetThumbnail(__pDummyImage);
805
806                         pThumbReq = new (std::nothrow) ThumbRequest(CREATE_ITEM_SOURCE_SEARCH_FORM);
807                         TryCatch(pThumbReq != null, , "ThumbRequest is null!");
808
809                         pThumbReq->iRquestId = index;
810                         pThumbReq->FilePath = pFileDetails->GetFullFilePath();
811
812                         pList = new (std::nothrow) ArrayList();
813                         TryCatch(pList != null, , "Failed to create pList");
814
815                         r = pList->Construct();
816                         TryCatch(r == E_SUCCESS, , "Failed to construct pList");
817
818                         r = pList->Add(pThumbReq);
819                         TryCatch(r == E_SUCCESS, , "Failed to add object to  pList");
820
821                         __pThumbnailManager->SendUserEvent(ThumbnailManager::THUMB_MGR_GET_THUMBNAIL, pList);
822                         }
823                 }
824                 else
825                 {
826                         pCustomItem->SetThumbnail(pFileDetails->GetBitmap());
827                 }
828         }
829 #endif
830
831         pCustomItem->SetListAnnexStyle(ANNEX_STYLE_NORMAL);
832
833         if (__bIsResultList)
834         {
835                 GetParentFolderPath(&filepath);
836                 pCustomItem->SetFilepath(filepath);
837                 pCustomItem->MakeSearchFormListItem();
838         }
839         else
840         {
841                 pCustomItem->Make();
842         }       pCustomItem->SetContextItem(__pItemContext);
843
844         AppLogDebug("EXIT::SearchForm::CreateItem");
845         return pCustomItem;
846
847 CATCH:
848         if (pCustomItem != null)
849         {
850                 delete pCustomItem;
851         }
852         if (pList != null)
853         {
854                 delete pList;
855         }
856         if (pThumbReq)
857         {
858                 delete pThumbReq;
859         }
860         AppLogDebug("EXIT::SearchForm::CreateItem");
861         return null;
862 }
863
864 bool
865 SearchForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
866 {
867         AppLogDebug("ENTER::SearchForm::DeleteItem");
868         if (pItem != null)
869         {
870                 delete pItem;
871                 pItem = null;
872         }
873         AppLogDebug("EXIT::SearchForm::DeleteItem");
874         return true;
875 }
876
877 void
878 SearchForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
879 {
880         AppLogDebug("Enter:SearchForm::OnKeypadActionPerformed");
881         int modalResult = 0;
882         String emptySearchString;
883
884         MessageBox messageEmptyString;
885         AppResource* pAppResource = null;
886
887         pAppResource = UiApp::GetInstance()->GetAppResource();
888         TryReturn(pAppResource != null, , "Failed to fetch AppResource");
889
890         pAppResource->GetString(L"IDS_SEARCH_STRING_CANNOT_BE_EMPTY", emptySearchString);
891
892         messageEmptyString.Construct(L"", emptySearchString, MSGBOX_STYLE_NONE, ID_MESSAGE_BOX_TIMEOUT_ONE_SECOND);
893
894
895         if (__pSearchBar->GetText().IsEmpty())
896         {
897                 messageEmptyString.ShowAndWait(modalResult);
898                 __pSearchBar->ShowKeypad();
899                 return;
900         }
901
902         __isCancelClicked = false;
903
904         //Get the text entered in SearchBar
905         __searchText.Clear();
906         __searchText = __pSearchBar->GetText();
907
908         //Start Searching
909         if (__searchText.IsEmpty() == false)
910                 StartSearch();
911
912         AppLogDebug("Exit::SearchForm::OnKeypadActionPerformed");
913 }
914 void
915 SearchForm::OnKeypadClosed(Tizen::Ui::Control& source)
916 {
917         AppLogDebug("ENTER::SearchForm::OnKeypadClosed");
918
919         __pSearchBar->SetContentAreaSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
920         __pListView->SetSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
921
922         AppLogDebug("EXIT::SearchForm::OnKeypadClosed");
923 }
924 void
925 SearchForm::OnKeypadOpened(Tizen::Ui::Control& source)
926 {
927         SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
928
929         __pSearchBar->SetContentAreaSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
930         __pListView->SetSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
931
932 }
933 void
934 SearchForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
935 {
936         //Empty Implementation
937 }
938 void
939 SearchForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
940 {
941         AppLogDebug("ENTER::SearchForm::OnActionPerformed");
942         switch (actionId)
943         {
944         case IDA_BTN_POPUP_SEARCH_CANCEL:
945         {
946                 AppLogDebug("SearchForm::OnSearchBarModeChanged:Search Cancelled");
947                 __isSearchCompleted = true;
948
949                 __pSearchModel->StopSearch();
950
951                 __searchBarMode = SEARCH_BAR_MODE_NORMAL;
952                 __pSearchBar->SetMode(__searchBarMode);
953                 __pSearchBar->HideKeypad();
954
955                 __pSearchPopup->SetShowState(false);
956                 __pSearchBar->SetEnabled(true);
957                 __pSearchBar->SetText(__searchText);
958
959                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
960                 __searchText.Clear();
961
962         }
963         break;
964
965         case IDA_DELETE_FILE:
966         {
967                 HideDeleteConfirmationPopup();
968                 //Call the DeleteFile Function.
969                 DeleteFile(__fileToDelete);
970         }
971         break;
972
973         case IDA_CANCEL_DELETION:
974         {
975                 HideDeleteConfirmationPopup();
976         }
977         break;
978
979         default:
980         {
981                 //Do nothing
982         }
983         break;
984         }
985         AppLogDebug("EXIT::SearchForm::OnActionPerformed");
986 }
987 void
988 SearchForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
989 {
990         AppLogDebug("ENTER::SearchForm::OnTextValueChangeCanceled");
991         if (__pSearchPopup->GetShowState() == true)
992         {
993                 __pSearchPopup->SetShowState(false);
994                 __pSearchBar->SetEnabled(true);
995         }
996 }
997
998 void
999 SearchForm::OnTextValueChanged(const Tizen::Ui::Control& source)
1000 {
1001         //Empty Implementation.
1002 }
1003
1004 //SearchBar Control
1005 void
1006 SearchForm::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
1007 {
1008         AppLogDebug("SearchForm::OnSearchBarModeChanged");
1009
1010         if (mode == SEARCH_BAR_MODE_INPUT)
1011         {
1012                 __searchBarMode = SEARCH_BAR_MODE_INPUT;
1013                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1014         }
1015         else
1016         {
1017                 __searchBarMode = SEARCH_BAR_MODE_NORMAL;
1018                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1019                 if (__isSearchStarted == true)
1020                 {
1021                         if (__isSearchCompleted == false)
1022                         {
1023                                 //Stop Search Thread
1024                                 __pSearchModel->StopSearch();
1025
1026                                 //Hide keypad of SearchBar
1027                                 __pSearchBar->HideKeypad();
1028
1029                                 //Hide popUp
1030                                 if (__pSearchPopup != null)
1031                                 {
1032                                         __pSearchPopup->SetShowState(false);
1033                                 }
1034                         }
1035                 }
1036                 __pListView->UpdateList();
1037         }
1038
1039         __pSearchBar->SetContentAreaSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
1040         __pListView->SetSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
1041
1042         __pSearchBar->Invalidate(true);
1043 }
1044
1045 void
1046 SearchForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
1047 {
1048         CustomAppControl::GetInstance()->SetAppControlInUse(null);
1049         ContentType contentType = ContentManagerUtil::CheckContentType(__pathOfSelectedFile);
1050
1051         __pSearchBar->SetMode(__searchBarMode);
1052
1053         if (GetLastResult() == E_FILE_NOT_FOUND)
1054         {
1055                 __isSearchCompleted = false;
1056                 if (__searchText.IsEmpty() == false)
1057                         StartSearch();
1058         }
1059         else
1060         {
1061                 AppLogDebug("OnAppControlResponseReceived:ContentType:%s:%d", GetErrorMessage(GetLastResult()), contentType);
1062         }
1063
1064         if (__pListView != null)
1065                 __pListView->UpdateList();
1066 }
1067
1068 void
1069 SearchForm::OnNotificationReceived(Tizen::Base::Collection::ArrayList* pArgs)
1070 {
1071         AppLogDebug("ENTER::SearchForm::GetCurrentFileControl");
1072         result r = E_FAILURE;
1073         Integer* pEventType = null;
1074         DirectoryEntry* pResultDirEntry = null;
1075         HashMap* pCacheList = null;
1076         DirectoryEntry* pCurrentEntry = null;
1077         bool cacheKeyStatus = false;
1078         String cachePath;
1079
1080         TryCatch(pArgs != null, , "SearchForm::GetCurrentFileControl::pArg is null");
1081
1082         pEventType = static_cast< Integer* >(pArgs->GetAt(0));
1083         TryCatch(pEventType != null, , "SearchForm::GetCurrentFileControl::pArg is null");
1084
1085         switch (pEventType->ToInt())
1086         {
1087         case ID_FOLDER_SEARCH_STARTED:
1088         {
1089                 String* pFolderSearchResult = (String*) pArgs->GetAt(1);
1090                 TryCatch(pFolderSearchResult != null, , "SearchForm::GetCurrentFileControl::folderSearchResult is null");
1091
1092                 String defMediaPath(L"/opt/usr/media");
1093                 String defSdCardPath(L"/opt/storage/sdcard");
1094
1095                 String displayPhone = defaultPhoneBody;
1096                 String displaySdCard = defaultSdCardBody;
1097
1098
1099                 if (pFolderSearchResult->IsEmpty() == false)
1100                 {
1101                         if (pFolderSearchResult->StartsWith(defMediaPath, 0))
1102                         {
1103                                 pFolderSearchResult->Replace(defMediaPath, displayPhone);
1104                         }
1105                         else if (pFolderSearchResult->StartsWith(defSdCardPath, 0))
1106                         {
1107                                 pFolderSearchResult->Replace(defSdCardPath, displaySdCard);
1108                         }
1109
1110                         __pFolderLabel->SetText(*pFolderSearchResult);
1111                         __pFolderLabel->Invalidate(true);
1112                 }
1113         }
1114         break;
1115
1116         case ID_SEARCH_COMPLETED:
1117         {
1118                 AppLogDebug("ENTER::SearchForm::GetCurrentFileControl:Search Completed");
1119                 __isSearchCompleted = true;
1120
1121                 __pSearchPopup->SetShowState(false);
1122                 __pSearchBar->SetEnabled(true);
1123
1124                 __pSearchModel->StopSearch();
1125
1126                 if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
1127                 {
1128                         __searchBarMode = SEARCH_BAR_MODE_NORMAL;
1129                         __pSearchBar->SetMode(__searchBarMode);
1130                         __pSearchBar->SetText(__searchText);
1131                 }
1132
1133                 //Scroll the List to top
1134                 __pListView->ScrollToItem(0);
1135         }
1136         break;
1137
1138         case ID_SEARCH_RESULT_FOUND:
1139         {
1140                 AppLogDebug("ENTER::SearchForm::GetCurrentFileControl:ID_SEARCH_RESULT_FOUND");
1141                 __isSearchCompleted = false;
1142                 __searchItemIndex++;
1143                 AppLogDebug("ItemCount::%d", __searchItemIndex);
1144
1145                 __pSearchBar->SetText(__searchText);
1146
1147                 DirectoryEntry* pSearchResult = static_cast< DirectoryEntry* >(pArgs->GetAt(1));
1148                 TryCatch(pSearchResult != null, , "GetCurrentFileControl::pSearchResult is null");
1149
1150                 AppLogDebug("ItemCount::%S", pSearchResult->GetFileName().GetPointer());
1151
1152                 pResultDirEntry = new (std::nothrow) DirectoryEntry(*pSearchResult);
1153                 r = __pSearchedContentList->InsertAt(pResultDirEntry, __searchItemIndex);
1154
1155                 AppLogDebug("Check Insert to SearchedContentList Result: %s", GetErrorMessage(r));
1156
1157                 TryCatch(r == E_SUCCESS, , "GetCurrentFileControl::Failed to add items to  __pSearchedContentList");
1158
1159                 AppLogDebug("Check SearchItemIndex: %d", __searchItemIndex);
1160
1161                 __bIsResultList = true;
1162
1163                 result res = __pListView->RefreshList(__searchItemIndex, LIST_REFRESH_TYPE_ITEM_ADD);
1164                 AppLogDebug("Check Refresh List Result: %s", GetErrorMessage(res));
1165         }
1166         break;
1167
1168         case FILE_MANAGING_RESULT_DELETING_SUCCESS:
1169         {
1170                 AppLogDebug("FILE_MANAGING_RESULT_DELETING_SUCCESS");
1171                 HideFileProgressingPopup();
1172                 pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1173
1174                 if (__isSearchCompleted == true || __isSearchStarted == true)
1175                 {
1176                         pCurrentEntry = static_cast<DirectoryEntry*>(__pSearchedContentList->GetAt(__selectedItemIndexForDelete));
1177
1178                         if (pCurrentEntry != null)
1179                         {
1180                                 cachePath = pCurrentEntry->GetFullFilePath();
1181                         }
1182
1183                         if (pCacheList != null)
1184                         {
1185                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1186                                 if (cacheKeyStatus)
1187                                 {
1188                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1189                                 }
1190                         }
1191                         __pSearchedContentList->RemoveAt(__selectedItemIndexForDelete, true);
1192                 }
1193                 else
1194                 {
1195                         pCurrentEntry = static_cast<DirectoryEntry*>(__pContentListFromLastView->GetAt(__selectedItemIndexForDelete));
1196
1197                         if (pCurrentEntry != null)
1198                         {
1199                                 cachePath = pCurrentEntry->GetFullFilePath();
1200                         }
1201
1202                         if (pCacheList != null)
1203                         {
1204                                 cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1205                                 if (cacheKeyStatus)
1206                                 {
1207                                         CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1208                                 }
1209                         }
1210                         __pContentListFromLastView->RemoveAt(__selectedItemIndexForDelete, false);
1211                 }
1212                 __pListView->UpdateList();
1213
1214         }
1215         break;
1216
1217         default:
1218                 break;
1219         }
1220
1221         pArgs->RemoveAll(true);
1222         delete pArgs;
1223         pArgs = null;
1224
1225         AppLogDebug("EXIT::SearchForm::GetCurrentFileControl");
1226         return;
1227
1228         CATCH:
1229
1230         AppLogDebug("EXIT::SearchForm::GetCurrentFileControl");
1231         return;
1232 }
1233
1234 void
1235 SearchForm::OnFolderSearchStarted(Tizen::Base::String& folderName)
1236 {
1237         //Empty Implementation
1238 }
1239
1240 void
1241 SearchForm::OnAllFoldersSearchCompleted(void)
1242 {
1243         //Empty Implementation
1244 }
1245
1246 void
1247 SearchForm::LoadSubDirectoryForm(Tizen::Base::String& fullPath, Tizen::Base::String& fileName)
1248 {
1249         result r = E_SUCCESS;
1250         ArrayList* pArg = null;
1251         SceneManager* pSceneManager = null;
1252
1253         //SetStorageType
1254         if (fullPath.Contains(BasePresentationModel::GetMediaPath()) == true)
1255         {
1256                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_PHONE);
1257         }
1258         else if (fullPath.Contains(BasePresentationModel::GetSdCardPath()) == true)
1259         {
1260                 FolderNavigationPresentationModel::SetStorageType(MEMORY_TYPE_SD_CARD);
1261         }
1262         //SetCurrentFilePath
1263         FolderNavigationPresentationModel::SetCurrentFilePath(fullPath);
1264
1265         pArg = new (std::nothrow) ArrayList();
1266         TryCatch(pArg != null, , "SearchForm::LoadSubDirectoryForm::Failed to allocate Memory to pArg");
1267
1268         r = pArg->Construct();
1269         TryCatch(r == E_SUCCESS, , "SearchForm::LoadSubDirectoryForm::Failed to construct pArg");
1270
1271         pArg->Add(&fileName);
1272
1273         pSceneManager = SceneManager::GetInstance();
1274         TryCatch(pSceneManager != null, , "SceneManager::GetInstance() failed:%s", GetErrorMessage(GetLastResult()));
1275
1276         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SUB_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_ADD_HISTORY, SCENE_DESTROY_OPTION_KEEP), pArg);
1277         return;
1278
1279 CATCH:
1280         if (pArg != null)
1281         {
1282                 pArg->RemoveAll(true);
1283                 delete pArg;
1284                 pArg = null;
1285         }
1286         return;
1287
1288 }
1289 void
1290 SearchForm::OnListViewItemStateChangedNotify(ViewType viewType)
1291 {
1292         //Empty Implementation.
1293 }
1294 void
1295 SearchForm::OnThumbnailReceived(ThumbRequest* pThumbReq)
1296 {
1297         AppLogDebug("Enter:SearchForm::OnThumbnailReceived");
1298         ArrayList* pResultList = null;
1299         result res = E_SUCCESS;
1300         DirectoryEntry* pFileDetails = null;
1301
1302         TryCatch(pThumbReq != null, , "SearchForm::Thumbrequest is null");
1303
1304         if (pThumbReq != null)
1305         {
1306                 if (pThumbReq->GetCurrentSourceForm() != __pFolderEntryPM->GetSourceForm())
1307                 {
1308                         if (pThumbReq->pBitmap != null)
1309                         {
1310                                 AppLogDebug("This Bitmap is not requested from same form");
1311                                 delete pThumbReq->pBitmap;
1312                         }
1313                         return;
1314                 }
1315         }
1316
1317         if (__isSearchCompleted == false)
1318         {
1319                 if (__isSearchStarted == true)
1320                         pResultList = __pSearchedContentList;
1321                 else
1322                         pResultList = __pContentListFromLastView;
1323         }
1324         else
1325                 pResultList = __pSearchedContentList;
1326
1327         TryCatch(pResultList != null, , "SearchForm::CreateItem::pResultList is null");
1328
1329         if (pThumbReq->iRquestId < pResultList->GetCount())
1330         {
1331                 pFileDetails = static_cast< DirectoryEntry* >(pResultList->GetAt(pThumbReq->iRquestId));
1332                 TryCatch(pFileDetails != null, , "SearchForm::CreateItem::pFileDetails is null");
1333
1334                 pFileDetails->SetBitmap(pThumbReq->pBitmap);
1335                 if (__pListView && __pListView->IsVisible())
1336                 {
1337                         res = __pListView->RefreshList(pThumbReq->iRquestId, LIST_REFRESH_TYPE_ITEM_MODIFY);
1338                 }
1339         }
1340         else
1341                 AppLogDebug("Thumbnail Request is not valid");
1342
1343         AppLogDebug("Exit");
1344         return;
1345         CATCH:
1346         if (pThumbReq != null)
1347         {
1348                 if (pThumbReq->pBitmap != null)
1349                         delete pThumbReq->pBitmap;
1350         }
1351         AppLogDebug("Exit");
1352         return;
1353
1354 }
1355
1356 void
1357 SearchForm::LoadDetailForm(String& fullFilePath)
1358 {
1359         AppLogDebug("ENTER:SearchForm::LoadDetailForm:%S", fullFilePath.GetPointer());
1360         result r = E_FAILURE;
1361
1362         SceneManager* pSceneManager = null;
1363         ArrayList* pList = null;
1364         String* pFullFilePath = null;
1365
1366         FolderNavigationPresentationModel::SetCurrentFilePath(fullFilePath);
1367
1368         pList = new (std::nothrow) ArrayList();
1369         TryCatch(pList != null, , "Failed to create pList");
1370
1371         r = pList->Construct();
1372         TryCatch(r == E_SUCCESS, , "Failed to construct pList");
1373
1374         pFullFilePath = new (std::nothrow) String(fullFilePath);
1375
1376         r = pList->Add(pFullFilePath);
1377         TryCatch(r == E_SUCCESS, , "Failed to add pFullFilePath to ArrayList");
1378
1379         pSceneManager = SceneManager::GetInstance();
1380         TryCatch(pSceneManager != null, , "Failed to allocate Memory to pSceneManager");
1381
1382         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FILE_DETAIL_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
1383         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
1384         return;
1385
1386         CATCH:
1387
1388         if (pFullFilePath != null)
1389         {
1390                 delete pFullFilePath;
1391                 pFullFilePath = null;
1392         }
1393         if (pList != null)
1394         {
1395                 delete pList;
1396                 pList = null;
1397         }
1398         return;
1399 }
1400
1401 void
1402 SearchForm::LoadRenameForm(int index, DirectoryEntry* pDirectory)
1403 {
1404         AppLogDebug("ENTER");
1405         result r = E_SUCCESS;
1406
1407         ArrayList* pArg = null;
1408         Integer* pSourceSelected = null;
1409         SceneManager* pSceneManager = null;
1410
1411         __selectedItemIndexForRename = index;
1412
1413         FolderNavigationPresentationModel::SetCurrentFilePath(pDirectory->GetFullFilePath());
1414
1415         if (pDirectory->IsDirectory() == true && (__currentSearchDirectoryPath == pDirectory->GetFullFilePath()))
1416                 __isCurrentDirectoryRenamed = true;
1417
1418         pSceneManager = SceneManager::GetInstance();
1419         TryCatch(pSceneManager != null, r = GetLastResult(), "Failed to Get SceneManager instance");
1420
1421         pArg = new (std::nothrow) ArrayList;
1422         r = pArg->Construct();
1423
1424         pSourceSelected = new (std::nothrow) Integer(SELECT_RENAME);
1425         r = pArg->Add(pSourceSelected);
1426         TryCatch(r == E_SUCCESS, r = GetLastResult(), "Failed to add sourceSelected");
1427
1428         r = pArg->Add(pDirectory);
1429         TryCatch(r == E_SUCCESS, r = GetLastResult(), "Failed to add pDirectory");
1430
1431         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CREATE_FOLDER_FORM, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArg);
1432
1433         return;
1434
1435 CATCH:
1436         if (pSourceSelected != null)
1437         {
1438                 delete pSourceSelected;
1439         }
1440
1441
1442         delete pDirectory;
1443
1444         if (pArg != null)
1445         {
1446                 delete pArg;
1447                 pArg = null;
1448         }
1449         return;
1450 }
1451
1452
1453 void
1454 SearchForm::DeleteFile(String& filePath)
1455 {
1456         AppLogDebug("ENTER");
1457
1458         ((MyFilesApp*) Application::GetInstance())->SetNotifyListener(this);
1459         ((MyFilesApp*) Application::GetInstance())->SetCurrentView(this);
1460
1461         FolderEntryEditorPresentationModel* __pFileManager = FolderEntryEditorPresentationModel::GetInstance();
1462         if (__pFileManager != null)
1463         {
1464                 __pFileManager->SetFileManagingListener(this);
1465                 __pFileManager->DeleteFolderEntries(&filePath);
1466         }
1467
1468         AppLogDebug("EXIT: r = %s", GetErrorMessage(GetLastResult()));
1469 }
1470
1471
1472 void
1473 SearchForm::OnFileManagingStart(void)
1474 {
1475         AppLogDebug("Entry");
1476         ShowFileProgressingPopup();
1477 }
1478
1479 void
1480 SearchForm::OnFileManagingStop(FileManagingResult fileManagingResult)
1481 {
1482         //Empty Implementation
1483 }
1484
1485 void
1486 SearchForm::ShowFileProgressingPopup(void)
1487 {
1488         CreateFileProgressingPopup();
1489
1490         if (__pFileProgressingPopup != null)
1491         {
1492                 __pFileProgressingPopup->SetShowState(true);
1493                 __pFileProgressingPopup->Show();
1494         }
1495 }
1496
1497 void
1498 SearchForm::HideFileProgressingPopup(void)
1499 {
1500         AppLogDebug("HideFileProgressingPopup:ENTER");
1501         if (__pFileProgressingPopup != null && __pFileProgressingPopup->IsVisible())
1502         {
1503                 __pFileProgressingPopup->SetShowState(false);
1504
1505                 delete __pFileProgressingPopup;
1506                 __pFileProgressingPopup = null;
1507         }
1508 }
1509
1510 result
1511 SearchForm::CreateFileProgressingPopup(void)
1512 {
1513         AppLogDebug("ENTER");
1514         result r = E_SUCCESS;
1515         String deleting;
1516
1517         AppResource* pAppResource = null;
1518         pAppResource = UiApp::GetInstance()->GetAppResource();
1519         TryReturn(pAppResource != null, r, "Failed to fetch AppResource");
1520
1521         pAppResource->GetString(L"IDS_COM_POP_DELETING", deleting);
1522
1523         __pFileProgressingPopup = new (std::nothrow) Popup();
1524         __pFileProgressingPopup->Construct(L"IDL_FILE_PROGRESSING_POPUP");
1525
1526         __pFileProgressingCancelButton = static_cast< Button* >(__pFileProgressingPopup->GetControl(L"IDC_CANCEL_BUTTON", true));
1527         if (__pFileProgressingCancelButton != null)
1528         {
1529                 __pFileProgressingCancelButton->SetActionId(IDA_BTN_ANIMATION_POPUP_CANCEL);
1530                 __pFileProgressingCancelButton->AddActionEventListener(*this);
1531         }
1532         __pFileProgressingProgress = static_cast< Progress* >(__pFileProgressingPopup->GetControl(L"IDC_PROGRESS_BAR", true));
1533         if (__pFileProgressingProgress != null)
1534         {
1535                 __pFileProgressingProgress->SetName(L"IDC_ANIMATION_PROGRESS");
1536                 __pFileProgressingProgress->SetValue(0);
1537         }
1538         __pFileProgressingHeaderLabel = static_cast< Label* >(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_HEADER", true));
1539         if (__pFileProgressingHeaderLabel != null)
1540         {
1541                 __pFileProgressingHeaderLabel->SetName(L"IDC_ANIMATION_HEADER");
1542                 __pFileProgressingHeaderLabel->SetText(deleting);
1543         }
1544         __pFileProgressingLabel = static_cast< Label* >(__pFileProgressingPopup->GetControl(L"IDC_ANIMATION_LABEL", true));
1545         if (__pFileProgressingLabel != null)
1546         {
1547                 __pFileProgressingLabel->SetName(L"IDC_FILE_COUNT_LABEL");
1548         }
1549
1550         return r;
1551
1552 }
1553
1554 result
1555 SearchForm::CreateDeleteConfirmationPopup(void)
1556 {
1557         result r = E_SUCCESS;
1558         Rectangle popupBounds;
1559
1560         //Create a Delete popup control
1561         __pDeleteConfirmationPopUp = new (std::nothrow) Popup();
1562         __pDeleteConfirmationPopUp->Construct(L"IDL_DELETE_POPUP");
1563
1564         popupBounds = __pDeleteConfirmationPopUp->GetClientAreaBounds();
1565
1566
1567         __pDelete = static_cast< Button* >(__pDeleteConfirmationPopUp->GetControl(L"IDC_BUTTON_DELETE", true));
1568         TryCatch(__pDelete != null, , "MfMyFilesApp::Button For Popup not created!");
1569
1570         __pDelete->SetActionId(IDA_DELETE_FILE);
1571         __pDelete->AddActionEventListener(*this);
1572         __pDelete->SetShowState(true);
1573
1574         __pCancelDeletion = static_cast< Button* >(__pDeleteConfirmationPopUp->GetControl(L"IDC_BUTTON_CANCEL", true));
1575         TryCatch(__pCancelDeletion != null, , "MfMyFilesApp::Button For Popup not created!");
1576
1577         __pCancelDeletion->SetActionId(IDA_CANCEL_DELETION);
1578         __pCancelDeletion->AddActionEventListener(*this);
1579         __pCancelDeletion->SetShowState(true);
1580
1581         return r;
1582
1583 CATCH:
1584
1585         if (__pDeleteConfirmationPopUp != null)
1586         {
1587                 delete __pDeleteConfirmationPopUp;
1588                 __pDeleteConfirmationPopUp = null;
1589         }
1590
1591         return r;
1592
1593 }
1594
1595 void
1596 SearchForm::HideDeleteConfirmationPopup(void)
1597 {
1598         if (__pDeleteConfirmationPopUp != null && __pDeleteConfirmationPopUp->IsVisible())
1599         {
1600                 __pDeleteConfirmationPopUp->SetShowState(false);
1601
1602                 delete __pDeleteConfirmationPopUp;
1603                 __pDeleteConfirmationPopUp = null;
1604
1605         }
1606 }
1607
1608 void
1609 SearchForm::ShowDeleteConfirmationPopup(void)
1610 {
1611         CreateDeleteConfirmationPopup();
1612
1613         if (__pDeleteConfirmationPopUp != null)
1614         {
1615                 __pDeleteConfirmationPopUp->SetShowState(true);
1616                 __pDeleteConfirmationPopUp->Show();
1617         }
1618 }
1619
1620 void
1621 SearchForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String& state)
1622 {
1623         AppLogDebug("SearchForm::OnDeviceStateChanged");
1624
1625         HideDeleteConfirmationPopup();
1626         HideFileProgressingPopup();
1627
1628         if (__SelectedTab == MEMORY_TYPE_NONE )
1629         {
1630                 __pSearchBar->SetMode(__searchBarMode);
1631
1632                 if (__searchText.IsEmpty() == false)
1633                         StartSearch();
1634
1635                 if (__pListView != null)
1636                         __pListView->UpdateList();
1637         }
1638         else if (__SelectedTab == MEMORY_TYPE_SD_CARD )
1639         {
1640                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_TOP_LEVEL_DIRECTORY_FORM, SCENE_TRANSITION_ANIMATION_TYPE_RIGHT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), null);
1641         }
1642 }
1643
1644
1645 void
1646 SearchForm::OnSceneTransitionCompleted(const Tizen::Ui::Scenes::SceneId &previousSceneId,
1647                 const Tizen::Ui::Scenes::SceneId &currentSceneId)
1648 {
1649         SceneManager::GetInstance()->RemoveSceneManagerEventListener(*this);
1650         __pSearchBar->SetMode(__searchBarMode);
1651
1652         if (__pFileEventManager != null)
1653         {
1654                 delete __pFileEventManager;
1655                 __pFileEventManager = null;
1656
1657         }
1658         __pFileEventManager = new (std::nothrow) FileEventManager();
1659         __pFileEventManager->Construct(*this);
1660
1661         if (__bCheckArgsNull)
1662         {
1663                 if (__pListView != null)
1664                 {
1665                         __pListView->UpdateList();
1666                 }
1667         }
1668         else
1669         {
1670                 if (previousSceneId == IDSCN_CREATE_FOLDER_FORM)
1671                 {
1672                         __pListView->RefreshList(__selectedItemIndexForRename, LIST_REFRESH_TYPE_ITEM_MODIFY);
1673                 }
1674         }
1675 }
1676
1677 void
1678 SearchForm::OnSceneTransitionStarted(const Tizen::Ui::Scenes::SceneId &currentSceneId,
1679                 const Tizen::Ui::Scenes::SceneId &nextSceneId)
1680 {
1681         //Empty Implementation.
1682 }
1683
1684 void
1685 SearchForm::StartSearch(void)
1686 {
1687         String searchtext;
1688         String folderToSearch;
1689         String topLevelPath;
1690
1691         //Hide keypad of Search bar
1692         __pSearchBar->HideKeypad();
1693         __pSearchBar->SetContentAreaVisible(true);
1694         __pSearchBar->SetEnabled(false);
1695         __pSearchBar->SetMode(__searchBarMode);
1696
1697         //Show Popup if Application is in FOREGROUND
1698         if ( Application::GetInstance()->GetAppUiState() == APP_UI_STATE_FOREGROUND)
1699         {
1700                 __pFolderLabel->SetText(folderToSearch);
1701                 __pSearchPopup->SetShowState(true);
1702                 __pSearchPopup->Show();
1703         }
1704
1705         ///Set Application Notification Listener to current form
1706         ((MyFilesApp*) Application::GetInstance())->SetNotifyListener(this);
1707
1708         if (__SelectedTab == MEMORY_TYPE_PHONE)
1709         {
1710                 topLevelPath = __pFolderEntryPM->GetMediaPath();
1711         }
1712         else if (__SelectedTab == MEMORY_TYPE_SD_CARD)
1713         {
1714                 topLevelPath = __pFolderEntryPM->GetSdCardPath();
1715         }
1716
1717         if ( (__currentSearchDirectoryPath.GetLength() > 0 && __currentSearchDirectoryPath == topLevelPath ) || (FolderNavigationPresentationModel::GetCurrentPath().IsEmpty() == true))
1718         {
1719                 __searchedAllFolders = true;
1720         }
1721
1722         if (__pSearchedContentList != null)
1723         {
1724                 __pSearchedContentList->RemoveAll(true);
1725         }
1726         __searchItemIndex = INVALID_LIST_INDEX;
1727         __isSearchCompleted = false;
1728         __isSearchStarted = true;
1729
1730         __pListView->UpdateList();
1731
1732         __pSearchModel->SetFolderToSearch(__currentSearchDirectoryPath);
1733         __pSearchModel->SetStringToSearch(__searchText);
1734         __pSearchModel->Start();
1735 }
1736
1737 void
1738 SearchForm::OnFileEventOccured(const unsigned long events,const Tizen::Base::String &  path, const unsigned int eventId)
1739 {
1740         bool cacheKeyStatus = false;
1741         HashMap* pCacheList = null;
1742         DirectoryEntry* pCurrentEntry = null;
1743
1744         String cachePath;
1745
1746         ArrayList*              pCurrentList = null;
1747
1748         if ((events & FILE_EVENT_TYPE_CREATE) || (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM) || (events & FILE_EVENT_TYPE_MOVED_TO ))
1749         {
1750                 __backFromAppControl = true;
1751
1752                 //changes added for Nabi issue # N_SE-38472
1753                 if ( (events & FILE_EVENT_TYPE_DELETE) || (events & FILE_EVENT_TYPE_MOVED_FROM))
1754                 {
1755                         pCacheList = CacheManager::GetInstance()->GetCacheHashMap();
1756                         if (pCacheList != null)
1757                         {
1758                                 if (__isSearchCompleted == false)
1759                                 {
1760                                         if (__isSearchStarted == true)
1761                                                 pCurrentList = __pSearchedContentList;
1762                                         else
1763                                                 pCurrentList = __pContentListFromLastView;
1764                                 }
1765                                 else
1766                                         pCurrentList = __pSearchedContentList;
1767
1768                                 if( pCurrentList )
1769                                 {
1770                                         pCurrentEntry = static_cast<DirectoryEntry*>(pCurrentList->GetAt(__selectedItemIndex));
1771                                         if (pCurrentEntry != null)
1772                                         {
1773                                                 cachePath = pCurrentEntry->GetFullFilePath();
1774                                         }
1775                                         cacheKeyStatus = pCacheList->ContainsKey(cachePath);
1776                                         if (cacheKeyStatus)
1777                                         {
1778                                                 CacheManager::GetInstance()->RemoveCacheEntry(cachePath);
1779                                         }
1780                                 }
1781                         }
1782                 }
1783         }
1784         __selectedItemIndex  =-1;
1785 }
1786
1787 void
1788 SearchForm::GetFolderName(void)
1789 {
1790         String delim(L"/");
1791         String token;
1792         String fullPath;
1793         String folderName;
1794
1795         AppResource::GetInstance()->GetString(L"IDS_MF_SK3_SEARCH", folderName);
1796
1797         folderName.Append(L" ");
1798
1799         fullPath = FolderNavigationPresentationModel::GetCurrentPath();
1800
1801         StringTokenizer tokenizer(fullPath, delim);
1802
1803 #if 0
1804         DataBindingContext* pContext = null;
1805         pContext = GetDataBindingContextN();
1806 #endif
1807
1808         int Counter = 3;
1809
1810         //Use a string tokenizer to get the filepath until it's the last token, break the loop when
1811         //it is the last token
1812         while (tokenizer.HasMoreTokens())
1813         {
1814                 if (Counter > 0)
1815                 {
1816                         Counter--;
1817                         tokenizer.GetNextToken(token);
1818                 }
1819                 else
1820                 {
1821                         tokenizer.GetNextToken(token);
1822                         folderName.Append(token);
1823                 }
1824         }
1825
1826         if (__pSearchBar != null)
1827         {
1828                 __pSearchBar->SetGuideText(folderName);
1829         }
1830 }
1831
1832 void
1833 SearchForm::GetParentFolderPath(Tizen::Base::String* filePath)
1834 {
1835         String displayPath;
1836         String delim(L"/");
1837         String token;
1838
1839         StringTokenizer tokenizer(*filePath, delim);
1840
1841         filePath->Clear();
1842
1843         //Use a string tokenizer to get the filepath until it's the last token, break the loop when
1844         //it is the last token
1845         while (tokenizer.HasMoreTokens())
1846         {
1847                 if (tokenizer.GetTokenCount() != 1)
1848                 {
1849                         filePath->Append(L"/");
1850                         tokenizer.GetNextToken(token);
1851                         filePath->Append(token);
1852                 }
1853                 else
1854                 {
1855                         break;
1856                 }
1857         }
1858
1859         filePath->Append(L"/");
1860
1861         if (filePath->StartsWith(BasePresentationModel::GetMediaPath(),0))
1862         {
1863                 filePath->Replace(BasePresentationModel::GetMediaPath(),"Phone/",0);
1864         }
1865         else if(filePath->StartsWith(BasePresentationModel::GetSdCardPath(),0))
1866         {
1867                 filePath->Replace(BasePresentationModel::GetSdCardPath(),"Memory Card/",0);
1868         }
1869
1870 }
1871
1872 void
1873 SearchForm::OnAppControlCompleted(void)
1874 {
1875         AppLogDebug("OnAppControlCompleted++");
1876         if ( __backFromAppControl==true )
1877         {
1878                 __pSearchBar->SetMode(__searchBarMode);
1879
1880                 if (__searchText.IsEmpty() == false)
1881                         StartSearch();
1882
1883                 if (__pListView != null)
1884                         __pListView->UpdateList();
1885                 __backFromAppControl = false;
1886         }
1887         AppLogDebug("OnAppControlCompleted--");
1888 }
1889
1890 void
1891 SearchForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1892 {
1893         __pSearchBar->SetContentAreaSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
1894         __pListView->SetSize(Dimension(GetClientAreaBounds().width, GetClientAreaBounds().height - H_SEARCH_BAR));
1895 }