From 3b870337fe80e700be33a352603c3cd6af187890 Mon Sep 17 00:00:00 2001 From: chitta ranjan Date: Tue, 23 Apr 2013 21:51:57 +0900 Subject: [PATCH] Fixed issue 36011 Change-Id: I9aa24c48e33b2404886cd7f25b5f6b8f91986e55 Signed-off-by: chitta ranjan --- inc/IvImageNameEditorForm.h | 1 + src/IvImageNameEditorForm.cpp | 167 ++++++++++++++++++++++++++++++------------ 2 files changed, 123 insertions(+), 45 deletions(-) diff --git a/inc/IvImageNameEditorForm.h b/inc/IvImageNameEditorForm.h index b72eaf8..2ba3e60 100644 --- a/inc/IvImageNameEditorForm.h +++ b/inc/IvImageNameEditorForm.h @@ -63,6 +63,7 @@ public: private: int __currentIndex; int __modalMsgBoxResult; + int __textLength; Tizen::Ui::Controls::EditField* __pNameEditField; Tizen::Base::String __nameEditFieldText; Tizen::Base::String __nameEditFieldPreText; diff --git a/src/IvImageNameEditorForm.cpp b/src/IvImageNameEditorForm.cpp index 9ddbaf3..e420f7e 100644 --- a/src/IvImageNameEditorForm.cpp +++ b/src/IvImageNameEditorForm.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "IvCommonUtil.h" #include "IvImageNameEditorForm.h" #include "IvImageViewerPresentationModel.h" @@ -41,12 +42,13 @@ using namespace Tizen::Graphics; using namespace Tizen::Media; using namespace Tizen::Io; using namespace Tizen::System; +using namespace Tizen::Text; -static const int FILE_MAX_LENGTH = 255; ImageNameEditorForm::ImageNameEditorForm(void) : __currentIndex(0) , __modalMsgBoxResult(0) + , __textLength(0) , __pNameEditField(null) , __pMessageBox(null) , __pPresentationModel(null) @@ -148,12 +150,14 @@ ImageNameEditorForm::OnActionPerformed(const Control& source, int actionId) String inputString; __nameEditFieldText = __pNameEditField->GetText(); + switch (actionId) { case IDA_BUTTON_EDITFIELD_SAVE: inputString = __nameEditFieldText; + inputString.Trim(); - if (__nameEditFieldPreText == __nameEditFieldText) + if (__nameEditFieldPreText == inputString) { String msg = ResourceManager::GetString(L"IDS_MEDIABR_POP_SAME_NAME_ALREADY_IN_USE"); CreateMessage(msg); @@ -164,7 +168,7 @@ ImageNameEditorForm::OnActionPerformed(const Control& source, int actionId) { String fileName = File::GetFileName(filePath); String fileExtension = File::GetFileExtension(filePath); - String tempFileName = __nameEditFieldText + FILE_EXT_SEPARATOR + fileExtension; + String tempFileName = inputString + FILE_EXT_SEPARATOR + fileExtension; filePath.Replace(fileName, tempFileName); if (File::IsFileExist(filePath) == true) @@ -219,66 +223,134 @@ ImageNameEditorForm::OnTextValueChangeCanceled (const Control &source) void ImageNameEditorForm::OnTextValueChanged (const Control &source) { - AppLogDebug("ENTER"); + String currentInput; + String currentText; + String specialCharacters(L"/"); + String byteCountForInput; + int byteCount = 0; + int inputLength = 0; + int tempLength = 220; + int textToCheck = 0; + MessageBox messageBox; + Utf8Encoding utf8; - String filePath = __pPresentationModel->GetFilePathAt(__currentIndex); - String inputString = __pNameEditField->GetText(); - if (inputString.Contains(DIRECTORY_SEPARATOR) == true) - { - String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"); - CreateMessage(msg); - - __pNameEditField->SetText(__nameEditFieldTempText); - __pNameEditField->SetFocus(); - - return; - } + FooterItemStatus currentStatus = FOOTER_ITEM_STATUS_NORMAL; - String ext = File::GetFileExtension(filePath); + result r = E_SUCCESS; - ByteBuffer* buffer = StringUtil::StringToUtf8N(inputString); - int remaining = 0; - if (buffer != null) + if (__pNameEditField != null) { - remaining = buffer->GetRemaining(); + byteCountForInput = __pNameEditField->GetText(); + r = utf8.GetByteCount(byteCountForInput, byteCount); + AppLogDebug("result is %s",GetErrorMessage(r)); + AppLogDebug("Bye count is %d",byteCount); } - int maximumLength = FILE_MAX_LENGTH - ext.GetLength() - 1; - if (remaining >= maximumLength) + if (__pNameEditField != null) { - String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED"); - CreateMessage(msg); + currentText = __pNameEditField->GetText(); + textToCheck = currentText.GetLength() - __textLength; + if (currentText.IsEmpty()) + { + if (GetFooter() != null) + { + GetFooter()->SetItemEnabled(0, false); + GetFooter()->Invalidate(true); + } + } + else + { + if (GetFooter() != null) + { + GetFooter()->GetItemStatus(0, currentStatus); - __pNameEditField->SetText(__nameEditFieldTempText); - __pNameEditField->SetFocus(); + if (currentStatus == FOOTER_ITEM_STATUS_DISABLED) + { + GetFooter()->SetItemEnabled(0,true); + GetFooter()->Invalidate(true); + } - AppLogDebug("EXIT1(%s)", GetErrorMessage(GetLastResult())); - return; - } - __nameEditFieldTempText = inputString; + } + } - inputString.Trim(); - FooterItemStatus itemStatus; - GetFooter()->GetItemStatus(0, itemStatus); - if (inputString.GetLength() == 0) - { - if (itemStatus != FOOTER_ITEM_STATUS_DISABLED) + if (currentText.StartsWith(".", 0)) + { + String invalidCharacterString; + String validString; + String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"); + CreateMessage(msg); + validString = __pNameEditField->GetText(); + + if (validString.GetLength() > 1) + { + validString.Remove(0,1); + __pNameEditField->SetText(validString); + } + else + { + __pNameEditField->SetText(""); + + if (GetFooter() != null) + { + GetFooter()->SetItemEnabled(0, false); + GetFooter()->Invalidate(true); + } + } + __pNameEditField->ShowKeypad(); + } + + currentInput = __pNameEditField->GetText(); + + if (currentInput.Contains(specialCharacters[0])) { - GetFooter()->SetItemEnabled(0, false); + String msg = ResourceManager::GetString(L"IDS_COM_POP_INVALID_CHARACTERS"); + CreateMessage(msg); + currentInput.Replace("/",""); + __pNameEditField->SetText(currentInput); } - } - else - { - if (itemStatus == FOOTER_ITEM_STATUS_DISABLED) + + inputLength = byteCount; + if (inputLength >= tempLength) { - GetFooter()->SetItemEnabled(0, true); + String maxCharacterString; + String currentInputCharacter; + int checkByteCount = 0; + int lengthOfFinalString = 0; + int currentCharacter = 0; + + String msg = ResourceManager::GetString(L"IDS_COM_POP_MAXIMUM_NUMBER_OF_CHARACTERS_REACHED"); + CreateMessage(msg); + currentText = __pNameEditField->GetText(); + + for (currentCharacter=0;checkByteCount < tempLength;currentCharacter++) + { + currentInputCharacter.Clear(); + currentInputCharacter = currentText[currentCharacter]; + r = utf8.GetByteCount(currentInputCharacter, byteCount); + if (r != E_SUCCESS) + { + break; + } + AppLogDebug("result of byte count is %s",GetErrorMessage(r)); + checkByteCount = checkByteCount + byteCount; + lengthOfFinalString++; + } + + r = __pNameEditField->GetText().SubString(0,lengthOfFinalString,currentInput); + AppLogDebug("current input is %S",currentInput.GetPointer()); + r = __pNameEditField->SetText(currentInput); + __pNameEditField->ShowKeypad(); + return; } + + r = utf8.GetByteCount(__pNameEditField->GetText(), byteCount); + __textLength = byteCount; } - GetFooter()->Invalidate(true); + return; + - AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult())); } void @@ -288,6 +360,9 @@ ImageNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId, AppLogDebug("ENTER"); if (previousSceneId == IDSCN_IMAGE_VIEWER) { + int byteCount = 0; + Utf8Encoding utf8; + if (pArgs != null) { IEnumerator* pEnum = pArgs->GetEnumeratorN(); @@ -308,6 +383,8 @@ ImageNameEditorForm::OnSceneActivatedN(const SceneId& previousSceneId, __nameEditFieldPreText = __nameEditFieldText; __pNameEditField->SetText(__nameEditFieldText); + utf8.GetByteCount(__nameEditFieldText, byteCount); + __textLength = byteCount; __nameEditFieldTempText = __nameEditFieldText; __pNameEditField->ShowKeypad(); -- 2.7.4