3 // Open Service Platform
4 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // All rights reserved.
7 // This software contains confidential and proprietary information
8 // of Samsung Electronics Co., Ltd.
9 // The user of this software agrees not to disclose, disseminate or copy such
10 // Confidential Information and shall use the software only in accordance with
11 // the terms of the license agreement the user entered into with Samsung.
14 #include "FileManagerForm.h"
15 #include <FSysEnvironment.h>
17 using namespace Tizen::App;
18 using namespace Tizen::Ui;
19 using namespace Tizen::Ui::Controls;
20 using namespace Tizen::Ui::Scenes;
21 using namespace Tizen::Base;
22 using namespace Tizen::Base::Collection;
23 using namespace Tizen::Graphics;
25 FileManagerForm::FileManagerForm(void)
28 , __canChooseNew(false)
29 , __canChooseOne(true)
33 FileManagerForm::~FileManagerForm(void)
38 FileManagerForm::Initialize(const Tizen::Base::Collection::ArrayListT<Tizen::Base::String>& fileExt, bool isEditField)
40 Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
42 __fileExts.Construct(fileExt);
43 __canChooseNew = isEditField;
45 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
46 __pFileIcon = pAppResource->GetBitmapN(L"home_type3.png");
47 __pFolderIcon = pAppResource->GetBitmapN(L"message_type3.png");
53 FileManagerForm::OnInitializing(void)
55 if (!CreateMainList())
60 Footer* pFooter = GetFooter();
62 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
63 Form::SetFormBackEventListener(this);
65 pFooter->AddActionEventListener(*this);
71 FileManagerForm::OnTerminating(void)
78 FileManagerForm::CreateMainList(void)
80 __pList = new ListView();
84 __pEditField = new EditField();
85 __pEditField->Construct(Rectangle(30, 0, GetClientAreaBounds().width - 60, 100));
86 __pEditField->SetKeypadEnabled(false);
87 this->AddControl(*__pEditField);
89 __pList->Construct(Rectangle(0, 130, GetClientAreaBounds().width, GetClientAreaBounds().height - 130), true, false);
93 __pList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
95 __pList->SetItemProvider(*this);
96 __pList->AddListViewItemEventListener(*this);
103 FileManagerForm::OnActionPerformed (const Tizen::Ui::Control &source, int actionId)
105 if (actionId == ID_BUTTON_EXIT)
107 SceneManager* pSceneManager = SceneManager::GetInstance();
108 AppAssert(pSceneManager);
109 ArrayList* pList = new (std::nothrow) ArrayList;
112 String* pFolder = new String("");
115 String fileName = __pEditField->GetText();
116 if (fileName.IsEmpty())
118 fileName = "default.xdb";
120 if (!fileName.EndsWith(".xdb"))
122 fileName.Append(".xdb");
124 *pFolder = __currentPath + "/" + fileName;
128 *pFolder = __currentPath;
130 pList->Add(*pFolder);
132 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
137 FileManagerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
139 SceneManager* pSceneManager = SceneManager::GetInstance();
140 AppAssert(pSceneManager);
141 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), null /*pList*/);
146 FileManagerForm::GetItemCount(void)
148 return __files.GetCount();
152 FileManagerForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
159 Tizen::Ui::Controls::ListItemBase*
160 FileManagerForm::CreateItem(int index, int itemWidth)
162 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
163 CustomItem* pItem = new CustomItem();
164 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 100), style);
166 Tizen::Base::String fileName;
167 __files.GetAt(index, fileName);
169 Tizen::Io::FileAttributes fileAtt;
171 if (Tizen::Io::File::GetAttributes(__currentPath + "/" + fileName, fileAtt) == E_SUCCESS)
173 if (fileAtt.IsDirectory())
175 pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pFolderIcon, null, null);
179 pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pFileIcon, null, null);
183 pItem->AddElement(Rectangle(80, 25, 720, 50), ID_FORMAT_STRING, fileName, true);
189 FileManagerForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &view, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
191 Tizen::Base::String fileName;
192 __files.GetAt(index, fileName);
194 if (status == LIST_ITEM_STATUS_SELECTED)
196 // Load database on click
197 if (fileName == "..")
200 __pList->ScrollToItem(0);
201 GetDirs(__currentPath);
203 else if (CheckExt(fileName))
207 __pEditField->SetText(fileName);
208 __pEditField->RequestRedraw(true);
210 else if (__canChooseOne)
212 SceneManager* pSceneManager = SceneManager::GetInstance();
213 AppAssert(pSceneManager);
214 ArrayList* pList = new (std::nothrow) ArrayList;
217 String* pFolder = new String(__currentPath + "/" + fileName);
218 pList->Add(*pFolder);
220 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
226 __pList->ScrollToItem(0);
227 GetDirs(__currentPath);
230 __pList->UpdateList();
237 FileManagerForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView &listView, int index, Tizen::Ui::Controls::SweepDirection direction)
242 FileManagerForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
247 FileManagerForm::OnItemReordered(Tizen::Ui::Controls::ListView &listView, int oldIndex, int newIndex)
252 FileManagerForm::CheckExt(Tizen::Base::String fileName)
255 const Tizen::Base::String period_symbol = ".";
256 if (E_SUCCESS != fileName.LastIndexOf(period_symbol, fileName.GetLength() - 1, period))
260 Tizen::Base::String extension;
261 if(E_SUCCESS != fileName.SubString(period + 1, extension))
266 return __fileExts.Contains(extension);
271 FileManagerForm::GetDirs(Tizen::Base::String dirPath)
273 Tizen::Io::Directory dir;
274 Tizen::Io::DirEnumerator *pDirEnum(null);
275 Tizen::Io::File file;
276 Tizen::Io::FileAttributes fileAtt;
278 if (dir.Construct(dirPath) == E_SUCCESS)
280 pDirEnum = dir.ReadN();
283 while(pDirEnum->MoveNext() == E_SUCCESS)
285 Tizen::Io::DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
286 if (CheckExt(dirEntry.GetName()) || dirEntry.IsDirectory())
288 __files.Add(dirEntry.GetName());
292 StrComparer* pStrComparer = new StrComparer();
293 __files.Sort(*pStrComparer);
298 if (dirPath.CompareTo("/") == 0)
300 __files.Remove("..");
304 else if (Tizen::Io::File::GetAttributes(dirPath, fileAtt) == E_SUCCESS)
313 FileManagerForm::GoDownDir(void)
315 int separator_pos = 0;
316 const Tizen::Base::String separator_symbol = "/";
317 if (E_SUCCESS != __currentPath.LastIndexOf(separator_symbol, __currentPath.GetLength() - 1, separator_pos))
321 if (E_SUCCESS != __currentPath.SubString(0, separator_pos, __currentPath))
325 if (__currentPath.IsEmpty())
332 __pEditField->RequestRedraw(true);
337 FileManagerForm::GoUpDir(Tizen::Base::String dir)
339 if (!__currentPath.Equals(L"/", false))
341 __currentPath += "/";
343 __currentPath += dir;
347 __pEditField->RequestRedraw(true);
352 FileManagerForm::IsFile(Tizen::Base::String filePath)
354 Tizen::Io::File file;
355 Tizen::Io::FileAttributes fileAtt;
356 return Tizen::Io::File::GetAttributes(filePath, fileAtt) == E_SUCCESS;
360 FileManagerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
361 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
364 Footer* pFooter = GetFooter();
365 pFooter->RemoveAllButtons();
366 pFooter->SetBackButton();
368 if (currentSceneId == "ChooseImageScene")
370 FooterItem footerItemChooseFolder;
371 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
372 footerItemChooseFolder.SetText("Choose");
373 pFooter->AddItem(footerItemChooseFolder);
375 else if (currentSceneId == "ChooseNewFeatureSetScene")
377 __pEditField->SetKeypadEnabled(true);
378 FooterItem footerItemChooseFolder;
379 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
380 footerItemChooseFolder.SetText("Create");
381 pFooter->AddItem(footerItemChooseFolder);
384 __currentPath = Tizen::System::Environment::GetMediaPath();
385 if (__currentPath.EndsWith("/"))
387 __currentPath.Remove(__currentPath.GetLength() - 1, 1);
389 __pList->ScrollToItem(0);
390 GetDirs(__currentPath);
391 __pList->UpdateList();
395 FileManagerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
396 const Tizen::Ui::Scenes::SceneId& nextSceneId)