TizenRefApp-7733 Impelement Thumbnail class 96/99996/4
authorIryna Ferenchak <i.ferenchak@samsung.com>
Wed, 30 Nov 2016 11:05:59 +0000 (13:05 +0200)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Thu, 1 Dec 2016 09:33:21 +0000 (01:33 -0800)
Change-Id: I0cd5c4da0be56e9982c4ccd6dc4272a125c36048
Signed-off-by: Iryna Ferenchak <i.ferenchak@samsung.com>
lib-common/inc/Common/Model/DataBasePath.h
lib-common/inc/Common/Model/Memo.h
lib-common/inc/Common/Model/MemoBuilder.h
lib-common/inc/Common/Model/Thumbnail.h [new file with mode: 0644]
lib-common/src/Common/MemoItem.cpp
lib-common/src/Common/Model/Memo.cpp
lib-common/src/Common/Model/MemoBuilder.cpp
lib-common/src/Common/Model/Thumbnail.cpp [new file with mode: 0644]
memo-svc/src/Service/DataProvider.cpp

index f10727ab994670f7a90e2a6da53ebd5b76512838..db86093e60c9ef08f7757c5c3878a8d64b117981 100644 (file)
@@ -47,6 +47,7 @@
 #define COLUMN_IMAGE_MEMO_ID     "image_memo_id"
 
 #define COLUMN_REMOVED_IMAGE_ID  "removed_image_id"
+#define COLUMN_THUMBNAIL_INFO    "thumbnail_info"
 #define COLUMN_ALL_IMAGE_PATH    "all_image_path"
 #define IMAGES_SEPARATOR         ","
 
index 8118088f6da5d0068b20fa76df140343ef975a40..65d69cc0ba4a8a6ddf0e5b939eccc09311d4afb1 100644 (file)
@@ -20,6 +20,7 @@
 #include "Common/Model/Colors.h"
 #include "Common/Model/Image.h"
 #include "Common/Model/SoundRecord.h"
+#include "Common/Model/Thumbnail.h"
 #include "Model/DataItem.h"
 
 #include <list>
@@ -135,10 +136,10 @@ namespace Common
                        const ImageList &getImagesToRemove() const;
 
                        /**
-                        * @brief Get thumbnail index.
-                        * @return Thumbnail index if success, otherwise empty string.
+                        * @brief Get thumbnail.
+                        * @return Thumbnail.
                         */
-                       const char *getThumbnail() const;
+                       const Thumbnail &getThumbnail() const;
 
                        /**
                         * @return First image.
@@ -204,12 +205,6 @@ namespace Common
                         */
                        int addImage(std::string image);
 
-                       /**
-                        * @brief Add thumbnail to Memo.
-                        * @param[in]   image   Image path.
-                        */
-                       void setThumbnail(std::string image);
-
                        /**
                         * @brief Add sound record to Memo.
                         */
@@ -256,6 +251,7 @@ namespace Common
                        const Image *getImage(int index) const;
                        void addSoundToRemove(SoundRecord sound);
                        void addImageToRemove(Image image);
+                       void setThumbnail(Thumbnail thumbnail);
 
                        long long m_Id;
                        time_t m_Time;
@@ -264,7 +260,7 @@ namespace Common
                        ColorId m_Color;
                        ImageList m_ImagesToRemove;
                        ImageList m_Images;
-                       std::string m_Thumbnail;
+                       Thumbnail m_Thumbnail;
                        SoundRecordList m_SoundRecords;
                        SoundRecordList m_SoundRecordsToRemove;
                        bool m_IsPinned;
index 681df649ccbb8834d8dce3110d5c6a33a4db931f..17c4cc7d9f776af8f65687118900b78dd9236966 100644 (file)
@@ -45,6 +45,7 @@ namespace Common
                        static void setMemoColumn(Memo *memo, result_set_cursor cursor, int column);
                        static void setMemoTextColumn(Memo *memo, result_set_cursor cursor, int column, char *columnName);
                        static void setMemoIntColumn(Memo *memo, result_set_cursor cursor, int column, char *columnName);
+                       static void setMemoThumbnail(Memo *memo, std::string thumbnail);
                        static void setMemoImages(Memo *memo, std::string images);
 
                        static void setMemoImages(Memo *memo, bundle *data);
diff --git a/lib-common/inc/Common/Model/Thumbnail.h b/lib-common/inc/Common/Model/Thumbnail.h
new file mode 100644 (file)
index 0000000..05be061
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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 COMMON_MODEL_THUMBNAIL_H
+#define COMMON_MODEL_THUMBNAIL_H
+
+#include <string>
+#include <tizen.h>
+
+namespace Common
+{
+       namespace Model
+       {
+               class EXPORT_API Thumbnail
+               {
+               public:
+                       Thumbnail();
+
+                       /**
+                        * @brief Create thumbnail.
+                        * @param[in]   id      thumbnail id
+                        * @param[in]   path    thumbnail path.
+                        */
+                       Thumbnail(int id, std::string path);
+
+                       bool operator==(const Thumbnail &other);
+                       bool operator!=(const Thumbnail &other);
+
+                       /**
+                        * @return Thumbnail id.
+                        */
+                       int getId() const;
+
+                       /**
+                        * @return Thumbnail path.
+                        */
+                       const std::string &getPath() const;
+
+               private:
+                       int m_Id;
+                       std::string m_Path;
+               };
+       }
+};
+
+#endif /* COMMON_MODEL_THUMBNAIL_H */
index 18723d03c83ee092cbed1d51b8ac1218f64eb44d..d7959fdc6a2968437436b88322701f363e7c6add 100644 (file)
@@ -178,7 +178,7 @@ Evas_Object *MemoItem::createImage(Evas_Object *parent) const
 
        Evas_Object *image = elm_image_add(layout);
        elm_image_aspect_fixed_set(image, EINA_FALSE);
-       elm_image_file_set(image, m_Memo.getThumbnail(), nullptr);
+       elm_image_file_set(image, m_Memo.getThumbnail().getPath().c_str(), nullptr);
        elm_object_part_content_set(layout, PART_IMAGE, image);
 
        return layout;
index 77a62499d78a48dd94873a5c6654664748263ea1..789660bcf224207a7954632eecfdfb803c4e5252 100644 (file)
@@ -97,9 +97,9 @@ const ImageList &Memo::getImagesToRemove() const
        return m_ImagesToRemove;
 }
 
-const char *Memo::getThumbnail() const
+const Thumbnail &Memo::getThumbnail() const
 {
-       return m_Thumbnail.c_str();
+       return m_Thumbnail;
 }
 
 const Image *Memo::getFirstImage() const
@@ -172,11 +172,6 @@ int Memo::addImage(std::string image)
        return index;
 }
 
-void Memo::setThumbnail(std::string image)
-{
-       m_Thumbnail = std::move(image);
-}
-
 void Memo::addSoundRecord()
 {
        if (!m_SoundRecords.empty()) {
@@ -266,7 +261,7 @@ int Memo::onUpdate(void *data)
                m_SoundRecords = std::move(memo->m_SoundRecords);
                changes |= ChangeSound;
        }
-       if (strcmp(getThumbnail(), memo->getThumbnail()) != 0) {
+       if (m_Thumbnail != memo->m_Thumbnail) {
                setThumbnail(memo->getThumbnail());
                changes |= ChangedThumbnail;
        }
@@ -328,3 +323,8 @@ void Memo::addImageToRemove(Image image)
 {
        m_ImagesToRemove.push_back(std::move(image));
 }
+
+void Memo::setThumbnail(Thumbnail thumbnail)
+{
+       m_Thumbnail = std::move(thumbnail);
+}
index 4af46c57da442f2c20f72941c73aac8cf1aa1c16..141305fc6c581410a467b69d3b311345487a62ad 100644 (file)
@@ -31,9 +31,9 @@ using namespace Common::Model;
 
 namespace
 {
-       const std::string thumbnailDir = std::string(getDataDir()).append("thumbnails/");
-       const std::string soundDir = std::string(getDataDir()).append("sounds/");
-       const std::string imageDir = std::string(getDataDir()).append("images/");
+       const std::string thumbnailDir = std::string(getDataDir()).append("thumbnails");
+       const std::string soundDir = std::string(getDataDir()).append("sounds");
+       const std::string imageDir = std::string(getDataDir()).append("images");
 }
 
 Memo *MemoBuilder::createMemo(result_set_cursor cursor)
@@ -82,8 +82,8 @@ void MemoBuilder::setMemoTextColumn(Memo *memo, result_set_cursor cursor, int co
                memo->setTitle(std::move(value));
        } else if (strcmp(columnName, COLUMN_ALL_IMAGE_PATH) == 0) {
                setMemoImages(memo, std::move(value));
-       } else if (strcmp(columnName, COLUMN_THUMBNAIL_PATH) == 0) {
-               memo->setThumbnail(Common::getFilePath(thumbnailDir, value));
+       } else if (strcmp(columnName, COLUMN_THUMBNAIL_INFO) == 0) {
+               setMemoThumbnail(memo, std::move(value));
        } else if (strcmp(columnName, COLUMN_SOUND_PATH) == 0) {
                memo->addSoundRecord(SoundRecord(Common::getFilePath(soundDir, value)));
        } else {
@@ -108,6 +108,15 @@ void MemoBuilder::setMemoIntColumn(Memo *memo, result_set_cursor cursor, int col
        }
 }
 
+void MemoBuilder::setMemoThumbnail(Memo *memo, std::string thumbnail)
+{
+       char *thumbnailName = nullptr;
+       char *str = strtok_r(&thumbnail[0], ",", &thumbnailName);
+       int thumbnailId = strtol(str, nullptr, 10);
+
+       memo->setThumbnail(Thumbnail(thumbnailId, getFilePath(thumbnailDir, thumbnailName)));
+}
+
 void MemoBuilder::setMemoImages(Memo *memo, std::string images)
 {
        int imageId = 0;
diff --git a/lib-common/src/Common/Model/Thumbnail.cpp b/lib-common/src/Common/Model/Thumbnail.cpp
new file mode 100644 (file)
index 0000000..2c97935
--- /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.
+ */
+
+#include "Common/Model/Thumbnail.h"
+
+using namespace Common::Model;
+
+Thumbnail::Thumbnail()
+       : m_Id(0)
+{
+}
+
+Thumbnail::Thumbnail(int id, std::string path)
+       : m_Id(id),
+         m_Path(std::move(path))
+{
+}
+
+bool Thumbnail::operator==(const Thumbnail &other)
+{
+       return (m_Id == other.m_Id && m_Path == other.m_Path);
+}
+
+bool Thumbnail::operator!=(const Thumbnail &other)
+{
+       return !(*this == other);
+}
+
+int Thumbnail::getId() const
+{
+       return m_Id;
+}
+
+const std::string &Thumbnail::getPath() const
+{
+       return m_Path;
+}
index 10ada07c29ce31804d6762508cacc0f3858accc6..63a2f8dfb260eee76e10ec934d1768bd272bca4e 100644 (file)
@@ -102,8 +102,8 @@ namespace
                COLUMN_MEMO_COLOR              ", "
                COLUMN_MEMO_PINNED             ", "
                COLUMN_MEMO_TIME               ", "
-               COLUMN_THUMBNAIL_PATH          ", "
                TABLE_SOUNDS "." COLUMN_SOUND_PATH ", "
+               "(" COLUMN_THUMBNAIL_ID " || '" IMAGES_SEPARATOR "' || " COLUMN_THUMBNAIL_PATH ") AS " COLUMN_THUMBNAIL_INFO ", "
                "GROUP_CONCAT((" COLUMN_IMAGE_ID " || '" IMAGES_SEPARATOR "' || " COLUMN_IMAGE_INDEX " || '" IMAGES_SEPARATOR "' || " COLUMN_IMAGE_PATH "), '"
                IMAGES_SEPARATOR "' ) AS " COLUMN_ALL_IMAGE_PATH
                " FROM " TABLE_MEMOS
@@ -123,8 +123,8 @@ namespace
                COLUMN_MEMO_COLOR              ", "
                COLUMN_MEMO_PINNED             ", "
                COLUMN_MEMO_TIME               ", "
-               COLUMN_THUMBNAIL_PATH          ", "
                TABLE_SOUNDS "." COLUMN_SOUND_PATH ", "
+               "(" COLUMN_THUMBNAIL_ID " || '" IMAGES_SEPARATOR "' || " COLUMN_THUMBNAIL_PATH ") AS " COLUMN_THUMBNAIL_INFO ", "
                "GROUP_CONCAT((" COLUMN_IMAGE_ID " || '" IMAGES_SEPARATOR "' || " COLUMN_IMAGE_INDEX " || '" IMAGES_SEPARATOR "' || " COLUMN_IMAGE_PATH "), '"
                IMAGES_SEPARATOR "' ) AS " COLUMN_ALL_IMAGE_PATH
                " FROM " TABLE_MEMOS