http://, man:/, file:/// and file:// all work as expected

svn path=/branches/KDE/4.4/kdelibs/; revision=1083284
This commit is contained in:
Aaron J. Seigo 2010-01-31 23:26:45 +00:00
parent b0737279cd
commit 3f57259d7a

View File

@ -116,7 +116,7 @@ bool correctPathCase(const QString& path, QString &corrected)
// path components // path components
QStringList components = QString(path).split(QDir::separator()); QStringList components = QString(path).split(QDir::separator());
if (components.size() < 2) { if (components.size() < 1) {
return false; return false;
} }
@ -124,12 +124,11 @@ bool correctPathCase(const QString& path, QString &corrected)
//kDebug() << "Components are" << components; //kDebug() << "Components are" << components;
QString correctPath; if (mustBeDir) {
if (components.back().isEmpty()) {
components.pop_back(); components.pop_back();
} }
QString correctPath;
const unsigned initialComponents = components.size(); const unsigned initialComponents = components.size();
for (unsigned i = 0; i < initialComponents - 1; i ++) { for (unsigned i = 0; i < initialComponents - 1; i ++) {
const QString tmp = components[0] + QDir::separator() + components[1]; const QString tmp = components[0] + QDir::separator() + components[1];
@ -174,6 +173,7 @@ class RunnerContextPrivate : public QSharedData
/** /**
* Determines type of query * Determines type of query
&&
*/ */
void determineType() void determineType()
{ {
@ -191,38 +191,51 @@ class RunnerContextPrivate : public QSharedData
RunnerContext::Executable; RunnerContext::Executable;
} else { } else {
KUrl url(term); KUrl url(term);
QString correctCasePath;
// check for a normal URL first // check for a normal URL first
if (KProtocolInfo::protocolClass(url.protocol()) == ":internet" && //kDebug() << url << KProtocolInfo::protocolClass(url.protocol()) << url.hasHost() <<
url.hasHost()) { // url.host() << url.isLocalFile() << path << path.indexOf('/');
const bool hasProtocol = !url.protocol().isEmpty();
const bool isLocalProtocol = KProtocolInfo::protocolClass(url.protocol()) == ":local";
if (hasProtocol &&
((!isLocalProtocol && url.hasHost()) ||
(isLocalProtocol && url.protocol() != "file"))) {
// we either have a network protocol with a host, so we can show matches for it
// or we have a non-file url that may be local so a host isn't required
type = RunnerContext::NetworkLocation; type = RunnerContext::NetworkLocation;
// check if we have a local network location first, otherwise assume a path, } else if (isLocalProtocol) {
// but if a path doesn't have any slashes is a single word or // at this point in the game, we assume we have a path,
// sentence: it's too ambiguous to be sure we're in a filesystem context // but if a path doesn't have any slashes
} else if (KProtocolInfo::protocolClass(url.protocol()) == ":local" && // it's too ambiguous to be sure we're in a filesystem context
!url.isLocalFile()) { path = QDir::cleanPath(url.toLocalFile());
type = RunnerContext::NetworkLocation; //kDebug( )<< "slash check" << path;
} else if ((path.indexOf('/') != -1 || path.indexOf('\\') != -1) && if (hasProtocol || ((path.indexOf('/') != -1 || path.indexOf('\\') != -1))) {
correctPathCase(path, correctCasePath)) { QString correctCasePath;
path = correctCasePath; if (correctPathCase(path, correctCasePath)) {
QFileInfo info(path); path = correctCasePath;
QFileInfo info(path);
//kDebug( )<< "correct cas epath is" << correctCasePath << info.isSymLink() <<
// info.isDir() << info.isFile();
if (info.isSymLink()) { if (info.isSymLink()) {
path = info.canonicalFilePath(); path = info.canonicalFilePath();
info = QFileInfo(path); info = QFileInfo(path);
} }
if (info.isDir()) { if (info.isDir()) {
type = RunnerContext::Directory; type = RunnerContext::Directory;
mimeType = "inode/folder"; mimeType = "inode/folder";
} else if (info.isFile()) { } else if (info.isFile()) {
type = RunnerContext::File; type = RunnerContext::File;
KMimeType::Ptr mimeTypePtr = KMimeType::findByPath(path); KMimeType::Ptr mimeTypePtr = KMimeType::findByPath(path);
if (mimeTypePtr) { if (mimeTypePtr) {
mimeType = mimeTypePtr->name(); mimeType = mimeTypePtr->name();
}
}
} }
} }
} }
} }
//kDebug() << "term2type" << term << type;
} }
void invalidate() void invalidate()