Add manager implementation
[platform/core/api/notification.git] / notification-ex / entry_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/entry_item.h"
22 #include "notification-ex/entry_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 ENTRY_TEXT_KEY "__ENTRY_TEXT_KEY__"
31 #define ENTRY_LIMIT_KEY "__ENTRY_LIMIT_KEY__"
32
33 namespace notification {
34 namespace item {
35
36 EntryItem::EntryItem(std::shared_ptr<AbstractAction> action)
37   : AbstractItem(action), impl_(new Impl(this)) {
38 }
39
40 EntryItem::EntryItem(std::string id, std::shared_ptr<AbstractAction> action)
41   : AbstractItem(id, action), impl_(new Impl(this)) {
42 }
43
44 EntryItem::Impl::Impl(EntryItem* parent)
45   : parent_(parent) {
46   LOGI("EntryItem created");
47 }
48
49 EntryItem::~EntryItem() = default;
50 EntryItem::Impl::~Impl() = default;
51
52 int EntryItem::GetType() const {
53   return AbstractItem::Entry;
54 }
55
56 Bundle EntryItem::Serialize() const {
57   Bundle b;
58   b = AbstractItem::Serialize();
59
60   if (!impl_->text_.empty())
61     b.Add(ENTRY_TEXT_KEY, impl_->text_);
62
63   b.Add(ENTRY_LIMIT_KEY, std::to_string(impl_->limit_));
64
65   return b;
66 }
67
68 void EntryItem::Deserialize(Bundle b) {
69   AbstractItem::Deserialize(b);
70   impl_->text_ = b.GetString(ENTRY_TEXT_KEY);
71   impl_->limit_ = std::stoi(b.GetString(ENTRY_LIMIT_KEY));
72 }
73
74 AbstractItem& EntryItem::FindByID(std::string id) {
75   if (GetId() == id)
76     return *this;
77   return FactoryManager::GetInst().GetNullItem();
78 }
79
80 std::string EntryItem::GetText() const {
81   return impl_->text_;
82 }
83
84 void EntryItem::SetText(std::string text) {
85   impl_->text_ = text;
86 }
87
88 int EntryItem::GetTextLimit() const {
89   return impl_->limit_;
90 }
91
92 }  // namespace item
93 }  // namespace notification