dali-adaptor internal folder refactoring
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / tizen-wayland / tizen-tv / accessibility-adaptor-impl-tv.cpp
1 /*
2  * Copyright (c) 2018 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 <dali/internal/accessibility/common/accessibility-adaptor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <vconf.h>
23
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/integration-api/debug.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/system/common/singleton-service-impl.h>
29 #include <dali/internal/system/common/system-settings.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 namespace
41 {
42
43 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS = "db/setting/accessibility/atspi";
44
45 // Disabled Accessibility temporarily in Tizen platform
46 bool GetEnabledVConf()
47 {
48   int isEnabled = 0;
49   //vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
50
51   if( isEnabled == 0 )
52   {
53     //vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
54   }
55
56   return static_cast<bool>(isEnabled);
57 }
58
59 #if defined(DEBUG_ENABLED)
60 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR" );
61 #endif
62
63 void AccessibilityOnOffNotification(keynode_t* node, void* data)
64 {
65   AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
66
67   bool isEnabled = GetEnabledVConf();
68
69   DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
70
71   if( isEnabled )
72   {
73     adaptor->EnableAccessibility();
74   }
75   else
76   {
77     adaptor->DisableAccessibility();
78   }
79 }
80
81 } // unnamed namespace
82
83 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
84 {
85   Dali::AccessibilityAdaptor adaptor;
86
87   Dali::SingletonService service( SingletonService::Get() );
88   if ( service )
89   {
90     // Check whether the singleton is already created
91     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
92     if(handle)
93     {
94       // If so, downcast the handle
95       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
96     }
97     else
98     {
99       adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
100       AccessibilityAdaptor& adaptorImpl = AccessibilityAdaptor::GetImplementation( adaptor );
101
102       bool isEnabled = GetEnabledVConf();
103
104       if( isEnabled )
105       {
106         adaptorImpl.EnableAccessibility();
107       }
108       DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
109
110       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
111       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
112
113       service.Register( typeid( adaptor ), adaptor );
114     }
115   }
116
117   return adaptor;
118 }
119
120 void AccessibilityAdaptor::OnDestroy()
121 {
122   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
123   vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
124 }
125
126 } // namespace Adaptor
127
128 } // namespace Internal
129
130 } // namespace Dali