[Release] wrt_0.8.225
[platform/framework/web/wrt.git] / src / domain / widget_deserialize_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_deserialize_model.h
18  * @author  Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19  * @version 1.0
20  * @brief   Widget deserialization creates WidgetModel from WidgetDAOReadOnly
21  */
22
23 #include "widget_model.h"
24
25 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
26 #include <dpl/wrt-dao-ro/widget_config.h>
27 #include <dpl/log/log.h>
28 #include <dpl/optional_typedefs.h>
29 // to apply widget default locales instead of calling localizeWidgetModel()
30 #include <dpl/localization/LanguageTagsProvider.h>
31
32 namespace Domain {
33 std::string getTimestamp()
34 {
35     struct timeval tv;
36     char buff[128];
37
38     gettimeofday(&tv, NULL);
39     sprintf(buff, "%lf", (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f);
40     LogInfo("timestamp: " << buff);
41     return std::string(buff);
42 }
43
44 std::shared_ptr<WidgetModel> deserializeWidgetModel(const std::string& tizenId,
45                                                     DPL::OptionalUInt appControlIndex)
46 {
47     std::shared_ptr<WidgetModel> model;
48     DPL::String dplTizenId(DPL::FromUTF8String(tizenId));
49     if (WrtDB::WidgetDAOReadOnly::isWidgetInstalled(dplTizenId)) {
50         LogDebug("Widget installed - creating model");
51         model.reset(new WidgetModel(tizenId));
52
53         WrtDB::WidgetDAOReadOnly dao(dplTizenId);
54         DPL::String pkgId = dao.getTizenPkgId();
55         model->PersistentStoragePath.Set(
56             DPL::FromUTF8String(
57                 WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(pkgId)));
58         model->TemporaryStoragePath.Set(
59             DPL::FromUTF8String(
60                 WrtDB::WidgetConfig::GetWidgetTemporaryStoragePath(pkgId)));
61
62         model->AppControlIndex.Set(appControlIndex);
63
64         DPL::Optional<DPL::String> defloc = model->defaultlocale.Get();
65         if (!defloc.IsNull()) {
66             LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(
67                 *defloc);
68         }
69
70         WrtDB::WidgetAccessInfoList widgetAccessInfoList;
71         // widgetAccessInfoList is output parameter
72         dao.getWidgetAccessInfo(widgetAccessInfoList);
73         model->AccessList.Set(widgetAccessInfoList);
74
75         // Widget app-control information data
76         WrtDB::WidgetAppControlList widgetApplicationControlList;
77         // widgetApplicationControlList is output parameter
78         dao.getAppControlList(widgetApplicationControlList);
79         model->AppControlList.Set(widgetApplicationControlList);
80
81         // Set Widget Settings
82         WrtDB::WidgetSettings widgetSettings;
83         dao.getWidgetSettings(widgetSettings);
84         model->SettingList.Set(widgetSettings);
85     } else {
86         LogError("Widget is not installed - model not created");
87     }
88     return model;
89 }
90
91 } //Namespace Domain
92