From fa0af40b5f3518e9f5adb43ac98c07c7fea1c2a6 Mon Sep 17 00:00:00 2001 From: Denis Dolzhenko Date: Thu, 2 Jun 2016 11:58:08 +0300 Subject: [PATCH] TizenRefApp-6409 Implement "Save all attachments" for attachments without preview Change-Id: Ib76087f76a0ed50d559eaf135ad57a3bec3eda8b Signed-off-by: Denis Dolzhenko --- res/edje/smil_item.edc | 196 +-------------------- src/Common/AppControl/inc/FileViewer.h | 7 +- src/Common/AppControl/src/FileViewer.cpp | 47 +++-- src/Common/Controller/src/SaveAttachmentsPopup.cpp | 24 +-- src/Common/MsgEngine/src/MsgEngine.cpp | 2 +- src/Common/Utils/inc/FileUtils.h | 15 ++ src/Common/Utils/src/FileUtils.cpp | 51 +++++- src/Conversation/Body/Controller/src/Body.cpp | 3 +- .../ConvList/Controller/inc/ConvListItem.h | 2 +- .../ConvList/Controller/src/ConvList.cpp | 2 +- src/Conversation/Utils/src/WorkingDir.cpp | 7 + src/Viewer/Controller/inc/SmilPage.h | 13 ++ src/Viewer/Controller/src/SmilPage.cpp | 36 +++- src/Viewer/View/inc/SmilAttachmentItemView.h | 42 ++++- src/Viewer/View/src/SmilAttachmentItemView.cpp | 169 ++++++++++++------ 15 files changed, 319 insertions(+), 297 deletions(-) diff --git a/res/edje/smil_item.edc b/res/edje/smil_item.edc index f70d0a0..368e774 100755 --- a/res/edje/smil_item.edc +++ b/res/edje/smil_item.edc @@ -365,203 +365,23 @@ collections { group { name: "smil_attachment_item_layout"; parts { - part { - name: "pad_left"; - type: SPACER; - scale: 1; - description { - state: "default" 0.0; - fixed: 1 0; - min: 7 0; - max: 7 0; - align: 0 0.5; - rel1.relative: 0 0; - rel2.relative: 0 1; - } - description { - state: "landscape" 0.0; - inherit: "default" 0.0; - min: 170 0; - max: 170 0; - } - } + PADDING_LEFT("pad.left", 32); + PADDING_RIGHT("pad.right", 32); + PADDING_TOP("pad.top", 15); + PADDING_BOTTOM("pad.bottom", 15); part { name: "swallow.content"; type: SWALLOW; scale: 1; - mouse_events: 1; - repeat_events: 1; - description { - state: "default" 0.0; - min: 1 0; - align: 0 0.5; - rel1.relative: 1.0 0.0; - rel2.relative: 0.0 0.0; - rel1.to: "pad_left"; - rel2.to: "pad_right"; - } - } - part { - name: "pad_right"; - type: SPACER; - scale: 1; - description { - state: "default" 0.0; - fixed: 1 0; - min: 7 0; - max: 7 0; - align: 1 0.5; - rel1.relative: 1 0; - rel2.relative: 1 1; - } - description { - state: "landscape" 0.0; - inherit: "default" 0.0; - min: 170 0; - max: 170 0; - } - } - } - programs { - program { - name: "show_landscape"; - signal: "show,landscape"; - source: "*"; - action: STATE_SET "landscape" 0.0; - target: "pad_right"; - target: "pad_left"; - } - program { - name: "show_portrait"; - signal: "show,portrait"; - source: "*"; - action: STATE_SET "default" 0.0; - target: "pad_right"; - target: "pad_left"; - } - } - } - group { - name: "smil_attachment_item"; - parts { - part { - name: "bg"; - type: RECT; - scale: 1; - description { - state: "default" 0.0; - min: 0 100; - max: -1 100; - color_class: "WO21L1"; - } - description { - state: "pressed" 0.0; - inherit: "default" 0.0; - color_class: "B0211P"; - } - } - - PART_PADDING_LEFT("pad.left", 16, "bg"); - PART_PADDING_RIGHT("pad.right", 16, "bg"); - - part { - name: "item.thumbnail.rect"; - type: RECT; - scale: 1; - mouse_events: 0; description { state: "default" 0.0; visible: 1; - fixed: 1 1; - min: 74 74; - max: 74 74; - rel1 { relative: 1.0 0.0; to_x: "pad.left"; to_y: "bg"; } - rel2 { relative: 1.0 1.0; to_x: "pad.left"; to_y: "bg"; } - align: 0.0 0.5; - color: 0 0 0 0; - } - } - - PART_PADDING_TOP("thumbnail.icon.line.top", 1, "item.thumbnail.rect") - PART_PADDING_LEFT("thumbnail.icon.line.left", 1, "item.thumbnail.rect") - PART_PADDING_RIGHT("thumbnail.icon.line.right", 1, "item.thumbnail.rect") - PART_PADDING_BOTTOM("thumbnail.icon.line.bottom", 1, "item.thumbnail.rect") - - PART_SWALLOW("item.thumbnail.icon", "item.thumbnail.rect") - PART_H_PIXEL_RECT("pad.thumbnail.icon.right", 10, 0.0, 1.0, "item.thumbnail.icon") - - part { - name: "item.filename.rect"; - type: RECT; - mouse_events: 0; - scale: 1; - description { - state: "default" 0.0; - align: 0.0 0.5; - rel1 { relative: 1.0 0.0; to_x: "pad.thumbnail.icon.right"; to_y: "bg"; } - rel2 { relative: 0.0 1.0; to_x: "pad.filename.right"; to_y: "bg"; } - color: 0 0 0 0; - } - } - PART_TEXT("item.filename.text", "item.filename.rect", 0.0, 0.5) - PART_H_PIXEL_RECT("pad.filename.right", 10, 1.0, 0.0, "item.filesize.rect") - - part { - name: "item.filesize.rect"; - type: RECT; - mouse_events: 0; - scale: 1; - description { - state: "default" 0.0; - min: 80 0; - align: 1.0 0.5; - rel1 { relative: 0.0 0.0; to_x: "pad.right"; to_y: "pad.right"; } - rel2 { relative: 0.0 1.0; to_x: "pad.right"; to_y: "pad.right"; } - color: 0 0 0 0; + fixed: 0 0; + align: 0 0; + rel1 {to_x: "pad.left"; to_y: "pad.top"; relative: 1.0 1.0;} + rel2 {to_x: "pad.right"; to_y: "pad.bottom"; relative: 0.0 0.0;} } } - PART_TEXT("item.filesize.text", "item.filesize.rect", 1.0, 0.5) - - PART_RECT("over", 0.0, 0.0, "bg", "bg", 0.0, 1.0, "item.filesize.rect", "item.filesize.rect") - PART_EVENT_RECT("over_event", "over") - - PART_TOP_LINE("line.top", "bg") - PART_BOTTOM_LINE("line.bottom", "bg") - PART_LEFT_LINE("line.left", "bg") - PART_RIGHT_LINE("line.right", "bg") - } - - programs { - program { - name: "mouse_clicked"; - signal: "mouse,clicked,1"; - source: "over_event"; - action: SIGNAL_EMIT "clicked" ""; - } - program { - name: "item.pressed"; - signal: "pressed"; - source: "over_event"; - action: STATE_SET "pressed" 0.0; - target: "bg"; - target: "item.filename.text"; - target: "item.filesize.text"; - } - program { - name: "item.unpressed"; - signal: "unpressed"; - source: "over_event"; - action: STATE_SET "default" 0.0; - target: "bg"; - target: "item.filename.text"; - target: "item.filesize.text"; - } - program { - name: "item_press"; - signal: "play,press,sound"; - source: "*"; - action: RUN_PLUGIN "touch_sound"; - } } } } diff --git a/src/Common/AppControl/inc/FileViewer.h b/src/Common/AppControl/inc/FileViewer.h index f6dbe8f..831db71 100644 --- a/src/Common/AppControl/inc/FileViewer.h +++ b/src/Common/AppControl/inc/FileViewer.h @@ -19,14 +19,14 @@ #define FileViewer_h_ #include "AppControlUtils.h" -#include "WorkingDir.h" namespace Msg { class FileViewer { public: - FileViewer(WorkingDirRef workingDir); + FileViewer(); + ~FileViewer(); static bool launch(const std::string &file); bool launchWithCopy(const std::string &file); @@ -35,8 +35,9 @@ namespace Msg FileViewer(const FileViewer&) = delete; FileViewer& operator=(const FileViewer&) = delete; + std::string addFile(const std::string &path); + private: - WorkingDirRef m_WorkingDir; std::string m_FilePath; }; } diff --git a/src/Common/AppControl/src/FileViewer.cpp b/src/Common/AppControl/src/FileViewer.cpp index e7c1548..c7d6cbc 100644 --- a/src/Common/AppControl/src/FileViewer.cpp +++ b/src/Common/AppControl/src/FileViewer.cpp @@ -18,16 +18,22 @@ #include "FileViewer.h" #include "Logger.h" #include "FileUtils.h" +#include "PathUtils.h" #include using namespace Msg; -FileViewer::FileViewer(WorkingDirRef workingDir) - : m_WorkingDir(workingDir) +FileViewer::FileViewer() { } +FileViewer::~FileViewer() +{ + if(!m_FilePath.empty()) + FileUtils::remove(m_FilePath); +} + bool FileViewer::launch(const std::string &file) { bool res = false; @@ -56,19 +62,40 @@ bool FileViewer::launch(const std::string &file) return res; } +std::string FileViewer::addFile(const std::string &path) +{ + std::string newPath; + + if(FileUtils::isExists(path)) + { + std::string dataPath = PathUtils::getDataPath(""); + + if(path.find(dataPath) != std::string::npos) + { + newPath = path; + MSG_LOG("File is already exists: ", newPath); + } + else + { + newPath = FileUtils::genUniqueFilePath(dataPath, path); + if(!FileUtils::copy(path, newPath)) + newPath.clear(); + } + } + + return newPath; +} + bool FileViewer::launchWithCopy(const std::string &file) { bool res = false; - if(m_WorkingDir) - { // Remove previous file (correct only for APP_CONTROL_LAUNCH_MODE_GROUP) - if(!m_FilePath.empty()) - m_WorkingDir->removeFile(m_FilePath); + if(!m_FilePath.empty()) + FileUtils::remove(m_FilePath); - m_FilePath = m_WorkingDir->addFile(file); - if(!m_FilePath.empty()) - res = launch(m_FilePath); - } + m_FilePath = addFile(file); + if(!m_FilePath.empty()) + res = launch(m_FilePath); return res; } diff --git a/src/Common/Controller/src/SaveAttachmentsPopup.cpp b/src/Common/Controller/src/SaveAttachmentsPopup.cpp index f8e9cee..e5274c1 100644 --- a/src/Common/Controller/src/SaveAttachmentsPopup.cpp +++ b/src/Common/Controller/src/SaveAttachmentsPopup.cpp @@ -21,8 +21,6 @@ #include "PopupManager.h" #include "MsgMedia.h" #include "FileUtils.h" -#include -#include #include using namespace Msg; @@ -122,23 +120,14 @@ void SaveAttachmentsPopup::onCancelButtonClicked(Popup &popup, int buttonId) void SaveAttachmentsPopup::onSaveButtonClicked(Popup &popup, int buttonId) { MSG_LOG(""); - bool result = false; - if(media_content_connect() != 0) - { - popup.destroy(); - showSavingFailedPopup(); - return; - } - result = saveCheckedItems(); + bool result = saveCheckedItems(); popup.destroy(); if(result) notification_status_message_post(msg("IDS_MSGF_POP_SAVED_IN_MY_FILES").cStr()); else showSavingFailedPopup(); - - media_content_disconnect(); } bool SaveAttachmentsPopup::isSaveButtonNeedToBeEnable() @@ -159,22 +148,19 @@ void SaveAttachmentsPopup::disableSaveButton(bool value) bool SaveAttachmentsPopup::saveCheckedItems() { - bool success = true; std::string filePathDst; std::string dowloadPath = PathUtils::getDownloadPath(); auto items = getListView().getItems(); + std::list files; + for(auto *item : items) { if(item->isCheckable() && item->getCheckedState()) - { - filePathDst = FileUtils::genUniqueFilePath(dowloadPath, item->getFilePath()); - bool copySucceed = FileUtils::copy(item->getFilePath(), filePathDst); - success &= copySucceed && (media_content_scan_file(filePathDst.c_str()) == MEDIA_CONTENT_ERROR_NONE); - } + files.push_back(item->getFilePath()); } - return success; + return FileUtils::saveFilesToStorage(files); } void SaveAttachmentsPopup::showSavingFailedPopup() diff --git a/src/Common/MsgEngine/src/MsgEngine.cpp b/src/Common/MsgEngine/src/MsgEngine.cpp index 3cbfc51..d908426 100644 --- a/src/Common/MsgEngine/src/MsgEngine.cpp +++ b/src/Common/MsgEngine/src/MsgEngine.cpp @@ -56,7 +56,7 @@ int MsgEngine::openService() #ifdef TIZEN_PRIVATE_API int res = msg_open_msg_handle(&m_MsgHandle); - MSG_LOG_ERROR("handle open error = ", res); + MSG_LOG("handle open error = ", res); m_Storage.reset(new MsgStoragePrivate(m_MsgHandle)); m_Transport.reset(new MsgTransportPrivate(m_MsgHandle)); diff --git a/src/Common/Utils/inc/FileUtils.h b/src/Common/Utils/inc/FileUtils.h index b28d56d..de2ea59 100755 --- a/src/Common/Utils/inc/FileUtils.h +++ b/src/Common/Utils/inc/FileUtils.h @@ -19,6 +19,7 @@ #define __MSG_FILE_UTIL_H__ #include +#include namespace Msg { @@ -123,6 +124,20 @@ namespace Msg * the given file extension is not associated with specific file formats */ static std::string getMimeType(const std::string &filePath); + + /** + * @brief Save files to default storage directory + * @param[in] file list of file path + * @return Returns true if all ok, false otherwise + */ + static bool saveFilesToStorage(const std::list &files); + + /** + * @brief Save file to default storage directory + * @param[in] file path + * @return Returns true if all ok, false otherwise + */ + static bool saveFileToStorage(const std::string &file); }; } diff --git a/src/Common/Utils/src/FileUtils.cpp b/src/Common/Utils/src/FileUtils.cpp index bc94d00..c0a41ce 100755 --- a/src/Common/Utils/src/FileUtils.cpp +++ b/src/Common/Utils/src/FileUtils.cpp @@ -16,6 +16,7 @@ */ #include "FileUtils.h" +#include "PathUtils.h" #include #include @@ -27,6 +28,7 @@ #include #include #include +#include using namespace Msg; @@ -52,6 +54,7 @@ bool FileUtils::isExists(const std::string &file) return res; } +#include "Logger.h" bool FileUtils::copy(const std::string &src, const std::string &dst) { FILE *f1 = nullptr; @@ -59,18 +62,10 @@ bool FileUtils::copy(const std::string &src, const std::string &dst) const size_t bufSize = 4 * 1024; char buf[bufSize]; - char realPath1[PATH_MAX]; - char realPath2[PATH_MAX]; size_t num = 0; bool ret = true; - if(!realpath(src.c_str(), realPath1)) - return false; - - if(realpath(dst.c_str(), realPath2) && !strcmp(realPath1, realPath2)) - return false; - f1 = fopen(src.c_str(), "rb"); if(!f1) return false; @@ -251,3 +246,43 @@ std::string FileUtils::getMimeType(const std::string &filePath) } return res; } + +static bool saveFileToStoragePrivate(const std::string &file) +{ + bool res = false; + + std::string dowloadPath = PathUtils::getDownloadPath(); + std::string filePathDst = FileUtils::genUniqueFilePath(dowloadPath, file); + + if(FileUtils::copy(file, filePathDst)) + res = media_content_scan_file(filePathDst.c_str()) == MEDIA_CONTENT_ERROR_NONE; + + return res; +} + +bool FileUtils::saveFilesToStorage(const std::list &files) +{ + bool res = true; + if(media_content_connect() != 0) + return false; + + for(const std::string &file : files) + { + res &= saveFileToStoragePrivate(file); + } + media_content_disconnect(); + return res; +} + +bool FileUtils::saveFileToStorage(const std::string &file) +{ + if(media_content_connect() != 0) + return false; + + bool res = saveFileToStoragePrivate(file); + + media_content_disconnect(); + return res; +} + + diff --git a/src/Conversation/Body/Controller/src/Body.cpp b/src/Conversation/Body/Controller/src/Body.cpp index a0b2a54..07c95d5 100644 --- a/src/Conversation/Body/Controller/src/Body.cpp +++ b/src/Conversation/Body/Controller/src/Body.cpp @@ -556,8 +556,7 @@ void Body::onFileReady(const std::string &filePath) MSG_LOG("Media type: ", mediaType.mime); Page *page = nullptr; - if(mediaType.type != MsgMedia::UnknownType && - mediaType.type != MsgMedia::TextType) + if(mediaType.type != MsgMedia::UnknownType && mediaType.type != MsgMedia::TextType) { page = static_cast(getPageForMedia(msgMediaTypeToPageItemType(mediaType.type))); if(!page) diff --git a/src/Conversation/ConvList/Controller/inc/ConvListItem.h b/src/Conversation/ConvList/Controller/inc/ConvListItem.h index 4756d7c..0318c43 100644 --- a/src/Conversation/ConvList/Controller/inc/ConvListItem.h +++ b/src/Conversation/ConvList/Controller/inc/ConvListItem.h @@ -25,10 +25,10 @@ #include "Message.h" #include "ContextPopup.h" #include "App.h" -#include #include "MessageDetailContent.h" #include "FileViewer.h" #include "MsgUtils.h" +#include "WorkingDir.h" namespace Msg { diff --git a/src/Conversation/ConvList/Controller/src/ConvList.cpp b/src/Conversation/ConvList/Controller/src/ConvList.cpp index 9bfb1c6..3ae6926 100644 --- a/src/Conversation/ConvList/Controller/src/ConvList.cpp +++ b/src/Conversation/ConvList/Controller/src/ConvList.cpp @@ -40,7 +40,7 @@ ConvList::ConvList(Evas_Object *parent, App &app, WorkingDirRef workingDir) , m_pListner(nullptr) , m_App(app) , m_WorkingDir(workingDir) - , m_FileViewer(workingDir) + , m_FileViewer() , m_RecipThumbId(m_App.getThumbnailMaker().getThumbId(ThumbnailMaker::SingleThumb)) , m_SearchWord() { diff --git a/src/Conversation/Utils/src/WorkingDir.cpp b/src/Conversation/Utils/src/WorkingDir.cpp index 3ce2652..52c67af 100644 --- a/src/Conversation/Utils/src/WorkingDir.cpp +++ b/src/Conversation/Utils/src/WorkingDir.cpp @@ -32,11 +32,13 @@ const std::string textFileName = "mms.txt"; WorkingDir::WorkingDir() { + MSG_LOG(""); createWorkingDir(); } WorkingDir::~WorkingDir() { + MSG_LOG(""); removeWorkingDir(); } @@ -109,6 +111,11 @@ std::string WorkingDir::addFile(const std::string &path) { MSG_LOG("File added: ", newPath); } + else + { + MSG_LOG_ERROR("Can't copy to working dir: ", path); + newPath.clear(); + } } } diff --git a/src/Viewer/Controller/inc/SmilPage.h b/src/Viewer/Controller/inc/SmilPage.h index 7f547c3..775749a 100644 --- a/src/Viewer/Controller/inc/SmilPage.h +++ b/src/Viewer/Controller/inc/SmilPage.h @@ -21,6 +21,8 @@ #include "SmilPageLayout.h" #include "MsgPage.h" #include "MsgAttachment.h" +#include "SmilAttachmentItemView.h" +#include "FileViewer.h" #include @@ -30,6 +32,8 @@ namespace Msg class SmilPage : public SmilPageLayout + , private ISmilSaveAllItemViewListener + , private ISmilAttachmentItemViewListener { public: SmilPage(Evas_Object *parent, const MsgPage &page); @@ -54,9 +58,17 @@ namespace Msg void buildText(const MsgMedia& media); void buildAudio(const MsgMedia& media); void buildVideo(const MsgMedia& media); + void buildSaveAllItem(int attachmentCount); void buildAttachmentInfo(int attachmentCount); void buildAttachment(const MsgAttachment& attachment); + // ISmilAttachmentItemViewListener: + virtual void onItemClicked(SmilAttachmentItemView &item); + virtual void onSaveButtonClicked(SmilAttachmentItemView &item); + + // ISmilSaveAllItemViewListener: + virtual void onItemClicked(SmilSaveAllItemView &item); + private: int m_Duration; std::string m_MediaPath; @@ -64,6 +76,7 @@ namespace Msg bool m_HasAudio; SmilImageItemView *m_pImageItem; std::list m_Attachments; + FileViewer m_FileViewer; }; } diff --git a/src/Viewer/Controller/src/SmilPage.cpp b/src/Viewer/Controller/src/SmilPage.cpp index ce6377d..2d0996c 100644 --- a/src/Viewer/Controller/src/SmilPage.cpp +++ b/src/Viewer/Controller/src/SmilPage.cpp @@ -21,16 +21,15 @@ #include "SmilTextItemView.h" #include "SmilAudioItemView.h" #include "SmilVideoItemView.h" -#include "SmilAttachmentItemView.h" #include "Logger.h" #include "FileUtils.h" #include "MediaPlayer.h" #include "MediaUtils.h" +#include using namespace Msg; const int defaultPageDuration = 5; // sec; -std::string makeKbStr(long long bytes); SmilPage::SmilPage(Evas_Object *parent, const MsgPage &page) : SmilPageLayout(parent) @@ -165,6 +164,7 @@ void SmilPage::build(const MsgAttachmentList &list) return; buildAttachmentInfo(list.getLength()); + buildSaveAllItem(list.getLength()); for(int i = 0; i < list.getLength(); ++i) { buildAttachment(list[i]); @@ -226,6 +226,13 @@ void SmilPage::buildVideo(const MsgMedia& media) appendItem(*item); } +void SmilPage::buildSaveAllItem(int attachmentCount) +{ + SmilSaveAllItemView *item = new SmilSaveAllItemView(getBox(), attachmentCount); + item->setListener(this); + appendItem(*item); +} + void SmilPage::buildAttachmentInfo(int attachmentCount) { SmilAttachmentInfoItemView *item = new SmilAttachmentInfoItemView(getBox(), attachmentCount > 1); @@ -236,9 +243,32 @@ void SmilPage::buildAttachmentInfo(int attachmentCount) void SmilPage::buildAttachment(const MsgAttachment& attachment) { SmilAttachmentItemView *item = new SmilAttachmentItemView(getBox()); + item->setListener(this); item->setFilePath(attachment.getFilePath()); item->setFileName(attachment.getFileName()); - item->setFileSize(makeKbStr(attachment.getFileSize())); item->show(); appendItem(*item); } + +void SmilPage::onItemClicked(SmilAttachmentItemView &item) +{ + MSG_LOG(""); + m_FileViewer.launchWithCopy(item.getFilePath()); +} + +void SmilPage::onSaveButtonClicked(SmilAttachmentItemView &item) +{ + MSG_LOG(""); + if(FileUtils::saveFileToStorage(item.getFilePath())) + notification_status_message_post(msg("IDS_MSGF_POP_SAVED_IN_MY_FILES").cStr()); + // TODO: else +} + +void SmilPage::onItemClicked(SmilSaveAllItemView &item) +{ + MSG_LOG(""); + if(!m_Attachments.empty() && FileUtils::saveFilesToStorage(m_Attachments)) + notification_status_message_post(msg("IDS_MSGF_POP_SAVED_IN_MY_FILES").cStr()); + // TODO: else + +} diff --git a/src/Viewer/View/inc/SmilAttachmentItemView.h b/src/Viewer/View/inc/SmilAttachmentItemView.h index fd35aa5..c991274 100644 --- a/src/Viewer/View/inc/SmilAttachmentItemView.h +++ b/src/Viewer/View/inc/SmilAttachmentItemView.h @@ -23,31 +23,29 @@ namespace Msg { class ISmilAttachmentItemViewListener; + class ISmilSaveAllItemViewListener; + // SmilAttachmentItemView: class SmilAttachmentItemView : public View { public: - SmilAttachmentItemView(Evas_Object *parent, const std::string &thumbFilePath = ""); + SmilAttachmentItemView(Evas_Object *parent); virtual ~SmilAttachmentItemView(); void setListener(ISmilAttachmentItemViewListener *l); void setFileName(const std::string &name); - void setFileSize(const std::string &size); void setFilePath(const std::string &filePath); const std::string &getFilePath() const; // Return reference to file path private: - void onClickedCb(Evas_Object *obj, const char *emission, const char *source); - Evas_Object *createItem(Evas_Object *parent, const std::string &thumbFilePath); - Evas_Object *createIcon(Evas_Object *parent, const std::string &thumbFilePath); - - private: - Evas_Object *m_pItem; ISmilAttachmentItemViewListener *m_pListener; std::string m_FilePath; + Evas_Object *m_pFileButton; + Evas_Object *m_pSaveButton; }; + // SmilAttachmentInfoItemView : class SmilAttachmentInfoItemView : public View { @@ -56,11 +54,39 @@ namespace Msg virtual ~SmilAttachmentInfoItemView(); }; + // SmilSaveAllItemView : + class SmilSaveAllItemView + : public View + { + public: + SmilSaveAllItemView(Evas_Object *parent, int count); + virtual ~SmilSaveAllItemView(); + + void setListener(ISmilSaveAllItemViewListener *l); + + private: + void onLanguageChanged(Evas_Object *obj, void *eventInfo); + void updateTitle(); + + private: + Evas_Object *m_pButton; + ISmilSaveAllItemViewListener *m_pListener; + const int m_Count; + }; + class ISmilAttachmentItemViewListener { public: virtual ~ISmilAttachmentItemViewListener() {} virtual void onItemClicked(SmilAttachmentItemView &item) {}; + virtual void onSaveButtonClicked(SmilAttachmentItemView &item) {}; + }; + + class ISmilSaveAllItemViewListener + { + public: + virtual ~ISmilSaveAllItemViewListener() {} + virtual void onItemClicked(SmilSaveAllItemView &item) {}; }; } diff --git a/src/Viewer/View/src/SmilAttachmentItemView.cpp b/src/Viewer/View/src/SmilAttachmentItemView.cpp index f4e2c0a..01d5527 100644 --- a/src/Viewer/View/src/SmilAttachmentItemView.cpp +++ b/src/Viewer/View/src/SmilAttachmentItemView.cpp @@ -17,25 +17,76 @@ #include "SmilAttachmentItemView.h" #include "Resource.h" +#include "FileUtils.h" +#include "LangUtils.h" +#include "Logger.h" using namespace Msg; namespace { - const char *attachmentGroup = "smil_attachment_item"; - const char * attachmentLayoutGroup = "smil_attachment_item_layout"; - const char *iconPart = "item.thumbnail.icon"; - const char *fileNamePart = "item.filename.text"; - const char *fileSizePart = "item.filesize.text"; - const char *attachmentLayoutContentPart = "swallow.content"; + const float fileButtonWeight = 2.0 / 3.0; + const float saveButtonWeight = 1.0 / 3.0; + const char *layoutGroupName = "smil_attachment_item_layout"; + const char *layoutSwallowContent = "swallow.content"; + #define paddingBetweenButton ELM_SCALE_SIZE(16) } -SmilAttachmentItemView::SmilAttachmentItemView(Evas_Object *parent, const std::string &thumbFilePath) - : m_pItem(nullptr) - , m_pListener(nullptr) +SmilAttachmentItemView::SmilAttachmentItemView(Evas_Object *parent) + : m_pListener(nullptr) + , m_pFileButton(nullptr) + , m_pSaveButton(nullptr) { - setEo(addLayout(parent, SMIL_ITEM_EDJ_PATH, attachmentLayoutGroup)); - setContent(createItem(getEo(), thumbFilePath), attachmentLayoutContentPart); + setEo(addLayout(parent, SMIL_ITEM_EDJ_PATH, layoutGroupName)); + + // Box: + Evas_Object *box = elm_box_add(getEo()); + elm_box_horizontal_set(box, true); + elm_box_homogeneous_set(box, false); + elm_box_padding_set(box, paddingBetweenButton, 0); + evas_object_show(box); + + setContent(box, layoutSwallowContent); + + // File button: + m_pFileButton = elm_button_add(box); + evas_object_size_hint_weight_set(m_pFileButton, fileButtonWeight, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(m_pFileButton, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_smart_callback_add + ( + m_pFileButton, + "clicked", + [] (void *data, Evas_Object *obj, void *event_info) + { + auto *self = (SmilAttachmentItemView*)data; + if(self->m_pListener) + self->m_pListener->onItemClicked(*self); + }, + this + ); + evas_object_show(m_pFileButton); + + // Save button: + m_pSaveButton = elm_button_add(box); + evas_object_size_hint_weight_set(m_pSaveButton, saveButtonWeight, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(m_pSaveButton, EVAS_HINT_FILL, EVAS_HINT_FILL); + setText(m_pSaveButton, msgt("IDS_MSG_BUTTON_SAVE_ABB2")); + evas_object_smart_callback_add + ( + m_pSaveButton, + "clicked", + [] (void *data, Evas_Object *obj, void *event_info) + { + auto *self = (SmilAttachmentItemView*)data; + if(self->m_pListener) + self->m_pListener->onSaveButtonClicked(*self); + }, + this + ); + evas_object_show(m_pSaveButton); + + elm_box_pack_end(box, m_pFileButton); + elm_box_pack_end(box, m_pSaveButton); } SmilAttachmentItemView::~SmilAttachmentItemView() @@ -48,14 +99,14 @@ void SmilAttachmentItemView::setListener(ISmilAttachmentItemViewListener *l) m_pListener = l; } -void SmilAttachmentItemView::setFileName(const std::string &name) +const std::string &SmilAttachmentItemView::getFilePath() const { - elm_object_part_text_set(m_pItem, fileNamePart, name.c_str()); + return m_FilePath; } -void SmilAttachmentItemView::setFileSize(const std::string &size) +void SmilAttachmentItemView::setFileName(const std::string &name) { - elm_object_part_text_set(m_pItem, fileSizePart, size.c_str()); + elm_object_text_set(m_pFileButton, name.c_str()); } void SmilAttachmentItemView::setFilePath(const std::string &filePath) @@ -63,60 +114,72 @@ void SmilAttachmentItemView::setFilePath(const std::string &filePath) m_FilePath = filePath; } -const std::string &SmilAttachmentItemView::getFilePath() const +// SmilAttachmentInfoItemView: +SmilAttachmentInfoItemView::SmilAttachmentInfoItemView(Evas_Object *parent, bool manyAttachments) { - return m_FilePath; -} + setEo(addLayout(parent, SMIL_ITEM_EDJ_PATH, layoutGroupName)); -Evas_Object *SmilAttachmentItemView::createItem(Evas_Object *parent, const std::string &thumbFilePath) -{ - m_pItem = addLayout(parent, SMIL_ITEM_EDJ_PATH, attachmentGroup); - elm_object_signal_callback_add(m_pItem, "clicked", "*", EDJE_SIGNAL_CALLBACK(SmilAttachmentItemView, onClickedCb), this); + Evas_Object *entry = elm_entry_add(getEo()); + elm_entry_editable_set(entry, false); + evas_object_show(entry); - Evas_Object *icon = createIcon(m_pItem, thumbFilePath); - elm_object_part_content_set(m_pItem, iconPart, icon); + setContent(entry, layoutSwallowContent); - evas_object_show(m_pItem); - return m_pItem; + if(manyAttachments) + setText(entry, msgt("IDS_MSGF_POP_HELP_PAGE_MESSAGE")); + else + setText(entry, msgt("IDS_MSGF_POP_HELP_PAGE_MESSAGE_FOR_ONE_FILE")); } -Evas_Object *SmilAttachmentItemView::createIcon(Evas_Object *parent, const std::string &thumbFilePath) +SmilAttachmentInfoItemView::~SmilAttachmentInfoItemView() { - Evas_Object *thumbnail = elm_icon_add(parent); - if(thumbFilePath.empty()) - { - std::string imageEdjePath = PathUtils::getResourcePath(IMAGES_EDJ_PATH); - elm_image_file_set(thumbnail, imageEdjePath.c_str(), ATTACH_IMG); - } - else - { - // TODO: impl. if needed - } - evas_object_size_hint_aspect_set(thumbnail, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); - evas_object_color_set(thumbnail, ICON_COLOR); - evas_object_show(thumbnail); - return thumbnail; } -void SmilAttachmentItemView::onClickedCb(Evas_Object *obj, const char *emission, const char *source) +// SmilSaveAllItemView: +SmilSaveAllItemView::SmilSaveAllItemView(Evas_Object *parent, int count) + : m_pButton(nullptr) + , m_pListener(nullptr) + , m_Count(count) { - if(m_pListener) - m_pListener->onItemClicked(*this); + setEo(addLayout(parent, SMIL_ITEM_EDJ_PATH, layoutGroupName)); + m_pButton = elm_button_add(getEo()); + updateTitle(); + evas_object_smart_callback_add(m_pButton, "language,changed", SMART_CALLBACK(SmilSaveAllItemView, onLanguageChanged), this); + evas_object_smart_callback_add + ( + m_pButton, + "clicked", + [] (void *data, Evas_Object *obj, void *event_info) + { + auto *self = (SmilSaveAllItemView*)data; + if(self->m_pListener) + self->m_pListener->onItemClicked(*self); + }, + this + ); + evas_object_show(m_pButton); + setContent(m_pButton, layoutSwallowContent); } -// SmilAttachmentInfoItemView: +SmilSaveAllItemView::~SmilSaveAllItemView() +{ -SmilAttachmentInfoItemView::SmilAttachmentInfoItemView(Evas_Object *parent, bool manyAttachments) +} + +void SmilSaveAllItemView::setListener(ISmilSaveAllItemViewListener *l) { - setEo(elm_entry_add(parent)); - elm_entry_editable_set(getEo(), false); + m_pListener = l; +} - if(manyAttachments) - setText(msgt("IDS_MSGF_POP_HELP_PAGE_MESSAGE")); - else - setText(msgt("IDS_MSGF_POP_HELP_PAGE_MESSAGE_FOR_ONE_FILE")); +void SmilSaveAllItemView::updateTitle() +{ + std::string title = msg("IDS_MSGF_BUTTON_SAVE_ALL_ATTACHMENTS_ABB"); + title += " (" + std::to_string(m_Count) + ")"; + elm_object_text_set(m_pButton, title.c_str()); } -SmilAttachmentInfoItemView::~SmilAttachmentInfoItemView() +void SmilSaveAllItemView::onLanguageChanged(Evas_Object *obj, void *eventInfo) { + MSG_LOG(""); + updateTitle(); } -- 2.7.4