upload tizen1.0 source
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Widget / Widget.cpp
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  *
18  *
19  * @file       Widget.h
20  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #include <dpl/log/log.h>
26 #include <Commons/StringUtils.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
28 #include "Widget.h"
29 #include <WidgetDB/IWidgetDB.h>
30 #include <WidgetDB/WidgetDBMgr.h>
31
32
33 namespace WrtDeviceApis {
34 namespace Widget {
35 using namespace std;
36 using namespace WidgetDB::Api;
37
38 Widget::Widget() 
39 {
40     using namespace WrtDeviceApis::Commons;
41     m_widgetId = WrtAccessSingleton::Instance().getWidgetId();
42 }
43
44 Widget::~Widget()
45 {
46 }
47
48 string Widget::getProperty(ConfigAttribute attr) const
49 {
50     checkWidgetId();
51
52     string value;
53     Try {
54         IWidgetDBPtr widgetDB = getWidgetDB(m_widgetId);
55         value = widgetDB->getConfigValue(attr);
56     }
57     Catch(Commons::InvalidArgumentException){
58         LogError("Invalid argument exception");
59         Throw(Commons::PlatformException);
60     }
61
62     return value;
63 }
64
65 string Widget::getAuthor() const
66 {
67     checkWidgetId();
68
69     if (!m_author.isValid()) {
70         m_author.setValue(getProperty(ConfigAttribute::AUTHOR_NAME));
71     }
72     return m_author.getValue();
73 }
74
75 string Widget::getAuthorEmail() const
76 {
77     checkWidgetId();
78
79     if (!m_authorEmail.isValid()) {
80         m_authorEmail.setValue(getProperty(ConfigAttribute::AUTHOR_EMAIL));
81     }
82     return m_authorEmail.getValue();
83 }
84
85 string Widget::getAuthorHref() const
86 {
87     checkWidgetId();
88
89     if (!m_authorHref.isValid()) {
90         m_authorHref.setValue(getProperty(ConfigAttribute::AUTHOR_HREF));
91     }
92     return m_authorHref.getValue();
93 }
94
95 string Widget::getDescription() const
96 {
97     checkWidgetId();
98
99     if (!m_description.isValid()) {
100         m_description.setValue(getProperty(ConfigAttribute::DESCRIPTION));
101     }
102     return m_description.getValue();
103 }
104
105 string Widget::getId() const
106 {
107     checkWidgetId();
108
109     LogDebug("entered");
110     if (!m_id.isValid()) {
111         m_id.setValue(getProperty(ConfigAttribute::ID));
112     }
113     return m_id.getValue();
114 }
115
116 string Widget::getName() const
117 {
118     checkWidgetId();
119
120     if (!m_name.isValid()) {
121         m_name.setValue(getProperty(ConfigAttribute::NAME));
122     }
123     return m_name.getValue();
124 }
125
126 string Widget::getShortName() const
127 {
128     checkWidgetId();
129
130     if (!m_shortName.isValid()) {
131         m_shortName.setValue(getProperty(ConfigAttribute::SHORT_NAME));
132     }
133     return m_shortName.getValue();
134 }
135
136 string Widget::getVersion() const
137 {
138     checkWidgetId();
139
140     if (!m_version.isValid()) {
141         m_version.setValue(getProperty(ConfigAttribute::VERSION));
142     }
143     return m_version.getValue();
144 }
145
146 unsigned int Widget::getHeight() const
147 {
148     checkWidgetId();
149
150     if (!m_height.isValid()) {
151         m_height.setValue(Commons::String::toInt(
152             getProperty(ConfigAttribute::HEIGHT)));
153     }
154     return m_height.getValue();
155 }
156
157 unsigned int Widget::getWidth() const
158 {
159     checkWidgetId();
160
161     if (!m_width.isValid()) {
162         m_width.setValue(Commons::String::toInt(
163             getProperty(ConfigAttribute::WIDTH)));
164     }
165     return m_width.getValue();
166 }
167
168 void Widget::checkWidgetId() const
169 {
170     if (m_widgetId < 0) {
171         LogError("Invalid widget id");
172         Throw(Commons::InvalidArgumentException);
173     }
174     return;
175 }
176 }
177 }