GFX2_OpenURL()

This commit is contained in:
Thomas Bernard 2020-04-11 23:42:50 +02:00
parent 663ddf39aa
commit 2fdceab6bc
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 45 additions and 32 deletions

View File

@ -361,38 +361,7 @@ static void Window_help_follow_link(const char * line)
buffer[i++] = *link++;
buffer[i] = '\0';
GFX2_Log(GFX2_DEBUG, "WWW link found : \"%s\"\n", buffer);
#if defined(WIN32)
/*HINSTANCE hInst = */ShellExecuteA(NULL, "open", buffer, NULL, NULL, SW_SHOWNORMAL);
#elif defined(__macosx__)
{
OSStatus ret;
CFURLRef url = CFURLCreateWithBytes (
NULL, // allocator
(UInt8*)buffer, // URLBytes
i, // length
kCFStringEncodingASCII, // encoding
NULL // baseURL
);
ret = LSOpenCFURLRef(url,0);
if (ret != noErr)
GFX2_Log(GFX2_ERROR, "LSOpenCFURLRef() returned %d\n", ret);
CFRelease(url);
}
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
{
int ret;
char command[80]; // use the xdg-open command to open the url in the default browser
snprintf(command, sizeof(command), "xdg-open \"%s\"", buffer);
ret = system(command);
if (ret < 0)
GFX2_Log(GFX2_ERROR, "system('%s') FAILED\n", command);
else if (ret == 127)
GFX2_Log(GFX2_ERROR, "system() FAILED to execute shell\n");
}
#else
// TODO : HAIKU, MINT, etc.
GFX2_Log(GFX2_WARNING, "URL open not supported yet on this system.\n");
#endif
GFX2_OpenURL(buffer, i);
}
///

View File

@ -49,6 +49,43 @@ dword GFX2_GetTicks(void)
#endif
}
void GFX2_OpenURL(const char * buffer, unsigned int len)
{
#if defined(WIN32)
(void)len;
/*HINSTANCE hInst = */ShellExecuteA(NULL, "open", buffer, NULL, NULL, SW_SHOWNORMAL);
#elif defined(__macosx__)
OSStatus ret;
CFURLRef url = CFURLCreateWithBytes (
NULL, // allocator
(UInt8*)buffer, // URLBytes
len, // length
kCFStringEncodingASCII, // encoding
NULL // baseURL
);
ret = LSOpenCFURLRef(url,0);
if (ret != noErr)
GFX2_Log(GFX2_ERROR, "LSOpenCFURLRef() returned %d\n", ret);
CFRelease(url);
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
int ret;
char command[256]; // use the xdg-open command to open the url in the default browser
(void)len;
snprintf(command, sizeof(command), "xdg-open \"%s\"", buffer);
ret = system(command);
if (ret < 0)
GFX2_Log(GFX2_ERROR, "system('%s') FAILED\n", command);
else if (ret == 127)
GFX2_Log(GFX2_ERROR, "system() FAILED to execute shell\n");
#else
// TODO : HAIKU, MINT, etc.
(void)len; (void)buffer;
GFX2_Log(GFX2_WARNING, "URL open not supported yet on this system.\n");
#endif
}
#if defined(__macosx__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__SWITCH__)
#if defined(__OpenBSD__)
#include <sys/param.h>

View File

@ -33,6 +33,13 @@
/// Return a number of milliseconds
dword GFX2_GetTicks(void);
/**
* Open an URL in the system default browser
* @param url URL (ascii)
* @param len URL length in bytes
*/
void GFX2_OpenURL(const char * url, unsigned int len);
#if defined (__MINT__)
void Atari_Memory_free(unsigned long *stRam, unsigned long *ttRam);
#else