Release version 0.7.18
[platform/core/api/notification.git] / notification-ex / group_item.cc
index db2a7ec..75a55c7 100644 (file)
@@ -23,6 +23,7 @@
 #include "notification-ex/group_item.h"
 #include "notification-ex/group_item_implementation.h"
 #include "notification-ex/factory_manager.h"
+#include "notification-ex/ex_util.h"
 #include "notification-ex/exception.h"
 
 #ifdef LOG_TAG
@@ -38,6 +39,7 @@
 #define GROUP_APP_LABEL_KEY "__GROUP_APP_LABEL_KEY__"
 
 using namespace std;
+using namespace tizen_base;
 namespace notification {
 namespace item {
 
@@ -52,6 +54,14 @@ GroupItem::GroupItem(shared_ptr<AbstractAction> action)
 GroupItem::Impl::Impl(GroupItem* parent)
     : parent_(parent) {
   LOGI("GroupItem created");
+  char* name;
+  int ret = app_get_name(&name);
+  if (ret != APP_ERROR_NONE) {
+    app_label_ = util::GetAppId();
+  } else {
+    app_label_ = string(name);
+    free(name);
+  }
 }
 
 GroupItem::~GroupItem() {
@@ -66,9 +76,8 @@ Bundle GroupItem::Serialize() const {
   b = AbstractItem::Serialize();
   b.Add(GROUP_DIRECTION_KEY, impl_->is_vertical_ ?
       GROUP_DIRECTION_VERTICAL : GROUP_DIRECTION_HORIZONTAL);
-  if (!impl_->app_label_.empty())
-    b.Add(GROUP_APP_LABEL_KEY, impl_->app_label_);
 
+  b.Add(GROUP_APP_LABEL_KEY, impl_->app_label_);
   if (impl_->children_list_.size() == 0)
     return b;
 
@@ -76,7 +85,7 @@ Bundle GroupItem::Serialize() const {
   for (auto& i : impl_->children_list_) {
     Bundle serialized = i.get()->Serialize();
     serialized.Add(
-        GROUP_CHILDREN_TYPE_KEY, to_string((int)i.get()->GetType()));
+        GROUP_CHILDREN_TYPE_KEY, to_string(static_cast<int>(i.get()->GetType())));
     arr.push_back(reinterpret_cast<char*>(serialized.ToRaw().first.get()));
   }
   b.Add(GROUP_CHILDREN_KEY, arr);
@@ -107,13 +116,77 @@ void GroupItem::Deserialize(Bundle b) {
 }
 
 AbstractItem& GroupItem::FindByID(std::string id) {
+  if (GetId() == id)
+    return *this;
+
   for (auto& i : impl_->children_list_) {
-    if (i.get()->GetId() == id)
-      return *i;
+    auto& re = i.get()->FindByID(id);
+    if (re.GetId() == id)
+      return re;
   }
   return FactoryManager::GetInst().GetNullItem();
 }
 
+AbstractItem& GroupItem::FindByMainType(MainType type) {
+  if (GetMainType() == type)
+    return *this;
+
+  for (auto& i : impl_->children_list_) {
+    auto& re = i.get()->FindByMainType(type);
+    if (re.GetType() != NullObject)
+      return re;
+  }
+  return FactoryManager::GetInst().GetNullItem();
+}
+
+bool GroupItem::IsItemTypeExist(int type) {
+  if (GetType() == type)
+    return true;
+
+  for (auto& i : impl_->children_list_) {
+    if (i.get()->IsItemTypeExist(type))
+      return true;
+  }
+  return false;
+}
+
+list<string> GroupItem::GetSharedPath() const {
+  list<string> ret;
+
+  auto r = AbstractItem::GetSharedPath();
+  for (auto& shared_path_r : r)
+    ret.push_back(move(shared_path_r));
+
+  for (auto& i : impl_->children_list_) {
+    auto c = i->GetSharedPath();
+    for (auto& shared_path_c : c)
+      ret.push_back(move(shared_path_c));
+  }
+
+  return ret;
+}
+
+void GroupItem::SetSharedPath() {
+  for (auto& i : impl_->children_list_)
+    i->SetSharedPath();
+}
+
+list<map<string, string>> GroupItem::GetPathMapList() const {
+  list<map<string, string>> path_map_list;
+
+  auto r = AbstractItem::GetPathMapList();
+  for (auto& path_map_r : r)
+    path_map_list.push_back(move(path_map_r));
+
+  for (auto& i : impl_->children_list_) {
+    auto c = i->GetPathMapList();
+    for (auto& path_map_c : c)
+      path_map_list.push_back(move(path_map_c));
+  }
+
+  return path_map_list;
+}
+
 void GroupItem::AddChild(shared_ptr<AbstractItem> child) {
   impl_->children_list_.emplace_back(child);
 }
@@ -127,6 +200,10 @@ void GroupItem::RemoveChild(string itemId) {
   }
 }
 
+void GroupItem::RemoveChildren() {
+  impl_->children_list_.clear();
+}
+
 list<shared_ptr<AbstractItem>> GroupItem::GetChildren() {
   return impl_->children_list_;
 }
@@ -140,14 +217,11 @@ bool GroupItem::IsVertical() {
 }
 
 string GroupItem::GetAppLabel() {
- if (impl_->app_label_.empty()) {
-   char* name;
-   int ret = app_get_name(&name);
-   if (ret != APP_ERROR_NONE)
-     THROW(NOTIFICATION_ERROR_IO_ERROR);
-   impl_->app_label_ = string(name);
- }
- return impl_->app_label_;
+  return impl_->app_label_;
+}
+
+void GroupItem::SetAppLabel(string label) {
+  impl_->app_label_ = label;
 }
 
 }  // namespace item