908c698698b49f36a5eb88b875158bd715780ade
[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     setAppCategory(uiApp);
552
553     manifest.addUiApplication(uiApp);
554     manifest.generate(path);
555     LogDebug("Manifest file serialized");
556 }
557
558 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp)
559 {
560     uiApp.setExec(DPL::FromASCIIString(m_context.locations->getExecFile()));
561 }
562
563 void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp)
564 {
565     bool defaultNameSaved = false;
566
567     DPL::OptionalString defaultLocale = m_context.widgetConfig.configInfo.defaultlocale;
568     std::pair<DPL::String, WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
569     //labels
570     FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
571     {
572         Locale i = localizedData->first;
573         DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
574         if (tag.IsNull())
575         {
576             tag = i;
577         }
578         DPL::OptionalString name = localizedData->second.name;
579         generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
580
581         //store default locale localized data
582         if(!!defaultLocale && defaultLocale == i)
583         {
584             defaultLocalizedData = *localizedData;
585         }
586     }
587
588     if (!!defaultLocale && !defaultNameSaved)
589     {
590         DPL::OptionalString name = defaultLocalizedData.second.name;
591         generateWidgetName(manifest, uiApp, DPL::OptionalString::Null, name, defaultNameSaved);
592     }
593     //appid
594     DPL::String pkgname;
595     if(!!m_context.widgetConfig.pkgname)
596     {
597         pkgname = *m_context.widgetConfig.pkgname;
598         uiApp.setAppid(pkgname);
599     }
600
601     //extraid
602     if(!!m_context.widgetConfig.guid) {
603         uiApp.setExtraid(*m_context.widgetConfig.guid);
604     } else {
605         if(!pkgname.empty()) {
606             uiApp.setExtraid(DPL::String(L"http://") + pkgname);
607         }
608     }
609
610     //type
611     uiApp.setType(DPL::FromASCIIString("webapp"));
612     manifest.setType(L"wgt");
613     uiApp.setTaskmanage(true);
614 }
615
616 void TaskManifestFile::generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved)
617 {
618     if (!!name) {
619         if (!!tag)
620         {
621             DPL::String locale =
622                     LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
623
624             if (!locale.empty()) {
625                 uiApp.addLabel(LabelType(*name,*tag));
626             }
627             else
628             {
629                 uiApp.addLabel(LabelType(*name));
630                 manifest.addLabel(LabelType(*name));
631             }
632         }
633         else
634         {
635             defaultNameSaved = true;
636             uiApp.addLabel(LabelType(*name));
637             manifest.addLabel(LabelType(*name));
638         }
639     }
640 }
641
642 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
643 {
644     DPL::OptionalString pkgname = m_context.widgetConfig.pkgname;
645     if (pkgname.IsNull()) {
646         ThrowMsg(Exceptions::InternalError, "No Package name exists.");
647     }
648
649     //TODO this file will need to be updated when user locale preferences
650     //changes.
651     bool defaultIconSaved = false;
652
653     DPL::OptionalString defaultLocale = m_context.widgetConfig.configInfo.defaultlocale;
654
655     std::vector<Locale> generatedLocales;
656     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = m_context.widgetConfig.localizationData.icons;
657
658     //reversed: last <icon> has highest priority to be writen to manifest if it has given locale (TODO: why was that working that way?)
659     for(WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator icon = icons.rbegin(); icon != icons.rend(); icon++)
660     {
661         FOREACH(locale, icon->availableLocales)
662         {
663             if(std::find(generatedLocales.begin(), generatedLocales.end(), *locale) != generatedLocales.end())
664             {
665                 LogDebug("Skipping - has that locale - already in manifest");
666                 continue;
667             }
668             else
669             {
670                 generatedLocales.push_back(*locale);
671             }
672
673             DPL::OptionalString tag = getLangTag(*locale); // translate en -> en_US etc
674             if (tag.IsNull()) { tag = *locale; }
675
676             generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
677         }
678     }
679     if (!!defaultLocale && !defaultIconSaved)
680     {
681         generateWidgetIcon(uiApp, DPL::OptionalString::Null,
682                            DPL::String(),
683                            defaultIconSaved);
684     }
685 }
686
687 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag,
688         const DPL::String& language, bool & defaultIconSaved)
689 {
690     DPL::String locale;
691     if (!!tag)
692     {
693         locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
694     }
695     else
696     {
697         defaultIconSaved = true;
698     }
699
700     DPL::String iconText;
701     iconText += getIconTargetFilename(language);
702
703     if(!locale.empty())
704     {
705         uiApp.addIcon(IconType(iconText, locale));
706     }
707     else
708     {
709         uiApp.addIcon(IconType(iconText));
710     }
711 }
712
713 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
714 {
715     if(!!m_context.widgetConfig.pkgname)
716     {
717         manifest.setPackage(*m_context.widgetConfig.pkgname);
718     }
719     if(!!m_context.widgetConfig.version)
720     {
721         manifest.setVersion(*m_context.widgetConfig.version);
722     }
723     DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
724                             *m_context.widgetConfig.configInfo.authorEmail : L"");
725     DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
726                             *m_context.widgetConfig.configInfo.authorHref : L"");
727     DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
728                             *m_context.widgetConfig.configInfo.authorName : L"");
729     manifest.addAuthor(Author(email,href,L"",name));
730 }
731
732 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
733 {
734     FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
735     {
736          if(!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
737              if(!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
738                 uiApp.setNodisplay(true);
739              }
740              else {
741                 uiApp.setNodisplay(false);
742             }
743          }
744      }
745     //TODO
746     //There is no "X-TIZEN-PackageType=wgt"
747     //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str()
748     //There is no Comment in pkgmgr "Comment=Widget application"
749     //that were in desktop file
750 }
751
752 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
753 {
754     WrtDB::ConfigParserData::ServiceInfoList appServiceList = m_context.widgetConfig.configInfo.appServiceList;
755
756     if (appServiceList.empty()) {
757         LogInfo("Widget doesn't contain application service");
758         return;
759     }
760
761     // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
762     FOREACH(it, appServiceList) {
763         AppControl appControl;
764         if (!it->m_operation.empty()) {
765             appControl.addOperation(it->m_operation); //TODO: encapsulation?
766         }
767         if (!it->m_scheme.empty()) {
768             appControl.addUri(it->m_scheme);
769         }
770         if (!it->m_mime.empty()) {
771             appControl.addMime(it->m_mime);
772         }
773         uiApp.addAppControl(appControl);
774     }
775 }
776
777 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
778 {
779     WrtDB::ConfigParserData::CategoryList categoryList =
780         m_context.widgetConfig.configInfo.categoryList;
781
782     if (categoryList.empty()) {
783         LogInfo("Widget doesn't contain application category");
784         return;
785     }
786     FOREACH(it, categoryList) {
787         if (!(*it).empty()) {
788             uiApp.addAppCategory(*it);
789         }
790     }
791 }
792
793 } //namespace WidgetInstall
794 } //namespace Jobs