TSAM-2119 Can attach more than 10 file - FIXED 33/65333/3
authorMykola Alieksieiev <m.alieksieie@samsung.com>
Fri, 8 Apr 2016 11:11:12 +0000 (14:11 +0300)
committerMykola Alieksieiev <m.alieksieie@samsung.com>
Mon, 11 Apr 2016 09:32:50 +0000 (12:32 +0300)
Change-Id: I52b7275cd00be153ba05eb8b1196d46dcdca9230
Signed-off-by: Mykola Alieksieiev <m.alieksieie@samsung.com>
src/Common/MsgEngine/inc/MsgSettings.h
src/Common/MsgEngine/src/MsgSettings.cpp
src/Common/Utils/inc/LangUtils.h
src/Conversation/Body/Controller/inc/Body.h
src/Conversation/Body/Controller/inc/Page.h
src/Conversation/Body/Controller/src/Body.cpp
src/Conversation/Body/Controller/src/Page.cpp

index 9439694..560b207 100644 (file)
@@ -36,6 +36,7 @@ namespace Msg
 
             int getMessageTextMaxChar() const;
             int getMessageMaxPage() const;
+            int getAttachmentsMaxCount() const;
             virtual int getAddressMaxLen() const = 0;
             virtual int getPhoneNumberMaxLen() const = 0;
             virtual int getAddressMaxCount() const = 0;
index 6c5429c..fa6f8d7 100644 (file)
@@ -23,7 +23,7 @@ using namespace Msg;
 
 const int defaultSmsGsm7MaxLen = 160;
 const int defaultSmsMaxPage = 3;
-
+const int defaultMaxAttachmentsCount = 10;
 
 MsgSettings::MsgSettings()
 {
@@ -45,6 +45,11 @@ int MsgSettings::getMessageMaxPage() const
     return defaultSmsMaxPage;
 }
 
+int MsgSettings::getAttachmentsMaxCount() const
+{
+    return defaultMaxAttachmentsCount;
+}
+
 void MsgSettings::addListener(IMsgSettingsListener &listener)
 {
     auto itr = std::find(m_Listeners.begin(), m_Listeners.end(), &listener);
index 9f068a0..0f74254 100644 (file)
@@ -98,10 +98,10 @@ namespace Msg
 
     #define msgt(strId) TText(strId, MSG_DOMAIN)
     #define msg(strId) DText(strId, MSG_DOMAIN)
-    #define msgArgs(strId, args) DText(0, strId, MSG_DOMAIN, args)
+    #define msgArgs(strId, ...) DText(0, strId, MSG_DOMAIN, __VA_ARGS__)
     #define sys(strId) DText(strId, SYS_DOMAIN)
     #define syst(strId) TText(strId, SYS_DOMAIN)
-    #define sysArgs(strId, args) DText(0, strId, SYS_DOMAIN, args)
+    #define sysArgs(strId, ...) DText(0, strId, SYS_DOMAIN, __VA_ARGS__)
 }
 
 #endif /* LangUtils_h_ */
index fa27352..cd0b7f8 100644 (file)
@@ -53,6 +53,7 @@ namespace Msg
             bool isMms();
             const MsgTextMetric &getTextMetric();
             long long getMsgSize();
+            int getAttachmentsCountTotal() const;
             void read(Message &msg);
             void write(const Message &msg);
             void execCmd(const AppControlComposeRef &cmd);
@@ -61,6 +62,8 @@ namespace Msg
         private:
             Page &createPage();
             void showTooLargePopup();
+            void showTooMuchAttachedPopup(int willBeAttached);
+            void showTooMuchAttachedPopup();
             void read(MessageSMS &msg);
             void read(MessageMms &msg);
             void readAttachments(MessageMms &msg);
@@ -71,6 +74,7 @@ namespace Msg
             void addAttachment( const std::string &filePath, const std::string &fileName = "");
 
             void onTooLargePopupDel(Evas_Object *obj, void *eventInfo);
+            void onTooMuchAttachedPopupDel(Evas_Object *obj, void *eventInfo);
 
             std::string createVcfFile(const AppControlComposeRef &cmd);
 
@@ -94,6 +98,7 @@ namespace Msg
             WorkingDirRef m_WorkingDir;
             Ecore_Idler *m_pOnChangedIdler;
             bool m_TooLargePopupShow;
+            bool m_TooMuchAttachedPopupShow;
     };
 
     class IBodyListener
index f09482f..48ea211 100644 (file)
@@ -36,6 +36,7 @@ namespace Msg
             Page(Body &parent, WorkingDirRef workingDir);
             virtual ~Page();
 
+            int getAttachmentsCount() const;
             const MsgTextMetric &getTextMetric();
             long long getSize();
             bool isMms();
index 27c8b74..768fdb5 100644 (file)
@@ -69,6 +69,7 @@ Body::Body(App &app, WorkingDirRef workingDir)
     , m_WorkingDir(workingDir)
     , m_pOnChangedIdler(nullptr)
     , m_TooLargePopupShow(false)
+    , m_TooMuchAttachedPopupShow(false)
 {
 }
 
@@ -106,8 +107,26 @@ void Body::setListener(IBodyListener *listener)
 bool Body::addMedia(const std::list<std::string> &fileList)
 {
     bool res = true;
+
+    int numAttached = getAttachmentsCountTotal();
+    int numToAttach = fileList.size();
+    int numAttachMax = m_App.getMsgEngine().getSettings().getAttachmentsMaxCount();
+
+    if((numAttached + numToAttach) > numAttachMax)
+    {
+        numToAttach = numAttachMax - numAttached;
+        if (numToAttach > 0)
+            showTooMuchAttachedPopup(numToAttach);
+    }
+
+    int i = 0;
     for(auto &file : fileList)
+    {
+        if (i > numToAttach)
+            break;
         res &= addMedia(file);
+        ++i;
+    }
     return res;
 }
 
@@ -115,6 +134,15 @@ bool Body::addMedia(const std::string &filePath)
 {
     MSG_LOG("Try add resource:", filePath);
 
+    int numAttached = getAttachmentsCountTotal();
+    int numAttachMax = m_App.getMsgEngine().getSettings().getAttachmentsMaxCount();
+
+    if(numAttached >= numAttachMax)
+    {
+        showTooMuchAttachedPopup();
+        return false;
+    }
+
     if(!FileUtils::isExists(filePath) || FileUtils::isDir(filePath))
     {
         MSG_LOG_ERROR("File not exists: ", filePath);
@@ -202,6 +230,17 @@ long long Body::getMsgSize()
     return size;
 }
 
+int Body::getAttachmentsCountTotal() const
+{
+    int count = getAttachments().size();
+
+    auto pages = getPages();
+    for(PageView *pageView : pages)
+        count += static_cast<Page*>(pageView)->getAttachmentsCount();
+
+    return count;
+}
+
 void Body::read(Message &msg)
 {
     MSG_LOG("");
@@ -380,6 +419,38 @@ void Body::showTooLargePopup()
    }
 }
 
+void Body::showTooMuchAttachedPopup(int willBeAttached)
+{
+   if(!m_TooMuchAttachedPopupShow)
+   {
+        Popup &popup = m_App.getPopupManager().getPopup();
+        popup.addEventCb(EVAS_CALLBACK_DEL, EVAS_EVENT_CALLBACK(Body, onTooMuchAttachedPopupDel), this);
+        popup.addButton(msgt("IDS_MSG_BUTTON_OK_ABB"), Popup::OkButtonId);
+        int maxCount = m_App.getMsgEngine().getSettings().getAttachmentsMaxCount();
+        std::string content(msgArgs("IDS_MSGF_BODY_MAXIMUM_NUMBER_OF_ATTACHMENTS_HP1SS_EXCEEDED_ONLY_FIRST_P2SS_WILL_BE_ADDED", std::to_string(maxCount).c_str(), std::to_string(willBeAttached).c_str()));
+        popup.setContent(content);
+        popup.setAutoDismissBlockClickedFlag(true);
+        popup.show();
+        m_TooMuchAttachedPopupShow = true;
+   }
+}
+
+void Body::showTooMuchAttachedPopup()
+{
+   if(!m_TooMuchAttachedPopupShow)
+   {
+        Popup &popup = m_App.getPopupManager().getPopup();
+        popup.addEventCb(EVAS_CALLBACK_DEL, EVAS_EVENT_CALLBACK(Body, onTooMuchAttachedPopupDel), this);
+        popup.addButton(msgt("IDS_MSG_BUTTON_OK_ABB"), Popup::OkButtonId);
+        int maxCount = m_App.getMsgEngine().getSettings().getAttachmentsMaxCount();
+        std::string content(msgArgs("IDS_MSGF_POP_MAXIMUM_NUMBER_OF_ATTACHMENTS_HPS_EXCEEDED", std::to_string(maxCount).c_str()));
+        popup.setContent(content);
+        popup.setAutoDismissBlockClickedFlag(true);
+        popup.show();
+        m_TooMuchAttachedPopupShow = true;
+   }
+}
+
 void Body::onRemoveMediaItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
@@ -404,6 +475,12 @@ void Body::onTooLargePopupDel(Evas_Object *obj, void *eventInfo)
     m_TooLargePopupShow = false;
 }
 
+void Body::onTooMuchAttachedPopupDel(Evas_Object *obj, void *eventInfo)
+{
+    MSG_LOG("");
+    m_TooMuchAttachedPopupShow = false;
+}
+
 std::string Body::createVcfFile(const AppControlComposeRef &cmd)
 {
     auto &idList = cmd->getVcfInfo().contactsIdList;
index fc10d61..2760b62 100644 (file)
@@ -89,6 +89,19 @@ long long Page::getSize()
     return totalSize;
 }
 
+int Page::getAttachmentsCount() const
+{
+    int res = 0;
+    auto items = getItems();
+    for(PageViewItem *item : items)
+    {
+        MediaPageViewItem *mediaItem = dynamic_cast<MediaPageViewItem*>(item);
+        if(mediaItem)
+            ++res;
+    }
+    return res;
+}
+
 bool Page::isMms()
 {
     auto pageItems = getItems();