Add code versioning for "SettingInfo TC"
[platform/framework/native/appfw.git] / src / system / FSys_SettingInfoImpl.cpp
index e6e0cd8..4dd0031 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
  * @file               FSys_SettingInfoImpl.cpp
  * @brief              This is the implementation file for _SysSettingInfoImpl class.
  */
+#include <unique_ptr.h>
 #include <system/system_settings.h>
 
-#include <FBase.h>
 #include <FBaseColArrayList.h>
 #include <FBaseSysLog.h>
+#include <FBaseUtilStringUtil.h>
+#include <FIoFile.h>
 
+#include <FIo_FileImpl.h>
 #include <FApp_AppInfo.h>
 #include <FBase_StringConverter.h>
 #include <FBase_NativeError.h>
 #include <FSys_SettingInfoImpl.h>
+
 #include "FSys_SettingClient.h"
 
+using namespace std;
+
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -39,9 +44,6 @@ using namespace Tizen::Base::Utility;
 
 namespace Tizen { namespace System
 {
-//IDs for IPC
-static const int _SYSTEM_RESPONSE_DATA = 2;
-
 //Reserved key
 static const wchar_t* _SETTING_SCREEN_WALLPAPER = L"http://tizen.org/setting/screen.wallpaper";
 static const wchar_t* _SETTING_SYSTEM_SOUND_VOLUME = L"SystemSoundVolume";
@@ -104,7 +106,7 @@ _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String&
 
                if(key == _FONTSIZE)
                {
-                       if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat() == true)
+                       if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
                        {
                                if(value ==  _FONT_SIZE_GIANT || value == _FONT_SIZE_HUGE)
                                {
@@ -118,6 +120,16 @@ _SettingInfoImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::String&
                InitSettingClient();
                SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
                r = pSettingClient->GetValue(key, value);
+
+               if(key == L"Wallpaper")
+               {
+                       if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+                       {
+                               String physicalFilePath = value;
+                               r = Tizen::Io::_FileImpl::ConvertPhysicalToVirtualPath(physicalFilePath, value);
+                               SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting virtual path", GetErrorMessage(r));
+                       }
+               }
        }
        return r;
 }
@@ -166,8 +178,19 @@ result
 _SettingInfoImpl::SetWallpaper(const Tizen::Base::String& filePath)
 {
        InitSettingClient();
+       result r = E_SUCCESS;
+
        SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
-       result r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, filePath);
+
+       String physicalFilePath = filePath;
+
+       if(Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
+       {
+               r = Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(filePath, physicalFilePath);
+               SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting physical path", GetErrorMessage(r));
+       }
+
+       r = pSettingClient->SetValue(_SETTING_SCREEN_WALLPAPER, physicalFilePath);
 
        if(r == E_INVALID_ARG)
                r = E_FILE_NOT_FOUND;
@@ -183,6 +206,7 @@ result
 _SettingInfoImpl::GetValueForPrivilegedKey(const String& key, bool& value)
 {
        InitSettingClient();
+       
        SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
        return pSettingClient->GetValueForPrivilegedKey(key, value);
 }
@@ -209,14 +233,24 @@ _SettingInfoImpl::SetValue(const String& key, String value)
 {
        result r = E_SUCCESS;
        if (key == _FONT_SIZE || key == _FONT_TYPE)
-        {
+       {
                r = SetValueForFont(key, value);
-        }
+       }
        else
        {
                InitSettingClient();
                SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
-               r = pSettingClient->SetValue(key, value);
+
+               if(key == _SETTING_SCREEN_WALLPAPER)
+               {
+                       if(_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
+                       {
+                               String virtualFilePath = value;
+                               r = Tizen::Io::_FileImpl::ConvertVirtualToPhysicalPath(virtualFilePath, value);
+                               SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] It is failed to converting physical path", GetErrorMessage(r));
+                       }
+               }
+               return pSettingClient->SetValue(key, value);
        }
        return r;
 }
@@ -255,9 +289,10 @@ _SettingInfoImpl::ResetToFactoryDefault(void)
 result
 _SettingInfoImpl::SetRingtone(const Tizen::Base::String& filePath)
 {
+       result r = E_SUCCESS;
        InitSettingClient();
        SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
-       result r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
+       r = pSettingClient->SetValue(_SETTING_SOUND_RINGTONE, filePath);
 
        if(r == E_INVALID_ARG)
                r = E_FILE_NOT_FOUND;
@@ -275,9 +310,6 @@ _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
        result r = E_SUCCESS;
        String key;
 
-       InitSettingClient();
-       SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
-
        if (soundCategory == _SETTING_SYSTEM_SOUND_VOLUME)
        {
                key = _SETTING_SOUND_SYSTEM_VOLUME;
@@ -299,6 +331,8 @@ _SettingInfoImpl::SetVolume(const Tizen::Base::String& soundCategory, int level)
                key = soundCategory;
        }
 
+       InitSettingClient();
+       SysTryReturnResult(NID_SYS, pSettingClient != null, E_SYSTEM, "It is failed to intialize setting manager");
        r = pSettingClient->SetValue(key, level);
 
        if (r == E_OBJ_NOT_FOUND)
@@ -478,15 +512,14 @@ _SettingInfoImpl::SetValueForFont(const Tizen::Base::String& key, Tizen::Base::S
        }
        else if(key == _FONT_TYPE)
        {
-               char* pFontType = null;
                int res = 0;
                r = E_SUCCESS;
 
-               pFontType = _StringConverter::CopyToCharArrayN(value);
-               SysTryReturnResult(NID_SYS, pFontType != null, E_SYSTEM, "It is failed to convert String to string.");
-               SysLog(NID_SYS, "Requested font type is %s.", pFontType);
-               res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType);
-               delete [] pFontType;
+               unique_ptr<char[]> pFontType(_StringConverter::CopyToCharArrayN(value));
+               SysTryReturnResult(NID_SYS, pFontType.get() != null, E_SYSTEM, "It is failed to convert String to string.");
+               SysLog(NID_SYS, "Requested font type is %s.", pFontType.get());
+               res = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, pFontType.get());
+               SysTryReturnResult(NID_SYS, res != SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, "It is not valid font type.");
                SysTryReturnResult(NID_SYS, res == SYSTEM_SETTINGS_ERROR_NONE, E_SYSTEM, "It is failed to set font type.");
        }
        return r;