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/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>
54 #include <dpl/utils/path.h>
56 #include <installer_log.h>
58 #define DEFAULT_ICON_NAME "icon.png"
59 #define DEFAULT_PREVIEW_NAME "preview.png"
61 using namespace WrtDB;
64 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
66 const char* const STR_TRUE = "true";
67 const char* const STR_FALSE = "false";
68 const char* const STR_NODISPLAY = "nodisplay";
70 LanguageTagMap getLanguageTagMap()
74 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
75 #include "languages.def"
81 DPL::OptionalString getLangTag(const DPL::String& tag)
83 static LanguageTagMap TagsMap =
86 DPL::String langTag = tag;
88 _D("Trying to map language tag: %ls", langTag.c_str());
89 size_t pos = langTag.find_first_of(L'_');
90 if (pos != DPL::String::npos) {
93 DPL::OptionalString ret;
95 LanguageTagMap::iterator it = TagsMap.find(langTag);
96 if (it != TagsMap.end()) {
98 _D("Mapping IANA Language tag to language tag: %ls -> %ls", langTag.c_str(), (*ret).c_str());
106 namespace WidgetInstall {
107 const char * TaskManifestFile::encoding = "UTF-8";
109 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
110 DPL::TaskDecl<TaskManifestFile>(this),
114 if (m_context.isUpdateMode) {
115 // for widget update.
116 AddStep(&TaskManifestFile::stepBackupIconFiles);
117 AddStep(&TaskManifestFile::stepCopyIconFiles);
118 AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
119 AddStep(&TaskManifestFile::stepCreateExecFile);
120 AddStep(&TaskManifestFile::stepGenerateManifest);
122 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
124 AddStep(&TaskManifestFile::stepCopyIconFiles);
125 AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
126 AddStep(&TaskManifestFile::stepCreateExecFile);
127 AddStep(&TaskManifestFile::stepGenerateManifest);
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 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
154 // app-control widgets
155 unsigned int indexMax = 0;
156 FOREACH(it, m_context.widgetConfig.configInfo.appControlList) {
157 if (it->m_index > indexMax) {
158 indexMax = it->m_index;
162 for (std::size_t i = 1; i <= indexMax; ++i) {
163 std::stringstream postfix;
164 postfix << AppControlPrefix::PROCESS_PREFIX << i;
165 std::string controlExec = exec;
166 controlExec.append(postfix.str());
168 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0) {
171 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
177 _D("link -s %s %s", clientExeStr.c_str(), exec.c_str());
179 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
183 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
186 // creation of box symlink
187 ConfigParserData::LiveboxList& liveboxList =
188 m_context.widgetConfig.configInfo.m_livebox;
189 if (!liveboxList.empty()) {
190 std::string boxExec = "/usr/bin/WebProcess";
191 std::string boxSymlink = m_context.locations->getExecFile();
192 boxSymlink += ".d-box";
195 if (symlink(boxExec.c_str(), boxSymlink.c_str()) != 0) {
198 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
203 m_context.job->UpdateProgress(
204 InstallerContext::INSTALL_CREATE_EXECFILE,
205 "Widget execfile creation Finished");
208 void TaskManifestFile::stepCopyIconFiles()
212 //This function copies icon to desktop icon path. For each locale avaliable
213 //which there is at least one icon in widget for, icon file is copied.
214 //Coping prioritize last positions when coping. If there is several icons
215 //with given locale, the one, that will be copied, will be icon
216 //which is declared by <icon> tag later than the others in config.xml of
219 std::vector<Locale> generatedLocales;
221 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
222 m_context.widgetConfig.localizationData.icons;
224 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_iterator
225 icon = icons.begin();
229 DPL::String src = icon->src;
230 FOREACH(locale, icon->availableLocales)
232 _D("Icon for locale: %ls is: %ls", (*locale).c_str(), src.c_str());
234 if (std::find(generatedLocales.begin(), generatedLocales.end(),
235 *locale) != generatedLocales.end())
237 _D("Skipping - has that locale");
240 generatedLocales.push_back(*locale);
243 DPL::Utils::Path sourceFile(m_context.locations->getSourceDir());
244 if (!locale->empty()) {
245 sourceFile /= "locales";
246 sourceFile /= *locale;
250 DPL::Utils::Path targetFile(GlobalConfig::GetUserWidgetDesktopIconPath());
251 targetFile /= getIconTargetFilename(*locale, sourceFile.Extension());
253 if (m_context.widgetConfig.packagingType ==
254 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
256 m_context.locations->setIconTargetFilenameForLocale(
257 targetFile.Fullpath());
260 _D("Copying icon: %s -> %s", sourceFile.Filename().c_str(), targetFile.Filename().c_str());
262 icon_list.push_back(targetFile.Fullpath());
266 DPL::FileInput input(sourceFile.Fullpath());
267 DPL::FileOutput output(targetFile.Fullpath());
268 DPL::Copy(&input, &output);
271 Catch(DPL::FileInput::Exception::Base)
273 // Error while opening or closing source file
274 //ReThrowMsg(InstallerException::CopyIconFailed,
275 // sourceFile.str());
276 _E("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());
285 _E("Copying widget's icon failed. Widget's icon will not be" \
286 "available from Main Screen");
289 Catch(DPL::CopyFailed)
291 // Error while copying
292 //ReThrowMsg(InstallerException::CopyIconFailed,
293 // targetFile.str());
294 _E("Copying widget's icon failed. Widget's icon will not be" \
295 "available from Main Screen");
300 m_context.job->UpdateProgress(
301 InstallerContext::INSTALL_COPY_ICONFILE,
302 "Widget iconfile copy Finished");
305 void TaskManifestFile::stepCopyLiveboxFiles()
307 _D("Copy Livebox Files");
309 using namespace WrtDB;
310 ConfigParserData &data = m_context.widgetConfig.configInfo;
311 ConfigParserData::LiveboxList liveBoxList = data.m_livebox;
313 if (liveBoxList.size() <= 0) {
317 std::ostringstream sourceFile;
318 std::ostringstream targetFile;
320 FOREACH (boxIt, liveBoxList) {
321 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
322 (**boxIt).m_boxInfo.m_boxSize;
323 FOREACH (sizeIt, boxSizeList) {
324 std::string preview = DPL::ToUTF8String((*sizeIt).m_preview);
325 if (preview.empty()) {
328 sourceFile << m_context.locations->getSourceDir() << "/";
329 sourceFile << preview;
330 targetFile << m_context.locations->getSharedDataDir() << "/";
331 targetFile << (**boxIt).m_liveboxId << ".";
332 targetFile << DPL::ToUTF8String((*sizeIt).m_size) << "." << DEFAULT_PREVIEW_NAME;
334 copyDynamicBoxFile(sourceFile.str(), targetFile.str());
336 // clear stream objects
340 // check this livebox has icon element
341 std::string icon = DPL::ToUTF8String((**boxIt).m_icon);
345 sourceFile << m_context.locations->getSourceDir() << "/";
347 targetFile << m_context.locations->getSharedDataDir() << "/";
348 targetFile << (**boxIt).m_liveboxId << "." << DEFAULT_ICON_NAME;
350 copyDynamicBoxFile(sourceFile.str(), targetFile.str());
352 // clear stream objects
356 m_context.job->UpdateProgress(
357 InstallerContext::INSTALL_COPY_LIVEBOX_FILES,
358 "Livebox files copy Finished");
361 void TaskManifestFile::copyDynamicBoxFile(const std::string& sourceFile,
362 const std::string& targetFile)
366 DPL::FileInput input(sourceFile);
367 DPL::FileOutput output(targetFile);
368 DPL::Copy(&input, &output);
370 Catch(DPL::Exception)
372 _E("Copying Dynamic Box File Failed. %s to %s", sourceFile.c_str(), targetFile.c_str());
373 ReThrowMsg(Exceptions::DynamicBoxFailed, "Dynamic Box File Copy Failed.");
377 bool TaskManifestFile::addBoxUiApplication(Manifest& manifest)
380 std::string postfix = ".d-box";
381 static bool isAdded = false;
386 _D("UiApplication for d-box is already added");
389 uiApp.setNodisplay(true);
390 uiApp.setTaskmanage(false);
391 uiApp.setMultiple(false);
392 setWidgetName(manifest, uiApp);
393 setWidgetIcons(uiApp);
395 // appid for box is like [webapp id].d-box
396 setWidgetIds(manifest, uiApp, postfix);
397 // executable path for box is like [app path]/bin/[webapp id].d-box
398 setWidgetExecPath(uiApp, postfix);
399 manifest.addUiApplication(uiApp);
404 Catch(DPL::Exception)
406 _E("Adding UiApplication on xml is failed.");
412 void TaskManifestFile::stepBackupIconFiles()
414 _D("Backup Icon Files");
416 backup_dir << m_context.locations->getBackupDir() << "/";
420 m_context.job->UpdateProgress(
421 InstallerContext::INSTALL_BACKUP_ICONFILE,
422 "New Widget icon file backup Finished");
425 void TaskManifestFile::stepAbortIconFiles()
427 _D("Abrot Icon Files");
428 FOREACH(it, icon_list)
430 _D("Remove Update Icon : %s", (*it).c_str());
431 unlink((*it).c_str());
434 std::ostringstream b_icon_dir;
435 b_icon_dir << backup_dir.str() << "icons";
437 std::list<std::string> fileList;
438 getFileList(b_icon_dir.str().c_str(), fileList);
440 FOREACH(back_icon, fileList)
442 std::ostringstream res_file;
443 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
444 res_file << "/" << (*back_icon);
446 std::ostringstream backup_file;
447 backup_file << b_icon_dir.str() << "/" << (*back_icon);
451 DPL::FileInput input(backup_file.str());
452 DPL::FileOutput output(res_file.str());
453 DPL::Copy(&input, &output);
455 Catch(DPL::FileInput::Exception::Base)
457 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
460 Catch(DPL::FileOutput::Exception::Base)
462 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
464 Catch(DPL::CopyFailed)
466 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
471 DPL::String TaskManifestFile::getIconTargetFilename(
472 const DPL::String& languageTag, const std::string & ext) const
474 DPL::OStringStream filename;
475 TizenAppId appid = m_context.widgetConfig.tzAppid;
477 filename << DPL::ToUTF8String(appid).c_str();
479 if (!languageTag.empty()) {
480 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
486 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
488 if (locale.empty()) {
489 filename << L"." << languageTag;
491 filename << L"." << locale;
497 filename << L"." + DPL::FromUTF8String(ext);
499 return filename.str();
502 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
503 const DPL::String& key,
504 const DPL::String& languageTag)
507 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
510 if (!locale.empty()) {
511 file << "[" << locale << "]";
516 void TaskManifestFile::backupIconFiles()
518 _D("Backup Icon Files");
520 std::ostringstream b_icon_dir;
521 b_icon_dir << backup_dir.str() << "icons";
523 _D("Create icon backup folder : %s", b_icon_dir.str().c_str());
524 WrtUtilMakeDir(b_icon_dir.str());
526 std::list<std::string> fileList;
527 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
528 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
530 FOREACH(it, fileList)
532 if (0 == (strncmp((*it).c_str(), appid.c_str(),
533 strlen(appid.c_str()))))
535 std::ostringstream icon_file, backup_icon;
536 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
537 icon_file << "/" << (*it);
539 backup_icon << b_icon_dir.str() << "/" << (*it);
541 _D("Backup icon file %s to %s", icon_file.str().c_str(), backup_icon.str().c_str());
544 DPL::FileInput input(icon_file.str());
545 DPL::FileOutput output(backup_icon.str());
546 DPL::Copy(&input, &output);
548 Catch(DPL::FileInput::Exception::Base)
550 _E("Backup Desktop File Failed.");
551 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
554 Catch(DPL::FileOutput::Exception::Base)
556 _E("Backup Desktop File Failed.");
557 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
559 Catch(DPL::CopyFailed)
561 _E("Backup Desktop File Failed.");
562 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
564 unlink((*it).c_str());
569 void TaskManifestFile::getFileList(const char* path,
570 std::list<std::string> &list)
572 DIR* dir = opendir(path);
574 _E("icon directory doesn't exist");
575 ThrowMsg(Exceptions::FileOperationFailed, path);
579 struct dirent *result;
582 for (return_code = readdir_r(dir, &entry, &result);
583 result != NULL && return_code == 0;
584 return_code = readdir_r(dir, &entry, &result))
586 if (strcmp(entry.d_name, ".") == 0 ||
587 strcmp(entry.d_name, "..") == 0)
591 std::string file_name = entry.d_name;
592 list.push_back(file_name);
595 if (return_code != 0 || errno != 0) {
596 _E("readdir_r() failed with %s", DPL::GetErrnoString().c_str());
599 if (-1 == closedir(dir)) {
600 _E("Failed to close dir: %s with error: %s", path, DPL::GetErrnoString().c_str());
604 void TaskManifestFile::stepGenerateManifest()
606 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
607 manifest_name = pkgid + L".xml";
608 manifest_file += L"/tmp/" + manifest_name;
610 //libxml - init and check
611 LibxmlSingleton::Instance().init();
613 writeManifest(manifest_file);
615 std::ostringstream destFile;
616 if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
617 destFile << WrtDB::GlobalConfig::GetPreloadManifestPath() << "/";
619 destFile << WrtDB::GlobalConfig::GetManifestPath() << "/";
622 destFile << DPL::ToUTF8String(manifest_name);
623 commit_manifest = destFile.str();
624 _D("Commiting manifest file : %s", commit_manifest.c_str());
628 m_context.job->UpdateProgress(
629 InstallerContext::INSTALL_CREATE_MANIFEST,
630 "Widget Manifest Creation Finished");
633 void TaskManifestFile::commitManifest()
636 if (!(m_context.mode.rootPath == InstallMode::RootPath::RO &&
637 m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
638 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
639 _D("cp %ls %s", manifest_file.c_str(), commit_manifest.c_str());
641 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
642 DPL::FileOutput output(commit_manifest);
643 DPL::Copy(&input, &output);
644 _D("Manifest writen to: %s", commit_manifest.c_str());
647 unlink((DPL::ToUTF8String(manifest_file)).c_str());
648 manifest_file = DPL::FromUTF8String(commit_manifest);
652 void TaskManifestFile::writeManifest(const DPL::String & path)
654 _D("Generating manifest file : %ls", path.c_str());
658 #ifdef MULTIPROCESS_SERVICE_SUPPORT
659 //default widget content
660 std::stringstream postfix;
661 // index 0 is reserved
662 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
663 setWidgetExecPath(uiApp, postfix.str());
664 setWidgetName(manifest, uiApp);
665 setWidgetIds(manifest, uiApp);
666 setWidgetIcons(uiApp);
667 setWidgetDescription(manifest);
668 setWidgetManifest(manifest);
669 setWidgetOtherInfo(uiApp);
670 setAppCategory(uiApp);
672 setLiveBoxInfo(manifest);
673 setAccount(manifest);
674 setPrivilege(manifest);
675 manifest.addUiApplication(uiApp);
677 //app-control content
678 ConfigParserData::AppControlInfoList appControlList =
679 m_context.widgetConfig.configInfo.appControlList;
680 FOREACH(it, appControlList) {
683 uiApp.setTaskmanage(true);
684 uiApp.setNodisplay(true);
685 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
686 uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition);
687 uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
689 std::stringstream postfix;
690 postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
691 setWidgetExecPath(uiApp, postfix.str());
692 setWidgetName(manifest, uiApp);
693 setWidgetIds(manifest, uiApp);
694 setWidgetIcons(uiApp);
695 setAppControlInfo(uiApp, *it);
696 setAppCategory(uiApp);
698 manifest.addUiApplication(uiApp);
701 //default widget content
702 setWidgetExecPath(uiApp);
703 setWidgetName(manifest, uiApp);
704 setWidgetIds(manifest, uiApp);
705 setWidgetIcons(uiApp);
706 setWidgetDescription(manifest);
707 setWidgetManifest(manifest);
708 setWidgetOtherInfo(uiApp);
709 setAppControlsInfo(uiApp);
710 setAppCategory(uiApp);
712 setLiveBoxInfo(manifest);
713 setAccount(manifest);
714 setPrivilege(manifest);
716 manifest.addUiApplication(uiApp);
719 manifest.generate(path);
720 _D("Manifest file serialized");
723 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
724 const std::string &postfix)
726 std::string exec = m_context.locations->getExecFile();
727 if (!postfix.empty()) {
728 exec.append(postfix);
730 _D("exec = %s", exec.c_str());
731 uiApp.setExec(DPL::FromASCIIString(exec));
734 void TaskManifestFile::setWidgetName(Manifest & manifest,
735 UiApplication & uiApp)
737 bool defaultNameSaved = false;
739 DPL::OptionalString defaultLocale =
740 m_context.widgetConfig.configInfo.defaultlocale;
741 std::pair<DPL::String,
742 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
744 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
746 Locale i = localizedData->first;
747 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
751 DPL::OptionalString name = localizedData->second.name;
752 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
754 //store default locale localized data
755 if (!!defaultLocale && defaultLocale == i) {
756 defaultLocalizedData = *localizedData;
760 if (!!defaultLocale && !defaultNameSaved) {
761 DPL::OptionalString name = defaultLocalizedData.second.name;
762 generateWidgetName(manifest,
764 DPL::OptionalString::Null,
770 void TaskManifestFile::setWidgetIds(Manifest & manifest,
771 UiApplication & uiApp,
772 const std::string &postfix)
775 TizenAppId appid = m_context.widgetConfig.tzAppid;
776 if (!postfix.empty()) {
777 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
779 uiApp.setAppid(appid);
782 if (!!m_context.widgetConfig.guid) {
783 uiApp.setExtraid(*m_context.widgetConfig.guid);
785 if (!appid.empty()) {
786 uiApp.setExtraid(DPL::String(L"http://") + appid);
791 uiApp.setType(DPL::FromASCIIString("webapp"));
792 manifest.setType(L"wgt");
795 void TaskManifestFile::generateWidgetName(Manifest & manifest,
796 UiApplication &uiApp,
797 const DPL::OptionalString& tag,
798 DPL::OptionalString name,
799 bool & defaultNameSaved)
804 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
806 if (!locale.empty()) {
807 uiApp.addLabel(LabelType(*name, *tag));
809 uiApp.addLabel(LabelType(*name));
810 manifest.addLabel(LabelType(*name));
813 defaultNameSaved = true;
814 uiApp.addLabel(LabelType(*name));
815 manifest.addLabel(LabelType(*name));
820 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
822 //TODO this file will need to be updated when user locale preferences
824 bool defaultIconSaved = false;
826 DPL::OptionalString defaultLocale =
827 m_context.widgetConfig.configInfo.defaultlocale;
829 std::vector<Locale> generatedLocales;
830 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
831 m_context.widgetConfig.localizationData.icons;
833 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_iterator
834 icon = icons.begin();
838 FOREACH(locale, icon->availableLocales)
840 if (std::find(generatedLocales.begin(), generatedLocales.end(),
841 *locale) != generatedLocales.end())
843 _D("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, DPL::Utils::Path(icon->src).Extension(), defaultIconSaved);
858 if (!!defaultLocale && !defaultIconSaved) {
859 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
866 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
867 const DPL::OptionalString& tag,
868 const DPL::String& language,
869 const std::string & extension,
870 bool & defaultIconSaved)
874 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
876 defaultIconSaved = true;
879 DPL::String iconText;
880 iconText += getIconTargetFilename(language, extension);
882 if (!locale.empty()) {
883 uiApp.addIcon(IconType(iconText, locale));
885 uiApp.addIcon(IconType(iconText));
887 std::ostringstream iconPath;
888 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
889 iconPath << getIconTargetFilename(locale, extension);
890 m_context.job->SendProgressIconPath(iconPath.str());
893 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
895 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
897 Locale i = localizedData->first;
898 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
902 DPL::OptionalString description = localizedData->second.description;
903 generateWidgetDescription(manifest, tag, description);
907 void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
908 const DPL::OptionalString& tag,
909 DPL::OptionalString description)
914 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
915 if (!locale.empty()) {
916 manifest.addDescription(DescriptionType(*description, locale));
918 manifest.addDescription(DescriptionType(*description));
921 manifest.addDescription(DescriptionType(*description));
926 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
928 manifest.setPackage(m_context.widgetConfig.tzPkgid);
930 if (!!m_context.widgetConfig.version) {
931 manifest.setVersion(*m_context.widgetConfig.version);
933 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
934 *m_context.widgetConfig.configInfo.authorEmail : L"");
935 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
936 *m_context.widgetConfig.configInfo.authorHref : L"");
937 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
938 *m_context.widgetConfig.configInfo.authorName : L"");
939 manifest.addAuthor(Author(email, href, L"", name));
941 if (!m_context.callerPkgId.empty()) {
942 manifest.setStoreClientId(m_context.callerPkgId);
946 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
948 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
950 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), STR_NODISPLAY)) {
951 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), STR_TRUE)) {
952 uiApp.setNodisplay(true);
953 uiApp.setTaskmanage(false);
955 uiApp.setNodisplay(false);
956 uiApp.setTaskmanage(true);
961 //There is no "X-TIZEN-PackageType=wgt"
962 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
963 // DPL::ToUTF8String(*widgetID).c_str()
964 //There is no Comment in pkgmgr "Comment=Widget application"
965 //that were in desktop file
968 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
970 WrtDB::ConfigParserData::AppControlInfoList appControlList =
971 m_context.widgetConfig.configInfo.appControlList;
973 if (appControlList.empty()) {
974 _D("Widget doesn't contain app control");
978 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
979 FOREACH(it, appControlList) {
980 setAppControlInfo(uiApp, *it);
984 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
985 const WrtDB::ConfigParserData::AppControlInfo & service)
987 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
988 AppControl appControl;
989 if (!service.m_operation.empty()) {
990 appControl.addOperation(service.m_operation); //TODO: encapsulation?
992 if (!service.m_uriList.empty()) {
993 FOREACH(uri, service.m_uriList) {
994 appControl.addUri(*uri);
997 if (!service.m_mimeList.empty()) {
998 FOREACH(mime, service.m_mimeList) {
999 appControl.addMime(*mime);
1002 uiApp.addAppControl(appControl);
1005 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
1007 WrtDB::ConfigParserData::CategoryList categoryList =
1008 m_context.widgetConfig.configInfo.categoryList;
1010 if (categoryList.empty()) {
1011 _D("Widget doesn't contain application category");
1014 FOREACH(it, categoryList) {
1015 if (!(*it).empty()) {
1016 uiApp.addAppCategory(*it);
1021 void TaskManifestFile::setMetadata(UiApplication &uiApp)
1023 WrtDB::ConfigParserData::MetadataList metadataList =
1024 m_context.widgetConfig.configInfo.metadataList;
1026 if (metadataList.empty()) {
1027 _D("Web application doesn't contain metadata");
1030 FOREACH(it, metadataList) {
1031 MetadataType metadataType(it->key, it->value);
1032 uiApp.addMetadata(metadataType);
1036 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
1038 ConfigParserData::LiveboxList& liveboxList =
1039 m_context.widgetConfig.configInfo.m_livebox;
1041 if (liveboxList.empty()) {
1046 if (!addBoxUiApplication(manifest)) {
1047 _D("error during adding UiApplication for d-box");
1051 FOREACH(it, liveboxList) {
1052 LogDebug("setLiveBoxInfo");
1053 LiveBoxInfo liveBox;
1054 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
1055 DPL::String appid = m_context.widgetConfig.tzAppid;
1057 if (ConfigInfo->m_liveboxId != L"") {
1058 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
1059 if (found != std::string::npos) {
1060 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
1061 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
1063 DPL::String liveboxId =
1064 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1065 liveBox.setLiveboxId(liveboxId);
1068 DPL::String liveboxId =
1069 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1070 liveBox.setLiveboxId(liveboxId);
1074 if (ConfigInfo->m_primary != L"") {
1075 liveBox.setPrimary(ConfigInfo->m_primary);
1078 if (ConfigInfo->m_updatePeriod != L"") {
1079 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
1082 std::list<std::pair<DPL::String, DPL::String> > boxLabelList;
1083 if (!ConfigInfo->m_label.empty()) {
1084 FOREACH(im, ConfigInfo->m_label) {
1085 std::pair<DPL::String, DPL::String> boxSize;
1086 Locale i = (*im).first;
1087 // translate en -> en_US etc
1088 DPL::OptionalString tag = getLangTag(i);
1092 boxSize.first = (*tag);
1093 boxSize.second = (*im).second;
1094 boxLabelList.push_back(boxSize);
1096 liveBox.setLabel(boxLabelList);
1099 DPL::String defaultLocale =
1100 DPL::FromUTF8String(m_context.locations->getPackageInstallationDir()) +
1101 DPL::String(L"/res/wgt/");
1103 if (ConfigInfo->m_icon != L"") {
1105 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1107 ConfigInfo->m_liveboxId + DPL::String(L".icon.png");
1108 liveBox.setIcon(icon);
1111 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1112 ConfigInfo->m_boxInfo.m_boxSize.empty())
1114 _D("Widget doesn't contain box");
1118 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1119 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1121 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1123 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1125 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1129 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1130 std::string boxType;
1131 if (ConfigInfo->m_type == L"") {
1132 // in case of default livebox
1133 boxType = web_provider_livebox_get_default_type();
1135 boxType = DPL::ToUTF8String(ConfigInfo->m_type);
1138 int box_scrollable =
1139 web_provider_plugin_get_box_scrollable(boxType.c_str());
1141 if (box_scrollable) {
1142 box.boxMouseEvent = L"true";
1144 box.boxMouseEvent = L"false";
1147 box.boxMouseEvent = L"false";
1150 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1151 box.boxTouchEffect = L"true";
1153 box.boxTouchEffect= L"false";
1156 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
1157 ConfigInfo->m_boxInfo.m_boxSize;
1158 FOREACH(it, boxSizeList) {
1159 if (!(*it).m_preview.empty()) {
1161 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1163 ConfigInfo->m_liveboxId + DPL::String(L".") +
1164 (*it).m_size + DPL::String(L".preview.png");
1166 box.boxSize.push_back((*it));
1169 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1170 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1171 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1173 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1174 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1176 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1178 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1180 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1181 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1183 liveBox.setBox(box);
1185 manifest.addLivebox(liveBox);
1189 void TaskManifestFile::setAccount(Manifest& manifest)
1191 WrtDB::ConfigParserData::AccountProvider account =
1192 m_context.widgetConfig.configInfo.accountProvider;
1194 AccountProviderType provider;
1196 if (account.m_iconSet.empty()) {
1197 _D("Widget doesn't contain Account");
1200 if (account.m_multiAccountSupport) {
1201 provider.multiAccount = L"true";
1203 provider.multiAccount = L"false";
1205 provider.appid = m_context.widgetConfig.tzAppid;
1207 FOREACH(it, account.m_iconSet) {
1208 std::pair<DPL::String, DPL::String> icon;
1210 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1211 icon.first = L"account";
1212 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1213 icon.first = L"account-small";
1215 icon.second = it->second;
1217 provider.icon.push_back(icon);
1220 FOREACH(it, account.m_displayNameSet) {
1221 provider.name.push_back(LabelType(it->second, it->first));
1224 FOREACH(it, account.m_capabilityList) {
1225 provider.capability.push_back(*it);
1228 Account accountInfo;
1229 accountInfo.addAccountProvider(provider);
1230 manifest.addAccount(accountInfo);
1233 void TaskManifestFile::setPrivilege(Manifest& manifest)
1235 WrtDB::ConfigParserData::PrivilegeList privileges =
1236 m_context.widgetConfig.configInfo.privilegeList;
1238 PrivilegeType privilege;
1240 FOREACH(it, privileges)
1242 privilege.addPrivilegeName(it->name);
1245 manifest.addPrivileges(privilege);
1248 void TaskManifestFile::StartStep()
1253 void TaskManifestFile::EndStep()
1257 } //namespace WidgetInstall