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.
18 #include <uuid/uuid.h>
26 #include "notification-ex/exception.h"
27 #include "notification-ex/abstract_item.h"
28 #include "notification-ex/abstract_item_implementation.h"
29 #include "notification-ex/item_info_internal.h"
30 #include "notification-ex/multi_language.h"
31 #include "notification-ex/ex_util.h"
32 #include "notification-ex/action_inflator.h"
33 #include "notification-ex/factory_manager.h"
34 #include "notification-ex/shared_file.h"
40 #define LOG_TAG "NOTIFICATION_EX"
41 #define ABSTRACT_ITEM_TYPE_KEY "__ABSTRACT_ITEM_TYPE_KEY__"
42 #define ABSTRACT_ITEM_ID_KEY "__ABSTRACT_ITEM_ID_KEY__"
43 #define ABSTRACT_ITEM_UID_KEY "__ABSTRACT_ITEM_UID_KEY__"
44 #define ABSTRACT_ITEM_PRIVATE_ID_KEY "__ABSTRACT_ITEM_PRIVATE_ID_KEY__"
45 #define ABSTRACT_ITEM_TIME_KEY "__ABSTRACT_ITEM_TIME_KEY__"
46 #define ABSTRACT_ITEM_SENDER_APPID_KEY "__ABSTRACT_ITEM_SENDER_APPID_KEY__"
47 #define ABSTRACT_ITEM_TAG_KEY "__ABSTRACT_ITEM_TAG_KEY__"
48 #define ABSTRACT_ITEM_CHANNEL_KEY "__ABSTRACT_ITEM_CHANNEL_KEY__"
49 #define ABSTRACT_ITEM_VERSION_KEY "__ABSTRACT_ITEM_VERSION_KEY__"
50 #define ABSTRACT_ITEM_HIDE_TIME_KEY "__ABSTRACT_ITEM_HIDE_TIME_KEY__"
51 #define ABSTRACT_ITEM_DELETE_TIME_KEY "__ABSTRACT_ITEM_DELETE_TIME_KEY__"
52 #define ABSTRACT_ITEM_CAN_RECEIVE_KEY "__ABSTRACT_ITEM_CAN_RECEIVE_KEY__"
53 #define ABSTRACT_ITEM_SOUND_PATH_KEY "__ABSTRACT_ITEM_SOUND_PATH_KEY__"
54 #define ABSTRACT_ITEM_VIBRATION_PATH_KEY "__ABSTRACT_ITEM_VIBRATION_PATH_KEY__"
55 #define ABSTRACT_ITEM_POLICY_KEY "__ABSTRACT_ITEM_POLICY_KEY__"
56 #define ABSTRACT_ITEM_RECEIVER_GROUP_KEY "__ABSTRACT_ITEM_RECEIVER_GROUP_KEY__"
57 #define ABSTRACT_ITEM_VISIBLE_KEY "__ABSTRACT_ITEM_VISIBLE_KEY__"
58 #define ABSTRACT_ITEM_ENABLE_KEY "__ABSTRACT_ITEM_ENABLE_KEY__"
59 #define ABSTRACT_ITEM_STYLE_IS_EXIST_KEY "__ABSTRACT_ITEM_STYLE_IS_EXIST_KEY__"
60 #define ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY "__ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY__"
61 #define ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY "__ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY__"
62 #define ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY "__ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY__"
63 #define ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY "__ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY__"
64 #define ABSTRACT_ITEM_STYLE_COLOR_A_KEY "__ABSTRACT_ITEM_STYLE_COLOR_A_KEY__"
65 #define ABSTRACT_ITEM_STYLE_COLOR_R_KEY "__ABSTRACT_ITEM_STYLE_COLOR_R_KEY__"
66 #define ABSTRACT_ITEM_STYLE_COLOR_G_KEY "__ABSTRACT_ITEM_STYLE_COLOR_G_KEY__"
67 #define ABSTRACT_ITEM_STYLE_COLOR_B_KEY "__ABSTRACT_ITEM_STYLE_COLOR_B_KEY__"
68 #define ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY__"
69 #define ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY__"
70 #define ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY__"
71 #define ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY__"
72 #define ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY "__ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY__"
73 #define ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY__"
74 #define ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY__"
75 #define ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY__"
76 #define ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY__"
77 #define ABSTRACT_ITEM_LED_ON_PERIOD_KEY "__ABSTRACT_ITEM_LED_ON_PERIOD_KEY__"
78 #define ABSTRACT_ITEM_LED_OFF_PERIOD_KEY "__ABSTRACT_ITEM_LED_OFF_PERIOD_KEY__"
79 #define ABSTRACT_ITEM_LED_COLOR_A_KEY "__ABSTRACT_ITEM_LED_COLOR_A_KEY__"
80 #define ABSTRACT_ITEM_LED_COLOR_R_KEY "__ABSTRACT_ITEM_LED_COLOR_R_KEY__"
81 #define ABSTRACT_ITEM_LED_COLOR_G_KEY "__ABSTRACT_ITEM_LED_COLOR_G_KEY__"
82 #define ABSTRACT_ITEM_LED_COLOR_B_KEY "__ABSTRACT_ITEM_LED_COLOR_B_KEY__"
83 #define ABSTRACT_ITEM_LED_IS_EXIST_KEY "__ABSTRACT_ITEM_LED_IS_EXIST_KEY__"
84 #define ABSTRACT_ITEM_ACTION_KEY "__ABSTRACT_ITEM_ACTION_KEY__"
85 #define ABSTRACT_ITEM_HIDE_VIEWER_KEY "__ABSTRACT_ITEM_HIDE_VIEWER_KEY__"
86 #define ABSTRACT_ITEM_TRUE "TRUE"
87 #define ABSTRACT_ITEM_ONGOING_KEY "__ABSTRACT_ITEM_ONGOING_KEY__"
88 #define ABSTRACT_ITEM_MAIN_TYPE_KEY "__ABSTRACT_ITEM_MAIN_TYPE_KEY__"
89 #define ABSTRACT_ITEM_MULTI_LANG_ARR_KEY "__ABSTRACT_ITEM_MULTI_LANG_ARR_KEY__"
90 #define ABSTRACT_ITEM_MULTI_LANG_KEY "__ABSTRACT_ITEM_MULTI_LANG_KEY__"
93 using namespace tizen_base;
94 namespace notification {
97 const string ReceiverGroup::Panel = "tizen.org/receiver/panel";
98 const string ReceiverGroup::Ticker = "tizen.org/receiver/ticker";
99 const string ReceiverGroup::LockScreen = "tizen.org/receiver/lockscreen";
100 const string ReceiverGroup::Indicator = "tizen.org/receiver/indicator";
101 const string ReceiverGroup::Popup = "tizen.org/receiver/popup";
103 string AbstractItem::Impl::GenerateItemId() {
107 uuid_unparse(u, uuid);
108 string id = util::GetAppId();
109 return string(uuid) + ":" + id;
112 AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
113 : impl_(new Impl(this, action)) {
116 AbstractItem::AbstractItem(std::string id,
117 std::shared_ptr<AbstractAction> action)
118 : impl_(new Impl(this, id, action)) {
121 AbstractItem::Impl::Impl(AbstractItem* parent, string id,
122 std::shared_ptr<AbstractAction> action)
123 : id_(id), action_(action), parent_(parent),
124 info_(std::make_shared<ItemInfo>(this)) {
126 id_ = GenerateItemId();
127 sender_appid_ = util::GetAppId();
128 LOGI("AbstractItem created (%s)", id_.c_str());
131 AbstractItem::Impl::Impl(AbstractItem* parent,
132 std::shared_ptr<AbstractAction> action)
133 : action_(action), parent_(parent),
134 info_(std::make_shared<ItemInfo>(this)) {
135 LOGI("AbstractItem created");
137 id_ = GenerateItemId();
138 sender_appid_ = util::GetAppId();
139 LOGI("AbstractItem created (%s)", id_.c_str());
142 AbstractItem::~AbstractItem() = default;
143 AbstractItem::Impl::~Impl() = default;
145 Bundle AbstractItem::Serialize() const {
148 char buf[80] = {0, };
150 if (impl_->uid_ == 0)
151 impl_->uid_ = getuid();
153 if (!impl_->channel_.empty())
154 b.Add(ABSTRACT_ITEM_CHANNEL_KEY, impl_->channel_);
156 b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_);
157 b.Add(ABSTRACT_ITEM_SENDER_APPID_KEY, GetSenderAppId().c_str());
158 b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string(GetType()));
159 b.Add(ABSTRACT_ITEM_VERSION_KEY, to_string(impl_->version_));
160 b.Add(ABSTRACT_ITEM_HIDE_TIME_KEY, to_string(impl_->hide_time_));
161 b.Add(ABSTRACT_ITEM_DELETE_TIME_KEY, to_string(impl_->delete_time_));
162 b.Add(ABSTRACT_ITEM_UID_KEY, to_string(impl_->uid_));
163 b.Add(ABSTRACT_ITEM_PRIVATE_ID_KEY, to_string(impl_->private_id_));
164 b.Add(ABSTRACT_ITEM_TAG_KEY, impl_->tag_);
166 localtime_r(&impl_->time_, &timeinfo);
167 strftime (buf, sizeof(buf), "%s", &timeinfo);
168 b.Add(ABSTRACT_ITEM_TIME_KEY, string(buf));
170 if (!impl_->can_receive_.empty())
171 b.Add(ABSTRACT_ITEM_CAN_RECEIVE_KEY, impl_->can_receive_);
173 if (!impl_->sound_path_.empty())
174 b.Add(ABSTRACT_ITEM_SOUND_PATH_KEY, impl_->sound_path_);
176 if (!impl_->vibration_path_.empty())
177 b.Add(ABSTRACT_ITEM_VIBRATION_PATH_KEY, impl_->vibration_path_);
179 b.Add(ABSTRACT_ITEM_VISIBLE_KEY, to_string((int)impl_->visible_));
180 b.Add(ABSTRACT_ITEM_ENABLE_KEY, to_string((int)impl_->enable_));
181 b.Add(ABSTRACT_ITEM_POLICY_KEY, to_string((int)impl_->policy_));
182 b.Add(ABSTRACT_ITEM_ONGOING_KEY, to_string((int)impl_->ongoing_));
183 b.Add(ABSTRACT_ITEM_MAIN_TYPE_KEY, to_string((int)impl_->main_type_));
185 if (impl_->receiver_group_list_.size() != 0) {
188 for (auto& i : impl_->receiver_group_list_) {
191 arr.push_back(receiver);
193 b.Add(ABSTRACT_ITEM_RECEIVER_GROUP_KEY, arr);
196 if (impl_->style_ != nullptr) {
197 shared_ptr<Padding> padding = impl_->style_->GetPadding();
198 if (padding.get() != nullptr) {
199 b.Add(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY, to_string(padding->GetLeft()));
200 b.Add(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY, to_string(padding->GetTop()));
201 b.Add(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY,
202 to_string(padding->GetRight()));
203 b.Add(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY,
204 to_string(padding->GetBottom()));
207 shared_ptr<Color> color = impl_->style_->GetColor();
208 if (color.get() != nullptr) {
209 b.Add(ABSTRACT_ITEM_STYLE_COLOR_A_KEY,
210 to_string(static_cast<int>(color->GetAVal())));
211 b.Add(ABSTRACT_ITEM_STYLE_COLOR_R_KEY,
212 to_string(static_cast<int>(color->GetRVal())));
213 b.Add(ABSTRACT_ITEM_STYLE_COLOR_G_KEY,
214 to_string(static_cast<int>(color->GetGVal())));
215 b.Add(ABSTRACT_ITEM_STYLE_COLOR_B_KEY,
216 to_string(static_cast<int>(color->GetBVal())));
219 shared_ptr<Geometry> geometry = impl_->style_->GetGeometry();
220 if (geometry.get() != nullptr) {
221 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY, to_string(geometry->GetX()));
222 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY, to_string(geometry->GetY()));
223 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY,
224 to_string(geometry->GetWidth()));
225 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY,
226 to_string(geometry->GetHeight()));
229 shared_ptr<Color> bg_color = impl_->style_->GetBackgroundColor();
230 if (bg_color.get() != nullptr) {
231 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY,
232 to_string(static_cast<int>(bg_color->GetAVal())));
233 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY,
234 to_string(static_cast<int>(bg_color->GetRVal())));
235 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY,
236 to_string(static_cast<int>(bg_color->GetGVal())));
237 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY,
238 to_string(static_cast<int>(bg_color->GetBVal())));
240 b.Add(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY,
241 impl_->style_->GetBackgroundImage());
242 b.Add(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
245 if (impl_->led_ != nullptr) {
246 b.Add(ABSTRACT_ITEM_LED_ON_PERIOD_KEY, to_string(impl_->led_->GetOnPeriod()));
247 b.Add(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY, to_string(impl_->led_->GetOffPeriod()));
248 b.Add(ABSTRACT_ITEM_LED_COLOR_A_KEY,
249 to_string(static_cast<int>(impl_->led_->GetColor()->GetAVal())));
250 b.Add(ABSTRACT_ITEM_LED_COLOR_R_KEY,
251 to_string(static_cast<int>(impl_->led_->GetColor()->GetRVal())));
252 b.Add(ABSTRACT_ITEM_LED_COLOR_G_KEY,
253 to_string(static_cast<int>(impl_->led_->GetColor()->GetGVal())));
254 b.Add(ABSTRACT_ITEM_LED_COLOR_B_KEY,
255 to_string(static_cast<int>(impl_->led_->GetColor()->GetBVal())));
256 b.Add(ABSTRACT_ITEM_LED_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
259 if (impl_->action_ != nullptr) {
260 b.Add(ABSTRACT_ITEM_ACTION_KEY,
261 reinterpret_cast<char*>(impl_->action_->Serialize().ToRaw().first.get()));
264 if (impl_->multi_lang_ != nullptr) {
265 b.Add(ABSTRACT_ITEM_MULTI_LANG_KEY,
266 reinterpret_cast<char*>(impl_->multi_lang_->Serialize().ToRaw().first.get()));
269 if (impl_->multi_lang_arr_.size() > 0) {
271 for (auto& i : impl_->multi_lang_arr_) {
272 arr.push_back(reinterpret_cast<char*>(i->Serialize().ToRaw().first.get()));
274 b.Add(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY, arr);
277 if (impl_->hide_viewer_list_.size() != 0) {
280 for (auto& i : impl_->hide_viewer_list_) {
283 arr.push_back(viewer);
285 b.Add(ABSTRACT_ITEM_HIDE_VIEWER_KEY, arr);
291 void AbstractItem::Deserialize(Bundle b) {
295 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
296 if (type_str.empty())
297 THROW(ERROR_IO_ERROR);
299 impl_->id_ = b.GetString(ABSTRACT_ITEM_ID_KEY);
300 impl_->sender_appid_ = b.GetString(ABSTRACT_ITEM_SENDER_APPID_KEY);
301 impl_->channel_ = b.GetString(ABSTRACT_ITEM_CHANNEL_KEY);
302 impl_->version_ = stoi(b.GetString(ABSTRACT_ITEM_VERSION_KEY));
303 impl_->hide_time_ = stoi(b.GetString(ABSTRACT_ITEM_HIDE_TIME_KEY));
304 impl_->delete_time_ = stoi(b.GetString(ABSTRACT_ITEM_DELETE_TIME_KEY));
305 impl_->can_receive_ = b.GetString(ABSTRACT_ITEM_CAN_RECEIVE_KEY);
306 impl_->sound_path_ = b.GetString(ABSTRACT_ITEM_SOUND_PATH_KEY);
307 impl_->vibration_path_ = b.GetString(ABSTRACT_ITEM_VIBRATION_PATH_KEY);
308 impl_->uid_ = stoi(b.GetString(ABSTRACT_ITEM_UID_KEY));
309 impl_->private_id_ = stoi(b.GetString(ABSTRACT_ITEM_PRIVATE_ID_KEY));
310 impl_->tag_ = b.GetString(ABSTRACT_ITEM_TAG_KEY);
312 time_s = b.GetString(ABSTRACT_ITEM_TIME_KEY);
313 strptime(time_s.c_str(), "%s", &timeinfo);
314 impl_->time_ = mktime(&timeinfo);
316 string policy_str = b.GetString(ABSTRACT_ITEM_POLICY_KEY);
318 impl_->policy_ = static_cast<Policy>(stoi(policy_str));
319 impl_->visible_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_VISIBLE_KEY)));
320 impl_->enable_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ENABLE_KEY)));
321 impl_->ongoing_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ONGOING_KEY)));
322 impl_->main_type_ = static_cast<MainType>(stoi(b.GetString(ABSTRACT_ITEM_MAIN_TYPE_KEY)));
324 vector<string> receiver_group = b.GetStringArray(ABSTRACT_ITEM_RECEIVER_GROUP_KEY);
325 if (receiver_group.size() != 0) {
326 for (string str : receiver_group) {
327 impl_->receiver_group_list_.push_back(str);
331 if (!b.GetString(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
332 shared_ptr<Padding> padding;
333 if (!b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY).empty()) {
334 padding = make_shared<Padding>(
335 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY)),
336 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY)),
337 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY)),
338 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY)));
341 shared_ptr<Color> color;
342 if (!b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY).empty()) {
343 color = make_shared<Color>(
344 static_cast<unsigned char>(
345 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY))),
346 static_cast<unsigned char>(
347 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_R_KEY))),
348 static_cast<unsigned char>(
349 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_G_KEY))),
350 static_cast<unsigned char>(
351 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_B_KEY))));
354 shared_ptr<Geometry> geometry;
355 if (!b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY).empty()) {
356 geometry = make_shared<Geometry>(
357 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY)),
358 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY)),
359 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY)),
360 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY)));
363 shared_ptr<Color> bg_color;
364 if (!b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY).empty()) {
365 bg_color = make_shared<Color>(
366 static_cast<unsigned char>(
367 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY))),
368 static_cast<unsigned char>(
369 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY))),
370 static_cast<unsigned char>(
371 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY))),
372 static_cast<unsigned char>(
373 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY))));
376 impl_->style_ = make_shared<Style>(color, padding, geometry, bg_color,
377 b.GetString(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY));
380 if (!b.GetString(ABSTRACT_ITEM_LED_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
381 shared_ptr<Color> led_color = make_shared<Color>(
382 static_cast<unsigned char>(
383 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_A_KEY))),
384 static_cast<unsigned char>(
385 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_R_KEY))),
386 static_cast<unsigned char>(
387 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_G_KEY))),
388 static_cast<unsigned char>(
389 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_B_KEY))));
391 impl_->led_ = make_shared<LEDInfo>(led_color);
392 impl_->led_->SetOnPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_ON_PERIOD_KEY)));
393 impl_->led_->SetOffPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY)));
396 string action_str = b.GetString(ABSTRACT_ITEM_ACTION_KEY);
397 if (!action_str.empty())
398 impl_->action_ = ActionInflator::Create(Bundle(action_str));
400 string multi_str = b.GetString(ABSTRACT_ITEM_MULTI_LANG_KEY);
401 if (!multi_str.empty())
402 impl_->multi_lang_ = shared_ptr<MultiLanguage>(new MultiLanguage(multi_str));
404 vector<string> multi_arr_str = b.GetStringArray(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY);
405 if (!multi_arr_str.empty()) {
406 for (string str : multi_arr_str) {
407 impl_->multi_lang_arr_.push_back(
408 shared_ptr<MultiLanguage>(new MultiLanguage(str)));
412 vector<string> hide_viewer = b.GetStringArray(ABSTRACT_ITEM_HIDE_VIEWER_KEY);
413 if (hide_viewer.size() != 0) {
414 for (string str : hide_viewer) {
415 impl_->hide_viewer_list_.push_back(str);
420 void AbstractItem::SetId(std::string id) {
424 string AbstractItem::GetId() const {
428 std::list<std::string> AbstractItem::GetSharedPath() const {
429 std::list<std::string> ret;
431 if (!impl_->priv_sound_path_.empty())
432 ret.push_back(impl_->priv_sound_path_);
434 if (!impl_->priv_vibration_path_.empty())
435 ret.push_back(impl_->priv_vibration_path_);
440 void AbstractItem::SetSharedPath() {
441 if (!impl_->priv_sound_path_.empty())
442 impl_->sound_path_ = impl_->priv_sound_path_;
444 if (!impl_->priv_vibration_path_.empty())
445 impl_->vibration_path_ = impl_->priv_vibration_path_;
448 std::list<std::map<std::string, std::string>> AbstractItem::GetPathMapList() const {
449 std::list<std::map<std::string, std::string>> path_map_list;
450 std::map<std::string, std::string> path_map;
452 if (!impl_->priv_sound_path_.empty()) {
453 path_map.insert(std::pair<std::string, std::string>(impl_->sound_path_,
454 impl_->priv_sound_path_));
455 path_map_list.push_back(path_map);
458 if (!impl_->priv_vibration_path_.empty()) {
459 path_map.insert(std::pair<std::string, std::string>(impl_->vibration_path_,
460 impl_->priv_vibration_path_));
461 path_map_list.push_back(path_map);
464 return path_map_list;
467 shared_ptr<AbstractAction> AbstractItem::GetAction() const {
468 return impl_->action_;
471 void AbstractItem::SetAction(std::shared_ptr<AbstractAction> action) {
472 impl_->action_ = action;
475 shared_ptr<Style> AbstractItem::GetStyle() const {
476 return impl_->style_;
479 void AbstractItem::SetStyle(shared_ptr<Style> style) {
480 impl_->style_ = style;
483 void AbstractItem::SetLEDInfo(std::shared_ptr<LEDInfo> led) {
487 std::shared_ptr<LEDInfo> AbstractItem::GetLEDInfo() const {
491 int AbstractItem::GetType(Bundle b) {
492 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
493 if (type_str.empty())
494 THROW(ERROR_IO_ERROR);
495 return strtol(type_str.c_str(), NULL, 10);
498 void AbstractItem::SetVisible(bool visible) {
499 impl_->visible_ = visible;
502 bool AbstractItem::GetVisible() const {
503 return impl_->visible_;
506 void AbstractItem::SetEnable(bool enable) {
507 impl_->enable_ = enable;
510 bool AbstractItem::GetEnable() const {
511 return impl_->enable_;
514 void AbstractItem::AddReceiver(std::string receiver_group) {
515 impl_->receiver_group_list_.push_back(receiver_group);
518 void AbstractItem::RemoveReceiver(std::string receiver_group) {
519 impl_->receiver_group_list_.remove(receiver_group);
522 list<string> AbstractItem::GetReceiverList() {
523 return impl_->receiver_group_list_;
526 void AbstractItem::SetPolicy(int policy) {
527 impl_->policy_ = policy;
530 int AbstractItem::GetPolicy() const {
531 return impl_->policy_;
534 std::shared_ptr<IItemInfo> AbstractItem::GetInfo() const {
538 string AbstractItem::GetChannel() const {
539 return impl_->channel_;
542 void AbstractItem::SetChannel(string channel) {
543 impl_->channel_ = channel;
546 void AbstractItem::SetSoundPath(std::string path) {
547 impl_->sound_path_ = path;
548 UpdateSoundPrivatePath();
551 void AbstractItem::SetVibrationPath(std::string path) {
552 impl_->vibration_path_ = path;
553 UpdateVibrationPrivatePath();
556 std::string AbstractItem::GetSoundPath() const {
557 return impl_->sound_path_;
560 std::string AbstractItem::GetVibrationPath() const {
561 return impl_->vibration_path_;
564 std::string AbstractItem::GetSenderAppId() const {
565 return impl_->sender_appid_;
568 void AbstractItem::SetSenderAppId(std::string sender_appid) {
569 impl_->sender_appid_ = sender_appid;
572 std::string AbstractItem::GetTag() const {
576 void AbstractItem::SetTag(std::string tag) {
580 void AbstractItem::SetOnGoingState(bool ongoing) {
581 impl_->ongoing_ = ongoing;
584 bool AbstractItem::GetOnGoingState() const {
585 return impl_->ongoing_;
588 bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
589 int item_type = target.GetType();
594 if (item_type != Text)
598 if (item_type != Image)
602 if (item_type != Button)
612 bool AbstractItem::SetMainType(std::string target_id, MainType type) {
613 AbstractItem& target = FindByID(target_id);
614 if (target.GetType() == NullObject)
616 if (!impl_->IsValidMainType(target, type)) {
617 LOGE("Main type and item type are not matched (%d, %d)",
618 type, target.GetType());
622 AbstractItem& old = FindByMainType(type);
623 if (target.GetType() != NullObject)
624 old.impl_->main_type_ = MainNone;
625 target.impl_->main_type_ = type;
630 AbstractItem::MainType AbstractItem::GetMainType() const {
631 return impl_->main_type_;
634 AbstractItem& AbstractItem::FindByID(std::string id) {
638 return FactoryManager::GetInst().GetNullItem();
641 AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
642 if (impl_->main_type_ == type)
645 return FactoryManager::GetInst().GetNullItem();
648 std::shared_ptr<MultiLanguage> AbstractItem::GetMultiLanguage() const {
649 return impl_->multi_lang_;
652 vector<shared_ptr<MultiLanguage>> AbstractItem::GetMultiLanguageArr() const {
653 return impl_->multi_lang_arr_;
656 void AbstractItem::SetMultiLanguage(std::shared_ptr<MultiLanguage> multi) {
657 impl_->multi_lang_ = multi;
660 void AbstractItem::SetMultiLanguage(
661 vector<shared_ptr<MultiLanguage>> multi_arr) {
662 impl_->multi_lang_arr_ = multi_arr;
665 void AbstractItem::UpdateSoundPrivatePath() {
666 SharedFile* shared_file = new SharedFile();
667 if (!shared_file->IsPrivatePath(impl_->sound_path_)) {
672 std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
675 impl_->priv_sound_path_ = path;
680 void AbstractItem::UpdateVibrationPrivatePath() {
681 SharedFile* shared_file = new SharedFile();
682 if (!shared_file->IsPrivatePath(impl_->vibration_path_)) {
687 std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
688 impl_->vibration_path_);
690 impl_->priv_vibration_path_ = path;
696 } // namespace notification