Merge "Update some items" into tizen
[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/item_factory.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), impl_(new Impl(text, hyperlink)) {
38 }
39
40 TextItem::Impl::Impl(std::string text, std::string hyperlink)
41   : text_(text), hyperlink_(hyperlink) {
42   LOGI("TextItem created");
43 }
44
45 TextItem::~TextItem() = default;
46 TextItem::Impl::~Impl() = default;
47
48 Bundle TextItem::Serialize() {
49   Bundle b;
50   b = AbstractItem::Serialize();
51
52   if (!impl_->text_.empty())
53     b.Add(TEXT_CONTENTS_KEY, impl_->text_);
54
55   if (!impl_->hyperlink_.empty())
56     b.Add(TEXT_HYPERLINK_KEY, impl_->hyperlink_);
57
58   return b;
59 }
60
61 void TextItem::Deserialize(Bundle b) {
62   AbstractItem::Deserialize(b);
63   impl_->text_ = b.GetString(TEXT_CONTENTS_KEY);
64   impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY);
65 }
66
67 AbstractItem& TextItem::FindByID(std::string id) {
68   if (GetId() == id)
69     return *this;
70   return ItemFactory::GetNullItem();
71 }
72
73 void TextItem::SetContents(std::string contents) {
74   impl_->text_ = contents;
75 }
76
77 std::string TextItem::GetContents() const {
78   return impl_->text_;
79 }
80
81 std::string TextItem::GetHyperLink() const {
82   return impl_->hyperlink_;
83 }
84
85 }  // namespace item
86 }  // namespace notification