Merge "Update some items" into tizen
[platform/core/api/notification.git] / notification-ex / image_item.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlog.h>
18
19 #include "notification-ex/image_item.h"
20 #include "notification-ex/image_item_implementation.h"
21 #include "notification-ex/item_factory.h"
22 #include "notification-ex/exception.h"
23
24 #ifdef LOG_TAG
25 #undef LOG_TAG
26 #endif
27
28 #define LOG_TAG "NOTIFICATION_EX"
29 #define IMAGE_PATH_KEY "__IMAGE_PATH_KEY__"
30
31 namespace notification {
32 namespace item {
33
34 ImageItem::ImageItem(std::string imagePath,
35   std::shared_ptr<AbstractAction> action)
36   : AbstractItem(AbstractItem::Image, action), impl_(new Impl(this, imagePath)) {
37 }
38
39 ImageItem::ImageItem(std::string id, std::string imagePath,
40   std::shared_ptr<AbstractAction> action)
41   : AbstractItem(id, AbstractItem::Image, action), impl_(new Impl(this, imagePath)) {
42 }
43
44 ImageItem::Impl::Impl(ImageItem* parent, std::string imagePath)
45   : parent_(parent), imagePath_(imagePath) {
46   LOGI("ImageItem impl created");
47 }
48
49 Bundle ImageItem::Serialize() {
50   Bundle b;
51   b = AbstractItem::Serialize();
52   b.Add(IMAGE_PATH_KEY, impl_->imagePath_);
53
54   return b;
55 }
56
57 void ImageItem::Deserialize(Bundle b) {
58   AbstractItem::Deserialize(b);
59
60   impl_->imagePath_ = b.GetString(IMAGE_PATH_KEY);
61 }
62
63 AbstractItem& ImageItem::FindByID(std::string id) {
64   if (GetId() == id)
65     return *this;
66
67   return ItemFactory::GetNullItem();
68 }
69
70 std::string ImageItem::GetImagePath() const {
71   return impl_->imagePath_;
72 }
73
74 ImageItem::~ImageItem() = default;
75 ImageItem::Impl::~Impl() = default;
76
77
78 }  // namespace item
79 }  // namespace notification