Fix group name for noti_ex
[platform/core/api/notification.git] / notification-ex / checkbox_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 "notification-ex/checkbox_item.h"
20 #include "notification-ex/checkbox_item_implementation.h"
21 #include "notification-ex/factory_manager.h"
22 #include "notification-ex/exception.h"
23
24 #ifdef LOG_TAG
25 #undef LOG_TAG
26 #endif
27
28 #define LOG_TAG "NOTIFICATION_EX"
29 #define CHECKBOX_TITLE_KEY "__CHECKBOX_TITLE_KEY__"
30 #define CHECKBOX_CHECKED_KEY "__CHECKBOX_CHECKED_KEY__"
31
32 using namespace tizen_base;
33
34 namespace notification {
35 namespace item {
36
37 CheckBoxItem::CheckBoxItem(std::string id, std::string title, bool checked,
38     std::shared_ptr<AbstractAction> action)
39     : AbstractItem(id, action), impl_(new Impl(this, title, checked)) {
40 }
41
42 CheckBoxItem::Impl::Impl(CheckBoxItem* parent, std::string title, bool checked)
43     : parent_(parent), title_(title), checked_(checked) {
44   LOGI("CheckBoxItem impl created");
45 }
46
47 int CheckBoxItem::GetType() const {
48   return AbstractItem::CheckBox;
49 }
50
51 Bundle CheckBoxItem::Serialize() const {
52   Bundle b;
53
54   b = AbstractItem::Serialize();
55   b.Add(CHECKBOX_TITLE_KEY, impl_->title_);
56   b.Add(CHECKBOX_CHECKED_KEY, std::to_string(impl_->checked_));
57
58   return b;
59 }
60
61 void CheckBoxItem::Deserialize(Bundle b) {
62   AbstractItem::Deserialize(b);
63
64   impl_->title_ = b.GetString(CHECKBOX_TITLE_KEY);
65   impl_->checked_ = std::stoi(b.GetString(CHECKBOX_CHECKED_KEY));
66 }
67
68 bool CheckBoxItem::IsItemTypeExist(int type) {
69   if (GetType() == type)
70     return true;
71   return false;
72 }
73
74 std::string CheckBoxItem::GetTitle(void) const {
75   return impl_->title_;
76 }
77
78 bool CheckBoxItem::IsChecked(void) const {
79   return impl_->checked_;
80 }
81
82 void CheckBoxItem::SetChecked(bool checked) {
83   impl_->checked_ = checked;
84 }
85
86 CheckBoxItem::~CheckBoxItem() = default;
87 CheckBoxItem::Impl::~Impl() = default;
88
89 }  // namespace item
90 }  // namespace notification