Kaydet (Commit) f1b60bd6 authored tarafından Milian Wolff's avatar Milian Wolff Kaydeden (comit) Thorsten Behrens

Support opening of (some) remote URLs through the KDE file dialog

LO already supports http, https, webdav and webdavs through the
WebDAVContentProvider. Ftp is supported via FTPContentProvider
and then finally we have the GIOContentProvider that can potentially
support SMB, if the dependencies for that are met.

We now configure the KDE file dialog to allow these remote protocols.
Note that this filtering depends on https://phabricator.kde.org/D10024
and https://phabricator.kde.org/D10025 to have any effect.

Then we rewrite the URLs we receive from KIO to a format that is
supported by LO. Most notably, we prepend `vnd.sun.star.` to the
webdav URL schemes, such that they get picked up by the
WebDAVContentProvider. Then finally, we clear the username from
the smb:// URLs we get from KIO, as that prevents GIO from opening
them.

In all cases, the user will get prompted a second time for the
credentials required to access the remote resource. This is
unfortunate, but better than nothing. In the future, we may solve
this issue through either a separate KIO UCP or by getting support
for the FDO Secret Service specification in KWallet.

Change-Id: I91df28434b115639c2698968e2a672b3320bf8e2
Reviewed-on: https://gerrit.libreoffice.org/48350Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst c7a13205
......@@ -32,17 +32,6 @@
#include <QtWidgets/QWidget>
#include <QtWidgets/QApplication>
// The dialog should check whether LO also supports the protocol
// provided by KIO, and KFileWidget::dirOperator() is only 4.3+ .
// Moreover it's only in this somewhat internal KFileWidget class,
// which may not necessarily be what QFileDialog::fileWidget() returns,
// but that's hopefully not a problem in practice.
//#if Qt_VERSION_MAJOR == 4 && Qt_VERSION_MINOR >= 2
//#define ALLOW_REMOTE_URLS 1
//#else
#define ALLOW_REMOTE_URLS 0
//#endif
// KDE5FilePicker
KDE5FilePicker::KDE5FilePicker(QObject* parent)
......@@ -53,16 +42,15 @@ KDE5FilePicker::KDE5FilePicker(QObject* parent)
, _winId(0)
, allowRemoteUrls(false)
{
#if ALLOW_REMOTE_URLS
if (KFileWidget* fileWidget = dynamic_cast<KFileWidget*>(_dialog->fileWidget()))
{
allowRemoteUrls = true;
// Use finishedLoading signal rather than e.g. urlEntered, because if there's a problem
// such as the URL being mistyped, there's no way to prevent two message boxes about it,
// one from us and one from Qt code.
connect(fileWidget->dirOperator(), SIGNAL(finishedLoading()), SLOT(checkProtocol()));
}
#endif
_dialog->setSupportedSchemes({
QStringLiteral("file"),
QStringLiteral("ftp"),
QStringLiteral("http"),
QStringLiteral("https"),
QStringLiteral("webdav"),
QStringLiteral("webdavs"),
QStringLiteral("smb"),
});
setMultiSelectionMode(false);
......@@ -245,21 +233,6 @@ void SAL_CALL KDE5FilePicker::initialize(bool saveDialog)
}
}
void KDE5FilePicker::checkProtocol()
{
// There's no libreoffice.desktop :(, so find a matching one.
/*
KService::List services = KServiceTypeTrader::self()->query( "Application", "Exec =~ 'libreoffice %U'" );
QStringList protocols;
if( !services.isEmpty())
protocols = services[ 0 ]->property( "X-Qt-Protocols" ).toStringList();
if( protocols.isEmpty()) // incorrect (developer?) installation ?
protocols << "file" << "http";
if( !protocols.contains( _dialog->baseUrl().protocol()) && !protocols.contains( "KIO" ))
KMessageBox::error( _dialog, KIO::buildErrorString( KIO::ERR_UNSUPPORTED_PROTOCOL, _dialog->baseUrl().protocol()));
*/
}
void KDE5FilePicker::setWinId(sal_uIntPtr winId) { _winId = winId; }
bool KDE5FilePicker::eventFilter(QObject* o, QEvent* e)
......
......@@ -102,9 +102,6 @@ private:
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
private Q_SLOTS:
void checkProtocol();
Q_SIGNALS:
void filterChanged();
void selectionChanged();
......
......@@ -44,12 +44,12 @@ void sendIpcArg(std::ostream& stream, const QString& string)
sendIpcStringArg(stream, utf8.size(), utf8.data());
}
void sendIpcArg(std::ostream& stream, const QList<QUrl>& urls)
void sendIpcArg(std::ostream& stream, const QStringList& list)
{
stream << static_cast<uint32_t>(urls.size()) << ' ';
for (const auto& url : urls)
stream << static_cast<uint32_t>(list.size()) << ' ';
for (const auto& entry : list)
{
sendIpcArg(stream, url.toString());
sendIpcArg(stream, entry);
}
}
......@@ -126,7 +126,24 @@ void FilePickerIpc::readCommand()
}
case Commands::GetSelectedFiles:
{
sendIpcArgs(std::cout, messageId, m_filePicker->getSelectedFiles());
QStringList files;
for (auto url : m_filePicker->getSelectedFiles())
{
if (url.scheme() == QLatin1String("webdav")
|| url.scheme() == QLatin1String("webdavs"))
{
// translate webdav and webdavs URLs into a format supported by LO
url.setScheme(QLatin1String("vnd.sun.star.") + url.scheme());
}
else if (url.scheme() == QLatin1String("smb"))
{
// clear the user name - the GIO backend does not support this apparently
// when no username is available, it will ask for the password
url.setUserName({});
}
files << url.toString();
}
sendIpcArgs(std::cout, messageId, files);
return;
}
case Commands::AppendFilter:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment