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>
25 #include "notification-ex/exception.h"
26 #include "notification-ex/abstract_item.h"
27 #include "notification-ex/abstract_item_implementation.h"
28 #include "notification-ex/item_info_internal.h"
29 #include "notification-ex/multi_language.h"
30 #include "notification-ex/ex_util.h"
31 #include "notification-ex/action_inflator.h"
32 #include "notification-ex/factory_manager.h"
38 #define LOG_TAG "NOTIFICATION_EX"
39 #define ABSTRACT_ITEM_TYPE_KEY "__ABSTRACT_ITEM_TYPE_KEY__"
40 #define ABSTRACT_ITEM_ID_KEY "__ABSTRACT_ITEM_ID_KEY__"
41 #define ABSTRACT_ITEM_UID_KEY "__ABSTRACT_ITEM_UID_KEY__"
42 #define ABSTRACT_ITEM_TIME_KEY "__ABSTRACT_ITEM_TIME_KEY__"
43 #define ABSTRACT_ITEM_SENDER_APPID_KEY "__ABSTRACT_ITEM_SENDER_APPID_KEY__"
44 #define ABSTRACT_ITEM_TAG_KEY "__ABSTRACT_ITEM_TAG_KEY__"
45 #define ABSTRACT_ITEM_CHANNEL_KEY "__ABSTRACT_ITEM_CHANNEL_KEY__"
46 #define ABSTRACT_ITEM_VERSION_KEY "__ABSTRACT_ITEM_VERSION_KEY__"
47 #define ABSTRACT_ITEM_HIDE_TIME_KEY "__ABSTRACT_ITEM_HIDE_TIME_KEY__"
48 #define ABSTRACT_ITEM_DELETE_TIME_KEY "__ABSTRACT_ITEM_DELETE_TIME_KEY__"
49 #define ABSTRACT_ITEM_CAN_RECEIVE_KEY "__ABSTRACT_ITEM_CAN_RECEIVE_KEY__"
50 #define ABSTRACT_ITEM_SOUND_PATH_KEY "__ABSTRACT_ITEM_SOUND_PATH_KEY__"
51 #define ABSTRACT_ITEM_VIBRATION_PATH_KEY "__ABSTRACT_ITEM_VIBRATION_PATH_KEY__"
52 #define ABSTRACT_ITEM_POLICY_KEY "__ABSTRACT_ITEM_POLICY_KEY__"
53 #define ABSTRACT_ITEM_RECEIVER_GROUP_KEY "__ABSTRACT_ITEM_RECEIVER_GROUP_KEY__"
54 #define ABSTRACT_ITEM_VISIBLE_KEY "__ABSTRACT_ITEM_VISIBLE_KEY__"
55 #define ABSTRACT_ITEM_ENABLE_KEY "__ABSTRACT_ITEM_ENABLE_KEY__"
56 #define ABSTRACT_ITEM_STYLE_IS_EXIST_KEY "__ABSTRACT_ITEM_STYLE_IS_EXIST_KEY__"
57 #define ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY "__ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY__"
58 #define ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY "__ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY__"
59 #define ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY "__ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY__"
60 #define ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY "__ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY__"
61 #define ABSTRACT_ITEM_STYLE_COLOR_A_KEY "__ABSTRACT_ITEM_STYLE_COLOR_A_KEY__"
62 #define ABSTRACT_ITEM_STYLE_COLOR_R_KEY "__ABSTRACT_ITEM_STYLE_COLOR_R_KEY__"
63 #define ABSTRACT_ITEM_STYLE_COLOR_G_KEY "__ABSTRACT_ITEM_STYLE_COLOR_G_KEY__"
64 #define ABSTRACT_ITEM_STYLE_COLOR_B_KEY "__ABSTRACT_ITEM_STYLE_COLOR_B_KEY__"
65 #define ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY__"
66 #define ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY__"
67 #define ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY__"
68 #define ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY "__ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY__"
69 #define ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY "__ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY__"
70 #define ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY__"
71 #define ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY__"
72 #define ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY__"
73 #define ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY "__ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY__"
74 #define ABSTRACT_ITEM_LED_ON_PERIOD_KEY "__ABSTRACT_ITEM_LED_ON_PERIOD_KEY__"
75 #define ABSTRACT_ITEM_LED_OFF_PERIOD_KEY "__ABSTRACT_ITEM_LED_OFF_PERIOD_KEY__"
76 #define ABSTRACT_ITEM_LED_COLOR_A_KEY "__ABSTRACT_ITEM_LED_COLOR_A_KEY__"
77 #define ABSTRACT_ITEM_LED_COLOR_R_KEY "__ABSTRACT_ITEM_LED_COLOR_R_KEY__"
78 #define ABSTRACT_ITEM_LED_COLOR_G_KEY "__ABSTRACT_ITEM_LED_COLOR_G_KEY__"
79 #define ABSTRACT_ITEM_LED_COLOR_B_KEY "__ABSTRACT_ITEM_LED_COLOR_B_KEY__"
80 #define ABSTRACT_ITEM_LED_IS_EXIST_KEY "__ABSTRACT_ITEM_LED_IS_EXIST_KEY__"
81 #define ABSTRACT_ITEM_ACTION_KEY "__ABSTRACT_ITEM_ACTION_KEY__"
82 #define ABSTRACT_ITEM_HIDE_VIEWER_KEY "__ABSTRACT_ITEM_HIDE_VIEWER_KEY__"
83 #define ABSTRACT_ITEM_TRUE "TRUE"
84 #define ABSTRACT_ITEM_ONGOING_KEY "__ABSTRACT_ITEM_ONGOING_KEY__"
85 #define ABSTRACT_ITEM_MAIN_TYPE_KEY "__ABSTRACT_ITEM_MAIN_TYPE_KEY__"
86 #define ABSTRACT_ITEM_MULTI_LANG_ARR_KEY "__ABSTRACT_ITEM_MULTI_LANG_ARR_KEY__"
87 #define ABSTRACT_ITEM_MULTI_LANG_KEY "__ABSTRACT_ITEM_MULTI_LANG_KEY__"
90 using namespace tizen_base;
91 namespace notification {
94 const string ReceiverGroup::Panel = "tizen.org/receiver/panel";
95 const string ReceiverGroup::Ticker = "tizen.org/receiver/ticker";
96 const string ReceiverGroup::LockScreen = "tizen.org/receiver/lockscreen";
97 const string ReceiverGroup::Indicator = "tizen.org/receiver/indicator";
98 const string ReceiverGroup::Popup = "tizen.org/receiver/popup";
100 string AbstractItem::Impl::GenerateItemId() {
104 uuid_unparse(u, uuid);
105 string id = util::GetAppId();
106 return string(uuid) + ":" + id;
109 AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
110 : impl_(new Impl(this, action)) {
113 AbstractItem::AbstractItem(std::string id,
114 std::shared_ptr<AbstractAction> action)
115 : impl_(new Impl(this, id, action)) {
118 AbstractItem::Impl::Impl(AbstractItem* parent, string id,
119 std::shared_ptr<AbstractAction> action)
120 : id_(id), action_(action), parent_(parent),
121 info_(std::make_shared<ItemInfo>(this)) {
123 id_ = GenerateItemId();
124 sender_appid_ = util::GetAppId();
125 LOGI("AbstractItem created (%s)", id_.c_str());
128 AbstractItem::Impl::Impl(AbstractItem* parent,
129 std::shared_ptr<AbstractAction> action)
130 : action_(action), parent_(parent),
131 info_(std::make_shared<ItemInfo>(this)) {
132 LOGI("AbstractItem created");
134 id_ = GenerateItemId();
135 sender_appid_ = util::GetAppId();
136 LOGI("AbstractItem created (%s)", id_.c_str());
139 AbstractItem::~AbstractItem() = default;
140 AbstractItem::Impl::~Impl() = default;
142 Bundle AbstractItem::Serialize() const {
145 char buf[80] = {0, };
147 if (impl_->uid_ == 0)
148 impl_->uid_ = getuid();
150 if (!impl_->channel_.empty())
151 b.Add(ABSTRACT_ITEM_CHANNEL_KEY, impl_->channel_);
153 b.Add(ABSTRACT_ITEM_ID_KEY, impl_->id_);
154 b.Add(ABSTRACT_ITEM_SENDER_APPID_KEY, GetSenderAppId().c_str());
155 b.Add(ABSTRACT_ITEM_TYPE_KEY, to_string(GetType()));
156 b.Add(ABSTRACT_ITEM_VERSION_KEY, to_string(impl_->version_));
157 b.Add(ABSTRACT_ITEM_HIDE_TIME_KEY, to_string(impl_->hide_time_));
158 b.Add(ABSTRACT_ITEM_DELETE_TIME_KEY, to_string(impl_->delete_time_));
159 b.Add(ABSTRACT_ITEM_UID_KEY, to_string(impl_->uid_));
160 b.Add(ABSTRACT_ITEM_TAG_KEY, impl_->tag_);
162 localtime_r(&impl_->time_, &timeinfo);
163 strftime (buf, sizeof(buf), "%s", &timeinfo);
164 b.Add(ABSTRACT_ITEM_TIME_KEY, string(buf));
166 if (!impl_->can_receive_.empty())
167 b.Add(ABSTRACT_ITEM_CAN_RECEIVE_KEY, impl_->can_receive_);
169 if (!impl_->sound_path_.empty())
170 b.Add(ABSTRACT_ITEM_SOUND_PATH_KEY, impl_->sound_path_);
172 if (!impl_->vibration_path_.empty())
173 b.Add(ABSTRACT_ITEM_VIBRATION_PATH_KEY, impl_->vibration_path_);
175 b.Add(ABSTRACT_ITEM_VISIBLE_KEY, to_string((int)impl_->visible_));
176 b.Add(ABSTRACT_ITEM_ENABLE_KEY, to_string((int)impl_->enable_));
177 b.Add(ABSTRACT_ITEM_POLICY_KEY, to_string((int)impl_->policy_));
178 b.Add(ABSTRACT_ITEM_ONGOING_KEY, to_string((int)impl_->ongoing_));
179 b.Add(ABSTRACT_ITEM_MAIN_TYPE_KEY, to_string((int)impl_->main_type_));
181 if (impl_->receiver_group_list_.size() != 0) {
184 for (auto& i : impl_->receiver_group_list_) {
187 arr.push_back(receiver);
189 b.Add(ABSTRACT_ITEM_RECEIVER_GROUP_KEY, arr);
192 if (impl_->style_ != nullptr) {
193 shared_ptr<Padding> padding = impl_->style_->GetPadding();
194 if (padding.get() != nullptr) {
195 b.Add(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY, to_string(padding->GetLeft()));
196 b.Add(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY, to_string(padding->GetTop()));
197 b.Add(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY,
198 to_string(padding->GetRight()));
199 b.Add(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY,
200 to_string(padding->GetBottom()));
203 shared_ptr<Color> color = impl_->style_->GetColor();
204 if (color.get() != nullptr) {
205 b.Add(ABSTRACT_ITEM_STYLE_COLOR_A_KEY,
206 to_string(static_cast<int>(color->GetAVal())));
207 b.Add(ABSTRACT_ITEM_STYLE_COLOR_R_KEY,
208 to_string(static_cast<int>(color->GetRVal())));
209 b.Add(ABSTRACT_ITEM_STYLE_COLOR_G_KEY,
210 to_string(static_cast<int>(color->GetGVal())));
211 b.Add(ABSTRACT_ITEM_STYLE_COLOR_B_KEY,
212 to_string(static_cast<int>(color->GetBVal())));
215 shared_ptr<Geometry> geometry = impl_->style_->GetGeometry();
216 if (geometry.get() != nullptr) {
217 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY, to_string(geometry->GetX()));
218 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY, to_string(geometry->GetY()));
219 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY,
220 to_string(geometry->GetWidth()));
221 b.Add(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY,
222 to_string(geometry->GetHeight()));
225 shared_ptr<Color> bg_color = impl_->style_->GetBackgroundColor();
226 if (bg_color.get() != nullptr) {
227 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY,
228 to_string(static_cast<int>(bg_color->GetAVal())));
229 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY,
230 to_string(static_cast<int>(bg_color->GetRVal())));
231 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY,
232 to_string(static_cast<int>(bg_color->GetGVal())));
233 b.Add(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY,
234 to_string(static_cast<int>(bg_color->GetBVal())));
236 b.Add(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY,
237 impl_->style_->GetBackgroundImage());
238 b.Add(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
241 if (impl_->led_ != nullptr) {
242 b.Add(ABSTRACT_ITEM_LED_ON_PERIOD_KEY, to_string(impl_->led_->GetOnPeriod()));
243 b.Add(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY, to_string(impl_->led_->GetOffPeriod()));
244 b.Add(ABSTRACT_ITEM_LED_COLOR_A_KEY,
245 to_string(static_cast<int>(impl_->led_->GetColor()->GetAVal())));
246 b.Add(ABSTRACT_ITEM_LED_COLOR_R_KEY,
247 to_string(static_cast<int>(impl_->led_->GetColor()->GetRVal())));
248 b.Add(ABSTRACT_ITEM_LED_COLOR_G_KEY,
249 to_string(static_cast<int>(impl_->led_->GetColor()->GetGVal())));
250 b.Add(ABSTRACT_ITEM_LED_COLOR_B_KEY,
251 to_string(static_cast<int>(impl_->led_->GetColor()->GetBVal())));
252 b.Add(ABSTRACT_ITEM_LED_IS_EXIST_KEY, ABSTRACT_ITEM_TRUE);
255 if (impl_->action_ != nullptr) {
256 b.Add(ABSTRACT_ITEM_ACTION_KEY,
257 reinterpret_cast<char*>(impl_->action_->Serialize().ToRaw().first.get()));
260 if (impl_->multi_lang_ != nullptr) {
261 b.Add(ABSTRACT_ITEM_MULTI_LANG_KEY,
262 reinterpret_cast<char*>(impl_->multi_lang_->Serialize().ToRaw().first.get()));
265 if (impl_->multi_lang_arr_.size() > 0) {
267 for (auto& i : impl_->multi_lang_arr_) {
268 arr.push_back(reinterpret_cast<char*>(i->Serialize().ToRaw().first.get()));
270 b.Add(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY, arr);
273 if (impl_->hide_viewer_list_.size() != 0) {
276 for (auto& i : impl_->hide_viewer_list_) {
279 arr.push_back(viewer);
281 b.Add(ABSTRACT_ITEM_HIDE_VIEWER_KEY, arr);
287 void AbstractItem::Deserialize(Bundle b) {
291 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
292 if (type_str.empty())
293 THROW(ERROR_IO_ERROR);
295 impl_->id_ = b.GetString(ABSTRACT_ITEM_ID_KEY);
296 impl_->sender_appid_ = b.GetString(ABSTRACT_ITEM_SENDER_APPID_KEY);
297 impl_->channel_ = b.GetString(ABSTRACT_ITEM_CHANNEL_KEY);
298 impl_->version_ = stoi(b.GetString(ABSTRACT_ITEM_VERSION_KEY));
299 impl_->hide_time_ = stoi(b.GetString(ABSTRACT_ITEM_HIDE_TIME_KEY));
300 impl_->delete_time_ = stoi(b.GetString(ABSTRACT_ITEM_DELETE_TIME_KEY));
301 impl_->can_receive_ = b.GetString(ABSTRACT_ITEM_CAN_RECEIVE_KEY);
302 impl_->sound_path_ = b.GetString(ABSTRACT_ITEM_SOUND_PATH_KEY);
303 impl_->vibration_path_ = b.GetString(ABSTRACT_ITEM_VIBRATION_PATH_KEY);
304 impl_->uid_ = stoi(b.GetString(ABSTRACT_ITEM_UID_KEY));
305 impl_->tag_ = b.GetString(ABSTRACT_ITEM_TAG_KEY);
307 time_s = b.GetString(ABSTRACT_ITEM_TIME_KEY);
308 strptime(time_s.c_str(), "%s", &timeinfo);
309 impl_->time_ = mktime(&timeinfo);
311 string policy_str = b.GetString(ABSTRACT_ITEM_POLICY_KEY);
313 impl_->policy_ = static_cast<Policy>(stoi(policy_str));
314 impl_->visible_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_VISIBLE_KEY)));
315 impl_->enable_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ENABLE_KEY)));
316 impl_->ongoing_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ONGOING_KEY)));
317 impl_->main_type_ = static_cast<MainType>(stoi(b.GetString(ABSTRACT_ITEM_MAIN_TYPE_KEY)));
319 vector<string> receiver_group = b.GetStringArray(ABSTRACT_ITEM_RECEIVER_GROUP_KEY);
320 if (receiver_group.size() != 0) {
321 for (string str : receiver_group) {
322 impl_->receiver_group_list_.push_back(str);
326 if (!b.GetString(ABSTRACT_ITEM_STYLE_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
327 shared_ptr<Padding> padding;
328 if (!b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY).empty()) {
329 padding = make_shared<Padding>(
330 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_LEFT_KEY)),
331 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_TOP_KEY)),
332 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_RIGHT_KEY)),
333 stoi(b.GetString(ABSTRACT_ITEM_STYLE_PADDING_BOTTOM_KEY)));
336 shared_ptr<Color> color;
337 if (!b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY).empty()) {
338 color = make_shared<Color>(
339 static_cast<unsigned char>(
340 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_A_KEY))),
341 static_cast<unsigned char>(
342 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_R_KEY))),
343 static_cast<unsigned char>(
344 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_G_KEY))),
345 static_cast<unsigned char>(
346 stoi(b.GetString(ABSTRACT_ITEM_STYLE_COLOR_B_KEY))));
349 shared_ptr<Geometry> geometry;
350 if (!b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY).empty()) {
351 geometry = make_shared<Geometry>(
352 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_X_KEY)),
353 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_Y_KEY)),
354 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_WIDTH_KEY)),
355 stoi(b.GetString(ABSTRACT_ITEM_STYLE_GEOMETRY_HEIGHT_KEY)));
358 shared_ptr<Color> bg_color;
359 if (!b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY).empty()) {
360 bg_color = make_shared<Color>(
361 static_cast<unsigned char>(
362 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_A_KEY))),
363 static_cast<unsigned char>(
364 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_R_KEY))),
365 static_cast<unsigned char>(
366 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_G_KEY))),
367 static_cast<unsigned char>(
368 stoi(b.GetString(ABSTRACT_ITEM_STYLE_BG_COLOR_B_KEY))));
371 impl_->style_ = make_shared<Style>(color, padding, geometry, bg_color,
372 b.GetString(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY));
375 if (!b.GetString(ABSTRACT_ITEM_LED_IS_EXIST_KEY).compare(ABSTRACT_ITEM_TRUE)) {
376 shared_ptr<Color> led_color = make_shared<Color>(
377 static_cast<unsigned char>(
378 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_A_KEY))),
379 static_cast<unsigned char>(
380 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_R_KEY))),
381 static_cast<unsigned char>(
382 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_G_KEY))),
383 static_cast<unsigned char>(
384 stoi(b.GetString(ABSTRACT_ITEM_LED_COLOR_B_KEY))));
386 impl_->led_ = make_shared<LEDInfo>(led_color);
387 impl_->led_->SetOnPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_ON_PERIOD_KEY)));
388 impl_->led_->SetOffPeriod(stoi(b.GetString(ABSTRACT_ITEM_LED_OFF_PERIOD_KEY)));
391 string action_str = b.GetString(ABSTRACT_ITEM_ACTION_KEY);
392 if (!action_str.empty())
393 impl_->action_ = ActionInflator::Create(Bundle(action_str));
395 string multi_str = b.GetString(ABSTRACT_ITEM_MULTI_LANG_KEY);
396 if (!multi_str.empty())
397 impl_->multi_lang_ = shared_ptr<MultiLanguage>(new MultiLanguage(multi_str));
399 vector<string> multi_arr_str = b.GetStringArray(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY);
400 if (!multi_arr_str.empty()) {
401 for (string str : multi_arr_str) {
402 impl_->multi_lang_arr_.push_back(
403 shared_ptr<MultiLanguage>(new MultiLanguage(str)));
407 vector<string> hide_viewer = b.GetStringArray(ABSTRACT_ITEM_HIDE_VIEWER_KEY);
408 if (hide_viewer.size() != 0) {
409 for (string str : hide_viewer) {
410 impl_->hide_viewer_list_.push_back(str);
415 void AbstractItem::SetId(std::string id) {
419 string AbstractItem::GetId() const {
423 std::list<std::string> AbstractItem::GetSharedPath() const {
427 shared_ptr<AbstractAction> AbstractItem::GetAction() const {
428 return impl_->action_;
431 void AbstractItem::SetAction(std::shared_ptr<AbstractAction> action) {
432 impl_->action_ = action;
435 shared_ptr<Style> AbstractItem::GetStyle() const {
436 return impl_->style_;
439 void AbstractItem::SetStyle(shared_ptr<Style> style) {
440 impl_->style_ = style;
443 void AbstractItem::SetLEDInfo(std::shared_ptr<LEDInfo> led) {
447 std::shared_ptr<LEDInfo> AbstractItem::GetLEDInfo() const {
451 int AbstractItem::GetType(Bundle b) {
452 string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
453 if (type_str.empty())
454 THROW(ERROR_IO_ERROR);
455 return strtol(type_str.c_str(), NULL, 10);
458 void AbstractItem::SetVisible(bool visible) {
459 impl_->visible_ = visible;
462 bool AbstractItem::GetVisible() const {
463 return impl_->visible_;
466 void AbstractItem::SetEnable(bool enable) {
467 impl_->enable_ = enable;
470 bool AbstractItem::GetEnable() const {
471 return impl_->enable_;
474 void AbstractItem::AddReceiver(std::string receiver_group) {
475 impl_->receiver_group_list_.push_back(receiver_group);
478 void AbstractItem::RemoveReceiver(std::string receiver_group) {
479 impl_->receiver_group_list_.remove(receiver_group);
482 list<string> AbstractItem::GetReceiverList() {
483 return impl_->receiver_group_list_;
486 void AbstractItem::SetPolicy(int policy) {
487 impl_->policy_ = policy;
490 int AbstractItem::GetPolicy() const {
491 return impl_->policy_;
494 std::shared_ptr<IItemInfo> AbstractItem::GetInfo() const {
498 string AbstractItem::GetChannel() const {
499 return impl_->channel_;
502 void AbstractItem::SetChannel(string channel) {
503 impl_->channel_ = channel;
506 void AbstractItem::SetSoundPath(std::string path) {
507 impl_->sound_path_ = path;
510 void AbstractItem::SetVibrationPath(std::string path) {
511 impl_->vibration_path_ = path;
514 std::string AbstractItem::GetSoundPath() const {
515 return impl_->sound_path_;
518 std::string AbstractItem::GetVibrationPath() const {
519 return impl_->vibration_path_;
522 std::string AbstractItem::GetSenderAppId() const {
523 return impl_->sender_appid_;
526 void AbstractItem::SetSenderAppId(std::string sender_appid) {
527 impl_->sender_appid_ = sender_appid;
530 std::string AbstractItem::GetTag() const {
534 void AbstractItem::SetTag(std::string tag) {
538 void AbstractItem::SetOnGoingState(bool ongoing) {
539 impl_->ongoing_ = ongoing;
542 bool AbstractItem::GetOnGoingState() const {
543 return impl_->ongoing_;
546 bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
547 int item_type = target.GetType();
552 if (item_type != Text)
556 if (item_type != Image)
560 if (item_type != Button)
570 bool AbstractItem::SetMainType(std::string target_id, MainType type) {
571 AbstractItem& target = FindByID(target_id);
572 if (target.GetType() == NullObject)
574 if (!impl_->IsValidMainType(target, type)) {
575 LOGE("Main type and item type are not matched (%d, %d)",
576 type, target.GetType());
580 AbstractItem& old = FindByMainType(type);
581 if (target.GetType() != NullObject)
582 old.impl_->main_type_ = MainNone;
583 target.impl_->main_type_ = type;
588 AbstractItem::MainType AbstractItem::GetMainType() const {
589 return impl_->main_type_;
592 AbstractItem& AbstractItem::FindByID(std::string id) {
596 return FactoryManager::GetInst().GetNullItem();
599 AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
600 if (impl_->main_type_ == type)
603 return FactoryManager::GetInst().GetNullItem();
606 std::shared_ptr<MultiLanguage> AbstractItem::GetMultiLanguage() const {
607 return impl_->multi_lang_;
610 vector<shared_ptr<MultiLanguage>> AbstractItem::GetMultiLanguageArr() const {
611 return impl_->multi_lang_arr_;
614 void AbstractItem::SetMultiLanguage(std::shared_ptr<MultiLanguage> multi) {
615 impl_->multi_lang_ = multi;
618 void AbstractItem::SetMultiLanguage(
619 vector<shared_ptr<MultiLanguage>> multi_arr) {
620 impl_->multi_lang_arr_ = multi_arr;
624 } // namespace notification