2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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.
19 #include "style-monitor-impl.h"
23 #include <dali/public-api/object/type-registry.h>
26 #include <dali/integration-api/debug.h>
29 #include <adaptor-impl.h>
30 #include <singleton-service-impl.h>
44 #if defined(DEBUG_ENABLED)
45 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_STYLE_MONITOR");
49 * Use font client to get the system default font family
50 * @param[in] fontClient handle to font client
51 * @param[out] fontFamily string representing font family
53 void GetSystemDefaultFontFamily( TextAbstraction::FontClient& fontClient, std::string& fontFamily )
55 TextAbstraction::FontDescription defaultFontDescription;
58 fontClient.GetDefaultPlatformFontDescription( defaultFontDescription );
59 fontFamily = defaultFontDescription.family;
63 } // unnamed namespace
65 Dali::StyleMonitor StyleMonitor::Get()
67 Dali::StyleMonitor styleMonitor;
69 Dali::SingletonService service( SingletonService::Get() );
72 // Check whether the singleton is already created
73 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
76 // If so, downcast the handle
77 styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
81 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
82 styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
83 service.Register( typeid( styleMonitor ), styleMonitor );
90 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
91 : mPlatformAbstraction(platformAbstraction),
94 mFontClient = TextAbstraction::FontClient::Get();
95 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
96 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
97 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
100 StyleMonitor::~StyleMonitor()
104 void StyleMonitor::StyleChanged( StyleChange::Type styleChange )
106 switch ( styleChange )
108 case StyleChange::DEFAULT_FONT_CHANGE:
112 mFontClient.ResetSystemDefaults();
113 GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
115 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleChanged::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
119 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
121 mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
125 case StyleChange::THEME_CHANGE:
131 EmitStyleChangeSignal(styleChange);
134 std::string StyleMonitor::GetDefaultFontFamily() const
136 return mDefaultFontFamily;
139 std::string StyleMonitor::GetDefaultFontStyle() const
141 return mDefaultFontStyle;
144 int StyleMonitor::GetDefaultFontSize() const
146 return mDefaultFontSize;
149 const std::string& StyleMonitor::GetTheme() const
151 return mUserDefinedThemeFilePath;
154 void StyleMonitor::SetTheme(const std::string& path)
156 mUserDefinedThemeFilePath = path;
157 EmitStyleChangeSignal( StyleChange::THEME_CHANGE );
160 std::string StyleMonitor::GetAppResourcePath()
162 std::string resourcePath = "";
163 resourcePath = app_get_resource_path();
167 bool StyleMonitor::LoadThemeFile( const std::string& filename, std::string& output )
169 bool retval( false );
170 std::ifstream in( filename.c_str(), std::ios::in );
173 std::stringstream buffer;
174 buffer << in.rdbuf();
176 output = buffer.str();
184 Dali::StyleMonitor::StyleChangeSignalType& StyleMonitor::StyleChangeSignal()
186 return mStyleChangeSignal;
189 void StyleMonitor::EmitStyleChangeSignal( StyleChange::Type styleChange )
191 if( !mStyleChangeSignal.Empty() )
193 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::EmitStyleChangeSignal\n" );
194 Dali::StyleMonitor handle( this );
195 mStyleChangeSignal.Emit( handle, styleChange );
199 } // namespace Adaptor
201 } // namespace Internal