Merge branch 'tizen' into tizen_5.5
[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
33 using namespace std;
34 using namespace tizen_base;
35
36 namespace notification {
37 namespace item {
38
39 ButtonItem::ButtonItem(string title, std::shared_ptr<AbstractAction> action)
40     : AbstractItem(action), impl_(new Impl(this, title)) {
41 }
42
43 ButtonItem::ButtonItem(string id, string title,
44     std::shared_ptr<AbstractAction> action)
45     : AbstractItem(id, action), impl_(new Impl(this, title)) {
46 }
47
48 ButtonItem::~ButtonItem() = default;
49 ButtonItem::Impl::~Impl() = default;
50
51 ButtonItem::Impl::Impl(ButtonItem* parent, string title)
52     : title_(title), parent_(parent) {
53   LOGI("ButtonItem impl created");
54 }
55
56 int ButtonItem::GetType() const {
57   return AbstractItem::Button;
58 }
59
60 Bundle ButtonItem::Serialize() const {
61   Bundle b;
62   b = AbstractItem::Serialize();
63   b.Add(BUTTON_TITLE_KEY, impl_->title_);
64   if (!impl_->img_path_.empty())
65     b.Add(BUTTON_IMAGE_KEY, impl_->img_path_);
66   return b;
67 }
68
69 void ButtonItem::Deserialize(Bundle b) {
70   AbstractItem::Deserialize(b);
71   impl_->title_ = b.GetString(BUTTON_TITLE_KEY);
72   impl_->img_path_ = b.GetString(BUTTON_IMAGE_KEY);
73 }
74
75 bool ButtonItem::IsItemTypeExist(int type) {
76   if (GetType() == type)
77     return true;
78   return false;
79 }
80
81 std::string ButtonItem::GetTitle() const {
82   return impl_->title_;
83 }
84
85 void ButtonItem::SetImgPath(string path) {
86   impl_->img_path_ = path;
87 }
88
89 std::string ButtonItem::GetImgPath() const {
90   return impl_->img_path_;
91 }
92
93 }  // namespace item
94 }  // namespace notification