Patch: GlobalPaths stored incorrectly and KGlobalSettings::downloadPath returning wrong data

Matthias Fuchs mat69 at gmx.net
Wed May 12 21:48:42 BST 2010


Hi,

I stumbled over two issues that are interconnected:

1. If you clear a line in the Paths KCM -- in our case take "Download Paths:" 
--  then users-dirs.dirs looks this way
XDG_DOWNLOAD_DIR=""
Though it should become
XDG_DOWNLOAD_DIR="$HOME"
as defined in the specification [1], we could also delete that line, though 
setting it to two doublequotes is clearly wrong and leads to issue 2.

2. In KGlobalSettings::downloadPath() [2] you see the following code:

======================
QString KGlobalSettings::downloadPath()
{
    // Qt 4.4.1 does not have DOWNLOAD, so we based on old code for now
    QString downloadPath = QDir::homePath();
#ifndef Q_WS_WIN
    const QString xdgUserDirs = KGlobal::dirs()->localxdgconfdir() + 
QLatin1String( "user-dirs.dirs" );
    if( QFile::exists( xdgUserDirs ) ) {
        KConfig xdgUserConf( xdgUserDirs, KConfig::SimpleConfig );
        KConfigGroup g( &xdgUserConf, "" );
        downloadPath  = g.readPathEntry( "XDG_DOWNLOAD_DIR", downloadPath 
).remove(  '"' );
    }
#endif
    downloadPath = QDir::cleanPath( downloadPath );
    if ( !downloadPath.endsWith( '/' ) ) {
        downloadPath.append( QLatin1Char(  '/' ) );
    }
    return downloadPath;
}
======================

Interesting is this line:
downloadPath  = g.readPathEntry( "XDG_DOWNLOAD_DIR", downloadPath ).remove(  
'"' );
In our case it reads in '""' (in words two double quotes) and that is not 
regared as empty, so the default (downloadPath) is _not_ taken. After the 
remove command downloadPath is empty though and
======================
if ( !downloadPath.endsWith( '/' ) ) {
        downloadPath.append( QLatin1Char(  '/' ) );
}
======================
lead to that KGlobalSettings::downloadPath() will return "/" in our case, 
while user-dirs.dirs still stores
XDG_DOWNLOAD_DIR=""

My attached patches (the difference between 4.4 and 4.5 is only the 
destination of the files) fix both issues could you please review them?
In general the patch for issue 1 should also solve issue 2, but only for new 
configs, if users already had the XDG... line mentioned above when they would 
still be hurt by this issue, that is why I think that the patch for the second 
issue should also go in. It does not change that line, but avoids hassle for 
users by returning something useful when downloadPath() is called.


Additionally I am not sure why the downloadPath is ended with a "/", since all 
other paths do not have it that way. Though I did not change that due to 
consistency reasons.


I only tested it with 4.4 branch and there it worked as intended.

Cheers
matthias

[1] http://freedesktop.org/wiki/Software/xdg-user-dirs
[2] kdelibs/kdeui/kernel/kglobalsettings.cpp:649
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GlobalPaths4.4-fix.diff
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100512/8ac6754d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GlobalPaths4.5-fix.diff
Type: text/x-patch
Size: 1163 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100512/8ac6754d/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KGlobalSettings.diff
Type: text/x-patch
Size: 621 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100512/8ac6754d/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100512/8ac6754d/attachment.sig>


More information about the kde-core-devel mailing list