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::getHandle,
44 template <typename RetType, RetType(*extFun) (WidgetHandle)>
45 struct BindToWidgetDAOStatic :
46 DPL::Event::BindToDAO_Static<WidgetModel,
49 &WidgetModel::getHandle,
54 WidgetModel::WidgetModel(const std::string &tizenId) :
55 Handle(this, WidgetDAOReadOnly::getHandle(DPL::FromASCIIString(tizenId))),
56 Type(this, &BindToWidgetDAO<WidgetType,
57 &WidgetDAOReadOnly::getWidgetType>::Get),
60 &BindToWidgetDAO<WidgetSize,
61 &WidgetDAOReadOnly::getPreferredSize>::Get),
63 //localized, so not binded
65 //localized, so not binded
66 PrefixURL(this, L"file://"),
69 &BindToWidgetDAO<DPL::String, &WidgetDAOReadOnly::getFullPath>::Get),
70 PersistentStoragePath(this,
72 WidgetConfig::GetWidgetPersistentStoragePath(
75 // use of multiple widget model
76 TemporaryStoragePath(this,
78 WidgetConfig::GetWidgetTemporaryStoragePath(
79 readTizenId(this) + getTimestamp()))
83 &BindToWidgetDAO<WidgetGUID, &WidgetDAOReadOnly::getGUID>::Get),
86 &BindToWidgetDAO<DPL::OptionalString,
87 &WidgetDAOReadOnly::getDefaultlocale>::Get),
88 Version(this, &WidgetModel::readVersion),
90 //localized, so not binded
92 //localized, so not binded
94 //localized, so not binded
96 //localized, so not binded
98 //localized, so not binded
102 &BindToWidgetDAO<DPL::OptionalString,
103 &WidgetDAOReadOnly::getSplashImgSrc>::Get),
106 &BindToWidgetDAO<WindowModeList,
107 &WidgetDAOReadOnly::getWindowModes>::Get),
108 TizenId(this, &WidgetModel::readTizenId),
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 WidgetHandle WidgetModel::getHandle() const
142 WidgetStorageSize WidgetModel::getApplicationStorage(DPL::Event::Model *model)
145 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
146 WidgetDAOReadOnly widgetDao(widgetModel->Handle.Get());
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 DPL::String WidgetModel::readTizenId(DPL::Event::Model *model)
188 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
189 DPL::OptionalString tizenId =
190 WidgetDAOReadOnly(widgetModel->Handle.Get()).getPkgname();
192 Assert(!!tizenId && "tizen id shouldn't be NULL");
193 DPL::String id = *tizenId;
197 namespace { //anonymous
198 const float FLOAT_WAC20_REPRESENTATION = 2.0;
199 } //namespace anonymous
201 WidgetStandard WidgetModel::readStandard(DPL::Event::Model *model)
203 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
205 DPL::OptionalString minWacVersionString =
206 WidgetDAOReadOnly(widgetModel->Handle.Get()).getMinimumWacVersion();
208 if (!minWacVersionString) {
209 return WidgetStandard_Unknown;
212 std::stringstream minWacVersionStream(DPL::ToUTF8String(
213 *minWacVersionString));
214 minWacVersionStream >> minWacVersion;
215 if (minWacVersionStream.fail()) {
216 return WidgetStandard_Unknown;
217 } else if (minWacVersion == FLOAT_WAC20_REPRESENTATION) {
218 return WidgetStandard_Wac20;
220 return WidgetStandard_Unknown;
225 OptionalWidgetVersion WidgetModel::readVersion(DPL::Event::Model *model)
227 WidgetModel *widgetModel = static_cast<WidgetModel *>(model);
229 DPL::OptionalString optionalVersionString =
230 WidgetDAOReadOnly(widgetModel->Handle.Get()).getVersion();
232 if (!optionalVersionString) {
233 return OptionalWidgetVersion();
235 return OptionalWidgetVersion(WidgetVersion(*optionalVersionString));
239 DPL::String WidgetModel::getTimestamp()
244 gettimeofday(&tv, NULL);
245 sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
246 LogInfo("timestamp: " << buff);
247 DPL::String timeString = DPL::FromUTF8String(std::string(buff));