Save value of auto-launch to livebox DB without adding manifest file
[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 setUpdatePeriod(const NcnameType &x)
407     {
408         this->updatePeriod = x;
409     }
410     void setLabel(const NcnameType &x)
411     {
412         this->label = x;
413     }
414     void setIcon(const NcnameType &x)
415     {
416         this->icon = x;
417     }
418     void setBox(const BoxInfoType &x)
419     {
420         this->box = x;
421     }
422
423     void serialize(xmlTextWriterPtr writer);
424
425   private:
426     NcnameType liveboxId;
427     NcnameType primary;
428     NcnameType autoLaunch;
429     NcnameType updatePeriod;
430     NcnameType timeout;
431     NcnameType label;
432     NcnameType icon;
433     BoxInfoType box;
434 };
435
436 typedef LiveBox LiveBoxInfo;
437
438 /**
439  * @brief manifest element
440  *
441  * Manifest xml file representation.
442  */
443 class Manifest
444 {
445   public:
446     Manifest() {}
447     void serialize(xmlTextWriterPtr writer);
448     void generate(DPL::String filename);
449
450     void addLabel(const LabelType &x)
451     {
452         this->label.push_back(x);
453     }
454     void addIcon(const IconType &x)
455     {
456         this->icon.push_back(x);
457     }
458     void addAuthor(const AuthorType &x)
459     {
460         this->author.push_back(x);
461     }
462     void addDescription(const DescriptionType &x)
463     {
464         this->description.push_back(x);
465     }
466     //    void addCompatibility(const CompatibilityType &x)
467     //    {
468     //        this->compatibility.push_back(x);
469     //    }
470     //    void addDeviceProfile(const DeviceProfileType &x)
471     //    {
472     //        this->deviceProfile.push_back(x);
473     //    }
474     void addServiceApplication(const ServiceApplicationType &x)
475     {
476         this->serviceApplication.push_back(x);
477     }
478     void addUiApplication(const UiApplicationType &x)
479     {
480         this->uiApplication.push_back(x);
481     }
482     void addImeApplication(const ImeApplicationType &x)
483     {
484         this->imeApplication.push_back(x);
485     }
486     //    void addFont(const FontType &x) { this->font.push_back(x); }
487
488     void addLivebox(const LiveBoxInfo &x)
489     {
490         this->livebox.push_back(x);
491     }
492
493     void addAccount(const Account &x)
494     {
495         this->account.push_back(x);
496     }
497
498     void addPrivileges(const PrivilegeType &x)
499     {
500         this->privileges = x;
501     }
502
503     void setInstallLocation(const InstallLocationType &x)
504     {
505         this->installLocation = x;
506     }
507     void setPackage(const NcnameType &x)
508     {
509         this->package = x;
510     }
511     void setType(const PackageType &x)
512     {
513         this->type = x;
514     }
515     void setVersion(const NmtokenType &x)
516     {
517         this->version = x;
518     }
519
520   private:
521     std::list<LabelType> label;
522     std::list<IconType> icon;
523     std::list<AuthorType> author;
524     std::list<DescriptionType> description;
525     //    std::list<CompatibilityType> compatibility;
526     //    std::list<DeviceProfileType> deviceProfile;
527     std::list<ServiceApplicationType> serviceApplication;
528     std::list<UiApplicationType> uiApplication;
529     std::list<ImeApplicationType> imeApplication;
530     //    std::list<FontType> font;
531     std::list<LiveBoxInfo> livebox;
532     InstallLocationType installLocation;
533     NcnameType package;
534     PackageType type;
535     NmtokenType version;
536     std::list<Account> account;
537     PrivilegeType privileges;
538
539 };
540 } //namespace Jobs
541 } //namespace WidgetInstall
542
543 #endif //INSTALLER_JOBS_MANIFEST_H