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