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