2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file task_manifest_file.cpp
18 * @author Pawel Sikorski (p.sikorski@samgsung.com)
26 #include <dpl/assert.h>
32 #include <widget_install/task_manifest_file.h>
33 #include <widget_install/job_widget_install.h>
34 #include <widget_install/widget_install_errors.h>
35 #include <widget_install/widget_install_context.h>
36 #include <web_provider_livebox_info.h>
37 #include <web_provider_plugin_info.h>
38 #include <dpl/wrt-dao-ro/global_config.h>
39 #include <dpl/log/log.h>
40 #include <dpl/file_input.h>
41 #include <dpl/errno_string.h>
42 #include <dpl/file_output.h>
44 #include <dpl/exception.h>
45 #include <dpl/foreach.h>
46 #include <dpl/sstream.h>
47 #include <dpl/string.h>
48 #include <dpl/optional.h>
49 #include <dpl/utils/wrt_utility.h>
51 #include <libxml_utils.h>
52 #include <pkgmgr/pkgmgr_parser.h>
53 #include <dpl/localization/LanguageTagsProvider.h>
55 #define DEFAULT_ICON_NAME "icon.png"
57 using namespace WrtDB;
60 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
62 const char* const ST_TRUE = "true";
63 const char* const ST_NODISPLAY = "nodisplay";
65 LanguageTagMap getLanguageTagMap()
69 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
70 #include "languages.def"
76 DPL::OptionalString getLangTag(const DPL::String& tag)
78 static LanguageTagMap TagsMap =
81 DPL::String langTag = tag;
83 LogDebug("Trying to map language tag: " << langTag);
84 size_t pos = langTag.find_first_of(L'_');
85 if (pos != DPL::String::npos) {
88 DPL::OptionalString ret;
90 LanguageTagMap::iterator it = TagsMap.find(langTag);
91 if (it != TagsMap.end()) {
94 LogDebug("Mapping IANA Language tag to language tag: " <<
95 langTag << " -> " << ret);
102 namespace WidgetInstall {
103 const char * TaskManifestFile::encoding = "UTF-8";
105 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
106 DPL::TaskDecl<TaskManifestFile>(this),
110 if (m_context.isUpdateMode) {
111 // for widget update.
112 AddStep(&TaskManifestFile::stepBackupIconFiles);
113 AddStep(&TaskManifestFile::stepCopyIconFiles);
114 AddStep(&TaskManifestFile::stepGenerateManifest);
115 AddStep(&TaskManifestFile::stepParseUpgradedManifest);
116 AddStep(&TaskManifestFile::stepUpdateFinalize);
118 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
120 AddStep(&TaskManifestFile::stepCopyIconFiles);
121 AddStep(&TaskManifestFile::stepCreateExecFile);
122 AddStep(&TaskManifestFile::stepGenerateManifest);
123 AddStep(&TaskManifestFile::stepParseManifest);
124 AddStep(&TaskManifestFile::stepFinalize);
126 AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
130 TaskManifestFile::~TaskManifestFile()
133 void TaskManifestFile::stepCreateExecFile()
135 std::string exec = m_context.locations->getExecFile();
136 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
138 #ifdef MULTIPROCESS_SERVICE_SUPPORT
140 std::stringstream postfix;
141 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
142 std::string controlExec = exec;
143 controlExec.append(postfix.str());
146 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0)
150 LogPedantic("Failed to make a symbolic name for a file "
151 << "[" << DPL::GetErrnoString(error) << "]");
152 ThrowMsg(Exceptions::FileOperationFailed,
153 "Symbolic link creating is not done.");
156 // app-control widgets
157 unsigned int indexMax = 0;
158 FOREACH(it, m_context.widgetConfig.configInfo.appControlList) {
159 if (it->m_index > indexMax) {
160 indexMax = it->m_index;
164 for (std::size_t i = 1; i <= indexMax; ++i) {
165 std::stringstream postfix;
166 postfix << AppControlPrefix::PROCESS_PREFIX << i;
167 std::string controlExec = exec;
168 controlExec.append(postfix.str());
170 if (symlink(clientExeStr.c_str(), controlExec.c_str()) != 0) {
173 LogPedantic("Failed to make a symbolic name for a file "
174 << "[" << DPL::GetErrnoString(error) << "]");
176 ThrowMsg(Exceptions::FileOperationFailed,
177 "Symbolic link creating is not done.");
182 LogInfo("link -s " << clientExeStr << " " << exec);
184 if (symlink(clientExeStr.c_str(), exec.c_str()) != 0)
188 LogPedantic("Failed to make a symbolic name for a file "
189 << "[" << DPL::GetErrnoString(error) << "]");
190 ThrowMsg(Exceptions::FileOperationFailed,
191 "Symbolic link creating is not done.");
194 m_context.job->UpdateProgress(
195 InstallerContext::INSTALL_CREATE_EXECFILE,
196 "Widget execfile creation Finished");
199 void TaskManifestFile::stepCopyIconFiles()
201 LogDebug("CopyIconFiles");
203 //This function copies icon to desktop icon path. For each locale avaliable
204 //which there is at least one icon in widget for, icon file is copied.
205 //Coping prioritize last positions when coping. If there is several icons
206 //with given locale, the one, that will be copied, will be icon
207 //which is declared by <icon> tag later than the others in config.xml of
210 std::vector<Locale> generatedLocales;
212 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
213 m_context.widgetConfig.localizationData.icons;
215 //reversed: last <icon> has highest priority to be copied if it has given
216 // locale (TODO: why was that working that way?)
217 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
218 icon = icons.rbegin();
219 icon != icons.rend();
222 FOREACH(locale, icon->availableLocales)
224 DPL::String src = icon->src;
225 LogDebug("Icon for locale: " << *locale << "is : " << src);
227 if (std::find(generatedLocales.begin(), generatedLocales.end(),
228 *locale) != generatedLocales.end())
230 LogDebug("Skipping - has that locale");
233 generatedLocales.push_back(*locale);
236 std::ostringstream sourceFile;
237 std::ostringstream targetFile;
239 sourceFile << m_context.locations->getSourceDir() << "/";
241 if (!locale->empty()) {
242 sourceFile << "locales/" << *locale << "/";
247 targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
248 targetFile << getIconTargetFilename(*locale);
250 if (m_context.widgetConfig.packagingType ==
251 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
253 m_context.locations->setIconTargetFilenameForLocale(
257 LogDebug("Copying icon: " << sourceFile.str() <<
258 " -> " << targetFile.str());
260 icon_list.push_back(targetFile.str());
264 DPL::FileInput input(sourceFile.str());
265 DPL::FileOutput output(targetFile.str());
266 DPL::Copy(&input, &output);
269 Catch(DPL::FileInput::Exception::Base)
271 // Error while opening or closing source file
272 //ReThrowMsg(InstallerException::CopyIconFailed,
273 // sourceFile.str());
275 "Copying widget's icon failed. Widget's icon will not be" \
276 "available from Main Screen");
279 Catch(DPL::FileOutput::Exception::Base)
281 // Error while opening or closing target file
282 //ReThrowMsg(InstallerException::CopyIconFailed,
283 // targetFile.str());
285 "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());
295 "Copying widget's icon failed. Widget's icon will not be" \
296 "available from Main Screen");
301 m_context.job->UpdateProgress(
302 InstallerContext::INSTALL_COPY_ICONFILE,
303 "Widget iconfile copy Finished");
306 void TaskManifestFile::stepBackupIconFiles()
308 LogDebug("Backup Icon Files");
310 backup_dir << m_context.locations->getPackageInstallationDir();
311 backup_dir << "/" << "backup" << "/";
315 m_context.job->UpdateProgress(
316 InstallerContext::INSTALL_BACKUP_ICONFILE,
317 "New Widget icon file backup Finished");
320 void TaskManifestFile::stepAbortIconFiles()
322 LogDebug("Abrot Icon Files");
323 FOREACH(it, icon_list)
325 LogDebug("Remove Update Icon : " << (*it));
326 unlink((*it).c_str());
329 std::ostringstream b_icon_dir;
330 b_icon_dir << backup_dir.str() << "icons";
332 std::list<std::string> fileList;
333 getFileList(b_icon_dir.str().c_str(), fileList);
335 FOREACH(back_icon, fileList)
337 std::ostringstream res_file;
338 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
339 res_file << "/" << (*back_icon);
341 std::ostringstream backup_file;
342 backup_file << b_icon_dir.str() << "/" << (*back_icon);
346 DPL::FileInput input(backup_file.str());
347 DPL::FileOutput output(res_file.str());
348 DPL::Copy(&input, &output);
350 Catch(DPL::FileInput::Exception::Base)
352 LogError("Restoration icon File Failed." << backup_file.str()
353 << " to " << res_file.str());
356 Catch(DPL::FileOutput::Exception::Base)
358 LogError("Restoration icon File Failed." << backup_file.str()
359 << " to " << res_file.str());
361 Catch(DPL::CopyFailed)
363 LogError("Restoration icon File Failed." << backup_file.str()
364 << " to " << res_file.str());
369 void TaskManifestFile::stepUpdateFinalize()
372 LogDebug("Finished Update Desktopfile");
375 DPL::String TaskManifestFile::getIconTargetFilename(
376 const DPL::String& languageTag) const
378 DPL::OStringStream filename;
379 TizenAppId appid = m_context.widgetConfig.tzAppid;
381 filename << DPL::ToUTF8String(appid).c_str();
383 if (!languageTag.empty()) {
384 DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
390 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
392 if (locale.empty()) {
393 filename << L"." << languageTag;
395 filename << L"." << locale;
400 return filename.str();
403 void TaskManifestFile::stepFinalize()
406 LogInfo("Finished ManifestFile step");
409 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
410 const DPL::String& key,
411 const DPL::String& languageTag)
414 LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
417 if (!locale.empty()) {
418 file << "[" << locale << "]";
423 void TaskManifestFile::backupIconFiles()
425 LogInfo("Backup Icon Files");
427 std::ostringstream b_icon_dir;
428 b_icon_dir << backup_dir.str() << "icons";
430 LogDebug("Create icon backup folder : " << b_icon_dir.str());
431 WrtUtilMakeDir(b_icon_dir.str());
433 std::list<std::string> fileList;
434 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
435 std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
437 FOREACH(it, fileList)
439 if (0 == (strncmp((*it).c_str(), appid.c_str(),
440 strlen(appid.c_str()))))
442 std::ostringstream icon_file, backup_icon;
443 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
444 icon_file << "/" << (*it);
446 backup_icon << b_icon_dir.str() << "/" << (*it);
448 LogDebug("Backup icon file " << icon_file.str() << " to " <<
452 DPL::FileInput input(icon_file.str());
453 DPL::FileOutput output(backup_icon.str());
454 DPL::Copy(&input, &output);
456 Catch(DPL::FileInput::Exception::Base)
458 LogError("Backup Desktop File Failed.");
459 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
462 Catch(DPL::FileOutput::Exception::Base)
464 LogError("Backup Desktop File Failed.");
465 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
467 Catch(DPL::CopyFailed)
469 LogError("Backup Desktop File Failed.");
470 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
472 unlink((*it).c_str());
477 void TaskManifestFile::getFileList(const char* path,
478 std::list<std::string> &list)
480 DIR* dir = opendir(path);
482 LogError("icon directory doesn't exist");
483 ThrowMsg(Exceptions::FileOperationFailed, path);
487 struct dirent *result;
490 for (return_code = readdir_r(dir, &entry, &result);
491 result != NULL && return_code == 0;
492 return_code = readdir_r(dir, &entry, &result))
494 if (strcmp(entry.d_name, ".") == 0 ||
495 strcmp(entry.d_name, "..") == 0)
499 std::string file_name = entry.d_name;
500 list.push_back(file_name);
503 if (return_code != 0 || errno != 0) {
504 LogError("readdir_r() failed with " << DPL::GetErrnoString());
507 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
508 LogError("Failed to close dir: " << path << " with error: "
509 << DPL::GetErrnoString());
513 void TaskManifestFile::stepGenerateManifest()
515 TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
516 manifest_name = pkgid + L".xml";
517 manifest_file += L"/tmp/" + manifest_name;
519 //libxml - init and check
520 LibxmlSingleton::Instance().init();
522 writeManifest(manifest_file);
524 m_context.job->UpdateProgress(
525 InstallerContext::INSTALL_CREATE_MANIFEST,
526 "Widget Manifest Creation Finished");
529 void TaskManifestFile::stepParseManifest()
531 int code = pkgmgr_parser_parse_manifest_for_installation(
532 DPL::ToUTF8String(manifest_file).c_str(), NULL);
535 LogError("Manifest parser error: " << code);
536 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
539 m_context.job->UpdateProgress(
540 InstallerContext::INSTALL_CREATE_MANIFEST,
541 "Widget Manifest Parsing Finished");
542 LogDebug("Manifest parsed");
545 void TaskManifestFile::stepParseUpgradedManifest()
547 int code = pkgmgr_parser_parse_manifest_for_upgrade(
548 DPL::ToUTF8String(manifest_file).c_str(), NULL);
551 LogError("Manifest parser error: " << code);
552 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
555 m_context.job->UpdateProgress(
556 InstallerContext::INSTALL_CREATE_MANIFEST,
557 "Widget Manifest Parsing Finished");
558 LogDebug("Manifest parsed");
561 void TaskManifestFile::commitManifest()
563 LogDebug("Commiting manifest file : " << manifest_file);
565 std::ostringstream destFile;
566 if (m_context.job->getInstallerStruct().m_installMode
567 == InstallMode::INSTALL_MODE_PRELOAD)
569 destFile << "/usr/share/packages" << "/"; //TODO constant with path
571 destFile << "/opt/share/packages" << "/"; //TODO constant with path
573 destFile << DPL::ToUTF8String(manifest_name);
574 LogInfo("cp " << manifest_file << " " << destFile.str());
576 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
577 DPL::FileOutput output(destFile.str());
578 DPL::Copy(&input, &output);
579 LogDebug("Manifest writen to: " << destFile.str());
582 unlink((DPL::ToUTF8String(manifest_file)).c_str());
583 manifest_file = DPL::FromUTF8String(destFile.str().c_str());
586 void TaskManifestFile::writeManifest(const DPL::String & path)
588 LogDebug("Generating manifest file : " << path);
592 #ifdef MULTIPROCESS_SERVICE_SUPPORT
593 //default widget content
594 std::stringstream postfix;
595 // index 0 is reserved
596 postfix << AppControlPrefix::PROCESS_PREFIX << 0;
597 setWidgetExecPath(uiApp, postfix.str());
598 setWidgetName(manifest, uiApp);
599 setWidgetIds(manifest, uiApp);
600 setWidgetIcons(uiApp);
601 setWidgetDescription(manifest);
602 setWidgetManifest(manifest);
603 setWidgetOtherInfo(uiApp);
604 setAppCategory(uiApp);
605 setLiveBoxInfo(manifest);
606 setAccount(manifest);
607 setPrivilege(manifest);
608 manifest.addUiApplication(uiApp);
610 //app-control content
611 ConfigParserData::AppControlInfoList appControlList =
612 m_context.widgetConfig.configInfo.appControlList;
613 FOREACH(it, appControlList) {
616 uiApp.setTaskmanage(true);
617 uiApp.setNodisplay(true);
618 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
619 uiApp.setTaskmanage(ConfigParserData::AppControlInfo::Disposition::INLINE != it->m_disposition);
620 uiApp.setMultiple(ConfigParserData::AppControlInfo::Disposition::INLINE == it->m_disposition);
622 std::stringstream postfix;
623 postfix << AppControlPrefix::PROCESS_PREFIX << it->m_index;
624 setWidgetExecPath(uiApp, postfix.str());
625 setWidgetName(manifest, uiApp);
626 setWidgetIds(manifest, uiApp);
627 setWidgetIcons(uiApp);
628 setAppControlInfo(uiApp, *it);
629 setAppCategory(uiApp);
630 manifest.addUiApplication(uiApp);
633 //default widget content
634 setWidgetExecPath(uiApp);
635 setWidgetName(manifest, uiApp);
636 setWidgetIds(manifest, uiApp);
637 setWidgetIcons(uiApp);
638 setWidgetDescription(manifest);
639 setWidgetManifest(manifest);
640 setWidgetOtherInfo(uiApp);
641 setAppControlsInfo(uiApp);
642 setAppCategory(uiApp);
643 setLiveBoxInfo(manifest);
644 setAccount(manifest);
645 setPrivilege(manifest);
647 manifest.addUiApplication(uiApp);
650 manifest.generate(path);
651 LogDebug("Manifest file serialized");
654 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp,
655 const std::string &postfix)
657 std::string exec = m_context.locations->getExecFile();
658 if (!postfix.empty()) {
659 exec.append(postfix);
661 LogDebug("exec = " << exec);
662 uiApp.setExec(DPL::FromASCIIString(exec));
665 void TaskManifestFile::setWidgetName(Manifest & manifest,
666 UiApplication & uiApp)
668 bool defaultNameSaved = false;
670 DPL::OptionalString defaultLocale =
671 m_context.widgetConfig.configInfo.defaultlocale;
672 std::pair<DPL::String,
673 WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
675 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
677 Locale i = localizedData->first;
678 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
682 DPL::OptionalString name = localizedData->second.name;
683 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
685 //store default locale localized data
686 if (!!defaultLocale && defaultLocale == i) {
687 defaultLocalizedData = *localizedData;
691 if (!!defaultLocale && !defaultNameSaved) {
692 DPL::OptionalString name = defaultLocalizedData.second.name;
693 generateWidgetName(manifest,
695 DPL::OptionalString::Null,
701 void TaskManifestFile::setWidgetIds(Manifest & manifest,
702 UiApplication & uiApp,
703 const std::string &postfix)
706 TizenAppId appid = m_context.widgetConfig.tzAppid;
707 if (!postfix.empty()) {
708 appid = DPL::FromUTF8String(DPL::ToUTF8String(appid).append(postfix));
710 uiApp.setAppid(appid);
713 if (!!m_context.widgetConfig.guid) {
714 uiApp.setExtraid(*m_context.widgetConfig.guid);
716 if (!appid.empty()) {
717 uiApp.setExtraid(DPL::String(L"http://") + appid);
722 uiApp.setType(DPL::FromASCIIString("webapp"));
723 manifest.setType(L"wgt");
726 void TaskManifestFile::generateWidgetName(Manifest & manifest,
727 UiApplication &uiApp,
728 const DPL::OptionalString& tag,
729 DPL::OptionalString name,
730 bool & defaultNameSaved)
735 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
737 if (!locale.empty()) {
738 uiApp.addLabel(LabelType(*name, *tag));
740 uiApp.addLabel(LabelType(*name));
741 manifest.addLabel(LabelType(*name));
744 defaultNameSaved = true;
745 uiApp.addLabel(LabelType(*name));
746 manifest.addLabel(LabelType(*name));
751 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
753 //TODO this file will need to be updated when user locale preferences
755 bool defaultIconSaved = false;
757 DPL::OptionalString defaultLocale =
758 m_context.widgetConfig.configInfo.defaultlocale;
760 std::vector<Locale> generatedLocales;
761 WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
762 m_context.widgetConfig.localizationData.icons;
764 //reversed: last <icon> has highest priority to be writen to manifest if it
765 // has given locale (TODO: why was that working that way?)
766 for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
767 icon = icons.rbegin();
768 icon != icons.rend();
771 FOREACH(locale, icon->availableLocales)
773 if (std::find(generatedLocales.begin(), generatedLocales.end(),
774 *locale) != generatedLocales.end())
776 LogDebug("Skipping - has that locale - already in manifest");
779 generatedLocales.push_back(*locale);
782 DPL::OptionalString tag = getLangTag(*locale); // translate en ->
788 generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
791 if (!!defaultLocale && !defaultIconSaved) {
792 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
798 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
799 const DPL::OptionalString& tag,
800 const DPL::String& language,
801 bool & defaultIconSaved)
805 locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
807 defaultIconSaved = true;
810 DPL::String iconText;
811 iconText += getIconTargetFilename(language);
813 if (!locale.empty()) {
814 uiApp.addIcon(IconType(iconText, locale));
816 uiApp.addIcon(IconType(iconText));
818 std::ostringstream iconPath;
819 iconPath << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
820 iconPath << getIconTargetFilename(locale);
821 m_context.job->SendProgressIconPath(iconPath.str());
824 void TaskManifestFile::setWidgetDescription(Manifest & manifest)
826 FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
828 Locale i = localizedData->first;
829 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
833 DPL::OptionalString description = localizedData->second.description;
834 generateWidgetDescription(manifest, tag, description);
838 void TaskManifestFile::generateWidgetDescription(Manifest & manifest,
839 const DPL::OptionalString& tag,
840 DPL::OptionalString description)
845 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
846 if (!locale.empty()) {
847 manifest.addDescription(DescriptionType(*description, locale));
849 manifest.addDescription(DescriptionType(*description));
852 manifest.addDescription(DescriptionType(*description));
857 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
859 manifest.setPackage(m_context.widgetConfig.tzPkgid);
861 if (!!m_context.widgetConfig.version) {
862 manifest.setVersion(*m_context.widgetConfig.version);
864 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
865 *m_context.widgetConfig.configInfo.authorEmail : L"");
866 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
867 *m_context.widgetConfig.configInfo.authorHref : L"");
868 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
869 *m_context.widgetConfig.configInfo.authorName : L"");
870 manifest.addAuthor(Author(email, href, L"", name));
873 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
875 FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
877 if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
878 if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
879 uiApp.setNodisplay(true);
880 uiApp.setTaskmanage(false);
882 uiApp.setNodisplay(false);
883 uiApp.setTaskmanage(true);
888 //There is no "X-TIZEN-PackageType=wgt"
889 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
890 // DPL::ToUTF8String(*widgetID).c_str()
891 //There is no Comment in pkgmgr "Comment=Widget application"
892 //that were in desktop file
895 void TaskManifestFile::setAppControlsInfo(UiApplication & uiApp)
897 WrtDB::ConfigParserData::AppControlInfoList appControlList =
898 m_context.widgetConfig.configInfo.appControlList;
900 if (appControlList.empty()) {
901 LogInfo("Widget doesn't contain app control");
905 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
906 FOREACH(it, appControlList) {
907 setAppControlInfo(uiApp, *it);
911 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp,
912 const WrtDB::ConfigParserData::AppControlInfo & service)
914 // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
915 AppControl appControl;
916 if (!service.m_operation.empty()) {
917 appControl.addOperation(service.m_operation); //TODO: encapsulation?
919 if (!service.m_uriList.empty()) {
920 FOREACH(uri, service.m_uriList) {
921 appControl.addUri(*uri);
924 if (!service.m_mimeList.empty()) {
925 FOREACH(mime, service.m_mimeList) {
926 appControl.addMime(*mime);
929 uiApp.addAppControl(appControl);
932 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
934 WrtDB::ConfigParserData::CategoryList categoryList =
935 m_context.widgetConfig.configInfo.categoryList;
937 if (categoryList.empty()) {
938 LogInfo("Widget doesn't contain application category");
941 FOREACH(it, categoryList) {
942 if (!(*it).empty()) {
943 uiApp.addAppCategory(*it);
948 void TaskManifestFile::stepAbortParseManifest()
950 LogError("[Parse Manifest] Abroting....");
952 int code = pkgmgr_parser_parse_manifest_for_uninstallation(
953 DPL::ToUTF8String(manifest_file).c_str(), NULL);
956 LogWarning("Manifest parser error: " << code);
957 ThrowMsg(Exceptions::ManifestInvalid, "Parser returncode: " << code);
959 int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
961 LogWarning("No manifest file found: " << manifest_file);
965 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
967 FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
968 LogInfo("setLiveBoxInfo");
970 DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
971 DPL::String appid = m_context.widgetConfig.tzAppid;
973 if (ConfigInfo->m_liveboxId != L"") {
974 size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
975 if (found != std::string::npos) {
976 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
977 liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
979 DPL::String liveboxId =
980 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
981 liveBox.setLiveboxId(liveboxId);
984 DPL::String liveboxId =
985 appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
986 liveBox.setLiveboxId(liveboxId);
990 if (ConfigInfo->m_primary != L"") {
991 liveBox.setPrimary(ConfigInfo->m_primary);
994 if (ConfigInfo->m_updatePeriod != L"") {
995 liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
998 if (ConfigInfo->m_label != L"") {
999 liveBox.setLabel(ConfigInfo->m_label);
1002 DPL::String defaultLocale
1003 = DPL::FromUTF8String(
1004 m_context.locations->getPackageInstallationDir())
1005 + DPL::String(L"/res/wgt/");
1007 if (ConfigInfo->m_icon != L"") {
1008 liveBox.setIcon(defaultLocale + ConfigInfo->m_icon);
1011 if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
1012 ConfigInfo->m_boxInfo.m_boxSize.empty())
1014 LogInfo("Widget doesn't contain box");
1018 if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
1019 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
1021 ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
1023 box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
1025 box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
1029 if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
1030 std::string boxType;
1031 if (ConfigInfo->m_type == L"") {
1032 // in case of default livebox
1033 boxType = web_provider_livebox_get_default_type();
1035 boxType = DPL::ToUTF8String(ConfigInfo->m_type);
1038 int box_scrollable =
1039 web_provider_plugin_get_box_scrollable(boxType.c_str());
1041 if (box_scrollable) {
1042 box.boxMouseEvent = L"true";
1044 box.boxMouseEvent = L"false";
1047 box.boxMouseEvent = L"false";
1050 if (ConfigInfo->m_boxInfo.m_boxTouchEffect == L"true") {
1051 box.boxTouchEffect = L"true";
1053 box.boxTouchEffect= L"false";
1056 std::list<std::pair<DPL::String, DPL::String> > BoxSizeList
1057 = ConfigInfo->m_boxInfo.m_boxSize;
1058 FOREACH(im, BoxSizeList) {
1059 std::pair<DPL::String, DPL::String> boxSize = *im;
1060 if (!boxSize.second.empty()) {
1061 boxSize.second = defaultLocale + boxSize.second;
1063 box.boxSize.push_back(boxSize);
1066 if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
1067 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
1068 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
1070 if ((0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 4, L"http"))
1071 || (0 == ConfigInfo->m_boxInfo.m_pdSrc.compare(0, 5, L"https")))
1073 box.pdSrc = ConfigInfo->m_boxInfo.m_pdSrc;
1075 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
1077 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
1078 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
1080 liveBox.setBox(box);
1082 manifest.addLivebox(liveBox);
1086 void TaskManifestFile::setAccount(Manifest& manifest)
1088 WrtDB::ConfigParserData::AccountProvider account =
1089 m_context.widgetConfig.configInfo.accountProvider;
1091 AccountProviderType provider;
1093 if (account.m_iconSet.empty()) {
1094 LogInfo("Widget doesn't contain Account");
1097 if (account.m_multiAccountSupport) {
1098 provider.multiAccount = L"ture";
1100 provider.multiAccount = L"false";
1102 provider.appid = m_context.widgetConfig.tzAppid;
1104 FOREACH(it, account.m_iconSet) {
1105 std::pair<DPL::String, DPL::String> icon;
1107 if (it->first == ConfigParserData::IconSectionType::DefaultIcon) {
1108 icon.first = L"account";
1109 } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) {
1110 icon.first = L"account-small";
1112 icon.second = it->second;
1114 provider.icon.push_back(icon);
1117 FOREACH(it, account.m_displayNameSet) {
1118 provider.name.push_back(LabelType(it->second, it->first));
1121 FOREACH(it, account.m_capabilityList) {
1122 provider.capability.push_back(*it);
1125 Account accountInfo;
1126 accountInfo.addAccountProvider(provider);
1127 manifest.addAccount(accountInfo);
1130 void TaskManifestFile::setPrivilege(Manifest& manifest)
1132 WrtDB::ConfigParserData::PrivilegeList privileges =
1133 m_context.widgetConfig.configInfo.privilegeList;
1135 PrivilegeType privilege;
1137 FOREACH(it, privileges)
1139 privilege.addPrivilegeName(it->name);
1142 manifest.addPrivileges(privilege);
1145 } //namespace WidgetInstall