kio: drop support for "most local URL"

was used by some slaves (e.g. the archive slave which is no more).

lets see if you can find it jira:
https://ivailo-monev.atlassian.net/browse/KDE-12

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-24 20:46:17 +03:00
parent aa66a2e00b
commit 75cf57aac5
15 changed files with 96 additions and 317 deletions

View file

@ -189,13 +189,6 @@ public:
QString locationEditCurrentText() const;
/**
* KIO::NetAccess::mostLocalUrl local replacement.
* This method won't show any progress dialogs for stating, since
* they are very annoying when stating.
*/
KUrl mostLocalUrl(const KUrl &url);
KFileWidget* q;
// the last selected url
@ -906,7 +899,7 @@ void KFileWidget::slotOk()
bool res = KIO::NetAccess::synchronousRun(statJob, this);
// if we are on local mode, make sure we haven't got a remote base url
if ((mode & KFile::LocalOnly) && !d->mostLocalUrl(d->url).isLocalFile()) {
if ((mode & KFile::LocalOnly) && !d->url.isLocalFile()) {
if (directoryMode) {
KMessageBox::sorry(
this,
@ -1638,10 +1631,9 @@ KUrl::List KFileWidgetPrivate::tokenize( const QString& line ) const
QString KFileWidget::selectedFile() const
{
if ( d->inAccept ) {
const KUrl url = d->mostLocalUrl(d->url);
if (url.isLocalFile())
return url.toLocalFile();
else {
if (d->url.isLocalFile()) {
return d->url.toLocalFile();
} else {
KMessageBox::sorry( const_cast<KFileWidget*>(this),
i18n("You can only select local files."),
i18n("Remote Files Not Accepted") );
@ -1656,19 +1648,16 @@ QStringList KFileWidget::selectedFiles() const
if (d->inAccept) {
if (d->ops->mode() & KFile::Files) {
const KUrl::List urls = d->parseSelectedUrls();
QList<KUrl>::const_iterator it = urls.begin();
while (it != urls.end()) {
KUrl url = d->mostLocalUrl(*it);
if (url.isLocalFile())
foreach (const KUrl &url, d->parseSelectedUrls()) {
if (url.isLocalFile()) {
list.append(url.toLocalFile());
++it;
}
}
}
else { // single-selection mode
if ( d->url.isLocalFile() )
} else {
// single-selection mode
if ( d->url.isLocalFile() ) {
list.append( d->url.toLocalFile() );
}
}
}
@ -2662,27 +2651,4 @@ QString KFileWidgetPrivate::locationEditCurrentText() const
return locationEdit->currentText();
}
KUrl KFileWidgetPrivate::mostLocalUrl(const KUrl &url)
{
if (url.isLocalFile()) {
return url;
}
KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo);
bool res = KIO::NetAccess::synchronousRun(statJob, q);
if (!res) {
return url;
}
const QString path = statJob->statResult().stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
if (!path.isEmpty()) {
KUrl newUrl;
newUrl.setPath(path);
return newUrl;
}
return url;
}
#include "moc_kfilewidget.cpp"

View file

@ -1104,10 +1104,9 @@ void KNewFileMenu::slotResult(KJob * job)
KIO::CopyJob* copyJob = ::qobject_cast<KIO::CopyJob*>(job);
if (copyJob) {
const KUrl destUrl = copyJob->destUrl();
const KUrl localUrl = KIO::NetAccess::mostLocalUrl(destUrl, d->m_parentWidget);
if (localUrl.isLocalFile()) {
if (destUrl.isLocalFile()) {
// Normal (local) file. Need to "touch" it, kio_file copied the mtime.
(void) ::utime(QFile::encodeName(localUrl.toLocalFile()), 0);
(void) ::utime(QFile::encodeName(destUrl.toLocalFile()), 0);
}
emit fileCreated(destUrl);
} else if (KIO::SimpleJob* simpleJob = ::qobject_cast<KIO::SimpleJob*>(job)) {

View file

@ -678,10 +678,10 @@ KFilePropsPlugin::KFilePropsPlugin(KPropertiesDialog *props)
// We set this data from the first item, and we'll
// check that the other items match against it, resetting when not.
bool isLocal = false;
const KFileItem item = properties->item();
KUrl url = item.mostLocalUrl(isLocal);
bool isReallyLocal = item.url().isLocalFile();
KUrl url = item.url();
bool isReallyLocal = url.isLocalFile();
bool isLocal = isReallyLocal;
bool bDesktopFile = item.isDesktopFile();
mode_t mode = item.mode();
bool hasDirs = item.isDir() && !item.isLink();
@ -1206,10 +1206,8 @@ void KFilePropsPlugin::slotSizeDetermine()
// also update the "Free disk space" display
if (d->m_capacityBar) {
bool isLocal = false;
const KFileItem item = properties->item();
KUrl url = item.mostLocalUrl(isLocal);
if (isLocal) {
const KUrl url = properties->item().url();
if (url.isLocalFile()) {
KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(url.toLocalFile());
if (mp) {
KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(mp->mountPoint());
@ -1405,8 +1403,7 @@ void KFilePropsPlugin::applyIconChanges()
}
// handle icon changes - only local files (or pseudo-local) for now
// TODO: Use KTempFile and KIO::file_copy with overwrite = true
KUrl url = properties->kurl();
url = KIO::NetAccess::mostLocalUrl(url, properties);
const KUrl url = properties->kurl();
if (url.isLocalFile()) {
QString path;
@ -2610,7 +2607,7 @@ KUrlPropsPlugin::KUrlPropsPlugin(KPropertiesDialog *props)
d->URLEdit = new KUrlRequester(d->m_frame);
layout->addWidget(d->URLEdit);
KUrl url = KIO::NetAccess::mostLocalUrl(properties->kurl(), properties);
const KUrl url = properties->kurl();
if (url.isLocalFile()) {
QString path = url.toLocalFile();
@ -2652,15 +2649,15 @@ bool KUrlPropsPlugin::supports(const KFileItemList &items)
return false;
}
const KFileItem item = items.first();
// check if desktop file
if (!item.isDesktopFile()) {
// open file and check type
const KUrl url = item.url();
if (!url.isLocalFile()) {
return false;
}
// open file and check type
bool isLocal = false;
KUrl url = item.mostLocalUrl(isLocal);
if (!isLocal) {
// check if desktop file
if (!item.isDesktopFile()) {
return false;
}
@ -2670,7 +2667,7 @@ bool KUrlPropsPlugin::supports(const KFileItemList &items)
void KUrlPropsPlugin::applyChanges()
{
KUrl url = KIO::NetAccess::mostLocalUrl(properties->kurl(), properties);
const KUrl url = properties->kurl();
if (!url.isLocalFile()) {
// FIXME: 4.2 add this: KMessageBox::sorry(0, i18n("Could not save properties. Only entries on local file systems are supported."));
return;
@ -2806,7 +2803,7 @@ KDevicePropsPlugin::KDevicePropsPlugin(KPropertiesDialog *props)
layout->setRowStretch(6, 1);
KUrl url = KIO::NetAccess::mostLocalUrl(props->kurl(), props);
const KUrl url = props->kurl();
if (!url.isLocalFile()) {
return;
}
@ -2925,15 +2922,15 @@ bool KDevicePropsPlugin::supports(const KFileItemList &items)
return false;
}
const KFileItem item = items.first();
// check if desktop file
if (!item.isDesktopFile()) {
// open file and check type
const KUrl url = item.url();
if (!url.isLocalFile()) {
return false;
}
// open file and check type
bool isLocal = false;
KUrl url = item.mostLocalUrl(isLocal);
if (!isLocal) {
// check if desktop file
if (!item.isDesktopFile()) {
return false;
}
@ -2943,7 +2940,7 @@ bool KDevicePropsPlugin::supports(const KFileItemList &items)
void KDevicePropsPlugin::applyChanges()
{
KUrl url = KIO::NetAccess::mostLocalUrl(properties->kurl(), properties);
const KUrl url = properties->kurl();
if (!url.isLocalFile()) {
return;
}
@ -3040,7 +3037,7 @@ KDesktopPropsPlugin::KDesktopPropsPlugin(KPropertiesDialog *props)
connect(d->w->advancedButton, SIGNAL(clicked()), this, SLOT(slotAdvanced()));
// now populate the page
KUrl url = KIO::NetAccess::mostLocalUrl(props->kurl(), props);
const KUrl url = props->kurl();
if (!url.isLocalFile()) {
return;
}
@ -3174,7 +3171,7 @@ void KDesktopPropsPlugin::applyChanges()
{
kDebug() << "KDesktopPropsPlugin::applyChanges";
KUrl url = KIO::NetAccess::mostLocalUrl( properties->kurl(), properties );
const KUrl url = properties->kurl();
if (!url.isLocalFile()) {
//FIXME: 4.2 add this: KMessageBox::sorry(0, i18n("Could not save properties. Only entries on local file systems are supported."));
return;
@ -3351,15 +3348,14 @@ bool KDesktopPropsPlugin::supports(const KFileItemList &items)
const KFileItem item = items.first();
// check if desktop file
if (!item.isDesktopFile()) {
// open file and check type
const KUrl url = item.url();
if (!url.isLocalFile()) {
return false;
}
// open file and check type
bool isLocal = false;
KUrl url = item.mostLocalUrl(isLocal);
if (!isLocal) {
// check if desktop file
if (!item.isDesktopFile()) {
return false;
}

View file

@ -369,15 +369,7 @@ void CopyJobPrivate::slotResultStating( KJob *job )
} else {
// Treat symlinks to dirs as dirs here, so no test on isLink
destinationState = isDir ? DEST_IS_DIR : DEST_IS_FILE;
//kDebug(7007) << "dest is dir:" << isDir;
const QString sLocalPath = entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
if ( !sLocalPath.isEmpty() && kio_resolve_local_urls && destinationState != DEST_DOESNT_EXIST ) {
m_dest = KUrl();
m_dest.setPath(sLocalPath);
if ( isGlobalDest )
m_globalDest = m_dest;
}
// kDebug(7007) << "dest is dir:" << isDir;
}
if ( isGlobalDest )
m_globalDestinationState = destinationState;
@ -395,9 +387,6 @@ void CopyJobPrivate::slotResultStating( KJob *job )
void CopyJobPrivate::sourceStated(const UDSEntry& entry, const KUrl& sourceUrl)
{
const QString sLocalPath = entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
const bool isDir = entry.isDir();
// We were stating the current source URL
// Is it a file or a dir ?
@ -413,29 +402,20 @@ void CopyJobPrivate::sourceStated(const UDSEntry& entry, const KUrl& sourceUrl)
// 5 - src is a file, destination is a file, m_dest is the exact destination name
// 6 - src is a file, destination doesn't exist, m_dest is the exact destination name
KUrl srcurl;
if (!sLocalPath.isEmpty() && destinationState != DEST_DOESNT_EXIST) {
kDebug() << "Using sLocalPath. destinationState=" << destinationState;
// Prefer the local path -- but only if we were able to stat() the dest.
// Otherwise, renaming a desktop:/ url would copy from src=file to dest=desktop (#218719)
srcurl.setPath(sLocalPath);
} else {
srcurl = sourceUrl;
}
addCopyInfoFromUDSEntry(entry, srcurl, false, m_dest);
addCopyInfoFromUDSEntry(entry, sourceUrl, false, m_dest);
m_currentDest = m_dest;
m_bCurrentSrcIsDir = false;
if ( isDir
if ( entry.isDir()
// treat symlinks as files (no recursion)
&& !entry.isLink()
&& m_mode != CopyJob::Link ) // No recursion in Link mode either.
{
//kDebug(7007) << "Source is a directory";
if (srcurl.isLocalFile()) {
const QString parentDir = srcurl.toLocalFile(KUrl::RemoveTrailingSlash);
if (sourceUrl.isLocalFile()) {
const QString parentDir = sourceUrl.toLocalFile(KUrl::RemoveTrailingSlash);
m_parentDirs.insert(parentDir);
}
@ -445,9 +425,9 @@ void CopyJobPrivate::sourceStated(const UDSEntry& entry, const KUrl& sourceUrl)
if ( !m_asMethod )
{
// Use <desturl>/<directory_copied> as destination, from now on
QString directory = srcurl.fileName();
QString directory = sourceUrl.fileName();
const QString sName = entry.stringValue( KIO::UDSEntry::UDS_NAME );
KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(srcurl);
KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(sourceUrl);
if (fnu == KProtocolInfo::Name) {
if (!sName.isEmpty())
directory = sName;
@ -472,14 +452,14 @@ void CopyJobPrivate::sourceStated(const UDSEntry& entry, const KUrl& sourceUrl)
m_globalDestinationState = destinationState;
}
startListing( srcurl );
startListing( sourceUrl );
}
else
{
//kDebug(7007) << "Source is a file (or a symlink), or we are linking -> no recursive listing";
if (srcurl.isLocalFile()) {
const QString parentDir = srcurl.directory(KUrl::LeaveTrailingSlash);
if (sourceUrl.isLocalFile()) {
const QString parentDir = sourceUrl.directory(KUrl::LeaveTrailingSlash);
m_parentDirs.insert(parentDir);
}
@ -598,12 +578,11 @@ void CopyJobPrivate::addCopyInfoFromUDSEntry(const UDSEntry& entry, const KUrl&
KUrl url;
if (!urlStr.isEmpty())
url = urlStr;
QString localPath = entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
const bool isDir = entry.isDir();
info.linkDest = entry.stringValue(KIO::UDSEntry::UDS_LINK_DEST);
if (fileName != QLatin1String("..") && fileName != QLatin1String(".")) {
const bool hasCustomURL = !url.isEmpty() || !localPath.isEmpty();
const bool hasCustomURL = !url.isEmpty();
if (!hasCustomURL) {
// Make URL from displayName
url = srcUrl;
@ -613,9 +592,6 @@ void CopyJobPrivate::addCopyInfoFromUDSEntry(const UDSEntry& entry, const KUrl&
}
}
//kDebug(7007) << "displayName=" << displayName << "url=" << url;
if (!localPath.isEmpty() && kio_resolve_local_urls && destinationState != DEST_DOESNT_EXIST) {
url = KUrl(localPath);
}
info.uSource = url;
info.uDest = currentDest;
@ -627,7 +603,7 @@ void CopyJobPrivate::addCopyInfoFromUDSEntry(const UDSEntry& entry, const KUrl&
(! (m_asMethod && state == STATE_STATING)))
{
QString destFileName;
KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(url);
KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(url);
if (hasCustomURL &&
fnu == KProtocolInfo::FromUrl) {
//destFileName = url.fileName(); // Doesn't work for recursive listing

View file

@ -696,18 +696,6 @@ const UDSEntry& StatJob::statResult() const
return d_func()->m_statResult;
}
KUrl StatJob::mostLocalUrl() const
{
if (!url().isLocalFile()) {
const UDSEntry& udsEntry = d_func()->m_statResult;
const QString path = udsEntry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
if (!path.isEmpty()) {
return KUrl(path);
}
}
return url();
}
void StatJobPrivate::start(SlaveInterface *slave)
{
Q_Q(StatJob);
@ -768,17 +756,6 @@ StatJob* KIO::stat(const KUrl &url, JobFlags flags)
return stat(url, StatJob::SourceSide, 2, flags);
}
StatJob *KIO::mostLocalUrl(const KUrl &url, JobFlags flags)
{
StatJob* job = stat(url, StatJob::SourceSide, 2, flags);
if (url.isLocalFile()) {
QTimer::singleShot(0, job, SLOT(slotFinished()));
Scheduler::self()->cancelJob(job); // deletes the slave if not 0
}
return job;
}
StatJob* KIO::stat(const KUrl &url, KIO::StatJob::StatSide side, short int details, JobFlags flags)
{
//kDebug(7007) << "stat" << url;

View file

@ -273,17 +273,6 @@ namespace KIO {
*/
KIO_EXPORT ListJob *listRecursive( const KUrl& url, JobFlags flags = DefaultFlags,
bool includeHidden = true );
/**
* Tries to map a local URL for the given URL, using a KIO job.
*
* Starts a (stat) job for determining the "most local URL" for a given URL.
* Retrieve the result with StatJob::mostLocalUrl in the result slot.
* @param url The URL we are testing.
* \since 4.4
*/
KIO_EXPORT StatJob* mostLocalUrl(const KUrl& url, JobFlags flags = DefaultFlags);
}
#endif

View file

@ -843,11 +843,12 @@ QMimeData * KDirModel::mimeData( const QModelIndexList & indexes ) const
bool canUseMostLocalUrls = true;
foreach (const QModelIndex &index, indexes) {
const KFileItem& item = d->nodeForIndex(index)->item();
urls << item.url();
bool isLocal;
mostLocalUrls << item.mostLocalUrl(isLocal);
if (!isLocal)
const KUrl& itemurl = item.url();
urls << itemurl;
mostLocalUrls << itemurl;
if (!itemurl.isLocalFile()) {
canUseMostLocalUrls = false;
}
}
QMimeData *data = new QMimeData();
const bool different = canUseMostLocalUrls && (mostLocalUrls != urls);

View file

@ -426,8 +426,7 @@ QString KFileItemPrivate::localPath() const
if (m_bIsLocalUrl) {
return m_url.toLocalFile();
}
// Extract the local path from the KIO::UDSEntry
return m_entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
return QString();
}
QString KFileItem::localPath() const
@ -602,9 +601,7 @@ KMimeType::Ptr KFileItem::determineMimeType() const
}
if (!d->m_pMimeType || !d->m_bMimeTypeKnown) {
bool isLocalUrl = false;
KUrl url = mostLocalUrl(isLocalUrl);
d->m_pMimeType = KMimeType::findByUrl(url, d->m_fileMode, !isLocalUrl);
d->m_pMimeType = KMimeType::findByUrl(d->m_url, d->m_fileMode, !d->m_url.isLocalFile());
Q_ASSERT(d->m_pMimeType);
// kDebug() << d << "finding final mimetype for" << url << ":" << d->m_pMimeType->name();
d->m_bMimeTypeKnown = true;
@ -651,20 +648,18 @@ QString KFileItem::mimeComment() const
}
KMimeType::Ptr mime = determineMimeType();
bool isLocalUrl = false;
KUrl url = mostLocalUrl(isLocalUrl);
// This cannot move to kio_file (with UDS_DISPLAY_TYPE) because it needs
// the mimetype to be determined, which is done here, and possibly delayed...
if (isLocalUrl && !d->isSlow() && mime->is("application/x-desktop")) {
KDesktopFile cfg(url.toLocalFile());
if (d->m_url.isLocalFile() && !d->isSlow() && mime->is("application/x-desktop")) {
KDesktopFile cfg(d->m_url.toLocalFile());
QString comment = cfg.desktopGroup().readEntry("Comment");
if (!comment.isEmpty()) {
return comment;
}
}
QString comment = d->isSlow() ? mime->comment() : mime->comment(url);
// kDebug() << "finding comment for " << url.url() << " : " << d->m_pMimeType->name();
QString comment = d->isSlow() ? mime->comment() : mime->comment(d->m_url);
// kDebug() << "finding comment for " << d->m_url.url() << " : " << d->m_pMimeType->name();
if (!comment.isEmpty()) {
return comment;
}
@ -711,9 +706,6 @@ QString KFileItem::iconName() const
return d->m_iconName;
}
bool isLocalUrl = false;
KUrl url = mostLocalUrl(isLocalUrl);
KMimeType::Ptr mime;
// Use guessed mimetype for the icon
if (!d->m_guessedMimeType.isEmpty()) {
@ -723,8 +715,8 @@ QString KFileItem::iconName() const
}
const bool delaySlowOperations = d->m_delayedMimeTypes;
if (isLocalUrl && !delaySlowOperations && mime->is("application/x-desktop")) {
d->m_iconName = iconFromDesktopFile(url.toLocalFile());
if (d->m_url.isLocalFile() && !delaySlowOperations && mime->is("application/x-desktop")) {
d->m_iconName = iconFromDesktopFile(d->m_url.toLocalFile());
if (!d->m_iconName.isEmpty()) {
d->m_useIconNameCache = d->m_bMimeTypeKnown;
return d->m_iconName;
@ -734,10 +726,10 @@ QString KFileItem::iconName() const
if (delaySlowOperations) {
d->m_iconName = mime->iconName();
} else {
d->m_iconName = mime->iconName(url);
d->m_iconName = mime->iconName(d->m_url);
}
d->m_useIconNameCache = d->m_bMimeTypeKnown;
// kDebug() << "finding icon for" << url << ":" << d->m_iconName;
// kDebug() << "finding icon for" << d->m_url << ":" << d->m_iconName;
return d->m_iconName;
}
@ -753,9 +745,7 @@ static bool checkDesktopFile(const KFileItem &item, bool _determineMimeType)
}
// only local files
bool isLocal = false;
const KUrl url = item.mostLocalUrl(isLocal);
if (!isLocal) {
if (!item.url().isLocalFile()) {
return false;
}
@ -875,10 +865,8 @@ QPixmap KFileItem::pixmap(int _size, int _state) const
mime = KMimeType::findByUrl(sf, 0, !d->m_bIsLocalUrl);
}
KUrl url = mostLocalUrl();
QPixmap p = KIconLoader::global()->loadMimeTypeIcon(mime->iconName(url), KIconLoader::Desktop, _size, _state);
// kDebug() << "finding pixmap for " << url.url() << " : " << mime->name();
QPixmap p = KIconLoader::global()->loadMimeTypeIcon(mime->iconName(d->m_url), KIconLoader::Desktop, _size, _state);
// kDebug() << "finding pixmap for " << d->m_url.url() << " : " << mime->name();
if (p.isNull()) {
kWarning() << "Pixmap not found for mimetype " << d->m_pMimeType->name();
}
@ -1152,29 +1140,6 @@ QString KFileItem::timeString(FileTimes which) const
return KGlobal::locale()->formatDateTime(d->time(which));
}
KUrl KFileItem::mostLocalUrl(bool &local) const
{
if (!d) {
return KUrl();
}
QString local_path = localPath();
if (!local_path.isEmpty()) {
local = true;
KUrl url;
url.setPath(local_path);
return url;
}
local = d->m_bIsLocalUrl;
return d->m_url;
}
KUrl KFileItem::mostLocalUrl() const
{
bool local = false;
return mostLocalUrl(local);
}
QDataStream& operator<<(QDataStream &s, const KFileItem &a)
{
if (a.d) {
@ -1315,17 +1280,15 @@ KMimeType::Ptr KFileItem::mimeTypePtr() const
if (!d->m_pMimeType) {
// On-demand fast (but not always accurate) mimetype determination
Q_ASSERT(!d->m_url.isEmpty());
bool isLocalUrl = false;
KUrl url = mostLocalUrl(isLocalUrl);
d->m_pMimeType = KMimeType::findByUrl(
url, d->m_fileMode,
d->m_url, d->m_fileMode,
// use fast mode if delayed mimetype determination can refine it later
d->m_delayedMimeTypes
);
// If it was not a perfect (glob and content-based) match,
// then determineMimeType will be able to do better for readable URLs.
const bool canDoBetter = d->m_delayedMimeTypes;
//kDebug() << "finding mimetype for" << url << ":" << d->m_pMimeType->name() << "canDoBetter=" << canDoBetter;
//kDebug() << "finding mimetype for" << d->m_url << ":" << d->m_pMimeType->name() << "canDoBetter=" << canDoBetter;
d->m_bMimeTypeKnown = !canDoBetter;
}
return d->m_pMimeType;

View file

@ -473,19 +473,6 @@ public:
*/
operator QVariant() const;
/**
* Tries to give a local URL for this file item if possible.
* The given boolean indicates if the returned url is local or not.
*/
KUrl mostLocalUrl(bool &local) const; // KDE4 TODO: bool* local = 0
/**
* Tries to give a local URL for this file item if possible.
*
* \since 4.6
*/
KUrl mostLocalUrl() const; // KDE5: merge with above version
/**
* Return true if default-constructed
*/

View file

@ -173,27 +173,6 @@ bool NetAccess::stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window)
return ret;
}
KUrl NetAccess::mostLocalUrl(const KUrl &url, QWidget *window)
{
if (url.isLocalFile()) {
return url;
}
KIO::UDSEntry entry;
if (!stat(url, entry, window)) {
return url;
}
const QString path = entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
if (!path.isEmpty()) {
KUrl new_url;
new_url.setPath(path);
return new_url;
}
return url;
}
bool NetAccess::del(const KUrl &url, QWidget *window)
{
NetAccess kioNet;

View file

@ -209,19 +209,6 @@ public:
*/
static bool stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window);
/**
* Tries to map a local URL for the given URL.
*
* This is a convenience function for KIO::stat() + parsing the resulting UDSEntry.
*
* @param url The URL we are testing.
* @param window main window associated with this job. This is used to show message boxes.
*
* @return a local URL corresponding to the same resource than the original URL, or the
* original URL if no local URL can be mapped
*/
static KUrl mostLocalUrl(const KUrl &url, QWidget *window);
/**
* Deletes a file or a directory in a synchronous way.
*

View file

@ -398,7 +398,7 @@ void PreviewJob::slotResult(KJob *job)
bool skipCurrentItem = false;
const KIO::filesize_t size = (KIO::filesize_t)entry.numberValue(KIO::UDSEntry::UDS_SIZE, 0);
const KUrl itemUrl = d->currentItem.item.mostLocalUrl();
const KUrl itemUrl = d->currentItem.item.url();
if (itemUrl.isLocalFile() || KProtocolInfo::protocolIsLocal(itemUrl.protocol())) {
skipCurrentItem = !d->ignoreMaximumSize && size > d->maximumLocalSize
@ -461,7 +461,7 @@ bool PreviewJobPrivate::statResultThumbnail()
return false;
}
KUrl url = currentItem.item.mostLocalUrl();
KUrl url = currentItem.item.url();
// Don't include the password if any
url.setPassword(QString());
origName = url.url();
@ -499,8 +499,7 @@ void PreviewJobPrivate::getOrCreateThumbnail()
tempName = KTemporaryFile::filePath();
KUrl localURL;
localURL.setPath(tempName);
const KUrl currentURL = item.mostLocalUrl();
KIO::Job * job = KIO::file_copy(currentURL, localURL, -1, KIO::Overwrite | KIO::HideProgressInfo /* No GUI */);
KIO::Job * job = KIO::file_copy(item.url(), localURL, -1, KIO::Overwrite | KIO::HideProgressInfo /* No GUI */);
job->addMetaData("thumbnail", "1");
q->addSubjob(job);
}

View file

@ -157,78 +157,75 @@ namespace KIO
/// To customize the appearance of files without changing the url
/// of the items, use UDS_DISPLAY_NAME.
UDS_NAME = 5 | UDS_STRING,
/// A local file path if the ioslave display files sitting
/// on the local filesystem (but in another hierarchy, e.g. settings:/ or remote:/)
UDS_LOCAL_PATH = 6 | UDS_STRING,
/// Access permissions (part of the mode returned by stat)
UDS_ACCESS = 7 | UDS_NUMBER,
UDS_ACCESS = 6 | UDS_NUMBER,
/// The last time the file was modified
UDS_MODIFICATION_TIME = 8 | UDS_NUMBER,
UDS_MODIFICATION_TIME = 7 | UDS_NUMBER,
/// The last time the file was opened
UDS_ACCESS_TIME = 9 | UDS_NUMBER,
UDS_ACCESS_TIME = 8 | UDS_NUMBER,
/// The time the file was created
UDS_CREATION_TIME = 10 | UDS_NUMBER,
UDS_CREATION_TIME = 9 | UDS_NUMBER,
/// File type, part of the mode returned by stat
/// (for a link, this returns the file type of the pointed item)
/// check UDS_LINK_DEST to know if this is a link
UDS_FILE_TYPE = 11 | UDS_NUMBER,
UDS_FILE_TYPE = 10 | UDS_NUMBER,
/// Name of the file where the link points to
/// Allows to check for a symlink (don't use S_ISLNK !)
UDS_LINK_DEST = 12 | UDS_STRING,
UDS_LINK_DEST = 11 | UDS_STRING,
/// An alternative URL (If different from the caption).
/// Can be used to mix different hierarchies.
///
/// Use UDS_DISPLAY_NAME if you simply want to customize the user-visible filenames, or use
/// UDS_TARGET_URL if you want "links" to unrelated urls.
UDS_URL = 13 | UDS_STRING,
UDS_URL = 12 | UDS_STRING,
/// A mime type; the slave should set it if it's known.
UDS_MIME_TYPE = 14 | UDS_STRING,
UDS_MIME_TYPE = 13 | UDS_STRING,
/// A mime type to be used for displaying only.
/// But when 'running' the file, the mimetype is re-determined
/// This is for special cases like symlinks in FTP; you probably don't want to use this one.
UDS_GUESSED_MIME_TYPE = 15 | UDS_STRING,
UDS_GUESSED_MIME_TYPE = 14 | UDS_STRING,
/// Indicates that the entry has extended ACL entries
UDS_EXTENDED_ACL = 16 | UDS_NUMBER,
UDS_EXTENDED_ACL = 15 | UDS_NUMBER,
/// The access control list serialized into a single string.
UDS_ACL_STRING = 17 | UDS_STRING,
UDS_ACL_STRING = 16 | UDS_STRING,
/// The default access control list serialized into a single string.
/// Only available for directories.
UDS_DEFAULT_ACL_STRING = 18 | UDS_STRING,
UDS_DEFAULT_ACL_STRING = 17 | UDS_STRING,
/// If set, contains the label to display instead of
/// the 'real name' in UDS_NAME
/// @since 4.1
UDS_DISPLAY_NAME = 19 | UDS_STRING,
UDS_DISPLAY_NAME = 18 | UDS_STRING,
/// This file is a shortcut or mount, pointing to an
/// URL in a different hierarchy
/// @since 4.1
UDS_TARGET_URL = 20 | UDS_STRING,
UDS_TARGET_URL = 19 | UDS_STRING,
/// User-readable type of file (if not specified,
/// the mimetype's description is used)
/// @since 4.4
UDS_DISPLAY_TYPE = 21 | UDS_STRING,
UDS_DISPLAY_TYPE = 20 | UDS_STRING,
/// A comma-separated list of supplementary icon overlays
/// which will be added to the list of overlays created
/// by KFileItem.
///
/// @since 4.5
UDS_ICON_OVERLAY_NAMES = 22 | UDS_STRING,
UDS_ICON_OVERLAY_NAMES = 21 | UDS_STRING,
/// A comment which will be displayed as is to the user. The string
/// value may contain plain text or Qt-style rich-text extensions.
///
/// @since 4.6
UDS_COMMENT = 23 | UDS_STRING,
UDS_COMMENT = 22 | UDS_STRING,
/// Device number for this file, used to detect hardlinks
/// @since 4.7.3
UDS_DEVICE_ID = 24 | UDS_NUMBER,
UDS_DEVICE_ID = 23 | UDS_NUMBER,
/// Inode number for this file, used to detect hardlinks
/// @since 4.7.3
UDS_INODE = 25 | UDS_NUMBER
UDS_INODE = 24 | UDS_NUMBER
};
private:

View file

@ -421,16 +421,6 @@ bool ReadOnlyPart::openUrl(const KUrl &url)
if (d->m_url.isLocalFile()) {
d->m_file = d->m_url.toLocalFile();
return d->openLocalFile();
} else if (KProtocolInfo::protocolIsLocal(url.protocol())) {
// Maybe we can use a "local path", to avoid a temp copy?
KIO::JobFlags flags = (d->m_showProgressInfo ? KIO::DefaultFlags : KIO::HideProgressInfo);
d->m_statJob = KIO::mostLocalUrl(d->m_url, flags);
d->m_statJob->ui()->setWindow(widget() ? widget()->window() : nullptr);
connect(
d->m_statJob, SIGNAL(result(KJob*)),
this, SLOT(_k_slotStatJobFinished(KJob*))
);
return true;
}
d->openRemoteFile();
return true;
@ -519,32 +509,6 @@ bool ReadOnlyPart::closeUrl()
return true;
}
void ReadOnlyPartPrivate::_k_slotStatJobFinished(KJob * job)
{
Q_ASSERT(job == m_statJob);
m_statJob = nullptr;
// We could emit canceled on error, but we haven't even emitted started yet,
// this could maybe confuse some apps? So for now we'll just fallback to KIO::get
// and error again. Well, maybe this even helps with wrong stat results.
if (job->error() != KJob::NoError) {
KIO::StatJob* statjob = static_cast<KIO::StatJob*>(job);
const KUrl localUrl = statjob->mostLocalUrl();
// set the mimetype only if it was not already set (for example, by the host application)
if (m_arguments.mimeType().isEmpty()) {
const QString mime = statjob->statResult().stringValue(KIO::UDSEntry::UDS_MIME_TYPE);
m_arguments.setMimeType(mime);
m_bAutoDetectedMime = true;
}
if (localUrl.isLocalFile()) {
m_file = localUrl.toLocalFile();
(void)openLocalFile();
return;
}
}
openRemoteFile();
}
void ReadOnlyPartPrivate::_k_slotJobFinished(KJob *job)
{
Q_Q(ReadOnlyPart);

View file

@ -502,7 +502,6 @@ protected:
private:
Q_PRIVATE_SLOT(d_func(), void _k_slotJobFinished( KJob * job ))
Q_PRIVATE_SLOT(d_func(), void _k_slotStatJobFinished(KJob*))
Q_DISABLE_COPY(ReadOnlyPart)
};