To not to GetSharedPath if there is no image item in chat-message item
[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 #define ABSTRACT_ITEM_EXTENSION_DATA_KEY "__ABSTRACT_ITEM_EXTENSION_DATA_KEY__"
92
93 using namespace std;
94 using namespace tizen_base;
95 namespace notification {
96 namespace item {
97
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";
103
104 string AbstractItem::Impl::GenerateItemId() {
105   char uuid[37];
106   uuid_t u;
107   uuid_generate(u);
108   uuid_unparse(u, uuid);
109   string id = util::GetAppId();
110   return string(uuid) + ":" + id;
111 }
112
113 AbstractItem::AbstractItem(std::shared_ptr<AbstractAction> action)
114     : impl_(new Impl(this, action)) {
115 }
116
117 AbstractItem::AbstractItem(std::string id,
118     std::shared_ptr<AbstractAction> action)
119     : impl_(new Impl(this, id, action)) {
120 }
121
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)) {
126   if (id_.empty())
127     id_ = GenerateItemId();
128   sender_appid_ = util::GetAppId();
129   LOGI("AbstractItem created (%s)", id_.c_str());
130 }
131
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");
137
138   id_ = GenerateItemId();
139   sender_appid_ = util::GetAppId();
140   LOGI("AbstractItem created (%s)", id_.c_str());
141 }
142
143 AbstractItem::~AbstractItem() = default;
144 AbstractItem::Impl::~Impl() = default;
145
146 Bundle AbstractItem::Serialize() const {
147   Bundle b;
148   struct tm timeinfo;
149   char buf[80] = {0, };
150
151   if (impl_->uid_ == 0)
152     impl_->uid_ = getuid();
153
154   if (!impl_->channel_.empty())
155     b.Add(ABSTRACT_ITEM_CHANNEL_KEY, impl_->channel_);
156
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_);
166
167   localtime_r(&impl_->time_, &timeinfo);
168   strftime (buf, sizeof(buf), "%s", &timeinfo);
169   b.Add(ABSTRACT_ITEM_TIME_KEY, string(buf));
170
171   if (!impl_->can_receive_.empty())
172     b.Add(ABSTRACT_ITEM_CAN_RECEIVE_KEY, impl_->can_receive_);
173
174   if (!impl_->sound_path_.empty())
175     b.Add(ABSTRACT_ITEM_SOUND_PATH_KEY, impl_->sound_path_);
176
177   if (!impl_->vibration_path_.empty())
178     b.Add(ABSTRACT_ITEM_VIBRATION_PATH_KEY, impl_->vibration_path_);
179
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_));
185
186   if (impl_->receiver_group_list_.size() != 0) {
187     vector<string> arr;
188
189     for (auto& i : impl_->receiver_group_list_) {
190       string receiver = i;
191
192       arr.push_back(receiver);
193     }
194     b.Add(ABSTRACT_ITEM_RECEIVER_GROUP_KEY, arr);
195   }
196
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()));
206     }
207
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())));
218     }
219
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()));
228     }
229
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())));
240     }
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);
244   }
245
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);
258   }
259
260   if (impl_->action_ != nullptr) {
261     b.Add(ABSTRACT_ITEM_ACTION_KEY,
262       reinterpret_cast<char*>(impl_->action_->Serialize().ToRaw().first.get()));
263   }
264
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()));
268   }
269
270   if (impl_->multi_lang_arr_.size() > 0) {
271     vector<string> arr;
272     for (auto& i : impl_->multi_lang_arr_) {
273       arr.push_back(reinterpret_cast<char*>(i->Serialize().ToRaw().first.get()));
274     }
275     b.Add(ABSTRACT_ITEM_MULTI_LANG_ARR_KEY, arr);
276   }
277
278   if (impl_->hide_viewer_list_.size() != 0) {
279     vector<string> arr;
280
281     for (auto& i : impl_->hide_viewer_list_) {
282       string viewer = i;
283
284       arr.push_back(viewer);
285     }
286     b.Add(ABSTRACT_ITEM_HIDE_VIEWER_KEY, arr);
287   }
288
289   b.Add(ABSTRACT_ITEM_EXTENSION_DATA_KEY,
290     reinterpret_cast<char*>(impl_->extension_data_.ToRaw().first.get()));
291
292   return b;
293 }
294
295 void AbstractItem::Deserialize(Bundle b) {
296   string time_s;
297   struct tm timeinfo;
298
299   string type_str = b.GetString(ABSTRACT_ITEM_TYPE_KEY);
300   if (type_str.empty())
301     THROW(ERROR_IO_ERROR);
302
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);
315
316   time_s = b.GetString(ABSTRACT_ITEM_TIME_KEY);
317   strptime(time_s.c_str(), "%s", &timeinfo);
318   impl_->time_ = mktime(&timeinfo);
319
320   string policy_str = b.GetString(ABSTRACT_ITEM_POLICY_KEY);
321
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)));
327
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);
332     }
333   }
334
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)));
343     }
344
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))));
356     }
357
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)));
365     }
366
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))));
378     }
379
380     impl_->style_ = make_shared<Style>(color, padding, geometry, bg_color,
381         b.GetString(ABSTRACT_ITEM_STYLE_BG_IMAGE_PATH_KEY));
382   }
383
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))));
394
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)));
398   }
399
400   string action_str = b.GetString(ABSTRACT_ITEM_ACTION_KEY);
401   if (!action_str.empty())
402     impl_->action_ = ActionInflator::Create(Bundle(action_str));
403
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));
407
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)));
413     }
414   }
415
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);
420     }
421   }
422
423   impl_->extension_data_ = Bundle(b.GetString(ABSTRACT_ITEM_EXTENSION_DATA_KEY));
424 }
425
426 void AbstractItem::SetId(std::string id) {
427   impl_->id_ = id;
428 }
429
430 string AbstractItem::GetId() const {
431   return impl_->id_;
432 }
433
434 std::list<std::string> AbstractItem::GetSharedPath() const {
435   std::list<std::string> ret;
436
437   if (!impl_->priv_sound_path_.empty())
438     ret.push_back(impl_->priv_sound_path_);
439
440   if (!impl_->priv_vibration_path_.empty())
441     ret.push_back(impl_->priv_vibration_path_);
442
443   return ret;
444 }
445
446 void AbstractItem::SetSharedPath() {
447   if (!impl_->priv_sound_path_.empty())
448     impl_->sound_path_ = impl_->priv_sound_path_;
449
450   if (!impl_->priv_vibration_path_.empty())
451     impl_->vibration_path_ = impl_->priv_vibration_path_;
452 }
453
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;
457
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);
462   }
463
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);
468   }
469
470   return path_map_list;
471 }
472
473 shared_ptr<AbstractAction> AbstractItem::GetAction() const {
474   return impl_->action_;
475 }
476
477 void AbstractItem::SetAction(std::shared_ptr<AbstractAction> action) {
478   impl_->action_ = action;
479 }
480
481 shared_ptr<Style> AbstractItem::GetStyle() const {
482   return impl_->style_;
483 }
484
485 void AbstractItem::SetStyle(shared_ptr<Style> style) {
486   impl_->style_ = style;
487 }
488
489 void AbstractItem::SetLEDInfo(std::shared_ptr<LEDInfo> led) {
490   impl_->led_ = led;
491 }
492
493 std::shared_ptr<LEDInfo> AbstractItem::GetLEDInfo() const {
494   return impl_->led_;
495 }
496
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);
502 }
503
504 void AbstractItem::SetVisible(bool visible) {
505   impl_->visible_ = visible;
506 }
507
508 bool AbstractItem::GetVisible() const {
509   return impl_->visible_;
510 }
511
512 void AbstractItem::SetEnable(bool enable) {
513   impl_->enable_ = enable;
514 }
515
516 bool AbstractItem::GetEnable() const {
517   return impl_->enable_;
518 }
519
520 void AbstractItem::AddReceiver(std::string receiver_group) {
521   impl_->receiver_group_list_.push_back(receiver_group);
522 }
523
524 void AbstractItem::RemoveReceiver(std::string receiver_group) {
525   impl_->receiver_group_list_.remove(receiver_group);
526 }
527
528 list<string> AbstractItem::GetReceiverList() {
529   return impl_->receiver_group_list_;
530 }
531
532 void AbstractItem::SetPolicy(int policy) {
533   impl_->policy_ = policy;
534 }
535
536 int AbstractItem::GetPolicy() const {
537   return impl_->policy_;
538 }
539
540 std::shared_ptr<IItemInfo> AbstractItem::GetInfo() const {
541   return impl_->info_;
542 }
543
544 string AbstractItem::GetChannel() const {
545   return impl_->channel_;
546 }
547
548 void AbstractItem::SetChannel(string channel) {
549   impl_->channel_ = channel;
550 }
551
552 void AbstractItem::SetSoundPath(std::string path) {
553   impl_->sound_path_ = path;
554   UpdateSoundPrivatePath();
555 }
556
557 void AbstractItem::SetVibrationPath(std::string path) {
558   impl_->vibration_path_ = path;
559   UpdateVibrationPrivatePath();
560 }
561
562 std::string AbstractItem::GetSoundPath() const {
563   return impl_->sound_path_;
564 }
565
566 std::string AbstractItem::GetVibrationPath() const {
567   return impl_->vibration_path_;
568 }
569
570 std::string AbstractItem::GetSenderAppId() const {
571   return impl_->sender_appid_;
572 }
573
574 void AbstractItem::SetSenderAppId(std::string sender_appid) {
575   impl_->sender_appid_ = sender_appid;
576 }
577
578 std::string AbstractItem::GetTag() const {
579   return impl_->tag_;
580 }
581
582 void AbstractItem::SetTag(std::string tag) {
583   impl_->tag_ = tag;
584 }
585
586 void AbstractItem::SetOnGoingState(bool ongoing) {
587   impl_->ongoing_ = ongoing;
588 }
589
590 bool AbstractItem::GetOnGoingState() const {
591   return impl_->ongoing_;
592 }
593
594 bool AbstractItem::Impl::IsValidMainType(AbstractItem& target, MainType type) {
595   int item_type = target.GetType();
596
597   switch (type) {
598     case MainNone:
599       return true;
600     case MainTitle:
601     case MainContents:
602       if (item_type != Text)
603         return false;
604       break;
605     case MainIcon:
606       if (item_type != Image)
607         return false;
608       break;
609     case MainButton:
610       if (item_type != Button)
611         return false;
612       break;
613     default:
614       return false;
615   }
616
617   return true;
618 }
619
620 bool AbstractItem::SetMainType(std::string target_id, MainType type) {
621   AbstractItem& target = FindByID(target_id);
622   if (target.GetType() == NullObject)
623     return false;
624
625   if (type == MainNone) {
626     LOGW("Clear main type from %s", target_id.c_str());
627     target.impl_->main_type_ = MainNone;
628     return true;
629   }
630
631   if (!impl_->IsValidMainType(target, type)) {
632     LOGE("Main type and item type are not matched (%d, %d)",
633         type, target.GetType());
634     return false;
635   }
636
637   AbstractItem& old = FindByMainType(type);
638   if (target.GetType() != NullObject)
639     old.impl_->main_type_ = MainNone;
640   target.impl_->main_type_ = type;
641
642   return true;
643 }
644
645 AbstractItem::MainType AbstractItem::GetMainType() const {
646   return impl_->main_type_;
647 }
648
649 AbstractItem& AbstractItem::FindByID(std::string id) {
650   if (GetId() == id)
651     return *this;
652
653   return FactoryManager::GetInst().GetNullItem();
654 }
655
656 AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
657   if (impl_->main_type_ == type)
658     return *this;
659
660   return FactoryManager::GetInst().GetNullItem();
661 }
662
663 std::shared_ptr<MultiLanguage> AbstractItem::GetMultiLanguage() const {
664   return impl_->multi_lang_;
665 }
666
667 vector<shared_ptr<MultiLanguage>> AbstractItem::GetMultiLanguageArr() const {
668   return impl_->multi_lang_arr_;
669 }
670
671 void AbstractItem::SetMultiLanguage(std::shared_ptr<MultiLanguage> multi) {
672   impl_->multi_lang_ = multi;
673 }
674
675 void AbstractItem::SetMultiLanguage(
676     vector<shared_ptr<MultiLanguage>> multi_arr) {
677   impl_->multi_lang_arr_ = multi_arr;
678 }
679
680 void AbstractItem::UpdateSoundPrivatePath() {
681   SharedFile* shared_file = new SharedFile();
682   if (!shared_file->IsPrivatePath(impl_->sound_path_)) {
683     delete(shared_file);
684     return;
685   }
686
687   std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
688             impl_->sound_path_);
689   if (!path.empty())
690     impl_->priv_sound_path_ = path;
691
692   delete(shared_file);
693 }
694
695 void AbstractItem::UpdateVibrationPrivatePath() {
696   SharedFile* shared_file = new SharedFile();
697   if (!shared_file->IsPrivatePath(impl_->vibration_path_)) {
698     delete(shared_file);
699     return;
700   }
701
702   std::string path = shared_file->GetDataPath(AbstractItem::GetSenderAppId(),
703             impl_->vibration_path_);
704   if (!path.empty())
705     impl_->priv_vibration_path_ = path;
706
707   delete(shared_file);
708 }
709
710 tizen_base::Bundle AbstractItem::GetExtensionData(std::string key) {
711   if (impl_->extension_data_.GetString(key) == "")
712     return Bundle();
713   else
714     return Bundle(impl_->extension_data_.GetString(key));
715 }
716
717 void AbstractItem::SetExtensionData(std::string key, Bundle value) {
718   if (impl_->extension_data_.GetString(key) != "")
719     impl_->extension_data_.Delete(key);
720
721   impl_->extension_data_.Add(key,
722     reinterpret_cast<char*>(value.ToRaw().first.get()));
723 }
724
725 }  // namespace item
726 }  // namespace notification