upport wxFileDataObject change for UTF8 handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-09-05 18:53:59 +00:00
parent 88a37bc3d9
commit ead90b5f73

View File

@@ -248,54 +248,56 @@ size_t wxFileDataObject::GetDataSize() const
bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf) bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
{ {
// we get data in the text/uri-list format, i.e. as a sequence of URIs
// (filenames prefixed by "file:") delimited by "\r\n". size includes
// the trailing zero (in theory, not for Nautilus in early GNOME
// versions).
m_filenames.Empty(); m_filenames.Empty();
// we get data in the text/uri-list format, i.e. as a sequence of URIs const gchar *nexttemp = (const gchar*) buf;
// (filenames prefixed by "file:") delimited by "\r\n" for ( ; ; )
wxString filename;
for ( const char *p = (const char *)buf; ; p++ )
{ {
// some broken programs (testdnd GTK+ sample!) omit the trailing int len = 0;
// "\r\n", so check for '\0' explicitly here instead of doing it in const gchar *temp = nexttemp;
// the loop statement to account for it for (;;)
if ( (*p == '\r' && *(p+1) == '\n') || !*p )
{ {
size_t lenPrefix = 5; // strlen("file:") if (temp[len] == 0)
if ( filename.Left(lenPrefix).MakeLower() == _T("file:") )
{ {
// sometimes the syntax is "file:filename", sometimes it's if (len > 0)
// URL-like: "file://filename" - deal with both
if ( filename[lenPrefix] == _T('/') &&
filename[lenPrefix + 1] == _T('/') )
{ {
// skip the slashes // if an app omits '\r''\n'
lenPrefix += 2; nexttemp = temp+len;
break;
} }
// It would probably be nicer to use a GTK or Glib return true;
// function to unescape the 8-bit strings pointed to
// by buf, but this does the same in wx code.
wxString filename_unicode = wxURI::Unescape(filename.c_str() + lenPrefix);
wxCharBuffer filename_8bit = filename_unicode.mb_str(wxConvISO8859_1);
AddFile(wxString(filename_8bit, *wxConvFileName));
filename.Empty();
} }
else if ( !filename.empty() ) if (temp[len] == '\r')
{ {
wxLogDebug(_T("Unsupported URI \"%s\" in wxFileDataObject"), if (temp[len+1] == '\n')
filename.c_str()); nexttemp = temp+len+2;
} else
nexttemp = temp+len+1;
if ( !*p )
break; break;
}
// skip '\r' len++;
p++;
} }
else
if (len == 0)
break;
// required to give it a trailing zero
gchar *uri = g_strndup( temp, len );
gchar *fn = g_filename_from_uri( uri, NULL, NULL );
g_free( uri );
if (fn)
{ {
// The string is in ISO-8859-1 according to XDND spec AddFile( wxConvFileName->cMB2WX( fn ) );
filename += *p; g_free( fn );
} }
} }