TizenRefApp-8305 Implement missing functionality for BubbleEntity* 51/122451/3
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 31 Mar 2017 10:36:30 +0000 (13:36 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 31 Mar 2017 12:15:45 +0000 (15:15 +0300)
+ Add VCalendarParser class.

Change-Id: I744cb655a9e9c1712da8da2befc81f8c1098351d
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/Utils/inc/VCalendarParser.h [new file with mode: 0644]
src/Common/Utils/src/VCalendarParser.cpp [new file with mode: 0644]
src/Conversation/Controller/inc/BubbleCalEventEntity.h
src/Conversation/Controller/inc/BubbleEntityFactory.h
src/Conversation/Controller/src/BubbleCalEventEntity.cpp
src/Conversation/Controller/src/BubbleEntityFactory.cpp
src/Conversation/Controller/src/BubbleVideoEntity.cpp

diff --git a/src/Common/Utils/inc/VCalendarParser.h b/src/Common/Utils/inc/VCalendarParser.h
new file mode 100644 (file)
index 0000000..d5c087e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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 VCalendarParser_h_
+#define VCalendarParser_h_
+
+#include <calendar.h>
+#include <string>
+#include <list>
+
+namespace Msg {
+    class CalendarEvent {
+        public:
+            CalendarEvent(calendar_record_h record);
+
+            const std::string &getSummary() const;
+            const std::string &getStartDate() const;
+
+        private:
+            std::string m_Summary;
+            std::string m_StartDate;
+    };
+
+    class VCalendarParser {
+        public:
+            static VCalendarParser &getInst();
+            std::list<CalendarEvent> parse(const std::string &filePath);
+
+        private:
+            VCalendarParser();
+            ~VCalendarParser();
+            VCalendarParser& operator=(VCalendarParser&) = delete;
+            VCalendarParser(VCalendarParser&) = delete;
+    };
+
+}
+#endif /* VCalendarParser_h_ */
diff --git a/src/Common/Utils/src/VCalendarParser.cpp b/src/Common/Utils/src/VCalendarParser.cpp
new file mode 100644 (file)
index 0000000..b40cbaf
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * 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 "VCalendarParser.h"
+#include "FileUtils.h"
+#include "Logger.h"
+#include "TimeUtils.h"
+
+#include <string.h>
+
+using namespace Msg;
+
+CalendarEvent::CalendarEvent(calendar_record_h record)
+{
+    char *summary = nullptr;
+    calendar_record_get_str_p(record, _calendar_event.summary, &summary);
+    if (summary)
+        m_Summary = summary;
+
+    calendar_time_s start = {};
+    if (calendar_record_get_caltime(record, _calendar_event.start_time, &start) == 0) {
+        if (start.type == CALENDAR_TIME_UTIME) { // Unix time
+            m_StartDate = TimeUtils::makeCalEventString(start.time.utime);
+        } else { // Local time
+            m_StartDate = TimeUtils::makeCalEventString
+            (
+                start.time.date.year,
+                start.time.date.month,
+                start.time.date.mday,
+                start.time.date.hour,
+                start.time.date.minute,
+                nullptr);
+        }
+    }
+}
+
+const std::string &CalendarEvent::getSummary() const
+{
+    return m_Summary;
+}
+
+const std::string &CalendarEvent::getStartDate() const
+{
+    return m_StartDate;
+}
+
+VCalendarParser::VCalendarParser()
+{
+    calendar_connect();
+}
+
+VCalendarParser::~VCalendarParser()
+{
+    calendar_disconnect();
+}
+
+VCalendarParser &VCalendarParser::getInst()
+{
+    static VCalendarParser inst;
+    return inst;
+}
+
+std::list<CalendarEvent> VCalendarParser::parse(const std::string &filePath)
+{
+    if (filePath.empty())
+        return {};
+
+    std::list<CalendarEvent> list;
+    std::string text = FileUtils::readTextFile(filePath);
+
+    calendar_list_h records = nullptr;
+    int parseRes = calendar_vcalendar_parse_to_calendar(text.c_str(), &records);
+    MSG_LOG("Parse results: ", parseRes);
+
+    int count = 0;
+    calendar_list_get_count(records, &count);
+    calendar_list_first(records);
+
+    for (int i = 0; i < count; ++i) {
+        calendar_record_h record = nullptr;
+        calendar_list_get_current_record_p(records, &record);
+        if (record) {
+            char *viewUri = nullptr;
+            calendar_record_get_uri_p(record, &viewUri);
+            if (viewUri && !strcmp(viewUri, _calendar_event._uri))
+                list.emplace_back(record);
+        }
+    }
+
+    if (records)
+        calendar_list_destroy(records, true);
+
+    return list;
+}
+
+
index 35df900a6132a6a4f1f7f86b088089c3165af6cc..06e26cfcc01eb3b578f99ea0597cb26228123138 100644 (file)
@@ -31,6 +31,7 @@ namespace Msg {
 
         private:
             std::string m_Name;
+            std::string m_DateTime;
     };
 }
 
index 2ccd70093e0dc6271c08ed2cb300b9b4b4658d7c..244465044a887ee985cd1cbcea770af73035a37f 100644 (file)
@@ -52,6 +52,7 @@ namespace Msg {
             BubbleEntity *createTextEntityFromFile(std::string filePath, 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);
+            BubbleEntity *createVoiceEntity(std::string filePath, std::string fileName, Message::Direction direction);
             BubbleEntityFactory(BubbleEntityFactory&) = delete;
             BubbleEntityFactory& operator=(const BubbleEntityFactory&) = delete;
 
index acb72860167bb0f5bf200b460e893da655a1033f..75934889db7b50298112ba4ee34082d68b5acfd0 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "BubbleCalEventEntity.h"
+#include "VCalendarParser.h"
 #include "Resource.h"
 
 using namespace Msg;
@@ -23,6 +24,14 @@ BubbleCalEventEntity::BubbleCalEventEntity(const std::string &filePath, const st
     : BubbleEntity(CalendarEventItem, direction, filePath)
     , m_Name(std::move(fileName))
 {
+    auto list = VCalendarParser::getInst().parse(filePath);
+    if (list.size() == 1) {
+        const CalendarEvent &event = list.front();
+        m_Name = event.getSummary();
+        m_DateTime = event.getStartDate();
+    } else {
+        m_Name = fileName;
+    }
 }
 
 BubbleCalEventEntity::~BubbleCalEventEntity()
index 5ee2a0264fa2b3a9b154ec4aa0c6306075bd065e..640f12d30aa7156fcbe95807f6a0d868935d662f 100644 (file)
 #include "BubbleCalEventEntity.h"
 #include "BubbleContactEntity.h"
 #include "BubbleNoContentEntity.h"
-
-// TODO: impl
-// #include "BubbleAudioEntity.h"
-// #include "BubbleUnknownFileEntity.h"
+#include "BubbleAudioEntity.h"
+#include "BubbleVoiceEntity.h"
+#include "BubbleUnknownFileEntity.h"
 
 #include <algorithm>
 
@@ -108,20 +107,21 @@ BubbleEntity *BubbleEntityFactory::createEntity(const MsgConvMedia &msgMedia, Me
         case MsgMedia::ImageType:
             return new BubbleImageEntity(std::move(filePath), direction);
         case MsgMedia::AudioType:
-            return createAudioEntity(std::move(filePath), std::move(fileName), direction);
+            if (mime == "audio/m4a")
+                return createVoiceEntity(std::move(filePath), std::move(fileName), direction);
+            else
+                return createAudioEntity(std::move(filePath), std::move(fileName), direction);
         case MsgMedia::VideoType:
             return createVideoEntity(std::move(filePath), std::move(fileName), direction);
         default:
           if (mime == "text/x-vcalendar" || mime == "text/calendar")
               return new BubbleCalEventEntity(std::move(filePath), std::move(fileName), direction);
-
-          // TDOO: impl.
-/*          else if (mime == "text/x-vcard" ||
+          else if (mime == "text/x-vcard" ||
                    mime == "text/vcard" ||
                    mime == "text/x-vcalendar")
               return new BubbleContactEntity(std::move(filePath), std::move(fileName), direction);
           else if (mime != "application/smil")
-              return new BubbleUnknownFileEntity(std::move(filePath), std::move(fileName), direction);*/
+              return new BubbleUnknownFileEntity(std::move(filePath), std::move(fileName), direction);
         }
     }
 
@@ -146,14 +146,20 @@ BubbleNoContentEntity *BubbleEntityFactory::createNoContentEntity(Message::Direc
 
 BubbleEntity *BubbleEntityFactory::createAudioEntity(std::string filePath, std::string fileName, Message::Direction direction)
 {
-    // TDOO: impl.
-    return nullptr;
-
-/*    if (MediaUtils::hasAudio(filePath))
+    if (MediaUtils::hasAudio(filePath))
         return new BubbleAudioEntity(filePath, fileName, direction);
 
     // File does not contain audio or broken:
-    return new BubbleUnknownFileEntity(filePath, fileName, bgType, direction);*/
+    return new BubbleUnknownFileEntity(filePath, fileName, direction);
+}
+
+BubbleEntity *BubbleEntityFactory::createVoiceEntity(std::string filePath, std::string fileName, Message::Direction direction)
+{
+    if (MediaUtils::hasAudio(filePath))
+        return new BubbleVoiceEntity(filePath, fileName, direction);
+
+    // File does not contain audio or broken:
+    return new BubbleUnknownFileEntity(filePath, fileName, direction);
 }
 
 BubbleEntity *BubbleEntityFactory::createVideoEntity(std::string filePath, std::string fileName, Message::Direction direction)
@@ -161,11 +167,8 @@ BubbleEntity *BubbleEntityFactory::createVideoEntity(std::string filePath, std::
     if (MediaUtils::hasVideo(filePath))
            return new BubbleVideoEntity(m_WorkingDir, std::move(filePath), direction);
 
-    return nullptr;
-
-    // TODO: impl.
     // Try to create Audio entity.
-   // return createAudioEntity(std::move(filePath), std::move(fileName), bgType, direction);
+    return createAudioEntity(std::move(filePath), std::move(fileName), direction);
 }
 
 BubbleEntity *BubbleEntityFactory::createTextEntityFromFile(std::string filePath, Message::Direction direction)
index 5469de7352b90c23738d31753323bd8895529e4c..6ce71b81cc077e99319f2740a02a32a2cc77908d 100644 (file)
@@ -24,11 +24,15 @@ BubbleVideoEntity::BubbleVideoEntity(WorkingDirRef workingDir, const std::string
     : BubbleEntity(VideoItem, direction, filePath)
     , m_WorkingDir(workingDir)
 {
-    // TODO: when video player will be available
+    static const std::string thumbFileName = "thumbnail.jpeg";
+    m_ImgPath =  m_WorkingDir->genUniqueFilePath(thumbFileName);
+    if (!m_ImgPath.empty())
+        MediaUtils::getVideoFrame(getFilePath(), m_ImgPath);
 }
 
 BubbleVideoEntity::~BubbleVideoEntity()
 {
+    m_WorkingDir->removeFile(m_ImgPath);
 }
 
 BubbleVideoViewItem *BubbleVideoEntity::createView(Evas_Object *parent)