X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FCallPresentationModel.cpp;h=a190395e6d6e2ea0528a506dabd9932753efeee6;hb=a7fa9b4151e7cb0896fa51cb8664b6713d2af09c;hp=7108c619fab01bd454250fa0acffc8db153e5fcb;hpb=968ce47ae7a353e2ad110ef3b64be43d5c9b0b36;p=apps%2Fosp%2FCall.git diff --git a/src/CallPresentationModel.cpp b/src/CallPresentationModel.cpp index 7108c61..a190395 100644 --- a/src/CallPresentationModel.cpp +++ b/src/CallPresentationModel.cpp @@ -1,7 +1,7 @@ // // Copyright (c) 2012 Samsung Electronics Co., Ltd. // -// Licensed under the Flora License, Version 1.0 (the License); +// Licensed under the Flora License, Version 1.1 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // @@ -40,6 +40,8 @@ using namespace Tizen::Media; using namespace Tizen::Social; using namespace Tizen::Ui::Scenes; using namespace Tizen::Telephony; +using namespace Tizen::Base::Utility; +using namespace Tizen::Messaging; CallPresentationModel* CallPresentationModel::__pInstance = null; @@ -51,6 +53,11 @@ CallPresentationModel::CallPresentationModel(void) __isMessageAppControlRunning = false; __isDialAppControlRunning = false; __pAppControlMgr = null; + __pNetworkManager = null; + __psimStateManager = null; + __psimInfo = null; + __pSmsManager = null; + __isMessageSendInProgress = false; } CallPresentationModel::~CallPresentationModel(void) @@ -58,6 +65,26 @@ CallPresentationModel::~CallPresentationModel(void) __pTelephonyMgr = null; __pSettingsPresentor = null; __pAppControlMgr =null; + if(__pNetworkManager != null) + { + delete __pNetworkManager; + __pNetworkManager = null; + } + if(__psimStateManager != null) + { + delete __psimStateManager; + __psimStateManager = null; + } + if(__psimInfo != null) + { + delete __psimInfo; + __psimInfo = null; + } + if(__pSmsManager != null) + { + delete __pSmsManager; + __pSmsManager = null; + } } void @@ -102,6 +129,9 @@ CallPresentationModel::Construct(void) __pTelephonyMgr = TelephonyManager::GetInstance(this); __pSettingsPresentor = SettingsPresentationModel::GetInstance(); __pAppControlMgr = CallAppControlRequestMgr::GetInstance(); + __pNetworkManager = new (std::nothrow)NetworkManager(); + __pNetworkManager->Construct(null); + GetSimInfo(); return E_SUCCESS; } @@ -112,13 +142,27 @@ CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventLis __pTelEventListener = pTelEventListener; } +bool +CallPresentationModel::IfNumberEndsWithHash(Tizen::Base::String& phoneNumber) +{ + String phoneNumberEndingWithHash(L"#$"); + RegularExpression checkHash; + checkHash.Construct(phoneNumberEndingWithHash); + bool endsWithHash = checkHash.Match(phoneNumber,false); + if(endsWithHash == true) + { + return true; + } + return false; +} + void CallPresentationModel::DialCall(String& contactNumber, bool isEmergency) { int errorCode = ERROR_NONE; bool isCallServiceAvailable = false; + bool numberEndsWithHash = false; NetworkStatus networkStatus; - NetworkManager* pNetworkManager = new NetworkManager(); result r; //Check if Telephony Manager is initialized TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed"); @@ -130,29 +174,36 @@ CallPresentationModel::DialCall(String& contactNumber, bool isEmergency) return; } //Check if dialing a call is possible - Check if sim is available - if (GetSimInfo() == E_FAILURE) + if (IsSimAvailable() == false) { __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED); return ; } //fetch call service status - r = pNetworkManager->Construct(null); - if (r == E_SUCCESS) + if(__pNetworkManager != null) { - r = pNetworkManager->GetNetworkStatus(networkStatus); + r = __pNetworkManager->GetNetworkStatus(networkStatus); if (r == E_SUCCESS) { isCallServiceAvailable = networkStatus.IsCallServiceAvailable(); } } - delete pNetworkManager; + if (isCallServiceAvailable == false) { __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED); return ; } + // check if GPRS number + numberEndsWithHash = IfNumberEndsWithHash(contactNumber); + if(numberEndsWithHash == true) + { + __pTelEventListener->HandleTelephonyError(ERROR_GPRS_NUMBER); + return ; + } + //setup outgoing call errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency); TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call"); @@ -431,6 +482,7 @@ CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& co void CallPresentationModel::OnAppForeground(void) { + AppLogDebug("Enter %d %d",__isDialAppControlRunning ,__isMessageAppControlRunning); if (__isDialAppControlRunning == true) { //This comes here, when Dialer AppControl is finished working. @@ -444,10 +496,10 @@ void CallPresentationModel::OnAppForeground(void) __pAppControlMgr->AppControlRequestCompleted(); //Check if this was the last call, then terminate application. //And if any calls are active, then those cases are already handled from Other places. - if( GetCurrentCallCount() == 0) + if( GetCurrentCallCount() == 0 && IsIncomingorDialingCallPresent() == false) { - CallApp* pPhoneApp = static_cast(UiApp::GetInstance()); - pPhoneApp->Terminate(); + CallApp* pCallApp = static_cast(UiApp::GetInstance()); + pCallApp->Terminate(); } } } @@ -512,7 +564,8 @@ CallPresentationModel::AddCall(const String& phoneNumber) { nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL; } - pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs); + pSceneManager->GoForward( ForwardSceneTransition( nextScene, + SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_KEEP), pLaunchArgs); } } @@ -670,6 +723,7 @@ CallPresentationModel::LaunchDialAppControl() if(__isDialAppControlRunning == true) { + AppLogDebug("__isDialAppControlRunning == true"); //Do not allow another app control if already running return; } @@ -809,41 +863,130 @@ CallPresentationModel::AppControlRequestCompleted(void) result CallPresentationModel::GetSimInfo(void) { - int mnc; - int mcc; - bool isAvailable; - String spn; - String iccId; - String operatorName; - - SimStateManager simStateManager; - SimInfo simInfo; - - result r = simStateManager.Construct(); + __psimStateManager = new (std::nothrow)SimStateManager(); + result r = __psimStateManager->Construct(); if (IsFailed(r)) { + delete __psimStateManager; + __psimStateManager = null; return E_FAILURE; } + __psimStateManager->SetSimEventListener(this); - r = simStateManager.GetSimInfo(simInfo); + __psimInfo = new (std::nothrow)SimInfo(); + r = __psimStateManager->GetSimInfo(*__psimInfo); if (IsFailed(r)) { + delete __psimStateManager; + __psimStateManager = null; + delete __psimInfo; + __psimInfo = null; return E_FAILURE; } + return E_SUCCESS; +} + +void +CallPresentationModel::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus) +{ + +} + +void +CallPresentationModel::OnTelephonySimStateChanged(Tizen::Telephony::SimState state) +{ + if(__psimStateManager != null) + { + delete __psimStateManager; + __psimStateManager =null; + } + if(__psimInfo != null) + { + delete __psimInfo; + __psimInfo = null; + } + + __psimStateManager = new SimStateManager(); + result r = __psimStateManager->Construct(); + if (IsFailed(r)) + { + delete __psimStateManager; + __psimStateManager = null; + return ; + } - mnc = simInfo.GetMnc(); - mcc = simInfo.GetMcc(); - spn = simInfo.GetSpn(); - iccId = simInfo.GetIccId(); - operatorName = simInfo.GetOperatorName(); - //Checks whether a SIM card is present in the device or not - isAvailable = simInfo.IsAvailable(); - if(isAvailable == true) + __psimInfo = new SimInfo(); + r = __psimStateManager->GetSimInfo(*__psimInfo); + if (IsFailed(r)) + { + delete __psimStateManager; + __psimStateManager = null; + delete __psimInfo; + __psimInfo = null; + return ; + } + +} + +bool +CallPresentationModel::IsSimAvailable(void) +{ + if(__psimInfo != null) { - return E_SUCCESS; + return __psimInfo->IsAvailable(); } else { - return E_FAILURE; + return false; + } + + +} + +void +CallPresentationModel::SendMessage(String& strMsg,String& recpientNum) +{ + AppLogDebug("Enter"); + result r; + if(__pSmsManager == null) + { + __pSmsManager = new (std::nothrow) SmsManager(); + result r = __pSmsManager->Construct(*this); + if (IsFailed(r) == true) + { + delete __pSmsManager; + __pSmsManager = null; + return; + } + } + RecipientList recipient; + recipient.Add(RECIPIENT_TYPE_TO,recpientNum); + SmsMessage smsMessage; + r = smsMessage.SetText(strMsg); + if (IsFailed(r) == false) + { + r = __pSmsManager->Send(smsMessage,recipient,true); + if (IsFailed(r) == false) + { + __isMessageSendInProgress = true; + } + + } + +} + +bool +CallPresentationModel::IsMessageSendingInProgress(void) +{ + AppLogDebug("Enter %d",__isMessageSendInProgress); + return __isMessageSendInProgress; +} + +void +CallPresentationModel::OnSmsMessageSent(result r) +{ + AppLogDebug("Enter"); + __isMessageSendInProgress = false; + }