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 <dpl/wrt-dao-ro/global_config.h>
37 #include <dpl/log/log.h>
38 #include <dpl/file_input.h>
39 #include <dpl/errno_string.h>
40 #include <dpl/file_output.h>
42 #include <dpl/exception.h>
43 #include <dpl/foreach.h>
44 #include <dpl/sstream.h>
45 #include <dpl/string.h>
46 #include <dpl/optional.h>
47 #include <dpl/utils/wrt_utility.h>
49 #include <libxml_utils.h>
50 #include <pkgmgr/pkgmgr_parser.h>
51 #include <dpl/localization/LanguageTagsProvider.h>
53 #define DEFAULT_ICON_NAME "icon.png"
55 using namespace WrtDB;
58 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
60 const char* const ST_TRUE = "true";
61 const char* const ST_NODISPLAY = "nodisplay";
63 LanguageTagMap getLanguageTagMap()
67 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
68 #include "languages.def"
74 DPL::OptionalString getLangTag(const DPL::String& tag)
76 static LanguageTagMap TagsMap =
79 DPL::String langTag = tag;
81 LogDebug("Trying to map language tag: " << langTag);
82 size_t pos = langTag.find_first_of(L'_');
83 if (pos != DPL::String::npos) {
86 DPL::OptionalString ret;
88 LanguageTagMap::iterator it = TagsMap.find(langTag);
89 if (it != TagsMap.end()) {
92 LogDebug("Mapping IANA Language tag to language tag: " <<
93 langTag << " -> " << ret);
100 namespace WidgetInstall {
101 const char * TaskManifestFile::encoding = "UTF-8";
103 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
104 DPL::TaskDecl<TaskManifestFile>(this),
108 if (m_context.isUpdateMode) {
109 // for widget update.
110 AddStep(&TaskManifestFile::stepBackupIconFiles);
111 AddStep(&TaskManifestFile::stepCopyIconFiles);
112 AddStep(&TaskManifestFile::stepGenerateManifest);
113 AddStep(&TaskManifestFile::stepParseUpgradedManifest);
114 AddStep(&TaskManifestFile::stepUpdateFinalize);
116 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
118 AddStep(&TaskManifestFile::stepCopyIconFiles);
119 AddStep(&TaskManifestFile::stepCreateExecFile);
120 AddStep(&TaskManifestFile::stepGenerateManifest);
121 AddStep(&TaskManifestFile::stepParseManifest);
122 AddStep(&TaskManifestFile::stepFinalize);
124 AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
128 TaskManifestFile::~TaskManifestFile()
131 void TaskManifestFile::stepCreateExecFile()
133 std::string exec = m_context.locations->getExecFile();
134 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
137 LogInfo("link -s " << clientExeStr << " " << exec);
139 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
143 LogPedantic("Failed to make a symbolic name for a file "
144 << "[" << DPL::GetErrnoString(error) << "]");
145 ThrowMsg(Exceptions::FileOperationFailed,
146 "Symbolic link creating is not done.");
149 #ifdef MULTIPROCESS_SERVICE_SUPPORT
151 std::size_t serviceCount =
152 m_context.widgetConfig.configInfo.appControlList.size();
153 serviceCount += m_context.widgetConfig.configInfo.appServiceList.size();
154 for (std::size_t i = 0; i < serviceCount; ++i) {
155 std::stringstream postfix;
156 postfix << "-__SERVICE_PROCESS__" << i;
157 std::string serviceExec = exec;
158 serviceExec.append(postfix.str());
160 if (symlink(clientExeStr.c_str(), serviceExec.c_str()) != 0)
164 LogPedantic("Failed to make a symbolic name for a file "
165 << "[" << DPL::GetErrnoString(error) << "]");
166 ThrowMsg(Exceptions::FileOperationFailed,
167 "Symbolic link creating is not done.");
173 m_context.job->UpdateProgress(
174 InstallerContext::INSTALL_CREATE_EXECFILE,
175 "Widget execfile creation Finished");
178 void TaskManifestFile::stepCopyIconFiles()
180 LogDebug("CopyIconFiles");
182 //This function copies icon to desktop icon path. For each locale avaliable
183 //which there is at least one icon in widget for, icon file is copied.
184 //Coping prioritize last positions when coping. If there is several icons
185 //with given locale, the one, that will be copied, will be icon
186 //which is declared by <icon> tag later than the others in config.xml of
189 std::vector<Locale> generatedLocales;
191 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
192 m_context.widgetConfig.localizationData.icons;
194 //reversed: last <icon> has highest priority to be copied if it has given
195 // locale (TODO: why was that working that way?)
196 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
197 icon = icons.rbegin();
198 icon != icons.rend();
201 FOREACH(locale, icon->availableLocales)
203 DPL::String src = icon->src;
204 LogDebug("Icon for locale: " << *locale << "is : " << src);
206 if (std::find(generatedLocales.begin(), generatedLocales.end(),
207 *locale) != generatedLocales.end())
209 LogDebug("Skipping - has that locale");
212 generatedLocales.push_back(*locale);
215 std::ostringstream sourceFile;
216 std::ostringstream targetFile;
218 sourceFile << m_context.locations->getSourceDir() << "/";
220 if (!locale->empty()) {
221 sourceFile << "locales/" << *locale << "/";
226 targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
227 targetFile << getIconTargetFilename(*locale);
229 if (m_context.widgetConfig.packagingType ==
230 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
232 m_context.locations->setIconTargetFilenameForLocale(
236 LogDebug("Copying icon: " << sourceFile.str() <<
237 " -> " << targetFile.str());
239 icon_list.push_back(targetFile.str());
243 DPL::FileInput input(sourceFile.str());
244 DPL::FileOutput output(targetFile.str());
245 DPL::Copy(&input, &output);
248 Catch(DPL::FileInput::Exception::Base)
250 // Error while opening or closing source file
251 //ReThrowMsg(InstallerException::CopyIconFailed,
252 // sourceFile.str());
254 "Copying widget's icon failed. Widget's icon will not be" \
255 "available from Main Screen");
258 Catch(DPL::FileOutput::Exception::Base)
260 // Error while opening or closing target file
261 //ReThrowMsg(InstallerException::CopyIconFailed,
262 // targetFile.str());
264 "Copying widget's icon failed. Widget's icon will not be" \
265 "available from Main Screen");
268 Catch(DPL::CopyFailed)
270 // Error while copying
271 //ReThrowMsg(InstallerException::CopyIconFailed,
272 // targetFile.str());
274 "Copying widget's icon failed. Widget's icon will not be" \
275 "available from Main Screen");
280 m_context.job->UpdateProgress(
281 InstallerContext::INSTALL_COPY_ICONFILE,
282 "Widget iconfile copy Finished");
285 void TaskManifestFile::stepBackupIconFiles()
287 LogDebug("Backup Icon Files");
289 backup_dir << m_context.locations->getPackageInstallationDir();
290 backup_dir << "/" << "backup" << "/";
294 m_context.job->UpdateProgress(
295 InstallerContext::INSTALL_BACKUP_ICONFILE,
296 "New Widget icon file backup Finished");
299 void TaskManifestFile::stepAbortIconFiles()
301 LogDebug("Abrot Icon Files");
302 FOREACH(it, icon_list)
304 LogDebug("Remove Update Icon : " << (*it));
305 unlink((*it).c_str());
308 std::ostringstream b_icon_dir;
309 b_icon_dir << backup_dir.str() << "icons";
311 std::list<std::string> fileList;
312 getFileList(b_icon_dir.str().c_str(), fileList);
314 FOREACH(back_icon, fileList)
316 std::ostringstream res_file;
317 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
318 res_file << "/" << (*back_icon);
320 std::ostringstream backup_file;
321 backup_file << b_icon_dir.str() << "/" << (*back_icon);
325 DPL::FileInput input(backup_file.str());
326 DPL::FileOutput output(res_file.str());
327 DPL::Copy(&input, &output);
329 Catch(DPL::FileInput::Exception::Base)
331 LogError("Restoration icon File Failed." << backup_file.str()
332 << " to " << res_file.str());
335 Catch(DPL::FileOutput::Exception::Base)
337 LogError("Restoration icon File Failed." << backup_file.str()
338 << " to " << res_file.str());
340 Catch(DPL::CopyFailed)
342 LogError("Restoration icon File Failed." << backup_file.str()
343 << " to " << res_file.str());
348 void TaskManifestFile::stepUpdateFinalize()
351 LogDebug("Finished Update Desktopfile");
354 DPL::String TaskManifestFile::getIconTargetFilename(
355 const DPL::String& languageTag) const
357 DPL::OStringStream filename;
358 TizenAppId appid = m_context.widgetConfig.tzAppid;
360 filename << DPL::ToUTF8String(appid).c_str();
362 if (!languageTag.empty()) {
363 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
369 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
371 if (locale.empty()) {
372 filename << L"." << languageTag;
374 filename << L"." << locale;
379 return filename.str();
382 void TaskManifestFile::stepFinalize()
385 LogInfo("Finished ManifestFile step");
388 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
389 const DPL::String& key,
390 const DPL::String& languageTag)
393 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
396 if (!locale.empty()) {
397 file << "[" << locale << "]";
402 void TaskManifestFile::updateAilInfo()
404 // Update ail for desktop
405 std::string cfgAppid =
406 DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
407 const char* appid = cfgAppid.c_str();
409 LogDebug("Update ail desktop : " << appid);
410 ail_appinfo_h ai = NULL;
413 ret = ail_get_appinfo(appid, &ai);
415 ail_destroy_appinfo(ai);
418 if (AIL_ERROR_NO_DATA == ret) {
419 if (ail_desktop_add(appid) < 0) {
420 LogWarning("Failed to add ail desktop : " << appid);
422 } else if (AIL_ERROR_OK == ret) {
423 if (ail_desktop_update(appid) < 0) {
424 LogWarning("Failed to update ail desktop : " << appid);
429 void TaskManifestFile::backupIconFiles()
431 LogInfo("Backup Icon Files");
433 std::ostringstream b_icon_dir;
434 b_icon_dir << backup_dir.str() << "icons";
436 LogDebug("Create icon backup folder : " << b_icon_dir.str());
437 WrtUtilMakeDir(b_icon_dir.str());
439 std::list<std::string> fileList;
440 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
441 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
443 FOREACH(it, fileList)
445 if (0 == (strncmp((*it).c_str(), appid.c_str(),
446 strlen(appid.c_str()))))
448 std::ostringstream icon_file, backup_icon;
449 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
450 icon_file << "/" << (*it);
452 backup_icon << b_icon_dir.str() << "/" << (*it);
454 LogDebug("Backup icon file " << icon_file.str() << " to " <<
458 DPL::FileInput input(icon_file.str());
459 DPL::FileOutput output(backup_icon.str());
460 DPL::Copy(&input, &output);
462 Catch(DPL::FileInput::Exception::Base)
464 LogError("Backup Desktop File Failed.");
465 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
468 Catch(DPL::FileOutput::Exception::Base)
470 LogError("Backup Desktop File Failed.");
471 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
473 Catch(DPL::CopyFailed)
475 LogError("Backup Desktop File Failed.");
476 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
478 unlink((*it).c_str());
483 void TaskManifestFile::getFileList(const char* path,
484 std::list<std::string> &list)
486 DIR* dir = opendir(path);
488 LogError("icon directory doesn't exist");
489 ThrowMsg(Exceptions::FileOperationFailed, path);
493 struct dirent *result;
496 for (return_code = readdir_r(dir, &entry, &result);
497 result != NULL && return_code == 0;
498 return_code = readdir_r(dir, &entry, &result))
500 if (strcmp(entry.d_name, ".") == 0 ||
501 strcmp(entry.d_name, "..") == 0)
505 std::string file_name = entry.d_name;
506 list.push_back(file_name);
509 if (return_code != 0 || errno != 0) {
510 LogError("readdir_r() failed with " << DPL::GetErrnoString());
513 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
514 LogError("Failed to close dir: " << path << " with error: "
515 << DPL::GetErrnoString());
519 void TaskManifestFile::stepGenerateManifest()
521 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
522 manifest_name = pkgid + L".xml";
523 manifest_file += L"/tmp/" + manifest_name;
525 //libxml - init and check
526 LibxmlSingleton::Instance().init();
528 writeManifest(manifest_file);
530 m_context.job->UpdateProgress(
531 InstallerContext::INSTALL_CREATE_MANIFEST,
532 "Widget Manifest Creation Finished");
535 void TaskManifestFile::stepParseManifest()
537 int code = pkgmgr_parser_parse_manifest_for_installation(
538 DPL::ToUTF8String(manifest_file).c_str(), NULL);
541 LogError("Manifest parser error: " << code);
542 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
545 // TODO : It will be removed. AIL update is temporary code request by pkgmgr
549 m_context.job->UpdateProgress(
550 InstallerContext::INSTALL_CREATE_MANIFEST,
551 "Widget Manifest Parsing Finished");
552 LogDebug("Manifest parsed");
555 void TaskManifestFile::stepParseUpgradedManifest()
557 int code = pkgmgr_parser_parse_manifest_for_upgrade(
558 DPL::ToUTF8String(manifest_file).c_str(), NULL);
561 LogError("Manifest parser error: " << code);
562 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
565 // TODO : It will be removed. AIL update is temporary code request by pkgmgr
569 m_context.job->UpdateProgress(
570 InstallerContext::INSTALL_CREATE_MANIFEST,
571 "Widget Manifest Parsing Finished");
572 LogDebug("Manifest parsed");
575 void TaskManifestFile::commitManifest()
577 LogDebug("Commiting manifest file : " << manifest_file);
579 std::ostringstream destFile;
580 destFile << "/opt/share/packages" << "/"; //TODO constant with path
581 destFile << DPL::ToUTF8String(manifest_name);
582 LogInfo("cp " << manifest_file << " " << destFile.str());
584 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
585 DPL::FileOutput output(destFile.str());
586 DPL::Copy(&input, &output);
587 LogDebug("Manifest writen to: " << destFile.str());
590 unlink((DPL::ToUTF8String(manifest_file)).c_str());
591 manifest_file = DPL::FromUTF8String(destFile.str().c_str());
594 void TaskManifestFile::writeManifest(const DPL::String & path)
596 LogDebug("Generating manifest file : " << path);
600 //default widget content
601 setWidgetExecPath(uiApp);
602 setWidgetName(manifest, uiApp);
603 setWidgetIds(manifest, uiApp);
604 setWidgetIcons(uiApp);
605 setWidgetManifest(manifest);
606 setWidgetOtherInfo(uiApp);
607 #ifndef MULTIPROCESS_SERVICE_SUPPORT
608 setAppServicesInfo(uiApp);
609 setAppControlsInfo(uiApp);
611 setAppCategory(uiApp);
612 setLiveBoxInfo(manifest);
613 setAccount(manifest);
614 setPrivilege(manifest);
616 manifest.addUiApplication(uiApp);
617 #ifdef MULTIPROCESS_SERVICE_SUPPORT
618 //services AppControl tag
619 ConfigParserData::AppControlInfoList appControlList =
620 m_context.widgetConfig.configInfo.appControlList;
623 FOREACH(it, appControlList) {
627 uiApp.setTaskmanage(true);
628 uiApp.setNodisplay(true);
630 std::stringstream postfix;
631 postfix << "-__SERVICE_PROCESS__" << count++;
633 setWidgetExecPath(uiApp, postfix.str());
634 setWidgetName(manifest, uiApp);
635 setWidgetIds(manifest, uiApp, postfix.str());
636 setWidgetIcons(uiApp);
637 setAppControlInfo(uiApp, *it);
638 setAppCategory(uiApp);
639 setAccount(manifest);
640 setPrivilege(manifest);
642 manifest.addUiApplication(uiApp);
644 //TODO: AppService tag will be removed
645 //services AppService tag
646 WrtDB::ConfigParserData::ServiceInfoList appServiceList =
647 m_context.widgetConfig.configInfo.appServiceList;
648 FOREACH(it, appServiceList) {
652 uiApp.setTaskmanage(true);
653 uiApp.setNodisplay(true);
655 std::stringstream postfix;
656 postfix << "-__SERVICE_PROCESS__" << count++;
658 setWidgetExecPath(uiApp, postfix.str());
659 setWidgetName(manifest, uiApp);
660 setWidgetIds(manifest, uiApp, postfix.str());
661 setWidgetIcons(uiApp);
662 setAppServiceInfo(uiApp, *it);
663 setAppCategory(uiApp);
664 setAccount(manifest);
665 setPrivilege(manifest);
667 manifest.addUiApplication(uiApp);
670 manifest.generate(path);
671 LogDebug("Manifest file serialized");
674 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
675 const std::string &postfix)
677 std::string exec = m_context.locations->getExecFile();
678 if (!postfix.empty()) {
679 exec.append(postfix);
681 LogDebug("exec = " << exec);
682 uiApp.setExec(DPL::FromASCIIString(exec));
685 void TaskManifestFile::setWidgetName(Manifest & manifest,
686 UiApplication & uiApp)
688 bool defaultNameSaved = false;
690 DPL::OptionalString defaultLocale =
691 m_context.widgetConfig.configInfo.defaultlocale;
692 std::pair<DPL::String,
693 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
695 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
697 Locale i = localizedData->first;
698 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
702 DPL::OptionalString name = localizedData->second.name;
703 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
705 //store default locale localized data
706 if (!!defaultLocale && defaultLocale == i) {
707 defaultLocalizedData = *localizedData;
711 if (!!defaultLocale && !defaultNameSaved) {
712 DPL::OptionalString name = defaultLocalizedData.second.name;
713 generateWidgetName(manifest,
715 DPL::OptionalString::Null,
721 void TaskManifestFile::setWidgetIds(Manifest & manifest,
722 UiApplication & uiApp,
723 const std::string &postfix)
726 TizenAppId appid = m_context.widgetConfig.tzAppid;
727 if (!postfix.empty()) {
728 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
730 uiApp.setAppid(appid);
733 if (!!m_context.widgetConfig.guid) {
734 uiApp.setExtraid(*m_context.widgetConfig.guid);
736 if (!appid.empty()) {
737 uiApp.setExtraid(DPL::String(L"http://") + appid);
742 uiApp.setType(DPL::FromASCIIString("webapp"));
743 manifest.setType(L"wgt");
746 void TaskManifestFile::generateWidgetName(Manifest & manifest,
747 UiApplication &uiApp,
748 const DPL::OptionalString& tag,
749 DPL::OptionalString name,
750 bool & defaultNameSaved)
755 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
757 if (!locale.empty()) {
758 uiApp.addLabel(LabelType(*name, *tag));
760 uiApp.addLabel(LabelType(*name));
761 manifest.addLabel(LabelType(*name));
764 defaultNameSaved = true;
765 uiApp.addLabel(LabelType(*name));
766 manifest.addLabel(LabelType(*name));
771 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
773 //TODO this file will need to be updated when user locale preferences
775 bool defaultIconSaved = false;
777 DPL::OptionalString defaultLocale =
778 m_context.widgetConfig.configInfo.defaultlocale;
780 std::vector<Locale> generatedLocales;
781 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
782 m_context.widgetConfig.localizationData.icons;
784 //reversed: last <icon> has highest priority to be writen to manifest if it
785 // has given locale (TODO: why was that working that way?)
786 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
787 icon = icons.rbegin();
788 icon != icons.rend();
791 FOREACH(locale, icon->availableLocales)
793 if (std::find(generatedLocales.begin(), generatedLocales.end(),
794 *locale) != generatedLocales.end())
796 LogDebug("Skipping - has that locale - already in manifest");
799 generatedLocales.push_back(*locale);
802 DPL::OptionalString tag = getLangTag(*locale); // translate en ->
808 generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
811 if (!!defaultLocale && !defaultIconSaved) {
812 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
818 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
819 const DPL::OptionalString& tag,
820 const DPL::String& language,
821 bool & defaultIconSaved)
825 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
827 defaultIconSaved = true;
830 DPL::String iconText;
831 iconText += getIconTargetFilename(language);
833 if (!locale.empty()) {
834 uiApp.addIcon(IconType(iconText, locale));
836 uiApp.addIcon(IconType(iconText));
838 std::ostringstream iconPath;
839 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
840 iconPath << getIconTargetFilename(locale);
841 m_context.job->SendProgressIconPath(iconPath.str());
844 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
846 manifest.setPackage(m_context.widgetConfig.tzPkgid);
848 if (!!m_context.widgetConfig.version) {
849 manifest.setVersion(*m_context.widgetConfig.version);
851 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
852 *m_context.widgetConfig.configInfo.authorEmail : L"");
853 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
854 *m_context.widgetConfig.configInfo.authorHref : L"");
855 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
856 *m_context.widgetConfig.configInfo.authorName : L"");
857 manifest.addAuthor(Author(email, href, L"", name));
860 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
862 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
864 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
865 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
866 uiApp.setNodisplay(true);
867 uiApp.setTaskmanage(false);
869 uiApp.setNodisplay(false);
870 uiApp.setTaskmanage(true);
875 //There is no "X-TIZEN-PackageType=wgt"
876 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
877 // DPL::ToUTF8String(*widgetID).c_str()
878 //There is no Comment in pkgmgr "Comment=Widget application"
879 //that were in desktop file
882 void TaskManifestFile::setAppServicesInfo(UiApplication & uiApp)
884 WrtDB::ConfigParserData::ServiceInfoList appServiceList =
885 m_context.widgetConfig.configInfo.appServiceList;
887 if (appServiceList.empty()) {
888 LogInfo("Widget doesn't contain application service");
892 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
893 FOREACH(it, appServiceList) {
894 setAppServiceInfo(uiApp, *it);
898 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
900 WrtDB::ConfigParserData::AppControlInfoList appControlList =
901 m_context.widgetConfig.configInfo.appControlList;
903 if (appControlList.empty()) {
904 LogInfo("Widget doesn't contain app control");
908 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
909 FOREACH(it, appControlList) {
910 setAppControlInfo(uiApp, *it);
914 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp,
915 const ConfigParserData::ServiceInfo & service)
917 AppControl appControl;
918 if (!service.m_operation.empty()) {
919 appControl.addOperation(service.m_operation); //TODO: encapsulation?
921 if (!service.m_scheme.empty()) {
922 appControl.addUri(service.m_scheme);
924 if (!service.m_mime.empty()) {
925 appControl.addMime(service.m_mime);
927 uiApp.addAppControl(appControl);
930 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
931 const WrtDB::ConfigParserData::AppControlInfo & service)
933 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
934 AppControl appControl;
935 if (!service.m_operation.empty()) {
936 appControl.addOperation(service.m_operation); //TODO: encapsulation?
938 if (!service.m_uriList.empty()) {
939 FOREACH(uri, service.m_uriList) {
940 appControl.addUri(*uri);
943 if (!service.m_mimeList.empty()) {
944 FOREACH(mime, service.m_mimeList) {
945 appControl.addMime(*mime);
948 uiApp.addAppControl(appControl);
951 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
953 WrtDB::ConfigParserData::CategoryList categoryList =
954 m_context.widgetConfig.configInfo.categoryList;
956 if (categoryList.empty()) {
957 LogInfo("Widget doesn't contain application category");
960 FOREACH(it, categoryList) {
961 if (!(*it).empty()) {
962 uiApp.addAppCategory(*it);
967 void TaskManifestFile::stepAbortParseManifest()
969 LogError("[Parse Manifest] Abroting....");
971 int code = pkgmgr_parser_parse_manifest_for_uninstallation(
972 DPL::ToUTF8String(manifest_file).c_str(), NULL);
975 LogWarning("Manifest parser error: " << code);
976 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
978 int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
980 LogWarning("No manifest file found: " << manifest_file);
984 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
986 FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
987 LogInfo("setLiveBoxInfo");
989 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
990 DPL::String appid = m_context.widgetConfig.tzAppid;
992 if (ConfigInfo->m_liveboxId != L"") {
993 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
994 if (found != std::string::npos) {
995 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
996 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
998 DPL::String liveboxId =
999 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1000 liveBox.setLiveboxId(liveboxId);
1003 DPL::String liveboxId =
1004 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1005 liveBox.setLiveboxId(liveboxId);
1009 if (ConfigInfo->m_primary != L"") {
1010 liveBox.setPrimary(ConfigInfo->m_primary);
1013 if (ConfigInfo->m_updatePeriod != L"") {
1014 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
1017 if (ConfigInfo->m_label != L"") {
1018 liveBox.setLabel(ConfigInfo->m_label);
1021 DPL::String defaultLocale
1022 = DPL::FromUTF8String(
1023 m_context.locations->getPackageInstallationDir())
1024 + DPL::String(L"/res/wgt/");
1026 if (ConfigInfo->m_icon != L"") {
1027 liveBox.setIcon(defaultLocale + ConfigInfo->m_icon);
1030 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1031 ConfigInfo->m_boxInfo.m_boxSize.empty())
1033 LogInfo("Widget doesn't contain box");
1037 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1038 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1040 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1042 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1044 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1048 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1049 box.boxMouseEvent = ConfigInfo->m_boxInfo.m_boxMouseEvent;
1051 box.boxMouseEvent = L"false";
1054 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1055 box.boxTouchEffect = ConfigInfo->m_boxInfo.m_boxTouchEffect;
1057 box.boxTouchEffect= L"false";
1060 std::list<std::pair<DPL::String, DPL::String> > BoxSizeList
1061 = ConfigInfo->m_boxInfo.m_boxSize;
1062 FOREACH(im, BoxSizeList) {
1063 std::pair<DPL::String, DPL::String> boxSize = *im;
1064 if (!boxSize.second.empty()) {
1065 boxSize.second = defaultLocale + boxSize.second;
1067 box.boxSize.push_back(boxSize);
1070 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1071 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1072 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1074 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1075 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1077 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1079 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1081 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1082 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1084 liveBox.setBox(box);
1086 manifest.addLivebox(liveBox);
1090 void TaskManifestFile::setAccount(Manifest& manifest)
1092 WrtDB::ConfigParserData::AccountProvider account =
1093 m_context.widgetConfig.configInfo.accountProvider;
1095 AccountProviderType provider;
1097 if (account.m_iconSet.empty()) {
1098 LogInfo("Widget doesn't contain Account");
1101 if (account.m_multiAccountSupport) {
1102 provider.multiAccount = L"ture";
1104 provider.multiAccount = L"false";
1106 provider.appid = m_context.widgetConfig.tzAppid;
1108 FOREACH(it, account.m_iconSet) {
1109 std::pair<DPL::String, DPL::String> icon;
1111 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1112 icon.first = L"account";
1113 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1114 icon.first = L"account-small";
1116 icon.second = it->second;
1118 provider.icon.push_back(icon);
1121 FOREACH(it, account.m_displayNameSet) {
1122 provider.name.push_back(LabelType(it->second, it->first));
1125 FOREACH(it, account.m_capabilityList) {
1126 provider.capability.push_back(*it);
1129 Account accountInfo;
1130 accountInfo.addAccountProvider(provider);
1131 manifest.addAccount(accountInfo);
1134 void TaskManifestFile::setPrivilege(Manifest& manifest)
1136 WrtDB::ConfigParserData::PrivilegeList privileges =
1137 m_context.widgetConfig.configInfo.privilegeList;
1139 PrivilegeType privilege;
1141 FOREACH(it, privileges)
1143 privilege.addPrivilegeName(it->name);
1146 manifest.addPrivileges(privilege);
1149 } //namespace WidgetInstall