diff options
author | Denis Dolzhenko <d.dolzhenko@samsung.com> | 2017-08-01 11:30:28 +0300 |
---|---|---|
committer | Denis Dolzhenko <d.dolzhenko@samsung.com> | 2017-08-01 17:44:31 +0300 |
commit | b391fe8119f9693eaed5dbe6d707bbe19fda1ad4 (patch) | |
tree | d94b586821aa0dd50e3cdcce25ba05c54c5a5c47 | |
parent | 6113f7b888e64aa7ff4d18f5bfc0c27ccd515682 (diff) | |
download | message-b391fe8119f9693eaed5dbe6d707bbe19fda1ad4.tar.gz message-b391fe8119f9693eaed5dbe6d707bbe19fda1ad4.tar.bz2 message-b391fe8119f9693eaed5dbe6d707bbe19fda1ad4.zip |
TizenRefApp-8980 Implement blocked number feature in Conversation
Change-Id: I899cbc17af10849875b7448e8994f64b722a8a54
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
-rw-r--r-- | src/Common/Controller/src/FrameController.cpp | 1 | ||||
-rw-r--r-- | src/Common/Utils/inc/PhoneNumberUtils.h | 6 | ||||
-rw-r--r-- | src/Common/Utils/src/PhoneNumberUtils.cpp | 111 | ||||
-rw-r--r-- | src/Common/View/inc/MoreOption.h | 12 | ||||
-rw-r--r-- | src/Common/View/src/MoreOption.cpp | 22 | ||||
-rw-r--r-- | src/Conversation/Controller/inc/ConvFrame.h | 6 | ||||
-rw-r--r-- | src/Conversation/Controller/src/ConvFrame.cpp | 58 | ||||
-rw-r--r-- | tizen-manifest.xml | 2 |
8 files changed, 181 insertions, 37 deletions
diff --git a/src/Common/Controller/src/FrameController.cpp b/src/Common/Controller/src/FrameController.cpp index dceed8f..b5c83a1 100644 --- a/src/Common/Controller/src/FrameController.cpp +++ b/src/Common/Controller/src/FrameController.cpp @@ -78,6 +78,7 @@ void FrameController::addToGroup(FrameController &frame) return; m_GroupList->merge(*frame.m_GroupList); + m_GroupList->sort(); m_GroupList->unique(); frame.m_GroupList = m_GroupList; } diff --git a/src/Common/Utils/inc/PhoneNumberUtils.h b/src/Common/Utils/inc/PhoneNumberUtils.h index 4ecacee..ee0b004 100644 --- a/src/Common/Utils/inc/PhoneNumberUtils.h +++ b/src/Common/Utils/inc/PhoneNumberUtils.h @@ -18,6 +18,7 @@ #define __PhoneNumberUtils_H__ #include <string> +#include <list> namespace Msg { class PhoneNumberUtils { @@ -25,6 +26,11 @@ namespace Msg { static PhoneNumberUtils &getInst(); std::string getNormalizedNumber(const std::string &number) const; + bool addToBlocked(const std::string &number); + bool removeFromBlocked(const std::string &number); + std::list<std::string> getBlockedNumList() const; + bool isBlocked(const std::string &number); + private: PhoneNumberUtils(); ~PhoneNumberUtils(); diff --git a/src/Common/Utils/src/PhoneNumberUtils.cpp b/src/Common/Utils/src/PhoneNumberUtils.cpp index 86d093b..b6822b3 100644 --- a/src/Common/Utils/src/PhoneNumberUtils.cpp +++ b/src/Common/Utils/src/PhoneNumberUtils.cpp @@ -22,24 +22,26 @@ using namespace Msg; - PhoneNumberUtils &PhoneNumberUtils::getInst() - { - static PhoneNumberUtils inst; - return inst; - } - - std::string PhoneNumberUtils::getNormalizedNumber(const std::string &number) const - { - std::string res; - char *normalizedNum = nullptr; - phone_number_get_normalized_number(number.c_str(), &normalizedNum); - if (normalizedNum) - { - res = normalizedNum; - free(normalizedNum); - } - return res; - } +PhoneNumberUtils &PhoneNumberUtils::getInst() +{ + static PhoneNumberUtils inst; + return inst; +} + +std::string PhoneNumberUtils::getNormalizedNumber(const std::string &number) const +{ + std::string res; + char *normalizedNum = nullptr; + phone_number_get_normalized_number(number.c_str(), &normalizedNum); + if (normalizedNum) { + res = normalizedNum; + free(normalizedNum); + } + if (res.empty()) + res = number; + + return res; +} PhoneNumberUtils::PhoneNumberUtils() { @@ -51,3 +53,76 @@ PhoneNumberUtils::~PhoneNumberUtils() { phone_number_disconnect(); } + +bool PhoneNumberUtils::addToBlocked(const std::string &number) +{ + if (number.empty()) + return false; + + bool res = false; + + phone_number_blocking_rule_h rule = nullptr; + phone_number_blocking_rule_create(&rule); + if (rule) { + phone_number_blocking_rule_set_match_type(rule, PHONE_NUMBER_MATCH_TYPE_EXACTLY); + phone_number_blocking_rule_set_number(rule, number.c_str()); + res = phone_number_add_blocking_rule(rule) == 0; + phone_number_blocking_rule_destroy(rule); + } + + return res; +} + +bool PhoneNumberUtils::removeFromBlocked(const std::string &number) +{ + if (number.empty()) + return false; + + bool res = false; + int count = 0; + phone_number_blocking_rule_h *rules = nullptr; + phone_number_get_blocking_rules_related(number.c_str(), &rules, &count); + if (rules) { + res = true; + for (int i = 0; i < count; ++i) { + res &= phone_number_remove_blocking_rule(rules[i]) == 0; + phone_number_blocking_rule_destroy(rules[i]); + } + free(rules); + } + + return res; +} + +std::list<std::string> PhoneNumberUtils::getBlockedNumList() const +{ + std::list<std::string> res; + + phone_number_blocking_rule_h *rules = nullptr; + int length = 0; + phone_number_get_blocking_rules(0, 0, &rules, &length); + for (int i = 0; i < length; i++) { + phone_number_blocking_rule_h rule = rules[i]; + if (rule) { + char *number = nullptr; + phone_number_blocking_rule_get_number(rule, &number); + if (number) + res.push_back(number); + free(number); + phone_number_blocking_rule_destroy(rule); + } + } + + free(rules); + res.sort(); + res.unique(); + + return res; +} + +bool PhoneNumberUtils::isBlocked(const std::string &number) +{ + bool res = false; + phone_number_check_blocking(number.c_str(), &res); + return res; +} diff --git a/src/Common/View/inc/MoreOption.h b/src/Common/View/inc/MoreOption.h index ace1f94..41918ef 100644 --- a/src/Common/View/inc/MoreOption.h +++ b/src/Common/View/inc/MoreOption.h @@ -54,6 +54,18 @@ namespace Msg { MoreOptionCb cb, void *userData); + Eext_Object_Item *insertItemBefore(Eext_Object_Item *before, + const TText &mainText, + const std::string &imgGroupName, + MoreOptionCb cb, + void *userData); + + Eext_Object_Item *insertItemBefore(Eext_Object_Item *before, + const TText &mainText, + Evas_Object *icon, + MoreOptionCb cb, + void *userData); + void removeItem(Eext_Object_Item *item); void setDirection(Eext_More_Option_Direction direction); void setOpened(bool opened); diff --git a/src/Common/View/src/MoreOption.cpp b/src/Common/View/src/MoreOption.cpp index cb4dc95..6405226 100644 --- a/src/Common/View/src/MoreOption.cpp +++ b/src/Common/View/src/MoreOption.cpp @@ -89,6 +89,28 @@ Eext_Object_Item *MoreOption::prependItem(const TText &mainText, return item; } +Eext_Object_Item *MoreOption::insertItemBefore(Eext_Object_Item *before, + const TText &mainText, + const std::string &imgGroupName, + MoreOptionCb cb, + void *userData) +{ + auto *item = eext_more_option_item_insert_before(getEo(), before); + prepareItem(item, mainText, imgGroupName, cb, userData); + return item; +} + +Eext_Object_Item *MoreOption::insertItemBefore(Eext_Object_Item *before, + const TText &mainText, + Evas_Object *icon, + MoreOptionCb cb, + void *userData) +{ + auto *item = eext_more_option_item_insert_before(getEo(), before); + prepareItem(item, mainText, icon, cb, userData); + return item; +} + Eext_Object_Item *MoreOption::prependItem(const TText &mainText, const std::string &imgGroupName, MoreOptionCb cb, diff --git a/src/Conversation/Controller/inc/ConvFrame.h b/src/Conversation/Controller/inc/ConvFrame.h index 3c27aa1..ee945cf 100644 --- a/src/Conversation/Controller/inc/ConvFrame.h +++ b/src/Conversation/Controller/inc/ConvFrame.h @@ -40,7 +40,6 @@ namespace Msg virtual ~ConvFrame(); void setThreadId(ThreadId id); - void execCmd(const AppControlComposeRef &cmd); void execCmd(const AppControlDefaultRef &cmd); private: @@ -60,7 +59,6 @@ namespace Msg // MoreOption: void onReplyClicked(MoreOption &obj); void onCallClicked(MoreOption &obj); - void onSendMyLocationClicked(MoreOption &obj); void onRecipientsClicked(MoreOption &obj); void onBlockNumberClicked(MoreOption &obj); void onUnblockNumberClicked(MoreOption &obj); @@ -108,8 +106,10 @@ namespace Msg void updateDeleteViews(); void reply(); void updateMoreOption(); - void prepedItem(MorOptionItemType itemType); + void prependItem(MorOptionItemType itemType); void removeItem(MorOptionItemType itemType); + void insertItemBefore(MorOptionItemType itemType, MorOptionItemType beforeType); + void updateBlockMoreOptionItem(); void navigateToReicpList(); void setMode(Mode mode); diff --git a/src/Conversation/Controller/src/ConvFrame.cpp b/src/Conversation/Controller/src/ConvFrame.cpp index bb78cab..bee46a6 100644 --- a/src/Conversation/Controller/src/ConvFrame.cpp +++ b/src/Conversation/Controller/src/ConvFrame.cpp @@ -26,6 +26,7 @@ #include "VoiceCall.h" #include "NaviFrameController.h" #include "RecipListFrame.h" +#include "PhoneNumberUtils.h" using namespace Msg; @@ -97,11 +98,6 @@ void ConvFrame::setDeleteMode(bool value) } } -void ConvFrame::execCmd(const AppControlComposeRef &cmd) -{ - // TODO: impl. -} - void ConvFrame::execCmd(const AppControlDefaultRef &cmd) { // TODO: impl. @@ -143,8 +139,8 @@ void ConvFrame::prepareMoreOption() m_MoreOptionItemsInfo[MorOptionDelete] = {nullptr, "WDS_MSG_OPT_DELETE_ABB", DELETEG_MORE_ICON, makeCbLast(&ConvFrame::onDeleteClicked)}; - prepedItem(MorOptionDelete); - prepedItem(MorOptionRecip); + prependItem(MorOptionDelete); + prependItem(MorOptionRecip); } } @@ -173,8 +169,9 @@ void ConvFrame::prepareList() } } -void ConvFrame::prepedItem(MorOptionItemType itemType) +void ConvFrame::prependItem(MorOptionItemType itemType) { + removeItem(itemType); MoreOptionItemInfo &info = m_MoreOptionItemsInfo[itemType]; if (!info.item) info.item = m_pMoreOption->prependItem(msgt(info.strId), info.icon, info.cb, this); @@ -189,6 +186,30 @@ void ConvFrame::removeItem(MorOptionItemType itemType) } } +void ConvFrame::insertItemBefore(MorOptionItemType itemType, MorOptionItemType beforeType) +{ + Eext_Object_Item *before = m_MoreOptionItemsInfo[beforeType].item; + if (before) { + removeItem(itemType); + MoreOptionItemInfo &info = m_MoreOptionItemsInfo[itemType]; + info.item = m_pMoreOption->insertItemBefore(before, msgt(info.strId), info.icon, info.cb, this); + } else { + MSG_LOG_ERROR("MorOptionItemType: ", beforeType, " is null"); + } +} + +void ConvFrame::updateBlockMoreOptionItem() +{ + removeItem(MorOptionBlock); + removeItem(MorOptionUnblock); + const Recipient &recip = m_pList->getRecip(); + if (recip.isValid()) { + bool isBlocked = PhoneNumberUtils::getInst().isBlocked(recip.getAddress()); + MorOptionItemType blockedType = isBlocked ? MorOptionUnblock : MorOptionBlock; + insertItemBefore(blockedType, MorOptionDelete); + } +} + void ConvFrame::navigateToReicpList() { auto *frame = new RecipListFrame(getParent()); @@ -245,13 +266,14 @@ void ConvFrame::updateMoreOption() { bool isValid = m_pList->getRecip().isValid(); if (isValid) { - prepedItem(MorOptionCall); - prepedItem(MorOptionReply); + prependItem(MorOptionCall); + prependItem(MorOptionReply); } else { removeItem(MorOptionReply); removeItem(MorOptionCall); } + updateBlockMoreOptionItem(); } void ConvFrame::showNumberBlockUnblockPopup(bool isBlocked) @@ -351,11 +373,6 @@ void ConvFrame::onCallClicked(MoreOption &obj) VoiceCall::launch(m_pList->getRecip().getAddress()); } -void ConvFrame::onSendMyLocationClicked(MoreOption &obj) -{ - MSG_LOG(""); -} - void ConvFrame::onRecipientsClicked(MoreOption &obj) { MSG_LOG(""); @@ -365,12 +382,21 @@ void ConvFrame::onRecipientsClicked(MoreOption &obj) void ConvFrame::onBlockNumberClicked(MoreOption &obj) { MSG_LOG(""); - showNumberBlockUnblockPopup(true); + const Recipient &recip = m_pList->getRecip(); + if (recip.isValid() && PhoneNumberUtils::getInst().addToBlocked(recip.getAddress())) { + showNumberBlockUnblockPopup(true); + updateBlockMoreOptionItem(); + } } void ConvFrame::onUnblockNumberClicked(MoreOption &obj) { MSG_LOG(""); + const Recipient &recip = m_pList->getRecip(); + if (recip.isValid() && PhoneNumberUtils::getInst().removeFromBlocked(recip.getAddress())) { + showNumberBlockUnblockPopup(false); + updateBlockMoreOptionItem(); + } } void ConvFrame::onDeleteClicked(MoreOption &obj) diff --git a/tizen-manifest.xml b/tizen-manifest.xml index 1deadff..0238a4d 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -115,6 +115,8 @@ <privilege>http://tizen.org/privilege/contact.read</privilege> <privilege>http://tizen.org/privilege/mediastorage</privilege> <privilege>http://tizen.org/privilege/externalstorage</privilege> + <privilege>http://tizen.org/privilege/blocknumber.write</privilege> + <privilege>http://tizen.org/privilege/blocknumber.read</privilege> </privileges> <feature name="http://tizen.org/feature/screen.size.normal">true</feature> <feature name="http://tizen.org/feature/network.telephony">true</feature> |