TizenRefApp-6280 Contact-attachment support 95/80895/2
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Wed, 20 Jul 2016 14:51:29 +0000 (17:51 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Wed, 20 Jul 2016 14:52:36 +0000 (17:52 +0300)
Change-Id: I7abc324594c7958d7aadb7e3c8a2b68391ed74ec
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
15 files changed:
src/Common/ContactManager/inc/Contact.h
src/Common/ContactManager/inc/ContactList.h
src/Common/ContactManager/inc/ContactRecord.h
src/Common/Utils/inc/ThumbnailMaker.h
src/Common/Utils/src/ThumbnailMaker.cpp
src/Conversation/ContactList/Controller/inc/ContactListItem.h
src/Conversation/ConvList/Controller/inc/ConvList.h
src/Conversation/ConvList/Controller/inc/ConvListItem.h
src/Conversation/ConvList/Controller/src/ConvList.cpp
src/Conversation/ConvList/Controller/src/ConvListItem.cpp
src/Conversation/ConvList/View/inc/BubbleContactViewItem.h [new file with mode: 0644]
src/Conversation/ConvList/View/inc/BubbleIconTextLayoutItem.h
src/Conversation/ConvList/View/src/BubbleContactViewItem.cpp [new file with mode: 0644]
src/Conversation/ConvList/View/src/BubbleIconTextLayoutItem.cpp
src/MsgThread/Controller/inc/BaseThreadListItem.h

index d677810..7da51bd 100644 (file)
@@ -38,6 +38,7 @@ namespace Msg
             std::string getPhoneNumber() const;
             std::string getEmail() const;
             std::string getThumb() const;
+            std::string getAddress() const;
     };
 
     inline Contact::Contact(bool release, contacts_record_h record)
@@ -52,18 +53,34 @@ namespace Msg
 
     inline std::string Contact::getPhoneNumber() const
     {
-        return getStr(_contacts_contact.number);
+        std::string res;
+        int count = getChildCount(_contacts_contact.number);
+        if(count > 0)
+            res = getStr(getChildP(_contacts_contact.number, 0), _contacts_number.number);
+        return res;
     }
 
     inline std::string Contact::getEmail() const
     {
-        return getStr(_contacts_contact.email);
+        std::string res;
+        int count = getChildCount(_contacts_contact.email);
+        if(count > 0)
+            res = getStr(getChildP(_contacts_contact.number, 0), _contacts_email.email);
+        return res;
     }
 
     inline std::string Contact::getThumb() const
     {
         return getStr(_contacts_contact.image_thumbnail_path);
     }
+
+    inline std::string Contact::getAddress() const
+    {
+        std::string address = getPhoneNumber();
+        if(address.empty())
+            address = getEmail();
+        return address;
+    }
 }
 
 #endif /* __Contact_h__ */
index 12a7766..2350e3a 100644 (file)
@@ -66,6 +66,11 @@ namespace Msg
                 return count;
             }
 
+            bool isEmpty() const
+            {
+                return getCount() <= 0;
+            }
+
         private:
             contacts_list_h m_List;
             T m_Record;
index fe95823..c324c44 100644 (file)
@@ -40,6 +40,13 @@ namespace Msg
         protected:
             std::string getStr(unsigned propertyId) const;
             int getInt(unsigned propertyId) const;
+            int getChildCount(unsigned propertyId) const;
+            contacts_record_h getChildP(unsigned propertyId, int index) const;
+
+            static std::string getStr(contacts_record_h rec, unsigned propertyId);
+            static int getInt(contacts_record_h rec, unsigned propertyId);
+            static int getChildCount(contacts_record_h rec, unsigned propertyId);
+            static contacts_record_h getChildP(contacts_record_h rec, unsigned propertyId, int index);
 
         private:
             contacts_record_h m_Record;
@@ -51,25 +58,58 @@ namespace Msg
         m_Record = record;
     }
 
-    inline std::string ContactRecord::getStr(unsigned propertyId) const
+    inline contacts_record_h ContactRecord::getRecord() const
+    {
+        return m_Record;
+    }
+
+    inline std::string ContactRecord::getStr(contacts_record_h rec, unsigned propertyId)
     {
         char *str = nullptr;
-        contacts_record_get_str_p(m_Record, propertyId, &str);
+        contacts_record_get_str_p(rec, propertyId, &str);
         return str ? str : std::string();
     }
 
-    inline int ContactRecord::getInt(unsigned propertyId) const
+    inline int ContactRecord::getChildCount(contacts_record_h rec, unsigned propertyId)
+    {
+        int count = 0;
+        contacts_record_get_child_record_count(rec, propertyId, &count);
+        return count;
+    }
+
+    inline contacts_record_h ContactRecord::getChildP(contacts_record_h rec, unsigned propertyId, int index)
+    {
+        contacts_record_h res = {};
+        contacts_record_get_child_record_at_p(rec, propertyId, index, &res);
+        return res;
+    }
+
+    inline int ContactRecord::getInt(contacts_record_h rec, unsigned propertyId)
     {
         int val = 0;
-        contacts_record_get_int(m_Record, propertyId, &val);
+        contacts_record_get_int(rec, propertyId, &val);
         return val;
     }
 
-    inline contacts_record_h ContactRecord::getRecord() const
+    inline std::string ContactRecord::getStr(unsigned propertyId) const
     {
-        return m_Record;
+        return getStr(m_Record, propertyId);
+    }
+
+    inline int ContactRecord::getChildCount(unsigned propertyId) const
+    {
+        return getChildCount(m_Record, propertyId);
     }
 
+    inline contacts_record_h ContactRecord::getChildP(unsigned propertyId, int index) const
+    {
+        return getChildP(m_Record, propertyId, index);
+    }
+
+    inline int ContactRecord::getInt(unsigned propertyId) const
+    {
+        return getInt(m_Record, propertyId);
+    }
 }
 
 #endif /* __ContactRecord_h__ */
index 76169af..9c16b3a 100644 (file)
 namespace Msg
 {
     class App;
+    typedef long ThumbId;
 
     class ThumbnailMaker
         : public IContactManagerListener
     {
         public:
-            typedef long ThumbId;
             enum DefaultThumbs
             {
                 SingleThumb = 0, // Static thumb
index a42e2f2..6da0526 100644 (file)
@@ -53,18 +53,18 @@ ThumbnailMaker::~ThumbnailMaker()
     m_App.getContactManager().removeListener(*this);
 }
 
-ThumbnailMaker::ThumbId ThumbnailMaker::getThumbId(const MsgAddress &address)
+ThumbId ThumbnailMaker::getThumbId(const MsgAddress &address)
 {
     return getThumbId(address.getAddress());
 }
 
-ThumbnailMaker::ThumbId ThumbnailMaker::getThumbId(const std::string &address)
+ThumbId ThumbnailMaker::getThumbId(const std::string &address)
 {
     ContactAddressRef contact = m_App.getContactManager().getContactAddress(address);
     return contact ? getThumbIdFromFile(contact->getThumbnailPath()) : getThumbId(SingleThumb);
 }
 
-ThumbnailMaker::ThumbId ThumbnailMaker::getThumbIdFromFile(const std::string &path)
+ThumbId ThumbnailMaker::getThumbIdFromFile(const std::string &path)
 {
     if(path.empty())
     {
@@ -83,7 +83,7 @@ ThumbnailMaker::ThumbId ThumbnailMaker::getThumbIdFromFile(const std::string &pa
     }
 }
 
-ThumbnailMaker::ThumbId ThumbnailMaker::getThumbId(DefaultThumbs thumb)
+ThumbId ThumbnailMaker::getThumbId(DefaultThumbs thumb)
 {
     auto it = m_ContactsMap.find(defaultThumbsToStr(thumb));
     if(it != m_ContactsMap.end())
index 6ddb155..991c186 100644 (file)
@@ -44,7 +44,7 @@ namespace Msg
         private:
             App &m_App;
             std::string m_Recipient;
-            ThumbnailMaker::ThumbId m_ThumbId;
+            ThumbId m_ThumbId;
             std::string m_MainText;
             std::string m_SubText;
     };
index 824e7fe..abd2cac 100644 (file)
@@ -171,7 +171,7 @@ namespace Msg
             App &m_App;
             WorkingDirRef m_WorkingDir;
             FileViewer m_FileViewer;
-            ThumbnailMaker::ThumbId m_RecipThumbId;
+            ThumbId m_RecipThumbId;
             std::string m_SearchWord;
     };
 
index 13f1baf..567f5d6 100644 (file)
@@ -53,7 +53,7 @@ namespace Msg
                          FileViewer &fileViewer,
                          WorkingDirRef workingDir,
                          const std::string &searchWord,
-                         const ThumbnailMaker::ThumbId &thumbId = -1);
+                         const ThumbId &thumbId = -1);
 
             virtual ~ConvListItem();
 
@@ -92,8 +92,9 @@ namespace Msg
             void addTextItem(const MsgConvMedia &media, const std::string &searchWord);
             void addTextItem(std::string text, bool markup, const std::string &searchWord);
             void addImageItem(const MsgConvMedia &media);
-            void addAttachedFileItem(const MsgConvMedia &media);
+            void addUnknownFileItem(const MsgConvMedia &media);
             void addCalendarItem(const MsgConvMedia &media);
+            void addContactItem(const MsgConvMedia &media);
 
             // Create Popup when message is clicked
             void showMainListPopup();
@@ -132,7 +133,7 @@ namespace Msg
             time_t m_Time;
             std::string m_TimeStr;
             std::list<BubbleEntity*> m_BubbleEntityList;
-            const ThumbnailMaker::ThumbId &m_ThumbId;
+            const ThumbId &m_ThumbId;
     };
 
     class IConvListItemListener
index fb1f12a..fe49062 100644 (file)
@@ -183,8 +183,8 @@ ConvListItem *ConvList::getItem(MsgId msgId) const
 
 void ConvList::appendItem(const MsgConversationItem &item)
 {
-    static const ThumbnailMaker::ThumbId invalidId = -1;
-    const ThumbnailMaker::ThumbId &thumbId = item.getDirection() == Message::MD_Received ? m_RecipThumbId : invalidId;
+    static const ThumbId invalidId = -1;
+    const ThumbId &thumbId = item.getDirection() == Message::MD_Received ? m_RecipThumbId : invalidId;
     appendItem(new ConvListItem(item, m_App, m_FileViewer, m_WorkingDir, m_SearchWord, thumbId));
 }
 
index 434b458..8dc4c8b 100644 (file)
@@ -29,6 +29,7 @@
 #include "TimeUtils.h"
 #include "FileViewer.h"
 #include "BubbleItemContainer.h"
+#include "ContactManager.h"
 
 // Bubble items:
 #include "BubbleTextViewItem.h"
@@ -38,6 +39,7 @@
 #include "BubbleDownloadButtonViewItem.h"
 #include "BubbleUnknownFileViewItem.h"
 #include "BubbleCalEventViewItem.h"
+#include "BubbleContactViewItem.h"
 
 #include <notification_status.h>
 #include <sstream>
@@ -71,6 +73,14 @@ namespace
            << std::setfill('0') << std::setw(2) << m;
         return ss.str();
     }
+
+    std::string getFileName(const MsgConvMedia &media)
+    {
+        std::string res = media.getName();
+        if(res.empty())
+            res = FileUtils::getFileName(media.getPath());
+        return res;
+    }
 }
 
 ConvListItem::ConvListItem(const MsgConversationItem &item,
@@ -78,7 +88,7 @@ ConvListItem::ConvListItem(const MsgConversationItem &item,
                            FileViewer &fileViewer,
                            WorkingDirRef workingDir,
                            const std::string &searchWord,
-                           const ThumbnailMaker::ThumbId &thumbId)
+                           const ThumbId &thumbId)
     : ConvListViewItem(getConvItemType(item))
     , m_pListener(nullptr)
     , m_App(app)
@@ -175,14 +185,10 @@ void ConvListItem::addAudioItem(const MsgConvMedia &media)
     m_BubbleEntityList.push_back(entity);
 }
 
-void ConvListItem::addAttachedFileItem(const MsgConvMedia &media)
+void ConvListItem::addUnknownFileItem(const MsgConvMedia &media)
 {
-    std::string dsipName = media.getName();
-    std::string path = media.getPath();
-    if(dsipName.empty())
-        dsipName = FileUtils::getFileName(path);
-
-    auto *entity = new BubbleUnknownFileEntity(path, dsipName);
+    std::string dsipName = getFileName(media);
+    auto *entity = new BubbleUnknownFileEntity(media.getPath(), dsipName);
     m_BubbleEntityList.push_back(entity);
 }
 
@@ -198,6 +204,28 @@ void ConvListItem::addCalendarItem(const MsgConvMedia &media)
     }
 }
 
+void ConvListItem::addContactItem(const MsgConvMedia &media)
+{
+    auto list = m_App.getContactManager().parseVcard(media.getPath());
+    if(list && !list->isEmpty())
+    {
+        BubbleContactEntity *entity = nullptr;
+
+        if(list->getCount() > 1)
+        {
+            std::string fileName = getFileName(media);
+            entity = new BubbleContactEntity(m_App.getThumbnailMaker(), media.getPath(), fileName);
+        }
+        else
+        {
+            const Contact &rec = list->get();
+            entity = new BubbleContactEntity(m_App.getThumbnailMaker(), media.getPath(), rec.getDispName(), rec.getAddress());
+        }
+        if(entity)
+            m_BubbleEntityList.push_back(entity);
+     }
+}
+
 void ConvListItem::addDownloadButtonItem()
 {
     auto *entity = new BubbleDownloadButtonEntity;
@@ -253,8 +281,8 @@ void ConvListItem::prepareBubble(const MsgConversationItem &item, const std::str
             const MsgConvMedia &media = list.at(i);
             std::string mime = media.getMime();
             MsgMedia::Type msgMediaType = getMsgMediaTypeByMime(mime);
-
             std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
+
             switch(msgMediaType)
             {
                 case MsgMedia::TextType:
@@ -272,8 +300,10 @@ void ConvListItem::prepareBubble(const MsgConversationItem &item, const std::str
                 default:
                     if(mime == "text/x-vcalendar" || mime == "text/calendar")
                         addCalendarItem(media);
+                    if(mime == "text/x-vcard" || mime == "text/vcard")
+                        addContactItem(media);
                     else if(mime != "application/smil")
-                        addAttachedFileItem(media);
+                        addUnknownFileItem(media);
                     break;
             }
         }
diff --git a/src/Conversation/ConvList/View/inc/BubbleContactViewItem.h b/src/Conversation/ConvList/View/inc/BubbleContactViewItem.h
new file mode 100644 (file)
index 0000000..26d5d42
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef BubbleContactViewItem_h_
+#define BubbleContactViewItem_h_
+
+#include "BubbleIconTextLayoutItem.h"
+#include "ThumbnailMaker.h"
+
+namespace Msg
+{
+    class BubbleContactViewItem
+        : public BubbleIconTextLayoutItem
+    {
+        public:
+            BubbleContactViewItem(BubbleEntity &entity, Evas_Object *parent, LayoutType type);
+            virtual ~BubbleContactViewItem();
+    };
+
+    class BubbleContactEntity
+        : public BubbleEntity
+    {
+        public:
+            BubbleContactEntity(ThumbnailMaker &thumbMaker, const std::string &filePath, const std::string &fileName);
+            BubbleContactEntity(ThumbnailMaker &thumbMaker, const std::string &filePath, const std::string &dispName, const std::string &address);
+            virtual ~BubbleContactEntity();
+
+            void setThumbId(ThumbId id);
+            virtual BubbleContactViewItem *createView(Evas_Object *parent);
+            virtual const std::string &getFilePath() const;
+
+        private:
+            ThumbnailMaker &m_ThumbMaker;
+            const std::string m_FilePath;
+            const std::string m_Name;
+            const std::string m_Address;
+            ThumbId m_ThumbId;
+    };
+}
+
+#endif /* BubbleContactViewItem_h_ */
index 79724e2..1f2f348 100644 (file)
@@ -31,16 +31,21 @@ namespace Msg
                 Layout1Icon1Text,
                 Layout1Icon2Text
             };
+            static const int iconSize = 50;
 
         public:
             BubbleIconTextLayoutItem(BubbleEntity &entity, Evas_Object *parent, LayoutType layoutType);
             virtual ~BubbleIconTextLayoutItem();
 
+            LayoutType getLayoutType() const;
             void setIcon(Evas_Object *icon);
             void setMainText(const std::string &text);
             void setSubText(const std::string &text);
 
             static Evas_Object *createIcon(Evas_Object *parent, const std::string &edjFileName);
+
+        private:
+            LayoutType m_LayoutType;
     };
 }
 
diff --git a/src/Conversation/ConvList/View/src/BubbleContactViewItem.cpp b/src/Conversation/ConvList/View/src/BubbleContactViewItem.cpp
new file mode 100644 (file)
index 0000000..4e50ac6
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "BubbleContactViewItem.h"
+#include "Resource.h"
+
+using namespace Msg;
+
+BubbleContactViewItem::BubbleContactViewItem(BubbleEntity &entity, Evas_Object *parent, LayoutType type)
+    : BubbleIconTextLayoutItem(entity, parent, type)
+{
+    attachGestureTapLayer(getEo(), getEo());
+}
+
+BubbleContactViewItem::~BubbleContactViewItem()
+{
+}
+
+BubbleContactEntity::BubbleContactEntity(ThumbnailMaker &thumbMaker, const std::string &filePath, const std::string &fileName)
+    : BubbleContactEntity(thumbMaker, filePath, fileName, {})
+{
+
+}
+
+BubbleContactEntity::BubbleContactEntity(ThumbnailMaker &thumbMaker, const std::string &filePath, const std::string &dispName, const std::string &address)
+    : BubbleEntity(ContactItem)
+    , m_FilePath(filePath)
+    , m_Name(dispName)
+    , m_Address(address)
+    , m_ThumbId(ThumbnailMaker::SingleThumb)
+    , m_ThumbMaker(thumbMaker)
+{
+}
+
+BubbleContactEntity::~BubbleContactEntity()
+{
+}
+
+BubbleContactViewItem *BubbleContactEntity::createView(Evas_Object *parent)
+{
+    BubbleContactViewItem::LayoutType type = m_Address.empty() ? BubbleContactViewItem::Layout1Icon1Text : BubbleContactViewItem::Layout1Icon2Text;
+    auto *item = new BubbleContactViewItem(*this, parent, type);
+    item->setIcon(m_ThumbMaker.getThumbById(*item, m_ThumbId, BubbleContactViewItem::iconSize));
+    item->setMainText(m_Name);
+    if(!m_Address.empty())
+        item->setSubText(m_Address);
+    return item;
+}
+
+const std::string &BubbleContactEntity::getFilePath() const
+{
+    return m_FilePath;
+}
+
+void BubbleContactEntity::setThumbId(ThumbId id)
+{
+    m_ThumbId = id;
+}
index 188e3c7..18b6dda 100644 (file)
@@ -26,6 +26,7 @@ using namespace Msg;
 
 BubbleIconTextLayoutItem::BubbleIconTextLayoutItem(BubbleEntity &entity, Evas_Object *parent, LayoutType layoutType)
     : BubbleViewItem(entity)
+    , m_LayoutType(layoutType)
 {
     const char *group = nullptr;
     switch(layoutType)
@@ -72,3 +73,8 @@ Evas_Object *BubbleIconTextLayoutItem::createIcon(Evas_Object *parent, const std
     evas_object_show(icon);
     return icon;
 }
+
+BubbleIconTextLayoutItem::LayoutType BubbleIconTextLayoutItem::getLayoutType() const
+{
+    return m_LayoutType;
+}
index 7362049..ae5c5e4 100644 (file)
@@ -55,7 +55,7 @@ namespace Msg
             virtual Evas_Object *getThumbnail();
 
             App &m_App;
-            ThumbnailMaker::ThumbId m_ThumbId;
+            ThumbId m_ThumbId;
             std::string m_Name;
             std::string m_Message;
             std::string m_Time;