FreeRDP
Loading...
Searching...
No Matches
SdlPref Class Reference

#include <sdl_prefs.hpp>

Public Member Functions

std::string get_pref_file (bool systemConfigOnly=false) const
 
std::string get_string (const std::string &key, const std::string &fallback="", bool systemConfigOnly=false) const
 
int64_t get_int (const std::string &key, int64_t fallback=0, bool systemConfigOnly=false) const
 
bool get_bool (const std::string &key, bool fallback=false, bool systemConfigOnly=false) const
 
std::vector< std::string > get_array (const std::string &key, const std::vector< std::string > &fallback={}, bool systemConfigOnly=false) const
 
bool is_commandline_override_allowed () const
 

Static Public Member Functions

static std::shared_ptr< SdlPref > instance (const std::string &name=SdlPref::get_default_file(false))
 
static void print_config_file_help (int version)
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Prefs

Copyright 2022 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 27 of file sdl_prefs.hpp.

Member Function Documentation

◆ get_array()

std::vector< std::string > SdlPref::get_array ( const std::string &  key,
const std::vector< std::string > &  fallback = {},
bool  systemConfigOnly = false 
) const

Definition at line 121 of file sdl_prefs.cpp.

124{
125 auto item = get_item(key, systemConfigOnly);
126 if (!item || !WINPR_JSON_IsArray(item))
127 return fallback;
128
129 std::vector<std::string> values;
130 for (size_t x = 0; x < WINPR_JSON_GetArraySize(item); x++)
131 {
132 auto cur = WINPR_JSON_GetArrayItem(item, x);
133 values.push_back(item_to_str(cur));
134 }
135
136 return values;
137}
WINPR_ATTR_NODISCARD WINPR_API size_t WINPR_JSON_GetArraySize(const WINPR_JSON *array)
Get the number of arrayitems from an array.
Definition c-json.c:114
WINPR_ATTR_NODISCARD WINPR_API WINPR_JSON * WINPR_JSON_GetArrayItem(const WINPR_JSON *array, size_t index)
Return a pointer to an item in the array.
Definition c-json.c:108
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsArray(const WINPR_JSON *item)
Check if JSON item is of type Array.
Definition c-json.c:187

◆ get_bool()

bool SdlPref::get_bool ( const std::string &  key,
bool  fallback = false,
bool  systemConfigOnly = false 
) const

Definition at line 104 of file sdl_prefs.cpp.

105{
106 auto item = get_item(key, systemConfigOnly);
107 if (!item || !WINPR_JSON_IsBool(item))
108 return fallback;
109 return WINPR_JSON_IsTrue(item);
110}
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsBool(const WINPR_JSON *item)
Check if JSON item is of type BOOL.
Definition c-json.c:167
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsTrue(const WINPR_JSON *item)
Check if JSON item is BOOL value True.
Definition c-json.c:162

◆ get_int()

int64_t SdlPref::get_int ( const std::string &  key,
int64_t  fallback = 0,
bool  systemConfigOnly = false 
) const

Definition at line 112 of file sdl_prefs.cpp.

113{
114 auto item = get_item(key, systemConfigOnly);
115 if (!item || !WINPR_JSON_IsNumber(item))
116 return fallback;
117 auto val = WINPR_JSON_GetNumberValue(item);
118 return static_cast<int64_t>(val);
119}
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsNumber(const WINPR_JSON *item)
Check if JSON item is of type Number.
Definition c-json.c:177
WINPR_ATTR_NODISCARD WINPR_API double WINPR_JSON_GetNumberValue(const WINPR_JSON *item)
Return the Number value of a JSON item.
Definition c-json.c:147

◆ get_pref_file()

std::string SdlPref::get_pref_file ( bool  systemConfigOnly = false) const

Definition at line 253 of file sdl_prefs.cpp.

254{
255 if (systemConfigOnly)
256 return _system_name;
257
258 return _name;
259}

◆ get_string()

std::string SdlPref::get_string ( const std::string &  key,
const std::string &  fallback = "",
bool  systemConfigOnly = false 
) const

Definition at line 97 of file sdl_prefs.cpp.

99{
100 auto item = get_item(key, systemConfigOnly);
101 return item_to_str(item, fallback);
102}

◆ instance()

std::shared_ptr< SdlPref > SdlPref::instance ( const std::string &  name = SdlPref::get_default_file(false))
static

Definition at line 245 of file sdl_prefs.cpp.

246{
247 static std::shared_ptr<SdlPref> _instance;
248 if (!_instance || (_instance->get_pref_file() != name))
249 _instance.reset(new SdlPref(name));
250 return _instance;
251}

◆ is_commandline_override_allowed()

bool SdlPref::is_commandline_override_allowed ( ) const

Definition at line 79 of file sdl_prefs.cpp.

80{
81 auto& config = _system_config;
82 if (!config)
83 return true;
84 return get_bool(config, "allowCommandlineToOverride", true);
85}

◆ print_config_file_help()

void SdlPref::print_config_file_help ( int  version)
static

Definition at line 139 of file sdl_prefs.cpp.

140{
141#if defined(WITH_WINPR_JSON)
142 const std::string url = "https://wiki.libsdl.org/SDL" + std::to_string(version);
143 std::cout << "GLOBAL CONFIGURATION FILE" << std::endl;
144 std::cout << std::endl;
145 std::cout << " The SDL client supports some system defined configuration options."
146 << std::endl;
147 std::cout << " Settings are stored in JSON format" << std::endl;
148 std::cout << " The location is a system configuration file. Location for current machine is "
149 << SdlPref::instance()->get_pref_file(true) << std::endl;
150 std::cout << std::endl;
151 std::cout << " The following configuration options are supported:" << std::endl;
152 std::cout << std::endl;
153 std::cout << " isUserConfigEnabled" << std::endl;
154 std::cout << " Allows to enable/disable user specific configuration files." << std::endl;
155 std::cout << " Default enabled" << std::endl;
156 std::cout << std::endl;
157 std::cout << " allowCommandlineToOverride" << std::endl;
158 std::cout
159 << " Allows command line options to override values from the configuration files."
160 << std::endl;
161 std::cout << " Default enabled" << std::endl;
162 std::cout << std::endl;
163 std::cout << " All options of the following user configuration file are also supported here."
164 << std::endl;
165 std::cout << std::endl;
166
167 std::cout << "CONFIGURATION FILE" << std::endl;
168 std::cout << std::endl;
169 std::cout << " The SDL client supports some user defined configuration options." << std::endl;
170 std::cout << " Settings are stored in JSON format" << std::endl;
171 std::cout << " The location is a per user file. Location for current user is "
172 << SdlPref::instance()->get_pref_file() << std::endl;
173 std::cout
174 << " The XDG_CONFIG_HOME environment variable can be used to override the base directory."
175 << std::endl;
176 std::cout << std::endl;
177 std::cout << " The following configuration options are supported:" << std::endl;
178 std::cout << std::endl;
179 std::cout << " SDL_KeyModMask" << std::endl;
180 std::cout << " Defines the key combination required for SDL client shortcuts."
181 << std::endl;
182 std::cout << " Default KMOD_RSHIFT" << std::endl;
183 std::cout << " An array of SDL_Keymod strings as defined at "
184 ""
185 << url << "/SDL_Keymod" << std::endl;
186 std::cout << std::endl;
187 std::cout << " SDL_Fullscreen" << std::endl;
188 std::cout << " Toggles client fullscreen state." << std::endl;
189 std::cout << " Default SDL_SCANCODE_RETURN." << std::endl;
190 std::cout << " A string as "
191 "defined at "
192 << url << "/SDLScancodeLookup" << std::endl;
193 std::cout << std::endl;
194 std::cout << " SDL_Minimize" << std::endl;
195 std::cout << " Minimizes client windows." << std::endl;
196 std::cout << " Default SDL_SCANCODE_M." << std::endl;
197 std::cout << " A string as "
198 "defined at "
199 << url << "/SDLScancodeLookup" << std::endl;
200 std::cout << std::endl;
201 std::cout << " SDL_Resizeable" << std::endl;
202 std::cout << " Toggles local window resizeable state." << std::endl;
203 std::cout << " Default SDL_SCANCODE_R." << std::endl;
204 std::cout << " A string as "
205 "defined at "
206 << url << "/SDLScancodeLookup" << std::endl;
207 std::cout << std::endl;
208 std::cout << " SDL_Grab" << std::endl;
209 std::cout << " Toggles keyboard and mouse grab state." << std::endl;
210 std::cout << " Default SDL_SCANCODE_G." << std::endl;
211 std::cout << " A string as "
212 "defined at "
213 << url << "/SDLScancodeLookup" << std::endl;
214 std::cout << std::endl;
215 std::cout << " SDL_Disconnect" << std::endl;
216 std::cout << " Disconnects from the RDP session." << std::endl;
217 std::cout << " Default SDL_SCANCODE_D." << std::endl;
218 std::cout << " A string as defined at " << url << "/SDLScancodeLookup" << std::endl;
219 if (version >= 3)
220 {
221 std::cout << std::endl;
222 std::cout << " SDL_ConnectionDialog" << std::endl;
223 std::cout << " Shows the connection dialog with progress and errors." << std::endl;
224 std::cout << " Default true. +/-sdl-connection-dialog overrides it unless "
225 "allowCommandlineToOverride is disabled."
226 << std::endl;
227 }
228
229#endif
230}

The documentation for this class was generated from the following files: