32 #include <tqstringlist.h> 33 #include <tqvaluelist.h> 38 #include <tqtextstream.h> 39 #include <tqdeepcopy.h> 42 #include <tdeapplication.h> 44 #include <kcompletion.h> 46 #include <tdeio/jobclasses.h> 47 #include <tdeio/job.h> 48 #include <kprotocolinfo.h> 49 #include <tdeconfig.h> 50 #include <tdeglobal.h> 51 #include <tdelocale.h> 54 #include <sys/types.h> 60 #include <sys/param.h> 62 #include "kurlcompletion.h" 64 static bool expandTilde(TQString &);
65 static bool expandEnv(TQString &);
67 static TQString unescape(
const TQString &text);
71 #define MODE_EXE (S_IXUSR | S_IXGRP | S_IXOTH) 74 enum ComplType {CTNone=0, CTEnv, CTUser, CTMan, CTExe, CTFile, CTUrl, CTInfo};
76 class CompletionThread;
83 class CompletionMatchEvent :
public TQCustomEvent
86 CompletionMatchEvent( CompletionThread *thread ) :
87 TQCustomEvent( uniqueType() ),
88 m_completionThread( thread )
91 CompletionThread *completionThread()
const {
return m_completionThread; }
92 static int uniqueType() {
return User + 61080; }
95 CompletionThread *m_completionThread;
98 class CompletionThread :
public TQThread
103 m_receiver( receiver ),
104 m_terminationRequested( false )
108 void requestTermination() { m_terminationRequested =
true; }
109 TQDeepCopy<TQStringList> matches()
const {
return m_matches; }
112 void addMatch(
const TQString &match ) { m_matches.append( match ); }
113 bool terminationRequested()
const {
return m_terminationRequested; }
116 if ( !m_terminationRequested )
117 kapp->postEvent( m_receiver,
new CompletionMatchEvent(
this ) );
124 TQStringList m_matches;
125 bool m_terminationRequested;
133 class UserListThread :
public CompletionThread
137 CompletionThread( receiver )
143 static const TQChar tilde =
'~';
146 while ( ( pw = ::getpwent() ) && !terminationRequested() )
147 addMatch( tilde + TQString::fromLocal8Bit( pw->pw_name ) );
157 class DirectoryListThread :
public CompletionThread
161 const TQStringList &dirList,
162 const TQString &filter,
166 bool appendSlashToDir ) :
167 CompletionThread( receiver ),
168 m_dirList( TQDeepCopy<TQStringList>( dirList ) ),
169 m_filter( TQDeepCopy<TQString>( filter ) ),
170 m_onlyExe( onlyExe ),
171 m_onlyDir( onlyDir ),
172 m_noHidden( noHidden ),
173 m_appendSlashToDir( appendSlashToDir )
179 TQStringList m_dirList;
184 bool m_appendSlashToDir;
187 void DirectoryListThread::run()
203 for ( TQStringList::ConstIterator it = m_dirList.begin();
204 it != m_dirList.end() && !terminationRequested();
210 dir = ::opendir( TQFile::encodeName( *it ) );
212 kdDebug() <<
"Failed to open dir: " << *it << endl;
222 TQString path = TQDir::currentDirPath();
223 TQDir::setCurrent( *it );
229 #ifndef HAVE_READDIR_R 230 struct dirent *dirEntry = 0;
231 while ( !terminationRequested() &&
232 (dirEntry = ::readdir( dir)))
234 #if !defined(MAXPATHLEN) && defined(__GNU__) 235 #define MAXPATHLEN UCHAR_MAX 237 struct dirent *dirPosition = (
struct dirent *) malloc(
sizeof(
struct dirent ) + MAXPATHLEN + 1 );
238 struct dirent *dirEntry = 0;
239 while ( !terminationRequested() &&
240 ::readdir_r( dir, dirPosition, &dirEntry ) == 0 && dirEntry )
246 if ( dirEntry->d_name[0] ==
'.' && m_noHidden )
251 if ( dirEntry->d_name[0] ==
'.' && dirEntry->d_name[1] ==
'\0' )
256 if ( dirEntry->d_name[0] ==
'.' && dirEntry->d_name[1] ==
'.' && dirEntry->d_name[2] ==
'\0' )
259 TQString file = TQFile::decodeName( dirEntry->d_name );
261 if ( m_filter.isEmpty() || file.startsWith( m_filter ) ) {
263 if ( m_onlyExe || m_onlyDir || m_appendSlashToDir ) {
264 KDE_struct_stat sbuff;
266 if ( KDE_stat( dirEntry->d_name, &sbuff ) == 0 ) {
270 if ( m_onlyExe && ( sbuff.st_mode & MODE_EXE ) == 0 )
275 if ( m_onlyDir && !S_ISDIR( sbuff.st_mode ) )
280 if ( m_appendSlashToDir && S_ISDIR( sbuff.st_mode ) )
285 kdDebug() <<
"Could not stat file " << file << endl;
296 TQDir::setCurrent( path );
300 #ifdef HAVE_READDIR_R 313 class KURLCompletion::MyURL
316 MyURL(
const TQString &url,
const TQString &cwd);
317 MyURL(
const MyURL &url);
320 KURL *kurl()
const {
return m_kurl; }
322 TQString protocol()
const {
return m_kurl->protocol(); }
324 TQString dir()
const {
return m_kurl->directory(
false,
false); }
325 TQString file()
const {
return m_kurl->fileName(
false); }
328 TQString url()
const {
return m_url; }
331 bool isURL()
const {
return m_isURL; }
333 void filter(
bool replace_user_dir,
bool replace_env );
336 void init(
const TQString &url,
const TQString &cwd);
343 KURLCompletion::MyURL::MyURL(
const TQString &url,
const TQString &cwd)
348 KURLCompletion::MyURL::MyURL(
const MyURL &url)
350 m_kurl =
new KURL( *(url.m_kurl) );
352 m_isURL = url.m_isURL;
355 void KURLCompletion::MyURL::init(
const TQString &url,
const TQString &cwd)
361 TQString url_copy = url;
364 if ( url_copy[0] ==
'#' ) {
365 if ( url_copy[1] ==
'#' )
366 url_copy.replace( 0, 2, TQString(
"info:") );
368 url_copy.replace( 0, 1, TQString(
"man:") );
372 TQRegExp protocol_regex = TQRegExp(
"^[^/\\s\\\\]*:" );
376 if ( protocol_regex.search( url_copy ) == 0 )
378 m_kurl =
new KURL( url_copy );
387 if ( !TQDir::isRelativePath(url_copy) || url_copy[0] ==
'$' || url_copy[0] ==
'~' )
388 m_kurl->setPath( url_copy );
394 KURL base = KURL::fromPathOrURL( cwd );
397 if ( !TQDir::isRelativePath(url_copy) || url_copy[0] ==
'~' || url_copy[0] ==
'$' )
400 m_kurl->setPath( url_copy );
405 m_kurl =
new KURL( base );
406 m_kurl->addPath( url_copy );
412 KURLCompletion::MyURL::~MyURL()
417 void KURLCompletion::MyURL::filter(
bool replace_user_dir,
bool replace_env )
419 TQString d = dir() + file();
420 if ( replace_user_dir ) expandTilde( d );
421 if ( replace_env ) expandEnv( d );
422 m_kurl->setPath( d );
429 class KURLCompletionPrivate
432 KURLCompletionPrivate() : url_auto_completion(true),
435 ~KURLCompletionPrivate();
437 TQValueList<KURL*> list_urls;
442 bool url_auto_completion;
446 bool popup_append_slash;
449 TQString last_path_listed;
450 TQString last_file_listed;
451 TQString last_prepend;
468 bool list_urls_only_exe;
469 bool list_urls_no_hidden;
470 TQString list_urls_filter;
472 CompletionThread *userListThread;
473 CompletionThread *dirListThread;
476 KURLCompletionPrivate::~KURLCompletionPrivate()
478 if ( userListThread )
479 userListThread->requestTermination();
481 dirListThread->requestTermination();
508 void KURLCompletion::init()
510 d =
new KURLCompletionPrivate;
512 d->cwd = TQDir::homeDirPath();
514 d->replace_home =
true;
515 d->replace_env =
true;
516 d->last_no_hidden =
false;
517 d->last_compl_type = 0;
519 d->mode = KURLCompletion::FileCompletion;
522 TDEConfig *c = TDEGlobal::config();
523 TDEConfigGroupSaver cgs( c,
"URLCompletion" );
525 d->url_auto_completion = c->readBoolEntry(
"alwaysAutoComplete",
true);
526 d->popup_append_slash = c->readBoolEntry(
"popupAppendSlash",
true);
527 d->onlyLocalProto = c->readBoolEntry(
"LocalProtocolsOnly",
false);
552 return d->replace_env;
557 d->replace_env = replace;
562 return d->replace_home;
567 d->replace_home = replace;
579 MyURL url(text, d->cwd);
581 d->compl_text = text;
585 int toRemove = url.file().length() - url.kurl()->query().length();
586 if ( url.kurl()->hasRef() )
587 toRemove += url.kurl()->ref().length() + 1;
588 d->prepend = text.left( text.length() - toRemove );
589 d->complete_url = url.isURL();
595 if ( d->replace_env && envCompletion( url, &match ) )
600 if ( d->replace_home && userCompletion( url, &match ) )
604 url.filter( d->replace_home, d->replace_env );
611 if ( d->mode == ExeCompletion ) {
614 if ( exeCompletion( url, &match ) )
620 if ( urlCompletion( url, &match ) )
623 else if ( d->mode == SystemExeCompletion ) {
626 if ( systemexeCompletion( url, &match ) )
632 if ( urlCompletion( url, &match ) )
638 if ( fileCompletion( url, &match ) )
643 if ( urlCompletion( url, &match ) )
647 setListedURL( CTNone );
650 return TQString::null;
659 TQString KURLCompletion::finished()
661 if ( d->last_compl_type == CTInfo )
662 return TDECompletion::makeCompletion( d->compl_text.lower() );
664 return TDECompletion::makeCompletion( d->compl_text );
675 return d->list_job || (d->dirListThread && !d->dirListThread->finished());
690 if ( !d->list_urls.isEmpty() ) {
691 TQValueList<KURL*>::Iterator it = d->list_urls.begin();
692 for ( ; it != d->list_urls.end(); it++ )
694 d->list_urls.clear();
697 if ( d->dirListThread ) {
698 d->dirListThread->requestTermination();
699 d->dirListThread = 0;
706 void KURLCompletion::setListedURL(
int complType,
708 const TQString& filter,
711 d->last_compl_type = complType;
712 d->last_path_listed =
dir;
713 d->last_file_listed = filter;
714 d->last_no_hidden = (int)no_hidden;
715 d->last_prepend = d->prepend;
718 bool KURLCompletion::isListedURL(
int complType,
720 const TQString& filter,
723 return d->last_compl_type == complType
724 && ( d->last_path_listed == dir
725 || (dir.isEmpty() && d->last_path_listed.isEmpty()) )
726 && ( filter.startsWith(d->last_file_listed)
727 || (filter.isEmpty() && d->last_file_listed.isEmpty()) )
728 && d->last_no_hidden == (int)no_hidden
729 && d->last_prepend == d->prepend;
737 bool KURLCompletion::isAutoCompletion()
739 return completionMode() == TDEGlobalSettings::CompletionAuto
740 || completionMode() == TDEGlobalSettings::CompletionPopup
741 || completionMode() == TDEGlobalSettings::CompletionMan
742 || completionMode() == TDEGlobalSettings::CompletionPopupAuto;
749 bool KURLCompletion::userCompletion(
const MyURL &url, TQString *match)
751 if ( url.protocol() !=
"file" 752 || !url.dir().isEmpty()
753 || url.file().at(0) !=
'~' )
756 if ( !isListedURL( CTUser ) ) {
760 if ( !d->userListThread ) {
761 d->userListThread =
new UserListThread(
this );
762 d->userListThread->start();
767 d->userListThread->wait( 200 );
768 TQStringList l = d->userListThread->matches();
781 #if !defined(__OpenBSD__) && !defined(__FreeBSD__) 782 extern char **environ;
785 bool KURLCompletion::envCompletion(
const MyURL &url, TQString *match)
787 #if defined(__OpenBSD__) || defined(__FreeBSD__) 790 if ( url.file().at(0) !=
'$' )
793 if ( !isListedURL( CTEnv ) ) {
797 char **env = environ;
799 TQString dollar = TQString(
"$");
804 TQString s = TQString::fromLocal8Bit( *env );
806 int pos = s.find(
'=');
812 l.append( dollar + s.left(pos) );
820 setListedURL( CTEnv );
832 bool KURLCompletion::exeCompletion(
const MyURL &url, TQString *match)
834 if ( url.protocol() !=
"file" )
837 TQString dir = url.dir();
839 dir = unescape( dir );
848 TQStringList dirList;
850 if ( !TQDir::isRelativePath(dir) ) {
852 dirList.append( dir );
854 else if ( !dir.isEmpty() && !d->cwd.isEmpty() ) {
856 dirList.append( d->cwd +
'/' + dir );
858 else if ( !url.file().isEmpty() ) {
860 dirList = TQStringList::split(KPATH_SEPARATOR,
861 TQString::fromLocal8Bit(::getenv(
"PATH")));
863 TQStringList::Iterator it = dirList.begin();
865 for ( ; it != dirList.end(); it++ )
870 bool no_hidden_files = url.file().at(0) !=
'.';
874 if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) )
879 setListedURL( CTExe, dir, url.file(), no_hidden_files );
881 *match = listDirectories( dirList, url.file(),
true,
false, no_hidden_files );
887 if ( d->dirListThread )
888 setListedURL( CTExe, dir, url.file(), no_hidden_files );
889 *match = TQString::null;
900 bool KURLCompletion::systemexeCompletion(
const MyURL &url, TQString *match)
902 if ( url.protocol() !=
"file" )
905 TQString dir = url.dir();
907 dir = unescape( dir );
916 TQStringList dirList;
918 if ( !url.file().isEmpty() ) {
920 dirList = TQStringList::split(KPATH_SEPARATOR,
921 TQString::fromLocal8Bit(::getenv(
"PATH")));
923 TQStringList::Iterator it = dirList.begin();
925 for ( ; it != dirList.end(); it++ )
930 bool no_hidden_files = url.file().at(0) !=
'.';
934 if ( !isListedURL( CTExe, dir, url.file(), no_hidden_files ) )
939 setListedURL( CTExe, dir, url.file(), no_hidden_files );
941 *match = listDirectories( dirList, url.file(),
true,
false, no_hidden_files );
947 if ( d->dirListThread )
948 setListedURL( CTExe, dir, url.file(), no_hidden_files );
949 *match = TQString::null;
960 bool KURLCompletion::fileCompletion(
const MyURL &url, TQString *match)
962 if ( url.protocol() !=
"file" )
965 TQString dir = url.dir();
967 if (url.url()[0] ==
'.')
969 if (url.url().length() == 1)
972 ( completionMode() == TDEGlobalSettings::CompletionMan )?
"." :
"..";
975 if (url.url().length() == 2 && url.url()[1]==
'.')
984 dir = unescape( dir );
992 TQStringList dirList;
994 if ( !TQDir::isRelativePath(dir) ) {
996 dirList.append( dir );
998 else if ( !d->cwd.isEmpty() ) {
1000 dirList.append( d->cwd +
'/' + dir );
1004 bool no_hidden_files = ( url.file().at(0) !=
'.' );
1008 if ( !isListedURL( CTFile, dir,
"", no_hidden_files ) )
1013 setListedURL( CTFile, dir,
"", no_hidden_files );
1016 bool append_slash = ( d->popup_append_slash
1017 && (completionMode() == TDEGlobalSettings::CompletionPopup ||
1018 completionMode() == TDEGlobalSettings::CompletionPopupAuto ) );
1020 bool only_dir = ( d->mode == DirCompletion );
1022 *match = listDirectories( dirList,
"",
false, only_dir, no_hidden_files,
1026 *match = finished();
1029 *match = TQString::null;
1040 bool KURLCompletion::urlCompletion(
const MyURL &url, TQString *match)
1047 KURL url_cwd = KURL::fromPathOrURL( d->cwd );
1050 KURL url_dir( url_cwd, url.kurl()->url() );
1058 bool man_or_info = ( url_dir.protocol() == TQString(
"man")
1059 || url_dir.protocol() == TQString(
"info") );
1061 if ( !url_dir.isValid()
1064 && ( url_dir.directory(
false,
false).isEmpty()
1065 || ( isAutoCompletion()
1066 && !d->url_auto_completion ) ) ) ) {
1070 url_dir.setFileName(
"");
1073 TQString dir = url_dir.directory(
false,
false );
1075 dir = unescape( dir );
1077 url_dir.setPath( dir );
1081 if ( !isListedURL( CTUrl, url_dir.prettyURL(), url.file() ) )
1086 setListedURL( CTUrl, url_dir.prettyURL(),
"" );
1088 TQValueList<KURL*> url_list;
1089 url_list.append(
new KURL( url_dir ) );
1091 listURLs( url_list,
"",
false );
1093 *match = TQString::null;
1096 *match = finished();
1099 *match = TQString::null;
1115 void KURLCompletion::addMatches(
const TQStringList &matches )
1117 TQStringList::ConstIterator it = matches.begin();
1118 TQStringList::ConstIterator end = matches.end();
1120 if ( d->complete_url )
1121 for ( ; it != end; it++ )
1122 addItem( d->prepend + KURL::encode_string(*it));
1124 for ( ; it != end; it++ )
1125 addItem( d->prepend + (*it));
1140 TQString KURLCompletion::listDirectories(
1141 const TQStringList &dirList,
1142 const TQString &filter,
1146 bool append_slash_to_dir)
1150 if ( !::getenv(
"KURLCOMPLETION_LOCAL_TDEIO") ) {
1156 if ( d->dirListThread )
1157 d->dirListThread->requestTermination();
1161 for ( TQStringList::ConstIterator it = dirList.begin();
1162 it != dirList.end();
1167 if ( kapp->authorizeURLAction(
"list", KURL(), url ) )
1171 d->dirListThread =
new DirectoryListThread(
this, dirs, filter, only_exe, only_dir,
1172 no_hidden, append_slash_to_dir );
1173 d->dirListThread->start();
1174 d->dirListThread->wait( 200 );
1175 addMatches( d->dirListThread->matches() );
1184 TQValueList<KURL*> url_list;
1186 TQStringList::ConstIterator it = dirList.begin();
1188 for ( ; it != dirList.end(); it++ )
1189 url_list.append(
new KURL(*it) );
1191 listURLs( url_list, filter, only_exe, no_hidden );
1194 return TQString::null;
1206 void KURLCompletion::listURLs(
1207 const TQValueList<KURL *> &urls,
1208 const TQString &filter,
1212 assert( d->list_urls.isEmpty() );
1213 assert( d->list_job == 0L );
1215 d->list_urls = urls;
1216 d->list_urls_filter = filter;
1217 d->list_urls_only_exe = only_exe;
1218 d->list_urls_no_hidden = no_hidden;
1235 void KURLCompletion::slotEntries(
TDEIO::Job*,
const TDEIO::UDSEntryList& entries)
1237 TQStringList matches;
1239 TDEIO::UDSEntryListConstIterator it = entries.begin();
1240 TDEIO::UDSEntryListConstIterator end = entries.end();
1242 TQString filter = d->list_urls_filter;
1244 int filter_len = filter.length();
1248 for (; it != end; ++it) {
1251 bool is_exe =
false;
1252 bool is_dir =
false;
1255 TDEIO::UDSEntry::ConstIterator it_2 = e.begin();
1257 for( ; it_2 != e.end(); it_2++ ) {
1258 switch ( (*it_2).m_uds ) {
1260 name = (*it_2).m_str;
1263 is_exe = ((*it_2).m_long & MODE_EXE) != 0;
1266 is_dir = ((*it_2).m_long & S_IFDIR) != 0;
1269 url = (*it_2).m_str;
1274 if (!url.isEmpty()) {
1276 name = KURL(url).fileName();
1281 if ( name[0] ==
'.' &&
1282 ( d->list_urls_no_hidden ||
1283 name.length() == 1 ||
1284 ( name.length() == 2 && name[1] ==
'.' ) ) )
1287 if ( d->mode == DirCompletion && !is_dir )
1290 if ( filter_len == 0 || name.left(filter_len) == filter ) {
1294 if ( is_exe || !d->list_urls_only_exe )
1295 matches.append( name );
1299 addMatches( matches );
1310 void KURLCompletion::slotIOFinished(
TDEIO::Job * job )
1314 assert( job == d->list_job );
1316 if ( d->list_urls.isEmpty() ) {
1325 KURL *kurl = d->list_urls.first();
1327 d->list_urls.remove( kurl );
1332 d->list_job->addMetaData(
"no-auth-prompt",
"true");
1334 assert( d->list_job );
1336 connect( d->list_job,
1340 connect( d->list_job,
1341 TQT_SIGNAL( entries(
TDEIO::Job*,
const TDEIO::UDSEntryList&)),
1342 TQT_SLOT( slotEntries(
TDEIO::Job*,
const TDEIO::UDSEntryList&)) );
1359 void KURLCompletion::postProcessMatch( TQString *match )
const 1363 if ( !match->isEmpty() ) {
1367 if ( d->last_compl_type == CTFile )
1368 adjustMatch( *match );
1372 void KURLCompletion::adjustMatch( TQString& match )
const 1374 if ( match.at( match.length()-1 ) !=
'/' )
1378 if ( match.startsWith( TQString(
"file:") ) )
1379 copy = KURL(match).path();
1383 expandTilde( copy );
1385 if ( TQDir::isRelativePath(copy) )
1386 copy.prepend( d->cwd +
'/' );
1390 KDE_struct_stat sbuff;
1392 TQCString file = TQFile::encodeName( copy );
1394 if ( KDE_stat( (
const char*)file, &sbuff ) == 0 ) {
1395 if ( S_ISDIR ( sbuff.st_mode ) )
1396 match.append(
'/' );
1399 kdDebug() <<
"Could not stat file " << copy << endl;
1404 void KURLCompletion::postProcessMatches( TQStringList * matches )
const 1406 if ( !matches->isEmpty() && d->last_compl_type == CTFile ) {
1407 TQStringList::Iterator it = matches->begin();
1408 for (; it != matches->end(); ++it ) {
1409 adjustMatch( (*it) );
1414 void KURLCompletion::postProcessMatches( TDECompletionMatches * matches )
const 1416 if ( !matches->isEmpty() && d->last_compl_type == CTFile ) {
1417 TDECompletionMatches::Iterator it = matches->begin();
1418 for (; it != matches->end(); ++it ) {
1419 adjustMatch( (*it).value() );
1424 void KURLCompletion::customEvent(TQCustomEvent *e)
1426 if ( e->type() == CompletionMatchEvent::uniqueType() ) {
1428 CompletionMatchEvent *
event =
static_cast<CompletionMatchEvent *
>( e );
1430 event->completionThread()->wait();
1432 if ( !isListedURL( CTUser ) ) {
1435 addMatches( event->completionThread()->matches() );
1438 setListedURL( CTUser );
1440 if ( d->userListThread == event->completionThread() )
1441 d->userListThread = 0;
1443 if ( d->dirListThread == event->completionThread() )
1444 d->dirListThread = 0;
1446 delete event->completionThread();
1453 if ( text.isEmpty() )
1456 MyURL url( text, TQString::null );
1457 if ( !url.kurl()->isLocalFile() )
1460 url.filter( replaceHome, replaceEnv );
1461 return url.dir() + url.file();
1467 return replacedPath( text, d->replace_home, d->replace_env );
1480 static bool expandEnv( TQString &text )
1486 bool expanded =
false;
1488 while ( (pos = text.find(
'$', pos)) != -1 ) {
1492 if ( text[pos-1] ==
'\\' ) {
1500 int pos2 = text.find(
' ', pos+1 );
1501 int pos_tmp = text.find(
'/', pos+1 );
1503 if ( pos2 == -1 || (pos_tmp != -1 && pos_tmp < pos2) )
1507 pos2 = text.length();
1513 int len = pos2 - pos;
1514 TQString key = text.mid( pos+1, len-1);
1516 TQString::fromLocal8Bit( ::getenv(key.local8Bit()) );
1518 if ( !value.isEmpty() ) {
1520 text.replace( pos, len, value );
1521 pos = pos + value.length();
1539 static bool expandTilde(TQString &text)
1541 if ( text[0] !=
'~' )
1544 bool expanded =
false;
1548 int pos2 = text.find(
' ', 1 );
1549 int pos_tmp = text.find(
'/', 1 );
1551 if ( pos2 == -1 || (pos_tmp != -1 && pos_tmp < pos2) )
1555 pos2 = text.length();
1561 TQString user = text.mid( 1, pos2-1 );
1566 if ( user.isEmpty() ) {
1567 dir = TQDir::homeDirPath();
1572 struct passwd *pw = ::getpwnam( user.local8Bit() );
1575 dir = TQFile::decodeName( pw->pw_dir );
1580 if ( !dir.isEmpty() ) {
1582 text.replace(0, pos2, dir);
1595 static TQString unescape(
const TQString &text)
1599 for (uint pos = 0; pos < text.length(); pos++)
1600 if ( text[pos] !=
'\\' )
1601 result.insert( result.length(), text[pos] );
1606 void KURLCompletion::virtual_hook(
int id,
void* data )
1607 { TDECompletion::virtual_hook(
id, data ); }
1609 #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.