3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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>
21 using namespace Tizen::App;
22 using namespace Tizen::Ui;
23 using namespace Tizen::Ui::Controls;
24 using namespace Tizen::Ui::Scenes;
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Graphics;
29 FileManagerForm::FileManagerForm(void)
32 , __canChooseNew(false)
33 , __canChooseOne(true)
37 FileManagerForm::~FileManagerForm(void)
42 FileManagerForm::Initialize(const Tizen::Base::Collection::ArrayListT<Tizen::Base::String>& fileExt, bool isEditField)
44 Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
46 __fileExts.Construct(fileExt);
47 __canChooseNew = isEditField;
49 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
50 __pFileIcon = pAppResource->GetBitmapN(L"home_type3.png");
51 __pFolderIcon = pAppResource->GetBitmapN(L"message_type3.png");
57 FileManagerForm::OnInitializing(void)
59 if (!CreateMainList())
64 Footer* pFooter = GetFooter();
66 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
67 Form::SetFormBackEventListener(this);
69 pFooter->AddActionEventListener(*this);
75 FileManagerForm::OnTerminating(void)
82 FileManagerForm::CreateMainList(void)
84 __pList = new ListView();
88 __pEditField = new EditField();
89 __pEditField->Construct(Rectangle(30, 0, GetClientAreaBounds().width - 60, 100));
90 __pEditField->SetKeypadEnabled(false);
91 this->AddControl(*__pEditField);
93 __pList->Construct(Rectangle(0, 130, GetClientAreaBounds().width, GetClientAreaBounds().height - 130), true, false);
97 __pList->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
99 __pList->SetItemProvider(*this);
100 __pList->AddListViewItemEventListener(*this);
101 AddControl(*__pList);
107 FileManagerForm::OnActionPerformed (const Tizen::Ui::Control &source, int actionId)
109 if (actionId == ID_BUTTON_EXIT)
111 SceneManager* pSceneManager = SceneManager::GetInstance();
112 AppAssert(pSceneManager);
113 ArrayList* pList = new (std::nothrow) ArrayList;
116 String* pFolder = new String("");
119 String fileName = __pEditField->GetText();
120 if (fileName.IsEmpty())
122 fileName = "default.xdb";
124 if (!fileName.EndsWith(".xdb"))
126 fileName.Append(".xdb");
128 *pFolder = __currentPath + "/" + fileName;
132 *pFolder = __currentPath;
134 pList->Add(*pFolder);
136 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
141 FileManagerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
143 SceneManager* pSceneManager = SceneManager::GetInstance();
144 AppAssert(pSceneManager);
145 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), null /*pList*/);
150 FileManagerForm::GetItemCount(void)
152 return __files.GetCount();
156 FileManagerForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
163 Tizen::Ui::Controls::ListItemBase*
164 FileManagerForm::CreateItem(int index, int itemWidth)
166 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
167 CustomItem* pItem = new CustomItem();
168 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 100), style);
170 Tizen::Base::String fileName;
171 __files.GetAt(index, fileName);
173 Tizen::Io::FileAttributes fileAtt;
175 if (Tizen::Io::File::GetAttributes(__currentPath + "/" + fileName, fileAtt) == E_SUCCESS)
177 if (fileAtt.IsDirectory())
179 pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pFolderIcon, null, null);
183 pItem->AddElement(Rectangle(10, 20, 60, 60), ID_FORMAT_BITMAP, *__pFileIcon, null, null);
187 pItem->AddElement(Rectangle(80, 25, 720, 50), ID_FORMAT_STRING, fileName, true);
193 FileManagerForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView &view, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
195 Tizen::Base::String fileName;
196 __files.GetAt(index, fileName);
198 if (status == LIST_ITEM_STATUS_SELECTED)
200 // Load database on click
201 if (fileName == "..")
204 __pList->ScrollToItem(0);
205 GetDirs(__currentPath);
207 else if (CheckExt(fileName))
211 __pEditField->SetText(fileName);
212 __pEditField->RequestRedraw(true);
214 else if (__canChooseOne)
216 SceneManager* pSceneManager = SceneManager::GetInstance();
217 AppAssert(pSceneManager);
218 ArrayList* pList = new (std::nothrow) ArrayList;
221 String* pFolder = new String(__currentPath + "/" + fileName);
222 pList->Add(*pFolder);
224 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT), pList);
230 __pList->ScrollToItem(0);
231 GetDirs(__currentPath);
234 __pList->UpdateList();
241 FileManagerForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView &listView, int index, Tizen::Ui::Controls::SweepDirection direction)
246 FileManagerForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView &listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
251 FileManagerForm::OnItemReordered(Tizen::Ui::Controls::ListView &listView, int oldIndex, int newIndex)
256 FileManagerForm::CheckExt(Tizen::Base::String fileName)
259 const Tizen::Base::String period_symbol = ".";
260 if (E_SUCCESS != fileName.LastIndexOf(period_symbol, fileName.GetLength() - 1, period))
264 Tizen::Base::String extension;
265 if (E_SUCCESS != fileName.SubString(period + 1, extension))
270 return __fileExts.Contains(extension);
275 FileManagerForm::GetDirs(Tizen::Base::String dirPath)
277 Tizen::Io::Directory dir;
278 Tizen::Io::DirEnumerator *pDirEnum(null);
279 Tizen::Io::File file;
280 Tizen::Io::FileAttributes fileAtt;
282 if (dir.Construct(dirPath) == E_SUCCESS)
284 pDirEnum = dir.ReadN();
287 while(pDirEnum->MoveNext() == E_SUCCESS)
289 Tizen::Io::DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
290 if (CheckExt(dirEntry.GetName()) || dirEntry.IsDirectory())
292 __files.Add(dirEntry.GetName());
296 StrComparer* pStrComparer = new StrComparer();
297 __files.Sort(*pStrComparer);
302 if (dirPath.CompareTo("/") == 0)
304 __files.Remove("..");
308 else if (Tizen::Io::File::GetAttributes(dirPath, fileAtt) == E_SUCCESS)
317 FileManagerForm::GoDownDir(void)
319 int separator_pos = 0;
320 const Tizen::Base::String separator_symbol = "/";
321 if (E_SUCCESS != __currentPath.LastIndexOf(separator_symbol, __currentPath.GetLength() - 1, separator_pos))
325 if (E_SUCCESS != __currentPath.SubString(0, separator_pos, __currentPath))
329 if (__currentPath.IsEmpty())
336 __pEditField->RequestRedraw(true);
341 FileManagerForm::GoUpDir(Tizen::Base::String dir)
343 if (!__currentPath.Equals(L"/", false))
345 __currentPath += "/";
347 __currentPath += dir;
351 __pEditField->RequestRedraw(true);
356 FileManagerForm::IsFile(Tizen::Base::String filePath)
358 Tizen::Io::File file;
359 Tizen::Io::FileAttributes fileAtt;
360 return Tizen::Io::File::GetAttributes(filePath, fileAtt) == E_SUCCESS;
364 FileManagerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
365 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
368 Footer* pFooter = GetFooter();
369 pFooter->RemoveAllButtons();
370 pFooter->SetBackButton();
372 if (currentSceneId == "ChooseImageScene")
374 FooterItem footerItemChooseFolder;
375 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
376 footerItemChooseFolder.SetText("Choose");
377 pFooter->AddItem(footerItemChooseFolder);
379 else if (currentSceneId == "ChooseNewFeatureSetScene")
381 __pEditField->SetKeypadEnabled(true);
382 FooterItem footerItemChooseFolder;
383 footerItemChooseFolder.Construct(ID_BUTTON_EXIT);
384 footerItemChooseFolder.SetText("Create");
385 pFooter->AddItem(footerItemChooseFolder);
388 __currentPath = Tizen::System::Environment::GetMediaPath();
389 if (__currentPath.EndsWith("/"))
391 __currentPath.Remove(__currentPath.GetLength() - 1, 1);
393 __pList->ScrollToItem(0);
394 GetDirs(__currentPath);
395 __pList->UpdateList();
399 FileManagerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
400 const Tizen::Ui::Scenes::SceneId& nextSceneId)