localizeWidgetModel() removal
authorMarcin Kaminski <marcin.ka@samsung.com>
Wed, 7 Nov 2012 14:35:44 +0000 (15:35 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Mon, 19 Nov 2012 15:34:50 +0000 (16:34 +0100)
New LanguageTagsPpovider API is used
for default widget locales setting
instead of calling deprecated
localizeWidgetModel()

[Issue#] N/A
[Feature] Code refactoring & cleaning.
[Cause] localizeWidgetModel() was the only
method in file and did not do anymore
what it's name suggest.
[Solution] N/A

[Verification] Successfull build.

Change-Id: Ic11531d63b7f5bc77ff183d33fe29115b7ab2f65

src/CMakeLists.txt
src/domain/widget_deserialize_model.cpp
src/domain/widget_localize_model.cpp [deleted file]
src/domain/widget_localize_model.h [deleted file]
src/view/webkit/bundles/wrt-wk2-bundle.cpp
src/wrt-client/wrt-client.cpp

index 2bdb064..4d3dc0d 100755 (executable)
@@ -30,7 +30,6 @@ SET(WRT_CORE_BASE_SOURCES
     ${WRT_SRC_DIR}/domain/global_context.cpp
     ${WRT_SRC_DIR}/domain/widget_data_types.cpp
     ${WRT_SRC_DIR}/domain/widget_deserialize_model.cpp
-    ${WRT_SRC_DIR}/domain/widget_localize_model.cpp
     ${WRT_SRC_DIR}/domain/localization_setting.cpp
     ${WRT_SRC_DIR}/domain/widget_model.cpp
     ${WRT_SRC_DIR}/domain/main_thread.cpp
index 3e1e324..6c121d9 100644 (file)
  * @brief   Widget deserialization creates WidgetModel from WidgetDAOReadOnly
  */
 
-#include "widget_localize_model.h"
 #include "widget_model.h"
 
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
 #include <dpl/log/log.h>
+// to apply widget default locales instead of calling localizeWidgetModel()
+#include <dpl/localization/LanguageTagsProvider.h>
+
 
 namespace Domain {
 
@@ -36,11 +38,12 @@ std::shared_ptr<WidgetModel> deserializeWidgetModel(const std::string& tizenId)
         LogDebug("Widget installed - creating model");
         model.reset(new WidgetModel(tizenId));
 
-        // Read DAO data
         WrtDB::WidgetDAOReadOnly dao(dplTizenId);
-
-        // Set localized data
-        Domain::localizeWidgetModel(model->defaultlocale.Get());
+        DPL::Optional<DPL::String> defloc = model->defaultlocale.Get();
+        if(!defloc.IsNull())
+        {
+            LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
+        }
 
         WrtDB::WidgetAccessInfoList widgetAccessInfoList;
         // widgetAccessInfoList is output parameter
diff --git a/src/domain/widget_localize_model.cpp b/src/domain/widget_localize_model.cpp
deleted file mode 100644 (file)
index 241e626..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/**
- * @file    widget_localize_model.cpp
- * @author  Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
- * @version 1.0
- * @brief   Widget localize localizes WidgetModel from system configuration
- */
-
-#include <dpl/foreach.h>
-#include <dpl/log/log.h>
-#include <dpl/optional_typedefs.h>
-#include <dpl/localization/LanguageTagsProvider.h>
-
-namespace Domain {
-
-//TODO this should be moved and renamed in LanguageTagsProviderSingleton
-void localizeWidgetModel(const DPL::OptionalString& defaultLocale)
-{
-    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);
-        } else {
-            LanguageTags::iterator placeToInsert = tags.end();
-            --placeToInsert;
-            if (*placeToInsert != L"") { ++placeToInsert; }
-            tags.insert(placeToInsert, *defaultLocale);
-        }
-    }
-    LogDebug("Setting runtime widget locale:");
-    FOREACH(it, tags) {
-        LogDebug("Locale: " << *it);
-    }
-    LanguageTagsProviderSingleton::Instance().setLanguageTags(tags);
-}
-
-} //Namespace Domain
diff --git a/src/domain/widget_localize_model.h b/src/domain/widget_localize_model.h
deleted file mode 100644 (file)
index 78e43fe..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/**
- * @file    widget_localize_model.h
- * @author  Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
- * @version 1.0
- * @brief   Widget localization localizes WidgetModel from current settings
- */
-#ifndef WRT_ENGINE_SRC_DOMAIN_WIDGET_LOCALIZE_MODEL_H_
-#define WRT_ENGINE_SRC_DOMAIN_WIDGET_LOCALIZE_MODEL_H_
-
-#include <dpl/optional_typedefs.h>
-
-namespace Domain {
-
-/**
- * @brief Localize widget model
- *
- * Function is using localization utils and W3C file localization
- * to process current language settingto enhance widget model with
- * localized properties.
- *
- * @param[in] model
- */
-void localizeWidgetModel(const DPL::OptionalString& defaultLocale);
-
-} //Namespace Domain
-
-#endif // ifndef WRT_ENGINE_SRC_DOMAIN_WIDGET_LOCALIZE_MODEL_H_
-
index 1bc730f..7543851 100644 (file)
@@ -231,25 +231,16 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
         // reset language tags (create new tags based on system locales)
         LanguageTagsProviderSingleton::Instance().resetLanguageTags();
         DPL::OptionalString defaultLocale = dao.getDefaultlocale();
-        LanguageTags tags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
-        // check if default widget language exists in language's list
-        if (!!defaultLocale &&
-            std::find(tags.begin(), tags.end(), *defaultLocale) == tags.end())
+        if(!defaultLocale.IsNull())
         {
-            if (tags.size() < 2) {
-                tags.push_front(*defaultLocale);
-            } else {
-                LanguageTags::iterator placeToInsert = tags.end();
-                --placeToInsert;
-                if (*placeToInsert != L"") { ++placeToInsert; }
-                tags.insert(placeToInsert, *defaultLocale);
-            }
+            LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defaultLocale);
         }
+        LanguageTags tags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
         LogDebug("Current widget locales (language tags):");
         FOREACH(it, tags) {
             LogDebug("Locale: " << *it);
         }
-        LanguageTagsProviderSingleton::Instance().setLanguageTags(tags);
+
         // ** Language tags setting completed **
 
         if (argScale != "null" && argScale[0] == '_')
index 36d9668..2827a63 100755 (executable)
@@ -22,7 +22,6 @@
 #include <common/application_data.h>
 #include <core_module.h>
 #include <global_logic.h>
-#include <widget_localize_model.h>
 #include <localization_setting.h>
 #include <widget_deserialize_model.h>
 #include <EWebKit2.h>
@@ -464,10 +463,13 @@ void WrtClient::launchStep()
         return;
     }
 
-    ADD_PROFILING_POINT("localizeWidgetModel", "start");
     m_dao.reset(new WrtDB::WidgetDAOReadOnly(DPL::FromASCIIString(m_tizenId)));
-    Domain::localizeWidgetModel(m_dao->getDefaultlocale());
-    ADD_PROFILING_POINT("localizeWidgetModel", "stop");
+    DPL::Optional<DPL::String> defloc = m_dao->getDefaultlocale();
+    if(!defloc.IsNull())
+    {
+        LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
+    }
+
     LocalizationSetting::SetLanguageChangedCallback(
             languageChangedCallback, this);
 
@@ -701,22 +703,24 @@ void WrtClient::shutdownStep()
 int WrtClient::languageChangedCallback(void *data)
 {
     LogDebug("Language Changed");
+    if(!data)
+        return 0;
     WrtClient* wrtClient = static_cast<WrtClient*>(data);
+    if(!(wrtClient->m_dao))
+        return 0;
 
-    LanguageTags oldtags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
     // reset function fetches system locales and recreates language tags
     LanguageTagsProviderSingleton::Instance().resetLanguageTags();
-    LanguageTags newtags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
-
-    // check whether LanguageTags changed or not
-    if (oldtags != newtags) {
-        // update localized data
-        Domain::localizeWidgetModel(wrtClient->m_dao->getDefaultlocale());
+    // widget default locales are added to language tags below
+    DPL::OptionalString defloc = wrtClient->m_dao->getDefaultlocale();
+    if(!defloc.IsNull())
+    {
+        LanguageTagsProviderSingleton::Instance().addWidgetDefaultLocales(*defloc);
+    }
 
-        if (true == wrtClient->m_launched &&
-                wrtClient->m_widgetState != WidgetState_Stopped) {
-            wrtClient->m_widget->ReloadStartPage();
-        }
+    if (wrtClient->m_launched &&
+            wrtClient->m_widgetState != WidgetState_Stopped) {
+        wrtClient->m_widget->ReloadStartPage();
     }
     return 0;
 }