Fix generation of widget-application for hybrid apps
[platform/core/appfw/wgt-backend.git] / src / wgt / step / pkgmgr / step_generate_xml.cc
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
5
6 #include "wgt/step/pkgmgr/step_generate_xml.h"
7
8 #include <boost/filesystem/path.hpp>
9 #include <boost/system/error_code.hpp>
10
11 #include <common/utils/file_util.h>
12 #include <common/utils/glist_range.h>
13 #include <common/privileges.h>
14
15 #include <libxml/parser.h>
16 #include <libxml/xmlreader.h>
17 #include <pkgmgr-info.h>
18 #include <pkgmgr_parser.h>
19 #include <tzplatform_config.h>
20 #include <unistd.h>
21
22 #include <cassert>
23 #include <cstring>
24 #include <string>
25
26 #include "wgt/wgt_backend_data.h"
27
28 namespace bs = boost::system;
29 namespace bf = boost::filesystem;
30
31 namespace {
32
33 const char kResWgt[] = "res/wgt";
34 const char kSharedRes[] = "shared/res";
35
36 void WriteUIApplicationAttributes(
37     xmlTextWriterPtr writer, application_x *app) {
38   if (app->taskmanage)
39     xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
40         BAD_CAST app->taskmanage);
41   if (app->nodisplay)
42     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
43         BAD_CAST app->nodisplay);
44   if (app->multiple)
45     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
46         BAD_CAST app->multiple);
47   if (app->launch_mode && strlen(app->launch_mode))
48     xmlTextWriterWriteAttribute(writer, BAD_CAST "launch_mode",
49         BAD_CAST app->launch_mode);
50   if (app->ui_gadget && strlen(app->ui_gadget))
51     xmlTextWriterWriteAttribute(writer, BAD_CAST "ui-gadget",
52         BAD_CAST app->ui_gadget);
53   if (app->submode && strlen(app->submode))
54     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode",
55         BAD_CAST app->submode);
56   if (app->submode_mainid && strlen(app->submode_mainid))
57     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode-mainid",
58         BAD_CAST app->submode_mainid);
59   if (app->indicatordisplay && strlen(app->indicatordisplay))
60     xmlTextWriterWriteAttribute(writer, BAD_CAST "indicatordisplay",
61         BAD_CAST app->indicatordisplay);
62   if (app->portraitimg && strlen(app->portraitimg))
63     xmlTextWriterWriteAttribute(writer, BAD_CAST "portrait-effectimage",
64         BAD_CAST app->portraitimg);
65   if (app->landscapeimg && strlen(app->landscapeimg))
66     xmlTextWriterWriteAttribute(writer, BAD_CAST "landscape-effectimage",
67         BAD_CAST app->landscapeimg);
68   if (app->effectimage_type && strlen(app->effectimage_type))
69     xmlTextWriterWriteAttribute(writer, BAD_CAST "effectimage-type",
70         BAD_CAST app->effectimage_type);
71   if (app->hwacceleration && strlen(app->hwacceleration))
72     xmlTextWriterWriteAttribute(writer, BAD_CAST "hwacceleration",
73         BAD_CAST app->hwacceleration);
74 }
75
76 void WriteServiceApplicationAttributes(
77     xmlTextWriterPtr writer, application_x *app) {
78   xmlTextWriterWriteAttribute(writer, BAD_CAST "auto-restart",
79       BAD_CAST(app->autorestart ? app->autorestart : "false"));
80   xmlTextWriterWriteAttribute(writer, BAD_CAST "on-boot",
81       BAD_CAST(app->onboot ? app->onboot : "false"));
82   if (app->taskmanage)
83       xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
84          BAD_CAST app->taskmanage);
85 }
86
87 bool WriteWidgetApplicationAttributesAndElements(
88     xmlTextWriterPtr writer, application_x *app,
89     const wgt::parse::AppWidgetInfo& widget_info,
90     const bf::path& shared_path) {
91   if (app->nodisplay)
92     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
93         BAD_CAST app->nodisplay);
94   if (app->multiple)
95     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
96         BAD_CAST app->multiple);
97
98   auto& appwidgets = widget_info.app_widgets();
99   const auto& appwidget = std::find_if(appwidgets.begin(), appwidgets.end(),
100                                  [app](const wgt::parse::AppWidget& widget) {
101                                     return widget.id == app->appid;
102                                  });
103   if (appwidget == appwidgets.end()) {
104     return true;
105   }
106
107   // Add extra elements for wgt widget-application
108   xmlTextWriterWriteAttribute(writer, BAD_CAST "main",
109       BAD_CAST (appwidget->primary ? "true" : "false"));  // NOLINT
110   if (!appwidget->update_period.empty()) {
111         xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST
112             std::to_string(static_cast<int>(
113                     appwidget->update_period.front())).c_str());
114   }
115
116   xmlTextWriterWriteAttribute(writer, BAD_CAST "max-instance",
117       BAD_CAST std::to_string(appwidget->max_instance).c_str());
118
119   for (auto& size : appwidget->content_size) {
120     xmlTextWriterStartElement(writer, BAD_CAST "support-size");
121
122     std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
123     if (!size.preview.empty()) {
124       std::string icon_name = shared_path.string() + "/"
125           + appwidget->id + "." + type + "." + "preview" +
126           bf::path(size.preview).extension().string();
127       xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
128           BAD_CAST icon_name.c_str());  // NOLINT
129     }
130
131     xmlTextWriterWriteAttribute(writer, BAD_CAST "frame",
132                                 BAD_CAST "true");
133     xmlTextWriterWriteString(writer,
134         BAD_CAST type.c_str());
135     xmlTextWriterEndElement(writer);
136   }
137
138   for (auto& pair : appwidget->metadata) {
139     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
140     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
141                                 BAD_CAST pair.first.c_str());
142     if (!pair.second.empty())
143       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
144                                   BAD_CAST pair.second.c_str());
145     xmlTextWriterEndElement(writer);
146   }
147   return true;
148 }
149
150 void WriteWatchApplicationAttributes(
151     xmlTextWriterPtr writer, application_x* app) {
152   if (app->ambient_support)
153     xmlTextWriterWriteAttribute(writer, BAD_CAST "ambient-support",
154         BAD_CAST app->ambient_support);
155 }
156
157 }  // namespace
158
159 namespace wgt {
160 namespace pkgmgr {
161
162 common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml(
163     application_x* app, xmlTextWriterPtr writer, AppCompType type) {
164   xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST app->appid);
165
166   // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
167   bf::path exec_path = context_->pkg_path.get()
168       / bf::path("bin") / bf::path(app->appid);
169   xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
170                               BAD_CAST exec_path.string().c_str());
171   if (app->type)
172     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST app->type);
173   else
174     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "capp");
175
176   if (app->process_pool && strlen(app->process_pool))
177     xmlTextWriterWriteAttribute(writer, BAD_CAST "process-pool",
178                                 BAD_CAST app->process_pool);
179   // app-specific attributes
180   switch (type) {
181   case AppCompType::UIAPP:
182     WriteUIApplicationAttributes(writer, app);
183     break;
184   case AppCompType::SVCAPP:
185     WriteServiceApplicationAttributes(writer, app);
186     break;
187   case AppCompType::WIDGETAPP:
188     if (!WriteWidgetApplicationAttributesAndElements(writer, app,
189         static_cast<WgtBackendData*>(
190             context_->backend_data.get())->appwidgets.get(),
191         context_->pkg_path.get() / "shared" / "res"))
192       return Status::MANIFEST_ERROR;
193     break;
194   case AppCompType::WATCHAPP:
195     WriteWatchApplicationAttributes(writer, app);
196     break;
197   }
198
199   for (label_x* label : GListRange<label_x*>(app->label)) {
200     if (label->name && strcmp(label->name, "") != 0) {
201       xmlTextWriterStartElement(writer, BAD_CAST "label");
202       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
203         xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
204                                     BAD_CAST label->lang);
205       }
206       xmlTextWriterWriteString(writer, BAD_CAST label->name);
207       xmlTextWriterEndElement(writer);
208     }
209   }
210
211   for (auto& icon : GListRange<icon_x*>(app->icon)) {
212     xmlTextWriterStartElement(writer, BAD_CAST "icon");
213     if (icon->lang && strcmp(DEFAULT_LOCALE, icon->lang) != 0) {
214       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
215                                   BAD_CAST icon->lang);
216     }
217     xmlTextWriterWriteString(writer, BAD_CAST icon->text);
218     xmlTextWriterEndElement(writer);
219   }
220
221   for (image_x* image : GListRange<image_x*>(app->image)) {
222     xmlTextWriterStartElement(writer, BAD_CAST "image");
223     if (image->lang && strcmp(DEFAULT_LOCALE, image->lang) != 0) {
224       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
225
226                                   BAD_CAST image->lang);
227     }
228     if (image->section)
229       xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
230                                   BAD_CAST image->section);
231     xmlTextWriterEndElement(writer);
232   }
233
234   for (appcontrol_x* appc : GListRange<appcontrol_x*>(app->appcontrol)) {
235     xmlTextWriterStartElement(writer, BAD_CAST "app-control");
236
237     if (appc->operation) {
238       xmlTextWriterStartElement(writer, BAD_CAST "operation");
239       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
240           BAD_CAST appc->operation);
241       xmlTextWriterEndElement(writer);
242     }
243
244     if (appc->uri) {
245       xmlTextWriterStartElement(writer, BAD_CAST "uri");
246       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
247           BAD_CAST appc->uri);
248       xmlTextWriterEndElement(writer);
249     }
250
251     if (appc->mime) {
252       xmlTextWriterStartElement(writer, BAD_CAST "mime");
253       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
254           BAD_CAST appc->mime);
255       xmlTextWriterEndElement(writer);
256     }
257
258     xmlTextWriterEndElement(writer);
259   }
260
261   for (datacontrol_x* datacontrol :
262        GListRange<datacontrol_x*>(app->datacontrol)) {
263     xmlTextWriterStartElement(writer, BAD_CAST "datacontrol");
264     if (datacontrol->access) {
265       xmlTextWriterWriteAttribute(writer, BAD_CAST "access",
266           BAD_CAST datacontrol->access);
267     }
268     if (datacontrol->providerid) {
269       xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
270           BAD_CAST datacontrol->providerid);
271     }
272     if (datacontrol->type) {
273       xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
274           BAD_CAST datacontrol->type);
275     }
276     xmlTextWriterEndElement(writer);
277   }
278
279   for (metadata_x* meta : GListRange<metadata_x*>(app->metadata)) {
280     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
281     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
282         BAD_CAST meta->key);
283     if (meta->value)
284       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
285           BAD_CAST meta->value);
286     xmlTextWriterEndElement(writer);
287   }
288
289   for (const char* category : GListRange<char*>(app->category)) {
290     xmlTextWriterStartElement(writer, BAD_CAST "category");
291     xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST category);
292     xmlTextWriterEndElement(writer);
293   }
294
295   for (const char* background_category : GListRange<char*>(
296       app->background_category)) {
297     xmlTextWriterStartElement(writer, BAD_CAST "background-category");
298     xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
299         BAD_CAST background_category);
300     xmlTextWriterEndElement(writer);
301   }
302
303   return Step::Status::OK;
304 }
305
306 common_installer::Step::Status StepGenerateXml::undo() {
307   bs::error_code error;
308   if (bf::exists(context_->xml_path.get()))
309     bf::remove_all(context_->xml_path.get(), error);
310   return Status::OK;
311 }
312
313 common_installer::Step::Status StepGenerateXml::precheck() {
314   if (!context_->manifest_data.get()) {
315     LOG(ERROR) << "manifest_data attribute is empty";
316     return Step::Status::INVALID_VALUE;
317   }
318   if (context_->pkgid.get().empty()) {
319     LOG(ERROR) << "pkgid attribute is empty";
320     return Step::Status::PACKAGE_NOT_FOUND;
321   }
322
323   if (!context_->manifest_data.get()->application) {
324     LOG(ERROR) << "No application in package";
325     return Step::Status::INVALID_VALUE;
326   }
327
328   return Step::Status::OK;
329 }
330
331 common_installer::Step::Status StepGenerateXml::process() {
332   bf::path xml_path =
333       bf::path(getUserManifestPath(context_->uid.get(), false))
334       / bf::path(context_->pkgid.get());
335   xml_path += ".xml";
336   context_->xml_path.set(xml_path.string());
337
338   bs::error_code error;
339   if (!bf::exists(xml_path.parent_path(), error)) {
340     if (!common_installer::CreateDir(xml_path.parent_path())) {
341       LOG(ERROR) <<
342           "Directory for manifest xml is missing and cannot be created";
343       return Status::MANIFEST_ERROR;
344     }
345   }
346
347   xmlTextWriterPtr writer;
348   writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0);
349   if (!writer) {
350     LOG(ERROR) << "Failed to create new file";
351     return Step::Status::MANIFEST_ERROR;
352   }
353
354   xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
355   xmlTextWriterSetIndent(writer, 1);
356
357   Status status = GenerateManifestElement(writer);
358   if (status != Status::OK) {
359     return status;
360   }
361
362   xmlTextWriterEndDocument(writer);
363   xmlFreeTextWriter(writer);
364
365   if (pkgmgr_parser_check_manifest_validation(
366       context_->xml_path.get().c_str()) != 0) {
367     LOG(ERROR) << "Manifest is not valid";
368     return Step::Status::MANIFEST_ERROR;
369   }
370
371   LOG(DEBUG) << "Successfully create manifest xml "
372       << context_->xml_path.get();
373   return Status::OK;
374 }
375
376 common_installer::Step::Status StepGenerateXml::GenerateManifestElement(
377         xmlTextWriterPtr writer) {
378   xmlTextWriterStartElement(writer, BAD_CAST "manifest");
379
380   GenerateManifestElementAttributes(writer);
381   GenerateLangLabels(writer);
382   GenerateAuthor(writer);
383   GenerateDescription(writer);
384   Status status = GenerateApplications(writer);
385   if (status != Status::OK) {
386     return status;
387   }
388   GeneratePrivilege(writer);
389   GenerateAccount(writer);
390   GenerateIme(writer);
391   GenerateProfiles(writer);
392   GenerateShortcuts(writer);
393
394   xmlTextWriterEndElement(writer);
395   return Status::OK;
396 }
397
398 void StepGenerateXml::GenerateManifestElementAttributes(
399         xmlTextWriterPtr writer) {
400   xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
401       BAD_CAST "http://tizen.org/ns/packages");
402   xmlTextWriterWriteAttribute(writer, BAD_CAST "package",
403       BAD_CAST context_->manifest_data.get()->package);
404   xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
405       BAD_CAST context_->manifest_data.get()->type);
406   xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
407       BAD_CAST context_->manifest_data.get()->version);
408   xmlTextWriterWriteAttribute(writer, BAD_CAST "api-version",
409       BAD_CAST context_->manifest_data.get()->api_version);
410   xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay-setting",
411       BAD_CAST context_->manifest_data.get()->nodisplay_setting);
412 }
413
414 void StepGenerateXml::GenerateLangLabels(xmlTextWriterPtr writer) {
415   for (label_x* label :
416        GListRange<label_x*>(context_->manifest_data.get()->label)) {
417     if (label->name && strcmp(label->name, "") != 0) {
418       xmlTextWriterStartElement(writer, BAD_CAST "label");
419       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
420       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
421                                     BAD_CAST label->lang);
422       }
423       xmlTextWriterWriteString(writer, BAD_CAST label->name);
424       xmlTextWriterEndElement(writer);
425     }
426   }
427 }
428
429 void StepGenerateXml::GenerateAuthor(xmlTextWriterPtr writer) {
430   for (author_x* author :
431        GListRange<author_x*>(context_->manifest_data.get()->author)) {
432     xmlTextWriterStartElement(writer, BAD_CAST "author");
433     if (author->email && strlen(author->email)) {
434       xmlTextWriterWriteAttribute(writer, BAD_CAST "email",
435                                   BAD_CAST author->email);
436     }
437     if (author->href && strlen(author->href)) {
438       xmlTextWriterWriteAttribute(writer, BAD_CAST "href",
439                                   BAD_CAST author->href);
440     }
441     xmlTextWriterWriteString(writer, BAD_CAST author->text);
442     xmlTextWriterEndElement(writer);
443   }
444 }
445
446 void StepGenerateXml::GenerateDescription(xmlTextWriterPtr writer) {
447   for (description_x* description :
448        GListRange<description_x*>(context_->manifest_data.get()->description)) {
449     xmlTextWriterStartElement(writer, BAD_CAST "description");
450     if (description->lang && strcmp(DEFAULT_LOCALE, description->lang) != 0) {
451       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
452                                   BAD_CAST description->lang);
453     }
454     xmlTextWriterWriteString(writer, BAD_CAST description->text);
455     xmlTextWriterEndElement(writer);
456   }
457 }
458
459 common_installer::Step::Status StepGenerateXml::GenerateApplications(
460         xmlTextWriterPtr writer) {
461   for (application_x* app :
462        GListRange<application_x*>(context_->manifest_data.get()->application)) {
463     AppCompType type;
464     if (strcmp(app->component_type, "uiapp") == 0) {
465       type = AppCompType::UIAPP;
466       xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
467     } else if (strcmp(app->component_type, "svcapp") == 0) {
468       type = AppCompType::SVCAPP;
469       xmlTextWriterStartElement(writer, BAD_CAST "service-application");
470     } else if (strcmp(app->component_type, "widgetapp") == 0) {
471       type = AppCompType::WIDGETAPP;
472       xmlTextWriterStartElement(writer, BAD_CAST "widget-application");
473     } else if (strcmp(app->component_type, "watchapp") == 0) {
474       type = AppCompType::WATCHAPP;
475       xmlTextWriterStartElement(writer, BAD_CAST "watch-application");
476     } else {
477       LOG(ERROR) << "Unknown application component_type";
478       xmlFreeTextWriter(writer);
479       return Status::ERROR;
480     }
481     Status status = GenerateApplicationCommonXml(app, writer, type);
482     if (status != Status::OK) {
483       xmlFreeTextWriter(writer);
484       return status;
485     }
486     xmlTextWriterEndElement(writer);
487   }
488   return Status::OK;
489 }
490
491 void StepGenerateXml::GeneratePrivilege(xmlTextWriterPtr writer) {
492     if (context_->manifest_data.get()->privileges) {
493     xmlTextWriterStartElement(writer, BAD_CAST "privileges");
494     for (const char* priv :
495          GListRange<char*>(context_->manifest_data.get()->privileges)) {
496       xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege",
497         "%s", BAD_CAST priv);
498     }
499
500     xmlTextWriterEndElement(writer);
501   }
502 }
503
504 void StepGenerateXml::GenerateAccount(xmlTextWriterPtr writer) {
505   const auto& accounts =
506       context_->manifest_plugins_data.get().account_info.get().accounts();
507   if (!accounts.empty()) {
508     xmlTextWriterStartElement(writer, BAD_CAST "account");
509     // add account info
510     for (auto& account : accounts) {
511       xmlTextWriterStartElement(writer, BAD_CAST "account-provider");
512
513       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
514                                   BAD_CAST account.appid.c_str());
515
516       if (!account.providerid.empty())
517         xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
518                                     BAD_CAST account.providerid.c_str());
519
520       if (account.multiple_account_support)
521         xmlTextWriterWriteAttribute(writer,
522                                     BAD_CAST "multiple-accounts-support",
523                                     BAD_CAST "true");
524       else
525         xmlTextWriterWriteAttribute(writer,
526                                     BAD_CAST "multiple-accounts-support",
527                                     BAD_CAST "false");
528       for (auto& icon_pair : account.icon_paths) {
529         xmlTextWriterStartElement(writer, BAD_CAST "icon");
530         if (icon_pair.first == "AccountSmall")
531           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
532                                       BAD_CAST "account-small");
533         else
534           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
535                                       BAD_CAST "account");
536         xmlTextWriterWriteString(writer, BAD_CAST icon_pair.second.c_str());
537         xmlTextWriterEndElement(writer);
538       }
539
540       for (auto& name_pair : account.names) {
541         xmlTextWriterStartElement(writer, BAD_CAST "label");
542         if (!name_pair.second.empty())
543           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
544                                       BAD_CAST name_pair.second.c_str());
545         xmlTextWriterWriteString(writer, BAD_CAST name_pair.first.c_str());
546         xmlTextWriterEndElement(writer);
547       }
548
549       for (auto& capability : account.capabilities) {
550         xmlTextWriterWriteFormatElement(writer, BAD_CAST "capability",
551           "%s", BAD_CAST capability.c_str());
552       }
553
554       xmlTextWriterEndElement(writer);
555     }
556     xmlTextWriterEndElement(writer);
557   }
558 }
559
560 void StepGenerateXml::GenerateIme(xmlTextWriterPtr writer) {
561   const auto &ime = context_->manifest_plugins_data.get().ime_info.get();
562   const auto ime_uuid = ime.uuid();
563   if (!ime_uuid.empty()) {
564     xmlTextWriterStartElement(writer, BAD_CAST "ime");
565
566     GListRange<application_x*> app_range(
567         context_->manifest_data.get()->application);
568     if (!app_range.Empty()) {
569       // wgt app have ui-application as first application element.
570       // there may be service-applications but not as first element.
571       application_x* app = *app_range.begin();
572       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
573                                   BAD_CAST app->appid);
574     }
575
576     xmlTextWriterStartElement(writer, BAD_CAST "uuid");
577     xmlTextWriterWriteString(writer, BAD_CAST ime_uuid.c_str());
578     xmlTextWriterEndElement(writer);
579
580     xmlTextWriterStartElement(writer, BAD_CAST "languages");
581
582     for (auto it = ime.LanguagesBegin(); it != ime.LanguagesEnd(); ++it) {
583       xmlTextWriterStartElement(writer, BAD_CAST "language");
584       xmlTextWriterWriteString(writer, BAD_CAST it->c_str());
585       xmlTextWriterEndElement(writer);
586     }
587
588     xmlTextWriterEndElement(writer);
589
590     xmlTextWriterEndElement(writer);
591   }
592 }
593
594 void StepGenerateXml::GenerateProfiles(xmlTextWriterPtr writer) {
595   for (const char* profile :
596        GListRange<char*>(context_->manifest_data.get()->deviceprofile)) {
597     xmlTextWriterStartElement(writer, BAD_CAST "profile");
598     xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
599                                 BAD_CAST profile);
600     xmlTextWriterEndElement(writer);
601   }
602 }
603
604 void StepGenerateXml::GenerateShortcuts(xmlTextWriterPtr writer) {
605   const auto& shortcuts =
606       context_->manifest_plugins_data.get().shortcut_info.get();
607   if (!shortcuts.empty()) {
608     xmlTextWriterStartElement(writer, BAD_CAST "shortcut-list");
609     for (auto& shortcut : shortcuts) {
610       xmlTextWriterStartElement(writer, BAD_CAST "shortcut");
611       if (!shortcut.app_id.empty())
612         xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
613                                     BAD_CAST shortcut.app_id.c_str());
614       if (!shortcut.app_id.empty())
615         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_data",
616                                     BAD_CAST shortcut.extra_data.c_str());
617       if (!shortcut.app_id.empty())
618         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_key",
619                                     BAD_CAST shortcut.extra_key.c_str());
620       if (!shortcut.icon.empty()) {
621         xmlTextWriterStartElement(writer, BAD_CAST "icon");
622         xmlTextWriterWriteString(writer, BAD_CAST shortcut.icon.c_str());
623         xmlTextWriterEndElement(writer);
624       }
625       for (auto& label : shortcut.labels) {
626         xmlTextWriterStartElement(writer, BAD_CAST "label");
627         if (!label.first.empty())
628           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
629                                       BAD_CAST label.first.c_str());
630         xmlTextWriterWriteString(writer, BAD_CAST label.second.c_str());
631         xmlTextWriterEndElement(writer);
632       }
633       xmlTextWriterEndElement(writer);
634     }
635     xmlTextWriterEndElement(writer);
636   }
637 }
638
639 }  // namespace pkgmgr
640 }  // namespace wgt