Handle 'mouse-event' attribute differently according to configuration of web-provider...
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_manifest_file.cpp
index 009b315..18ddf7e 100644 (file)
@@ -33,6 +33,8 @@
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
+#include <web_provider_livebox_info.h>
+#include <web_provider_plugin_info.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/log/log.h>
 #include <dpl/file_input.h>
@@ -133,10 +135,15 @@ void TaskManifestFile::stepCreateExecFile()
     std::string exec = m_context.locations->getExecFile();
     std::string clientExeStr = GlobalConfig::GetWrtClientExec();
 
+#ifdef MULTIPROCESS_SERVICE_SUPPORT
     //default widget
-    LogInfo("link -s " << clientExeStr << " " << exec);
+    std::stringstream postfix;
+    postfix << AppControlPrefix::PROCESS_PREFIX << 0;
+    std::string controlExec = exec;
+    controlExec.append(postfix.str());
+
     errno = 0;
-    if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
+    if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0)
     {
         int error = errno;
         if (error)
@@ -146,30 +153,44 @@ void TaskManifestFile::stepCreateExecFile()
                 "Symbolic link creating is not done.");
     }
 
-#ifdef MULTIPROCESS_SERVICE_SUPPORT
-    //services
-    std::size_t serviceCount =
-        m_context.widgetConfig.configInfo.appControlList.size();
-    serviceCount += m_context.widgetConfig.configInfo.appServiceList.size();
-    for (std::size_t i = 0; i < serviceCount; ++i) {
+    // app-control widgets
+    unsigned int indexMax = 0;
+    FOREACH(it, m_context.widgetConfig.configInfo.appControlList) {
+        if (it->m_index > indexMax) {
+            indexMax = it->m_index;
+        }
+    }
+
+    for (std::size_t i = 1; i <= indexMax; ++i) {
         std::stringstream postfix;
-        postfix << "-__SERVICE_PROCESS__" << i;
-        std::string serviceExec = exec;
-        serviceExec.append(postfix.str());
+        postfix << AppControlPrefix::PROCESS_PREFIX << i;
+        std::string controlExec = exec;
+        controlExec.append(postfix.str());
         errno = 0;
-        if (symlink(clientExeStr.c_str(), serviceExec.c_str()) != 0)
-        {
+        if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0) {
             int error = errno;
-            if (error)
+            if (error) {
                 LogPedantic("Failed to make a symbolic name for a file "
-                        << "[" <<  DPL::GetErrnoString(error) << "]");
+                    << "[" <<  DPL::GetErrnoString(error) << "]");
+            }
             ThrowMsg(Exceptions::FileOperationFailed,
-                    "Symbolic link creating is not done.");
+                     "Symbolic link creating is not done.");
         }
-
+    }
+#else
+    //default widget
+    LogInfo("link -s " << clientExeStr << " " << exec);
+    errno = 0;
+    if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
+    {
+        int error = errno;
+        if (error)
+            LogPedantic("Failed to make a symbolic name for a file "
+                    << "[" <<  DPL::GetErrnoString(error) << "]");
+        ThrowMsg(Exceptions::FileOperationFailed,
+                "Symbolic link creating is not done.");
     }
 #endif
-
     m_context.job->UpdateProgress(
             InstallerContext::INSTALL_CREATE_EXECFILE,
             "Widget execfile creation Finished");
@@ -399,33 +420,6 @@ void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
     file << "=";
 }
 
-void TaskManifestFile::updateAilInfo()
-{
-    // Update ail for desktop
-    std::string cfgAppid =
-        DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
-    const char* appid = cfgAppid.c_str();
-
-    LogDebug("Update ail desktop : " << appid);
-    ail_appinfo_h ai = NULL;
-    ail_error_e ret;
-
-    ret = ail_get_appinfo(appid, &ai);
-    if (ai) {
-        ail_destroy_appinfo(ai);
-    }
-
-    if (AIL_ERROR_NO_DATA == ret) {
-        if (ail_desktop_add(appid) < 0) {
-            LogWarning("Failed to add ail desktop : " << appid);
-        }
-    } else if (AIL_ERROR_OK == ret) {
-        if (ail_desktop_update(appid) < 0) {
-            LogWarning("Failed to update ail desktop : " << appid);
-        }
-    }
-}
-
 void TaskManifestFile::backupIconFiles()
 {
     LogInfo("Backup Icon Files");
@@ -542,10 +536,6 @@ void TaskManifestFile::stepParseManifest()
         ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
     }
 
-    // TODO : It will be removed. AIL update is temporary code request by pkgmgr
-    // team.
-    updateAilInfo();
-
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_CREATE_MANIFEST,
         "Widget Manifest Parsing Finished");
@@ -562,10 +552,6 @@ void TaskManifestFile::stepParseUpgradedManifest()
         ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
     }
 
-    // TODO : It will be removed. AIL update is temporary code request by pkgmgr
-    // team.
-    updateAilInfo();
-
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_CREATE_MANIFEST,
         "Widget Manifest Parsing Finished");
@@ -577,7 +563,13 @@ void TaskManifestFile::commitManifest()
     LogDebug("Commiting manifest file : " << manifest_file);
 
     std::ostringstream destFile;
-    destFile << "/opt/share/packages" << "/"; //TODO constant with path
+    if (m_context.job->getInstallerStruct().m_installMode
+            == InstallMode::INSTALL_MODE_PRELOAD)
+    {
+        destFile << "/usr/share/packages" << "/"; //TODO constant with path
+    } else {
+        destFile << "/opt/share/packages" << "/"; //TODO constant with path
+    }
     destFile << DPL::ToUTF8String(manifest_name);
     LogInfo("cp " << manifest_file << " " << destFile.str());
 
@@ -597,31 +589,28 @@ void TaskManifestFile::writeManifest(const DPL::String & path)
     Manifest manifest;
     UiApplication uiApp;
 
+#ifdef MULTIPROCESS_SERVICE_SUPPORT
     //default widget content
-    setWidgetExecPath(uiApp);
+    std::stringstream postfix;
+    // index 0 is reserved
+    postfix << AppControlPrefix::PROCESS_PREFIX << 0;
+    setWidgetExecPath(uiApp, postfix.str());
     setWidgetName(manifest, uiApp);
     setWidgetIds(manifest, uiApp);
     setWidgetIcons(uiApp);
+    setWidgetDescription(manifest);
     setWidgetManifest(manifest);
     setWidgetOtherInfo(uiApp);
-#ifndef MULTIPROCESS_SERVICE_SUPPORT
-    setAppServicesInfo(uiApp);
-    setAppControlsInfo(uiApp);
-#endif
     setAppCategory(uiApp);
     setLiveBoxInfo(manifest);
     setAccount(manifest);
     setPrivilege(manifest);
-
     manifest.addUiApplication(uiApp);
-#ifdef MULTIPROCESS_SERVICE_SUPPORT
-    //services AppControl tag
+
+    //app-control content
     ConfigParserData::AppControlInfoList appControlList =
         m_context.widgetConfig.configInfo.appControlList;
-    unsigned count = 0;
-
     FOREACH(it, appControlList) {
-        it->m_index = count;
         UiApplication uiApp;
 
         uiApp.setTaskmanage(true);
@@ -631,49 +620,32 @@ void TaskManifestFile::writeManifest(const DPL::String & path)
         uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
 #endif
         std::stringstream postfix;
-        postfix << "-__SERVICE_PROCESS__" << count++;
-
+        postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
         setWidgetExecPath(uiApp, postfix.str());
         setWidgetName(manifest, uiApp);
-        setWidgetIds(manifest, uiApp, postfix.str());
+        setWidgetIds(manifest, uiApp);
         setWidgetIcons(uiApp);
         setAppControlInfo(uiApp, *it);
         setAppCategory(uiApp);
-        setAccount(manifest);
-        setPrivilege(manifest);
-
         manifest.addUiApplication(uiApp);
     }
-    //TODO: AppService tag will be removed
-    //services AppService tag
-    WrtDB::ConfigParserData::ServiceInfoList appServiceList =
-        m_context.widgetConfig.configInfo.appServiceList;
-    FOREACH(it, appServiceList) {
-        it->m_index = count;
-        UiApplication uiApp;
+#else
+    //default widget content
+    setWidgetExecPath(uiApp);
+    setWidgetName(manifest, uiApp);
+    setWidgetIds(manifest, uiApp);
+    setWidgetIcons(uiApp);
+    setWidgetManifest(manifest);
+    setWidgetOtherInfo(uiApp);
+    setAppControlsInfo(uiApp);
+    setAppCategory(uiApp);
+    setLiveBoxInfo(manifest);
+    setAccount(manifest);
+    setPrivilege(manifest);
 
-        uiApp.setTaskmanage(true);
-        uiApp.setNodisplay(true);
-#ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
-        uiApp.setTaskmanage(ConfigParserData::ServiceInfo::Disposition::INLINE != it->m_disposition);
-        uiApp.setMultiple(ConfigParserData::ServiceInfo::Disposition::INLINE == it->m_disposition);
+    manifest.addUiApplication(uiApp);
 #endif
 
-        std::stringstream postfix;
-        postfix << "-__SERVICE_PROCESS__" << count++;
-
-        setWidgetExecPath(uiApp, postfix.str());
-        setWidgetName(manifest, uiApp);
-        setWidgetIds(manifest, uiApp, postfix.str());
-        setWidgetIcons(uiApp);
-        setAppServiceInfo(uiApp, *it);
-        setAppCategory(uiApp);
-        setAccount(manifest);
-        setPrivilege(manifest);
-
-        manifest.addUiApplication(uiApp);
-    }
-#endif
     manifest.generate(path);
     LogDebug("Manifest file serialized");
 }
@@ -848,6 +820,39 @@ void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
      m_context.job->SendProgressIconPath(iconPath.str());
 }
 
+void TaskManifestFile::setWidgetDescription(Manifest & manifest)
+{
+    FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
+    {
+        Locale i = localizedData->first;
+        DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
+        if (tag.IsNull()) {
+            tag = i;
+        }
+        DPL::OptionalString description = localizedData->second.description;
+        generateWidgetDescription(manifest, tag, description);
+    }
+}
+
+void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
+                                                 const DPL::OptionalString& tag,
+                                                  DPL::OptionalString description)
+{
+    if (!!description) {
+        if (!!tag) {
+            DPL::String locale =
+                LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
+            if (!locale.empty()) {
+                manifest.addDescription(DescriptionType(*description, locale));
+            } else {
+                manifest.addDescription(DescriptionType(*description));
+            }
+        } else {
+            manifest.addDescription(DescriptionType(*description));
+        }
+    }
+}
+
 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
 {
     manifest.setPackage(m_context.widgetConfig.tzPkgid);
@@ -886,22 +891,6 @@ void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
     //that were in desktop file
 }
 
-void TaskManifestFile::setAppServicesInfo(UiApplication & uiApp)
-{
-    WrtDB::ConfigParserData::ServiceInfoList appServiceList =
-        m_context.widgetConfig.configInfo.appServiceList;
-
-    if (appServiceList.empty()) {
-        LogInfo("Widget doesn't contain application service");
-        return;
-    }
-
-    // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
-    FOREACH(it, appServiceList) {
-        setAppServiceInfo(uiApp, *it);
-     }
- }
-
 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
 {
     WrtDB::ConfigParserData::AppControlInfoList appControlList =
@@ -918,22 +907,6 @@ void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
     }
 }
 
-void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp,
-                                         const ConfigParserData::ServiceInfo & service)
-{
-    AppControl appControl;
-    if (!service.m_operation.empty()) {
-        appControl.addOperation(service.m_operation); //TODO: encapsulation?
-    }
-    if (!service.m_scheme.empty()) {
-        appControl.addUri(service.m_scheme);
-    }
-    if (!service.m_mime.empty()) {
-        appControl.addMime(service.m_mime);
-    }
-    uiApp.addAppControl(appControl);
-}
-
 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
                                          const WrtDB::ConfigParserData::AppControlInfo & service)
 {
@@ -1053,13 +1026,28 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
             }
 
             if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
-                box.boxMouseEvent = ConfigInfo->m_boxInfo.m_boxMouseEvent;
+                std::string boxType;
+                if (ConfigInfo->m_type == L"") {
+                    // in case of default livebox
+                    boxType = web_provider_livebox_get_default_type();
+                } else {
+                    boxType = DPL::ToUTF8String(ConfigInfo->m_type);
+                }
+
+                int box_scrollable =
+                    web_provider_plugin_get_box_scrollable(boxType.c_str());
+
+                if (box_scrollable) {
+                    box.boxMouseEvent = L"true";
+                } else {
+                    box.boxMouseEvent = L"false";
+                }
             } else {
                 box.boxMouseEvent = L"false";
             }
 
             if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
-                box.boxTouchEffect = ConfigInfo->m_boxInfo.m_boxTouchEffect;
+                box.boxTouchEffect = L"true";
             } else {
                 box.boxTouchEffect= L"false";
             }