d1761bf9657cd4753a1648d93cc83a2a0886cbdb
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen-wayland / adaptor-impl-tizen.cpp
1 /*
2  * Copyright (c) 2019 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 <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
31 #else
32 #include <dali/internal/adaptor/tizen-wayland/dali-ecore-wayland.h>
33 #endif
34
35
36 #include <aul.h>
37 #include <unistd.h>
38
39 namespace Dali
40 {
41
42 namespace Internal
43 {
44
45 namespace Adaptor
46 {
47
48 namespace
49 {
50
51 static void OnSystemLanguageChanged( system_settings_key_e key, void* data )
52 {
53   char* locale = NULL;
54   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
55       locale == NULL )
56   {
57     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
58     return;
59   }
60
61   Adaptor* adaptor = static_cast< Adaptor* >( data );
62   if( adaptor != NULL )
63   {
64     adaptor->SetRootLayoutDirection( locale );
65   }
66
67   free( locale );
68 }
69
70 } // namesapce
71
72 std::string Adaptor::GetApplicationPackageName()
73 {
74   char appname[4096] = {0};
75   int pid = getpid();
76   aul_app_get_pkgname_bypid( pid, appname, sizeof( appname ) );
77   return appname;
78 }
79
80 void Adaptor::GetDataStoragePath( std::string& path)
81 {
82 #ifdef USE_APPFW
83   char *pathInt = app_get_data_path();
84   if ( pathInt )
85   {
86     path = pathInt;
87     free( pathInt );
88   }
89   else
90   {
91     path = "";
92   }
93 #endif
94
95 }
96
97 void Adaptor::GetAppId( std::string& appId )
98 {
99 #ifdef USE_APPFW
100   char *id;
101   app_get_id(&id);
102   if ( id )
103   {
104     appId = id;
105   }
106   else
107   {
108     appId = "";
109   }
110 #endif
111 }
112
113 void Adaptor::SurfaceInitialized()
114 {
115 #ifdef APPCORE_WATCH_AVAILABLE
116   if ( !mUseRemoteSurface )
117   {
118     return;
119   }
120   char *appId;
121   app_get_id(&appId);
122
123   // Use strdup() in app_get_id(), so need to free memory
124   if( appId )
125   {
126 #ifdef ECORE_WAYLAND2
127     Ecore_Wl2_Window* ecoreWlWindow = AnyCast< Ecore_Wl2_Window* >( mWindows.front()->GetNativeHandle() );
128     screen_connector_provider_remote_enable( appId, ecore_wl2_window_surface_get( ecoreWlWindow ) );
129 #else
130     Ecore_Wl_Window* ecoreWlWindow = AnyCast< Ecore_Wl_Window* >( mWindows.front()->GetNativeHandle() );
131     screen_connector_provider_remote_enable( appId, ecore_wl_window_surface_get( ecoreWlWindow ) );
132 #endif
133     free( appId );
134   }
135 #endif
136 }
137
138 void Adaptor::SetupSystemInformation()
139 {
140   if( system_settings_set_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
141   {
142     DALI_LOG_ERROR( "DALI system_settings_set_changed_cb failed.\n" );
143     return;
144   }
145
146   char* locale = NULL;
147   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
148       locale == NULL )
149   {
150     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
151     return;
152   }
153
154   SetRootLayoutDirection( locale );
155
156   free( locale );
157
158 }
159
160 } // namespace Adaptor
161
162 } // namespace Internal
163
164 } // namespace Dali