Update description for chat_message item
[platform/core/api/notification.git] / notification-ex / button_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/button_item.h"
22 #include "notification-ex/button_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 BUTTON_TITLE_KEY "__BUTTON_TITLE_KEY__"
31 #define BUTTON_IMAGE_KEY "__BUTTON_IMAGE_KEY__"
32 #define BUTTON_CONTENTS_KEY "__BUTTON_CONTENTS_KEY__"
33
34 using namespace std;
35 using namespace tizen_base;
36
37 namespace notification {
38 namespace item {
39
40 ButtonItem::ButtonItem(string title, std::shared_ptr<AbstractAction> action)
41     : AbstractItem(action), impl_(new Impl(this, title)) {
42 }
43
44 ButtonItem::ButtonItem(string id, string title,
45     std::shared_ptr<AbstractAction> action)
46     : AbstractItem(id, action), impl_(new Impl(this, title)) {
47 }
48
49 ButtonItem::~ButtonItem() = default;
50 ButtonItem::Impl::~Impl() = default;
51
52 ButtonItem::Impl::Impl(ButtonItem* parent, string title)
53     : title_(title), parent_(parent) {
54   LOGI("ButtonItem impl created");
55 }
56
57 int ButtonItem::GetType() const {
58   return AbstractItem::Button;
59 }
60
61 Bundle ButtonItem::Serialize() const {
62   Bundle b;
63   b = AbstractItem::Serialize();
64   b.Add(BUTTON_TITLE_KEY, impl_->title_);
65   if (!impl_->img_path_.empty())
66     b.Add(BUTTON_IMAGE_KEY, impl_->img_path_);
67   if (!impl_->contents_.empty())
68     b.Add(BUTTON_CONTENTS_KEY, impl_->contents_);
69   return b;
70 }
71
72 void ButtonItem::Deserialize(Bundle b) {
73   AbstractItem::Deserialize(b);
74   impl_->title_ = b.GetString(BUTTON_TITLE_KEY);
75   impl_->img_path_ = b.GetString(BUTTON_IMAGE_KEY);
76   impl_->contents_ = b.GetString(BUTTON_CONTENTS_KEY);
77 }
78
79 bool ButtonItem::IsItemTypeExist(int type) {
80   if (GetType() == type)
81     return true;
82   return false;
83 }
84
85 std::string ButtonItem::GetTitle() const {
86   return impl_->title_;
87 }
88
89 void ButtonItem::SetImgPath(string path) {
90   impl_->img_path_ = path;
91 }
92
93 std::string ButtonItem::GetImgPath() const {
94   return impl_->img_path_;
95 }
96
97 void ButtonItem::SetContents(std::string contents) {
98   impl_->contents_ = contents;
99 }
100
101 std::string ButtonItem::GetContents() const {
102   return impl_->contents_;
103 }
104
105 }  // namespace item
106 }  // namespace notification