On Sun, Aug 27, 2006 at 03:01:47PM +0200, Georg Baum wrote:
> Am Sonntag, 27. August 2006 03:15 schrieb Enrico Forestieri:
> > On Windows, LyX fails to open a file dropped from a shared drive, i.e.,
> > from an explorer window whose path is something like \\host\path.
> >
> > The attached patch fixes this. It took a while to understand that it
> > was not me messing with paths in the cygwin port of Qt4 ;-)
> >
> > --
> > Enrico
> > dragdrop.diff
> > Index: src/frontends/qt4/GuiWorkArea.C
> > ===================================================================
> > --- src/frontends/qt4/GuiWorkArea.C (revision 14845)
> > +++ src/frontends/qt4/GuiWorkArea.C (working copy)
> > @@ -221,7 +221,7 @@ void GuiWorkArea::dropEvent(QDropEvent*
> >
> > lyxerr[Debug::GUI] << "GuiWorkArea::dropEvent: got URIs!" <<
> endl;
> > for (int i = 0; i!=files.size(); ++i) {
> > - string const file =
> os::internal_path(fromqstr(files.at(i).toString()));
> > + string const file =
> os::internal_path(fromqstr(files.at(i).toLocalFile()));
> > if (!file.empty())
> > dispatch(FuncRequest(LFUN_FILE_OPEN, file));
>
> How does toLocalFile format the string, and how does the result of toString
> look like?
toString() gives file:/host/path/file.lyx
toLocalFile() gives //host/path/file.lyx
> I ask because LyX should be able to deal with \\host\path style paths, e.g.
> passing \\host\path as a command line argument should work as well. If
> that is not the case then we might need to fix it somewhere else.
Yes, I know that. Indeed the problem occurs only with drag and drop
and is due to the way Qt4 deals with UNC paths. So, it is a Qt4 problem,
not a LyX one. Qt4 stores an UNC path url as a file: scheme but without
the initial "//" (this is done in fromLocalFile() and maybe it is done
because // is special in urls) and non-empty host part.
The toString() method does not check for this (or maybe it cannot do it
without breaking something else), whereas toLocalFile() does:
QString QUrl::toLocalFile() const
{
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QString tmp;
if (d->scheme.isEmpty() || d->scheme.toLower() == QLatin1String("file")) {
// magic for shared drive on windows
if (!d->host.isEmpty()) {
tmp = QLatin1String("//") + d->host + (d->path.length() > 0 &&
d->path.at(0) != QLatin1Char('/')
? QLatin1String("/") +
d->path : d->path);
} else {
tmp = d->path;
// magic for drives on windows
if (d->path.length() > 2 && d->path.at(0) == QLatin1Char('/') &&
d->path.at(2) == QLatin1Char(':'))
tmp.remove(0, 1);
}
}
return tmp;
}
So, maybe toString() is buggy, but toLocalFile() DTRT.
--
Enrico