X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ffeedback%2Ffeedback-style.cpp;h=c96cd171841b65544b926b5ea5de543c1951d051;hp=da2f055f84a6ce8b3f8a0d47a396ae8ff8fcb594;hb=666b4b2f13d2f417557180a8440c6686c5dbfe83;hpb=a073ebfd862b49692c8e6d7dff2b128e62a4f6df diff --git a/dali-toolkit/internal/feedback/feedback-style.cpp b/dali-toolkit/internal/feedback/feedback-style.cpp index da2f055..c96cd17 100644 --- a/dali-toolkit/internal/feedback/feedback-style.cpp +++ b/dali-toolkit/internal/feedback/feedback-style.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,16 @@ #include // EXTERNAL INCLUDES +#include #include -#include #include #include // INTERNAL INCLUDES +#include #include #include -using std::string; - namespace // unnamed namespace { @@ -37,7 +36,7 @@ namespace // unnamed namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::General, false, "LOG_FEEDBACK"); #endif -const char* DEFAULT_FEEDBACK_THEME_PATH = DALI_STYLE_DIR"default-feedback-theme.json"; +const char* DEFAULT_FEEDBACK_THEME_FILE_NAME = "default-feedback-theme.json"; // Sets bool and string if the node has a child "name" void GetIfString(const Dali::Toolkit::TreeNode& node, const std::string& name, bool& exists, std::string& str) @@ -75,11 +74,11 @@ struct SignalFeedbackInfo bool mHasHapticFeedbackInfo; bool mHasSoundFeedbackInfo; - string mSignalName; - string mHapticFeedbackPattern; - string mSoundFeedbackPattern; - string mHapticFeedbackFile; - string mSoundFeedbackFile; + std::string mSignalName; + std::string mHapticFeedbackPattern; + std::string mSoundFeedbackPattern; + std::string mHapticFeedbackFile; + std::string mSoundFeedbackFile; }; typedef std::vector SignalFeedbackInfoContainer; @@ -94,7 +93,7 @@ struct FeedbackStyleInfo { } - string mTypeName; + std::string mTypeName; SignalFeedbackInfoContainer mSignalFeedbackInfoList; }; @@ -102,21 +101,23 @@ struct FeedbackStyleInfo static const FeedbackStyleInfo DEFAULT_FEEDBACK_STYLE_INFO; FeedbackStyle::FeedbackStyle() -: mConnections( this ) { mFeedback = Dali::FeedbackPlayer::Get(); - string defaultTheme; + const std::string styleDirPath = AssetManager::GetDaliStylePath(); + const std::string defaultThemeFilePath = styleDirPath + DEFAULT_FEEDBACK_THEME_FILE_NAME; + + std::string defaultTheme; - if( mFeedback && mFeedback.LoadFile( DEFAULT_FEEDBACK_THEME_PATH, defaultTheme ) ) + if( mFeedback && mFeedback.LoadFile( defaultThemeFilePath, defaultTheme ) ) { LoadTheme( defaultTheme ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ResourceLoader::LoadTheme(%s) - loaded %d bytes\n", - DEFAULT_FEEDBACK_THEME_PATH, defaultTheme.size() ); + defaultThemeFilePath.c_str(), defaultTheme.size() ); } else { - DALI_LOG_ERROR("ResourceLoader::LoadTheme(%s) - failed to load\n", DEFAULT_FEEDBACK_THEME_PATH); + DALI_LOG_ERROR("ResourceLoader::LoadTheme(%s) - failed to load\n", defaultThemeFilePath.c_str()); } } @@ -127,7 +128,7 @@ FeedbackStyle::~FeedbackStyle() struct PlayFeedbackFromSignal { - PlayFeedbackFromSignal( FeedbackStyle& controller, const string& typeName, const string& signalName ) + PlayFeedbackFromSignal( FeedbackStyle& controller, const std::string& typeName, const std::string& signalName ) : mController( controller ), mTypeName( typeName ), mSignalName( signalName ) @@ -140,18 +141,16 @@ struct PlayFeedbackFromSignal } FeedbackStyle& mController; - string mTypeName; - string mSignalName; + std::string mTypeName; + std::string mSignalName; }; void FeedbackStyle::ObjectCreated( BaseHandle handle ) { - std::string typeName = handle.GetTypeName(); - if( handle ) { - string type = handle.GetTypeName(); + const std::string& type = handle.GetTypeName(); const FeedbackStyleInfo styleInfo = GetStyleInfo( type ); @@ -180,9 +179,9 @@ void FeedbackStyle::ObjectCreated( BaseHandle handle ) } } -const FeedbackStyleInfo& FeedbackStyle::GetStyleInfo( const string& type ) const +const FeedbackStyleInfo& FeedbackStyle::GetStyleInfo( const std::string& type ) const { - std::map::const_iterator iter( mStyleInfoLut.find( type ) ); + std::map::const_iterator iter( mStyleInfoLut.find( type ) ); if( iter != mStyleInfoLut.end() ) { return iter->second; @@ -195,9 +194,9 @@ const FeedbackStyleInfo& FeedbackStyle::GetStyleInfo( const string& type ) const void FeedbackStyle::StyleChanged( const std::string& userDefinedThemePath, Dali::StyleChange::Type styleChange ) { - if( StyleChange::THEME_CHANGE ) + if( styleChange == StyleChange::THEME_CHANGE ) { - string userDefinedTheme; + std::string userDefinedTheme; if( mFeedback && mFeedback.LoadFile( userDefinedThemePath, userDefinedTheme ) ) { @@ -205,8 +204,11 @@ void FeedbackStyle::StyleChanged( const std::string& userDefinedThemePath, Dali: { DALI_LOG_ERROR("FeedbackStyle::StyleChanged() User defined theme failed to load! \n"); + const std::string styleDirPath = AssetManager::GetDaliStylePath(); + const std::string defaultThemeFilePath = styleDirPath + DEFAULT_FEEDBACK_THEME_FILE_NAME; + //If there is any problem is using the user defined theme, then fall back to default theme - if( !LoadTheme( DEFAULT_FEEDBACK_THEME_PATH ) ) + if( !LoadTheme( defaultThemeFilePath ) ) { //If the default theme fails, Then No luck! DALI_LOG_ERROR("FeedbackStyle::StyleChanged() Default theme failed to load! \n"); @@ -225,7 +227,7 @@ void FeedbackStyle::StyleChanged( const std::string& userDefinedThemePath, Dali: } } -bool FeedbackStyle::LoadTheme( const string& data ) +bool FeedbackStyle::LoadTheme( const std::string& data ) { bool result = false; @@ -244,7 +246,7 @@ bool FeedbackStyle::LoadTheme( const string& data ) return result; } -void FeedbackStyle::LoadFromString( const string& data ) +void FeedbackStyle::LoadFromString( const std::string& data ) { Toolkit::JsonParser parser = Toolkit::JsonParser::New(); const Toolkit::TreeNode* root = NULL; @@ -307,7 +309,7 @@ void FeedbackStyle::LoadFromString( const string& data ) if( signalFeedbackInfo.mHasHapticFeedbackInfo || signalFeedbackInfo.mHasSoundFeedbackInfo ) { - AddSignalInfo( themeInfo, signalFeedbackInfo ); + AddSignalInfo( themeInfo, std::move( signalFeedbackInfo ) ); } } } @@ -320,10 +322,10 @@ void FeedbackStyle::LoadFromString( const string& data ) } // LoadFromString() -void FeedbackStyle::AddSignalInfo( FeedbackStyleInfo& styleInfo, SignalFeedbackInfo signalInfo ) +void FeedbackStyle::AddSignalInfo( FeedbackStyleInfo& styleInfo, SignalFeedbackInfo&& signalInfo ) { bool updated = false; - std::vector::iterator iter; + SignalFeedbackInfoContainer::iterator iter; // If info exists for the signal then update it, else add new for( iter = styleInfo.mSignalFeedbackInfoList.begin(); iter != styleInfo.mSignalFeedbackInfoList.end(); ++iter ) @@ -344,11 +346,11 @@ void FeedbackStyle::AddSignalInfo( FeedbackStyleInfo& styleInfo, SignalFeedbackI if( !updated ) { - styleInfo.mSignalFeedbackInfoList.push_back( signalInfo ); + styleInfo.mSignalFeedbackInfoList.emplace_back( std::move( signalInfo ) ); } } -void FeedbackStyle::PlayFeedback(const string& type, const string& signalName) +void FeedbackStyle::PlayFeedback(const std::string& type, const std::string& signalName) { const FeedbackStyleInfo styleInfo = GetStyleInfo(type); SignalFeedbackInfoConstIter iter; @@ -394,7 +396,7 @@ void FeedbackStyle::PlayFeedback(const string& type, const string& signalName) } } -FeedbackPattern FeedbackStyle::GetFeedbackPattern( const string &pattern ) +FeedbackPattern FeedbackStyle::GetFeedbackPattern( const std::string &pattern ) { if( 0 == mFeedbackPatternLut.size() ) { @@ -450,7 +452,7 @@ FeedbackPattern FeedbackStyle::GetFeedbackPattern( const string &pattern ) mFeedbackPatternLut["FEEDBACK_PATTERN_SLIDER_SWEEP"] = Dali::FEEDBACK_PATTERN_SLIDER_SWEEP; } - std::map::const_iterator iter( mFeedbackPatternLut.find( pattern ) ); + std::map::const_iterator iter( mFeedbackPatternLut.find( pattern ) ); if( iter != mFeedbackPatternLut.end() ) {