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; 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; KFileWidget* q;
// the last selected url // the last selected url
@ -906,7 +899,7 @@ void KFileWidget::slotOk()
bool res = KIO::NetAccess::synchronousRun(statJob, this); bool res = KIO::NetAccess::synchronousRun(statJob, this);
// if we are on local mode, make sure we haven't got a remote base url // 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) { if (directoryMode) {
KMessageBox::sorry( KMessageBox::sorry(
this, this,
@ -1638,10 +1631,9 @@ KUrl::List KFileWidgetPrivate::tokenize( const QString& line ) const
QString KFileWidget::selectedFile() const QString KFileWidget::selectedFile() const
{ {
if ( d->inAccept ) { if ( d->inAccept ) {
const KUrl url = d->mostLocalUrl(d->url); if (d->url.isLocalFile()) {
if (url.isLocalFile()) return d->url.toLocalFile();
return url.toLocalFile(); } else {
else {
KMessageBox::sorry( const_cast<KFileWidget*>(this), KMessageBox::sorry( const_cast<KFileWidget*>(this),
i18n("You can only select local files."), i18n("You can only select local files."),
i18n("Remote Files Not Accepted") ); i18n("Remote Files Not Accepted") );
@ -1656,21 +1648,18 @@ QStringList KFileWidget::selectedFiles() const
if (d->inAccept) { if (d->inAccept) {
if (d->ops->mode() & KFile::Files) { if (d->ops->mode() & KFile::Files) {
const KUrl::List urls = d->parseSelectedUrls(); foreach (const KUrl &url, d->parseSelectedUrls()) {
QList<KUrl>::const_iterator it = urls.begin(); if (url.isLocalFile()) {
while (it != urls.end()) {
KUrl url = d->mostLocalUrl(*it);
if (url.isLocalFile())
list.append(url.toLocalFile()); list.append(url.toLocalFile());
++it;
} }
} }
} else {
else { // single-selection mode // single-selection mode
if ( d->url.isLocalFile() ) if ( d->url.isLocalFile() ) {
list.append( d->url.toLocalFile() ); list.append( d->url.toLocalFile() );
} }
} }
}
return list; return list;
} }
@ -2662,27 +2651,4 @@ QString KFileWidgetPrivate::locationEditCurrentText() const
return locationEdit->currentText(); 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" #include "moc_kfilewidget.cpp"

View file

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

View file

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

View file

@ -696,18 +696,6 @@ const UDSEntry& StatJob::statResult() const
return d_func()->m_statResult; 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) void StatJobPrivate::start(SlaveInterface *slave)
{ {
Q_Q(StatJob); Q_Q(StatJob);
@ -768,17 +756,6 @@ StatJob* KIO::stat(const KUrl &url, JobFlags flags)
return stat(url, StatJob::SourceSide, 2, 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) StatJob* KIO::stat(const KUrl &url, KIO::StatJob::StatSide side, short int details, JobFlags flags)
{ {
//kDebug(7007) << "stat" << url; //kDebug(7007) << "stat" << url;

View file

@ -273,17 +273,6 @@ namespace KIO {
*/ */
KIO_EXPORT ListJob *listRecursive( const KUrl& url, JobFlags flags = DefaultFlags, KIO_EXPORT ListJob *listRecursive( const KUrl& url, JobFlags flags = DefaultFlags,
bool includeHidden = true ); 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 #endif

View file

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

View file

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

View file

@ -473,19 +473,6 @@ public:
*/ */
operator QVariant() const; 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 * Return true if default-constructed
*/ */

View file

@ -173,27 +173,6 @@ bool NetAccess::stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window)
return ret; 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) bool NetAccess::del(const KUrl &url, QWidget *window)
{ {
NetAccess kioNet; NetAccess kioNet;

View file

@ -209,19 +209,6 @@ public:
*/ */
static bool stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window); 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. * Deletes a file or a directory in a synchronous way.
* *

View file

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

View file

@ -157,78 +157,75 @@ namespace KIO
/// To customize the appearance of files without changing the url /// To customize the appearance of files without changing the url
/// of the items, use UDS_DISPLAY_NAME. /// of the items, use UDS_DISPLAY_NAME.
UDS_NAME = 5 | UDS_STRING, 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) /// 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 /// 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 /// 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 /// 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 /// File type, part of the mode returned by stat
/// (for a link, this returns the file type of the pointed item) /// (for a link, this returns the file type of the pointed item)
/// check UDS_LINK_DEST to know if this is a link /// 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 /// Name of the file where the link points to
/// Allows to check for a symlink (don't use S_ISLNK !) /// 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). /// An alternative URL (If different from the caption).
/// Can be used to mix different hierarchies. /// Can be used to mix different hierarchies.
/// ///
/// Use UDS_DISPLAY_NAME if you simply want to customize the user-visible filenames, or use /// 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_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. /// 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. /// A mime type to be used for displaying only.
/// But when 'running' the file, the mimetype is re-determined /// 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. /// 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 /// 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. /// 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. /// The default access control list serialized into a single string.
/// Only available for directories. /// 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 /// If set, contains the label to display instead of
/// the 'real name' in UDS_NAME /// the 'real name' in UDS_NAME
/// @since 4.1 /// @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 /// This file is a shortcut or mount, pointing to an
/// URL in a different hierarchy /// URL in a different hierarchy
/// @since 4.1 /// @since 4.1
UDS_TARGET_URL = 20 | UDS_STRING, UDS_TARGET_URL = 19 | UDS_STRING,
/// User-readable type of file (if not specified, /// User-readable type of file (if not specified,
/// the mimetype's description is used) /// the mimetype's description is used)
/// @since 4.4 /// @since 4.4
UDS_DISPLAY_TYPE = 21 | UDS_STRING, UDS_DISPLAY_TYPE = 20 | UDS_STRING,
/// A comma-separated list of supplementary icon overlays /// A comma-separated list of supplementary icon overlays
/// which will be added to the list of overlays created /// which will be added to the list of overlays created
/// by KFileItem. /// by KFileItem.
/// ///
/// @since 4.5 /// @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 /// A comment which will be displayed as is to the user. The string
/// value may contain plain text or Qt-style rich-text extensions. /// value may contain plain text or Qt-style rich-text extensions.
/// ///
/// @since 4.6 /// @since 4.6
UDS_COMMENT = 23 | UDS_STRING, UDS_COMMENT = 22 | UDS_STRING,
/// Device number for this file, used to detect hardlinks /// Device number for this file, used to detect hardlinks
/// @since 4.7.3 /// @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 /// Inode number for this file, used to detect hardlinks
/// @since 4.7.3 /// @since 4.7.3
UDS_INODE = 25 | UDS_NUMBER UDS_INODE = 24 | UDS_NUMBER
}; };
private: private:

View file

@ -421,16 +421,6 @@ bool ReadOnlyPart::openUrl(const KUrl &url)
if (d->m_url.isLocalFile()) { if (d->m_url.isLocalFile()) {
d->m_file = d->m_url.toLocalFile(); d->m_file = d->m_url.toLocalFile();
return d->openLocalFile(); 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(); d->openRemoteFile();
return true; return true;
@ -519,32 +509,6 @@ bool ReadOnlyPart::closeUrl()
return true; 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) void ReadOnlyPartPrivate::_k_slotJobFinished(KJob *job)
{ {
Q_Q(ReadOnlyPart); Q_Q(ReadOnlyPart);

View file

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