Fix for N_SE-52935 N_SE-52866
[apps/osp/Call.git] / src / CallPresentationModel.cpp
index 3da9eed..04220e0 100644 (file)
@@ -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
 //
 #include <FApp.h>
 #include <FUi.h>
 #include <FMedia.h>
+#include <FShell.h>
 #include "CallApp.h"
 #include "CallAppControlRequestMgr.h"
 #include "CallActiveCallForm.h"
+#include "CallAppUtility.h"
 #include "CallInfo.h"
 #include "CallPresentationModel.h"
 #include "CallSettingsPresentationModel.h"
@@ -41,6 +43,8 @@ using namespace Tizen::Social;
 using namespace Tizen::Ui::Scenes;
 using namespace Tizen::Telephony;
 using namespace Tizen::Base::Utility;
+using namespace Tizen::Messaging;
+using namespace Tizen::Shell;
 
 CallPresentationModel* CallPresentationModel::__pInstance = null;
 
@@ -55,10 +59,14 @@ CallPresentationModel::CallPresentationModel(void)
        __pNetworkManager = null;
        __psimStateManager = null;
        __psimInfo = null;
+       __pSmsManager = null;
+       __isMessageSendInProgress = false;
+       __pNotificationManager = null;
 }
 
 CallPresentationModel::~CallPresentationModel(void)
 {
+       AppControl::StopAppControlResponseListener(this);
        __pTelephonyMgr = null;
        __pSettingsPresentor = null;
        __pAppControlMgr =null;
@@ -77,6 +85,11 @@ CallPresentationModel::~CallPresentationModel(void)
                delete __psimInfo;
                __psimInfo = null;
        }
+       if(__pSmsManager != null)
+       {
+               delete __pSmsManager;
+               __pSmsManager = null;
+       }
 }
 
 void
@@ -123,6 +136,8 @@ CallPresentationModel::Construct(void)
        __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
        __pNetworkManager = new (std::nothrow)NetworkManager();
        __pNetworkManager->Construct(null);
+       __pNotificationManager = new (std::nothrow) Tizen::Shell::NotificationManager;
+       __pNotificationManager->Construct();
        GetSimInfo();
        return E_SUCCESS;
 }
@@ -192,7 +207,7 @@ CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
        numberEndsWithHash = IfNumberEndsWithHash(contactNumber);
        if(numberEndsWithHash == true)
        {
-               __pTelEventListener->HandleTelephonyError(ERROR_GPRS_NUMBER);
+               __pTelEventListener->HandleTelephonyError(ERROR_USSD_NUMBER);
                return ;
        }
 
@@ -454,7 +469,7 @@ CallPresentationModel::GetCallListN(void)
 bool
 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
 {
-       AppLogDebug("Enter");
+       AppLogDebug("Enter %d",callHandle);
        if (sendMsg == true && __pAppControlMgr != null)
        {
                //launch compose message AppControl
@@ -556,7 +571,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);
 
        }
 }
@@ -585,6 +601,17 @@ CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber,
 }
 
 void
+CallPresentationModel::ResumeAlert(AppCallInfo& incomingCallInfo)
+{
+       //Adding incoming call sate setting here
+       if(__pSettingsPresentor != null)
+       {
+               __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
+       }
+       __pTelephonyMgr->ResumeAlert(incomingCallInfo);
+}
+
+void
 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
 {
        //Adding incoming call sate setting here
@@ -595,6 +622,12 @@ CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
        __pTelephonyMgr->StartAlert(incomingCallInfo);
 }
 
+AppCallInfo*
+CallPresentationModel::GetIncomingCallHandle()
+{
+       return __pTelephonyMgr->GetIncomingCallHandle();
+}
+
 void
 CallPresentationModel::StopAlert(void)
 {
@@ -632,7 +665,28 @@ CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCa
        }
        if(__pSettingsPresentor != null)
        {
-               __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
+               if(IsIncomingorDialingCallPresent() == false)
+               {
+                       __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
+               }
+       }
+}
+
+void
+CallPresentationModel::HandleCallActive(bool isActive)
+{
+       if (__pTelEventListener != null)
+       {
+               __pTelEventListener->HandleCallActive(isActive);
+       }
+}
+
+void
+CallPresentationModel::HandleCallHeld(bool isHeld)
+{
+       if (__pTelEventListener != null)
+       {
+               __pTelEventListener->HandleCallHeld(isHeld);
        }
 }
 
@@ -646,14 +700,21 @@ CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Coll
                SetMuteStatus(false);
                if(__pSettingsPresentor != null)
                {
-                       __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
+                       //Check if there is a incoming call or dialing call present before setting the status
+                       if(IsIncomingorDialingCallPresent() == false)
+                       {
+                               __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
+                       }
                }
        }
        else
        {
                if(__pSettingsPresentor != null)
                {
-                       __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
+                       if(IsIncomingorDialingCallPresent() == false)
+                       {
+                               __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
+                       }
                }
        }
        //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
@@ -681,6 +742,24 @@ CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
 }
 
 void
+CallPresentationModel::HandleConfCallHoldOccured(bool success)
+{
+       if (__pTelEventListener != null)
+       {
+               __pTelEventListener->HandleConfCallHoldOccured(success);
+       }
+}
+
+void
+CallPresentationModel::HandleConfCallActiveOccured(bool success)
+{
+       if (__pTelEventListener != null)
+       {
+               __pTelEventListener->HandleConfCallActiveOccured(success);
+       }
+}
+
+void
 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
 {
        if (__pTelEventListener != null)
@@ -934,3 +1013,83 @@ CallPresentationModel::IsSimAvailable(void)
 
 }
 
+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;
+               }
+               else
+               {
+                       AppLogDebug("%s",GetErrorMessage(r));
+                       ShowSMSErrorNotification();
+               }
+
+       }
+
+}
+
+void
+CallPresentationModel::ShowSMSErrorNotification(void)
+{
+       NotificationRequest request;
+       String alertString = AppUtility::GetResourceString(IDS_MESSAGE_SENDING_FAILED);
+       request.SetAlertText(L" ");
+       request.SetTitleText(L"\n"+alertString);
+       request.SetNotificationStyle(NOTIFICATION_STYLE_NORMAL);
+       request.SetNotificationCountText(alertString.GetLength());
+
+
+       String resourcePath = App::GetInstance()->GetAppSharedPath() + L"res/";
+
+       String iconPath = resourcePath + L"messages.png";
+       request.SetIconFilePath(iconPath);
+
+       int badgeNumber = __pNotificationManager->GetBadgeNumber();
+       ++badgeNumber;
+       if (badgeNumber <= 0)
+       {
+               badgeNumber = 1;
+       }
+       request.SetBadgeNumber(badgeNumber);
+
+       __pNotificationManager->Notify(request);
+       __pNotificationManager->RemoveNotification();
+}
+
+bool
+CallPresentationModel::IsMessageSendingInProgress(void)
+{
+       AppLogDebug("Enter %d",__isMessageSendInProgress);
+       return __isMessageSendInProgress;
+}
+
+void
+CallPresentationModel::OnSmsMessageSent(result r)
+{
+       AppLogDebug("Enter");
+       __isMessageSendInProgress = false;
+
+}