Problems with KUrlCompletion

Jeff Mitchell kde-dev at emailgoeshere.com
Sat Mar 29 15:07:36 GMT 2008


KUrlCompletion is the completion object often used with KLineEdit, but 
it has a behavior that is undesired: the last part (the completed part) 
has an appended slash that is often percent encoded.  For me, running 
Dolphin on Windows, I get completion suggestions like:

C:/Documents and Settings/Jeff%2F

On my Linux box, I get: /home/jeff/ (the last slash does not get percent 
encoded).  But after talking to some other users, I found that they see 
it too.  In those cases it's behaving like it should, but it's not 
behaving like the users expect.

This is the code that causes the issue:

void KUrlCompletionPrivate::addMatches( const QStringList &matchList )
{
	foreach(QString match, matchList)
		kDebug() << "KUrlCompletionPrivate::addMatches: " << match;
	QStringList::ConstIterator it = matchList.begin();
	QStringList::ConstIterator end = matchList.end();

	if ( complete_url )
		for ( ; it != end; ++it )
			q->addItem( prepend + QUrl::toPercentEncoding(*it) );
	else
		for ( ; it != end; ++it )
			q->addItem( prepend + (*it));
}

complete_url is set by testing url.isURL().  On Windows, this is most 
likely being tripped up by the colon and forward slash in C:/  For users 
on Linux, they see it when completion is happening on e.g. ftp://host/blah

One way to fix this would be to better define isURL(), which would fix 
it on Windows local files.

Another way (not necessarily mutually exclusive with the above option) 
would be to never percent encode as this is not a very good way to 
present completion options to a user.  Since the user will be typing 
with slashes, not percent encodings, the end URL that is activated in 
the line edit has to be encoded anyways.  (When talking to the others, 
they had assumed that this was actually a bug, not desired behavior). 
But I'm not sure if any applications explicitly rely on this behavior -- 
I doubt it since half the URL isn't percent encoded anyways (although if 
any do they should probably be fixed).

So what I'd like to do is a) better define isURL in the Windows case, 
and b) remove the complete_url check and never percent encode what comes 
back as completion matches.

Thoughts?
--Jeff




More information about the kde-core-devel mailing list