2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/types.h>
26 #include "notification-ex/image_item.h"
27 #include "notification-ex/image_item_implementation.h"
28 #include "notification-ex/factory_manager.h"
29 #include "notification-ex/exception.h"
30 #include "notification-ex/shared_file.h"
31 #include "notification-ex/item_info_internal.h"
32 #include "notification-ex/ex_util.h"
38 #define LOG_TAG "NOTIFICATION_EX"
39 #define IMAGE_PATH_KEY "__IMAGE_PATH_KEY__"
40 #define PRIV_IMAGE_PATH_KEY "__PRIV_IMAGE_PATH_KEY__"
42 using namespace tizen_base;
44 namespace notification {
46 ImageItem::ImageItem(std::string image_path,
47 std::shared_ptr<AbstractAction> action)
48 : AbstractItem(action), impl_(new Impl(this, image_path)) {
52 ImageItem::ImageItem(std::string id, std::string image_path,
53 std::shared_ptr<AbstractAction> action)
54 : AbstractItem(id, action), impl_(new Impl(this, image_path)) {
58 ImageItem::Impl::Impl(ImageItem* parent, std::string image_path)
59 : parent_(parent), image_path_(image_path) {
60 LOGI("ImageItem impl created");
63 int ImageItem::GetType() const {
64 return AbstractItem::Image;
67 Bundle ImageItem::Serialize() const {
69 b = AbstractItem::Serialize();
70 b.Add(IMAGE_PATH_KEY, impl_->image_path_);
72 if (!impl_->priv_image_path_.empty())
73 b.Add(PRIV_IMAGE_PATH_KEY, impl_->priv_image_path_);
78 void ImageItem::Deserialize(Bundle b) {
79 AbstractItem::Deserialize(b);
80 impl_->image_path_ = b.GetString(IMAGE_PATH_KEY);
81 impl_->priv_image_path_ = b.GetString(PRIV_IMAGE_PATH_KEY);
84 bool ImageItem::IsItemTypeExist(int type) {
85 if (GetType() == type)
90 std::string ImageItem::GetImagePath() const {
91 return impl_->image_path_;
94 std::list<std::string> ImageItem::GetSharedPath() const {
95 std::list<std::string> ret;
97 if (!impl_->priv_image_path_.empty())
98 ret.push_back(impl_->priv_image_path_);
103 void ImageItem::SetSharedPath() {
104 if (!impl_->priv_image_path_.empty())
105 impl_->image_path_ = impl_->priv_image_path_;
108 std::list<std::map<std::string, std::string>> ImageItem::GetPathMapList() const {
109 std::list<std::map<std::string, std::string>> path_map_list;
110 std::map<std::string, std::string> path_map;
112 if (!impl_->priv_image_path_.empty()) {
113 path_map.insert(std::pair<std::string, std::string>(impl_->image_path_,
114 impl_->priv_image_path_));
115 path_map_list.push_back(path_map);
118 return path_map_list;
121 void ImageItem::UpdatePrivatePath() {
124 SharedFile* shared_file = new SharedFile();
125 if (!shared_file->IsPrivatePath(impl_->image_path_)) {
130 path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
133 impl_->priv_image_path_ = path;
138 ImageItem::~ImageItem() = default;
139 ImageItem::Impl::~Impl() = default;
142 } // namespace notification