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