tizen beta release
[framework/web/wrt-commons.git] / tests / localization / mockup_include / dpl / wrt-dao-rw / widget_dao.h
1 /*
2  * Copyright (c) 2011 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  * This file contains the declaration of widget dao class.
18  *
19  * @file    widget_dao_read_only.h
20  * @author  Yang Jie (jie2.yang@samsung.com)
21  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
22  * @author  Pawel Sikorski (p.sikorski@samsung.com)
23  * @version 1.0
24  * @brief   This file contains the declaration of widget dao
25  */
26
27 #ifndef _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
28 #define _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
29
30 #include <time.h>
31
32 #include <list>
33 #include <map>
34 #include <set>
35 #include <string>
36
37 #include <dpl/string.h>
38 #include <dpl/exception.h>
39 #include <dpl/optional_typedefs.h>
40
41 #include <dpl/wrt-dao-ro/common_dao_types.h>
42
43 typedef DPL::OptionalString WidgetGUID;
44
45 namespace ConfigParserData {
46
47 struct Icon
48 {
49     Icon(const DPL::String& src) : src(src)
50     {
51     }
52     DPL::String src;
53     DPL::OptionalInt width;
54     DPL::OptionalInt height;
55     bool operator==(const Icon&) const;
56     bool operator!=(const Icon&) const;
57     bool operator >(const Icon&) const;
58     bool operator>=(const Icon&) const;
59     bool operator <(const Icon&) const;
60     bool operator<=(const Icon&) const;
61 };
62 } // namespace ConfigParserData
63 namespace WrtDB {
64
65 typedef std::list<DPL::String> StringList;
66
67 struct WidgetLocalizedInfo
68 {
69     DPL::OptionalString name;
70     DPL::OptionalString shortName;
71     DPL::OptionalString description;
72     DPL::OptionalString license;
73     DPL::OptionalString licenseHref;
74 };
75
76 typedef std::list<DPL::String> LanguageTagList;
77
78 class WidgetDAO
79 {
80   public:
81     /**
82      * WidgetDAO Exception classes
83      */
84     class Exception
85     {
86       public:
87         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
88         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
89         DECLARE_EXCEPTION_TYPE(Base, ReadOnlyProperty)
90         DECLARE_EXCEPTION_TYPE(Base, GUIDisNull)
91         DECLARE_EXCEPTION_TYPE(Base, UnexpectedEmptyResult)
92         DECLARE_EXCEPTION_TYPE(Base, WidgetNotExist)
93         DECLARE_EXCEPTION_TYPE(Base, AlreadyRegistered)
94     };
95
96   protected:
97     DbWidgetHandle m_widgetHandle;
98  
99   public:
100     struct WidgetLocalizedIconRow
101     {
102         int appId;
103         int iconId;
104         DPL::String widgetLocale;
105     };
106     typedef std::list<WidgetLocalizedIconRow> WidgetLocalizedIconList;
107
108     struct WidgetIconRow
109     {
110         int iconId;
111         int appId;
112         DPL::String iconSrc;
113         DPL::OptionalInt iconWidth;
114         DPL::OptionalInt iconHeight;
115     };
116     typedef std::list<WidgetIconRow> WidgetIconList;
117
118     struct WidgetStartFileRow
119     {
120         int startFileId;
121         int appId;
122         DPL::String src;
123     };
124     typedef std::list<WidgetStartFileRow> WidgetStartFileList;
125
126     struct WidgetLocalizedStartFileRow
127     {
128         int startFileId;
129         int appId;
130         DPL::String widgetLocale;
131         DPL::String type;
132         DPL::String encoding;
133     };
134     typedef std::list<WidgetLocalizedStartFileRow> LocalizedStartFileList;
135
136
137     /**
138      * This is a constructor.
139      *
140      * @param[in] widgetHandle application id of widget.
141      */
142     WidgetDAO(DbWidgetHandle widgetHandle)
143       : m_widgetHandle(widgetHandle)
144     {}
145
146     /**
147      * Destructor
148      */
149     virtual ~WidgetDAO(){}
150
151     /**
152      * This method returns widget handle(m_widgetHandle).
153      *
154      * @return widget handle(m_widgetHandle).
155      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
156      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in DB table.
157      */
158     DbWidgetHandle getHandle() const { return m_widgetHandle; }
159     DbWidgetHandle getHandle(const WidgetGUID GUID) const;
160     static DbWidgetHandle getHandle(const DPL::String pkgName);
161
162     /**
163      * This method returns the root directory of widget resource.
164      *
165      * @return path name of root directory.
166      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
167      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
168      * DB table.
169      */
170     DPL::String getPath() const;
171     void setPath(const DPL::String &path) const;
172
173     /**
174      * This method returns the defaultlocale for the widget.
175      *
176      * @return defaultlocale
177      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
178      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
179      *  DB table.
180      */
181     DPL::OptionalString getDefaultlocale() const;
182
183     /**
184      * This method returns list of localized icons files;
185      *
186      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
187      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
188      *  DB table.
189      */
190     WidgetLocalizedIconList getLocalizedIconList() const;
191
192     /**
193      * This method returns list of icons files;
194      *
195      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
196      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
197      *  DB table.
198      */
199     WidgetIconList getIconList() const;
200
201     /**
202      * This method returns list of localized start files;
203      *
204      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
205      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
206      *  DB table.
207      */
208     LocalizedStartFileList getLocalizedStartFileList() const;
209     void setLocalizedStartFileList(const LocalizedStartFileList &list) const;
210     /**
211      * This method returns list of start files;
212      *
213      * @exception WRT_CONF_ERR_EMDB_FAILURE - Fail to query DB table.
214      * @exception WRT_CONF_ERR_EMDB_NO_RECORD - Can not find matching records in
215      *  DB table.
216      */
217     WidgetStartFileList getStartFileList() const;
218     void setStartFileList(const WidgetStartFileList &list) const;
219
220     WidgetLocalizedInfo getLocalizedInfo(const DPL::String& languageTag) const;
221   protected:
222     static std::map<DbWidgetHandle,WidgetStartFileList> s_startFileMap;
223     static std::map<DbWidgetHandle,LocalizedStartFileList> s_localizedStartFileMap;
224     static std::map<DbWidgetHandle,DPL::String> s_pathMap;
225 };
226
227 } // namespace WrtDB
228
229 #endif // _WRT_SRC_CONFIGURATION_WIDGET_DAO_READ_ONLY_H_
230