Update wrt-installer_0.0.54
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_manifest_file.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_manifest_file.cpp
18  * @author  Pawel Sikorski (p.sikorski@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 //SYSTEM INCLUDES
24 #include <string>
25 #include <dpl/assert.h>
26 #include <dirent.h>
27 #include <fstream>
28 #include <ail.h>
29
30 //WRT INCLUDES
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>
39 #include <dpl/copy.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>
46 #include <map>
47 #include <libxml_utils.h>
48 #include <pkgmgr/pkgmgr_parser.h>
49
50 #define DEFAULT_ICON_NAME   "icon.png"
51
52 using namespace WrtDB;
53
54 namespace {
55 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
56
57 LanguageTagMap getLanguageTagMap()
58 {
59     LanguageTagMap map;
60
61 #define ADD(tag, l_tag) map.insert(std::make_pair(L ## # tag, L ## # l_tag));
62 #include "languages.def"
63 #undef ADD
64
65     return map;
66 }
67
68 DPL::OptionalString getLangTag(const DPL::String& tag)
69 {
70     static LanguageTagMap TagsMap =
71         getLanguageTagMap();
72
73     DPL::String langTag = tag;
74
75     LogDebug("Trying to map language tag: " << langTag);
76     size_t pos = langTag.find_first_of(L'_');
77     if (pos != DPL::String::npos) {
78         langTag.erase(pos);
79     }
80     DPL::OptionalString ret;
81
82     LanguageTagMap::iterator it = TagsMap.find(langTag);
83     if (it != TagsMap.end()) {
84         ret = it->second;
85     }
86     LogDebug("Mapping IANA Language tag to language tag: " <<
87              langTag << " -> " << ret);
88
89     return ret;
90 }
91 }
92
93 namespace Jobs {
94 namespace WidgetInstall {
95
96 const char * TaskManifestFile::encoding = "UTF-8";
97
98 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
99     DPL::TaskDecl<TaskManifestFile>(this),
100     m_context(inCont)
101 {
102     if (false == m_context.existingWidgetInfo.isExist) {
103         AddStep(&TaskManifestFile::stepCopyIconFiles);
104         AddStep(&TaskManifestFile::stepCreateExecFile);
105         AddStep(&TaskManifestFile::stepGenerateManifest);
106         AddStep(&TaskManifestFile::stepParseManifest);
107         AddStep(&TaskManifestFile::stepFinalize);
108     } else {
109     // for widget update.
110         AddStep(&TaskManifestFile::stepBackupIconFiles);
111         AddStep(&TaskManifestFile::stepCopyIconFiles);
112         AddStep(&TaskManifestFile::stepGenerateManifest);
113         AddStep(&TaskManifestFile::stepParseUpgradedManifest);
114         AddStep(&TaskManifestFile::stepUpdateFinalize);
115
116         AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
117     }
118 }
119
120 TaskManifestFile::~TaskManifestFile()
121 {
122 }
123
124 void TaskManifestFile::stepCreateExecFile()
125 {
126     //ln -s /usr/bin/wrt-client {widget-handle}
127
128     std::ostringstream real_path;
129     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
130     if (pkgname.IsNull()) {
131         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
132     }
133
134     real_path << m_context.locations->getBinaryDir() << "/" << m_context.widgetHandle;
135     std::string clientExeStr = GlobalConfig::GetWrtClientExec();
136
137     LogInfo("link -s " << clientExeStr << " " << real_path.str());
138     symlink(clientExeStr.c_str(), real_path.str().c_str());
139
140     m_context.job->UpdateProgress(
141         InstallerContext::INSTALL_CREATE_EXECFILE,
142         "Widget execfile creation Finished");
143 }
144
145 void TaskManifestFile::stepCopyIconFiles()
146 {
147     LogDebug("CopyIconFiles");
148
149     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
150     if (pkgname.IsNull()) {
151         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
152     }
153     Assert(!!m_context.widgetHandle);
154
155     WidgetDAOReadOnly dao(*m_context.widgetHandle);
156     WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
157     WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
158
159     FOREACH(it, locList)
160     {
161         DPL::String i = it->widgetLocale;
162         DPL::OptionalString src;
163         FOREACH(icon, list)
164         {
165             if (icon->iconId == it->iconId) {
166                 src = icon->iconSrc;
167             }
168         }
169         LogDebug("Icon for locale: " << i << "is : " << src);
170
171         std::ostringstream sourceFile;
172         std::ostringstream targetFile;
173
174         if (!!src) {
175
176             sourceFile << m_context.locations->getSourceDir() << "/";
177
178             if (!i.empty()) {
179                 sourceFile << "locales/" << i << "/";
180             }
181
182             sourceFile << *src;
183
184             targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
185             targetFile << getIconTargetFilename(i);
186
187             if (m_context.locations->browserRequest())
188             {
189                 m_context.locations->setIconTargetFilenameForLocale(targetFile.str());
190             }
191
192         } else {
193             //Use WRT default (not from the widget) only if widget default (not
194             // localized) doesn't exist.
195             if (i.empty()) {
196                 LogError("Using Default Icon for widget");
197                 sourceFile << GlobalConfig::GetUserWidgetDefaultIconFile();
198             } else {
199                 continue;
200             }
201         }
202
203         LogDebug("Copying icon: " << sourceFile.str() <<
204                  " -> " << targetFile.str());
205
206         icon_list.push_back(targetFile.str());
207
208         Try
209         {
210             DPL::FileInput input(sourceFile.str());
211             DPL::FileOutput output(targetFile.str());
212             DPL::Copy(&input, &output);
213         }
214
215         Catch(DPL::FileInput::Exception::Base)
216         {
217             // Error while opening or closing source file
218             //ReThrowMsg(InstallerException::CopyIconFailed, sourceFile.str());
219             LogError(
220                 "Copying widget's icon failed. Widget's icon will not be"\
221                 "available from Main Screen");
222         }
223
224         Catch(DPL::FileOutput::Exception::Base)
225         {
226             // Error while opening or closing target file
227             //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
228             LogError(
229                 "Copying widget's icon failed. Widget's icon will not be"\
230                 "available from Main Screen");
231         }
232
233         Catch(DPL::CopyFailed)
234         {
235             // Error while copying
236             //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
237             LogError(
238                 "Copying widget's icon failed. Widget's icon will not be"\
239                 "available from Main Screen");
240         }
241     }
242
243     m_context.job->UpdateProgress(
244         InstallerContext::INSTALL_COPY_ICONFILE,
245         "Widget iconfile copy Finished");
246 }
247
248 void TaskManifestFile::stepBackupIconFiles()
249 {
250     LogDebug("Backup Icon Files");
251
252     backup_dir << m_context.locations->getPackageInstallationDir();
253     backup_dir << "/" << "backup" << "/";
254
255     backupIconFiles();
256
257     m_context.job->UpdateProgress(
258         InstallerContext::INSTALL_BACKUP_ICONFILE,
259         "New Widget icon file backup Finished");
260 }
261
262 void TaskManifestFile::stepAbortIconFiles()
263 {
264     LogDebug("Abrot Icon Files");
265     FOREACH(it, icon_list)
266     {
267         LogDebug("Remove Update Icon : " << (*it));
268         unlink((*it).c_str());
269     }
270
271     std::ostringstream b_icon_dir;
272     b_icon_dir << backup_dir.str() << "icons";
273
274     std::list<std::string> fileList;
275     getFileList(b_icon_dir.str().c_str(), fileList);
276
277     FOREACH(back_icon, fileList)
278     {
279         std::ostringstream res_file;
280         res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
281         res_file << "/" << (*back_icon);
282
283         std::ostringstream backup_file;
284         backup_file << b_icon_dir.str() << "/" << (*back_icon);
285
286         Try
287         {
288             DPL::FileInput input(backup_file.str());
289             DPL::FileOutput output(res_file.str());
290             DPL::Copy(&input, &output);
291         }
292         Catch(DPL::FileInput::Exception::Base)
293         {
294             LogError("Restoration icon File Failed." << backup_file.str()
295                     << " to " << res_file.str());
296         }
297
298         Catch(DPL::FileOutput::Exception::Base)
299         {
300             LogError("Restoration icon File Failed." << backup_file.str()
301                     << " to " << res_file.str());
302         }
303         Catch(DPL::CopyFailed)
304         {
305             LogError("Restoration icon File Failed." << backup_file.str()
306                     << " to " << res_file.str());
307         }
308     }
309 }
310
311 void TaskManifestFile::stepUpdateFinalize()
312 {
313     LogDebug("Finished Update Desktopfile");
314 }
315
316 DPL::String TaskManifestFile::getIconTargetFilename(
317         const DPL::String& languageTag) const
318 {
319     DPL::OStringStream filename;
320     DPL::Optional<DPL::String> pkgname = m_context.widgetConfig.pkgname;
321     if (pkgname.IsNull()) {
322         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
323     }
324
325     filename << DPL::ToUTF8String(*pkgname).c_str();
326
327     if (!languageTag.empty()) {
328         DPL::OptionalString tag = getLangTag(languageTag); // translate en -> en_US etc
329         if (tag.IsNull()) { tag = languageTag; }
330         DPL::String locale =
331             LocalizationUtils::BCP47LanguageTagToLocale(*tag);
332
333        if(locale.empty()) {
334             filename << L"." << languageTag;
335         } else {
336             filename << L"." << locale;
337         }
338     }
339
340     filename << L".png";
341     return filename.str();
342 }
343
344 void TaskManifestFile::stepFinalize()
345 {
346     LogInfo("Finished ManifestFile step");
347 }
348
349
350 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
351         const DPL::String& key,
352         const DPL::String& languageTag)
353 {
354     DPL::String locale =
355         LocalizationUtils::BCP47LanguageTagToLocale(languageTag);
356
357     file << key;
358     if (!locale.empty()) {
359         file << "[" << locale << "]";
360     }
361     file << "=";
362 }
363
364 void TaskManifestFile::updateAilInfo()
365 {
366     // Update ail for desktop
367     std::string cfgPkgname =
368         DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
369     const char* pkgname = cfgPkgname.c_str();
370
371     LogDebug("Update ail desktop : " << pkgname );
372     ail_appinfo_h ai = NULL;
373     ail_error_e ret;
374
375     ret = ail_package_get_appinfo(pkgname, &ai);
376     if (ai) {
377         ail_package_destroy_appinfo(ai);
378     }
379     
380     if (AIL_ERROR_NO_DATA == ret) {
381         if (ail_desktop_add(pkgname) < 0) {
382             LogDebug("Failed to add ail desktop : " << pkgname);
383         }
384     } else if (AIL_ERROR_OK == ret) {
385         if (ail_desktop_update(pkgname) < 0) {
386             LogDebug("Failed to update ail desktop : " << pkgname);
387         }
388     }
389 }
390
391 void TaskManifestFile::backupIconFiles()
392 {
393     LogInfo("Backup Icon Files");
394
395     std::ostringstream b_icon_dir;
396     b_icon_dir << backup_dir.str() << "icons";
397
398     LogDebug("Create icon backup folder : " << b_icon_dir.str());
399     _WrtMakeDir(b_icon_dir.str().c_str(), 0755, WRT_FILEUTILS_RECUR);
400
401     std::list<std::string> fileList;
402     getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
403     std::string pkgname = DPL::ToUTF8String(*m_context.widgetConfig.pkgname);
404     
405     FOREACH(it, fileList)
406     {
407         if (0 == (strncmp((*it).c_str(), pkgname.c_str(),
408                         strlen(pkgname.c_str())))) {
409             std::ostringstream icon_file, backup_icon;
410             icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
411             icon_file << "/" << (*it);
412
413             backup_icon << b_icon_dir.str() << "/" << (*it);
414
415             LogDebug("Backup icon file " << icon_file.str() << " to " <<
416                     backup_icon.str());
417             Try
418             {
419                 DPL::FileInput input(icon_file.str());
420                 DPL::FileOutput output(backup_icon.str());
421                 DPL::Copy(&input, &output);
422             }
423             Catch(DPL::FileInput::Exception::Base)
424             {
425                 LogError("Backup Desktop File Failed.");
426                 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
427             }
428
429             Catch(DPL::FileOutput::Exception::Base)
430             {
431                 LogError("Backup Desktop File Failed.");
432                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
433             }
434             Catch(DPL::CopyFailed)
435             {
436                 LogError("Backup Desktop File Failed.");
437                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
438             }
439             unlink((*it).c_str());
440         }
441     }
442 }
443
444 void TaskManifestFile::getFileList(const char* path,
445         std::list<std::string> &list)
446 {
447     DIR* dir = opendir(path);
448     if (!dir) {
449         LogError("icon directory doesn't exist");
450         ThrowMsg(Exceptions::InternalError, path);
451     }
452
453     struct dirent* d_ent;
454     do {
455         if ((d_ent = readdir(dir))) {
456             if(strcmp(d_ent->d_name, ".") == 0 || 
457                     strcmp(d_ent->d_name, "..") == 0) {
458                 continue;
459             }
460             std::string file_name = d_ent->d_name;
461             list.push_back(file_name);
462         }
463     }while(d_ent);
464 }
465
466 void TaskManifestFile::stepGenerateManifest()
467 {
468     DPL::String pkgname = *m_context.widgetConfig.pkgname;
469     manifest_name = pkgname + L".xml";
470     manifest_file += L"/tmp/" + manifest_name;
471
472     //libxml - init and check
473     LibxmlSingleton::Instance().init();
474
475     writeManifest(manifest_file);
476     validateManifest();
477     commitManifest();
478
479     m_context.job->UpdateProgress(
480         InstallerContext::INSTALL_CREATE_MANIFEST,
481         "Widget Manifest Creation Finished");
482 }
483
484 void TaskManifestFile::stepParseManifest()
485 {
486     int code = pkgmgr_parser_parse_manifest_for_installation(
487             DPL::ToUTF8String(manifest_file).c_str(), NULL);
488
489     if(code != 0)
490     {
491         LogError("Manifest parser error: " << code);
492         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
493     }
494
495     // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
496     updateAilInfo();
497
498     m_context.job->UpdateProgress(
499         InstallerContext::INSTALL_CREATE_MANIFEST,
500         "Widget Manifest Parsing Finished");
501     LogDebug("Manifest parsed");
502 }
503
504 void TaskManifestFile::stepParseUpgradedManifest()
505 {
506     int code = pkgmgr_parser_parse_manifest_for_upgrade(
507             DPL::ToUTF8String(manifest_file).c_str(), NULL);
508
509     if(code != 0)
510     {
511         LogError("Manifest parser error: " << code);
512         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
513     }
514
515     // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
516     updateAilInfo();
517
518     m_context.job->UpdateProgress(
519         InstallerContext::INSTALL_CREATE_MANIFEST,
520         "Widget Manifest Parsing Finished");
521     LogDebug("Manifest parsed");
522 }
523
524 void TaskManifestFile::validateManifest()
525 {
526     int code = pkgmgr_parser_check_manifest_validation(
527             DPL::ToUTF8String(manifest_name).c_str());
528
529     if(code != 0)
530     {
531         LogError("Manifest validation error");
532         //TODO: manifest files are not yet validating properly because of href
533         // attribute in author element (incompatible types in W3C spec. and
534         // manifest spec.)
535         //ThrowMsg(ManifestValidationError, "Validation returncode: " << code);
536     }
537
538     m_context.job->UpdateProgress(
539         InstallerContext::INSTALL_CREATE_MANIFEST,
540         "Widget Manifest Validation Finished");
541     LogDebug("Manifest validated");
542 }
543
544 void TaskManifestFile::commitManifest()
545 {
546     LogDebug("Commiting manifest file : " << manifest_file);
547
548     std::ostringstream destFile;
549     destFile << "/opt/share/packages" << "/"; //TODO constant with path
550     destFile << DPL::ToUTF8String(manifest_name);
551     LogInfo("cp " << manifest_file << " " << destFile.str());
552
553     DPL::FileInput input(DPL::ToUTF8String(manifest_file));
554     DPL::FileOutput output(destFile.str());
555     DPL::Copy(&input, &output);
556     LogDebug("Manifest writen to: " << destFile.str());
557
558     //removing temp file
559     unlink((DPL::ToUTF8String(manifest_file)).c_str());
560     manifest_file = DPL::FromUTF8String(destFile.str().c_str());
561 }
562
563 void TaskManifestFile::writeManifest(const DPL::String & path)
564 {
565     LogDebug("Generating manifest file : " << path);
566     Manifest manifest;
567     UiApplication uiApp;
568
569     setWidgetExecPath(uiApp);
570     setWidgetName(manifest, uiApp);
571     setWidgetIcons(uiApp);
572     setWidgetManifest(manifest);
573     setWidgetOtherInfo(uiApp);
574     setAppServiceInfo(uiApp);
575
576     manifest.addUiApplication(uiApp);
577     manifest.generate(path);
578     LogDebug("Manifest file serialized");
579 }
580
581 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp)
582 {
583     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
584     if (pkgname.IsNull()) {
585         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
586     }
587
588     std::ostringstream path;
589     path << m_context.locations->getBinaryDir() << "/" << *m_context.widgetHandle;
590     uiApp.setExec(DPL::FromASCIIString(path.str()));
591 }
592
593 void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp)
594 {
595     Assert(!!m_context.widgetHandle);
596     WidgetDAOReadOnly dao(*m_context.widgetHandle);
597     LanguageTagsList languageTags(dao.getLanguageTags());
598     bool defaultNameSaved = false;
599
600     //labels
601     FOREACH(i, languageTags)
602     {
603         DPL::OptionalString tag = getLangTag(*i); // translate en -> en_US etc
604         if (tag.IsNull())
605         {
606             tag = *i;
607         }
608         DPL::OptionalString name = dao.getLocalizedInfo(*i).name;
609         generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
610     }
611     DPL::OptionalString defaultLocale = dao.getDefaultlocale();
612     if (!!defaultLocale && !defaultNameSaved)
613     {
614         DPL::OptionalString name = dao.getLocalizedInfo(*defaultLocale).name;
615         generateWidgetName(manifest, uiApp, DPL::OptionalString::Null, name, defaultNameSaved);
616     }
617     //appid
618     DPL::String pkgname;
619     if(!!m_context.widgetConfig.pkgname)
620     {
621         pkgname = *m_context.widgetConfig.pkgname;
622         uiApp.setAppid(pkgname);
623     }
624
625     //extraid
626     if(!!m_context.widgetConfig.guid) {
627         uiApp.setExtraid(*m_context.widgetConfig.guid);
628     } else {
629         if(!pkgname.empty()) {
630             uiApp.setExtraid(DPL::String(L"http://") + pkgname);
631         }
632     }
633
634     //type
635     uiApp.setType(DPL::FromASCIIString("webapp"));
636     manifest.setType(L"wgt");
637     uiApp.setTaskmanage(true);
638 }
639
640 void TaskManifestFile::generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved)
641 {
642     if (!!name) {
643         if (!!tag)
644         {
645             DPL::String locale =
646                 LocalizationUtils::BCP47LanguageTagToLocale(*tag);
647
648             if (!locale.empty()) {
649                 uiApp.addLabel(LabelType(*name,*tag));
650             }
651             else
652             {
653                 uiApp.addLabel(LabelType(*name));
654                 manifest.addLabel(LabelType(*name));
655             }
656         }
657         else
658         {
659             defaultNameSaved = true;
660             uiApp.addLabel(LabelType(*name));
661             manifest.addLabel(LabelType(*name));
662         }
663     }
664 }
665
666 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
667 {
668     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
669     if (pkgname.IsNull()) {
670         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
671     }
672
673     //TODO this file will need to be updated when user locale preferences
674     //changes.
675     Assert(!!m_context.widgetHandle);
676     WidgetDAOReadOnly dao(*m_context.widgetHandle);
677
678     WidgetDAOReadOnly::WidgetLocalizedIconList locList = dao.getLocalizedIconList();
679     WidgetDAOReadOnly::WidgetIconList list = dao.getIconList();
680     bool defaultIconSaved = false;
681
682     FOREACH(it, locList)
683     {
684         DPL::String i = it->widgetLocale;
685         DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
686         if (tag.IsNull()) { tag = i; }
687
688         generateWidgetIcon(uiApp, tag, i, it->iconId, list, defaultIconSaved);
689     }
690     DPL::OptionalString defaultLocale = dao.getDefaultlocale();
691     if (!!defaultLocale && !defaultIconSaved)
692     {
693         int iconId = -1;
694         FOREACH(it, locList)
695         {
696             if (it->widgetLocale == *defaultLocale)
697             {
698                 iconId = it->iconId;
699             }
700         }
701         if (-1 != iconId)
702         {
703             generateWidgetIcon(uiApp, DPL::OptionalString::Null,
704                                DPL::String(),
705                                iconId,
706                                list,
707                                defaultIconSaved);
708         }
709     }
710 }
711
712 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag,
713         const DPL::String& language, int iconId, const WrtDB::WidgetDAOReadOnly::WidgetIconList & list,
714         bool & defaultIconSaved)
715 {
716     DPL::String locale;
717     if (!!tag)
718     {
719         locale = LocalizationUtils::BCP47LanguageTagToLocale(*tag);
720     }
721     else
722     {
723         defaultIconSaved = true;
724     }
725
726     DPL::OptionalString src;
727     FOREACH(icon, list)
728     {
729         if (icon->iconId == iconId) {
730             src = icon->iconSrc;
731         }
732     }
733     if (!!src) {
734         DPL::String iconText;
735         iconText += getIconTargetFilename(language);
736
737         if(!locale.empty())
738         {
739             uiApp.addIcon(IconType(iconText,locale));
740         }
741         else
742         {
743             uiApp.addIcon(IconType(iconText));
744         }
745     }
746 }
747
748 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
749 {
750     if(!!m_context.widgetConfig.pkgname)
751     {
752         manifest.setPackage(*m_context.widgetConfig.pkgname);
753     }
754     if(!!m_context.widgetConfig.version)
755     {
756         manifest.setVersion(*m_context.widgetConfig.version);
757     }
758     DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
759                             *m_context.widgetConfig.configInfo.authorEmail : L"");
760     DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
761                             *m_context.widgetConfig.configInfo.authorHref : L"");
762     DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
763                             *m_context.widgetConfig.configInfo.authorName : L"");
764     manifest.addAuthor(Author(email,href,L"",name));
765 }
766
767 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
768 {
769     uiApp.setNodisplay(false);
770     //TODO
771     //There is no "X-TIZEN-PackageType=wgt"
772     //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str()
773     //There is no Comment in pkgmgr "Comment=Widget application"
774     //that were in desktop file
775 }
776
777 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
778 {
779     Assert(!!m_context.widgetHandle);
780     WidgetDAOReadOnly dao(*m_context.widgetHandle);
781     WidgetApplicationServiceList appServiceList;
782     dao.getAppServiceList(appServiceList);
783
784     if (appServiceList.empty()) {
785         LogInfo("Widget doesn't contain application service");
786         return;
787     }
788
789     // x-tizen-svc=http://tizen.org/appsvc/operation/pick|NULL|image;
790     FOREACH(it, appServiceList) {
791         ApplicationService appService;
792         appService.addOperation(it->operation);
793         appService.addOperation(it->scheme);
794         appService.addOperation(it->mime);
795         uiApp.addApplicationService(appService);
796     }
797 }
798
799 } //namespace WidgetInstall
800 } //namespace Jobs