Add internal api to support C#
[platform/core/api/notification.git] / notification-ex / abstract_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 #include <uuid/uuid.h>
19 #include <unistd.h>
20
21 #include <memory>
22 #include <algorithm>
23 #include <vector>
24 #include <map>
25
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"
35
36 #ifdef LOG_TAG
37 #undef LOG_TAG
38 #endif
39
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
92 using namespace std;
93 using namespace tizen_base;
94 namespace notification {
95 namespace item {
96
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";
102
103 string AbstractItem::Impl::GenerateItemId() {
104   char uuid[37];
105   uuid_t u;
106   uuid_generate(u);
107   uuid_unparse(u, uuid);
108   string id = util::GetAppId();
109   return string(uuid) + ":" + id;
110 }
111
112 AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
113     : impl_(new Impl(this, action)) {
114 }
115
116 AbstractItem::AbstractItem(std::string id,
117     std::shared_ptr<AbstractAction> action)
118     : impl_(new Impl(this, id, action)) {
119 }
120
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)) {
125   if (id_.empty())
126     id_ = GenerateItemId();
127   sender_appid_ = util::GetAppId();
128   LOGI("AbstractItem created (%s)", id_.c_str());
129 }
130
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");
136
137   id_ = GenerateItemId();
138   sender_appid_ = util::GetAppId();
139   LOGI("AbstractItem created (%s)", id_.c_str());
140 }
141
142 AbstractItem::~AbstractItem() = default;
143 AbstractItem::Impl::~Impl() = default;
144
145 Bundle AbstractItem::Serialize() const {
146   Bundle b;
147   struct tm timeinfo;
148   char buf[80] = {0, };
149
150   if (impl_->uid_ == 0)
151     impl_->uid_ = getuid();
152
153   if (!impl_->channel_.empty())
154     b.Add(ABSTRACT_ITEM_CHANNEL_KEY, impl_->channel_);
155
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_);
165
166   localtime_r(&impl_->time_, &timeinfo);
167   strftime (buf, sizeof(buf), "%s", &timeinfo);
168   b.Add(ABSTRACT_ITEM_TIME_KEY, string(buf));
169
170   if (!impl_->can_receive_.empty())
171     b.Add(ABSTRACT_ITEM_CAN_RECEIVE_KEY, impl_->can_receive_);
172
173   if (!impl_->sound_path_.empty())
174     b.Add(ABSTRACT_ITEM_SOUND_PATH_KEY, impl_->sound_path_);
175
176   if (!impl_->vibration_path_.empty())
177     b.Add(ABSTRACT_ITEM_VIBRATION_PATH_KEY, impl_->vibration_path_);
178
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_));
184
185   if (impl_->receiver_group_list_.size() != 0) {
186     vector<string> arr;
187
188     for (auto& i : impl_->receiver_group_list_) {
189       string receiver = i;
190
191       arr.push_back(receiver);
192     }
193     b.Add(ABSTRACT_ITEM_RECEIVER_GROUP_KEY, arr);
194   }
195
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()));
205     }
206
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())));
217     }
218
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()));
227     }
228
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())));
239     }
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);
243   }
244
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);
257   }
258
259   if (impl_->action_ != nullptr) {
260     b.Add(ABSTRACT_ITEM_ACTION_KEY,
261       reinterpret_cast<char*>(impl_->action_->Serialize().ToRaw().first.get()));
262   }
263
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()));
267   }
268
269   if (impl_->multi_lang_arr_.size() > 0) {
270     vector<string> arr;
271     for (auto& i : impl_->multi_lang_arr_) {
272       arr.push_back(reinterpret_cast<char*>(i->Serialize().ToRaw().first.get()));
273     }
274     b.Add(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY, arr);
275   }
276
277   if (impl_->hide_viewer_list_.size() != 0) {
278     vector<string> arr;
279
280     for (auto& i : impl_->hide_viewer_list_) {
281       string viewer = i;
282
283       arr.push_back(viewer);
284     }
285     b.Add(ABSTRACT_ITEM_HIDE_VIEWER_KEY, arr);
286   }
287
288   return b;
289 }
290
291 void AbstractItem::Deserialize(Bundle b) {
292   string time_s;
293   struct tm timeinfo;
294
295   string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
296   if (type_str.empty())
297     THROW(ERROR_IO_ERROR);
298
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);
311
312   time_s = b.GetString(ABSTRACT_ITEM_TIME_KEY);
313   strptime(time_s.c_str(), "%s", &timeinfo);
314   impl_->time_ = mktime(&timeinfo);
315
316   string policy_str = b.GetString(ABSTRACT_ITEM_POLICY_KEY);
317
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)));
323
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);
328     }
329   }
330
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)));
339     }
340
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))));
352     }
353
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)));
361     }
362
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))));
374     }
375
376     impl_->style_ = make_shared<Style>(color, padding, geometry, bg_color,
377         b.GetString(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY));
378   }
379
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))));
390
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)));
394   }
395
396   string action_str = b.GetString(ABSTRACT_ITEM_ACTION_KEY);
397   if (!action_str.empty())
398     impl_->action_ = ActionInflator::Create(Bundle(action_str));
399
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));
403
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)));
409     }
410   }
411
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);
416     }
417   }
418 }
419
420 void AbstractItem::SetId(std::string id) {
421   impl_->id_ = id;
422 }
423
424 string AbstractItem::GetId() const {
425   return impl_->id_;
426 }
427
428 std::list<std::string> AbstractItem::GetSharedPath() const {
429   std::list<std::string> ret;
430
431   if (!impl_->priv_sound_path_.empty())
432     ret.push_back(impl_->priv_sound_path_);
433
434   if (!impl_->priv_vibration_path_.empty())
435     ret.push_back(impl_->priv_vibration_path_);
436
437   return ret;
438 }
439
440 void AbstractItem::SetSharedPath() {
441   if (!impl_->priv_sound_path_.empty())
442     impl_->sound_path_ = impl_->priv_sound_path_;
443
444   if (!impl_->priv_vibration_path_.empty())
445     impl_->vibration_path_ = impl_->priv_vibration_path_;
446 }
447
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;
451
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);
456   }
457
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);
462   }
463
464   return path_map_list;
465 }
466
467 shared_ptr<AbstractAction> AbstractItem::GetAction() const {
468   return impl_->action_;
469 }
470
471 void AbstractItem::SetAction(std::shared_ptr<AbstractAction> action) {
472   impl_->action_ = action;
473 }
474
475 shared_ptr<Style> AbstractItem::GetStyle() const {
476   return impl_->style_;
477 }
478
479 void AbstractItem::SetStyle(shared_ptr<Style> style) {
480   impl_->style_ = style;
481 }
482
483 void AbstractItem::SetLEDInfo(std::shared_ptr<LEDInfo> led) {
484   impl_->led_ = led;
485 }
486
487 std::shared_ptr<LEDInfo> AbstractItem::GetLEDInfo() const {
488   return impl_->led_;
489 }
490
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);
496 }
497
498 void AbstractItem::SetVisible(bool visible) {
499   impl_->visible_ = visible;
500 }
501
502 bool AbstractItem::GetVisible() const {
503   return impl_->visible_;
504 }
505
506 void AbstractItem::SetEnable(bool enable) {
507   impl_->enable_ = enable;
508 }
509
510 bool AbstractItem::GetEnable() const {
511   return impl_->enable_;
512 }
513
514 void AbstractItem::AddReceiver(std::string receiver_group) {
515   impl_->receiver_group_list_.push_back(receiver_group);
516 }
517
518 void AbstractItem::RemoveReceiver(std::string receiver_group) {
519   impl_->receiver_group_list_.remove(receiver_group);
520 }
521
522 list<string> AbstractItem::GetReceiverList() {
523   return impl_->receiver_group_list_;
524 }
525
526 void AbstractItem::SetPolicy(int policy) {
527   impl_->policy_ = policy;
528 }
529
530 int AbstractItem::GetPolicy() const {
531   return impl_->policy_;
532 }
533
534 std::shared_ptr<IItemInfo> AbstractItem::GetInfo() const {
535   return impl_->info_;
536 }
537
538 string AbstractItem::GetChannel() const {
539   return impl_->channel_;
540 }
541
542 void AbstractItem::SetChannel(string channel) {
543   impl_->channel_ = channel;
544 }
545
546 void AbstractItem::SetSoundPath(std::string path) {
547   impl_->sound_path_ = path;
548   UpdateSoundPrivatePath();
549 }
550
551 void AbstractItem::SetVibrationPath(std::string path) {
552   impl_->vibration_path_ = path;
553   UpdateVibrationPrivatePath();
554 }
555
556 std::string AbstractItem::GetSoundPath() const {
557   return impl_->sound_path_;
558 }
559
560 std::string AbstractItem::GetVibrationPath() const {
561   return impl_->vibration_path_;
562 }
563
564 std::string AbstractItem::GetSenderAppId() const {
565   return impl_->sender_appid_;
566 }
567
568 void AbstractItem::SetSenderAppId(std::string sender_appid) {
569   impl_->sender_appid_ = sender_appid;
570 }
571
572 std::string AbstractItem::GetTag() const {
573   return impl_->tag_;
574 }
575
576 void AbstractItem::SetTag(std::string tag) {
577   impl_->tag_ = tag;
578 }
579
580 void AbstractItem::SetOnGoingState(bool ongoing) {
581   impl_->ongoing_ = ongoing;
582 }
583
584 bool AbstractItem::GetOnGoingState() const {
585   return impl_->ongoing_;
586 }
587
588 bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
589   int item_type = target.GetType();
590
591   switch (type) {
592     case MainTitle:
593     case MainContents:
594       if (item_type != Text)
595         return false;
596       break;
597     case MainIcon:
598       if (item_type != Image)
599         return false;
600       break;
601     case MainButton:
602       if (item_type != Button)
603         return false;
604       break;
605     default:
606       return false;
607   }
608
609   return true;
610 }
611
612 bool AbstractItem::SetMainType(std::string target_id, MainType type) {
613   AbstractItem& target = FindByID(target_id);
614   if (target.GetType() == NullObject)
615     return false;
616   if (!impl_->IsValidMainType(target, type)) {
617     LOGE("Main type and item type are not matched (%d, %d)",
618         type, target.GetType());
619     return false;
620   }
621
622   AbstractItem& old = FindByMainType(type);
623   if (target.GetType() != NullObject)
624     old.impl_->main_type_ = MainNone;
625   target.impl_->main_type_ = type;
626
627   return true;
628 }
629
630 AbstractItem::MainType AbstractItem::GetMainType() const {
631   return impl_->main_type_;
632 }
633
634 AbstractItem& AbstractItem::FindByID(std::string id) {
635   if (GetId() == id)
636     return *this;
637
638   return FactoryManager::GetInst().GetNullItem();
639 }
640
641 AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
642   if (impl_->main_type_ == type)
643     return *this;
644
645   return FactoryManager::GetInst().GetNullItem();
646 }
647
648 std::shared_ptr<MultiLanguage> AbstractItem::GetMultiLanguage() const {
649   return impl_->multi_lang_;
650 }
651
652 vector<shared_ptr<MultiLanguage>> AbstractItem::GetMultiLanguageArr() const {
653   return impl_->multi_lang_arr_;
654 }
655
656 void AbstractItem::SetMultiLanguage(std::shared_ptr<MultiLanguage> multi) {
657   impl_->multi_lang_ = multi;
658 }
659
660 void AbstractItem::SetMultiLanguage(
661     vector<shared_ptr<MultiLanguage>> multi_arr) {
662   impl_->multi_lang_arr_ = multi_arr;
663 }
664
665 void AbstractItem::UpdateSoundPrivatePath() {
666   SharedFile* shared_file = new SharedFile();
667   if (!shared_file->IsPrivatePath(impl_->sound_path_)) {
668     delete(shared_file);
669     return;
670   }
671
672   std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
673             impl_->sound_path_);
674   if (!path.empty())
675     impl_->priv_sound_path_ = path;
676
677   delete(shared_file);
678 }
679
680 void AbstractItem::UpdateVibrationPrivatePath() {
681   SharedFile* shared_file = new SharedFile();
682   if (!shared_file->IsPrivatePath(impl_->vibration_path_)) {
683     delete(shared_file);
684     return;
685   }
686
687   std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
688             impl_->vibration_path_);
689   if (!path.empty())
690     impl_->priv_vibration_path_ = path;
691
692   delete(shared_file);
693 }
694
695 }  // namespace item
696 }  // namespace notification