TizenRefApp-5847 Implement LogDetailItem 59/61059/3
authorNataliia Kamyshna <n.kamyshna@samsung.com>
Thu, 3 Mar 2016 15:03:20 +0000 (17:03 +0200)
committerNataliia Kamyshna <n.kamyshna@samsung.com>
Fri, 4 Mar 2016 07:59:20 +0000 (09:59 +0200)
Change-Id: I8a2d20c50d2394b06d81fe788e0594f8b1b74745
Signed-off-by: Nataliia Kamyshna <n.kamyshna@samsung.com>
lib-logs/inc/Logs/Common/Utils.h
lib-logs/inc/Logs/Details/LogDetailItem.h [new file with mode: 0644]
lib-logs/inc/Logs/Model/Log.h
lib-logs/src/Logs/Common/Utils.cpp
lib-logs/src/Logs/Details/LogDetailItem.cpp [new file with mode: 0644]
lib-logs/src/Logs/Model/Log.cpp

index 1bd08c8..74c9a8a 100644 (file)
@@ -26,11 +26,18 @@ namespace Logs
        namespace Common
        {
                /**
-                * @brief Convert tm to string
+                * @brief Convert tm to string in format HH:MM
                 * @param[in]   time   Time to convert
                 * @return string.
                 */
                std::string formatTime(const tm &time);
+
+               /**
+                * @brief Convert tm to string in format HH:MM:SS
+                * @param[in]   time   Time to convert
+                * @return string.
+                */
+               std::string formatDuration(const tm &time);
        }
 }
 
diff --git a/lib-logs/inc/Logs/Details/LogDetailItem.h b/lib-logs/inc/Logs/Details/LogDetailItem.h
new file mode 100644 (file)
index 0000000..bbcdfdc
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 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 LOGS_DETAILS_LOG_DETAIL_ITEM_H
+#define LOGS_DETAILS_LOG_DETAIL_ITEM_H
+
+#include "Contacts/SelectItem.h"
+
+namespace Logs
+{
+       namespace Model
+       {
+               class Log;
+       }
+
+       namespace Details
+       {
+               class LogDetailItem : public Contacts::SelectItem
+               {
+               public:
+
+                       /**
+                        * @brief Create log item
+                        * @param[in]   log   Log
+                        */
+                       LogDetailItem(Model::Log *log);
+
+               private:
+                       virtual char *getText(Evas_Object *parent, const char *part) override;
+                       virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override;
+                       virtual Contacts::SelectResult getSelectResult() const override;
+
+                       static Evas_Object *createIcon(Evas_Object *parent, const char *path);
+                       static const char *getImagePath(int type);
+                       static char *getTypeString(int type, time_t duration);
+                       static char *appendDuration(const char *typeStr, time_t duration);
+
+                       Model::Log *m_Log;
+               };
+       }
+}
+
+#endif /* LOGS_DETAILS_LOG_DETAIL_ITEM_H */
index 477738f..e0c23c3 100644 (file)
@@ -77,6 +77,11 @@ namespace Logs
                        int getPersonId() const;
 
                        /**
+                        * @return log duration in seconds
+                        */
+                       time_t getDuration() const;
+
+                       /**
                         * @brief  Set log group
                         * @param[in]   logGroup  Parent log group
                         */
index 1dc933b..bd96610 100644 (file)
@@ -32,3 +32,11 @@ std::string Common::formatTime(const tm &time)
 
        return buffer;
 }
+
+std::string Common::formatDuration(const tm &time)
+{
+       char buffer[BUFFER_SIZE];
+       strftime(buffer, sizeof(buffer), "%T", &time);
+
+       return buffer;
+}
diff --git a/lib-logs/src/Logs/Details/LogDetailItem.cpp b/lib-logs/src/Logs/Details/LogDetailItem.cpp
new file mode 100644 (file)
index 0000000..dd11a17
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 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 "Logs/Details/LogDetailItem.h"
+#include "Logs/Model/Log.h"
+#include "Logs/Common/Utils.h"
+#include "LogItemLayout.h"
+#include "LogPath.h"
+
+#include "App/Path.h"
+#include "Ui/Scale.h"
+
+#include <app_i18n.h>
+#define BUFFER_SIZE             64
+#define LOG_TYPE_SIZE           45
+
+#define PART_LOG_TIME           "elm.text"
+#define PART_LOG_TYPE           "elm.text.sub"
+
+#define PART_LOG_TYPE_ICON      "elm.swallow.icon"
+#define PART_CHECK              "elm.swallow.end"
+
+using namespace Ui;
+using namespace Logs::Details;
+using namespace Logs::Model;
+using namespace Logs::Common;
+using namespace Contacts;
+
+namespace
+{
+       const std::string layoutPath = App::getResourcePath(LOG_ITEM_LAYOUT_EDJ);
+}
+
+LogDetailItem::LogDetailItem(Log *log)
+       : m_Log(log)
+{
+}
+
+char *LogDetailItem::getText(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, PART_LOG_TYPE) == 0) {
+               return getTypeString(m_Log->getType(), m_Log->getDuration());
+       } else if (strcmp(part, PART_LOG_TIME) == 0) {
+               return strdup(formatTime(m_Log->getTime()).c_str());
+       }
+
+       return nullptr;
+}
+
+Evas_Object *LogDetailItem::getContent(Evas_Object *parent, const char *part)
+{
+       if (strcmp(part, PART_LOG_TYPE_ICON) == 0) {
+               return createIcon(parent, getImagePath(m_Log->getType()));
+       } else if (strcmp(part, PART_CHECK) == 0) {
+               return SelectItem::getContent(parent, part);
+       }
+
+       return nullptr;
+}
+
+SelectResult LogDetailItem::getSelectResult() const
+{
+       return { 0, m_Log };
+}
+
+Evas_Object *LogDetailItem::createIcon(Evas_Object *parent, const char *path)
+{
+       Evas_Object *icon = elm_image_add(parent);
+       elm_image_file_set(icon, layoutPath.c_str(), path);
+
+       static int size = getScaledValue(LOG_TYPE_SIZE);
+       evas_object_size_hint_min_set(icon, size, size);
+       return icon;
+}
+
+const char *LogDetailItem::getImagePath(int type)
+{
+       const char *path = nullptr;
+       switch (type) {
+               case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
+                       path = ICON_OUTGOING;
+                       break;
+               case CONTACTS_PLOG_TYPE_VOICE_INCOMING:
+                       path = ICON_INCOMING;
+                       break;
+               case CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN:
+               case CONTACTS_PLOG_TYPE_VOICE_INCOMING_SEEN:
+                       path = ICON_MISSED;
+                       break;
+               case CONTACTS_PLOG_TYPE_VOICE_REJECT:
+                       path = ICON_REJECTED;
+                       break;
+               case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
+                       path = ICON_AUTO_REJECTED;
+                       break;
+       }
+
+       return path;
+}
+
+char *LogDetailItem::getTypeString(int type, time_t duration)
+{
+       const char *str = nullptr;
+
+       if (duration > 0) {
+               switch (type) {
+                       case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
+                               str = "IDS_ST_BODY_OUTGOING_CALL";
+                               break;
+                       case CONTACTS_PLOG_TYPE_VOICE_INCOMING:
+                               str = "IDS_CALL_BODY_INCOMING_CALL";
+                               break;
+               }
+
+               if (str) {
+                       return appendDuration(str, duration);
+               }
+       }
+
+       switch (type) {
+               case CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN:
+               case CONTACTS_PLOG_TYPE_VOICE_INCOMING_SEEN:
+                       str = "IDS_LOGS_SBODY_MISSEDM_CALL_STATUS";
+                       break;
+               case CONTACTS_PLOG_TYPE_VOICE_REJECT:
+               case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
+               default:
+                       str = "IDS_LOGS_SBODY_CANCELLED_M_STATUS";
+                       break;
+       }
+
+       return strdup(_(str));
+}
+
+char *LogDetailItem::appendDuration(const char *typeStr, time_t duration)
+{
+       char buffer[BUFFER_SIZE];
+       snprintf(buffer, sizeof(buffer), "%s, %s", _(typeStr), formatDuration(*gmtime(&duration)).c_str());
+       return strdup(buffer);
+}
index 3176eeb..e8e62f9 100644 (file)
@@ -93,6 +93,13 @@ int Log::getPersonId() const
        return id;
 }
 
+time_t Log::getDuration() const
+{
+       time_t duration = 0;
+       contacts_record_get_int(m_LogRecord, _contacts_phone_log.extra_data1, (int *)&duration);
+       return duration;
+}
+
 contacts_record_h Log::getContactRecord()
 {
        contacts_record_h record = nullptr;