summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-10-14 07:14:57 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-10-14 07:14:57 +0000
commit715433c853b0ad163093e08ecf55b5621db62022 (patch)
treed34727c09e4d2b60187148b668a2dd1793de9b30
parent80f78d20c3052824bdca130c00dec33756fc4387 (diff)
downloadtdelibs-715433c853b0ad163093e08ecf55b5621db62022.tar.gz
tdelibs-715433c853b0ad163093e08ecf55b5621db62022.zip
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
-rw-r--r--kio/kio/kurlcompletion.cpp72
-rw-r--r--kio/kio/kurlcompletion.h3
2 files changed, 74 insertions, 1 deletions
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
//
@@ -876,6 +888,66 @@ bool KURLCompletion::exeCompletion(const MyURL &url, TQString *match)
//////////////////////////////////////////////////
//////////////////////////////////////////////////
+// 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);