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://floralicense.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 //!Internet EditHomePageForm class
19 /*@file: EditHomePageForm.h
20 *@brief: Allow user to set any page as Home page.
24 #include <FAppUiApp.h>
27 #include "IntBookmarkData.h"
28 #include "IntCommonLib.h"
29 #include "IntEditHomePageForm.h"
30 #include "IntMultipleWindowPresentationModel.h"
31 #include "IntSceneRegister.h"
32 #include "IntSettingPresentationModel.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Utility;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
44 const int EditHomePageForm::IDA_BUTTON_DONE = 101;
45 const int EditHomePageForm::IDA_BUTTON_CANCEL = 102;
47 EditHomePageForm::EditHomePageForm(void)
48 :__pUrlEditField(null)
50 , __modalMsgBoxResult(0)
55 EditHomePageForm::~EditHomePageForm(void)
61 EditHomePageForm::Initialize(void)
63 Construct(L"IDL_EDIT_HOME_PAGE");
64 SetOrientation(ORIENTATION_AUTOMATIC);
69 EditHomePageForm::OnInitializing(void)
72 SetFormBackEventListener(this);
73 SceneManager* pSceneManager = SceneManager::GetInstance();
74 AppAssert(pSceneManager);
75 pSceneManager->AddSceneEventListener(IDSCN_EDIT_HOMEPAGE_VIEW, *this);
77 GetHeader()->AddActionEventListener(*this);
79 __pUrlEditField = static_cast<EditField*>(GetControl(L"IDC_EDITFIELD"));
80 if (__pUrlEditField != null)
82 __pUrlEditField->AddTextEventListener(*this);
83 __pUrlEditField->SetOverlayKeypadCommandButtonVisible(false);
89 EditHomePageForm::OnTerminating(void)
96 EditHomePageForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
98 if (__pUrlEditField != null)
100 String favURL = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
101 AppLogDebug("EditHomePageForm::OnSceneActivatedN favURL %ls",favURL.GetPointer());
102 __pUrlEditField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteUrl());
103 __pUrlEditField->SetFocus();
104 __pUrlEditField->SetCursorPosition(__pUrlEditField->GetTextLength());
105 __pUrlEditField->ShowKeypad();
106 __pUrlEditField->Invalidate(true);
115 EditHomePageForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
121 EditHomePageForm::OnFormBackRequested(Form& source)
127 EditHomePageForm::OnActionPerformed(const Control& source, int actionId)
129 ArrayList* pArgList = null;
130 pArgList = new(std::nothrow) ArrayList();
133 case IDA_BUTTON_DONE:
135 pArgList->Add(*new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_SK_DONE")));
136 String urlText = __pUrlEditField->GetText();
137 AppLogDebug("set url text is %ls",urlText.GetPointer());
141 String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
142 String secondPattern(L"^[A-Za-z0-9\.\+-:#@%/;$~?]+\\.[A-Za-z0-9\+-=:#@%/;$~()_?\\\.&]{2,}$"); // URL of type abc.com (i.e without protocol in front of it)
143 RegularExpression firstRegex;
144 RegularExpression secondRegex;
146 firstRegex.Construct(firstPattern, REGEX_CASELESS);
147 secondRegex.Construct(secondPattern, REGEX_CASELESS);
151 urlText = uri.GetEncodedString();
154 ret = firstRegex.Match(urlText, false); // This returns true value
155 flag = secondRegex.Match(urlText, false); // Checks whether URL typed is of type abc.com (i.e without protocol in front of it)
161 SettingPresentationModel::GetInstance()->SetHomepage(urlText);
162 SettingPresentationModel::GetInstance()->SetFavoriteValue(urlText);
163 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
164 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
171 validUrl = L"http://";
172 validUrl.Append(urlText);
174 SettingPresentationModel::GetInstance()->SetHomepage(validUrl);
175 SettingPresentationModel::GetInstance()->SetFavoriteValue(validUrl);
176 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
177 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
181 // show pop up , not a valid URL
182 String msg = CommonUtil::GetString(L"IDS_BR_POP_INVALIDADDRESS");
189 case IDA_BUTTON_CANCEL:
191 pArgList->Add(*new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_SK_CANCEL")));
192 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
193 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
201 pArgList->RemoveAll(true);
207 EditHomePageForm::OnTextValueChanged(const Control& source)
210 Header* pHeader = GetHeader();
217 if (__pUrlEditField == NULL)
222 title = __pUrlEditField->GetText();
225 // To disable done button when folder title edit-field is empty
226 if (__pUrlEditField && title.IsEmpty() == true)
228 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
232 pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
234 pHeader->Invalidate(true);
239 EditHomePageForm::OnTextValueChangeCanceled(const Control& source)
245 EditHomePageForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
251 EditHomePageForm::CreateMessage(String& message)
254 if (__pMsgBox != null)
258 __modalMsgBoxResult = 0;
261 __pMsgBox = new(std::nothrow) MessageBox;
262 if (__pMsgBox != null)
264 __pMsgBox->Construct(L"", message, MSGBOX_STYLE_OK, 3000);
267 if (__pMsgBox != null)
269 __pMsgBox->ShowAndWait(__modalMsgBoxResult);
270 if (__modalMsgBoxResult == MSGBOX_RESULT_OK)
272 if (__pMsgBox != null)
278 __modalMsgBoxResult = 0;