[Release] wrt-installer_0.1.16
[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 /**
180  * @brief ime-application element
181  */
182 class ImeApplication
183 {
184   public:
185     ImeApplication() {}
186     void setAppid(const NcnameType &x)
187     {
188         this->appid = x;
189     }
190     void setExec(const NcnameType &x)
191     {
192         this->exec = x;
193     }
194     void setMultiple(bool x)
195     {
196         this->multiple = x;
197     }
198     void setNodisplay(bool x)
199     {
200         this->nodisplay = x;
201     }
202     void setType(const TypeType &x)
203     {
204         this->type = x;
205     }
206     void addLabel(const LabelType &x)
207     {
208         this->label.push_back(x);
209     }
210     void addIcon(const IconType &x)
211     {
212         this->icon.push_back(x);
213     }
214     void serialize(xmlTextWriterPtr writer);
215
216   private:
217     NcnameType appid;
218     NcnameType exec;
219     DPL::OptionalBool multiple;
220     DPL::OptionalBool nodisplay;
221     TypeType type;
222     std::list<LabelType> label;
223     std::list<IconType> icon;
224 };
225
226 typedef ImeApplication ImeApplicationType;
227
228 /**
229  * @brief service-application element
230  */
231 class ServiceApplication
232 {
233   public:
234     ServiceApplication() {}
235     void setAppid(const NcnameType &x)
236     {
237         this->appid = x;
238     }
239     void setAutoRestart(bool x)
240     {
241         this->autoRestart = x;
242     }
243     void setExec(const AnySimpleType &x)
244     {
245         this->exec = x;
246     }
247     void setOnBoot(bool x)
248     {
249         this->onBoot = x;
250     }
251     void setType(const TypeType &x)
252     {
253         this->type = x;
254     }
255     void addLabel(const LabelType &x)
256     {
257         this->label.push_back(x);
258     }
259     void addIcon(const IconType &x)
260     {
261         this->icon.push_back(x);
262     }
263     void addAppControl(const AppControlType &x)
264     {
265         this->appControl.push_back(x);
266     }
267     void serialize(xmlTextWriterPtr writer);
268
269   private:
270     NcnameType appid;
271     DPL::OptionalBool autoRestart;
272     AnySimpleType exec;
273     DPL::OptionalBool onBoot;
274     TypeType type;
275     std::list<LabelType> label; //attr name AnySimpleType
276     std::list<IconType> icon; //attr name AnySimpleType
277     std::list<AppControlType> appControl; //attr name AnySimpleType
278 };
279
280 typedef ServiceApplication ServiceApplicationType;
281
282 /**
283  * @brief ui-application element
284  */
285 class UiApplication
286 {
287   public:
288     UiApplication() {}
289     void setAppid(const NcnameType &x)
290     {
291         this->appid = x;
292     }
293     void setExtraid(const NcnameType &x)
294     {
295         this->extraid = x;
296     }
297     void setExec(const AnySimpleType &x)
298     {
299         this->exec = x;
300     }
301     void setMultiple(bool x)
302     {
303         this->multiple = x;
304     }
305     void setNodisplay(bool x)
306     {
307         this->nodisplay = x;
308     }
309     void setTaskmanage(bool x)
310     {
311         this->taskmanage = x;
312     }
313     void setType(const TypeType &x)
314     {
315         this->type = x;
316     }
317     void setCategories(const NcnameType &x)
318     {
319         this->categories = x;
320     }
321     void addLabel(const LabelType &x)
322     {
323         this->label.push_back(x);
324     }
325     void addIcon(const IconType &x)
326     {
327         this->icon.push_back(x);
328     }
329     void addAppControl(const AppControlType &x)
330     {
331         this->appControl.push_back(x);
332     }
333     void addAppCategory(const AppCategoryType &x)
334     {
335         this->appCategory.push_back(x);
336     }
337     void serialize(xmlTextWriterPtr writer);
338
339   private:
340     NcnameType appid;
341     NcnameType extraid;
342     AnySimpleType exec;
343     DPL::OptionalBool multiple;
344     DPL::OptionalBool nodisplay;
345     DPL::OptionalBool taskmanage;
346     TypeType type;
347     CategoriesType categories;
348     std::list<LabelType> label;
349     std::list<IconType> icon;
350     std::list<AppControlType> appControl;
351     std::list<AppCategoryType> appCategory;
352 };
353
354 typedef UiApplication UiApplicationType;
355
356 /**
357  * @brief LiveBox element
358  */
359 typedef std::list<std::pair<DPL::String, DPL::String> > boxSizeType;
360
361 struct BoxInfo
362 {
363     NcnameType boxSrc;
364     NcnameType boxMouseEvent;
365     NcnameType boxTouchEffect;
366     boxSizeType boxSize;
367     NcnameType pdSrc;
368     NcnameType pdWidth;
369     NcnameType pdHeight;
370 };
371 typedef BoxInfo BoxInfoType;
372
373 class LiveBox
374 {
375   public:
376     LiveBox() { }
377     void setLiveboxId(const NcnameType &x)
378     {
379         this->liveboxId = x;
380     }
381     void setPrimary(const NcnameType &x)
382     {
383         this->primary = x;
384     }
385     void setAutoLaunch(const NcnameType &x)
386     {
387         this->autoLaunch = x;
388     }
389     void setUpdatePeriod(const NcnameType &x)
390     {
391         this->updatePeriod = x;
392     }
393     void setLabel(const NcnameType &x)
394     {
395         this->label = x;
396     }
397     void setIcon(const NcnameType &x)
398     {
399         this->icon = x;
400     }
401     void setBox(const BoxInfoType &x)
402     {
403         this->box = x;
404     }
405
406     void serialize(xmlTextWriterPtr writer);
407
408   private:
409     NcnameType liveboxId;
410     NcnameType primary;
411     NcnameType autoLaunch;
412     NcnameType updatePeriod;
413     NcnameType timeout;
414     NcnameType label;
415     NcnameType icon;
416     BoxInfoType box;
417 };
418
419 typedef LiveBox LiveBoxInfo;
420
421 /**
422  * @brief manifest element
423  *
424  * Manifest xml file representation.
425  */
426 class Manifest
427 {
428   public:
429     Manifest() {}
430     void serialize(xmlTextWriterPtr writer);
431     void generate(DPL::String filename);
432
433     void addLabel(const LabelType &x)
434     {
435         this->label.push_back(x);
436     }
437     void addIcon(const IconType &x)
438     {
439         this->icon.push_back(x);
440     }
441     void addAuthor(const AuthorType &x)
442     {
443         this->author.push_back(x);
444     }
445     void addDescription(const DescriptionType &x)
446     {
447         this->description.push_back(x);
448     }
449     //    void addCompatibility(const CompatibilityType &x)
450     //    {
451     //        this->compatibility.push_back(x);
452     //    }
453     //    void addDeviceProfile(const DeviceProfileType &x)
454     //    {
455     //        this->deviceProfile.push_back(x);
456     //    }
457     void addServiceApplication(const ServiceApplicationType &x)
458     {
459         this->serviceApplication.push_back(x);
460     }
461     void addUiApplication(const UiApplicationType &x)
462     {
463         this->uiApplication.push_back(x);
464     }
465     void addImeApplication(const ImeApplicationType &x)
466     {
467         this->imeApplication.push_back(x);
468     }
469     //    void addFont(const FontType &x) { this->font.push_back(x); }
470
471     void addLivebox(const LiveBoxInfo &x)
472     {
473         this->livebox.push_back(x);
474     }
475
476     void addAccount(const Account &x)
477     {
478         this->account.push_back(x);
479     }
480
481     void setInstallLocation(const InstallLocationType &x)
482     {
483         this->installLocation = x;
484     }
485     void setPackage(const NcnameType &x)
486     {
487         this->package = x;
488     }
489     void setType(const PackageType &x)
490     {
491         this->type = x;
492     }
493     void setVersion(const NmtokenType &x)
494     {
495         this->version = x;
496     }
497
498   private:
499     std::list<LabelType> label;
500     std::list<IconType> icon;
501     std::list<AuthorType> author;
502     std::list<DescriptionType> description;
503     //    std::list<CompatibilityType> compatibility;
504     //    std::list<DeviceProfileType> deviceProfile;
505     std::list<ServiceApplicationType> serviceApplication;
506     std::list<UiApplicationType> uiApplication;
507     std::list<ImeApplicationType> imeApplication;
508     //    std::list<FontType> font;
509     std::list<LiveBoxInfo> livebox;
510     InstallLocationType installLocation;
511     NcnameType package;
512     PackageType type;
513     NmtokenType version;
514     std::list<Account> account;
515 };
516 } //namespace Jobs
517 } //namespace WidgetInstall
518
519 #endif //INSTALLER_JOBS_MANIFEST_H