Support for GCC 4.7
[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 <unistd.h>
25 #include <string>
26 #include <dpl/assert.h>
27 #include <dirent.h>
28 #include <fstream>
29 #include <ail.h>
30
31 //WRT INCLUDES
32 #include <widget_install/task_manifest_file.h>
33 #include <widget_install/job_widget_install.h>
34 #include <widget_install/widget_install_errors.h>
35 #include <widget_install/widget_install_context.h>
36 #include <dpl/wrt-dao-ro/global_config.h>
37 #include <dpl/log/log.h>
38 #include <dpl/file_input.h>
39 #include <dpl/errno_string.h>
40 #include <dpl/file_output.h>
41 #include <dpl/copy.h>
42 #include <dpl/exception.h>
43 #include <dpl/foreach.h>
44 #include <dpl/sstream.h>
45 #include <dpl/string.h>
46 #include <dpl/optional.h>
47 #include <dpl/utils/wrt_utility.h>
48 #include <map>
49 #include <libxml_utils.h>
50 #include <pkgmgr/pkgmgr_parser.h>
51 #include <dpl/localization/LanguageTagsProvider.h>
52
53 #define DEFAULT_ICON_NAME   "icon.png"
54
55 using namespace WrtDB;
56
57 namespace {
58 typedef std::map<DPL::String, DPL::String> LanguageTagMap;
59
60 const char* const ST_TRUE = "true";
61 const char* const ST_NODISPLAY = "nodisplay";
62
63 LanguageTagMap getLanguageTagMap()
64 {
65     LanguageTagMap map;
66
67 #define ADD(tag, l_tag) map.insert(std::make_pair(L###tag, L###l_tag));
68 #include "languages.def"
69 #undef ADD
70
71     return map;
72 }
73
74 DPL::OptionalString getLangTag(const DPL::String& tag)
75 {
76     static LanguageTagMap TagsMap =
77         getLanguageTagMap();
78
79     DPL::String langTag = tag;
80
81     LogDebug("Trying to map language tag: " << langTag);
82     size_t pos = langTag.find_first_of(L'_');
83     if (pos != DPL::String::npos) {
84         langTag.erase(pos);
85     }
86     DPL::OptionalString ret;
87
88     LanguageTagMap::iterator it = TagsMap.find(langTag);
89     if (it != TagsMap.end()) {
90         ret = it->second;
91     }
92     LogDebug("Mapping IANA Language tag to language tag: " <<
93              langTag << " -> " << ret);
94
95     return ret;
96 }
97 }
98
99 namespace Jobs {
100 namespace WidgetInstall {
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 void TaskManifestFile::stepCreateExecFile()
131 {
132     std::string exec = m_context.locations->getExecFile();
133     std::string clientExeStr = GlobalConfig::GetWrtClientExec();
134
135     LogInfo("link -s " << clientExeStr << " " << exec);
136     symlink(clientExeStr.c_str(), exec.c_str());
137
138     m_context.job->UpdateProgress(
139         InstallerContext::INSTALL_CREATE_EXECFILE,
140         "Widget execfile creation Finished");
141 }
142
143 void TaskManifestFile::stepCopyIconFiles()
144 {
145     LogDebug("CopyIconFiles");
146
147     //This function copies icon to desktop icon path. For each locale avaliable
148     //which there is at least one icon in widget for, icon file is copied.
149     //Coping prioritize last positions when coping. If there is several icons
150     //with given locale, the one, that will be copied, will be icon
151     //which is declared by <icon> tag later than the others in config.xml of
152     // widget
153
154     std::vector<Locale> generatedLocales;
155
156     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
157         m_context.widgetConfig.localizationData.icons;
158
159     //reversed: last <icon> has highest priority to be copied if it has given
160     // locale (TODO: why was that working that way?)
161     for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
162          icon = icons.rbegin();
163          icon != icons.rend();
164          icon++)
165     {
166         FOREACH(locale, icon->availableLocales)
167         {
168             DPL::String src = icon->src;
169             LogDebug("Icon for locale: " << *locale << "is : " << src);
170
171             if (std::find(generatedLocales.begin(), generatedLocales.end(),
172                           *locale) != generatedLocales.end())
173             {
174                 LogDebug("Skipping - has that locale");
175                 continue;
176             } else {
177                 generatedLocales.push_back(*locale);
178             }
179
180             std::ostringstream sourceFile;
181             std::ostringstream targetFile;
182
183             sourceFile << m_context.locations->getSourceDir() << "/";
184
185             if (!locale->empty()) {
186                 sourceFile << "locales/" << *locale << "/";
187             }
188
189             sourceFile << src;
190
191             targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/";
192             targetFile << getIconTargetFilename(*locale);
193
194             if (m_context.widgetConfig.packagingType ==
195                 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
196             {
197                 m_context.locations->setIconTargetFilenameForLocale(
198                     targetFile.str());
199             }
200
201             LogDebug("Copying icon: " << sourceFile.str() <<
202                      " -> " << targetFile.str());
203
204             icon_list.push_back(targetFile.str());
205
206             Try
207             {
208                 DPL::FileInput input(sourceFile.str());
209                 DPL::FileOutput output(targetFile.str());
210                 DPL::Copy(&input, &output);
211             }
212
213             Catch(DPL::FileInput::Exception::Base)
214             {
215                 // Error while opening or closing source file
216                 //ReThrowMsg(InstallerException::CopyIconFailed,
217                 // sourceFile.str());
218                 LogError(
219                     "Copying widget's icon failed. Widget's icon will not be" \
220                     "available from Main Screen");
221             }
222
223             Catch(DPL::FileOutput::Exception::Base)
224             {
225                 // Error while opening or closing target file
226                 //ReThrowMsg(InstallerException::CopyIconFailed,
227                 // 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,
237                 // targetFile.str());
238                 LogError(
239                     "Copying widget's icon failed. Widget's icon will not be" \
240                     "available from Main Screen");
241             }
242         }
243     }
244
245     m_context.job->UpdateProgress(
246         InstallerContext::INSTALL_COPY_ICONFILE,
247         "Widget iconfile copy Finished");
248 }
249
250 void TaskManifestFile::stepBackupIconFiles()
251 {
252     LogDebug("Backup Icon Files");
253
254     backup_dir << m_context.locations->getPackageInstallationDir();
255     backup_dir << "/" << "backup" << "/";
256
257     backupIconFiles();
258
259     m_context.job->UpdateProgress(
260         InstallerContext::INSTALL_BACKUP_ICONFILE,
261         "New Widget icon file backup Finished");
262 }
263
264 void TaskManifestFile::stepAbortIconFiles()
265 {
266     LogDebug("Abrot Icon Files");
267     FOREACH(it, icon_list)
268     {
269         LogDebug("Remove Update Icon : " << (*it));
270         unlink((*it).c_str());
271     }
272
273     std::ostringstream b_icon_dir;
274     b_icon_dir << backup_dir.str() << "icons";
275
276     std::list<std::string> fileList;
277     getFileList(b_icon_dir.str().c_str(), fileList);
278
279     FOREACH(back_icon, fileList)
280     {
281         std::ostringstream res_file;
282         res_file << GlobalConfig::GetUserWidgetDesktopIconPath();
283         res_file << "/" << (*back_icon);
284
285         std::ostringstream backup_file;
286         backup_file << b_icon_dir.str() << "/" << (*back_icon);
287
288         Try
289         {
290             DPL::FileInput input(backup_file.str());
291             DPL::FileOutput output(res_file.str());
292             DPL::Copy(&input, &output);
293         }
294         Catch(DPL::FileInput::Exception::Base)
295         {
296             LogError("Restoration icon File Failed." << backup_file.str()
297                                                      << " to " << res_file.str());
298         }
299
300         Catch(DPL::FileOutput::Exception::Base)
301         {
302             LogError("Restoration icon File Failed." << backup_file.str()
303                                                      << " to " << res_file.str());
304         }
305         Catch(DPL::CopyFailed)
306         {
307             LogError("Restoration icon File Failed." << backup_file.str()
308                                                      << " to " << res_file.str());
309         }
310     }
311 }
312
313 void TaskManifestFile::stepUpdateFinalize()
314 {
315     commitManifest();
316     LogDebug("Finished Update Desktopfile");
317 }
318
319 DPL::String TaskManifestFile::getIconTargetFilename(
320     const DPL::String& languageTag) const
321 {
322     DPL::OStringStream filename;
323     TizenAppId appid = m_context.widgetConfig.tzAppid;
324
325     filename << DPL::ToUTF8String(appid).c_str();
326
327     if (!languageTag.empty()) {
328         DPL::OptionalString tag = getLangTag(languageTag); // translate en ->
329                                                            // en_US etc
330         if (tag.IsNull()) {
331             tag = languageTag;
332         }
333         DPL::String locale =
334             LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
335
336         if (locale.empty()) {
337             filename << L"." << languageTag;
338         } else {
339             filename << L"." << locale;
340         }
341     }
342
343     filename << L".png";
344     return filename.str();
345 }
346
347 void TaskManifestFile::stepFinalize()
348 {
349     commitManifest();
350     LogInfo("Finished ManifestFile step");
351 }
352
353 void TaskManifestFile::saveLocalizedKey(std::ofstream &file,
354                                         const DPL::String& key,
355                                         const DPL::String& languageTag)
356 {
357     DPL::String locale =
358         LanguageTagsProvider::BCP47LanguageTagToLocale(languageTag);
359
360     file << key;
361     if (!locale.empty()) {
362         file << "[" << locale << "]";
363     }
364     file << "=";
365 }
366
367 void TaskManifestFile::updateAilInfo()
368 {
369     // Update ail for desktop
370     std::string cfgAppid =
371         DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
372     const char* appid = cfgAppid.c_str();
373
374     LogDebug("Update ail desktop : " << appid);
375     ail_appinfo_h ai = NULL;
376     ail_error_e ret;
377
378     ret = ail_package_get_appinfo(appid, &ai);
379     if (ai) {
380         ail_package_destroy_appinfo(ai);
381     }
382
383     if (AIL_ERROR_NO_DATA == ret) {
384         if (ail_desktop_add(appid) < 0) {
385             LogWarning("Failed to add ail desktop : " << appid);
386         }
387     } else if (AIL_ERROR_OK == ret) {
388         if (ail_desktop_update(appid) < 0) {
389             LogWarning("Failed to update ail desktop : " << appid);
390         }
391     }
392 }
393
394 void TaskManifestFile::backupIconFiles()
395 {
396     LogInfo("Backup Icon Files");
397
398     std::ostringstream b_icon_dir;
399     b_icon_dir << backup_dir.str() << "icons";
400
401     LogDebug("Create icon backup folder : " << b_icon_dir.str());
402     WrtUtilMakeDir(b_icon_dir.str());
403
404     std::list<std::string> fileList;
405     getFileList(GlobalConfig::GetUserWidgetDesktopIconPath(), fileList);
406     std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
407
408     FOREACH(it, fileList)
409     {
410         if (0 == (strncmp((*it).c_str(), appid.c_str(),
411                           strlen(appid.c_str()))))
412         {
413             std::ostringstream icon_file, backup_icon;
414             icon_file << GlobalConfig::GetUserWidgetDesktopIconPath();
415             icon_file << "/" << (*it);
416
417             backup_icon << b_icon_dir.str() << "/" << (*it);
418
419             LogDebug("Backup icon file " << icon_file.str() << " to " <<
420                      backup_icon.str());
421             Try
422             {
423                 DPL::FileInput input(icon_file.str());
424                 DPL::FileOutput output(backup_icon.str());
425                 DPL::Copy(&input, &output);
426             }
427             Catch(DPL::FileInput::Exception::Base)
428             {
429                 LogError("Backup Desktop File Failed.");
430                 ReThrowMsg(Exceptions::BackupFailed, icon_file.str());
431             }
432
433             Catch(DPL::FileOutput::Exception::Base)
434             {
435                 LogError("Backup Desktop File Failed.");
436                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
437             }
438             Catch(DPL::CopyFailed)
439             {
440                 LogError("Backup Desktop File Failed.");
441                 ReThrowMsg(Exceptions::BackupFailed, backup_icon.str());
442             }
443             unlink((*it).c_str());
444         }
445     }
446 }
447
448 void TaskManifestFile::getFileList(const char* path,
449                                    std::list<std::string> &list)
450 {
451     DIR* dir = opendir(path);
452     if (!dir) {
453         LogError("icon directory doesn't exist");
454         ThrowMsg(Exceptions::InternalError, path);
455     }
456
457     struct dirent* d_ent;
458     do {
459         if ((d_ent = readdir(dir))) {
460             if (strcmp(d_ent->d_name, ".") == 0 ||
461                 strcmp(d_ent->d_name, "..") == 0)
462             {
463                 continue;
464             }
465             std::string file_name = d_ent->d_name;
466             list.push_back(file_name);
467         }
468     } while (d_ent);
469     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
470         LogError("Failed to close dir: " << path << " with error: "
471                                          << DPL::GetErrnoString());
472     }
473 }
474
475 void TaskManifestFile::stepGenerateManifest()
476 {
477     TizenPkgId pkgid = m_context.widgetConfig.tzPkgid;
478     manifest_name = pkgid + L".xml";
479     manifest_file += L"/tmp/" + manifest_name;
480
481     //libxml - init and check
482     LibxmlSingleton::Instance().init();
483
484     writeManifest(manifest_file);
485
486     m_context.job->UpdateProgress(
487         InstallerContext::INSTALL_CREATE_MANIFEST,
488         "Widget Manifest Creation Finished");
489 }
490
491 void TaskManifestFile::stepParseManifest()
492 {
493     int code = pkgmgr_parser_parse_manifest_for_installation(
494             DPL::ToUTF8String(manifest_file).c_str(), NULL);
495
496     if (code != 0) {
497         LogError("Manifest parser error: " << code);
498         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
499     }
500
501     // TODO : It will be removed. AIL update is temporary code request by pkgmgr
502     // team.
503     updateAilInfo();
504
505     m_context.job->UpdateProgress(
506         InstallerContext::INSTALL_CREATE_MANIFEST,
507         "Widget Manifest Parsing Finished");
508     LogDebug("Manifest parsed");
509 }
510
511 void TaskManifestFile::stepParseUpgradedManifest()
512 {
513     int code = pkgmgr_parser_parse_manifest_for_upgrade(
514             DPL::ToUTF8String(manifest_file).c_str(), NULL);
515
516     if (code != 0) {
517         LogError("Manifest parser error: " << code);
518         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
519     }
520
521     // TODO : It will be removed. AIL update is temporary code request by pkgmgr
522     // team.
523     updateAilInfo();
524
525     m_context.job->UpdateProgress(
526         InstallerContext::INSTALL_CREATE_MANIFEST,
527         "Widget Manifest Parsing Finished");
528     LogDebug("Manifest parsed");
529 }
530
531 void TaskManifestFile::commitManifest()
532 {
533     LogDebug("Commiting manifest file : " << manifest_file);
534
535     std::ostringstream destFile;
536     destFile << "/opt/share/packages" << "/"; //TODO constant with path
537     destFile << DPL::ToUTF8String(manifest_name);
538     LogInfo("cp " << manifest_file << " " << destFile.str());
539
540     DPL::FileInput input(DPL::ToUTF8String(manifest_file));
541     DPL::FileOutput output(destFile.str());
542     DPL::Copy(&input, &output);
543     LogDebug("Manifest writen to: " << destFile.str());
544
545     //removing temp file
546     unlink((DPL::ToUTF8String(manifest_file)).c_str());
547     manifest_file = DPL::FromUTF8String(destFile.str().c_str());
548 }
549
550 void TaskManifestFile::writeManifest(const DPL::String & path)
551 {
552     LogDebug("Generating manifest file : " << path);
553     Manifest manifest;
554     UiApplication uiApp;
555
556     setWidgetExecPath(uiApp);
557     setWidgetName(manifest, uiApp);
558     setWidgetIcons(uiApp);
559     setWidgetManifest(manifest);
560     setWidgetOtherInfo(uiApp);
561     setAppServiceInfo(uiApp);
562     setAppControlInfo(uiApp);
563     setAppCategory(uiApp);
564     setLiveBoxInfo(manifest);
565
566     manifest.addUiApplication(uiApp);
567     manifest.generate(path);
568     LogDebug("Manifest file serialized");
569 }
570
571 void TaskManifestFile::setWidgetExecPath(UiApplication & uiApp)
572 {
573     uiApp.setExec(DPL::FromASCIIString(m_context.locations->getExecFile()));
574 }
575
576 void TaskManifestFile::setWidgetName(Manifest & manifest, UiApplication & uiApp)
577 {
578     bool defaultNameSaved = false;
579
580     DPL::OptionalString defaultLocale =
581         m_context.widgetConfig.configInfo.defaultlocale;
582     std::pair<DPL::String,
583               WrtDB::ConfigParserData::LocalizedData> defaultLocalizedData;
584     //labels
585     FOREACH(localizedData, m_context.widgetConfig.configInfo.localizedDataSet)
586     {
587         Locale i = localizedData->first;
588         DPL::OptionalString tag = getLangTag(i); // translate en -> en_US etc
589         if (tag.IsNull()) {
590             tag = i;
591         }
592         DPL::OptionalString name = localizedData->second.name;
593         generateWidgetName(manifest, uiApp, tag, name, defaultNameSaved);
594
595         //store default locale localized data
596         if (!!defaultLocale && defaultLocale == i) {
597             defaultLocalizedData = *localizedData;
598         }
599     }
600
601     if (!!defaultLocale && !defaultNameSaved) {
602         DPL::OptionalString name = defaultLocalizedData.second.name;
603         generateWidgetName(manifest,
604                            uiApp,
605                            DPL::OptionalString::Null,
606                            name,
607                            defaultNameSaved);
608     }
609     //appid
610     TizenAppId appid = m_context.widgetConfig.tzAppid;
611     uiApp.setAppid(appid);
612
613     //extraid
614     if (!!m_context.widgetConfig.guid) {
615         uiApp.setExtraid(*m_context.widgetConfig.guid);
616     } else {
617         if (!appid.empty()) {
618             uiApp.setExtraid(DPL::String(L"http://") + appid);
619         }
620     }
621
622     //type
623     uiApp.setType(DPL::FromASCIIString("webapp"));
624     manifest.setType(L"wgt");
625 }
626
627 void TaskManifestFile::generateWidgetName(Manifest & manifest,
628                                           UiApplication &uiApp,
629                                           const DPL::OptionalString& tag,
630                                           DPL::OptionalString name,
631                                           bool & defaultNameSaved)
632 {
633     if (!!name) {
634         if (!!tag) {
635             DPL::String locale =
636                 LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
637
638             if (!locale.empty()) {
639                 uiApp.addLabel(LabelType(*name, *tag));
640             } else {
641                 uiApp.addLabel(LabelType(*name));
642                 manifest.addLabel(LabelType(*name));
643             }
644         } else {
645             defaultNameSaved = true;
646             uiApp.addLabel(LabelType(*name));
647             manifest.addLabel(LabelType(*name));
648         }
649     }
650 }
651
652 void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
653 {
654     //TODO this file will need to be updated when user locale preferences
655     //changes.
656     bool defaultIconSaved = false;
657
658     DPL::OptionalString defaultLocale =
659         m_context.widgetConfig.configInfo.defaultlocale;
660
661     std::vector<Locale> generatedLocales;
662     WrtDB::WidgetRegisterInfo::LocalizedIconList & icons =
663         m_context.widgetConfig.localizationData.icons;
664
665     //reversed: last <icon> has highest priority to be writen to manifest if it
666     // has given locale (TODO: why was that working that way?)
667     for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
668          icon = icons.rbegin();
669          icon != icons.rend();
670          icon++)
671     {
672         FOREACH(locale, icon->availableLocales)
673         {
674             if (std::find(generatedLocales.begin(), generatedLocales.end(),
675                           *locale) != generatedLocales.end())
676             {
677                 LogDebug("Skipping - has that locale - already in manifest");
678                 continue;
679             } else {
680                 generatedLocales.push_back(*locale);
681             }
682
683             DPL::OptionalString tag = getLangTag(*locale); // translate en ->
684                                                            // en_US etc
685             if (tag.IsNull()) {
686                 tag = *locale;
687             }
688
689             generateWidgetIcon(uiApp, tag, *locale, defaultIconSaved);
690         }
691     }
692     if (!!defaultLocale && !defaultIconSaved) {
693         generateWidgetIcon(uiApp, DPL::OptionalString::Null,
694                            DPL::String(),
695                            defaultIconSaved);
696     }
697 }
698
699 void TaskManifestFile::generateWidgetIcon(UiApplication & uiApp,
700                                           const DPL::OptionalString& tag,
701                                           const DPL::String& language,
702                                           bool & defaultIconSaved)
703 {
704     DPL::String locale;
705     if (!!tag) {
706         locale = LanguageTagsProvider::BCP47LanguageTagToLocale(*tag);
707     } else {
708         defaultIconSaved = true;
709     }
710
711     DPL::String iconText;
712     iconText += getIconTargetFilename(language);
713
714     if (!locale.empty()) {
715         uiApp.addIcon(IconType(iconText, locale));
716     } else {
717         uiApp.addIcon(IconType(iconText));
718     }
719 }
720
721 void TaskManifestFile::setWidgetManifest(Manifest & manifest)
722 {
723     manifest.setPackage(m_context.widgetConfig.tzPkgid);
724
725     if (!!m_context.widgetConfig.version) {
726         manifest.setVersion(*m_context.widgetConfig.version);
727     }
728     DPL::String email = (!!m_context.widgetConfig.configInfo.authorEmail ?
729                          *m_context.widgetConfig.configInfo.authorEmail : L"");
730     DPL::String href = (!!m_context.widgetConfig.configInfo.authorHref ?
731                         *m_context.widgetConfig.configInfo.authorHref : L"");
732     DPL::String name = (!!m_context.widgetConfig.configInfo.authorName ?
733                         *m_context.widgetConfig.configInfo.authorName : L"");
734     manifest.addAuthor(Author(email, href, L"", name));
735 }
736
737 void TaskManifestFile::setWidgetOtherInfo(UiApplication & uiApp)
738 {
739     FOREACH(it, m_context.widgetConfig.configInfo.settingsList)
740     {
741         if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), ST_NODISPLAY)) {
742             if (!strcmp(DPL::ToUTF8String(it->m_value).c_str(), ST_TRUE)) {
743                 uiApp.setNodisplay(true);
744                 uiApp.setTaskmanage(false);
745             } else {
746                 uiApp.setNodisplay(false);
747                 uiApp.setTaskmanage(true);
748             }
749         }
750     }
751     //TODO
752     //There is no "X-TIZEN-PackageType=wgt"
753     //There is no X-TIZEN-PackageID in manifest "X-TIZEN-PackageID=" <<
754     // DPL::ToUTF8String(*widgetID).c_str()
755     //There is no Comment in pkgmgr "Comment=Widget application"
756     //that were in desktop file
757 }
758
759 void TaskManifestFile::setAppServiceInfo(UiApplication & uiApp)
760 {
761     WrtDB::ConfigParserData::ServiceInfoList appServiceList =
762         m_context.widgetConfig.configInfo.appServiceList;
763
764     if (appServiceList.empty()) {
765         LogInfo("Widget doesn't contain application service");
766         return;
767     }
768
769     // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
770     FOREACH(it, appServiceList) {
771         AppControl appControl;
772         if (!it->m_operation.empty()) {
773             appControl.addOperation(it->m_operation); //TODO: encapsulation?
774         }
775         if (!it->m_scheme.empty()) {
776             appControl.addUri(it->m_scheme);
777         }
778         if (!it->m_mime.empty()) {
779             appControl.addMime(it->m_mime);
780         }
781         uiApp.addAppControl(appControl);
782     }
783 }
784
785 void TaskManifestFile::setAppControlInfo(UiApplication & uiApp)
786 {
787     WrtDB::ConfigParserData::AppControlInfoList appControlList =
788         m_context.widgetConfig.configInfo.appControlList;
789
790     if (appControlList.empty()) {
791         LogInfo("Widget doesn't contain app control");
792         return;
793     }
794
795     // x-tizen-svc=http://tizen.org/appcontrol/operation/pick|NULL|image;
796     FOREACH(it, appControlList) {
797         AppControl appControl;
798         if (!it->m_operation.empty()) {
799             appControl.addOperation(it->m_operation); //TODO: encapsulation?
800         }
801         if (!it->m_uriList.empty()) {
802             FOREACH(uri, it->m_uriList) {
803                 appControl.addUri(*uri);
804             }
805         }
806         if (!it->m_mimeList.empty()) {
807             FOREACH(mime, it->m_mimeList) {
808                 appControl.addMime(*mime);
809             }
810         }
811         uiApp.addAppControl(appControl);
812     }
813 }
814
815 void TaskManifestFile::setAppCategory(UiApplication &uiApp)
816 {
817     WrtDB::ConfigParserData::CategoryList categoryList =
818         m_context.widgetConfig.configInfo.categoryList;
819
820     if (categoryList.empty()) {
821         LogInfo("Widget doesn't contain application category");
822         return;
823     }
824     FOREACH(it, categoryList) {
825         if (!(*it).empty()) {
826             uiApp.addAppCategory(*it);
827         }
828     }
829 }
830
831 void TaskManifestFile::stepAbortParseManifest()
832 {
833     LogError("[Parse Manifest] Abroting....");
834
835     int code = pkgmgr_parser_parse_manifest_for_uninstallation(
836             DPL::ToUTF8String(manifest_file).c_str(), NULL);
837
838     if (0 != code) {
839         LogWarning("Manifest parser error: " << code);
840         ThrowMsg(ManifestParsingError, "Parser returncode: " << code);
841     }
842     int ret = unlink(DPL::ToUTF8String(manifest_file).c_str());
843     if (0 != ret) {
844         LogWarning("No manifest file found: " << manifest_file);
845     }
846 }
847
848 void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
849 {
850     FOREACH(it, m_context.widgetConfig.configInfo.m_livebox) {
851         LogInfo("setLiveBoxInfo");
852         LiveBoxInfo liveBox;
853         DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
854         DPL::String appid = m_context.widgetConfig.tzAppid;
855         size_t found;
856
857         if (ConfigInfo->m_liveboxId != L"") {
858             found = ConfigInfo->m_liveboxId.find_last_of(L".");
859             if (found != std::string::npos) {
860                 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
861                     liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
862                 } else {
863                     DPL::String liveboxId =
864                         appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
865                     liveBox.setLiveboxId(liveboxId);
866                 }
867             } else {
868                 DPL::String liveboxId =
869                     appid + DPL::String(L".") + ConfigInfo->m_liveboxId;
870                 liveBox.setLiveboxId(liveboxId);
871             }
872         }
873
874         if (ConfigInfo->m_primary != L"") {
875             liveBox.setPrimary(ConfigInfo->m_primary);
876         }
877
878         if (ConfigInfo->m_autoLaunch == L"true") {
879             liveBox.setAutoLaunch(appid);
880         }
881
882         if (ConfigInfo->m_updatePeriod != L"") {
883             liveBox.setUpdatePeriod(ConfigInfo->m_updatePeriod);
884         }
885
886         if (ConfigInfo->m_label != L"") {
887             liveBox.setLabel(ConfigInfo->m_label);
888         }
889
890         DPL::String defaultLocale
891             = DPL::FromUTF8String(
892                     m_context.locations->getPackageInstallationDir())
893                 + DPL::String(L"/res/wgt/");
894
895         if (ConfigInfo->m_icon != L"") {
896             liveBox.setIcon(defaultLocale + ConfigInfo->m_icon);
897         }
898
899         if (ConfigInfo->m_boxInfo.m_boxSrc.empty() ||
900             ConfigInfo->m_boxInfo.m_boxSize.empty())
901         {
902             LogInfo("Widget doesn't contain box");
903             return;
904         } else {
905             BoxInfoType box;
906             if (!ConfigInfo->m_boxInfo.m_boxSrc.empty()) {
907                 if ((0 == ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 4, L"http"))
908                     || (0 ==
909                         ConfigInfo->m_boxInfo.m_boxSrc.compare(0, 5, L"https")))
910                 {
911                     box.boxSrc = ConfigInfo->m_boxInfo.m_boxSrc;
912                 } else {
913                     box.boxSrc = defaultLocale + ConfigInfo->m_boxInfo.m_boxSrc;
914                 }
915             }
916
917             if (ConfigInfo->m_boxInfo.m_boxMouseEvent == L"true") {
918                 box.boxMouseEvent = ConfigInfo->m_boxInfo.m_boxMouseEvent;
919             } else {
920                 box.boxMouseEvent = L"false";
921             }
922
923             std::list<std::pair<DPL::String, DPL::String> > BoxSizeList
924                 = ConfigInfo->m_boxInfo.m_boxSize;
925             FOREACH(im, BoxSizeList) {
926                 std::pair<DPL::String, DPL::String> boxSize = *im;
927                 if (!boxSize.second.empty()) {
928                     boxSize.second = defaultLocale + boxSize.second;
929                 }
930                 box.boxSize.push_back(boxSize);
931             }
932
933             if (!ConfigInfo->m_boxInfo.m_pdSrc.empty()
934                 && !ConfigInfo->m_boxInfo.m_pdWidth.empty()
935                 && !ConfigInfo->m_boxInfo.m_pdHeight.empty())
936             {
937                 box.pdSrc = defaultLocale + ConfigInfo->m_boxInfo.m_pdSrc;
938                 box.pdWidth = ConfigInfo->m_boxInfo.m_pdWidth;
939                 box.pdHeight = ConfigInfo->m_boxInfo.m_pdHeight;
940             }
941             liveBox.setBox(box);
942         }
943         manifest.addLivebox(liveBox);
944     }
945 }
946 } //namespace WidgetInstall
947 } //namespace Jobs