2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "notification-ex/time_item.h"
20 #include "notification-ex/time_item_implementation.h"
21 #include "notification-ex/factory_manager.h"
22 #include "notification-ex/exception.h"
28 #define LOG_TAG "NOTIFICATION_EX"
29 #define TIME_KEY "__TIME_KEY__"
31 using namespace tizen_base;
33 namespace notification {
36 TimeItem::TimeItem(std::shared_ptr<AbstractAction> action)
37 : AbstractItem(action), impl_(new Impl(this, 0)) {
41 impl_->time_ = current_time;
44 TimeItem::TimeItem(time_t time, std::shared_ptr<AbstractAction> action)
45 : AbstractItem(action), impl_(new Impl(this, time)) {
48 TimeItem::TimeItem(std::string id, time_t time,
49 std::shared_ptr<AbstractAction> action)
50 : AbstractItem(id, action), impl_(new Impl(this, time)) {
53 TimeItem::Impl::Impl(TimeItem* parent, time_t time)
54 : parent_(parent), time_(time) {
55 LOGI("TimeItem impl created");
58 int TimeItem::GetType() const {
59 return AbstractItem::Time;
62 Bundle TimeItem::Serialize() const {
67 b = AbstractItem::Serialize();
70 localtime_r(&impl_->time_, &timeinfo);
72 strftime (buf, sizeof(buf), "%s", &timeinfo);
73 b.Add(TIME_KEY, std::string(buf));
78 void TimeItem::Deserialize(Bundle b) {
82 AbstractItem::Deserialize(b);
83 time_s = b.GetString(TIME_KEY);
86 strptime(time_s.c_str(), "%s", &timeinfo);
88 impl_->time_ = mktime(&timeinfo);
91 bool TimeItem::IsItemTypeExist(int type) {
92 if (GetType() == type)
97 time_t TimeItem::GetTime() const {
101 void TimeItem::SetTime(time_t time) {
105 TimeItem::~TimeItem() = default;
106 TimeItem::Impl::~Impl() = default;
109 } // namespace notification