[Release] wrt_0.8.191
[platform/framework/web/wrt.git] / src / domain / widget_model.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  * @file    widget_model.cpp
18  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for widget model
21  */
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>
28
29 #include <dpl/utils/folder_size.h>
30
31 using namespace WrtDB;
32
33 template <typename RetType, RetType(WidgetDAOReadOnly::*extFun) () const >
34 struct BindToWidgetDAO :
35     DPL::Event::BindToDAO<WidgetModel,
36                           RetType,
37                           DPL::String,
38                           WidgetDAOReadOnly,
39                           &WidgetModel::getTizenId,
40                           extFun>
41 {};
42
43 template <typename RetType, RetType(*extFun) (DPL::String)>
44 struct BindToWidgetDAOStatic :
45     DPL::Event::BindToDAO_Static<WidgetModel,
46                                  RetType,
47                                  DPL::String,
48                                  &WidgetModel::getTizenId,
49                                  extFun>
50 {};
51
52 WidgetModel::WidgetModel(const std::string &tizenId) :
53     TizenId(DPL::FromASCIIString(tizenId)),
54     TzPkgId(this, &BindToWidgetDAO<WrtDB::TizenPkgId,
55                                    &WidgetDAOReadOnly::getTizenPkgId>::Get),
56     Type(this, &BindToWidgetDAO<WidgetType,
57                                 &WidgetDAOReadOnly::getWidgetType>::Get),
58     CspPolicy(this, &BindToWidgetDAO<DPL::OptionalString,
59                                      &WidgetDAOReadOnly::getCspPolicy>::Get),
60     CspReportOnlyPolicy(this, &BindToWidgetDAO<DPL::OptionalString,
61                         &WidgetDAOReadOnly::getCspPolicyReportOnly>::Get),
62     ActualSize(this),
63     PreferredSize(this,
64                   &BindToWidgetDAO<WidgetSize,
65                                    &WidgetDAOReadOnly::getPreferredSize>::Get),
66     StartURL(this),
67     //localized, so not binded
68     StartFileInfo(this),
69 #ifdef APP_SCHEME_ENABLED
70     PrefixURL(this, DPL::String(L"app://") + DPL::FromASCIIString(tizenId) + L"/"),
71 #else
72     //localized, so not binded
73     // file:// + / : without "/" path, webkit return security error
74     PrefixURL(this, L"file:///"),
75 #endif
76     InstallPath(
77         this,
78         &BindToWidgetDAO<DPL::String, &WidgetDAOReadOnly::getFullPath>::Get),
79     PersistentStoragePath(this,
80                           DPL::FromUTF8String(
81                               WidgetConfig::GetWidgetPersistentStoragePath(
82                                   this->TizenId))
83                           ),
84     // use of multiple widget model
85     TemporaryStoragePath(this,
86                          DPL::FromUTF8String(
87                              WidgetConfig::GetWidgetTemporaryStoragePath(
88                                  this->TizenId + getTimestamp()))
89                          ),
90     defaultlocale(
91         this,
92         &BindToWidgetDAO<DPL::OptionalString,
93                          &WidgetDAOReadOnly::getDefaultlocale>::Get),
94     Name(this),
95     //localized, so not binded
96     ShortName(this),
97     //localized, so not binded
98     Description(this),
99     //localized, so not binded
100     License(this),
101     //localized, so not binded
102     LicenseHref(this),
103     //localized, so not binded
104     Icon(this),
105     SplashImg(
106         this,
107         &BindToWidgetDAO<DPL::OptionalString,
108                          &WidgetDAOReadOnly::getSplashImgSrc>::Get),
109     WindowModes(
110         this,
111         &BindToWidgetDAO<WindowModeList,
112                          &WidgetDAOReadOnly::getWindowModes>::Get),
113     //localized, so not binded
114     //    AccessNetwork(this, false),
115     //    WarpDefinitionEmpty(this),
116     BackSupported(
117         this,
118         //TODO this type has to be here now, as Property constructor is wrongly
119         //chosen
120         (DPL::Event::Property<bool,
121                               DPL::Event::PropertyReadOnly,
122                               DPL::Event::PropertyStorageDynamicCached>::
123              ReadDelegateType) &
124         BindToWidgetDAO<bool, &WidgetDAOReadOnly::getBackSupported>::Get),
125     AccessList(this),
126     IsTestWidget(
127         this,
128         //TODO this type has to be here now, as Property constructor is wrongly
129         //chosen
130         (DPL::Event::Property<bool,
131                               DPL::Event::PropertyReadOnly,
132                               DPL::Event::PropertyStorageDynamicCached>::
133              ReadDelegateType) &
134         BindToWidgetDAO<bool, &WidgetDAOReadOnly::isTestWidget>::Get),
135
136     SettingList(this),
137     AppControlList(this),
138     AppControlIndex(this),
139     SecurityModelVersion(this,
140                          &BindToWidgetDAO<WidgetSecurityModelVersion,
141                           &WidgetDAOReadOnly::getSecurityModelVersion>::Get)
142 {}
143
144 DPL::String WidgetModel::getTizenId() const
145 {
146     return TizenId;
147 }
148
149 DPL::String WidgetModel::getTimestamp()
150 {
151     struct timeval tv;
152     char buff[128];
153
154     gettimeofday(&tv, NULL);
155     sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
156     LogInfo("timestamp: " << buff);
157     DPL::String timeString = DPL::FromUTF8String(std::string(buff));
158     return timeString;
159 }