2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file task_manifest_file.cpp
18 * @author Pawel Sikorski (p.sikorski@samgsung.com)
26 #include <dpl/assert.h>
32 #include <widget_install/task_manifest_file.h>
33 #include <widget_install/job_widget_install.h>
34 #include <widget_install/widget_install_errors.h>
35 #include <widget_install/widget_install_context.h>
36 #include <web_provider_livebox_info.h>
37 #include <web_provider_plugin_info.h>
38 #include <dpl/wrt-dao-ro/global_config.h>
39 #include <dpl/log/log.h>
40 #include <dpl/file_input.h>
41 #include <dpl/errno_string.h>
42 #include <dpl/file_output.h>
44 #include <dpl/exception.h>
45 #include <dpl/foreach.h>
46 #include <dpl/sstream.h>
47 #include <dpl/string.h>
48 #include <dpl/optional.h>
49 #include <dpl/utils/wrt_utility.h>
51 #include <libxml_utils.h>
52 #include <pkgmgr/pkgmgr_parser.h>
53 #include <dpl/localization/LanguageTagsProvider.h>
55 #define DEFAULT_ICON_NAME "icon.png"
57 using namespace WrtDB;
60 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
62 const char* const ST_TRUE = "true";
63 const char* const ST_NODISPLAY = "nodisplay";
65 LanguageTagMap getLanguageTagMap()
69 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
70 #include "languages.def"
76 DPL::OptionalString getLangTag(const DPL::String& tag)
78 static LanguageTagMap TagsMap =
81 DPL::String langTag = tag;
83 LogDebug("Trying to map language tag: " << langTag);
84 size_t pos = langTag.find_first_of(L'_');
85 if (pos != DPL::String::npos) {
88 DPL::OptionalString ret;
90 LanguageTagMap::iterator it = TagsMap.find(langTag);
91 if (it != TagsMap.end()) {
94 LogDebug("Mapping IANA Language tag to language tag: " <<
95 langTag << " -> " << ret);
102 namespace WidgetInstall {
103 const char * TaskManifestFile::encoding = "UTF-8";
105 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
106 DPL::TaskDecl<TaskManifestFile>(this),
110 if (m_context.isUpdateMode) {
111 // for widget update.
112 AddStep(&TaskManifestFile::stepBackupIconFiles);
113 AddStep(&TaskManifestFile::stepCopyIconFiles);
114 AddStep(&TaskManifestFile::stepCreateExecFile);
115 AddStep(&TaskManifestFile::stepGenerateManifest);
116 AddStep(&TaskManifestFile::stepParseUpgradedManifest);
117 AddStep(&TaskManifestFile::stepUpdateFinalize);
119 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
121 AddStep(&TaskManifestFile::stepCopyIconFiles);
122 AddStep(&TaskManifestFile::stepCreateExecFile);
123 AddStep(&TaskManifestFile::stepGenerateManifest);
124 AddStep(&TaskManifestFile::stepParseManifest);
125 AddStep(&TaskManifestFile::stepFinalize);
127 AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
131 TaskManifestFile::~TaskManifestFile()
134 void TaskManifestFile::stepCreateExecFile()
136 std::string exec = m_context.locations->getExecFile();
137 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
139 #ifdef MULTIPROCESS_SERVICE_SUPPORT
141 std::stringstream postfix;
142 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
143 std::string controlExec = exec;
144 controlExec.append(postfix.str());
147 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0)
151 LogPedantic("Failed to make a symbolic name for a file "
152 << "[" << DPL::GetErrnoString(error) << "]");
153 ThrowMsg(Exceptions::FileOperationFailed,
154 "Symbolic link creating is not done.");
157 // app-control widgets
158 unsigned int indexMax = 0;
159 FOREACH(it, m_context.widgetConfig.configInfo.appControlList) {
160 if (it->m_index > indexMax) {
161 indexMax = it->m_index;
165 for (std::size_t i = 1; i <= indexMax; ++i) {
166 std::stringstream postfix;
167 postfix << AppControlPrefix::PROCESS_PREFIX << i;
168 std::string controlExec = exec;
169 controlExec.append(postfix.str());
171 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0) {
174 LogPedantic("Failed to make a symbolic name for a file "
175 << "[" << DPL::GetErrnoString(error) << "]");
177 ThrowMsg(Exceptions::FileOperationFailed,
178 "Symbolic link creating is not done.");
183 LogInfo("link -s " << clientExeStr << " " << exec);
185 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
189 LogPedantic("Failed to make a symbolic name for a file "
190 << "[" << DPL::GetErrnoString(error) << "]");
191 ThrowMsg(Exceptions::FileOperationFailed,
192 "Symbolic link creating is not done.");
195 m_context.job->UpdateProgress(
196 InstallerContext::INSTALL_CREATE_EXECFILE,
197 "Widget execfile creation Finished");
200 void TaskManifestFile::stepCopyIconFiles()
202 LogDebug("CopyIconFiles");
204 //This function copies icon to desktop icon path. For each locale avaliable
205 //which there is at least one icon in widget for, icon file is copied.
206 //Coping prioritize last positions when coping. If there is several icons
207 //with given locale, the one, that will be copied, will be icon
208 //which is declared by <icon> tag later than the others in config.xml of
211 std::vector<Locale> generatedLocales;
213 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
214 m_context.widgetConfig.localizationData.icons;
216 //reversed: last <icon> has highest priority to be copied if it has given
217 // locale (TODO: why was that working that way?)
218 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
219 icon = icons.rbegin();
220 icon != icons.rend();
223 FOREACH(locale, icon->availableLocales)
225 DPL::String src = icon->src;
226 LogDebug("Icon for locale: " << *locale << "is : " << src);
228 if (std::find(generatedLocales.begin(), generatedLocales.end(),
229 *locale) != generatedLocales.end())
231 LogDebug("Skipping - has that locale");
234 generatedLocales.push_back(*locale);
237 std::ostringstream sourceFile;
238 std::ostringstream targetFile;
240 sourceFile << m_context.locations->getSourceDir() << "/";
242 if (!locale->empty()) {
243 sourceFile << "locales/" << *locale << "/";
248 targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
249 targetFile << getIconTargetFilename(*locale);
251 if (m_context.widgetConfig.packagingType ==
252 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
254 m_context.locations->setIconTargetFilenameForLocale(
258 LogDebug("Copying icon: " << sourceFile.str() <<
259 " -> " << targetFile.str());
261 icon_list.push_back(targetFile.str());
265 DPL::FileInput input(sourceFile.str());
266 DPL::FileOutput output(targetFile.str());
267 DPL::Copy(&input, &output);
270 Catch(DPL::FileInput::Exception::Base)
272 // Error while opening or closing source file
273 //ReThrowMsg(InstallerException::CopyIconFailed,
274 // sourceFile.str());
276 "Copying widget's icon failed. Widget's icon will not be" \
277 "available from Main Screen");
280 Catch(DPL::FileOutput::Exception::Base)
282 // Error while opening or closing target file
283 //ReThrowMsg(InstallerException::CopyIconFailed,
284 // targetFile.str());
286 "Copying widget's icon failed. Widget's icon will not be" \
287 "available from Main Screen");
290 Catch(DPL::CopyFailed)
292 // Error while copying
293 //ReThrowMsg(InstallerException::CopyIconFailed,
294 // targetFile.str());
296 "Copying widget's icon failed. Widget's icon will not be" \
297 "available from Main Screen");
302 m_context.job->UpdateProgress(
303 InstallerContext::INSTALL_COPY_ICONFILE,
304 "Widget iconfile copy Finished");
307 void TaskManifestFile::stepBackupIconFiles()
309 LogDebug("Backup Icon Files");
311 backup_dir << m_context.locations->getBackupDir() << "/";
315 m_context.job->UpdateProgress(
316 InstallerContext::INSTALL_BACKUP_ICONFILE,
317 "New Widget icon file backup Finished");
320 void TaskManifestFile::stepAbortIconFiles()
322 LogDebug("Abrot Icon Files");
323 FOREACH(it, icon_list)
325 LogDebug("Remove Update Icon : " << (*it));
326 unlink((*it).c_str());
329 std::ostringstream b_icon_dir;
330 b_icon_dir << backup_dir.str() << "icons";
332 std::list<std::string> fileList;
333 getFileList(b_icon_dir.str().c_str(), fileList);
335 FOREACH(back_icon, fileList)
337 std::ostringstream res_file;
338 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
339 res_file << "/" << (*back_icon);
341 std::ostringstream backup_file;
342 backup_file << b_icon_dir.str() << "/" << (*back_icon);
346 DPL::FileInput input(backup_file.str());
347 DPL::FileOutput output(res_file.str());
348 DPL::Copy(&input, &output);
350 Catch(DPL::FileInput::Exception::Base)
352 LogError("Restoration icon File Failed." << backup_file.str()
353 << " to " << res_file.str());
356 Catch(DPL::FileOutput::Exception::Base)
358 LogError("Restoration icon File Failed." << backup_file.str()
359 << " to " << res_file.str());
361 Catch(DPL::CopyFailed)
363 LogError("Restoration icon File Failed." << backup_file.str()
364 << " to " << res_file.str());
369 void TaskManifestFile::stepUpdateFinalize()
372 LogDebug("Finished Update Desktopfile");
375 DPL::String TaskManifestFile::getIconTargetFilename(
376 const DPL::String& languageTag) const
378 DPL::OStringStream filename;
379 TizenAppId appid = m_context.widgetConfig.tzAppid;
381 filename << DPL::ToUTF8String(appid).c_str();
383 if (!languageTag.empty()) {
384 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
390 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
392 if (locale.empty()) {
393 filename << L"." << languageTag;
395 filename << L"." << locale;
400 return filename.str();
403 void TaskManifestFile::stepFinalize()
406 LogInfo("Finished ManifestFile step");
409 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
410 const DPL::String& key,
411 const DPL::String& languageTag)
414 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
417 if (!locale.empty()) {
418 file << "[" << locale << "]";
423 void TaskManifestFile::backupIconFiles()
425 LogInfo("Backup Icon Files");
427 std::ostringstream b_icon_dir;
428 b_icon_dir << backup_dir.str() << "icons";
430 LogDebug("Create icon backup folder : " << b_icon_dir.str());
431 WrtUtilMakeDir(b_icon_dir.str());
433 std::list<std::string> fileList;
434 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
435 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
437 FOREACH(it, fileList)
439 if (0 == (strncmp((*it).c_str(), appid.c_str(),
440 strlen(appid.c_str()))))
442 std::ostringstream icon_file, backup_icon;
443 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
444 icon_file << "/" << (*it);
446 backup_icon << b_icon_dir.str() << "/" << (*it);
448 LogDebug("Backup icon file " << icon_file.str() << " to " <<
452 DPL::FileInput input(icon_file.str());
453 DPL::FileOutput output(backup_icon.str());
454 DPL::Copy(&input, &output);
456 Catch(DPL::FileInput::Exception::Base)
458 LogError("Backup Desktop File Failed.");
459 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
462 Catch(DPL::FileOutput::Exception::Base)
464 LogError("Backup Desktop File Failed.");
465 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
467 Catch(DPL::CopyFailed)
469 LogError("Backup Desktop File Failed.");
470 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
472 unlink((*it).c_str());
477 void TaskManifestFile::getFileList(const char* path,
478 std::list<std::string> &list)
480 DIR* dir = opendir(path);
482 LogError("icon directory doesn't exist");
483 ThrowMsg(Exceptions::FileOperationFailed, path);
487 struct dirent *result;
490 for (return_code = readdir_r(dir, &entry, &result);
491 result != NULL && return_code == 0;
492 return_code = readdir_r(dir, &entry, &result))
494 if (strcmp(entry.d_name, ".") == 0 ||
495 strcmp(entry.d_name, "..") == 0)
499 std::string file_name = entry.d_name;
500 list.push_back(file_name);
503 if (return_code != 0 || errno != 0) {
504 LogError("readdir_r() failed with " << DPL::GetErrnoString());
507 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
508 LogError("Failed to close dir: " << path << " with error: "
509 << DPL::GetErrnoString());
513 void TaskManifestFile::stepGenerateManifest()
515 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
516 manifest_name = pkgid + L".xml";
517 manifest_file += L"/tmp/" + manifest_name;
519 //libxml - init and check
520 LibxmlSingleton::Instance().init();
522 writeManifest(manifest_file);
524 m_context.job->UpdateProgress(
525 InstallerContext::INSTALL_CREATE_MANIFEST,
526 "Widget Manifest Creation Finished");
529 void TaskManifestFile::stepParseManifest()
531 int code = pkgmgr_parser_parse_manifest_for_installation(
532 DPL::ToUTF8String(manifest_file).c_str(), NULL);
535 LogError("Manifest parser error: " << code);
536 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
539 m_context.job->UpdateProgress(
540 InstallerContext::INSTALL_CREATE_MANIFEST,
541 "Widget Manifest Parsing Finished");
542 LogDebug("Manifest parsed");
545 void TaskManifestFile::stepParseUpgradedManifest()
547 if (m_context.widgetConfig.packagingType !=
548 PKG_TYPE_HYBRID_WEB_APP)
550 int code = pkgmgr_parser_parse_manifest_for_upgrade(
551 DPL::ToUTF8String(manifest_file).c_str(), NULL);
554 LogError("Manifest parser error: " << code);
555 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
558 m_context.job->UpdateProgress(
559 InstallerContext::INSTALL_CREATE_MANIFEST,
560 "Widget Manifest Parsing Finished");
561 LogDebug("Manifest parsed");
565 void TaskManifestFile::commitManifest()
567 LogDebug("Commiting manifest file : " << manifest_file);
569 std::ostringstream destFile;
570 if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
571 destFile << "/usr/share/packages" << "/"; //TODO constant with path
573 destFile << "/opt/share/packages" << "/"; //TODO constant with path
575 destFile << DPL::ToUTF8String(manifest_name);
576 LogInfo("cp " << manifest_file << " " << destFile.str());
578 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
579 DPL::FileOutput output(destFile.str());
580 DPL::Copy(&input, &output);
581 LogDebug("Manifest writen to: " << destFile.str());
584 unlink((DPL::ToUTF8String(manifest_file)).c_str());
585 manifest_file = DPL::FromUTF8String(destFile.str().c_str());
588 void TaskManifestFile::writeManifest(const DPL::String & path)
590 LogDebug("Generating manifest file : " << path);
594 #ifdef MULTIPROCESS_SERVICE_SUPPORT
595 //default widget content
596 std::stringstream postfix;
597 // index 0 is reserved
598 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
599 setWidgetExecPath(uiApp, postfix.str());
600 setWidgetName(manifest, uiApp);
601 setWidgetIds(manifest, uiApp);
602 setWidgetIcons(uiApp);
603 setWidgetDescription(manifest);
604 setWidgetManifest(manifest);
605 setWidgetOtherInfo(uiApp);
606 setAppCategory(uiApp);
607 setLiveBoxInfo(manifest);
608 setAccount(manifest);
609 setPrivilege(manifest);
610 manifest.addUiApplication(uiApp);
612 //app-control content
613 ConfigParserData::AppControlInfoList appControlList =
614 m_context.widgetConfig.configInfo.appControlList;
615 FOREACH(it, appControlList) {
618 uiApp.setTaskmanage(true);
619 uiApp.setNodisplay(true);
620 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
621 uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition);
622 uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
624 std::stringstream postfix;
625 postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
626 setWidgetExecPath(uiApp, postfix.str());
627 setWidgetName(manifest, uiApp);
628 setWidgetIds(manifest, uiApp);
629 setWidgetIcons(uiApp);
630 setAppControlInfo(uiApp, *it);
631 setAppCategory(uiApp);
632 manifest.addUiApplication(uiApp);
635 //default widget content
636 setWidgetExecPath(uiApp);
637 setWidgetName(manifest, uiApp);
638 setWidgetIds(manifest, uiApp);
639 setWidgetIcons(uiApp);
640 setWidgetDescription(manifest);
641 setWidgetManifest(manifest);
642 setWidgetOtherInfo(uiApp);
643 setAppControlsInfo(uiApp);
644 setAppCategory(uiApp);
645 setLiveBoxInfo(manifest);
646 setAccount(manifest);
647 setPrivilege(manifest);
649 manifest.addUiApplication(uiApp);
652 manifest.generate(path);
653 LogDebug("Manifest file serialized");
656 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
657 const std::string &postfix)
659 std::string exec = m_context.locations->getExecFile();
660 if (!postfix.empty()) {
661 exec.append(postfix);
663 LogDebug("exec = " << exec);
664 uiApp.setExec(DPL::FromASCIIString(exec));
667 void TaskManifestFile::setWidgetName(Manifest & manifest,
668 UiApplication & uiApp)
670 bool defaultNameSaved = false;
672 DPL::OptionalString defaultLocale =
673 m_context.widgetConfig.configInfo.defaultlocale;
674 std::pair<DPL::String,
675 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
677 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
679 Locale i = localizedData->first;
680 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
684 DPL::OptionalString name = localizedData->second.name;
685 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
687 //store default locale localized data
688 if (!!defaultLocale && defaultLocale == i) {
689 defaultLocalizedData = *localizedData;
693 if (!!defaultLocale && !defaultNameSaved) {
694 DPL::OptionalString name = defaultLocalizedData.second.name;
695 generateWidgetName(manifest,
697 DPL::OptionalString::Null,
703 void TaskManifestFile::setWidgetIds(Manifest & manifest,
704 UiApplication & uiApp,
705 const std::string &postfix)
708 TizenAppId appid = m_context.widgetConfig.tzAppid;
709 if (!postfix.empty()) {
710 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
712 uiApp.setAppid(appid);
715 if (!!m_context.widgetConfig.guid) {
716 uiApp.setExtraid(*m_context.widgetConfig.guid);
718 if (!appid.empty()) {
719 uiApp.setExtraid(DPL::String(L"http://") + appid);
724 uiApp.setType(DPL::FromASCIIString("webapp"));
725 manifest.setType(L"wgt");
728 void TaskManifestFile::generateWidgetName(Manifest & manifest,
729 UiApplication &uiApp,
730 const DPL::OptionalString& tag,
731 DPL::OptionalString name,
732 bool & defaultNameSaved)
737 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
739 if (!locale.empty()) {
740 uiApp.addLabel(LabelType(*name, *tag));
742 uiApp.addLabel(LabelType(*name));
743 manifest.addLabel(LabelType(*name));
746 defaultNameSaved = true;
747 uiApp.addLabel(LabelType(*name));
748 manifest.addLabel(LabelType(*name));
753 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
755 //TODO this file will need to be updated when user locale preferences
757 bool defaultIconSaved = false;
759 DPL::OptionalString defaultLocale =
760 m_context.widgetConfig.configInfo.defaultlocale;
762 std::vector<Locale> generatedLocales;
763 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
764 m_context.widgetConfig.localizationData.icons;
766 //reversed: last <icon> has highest priority to be writen to manifest if it
767 // has given locale (TODO: why was that working that way?)
768 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
769 icon = icons.rbegin();
770 icon != icons.rend();
773 FOREACH(locale, icon->availableLocales)
775 if (std::find(generatedLocales.begin(), generatedLocales.end(),
776 *locale) != generatedLocales.end())
778 LogDebug("Skipping - has that locale - already in manifest");
781 generatedLocales.push_back(*locale);
784 DPL::OptionalString tag = getLangTag(*locale); // translate en ->
790 generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
793 if (!!defaultLocale && !defaultIconSaved) {
794 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
800 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
801 const DPL::OptionalString& tag,
802 const DPL::String& language,
803 bool & defaultIconSaved)
807 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
809 defaultIconSaved = true;
812 DPL::String iconText;
813 iconText += getIconTargetFilename(language);
815 if (!locale.empty()) {
816 uiApp.addIcon(IconType(iconText, locale));
818 uiApp.addIcon(IconType(iconText));
820 std::ostringstream iconPath;
821 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
822 iconPath << getIconTargetFilename(locale);
823 m_context.job->SendProgressIconPath(iconPath.str());
826 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
828 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
830 Locale i = localizedData->first;
831 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
835 DPL::OptionalString description = localizedData->second.description;
836 generateWidgetDescription(manifest, tag, description);
840 void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
841 const DPL::OptionalString& tag,
842 DPL::OptionalString description)
847 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
848 if (!locale.empty()) {
849 manifest.addDescription(DescriptionType(*description, locale));
851 manifest.addDescription(DescriptionType(*description));
854 manifest.addDescription(DescriptionType(*description));
859 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
861 manifest.setPackage(m_context.widgetConfig.tzPkgid);
863 if (!!m_context.widgetConfig.version) {
864 manifest.setVersion(*m_context.widgetConfig.version);
866 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
867 *m_context.widgetConfig.configInfo.authorEmail : L"");
868 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
869 *m_context.widgetConfig.configInfo.authorHref : L"");
870 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
871 *m_context.widgetConfig.configInfo.authorName : L"");
872 manifest.addAuthor(Author(email, href, L"", name));
875 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
877 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
879 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
880 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
881 uiApp.setNodisplay(true);
882 uiApp.setTaskmanage(false);
884 uiApp.setNodisplay(false);
885 uiApp.setTaskmanage(true);
890 //There is no "X-TIZEN-PackageType=wgt"
891 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
892 // DPL::ToUTF8String(*widgetID).c_str()
893 //There is no Comment in pkgmgr "Comment=Widget application"
894 //that were in desktop file
897 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
899 WrtDB::ConfigParserData::AppControlInfoList appControlList =
900 m_context.widgetConfig.configInfo.appControlList;
902 if (appControlList.empty()) {
903 LogInfo("Widget doesn't contain app control");
907 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
908 FOREACH(it, appControlList) {
909 setAppControlInfo(uiApp, *it);
913 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
914 const WrtDB::ConfigParserData::AppControlInfo & service)
916 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
917 AppControl appControl;
918 if (!service.m_operation.empty()) {
919 appControl.addOperation(service.m_operation); //TODO: encapsulation?
921 if (!service.m_uriList.empty()) {
922 FOREACH(uri, service.m_uriList) {
923 appControl.addUri(*uri);
926 if (!service.m_mimeList.empty()) {
927 FOREACH(mime, service.m_mimeList) {
928 appControl.addMime(*mime);
931 uiApp.addAppControl(appControl);
934 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
936 WrtDB::ConfigParserData::CategoryList categoryList =
937 m_context.widgetConfig.configInfo.categoryList;
939 if (categoryList.empty()) {
940 LogInfo("Widget doesn't contain application category");
943 FOREACH(it, categoryList) {
944 if (!(*it).empty()) {
945 uiApp.addAppCategory(*it);
950 void TaskManifestFile::stepAbortParseManifest()
952 LogError("[Parse Manifest] Abroting....");
954 int code = pkgmgr_parser_parse_manifest_for_uninstallation(
955 DPL::ToUTF8String(manifest_file).c_str(), NULL);
958 LogWarning("Manifest parser error: " << code);
959 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
961 int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
963 LogWarning("No manifest file found: " << manifest_file);
967 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
969 FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
970 LogInfo("setLiveBoxInfo");
972 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
973 DPL::String appid = m_context.widgetConfig.tzAppid;
975 if (ConfigInfo->m_liveboxId != L"") {
976 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
977 if (found != std::string::npos) {
978 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
979 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
981 DPL::String liveboxId =
982 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
983 liveBox.setLiveboxId(liveboxId);
986 DPL::String liveboxId =
987 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
988 liveBox.setLiveboxId(liveboxId);
992 if (ConfigInfo->m_primary != L"") {
993 liveBox.setPrimary(ConfigInfo->m_primary);
996 if (ConfigInfo->m_updatePeriod != L"") {
997 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
1000 if (ConfigInfo->m_label != L"") {
1001 liveBox.setLabel(ConfigInfo->m_label);
1004 DPL::String defaultLocale
1005 = DPL::FromUTF8String(
1006 m_context.locations->getPackageInstallationDir())
1007 + DPL::String(L"/res/wgt/");
1009 if (ConfigInfo->m_icon != L"") {
1010 liveBox.setIcon(defaultLocale + ConfigInfo->m_icon);
1013 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1014 ConfigInfo->m_boxInfo.m_boxSize.empty())
1016 LogInfo("Widget doesn't contain box");
1020 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1021 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1023 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1025 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1027 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1031 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1032 std::string boxType;
1033 if (ConfigInfo->m_type == L"") {
1034 // in case of default livebox
1035 boxType = web_provider_livebox_get_default_type();
1037 boxType = DPL::ToUTF8String(ConfigInfo->m_type);
1040 int box_scrollable =
1041 web_provider_plugin_get_box_scrollable(boxType.c_str());
1043 if (box_scrollable) {
1044 box.boxMouseEvent = L"true";
1046 box.boxMouseEvent = L"false";
1049 box.boxMouseEvent = L"false";
1052 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1053 box.boxTouchEffect = L"true";
1055 box.boxTouchEffect= L"false";
1058 std::list<std::pair<DPL::String, DPL::String> > BoxSizeList
1059 = ConfigInfo->m_boxInfo.m_boxSize;
1060 FOREACH(im, BoxSizeList) {
1061 std::pair<DPL::String, DPL::String> boxSize = *im;
1062 if (!boxSize.second.empty()) {
1063 boxSize.second = defaultLocale + boxSize.second;
1065 box.boxSize.push_back(boxSize);
1068 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1069 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1070 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1072 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1073 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1075 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1077 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1079 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1080 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1082 liveBox.setBox(box);
1084 manifest.addLivebox(liveBox);
1088 void TaskManifestFile::setAccount(Manifest& manifest)
1090 WrtDB::ConfigParserData::AccountProvider account =
1091 m_context.widgetConfig.configInfo.accountProvider;
1093 AccountProviderType provider;
1095 if (account.m_iconSet.empty()) {
1096 LogInfo("Widget doesn't contain Account");
1099 if (account.m_multiAccountSupport) {
1100 provider.multiAccount = L"ture";
1102 provider.multiAccount = L"false";
1104 provider.appid = m_context.widgetConfig.tzAppid;
1106 FOREACH(it, account.m_iconSet) {
1107 std::pair<DPL::String, DPL::String> icon;
1109 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1110 icon.first = L"account";
1111 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1112 icon.first = L"account-small";
1114 icon.second = it->second;
1116 provider.icon.push_back(icon);
1119 FOREACH(it, account.m_displayNameSet) {
1120 provider.name.push_back(LabelType(it->second, it->first));
1123 FOREACH(it, account.m_capabilityList) {
1124 provider.capability.push_back(*it);
1127 Account accountInfo;
1128 accountInfo.addAccountProvider(provider);
1129 manifest.addAccount(accountInfo);
1132 void TaskManifestFile::setPrivilege(Manifest& manifest)
1134 WrtDB::ConfigParserData::PrivilegeList privileges =
1135 m_context.widgetConfig.configInfo.privilegeList;
1137 PrivilegeType privilege;
1139 FOREACH(it, privileges)
1141 privilege.addPrivilegeName(it->name);
1144 manifest.addPrivileges(privilege);
1147 } //namespace WidgetInstall