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_localize_model.cpp
18 * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
20 * @brief Widget localize localizes WidgetModel from system configuration
25 #include <dpl/foreach.h>
26 #include <dpl/log/log.h>
28 #include <widget_model.h>
29 #include <dpl/localization/w3c_file_localization.h>
30 #include <dpl/localization/localization_utils.h>
34 void localizeWidgetModel(const std::shared_ptr<WidgetModel>& model)
36 using namespace WrtDB;
38 LogDebug("Updating model with localized info ...");
39 LanguageTagsList tags = LocalizationUtils::GetUserAgentLanguageTags();
40 DPL::OptionalString defaultlocale = model->defaultlocale.Get();
41 LogDebug("Default locale for widget: " << defaultlocale);
42 if (!!defaultlocale &&
43 std::find(tags.begin(), tags.end(), *defaultlocale) == tags.end())
45 if (tags.size() < 2) {
46 tags.push_front(*defaultlocale);
48 LanguageTagsList::iterator placeToInsert = tags.end();
50 if (*placeToInsert != L"") { ++placeToInsert; }
51 tags.insert(placeToInsert, *defaultlocale);
54 LogDebug("Setting runtime widget locale:");
56 LogDebug("Locale: " << *it);
58 model->LanguageTags.Set(tags);
60 WidgetLocalizedInfo localizedInfo =
61 W3CFileLocalization::getLocalizedInfo(model->Handle.Get());
63 model->Name.Set(localizedInfo.name);
64 model->ShortName.Set(localizedInfo.shortName);
65 model->Description.Set(localizedInfo.description);
66 model->License.Set(localizedInfo.license);
67 model->LicenseHref.Set(localizedInfo.licenseHref);
68 model->StartURL.Set(W3CFileLocalization::getStartFile(model->Handle.Get()));
69 model->Icon.Set(W3CFileLocalization::getIcon(model->Handle.Get()));
70 LogDebug("... finished");
71 OptionalWidgetStartFileInfo info =
72 W3CFileLocalization::getStartFileInfo(
74 model->LanguageTags.Get());
75 model->StartFileInfo.Set(info);