Add action parameter to Base class for EntryItem and TextItem
[platform/core/api/notification.git] / notification-ex / text_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 <memory>
20
21 #include "notification-ex/text_item.h"
22 #include "notification-ex/text_item_implementation.h"
23 #include "notification-ex/factory_manager.h"
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28
29 #define LOG_TAG "NOTIFICATION_EX"
30 #define TEXT_CONTENTS_KEY "__TEXT_CONTENTS_KEY__"
31 #define TEXT_HYPERLINK_KEY "__TEXT_HYPERLINK_KEY__"
32
33 namespace notification {
34 namespace item {
35 TextItem::TextItem(std::string id, std::string text, std::string hyperlink,
36       std::shared_ptr<AbstractAction> action)
37   : AbstractItem(id, AbstractItem::Type::Text, action),
38   impl_(new Impl(this, text, hyperlink)) {
39 }
40
41 TextItem::Impl::Impl(TextItem* parent, std::string text, std::string hyperlink)
42   : parent_(parent), text_(text), hyperlink_(hyperlink) {
43   LOGI("TextItem created");
44 }
45
46 TextItem::~TextItem() = default;
47 TextItem::Impl::~Impl() = default;
48
49 Bundle TextItem::Serialize() {
50   Bundle b;
51   b = AbstractItem::Serialize();
52
53   if (!impl_->text_.empty())
54     b.Add(TEXT_CONTENTS_KEY, impl_->text_);
55
56   if (!impl_->hyperlink_.empty())
57     b.Add(TEXT_HYPERLINK_KEY, impl_->hyperlink_);
58
59   return b;
60 }
61
62 void TextItem::Deserialize(Bundle b) {
63   AbstractItem::Deserialize(b);
64   impl_->text_ = b.GetString(TEXT_CONTENTS_KEY);
65   impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY);
66 }
67
68 AbstractItem& TextItem::FindByID(std::string id) {
69   if (GetId() == id)
70     return *this;
71   return FactoryManager::GetInst().GetNullItem();
72 }
73
74 void TextItem::SetContents(std::string contents) {
75   impl_->text_ = contents;
76 }
77
78 std::string TextItem::GetContents() const {
79   return impl_->text_;
80 }
81
82 std::string TextItem::GetHyperLink() const {
83   return impl_->hyperlink_;
84 }
85
86 }  // namespace item
87 }  // namespace notification