Merge branch 'tizen' into tizen_5.5
[platform/core/api/notification.git] / notification-ex / input_selector_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 #include <vector>
21 #include <algorithm>
22
23 #include "notification-ex/input_selector_item.h"
24 #include "notification-ex/input_selector_item_implementation.h"
25 #include "notification-ex/factory_manager.h"
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "NOTIFICATION_EX"
32 #define INPUT_SELECTOR_CONTENTS_KEY "__INPUT_SELECTOR_CONTENTS_KEY__"
33
34 using namespace std;
35 using namespace tizen_base;
36
37 namespace notification {
38 namespace item {
39
40 InputSelectorItem::InputSelectorItem(std::shared_ptr<AbstractAction> action)
41     : AbstractItem(action), impl_(new Impl(this)) {
42 }
43
44 InputSelectorItem::InputSelectorItem(string id, std::shared_ptr<AbstractAction> action)
45     : AbstractItem(id, action), impl_(new Impl(this)) {
46 }
47
48 InputSelectorItem::~InputSelectorItem() = default;
49 InputSelectorItem::Impl::~Impl() = default;
50
51 InputSelectorItem::Impl::Impl(InputSelectorItem* parent)
52     : parent_(parent) {
53   LOGI("InputSelectorItem impl created");
54 }
55
56 int InputSelectorItem::GetType() const {
57   return AbstractItem::InputSelector;
58 }
59
60 Bundle InputSelectorItem::Serialize() const {
61   Bundle b;
62   b = AbstractItem::Serialize();
63   vector<string> contents_vector {
64     begin(impl_->contents_),
65     end(impl_->contents_)
66   };
67   b.Add(INPUT_SELECTOR_CONTENTS_KEY, contents_vector);
68   return b;
69 }
70
71 void InputSelectorItem::Deserialize(Bundle b) {
72   AbstractItem::Deserialize(b);
73   vector<string> contents = b.GetStringArray(INPUT_SELECTOR_CONTENTS_KEY);
74   impl_->contents_ = list<string>(contents.begin(), contents.end());
75 }
76
77 bool InputSelectorItem::IsItemTypeExist(int type) {
78   if (GetType() == type)
79     return true;
80   return false;
81 }
82
83 list<string> InputSelectorItem::GetContents() const {
84   return impl_->contents_;
85 }
86
87 void InputSelectorItem::SetContents(list<string> contents) {
88   impl_->contents_ = move(contents);
89 }
90
91 }  // namespace item
92 }  // namespace notification