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