2 // Open Service Platform
\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Flora License, Version 1.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.tizenopensource.org/license
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an AS IS BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
18 #include "SocketChat.h"
\r
19 #include "MainFrm.h"
\r
20 using namespace Osp::App;
\r
21 using namespace Osp::Base;
\r
22 using namespace Osp::Ui;
\r
23 using namespace Osp::Ui::Controls;
\r
24 using namespace Osp::Net;
\r
25 using namespace Osp::System;
\r
26 MainFrm::MainFrm(void)
\r
29 __pip_clientip = NULL;
\r
30 __pButtonServer = NULL;
\r
31 __pButtonTcp = NULL;
\r
32 __pEditIPAddress= NULL;
\r
39 MainFrm::~MainFrm(void)
\r
44 MainFrm::Initialize()
\r
46 // Construct an XML form
\r
47 Construct(L"IDF_MAINFRM");
\r
53 MainFrm::OnInitializing(void)
\r
55 result r = E_SUCCESS;
\r
57 // Get a button via resource ID
\r
58 __pButtonServer = static_cast <CheckButton *>(GetControl(L"IDC_CHECKServer"));
\r
60 if (__pButtonServer != null)
\r
62 __pButtonServer->SetActionId(IDC_CHECKServer_SEL,IDC_CHECKServer_UNSEL);
\r
63 __pButtonServer->AddActionEventListener(*this);
\r
66 __pButtonTcp = static_cast <CheckButton *>(GetControl(L"IDC_CHECKTCP"));
\r
67 __pButtonUdp = static_cast <CheckButton *>(GetControl(L"IDC_CHECKUDP"));
\r
69 __pEditIPAddress = static_cast <EditField *>(GetControl(L"IDC_EDITIPaddress"));
\r
70 if(__pEditIPAddress == null)
\r
75 __pEditPort = static_cast <EditField *>(GetControl(L"IDC_EDITPort"));
\r
76 Footer* pFooter = GetFooter();
\r
79 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
\r
82 footerItem_Left.Construct(ID_START);
\r
83 footerItem_Left.SetText(L"Connect");
\r
84 pFooter->AddItem(footerItem_Left);
\r
85 pFooter->AddActionEventListener(*this);
\r
90 MainFrm::SetDefaultValues()
\r
92 if (__pButtonTcp != null)
\r
94 __pButtonTcp->SetSelected(true);
\r
98 MainFrm::OnTerminating(void)
\r
100 result r = E_SUCCESS;
\r
102 AppLog("MainFrm::OnTerminating");
\r
108 MainFrm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
\r
113 case IDC_CHECKServer_UNSEL:
\r
115 AppLog("Server Button unselected");
\r
116 __pEditIPAddress->SetEnabled(true);
\r
117 __pEditIPAddress->RequestRedraw(true);
\r
118 Footer* pFooter = GetFooter();
\r
119 pFooter->RemoveItemAt(0);
\r
120 footerItem_Left.SetText(L"Connect");
\r
121 pFooter->InsertItemAt(0,footerItem_Left);
\r
127 case IDC_CHECKServer_SEL:
\r
129 AppLog("Server button selected");
\r
131 __pEditIPAddress->SetEnabled(false);
\r
132 __pEditIPAddress->RequestRedraw(true);
\r
134 Footer* pFooter = GetFooter();
\r
135 pFooter->RemoveItemAt(0);
\r
136 footerItem_Left.SetText(L"Listen");
\r
137 pFooter->InsertItemAt(0,footerItem_Left);
\r
144 AppLog("Start Button is clicked! \n");
\r
148 case ID_BUTTON_CLOSE:
\r
150 AppLog("Back Button pressed, close application now");
\r
151 Application::GetInstance()->Terminate();
\r
164 MainFrm::StartChat()
\r
167 // get protocol type
\r
168 b_protocol = __pButtonTcp->IsSelected();
\r
170 //get connection type
\r
171 b_server = __pButtonServer->IsSelected();
\r
173 if(b_server== false)
\r
175 //get ipaddress and port
\r
177 ipaddress = __pEditIPAddress->GetText();
\r
180 if(ipaddress.IsEmpty() == true)
\r
183 MessageBox *pMsgBox = new MessageBox() ;
\r
184 pMsgBox->Construct(L"IP Address", L"Please enter IP address", MSGBOX_STYLE_OK) ;
\r
185 pMsgBox->ShowAndWait(result) ;
\r
191 result r = E_SUCCESS;
\r
192 __pip_clientip = new Ip4Address(ipaddress);
\r
194 r = GetLastResult();
\r
195 if(r!=E_SUCCESS || __pip_clientip==NULL)
\r
198 MessageBox *pMsgBox = new MessageBox() ;
\r
199 pMsgBox->Construct(L"IP Address", L"Invalid IP address", MSGBOX_STYLE_OK) ;
\r
200 pMsgBox->ShowAndWait(result) ;
\r
207 port = __pEditPort->GetText();
\r
208 if(port.IsEmpty()==true)
\r
211 MessageBox *pMsgBox = new MessageBox() ;
\r
212 pMsgBox->Construct(L"Port", L"Enter Valid User Port Number", MSGBOX_STYLE_OK) ;
\r
213 pMsgBox->ShowAndWait(result) ;
\r
219 result res=E_SUCCESS;
\r
222 res =Osp::Base::Integer::Decode(port,iport);
\r
223 AppLog("Port No is %d",iport);
\r
224 if(iport<1024 || iport>49151 || res != E_SUCCESS)
\r
226 MessageBox *pMsgBox = new MessageBox() ;
\r
227 pMsgBox->Construct(L"Port", L"Enter Valid User Port Number", MSGBOX_STYLE_OK) ;
\r
228 pMsgBox->ShowAndWait(result) ;
\r
234 if(pChatForm!=NULL)
\r
240 pChatForm = new ChatFrm(__pip_clientip,iport,b_server,b_protocol, this);
\r
241 if(pChatForm==NULL)
\r
244 MessageBox *pMsgBox = new MessageBox() ;
\r
245 pMsgBox->Construct(L"Error", L"Error in allocating Memory", MSGBOX_STYLE_OK) ;
\r
246 pMsgBox->ShowAndWait(result) ;
\r
248 if(__pip_clientip!=NULL)
\r
250 delete __pip_clientip;
\r
251 __pip_clientip=NULL;
\r
256 if(__pip_clientip!=NULL)
\r
258 delete __pip_clientip;
\r
259 __pip_clientip=NULL;
\r
261 pChatForm->Initialize();
\r
263 // Add the form to the frame
\r
264 Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
\r
265 pFrame->AddControl(*pChatForm);
\r
266 pFrame->SetCurrentForm(*pChatForm);
\r
267 pFrame->RequestRedraw();
\r
268 pChatForm->EnableControl(false);
\r
269 pChatForm->StartChat();
\r
274 MainFrm::StopChat()
\r
276 Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
\r
277 if(pFrame!=NULL && pChatForm !=NULL)
\r
279 pFrame->SetCurrentForm(*this);
\r
281 AppLog("Removing Control");
\r
282 pFrame->RemoveControl(*pChatForm);
\r
286 AppLog("request redraw");
\r
287 pFrame->RequestRedraw();
\r
290 void MainFrm::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs)
\r
292 AppLog("User Event Received");
\r
295 //SwitchToForm(requestId, pArgs);
\r