Alvin wrote:
> Thanks for comments. I agree, the actual handling of the URL is severely
> flawed in the example. I was debating on whether I should make it truely
> robust, but by doing so would complicate the example of receiving the DND
> events themselves.
Yes, I agree to keep the example simple.
Up to you where to draw the line on what to support.
On linux it seemed it would be good if at least Firefox and Konqueror
were supported; in the example as it reads, neither operated.
I made some mods to dnd_open() that make it work on linux,
while preserving original behavior (I think). Feel free to use it
or not as you like.
I'm not using iconv() here to do the multibyte conversion, I'm just
using the hack I described earlier.
So basically I replaced dnd_open() with the following:
---- snip
// Assume pairs of bytes: <char> <nul> <char> <nul> .. <nul> <nul>
void multibyte_convert(const char *in, char *out)
{
for ( ; *in; out++, in+=2 )
{ *out = *in; }
}
void dnd_open(const char *urls, size_t length)
{
char *fpath = new char [length+1];
// Check for multibyte chars from Firefox/linux.
// Length will be >1 and second byte will be zero.
//
if ( strlen(urls) != length && length > 1 && urls[1] == 0 )
{ multibyte_convert(urls, fpath); }
else
{ strcpy(fpath, urls); }
// Count number of files, truncate at first CRLF
int cnt = 0;
for ( char *c = fpath; *c; c++ )
{
if ( *c == '\n' ) { *c = 0; cnt++; }
if ( *c == '\r' ) { *c = 0; }
}
if (cnt != 1)
{
fl_alert("Invalid number of files being dropped: %d.\nDrop 1 file
only.", cnt);
delete [] fpath;
return;
}
// Handle file: prefix
if ( strncmp(fpath, "file:", 5) == 0 )
{ strcpy(fpath, fpath+5); }
// NOTE: fpath may contain URL escape codes which we really should decode.
// For this example, they are ignored.
if (fl_choice("Do you really want to open image: %s?", "&No", "&Yes", 0,
fl_filename_name(fpath)) == 1)
file_open(fpath);
delete [] fpath;
}
---- snip
> As for the wide-character strings you found with firefox, I wonder if that's
> a fltk's ASCII limitation? Would the UTF-8 that Ian MacArthur implicitly
> handle that? I haven't come across wide-characters in my work (yet), so I'm
> unfamiliar with them.
I don't know for sure.
It appears to be double bytes, with a double-null at the end.
I'm thinking Firefox is sending multibyte chars, and fltk is just
passing that data straight through, unmodified. I don't think it's
FLTK's job to attempt any conversions on the DND contents, since
IIRC, DND payloads can be 'anything'.. but I'm not 100% sure of this.
> For the file:/ issue, the problem is that each URL in the string is checked
> to see if it starts with "file://". So that can be easily fixed. But a
> better, more robust solution I think, would be to use something like
> libcurl or the library behind wget (I'm not sure if there is one though).
> If I understand the homepage, http://curl.haxx.se/libcurl/, libcurl
> supports a wide range of protocols file:// , http:// https:// ftp:// etc. I
> have (very) briefly looked at some of the examples using libcurl found here
> http://curl.haxx.se/libcurl/c/example.html
> and it looks like libcurl may be useful in this regard?
Yes, that would be how to handle non-local connections, which probably
shouldn't be in the example code (to reduce complexity/dependence on
things a novice might not have), but it's probably a good idea to
mention
this in the paragraphs around the example as a recommendation to the
reader.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk