From: Denis Dolzhenko Date: Fri, 18 Nov 2016 11:13:59 +0000 (+0200) Subject: TizenRefApp-7685 Check whether storage is full while copying message to sim-card X-Git-Tag: submit/tizen_3.0/20161118.143808^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=136051c8c46f7661c3718bffa974e8f8b5b151c8;p=profile%2Fmobile%2Fapps%2Fnative%2Fmessage.git TizenRefApp-7685 Check whether storage is full while copying message to sim-card Change-Id: Ie2796cc4bae62c2781a48b02de4b677b740420c1 Signed-off-by: Denis Dolzhenko --- diff --git a/src/Common/MsgEngine/inc/MsgStorage.h b/src/Common/MsgEngine/inc/MsgStorage.h index 8b661118..4556f905 100644 --- a/src/Common/MsgEngine/inc/MsgStorage.h +++ b/src/Common/MsgEngine/inc/MsgStorage.h @@ -38,6 +38,17 @@ namespace Msg */ class MsgStorage { + public: + /** + * @brief Possible results message storage could cause to. + */ + enum StorageResult + { + StorageSuccess = 0, /**< Storage successful.*/ + StorageFail = -1, /**< Storage failure.*/ + StorageSimFull = -2, /**< SIM storage is full.*/ + }; + public: MsgStorage(); virtual ~MsgStorage(); @@ -147,11 +158,12 @@ namespace Msg * @brief Commits edited message into message-storage in two optional way: * -# save existing message * -# create a copy of source message - * @param[out] msg message to be saved. + * @param[in] msg message to be saved. * @param[in] a updateExisting flag that defines a saving strategy. If true the existing message is saved, otherwise a new message-copy is created. + * @param[out] result of storage operation. * @return id of saved message. */ - virtual MsgId saveMessage(Message &msg, bool updateExisting) = 0; + virtual MsgId saveMessage(Message &msg, bool updateExisting, StorageResult *result = nullptr) = 0; /** * @brief Deletes single message with specified id. diff --git a/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp b/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp index ccac32ec..a9a09af5 100644 --- a/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp +++ b/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp @@ -23,6 +23,7 @@ #include "Logger.h" #include "MsgUtilsPrivate.h" #include "MsgReportPrivate.h" +#include "MsgEngine.h" #include #include @@ -317,8 +318,11 @@ MessageRef MsgStoragePrivate::getMessage(MsgId id) return msgRef; } -MsgId MsgStoragePrivate::saveMessage(Message &msg, bool updateExisting) +MsgId MsgStoragePrivate::saveMessage(Message &msg, bool updateExisting, StorageResult *result) { + if(result) + *result = StorageFail; + MsgId newMsgId; MessagePrivate &msgPriv = dynamic_cast(msg); @@ -328,22 +332,29 @@ MsgId MsgStoragePrivate::saveMessage(Message &msg, bool updateExisting) msgPriv.commit(); if(msgPriv.getId().isValid() && updateExisting) { - if(msg_update_message(m_ServiceHandle, msgPriv, sendOpt) == 0) - { + int err = msg_update_message(m_ServiceHandle, msgPriv, sendOpt); + if(result) + *result = MsgUtilsPrivate::nativeToStorageResult(err); + if(err == MSG_SUCCESS) newMsgId = msg.getId(); - } } else { - int tmpMsgId = msg_add_message(m_ServiceHandle, msgPriv, sendOpt); - if(tmpMsgId > 0) + newMsgId = msg_add_message(m_ServiceHandle, msgPriv, sendOpt); + if(newMsgId > 0) { - newMsgId = tmpMsgId; - msg_move_msg_to_storage(m_ServiceHandle, newMsgId, msg.getMessageStorageType()); + int err = msg_move_msg_to_storage(m_ServiceHandle, newMsgId, msg.getMessageStorageType()); + if(result) + *result = MsgUtilsPrivate::nativeToStorageResult(err); + if(err != MSG_SUCCESS) + { + MSG_LOG_WARN("Can't move msg to storage, error = ", MsgEngine::whatError(err)); + deleteMessage(newMsgId); + newMsgId.reset(); + } } } msg_release_struct(&sendOpt); - return newMsgId; } diff --git a/src/Common/MsgEngine/src/private/MsgStoragePrivate.h b/src/Common/MsgEngine/src/private/MsgStoragePrivate.h index c102bc31..e7abfcee 100644 --- a/src/Common/MsgEngine/src/private/MsgStoragePrivate.h +++ b/src/Common/MsgEngine/src/private/MsgStoragePrivate.h @@ -52,12 +52,13 @@ namespace Msg /** *@brief Return id of new message or of updated message - *@param[out] msg - message that we need to save + *@param[in] msg - message that we need to save *@param[in] updateExisting - true if we need to update our message id DB, * false if we need to save message with new id + *@param[out] result of storage operation. *@return MessageId */ - virtual MsgId saveMessage(Message &msg, bool updateExisting); + virtual MsgId saveMessage(Message &msg, bool updateExisting, StorageResult *result); virtual bool deleteMessage(MsgId id); virtual bool deleteMessages(const MsgIdList &idList); virtual MessageListRef searchMessage(const std::string &word); diff --git a/src/Common/MsgEngine/src/private/MsgUtilsPrivate.cpp b/src/Common/MsgEngine/src/private/MsgUtilsPrivate.cpp index 68879058..59219758 100644 --- a/src/Common/MsgEngine/src/private/MsgUtilsPrivate.cpp +++ b/src/Common/MsgEngine/src/private/MsgUtilsPrivate.cpp @@ -392,3 +392,18 @@ int MsgUtilsPrivate::ringtoneTypeToNative(MsgSettings::RingtoneType type) } return MSG_RINGTONE_TYPE_DEFAULT; } + +MsgStorage::StorageResult MsgUtilsPrivate::nativeToStorageResult(int resultCode) +{ + MsgStorage::StorageResult res = MsgStorage::StorageFail; + switch(resultCode) + { + case MSG_SUCCESS: + res = MsgStorage::StorageSuccess; + break; + case MSG_ERR_SIM_STORAGE_FULL: + res = MsgStorage::StorageSimFull; + break; + } + return res; +} diff --git a/src/Common/MsgEngine/src/private/MsgUtilsPrivate.h b/src/Common/MsgEngine/src/private/MsgUtilsPrivate.h index f8e40f1a..04eae910 100644 --- a/src/Common/MsgEngine/src/private/MsgUtilsPrivate.h +++ b/src/Common/MsgEngine/src/private/MsgUtilsPrivate.h @@ -23,6 +23,7 @@ #include "MsgUtils.h" #include "MsgSettings.h" #include "MsgTransport.h" +#include "MsgStorage.h" #include #include @@ -54,6 +55,7 @@ namespace Msg static MsgTransport::SendResult nativeToSendResult(int sendRes); static MsgSettings::RingtoneType nativeToRingtoneType(int type); static int ringtoneTypeToNative(MsgSettings::RingtoneType type); + static MsgStorage::StorageResult nativeToStorageResult(int resultCode); static std::string getStr(msg_struct_t msgStruct, int field, int maxStrLen); static int setStr(msg_struct_t msgStruct, int field, const std::string &text); diff --git a/src/Conversation/ConvList/Controller/inc/ConvListItem.h b/src/Conversation/ConvList/Controller/inc/ConvListItem.h index 727948a6..13b40868 100644 --- a/src/Conversation/ConvList/Controller/inc/ConvListItem.h +++ b/src/Conversation/ConvList/Controller/inc/ConvListItem.h @@ -97,6 +97,7 @@ namespace Msg void updateDownloadButton(); BubbleDownloadButtonEntity *findDownloadButton() const; void shareContent(); + void copyMsgToSimCard(); // Create Popup when message is clicked void showMainListPopup(); diff --git a/src/Conversation/ConvList/Controller/src/ConvListItem.cpp b/src/Conversation/ConvList/Controller/src/ConvListItem.cpp index d9d5d066..7e1c29e7 100644 --- a/src/Conversation/ConvList/Controller/src/ConvListItem.cpp +++ b/src/Conversation/ConvList/Controller/src/ConvListItem.cpp @@ -272,6 +272,22 @@ void ConvListItem::shareContent() } } +void ConvListItem::copyMsgToSimCard() +{ + MsgStorage::StorageResult result = MsgStorage::StorageFail; + MessageRef msg = m_App.getMsgEngine().getStorage().getMessage(m_MsgId); + if(msg) + { + msg->setMessageStorageType(Message::MS_Sim); + m_App.getMsgEngine().getStorage().saveMessage(*msg, false, &result); + + if(result == MsgStorage::StorageSimFull) + notification_status_message_post(msg("IDS_MSGF_BODY_SIM_MEMORY_FULL_DELETE_SOME_ITEMS").cStr()); + } + if(result == MsgStorage::StorageSuccess) + notification_status_message_post(msg("IDS_MSGC_POP_COPIED_TO_SIM_CARD").cStr()); +} + Evas_Object *ConvListItem::getBubbleContent() { auto *bubble = new BubbleItemContainer(*getOwner()); @@ -519,14 +535,7 @@ void ConvListItem::onCopyToSimCardItemPressed(PopupListItem &item) { MSG_LOG(""); item.getParent().destroy(); - MessageRef msg = m_App.getMsgEngine().getStorage().getMessage(m_MsgId); - if(msg) - { - msg->setMessageStorageType(Message::MS_Sim); - m_App.getMsgEngine().getStorage().saveMessage(*msg, false); - } - - notification_status_message_post(msg("IDS_MSGC_POP_COPIED_TO_SIM_CARD").cStr()); + copyMsgToSimCard(); } void ConvListItem::onViewDetailsItemPressed(PopupListItem &item) diff --git a/src/Settings/Controller/inc/MsgOnSimCard.h b/src/Settings/Controller/inc/MsgOnSimCard.h index d5c29f2b..d7663f5a 100644 --- a/src/Settings/Controller/inc/MsgOnSimCard.h +++ b/src/Settings/Controller/inc/MsgOnSimCard.h @@ -69,7 +69,6 @@ namespace Msg // IListViewListener: virtual void onListItemChecked(ListItem &listItem); - void checkHandler(SelectAllListItem &item); // IHwButtonListener: virtual void onHwMoreButtonClicked(); diff --git a/src/Settings/Controller/src/MsgOnSimCard.cpp b/src/Settings/Controller/src/MsgOnSimCard.cpp index 4c8b37aa..eeb4932f 100644 --- a/src/Settings/Controller/src/MsgOnSimCard.cpp +++ b/src/Settings/Controller/src/MsgOnSimCard.cpp @@ -117,13 +117,10 @@ void MsgOnSimCard::onButtonClicked(NaviFrameItem &item, NaviButtonId buttonId) void MsgOnSimCard::onListItemChecked(ListItem &listItem) { - if(SelectAllListItem *it = dynamic_cast(&listItem)) + if(dynamic_cast(&listItem)) { - checkHandler(*it); - } - else - { - MSG_LOG_ERROR("dynamic_cast was FAILED!"); + bool checked = listItem.getCheckedState(); + m_pList->checkAllItems(checked); } int check = 0; @@ -137,13 +134,6 @@ void MsgOnSimCard::onListItemChecked(ListItem &listItem) setTitleTranslatable(); } -void MsgOnSimCard::checkHandler(SelectAllListItem &item) -{ - bool checked = item.getCheckedState(); - m_pList->checkAllItems(checked); - getNaviBar().disabledButton(NaviOkButtonId, !checked); -} - void MsgOnSimCard::onHwMoreButtonClicked() { showCopyDeletePopup();