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/wrt-dao-ro/config_parser_data.h>
40 #include <dpl/log/log.h>
41 #include <dpl/file_input.h>
42 #include <dpl/errno_string.h>
43 #include <dpl/file_output.h>
45 #include <dpl/exception.h>
46 #include <dpl/foreach.h>
47 #include <dpl/sstream.h>
48 #include <dpl/string.h>
49 #include <dpl/optional.h>
50 #include <dpl/utils/wrt_utility.h>
52 #include <libxml_utils.h>
53 #include <pkgmgr/pkgmgr_parser.h>
54 #include <dpl/localization/LanguageTagsProvider.h>
56 #define DEFAULT_ICON_NAME "icon.png"
58 using namespace WrtDB;
61 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
63 const char* const STR_TRUE = "true";
64 const char* const STR_FALSE = "false";
65 const char* const STR_NODISPLAY = "nodisplay";
67 LanguageTagMap getLanguageTagMap()
71 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
72 #include "languages.def"
78 DPL::OptionalString getLangTag(const DPL::String& tag)
80 static LanguageTagMap TagsMap =
83 DPL::String langTag = tag;
85 LogDebug("Trying to map language tag: " << langTag);
86 size_t pos = langTag.find_first_of(L'_');
87 if (pos != DPL::String::npos) {
90 DPL::OptionalString ret;
92 LanguageTagMap::iterator it = TagsMap.find(langTag);
93 if (it != TagsMap.end()) {
96 LogDebug("Mapping IANA Language tag to language tag: " <<
97 langTag << " -> " << ret);
104 namespace WidgetInstall {
105 const char * TaskManifestFile::encoding = "UTF-8";
107 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
108 DPL::TaskDecl<TaskManifestFile>(this),
112 if (m_context.isUpdateMode) {
113 // for widget update.
114 AddStep(&TaskManifestFile::stepBackupIconFiles);
115 AddStep(&TaskManifestFile::stepCopyIconFiles);
116 AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
117 AddStep(&TaskManifestFile::stepCreateExecFile);
118 AddStep(&TaskManifestFile::stepGenerateManifest);
119 AddStep(&TaskManifestFile::stepParseManifest);
121 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
123 AddStep(&TaskManifestFile::stepCopyIconFiles);
124 AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
125 AddStep(&TaskManifestFile::stepCreateExecFile);
126 AddStep(&TaskManifestFile::stepGenerateManifest);
127 AddStep(&TaskManifestFile::stepParseManifest);
129 AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
133 TaskManifestFile::~TaskManifestFile()
136 void TaskManifestFile::stepCreateExecFile()
138 std::string exec = m_context.locations->getExecFile();
139 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
141 #ifdef MULTIPROCESS_SERVICE_SUPPORT
143 std::stringstream postfix;
144 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
145 std::string controlExec = exec;
146 controlExec.append(postfix.str());
149 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0)
153 LogPedantic("Failed to make a symbolic name for a file "
154 << "[" << DPL::GetErrnoString(error) << "]");
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) << "]");
181 LogInfo("link -s " << clientExeStr << " " << exec);
183 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
187 LogPedantic("Failed to make a symbolic name for a file "
188 << "[" << DPL::GetErrnoString(error) << "]");
191 m_context.job->UpdateProgress(
192 InstallerContext::INSTALL_CREATE_EXECFILE,
193 "Widget execfile creation Finished");
196 void TaskManifestFile::stepCopyIconFiles()
198 LogDebug("CopyIconFiles");
200 //This function copies icon to desktop icon path. For each locale avaliable
201 //which there is at least one icon in widget for, icon file is copied.
202 //Coping prioritize last positions when coping. If there is several icons
203 //with given locale, the one, that will be copied, will be icon
204 //which is declared by <icon> tag later than the others in config.xml of
207 std::vector<Locale> generatedLocales;
209 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
210 m_context.widgetConfig.localizationData.icons;
212 //reversed: last <icon> has highest priority to be copied if it has given
213 // locale (TODO: why was that working that way?)
214 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
215 icon = icons.rbegin();
216 icon != icons.rend();
219 FOREACH(locale, icon->availableLocales)
221 DPL::String src = icon->src;
222 LogDebug("Icon for locale: " << *locale << "is : " << src);
224 if (std::find(generatedLocales.begin(), generatedLocales.end(),
225 *locale) != generatedLocales.end())
227 LogDebug("Skipping - has that locale");
230 generatedLocales.push_back(*locale);
233 std::ostringstream sourceFile;
234 std::ostringstream targetFile;
236 sourceFile << m_context.locations->getSourceDir() << "/";
238 if (!locale->empty()) {
239 sourceFile << "locales/" << *locale << "/";
244 targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
245 targetFile << getIconTargetFilename(*locale);
247 if (m_context.widgetConfig.packagingType ==
248 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
250 m_context.locations->setIconTargetFilenameForLocale(
254 LogDebug("Copying icon: " << sourceFile.str() <<
255 " -> " << targetFile.str());
257 icon_list.push_back(targetFile.str());
261 DPL::FileInput input(sourceFile.str());
262 DPL::FileOutput output(targetFile.str());
263 DPL::Copy(&input, &output);
266 Catch(DPL::FileInput::Exception::Base)
268 // Error while opening or closing source file
269 //ReThrowMsg(InstallerException::CopyIconFailed,
270 // sourceFile.str());
272 "Copying widget's icon failed. Widget's icon will not be" \
273 "available from Main Screen");
276 Catch(DPL::FileOutput::Exception::Base)
278 // Error while opening or closing target file
279 //ReThrowMsg(InstallerException::CopyIconFailed,
280 // targetFile.str());
282 "Copying widget's icon failed. Widget's icon will not be" \
283 "available from Main Screen");
286 Catch(DPL::CopyFailed)
288 // Error while copying
289 //ReThrowMsg(InstallerException::CopyIconFailed,
290 // targetFile.str());
292 "Copying widget's icon failed. Widget's icon will not be" \
293 "available from Main Screen");
298 m_context.job->UpdateProgress(
299 InstallerContext::INSTALL_COPY_ICONFILE,
300 "Widget iconfile copy Finished");
303 void TaskManifestFile::stepCopyLiveboxFiles()
305 LogDebug("Copy Livebox Files");
307 using namespace WrtDB;
308 ConfigParserData &data = m_context.widgetConfig.configInfo;
309 ConfigParserData::LiveboxList liveBoxList = data.m_livebox;
311 if (liveBoxList.size() <= 0) {
315 std::ostringstream sourceFile;
316 std::ostringstream targetFile;
318 FOREACH (boxIt, liveBoxList) {
319 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
320 (**boxIt).m_boxInfo.m_boxSize;
321 FOREACH (sizeIt, boxSizeList) {
322 std::string preview = DPL::ToUTF8String((*sizeIt).m_preview);
323 if (preview.empty()) {
326 // copy preview image to shared directory
327 sourceFile << m_context.locations->getSourceDir() << "/";
328 sourceFile << preview;
329 targetFile << m_context.locations->getSharedDataDir() << "/";
330 targetFile << (**boxIt).m_liveboxId << ".";
331 targetFile << DPL::ToUTF8String((*sizeIt).m_size) << ".preview.png";
333 DPL::FileInput input(sourceFile.str());
334 DPL::FileOutput output(targetFile.str());
335 DPL::Copy(&input, &output);
337 // clear stream objects
341 // check this livebox has icon element
342 std::string icon = DPL::ToUTF8String((**boxIt).m_icon);
346 // copy icon to shared directory
347 sourceFile << m_context.locations->getSourceDir() << "/";
349 targetFile << m_context.locations->getSharedDataDir() << "/";
350 targetFile << (**boxIt).m_liveboxId << ".icon.png";
352 DPL::FileInput input(sourceFile.str());
353 DPL::FileOutput output(targetFile.str());
354 DPL::Copy(&input, &output);
356 // clear stream objects
361 m_context.job->UpdateProgress(
362 InstallerContext::INSTALL_COPY_LIVEBOX_FILES,
363 "Livebox files copy Finished");
366 void TaskManifestFile::stepBackupIconFiles()
368 LogDebug("Backup Icon Files");
370 backup_dir << m_context.locations->getBackupDir() << "/";
374 m_context.job->UpdateProgress(
375 InstallerContext::INSTALL_BACKUP_ICONFILE,
376 "New Widget icon file backup Finished");
379 void TaskManifestFile::stepAbortIconFiles()
381 LogDebug("Abrot Icon Files");
382 FOREACH(it, icon_list)
384 LogDebug("Remove Update Icon : " << (*it));
385 unlink((*it).c_str());
388 std::ostringstream b_icon_dir;
389 b_icon_dir << backup_dir.str() << "icons";
391 std::list<std::string> fileList;
392 getFileList(b_icon_dir.str().c_str(), fileList);
394 FOREACH(back_icon, fileList)
396 std::ostringstream res_file;
397 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
398 res_file << "/" << (*back_icon);
400 std::ostringstream backup_file;
401 backup_file << b_icon_dir.str() << "/" << (*back_icon);
405 DPL::FileInput input(backup_file.str());
406 DPL::FileOutput output(res_file.str());
407 DPL::Copy(&input, &output);
409 Catch(DPL::FileInput::Exception::Base)
411 LogError("Restoration icon File Failed." << backup_file.str()
412 << " to " << res_file.str());
415 Catch(DPL::FileOutput::Exception::Base)
417 LogError("Restoration icon File Failed." << backup_file.str()
418 << " to " << res_file.str());
420 Catch(DPL::CopyFailed)
422 LogError("Restoration icon File Failed." << backup_file.str()
423 << " to " << res_file.str());
428 DPL::String TaskManifestFile::getIconTargetFilename(
429 const DPL::String& languageTag) const
431 DPL::OStringStream filename;
432 TizenAppId appid = m_context.widgetConfig.tzAppid;
434 filename << DPL::ToUTF8String(appid).c_str();
436 if (!languageTag.empty()) {
437 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
443 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
445 if (locale.empty()) {
446 filename << L"." << languageTag;
448 filename << L"." << locale;
453 return filename.str();
456 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
457 const DPL::String& key,
458 const DPL::String& languageTag)
461 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
464 if (!locale.empty()) {
465 file << "[" << locale << "]";
470 void TaskManifestFile::backupIconFiles()
472 LogInfo("Backup Icon Files");
474 std::ostringstream b_icon_dir;
475 b_icon_dir << backup_dir.str() << "icons";
477 LogDebug("Create icon backup folder : " << b_icon_dir.str());
478 WrtUtilMakeDir(b_icon_dir.str());
480 std::list<std::string> fileList;
481 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
482 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
484 FOREACH(it, fileList)
486 if (0 == (strncmp((*it).c_str(), appid.c_str(),
487 strlen(appid.c_str()))))
489 std::ostringstream icon_file, backup_icon;
490 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
491 icon_file << "/" << (*it);
493 backup_icon << b_icon_dir.str() << "/" << (*it);
495 LogDebug("Backup icon file " << icon_file.str() << " to " <<
499 DPL::FileInput input(icon_file.str());
500 DPL::FileOutput output(backup_icon.str());
501 DPL::Copy(&input, &output);
503 Catch(DPL::FileInput::Exception::Base)
505 LogError("Backup Desktop File Failed.");
506 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
509 Catch(DPL::FileOutput::Exception::Base)
511 LogError("Backup Desktop File Failed.");
512 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
514 Catch(DPL::CopyFailed)
516 LogError("Backup Desktop File Failed.");
517 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
519 unlink((*it).c_str());
524 void TaskManifestFile::getFileList(const char* path,
525 std::list<std::string> &list)
527 DIR* dir = opendir(path);
529 LogError("icon directory doesn't exist");
530 ThrowMsg(Exceptions::FileOperationFailed, path);
534 struct dirent *result;
537 for (return_code = readdir_r(dir, &entry, &result);
538 result != NULL && return_code == 0;
539 return_code = readdir_r(dir, &entry, &result))
541 if (strcmp(entry.d_name, ".") == 0 ||
542 strcmp(entry.d_name, "..") == 0)
546 std::string file_name = entry.d_name;
547 list.push_back(file_name);
550 if (return_code != 0 || errno != 0) {
551 LogError("readdir_r() failed with " << DPL::GetErrnoString());
554 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
555 LogError("Failed to close dir: " << path << " with error: "
556 << DPL::GetErrnoString());
560 void TaskManifestFile::stepGenerateManifest()
562 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
563 manifest_name = pkgid + L".xml";
564 manifest_file += L"/tmp/" + manifest_name;
566 //libxml - init and check
567 LibxmlSingleton::Instance().init();
569 writeManifest(manifest_file);
571 std::ostringstream destFile;
572 if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
573 destFile << "/usr/share/packages" << "/"; //TODO constant with path
575 destFile << "/opt/share/packages" << "/"; //TODO constant with path
578 destFile << DPL::ToUTF8String(manifest_name);
579 commit_manifest = destFile.str();
580 LogDebug("Commiting manifest file : " << commit_manifest);
582 m_context.job->UpdateProgress(
583 InstallerContext::INSTALL_CREATE_MANIFEST,
584 "Widget Manifest Creation Finished");
587 void TaskManifestFile::stepParseManifest()
590 char* updateTags[3] = {NULL, };
592 if (!m_context.mode.removable) {
593 updateTags[0] = "preload=false";
594 updateTags[1] = "removable=false";
595 updateTags[2] = NULL;
601 if (m_context.isUpdateMode || (
602 m_context.mode.rootPath == InstallMode::RootPath::RO
603 && m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
604 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
606 if (m_context.widgetConfig.packagingType != PKG_TYPE_HYBRID_WEB_APP) {
607 code = pkgmgr_parser_parse_manifest_for_upgrade(
608 commit_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
611 LogError("Manifest parser error: " << code);
612 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
616 code = pkgmgr_parser_parse_manifest_for_installation(
617 commit_manifest.c_str(), (updateTags[0] == NULL) ? NULL : updateTags);
620 LogError("Manifest parser error: " << code);
621 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
625 m_context.job->UpdateProgress(
626 InstallerContext::INSTALL_CREATE_MANIFEST,
627 "Widget Manifest Parsing Finished");
628 LogDebug("Manifest parsed");
631 void TaskManifestFile::commitManifest()
634 if (!(m_context.mode.rootPath == InstallMode::RootPath::RO &&
635 m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
636 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
637 LogInfo("cp " << manifest_file << " " << commit_manifest);
639 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
640 DPL::FileOutput output(commit_manifest);
641 DPL::Copy(&input, &output);
642 LogDebug("Manifest writen to: " << commit_manifest);
645 unlink((DPL::ToUTF8String(manifest_file)).c_str());
646 manifest_file = DPL::FromUTF8String(commit_manifest);
650 void TaskManifestFile::writeManifest(const DPL::String & path)
652 LogDebug("Generating manifest file : " << path);
656 #ifdef MULTIPROCESS_SERVICE_SUPPORT
657 //default widget content
658 std::stringstream postfix;
659 // index 0 is reserved
660 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
661 setWidgetExecPath(uiApp, postfix.str());
662 setWidgetName(manifest, uiApp);
663 setWidgetIds(manifest, uiApp);
664 setWidgetIcons(uiApp);
665 setWidgetDescription(manifest);
666 setWidgetManifest(manifest);
667 setWidgetOtherInfo(uiApp);
668 setAppCategory(uiApp);
670 setLiveBoxInfo(manifest);
671 setAccount(manifest);
672 setPrivilege(manifest);
673 manifest.addUiApplication(uiApp);
675 //app-control content
676 ConfigParserData::AppControlInfoList appControlList =
677 m_context.widgetConfig.configInfo.appControlList;
678 FOREACH(it, appControlList) {
681 uiApp.setTaskmanage(true);
682 uiApp.setNodisplay(true);
683 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
684 uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition);
685 uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
687 std::stringstream postfix;
688 postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
689 setWidgetExecPath(uiApp, postfix.str());
690 setWidgetName(manifest, uiApp);
691 setWidgetIds(manifest, uiApp);
692 setWidgetIcons(uiApp);
693 setAppControlInfo(uiApp, *it);
694 setAppCategory(uiApp);
696 manifest.addUiApplication(uiApp);
699 //default widget content
700 setWidgetExecPath(uiApp);
701 setWidgetName(manifest, uiApp);
702 setWidgetIds(manifest, uiApp);
703 setWidgetIcons(uiApp);
704 setWidgetDescription(manifest);
705 setWidgetManifest(manifest);
706 setWidgetOtherInfo(uiApp);
707 setAppControlsInfo(uiApp);
708 setAppCategory(uiApp);
710 setLiveBoxInfo(manifest);
711 setAccount(manifest);
712 setPrivilege(manifest);
714 manifest.addUiApplication(uiApp);
717 manifest.generate(path);
718 LogDebug("Manifest file serialized");
721 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
722 const std::string &postfix)
724 std::string exec = m_context.locations->getExecFile();
725 if (!postfix.empty()) {
726 exec.append(postfix);
728 LogDebug("exec = " << exec);
729 uiApp.setExec(DPL::FromASCIIString(exec));
732 void TaskManifestFile::setWidgetName(Manifest & manifest,
733 UiApplication & uiApp)
735 bool defaultNameSaved = false;
737 DPL::OptionalString defaultLocale =
738 m_context.widgetConfig.configInfo.defaultlocale;
739 std::pair<DPL::String,
740 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
742 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
744 Locale i = localizedData->first;
745 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
749 DPL::OptionalString name = localizedData->second.name;
750 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
752 //store default locale localized data
753 if (!!defaultLocale && defaultLocale == i) {
754 defaultLocalizedData = *localizedData;
758 if (!!defaultLocale && !defaultNameSaved) {
759 DPL::OptionalString name = defaultLocalizedData.second.name;
760 generateWidgetName(manifest,
762 DPL::OptionalString::Null,
768 void TaskManifestFile::setWidgetIds(Manifest & manifest,
769 UiApplication & uiApp,
770 const std::string &postfix)
773 TizenAppId appid = m_context.widgetConfig.tzAppid;
774 if (!postfix.empty()) {
775 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
777 uiApp.setAppid(appid);
780 if (!!m_context.widgetConfig.guid) {
781 uiApp.setExtraid(*m_context.widgetConfig.guid);
783 if (!appid.empty()) {
784 uiApp.setExtraid(DPL::String(L"http://") + appid);
789 uiApp.setType(DPL::FromASCIIString("webapp"));
790 manifest.setType(L"wgt");
793 void TaskManifestFile::generateWidgetName(Manifest & manifest,
794 UiApplication &uiApp,
795 const DPL::OptionalString& tag,
796 DPL::OptionalString name,
797 bool & defaultNameSaved)
802 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
804 if (!locale.empty()) {
805 uiApp.addLabel(LabelType(*name, *tag));
807 uiApp.addLabel(LabelType(*name));
808 manifest.addLabel(LabelType(*name));
811 defaultNameSaved = true;
812 uiApp.addLabel(LabelType(*name));
813 manifest.addLabel(LabelType(*name));
818 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
820 //TODO this file will need to be updated when user locale preferences
822 bool defaultIconSaved = false;
824 DPL::OptionalString defaultLocale =
825 m_context.widgetConfig.configInfo.defaultlocale;
827 std::vector<Locale> generatedLocales;
828 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
829 m_context.widgetConfig.localizationData.icons;
831 //reversed: last <icon> has highest priority to be writen to manifest if it
832 // has given locale (TODO: why was that working that way?)
833 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
834 icon = icons.rbegin();
835 icon != icons.rend();
838 FOREACH(locale, icon->availableLocales)
840 if (std::find(generatedLocales.begin(), generatedLocales.end(),
841 *locale) != generatedLocales.end())
843 LogDebug("Skipping - has that locale - already in manifest");
846 generatedLocales.push_back(*locale);
849 DPL::OptionalString tag = getLangTag(*locale); // translate en ->
855 generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
858 if (!!defaultLocale && !defaultIconSaved) {
859 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
865 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
866 const DPL::OptionalString& tag,
867 const DPL::String& language,
868 bool & defaultIconSaved)
872 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
874 defaultIconSaved = true;
877 DPL::String iconText;
878 iconText += getIconTargetFilename(language);
880 if (!locale.empty()) {
881 uiApp.addIcon(IconType(iconText, locale));
883 uiApp.addIcon(IconType(iconText));
885 std::ostringstream iconPath;
886 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
887 iconPath << getIconTargetFilename(locale);
888 m_context.job->SendProgressIconPath(iconPath.str());
891 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
893 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
895 Locale i = localizedData->first;
896 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
900 DPL::OptionalString description = localizedData->second.description;
901 generateWidgetDescription(manifest, tag, description);
905 void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
906 const DPL::OptionalString& tag,
907 DPL::OptionalString description)
912 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
913 if (!locale.empty()) {
914 manifest.addDescription(DescriptionType(*description, locale));
916 manifest.addDescription(DescriptionType(*description));
919 manifest.addDescription(DescriptionType(*description));
924 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
926 manifest.setPackage(m_context.widgetConfig.tzPkgid);
928 if (!!m_context.widgetConfig.version) {
929 manifest.setVersion(*m_context.widgetConfig.version);
931 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
932 *m_context.widgetConfig.configInfo.authorEmail : L"");
933 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
934 *m_context.widgetConfig.configInfo.authorHref : L"");
935 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
936 *m_context.widgetConfig.configInfo.authorName : L"");
937 manifest.addAuthor(Author(email, href, L"", name));
940 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
942 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
944 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), STR_NODISPLAY)) {
945 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), STR_TRUE)) {
946 uiApp.setNodisplay(true);
947 uiApp.setTaskmanage(false);
949 uiApp.setNodisplay(false);
950 uiApp.setTaskmanage(true);
955 //There is no "X-TIZEN-PackageType=wgt"
956 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
957 // DPL::ToUTF8String(*widgetID).c_str()
958 //There is no Comment in pkgmgr "Comment=Widget application"
959 //that were in desktop file
962 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
964 WrtDB::ConfigParserData::AppControlInfoList appControlList =
965 m_context.widgetConfig.configInfo.appControlList;
967 if (appControlList.empty()) {
968 LogInfo("Widget doesn't contain app control");
972 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
973 FOREACH(it, appControlList) {
974 setAppControlInfo(uiApp, *it);
978 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
979 const WrtDB::ConfigParserData::AppControlInfo & service)
981 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
982 AppControl appControl;
983 if (!service.m_operation.empty()) {
984 appControl.addOperation(service.m_operation); //TODO: encapsulation?
986 if (!service.m_uriList.empty()) {
987 FOREACH(uri, service.m_uriList) {
988 appControl.addUri(*uri);
991 if (!service.m_mimeList.empty()) {
992 FOREACH(mime, service.m_mimeList) {
993 appControl.addMime(*mime);
996 uiApp.addAppControl(appControl);
999 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
1001 WrtDB::ConfigParserData::CategoryList categoryList =
1002 m_context.widgetConfig.configInfo.categoryList;
1004 if (categoryList.empty()) {
1005 LogInfo("Widget doesn't contain application category");
1008 FOREACH(it, categoryList) {
1009 if (!(*it).empty()) {
1010 uiApp.addAppCategory(*it);
1015 void TaskManifestFile::setMetadata(UiApplication &uiApp)
1017 WrtDB::ConfigParserData::MetadataList metadataList =
1018 m_context.widgetConfig.configInfo.metadataList;
1020 if (metadataList.empty()) {
1021 LogInfo("Web application doesn't contain metadata");
1024 FOREACH(it, metadataList) {
1025 MetadataType metadataType(it->key, it->value);
1026 uiApp.addMetadata(metadataType);
1030 void TaskManifestFile::stepAbortParseManifest()
1032 LogError("[Parse Manifest] Abroting....");
1034 int code = pkgmgr_parser_parse_manifest_for_uninstallation(
1035 DPL::ToUTF8String(manifest_file).c_str(), NULL);
1038 LogWarning("Manifest parser error: " << code);
1039 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
1041 int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
1043 LogWarning("No manifest file found: " << manifest_file);
1047 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
1049 FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
1050 LogInfo("setLiveBoxInfo");
1051 LiveBoxInfo liveBox;
1052 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
1053 DPL::String appid = m_context.widgetConfig.tzAppid;
1055 if (ConfigInfo->m_liveboxId != L"") {
1056 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
1057 if (found != std::string::npos) {
1058 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
1059 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
1061 DPL::String liveboxId =
1062 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1063 liveBox.setLiveboxId(liveboxId);
1066 DPL::String liveboxId =
1067 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1068 liveBox.setLiveboxId(liveboxId);
1072 if (ConfigInfo->m_primary != L"") {
1073 liveBox.setPrimary(ConfigInfo->m_primary);
1076 if (ConfigInfo->m_updatePeriod != L"") {
1077 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
1080 std::list<std::pair<DPL::String, DPL::String> > boxLabelList;
1081 if (!ConfigInfo->m_label.empty()) {
1082 FOREACH(im, ConfigInfo->m_label) {
1083 std::pair<DPL::String, DPL::String> boxSize;
1084 Locale i = (*im).first;
1085 // translate en -> en_US etc
1086 DPL::OptionalString tag = getLangTag(i);
1090 boxSize.first = (*tag);
1091 boxSize.second = (*im).second;
1092 boxLabelList.push_back(boxSize);
1094 liveBox.setLabel(boxLabelList);
1097 DPL::String defaultLocale =
1098 DPL::FromUTF8String(m_context.locations->getPackageInstallationDir()) +
1099 DPL::String(L"/res/wgt/");
1101 if (ConfigInfo->m_icon != L"") {
1103 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1105 ConfigInfo->m_liveboxId + DPL::String(L".icon.png");
1106 liveBox.setIcon(icon);
1109 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1110 ConfigInfo->m_boxInfo.m_boxSize.empty())
1112 LogInfo("Widget doesn't contain box");
1116 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1117 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1119 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1121 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1123 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1127 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1128 std::string boxType;
1129 if (ConfigInfo->m_type == L"") {
1130 // in case of default livebox
1131 boxType = web_provider_livebox_get_default_type();
1133 boxType = DPL::ToUTF8String(ConfigInfo->m_type);
1136 int box_scrollable =
1137 web_provider_plugin_get_box_scrollable(boxType.c_str());
1139 if (box_scrollable) {
1140 box.boxMouseEvent = L"true";
1142 box.boxMouseEvent = L"false";
1145 box.boxMouseEvent = L"false";
1148 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1149 box.boxTouchEffect = L"true";
1151 box.boxTouchEffect= L"false";
1154 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
1155 ConfigInfo->m_boxInfo.m_boxSize;
1156 FOREACH(it, boxSizeList) {
1157 if (!(*it).m_preview.empty()) {
1159 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1161 ConfigInfo->m_liveboxId + DPL::String(L".") +
1162 (*it).m_size + DPL::String(L".preview.png");
1164 box.boxSize.push_back((*it));
1167 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1168 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1169 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1171 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1172 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1174 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1176 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1178 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1179 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1181 liveBox.setBox(box);
1183 manifest.addLivebox(liveBox);
1187 void TaskManifestFile::setAccount(Manifest& manifest)
1189 WrtDB::ConfigParserData::AccountProvider account =
1190 m_context.widgetConfig.configInfo.accountProvider;
1192 AccountProviderType provider;
1194 if (account.m_iconSet.empty()) {
1195 LogInfo("Widget doesn't contain Account");
1198 if (account.m_multiAccountSupport) {
1199 provider.multiAccount = L"ture";
1201 provider.multiAccount = L"false";
1203 provider.appid = m_context.widgetConfig.tzAppid;
1205 FOREACH(it, account.m_iconSet) {
1206 std::pair<DPL::String, DPL::String> icon;
1208 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1209 icon.first = L"account";
1210 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1211 icon.first = L"account-small";
1213 icon.second = it->second;
1215 provider.icon.push_back(icon);
1218 FOREACH(it, account.m_displayNameSet) {
1219 provider.name.push_back(LabelType(it->second, it->first));
1222 FOREACH(it, account.m_capabilityList) {
1223 provider.capability.push_back(*it);
1226 Account accountInfo;
1227 accountInfo.addAccountProvider(provider);
1228 manifest.addAccount(accountInfo);
1231 void TaskManifestFile::setPrivilege(Manifest& manifest)
1233 WrtDB::ConfigParserData::PrivilegeList privileges =
1234 m_context.widgetConfig.configInfo.privilegeList;
1236 PrivilegeType privilege;
1238 FOREACH(it, privileges)
1240 privilege.addPrivilegeName(it->name);
1243 manifest.addPrivileges(privilege);
1246 } //namespace WidgetInstall