+ Add VCalendarParser class.
Change-Id: I744cb655a9e9c1712da8da2befc81f8c1098351d
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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;
+}
+
+
private:
std::string m_Name;
+ std::string m_DateTime;
};
}
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;
*/
#include "BubbleCalEventEntity.h"
+#include "VCalendarParser.h"
#include "Resource.h"
using namespace Msg;
: 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()
#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>
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);
}
}
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)
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)
: 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)