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__"
91 #define ABSTRACT_ITEM_EXTENSION_DATA_KEY "__ABSTRACT_ITEM_EXTENSION_DATA_KEY__"
94 using namespace tizen_base;
95 namespace notification {
98 const string ReceiverGroup::Panel = "tizen.org/receiver/panel";
99 const string ReceiverGroup::Ticker = "tizen.org/receiver/ticker";
100 const string ReceiverGroup::LockScreen = "tizen.org/receiver/lockscreen";
101 const string ReceiverGroup::Indicator = "tizen.org/receiver/indicator";
102 const string ReceiverGroup::Popup = "tizen.org/receiver/popup";
104 string AbstractItem::Impl::GenerateItemId() {
108 uuid_unparse(u, uuid);
109 string id = util::GetAppId();
110 return string(uuid) + ":" + id;
113 AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
114 : impl_(new Impl(this, action)) {
117 AbstractItem::AbstractItem(std::string id,
118 std::shared_ptr<AbstractAction> action)
119 : impl_(new Impl(this, id, action)) {
122 AbstractItem::Impl::Impl(AbstractItem* parent, string id,
123 std::shared_ptr<AbstractAction> action)
124 : id_(id), action_(action), parent_(parent),
125 info_(std::make_shared<ItemInfo>(this)) {
127 id_ = GenerateItemId();
128 sender_appid_ = util::GetAppId();
129 LOGI("AbstractItem created (%s)", id_.c_str());
132 AbstractItem::Impl::Impl(AbstractItem* parent,
133 std::shared_ptr<AbstractAction> action)
134 : action_(action), parent_(parent),
135 info_(std::make_shared<ItemInfo>(this)) {
136 LOGI("AbstractItem created");
138 id_ = GenerateItemId();
139 sender_appid_ = util::GetAppId();
140 LOGI("AbstractItem created (%s)", id_.c_str());
143 AbstractItem::~AbstractItem() = default;
144 AbstractItem::Impl::~Impl() = default;
146 Bundle AbstractItem::Serialize() const {
149 char buf[80] = {0, };
151 if (impl_->uid_ == 0)
152 impl_->uid_ = getuid();
154 if (!impl_->channel_.empty())
155 b.Add(ABSTRACT_ITEM_CHANNEL_KEY, impl_->channel_);
157 b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_);
158 b.Add(ABSTRACT_ITEM_SENDER_APPID_KEY, impl_->sender_appid_);
159 b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string(GetType()));
160 b.Add(ABSTRACT_ITEM_VERSION_KEY, to_string(impl_->version_));
161 b.Add(ABSTRACT_ITEM_HIDE_TIME_KEY, to_string(impl_->hide_time_));
162 b.Add(ABSTRACT_ITEM_DELETE_TIME_KEY, to_string(impl_->delete_time_));
163 b.Add(ABSTRACT_ITEM_UID_KEY, to_string(impl_->uid_));
164 b.Add(ABSTRACT_ITEM_PRIVATE_ID_KEY, to_string(impl_->private_id_));
165 b.Add(ABSTRACT_ITEM_TAG_KEY, impl_->tag_);
167 localtime_r(&impl_->time_, &timeinfo);
168 strftime (buf, sizeof(buf), "%s", &timeinfo);
169 b.Add(ABSTRACT_ITEM_TIME_KEY, string(buf));
171 if (!impl_->can_receive_.empty())
172 b.Add(ABSTRACT_ITEM_CAN_RECEIVE_KEY, impl_->can_receive_);
174 if (!impl_->sound_path_.empty())
175 b.Add(ABSTRACT_ITEM_SOUND_PATH_KEY, impl_->sound_path_);
177 if (!impl_->vibration_path_.empty())
178 b.Add(ABSTRACT_ITEM_VIBRATION_PATH_KEY, impl_->vibration_path_);
180 b.Add(ABSTRACT_ITEM_VISIBLE_KEY, to_string((int)impl_->visible_));
181 b.Add(ABSTRACT_ITEM_ENABLE_KEY, to_string((int)impl_->enable_));
182 b.Add(ABSTRACT_ITEM_POLICY_KEY, to_string((int)impl_->policy_));
183 b.Add(ABSTRACT_ITEM_ONGOING_KEY, to_string((int)impl_->ongoing_));
184 b.Add(ABSTRACT_ITEM_MAIN_TYPE_KEY, to_string((int)impl_->main_type_));
186 if (impl_->receiver_group_list_.size() != 0) {
189 for (auto& i : impl_->receiver_group_list_) {
192 arr.push_back(receiver);
194 b.Add(ABSTRACT_ITEM_RECEIVER_GROUP_KEY, arr);
197 if (impl_->style_ != nullptr) {
198 shared_ptr<Padding> padding = impl_->style_->GetPadding();
199 if (padding.get() != nullptr) {
200 b.Add(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY, to_string(padding->GetLeft()));
201 b.Add(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY, to_string(padding->GetTop()));
202 b.Add(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY,
203 to_string(padding->GetRight()));
204 b.Add(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY,
205 to_string(padding->GetBottom()));
208 shared_ptr<Color> color = impl_->style_->GetColor();
209 if (color.get() != nullptr) {
210 b.Add(ABSTRACT_ITEM_STYLE_COLOR_A_KEY,
211 to_string(static_cast<int>(color->GetAVal())));
212 b.Add(ABSTRACT_ITEM_STYLE_COLOR_R_KEY,
213 to_string(static_cast<int>(color->GetRVal())));
214 b.Add(ABSTRACT_ITEM_STYLE_COLOR_G_KEY,
215 to_string(static_cast<int>(color->GetGVal())));
216 b.Add(ABSTRACT_ITEM_STYLE_COLOR_B_KEY,
217 to_string(static_cast<int>(color->GetBVal())));
220 shared_ptr<Geometry> geometry = impl_->style_->GetGeometry();
221 if (geometry.get() != nullptr) {
222 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY, to_string(geometry->GetX()));
223 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY, to_string(geometry->GetY()));
224 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY,
225 to_string(geometry->GetWidth()));
226 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY,
227 to_string(geometry->GetHeight()));
230 shared_ptr<Color> bg_color = impl_->style_->GetBackgroundColor();
231 if (bg_color.get() != nullptr) {
232 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY,
233 to_string(static_cast<int>(bg_color->GetAVal())));
234 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY,
235 to_string(static_cast<int>(bg_color->GetRVal())));
236 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY,
237 to_string(static_cast<int>(bg_color->GetGVal())));
238 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY,
239 to_string(static_cast<int>(bg_color->GetBVal())));
241 b.Add(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY,
242 impl_->style_->GetBackgroundImage());
243 b.Add(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
246 if (impl_->led_ != nullptr) {
247 b.Add(ABSTRACT_ITEM_LED_ON_PERIOD_KEY, to_string(impl_->led_->GetOnPeriod()));
248 b.Add(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY, to_string(impl_->led_->GetOffPeriod()));
249 b.Add(ABSTRACT_ITEM_LED_COLOR_A_KEY,
250 to_string(static_cast<int>(impl_->led_->GetColor()->GetAVal())));
251 b.Add(ABSTRACT_ITEM_LED_COLOR_R_KEY,
252 to_string(static_cast<int>(impl_->led_->GetColor()->GetRVal())));
253 b.Add(ABSTRACT_ITEM_LED_COLOR_G_KEY,
254 to_string(static_cast<int>(impl_->led_->GetColor()->GetGVal())));
255 b.Add(ABSTRACT_ITEM_LED_COLOR_B_KEY,
256 to_string(static_cast<int>(impl_->led_->GetColor()->GetBVal())));
257 b.Add(ABSTRACT_ITEM_LED_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
260 if (impl_->action_ != nullptr) {
261 b.Add(ABSTRACT_ITEM_ACTION_KEY,
262 reinterpret_cast<char*>(impl_->action_->Serialize().ToRaw().first.get()));
265 if (impl_->multi_lang_ != nullptr) {
266 b.Add(ABSTRACT_ITEM_MULTI_LANG_KEY,
267 reinterpret_cast<char*>(impl_->multi_lang_->Serialize().ToRaw().first.get()));
270 if (impl_->multi_lang_arr_.size() > 0) {
272 for (auto& i : impl_->multi_lang_arr_) {
273 arr.push_back(reinterpret_cast<char*>(i->Serialize().ToRaw().first.get()));
275 b.Add(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY, arr);
278 if (impl_->hide_viewer_list_.size() != 0) {
281 for (auto& i : impl_->hide_viewer_list_) {
284 arr.push_back(viewer);
286 b.Add(ABSTRACT_ITEM_HIDE_VIEWER_KEY, arr);
289 b.Add(ABSTRACT_ITEM_EXTENSION_DATA_KEY,
290 reinterpret_cast<char*>(impl_->extension_data_.ToRaw().first.get()));
295 void AbstractItem::Deserialize(Bundle b) {
299 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
300 if (type_str.empty())
301 THROW(ERROR_IO_ERROR);
303 impl_->id_ = b.GetString(ABSTRACT_ITEM_ID_KEY);
304 impl_->sender_appid_ = b.GetString(ABSTRACT_ITEM_SENDER_APPID_KEY);
305 impl_->channel_ = b.GetString(ABSTRACT_ITEM_CHANNEL_KEY);
306 impl_->version_ = stoi(b.GetString(ABSTRACT_ITEM_VERSION_KEY));
307 impl_->hide_time_ = stoi(b.GetString(ABSTRACT_ITEM_HIDE_TIME_KEY));
308 impl_->delete_time_ = stoi(b.GetString(ABSTRACT_ITEM_DELETE_TIME_KEY));
309 impl_->can_receive_ = b.GetString(ABSTRACT_ITEM_CAN_RECEIVE_KEY);
310 impl_->sound_path_ = b.GetString(ABSTRACT_ITEM_SOUND_PATH_KEY);
311 impl_->vibration_path_ = b.GetString(ABSTRACT_ITEM_VIBRATION_PATH_KEY);
312 impl_->uid_ = stoi(b.GetString(ABSTRACT_ITEM_UID_KEY));
313 impl_->private_id_ = stoi(b.GetString(ABSTRACT_ITEM_PRIVATE_ID_KEY));
314 impl_->tag_ = b.GetString(ABSTRACT_ITEM_TAG_KEY);
316 time_s = b.GetString(ABSTRACT_ITEM_TIME_KEY);
317 strptime(time_s.c_str(), "%s", &timeinfo);
318 impl_->time_ = mktime(&timeinfo);
320 string policy_str = b.GetString(ABSTRACT_ITEM_POLICY_KEY);
322 impl_->policy_ = static_cast<Policy>(stoi(policy_str));
323 impl_->visible_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_VISIBLE_KEY)));
324 impl_->enable_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ENABLE_KEY)));
325 impl_->ongoing_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ONGOING_KEY)));
326 impl_->main_type_ = static_cast<MainType>(stoi(b.GetString(ABSTRACT_ITEM_MAIN_TYPE_KEY)));
328 vector<string> receiver_group = b.GetStringArray(ABSTRACT_ITEM_RECEIVER_GROUP_KEY);
329 if (receiver_group.size() != 0) {
330 for (string str : receiver_group) {
331 impl_->receiver_group_list_.push_back(str);
335 if (!b.GetString(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
336 shared_ptr<Padding> padding;
337 if (!b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY).empty()) {
338 padding = make_shared<Padding>(
339 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY)),
340 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY)),
341 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY)),
342 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY)));
345 shared_ptr<Color> color;
346 if (!b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY).empty()) {
347 color = make_shared<Color>(
348 static_cast<unsigned char>(
349 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY))),
350 static_cast<unsigned char>(
351 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_R_KEY))),
352 static_cast<unsigned char>(
353 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_G_KEY))),
354 static_cast<unsigned char>(
355 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_B_KEY))));
358 shared_ptr<Geometry> geometry;
359 if (!b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY).empty()) {
360 geometry = make_shared<Geometry>(
361 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY)),
362 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY)),
363 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY)),
364 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY)));
367 shared_ptr<Color> bg_color;
368 if (!b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY).empty()) {
369 bg_color = make_shared<Color>(
370 static_cast<unsigned char>(
371 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY))),
372 static_cast<unsigned char>(
373 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY))),
374 static_cast<unsigned char>(
375 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY))),
376 static_cast<unsigned char>(
377 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY))));
380 impl_->style_ = make_shared<Style>(color, padding, geometry, bg_color,
381 b.GetString(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY));
384 if (!b.GetString(ABSTRACT_ITEM_LED_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
385 shared_ptr<Color> led_color = make_shared<Color>(
386 static_cast<unsigned char>(
387 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_A_KEY))),
388 static_cast<unsigned char>(
389 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_R_KEY))),
390 static_cast<unsigned char>(
391 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_G_KEY))),
392 static_cast<unsigned char>(
393 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_B_KEY))));
395 impl_->led_ = make_shared<LEDInfo>(led_color);
396 impl_->led_->SetOnPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_ON_PERIOD_KEY)));
397 impl_->led_->SetOffPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY)));
400 string action_str = b.GetString(ABSTRACT_ITEM_ACTION_KEY);
401 if (!action_str.empty())
402 impl_->action_ = ActionInflator::Create(Bundle(action_str));
404 string multi_str = b.GetString(ABSTRACT_ITEM_MULTI_LANG_KEY);
405 if (!multi_str.empty())
406 impl_->multi_lang_ = shared_ptr<MultiLanguage>(new MultiLanguage(multi_str));
408 vector<string> multi_arr_str = b.GetStringArray(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY);
409 if (!multi_arr_str.empty()) {
410 for (string str : multi_arr_str) {
411 impl_->multi_lang_arr_.push_back(
412 shared_ptr<MultiLanguage>(new MultiLanguage(str)));
416 vector<string> hide_viewer = b.GetStringArray(ABSTRACT_ITEM_HIDE_VIEWER_KEY);
417 if (hide_viewer.size() != 0) {
418 for (string str : hide_viewer) {
419 impl_->hide_viewer_list_.push_back(str);
423 impl_->extension_data_ = Bundle(b.GetString(ABSTRACT_ITEM_EXTENSION_DATA_KEY));
426 void AbstractItem::SetId(std::string id) {
430 string AbstractItem::GetId() const {
434 std::list<std::string> AbstractItem::GetSharedPath() const {
435 std::list<std::string> ret;
437 if (!impl_->priv_sound_path_.empty())
438 ret.push_back(impl_->priv_sound_path_);
440 if (!impl_->priv_vibration_path_.empty())
441 ret.push_back(impl_->priv_vibration_path_);
446 void AbstractItem::SetSharedPath() {
447 if (!impl_->priv_sound_path_.empty())
448 impl_->sound_path_ = impl_->priv_sound_path_;
450 if (!impl_->priv_vibration_path_.empty())
451 impl_->vibration_path_ = impl_->priv_vibration_path_;
454 std::list<std::map<std::string, std::string>> AbstractItem::GetPathMapList() const {
455 std::list<std::map<std::string, std::string>> path_map_list;
456 std::map<std::string, std::string> path_map;
458 if (!impl_->priv_sound_path_.empty()) {
459 path_map.insert(std::pair<std::string, std::string>(impl_->sound_path_,
460 impl_->priv_sound_path_));
461 path_map_list.push_back(path_map);
464 if (!impl_->priv_vibration_path_.empty()) {
465 path_map.insert(std::pair<std::string, std::string>(impl_->vibration_path_,
466 impl_->priv_vibration_path_));
467 path_map_list.push_back(path_map);
470 return path_map_list;
473 shared_ptr<AbstractAction> AbstractItem::GetAction() const {
474 return impl_->action_;
477 void AbstractItem::SetAction(std::shared_ptr<AbstractAction> action) {
478 impl_->action_ = action;
481 shared_ptr<Style> AbstractItem::GetStyle() const {
482 return impl_->style_;
485 void AbstractItem::SetStyle(shared_ptr<Style> style) {
486 impl_->style_ = style;
489 void AbstractItem::SetLEDInfo(std::shared_ptr<LEDInfo> led) {
493 std::shared_ptr<LEDInfo> AbstractItem::GetLEDInfo() const {
497 int AbstractItem::GetType(Bundle b) {
498 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
499 if (type_str.empty())
500 THROW(ERROR_IO_ERROR);
501 return strtol(type_str.c_str(), NULL, 10);
504 void AbstractItem::SetVisible(bool visible) {
505 impl_->visible_ = visible;
508 bool AbstractItem::GetVisible() const {
509 return impl_->visible_;
512 void AbstractItem::SetEnable(bool enable) {
513 impl_->enable_ = enable;
516 bool AbstractItem::GetEnable() const {
517 return impl_->enable_;
520 void AbstractItem::AddReceiver(std::string receiver_group) {
521 impl_->receiver_group_list_.push_back(receiver_group);
524 void AbstractItem::RemoveReceiver(std::string receiver_group) {
525 impl_->receiver_group_list_.remove(receiver_group);
528 list<string> AbstractItem::GetReceiverList() {
529 return impl_->receiver_group_list_;
532 void AbstractItem::SetPolicy(int policy) {
533 impl_->policy_ = policy;
536 int AbstractItem::GetPolicy() const {
537 return impl_->policy_;
540 std::shared_ptr<IItemInfo> AbstractItem::GetInfo() const {
544 string AbstractItem::GetChannel() const {
545 return impl_->channel_;
548 void AbstractItem::SetChannel(string channel) {
549 impl_->channel_ = channel;
552 void AbstractItem::SetSoundPath(std::string path) {
553 impl_->sound_path_ = path;
554 UpdateSoundPrivatePath();
557 void AbstractItem::SetVibrationPath(std::string path) {
558 impl_->vibration_path_ = path;
559 UpdateVibrationPrivatePath();
562 std::string AbstractItem::GetSoundPath() const {
563 return impl_->sound_path_;
566 std::string AbstractItem::GetVibrationPath() const {
567 return impl_->vibration_path_;
570 std::string AbstractItem::GetSenderAppId() const {
571 return impl_->sender_appid_;
574 void AbstractItem::SetSenderAppId(std::string sender_appid) {
575 impl_->sender_appid_ = sender_appid;
578 std::string AbstractItem::GetTag() const {
582 void AbstractItem::SetTag(std::string tag) {
586 void AbstractItem::SetOnGoingState(bool ongoing) {
587 impl_->ongoing_ = ongoing;
590 bool AbstractItem::GetOnGoingState() const {
591 return impl_->ongoing_;
594 bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
595 int item_type = target.GetType();
602 if (item_type != Text)
606 if (item_type != Image)
610 if (item_type != Button)
620 bool AbstractItem::SetMainType(std::string target_id, MainType type) {
621 AbstractItem& target = FindByID(target_id);
622 if (target.GetType() == NullObject)
625 if (type == MainNone) {
626 LOGW("Clear main type from %s", target_id.c_str());
627 target.impl_->main_type_ = MainNone;
631 if (!impl_->IsValidMainType(target, type)) {
632 LOGE("Main type and item type are not matched (%d, %d)",
633 type, target.GetType());
637 AbstractItem& old = FindByMainType(type);
638 if (target.GetType() != NullObject)
639 old.impl_->main_type_ = MainNone;
640 target.impl_->main_type_ = type;
645 AbstractItem::MainType AbstractItem::GetMainType() const {
646 return impl_->main_type_;
649 AbstractItem& AbstractItem::FindByID(std::string id) {
653 return FactoryManager::GetInst().GetNullItem();
656 AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
657 if (impl_->main_type_ == type)
660 return FactoryManager::GetInst().GetNullItem();
663 std::shared_ptr<MultiLanguage> AbstractItem::GetMultiLanguage() const {
664 return impl_->multi_lang_;
667 vector<shared_ptr<MultiLanguage>> AbstractItem::GetMultiLanguageArr() const {
668 return impl_->multi_lang_arr_;
671 void AbstractItem::SetMultiLanguage(std::shared_ptr<MultiLanguage> multi) {
672 impl_->multi_lang_ = multi;
675 void AbstractItem::SetMultiLanguage(
676 vector<shared_ptr<MultiLanguage>> multi_arr) {
677 impl_->multi_lang_arr_ = multi_arr;
680 void AbstractItem::UpdateSoundPrivatePath() {
681 SharedFile* shared_file = new SharedFile();
682 if (!shared_file->IsPrivatePath(impl_->sound_path_)) {
687 std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
690 impl_->priv_sound_path_ = path;
695 void AbstractItem::UpdateVibrationPrivatePath() {
696 SharedFile* shared_file = new SharedFile();
697 if (!shared_file->IsPrivatePath(impl_->vibration_path_)) {
702 std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
703 impl_->vibration_path_);
705 impl_->priv_vibration_path_ = path;
710 tizen_base::Bundle AbstractItem::GetExtensionData(std::string key) {
711 if (impl_->extension_data_.GetString(key) == "")
714 return Bundle(impl_->extension_data_.GetString(key));
717 void AbstractItem::SetExtensionData(std::string key, Bundle value) {
718 if (impl_->extension_data_.GetString(key) != "")
719 impl_->extension_data_.Delete(key);
721 impl_->extension_data_.Add(key,
722 reinterpret_cast<char*>(value.ToRaw().first.get()));
726 } // namespace notification