TizenRefApp-8235 Implement ConvListItem controller 59/120859/4
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 24 Mar 2017 08:53:55 +0000 (10:53 +0200)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 24 Mar 2017 15:23:04 +0000 (17:23 +0200)
+ Add WorkingDir class

Change-Id: Icc2ffc53d5e79ea75821ec1471ace266a80b3683
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
15 files changed:
.cproject
src/Common/MsgEngine/src/dummy/MsgConversationItemDummy.cpp
src/Common/MsgEngine/src/dummy/MsgUtilsDummy.cpp
src/Common/Utils/inc/WorkingDir.h [new file with mode: 0644]
src/Common/Utils/src/WorkingDir.cpp [new file with mode: 0644]
src/Conversation/Controller/inc/BubbleEntityFactory.h [new file with mode: 0644]
src/Conversation/Controller/inc/ConvFrame.h
src/Conversation/Controller/inc/ConvList.h
src/Conversation/Controller/inc/ConvListItem.h [new file with mode: 0644]
src/Conversation/Controller/src/BubbleEntityFactory.cpp [new file with mode: 0644]
src/Conversation/Controller/src/ConvFrame.cpp
src/Conversation/Controller/src/ConvList.cpp
src/Conversation/Controller/src/ConvListItem.cpp [new file with mode: 0644]
src/Conversation/View/inc/ConvListViewItem.h
src/Conversation/View/src/ConvListViewItem.cpp

index 96ddf4d9d1fc4a20cb2c7f5c191ea075f3555d64..b8834e4c7220189e310013d67da1fa2bb8d82714 100644 (file)
--- a/.cproject
+++ b/.cproject
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/Controller/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/AppControl/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/ContactManager/inc}&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/ConvList/View/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/MsgEngine/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/SystemSettingsManager/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/Utils/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/Controller/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/AppControl/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/ContactManager/inc}&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Conversation/ConvList/View/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/MsgEngine/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/SystemSettingsManager/inc}&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src/Common/Utils/inc}&quot;"/>
index 41220173c59e37af08d2c3f0c22d2ea9dcd4dc63..bc7bad3e06d7de791f658cee0aff10500ab4af55 100644 (file)
@@ -17,6 +17,7 @@
 #include "MsgConversationItemDummy.h"
 #include "Logger.h"
 #include "MsgUtilsDummy.h"
+#include "fakeNames.h"
 
 #include <assert.h>
 
@@ -34,30 +35,29 @@ MsgConversationItemDummy::~MsgConversationItemDummy()
 
 MsgId MsgConversationItemDummy::getMsgId() const
 {
-    int id = rand()%100;
+    int id = rand() % 100;
     return id;
 }
 
 ThreadId MsgConversationItemDummy::getThreadId() const
 {
-    int id = rand()%50;
+    int id = rand() % 50;
     return id;
 }
 
 std::string MsgConversationItemDummy::getText() const
 {
-    return MsgUtilsDummy::getStr();
+    return fakeMessages[rand() % fakeMessages.size()];
 }
 
 std::string MsgConversationItemDummy::getSubject() const
 {
-    return MsgUtilsDummy::getStr();
+    return "Subject";
 }
 
 time_t MsgConversationItemDummy::getTime() const
 {
-    int time = 0;
-    return time;
+    return rand();
 }
 
 Message::Direction MsgConversationItemDummy::getDirection() const
@@ -68,13 +68,23 @@ Message::Direction MsgConversationItemDummy::getDirection() const
 
 Message::Type MsgConversationItemDummy::getType() const
 {
-    int type = 0;
-    return MsgUtilsDummy::nativeToMessageType(type);
+    Message::Type type = (Message::Type )(rand() % Message::MT_MMS + 1);
+    return type;
 }
 
 Message::NetworkStatus MsgConversationItemDummy::getNetworkStatus() const
 {
-    return MsgUtilsDummy::nativeToNetworkStatus(0);
+    Message::NetworkStatus m[] = {Message::NS_Sending,
+                                  Message::NS_Send_Success,
+                                  Message::NS_Received,
+                                  Message::NS_Retrieving,
+                                  Message::NS_Retrieve_Success,
+                                  Message::NS_Retrieve_Fail,
+                                  Message::NS_Send_Fail};
+
+    size_t count = sizeof(m) / sizeof(Message::NetworkStatus);
+    size_t index = rand() % count;
+    return m[index];
 }
 
 bool MsgConversationItemDummy::isDraft() const
@@ -106,5 +116,5 @@ const MsgConvMediaListHandleDummy &MsgConversationItemDummy::getMediaList() cons
 
 bool MsgConversationItemDummy::isRestrictedByDpm() const
 {
-    return true;
+    return false;
 }
index 02e74805b86c96c9f15e557d0cb755a2bfa9aa7e..42f4db68f42fc93e18d4ff265a2d5cf9d1883591 100644 (file)
@@ -26,7 +26,7 @@ int MsgUtilsDummy::directionToNative(Message::Direction direction)
 
 Message::Direction MsgUtilsDummy::nativeToDirection(int direction)
 {
-    return Message::MD_Sent;
+    return (Message::Direction)(rand() % 2);
 }
 
 Message::MessageStorageType MsgUtilsDummy::nativeToMessageStorage(int id)
@@ -36,16 +36,14 @@ Message::MessageStorageType MsgUtilsDummy::nativeToMessageStorage(int id)
 
 int MsgUtilsDummy::addressTypeToNative(MsgAddress::AddressType type)
 {
-       return 0;
+    return 0;
 }
 
 MsgAddress::AddressType MsgUtilsDummy::nativeToAddressType(int type)
 {
     return MsgAddress::Phone;
-
 }
 
-
 MsgReport::DeliveryStatus MsgUtilsDummy::nativeToReportDeliveryStatus(int status)
 {
     return MsgReport::StatusNone;
diff --git a/src/Common/Utils/inc/WorkingDir.h b/src/Common/Utils/inc/WorkingDir.h
new file mode 100644 (file)
index 0000000..e44fb6b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 WorkingDir_h_
+#define WorkingDir_h_
+
+#include <string>
+#include <memory>
+#include <mutex>
+
+namespace Msg {
+    class WorkingDir {
+        public:
+            WorkingDir();
+            ~WorkingDir();
+
+            WorkingDir(WorkingDir&) = delete;
+            void operator=(WorkingDir&) = delete;
+
+            bool isValid() const;
+            const std::string &getPath() const;
+
+            std::string genUniqueFilePath(const std::string &fileName) const;
+            std::string addFile(const std::string &path);
+            std::string addTextFile(const std::string &text, const std::string &fileName = "");
+            void removeFile(const std::string &path);
+            void clear();
+
+        private:
+            void createWorkingDir();
+            void removeWorkingDir();
+            std::string getUniqueDirName(const std::string &path);
+
+        private:
+            std::string m_Path;
+            mutable std::recursive_mutex m_Mutex;
+    };
+
+    typedef std::shared_ptr<WorkingDir> WorkingDirRef;
+}
+
+#endif /* WorkingDir_h_ */
diff --git a/src/Common/Utils/src/WorkingDir.cpp b/src/Common/Utils/src/WorkingDir.cpp
new file mode 100644 (file)
index 0000000..7fca2b5
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 "WorkingDir.h"
+#include "PathUtils.h"
+#include "FileUtils.h"
+#include "Logger.h"
+
+#include <string>
+#include <fstream>
+
+using namespace Msg;
+
+const std::string commonWorkingDirName = "Temp";
+const std::string currentWorkingDirPrefix = "Temp";
+const std::string textFileName = "mms.txt";
+
+
+WorkingDir::WorkingDir()
+{
+    MSG_LOG("");
+    createWorkingDir();
+}
+
+WorkingDir::~WorkingDir()
+{
+    MSG_LOG("");
+    removeWorkingDir();
+}
+
+void WorkingDir::createWorkingDir()
+{
+    // Create common dir. if not exists:
+    std::string commonDir = PathUtils::getDataPath(commonWorkingDirName);
+    bool isCommonExists = FileUtils::isExists(commonDir);
+    if (!isCommonExists) {
+        isCommonExists = FileUtils::makeDir(commonDir);
+        MSG_ASSERT(isCommonExists, "Can't create common working dir: ", commonDir);
+    }
+
+    // Create current dir:
+    if (isCommonExists) {
+        std::string uniqueDir = getUniqueDirName(commonDir + "/" + currentWorkingDirPrefix);
+        FileUtils::makeDir(uniqueDir);
+        bool isExists = FileUtils::isExists(uniqueDir);
+        MSG_ASSERT(isExists, "Can't create current working dir: ", uniqueDir);
+        if (isExists)
+            m_Path = uniqueDir;
+    }
+}
+
+void WorkingDir::removeWorkingDir()
+{
+    if (!m_Path.empty()) {
+        bool res = FileUtils::remove(m_Path, true);
+        MSG_LOG("Working dir remove with result = ", res);
+    }
+}
+
+bool WorkingDir::isValid() const
+{
+    return !m_Path.empty() && FileUtils::isExists(m_Path);
+}
+
+const std::string &WorkingDir::getPath() const
+{
+    return m_Path;
+}
+
+std::string WorkingDir::genUniqueFilePath(const std::string &path) const
+{
+    std::lock_guard<std::recursive_mutex> _lock(m_Mutex);
+    return FileUtils::genUniqueFilePath(m_Path, path);
+}
+
+std::string WorkingDir::addFile(const std::string &path)
+{
+    std::lock_guard<std::recursive_mutex> _lock(m_Mutex);
+    std::string newPath;
+
+    if (FileUtils::isExists(path)) {
+        if (path.find(m_Path) != std::string::npos) {
+            newPath = path;
+            MSG_LOG("File is already exists: ", newPath);
+        } else {
+            newPath = genUniqueFilePath(path);
+            if (FileUtils::copy(path, newPath)) {
+                MSG_LOG("File added: ", newPath);
+            } else {
+                MSG_LOG_ERROR("Can't copy to working dir: ", path);
+                newPath.clear();
+            }
+        }
+    }
+
+    return newPath;
+}
+
+std::string WorkingDir::addTextFile(const std::string &text, const std::string &fileName)
+{
+    std::lock_guard<std::recursive_mutex> _lock(m_Mutex);
+    std::string result;
+    result = fileName.empty() ? textFileName : fileName;
+
+    std::string path = genUniqueFilePath(result);
+    std::ofstream file(path, std::ofstream::trunc | std::ofstream::binary | std::ofstream::out);
+    if (file.is_open()) {
+        file << text;
+        MSG_LOG("Text file added: ", path);
+    } else {
+        path.clear();
+    }
+
+    return path;
+}
+
+void WorkingDir::removeFile(const std::string &path)
+{
+    std::lock_guard<std::recursive_mutex> _lock(m_Mutex);
+    if (!path.empty())
+        FileUtils::remove(path);
+}
+
+void WorkingDir::clear()
+{
+    std::lock_guard<std::recursive_mutex> _lock(m_Mutex);
+    FileUtils::remove(m_Path, false);
+}
+
+std::string WorkingDir::getUniqueDirName(const std::string &path)
+{
+    std::string res;
+    unsigned i = 0;
+    do {
+        res = path + "-" + std::to_string(i);
+        ++i;
+    } while (FileUtils::isExists(res));
+    return res;
+}
diff --git a/src/Conversation/Controller/inc/BubbleEntityFactory.h b/src/Conversation/Controller/inc/BubbleEntityFactory.h
new file mode 100644 (file)
index 0000000..4b56f5f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 BubbleEntityFactory_h_
+#define BubbleEntityFactory_h_
+
+#include "MsgConvMedia.h"
+#include "WorkingDir.h"
+
+// Bubble items:
+#include "BubbleTextEntity.h"
+/*
+#include "BubbleImageEntity.h"
+#include "BubbleVideoEntity.h"
+#include "BubbleAudioEntity.h"
+#include "BubbleDownloadButtonEntity.h"
+#include "BubbleUnknownFileEntity.h"
+#include "BubbleCalEventEntity.h"
+#include "BubbleContactEntity.h"
+*/
+
+#include <string>
+
+namespace Msg {
+    class BubbleEntityFactory {
+        public:
+            BubbleEntityFactory(WorkingDirRef &workingDir);
+            ~BubbleEntityFactory();
+
+            BubbleEntity *createEntity(std::string filePath, Message::Direction direction);
+            BubbleEntity *createEntity(const MsgConvMedia &msgMedia, Message::Direction direction);
+            BubbleTextEntity *createTextEntity(std::string text, Message::Direction direction);
+
+        private:
+            BubbleEntity *createTextEntityFromFile(std::string filePath, Message::Direction direction);
+            BubbleEntity *createEntity(std::string filePath, std::string fileName, std::string mime, Message::Direction direction);
+            BubbleEntity *createVideoEntity(std::string filePath, std::string fileName, Message::Direction direction);
+            BubbleEntity *createAudioEntity(std::string filePath, std::string fileName, Message::Direction direction);
+            BubbleEntityFactory(BubbleEntityFactory&) = delete;
+            BubbleEntityFactory& operator=(const BubbleEntityFactory&) = delete;
+
+        private:
+            WorkingDirRef m_WorkingDir;
+    };
+}
+
+#endif /* BubbleEntityFactory_h_ */
index 0d99154f89cab347ab1ed6411f426410f5725255..c69f6dff18bba20c1e12d98f482561757d2766f9 100644 (file)
@@ -21,6 +21,7 @@
 #include "AppControlCompose.h"
 #include "AppControlDefault.h"
 #include "ConvList.h"
+#include "WorkingDir.h"
 
 namespace Msg
 {
@@ -72,6 +73,7 @@ namespace Msg
 
 
         private:
+            void prepareWorkingDir();
             void prepareLayout();
             void prepareMoreOption();
             void prepareDeleteViews();
@@ -89,6 +91,7 @@ namespace Msg
             MoreOption *m_pMoreOption;
             BottomButton *m_pDeleteButton;
             SelectButton *m_pSelectButton;
+            WorkingDirRef m_WorkingDir;
     };
 }
 
index 6f630d55d4d287e9c69dd87cfa1644a4615df9f6..bcfc30f004e49f9df5583a41b0e3b9b9a5fe41f5 100644 (file)
 
 #include "ListView.h"
 #include "MsgEngine.h"
+#include "WorkingDir.h"
+#include "BubbleEntityFactory.h"
+#include "ConvListItem.h"
+
+#include <unordered_map>
+#include <unordered_set>
 
 namespace Msg {
 
@@ -30,7 +36,7 @@ namespace Msg {
         : public ListView
         , private IListViewListener {
         public:
-            ConvList(Evas_Object *parent);
+            ConvList(Evas_Object *parent, WorkingDirRef &workingDir);
             virtual ~ConvList();
 
             void setThreadId(ThreadId id);
@@ -39,11 +45,13 @@ namespace Msg {
             bool getDeleteMode() const;
 
         private:
+            typedef std::unordered_map<MsgId::Type, ConvListItem*> ConvListItemMap;
+            typedef std::unordered_set<std::string> DateLineItemSet;
+
             void onListItemSelected(ListItem &listItem) override;
             void onListItemLongPressed(ListItem &listItem) override;
             void onListItemChecked(ListItem &listItem) override;
 
-        private:
             void fillList();
             MsgStorage &getMsgStorage();
             void insertItem(const MsgConversationItem &item);
@@ -54,6 +62,10 @@ namespace Msg {
             IConvListListener *m_pListener;
             PaddingListViewItem *m_pBottomPadItem;
             ConvReplyListItem *m_pReplyItem;
+            WorkingDirRef m_WorkingDir;
+            BubbleEntityFactory m_BubbleEntityFactory;
+            ConvListItemMap m_ConvListItemMap;
+            DateLineItemSet m_DateLineItemSet;
     };
 
     class IConvListListener {
diff --git a/src/Conversation/Controller/inc/ConvListItem.h b/src/Conversation/Controller/inc/ConvListItem.h
new file mode 100644 (file)
index 0000000..4c13020
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 ConvListItem_h_
+#define ConvListItem_h_
+
+#include "ConvListViewItem.h"
+#include "BubbleViewItem.h"
+#include "MsgTypes.h"
+#include "Message.h"
+#include "WorkingDir.h"
+
+#include <list>
+
+namespace Msg {
+
+    class MsgConversationItem;
+    class BubbleEntityFactory;
+    class BubbleEntity;
+
+    class ConvListItem
+        : public ConvListViewItem
+        , private IBubbleViewItemListener {
+
+        public:
+            ConvListItem(const MsgConversationItem &item,
+                         WorkingDirRef &workingDir,
+                         BubbleEntityFactory &bubbleEntityFactory);
+            virtual ~ConvListItem();
+
+            MsgId getMsgId() const;
+            time_t getRawTime() const;
+            void updateStatus();
+            void updateTime();
+
+        protected:
+            Evas_Object *getBubbleContent() override;
+            std::string getTime() override;
+            std::string getMsgType() override;
+
+        private:
+            // IBubbleViewItemListener
+            void onAction(BubbleViewItem &item) override;
+
+            void updateViewStatus();
+            void prepareContent(const MsgConversationItem &item);
+            void addEntity(BubbleEntity *entity);
+
+        private:
+            MsgId m_MsgId;
+            time_t m_Time;
+            Message::Direction m_Direction;
+            Message::NetworkStatus m_NetworkStatus;
+            Message::Type m_Type;
+            std::string m_TimeStr;
+            std::list<BubbleEntity*> m_BubbleEntityList;
+            WorkingDirRef m_WorkingDir;
+            BubbleEntityFactory &m_BubbleEntityFactory;
+    };
+}
+
+#endif /* ConvListItem_h_ */
diff --git a/src/Conversation/Controller/src/BubbleEntityFactory.cpp b/src/Conversation/Controller/src/BubbleEntityFactory.cpp
new file mode 100644 (file)
index 0000000..742c628
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 "BubbleEntityFactory.h"
+#include "FileUtils.h"
+#include "MediaType.h"
+#include "MediaUtils.h"
+
+// Bubble items:
+#include "BubbleTextEntity.h"
+/*
+#include "BubbleImageEntity.h"
+#include "BubbleVideoEntity.h"
+#include "BubbleAudioEntity.h"
+#include "BubbleDownloadButtonEntity.h"
+#include "BubbleUnknownFileEntity.h"
+#include "BubbleCalEventEntity.h"
+#include "BubbleContactEntity.h"
+*/
+
+#include <algorithm>
+
+using namespace Msg;
+
+BubbleEntityFactory::BubbleEntityFactory(WorkingDirRef &workingDir)
+    : m_WorkingDir(workingDir)
+{
+}
+
+BubbleEntityFactory::~BubbleEntityFactory()
+{
+}
+
+BubbleEntity *BubbleEntityFactory::createEntity(const MsgConvMedia &msgMedia, Message::Direction direction)
+{
+    std::string mime = msgMedia.getMime();
+    std::string fileName = msgMedia.getName();
+    std::string filePath = msgMedia.getPath();
+
+    if (mime.empty())
+        mime = FileUtils::getMimeType(filePath);
+
+    if (fileName.empty())
+        fileName = FileUtils::getFileName(filePath);
+
+    return createEntity(filePath, fileName, mime, direction);
+}
+
+BubbleEntity *BubbleEntityFactory::createEntity(std::string filePath, Message::Direction direction)
+{
+    return createEntity(std::move(filePath), FileUtils::getFileName(filePath), FileUtils::getMimeType(filePath), direction);
+}
+
+BubbleTextEntity *BubbleEntityFactory::createTextEntity(std::string text, Message::Direction direction)
+{
+    return text.empty() ? nullptr : new BubbleTextEntity(direction, std::move(text));
+}
+
+BubbleEntity *BubbleEntityFactory::createAudioEntity(std::string filePath, std::string fileName, Message::Direction direction)
+{
+    // TDOO: impl.
+    return nullptr;
+
+/*    if (MediaUtils::hasAudio(filePath))
+        return new BubbleAudioEntity(filePath, fileName, direction);
+
+    // File does not contain audio or broken:
+    return new BubbleUnknownFileEntity(filePath, fileName, bgType, direction);*/
+}
+
+BubbleEntity *BubbleEntityFactory::createVideoEntity(std::string filePath, std::string fileName, Message::Direction direction)
+{
+    // TDOO: impl.
+    return nullptr;
+
+/*    if (MediaUtils::hasVideo(filePath))
+           return new BubbleVideoEntity(m_WorkingDir, filePath, direction);
+
+    // Try to create Audio entity.
+    return createAudioEntity(filePath, fileName, bgType, direction);*/
+}
+
+BubbleEntity *BubbleEntityFactory::createTextEntityFromFile(std::string filePath, Message::Direction direction)
+{
+    std::string text = FileUtils::readTextFile(filePath);
+    BubbleTextEntity *entity = createTextEntity(std::move(text), direction);
+    if (entity)
+        entity->setFilePath(std::move(filePath));
+    return entity;
+}
+
+BubbleEntity *BubbleEntityFactory::createEntity(std::string filePath, std::string fileName, std::string mime, Message::Direction direction)
+{
+    if (FileUtils::isExists(filePath)) {
+        std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
+        MsgMedia::Type msgMediaType = getMsgMediaTypeByMime(mime);
+
+        switch (msgMediaType) {
+        case MsgMedia::TextType:
+            return createTextEntityFromFile(std::move(filePath), direction);
+
+        // TDOO: impl.
+
+       /* case MsgMedia::ImageType:
+            return new BubbleImageEntity(filePath, direction);
+        case MsgMedia::AudioType:
+            return createAudioEntity(filePath, fileName, direction);
+        case MsgMedia::VideoType:
+            return createVideoEntity(filePath, fileName, direction);
+        default:
+          if (mime == "text/x-vcalendar" || mime == "text/calendar")
+              return new BubbleCalEventEntity(filePath, fileName, direction);
+          else if (mime == "text/x-vcard" ||
+                  mime == "text/vcard" ||
+                  mime == "text/x-vcalendar")
+              return new BubbleContactEntity(m_App, filePath, fileName, direction);
+          else if (mime != "application/smil")
+              return new BubbleUnknownFileEntity(filePath, fileName, direction);
+              */
+        }
+    }
+
+    return nullptr;
+}
+
index 28cf6c0e067c5b7765f33b6b26babc7197ff1108..ddff70e8c7091f5a94dc989a363ea37b22bcb027 100644 (file)
@@ -32,6 +32,7 @@ ConvFrame::ConvFrame(NaviFrameController &parent)
     , m_pDeleteButton(nullptr)
     , m_pSelectButton(nullptr)
 {
+    prepareWorkingDir();
     prepareLayout();
     prepareList();
     prepareMoreOption();
@@ -97,6 +98,12 @@ void ConvFrame::execCmd(const AppControlDefaultRef &cmd)
     // TODO: impl.
 }
 
+void ConvFrame::prepareWorkingDir()
+{
+    if (!m_WorkingDir)
+        m_WorkingDir = std::make_shared<WorkingDir>();
+}
+
 void ConvFrame::prepareLayout()
 {
     if (!m_pLayout) {
@@ -140,7 +147,7 @@ void ConvFrame::prepareDeleteViews()
 void ConvFrame::prepareList()
 {
     if (!m_pList) {
-        m_pList = new ConvList(*m_pLayout);
+        m_pList = new ConvList(*m_pLayout, m_WorkingDir);
         m_pList->setListener(this);
         m_pLayout->setContent(*m_pList);
     }
index 07e4b88a34a01f6e83dc9137f7efe1fc13f21038..6ac7da97147ff229df0ca3da601c61c82c68c566 100644 (file)
 
 using namespace Msg;
 
-ConvList::ConvList(Evas_Object *parent)
+ConvList::ConvList(Evas_Object *parent, WorkingDirRef &workingDir)
     : ListView(parent, App::getInst().getWindow().getCircleSurface())
     , m_DeleteMode(false)
     , m_pListener(nullptr)
     , m_pBottomPadItem(nullptr)
     , m_pReplyItem(nullptr)
+    , m_WorkingDir(workingDir)
+    , m_BubbleEntityFactory(m_WorkingDir)
 {
     ListView::setListener(this);
     ListView::setHomogeneous(false);
     ListView::setMultiSelection(false);
     ListView::enabledAlign(false);
-
-    fillList();
 }
 
 ConvList::~ConvList()
@@ -89,6 +89,7 @@ void ConvList::fillList()
 
 void ConvList::insertItem(const MsgConversationItem &item)
 {
+    ListView::appendItem(*new ConvListItem(item, m_WorkingDir, m_BubbleEntityFactory));
 }
 
 void ConvList::setThreadId(ThreadId id)
diff --git a/src/Conversation/Controller/src/ConvListItem.cpp b/src/Conversation/Controller/src/ConvListItem.cpp
new file mode 100644 (file)
index 0000000..e240dc5
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 "ConvListItem.h"
+#include "MsgEngine.h"
+#include "TimeUtils.h"
+#include "MsgUtils.h"
+#include "MediaUtils.h"
+#include "FileUtils.h"
+#include "FileViewer.h"
+#include "Logger.h"
+#include "ListView.h"
+#include "App.h"
+
+#include <algorithm>
+
+// Bubble items:
+#include "BubbleItemContainer.h"
+#include "BubbleEntityFactory.h"
+#include "BubbleTextEntity.h"
+// #include "BubbleImageEntity.h"
+// #include "BubbleVideoEntity.h"
+// #include "BubbleAudioEntity.h"
+// #include "BubbleDownloadButtonEntity.h"
+// #include "BubbleUnknownFileEntity.h"
+// #include "BubbleCalEventEntity.h"
+// #include "BubbleContactEntity.h"
+
+using namespace Msg;
+
+ConvListItem::ConvListItem(const MsgConversationItem &item,
+                           WorkingDirRef &workingDir,
+                           BubbleEntityFactory &bubbleEntityFactory)
+    : ConvListViewItem(item.getDirection() == Message::MD_Sent ? Sent : Received)
+    , m_MsgId(item.getMsgId())
+    , m_Time(item.getTime())
+    , m_Direction(item.getDirection())
+    , m_NetworkStatus(item.getNetworkStatus())
+    , m_Type(item.getType())
+    , m_WorkingDir(workingDir)
+    , m_BubbleEntityFactory(bubbleEntityFactory)
+{
+    prepareContent(item);
+    updateViewStatus();
+}
+
+ConvListItem::~ConvListItem()
+{
+    for (auto *entity : m_BubbleEntityList)
+        delete entity;
+
+    m_BubbleEntityList.clear();
+}
+
+MsgId ConvListItem::getMsgId() const
+{
+    return m_MsgId;
+}
+
+time_t ConvListItem::getRawTime() const
+{
+    return m_Time;
+}
+
+void ConvListItem::updateViewStatus()
+{
+    switch (m_NetworkStatus) {
+    case Message::NS_Send_Fail:
+        setInfoStatus(ConvListViewItem::FailedStatus);
+        break;
+
+    case Message::NS_Sending:
+        setInfoStatus(ConvListViewItem::ProgressStatus);
+        break;
+
+    case Message::NS_Retrieving:
+    case Message::NS_Retrieve_Success:
+    case Message::NS_Retrieve_Fail:
+        setInfoStatus(m_NetworkStatus == Message::NS_Retrieving ? ProgressStatus : NoneStatus);
+        break;
+
+    default:
+        setInfoStatus(NoneStatus);
+        break;
+    }
+}
+
+void ConvListItem::updateStatus()
+{
+    MessageRef msg = App::getInst().getMsgEngine().getStorage().getMessage(m_MsgId);
+    if (msg) {
+        m_Time = msg->getTime();
+        m_NetworkStatus = msg->getNetworkStatus();
+        updateTime();
+        updateViewStatus();
+    }
+}
+
+void ConvListItem::updateTime()
+{
+    m_TimeStr.clear();
+}
+
+void ConvListItem::prepareContent(const MsgConversationItem &item)
+{
+    if (MsgUtils::isSms(m_Type)) {
+        addEntity(m_BubbleEntityFactory.createTextEntity(item.getText(), m_Direction));
+    } else if (m_Type == Message::MT_MMS_Noti) {
+        // TODO: impl.
+    } else {
+        const MsgConvMediaList &list = item.getMediaList();
+        for (int i = 0; i < list.getLength(); ++i) {
+            const MsgConvMedia &media = list.at(i);
+            addEntity(m_BubbleEntityFactory.createEntity(media, m_Direction));
+        }
+    }
+}
+
+void ConvListItem::addEntity(BubbleEntity *entity)
+{
+    if (entity)
+        m_BubbleEntityList.push_back(entity);
+}
+
+Evas_Object *ConvListItem::getBubbleContent()
+{
+    if (m_BubbleEntityList.empty())
+        return nullptr;
+
+    auto *bubble = new BubbleItemContainer(*getOwner());
+    for (BubbleEntity *entity : m_BubbleEntityList) {
+        BubbleViewItem *item = entity->createView(*bubble);
+        if (item) {
+            bubble->append(*item, entity->getDirection());
+            item->setListener(this);
+        }
+    }
+    bubble->go();
+    bubble->show();
+    return *bubble;
+}
+
+std::string ConvListItem::getTime()
+{
+    if (m_TimeStr.empty())
+        m_TimeStr = TimeUtils::makeBubbleTimeString(m_Time);
+    return m_TimeStr;
+}
+
+std::string ConvListItem::getMsgType()
+{
+    return MsgUtils::isMms(m_Type) ? (std::string)msg("WDS_MSG_SBODY_MMS_ABB") : "";
+}
+
+void ConvListItem::onAction(BubbleViewItem &item)
+{
+    MSG_LOG("");
+    // TODO: iml.
+}
+
+
index 0a9d3a021008dd3f4fc1ba20fcae8383280c5814..4a068cdf46dce35b4d98783939cca9b142c0d2c2 100644 (file)
@@ -30,7 +30,7 @@ namespace Msg {
 
             enum InfoStatusType {
                 NoneStatus,
-                SendingStatus,
+                ProgressStatus,
                 FailedStatus
             };
 
@@ -38,7 +38,7 @@ namespace Msg {
             virtual ~ConvListViewItem();
 
             void setCheckedState(bool state);
-            void setInfoStatusType(InfoStatusType statusType, bool updateUi);
+            void setInfoStatus(InfoStatusType statusType);
 
         protected:
             virtual Evas_Object *getBubbleContent() = 0;
@@ -47,14 +47,14 @@ namespace Msg {
 
         protected:
             void updateContent();
-            void updateItemType(ConvItemType type);
 
         private:
-            virtual std::string getText(ListItem &item, const char *part);
-            virtual Evas_Object *getContent(ListItem &item, const char *part);
+            std::string getText(ListItem &item, const char *part) override;
+            Evas_Object *getContent(ListItem &item, const char *part) override;
 
             Evas_Object *createProgress();
             Evas_Object *createFailedButton();
+            void updateItemType(ConvItemType type);
 
         private:
             ConvItemType m_Type;
index 59c9a30f087f67bd9cfebe183bd8e2e340c0319a..43b9d188b7022b0f12772156483a79e324e39078 100644 (file)
@@ -50,14 +50,14 @@ void ConvListViewItem::setCheckedState(bool state)
     emitSignal(sig, "");
 }
 
-void ConvListViewItem::setInfoStatusType(InfoStatusType statusType, bool updateUi)
+void ConvListViewItem::setInfoStatus(InfoStatusType statusType)
 {
     if (statusType == m_Status)
         return;
 
     m_Status = statusType;
 
-    if (updateUi) {
+    if (getElmObjItem()) {
         updateFields(infoStatus, ELM_GENLIST_ITEM_FIELD_CONTENT);
         updateFields(timeTextPart, ELM_GENLIST_ITEM_FIELD_TEXT);
         updateFields(msgType, ELM_GENLIST_ITEM_FIELD_TEXT);
@@ -82,7 +82,7 @@ Evas_Object *ConvListViewItem::getContent(ListItem &item, const char *part)
         return getBubbleContent();
     } else if (!strcmp(part, infoStatus)) {
         if (m_Type == Sent) {
-            if (m_Status == SendingStatus)
+            if (m_Status == ProgressStatus)
                 return createProgress();
             if (m_Status == FailedStatus)
                 return createFailedButton();