Add category element at manifest and config.xml
[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 /**
37  * @brief string with optional language attribute
38  */
39 class StringWithLang
40 {
41 public:
42     StringWithLang() { }
43     StringWithLang(DPL::String s): string(s) { }
44     StringWithLang(DPL::String s, DPL::String l): string(s), lang(l) { }
45     DPL::String getString() { return this->string; }
46     DPL::String getLang() { return this->lang; }
47     bool hasLang() { return !this->lang.empty(); }
48 private:
49     DPL::String string;
50     DPL::String lang;
51 };
52
53 typedef StringWithLang LabelType, IconType, DescriptionType;
54
55 /**
56  * These types are basicaly strings but they should allow usage of different
57  * range of characters or words (details in XML spec.).
58  * For simplicity DPL::Strings are used, although this can lead to XML validation
59  * errors (related to usage of not allowed characters in given places).
60  */
61 typedef DPL::String NcnameType, NmtokenType, AnySimpleType, LangType;
62 typedef DPL::String OperationType, MimeType, UriType, TypeType, PackageType;
63 typedef DPL::OptionalString InstallLocationType, CategoriesType;
64 typedef DPL::String AppCategoryType;
65
66 /**
67  * xmllib2 wrappers
68  */
69 void writeElement(xmlTextWriterPtr writer, const char * name, DPL::String body);
70 void writeText(xmlTextWriterPtr writer, DPL::String text);
71 void writeElement(xmlTextWriterPtr writer, const char * name, const char * body);
72 void writeElementWithOneAttribute(xmlTextWriterPtr writer, const char * name,
73         const char * body, const char * nameAttr, DPL::String bodyAttr,
74         bool condition = true);
75 void startElement(xmlTextWriterPtr writer, const char * name);
76 void endElement(xmlTextWriterPtr writer);
77 void writeAttribute(xmlTextWriterPtr writer, const char * name,
78         DPL::String body, bool condition);
79 void writeAttribute(xmlTextWriterPtr writer, const char * name,
80         const char * body, bool condition);
81
82 /**
83  * @brief author element
84  */
85 class Author
86 {
87 public:
88     Author() {}
89     Author(AnySimpleType e,
90             NcnameType h,
91             LangType l,
92             DPL::String b)
93         : email(e), href(h), lang(l), body(b) {}
94     void serialize(xmlTextWriterPtr writer);
95 private:
96     AnySimpleType email;
97     NcnameType href;
98     LangType lang;
99     DPL::String body;
100 };
101
102 typedef Author AuthorType;
103
104 /**
105  * @brief application-service element
106  */
107 class AppControl
108 {
109 public:
110     AppControl() {}
111     void addOperation(const OperationType &x) { this->operation.push_back(x); }
112     void addUri(const UriType &x) { this->uri.push_back(x); }
113     void addMime(const MimeType &x) { this->mime.push_back(x); }
114     void serialize(xmlTextWriterPtr writer);
115 private:
116     std::list<OperationType> operation; //attr name AnySimpleType
117     std::list<UriType> uri; //attr name AnySimpleType
118     std::list<MimeType> mime; //attr name AnySimpleType
119 };
120
121 typedef AppControl AppControlType;
122
123 /**
124  * @brief ime-application element
125  */
126 class ImeApplication
127 {
128 public:
129     ImeApplication() {}
130     void setAppid(const NcnameType &x) { this->appid = x; }
131     void setExec(const NcnameType &x) { this->exec = x; }
132     void setMultiple(bool x) { this->multiple = x; }
133     void setNodisplay(bool x) { this->nodisplay = x; }
134     void setType(const TypeType &x) { this->type = x; }
135     void addLabel(const LabelType &x) { this->label.push_back(x); }
136     void addIcon(const IconType &x) { this->icon.push_back(x); }
137     void serialize(xmlTextWriterPtr writer);
138 private:
139     NcnameType appid;
140     NcnameType exec;
141     DPL::OptionalBool multiple;
142     DPL::OptionalBool nodisplay;
143     TypeType type;
144     std::list<LabelType> label;
145     std::list<IconType> icon;
146 };
147
148 typedef ImeApplication ImeApplicationType;
149
150 /**
151  * @brief service-application element
152  */
153 class ServiceApplication
154 {
155 public:
156     ServiceApplication() {}
157     void setAppid(const NcnameType &x) { this->appid = x; }
158     void setAutoRestart(bool x) { this->autoRestart = x; }
159     void setExec(const AnySimpleType &x) { this->exec = x; }
160     void setOnBoot(bool x) { this->onBoot = x; }
161     void setType(const TypeType &x) { this->type = x; }
162     void addLabel(const LabelType &x) { this->label.push_back(x); }
163     void addIcon(const IconType &x) { this->icon.push_back(x); }
164     void addAppControl(const AppControlType &x)
165     {
166         this->appControl.push_back(x);
167     }
168     void serialize(xmlTextWriterPtr writer);
169 private:
170     NcnameType appid;
171     DPL::OptionalBool autoRestart;
172     AnySimpleType exec;
173     DPL::OptionalBool onBoot;
174     TypeType type;
175     std::list<LabelType> label; //attr name AnySimpleType
176     std::list<IconType> icon; //attr name AnySimpleType
177     std::list<AppControlType> appControl; //attr name AnySimpleType
178 };
179
180 typedef ServiceApplication ServiceApplicationType;
181
182 /**
183  * @brief ui-application element
184  */
185 class UiApplication
186 {
187 public:
188     UiApplication() {}
189     void setAppid(const NcnameType &x) { this->appid = x; }
190     void setExtraid(const NcnameType &x) { this->extraid = x; }
191     void setExec(const AnySimpleType &x) { this->exec = x; }
192     void setMultiple(bool x) { this->multiple = x; }
193     void setNodisplay(bool x) { this->nodisplay = x; }
194     void setTaskmanage(bool x) { this->taskmanage = x; }
195     void setType(const TypeType &x) { this->type = x; }
196     void setCategories(const NcnameType &x) { this->categories = x; }
197     void addLabel(const LabelType &x) { this->label.push_back(x); }
198     void addIcon(const IconType &x) { this->icon.push_back(x); }
199     void addAppControl(const AppControlType &x)
200     {
201         this->appControl.push_back(x);
202     }
203     void addAppCategory(const AppCategoryType &x)
204     {
205         this->appCategory.push_back(x);
206     }
207     void serialize(xmlTextWriterPtr writer);
208 private:
209     NcnameType appid;
210     NcnameType extraid;
211     AnySimpleType exec;
212     DPL::OptionalBool multiple;
213     DPL::OptionalBool nodisplay;
214     DPL::OptionalBool taskmanage;
215     TypeType type;
216     CategoriesType categories;
217     std::list<LabelType> label;
218     std::list<IconType> icon;
219     std::list<AppControlType> appControl;
220     std::list<AppCategoryType> appCategory;
221 };
222
223 typedef UiApplication UiApplicationType;
224
225 /**
226  * @brief manifest element
227  *
228  * Manifest xml file representation.
229  */
230 class Manifest
231 {
232 public:
233     Manifest() {}
234     void serialize(xmlTextWriterPtr writer);
235     void generate(DPL::String filename);
236
237     void addLabel(const LabelType &x) { this->label.push_back(x); }
238     void addIcon(const IconType &x) { this->icon.push_back(x); }
239     void addAuthor(const AuthorType &x) { this->author.push_back(x); };
240     void addDescription(const DescriptionType &x)
241     {
242         this->description.push_back(x);
243     }
244 //    void addCompatibility(const CompatibilityType &x)
245 //    {
246 //        this->compatibility.push_back(x);
247 //    }
248 //    void addDeviceProfile(const DeviceProfileType &x)
249 //    {
250 //        this->deviceProfile.push_back(x);
251 //    }
252     void addServiceApplication(const ServiceApplicationType &x)
253     {
254         this->serviceApplication.push_back(x);
255     }
256     void addUiApplication(const UiApplicationType &x)
257     {
258         this->uiApplication.push_back(x);
259     }
260     void addImeApplication(const ImeApplicationType &x)
261     {
262         this->imeApplication.push_back(x);
263     }
264 //    void addFont(const FontType &x) { this->font.push_back(x); }
265
266     void setInstallLocation(const InstallLocationType &x)
267     {
268         this->installLocation = x;
269     }
270     void setPackage(const NcnameType &x) { this->package = x; }
271     void setType(const PackageType &x) { this->type = x; }
272     void setVersion(const NmtokenType &x) { this->version = x; }
273 private:
274     std::list<LabelType> label;
275     std::list<IconType> icon;
276     std::list<AuthorType> author;
277     std::list<DescriptionType> description;
278 //    std::list<CompatibilityType> compatibility;
279 //    std::list<DeviceProfileType> deviceProfile;
280     std::list<ServiceApplicationType> serviceApplication;
281     std::list<UiApplicationType> uiApplication;
282     std::list<ImeApplicationType> imeApplication;
283 //    std::list<FontType> font;
284     InstallLocationType installLocation;
285     NcnameType package;
286     PackageType type;
287     NmtokenType version;
288 };
289
290 } //namespace Jobs
291 } //namespace WidgetInstall
292
293 #endif //INSTALLER_JOBS_MANIFEST_H