Fix for 38340 38396
[apps/osp/Call.git] / src / CallPresentationModel.cpp
index 468f732..298a3fc 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
 //
@@ -41,6 +41,7 @@ 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;
 
@@ -55,6 +56,8 @@ CallPresentationModel::CallPresentationModel(void)
        __pNetworkManager = null;
        __psimStateManager = null;
        __psimInfo = null;
+       __pSmsManager = null;
+       __isMessageSendInProgress = false;
 }
 
 CallPresentationModel::~CallPresentationModel(void)
@@ -77,6 +80,11 @@ CallPresentationModel::~CallPresentationModel(void)
                delete __psimInfo;
                __psimInfo = null;
        }
+       if(__pSmsManager != null)
+       {
+               delete __pSmsManager;
+               __pSmsManager = null;
+       }
 }
 
 void
@@ -474,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.
@@ -487,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<CallApp*>(UiApp::GetInstance());
-                       pPhoneApp->Terminate();
+                       CallApp* pCallApp = static_cast<CallApp*>(UiApp::GetInstance());
+                       pCallApp->Terminate();
                }
        }
 }
@@ -713,6 +722,7 @@ CallPresentationModel::LaunchDialAppControl()
 
        if(__isDialAppControlRunning == true)
        {
+               AppLogDebug("__isDialAppControlRunning == true");
                //Do not allow another app control if already running
                return;
        }
@@ -932,3 +942,56 @@ CallPresentationModel::IsSimAvailable(void)
 
 }
 
+void
+CallPresentationModel::SendMessage(String& strMsg,String& recpientNum)
+{
+       AppLogDebug("Enter");
+       if(__pSmsManager == null)
+       {
+               __pSmsManager = new (std::nothrow) SmsManager();
+       }
+       result r = __pSmsManager->Construct(*this);
+       if (IsFailed(r) == false)
+       {
+               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) == true)
+                       {
+                               //todo: error message
+                       }
+                       else
+                       {
+                               __isMessageSendInProgress = true;
+                       }
+               }
+               else
+               {
+                       //todo: error message
+               }
+       }
+       else
+       {
+               //todo: error message
+       }
+
+}
+
+bool
+CallPresentationModel::IsMessageSendingInProgress(void)
+{
+       AppLogDebug("Enter %d",__isMessageSendInProgress);
+       return __isMessageSendInProgress;
+}
+
+void
+CallPresentationModel::OnSmsMessageSent(result r)
+{
+       AppLogDebug("Enter");
+       __isMessageSendInProgress = false;
+
+}