2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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 PhnSettingsEditRejectMsgForm.cpp
19 * @brief Settings Edit reject message form
22 #include "PhnAppUtility.h"
24 #include "PhnSettingsPresentationModel.h"
25 #include "PhnSettingsEditRejectMsgForm.h"
26 #include "PhnSceneRegister.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 static const wchar_t* IDL_SETTINGS_ADD_EDIT_REJECT_MSGS_FORM = L"IDL_SETTINGS_ADD_EDIT_REJECT_MSGS_FORM";
38 SettingsEditRejectMsgForm::SettingsEditRejectMsgForm(FormMode formMode)
39 : __formMode(formMode),__pSettingsPresentor(null)
43 SettingsEditRejectMsgForm::~SettingsEditRejectMsgForm(void)
48 SettingsEditRejectMsgForm::Initialize(void)
50 Construct(IDL_SETTINGS_ADD_EDIT_REJECT_MSGS_FORM);
55 SettingsEditRejectMsgForm::OnInitializing(void)
58 int mainFontSize = AppUtility::GetSettingsItemFontSize();
59 int mainItemTextSize =AppUtility::GetSettingsMainItemSize();
60 //Initialize Header & Footer
61 InitializeHeaderAndFooter();
62 //Initialize reject message editArea
63 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA,true));
64 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
65 if (pEditMsgs != null)
67 pEditMsgs->AddTextEventListener(*this);
68 pEditMsgs->SetTextSize(mainFontSize);
69 pEditMsgs->SetSize(pEditMsgs->GetWidth(), mainItemTextSize);
76 SettingsEditRejectMsgForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
79 int mainFontSize = AppUtility::GetSettingsItemFontSize();
80 int mainItemTextSize =AppUtility::GetSettingsMainItemSize();
81 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA,true));
82 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
83 if (pEditMsgs != null)
85 pEditMsgs->SetTextSize(mainFontSize);
86 pEditMsgs->SetSize(pEditMsgs->GetWidth(), mainItemTextSize);
87 pEditMsgs->Invalidate(true);
92 SettingsEditRejectMsgForm::InitializeHeaderAndFooter(void)
94 Header* pHeader = GetHeader();
97 pHeader->SetStyle(HEADER_STYLE_TITLE);
101 case FORMMODE_NEW_MESSAGE:
103 title.Append(AppUtility::GetResourceString(IDS_SETTING_ADD_REJECT_MSG_TITLE));
107 case FORMMODE_EDIT_MESSAGE:
109 title.Append(AppUtility::GetResourceString(IDS_SETTING_EDIT_REJECT_MSG_TITLE));
113 pHeader->SetTitleText(title);
116 Footer* pFooter = GetFooter();
119 //change style to show "save" in center
120 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
124 saveItemName.Append(AppUtility::GetResourceString(IDS_SETTING_SAVE_HEADER_ITEM));
125 FooterItem saveFooterItem;
126 saveFooterItem.Construct(IDA_SAVE_FOOTER_ITEMID);
127 saveFooterItem.SetText(saveItemName);
128 pFooter->AddItem(saveFooterItem);
129 pFooter->SetItemEnabled(0,false);
132 SetFormBackEventListener(this);
134 pFooter->AddActionEventListener(*this);
139 SettingsEditRejectMsgForm::OnTerminating(void)
141 result r = E_SUCCESS;
146 SettingsEditRejectMsgForm::OnActionPerformed(const Control& source, int actionId)
148 SceneManager* pSceneManager = SceneManager::GetInstance();
149 AppAssert(pSceneManager != null);
153 case IDA_SAVE_FOOTER_ITEMID:
155 if (__itemIndex != -1)
157 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA,true));
158 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
159 if (pEditMsgs != null)
161 String rejectMsg = pEditMsgs->GetText();
163 result r = __pSettingsPresentor->SetRejectMessage(__itemIndex, rejectMsg);
164 if (r == E_OBJ_ALREADY_EXIST)
167 //show error Message box, in case of duplicate message error.
169 errorMsg.Append("\"");
170 errorMsg.Append(rejectMsg);
171 errorMsg.Append("\"\n");
172 errorMsg.Append(AppUtility::GetResourceString(IDS_DUPLICATE_REJECT_MSG_ERROR_STRING));
176 msgBox.Construct(L"", errorMsg, MSGBOX_STYLE_OK,300000);
177 msgBox.ShowAndWait(msgResult);
181 //switch back to previous form
182 pSceneManager->GoForward(
183 ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTMSGS_MENU,
184 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
185 SCENE_HISTORY_OPTION_ADD_HISTORY,
186 SCENE_DESTROY_OPTION_DESTROY), null);
196 SettingsEditRejectMsgForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
199 __editRejectMsg.Clear();
200 AddOrientationEventListener(*this);
201 int mainFontSize = AppUtility::GetSettingsItemFontSize();
202 int mainItemTextSize =AppUtility::GetSettingsMainItemSize();
203 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
204 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA,true));
205 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
206 if (pEditMsgs != null && pArgs != null)
208 __itemIndex = (static_cast<Integer*>(pArgs->GetAt(0)))->ToInt();
209 if (__formMode == FORMMODE_EDIT_MESSAGE )
211 __editRejectMsg.Append(*(static_cast<String*>(pArgs->GetAt(1))));
213 pEditMsgs->SetText(__editRejectMsg);
215 //reset limit length.Since there is issue that ExpandableEditArea takes
216 //another 80 chars each time it is opened in edit mode.
217 //int limitLength = pEditMsgs->GetLimitLength() - __editRejectMsg.GetLength();
218 //pEditMsgs->SetLimitLength(limitLength);
219 pEditMsgs->SetTextSize(mainFontSize);
220 // pEditMsgs->SetSize(pEditMsgs->GetWidth(), mainItemTextSize);
221 pEditMsgs->SetPropagatedKeyEventListener(this);
222 pEditMsgs->SetFocus();
223 pEditMsgs->Invalidate(true);
226 //Disable save button
227 Footer* pFooter = GetFooter();
230 pFooter->SetItemEnabled(0, false);
231 pFooter->Invalidate(true);
244 SettingsEditRejectMsgForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
246 // Add your scene de-activate code here
247 __pSettingsPresentor = null;
248 RemoveOrientationEventListener(*this);
249 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA, true));
250 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
251 if (pEditMsgs != null)
253 pEditMsgs->HideKeypad();
254 pEditMsgs->SetPropagatedKeyEventListener(null);
259 SettingsEditRejectMsgForm::OnTextValueChanged(const Control& source)
261 AppLogDebug("Enter");
262 //ExpandableEditArea* pEditMsgs = static_cast<ExpandableEditArea*>(GetControl(IDC_REJECTMSG_EXPANDABLEEDITAREA, true));
263 EditField* pEditMsgs = static_cast<EditField*>(GetControl(IDC_REJECTMSG_EDITFIELD,true));
266 String text = pEditMsgs->GetText();
268 Footer* pFooter = GetFooter();
269 if ((text.IsEmpty() == false)
270 && (__editRejectMsg.Equals(text, true) == false))
273 pFooter->SetItemEnabled(0, true);
278 pFooter->SetItemEnabled(0, false);
280 pFooter->Invalidate(true);
285 SettingsEditRejectMsgForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
287 AppLogDebug("Enter");
291 SettingsEditRejectMsgForm::OnTextValueChangeCanceled(const Control& source)
296 SettingsEditRejectMsgForm::OnFormBackRequested(Form& source)
298 //switch back to previous form
299 SceneManager* pSceneManager = SceneManager::GetInstance();
300 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTMSGS_MENU,
301 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
302 SCENE_HISTORY_OPTION_ADD_HISTORY,
303 SCENE_DESTROY_OPTION_DESTROY), null);