3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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);
84 AppLog("width of editfield edithomepage %d",__pUrlEditField->GetWidth());
91 EditHomePageForm::OnTerminating(void)
98 EditHomePageForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
100 if (__pUrlEditField != null)
102 String favURL = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
103 AppLogDebug("EditHomePageForm::OnSceneActivatedN favURL %ls",favURL.GetPointer());
104 __pUrlEditField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteUrl());
105 __pUrlEditField->SetFocus();
106 __pUrlEditField->SetCursorPosition(__pUrlEditField->GetTextLength());
107 __pUrlEditField->ShowKeypad();
108 __pUrlEditField->Invalidate(true);
117 EditHomePageForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
123 EditHomePageForm::OnFormBackRequested(Form& source)
125 ArrayList* pArgList = null;
126 pArgList = new(std::nothrow) ArrayList();
127 pArgList->Construct();
128 pArgList->Add(*new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_SK_CANCEL")));
129 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
134 EditHomePageForm::OnActionPerformed(const Control& source, int actionId)
136 ArrayList* pArgList = null;
137 pArgList = new(std::nothrow) ArrayList();
138 pArgList->Construct();
141 case IDA_BUTTON_DONE:
143 pArgList->Add(*new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_SK_DONE")));
144 String urlText = __pUrlEditField->GetText();
146 AppLogDebug("set url text is %ls",urlText.GetPointer());
150 String firstPattern(L"((ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");//[\w\d:#@%/;$()~_?\+-=\\\.&]*
151 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)
152 RegularExpression firstRegex;
153 RegularExpression secondRegex;
155 firstRegex.Construct(firstPattern, REGEX_CASELESS);
156 secondRegex.Construct(secondPattern, REGEX_CASELESS);
159 // uri.SetUri(urlText);
160 // urlText = uri.GetEncodedString();
163 ret = firstRegex.Match(urlText, false); // This returns true value
164 flag = secondRegex.Match(urlText, false); // Checks whether URL typed is of type abc.com (i.e without protocol in front of it)
170 SettingPresentationModel::GetInstance()->SetHomepage(urlText);
171 SettingPresentationModel::GetInstance()->SetFavoriteValue(urlText);
172 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
173 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
180 if(urlText.Contains("http://") == true)
182 validUrl.Append(urlText);
186 validUrl = L"http://";
187 validUrl.Append(urlText);
191 SettingPresentationModel::GetInstance()->SetHomepage(validUrl);
192 SettingPresentationModel::GetInstance()->SetFavoriteValue(validUrl);
193 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
194 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
198 // show pop up , not a valid URL
199 String msg = CommonUtil::GetString(L"IDS_COM_POP_INVALID_URL");
206 case IDA_BUTTON_CANCEL:
208 pArgList->Add(*new(std::nothrow) String(CommonUtil::GetString(L"IDS_BR_SK_CANCEL")));
209 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(), pArgList);
210 TryCatch(!IsFailed(r), "EditHomePageForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
218 pArgList->RemoveAll(true);
224 EditHomePageForm::OnTextValueChanged(const Control& source)
227 Header* pHeader = GetHeader();
234 if (__pUrlEditField == NULL)
239 title = __pUrlEditField->GetText();
242 // To disable done button when folder title edit-field is empty
243 if (__pUrlEditField && title.IsEmpty() == true)
245 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, false);
249 pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
251 pHeader->Invalidate(true);
256 EditHomePageForm::OnTextValueChangeCanceled(const Control& source)
262 EditHomePageForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
268 EditHomePageForm::CreateMessage(String& message)
271 if (__pMsgBox != null)
275 __modalMsgBoxResult = 0;
278 __pMsgBox = new(std::nothrow) MessageBox;
279 if (__pMsgBox != null)
281 __pMsgBox->Construct(L"", message, MSGBOX_STYLE_OK, 3000);
284 if (__pMsgBox != null)
286 __pMsgBox->ShowAndWait(__modalMsgBoxResult);
287 if (__modalMsgBoxResult == MSGBOX_RESULT_OK)
289 if (__pMsgBox != null)
295 __modalMsgBoxResult = 0;