Source code formating unification
[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     ActualSize(this),
59     PreferredSize(this,
60                   &BindToWidgetDAO<WidgetSize,
61                                    &WidgetDAOReadOnly::getPreferredSize>::Get),
62     StartURL(this),
63     //localized, so not binded
64     StartFileInfo(this),
65     //localized, so not binded
66     // file:// + / : without "/" path, webkit return security error
67     PrefixURL(this, L"file:///"),
68     InstallPath(
69         this,
70         &BindToWidgetDAO<DPL::String, &WidgetDAOReadOnly::getFullPath>::Get),
71     PersistentStoragePath(this,
72                           DPL::FromUTF8String(
73                               WidgetConfig::GetWidgetPersistentStoragePath(
74                                   this->TizenId))
75                           ),
76     // use of multiple widget model
77     TemporaryStoragePath(this,
78                          DPL::FromUTF8String(
79                              WidgetConfig::GetWidgetTemporaryStoragePath(
80                                  this->TizenId + getTimestamp()))
81                          ),
82     defaultlocale(
83         this,
84         &BindToWidgetDAO<DPL::OptionalString,
85                          &WidgetDAOReadOnly::getDefaultlocale>::Get),
86     Name(this),
87     //localized, so not binded
88     ShortName(this),
89     //localized, so not binded
90     Description(this),
91     //localized, so not binded
92     License(this),
93     //localized, so not binded
94     LicenseHref(this),
95     //localized, so not binded
96     Icon(this),
97     SplashImg(
98         this,
99         &BindToWidgetDAO<DPL::OptionalString,
100                          &WidgetDAOReadOnly::getSplashImgSrc>::Get),
101     WindowModes(
102         this,
103         &BindToWidgetDAO<WindowModeList,
104                          &WidgetDAOReadOnly::getWindowModes>::Get),
105     //localized, so not binded
106     //    AccessNetwork(this, false),
107     //    WarpDefinitionEmpty(this),
108     BackSupported(
109         this,
110         //TODO this type has to be here now, as Property constructor is wrongly
111         //chosen
112         (DPL::Event::Property<bool,
113                               DPL::Event::PropertyReadOnly,
114                               DPL::Event::PropertyStorageDynamicCached>::
115              ReadDelegateType) &
116         BindToWidgetDAO<bool, &WidgetDAOReadOnly::getBackSupported>::Get),
117     AccessList(this),
118     IsTestWidget(
119         this,
120         //TODO this type has to be here now, as Property constructor is wrongly
121         //chosen
122         (DPL::Event::Property<bool,
123                               DPL::Event::PropertyReadOnly,
124                               DPL::Event::PropertyStorageDynamicCached>::
125              ReadDelegateType) &
126         BindToWidgetDAO<bool, &WidgetDAOReadOnly::isTestWidget>::Get),
127
128     SettingList(this),
129     AppServiceList(this)
130 {}
131
132 DPL::String WidgetModel::getTizenId() const
133 {
134     return TizenId;
135 }
136
137 DPL::String WidgetModel::getTimestamp()
138 {
139     struct timeval tv;
140     char buff[128];
141
142     gettimeofday(&tv, NULL);
143     sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
144     LogInfo("timestamp: " << buff);
145     DPL::String timeString = DPL::FromUTF8String(std::string(buff));
146     return timeString;
147 }