Merge "Changes needed for https://review.tizen.org/gerrit/#/c/191202/" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen-wayland / 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 <dali/internal/adaptor/common/adaptor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <app_common.h>
23 #include <system_settings.h>
24
25 #ifdef APPCORE_WATCH_AVAILABLE
26 #include <screen_connector_provider.h>
27 #endif
28
29 #ifdef ECORE_WAYLAND2
30 #include <Ecore_Wl2.h>
31 #else
32 #include <Ecore_Wayland.h>
33 #endif
34
35
36 namespace Dali
37 {
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 namespace
46 {
47
48 static void OnSystemLanguageChanged( system_settings_key_e key, void* data )
49 {
50   char* locale = NULL;
51   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
52       locale == NULL )
53   {
54     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
55     return;
56   }
57
58   Adaptor* adaptor = static_cast< Adaptor* >( data );
59   if( adaptor != NULL )
60   {
61     adaptor->SetRootLayoutDirection( locale );
62   }
63
64   free( locale );
65 }
66
67 } // namesapce
68
69 void Adaptor::GetDataStoragePath( std::string& path)
70 {
71 #ifdef USE_APPFW
72   char *pathInt = app_get_data_path();
73   if ( pathInt )
74   {
75     path = pathInt;
76     free( pathInt );
77   }
78   else
79   {
80     path = "";
81   }
82 #endif
83
84 }
85
86 void Adaptor::GetAppId( std::string& appId )
87 {
88 #ifdef USE_APPFW
89   char *id;
90   app_get_id(&id);
91   if ( id )
92   {
93     appId = id;
94   }
95   else
96   {
97     appId = "";
98   }
99 #endif
100 }
101
102 void Adaptor::SurfaceInitialized()
103 {
104 #ifdef APPCORE_WATCH_AVAILABLE
105   if ( !mUseRemoteSurface )
106   {
107     return;
108   }
109   char *appId;
110   app_get_id(&appId);
111
112   // Use strdup() in app_get_id(), so need to free memory
113   if( appId )
114   {
115     WindowPane defaultWindow = mWindowFrame.front();
116 #ifdef ECORE_WAYLAND2
117     Ecore_Wl2_Window* ecoreWlWindow = AnyCast< Ecore_Wl2_Window* >( defaultWindow.nativeWindow );
118     screen_connector_provider_remote_enable( appId, ecore_wl2_window_surface_get( ecoreWlWindow ) );
119 #else
120     Ecore_Wl_Window* ecoreWlWindow = AnyCast< Ecore_Wl_Window* >( defaultWindow.nativeWindow );
121     screen_connector_provider_remote_enable( appId, ecore_wl_window_surface_get( ecoreWlWindow ) );
122 #endif
123     free( appId );
124   }
125 #endif
126 }
127
128 void Adaptor::SetupSystemInformation()
129 {
130   if( system_settings_set_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
131   {
132     DALI_LOG_ERROR( "DALI system_settings_set_changed_cb failed.\n" );
133     return;
134   }
135
136   char* locale = NULL;
137   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
138       locale == NULL )
139   {
140     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
141     return;
142   }
143
144   SetRootLayoutDirection( locale );
145
146   free( locale );
147
148 }
149
150 } // namespace Adaptor
151
152 } // namespace Internal
153
154 } // namespace Dali