Add is_type_exist function to an abstract item
[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/factory_manager.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 image_path,
35     std::shared_ptr<AbstractAction> action)
36     : AbstractItem(action), impl_(new Impl(this, image_path)) {
37 }
38
39 ImageItem::ImageItem(std::string id, std::string image_path,
40     std::shared_ptr<AbstractAction> action)
41     : AbstractItem(id, action), impl_(new Impl(this, image_path)) {
42 }
43
44 ImageItem::Impl::Impl(ImageItem* parent, std::string image_path)
45     : parent_(parent), image_path_(image_path) {
46   LOGI("ImageItem impl created");
47 }
48
49 int ImageItem::GetType() const {
50   return AbstractItem::Image;
51 }
52
53 Bundle ImageItem::Serialize() const {
54   Bundle b;
55   b = AbstractItem::Serialize();
56   b.Add(IMAGE_PATH_KEY, impl_->image_path_);
57
58   return b;
59 }
60
61 void ImageItem::Deserialize(Bundle b) {
62   AbstractItem::Deserialize(b);
63   impl_->image_path_ = b.GetString(IMAGE_PATH_KEY);
64 }
65
66 AbstractItem& ImageItem::FindByID(std::string id) {
67   if (GetId() == id)
68     return *this;
69
70   return FactoryManager::GetInst().GetNullItem();
71 }
72
73 bool ImageItem::IsItemTypeExist(int type) {
74   if (GetType() == type)
75     return true;
76   return false;
77 }
78
79 std::string ImageItem::GetImagePath() const {
80   return impl_->image_path_;
81 }
82
83 ImageItem::~ImageItem() = default;
84 ImageItem::Impl::~Impl() = default;
85
86 }  // namespace item
87 }  // namespace notification