[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / common / style-monitor-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // CLASS HEADER
18 #include "style-monitor-impl.h"
19
20 // EXTERNAL INCLUDES
21 #include <vconf.h>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/object/type-registry.h>
25 #include <internal/common/adaptor-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 namespace
37 {
38
39 void DefaultFontSizeChangeNotification(keynode_t* node, void* data)
40 {
41   StyleMonitor* styleMonitor = static_cast<StyleMonitor*>(data);
42
43   StyleChange styleChange;
44   styleChange.defaultFontSizeChange = true;
45   styleMonitor->StyleChanged(styleChange);
46 }
47
48 BaseHandle Create()
49 {
50   BaseHandle handle( StyleMonitor::Get() );
51
52   if ( !handle && Adaptor::IsAvailable() )
53   {
54     Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
55     Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
56     adaptorImpl.RegisterSingleton( typeid( styleMonitor ), styleMonitor );
57     handle = styleMonitor;
58   }
59
60   return handle;
61 }
62 TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
63
64 } // unnamed namespace
65
66 Dali::StyleMonitor StyleMonitor::Get()
67 {
68   Dali::StyleMonitor styleMonitor;
69
70   if ( Adaptor::IsAvailable() )
71   {
72     // Check whether the singleton is already created
73     Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::StyleMonitor ) );
74     if(handle)
75     {
76       // If so, downcast the handle
77       styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
78     }
79   }
80
81   return styleMonitor;
82 }
83
84 StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
85 : mPlatformAbstraction(platformAbstraction)
86 {
87   vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, DefaultFontSizeChangeNotification, this );
88 }
89
90 StyleMonitor::~StyleMonitor()
91 {
92   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, DefaultFontSizeChangeNotification );
93 }
94
95 void StyleMonitor::StyleChanged(StyleChange styleChange)
96 {
97   if (styleChange.defaultFontChange || styleChange.defaultFontSizeChange)
98   {
99     mPlatformAbstraction.UpdateDefaultsFromDevice();
100   }
101
102   EmitStyleChangeSignal(styleChange);
103 }
104
105 std::string StyleMonitor::GetDefaultFontFamily() const
106 {
107   return mPlatformAbstraction.GetDefaultFontFamily();
108 }
109
110 float StyleMonitor::GetDefaultFontSize() const
111 {
112   return mPlatformAbstraction.GetDefaultFontSize();
113 }
114
115 const std::string& StyleMonitor::GetTheme() const
116 {
117   return mUserDefinedThemeFilePath;
118 }
119
120 void StyleMonitor::SetTheme(const std::string& path)
121 {
122   StyleChange styleChange;
123   styleChange.themeChange = true;
124   styleChange.themeFilePath = path;
125   mUserDefinedThemeFilePath = path;
126
127   EmitStyleChangeSignal(styleChange);
128 }
129
130 Dali::StyleMonitor::StyleChangeSignalV2& StyleMonitor::StyleChangeSignal()
131 {
132   return mStyleChangeSignalV2;
133 }
134
135 void StyleMonitor::EmitStyleChangeSignal(StyleChange styleChange)
136 {
137   if( !mStyleChangeSignalV2.Empty() )
138   {
139     Dali::StyleMonitor handle( this );
140     mStyleChangeSignalV2.Emit( handle, styleChange );
141   }
142 }
143
144 } // namespace Adaptor
145
146 } // namespace Internal
147
148 } // namespace Dali