3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "FileManagerForm.h"
19 #include <FSysEnvironment.h>
23 using namespace Tizen::App;
24 using namespace Tizen::Ui;
25 using namespace Tizen::Ui::Controls;
26 using namespace Tizen::Ui::Scenes;
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Media;
31 using namespace Tizen::Text;
33 FileManagerForm::FileManagerForm(void)
36 , __canChooseNew(false)
37 , __canChooseOne(true)
41 FileManagerForm::~FileManagerForm(void)
46 FileManagerForm::Initialize(const Tizen::Base::Collection::ArrayListT<Tizen::Base::String>& fileExt, bool isEditField)
48 Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
50 __fileExts.Construct(fileExt);
51 __canChooseNew = isEditField;
53 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
54 __pFolderIcon = pAppResource->GetBitmapN(L"U01_icon_folder.png");
60 FileManagerForm::OnInitializing(void)
62 if (!CreateMainList())
67 Footer* pFooter = GetFooter();
69 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
70 Form::SetFormBackEventListener(this);
72 pFooter->AddActionEventListener(*this);
78 FileManagerForm::OnTerminating(void)
85 FileManagerForm::CreateMainList(void)
87 __pList = new ListView();
91 __pEditField = new EditField();
92 __pEditField->Construct(Rectangle(30, 20, GetClientAreaBounds().width - 60, 100));
93 __pEditField->SetKeypadEnabled(false);
94 this->AddControl(__pEditField);
96 __pList->Construct(Rectangle(0, 150, GetClientAreaBounds().width, GetClientAreaBounds().height-150), true, false);
100 __pList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
102 __pList->SetItemProvider(*this);
103 __pList->AddListViewItemEventListener(*this);
110 FileManagerForm::OnActionPerformed (const Tizen::Ui::Control &source, int actionId)
112 if (actionId == ID_BUTTON_EXIT)
114 SceneManager* pSceneManager = SceneManager::GetInstance();
115 AppAssert(pSceneManager);
116 ArrayList* pList = new (std::nothrow) ArrayList;
119 String* pFolder = new String("");
123 String fileName = __pEditField->GetText();
125 if (fileName.IsEmpty() || fileName == ".xdb")
127 fileName = "default.xdb";
129 if (!fileName.EndsWith(".xdb"))
131 fileName.Append(".xdb");
134 if(fileName.GetLength() > 32)
139 msgBox.Construct(L"Warning", L"File name too long.\nPlease rename (max 32 characters supported).", MSGBOX_STYLE_OK);
140 msgBox.ShowAndWait(modalResult);
144 *pFolder = __currentPath + "/" + fileName;
146 Tizen::Text::Utf8Encoding utf8;
147 int countOfBytes = 0;
148 result res = utf8.GetByteCount(fileName,countOfBytes);
150 if(countOfBytes > 240)
155 msgBox.Construct(L"Warning", L"File name too long.\nPlease rename.", MSGBOX_STYLE_OK);
156 msgBox.ShowAndWait(modalResult);
158 if (modalResult != MSGBOX_RESULT_OK)
165 pList->Add(*pFolder);
167 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
172 *pFolder = __currentPath;
174 pList->Add(*pFolder);
176 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
182 FileManagerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
184 if ( (__currentPath + "/" ) == Tizen::System::Environment::GetMediaPath())
186 SceneManager* pSceneManager = SceneManager::GetInstance();
187 AppAssert(pSceneManager);
188 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), null /*pList*/);
193 __pList->ScrollToItem(0);
194 GetDirs(__currentPath);
196 __pList->UpdateList();
203 FileManagerForm::GetItemCount(void)
205 return __files.GetCount();
209 FileManagerForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
216 Tizen::Ui::Controls::ListItemBase*
217 FileManagerForm::CreateItem(int index, int itemWidth)
219 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
220 CustomItem* pItem = new CustomItem();
221 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 100), style);
223 Tizen::Base::String fileName;
224 __files.GetAt(index, fileName);
226 Tizen::Io::FileAttributes fileAtt;
228 if (Tizen::Io::File::GetAttributes(__currentPath + "/" + fileName, fileAtt) == E_SUCCESS)
230 if (fileAtt.IsDirectory())
232 pItem->AddElement(Rectangle(10, 10, 80, 80), ID_FORMAT_BITMAP, *__pFolderIcon, null, null);
236 result r = E_SUCCESS;
237 Tizen::Media::Image* pImage = new (std::nothrow) Image();
238 TryReturn(pImage != null, null, "Failed to create Image");
239 r = pImage->Construct();
240 TryReturn(r == E_SUCCESS, null, "Failed to construct Image");
242 Tizen::Graphics::Bitmap* pFileIcon;
244 pFileIcon = pImage->DecodeN(__currentPath + "/" + fileName, BITMAP_PIXEL_FORMAT_RGB565, 60, 60);
245 pItem->AddElement(Rectangle(10, 10, 80, 80), ID_FORMAT_BITMAP, *pFileIcon, null, null);
252 pItem->AddElement(Rectangle(110, 10, 610, 80), ID_FORMAT_STRING, fileName, true);
258 FileManagerForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &view, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
260 Tizen::Base::String fileName;
261 __files.GetAt(index, fileName);
263 if (status == LIST_ITEM_STATUS_SELECTED)
265 // Load database on click
266 if (fileName == "..")
269 __pList->ScrollToItem(0);
270 GetDirs(__currentPath);
272 else if (CheckExt(fileName))
276 __pEditField->SetText(fileName);
277 __pEditField->RequestRedraw(true);
279 else if (__canChooseOne)
281 SceneManager* pSceneManager = SceneManager::GetInstance();
282 AppAssert(pSceneManager);
283 ArrayList* pList = new (std::nothrow) ArrayList;
286 String* pFolder = new String(__currentPath + "/" + fileName);
287 pList->Add(*pFolder);
289 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
296 __pList->ScrollToItem(0);
297 GetDirs(__currentPath);
300 __pList->UpdateList();
307 FileManagerForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView &listView, int index, Tizen::Ui::Controls::SweepDirection direction)
312 FileManagerForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
317 FileManagerForm::OnItemReordered(Tizen::Ui::Controls::ListView &listView, int oldIndex, int newIndex)
322 FileManagerForm::CheckExt(Tizen::Base::String fileName)
325 const Tizen::Base::String period_symbol = ".";
326 if (E_SUCCESS != fileName.LastIndexOf(period_symbol, fileName.GetLength() - 1, period))
330 Tizen::Base::String extension;
331 if (E_SUCCESS != fileName.SubString(period + 1, extension))
336 return __fileExts.Contains(extension);
341 FileManagerForm::GetDirs(Tizen::Base::String dirPath)
343 Tizen::Io::Directory dir;
344 Tizen::Io::DirEnumerator *pDirEnum(null);
345 Tizen::Io::File file;
346 Tizen::Io::FileAttributes fileAtt;
348 if (dir.Construct(dirPath) == E_SUCCESS)
350 pDirEnum = dir.ReadN();
353 while(pDirEnum->MoveNext() == E_SUCCESS)
355 Tizen::Io::DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
356 if (CheckExt(dirEntry.GetName()) || dirEntry.IsDirectory())
358 if(dirEntry.GetName().CompareTo("..") == 0 || (Tizen::Io::File::GetAttributes(dirPath + "/" + dirEntry.GetName(), fileAtt) == E_SUCCESS && !fileAtt.IsHidden()))
360 __files.Add(dirEntry.GetName());
365 StrComparer* pStrComparer = new StrComparer();
366 __files.Sort(*pStrComparer);
371 String mediaPath = Tizen::System::Environment::GetMediaPath();
372 if (mediaPath.EndsWith("/"))
374 mediaPath.Remove(mediaPath.GetLength() - 1, 1);
376 if (dirPath.CompareTo("/") == 0 || dirPath.CompareTo(mediaPath) == 0)
378 __files.Remove("..");
382 else if (Tizen::Io::File::GetAttributes(dirPath, fileAtt) == E_SUCCESS)
391 FileManagerForm::GoDownDir(void)
393 int separator_pos = 0;
394 const Tizen::Base::String separator_symbol = "/";
395 if (E_SUCCESS != __currentPath.LastIndexOf(separator_symbol, __currentPath.GetLength() - 1, separator_pos))
399 if (E_SUCCESS != __currentPath.SubString(0, separator_pos, __currentPath))
403 if (__currentPath.IsEmpty())
410 __pEditField->RequestRedraw(true);
415 FileManagerForm::GoUpDir(Tizen::Base::String dir)
417 if (!__currentPath.Equals(L"/", false))
419 __currentPath += "/";
421 __currentPath += dir;
425 __pEditField->RequestRedraw(true);
430 FileManagerForm::IsFile(Tizen::Base::String filePath)
432 Tizen::Io::File file;
433 Tizen::Io::FileAttributes fileAtt;
434 return Tizen::Io::File::GetAttributes(filePath, fileAtt) == E_SUCCESS;
438 FileManagerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
439 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
442 Footer* pFooter = GetFooter();
443 pFooter->RemoveAllButtons();
444 pFooter->SetBackButton();
446 if (currentSceneId == "ChooseImageScene")
448 FooterItem footerItemChooseFolder;
449 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
450 footerItemChooseFolder.SetText("Choose");
451 pFooter->AddItem(footerItemChooseFolder);
453 else if (currentSceneId == "ChooseNewFeatureSetScene")
455 __pEditField->SetKeypadEnabled(true);
456 FooterItem footerItemChooseFolder;
457 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
458 footerItemChooseFolder.SetText("Create");
459 pFooter->AddItem(footerItemChooseFolder);
461 else if (currentSceneId == "ChooseExistingFeatureSetScene")
463 pFooter-> SetShowState(true);
466 __currentPath = Tizen::System::Environment::GetMediaPath();
467 if (__currentPath.EndsWith("/"))
469 __currentPath.Remove(__currentPath.GetLength() - 1, 1);
471 __pList->ScrollToItem(0);
472 GetDirs(__currentPath);
473 __pList->UpdateList();
477 FileManagerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
478 const Tizen::Ui::Scenes::SceneId& nextSceneId)