mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 08:24:16 +09:00
[client,sdl] show file selection dialog
When started without arguments show a file selection dialog when starting SDL freerdp
This commit is contained in:
@@ -1698,6 +1698,82 @@ static void SDLCALL winpr_LogOutputFunction(void* userdata, int category, SDL_Lo
|
||||
category2str(category), message);
|
||||
}
|
||||
|
||||
static void sdl_quit()
|
||||
{
|
||||
SDL_Event ev = {};
|
||||
ev.type = SDL_EVENT_QUIT;
|
||||
if (!SDL_PushEvent(&ev))
|
||||
{
|
||||
SDL_Log("An error occurred: %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL rdp_file_cb(void* userdata, const char* const* filelist,
|
||||
WINPR_ATTR_UNUSED int filter)
|
||||
{
|
||||
auto rdp = static_cast<std::string*>(userdata);
|
||||
|
||||
if (!filelist)
|
||||
{
|
||||
SDL_Log("An error occurred: %s", SDL_GetError());
|
||||
sdl_quit();
|
||||
return;
|
||||
}
|
||||
else if (!*filelist)
|
||||
{
|
||||
SDL_Log("The user did not select any file.");
|
||||
SDL_Log("Most likely, the dialog was canceled.");
|
||||
sdl_quit();
|
||||
return;
|
||||
}
|
||||
|
||||
while (*filelist)
|
||||
{
|
||||
SDL_Log("Full path to selected file: '%s'", *filelist);
|
||||
*rdp = *filelist;
|
||||
filelist++;
|
||||
}
|
||||
|
||||
sdl_quit();
|
||||
}
|
||||
|
||||
static std::string getRdpFile()
|
||||
{
|
||||
const auto flags = SDL_INIT_VIDEO | SDL_INIT_EVENTS;
|
||||
SDL_DialogFileFilter filters[] = { { "RDP files", "rdp;rdpw" } };
|
||||
std::string rdp;
|
||||
|
||||
bool running = true;
|
||||
if (!SDL_Init(flags))
|
||||
return {};
|
||||
|
||||
auto props = SDL_CreateProperties();
|
||||
SDL_SetStringProperty(props, SDL_PROP_FILE_DIALOG_TITLE_STRING,
|
||||
"SDL Freerdp - Open a RDP file");
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_FILE_DIALOG_MANY_BOOLEAN, false);
|
||||
SDL_SetPointerProperty(props, SDL_PROP_FILE_DIALOG_FILTERS_POINTER, filters);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER, ARRAYSIZE(filters));
|
||||
SDL_ShowFileDialogWithProperties(SDL_FILEDIALOG_OPENFILE, rdp_file_cb, &rdp, props);
|
||||
SDL_DestroyProperties(props);
|
||||
|
||||
do
|
||||
{
|
||||
SDL_Event event = {};
|
||||
(void)SDL_PollEvent(&event);
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (running);
|
||||
SDL_Quit();
|
||||
return rdp;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int rc = -1;
|
||||
@@ -1716,7 +1792,23 @@ int main(int argc, char* argv[])
|
||||
auto settings = sdl->context()->settings;
|
||||
WINPR_ASSERT(settings);
|
||||
|
||||
status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
|
||||
std::string rdp_file;
|
||||
std::vector<char*> args;
|
||||
args.reserve(WINPR_ASSERTING_INT_CAST(size_t, argc));
|
||||
for (auto x = 0; x < argc; x++)
|
||||
args.push_back(argv[x]);
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
rdp_file = getRdpFile();
|
||||
if (!rdp_file.empty())
|
||||
{
|
||||
args.push_back(rdp_file.data());
|
||||
}
|
||||
}
|
||||
|
||||
status = freerdp_client_settings_parse_command_line(
|
||||
settings, WINPR_ASSERTING_INT_CAST(int, args.size()), args.data(), FALSE);
|
||||
sdl_rdp->sdl->setMetadata();
|
||||
if (status)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user