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