2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file widget_model.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief Implementation file for widget model
22 #include <widget_model.h>
23 #include <dpl/sstream.h>
24 #include <dpl/event/model_bind_to_dao.h>
25 #include <dpl/wrt-dao-ro/global_config.h>
26 #include <dpl/wrt-dao-ro/widget_config.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
29 #include <dpl/utils/folder_size.h>
31 using namespace WrtDB;
33 template <typename RetType, RetType (WidgetDAOReadOnly::*extFun)() const >
34 struct BindToWidgetDAO :
35 DPL::Event::BindToDAO<WidgetModel,
39 &WidgetModel::getTizenId,
44 template <typename RetType, RetType(*extFun) (DPL::String)>
45 struct BindToWidgetDAOStatic :
46 DPL::Event::BindToDAO_Static<WidgetModel,
49 &WidgetModel::getTizenId,
54 WidgetModel::WidgetModel(const std::string &tizenId) :
55 TizenId(DPL::FromASCIIString(tizenId)),
56 Handle(this, WidgetDAOReadOnly::getHandle(DPL::FromASCIIString(tizenId))),
57 Type(this, &BindToWidgetDAO<WidgetType,
58 &WidgetDAOReadOnly::getWidgetType>::Get),
61 &BindToWidgetDAO<WidgetSize,
62 &WidgetDAOReadOnly::getPreferredSize>::Get),
64 //localized, so not binded
66 //localized, so not binded
67 PrefixURL(this, L"file://"),
70 &BindToWidgetDAO<DPL::String, &WidgetDAOReadOnly::getFullPath>::Get),
71 PersistentStoragePath(this,
73 WidgetConfig::GetWidgetPersistentStoragePath(
76 // use of multiple widget model
77 TemporaryStoragePath(this,
79 WidgetConfig::GetWidgetTemporaryStoragePath(
80 this->TizenId + getTimestamp()))
84 &BindToWidgetDAO<WidgetGUID, &WidgetDAOReadOnly::getGUID>::Get),
87 &BindToWidgetDAO<DPL::OptionalString,
88 &WidgetDAOReadOnly::getDefaultlocale>::Get),
89 Version(this, &WidgetModel::readVersion),
91 //localized, so not binded
93 //localized, so not binded
95 //localized, so not binded
97 //localized, so not binded
99 //localized, so not binded
103 &BindToWidgetDAO<DPL::OptionalString,
104 &WidgetDAOReadOnly::getSplashImgSrc>::Get),
107 &BindToWidgetDAO<WindowModeList,
108 &WidgetDAOReadOnly::getWindowModes>::Get),
109 //localized, so not binded
110 Standard(this, &WidgetModel::readStandard),
111 ApplicationStorage(this, &WidgetModel::getApplicationStorage),
112 // AccessNetwork(this, false),
113 // WarpDefinitionEmpty(this),
116 //TODO this type has to be here now, as Property constructor is wrongly
118 (DPL::Event::Property<bool,
119 DPL::Event::PropertyReadOnly,
120 DPL::Event::PropertyStorageDynamicCached>::ReadDelegateType) &
121 BindToWidgetDAO<bool, &WidgetDAOReadOnly::getBackSupported>::Get),
125 //TODO this type has to be here now, as Property constructor is wrongly
127 (DPL::Event::Property<bool,
128 DPL::Event::PropertyReadOnly,
129 DPL::Event::PropertyStorageDynamicCached>::ReadDelegateType) &
130 BindToWidgetDAO<bool, &WidgetDAOReadOnly::isTestWidget>::Get),
137 DPL::String WidgetModel::getTizenId() const
142 WidgetStorageSize WidgetModel::getApplicationStorage(DPL::Event::Model *model)
145 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
146 WidgetDAOReadOnly widgetDao(widgetModel->TizenId);
148 const DPL::String installPath = widgetDao.getPath();
149 const DPL::String persistentPath =
150 widgetModel->PersistentStoragePath.Get();
151 const DPL::String temporaryPath =
152 widgetModel->TemporaryStoragePath.Get();
155 Utils::getFolderSize(DPL::ToUTF8String(installPath));
158 [&installPath](const DPL::String& possiblePrefix)
160 return possiblePrefix.length() <= installPath.length() &&
161 std::equal(possiblePrefix.begin(),
162 possiblePrefix.end(),
163 installPath.begin());
166 size_t persistanceSize =
167 Utils::getFolderSize(DPL::ToUTF8String(persistentPath));
168 // we have to remember that persistance path can be inside install path
169 if (isPrefix(persistentPath)) {
170 appSize -= persistanceSize;
173 size_t temporarySize =
174 Utils::getFolderSize(DPL::ToUTF8String(temporaryPath));
175 // we have to remember that persistance path can be inside install path
176 if (isPrefix(temporaryPath)) {
177 appSize -= temporarySize;
180 LogDebug("App size: " << appSize);
181 LogDebug("Persistance size: " << persistanceSize);
182 LogDebug("Temporary size: " << temporaryPath);
183 return WidgetStorageSize(appSize, persistanceSize + temporarySize);
186 namespace { //anonymous
187 const float FLOAT_WAC20_REPRESENTATION = 2.0;
188 } //namespace anonymous
190 WidgetStandard WidgetModel::readStandard(DPL::Event::Model *model)
192 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
194 DPL::OptionalString minWacVersionString =
195 WidgetDAOReadOnly(widgetModel->TizenId).getMinimumWacVersion();
197 if (!minWacVersionString) {
198 return WidgetStandard_Unknown;
201 std::stringstream minWacVersionStream(DPL::ToUTF8String(
202 *minWacVersionString));
203 minWacVersionStream >> minWacVersion;
204 if (minWacVersionStream.fail()) {
205 return WidgetStandard_Unknown;
206 } else if (minWacVersion == FLOAT_WAC20_REPRESENTATION) {
207 return WidgetStandard_Wac20;
209 return WidgetStandard_Unknown;
214 OptionalWidgetVersion WidgetModel::readVersion(DPL::Event::Model *model)
216 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
218 DPL::OptionalString optionalVersionString =
219 WidgetDAOReadOnly(widgetModel->TizenId).getVersion();
221 if (!optionalVersionString) {
222 return OptionalWidgetVersion();
224 return OptionalWidgetVersion(WidgetVersion(*optionalVersionString));
228 DPL::String WidgetModel::getTimestamp()
233 gettimeofday(&tv, NULL);
234 sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
235 LogInfo("timestamp: " << buff);
236 DPL::String timeString = DPL::FromUTF8String(std::string(buff));