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