Fix generating widget-application item 75/72575/3 accepted/tizen/common/20160610.175859 accepted/tizen/ivi/20160609.091412 accepted/tizen/mobile/20160609.091547 accepted/tizen/tv/20160609.091350 accepted/tizen/wearable/20160609.091326 submit/tizen/20160609.010102
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 1 Jun 2016 11:29:06 +0000 (13:29 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 7 Jun 2016 15:23:39 +0000 (17:23 +0200)
This commit is based on:
 - https://review.tizen.org/gerrit/71796

The way it is changed is:
 - widget information is gathered in manifest_x structure and
   backend data because data that is created by StepParse is
   inserted into database directly according to past changes
   (even we add widget information to generated manifest
   it is not read).
 - icon path is full path for widget-application (same as for
   ui-application) to handle icon backup, copying and pkgmgr
   expectations.
 - <size> is changed to <support-size> defined in manifest.xsd.in
   in pkgmgr-info repository.

Requires:
 - https://review.tizen.org/gerrit/71798
 - https://review.tizen.org/gerrit/72573

Change-Id: I2c980ae205f29fb70928aba58d8d3458d88a9c90

src/wgt/step/configuration/step_parse.cc
src/wgt/step/configuration/step_parse.h
src/wgt/step/filesystem/step_create_symbolic_link.cc
src/wgt/step/filesystem/step_create_symbolic_link.h
src/wgt/step/pkgmgr/step_generate_xml.cc
src/wgt/step/pkgmgr/step_generate_xml.h

index ad485ca..ee937d2 100644 (file)
@@ -84,6 +84,17 @@ void SetApplicationXDefaults(application_x* application) {
   application->ui_gadget = strdup("false");
 }
 
+template<typename T>
+void AppendLabel(T* root, const std::string& label,
+                 const std::string& locale) {
+  label_x* label_item = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+  label_item->name = strdup(label.c_str());
+  label_item->text = strdup(label.c_str());
+  label_item->lang = !locale.empty() ?
+      strdup(locale.c_str()) : strdup(DEFAULT_LOCALE);
+  root->label = g_list_append(root->label, label_item);
+}
+
 }  // namespace
 
 namespace wgt {
@@ -182,12 +193,7 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) {
   }
 
   for (auto& item : wgt_info->name_set()) {
-    label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
-    label->name = strdup(item.second.c_str());
-    label->text = strdup(item.second.c_str());
-    label->lang = !item.first.empty() ?
-        strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE);
-    manifest->label = g_list_append(manifest->label, label);
+    AppendLabel(manifest, item.second, item.first);
   }
 
   manifest->type = strdup("wgt");
@@ -199,12 +205,7 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) {
   for (auto& item : wgt_info->name_set()) {
     application_x* app =
         reinterpret_cast<application_x*>(manifest->application->data);
-    label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
-    label->name = strdup(item.second.c_str());
-    label->text = strdup(item.second.c_str());
-    label->lang = !item.first.empty() ?
-        strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE);
-    app->label = g_list_append(app->label, label);
+    AppendLabel(app, item.second, item.first);
   }
 
   author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
@@ -337,12 +338,7 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
     application->package = strdup(manifest->package);
 
     for (auto& pair : service_info.names()) {
-      label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
-      label->lang = !pair.first.empty() ?
-          strdup(pair.first.c_str()) : strdup(DEFAULT_LOCALE);
-      label->name = strdup(pair.second.c_str());
-      label->text = strdup(pair.second.c_str());
-      application->label = g_list_append(application->label, label);
+      AppendLabel(application, pair.second, pair.first);
     }
 
     if (!service_info.icon().empty()) {
@@ -373,6 +369,51 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
   return true;
 }
 
+bool StepParse::FillWidgetApplicationInfo(manifest_x* manifest) {
+  std::shared_ptr<const wgt::parse::AppWidgetInfo> appwidget_info =
+      std::static_pointer_cast<const wgt::parse::AppWidgetInfo>(
+          parser_->GetManifestData(
+              wgt::application_widget_keys::kTizenAppWidgetFullKey));
+  if (!appwidget_info)
+    return true;
+  for (auto& app_widget : appwidget_info->app_widgets()) {
+    application_x* application = reinterpret_cast<application_x*>
+        (calloc(1, sizeof(application_x)));
+    application->component_type = strdup("widgetapp");
+    application->mainapp = strdup("false");
+    application->multiple = strdup("false");
+    application->appid = strdup(app_widget.id.c_str());
+    application->exec =
+        strdup((context_->root_application_path.get() / manifest->package
+                / "bin" / application->appid).c_str());
+    application->type = strdup("webapp");
+    application->nodisplay = strdup("false");
+    application->taskmanage = strdup("false");
+    SetApplicationXDefaults(application);
+    application->ambient_support = strdup("false");
+    application->package = strdup(manifest->package);
+
+    if (!app_widget.label.default_value.empty()) {
+      AppendLabel(application, app_widget.label.default_value, std::string());
+    }
+
+    for (auto& pair : app_widget.label.lang_value_map) {
+      AppendLabel(application, pair.second, pair.first);
+    }
+
+    if (!app_widget.icon_src.empty()) {
+      icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+      icon->text = strdup(app_widget.icon_src.c_str());
+      icon->lang = strdup(DEFAULT_LOCALE);
+      application->icon = g_list_append(application->icon, icon);
+    }
+
+    manifest->application = g_list_append(manifest->application, application);
+  }
+  return true;
+}
+
+
 bool StepParse::FillBackgroundCategoryInfo(manifest_x* manifest) {
   auto manifest_data = parser_->GetManifestData(
       app_keys::kTizenBackgroundCategoryKey);
@@ -459,6 +500,7 @@ bool StepParse::FillMetadata(manifest_x* manifest) {
 }
 
 bool StepParse::FillAppWidget() {
+  // This is needed to store preview icons which are not saved into manifest_x
   WgtBackendData* backend_data =
       static_cast<WgtBackendData*>(context_->backend_data.get());
 
@@ -533,9 +575,11 @@ bool StepParse::FillManifestX(manifest_x* manifest) {
   // TODO(t.iwanek): fix adding ui application element
   // for now adding application service is added here because rest of code
   // assumes that there is one application at manifest->application
-  // so this must execute last
+  // so this must execute last. Don't move it above any item
   if (!FillServiceApplicationInfo(manifest))
     return false;
+  if (!FillWidgetApplicationInfo(manifest))
+    return false;
   if (!FillBackgroundCategoryInfo(manifest))
     return false;
   if (!FillExtraManifestInfo(manifest))
index eb7e7fa..e7b9357 100644 (file)
@@ -59,6 +59,7 @@ class StepParse : public common_installer::Step {
   bool FillWidgetInfo(manifest_x* manifest);
   bool FillMainApplicationInfo(manifest_x* manifest);
   bool FillServiceApplicationInfo(manifest_x* manifest);
+  bool FillWidgetApplicationInfo(manifest_x* manifest);
   bool FillAppControl(manifest_x* manifest);
   bool FillPrivileges(manifest_x* manifest);
   bool FillCategories(manifest_x* manifest);
index b23fcae..bc94fe2 100644 (file)
@@ -17,8 +17,6 @@
 #include <cstdio>
 #include <string>
 
-#include "wgt/wgt_backend_data.h"
-
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
 
@@ -49,6 +47,8 @@ bool StepCreateSymbolicLink::CreateSymlinksForApps() {
       bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error);
     } else if (strcmp(app->component_type, "watchapp") == 0) {
       bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error);
+    } else if (strcmp(app->component_type, "widgetapp") == 0) {
+      bf::create_symlink(kWidgetClientBinaryPath, exec_path, error);
     } else {
       bf::create_symlink(kWrtServiceBinaryPath, exec_path, error);
     }
@@ -61,31 +61,12 @@ bool StepCreateSymbolicLink::CreateSymlinksForApps() {
   return true;
 }
 
-bool StepCreateSymbolicLink::CreateSymlinksForAppWidgets() {
-  WgtBackendData* backend_data =
-      static_cast<WgtBackendData*>(context_->backend_data.get());
-  for (auto& appwidget : backend_data->appwidgets.get().app_widgets()) {
-    bf::path exec_path = context_->pkg_path.get() / "bin" / appwidget.id;
-    bs::error_code error;
-    bf::create_symlink(kWidgetClientBinaryPath, exec_path, error);
-    if (error) {
-      LOG(ERROR) << "Failed to create symlink for app widget: "
-                 << appwidget.id;
-      return false;
-    }
-  }
-  return true;
-}
-
 common_installer::Step::Status StepCreateSymbolicLink::process() {
   assert(context_->manifest_data.get());
 
   if (!CreateSymlinksForApps())
     return Status::APP_DIR_ERROR;
 
-  if (!CreateSymlinksForAppWidgets())
-    return Status::APP_DIR_ERROR;
-
   LOG(DEBUG) << "Symlinks created successfully";
   return Status::OK;
 }
index 43b3ddb..048c759 100644 (file)
@@ -54,7 +54,6 @@ class StepCreateSymbolicLink : public common_installer::Step {
 
  private:
   bool CreateSymlinksForApps();
-  bool CreateSymlinksForAppWidgets();
 
   STEP_NAME(SymbolicLink)
 };
index 724203d..1148642 100644 (file)
@@ -84,18 +84,54 @@ void WriteServiceApplicationAttributes(
          BAD_CAST app->taskmanage);
 }
 
-void WriteWidgetApplicationAttributes(
-    xmlTextWriterPtr writer, application_x *app) {
+bool WriteWidgetApplicationAttributesAndElements(
+    xmlTextWriterPtr writer, application_x *app,
+    const wgt::parse::AppWidgetInfo& widget_info,
+    const bf::path& shared_path) {
   if (app->nodisplay)
     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
         BAD_CAST app->nodisplay);
   if (app->multiple)
     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
         BAD_CAST app->multiple);
+
+  // Generate attributes and elements not covered in manifest.xsd
+  auto& appwidgets = widget_info.app_widgets();
+  const auto& appwidget = std::find_if(appwidgets.begin(), appwidgets.end(),
+                                 [app](const wgt::parse::AppWidget& widget) {
+                                    return widget.id == app->appid;
+                                 });
+  if (appwidget == appwidgets.end()) {
+    LOG(ERROR) << "Failed to generate appwidget extra elements";
+    return false;
+  }
+
+  xmlTextWriterWriteAttribute(writer, BAD_CAST "main",
+      BAD_CAST (appwidget->primary ? "true" : "false"));  // NOLINT
+  xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST "0");
+
+  for (auto& size : appwidget->content_size) {
+    xmlTextWriterStartElement(writer, BAD_CAST "support-size");
+
+    std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
+    if (!size.preview.empty()) {
+      std::string icon_name = shared_path.string() + "/" + appwidget->id + "." + type + "." + "preview" +
+          bf::path(size.preview).extension().string();
+      xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
+          BAD_CAST icon_name.c_str());  // NOLINT
+    }
+
+    xmlTextWriterWriteAttribute(writer, BAD_CAST "frame",
+                                BAD_CAST "true");
+    xmlTextWriterWriteString(writer,
+        BAD_CAST type.c_str());
+    xmlTextWriterEndElement(writer);
+  }
+  return true;
 }
 
 void WriteWatchApplicationAttributes(
-    xmlTextWriterPtr writer, application_x *app) {
+    xmlTextWriterPtr writer, application_xapp) {
   if (app->ambient_support)
     xmlTextWriterWriteAttribute(writer, BAD_CAST "ambient-support",
         BAD_CAST app->ambient_support);
@@ -132,7 +168,11 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml(
     WriteServiceApplicationAttributes(writer, app);
     break;
   case AppCompType::WIDGETAPP:
-    WriteWidgetApplicationAttributes(writer, app);
+    if (!WriteWidgetApplicationAttributesAndElements(writer, app,
+        static_cast<WgtBackendData*>(
+            context_->backend_data.get())->appwidgets.get(),
+        context_->pkg_path.get() / "shared" / "res"))
+      return Status::MANIFEST_ERROR;
     break;
   case AppCompType::WATCHAPP:
     WriteWatchApplicationAttributes(writer, app);
@@ -330,7 +370,6 @@ common_installer::Step::Status StepGenerateXml::GenerateManifestElement(
   GenerateIme(writer);
   GenerateProfiles(writer);
   GenerateShortcuts(writer);
-  GenerateWidget(writer);
 
   xmlTextWriterEndElement(writer);
   return Status::OK;
@@ -417,7 +456,11 @@ common_installer::Step::Status StepGenerateXml::GenerateApplications(
       xmlFreeTextWriter(writer);
       return Status::ERROR;
     }
-    GenerateApplicationCommonXml(app, writer, type);
+    Status status = GenerateApplicationCommonXml(app, writer, type);
+    if (status != Status::OK) {
+      xmlFreeTextWriter(writer);
+      return status;
+    }
     xmlTextWriterEndElement(writer);
   }
   return Status::OK;
@@ -567,78 +610,5 @@ void StepGenerateXml::GenerateShortcuts(xmlTextWriterPtr writer) {
   }
 }
 
-void StepGenerateXml::GenerateWidget(xmlTextWriterPtr writer) {
-  WgtBackendData* backend_data =
-      static_cast<WgtBackendData*>(context_->backend_data.get());
-  bf::path widget_content_path = context_->pkg_path.get() / kResWgt;
-  for (auto& appwidget : backend_data->appwidgets.get().app_widgets()) {
-    xmlTextWriterStartElement(writer, BAD_CAST "widget");
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
-                                BAD_CAST appwidget.id.c_str());
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "primary",
-        BAD_CAST (appwidget.primary ? "true" : "false"));  // NOLINT
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "abi",
-                                BAD_CAST "html");
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "network",
-                                BAD_CAST "true");
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
-                                BAD_CAST "false");
-
-    if (!appwidget.label.default_value.empty()) {
-      xmlTextWriterStartElement(writer, BAD_CAST "label");
-      xmlTextWriterWriteString(writer,
-                               BAD_CAST appwidget.label.default_value.c_str());
-      xmlTextWriterEndElement(writer);
-    }
-    for (auto& pair : appwidget.label.lang_value_map) {
-      xmlTextWriterStartElement(writer, BAD_CAST "label");
-      xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
-                                  BAD_CAST pair.first.c_str());
-      xmlTextWriterWriteString(writer, BAD_CAST pair.second.c_str());
-      xmlTextWriterEndElement(writer);
-    }
-
-    if (!appwidget.icon_src.empty()) {
-      xmlTextWriterStartElement(writer, BAD_CAST "icon");
-      xmlTextWriterWriteString(writer, BAD_CAST appwidget.icon_src.c_str());
-      xmlTextWriterEndElement(writer);
-    }
-
-    xmlTextWriterStartElement(writer, BAD_CAST "box");
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "buffer");
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "mouse_event",
-        BAD_CAST (appwidget.content_mouse_event ? "true" : "false"));  // NOLINT
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "touch_effect",
-        BAD_CAST (appwidget.content_touch_effect ? "true" : "false"));  // NOLINT
-    xmlTextWriterStartElement(writer, BAD_CAST "script");
-    bf::path src = widget_content_path / appwidget.content_src;
-    xmlTextWriterWriteAttribute(writer, BAD_CAST "src",
-        BAD_CAST src.c_str());
-    xmlTextWriterEndElement(writer);
-    for (auto& size : appwidget.content_size) {
-      xmlTextWriterStartElement(writer, BAD_CAST "size");
-
-      std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
-      if (!size.preview.empty()) {
-        std::string icon_name = appwidget.id + "." + type + "." + "preview" +
-            bf::path(size.preview).extension().string();
-        bf::path preview_icon =
-            context_->pkg_path.get() / kSharedRes / icon_name;
-        xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
-            BAD_CAST preview_icon.c_str());  // NOLINT
-      }
-
-      xmlTextWriterWriteAttribute(writer, BAD_CAST "need_frame",
-                                  BAD_CAST "true");
-      xmlTextWriterWriteString(writer,
-          BAD_CAST type.c_str());
-      xmlTextWriterEndElement(writer);
-    }
-    xmlTextWriterEndElement(writer);
-
-    xmlTextWriterEndElement(writer);
-  }
-}
-
 }  // namespace pkgmgr
 }  // namespace wgt
index f4be3a7..5dbb706 100644 (file)
@@ -48,7 +48,6 @@ class StepGenerateXml : public common_installer::Step {
   void GenerateIme(xmlTextWriterPtr writer);
   void GenerateProfiles(xmlTextWriterPtr writer);
   void GenerateShortcuts(xmlTextWriterPtr writer);
-  void GenerateWidget(xmlTextWriterPtr writer);
 
   STEP_NAME(GenerateXML)
 };