[Release] wrt-installer_0.0.91 for sdk branch
[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
114         AddAbortStep(&TaskManifestFile::stepAbortParseManifest);
115     } else {
116     // for widget update.
117         AddStep(&TaskManifestFile::stepBackupIconFiles);
118         AddStep(&TaskManifestFile::stepCopyIconFiles);
119         AddStep(&TaskManifestFile::stepGenerateManifest);
120         AddStep(&TaskManifestFile::stepParseUpgradedManifest);
121         AddStep(&TaskManifestFile::stepUpdateFinalize);
122
123         AddAbortStep(&TaskManifestFile::stepAbortIconFiles);
124     }
125 }
126
127 TaskManifestFile::~TaskManifestFile()
128 {
129 }
130
131 void TaskManifestFile::stepCreateExecFile()
132 {
133     std::string exec = m_context.locations->getExecFile();
134     std::string clientExeStr = GlobalConfig::GetWrtClientExec();
135
136     LogInfo("link -s " << clientExeStr << " " << exec);
137     symlink(clientExeStr.c_str(), exec.c_str());
138
139     m_context.job->UpdateProgress(
140         InstallerContext::INSTALL_CREATE_EXECFILE,
141         "Widget execfile creation Finished");
142 }
143
144 void TaskManifestFile::stepCopyIconFiles()
145 {
146     LogDebug("CopyIconFiles");
147
148     //This function copies icon to desktop icon path. For each locale avaliable
149     //which there is at least one icon in widget for, icon file is copied.
150     //Coping prioritize last positions when coping. If there is several icons
151     //with given locale, the one, that will be copied, will be icon
152     //which is declared by <icon> tag later than the others in config.xml of widget
153
154     std::vector<Locale> generatedLocales;
155
156     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = m_context.widgetConfig.localizationData.icons;
157
158     //reversed: last <icon> has highest priority to be copied if it has given locale (TODO: why was that working that way?)
159     for(WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator icon = icons.rbegin(); icon != icons.rend(); icon++)
160     {
161         FOREACH(locale, icon->availableLocales)
162         {
163             DPL::String src = icon->src;
164             LogDebug("Icon for locale: " << *locale << "is : " << src);
165
166             if(std::find(generatedLocales.begin(), generatedLocales.end(), *locale) != generatedLocales.end())
167             {
168                 LogDebug("Skipping - has that locale");
169                 continue;
170             }
171             else
172             {
173                 generatedLocales.push_back(*locale);
174             }
175
176             std::ostringstream sourceFile;
177             std::ostringstream targetFile;
178
179             sourceFile << m_context.locations->getSourceDir() << "/";
180
181             if (!locale->empty()) {
182                 sourceFile << "locales/" << *locale << "/";
183             }
184
185             sourceFile << src;
186
187             targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
188             targetFile << getIconTargetFilename(*locale);
189
190
191             if (m_context.widgetConfig.packagingType ==
192                     WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
193                 m_context.locations->setIconTargetFilenameForLocale(targetFile.str());
194             }
195
196             LogDebug("Copying icon: " << sourceFile.str() <<
197                      " -> " << targetFile.str());
198
199             icon_list.push_back(targetFile.str());
200
201             Try
202             {
203                 DPL::FileInput input(sourceFile.str());
204                 DPL::FileOutput output(targetFile.str());
205                 DPL::Copy(&input, &output);
206             }
207
208             Catch(DPL::FileInput::Exception::Base)
209             {
210                 // Error while opening or closing source file
211                 //ReThrowMsg(InstallerException::CopyIconFailed, sourceFile.str());
212                 LogError(
213                     "Copying widget's icon failed. Widget's icon will not be"\
214                     "available from Main Screen");
215             }
216
217             Catch(DPL::FileOutput::Exception::Base)
218             {
219                 // Error while opening or closing target file
220                 //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
221                 LogError(
222                     "Copying widget's icon failed. Widget's icon will not be"\
223                     "available from Main Screen");
224             }
225
226             Catch(DPL::CopyFailed)
227             {
228                 // Error while copying
229                 //ReThrowMsg(InstallerException::CopyIconFailed, targetFile.str());
230                 LogError(
231                     "Copying widget's icon failed. Widget's icon will not be"\
232                     "available from Main Screen");
233             }
234         }
235     }
236
237     m_context.job->UpdateProgress(
238         InstallerContext::INSTALL_COPY_ICONFILE,
239         "Widget iconfile copy Finished");
240 }
241
242 void TaskManifestFile::stepBackupIconFiles()
243 {
244     LogDebug("Backup Icon Files");
245
246     backup_dir << m_context.locations->getPackageInstallationDir();
247     backup_dir << "/" << "backup" << "/";
248
249     backupIconFiles();
250
251     m_context.job->UpdateProgress(
252         InstallerContext::INSTALL_BACKUP_ICONFILE,
253         "New Widget icon file backup Finished");
254 }
255
256 void TaskManifestFile::stepAbortIconFiles()
257 {
258     LogDebug("Abrot Icon Files");
259     FOREACH(it, icon_list)
260     {
261         LogDebug("Remove Update Icon : " << (*it));
262         unlink((*it).c_str());
263     }
264
265     std::ostringstream b_icon_dir;
266     b_icon_dir << backup_dir.str() << "icons";
267
268     std::list<std::string> fileList;
269     getFileList(b_icon_dir.str().c_str(), fileList);
270
271     FOREACH(back_icon, fileList)
272     {
273         std::ostringstream res_file;
274         res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
275         res_file << "/" << (*back_icon);
276
277         std::ostringstream backup_file;
278         backup_file << b_icon_dir.str() << "/" << (*back_icon);
279
280         Try
281         {
282             DPL::FileInput input(backup_file.str());
283             DPL::FileOutput output(res_file.str());
284             DPL::Copy(&input, &output);
285         }
286         Catch(DPL::FileInput::Exception::Base)
287         {
288             LogError("Restoration icon File Failed." << backup_file.str()
289                     << " to " << res_file.str());
290         }
291
292         Catch(DPL::FileOutput::Exception::Base)
293         {
294             LogError("Restoration icon File Failed." << backup_file.str()
295                     << " to " << res_file.str());
296         }
297         Catch(DPL::CopyFailed)
298         {
299             LogError("Restoration icon File Failed." << backup_file.str()
300                     << " to " << res_file.str());
301         }
302     }
303 }
304
305 void TaskManifestFile::stepUpdateFinalize()
306 {
307     commitManifest();
308     LogDebug("Finished Update Desktopfile");
309 }
310
311 DPL::String TaskManifestFile::getIconTargetFilename(
312         const DPL::String& languageTag) const
313 {
314     DPL::OStringStream filename;
315     WidgetPkgName pkgname = m_context.widgetConfig.pkgName;
316
317     filename << DPL::ToUTF8String(pkgname).c_str();
318
319     if (!languageTag.empty()) {
320         DPL::OptionalString tag = getLangTag(languageTag); // translate en -> en_US etc
321         if (tag.IsNull()) { tag = languageTag; }
322         DPL::String locale =
323             LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
324
325        if(locale.empty()) {
326             filename << L"." << languageTag;
327         } else {
328             filename << L"." << locale;
329         }
330     }
331
332     filename << L".png";
333     return filename.str();
334 }
335
336 void TaskManifestFile::stepFinalize()
337 {
338     commitManifest();
339     LogInfo("Finished ManifestFile step");
340 }
341
342
343 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
344         const DPL::String& key,
345         const DPL::String& languageTag)
346 {
347     DPL::String locale =
348             LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
349
350     file << key;
351     if (!locale.empty()) {
352         file << "[" << locale << "]";
353     }
354     file << "=";
355 }
356
357 void TaskManifestFile::updateAilInfo()
358 {
359     // Update ail for desktop
360     std::string cfgPkgname =
361         DPL::ToUTF8String(m_context.widgetConfig.pkgName);
362     const char* pkgname = cfgPkgname.c_str();
363
364     LogDebug("Update ail desktop : " << pkgname );
365     ail_appinfo_h ai = NULL;
366     ail_error_e ret;
367
368     ret = ail_package_get_appinfo(pkgname, &ai);
369     if (ai) {
370         ail_package_destroy_appinfo(ai);
371     }
372
373     if (AIL_ERROR_NO_DATA == ret) {
374         if (ail_desktop_add(pkgname) < 0) {
375             LogWarning("Failed to add ail desktop : " << pkgname);
376         }
377     } else if (AIL_ERROR_OK == ret) {
378         if (ail_desktop_update(pkgname) < 0) {
379             LogWarning("Failed to update ail desktop : " << pkgname);
380         }
381     }
382 }
383
384 void TaskManifestFile::backupIconFiles()
385 {
386     LogInfo("Backup Icon Files");
387
388     std::ostringstream b_icon_dir;
389     b_icon_dir << backup_dir.str() << "icons";
390
391     LogDebug("Create icon backup folder : " << b_icon_dir.str());
392     WrtUtilMakeDir(b_icon_dir.str());
393
394     std::list<std::string> fileList;
395     getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
396     std::string pkgname = DPL::ToUTF8String(m_context.widgetConfig.pkgName);
397
398     FOREACH(it, fileList)
399     {
400         if (0 == (strncmp((*it).c_str(), pkgname.c_str(),
401                         strlen(pkgname.c_str())))) {
402             std::ostringstream icon_file, backup_icon;
403             icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
404             icon_file << "/" << (*it);
405
406             backup_icon << b_icon_dir.str() << "/" << (*it);
407
408             LogDebug("Backup icon file " << icon_file.str() << " to " <<
409                     backup_icon.str());
410             Try
411             {
412                 DPL::FileInput input(icon_file.str());
413                 DPL::FileOutput output(backup_icon.str());
414                 DPL::Copy(&input, &output);
415             }
416             Catch(DPL::FileInput::Exception::Base)
417             {
418                 LogError("Backup Desktop File Failed.");
419                 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
420             }
421
422             Catch(DPL::FileOutput::Exception::Base)
423             {
424                 LogError("Backup Desktop File Failed.");
425                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
426             }
427             Catch(DPL::CopyFailed)
428             {
429                 LogError("Backup Desktop File Failed.");
430                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
431             }
432             unlink((*it).c_str());
433         }
434     }
435 }
436
437 void TaskManifestFile::getFileList(const char* path,
438         std::list<std::string> &list)
439 {
440     DIR* dir = opendir(path);
441     if (!dir) {
442         LogError("icon directory doesn't exist");
443         ThrowMsg(Exceptions::InternalError, path);
444     }
445
446     struct dirent* d_ent;
447     do {
448         if ((d_ent = readdir(dir))) {
449             if(strcmp(d_ent->d_name, ".") == 0 ||
450                     strcmp(d_ent->d_name, "..") == 0) {
451                 continue;
452             }
453             std::string file_name = d_ent->d_name;
454             list.push_back(file_name);
455         }
456     }while(d_ent);
457     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
458         LogError("Failed to close dir: " << path << " with error: "
459                 << DPL::GetErrnoString());
460     }
461 }
462
463 void TaskManifestFile::stepGenerateManifest()
464 {
465     WidgetPkgName pkgname = m_context.widgetConfig.pkgName;
466     manifest_name = pkgname + L".xml";
467     manifest_file += L"/tmp/" + manifest_name;
468
469     //libxml - init and check
470     LibxmlSingleton::Instance().init();
471
472     writeManifest(manifest_file);
473
474     m_context.job->UpdateProgress(
475         InstallerContext::INSTALL_CREATE_MANIFEST,
476         "Widget Manifest Creation Finished");
477 }
478
479 void TaskManifestFile::stepParseManifest()
480 {
481     int code = pkgmgr_parser_parse_manifest_for_installation(
482             DPL::ToUTF8String(manifest_file).c_str(), NULL);
483
484     if(code != 0)
485     {
486         LogError("Manifest parser error: " << code);
487         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
488     }
489
490     // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
491     updateAilInfo();
492
493     m_context.job->UpdateProgress(
494         InstallerContext::INSTALL_CREATE_MANIFEST,
495         "Widget Manifest Parsing Finished");
496     LogDebug("Manifest parsed");
497 }
498
499 void TaskManifestFile::stepParseUpgradedManifest()
500 {
501     int code = pkgmgr_parser_parse_manifest_for_upgrade(
502             DPL::ToUTF8String(manifest_file).c_str(), NULL);
503
504     if(code != 0)
505     {
506         LogError("Manifest parser error: " << code);
507         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
508     }
509
510     // TODO : It will be removed. AIL update is temporary code request by pkgmgr team.
511     updateAilInfo();
512
513     m_context.job->UpdateProgress(
514         InstallerContext::INSTALL_CREATE_MANIFEST,
515         "Widget Manifest Parsing Finished");
516     LogDebug("Manifest parsed");
517 }
518
519 void TaskManifestFile::commitManifest()
520 {
521     LogDebug("Commiting manifest file : " << manifest_file);
522
523     std::ostringstream destFile;
524     destFile << "/opt/share/packages" << "/"; //TODO constant with path
525     destFile << DPL::ToUTF8String(manifest_name);
526     LogInfo("cp " << manifest_file << " " << destFile.str());
527
528     DPL::FileInput input(DPL::ToUTF8String(manifest_file));
529     DPL::FileOutput output(destFile.str());
530     DPL::Copy(&input, &output);
531     LogDebug("Manifest writen to: " << destFile.str());
532
533     //removing temp file
534     unlink((DPL::ToUTF8String(manifest_file)).c_str());
535     manifest_file = DPL::FromUTF8String(destFile.str().c_str());
536 }
537
538 void TaskManifestFile::writeManifest(const DPL::String & path)
539 {
540     LogDebug("Generating manifest file : " << path);
541     Manifest manifest;
542     UiApplication uiApp;
543
544     setWidgetExecPath(uiApp);
545     setWidgetName(manifest, uiApp);
546     setWidgetIcons(uiApp);
547     setWidgetManifest(manifest);
548     setWidgetOtherInfo(uiApp);
549     setAppServiceInfo(uiApp);
550     setAppCategory(uiApp);
551     setLiveBoxInfo(manifest);
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     WidgetPkgName pkgname = m_context.widgetConfig.pkgName;
595     uiApp.setAppid(pkgname);
596
597
598     //extraid
599     if(!!m_context.widgetConfig.guid) {
600         uiApp.setExtraid(*m_context.widgetConfig.guid);
601     } else {
602         if(!pkgname.empty()) {
603             uiApp.setExtraid(DPL::String(L"http://") + pkgname);
604         }
605     }
606
607     //type
608     uiApp.setType(DPL::FromASCIIString("webapp"));
609     manifest.setType(L"wgt");
610     uiApp.setTaskmanage(true);
611 }
612
613 void TaskManifestFile::generateWidgetName(Manifest & manifest, UiApplication &uiApp, const DPL::OptionalString& tag, DPL::OptionalString name, bool & defaultNameSaved)
614 {
615     if (!!name) {
616         if (!!tag)
617         {
618             DPL::String locale =
619                     LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
620
621             if (!locale.empty()) {
622                 uiApp.addLabel(LabelType(*name,*tag));
623             }
624             else
625             {
626                 uiApp.addLabel(LabelType(*name));
627                 manifest.addLabel(LabelType(*name));
628             }
629         }
630         else
631         {
632             defaultNameSaved = true;
633             uiApp.addLabel(LabelType(*name));
634             manifest.addLabel(LabelType(*name));
635         }
636     }
637 }
638
639 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
640 {
641     //TODO this file will need to be updated when user locale preferences
642     //changes.
643     bool defaultIconSaved = false;
644
645     DPL::OptionalString defaultLocale = m_context.widgetConfig.configInfo.defaultlocale;
646
647     std::vector<Locale> generatedLocales;
648     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons = m_context.widgetConfig.localizationData.icons;
649
650     //reversed: last <icon> has highest priority to be writen to manifest if it has given locale (TODO: why was that working that way?)
651     for(WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator icon = icons.rbegin(); icon != icons.rend(); icon++)
652     {
653         FOREACH(locale, icon->availableLocales)
654         {
655             if(std::find(generatedLocales.begin(), generatedLocales.end(), *locale) != generatedLocales.end())
656             {
657                 LogDebug("Skipping - has that locale - already in manifest");
658                 continue;
659             }
660             else
661             {
662                 generatedLocales.push_back(*locale);
663             }
664
665             DPL::OptionalString tag = getLangTag(*locale); // translate en -> en_US etc
666             if (tag.IsNull()) { tag = *locale; }
667
668             generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
669         }
670     }
671     if (!!defaultLocale && !defaultIconSaved)
672     {
673         generateWidgetIcon(uiApp, DPL::OptionalString::Null,
674                            DPL::String(),
675                            defaultIconSaved);
676     }
677 }
678
679 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp, const DPL::OptionalString& tag,
680         const DPL::String& language, bool & defaultIconSaved)
681 {
682     DPL::String locale;
683     if (!!tag)
684     {
685         locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
686     }
687     else
688     {
689         defaultIconSaved = true;
690     }
691
692     DPL::String iconText;
693     iconText += getIconTargetFilename(language);
694
695     if(!locale.empty())
696     {
697         uiApp.addIcon(IconType(iconText, locale));
698     }
699     else
700     {
701         uiApp.addIcon(IconType(iconText));
702     }
703 }
704
705 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
706 {
707     manifest.setPackage(m_context.widgetConfig.pkgName);
708
709     if(!!m_context.widgetConfig.version)
710     {
711         manifest.setVersion(*m_context.widgetConfig.version);
712     }
713     DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
714                             *m_context.widgetConfig.configInfo.authorEmail : L"");
715     DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
716                             *m_context.widgetConfig.configInfo.authorHref : L"");
717     DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
718                             *m_context.widgetConfig.configInfo.authorName : L"");
719     manifest.addAuthor(Author(email,href,L"",name));
720 }
721
722 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
723 {
724     FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
725     {
726          if(!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
727              if(!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
728                 uiApp.setNodisplay(true);
729              }
730              else {
731                 uiApp.setNodisplay(false);
732             }
733          }
734      }
735     //TODO
736     //There is no "X-TIZEN-PackageType=wgt"
737     //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" << DPL::ToUTF8String(*widgetID).c_str()
738     //There is no Comment in pkgmgr "Comment=Widget application"
739     //that were in desktop file
740 }
741
742 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
743 {
744     WrtDB::ConfigParserData::ServiceInfoList appServiceList = m_context.widgetConfig.configInfo.appServiceList;
745
746     if (appServiceList.empty()) {
747         LogInfo("Widget doesn't contain application service");
748         return;
749     }
750
751     // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
752     FOREACH(it, appServiceList) {
753         AppControl appControl;
754         if (!it->m_operation.empty()) {
755             appControl.addOperation(it->m_operation); //TODO: encapsulation?
756         }
757         if (!it->m_scheme.empty()) {
758             appControl.addUri(it->m_scheme);
759         }
760         if (!it->m_mime.empty()) {
761             appControl.addMime(it->m_mime);
762         }
763         uiApp.addAppControl(appControl);
764     }
765 }
766
767 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
768 {
769     WrtDB::ConfigParserData::CategoryList categoryList =
770         m_context.widgetConfig.configInfo.categoryList;
771
772     if (categoryList.empty()) {
773         LogInfo("Widget doesn't contain application category");
774         return;
775     }
776     FOREACH(it, categoryList) {
777         if (!(*it).empty()) {
778             uiApp.addAppCategory(*it);
779         }
780     }
781 }
782
783 void TaskManifestFile::stepAbortParseManifest()
784 {
785     LogError("[Parse Manifest] Abroting....");
786
787     int code = pkgmgr_parser_parse_manifest_for_uninstallation(
788             DPL::ToUTF8String(manifest_file).c_str(), NULL);
789
790     if (0 != code)
791     {
792         LogWarning("Manifest parser error: " << code);
793         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
794     }
795     int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
796     if (0 != ret)
797     {
798         LogWarning("No manifest file found: " << manifest_file);
799     }
800 }
801
802 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
803 {
804     FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
805         LogInfo("setLiveBoxInfo");
806         LiveBoxInfo liveBox;
807         DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
808         DPL::String pkgname = *m_context.widgetConfig.pkgname;
809         size_t found;
810
811         if(ConfigInfo->m_liveboxId != L"") {
812             found = ConfigInfo->m_liveboxId.find_first_of(L".");
813             if(found != std::string::npos) {
814                 if(0 == ConfigInfo->m_liveboxId.compare(0, found, pkgname))
815                     liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
816                 else {
817                     DPL::String liveboxId =
818                         pkgname+DPL::String(L".")+ConfigInfo->m_liveboxId;
819                     liveBox.setLiveboxId(liveboxId);
820                 }
821             } else {
822                 DPL::String liveboxId =
823                     pkgname+DPL::String(L".")+ConfigInfo->m_liveboxId;
824                 liveBox.setLiveboxId(liveboxId);
825             }
826         }
827
828         if(ConfigInfo->m_primary != L"")
829             liveBox.setPrimary(ConfigInfo->m_primary);
830
831         if(ConfigInfo->m_autoLaunch == L"true")
832             liveBox.setAutoLaunch(pkgname);
833
834         if(ConfigInfo->m_updatePeriod != L"")
835             liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
836
837         if(ConfigInfo->m_label != L"")
838             liveBox.setLabel(ConfigInfo->m_label);
839
840         DPL::String defaultLocale
841             = DPL::FromUTF8String(m_context.locations->getPackageInstallationDir())
842             + DPL::String(L"/res/wgt/");
843
844         if(ConfigInfo->m_icon!=L"") {
845             liveBox.setIcon(defaultLocale+ConfigInfo->m_icon);
846         }
847
848         if (ConfigInfo->m_boxInfo.m_boxSrc.empty() || ConfigInfo->m_boxInfo.m_boxSize.empty()) {
849             LogInfo("Widget doesn't contain box");
850             return;
851         } else {
852             BoxInfoType box;
853             if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
854                 if((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
855                         || (0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
856                     box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
857                 else
858                     box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
859             }
860
861             std::list<std::pair<DPL::String,DPL::String>> BoxSizeList
862                 = ConfigInfo->m_boxInfo.m_boxSize;
863             FOREACH(im, BoxSizeList) {
864                 std::pair<DPL::String, DPL::String> boxSize = *im;
865                 if(!boxSize.second.empty())
866                     boxSize.second = defaultLocale + boxSize.second;
867                 box.boxSize.push_back(boxSize);
868             }
869
870             if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
871                     && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
872                     && !ConfigInfo->m_boxInfo.m_pdHeight.empty()) {
873                 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
874                 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
875                 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
876             }
877
878             liveBox.setBox(box);
879         }
880
881         manifest.addLivebox(liveBox);
882     }
883
884 }
885
886 } //namespace WidgetInstall
887 } //namespace Jobs