2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file GlAlbumNameEditorForm.cpp
19 * @brief This is the implementation file for AlbumNameEditorForm class.
23 #include "GlAlbumInfo.h"
24 #include "GlAlbumNameEditorForm.h"
25 #include "GlAlbumListPresentationModel.h"
26 #include "GlFileListPresentationModel.h"
27 #include "GlResourceManager.h"
29 #include "GlFileMoveTimer.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Content;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::Io;
40 using namespace Tizen::System;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
45 static const Rectangle RECT_NAME_EDIT_FIELD (0, 0, 720, 100);
46 static const unsigned int COLOR_NAME_EDIT_FIELD = Color32<255, 255, 255>::Value;
47 static const int ALBUM_MAX_LENGTH = 255;
49 AlbumNameEditorForm::AlbumNameEditorForm()
50 : __pNameEditField(null)
52 , __albumNameEditorMode(ALBUM_NAME_EDITOR_MODE_RENAME)
54 , __pPresentationModel(null)
55 , __pFilePresentationModel(null)
56 , __pMoveIndexList(null)
61 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
64 AlbumNameEditorForm::~AlbumNameEditorForm()
68 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72 AlbumNameEditorForm::Initialize(void)
75 result r = Construct(FORM_STYLE_HEADER | FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
76 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
82 AlbumNameEditorForm::OnInitializing(void)
85 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
86 __pFilePresentationModel = FileListPresentationModel::GetInstance();
91 AlbumNameEditorForm::OnTextValueChanged(const Control& source)
94 String inputString = __pNameEditField->GetText();
96 if (inputString.Contains(DIRECTORY_SEPARATOR) == true)
98 if (__pMessageBox == null)
100 __pMessageBox = new (std::nothrow) MessageBox();
101 __pMessageBox->Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"),
102 MSGBOX_STYLE_NONE, 3000);
105 __pMessageBox->ShowAndWait(modalResult);
106 __overlayMsg = false;
107 delete __pMessageBox;
108 __pMessageBox = null;
111 __pNameEditField->SetText(__nameEditFieldTempText);
112 __pNameEditField->SetFocus();
117 ByteBuffer* buffer = StringUtil::StringToUtf8N(inputString);
121 remaining = buffer->GetRemaining();
124 if (remaining >= ALBUM_MAX_LENGTH)
126 if (__pMessageBox == null)
128 __pMessageBox = new (std::nothrow) MessageBox();
129 __pMessageBox->Construct(L"",
130 ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED"),
131 MSGBOX_STYLE_NONE, 3000);
133 __pMessageBox->ShowAndWait(modalResult);
134 delete __pMessageBox;
135 __pMessageBox = null;
138 __pNameEditField->SetText(__nameEditFieldTempText);
139 __pNameEditField->SetFocus();
143 __nameEditFieldTempText = inputString;
147 Header* header = GetHeader();
148 HeaderItemStatus itemStatus;
149 header->GetItemStatus(0, itemStatus);
150 if (inputString.GetLength() == 0)
152 if (itemStatus != HEADER_ITEM_STATUS_DISABLED)
154 header->SetItemEnabled(0, false);
155 header->RequestRedraw(true);
160 if (itemStatus == HEADER_ITEM_STATUS_DISABLED)
162 header->SetItemEnabled(0, true);
163 header->RequestRedraw(true);
166 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
170 AlbumNameEditorForm::OnTextValueChangeCanceled(const Control& source)
172 AppLogDebug("ENTER");
173 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
177 AlbumNameEditorForm::OnTerminating(void)
179 AppLogDebug("ENTER");
180 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
185 void AlbumNameEditorForm::OnFileOpInvalidate(enum FileActionMode actionId)
190 void AlbumNameEditorForm::OnFileOpComplete(enum FileActionMode actionId, enum FileActionCompleteRes res)
192 __overlayMsg = false;
193 if (res != COMPLETE_SUCCESS)
195 __pNameEditField->SetText(__nameEditFieldPreText);
196 __pNameEditField->HideKeypad();
197 __pNameEditField->Draw();
198 SceneManager* pSceneManager = SceneManager::GetInstance();
199 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
204 AlbumNameEditorForm::OnActionPerformed(const Control& source, int actionId)
206 AppLogDebug("ENTER");
207 SceneManager* pSceneManager = SceneManager::GetInstance();
211 __nameEditFieldText = __pNameEditField->GetText();
213 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_RENAME)
215 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
216 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
217 pPath = pAlbumInfo->GetDirectory(0);
223 case ACTION_ID_BUTTON_CREATE_NAME_DONE:
225 __pNameEditField->HideKeypad();
226 __pNameEditField->RequestRedraw();
227 pPath.Append(Tizen::System::Environment::GetMediaPath());
228 pPath.Append(__nameEditFieldText);
230 if (__previousSceneId != IDSCN_ALL_LIST_EDITOR && __previousSceneId != IDSCN_ALL_LIST_SELECTION)
232 Directory::Create( pPath, true);
235 __nameEditFieldPreText = __nameEditFieldText;
237 argsList.Construct();
238 argsList.Add(new (std::nothrow) String(pPath));
243 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
244 delete __pMoveIndexList;
245 __pMoveIndexList = null;
249 if (__pMoveIndexList == null || __pMoveIndexList->GetCount() <= 0)
251 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
252 delete __pMoveIndexList;
253 __pMoveIndexList = null;
258 GetMoveFileIndexList(pPath, __pMoveIndexList, __pFilePresentationModel);
259 __pFileMove = new FileMoveTimer(pPath, __pMoveIndexList,
260 __pFilePresentationModel,
262 result r = __pFileMove->StartTimer();
268 __pNameEditField->SetText(__nameEditFieldPreText);
269 __pNameEditField->HideKeypad();
270 __pNameEditField->Draw();
271 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
278 AppLogDebug("MoveToContentFileList content failed (%s)", GetErrorMessage(r));
282 case ACTION_ID_BUTTON_CREATE_NAME_CANCEL:
284 __pNameEditField->SetText(__nameEditFieldPreText);
285 __pNameEditField->HideKeypad();
286 __pNameEditField->Draw();
287 pSceneManager->GoBackward(BackwardSceneTransition(__callerSceneId));
294 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
298 AlbumNameEditorForm::OnFormBackRequested(Form& source)
300 AppLogDebug("ENTER");
301 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
303 SceneManager* pSceneManager = SceneManager::GetInstance();
304 pSceneManager->GoForward(ForwardSceneTransition(__callerSceneId));
308 SceneManager* pSceneManager = SceneManager::GetInstance();
309 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST_EDITOR));
311 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
315 AlbumNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId,
316 const SceneId& currentSceneId, IList* pArgs)
318 AppLogDebug("ENTER");
319 __pPresentationModel = AlbumListPresentationModel::GetInstance();
320 __previousSceneId = previousSceneId;
322 if (previousSceneId == IDSCN_ALBUM_LIST_EDITOR)
326 IEnumerator* pEnum = pArgs->GetEnumeratorN();
327 if (pEnum->MoveNext() == E_SUCCESS)
329 Integer *index = static_cast<Integer*>(pEnum->GetCurrent());
332 __folderIndex = index->ToInt();
340 if (previousSceneId == IDSCN_ALL_LIST_EDITOR
341 || previousSceneId == IDSCN_IMAGE_LIST_EDITOR
342 || previousSceneId == IDSCN_VIDEO_LIST_EDITOR
343 || previousSceneId == IDSCN_ALL_LIST_SELECTION)
345 if (previousSceneId == IDSCN_ALL_LIST_EDITOR)
347 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_EDITOR");
349 else if (previousSceneId == IDSCN_ALL_LIST_SELECTION)
351 AppLogDebug("[MOVE] previousSceneId = IDSCN_ALL_LIST_SELECTION");
354 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_CREATE;
355 __callerSceneId = previousSceneId;
359 __albumNameEditorMode = ALBUM_NAME_EDITOR_MODE_RENAME;
360 __callerSceneId = EMPTY_SPACE;
363 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
365 Header* pHeader = GetHeader();
367 pHeader->SetStyle(HEADER_STYLE_BUTTON);
370 HeaderItem cancelItem;
371 doneItem.Construct(ACTION_ID_BUTTON_CREATE_NAME_DONE);
372 doneItem.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
373 cancelItem.Construct(ACTION_ID_BUTTON_CREATE_NAME_CANCEL);
374 cancelItem.SetText(ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
376 pHeader->SetStyle(HEADER_STYLE_BUTTON);
377 pHeader->AddItem(doneItem);
378 pHeader->AddItem(cancelItem);
379 pHeader->AddActionEventListener(*this);
380 pHeader->SetItemEnabled(0, false);
382 __pNameEditField = new (std::nothrow) EditField();
383 __pNameEditField->Construct(RECT_NAME_EDIT_FIELD, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY,
384 EDIT_FIELD_TITLE_STYLE_NONE, true, ALBUM_MAX_LENGTH);
385 __pNameEditField->AddTextEventListener(*this);
386 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
388 AddControl(*__pNameEditField);
389 __pNameEditField->AddActionEventListener(*this);
391 __nameEditFieldText = EMPTY_SPACE;
392 __nameEditFieldPreText = EMPTY_SPACE;
393 __pNameEditField->SetText(__nameEditFieldText);
394 __nameEditFieldTempText = __nameEditFieldText;
396 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
397 __pNameEditField->SetFocus();
402 Header* pHeader = GetHeader();
404 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CHANGE_NAME"));
405 pHeader->SetStyle(HEADER_STYLE_BUTTON);
408 HeaderItem cancelItem;
409 doneItem.Construct(ACTION_ID_BUTTON_CREATE_NAME_DONE);
410 doneItem.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
411 cancelItem.Construct(ACTION_ID_BUTTON_CREATE_NAME_CANCEL);
412 cancelItem.SetText(ResourceManager::GetString(L"IDS_COM_POP_CANCEL"));
414 pHeader->SetStyle(HEADER_STYLE_BUTTON);
415 pHeader->AddItem(doneItem);
416 pHeader->AddItem(cancelItem);
417 pHeader->AddActionEventListener(*this);
419 __pNameEditField = new (std::nothrow) EditField();
420 __pNameEditField->Construct(RECT_NAME_EDIT_FIELD, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY,
421 EDIT_FIELD_TITLE_STYLE_NONE, true, ALBUM_MAX_LENGTH);
422 __pNameEditField->AddTextEventListener(*this);
423 __pNameEditField->SetColor(EDIT_STATUS_NORMAL, COLOR_NAME_EDIT_FIELD);
425 AddControl(*__pNameEditField);
426 __pNameEditField->AddActionEventListener(*this);
429 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
430 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
432 strName = pAlbumInfo->GetAlbumName();
433 __nameEditFieldText = strName;
434 __nameEditFieldPreText = strName;
435 __pNameEditField->SetText(__nameEditFieldText);
437 __pNameEditField->SetOverlayKeypadCommandButtonVisible(false);
438 __pNameEditField->SetFocus();
441 if (__albumNameEditorMode == ALBUM_NAME_EDITOR_MODE_CREATE)
443 __nameEditFieldText = EMPTY_SPACE;
444 __nameEditFieldPreText = EMPTY_SPACE;
445 __pNameEditField->SetText(__nameEditFieldText);
449 IList* pAlbumInfoList = __pPresentationModel->GetAlbumInfoList();
450 AlbumInfo* pAlbumInfo = static_cast<AlbumInfo*>(pAlbumInfoList->GetAt(__folderIndex));
451 if (pAlbumInfo != null)
454 strName = pAlbumInfo->GetAlbumName();
456 __nameEditFieldText = strName;
457 __nameEditFieldPreText = strName;
458 __pNameEditField->SetText(__nameEditFieldText);
464 __pMoveIndexList = pArgs;
467 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
471 AlbumNameEditorForm::OnSceneDeactivated(const SceneId& currentSceneId,
472 const SceneId& nextSceneId)
474 AppLogDebug("ENTER");
475 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));