Revert "[Tizen] Fix build errors in adaptor-uv by ecore wayland"
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / accessibility-adaptor-impl-tizen.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 "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 <singleton-service-impl.h>
29 #include <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 bool GetEnabledVConf()
46 {
47   int isEnabled = 0;
48   vconf_get_bool( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, &isEnabled );
49
50   if( isEnabled == 0 )
51   {
52     vconf_get_bool( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &isEnabled );
53   }
54
55   return static_cast<bool>(isEnabled);
56 }
57
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gAccessibilityAdaptorLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_ACCESSIBILITY_ADAPTOR" );
60 #endif
61
62 void AccessibilityOnOffNotification(keynode_t* node, void* data)
63 {
64   AccessibilityAdaptor* adaptor = static_cast<AccessibilityAdaptor*>( data );
65
66   bool isEnabled = GetEnabledVConf();
67
68   DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
69
70   if( isEnabled )
71   {
72     adaptor->EnableAccessibility();
73   }
74   else
75   {
76     adaptor->DisableAccessibility();
77   }
78 }
79
80 } // unnamed namespace
81
82 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
83 {
84   Dali::AccessibilityAdaptor adaptor;
85
86   Dali::SingletonService service( SingletonService::Get() );
87   if ( service )
88   {
89     // Check whether the singleton is already created
90     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
91     if(handle)
92     {
93       // If so, downcast the handle
94       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
95     }
96     else
97     {
98       adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
99       AccessibilityAdaptor& adaptorImpl = AccessibilityAdaptor::GetImplementation( adaptor );
100
101       bool isEnabled = GetEnabledVConf();
102
103       if( isEnabled )
104       {
105         adaptorImpl.EnableAccessibility();
106       }
107       DALI_LOG_INFO( gAccessibilityAdaptorLogFilter, Debug::General, "[%s:%d] %s\n", __FUNCTION__, __LINE__, isEnabled ? "ENABLED" : "DISABLED" );
108
109       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification, &adaptorImpl );
110       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
111
112       service.Register( typeid( adaptor ), adaptor );
113     }
114   }
115
116   return adaptor;
117 }
118
119 void AccessibilityAdaptor::OnDestroy()
120 {
121   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification );
122   vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_DBUS_TTS, AccessibilityOnOffNotification );
123 }
124
125 } // namespace Adaptor
126
127 } // namespace Internal
128
129 } // namespace Dali