diff --git a/src/readonlypart.h b/src/readonlypart.h --- a/src/readonlypart.h +++ b/src/readonlypart.h @@ -305,6 +305,11 @@ */ void setUrl(const QUrl &url); + /** + * Convert the given url to local if it is an URL of an ioslave using UDS_LOCAL_PATH + */ + QUrl mostLocalUrl(const QUrl &url) const; + /** * Returns the local file path associated with this part. */ @@ -315,6 +320,11 @@ */ void setLocalFilePath(const QString &localFilePath); + /** + * Returns true if local file path is set for this part. + */ + bool isLocalFile() const; + protected: ReadOnlyPart(ReadOnlyPartPrivate &dd, QObject *parent); diff --git a/src/readonlypart.cpp b/src/readonlypart.cpp --- a/src/readonlypart.cpp +++ b/src/readonlypart.cpp @@ -65,11 +65,24 @@ Q_D(ReadOnlyPart); if (d->m_url != url) { - d->m_url = url; - emit urlChanged(url); + d->m_url = url; + + d->m_file.clear(); + QUrl u = mostLocalUrl(d->m_url); + if (u.isLocalFile()) { + d->m_file = u.toLocalFile(); + } + + emit urlChanged(url); } } +QUrl ReadOnlyPart::mostLocalUrl(const QUrl &url) const { + KIO::StatJob* statJob = KIO::mostLocalUrl(url); + statJob->exec(); + return statJob->mostLocalUrl(); +} + QString ReadOnlyPart::localFilePath() const { Q_D(const ReadOnlyPart); @@ -84,6 +97,13 @@ d->m_file = localFilePath; } +bool ReadOnlyPart::isLocalFile() const +{ + Q_D(const ReadOnlyPart); + + return !(d->m_file.isEmpty()); +} + #if KPARTS_BUILD_DEPRECATED_SINCE(5, 0) bool ReadOnlyPart::isLocalFileTemporary() const { @@ -144,12 +164,10 @@ return false; } d->m_arguments = args; - setUrl(url); - d->m_file.clear(); + setUrl(url); - if (d->m_url.isLocalFile()) { - d->m_file = d->m_url.toLocalFile(); + if (isLocalFile()) { return d->openLocalFile(); } else if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) { // Maybe we can use a "local path", to avoid a temp copy?