update wrt_0.8.107
[platform/framework/web/wrt.git] / src / domain / widget_localize_model.cpp
index b7fd4a5..241e626 100644 (file)
  * @brief   Widget localize localizes WidgetModel from system configuration
  */
 
-#include <algorithm>
-
 #include <dpl/foreach.h>
 #include <dpl/log/log.h>
-
-#include <widget_model.h>
-#include <dpl/localization/w3c_file_localization.h>
-#include <dpl/localization/localization_utils.h>
+#include <dpl/optional_typedefs.h>
+#include <dpl/localization/LanguageTagsProvider.h>
 
 namespace Domain {
 
-void localizeWidgetModel(const std::shared_ptr<WidgetModel>& model)
+//TODO this should be moved and renamed in LanguageTagsProviderSingleton
+void localizeWidgetModel(const DPL::OptionalString& defaultLocale)
 {
-    using namespace WrtDB;
-
-    LogDebug("Updating model with localized info ...");
-    LanguageTagsList tags = LocalizationUtils::GetUserAgentLanguageTags();
-    DPL::OptionalString defaultlocale = model->defaultlocale.Get();
-    LogDebug("Default locale for widget: " << defaultlocale);
-    if (!!defaultlocale &&
-        std::find(tags.begin(), tags.end(), *defaultlocale) == tags.end())
+    LogDebug("Default locale for widget: " << defaultLocale);
+    LanguageTags tags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
+    if (!!defaultLocale &&
+        std::find(tags.begin(), tags.end(), *defaultLocale) == tags.end())
     {
         if (tags.size() < 2) {
-            tags.push_front(*defaultlocale);
+            tags.push_front(*defaultLocale);
         } else {
-            LanguageTagsList::iterator placeToInsert = tags.end();
+            LanguageTags::iterator placeToInsert = tags.end();
             --placeToInsert;
             if (*placeToInsert != L"") { ++placeToInsert; }
-            tags.insert(placeToInsert, *defaultlocale);
+            tags.insert(placeToInsert, *defaultLocale);
         }
     }
     LogDebug("Setting runtime widget locale:");
     FOREACH(it, tags) {
         LogDebug("Locale: " << *it);
     }
-    model->LanguageTags.Set(tags);
-
-    WidgetLocalizedInfo localizedInfo =
-        W3CFileLocalization::getLocalizedInfo(model->Handle.Get());
-
-    model->Name.Set(localizedInfo.name);
-    model->ShortName.Set(localizedInfo.shortName);
-    model->Description.Set(localizedInfo.description);
-    model->License.Set(localizedInfo.license);
-    model->LicenseHref.Set(localizedInfo.licenseHref);
-    model->StartURL.Set(W3CFileLocalization::getStartFile(model->Handle.Get()));
-    model->Icon.Set(W3CFileLocalization::getIcon(model->Handle.Get()));
-    LogDebug("... finished");
-    OptionalWidgetStartFileInfo info =
-        W3CFileLocalization::getStartFileInfo(
-            model->Handle.Get(),
-            model->LanguageTags.Get());
-    model->StartFileInfo.Set(info);
+    LanguageTagsProviderSingleton::Instance().setLanguageTags(tags);
 }
 
 } //Namespace Domain