31 #include <tqstringlist.h> 32 #include <tqvaluelist.h> 37 #include <tqtextstream.h> 38 #include <tqdeepcopy.h> 41 #include <tdeapplication.h> 43 #include <kcompletion.h> 45 #include <tdeio/jobclasses.h> 46 #include <tdeio/job.h> 47 #include <kprotocolinfo.h> 48 #include <tdeconfig.h> 49 #include <tdeglobal.h> 50 #include <tdelocale.h> 53 #include <sys/types.h> 59 #include <sys/param.h> 61 #include "kurlcompletion.h" 63 static bool expandTilde(TQString &);
64 static bool expandEnv(TQString &);
66 static TQString unescape(
const TQString &text);
70 #define MODE_EXE (S_IXUSR | S_IXGRP | S_IXOTH) 73 enum ComplType {CTNone=0, CTEnv, CTUser, CTMan, CTExe, CTFile, CTUrl, CTInfo};
75 class CompletionThread;
82 class CompletionMatchEvent :
public TQCustomEvent
85 CompletionMatchEvent( CompletionThread *thread ) :
86 TQCustomEvent( uniqueType() ),
87 m_completionThread( thread )
90 CompletionThread *completionThread()
const {
return m_completionThread; }
91 static int uniqueType() {
return User + 61080; }
94 CompletionThread *m_completionThread;
97 class CompletionThread :
public TQThread
102 m_receiver( receiver ),
103 m_terminationRequested( false )
107 void requestTermination() { m_terminationRequested =
true; }
108 TQDeepCopy<TQStringList> matches()
const {
return m_matches; }
111 void addMatch(
const TQString &match ) { m_matches.append( match ); }
112 bool terminationRequested()
const {
return m_terminationRequested; }
115 if ( !m_terminationRequested )
116 kapp->postEvent( m_receiver,
new CompletionMatchEvent(
this ) );
123 TQStringList m_matches;
124 bool m_terminationRequested;
132 class UserListThread :
public CompletionThread
136 CompletionThread( receiver )
142 static const TQChar tilde =
'~';
145 while ( ( pw = ::getpwent() ) && !terminationRequested() )
146 addMatch( tilde + TQString::fromLocal8Bit( pw->pw_name ) );
156 class DirectoryListThread :
public CompletionThread
160 const TQStringList &dirList,
161 const TQString &filter,
165 bool appendSlashToDir ) :
166 CompletionThread( receiver ),
167 m_dirList( TQDeepCopy<TQStringList>( dirList ) ),
168 m_filter( TQDeepCopy<TQString>( filter ) ),
169 m_onlyExe( onlyExe ),
170 m_onlyDir( onlyDir ),
171 m_noHidden( noHidden ),
172 m_appendSlashToDir( appendSlashToDir )
178 TQStringList m_dirList;
183 bool m_appendSlashToDir;
186 void DirectoryListThread::run()
202 for ( TQStringList::ConstIterator it = m_dirList.begin();
203 it != m_dirList.end() && !terminationRequested();
209 dir = ::opendir( TQFile::encodeName( *it ) );
211 kdDebug() <<
"Failed to open dir: " << *it << endl;
221 TQString path = TQDir::currentDirPath();
222 TQDir::setCurrent( *it );
227 #ifndef HAVE_READDIR_R 228 struct dirent *dirEntry = 0;
229 while ( !terminationRequested() &&
230 (dirEntry = ::readdir( dir)))
232 #if !defined(MAXPATHLEN) && defined(__GNU__) 233 #define MAXPATHLEN UCHAR_MAX 235 struct dirent *dirPosition = (
struct dirent *) malloc(
sizeof(
struct dirent ) + MAXPATHLEN + 1 );
236 struct dirent *dirEntry = 0;
237 while ( !terminationRequested() &&
238 ::readdir_r( dir, dirPosition, &dirEntry ) == 0 && dirEntry )
244 if ( dirEntry->d_name[0] ==
'.' && m_noHidden )
249 if ( dirEntry->d_name[0] ==
'.' && dirEntry->d_name[1] ==
'\0' )
254 if ( dirEntry->d_name[0] ==
'.' && dirEntry->d_name[1] ==
'.' && dirEntry->d_name[2] ==
'\0' )
257 TQString file = TQFile::decodeName( dirEntry->d_name );
259 if ( m_filter.isEmpty() || file.startsWith( m_filter ) ) {
261 if ( m_onlyExe || m_onlyDir || m_appendSlashToDir ) {
262 KDE_struct_stat sbuff;
264 if ( KDE_stat( dirEntry->d_name, &sbuff ) == 0 ) {
268 if ( m_onlyExe && ( sbuff.st_mode & MODE_EXE ) == 0 )
273 if ( m_onlyDir && !S_ISDIR( sbuff.st_mode ) )
278 if ( m_appendSlashToDir && S_ISDIR( sbuff.st_mode ) )
283 kdDebug() <<
"Could not stat file " << file << endl;
294 TQDir::setCurrent( path );
298 #ifdef HAVE_READDIR_R 311 class KURLCompletion::MyURL
314 MyURL(
const TQString &url,
const TQString &cwd);
315 MyURL(
const MyURL &url);
318 KURL *kurl()
const {
return m_kurl; }
320 TQString protocol()
const {
return m_kurl->protocol(); }
322 TQString dir()
const {
return m_kurl->directory(
false,
false); }
323 TQString file()
const {
return m_kurl->fileName(
false); }
326 TQString url()
const {
return m_url; }
329 bool isURL()
const {
return m_isURL; }
331 void filter(
bool replace_user_dir,
bool replace_env );
334 void init(
const TQString &url,
const TQString &cwd);
341 KURLCompletion::MyURL::MyURL(
const TQString &url,
const TQString &cwd)
346 KURLCompletion::MyURL::MyURL(
const MyURL &url)
348 m_kurl =
new KURL( *(url.m_kurl) );
350 m_isURL = url.m_isURL;
353 void KURLCompletion::MyURL::init(
const TQString &url,
const TQString &cwd)
359 TQString url_copy = url;
362 if ( url_copy[0] ==
'#' ) {
363 if ( url_copy[1] ==
'#' )
364 url_copy.replace( 0, 2, TQString(
"info:") );
366 url_copy.replace( 0, 1, TQString(
"man:") );
370 TQRegExp protocol_regex = TQRegExp(
"^[^/\\s\\\\]*:" );
374 if ( protocol_regex.search( url_copy ) == 0 )
376 m_kurl =
new KURL( url_copy );
385 if ( !TQDir::isRelativePath(url_copy) || url_copy[0] ==
'$' || url_copy[0] ==
'~' )
386 m_kurl->setPath( url_copy );
392 KURL base = KURL::fromPathOrURL( cwd );
395 if ( !TQDir::isRelativePath(url_copy) || url_copy[0] ==
'~' || url_copy[0] ==
'$' )
398 m_kurl->setPath( url_copy );
403 m_kurl =
new KURL( base );
404 m_kurl->addPath( url_copy );
410 KURLCompletion::MyURL::~MyURL()
415 void KURLCompletion::MyURL::filter(
bool replace_user_dir,
bool replace_env )
417 TQString d = dir() + file();
418 if ( replace_user_dir ) expandTilde( d );
419 if ( replace_env ) expandEnv( d );
420 m_kurl->setPath( d );
427 class KURLCompletionPrivate
430 KURLCompletionPrivate() : url_auto_completion(true),
433 ~KURLCompletionPrivate();
435 TQValueList<KURL*> list_urls;
440 bool url_auto_completion;
444 bool popup_append_slash;
447 TQString last_path_listed;
448 TQString last_file_listed;
449 TQString last_prepend;
466 bool list_urls_only_exe;
467 bool list_urls_no_hidden;
468 TQString list_urls_filter;
470 CompletionThread *userListThread;
471 CompletionThread *dirListThread;
474 KURLCompletionPrivate::~KURLCompletionPrivate()
476 if ( userListThread )
477 userListThread->requestTermination();
479 dirListThread->requestTermination();
506 void KURLCompletion::init()
508 d =
new KURLCompletionPrivate;
510 d->cwd = TQDir::homeDirPath();
512 d->replace_home =
true;
513 d->replace_env =
true;
514 d->last_no_hidden =
false;
515 d->last_compl_type = 0;
517 d->mode = KURLCompletion::FileCompletion;
520 TDEConfig *c = TDEGlobal::config();
521 TDEConfigGroupSaver cgs( c,
"URLCompletion" );
523 d->url_auto_completion = c->readBoolEntry(
"alwaysAutoComplete",
true);
524 d->popup_append_slash = c->readBoolEntry(
"popupAppendSlash",
true);
525 d->onlyLocalProto = c->readBoolEntry(
"LocalProtocolsOnly",
false);
550 return d->replace_env;
555 d->replace_env = replace;
560 return d->replace_home;
565 d->replace_home = replace;
577 MyURL url(text, d->cwd);
579 d->compl_text = text;
583 int toRemove = url.file().length() - url.kurl()->query().length();
584 if ( url.kurl()->hasRef() )
585 toRemove += url.kurl()->ref().length() + 1;
586 d->prepend = text.left( text.length() - toRemove );
587 d->complete_url = url.isURL();
593 if ( d->replace_env && envCompletion( url, &match ) )
598 if ( d->replace_home && userCompletion( url, &match ) )
602 url.filter( d->replace_home, d->replace_env );
609 if ( d->mode == ExeCompletion ) {
612 if ( exeCompletion( url, &match ) )
618 if ( urlCompletion( url, &match ) )
621 else if ( d->mode == SystemExeCompletion ) {
624 if ( systemexeCompletion( url, &match ) )
630 if ( urlCompletion( url, &match ) )
636 if ( fileCompletion( url, &match ) )
641 if ( urlCompletion( url, &match ) )
645 setListedURL( CTNone );
648 return TQString::null;
657 TQString KURLCompletion::finished()
659 if ( d->last_compl_type == CTInfo )
660 return TDECompletion::makeCompletion( d->compl_text.lower() );
662 return TDECompletion::makeCompletion( d->compl_text );
673 return d->list_job || (d->dirListThread && !d->dirListThread->finished());
688 if ( !d->list_urls.isEmpty() ) {
689 TQValueList<KURL*>::Iterator it = d->list_urls.begin();
690 for ( ; it != d->list_urls.end(); it++ )
692 d->list_urls.clear();
695 if ( d->dirListThread ) {
696 d->dirListThread->requestTermination();
697 d->dirListThread = 0;
704 void KURLCompletion::setListedURL(
int complType,
706 const TQString& filter,
709 d->last_compl_type = complType;
710 d->last_path_listed =
dir;
711 d->last_file_listed = filter;
712 d->last_no_hidden = (int)no_hidden;
713 d->last_prepend = d->prepend;
716 bool KURLCompletion::isListedURL(
int complType,
718 const TQString& filter,
721 return d->last_compl_type == complType
722 && ( d->last_path_listed == dir
723 || (dir.isEmpty() && d->last_path_listed.isEmpty()) )
724 && ( filter.startsWith(d->last_file_listed)
725 || (filter.isEmpty() && d->last_file_listed.isEmpty()) )
726 && d->last_no_hidden == (int)no_hidden
727 && d->last_prepend == d->prepend;
735 bool KURLCompletion::isAutoCompletion()
737 return completionMode() == TDEGlobalSettings::CompletionAuto
738 || completionMode() == TDEGlobalSettings::CompletionPopup
739 || completionMode() == TDEGlobalSettings::CompletionMan
740 || completionMode() == TDEGlobalSettings::CompletionPopupAuto;
747 bool KURLCompletion::userCompletion(
const MyURL &url, TQString *match)
749 if ( url.protocol() !=
"file" 750 || !url.dir().isEmpty()
751 || url.file().at(0) !=
'~' )
754 if ( !isListedURL( CTUser ) ) {
758 if ( !d->userListThread ) {
759 d->userListThread =
new UserListThread(
this );
760 d->userListThread->start();
765 d->userListThread->wait( 200 );
766 TQStringList l = d->userListThread->matches();
779 #if !defined(__OpenBSD__) && !defined(__FreeBSD__) 780 extern char **environ;
783 bool KURLCompletion::envCompletion(
const MyURL &url, TQString *match)
785 #if defined(__OpenBSD__) || defined(__FreeBSD__) 788 if ( url.file().at(0) !=
'$' )
791 if ( !isListedURL( CTEnv ) ) {
795 char **env = environ;
797 TQString dollar = TQString(
"$");
802 TQString s = TQString::fromLocal8Bit( *env );
804 int pos = s.find(
'=');
810 l.append( dollar + s.left(pos) );
818 setListedURL( CTEnv );
830 bool KURLCompletion::exeCompletion(
const MyURL &url, TQString *match)
832 if ( url.protocol() !=
"file" )
835 TQString dir = url.dir();
837 dir = unescape( dir );
846 TQStringList dirList;
848 if ( !TQDir::isRelativePath(dir) ) {
850 dirList.append( dir );
852 else if ( !dir.isEmpty() && !d->cwd.isEmpty() ) {
854 dirList.append( d->cwd +
'/' + dir );
856 else if ( !url.file().isEmpty() ) {
858 dirList = TQStringList::split(KPATH_SEPARATOR,
859 TQString::fromLocal8Bit(::getenv(
"PATH")));
861 TQStringList::Iterator it = dirList.begin();
863 for ( ; it != dirList.end(); it++ )
868 bool no_hidden_files = url.file().at(0) !=
'.';
872 if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) )
877 setListedURL( CTExe, dir, url.file(), no_hidden_files );
879 *match = listDirectories( dirList, url.file(),
true,
false, no_hidden_files );
885 if ( d->dirListThread )
886 setListedURL( CTExe, dir, url.file(), no_hidden_files );
887 *match = TQString::null;
898 bool KURLCompletion::systemexeCompletion(
const MyURL &url, TQString *match)
900 if ( url.protocol() !=
"file" )
903 TQString dir = url.dir();
905 dir = unescape( dir );
914 TQStringList dirList;
916 if ( !url.file().isEmpty() ) {
918 dirList = TQStringList::split(KPATH_SEPARATOR,
919 TQString::fromLocal8Bit(::getenv(
"PATH")));
921 TQStringList::Iterator it = dirList.begin();
923 for ( ; it != dirList.end(); it++ )
928 bool no_hidden_files = url.file().at(0) !=
'.';
932 if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) )
937 setListedURL( CTExe, dir, url.file(), no_hidden_files );
939 *match = listDirectories( dirList, url.file(),
true,
false, no_hidden_files );
945 if ( d->dirListThread )
946 setListedURL( CTExe, dir, url.file(), no_hidden_files );
947 *match = TQString::null;
958 bool KURLCompletion::fileCompletion(
const MyURL &url, TQString *match)
960 if ( url.protocol() !=
"file" )
963 TQString dir = url.dir();
965 if (url.url()[0] ==
'.')
967 if (url.url().length() == 1)
970 ( completionMode() == TDEGlobalSettings::CompletionMan )?
"." :
"..";
973 if (url.url().length() == 2 && url.url()[1]==
'.')
982 dir = unescape( dir );
990 TQStringList dirList;
992 if ( !TQDir::isRelativePath(dir) ) {
994 dirList.append( dir );
996 else if ( !d->cwd.isEmpty() ) {
998 dirList.append( d->cwd +
'/' + dir );
1002 bool no_hidden_files = ( url.file().at(0) !=
'.' );
1006 if ( !isListedURL( CTFile, dir,
"", no_hidden_files ) )
1011 setListedURL( CTFile, dir,
"", no_hidden_files );
1014 bool append_slash = ( d->popup_append_slash
1015 && (completionMode() == TDEGlobalSettings::CompletionPopup ||
1016 completionMode() == TDEGlobalSettings::CompletionPopupAuto ) );
1018 bool only_dir = ( d->mode == DirCompletion );
1020 *match = listDirectories( dirList,
"",
false, only_dir, no_hidden_files,
1024 *match = finished();
1027 *match = TQString::null;
1038 bool KURLCompletion::urlCompletion(
const MyURL &url, TQString *match)
1045 KURL url_cwd = KURL::fromPathOrURL( d->cwd );
1048 KURL url_dir( url_cwd, url.kurl()->url() );
1056 bool man_or_info = ( url_dir.protocol() == TQString(
"man")
1057 || url_dir.protocol() == TQString(
"info") );
1059 if ( !url_dir.isValid()
1062 && ( url_dir.directory(
false,
false).isEmpty()
1063 || ( isAutoCompletion()
1064 && !d->url_auto_completion ) ) ) ) {
1068 url_dir.setFileName(
"");
1071 TQString dir = url_dir.directory(
false,
false );
1073 dir = unescape( dir );
1075 url_dir.setPath( dir );
1079 if ( !isListedURL( CTUrl, url_dir.prettyURL(), url.file() ) )
1084 setListedURL( CTUrl, url_dir.prettyURL(),
"" );
1086 TQValueList<KURL*> url_list;
1087 url_list.append(
new KURL( url_dir ) );
1089 listURLs( url_list,
"",
false );
1091 *match = TQString::null;
1094 *match = finished();
1097 *match = TQString::null;
1113 void KURLCompletion::addMatches(
const TQStringList &matches )
1115 TQStringList::ConstIterator it = matches.begin();
1116 TQStringList::ConstIterator end = matches.end();
1118 if ( d->complete_url )
1119 for ( ; it != end; it++ )
1120 addItem( d->prepend + KURL::encode_string(*it));
1122 for ( ; it != end; it++ )
1123 addItem( d->prepend + (*it));
1138 TQString KURLCompletion::listDirectories(
1139 const TQStringList &dirList,
1140 const TQString &filter,
1144 bool append_slash_to_dir)
1148 if ( !::getenv(
"KURLCOMPLETION_LOCAL_TDEIO") ) {
1154 if ( d->dirListThread )
1155 d->dirListThread->requestTermination();
1159 for ( TQStringList::ConstIterator it = dirList.begin();
1160 it != dirList.end();
1165 if ( kapp->authorizeURLAction(
"list", KURL(), url ) )
1169 d->dirListThread =
new DirectoryListThread(
this, dirs, filter, only_exe, only_dir,
1170 no_hidden, append_slash_to_dir );
1171 d->dirListThread->start();
1172 d->dirListThread->wait( 200 );
1173 addMatches( d->dirListThread->matches() );
1182 TQValueList<KURL*> url_list;
1184 TQStringList::ConstIterator it = dirList.begin();
1186 for ( ; it != dirList.end(); it++ )
1187 url_list.append(
new KURL(*it) );
1189 listURLs( url_list, filter, only_exe, no_hidden );
1192 return TQString::null;
1204 void KURLCompletion::listURLs(
1205 const TQValueList<KURL *> &urls,
1206 const TQString &filter,
1210 assert( d->list_urls.isEmpty() );
1211 assert( d->list_job == 0L );
1213 d->list_urls = urls;
1214 d->list_urls_filter = filter;
1215 d->list_urls_only_exe = only_exe;
1216 d->list_urls_no_hidden = no_hidden;
1233 void KURLCompletion::slotEntries(
TDEIO::Job*,
const TDEIO::UDSEntryList& entries)
1235 TQStringList matches;
1237 TDEIO::UDSEntryListConstIterator it = entries.begin();
1238 TDEIO::UDSEntryListConstIterator end = entries.end();
1240 TQString filter = d->list_urls_filter;
1242 int filter_len = filter.length();
1246 for (; it != end; ++it) {
1249 bool is_exe =
false;
1250 bool is_dir =
false;
1253 TDEIO::UDSEntry::ConstIterator it_2 = e.begin();
1255 for( ; it_2 != e.end(); it_2++ ) {
1256 switch ( (*it_2).m_uds ) {
1258 name = (*it_2).m_str;
1261 is_exe = ((*it_2).m_long & MODE_EXE) != 0;
1264 is_dir = ((*it_2).m_long & S_IFDIR) != 0;
1267 url = (*it_2).m_str;
1272 if (!url.isEmpty()) {
1274 name = KURL(url).fileName();
1279 if ( name[0] ==
'.' &&
1280 ( d->list_urls_no_hidden ||
1281 name.length() == 1 ||
1282 ( name.length() == 2 && name[1] ==
'.' ) ) )
1285 if ( d->mode == DirCompletion && !is_dir )
1288 if ( filter_len == 0 || name.left(filter_len) == filter ) {
1292 if ( is_exe || !d->list_urls_only_exe )
1293 matches.append( name );
1297 addMatches( matches );
1308 void KURLCompletion::slotIOFinished(
TDEIO::Job * job )
1312 assert( job == d->list_job );
1314 if ( d->list_urls.isEmpty() ) {
1323 KURL *kurl = d->list_urls.first();
1325 d->list_urls.remove( kurl );
1330 d->list_job->addMetaData(
"no-auth-prompt",
"true");
1332 assert( d->list_job );
1334 connect( d->list_job,
1338 connect( d->list_job,
1339 TQ_SIGNAL( entries(
TDEIO::Job*,
const TDEIO::UDSEntryList&)),
1340 TQ_SLOT( slotEntries(
TDEIO::Job*,
const TDEIO::UDSEntryList&)) );
1357 void KURLCompletion::postProcessMatch( TQString *match )
const 1361 if ( !match->isEmpty() ) {
1365 if ( d->last_compl_type == CTFile )
1366 adjustMatch( *match );
1370 void KURLCompletion::adjustMatch( TQString& match )
const 1372 if ( match.at( match.length()-1 ) !=
'/' )
1376 if ( match.startsWith( TQString(
"file:") ) )
1377 copy = KURL(match).path();
1381 expandTilde( copy );
1383 if ( TQDir::isRelativePath(copy) )
1384 copy.prepend( d->cwd +
'/' );
1388 KDE_struct_stat sbuff;
1390 TQCString file = TQFile::encodeName( copy );
1392 if ( KDE_stat( (
const char*)file, &sbuff ) == 0 ) {
1393 if ( S_ISDIR ( sbuff.st_mode ) )
1394 match.append(
'/' );
1397 kdDebug() <<
"Could not stat file " << copy << endl;
1402 void KURLCompletion::postProcessMatches( TQStringList * matches )
const 1404 if ( !matches->isEmpty() && d->last_compl_type == CTFile ) {
1405 TQStringList::Iterator it = matches->begin();
1406 for (; it != matches->end(); ++it ) {
1407 adjustMatch( (*it) );
1412 void KURLCompletion::postProcessMatches( TDECompletionMatches * matches )
const 1414 if ( !matches->isEmpty() && d->last_compl_type == CTFile ) {
1415 TDECompletionMatches::Iterator it = matches->begin();
1416 for (; it != matches->end(); ++it ) {
1417 adjustMatch( (*it).value() );
1422 void KURLCompletion::customEvent(TQCustomEvent *e)
1424 if ( e->type() == CompletionMatchEvent::uniqueType() ) {
1426 CompletionMatchEvent *
event =
static_cast<CompletionMatchEvent *
>( e );
1428 event->completionThread()->wait();
1430 if ( !isListedURL( CTUser ) ) {
1433 addMatches( event->completionThread()->matches() );
1436 setListedURL( CTUser );
1438 if ( d->userListThread == event->completionThread() )
1439 d->userListThread = 0;
1441 if ( d->dirListThread == event->completionThread() )
1442 d->dirListThread = 0;
1444 delete event->completionThread();
1451 if ( text.isEmpty() )
1454 MyURL url( text, TQString::null );
1455 if ( !url.kurl()->isLocalFile() )
1458 url.filter( replaceHome, replaceEnv );
1459 return url.dir() + url.file();
1465 return replacedPath( text, d->replace_home, d->replace_env );
1478 static bool expandEnv( TQString &text )
1484 bool expanded =
false;
1486 while ( (pos = text.find(
'$', pos)) != -1 ) {
1490 if ( text[pos-1] ==
'\\' ) {
1498 int pos2 = text.find(
' ', pos+1 );
1499 int pos_tmp = text.find(
'/', pos+1 );
1501 if ( pos2 == -1 || (pos_tmp != -1 && pos_tmp < pos2) )
1505 pos2 = text.length();
1511 int len = pos2 - pos;
1512 TQString key = text.mid( pos+1, len-1);
1514 TQString::fromLocal8Bit( ::getenv(key.local8Bit()) );
1516 if ( !value.isEmpty() ) {
1518 text.replace( pos, len, value );
1519 pos = pos + value.length();
1537 static bool expandTilde(TQString &text)
1539 if ( text[0] !=
'~' )
1542 bool expanded =
false;
1546 int pos2 = text.find(
' ', 1 );
1547 int pos_tmp = text.find(
'/', 1 );
1549 if ( pos2 == -1 || (pos_tmp != -1 && pos_tmp < pos2) )
1553 pos2 = text.length();
1559 TQString user = text.mid( 1, pos2-1 );
1564 if ( user.isEmpty() ) {
1565 dir = TQDir::homeDirPath();
1570 struct passwd *pw = ::getpwnam( user.local8Bit() );
1573 dir = TQFile::decodeName( pw->pw_dir );
1578 if ( !dir.isEmpty() ) {
1580 text.replace(0, pos2, dir);
1593 static TQString unescape(
const TQString &text)
1597 for (uint pos = 0; pos < text.length(); pos++)
1598 if ( text[pos] !=
'\\' )
1599 result.insert( result.length(), text[pos] );
1604 void KURLCompletion::virtual_hook(
int id,
void* data )
1605 { TDECompletion::virtual_hook(
id, data ); }
1607 #include "kurlcompletion.moc" TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
This class does completion of URLs including user directories (~user) and environment variables...
virtual void setReplaceHome(bool replace)
Enables/disables completion of ~username and replacement (internally) of ~username with the user's ho...
An alternative URL (If different from the caption)
virtual TQString makeCompletion(const TQString &text)
Finds completions to the given text.
Mode
Determines how completion is done.
virtual void setReplaceEnv(bool replace)
Enables/disables completion and replacement (internally) of environment variables in URLs...
virtual void setMode(Mode mode)
Changes the completion mode: exe or file completion.
The base class for all jobs.
virtual void setDir(const TQString &dir)
Sets the current directory (used as base for completion).
static bool supportsListing(const KURL &url)
Returns whether the protocol can list files/objects.
virtual bool replaceEnv() const
Checks whether environment variables are completed and whether they are replaced internally while fin...
static TQString protocolClass(const TQString &protocol)
Returns the protocol class for the specified protocol.
File type, part of the mode returned by stat (for a link, this returns the file type of the pointed i...
A ListJob is allows you to get the get the content of a directory.
virtual void stop()
Stops asynchronous completion.
Filename - as displayed in directory listings etc.
Access permissions (part of the mode returned by stat)
virtual TQString dir() const
Returns the current directory, as it was given in setDir.
TDEIO_EXPORT ListJob * listDir(const KURL &url, bool showProgressInfo=true, bool includeHidden=true)
List the contents of url, which is assumed to be a directory.
virtual Mode mode() const
Returns the completion mode: exe or file completion (default FileCompletion).
KURLCompletion()
Constructs a KURLCompletion object in FileCompletion mode.
TQString replacedPath(const TQString &text)
Replaces username and/or environment variables, depending on the current settings and returns the fil...
virtual bool replaceHome() const
Returns whether ~username is completed and whether ~username is replaced internally with the user's h...
virtual ~KURLCompletion()
Destructs the KURLCompletion object.
virtual bool isRunning() const
Check whether asynchronous completion is in progress.