Merge "removed send signal during widget uninstallation."
[framework/web/wrt-installer.git] / src / jobs / widget_install / manifest.h
1 /*
2  * Copyright (c) 2012 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    manifest.h
18  * @author  Mariusz Domanski (m.domanski@samsung.com)
19  */
20
21 #ifndef INSTALLER_JOBS_MANIFEST_H
22 #define INSTALLER_JOBS_MANIFEST_H
23
24 #include <list>
25
26 #include <libxml/encoding.h>
27 #include <libxml/xmlwriter.h>
28
29 #include <dpl/string.h>
30 #include <dpl/optional_typedefs.h>
31 #include <dpl/foreach.h>
32
33 namespace Jobs {
34 namespace WidgetInstall {
35 /**
36  * @brief string with optional language attribute
37  */
38 class StringWithLang
39 {
40   public:
41     StringWithLang() { }
42     StringWithLang(DPL::String s) : string(s) { }
43     StringWithLang(DPL::String s, DPL::String l) : string(s), lang(l) { }
44     DPL::String getString()
45     {
46         return this->string;
47     }
48     DPL::String getLang()
49     {
50         return this->lang;
51     }
52     bool hasLang()
53     {
54         return !this->lang.empty();
55     }
56
57   private:
58     DPL::String string;
59     DPL::String lang;
60 };
61
62 typedef StringWithLang LabelType, IconType, DescriptionType;
63
64 /**
65  * These types are basicaly strings but they should allow usage of different
66  * range of characters or words (details in XML spec.).
67  * For simplicity DPL::Strings are used, although this can lead to XML
68  * validation
69  * errors (related to usage of not allowed characters in given places).
70  */
71 typedef DPL::String NcnameType, NmtokenType, AnySimpleType, LangType;
72 typedef DPL::String OperationType, MimeType, UriType, TypeType, PackageType;
73 typedef DPL::OptionalString InstallLocationType, CategoriesType;
74 typedef DPL::String AppCategoryType;
75
76 /**
77  * xmllib2 wrappers
78  */
79 void writeElement(xmlTextWriterPtr writer, const char * name, DPL::String body);
80 void writeText(xmlTextWriterPtr writer, DPL::String text);
81 void writeElement(xmlTextWriterPtr writer, const char * name, const char * body);
82 void writeElementWithOneAttribute(xmlTextWriterPtr writer,
83                                   const char * name,
84                                   const char * body,
85                                   const char * nameAttr,
86                                   DPL::String bodyAttr,
87                                   bool condition = true);
88 void startElement(xmlTextWriterPtr writer, const char * name);
89 void endElement(xmlTextWriterPtr writer);
90 void writeAttribute(xmlTextWriterPtr writer, const char * name,
91                     DPL::String body, bool condition);
92 void writeAttribute(xmlTextWriterPtr writer, const char * name,
93                     const char * body, bool condition);
94
95 /**
96  * @brief author element
97  */
98 class Author
99 {
100   public:
101     Author() {}
102     Author(AnySimpleType e,
103            NcnameType h,
104            LangType l,
105            DPL::String b) :
106         email(e), href(h), lang(l), body(b) {}
107     void serialize(xmlTextWriterPtr writer);
108
109   private:
110     AnySimpleType email;
111     NcnameType href;
112     LangType lang;
113     DPL::String body;
114 };
115
116 typedef Author AuthorType;
117
118 /**
119  * @brief application-service element
120  */
121 class AppControl
122 {
123   public:
124     AppControl() {}
125     void addOperation(const OperationType &x)
126     {
127         this->operation.push_back(x);
128     }
129     void addUri(const UriType &x)
130     {
131         this->uri.push_back(x);
132     }
133     void addMime(const MimeType &x)
134     {
135         this->mime.push_back(x);
136     }
137     void serialize(xmlTextWriterPtr writer);
138
139   private:
140     std::list<OperationType> operation; //attr name AnySimpleType
141     std::list<UriType> uri; //attr name AnySimpleType
142     std::list<MimeType> mime; //attr name AnySimpleType
143 };
144
145 typedef AppControl AppControlType;
146
147 /**
148  * @brief account element
149  */
150 typedef std::list<std::pair<DPL::String, DPL::String>> IconListType;
151 typedef std::list<LabelType> DisplayNameListType;
152 typedef std::list<DPL::String> AccountCapabilityType;
153
154 struct AccountProvider
155 {
156     NcnameType appid;
157     NcnameType multiAccount;
158     IconListType icon;
159     DisplayNameListType name;
160     AccountCapabilityType capability;
161 };
162
163 typedef AccountProvider AccountProviderType;
164
165 class Account
166 {
167   public:
168     Account() {}
169     void addAccountProvider(const AccountProvider &x)
170     {
171         this->provider = x;
172     }
173     void serialize(xmlTextWriterPtr writer);
174
175   private:
176     AccountProviderType provider;
177 };
178
179 class Privilege
180 {
181   public:
182     Privilege() {}
183     void addPrivilegeName(const DPL::String &x)
184     {
185         this->name.push_back(x);
186     }
187     bool isEmpty()
188     {
189         return this->name.empty();
190     }
191
192     void serialize(xmlTextWriterPtr writer);
193
194   private:
195     std::list<DPL::String> name;
196 };
197
198 typedef Privilege PrivilegeType;
199
200 /**
201  * @brief ime-application element
202  */
203 class ImeApplication
204 {
205   public:
206     ImeApplication() {}
207     void setAppid(const NcnameType &x)
208     {
209         this->appid = x;
210     }
211     void setExec(const NcnameType &x)
212     {
213         this->exec = x;
214     }
215     void setMultiple(bool x)
216     {
217         this->multiple = x;
218     }
219     void setNodisplay(bool x)
220     {
221         this->nodisplay = x;
222     }
223     void setType(const TypeType &x)
224     {
225         this->type = x;
226     }
227     void addLabel(const LabelType &x)
228     {
229         this->label.push_back(x);
230     }
231     void addIcon(const IconType &x)
232     {
233         this->icon.push_back(x);
234     }
235     void serialize(xmlTextWriterPtr writer);
236
237   private:
238     NcnameType appid;
239     NcnameType exec;
240     DPL::OptionalBool multiple;
241     DPL::OptionalBool nodisplay;
242     TypeType type;
243     std::list<LabelType> label;
244     std::list<IconType> icon;
245 };
246
247 typedef ImeApplication ImeApplicationType;
248
249 /**
250  * @brief service-application element
251  */
252 class ServiceApplication
253 {
254   public:
255     ServiceApplication() {}
256     void setAppid(const NcnameType &x)
257     {
258         this->appid = x;
259     }
260     void setAutoRestart(bool x)
261     {
262         this->autoRestart = x;
263     }
264     void setExec(const AnySimpleType &x)
265     {
266         this->exec = x;
267     }
268     void setOnBoot(bool x)
269     {
270         this->onBoot = x;
271     }
272     void setType(const TypeType &x)
273     {
274         this->type = x;
275     }
276     void addLabel(const LabelType &x)
277     {
278         this->label.push_back(x);
279     }
280     void addIcon(const IconType &x)
281     {
282         this->icon.push_back(x);
283     }
284     void addAppControl(const AppControlType &x)
285     {
286         this->appControl.push_back(x);
287     }
288     void serialize(xmlTextWriterPtr writer);
289
290   private:
291     NcnameType appid;
292     DPL::OptionalBool autoRestart;
293     AnySimpleType exec;
294     DPL::OptionalBool onBoot;
295     TypeType type;
296     std::list<LabelType> label; //attr name AnySimpleType
297     std::list<IconType> icon; //attr name AnySimpleType
298     std::list<AppControlType> appControl; //attr name AnySimpleType
299 };
300
301 typedef ServiceApplication ServiceApplicationType;
302
303 /**
304  * @brief ui-application element
305  */
306 class UiApplication
307 {
308   public:
309     UiApplication() {}
310     void setAppid(const NcnameType &x)
311     {
312         this->appid = x;
313     }
314     void setExtraid(const NcnameType &x)
315     {
316         this->extraid = x;
317     }
318     void setExec(const AnySimpleType &x)
319     {
320         this->exec = x;
321     }
322     void setMultiple(bool x)
323     {
324         this->multiple = x;
325     }
326     void setNodisplay(bool x)
327     {
328         this->nodisplay = x;
329     }
330     void setTaskmanage(bool x)
331     {
332         this->taskmanage = x;
333     }
334     void setType(const TypeType &x)
335     {
336         this->type = x;
337     }
338     void setCategories(const NcnameType &x)
339     {
340         this->categories = x;
341     }
342     void addLabel(const LabelType &x)
343     {
344         this->label.push_back(x);
345     }
346     void addIcon(const IconType &x)
347     {
348         this->icon.push_back(x);
349     }
350     void addAppControl(const AppControlType &x)
351     {
352         this->appControl.push_back(x);
353     }
354     void addAppCategory(const AppCategoryType &x)
355     {
356         this->appCategory.push_back(x);
357     }
358     void serialize(xmlTextWriterPtr writer);
359
360   private:
361     NcnameType appid;
362     NcnameType extraid;
363     AnySimpleType exec;
364     DPL::OptionalBool multiple;
365     DPL::OptionalBool nodisplay;
366     DPL::OptionalBool taskmanage;
367     TypeType type;
368     CategoriesType categories;
369     std::list<LabelType> label;
370     std::list<IconType> icon;
371     std::list<AppControlType> appControl;
372     std::list<AppCategoryType> appCategory;
373 };
374
375 typedef UiApplication UiApplicationType;
376
377 /**
378  * @brief LiveBox element
379  */
380 typedef std::list<std::pair<DPL::String, DPL::String> > boxSizeType;
381
382 struct BoxInfo
383 {
384     NcnameType boxSrc;
385     NcnameType boxMouseEvent;
386     NcnameType boxTouchEffect;
387     boxSizeType boxSize;
388     NcnameType pdSrc;
389     NcnameType pdWidth;
390     NcnameType pdHeight;
391 };
392 typedef BoxInfo BoxInfoType;
393
394 class LiveBox
395 {
396   public:
397     LiveBox() { }
398     void setLiveboxId(const NcnameType &x)
399     {
400         this->liveboxId = x;
401     }
402     void setPrimary(const NcnameType &x)
403     {
404         this->primary = x;
405     }
406     void setAutoLaunch(const NcnameType &x)
407     {
408         this->autoLaunch = x;
409     }
410     void setUpdatePeriod(const NcnameType &x)
411     {
412         this->updatePeriod = x;
413     }
414     void setLabel(const NcnameType &x)
415     {
416         this->label = x;
417     }
418     void setIcon(const NcnameType &x)
419     {
420         this->icon = x;
421     }
422     void setBox(const BoxInfoType &x)
423     {
424         this->box = x;
425     }
426
427     void serialize(xmlTextWriterPtr writer);
428
429   private:
430     NcnameType liveboxId;
431     NcnameType primary;
432     NcnameType autoLaunch;
433     NcnameType updatePeriod;
434     NcnameType timeout;
435     NcnameType label;
436     NcnameType icon;
437     BoxInfoType box;
438 };
439
440 typedef LiveBox LiveBoxInfo;
441
442 /**
443  * @brief manifest element
444  *
445  * Manifest xml file representation.
446  */
447 class Manifest
448 {
449   public:
450     Manifest() {}
451     void serialize(xmlTextWriterPtr writer);
452     void generate(DPL::String filename);
453
454     void addLabel(const LabelType &x)
455     {
456         this->label.push_back(x);
457     }
458     void addIcon(const IconType &x)
459     {
460         this->icon.push_back(x);
461     }
462     void addAuthor(const AuthorType &x)
463     {
464         this->author.push_back(x);
465     }
466     void addDescription(const DescriptionType &x)
467     {
468         this->description.push_back(x);
469     }
470     //    void addCompatibility(const CompatibilityType &x)
471     //    {
472     //        this->compatibility.push_back(x);
473     //    }
474     //    void addDeviceProfile(const DeviceProfileType &x)
475     //    {
476     //        this->deviceProfile.push_back(x);
477     //    }
478     void addServiceApplication(const ServiceApplicationType &x)
479     {
480         this->serviceApplication.push_back(x);
481     }
482     void addUiApplication(const UiApplicationType &x)
483     {
484         this->uiApplication.push_back(x);
485     }
486     void addImeApplication(const ImeApplicationType &x)
487     {
488         this->imeApplication.push_back(x);
489     }
490     //    void addFont(const FontType &x) { this->font.push_back(x); }
491
492     void addLivebox(const LiveBoxInfo &x)
493     {
494         this->livebox.push_back(x);
495     }
496
497     void addAccount(const Account &x)
498     {
499         this->account.push_back(x);
500     }
501
502     void addPrivileges(const PrivilegeType &x)
503     {
504         this->privileges = x;
505     }
506
507     void setInstallLocation(const InstallLocationType &x)
508     {
509         this->installLocation = x;
510     }
511     void setPackage(const NcnameType &x)
512     {
513         this->package = x;
514     }
515     void setType(const PackageType &x)
516     {
517         this->type = x;
518     }
519     void setVersion(const NmtokenType &x)
520     {
521         this->version = x;
522     }
523
524   private:
525     std::list<LabelType> label;
526     std::list<IconType> icon;
527     std::list<AuthorType> author;
528     std::list<DescriptionType> description;
529     //    std::list<CompatibilityType> compatibility;
530     //    std::list<DeviceProfileType> deviceProfile;
531     std::list<ServiceApplicationType> serviceApplication;
532     std::list<UiApplicationType> uiApplication;
533     std::list<ImeApplicationType> imeApplication;
534     //    std::list<FontType> font;
535     std::list<LiveBoxInfo> livebox;
536     InstallLocationType installLocation;
537     NcnameType package;
538     PackageType type;
539     NmtokenType version;
540     std::list<Account> account;
541     PrivilegeType privileges;
542
543 };
544 } //namespace Jobs
545 } //namespace WidgetInstall
546
547 #endif //INSTALLER_JOBS_MANIFEST_H