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::stepCopyAccountIconFiles);
120 AddStep(&TaskManifestFile::stepCreateExecFile);
121 AddStep(&TaskManifestFile::stepCreateLinkNPPluginsFile);
122 AddStep(&TaskManifestFile::stepGenerateManifest);
123 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
125 AddStep(&TaskManifestFile::stepCopyIconFiles);
126 AddStep(&TaskManifestFile::stepCopyLiveboxFiles);
127 AddStep(&TaskManifestFile::stepCopyAccountIconFiles);
128 AddStep(&TaskManifestFile::stepCreateExecFile);
129 AddStep(&TaskManifestFile::stepCreateLinkNPPluginsFile);
130 AddStep(&TaskManifestFile::stepGenerateManifest);
134 TaskManifestFile::~TaskManifestFile()
137 void TaskManifestFile::stepCreateExecFile()
139 std::string exec = m_context.locations->getExecFile();
140 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
142 #ifdef MULTIPROCESS_SERVICE_SUPPORT
144 std::stringstream postfix;
145 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
146 std::string controlExec = exec;
147 controlExec.append(postfix.str());
150 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0)
154 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
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 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
180 _D("link -s %s %s", clientExeStr.c_str(), exec.c_str());
182 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
186 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
189 // creation of box symlink
190 ConfigParserData::LiveboxList& liveboxList =
191 m_context.widgetConfig.configInfo.m_livebox;
192 if (!liveboxList.empty()) {
193 std::string boxExec = "/usr/bin/WebProcess";
194 std::string boxSymlink = m_context.locations->getExecFile();
195 boxSymlink += ".d-box";
198 if (symlink(boxExec.c_str(), boxSymlink.c_str()) != 0) {
201 _E("Failed to make a symbolic name for a file [%s]", DPL::GetErrnoString(error).c_str());
206 m_context.job->UpdateProgress(
207 InstallerContext::INSTALL_CREATE_EXECFILE,
208 "Widget execfile creation Finished");
211 void TaskManifestFile::stepCreateLinkNPPluginsFile()
213 _D("stepCreateLinkNPPluginsFile");
214 if (0 == access(m_context.locations->getNPPluginsDir().c_str(), F_OK)) {
215 _D("This webapp has NPPlugins");
216 std::string pluginsExec = "/usr/bin/PluginProcess";
218 if (symlink(pluginsExec.c_str(),
219 m_context.locations->getNPPluginsExecFile().c_str()) != 0) {
222 _E("Failed to create symbolic link for npplugins : %ls",
223 DPL::GetErrnoString(error).c_str());
229 void TaskManifestFile::stepCopyIconFiles()
233 //This function copies icon to desktop icon path. For each locale avaliable
234 //which there is at least one icon in widget for, icon file is copied.
235 //Coping prioritize last positions when coping. If there is several icons
236 //with given locale, the one, that will be copied, will be icon
237 //which is declared by <icon> tag later than the others in config.xml of
240 std::vector<Locale> generatedLocales;
242 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
243 m_context.widgetConfig.localizationData.icons;
245 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_iterator
246 icon = icons.begin();
250 DPL::String src = icon->src;
251 FOREACH(locale, icon->availableLocales)
253 _D("Icon for locale: %ls is: %ls", (*locale).c_str(), src.c_str());
255 if (std::find(generatedLocales.begin(), generatedLocales.end(),
256 *locale) != generatedLocales.end())
258 _D("Skipping - has that locale");
261 generatedLocales.push_back(*locale);
264 DPL::Utils::Path sourceFile(m_context.locations->getSourceDir());
265 if (!locale->empty()) {
266 sourceFile /= "locales";
267 sourceFile /= *locale;
271 DPL::Utils::Path targetFile(GlobalConfig::GetUserWidgetDesktopIconPath());
272 targetFile /= getIconTargetFilename(*locale, sourceFile.Extension());
274 if (m_context.widgetConfig.packagingType ==
275 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
277 m_context.locations->setIconTargetFilenameForLocale(
278 targetFile.Fullpath());
281 _D("Copying icon: %s -> %s", sourceFile.Filename().c_str(), targetFile.Filename().c_str());
283 icon_list.push_back(targetFile.Fullpath());
287 DPL::FileInput input(sourceFile.Fullpath());
288 DPL::FileOutput output(targetFile.Fullpath());
289 DPL::Copy(&input, &output);
292 Catch(DPL::FileInput::Exception::Base)
294 // Error while opening or closing source file
295 //ReThrowMsg(InstallerException::CopyIconFailed,
296 // sourceFile.str());
297 _E("Copying widget's icon failed. Widget's icon will not be" \
298 "available from Main Screen");
301 Catch(DPL::FileOutput::Exception::Base)
303 // Error while opening or closing target file
304 //ReThrowMsg(InstallerException::CopyIconFailed,
305 // targetFile.str());
306 _E("Copying widget's icon failed. Widget's icon will not be" \
307 "available from Main Screen");
310 Catch(DPL::CopyFailed)
312 // Error while copying
313 //ReThrowMsg(InstallerException::CopyIconFailed,
314 // targetFile.str());
315 _E("Copying widget's icon failed. Widget's icon will not be" \
316 "available from Main Screen");
321 m_context.job->UpdateProgress(
322 InstallerContext::INSTALL_COPY_ICONFILE,
323 "Widget iconfile copy Finished");
326 void TaskManifestFile::stepCopyLiveboxFiles()
328 _D("Copy Livebox Files");
330 using namespace WrtDB;
331 ConfigParserData &data = m_context.widgetConfig.configInfo;
332 ConfigParserData::LiveboxList liveBoxList = data.m_livebox;
334 if (liveBoxList.size() <= 0) {
338 std::ostringstream sourceFile;
339 std::ostringstream targetFile;
341 FOREACH (boxIt, liveBoxList) {
342 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
343 (**boxIt).m_boxInfo.m_boxSize;
344 FOREACH (sizeIt, boxSizeList) {
345 std::string preview = DPL::ToUTF8String((*sizeIt).m_preview);
346 if (preview.empty()) {
349 sourceFile << m_context.locations->getSourceDir() << "/";
350 sourceFile << preview;
351 targetFile << m_context.locations->getSharedDataDir() << "/";
352 targetFile << (**boxIt).m_liveboxId << ".";
353 targetFile << DPL::ToUTF8String((*sizeIt).m_size) << "." << DEFAULT_PREVIEW_NAME;
355 copyFile(sourceFile.str(), targetFile.str());
357 // clear stream objects
361 // check this livebox has icon element
362 std::string icon = DPL::ToUTF8String((**boxIt).m_icon);
366 sourceFile << m_context.locations->getSourceDir() << "/";
368 targetFile << m_context.locations->getSharedDataDir() << "/";
369 targetFile << (**boxIt).m_liveboxId << "." << DEFAULT_ICON_NAME;
371 copyFile(sourceFile.str(), targetFile.str());
373 // clear stream objects
377 m_context.job->UpdateProgress(
378 InstallerContext::INSTALL_COPY_LIVEBOX_FILES,
379 "Livebox files copy Finished");
382 void TaskManifestFile::stepCopyAccountIconFiles()
384 _D("Copy Account icon files");
385 WrtDB::ConfigParserData::AccountProvider account =
386 m_context.widgetConfig.configInfo.accountProvider;
388 if (account.m_iconSet.empty()) {
389 _D("Widget doesn't contain Account");
393 FOREACH(it, account.m_iconSet) {
394 std::string sourceFile = m_context.locations->getSourceDir() +
396 DPL::ToUTF8String(it->second);
397 std::string targetFile = m_context.locations->getSharedResourceDir() +
399 DPL::ToUTF8String(it->second);
400 copyFile(sourceFile, targetFile);
404 void TaskManifestFile::copyFile(const std::string& sourceFile,
405 const std::string& targetFile)
409 DPL::FileInput input(sourceFile);
410 DPL::FileOutput output(targetFile);
411 DPL::Copy(&input, &output);
413 Catch(DPL::Exception)
415 _E("Failed to file copy. %s to %s", sourceFile.c_str(), targetFile.c_str());
416 ReThrowMsg(Exceptions::CopyIconFailed, "Error during file copy.");
420 bool TaskManifestFile::addBoxUiApplication(Manifest& manifest)
423 std::string postfix = ".d-box";
424 static bool isAdded = false;
429 _D("UiApplication for d-box is already added");
432 uiApp.setNodisplay(true);
433 uiApp.setTaskmanage(false);
434 uiApp.setMultiple(false);
435 setWidgetName(manifest, uiApp);
436 setWidgetIcons(uiApp);
438 // appid for box is like [webapp id].d-box
439 setWidgetIds(manifest, uiApp, postfix);
440 // executable path for box is like [app path]/bin/[webapp id].d-box
441 setWidgetExecPath(uiApp, postfix);
442 manifest.addUiApplication(uiApp);
447 Catch(DPL::Exception)
449 _E("Adding UiApplication on xml is failed.");
455 void TaskManifestFile::stepBackupIconFiles()
457 _D("Backup Icon Files");
459 backup_dir << m_context.locations->getBackupDir() << "/";
463 m_context.job->UpdateProgress(
464 InstallerContext::INSTALL_BACKUP_ICONFILE,
465 "New Widget icon file backup Finished");
468 void TaskManifestFile::stepAbortIconFiles()
470 _D("Abrot Icon Files");
471 FOREACH(it, icon_list)
473 _D("Remove Update Icon : %s", (*it).c_str());
474 unlink((*it).c_str());
477 std::ostringstream b_icon_dir;
478 b_icon_dir << backup_dir.str() << "icons";
480 std::list<std::string> fileList;
481 getFileList(b_icon_dir.str().c_str(), fileList);
483 FOREACH(back_icon, fileList)
485 std::ostringstream res_file;
486 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
487 res_file << "/" << (*back_icon);
489 std::ostringstream backup_file;
490 backup_file << b_icon_dir.str() << "/" << (*back_icon);
494 DPL::FileInput input(backup_file.str());
495 DPL::FileOutput output(res_file.str());
496 DPL::Copy(&input, &output);
498 Catch(DPL::FileInput::Exception::Base)
500 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
503 Catch(DPL::FileOutput::Exception::Base)
505 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
507 Catch(DPL::CopyFailed)
509 _E("Restoration icon File Failed. %s to %s", backup_file.str().c_str(), res_file.str().c_str());
514 DPL::String TaskManifestFile::getIconTargetFilename(
515 const DPL::String& languageTag, const std::string & ext) const
517 DPL::OStringStream filename;
518 TizenAppId appid = m_context.widgetConfig.tzAppid;
520 filename << DPL::ToUTF8String(appid).c_str();
522 if (!languageTag.empty()) {
523 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
529 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
531 if (locale.empty()) {
532 filename << L"." << languageTag;
534 filename << L"." << locale;
540 filename << L"." + DPL::FromUTF8String(ext);
542 return filename.str();
545 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
546 const DPL::String& key,
547 const DPL::String& languageTag)
550 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
553 if (!locale.empty()) {
554 file << "[" << locale << "]";
559 void TaskManifestFile::backupIconFiles()
561 _D("Backup Icon Files");
563 std::ostringstream b_icon_dir;
564 b_icon_dir << backup_dir.str() << "icons";
566 _D("Create icon backup folder : %s", b_icon_dir.str().c_str());
567 WrtUtilMakeDir(b_icon_dir.str());
569 std::list<std::string> fileList;
570 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
571 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
573 FOREACH(it, fileList)
575 if (0 == (strncmp((*it).c_str(), appid.c_str(),
576 strlen(appid.c_str()))))
578 std::ostringstream icon_file, backup_icon;
579 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
580 icon_file << "/" << (*it);
582 backup_icon << b_icon_dir.str() << "/" << (*it);
584 _D("Backup icon file %s to %s", icon_file.str().c_str(), backup_icon.str().c_str());
587 DPL::FileInput input(icon_file.str());
588 DPL::FileOutput output(backup_icon.str());
589 DPL::Copy(&input, &output);
591 Catch(DPL::FileInput::Exception::Base)
593 _E("Backup Desktop File Failed.");
594 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
597 Catch(DPL::FileOutput::Exception::Base)
599 _E("Backup Desktop File Failed.");
600 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
602 Catch(DPL::CopyFailed)
604 _E("Backup Desktop File Failed.");
605 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
607 unlink((*it).c_str());
612 void TaskManifestFile::getFileList(const char* path,
613 std::list<std::string> &list)
615 DIR* dir = opendir(path);
617 _E("icon directory doesn't exist");
618 ThrowMsg(Exceptions::FileOperationFailed, path);
622 struct dirent *result;
625 for (return_code = readdir_r(dir, &entry, &result);
626 result != NULL && return_code == 0;
627 return_code = readdir_r(dir, &entry, &result))
629 if (strcmp(entry.d_name, ".") == 0 ||
630 strcmp(entry.d_name, "..") == 0)
634 std::string file_name = entry.d_name;
635 list.push_back(file_name);
638 if (return_code != 0 || errno != 0) {
639 _E("readdir_r() failed with %s", DPL::GetErrnoString().c_str());
642 if (-1 == closedir(dir)) {
643 _E("Failed to close dir: %s with error: %s", path, DPL::GetErrnoString().c_str());
647 void TaskManifestFile::stepGenerateManifest()
649 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
650 manifest_name = pkgid + L".xml";
651 manifest_file += L"/tmp/" + manifest_name;
653 //libxml - init and check
654 LibxmlSingleton::Instance().init();
656 writeManifest(manifest_file);
658 std::ostringstream destFile;
659 if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
660 destFile << WrtDB::GlobalConfig::GetPreloadManifestPath() << "/";
662 destFile << WrtDB::GlobalConfig::GetManifestPath() << "/";
665 destFile << DPL::ToUTF8String(manifest_name);
666 commit_manifest = destFile.str();
667 _D("Commiting manifest file : %s", commit_manifest.c_str());
671 m_context.job->UpdateProgress(
672 InstallerContext::INSTALL_CREATE_MANIFEST,
673 "Widget Manifest Creation Finished");
676 void TaskManifestFile::commitManifest()
679 if (!(m_context.mode.rootPath == InstallMode::RootPath::RO &&
680 m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
681 && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
682 _D("cp %ls %s", manifest_file.c_str(), commit_manifest.c_str());
684 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
685 DPL::FileOutput output(commit_manifest);
686 DPL::Copy(&input, &output);
687 _D("Manifest writen to: %s", commit_manifest.c_str());
690 unlink((DPL::ToUTF8String(manifest_file)).c_str());
691 manifest_file = DPL::FromUTF8String(commit_manifest);
695 void TaskManifestFile::writeManifest(const DPL::String & path)
697 _D("Generating manifest file : %ls", path.c_str());
701 #ifdef MULTIPROCESS_SERVICE_SUPPORT
702 //default widget content
703 std::stringstream postfix;
704 // index 0 is reserved
705 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
706 setWidgetExecPath(uiApp, postfix.str());
707 setWidgetName(manifest, uiApp);
708 setWidgetIds(manifest, uiApp);
709 setWidgetIcons(uiApp);
710 setWidgetDescription(manifest);
711 setWidgetManifest(manifest);
712 setWidgetOtherInfo(uiApp);
713 setAppCategory(uiApp);
715 // move to the last of this procedure
716 //setLiveBoxInfo(manifest);
717 setAccount(manifest);
718 setPrivilege(manifest);
719 manifest.addUiApplication(uiApp);
721 //app-control content
722 ConfigParserData::AppControlInfoList appControlList =
723 m_context.widgetConfig.configInfo.appControlList;
724 FOREACH(it, appControlList) {
727 uiApp.setTaskmanage(true);
728 uiApp.setNodisplay(true);
729 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
730 uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition);
731 uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
733 std::stringstream postfix;
734 postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
735 setWidgetExecPath(uiApp, postfix.str());
736 setWidgetName(manifest, uiApp);
737 setWidgetIds(manifest, uiApp);
738 setWidgetIcons(uiApp);
739 setAppControlInfo(uiApp, *it);
740 setAppCategory(uiApp);
742 manifest.addUiApplication(uiApp);
744 // TODO: Must fix again with right method
745 // The mainapp attiribute must be set
746 // when there are multiple uiapps in mainfest
747 setLiveBoxInfo(manifest);
749 //default widget content
750 setWidgetExecPath(uiApp);
751 setWidgetName(manifest, uiApp);
752 setWidgetIds(manifest, uiApp);
753 setWidgetIcons(uiApp);
754 setWidgetDescription(manifest);
755 setWidgetManifest(manifest);
756 setWidgetOtherInfo(uiApp);
757 setAppControlsInfo(uiApp);
758 setAppCategory(uiApp);
760 // move to the last of this procedure
761 //setLiveBoxInfo(manifest);
762 setAccount(manifest);
763 setPrivilege(manifest);
765 manifest.addUiApplication(uiApp);
766 // TODO: Must fix again with right method
767 // The mainapp attiribute must be set
768 // when there are multiple uiapps in mainfest
769 setLiveBoxInfo(manifest);
772 manifest.generate(path);
773 _D("Manifest file serialized");
776 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
777 const std::string &postfix)
779 std::string exec = m_context.locations->getExecFile();
780 if (!postfix.empty()) {
781 exec.append(postfix);
783 _D("exec = %s", exec.c_str());
784 uiApp.setExec(DPL::FromASCIIString(exec));
787 void TaskManifestFile::setWidgetName(Manifest & manifest,
788 UiApplication & uiApp)
790 bool defaultNameSaved = false;
792 DPL::OptionalString defaultLocale =
793 m_context.widgetConfig.configInfo.defaultlocale;
794 std::pair<DPL::String,
795 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
797 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
799 Locale i = localizedData->first;
800 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
804 DPL::OptionalString name = localizedData->second.name;
805 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
807 //store default locale localized data
808 if (!!defaultLocale && defaultLocale == i) {
809 defaultLocalizedData = *localizedData;
813 if (!!defaultLocale && !defaultNameSaved) {
814 DPL::OptionalString name = defaultLocalizedData.second.name;
815 generateWidgetName(manifest,
817 DPL::OptionalString::Null,
823 void TaskManifestFile::setWidgetIds(Manifest & manifest,
824 UiApplication & uiApp,
825 const std::string &postfix)
828 TizenAppId appid = m_context.widgetConfig.tzAppid;
829 if (!postfix.empty()) {
830 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
832 uiApp.setAppid(appid);
835 if (!!m_context.widgetConfig.guid) {
836 uiApp.setExtraid(*m_context.widgetConfig.guid);
838 if (!appid.empty()) {
839 uiApp.setExtraid(DPL::String(L"http://") + appid);
844 uiApp.setType(DPL::FromASCIIString("webapp"));
845 manifest.setType(L"wgt");
848 void TaskManifestFile::generateWidgetName(Manifest & manifest,
849 UiApplication &uiApp,
850 const DPL::OptionalString& tag,
851 DPL::OptionalString name,
852 bool & defaultNameSaved)
857 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
859 if (!locale.empty()) {
860 uiApp.addLabel(LabelType(*name, *tag));
862 uiApp.addLabel(LabelType(*name));
863 manifest.addLabel(LabelType(*name));
866 defaultNameSaved = true;
867 uiApp.addLabel(LabelType(*name));
868 manifest.addLabel(LabelType(*name));
873 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
875 //TODO this file will need to be updated when user locale preferences
877 bool defaultIconSaved = false;
879 DPL::OptionalString defaultLocale =
880 m_context.widgetConfig.configInfo.defaultlocale;
882 std::vector<Locale> generatedLocales;
883 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
884 m_context.widgetConfig.localizationData.icons;
886 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_iterator
887 icon = icons.begin();
891 FOREACH(locale, icon->availableLocales)
893 if (std::find(generatedLocales.begin(), generatedLocales.end(),
894 *locale) != generatedLocales.end())
896 _D("Skipping - has that locale - already in manifest");
899 generatedLocales.push_back(*locale);
902 DPL::OptionalString tag = getLangTag(*locale); // translate en ->
908 generateWidgetIcon(uiApp, tag, *locale, DPL::Utils::Path(icon->src).Extension(), defaultIconSaved);
911 if (!!defaultLocale && !defaultIconSaved) {
912 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
919 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
920 const DPL::OptionalString& tag,
921 const DPL::String& language,
922 const std::string & extension,
923 bool & defaultIconSaved)
927 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
929 defaultIconSaved = true;
932 DPL::String iconText;
933 iconText += getIconTargetFilename(language, extension);
935 if (!locale.empty()) {
936 uiApp.addIcon(IconType(iconText, locale));
938 uiApp.addIcon(IconType(iconText));
940 std::ostringstream iconPath;
941 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
942 iconPath << getIconTargetFilename(locale, extension);
943 m_context.job->SendProgressIconPath(iconPath.str());
946 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
948 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
950 Locale i = localizedData->first;
951 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
955 DPL::OptionalString description = localizedData->second.description;
956 generateWidgetDescription(manifest, tag, description);
960 void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
961 const DPL::OptionalString& tag,
962 DPL::OptionalString description)
967 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
968 if (!locale.empty()) {
969 manifest.addDescription(DescriptionType(*description, locale));
971 manifest.addDescription(DescriptionType(*description));
974 manifest.addDescription(DescriptionType(*description));
979 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
981 manifest.setPackage(m_context.widgetConfig.tzPkgid);
983 if (!!m_context.widgetConfig.version) {
984 manifest.setVersion(*m_context.widgetConfig.version);
986 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
987 *m_context.widgetConfig.configInfo.authorEmail : L"");
988 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
989 *m_context.widgetConfig.configInfo.authorHref : L"");
990 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
991 *m_context.widgetConfig.configInfo.authorName : L"");
992 manifest.addAuthor(Author(email, href, L"", name));
994 if (!m_context.callerPkgId.empty()) {
995 manifest.setStoreClientId(m_context.callerPkgId);
999 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
1001 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
1003 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), STR_NODISPLAY)) {
1004 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), STR_TRUE)) {
1005 uiApp.setNodisplay(true);
1006 uiApp.setTaskmanage(false);
1008 uiApp.setNodisplay(false);
1009 uiApp.setTaskmanage(true);
1014 //There is no "X-TIZEN-PackageType=wgt"
1015 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
1016 // DPL::ToUTF8String(*widgetID).c_str()
1017 //There is no Comment in pkgmgr "Comment=Widget application"
1018 //that were in desktop file
1021 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
1023 WrtDB::ConfigParserData::AppControlInfoList appControlList =
1024 m_context.widgetConfig.configInfo.appControlList;
1026 if (appControlList.empty()) {
1027 _D("Widget doesn't contain app control");
1031 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
1032 FOREACH(it, appControlList) {
1033 setAppControlInfo(uiApp, *it);
1037 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
1038 const WrtDB::ConfigParserData::AppControlInfo & service)
1040 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
1041 AppControl appControl;
1042 if (!service.m_operation.empty()) {
1043 appControl.addOperation(service.m_operation); //TODO: encapsulation?
1045 if (!service.m_uriList.empty()) {
1046 FOREACH(uri, service.m_uriList) {
1047 appControl.addUri(*uri);
1050 if (!service.m_mimeList.empty()) {
1051 FOREACH(mime, service.m_mimeList) {
1052 appControl.addMime(*mime);
1055 uiApp.addAppControl(appControl);
1058 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
1060 WrtDB::ConfigParserData::CategoryList categoryList =
1061 m_context.widgetConfig.configInfo.categoryList;
1063 if (categoryList.empty()) {
1064 _D("Widget doesn't contain application category");
1067 FOREACH(it, categoryList) {
1068 if (!(*it).empty()) {
1069 uiApp.addAppCategory(*it);
1074 void TaskManifestFile::setMetadata(UiApplication &uiApp)
1076 WrtDB::ConfigParserData::MetadataList metadataList =
1077 m_context.widgetConfig.configInfo.metadataList;
1079 if (metadataList.empty()) {
1080 _D("Web application doesn't contain metadata");
1083 FOREACH(it, metadataList) {
1084 MetadataType metadataType(it->key, it->value);
1085 uiApp.addMetadata(metadataType);
1089 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
1091 ConfigParserData::LiveboxList& liveboxList =
1092 m_context.widgetConfig.configInfo.m_livebox;
1094 if (liveboxList.empty()) {
1099 if (!addBoxUiApplication(manifest)) {
1100 _D("error during adding UiApplication for d-box");
1104 FOREACH(it, liveboxList) {
1105 _D("setLiveBoxInfo");
1106 LiveBoxInfo liveBox;
1107 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
1108 DPL::String appid = m_context.widgetConfig.tzAppid;
1110 if (ConfigInfo->m_liveboxId != L"") {
1111 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
1112 if (found != std::string::npos) {
1113 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
1114 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
1116 DPL::String liveboxId =
1117 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1118 liveBox.setLiveboxId(liveboxId);
1121 DPL::String liveboxId =
1122 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
1123 liveBox.setLiveboxId(liveboxId);
1127 if (ConfigInfo->m_primary != L"") {
1128 liveBox.setPrimary(ConfigInfo->m_primary);
1131 if (ConfigInfo->m_updatePeriod != L"") {
1132 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
1135 std::list<std::pair<DPL::String, DPL::String> > boxLabelList;
1136 if (!ConfigInfo->m_label.empty()) {
1137 FOREACH(im, ConfigInfo->m_label) {
1138 std::pair<DPL::String, DPL::String> boxSize;
1139 Locale i = (*im).first;
1140 // translate en -> en_US etc
1141 DPL::OptionalString tag = getLangTag(i);
1145 boxSize.first = (*tag);
1146 boxSize.second = (*im).second;
1147 boxLabelList.push_back(boxSize);
1149 liveBox.setLabel(boxLabelList);
1152 DPL::String defaultLocale =
1153 DPL::FromUTF8String(m_context.locations->getPackageInstallationDir()) +
1154 DPL::String(L"/res/wgt/");
1156 if (ConfigInfo->m_icon != L"") {
1158 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1160 ConfigInfo->m_liveboxId + DPL::String(L".icon.png");
1161 liveBox.setIcon(icon);
1164 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1165 ConfigInfo->m_boxInfo.m_boxSize.empty())
1167 _D("Widget doesn't contain box");
1171 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1172 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1174 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1176 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1178 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1182 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1183 std::string boxType;
1184 if (ConfigInfo->m_type == L"") {
1185 // in case of default livebox
1186 boxType = web_provider_livebox_get_default_type();
1188 boxType = DPL::ToUTF8String(ConfigInfo->m_type);
1191 int box_scrollable =
1192 web_provider_plugin_get_box_scrollable(boxType.c_str());
1194 if (box_scrollable) {
1195 box.boxMouseEvent = L"true";
1197 box.boxMouseEvent = L"false";
1200 box.boxMouseEvent = L"false";
1203 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1204 box.boxTouchEffect = L"true";
1206 box.boxTouchEffect= L"false";
1209 ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
1210 ConfigInfo->m_boxInfo.m_boxSize;
1211 FOREACH(it, boxSizeList) {
1212 if (!(*it).m_preview.empty()) {
1214 DPL::FromUTF8String(m_context.locations->getSharedDataDir()) +
1216 ConfigInfo->m_liveboxId + DPL::String(L".") +
1217 (*it).m_size + DPL::String(L".preview.png");
1219 box.boxSize.push_back((*it));
1222 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1223 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1224 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1226 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1227 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1229 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1231 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1233 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1234 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1236 liveBox.setBox(box);
1238 manifest.addLivebox(liveBox);
1242 void TaskManifestFile::setAccount(Manifest& manifest)
1244 WrtDB::ConfigParserData::AccountProvider account =
1245 m_context.widgetConfig.configInfo.accountProvider;
1247 AccountProviderType provider;
1249 if (account.m_iconSet.empty()) {
1250 _D("Widget doesn't contain Account");
1253 if (account.m_multiAccountSupport) {
1254 provider.multiAccount = L"true";
1256 provider.multiAccount = L"false";
1258 provider.appid = m_context.widgetConfig.tzAppid;
1260 FOREACH(it, account.m_iconSet) {
1261 std::pair<DPL::String, DPL::String> icon;
1263 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1264 icon.first = L"account";
1265 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1266 icon.first = L"account-small";
1269 // account manifest requires absolute path for icon
1270 // /opt/apps/[package]/shared/res/[icon_path]
1271 icon.second = DPL::FromUTF8String(m_context.locations->getSharedResourceDir()) +
1274 provider.icon.push_back(icon);
1277 FOREACH(it, account.m_displayNameSet) {
1278 provider.name.push_back(LabelType(it->second, it->first));
1281 FOREACH(it, account.m_capabilityList) {
1282 provider.capability.push_back(*it);
1285 Account accountInfo;
1286 accountInfo.addAccountProvider(provider);
1287 manifest.addAccount(accountInfo);
1290 void TaskManifestFile::setPrivilege(Manifest& manifest)
1292 WrtDB::ConfigParserData::PrivilegeList privileges =
1293 m_context.widgetConfig.configInfo.privilegeList;
1295 PrivilegeType privilege;
1297 FOREACH(it, privileges)
1299 privilege.addPrivilegeName(it->name);
1302 manifest.addPrivileges(privilege);
1305 void TaskManifestFile::StartStep()
1310 void TaskManifestFile::EndStep()
1314 } //namespace WidgetInstall