From 715433c853b0ad163093e08ecf55b5621db62022 Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 14 Oct 2011 07:14:57 +0000 Subject: Add new system executable completion mode to kurlcompletion git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1258882 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kio/kio/kurlcompletion.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++ kio/kio/kurlcompletion.h | 3 +- 2 files changed, 74 insertions(+), 1 deletion(-) (limited to 'kio') diff --git a/kio/kio/kurlcompletion.cpp b/kio/kio/kurlcompletion.cpp index e09ce2ed8..79a939530 100644 --- a/kio/kio/kurlcompletion.cpp +++ b/kio/kio/kurlcompletion.cpp @@ -620,6 +620,18 @@ TQString KURLCompletion::makeCompletion(const TQString &text) if ( urlCompletion( url, &match ) ) return match; } + else if ( d->mode == SystemExeCompletion ) { + // Executables + // + if ( systemexeCompletion( url, &match ) ) + return match; + + // KRun can run "man:" and "info:" etc. so why not treat them + // as executables... + + if ( urlCompletion( url, &match ) ) + return match; + } else { // Local files, directories // @@ -874,6 +886,66 @@ bool KURLCompletion::exeCompletion(const MyURL &url, TQString *match) return true; } +////////////////////////////////////////////////// +////////////////////////////////////////////////// +// System Executables +// + +bool KURLCompletion::systemexeCompletion(const MyURL &url, TQString *match) +{ + if ( url.protocol() != "file" ) + return false; + + TQString dir = url.dir(); + + dir = unescape( dir ); // remove escapes + + // Find directories to search for completions, either + // + // 1. complete path given in url + // 2. current directory (d->cwd) + // 3. $PATH + // 4. no directory at all + + TQStringList dirList; + + if ( !url.file().isEmpty() ) { + // $PATH + dirList = TQStringList::split(KPATH_SEPARATOR, + TQString::fromLocal8Bit(::getenv("PATH"))); + + TQStringList::Iterator it = dirList.begin(); + + for ( ; it != dirList.end(); it++ ) + (*it).append('/'); + } + + // No hidden files unless the user types "." + bool no_hidden_files = url.file().tqat(0) != '.'; + + // List files if needed + // + if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) ) + { + stop(); + clear(); + + setListedURL( CTExe, dir, url.file(), no_hidden_files ); + + *match = listDirectories( dirList, url.file(), true, false, no_hidden_files ); + } + else if ( !isRunning() ) { + *match = finished(); + } + else { + if ( d->dirListThread ) + setListedURL( CTExe, dir, url.file(), no_hidden_files ); + *match = TQString::null; + } + + return true; +} + ////////////////////////////////////////////////// ////////////////////////////////////////////////// // Local files diff --git a/kio/kio/kurlcompletion.h b/kio/kio/kurlcompletion.h index a06d7dc4b..2e042c3bc 100644 --- a/kio/kio/kurlcompletion.h +++ b/kio/kio/kurlcompletion.h @@ -50,7 +50,7 @@ public: * are listed using KIO. * @li DirCompletion - Same as FileCompletion but only returns directories. */ - enum Mode { ExeCompletion=1, FileCompletion, DirCompletion }; + enum Mode { ExeCompletion=1, FileCompletion, DirCompletion, SystemExeCompletion }; /** * Constructs a KURLCompletion object in FileCompletion mode. @@ -186,6 +186,7 @@ private: bool userCompletion(const MyURL &url, TQString *match); bool envCompletion(const MyURL &url, TQString *match); bool exeCompletion(const MyURL &url, TQString *match); + bool systemexeCompletion(const MyURL &url, TQString *match); bool fileCompletion(const MyURL &url, TQString *match); bool urlCompletion(const MyURL &url, TQString *match); -- cgit v1.2.1