X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fjobs%2Fwidget_install%2Ftask_manifest_file.cpp;h=33b1283dc05998e95697867bf8847180b4ca2c1b;hb=7fb83d1e97cd557be2a3b16edd5dc651a2d27306;hp=b34b13ccb2a344e2f0223e6050a02d68970cb11e;hpb=ded645291b7e133bde628ab9efc7cdaee35cd3c2;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp old mode 100755 new mode 100644 index b34b13c..33b1283 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -21,6 +21,7 @@ */ //SYSTEM INCLUDES +#include #include #include #include @@ -32,6 +33,8 @@ #include #include #include +#include +#include #include #include #include @@ -63,7 +66,7 @@ LanguageTagMap getLanguageTagMap() { LanguageTagMap map; -#define ADD(tag, l_tag) map.insert(std::make_pair(L ## # tag, L ## # l_tag)); +#define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag)); #include "languages.def" #undef ADD @@ -97,48 +100,101 @@ DPL::OptionalString getLangTag(const DPL::String& tag) namespace Jobs { namespace WidgetInstall { - const char * TaskManifestFile::encoding = "UTF-8"; TaskManifestFile::TaskManifestFile(InstallerContext &inCont) : DPL::TaskDecl(this), - m_context(inCont) + m_context(inCont), + writer(NULL) { - if (false == m_context.existingWidgetInfo.isExist) { + if (m_context.isUpdateMode) { + // for widget update. + AddStep(&TaskManifestFile::stepBackupIconFiles); AddStep(&TaskManifestFile::stepCopyIconFiles); AddStep(&TaskManifestFile::stepCreateExecFile); AddStep(&TaskManifestFile::stepGenerateManifest); - AddStep(&TaskManifestFile::stepParseManifest); - AddStep(&TaskManifestFile::stepFinalize); + AddStep(&TaskManifestFile::stepParseUpgradedManifest); + AddStep(&TaskManifestFile::stepUpdateFinalize); - AddAbortStep(&TaskManifestFile::stepAbortParseManifest); + AddAbortStep(&TaskManifestFile::stepAbortIconFiles); } else { - // for widget update. - AddStep(&TaskManifestFile::stepBackupIconFiles); AddStep(&TaskManifestFile::stepCopyIconFiles); + AddStep(&TaskManifestFile::stepCreateExecFile); AddStep(&TaskManifestFile::stepGenerateManifest); - AddStep(&TaskManifestFile::stepParseUpgradedManifest); - AddStep(&TaskManifestFile::stepUpdateFinalize); + AddStep(&TaskManifestFile::stepParseManifest); + AddStep(&TaskManifestFile::stepFinalize); - AddAbortStep(&TaskManifestFile::stepAbortIconFiles); + AddAbortStep(&TaskManifestFile::stepAbortParseManifest); } } TaskManifestFile::~TaskManifestFile() -{ -} +{} void TaskManifestFile::stepCreateExecFile() { std::string exec = m_context.locations->getExecFile(); std::string clientExeStr = GlobalConfig::GetWrtClientExec(); - LogInfo("link -s " << clientExeStr << " " << exec); - symlink(clientExeStr.c_str(), exec.c_str()); +#ifdef MULTIPROCESS_SERVICE_SUPPORT + //default widget + std::stringstream postfix; + postfix << AppControlPrefix::PROCESS_PREFIX << 0; + std::string controlExec = exec; + controlExec.append(postfix.str()); + errno = 0; + if (symlink(clientExeStr.c_str(), controlExec.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."); + } + + // 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 << AppControlPrefix::PROCESS_PREFIX << i; + std::string controlExec = exec; + controlExec.append(postfix.str()); + errno = 0; + if (symlink(clientExeStr.c_str(), controlExec.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."); + } + } +#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"); + InstallerContext::INSTALL_CREATE_EXECFILE, + "Widget execfile creation Finished"); } void TaskManifestFile::stepCopyIconFiles() @@ -149,27 +205,32 @@ void TaskManifestFile::stepCopyIconFiles() //which there is at least one icon in widget for, icon file is copied. //Coping prioritize last positions when coping. If there is several icons //with given locale, the one, that will be copied, will be icon - //which is declared by tag later than the others in config.xml of widget + //which is declared by tag later than the others in config.xml of + // widget std::vector generatedLocales; - WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = m_context.widgetConfig.localizationData.icons; + WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = + m_context.widgetConfig.localizationData.icons; - //reversed: last has highest priority to be copied if it has given locale (TODO: why was that working that way?) - for(WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator icon = icons.rbegin(); icon != icons.rend(); icon++) + //reversed: last has highest priority to be copied if it has given + // locale (TODO: why was that working that way?) + for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator + icon = icons.rbegin(); + icon != icons.rend(); + ++icon) { FOREACH(locale, icon->availableLocales) { DPL::String src = icon->src; LogDebug("Icon for locale: " << *locale << "is : " << src); - if(std::find(generatedLocales.begin(), generatedLocales.end(), *locale) != generatedLocales.end()) + if (std::find(generatedLocales.begin(), generatedLocales.end(), + *locale) != generatedLocales.end()) { LogDebug("Skipping - has that locale"); continue; - } - else - { + } else { generatedLocales.push_back(*locale); } @@ -187,10 +248,11 @@ void TaskManifestFile::stepCopyIconFiles() targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/"; targetFile << getIconTargetFilename(*locale); - if (m_context.widgetConfig.packagingType == - WrtDB::PKG_TYPE_HOSTED_WEB_APP) { - m_context.locations->setIconTargetFilenameForLocale(targetFile.str()); + WrtDB::PKG_TYPE_HOSTED_WEB_APP) + { + m_context.locations->setIconTargetFilenameForLocale( + targetFile.str()); } LogDebug("Copying icon: " << sourceFile.str() << @@ -208,27 +270,30 @@ void TaskManifestFile::stepCopyIconFiles() Catch(DPL::FileInput::Exception::Base) { // Error while opening or closing source file - //ReThrowMsg(InstallerException::CopyIconFailed, sourceFile.str()); + //ReThrowMsg(InstallerException::CopyIconFailed, + // sourceFile.str()); LogError( - "Copying widget's icon failed. Widget's icon will not be"\ + "Copying widget's icon failed. Widget's icon will not be" \ "available from Main Screen"); } Catch(DPL::FileOutput::Exception::Base) { // Error while opening or closing target file - //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str()); + //ReThrowMsg(InstallerException::CopyIconFailed, + // targetFile.str()); LogError( - "Copying widget's icon failed. Widget's icon will not be"\ + "Copying widget's icon failed. Widget's icon will not be" \ "available from Main Screen"); } Catch(DPL::CopyFailed) { // Error while copying - //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str()); + //ReThrowMsg(InstallerException::CopyIconFailed, + // targetFile.str()); LogError( - "Copying widget's icon failed. Widget's icon will not be"\ + "Copying widget's icon failed. Widget's icon will not be" \ "available from Main Screen"); } } @@ -243,8 +308,7 @@ void TaskManifestFile::stepBackupIconFiles() { LogDebug("Backup Icon Files"); - backup_dir << m_context.locations->getPackageInstallationDir(); - backup_dir << "/" << "backup" << "/"; + backup_dir << m_context.locations->getBackupDir() << "/"; backupIconFiles(); @@ -286,18 +350,18 @@ void TaskManifestFile::stepAbortIconFiles() Catch(DPL::FileInput::Exception::Base) { LogError("Restoration icon File Failed." << backup_file.str() - << " to " << res_file.str()); + << " to " << res_file.str()); } Catch(DPL::FileOutput::Exception::Base) { LogError("Restoration icon File Failed." << backup_file.str() - << " to " << res_file.str()); + << " to " << res_file.str()); } Catch(DPL::CopyFailed) { LogError("Restoration icon File Failed." << backup_file.str() - << " to " << res_file.str()); + << " to " << res_file.str()); } } } @@ -309,20 +373,23 @@ void TaskManifestFile::stepUpdateFinalize() } DPL::String TaskManifestFile::getIconTargetFilename( - const DPL::String& languageTag) const + const DPL::String& languageTag) const { DPL::OStringStream filename; - WidgetPkgName pkgname = m_context.widgetConfig.pkgName; + TizenAppId appid = m_context.widgetConfig.tzAppid; - filename << DPL::ToUTF8String(pkgname).c_str(); + filename << DPL::ToUTF8String(appid).c_str(); if (!languageTag.empty()) { - DPL::OptionalString tag = getLangTag(languageTag); // translate en -> en_US etc - if (tag.IsNull()) { tag = languageTag; } + DPL::OptionalString tag = getLangTag(languageTag); // translate en -> + // en_US etc + if (tag.IsNull()) { + tag = languageTag; + } DPL::String locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag); - if(locale.empty()) { + if (locale.empty()) { filename << L"." << languageTag; } else { filename << L"." << locale; @@ -339,13 +406,12 @@ void TaskManifestFile::stepFinalize() LogInfo("Finished ManifestFile step"); } - void TaskManifestFile::saveLocalizedKey(std::ofstream &file, - const DPL::String& key, - const DPL::String& languageTag) + const DPL::String& key, + const DPL::String& languageTag) { DPL::String locale = - LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag); + LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag); file << key; if (!locale.empty()) { @@ -354,33 +420,6 @@ void TaskManifestFile::saveLocalizedKey(std::ofstream &file, file << "="; } -void TaskManifestFile::updateAilInfo() -{ - // Update ail for desktop - std::string cfgPkgname = - DPL::ToUTF8String(m_context.widgetConfig.pkgName); - const char* pkgname = cfgPkgname.c_str(); - - LogDebug("Update ail desktop : " << pkgname ); - ail_appinfo_h ai = NULL; - ail_error_e ret; - - ret = ail_package_get_appinfo(pkgname, &ai); - if (ai) { - ail_package_destroy_appinfo(ai); - } - - if (AIL_ERROR_NO_DATA == ret) { - if (ail_desktop_add(pkgname) < 0) { - LogWarning("Failed to add ail desktop : " << pkgname); - } - } else if (AIL_ERROR_OK == ret) { - if (ail_desktop_update(pkgname) < 0) { - LogWarning("Failed to update ail desktop : " << pkgname); - } - } -} - void TaskManifestFile::backupIconFiles() { LogInfo("Backup Icon Files"); @@ -393,12 +432,13 @@ void TaskManifestFile::backupIconFiles() std::list fileList; getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList); - std::string pkgname = DPL::ToUTF8String(m_context.widgetConfig.pkgName); + std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid); FOREACH(it, fileList) { - if (0 == (strncmp((*it).c_str(), pkgname.c_str(), - strlen(pkgname.c_str())))) { + if (0 == (strncmp((*it).c_str(), appid.c_str(), + strlen(appid.c_str())))) + { std::ostringstream icon_file, backup_icon; icon_file << GlobalConfig::GetUserWidgetDesktopIconPath(); icon_file << "/" << (*it); @@ -406,7 +446,7 @@ void TaskManifestFile::backupIconFiles() backup_icon << b_icon_dir.str() << "/" << (*it); LogDebug("Backup icon file " << icon_file.str() << " to " << - backup_icon.str()); + backup_icon.str()); Try { DPL::FileInput input(icon_file.str()); @@ -435,35 +475,45 @@ void TaskManifestFile::backupIconFiles() } void TaskManifestFile::getFileList(const char* path, - std::list &list) + std::list &list) { DIR* dir = opendir(path); if (!dir) { LogError("icon directory doesn't exist"); - ThrowMsg(Exceptions::InternalError, path); + ThrowMsg(Exceptions::FileOperationFailed, path); } - struct dirent* d_ent; - do { - if ((d_ent = readdir(dir))) { - if(strcmp(d_ent->d_name, ".") == 0 || - strcmp(d_ent->d_name, "..") == 0) { - continue; - } - std::string file_name = d_ent->d_name; - list.push_back(file_name); + struct dirent entry; + struct dirent *result; + int return_code; + errno = 0; + for (return_code = readdir_r(dir, &entry, &result); + result != NULL && return_code == 0; + return_code = readdir_r(dir, &entry, &result)) + { + if (strcmp(entry.d_name, ".") == 0 || + strcmp(entry.d_name, "..") == 0) + { + continue; } - }while(d_ent); + std::string file_name = entry.d_name; + list.push_back(file_name); + } + + if (return_code != 0 || errno != 0) { + LogError("readdir_r() failed with " << DPL::GetErrnoString()); + } + if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { LogError("Failed to close dir: " << path << " with error: " - << DPL::GetErrnoString()); + << DPL::GetErrnoString()); } } void TaskManifestFile::stepGenerateManifest() { - WidgetPkgName pkgname = m_context.widgetConfig.pkgName; - manifest_name = pkgname + L".xml"; + TizenPkgId pkgid = m_context.widgetConfig.tzPkgid; + manifest_name = pkgid + L".xml"; manifest_file += L"/tmp/" + manifest_name; //libxml - init and check @@ -481,15 +531,11 @@ void TaskManifestFile::stepParseManifest() int code = pkgmgr_parser_parse_manifest_for_installation( DPL::ToUTF8String(manifest_file).c_str(), NULL); - if(code != 0) - { + if (code != 0) { LogError("Manifest parser error: " << code); - ThrowMsg(ManifestParsingError, "Parser returncode: " << code); + 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"); @@ -498,22 +544,22 @@ void TaskManifestFile::stepParseManifest() void TaskManifestFile::stepParseUpgradedManifest() { - int code = pkgmgr_parser_parse_manifest_for_upgrade( - DPL::ToUTF8String(manifest_file).c_str(), NULL); - - if(code != 0) + if (m_context.widgetConfig.packagingType != + PKG_TYPE_HYBRID_WEB_APP) { - LogError("Manifest parser error: " << code); - ThrowMsg(ManifestParsingError, "Parser returncode: " << code); - } + int code = pkgmgr_parser_parse_manifest_for_upgrade( + DPL::ToUTF8String(manifest_file).c_str(), NULL); - // TODO : It will be removed. AIL update is temporary code request by pkgmgr team. - updateAilInfo(); + if (code != 0) { + LogError("Manifest parser error: " << code); + ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code); + } - m_context.job->UpdateProgress( - InstallerContext::INSTALL_CREATE_MANIFEST, - "Widget Manifest Parsing Finished"); - LogDebug("Manifest parsed"); + m_context.job->UpdateProgress( + InstallerContext::INSTALL_CREATE_MANIFEST, + "Widget Manifest Parsing Finished"); + LogDebug("Manifest parsed"); + } } void TaskManifestFile::commitManifest() @@ -521,7 +567,11 @@ void TaskManifestFile::commitManifest() LogDebug("Commiting manifest file : " << manifest_file); std::ostringstream destFile; - destFile << "/opt/share/packages" << "/"; //TODO constant with path + if (m_context.mode.rootPath == InstallMode::RootPath::RO) { + 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()); @@ -541,67 +591,135 @@ void TaskManifestFile::writeManifest(const DPL::String & path) Manifest manifest; UiApplication uiApp; +#ifdef MULTIPROCESS_SERVICE_SUPPORT + //default widget content + 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); + setAppCategory(uiApp); + setMetadata(uiApp); + setLiveBoxInfo(manifest); + setAccount(manifest); + setPrivilege(manifest); + manifest.addUiApplication(uiApp); + + //app-control content + ConfigParserData::AppControlInfoList appControlList = + m_context.widgetConfig.configInfo.appControlList; + FOREACH(it, appControlList) { + UiApplication uiApp; + + uiApp.setTaskmanage(true); + uiApp.setNodisplay(true); +#ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE + uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition); + uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition); +#endif + std::stringstream postfix; + postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index; + setWidgetExecPath(uiApp, postfix.str()); + setWidgetName(manifest, uiApp); + setWidgetIds(manifest, uiApp); + setWidgetIcons(uiApp); + setAppControlInfo(uiApp, *it); + setAppCategory(uiApp); + setMetadata(uiApp); + manifest.addUiApplication(uiApp); + } +#else + //default widget content setWidgetExecPath(uiApp); setWidgetName(manifest, uiApp); + setWidgetIds(manifest, uiApp); setWidgetIcons(uiApp); + setWidgetDescription(manifest); setWidgetManifest(manifest); setWidgetOtherInfo(uiApp); - setAppServiceInfo(uiApp); - setAppControlInfo(uiApp); + setAppControlsInfo(uiApp); setAppCategory(uiApp); + setMetadata(uiApp); setLiveBoxInfo(manifest); + setAccount(manifest); + setPrivilege(manifest); manifest.addUiApplication(uiApp); +#endif + manifest.generate(path); LogDebug("Manifest file serialized"); } -void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp) +void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp, + const std::string &postfix) { - uiApp.setExec(DPL::FromASCIIString(m_context.locations->getExecFile())); + std::string exec = m_context.locations->getExecFile(); + if (!postfix.empty()) { + exec.append(postfix); + } + LogDebug("exec = " << exec); + uiApp.setExec(DPL::FromASCIIString(exec)); } -void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp) +void TaskManifestFile::setWidgetName(Manifest & manifest, + UiApplication & uiApp) { bool defaultNameSaved = false; - DPL::OptionalString defaultLocale = m_context.widgetConfig.configInfo.defaultlocale; - std::pair defaultLocalizedData; + DPL::OptionalString defaultLocale = + m_context.widgetConfig.configInfo.defaultlocale; + std::pair defaultLocalizedData; //labels FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet) { Locale i = localizedData->first; DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc - if (tag.IsNull()) - { + if (tag.IsNull()) { tag = i; } DPL::OptionalString name = localizedData->second.name; generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved); //store default locale localized data - if(!!defaultLocale && defaultLocale == i) - { + if (!!defaultLocale && defaultLocale == i) { defaultLocalizedData = *localizedData; } } - if (!!defaultLocale && !defaultNameSaved) - { + if (!!defaultLocale && !defaultNameSaved) { DPL::OptionalString name = defaultLocalizedData.second.name; - generateWidgetName(manifest, uiApp, DPL::OptionalString::Null, name, defaultNameSaved); + generateWidgetName(manifest, + uiApp, + DPL::OptionalString::Null, + name, + defaultNameSaved); } - //appid - WidgetPkgName pkgname = m_context.widgetConfig.pkgName; - uiApp.setAppid(pkgname); +} +void TaskManifestFile::setWidgetIds(Manifest & manifest, + UiApplication & uiApp, + const std::string &postfix) +{ + //appid + TizenAppId appid = m_context.widgetConfig.tzAppid; + if (!postfix.empty()) { + appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix)); + } + uiApp.setAppid(appid); //extraid - if(!!m_context.widgetConfig.guid) { + if (!!m_context.widgetConfig.guid) { uiApp.setExtraid(*m_context.widgetConfig.guid); } else { - if(!pkgname.empty()) { - uiApp.setExtraid(DPL::String(L"http://") + pkgname); + if (!appid.empty()) { + uiApp.setExtraid(DPL::String(L"http://") + appid); } } @@ -610,25 +728,24 @@ void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp) manifest.setType(L"wgt"); } -void TaskManifestFile::generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved) +void TaskManifestFile::generateWidgetName(Manifest & manifest, + UiApplication &uiApp, + const DPL::OptionalString& tag, + DPL::OptionalString name, + bool & defaultNameSaved) { if (!!name) { - if (!!tag) - { + if (!!tag) { DPL::String locale = - LanguageTagsProvider::BCP47LanguageTagToLocale(*tag); + LanguageTagsProvider::BCP47LanguageTagToLocale(*tag); if (!locale.empty()) { - uiApp.addLabel(LabelType(*name,*tag)); - } - else - { + uiApp.addLabel(LabelType(*name, *tag)); + } else { uiApp.addLabel(LabelType(*name)); manifest.addLabel(LabelType(*name)); } - } - else - { + } else { defaultNameSaved = true; uiApp.addLabel(LabelType(*name)); manifest.addLabel(LabelType(*name)); @@ -642,131 +759,145 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp) //changes. bool defaultIconSaved = false; - DPL::OptionalString defaultLocale = m_context.widgetConfig.configInfo.defaultlocale; + DPL::OptionalString defaultLocale = + m_context.widgetConfig.configInfo.defaultlocale; std::vector generatedLocales; - WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = m_context.widgetConfig.localizationData.icons; - - //reversed: last has highest priority to be writen to manifest if it has given locale (TODO: why was that working that way?) - for(WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator icon = icons.rbegin(); icon != icons.rend(); icon++) + WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = + m_context.widgetConfig.localizationData.icons; + + //reversed: last has highest priority to be writen to manifest if it + // has given locale (TODO: why was that working that way?) + for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator + icon = icons.rbegin(); + icon != icons.rend(); + ++icon) { FOREACH(locale, icon->availableLocales) { - if(std::find(generatedLocales.begin(), generatedLocales.end(), *locale) != generatedLocales.end()) + if (std::find(generatedLocales.begin(), generatedLocales.end(), + *locale) != generatedLocales.end()) { LogDebug("Skipping - has that locale - already in manifest"); continue; - } - else - { + } else { generatedLocales.push_back(*locale); } - DPL::OptionalString tag = getLangTag(*locale); // translate en -> en_US etc - if (tag.IsNull()) { tag = *locale; } + DPL::OptionalString tag = getLangTag(*locale); // translate en -> + // en_US etc + if (tag.IsNull()) { + tag = *locale; + } generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved); } } - if (!!defaultLocale && !defaultIconSaved) - { + if (!!defaultLocale && !defaultIconSaved) { generateWidgetIcon(uiApp, DPL::OptionalString::Null, DPL::String(), defaultIconSaved); } } -void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, - const DPL::String& language, bool & defaultIconSaved) +void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, + const DPL::OptionalString& tag, + const DPL::String& language, + bool & defaultIconSaved) { DPL::String locale; - if (!!tag) - { + if (!!tag) { locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag); - } - else - { + } else { defaultIconSaved = true; } DPL::String iconText; iconText += getIconTargetFilename(language); - if(!locale.empty()) - { + if (!locale.empty()) { uiApp.addIcon(IconType(iconText, locale)); + } else { + uiApp.addIcon(IconType(iconText)); } - else + std::ostringstream iconPath; + iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/"; + iconPath << getIconTargetFilename(locale); + m_context.job->SendProgressIconPath(iconPath.str()); +} + +void TaskManifestFile::setWidgetDescription(Manifest & manifest) +{ + FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet) { - uiApp.addIcon(IconType(iconText)); + 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.pkgName); + manifest.setPackage(m_context.widgetConfig.tzPkgid); - if(!!m_context.widgetConfig.version) - { + if (!!m_context.widgetConfig.version) { manifest.setVersion(*m_context.widgetConfig.version); } DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ? - *m_context.widgetConfig.configInfo.authorEmail : L""); + *m_context.widgetConfig.configInfo.authorEmail : L""); DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ? - *m_context.widgetConfig.configInfo.authorHref : L""); + *m_context.widgetConfig.configInfo.authorHref : L""); DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ? - *m_context.widgetConfig.configInfo.authorName : L""); - manifest.addAuthor(Author(email,href,L"",name)); + *m_context.widgetConfig.configInfo.authorName : L""); + manifest.addAuthor(Author(email, href, L"", name)); } void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp) { FOREACH(it, m_context.widgetConfig.configInfo.settingsList) { - if(!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) { - if(!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) { + if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) { + if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) { uiApp.setNodisplay(true); uiApp.setTaskmanage(false); - } - else { + } else { uiApp.setNodisplay(false); uiApp.setTaskmanage(true); } - } - } + } + } //TODO //There is no "X-TIZEN-PackageType=wgt" - //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str() + //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << + // DPL::ToUTF8String(*widgetID).c_str() //There is no Comment in pkgmgr "Comment=Widget application" //that were in desktop file } -void TaskManifestFile::setAppServiceInfo(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) { - AppControl appControl; - if (!it->m_operation.empty()) { - appControl.addOperation(it->m_operation); //TODO: encapsulation? - } - if (!it->m_scheme.empty()) { - appControl.addUri(it->m_scheme); - } - if (!it->m_mime.empty()) { - appControl.addMime(it->m_mime); - } - uiApp.addAppControl(appControl); - } -} - -void TaskManifestFile::setAppControlInfo(UiApplication & uiApp) +void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp) { WrtDB::ConfigParserData::AppControlInfoList appControlList = m_context.widgetConfig.configInfo.appControlList; @@ -776,24 +907,31 @@ void TaskManifestFile::setAppControlInfo(UiApplication & uiApp) return; } - // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image; + // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image; FOREACH(it, appControlList) { - AppControl appControl; - if (!it->m_operation.empty()) { - appControl.addOperation(it->m_operation); //TODO: encapsulation? - } - if (!it->m_uriList.empty()) { - FOREACH(uri, it->m_uriList) { - appControl.addUri(*uri); - } + setAppControlInfo(uiApp, *it); + } +} + +void TaskManifestFile::setAppControlInfo(UiApplication & uiApp, + const WrtDB::ConfigParserData::AppControlInfo & service) +{ + // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image; + AppControl appControl; + if (!service.m_operation.empty()) { + appControl.addOperation(service.m_operation); //TODO: encapsulation? + } + if (!service.m_uriList.empty()) { + FOREACH(uri, service.m_uriList) { + appControl.addUri(*uri); } - if (!it->m_mimeList.empty()) { - FOREACH(mime, it->m_mimeList) { - appControl.addMime(*mime); - } + } + if (!service.m_mimeList.empty()) { + FOREACH(mime, service.m_mimeList) { + appControl.addMime(*mime); } - uiApp.addAppControl(appControl); } + uiApp.addAppControl(appControl); } void TaskManifestFile::setAppCategory(UiApplication &uiApp) @@ -812,6 +950,21 @@ void TaskManifestFile::setAppCategory(UiApplication &uiApp) } } +void TaskManifestFile::setMetadata(UiApplication &uiApp) +{ + WrtDB::ConfigParserData::MetadataList metadataList = + m_context.widgetConfig.configInfo.metadataList; + + if (metadataList.empty()) { + LogInfo("Web application doesn't contain metadata"); + return; + } + FOREACH(it, metadataList) { + MetadataType metadataType(it->key, it->value); + uiApp.addMetadata(metadataType); + } +} + void TaskManifestFile::stepAbortParseManifest() { LogError("[Parse Manifest] Abroting...."); @@ -819,14 +972,12 @@ void TaskManifestFile::stepAbortParseManifest() int code = pkgmgr_parser_parse_manifest_for_uninstallation( DPL::ToUTF8String(manifest_file).c_str(), NULL); - if (0 != code) - { + if (0 != code) { LogWarning("Manifest parser error: " << code); - ThrowMsg(ManifestParsingError, "Parser returncode: " << code); + ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code); } int ret = unlink(DPL::ToUTF8String(manifest_file).c_str()); - if (0 != ret) - { + if (0 != ret) { LogWarning("No manifest file found: " << manifest_file); } } @@ -837,82 +988,178 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest) LogInfo("setLiveBoxInfo"); LiveBoxInfo liveBox; DPL::Optional ConfigInfo = *it; - DPL::String pkgname = m_context.widgetConfig.pkgName; - size_t found; + DPL::String appid = m_context.widgetConfig.tzAppid; - if(ConfigInfo->m_liveboxId != L"") { - found = ConfigInfo->m_liveboxId.find_first_of(L"."); - if(found != std::string::npos) { - if(0 == ConfigInfo->m_liveboxId.compare(0, found, pkgname)) + if (ConfigInfo->m_liveboxId != L"") { + size_t found = ConfigInfo->m_liveboxId.find_last_of(L"."); + if (found != std::string::npos) { + if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) { liveBox.setLiveboxId(ConfigInfo->m_liveboxId); - else { + } else { DPL::String liveboxId = - pkgname+DPL::String(L".")+ConfigInfo->m_liveboxId; + appid + DPL::String(L".") + ConfigInfo->m_liveboxId; liveBox.setLiveboxId(liveboxId); } } else { DPL::String liveboxId = - pkgname+DPL::String(L".")+ConfigInfo->m_liveboxId; + appid + DPL::String(L".") + ConfigInfo->m_liveboxId; liveBox.setLiveboxId(liveboxId); } } - if(ConfigInfo->m_primary != L"") + if (ConfigInfo->m_primary != L"") { liveBox.setPrimary(ConfigInfo->m_primary); + } - if(ConfigInfo->m_autoLaunch == L"true") - liveBox.setAutoLaunch(pkgname); - - if(ConfigInfo->m_updatePeriod != L"") + if (ConfigInfo->m_updatePeriod != L"") { liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod); + } - if(ConfigInfo->m_label != L"") + if (ConfigInfo->m_label != L"") { liveBox.setLabel(ConfigInfo->m_label); + } DPL::String defaultLocale - = DPL::FromUTF8String(m_context.locations->getPackageInstallationDir()) - + DPL::String(L"/res/wgt/"); + = DPL::FromUTF8String( + m_context.locations->getPackageInstallationDir()) + + DPL::String(L"/res/wgt/"); - if(ConfigInfo->m_icon!=L"") { - liveBox.setIcon(defaultLocale+ConfigInfo->m_icon); + if (ConfigInfo->m_icon != L"") { + liveBox.setIcon(defaultLocale + ConfigInfo->m_icon); } - if (ConfigInfo->m_boxInfo.m_boxSrc.empty() || ConfigInfo->m_boxInfo.m_boxSize.empty()) { + if (ConfigInfo->m_boxInfo.m_boxSrc.empty() || + ConfigInfo->m_boxInfo.m_boxSize.empty()) + { LogInfo("Widget doesn't contain box"); return; } else { BoxInfoType box; if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) { - if((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http")) - || (0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https"))) + if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http")) + || (0 == + ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https"))) + { box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc; - else + } else { box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc; + } } - std::list> BoxSizeList + if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") { + 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 = L"true"; + } else { + box.boxTouchEffect= L"false"; + } + + std::list > BoxSizeList = ConfigInfo->m_boxInfo.m_boxSize; FOREACH(im, BoxSizeList) { std::pair boxSize = *im; - if(!boxSize.second.empty()) + if (!boxSize.second.empty()) { boxSize.second = defaultLocale + boxSize.second; + } box.boxSize.push_back(boxSize); } if (!ConfigInfo->m_boxInfo.m_pdSrc.empty() - && !ConfigInfo->m_boxInfo.m_pdWidth.empty() - && !ConfigInfo->m_boxInfo.m_pdHeight.empty()) { - box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc; + && !ConfigInfo->m_boxInfo.m_pdWidth.empty() + && !ConfigInfo->m_boxInfo.m_pdHeight.empty()) + { + if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http")) + || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https"))) + { + box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc; + } else { + box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc; + } box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth; box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight; } - liveBox.setBox(box); } - manifest.addLivebox(liveBox); } +} + +void TaskManifestFile::setAccount(Manifest& manifest) +{ + WrtDB::ConfigParserData::AccountProvider account = + m_context.widgetConfig.configInfo.accountProvider; + + AccountProviderType provider; + + if (account.m_iconSet.empty()) { + LogInfo("Widget doesn't contain Account"); + return; + } + if (account.m_multiAccountSupport) { + provider.multiAccount = L"ture"; + } else { + provider.multiAccount = L"false"; + } + provider.appid = m_context.widgetConfig.tzAppid; + + FOREACH(it, account.m_iconSet) { + std::pair icon; + + if (it->first == ConfigParserData::IconSectionType::DefaultIcon) { + icon.first = L"account"; + } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) { + icon.first = L"account-small"; + } + icon.second = it->second; + + provider.icon.push_back(icon); + } + + FOREACH(it, account.m_displayNameSet) { + provider.name.push_back(LabelType(it->second, it->first)); + } + + FOREACH(it, account.m_capabilityList) { + provider.capability.push_back(*it); + } + + Account accountInfo; + accountInfo.addAccountProvider(provider); + manifest.addAccount(accountInfo); +} + +void TaskManifestFile::setPrivilege(Manifest& manifest) +{ + WrtDB::ConfigParserData::PrivilegeList privileges = + m_context.widgetConfig.configInfo.privilegeList; + + PrivilegeType privilege; + + FOREACH(it, privileges) + { + privilege.addPrivilegeName(it->name); + } + manifest.addPrivileges(privilege); } } //namespace WidgetInstall