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)
25 #include <dpl/assert.h>
31 #include <widget_install/task_manifest_file.h>
32 #include <widget_install/job_widget_install.h>
33 #include <widget_install/widget_install_errors.h>
34 #include <widget_install/widget_install_context.h>
35 #include <dpl/wrt-dao-ro/global_config.h>
36 #include <dpl/log/log.h>
37 #include <dpl/file_input.h>
38 #include <dpl/file_output.h>
40 #include <dpl/exception.h>
41 #include <dpl/foreach.h>
42 #include <dpl/sstream.h>
43 #include <dpl/string.h>
44 #include <dpl/optional.h>
45 #include <dpl/utils/wrt_utility.h>
47 #include <libxml_utils.h>
48 #include <pkgmgr/pkgmgr_parser.h>
50 using namespace WrtDB;
53 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
55 LanguageTagMap getLanguageTagMap()
59 #define ADD(tag, l_tag) map.insert(std::make_pair(L ## # tag, L ## # l_tag));
60 #include "languages.def"
66 DPL::OptionalString getLangTag(const DPL::String& tag)
68 static LanguageTagMap TagsMap =
71 DPL::String langTag = tag;
73 LogDebug("Trying to map language tag: " << langTag);
74 size_t pos = langTag.find_first_of(L'_');
75 if (pos != DPL::String::npos) {
78 DPL::OptionalString ret;
80 LanguageTagMap::iterator it = TagsMap.find(langTag);
81 if (it != TagsMap.end()) {
84 LogDebug("Mapping IANA Language tag to language tag: " <<
85 langTag << " -> " << ret);
92 namespace WidgetInstall {
94 const char * TaskManifestFile::encoding = "UTF-8";
96 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
97 DPL::TaskDecl<TaskManifestFile>(this),
100 if (false == m_context.existingWidgetInfo.isExist) {
101 AddStep(&TaskManifestFile::stepCopyIconFiles);
102 //AddStep(&TaskManifestFile::stepCreateDesktopFile);
103 AddStep(&TaskManifestFile::stepGenerateManifest);
104 AddStep(&TaskManifestFile::stepParseManifest);
105 AddStep(&TaskManifestFile::stepCreateExecFile);
106 AddStep(&TaskManifestFile::stepFinalize);
108 // for widget update.
109 AddStep(&TaskManifestFile::stepBackupIconFiles);
110 AddStep(&TaskManifestFile::stepCopyIconFiles);
111 //AddStep(&TaskManifestFile::stepUpdateDesktopFile);
112 AddStep(&TaskManifestFile::stepGenerateManifest);
113 AddStep(&TaskManifestFile::stepParseUpgradedManifest);
114 AddStep(&TaskManifestFile::stepUpdateFinalize);
116 AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
117 //AddAbortStep(&TaskManifestFile::stepAbortDesktopFile);
121 TaskManifestFile::~TaskManifestFile()
126 void TaskManifestFile::stepCreateDesktopFile()
128 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
129 desktop_name << pkgname << ".desktop";
130 desktop_file << "/tmp/" << desktop_name.str();
131 LogInfo("desktop file : " << desktop_file.str());
132 std::ofstream file(desktop_file.str().c_str());
134 saveWidgetType(file);
135 saveWidgetExecPath(file);
136 saveWidgetName(file);
137 saveWidgetIcons(file);
138 saveWidgetVersion(file);
139 saveWidgetOtherInfo(file);
140 saveAppServiceInfo(file);
146 m_context.job->UpdateProgress(
147 InstallerContext::INSTALL_CREATE_DESKTOP,
148 "Widget Desktop Creation Finished");
151 void TaskManifestFile::stepCreateExecFile()
153 //ln -s /usr/bin/wrt-client {widget-handle}
155 std::ostringstream real_path;
156 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
157 if (pkgname.IsNull()) {
158 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
161 real_path << GlobalConfig::GetUserInstalledWidgetPath() << "/";
162 real_path << pkgname << "/";
163 real_path << GlobalConfig::GetUserWidgetExecPath() << "/" <<
164 m_context.widgetHandle;
165 std::string clientExeStr = GlobalConfig::GetWrtClientExec();
167 LogInfo("link -s " << clientExeStr << " " << real_path.str());
168 symlink(clientExeStr.c_str(), real_path.str().c_str());
170 m_context.job->UpdateProgress(
171 InstallerContext::INSTALL_CREATE_EXECFILE,
172 "Widget execfile creation Finished");
175 void TaskManifestFile::stepCopyIconFiles()
177 LogDebug("CopyIconFiles");
179 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
180 if (pkgname.IsNull()) {
181 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
184 Assert(!!m_context.widgetHandle);
185 WidgetDAOReadOnly dao(*m_context.widgetHandle);
186 WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
187 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
190 DPL::String i = it->widgetLocale;
191 DPL::OptionalString src;
194 if (icon->iconId == it->iconId) {
198 LogDebug("Icon for locale: " << i << "is : " << src);
200 std::ostringstream sourceFile;
201 std::ostringstream targetFile;
204 sourceFile << GlobalConfig::GetUserInstalledWidgetPath() << "/";
205 sourceFile << pkgname << "/";
206 sourceFile << GlobalConfig::GetWidgetSrcPath() << "/";
208 targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
211 sourceFile << "locales/" << i << "/";
214 targetFile << getIconTargetFilename(i);
217 //Use WRT default (not from the widget) only if widget default (not
218 // localized) doesn't exist.
220 LogError("Using Default Icon for widget");
221 sourceFile << GlobalConfig::GetUserWidgetDefaultIconFile();
227 LogDebug("Copying icon: " << sourceFile.str() <<
228 " -> " << targetFile.str());
230 icon_list.push_back(targetFile.str());
234 DPL::FileInput input(sourceFile.str());
235 DPL::FileOutput output(targetFile.str());
236 DPL::Copy(&input, &output);
239 Catch(DPL::FileInput::Exception::Base)
241 // Error while opening or closing source file
242 //ReThrowMsg(InstallerException::CopyIconFailed, sourceFile.str());
244 "Copying widget's icon failed. Widget's icon will not be"\
245 "available from Main Screen");
248 Catch(DPL::FileOutput::Exception::Base)
250 // Error while opening or closing target file
251 //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
253 "Copying widget's icon failed. Widget's icon will not be"\
254 "available from Main Screen");
257 Catch(DPL::CopyFailed)
259 // Error while copying
260 //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
262 "Copying widget's icon failed. Widget's icon will not be"\
263 "available from Main Screen");
267 m_context.job->UpdateProgress(
268 InstallerContext::INSTALL_COPY_ICONFILE,
269 "Widget iconfile copy Finished");
272 void TaskManifestFile::stepBackupIconFiles()
274 LogDebug("Backup Icon Files");
275 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
276 desktop_name << pkgname << ".desktop";
278 desktop_file << GlobalConfig::GetUserWidgetDesktopPath() << "/";
279 desktop_file << desktop_name.str();
281 backup_dir << GlobalConfig::GetUserInstalledWidgetPath();
282 backup_dir << "/" << m_context.widgetConfig.pkgname;
283 backup_dir << "/" << "backup" << "/";
287 m_context.job->UpdateProgress(
288 InstallerContext::INSTALL_BACKUP_ICONFILE,
289 "New Widget icon file backup Finished");
293 void TaskManifestFile::stepUpdateDesktopFile()
295 LogDebug("Update Desktop File");
298 std::ofstream file(desktop_file.str().c_str(), std::ios::trunc);
300 saveWidgetType(file);
301 saveWidgetExecPath(file);
302 saveWidgetName(file);
303 saveWidgetIcons(file);
304 saveWidgetVersion(file);
305 saveWidgetOtherInfo(file);
306 saveAppServiceInfo(file);
312 m_context.job->UpdateProgress(
313 InstallerContext::INSTALL_UPDATE_DESKTOP,
314 "New Widget desktop file update Finished");
317 void TaskManifestFile::stepAbortIconFiles()
319 LogDebug("Abrot Icon Files");
320 FOREACH(it, icon_list)
322 LogDebug("Remove Update Icon : " << (*it));
323 unlink((*it).c_str());
326 std::ostringstream b_icon_dir;
327 b_icon_dir << backup_dir.str() << "icons";
329 std::list<std::string> fileList;
330 getFileList(b_icon_dir.str().c_str(), fileList);
332 FOREACH(back_icon, fileList)
334 std::ostringstream res_file;
335 res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
336 res_file << "/" << (*back_icon);
338 std::ostringstream backup_file;
339 backup_file << b_icon_dir.str() << "/" << (*back_icon);
343 DPL::FileInput input(backup_file.str());
344 DPL::FileOutput output(res_file.str());
345 DPL::Copy(&input, &output);
347 Catch(DPL::FileInput::Exception::Base)
349 LogError("Restoration icon File Failed." << backup_file.str()
350 << " to " << res_file.str());
353 Catch(DPL::FileOutput::Exception::Base)
355 LogError("Restoration icon File Failed." << backup_file.str()
356 << " to " << res_file.str());
358 Catch(DPL::CopyFailed)
360 LogError("Restoration icon File Failed." << backup_file.str()
361 << " to " << res_file.str());
366 void TaskManifestFile::stepUpdateFinalize()
368 LogDebug("Finished Update Desktopfile");
371 void TaskManifestFile::stepAbortDesktopFile()
373 LogDebug("Abort desktop backup ");
375 std::ifstream backupFile(bp_desktop_file.str().c_str());
376 std::ofstream file(desktop_file.str().c_str(), std::ios::trunc);
378 while(!backupFile.eof()) {
379 char contents[256] = {0, };
381 backupFile.getline(contents, sizeof(contents));
382 file << contents << std::endl;
389 m_context.job->UpdateProgress(
390 InstallerContext::INSTALL_UPDATE_DESKTOP,
391 "New Widget desktop file update Finished");
394 void TaskManifestFile::moveDesktopFile()
396 std::ostringstream destFile;
397 destFile << GlobalConfig::GetUserWidgetDesktopPath() << "/";
398 destFile << desktop_name.str();
399 LogInfo("cp " << desktop_file.str() << " " << destFile.str());
402 DPL::FileInput input(desktop_file.str());
403 DPL::FileOutput output(destFile.str());
404 DPL::Copy(&input, &output);
407 Catch(DPL::FileInput::Exception::Base)
409 // Error while opening or closing source file
410 // ReThrowMsg(InstallerException::CopyIconFailed,
411 // desktop_file.str());
413 "Creating Desktop File Failed. Widget's icon will not be available"\
417 Catch(DPL::FileOutput::Exception::Base)
419 // Error while opening or closing target file
420 // ReThrowMsg(InstallerException::CopyIconFailed,
423 "Creating Desktop File Failed. Widget's icon will not be available"\
427 Catch(DPL::CopyFailed)
429 // Error while copying
430 // ReThrowMsg(InstallerException::CopyIconFailed,
433 "Creating Desktop File Failed. Widget's icon will not be available"\
440 unlink(desktop_file.str().c_str());
443 void TaskManifestFile::saveWidgetType(std::ofstream &file)
445 file << "Type=" << "Application" << std::endl;
448 void TaskManifestFile::saveWidgetExecPath(std::ofstream &file)
450 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
451 if (pkgname.IsNull()) {
452 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
456 file << GlobalConfig::GetUserInstalledWidgetPath() << "/";
457 file << pkgname << "/";
458 file << GlobalConfig::GetUserWidgetExecPath() << "/";
459 file << m_context.widgetHandle << std::endl;
462 void TaskManifestFile::saveWidgetVersion(std::ofstream &file)
464 DPL::OptionalString widget_version = m_context.widgetConfig.version;
465 file << "Version=" << widget_version << std::endl;
468 void TaskManifestFile::saveWidgetName(std::ofstream &file)
470 Assert(!!m_context.widgetHandle);
471 WidgetDAOReadOnly dao(*m_context.widgetHandle);
472 LanguageTagsList languageTags(dao.getLanguageTags());
473 bool defaultNameSaved = false;
474 auto generateWidgetName = [&] (const DPL::OptionalString& tag,
475 const DPL::OptionalString& language)
477 DPL::OptionalString name = dao.getLocalizedInfo(*language).name;
481 saveLocalizedKey(file, L"Name", *tag);
486 defaultNameSaved = true;
493 FOREACH(i, languageTags)
495 DPL::OptionalString tag = getLangTag(*i);// translate en -> en_US etc
496 if (tag.IsNull()) { tag = *i; }
498 generateWidgetName(tag, *i);
501 DPL::OptionalString defaultLocale = dao.getDefaultlocale();
502 if (!!defaultLocale && !defaultNameSaved)
504 generateWidgetName(DPL::OptionalString::Null, *defaultLocale);
508 void TaskManifestFile::saveWidgetIcons(std::ofstream &file)
510 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
511 if (pkgname.IsNull()) {
512 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
515 //TODO this file will need to be updated when user locale preferences
517 Assert(!!m_context.widgetHandle);
518 WidgetDAOReadOnly dao(*m_context.widgetHandle);
520 WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
521 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
523 LanguageTagsList languageTags(dao.getLanguageTags());
524 bool defaultIconSaved = false;
527 auto generateWidgetIcon = [&] (const DPL::OptionalString& tag,
528 const DPL::String& language,
533 saveLocalizedKey(file, L"Icon", *tag);
538 defaultIconSaved = true;
541 DPL::OptionalString src;
544 if (icon->iconId == iconId) {
549 //If menuscreen need use absolute path of widget's icon, comment out
550 //the following lines.
552 file << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
553 file << getIconTargetFilename(language) << std::endl;
559 DPL::String i = it->widgetLocale;
560 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
561 if (tag.IsNull()) { tag = i; }
563 generateWidgetIcon(tag, i, it->iconId);
566 DPL::OptionalString defaultLocale = dao.getDefaultlocale();
567 if (!!defaultLocale && !defaultIconSaved)
572 if (it->widgetLocale == *defaultLocale)
579 generateWidgetIcon(DPL::OptionalString::Null,
586 DPL::String TaskManifestFile::getIconTargetFilename(
587 const DPL::String& languageTag) const
589 DPL::OStringStream filename;
590 DPL::Optional<DPL::String> pkgname = m_context.widgetConfig.pkgname;
591 if (pkgname.IsNull()) {
592 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
595 filename << DPL::ToUTF8String(*pkgname).c_str();
597 if (!languageTag.empty()) {
598 DPL::OptionalString tag = getLangTag(languageTag); // translate en -> en_US etc
599 if (tag.IsNull()) { tag = languageTag; }
601 LocalizationUtils::BCP47LanguageTagToLocale(*tag);
604 filename << L"." << languageTag;
606 filename << L"." << locale;
611 return filename.str();
614 void TaskManifestFile::saveWidgetOtherInfo(std::ofstream &file)
616 DPL::Optional<DPL::String> widgetID = m_context.widgetConfig.guid;
619 // strncat(desktop, format_network, strlen(format_network));
620 // //TODO -- get the network value from the widget
621 // strncat(desktop, "True", 4);
622 // strncat(desktop, line, strlen(line));
625 file << "Comment=Widget application" << std::endl;
628 //file << "BG_SCHEDULE=True" << std::endl;
631 file << "nodisplay=FALSE" << std::endl;
633 file << "X-TIZEN-PackageType=wgt" << std::endl;
634 if (!widgetID.IsNull()) {
635 file << "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str() << std::endl;
639 void TaskManifestFile::saveAppServiceInfo(std::ofstream &file)
641 Assert(!!m_context.widgetHandle);
642 WidgetDAOReadOnly dao(*m_context.widgetHandle);
643 WidgetApplicationServiceList appServiceList;
644 dao.getAppServiceList(appServiceList);
646 if (appServiceList.empty()) {
647 LogInfo("Widget doesn't contain application service");
651 // x-tizen-svc=http://tizen.org/appsvc/operation/pick|NULL|image;
652 file << "X-TIZEN-SVC=";
653 FOREACH(it, appServiceList) {
654 if (appServiceList.begin() != it) {
657 file << DPL::ToUTF8String(it->operation).c_str() << "|";
658 if (it->scheme.empty()) {
659 file << "NULL" << "|";
661 file << DPL::ToUTF8String(it->scheme).c_str() << "|";
663 if (it->mime.empty()) {
666 file << DPL::ToUTF8String(it->mime).c_str();
671 void TaskManifestFile::stepFinalize()
673 LogInfo("Finished ManifestFile step");
676 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
677 const DPL::String& key,
678 const DPL::String& languageTag)
681 LocalizationUtils::BCP47LanguageTagToLocale(languageTag);
684 if (!locale.empty()) {
685 file << "[" << locale << "]";
690 void TaskManifestFile::updateAilInfo()
692 // Update ail for desktop
693 std::string cfgPkgname =
694 DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
695 const char* pkgname = cfgPkgname.c_str();
697 LogDebug("Update ail desktop : " << pkgname );
698 ail_appinfo_h ai = NULL;
701 ret = ail_package_get_appinfo(pkgname, &ai);
703 ail_package_destroy_appinfo(ai);
706 if (AIL_ERROR_NO_DATA == ret) {
707 if (ail_desktop_add(pkgname) < 0) {
708 LogDebug("Failed to add ail desktop : " << pkgname);
710 } else if (AIL_ERROR_OK == ret) {
711 if (ail_desktop_update(pkgname) < 0) {
712 LogDebug("Failed to update ail desktop : " << pkgname);
717 void TaskManifestFile::backupIconFiles()
719 LogInfo("Backup Icon Files");
721 std::ostringstream b_icon_dir;
722 b_icon_dir << backup_dir.str() << "icons";
724 LogDebug("Create icon backup folder : " << b_icon_dir.str());
725 _WrtMakeDir(b_icon_dir.str().c_str(), 0755, WRT_FILEUTILS_RECUR);
727 std::list<std::string> fileList;
728 getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
729 std::string pkgname = DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
731 FOREACH(it, fileList)
733 if (0 == (strncmp((*it).c_str(), pkgname.c_str(),
734 strlen(pkgname.c_str())))) {
735 std::ostringstream icon_file, backup_icon;
736 icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
737 icon_file << "/" << (*it);
739 backup_icon << b_icon_dir.str() << "/" << (*it);
741 LogDebug("Backup icon file " << icon_file.str() << " to " <<
745 DPL::FileInput input(icon_file.str());
746 DPL::FileOutput output(backup_icon.str());
747 DPL::Copy(&input, &output);
749 Catch(DPL::FileInput::Exception::Base)
751 LogError("Backup Desktop File Failed.");
752 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
755 Catch(DPL::FileOutput::Exception::Base)
757 LogError("Backup Desktop File Failed.");
758 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
760 Catch(DPL::CopyFailed)
762 LogError("Backup Desktop File Failed.");
763 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
765 unlink((*it).c_str());
770 void TaskManifestFile::backupDesktopFile()
772 LogInfo("Backup Desktop File");
774 std::ostringstream b_desktop_dir;
775 b_desktop_dir << backup_dir.str() << "desktop";
777 LogDebug("Create desktop file backup folder : " << b_desktop_dir.str());
778 _WrtMakeDir(b_desktop_dir.str().c_str(), 0755, WRT_FILEUTILS_RECUR);
780 bp_desktop_file << b_desktop_dir.str() << "/" << desktop_name.str();
784 DPL::FileInput input(desktop_file.str());
785 DPL::FileOutput output(bp_desktop_file.str());
786 DPL::Copy(&input, &output);
789 Catch(DPL::FileInput::Exception::Base)
791 ReThrowMsg(Exceptions::BackupFailed, desktop_file.str());
794 Catch(DPL::FileOutput::Exception::Base)
796 ReThrowMsg(Exceptions::BackupFailed, bp_desktop_file.str());
798 Catch(DPL::CopyFailed)
800 ReThrowMsg(Exceptions::BackupFailed, bp_desktop_file.str());
804 void TaskManifestFile::getFileList(const char* path,
805 std::list<std::string> &list)
807 DIR* dir = opendir(path);
809 LogError("icon directory doesn't exist");
810 ThrowMsg(Exceptions::InternalError, path);
813 struct dirent* d_ent;
815 if ((d_ent = readdir(dir))) {
816 if(strcmp(d_ent->d_name, ".") == 0 ||
817 strcmp(d_ent->d_name, "..") == 0) {
820 std::string file_name = d_ent->d_name;
821 list.push_back(file_name);
826 void TaskManifestFile::stepGenerateManifest()
828 DPL::String pkgname = *m_context.widgetConfig.pkgname;
829 manifest_name = pkgname + L".xml";
830 manifest_file += L"/tmp/" + manifest_name;
832 //libxml - init and check
833 LibxmlSingleton::Instance().init();
835 writeManifest(manifest_file);
839 m_context.job->UpdateProgress(
840 InstallerContext::INSTALL_CREATE_MANIFEST,
841 "Widget Manifest Creation Finished");
844 void TaskManifestFile::stepParseManifest()
846 int code = pkgmgr_parser_parse_manifest_for_installation(
847 DPL::ToUTF8String(manifest_file).c_str(), NULL);
851 LogError("Manifest parser error: " << code);
852 ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
855 // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
858 m_context.job->UpdateProgress(
859 InstallerContext::INSTALL_CREATE_MANIFEST,
860 "Widget Manifest Parsing Finished");
861 LogDebug("Manifest parsed");
864 void TaskManifestFile::stepParseUpgradedManifest()
866 int code = pkgmgr_parser_parse_manifest_for_upgrade(
867 DPL::ToUTF8String(manifest_file).c_str(), NULL);
871 LogError("Manifest parser error: " << code);
872 ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
875 // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
878 m_context.job->UpdateProgress(
879 InstallerContext::INSTALL_CREATE_MANIFEST,
880 "Widget Manifest Parsing Finished");
881 LogDebug("Manifest parsed");
884 void TaskManifestFile::validateManifest()
886 int code = pkgmgr_parser_check_manifest_validation(
887 DPL::ToUTF8String(manifest_name).c_str());
891 LogError("Manifest validation error");
892 //TODO: manifest files are not yet validating properly because of href
893 // attribute in author element (incompatible types in W3C spec. and
895 //ThrowMsg(ManifestValidationError, "Validation returncode: " << code);
898 m_context.job->UpdateProgress(
899 InstallerContext::INSTALL_CREATE_MANIFEST,
900 "Widget Manifest Validation Finished");
901 LogDebug("Manifest validated");
904 void TaskManifestFile::commitManifest()
906 LogDebug("Commiting manifest file : " << manifest_file);
908 std::ostringstream destFile;
909 destFile << "/opt/share/packages" << "/"; //TODO constant with path
910 destFile << DPL::ToUTF8String(manifest_name);
911 LogInfo("cp " << manifest_file << " " << destFile.str());
913 DPL::FileInput input(DPL::ToUTF8String(manifest_file));
914 DPL::FileOutput output(destFile.str());
915 DPL::Copy(&input, &output);
916 LogDebug("Manifest writen to: " << destFile.str());
919 unlink((DPL::ToUTF8String(manifest_file)).c_str());
920 manifest_file = DPL::FromUTF8String(destFile.str().c_str());
923 void TaskManifestFile::writeManifest(const DPL::String & path)
925 LogDebug("Generating manifest file : " << path);
929 setWidgetExecPath(uiApp);
930 setWidgetName(manifest, uiApp);
931 setWidgetIcons(uiApp);
932 setWidgetManifest(manifest);
933 setWidgetOtherInfo(uiApp);
934 setAppServiceInfo(uiApp);
936 manifest.addUiApplication(uiApp);
937 manifest.generate(path);
938 LogDebug("Manifest file serialized");
941 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp)
943 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
944 if (pkgname.IsNull()) {
945 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
948 std::ostringstream path;
949 path << GlobalConfig::GetUserInstalledWidgetPath() << "/" << *pkgname << "/";
950 path << GlobalConfig::GetUserWidgetExecPath() << "/" << *m_context.widgetHandle;
951 uiApp.setExec(DPL::FromASCIIString(path.str()));
954 void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp)
956 Assert(!!m_context.widgetHandle);
957 WidgetDAOReadOnly dao(*m_context.widgetHandle);
958 LanguageTagsList languageTags(dao.getLanguageTags());
959 bool defaultNameSaved = false;
962 FOREACH(i, languageTags)
964 DPL::OptionalString tag = getLangTag(*i); // translate en -> en_US etc
969 DPL::OptionalString name = dao.getLocalizedInfo(*i).name;
970 generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
972 DPL::OptionalString defaultLocale = dao.getDefaultlocale();
973 if (!!defaultLocale && !defaultNameSaved)
975 DPL::OptionalString name = dao.getLocalizedInfo(*defaultLocale).name;
976 generateWidgetName(manifest, uiApp, DPL::OptionalString::Null, name, defaultNameSaved);
980 if(!!m_context.widgetConfig.pkgname)
982 pkgname = *m_context.widgetConfig.pkgname;
983 uiApp.setAppid(pkgname);
987 if(!!m_context.widgetConfig.guid) {
988 uiApp.setExtraid(*m_context.widgetConfig.guid);
990 if(!pkgname.empty()) {
991 uiApp.setExtraid(DPL::String(L"http://") + pkgname);
996 uiApp.setType(DPL::FromASCIIString("webapp"));
997 manifest.setType(L"wgt");
998 uiApp.setTaskmanage(true);
1001 void TaskManifestFile::generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved)
1006 DPL::String locale =
1007 LocalizationUtils::BCP47LanguageTagToLocale(*tag);
1009 if (!locale.empty()) {
1010 uiApp.addLabel(LabelType(*name,*tag));
1014 uiApp.addLabel(LabelType(*name));
1015 manifest.addLabel(LabelType(*name));
1020 defaultNameSaved = true;
1021 uiApp.addLabel(LabelType(*name));
1022 manifest.addLabel(LabelType(*name));
1027 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
1029 DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
1030 if (pkgname.IsNull()) {
1031 ThrowMsg(Exceptions::InternalError, "No Package name exists.");
1034 //TODO this file will need to be updated when user locale preferences
1036 Assert(!!m_context.widgetHandle);
1037 WidgetDAOReadOnly dao(*m_context.widgetHandle);
1039 WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
1040 WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
1041 bool defaultIconSaved = false;
1043 FOREACH(it, locList)
1045 DPL::String i = it->widgetLocale;
1046 DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
1047 if (tag.IsNull()) { tag = i; }
1049 generateWidgetIcon(uiApp, tag, i, it->iconId, list, defaultIconSaved);
1051 DPL::OptionalString defaultLocale = dao.getDefaultlocale();
1052 if (!!defaultLocale && !defaultIconSaved)
1055 FOREACH(it, locList)
1057 if (it->widgetLocale == *defaultLocale)
1059 iconId = it->iconId;
1064 generateWidgetIcon(uiApp, DPL::OptionalString::Null,
1073 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag, const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list, bool & defaultIconSaved)
1078 locale = LocalizationUtils::BCP47LanguageTagToLocale(*tag);
1082 defaultIconSaved = true;
1085 DPL::OptionalString src;
1088 if (icon->iconId == iconId) {
1089 src = icon->iconSrc;
1093 DPL::String iconText;
1094 iconText += /*DPL::FromASCIIString(GlobalConfig::GetUserWidgetDesktopIconPath()) + L"/" +*/ getIconTargetFilename(language);
1097 uiApp.addIcon(IconType(iconText,locale));
1101 uiApp.addIcon(IconType(iconText));
1106 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
1108 if(!!m_context.widgetConfig.pkgname)
1110 manifest.setPackage(*m_context.widgetConfig.pkgname);
1112 if(!!m_context.widgetConfig.version)
1114 manifest.setVersion(*m_context.widgetConfig.version);
1116 DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
1117 *m_context.widgetConfig.configInfo.authorEmail : L"");
1118 DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
1119 *m_context.widgetConfig.configInfo.authorHref : L"");
1120 DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
1121 *m_context.widgetConfig.configInfo.authorName : L"");
1122 manifest.addAuthor(Author(email,href,L"",name));
1125 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
1127 uiApp.setNodisplay(false);
1129 //There is no "X-TIZEN-PackageType=wgt", there is not field in manifest
1130 //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str()
1131 //There is no Comment in pkgmgr "Comment=Widget application"
1134 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
1136 Assert(!!m_context.widgetHandle);
1137 WidgetDAOReadOnly dao(*m_context.widgetHandle);
1138 WidgetApplicationServiceList appServiceList;
1139 dao.getAppServiceList(appServiceList);
1141 if (appServiceList.empty()) {
1142 LogInfo("Widget doesn't contain application service");
1146 // x-tizen-svc=http://tizen.org/appsvc/operation/pick|NULL|image;
1147 FOREACH(it, appServiceList) {
1148 ApplicationService appService;
1149 appService.addOperation(it->operation);
1150 appService.addOperation(it->scheme);
1151 appService.addOperation(it->mime);
1152 uiApp.addApplicationService(appService);
1156 } //namespace WidgetInstall