mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
generic: KIO protocols classification optimization
unfortunate as it is the class for getting protocol information is not part of kio library so generic.. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
649e704698
commit
d4fb98cc28
14 changed files with 26 additions and 41 deletions
|
@ -85,11 +85,8 @@ KProtocolInfo::KProtocolInfo(const QString &path)
|
|||
}
|
||||
d->maxSlavesPerHost = config.readEntry("maxInstancesPerHost", 0);
|
||||
d->docPath = config.readPathEntry("X-DocPath", QString());
|
||||
d->protClass = config.readEntry("Class").toLower();
|
||||
if (d->protClass[0] != QLatin1Char(':')) {
|
||||
d->protClass.prepend(QLatin1Char(':'));
|
||||
}
|
||||
d->showPreviews = config.readEntry("ShowPreviews", d->protClass == QLatin1String(":local"));
|
||||
d->local = config.readEntry("local", false);
|
||||
d->showPreviews = config.readEntry("ShowPreviews", d->local);
|
||||
}
|
||||
|
||||
KProtocolInfo::KProtocolInfo(QDataStream &str, int offset)
|
||||
|
@ -123,7 +120,7 @@ void KProtocolInfo::load(QDataStream &str)
|
|||
>> i_supportsMakeDir >> i_supportsDeleting
|
||||
>> i_supportsLinking >> i_supportsMoving
|
||||
>> i_canCopyFromFile >> i_canCopyToFile
|
||||
>> m_config >> m_maxSlaves >> d->docPath >> d->protClass
|
||||
>> m_config >> m_maxSlaves >> d->docPath >> d->local
|
||||
>> i_showPreviews
|
||||
>> i_canRenameFromFile >> i_canRenameToFile
|
||||
>> i_canDeleteRecursive >> i_fileNameUsedForCopying
|
||||
|
@ -186,7 +183,7 @@ void KProtocolInfoPrivate::save(QDataStream &str)
|
|||
<< i_supportsMakeDir << i_supportsDeleting
|
||||
<< i_supportsLinking << i_supportsMoving
|
||||
<< i_canCopyFromFile << i_canCopyToFile
|
||||
<< q->m_config << q->m_maxSlaves << docPath << protClass
|
||||
<< q->m_config << q->m_maxSlaves << docPath << local
|
||||
<< i_showPreviews
|
||||
<< i_canRenameFromFile << i_canRenameToFile
|
||||
<< i_canDeleteRecursive << i_fileNameUsedForCopying
|
||||
|
@ -272,13 +269,13 @@ QString KProtocolInfo::docPath(const QString &protocol)
|
|||
return prot->d_func()->docPath;
|
||||
}
|
||||
|
||||
QString KProtocolInfo::protocolClass(const QString &protocol)
|
||||
bool KProtocolInfo::protocolIsLocal(const QString &protocol)
|
||||
{
|
||||
KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(protocol);
|
||||
if (!prot) {
|
||||
return QString();
|
||||
return false;
|
||||
}
|
||||
return prot->d_func()->protClass;
|
||||
return prot->d_func()->local;
|
||||
}
|
||||
|
||||
bool KProtocolInfo::showFilePreview(const QString &protocol)
|
||||
|
|
|
@ -181,28 +181,21 @@ public:
|
|||
static QString docPath(const QString &protocol);
|
||||
|
||||
/**
|
||||
* Returns the protocol class for the specified protocol.
|
||||
* Returns whether the specified protocol is local.
|
||||
*
|
||||
* This corresponds to the "Class=" field in the protocol description file.
|
||||
*
|
||||
* The following classes are defined:
|
||||
* @li ":internet" for common internet protocols
|
||||
* @li ":local" for protocols that access local resources
|
||||
*
|
||||
* Protocol classes always start with a ':' so that they can not be confused with
|
||||
* the protocols themselves.
|
||||
* This corresponds to the "local=" field in the protocol description file.
|
||||
*
|
||||
* @param protocol the protocol to check
|
||||
* @return the class of the protocol, or an empty string if unknown
|
||||
* @return true if protocol is local, false otherwise
|
||||
*/
|
||||
static QString protocolClass(const QString &protocol);
|
||||
static bool protocolIsLocal(const QString &protocol);
|
||||
|
||||
/**
|
||||
* Returns whether file previews should be shown for the specified protocol.
|
||||
*
|
||||
* This corresponds to the "ShowPreviews=" field in the protocol description file.
|
||||
*
|
||||
* By default previews are shown if protocolClass is :local.
|
||||
* By default previews are shown if protocol is local.
|
||||
*
|
||||
* @param protocol the protocol to check
|
||||
* @return true if previews should be shown by default, false otherwise
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
KProtocolInfo *q;
|
||||
QString docPath;
|
||||
QString protClass;
|
||||
bool local;
|
||||
bool showPreviews;
|
||||
bool canRenameFromFile;
|
||||
bool canRenameToFile;
|
||||
|
|
|
@ -401,7 +401,7 @@ KIO_EXPORT QByteArray KIO::rawErrorDetail(int errorCode, const QString &errorTex
|
|||
path = reqUrl->path();
|
||||
|
||||
// detect if protocol is a network protocol...
|
||||
isSlaveNetwork = KProtocolInfo::protocolClass(protocol) == ":internet";
|
||||
isSlaveNetwork = !KProtocolInfo::protocolIsLocal(protocol);
|
||||
} else {
|
||||
// assume that the errorText has the location we are interested in
|
||||
url = host = domain = path = filename = errorText;
|
||||
|
|
|
@ -686,7 +686,7 @@ static KUrl::List resolveURLs(const KUrl::List& _urls, const KService& _service)
|
|||
const KUrl url = *it;
|
||||
bool supported = isProtocolInSupportedList(url, appSupportedProtocols);
|
||||
kDebug(7010) << "Looking at url=" << url << " supported=" << supported;
|
||||
if (!supported && KProtocolInfo::protocolClass(url.protocol()) == ":local") {
|
||||
if (!supported && KProtocolInfo::protocolIsLocal(url.protocol())) {
|
||||
// Maybe we can resolve to a local URL?
|
||||
KUrl localURL = KIO::NetAccess::mostLocalUrl(url, 0);
|
||||
if (localURL != url) {
|
||||
|
|
|
@ -997,15 +997,10 @@ bool KUrlCompletionPrivate::fileCompletion(const KUrlCompletionPrivate::MyURL& u
|
|||
// URLs not handled elsewhere...
|
||||
//
|
||||
|
||||
static bool isLocalProtocol(const QString& protocol)
|
||||
{
|
||||
return (KProtocolInfo::protocolClass(protocol) == QLatin1String(":local"));
|
||||
}
|
||||
|
||||
bool KUrlCompletionPrivate::urlCompletion(const KUrlCompletionPrivate::MyURL& url, QString* pMatch)
|
||||
{
|
||||
//kDebug() << *url.kurl();
|
||||
if (onlyLocalProto && isLocalProtocol(url.protocol()))
|
||||
if (onlyLocalProto && KProtocolInfo::protocolIsLocal(url.protocol()))
|
||||
return false;
|
||||
|
||||
// Use d->cwd as base url in case url is not absolute
|
||||
|
@ -1021,7 +1016,7 @@ bool KUrlCompletionPrivate::urlCompletion(const KUrlCompletionPrivate::MyURL& ur
|
|||
return false;
|
||||
|
||||
// non local urls
|
||||
if (!isLocalProtocol(url.protocol())) {
|
||||
if (!KProtocolInfo::protocolIsLocal(url.protocol())) {
|
||||
// url does not specify host
|
||||
if (url_dir.host().isEmpty())
|
||||
return false;
|
||||
|
|
|
@ -400,7 +400,7 @@ void PreviewJob::slotResult(KJob *job)
|
|||
const KIO::filesize_t size = (KIO::filesize_t)entry.numberValue(KIO::UDSEntry::UDS_SIZE, 0);
|
||||
const KUrl itemUrl = d->currentItem.item.mostLocalUrl();
|
||||
|
||||
if (itemUrl.isLocalFile() || KProtocolInfo::protocolClass(itemUrl.protocol()) == QLatin1String(":local")) {
|
||||
if (itemUrl.isLocalFile() || KProtocolInfo::protocolIsLocal(itemUrl.protocol())) {
|
||||
skipCurrentItem = !d->ignoreMaximumSize && size > d->maximumLocalSize
|
||||
&& !d->currentItem.plugin->property("IgnoreMaximumSize").toBool();
|
||||
} else {
|
||||
|
|
|
@ -13,4 +13,4 @@ Icon=folder-remote
|
|||
maxInstances=20
|
||||
maxInstancesPerHost=5
|
||||
X-DocPath=kioslave/curl/index.html
|
||||
Class=:internet
|
||||
local=false
|
||||
|
|
|
@ -15,4 +15,4 @@ maxInstancesPerHost=5
|
|||
defaultMimetype=application/octet-stream
|
||||
determineMimetypeFromExtension=false
|
||||
X-DocPath=kioslave/curl/index.html
|
||||
Class=:internet
|
||||
local=false
|
||||
|
|
|
@ -15,4 +15,4 @@ maxInstancesPerHost=5
|
|||
defaultMimetype=application/octet-stream
|
||||
determineMimetypeFromExtension=false
|
||||
X-DocPath=kioslave/curl/index.html
|
||||
Class=:internet
|
||||
local=false
|
||||
|
|
|
@ -13,4 +13,4 @@ Icon=folder-remote
|
|||
maxInstances=20
|
||||
maxInstancesPerHost=5
|
||||
X-DocPath=kioslave/curl/index.html
|
||||
Class=:internet
|
||||
local=false
|
||||
|
|
|
@ -12,4 +12,4 @@ moving=true
|
|||
deleteRecursive=true
|
||||
maxInstances=5
|
||||
X-DocPath=kioslave/file/index.html
|
||||
Class=:local
|
||||
local=true
|
||||
|
|
|
@ -422,7 +422,7 @@ bool ReadOnlyPart::openUrl(const KUrl &url)
|
|||
if (d->m_url.isLocalFile()) {
|
||||
d->m_file = d->m_url.toLocalFile();
|
||||
return d->openLocalFile();
|
||||
} else if (KProtocolInfo::protocolClass(url.protocol()) == ":local") {
|
||||
} 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);
|
||||
|
|
|
@ -192,10 +192,10 @@ class RunnerContextPrivate : public QSharedData
|
|||
} else {
|
||||
KUrl url(term);
|
||||
// check for a normal URL first
|
||||
//kDebug() << url << KProtocolInfo::protocolClass(url.protocol()) << url.hasHost() <<
|
||||
// kDebug() << url << KProtocolInfo::protocolIsLocal(url.protocol()) << url.hasHost() <<
|
||||
// url.host() << url.isLocalFile() << path << path.indexOf('/');
|
||||
const bool hasProtocol = !url.protocol().isEmpty();
|
||||
const bool isLocalProtocol = KProtocolInfo::protocolClass(url.protocol()) == ":local";
|
||||
const bool isLocalProtocol = KProtocolInfo::protocolIsLocal(url.protocol());
|
||||
if (hasProtocol &&
|
||||
((!isLocalProtocol && url.hasHost()) ||
|
||||
(isLocalProtocol && url.protocol() != "file"))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue