TizenRefApp-7387 Implement mechanism that will checks whether we can reply to incomin... 29/91429/1
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 7 Oct 2016 10:54:07 +0000 (13:54 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 7 Oct 2016 10:54:07 +0000 (13:54 +0300)
Change-Id: I44cb3eeb6ce751ba913c21b8de9ee0b9204afaf3
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/MsgEngine/inc/MsgUtils.h
src/Common/MsgEngine/src/MsgUtils.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/Conversation/Utils/src/MessageDetailContent.cpp

index 6a8f985..d9e8d01 100644 (file)
@@ -40,11 +40,13 @@ namespace Msg
             static TokenizedRecipients tokenizeRecipients(const std::string &inputText);
             static bool isValidNumber(const std::string &address);
             static bool isValidEmail(const std::string &address);
+            static bool isValidAddress(const std::string &address);
             static MsgAddress::AddressType getAddressType(const std::string &address);
             static std::string makeNormalizedNumber(const std::string &number);
             static std::string makeCleanedNumber(const std::string &number);
             static bool isMms(Message::Type type);
             static bool isSms(Message::Type type);
+            static std::string makeKbStr(long long bytes);
     };
 }
 
index 03ebd06..013da65 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include "MsgUtils.h"
+#include "LangUtils.h"
 
 #include <string.h>
 #include <ctype.h>
@@ -80,6 +81,11 @@ bool MsgUtils::isValidEmail(const std::string &address)
     return std::regex_match(address,emailTemplate);
 }
 
+bool MsgUtils::isValidAddress(const std::string &address)
+{
+    return isValidNumber(address) || isValidEmail(address);
+}
+
 MsgAddress::AddressType MsgUtils::getAddressType(const std::string &address)
 {
     if(isValidNumber(address))
@@ -135,3 +141,22 @@ bool MsgUtils::isSms(Message::Type type)
 {
     return type == Message::MT_SMS;
 }
+
+std::string MsgUtils::makeKbStr(long long bytes)
+{
+    const long long kb = 1000; // Bytes in kb
+    long long sizeKb = 0;
+    if(bytes <= kb)
+    {
+        sizeKb = 1;
+    }
+    else
+    {
+        sizeKb =  bytes / kb;
+        long long sizeB = bytes % kb;
+        if(sizeB >= (kb / 2))
+            ++sizeKb;
+    }
+    return std::to_string(sizeKb) + " " + (std::string)msg("IDS_MSGF_BODY_MSGSIZE_KB");
+
+}
index 6d27c38..eda566d 100644 (file)
@@ -155,18 +155,14 @@ namespace Msg
             void setMode(Mode mode);
             void setNewMessageMode();
             void setConversationMode();
-            void createBody(Evas_Object *parent, ConvList &convList);
-            void createRecipPanel(Evas_Object *parent);
-            void destroyRecipPanel();
-            void createContactList(Evas_Object *parent);
-            void destroyContactList();
-            void createMsgInputPanel(Evas_Object *parent, ConvList &convList);
+            void showConvList(bool show);
+            void showRecipPanel(bool show);
+            void showContactList(bool show);
+            void showMsgInputPanel(bool show);
             void updateMsgInputPanel();
             void updateNavibar();
             void updateSelectMsgTitle();
-            void createMainLayout(Evas_Object *parent);
-            void createConvList(Evas_Object *parent);
-            void destroyConvList();
+            void createMainLayout();
             void markAsRead();
             void recipientClickHandler(const std::string &address);
             void contactChangedHandler();
@@ -184,6 +180,7 @@ namespace Msg
             void resetMsgThread(bool updateConvList = true, bool updateRecipPanel = true);
             void updateActiveNotifPolicy();
             std::vector<MsgId> getMsgIdListForReadReport() const;
+            bool isHiddenAddress() const;
 
             void showSendReadReportPopup();
             void showMainPopup();
index 16ec369..7e9c9db 100644 (file)
 
 using namespace Msg;
 
-// TODO: move to common part
-std::string makeKbStr(long long bytes)
-{
-    const long long kb = 1000; // Bytes in kb
-    long long sizeKb = 0;
-    if(bytes <= kb)
-    {
-        sizeKb = 1;
-    }
-    else
-    {
-        sizeKb =  bytes / kb;
-        long long sizeB = bytes % kb;
-        if(sizeB >= (kb / 2))
-            ++sizeKb;
-    }
-    return std::to_string(sizeKb) + " " + (std::string)msg("IDS_MSGF_BODY_MSGSIZE_KB");
-}
-
 namespace
 {
     std::string makeDispAddress(std::string address, std::string dispName)
@@ -182,13 +163,10 @@ void Conversation::execCmd(const AppControlDefaultRef &cmd)
 void Conversation::create()
 {
     m_WorkingDir = std::make_shared<WorkingDir>();
-    createMainLayout(getParent());
-    createConvList(*m_pLayout);
-    createMsgInputPanel(*m_pLayout, *m_pConvList);
-
+    createMainLayout();
+    showConvList(true);
     getApp().getContactManager().addListener(*this);
     getApp().getSysSettingsManager().addListener(*this);
-    setHwButtonListener(*m_pLayout, this);
     m_AttachPanel.setListener(this);
 }
 
@@ -203,6 +181,7 @@ void Conversation::recipientClickHandler(const std::string &address)
 {
     MSG_LOG("");
     MSG_ASSERT(m_Mode != InitMode, "m_Mode is in initial state");
+
     ContactAddressRef contactAddress = getApp().getContactManager().getContactAddress(address);
     if(contactAddress)
     {
@@ -299,6 +278,7 @@ void Conversation::setThreadId(ThreadId id, const std::string &searchWord, bool
         m_AddressList.reset();
 
     setMode(m_ThreadId.isValid() ? ConversationMode : NewMessageMode);
+    showMsgInputPanel(!isHiddenAddress());
 
     if(m_pBody)
         m_pBody->setMmsRecipFlag(getMsgEngine().getStorage().hasEmail(m_ThreadId));
@@ -327,6 +307,16 @@ void Conversation::resetMsgThread(bool updateConvList, bool updateRecipPanel)
     setThreadId(ThreadId(), "", updateConvList, updateRecipPanel);
 }
 
+bool Conversation::isHiddenAddress() const
+{
+    if(m_AddressList && !m_AddressList->isEmpty())
+    {
+        std::string addr = m_AddressList->at(0).getAddress();
+        return !MsgUtils::isValidAddress(addr);
+    }
+    return false;
+}
+
 void Conversation::setListener(IConversationListener *listener)
 {
     m_pListener = listener;
@@ -379,8 +369,9 @@ void Conversation::setNewMessageMode()
 
     m_Mode = NewMessageMode;
     m_pLayout->showRecipEditMode(true);
-    createRecipPanel(*m_pLayout);
-    createContactList(*m_pLayout);
+    showMsgInputPanel(true);
+    showRecipPanel(true);
+    showContactList(true);
     m_pRecipPanel->update(m_ThreadId);
     m_pRecipPanel->showMbe(!m_pRecipPanel->isMbeEmpty());
     m_pRecipPanel->showEntry(true);
@@ -396,108 +387,134 @@ void Conversation::setConversationMode()
     MsgAddressListRef addressList = getAddressList();
     if(addressList && addressList->getLength() > 1)
     {
-        createRecipPanel(*m_pLayout);
+        showRecipPanel(true);
         m_pRecipPanel->showEntry(false);
         m_pRecipPanel->update(addressList);
     }
     else
     {
-        destroyRecipPanel();
+        showRecipPanel(false);
     }
-    destroyContactList();
+    showContactList(false);
 }
 
-void Conversation::createMainLayout(Evas_Object *parent)
+void Conversation::createMainLayout()
 {
-    m_pLayout = new ConversationLayout(parent);
+    m_pLayout = new ConversationLayout(getParent());
     m_pLayout->show();
     m_pLayout->expand();
+    setHwButtonListener(*m_pLayout, this);
 }
 
-void Conversation::createConvList(Evas_Object *parent)
+void Conversation::showConvList(bool show)
 {
-    if(!m_pConvList)
+    if(show)
     {
-        m_pConvList = new ConvList(*m_pLayout, getApp(), m_WorkingDir);
-        m_pConvList->setListener(this);
-        m_pConvList->show();
-        m_pLayout->setConvList(*m_pConvList);
+        if(!m_pConvList)
+        {
+            m_pConvList = new ConvList(*m_pLayout, getApp(), m_WorkingDir);
+            m_pConvList->setListener(this);
+            m_pConvList->show();
+            m_pLayout->setConvList(*m_pConvList);
+        }
     }
-}
-
-void Conversation::destroyConvList()
-{
-    if(m_pConvList)
+    else
     {
-        m_pConvList->destroy();
-        m_pConvList = nullptr;
+        if(m_pConvList)
+        {
+            m_pConvList->setListener(nullptr);
+            m_pConvList->destroy();
+            m_pConvList = nullptr;
+        }
     }
 }
 
-void Conversation::createRecipPanel(Evas_Object *parent)
+void Conversation::showRecipPanel(bool show)
 {
-    if(!m_pRecipPanel)
+    if(show)
     {
-        m_pRecipPanel = new ConvRecipientsPanel(parent, getApp());
-        m_pRecipPanel->setListener(this);
-        m_pRecipPanel->show();
-        m_pLayout->setRecipientPanel(*m_pRecipPanel);
-        m_pLayout->setRecipientRect(m_pRecipPanel->getAreaRect());
+        if(!m_pRecipPanel)
+        {
+            m_pRecipPanel = new ConvRecipientsPanel(*m_pLayout, getApp());
+            m_pRecipPanel->setListener(this);
+            m_pRecipPanel->show();
+            m_pLayout->setRecipientPanel(*m_pRecipPanel);
+            m_pLayout->setRecipientRect(m_pRecipPanel->getAreaRect());
+        }
     }
-}
-
-void Conversation::destroyRecipPanel()
-{
-    if(m_pRecipPanel)
+    else
     {
-        m_pRecipPanel->destroy();
-        m_pRecipPanel = nullptr;
+        if(m_pRecipPanel)
+        {
+            m_pRecipPanel->destroy();
+            m_pRecipPanel = nullptr;
+        }
     }
 }
 
-void Conversation::createContactList(Evas_Object *parent)
+void Conversation::showContactList(bool show)
 {
-    if(!m_pContactsList)
+    if(show)
     {
-        m_pContactsList = new ConvContactList(parent, getApp());
-        m_pContactsList->setListener(this);
-        m_pContactsList->show();
-        m_pLayout->setContactList(*m_pContactsList);
+        if(!m_pContactsList)
+        {
+            m_pContactsList = new ConvContactList(*m_pLayout, getApp());
+            m_pContactsList->setListener(this);
+            m_pLayout->setContactList(*m_pContactsList);
+        }
     }
-}
-
-void Conversation::destroyContactList()
-{
-    m_pLayout->showContactList(false);
-    if(m_pContactsList)
+    else
     {
-        m_pContactsList->destroy();
-        m_pContactsList = nullptr;
+        if(m_pContactsList)
+        {
+            m_pContactsList->destroy();
+            m_pContactsList = nullptr;
+            m_pLayout->showContactList(false);
+        }
     }
 }
 
-void Conversation::createMsgInputPanel(Evas_Object *parent, ConvList &convList)
+void Conversation::showMsgInputPanel(bool show)
 {
-    if(!m_pMsgInputPanel)
+    if(show)
     {
-        m_pMsgInputPanel = new MessageInputPanel(parent);
-        m_pMsgInputPanel->setListener(this);
-        m_pLayout->setMsgInputPanel(*m_pMsgInputPanel);
-        m_pLayout->showMsgInputPanel(true);
+        if(!m_pMsgInputPanel)
+        {
+            m_pMsgInputPanel = new MessageInputPanel(*m_pConvList);
+            m_pMsgInputPanel->setListener(this);
+            m_pLayout->setMsgInputPanel(*m_pMsgInputPanel);
+        }
+        if(!m_pBody && m_pConvList)
+        {
+            m_pBody = new Body(*m_pMsgInputPanel, getApp(), m_WorkingDir, *m_pConvList);
+            m_pBody->setListener(this);
+            m_pBody->show();
+            m_pMsgInputPanel->setEntry(*m_pBody);
+            updateMsgInputPanel();
+        }
     }
-    if(!m_pBody)
+    else
     {
-        m_pBody = new Body(*m_pMsgInputPanel, getApp(), m_WorkingDir, convList);
-        m_pBody->setListener(this);
-        m_pBody->show();
-        m_pMsgInputPanel->setEntry(*m_pBody);
-        updateMsgInputPanel();
+        if(m_pBody)
+        {
+            m_pBody->setListener(this);
+            m_pBody->destroy();
+            m_pBody = nullptr;
+        }
+        if(m_pMsgInputPanel)
+        {
+            m_pMsgInputPanel->setListener(this);
+            m_pMsgInputPanel->destroy();
+            m_pMsgInputPanel = nullptr;
+        }
     }
+    m_pLayout->showMsgInputPanel(show);
 }
 
 void Conversation::write(const Message &msg)
 {
-    m_pBody->write(msg);
+    if(m_pBody)
+        m_pBody->write(msg);
     if(m_pRecipPanel)
         m_pRecipPanel->write(msg);
 }
@@ -506,7 +523,8 @@ bool Conversation::read(Message &msg)
 {
     if(readMsgAddress(msg))
     {
-        m_pBody->read(msg);
+        if(m_pBody)
+            m_pBody->read(msg);
         return true;
     }
     return false;
@@ -630,6 +648,9 @@ void Conversation::sendMessage(MsgId msgId)
 
 void Conversation::sendMessage()
 {
+    if(!m_pMsgInputPanel || !m_pBody)
+        return;
+
     if(m_pRecipPanel &&
        m_pRecipPanel->getEntryFocus() &&
        !m_pRecipPanel->getEntryText().empty() &&
@@ -681,6 +702,9 @@ MsgId Conversation::saveDraftMsg()
 
 void Conversation::editDraftMsg(MsgId id)
 {
+    if(!m_pBody)
+        return;
+
     MessageRef msg = getMsgEngine().getStorage().getMessage(id);
     if(msg)
     {
@@ -773,7 +797,7 @@ bool Conversation::isRecipExists() const
 
 bool Conversation::isBodyEmpty() const
 {
-    return m_pBody && m_pBody->isEmpty();
+    return !m_pBody || m_pBody->isEmpty();
 }
 
 void Conversation::navigateToSlideShow(MsgId id)
@@ -898,7 +922,8 @@ void Conversation::showMainPopup()
 {
     PopupList &popup = getApp().getPopupManager().getPopupList(PopupList::MoreMenuPopup);
     popup.appendItem(msg("IDS_MSG_OPT_DELETE"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onDeleteItemPressed), this);
-    popup.appendItem(msg("IDS_MSG_TMBODY_ADD_OR_REMOVE_RECIPIENTS"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onAddRecipientsItemPressed), this);
+    if(!isHiddenAddress())
+        popup.appendItem(msg("IDS_MSG_TMBODY_ADD_OR_REMOVE_RECIPIENTS"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onAddRecipientsItemPressed), this);
     popup.show();
 }
 
@@ -938,7 +963,8 @@ void Conversation::onEntryChanged(ConvRecipientsPanel &panel)
 void Conversation::onMbeChanged(ConvRecipientsPanel &panel)
 {
     MSG_LOG("");
-    m_pBody->setMmsRecipFlag(m_pRecipPanel->isMms());
+    if(m_pBody)
+        m_pBody->setMmsRecipFlag(m_pRecipPanel->isMms());
     checkAndSetMsgType();
     if(m_pConvList)
     {
@@ -972,13 +998,13 @@ void Conversation::onChanged(Body &body)
 
 void Conversation::updateMsgInputPanel()
 {
-    if(!m_pBody)
+    if(!m_pBody || !m_pMsgInputPanel)
         return;
 
     if(m_pBody->isMms())
     {
         // Mms:
-        m_pMsgInputPanel->setCounter(makeKbStr(m_pBody->getMsgSize()));
+        m_pMsgInputPanel->setCounter(MsgUtils::makeKbStr(m_pBody->getMsgSize()));
     }
     else
     {
@@ -1161,7 +1187,7 @@ void Conversation::onNaviCenterButtonClicked()
     else
     {
         MsgAddressListRef addressList = getAddressList();
-        if(addressList && !addressList->isEmpty())
+        if(addressList && !addressList->isEmpty() && !isHiddenAddress())
             recipientClickHandler(addressList->at(0).getAddress());
     }
 }
@@ -1210,7 +1236,8 @@ void Conversation::onButtonClicked(NaviFrameItem &item, NaviButtonId buttonId)
 void Conversation::onPopupDel(Evas_Object *popup, void *eventInfo)
 {
     MSG_LOG("");
-    m_pBody->setFocus(true);
+    if(m_pBody)
+        m_pBody->setFocus(true);
 }
 
 void Conversation::onSendReadReportPopupDel(Evas_Object *popup, void *eventInfo)
@@ -1237,8 +1264,9 @@ void Conversation::onRecipPopupDel(Evas_Object *popup, void *eventInfo)
 void Conversation::onMsgSendErrorButtonClicked(Popup &popup, int buttonId)
 {
     MSG_LOG("");
-    m_pBody->setFocus(true);
     popup.destroy();
+    if(m_pBody)
+        m_pBody->setFocus(true);
 }
 
 void Conversation::onMsgSettingsButtonClicked(Popup &popup, int buttonId)
@@ -1250,15 +1278,18 @@ void Conversation::onMsgSettingsButtonClicked(Popup &popup, int buttonId)
 
 void Conversation::onNoRecipCancelButtonClicked(Popup &popup, int buttonId)
 {
-    m_pBody->setFocus(true);
     popup.destroy();
+    if(m_pBody)
+        m_pBody->setFocus(true);
 }
 
 void Conversation::onNoRecipDiscardButtonClicked(Popup &popup, int buttonId)
 {
+    popup.destroy();
     if(isDefferedCmd())
     {
-        m_pBody->clear();
+        if(m_pBody)
+            m_pBody->clear();
         if(m_DefferedCmd.defaultCmd)
         {   // If we came from notification menu and unread threads will be more than one, we should to go back on thread list view
             if(m_DefferedCmd.defaultCmd->getDefaultType() == AppControlDefault::NotificationType && getMsgEngine().getStorage().getUnreadThreadCount() > 1)
@@ -1285,11 +1316,9 @@ void Conversation::onNoRecipDiscardButtonClicked(Popup &popup, int buttonId)
         resetDefferedCmd();
     }
     else
-    {   // We will get here from conversation after tap on Back Button
+    {
         pop();
     }
-
-    popup.destroy();
 }
 
 void Conversation::onDeleteItemPressed(PopupListItem &item)
@@ -1365,7 +1394,7 @@ void Conversation::onAllConvItemsDeleted(ConvList &list)
         auto convList = getMsgEngine().getStorage().getConversationList(m_ThreadId);
         if((convList && convList->getLength() == 0) || !convList)
         {
-            if(m_pBody->isEmpty())
+            if(isBodyEmpty())
             {
                 onHwBackButtonClicked();
             }
@@ -1373,7 +1402,8 @@ void Conversation::onAllConvItemsDeleted(ConvList &list)
             {
                 // Current MsgThread is dead, so create new MsgThread from existing recipients.
                 createNewMsgThread();
-                m_pBody->setFocus(true);
+                if(m_pBody)
+                    m_pBody->setFocus(true);
             }
         }
     }
index 7b8a653..4517b59 100644 (file)
@@ -20,6 +20,7 @@
 #include "ContactManager.h"
 #include "LangUtils.h"
 #include "TimeUtils.h"
+#include "MsgUtils.h"
 #include "MessageMms.h"
 
 #include <telephony_common.h>
@@ -27,8 +28,6 @@
 
 using namespace Msg;
 
-extern std::string makeKbStr(long long bytes);
-
 std::string MessageDetailContent::getMsgDetailsPopupContent(App &app, MsgId msgId)
 {
     return createMsgDetailsPopupText(app, msgId);
@@ -310,7 +309,7 @@ std::string MessageDetailContent::getMmsMessageSize(App &app, MsgId msgId)
     std::string msgDetails = msg("IDS_MSGF_BODY_MESSAGE_SIZE");
     msgDetails.append(": ");
     int msgSize = app.getMsgEngine().getStorage().getMessage(msgId)->getSize();
-    msgDetails.append(makeKbStr(msgSize));
+    msgDetails.append(MsgUtils::makeKbStr(msgSize));
     msgDetails.append("<br/>");
     return msgDetails;
 }